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

@viewstem/dom

v0.1.0

Published

Browser renderer and DOM component connector for Viewstem

Readme

@viewstem/dom

English | 한국어

Register component contracts and implementations through defineResourceSet in @viewstem/core. For vanilla DOM, use DOM_CONNECTOR_ID and supply a DomComponent. Pass the Runtime to createRenderer({ runtime }). Additional connectors can be supplied through connectors.

renderer.mount({ target, source }) owns its View. await mounted.ready returns the View when it is prepared and connected. await mounted.whenRendered() observes DOM completion on that connection. Use renderer.attach(view, target) to display an existing View and detach() to release the display.

A fallback({ parent, anchor, node, error }) can insert static DOM before anchor in parent. Return a handle with dispose() to clean up resources such as timers. Without update(context), a returned handle is disposed and the fallback is recreated when the node's status or error changes. Implement update(context) to use the latest snapshot in place. Optional whenRendered() signals completion.

A connector places its DOM before context.anchor in context.parent, then returns a MountedComponent. Register each named content host with provideSlot. Its cleanup callback withdraws that registration. The browser renderer places Viewstem children in registered hosts and handles movement and disposal. An implementation should stop its work when the supplied instance or update signal is aborted.

A synchronous DOM component returns update(), setPending(), and dispose().

import type { DomComponent } from '@viewstem/dom';

export const label: DomComponent = {
  mount({ parent, anchor, node }) {
    const element = parent.ownerDocument.createElement('span');
    element.textContent = String(node.inputs.label);
    parent.insertBefore(element, anchor);
    return {
      update(next) { element.textContent = String(next.inputs.label); },
      setPending(pending) { element.toggleAttribute('aria-busy', pending); },
      dispose() { element.remove(); },
    };
  },
};

If the connector applies its DOM asynchronously, provide whenRendered(signal) to report when its own DOM and slots are ready. The renderer waits for that result, then renders children into the slots provided so far and runs afterChildren if supplied. The display's whenRendered() covers both the connector and those children.

Styles for a component set

Use the same package-specific style ID for the CSS build and for the DOM your components create. The ID starts with a lowercase letter and uses lowercase letters, digits, and hyphens.

import { createStyleScope } from '@viewstem/dom/styles';

const forms = createStyleScope('acme-forms');
const input = forms.createElement(document, 'input');

Use createElementNS(document, namespace, tag) for owned SVG and mark(element) for an element created by a library on your behalf. Keep the host and borrowed slot elements in their original scopes.

import postcss from 'postcss';
import { scopeUiCss } from '@viewstem/dom/styles/postcss';

const result = await postcss([scopeUiCss('acme-forms')]).process(css, { from: 'styles.css' });

Resolve CSS imports before this step and publish the resulting stylesheet. The plugin scopes the final target of each selector and prefixes internal custom properties, layers, and animation names. In .theme { .field { … } }, an owned .field can match inside a host or another set's .theme. Declarations on .theme itself apply to owned .theme elements. Use publicProperties for custom properties the app can set by name.

The plugin accepts @media, @supports, @container, @scope, @starting-style, @layer, @keyframes, and private @property registrations. Top-level @charset and @namespace directives are also supported. Expand build-tool directives before this step. Other at-rules fail the build.

Declare document-wide rules such as @font-face and @counter-style in a host stylesheet. The host also registers public custom properties and defines names used by document View Transitions, named anchors, or named scroll and view timelines. Set styles can reference a host-provided font, counter style, or public custom property in their own rules.

When a component updates a local stylesheet property from JavaScript, pass forms.localProperty('--progress') to element.style.setProperty(). This resolves the same name that the build emits for --progress.

To bundle styles with the set, make the package’s browser export import the generated CSS and re-export the set from its JavaScript entry. Put the browser condition before the normal JavaScript entry in exports, and include the browser entry and the CSS in sideEffects. Consumers register the set as usual. Export the stylesheet separately for hosts that load CSS explicitly.

Source and documentation for this version