kerfjs 0.3.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/delegate.ts","../src/each.ts","../src/diff.ts","../src/list-reconcile.ts","../src/mount.ts","../src/toElement.ts"],"names":[],"mappings":";;;;;;AA6BA,SAAS,mBAAA,CAAoB,UAAkB,EAAA,EAAkB;AAC/D,EAAA,IAAI;AACF,IAAA,QAAA,CAAS,aAAA,CAAc,KAAK,CAAA,CAAE,OAAA,CAAQ,QAAQ,CAAA;AAAA,EAChD,CAAA,CAAA,MAAQ;AACN,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,EAAG,EAAE,CAAA,oBAAA,EAAuB,QAAQ,CAAA,2EAAA;AAAA,KAEtC;AAAA,EACF;AACF;AAaO,SAAS,QAAA,CACd,MAAA,EACA,IAAA,EACA,QAAA,EACA,OAAA,EACY;AACZ,EAAA,mBAAA,CAAoB,UAAU,UAAU,CAAA;AACxC,EAAA,MAAM,QAAA,GAAW,CAAC,KAAA,KAAuB;AACvC,IAAA,MAAM,SAAS,KAAA,CAAM,MAAA;AACrB,IAAA,IAAI,EAAE,kBAAkB,OAAA,CAAA,EAAU;AAClC,IAAA,MAAM,OAAA,GAAU,MAAA,CAAO,OAAA,CAAQ,QAAQ,CAAA;AACvC,IAAA,IAAI,OAAA,KAAY,IAAA,IAAQ,MAAA,CAAO,QAAA,CAAS,OAAO,CAAA,EAAG;AAChD,MAAA,OAAA,CAAQ,OAAO,OAAO,CAAA;AAAA,IACxB;AAAA,EACF,CAAA;AACA,EAAA,MAAA,CAAO,gBAAA,CAAiB,MAAM,QAAQ,CAAA;AACtC,EAAA,OAAO,MAAM;AACX,IAAA,MAAA,CAAO,mBAAA,CAAoB,MAAM,QAAQ,CAAA;AAAA,EAC3C,CAAA;AACF;AAUO,SAAS,eAAA,CACd,MAAA,EACA,IAA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AA,MAAM,GAAA,GAAM,WAAW,IAAI,CAAA;AAE3B,EAAA,IAAI,QAAQ,KAAA,EAAO;AAEjB,IAAA,OAAO,eAAA,CAAgB,IAAA,EAAM,KAAA,EAAO,IAAI,CAAA,CAAE,eAAA;AAAA,EAC5C;AAEA,EAAA,IAAI,GAAA,KAAQ,IAAA,IAAQ,iBAAA,CAAkB,GAAA,CAAI,GAAG,CAAA,EAAG;AAE9C,IAAA,MAAM,OAAA,GAAU,CAAA,YAAA,EAAe,MAAM,CAAA,EAAA,EAAK,IAAI,CAAA,MAAA,CAAA;AAC9C,IAAA,MAAM,GAAA,GAAM,eAAA,CAAgB,OAAA,EAAS,cAAA,EAAgB,IAAI,CAAA;AACzD,IAAA,MAAM,KAAA,GAAQ,IAAI,eAAA,CAAgB,iBAAA;AAElC,IAAA,IAAI,KAAA,KAAU,IAAA,EAAM,MAAM,IAAI,KAAA,CAAM,CAAA;AAAA,SAAA,EAAyD,OAAA,CAAQ,IAAI,CAAC,CAAA,CAAE,CAAA;AAC5G,IAAA,OAAO,KAAA;AAAA,EACT;AAGA,EAAA,MAAM,CAAA,GAAI,QAAA,CAAS,aAAA,CAAc,UAAU,CAAA;AAC3C,EAAA,CAAA,CAAE,SAAA,GAAY,IAAA;AACd,EAAA,MAAM,KAAA,GAAQ,EAAE,OAAA,CAAQ,iBAAA;AACxB,EAAA,IAAI,KAAA,KAAU,IAAA,EAAM,MAAM,IAAI,KAAA,CAAM,CAAA;AAAA,SAAA,EAA4C,OAAA,CAAQ,IAAI,CAAC,CAAA,CAAE,CAAA;AAC/F,EAAA,OAAO,KAAA;AACT","file":"index.js","sourcesContent":["/**\n * Tiny event-delegation helpers. Replace per-element `addEventListener` calls\n * (which don't survive morph re-renders for nodes the diff creates) with one\n * listener at the morph-root that dispatches via `closest()`.\n *\n * Three-tier listener model:\n *\n * - Tier 1 (bubbling events) — use `delegate()`.\n * click, input, change, submit, mousedown/up, keydown/up, pointerdown/up/move,\n * drag*, drop, contextmenu, wheel, copy/paste/cut, focusin/focusout.\n *\n * - Tier 2 (non-bubbling events) — use `delegateCapture()`.\n * focus, blur, scroll, load, error, mouseenter, mouseleave.\n * The capture phase fires on the way down from the root to the target,\n * so a root-level listener with `capture: true` reaches events that\n * wouldn't bubble back up.\n *\n * - Tier 3 (per-element instances / library-owned subtrees) — mark the\n * host element with `data-morph-skip` and manage the library's\n * lifecycle directly. No delegation helper applies.\n */\n\ntype Handler = (event: Event, target: Element) => void;\n\n/**\n * Validate a CSS selector at registration time, so a typo throws immediately\n * with the bad selector quoted instead of producing a cryptic DOMException\n * the first time a matching event fires.\n */\nfunction assertValidSelector(selector: string, fn: string): void {\n try {\n document.createElement('div').matches(selector);\n } catch {\n throw new Error(\n `${fn}: invalid selector \"${selector}\". `\n + 'Pass a valid CSS selector (e.g. \\'[data-action=\"add\"]\\', \\'.btn\\', \\'input\\').',\n );\n }\n}\n\n/**\n * Bubble-phase delegation. Installs ONE listener on `rootEl` for the given\n * event type. When the event fires, walks up from `event.target` to the root\n * looking for an element matching `selector`; if found, fires `handler` with\n * the matched element as the second arg.\n *\n * Returns a disposer that removes the listener.\n *\n * Usage (pseudo-code — see examples for live ones):\n * delegate(rootEl, 'click', '[data-action=\"add\"]', handlerFn);\n */\nexport function delegate(\n rootEl: HTMLElement,\n type: string,\n selector: string,\n handler: Handler,\n): () => void {\n assertValidSelector(selector, 'delegate');\n const listener = (event: Event): void => {\n const target = event.target;\n if (!(target instanceof Element)) return;\n const matched = target.closest(selector);\n if (matched !== null && rootEl.contains(matched)) {\n handler(event, matched);\n }\n };\n rootEl.addEventListener(type, listener);\n return () => {\n rootEl.removeEventListener(type, listener);\n };\n}\n\n/**\n * Capture-phase delegation — for non-bubbling events (`focus`, `blur`,\n * `scroll`, `load`, `error`). Reaches descendants of `rootEl` that match\n * `selector` regardless of how many times the diff has rebuilt them.\n *\n * Usage (pseudo-code — see examples for live ones):\n * delegateCapture(rootEl, 'focus', 'input, textarea', handlerFn);\n */\nexport function delegateCapture(\n rootEl: HTMLElement,\n type: string,\n selector: string,\n handler: Handler,\n): () => void {\n assertValidSelector(selector, 'delegateCapture');\n const listener = (event: Event): void => {\n const target = event.target;\n if (!(target instanceof Element)) return;\n if (target.matches(selector) && rootEl.contains(target)) {\n handler(event, target);\n }\n };\n rootEl.addEventListener(type, listener, true);\n return () => {\n rootEl.removeEventListener(type, listener, true);\n };\n}\n","/**\n * `each(items, render, key?)` — keyed list iteration with per-item memoisation.\n *\n * Drops in as the body of a list-rendering JSX expression inside a `mount()`\n * render function. Returns a `SafeHtml` carrying a structured list segment,\n * so `mount()` can run a native keyed reconciler instead of the general-\n * purpose morph for these children.\n *\n * Two layers of optimisation:\n *\n * 1. Per-item memoisation. `render(item)` is skipped for items whose object\n * identity (and optional `key`) are unchanged since the previous call.\n * Their HTML strings come from a `WeakMap` keyed by item reference. The\n * immutable-update style (\"replace the row object\" instead of \"mutate it\")\n * makes the cache work automatically.\n *\n * 2. Structural handoff. `mount()` recognises the list segment and bypasses\n * the parse-the-whole-table round trip: only fresh items get parsed (one\n * at a time, into the smallest detached element), and only changed rows\n * get patched in the live DOM. Unchanged rows are physically the same\n * nodes they were before — never visited.\n *\n * `key` covers the case where external state, not the item itself, drives\n * what the row should render (e.g. a \"currently selected\" id flips a CSS\n * class on one row). Same item identity but a different `key` value means\n * \"re-render this item.\" If you don't pass `key`, only identity changes\n * invalidate.\n *\n * Items must be objects (cache is a `WeakMap`); wrap primitives if you need\n * to iterate them. Each item's render output must produce exactly one\n * top-level element — the list reconciler binds one live DOM node per item.\n */\n\nimport type { SafeHtml } from './jsx-runtime.js';\nimport { isSafeHtml, listSafeHtml } from './jsx-runtime.js';\n\ninterface CacheEntry {\n key: unknown;\n html: string;\n}\n\nconst ROW_CACHE = new WeakMap<object, CacheEntry>();\n\n/**\n * Per-mount counter for assigning stable list ids across renders. `mount()`\n * sets this at the start of each render so that the n-th `each()` call\n * produces id \"n\" every render — the binding to the live parent persists.\n *\n * Outside a mount() render, calls to `each()` still work but get the\n * sentinel id \"orphan\"; their output flattens correctly via `toString()`\n * but the structural fast-path doesn't apply (no `mount()` is watching).\n */\nlet listCounter: { value: number } | null = null;\n\nexport function _setListCounter(c: { value: number } | null): void {\n listCounter = c;\n}\n\nexport function each<T extends object>(\n items: readonly T[],\n render: (item: T, index: number) => SafeHtml | string,\n key?: (item: T, index: number) => unknown,\n): SafeHtml {\n const id = listCounter !== null ? String(listCounter.value++) : 'orphan';\n const segItems = new Array<{ ref: object; cacheKey: unknown; html: string }>(items.length);\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n const k = key ? key(item, i) : undefined;\n const cached = ROW_CACHE.get(item);\n let html: string;\n if (cached !== undefined && cached.key === k) {\n html = cached.html;\n } else {\n const out = render(item, i);\n html = isSafeHtml(out) ? out.toString() : out;\n ROW_CACHE.set(item, { key: k, html });\n }\n segItems[i] = { ref: item, cacheKey: k, html };\n }\n return listSafeHtml(id, segItems);\n}\n","/**\n * `diff(liveRoot, templateRoot, listParents)` — minimum-mutation DOM\n * reconciliation.\n *\n * Replaces our previous dependency on `morphdom`. The algorithm is the\n * classic two-tree walk: match children by key (id, then data-key, then\n * positional same-tag), morph matches in place, insert / remove / clone\n * the rest. Specialised for what kerf needs:\n *\n * - `childrenOnly` is always true; the live root is never replaced.\n * - Three short-circuit paths on each element:\n * 1. `data-morph-skip`: subtree is library-owned, leave verbatim.\n * 2. `isEqualNode`: subtree is byte-identical, no work needed.\n * 3. `listParents` membership: a kerf list reconciler owns this\n * element's children, so we morph attributes only and stop.\n * - Focused text inputs (`<input>`/`<textarea>`) keep their value +\n * selection across the morph; focused `[contenteditable]` keeps its\n * entire subtree (typed content + caret + multi-range selection).\n *\n * Algorithm credit: based on the design of\n * https://github.com/patrick-steele-idem/morphdom by Patrick Steele-Idem\n * (MIT licensed). Reimplemented here so kerf can specialise the hot paths\n * (segment-aware list dispatch, lighter callback surface) and drop the\n * runtime dependency. Original copyright preserved in `LICENSE`.\n */\n\nconst ID_KEY_PREFIX = 'id:';\nconst DATA_KEY_PREFIX = 'data-key:';\nconst ELEMENT_NODE = 1;\nconst TEXT_NODE = 3;\nconst COMMENT_NODE = 8;\n\nfunction getNodeKey(node: Node): string | undefined {\n if (node.nodeType !== ELEMENT_NODE) return undefined;\n const el = node as HTMLElement;\n if (el.id !== '') return `${ID_KEY_PREFIX}${el.id}`;\n if (el.dataset !== undefined && el.dataset.key !== undefined) {\n return `${DATA_KEY_PREFIX}${el.dataset.key}`;\n }\n return undefined;\n}\n\n/**\n * Reconcile the children of `liveRoot` to match the children of\n * `templateRoot`. `listParents` is the set of live elements whose children\n * are managed by `each()`'s reconciler — they get attribute morphing but\n * not children diffing.\n */\nexport function diff(\n liveRoot: Element,\n templateRoot: Element,\n listParents: ReadonlySet<Element>,\n): void {\n diffChildren(liveRoot, templateRoot, listParents);\n}\n\nfunction diffChildren(\n fromParent: Element,\n toParent: Element,\n listParents: ReadonlySet<Element>,\n): void {\n // Build a keyed lookup from the live children so we can match by key\n // even after reorders.\n const keyed = new Map<string, Element>();\n for (let c = fromParent.firstChild; c !== null; c = c.nextSibling) {\n const k = getNodeKey(c);\n if (k !== undefined) keyed.set(k, c as Element);\n }\n\n let fromChild: Node | null = fromParent.firstChild;\n let toChild: Node | null = toParent.firstChild;\n\n while (toChild !== null) {\n const toNext = toChild.nextSibling;\n let matched: Node | null = null;\n\n // 1. Try key match.\n const toKey = getNodeKey(toChild);\n if (toKey !== undefined && keyed.has(toKey)) {\n matched = keyed.get(toKey) as Element;\n keyed.delete(toKey);\n if (matched !== fromChild) {\n fromParent.insertBefore(matched, fromChild);\n } else {\n fromChild = fromChild.nextSibling;\n }\n }\n\n // 2. Fall back to positional match — same nodeType, same tag (for\n // elements), and the live node has no key (a keyed node only\n // matches by key, never positionally, so reorders work).\n if (matched === null && fromChild !== null\n && fromChild.nodeType === toChild.nodeType\n && (toChild.nodeType !== ELEMENT_NODE\n || ((fromChild as Element).tagName === (toChild as Element).tagName\n && getNodeKey(fromChild) === undefined))) {\n matched = fromChild;\n fromChild = fromChild.nextSibling;\n }\n\n if (matched !== null) {\n morphNode(matched, toChild, listParents);\n } else {\n // 3. No match — clone the new node and insert.\n const cloned = toChild.cloneNode(true);\n fromParent.insertBefore(cloned, fromChild);\n }\n\n toChild = toNext;\n }\n\n // 4. Anything past the cursor is unmatched — remove. Any keyed node that\n // wasn't matched in the toParent walk falls into this trailing range\n // by construction (matched keyed nodes get moved before the cursor;\n // unmatched ones stay at or after it), so we don't need a separate\n // orphan pass.\n while (fromChild !== null) {\n const next = fromChild.nextSibling;\n fromParent.removeChild(fromChild);\n fromChild = next;\n }\n}\n\nfunction morphNode(\n fromNode: Node,\n toNode: Node,\n listParents: ReadonlySet<Element>,\n): void {\n if (fromNode.nodeType === ELEMENT_NODE) {\n morphElement(fromNode as Element, toNode as Element, listParents);\n return;\n }\n if (fromNode.nodeType === TEXT_NODE || fromNode.nodeType === COMMENT_NODE) {\n const fromText = fromNode as CharacterData;\n const toText = toNode as CharacterData;\n if (fromText.data !== toText.data) fromText.data = toText.data;\n }\n}\n\nfunction morphElement(\n fromEl: Element,\n toEl: Element,\n listParents: ReadonlySet<Element>,\n): void {\n if (fromEl.tagName !== toEl.tagName) {\n const replacement = toEl.cloneNode(true);\n fromEl.parentNode?.replaceChild(replacement, fromEl);\n return;\n }\n // 1. Library-owned subtree — leave verbatim.\n if ((fromEl as HTMLElement).dataset.morphSkip !== undefined) return;\n // 2. Byte-identical — nothing to do.\n if (fromEl.isEqualNode(toEl)) return;\n // 3. Focused contenteditable — preserve user's in-progress edit.\n if (fromEl === document.activeElement) {\n const ce = fromEl.getAttribute('contenteditable');\n if (ce !== null && ce.toLowerCase() !== 'false') return;\n if (isTextInputOrTextarea(fromEl)) preserveTextEntryState(fromEl, toEl);\n }\n morphAttributes(fromEl, toEl);\n // 4. List parent — its children are managed by the each() reconciler;\n // diff stops here. We still ran morphAttributes above, so attribute\n // changes on the parent itself (id, class, data-* …) propagate.\n if (listParents.has(fromEl)) return;\n diffChildren(fromEl, toEl, listParents);\n}\n\nfunction morphAttributes(fromEl: Element, toEl: Element): void {\n // Set/update every attribute on toEl.\n const toAttrs = toEl.attributes;\n for (let i = 0; i < toAttrs.length; i++) {\n const attr = toAttrs[i];\n const ns = attr.namespaceURI;\n const name = attr.localName;\n const value = attr.value;\n if (ns !== null) {\n if (fromEl.getAttributeNS(ns, name) !== value) {\n fromEl.setAttributeNS(ns, attr.name, value);\n }\n } else if (fromEl.getAttribute(name) !== value) {\n fromEl.setAttribute(name, value);\n }\n }\n // Remove attributes that are no longer present on toEl.\n const fromAttrs = fromEl.attributes;\n for (let i = fromAttrs.length - 1; i >= 0; i--) {\n const attr = fromAttrs[i];\n const ns = attr.namespaceURI;\n const name = attr.localName;\n if (ns !== null) {\n if (!toEl.hasAttributeNS(ns, name)) fromEl.removeAttributeNS(ns, name);\n } else if (!toEl.hasAttribute(name)) {\n fromEl.removeAttribute(name);\n }\n }\n}\n\nfunction isTextInputOrTextarea(el: Element): boolean {\n if (el.tagName === 'TEXTAREA') return true;\n if (el.tagName === 'INPUT') {\n const type = (el as HTMLInputElement).type;\n return type === 'text' || type === 'search' || type === 'url' || type === 'email'\n || type === 'tel' || type === 'password' || type === '';\n }\n return false;\n}\n\nfunction preserveTextEntryState(fromEl: Element, toEl: Element): void {\n if (fromEl.tagName === 'TEXTAREA' || fromEl.tagName === 'INPUT') {\n const fromInput = fromEl as HTMLInputElement;\n const toInput = toEl as HTMLInputElement;\n toInput.value = fromInput.value;\n try {\n toInput.setSelectionRange(fromInput.selectionStart, fromInput.selectionEnd);\n } catch {\n // Some input types (number, range, color, …) reject selection APIs.\n }\n }\n}\n","/**\n * Keyed list reconciler — the engine behind `each(...)` inside `mount()`.\n *\n * Given a `ListBinding` (the live parent + the items currently mounted under\n * it) and a fresh `ListSegment` from this render, mutate the live DOM with\n * the minimum number of operations:\n *\n * 1. Classify each new item as `stable` (cache hit on identity + html),\n * `replaced` (same ref, html changed), or `new` (never seen before).\n * 2. Bulk-parse every fresh row's HTML in ONE `innerHTML` call — for an\n * initial population of 10k rows that's 1 parse instead of 10k.\n * 3. Remove orphan refs (gone from the new list) + replaced rows' old nodes.\n * 4. Compute a longest-increasing-subsequence over old positions; items in\n * the LIS are already in the right relative order, so they don't move.\n * 5. Reverse-pass over the new record, `insertBefore` only the items that\n * didn't anchor the LIS.\n *\n * Lives in its own file so `mount.ts` can stay an orchestrator under the\n * 200-LOC guideline. Internal to kerf — not part of the public API.\n */\n\nimport type { ListSegment } from './segment.js';\n\nexport interface BoundItem {\n ref: object;\n cacheKey: unknown;\n html: string;\n node: Element;\n}\n\nexport interface ListBinding {\n liveParent: Element;\n /**\n * One entry per item currently mounted under `liveParent`, in order.\n * Mirrors the segment's `items` length after each reconcile.\n */\n items: BoundItem[];\n}\n\ninterface Classification {\n newRecord: BoundItem[];\n prevIdx: number[];\n replacedNodes: Element[];\n freshIndices: number[];\n freshHtmls: string[];\n}\n\n/**\n * Classify each item in the new segment against the old binding. Items with\n * a cache-hit (same ref + same html) are reused; replaced/new items get a\n * placeholder `BoundItem` whose `node` is filled in by the bulk parse below.\n */\nfunction classifyItems(oldItems: BoundItem[], listSeg: ListSegment): Classification {\n const oldByRef = new Map<object, BoundItem>();\n const oldIndex = new Map<object, number>();\n for (let i = 0; i < oldItems.length; i++) {\n oldByRef.set(oldItems[i].ref, oldItems[i]);\n oldIndex.set(oldItems[i].ref, i);\n }\n\n const newRecord: BoundItem[] = new Array(listSeg.items.length);\n const prevIdx = new Array<number>(listSeg.items.length);\n const replacedNodes: Element[] = [];\n const freshIndices: number[] = [];\n const freshHtmls: string[] = [];\n\n for (let i = 0; i < listSeg.items.length; i++) {\n const ni = listSeg.items[i];\n const oi = oldByRef.get(ni.ref);\n if (oi !== undefined) {\n oldByRef.delete(ni.ref);\n if (oi.html === ni.html) {\n newRecord[i] = oi;\n prevIdx[i] = oldIndex.get(ni.ref) as number;\n continue;\n }\n replacedNodes.push(oi.node);\n }\n newRecord[i] = {\n ref: ni.ref, cacheKey: ni.cacheKey, html: ni.html, node: null as unknown as Element,\n };\n prevIdx[i] = -1;\n freshIndices.push(i);\n freshHtmls.push(ni.html);\n }\n\n // Whatever's left in oldByRef is an orphan ref that disappeared from the\n // new list. The caller removes those nodes.\n for (const [, orphan] of oldByRef) replacedNodes.push(orphan.node);\n // Distinguish: replacedNodes here mixes \"old node for replaced row\" and\n // \"orphan node\". That's fine — the caller removes both unconditionally.\n\n return { newRecord, prevIdx, replacedNodes, freshIndices, freshHtmls };\n}\n\n/**\n * Bulk-parse every fresh row's HTML in one `innerHTML` call, then walk the\n * parsed children in order and fill in each placeholder's `node` field.\n */\nfunction buildFreshNodes(\n newRecord: BoundItem[],\n freshIndices: number[],\n freshHtmls: string[],\n): void {\n if (freshHtmls.length === 0) return;\n const tpl = document.createElement('template');\n tpl.innerHTML = freshHtmls.join('');\n let node = tpl.content.firstElementChild;\n for (const idx of freshIndices) {\n if (node === null) {\n throw new Error(\n `each(): row render produced no top-level element. Each item's render must return exactly one element. Got HTML: ${newRecord[idx].html.slice(0, 120)}`,\n );\n }\n const next = node.nextElementSibling;\n newRecord[idx].node = node;\n node = next;\n }\n}\n\n/**\n * Remove every replaced/orphan node still attached to the live parent.\n */\nfunction removeOldNodes(liveParent: Element, replacedNodes: Element[]): void {\n for (const node of replacedNodes) {\n if (node.parentElement === liveParent) liveParent.removeChild(node);\n }\n}\n\n/**\n * `insertBefore` everything that's not in the LIS. Walks the new record in\n * reverse so each move's anchor (`nextSibling`) is already in its final\n * position by the time we reach earlier items.\n */\nfunction applyMoves(\n liveParent: Element,\n newRecord: BoundItem[],\n prevIdx: number[],\n stable: ReadonlySet<number>,\n): void {\n let nextSibling: Element | null = null;\n for (let i = newRecord.length - 1; i >= 0; i--) {\n const node = newRecord[i].node;\n if (prevIdx[i] === -1 || !stable.has(i)) {\n liveParent.insertBefore(node, nextSibling);\n }\n nextSibling = node;\n }\n}\n\n/**\n * Patience-sort LIS: returns the *set of indices* in `arr` that participate\n * in a longest strictly-increasing subsequence. `-1` entries (representing\n * brand-new items in the new list) are ignored — they can't anchor the\n * subsequence and shouldn't count as stable.\n */\nfunction lis(arr: ReadonlyArray<number>): ReadonlySet<number> {\n const tails: number[] = [];\n const tailIdx: number[] = [];\n const prev = new Array<number>(arr.length);\n for (let i = 0; i < arr.length; i++) {\n const v = arr[i];\n if (v === -1) {\n prev[i] = -1;\n continue;\n }\n let lo = 0;\n let hi = tails.length;\n while (lo < hi) {\n const mid = (lo + hi) >> 1;\n if (tails[mid] < v) lo = mid + 1;\n else hi = mid;\n }\n prev[i] = lo > 0 ? tailIdx[lo - 1] : -1;\n tails[lo] = v;\n tailIdx[lo] = i;\n }\n const out = new Set<number>();\n let k = tailIdx.length > 0 ? tailIdx[tailIdx.length - 1] : -1;\n while (k !== -1) {\n out.add(k);\n k = prev[k];\n }\n return out;\n}\n\n/**\n * Reconcile `binding`'s live parent against `listSeg`. Mutates `binding.items`\n * to mirror the new segment when done.\n */\nexport function reconcileList(binding: ListBinding, listSeg: ListSegment): void {\n const { liveParent } = binding;\n const { newRecord, prevIdx, replacedNodes, freshIndices, freshHtmls }\n = classifyItems(binding.items, listSeg);\n buildFreshNodes(newRecord, freshIndices, freshHtmls);\n removeOldNodes(liveParent, replacedNodes);\n applyMoves(liveParent, newRecord, prevIdx, lis(prevIdx));\n binding.items = newRecord;\n}\n","/**\n * `mount(rootEl, render)` — kerf's render primitive.\n *\n * Wraps `effect()` so that whenever any signal read inside `render()`\n * changes, we re-run `render()` and apply the minimum DOM mutations against\n * the live tree. Element identity (and thus focus, selection, in-flight\n * pointer interactions, and event listeners on preserved nodes) is preserved\n * wherever the keyed/positional diff matches.\n *\n * Two phases per render:\n *\n * - Static surrounds (everything outside `each()` lists): kerf's native\n * `diff()` reconciler walks a freshly-built template against the live\n * tree. Conventions: id/data-key matching, `data-morph-skip`, focus\n * preservation.\n *\n * - List interiors (children of every `each()` parent): native keyed\n * reconciler operates directly on the live parent's children. No\n * re-parse, no morph walk for cache-hit rows. Cost is O(changes), not\n * O(rows).\n *\n * Compared to a `replaceChildren(...rows.map(toElement))` rebuild pattern,\n * the user-visible win is that an `<input>` the user is typing into\n * survives an unrelated re-render — its DOM node, focus state, and cursor\n * position are not destroyed and recreated on each tick.\n */\n\nimport { diff } from './diff.js';\nimport { _setListCounter } from './each.js';\nimport type { SafeHtml } from './jsx-runtime.js';\nimport { isSafeHtml } from './jsx-runtime.js';\nimport {\n type BoundItem,\n type ListBinding,\n reconcileList,\n} from './list-reconcile.js';\nimport { effect } from './reactive.js';\nimport {\n collectLists,\n flatten,\n flattenWithoutListItems,\n type ListSegment,\n type Segment,\n} from './segment.js';\n\nconst LIST_MARKER_PREFIX = 'kf-list:';\n\n/**\n * Bind `render()` to the children of `rootEl`. Re-runs whenever any signal\n * read inside `render()` changes. Returns a disposer that tears down the\n * effect; call it when the host element is removed from the DOM.\n *\n * Conventions:\n *\n * - Diff keys: `id` and `data-key` are matched across the morph by key\n * rather than positionally, so list reorders move existing nodes instead\n * of churning unrelated siblings.\n * - `data-morph-skip`: any element with this attribute is left untouched\n * inside on subsequent renders. Used for library-owned subtrees (xterm-\n * style widgets, charts, third-party editors) where the library's own\n * lifecycle manages the children.\n * - Focused text-entry inputs (`<input>` of typing kinds, `<textarea>`)\n * keep their current value + selection range across morphs while focused.\n * The user never sees their cursor jump mid-keystroke.\n * - Focused `[contenteditable]` elements have their entire subtree\n * skipped (same mechanism as `data-morph-skip`). The user's in-progress\n * edit — typed content, caret position, multi-range selections, anything\n * else they did to the DOM — survives verbatim. The next render after\n * blur catches up.\n */\nexport function mount(rootEl: HTMLElement, render: () => SafeHtml | string): () => void {\n const bindings = new Map<string, ListBinding>();\n const counter = { value: 0 };\n let isFirst = true;\n\n return effect(() => {\n counter.value = 0;\n _setListCounter(counter);\n let result: SafeHtml | string;\n try {\n result = render();\n } finally {\n _setListCounter(null);\n }\n\n const segment: Segment = isSafeHtml(result)\n ? (result.__segment ?? { kind: 'static', html: result.__html })\n : { kind: 'static', html: result };\n\n if (isFirst) {\n // Bulk-render with items inlined and a marker per list. The marker walk\n // afterwards binds each list to the rows already in the DOM, so the\n // first-render reconcile is a no-op (every item is a cache hit).\n rootEl.innerHTML = flatten(segment, true);\n bindListsFromMarkers(rootEl, segment, bindings);\n isFirst = false;\n } else {\n // Static-surrounds-only render: lists become marker-only in the\n // template. `diff()` skips bound list parents' children entirely\n // (so existing rows stay) and inserts the marker for any list that\n // didn't exist before. The marker walk afterwards binds those new\n // lists; the per-list reconcile below patches every list's items.\n const template = rootEl.cloneNode(false) as HTMLElement;\n template.innerHTML = flattenWithoutListItems(segment);\n const listParents = new Set<Element>();\n for (const b of bindings.values()) listParents.add(b.liveParent);\n diff(rootEl, template, listParents);\n bindListsFromMarkers(rootEl, segment, bindings);\n }\n\n for (const listSeg of collectLists(segment).values()) {\n const binding = bindings.get(listSeg.id) as ListBinding;\n reconcileList(binding, listSeg);\n }\n });\n}\n\n/**\n * Walk the live tree's comment nodes; every `<!--kf-list:{id}-->` marker\n * is the first child of a list parent. Record the binding (parent + the\n * already-rendered item nodes that follow the marker) and then remove the\n * marker — bindings live in JS, not in the DOM.\n */\nfunction bindListsFromMarkers(\n rootEl: Element,\n segment: Segment,\n bindings: Map<string, ListBinding>,\n): void {\n const lists = collectLists(segment);\n const found: Comment[] = [];\n collectComments(rootEl, found);\n for (const marker of found) {\n if (!marker.data.startsWith(LIST_MARKER_PREFIX)) continue;\n const id = marker.data.slice(LIST_MARKER_PREFIX.length);\n // Markers are only emitted by `flatten(..., true)` paired with a list\n // segment in the same render, so both lookups always succeed here.\n const listSeg = lists.get(id) as ListSegment;\n const liveParent = marker.parentElement as Element;\n // On first render, items are inlined right after the marker (so the\n // first element sibling is `items[0]`, the next is `items[1]`, etc.).\n // On subsequent renders for a list newly appearing, the list parent\n // is empty after the marker; the loop falls through with `items=[]`\n // and the reconcile phase below builds the items.\n const items: BoundItem[] = [];\n let next: Element | null = marker.nextElementSibling;\n for (let i = 0; i < listSeg.items.length && next !== null; i++) {\n items.push({\n ref: listSeg.items[i].ref,\n cacheKey: listSeg.items[i].cacheKey,\n html: listSeg.items[i].html,\n node: next,\n });\n next = next.nextElementSibling;\n }\n bindings.set(id, { liveParent, items });\n marker.remove();\n }\n}\n\n/**\n * Recursive collector for comment nodes — happy-dom's `TreeWalker` doesn't\n * surface `Node.COMMENT_NODE` despite accepting `NodeFilter.SHOW_COMMENT`,\n * so we walk children directly. Cheap (O(elements)) and portable.\n */\nfunction collectComments(node: Node, out: Comment[]): void {\n for (let c: Node | null = node.firstChild; c !== null; c = c.nextSibling) {\n if (c.nodeType === Node.COMMENT_NODE) out.push(c as Comment);\n else if (c.nodeType === Node.ELEMENT_NODE) collectComments(c, out);\n }\n}\n\n\n","/**\n * `toElement(jsx)` — JSX → DOM, with SVG-aware namespace handling.\n *\n * The naive implementation parses JSX through a `<template>` element's\n * `innerHTML`. That works for HTML and for SVG fragments whose root tag is\n * `<svg>` (the parser switches to \"foreign content\" mode). It silently\n * fails for SVG fragments WITHOUT an `<svg>` wrapper — descendants come out\n * as `HTMLUnknownElement` and never paint.\n *\n * `toElement` detects SVG content and routes through `DOMParser` with the\n * `image/svg+xml` MIME, which guarantees correct namespacing for all\n * descendants. HTML content takes the original `<template>` path unchanged.\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', 'path', 'circle', 'rect', 'line', 'polygon', 'polyline', 'ellipse',\n 'text', 'tspan', 'defs', 'use', 'symbol', 'clipPath', 'mask', 'pattern',\n 'filter', 'marker', 'linearGradient', 'radialGradient', 'stop', 'image',\n 'foreignObject',\n]);\n\nconst EXCERPT_MAX_LEN = 100;\n\nfunction leadingTag(html: string): string | null {\n const match = /^\\s*<([a-zA-Z][a-zA-Z0-9]*)\\b/.exec(html);\n return match !== null ? match[1] : null;\n}\n\nfunction excerpt(html: string): string {\n const trimmed = html.trim();\n return trimmed.length > EXCERPT_MAX_LEN ? `${trimmed.slice(0, EXCERPT_MAX_LEN)}…` : trimmed;\n}\n\nfunction parseSvgOrThrow(html: string, label: string, originalHtml: string): 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(`toElement: ${label} parse error — ${err.textContent}\\n input: ${excerpt(originalHtml)}`);\n }\n return doc;\n}\n\nexport function toElement(jsx: SafeHtml | string): Element {\n const html = typeof jsx === 'string' ? jsx : jsx.toString();\n const tag = leadingTag(html);\n\n if (tag === 'svg') {\n // SVG root — parse as XML to guarantee namespace propagation.\n return parseSvgOrThrow(html, 'SVG', html).documentElement;\n }\n\n if (tag !== null && SVG_FRAGMENT_TAGS.has(tag)) {\n // SVG fragment without an <svg> wrapper — wrap, parse, unwrap.\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) throw new Error(`toElement: SVG fragment produced no element\\n input: ${excerpt(html)}`);\n return first;\n }\n\n // HTML — `<template>`-based parse.\n const t = document.createElement('template');\n t.innerHTML = html;\n const child = t.content.firstElementChild;\n if (child === null) throw new Error(`toElement: produced no element\\n input: ${excerpt(html)}`);\n return child;\n}\n"]}
1
+ {"version":3,"sources":["../src/delegate.ts","../src/each.ts","../src/diff.ts","../src/list-binding.ts","../src/list-reconcile-focus.ts","../src/utils/rowContract.ts","../src/list-reconcile-granular.ts","../src/list-reconcile-snapshot.ts","../src/list-reconcile.ts","../src/mount.ts","../src/toElement.ts"],"names":[],"mappings":";;;;;;;AA0CA,IAAM,YAAA,uBAAmB,GAAA,CAAY;AAAA,EACnC,OAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,YAAA;AAAA,E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":"index.js","sourcesContent":["/**\n * Tiny event-delegation helpers. Replace per-element `addEventListener` calls\n * (which don't survive morph re-renders for nodes the diff creates) with one\n * listener at the morph-root that dispatches via `closest()`.\n *\n * Three-tier listener model:\n *\n * - Tier 1 (bubbling events) — use `delegate()`.\n * click, input, change, submit, mousedown/up, keydown/up, pointerdown/up/move,\n * drag*, drop, contextmenu, wheel, copy/paste/cut, focusin/focusout.\n *\n * `delegate()` also auto-promotes the well-known non-bubbling event\n * types (`focus`, `blur`, `scroll`, `load`, `error`, `mouseenter`,\n * `mouseleave`) to the capture phase under the hood, so the call site\n * looks identical for \"interactive thing happens on a descendant\"\n * regardless of whether that event bubbles. Selector matching stays\n * `closest()`-style — the same as for bubbling events — so a wrapper\n * selector like `'.field-row'` still matches when the event fires on\n * a descendant `<input>`.\n *\n * - Tier 2 (explicit capture) — use `delegateCapture()`.\n * The escape hatch for cases the auto-promotion list doesn't cover, or\n * when you want capture-phase semantics and direct `matches()`-style\n * selector matching (no walk-up).\n *\n * - Tier 3 (per-element instances / library-owned subtrees) — mark the\n * host element with `data-morph-skip` and manage the library's\n * lifecycle directly. No delegation helper applies.\n */\n\ntype Handler = (event: Event, target: Element) => void;\n\n/**\n * Event types that don't bubble and so wouldn't reach a root-level\n * bubble-phase listener. `delegate()` flips to capture for these; the\n * caller doesn't need to know or care.\n *\n * Membership is conservative — it covers the cases that \"should obviously\n * work\" with delegate() but otherwise don't. For exotic non-bubbling events\n * (custom events, less-common DOM events) the explicit `delegateCapture()`\n * remains the escape hatch.\n */\nconst NON_BUBBLING = new Set<string>([\n 'focus',\n 'blur',\n 'scroll',\n 'load',\n 'error',\n 'mouseenter',\n 'mouseleave',\n]);\n\n/**\n * Validate a CSS selector at registration time, so a typo throws immediately\n * with the bad selector quoted instead of producing a cryptic DOMException\n * the first time a matching event fires.\n */\nfunction assertValidSelector(selector: string, fn: string): void {\n try {\n document.createElement('div').matches(selector);\n } catch {\n throw new Error(\n `${fn}: invalid selector \"${selector}\". `\n + 'Pass a valid CSS selector (e.g. \\'[data-action=\"add\"]\\', \\'.btn\\', \\'input\\').',\n );\n }\n}\n\n/**\n * Delegation that \"just works\" for both bubbling and the common non-bubbling\n * events. Installs ONE listener on `rootEl`; for known non-bubblers (see\n * `NON_BUBBLING` above) the listener is registered on the capture phase so\n * it actually reaches the target, otherwise on the bubble phase. Either way,\n * matching walks up from `event.target` via `closest(selector)` and fires\n * `handler(event, matched)` if the match is inside `rootEl`.\n *\n * Returns a disposer that removes the listener.\n *\n * Usage (pseudo-code — see examples for live ones):\n * delegate(rootEl, 'click', '[data-action=\"add\"]', handlerFn);\n * delegate(rootEl, 'focus', 'input', handlerFn); // auto-capture\n */\nexport function delegate(\n rootEl: HTMLElement,\n type: string,\n selector: string,\n handler: Handler,\n): () => void {\n assertValidSelector(selector, 'delegate');\n const listener = (event: Event): void => {\n const target = event.target;\n if (!(target instanceof Element)) return;\n const matched = target.closest(selector);\n if (matched !== null && rootEl.contains(matched)) {\n handler(event, matched);\n }\n };\n const capture = NON_BUBBLING.has(type);\n rootEl.addEventListener(type, listener, capture);\n return () => {\n rootEl.removeEventListener(type, listener, capture);\n };\n}\n\n/**\n * Capture-phase delegation — for non-bubbling events (`focus`, `blur`,\n * `scroll`, `load`, `error`). Reaches descendants of `rootEl` that match\n * `selector` regardless of how many times the diff has rebuilt them.\n *\n * Usage (pseudo-code — see examples for live ones):\n * delegateCapture(rootEl, 'focus', 'input, textarea', handlerFn);\n */\nexport function delegateCapture(\n rootEl: HTMLElement,\n type: string,\n selector: string,\n handler: Handler,\n): () => void {\n assertValidSelector(selector, 'delegateCapture');\n const listener = (event: Event): void => {\n const target = event.target;\n if (!(target instanceof Element)) return;\n if (target.matches(selector) && rootEl.contains(target)) {\n handler(event, target);\n }\n };\n rootEl.addEventListener(type, listener, true);\n return () => {\n rootEl.removeEventListener(type, listener, true);\n };\n}\n","/**\n * `each(items, render, key?)` — keyed list iteration with per-item memoisation.\n *\n * Drops in as the body of a list-rendering JSX expression inside a `mount()`\n * render function. Returns a `SafeHtml` carrying a structured list segment,\n * so `mount()` can run a native keyed reconciler instead of the general-\n * purpose morph for these children.\n *\n * Two layers of optimisation:\n *\n * 1. Per-item memoisation. `render(item)` is skipped for items whose object\n * identity (and optional `key`) are unchanged since the previous call.\n * Their HTML strings come from a `WeakMap` keyed by item reference. The\n * immutable-update style (\"replace the row object\" instead of \"mutate it\")\n * makes the cache work automatically.\n *\n * 2. Structural handoff. `mount()` recognises the list segment and bypasses\n * the parse-the-whole-table round trip: only fresh items get parsed (one\n * at a time, into the smallest detached element), and only changed rows\n * get patched in the live DOM. Unchanged rows are physically the same\n * nodes they were before — never visited.\n *\n * `key` covers the case where external state, not the item itself, drives\n * what the row should render (e.g. a \"currently selected\" id flips a CSS\n * class on one row). Same item identity but a different `key` value means\n * \"re-render this item.\" If you don't pass `key`, only identity changes\n * invalidate.\n *\n * Items must be objects (cache is a `WeakMap`); wrap primitives if you need\n * to iterate them. Each item's render output must produce exactly one\n * top-level element — the list reconciler binds one live DOM node per item.\n */\n\nimport type { ArraySignal } from './array-signal.js';\nimport type { SafeHtml } from './jsx-runtime.js';\nimport { granularListSafeHtml, isSafeHtml, listSafeHtml } from './jsx-runtime.js';\nimport type { ArrayPatchInternal } from './segment.js';\n\n/**\n * Cross-bundle brand check for `ArraySignal` instances (KF-95). The\n * `arraySignal` factory + class live in their own subpath\n * (`kerfjs/array-signal`); this module knows nothing about that\n * subpath at runtime — it identifies instances by the brand symbol\n * stamped on them. Apps that never import `arraySignal` shed the\n * ~1 KB of class code without breaking the structural contract here.\n */\nconst ARRAY_SIGNAL_BRAND = Symbol.for('kerfjs.ArraySignal');\n\nfunction isArraySignal<T extends object>(value: unknown): value is ArraySignal<T> {\n return typeof value === 'object'\n && value !== null\n && (value as Record<symbol, unknown>)[ARRAY_SIGNAL_BRAND] === true;\n}\n\ninterface CacheEntry {\n key: unknown;\n html: string;\n}\n\n/**\n * Per-render context passed in by `mount()` for the duration of one render\n * pass. Carries (a) a counter that assigns a stable list id to the n-th\n * `each()` call across renders within a mount, and (b) a per-mount cache map\n * keyed on those list ids.\n *\n * Why per-(mount, listId) keying for the cache:\n * - Same `each()` callsite across renders within a mount → same id → same\n * cache → cache hits work, even when the JSX render fn is an inline arrow\n * that's a fresh function reference on every closure run (the typical\n * pattern; KF-87 fixed the regression where this broke).\n * - Different `each()` callsites within the same mount → different ids →\n * separate caches → no cross-callsite collision (the case KF-73 fixed,\n * preserved here).\n * - Different mounts → different `RenderContext` instances (the cache map\n * lives on `mount()`'s closure) → separate caches.\n *\n * Outside a `mount()` render (e.g. `each(...).toString()` for SSR string\n * production) `context` is null and items are rendered every call —\n * caching is a `mount()` feature, not a global one.\n */\nexport interface RenderContext {\n counter: number;\n caches: Map<string, WeakMap<object, CacheEntry>>;\n /**\n * Per-list-id record of the binding's `items.length` after the most recent\n * successful reconcile. Maintained by `mount()` via `_setBindingCount`. The\n * granular path consults this to detect drift between the live binding and\n * the arraySignal — drift means a previous render threw mid-reconcile (or\n * a granular path was bypassed externally), so the next render forces a\n * snapshot rebuild rather than applying patches against a stale binding.\n */\n bindingCounts: Map<string, number>;\n}\n\nlet context: RenderContext | null = null;\n\nexport function _setRenderContext(c: RenderContext | null): void {\n context = c;\n}\n\nexport function each<T extends object>(\n items: readonly T[] | ArraySignal<T>,\n render: (item: T, index: number) => SafeHtml | string,\n key?: (item: T, index: number) => unknown,\n): SafeHtml {\n // KF-92 fast path: when items is an ArraySignal AND we're inside a mount\n // render context AND patches have queued since the last drain, emit a\n // granular list segment that the list reconciler applies in O(patches)\n // instead of O(N). Detection via the brand symbol (KF-95) — the\n // `arraySignal` class lives in the `kerfjs/array-signal` subpath and is\n // not imported here at runtime.\n if (isArraySignal<T>(items) && context !== null) {\n return eachGranular(items, render, key);\n }\n const snapshotItems: readonly T[] = isArraySignal<T>(items)\n ? items.value as readonly T[]\n : items;\n return eachSnapshot(snapshotItems, render, key);\n}\n\nfunction eachSnapshot<T extends object>(\n items: readonly T[],\n render: (item: T, index: number) => SafeHtml | string,\n key: ((item: T, index: number) => unknown) | undefined,\n): SafeHtml {\n let id: string;\n if (context !== null) {\n id = String(context.counter++);\n } else {\n id = 'orphan';\n }\n return eachSnapshotById(items, render, key, id);\n}\n\n/**\n * Granular path for `arraySignal`-backed lists. Drains queued patches and\n * emits a list segment that the reconciler applies to the existing binding\n * directly — no full iteration of the snapshot, no O(N) classify pass.\n *\n * On the very first render of a list, the binding doesn't exist yet, so\n * the reconciler falls through to the snapshot path. Subsequent renders\n * of the same list (where the binding now exists) take the granular path\n * whenever there are patches to apply.\n */\nfunction eachGranular<T extends object>(\n sig: ArraySignal<T>,\n render: (item: T, index: number) => SafeHtml | string,\n key: ((item: T, index: number) => unknown) | undefined,\n): SafeHtml {\n // We're inside a mount context (caller-checked).\n const ctx = context as RenderContext;\n const id = String(ctx.counter++);\n // KF-98: a tracked binding count means a prior render of this mount has\n // successfully reconciled this list. On the very first render (no count\n // recorded yet) the granular reconciler has no binding to apply patches\n // to, so any pre-mount mutations would silently produce an empty list.\n // Drain the queue (the snapshot already reflects those mutations) and\n // take the snapshot path; the count will be recorded for the next render.\n const previousBindingCount = ctx.bindingCounts.get(id);\n const patches = sig._consumePatches();\n const snapshot = sig.value as readonly T[];\n\n // First render of this list, no patches, or any 'replace' patch → snapshot.\n // No patches: typical re-render triggered by a non-arraySignal signal change.\n // 'replace': wholesale reset — granular can't help; the snapshot already\n // reflects the post-replace state (and any subsequent granular ops).\n if (previousBindingCount === undefined || patches.length === 0) {\n return eachSnapshotById(snapshot, render, key, id);\n }\n // KF-99: detect drift between the live binding and the arraySignal. After\n // a clean prior reconcile, `previousBindingCount + (#inserts - #removes)`\n // must equal `snapshot.length`. If it doesn't, a previous render threw\n // mid-reconcile and left the binding inconsistent with the signal — fall\n // back to the snapshot path, which classifies fresh against `snapshot`\n // and rebuilds the binding to match.\n let netDelta = 0;\n for (const p of patches) {\n if (p.type === 'insert') netDelta += 1;\n else if (p.type === 'remove') netDelta -= 1;\n else if (p.type === 'replace') {\n return eachSnapshotById(snapshot, render, key, id);\n }\n }\n // Defensive: triggered only when an external party drains `_consumePatches()`\n // or mutates `_items` behind arraySignal's back, OR when a previous reconcile\n // threw mid-DOM-op (rare; not naturally reachable in tests since apply* ops\n // don't throw on well-formed row HTML).\n /* c8 ignore next 3 */\n if (previousBindingCount + netDelta !== snapshot.length) {\n return eachSnapshotById(snapshot, render, key, id);\n }\n\n // Granular path: pre-render every insert/update HTML at JSX-eval time so\n // a throwing render is caught here and we can fall back to the snapshot\n // path (KF-99). Without this, a throw mid-batch would leave patches drained\n // (already done above), the signal mutated, and the live DOM unchanged —\n // permanent divergence with no recovery.\n const renderFnInternal = (item: object, index: number): string => {\n const out = render(item as T, index);\n return isSafeHtml(out) ? out.toString() : out;\n };\n const internalPatches = new Array<ArrayPatchInternal>(patches.length);\n try {\n for (let i = 0; i < patches.length; i++) {\n const p = patches[i];\n if (p.type === 'insert' || p.type === 'update') {\n internalPatches[i] = {\n type: p.type, index: p.index, item: p.item as object,\n html: renderFnInternal(p.item as object, p.index),\n };\n } else {\n internalPatches[i] = p as ArrayPatchInternal;\n }\n }\n } catch {\n // Pre-render threw. The snapshot already reflects every mutation\n // (arraySignal mutates _items eagerly at the call site), but the snapshot\n // path is going to throw on the same bad item too — leaving the binding\n // out of sync with the signal. Clear the binding count so the NEXT\n // render (after the user fixes the bad item) doesn't see the previous\n // render's count and falsely conclude there's no drift; instead it'll\n // take the snapshot path and rebuild from scratch.\n ctx.bindingCounts.delete(id);\n return eachSnapshotById(snapshot, render, key, id);\n }\n // The `items` field is left empty for the granular case — the reconciler\n // doesn't need it; every insert/update patch carries pre-rendered HTML.\n return granularListSafeHtml(id, [], internalPatches);\n}\n\n/** Like eachSnapshot but uses a pre-allocated id (caller already advanced the counter). */\nfunction eachSnapshotById<T extends object>(\n items: readonly T[],\n render: (item: T, index: number) => SafeHtml | string,\n key: ((item: T, index: number) => unknown) | undefined,\n id: string,\n): SafeHtml {\n let cache: WeakMap<object, CacheEntry> | null = null;\n if (context !== null) {\n let c = context.caches.get(id);\n if (c === undefined) {\n c = new WeakMap<object, CacheEntry>();\n context.caches.set(id, c);\n }\n cache = c;\n }\n const segItems = new Array<{ ref: object; cacheKey: unknown; html: string }>(items.length);\n const seen = new Set<object>();\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n if (typeof item !== 'object' || item === null) {\n throw new Error(\n `each(): items must be objects (the per-item HTML cache is a WeakMap), got ${item === null ? 'null' : typeof item} at index ${i}. `\n + 'Wrap primitives if you need to iterate them, e.g. items.map(v => ({ v })).',\n );\n }\n if (seen.has(item)) {\n throw new Error(\n `each(): the same object reference appears at multiple indices in items (first seen earlier, again at index ${i}). `\n + 'The per-item HTML cache is keyed on object identity, so duplicate references break the keyed reconciler and can leak DOM nodes on re-render. '\n + 'Use a fresh object per row (e.g. items.map(o => ({ ...o })) before passing to each()).',\n );\n }\n seen.add(item);\n const k = key ? key(item, i) : undefined;\n let html: string;\n const cached = cache !== null ? cache.get(item) : undefined;\n if (cached !== undefined && cached.key === k) {\n html = cached.html;\n } else {\n const out = render(item, i);\n html = isSafeHtml(out) ? out.toString() : out;\n if (cache !== null) cache.set(item, { key: k, html });\n }\n segItems[i] = { ref: item, cacheKey: k, html };\n }\n return listSafeHtml(id, segItems);\n}\n","/**\n * `diff(liveRoot, templateRoot, ownedItems)` — minimum-mutation DOM\n * reconciliation.\n *\n * Replaces our previous dependency on `morphdom`. The algorithm is the\n * classic two-tree walk: match children by key (id, then data-key, then\n * positional same-tag), morph matches in place, insert / remove / clone\n * the rest. Specialised for what kerf needs:\n *\n * - `childrenOnly` is always true; the live root is never replaced.\n * - Per-element short-circuits: `data-morph-skip` (library-owned, leave\n * verbatim) and `isEqualNode` (byte-identical, no work needed).\n * - **`ownedItems`** is the set of element nodes owned by an `each()`\n * list reconciler. The diff skips them in every children walk —\n * they're not added to the keyed-lookup map, the from-cursor advances\n * past them, and the trailing-removal pass leaves them in place. This\n * lets each() coexist with non-list siblings inside the same parent\n * (KF-102 round 2): the diff still walks the parent's children to\n * reconcile siblings, but never disturbs list rows.\n * - Focused text inputs (`<input>`/`<textarea>`) keep their value +\n * selection across the morph; focused `[contenteditable]` keeps its\n * entire subtree (typed content + caret + multi-range selection).\n *\n * Algorithm credit: based on the design of\n * https://github.com/patrick-steele-idem/morphdom by Patrick Steele-Idem\n * (MIT licensed). Reimplemented here so kerf can specialise the hot paths\n * (segment-aware list dispatch, lighter callback surface) and drop the\n * runtime dependency. Original copyright preserved in `LICENSE`.\n */\n\nconst ID_KEY_PREFIX = 'id:';\nconst DATA_KEY_PREFIX = 'data-key:';\nconst ELEMENT_NODE = 1;\nconst TEXT_NODE = 3;\nconst COMMENT_NODE = 8;\n\nfunction getNodeKey(node: Node): string | undefined {\n if (node.nodeType !== ELEMENT_NODE) return undefined;\n const el = node as HTMLElement;\n if (el.id !== '') return `${ID_KEY_PREFIX}${el.id}`;\n if (el.dataset !== undefined && el.dataset.key !== undefined) {\n return `${DATA_KEY_PREFIX}${el.dataset.key}`;\n }\n return undefined;\n}\n\n/**\n * Reconcile the children of `liveRoot` to match the children of\n * `templateRoot`. `ownedItems` is the set of element nodes owned by `each()`\n * list reconcilers — the diff skips them in every children walk.\n */\nexport function diff(\n liveRoot: Element,\n templateRoot: Element,\n ownedItems: ReadonlySet<Element>,\n): void {\n diffChildren(liveRoot, templateRoot, ownedItems);\n}\n\n/**\n * Advance past any owned (list-reconciler-managed) element. Owned items\n * stay put across diffs — they're invisible to the diff's child cursor.\n */\nfunction skipOwned(node: Node | null, ownedItems: ReadonlySet<Element>): Node | null {\n while (node !== null && node.nodeType === ELEMENT_NODE\n && ownedItems.has(node as Element)) {\n node = node.nextSibling;\n }\n return node;\n}\n\nfunction diffChildren(\n fromParent: Element,\n toParent: Element,\n ownedItems: ReadonlySet<Element>,\n): void {\n // Build a keyed lookup from the live children so we can match by key\n // even after reorders. Owned items don't participate in keyed matching\n // (they're not visible to the diff).\n const keyed = new Map<string, Element>();\n for (let c = fromParent.firstChild; c !== null; c = c.nextSibling) {\n if (c.nodeType === ELEMENT_NODE && ownedItems.has(c as Element)) continue;\n const k = getNodeKey(c);\n if (k !== undefined) keyed.set(k, c as Element);\n }\n\n let fromChild: Node | null = skipOwned(fromParent.firstChild, ownedItems);\n let toChild: Node | null = toParent.firstChild;\n\n while (toChild !== null) {\n const toNext = toChild.nextSibling;\n let matched: Node | null = null;\n\n // 1. Try key match.\n const toKey = getNodeKey(toChild);\n if (toKey !== undefined && keyed.has(toKey)) {\n matched = keyed.get(toKey) as Element;\n keyed.delete(toKey);\n if (matched !== fromChild) {\n fromParent.insertBefore(matched, fromChild);\n } else {\n fromChild = skipOwned(fromChild.nextSibling, ownedItems);\n }\n }\n\n // 2. Fall back to positional match — same nodeType, same tag (for\n // elements), and the live node has no key (a keyed node only\n // matches by key, never positionally, so reorders work).\n if (matched === null && fromChild !== null\n && fromChild.nodeType === toChild.nodeType\n && (toChild.nodeType !== ELEMENT_NODE\n || ((fromChild as Element).tagName === (toChild as Element).tagName\n && getNodeKey(fromChild) === undefined))) {\n matched = fromChild;\n fromChild = skipOwned(fromChild.nextSibling, ownedItems);\n }\n\n if (matched !== null) {\n morphNode(matched, toChild, ownedItems);\n } else {\n // 3. No match — clone the new node and insert before fromChild\n // (which may be an owned item we deliberately stopped at; that's\n // fine — `insertBefore(node, ownedItem)` slots the new sibling\n // in immediately before the list region).\n const cloned = toChild.cloneNode(true);\n fromParent.insertBefore(cloned, fromChild);\n }\n\n toChild = toNext;\n }\n\n // 4. Anything past the cursor is unmatched — remove, except for owned\n // items (those stay; they belong to a list reconciler).\n while (fromChild !== null) {\n const next = fromChild.nextSibling;\n if (fromChild.nodeType !== ELEMENT_NODE\n || !ownedItems.has(fromChild as Element)) {\n fromParent.removeChild(fromChild);\n }\n fromChild = next;\n }\n}\n\nfunction morphNode(\n fromNode: Node,\n toNode: Node,\n ownedItems: ReadonlySet<Element>,\n): void {\n if (fromNode.nodeType === ELEMENT_NODE) {\n morphElement(fromNode as Element, toNode as Element, ownedItems);\n return;\n }\n if (fromNode.nodeType === TEXT_NODE || fromNode.nodeType === COMMENT_NODE) {\n const fromText = fromNode as CharacterData;\n const toText = toNode as CharacterData;\n if (fromText.data !== toText.data) fromText.data = toText.data;\n }\n}\n\nfunction morphElement(\n fromEl: Element,\n toEl: Element,\n ownedItems: ReadonlySet<Element>,\n): void {\n if (fromEl.tagName !== toEl.tagName) {\n const replacement = toEl.cloneNode(true);\n fromEl.parentNode?.replaceChild(replacement, fromEl);\n return;\n }\n // 1. Library-owned subtree — leave verbatim.\n if ((fromEl as HTMLElement).dataset.morphSkip !== undefined) return;\n // 2. Byte-identical — nothing to do.\n if (fromEl.isEqualNode(toEl)) return;\n // 3. Focused contenteditable — preserve user's in-progress edit.\n if (fromEl === document.activeElement) {\n const ce = fromEl.getAttribute('contenteditable');\n if (ce !== null && ce.toLowerCase() !== 'false') return;\n if (isTextInputOrTextarea(fromEl)) preserveTextEntryState(fromEl, toEl);\n }\n morphAttributes(fromEl, toEl);\n // 4. Recurse into children. List items inside `fromEl` (if any) are\n // skipped via `ownedItems` inside diffChildren — list reconciler\n // owns them — but non-list siblings are still diffed.\n diffChildren(fromEl, toEl, ownedItems);\n}\n\n/**\n * Attributes the user agent toggles in response to user interaction.\n * `<details>` and `<dialog>` add/remove `open=\"\"` themselves when the user\n * expands or closes the element. If the developer's JSX never mentions\n * `open`, treating that attribute as user-agent-owned and leaving it alone\n * during the morph keeps the user-driven state intact across re-renders.\n *\n * Trade-off (KF-84): controlled-style `<details open={signal.value}>` where\n * the signal flips false won't auto-collapse the element, because the\n * morph's remove pass no longer reaches `open`. Apps that need controlled\n * behaviour should drive `open` imperatively (e.g. `el.removeAttribute('open')`\n * inside an action) or wrap with a state-toggle pattern. The uncontrolled\n * case is the common one and the one that was silently broken before.\n */\nfunction isUserAgentOwnedAttr(tagName: string, name: string): boolean {\n return name === 'open' && (tagName === 'DETAILS' || tagName === 'DIALOG');\n}\n\nfunction morphAttributes(fromEl: Element, toEl: Element): void {\n // Set/update every attribute on toEl.\n const toAttrs = toEl.attributes;\n for (let i = 0; i < toAttrs.length; i++) {\n const attr = toAttrs[i];\n const ns = attr.namespaceURI;\n const name = attr.localName;\n const value = attr.value;\n if (ns !== null) {\n if (fromEl.getAttributeNS(ns, name) !== value) {\n fromEl.setAttributeNS(ns, attr.name, value);\n }\n } else if (fromEl.getAttribute(name) !== value) {\n fromEl.setAttribute(name, value);\n }\n }\n // Remove attributes that are no longer present on toEl.\n const fromAttrs = fromEl.attributes;\n const fromTag = fromEl.tagName;\n for (let i = fromAttrs.length - 1; i >= 0; i--) {\n const attr = fromAttrs[i];\n const ns = attr.namespaceURI;\n const name = attr.localName;\n if (ns !== null) {\n if (!toEl.hasAttributeNS(ns, name)) fromEl.removeAttributeNS(ns, name);\n } else if (!toEl.hasAttribute(name) && !isUserAgentOwnedAttr(fromTag, name)) {\n fromEl.removeAttribute(name);\n }\n }\n}\n\nfunction isTextInputOrTextarea(el: Element): boolean {\n if (el.tagName === 'TEXTAREA') return true;\n if (el.tagName === 'INPUT') {\n const type = (el as HTMLInputElement).type;\n return type === 'text' || type === 'search' || type === 'url' || type === 'email'\n || type === 'tel' || type === 'password' || type === '';\n }\n return false;\n}\n\nfunction preserveTextEntryState(fromEl: Element, toEl: Element): void {\n if (fromEl.tagName === 'TEXTAREA' || fromEl.tagName === 'INPUT') {\n const fromInput = fromEl as HTMLInputElement;\n const toInput = toEl as HTMLInputElement;\n toInput.value = fromInput.value;\n try {\n toInput.setSelectionRange(fromInput.selectionStart, fromInput.selectionEnd);\n } catch {\n // Some input types (number, range, color, …) reject selection APIs.\n }\n }\n}\n","/**\n * Per-list binding shape kept by `mount()` and consumed by both reconcile\n * paths in `list-reconcile-snapshot.ts` and `list-reconcile-granular.ts`.\n *\n * Living in its own file (not re-exported through `list-reconcile.ts`) so\n * the snapshot + granular paths can import it without creating a circular\n * dependency on `list-reconcile.ts` itself. ESM handles cycles via function\n * hoisting, but a cycle involving a non-function helper would be a temporal\n * dead zone — extracting the binding shape + `endAnchor` here keeps the\n * dependency graph acyclic.\n */\n\nexport interface BoundItem {\n ref: object;\n cacheKey: unknown;\n html: string;\n node: Element;\n}\n\nexport interface ListBinding {\n liveParent: Element;\n /**\n * One entry per item currently mounted under `liveParent`, in order.\n * Mirrors the segment's `items` length after each reconcile.\n */\n items: BoundItem[];\n /**\n * The list's `<!--kf-list:N-->` start marker, kept in the live DOM as\n * a permanent anchor (KF-102 round 2). The marker stays put across\n * static-surrounds diffs (it morphs as a comment node), so it gives\n * the list reconciler a stable \"begin\" position even when surrounding\n * siblings get inserted, removed, or reordered around the list.\n *\n * `endAnchor(binding)` derives the \"insert at end of list\" anchor from\n * `marker.nextElementSibling` (empty list) or\n * `items[last].node.nextElementSibling` (non-empty list) — picking up\n * any non-list element the diff inserted between the list and the\n * parent's tail.\n */\n marker: Comment;\n}\n\n/**\n * Compute the live-DOM anchor that comes after the list's last item, used\n * by the apply* functions when inserting at the tail of the list.\n *\n * - Empty list: `marker.nextElementSibling` — the next non-list element\n * after the marker, or `null` if the list is the last thing in `liveParent`.\n * - Non-empty list: `items[last].node.nextElementSibling` — derived\n * dynamically so that non-list siblings the diff inserted between the\n * list's last item and the parent's tail still anchor correctly.\n */\nexport function endAnchor(binding: ListBinding): Element | null {\n if (binding.items.length > 0) {\n return binding.items[binding.items.length - 1].node.nextElementSibling;\n }\n return binding.marker.nextElementSibling;\n}\n","/**\n * Focus snapshot/restore for the keyed list reconciler.\n *\n * Some engines (older Safari, happy-dom) drop focus state on `insertBefore`\n * even when the focused element survives the move connected to the document.\n * The reconciler snapshots the active element + selection range before its\n * move pass, then re-applies them afterwards. Engines that already preserve\n * focus across DOM moves see a no-op; engines that don't get a transparent\n * fix.\n *\n * Lives in its own file (rather than inside `list-reconcile.ts`) to keep that\n * file under the 200-LOC project guideline and to isolate the engine-quirk\n * handling described in `docs/4-render.md` §4.4.\n */\n\nexport interface FocusSnapshot {\n el: HTMLElement;\n selStart: number | null;\n selEnd: number | null;\n}\n\n/**\n * Capture focus + selection on a focused descendant of `liveParent`.\n *\n * Returns null when the active element is outside the list (the diff path\n * handles those cases) or when there's no useful focus state to capture.\n */\nexport function captureFocus(liveParent: Element): FocusSnapshot | null {\n const active = document.activeElement;\n if (active === null || active === document.body) return null;\n if (!liveParent.contains(active)) return null;\n const el = active as HTMLElement;\n let selStart: number | null = null;\n let selEnd: number | null = null;\n if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA') {\n try {\n selStart = (el as HTMLInputElement).selectionStart;\n selEnd = (el as HTMLInputElement).selectionEnd;\n } catch {\n // Some input types (number, range, color, …) reject selection APIs.\n }\n }\n return { el, selStart, selEnd };\n}\n\nexport function restoreFocus(snap: FocusSnapshot): void {\n if (document.activeElement === snap.el) return;\n if (!snap.el.isConnected) return;\n snap.el.focus();\n if (snap.selStart !== null && snap.selEnd !== null) {\n try {\n (snap.el as HTMLInputElement).setSelectionRange(snap.selStart, snap.selEnd);\n } catch {\n // Selection may have been clobbered by .focus(); not fatal.\n }\n }\n}\n","/**\n * Shared \"exactly one top-level element per row\" contract helpers (KF-103).\n *\n * The keyed-list reconciler in `list-reconcile.ts` and the first-render\n * binding path in `mount.ts` both enforce the same contract on `each()`\n * row HTML. Centralising the constants and helpers here keeps the three\n * call sites that build error snippets and the eight call sites that\n * parse a row's HTML into a template element from drifting (KF-111 +\n * KF-115).\n */\n\n/**\n * Truncation limit applied to row HTML when including it in a contract-\n * violation error message. Keeps the error readable when a row produced\n * megabytes of HTML by accident.\n */\nexport const ROW_HTML_SNIPPET_MAX = 120;\n\n/**\n * Truncate a row's HTML for inclusion in an error message. Returns the\n * raw string if it's short enough; otherwise the first\n * `ROW_HTML_SNIPPET_MAX` characters with a trailing ellipsis.\n */\nexport function truncateRowHtml(html: string): string {\n return html.length > ROW_HTML_SNIPPET_MAX\n ? html.slice(0, ROW_HTML_SNIPPET_MAX) + '…'\n : html;\n}\n\n/**\n * Parse a row's HTML into a `<template>` and report how many top-level\n * elements it produced. The reconciler uses the count to detect contract\n * violations (count !== 1) on both single-row and bulk-row paths.\n */\nexport function parseRowTemplate(html: string): { tpl: HTMLTemplateElement; count: number } {\n const tpl = document.createElement('template');\n tpl.innerHTML = html;\n return { tpl, count: tpl.content.children.length };\n}\n\n/**\n * Build a precise contract-violation `Error` for the row at `index` whose\n * render produced the given `html`. The thrown message mentions the row\n * index, the actual element count, and the (truncated) HTML so the author\n * can locate and fix the offending row quickly.\n */\nexport function rowContractError(index: number, html: string): Error {\n const { count } = parseRowTemplate(html);\n const reason = count === 0\n ? 'produced no top-level element'\n : `produced ${count} top-level elements; exactly one is required`;\n return new Error(\n `each(): row render at index ${index} ${reason}. `\n + 'Each item\\'s render must return exactly one element — '\n + 'wrap multiple roots in a single parent (e.g. <li>...</li>). '\n + `Got HTML: ${JSON.stringify(truncateRowHtml(html))}`,\n );\n}\n","/**\n * Granular reconcile path for `each(...)` bound to an `arraySignal` (KF-92).\n *\n * Applies the patch events emitted by `arraySignal` mutators directly to\n * the live DOM and to `binding.items`, without iterating the full snapshot\n * or doing a classify pass. Cost is O(patches), not O(N).\n *\n * Two perf optimisations:\n * - **KF-93**: contiguous insert runs (patches at index N, N+1, N+2, …) are\n * bulk-parsed in one `template.innerHTML` call and inserted as a single\n * fragment. Saves ~50 ms on append-1k.\n * - **KF-94**: consecutive update runs (any indices — `replaceChild`\n * operates on each row's existing live node independently) are bulk-\n * parsed in one `template.innerHTML` call. Saves the per-patch parse\n * cost on the krausest partial-update scenario.\n *\n * Patches with `type: 'replace'` are filtered out by `each()` upstream and\n * never reach this function (the runtime contract guarantees absence even\n * though the TypeScript type allows them).\n *\n * Internal to kerf — re-exported via `list-reconcile.ts`'s `reconcileList`.\n */\n\nimport { type BoundItem, endAnchor, type ListBinding } from './list-binding.js';\nimport { captureFocus, restoreFocus } from './list-reconcile-focus.js';\nimport type { ListSegment } from './segment.js';\nimport { parseRowTemplate, rowContractError, truncateRowHtml } from './utils/rowContract.js';\n\nexport function reconcileGranular(\n binding: ListBinding,\n patches: NonNullable<ListSegment['patches']>,\n): void {\n const { liveParent } = binding;\n const items = binding.items;\n\n // Capture/restore focus around the whole batch (mirrors the snapshot\n // path's KF-65 fix). Some engines (older Safari, happy-dom) blur a\n // focused descendant on `insertBefore` / `replaceChild` even when the\n // ancestor stays connected — covers the move patch (which moves an\n // existing row's <li>), and is a no-op on engines that already\n // preserve focus across DOM ops.\n const focusSnap = captureFocus(liveParent);\n\n let i = 0;\n while (i < patches.length) {\n const patch = patches[i];\n /* c8 ignore next 5 — replace is filtered upstream by each(); this branch\n is defensive type-completeness only. */\n if (patch.type === 'replace') {\n i += 1;\n continue;\n }\n if (patch.type === 'update') {\n // KF-94: detect a run of consecutive update patches (any indices —\n // replaceChild operates on each row's existing live node independently,\n // so contiguity isn't required) and bulk-parse all their HTML in a\n // single `template.innerHTML` call. Saves the per-patch parse overhead\n // on krausest's partial-update scenario (100 update patches at\n // indices 0, 10, 20, … — non-contiguous, so KF-93's run detector\n // doesn't kick in).\n let runEnd = i + 1;\n while (runEnd < patches.length && patches[runEnd].type === 'update') {\n runEnd += 1;\n }\n const runLen = runEnd - i;\n if (runLen === 1) {\n applySingleUpdate(liveParent, items, patch);\n } else {\n applyBulkUpdate(liveParent, items, patches, i, runEnd);\n }\n i = runEnd;\n continue;\n }\n if (patch.type === 'insert') {\n // KF-93: detect a contiguous run of inserts at adjacent indices (each\n // next insert at the previous one's index + 1) and bulk-parse all\n // their HTML in a single `template.innerHTML` call, followed by a\n // single `insertBefore(fragment, anchor)`.\n let runEnd = i + 1;\n while (runEnd < patches.length\n && patches[runEnd].type === 'insert'\n && (patches[runEnd] as { index: number }).index\n === (patches[runEnd - 1] as { index: number }).index + 1) {\n runEnd += 1;\n }\n const runLen = runEnd - i;\n if (runLen === 1) {\n applySingleInsert(liveParent, items, patch, endAnchor(binding));\n } else {\n applyBulkInsert(liveParent, items, patches, i, runEnd, endAnchor(binding));\n }\n i = runEnd;\n continue;\n }\n if (patch.type === 'remove') {\n const entry = items[patch.index];\n liveParent.removeChild(entry.node);\n items.splice(patch.index, 1);\n i += 1;\n continue;\n }\n if (patch.type === 'move') {\n const moved = items[patch.from];\n // Compute the anchor BEFORE we splice, so the index references the\n // pre-move state.\n let anchorIdx = patch.to;\n if (patch.from < patch.to) anchorIdx += 1; // account for upcoming splice removal\n const anchor = anchorIdx < items.length ? items[anchorIdx].node : endAnchor(binding);\n liveParent.insertBefore(moved.node, anchor);\n items.splice(patch.from, 1);\n items.splice(patch.to, 0, moved);\n i += 1;\n continue;\n }\n }\n\n if (focusSnap !== null) restoreFocus(focusSnap);\n}\n\nfunction applySingleInsert(\n liveParent: Element,\n items: BoundItem[],\n patch: { type: 'insert'; index: number; item: object; html: string },\n tailAnchor: Element | null,\n): void {\n const { html } = patch;\n const newNode = parseSingleRow(html);\n const anchor = patch.index < items.length ? items[patch.index].node : tailAnchor;\n liveParent.insertBefore(newNode, anchor);\n items.splice(patch.index, 0, {\n ref: patch.item, cacheKey: undefined, html, node: newNode,\n });\n}\n\nfunction applySingleUpdate(\n liveParent: Element,\n items: BoundItem[],\n patch: { type: 'update'; index: number; item: object; html: string },\n): void {\n const { html } = patch;\n const oldEntry = items[patch.index];\n if (html === oldEntry.html) return; // no-op (defensive: caller may emit redundant patches)\n const newNode = parseSingleRow(html);\n liveParent.replaceChild(newNode, oldEntry.node);\n items[patch.index] = { ref: patch.item, cacheKey: undefined, html, node: newNode };\n}\n\n/**\n * Bulk-parse a run of consecutive update patches (KF-94). Indices may be\n * scattered (non-contiguous). Renders all HTMLs first, filters out no-ops\n * where the new HTML matches the old, then bulk-parses the remaining HTMLs\n * in one `template.innerHTML` call. The replaceChild loop afterwards is\n * unavoidable (one DOM op per row), but we save the per-patch parse cost.\n */\nfunction applyBulkUpdate(\n liveParent: Element,\n items: BoundItem[],\n patches: NonNullable<ListSegment['patches']>,\n start: number,\n end: number,\n): void {\n // Patches already carry pre-rendered HTML (KF-99). Filter out no-ops where\n // the new HTML matches the existing entry's html.\n interface Change { patchIdx: number; html: string }\n const changes: Change[] = [];\n for (let k = start; k < end; k++) {\n const p = patches[k] as { type: 'update'; index: number; item: object; html: string };\n if (p.html !== items[p.index].html) {\n changes.push({ patchIdx: k, html: p.html });\n }\n }\n if (changes.length === 0) return; // every update was a no-op\n\n // Bulk-parse all real changes in one innerHTML call.\n const { tpl, count } = parseRowTemplate(changes.map((c) => c.html).join(''));\n if (count !== changes.length) {\n throw findOffendingChange(patches, changes);\n }\n // Count matches; walk children unconditionally.\n const newNodes = new Array<Element>(changes.length);\n let child = tpl.content.firstElementChild;\n for (let k = 0; k < newNodes.length; k++) {\n newNodes[k] = child as Element;\n child = (child as Element).nextElementSibling;\n }\n\n // Apply replaceChild for each real change.\n for (let k = 0; k < changes.length; k++) {\n const c = changes[k];\n const p = patches[c.patchIdx] as { type: 'update'; index: number; item: object; html: string };\n const oldEntry = items[p.index];\n liveParent.replaceChild(newNodes[k], oldEntry.node);\n items[p.index] = { ref: p.item, cacheKey: undefined, html: c.html, node: newNodes[k] };\n }\n}\n\n/**\n * Bulk-parse a contiguous run of insert patches (KF-93). The run starts at\n * `start` (inclusive) and ends at `end` (exclusive); every patch in that\n * range is type `insert` with index === previous.index + 1. We render each\n * row's HTML, concatenate, parse the lot in one `template.innerHTML`, and\n * insert the resulting fragment in a single DOM op.\n */\nfunction applyBulkInsert(\n liveParent: Element,\n items: BoundItem[],\n patches: NonNullable<ListSegment['patches']>,\n start: number,\n end: number,\n tailAnchor: Element | null,\n): void {\n const startIdx = (patches[start] as { index: number }).index;\n const htmls = new Array<string>(end - start);\n for (let k = start; k < end; k++) {\n const p = patches[k] as { type: 'insert'; index: number; item: object; html: string };\n htmls[k - start] = p.html;\n }\n const { tpl, count } = parseRowTemplate(htmls.join(''));\n if (count !== htmls.length) {\n throw findOffendingInsert(patches, start, htmls);\n }\n // Count matches; capture child refs BEFORE the fragment-insert empties\n // tpl.content. Walk unconditionally — count check above guarantees\n // `firstElementChild` is non-null and there are exactly `end - start`\n // children.\n const newNodes = new Array<Element>(end - start);\n let child = tpl.content.firstElementChild;\n for (let k = 0; k < newNodes.length; k++) {\n newNodes[k] = child as Element;\n child = (child as Element).nextElementSibling;\n }\n const anchor = startIdx < items.length ? items[startIdx].node : tailAnchor;\n liveParent.insertBefore(tpl.content, anchor);\n // Splice all new entries into binding.items at the run's start index.\n const newEntries = new Array<BoundItem>(end - start);\n for (let k = 0; k < newEntries.length; k++) {\n const p = patches[start + k] as { type: 'insert'; index: number; item: object; html: string };\n newEntries[k] = {\n ref: p.item, cacheKey: undefined, html: htmls[k], node: newNodes[k],\n };\n }\n items.splice(startIdx, 0, ...newEntries);\n}\n\n/**\n * Parse a single row's HTML string into one Element. Used by the granular\n * reconciler's single-row paths (`applySingleInsert`, `applySingleUpdate`).\n * Each row is expected to render exactly one top-level element (the same\n * contract `each()` enforces in the snapshot path).\n */\nfunction parseSingleRow(html: string): Element {\n const { tpl, count } = parseRowTemplate(html);\n if (count !== 1) {\n const reason = count === 0\n ? 'produced no top-level element'\n : `produced ${count} top-level elements; exactly one is required`;\n throw new Error(\n `each() granular reconcile: row render ${reason}. `\n + 'Each item\\'s render must return exactly one element. '\n + `Got HTML: ${JSON.stringify(truncateRowHtml(html))}`,\n );\n }\n return tpl.content.firstElementChild as Element;\n}\n\n/**\n * Slow-path helper for `applyBulkInsert`. Walks each pre-rendered insert\n * patch's html in isolation to find the offending row.\n */\nfunction findOffendingInsert(\n patches: NonNullable<ListSegment['patches']>,\n start: number,\n htmls: string[],\n): Error {\n for (let i = 0; i < htmls.length; i++) {\n if (parseRowTemplate(htmls[i]).count !== 1) {\n const p = patches[start + i] as { type: 'insert'; index: number };\n return rowContractError(p.index, htmls[i]);\n }\n }\n /* c8 ignore start */\n return new Error('each(): bulk-insert mismatch with no per-row offender (kerf bug).');\n}\n/* c8 ignore stop */\n\n/**\n * Slow-path helper for `applyBulkUpdate`. Walks each non-no-op change to\n * find the offending row.\n */\nfunction findOffendingChange(\n patches: NonNullable<ListSegment['patches']>,\n changes: { patchIdx: number; html: string }[],\n): Error {\n for (const c of changes) {\n if (parseRowTemplate(c.html).count !== 1) {\n const p = patches[c.patchIdx] as { type: 'update'; index: number };\n return rowContractError(p.index, c.html);\n }\n }\n /* c8 ignore start */\n return new Error('each(): bulk-update mismatch with no per-row offender (kerf bug).');\n}\n/* c8 ignore stop */\n","/**\n * Snapshot reconcile path for `each(...)` — the original (non-granular)\n * keyed-list algorithm. Used when:\n * - The list is rendered with a plain array (not an `arraySignal`).\n * - The list is rendered with an `arraySignal` but no patch queue is\n * present (first render, post-`replace()`, or post-drift recovery).\n *\n * Algorithm:\n * 1. Classify each new item as `stable` (cache hit on identity + html),\n * `replaced` (same ref, html changed), or `new` (never seen before).\n * 2. Bulk-parse every fresh row's HTML in ONE `innerHTML` call — for an\n * initial population of 10k rows that's 1 parse instead of 10k.\n * 3. Remove orphan refs (gone from the new list) + replaced rows' old nodes.\n * 4. Compute a longest-increasing-subsequence over old positions; items in\n * the LIS are already in the right relative order, so they don't move.\n * 5. Reverse-pass over the new record, `insertBefore` only the items that\n * didn't anchor the LIS.\n *\n * The KF-89 fast path short-circuits when nothing structural changed —\n * the live tree already matches the new segment, so we can return after\n * step 1 with just the binding update.\n *\n * Internal to kerf — re-exported via `list-reconcile.ts`'s `reconcileList`.\n */\n\nimport { type BoundItem, endAnchor, type ListBinding } from './list-binding.js';\nimport { captureFocus, restoreFocus } from './list-reconcile-focus.js';\nimport type { ListSegment } from './segment.js';\nimport { parseRowTemplate, rowContractError } from './utils/rowContract.js';\n\ninterface Classification {\n newRecord: BoundItem[];\n prevIdx: number[];\n replacedNodes: Element[];\n freshIndices: number[];\n freshHtmls: string[];\n}\n\n/**\n * Reconcile via the snapshot algorithm. Mutates `binding.items` to mirror\n * the new segment when done.\n *\n * Focus capture/restore lives in `list-reconcile-focus.ts` — `insertBefore`\n * of a focused descendant's ancestor blurs the element in some engines\n * (happy-dom, older Safari) even when it stays connected; the snapshot fixes\n * those engines and is a no-op on engines that already preserve focus.\n */\nexport function reconcileSnapshot(binding: ListBinding, listSeg: ListSegment): void {\n const { liveParent } = binding;\n const { newRecord, prevIdx, replacedNodes, freshIndices, freshHtmls }\n = classifyItems(binding.items, listSeg);\n\n // KF-89 fast path: if no items were replaced, none are fresh, and every\n // surviving item kept its original position, the live tree already matches\n // the new segment. Skip buildFreshNodes (nothing to build), removeOldNodes\n // (nothing to remove), the LIS pass (no reorder possible), and applyMoves'\n // reverse walk (no moves). For a 1k-row list whose only change is a signal\n // re-read with no item-array delta, this collapses ~10–15 ms of per-render\n // bookkeeping into a single classification pass + the binding update.\n if (replacedNodes.length === 0 && freshIndices.length === 0\n && isInOrder(prevIdx)) {\n binding.items = newRecord;\n return;\n }\n\n // Compute tail anchor BEFORE removing old nodes: once an item is\n // detached, its `.nextElementSibling` is null and we lose the\n // boundary. Capturing here uses the binding's current (pre-mutation)\n // items[last].node which is still attached.\n const tailAnchor = endAnchor(binding);\n buildFreshNodes(newRecord, freshIndices, freshHtmls);\n const focusSnap = captureFocus(liveParent);\n removeOldNodes(liveParent, replacedNodes);\n applyMoves(liveParent, newRecord, prevIdx, lis(prevIdx), tailAnchor);\n if (focusSnap !== null) restoreFocus(focusSnap);\n binding.items = newRecord;\n}\n\n/**\n * Classify each item in the new segment against the old binding. Items with\n * a cache-hit (same ref + same html) are reused; replaced/new items get a\n * placeholder `BoundItem` whose `node` is filled in by the bulk parse below.\n */\nfunction classifyItems(oldItems: BoundItem[], listSeg: ListSegment): Classification {\n // Single Map<ref, [item, index]> instead of two Maps over the same key set\n // (KF-90). Halves the .set() calls during the build, halves the lookup\n // probe count during classification. ~1-2 ms saved per render on 1k-row\n // lists.\n const oldByRef = new Map<object, [BoundItem, number]>();\n for (let i = 0; i < oldItems.length; i++) {\n oldByRef.set(oldItems[i].ref, [oldItems[i], i]);\n }\n\n const newRecord: BoundItem[] = new Array(listSeg.items.length);\n const prevIdx = new Array<number>(listSeg.items.length);\n const replacedNodes: Element[] = [];\n const freshIndices: number[] = [];\n const freshHtmls: string[] = [];\n\n for (let i = 0; i < listSeg.items.length; i++) {\n const ni = listSeg.items[i];\n const oi = oldByRef.get(ni.ref);\n if (oi !== undefined) {\n oldByRef.delete(ni.ref);\n if (oi[0].html === ni.html) {\n newRecord[i] = oi[0];\n prevIdx[i] = oi[1];\n continue;\n }\n replacedNodes.push(oi[0].node);\n }\n newRecord[i] = {\n ref: ni.ref, cacheKey: ni.cacheKey, html: ni.html, node: null as unknown as Element,\n };\n prevIdx[i] = -1;\n freshIndices.push(i);\n freshHtmls.push(ni.html);\n }\n\n // Whatever's left in oldByRef is an orphan ref that disappeared from the\n // new list. The caller removes those nodes alongside the replaced ones.\n for (const [, orphan] of oldByRef) replacedNodes.push(orphan[0].node);\n\n return { newRecord, prevIdx, replacedNodes, freshIndices, freshHtmls };\n}\n\n/**\n * Bulk-parse every fresh row's HTML in one `innerHTML` call, then walk the\n * parsed children in order and fill in each placeholder's `node` field.\n *\n * Enforces the \"exactly one top-level element per row\" contract (KF-103):\n * if the bulk parse produces a different number of top-level elements\n * than fresh rows, fall back to per-row parsing to identify the offending\n * row and throw a precise error. The success path stays a single parse.\n */\nfunction buildFreshNodes(\n newRecord: BoundItem[],\n freshIndices: number[],\n freshHtmls: string[],\n): void {\n if (freshHtmls.length === 0) return;\n const { tpl, count } = parseRowTemplate(freshHtmls.join(''));\n if (count !== freshHtmls.length) {\n throw findOffendingRow(newRecord, freshIndices, freshHtmls);\n }\n // After the count check above, we know `tpl.content.children.length`\n // equals `freshIndices.length`, so the walk below always finds an element\n // for every index. No defensive null-guard needed.\n let node = tpl.content.firstElementChild;\n for (const idx of freshIndices) {\n const next = (node as Element).nextElementSibling;\n newRecord[idx].node = node as Element;\n node = next;\n }\n}\n\n/**\n * Walk per-row to find the offending row that violated the contract,\n * returning a precise error to throw. Only invoked when the bulk parse\n * detected a count mismatch — the success path is one parse with no\n * per-row work.\n */\nfunction findOffendingRow(\n newRecord: BoundItem[],\n freshIndices: number[],\n freshHtmls: string[],\n): Error {\n for (let i = 0; i < freshHtmls.length; i++) {\n if (parseRowTemplate(freshHtmls[i]).count !== 1) {\n return rowContractError(freshIndices[i], newRecord[freshIndices[i]].html);\n }\n }\n /* c8 ignore next 2 — unreachable: bulk mismatch ⇒ at least one row violates. */\n return new Error('each(): bulk-parse mismatch with no per-row offender (kerf bug).');\n}\n\n/**\n * Remove every replaced/orphan node still attached to the live parent.\n */\nfunction removeOldNodes(liveParent: Element, replacedNodes: Element[]): void {\n for (const node of replacedNodes) {\n if (node.parentElement === liveParent) liveParent.removeChild(node);\n }\n}\n\n/**\n * `insertBefore` everything that's not in the LIS. Walks the new record in\n * reverse so each move's anchor (`nextSibling`) is already in its final\n * position by the time we reach earlier items.\n *\n * `tailAnchor` is the element that comes AFTER the list inside `liveParent`\n * (or `null` if the list is at the end). The reconciler computes it via\n * `endAnchor(binding)` so it picks up non-list siblings the diff may have\n * inserted between the list and the parent's tail (KF-102).\n */\nfunction applyMoves(\n liveParent: Element,\n newRecord: BoundItem[],\n prevIdx: number[],\n stable: ReadonlySet<number>,\n tailAnchor: Element | null,\n): void {\n let nextSibling: Element | null = tailAnchor;\n for (let i = newRecord.length - 1; i >= 0; i--) {\n const node = newRecord[i].node;\n if (prevIdx[i] === -1 || !stable.has(i)) {\n liveParent.insertBefore(node, nextSibling);\n }\n nextSibling = node;\n }\n}\n\n/**\n * Patience-sort LIS: returns the *set of indices* in `arr` that participate\n * in a longest strictly-increasing subsequence. `-1` entries (representing\n * brand-new items in the new list) are ignored — they can't anchor the\n * subsequence and shouldn't count as stable.\n */\nfunction lis(arr: ReadonlyArray<number>): ReadonlySet<number> {\n const tails: number[] = [];\n const tailIdx: number[] = [];\n const prev = new Array<number>(arr.length);\n for (let i = 0; i < arr.length; i++) {\n const v = arr[i];\n if (v === -1) {\n prev[i] = -1;\n continue;\n }\n let lo = 0;\n let hi = tails.length;\n while (lo < hi) {\n const mid = (lo + hi) >> 1;\n if (tails[mid] < v) lo = mid + 1;\n else hi = mid;\n }\n prev[i] = lo > 0 ? tailIdx[lo - 1] : -1;\n tails[lo] = v;\n tailIdx[lo] = i;\n }\n const out = new Set<number>();\n let k = tailIdx.length > 0 ? tailIdx[tailIdx.length - 1] : -1;\n while (k !== -1) {\n out.add(k);\n k = prev[k];\n }\n return out;\n}\n\n/**\n * True iff `prevIdx` is `[0, 1, 2, …, n-1]` — every item kept the position it\n * had in the previous render. Used by `reconcileSnapshot` to short-circuit\n * the LIS + move pass when nothing structural changed.\n */\nfunction isInOrder(prevIdx: number[]): boolean {\n for (let i = 0; i < prevIdx.length; i++) {\n if (prevIdx[i] !== i) return false;\n }\n return true;\n}\n","/**\n * Keyed list reconciler — the engine behind `each(...)` inside `mount()`.\n *\n * Public surface (re-exported via the rest of the runtime):\n * - `BoundItem` / `ListBinding`: the binding shape `mount()` keeps\n * per-list, mapping `each()` items to their live DOM nodes.\n * Defined in `list-binding.ts` and re-exported here.\n * - `endAnchor(binding)`: dynamic \"insert at end of list\" anchor.\n * Also defined in `list-binding.ts` and re-exported here.\n * - `reconcileList(binding, listSeg)`: top-level dispatch.\n *\n * Implementation lives in two sibling files:\n * - `list-reconcile-snapshot.ts` — the original keyed algorithm\n * (classify / bulk-parse / LIS / move). Used for plain-array `each()`\n * and for arraySignal-backed `each()` when the patch path can't apply\n * (first render, post-`replace()`, post-drift recovery).\n * - `list-reconcile-granular.ts` — the KF-92 patch-driven path used\n * when an `arraySignal`'s queued patches can be applied directly to\n * the existing binding without iterating the snapshot.\n *\n * The split mirrors the two-axis nature of the reconciler: snapshot-vs-\n * granular path × shared bookkeeping (binding shape, end-of-list anchor,\n * focus capture/restore). The binding shape is in its own `list-binding.ts`\n * file so the two sibling reconcilers can import it without creating a\n * circular dependency back to `list-reconcile.ts`. Internal to kerf — not\n * part of the public API.\n */\n\nexport { type BoundItem, endAnchor, type ListBinding } from './list-binding.js';\nimport type { ListBinding } from './list-binding.js';\nimport { reconcileGranular } from './list-reconcile-granular.js';\nimport { reconcileSnapshot } from './list-reconcile-snapshot.js';\nimport type { ListSegment } from './segment.js';\n\n/**\n * Reconcile `binding`'s live parent against `listSeg`. Mutates `binding.items`\n * to mirror the new segment when done.\n *\n * Dispatch:\n * - **Granular (KF-92)**: an `arraySignal`-backed `each()` whose patch\n * queue is non-empty AND the binding has at least one row. Applies\n * patches directly. `each()` filters `replace` patches upstream so the\n * patches reaching here are guaranteed to be update/insert/remove/move\n * only.\n * - **Snapshot**: every other case — first render of a list, plain-array\n * `each()`, post-`replace()`, post-drift recovery. Runs the keyed\n * classify/build/move algorithm.\n */\nexport function reconcileList(binding: ListBinding, listSeg: ListSegment): void {\n if (listSeg.patches !== undefined && binding.items.length > 0) {\n reconcileGranular(binding, listSeg.patches);\n return;\n }\n reconcileSnapshot(binding, listSeg);\n}\n","/**\n * `mount(rootEl, render)` — kerf's render primitive.\n *\n * Wraps `effect()` so that whenever any signal read inside `render()`\n * changes, we re-run `render()` and apply the minimum DOM mutations against\n * the live tree. Element identity (and thus focus, selection, in-flight\n * pointer interactions, and event listeners on preserved nodes) is preserved\n * wherever the keyed/positional diff matches.\n *\n * Two phases per render:\n *\n * - Static surrounds (everything outside `each()` lists): kerf's native\n * `diff()` reconciler walks a freshly-built template against the live\n * tree. Conventions: id/data-key matching, `data-morph-skip`, focus\n * preservation.\n *\n * - List interiors (children of every `each()` parent): native keyed\n * reconciler operates directly on the live parent's children. No\n * re-parse, no morph walk for cache-hit rows. Cost is O(changes), not\n * O(rows).\n *\n * Compared to a `replaceChildren(...rows.map(toElement))` rebuild pattern,\n * the user-visible win is that an `<input>` the user is typing into\n * survives an unrelated re-render — its DOM node, focus state, and cursor\n * position are not destroyed and recreated on each tick.\n */\n\nimport { diff } from './diff.js';\nimport { _setRenderContext, type RenderContext } from './each.js';\nimport type { SafeHtml } from './jsx-runtime.js';\nimport { isSafeHtml } from './jsx-runtime.js';\nimport {\n type BoundItem,\n type ListBinding,\n reconcileList,\n} from './list-reconcile.js';\nimport { effect } from './reactive.js';\nimport {\n collectLists,\n flatten,\n flattenWithoutListItems,\n type ListSegment,\n type Segment,\n} from './segment.js';\nimport { parseRowTemplate, rowContractError } from './utils/rowContract.js';\n\nconst LIST_MARKER_PREFIX = 'kf-list:';\n\n/**\n * Bind `render()` to the children of `rootEl`. Re-runs whenever any signal\n * read inside `render()` changes. Returns a disposer that tears down the\n * effect; call it when the host element is removed from the DOM.\n *\n * Conventions:\n *\n * - Diff keys: `id` and `data-key` are matched across the morph by key\n * rather than positionally, so list reorders move existing nodes instead\n * of churning unrelated siblings.\n * - `data-morph-skip`: any element with this attribute is left untouched\n * inside on subsequent renders. Used for library-owned subtrees (xterm-\n * style widgets, charts, third-party editors) where the library's own\n * lifecycle manages the children.\n * - Focused text-entry inputs (`<input>` of typing kinds, `<textarea>`)\n * keep their current value + selection range across morphs while focused.\n * The user never sees their cursor jump mid-keystroke.\n * - Focused `[contenteditable]` elements have their entire subtree\n * skipped (same mechanism as `data-morph-skip`). The user's in-progress\n * edit — typed content, caret position, multi-range selections, anything\n * else they did to the DOM — survives verbatim. The next render after\n * blur catches up.\n */\nexport type MountResult = SafeHtml | string | number | boolean | null | undefined;\n\nexport function mount(rootEl: HTMLElement, render: () => MountResult): () => void {\n if (rootEl == null) {\n throw new Error(\n 'mount: rootEl is null/undefined — pass the live element, e.g. mount(document.getElementById(\"app\")!, render). '\n + 'A common cause is a typo in the id or selector that returns null at runtime even though the TypeScript types say HTMLElement.',\n );\n }\n const bindings = new Map<string, ListBinding>();\n // Per-mount render context: the list-id counter is reset at the start of\n // each render (so the n-th `each()` call gets the same id every render);\n // the `caches` map persists across renders so unchanged items skip the\n // JSX work via cache hits even when the JSX render function is an inline\n // arrow that's a fresh function reference on every closure run (KF-87).\n const renderCtx: RenderContext = {\n counter: 0,\n caches: new Map(),\n bindingCounts: new Map(),\n };\n let isFirst = true;\n // KF-88: the static-surrounds HTML string from the previous render. If a\n // re-render produces the same string (the common case when a signal flips\n // a class on one row but the page chrome is unchanged), we skip the\n // template clone, the innerHTML re-parse, and the diff() walk entirely\n // and go straight to the per-list reconcilers. Saves ~8 ms per update-\n // path render against the krausest harness.\n let prevStaticHtml = '';\n\n return effect(() => {\n renderCtx.counter = 0;\n _setRenderContext(renderCtx);\n let result: MountResult;\n try {\n result = render();\n } finally {\n _setRenderContext(null);\n }\n\n // The `MountResult` union covers `null`, `undefined`, `false`, `true`,\n // and `number` so consumers can write `() => cond ? <jsx/> : null` and\n // `() => cond && <jsx/>` without a cast. `coerceRenderResult` collapses\n // nullish + boolean to `''` (render nothing) and stringifies numbers.\n const segment: Segment = isSafeHtml(result)\n ? (result.__segment ?? { kind: 'static', html: result.__html })\n : { kind: 'static', html: coerceRenderResult(result) };\n\n if (isFirst) {\n runFirstRender(rootEl, segment, bindings);\n prevStaticHtml = flattenWithoutListItems(segment);\n isFirst = false;\n } else {\n prevStaticHtml = runSubsequentRender(rootEl, segment, bindings, renderCtx, prevStaticHtml);\n }\n\n for (const listSeg of collectLists(segment).values()) {\n const binding = bindings.get(listSeg.id) as ListBinding;\n reconcileList(binding, listSeg);\n // KF-99: record the post-reconcile binding length so the next render's\n // granular path can detect drift (a prior render that threw mid-batch\n // leaves the binding shorter than the signal expects).\n renderCtx.bindingCounts.set(listSeg.id, binding.items.length);\n }\n });\n}\n\n/**\n * First render of a mount: bulk-flatten the segment (items inlined, markers\n * around each list) into `rootEl.innerHTML`, then walk the markers to\n * register a `ListBinding` per list. The subsequent `reconcileList` pass is\n * a no-op (every row's a cache hit on the just-bound items).\n */\nfunction runFirstRender(\n rootEl: HTMLElement,\n segment: Segment,\n bindings: Map<string, ListBinding>,\n): void {\n rootEl.innerHTML = flatten(segment, true);\n bindListsFromMarkers(rootEl, segment, bindings, true);\n}\n\n/**\n * Subsequent render of a mount. Returns the new `prevStaticHtml` so the\n * caller can carry it forward.\n *\n * Two paths:\n *\n * - **KF-88 fast path**: when the static-surrounds string didn't change\n * byte-for-byte, `bindListsFromMarkers` has nothing to discover and the\n * diff would short-circuit on `isEqualNode` for every element it visited —\n * but the visit itself isn't free. Skip both to save ~8 ms per partial-\n * update / select-row / swap-rows render against the krausest harness.\n *\n * Trade-off (KF-117, documented in `docs/4-render.md` §4.4.2): any\n * attribute or child set imperatively on a kerf-managed element (e.g.\n * `el.setAttribute(...)`) survives across no-op re-renders because the\n * diff doesn't run to wipe it. When the surrounds DO change, the diff\n * runs and `morphAttributes` removes anything the JSX didn't authorise.\n * This matches the framework's \"smallest cut\" model: don't touch what\n * JSX didn't change.\n *\n * - **Surrounds-changed path**: clean up orphan bindings (lists that\n * disappeared from this render's segment), build a template from the\n * static-only HTML, run `diff()` over the surrounds with the\n * list-owned items as `ownedItems` (KF-102 round 2 — the diff skips\n * owned items individually but still walks every parent so non-list\n * siblings around an each() reconcile correctly), then bind any\n * newly-appearing lists.\n */\nfunction runSubsequentRender(\n rootEl: HTMLElement,\n segment: Segment,\n bindings: Map<string, ListBinding>,\n renderCtx: RenderContext,\n prevStaticHtml: string,\n): string {\n const currentStaticHtml = flattenWithoutListItems(segment);\n if (currentStaticHtml === prevStaticHtml) {\n return prevStaticHtml;\n }\n cleanupOrphanBindings(segment, bindings, renderCtx);\n const template = rootEl.cloneNode(false) as HTMLElement;\n template.innerHTML = currentStaticHtml;\n diff(rootEl, template, collectOwnedItems(bindings));\n bindListsFromMarkers(rootEl, segment, bindings, false);\n return currentStaticHtml;\n}\n\n/**\n * Coerce a non-`SafeHtml` render result to a safe HTML string. Nullish\n * values and booleans become `''` (render nothing) — matches the React /\n * Solid convention so `{cond ? <jsx/> : null}` and `{cond && <jsx/>}`\n * patterns work without each consumer adding a sentinel. Everything else\n * is stringified (numbers → `\"42\"`, strings pass through).\n */\nfunction coerceRenderResult(result: unknown): string {\n if (result === null || result === undefined) return '';\n if (result === false || result === true) return '';\n return String(result);\n}\n\n/**\n * Walk the live tree's comment nodes; every `<!--kf-list:{id}-->` marker\n * is the start anchor of a list inside `liveParent`. Bind the list (parent +\n * already-rendered item nodes between the marker and the tail). The marker\n * stays in the live DOM (KF-102 round 2): keeping it as a permanent\n * comment-node anchor lets the static-surrounds diff insert/remove/morph\n * non-list siblings around the list without needing to re-establish the\n * list's begin position.\n *\n * `inlinedItems` distinguishes the first-render path (where `flatten(seg,\n * true)` inlines item HTML right after the marker, so the marker's element\n * siblings *are* the list rows) from subsequent renders that newly\n * introduce a list (where `flattenWithoutListItems` emits only the marker\n * and the list reconciler populates items afterwards).\n *\n * Existing bindings whose marker is still in the DOM are left intact —\n * `bindings.has(id)` skips re-binding so the prior render's item nodes\n * survive across static-surrounds diffs.\n */\nfunction bindListsFromMarkers(\n rootEl: Element,\n segment: Segment,\n bindings: Map<string, ListBinding>,\n inlinedItems: boolean,\n): void {\n const lists = collectLists(segment);\n const found: Comment[] = [];\n collectComments(rootEl, found);\n for (const marker of found) {\n if (!marker.data.startsWith(LIST_MARKER_PREFIX)) continue;\n const id = marker.data.slice(LIST_MARKER_PREFIX.length);\n if (bindings.has(id)) continue; // existing binding survives the diff\n const listSeg = lists.get(id) as ListSegment;\n const liveParent = marker.parentElement as Element;\n const items: BoundItem[] = [];\n if (inlinedItems) {\n // KF-103: enforce the \"exactly one top-level element per row\" contract\n // on first render too. Without this check, a multi-root row inlined\n // via `flatten(seg, true)` would silently misalign the binding (each\n // bound item.node points at only the first of a row's 2+ elements,\n // and the leftover elements are picked up as \"next\" rows). The check\n // is per-row so we can pinpoint the offender by index.\n let next: Element | null = marker.nextElementSibling;\n for (let i = 0; i < listSeg.items.length && next !== null; i++) {\n validateInlinedRowMatch(listSeg.items[i].html, i, next);\n items.push({\n ref: listSeg.items[i].ref,\n cacheKey: listSeg.items[i].cacheKey,\n html: listSeg.items[i].html,\n node: next,\n });\n next = next.nextElementSibling;\n }\n }\n bindings.set(id, { liveParent, items, marker });\n }\n}\n\n/**\n * KF-103: validate that `expectedHtml` (one row's render output) matches\n * the live `boundEl`'s `outerHTML` — confirming the row produced exactly\n * one top-level element. If they differ, parse the row in isolation and\n * throw a precise error mentioning the row index and the actual count.\n *\n * Fast path: outerHTML compare is a string equality check (zero allocs in\n * happy-dom; one alloc in V8). Only when they DON'T match (multi-root or\n * subtle browser-normalised single-root case) do we fall back to a full\n * per-row parse for the precise count.\n */\nfunction validateInlinedRowMatch(\n expectedHtml: string,\n index: number,\n boundEl: Element,\n): void {\n if (boundEl.outerHTML === expectedHtml) return;\n // The bound element's outerHTML differs from what we emitted. Parse the\n // expected html in isolation; if it's still single-root the difference\n // is whitespace / browser-normalisation (e.g. `<br/>` → `<br>`) and\n // we proceed silently. Otherwise build the precise contract-violation\n // error from the shared helper.\n const { count } = parseRowTemplate(expectedHtml);\n if (count === 1) return;\n throw rowContractError(index, expectedHtml);\n}\n\n/**\n * Build the set of element nodes owned by `each()` list reconcilers, the\n * union of every binding's `items[].node`. The static-surrounds diff\n * skips these so list rows are invisible to the parent walk while\n * sibling reconciliation continues normally (KF-102 round 2).\n */\nfunction collectOwnedItems(bindings: Map<string, ListBinding>): Set<Element> {\n const owned = new Set<Element>();\n for (const b of bindings.values()) {\n for (const item of b.items) owned.add(item.node);\n }\n return owned;\n}\n\n/**\n * Remove items + binding entries for any list that's no longer present in\n * the new segment. The diff's trailing-removal pass would have removed the\n * marker (since the new template no longer emits one for this id), but\n * items are owned and stay protected from removal — so we drop them\n * explicitly here before the diff runs.\n */\nfunction cleanupOrphanBindings(\n segment: Segment,\n bindings: Map<string, ListBinding>,\n renderCtx: RenderContext,\n): void {\n const liveIds = collectLists(segment);\n for (const [id, binding] of bindings) {\n if (liveIds.has(id)) continue;\n for (const item of binding.items) {\n if (item.node.parentElement !== null) {\n item.node.parentElement.removeChild(item.node);\n }\n }\n if (binding.marker.parentElement !== null) {\n binding.marker.parentElement.removeChild(binding.marker);\n }\n bindings.delete(id);\n renderCtx.bindingCounts.delete(id);\n renderCtx.caches.delete(id);\n }\n}\n\n/**\n * Recursive collector for comment nodes — happy-dom's `TreeWalker` doesn't\n * surface `Node.COMMENT_NODE` despite accepting `NodeFilter.SHOW_COMMENT`,\n * so we walk children directly. Cheap (O(elements)) and portable.\n */\nfunction collectComments(node: Node, out: Comment[]): void {\n for (let c: Node | null = node.firstChild; c !== null; c = c.nextSibling) {\n if (c.nodeType === Node.COMMENT_NODE) out.push(c as Comment);\n else if (c.nodeType === Node.ELEMENT_NODE) collectComments(c, out);\n }\n}\n\n\n","/**\n * `toElement(jsx)` — JSX → DOM, with SVG-aware namespace handling.\n *\n * The naive implementation parses JSX through a `<template>` element's\n * `innerHTML`. That works for HTML and for SVG fragments whose root tag is\n * `<svg>` (the parser switches to \"foreign content\" mode). It silently\n * fails for SVG fragments WITHOUT an `<svg>` wrapper — descendants come out\n * as `HTMLUnknownElement` and never paint.\n *\n * `toElement` detects SVG content and routes through `DOMParser` with the\n * `image/svg+xml` MIME, which guarantees correct namespacing for all\n * descendants. HTML content takes the original `<template>` path unchanged.\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', 'path', 'circle', 'rect', 'line', 'polygon', 'polyline', 'ellipse',\n 'text', 'tspan', 'defs', 'use', 'symbol', 'clipPath', 'mask', 'pattern',\n 'filter', 'marker', 'linearGradient', 'radialGradient', 'stop', 'image',\n 'foreignObject',\n]);\n\nconst EXCERPT_MAX_LEN = 100;\n\nfunction leadingTag(html: string): string | null {\n const match = /^\\s*<([a-zA-Z][a-zA-Z0-9]*)\\b/.exec(html);\n return match !== null ? match[1] : null;\n}\n\nfunction excerpt(html: string): string {\n const trimmed = html.trim();\n return trimmed.length > EXCERPT_MAX_LEN ? `${trimmed.slice(0, EXCERPT_MAX_LEN)}…` : trimmed;\n}\n\nfunction parseSvgOrThrow(html: string, label: string, originalHtml: string): 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(`toElement: ${label} parse error — ${err.textContent}\\n input: ${excerpt(originalHtml)}`);\n }\n return doc;\n}\n\nexport function toElement(jsx: SafeHtml | string): Element {\n const html = typeof jsx === 'string' ? jsx : jsx.toString();\n const tag = leadingTag(html);\n\n if (tag === 'svg') {\n // SVG root — parse as XML to guarantee namespace propagation.\n return parseSvgOrThrow(html, 'SVG', html).documentElement;\n }\n\n if (tag !== null && SVG_FRAGMENT_TAGS.has(tag)) {\n // SVG fragment without an <svg> wrapper — wrap, parse, unwrap.\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) throw new Error(`toElement: SVG fragment produced no element\\n input: ${excerpt(html)}`);\n return first;\n }\n\n // HTML — `<template>`-based parse.\n const t = document.createElement('template');\n t.innerHTML = html;\n const child = t.content.firstElementChild;\n if (child === null) throw new Error(`toElement: produced no element\\n input: ${excerpt(html)}`);\n return child;\n}\n"]}