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

@ts0/dom

v0.3.0-beta.0

Published

Zero-dependency, schema-validated, deterministic scoped DOM driver for ts0 Malleable UI.

Readme

@ts0/dom

Beta. Until v1 a release can break the previous one, with no migration path.

Zero-dependency, schema-allowlisted, deterministic scoped DOM driver for ts0 Malleable UI (@ts0/core).

Features

  • Per-tenant scoped SlotRef handles: Guests never see HTMLElement, document, window, or CSS selectors. Every mounted element is bound to a generation-tracked slot lease with explicit read, write, focus, and scroll grants.
  • Schema-allowlisted DOM patching: Rejects on* event attributes, raw style strings/objects, URL attributes (href, src, action), srcdoc, innerHTML, contenteditable, and invalid tabindex values. CSS custom properties are typed and range-checked ([min, max] + host-supplied unit).
  • Atomic preflighted turns: DomScope.run() validates reducer state, the full effect batch against allowedIntents, and the projected view before admitting a revision or calling onPreventDefault(). Apply the admitted revision with flush(revision).
  • SSR/edge-safe & deterministic replay: createHeadlessDriver() and createBrowserDriver() share the exact DomScope contract with zero top-level browser global reads.

Install with pnpm add @ts0/[email protected] @ts0/[email protected] to compile and run a scoped guest.

Grants and turn intents

scope.attach(ref, node, grant) requires a grant. Supply {} to deny every capability, { read: true } to enable measurement and resize observation, or the exported FULL_SLOT_GRANT for all four capabilities. Omitted flags are denied. Grant flags must be booleans. Unknown flags are rejected.

A turn that emits effects must list their intent kinds in TurnInput.allowedIntents. Omitting the list denies every effect. A turn with no effects may omit it.

Pass the raw guest result directly to run. It checks the { state, effects } envelope and calls validateState once and validateEffect once per effect. The view callback receives the state returned by validateState.

import { compile } from "@ts0/core"
import { createDomScope, createHeadlessDriver } from "@ts0/dom"

const driver = createHeadlessDriver()
const pane = driver.createNode({ width: 640 })
const scope = createDomScope(driver, {
  slots: { pane: { attrs: { "data-compact": "boolean" } } },
  validateState(value) {
    if (typeof value !== "boolean") {
      throw new Error("Expected a compact-layout flag.")
    }
    return value
  },
  validateEffect() {
    throw new Error("This controller has no host effects.")
  },
  intentKind: () => "",
})
scope.attach("pane", pane, { read: true, write: true })

const program = compile(
  `
    import { measure } from "@ts0/dom/guest"
    export function step() {
      const box = measure("pane")
      return { state: box !== null && box.width < 700, effects: [] }
    }
    export function project(compact) {
      return { pane: { attrs: { "data-compact": compact } } }
    }
  `,
  { imports: { "@ts0/dom/guest": scope.imports } }
)

const revision = scope.run(
  { kind: "init" },
  () => program.call("step"),
  (state) => program.call("project", [state])
)
scope.flush(revision)
const snapshot = driver.readSnapshot(pane)
scope.dispose()

export { snapshot }

Retrying a flush

If the driver fails during flush, the scope attempts to restore the previous view. With an onDriverError callback, the scope calls it with phase "flush" and returns { error }. Without an error callback, or if the callback throws, the scope throws the driver error. While the revision is current, a retry reapplies the view and continues with the remaining commands. Each command is attempted at most once per revision. If a command throws, its delivery is indeterminate and the retry skips it. Flushing a fully applied revision again is a no-op.

Attribute constraints and tracing

Each SlotSchema.attrs entry accepts an AttrSpec. Use a scalar type like "string", { enum: ["compact", "wide"] }, or { type: "number", min: 0, max: 10, integer: true }. Numeric bounds are inclusive.

Policy budgets are finite non-negative integers. Zero is a valid cap. maxAttrLength, maxTextLength, and a slot's text maxLength count UTF-16 code units. maxTotalViewBytes and the bytes returned by validateSlotPatch also count UTF-16 code units. The total includes slot refs, normalized attribute and CSS variable names and values, and text. A present boolean attribute uses one unit for its value.

For untrusted data passed to validateView or validateSlotPatch, cap serialized bytes before decoding and bound record members before constructing objects when the decoder supports it. The view slot cap checks enumerable slot keys before walking descriptors. Native enumeration can still allocate key lists before the policy rejects a record.

Policy errors expose phase and path, plus slot when a slot is known. For example, an invalid enum attribute may have phase "view", slot "root" and path ["root", "attrs", "data-layout"]. An effect rejection has phase "step" and a path such as ["effects", 0].

DomPolicy.onTrace receives frozen DomTraceEntry objects from either driver, including slot references, measured boxes, validated patches, and revision IDs for flushed operations. Trace callback errors go to onDriverError with phase "trace".

Pass onAnnounce to createBrowserDriver to send announcements to your own live region. The browser driver creates its built-in region when the callback is omitted.

Headless history and replay

createHeadlessDriver({ maxHistory: 100 }) keeps the latest 100 entries in each of trace and announcements. Use maxHistory: 0 to skip recording or omit it for unbounded history. Headless measurements use the geometry provided by the host. Compare normalized inputs, accepted revisions, and the measurements and operations recorded by the scope's onTrace hook. Use browser assertions for native outcomes such as actual focus, scroll position and resize observer delivery.

Guest virtual module

Use the declarations-only @ts0/dom/guest import in ts0 guest code.

import {
  measure,
  focus,
  scrollIntoView,
  preventDefault,
  announce,
} from "@ts0/dom/guest"

Bind the virtual module to your scope when compiling the guest.

const program = compile(source, {
  imports: { "@ts0/dom/guest": scope.imports },
})

Host code imports drivers and scopes from @ts0/dom. Headless hosts can type-check with an ES2022 library and without installing @ts0/core.