import { SafeHtml } from './jsx-runtime.js'; /** * `mount(rootEl, render)` — kerf's render primitive. * * Wraps `effect()` so that whenever any signal read inside `render()` * changes, we re-run `render()` and apply the minimum DOM mutations against * the live tree. Element identity (and thus focus, selection, in-flight * pointer interactions, and event listeners on preserved nodes) is preserved * wherever the keyed/positional diff matches. * * Two phases per render: * * - Static surrounds (everything outside `each()` lists): kerf's native * `morph()` reconciler walks a freshly-built template against the live * tree. Conventions: id/data-key matching, `data-morph-skip`, focus * preservation. * * - List interiors (children of every `each()` parent): native keyed * reconciler operates directly on the live parent's children. No * re-parse, no morph walk for cache-hit rows. Cost is O(changes), not * O(rows). * * Compared to a `replaceChildren(...rows.map(toElement))` rebuild pattern, * the user-visible win is that an `` the user is typing into * survives an unrelated re-render — its DOM node, focus state, and cursor * position are not destroyed and recreated on each tick. */ /** What `mount()`'s render function may return; non-SafeHtml values coerce (nullish/boolean → render nothing). */ type MountResult = SafeHtml | string | number | boolean | null | undefined; /** * Bind `render()` to the children of `rootEl`. Re-runs whenever any signal * read inside `render()` changes. Returns a disposer that tears down the * effect; call it when the host element is removed from the DOM. * * Conventions: * * - Diff keys: `id` and `data-key` are matched across the morph by key * rather than positionally, so list reorders move existing nodes instead * of churning unrelated siblings. * - `data-morph-skip`: any element with this attribute is left untouched * inside on subsequent renders. Used for library-owned subtrees (xterm- * style widgets, charts, third-party editors) where the library's own * lifecycle manages the children. * - Focused text-entry inputs (`` of typing kinds, `