@streetui/dom 1.6.1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -30,13 +30,20 @@ __export(index_exports, {
30
30
  ServerStyle: () => ServerStyle,
31
31
  ServerText: () => ServerText,
32
32
  browserDOMAdapter: () => browserDOMAdapter,
33
+ containFocus: () => containFocus,
33
34
  escapeHtmlAttr: () => escapeHtmlAttr,
34
35
  escapeHtmlText: () => escapeHtmlText,
35
36
  focusById: () => focusById,
36
37
  focusFirst: () => focusFirst,
38
+ focusInitial: () => focusInitial,
39
+ getFocusable: () => getFocusable,
40
+ onEscape: () => onEscape,
41
+ restoreFocus: () => restoreFocus,
42
+ saveFocus: () => saveFocus,
37
43
  serializeChildren: () => serializeChildren,
38
44
  serializeServerNode: () => serializeServerNode,
39
- serverDOMAdapter: () => serverDOMAdapter
45
+ serverDOMAdapter: () => serverDOMAdapter,
46
+ trapFocus: () => trapFocus
40
47
  });
41
48
  module.exports = __toCommonJS(index_exports);
42
49
 
@@ -105,6 +112,18 @@ var BrowserDOMAdapter = class {
105
112
  focus(element) {
106
113
  element.focus?.();
107
114
  }
115
+ body() {
116
+ return document.body ?? null;
117
+ }
118
+ activeElement() {
119
+ return document.activeElement ?? null;
120
+ }
121
+ contains(ancestor, node) {
122
+ return ancestor.contains(node);
123
+ }
124
+ matches(element, selector) {
125
+ return typeof element.matches === "function" && element.matches(selector);
126
+ }
108
127
  isElement(node) {
109
128
  return node.nodeType === Node.ELEMENT_NODE;
110
129
  }
@@ -472,6 +491,18 @@ var ServerDOMAdapter = class {
472
491
  }
473
492
  focus() {
474
493
  }
494
+ body() {
495
+ return null;
496
+ }
497
+ activeElement() {
498
+ return null;
499
+ }
500
+ contains(_ancestor, _node) {
501
+ return false;
502
+ }
503
+ matches(_element, _selector) {
504
+ return false;
505
+ }
475
506
  isElement(node) {
476
507
  return asServer(node).kind === "element";
477
508
  }
@@ -537,6 +568,66 @@ function focusFirst(dom, container, selector = FOCUSABLE_SELECTOR) {
537
568
  dom.focus(el);
538
569
  return true;
539
570
  }
571
+ function getFocusable(dom, container, selector = FOCUSABLE_SELECTOR) {
572
+ return Array.from(dom.querySelectorAll(container, selector)).filter(
573
+ (el) => dom.matches(el, selector)
574
+ );
575
+ }
576
+ function saveFocus(dom) {
577
+ return dom.activeElement();
578
+ }
579
+ function restoreFocus(dom, saved) {
580
+ if (saved !== null) dom.focus(saved);
581
+ }
582
+ function focusInitial(dom, container, initialFocusId) {
583
+ if (initialFocusId !== void 0 && focusById(dom, container, initialFocusId)) return;
584
+ focusFirst(dom, container);
585
+ }
586
+ function trapFocus(dom, container) {
587
+ const onKeydown = (event) => {
588
+ if (event.key !== "Tab") return;
589
+ const items = getFocusable(dom, container);
590
+ if (items.length === 0) {
591
+ event.preventDefault();
592
+ return;
593
+ }
594
+ const first = items[0];
595
+ const last = items[items.length - 1];
596
+ const active = dom.activeElement();
597
+ if (active === null || !dom.contains(container, active)) {
598
+ event.preventDefault();
599
+ dom.focus(first);
600
+ } else if (event.shiftKey && active === first) {
601
+ event.preventDefault();
602
+ dom.focus(last);
603
+ } else if (!event.shiftKey && active === last) {
604
+ event.preventDefault();
605
+ dom.focus(first);
606
+ }
607
+ };
608
+ dom.addEventListener(container, "keydown", onKeydown);
609
+ return () => dom.removeEventListener(container, "keydown", onKeydown);
610
+ }
611
+ function containFocus(dom, container) {
612
+ const body = dom.body();
613
+ if (body === null) return () => {
614
+ };
615
+ const onFocusIn = (event) => {
616
+ const target = event.target;
617
+ if (target !== null && !dom.contains(container, target)) {
618
+ focusFirst(dom, container);
619
+ }
620
+ };
621
+ dom.addEventListener(body, "focusin", onFocusIn);
622
+ return () => dom.removeEventListener(body, "focusin", onFocusIn);
623
+ }
624
+ function onEscape(dom, target, handler) {
625
+ const onKeydown = (event) => {
626
+ if (event.key === "Escape") handler();
627
+ };
628
+ dom.addEventListener(target, "keydown", onKeydown);
629
+ return () => dom.removeEventListener(target, "keydown", onKeydown);
630
+ }
540
631
  // Annotate the CommonJS export names for ESM import in node:
541
632
  0 && (module.exports = {
542
633
  BrowserDOMAdapter,
@@ -549,12 +640,19 @@ function focusFirst(dom, container, selector = FOCUSABLE_SELECTOR) {
549
640
  ServerStyle,
550
641
  ServerText,
551
642
  browserDOMAdapter,
643
+ containFocus,
552
644
  escapeHtmlAttr,
553
645
  escapeHtmlText,
554
646
  focusById,
555
647
  focusFirst,
648
+ focusInitial,
649
+ getFocusable,
650
+ onEscape,
651
+ restoreFocus,
652
+ saveFocus,
556
653
  serializeChildren,
557
654
  serializeServerNode,
558
- serverDOMAdapter
655
+ serverDOMAdapter,
656
+ trapFocus
559
657
  });
560
658
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/browser-adapter.ts","../src/server-node.ts","../src/server-adapter.ts","../src/focus.ts"],"sourcesContent":["export * from './adapter.js';\nexport * from './browser-adapter.js';\nexport * from './server-node.js';\nexport * from './server-adapter.js';\nexport * from './focus.js';\n","/**\n * Browser implementation of DOMAdapter — delegates directly to browser APIs.\n */\n\nimport type { DOMAdapter } from './adapter.js';\n\nexport class BrowserDOMAdapter implements DOMAdapter {\n createElement(tag: string, ns?: string): Element {\n if (ns !== undefined) {\n return document.createElementNS(ns, tag);\n }\n return document.createElement(tag);\n }\n\n createTextNode(data: string): Text {\n return document.createTextNode(data);\n }\n\n createComment(data: string): Comment {\n return document.createComment(data);\n }\n\n createFragment(): DocumentFragment {\n return document.createDocumentFragment();\n }\n\n appendChild(parent: Node, child: Node): void {\n parent.appendChild(child);\n }\n\n insertBefore(parent: Node, child: Node, reference: Node | null): void {\n parent.insertBefore(child, reference);\n }\n\n removeChild(parent: Node, child: Node): void {\n parent.removeChild(child);\n }\n\n replaceChild(parent: Node, newChild: Node, oldChild: Node): void {\n parent.replaceChild(newChild, oldChild);\n }\n\n setAttribute(element: Element, name: string, value: string): void {\n element.setAttribute(name, value);\n }\n\n removeAttribute(element: Element, name: string): void {\n element.removeAttribute(name);\n }\n\n getAttribute(element: Element, name: string): string | null {\n return element.getAttribute(name);\n }\n\n setProperty(element: Element, name: string, value: unknown): void {\n (element as unknown as Record<string, unknown>)[name] = value;\n }\n\n setTextContent(node: Node, text: string): void {\n node.textContent = text;\n }\n\n getTextContent(node: Node): string | null {\n return node.textContent;\n }\n\n addEventListener(\n target: EventTarget,\n type: string,\n handler: EventListener,\n options?: AddEventListenerOptions,\n ): void {\n target.addEventListener(type, handler, options);\n }\n\n removeEventListener(\n target: EventTarget,\n type: string,\n handler: EventListener,\n options?: EventListenerOptions,\n ): void {\n target.removeEventListener(type, handler, options);\n }\n\n querySelector(root: Element | Document, selector: string): Element | null {\n return root.querySelector(selector);\n }\n\n querySelectorAll(root: Element | Document, selector: string): NodeListOf<Element> {\n return root.querySelectorAll(selector);\n }\n\n getElementById(id: string): Element | null {\n return document.getElementById(id);\n }\n\n focus(element: Element): void {\n (element as unknown as { focus?: () => void }).focus?.();\n }\n\n isElement(node: Node): node is Element {\n return node.nodeType === Node.ELEMENT_NODE;\n }\n\n isTextNode(node: Node): node is Text {\n return node.nodeType === Node.TEXT_NODE;\n }\n\n tagName(element: Element): string {\n return element.tagName.toLowerCase();\n }\n\n parentNode(node: Node): Node | null {\n return node.parentNode;\n }\n\n nextSibling(node: Node): Node | null {\n return node.nextSibling;\n }\n\n firstChild(node: Node): Node | null {\n return node.firstChild;\n }\n\n childNodes(node: Node): Node[] {\n return Array.from(node.childNodes);\n }\n}\n\n// `/* @__PURE__ */`: convenience singleton, unreferenced by internal runtime\n// paths. Marking construction pure lets bundlers drop it when unused instead of\n// retaining it (and the BrowserDOMAdapter class) as an import-time side effect.\nexport const browserDOMAdapter = /* @__PURE__ */ new BrowserDOMAdapter();\n","/**\n * Server-side DOM node model.\n *\n * A tiny, dependency-free tree of plain objects that mirrors just enough of the\n * browser DOM for StreetUI's renderer to build a tree on the server and\n * serialize it to an HTML string. There is NO browser global here — these are\n * ordinary classes usable in any JavaScript environment (Node, workers, tests).\n *\n * The renderer never touches these types directly; it goes through the\n * `DOMAdapter` interface, and `ServerDOMAdapter` translates adapter calls into\n * operations on this model.\n */\n\nexport type ServerNodeKind = 'element' | 'text' | 'comment' | 'fragment' | 'raw';\n\nexport interface ServerNode {\n readonly kind: ServerNodeKind;\n parent: ServerParent | null;\n}\n\nexport type ServerParent = ServerElement | ServerFragment;\n\n/** A minimal inline-style holder mirroring `element.style.setProperty`. */\nexport class ServerStyle {\n readonly declarations = new Map<string, string>();\n setProperty(name: string, value: string): void {\n this.declarations.set(name, value);\n }\n get isEmpty(): boolean {\n return this.declarations.size === 0;\n }\n toCss(): string {\n return [...this.declarations.entries()].map(([k, v]) => `${k}: ${v}`).join('; ');\n }\n}\n\nexport class ServerText implements ServerNode {\n readonly kind = 'text' as const;\n parent: ServerParent | null = null;\n data: string;\n constructor(data: string) {\n this.data = data;\n }\n}\n\nexport class ServerComment implements ServerNode {\n readonly kind = 'comment' as const;\n parent: ServerParent | null = null;\n data: string;\n constructor(data: string) {\n this.data = data;\n }\n}\n\nexport class ServerFragment implements ServerNode {\n readonly kind = 'fragment' as const;\n parent: ServerParent | null = null;\n readonly children: ServerNode[] = [];\n}\n\n/**\n * A pre-serialized, verbatim HTML fragment (v1.7 static SSR plan).\n *\n * Emitted for provably-static subtrees whose HTML the compiler-derived static\n * SSR plan already computed once. Serializing this node copies its stored\n * string directly — it allocates no ServerElement/ServerText, no attribute Map\n * and no children array for the collapsed subtree. The stored `html` is\n * produced by the exact same mount + serialize pipeline as the runtime path, so\n * the output is byte-identical (the v1.7 byte-identity gate proves this).\n *\n * This node is SSR-only: it is created solely via `ServerDOMAdapter.createRawHTML`\n * on the server render path and never appears in a browser build.\n */\nexport class ServerRawHTML implements ServerNode {\n readonly kind = 'raw' as const;\n parent: ServerParent | null = null;\n readonly html: string;\n constructor(html: string) {\n this.html = html;\n }\n}\n\nexport class ServerElement implements ServerNode {\n readonly kind = 'element' as const;\n parent: ServerParent | null = null;\n readonly tagName: string;\n readonly attributes = new Map<string, string>();\n readonly children: ServerNode[] = [];\n\n // Lazily-allocated stores. On the 10k-row SSR corpus ~0% of elements carry JS\n // properties or inline styles (measured, §5: 1 of 80,029 elements uses\n // `properties`, 0 use `style`), so eagerly allocating a `properties` Map plus\n // a `ServerStyle` (which itself holds a Map) per element wasted ~240k\n // allocations per /users render — all in the dominant mount phase. These are\n // created on first WRITE via the `properties`/`style` getters; the serializer\n // reads the raw `_properties`/`_style` fields so a READ never forces an\n // allocation. Output is byte-identical: an unset store previously serialized\n // to nothing (empty `properties.has(...)` / `style.isEmpty`), and a null store\n // is skipped the same way.\n _properties: Map<string, unknown> | null = null;\n _style: ServerStyle | null = null;\n\n constructor(tagName: string) {\n this.tagName = tagName.toLowerCase();\n }\n\n /** JS properties set via `setProperty` (e.g. input `value`, `checked`). Allocated on first access. */\n get properties(): Map<string, unknown> {\n return (this._properties ??= new Map());\n }\n\n /** Inline-style holder mirroring `element.style`. Allocated on first access. */\n get style(): ServerStyle {\n return (this._style ??= new ServerStyle());\n }\n}\n\n// ── HTML serialization ─────────────────────────────────────────────────────────\n\n/**\n * HTML \"void\" elements — self-closing, never given a closing tag or children.\n */\nconst VOID_ELEMENTS = new Set([\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\n 'link', 'meta', 'param', 'source', 'track', 'wbr',\n]);\n\n/**\n * Element properties that should be reflected into the serialized HTML so the\n * hydrated DOM carries the same initial state. `value`/`checked` matter for\n * form controls whose live state is a JS property, not an attribute.\n */\nconst SERIALIZED_PROPERTIES: Record<string, 'attr' | 'boolean'> = {\n value: 'attr',\n checked: 'boolean',\n selected: 'boolean',\n};\n\n/**\n * Precomputed `[name, kind]` pairs of SERIALIZED_PROPERTIES. Hoisted to module\n * scope so `serializeAttributes` does not allocate a fresh entries array for\n * every element serialized (measured hot: ~80k elements on the 10k-row route).\n */\nconst SERIALIZED_PROPERTY_ENTRIES: ReadonlyArray<readonly [string, 'attr' | 'boolean']> =\n Object.entries(SERIALIZED_PROPERTIES) as Array<[string, 'attr' | 'boolean']>;\n\n// Fast-path escaping. The chained `.replace(/…/g, …)` form makes 3–4 full\n// passes and allocates an intermediate string per pass even when nothing needs\n// escaping. These variants scan once and, in the overwhelmingly common case of\n// no special character, return the input unchanged (zero allocation). Output is\n// byte-identical to the chained form (verified over the real SSR corpus).\nconst TEXT_SPECIAL = /[&<>]/;\nconst ATTR_SPECIAL = /[&<>\"]/;\n\n/** Escape text node content. */\nexport function escapeHtmlText(value: string): string {\n if (!TEXT_SPECIAL.test(value)) return value;\n let out = '';\n let last = 0;\n for (let i = 0; i < value.length; i++) {\n let esc: string;\n switch (value.charCodeAt(i)) {\n case 38: esc = '&amp;'; break; // &\n case 60: esc = '&lt;'; break; // <\n case 62: esc = '&gt;'; break; // >\n default: continue;\n }\n out += value.slice(last, i) + esc;\n last = i + 1;\n }\n return out + value.slice(last);\n}\n\n/** Escape a double-quoted attribute value. */\nexport function escapeHtmlAttr(value: string): string {\n if (!ATTR_SPECIAL.test(value)) return value;\n let out = '';\n let last = 0;\n for (let i = 0; i < value.length; i++) {\n let esc: string;\n switch (value.charCodeAt(i)) {\n case 38: esc = '&amp;'; break; // &\n case 60: esc = '&lt;'; break; // <\n case 62: esc = '&gt;'; break; // >\n case 34: esc = '&quot;'; break; // \"\n default: continue;\n }\n out += value.slice(last, i) + esc;\n last = i + 1;\n }\n return out + value.slice(last);\n}\n\nfunction serializeAttributes(el: ServerElement): string {\n const parts: string[] = [];\n\n for (const [name, value] of el.attributes) {\n if (value === '') {\n parts.push(` ${name}`);\n } else {\n parts.push(` ${name}=\"${escapeHtmlAttr(value)}\"`);\n }\n }\n\n // Read the raw backing field (may be null): most elements have no JS\n // properties, so skipping the whole loop avoids touching a store that was\n // never allocated (§5).\n const props = el._properties;\n if (props !== null) {\n for (const [name, kind] of SERIALIZED_PROPERTY_ENTRIES) {\n if (!props.has(name)) continue;\n if (el.attributes.has(name)) continue; // an explicit attribute already won\n const raw = props.get(name);\n if (kind === 'boolean') {\n if (raw === true) parts.push(` ${name}`);\n } else {\n if (raw !== undefined && raw !== null) {\n parts.push(` ${name}=\"${escapeHtmlAttr(String(raw))}\"`);\n }\n }\n }\n }\n\n const style = el._style;\n if (style !== null && !style.isEmpty && !el.attributes.has('style')) {\n parts.push(` style=\"${escapeHtmlAttr(style.toCss())}\"`);\n }\n\n return parts.join('');\n}\n\n/** Serialize a single server node (element/text/comment/fragment/raw) to HTML. */\nexport function serializeServerNode(node: ServerNode): string {\n switch (node.kind) {\n case 'text':\n return escapeHtmlText((node as ServerText).data);\n case 'comment':\n return `<!--${(node as ServerComment).data}-->`;\n case 'fragment':\n return serializeChildren(node as ServerFragment);\n case 'raw':\n // Verbatim: the string was produced by this same serializer for a static\n // subtree, so it is already correctly escaped. Copy it as-is (§8).\n return (node as ServerRawHTML).html;\n case 'element': {\n const el = node as ServerElement;\n const tag = el.tagName;\n const attrs = serializeAttributes(el);\n if (VOID_ELEMENTS.has(tag)) {\n return `<${tag}${attrs}>`;\n }\n return `<${tag}${attrs}>${serializeChildren(el)}</${tag}>`;\n }\n }\n}\n\n/** Serialize the children of an element or fragment (its \"inner HTML\"). */\nexport function serializeChildren(node: ServerElement | ServerFragment): string {\n let out = '';\n for (const child of node.children) {\n out += serializeServerNode(child);\n }\n return out;\n}\n","/**\n * Server implementation of `DOMAdapter`.\n *\n * Builds a lightweight in-memory tree (see `server-node.ts`) instead of touching\n * a real browser DOM, then lets the caller serialize it to an HTML string. It is\n * completely free of browser globals, so the exact same renderer that runs in\n * the browser can produce HTML on the server.\n *\n * The `DOMAdapter` interface is typed against the lib DOM types (`Element`,\n * `Node`, `Text`, …). Our server nodes structurally stand in for those at\n * runtime, so the boundary uses `as unknown as` casts in one place. Everything\n * inside operates on the real server-node model.\n */\n\nimport type { DOMAdapter } from './adapter.js';\nimport {\n ServerElement,\n ServerText,\n ServerComment,\n ServerFragment,\n ServerRawHTML,\n serializeChildren,\n serializeServerNode,\n type ServerNode,\n type ServerParent,\n} from './server-node.js';\n\nfunction asServer(node: unknown): ServerNode {\n return node as unknown as ServerNode;\n}\nfunction asParent(node: unknown): ServerParent {\n return node as unknown as ServerParent;\n}\n\nexport class ServerDOMAdapter implements DOMAdapter {\n createElement(tag: string, _ns?: string): Element {\n return new ServerElement(tag) as unknown as Element;\n }\n\n createTextNode(data: string): Text {\n return new ServerText(data) as unknown as Text;\n }\n\n createComment(data: string): Comment {\n return new ServerComment(data) as unknown as Comment;\n }\n\n createFragment(): DocumentFragment {\n return new ServerFragment() as unknown as DocumentFragment;\n }\n\n /**\n * Create a verbatim pre-serialized HTML node (v1.7 static SSR plan, §6).\n * Server-only: the browser adapter does not implement this, and the renderer\n * fast path only invokes it when a static SSR plan is present (SSR). The\n * stored HTML was produced by this same serializer, so it is emitted as-is.\n */\n createRawHTML(html: string): Node {\n return new ServerRawHTML(html) as unknown as Node;\n }\n\n appendChild(parent: Node, child: Node): void {\n const p = asParent(parent);\n const c = asServer(child);\n this._detach(c);\n c.parent = p;\n p.children.push(c);\n }\n\n insertBefore(parent: Node, child: Node, reference: Node | null): void {\n const p = asParent(parent);\n const c = asServer(child);\n this._detach(c);\n c.parent = p;\n if (reference === null) {\n p.children.push(c);\n return;\n }\n const ref = asServer(reference);\n const idx = p.children.indexOf(ref);\n if (idx === -1) p.children.push(c);\n else p.children.splice(idx, 0, c);\n }\n\n removeChild(parent: Node, child: Node): void {\n const p = asParent(parent);\n const c = asServer(child);\n const idx = p.children.indexOf(c);\n if (idx !== -1) {\n p.children.splice(idx, 1);\n c.parent = null;\n }\n }\n\n replaceChild(parent: Node, newChild: Node, oldChild: Node): void {\n const p = asParent(parent);\n const nc = asServer(newChild);\n const oc = asServer(oldChild);\n const idx = p.children.indexOf(oc);\n if (idx === -1) return;\n this._detach(nc);\n nc.parent = p;\n p.children.splice(idx, 1, nc);\n oc.parent = null;\n }\n\n private _detach(node: ServerNode): void {\n if (node.parent !== null) {\n const siblings = node.parent.children;\n const idx = siblings.indexOf(node);\n if (idx !== -1) siblings.splice(idx, 1);\n node.parent = null;\n }\n }\n\n setAttribute(element: Element, name: string, value: string): void {\n (element as unknown as ServerElement).attributes.set(name, value);\n }\n\n removeAttribute(element: Element, name: string): void {\n (element as unknown as ServerElement).attributes.delete(name);\n }\n\n getAttribute(element: Element, name: string): string | null {\n return (element as unknown as ServerElement).attributes.get(name) ?? null;\n }\n\n setProperty(element: Element, name: string, value: unknown): void {\n (element as unknown as ServerElement).properties.set(name, value);\n }\n\n setTextContent(node: Node, text: string): void {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n const el = n as ServerElement | ServerFragment;\n el.children.length = 0;\n const t = new ServerText(text);\n t.parent = el;\n el.children.push(t);\n } else if (n.kind === 'text') {\n (n as ServerText).data = text;\n }\n }\n\n getTextContent(node: Node): string | null {\n const n = asServer(node);\n if (n.kind === 'text') return (n as ServerText).data;\n if (n.kind === 'element' || n.kind === 'fragment') {\n let out = '';\n for (const c of (n as ServerElement | ServerFragment).children) {\n out += this.getTextContent(c as unknown as Node) ?? '';\n }\n return out;\n }\n return null;\n }\n\n // Server nodes never dispatch events — listeners are a no-op on the server.\n addEventListener(): void {\n /* no-op on the server */\n }\n removeEventListener(): void {\n /* no-op on the server */\n }\n\n querySelector(): Element | null {\n return null;\n }\n querySelectorAll(): NodeListOf<Element> {\n return [] as unknown as NodeListOf<Element>;\n }\n getElementById(): Element | null {\n return null;\n }\n\n focus(): void {\n // No focus concept on the server — intentional no-op (SSR-safe).\n }\n\n isElement(node: Node): node is Element {\n return asServer(node).kind === 'element';\n }\n\n isTextNode(node: Node): node is Text {\n return asServer(node).kind === 'text';\n }\n\n tagName(element: Element): string {\n return (element as unknown as ServerElement).tagName;\n }\n\n parentNode(node: Node): Node | null {\n return (asServer(node).parent as unknown as Node | null) ?? null;\n }\n\n nextSibling(node: Node): Node | null {\n const n = asServer(node);\n const parent = n.parent;\n if (parent === null) return null;\n const idx = parent.children.indexOf(n);\n if (idx === -1 || idx + 1 >= parent.children.length) return null;\n return parent.children[idx + 1] as unknown as Node;\n }\n\n firstChild(node: Node): Node | null {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n const el = n as ServerElement | ServerFragment;\n return (el.children[0] as unknown as Node) ?? null;\n }\n return null;\n }\n\n childNodes(node: Node): Node[] {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n return (n as ServerElement | ServerFragment).children as unknown as Node[];\n }\n return [];\n }\n\n // ── Server-only ────────────────────────────────────────────────────────────\n\n /** Serialize a node's children (\"inner HTML\") to an HTML string. */\n serializeInner(node: Node): string {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n return serializeChildren(n as ServerElement | ServerFragment);\n }\n return '';\n }\n\n /** Serialize a node (including itself) to an HTML string. */\n serializeOuter(node: Node): string {\n return serializeServerNode(asServer(node));\n }\n}\n\n// `/* @__PURE__ */`: this singleton is a convenience export only (no internal\n// runtime path references it). Marking construction pure lets bundlers drop it —\n// and with it the whole server serializer chain (serializeServerNode/escape/\n// VOID_ELEMENTS) — out of client bundles that never import SSR. Without this,\n// the un-annotated `new` is treated as a side effect and retained everywhere.\nexport const serverDOMAdapter = /* @__PURE__ */ new ServerDOMAdapter();\n","/**\n * Focus helpers built on the {@link DOMAdapter} abstraction.\n *\n * These are the minimal, genuinely-useful focus operations an app needs:\n * focus a specific element (e.g. the first field when a route or modal opens)\n * or focus the first focusable element inside a container (e.g. move focus\n * into a dialog). Both go through the adapter, so they are no-ops on the server\n * (`ServerDOMAdapter.querySelector` returns null / `focus` does nothing) and\n * therefore safe to call from universal code.\n */\n\nimport type { DOMAdapter } from './adapter.js';\n\n/** Default selector for natively focusable / tabbable elements. */\nexport const FOCUSABLE_SELECTOR =\n 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * Focus the element with the given id, scoped to `root`.\n * Returns true if an element was found and focused.\n */\nexport function focusById(dom: DOMAdapter, root: Element | Document, id: string): boolean {\n const el = dom.querySelector(root, `[id=\"${id}\"]`);\n if (el === null) return false;\n dom.focus(el);\n return true;\n}\n\n/**\n * Focus the first focusable element inside `container`.\n * Returns true if a focusable element was found and focused.\n */\nexport function focusFirst(\n dom: DOMAdapter,\n container: Element | Document,\n selector: string = FOCUSABLE_SELECTOR,\n): boolean {\n const el = dom.querySelector(container, selector);\n if (el === null) return false;\n dom.focus(el);\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,IAAM,oBAAN,MAA8C;AAAA,EACnD,cAAc,KAAa,IAAsB;AAC/C,QAAI,OAAO,QAAW;AACpB,aAAO,SAAS,gBAAgB,IAAI,GAAG;AAAA,IACzC;AACA,WAAO,SAAS,cAAc,GAAG;AAAA,EACnC;AAAA,EAEA,eAAe,MAAoB;AACjC,WAAO,SAAS,eAAe,IAAI;AAAA,EACrC;AAAA,EAEA,cAAc,MAAuB;AACnC,WAAO,SAAS,cAAc,IAAI;AAAA,EACpC;AAAA,EAEA,iBAAmC;AACjC,WAAO,SAAS,uBAAuB;AAAA,EACzC;AAAA,EAEA,YAAY,QAAc,OAAmB;AAC3C,WAAO,YAAY,KAAK;AAAA,EAC1B;AAAA,EAEA,aAAa,QAAc,OAAa,WAA8B;AACpE,WAAO,aAAa,OAAO,SAAS;AAAA,EACtC;AAAA,EAEA,YAAY,QAAc,OAAmB;AAC3C,WAAO,YAAY,KAAK;AAAA,EAC1B;AAAA,EAEA,aAAa,QAAc,UAAgB,UAAsB;AAC/D,WAAO,aAAa,UAAU,QAAQ;AAAA,EACxC;AAAA,EAEA,aAAa,SAAkB,MAAc,OAAqB;AAChE,YAAQ,aAAa,MAAM,KAAK;AAAA,E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BAAmC,oBAAI,iBAAiB;;;ACrO9D,IAAM,qBACX;AAMK,SAAS,UAAU,KAAiB,MAA0B,IAAqB;AACxF,QAAM,KAAK,IAAI,cAAc,MAAM,QAAQ,EAAE,IAAI;AACjD,MAAI,OAAO,KAAM,QAAO;AACxB,MAAI,MAAM,EAAE;AACZ,SAAO;AACT;AAMO,SAAS,WACd,KACA,WACA,WAAmB,oBACV;AACT,QAAM,KAAK,IAAI,cAAc,WAAW,QAAQ;AAChD,MAAI,OAAO,KAAM,QAAO;AACxB,MAAI,MAAM,EAAE;AACZ,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/browser-adapter.ts","../src/server-node.ts","../src/server-adapter.ts","../src/focus.ts"],"sourcesContent":["export * from './adapter.js';\nexport * from './browser-adapter.js';\nexport * from './server-node.js';\nexport * from './server-adapter.js';\nexport * from './focus.js';\n","/**\n * Browser implementation of DOMAdapter — delegates directly to browser APIs.\n */\n\nimport type { DOMAdapter } from './adapter.js';\n\nexport class BrowserDOMAdapter implements DOMAdapter {\n createElement(tag: string, ns?: string): Element {\n if (ns !== undefined) {\n return document.createElementNS(ns, tag);\n }\n return document.createElement(tag);\n }\n\n createTextNode(data: string): Text {\n return document.createTextNode(data);\n }\n\n createComment(data: string): Comment {\n return document.createComment(data);\n }\n\n createFragment(): DocumentFragment {\n return document.createDocumentFragment();\n }\n\n appendChild(parent: Node, child: Node): void {\n parent.appendChild(child);\n }\n\n insertBefore(parent: Node, child: Node, reference: Node | null): void {\n parent.insertBefore(child, reference);\n }\n\n removeChild(parent: Node, child: Node): void {\n parent.removeChild(child);\n }\n\n replaceChild(parent: Node, newChild: Node, oldChild: Node): void {\n parent.replaceChild(newChild, oldChild);\n }\n\n setAttribute(element: Element, name: string, value: string): void {\n element.setAttribute(name, value);\n }\n\n removeAttribute(element: Element, name: string): void {\n element.removeAttribute(name);\n }\n\n getAttribute(element: Element, name: string): string | null {\n return element.getAttribute(name);\n }\n\n setProperty(element: Element, name: string, value: unknown): void {\n (element as unknown as Record<string, unknown>)[name] = value;\n }\n\n setTextContent(node: Node, text: string): void {\n node.textContent = text;\n }\n\n getTextContent(node: Node): string | null {\n return node.textContent;\n }\n\n addEventListener(\n target: EventTarget,\n type: string,\n handler: EventListener,\n options?: AddEventListenerOptions,\n ): void {\n target.addEventListener(type, handler, options);\n }\n\n removeEventListener(\n target: EventTarget,\n type: string,\n handler: EventListener,\n options?: EventListenerOptions,\n ): void {\n target.removeEventListener(type, handler, options);\n }\n\n querySelector(root: Element | Document, selector: string): Element | null {\n return root.querySelector(selector);\n }\n\n querySelectorAll(root: Element | Document, selector: string): NodeListOf<Element> {\n return root.querySelectorAll(selector);\n }\n\n getElementById(id: string): Element | null {\n return document.getElementById(id);\n }\n\n focus(element: Element): void {\n (element as unknown as { focus?: () => void }).focus?.();\n }\n\n body(): Element | null {\n return document.body ?? null;\n }\n\n activeElement(): Element | null {\n return document.activeElement ?? null;\n }\n\n contains(ancestor: Element, node: Node): boolean {\n return ancestor.contains(node);\n }\n\n matches(element: Element, selector: string): boolean {\n return typeof element.matches === 'function' && element.matches(selector);\n }\n\n isElement(node: Node): node is Element {\n return node.nodeType === Node.ELEMENT_NODE;\n }\n\n isTextNode(node: Node): node is Text {\n return node.nodeType === Node.TEXT_NODE;\n }\n\n tagName(element: Element): string {\n return element.tagName.toLowerCase();\n }\n\n parentNode(node: Node): Node | null {\n return node.parentNode;\n }\n\n nextSibling(node: Node): Node | null {\n return node.nextSibling;\n }\n\n firstChild(node: Node): Node | null {\n return node.firstChild;\n }\n\n childNodes(node: Node): Node[] {\n return Array.from(node.childNodes);\n }\n}\n\n// `/* @__PURE__ */`: convenience singleton, unreferenced by internal runtime\n// paths. Marking construction pure lets bundlers drop it when unused instead of\n// retaining it (and the BrowserDOMAdapter class) as an import-time side effect.\nexport const browserDOMAdapter = /* @__PURE__ */ new BrowserDOMAdapter();\n","/**\n * Server-side DOM node model.\n *\n * A tiny, dependency-free tree of plain objects that mirrors just enough of the\n * browser DOM for StreetUI's renderer to build a tree on the server and\n * serialize it to an HTML string. There is NO browser global here — these are\n * ordinary classes usable in any JavaScript environment (Node, workers, tests).\n *\n * The renderer never touches these types directly; it goes through the\n * `DOMAdapter` interface, and `ServerDOMAdapter` translates adapter calls into\n * operations on this model.\n */\n\nexport type ServerNodeKind = 'element' | 'text' | 'comment' | 'fragment' | 'raw';\n\nexport interface ServerNode {\n readonly kind: ServerNodeKind;\n parent: ServerParent | null;\n}\n\nexport type ServerParent = ServerElement | ServerFragment;\n\n/** A minimal inline-style holder mirroring `element.style.setProperty`. */\nexport class ServerStyle {\n readonly declarations = new Map<string, string>();\n setProperty(name: string, value: string): void {\n this.declarations.set(name, value);\n }\n get isEmpty(): boolean {\n return this.declarations.size === 0;\n }\n toCss(): string {\n return [...this.declarations.entries()].map(([k, v]) => `${k}: ${v}`).join('; ');\n }\n}\n\nexport class ServerText implements ServerNode {\n readonly kind = 'text' as const;\n parent: ServerParent | null = null;\n data: string;\n constructor(data: string) {\n this.data = data;\n }\n}\n\nexport class ServerComment implements ServerNode {\n readonly kind = 'comment' as const;\n parent: ServerParent | null = null;\n data: string;\n constructor(data: string) {\n this.data = data;\n }\n}\n\nexport class ServerFragment implements ServerNode {\n readonly kind = 'fragment' as const;\n parent: ServerParent | null = null;\n readonly children: ServerNode[] = [];\n}\n\n/**\n * A pre-serialized, verbatim HTML fragment (v1.7 static SSR plan).\n *\n * Emitted for provably-static subtrees whose HTML the compiler-derived static\n * SSR plan already computed once. Serializing this node copies its stored\n * string directly — it allocates no ServerElement/ServerText, no attribute Map\n * and no children array for the collapsed subtree. The stored `html` is\n * produced by the exact same mount + serialize pipeline as the runtime path, so\n * the output is byte-identical (the v1.7 byte-identity gate proves this).\n *\n * This node is SSR-only: it is created solely via `ServerDOMAdapter.createRawHTML`\n * on the server render path and never appears in a browser build.\n */\nexport class ServerRawHTML implements ServerNode {\n readonly kind = 'raw' as const;\n parent: ServerParent | null = null;\n readonly html: string;\n constructor(html: string) {\n this.html = html;\n }\n}\n\nexport class ServerElement implements ServerNode {\n readonly kind = 'element' as const;\n parent: ServerParent | null = null;\n readonly tagName: string;\n readonly attributes = new Map<string, string>();\n readonly children: ServerNode[] = [];\n\n // Lazily-allocated stores. On the 10k-row SSR corpus ~0% of elements carry JS\n // properties or inline styles (measured, §5: 1 of 80,029 elements uses\n // `properties`, 0 use `style`), so eagerly allocating a `properties` Map plus\n // a `ServerStyle` (which itself holds a Map) per element wasted ~240k\n // allocations per /users render — all in the dominant mount phase. These are\n // created on first WRITE via the `properties`/`style` getters; the serializer\n // reads the raw `_properties`/`_style` fields so a READ never forces an\n // allocation. Output is byte-identical: an unset store previously serialized\n // to nothing (empty `properties.has(...)` / `style.isEmpty`), and a null store\n // is skipped the same way.\n _properties: Map<string, unknown> | null = null;\n _style: ServerStyle | null = null;\n\n constructor(tagName: string) {\n this.tagName = tagName.toLowerCase();\n }\n\n /** JS properties set via `setProperty` (e.g. input `value`, `checked`). Allocated on first access. */\n get properties(): Map<string, unknown> {\n return (this._properties ??= new Map());\n }\n\n /** Inline-style holder mirroring `element.style`. Allocated on first access. */\n get style(): ServerStyle {\n return (this._style ??= new ServerStyle());\n }\n}\n\n// ── HTML serialization ─────────────────────────────────────────────────────────\n\n/**\n * HTML \"void\" elements — self-closing, never given a closing tag or children.\n */\nconst VOID_ELEMENTS = new Set([\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\n 'link', 'meta', 'param', 'source', 'track', 'wbr',\n]);\n\n/**\n * Element properties that should be reflected into the serialized HTML so the\n * hydrated DOM carries the same initial state. `value`/`checked` matter for\n * form controls whose live state is a JS property, not an attribute.\n */\nconst SERIALIZED_PROPERTIES: Record<string, 'attr' | 'boolean'> = {\n value: 'attr',\n checked: 'boolean',\n selected: 'boolean',\n};\n\n/**\n * Precomputed `[name, kind]` pairs of SERIALIZED_PROPERTIES. Hoisted to module\n * scope so `serializeAttributes` does not allocate a fresh entries array for\n * every element serialized (measured hot: ~80k elements on the 10k-row route).\n */\nconst SERIALIZED_PROPERTY_ENTRIES: ReadonlyArray<readonly [string, 'attr' | 'boolean']> =\n Object.entries(SERIALIZED_PROPERTIES) as Array<[string, 'attr' | 'boolean']>;\n\n// Fast-path escaping. The chained `.replace(/…/g, …)` form makes 3–4 full\n// passes and allocates an intermediate string per pass even when nothing needs\n// escaping. These variants scan once and, in the overwhelmingly common case of\n// no special character, return the input unchanged (zero allocation). Output is\n// byte-identical to the chained form (verified over the real SSR corpus).\nconst TEXT_SPECIAL = /[&<>]/;\nconst ATTR_SPECIAL = /[&<>\"]/;\n\n/** Escape text node content. */\nexport function escapeHtmlText(value: string): string {\n if (!TEXT_SPECIAL.test(value)) return value;\n let out = '';\n let last = 0;\n for (let i = 0; i < value.length; i++) {\n let esc: string;\n switch (value.charCodeAt(i)) {\n case 38: esc = '&amp;'; break; // &\n case 60: esc = '&lt;'; break; // <\n case 62: esc = '&gt;'; break; // >\n default: continue;\n }\n out += value.slice(last, i) + esc;\n last = i + 1;\n }\n return out + value.slice(last);\n}\n\n/** Escape a double-quoted attribute value. */\nexport function escapeHtmlAttr(value: string): string {\n if (!ATTR_SPECIAL.test(value)) return value;\n let out = '';\n let last = 0;\n for (let i = 0; i < value.length; i++) {\n let esc: string;\n switch (value.charCodeAt(i)) {\n case 38: esc = '&amp;'; break; // &\n case 60: esc = '&lt;'; break; // <\n case 62: esc = '&gt;'; break; // >\n case 34: esc = '&quot;'; break; // \"\n default: continue;\n }\n out += value.slice(last, i) + esc;\n last = i + 1;\n }\n return out + value.slice(last);\n}\n\nfunction serializeAttributes(el: ServerElement): string {\n const parts: string[] = [];\n\n for (const [name, value] of el.attributes) {\n if (value === '') {\n parts.push(` ${name}`);\n } else {\n parts.push(` ${name}=\"${escapeHtmlAttr(value)}\"`);\n }\n }\n\n // Read the raw backing field (may be null): most elements have no JS\n // properties, so skipping the whole loop avoids touching a store that was\n // never allocated (§5).\n const props = el._properties;\n if (props !== null) {\n for (const [name, kind] of SERIALIZED_PROPERTY_ENTRIES) {\n if (!props.has(name)) continue;\n if (el.attributes.has(name)) continue; // an explicit attribute already won\n const raw = props.get(name);\n if (kind === 'boolean') {\n if (raw === true) parts.push(` ${name}`);\n } else {\n if (raw !== undefined && raw !== null) {\n parts.push(` ${name}=\"${escapeHtmlAttr(String(raw))}\"`);\n }\n }\n }\n }\n\n const style = el._style;\n if (style !== null && !style.isEmpty && !el.attributes.has('style')) {\n parts.push(` style=\"${escapeHtmlAttr(style.toCss())}\"`);\n }\n\n return parts.join('');\n}\n\n/** Serialize a single server node (element/text/comment/fragment/raw) to HTML. */\nexport function serializeServerNode(node: ServerNode): string {\n switch (node.kind) {\n case 'text':\n return escapeHtmlText((node as ServerText).data);\n case 'comment':\n return `<!--${(node as ServerComment).data}-->`;\n case 'fragment':\n return serializeChildren(node as ServerFragment);\n case 'raw':\n // Verbatim: the string was produced by this same serializer for a static\n // subtree, so it is already correctly escaped. Copy it as-is (§8).\n return (node as ServerRawHTML).html;\n case 'element': {\n const el = node as ServerElement;\n const tag = el.tagName;\n const attrs = serializeAttributes(el);\n if (VOID_ELEMENTS.has(tag)) {\n return `<${tag}${attrs}>`;\n }\n return `<${tag}${attrs}>${serializeChildren(el)}</${tag}>`;\n }\n }\n}\n\n/** Serialize the children of an element or fragment (its \"inner HTML\"). */\nexport function serializeChildren(node: ServerElement | ServerFragment): string {\n let out = '';\n for (const child of node.children) {\n out += serializeServerNode(child);\n }\n return out;\n}\n","/**\n * Server implementation of `DOMAdapter`.\n *\n * Builds a lightweight in-memory tree (see `server-node.ts`) instead of touching\n * a real browser DOM, then lets the caller serialize it to an HTML string. It is\n * completely free of browser globals, so the exact same renderer that runs in\n * the browser can produce HTML on the server.\n *\n * The `DOMAdapter` interface is typed against the lib DOM types (`Element`,\n * `Node`, `Text`, …). Our server nodes structurally stand in for those at\n * runtime, so the boundary uses `as unknown as` casts in one place. Everything\n * inside operates on the real server-node model.\n */\n\nimport type { DOMAdapter } from './adapter.js';\nimport {\n ServerElement,\n ServerText,\n ServerComment,\n ServerFragment,\n ServerRawHTML,\n serializeChildren,\n serializeServerNode,\n type ServerNode,\n type ServerParent,\n} from './server-node.js';\n\nfunction asServer(node: unknown): ServerNode {\n return node as unknown as ServerNode;\n}\nfunction asParent(node: unknown): ServerParent {\n return node as unknown as ServerParent;\n}\n\nexport class ServerDOMAdapter implements DOMAdapter {\n createElement(tag: string, _ns?: string): Element {\n return new ServerElement(tag) as unknown as Element;\n }\n\n createTextNode(data: string): Text {\n return new ServerText(data) as unknown as Text;\n }\n\n createComment(data: string): Comment {\n return new ServerComment(data) as unknown as Comment;\n }\n\n createFragment(): DocumentFragment {\n return new ServerFragment() as unknown as DocumentFragment;\n }\n\n /**\n * Create a verbatim pre-serialized HTML node (v1.7 static SSR plan, §6).\n * Server-only: the browser adapter does not implement this, and the renderer\n * fast path only invokes it when a static SSR plan is present (SSR). The\n * stored HTML was produced by this same serializer, so it is emitted as-is.\n */\n createRawHTML(html: string): Node {\n return new ServerRawHTML(html) as unknown as Node;\n }\n\n appendChild(parent: Node, child: Node): void {\n const p = asParent(parent);\n const c = asServer(child);\n this._detach(c);\n c.parent = p;\n p.children.push(c);\n }\n\n insertBefore(parent: Node, child: Node, reference: Node | null): void {\n const p = asParent(parent);\n const c = asServer(child);\n this._detach(c);\n c.parent = p;\n if (reference === null) {\n p.children.push(c);\n return;\n }\n const ref = asServer(reference);\n const idx = p.children.indexOf(ref);\n if (idx === -1) p.children.push(c);\n else p.children.splice(idx, 0, c);\n }\n\n removeChild(parent: Node, child: Node): void {\n const p = asParent(parent);\n const c = asServer(child);\n const idx = p.children.indexOf(c);\n if (idx !== -1) {\n p.children.splice(idx, 1);\n c.parent = null;\n }\n }\n\n replaceChild(parent: Node, newChild: Node, oldChild: Node): void {\n const p = asParent(parent);\n const nc = asServer(newChild);\n const oc = asServer(oldChild);\n const idx = p.children.indexOf(oc);\n if (idx === -1) return;\n this._detach(nc);\n nc.parent = p;\n p.children.splice(idx, 1, nc);\n oc.parent = null;\n }\n\n private _detach(node: ServerNode): void {\n if (node.parent !== null) {\n const siblings = node.parent.children;\n const idx = siblings.indexOf(node);\n if (idx !== -1) siblings.splice(idx, 1);\n node.parent = null;\n }\n }\n\n setAttribute(element: Element, name: string, value: string): void {\n (element as unknown as ServerElement).attributes.set(name, value);\n }\n\n removeAttribute(element: Element, name: string): void {\n (element as unknown as ServerElement).attributes.delete(name);\n }\n\n getAttribute(element: Element, name: string): string | null {\n return (element as unknown as ServerElement).attributes.get(name) ?? null;\n }\n\n setProperty(element: Element, name: string, value: unknown): void {\n (element as unknown as ServerElement).properties.set(name, value);\n }\n\n setTextContent(node: Node, text: string): void {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n const el = n as ServerElement | ServerFragment;\n el.children.length = 0;\n const t = new ServerText(text);\n t.parent = el;\n el.children.push(t);\n } else if (n.kind === 'text') {\n (n as ServerText).data = text;\n }\n }\n\n getTextContent(node: Node): string | null {\n const n = asServer(node);\n if (n.kind === 'text') return (n as ServerText).data;\n if (n.kind === 'element' || n.kind === 'fragment') {\n let out = '';\n for (const c of (n as ServerElement | ServerFragment).children) {\n out += this.getTextContent(c as unknown as Node) ?? '';\n }\n return out;\n }\n return null;\n }\n\n // Server nodes never dispatch events — listeners are a no-op on the server.\n addEventListener(): void {\n /* no-op on the server */\n }\n removeEventListener(): void {\n /* no-op on the server */\n }\n\n querySelector(): Element | null {\n return null;\n }\n querySelectorAll(): NodeListOf<Element> {\n return [] as unknown as NodeListOf<Element>;\n }\n getElementById(): Element | null {\n return null;\n }\n\n focus(): void {\n // No focus concept on the server — intentional no-op (SSR-safe).\n }\n\n body(): Element | null {\n // No document on the server — portals degrade to inline rendering.\n return null;\n }\n\n activeElement(): Element | null {\n return null;\n }\n\n contains(_ancestor: Element, _node: Node): boolean {\n return false;\n }\n\n matches(_element: Element, _selector: string): boolean {\n return false;\n }\n\n isElement(node: Node): node is Element {\n return asServer(node).kind === 'element';\n }\n\n isTextNode(node: Node): node is Text {\n return asServer(node).kind === 'text';\n }\n\n tagName(element: Element): string {\n return (element as unknown as ServerElement).tagName;\n }\n\n parentNode(node: Node): Node | null {\n return (asServer(node).parent as unknown as Node | null) ?? null;\n }\n\n nextSibling(node: Node): Node | null {\n const n = asServer(node);\n const parent = n.parent;\n if (parent === null) return null;\n const idx = parent.children.indexOf(n);\n if (idx === -1 || idx + 1 >= parent.children.length) return null;\n return parent.children[idx + 1] as unknown as Node;\n }\n\n firstChild(node: Node): Node | null {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n const el = n as ServerElement | ServerFragment;\n return (el.children[0] as unknown as Node) ?? null;\n }\n return null;\n }\n\n childNodes(node: Node): Node[] {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n return (n as ServerElement | ServerFragment).children as unknown as Node[];\n }\n return [];\n }\n\n // ── Server-only ────────────────────────────────────────────────────────────\n\n /** Serialize a node's children (\"inner HTML\") to an HTML string. */\n serializeInner(node: Node): string {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n return serializeChildren(n as ServerElement | ServerFragment);\n }\n return '';\n }\n\n /** Serialize a node (including itself) to an HTML string. */\n serializeOuter(node: Node): string {\n return serializeServerNode(asServer(node));\n }\n}\n\n// `/* @__PURE__ */`: this singleton is a convenience export only (no internal\n// runtime path references it). Marking construction pure lets bundlers drop it —\n// and with it the whole server serializer chain (serializeServerNode/escape/\n// VOID_ELEMENTS) — out of client bundles that never import SSR. Without this,\n// the un-annotated `new` is treated as a side effect and retained everywhere.\nexport const serverDOMAdapter = /* @__PURE__ */ new ServerDOMAdapter();\n","/**\n * Focus helpers built on the {@link DOMAdapter} abstraction.\n *\n * These are the minimal, genuinely-useful focus operations an app needs:\n * focus a specific element (e.g. the first field when a route or modal opens)\n * or focus the first focusable element inside a container (e.g. move focus\n * into a dialog). Both go through the adapter, so they are no-ops on the server\n * (`ServerDOMAdapter.querySelector` returns null / `focus` does nothing) and\n * therefore safe to call from universal code.\n */\n\nimport type { DOMAdapter } from './adapter.js';\n\n/** Default selector for natively focusable / tabbable elements. */\nexport const FOCUSABLE_SELECTOR =\n 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * Focus the element with the given id, scoped to `root`.\n * Returns true if an element was found and focused.\n */\nexport function focusById(dom: DOMAdapter, root: Element | Document, id: string): boolean {\n const el = dom.querySelector(root, `[id=\"${id}\"]`);\n if (el === null) return false;\n dom.focus(el);\n return true;\n}\n\n/**\n * Focus the first focusable element inside `container`.\n * Returns true if a focusable element was found and focused.\n */\nexport function focusFirst(\n dom: DOMAdapter,\n container: Element | Document,\n selector: string = FOCUSABLE_SELECTOR,\n): boolean {\n const el = dom.querySelector(container, selector);\n if (el === null) return false;\n dom.focus(el);\n return true;\n}\n\n/**\n * Ordered list of focusable/tabbable descendants of `container`.\n * Re-checks each candidate against the selector so elements disabled after the\n * initial query (e.g. a button toggled to `disabled`) are excluded.\n */\nexport function getFocusable(\n dom: DOMAdapter,\n container: Element,\n selector: string = FOCUSABLE_SELECTOR,\n): Element[] {\n return Array.from(dom.querySelectorAll(container, selector)).filter((el) =>\n dom.matches(el, selector),\n );\n}\n\n/**\n * Capture the currently-focused element so it can be restored later (e.g. when\n * a dialog closes). Returns null on the server or when nothing is focused.\n */\nexport function saveFocus(dom: DOMAdapter): Element | null {\n return dom.activeElement();\n}\n\n/** Restore focus to a previously {@link saveFocus}-d element. No-op if null. */\nexport function restoreFocus(dom: DOMAdapter, saved: Element | null): void {\n if (saved !== null) dom.focus(saved);\n}\n\n/**\n * Move focus into `container` on open: the element with id `initialFocusId` if\n * given and present, otherwise the first focusable element. Server-safe no-op.\n */\nexport function focusInitial(\n dom: DOMAdapter,\n container: Element,\n initialFocusId?: string,\n): void {\n if (initialFocusId !== undefined && focusById(dom, container, initialFocusId)) return;\n focusFirst(dom, container);\n}\n\n/**\n * Trap Tab / Shift+Tab focus within `container` (wrap-around at both ends).\n * Attaches a keydown listener to the container and returns a cleanup function\n * that detaches it. Server-safe: `addEventListener` is a no-op, and the returned\n * cleanup is still callable.\n */\nexport function trapFocus(dom: DOMAdapter, container: Element): () => void {\n const onKeydown = ((event: KeyboardEvent): void => {\n if (event.key !== 'Tab') return;\n const items = getFocusable(dom, container);\n if (items.length === 0) {\n event.preventDefault();\n return;\n }\n const first = items[0]!;\n const last = items[items.length - 1]!;\n const active = dom.activeElement();\n if (active === null || !dom.contains(container, active)) {\n event.preventDefault();\n dom.focus(first);\n } else if (event.shiftKey && active === first) {\n event.preventDefault();\n dom.focus(last);\n } else if (!event.shiftKey && active === last) {\n event.preventDefault();\n dom.focus(first);\n }\n }) as EventListener;\n dom.addEventListener(container, 'keydown', onKeydown);\n return () => dom.removeEventListener(container, 'keydown', onKeydown);\n}\n\n/**\n * Modal containment: if focus moves to an element outside `container`, redirect\n * it back inside. Listens on the document body (focusin bubbles there) and\n * returns a cleanup function. Server-safe no-op (body() is null).\n */\nexport function containFocus(dom: DOMAdapter, container: Element): () => void {\n const body = dom.body();\n if (body === null) return () => {};\n const onFocusIn = ((event: FocusEvent): void => {\n const target = event.target as Node | null;\n if (target !== null && !dom.contains(container, target)) {\n focusFirst(dom, container);\n }\n }) as EventListener;\n dom.addEventListener(body, 'focusin', onFocusIn);\n return () => dom.removeEventListener(body, 'focusin', onFocusIn);\n}\n\n/**\n * Invoke `handler` when Escape is pressed while focus is within `target`.\n * Returns a cleanup function. Server-safe no-op.\n */\nexport function onEscape(dom: DOMAdapter, target: Element, handler: () => void): () => void {\n const onKeydown = ((event: KeyboardEvent): void => {\n if (event.key === 'Escape') handler();\n }) as EventListener;\n dom.addEventListener(target, 'keydown', onKeydown);\n return () => dom.removeEventListener(target, 'keydown', onKeydown);\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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AI,SAAS,WAAW,MAAM,GAAG;AACvD,YAAM,eAAe;AACrB,UAAI,MAAM,KAAK;AAAA,IACjB,WAAW,MAAM,YAAY,WAAW,OAAO;AAC7C,YAAM,eAAe;AACrB,UAAI,MAAM,IAAI;AAAA,IAChB,WAAW,CAAC,MAAM,YAAY,WAAW,MAAM;AAC7C,YAAM,eAAe;AACrB,UAAI,MAAM,KAAK;AAAA,IACjB;AAAA,EACF;AACA,MAAI,iBAAiB,WAAW,WAAW,SAAS;AACpD,SAAO,MAAM,IAAI,oBAAoB,WAAW,WAAW,SAAS;AACtE;AAOO,SAAS,aAAa,KAAiB,WAAgC;AAC5E,QAAM,OAAO,IAAI,KAAK;AACtB,MAAI,SAAS,KAAM,QAAO,MAAM;AAAA,EAAC;AACjC,QAAM,YAAa,CAAC,UAA4B;AAC9C,UAAM,SAAS,MAAM;AACrB,QAAI,WAAW,QAAQ,CAAC,IAAI,SAAS,WAAW,MAAM,GAAG;AACvD,iBAAW,KAAK,SAAS;AAAA,IAC3B;AAAA,EACF;AACA,MAAI,iBAAiB,MAAM,WAAW,SAAS;AAC/C,SAAO,MAAM,IAAI,oBAAoB,MAAM,WAAW,SAAS;AACjE;AAMO,SAAS,SAAS,KAAiB,QAAiB,SAAiC;AAC1F,QAAM,YAAa,CAAC,UAA+B;AACjD,QAAI,MAAM,QAAQ,SAAU,SAAQ;AAAA,EACtC;AACA,MAAI,iBAAiB,QAAQ,WAAW,SAAS;AACjD,SAAO,MAAM,IAAI,oBAAoB,QAAQ,WAAW,SAAS;AACnE;","names":[]}
package/dist/index.d.cts CHANGED
@@ -36,6 +36,18 @@ interface DOMAdapter {
36
36
  * focus) this is a safe no-op, keeping focus management SSR-compatible.
37
37
  */
38
38
  focus(element: Element): void;
39
+ /**
40
+ * The document body — the default mount target for portals/overlays. Returns
41
+ * null on the server (no document), which is what makes portal SSR degrade to
42
+ * inline rendering and focus management degrade to a no-op.
43
+ */
44
+ body(): Element | null;
45
+ /** The currently focused element, or null on the server / when none is focused. */
46
+ activeElement(): Element | null;
47
+ /** True if `ancestor` contains `node` (inclusive). Always false on the server. */
48
+ contains(ancestor: Element, node: Node): boolean;
49
+ /** True if `element` matches the given CSS selector. Always false on the server. */
50
+ matches(element: Element, selector: string): boolean;
39
51
  isElement(node: Node): node is Element;
40
52
  isTextNode(node: Node): node is Text;
41
53
  /** Lower-cased tag name of an element (e.g. "div", "h1"). */
@@ -73,6 +85,10 @@ declare class BrowserDOMAdapter implements DOMAdapter {
73
85
  querySelectorAll(root: Element | Document, selector: string): NodeListOf<Element>;
74
86
  getElementById(id: string): Element | null;
75
87
  focus(element: Element): void;
88
+ body(): Element | null;
89
+ activeElement(): Element | null;
90
+ contains(ancestor: Element, node: Node): boolean;
91
+ matches(element: Element, selector: string): boolean;
76
92
  isElement(node: Node): node is Element;
77
93
  isTextNode(node: Node): node is Text;
78
94
  tagName(element: Element): string;
@@ -210,6 +226,10 @@ declare class ServerDOMAdapter implements DOMAdapter {
210
226
  querySelectorAll(): NodeListOf<Element>;
211
227
  getElementById(): Element | null;
212
228
  focus(): void;
229
+ body(): Element | null;
230
+ activeElement(): Element | null;
231
+ contains(_ancestor: Element, _node: Node): boolean;
232
+ matches(_element: Element, _selector: string): boolean;
213
233
  isElement(node: Node): node is Element;
214
234
  isTextNode(node: Node): node is Text;
215
235
  tagName(element: Element): string;
@@ -247,5 +267,41 @@ declare function focusById(dom: DOMAdapter, root: Element | Document, id: string
247
267
  * Returns true if a focusable element was found and focused.
248
268
  */
249
269
  declare function focusFirst(dom: DOMAdapter, container: Element | Document, selector?: string): boolean;
270
+ /**
271
+ * Ordered list of focusable/tabbable descendants of `container`.
272
+ * Re-checks each candidate against the selector so elements disabled after the
273
+ * initial query (e.g. a button toggled to `disabled`) are excluded.
274
+ */
275
+ declare function getFocusable(dom: DOMAdapter, container: Element, selector?: string): Element[];
276
+ /**
277
+ * Capture the currently-focused element so it can be restored later (e.g. when
278
+ * a dialog closes). Returns null on the server or when nothing is focused.
279
+ */
280
+ declare function saveFocus(dom: DOMAdapter): Element | null;
281
+ /** Restore focus to a previously {@link saveFocus}-d element. No-op if null. */
282
+ declare function restoreFocus(dom: DOMAdapter, saved: Element | null): void;
283
+ /**
284
+ * Move focus into `container` on open: the element with id `initialFocusId` if
285
+ * given and present, otherwise the first focusable element. Server-safe no-op.
286
+ */
287
+ declare function focusInitial(dom: DOMAdapter, container: Element, initialFocusId?: string): void;
288
+ /**
289
+ * Trap Tab / Shift+Tab focus within `container` (wrap-around at both ends).
290
+ * Attaches a keydown listener to the container and returns a cleanup function
291
+ * that detaches it. Server-safe: `addEventListener` is a no-op, and the returned
292
+ * cleanup is still callable.
293
+ */
294
+ declare function trapFocus(dom: DOMAdapter, container: Element): () => void;
295
+ /**
296
+ * Modal containment: if focus moves to an element outside `container`, redirect
297
+ * it back inside. Listens on the document body (focusin bubbles there) and
298
+ * returns a cleanup function. Server-safe no-op (body() is null).
299
+ */
300
+ declare function containFocus(dom: DOMAdapter, container: Element): () => void;
301
+ /**
302
+ * Invoke `handler` when Escape is pressed while focus is within `target`.
303
+ * Returns a cleanup function. Server-safe no-op.
304
+ */
305
+ declare function onEscape(dom: DOMAdapter, target: Element, handler: () => void): () => void;
250
306
 
251
- export { BrowserDOMAdapter, type DOMAdapter, FOCUSABLE_SELECTOR, ServerComment, ServerDOMAdapter, ServerElement, ServerFragment, type ServerNode, type ServerNodeKind, type ServerParent, ServerRawHTML, ServerStyle, ServerText, browserDOMAdapter, escapeHtmlAttr, escapeHtmlText, focusById, focusFirst, serializeChildren, serializeServerNode, serverDOMAdapter };
307
+ export { BrowserDOMAdapter, type DOMAdapter, FOCUSABLE_SELECTOR, ServerComment, ServerDOMAdapter, ServerElement, ServerFragment, type ServerNode, type ServerNodeKind, type ServerParent, ServerRawHTML, ServerStyle, ServerText, browserDOMAdapter, containFocus, escapeHtmlAttr, escapeHtmlText, focusById, focusFirst, focusInitial, getFocusable, onEscape, restoreFocus, saveFocus, serializeChildren, serializeServerNode, serverDOMAdapter, trapFocus };
package/dist/index.d.ts CHANGED
@@ -36,6 +36,18 @@ interface DOMAdapter {
36
36
  * focus) this is a safe no-op, keeping focus management SSR-compatible.
37
37
  */
38
38
  focus(element: Element): void;
39
+ /**
40
+ * The document body — the default mount target for portals/overlays. Returns
41
+ * null on the server (no document), which is what makes portal SSR degrade to
42
+ * inline rendering and focus management degrade to a no-op.
43
+ */
44
+ body(): Element | null;
45
+ /** The currently focused element, or null on the server / when none is focused. */
46
+ activeElement(): Element | null;
47
+ /** True if `ancestor` contains `node` (inclusive). Always false on the server. */
48
+ contains(ancestor: Element, node: Node): boolean;
49
+ /** True if `element` matches the given CSS selector. Always false on the server. */
50
+ matches(element: Element, selector: string): boolean;
39
51
  isElement(node: Node): node is Element;
40
52
  isTextNode(node: Node): node is Text;
41
53
  /** Lower-cased tag name of an element (e.g. "div", "h1"). */
@@ -73,6 +85,10 @@ declare class BrowserDOMAdapter implements DOMAdapter {
73
85
  querySelectorAll(root: Element | Document, selector: string): NodeListOf<Element>;
74
86
  getElementById(id: string): Element | null;
75
87
  focus(element: Element): void;
88
+ body(): Element | null;
89
+ activeElement(): Element | null;
90
+ contains(ancestor: Element, node: Node): boolean;
91
+ matches(element: Element, selector: string): boolean;
76
92
  isElement(node: Node): node is Element;
77
93
  isTextNode(node: Node): node is Text;
78
94
  tagName(element: Element): string;
@@ -210,6 +226,10 @@ declare class ServerDOMAdapter implements DOMAdapter {
210
226
  querySelectorAll(): NodeListOf<Element>;
211
227
  getElementById(): Element | null;
212
228
  focus(): void;
229
+ body(): Element | null;
230
+ activeElement(): Element | null;
231
+ contains(_ancestor: Element, _node: Node): boolean;
232
+ matches(_element: Element, _selector: string): boolean;
213
233
  isElement(node: Node): node is Element;
214
234
  isTextNode(node: Node): node is Text;
215
235
  tagName(element: Element): string;
@@ -247,5 +267,41 @@ declare function focusById(dom: DOMAdapter, root: Element | Document, id: string
247
267
  * Returns true if a focusable element was found and focused.
248
268
  */
249
269
  declare function focusFirst(dom: DOMAdapter, container: Element | Document, selector?: string): boolean;
270
+ /**
271
+ * Ordered list of focusable/tabbable descendants of `container`.
272
+ * Re-checks each candidate against the selector so elements disabled after the
273
+ * initial query (e.g. a button toggled to `disabled`) are excluded.
274
+ */
275
+ declare function getFocusable(dom: DOMAdapter, container: Element, selector?: string): Element[];
276
+ /**
277
+ * Capture the currently-focused element so it can be restored later (e.g. when
278
+ * a dialog closes). Returns null on the server or when nothing is focused.
279
+ */
280
+ declare function saveFocus(dom: DOMAdapter): Element | null;
281
+ /** Restore focus to a previously {@link saveFocus}-d element. No-op if null. */
282
+ declare function restoreFocus(dom: DOMAdapter, saved: Element | null): void;
283
+ /**
284
+ * Move focus into `container` on open: the element with id `initialFocusId` if
285
+ * given and present, otherwise the first focusable element. Server-safe no-op.
286
+ */
287
+ declare function focusInitial(dom: DOMAdapter, container: Element, initialFocusId?: string): void;
288
+ /**
289
+ * Trap Tab / Shift+Tab focus within `container` (wrap-around at both ends).
290
+ * Attaches a keydown listener to the container and returns a cleanup function
291
+ * that detaches it. Server-safe: `addEventListener` is a no-op, and the returned
292
+ * cleanup is still callable.
293
+ */
294
+ declare function trapFocus(dom: DOMAdapter, container: Element): () => void;
295
+ /**
296
+ * Modal containment: if focus moves to an element outside `container`, redirect
297
+ * it back inside. Listens on the document body (focusin bubbles there) and
298
+ * returns a cleanup function. Server-safe no-op (body() is null).
299
+ */
300
+ declare function containFocus(dom: DOMAdapter, container: Element): () => void;
301
+ /**
302
+ * Invoke `handler` when Escape is pressed while focus is within `target`.
303
+ * Returns a cleanup function. Server-safe no-op.
304
+ */
305
+ declare function onEscape(dom: DOMAdapter, target: Element, handler: () => void): () => void;
250
306
 
251
- export { BrowserDOMAdapter, type DOMAdapter, FOCUSABLE_SELECTOR, ServerComment, ServerDOMAdapter, ServerElement, ServerFragment, type ServerNode, type ServerNodeKind, type ServerParent, ServerRawHTML, ServerStyle, ServerText, browserDOMAdapter, escapeHtmlAttr, escapeHtmlText, focusById, focusFirst, serializeChildren, serializeServerNode, serverDOMAdapter };
307
+ export { BrowserDOMAdapter, type DOMAdapter, FOCUSABLE_SELECTOR, ServerComment, ServerDOMAdapter, ServerElement, ServerFragment, type ServerNode, type ServerNodeKind, type ServerParent, ServerRawHTML, ServerStyle, ServerText, browserDOMAdapter, containFocus, escapeHtmlAttr, escapeHtmlText, focusById, focusFirst, focusInitial, getFocusable, onEscape, restoreFocus, saveFocus, serializeChildren, serializeServerNode, serverDOMAdapter, trapFocus };
package/dist/index.js CHANGED
@@ -63,6 +63,18 @@ var BrowserDOMAdapter = class {
63
63
  focus(element) {
64
64
  element.focus?.();
65
65
  }
66
+ body() {
67
+ return document.body ?? null;
68
+ }
69
+ activeElement() {
70
+ return document.activeElement ?? null;
71
+ }
72
+ contains(ancestor, node) {
73
+ return ancestor.contains(node);
74
+ }
75
+ matches(element, selector) {
76
+ return typeof element.matches === "function" && element.matches(selector);
77
+ }
66
78
  isElement(node) {
67
79
  return node.nodeType === Node.ELEMENT_NODE;
68
80
  }
@@ -430,6 +442,18 @@ var ServerDOMAdapter = class {
430
442
  }
431
443
  focus() {
432
444
  }
445
+ body() {
446
+ return null;
447
+ }
448
+ activeElement() {
449
+ return null;
450
+ }
451
+ contains(_ancestor, _node) {
452
+ return false;
453
+ }
454
+ matches(_element, _selector) {
455
+ return false;
456
+ }
433
457
  isElement(node) {
434
458
  return asServer(node).kind === "element";
435
459
  }
@@ -495,6 +519,66 @@ function focusFirst(dom, container, selector = FOCUSABLE_SELECTOR) {
495
519
  dom.focus(el);
496
520
  return true;
497
521
  }
522
+ function getFocusable(dom, container, selector = FOCUSABLE_SELECTOR) {
523
+ return Array.from(dom.querySelectorAll(container, selector)).filter(
524
+ (el) => dom.matches(el, selector)
525
+ );
526
+ }
527
+ function saveFocus(dom) {
528
+ return dom.activeElement();
529
+ }
530
+ function restoreFocus(dom, saved) {
531
+ if (saved !== null) dom.focus(saved);
532
+ }
533
+ function focusInitial(dom, container, initialFocusId) {
534
+ if (initialFocusId !== void 0 && focusById(dom, container, initialFocusId)) return;
535
+ focusFirst(dom, container);
536
+ }
537
+ function trapFocus(dom, container) {
538
+ const onKeydown = (event) => {
539
+ if (event.key !== "Tab") return;
540
+ const items = getFocusable(dom, container);
541
+ if (items.length === 0) {
542
+ event.preventDefault();
543
+ return;
544
+ }
545
+ const first = items[0];
546
+ const last = items[items.length - 1];
547
+ const active = dom.activeElement();
548
+ if (active === null || !dom.contains(container, active)) {
549
+ event.preventDefault();
550
+ dom.focus(first);
551
+ } else if (event.shiftKey && active === first) {
552
+ event.preventDefault();
553
+ dom.focus(last);
554
+ } else if (!event.shiftKey && active === last) {
555
+ event.preventDefault();
556
+ dom.focus(first);
557
+ }
558
+ };
559
+ dom.addEventListener(container, "keydown", onKeydown);
560
+ return () => dom.removeEventListener(container, "keydown", onKeydown);
561
+ }
562
+ function containFocus(dom, container) {
563
+ const body = dom.body();
564
+ if (body === null) return () => {
565
+ };
566
+ const onFocusIn = (event) => {
567
+ const target = event.target;
568
+ if (target !== null && !dom.contains(container, target)) {
569
+ focusFirst(dom, container);
570
+ }
571
+ };
572
+ dom.addEventListener(body, "focusin", onFocusIn);
573
+ return () => dom.removeEventListener(body, "focusin", onFocusIn);
574
+ }
575
+ function onEscape(dom, target, handler) {
576
+ const onKeydown = (event) => {
577
+ if (event.key === "Escape") handler();
578
+ };
579
+ dom.addEventListener(target, "keydown", onKeydown);
580
+ return () => dom.removeEventListener(target, "keydown", onKeydown);
581
+ }
498
582
  export {
499
583
  BrowserDOMAdapter,
500
584
  FOCUSABLE_SELECTOR,
@@ -506,12 +590,19 @@ export {
506
590
  ServerStyle,
507
591
  ServerText,
508
592
  browserDOMAdapter,
593
+ containFocus,
509
594
  escapeHtmlAttr,
510
595
  escapeHtmlText,
511
596
  focusById,
512
597
  focusFirst,
598
+ focusInitial,
599
+ getFocusable,
600
+ onEscape,
601
+ restoreFocus,
602
+ saveFocus,
513
603
  serializeChildren,
514
604
  serializeServerNode,
515
- serverDOMAdapter
605
+ serverDOMAdapter,
606
+ trapFocus
516
607
  };
517
608
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/browser-adapter.ts","../src/server-node.ts","../src/server-adapter.ts","../src/focus.ts"],"sourcesContent":["/**\n * Browser implementation of DOMAdapter — delegates directly to browser APIs.\n */\n\nimport type { DOMAdapter } from './adapter.js';\n\nexport class BrowserDOMAdapter implements DOMAdapter {\n createElement(tag: string, ns?: string): Element {\n if (ns !== undefined) {\n return document.createElementNS(ns, tag);\n }\n return document.createElement(tag);\n }\n\n createTextNode(data: string): Text {\n return document.createTextNode(data);\n }\n\n createComment(data: string): Comment {\n return document.createComment(data);\n }\n\n createFragment(): DocumentFragment {\n return document.createDocumentFragment();\n }\n\n appendChild(parent: Node, child: Node): void {\n parent.appendChild(child);\n }\n\n insertBefore(parent: Node, child: Node, reference: Node | null): void {\n parent.insertBefore(child, reference);\n }\n\n removeChild(parent: Node, child: Node): void {\n parent.removeChild(child);\n }\n\n replaceChild(parent: Node, newChild: Node, oldChild: Node): void {\n parent.replaceChild(newChild, oldChild);\n }\n\n setAttribute(element: Element, name: string, value: string): void {\n element.setAttribute(name, value);\n }\n\n removeAttribute(element: Element, name: string): void {\n element.removeAttribute(name);\n }\n\n getAttribute(element: Element, name: string): string | null {\n return element.getAttribute(name);\n }\n\n setProperty(element: Element, name: string, value: unknown): void {\n (element as unknown as Record<string, unknown>)[name] = value;\n }\n\n setTextContent(node: Node, text: string): void {\n node.textContent = text;\n }\n\n getTextContent(node: Node): string | null {\n return node.textContent;\n }\n\n addEventListener(\n target: EventTarget,\n type: string,\n handler: EventListener,\n options?: AddEventListenerOptions,\n ): void {\n target.addEventListener(type, handler, options);\n }\n\n removeEventListener(\n target: EventTarget,\n type: string,\n handler: EventListener,\n options?: EventListenerOptions,\n ): void {\n target.removeEventListener(type, handler, options);\n }\n\n querySelector(root: Element | Document, selector: string): Element | null {\n return root.querySelector(selector);\n }\n\n querySelectorAll(root: Element | Document, selector: string): NodeListOf<Element> {\n return root.querySelectorAll(selector);\n }\n\n getElementById(id: string): Element | null {\n return document.getElementById(id);\n }\n\n focus(element: Element): void {\n (element as unknown as { focus?: () => void }).focus?.();\n }\n\n isElement(node: Node): node is Element {\n return node.nodeType === Node.ELEMENT_NODE;\n }\n\n isTextNode(node: Node): node is Text {\n return node.nodeType === Node.TEXT_NODE;\n }\n\n tagName(element: Element): string {\n return element.tagName.toLowerCase();\n }\n\n parentNode(node: Node): Node | null {\n return node.parentNode;\n }\n\n nextSibling(node: Node): Node | null {\n return node.nextSibling;\n }\n\n firstChild(node: Node): Node | null {\n return node.firstChild;\n }\n\n childNodes(node: Node): Node[] {\n return Array.from(node.childNodes);\n }\n}\n\n// `/* @__PURE__ */`: convenience singleton, unreferenced by internal runtime\n// paths. Marking construction pure lets bundlers drop it when unused instead of\n// retaining it (and the BrowserDOMAdapter class) as an import-time side effect.\nexport const browserDOMAdapter = /* @__PURE__ */ new BrowserDOMAdapter();\n","/**\n * Server-side DOM node model.\n *\n * A tiny, dependency-free tree of plain objects that mirrors just enough of the\n * browser DOM for StreetUI's renderer to build a tree on the server and\n * serialize it to an HTML string. There is NO browser global here — these are\n * ordinary classes usable in any JavaScript environment (Node, workers, tests).\n *\n * The renderer never touches these types directly; it goes through the\n * `DOMAdapter` interface, and `ServerDOMAdapter` translates adapter calls into\n * operations on this model.\n */\n\nexport type ServerNodeKind = 'element' | 'text' | 'comment' | 'fragment' | 'raw';\n\nexport interface ServerNode {\n readonly kind: ServerNodeKind;\n parent: ServerParent | null;\n}\n\nexport type ServerParent = ServerElement | ServerFragment;\n\n/** A minimal inline-style holder mirroring `element.style.setProperty`. */\nexport class ServerStyle {\n readonly declarations = new Map<string, string>();\n setProperty(name: string, value: string): void {\n this.declarations.set(name, value);\n }\n get isEmpty(): boolean {\n return this.declarations.size === 0;\n }\n toCss(): string {\n return [...this.declarations.entries()].map(([k, v]) => `${k}: ${v}`).join('; ');\n }\n}\n\nexport class ServerText implements ServerNode {\n readonly kind = 'text' as const;\n parent: ServerParent | null = null;\n data: string;\n constructor(data: string) {\n this.data = data;\n }\n}\n\nexport class ServerComment implements ServerNode {\n readonly kind = 'comment' as const;\n parent: ServerParent | null = null;\n data: string;\n constructor(data: string) {\n this.data = data;\n }\n}\n\nexport class ServerFragment implements ServerNode {\n readonly kind = 'fragment' as const;\n parent: ServerParent | null = null;\n readonly children: ServerNode[] = [];\n}\n\n/**\n * A pre-serialized, verbatim HTML fragment (v1.7 static SSR plan).\n *\n * Emitted for provably-static subtrees whose HTML the compiler-derived static\n * SSR plan already computed once. Serializing this node copies its stored\n * string directly — it allocates no ServerElement/ServerText, no attribute Map\n * and no children array for the collapsed subtree. The stored `html` is\n * produced by the exact same mount + serialize pipeline as the runtime path, so\n * the output is byte-identical (the v1.7 byte-identity gate proves this).\n *\n * This node is SSR-only: it is created solely via `ServerDOMAdapter.createRawHTML`\n * on the server render path and never appears in a browser build.\n */\nexport class ServerRawHTML implements ServerNode {\n readonly kind = 'raw' as const;\n parent: ServerParent | null = null;\n readonly html: string;\n constructor(html: string) {\n this.html = html;\n }\n}\n\nexport class ServerElement implements ServerNode {\n readonly kind = 'element' as const;\n parent: ServerParent | null = null;\n readonly tagName: string;\n readonly attributes = new Map<string, string>();\n readonly children: ServerNode[] = [];\n\n // Lazily-allocated stores. On the 10k-row SSR corpus ~0% of elements carry JS\n // properties or inline styles (measured, §5: 1 of 80,029 elements uses\n // `properties`, 0 use `style`), so eagerly allocating a `properties` Map plus\n // a `ServerStyle` (which itself holds a Map) per element wasted ~240k\n // allocations per /users render — all in the dominant mount phase. These are\n // created on first WRITE via the `properties`/`style` getters; the serializer\n // reads the raw `_properties`/`_style` fields so a READ never forces an\n // allocation. Output is byte-identical: an unset store previously serialized\n // to nothing (empty `properties.has(...)` / `style.isEmpty`), and a null store\n // is skipped the same way.\n _properties: Map<string, unknown> | null = null;\n _style: ServerStyle | null = null;\n\n constructor(tagName: string) {\n this.tagName = tagName.toLowerCase();\n }\n\n /** JS properties set via `setProperty` (e.g. input `value`, `checked`). Allocated on first access. */\n get properties(): Map<string, unknown> {\n return (this._properties ??= new Map());\n }\n\n /** Inline-style holder mirroring `element.style`. Allocated on first access. */\n get style(): ServerStyle {\n return (this._style ??= new ServerStyle());\n }\n}\n\n// ── HTML serialization ─────────────────────────────────────────────────────────\n\n/**\n * HTML \"void\" elements — self-closing, never given a closing tag or children.\n */\nconst VOID_ELEMENTS = new Set([\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\n 'link', 'meta', 'param', 'source', 'track', 'wbr',\n]);\n\n/**\n * Element properties that should be reflected into the serialized HTML so the\n * hydrated DOM carries the same initial state. `value`/`checked` matter for\n * form controls whose live state is a JS property, not an attribute.\n */\nconst SERIALIZED_PROPERTIES: Record<string, 'attr' | 'boolean'> = {\n value: 'attr',\n checked: 'boolean',\n selected: 'boolean',\n};\n\n/**\n * Precomputed `[name, kind]` pairs of SERIALIZED_PROPERTIES. Hoisted to module\n * scope so `serializeAttributes` does not allocate a fresh entries array for\n * every element serialized (measured hot: ~80k elements on the 10k-row route).\n */\nconst SERIALIZED_PROPERTY_ENTRIES: ReadonlyArray<readonly [string, 'attr' | 'boolean']> =\n Object.entries(SERIALIZED_PROPERTIES) as Array<[string, 'attr' | 'boolean']>;\n\n// Fast-path escaping. The chained `.replace(/…/g, …)` form makes 3–4 full\n// passes and allocates an intermediate string per pass even when nothing needs\n// escaping. These variants scan once and, in the overwhelmingly common case of\n// no special character, return the input unchanged (zero allocation). Output is\n// byte-identical to the chained form (verified over the real SSR corpus).\nconst TEXT_SPECIAL = /[&<>]/;\nconst ATTR_SPECIAL = /[&<>\"]/;\n\n/** Escape text node content. */\nexport function escapeHtmlText(value: string): string {\n if (!TEXT_SPECIAL.test(value)) return value;\n let out = '';\n let last = 0;\n for (let i = 0; i < value.length; i++) {\n let esc: string;\n switch (value.charCodeAt(i)) {\n case 38: esc = '&amp;'; break; // &\n case 60: esc = '&lt;'; break; // <\n case 62: esc = '&gt;'; break; // >\n default: continue;\n }\n out += value.slice(last, i) + esc;\n last = i + 1;\n }\n return out + value.slice(last);\n}\n\n/** Escape a double-quoted attribute value. */\nexport function escapeHtmlAttr(value: string): string {\n if (!ATTR_SPECIAL.test(value)) return value;\n let out = '';\n let last = 0;\n for (let i = 0; i < value.length; i++) {\n let esc: string;\n switch (value.charCodeAt(i)) {\n case 38: esc = '&amp;'; break; // &\n case 60: esc = '&lt;'; break; // <\n case 62: esc = '&gt;'; break; // >\n case 34: esc = '&quot;'; break; // \"\n default: continue;\n }\n out += value.slice(last, i) + esc;\n last = i + 1;\n }\n return out + value.slice(last);\n}\n\nfunction serializeAttributes(el: ServerElement): string {\n const parts: string[] = [];\n\n for (const [name, value] of el.attributes) {\n if (value === '') {\n parts.push(` ${name}`);\n } else {\n parts.push(` ${name}=\"${escapeHtmlAttr(value)}\"`);\n }\n }\n\n // Read the raw backing field (may be null): most elements have no JS\n // properties, so skipping the whole loop avoids touching a store that was\n // never allocated (§5).\n const props = el._properties;\n if (props !== null) {\n for (const [name, kind] of SERIALIZED_PROPERTY_ENTRIES) {\n if (!props.has(name)) continue;\n if (el.attributes.has(name)) continue; // an explicit attribute already won\n const raw = props.get(name);\n if (kind === 'boolean') {\n if (raw === true) parts.push(` ${name}`);\n } else {\n if (raw !== undefined && raw !== null) {\n parts.push(` ${name}=\"${escapeHtmlAttr(String(raw))}\"`);\n }\n }\n }\n }\n\n const style = el._style;\n if (style !== null && !style.isEmpty && !el.attributes.has('style')) {\n parts.push(` style=\"${escapeHtmlAttr(style.toCss())}\"`);\n }\n\n return parts.join('');\n}\n\n/** Serialize a single server node (element/text/comment/fragment/raw) to HTML. */\nexport function serializeServerNode(node: ServerNode): string {\n switch (node.kind) {\n case 'text':\n return escapeHtmlText((node as ServerText).data);\n case 'comment':\n return `<!--${(node as ServerComment).data}-->`;\n case 'fragment':\n return serializeChildren(node as ServerFragment);\n case 'raw':\n // Verbatim: the string was produced by this same serializer for a static\n // subtree, so it is already correctly escaped. Copy it as-is (§8).\n return (node as ServerRawHTML).html;\n case 'element': {\n const el = node as ServerElement;\n const tag = el.tagName;\n const attrs = serializeAttributes(el);\n if (VOID_ELEMENTS.has(tag)) {\n return `<${tag}${attrs}>`;\n }\n return `<${tag}${attrs}>${serializeChildren(el)}</${tag}>`;\n }\n }\n}\n\n/** Serialize the children of an element or fragment (its \"inner HTML\"). */\nexport function serializeChildren(node: ServerElement | ServerFragment): string {\n let out = '';\n for (const child of node.children) {\n out += serializeServerNode(child);\n }\n return out;\n}\n","/**\n * Server implementation of `DOMAdapter`.\n *\n * Builds a lightweight in-memory tree (see `server-node.ts`) instead of touching\n * a real browser DOM, then lets the caller serialize it to an HTML string. It is\n * completely free of browser globals, so the exact same renderer that runs in\n * the browser can produce HTML on the server.\n *\n * The `DOMAdapter` interface is typed against the lib DOM types (`Element`,\n * `Node`, `Text`, …). Our server nodes structurally stand in for those at\n * runtime, so the boundary uses `as unknown as` casts in one place. Everything\n * inside operates on the real server-node model.\n */\n\nimport type { DOMAdapter } from './adapter.js';\nimport {\n ServerElement,\n ServerText,\n ServerComment,\n ServerFragment,\n ServerRawHTML,\n serializeChildren,\n serializeServerNode,\n type ServerNode,\n type ServerParent,\n} from './server-node.js';\n\nfunction asServer(node: unknown): ServerNode {\n return node as unknown as ServerNode;\n}\nfunction asParent(node: unknown): ServerParent {\n return node as unknown as ServerParent;\n}\n\nexport class ServerDOMAdapter implements DOMAdapter {\n createElement(tag: string, _ns?: string): Element {\n return new ServerElement(tag) as unknown as Element;\n }\n\n createTextNode(data: string): Text {\n return new ServerText(data) as unknown as Text;\n }\n\n createComment(data: string): Comment {\n return new ServerComment(data) as unknown as Comment;\n }\n\n createFragment(): DocumentFragment {\n return new ServerFragment() as unknown as DocumentFragment;\n }\n\n /**\n * Create a verbatim pre-serialized HTML node (v1.7 static SSR plan, §6).\n * Server-only: the browser adapter does not implement this, and the renderer\n * fast path only invokes it when a static SSR plan is present (SSR). The\n * stored HTML was produced by this same serializer, so it is emitted as-is.\n */\n createRawHTML(html: string): Node {\n return new ServerRawHTML(html) as unknown as Node;\n }\n\n appendChild(parent: Node, child: Node): void {\n const p = asParent(parent);\n const c = asServer(child);\n this._detach(c);\n c.parent = p;\n p.children.push(c);\n }\n\n insertBefore(parent: Node, child: Node, reference: Node | null): void {\n const p = asParent(parent);\n const c = asServer(child);\n this._detach(c);\n c.parent = p;\n if (reference === null) {\n p.children.push(c);\n return;\n }\n const ref = asServer(reference);\n const idx = p.children.indexOf(ref);\n if (idx === -1) p.children.push(c);\n else p.children.splice(idx, 0, c);\n }\n\n removeChild(parent: Node, child: Node): void {\n const p = asParent(parent);\n const c = asServer(child);\n const idx = p.children.indexOf(c);\n if (idx !== -1) {\n p.children.splice(idx, 1);\n c.parent = null;\n }\n }\n\n replaceChild(parent: Node, newChild: Node, oldChild: Node): void {\n const p = asParent(parent);\n const nc = asServer(newChild);\n const oc = asServer(oldChild);\n const idx = p.children.indexOf(oc);\n if (idx === -1) return;\n this._detach(nc);\n nc.parent = p;\n p.children.splice(idx, 1, nc);\n oc.parent = null;\n }\n\n private _detach(node: ServerNode): void {\n if (node.parent !== null) {\n const siblings = node.parent.children;\n const idx = siblings.indexOf(node);\n if (idx !== -1) siblings.splice(idx, 1);\n node.parent = null;\n }\n }\n\n setAttribute(element: Element, name: string, value: string): void {\n (element as unknown as ServerElement).attributes.set(name, value);\n }\n\n removeAttribute(element: Element, name: string): void {\n (element as unknown as ServerElement).attributes.delete(name);\n }\n\n getAttribute(element: Element, name: string): string | null {\n return (element as unknown as ServerElement).attributes.get(name) ?? null;\n }\n\n setProperty(element: Element, name: string, value: unknown): void {\n (element as unknown as ServerElement).properties.set(name, value);\n }\n\n setTextContent(node: Node, text: string): void {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n const el = n as ServerElement | ServerFragment;\n el.children.length = 0;\n const t = new ServerText(text);\n t.parent = el;\n el.children.push(t);\n } else if (n.kind === 'text') {\n (n as ServerText).data = text;\n }\n }\n\n getTextContent(node: Node): string | null {\n const n = asServer(node);\n if (n.kind === 'text') return (n as ServerText).data;\n if (n.kind === 'element' || n.kind === 'fragment') {\n let out = '';\n for (const c of (n as ServerElement | ServerFragment).children) {\n out += this.getTextContent(c as unknown as Node) ?? '';\n }\n return out;\n }\n return null;\n }\n\n // Server nodes never dispatch events — listeners are a no-op on the server.\n addEventListener(): void {\n /* no-op on the server */\n }\n removeEventListener(): void {\n /* no-op on the server */\n }\n\n querySelector(): Element | null {\n return null;\n }\n querySelectorAll(): NodeListOf<Element> {\n return [] as unknown as NodeListOf<Element>;\n }\n getElementById(): Element | null {\n return null;\n }\n\n focus(): void {\n // No focus concept on the server — intentional no-op (SSR-safe).\n }\n\n isElement(node: Node): node is Element {\n return asServer(node).kind === 'element';\n }\n\n isTextNode(node: Node): node is Text {\n return asServer(node).kind === 'text';\n }\n\n tagName(element: Element): string {\n return (element as unknown as ServerElement).tagName;\n }\n\n parentNode(node: Node): Node | null {\n return (asServer(node).parent as unknown as Node | null) ?? null;\n }\n\n nextSibling(node: Node): Node | null {\n const n = asServer(node);\n const parent = n.parent;\n if (parent === null) return null;\n const idx = parent.children.indexOf(n);\n if (idx === -1 || idx + 1 >= parent.children.length) return null;\n return parent.children[idx + 1] as unknown as Node;\n }\n\n firstChild(node: Node): Node | null {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n const el = n as ServerElement | ServerFragment;\n return (el.children[0] as unknown as Node) ?? null;\n }\n return null;\n }\n\n childNodes(node: Node): Node[] {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n return (n as ServerElement | ServerFragment).children as unknown as Node[];\n }\n return [];\n }\n\n // ── Server-only ────────────────────────────────────────────────────────────\n\n /** Serialize a node's children (\"inner HTML\") to an HTML string. */\n serializeInner(node: Node): string {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n return serializeChildren(n as ServerElement | ServerFragment);\n }\n return '';\n }\n\n /** Serialize a node (including itself) to an HTML string. */\n serializeOuter(node: Node): string {\n return serializeServerNode(asServer(node));\n }\n}\n\n// `/* @__PURE__ */`: this singleton is a convenience export only (no internal\n// runtime path references it). Marking construction pure lets bundlers drop it —\n// and with it the whole server serializer chain (serializeServerNode/escape/\n// VOID_ELEMENTS) — out of client bundles that never import SSR. Without this,\n// the un-annotated `new` is treated as a side effect and retained everywhere.\nexport const serverDOMAdapter = /* @__PURE__ */ new ServerDOMAdapter();\n","/**\n * Focus helpers built on the {@link DOMAdapter} abstraction.\n *\n * These are the minimal, genuinely-useful focus operations an app needs:\n * focus a specific element (e.g. the first field when a route or modal opens)\n * or focus the first focusable element inside a container (e.g. move focus\n * into a dialog). Both go through the adapter, so they are no-ops on the server\n * (`ServerDOMAdapter.querySelector` returns null / `focus` does nothing) and\n * therefore safe to call from universal code.\n */\n\nimport type { DOMAdapter } from './adapter.js';\n\n/** Default selector for natively focusable / tabbable elements. */\nexport const FOCUSABLE_SELECTOR =\n 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * Focus the element with the given id, scoped to `root`.\n * Returns true if an element was found and focused.\n */\nexport function focusById(dom: DOMAdapter, root: Element | Document, id: string): boolean {\n const el = dom.querySelector(root, `[id=\"${id}\"]`);\n if (el === null) return false;\n dom.focus(el);\n return true;\n}\n\n/**\n * Focus the first focusable element inside `container`.\n * Returns true if a focusable element was found and focused.\n */\nexport function focusFirst(\n dom: DOMAdapter,\n container: Element | Document,\n selector: string = FOCUSABLE_SELECTOR,\n): boolean {\n const el = dom.querySelector(container, selector);\n if (el === null) return false;\n dom.focus(el);\n return true;\n}\n"],"mappings":";AAMO,IAAM,oBAAN,MAA8C;AAAA,EACnD,cAAc,KAAa,IAAsB;AAC/C,QAAI,OAAO,QAAW;AACpB,aAAO,SAAS,gBAAgB,IAAI,GAAG;AAAA,IACzC;AACA,WAAO,SAAS,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I,SAAS,IAAI;AACvB,QAAI,EAAE,SAAS,aAAa,EAAE,SAAS,YAAY;AACjD,YAAM,KAAK;AACX,aAAQ,GAAG,SAAS,CAAC,KAAyB;AAAA,IAChD;AACA,WAAO;AAAA,EACT;AAAA,EAEA,WAAW,MAAoB;AAC7B,UAAM,IAAI,SAAS,IAAI;AACvB,QAAI,EAAE,SAAS,aAAa,EAAE,SAAS,YAAY;AACjD,aAAQ,EAAqC;AAAA,IAC/C;AACA,WAAO,CAAC;AAAA,EACV;AAAA;AAAA;AAAA,EAKA,eAAe,MAAoB;AACjC,UAAM,IAAI,SAAS,IAAI;AACvB,QAAI,EAAE,SAAS,aAAa,EAAE,SAAS,YAAY;AACjD,aAAO,kBAAkB,CAAmC;AAAA,IAC9D;AACA,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,eAAe,MAAoB;AACjC,WAAO,oBAAoB,SAAS,IAAI,CAAC;AAAA,EAC3C;AACF;AAOO,IAAM,mBAAmC,oBAAI,iBAAiB;;;ACrO9D,IAAM,qBACX;AAMK,SAAS,UAAU,KAAiB,MAA0B,IAAqB;AACxF,QAAM,KAAK,IAAI,cAAc,MAAM,QAAQ,EAAE,IAAI;AACjD,MAAI,OAAO,KAAM,QAAO;AACxB,MAAI,MAAM,EAAE;AACZ,SAAO;AACT;AAMO,SAAS,WACd,KACA,WACA,WAAmB,oBACV;AACT,QAAM,KAAK,IAAI,cAAc,WAAW,QAAQ;AAChD,MAAI,OAAO,KAAM,QAAO;AACxB,MAAI,MAAM,EAAE;AACZ,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/browser-adapter.ts","../src/server-node.ts","../src/server-adapter.ts","../src/focus.ts"],"sourcesContent":["/**\n * Browser implementation of DOMAdapter — delegates directly to browser APIs.\n */\n\nimport type { DOMAdapter } from './adapter.js';\n\nexport class BrowserDOMAdapter implements DOMAdapter {\n createElement(tag: string, ns?: string): Element {\n if (ns !== undefined) {\n return document.createElementNS(ns, tag);\n }\n return document.createElement(tag);\n }\n\n createTextNode(data: string): Text {\n return document.createTextNode(data);\n }\n\n createComment(data: string): Comment {\n return document.createComment(data);\n }\n\n createFragment(): DocumentFragment {\n return document.createDocumentFragment();\n }\n\n appendChild(parent: Node, child: Node): void {\n parent.appendChild(child);\n }\n\n insertBefore(parent: Node, child: Node, reference: Node | null): void {\n parent.insertBefore(child, reference);\n }\n\n removeChild(parent: Node, child: Node): void {\n parent.removeChild(child);\n }\n\n replaceChild(parent: Node, newChild: Node, oldChild: Node): void {\n parent.replaceChild(newChild, oldChild);\n }\n\n setAttribute(element: Element, name: string, value: string): void {\n element.setAttribute(name, value);\n }\n\n removeAttribute(element: Element, name: string): void {\n element.removeAttribute(name);\n }\n\n getAttribute(element: Element, name: string): string | null {\n return element.getAttribute(name);\n }\n\n setProperty(element: Element, name: string, value: unknown): void {\n (element as unknown as Record<string, unknown>)[name] = value;\n }\n\n setTextContent(node: Node, text: string): void {\n node.textContent = text;\n }\n\n getTextContent(node: Node): string | null {\n return node.textContent;\n }\n\n addEventListener(\n target: EventTarget,\n type: string,\n handler: EventListener,\n options?: AddEventListenerOptions,\n ): void {\n target.addEventListener(type, handler, options);\n }\n\n removeEventListener(\n target: EventTarget,\n type: string,\n handler: EventListener,\n options?: EventListenerOptions,\n ): void {\n target.removeEventListener(type, handler, options);\n }\n\n querySelector(root: Element | Document, selector: string): Element | null {\n return root.querySelector(selector);\n }\n\n querySelectorAll(root: Element | Document, selector: string): NodeListOf<Element> {\n return root.querySelectorAll(selector);\n }\n\n getElementById(id: string): Element | null {\n return document.getElementById(id);\n }\n\n focus(element: Element): void {\n (element as unknown as { focus?: () => void }).focus?.();\n }\n\n body(): Element | null {\n return document.body ?? null;\n }\n\n activeElement(): Element | null {\n return document.activeElement ?? null;\n }\n\n contains(ancestor: Element, node: Node): boolean {\n return ancestor.contains(node);\n }\n\n matches(element: Element, selector: string): boolean {\n return typeof element.matches === 'function' && element.matches(selector);\n }\n\n isElement(node: Node): node is Element {\n return node.nodeType === Node.ELEMENT_NODE;\n }\n\n isTextNode(node: Node): node is Text {\n return node.nodeType === Node.TEXT_NODE;\n }\n\n tagName(element: Element): string {\n return element.tagName.toLowerCase();\n }\n\n parentNode(node: Node): Node | null {\n return node.parentNode;\n }\n\n nextSibling(node: Node): Node | null {\n return node.nextSibling;\n }\n\n firstChild(node: Node): Node | null {\n return node.firstChild;\n }\n\n childNodes(node: Node): Node[] {\n return Array.from(node.childNodes);\n }\n}\n\n// `/* @__PURE__ */`: convenience singleton, unreferenced by internal runtime\n// paths. Marking construction pure lets bundlers drop it when unused instead of\n// retaining it (and the BrowserDOMAdapter class) as an import-time side effect.\nexport const browserDOMAdapter = /* @__PURE__ */ new BrowserDOMAdapter();\n","/**\n * Server-side DOM node model.\n *\n * A tiny, dependency-free tree of plain objects that mirrors just enough of the\n * browser DOM for StreetUI's renderer to build a tree on the server and\n * serialize it to an HTML string. There is NO browser global here — these are\n * ordinary classes usable in any JavaScript environment (Node, workers, tests).\n *\n * The renderer never touches these types directly; it goes through the\n * `DOMAdapter` interface, and `ServerDOMAdapter` translates adapter calls into\n * operations on this model.\n */\n\nexport type ServerNodeKind = 'element' | 'text' | 'comment' | 'fragment' | 'raw';\n\nexport interface ServerNode {\n readonly kind: ServerNodeKind;\n parent: ServerParent | null;\n}\n\nexport type ServerParent = ServerElement | ServerFragment;\n\n/** A minimal inline-style holder mirroring `element.style.setProperty`. */\nexport class ServerStyle {\n readonly declarations = new Map<string, string>();\n setProperty(name: string, value: string): void {\n this.declarations.set(name, value);\n }\n get isEmpty(): boolean {\n return this.declarations.size === 0;\n }\n toCss(): string {\n return [...this.declarations.entries()].map(([k, v]) => `${k}: ${v}`).join('; ');\n }\n}\n\nexport class ServerText implements ServerNode {\n readonly kind = 'text' as const;\n parent: ServerParent | null = null;\n data: string;\n constructor(data: string) {\n this.data = data;\n }\n}\n\nexport class ServerComment implements ServerNode {\n readonly kind = 'comment' as const;\n parent: ServerParent | null = null;\n data: string;\n constructor(data: string) {\n this.data = data;\n }\n}\n\nexport class ServerFragment implements ServerNode {\n readonly kind = 'fragment' as const;\n parent: ServerParent | null = null;\n readonly children: ServerNode[] = [];\n}\n\n/**\n * A pre-serialized, verbatim HTML fragment (v1.7 static SSR plan).\n *\n * Emitted for provably-static subtrees whose HTML the compiler-derived static\n * SSR plan already computed once. Serializing this node copies its stored\n * string directly — it allocates no ServerElement/ServerText, no attribute Map\n * and no children array for the collapsed subtree. The stored `html` is\n * produced by the exact same mount + serialize pipeline as the runtime path, so\n * the output is byte-identical (the v1.7 byte-identity gate proves this).\n *\n * This node is SSR-only: it is created solely via `ServerDOMAdapter.createRawHTML`\n * on the server render path and never appears in a browser build.\n */\nexport class ServerRawHTML implements ServerNode {\n readonly kind = 'raw' as const;\n parent: ServerParent | null = null;\n readonly html: string;\n constructor(html: string) {\n this.html = html;\n }\n}\n\nexport class ServerElement implements ServerNode {\n readonly kind = 'element' as const;\n parent: ServerParent | null = null;\n readonly tagName: string;\n readonly attributes = new Map<string, string>();\n readonly children: ServerNode[] = [];\n\n // Lazily-allocated stores. On the 10k-row SSR corpus ~0% of elements carry JS\n // properties or inline styles (measured, §5: 1 of 80,029 elements uses\n // `properties`, 0 use `style`), so eagerly allocating a `properties` Map plus\n // a `ServerStyle` (which itself holds a Map) per element wasted ~240k\n // allocations per /users render — all in the dominant mount phase. These are\n // created on first WRITE via the `properties`/`style` getters; the serializer\n // reads the raw `_properties`/`_style` fields so a READ never forces an\n // allocation. Output is byte-identical: an unset store previously serialized\n // to nothing (empty `properties.has(...)` / `style.isEmpty`), and a null store\n // is skipped the same way.\n _properties: Map<string, unknown> | null = null;\n _style: ServerStyle | null = null;\n\n constructor(tagName: string) {\n this.tagName = tagName.toLowerCase();\n }\n\n /** JS properties set via `setProperty` (e.g. input `value`, `checked`). Allocated on first access. */\n get properties(): Map<string, unknown> {\n return (this._properties ??= new Map());\n }\n\n /** Inline-style holder mirroring `element.style`. Allocated on first access. */\n get style(): ServerStyle {\n return (this._style ??= new ServerStyle());\n }\n}\n\n// ── HTML serialization ─────────────────────────────────────────────────────────\n\n/**\n * HTML \"void\" elements — self-closing, never given a closing tag or children.\n */\nconst VOID_ELEMENTS = new Set([\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\n 'link', 'meta', 'param', 'source', 'track', 'wbr',\n]);\n\n/**\n * Element properties that should be reflected into the serialized HTML so the\n * hydrated DOM carries the same initial state. `value`/`checked` matter for\n * form controls whose live state is a JS property, not an attribute.\n */\nconst SERIALIZED_PROPERTIES: Record<string, 'attr' | 'boolean'> = {\n value: 'attr',\n checked: 'boolean',\n selected: 'boolean',\n};\n\n/**\n * Precomputed `[name, kind]` pairs of SERIALIZED_PROPERTIES. Hoisted to module\n * scope so `serializeAttributes` does not allocate a fresh entries array for\n * every element serialized (measured hot: ~80k elements on the 10k-row route).\n */\nconst SERIALIZED_PROPERTY_ENTRIES: ReadonlyArray<readonly [string, 'attr' | 'boolean']> =\n Object.entries(SERIALIZED_PROPERTIES) as Array<[string, 'attr' | 'boolean']>;\n\n// Fast-path escaping. The chained `.replace(/…/g, …)` form makes 3–4 full\n// passes and allocates an intermediate string per pass even when nothing needs\n// escaping. These variants scan once and, in the overwhelmingly common case of\n// no special character, return the input unchanged (zero allocation). Output is\n// byte-identical to the chained form (verified over the real SSR corpus).\nconst TEXT_SPECIAL = /[&<>]/;\nconst ATTR_SPECIAL = /[&<>\"]/;\n\n/** Escape text node content. */\nexport function escapeHtmlText(value: string): string {\n if (!TEXT_SPECIAL.test(value)) return value;\n let out = '';\n let last = 0;\n for (let i = 0; i < value.length; i++) {\n let esc: string;\n switch (value.charCodeAt(i)) {\n case 38: esc = '&amp;'; break; // &\n case 60: esc = '&lt;'; break; // <\n case 62: esc = '&gt;'; break; // >\n default: continue;\n }\n out += value.slice(last, i) + esc;\n last = i + 1;\n }\n return out + value.slice(last);\n}\n\n/** Escape a double-quoted attribute value. */\nexport function escapeHtmlAttr(value: string): string {\n if (!ATTR_SPECIAL.test(value)) return value;\n let out = '';\n let last = 0;\n for (let i = 0; i < value.length; i++) {\n let esc: string;\n switch (value.charCodeAt(i)) {\n case 38: esc = '&amp;'; break; // &\n case 60: esc = '&lt;'; break; // <\n case 62: esc = '&gt;'; break; // >\n case 34: esc = '&quot;'; break; // \"\n default: continue;\n }\n out += value.slice(last, i) + esc;\n last = i + 1;\n }\n return out + value.slice(last);\n}\n\nfunction serializeAttributes(el: ServerElement): string {\n const parts: string[] = [];\n\n for (const [name, value] of el.attributes) {\n if (value === '') {\n parts.push(` ${name}`);\n } else {\n parts.push(` ${name}=\"${escapeHtmlAttr(value)}\"`);\n }\n }\n\n // Read the raw backing field (may be null): most elements have no JS\n // properties, so skipping the whole loop avoids touching a store that was\n // never allocated (§5).\n const props = el._properties;\n if (props !== null) {\n for (const [name, kind] of SERIALIZED_PROPERTY_ENTRIES) {\n if (!props.has(name)) continue;\n if (el.attributes.has(name)) continue; // an explicit attribute already won\n const raw = props.get(name);\n if (kind === 'boolean') {\n if (raw === true) parts.push(` ${name}`);\n } else {\n if (raw !== undefined && raw !== null) {\n parts.push(` ${name}=\"${escapeHtmlAttr(String(raw))}\"`);\n }\n }\n }\n }\n\n const style = el._style;\n if (style !== null && !style.isEmpty && !el.attributes.has('style')) {\n parts.push(` style=\"${escapeHtmlAttr(style.toCss())}\"`);\n }\n\n return parts.join('');\n}\n\n/** Serialize a single server node (element/text/comment/fragment/raw) to HTML. */\nexport function serializeServerNode(node: ServerNode): string {\n switch (node.kind) {\n case 'text':\n return escapeHtmlText((node as ServerText).data);\n case 'comment':\n return `<!--${(node as ServerComment).data}-->`;\n case 'fragment':\n return serializeChildren(node as ServerFragment);\n case 'raw':\n // Verbatim: the string was produced by this same serializer for a static\n // subtree, so it is already correctly escaped. Copy it as-is (§8).\n return (node as ServerRawHTML).html;\n case 'element': {\n const el = node as ServerElement;\n const tag = el.tagName;\n const attrs = serializeAttributes(el);\n if (VOID_ELEMENTS.has(tag)) {\n return `<${tag}${attrs}>`;\n }\n return `<${tag}${attrs}>${serializeChildren(el)}</${tag}>`;\n }\n }\n}\n\n/** Serialize the children of an element or fragment (its \"inner HTML\"). */\nexport function serializeChildren(node: ServerElement | ServerFragment): string {\n let out = '';\n for (const child of node.children) {\n out += serializeServerNode(child);\n }\n return out;\n}\n","/**\n * Server implementation of `DOMAdapter`.\n *\n * Builds a lightweight in-memory tree (see `server-node.ts`) instead of touching\n * a real browser DOM, then lets the caller serialize it to an HTML string. It is\n * completely free of browser globals, so the exact same renderer that runs in\n * the browser can produce HTML on the server.\n *\n * The `DOMAdapter` interface is typed against the lib DOM types (`Element`,\n * `Node`, `Text`, …). Our server nodes structurally stand in for those at\n * runtime, so the boundary uses `as unknown as` casts in one place. Everything\n * inside operates on the real server-node model.\n */\n\nimport type { DOMAdapter } from './adapter.js';\nimport {\n ServerElement,\n ServerText,\n ServerComment,\n ServerFragment,\n ServerRawHTML,\n serializeChildren,\n serializeServerNode,\n type ServerNode,\n type ServerParent,\n} from './server-node.js';\n\nfunction asServer(node: unknown): ServerNode {\n return node as unknown as ServerNode;\n}\nfunction asParent(node: unknown): ServerParent {\n return node as unknown as ServerParent;\n}\n\nexport class ServerDOMAdapter implements DOMAdapter {\n createElement(tag: string, _ns?: string): Element {\n return new ServerElement(tag) as unknown as Element;\n }\n\n createTextNode(data: string): Text {\n return new ServerText(data) as unknown as Text;\n }\n\n createComment(data: string): Comment {\n return new ServerComment(data) as unknown as Comment;\n }\n\n createFragment(): DocumentFragment {\n return new ServerFragment() as unknown as DocumentFragment;\n }\n\n /**\n * Create a verbatim pre-serialized HTML node (v1.7 static SSR plan, §6).\n * Server-only: the browser adapter does not implement this, and the renderer\n * fast path only invokes it when a static SSR plan is present (SSR). The\n * stored HTML was produced by this same serializer, so it is emitted as-is.\n */\n createRawHTML(html: string): Node {\n return new ServerRawHTML(html) as unknown as Node;\n }\n\n appendChild(parent: Node, child: Node): void {\n const p = asParent(parent);\n const c = asServer(child);\n this._detach(c);\n c.parent = p;\n p.children.push(c);\n }\n\n insertBefore(parent: Node, child: Node, reference: Node | null): void {\n const p = asParent(parent);\n const c = asServer(child);\n this._detach(c);\n c.parent = p;\n if (reference === null) {\n p.children.push(c);\n return;\n }\n const ref = asServer(reference);\n const idx = p.children.indexOf(ref);\n if (idx === -1) p.children.push(c);\n else p.children.splice(idx, 0, c);\n }\n\n removeChild(parent: Node, child: Node): void {\n const p = asParent(parent);\n const c = asServer(child);\n const idx = p.children.indexOf(c);\n if (idx !== -1) {\n p.children.splice(idx, 1);\n c.parent = null;\n }\n }\n\n replaceChild(parent: Node, newChild: Node, oldChild: Node): void {\n const p = asParent(parent);\n const nc = asServer(newChild);\n const oc = asServer(oldChild);\n const idx = p.children.indexOf(oc);\n if (idx === -1) return;\n this._detach(nc);\n nc.parent = p;\n p.children.splice(idx, 1, nc);\n oc.parent = null;\n }\n\n private _detach(node: ServerNode): void {\n if (node.parent !== null) {\n const siblings = node.parent.children;\n const idx = siblings.indexOf(node);\n if (idx !== -1) siblings.splice(idx, 1);\n node.parent = null;\n }\n }\n\n setAttribute(element: Element, name: string, value: string): void {\n (element as unknown as ServerElement).attributes.set(name, value);\n }\n\n removeAttribute(element: Element, name: string): void {\n (element as unknown as ServerElement).attributes.delete(name);\n }\n\n getAttribute(element: Element, name: string): string | null {\n return (element as unknown as ServerElement).attributes.get(name) ?? null;\n }\n\n setProperty(element: Element, name: string, value: unknown): void {\n (element as unknown as ServerElement).properties.set(name, value);\n }\n\n setTextContent(node: Node, text: string): void {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n const el = n as ServerElement | ServerFragment;\n el.children.length = 0;\n const t = new ServerText(text);\n t.parent = el;\n el.children.push(t);\n } else if (n.kind === 'text') {\n (n as ServerText).data = text;\n }\n }\n\n getTextContent(node: Node): string | null {\n const n = asServer(node);\n if (n.kind === 'text') return (n as ServerText).data;\n if (n.kind === 'element' || n.kind === 'fragment') {\n let out = '';\n for (const c of (n as ServerElement | ServerFragment).children) {\n out += this.getTextContent(c as unknown as Node) ?? '';\n }\n return out;\n }\n return null;\n }\n\n // Server nodes never dispatch events — listeners are a no-op on the server.\n addEventListener(): void {\n /* no-op on the server */\n }\n removeEventListener(): void {\n /* no-op on the server */\n }\n\n querySelector(): Element | null {\n return null;\n }\n querySelectorAll(): NodeListOf<Element> {\n return [] as unknown as NodeListOf<Element>;\n }\n getElementById(): Element | null {\n return null;\n }\n\n focus(): void {\n // No focus concept on the server — intentional no-op (SSR-safe).\n }\n\n body(): Element | null {\n // No document on the server — portals degrade to inline rendering.\n return null;\n }\n\n activeElement(): Element | null {\n return null;\n }\n\n contains(_ancestor: Element, _node: Node): boolean {\n return false;\n }\n\n matches(_element: Element, _selector: string): boolean {\n return false;\n }\n\n isElement(node: Node): node is Element {\n return asServer(node).kind === 'element';\n }\n\n isTextNode(node: Node): node is Text {\n return asServer(node).kind === 'text';\n }\n\n tagName(element: Element): string {\n return (element as unknown as ServerElement).tagName;\n }\n\n parentNode(node: Node): Node | null {\n return (asServer(node).parent as unknown as Node | null) ?? null;\n }\n\n nextSibling(node: Node): Node | null {\n const n = asServer(node);\n const parent = n.parent;\n if (parent === null) return null;\n const idx = parent.children.indexOf(n);\n if (idx === -1 || idx + 1 >= parent.children.length) return null;\n return parent.children[idx + 1] as unknown as Node;\n }\n\n firstChild(node: Node): Node | null {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n const el = n as ServerElement | ServerFragment;\n return (el.children[0] as unknown as Node) ?? null;\n }\n return null;\n }\n\n childNodes(node: Node): Node[] {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n return (n as ServerElement | ServerFragment).children as unknown as Node[];\n }\n return [];\n }\n\n // ── Server-only ────────────────────────────────────────────────────────────\n\n /** Serialize a node's children (\"inner HTML\") to an HTML string. */\n serializeInner(node: Node): string {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n return serializeChildren(n as ServerElement | ServerFragment);\n }\n return '';\n }\n\n /** Serialize a node (including itself) to an HTML string. */\n serializeOuter(node: Node): string {\n return serializeServerNode(asServer(node));\n }\n}\n\n// `/* @__PURE__ */`: this singleton is a convenience export only (no internal\n// runtime path references it). Marking construction pure lets bundlers drop it —\n// and with it the whole server serializer chain (serializeServerNode/escape/\n// VOID_ELEMENTS) — out of client bundles that never import SSR. Without this,\n// the un-annotated `new` is treated as a side effect and retained everywhere.\nexport const serverDOMAdapter = /* @__PURE__ */ new ServerDOMAdapter();\n","/**\n * Focus helpers built on the {@link DOMAdapter} abstraction.\n *\n * These are the minimal, genuinely-useful focus operations an app needs:\n * focus a specific element (e.g. the first field when a route or modal opens)\n * or focus the first focusable element inside a container (e.g. move focus\n * into a dialog). Both go through the adapter, so they are no-ops on the server\n * (`ServerDOMAdapter.querySelector` returns null / `focus` does nothing) and\n * therefore safe to call from universal code.\n */\n\nimport type { DOMAdapter } from './adapter.js';\n\n/** Default selector for natively focusable / tabbable elements. */\nexport const FOCUSABLE_SELECTOR =\n 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * Focus the element with the given id, scoped to `root`.\n * Returns true if an element was found and focused.\n */\nexport function focusById(dom: DOMAdapter, root: Element | Document, id: string): boolean {\n const el = dom.querySelector(root, `[id=\"${id}\"]`);\n if (el === null) return false;\n dom.focus(el);\n return true;\n}\n\n/**\n * Focus the first focusable element inside `container`.\n * Returns true if a focusable element was found and focused.\n */\nexport function focusFirst(\n dom: DOMAdapter,\n container: Element | Document,\n selector: string = FOCUSABLE_SELECTOR,\n): boolean {\n const el = dom.querySelector(container, selector);\n if (el === null) return false;\n dom.focus(el);\n return true;\n}\n\n/**\n * Ordered list of focusable/tabbable descendants of `container`.\n * Re-checks each candidate against the selector so elements disabled after the\n * initial query (e.g. a button toggled to `disabled`) are excluded.\n */\nexport function getFocusable(\n dom: DOMAdapter,\n container: Element,\n selector: string = FOCUSABLE_SELECTOR,\n): Element[] {\n return Array.from(dom.querySelectorAll(container, selector)).filter((el) =>\n dom.matches(el, selector),\n );\n}\n\n/**\n * Capture the currently-focused element so it can be restored later (e.g. when\n * a dialog closes). Returns null on the server or when nothing is focused.\n */\nexport function saveFocus(dom: DOMAdapter): Element | null {\n return dom.activeElement();\n}\n\n/** Restore focus to a previously {@link saveFocus}-d element. No-op if null. */\nexport function restoreFocus(dom: DOMAdapter, saved: Element | null): void {\n if (saved !== null) dom.focus(saved);\n}\n\n/**\n * Move focus into `container` on open: the element with id `initialFocusId` if\n * given and present, otherwise the first focusable element. Server-safe no-op.\n */\nexport function focusInitial(\n dom: DOMAdapter,\n container: Element,\n initialFocusId?: string,\n): void {\n if (initialFocusId !== undefined && focusById(dom, container, initialFocusId)) return;\n focusFirst(dom, container);\n}\n\n/**\n * Trap Tab / Shift+Tab focus within `container` (wrap-around at both ends).\n * Attaches a keydown listener to the container and returns a cleanup function\n * that detaches it. Server-safe: `addEventListener` is a no-op, and the returned\n * cleanup is still callable.\n */\nexport function trapFocus(dom: DOMAdapter, container: Element): () => void {\n const onKeydown = ((event: KeyboardEvent): void => {\n if (event.key !== 'Tab') return;\n const items = getFocusable(dom, container);\n if (items.length === 0) {\n event.preventDefault();\n return;\n }\n const first = items[0]!;\n const last = items[items.length - 1]!;\n const active = dom.activeElement();\n if (active === null || !dom.contains(container, active)) {\n event.preventDefault();\n dom.focus(first);\n } else if (event.shiftKey && active === first) {\n event.preventDefault();\n dom.focus(last);\n } else if (!event.shiftKey && active === last) {\n event.preventDefault();\n dom.focus(first);\n }\n }) as EventListener;\n dom.addEventListener(container, 'keydown', onKeydown);\n return () => dom.removeEventListener(container, 'keydown', onKeydown);\n}\n\n/**\n * Modal containment: if focus moves to an element outside `container`, redirect\n * it back inside. Listens on the document body (focusin bubbles there) and\n * returns a cleanup function. Server-safe no-op (body() is null).\n */\nexport function containFocus(dom: DOMAdapter, container: Element): () => void {\n const body = dom.body();\n if (body === null) return () => {};\n const onFocusIn = ((event: FocusEvent): void => {\n const target = event.target as Node | null;\n if (target !== null && !dom.contains(container, target)) {\n focusFirst(dom, container);\n }\n }) as EventListener;\n dom.addEventListener(body, 'focusin', onFocusIn);\n return () => dom.removeEventListener(body, 'focusin', onFocusIn);\n}\n\n/**\n * Invoke `handler` when Escape is pressed while focus is within `target`.\n * Returns a cleanup function. Server-safe no-op.\n */\nexport function onEscape(dom: DOMAdapter, target: Element, handler: () => void): () => void {\n const onKeydown = ((event: KeyboardEvent): void => {\n if (event.key === 'Escape') handler();\n }) as EventListener;\n dom.addEventListener(target, 'keydown', onKeydown);\n return () => dom.removeEventListener(target, 'keydown', onKeydown);\n}\n\n"],"mappings":";AAMO,IAAM,oBAAN,MAA8C;AAAA,EACnD,cAAc,KAAa,IAAsB;AAC/C,QAAI,OAAO,QAAW;AACpB,aAAO,SAAS,gBAAgB,IAAI,GAAG;AAAA,IACzC;AACA,WAAO,SAAS,cAAc,GAAG;AAAA,EACnC;AAAA,EAEA,eAAe,MAAoB;AACjC,WAAO,SAAS,eAAe,IAAI;AAAA,EACrC;AAAA,EAEA,cAAc,MAAuB;AACnC,WAAO,SAAS,cAAc,IAAI;AAAA,EACpC;AAAA,EAEA,iBAAmC;AACjC,WAAO,SAAS,uBAAuB;AAAA,EACzC;AAAA,EAEA,YAAY,QAAc,OAAmB;AAC3C,WAAO,YAAY,KAAK;AAAA,EAC1B;AAAA,EAEA,aAAa,QAAc,OAAa,WAA8B;AACpE,WAAO,aAAa,OAAO,SAAS;AAAA,EACtC;AAAA,EAEA,YAAY,QAAc,OAAmB;AAC3C,WAAO,YAAY,KAAK;AAAA,EAC1B;AAAA,EAEA,aAAa,QAAc,UAAgB,UAAsB;AAC/D,WAAO,aAAa,UAAU,QAAQ;AAAA,EACxC;AAAA,EAEA,aAAa,SAAkB,MAAc,OAAqB;AAChE,YAAQ,aAAa,MAAM,KAAK;AAAA,EAClC;AAAA,EAEA,gBAAgB,SAAkB,MAAoB;AACpD,YAAQ,gBAAgB,IAAI;AAAA,EAC9B;AA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,oBAAoB,QAAQ,WAAW,SAAS;AACnE;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streetui/dom",
3
- "version": "1.6.1",
3
+ "version": "1.7.0",
4
4
  "description": "StreetUI DOM abstraction layer",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",