@native-dom/runtime
v0.0.7
Published
DOM runtime facade backed by native-dom's Rust core.
Readme
@native-dom/runtime
TypeScript DOM runtime facade for native-dom.
This package exposes browser-facing classes such as Window, Document, Node, Element, HTMLElement, events, observers, forms, CSS objects, and storage. It wraps @native-dom/native-core for native parse, query, serialize, and mutation operations.
Usage
import { Window } from "@native-dom/runtime";
const window = new Window("<button id='save'>Save</button>", "http://localhost:3000");
const button = window.document.getElementById("save");
button?.dispatchEvent(new window.MouseEvent("click", { bubbles: true }));Main Exports
Window,Document,DOMParser,XMLSerializer,Selection,Range.Node,Element,HTMLElement,Text,Comment,DocumentFragment,DocumentType.- Common HTML element subclasses including forms, inputs, templates, image, link, script, style, and table elements.
EventTarget,Event,CustomEvent,MouseEvent,KeyboardEvent,InputEvent,FocusEvent,SubmitEvent,PointerEvent,TouchEvent, and related init types.MutationObserver,ResizeObserver,IntersectionObserver.CSSStyleDeclaration,CSSStyleSheet,CSSRule,CSSStyleRule,CSSMediaRule.Location,History,Navigator,Screen,Storage,FormData,URL,DOMException,DOMRect.- Runtime stats helpers:
getRuntimeStats(),resetRuntimeStats(), andsetRuntimeStatsEnabled().
Design Notes
- Native nodes are wrapped lazily and cached so JS object identity remains stable.
- The TypeScript layer owns browser semantics that depend on JS object behavior, callbacks, prototype chains, and framework compatibility.
- The Rust layer owns compact data operations: parse, serialize, query, tree links, indexes, and selected high-volume mutations.
- Some browser APIs are intentionally stubs or partial implementations when tests need shape compatibility but not full browser behavior.
Development
pnpm --filter @native-dom/runtime build
pnpm --filter @native-dom/runtime typecheck
pnpm --filter @native-dom/runtime testThe runtime depends on a working @native-dom/native-core binding at runtime. Static checks run through Vite+; tests and package builds should be run after the native binding has been built locally.
