npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mirawision/domino-inject

v1.0.0

Published

Ultra-lean helpers to embed UI into existing pages and sync styles

Downloads

4

Readme

@mirawision/domino-inject

A lightweight DOM injection library for web applications, @mirawision/domino-inject provides a comprehensive set of tools for mounting UI elements, managing styles, and syncing visual states with a clean, performant API.

Features

Mount Utilities

  • Direct Node Mounting: Mount existing nodes without wrappers
  • Light DOM Mounting: Inject elements with controlled wrappers
  • Shadow DOM Support: Mount isolated components with style encapsulation
  • Position Control: Flexible element positioning (before, after, first, last)
  • Cleanup Handling: Automatic resource cleanup and event listener management

Style Management

  • Style Injection: Add styles to both Light and Shadow DOM
  • Class Mirroring: Sync classes between elements with smart filtering
  • State Syncing: Mirror disabled states and ARIA attributes
  • Theme Support: Automatically sync ancestor theme classes

Key Benefits

  • Zero Dependencies: Tiny footprint for fast loading
  • TypeScript Support: Full type definitions included
  • Memory Efficient: Automatic resource cleanup
  • Performance Optimized: Debounced updates and efficient DOM operations

Installation

npm install @mirawision/domino-inject

or

npm install @mirawision/domino-inject

Usage

Here's a quick overview of how to use the core functionalities:

Mount Elements

import { mountNode, mountLight, mountShadow } from '@mirawision/domino-inject';

// Direct node mounting (no wrapper)
mountNode(
  document.querySelector('.toolbar')!,
  'last',                // position
  existingButton        // node to mount
);

// Light DOM mounting with cleanup
const light = mountLight(
  document.querySelector('.toolbar')!, 
  { 
    position: 'last',
    classes: ['btn-wrap'],
    tag: 'div'
  }, 
  root => {
    const btn = document.createElement('button');
    btn.className = 'btn btn-primary';
    root.appendChild(btn);
    
    // Return cleanup function
    return () => btn.remove();
  }
);

// Shadow DOM with style isolation
const shadow = mountShadow(
  document.body, 
  { 
    position: 'last',
    styles: [':host { all: initial }']
  }, 
  root => {
    const widget = document.createElement('div');
    root.appendChild(widget);
  }
);

// Cleanup when done
light.destroy();
shadow.destroy();

Manage Styles

import { injectStyles, mirrorClasses } from '@mirawision/domino-inject';

// Inject styles into any root
injectStyles(root, [
  // CSS strings
  '.btn { padding: 8px 16px; }',
  // CSSStyleSheet objects
  new CSSStyleSheet().replace('.btn-primary { background: blue; }')
]);

// Mirror classes with smart filtering
const controller = mirrorClasses(sourceBtn, targetBtn, {
  // Filter classes to mirror
  allow: cls => cls.startsWith('btn-'),
  deny: cls => cls === 'btn-danger',
  
  // Transform during mirroring
  map: cls => cls === 'primary' ? 'btn-primary' : cls,
  
  // Add permanent classes
  extraClasses: ['custom'],
  
  // Sync with parent themes
  observeAncestors: true,
  ancestorDepth: 2
});

// Cleanup when done
controller.disconnect();

API Reference

Mount Functions

mountNode(anchor, position, node)

Mount an existing DOM node at a specified position relative to an anchor element. Provides direct node insertion without wrappers or cleanup handling.

function mountNode(
  anchor: Element,
  position: 'before' | 'after' | 'first' | 'last' | 'replace',
  node: Node
): void

mountLight(anchor, options?, render?)

Create a controlled wrapper element in Light DOM with optional styling, attributes, and cleanup handling. Returns a controller for managing the mounted element.

function mountLight(
  anchor: Element,
  options?: MountLightOptions,
  render?: RenderFn<HTMLElement>
): LightController

interface MountLightOptions {
  position?: 'before' | 'after' | 'first' | 'last' | 'replace';
  tag?: keyof HTMLElementTagNameMap;
  classes?: string[];
  attrs?: Record<string, string>;
  style?: Partial<CSSStyleDeclaration>;
}

mountShadow(anchor, options?, render?)

Create an isolated component using Shadow DOM with its own style scope. Returns a controller for managing both the host element and shadow root.

function mountShadow(
  anchor: Element,
  options?: MountShadowOptions,
  render?: RenderFn<ShadowRoot>
): ShadowController

interface MountShadowOptions {
  position?: 'before' | 'after' | 'first' | 'last' | 'replace';
  tag?: keyof HTMLElementTagNameMap;
  mode?: 'open' | 'closed';
  styles?: (CSSStyleSheet | string)[];
  className?: string;
}

Style Functions

injectStyles(root, styles)

Add styles to any DOM root (Document, ShadowRoot, or Element) using either CSS strings or CSSStyleSheet objects. Automatically handles adoptedStyleSheets for Shadow DOM when available.

function injectStyles(
  root: ShadowRoot | Document | HTMLElement,
  styles: (CSSStyleSheet | string)[]
): void

mirrorClasses(source, target, options?)

Mirror CSS classes from one element to another with smart filtering, transformation, and state syncing. Perfect for matching existing UI styles and themes.

function mirrorClasses(
  source: Element,
  target: HTMLElement,
  options?: MirrorOptions
): MirrorController

interface MirrorOptions {
  debounceMs?: number;                   // default: 50
  extraClasses?: string[];               // never removed by mirror
  allow?: (cls: string) => boolean;      // whitelist filter
  deny?: (cls: string) => boolean;       // blacklist filter
  map?: (cls: string) => string | null;  // transform or drop class
  observeAncestors?: boolean;            // default: true
  ancestorDepth?: number;                // default: 2
  syncStateAttrs?: boolean;              // default: true
}

interface MirrorController {
  resync(): void;                        // force immediate sync
  disconnect(): void;                    // stop mirroring
  isConnected(): boolean;                // check if active
}

Contributing

Contributions are always welcome! Feel free to open issues or submit pull requests.

License

This project is licensed under the MIT License.