/** * Main-thread snapshot runtime (#626, phase 2 of #620). * * Instantiates compiled snapshot templates (see * `@sigx/lynx-runtime-internal/snapshot` for the transform contract) on the * main thread. An instance is a cheap staged record until materialization — * `ensureElements()` runs the template's `create()` (direct element-PAPI * calls), applies `__SetCSSId`, then replays staged hole values through the * template's `update[i]` patchers. Lazy materialization is what makes a * future synchronous `componentAtIndex` free: offscreen rows stay as records. * * Integration points with the existing MT runtime: * - Instances and their slot/inner elements resolve through the SAME * `elements` map as op-built elements, so INSERT/REMOVE/SET_EVENT/ * SET_MT_REF/gesture ops work on template-built trees unchanged. * - Template-INNER elements that need events/refs get synthetic NEGATIVE ids * (BG-assigned ids are positive; the sign documents the origin) feeding * the existing `event-slots.ts` state machine — the hybrid * worklet+BG-handler slot behavior applies inside templates unchanged. * - Hole updaters are installed into the contract module via * `installSnapshotMTHooks()` (called from entry-main's bootstrap). * * The snapshot op protocol lives in ops-apply.ts (#629); BG-side emission in * lynx-runtime (#631); list templates, the synchronous `componentAtIndex` * pull path, and template-keyed recycling in list-mt.ts (#639). */ import { type SnapshotDef, type SnapshotInstanceLike } from '@sigx/lynx-runtime-internal/snapshot'; export declare class MTSnapshotInstance implements SnapshotInstanceLike { /** BG-assigned instance id (positive) — also its key in `instances`. */ readonly __id: number; readonly type: string; /** Dynamic hole values; staged until materialization, then live-patched. */ __values: unknown[]; /** Elements from `create()`, or null while staged. */ __elements: MainThreadElement[] | null; __element_root: MainThreadElement | null; readonly def: SnapshotDef; /** elementIndex → synthetic negative id (for event/ref plumbing). */ syntheticIds: Map; /** hole index → wvid currently bound through a ref hole (for teardown). */ boundWvids: Map; /** element-registry ids minted by SNAPSHOT_BIND_SLOT (for teardown). */ slotElIds: Set; constructor(id: number, type: string); /** * Materialize: build the element tree and replay staged values. Idempotent. */ ensureElements(): void; /** * Set hole `index`. Staged instances just record the value; materialized * ones patch through the template's updater with a direct-or-identical * skip (mirrors the reference `callUpdateIfNotDirectOrDeepEqual` gate — * wire values are JSON-decoded fresh objects, so `===` misses only * genuinely-equal structures, costing a redundant-but-idempotent patch). */ setValue(index: number, value: unknown): void; /** * Replace the whole values array (instantiation / reuse payload). Holes * beyond the new payload's length are cleared through their updaters * (stale values must not survive instance reuse), then the array shrinks * to match. */ setValues(values: unknown[]): void; /** * Resolve the host element for slot `slotIndex` (where child content * attaches). Materializes on demand. */ slotElement(slotIndex: number): MainThreadElement | null; } export declare function createSnapshotInstance(id: number, type: string): MTSnapshotInstance; export declare function getSnapshotInstance(id: number): MTSnapshotInstance | undefined; /** True when `id` names a live snapshot instance. */ export declare function isSnapshotInstance(id: number): boolean; /** * Drop an instance and every registry entry it minted: synthetic ids in * `elements` (which would pin the whole subtree), their event-slot state, * and any ref bindings its holes created. */ export declare function destroySnapshotInstance(id: number): void; /** * Register template-inner element `elementIndex` of `inst` under a synthetic * negative id in the shared `elements` map, so the event-slot machinery and * ref binding address it exactly like an op-built element. */ export declare function ensureSyntheticId(inst: MTSnapshotInstance, elementIndex: number): number; /** Test / hot-reload reset. */ export declare function resetSnapshotInstances(): void; /** Park a SNAPSHOT_CREATE whose template isn't registered (yet). */ export declare function parkSnapshotCreate(id: number, templateId: string): void; export declare function isParkedSnapshot(id: number): boolean; /** * Resolve an id that belongs to a parked instance's world: the instance id * itself, or a slot-el id from one of its queued BIND_SLOTs (the BG replays * slot children with parentId = slotElId — those INSERTs must queue too). */ export declare function parkedOwnerOf(id: number): number | undefined; /** Queue a raw op tuple (opcode-first) that targets a parked instance id. */ export declare function queueOpForParked(id: number, tuple: unknown[]): void; /** Drop one parked create (its subtree was removed before it could resolve). */ export declare function dropParkedSnapshot(id: number): void; /** * Called after each `sigxApplyMtHotUpdate`: creates whose templates are now * registered replay as a real op batch (SNAPSHOT_CREATE + their queued ops, * in order) through `applyBatch`; the rest age out with a loud log after * PARK_MAX_AGE cycles. */ export declare function retryParkedSnapshots(applyBatch: (ops: unknown[]) => void): void; /** * Install the MT hole updaters into the shared contract module. Called once * from entry-main's bootstrap (before any user module evaluates). Idempotent. */ export declare function installSnapshotMTHooks(): void;