@vibecook/ice 0.4.0 → 0.7.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.
Files changed (39) hide show
  1. package/README.md +4 -4
  2. package/dist/{chunk-3PHPWRB2.js → chunk-55QCOE74.js} +7 -4
  3. package/dist/chunk-55QCOE74.js.map +1 -0
  4. package/dist/{chunk-ENMRSITH.js → chunk-5OU3OWDH.js} +16 -3
  5. package/dist/chunk-5OU3OWDH.js.map +1 -0
  6. package/dist/{chunk-7LZAXQAO.js → chunk-LATXYFMO.js} +6823 -3926
  7. package/dist/chunk-LATXYFMO.js.map +1 -0
  8. package/dist/devtools.js +5 -2
  9. package/dist/devtools.js.map +1 -1
  10. package/dist/dom.js +2 -2
  11. package/dist/ground.js +1 -1
  12. package/dist/index.js +35 -1
  13. package/dist/r3f.js +3 -3
  14. package/dist/react.js +5 -3
  15. package/dist/types/packages/core/src/behavior/compile.d.ts +74 -0
  16. package/dist/types/packages/core/src/behavior/define-behavior.d.ts +56 -0
  17. package/dist/types/packages/core/src/behavior/differ.d.ts +91 -0
  18. package/dist/types/packages/core/src/behavior/harness.d.ts +65 -0
  19. package/dist/types/packages/core/src/behavior/migrate.d.ts +87 -0
  20. package/dist/types/packages/core/src/behavior/public-reads.d.ts +31 -0
  21. package/dist/types/packages/core/src/behavior/runtime.d.ts +102 -0
  22. package/dist/types/packages/core/src/behavior/types.d.ts +358 -0
  23. package/dist/types/packages/core/src/behavior/world-view.d.ts +36 -0
  24. package/dist/types/packages/core/src/engine/engine.d.ts +38 -1
  25. package/dist/types/packages/core/src/engine/guests.d.ts +199 -0
  26. package/dist/types/packages/core/src/engine/reflectors.d.ts +8 -0
  27. package/dist/types/packages/core/src/facade/create-canvas-engine.d.ts +26 -0
  28. package/dist/types/packages/core/src/guards/guarded-tx.d.ts +57 -0
  29. package/dist/types/packages/core/src/index.d.ts +11 -3
  30. package/dist/types/packages/core/src/widget/define-widget.d.ts +28 -0
  31. package/dist/types/packages/core/src/widget/props.d.ts +35 -1
  32. package/dist/types/packages/core/src/widget/spawn.d.ts +14 -0
  33. package/dist/types/packages/dom/src/loop.d.ts +9 -0
  34. package/dist/types/packages/react/src/hooks.d.ts +12 -1
  35. package/dist/types/packages/react/src/index.d.ts +1 -1
  36. package/package.json +31 -65
  37. package/dist/chunk-3PHPWRB2.js.map +0 -1
  38. package/dist/chunk-7LZAXQAO.js.map +0 -1
  39. package/dist/chunk-ENMRSITH.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../react/src/hooks.ts","../../react/src/widget-root.tsx","../../react/src/engine-context.tsx","../../react/src/use-commit.ts","../../react/src/preview-snapshots.ts","../../react/src/widget-preview.tsx","../../react/src/use-tool.ts","../../react/src/use-presence.ts","../../react/src/keymap.ts","../../react/src/infinite-canvas.tsx","../../react/src/index.ts"],"sourcesContent":["/**\n * React hooks over the engine's Tier-3 reactivity (design-005 §2 hooks;\n * design-004 §2 frozen-hidden rule).\n *\n * Implemented directly on `world.reactive.observeValue` + `useSyncExternalStore`\n * rather than strata's own react module: core is react-free by law, so\n * strata/react cannot be re-exported through it — and the adapter is ~20\n * lines. Value semantics are strata Tier-3: equality-suppressed, fired at\n * notify(), never during the tick.\n *\n * FROZEN-HIDDEN: a widget inside a hidden (culled-but-kept-mounted) host must\n * not re-render on doc edits — `useWidgetProps` reads {@link WidgetHiddenContext}\n * (provided per-portal by WidgetRoot) and suspends its subscription while\n * hidden, serving the last snapshot; on show it resubscribes and refreshes.\n */\nimport {\n Selected,\n WidgetBreakpoint,\n defineQuery,\n widgets,\n type Component,\n type Entity,\n type World,\n} from \"@ice/core\";\nimport { createContext, useCallback, useContext, useMemo, useRef, useSyncExternalStore } from \"react\";\n\n/** Per-portal hidden flag (WidgetRoot provides it; defaults to live). */\nexport const WidgetHiddenContext = createContext(false);\n\nconst selectedQ = defineQuery([Selected]);\n\n/** Shallow field equality — strata cells are flat field records. */\nfunction shallowEq(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true;\n if (typeof a !== \"object\" || typeof b !== \"object\" || a === null || b === null) return false;\n const ka = Object.keys(a);\n const kb = Object.keys(b);\n if (ka.length !== kb.length) return false;\n for (const k of ka) {\n if (!Object.is((a as Record<string, unknown>)[k], (b as Record<string, unknown>)[k])) return false;\n }\n return true;\n}\n\n/**\n * Tier-3 component value subscription (equality-suppressed). Snapshot\n * STABILITY is load-bearing: strata's `get()` materializes a fresh object per\n * read (SoA columns), and `useSyncExternalStore` treats a new reference as a\n * new snapshot — so reads go through a shallow-equality cache and only a real\n * field change yields a new reference.\n */\nexport function useWorldComponent<S>(world: World, entity: Entity, component: Component<S>): S | undefined {\n const hidden = useContext(WidgetHiddenContext);\n const last = useRef<S | undefined>(undefined);\n const subscribe = useCallback(\n (onChange: () => void) => {\n if (hidden) return () => {}; // frozen while hidden — no wakeups, no renders\n return world.reactive.observeValue(entity, component, onChange);\n },\n [world, entity, component, hidden],\n );\n const getSnapshot = useCallback(() => {\n if (hidden) return last.current; // stable snapshot while frozen\n const v = world.isAlive(entity) ? world.get(entity, component) : undefined;\n if (!shallowEq(v, last.current)) last.current = v;\n return last.current;\n }, [world, entity, component, hidden]);\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\n/**\n * Typed props for one conflict group of a widget (design-005 §2). Group\n * component values come back whole; `p.json` fields are parsed. Identity is\n * stable per underlying group value (memo on the raw reference).\n */\nexport function useWidgetProps<T extends Record<string, unknown>>(\n world: World,\n entity: Entity,\n type: string,\n group = \"props\",\n): T | undefined {\n const widget = widgets.get(type);\n const g = widget?.groups.find((x) => x.name === group);\n if (widget === undefined || g === undefined) {\n throw new Error(`ice: useWidgetProps — unknown widget type/group \"${type}\"/\"${group}\".`);\n }\n const raw = useWorldComponent(world, entity, g.component) as Record<string, unknown> | undefined;\n return useMemo(() => {\n if (raw === undefined) return undefined;\n const out: Record<string, unknown> = {};\n for (const [name, spec] of Object.entries(g.fields)) {\n const v = raw[name];\n out[name] = spec.kind === \"json\" && typeof v === \"string\" ? parseJsonCell(v, spec.default) : v;\n }\n return out as T;\n }, [raw, g]);\n}\n\n/**\n * A json cell is one CRDT string a remote peer may have written malformed —\n * decoding must never throw mid-render (2026-07-13 review). Fall back to the\n * spec's serialized default (engine-derived, always valid JSON), then null.\n */\nfunction parseJsonCell(cell: string, serializedDefault: string | undefined): unknown {\n try {\n return JSON.parse(cell);\n } catch {\n try {\n return JSON.parse(serializedDefault ?? \"null\");\n } catch {\n return null;\n }\n }\n}\n\n/**\n * Selection membership (Tier-1 wake on Selected churn; O(1) snapshot).\n * Frozen-hidden like every widget hook: a selection change must not re-render\n * 256 hidden trees (review finding — design-004 §2 applies to ALL hooks).\n */\nexport function useSelected(world: World, entity: Entity): boolean {\n const hidden = useContext(WidgetHiddenContext);\n const last = useRef(false);\n const subscribe = useCallback(\n (onChange: () => void) => {\n if (hidden) return () => {};\n return world.reactive.observeQuery(selectedQ, onChange);\n },\n [world, hidden],\n );\n const getSnapshot = useCallback(() => {\n if (hidden) return last.current;\n last.current = world.isAlive(entity) && world.hasTag(entity, Selected);\n return last.current;\n }, [world, entity, hidden]);\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\n/** LOD tier (design-004 §8); \"normal\" until the breakpoint system stamps one. */\nexport function useBreakpoint(world: World, entity: Entity): string {\n const bp = useWorldComponent(world, entity, WidgetBreakpoint);\n return (bp as { tier?: string } | undefined)?.tier ?? \"normal\";\n}\n","/**\n * WidgetRoot — portals from ONE app root (design-004 §2).\n *\n * Portal-list membership (mount/unmount/evict) is owned HERE, by React,\n * subscribed to the engine's mount store via `useSyncExternalStore`; the\n * imperative dom-widgets reflector owns only the host DIVs. Eviction is\n * decided engine-side (LRU derive) and merely consumed. Each mounted entry\n * portals its widget type's component (from the defineWidget registry) into\n * the host's content element; hidden entries stay mounted (React state\n * preserved — cull ≠ unmount) inside a `WidgetHiddenContext` so their prop\n * subscriptions freeze (design-004 §2).\n *\n * A host div may not exist yet on the very first snapshot after mount (the\n * host reflector runs in the same post-notify pass, ordered by reflector\n * registration) — entries without a host render nothing this pass and pick\n * up on the next notification.\n */\nimport { PrefabId, widgets, type Entity, type World, type WidgetMountStore } from \"@ice/core\";\nimport { createElement, type ComponentType, type ReactElement } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { useSyncExternalStore } from \"react\";\nimport { WidgetHiddenContext } from \"./hooks\";\n\nexport interface WidgetHosts {\n /** The dom-widgets reflector's lookup (content element per entity). */\n hostFor(entity: Entity): HTMLElement | undefined;\n}\n\nexport interface WidgetRootProps {\n readonly world: World;\n readonly store: WidgetMountStore;\n readonly hosts: WidgetHosts;\n}\n\nexport interface WidgetComponentProps {\n readonly entity: Entity;\n readonly world: World;\n}\n\nexport function WidgetRoot({ world, store, hosts }: WidgetRootProps): ReactElement {\n const entries = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\n const portals: ReactElement[] = [];\n for (const entry of entries) {\n if (!world.isAlive(entry.entity)) continue;\n const type = world.get(entry.entity, PrefabId)?.id;\n const widget = typeof type === \"string\" ? widgets.get(type) : undefined;\n if (widget === undefined) continue;\n // dom widgets portal their component; gl widgets portal their optional\n // DOM CHROME — the host div lives in the content plane (P1), which stacks\n // UNDER the GL canvas (P2), so the card body renders beneath the island's\n // 3D content (v1's CardChrome sandwich — shared CSS with DOM cards).\n const view = widget.surface === \"dom\" ? widget.component : widget.chrome;\n if (view == null) continue;\n const target = hosts.hostFor(entry.entity);\n if (target === undefined) continue; // host lands next pass\n const View = view as ComponentType<WidgetComponentProps>;\n portals.push(\n createPortal(\n createElement(\n WidgetHiddenContext.Provider,\n { value: entry.hidden },\n createElement(View, { entity: entry.entity, world }),\n ),\n target,\n String(entry.entity),\n ),\n );\n }\n return createElement(\"div\", { \"data-ice-widget-root\": \"\" }, portals);\n}\n","/**\n * `<EngineProvider>` + engine access hooks (design-005 §5; the M6 field\n * amendment 2026-07-10 gap — grep \"useCommit\" in design-005).\n *\n * The whole React surface reaches the running canvas through ONE context\n * carrying the {@link CanvasEngine} facade (world + engine + stack + runtime +\n * ops + docs). Widgets never hand-roll store plumbing again: {@link useOps}\n * gives the engine-owned write paths, {@link useCommit} (its own module) the\n * sanctioned durable commit seam, and {@link useWorld} the read/observe escape\n * hatch. `<InfiniteCanvas>` provides this automatically; apps that mount\n * WidgetRoot themselves wrap it in `<EngineProvider>`.\n */\nimport { devGuardsEnabled, type CanvasEngine, type CanvasOps, type World } from \"@ice/core\";\nimport { createContext, useContext, useEffect, type ReactElement, type ReactNode } from \"react\";\n\nconst EngineContext = createContext<CanvasEngine | null>(null);\n\nexport interface EngineProviderProps {\n readonly engine: CanvasEngine;\n readonly children?: ReactNode;\n}\n\n/** Publish the canvas engine to the React subtree (WidgetRoot + userland hooks). */\nexport function EngineProvider({ engine, children }: EngineProviderProps): ReactElement {\n return <EngineContext.Provider value={engine}>{children}</EngineContext.Provider>;\n}\n\n/** The canvas engine for this subtree; throws with guidance outside a provider. */\nexport function useCanvasEngine(): CanvasEngine {\n const engine = useContext(EngineContext);\n if (engine === null) {\n throw new Error(\n \"ice: useCanvasEngine — no <EngineProvider>. Render widgets inside <InfiniteCanvas> (which provides it) or wrap your tree in <EngineProvider engine={...}>.\",\n );\n }\n return engine;\n}\n\n/** The engine-owned write paths (design-005 §4): setTool, deleteSelection, etc. */\nexport function useOps(): CanvasOps {\n return useCanvasEngine().ops;\n}\n\n/**\n * Take a stage background hold while `active` (ce.stage, 2026-07-19): the\n * overlay-lifecycle sugar — the disposer releases on deactivate AND unmount,\n * so a crashed/unmounted overlay can never wedge the canvas backgrounded.\n * `engine` is an explicit param (not context): overlays typically render as\n * SIBLINGS of <InfiniteCanvas>, outside the provider.\n */\nexport function useStageHold(engine: CanvasEngine, active: boolean, name: string): void {\n useEffect(() => {\n if (!active) return undefined;\n return engine.stage.background(name);\n }, [engine, active, name]);\n}\n\n/**\n * Freeze the engine while `active` (ce.frame, 2026-08-04) — {@link useStageHold}'s\n * stricter sibling, same lifecycle sugar: the effect cleanup IS the thaw, so an\n * overlay that unmounts (or crashes) can never wedge the engine parked.\n *\n * WHICH ONE. A stage hold quiets discretionary rendering over a world that\n * keeps stepping — right for chrome that RECEDES the canvas, where undo,\n * collab and tweens must still land visibly behind a partial overlay. A freeze\n * stops the loop outright — right for chrome that COVERS the canvas, where\n * every frame behind it is work nobody can see. Reaching for a freeze under a\n * partial overlay will look broken: the canvas is a photograph until thaw.\n */\nexport function useFrameFreeze(engine: CanvasEngine, active: boolean, name: string): void {\n useEffect(() => {\n if (!active) return undefined;\n return engine.frame.freeze(name);\n }, [engine, active, name]);\n}\n\nlet warnedUseWorld = false;\n\n/**\n * Escape hatch — the raw {@link World} for READS and Tier-3 OBSERVATION only.\n * Mutation goes through {@link useOps}/{@link useCommit} (a gesture-claimed,\n * one-tx-per-gesture durable write; direct world writes bypass sovereignty and\n * the guards). DEV-warns once on first use.\n */\nexport function useWorld(): World {\n const engine = useCanvasEngine();\n if (devGuardsEnabled() && !warnedUseWorld) {\n warnedUseWorld = true;\n console.warn(\n \"ice: useWorld() is a READ/OBSERVE escape hatch — never write to the world directly. Use useOps()/useCommit() for mutation (design-005 §5).\",\n );\n }\n return engine.world;\n}\n","/**\n * `useCommit` + `useUndoStatus` — the sanctioned widget durable-write path and\n * the undo/redo status subscription (design-005 §2 M6 field amendment,\n * 2026-07-10: \"widgets also need a SANCTIONED commit path\").\n *\n * A widget commits a prop edit through {@link useCommit}: it resolves the\n * CURRENT doc session (`engine.docs.current()`) and runs a\n * {@link guardedTransaction} against that session's store — one transaction per\n * call, eligibility-guarded, absolute writes only. The session is resolved at\n * CALL time (not hook time) so a widget rendered doc-less that gains a doc later\n * commits correctly without re-mounting.\n */\nimport { DurableUndoStatus, guardedTransaction, type GuardedTx, type GuardedTxOpts } from \"@ice/core\";\nimport { useCallback, useRef, useSyncExternalStore } from \"react\";\nimport { useCanvasEngine } from \"./engine-context\";\n\n/** A durable commit: run `fn` against the current doc session's store, one tx. */\nexport type Commit = (fn: (tx: GuardedTx) => void, opts?: GuardedTxOpts) => void;\n\n/**\n * The widget commit seam. The returned function throws with guidance when no\n * document is attached (commits need a durable store — call\n * `engine.docs.create()/open()/join()` first).\n */\nexport function useCommit(): Commit {\n const engine = useCanvasEngine();\n return useCallback(\n (fn, opts) => {\n const session = engine.docs.current();\n if (session === undefined) {\n throw new Error(\n \"ice: useCommit — no active document. Attach one with engine.docs.create()/open()/join() before committing widget edits.\",\n );\n }\n if (session.readOnly) {\n // The version gate said read-only: a raw store write here would edit —\n // and broadcast — a document the gate refused (2026-07-13 review).\n throw new Error(\"ice: useCommit — the document is read-only (version gate); widget edits are disabled.\");\n }\n guardedTransaction(session.store, engine.world, fn, opts);\n },\n [engine],\n );\n}\n\nexport interface UndoStatus {\n readonly canUndo: boolean;\n readonly canRedo: boolean;\n}\n\nconst NO_UNDO: UndoStatus = { canUndo: false, canRedo: false };\n\n/**\n * Undo/redo availability for the current document (drives toolbar\n * disablement) — the design-005 §5 path: the `DurableUndoStatus` RESOURCE\n * (strata plan-undo U2, re-exported through @ice/core) via\n * `observeResource`. A resource subscription is WORLD-level, so it survives\n * document swaps — no remount needed, the earlier onHistoryChange-per-store\n * caveat is gone. Fires at notify(), equality-suppressed; snapshot identity\n * is stable while the flags are unchanged.\n */\nexport function useUndoStatus(): UndoStatus {\n const engine = useCanvasEngine();\n const last = useRef<UndoStatus>(NO_UNDO);\n const subscribe = useCallback(\n (onChange: () => void) => engine.world.reactive.observeResource(DurableUndoStatus, onChange),\n [engine],\n );\n const getSnapshot = useCallback(() => {\n const status = engine.world.getResource(DurableUndoStatus);\n const canUndo = status?.canUndo ?? false;\n const canRedo = status?.canRedo ?? false;\n if (last.current.canUndo !== canUndo || last.current.canRedo !== canRedo) {\n last.current = { canUndo, canRedo };\n }\n return last.current;\n }, [engine]);\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n","/**\n * The GL preview snapshot store (design-005 §2 preview contract, P2 —\n * 2026-07-19). react stays three-free by LAW, so the capture pipeline lives\n * in @ice/r3f and meets `<WidgetPreview>` HERE, at a dumb data seam: a\n * module-level map of widget type → captured image, with subscription so an\n * open palette re-renders the moment a capture lands.\n *\n * `PreviewImage` accepts a canvas alongside ImageBitmap so tests (and any\n * app-side prebuilt-cache policy — the P3 seam) can inject without a GPU.\n */\nexport type PreviewImage = ImageBitmap | HTMLCanvasElement;\n\nconst images = new Map<string, PreviewImage>();\nconst listeners = new Set<() => void>();\n\nexport function setPreviewSnapshot(type: string, image: PreviewImage): void {\n images.set(type, image);\n for (const l of listeners) l();\n}\n\nexport function getPreviewSnapshot(type: string): PreviewImage | undefined {\n return images.get(type);\n}\n\nexport function hasPreviewSnapshot(type: string): boolean {\n return images.has(type);\n}\n\nexport function subscribePreviewSnapshots(listener: () => void): () => void {\n listeners.add(listener);\n return () => listeners.delete(listener);\n}\n\n/** TEST-ONLY wipe (not on the barrel). */\nexport function __resetPreviewSnapshotsForTests(): void {\n images.clear();\n}\n","/**\n * `<WidgetPreview>` — the framework answer to \"give me the preview for type\n * X\" (design-005 §2 amendment, 2026-07-19). Palettes/trays stay app chrome\n * (design-004); THIS is the seam they consume, owning the whole fallback\n * chain so every app and every `defineWidget` author gets the same behavior:\n *\n * 1. the def's DECLARED preview (engine-free by contract — no world, no\n * entity, no ops; authored at `defaultSize`, scaled here);\n * 2. dom surfaces with no declaration: the REAL component with default (or\n * `preview.props`-curated) props, mounted against the framework's\n * internal preview sandbox — truthful by construction;\n * 3. the `fallback` prop (the app's silhouette), else a neutral placeholder.\n *\n * Every branch renders INERT (`inert` + pointer-events none) inside an error\n * boundary — a broken preview degrades to the fallback, it never kills the\n * palette. GL surfaces without a declared preview go straight to fallback in\n * P1 (the r3f snapshot pipeline is P2; a DOM mockup declaration is the\n * sanctioned escape hatch meanwhile).\n *\n * The sandbox: one lazy module-level engine (own in-memory doc, no adapters,\n * never stepped past two settle ticks) spawning ONE entity per previewed\n * type ON DEMAND. Preview entities never receive Selected/Grab/overlap tags,\n * so chrome renders permanently at rest — \"static\" is a property of the\n * sandbox, not a discipline widget authors must follow.\n */\nimport {\n createCanvasEngine,\n widgets,\n type CanvasEngine,\n type Entity,\n type WidgetType,\n type World,\n} from \"@ice/core\";\nimport {\n Component,\n useEffect,\n useRef,\n useSyncExternalStore,\n type ComponentType,\n type CSSProperties,\n type ReactElement,\n type ReactNode,\n} from \"react\";\nimport { EngineProvider } from \"./engine-context\";\nimport { getPreviewSnapshot, subscribePreviewSnapshots, type PreviewImage } from \"./preview-snapshots\";\n\n// --- the preview sandbox -----------------------------------------------------\n\ninterface PreviewSandbox {\n readonly ce: CanvasEngine;\n readonly entities: Map<string, Entity>;\n}\n\nlet sandbox: PreviewSandbox | null = null;\n\nfunction ensurePreviewEntity(def: WidgetType): Entity | undefined {\n if (sandbox === null) {\n const ce = createCanvasEngine();\n ce.docs.create();\n ce.world.sync();\n ce.step(16);\n sandbox = { ce, entities: new Map() };\n }\n const existing = sandbox.entities.get(def.type);\n if (existing !== undefined) return existing;\n try {\n const e = sandbox.ce.ops.spawnWidget(def.type, {\n x: 0,\n y: 0,\n undoable: false,\n ...(def.previewProps !== undefined ? { props: def.previewProps } : {}),\n });\n sandbox.ce.world.sync();\n sandbox.ce.step(32); // settle tick: equip stamps land before first render\n sandbox.entities.set(def.type, e);\n return e;\n } catch (err) {\n console.warn(`ice: WidgetPreview(\"${def.type}\") sandbox spawn failed — falling back.`, err);\n return undefined;\n }\n}\n\n/** TEST-ONLY sandbox wipe (mirrors __resetWidgetsForTests; not on the barrel). */\nexport function __resetPreviewSandboxForTests(): void {\n sandbox?.ce.dispose();\n sandbox = null;\n}\n\n// --- error containment ---------------------------------------------------------\n\nclass PreviewBoundary extends Component<{ fallback: ReactNode; children: ReactNode }, { failed: boolean }> {\n override state = { failed: false };\n static getDerivedStateFromError(): { failed: boolean } {\n return { failed: true };\n }\n override componentDidCatch(error: unknown): void {\n console.warn(\"ice: a widget preview threw while rendering — showing the fallback.\", error);\n }\n override render(): ReactNode {\n return this.state.failed ? this.props.fallback : this.props.children;\n }\n}\n\n// --- the host ------------------------------------------------------------------\n\nexport interface WidgetPreviewProps {\n readonly type: string;\n /** The available box; the preview renders aspect-FITTED inside it. */\n readonly width: number;\n readonly height: number;\n /** App silhouette shown when no preview path applies (or one throws). */\n readonly fallback?: ReactNode;\n readonly className?: string;\n readonly style?: CSSProperties;\n}\n\n/** Draws a captured snapshot (P2 pipeline / injected cache) at natural size. */\nfunction SnapshotLayer({ image }: { image: PreviewImage }): ReactElement {\n const ref = useRef<HTMLCanvasElement>(null);\n useEffect(() => {\n const canvas = ref.current;\n if (canvas === null) return;\n canvas.width = image.width;\n canvas.height = image.height;\n try {\n canvas.getContext(\"2d\")?.drawImage(image, 0, 0);\n } catch {\n // a torn-down ImageBitmap or a contextless test DOM — the layer stays blank\n }\n }, [image]);\n return (\n <canvas\n ref={ref}\n data-preview-snapshot=\"\"\n style={{ position: \"absolute\", inset: 0, width: \"100%\", height: \"100%\" }}\n />\n );\n}\n\nfunction defaultPlaceholder(label: string): ReactElement {\n return (\n <div\n style={{\n width: \"100%\",\n height: \"100%\",\n borderRadius: 12,\n background: \"rgba(127, 127, 127, 0.12)\",\n boxShadow: \"inset 0 0 0 1px rgba(127, 127, 127, 0.25)\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n fontSize: 11,\n color: \"rgba(127, 127, 127, 0.8)\",\n overflow: \"hidden\",\n }}\n >\n {label}\n </div>\n );\n}\n\nexport function WidgetPreview({ type, width, height, fallback, className, style }: WidgetPreviewProps): ReactElement {\n // Subscribed BEFORE any early return (hook order): an open palette\n // re-renders the moment the P2 capture pipeline lands this type's snapshot.\n const snapshot = useSyncExternalStore(subscribePreviewSnapshots, () => getPreviewSnapshot(type));\n const def = widgets.get(type);\n const safeFallback = fallback ?? defaultPlaceholder(type);\n if (def === undefined || def.defaultSize.w <= 0 || def.defaultSize.h <= 0) {\n return (\n <div className={className} style={{ width, height, ...style }}>\n {safeFallback}\n </div>\n );\n }\n\n const s = Math.min(width / def.defaultSize.w, height / def.defaultSize.h);\n const fitW = def.defaultSize.w * s;\n const fitH = def.defaultSize.h * s;\n\n // The inert, natural-size stage every preview branch renders on: authors\n // (and the real component) write at defaultSize; the host scales.\n const stage = (content: ReactNode): ReactElement => (\n <div className={className} style={{ width: fitW, height: fitH, overflow: \"hidden\", ...style }}>\n <div\n inert\n style={{\n width: def.defaultSize.w,\n height: def.defaultSize.h,\n transform: `scale(${s})`,\n transformOrigin: \"0 0\",\n pointerEvents: \"none\",\n userSelect: \"none\",\n }}\n >\n <PreviewBoundary fallback={safeFallback}>{content}</PreviewBoundary>\n </div>\n </div>\n );\n\n // 1. Author-declared preview: engine-free by contract — rendered bare.\n if (def.previewComponent !== null && def.previewComponent !== undefined) {\n const Declared = def.previewComponent as ComponentType;\n return stage(<Declared />);\n }\n\n // 2. gl surface with a captured snapshot (the P2 pipeline / an injected\n // cache): the widget's DOM chrome (if any) renders UNDERNEATH via the\n // sandbox — the live card's chrome-beneath-canvas sandwich, reproduced —\n // and the transparent 3D capture layers on top. ONE capture serves both\n // themes: the 3D content is theme-independent; theme lives in the chrome's\n // CSS.\n if (def.surface === \"gl\" && snapshot !== undefined) {\n let chromeLayer: ReactNode = null;\n if (def.chrome !== null && def.chrome !== undefined) {\n const entity = ensurePreviewEntity(def);\n if (entity !== undefined && sandbox !== null) {\n const Chrome = def.chrome as ComponentType<{ entity: Entity; world: World }>;\n chromeLayer = (\n <EngineProvider engine={sandbox.ce}>\n <div style={{ position: \"absolute\", inset: 0 }}>\n <Chrome entity={entity} world={sandbox.ce.world} />\n </div>\n </EngineProvider>\n );\n }\n }\n return stage(\n <div style={{ position: \"relative\", width: \"100%\", height: \"100%\" }}>\n {chromeLayer}\n <SnapshotLayer image={snapshot} />\n </div>,\n );\n }\n\n // 3. dom surface: the real component + default/curated props in the sandbox.\n if (def.surface === \"dom\" && def.component !== null && def.component !== undefined) {\n const entity = ensurePreviewEntity(def);\n if (entity !== undefined && sandbox !== null) {\n const View = def.component as ComponentType<{ entity: Entity; world: World }>;\n return stage(\n <EngineProvider engine={sandbox.ce}>\n <View entity={entity} world={sandbox.ce.world} />\n </EngineProvider>,\n );\n }\n }\n\n // 4. No path (gl before its capture lands, broken spawn): the fallback.\n return (\n <div className={className} style={{ width: fitW, height: fitH, ...style }}>\n {safeFallback}\n </div>\n );\n}\n","/**\n * `useTool` + `useToolState` — the active-tool subscription (design-005 §5).\n *\n * The active tool is the `ActiveTool` runtime resource (design-005 §4). Reads go\n * through strata's Tier-3 `observeResource` (fires only when the id actually\n * changes, at notify()); the setter is `ops.setTool`, which cancels active\n * gestures before the switch (the strata-example lesson, design-003 §8) — never\n * a raw resource write. The snapshot is a primitive string, so identity is\n * inherently stable.\n */\nimport { ActiveTool } from \"@ice/core\";\nimport { useCallback, useSyncExternalStore } from \"react\";\nimport { useCanvasEngine } from \"./engine-context\";\n\n/** `[activeToolId, setTool]`. `setTool` routes through `ops.setTool`. */\nexport function useTool(): [string, (id: string) => void] {\n const engine = useCanvasEngine();\n const subscribe = useCallback(\n (onChange: () => void) => engine.world.reactive.observeResource(ActiveTool, onChange),\n [engine],\n );\n const getSnapshot = useCallback(() => engine.world.getResource(ActiveTool)?.id ?? \"select\", [engine]);\n const active = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n const setTool = useCallback((id: string) => engine.ops.setTool(id), [engine]);\n return [active, setTool];\n}\n\n/** Sugar: is tool `id` the active one? (toolbar button pressed-state). */\nexport function useToolState(id: string): boolean {\n const [active] = useTool();\n return active === id;\n}\n","/**\n * `usePresencePeers` — the remote-collaborator roster (design-005 §5:\n * \"Not(Local) presence query\").\n *\n * Queries `PresencePeer` entities that are NOT `Local` (the local peer carries\n * `Local`, auto-applied by the ephemeral store and never transmitted) and pairs\n * each with its `PresenceInfo` (name/color). Wakes on Tier-1 query membership\n * churn (`observeQuery`) — peers joining/leaving. The snapshot is\n * MEMBERSHIP-KEYED: identity stays stable across unrelated re-renders, and info\n * is sampled when membership changes (steady-state presence info is set once at\n * join; a mid-session rename reflects on the next membership change).\n */\nimport { Local, Not, PresenceInfo, PresencePeer, defineQuery, type Entity } from \"@ice/core\";\nimport { useCallback, useRef, useSyncExternalStore } from \"react\";\nimport { useCanvasEngine } from \"./engine-context\";\n\nconst remotePeersQ = defineQuery([PresencePeer, Not(Local)]);\n\nexport interface PresencePeerView {\n readonly entity: Entity;\n /** The peer's `PresenceInfo` (strata \"string\" fields are nullable until set). */\n readonly info: { readonly name: string | null; readonly color: string | null } | undefined;\n}\n\n/** Remote presence peers (excludes the local peer); stable identity by membership. */\nexport function usePresencePeers(): readonly PresencePeerView[] {\n const engine = useCanvasEngine();\n const cache = useRef<{ key: string; value: readonly PresencePeerView[] }>({ key: \"\u0000\", value: [] });\n const subscribe = useCallback(\n (onChange: () => void) => engine.world.reactive.observeQuery(remotePeersQ, onChange),\n [engine],\n );\n const getSnapshot = useCallback(() => {\n const world = engine.world;\n const ids: Entity[] = [];\n world.query(remotePeersQ).each((b) => {\n for (const r of b) ids.push(b.entity(r));\n });\n const key = ids.join(\",\");\n if (key !== cache.current.key) {\n cache.current = {\n key,\n value: ids.map((entity) => ({ entity, info: world.get(entity, PresenceInfo) })),\n };\n }\n return cache.current.value;\n }, [engine]);\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n","/**\n * The default keymap (design-005 §4 \"Keymap\"; design-003 §2 — NO system-side\n * keyboard logic, every entry resolves to an `ops.*`/`docs.*` call).\n *\n * Locked defaults:\n * ⌫/Delete → ops.deleteSelection\n * ⌘Z / Ctrl-Z → docs.undo\n * ⇧⌘Z / ⇧Ctrl-Z → docs.redo\n * ⌘D → ops.duplicateSelection\n * ⌘A → ops.selectAll\n * Esc → ops.cancelActiveGestures\n * Arrows → nudge the selection ±1px (⇧ = ±10px) — ONE tx per press\n * tool shortcuts → ops.setTool (v/h/c + any registered tool's shortcut)\n *\n * Space-hold pan is ALREADY owned by the pointer adapter (design-003 §2) — it is\n * NOT rebound here. `mod` = ⌘ on macOS, Ctrl elsewhere (metaKey || ctrlKey).\n *\n * The widget input contract (design-007, petition I1) — three gates, in order:\n * 1. `event.defaultPrevented` → the widget's own handler consumed the key\n * (\"preventDefault = handled by content\"); the engine never competes.\n * 2. The `data-canvas-keyboard` claim marker on the event-target chain (the\n * keydown target IS `document.activeElement` — browser focus is the one\n * page-global truth, so two engines on one page stand down together) →\n * EVERY entry cedes except Escape, the engine-reserved release gesture:\n * Escape blurs the claim (the NEXT press, with focus gone, falls through\n * to cancelActiveGestures). A widget that declared `keyboardEscape:\n * \"widget\"` receives even Escape — release is click-away or blurFocus().\n * This gate runs BEFORE the editable gate on purpose (2026-08-09 review):\n * a claim whose focus node is an editable proxy (the Ghosttea-style\n * hidden textarea, design-007 §6) must still get the Escape release —\n * editable-first would shadow it and silently turn every such widget\n * into `keyboardEscape: \"widget\"`.\n * 3. Editable target (input/textarea/select/contentEditable — the shared\n * 4-class predicate from @ice/dom) → ignored, so typing never triggers a\n * shortcut. Kept narrow so UNDECLARED widgets behave exactly as before.\n *\n * Overrides replace a default by its key-signature `key|mod|shift`; a signature\n * with no default is added. A matched entry `preventDefault()`s (the target was\n * already filtered to non-editable, so no typing is swallowed). An override on\n * Space warns at attach: the pointer adapter owns Space (the pan modifier,\n * design-003 §4.4) and preventDefaults it before gate 1 can let it through.\n */\nimport { Position, guardedTransaction, selectedEntities, tools, type CanvasEngine } from \"@ice/core\";\nimport { isEditableTarget, keyboardClaimOf } from \"@ice/dom\";\n\nexport interface KeymapEntry {\n /** `event.key` to match (case-insensitive; e.g. \"z\", \"Backspace\", \"ArrowUp\"). */\n readonly key: string;\n /** Require ⌘/Ctrl (default false → must NOT be held). */\n readonly mod?: boolean;\n /** Require ⇧ (default false → must NOT be held). */\n readonly shift?: boolean;\n /** Resolve to an engine write path — no keyboard logic beyond dispatch. */\n run(engine: CanvasEngine): void;\n}\n\ntype KeyTarget = Pick<Window, \"addEventListener\" | \"removeEventListener\">;\n\nconst signature = (key: string, mod?: boolean, shift?: boolean): string =>\n `${key.toLowerCase()}|${mod ? 1 : 0}|${shift ? 1 : 0}`;\n\n/** One nudge = one gesture-equivalent transaction (absolute Position writes). */\nfunction nudgeSelection(engine: CanvasEngine, dx: number, dy: number): void {\n const session = engine.docs.current();\n if (session === undefined) return;\n const selection = selectedEntities(engine.world).filter((e) => session.store.keyOf(e) !== undefined);\n if (selection.length === 0) return;\n guardedTransaction(session.store, engine.world, (tx) => {\n for (const e of selection) {\n const p = engine.world.get(e, Position);\n if (p === undefined) continue;\n tx.edit(e).set(Position, { x: p.x + dx, y: p.y + dy });\n }\n });\n}\n\nconst ARROWS: readonly [key: string, dx: number, dy: number][] = [\n [\"ArrowLeft\", -1, 0],\n [\"ArrowRight\", 1, 0],\n [\"ArrowUp\", 0, -1],\n [\"ArrowDown\", 0, 1],\n];\n\n/** The locked defaults + tool shortcuts (read from the registry at attach time). */\nfunction defaultEntries(): KeymapEntry[] {\n const entries: KeymapEntry[] = [\n { key: \"Backspace\", run: (e) => e.ops.deleteSelection() },\n { key: \"Delete\", run: (e) => e.ops.deleteSelection() },\n { key: \"z\", mod: true, run: (e) => e.docs.undo() },\n { key: \"z\", mod: true, shift: true, run: (e) => e.docs.redo() },\n { key: \"d\", mod: true, run: (e) => e.ops.duplicateSelection() },\n { key: \"a\", mod: true, run: (e) => e.ops.selectAll() },\n { key: \"Escape\", run: (e) => e.ops.cancelActiveGestures() },\n ];\n for (const [key, dx, dy] of ARROWS) {\n entries.push({ key, run: (e) => nudgeSelection(e, dx, dy) });\n entries.push({ key, shift: true, run: (e) => nudgeSelection(e, dx * 10, dy * 10) });\n }\n for (const tool of tools.all()) {\n if (tool.shortcut !== undefined) {\n const id = tool.id;\n entries.push({ key: tool.shortcut, run: (e) => e.ops.setTool(id) });\n }\n }\n return entries;\n}\n\nfunction resolveTarget(target?: KeyTarget): KeyTarget | undefined {\n if (target !== undefined) return target;\n return typeof window !== \"undefined\" ? window : undefined;\n}\n\n/**\n * Attach the default keymap (plus `overrides`) to `target` (default: `window`).\n * Returns a detach function. No-op (returns a no-op detach) when there is no\n * target — e.g. a headless environment with no `window`.\n */\nexport function attachKeymap(\n engine: CanvasEngine,\n target?: KeyTarget,\n overrides: readonly KeymapEntry[] = [],\n): () => void {\n const el = resolveTarget(target);\n if (el === undefined) return () => {};\n\n const map = new Map<string, KeymapEntry>();\n for (const entry of defaultEntries()) map.set(signature(entry.key, entry.mod, entry.shift), entry);\n for (const entry of overrides) {\n if (entry.key === \" \") {\n // Fail loud at attach, not silently at runtime: the adapter's window\n // listener registers first and preventDefaults Space (pan modifier),\n // so gate 1 makes this entry unreachable by construction.\n console.warn(\n \"ice: attachKeymap — an override on Space can never fire: the pointer adapter owns Space as the pan modifier (design-003 §4.4) and preventDefaults it before the keymap's handled-by-content gate.\",\n );\n }\n map.set(signature(entry.key, entry.mod, entry.shift), entry);\n }\n\n const onKeyDown = (event: KeyboardEvent): void => {\n if (event.defaultPrevented) return; // gate 1 — handled by content\n const claim = keyboardClaimOf(event.target);\n if (claim.claimed) {\n // Gate 2 — exclusive standdown (BEFORE the editable gate, so editable\n // focus proxies keep the release gesture — header note). Escape stays\n // engine-reserved (blur, no gesture-cancel THIS press) unless the\n // widget owns it. Everything else flows to the widget,\n // un-preventDefaulted.\n if (event.key === \"Escape\" && !claim.ownsEscape) {\n event.preventDefault();\n // SVG nodes are focusable too (tabindex) and are not HTMLElement —\n // the release must never eat Escape without actually blurring.\n const t = event.target;\n if (t instanceof HTMLElement || t instanceof SVGElement) t.blur();\n }\n return;\n }\n if (isEditableTarget(event.target)) return; // gate 3 — typing\n const mod = event.metaKey || event.ctrlKey;\n const entry = map.get(signature(event.key, mod, event.shiftKey));\n if (entry === undefined) return;\n event.preventDefault();\n entry.run(engine);\n };\n\n el.addEventListener(\"keydown\", onKeyDown as EventListener);\n return () => el.removeEventListener(\"keydown\", onKeyDown as EventListener);\n}\n","/**\n * `<InfiniteCanvas>` — the one-line canvas mount (design-005 §5): planes +\n * adapters + reflectors + portal root, wired in node-board's PROVEN boot order\n * (apps/nodeboard/src/app.tsx). The app supplies a constructed {@link\n * CanvasEngine} (via `createCanvasEngine`); this component owns only the DOM\n * host, the reflector registrations, the pointer/keymap adapters, the rAF loop,\n * and the viewport sync — everything that must live next to a real container.\n *\n * Boot order (registration order = reflector flush order, mirrored exactly):\n * host → planes → reflectors[ planeTransform · ground(P0, app-injected) ·\n * domWidgets(P1/P3) · chrome(P4) · cursor · remoteCursors(P5) ] →\n * pointer adapter → measurement (optional) → keymap → rAF loop → viewport RO.\n *\n * The dom-widgets reflector is BOTH a reflector and the host lookup WidgetRoot\n * portals into; it is created before mount and stored in state so WidgetRoot\n * renders once the hosts exist.\n *\n * Lifecycle: this component does NOT own the engine — it never calls\n * `engine.dispose()` (the engine outlives the mount; the app owns it). Unmount\n * detaches every adapter, unregisters every reflector, stops the loop, and\n * disposes the host.\n *\n * Not handled here (by design):\n * - GL / R3F: the `@ice/r3f` wall forbids `@ice/react` importing three, so a\n * GL layer (GLViews) mounts APP-SIDE. Use {@link onReady} to receive the host\n * + planes and mount it yourself (like apps/glboard).\n * - The GROUND layer (P0: dot grid, wires, snap guides — @ice/ground, three's\n * WebGPURenderer) rides the same wall: pass its factory through the OPAQUE\n * {@link InfiniteCanvasProps.ground} prop (`ground={ground({...})}`); this\n * component types it structurally and never imports the package. No factory\n * ⇒ no ground layer (headless/test boots).\n * - Devtools: the import wall forbids `@ice/react` importing `@ice/devtools`.\n * Wire the panel app-side against `engine.engine` (also via {@link onReady}).\n * - Measurement: auto-sized widgets need a `MeasureQueue` passed to BOTH\n * `createCanvasEngine({ measureQueue })` (ingest side) and this component's\n * `measureQueue` prop (ResizeObserver side). Absent ⇒ measurement is skipped.\n */\nimport {\n Viewport,\n writeRuntimeResource,\n type CanvasEngine,\n type GridConfig,\n type MeasureQueue,\n type ReflectorDef,\n type WirePreviewBuffer,\n type World,\n} from \"@ice/core\";\nimport {\n attachPointerAdapter,\n attachWidgetFocus,\n createCanvasHost,\n createChromeReflector,\n createCursorReflector,\n createDomWidgetsReflector,\n createPlaneTransformReflector,\n createPlanes,\n createRemoteCursorsReflector,\n startRafLoop,\n wireMeasurement,\n type CanvasHost,\n type DomWidgetsReflector,\n type GLRoute,\n type Planes,\n type WidgetFocusHandle,\n} from \"@ice/dom\";\nimport { useEffect, useRef, useState, type CSSProperties, type ReactElement, type ReactNode } from \"react\";\nimport { EngineProvider } from \"./engine-context\";\nimport { attachKeymap, type KeymapEntry } from \"./keymap\";\nimport { WidgetRoot } from \"./widget-root\";\n\n/** Handed to {@link InfiniteCanvasProps.onReady} for app-side GL/devtools wiring. */\nexport interface InfiniteCanvasHandle {\n readonly engine: CanvasEngine;\n readonly host: CanvasHost;\n readonly planes: Planes;\n /**\n * Programmatic widget focus (design-007 §2.3): `focusWidget(entity)` /\n * `blurFocus()` for `keyboard: \"exclusive\"` widgets. Focus is VIEW state\n * (design-007 §2.6) — it rides this handle, not `engine.ops` (a headless\n * engine correctly has no focus concept).\n */\n readonly focus: WidgetFocusHandle;\n}\n\n/**\n * STRUCTURAL mirror of `@ice/ground`'s GroundLayer/GroundFactory (the\n * `WidgetDef.component`-style opaque seam: react never imports the package —\n * the wall forbids three here). `@ice/ground.ground(...)` returns a function\n * assignable to this type.\n */\nexport interface GroundLayerHandle {\n readonly reflector: ReflectorDef & { available(): boolean };\n configureGrid(cfg: Partial<GridConfig>): void;\n dispose(): void;\n}\n\nexport type GroundLayerFactory = (ctx: {\n readonly host: { readonly container: HTMLElement; readonly contentPlane: HTMLElement };\n readonly world: World;\n readonly readWirePreview: () => WirePreviewBuffer;\n}) => GroundLayerHandle;\n\nexport interface InfiniteCanvasProps {\n /** A constructed engine (`createCanvasEngine(...)`); NOT disposed on unmount. */\n readonly engine: CanvasEngine;\n /**\n * The ResizeObserver side of widget measurement. Pass the SAME queue given to\n * `createCanvasEngine({ measureQueue })`. Absent ⇒ measurement skipped.\n */\n readonly measureQueue?: MeasureQueue;\n /** Called once after the host/reflectors/loop are live (app-side GL/devtools). */\n readonly onReady?: (handle: InfiniteCanvasHandle) => void;\n /**\n * The P0 ground layer (dot grid, wires, snap guides — one WebGPU canvas).\n * Pass `ground(opts)` from `@ice/ground`; received opaquely (see\n * {@link GroundLayerFactory}). Memoize in the caller — a new identity\n * re-boots the canvas mount effect. Absent ⇒ no ground layer renders.\n */\n readonly ground?: GroundLayerFactory;\n /**\n * Dot-grid tuning (theme dot color, spacing, fades). Applied live via the\n * ground layer's `configureGrid` — changing it never re-boots the canvas\n * (memoize in the caller to avoid redundant same-value redraws). No-op\n * when {@link ground} is absent.\n */\n readonly grid?: Partial<GridConfig>;\n /**\n * GL pointer routing (event-time island pick — @ice/r3f's\n * createGLPointerRouter). Provide from the FIRST render (a stub delegating\n * to a ref is fine — the real router usually arrives in onReady); the prop\n * is read through a ref, so later identity changes take effect without\n * re-attaching the adapter.\n */\n readonly glRoute?: GLRoute;\n /**\n * Keymap overrides plumbed to {@link attachKeymap} (design-007 §5 M-d — the\n * declared alternative to capture-phase `stopPropagation` folklore; retires\n * the widgetlab C-key hack). An entry replaces a default by its\n * `key|mod|shift` signature; conditional behavior belongs INSIDE `run`\n * (read engine state there — e.g. selection → comment, else the default's\n * action). BOUND ONCE at mount, like the adapter: entries should read live\n * state from the engine at run time, never close over render-time values.\n */\n readonly keymapOverrides?: readonly KeymapEntry[];\n readonly className?: string;\n readonly style?: CSSProperties;\n /** Overlays inside the viewport (toolbars, HUD) — rendered under the EngineProvider. */\n readonly children?: ReactNode;\n}\n\nexport function InfiniteCanvas({\n engine,\n measureQueue,\n onReady,\n ground,\n grid: gridConfig,\n glRoute,\n keymapOverrides,\n className,\n style,\n children,\n}: InfiniteCanvasProps): ReactElement {\n const containerRef = useRef<HTMLDivElement>(null);\n const [hosts, setHosts] = useState<DomWidgetsReflector | undefined>(undefined);\n // Keep onReady out of the effect deps (identity churn must not re-boot).\n const onReadyRef = useRef(onReady);\n onReadyRef.current = onReady;\n // The live ground handle (set by the mount effect); the grid-config effect\n // below re-tunes it without re-booting the canvas.\n const groundRef = useRef<GroundLayerHandle | null>(null);\n const gridConfigRef = useRef(gridConfig);\n gridConfigRef.current = gridConfig;\n // glRoute reads through a ref: the adapter captures ONE function at attach,\n // and the app's real router typically arrives post-mount (onReady).\n const glRouteRef = useRef(glRoute);\n glRouteRef.current = glRoute;\n // Overrides are bound once at mount (attachKeymap builds its map at attach);\n // the ref keeps identity churn from re-booting the canvas.\n const keymapOverridesRef = useRef(keymapOverrides);\n keymapOverridesRef.current = keymapOverrides;\n\n useEffect(() => {\n const container = containerRef.current;\n if (container === null) return;\n const { world, engine: core, stack, runtime } = engine;\n\n const host = createCanvasHost(container);\n const planes = createPlanes(host);\n const planeArgs = { contentPlane: planes.content, liftedPlane: planes.lifted };\n const domWidgets = createDomWidgetsReflector(planeArgs, world, runtime.store);\n const remoteCursors = createRemoteCursorsReflector(host, world);\n\n // Handles kept for teardown: unregistering only stops flushes — the DOM\n // these factories inserted (ground canvas, chrome plane) must be disposed\n // too, or a StrictMode remount stacks duplicates (the double-grid field\n // report, 2026-07-11).\n const groundLayer =\n ground?.({ host, world, readWirePreview: () => stack.wirePreview }) ?? null;\n groundRef.current = groundLayer;\n if (groundLayer !== null && gridConfigRef.current !== undefined) {\n groundLayer.configureGrid(gridConfigRef.current);\n }\n const chrome = createChromeReflector(host, world, stack.marqueeBuffer);\n\n // Registration order = flush order — node-board's proven sequence.\n const unregister = [\n core.registerReflector(createPlaneTransformReflector(planeArgs)),\n ...(groundLayer !== null ? [core.registerReflector(groundLayer.reflector)] : []),\n core.registerReflector(domWidgets),\n core.registerReflector(chrome),\n core.registerReflector(createCursorReflector(host, stack.readCursor)),\n core.registerReflector(remoteCursors.reflector),\n ];\n\n const detachPointer = attachPointerAdapter(\n host,\n stack.queue,\n glRouteRef.current !== undefined\n ? // Pass the verdict through UNCOERCED: a rich GLRouteVerdict return\n // (hover-time overInteractive, 2026-07-18) must survive this seam.\n { glRoute: (kind, x, y, e) => glRouteRef.current?.(kind, x, y, e) ?? false }\n : {},\n );\n const detachMeasure =\n measureQueue !== undefined ? wireMeasurement(runtime.store, domWidgets, measureQueue) : undefined;\n const detachKeymap = attachKeymap(engine, undefined, keymapOverridesRef.current ?? []);\n // Click-to-focus acquisition for keyboard-claiming widgets + the\n // programmatic focus handle (design-007 §2.3; the reflector's hostFor\n // resolves entity → content, the driver walks to the marked host).\n const focus = attachWidgetFocus(host, domWidgets);\n\n const syncViewport = (): void => {\n const rect = container.getBoundingClientRect();\n const dpr = typeof window !== \"undefined\" ? window.devicePixelRatio : 1;\n writeRuntimeResource(world, Viewport, { w: rect.width, h: rect.height, dpr });\n };\n syncViewport();\n let resizeObserver: ResizeObserver | undefined;\n if (typeof ResizeObserver !== \"undefined\") {\n resizeObserver = new ResizeObserver(syncViewport);\n resizeObserver.observe(container);\n }\n\n const stopLoop = startRafLoop(core);\n setHosts(domWidgets);\n onReadyRef.current?.({ engine, host, planes, focus });\n\n return () => {\n stopLoop();\n focus.detach();\n detachKeymap();\n detachMeasure?.();\n detachPointer();\n resizeObserver?.disconnect();\n for (const unreg of unregister) unreg();\n remoteCursors.destroy();\n groundLayer?.dispose();\n groundRef.current = null;\n domWidgets.dispose();\n chrome.dispose();\n planes.dispose();\n host.dispose();\n setHosts(undefined);\n };\n }, [engine, measureQueue, ground]);\n\n // Live grid re-tune — never re-boots the canvas (the mount effect above\n // deliberately omits `gridConfig` from its deps; initial config rides the\n // ref at creation).\n useEffect(() => {\n if (gridConfig !== undefined) groundRef.current?.configureGrid(gridConfig);\n }, [gridConfig]);\n\n return (\n <EngineProvider engine={engine}>\n <div ref={containerRef} className={className} style={{ width: \"100%\", height: \"100%\", ...style }} data-ice-canvas=\"\">\n {hosts !== undefined ? (\n <WidgetRoot world={engine.world} store={engine.runtime.store} hosts={hosts} />\n ) : null}\n {children}\n </div>\n </EngineProvider>\n );\n}\n","/**\n * @ice/react — widget content layer: portals from one root + Tier-3 hooks.\n * Import wall: @ice/dom → @ice/core down only — never three/@react-three\n * (enforced). react/react-dom are peers.\n */\nexport const REACT_VERSION = \"0.0.0\";\n\nexport {\n WidgetHiddenContext,\n useBreakpoint,\n useSelected,\n useWidgetProps,\n useWorldComponent,\n} from \"./hooks\";\nexport { WidgetRoot, type WidgetComponentProps, type WidgetHosts, type WidgetRootProps } from \"./widget-root\";\n\n// M10 React facade (design-005 §5): engine context, commit seam, hooks, keymap,\n// and the <InfiniteCanvas> mount.\nexport {\n EngineProvider,\n useCanvasEngine,\n useFrameFreeze,\n useOps,\n useStageHold,\n useWorld,\n type EngineProviderProps,\n} from \"./engine-context\";\nexport { useCommit, useUndoStatus, type Commit, type UndoStatus } from \"./use-commit\";\nexport { WidgetPreview, type WidgetPreviewProps } from \"./widget-preview\";\nexport {\n getPreviewSnapshot,\n hasPreviewSnapshot,\n setPreviewSnapshot,\n subscribePreviewSnapshots,\n type PreviewImage,\n} from \"./preview-snapshots\";\nexport { useTool, useToolState } from \"./use-tool\";\nexport { usePresencePeers, type PresencePeerView } from \"./use-presence\";\nexport { attachKeymap, type KeymapEntry } from \"./keymap\";\nexport {\n InfiniteCanvas,\n type GroundLayerFactory,\n type GroundLayerHandle,\n type InfiniteCanvasHandle,\n type InfiniteCanvasProps,\n} from \"./infinite-canvas\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAS,eAAe,aAAa,YAAY,SAAS,QAAQ,4BAA4B;AAGvF,IAAM,sBAAsB,cAAc,KAAK;AAEtD,IAAM,YAAY,YAAY,CAAC,QAAQ,CAAC;AAGxC,SAAS,UAAU,GAAY,GAAqB;AAClD,MAAI,OAAO,GAAG,GAAG,CAAC,EAAG,QAAO;AAC5B,MAAI,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,MAAM,QAAQ,MAAM,KAAM,QAAO;AACvF,QAAM,KAAK,OAAO,KAAK,CAAC;AACxB,QAAM,KAAK,OAAO,KAAK,CAAC;AACxB,MAAI,GAAG,WAAW,GAA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ternalStore","useSyncExternalStore","createContext","useContext","useCallback","useRef","useSyncExternalStore","useCallback","useRef","useSyncExternalStore","useEffect","useRef","useSyncExternalStore","jsx","useRef","useEffect","jsx","useSyncExternalStore","useCallback","useSyncExternalStore","useCallback","useSyncExternalStore","useCallback","useRef","useSyncExternalStore","useRef","useCallback","useSyncExternalStore","useEffect","useRef","jsx","jsxs","useRef","useEffect"]}