/** * Carries child element state across a template re-instantiation. * * When a hot patch changes a template's text, lit-html sees a new template, * clones fresh DOM and swaps it in: every custom element inside the edited * template is re-created and starts from its defaults. For a short window * after a hot patch this module pairs each element dropped from a root with * the next freshly created element of the same tag connected in that root * (FIFO, i.e. document order), then either copies the old element's state * onto the new one (`'transfer'`) or, where the new element carries no * bindings, puts the old element back in its place (`'reuse'`). * * Dependency-free and duck-typed like `patch.ts`. The lit-html internals it * reads (`_$litPart$`, `_$committedValue`, `_$template`, `_$parts`, * `_$startNode`, `_$endNode`) are looked up by their development names first * and then by the stable minified names lit's prod build gives them * (`_$AH`, `_$AD`, `_$AV`, `_$AA`, `_$AB`). Every access is guarded; when the * part tree can't be read, transfer skips only attribute-driven keys and * reuse falls back to transfer. */ export type ChildStateMode = 'reset' | 'transfer' | 'reuse'; /** `Symbol.for` description prefix of the dev-only `#private` rewrite. */ export declare const PRIVATE_KEY_PREFIX = "@oddsquad/vite-plugin-lit#private:"; /** Duck-typed lit-html part. */ export interface PartLike { type: number; element?: unknown; name?: unknown; } /** Duck-typed element the window works with. */ export type ElementLike = HTMLElement & { renderRoot?: unknown; hasUpdated?: boolean; updateComplete?: unknown; }; /** * Every lit-html part rendered into the tree `el` lives in: the parts of each * render container (`_$litPart$`) among `el`'s ancestors up to its root. * `undefined` when `el` isn't in a tree or the walk hits a surprise. */ export declare const partsAround: (el: Node) => PartLike[] | undefined; /** * Reactive property keys the new element already got from its template: * keys whose attribute is present on it (static attributes), plus, when the * part tree could be read, keys bound by a property, boolean or attribute * part targeting it. */ export declare const templateDrivenKeys: (el: ElementLike, parts: readonly PartLike[] | undefined) => Set; /** Own symbol keys of `el` minted by the dev-only `#private` rewrite. */ export declare const privateKeys: (el: object) => symbol[]; /** `el`'s own `#private` values, to tell later which ones `el` set itself. */ export declare const privateSnapshot: (el: object) => Map; /** * Copies `from`'s state onto `to`: reactive properties not driven by `to`'s * template, and the `#private` members the dev rewrite turned into * `Symbol.for` keys. Nothing else — Lit's own bookkeeping lives in string * keys and must stay per-instance. * * A `#private` field is left alone when it holds a function (an arrow * listener closes over `from`) or when `to` changed it since `before`, a * {@link privateSnapshot} taken ahead of its `connectedCallback`: what `to` * set while connecting belongs to `to`, and `from` may have cleared it on * disconnect. */ export declare const transferState: (from: ElementLike, to: ElementLike, parts: readonly PartLike[] | undefined, before?: ReadonlyMap) => void; /** * Whether `el` (and its light DOM) carries no bindings, so another element * can take its place without lit-html noticing: no part targets it or an * element inside it, no child part's markers or parent lie inside it, and * nothing rendered into it as a container. `false` when `parts` is unknown. */ export declare const isReuseSafe: (el: ElementLike, parts: readonly PartLike[] | undefined) => boolean; export interface ChildStateOptions { /** Read at every `open()`. */ mode: () => ChildStateMode; /** Hard cap on a window's lifetime. Defaults to {@link WINDOW_CAP_MS}. */ capMs?: number; } export interface ChildState { /** * From the instrumented `connectedCallback`, before the original runs. * `fresh` is whether the element has never been connected before. */ connected(el: ElementLike, fresh: boolean): void; /** From the instrumented `disconnectedCallback`. */ disconnected(el: ElementLike): void; /** A hot patch is about to re-render instances: open (or extend) a window. */ open(): void; /** Keep the window open until these instances' updates complete. */ watch(els: Iterable): void; /** Whether a window is currently open. */ readonly active: boolean; } export declare const createChildState: (options: ChildStateOptions) => ChildState; //# sourceMappingURL=child-state.d.ts.map