kerfjs 5.0.0-beta.52 → 5.0.0-beta.53
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/CHANGELOG.md +329 -0
- package/README.md +4 -3
- package/ai/cursorrules +6 -5
- package/ai/manifest.json +9 -7
- package/ai/skill.md +6 -5
- package/dist/actions.js +3 -3
- package/dist/actions.js.map +1 -1
- package/dist/array-signal.js +1 -1
- package/dist/async.js +1 -1
- package/dist/attach.js +1 -68
- package/dist/attach.js.map +1 -1
- package/dist/{chunk-CEQMZYLR.js → chunk-3C6F6NM4.js} +1 -1
- package/dist/{chunk-CEQMZYLR.js.map → chunk-3C6F6NM4.js.map} +1 -1
- package/dist/{chunk-ZOIERTUW.js → chunk-BI4HGICV.js} +3 -3
- package/dist/{chunk-ZOIERTUW.js.map → chunk-BI4HGICV.js.map} +1 -1
- package/dist/{chunk-3GSWKMBZ.js → chunk-DU35YGKW.js} +3 -3
- package/dist/{chunk-3GSWKMBZ.js.map → chunk-DU35YGKW.js.map} +1 -1
- package/dist/chunk-FM6N2B4N.js +70 -0
- package/dist/chunk-FM6N2B4N.js.map +1 -0
- package/dist/{chunk-ELXVRKY2.js → chunk-H7WTRM6F.js} +2 -2
- package/dist/{chunk-ELXVRKY2.js.map → chunk-H7WTRM6F.js.map} +1 -1
- package/dist/{chunk-H3TTM7PQ.js → chunk-HTXQR2KL.js} +108 -106
- package/dist/chunk-HTXQR2KL.js.map +1 -0
- package/dist/{chunk-Y2FOYPBV.js → chunk-IHMDBBUJ.js} +2 -2
- package/dist/chunk-IHMDBBUJ.js.map +1 -0
- package/dist/{chunk-E5R5GNKE.js → chunk-X6OQ2HTR.js} +2 -2
- package/dist/{chunk-E5R5GNKE.js.map → chunk-X6OQ2HTR.js.map} +1 -1
- package/dist/dev.d.ts +31 -13
- package/dist/dev.js +34 -18
- package/dist/dev.js.map +1 -1
- package/dist/html.js +2 -2
- package/dist/index.d.ts +12 -7
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/jsx-runtime.js +1 -1
- package/dist/list.d.ts +3 -2
- package/dist/list.js +27 -13
- package/dist/list.js.map +1 -1
- package/dist/overlay.d.ts +0 -22
- package/dist/overlay.js +107 -30
- package/dist/overlay.js.map +1 -1
- package/dist/remount.js +2 -2
- package/dist/router.d.ts +13 -4
- package/dist/router.js +8 -4
- package/dist/router.js.map +1 -1
- package/dist/scope.d.ts +10 -2
- package/dist/scope.js +22 -28
- package/dist/scope.js.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/timing.d.ts +3 -2
- package/dist/timing.js +1 -1
- package/dist/timing.js.map +1 -1
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/dist/chunk-H3TTM7PQ.js.map +0 -1
- package/dist/chunk-Y2FOYPBV.js.map +0 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/renderDocument.ts","../src/toElement.ts"],"names":[],"mappings":";;;;;;;;;;;;AAuBO,SAAS,cAAA,CACd,IAAA,EACA,OAAA,GAAiC,EAAC,EAC1B;AACR,EAAA,MAAM,EAAE,OAAA,GAAU,MAAA,EAAO,GAAI,OAAA;AAC7B,EAAA,OAAO,CAAA,UAAA,EAAa,OAAO,CAAA,CAAA,EAAI,IAAA,CAAK,UAAU,CAAA,CAAA;AAChD;;;ACHA,IAAM,MAAA,GAAS,4BAAA;AAEf,IAAM,iBAAA,uBAAwB,GAAA,CAAI;AAAA,EAChC,GAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,KAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EAC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AAEA,IAAA,OAAO,MAAM,MAAM,CAAA;AAAA,EACrB;AAMA,EAAA,IAAI,OAAA,CAAQ,UAAA,CAAW,MAAA,KAAW,CAAA,EAAG;AACnC,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA;AAAA,SAAA,EAA4C,OAAA,CAAQ,IAAI,CAAC,CAAA;AAAA,KAC3D;AAAA,EACF;AACA,EAAA,IAAI,OAAA,CAAQ,QAAA,CAAS,MAAA,KAAW,CAAA,EAAG;AAIjC,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA;AAAA,SAAA,EAA4C,OAAA,CAAQ,IAAI,CAAC,CAAA;AAAA,KAC3D;AAAA,EACF;AACA,EAAA,OAAO,MAAM,OAAO,CAAA;AACtB","file":"index.js","sourcesContent":["/**\n * `renderDocument(node)` — prepend the doctype to a rendered document.\n *\n * Every kerf SSR app ends its routes with the identical concat\n * `\"<!DOCTYPE html>\" + page.toString()`. This is that one line, blessed, so the\n * doctype isn't reinvented (or forgotten) per route.\n *\n * import { renderDocument } from 'kerfjs';\n * return c.html(renderDocument(<Page />)); // \"<!DOCTYPE html><html>…\"\n *\n * `node` is a `SafeHtml` (from JSX / the `html` tagged template) or a raw string\n * — both are stringified via `.toString()`. The optional `doctype` overrides the\n * default `'html'`.\n */\nimport type { SafeHtml } from './jsx-runtime.js';\n\n/** Options for {@link renderDocument}. */\nexport interface RenderDocumentOptions {\n /** The doctype name. Default `'html'` → `<!DOCTYPE html>`. */\n doctype?: string;\n}\n\n/** Prepend `<!DOCTYPE …>` to a rendered `SafeHtml` (or string) document and return the full HTML string. */\nexport function renderDocument(\n node: SafeHtml | string,\n options: RenderDocumentOptions = {},\n): string {\n const { doctype = 'html' } = options;\n return `<!DOCTYPE ${doctype}>${node.toString()}`;\n}\n","/**\n * `toElement(jsx)` — JSX → DOM, with SVG-aware namespace handling.\n *\n * Single-root inputs return an `Element`. Multi-root inputs (text + element,\n * `<><svg/> label</>`, two icons side by side, …) return a `DocumentFragment`\n * containing every top-level node. The DOM insertion APIs (`appendChild`,\n * `replaceChildren`, `append`) inline a `DocumentFragment`'s children on\n * insert, so `parent.replaceChildren(toElement(<>{ICON} label</>))` does the\n * obvious thing — parent gets the svg AND the text, no silent loss.\n *\n * The returned node is always adopted into the live `document` before it's\n * handed back (see `adopt()` below) — never left owned by the inert\n * `<template>`/`DOMParser` document it was parsed in, which is unsafe to mutate\n * before insertion on some engines.\n *\n * SVG namespacing: the HTML5 parser handles `<svg>` as foreign content\n * correctly even when wrapped in a fragment, so multi-root inputs containing\n * SVGs come out namespaced correctly via the `<template>.innerHTML` path. For\n * single-root SVG inputs the XML parser is preferred (stricter — catches\n * malformed markup the HTML5 parser would silently auto-correct). For orphan\n * SVG-namespace fragments without an `<svg>` wrapper (`<path/>`, `<g>`, …)\n * the input is wrapped in `<svg xmlns=...>` and XML-parsed.\n */\n\nimport type { SafeHtml } from './jsx-runtime.js';\n\nconst SVG_NS = 'http://www.w3.org/2000/svg';\n\nconst SVG_FRAGMENT_TAGS = new Set([\n 'g',\n 'path',\n 'circle',\n 'rect',\n 'line',\n 'polygon',\n 'polyline',\n 'ellipse',\n 'text',\n 'tspan',\n 'defs',\n 'use',\n 'symbol',\n 'clipPath',\n 'mask',\n 'pattern',\n 'filter',\n 'marker',\n 'linearGradient',\n 'radialGradient',\n 'stop',\n 'image',\n 'foreignObject',\n]);\n\nconst EXCERPT_MAX_LEN = 100;\n\nfunction excerpt(html: string): string {\n const trimmed = html.trim();\n return trimmed.length > EXCERPT_MAX_LEN\n ? `${trimmed.slice(0, EXCERPT_MAX_LEN)}…`\n : trimmed;\n}\n\n/**\n * Adopt `node` into the live `document` before returning it.\n *\n * Both parse paths produce nodes that belong to an *inert* document, not the\n * one the caller renders into: the `<template>.content` path yields nodes\n * owned by the template-contents owner document, and the `DOMParser` path\n * yields nodes owned by the parser's document. Returning such a node is a\n * footgun — operating on it before it's inserted (most notably `mount()`'s\n * first-render `rootEl.innerHTML = …`) runs against an inert-document element,\n * which on WebKit trips a fragment-parsing bug: under rapid bursts the parser\n * can hand back a *previous* parse's nodes, so a freshly-built element silently\n * inherits unrelated DOM. (Chromium never reproduces it; the originating\n * report was Safari-only — a feed mounting many `toElement(<div/>)` cards in\n * one flush, each painting a stale sibling's state.) `adoptNode` moves the node\n * into the live document (preserving identity and namespaces), so the returned\n * node is always safe to mutate before insertion.\n */\nfunction adopt<T extends Node>(node: T): T {\n document.adoptNode(node);\n return node;\n}\n\nfunction parseSvgOrThrow(\n html: string,\n label: string,\n originalHtml: string,\n): Document {\n const doc = new DOMParser().parseFromString(html, 'image/svg+xml');\n const err = doc.querySelector('parsererror');\n if (err !== null) {\n throw new Error(\n `toElement: ${label} parse error — ${err.textContent}\\n input: ${excerpt(originalHtml)}`,\n );\n }\n return doc;\n}\n\n// True when the fragment is effectively a single root — exactly one element\n// child, all sibling nodes whitespace-only text. Returns that element, else\n// null. The whitespace tolerance matches the pre-KF-232 behavior for inputs\n// like ` <svg/>\\n` (which were treated as a single SVG root).\nfunction singleRootElement(content: DocumentFragment): Element | null {\n if (content.children.length !== 1) return null;\n const onlyElement = content.firstElementChild;\n /* c8 ignore next — guarded by children.length === 1 above. */\n if (onlyElement === null) return null;\n for (const node of content.childNodes) {\n if (node === onlyElement) continue;\n if (node.nodeType !== Node.TEXT_NODE) return null;\n /* c8 ignore next — `textContent` on a TEXT_NODE is always a string; the `??` is a TypeScript-only guard. */\n if ((node.textContent ?? '').trim() !== '') return null;\n }\n return onlyElement;\n}\n\nexport function toElement(jsx: SafeHtml | string): Element | DocumentFragment {\n const html = typeof jsx === 'string' ? jsx : jsx.toString();\n\n // First pass: HTML <template> parse. This gives us correct namespacing for\n // `<svg>` (foreign content), reveals the multi-root vs single-root shape,\n // and is the universal fallback path. Orphan SVG fragments without an\n // `<svg>` wrapper are the one case that needs a different parser — handled\n // below.\n const t = document.createElement('template');\n t.innerHTML = html;\n const content = t.content;\n\n const single = singleRootElement(content);\n\n if (single !== null) {\n const tag = single.tagName.toLowerCase();\n\n // Single SVG root → re-parse via XML for strict validation. The HTML5\n // parser silently auto-corrects malformed SVG (`<svg><unclosed</svg>`),\n // which is worse than throwing. Trim so trailing whitespace in the input\n // doesn't trip up the XML parser.\n if (tag === 'svg') {\n return adopt(parseSvgOrThrow(html.trim(), 'SVG', html).documentElement);\n }\n\n // Single orphan SVG-namespace fragment (`<path/>`, `<g>`, …) — the HTML5\n // parser puts these in the XHTML namespace, so wrap in `<svg>` and\n // XML-parse to get the right namespace on the returned element.\n if (SVG_FRAGMENT_TAGS.has(tag)) {\n const wrapped = `<svg xmlns=\"${SVG_NS}\">${html}</svg>`;\n const doc = parseSvgOrThrow(wrapped, 'SVG fragment', html);\n const first = doc.documentElement.firstElementChild;\n /* c8 ignore next 2 — defensive: a successful XML parse of a wrapped svg always yields ≥1 child. */\n if (first === null)\n throw new Error(\n `toElement: SVG fragment produced no element\\n input: ${excerpt(html)}`,\n );\n return adopt(first);\n }\n\n return adopt(single);\n }\n\n // Multi-root (or no roots): return the parsed DocumentFragment so the caller\n // can splat all the top-level nodes into their container via appendChild /\n // replaceChildren / append. If the input produced nothing at all, throw —\n // there's no useful Node to hand back.\n if (content.childNodes.length === 0) {\n throw new Error(\n `toElement: produced no element\\n input: ${excerpt(html)}`,\n );\n }\n if (content.children.length === 0) {\n // No element children at all — only text or comments. Same \"no element\"\n // failure as the empty case; toElement's name implies at least one\n // element somewhere.\n throw new Error(\n `toElement: produced no element\\n input: ${excerpt(html)}`,\n );\n }\n return adopt(content);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/renderDocument.ts","../src/toElement.ts"],"names":[],"mappings":";;;;;;;;;;;;AAuBO,SAAS,cAAA,CACd,IAAA,EACA,OAAA,GAAiC,EAAC,EAC1B;AACR,EAAA,MAAM,EAAE,OAAA,GAAU,MAAA,EAAO,GAAI,OAAA;AAC7B,EAAA,OAAO,CAAA,UAAA,EAAa,OAAO,CAAA,CAAA,EAAI,IAAA,CAAK,UAAU,CAAA,CAA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AA,CAAiB,IAAA,CAAK,IAAI,CAAA,EAC5C;AACA,MAAA,MAAM,OAAA,GAAU,CAAA,YAAA,EAAe,MAAM,CAAA,EAAA,EAAK,IAAI,CAAA,MAAA,CAAA;AAC9C,MAAA,MAAM,GAAA,GAAM,eAAA,CAAgB,OAAA,EAAS,cAAA,EAAgB,IAAI,CAAA;AACzD,MAAA,MAAM,KAAA,GAAQ,IAAI,eAAA,CAAgB,iBAAA;AAElC,MAAA,IAAI,KAAA,KAAU,IAAA;AACZ,QAAA,MAAM,IAAI,KAAA;AAAA,UACR,CAAA;AAAA,SAAA,EAAyD,OAAA,CAAQ,IAAI,CAAC,CAAA;AAAA,SACxE;AACF,MAAA,OAAO,MAAM,KAAK,CAAA;AAAA,IACpB;AAEA,IAAA,OAAO,MAAM,MAAM,CAAA;AAAA,EACrB;AAMA,EAAA,IAAI,OAAA,CAAQ,UAAA,CAAW,MAAA,KAAW,CAAA,EAAG;AACnC,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA;AAAA,SAAA,EAA4C,OAAA,CAAQ,IAAI,CAAC,CAAA;AAAA,KAC3D;AAAA,EACF;AACA,EAAA,IAAI,OAAA,CAAQ,QAAA,CAAS,MAAA,KAAW,CAAA,EAAG;AAIjC,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA;AAAA,SAAA,EAA4C,OAAA,CAAQ,IAAI,CAAC,CAAA;AAAA,KAC3D;AAAA,EACF;AACA,EAAA,OAAO,MAAM,OAAO,CAAA;AACtB","file":"index.js","sourcesContent":["/**\n * `renderDocument(node)` — prepend the doctype to a rendered document.\n *\n * Every kerf SSR app ends its routes with the identical concat\n * `\"<!DOCTYPE html>\" + page.toString()`. This is that one line, blessed, so the\n * doctype isn't reinvented (or forgotten) per route.\n *\n * import { renderDocument } from 'kerfjs';\n * return c.html(renderDocument(<Page />)); // \"<!DOCTYPE html><html>…\"\n *\n * `node` is a `SafeHtml` (from JSX / the `html` tagged template) or a raw string\n * — both are stringified via `.toString()`. The optional `doctype` overrides the\n * default `'html'`.\n */\nimport type { SafeHtml } from './jsx-runtime.js';\n\n/** Options for {@link renderDocument}. */\nexport interface RenderDocumentOptions {\n /** The doctype name. Default `'html'` → `<!DOCTYPE html>`. */\n doctype?: string;\n}\n\n/** Prepend `<!DOCTYPE …>` to a rendered `SafeHtml` (or string) document and return the full HTML string. */\nexport function renderDocument(\n node: SafeHtml | string,\n options: RenderDocumentOptions = {},\n): string {\n const { doctype = 'html' } = options;\n return `<!DOCTYPE ${doctype}>${node.toString()}`;\n}\n","/**\n * `toElement(jsx)` — JSX → DOM, with SVG-aware namespace handling.\n *\n * Single-root inputs return an `Element`. Multi-root inputs (text + element,\n * `<><svg/> label</>`, two icons side by side, …) return a `DocumentFragment`\n * containing every top-level node. The DOM insertion APIs (`appendChild`,\n * `replaceChildren`, `append`) inline a `DocumentFragment`'s children on\n * insert, so `parent.replaceChildren(toElement(<>{ICON} label</>))` does the\n * obvious thing — parent gets the svg AND the text, no silent loss.\n *\n * The returned node is always adopted into the live `document` before it's\n * handed back (see `adopt()` below) — never left owned by the inert\n * `<template>`/`DOMParser` document it was parsed in, which is unsafe to mutate\n * before insertion on some engines.\n *\n * SVG namespacing: the HTML5 parser handles `<svg>` as foreign content\n * correctly even when wrapped in a fragment, so multi-root inputs containing\n * SVGs come out namespaced correctly via the `<template>.innerHTML` path. For\n * single-root SVG inputs the XML parser is preferred (stricter — catches\n * malformed markup the HTML5 parser would silently auto-correct). For orphan\n * SVG-namespace fragments without an `<svg>` wrapper (`<path/>`, `<g>`, …)\n * the input is wrapped in `<svg xmlns=...>` and XML-parsed.\n */\n\nimport type { SafeHtml } from './jsx-runtime.js';\n\nconst SVG_NS = 'http://www.w3.org/2000/svg';\n\n// Entries are lowercase: the lookup key is the HTML parser's\n// `tagName.toLowerCase()`, and the HTML parser has already folded\n// `<linearGradient>` to `lineargradient` by then. A camelCase entry would never\n// match (the orphan `clipPath` / `linearGradient` / `radialGradient` /\n// `foreignObject` fragments used to fall through to the XHTML namespace). The\n// XML re-parse restores the camelCase localName on the returned element. Keep\n// this a plain array literal — no `.map()` — so esbuild still marks the `Set`\n// pure and the whole module tree-shakes out of bundles that never import\n// `toElement`. `image` is not listed: the HTML parser rewrites `<image>` to\n// `<img>`, so it is detected from the raw input instead (see\n// `ORPHAN_SVG_IMAGE`).\nconst SVG_FRAGMENT_TAGS: ReadonlySet<string> = new Set([\n 'g',\n 'path',\n 'circle',\n 'rect',\n 'line',\n 'polygon',\n 'polyline',\n 'ellipse',\n 'text',\n 'tspan',\n 'defs',\n 'use',\n 'symbol',\n 'clippath',\n 'mask',\n 'pattern',\n 'filter',\n 'marker',\n 'lineargradient',\n 'radialgradient',\n 'stop',\n 'foreignobject',\n]);\n\n// A leading `<image` start tag (after whitespace), case-insensitive. The HTML\n// parser turns an orphan SVG `<image>` into an HTML `<img>`, so by the time\n// the tag name is inspected the only trace of the author's intent is the raw\n// input; this regex distinguishes it from a genuine `<img>`.\nconst ORPHAN_SVG_IMAGE = /^\\s*<image[\\s/>]/i;\n\nconst EXCERPT_MAX_LEN = 100;\n\nfunction excerpt(html: string): string {\n const trimmed = html.trim();\n return trimmed.length > EXCERPT_MAX_LEN\n ? `${trimmed.slice(0, EXCERPT_MAX_LEN)}…`\n : trimmed;\n}\n\n/**\n * Adopt `node` into the live `document` before returning it.\n *\n * Both parse paths produce nodes that belong to an *inert* document, not the\n * one the caller renders into: the `<template>.content` path yields nodes\n * owned by the template-contents owner document, and the `DOMParser` path\n * yields nodes owned by the parser's document. Returning such a node is a\n * footgun — operating on it before it's inserted (most notably `mount()`'s\n * first-render `rootEl.innerHTML = …`) runs against an inert-document element,\n * which on WebKit trips a fragment-parsing bug: under rapid bursts the parser\n * can hand back a *previous* parse's nodes, so a freshly-built element silently\n * inherits unrelated DOM. (Chromium never reproduces it; the originating\n * report was Safari-only — a feed mounting many `toElement(<div/>)` cards in\n * one flush, each painting a stale sibling's state.) `adoptNode` moves the node\n * into the live document (preserving identity and namespaces), so the returned\n * node is always safe to mutate before insertion.\n */\nfunction adopt<T extends Node>(node: T): T {\n document.adoptNode(node);\n return node;\n}\n\nfunction parseSvgOrThrow(\n html: string,\n label: string,\n originalHtml: string,\n): Document {\n const doc = new DOMParser().parseFromString(html, 'image/svg+xml');\n const err = doc.querySelector('parsererror');\n if (err !== null) {\n throw new Error(\n `toElement: ${label} parse error — ${err.textContent}\\n input: ${excerpt(originalHtml)}`,\n );\n }\n return doc;\n}\n\n// True when the fragment is effectively a single root — exactly one element\n// child, all sibling nodes whitespace-only text. Returns that element, else\n// null. The whitespace tolerance matches the pre-KF-232 behavior for inputs\n// like ` <svg/>\\n` (which were treated as a single SVG root).\nfunction singleRootElement(content: DocumentFragment): Element | null {\n if (content.children.length !== 1) return null;\n const onlyElement = content.firstElementChild;\n /* c8 ignore next — guarded by children.length === 1 above. */\n if (onlyElement === null) return null;\n for (const node of content.childNodes) {\n if (node === onlyElement) continue;\n if (node.nodeType !== Node.TEXT_NODE) return null;\n /* c8 ignore next — `textContent` on a TEXT_NODE is always a string; the `??` is a TypeScript-only guard. */\n if ((node.textContent ?? '').trim() !== '') return null;\n }\n return onlyElement;\n}\n\nexport function toElement(jsx: SafeHtml | string): Element | DocumentFragment {\n const html = typeof jsx === 'string' ? jsx : jsx.toString();\n\n // First pass: HTML <template> parse. This gives us correct namespacing for\n // `<svg>` (foreign content), reveals the multi-root vs single-root shape,\n // and is the universal fallback path. Orphan SVG fragments without an\n // `<svg>` wrapper are the one case that needs a different parser — handled\n // below.\n const t = document.createElement('template');\n t.innerHTML = html;\n const content = t.content;\n\n const single = singleRootElement(content);\n\n if (single !== null) {\n const tag = single.tagName.toLowerCase();\n\n // Single SVG root → re-parse via XML for strict validation. The HTML5\n // parser silently auto-corrects malformed SVG (`<svg><unclosed</svg>`),\n // which is worse than throwing. Trim so trailing whitespace in the input\n // doesn't trip up the XML parser.\n if (tag === 'svg') {\n return adopt(parseSvgOrThrow(html.trim(), 'SVG', html).documentElement);\n }\n\n // Single orphan SVG-namespace fragment (`<path/>`, `<g>`, …) — the HTML5\n // parser puts these in the XHTML namespace, so wrap in `<svg>` and\n // XML-parse to get the right namespace on the returned element.\n if (\n SVG_FRAGMENT_TAGS.has(tag) ||\n (tag === 'img' && ORPHAN_SVG_IMAGE.test(html))\n ) {\n const wrapped = `<svg xmlns=\"${SVG_NS}\">${html}</svg>`;\n const doc = parseSvgOrThrow(wrapped, 'SVG fragment', html);\n const first = doc.documentElement.firstElementChild;\n /* c8 ignore next 2 — defensive: a successful XML parse of a wrapped svg always yields ≥1 child. */\n if (first === null)\n throw new Error(\n `toElement: SVG fragment produced no element\\n input: ${excerpt(html)}`,\n );\n return adopt(first);\n }\n\n return adopt(single);\n }\n\n // Multi-root (or no roots): return the parsed DocumentFragment so the caller\n // can splat all the top-level nodes into their container via appendChild /\n // replaceChildren / append. If the input produced nothing at all, throw —\n // there's no useful Node to hand back.\n if (content.childNodes.length === 0) {\n throw new Error(\n `toElement: produced no element\\n input: ${excerpt(html)}`,\n );\n }\n if (content.children.length === 0) {\n // No element children at all — only text or comments. Same \"no element\"\n // failure as the empty case; toElement's name implies at least one\n // element somewhere.\n throw new Error(\n `toElement: produced no element\\n input: ${excerpt(html)}`,\n );\n }\n return adopt(content);\n}\n"]}
|
package/dist/jsx-runtime.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Fragment, SafeHtml, assertEmittableAttrName as _assertEmittableAttrName, _renderAttrVerbatim, _toSegment, granularListSafeHtml, isSafeHtml, jsx, jsx as jsxDEV, jsx as jsxs, listSafeHtml, raw } from './chunk-
|
|
1
|
+
export { Fragment, SafeHtml, assertEmittableAttrName as _assertEmittableAttrName, _renderAttrVerbatim, _toSegment, granularListSafeHtml, isSafeHtml, jsx, jsx as jsxDEV, jsx as jsxs, listSafeHtml, raw } from './chunk-DU35YGKW.js';
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
package/dist/list.d.ts
CHANGED
|
@@ -179,8 +179,9 @@ declare function bindList<T>(parent: HTMLElement, source: ListSource<T>, options
|
|
|
179
179
|
* as the window shifts. Returns a disposer.
|
|
180
180
|
*
|
|
181
181
|
* This is the batteries-included measurement path; it is deliberately separate
|
|
182
|
-
* from `bindList` (which never
|
|
183
|
-
*
|
|
182
|
+
* from `bindList` (which never observes rows; its only `ResizeObserver` use is
|
|
183
|
+
* an optional observer on the scroll parent that re-windows on resize) — you
|
|
184
|
+
* can measure however you like and call `handle.setHeight` yourself instead. A no-op for a
|
|
184
185
|
* non-virtualized handle or where `ResizeObserver` is unavailable (SSR).
|
|
185
186
|
*
|
|
186
187
|
* const list = bindList(scrollEl, source, { key, render, virtualize: { rowHeight: { estimate: 64 } } });
|
package/dist/list.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ARRAY_SIGNAL_BRAND } from './chunk-
|
|
2
|
-
import { captureFocus, restoreFocus, moveNode, mount } from './chunk-
|
|
1
|
+
import { ARRAY_SIGNAL_BRAND } from './chunk-H7WTRM6F.js';
|
|
2
|
+
import { captureFocus, restoreFocus, moveNode, mount } from './chunk-HTXQR2KL.js';
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import { effect } from './chunk-
|
|
6
|
+
import { effect } from './chunk-IHMDBBUJ.js';
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
@@ -182,7 +182,7 @@ function createListVirtualizationController(options) {
|
|
|
182
182
|
let items = [];
|
|
183
183
|
let offsets = [0];
|
|
184
184
|
let heightsDirty = true;
|
|
185
|
-
|
|
185
|
+
const pendingAnchorBaselines = /* @__PURE__ */ new Map();
|
|
186
186
|
let rafPending = false;
|
|
187
187
|
let disposed = false;
|
|
188
188
|
const estimateAt = (index) => {
|
|
@@ -213,6 +213,9 @@ function createListVirtualizationController(options) {
|
|
|
213
213
|
for (const rowKey of measured.keys()) {
|
|
214
214
|
if (!indexByKey.has(rowKey)) measured.delete(rowKey);
|
|
215
215
|
}
|
|
216
|
+
for (const rowKey of pendingAnchorBaselines.keys()) {
|
|
217
|
+
if (!indexByKey.has(rowKey)) pendingAnchorBaselines.delete(rowKey);
|
|
218
|
+
}
|
|
216
219
|
}
|
|
217
220
|
};
|
|
218
221
|
const findStart = (target, total) => {
|
|
@@ -269,9 +272,9 @@ function createListVirtualizationController(options) {
|
|
|
269
272
|
padBottom = 0;
|
|
270
273
|
} else if (fixedHeight !== null) {
|
|
271
274
|
const viewportBottom = parent.scrollTop + parent.clientHeight;
|
|
272
|
-
start2 = Math.
|
|
273
|
-
|
|
274
|
-
Math.floor(parent.scrollTop / fixedHeight) - overscan
|
|
275
|
+
start2 = Math.min(
|
|
276
|
+
total,
|
|
277
|
+
Math.max(0, Math.floor(parent.scrollTop / fixedHeight) - overscan)
|
|
275
278
|
);
|
|
276
279
|
end = Math.min(total, Math.ceil(viewportBottom / fixedHeight) + overscan);
|
|
277
280
|
padTop = start2 * fixedHeight;
|
|
@@ -298,16 +301,27 @@ function createListVirtualizationController(options) {
|
|
|
298
301
|
heightsDirty = true;
|
|
299
302
|
renderCurrent();
|
|
300
303
|
};
|
|
304
|
+
const applyAnchorCorrection = () => {
|
|
305
|
+
if (heightsDirty) {
|
|
306
|
+
rebuildOffsets();
|
|
307
|
+
heightsDirty = false;
|
|
308
|
+
}
|
|
309
|
+
let delta = 0;
|
|
310
|
+
for (const [rowKey, baseline] of pendingAnchorBaselines) {
|
|
311
|
+
const index = indexByKey.get(rowKey);
|
|
312
|
+
if (offsets[index] + baseline <= parent.scrollTop)
|
|
313
|
+
delta += offsets[index + 1] - offsets[index] - baseline;
|
|
314
|
+
}
|
|
315
|
+
pendingAnchorBaselines.clear();
|
|
316
|
+
if (delta !== 0) parent.scrollTop += delta;
|
|
317
|
+
};
|
|
301
318
|
const scheduleRender = () => {
|
|
302
319
|
if (rafPending) return;
|
|
303
320
|
rafPending = true;
|
|
304
321
|
globalThis.requestAnimationFrame(() => {
|
|
305
322
|
rafPending = false;
|
|
306
323
|
if (disposed) return;
|
|
307
|
-
if (
|
|
308
|
-
parent.scrollTop += pendingAnchorDelta;
|
|
309
|
-
pendingAnchorDelta = 0;
|
|
310
|
-
}
|
|
324
|
+
if (pendingAnchorBaselines.size > 0) applyAnchorCorrection();
|
|
311
325
|
renderCurrent();
|
|
312
326
|
});
|
|
313
327
|
};
|
|
@@ -325,8 +339,8 @@ function createListVirtualizationController(options) {
|
|
|
325
339
|
const oldHeight = measured.get(rowKey) ?? estimateAt(index);
|
|
326
340
|
if (height === oldHeight) return;
|
|
327
341
|
measured.set(rowKey, height);
|
|
328
|
-
if (
|
|
329
|
-
|
|
342
|
+
if (!pendingAnchorBaselines.has(rowKey))
|
|
343
|
+
pendingAnchorBaselines.set(rowKey, oldHeight);
|
|
330
344
|
heightsDirty = true;
|
|
331
345
|
scheduleRender();
|
|
332
346
|
};
|
package/dist/list.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/list-row-controller.ts","../src/list-virtualization-controller.ts","../src/list.ts"],"names":["dispose","start","NOOP"],"mappings":";;;;;;;;;;AA6BA,IAAM,OAAO,MAAY;AAEzB,CAAA;AAGO,SAAS,wBACd,OAAA,EACsB;AACtB,EAAA,MAAM,EAAE,SAAA,EAAW,GAAA,EAAK,MAAA,EAAQ,GAAA,EAAK,WAAU,GAAI,OAAA;AACnD,EAAA,MAAM,IAAA,uBAAW,GAAA,EAAyB;AAC1C,EAAA,MAAM,QAA2B,EAAC;AAElC,EAAA,MAAM,YAAA,GAAe,CACnB,QAAA,KAKU;AACV,IAAA,IAAI,oBAAoB,WAAA,EAAa,OAAO,EAAE,EAAA,EAAI,QAAA,EAAU,SAAS,IAAA,EAAK;AAC1E,IAAA,IACE,QAAA,KAAa,QACb,OAAO,QAAA,KAAa,YACpB,IAAA,IAAQ,QAAA,IACP,QAAA,CAA6B,EAAA,YAAc,WAAA,EAC5C;AACA,MAAA,MAAM,GAAA,GAAM,QAAA;AAKZ,MAAA,OAAO,EAAE,EAAA,EAAI,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AAS,MAAY;AACzB,IAAA,QAAA,CAAS,UAAA,EAAW;AACpB,IAAA,KAAA,MAAW,EAAE,GAAA,EAAK,CAAA,EAAG,IAAG,IAAK,SAAA,CAAU,aAAY,EAAG;AACpD,MAAA,OAAA,CAAQ,GAAA,CAAI,IAAI,CAAC,CAAA;AACjB,MAAA,QAAA,CAAS,QAAQ,EAAE,CAAA;AAAA,IACrB;AAAA,EACF,CAAA;AAEA,EAAA,MAAM,WAAA,GAAc,SAAA,CAAU,QAAA,CAAS,MAAM,CAAA;AAC7C,EAAA,MAAA,EAAO;AAEP,EAAA,OAAO,MAAM;AACX,IAAA,QAAA,CAAS,UAAA,EAAW;AACpB,IAAA,WAAA,EAAY;AAAA,EACd,CAAA;AACF","file":"list.js","sourcesContent":["import type { ArrayPatch } from './array-signal.js';\nimport type { BindListOptions, ListKey, RowElement } from './list.js';\nimport { captureFocus, restoreFocus } from './list-reconcile-focus.js';\nimport { mount, type MountResult } from './mount.js';\nimport { moveNode } from './utils/moveNode.js';\n\ninterface ListRow<T> {\n el: HTMLElement;\n item: T;\n dispose: () => void;\n elementMode: boolean;\n update?: (item: T) => void;\n}\n\nexport interface ListRowController<T> {\n readonly order: Array<ListRow<T>>;\n sync: (visible: readonly T[]) => void;\n applyPatches: (patches: readonly ArrayPatch<T>[]) => void;\n dispose: (removeElements: boolean) => void;\n}\n\ninterface ListRowControllerOptions<T> {\n container: HTMLElement;\n key: (item: T) => ListKey;\n render: BindListOptions<T>['render'];\n tag: string;\n endAnchor: () => Node | null;\n}\n\nconst NOOP = (): void => {\n /* element-mode rows with no caller teardown */\n};\n\n/** Own the keyed row map, DOM order, row lifecycles, and both reconcile paths. */\nexport function createListRowController<T>(\n options: ListRowControllerOptions<T>,\n): ListRowController<T> {\n const { container, key, render, tag, endAnchor } = options;\n const rows = new Map<ListKey, ListRow<T>>();\n const order: Array<ListRow<T>> = [];\n\n const asElementRow = (\n rendered: MountResult | RowElement<T>,\n ): {\n el: HTMLElement;\n dispose: () => void;\n update?: (item: T) => void;\n } | null => {\n if (rendered instanceof HTMLElement) return { el: rendered, dispose: NOOP };\n if (\n rendered !== null &&\n typeof rendered === 'object' &&\n 'el' in rendered &&\n (rendered as { el: unknown }).el instanceof HTMLElement\n ) {\n const row = rendered as {\n el: HTMLElement;\n update?: (item: T) => void;\n dispose?: () => void;\n };\n return { el: row.el, dispose: row.dispose ?? NOOP, update: row.update };\n }\n return null;\n };\n\n const makeRow = (item: T): ListRow<T> => {\n const elementRow = asElementRow(render(item));\n if (elementRow !== null) {\n return {\n el: elementRow.el,\n item,\n dispose: elementRow.dispose,\n elementMode: true,\n update: elementRow.update,\n };\n }\n const el = document.createElement(tag);\n const dispose = mount(el, () => render(item) as MountResult);\n return { el, item, dispose, elementMode: false };\n };\n\n // The single item-replacement contract used by snapshot and granular paths.\n // Element-mode rows keep their caller-owned element and are re-keyed; content\n // rows replace their mount. DOM placement remains the caller's responsibility.\n const reconcileItem = (row: ListRow<T>, item: T): ListRow<T> => {\n if (row.item === item) return row;\n const oldKey = key(row.item);\n const newKey = key(item);\n if (row.elementMode) {\n row.item = item;\n if (newKey !== oldKey) {\n rows.delete(oldKey);\n rows.set(newKey, row);\n }\n row.update?.(item);\n return row;\n }\n row.dispose();\n row.el.remove();\n rows.delete(oldKey);\n const fresh = makeRow(item);\n rows.set(newKey, fresh);\n return fresh;\n };\n\n const preserveFocus = (operation: () => void): void => {\n const focus = captureFocus(container);\n try {\n operation();\n } finally {\n if (focus !== null) restoreFocus(focus);\n }\n };\n\n const sync = (visible: readonly T[]): void => {\n preserveFocus(() => {\n const wanted = new Set<ListKey>();\n for (const item of visible) wanted.add(key(item));\n\n for (const [rowKey, row] of rows) {\n if (!wanted.has(rowKey)) {\n row.dispose();\n row.el.remove();\n rows.delete(rowKey);\n }\n }\n\n order.length = 0;\n for (const item of visible) {\n const rowKey = key(item);\n const existing = rows.get(rowKey);\n const row =\n existing === undefined\n ? makeRow(item)\n : reconcileItem(existing, item);\n if (existing === undefined) rows.set(rowKey, row);\n order.push(row);\n }\n\n let ref: Node | null = endAnchor();\n for (let index = order.length - 1; index >= 0; index--) {\n const el = order[index].el;\n if (el.parentNode !== container || el.nextSibling !== ref)\n moveNode(container, el, ref);\n ref = el;\n }\n });\n };\n\n const applyPatches = (patches: readonly ArrayPatch<T>[]): void => {\n preserveFocus(() => {\n for (const patch of patches) {\n if (patch.type === 'insert') {\n const row = makeRow(patch.item);\n rows.set(key(patch.item), row);\n order.splice(patch.index, 0, row);\n container.insertBefore(\n row.el,\n order[patch.index + 1]?.el ?? endAnchor(),\n );\n } else if (patch.type === 'remove') {\n const [row] = order.splice(patch.index, 1);\n row.dispose();\n row.el.remove();\n rows.delete(key(row.item));\n } else if (patch.type === 'move') {\n const [row] = order.splice(patch.from, 1);\n order.splice(patch.to, 0, row);\n moveNode(container, row.el, order[patch.to + 1]?.el ?? endAnchor());\n } else if (patch.type === 'update') {\n const current = order[patch.index];\n const row = reconcileItem(current, patch.item);\n if (row !== current) {\n order[patch.index] = row;\n container.insertBefore(\n row.el,\n order[patch.index + 1]?.el ?? endAnchor(),\n );\n }\n }\n }\n });\n };\n\n const dispose = (removeElements: boolean): void => {\n for (const row of rows.values()) {\n row.dispose();\n if (removeElements) row.el.remove();\n }\n rows.clear();\n order.length = 0;\n };\n\n return { order, sync, applyPatches, dispose };\n}\n","import type { BindListOptions, ListKey } from './list.js';\nimport type { ListRowController } from './list-row-controller.js';\n\ninterface ListVirtualizationController<T> {\n readonly contentVisibility: boolean;\n render: (items: readonly T[]) => void;\n start: () => void;\n setHeight: (key: ListKey, height: number) => void;\n onRender: (callback: () => void) => () => void;\n dispose: () => void;\n}\n\ninterface ListVirtualizationControllerOptions<T> {\n parent: HTMLElement;\n container: HTMLElement;\n virtualize: NonNullable<BindListOptions<T>['virtualize']>;\n key: (item: T) => ListKey;\n rows: ListRowController<T>;\n}\n\n/** A pixel height: a finite number >= 0 (zero-height rows are allowed). */\nfunction assertHeight(value: unknown, what: string): number {\n if (!(typeof value === 'number' && value >= 0 && value < Infinity))\n throw new RangeError(\n `bindList: ${what} must be a finite height >= 0 (got ${String(value)})`,\n );\n return value;\n}\n\n/** Reject an invalid `virtualize` configuration before any DOM is touched. */\nfunction validateVirtualize<T>(\n virtualize: NonNullable<BindListOptions<T>['virtualize']>,\n): void {\n const { rowHeight, overscan, minRows } = virtualize;\n for (const [name, count] of [\n ['overscan', overscan],\n ['minRows', minRows],\n ] as const) {\n if (count !== undefined && !(Number.isInteger(count) && count >= 0))\n throw new RangeError(\n `bindList: virtualize.${name} must be an integer >= 0 (got ${count})`,\n );\n }\n if (typeof rowHeight === 'number') {\n // Window mode divides by a fixed height; content-visibility only uses it as\n // a placeholder size, where zero is harmless.\n if (\n assertHeight(rowHeight, 'rowHeight') === 0 &&\n virtualize.mode !== 'content-visibility'\n )\n throw new RangeError(\n 'bindList: a fixed rowHeight must be > 0 in window mode',\n );\n } else if (typeof rowHeight !== 'function') {\n const estimate = (rowHeight as { estimate?: unknown } | null)?.estimate;\n if (typeof estimate !== 'function')\n assertHeight(estimate, 'rowHeight.estimate');\n }\n}\n\n/** Own window calculation, height models, scheduling, observers, and CSS strategy. */\nexport function createListVirtualizationController<T>(\n options: ListVirtualizationControllerOptions<T>,\n): ListVirtualizationController<T> {\n const { parent, container, virtualize, key, rows } = options;\n validateVirtualize(virtualize);\n const overscan = virtualize.overscan ?? 3;\n const { minRows, rowHeight } = virtualize;\n const contentVisibility = virtualize.mode === 'content-visibility';\n const fixedHeight = typeof rowHeight === 'number' ? rowHeight : null;\n const measuring = typeof rowHeight === 'object' && rowHeight !== null;\n const measured = new Map<ListKey, number>();\n const indexByKey = new Map<ListKey, number>();\n const renderSubscribers = new Set<() => void>();\n let items: readonly T[] = [];\n let offsets: number[] = [0];\n let heightsDirty = true;\n let pendingAnchorDelta = 0;\n let rafPending = false;\n let disposed = false;\n\n const estimateAt = (index: number): number => {\n const estimate = (\n rowHeight as { estimate: number | ((item: T, index: number) => number) }\n ).estimate;\n return typeof estimate === 'function'\n ? assertHeight(\n estimate(items[index], index),\n `rowHeight.estimate(item, ${index})`,\n )\n : estimate;\n };\n const variableHeightAt: ((index: number) => number) | null =\n fixedHeight !== null\n ? null\n : measuring\n ? (index): number =>\n measured.get(key(items[index])) ?? estimateAt(index)\n : (index): number =>\n assertHeight(\n (rowHeight as (item: T, index: number) => number)(\n items[index],\n index,\n ),\n `rowHeight(item, ${index})`,\n );\n const intrinsicSizeAt = (index: number): number =>\n fixedHeight ?? (variableHeightAt as (index: number) => number)(index);\n\n const rebuildOffsets = (): void => {\n const heightAt = variableHeightAt as (index: number) => number;\n offsets = new Array<number>(items.length + 1);\n offsets[0] = 0;\n if (measuring) indexByKey.clear();\n for (let index = 0; index < items.length; index++) {\n offsets[index + 1] = offsets[index] + heightAt(index);\n if (measuring) indexByKey.set(key(items[index]), index);\n }\n if (measuring) {\n for (const rowKey of measured.keys()) {\n if (!indexByKey.has(rowKey)) measured.delete(rowKey);\n }\n }\n };\n\n const findStart = (target: number, total: number): number => {\n let low = 0;\n let high = total;\n while (low < high) {\n const middle = (low + high + 1) >> 1;\n if (offsets[middle] <= target) low = middle;\n else high = middle - 1;\n }\n return low;\n };\n\n const findEnd = (target: number, total: number): number => {\n let low = 0;\n let high = total;\n while (low < high) {\n const middle = (low + high) >> 1;\n if (offsets[middle] >= target) high = middle;\n else low = middle + 1;\n }\n return low;\n };\n\n const sizeRows = (start: number): void => {\n if (measuring) return;\n for (let index = 0; index < rows.order.length; index++) {\n const absoluteIndex = start + index;\n const height =\n fixedHeight ?? offsets[absoluteIndex + 1] - offsets[absoluteIndex];\n rows.order[index].el.style.height = `${height}px`;\n }\n };\n\n const renderCurrent = (): void => {\n if (contentVisibility) {\n rows.sync(items);\n for (let index = 0; index < rows.order.length; index++) {\n const el = rows.order[index].el;\n el.style.contentVisibility = 'auto';\n el.style.containIntrinsicSize = `0 ${intrinsicSizeAt(index)}px`;\n }\n return;\n }\n\n const total = items.length;\n let start: number;\n let end: number;\n let padTop: number;\n let padBottom: number;\n if (minRows !== undefined && total < minRows) {\n if (fixedHeight === null && heightsDirty) {\n rebuildOffsets();\n heightsDirty = false;\n }\n start = 0;\n end = total;\n padTop = 0;\n padBottom = 0;\n } else if (fixedHeight !== null) {\n const viewportBottom = parent.scrollTop + parent.clientHeight;\n start = Math.max(\n 0,\n Math.floor(parent.scrollTop / fixedHeight) - overscan,\n );\n end = Math.min(total, Math.ceil(viewportBottom / fixedHeight) + overscan);\n padTop = start * fixedHeight;\n padBottom = Math.max(0, total - end) * fixedHeight;\n } else {\n if (heightsDirty) {\n rebuildOffsets();\n heightsDirty = false;\n }\n const viewportBottom = parent.scrollTop + parent.clientHeight;\n start = Math.max(0, findStart(parent.scrollTop, total) - overscan);\n end = Math.min(total, findEnd(viewportBottom, total) + overscan);\n padTop = offsets[start];\n padBottom = offsets[total] - offsets[end];\n }\n rows.sync(items.slice(start, end));\n sizeRows(start);\n container.style.paddingTop = `${padTop}px`;\n container.style.paddingBottom = `${padBottom}px`;\n for (const callback of renderSubscribers) callback();\n };\n\n const render = (nextItems: readonly T[]): void => {\n items = nextItems;\n heightsDirty = true;\n renderCurrent();\n };\n\n const scheduleRender = (): void => {\n if (rafPending) return;\n rafPending = true;\n globalThis.requestAnimationFrame(() => {\n rafPending = false;\n if (disposed) return;\n if (pendingAnchorDelta !== 0) {\n parent.scrollTop += pendingAnchorDelta;\n pendingAnchorDelta = 0;\n }\n renderCurrent();\n });\n };\n\n const resizeObserver =\n !contentVisibility && globalThis.ResizeObserver !== undefined\n ? new globalThis.ResizeObserver(scheduleRender)\n : undefined;\n\n const start = (): void => {\n if (contentVisibility) return;\n parent.addEventListener('scroll', scheduleRender);\n resizeObserver?.observe(parent);\n };\n\n const setHeight = (rowKey: ListKey, height: number): void => {\n assertHeight(height, 'setHeight()');\n if (!measuring || contentVisibility) return;\n const index = indexByKey.get(rowKey);\n if (index === undefined) return;\n const oldHeight = measured.get(rowKey) ?? estimateAt(index);\n if (height === oldHeight) return;\n measured.set(rowKey, height);\n if (offsets[index + 1] <= parent.scrollTop)\n pendingAnchorDelta += height - oldHeight;\n heightsDirty = true;\n scheduleRender();\n };\n\n const onRender = (callback: () => void): (() => void) => {\n renderSubscribers.add(callback);\n return () => renderSubscribers.delete(callback);\n };\n\n const dispose = (): void => {\n disposed = true;\n parent.removeEventListener('scroll', scheduleRender);\n resizeObserver?.disconnect();\n renderSubscribers.clear();\n };\n\n return { contentVisibility, render, start, setHeight, onRender, dispose };\n}\n","/**\n * `kerfjs/list` — `bindList`, a keyed list with a live per-row mount and\n * optional viewport virtualization.\n *\n * This is a DELIBERATE second list API, distinct from `each()`. It does two\n * things `each()` structurally cannot:\n * 1. **Per-row reactivity.** Every row is individually `mount()`ed, so a signal\n * the row's `render` reads updates just that row (fine-grained binding or a\n * one-row morph) without touching its siblings — no full-list pass.\n * 2. **Virtualization.** With `{ virtualize: { rowHeight } }` only the rows in\n * the scroll viewport are rendered; padding on the scroll container keeps\n * `scrollHeight` honest. `rowHeight` is a fixed `number` (O(1) windowing), a\n * `(item, index) => number` for **app-declared variable** heights (a prefix\n * sum + binary-search window), or `{ estimate }` for **measured** heights —\n * the app reports real heights via the returned handle's `setHeight` (or the\n * `observeRowHeights` helper) and kerf anchor-corrects `scrollTop`. See\n * `docs/17-list-virtualization.md`.\n *\n * `each()` stays the choice for item-owned-state lists rendered to HTML strings;\n * reach for `bindList` when you need surgical per-row updates or windowing.\n *\n * import { bindList } from 'kerfjs/list';\n *\n * const dispose = bindList(listEl, itemsSignal, {\n * key: (row) => row.id,\n * render: (row) => <span class={selected} data-id={row.id}>{row.label}</span>,\n * tag: 'li',\n * virtualize: { rowHeight: 32 },\n * });\n *\n * `render` reads signals for reactivity (external state like a `selectedId`, or\n * signals the item carries) — keep the item OBJECTS stable across renders and\n * drive structure (add/remove/move) through `itemsSignal`. A row whose item\n * object identity changes is rebuilt (same rule as `each()`'s memo). `bindList`\n * OWNS `parent`'s children by default (append/move to the end) — to share\n * `parent` with fixed trailing siblings (an \"add\" button, an indicator), pass\n * `before` so the rows end just before that node. It reads `itemsSignal.value`,\n * so a plain `signal<T[]>` or an `arraySignal<T>` both work.\n */\nimport { ARRAY_SIGNAL_BRAND, type ArrayPatch } from './array-signal.js';\nimport { createListRowController } from './list-row-controller.js';\nimport { createListVirtualizationController } from './list-virtualization-controller.js';\nimport type { MountResult } from './mount.js';\nimport { effect } from './reactive.js';\n\nconst NOOP = (): void => {\n /* intentional no-op */\n};\n\n/** A row's stable key. */\nexport type ListKey = string | number;\n\n/** Anything with a tracking `.value` array read — a `signal<readonly T[]>` or an `arraySignal<T>`. */\nexport interface ListSource<T> {\n readonly value: readonly T[];\n}\n\n/**\n * A row built imperatively by `render`: return the row **element** itself (kerf\n * keys/moves/reuses it and owns nothing inside it), or `{ el, update?, dispose? }`\n * to also hand back an `update(item)` — called on the SAME element when the row's\n * key persists but its item changes — and a `dispose` that runs only when the row\n * is removed.\n */\nexport type RowElement<T> =\n | HTMLElement\n | { el: HTMLElement; update?: (item: T) => void; dispose?: () => void };\n\n/**\n * The virtualization height model:\n * - **`number`** — every row is this fixed pixel height (O(1) windowing).\n * - **`(item, index) => number`** — app-declared **variable** heights, derived\n * purely from the item and its index.\n * - **`{ estimate }`** — **measured** heights: kerf uses `estimate` for a row\n * until the app reports its real height through {@link BindListHandle.setHeight}\n * (or the `observeRowHeights` helper). See `docs/17-list-virtualization.md`.\n */\nexport type RowHeight<T> =\n | number\n | ((item: T, index: number) => number)\n | { estimate: number | ((item: T, index: number) => number) };\n\n/**\n * The value {@link bindList} returns: a disposer you call to tear the list down,\n * augmented with `setHeight` for the **measured** virtualization mode.\n */\nexport type BindListHandle = (() => void) & {\n /**\n * Report a row's real pixel height (measured after layout) for\n * `virtualize: { rowHeight: { estimate } }` lists. Keyed by the list `key`, so\n * a report survives reorders. kerf recomputes the window and, if the row sits\n * ABOVE the viewport, anchor-corrects `scrollTop` so content doesn't jump.\n * A no-op for fixed / declared-height lists and for unknown keys.\n */\n setHeight: (key: ListKey, height: number) => void;\n /**\n * The inner container element kerf creates to hold the rows in a **virtualized**\n * list (the \"sizer\"). `undefined` for a non-virtualized list (there the rows\n * live directly in `parent`). Use it to style, id, or otherwise reach the row\n * block without guessing at `parent.lastElementChild` — though `containerClass`\n * / `containerId` on `virtualize` set those declaratively.\n */\n container?: HTMLElement;\n};\n\n/** Options for {@link bindList}. */\nexport interface BindListOptions<T> {\n /** Stable, unique per-row key. Duplicate keys are rejected before DOM mutation. */\n key: (item: T) => ListKey;\n /**\n * Build a row. Two modes, chosen per call by what you return:\n * - **Content mode** (a `MountResult` — JSX / `SafeHtml`): kerf creates the\n * row element (`tag`) and `mount()`s your content inside it, so signals your\n * content reads drive per-row reactivity.\n * - **Element mode** (an `HTMLElement`, or `{ el, update?, dispose? }`): the\n * element you return IS the row, so you own its tag, class, `data-*`, and\n * listeners. kerf **keys/moves/reuses** it — the SAME element survives an\n * append/remove/reorder or a fresh item object at the same key. Refresh its\n * content by reading signals inside it, or by returning an `update(item)`\n * that kerf calls on the existing element when the item changes. `dispose`\n * runs only when the row is genuinely removed.\n */\n render: (item: T) => MountResult | RowElement<T>;\n /** Row element tag for **content mode**. Default `'div'` (use `'li'` inside a `<ul>`, `'tr'` inside a `<tbody>`, …). Ignored in element mode. */\n tag?: string;\n /**\n * Keep the rows as a contiguous block that ENDS just before this node, instead\n * of at the very end of `parent`. Use it when `parent` also holds non-row\n * siblings that must stay put — a trailing \"add\" button, a sliding indicator:\n * `before: () => addButton`. The node (a function is re-read each reconcile, or\n * pass the node directly) must be a child of `parent`. Without it, bindList\n * assumes exclusive ownership and appends rows to the end. Ignored when\n * virtualized (the rows own bindList's inner sizer exclusively).\n */\n before?: Node | (() => Node | null);\n /**\n * Turn on viewport virtualization. `parent` must be a scroll container (your\n * CSS: a fixed height + `overflow: auto`). `overscan` (default 3) is how many\n * extra rows to render above and below the viewport. Every height must be a\n * finite, non-negative number of pixels (a fixed `rowHeight` must be > 0 in\n * `'window'` mode), and `overscan` / `minRows` non-negative integers; invalid\n * values throw a descriptive `bindList:` error.\n *\n * `rowHeight` (a {@link RowHeight}) is the height model:\n * - **`number`** — every row is this fixed pixel height. O(1) windowing, no\n * cumulative model built.\n * - **`(item, index) => number`** — app-declared **variable** heights, derived\n * purely from the item and its index. kerf builds a prefix sum of the\n * heights (rebuilt when the source array changes, not per scroll frame) and\n * binary-searches it to find the visible window. Return a non-negative\n * number of pixels.\n * - **`{ estimate }`** — **measured** heights for rows whose height is only\n * known after layout. kerf sizes an unmeasured row by `estimate` (a number\n * or an `(item, index) => number`), and the app reports each row's real\n * height via {@link BindListHandle.setHeight} (or the `observeRowHeights`\n * helper). kerf anchor-corrects `scrollTop` when an above-viewport row is\n * remeasured, so content doesn't jump.\n *\n * `minRows` renders **every** row (no windowing, zero padding) while the list\n * is shorter than it, and windows only at or above it — the DOM structure (the\n * inner container) is the same either way, so the call site never branches. A\n * fully-rendered short list is friendlier to find-in-page, screen readers, and\n * DOM-count assertions, which only see rows actually in the DOM.\n *\n * `containerClass` / `containerId` are set on the inner container kerf creates\n * to hold the rows, so it's reachable from CSS and tests without guessing at\n * `parent.lastElementChild` (it's also on the handle as `handle.container`).\n *\n * kerf re-windows on `parent`'s `scroll` and, where `ResizeObserver` exists, on\n * `parent` resizing — so a list that mounts before layout (a hidden tab,\n * `clientHeight` 0) fills in once it's sized, and a resized container re-windows.\n *\n * `mode` (default `'window'`) picks the virtualization STRATEGY:\n * - **`'window'`** — the JS windowing above: only the visible rows are in the\n * DOM, bounded node count, works on every engine. Off-window rows are removed\n * (see the findability tradeoff below).\n * - **`'content-visibility'`** — **every** row stays in the DOM and kerf sets\n * `content-visibility: auto` + `contain-intrinsic-size: 0 <rowHeight>px` on\n * each one, so a supporting engine (Chromium, Safari 18) skips the *layout /\n * paint* of off-screen rows while keeping them findable. `rowHeight` here is\n * used **only** as the `contain-intrinsic-size` placeholder (scrollbar\n * accuracy before a row is first rendered) — there is no windowing math, no\n * padding, no scroll listener, no anchor correction, and `setHeight` /\n * `observeRowHeights` are **no-ops** (the browser owns real measurement).\n * `minRows` is ignored (all rows already render). On an engine without\n * `content-visibility` the CSS is simply inert — all rows render, correct and\n * fully findable, only without the skip optimization. Choose this mode for\n * medium lists where find-in-page / a11y / anchor links matter more than the\n * node ceiling; keep `'window'` for very large (100k-row) lists.\n *\n * **Findability tradeoff (`'window'` mode).** Off-window rows are removed from\n * the DOM (not merely hidden), so with `mode: 'window'`: **find-in-page\n * (Cmd/Ctrl+F)**, **screen readers / the a11y tree**, and **anchor links /\n * `scrollIntoView`** only reach the visible window — a match, an announced row,\n * or a linked element that has been windowed out isn't in the DOM to find.\n * Convey the true total via ARIA (`aria-rowcount` / `aria-setsize`) if it\n * matters, and use a non-virtualized list — `minRows` above the list length, or\n * `mode: 'content-visibility'` — when full findability matters more than the DOM\n * node ceiling. See `docs/17-list-virtualization.md` §17.10 / §17.11.\n */\n virtualize?: {\n rowHeight: RowHeight<T>;\n overscan?: number;\n minRows?: number;\n containerClass?: string;\n containerId?: string;\n /**\n * Virtualization strategy. `'window'` (default) removes off-window rows from\n * the DOM; `'content-visibility'` keeps every row in the DOM and lets the\n * browser skip off-screen layout/paint (full find-in-page / a11y, at the cost\n * of an unbounded node count). See the option JSDoc above.\n */\n mode?: 'window' | 'content-visibility';\n };\n}\n\n/** Reject a keyed snapshot before reconciliation can alias two rows in the DOM. */\nfunction assertUniqueListKeys<T>(\n items: readonly T[],\n key: (item: T) => ListKey,\n): void {\n const firstIndex = new Map<ListKey, number>();\n for (let index = 0; index < items.length; index++) {\n const rowKey = key(items[index]);\n const first = firstIndex.get(rowKey);\n if (first !== undefined) {\n const displayed =\n typeof rowKey === 'string' ? JSON.stringify(rowKey) : String(rowKey);\n throw new Error(\n `bindList: duplicate key ${displayed} at indices ${first} and ${index} — every row key must be unique.`,\n );\n }\n firstIndex.set(rowKey, index);\n }\n}\n\n/**\n * The bound patch-queue consumer of an `arraySignal` source, or `undefined` for\n * a plain signal. A source that carries the `arraySignal` brand but no callable\n * queue (a hand-rolled or mismatched copy) is rejected with an informative error.\n */\nfunction resolvePatchConsumer<T>(\n source: ListSource<T>,\n): (() => ArrayPatch<T>[]) | undefined {\n const branded = source as {\n [ARRAY_SIGNAL_BRAND]?: unknown;\n _consumePatches?: unknown;\n };\n if (branded[ARRAY_SIGNAL_BRAND] !== true) return undefined;\n const consume = branded._consumePatches;\n if (typeof consume !== 'function') {\n throw new TypeError(\n 'bindList: source carries the arraySignal brand but has no _consumePatches() queue',\n );\n }\n return (consume as () => ArrayPatch<T>[]).bind(source);\n}\n\n/**\n * Bind a keyed, per-row-reactive list to `parent`, driven by `source` (a\n * `signal<readonly T[]>` or an `arraySignal<T>`). Returns a disposer that tears\n * down every row mount, the scroll listener (if virtualized), and the source\n * subscription.\n */\nexport function bindList<T>(\n parent: HTMLElement,\n source: ListSource<T>,\n options: BindListOptions<T>,\n): BindListHandle {\n const { key, render, tag = 'div', virtualize, before } = options;\n let firstRender = true;\n let forceSnapshot = false;\n\n // The granular path needs the arraySignal patch queue. Resolve it once, as a\n // bound function, so a branded source without one fails here with a clear\n // message instead of as a generic TypeError on the first render.\n const consumePatches =\n virtualize === undefined ? resolvePatchConsumer(source) : undefined;\n\n const container =\n virtualize === undefined ? parent : document.createElement('div');\n if (virtualize !== undefined) {\n if (virtualize.containerClass !== undefined)\n container.className = virtualize.containerClass;\n if (virtualize.containerId !== undefined)\n container.id = virtualize.containerId;\n }\n const endAnchor = (): Node | null => {\n if (virtualize !== undefined || before === undefined) return null;\n return (typeof before === 'function' ? before() : before) ?? null;\n };\n\n const rows = createListRowController({\n container,\n key,\n render,\n tag,\n endAnchor,\n });\n const virtualization =\n virtualize === undefined\n ? undefined\n : createListVirtualizationController({\n parent,\n container,\n virtualize,\n key,\n rows,\n });\n\n const renderItems = (items: readonly T[]): void => {\n if (virtualization !== undefined) {\n virtualization.render(items);\n return;\n }\n if (consumePatches !== undefined) {\n const patches = consumePatches();\n if (\n !firstRender &&\n !forceSnapshot &&\n patches.length > 0 &&\n !patches.some((patch) => patch.type === 'replace')\n ) {\n try {\n rows.applyPatches(patches);\n } catch (error) {\n forceSnapshot = true;\n throw error;\n }\n return;\n }\n }\n rows.sync(items);\n firstRender = false;\n forceSnapshot = false;\n };\n\n const track = (): void => {\n const items = source.value;\n try {\n assertUniqueListKeys(items, key);\n } catch (error) {\n if (consumePatches !== undefined) {\n consumePatches();\n forceSnapshot = true;\n }\n throw error;\n }\n renderItems(items);\n };\n\n // The first render runs synchronously inside effect(). If it throws, no\n // handle ever reaches the caller, so release every row that pass already\n // created (content mounts, element-mode dispose callbacks, DOM) here — the\n // effect itself is already disposed by effect() — and rethrow the original.\n let stopEffect: () => void;\n try {\n stopEffect = effect(track);\n } catch (error) {\n rows.dispose(true);\n virtualization?.dispose();\n throw error;\n }\n\n if (virtualization !== undefined) {\n parent.appendChild(container);\n virtualization.start();\n }\n\n const dispose = ((): void => {\n stopEffect();\n rows.dispose(virtualization === undefined);\n if (virtualization !== undefined) {\n virtualization.dispose();\n container.remove();\n VIRTUAL_INTERNALS.delete(handle);\n }\n }) as BindListHandle;\n const handle = dispose;\n handle.setHeight = virtualization?.setHeight ?? NOOP;\n\n if (virtualization !== undefined) {\n handle.container = container;\n if (!virtualization.contentVisibility) {\n VIRTUAL_INTERNALS.set(handle, {\n visibleRows: () =>\n rows.order.map((row) => ({ key: key(row.item), el: row.el })),\n onRender: virtualization.onRender,\n });\n }\n }\n\n return handle;\n}\n\n/** Internal coordination surface between {@link bindList} and {@link observeRowHeights}. */\ninterface VirtualInternals {\n /** The current visible rows, in order, with their keys. */\n visibleRows: () => Array<{ key: ListKey; el: HTMLElement }>;\n /** Subscribe to each window render; returns an unsubscribe. */\n onRender: (cb: () => void) => () => void;\n}\n\n// GC-tied (WeakMap) coordination store — a pure cache, not counted against\n// Design rule 5 (same class as `bindings.ts:insertedTextNodes`).\nconst VIRTUAL_INTERNALS = new WeakMap<object, VirtualInternals>();\n\n/**\n * Drive a **measured** virtualized `bindList` (`virtualize: { rowHeight: {\n * estimate } }`) from real layout: install ONE `ResizeObserver` over the visible\n * rows and forward each row's `offsetHeight` to `handle.setHeight`, re-observing\n * as the window shifts. Returns a disposer.\n *\n * This is the batteries-included measurement path; it is deliberately separate\n * from `bindList` (which never depends on `ResizeObserver`) — you can measure\n * however you like and call `handle.setHeight` yourself instead. A no-op for a\n * non-virtualized handle or where `ResizeObserver` is unavailable (SSR).\n *\n * const list = bindList(scrollEl, source, { key, render, virtualize: { rowHeight: { estimate: 64 } } });\n * const stopMeasuring = observeRowHeights(list);\n */\nexport function observeRowHeights(handle: BindListHandle): () => void {\n const internals = VIRTUAL_INTERNALS.get(handle);\n const RO = globalThis.ResizeObserver;\n if (internals === undefined || RO === undefined) return NOOP;\n\n const keyByEl = new WeakMap<Element, ListKey>();\n const observer = new RO((entries) => {\n for (const entry of entries) {\n const k = keyByEl.get(entry.target);\n if (k !== undefined)\n handle.setHeight(k, (entry.target as HTMLElement).offsetHeight);\n }\n });\n\n const resync = (): void => {\n observer.disconnect();\n for (const { key: k, el } of internals.visibleRows()) {\n keyByEl.set(el, k);\n observer.observe(el);\n }\n };\n\n const unsubscribe = internals.onRender(resync);\n resync(); // observe the initial window\n\n return () => {\n observer.disconnect();\n unsubscribe();\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/list-row-controller.ts","../src/list-virtualization-controller.ts","../src/list.ts"],"names":["dispose","start","NOOP"],"mappings":";;;;;;;;;;AA6BA,IAAM,OAAO,MAAY;AAEzB,CAAA;AAGO,SAAS,wBACd,OAAA,EACsB;AACtB,EAAA,MAAM,EAAE,SAAA,EAAW,GAAA,EAAK,MAAA,EAAQ,GAAA,EAAK,WAAU,GAAI,OAAA;AACnD,EAAA,MAAM,IAAA,uBAAW,GAAA,EAAyB;AAC1C,EAAA,MAAM,QAA2B,EAAC;AAElC,EAAA,MAAM,YAAA,GAAe,CACnB,QAAA,KAKU;AACV,IAAA,IAAI,oBAAoB,WAAA,EAAa,OAAO,E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A,QAAA,CAAS,QAAQ,EAAE,CAAA;AAAA,IACrB;AAAA,EACF,CAAA;AAEA,EAAA,MAAM,WAAA,GAAc,SAAA,CAAU,QAAA,CAAS,MAAM,CAAA;AAC7C,EAAA,MAAA,EAAO;AAEP,EAAA,OAAO,MAAM;AACX,IAAA,QAAA,CAAS,UAAA,EAAW;AACpB,IAAA,WAAA,EAAY;AAAA,EACd,CAAA;AACF","file":"list.js","sourcesContent":["import type { ArrayPatch } from './array-signal.js';\nimport type { BindListOptions, ListKey, RowElement } from './list.js';\nimport { captureFocus, restoreFocus } from './list-reconcile-focus.js';\nimport { mount, type MountResult } from './mount.js';\nimport { moveNode } from './utils/moveNode.js';\n\ninterface ListRow<T> {\n el: HTMLElement;\n item: T;\n dispose: () => void;\n elementMode: boolean;\n update?: (item: T) => void;\n}\n\nexport interface ListRowController<T> {\n readonly order: Array<ListRow<T>>;\n sync: (visible: readonly T[]) => void;\n applyPatches: (patches: readonly ArrayPatch<T>[]) => void;\n dispose: (removeElements: boolean) => void;\n}\n\ninterface ListRowControllerOptions<T> {\n container: HTMLElement;\n key: (item: T) => ListKey;\n render: BindListOptions<T>['render'];\n tag: string;\n endAnchor: () => Node | null;\n}\n\nconst NOOP = (): void => {\n /* element-mode rows with no caller teardown */\n};\n\n/** Own the keyed row map, DOM order, row lifecycles, and both reconcile paths. */\nexport function createListRowController<T>(\n options: ListRowControllerOptions<T>,\n): ListRowController<T> {\n const { container, key, render, tag, endAnchor } = options;\n const rows = new Map<ListKey, ListRow<T>>();\n const order: Array<ListRow<T>> = [];\n\n const asElementRow = (\n rendered: MountResult | RowElement<T>,\n ): {\n el: HTMLElement;\n dispose: () => void;\n update?: (item: T) => void;\n } | null => {\n if (rendered instanceof HTMLElement) return { el: rendered, dispose: NOOP };\n if (\n rendered !== null &&\n typeof rendered === 'object' &&\n 'el' in rendered &&\n (rendered as { el: unknown }).el instanceof HTMLElement\n ) {\n const row = rendered as {\n el: HTMLElement;\n update?: (item: T) => void;\n dispose?: () => void;\n };\n return { el: row.el, dispose: row.dispose ?? NOOP, update: row.update };\n }\n return null;\n };\n\n const makeRow = (item: T): ListRow<T> => {\n const elementRow = asElementRow(render(item));\n if (elementRow !== null) {\n return {\n el: elementRow.el,\n item,\n dispose: elementRow.dispose,\n elementMode: true,\n update: elementRow.update,\n };\n }\n const el = document.createElement(tag);\n const dispose = mount(el, () => render(item) as MountResult);\n return { el, item, dispose, elementMode: false };\n };\n\n // The single item-replacement contract used by snapshot and granular paths.\n // Element-mode rows keep their caller-owned element and are re-keyed; content\n // rows replace their mount. DOM placement remains the caller's responsibility.\n const reconcileItem = (row: ListRow<T>, item: T): ListRow<T> => {\n if (row.item === item) return row;\n const oldKey = key(row.item);\n const newKey = key(item);\n if (row.elementMode) {\n row.item = item;\n if (newKey !== oldKey) {\n rows.delete(oldKey);\n rows.set(newKey, row);\n }\n row.update?.(item);\n return row;\n }\n row.dispose();\n row.el.remove();\n rows.delete(oldKey);\n const fresh = makeRow(item);\n rows.set(newKey, fresh);\n return fresh;\n };\n\n const preserveFocus = (operation: () => void): void => {\n const focus = captureFocus(container);\n try {\n operation();\n } finally {\n if (focus !== null) restoreFocus(focus);\n }\n };\n\n const sync = (visible: readonly T[]): void => {\n preserveFocus(() => {\n const wanted = new Set<ListKey>();\n for (const item of visible) wanted.add(key(item));\n\n for (const [rowKey, row] of rows) {\n if (!wanted.has(rowKey)) {\n row.dispose();\n row.el.remove();\n rows.delete(rowKey);\n }\n }\n\n order.length = 0;\n for (const item of visible) {\n const rowKey = key(item);\n const existing = rows.get(rowKey);\n const row =\n existing === undefined\n ? makeRow(item)\n : reconcileItem(existing, item);\n if (existing === undefined) rows.set(rowKey, row);\n order.push(row);\n }\n\n let ref: Node | null = endAnchor();\n for (let index = order.length - 1; index >= 0; index--) {\n const el = order[index].el;\n if (el.parentNode !== container || el.nextSibling !== ref)\n moveNode(container, el, ref);\n ref = el;\n }\n });\n };\n\n const applyPatches = (patches: readonly ArrayPatch<T>[]): void => {\n preserveFocus(() => {\n for (const patch of patches) {\n if (patch.type === 'insert') {\n const row = makeRow(patch.item);\n rows.set(key(patch.item), row);\n order.splice(patch.index, 0, row);\n container.insertBefore(\n row.el,\n order[patch.index + 1]?.el ?? endAnchor(),\n );\n } else if (patch.type === 'remove') {\n const [row] = order.splice(patch.index, 1);\n row.dispose();\n row.el.remove();\n rows.delete(key(row.item));\n } else if (patch.type === 'move') {\n const [row] = order.splice(patch.from, 1);\n order.splice(patch.to, 0, row);\n moveNode(container, row.el, order[patch.to + 1]?.el ?? endAnchor());\n } else if (patch.type === 'update') {\n const current = order[patch.index];\n const row = reconcileItem(current, patch.item);\n if (row !== current) {\n order[patch.index] = row;\n container.insertBefore(\n row.el,\n order[patch.index + 1]?.el ?? endAnchor(),\n );\n }\n }\n }\n });\n };\n\n const dispose = (removeElements: boolean): void => {\n for (const row of rows.values()) {\n row.dispose();\n if (removeElements) row.el.remove();\n }\n rows.clear();\n order.length = 0;\n };\n\n return { order, sync, applyPatches, dispose };\n}\n","import type { BindListOptions, ListKey } from './list.js';\nimport type { ListRowController } from './list-row-controller.js';\n\ninterface ListVirtualizationController<T> {\n readonly contentVisibility: boolean;\n render: (items: readonly T[]) => void;\n start: () => void;\n setHeight: (key: ListKey, height: number) => void;\n onRender: (callback: () => void) => () => void;\n dispose: () => void;\n}\n\ninterface ListVirtualizationControllerOptions<T> {\n parent: HTMLElement;\n container: HTMLElement;\n virtualize: NonNullable<BindListOptions<T>['virtualize']>;\n key: (item: T) => ListKey;\n rows: ListRowController<T>;\n}\n\n/** A pixel height: a finite number >= 0 (zero-height rows are allowed). */\nfunction assertHeight(value: unknown, what: string): number {\n if (!(typeof value === 'number' && value >= 0 && value < Infinity))\n throw new RangeError(\n `bindList: ${what} must be a finite height >= 0 (got ${String(value)})`,\n );\n return value;\n}\n\n/** Reject an invalid `virtualize` configuration before any DOM is touched. */\nfunction validateVirtualize<T>(\n virtualize: NonNullable<BindListOptions<T>['virtualize']>,\n): void {\n const { rowHeight, overscan, minRows } = virtualize;\n for (const [name, count] of [\n ['overscan', overscan],\n ['minRows', minRows],\n ] as const) {\n if (count !== undefined && !(Number.isInteger(count) && count >= 0))\n throw new RangeError(\n `bindList: virtualize.${name} must be an integer >= 0 (got ${count})`,\n );\n }\n if (typeof rowHeight === 'number') {\n // Window mode divides by a fixed height; content-visibility only uses it as\n // a placeholder size, where zero is harmless.\n if (\n assertHeight(rowHeight, 'rowHeight') === 0 &&\n virtualize.mode !== 'content-visibility'\n )\n throw new RangeError(\n 'bindList: a fixed rowHeight must be > 0 in window mode',\n );\n } else if (typeof rowHeight !== 'function') {\n const estimate = (rowHeight as { estimate?: unknown } | null)?.estimate;\n if (typeof estimate !== 'function')\n assertHeight(estimate, 'rowHeight.estimate');\n }\n}\n\n/** Own window calculation, height models, scheduling, observers, and CSS strategy. */\nexport function createListVirtualizationController<T>(\n options: ListVirtualizationControllerOptions<T>,\n): ListVirtualizationController<T> {\n const { parent, container, virtualize, key, rows } = options;\n validateVirtualize(virtualize);\n const overscan = virtualize.overscan ?? 3;\n const { minRows, rowHeight } = virtualize;\n const contentVisibility = virtualize.mode === 'content-visibility';\n const fixedHeight = typeof rowHeight === 'number' ? rowHeight : null;\n const measuring = typeof rowHeight === 'object' && rowHeight !== null;\n const measured = new Map<ListKey, number>();\n const indexByKey = new Map<ListKey, number>();\n const renderSubscribers = new Set<() => void>();\n let items: readonly T[] = [];\n let offsets: number[] = [0];\n let heightsDirty = true;\n // Measured-mode anchor correction is resolved at frame time, not at\n // setHeight() time: each key remembers the height it had before its first\n // report this frame, and the frame applies the net change only for keys\n // still in the source AND still above the viewport top. A delta summed at\n // report time went stale when the source removed or reordered the key, or\n // the user scrolled, before the frame ran (KF-FJ40AE).\n const pendingAnchorBaselines = new Map<ListKey, number>();\n let rafPending = false;\n let disposed = false;\n\n const estimateAt = (index: number): number => {\n const estimate = (\n rowHeight as { estimate: number | ((item: T, index: number) => number) }\n ).estimate;\n return typeof estimate === 'function'\n ? assertHeight(\n estimate(items[index], index),\n `rowHeight.estimate(item, ${index})`,\n )\n : estimate;\n };\n const variableHeightAt: ((index: number) => number) | null =\n fixedHeight !== null\n ? null\n : measuring\n ? (index): number =>\n measured.get(key(items[index])) ?? estimateAt(index)\n : (index): number =>\n assertHeight(\n (rowHeight as (item: T, index: number) => number)(\n items[index],\n index,\n ),\n `rowHeight(item, ${index})`,\n );\n const intrinsicSizeAt = (index: number): number =>\n fixedHeight ?? (variableHeightAt as (index: number) => number)(index);\n\n const rebuildOffsets = (): void => {\n const heightAt = variableHeightAt as (index: number) => number;\n offsets = new Array<number>(items.length + 1);\n offsets[0] = 0;\n if (measuring) indexByKey.clear();\n for (let index = 0; index < items.length; index++) {\n offsets[index + 1] = offsets[index] + heightAt(index);\n if (measuring) indexByKey.set(key(items[index]), index);\n }\n if (measuring) {\n for (const rowKey of measured.keys()) {\n if (!indexByKey.has(rowKey)) measured.delete(rowKey);\n }\n for (const rowKey of pendingAnchorBaselines.keys()) {\n if (!indexByKey.has(rowKey)) pendingAnchorBaselines.delete(rowKey);\n }\n }\n };\n\n const findStart = (target: number, total: number): number => {\n let low = 0;\n let high = total;\n while (low < high) {\n const middle = (low + high + 1) >> 1;\n if (offsets[middle] <= target) low = middle;\n else high = middle - 1;\n }\n return low;\n };\n\n const findEnd = (target: number, total: number): number => {\n let low = 0;\n let high = total;\n while (low < high) {\n const middle = (low + high) >> 1;\n if (offsets[middle] >= target) high = middle;\n else low = middle + 1;\n }\n return low;\n };\n\n const sizeRows = (start: number): void => {\n if (measuring) return;\n for (let index = 0; index < rows.order.length; index++) {\n const absoluteIndex = start + index;\n const height =\n fixedHeight ?? offsets[absoluteIndex + 1] - offsets[absoluteIndex];\n rows.order[index].el.style.height = `${height}px`;\n }\n };\n\n const renderCurrent = (): void => {\n if (contentVisibility) {\n rows.sync(items);\n for (let index = 0; index < rows.order.length; index++) {\n const el = rows.order[index].el;\n el.style.contentVisibility = 'auto';\n el.style.containIntrinsicSize = `0 ${intrinsicSizeAt(index)}px`;\n }\n return;\n }\n\n const total = items.length;\n let start: number;\n let end: number;\n let padTop: number;\n let padBottom: number;\n if (minRows !== undefined && total < minRows) {\n if (fixedHeight === null && heightsDirty) {\n rebuildOffsets();\n heightsDirty = false;\n }\n start = 0;\n end = total;\n padTop = 0;\n padBottom = 0;\n } else if (fixedHeight !== null) {\n const viewportBottom = parent.scrollTop + parent.clientHeight;\n // Clamp to `total`: a source that shrinks while scrolled deep (before the\n // browser clamps scrollTop) must not pad past the content (KF-FJ40AE).\n start = Math.min(\n total,\n Math.max(0, Math.floor(parent.scrollTop / fixedHeight) - overscan),\n );\n end = Math.min(total, Math.ceil(viewportBottom / fixedHeight) + overscan);\n padTop = start * fixedHeight;\n padBottom = Math.max(0, total - end) * fixedHeight;\n } else {\n if (heightsDirty) {\n rebuildOffsets();\n heightsDirty = false;\n }\n const viewportBottom = parent.scrollTop + parent.clientHeight;\n start = Math.max(0, findStart(parent.scrollTop, total) - overscan);\n end = Math.min(total, findEnd(viewportBottom, total) + overscan);\n padTop = offsets[start];\n padBottom = offsets[total] - offsets[end];\n }\n rows.sync(items.slice(start, end));\n sizeRows(start);\n container.style.paddingTop = `${padTop}px`;\n container.style.paddingBottom = `${padBottom}px`;\n for (const callback of renderSubscribers) callback();\n };\n\n const render = (nextItems: readonly T[]): void => {\n items = nextItems;\n heightsDirty = true;\n renderCurrent();\n };\n\n const applyAnchorCorrection = (): void => {\n if (heightsDirty) {\n rebuildOffsets();\n heightsDirty = false;\n }\n let delta = 0;\n for (const [rowKey, baseline] of pendingAnchorBaselines) {\n // rebuildOffsets() just pruned every key that left the source.\n const index = indexByKey.get(rowKey) as number;\n if (offsets[index] + baseline <= parent.scrollTop)\n delta += offsets[index + 1] - offsets[index] - baseline;\n }\n pendingAnchorBaselines.clear();\n if (delta !== 0) parent.scrollTop += delta;\n };\n\n const scheduleRender = (): void => {\n if (rafPending) return;\n rafPending = true;\n globalThis.requestAnimationFrame(() => {\n rafPending = false;\n if (disposed) return;\n if (pendingAnchorBaselines.size > 0) applyAnchorCorrection();\n renderCurrent();\n });\n };\n\n const resizeObserver =\n !contentVisibility && globalThis.ResizeObserver !== undefined\n ? new globalThis.ResizeObserver(scheduleRender)\n : undefined;\n\n const start = (): void => {\n if (contentVisibility) return;\n parent.addEventListener('scroll', scheduleRender);\n resizeObserver?.observe(parent);\n };\n\n const setHeight = (rowKey: ListKey, height: number): void => {\n assertHeight(height, 'setHeight()');\n if (!measuring || contentVisibility) return;\n const index = indexByKey.get(rowKey);\n if (index === undefined) return;\n const oldHeight = measured.get(rowKey) ?? estimateAt(index);\n if (height === oldHeight) return;\n measured.set(rowKey, height);\n if (!pendingAnchorBaselines.has(rowKey))\n pendingAnchorBaselines.set(rowKey, oldHeight);\n heightsDirty = true;\n scheduleRender();\n };\n\n const onRender = (callback: () => void): (() => void) => {\n renderSubscribers.add(callback);\n return () => renderSubscribers.delete(callback);\n };\n\n const dispose = (): void => {\n disposed = true;\n parent.removeEventListener('scroll', scheduleRender);\n resizeObserver?.disconnect();\n renderSubscribers.clear();\n };\n\n return { contentVisibility, render, start, setHeight, onRender, dispose };\n}\n","/**\n * `kerfjs/list` — `bindList`, a keyed list with a live per-row mount and\n * optional viewport virtualization.\n *\n * This is a DELIBERATE second list API, distinct from `each()`. It does two\n * things `each()` structurally cannot:\n * 1. **Per-row reactivity.** Every row is individually `mount()`ed, so a signal\n * the row's `render` reads updates just that row (fine-grained binding or a\n * one-row morph) without touching its siblings — no full-list pass.\n * 2. **Virtualization.** With `{ virtualize: { rowHeight } }` only the rows in\n * the scroll viewport are rendered; padding on the scroll container keeps\n * `scrollHeight` honest. `rowHeight` is a fixed `number` (O(1) windowing), a\n * `(item, index) => number` for **app-declared variable** heights (a prefix\n * sum + binary-search window), or `{ estimate }` for **measured** heights —\n * the app reports real heights via the returned handle's `setHeight` (or the\n * `observeRowHeights` helper) and kerf anchor-corrects `scrollTop`. See\n * `docs/17-list-virtualization.md`.\n *\n * `each()` stays the choice for item-owned-state lists rendered to HTML strings;\n * reach for `bindList` when you need surgical per-row updates or windowing.\n *\n * import { bindList } from 'kerfjs/list';\n *\n * const dispose = bindList(listEl, itemsSignal, {\n * key: (row) => row.id,\n * render: (row) => <span class={selected} data-id={row.id}>{row.label}</span>,\n * tag: 'li',\n * virtualize: { rowHeight: 32 },\n * });\n *\n * `render` reads signals for reactivity (external state like a `selectedId`, or\n * signals the item carries) — keep the item OBJECTS stable across renders and\n * drive structure (add/remove/move) through `itemsSignal`. A row whose item\n * object identity changes is rebuilt (same rule as `each()`'s memo). `bindList`\n * OWNS `parent`'s children by default (append/move to the end) — to share\n * `parent` with fixed trailing siblings (an \"add\" button, an indicator), pass\n * `before` so the rows end just before that node. It reads `itemsSignal.value`,\n * so a plain `signal<T[]>` or an `arraySignal<T>` both work.\n */\nimport { ARRAY_SIGNAL_BRAND, type ArrayPatch } from './array-signal.js';\nimport { createListRowController } from './list-row-controller.js';\nimport { createListVirtualizationController } from './list-virtualization-controller.js';\nimport type { MountResult } from './mount.js';\nimport { effect } from './reactive.js';\n\nconst NOOP = (): void => {\n /* intentional no-op */\n};\n\n/** A row's stable key. */\nexport type ListKey = string | number;\n\n/** Anything with a tracking `.value` array read — a `signal<readonly T[]>` or an `arraySignal<T>`. */\nexport interface ListSource<T> {\n readonly value: readonly T[];\n}\n\n/**\n * A row built imperatively by `render`: return the row **element** itself (kerf\n * keys/moves/reuses it and owns nothing inside it), or `{ el, update?, dispose? }`\n * to also hand back an `update(item)` — called on the SAME element when the row's\n * key persists but its item changes — and a `dispose` that runs only when the row\n * is removed.\n */\nexport type RowElement<T> =\n | HTMLElement\n | { el: HTMLElement; update?: (item: T) => void; dispose?: () => void };\n\n/**\n * The virtualization height model:\n * - **`number`** — every row is this fixed pixel height (O(1) windowing).\n * - **`(item, index) => number`** — app-declared **variable** heights, derived\n * purely from the item and its index.\n * - **`{ estimate }`** — **measured** heights: kerf uses `estimate` for a row\n * until the app reports its real height through {@link BindListHandle.setHeight}\n * (or the `observeRowHeights` helper). See `docs/17-list-virtualization.md`.\n */\nexport type RowHeight<T> =\n | number\n | ((item: T, index: number) => number)\n | { estimate: number | ((item: T, index: number) => number) };\n\n/**\n * The value {@link bindList} returns: a disposer you call to tear the list down,\n * augmented with `setHeight` for the **measured** virtualization mode.\n */\nexport type BindListHandle = (() => void) & {\n /**\n * Report a row's real pixel height (measured after layout) for\n * `virtualize: { rowHeight: { estimate } }` lists. Keyed by the list `key`, so\n * a report survives reorders. kerf recomputes the window and, if the row sits\n * ABOVE the viewport, anchor-corrects `scrollTop` so content doesn't jump.\n * A no-op for fixed / declared-height lists and for unknown keys.\n */\n setHeight: (key: ListKey, height: number) => void;\n /**\n * The inner container element kerf creates to hold the rows in a **virtualized**\n * list (the \"sizer\"). `undefined` for a non-virtualized list (there the rows\n * live directly in `parent`). Use it to style, id, or otherwise reach the row\n * block without guessing at `parent.lastElementChild` — though `containerClass`\n * / `containerId` on `virtualize` set those declaratively.\n */\n container?: HTMLElement;\n};\n\n/** Options for {@link bindList}. */\nexport interface BindListOptions<T> {\n /** Stable, unique per-row key. Duplicate keys are rejected before DOM mutation. */\n key: (item: T) => ListKey;\n /**\n * Build a row. Two modes, chosen per call by what you return:\n * - **Content mode** (a `MountResult` — JSX / `SafeHtml`): kerf creates the\n * row element (`tag`) and `mount()`s your content inside it, so signals your\n * content reads drive per-row reactivity.\n * - **Element mode** (an `HTMLElement`, or `{ el, update?, dispose? }`): the\n * element you return IS the row, so you own its tag, class, `data-*`, and\n * listeners. kerf **keys/moves/reuses** it — the SAME element survives an\n * append/remove/reorder or a fresh item object at the same key. Refresh its\n * content by reading signals inside it, or by returning an `update(item)`\n * that kerf calls on the existing element when the item changes. `dispose`\n * runs only when the row is genuinely removed.\n */\n render: (item: T) => MountResult | RowElement<T>;\n /** Row element tag for **content mode**. Default `'div'` (use `'li'` inside a `<ul>`, `'tr'` inside a `<tbody>`, …). Ignored in element mode. */\n tag?: string;\n /**\n * Keep the rows as a contiguous block that ENDS just before this node, instead\n * of at the very end of `parent`. Use it when `parent` also holds non-row\n * siblings that must stay put — a trailing \"add\" button, a sliding indicator:\n * `before: () => addButton`. The node (a function is re-read each reconcile, or\n * pass the node directly) must be a child of `parent`. Without it, bindList\n * assumes exclusive ownership and appends rows to the end. Ignored when\n * virtualized (the rows own bindList's inner sizer exclusively).\n */\n before?: Node | (() => Node | null);\n /**\n * Turn on viewport virtualization. `parent` must be a scroll container (your\n * CSS: a fixed height + `overflow: auto`). `overscan` (default 3) is how many\n * extra rows to render above and below the viewport. Every height must be a\n * finite, non-negative number of pixels (a fixed `rowHeight` must be > 0 in\n * `'window'` mode), and `overscan` / `minRows` non-negative integers; invalid\n * values throw a descriptive `bindList:` error.\n *\n * `rowHeight` (a {@link RowHeight}) is the height model:\n * - **`number`** — every row is this fixed pixel height. O(1) windowing, no\n * cumulative model built.\n * - **`(item, index) => number`** — app-declared **variable** heights, derived\n * purely from the item and its index. kerf builds a prefix sum of the\n * heights (rebuilt when the source array changes, not per scroll frame) and\n * binary-searches it to find the visible window. Return a non-negative\n * number of pixels.\n * - **`{ estimate }`** — **measured** heights for rows whose height is only\n * known after layout. kerf sizes an unmeasured row by `estimate` (a number\n * or an `(item, index) => number`), and the app reports each row's real\n * height via {@link BindListHandle.setHeight} (or the `observeRowHeights`\n * helper). kerf anchor-corrects `scrollTop` when an above-viewport row is\n * remeasured, so content doesn't jump.\n *\n * `minRows` renders **every** row (no windowing, zero padding) while the list\n * is shorter than it, and windows only at or above it — the DOM structure (the\n * inner container) is the same either way, so the call site never branches. A\n * fully-rendered short list is friendlier to find-in-page, screen readers, and\n * DOM-count assertions, which only see rows actually in the DOM.\n *\n * `containerClass` / `containerId` are set on the inner container kerf creates\n * to hold the rows, so it's reachable from CSS and tests without guessing at\n * `parent.lastElementChild` (it's also on the handle as `handle.container`).\n *\n * kerf re-windows on `parent`'s `scroll` and, where `ResizeObserver` exists, on\n * `parent` resizing — so a list that mounts before layout (a hidden tab,\n * `clientHeight` 0) fills in once it's sized, and a resized container re-windows.\n *\n * `mode` (default `'window'`) picks the virtualization STRATEGY:\n * - **`'window'`** — the JS windowing above: only the visible rows are in the\n * DOM, bounded node count, works on every engine. Off-window rows are removed\n * (see the findability tradeoff below).\n * - **`'content-visibility'`** — **every** row stays in the DOM and kerf sets\n * `content-visibility: auto` + `contain-intrinsic-size: 0 <rowHeight>px` on\n * each one, so a supporting engine (Chromium, Safari 18) skips the *layout /\n * paint* of off-screen rows while keeping them findable. `rowHeight` here is\n * used **only** as the `contain-intrinsic-size` placeholder (scrollbar\n * accuracy before a row is first rendered) — there is no windowing math, no\n * padding, no scroll listener, no anchor correction, and `setHeight` /\n * `observeRowHeights` are **no-ops** (the browser owns real measurement).\n * `minRows` is ignored (all rows already render). On an engine without\n * `content-visibility` the CSS is simply inert — all rows render, correct and\n * fully findable, only without the skip optimization. Choose this mode for\n * medium lists where find-in-page / a11y / anchor links matter more than the\n * node ceiling; keep `'window'` for very large (100k-row) lists.\n *\n * **Findability tradeoff (`'window'` mode).** Off-window rows are removed from\n * the DOM (not merely hidden), so with `mode: 'window'`: **find-in-page\n * (Cmd/Ctrl+F)**, **screen readers / the a11y tree**, and **anchor links /\n * `scrollIntoView`** only reach the visible window — a match, an announced row,\n * or a linked element that has been windowed out isn't in the DOM to find.\n * Convey the true total via ARIA (`aria-rowcount` / `aria-setsize`) if it\n * matters, and use a non-virtualized list — `minRows` above the list length, or\n * `mode: 'content-visibility'` — when full findability matters more than the DOM\n * node ceiling. See `docs/17-list-virtualization.md` §17.10 / §17.11.\n */\n virtualize?: {\n rowHeight: RowHeight<T>;\n overscan?: number;\n minRows?: number;\n containerClass?: string;\n containerId?: string;\n /**\n * Virtualization strategy. `'window'` (default) removes off-window rows from\n * the DOM; `'content-visibility'` keeps every row in the DOM and lets the\n * browser skip off-screen layout/paint (full find-in-page / a11y, at the cost\n * of an unbounded node count). See the option JSDoc above.\n */\n mode?: 'window' | 'content-visibility';\n };\n}\n\n/** Reject a keyed snapshot before reconciliation can alias two rows in the DOM. */\nfunction assertUniqueListKeys<T>(\n items: readonly T[],\n key: (item: T) => ListKey,\n): void {\n const firstIndex = new Map<ListKey, number>();\n for (let index = 0; index < items.length; index++) {\n const rowKey = key(items[index]);\n const first = firstIndex.get(rowKey);\n if (first !== undefined) {\n const displayed =\n typeof rowKey === 'string' ? JSON.stringify(rowKey) : String(rowKey);\n throw new Error(\n `bindList: duplicate key ${displayed} at indices ${first} and ${index} — every row key must be unique.`,\n );\n }\n firstIndex.set(rowKey, index);\n }\n}\n\n/**\n * The bound patch-queue consumer of an `arraySignal` source, or `undefined` for\n * a plain signal. A source that carries the `arraySignal` brand but no callable\n * queue (a hand-rolled or mismatched copy) is rejected with an informative error.\n */\nfunction resolvePatchConsumer<T>(\n source: ListSource<T>,\n): (() => ArrayPatch<T>[]) | undefined {\n const branded = source as {\n [ARRAY_SIGNAL_BRAND]?: unknown;\n _consumePatches?: unknown;\n };\n if (branded[ARRAY_SIGNAL_BRAND] !== true) return undefined;\n const consume = branded._consumePatches;\n if (typeof consume !== 'function') {\n throw new TypeError(\n 'bindList: source carries the arraySignal brand but has no _consumePatches() queue',\n );\n }\n return (consume as () => ArrayPatch<T>[]).bind(source);\n}\n\n/**\n * Bind a keyed, per-row-reactive list to `parent`, driven by `source` (a\n * `signal<readonly T[]>` or an `arraySignal<T>`). Returns a disposer that tears\n * down every row mount, the scroll listener (if virtualized), and the source\n * subscription.\n */\nexport function bindList<T>(\n parent: HTMLElement,\n source: ListSource<T>,\n options: BindListOptions<T>,\n): BindListHandle {\n const { key, render, tag = 'div', virtualize, before } = options;\n let firstRender = true;\n let forceSnapshot = false;\n\n // The granular path needs the arraySignal patch queue. Resolve it once, as a\n // bound function, so a branded source without one fails here with a clear\n // message instead of as a generic TypeError on the first render.\n const consumePatches =\n virtualize === undefined ? resolvePatchConsumer(source) : undefined;\n\n const container =\n virtualize === undefined ? parent : document.createElement('div');\n if (virtualize !== undefined) {\n if (virtualize.containerClass !== undefined)\n container.className = virtualize.containerClass;\n if (virtualize.containerId !== undefined)\n container.id = virtualize.containerId;\n }\n const endAnchor = (): Node | null => {\n if (virtualize !== undefined || before === undefined) return null;\n return (typeof before === 'function' ? before() : before) ?? null;\n };\n\n const rows = createListRowController({\n container,\n key,\n render,\n tag,\n endAnchor,\n });\n const virtualization =\n virtualize === undefined\n ? undefined\n : createListVirtualizationController({\n parent,\n container,\n virtualize,\n key,\n rows,\n });\n\n const renderItems = (items: readonly T[]): void => {\n if (virtualization !== undefined) {\n virtualization.render(items);\n return;\n }\n if (consumePatches !== undefined) {\n const patches = consumePatches();\n if (\n !firstRender &&\n !forceSnapshot &&\n patches.length > 0 &&\n !patches.some((patch) => patch.type === 'replace')\n ) {\n try {\n rows.applyPatches(patches);\n } catch (error) {\n forceSnapshot = true;\n throw error;\n }\n return;\n }\n }\n rows.sync(items);\n firstRender = false;\n forceSnapshot = false;\n };\n\n const track = (): void => {\n const items = source.value;\n try {\n assertUniqueListKeys(items, key);\n } catch (error) {\n if (consumePatches !== undefined) {\n consumePatches();\n forceSnapshot = true;\n }\n throw error;\n }\n renderItems(items);\n };\n\n // The first render runs synchronously inside effect(). If it throws, no\n // handle ever reaches the caller, so release every row that pass already\n // created (content mounts, element-mode dispose callbacks, DOM) here — the\n // effect itself is already disposed by effect() — and rethrow the original.\n let stopEffect: () => void;\n try {\n stopEffect = effect(track);\n } catch (error) {\n rows.dispose(true);\n virtualization?.dispose();\n throw error;\n }\n\n if (virtualization !== undefined) {\n parent.appendChild(container);\n virtualization.start();\n }\n\n const dispose = ((): void => {\n stopEffect();\n rows.dispose(virtualization === undefined);\n if (virtualization !== undefined) {\n virtualization.dispose();\n container.remove();\n VIRTUAL_INTERNALS.delete(handle);\n }\n }) as BindListHandle;\n const handle = dispose;\n handle.setHeight = virtualization?.setHeight ?? NOOP;\n\n if (virtualization !== undefined) {\n handle.container = container;\n if (!virtualization.contentVisibility) {\n VIRTUAL_INTERNALS.set(handle, {\n visibleRows: () =>\n rows.order.map((row) => ({ key: key(row.item), el: row.el })),\n onRender: virtualization.onRender,\n });\n }\n }\n\n return handle;\n}\n\n/** Internal coordination surface between {@link bindList} and {@link observeRowHeights}. */\ninterface VirtualInternals {\n /** The current visible rows, in order, with their keys. */\n visibleRows: () => Array<{ key: ListKey; el: HTMLElement }>;\n /** Subscribe to each window render; returns an unsubscribe. */\n onRender: (cb: () => void) => () => void;\n}\n\n// GC-tied (WeakMap) coordination store — a pure cache, not counted against\n// Design rule 5 (same class as `bindings.ts:insertedTextNodes`).\nconst VIRTUAL_INTERNALS = new WeakMap<object, VirtualInternals>();\n\n/**\n * Drive a **measured** virtualized `bindList` (`virtualize: { rowHeight: {\n * estimate } }`) from real layout: install ONE `ResizeObserver` over the visible\n * rows and forward each row's `offsetHeight` to `handle.setHeight`, re-observing\n * as the window shifts. Returns a disposer.\n *\n * This is the batteries-included measurement path; it is deliberately separate\n * from `bindList` (which never observes rows; its only `ResizeObserver` use is\n * an optional observer on the scroll parent that re-windows on resize) — you\n * can measure however you like and call `handle.setHeight` yourself instead. A no-op for a\n * non-virtualized handle or where `ResizeObserver` is unavailable (SSR).\n *\n * const list = bindList(scrollEl, source, { key, render, virtualize: { rowHeight: { estimate: 64 } } });\n * const stopMeasuring = observeRowHeights(list);\n */\nexport function observeRowHeights(handle: BindListHandle): () => void {\n const internals = VIRTUAL_INTERNALS.get(handle);\n const RO = globalThis.ResizeObserver;\n if (internals === undefined || RO === undefined) return NOOP;\n\n const keyByEl = new WeakMap<Element, ListKey>();\n const observer = new RO((entries) => {\n for (const entry of entries) {\n const k = keyByEl.get(entry.target);\n if (k !== undefined)\n handle.setHeight(k, (entry.target as HTMLElement).offsetHeight);\n }\n });\n\n const resync = (): void => {\n observer.disconnect();\n for (const { key: k, el } of internals.visibleRows()) {\n keyByEl.set(el, k);\n observer.observe(el);\n }\n };\n\n const unsubscribe = internals.onRender(resync);\n resync(); // observe the initial window\n\n return () => {\n observer.disconnect();\n unsubscribe();\n };\n}\n"]}
|
package/dist/overlay.d.ts
CHANGED
|
@@ -39,28 +39,6 @@ declare function positionAnchored(el: HTMLElement, anchor: Element, options?: An
|
|
|
39
39
|
*/
|
|
40
40
|
declare function autoReposition(el: HTMLElement, anchor: Element, options?: AnchorPositionOptions): () => void;
|
|
41
41
|
|
|
42
|
-
/**
|
|
43
|
-
* Internal overlay / popover / tooltip lifecycle implementation.
|
|
44
|
-
*
|
|
45
|
-
* Every real kerf app hand-rolls this: `toElement → body.appendChild → mount →
|
|
46
|
-
* wire dismissal → remove`, plus the fiddly parts (Escape, backdrop / outside
|
|
47
|
-
* click, focus trap, restoring focus on close). `window.confirm` is a no-op in
|
|
48
|
-
* Tauri WKWebViews, so a hand-built overlay is mandatory there. This subpath
|
|
49
|
-
* blesses the pattern as three functions over `mount()` — `overlay()`, and the
|
|
50
|
-
* `confirm()` / `toast()` conveniences built on it. No per-instance framework
|
|
51
|
-
* state: each call owns its DOM + listeners in a closure and returns a handle.
|
|
52
|
-
*
|
|
53
|
-
* import { overlay, confirm, toast } from 'kerfjs/overlay';
|
|
54
|
-
*
|
|
55
|
-
* const ok = await confirm('Delete this file?', { danger: true });
|
|
56
|
-
* toast('Saved');
|
|
57
|
-
* const dialog = overlay(<Settings />, { dismiss: ['escape', 'backdrop'] });
|
|
58
|
-
* // …later: dialog.close(); or await dialog.result;
|
|
59
|
-
*
|
|
60
|
-
* Structural only — kerf ships no CSS. The wrapper gets your `className`; style
|
|
61
|
-
* the backdrop / centering / animation yourself.
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
42
|
/** A user-initiated dismissal trigger. */
|
|
65
43
|
type DismissTrigger = 'escape' | 'backdrop' | 'outside';
|
|
66
44
|
/** Content for an overlay: static `SafeHtml`, or a render function `mount()` drives reactively. */
|