streetui 1.9.0 → 2.1.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/version.ts","../../state/src/signal.ts","../../state/src/store.ts","../../state/src/resource.ts","../../core/src/a11y-ids.ts","../../core/src/identity.ts","../../core/src/lifecycle.ts","../../core/src/environment.ts","../../core/src/diagnostics.ts","../../core/src/application.ts","../../core/src/node.ts","../../core/src/observability.ts","../../graph/src/graph-node.ts","../../graph/src/graph.ts","../../dsl/src/transition.ts","../../dsl/src/builders.ts","../../dsl/src/component.ts","../../dsl/src/dsl.ts","../../compiler/src/validation/validator.ts","../../compiler/src/transform/transform.ts","../../compiler/src/compile.ts","../../runtime/src/node-instance.ts","../../scheduler/src/scheduler.ts","../../runtime/src/runtime.ts","../../events/src/event-types.ts","../../events/src/event-bus.ts","../../events/src/dom-bridge.ts","../../dom/src/browser-adapter.ts","../../dom/src/server-node.ts","../../dom/src/server-adapter.ts","../../dom/src/focus.ts","../../dom/src/live-region.ts","../../renderer/src/render-context.ts","../../renderer/src/node-instance.ts","../../renderer/src/attributes.ts","../../renderer/src/events.ts","../../renderer/src/tag-map.ts","../../renderer/src/patch.ts","../../renderer/src/reconciliation.ts","../../renderer/src/transition.ts","../../renderer/src/mount.ts","../../renderer/src/hydration-diagnostics.ts","../../renderer/src/hydrate.ts","../../renderer/src/render-handle.ts","../../renderer/src/renderer.ts","../../renderer/src/dehydrate.ts","../../compiler/src/analysis/analyze.ts","../../compiler/src/analysis/inspect.ts","../../renderer/src/static-ssr-plan.ts","../../renderer/src/ssr.ts","../../router/src/matching.ts","../../router/src/history.ts","../../router/src/router.ts","../../router/src/mount-router.ts","../../forms/src/validators.ts","../../forms/src/form.ts","../../context/src/context.ts","../../i18n/src/i18n.ts","../../devtools/src/inspector.ts","../../devtools/src/application.ts","../../devtools/src/diagnostics.ts","../../devtools/src/inspect-reactive.ts","../../devtools/src/panels.ts","../src/config.ts"],"sourcesContent":["/**\n * The single authoritative StreetUI framework version.\n *\n * This constant is the one source of truth for the version of the shipped\n * `streetui` package. It is kept in lock-step with this package's\n * `package.json` `version` field and with the bundled CLI's reported version\n * (`streetui --version`) — the consolidated test-suite pins all three to the\n * same coordinated release so they can never silently drift apart.\n */\nexport const VERSION = '1.9.0';\n","/**\n * StreetUI reactive signals — framework-owned reactivity, no external libraries.\n *\n * Architecture:\n * Signal<T> — writable, holds a value, notifies on change\n * DerivedSignal<T> — read-only, lazily computed from other signals\n * effect() — side-effect that re-runs when dependencies change\n * batch() — run multiple updates before notifying\n */\n\nexport type Subscriber<T> = (value: T) => void;\nexport type Unsubscribe = () => void;\n\n// ── Tracking ──────────────────────────────────────────────────────────────────\n\n/**\n * Any reactive source that can have downstream consumers attached.\n * Both Signal and DerivedSignal implement this.\n */\nexport interface ReactiveSource<T> {\n get(): T;\n peek(): T;\n subscribe(fn: Subscriber<T>): Unsubscribe;\n /** Internal: remove a downstream consumer. */\n _removeConsumer(consumer: ReactiveConsumer): void;\n}\n\n/**\n * A downstream consumer (DerivedSignal or Effect) that can be invalidated\n * and can register itself as depending on a source.\n */\nexport interface ReactiveConsumer {\n _invalidate(): void;\n /** Internal: called by a source to register a dependency. */\n _addSource(src: ReactiveSource<unknown>): void;\n}\n\n/** The active consumer being tracked during a computation. */\nlet _activeConsumer: ReactiveConsumer | null = null;\n\nfunction withConsumer<T>(consumer: ReactiveConsumer, fn: () => T): T {\n const prev = _activeConsumer;\n _activeConsumer = consumer;\n try {\n return fn();\n } finally {\n _activeConsumer = prev;\n }\n}\n\n// ── Batch state (must be before Signal class so .set() can reference it) ──────\n\n/** Depth counter — batches nest; only the outermost flush propagates. */\nlet _batchDepth = 0;\n\ninterface PendingFlush {\n signal: Signal<unknown>;\n value: unknown;\n}\n\n/**\n * Keyed by signal identity — last-write-wins for each signal within a batch.\n * An ordered Map preserves first-seen insertion order for stable flush sequence.\n */\nconst _pendingFlushes = new Map<Signal<unknown>, PendingFlush>();\n\nfunction _enqueueBatchFlush(sig: Signal<unknown>, value: unknown): void {\n _pendingFlushes.set(sig, { signal: sig, value });\n}\n\nfunction _drainBatch(): void {\n const flushes = [..._pendingFlushes.values()];\n _pendingFlushes.clear();\n for (const { signal: sig, value } of flushes) {\n sig._flushBatch(value);\n }\n}\n\n// ── Signal ────────────────────────────────────────────────────────────────────\n\nexport interface ReadonlySignal<T> {\n get(): T;\n peek(): T;\n subscribe(fn: Subscriber<T>): Unsubscribe;\n}\n\nexport class Signal<T> implements ReactiveSource<T>, ReadonlySignal<T> {\n protected _value: T;\n private readonly _subscribers: Set<Subscriber<T>> = new Set();\n private readonly _consumers: Set<ReactiveConsumer> = new Set();\n\n constructor(initial: T) {\n this._value = initial;\n }\n\n get(): T {\n if (_activeConsumer !== null) {\n this._consumers.add(_activeConsumer);\n _activeConsumer._addSource(this as ReactiveSource<unknown>);\n }\n return this._value;\n }\n\n peek(): T {\n return this._value;\n }\n\n set(value: T): void {\n if (Object.is(this._value, value)) return;\n this._value = value;\n if (_batchDepth > 0) {\n // Defer notification until the batch flushes.\n // The stored value is always the latest (last-write-wins for same signal).\n _enqueueBatchFlush(this as unknown as Signal<unknown>, value);\n } else {\n this._flush(value);\n }\n }\n\n update(fn: (current: T) => T): void {\n this.set(fn(this._value));\n }\n\n subscribe(fn: Subscriber<T>): Unsubscribe {\n this._subscribers.add(fn);\n return () => { this._subscribers.delete(fn); };\n }\n\n _removeConsumer(consumer: ReactiveConsumer): void {\n this._consumers.delete(consumer);\n }\n\n /**\n * Called by the batch machinery after the batch has completed.\n * Notifies subscribers with the final coalesced value.\n */\n _flushBatch(value: unknown): void {\n this._flush(value as T);\n }\n\n private _flush(value: T): void {\n for (const sub of [...this._subscribers]) sub(value);\n for (const consumer of [...this._consumers]) consumer._invalidate();\n }\n\n /**\n * @internal DevTools inspection only. The number of live observers\n * (direct subscribers plus derived/effect consumers). Read-only; never\n * mutates reactive state.\n */\n _observerCount(): number {\n return this._subscribers.size + this._consumers.size;\n }\n}\n\n// ── DerivedSignal ─────────────────────────────────────────────────────────────\n\nexport class DerivedSignal<T> implements ReactiveSource<T>, ReactiveConsumer, ReadonlySignal<T> {\n private _value: T | undefined = undefined;\n private _dirty = true;\n private _disposed = false;\n private readonly _fn: () => T;\n private readonly _subscribers: Set<Subscriber<T>> = new Set();\n /** All upstream sources this derived currently reads from. */\n private readonly _sources: Set<ReactiveSource<unknown>> = new Set();\n /** Downstream consumers that depend on this derived. */\n private readonly _consumers: Set<ReactiveConsumer> = new Set();\n\n constructor(fn: () => T) {\n this._fn = fn;\n }\n\n get(): T {\n // Register this derived with the outer consumer if any\n if (_activeConsumer !== null) {\n this._consumers.add(_activeConsumer);\n _activeConsumer._addSource(this as ReactiveSource<unknown>);\n }\n if (this._dirty) this._recompute();\n return this._value as T;\n }\n\n peek(): T {\n if (this._dirty) this._recompute();\n return this._value as T;\n }\n\n subscribe(fn: Subscriber<T>): Unsubscribe {\n // Eagerly compute so sources track this derived as a consumer\n if (this._dirty) this._recompute();\n this._subscribers.add(fn);\n return () => { this._subscribers.delete(fn); };\n }\n\n _addSource(src: ReactiveSource<unknown>): void {\n this._sources.add(src);\n }\n\n _removeConsumer(consumer: ReactiveConsumer): void {\n this._consumers.delete(consumer);\n }\n\n _invalidate(): void {\n if (this._disposed) return;\n this._dirty = true;\n const newVal = this.peek(); // recompute\n for (const sub of [...this._subscribers]) sub(newVal);\n for (const consumer of [...this._consumers]) consumer._invalidate();\n }\n\n private _recompute(): void {\n // Detach from all current sources before re-tracking\n for (const src of this._sources) src._removeConsumer(this);\n this._sources.clear();\n\n this._value = withConsumer(this, this._fn);\n this._dirty = false;\n }\n\n dispose(): void {\n this._disposed = true;\n for (const src of this._sources) src._removeConsumer(this);\n this._sources.clear();\n this._subscribers.clear();\n this._consumers.clear();\n }\n\n /**\n * @internal DevTools inspection only. Live observers (subscribers plus\n * downstream consumers). Read-only.\n */\n _observerCount(): number {\n return this._subscribers.size + this._consumers.size;\n }\n}\n\n// ── effect ────────────────────────────────────────────────────────────────────\n\nclass Effect implements ReactiveConsumer {\n private readonly _fn: () => void | (() => void);\n private _cleanup: (() => void) | undefined = undefined;\n private _disposed = false;\n private readonly _sources: Set<ReactiveSource<unknown>> = new Set();\n\n constructor(fn: () => void | (() => void)) {\n this._fn = fn;\n this._run();\n }\n\n _addSource(src: ReactiveSource<unknown>): void {\n this._sources.add(src);\n }\n\n _invalidate(): void {\n if (this._disposed) return;\n this._run();\n }\n\n private _run(): void {\n // Detach from all current sources before re-tracking\n for (const src of this._sources) src._removeConsumer(this);\n this._sources.clear();\n\n if (typeof this._cleanup === 'function') this._cleanup();\n const result = withConsumer(this, this._fn);\n this._cleanup = typeof result === 'function' ? result : undefined;\n }\n\n dispose(): void {\n this._disposed = true;\n for (const src of this._sources) src._removeConsumer(this);\n this._sources.clear();\n if (typeof this._cleanup === 'function') this._cleanup();\n this._cleanup = undefined;\n }\n}\n\n// ── Public API ─────────────────────────────────────────────────────────────────\n\nexport function signal<T>(initial: T): Signal<T> {\n return new Signal(initial);\n}\n\nexport function derived<T>(fn: () => T): DerivedSignal<T> {\n return new DerivedSignal(fn);\n}\n\nexport function effect(fn: () => void | (() => void)): Unsubscribe {\n const e = new Effect(fn);\n return () => e.dispose();\n}\n\n/**\n * Run multiple signal updates as an atomic batch.\n *\n * Within the callback, calls to signal.set() are deferred — each signal\n * accumulates its latest value. When the outermost batch() returns,\n * each modified signal fires its subscribers exactly once with the final\n * value. Nested batch() calls are supported; the flush only runs when the\n * outermost batch exits.\n *\n * Example:\n * batch(() => {\n * count.set(1);\n * count.set(2);\n * count.set(3);\n * });\n * // subscribers see count = 3 exactly once\n */\nexport function batch(fn: () => void): void {\n _batchDepth++;\n try {\n fn();\n } finally {\n _batchDepth--;\n if (_batchDepth === 0) {\n _drainBatch();\n }\n }\n}\n\n/** True when inside a batch() call. Useful for advanced scheduling integration. */\nexport function isBatching(): boolean {\n return _batchDepth > 0;\n}\n\n// ── Inspection (read-only, DevTools-facing) ─────────────────────────────────\n\n/** Whether a signal is writable (`signal()`) or computed (`derived()`). */\nexport type SignalKind = 'writable' | 'derived';\n\n/** Classify a reactive value as writable or derived. */\nexport function signalKind(source: ReadonlySignal<unknown>): SignalKind {\n return source instanceof DerivedSignal ? 'derived' : 'writable';\n}\n\n/**\n * The number of live observers on a signal — direct subscribers plus derived\n * or effect consumers — or `undefined` if the source does not expose the count.\n * Read-only; safe for DevTools. Never mutates reactive state.\n */\nexport function observerCount(source: ReadonlySignal<unknown>): number | undefined {\n const maybe = source as { _observerCount?: () => number };\n return typeof maybe._observerCount === 'function' ? maybe._observerCount() : undefined;\n}\n","/**\n * A simple reactive store built on top of signals.\n * Useful for structured state with multiple fields.\n */\n\nimport { Signal, signal, type Subscriber, type Unsubscribe } from './signal.js';\n\nexport type StoreState = Record<string, unknown>;\n\nexport class Store<T extends StoreState> {\n private readonly _signals: Record<string, Signal<unknown>>;\n\n constructor(initial: T) {\n const signals: Record<string, Signal<unknown>> = {};\n for (const key in initial) {\n if (Object.prototype.hasOwnProperty.call(initial, key)) {\n signals[key] = signal(initial[key] as unknown);\n }\n }\n this._signals = signals;\n }\n\n get<K extends keyof T>(key: K): T[K] {\n const s = this._signals[key as string];\n if (s === undefined) {\n throw new Error(`Store: unknown key \"${String(key)}\"`);\n }\n return s.get() as T[K];\n }\n\n set<K extends keyof T>(key: K, value: T[K]): void {\n const s = this._signals[key as string];\n if (s === undefined) {\n throw new Error(`Store: unknown key \"${String(key)}\"`);\n }\n s.set(value as unknown);\n }\n\n signal<K extends keyof T>(key: K): Signal<T[K]> {\n const s = this._signals[key as string];\n if (s === undefined) {\n throw new Error(`Store: unknown key \"${String(key)}\"`);\n }\n return s as unknown as Signal<T[K]>;\n }\n\n subscribe<K extends keyof T>(key: K, fn: Subscriber<T[K]>): Unsubscribe {\n return this.signal(key).subscribe(fn);\n }\n\n getSnapshot(): T {\n const snap = {} as T;\n for (const key in this._signals) {\n if (Object.prototype.hasOwnProperty.call(this._signals, key)) {\n (snap as Record<string, unknown>)[key] = this._signals[key]?.peek();\n }\n }\n return snap;\n }\n}\n\nexport function createStore<T extends StoreState>(initial: T): Store<T> {\n return new Store(initial);\n}\n","/**\n * StreetUI async resources — framework-native asynchronous data.\n *\n * A `resource` wraps a Promise-returning loader and exposes its lifecycle as\n * ordinary StreetUI signals (status / data / error), so it composes with\n * `derived`, `effect`, `when()`, `listOf` and the renderer with no second\n * reactive system.\n *\n * State machine:\n *\n * idle ──(load)──▶ loading ──(resolve)──▶ success\n * │\n * └────(reject)──────▶ error\n *\n * Refetch keeps the previously-loaded `data` visible while `status` is\n * `'loading'` again (see `isRefetching`) — there is no separate `'refetching'`\n * status; it is expressed through `status === 'loading'` with `data` still set.\n *\n * The resource is transport-agnostic: the loader is any function returning a\n * value or a Promise. When it accepts the provided `AbortSignal`, in-flight\n * work is cancelled on `dispose()` or when a newer request supersedes it.\n */\n\nimport { signal, derived, batch, type ReadonlySignal, type Unsubscribe } from './signal.js';\n\nexport type ResourceStatus = 'idle' | 'loading' | 'success' | 'error';\n\n/** Context handed to the loader; carries an AbortSignal for cancellation. */\nexport interface ResourceLoaderContext {\n readonly signal: AbortSignal;\n}\n\n/** Any value-or-Promise producing function. Receives an abort-aware context. */\nexport type ResourceLoader<T> = (ctx: ResourceLoaderContext) => Promise<T> | T;\n\nexport interface ResourceOptions<T = unknown> {\n /** Load immediately on creation. Defaults to `true`. When `false`, stays `idle` until `refetch()`. */\n readonly immediate?: boolean;\n /**\n * Explicit reactive dependencies. When any listed signal changes, the\n * resource refetches. Dependencies are explicit (not auto-tracked from the\n * loader body) so there is no risk of an accidental infinite refetch loop.\n */\n readonly watch?: ReadonlyArray<ReadonlySignal<unknown>>;\n /**\n * Optional teardown registrar (e.g. a route's `ctx.onCleanup`). When given,\n * the resource registers its own `dispose` so it is cleaned up automatically\n * when its owner is removed.\n */\n readonly onCleanup?: (fn: () => void) => void;\n /**\n * Server-provided initial value for hydration. When present the resource\n * starts in `'success'` with this data already visible, and the initial\n * auto-load is skipped (so the client does not refetch data the server\n * already resolved). This is the client half of SSR resource transfer; the\n * server side awaits `refetch()` before serializing. Set `immediate: true`\n * explicitly to force a client refetch anyway.\n */\n readonly initialData?: T;\n /** Server-provided initial error for hydration (mirrors `initialData`). */\n readonly initialError?: unknown;\n /**\n * Explicit initial status override. Rarely needed — inferred as `'success'`\n * from `initialData` or `'error'` from `initialError`.\n */\n readonly initialStatus?: ResourceStatus;\n}\n\nexport interface Resource<T> {\n /** Reactive lifecycle status. */\n readonly status: ReadonlySignal<ResourceStatus>;\n /** The last successfully-loaded value, or `undefined` before first success. */\n readonly data: ReadonlySignal<T | undefined>;\n /** The most recent error, or `undefined` when there is none. Typed `unknown` — never `any`. */\n readonly error: ReadonlySignal<unknown>;\n /** Convenience: `status === 'loading'`. */\n readonly loading: ReadonlySignal<boolean>;\n /** Convenience: loading while previously-loaded data is still present (a refetch). */\n readonly isRefetching: ReadonlySignal<boolean>;\n /** Trigger a new request. Resolves when the request settles (or is superseded). */\n refetch(): Promise<void>;\n /** Cancel in-flight work, drop watchers, and ignore any late results. Idempotent. */\n dispose(): void;\n}\n\n/** True for an abort we initiated (so it is not surfaced as a real error). */\nfunction isAbortError(err: unknown): boolean {\n return (\n err instanceof Error && err.name === 'AbortError'\n ) || (\n typeof DOMException !== 'undefined' && err instanceof DOMException && err.name === 'AbortError'\n );\n}\n\nexport function resource<T>(loader: ResourceLoader<T>, options: ResourceOptions<T> = {}): Resource<T> {\n // Seed hydrated initial state (SSR transfer). `initialStatus` wins if given,\n // otherwise infer success/error from the provided value.\n const hasInitial =\n options.initialData !== undefined ||\n options.initialError !== undefined ||\n options.initialStatus !== undefined;\n\n const seededStatus: ResourceStatus =\n options.initialStatus ??\n (options.initialData !== undefined\n ? 'success'\n : options.initialError !== undefined\n ? 'error'\n : 'idle');\n\n const status = signal<ResourceStatus>(seededStatus);\n const data = signal<T | undefined>(options.initialData);\n const error = signal<unknown>(options.initialError);\n\n const loading = derived<boolean>(() => status.get() === 'loading');\n const isRefetching = derived<boolean>(() => status.get() === 'loading' && data.get() !== undefined);\n\n let disposed = false;\n /** Monotonic request id — only the newest request may write state (race guard). */\n let runId = 0;\n let controller: AbortController | null = null;\n\n const load = async (): Promise<void> => {\n if (disposed) return;\n\n // Supersede any in-flight request: abort it and bump the run id so its\n // eventual resolution is ignored.\n controller?.abort();\n const myRun = ++runId;\n const myController = new AbortController();\n controller = myController;\n\n // Enter loading. Preserve `data` (so a refetch keeps showing the old value)\n // and clear any previous error.\n batch(() => {\n error.set(undefined);\n status.set('loading');\n });\n\n try {\n const result = await loader({ signal: myController.signal });\n // Ignore stale or cancelled resolutions.\n if (disposed || myRun !== runId) return;\n batch(() => {\n data.set(result);\n error.set(undefined);\n status.set('success');\n });\n } catch (err) {\n if (disposed || myRun !== runId) return;\n // A self-initiated abort is not a user-visible error.\n if (isAbortError(err)) return;\n batch(() => {\n error.set(err);\n status.set('error');\n });\n }\n };\n\n const refetch = (): Promise<void> => load();\n\n // Explicit reactive dependencies: refetch when any watched signal changes.\n const watchUnsubs: Unsubscribe[] = [];\n if (options.watch !== undefined) {\n for (const dep of options.watch) {\n watchUnsubs.push(\n dep.subscribe(() => {\n if (!disposed) void load();\n }),\n );\n }\n }\n\n const dispose = (): void => {\n if (disposed) return;\n disposed = true;\n controller?.abort();\n controller = null;\n for (const unsub of watchUnsubs) unsub();\n watchUnsubs.length = 0;\n };\n\n if (options.onCleanup !== undefined) {\n options.onCleanup(dispose);\n }\n\n // Auto-load on creation unless disabled. When hydrated initial state is\n // present we skip the initial load by default (the server already resolved\n // it); an explicit `immediate: true` still forces a refetch.\n if (options.immediate === true || (options.immediate !== false && !hasInitial)) {\n void load();\n }\n\n return {\n status,\n data,\n error,\n loading,\n isRefetching,\n refetch,\n dispose,\n };\n}\n","/**\n * Deterministic accessibility id helpers.\n *\n * Accessible markup often needs stable id relationships — a `<label for>` (or\n * `aria-labelledby`) pointing at an input, an `aria-describedby` pointing at a\n * hint/error, an `aria-labelledby` on a dialog pointing at its title. Those ids\n * must be IDENTICAL on the server and the client, otherwise a hydrated subtree\n * that re-renders (e.g. a toggled `when()` branch) would compute a different id\n * than the server emitted and break the association.\n *\n * These helpers derive ids purely from a caller-supplied stable base string\n * (typically a form field name or a dialog name). They use NO incrementing\n * counter and NO randomness, so `a11yIds('email')` yields the same ids in every\n * environment and on every call — which is exactly what SSR + hydration needs.\n */\n\nconst UNSAFE = /[^A-Za-z0-9_-]+/g;\n\n/** Normalise an arbitrary base into a token safe for use in an id/selector. */\nexport function toIdToken(base: string): string {\n const token = base.trim().replace(UNSAFE, '-').replace(/^-+|-+$/g, '');\n return token.length > 0 ? token : 'field';\n}\n\nexport interface A11yIds {\n /** The normalised base token. */\n readonly base: string;\n /** Id for the primary interactive element (e.g. the input). */\n readonly input: string;\n /** Id for a label element / labelling text (target of `aria-labelledby`). */\n readonly label: string;\n /** Id for descriptive/help text (target of `aria-describedby`). */\n readonly description: string;\n /** Id for an error message element. */\n readonly error: string;\n /** Id for a title element (e.g. a dialog title; target of `aria-labelledby`). */\n readonly title: string;\n /**\n * Id for a control that triggers a popup (button/summary). Pair with\n * `controls` on the popup it opens (`ariaControls: ids.controls`,\n * `ariaExpanded: open`).\n */\n readonly trigger: string;\n /** Id for a popup/region a `trigger` controls (target of `aria-controls`). */\n readonly controls: string;\n /** Id for a subtree owned out-of-DOM-order (target of `aria-owns`). */\n readonly owns: string;\n /** Derive an arbitrary suffixed id from the same base. */\n id(suffix: string): string;\n}\n\n/**\n * Build a set of deterministic, SSR-stable ids from a base string.\n *\n * @example\n * const ids = a11yIds('email');\n * // ids.input === 'email-input', ids.label === 'email-label', ...\n * input({ bind: value, id: ids.input, ariaLabelledBy: ids.label, ariaDescribedBy: ids.error });\n * text('Email', { id: ids.label });\n *\n * @example\n * // A menu button that controls its popup, wired by shared ids:\n * const m = a11yIds('actions');\n * button('Actions', { id: m.trigger, ariaControls: m.controls, ariaExpanded: open });\n * page.dropdown('menu', { open, id: m.controls }, (d) => { … });\n */\nexport function a11yIds(base: string): A11yIds {\n const token = toIdToken(base);\n return {\n base: token,\n input: `${token}-input`,\n label: `${token}-label`,\n description: `${token}-description`,\n error: `${token}-error`,\n title: `${token}-title`,\n trigger: `${token}-trigger`,\n controls: `${token}-controls`,\n owns: `${token}-owns`,\n id: (suffix: string) => `${token}-${toIdToken(suffix)}`,\n };\n}\n","/**\n * Node and application identity utilities.\n * Every node in the semantic graph has a stable, unique identity.\n */\n\nlet _counter = 0;\n\n/** Generate a framework-internal monotonic integer ID. */\nexport function nextId(): number {\n return ++_counter;\n}\n\n/** Reset the counter (test use only). */\nexport function resetIdCounter(): void {\n _counter = 0;\n}\n\n/** Opaque branded type for node IDs. */\nexport type NodeId = string & { readonly __brand: 'NodeId' };\n\n/** Create a NodeId from a string (must be unique at call site). */\nexport function createNodeId(value: string): NodeId {\n return value as NodeId;\n}\n\n/** Generate a fresh, unique NodeId. */\nexport function generateNodeId(prefix: string = 'node'): NodeId {\n return createNodeId(`${prefix}:${nextId()}`);\n}\n\n/** Parse the prefix from a NodeId. */\nexport function nodeIdPrefix(id: NodeId): string {\n const colon = id.indexOf(':');\n return colon === -1 ? id : id.slice(0, colon);\n}\n\n/** Branded type for application IDs. */\nexport type ApplicationId = string & { readonly __brand: 'ApplicationId' };\n\n/** Generate a fresh application ID. */\nexport function generateApplicationId(name: string): ApplicationId {\n return `app:${name}:${nextId()}` as ApplicationId;\n}\n","/**\n * Application and component lifecycle primitives.\n *\n * Lifecycle phases:\n * created → mounted → active ⇄ updating → unmounting → destroyed\n */\n\nexport type LifecyclePhase =\n | 'created'\n | 'mounted'\n | 'active'\n | 'updating'\n | 'unmounting'\n | 'destroyed';\n\nexport type LifecycleHook = () => void | Promise<void>;\n\nexport class Lifecycle {\n private _phase: LifecyclePhase = 'created';\n private readonly _hooks: Map<LifecyclePhase, LifecycleHook[]> = new Map();\n\n get phase(): LifecyclePhase {\n return this._phase;\n }\n\n get isMounted(): boolean {\n return this._phase === 'mounted' || this._phase === 'active' || this._phase === 'updating';\n }\n\n get isDestroyed(): boolean {\n return this._phase === 'destroyed';\n }\n\n on(phase: LifecyclePhase, hook: LifecycleHook): () => void {\n const hooks = this._hooks.get(phase) ?? [];\n hooks.push(hook);\n this._hooks.set(phase, hooks);\n return () => {\n const current = this._hooks.get(phase);\n if (current !== undefined) {\n const idx = current.indexOf(hook);\n if (idx !== -1) current.splice(idx, 1);\n }\n };\n }\n\n async transition(to: LifecyclePhase): Promise<void> {\n this._phase = to;\n const hooks = this._hooks.get(to) ?? [];\n for (const hook of hooks) {\n await hook();\n }\n }\n\n onMount(hook: LifecycleHook): () => void {\n return this.on('mounted', hook);\n }\n\n onUnmount(hook: LifecycleHook): () => void {\n return this.on('unmounting', hook);\n }\n\n onDestroy(hook: LifecycleHook): () => void {\n return this.on('destroyed', hook);\n }\n}\n\n/** A simple cleanup registry — collect teardown functions and run them all at once. */\nexport class CleanupRegistry {\n private readonly _fns: Array<() => void> = [];\n\n add(fn: () => void): void {\n this._fns.push(fn);\n }\n\n run(): void {\n for (const fn of this._fns) {\n try {\n fn();\n } catch {\n // Best-effort cleanup; don't let one failure block others\n }\n }\n this._fns.length = 0;\n }\n}\n","/**\n * Environment detection and capability flags.\n * The framework behaves slightly differently in browser vs. server vs. test.\n *\n * We use `typeof` checks throughout to remain safe across environments\n * without depending on @types/node.\n */\n\nexport type EnvironmentKind = 'browser' | 'server' | 'worker' | 'test' | 'unknown';\n\nexport interface EnvironmentCapabilities {\n readonly hasDom: boolean;\n readonly hasWindow: boolean;\n readonly hasDocument: boolean;\n readonly isSecureContext: boolean;\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\ndeclare const process: any;\n/* eslint-enable @typescript-eslint/no-explicit-any */\n\nfunction detectEnvironment(): EnvironmentKind {\n // Explicit test override via process.env\n try {\n if (\n typeof process !== 'undefined' &&\n process !== null &&\n typeof process === 'object' &&\n (process.env?.['NODE_ENV'] === 'test' || process.env?.['VITEST'] === 'true')\n ) {\n return 'test';\n }\n } catch {\n // process may not be defined in all environments\n }\n\n if (typeof window !== 'undefined' && typeof document !== 'undefined') {\n return 'browser';\n }\n\n if (\n typeof self !== 'undefined' &&\n typeof (self as unknown as Record<string, unknown>)['importScripts'] === 'function'\n ) {\n return 'worker';\n }\n\n try {\n if (typeof process !== 'undefined' && typeof process === 'object') {\n return 'server';\n }\n } catch {\n // ignore\n }\n\n return 'unknown';\n}\n\nfunction detectCapabilities(): EnvironmentCapabilities {\n return {\n hasDom: typeof document !== 'undefined',\n hasWindow: typeof window !== 'undefined',\n hasDocument: typeof document !== 'undefined',\n isSecureContext:\n typeof window !== 'undefined'\n ? ((window as unknown as Record<string, unknown>)['isSecureContext'] === true)\n : false,\n };\n}\n\nexport class Environment {\n readonly kind: EnvironmentKind;\n readonly capabilities: EnvironmentCapabilities;\n\n constructor(kind?: EnvironmentKind) {\n this.kind = kind ?? detectEnvironment();\n this.capabilities = detectCapabilities();\n }\n\n get isBrowser(): boolean {\n return this.kind === 'browser';\n }\n\n get isServer(): boolean {\n return this.kind === 'server';\n }\n\n get isTest(): boolean {\n return this.kind === 'test';\n }\n\n get isWorker(): boolean {\n return this.kind === 'worker';\n }\n}\n\n/** The singleton environment for this execution context. */\nexport const environment = new Environment();\n","/**\n * Framework diagnostics — structured errors, warnings, and hints\n * that flow through the compiler, validator, and runtime.\n */\n\nexport type DiagnosticSeverity = 'error' | 'warning' | 'info';\n\nexport interface DiagnosticLocation {\n readonly file?: string;\n readonly line?: number;\n readonly column?: number;\n readonly nodeId?: string;\n}\n\nexport interface Diagnostic {\n readonly severity: DiagnosticSeverity;\n readonly code: string;\n readonly message: string;\n readonly location: DiagnosticLocation | undefined;\n readonly cause: unknown;\n}\n\nexport class DiagnosticError extends Error {\n readonly diagnostics: readonly Diagnostic[];\n\n constructor(diagnostics: readonly Diagnostic[]) {\n const summary = diagnostics\n .filter(d => d.severity === 'error')\n .map(d => `[${d.code}] ${d.message}`)\n .join('\\n');\n super(`StreetUI diagnostics:\\n${summary}`);\n this.name = 'DiagnosticError';\n this.diagnostics = diagnostics;\n }\n}\n\nexport class DiagnosticCollector {\n private readonly _diagnostics: Diagnostic[] = [];\n\n get diagnostics(): readonly Diagnostic[] {\n return this._diagnostics;\n }\n\n get hasErrors(): boolean {\n return this._diagnostics.some(d => d.severity === 'error');\n }\n\n get hasWarnings(): boolean {\n return this._diagnostics.some(d => d.severity === 'warning');\n }\n\n error(\n code: string,\n message: string,\n location?: DiagnosticLocation,\n cause?: unknown,\n ): void {\n this._diagnostics.push({ severity: 'error', code, message, location: location ?? undefined, cause: cause ?? undefined });\n }\n\n warn(\n code: string,\n message: string,\n location?: DiagnosticLocation,\n ): void {\n this._diagnostics.push({ severity: 'warning', code, message, location: location ?? undefined, cause: undefined });\n }\n\n info(\n code: string,\n message: string,\n location?: DiagnosticLocation,\n ): void {\n this._diagnostics.push({ severity: 'info', code, message, location: location ?? undefined, cause: undefined });\n }\n\n merge(other: DiagnosticCollector): void {\n for (const d of other.diagnostics) {\n this._diagnostics.push(d);\n }\n }\n\n throwIfErrors(): void {\n if (this.hasErrors) {\n throw new DiagnosticError(this._diagnostics);\n }\n }\n\n clear(): void {\n this._diagnostics.length = 0;\n }\n}\n\n/** Format a single diagnostic as a human-readable string. */\nexport function formatDiagnostic(d: Diagnostic): string {\n const loc = d.location !== undefined\n ? ` (${[d.location.file, d.location.line, d.location.column]\n .filter(Boolean)\n .join(':')})`\n : '';\n return `[${d.severity.toUpperCase()}] ${d.code}: ${d.message}${loc}`;\n}\n","/**\n * Top-level Application primitive.\n * Owns lifecycle, identity, and the root of the application graph.\n */\n\nimport { type ApplicationId, generateApplicationId } from './identity.js';\nimport { Lifecycle, CleanupRegistry } from './lifecycle.js';\nimport { Environment, environment as defaultEnvironment } from './environment.js';\nimport { DiagnosticCollector } from './diagnostics.js';\n\nexport interface ApplicationOptions {\n readonly name: string;\n readonly version?: string;\n readonly environment?: Environment;\n}\n\nexport class Application {\n readonly id: ApplicationId;\n readonly name: string;\n readonly version: string;\n readonly lifecycle: Lifecycle;\n readonly cleanup: CleanupRegistry;\n readonly diagnostics: DiagnosticCollector;\n readonly environment: Environment;\n\n constructor(options: ApplicationOptions) {\n this.name = options.name;\n this.version = options.version ?? '0.0.1';\n this.id = generateApplicationId(options.name);\n this.lifecycle = new Lifecycle();\n this.cleanup = new CleanupRegistry();\n this.diagnostics = new DiagnosticCollector();\n this.environment = options.environment ?? defaultEnvironment;\n }\n\n async mount(): Promise<void> {\n if (this.lifecycle.phase !== 'created') {\n throw new Error(`Application \"${this.name}\" is already mounted (phase: ${this.lifecycle.phase})`);\n }\n await this.lifecycle.transition('mounted');\n await this.lifecycle.transition('active');\n }\n\n async unmount(): Promise<void> {\n if (!this.lifecycle.isMounted) {\n return;\n }\n await this.lifecycle.transition('unmounting');\n this.cleanup.run();\n await this.lifecycle.transition('destroyed');\n }\n\n onMount(fn: () => void | Promise<void>): void {\n this.lifecycle.onMount(fn);\n }\n\n onUnmount(fn: () => void | Promise<void>): void {\n this.lifecycle.onUnmount(fn);\n }\n}\n\n/** Factory convenience wrapper. */\nexport function createApplication(options: ApplicationOptions): Application {\n return new Application(options);\n}\n","/**\n * Framework node primitives — the base abstraction for every node\n * in the Semantic Application Graph.\n */\n\nimport { type NodeId, generateNodeId } from './identity.js';\n\nexport type SemanticNodeType =\n | 'application'\n | 'page'\n | 'section'\n | 'container'\n | 'heading'\n | 'text'\n | 'button'\n | 'input'\n | 'form'\n | 'list'\n | 'list-item'\n | 'image'\n | 'link'\n | 'component'\n | 'slot'\n | 'fragment'\n | 'reactive-list'\n | 'conditional'\n | 'portal';\n\nexport interface NodeMetadata {\n readonly createdAt: number;\n readonly [key: string]: unknown;\n}\n\nexport abstract class BaseNode {\n readonly id: NodeId;\n readonly type: SemanticNodeType;\n readonly metadata: NodeMetadata;\n\n constructor(type: SemanticNodeType, id?: NodeId) {\n this.type = type;\n this.id = id ?? generateNodeId(type);\n this.metadata = { createdAt: Date.now() };\n }\n\n abstract clone(): BaseNode;\n}\n","/**\n * Observability boundary — a tiny, optional logging seam plus contextual\n * framework errors.\n *\n * StreetUI never ships a telemetry service, never sends anything over the\n * network, and never logs on its own by default. Instead an application MAY\n * hand the framework a `DiagnosticSink` — any object with the log methods it\n * cares about — and the framework will route the diagnostics it already\n * produces (runtime errors, resource failures, hydration mismatches, router\n * transitions) to it. With no sink attached there is no logging and no cost.\n *\n * This is deliberately smaller than a logging library: it duplicates neither\n * `console` nor any structured-diagnostic type. It is a boundary, not a logger.\n */\n\n/**\n * Where a framework diagnostic originated. Every field is optional so a caller\n * supplies only what is meaningful for the situation. Values are intended to be\n * non-sensitive identifiers — never tokens, secrets, cookies, or form values.\n */\nexport interface DiagnosticContext {\n /** The package that produced the diagnostic, e.g. `@streetui/renderer`. */\n readonly package?: string;\n /** The operation underway, e.g. `hydrate`, `compile`, `navigate`. */\n readonly operation?: string;\n /** The graph node id involved, when applicable. */\n readonly nodeId?: string;\n /** The route path involved, when applicable. */\n readonly route?: string;\n /** A resource identifier involved, when applicable. */\n readonly resource?: string;\n}\n\n/**\n * The application-provided logging seam. Every method is optional; the\n * framework calls only the ones present. Implementations must not throw.\n */\nexport interface DiagnosticSink {\n debug?(message: string, context?: DiagnosticContext): void;\n info?(message: string, context?: DiagnosticContext): void;\n warn?(message: string, context?: DiagnosticContext): void;\n error?(message: string, context?: DiagnosticContext): void;\n}\n\n/** Format a context object as a compact ` [k=v, …]` suffix (empty when bare). */\nexport function formatDiagnosticContext(context?: DiagnosticContext): string {\n if (context === undefined) return '';\n const parts: string[] = [];\n if (context.package !== undefined) parts.push(`package=${context.package}`);\n if (context.operation !== undefined) parts.push(`operation=${context.operation}`);\n if (context.nodeId !== undefined) parts.push(`node=${context.nodeId}`);\n if (context.route !== undefined) parts.push(`route=${context.route}`);\n if (context.resource !== undefined) parts.push(`resource=${context.resource}`);\n return parts.length > 0 ? ` [${parts.join(', ')}]` : '';\n}\n\n/**\n * A framework error whose message carries structured, non-sensitive context so\n * a developer immediately sees which package/operation/node was involved. The\n * message never embeds a stack or environment values; production stack\n * disclosure decisions stay with the server layer.\n */\nexport class StreetFrameworkError extends Error {\n readonly context: DiagnosticContext | undefined;\n\n constructor(message: string, context?: DiagnosticContext) {\n super(`${message}${formatDiagnosticContext(context)}`);\n this.name = 'StreetFrameworkError';\n this.context = context ?? undefined;\n }\n}\n\n/** Build a `StreetFrameworkError` with the given context. */\nexport function frameworkError(\n message: string,\n context?: DiagnosticContext,\n): StreetFrameworkError {\n return new StreetFrameworkError(message, context);\n}\n\n/**\n * Route a diagnostic to a sink if it implements the matching level. Safe to\n * call with `undefined` — it simply does nothing, which is the default (no\n * logging) posture. Never throws even if the sink method does.\n */\nexport function reportDiagnostic(\n sink: DiagnosticSink | undefined,\n level: 'debug' | 'info' | 'warn' | 'error',\n message: string,\n context?: DiagnosticContext,\n): void {\n if (sink === undefined) return;\n const fn = sink[level];\n if (typeof fn !== 'function') return;\n try {\n fn.call(sink, message, context);\n } catch {\n // A misbehaving sink must never break the framework.\n }\n}\n\n/** A sink that forwards to a `console`-like object, one call per level. */\nexport function consoleDiagnosticSink(\n logger: Partial<Record<'debug' | 'info' | 'warn' | 'error', (msg: string) => void>> = console,\n): DiagnosticSink {\n return {\n debug: (m, c) => logger.debug?.(`${m}${formatDiagnosticContext(c)}`),\n info: (m, c) => logger.info?.(`${m}${formatDiagnosticContext(c)}`),\n warn: (m, c) => logger.warn?.(`${m}${formatDiagnosticContext(c)}`),\n error: (m, c) => logger.error?.(`${m}${formatDiagnosticContext(c)}`),\n };\n}\n","/**\n * Semantic Application Graph nodes.\n *\n * Every element in a StreetUI application is represented as a GraphNode.\n * Nodes form a tree: each has an optional parent and an ordered list of children.\n */\n\nimport { generateNodeId, type NodeId, type SemanticNodeType } from '@streetui/core';\n\n// ── Property values ───────────────────────────────────────────────────────────\n\nexport type PropValue =\n | string\n | number\n | boolean\n | null\n | undefined\n | string[]\n | number[]\n | Record<string, unknown>;\n\nexport type Props = Record<string, PropValue>;\n\n// ── Event descriptors ─────────────────────────────────────────────────────────\n\nexport interface EventDescriptor {\n readonly type: string;\n /** Reference key into the application's handler registry. */\n readonly handlerKey: string;\n}\n\n// ── State references ──────────────────────────────────────────────────────────\n\nexport interface StateRef {\n /** ID of the signal/store this node's property is bound to. */\n readonly signalId: string;\n /** The prop key on this node that is bound. */\n readonly propKey: string;\n}\n\n// ── The core graph node ───────────────────────────────────────────────────────\n\nexport interface GraphNodeData {\n readonly id: NodeId;\n readonly type: SemanticNodeType;\n readonly key: string | undefined;\n props: Props;\n events: EventDescriptor[];\n stateRefs: StateRef[];\n children: GraphNode[];\n parent: GraphNode | null;\n}\n\nexport class GraphNode implements GraphNodeData {\n readonly id: NodeId;\n readonly type: SemanticNodeType;\n readonly key: string | undefined;\n props: Props;\n events: EventDescriptor[];\n stateRefs: StateRef[];\n children: GraphNode[];\n parent: GraphNode | null;\n\n constructor(\n type: SemanticNodeType,\n options: {\n id?: NodeId;\n key?: string;\n props?: Props;\n events?: EventDescriptor[];\n stateRefs?: StateRef[];\n } = {},\n ) {\n this.type = type;\n this.id = options.id ?? generateNodeId(type);\n this.key = options.key;\n this.props = options.props ?? {};\n this.events = options.events ?? [];\n this.stateRefs = options.stateRefs ?? [];\n this.children = [];\n this.parent = null;\n }\n\n // ── Child management ────────────────────────────────────────────────────────\n\n appendChild(child: GraphNode): void {\n if (child.parent !== null) {\n child.parent.removeChild(child);\n }\n child.parent = this;\n this.children.push(child);\n }\n\n insertBefore(child: GraphNode, reference: GraphNode): void {\n const idx = this.children.indexOf(reference);\n if (idx === -1) {\n this.appendChild(child);\n return;\n }\n if (child.parent !== null) {\n child.parent.removeChild(child);\n }\n child.parent = this;\n this.children.splice(idx, 0, child);\n }\n\n removeChild(child: GraphNode): void {\n const idx = this.children.indexOf(child);\n if (idx === -1) return;\n this.children.splice(idx, 1);\n child.parent = null;\n }\n\n replaceChild(newChild: GraphNode, oldChild: GraphNode): void {\n const idx = this.children.indexOf(oldChild);\n if (idx === -1) {\n throw new Error(`GraphNode.replaceChild: oldChild is not a child of this node`);\n }\n if (newChild.parent !== null) {\n newChild.parent.removeChild(newChild);\n }\n oldChild.parent = null;\n newChild.parent = this;\n this.children.splice(idx, 1, newChild);\n }\n\n // ── Prop helpers ────────────────────────────────────────────────────────────\n\n setProp(key: string, value: PropValue): void {\n this.props = { ...this.props, [key]: value };\n }\n\n getProp<T extends PropValue = PropValue>(key: string): T | undefined {\n return this.props[key] as T | undefined;\n }\n\n // ── Event helpers ───────────────────────────────────────────────────────────\n\n addEvent(descriptor: EventDescriptor): void {\n this.events.push(descriptor);\n }\n\n removeEvent(type: string): void {\n this.events = this.events.filter(e => e.type !== type);\n }\n\n // ── Queries ─────────────────────────────────────────────────────────────────\n\n get isLeaf(): boolean {\n return this.children.length === 0;\n }\n\n get depth(): number {\n let d = 0;\n let node: GraphNode | null = this.parent;\n while (node !== null) {\n d++;\n node = node.parent;\n }\n return d;\n }\n\n get root(): GraphNode {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n let node: GraphNode = this;\n while (node.parent !== null) {\n node = node.parent;\n }\n return node;\n }\n\n /** Shallow clone — does not clone children. */\n shallowClone(): GraphNode {\n const opts: { key?: string; props: Props; events: EventDescriptor[]; stateRefs: StateRef[] } = {\n props: { ...this.props },\n events: [...this.events],\n stateRefs: [...this.stateRefs],\n };\n if (this.key !== undefined) opts.key = this.key;\n return new GraphNode(this.type, opts);\n }\n}\n","/**\n * The Semantic Application Graph.\n *\n * Holds the application root node and all its descendants.\n * Supports traversal, lookup by ID, validation, and serialization.\n */\n\nimport { type NodeId, DiagnosticCollector } from '@streetui/core';\nimport { GraphNode, type Props, type EventDescriptor } from './graph-node.js';\n\nexport interface ApplicationGraphOptions {\n readonly name: string;\n readonly version?: string;\n}\n\nexport interface HandlerFn {\n (...args: unknown[]): unknown;\n}\n\nexport class ApplicationGraph {\n readonly root: GraphNode;\n readonly name: string;\n readonly version: string;\n private readonly _nodeIndex: Map<NodeId, GraphNode> = new Map();\n /** Handler registry — maps handlerKey → actual function */\n readonly handlers: Map<string, HandlerFn> = new Map();\n\n constructor(options: ApplicationGraphOptions) {\n this.name = options.name;\n this.version = options.version ?? '0.0.1';\n this.root = new GraphNode('application', { props: { name: options.name } });\n this._nodeIndex.set(this.root.id, this.root);\n }\n\n // ── Node creation & attachment ────────────────────────────────────────────\n\n createNode(\n type: GraphNode['type'],\n options: { key?: string; props?: Props; parent?: GraphNode } = {},\n ): GraphNode {\n const nodeOpts: { key?: string; props?: Props } = {};\n if (options.key !== undefined) nodeOpts.key = options.key;\n if (options.props !== undefined) nodeOpts.props = options.props;\n const node = new GraphNode(type, nodeOpts);\n this._nodeIndex.set(node.id, node);\n if (options.parent !== undefined) {\n options.parent.appendChild(node);\n }\n return node;\n }\n\n attachNode(node: GraphNode, parent: GraphNode): void {\n this._nodeIndex.set(node.id, node);\n parent.appendChild(node);\n }\n\n detachNode(node: GraphNode): void {\n if (node.parent !== null) {\n node.parent.removeChild(node);\n }\n this._removeFromIndex(node);\n }\n\n private _removeFromIndex(node: GraphNode): void {\n this._nodeIndex.delete(node.id);\n this._unregisterNodeHandlers(node);\n for (const child of node.children) {\n this._removeFromIndex(child);\n }\n }\n\n /**\n * Remove every handler-registry entry owned by a single node. A node owns:\n * - one entry per event descriptor (its `handlerKey`),\n * - one `__signal__<signalId>` entry per state ref (signalIds are namespaced\n * by node id, so they are never shared between nodes), and\n * - a `__listbuild__<id>` entry if it is a reactive-list.\n * Called for every node in a detached subtree so removing list items (or\n * discarding freshly-built-but-unadopted item subtrees) leaves no stale\n * registrations behind.\n */\n private _unregisterNodeHandlers(node: GraphNode): void {\n for (const event of node.events) {\n this.handlers.delete(event.handlerKey);\n }\n for (const ref of node.stateRefs) {\n this.handlers.delete(`__signal__${ref.signalId}`);\n }\n this.handlers.delete(`__listbuild__${node.id}`);\n this.handlers.delete(`__listplan__${node.id}`);\n this.handlers.delete(`__overlay__${node.id}`);\n this.handlers.delete(`__component__${node.id}`);\n this.handlers.delete(`__transition__${node.id}`);\n }\n\n // ── Handler registry ──────────────────────────────────────────────────────\n\n registerHandler(key: string, fn: HandlerFn): void {\n this.handlers.set(key, fn);\n }\n\n getHandler(key: string): HandlerFn | undefined {\n return this.handlers.get(key);\n }\n\n /** True if a handler is currently registered under `key`. Inspection helper. */\n hasHandler(key: string): boolean {\n return this.handlers.has(key);\n }\n\n /** Number of currently-registered handlers. Inspection helper. */\n get handlerCount(): number {\n return this.handlers.size;\n }\n\n // ── Lookup ────────────────────────────────────────────────────────────────\n\n findById(id: NodeId): GraphNode | undefined {\n return this._nodeIndex.get(id);\n }\n\n findAll(predicate: (node: GraphNode) => boolean): GraphNode[] {\n const results: GraphNode[] = [];\n this._walk(this.root, node => {\n if (predicate(node)) results.push(node);\n });\n return results;\n }\n\n findByType(type: GraphNode['type']): GraphNode[] {\n return this.findAll(n => n.type === type);\n }\n\n // ── Traversal ─────────────────────────────────────────────────────────────\n\n walk(visitor: (node: GraphNode, depth: number) => void): void {\n this._walk(this.root, visitor, 0);\n }\n\n private _walk(\n node: GraphNode,\n visitor: (node: GraphNode, depth: number) => void,\n depth: number = 0,\n ): void {\n visitor(node, depth);\n for (const child of node.children) {\n this._walk(child, visitor, depth + 1);\n }\n }\n\n get nodeCount(): number {\n return this._nodeIndex.size;\n }\n\n // ── Validation ────────────────────────────────────────────────────────────\n\n validate(): DiagnosticCollector {\n const dc = new DiagnosticCollector();\n\n this.walk((node) => {\n // Validate event handler references exist\n for (const event of node.events) {\n if (!this.handlers.has(event.handlerKey)) {\n dc.warn(\n 'GRAPH_MISSING_HANDLER',\n `Node \"${node.id}\" references handler \"${event.handlerKey}\" which is not registered`,\n { nodeId: node.id },\n );\n }\n }\n\n // Validate page nodes are direct children of root\n if (node.type === 'page' && node.parent?.type !== 'application') {\n dc.error(\n 'GRAPH_PAGE_DEPTH',\n `Page node \"${node.id}\" must be a direct child of the application root`,\n { nodeId: node.id },\n );\n }\n });\n\n return dc;\n }\n\n // ── Serialization ─────────────────────────────────────────────────────────\n\n serialize(): SerializedGraph {\n return {\n name: this.name,\n version: this.version,\n root: this._serializeNode(this.root),\n };\n }\n\n private _serializeNode(node: GraphNode): SerializedNode {\n const result: SerializedNode = {\n id: node.id,\n type: node.type,\n key: node.key,\n props: node.props,\n events: node.events,\n stateRefs: node.stateRefs,\n children: node.children.map(c => this._serializeNode(c)),\n };\n return result;\n }\n}\n\nexport interface SerializedNode {\n readonly id: string;\n readonly type: string;\n readonly key: string | undefined;\n readonly props: Props;\n readonly events: EventDescriptor[];\n readonly stateRefs: unknown[];\n readonly children: SerializedNode[];\n}\n\nexport interface SerializedGraph {\n readonly name: string;\n readonly version: string;\n readonly root: SerializedNode;\n}\n","/**\n * Transition configuration (§2, §4).\n *\n * A `TransitionConfig` is a pure, declarative description of a CSS class-based\n * enter/leave transition — the engine choice for this milestone. It contains NO\n * DOM references, NO timers and NO browser-only APIs, so it is safe to build on\n * the server (where it is simply ignored — see the renderer's SSR guard) and to\n * carry on a graph handler (`__transition__<nodeId>`) alongside the existing\n * `__overlay__`/`__component__` descriptors.\n *\n * The class model follows the widely-understood enter/leave convention:\n *\n * enter: [enterActive (+ enter) whole phase] · enterFrom (start) → enterTo (end)\n * leave: [leaveActive (+ leave) whole phase] · leaveFrom (start) → leaveTo (end)\n *\n * `name` is a shorthand that expands to `${name}-enter-from`,\n * `${name}-enter-active`, `${name}-enter-to` and the leave equivalents; explicit\n * class fields override the derived ones. Because the classes are just strings,\n * SSR output is deterministic (no class is applied on the server at all — the\n * controller is browser-only), satisfying §4/§21.\n */\nexport interface TransitionConfig {\n /** Shorthand base: expands to `${name}-enter-from`, `${name}-enter-active`, … */\n readonly name?: string;\n /** Class(es) present for the whole enter phase (in addition to `enterActive`). */\n readonly enter?: string;\n /** Class(es) applied at the start of enter, removed on the next frame. */\n readonly enterFrom?: string;\n /** Class(es) present for the whole enter phase (where the CSS `transition` lives). */\n readonly enterActive?: string;\n /** Class(es) added on the next frame, removed when enter completes. */\n readonly enterTo?: string;\n /** Class(es) present for the whole leave phase (in addition to `leaveActive`). */\n readonly leave?: string;\n /** Class(es) applied at the start of leave, removed on the next frame. */\n readonly leaveFrom?: string;\n /** Class(es) present for the whole leave phase (where the CSS `transition` lives). */\n readonly leaveActive?: string;\n /** Class(es) added on the next frame, removed when leave completes. */\n readonly leaveTo?: string;\n /**\n * Also animate the very first appearance (initial mount). Hydration never\n * animates appear (the DOM is already present and correct); this only affects\n * fresh browser mounts. Defaults to false.\n */\n readonly appear?: boolean;\n /**\n * Fallback completion timeout in milliseconds. A transition normally completes\n * on the element's `transitionend`/`animationend`. This timeout is the safety\n * net for (a) transitions that fire no such event and (b) test DOMs like\n * happy-dom that dispatch no transition events at all — making tests\n * deterministic without a real browser (§24). Defaults to 1000. Use a small\n * value (or 0 → next macrotask) in tests.\n */\n readonly duration?: number;\n}\n\n/**\n * The resolved, ready-to-apply form of a {@link TransitionConfig}: each phase's\n * classes are pre-split into arrays so the controller applies/removes them with\n * no per-run string parsing. Produced once by {@link resolveTransition} at wire\n * time (browser only).\n */\nexport interface ResolvedTransition {\n /** enter classes present for the whole phase (base `enter` + `enterActive`). */\n readonly enterActive: readonly string[];\n /** enter start classes (removed next frame). */\n readonly enterFrom: readonly string[];\n /** enter end classes (added next frame). */\n readonly enterTo: readonly string[];\n readonly leaveActive: readonly string[];\n readonly leaveFrom: readonly string[];\n readonly leaveTo: readonly string[];\n readonly appear: boolean;\n readonly duration: number;\n}\n\n/** Split a class string on whitespace into a de-duplicated array (empty-safe). */\nfunction classes(value: string | undefined): string[] {\n if (value === undefined) return [];\n const out: string[] = [];\n for (const token of value.split(/\\s+/)) {\n if (token.length > 0 && !out.includes(token)) out.push(token);\n }\n return out;\n}\n\n/** Merge two class arrays, preserving order and dropping duplicates. */\nfunction merge(a: string[], b: string[]): string[] {\n const out = [...a];\n for (const token of b) if (!out.includes(token)) out.push(token);\n return out;\n}\n\n/**\n * Resolve a {@link TransitionConfig} into applied class arrays. The `name`\n * shorthand supplies defaults; any explicit field overrides the derived class\n * for that phase-slot (still merged with `enter`/`leave` base classes).\n */\nexport function resolveTransition(config: TransitionConfig): ResolvedTransition {\n const n = config.name;\n const enterActive = merge(\n classes(config.enter),\n classes(config.enterActive ?? (n !== undefined ? `${n}-enter-active` : undefined)),\n );\n const leaveActive = merge(\n classes(config.leave),\n classes(config.leaveActive ?? (n !== undefined ? `${n}-leave-active` : undefined)),\n );\n return {\n enterActive,\n enterFrom: classes(config.enterFrom ?? (n !== undefined ? `${n}-enter-from` : undefined)),\n enterTo: classes(config.enterTo ?? (n !== undefined ? `${n}-enter-to` : undefined)),\n leaveActive,\n leaveFrom: classes(config.leaveFrom ?? (n !== undefined ? `${n}-leave-from` : undefined)),\n leaveTo: classes(config.leaveTo ?? (n !== undefined ? `${n}-leave-to` : undefined)),\n appear: config.appear ?? false,\n duration: config.duration ?? 1000,\n };\n}\n\n/** Runtime brand check for a transition descriptor value. */\nexport function isTransitionConfig(value: unknown): value is TransitionConfig {\n if (value === null || typeof value !== 'object') return false;\n const o = value as Record<string, unknown>;\n // A config is meaningful only if it carries at least one class source.\n return (\n typeof o['name'] === 'string' ||\n typeof o['enter'] === 'string' ||\n typeof o['enterActive'] === 'string' ||\n typeof o['enterFrom'] === 'string' ||\n typeof o['leave'] === 'string' ||\n typeof o['leaveActive'] === 'string' ||\n typeof o['leaveFrom'] === 'string'\n );\n}\n","/**\n * DSL builder implementations.\n *\n * Each builder wraps a GraphNode and provides the fluent API\n * for constructing the Semantic Application Graph via the DSL.\n *\n * Builders do NOT render anything — they only build the graph.\n */\n\nimport { ApplicationGraph, GraphNode, type Props } from '@streetui/graph';\nimport type {\n ContentDSL,\n ContainerDSL,\n SectionDSL,\n PageDSL,\n FormDSL,\n ListDSL,\n AppDSL,\n HeadingOptions,\n TextOptions,\n ButtonOptions,\n InputOptions,\n LinkOptions,\n ImageOptions,\n ContainerOptions,\n SectionOptions,\n FormOptions,\n ListOptions,\n PortalOptions,\n OverlayOptions,\n A11yOptions,\n Bindable,\n BindableText,\n TextValue,\n ErrorBoundaryOptions,\n ErrorSource,\n PageBuilder,\n SectionBuilder,\n ContainerBuilder as ContainerBuilderFn,\n FormBuilder,\n ListBuilder,\n} from './dsl-types.js';\nimport type {\n ComponentContext,\n ComponentDefinition,\n ComponentRender,\n} from './component.js';\nimport type { TransitionConfig } from './transition.js';\nimport { resolveTransition } from './transition.js';\nimport type { WhenOptions } from './dsl-types.js';\nimport { signal, derived, effect, type Signal, type ReadonlySignal } from '@streetui/state';\n\n/**\n * A single reactive-list reconciliation descriptor (spec §15).\n *\n * Emitted by the `__listplan__<nodeId>` handler on every list change. `key` is\n * the item's identity-only reconciliation key (cheap to compute); `item` is the\n * source value *reference* used for identity short-circuiting; `sig()` computes\n * the content signature on demand (only when the reference changed); `build()`\n * materialises the full item subtree on demand (only for new/changed rows).\n */\nexport interface ListPlanEntry {\n readonly key: string;\n readonly item: unknown;\n readonly sig: () => string;\n readonly build: () => GraphNode;\n}\n\n// ── Signal helpers ────────────────────────────────────────────────────────────\n\nfunction isSignal(v: unknown): v is Signal<unknown> | ReadonlySignal<unknown> {\n return (\n v !== null &&\n typeof v === 'object' &&\n typeof (v as Record<string, unknown>)['get'] === 'function' &&\n typeof (v as Record<string, unknown>)['subscribe'] === 'function'\n );\n}\n\n/** Register a signal binding on the node and return the current static value. */\nfunction bindValue<T>(\n graph: ApplicationGraph,\n node: GraphNode,\n propKey: string,\n value: Bindable<T>,\n): T {\n if (isSignal(value)) {\n const signalId = `${node.id}:${propKey}`;\n node.stateRefs.push({ signalId, propKey });\n graph.registerHandler(`__signal__${signalId}`, value as unknown as () => unknown);\n return (value as ReadonlySignal<T>).peek();\n }\n return value as T;\n}\n\n// ── Helper to build Props from ContainerOptions ───────────────────────────────\n\n/**\n * Copy accessibility options onto a props bag as their corresponding HTML/ARIA\n * attribute names. Values are written as strings (booleans become \"true\"/\"false\"\n * rather than being dropped) so ARIA state attributes render literally. These\n * flow to the DOM via the renderer's generic attribute pass — no ARIA-specific\n * renderer code is involved.\n */\nfunction applyA11yProps(props: Props, options: A11yOptions): void {\n if (options.role !== undefined) props['role'] = options.role;\n if (options.tabIndex !== undefined) props['tabindex'] = String(options.tabIndex);\n if (options.ariaLabel !== undefined) props['aria-label'] = options.ariaLabel;\n if (options.ariaLabelledBy !== undefined) props['aria-labelledby'] = options.ariaLabelledBy;\n if (options.ariaDescribedBy !== undefined) props['aria-describedby'] = options.ariaDescribedBy;\n if (options.ariaExpanded !== undefined) props['aria-expanded'] = String(options.ariaExpanded);\n if (options.ariaControls !== undefined) props['aria-controls'] = options.ariaControls;\n if (options.ariaHidden !== undefined) props['aria-hidden'] = String(options.ariaHidden);\n if (options.ariaLive !== undefined) props['aria-live'] = options.ariaLive;\n if (options.ariaCurrent !== undefined) props['aria-current'] = String(options.ariaCurrent);\n if (options.ariaInvalid !== undefined) props['aria-invalid'] = String(options.ariaInvalid);\n if (options.ariaRequired !== undefined) props['aria-required'] = String(options.ariaRequired);\n if (options.ariaModal !== undefined) props['aria-modal'] = String(options.ariaModal);\n if (options.ariaOwns !== undefined) props['aria-owns'] = options.ariaOwns;\n if (options.ariaActiveDescendant !== undefined) props['aria-activedescendant'] = options.ariaActiveDescendant;\n if (options.ariaHasPopup !== undefined) props['aria-haspopup'] = String(options.ariaHasPopup);\n if (options.ariaSelected !== undefined) props['aria-selected'] = String(options.ariaSelected);\n}\n\n/**\n * Register a `__transition__<nodeId>` descriptor for an element that opts into a\n * CSS class-based enter/leave transition (§2). Mirrors the `__overlay__` /\n * `__component__` handler pattern: the renderer reads it (browser only) to run\n * enter on mount and to defer removal/dispose until leave completes. Pure config\n * — no DOM, no timers — so it is inert on the server and pruned by\n * `graph._unregisterNodeHandlers` (§23). A no-op when no transition is supplied.\n */\nfunction registerTransition(\n graph: ApplicationGraph,\n node: GraphNode,\n config: TransitionConfig | undefined,\n): void {\n if (config === undefined) return;\n // Resolve to the pre-split class arrays at wire time so the renderer's\n // controller consumes a plain `ResolvedTransition` and never re-parses class\n // strings per run — and so the renderer needs no compile-time dependency on\n // this DSL package (it reads the descriptor structurally, exactly like\n // `__overlay__`/`__component__`).\n const resolved = resolveTransition(config);\n graph.registerHandler(\n `__transition__${node.id}`,\n (() => resolved) as unknown as () => unknown,\n );\n}\n\nfunction containerProps(options: ContainerOptions): Props {\n const props: Props = {};\n if (options.class !== undefined) props['class'] = options.class;\n if (options.id !== undefined) props['id'] = options.id;\n if (options.key !== undefined) props['key'] = options.key;\n applyA11yProps(props, options);\n return props;\n}\n\n// ── Reactive-list item keying ──────────────────────────────────────────────────\n//\n// The `listOf` DSL signature does not take an explicit key extractor, so we\n// derive a stable reconciliation key from each item. The key combines an\n// *identity* part (so reordering the same items reuses their DOM nodes) with a\n// *value signature* (so an item whose data changed is treated as a fresh node\n// and re-rendered rather than silently kept stale by the shallow reconciler).\n\nfunction itemIdentity(item: unknown, index: number): string {\n if (item !== null && typeof item === 'object') {\n const obj = item as Record<string, unknown>;\n if ('id' in obj) return `id:${String(obj['id'])}`;\n if ('key' in obj) return `key:${String(obj['key'])}`;\n return `idx:${index}`;\n }\n return `val:${String(item)}`;\n}\n\nfunction itemValueSignature(item: unknown): string {\n try {\n return JSON.stringify(item) ?? String(item);\n } catch {\n return String(item);\n }\n}\n\n/** Content signature used to detect in-place data changes of a stable item. */\nexport function reactiveListItemSignature(item: unknown): string {\n return itemValueSignature(item);\n}\n\n/** Stable, identity-only reconciliation key for a reactive-list item. */\nexport function reactiveListItemKey(item: unknown, index: number): string {\n return itemIdentity(item, index);\n}\n\n// ── Overlay kind configuration ──────────────────────────────────────────────────\n//\n// Each overlay builder (dialog/popover/tooltip/dropdown/toast) is the same\n// portal + `when(open, …)` panel + focus/keyboard behavior, differing only in\n// ARIA role, modality, whether it takes focus, and its escape/restore defaults.\n// This table captures those differences; `_overlay` does the shared assembly.\n\ninterface OverlayKindConfig {\n /** Default ARIA role for the panel. */\n readonly role: string;\n /** Trap + contain focus (modal semantics). */\n readonly modal: boolean;\n /** Move focus into the panel when it opens. */\n readonly takesFocus: boolean;\n /** Wire arrow/Home/End/Enter/Space roving-focus navigation (role=\"menu\"). */\n readonly menu?: boolean;\n /** Emit `aria-modal=\"true\"` on the panel. */\n readonly ariaModal: boolean;\n /** Emit an `aria-live` region on the panel (announcements). */\n readonly ariaLive?: 'polite' | 'assertive';\n /** Default for `closeOnEscape` when the caller does not specify it. */\n readonly defaultCloseOnEscape: boolean;\n /** Default for `restoreFocus` when the caller does not specify it. */\n readonly defaultRestoreFocus: boolean;\n}\n\nconst OVERLAY_KINDS = {\n dialog: {\n role: 'dialog', modal: true, takesFocus: true, ariaModal: true,\n defaultCloseOnEscape: true, defaultRestoreFocus: true,\n },\n popover: {\n role: 'dialog', modal: false, takesFocus: true, ariaModal: false,\n defaultCloseOnEscape: true, defaultRestoreFocus: true,\n },\n tooltip: {\n role: 'tooltip', modal: false, takesFocus: false, ariaModal: false,\n defaultCloseOnEscape: false, defaultRestoreFocus: false,\n },\n dropdown: {\n role: 'menu', modal: false, takesFocus: true, menu: true, ariaModal: false,\n defaultCloseOnEscape: true, defaultRestoreFocus: true,\n },\n toast: {\n role: 'status', modal: false, takesFocus: false, ariaModal: false,\n ariaLive: 'polite', defaultCloseOnEscape: false, defaultRestoreFocus: false,\n },\n} as const satisfies Record<string, OverlayKindConfig>;\n\n/** The opaque descriptor the renderer reads from `__overlay__<portalId>`. */\ninterface OverlayBehaviorDescriptor {\n readonly open: ReadonlySignal<boolean>;\n readonly modal: boolean;\n readonly takesFocus: boolean;\n readonly menu: boolean;\n readonly closeOnEscape: boolean;\n readonly restoreFocus: boolean;\n readonly initialFocusId?: string;\n readonly onClose?: () => void;\n}\n\n// ── Base content builder ──────────────────────────────────────────────────────\n\nclass ContentBuilderBase implements ContentDSL {\n constructor(\n protected readonly _node: GraphNode,\n protected readonly _graph: ApplicationGraph,\n ) {}\n\n heading(text: BindableText, options: HeadingOptions = {}): void {\n const props: Props = { level: options.level ?? 1 };\n if (options.class !== undefined) props['class'] = options.class;\n if (options.id !== undefined) props['id'] = options.id;\n applyA11yProps(props, options);\n const node = this._graph.createNode('heading', { parent: this._node, props });\n const resolved = bindValue<TextValue>(this._graph, node, 'text', text);\n node.setProp('text', resolved);\n }\n\n text(content: BindableText, options: TextOptions = {}): void {\n const props: Props = {};\n if (options.class !== undefined) props['class'] = options.class;\n if (options.id !== undefined) props['id'] = options.id;\n applyA11yProps(props, options);\n const node = this._graph.createNode('text', { parent: this._node, props });\n const resolved = bindValue<TextValue>(this._graph, node, 'text', content);\n node.setProp('text', resolved);\n }\n\n button(label: BindableText, options: ButtonOptions = {}): void {\n const props: Props = {};\n if (options.class !== undefined) props['class'] = options.class;\n if (options.id !== undefined) props['id'] = options.id;\n applyA11yProps(props, options);\n const node = this._graph.createNode('button', { parent: this._node, props });\n const resolved = bindValue<TextValue>(this._graph, node, 'label', label);\n node.setProp('label', resolved);\n if (options.disabled !== undefined) {\n const resolvedDisabled = bindValue(this._graph, node, 'disabled', options.disabled);\n node.setProp('disabled', resolvedDisabled);\n }\n if (options.onClick !== undefined) {\n const handlerKey = `click:${node.id}`;\n this._graph.registerHandler(handlerKey, options.onClick as () => unknown);\n node.addEvent({ type: 'click', handlerKey });\n }\n }\n\n input(options: InputOptions = {}): void {\n const props: Props = {};\n props['inputType'] = options.type ?? 'text';\n if (options.placeholder !== undefined) props['placeholder'] = options.placeholder;\n if (options.class !== undefined) props['class'] = options.class;\n if (options.id !== undefined) props['id'] = options.id;\n applyA11yProps(props, options);\n const nodeOpts: { key?: string; props: Props; parent: GraphNode } = {\n props,\n parent: this._node,\n };\n if (options.id !== undefined) nodeOpts.key = options.id;\n const node = this._graph.createNode('input', nodeOpts);\n\n // Two-way `bind` expands to a value binding + an input write-back. The type\n // system (BoundInputOptions vs ControlledInputOptions) guarantees `bind` is\n // never combined with explicit `value`/`onInput`, so there is no ambiguity.\n const bindSignal = options.bind;\n const valueBindable: Bindable<string> | undefined =\n bindSignal !== undefined ? bindSignal : options.value;\n const inputHandler: ((value: string) => void) | undefined =\n bindSignal !== undefined ? (v: string) => bindSignal.set(v) : options.onInput;\n\n if (valueBindable !== undefined) {\n const resolved = bindValue(this._graph, node, 'value', valueBindable);\n node.setProp('value', resolved);\n }\n if (options.disabled !== undefined) {\n const resolved = bindValue(this._graph, node, 'disabled', options.disabled);\n node.setProp('disabled', resolved);\n }\n if (inputHandler !== undefined) {\n const handlerKey = `input:${node.id}`;\n this._graph.registerHandler(handlerKey, inputHandler as () => unknown);\n node.addEvent({ type: 'input', handlerKey });\n }\n if (options.onChange !== undefined) {\n const handlerKey = `change:${node.id}`;\n this._graph.registerHandler(handlerKey, options.onChange as () => unknown);\n node.addEvent({ type: 'change', handlerKey });\n }\n }\n\n image(options: ImageOptions): void {\n const props: Props = {\n src: options.src,\n alt: options.alt,\n };\n if (options.width !== undefined) props['width'] = options.width;\n if (options.height !== undefined) props['height'] = options.height;\n if (options.class !== undefined) props['class'] = options.class;\n if (options.id !== undefined) props['id'] = options.id;\n applyA11yProps(props, options);\n const nodeOpts: { key?: string; props: Props; parent: GraphNode } = {\n props,\n parent: this._node,\n };\n if (options.id !== undefined) nodeOpts.key = options.id;\n this._graph.createNode('image', nodeOpts);\n }\n\n link(label: BindableText, options: LinkOptions): void {\n const props: Props = {\n href: options.href,\n external: options.external ?? false,\n };\n if (options.class !== undefined) props['class'] = options.class;\n if (options.id !== undefined) props['id'] = options.id;\n applyA11yProps(props, options);\n const node = this._graph.createNode('link', { parent: this._node, props });\n const resolved = bindValue<TextValue>(this._graph, node, 'label', label);\n node.setProp('label', resolved);\n if (options.onClick !== undefined) {\n const handlerKey = `click:${node.id}`;\n this._graph.registerHandler(handlerKey, options.onClick as () => unknown);\n node.addEvent({ type: 'click', handlerKey });\n }\n }\n}\n\n// ── Container builder ─────────────────────────────────────────────────────────\n\nclass ContainerBuilderBase extends ContentBuilderBase implements ContainerDSL {\n section(key: string, builder: SectionBuilder, options: SectionOptions = {}): void {\n const node = this._graph.createNode('section', {\n key,\n parent: this._node,\n props: containerProps(options),\n });\n registerTransition(this._graph, node, options.transition);\n builder(new SectionBuilderImpl(node, this._graph));\n }\n\n container(key: string, builder: ContainerBuilderFn, options: ContainerOptions = {}): void {\n const node = this._graph.createNode('container', {\n key,\n parent: this._node,\n props: containerProps(options),\n });\n registerTransition(this._graph, node, options.transition);\n builder(new ContainerBuilderImpl(node, this._graph));\n }\n\n list(key: string, builder: ListBuilder, options: ListOptions = {}): void {\n const node = this._graph.createNode('list', {\n key,\n parent: this._node,\n props: containerProps(options),\n });\n registerTransition(this._graph, node, options.transition);\n builder(new ListBuilderImpl(node, this._graph));\n }\n\n listOf<T>(\n key: string,\n items: Signal<T[]> | ReadonlySignal<T[]>,\n renderItem: (item: T, index: number, content: ContentDSL) => void,\n options: ListOptions = {},\n ): void {\n const graph = this._graph;\n const node = graph.createNode('reactive-list', {\n key,\n parent: this._node,\n props: containerProps(options),\n });\n registerTransition(graph, node, options.transition);\n\n // Register the driving signal so the runtime/renderer can subscribe to it.\n const signalId = `${node.id}:items`;\n node.stateRefs.push({ signalId, propKey: 'items' });\n graph.registerHandler(`__signal__${signalId}`, items as unknown as () => unknown);\n\n // Build a single detached list-item subtree for one item. The item's\n // reconciliation `key` is identity-only, and its value signature is stored\n // in the internal `_sig` prop so the renderer can detect (and apply a\n // targeted update for) a data change on an item whose identity is stable.\n const buildItem = (item: T, index: number): GraphNode => {\n const itemKey = reactiveListItemKey(item, index);\n const itemNode = graph.createNode('list-item', {\n key: itemKey,\n // `_item` records the source item *reference* so the reconciler can\n // short-circuit unchanged rows by identity (no signature hashing); `_sig`\n // is the content signature used to detect an in-place data change when the\n // reference differs. Both are internal metadata (leading `_`) and never\n // reach the DOM.\n props: {\n key: itemKey,\n _sig: reactiveListItemSignature(item),\n // The item reference is stored as opaque internal metadata (never\n // rendered); cast through `unknown` since `T` is not a `PropValue`.\n _item: item as unknown as Props[string],\n },\n });\n renderItem(item, index, new ContainerBuilderImpl(itemNode, graph));\n // Per-item enter/leave transition (§7). Registered on every item node so a\n // freshly-built row (append/prepend/change) carries it; keyed identity is\n // unaffected because the transition descriptor is keyed by node id and the\n // row's reconciliation key is derived separately.\n registerTransition(graph, itemNode, options.itemTransition);\n return itemNode;\n };\n\n // Lazy reconciliation plan (spec §15 — the measured keyed-list hot path).\n //\n // Instead of eagerly rebuilding all N item GraphNodes (and hashing every item\n // with JSON.stringify) on *every* emission — the dominant cost of the old\n // `buildAll` path — the renderer receives lightweight descriptors and only\n // materialises a subtree for rows that are genuinely new or whose data\n // actually changed. `key` is cheap (identity only); `sig()` and `build()` are\n // thunks the reconciler calls on demand.\n const buildPlan = (raw: unknown): ListPlanEntry[] => {\n const arr = Array.isArray(raw) ? (raw as T[]) : [];\n const plan: ListPlanEntry[] = new Array(arr.length);\n for (let i = 0; i < arr.length; i++) {\n const item = arr[i]!;\n const index = i;\n plan[i] = {\n key: reactiveListItemKey(item, index),\n item,\n sig: () => reactiveListItemSignature(item),\n build: () => buildItem(item, index),\n };\n }\n return plan;\n };\n graph.registerHandler(`__listplan__${node.id}`, buildPlan as unknown as () => unknown);\n\n // Build the initial children into the graph so the first mount renders them.\n const current = isSignal(items)\n ? (items as ReadonlySignal<T[]>).peek()\n : (items as unknown as T[]);\n const initial = Array.isArray(current) ? current : [];\n initial.forEach((item, i) => {\n node.appendChild(buildItem(item, i));\n });\n }\n\n form(key: string, builder: FormBuilder, options: FormOptions = {}): void {\n const props: Props = containerProps(options);\n const node = this._graph.createNode('form', {\n key,\n parent: this._node,\n props,\n });\n registerTransition(this._graph, node, options.transition);\n if (options.onSubmit !== undefined) {\n const handlerKey = `submit:${node.id}`;\n this._graph.registerHandler(handlerKey, options.onSubmit as () => unknown);\n node.addEvent({ type: 'submit', handlerKey });\n }\n builder(new FormBuilderImpl(node, this._graph));\n }\n\n when(\n condition: Bindable<boolean>,\n builder: ContainerBuilderFn,\n elseBuilder?: ContainerBuilderFn,\n options: WhenOptions = {},\n ): void {\n const graph = this._graph;\n // A dedicated 'conditional' node reuses the reactive-list reconciliation\n // machinery (same signal subscription + keyed reconcile) but renders as a\n // neutral <div> rather than a <ul>. It holds zero or one child branch.\n const node = graph.createNode('conditional', {\n parent: this._node,\n props: containerProps({}),\n });\n\n // A transition on a `when` applies to whichever branch is mounted/removed\n // (§2). `appear` promotes the transition to a config that also animates the\n // branch present on the very first mount; the renderer distinguishes appear\n // from a reactive enter via the descriptor's `appear` flag.\n const branchTransition: TransitionConfig | undefined =\n options.transition !== undefined && options.appear === true\n ? { ...options.transition, appear: true }\n : options.transition;\n\n // Build the active branch as a single keyed container. Distinct keys for the\n // then/else branches make a flip a clean swap under the keyed reconciler.\n const buildBranch = (build: ContainerBuilderFn, tag: 'then' | 'else'): GraphNode => {\n const branchKey = `when-${tag}:${node.id}`;\n const branch = graph.createNode('container', {\n key: branchKey,\n props: { key: branchKey },\n });\n registerTransition(graph, branch, branchTransition);\n build(new ContainerBuilderImpl(branch, graph));\n return branch;\n };\n\n const buildAll = (raw: unknown): GraphNode[] => {\n if (raw) return [buildBranch(builder, 'then')];\n return elseBuilder !== undefined ? [buildBranch(elseBuilder, 'else')] : [];\n };\n\n if (isSignal(condition)) {\n const signalId = `${node.id}:items`;\n node.stateRefs.push({ signalId, propKey: 'items' });\n graph.registerHandler(`__signal__${signalId}`, condition as unknown as () => unknown);\n graph.registerHandler(`__listbuild__${node.id}`, buildAll as unknown as () => unknown);\n const current = (condition as ReadonlySignal<boolean>).peek();\n for (const child of buildAll(current)) node.appendChild(child);\n } else {\n // Static condition — resolve once at build time, no reactive wiring.\n for (const child of buildAll(condition)) node.appendChild(child);\n }\n }\n\n errorBoundary(\n id: string,\n builder: ContainerBuilderFn,\n options: ErrorBoundaryOptions,\n ): void {\n // Normalise the observed error source(s) into an array.\n const sources: ErrorSource[] =\n options.source === undefined\n ? []\n : Array.isArray(options.source)\n ? [...options.source]\n : [options.source];\n\n // The boundary's own captured error (from a synchronous build throw) and a\n // retry nonce that forces a re-evaluation even when the boolean is unchanged.\n const localError = signal<unknown>(undefined);\n const retryNonce = signal<number>(0);\n\n const readError = (): unknown => {\n const local = localError.peek();\n if (local !== undefined && local !== null) return local;\n for (const s of sources) {\n const e = s.peek();\n if (e !== undefined && e !== null) return e;\n }\n return undefined;\n };\n\n // Reactive condition: true while an error is present. Reads every input so a\n // change in any source (or a retry) re-runs the conditional.\n const hasError = derived<boolean>(() => {\n retryNonce.get();\n localError.get();\n for (const s of sources) s.get();\n return readError() !== undefined;\n });\n\n const retry = (): void => {\n localError.set(undefined);\n options.onRetry?.();\n // Force the body branch to re-attempt even if no observed value changed.\n retryNonce.update((n) => n + 1);\n };\n\n // Wrap in a container so the whole boundary is addressable and disposes as a\n // unit. `when` provides the reactive body↔fallback swap (and its cleanup).\n this.container(id, (c) => {\n c.when(\n hasError,\n // Error state → fallback.\n (fb) => options.fallback(fb, readError(), retry),\n // Healthy state → body, guarded against synchronous build throws.\n (body) => {\n try {\n builder(body);\n } catch (err) {\n // Surface the throw as the boundary's error on the next microtask\n // (deferred to avoid re-entrant reconciliation during this build).\n queueMicrotask(() => localError.set(err));\n }\n },\n );\n }, { id });\n }\n\n // ── Portals & overlays ──────────────────────────────────────────────────────\n\n portal(key: string, builder: ContainerBuilderFn, options: PortalOptions = {}): void {\n const node = this._graph.createNode('portal', {\n key,\n parent: this._node,\n props: containerProps(options),\n });\n builder(new ContainerBuilderImpl(node, this._graph));\n }\n\n /**\n * Shared assembly for every overlay kind: a `portal` node whose single child\n * is a `when(open, panel)` conditional. The panel container carries the\n * kind's ARIA semantics; `builder` fills it. An `__overlay__<portalId>`\n * descriptor is registered so the renderer wires focus/keyboard behavior to\n * the same `open` signal that drives the panel. Reuses existing primitives\n * (portal + when + container) — no new render path.\n */\n private _overlay(\n kind: OverlayKindConfig,\n key: string,\n options: OverlayOptions,\n builder: ContainerBuilderFn,\n ): void {\n const graph = this._graph;\n const portalNode = graph.createNode('portal', {\n key,\n parent: this._node,\n props: { key },\n });\n\n // Resolve `open` to a signal we can both bind (drives the panel's `when`)\n // and hand to the renderer (drives focus behavior). A literal is wrapped so\n // the panel still mounts/unmounts through the same reactive path.\n const openBindable = options.open;\n const openSignal: ReadonlySignal<boolean> = isSignal(openBindable)\n ? (openBindable as ReadonlySignal<boolean>)\n : signal(openBindable as boolean);\n\n // Panel a11y semantics (kind defaults, overridable via options).\n const panelOptions: ContainerOptions = {\n role: options.role ?? kind.role,\n ...(kind.ariaModal ? { ariaModal: true } : {}),\n ...(kind.ariaLive !== undefined ? { ariaLive: kind.ariaLive } : {}),\n ...(options.class !== undefined ? { class: options.class } : {}),\n ...(options.ariaLabel !== undefined ? { ariaLabel: options.ariaLabel } : {}),\n ...(options.ariaLabelledBy !== undefined ? { ariaLabelledBy: options.ariaLabelledBy } : {}),\n ...(options.ariaDescribedBy !== undefined ? { ariaDescribedBy: options.ariaDescribedBy } : {}),\n };\n\n const portalBuilder = new ContainerBuilderImpl(portalNode, graph);\n portalBuilder.when(\n openSignal,\n (panelHost) => {\n panelHost.container(`${key}__panel`, builder, panelOptions);\n },\n undefined,\n // Overlay open/close rides the panel's `when`; a transition animates the\n // panel in on open and — via the reconciler's deferred-leave — plays the\n // leave before the panel is removed (§10). Focus is restored at close-\n // request time (see wireOverlayBehavior), so it never stays trapped inside\n // a panel that is animating away.\n options.transition !== undefined ? { transition: options.transition } : {},\n );\n\n const descriptor: OverlayBehaviorDescriptor = {\n open: openSignal,\n modal: kind.modal,\n takesFocus: kind.takesFocus,\n menu: kind.menu ?? false,\n closeOnEscape: options.closeOnEscape ?? kind.defaultCloseOnEscape,\n restoreFocus: options.restoreFocus ?? kind.defaultRestoreFocus,\n ...(options.initialFocusId !== undefined ? { initialFocusId: options.initialFocusId } : {}),\n ...(options.onClose !== undefined ? { onClose: options.onClose } : {}),\n };\n graph.registerHandler(\n `__overlay__${portalNode.id}`,\n (() => descriptor) as unknown as () => unknown,\n );\n }\n\n dialog(key: string, options: OverlayOptions, builder: ContainerBuilderFn): void {\n this._overlay(OVERLAY_KINDS.dialog, key, options, builder);\n }\n\n popover(key: string, options: OverlayOptions, builder: ContainerBuilderFn): void {\n this._overlay(OVERLAY_KINDS.popover, key, options, builder);\n }\n\n tooltip(key: string, options: OverlayOptions, builder: ContainerBuilderFn): void {\n this._overlay(OVERLAY_KINDS.tooltip, key, options, builder);\n }\n\n dropdown(key: string, options: OverlayOptions, builder: ContainerBuilderFn): void {\n this._overlay(OVERLAY_KINDS.dropdown, key, options, builder);\n }\n\n toast(key: string, options: OverlayOptions, builder: ContainerBuilderFn): void {\n this._overlay(OVERLAY_KINDS.toast, key, options, builder);\n }\n\n // ── Components ────────────────────────────────────────────────────────────\n\n /**\n * Instantiate a reusable component (§3–§9). Creates a `'component'` node\n * (rendered as a `<div>` wrapper — preserves the one-node/one-element\n * positional-hydration invariant), then runs `def.setup(props, ctx)`\n * synchronously to obtain the render function and fills the component's own\n * container scope with it — structurally identical to `container`/\n * `errorBoundary`. Cleanups the setup registers via `ctx.effect`/\n * `ctx.onCleanup` are collected into a closure and exposed to the renderer\n * through a `__component__<id>` handler (mirroring `__overlay__`); the mount/\n * hydrate paths read it and route each into `NodeInstance.trackCleanup`, so\n * teardown runs (children-first) when the component leaves the graph.\n *\n * `setup` runs once per instance here at build time. When this component sits\n * inside a keyed list / conditional, a rebuild disposes the old instance\n * (running its cleanups + pruning its `__component__` entry) and re-runs this\n * method for the new node — so re-invocation is safe and leak-free.\n */\n component<P>(\n key: string,\n def: ComponentDefinition<P>,\n props: P,\n children?: ContainerBuilderFn,\n ): void {\n const graph = this._graph;\n const node = graph.createNode('component', {\n key,\n parent: this._node,\n // `data-streetui-component` is a non-underscore prop, so it reaches the\n // DOM as an attribute and is visible to DevTools (§21) — unlike the\n // internal `_`-prefixed metadata the renderer hides.\n props: { key, 'data-streetui-component': def.name },\n });\n\n // Ownership collector: every teardown the setup registers lands here and is\n // handed to the NodeInstance at mount.\n const cleanups: Array<() => void> = [];\n const ctx: ComponentContext = {\n key,\n onCleanup(fn: () => void): void {\n cleanups.push(fn);\n },\n effect(fn: () => void | (() => void)): void {\n // Reuse the EXISTING reactive engine (§8) — no new reactivity. The\n // effect runs immediately (build time, like errorBoundary's derived);\n // its unsubscribe is owned by this component.\n cleanups.push(effect(fn));\n },\n renderChildren(content: ContainerDSL): void {\n if (children !== undefined) children(content);\n },\n };\n\n // Run setup to get the render function, guarding a synchronous throw the\n // same way errorBoundary does (defer so we never re-enter reconciliation\n // during this build). A component wrapped in an errorBoundary still surfaces\n // the error through the boundary's observed sources.\n let render: ComponentRender;\n try {\n render = def.setup(props, ctx);\n render(new ContainerBuilderImpl(node, graph));\n } catch (err) {\n queueMicrotask(() => {\n throw err;\n });\n }\n\n if (cleanups.length > 0) {\n graph.registerHandler(\n `__component__${node.id}`,\n (() => cleanups) as unknown as () => unknown,\n );\n }\n }\n}\n\n// ── Concrete builder implementations ─────────────────────────────────────────\n\nexport class SectionBuilderImpl extends ContainerBuilderBase implements SectionDSL {}\nexport class ContainerBuilderImpl extends ContainerBuilderBase implements ContainerDSL {}\nexport class FormBuilderImpl extends ContainerBuilderBase implements FormDSL {}\n\nexport class ListBuilderImpl extends ContentBuilderBase implements ListDSL {\n item(key: string, builder: ContainerBuilderFn, options: ContainerOptions = {}): void {\n const node = this._graph.createNode('list-item', {\n key,\n parent: this._node,\n props: containerProps(options),\n });\n registerTransition(this._graph, node, options.transition);\n builder(new ContainerBuilderImpl(node, this._graph));\n }\n}\n\nexport class PageBuilderImpl extends ContainerBuilderBase implements PageDSL {}\n\n// ── App builder ───────────────────────────────────────────────────────────────\n\nexport class AppBuilder implements AppDSL {\n constructor(private readonly _graph: ApplicationGraph) {}\n\n page(key: string, builder: PageBuilder): void {\n const node = this._graph.createNode('page', {\n key,\n parent: this._graph.root,\n props: { key },\n });\n builder(new PageBuilderImpl(node, this._graph));\n }\n}\n","/**\n * First-class StreetUI-native components (§3–§9).\n *\n * A component is a *reusable unit that owns its own local state and lifecycle*.\n * It is NOT a virtual-DOM element, a second reactive system, or a second\n * renderer. It compiles into the EXISTING pipeline: `container.component(...)`\n * creates a reserved `'component'` GraphNode (already a `SemanticNodeType`,\n * already mapped to `<div>`), runs the component's `setup` synchronously during\n * the same build-time descent every other builder uses, and routes any cleanups\n * the setup registers into the node's `NodeInstance` at mount (so they run,\n * children-first, when the component leaves the graph).\n *\n * Design (derived from the existing DSL architecture, not copied from React/Vue):\n *\n * const UserCard = component<{ name: Signal<string> }>((props, ctx) => {\n * // ── setup: runs ONCE per instance, at build time ──\n * const open = signal(false);\n * ctx.effect(() => { ... }); // auto-disposed on unmount\n * ctx.onCleanup(() => { ... }); // explicit teardown hook\n * // ── render: fills the component's own container scope ──\n * return (content) => {\n * content.text(props.name); // fine-grained: signal prop, no re-setup\n * content.when(open, (c) => c.text('expanded'));\n * ctx.renderChildren(content); // where slotted children go (§6)\n * };\n * }, { name: 'UserCard' });\n *\n * page.component('card-1', UserCard, { name }, (slot) => slot.text('child'));\n *\n * Props are ordinary typed values (§5 — typing is a TypeScript concern, no\n * runtime schema). Passing a `Signal<T>` prop and binding it in the render body\n * gives fine-grained updates (§13) WITHOUT re-running `setup`: only the bound\n * node mutates when the signal changes. `setup` re-runs only when the component\n * is genuinely rebuilt (removed + re-created by a keyed list / conditional),\n * at which point the previous instance is disposed first — so cleanup stays\n * correct.\n */\n\nimport type { ContainerDSL, ContainerBuilder } from './dsl-types.js';\n\n/**\n * The render half of a component: fills the component's own container scope.\n * Returned by `setup` so that per-instance state created in `setup` is captured\n * by closure and the render body can read it.\n */\nexport type ComponentRender = (content: ContainerDSL) => void;\n\n/**\n * Lifecycle + composition surface handed to a component's `setup`. Local\n * reactive state is created with the EXISTING `signal`/`derived`/`effect`/\n * `batch` primitives (§8) — `ctx` only adds ownership: anything registered here\n * is torn down automatically when the component leaves the graph (§9).\n */\nexport interface ComponentContext {\n /** This instance's stable identity key (the `key` passed at the call site). */\n readonly key: string;\n /**\n * Register a teardown callback. Runs when the component unmounts (children\n * first, then this — mirroring `NodeInstance.dispose`). Use for resources,\n * `form.dispose`, subscriptions, timers, etc.\n */\n onCleanup(fn: () => void): void;\n /**\n * Run a reactive effect owned by this component. Wraps the framework's\n * `effect()`; the returned unsubscribe is auto-tracked and disposed on\n * unmount, so component effects never leak (the pain point the audit ranked\n * #1). The effect may itself return a cleanup, exactly like `effect()`.\n */\n effect(fn: () => void | (() => void)): void;\n /**\n * Render the caller-supplied children into `content` at this point (§6 native\n * child composition / slots). No-op when the call site passed no children.\n * Call it wherever the component wants its slotted content to appear.\n */\n renderChildren(content: ContainerDSL): void;\n}\n\n/**\n * A component's setup function: receives typed props and the lifecycle context,\n * creates any local state, and returns the render function. Runs synchronously\n * during the build-time descent (like `errorBoundary`'s callback), so it must be\n * SSR-safe — on the server it runs at render time and its cleanups run when the\n * SSR root is disposed.\n */\nexport type ComponentSetup<P> = (props: P, ctx: ComponentContext) => ComponentRender;\n\n/**\n * The opaque, reusable definition produced by `component(...)`. Carries the\n * `setup` and an inspectable `name`; the brand lets the builder method (and\n * DevTools) recognise a definition at runtime without a class.\n */\nexport interface ComponentDefinition<P> {\n readonly __streetui_component: true;\n readonly name: string;\n readonly setup: ComponentSetup<P>;\n}\n\n/**\n * Define a reusable component. Returns a `ComponentDefinition` you render with\n * `container.component(key, def, props, children?)`. This is a pure factory — it\n * builds no graph and runs no `setup`; instantiation happens per call site.\n *\n * @param setup Runs once per instance: create local state, return the render fn.\n * @param options.name Human-readable name for DevTools/`data-streetui-component`.\n */\nexport function component<P = Record<string, never>>(\n setup: ComponentSetup<P>,\n options: { name?: string } = {},\n): ComponentDefinition<P> {\n return {\n __streetui_component: true,\n name: options.name ?? setup.name ?? 'Component',\n setup,\n };\n}\n\n/** Runtime guard: is `value` a component definition? */\nexport function isComponentDefinition(value: unknown): value is ComponentDefinition<unknown> {\n return (\n value !== null &&\n typeof value === 'object' &&\n (value as { __streetui_component?: unknown }).__streetui_component === true\n );\n}\n\nexport type { ContainerBuilder as ComponentChildren };\n","/**\n * StreetUI DSL entry point.\n *\n * Usage:\n * import { streetui } from '@streetui/dsl';\n *\n * const app = streetui.app({ name: 'My App' });\n * app.page('home', page => {\n * page.section('hero', section => {\n * section.heading('Welcome');\n * section.button('Click me', { onClick: () => {} });\n * });\n * });\n *\n * const graph = app.build();\n */\n\nimport { ApplicationGraph } from '@streetui/graph';\nimport { AppBuilder } from './builders.js';\n\nexport interface AppOptions {\n readonly name: string;\n readonly version?: string;\n}\n\nexport class StreetApp {\n private readonly _graph: ApplicationGraph;\n private readonly _builder: AppBuilder;\n\n constructor(options: AppOptions) {\n const graphOpts: { name: string; version?: string } = { name: options.name };\n if (options.version !== undefined) graphOpts.version = options.version;\n this._graph = new ApplicationGraph(graphOpts);\n this._builder = new AppBuilder(this._graph);\n }\n\n page(key: string, builder: Parameters<AppBuilder['page']>[1]): this {\n this._builder.page(key, builder);\n return this;\n }\n\n /** Compile to ApplicationGraph — validates and returns the graph. */\n build(): ApplicationGraph {\n const dc = this._graph.validate();\n dc.throwIfErrors();\n return this._graph;\n }\n\n /** Access graph before building (useful for inspection). */\n get graph(): ApplicationGraph {\n return this._graph;\n }\n}\n\nexport interface StreetUI {\n app(options: AppOptions): StreetApp;\n}\n\nexport const streetui: StreetUI = {\n app(options: AppOptions): StreetApp {\n return new StreetApp(options);\n },\n};\n","/**\n * Compiler-phase validation of the ApplicationGraph.\n *\n * This runs after the DSL has built the graph but before the runtime\n * receives a CompiledApplication. More checks live here than in the\n * graph's own validate() because the compiler has broader context.\n */\n\nimport { DiagnosticCollector } from '@streetui/core';\nimport { ApplicationGraph, GraphNode } from '@streetui/graph';\n\nexport function validateGraph(graph: ApplicationGraph): DiagnosticCollector {\n const dc = new DiagnosticCollector();\n\n // Merge built-in graph validations\n dc.merge(graph.validate());\n\n // Must have at least one page\n const pages = graph.findByType('page');\n if (pages.length === 0) {\n dc.warn(\n 'COMPILER_NO_PAGES',\n 'Application has no pages defined. At least one page is recommended.',\n );\n }\n\n // Walk and validate individual nodes\n graph.walk((node) => {\n validateNode(node, dc);\n });\n\n return dc;\n}\n\nfunction validateNode(node: GraphNode, dc: DiagnosticCollector): void {\n switch (node.type) {\n case 'heading': {\n const text = node.getProp('text');\n if (text === undefined || text === '') {\n dc.warn('COMPILER_EMPTY_HEADING', `Heading node \"${node.id}\" has no text content`, {\n nodeId: node.id,\n });\n }\n break;\n }\n case 'image': {\n const src = node.getProp('src');\n const alt = node.getProp('alt');\n if (!src) {\n dc.error('COMPILER_IMAGE_NO_SRC', `Image node \"${node.id}\" is missing src`, {\n nodeId: node.id,\n });\n }\n if (!alt) {\n dc.warn('COMPILER_IMAGE_NO_ALT', `Image node \"${node.id}\" is missing alt text`, {\n nodeId: node.id,\n });\n }\n break;\n }\n case 'link': {\n const href = node.getProp('href');\n if (!href) {\n dc.error('COMPILER_LINK_NO_HREF', `Link node \"${node.id}\" is missing href`, {\n nodeId: node.id,\n });\n }\n break;\n }\n default:\n break;\n }\n}\n","/**\n * Graph transformation pass.\n *\n * After validation, the transformer prepares the graph for the runtime by:\n * - Resolving implicit defaults (e.g. heading level defaults to 1)\n * - Normalizing prop names\n * - Assigning deterministic render keys where missing\n * - Flattening / hoisting where beneficial\n */\n\nimport { ApplicationGraph, GraphNode } from '@streetui/graph';\n\nexport function transformGraph(graph: ApplicationGraph): void {\n graph.walk((node, depth) => {\n applyDefaults(node);\n ensureRenderKey(node, depth);\n });\n}\n\nfunction applyDefaults(node: GraphNode): void {\n switch (node.type) {\n case 'heading': {\n if (node.getProp('level') === undefined) {\n node.setProp('level', 1);\n }\n break;\n }\n case 'input': {\n if (node.getProp('inputType') === undefined) {\n node.setProp('inputType', 'text');\n }\n break;\n }\n case 'link': {\n if (node.getProp('external') === undefined) {\n node.setProp('external', false);\n }\n break;\n }\n default:\n break;\n }\n}\n\nfunction ensureRenderKey(node: GraphNode, depth: number): void {\n if (node.getProp('_renderKey') === undefined) {\n const key = node.key ?? `${node.type}:${node.id}:${depth}`;\n node.setProp('_renderKey', key);\n }\n}\n","/**\n * StreetUI compiler entry point.\n *\n * Pipeline:\n * StreetApp (DSL)\n * → ApplicationGraph (build)\n * → validate\n * → transform\n * → CompiledApplication\n */\n\nimport { DiagnosticCollector } from '@streetui/core';\nimport { type ApplicationGraph } from '@streetui/graph';\nimport { type StreetApp } from '@streetui/dsl';\nimport { validateGraph } from './validation/validator.js';\nimport { transformGraph } from './transform/transform.js';\n\nexport interface CompiledApplication {\n /** The fully built, validated, and transformed graph. */\n readonly graph: ApplicationGraph;\n /** Diagnostics accumulated during compilation. */\n readonly diagnostics: DiagnosticCollector;\n /** Metadata */\n readonly name: string;\n readonly version: string;\n readonly compiledAt: number;\n}\n\nexport interface CompileOptions {\n /** If true, compilation throws on errors. Defaults to true. */\n readonly strict?: boolean;\n /** If true, also throw on warnings. Defaults to false. */\n readonly strictWarnings?: boolean;\n}\n\n/**\n * Compile a StreetApp DSL definition into a CompiledApplication\n * ready for the runtime to execute.\n */\nexport function compile(\n app: StreetApp,\n options: CompileOptions = {},\n): CompiledApplication {\n const strict = options.strict ?? true;\n const strictWarnings = options.strictWarnings ?? false;\n const dc = new DiagnosticCollector();\n\n // 1. Build the graph from the DSL\n const graph = app.graph;\n\n // 2. Validate\n const validationDc = validateGraph(graph);\n dc.merge(validationDc);\n\n if (strict && dc.hasErrors) {\n dc.throwIfErrors();\n }\n if (strictWarnings && dc.hasWarnings) {\n throw new Error(\n `[StreetUI Compiler] Compilation failed: warnings treated as errors.\\n` +\n dc.diagnostics\n .filter(d => d.severity === 'warning')\n .map(d => ` [${d.code}] ${d.message}`)\n .join('\\n'),\n );\n }\n\n // 3. Transform\n transformGraph(graph);\n\n return {\n graph,\n diagnostics: dc,\n name: graph.name,\n version: graph.version,\n compiledAt: Date.now(),\n };\n}\n\n/**\n * Compile from a pre-built ApplicationGraph (used when the graph\n * was constructed programmatically rather than through the DSL).\n */\nexport function compileGraph(\n graph: ApplicationGraph,\n options: CompileOptions = {},\n): CompiledApplication {\n const strict = options.strict ?? true;\n const dc = new DiagnosticCollector();\n\n const validationDc = validateGraph(graph);\n dc.merge(validationDc);\n\n if (strict && dc.hasErrors) {\n dc.throwIfErrors();\n }\n\n transformGraph(graph);\n\n return {\n graph,\n diagnostics: dc,\n name: graph.name,\n version: graph.version,\n compiledAt: Date.now(),\n };\n}\n","/**\n * RuntimeNodeInstance — the runtime's live representation of a GraphNode.\n *\n * Each GraphNode in the compiled application gets a corresponding\n * RuntimeNodeInstance during mounting. The instance owns:\n * - the DOM node(s) produced for this graph node\n * - all signal subscriptions that drive updates\n * - all DOM event listeners\n * - child instances\n */\n\nimport { CleanupRegistry } from '@streetui/core';\nimport type { GraphNode } from '@streetui/graph';\nimport type { Signal, ReadonlySignal } from '@streetui/state';\n\nexport interface NodeInstanceOptions {\n readonly graphNode: GraphNode;\n readonly domNode: Node;\n}\n\nexport class RuntimeNodeInstance {\n readonly graphNode: GraphNode;\n domNode: Node;\n readonly children: RuntimeNodeInstance[] = [];\n readonly cleanup: CleanupRegistry = new CleanupRegistry();\n private _mounted = false;\n\n constructor(options: NodeInstanceOptions) {\n this.graphNode = options.graphNode;\n this.domNode = options.domNode;\n }\n\n get isMounted(): boolean {\n return this._mounted;\n }\n\n mount(): void {\n this._mounted = true;\n }\n\n unmount(): void {\n if (!this._mounted) return;\n this._mounted = false;\n for (const child of this.children) {\n child.unmount();\n }\n this.cleanup.run();\n }\n\n addChild(instance: RuntimeNodeInstance): void {\n this.children.push(instance);\n }\n\n /** Subscribe to a signal and register the unsubscribe for cleanup. */\n trackSignal<T>(\n signal: Signal<T> | ReadonlySignal<T>,\n handler: (value: T) => void,\n ): void {\n const unsub = signal.subscribe(handler);\n this.cleanup.add(unsub);\n }\n\n /** Register an arbitrary cleanup function (e.g. DOM event removal). */\n trackCleanup(fn: () => void): void {\n this.cleanup.add(fn);\n }\n}\n","/**\n * StreetUI update scheduler.\n *\n * Responsibilities:\n * - Queue update callbacks\n * - Batch synchronous enqueues into a single microtask flush\n * - Guarantee ordering: higher priority jobs flush first\n * - Prevent duplicate work for the same job key\n * - Allow synchronous flush for tests\n */\n\nexport type Priority = 'immediate' | 'normal' | 'idle';\n\nconst PRIORITY_ORDER: Record<Priority, number> = {\n immediate: 0,\n normal: 1,\n idle: 2,\n};\n\nexport interface Job {\n /** Unique key — if another job with the same key is already queued, it is replaced. */\n readonly key: string;\n readonly priority: Priority;\n readonly fn: () => void;\n}\n\n/**\n * Optional error-reporting hook (v0.9 §26/§27). Structurally compatible with\n * `@streetui/core`'s `DiagnosticSink` (the `error` method) so an application can\n * route swallowed scheduler-job failures through its own logger instead of the\n * default `console.error`. Kept as a local structural type so the scheduler\n * stays dependency-free; no network, no telemetry. When unset, behaviour is\n * exactly as before.\n */\nexport interface SchedulerDiagnostics {\n error?(message: string, context?: unknown): void;\n}\n\nexport class Scheduler {\n private readonly _queue: Map<string, Job> = new Map();\n private _flushScheduled = false;\n private _flushing = false;\n private _diagnostics: SchedulerDiagnostics | undefined = undefined;\n\n /**\n * Install an optional diagnostic sink for swallowed job errors. Pass\n * `undefined` to restore the default `console.error` reporting. Additive and\n * opt-in — the scheduler never sends anything anywhere on its own.\n */\n setDiagnostics(sink: SchedulerDiagnostics | undefined): void {\n this._diagnostics = sink;\n }\n\n /** Total jobs currently queued. */\n get size(): number {\n return this._queue.size;\n }\n\n /** True if a flush has been scheduled but not yet executed. */\n get isPending(): boolean {\n return this._flushScheduled;\n }\n\n /**\n * Enqueue a job. If a job with the same key exists, the new one replaces it\n * (allowing callers to coalesce repeated updates for the same node).\n */\n schedule(job: Job): void {\n this._queue.set(job.key, job);\n if (!this._flushScheduled && !this._flushing) {\n this._flushScheduled = true;\n this._scheduleMicrotask();\n }\n }\n\n /** Schedule multiple jobs atomically. */\n scheduleAll(jobs: readonly Job[]): void {\n for (const job of jobs) {\n this._queue.set(job.key, job);\n }\n if (!this._flushScheduled && !this._flushing && this._queue.size > 0) {\n this._flushScheduled = true;\n this._scheduleMicrotask();\n }\n }\n\n /**\n * Cancel a queued job by key. No-op if not queued.\n */\n cancel(key: string): void {\n this._queue.delete(key);\n }\n\n /**\n * Synchronously flush all queued jobs (sorted by priority).\n * Useful in tests and for immediate rendering.\n */\n flush(): void {\n if (this._flushing) return;\n this._flushScheduled = false;\n this._flushing = true;\n\n const jobs = Array.from(this._queue.values()).sort(\n (a, b) => PRIORITY_ORDER[a.priority] - PRIORITY_ORDER[b.priority],\n );\n this._queue.clear();\n\n try {\n for (const job of jobs) {\n try {\n job.fn();\n } catch (err) {\n // Isolate job failures — report and continue so remaining jobs still run.\n if (this._diagnostics?.error) {\n this._diagnostics.error(`Scheduler job \"${job.key}\" threw`, err);\n } else {\n console.error(`[Scheduler] Job \"${job.key}\" threw:`, err);\n }\n }\n }\n } finally {\n this._flushing = false;\n }\n }\n\n /** Clear all pending jobs without executing them. */\n clear(): void {\n this._queue.clear();\n this._flushScheduled = false;\n }\n\n private _scheduleMicrotask(): void {\n Promise.resolve().then(() => {\n if (this._flushScheduled) {\n this.flush();\n }\n });\n }\n}\n\n/** The shared global scheduler instance. */\nexport const scheduler = new Scheduler();\n\n/** Convenience: schedule a normal-priority job. */\nexport function scheduleUpdate(key: string, fn: () => void): void {\n scheduler.schedule({ key, priority: 'normal', fn });\n}\n\n/** Convenience: schedule an immediate-priority job. */\nexport function scheduleImmediate(key: string, fn: () => void): void {\n scheduler.schedule({ key, priority: 'immediate', fn });\n}\n\n/** Convenience: flush the global scheduler synchronously. */\nexport function flushSync(): void {\n scheduler.flush();\n}\n","/**\n * StreetUI Runtime.\n *\n * Owns:\n * - Signal binding — wires signal subscriptions to renderer update calls\n * - Event dispatch — calls registered handlers from graph events\n * - Lifecycle — orchestrates mount, update cycles, unmount\n *\n * The runtime does NOT create DOM nodes. It calls into StreetRenderer\n * for all DOM operations.\n */\n\nimport { CleanupRegistry } from '@streetui/core';\nimport type { GraphNode, ApplicationGraph } from '@streetui/graph';\nimport type { Signal, ReadonlySignal } from '@streetui/state';\nimport { Scheduler } from '@streetui/scheduler';\nimport type { CompiledApplication } from '@streetui/compiler';\nimport type { StreetRenderer, RenderHandle } from './renderer-interface.js';\n\nexport interface RuntimeOptions {\n readonly renderer: StreetRenderer;\n readonly scheduler?: Scheduler;\n}\n\nexport interface MountedApplication {\n readonly renderHandle: RenderHandle;\n readonly runtime: Runtime;\n unmount(): void;\n flush(): void;\n}\n\nexport class Runtime {\n private readonly _renderer: StreetRenderer;\n private readonly _scheduler: Scheduler;\n private readonly _cleanup: CleanupRegistry = new CleanupRegistry();\n private _renderHandle: RenderHandle | null = null;\n private _mounted = false;\n\n constructor(options: RuntimeOptions) {\n this._renderer = options.renderer;\n this._scheduler = options.scheduler ?? new Scheduler();\n }\n\n get isMounted(): boolean {\n return this._mounted;\n }\n\n /**\n * Mount the compiled application into the given DOM container.\n */\n mount(compiled: CompiledApplication, container: Element): MountedApplication {\n if (this._mounted) {\n throw new Error('[Runtime] Already mounted. Call unmount() first.');\n }\n\n // Hand off to renderer — it creates all DOM nodes\n this._renderHandle = this._renderer.mount(compiled, container);\n this._mounted = true;\n\n // Wire signal subscriptions from the graph\n this._bindSignals(compiled.graph);\n\n const self = this;\n return {\n renderHandle: this._renderHandle,\n runtime: this,\n unmount() { self.unmount(); },\n flush() { self._scheduler.flush(); },\n };\n }\n\n unmount(): void {\n if (!this._mounted) return;\n this._mounted = false;\n this._renderHandle?.unmount();\n this._renderHandle = null;\n this._cleanup.run();\n }\n\n /**\n * Hydrate a container that already holds server-rendered HTML for this\n * application. Delegates to the renderer's `hydrate` (adopting the existing\n * DOM instead of recreating it) and falls back to `mount` for renderers that\n * cannot hydrate. Signal binding is identical to `mount`, so the live client\n * lifecycle is established the same way.\n */\n hydrate(compiled: CompiledApplication, container: Element): MountedApplication {\n if (this._mounted) {\n throw new Error('[Runtime] Already mounted. Call unmount() first.');\n }\n\n this._renderHandle = this._renderer.hydrate !== undefined\n ? this._renderer.hydrate(compiled, container)\n : this._renderer.mount(compiled, container);\n this._mounted = true;\n\n this._bindSignals(compiled.graph);\n\n const self = this;\n return {\n renderHandle: this._renderHandle,\n runtime: this,\n unmount() { self.unmount(); },\n flush() { self._scheduler.flush(); },\n };\n }\n\n /**\n * Walk the graph and subscribe to all signal-bound nodes.\n * When a signal changes, schedule a renderer update for that node.\n */\n private _bindSignals(graph: ApplicationGraph): void {\n graph.walk((node) => {\n for (const stateRef of node.stateRefs) {\n const signalKey = `__signal__${stateRef.signalId}`;\n const maybeSignal = graph.getHandler(signalKey) as\n | (Signal<unknown> & ReadonlySignal<unknown>)\n | undefined;\n\n if (maybeSignal === undefined || typeof maybeSignal.subscribe !== 'function') continue;\n\n const unsub = maybeSignal.subscribe(() => {\n // Schedule a re-render update keyed to this node+prop\n this._scheduler.schedule({\n key: `update:${node.id}:${stateRef.propKey}`,\n priority: 'normal',\n fn: () => {\n // The renderer handles the actual DOM update\n this._renderHandle?.flush();\n },\n });\n });\n this._cleanup.add(unsub);\n }\n });\n }\n}\n\n/**\n * Convenience factory — create a runtime, mount, and return the handle.\n */\nexport function createRuntime(options: RuntimeOptions): Runtime {\n return new Runtime(options);\n}\n","/**\n * StreetUI event type catalogue.\n * Framework events are distinct from raw DOM events.\n */\n\nexport type StreetEventType =\n | 'click'\n | 'dblclick'\n | 'input'\n | 'change'\n | 'submit'\n | 'focus'\n | 'blur'\n | 'keydown'\n | 'keyup'\n | 'keypress'\n | 'mouseenter'\n | 'mouseleave'\n | 'mousemove'\n | 'mousedown'\n | 'mouseup'\n | 'pointerdown'\n | 'pointerup'\n | 'pointermove'\n | 'pointerenter'\n | 'pointerleave'\n | 'scroll'\n | 'resize'\n | 'mount'\n | 'unmount'\n | 'update';\n\nexport interface StreetEvent<T = unknown> {\n readonly type: StreetEventType | string;\n readonly target: unknown;\n readonly data: T | undefined;\n readonly originalEvent: Event | undefined;\n readonly timestamp: number;\n defaultPrevented: boolean;\n stopPropagation(): void;\n preventDefault(): void;\n}\n\nexport function createStreetEvent<T = unknown>(\n type: StreetEventType | string,\n target: unknown,\n data?: T,\n originalEvent?: Event,\n): StreetEvent<T> {\n let _stopped = false;\n const ev: StreetEvent<T> = {\n type,\n target,\n data: data as T | undefined,\n originalEvent: originalEvent as Event | undefined,\n timestamp: Date.now(),\n defaultPrevented: false,\n stopPropagation() { _stopped = true; },\n preventDefault() { ev.defaultPrevented = true; },\n };\n return ev;\n}\n\nexport type EventHandler<T = unknown> = (event: StreetEvent<T>) => void;\n","/**\n * Framework-internal event bus.\n * Decouples emitters from handlers across subsystems.\n */\n\nimport type { StreetEvent, EventHandler } from './event-types.js';\n\nexport class EventBus {\n private readonly _handlers: Map<string, Set<EventHandler>> = new Map();\n\n on<T = unknown>(type: string, handler: EventHandler<T>): () => void {\n let set = this._handlers.get(type);\n if (set === undefined) {\n set = new Set();\n this._handlers.set(type, set);\n }\n set.add(handler as EventHandler);\n return () => this.off(type, handler as EventHandler);\n }\n\n off<T = unknown>(type: string, handler: EventHandler<T>): void {\n this._handlers.get(type)?.delete(handler as EventHandler);\n }\n\n once<T = unknown>(type: string, handler: EventHandler<T>): () => void {\n const wrapped: EventHandler<T> = (event) => {\n handler(event);\n this.off(type, wrapped);\n };\n return this.on(type, wrapped);\n }\n\n emit<T = unknown>(event: StreetEvent<T>): void {\n const handlers = this._handlers.get(event.type);\n if (handlers === undefined) return;\n for (const h of handlers) {\n h(event as StreetEvent);\n }\n }\n\n clear(type?: string): void {\n if (type !== undefined) {\n this._handlers.delete(type);\n } else {\n this._handlers.clear();\n }\n }\n\n listenerCount(type: string): number {\n return this._handlers.get(type)?.size ?? 0;\n }\n}\n\nexport const globalEventBus = new EventBus();\n","/**\n * DOM ↔ StreetUI event bridge.\n *\n * Attaches native DOM event listeners and translates them into\n * StreetUI events dispatched to registered handlers.\n * The renderer uses this to wire events without coupling\n * DOM event mechanics into the render pipeline directly.\n */\n\nimport { createStreetEvent, type EventHandler, type StreetEventType } from './event-types.js';\n\nexport interface DomBinding {\n remove(): void;\n}\n\n/**\n * Attach a DOM event listener that fires the given StreetUI handler.\n * Returns a binding whose `remove()` detaches the listener.\n */\nexport function bindDomEvent<T extends Event = Event>(\n element: EventTarget,\n domEventType: StreetEventType | string,\n handler: EventHandler,\n options?: AddEventListenerOptions,\n): DomBinding {\n const listener = (e: T) => {\n const streetEvent = createStreetEvent(domEventType, element, undefined, e as unknown as Event);\n handler(streetEvent);\n };\n\n element.addEventListener(domEventType, listener as EventListener, options);\n\n return {\n remove() {\n element.removeEventListener(domEventType, listener as EventListener, options);\n },\n };\n}\n\n/**\n * A registry that tracks all DOM bindings for a single node,\n * making bulk teardown easy.\n */\nexport class DomEventRegistry {\n private readonly _bindings: DomBinding[] = [];\n\n bind(\n element: EventTarget,\n type: StreetEventType | string,\n handler: EventHandler,\n options?: AddEventListenerOptions,\n ): void {\n this._bindings.push(bindDomEvent(element, type, handler, options));\n }\n\n removeAll(): void {\n for (const b of this._bindings) {\n b.remove();\n }\n this._bindings.length = 0;\n }\n\n get count(): number {\n return this._bindings.length;\n }\n}\n","/**\n * Browser implementation of DOMAdapter — delegates directly to browser APIs.\n */\n\nimport type { DOMAdapter } from './adapter.js';\n\nexport class BrowserDOMAdapter implements DOMAdapter {\n createElement(tag: string, ns?: string): Element {\n if (ns !== undefined) {\n return document.createElementNS(ns, tag);\n }\n return document.createElement(tag);\n }\n\n createTextNode(data: string): Text {\n return document.createTextNode(data);\n }\n\n createComment(data: string): Comment {\n return document.createComment(data);\n }\n\n createFragment(): DocumentFragment {\n return document.createDocumentFragment();\n }\n\n appendChild(parent: Node, child: Node): void {\n parent.appendChild(child);\n }\n\n insertBefore(parent: Node, child: Node, reference: Node | null): void {\n parent.insertBefore(child, reference);\n }\n\n removeChild(parent: Node, child: Node): void {\n parent.removeChild(child);\n }\n\n replaceChild(parent: Node, newChild: Node, oldChild: Node): void {\n parent.replaceChild(newChild, oldChild);\n }\n\n setAttribute(element: Element, name: string, value: string): void {\n element.setAttribute(name, value);\n }\n\n removeAttribute(element: Element, name: string): void {\n element.removeAttribute(name);\n }\n\n getAttribute(element: Element, name: string): string | null {\n return element.getAttribute(name);\n }\n\n setProperty(element: Element, name: string, value: unknown): void {\n (element as unknown as Record<string, unknown>)[name] = value;\n }\n\n setTextContent(node: Node, text: string): void {\n node.textContent = text;\n }\n\n getTextContent(node: Node): string | null {\n return node.textContent;\n }\n\n addEventListener(\n target: EventTarget,\n type: string,\n handler: EventListener,\n options?: AddEventListenerOptions,\n ): void {\n target.addEventListener(type, handler, options);\n }\n\n removeEventListener(\n target: EventTarget,\n type: string,\n handler: EventListener,\n options?: EventListenerOptions,\n ): void {\n target.removeEventListener(type, handler, options);\n }\n\n querySelector(root: Element | Document, selector: string): Element | null {\n return root.querySelector(selector);\n }\n\n querySelectorAll(root: Element | Document, selector: string): NodeListOf<Element> {\n return root.querySelectorAll(selector);\n }\n\n getElementById(id: string): Element | null {\n return document.getElementById(id);\n }\n\n focus(element: Element): void {\n (element as unknown as { focus?: () => void }).focus?.();\n }\n\n body(): Element | null {\n return document.body ?? null;\n }\n\n activeElement(): Element | null {\n return document.activeElement ?? null;\n }\n\n contains(ancestor: Element, node: Node): boolean {\n return ancestor.contains(node);\n }\n\n matches(element: Element, selector: string): boolean {\n return typeof element.matches === 'function' && element.matches(selector);\n }\n\n isElement(node: Node): node is Element {\n return node.nodeType === Node.ELEMENT_NODE;\n }\n\n isTextNode(node: Node): node is Text {\n return node.nodeType === Node.TEXT_NODE;\n }\n\n tagName(element: Element): string {\n return element.tagName.toLowerCase();\n }\n\n parentNode(node: Node): Node | null {\n return node.parentNode;\n }\n\n nextSibling(node: Node): Node | null {\n return node.nextSibling;\n }\n\n firstChild(node: Node): Node | null {\n return node.firstChild;\n }\n\n childNodes(node: Node): Node[] {\n return Array.from(node.childNodes);\n }\n}\n\n// `/* @__PURE__ */`: convenience singleton, unreferenced by internal runtime\n// paths. Marking construction pure lets bundlers drop it when unused instead of\n// retaining it (and the BrowserDOMAdapter class) as an import-time side effect.\nexport const browserDOMAdapter = /* @__PURE__ */ new BrowserDOMAdapter();\n","/**\n * Server-side DOM node model.\n *\n * A tiny, dependency-free tree of plain objects that mirrors just enough of the\n * browser DOM for StreetUI's renderer to build a tree on the server and\n * serialize it to an HTML string. There is NO browser global here — these are\n * ordinary classes usable in any JavaScript environment (Node, workers, tests).\n *\n * The renderer never touches these types directly; it goes through the\n * `DOMAdapter` interface, and `ServerDOMAdapter` translates adapter calls into\n * operations on this model.\n */\n\nexport type ServerNodeKind = 'element' | 'text' | 'comment' | 'fragment' | 'raw';\n\nexport interface ServerNode {\n readonly kind: ServerNodeKind;\n parent: ServerParent | null;\n}\n\nexport type ServerParent = ServerElement | ServerFragment;\n\n/** A minimal inline-style holder mirroring `element.style.setProperty`. */\nexport class ServerStyle {\n readonly declarations = new Map<string, string>();\n setProperty(name: string, value: string): void {\n this.declarations.set(name, value);\n }\n get isEmpty(): boolean {\n return this.declarations.size === 0;\n }\n toCss(): string {\n return [...this.declarations.entries()].map(([k, v]) => `${k}: ${v}`).join('; ');\n }\n}\n\nexport class ServerText implements ServerNode {\n readonly kind = 'text' as const;\n parent: ServerParent | null = null;\n data: string;\n constructor(data: string) {\n this.data = data;\n }\n}\n\nexport class ServerComment implements ServerNode {\n readonly kind = 'comment' as const;\n parent: ServerParent | null = null;\n data: string;\n constructor(data: string) {\n this.data = data;\n }\n}\n\nexport class ServerFragment implements ServerNode {\n readonly kind = 'fragment' as const;\n parent: ServerParent | null = null;\n readonly children: ServerNode[] = [];\n}\n\n/**\n * A pre-serialized, verbatim HTML fragment (v1.7 static SSR plan).\n *\n * Emitted for provably-static subtrees whose HTML the compiler-derived static\n * SSR plan already computed once. Serializing this node copies its stored\n * string directly — it allocates no ServerElement/ServerText, no attribute Map\n * and no children array for the collapsed subtree. The stored `html` is\n * produced by the exact same mount + serialize pipeline as the runtime path, so\n * the output is byte-identical (the v1.7 byte-identity gate proves this).\n *\n * This node is SSR-only: it is created solely via `ServerDOMAdapter.createRawHTML`\n * on the server render path and never appears in a browser build.\n */\nexport class ServerRawHTML implements ServerNode {\n readonly kind = 'raw' as const;\n parent: ServerParent | null = null;\n readonly html: string;\n constructor(html: string) {\n this.html = html;\n }\n}\n\nexport class ServerElement implements ServerNode {\n readonly kind = 'element' as const;\n parent: ServerParent | null = null;\n readonly tagName: string;\n readonly attributes = new Map<string, string>();\n readonly children: ServerNode[] = [];\n\n // Lazily-allocated stores. On the 10k-row SSR corpus ~0% of elements carry JS\n // properties or inline styles (measured, §5: 1 of 80,029 elements uses\n // `properties`, 0 use `style`), so eagerly allocating a `properties` Map plus\n // a `ServerStyle` (which itself holds a Map) per element wasted ~240k\n // allocations per /users render — all in the dominant mount phase. These are\n // created on first WRITE via the `properties`/`style` getters; the serializer\n // reads the raw `_properties`/`_style` fields so a READ never forces an\n // allocation. Output is byte-identical: an unset store previously serialized\n // to nothing (empty `properties.has(...)` / `style.isEmpty`), and a null store\n // is skipped the same way.\n _properties: Map<string, unknown> | null = null;\n _style: ServerStyle | null = null;\n\n constructor(tagName: string) {\n this.tagName = tagName.toLowerCase();\n }\n\n /** JS properties set via `setProperty` (e.g. input `value`, `checked`). Allocated on first access. */\n get properties(): Map<string, unknown> {\n return (this._properties ??= new Map());\n }\n\n /** Inline-style holder mirroring `element.style`. Allocated on first access. */\n get style(): ServerStyle {\n return (this._style ??= new ServerStyle());\n }\n}\n\n// ── HTML serialization ─────────────────────────────────────────────────────────\n\n/**\n * HTML \"void\" elements — self-closing, never given a closing tag or children.\n */\nconst VOID_ELEMENTS = new Set([\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\n 'link', 'meta', 'param', 'source', 'track', 'wbr',\n]);\n\n/**\n * Element properties that should be reflected into the serialized HTML so the\n * hydrated DOM carries the same initial state. `value`/`checked` matter for\n * form controls whose live state is a JS property, not an attribute.\n */\nconst SERIALIZED_PROPERTIES: Record<string, 'attr' | 'boolean'> = {\n value: 'attr',\n checked: 'boolean',\n selected: 'boolean',\n};\n\n/**\n * Precomputed `[name, kind]` pairs of SERIALIZED_PROPERTIES. Hoisted to module\n * scope so `serializeAttributes` does not allocate a fresh entries array for\n * every element serialized (measured hot: ~80k elements on the 10k-row route).\n */\nconst SERIALIZED_PROPERTY_ENTRIES: ReadonlyArray<readonly [string, 'attr' | 'boolean']> =\n Object.entries(SERIALIZED_PROPERTIES) as Array<[string, 'attr' | 'boolean']>;\n\n// Fast-path escaping. The chained `.replace(/…/g, …)` form makes 3–4 full\n// passes and allocates an intermediate string per pass even when nothing needs\n// escaping. These variants scan once and, in the overwhelmingly common case of\n// no special character, return the input unchanged (zero allocation). Output is\n// byte-identical to the chained form (verified over the real SSR corpus).\nconst TEXT_SPECIAL = /[&<>]/;\nconst ATTR_SPECIAL = /[&<>\"]/;\n\n/** Escape text node content. */\nexport function escapeHtmlText(value: string): string {\n if (!TEXT_SPECIAL.test(value)) return value;\n let out = '';\n let last = 0;\n for (let i = 0; i < value.length; i++) {\n let esc: string;\n switch (value.charCodeAt(i)) {\n case 38: esc = '&amp;'; break; // &\n case 60: esc = '&lt;'; break; // <\n case 62: esc = '&gt;'; break; // >\n default: continue;\n }\n out += value.slice(last, i) + esc;\n last = i + 1;\n }\n return out + value.slice(last);\n}\n\n/** Escape a double-quoted attribute value. */\nexport function escapeHtmlAttr(value: string): string {\n if (!ATTR_SPECIAL.test(value)) return value;\n let out = '';\n let last = 0;\n for (let i = 0; i < value.length; i++) {\n let esc: string;\n switch (value.charCodeAt(i)) {\n case 38: esc = '&amp;'; break; // &\n case 60: esc = '&lt;'; break; // <\n case 62: esc = '&gt;'; break; // >\n case 34: esc = '&quot;'; break; // \"\n default: continue;\n }\n out += value.slice(last, i) + esc;\n last = i + 1;\n }\n return out + value.slice(last);\n}\n\nfunction serializeAttributes(el: ServerElement): string {\n const parts: string[] = [];\n\n for (const [name, value] of el.attributes) {\n if (value === '') {\n parts.push(` ${name}`);\n } else {\n parts.push(` ${name}=\"${escapeHtmlAttr(value)}\"`);\n }\n }\n\n // Read the raw backing field (may be null): most elements have no JS\n // properties, so skipping the whole loop avoids touching a store that was\n // never allocated (§5).\n const props = el._properties;\n if (props !== null) {\n for (const [name, kind] of SERIALIZED_PROPERTY_ENTRIES) {\n if (!props.has(name)) continue;\n if (el.attributes.has(name)) continue; // an explicit attribute already won\n const raw = props.get(name);\n if (kind === 'boolean') {\n if (raw === true) parts.push(` ${name}`);\n } else {\n if (raw !== undefined && raw !== null) {\n parts.push(` ${name}=\"${escapeHtmlAttr(String(raw))}\"`);\n }\n }\n }\n }\n\n const style = el._style;\n if (style !== null && !style.isEmpty && !el.attributes.has('style')) {\n parts.push(` style=\"${escapeHtmlAttr(style.toCss())}\"`);\n }\n\n return parts.join('');\n}\n\n/** Serialize a single server node (element/text/comment/fragment/raw) to HTML. */\nexport function serializeServerNode(node: ServerNode): string {\n switch (node.kind) {\n case 'text':\n return escapeHtmlText((node as ServerText).data);\n case 'comment':\n return `<!--${(node as ServerComment).data}-->`;\n case 'fragment':\n return serializeChildren(node as ServerFragment);\n case 'raw':\n // Verbatim: the string was produced by this same serializer for a static\n // subtree, so it is already correctly escaped. Copy it as-is (§8).\n return (node as ServerRawHTML).html;\n case 'element': {\n const el = node as ServerElement;\n const tag = el.tagName;\n const attrs = serializeAttributes(el);\n if (VOID_ELEMENTS.has(tag)) {\n return `<${tag}${attrs}>`;\n }\n return `<${tag}${attrs}>${serializeChildren(el)}</${tag}>`;\n }\n }\n}\n\n/** Serialize the children of an element or fragment (its \"inner HTML\"). */\nexport function serializeChildren(node: ServerElement | ServerFragment): string {\n let out = '';\n for (const child of node.children) {\n out += serializeServerNode(child);\n }\n return out;\n}\n","/**\n * Server implementation of `DOMAdapter`.\n *\n * Builds a lightweight in-memory tree (see `server-node.ts`) instead of touching\n * a real browser DOM, then lets the caller serialize it to an HTML string. It is\n * completely free of browser globals, so the exact same renderer that runs in\n * the browser can produce HTML on the server.\n *\n * The `DOMAdapter` interface is typed against the lib DOM types (`Element`,\n * `Node`, `Text`, …). Our server nodes structurally stand in for those at\n * runtime, so the boundary uses `as unknown as` casts in one place. Everything\n * inside operates on the real server-node model.\n */\n\nimport type { DOMAdapter } from './adapter.js';\nimport {\n ServerElement,\n ServerText,\n ServerComment,\n ServerFragment,\n ServerRawHTML,\n serializeChildren,\n serializeServerNode,\n type ServerNode,\n type ServerParent,\n} from './server-node.js';\n\nfunction asServer(node: unknown): ServerNode {\n return node as unknown as ServerNode;\n}\nfunction asParent(node: unknown): ServerParent {\n return node as unknown as ServerParent;\n}\n\nexport class ServerDOMAdapter implements DOMAdapter {\n createElement(tag: string, _ns?: string): Element {\n return new ServerElement(tag) as unknown as Element;\n }\n\n createTextNode(data: string): Text {\n return new ServerText(data) as unknown as Text;\n }\n\n createComment(data: string): Comment {\n return new ServerComment(data) as unknown as Comment;\n }\n\n createFragment(): DocumentFragment {\n return new ServerFragment() as unknown as DocumentFragment;\n }\n\n /**\n * Create a verbatim pre-serialized HTML node (v1.7 static SSR plan, §6).\n * Server-only: the browser adapter does not implement this, and the renderer\n * fast path only invokes it when a static SSR plan is present (SSR). The\n * stored HTML was produced by this same serializer, so it is emitted as-is.\n */\n createRawHTML(html: string): Node {\n return new ServerRawHTML(html) as unknown as Node;\n }\n\n appendChild(parent: Node, child: Node): void {\n const p = asParent(parent);\n const c = asServer(child);\n this._detach(c);\n c.parent = p;\n p.children.push(c);\n }\n\n insertBefore(parent: Node, child: Node, reference: Node | null): void {\n const p = asParent(parent);\n const c = asServer(child);\n this._detach(c);\n c.parent = p;\n if (reference === null) {\n p.children.push(c);\n return;\n }\n const ref = asServer(reference);\n const idx = p.children.indexOf(ref);\n if (idx === -1) p.children.push(c);\n else p.children.splice(idx, 0, c);\n }\n\n removeChild(parent: Node, child: Node): void {\n const p = asParent(parent);\n const c = asServer(child);\n const idx = p.children.indexOf(c);\n if (idx !== -1) {\n p.children.splice(idx, 1);\n c.parent = null;\n }\n }\n\n replaceChild(parent: Node, newChild: Node, oldChild: Node): void {\n const p = asParent(parent);\n const nc = asServer(newChild);\n const oc = asServer(oldChild);\n const idx = p.children.indexOf(oc);\n if (idx === -1) return;\n this._detach(nc);\n nc.parent = p;\n p.children.splice(idx, 1, nc);\n oc.parent = null;\n }\n\n private _detach(node: ServerNode): void {\n if (node.parent !== null) {\n const siblings = node.parent.children;\n const idx = siblings.indexOf(node);\n if (idx !== -1) siblings.splice(idx, 1);\n node.parent = null;\n }\n }\n\n setAttribute(element: Element, name: string, value: string): void {\n (element as unknown as ServerElement).attributes.set(name, value);\n }\n\n removeAttribute(element: Element, name: string): void {\n (element as unknown as ServerElement).attributes.delete(name);\n }\n\n getAttribute(element: Element, name: string): string | null {\n return (element as unknown as ServerElement).attributes.get(name) ?? null;\n }\n\n setProperty(element: Element, name: string, value: unknown): void {\n (element as unknown as ServerElement).properties.set(name, value);\n }\n\n setTextContent(node: Node, text: string): void {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n const el = n as ServerElement | ServerFragment;\n el.children.length = 0;\n const t = new ServerText(text);\n t.parent = el;\n el.children.push(t);\n } else if (n.kind === 'text') {\n (n as ServerText).data = text;\n }\n }\n\n getTextContent(node: Node): string | null {\n const n = asServer(node);\n if (n.kind === 'text') return (n as ServerText).data;\n if (n.kind === 'element' || n.kind === 'fragment') {\n let out = '';\n for (const c of (n as ServerElement | ServerFragment).children) {\n out += this.getTextContent(c as unknown as Node) ?? '';\n }\n return out;\n }\n return null;\n }\n\n // Server nodes never dispatch events — listeners are a no-op on the server.\n addEventListener(): void {\n /* no-op on the server */\n }\n removeEventListener(): void {\n /* no-op on the server */\n }\n\n querySelector(): Element | null {\n return null;\n }\n querySelectorAll(): NodeListOf<Element> {\n return [] as unknown as NodeListOf<Element>;\n }\n getElementById(): Element | null {\n return null;\n }\n\n focus(): void {\n // No focus concept on the server — intentional no-op (SSR-safe).\n }\n\n body(): Element | null {\n // No document on the server — portals degrade to inline rendering.\n return null;\n }\n\n activeElement(): Element | null {\n return null;\n }\n\n contains(_ancestor: Element, _node: Node): boolean {\n return false;\n }\n\n matches(_element: Element, _selector: string): boolean {\n return false;\n }\n\n isElement(node: Node): node is Element {\n return asServer(node).kind === 'element';\n }\n\n isTextNode(node: Node): node is Text {\n return asServer(node).kind === 'text';\n }\n\n tagName(element: Element): string {\n return (element as unknown as ServerElement).tagName;\n }\n\n parentNode(node: Node): Node | null {\n return (asServer(node).parent as unknown as Node | null) ?? null;\n }\n\n nextSibling(node: Node): Node | null {\n const n = asServer(node);\n const parent = n.parent;\n if (parent === null) return null;\n const idx = parent.children.indexOf(n);\n if (idx === -1 || idx + 1 >= parent.children.length) return null;\n return parent.children[idx + 1] as unknown as Node;\n }\n\n firstChild(node: Node): Node | null {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n const el = n as ServerElement | ServerFragment;\n return (el.children[0] as unknown as Node) ?? null;\n }\n return null;\n }\n\n childNodes(node: Node): Node[] {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n return (n as ServerElement | ServerFragment).children as unknown as Node[];\n }\n return [];\n }\n\n // ── Server-only ────────────────────────────────────────────────────────────\n\n /** Serialize a node's children (\"inner HTML\") to an HTML string. */\n serializeInner(node: Node): string {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n return serializeChildren(n as ServerElement | ServerFragment);\n }\n return '';\n }\n\n /** Serialize a node (including itself) to an HTML string. */\n serializeOuter(node: Node): string {\n return serializeServerNode(asServer(node));\n }\n}\n\n// `/* @__PURE__ */`: this singleton is a convenience export only (no internal\n// runtime path references it). Marking construction pure lets bundlers drop it —\n// and with it the whole server serializer chain (serializeServerNode/escape/\n// VOID_ELEMENTS) — out of client bundles that never import SSR. Without this,\n// the un-annotated `new` is treated as a side effect and retained everywhere.\nexport const serverDOMAdapter = /* @__PURE__ */ new ServerDOMAdapter();\n","/**\n * Focus helpers built on the {@link DOMAdapter} abstraction.\n *\n * These are the minimal, genuinely-useful focus operations an app needs:\n * focus a specific element (e.g. the first field when a route or modal opens)\n * or focus the first focusable element inside a container (e.g. move focus\n * into a dialog). Both go through the adapter, so they are no-ops on the server\n * (`ServerDOMAdapter.querySelector` returns null / `focus` does nothing) and\n * therefore safe to call from universal code.\n */\n\nimport type { DOMAdapter } from './adapter.js';\n\n/** Default selector for natively focusable / tabbable elements. */\nexport const FOCUSABLE_SELECTOR =\n 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * Focus the element with the given id, scoped to `root`.\n * Returns true if an element was found and focused.\n */\nexport function focusById(dom: DOMAdapter, root: Element | Document, id: string): boolean {\n const el = dom.querySelector(root, `[id=\"${id}\"]`);\n if (el === null) return false;\n dom.focus(el);\n return true;\n}\n\n/**\n * Focus the first focusable element inside `container`.\n * Returns true if a focusable element was found and focused.\n */\nexport function focusFirst(\n dom: DOMAdapter,\n container: Element | Document,\n selector: string = FOCUSABLE_SELECTOR,\n): boolean {\n const el = dom.querySelector(container, selector);\n if (el === null) return false;\n dom.focus(el);\n return true;\n}\n\n/**\n * Ordered list of focusable/tabbable descendants of `container`.\n * Re-checks each candidate against the selector so elements disabled after the\n * initial query (e.g. a button toggled to `disabled`) are excluded.\n */\nexport function getFocusable(\n dom: DOMAdapter,\n container: Element,\n selector: string = FOCUSABLE_SELECTOR,\n): Element[] {\n return Array.from(dom.querySelectorAll(container, selector)).filter((el) =>\n dom.matches(el, selector),\n );\n}\n\n/**\n * Capture the currently-focused element so it can be restored later (e.g. when\n * a dialog closes). Returns null on the server or when nothing is focused.\n */\nexport function saveFocus(dom: DOMAdapter): Element | null {\n return dom.activeElement();\n}\n\n/** Restore focus to a previously {@link saveFocus}-d element. No-op if null. */\nexport function restoreFocus(dom: DOMAdapter, saved: Element | null): void {\n if (saved !== null) dom.focus(saved);\n}\n\n/**\n * Move focus into `container` on open: the element with id `initialFocusId` if\n * given and present, otherwise the first focusable element. Server-safe no-op.\n */\nexport function focusInitial(\n dom: DOMAdapter,\n container: Element,\n initialFocusId?: string,\n): void {\n if (initialFocusId !== undefined && focusById(dom, container, initialFocusId)) return;\n focusFirst(dom, container);\n}\n\n/**\n * Trap Tab / Shift+Tab focus within `container` (wrap-around at both ends).\n * Attaches a keydown listener to the container and returns a cleanup function\n * that detaches it. Server-safe: `addEventListener` is a no-op, and the returned\n * cleanup is still callable.\n */\nexport function trapFocus(dom: DOMAdapter, container: Element): () => void {\n const onKeydown = ((event: KeyboardEvent): void => {\n if (event.key !== 'Tab') return;\n const items = getFocusable(dom, container);\n if (items.length === 0) {\n event.preventDefault();\n return;\n }\n const first = items[0]!;\n const last = items[items.length - 1]!;\n const active = dom.activeElement();\n if (active === null || !dom.contains(container, active)) {\n event.preventDefault();\n dom.focus(first);\n } else if (event.shiftKey && active === first) {\n event.preventDefault();\n dom.focus(last);\n } else if (!event.shiftKey && active === last) {\n event.preventDefault();\n dom.focus(first);\n }\n }) as EventListener;\n dom.addEventListener(container, 'keydown', onKeydown);\n return () => dom.removeEventListener(container, 'keydown', onKeydown);\n}\n\n/**\n * Modal containment: if focus moves to an element outside `container`, redirect\n * it back inside. Listens on the document body (focusin bubbles there) and\n * returns a cleanup function. Server-safe no-op (body() is null).\n *\n * Nested modals (§16): every active containment pushes its container onto a\n * module-level stack, and a handler only redirects while ITS container is the\n * top of the stack — i.e. the most recently opened modal. This is the framework's\n * minimal \"focus owner\" concept: because overlay panels are relocated to\n * body-level portals (siblings, not descendants), two overlapping `containFocus`\n * handlers would otherwise fight over every `focusin`. The stack makes exactly\n * one owner authoritative at a time; cleanup pops it so the previous modal\n * resumes ownership. State is internal and torn down on cleanup — nothing is\n * retained on the graph (§18).\n */\nconst containmentStack: Element[] = [];\n\nexport function containFocus(dom: DOMAdapter, container: Element): () => void {\n const body = dom.body();\n if (body === null) return () => {};\n containmentStack.push(container);\n const onFocusIn = ((event: FocusEvent): void => {\n // Only the topmost owner enforces containment (nested-modal correctness).\n if (containmentStack[containmentStack.length - 1] !== container) return;\n const target = event.target as Node | null;\n if (target !== null && !dom.contains(container, target)) {\n focusFirst(dom, container);\n }\n }) as EventListener;\n dom.addEventListener(body, 'focusin', onFocusIn);\n return () => {\n dom.removeEventListener(body, 'focusin', onFocusIn);\n const index = containmentStack.lastIndexOf(container);\n if (index !== -1) containmentStack.splice(index, 1);\n };\n}\n\n/**\n * Invoke `handler` when Escape is pressed while focus is within `target`.\n * Returns a cleanup function. Server-safe no-op.\n */\nexport function onEscape(dom: DOMAdapter, target: Element, handler: () => void): () => void {\n const onKeydown = ((event: KeyboardEvent): void => {\n if (event.key === 'Escape') handler();\n }) as EventListener;\n dom.addEventListener(target, 'keydown', onKeydown);\n return () => dom.removeEventListener(target, 'keydown', onKeydown);\n}\n\n/**\n * Roving-focus keyboard navigation for a menu (role=\"menu\") container: the\n * arrow keys move focus between the container's focusable items (wrap-around at\n * both ends), Home/End jump to the first/last item, and Enter/Space activate\n * the currently-focused item (a native `click`, so an item's `onClick` fires).\n * `Tab` and `Escape` are deliberately left alone — the overlay layer wires\n * Escape-to-close separately and a menu does not trap Tab.\n *\n * Items are re-queried on every key (via {@link getFocusable}) so a menu whose\n * items change reactively is always navigated against the live set, and items\n * disabled after mount are skipped. Attaches a keydown listener to the\n * container and returns a cleanup function. Server-safe: `addEventListener` is\n * a no-op and the returned cleanup is still callable.\n */\nexport function rovingMenu(\n dom: DOMAdapter,\n container: Element,\n selector: string = FOCUSABLE_SELECTOR,\n): () => void {\n const onKeydown = ((event: KeyboardEvent): void => {\n const key = event.key;\n const isActivate = key === 'Enter' || key === ' ' || key === 'Spacebar';\n const isMove =\n key === 'ArrowDown' || key === 'ArrowUp' || key === 'Home' || key === 'End';\n if (!isActivate && !isMove) return;\n\n const items = getFocusable(dom, container, selector);\n if (items.length === 0) return;\n const active = dom.activeElement();\n const index = active === null ? -1 : items.indexOf(active);\n\n if (isActivate) {\n // Activating a menu item only makes sense when one is focused; otherwise\n // let the event fall through unchanged.\n if (index < 0) return;\n event.preventDefault();\n (items[index] as unknown as { click?: () => void }).click?.();\n return;\n }\n\n event.preventDefault();\n let next: number;\n if (key === 'Home') next = 0;\n else if (key === 'End') next = items.length - 1;\n else if (key === 'ArrowDown') next = index < 0 ? 0 : (index + 1) % items.length;\n else next = index <= 0 ? items.length - 1 : index - 1; // ArrowUp\n dom.focus(items[next]!);\n }) as EventListener;\n dom.addEventListener(container, 'keydown', onKeydown);\n return () => dom.removeEventListener(container, 'keydown', onKeydown);\n}\n\n","/**\n * ARIA live-region announcer (§15).\n *\n * Screen readers announce text that appears inside an `aria-live` region. The\n * naive approach — append a fresh `<div aria-live>` per message — leaks a\n * growing pile of stale nodes and (because a node inserted *already carrying*\n * its text is often not re-announced) is unreliable. This announcer instead\n * keeps exactly TWO persistent regions on `<body>` — one `polite`, one\n * `assertive` — and mutates their text to speak. Announcing clears the region\n * first and writes on a microtask so that repeating the same string still\n * triggers a DOM mutation the AT will pick up.\n *\n * Built entirely on the {@link DOMAdapter}, so it is server-safe: when\n * `dom.body()` is null (SSR / headless) construction returns an inert announcer\n * whose `announce`/`clear`/`destroy` are no-ops. There is never any SSR markup\n * for a live region — announcements are a runtime-only concept.\n */\n\nimport type { DOMAdapter } from './adapter.js';\n\nexport interface Announcer {\n /**\n * Announce `message`. `assertive` (default false) routes to the assertive\n * region (interrupts the user) instead of the polite one (waits for a pause).\n */\n announce(message: string, options?: { assertive?: boolean }): void;\n /** Clear both regions without announcing anything. */\n clear(): void;\n /** Remove both regions from the DOM. Idempotent. */\n destroy(): void;\n}\n\n/** Build the hidden, visually-clipped style shared by both regions. */\nconst VISUALLY_HIDDEN =\n 'position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0;';\n\nfunction makeRegion(dom: DOMAdapter, politeness: 'polite' | 'assertive'): Element {\n const el = dom.createElement('div');\n dom.setAttribute(el, 'aria-live', politeness);\n // `aria-atomic=true` makes the AT read the whole region on each change, so a\n // replaced message is spoken in full rather than diffed.\n dom.setAttribute(el, 'aria-atomic', 'true');\n dom.setAttribute(el, 'role', politeness === 'assertive' ? 'alert' : 'status');\n dom.setAttribute(el, 'data-streetui-live', politeness);\n dom.setAttribute(el, 'style', VISUALLY_HIDDEN);\n return el;\n}\n\n/**\n * Create a live-region announcer bound to `dom`. Idempotent per call — each\n * call owns its own pair of regions, so an app that wants a single shared\n * announcer should create one and reuse it (and `destroy()` it on teardown).\n */\nexport function createAnnouncer(dom: DOMAdapter): Announcer {\n const body = dom.body();\n if (body === null) {\n // Server / headless: nothing to announce into.\n return { announce() {}, clear() {}, destroy() {} };\n }\n\n const polite = makeRegion(dom, 'polite');\n const assertive = makeRegion(dom, 'assertive');\n dom.appendChild(body, polite);\n dom.appendChild(body, assertive);\n let destroyed = false;\n\n const write = (region: Element, message: string): void => {\n // Clear first so an identical repeat message still mutates the region (and\n // is therefore re-announced); set on a microtask so the empty→text change\n // is observed as a distinct mutation.\n dom.setTextContent(region, '');\n void Promise.resolve().then(() => {\n if (!destroyed) dom.setTextContent(region, message);\n });\n };\n\n return {\n announce(message, options): void {\n if (destroyed) return;\n write(options?.assertive === true ? assertive : polite, message);\n },\n clear(): void {\n if (destroyed) return;\n dom.setTextContent(polite, '');\n dom.setTextContent(assertive, '');\n },\n destroy(): void {\n if (destroyed) return;\n destroyed = true;\n for (const region of [polite, assertive]) {\n const parent = dom.parentNode(region);\n if (parent !== null) dom.removeChild(parent, region);\n }\n },\n };\n}\n","/**\n * RenderContext — shared state for a single mount operation.\n *\n * Passed through the render pipeline so every sub-function has access\n * to the DOM adapter, graph, and instance map without prop-drilling.\n */\n\nimport type { DOMAdapter } from '@streetui/dom';\nimport type { ApplicationGraph, GraphNode } from '@streetui/graph';\nimport type { NodeInstance } from './node-instance.js';\nimport type { HydrationDiagnosticSink } from './hydration-diagnostics.js';\n\nexport interface RenderContext {\n readonly dom: DOMAdapter;\n readonly graph: ApplicationGraph;\n /** Maps GraphNode.id → its live NodeInstance */\n readonly instances: Map<string, NodeInstance>;\n /** The root container element. */\n readonly container: Element;\n /**\n * Optional dev-only sink that observes hydration mismatch repairs. When\n * absent (the default) the hydration path does no extra work — this is how\n * DevTools/diagnostics stay off the production runtime path.\n */\n readonly hydrationDiagnostics?: HydrationDiagnosticSink;\n /**\n * Optional SSR-only static-subtree plan (v1.7). Maps a maximal\n * static-subtree root GraphNode.id → its precomputed, verbatim HTML string.\n * Present only on the server render path when a plan has been built; on the\n * browser mount path it is always `undefined`, so the client hot path is\n * unaffected (a single `=== undefined` check short-circuits). When a mounted\n * node's id is in this map, the renderer emits the precomputed HTML via\n * `dom.createRawHTML` instead of recursively constructing the subtree.\n */\n readonly staticHTML?: ReadonlyMap<string, string>;\n}\n\nexport function createRenderContext(\n dom: DOMAdapter,\n graph: ApplicationGraph,\n container: Element,\n hydrationDiagnostics?: HydrationDiagnosticSink,\n staticHTML?: ReadonlyMap<string, string>,\n): RenderContext {\n return {\n dom,\n graph,\n instances: new Map(),\n container,\n ...(hydrationDiagnostics !== undefined ? { hydrationDiagnostics } : {}),\n ...(staticHTML !== undefined ? { staticHTML } : {}),\n };\n}\n","/**\n * NodeInstance — the renderer's live counterpart to a GraphNode.\n *\n * Tracks the actual DOM node(s), all signal subscriptions that drive\n * targeted DOM updates, and DOM event listener teardowns.\n */\n\nimport { CleanupRegistry } from '@streetui/core';\nimport type { GraphNode } from '@streetui/graph';\nimport type { ReadonlySignal } from '@streetui/state';\n\nexport class NodeInstance {\n readonly graphNode: GraphNode;\n /** The primary DOM node for this instance (element or text node). */\n domNode: Node;\n readonly children: NodeInstance[] = [];\n readonly cleanup: CleanupRegistry = new CleanupRegistry();\n\n constructor(graphNode: GraphNode, domNode: Node) {\n this.graphNode = graphNode;\n this.domNode = domNode;\n }\n\n addChild(child: NodeInstance): void {\n this.children.push(child);\n }\n\n /** Subscribe to a signal; auto-cleanup on unmount. */\n trackSignal<T>(sig: ReadonlySignal<T>, handler: (v: T) => void): void {\n const unsub = sig.subscribe(handler);\n this.cleanup.add(unsub);\n }\n\n /** Register a raw cleanup fn (DOM event removal, etc.). */\n trackCleanup(fn: () => void): void {\n this.cleanup.add(fn);\n }\n\n dispose(): void {\n for (const child of this.children) {\n child.dispose();\n }\n this.cleanup.run();\n }\n}\n","/**\n * Attribute and property application helpers.\n *\n * Decides whether a prop should be set as a DOM attribute or a JS property,\n * handling special cases (boolean attrs, event-like props, style, class).\n */\n\nimport type { DOMAdapter } from '@streetui/dom';\n\n// Properties that must be set as JS object properties, not HTML attributes\nconst DOM_PROPERTIES = new Set([\n 'value', 'checked', 'selected', 'indeterminate',\n 'innerHTML', 'textContent', 'innerText',\n 'scrollTop', 'scrollLeft',\n]);\n\n// Boolean attributes — present means true, absent means false\nconst BOOLEAN_ATTRS = new Set([\n 'disabled', 'readonly', 'required', 'checked', 'selected',\n 'multiple', 'autofocus', 'autoplay', 'controls', 'default',\n 'defer', 'formnovalidate', 'hidden', 'ismap', 'loop',\n 'novalidate', 'open', 'reversed', 'scoped', 'seamless',\n]);\n\nexport function applyProp(\n dom: DOMAdapter,\n element: Element,\n name: string,\n value: unknown,\n): void {\n // Skip internal renderer metadata\n if (name.startsWith('_')) return;\n // Skip event handlers (handled separately)\n if (name.startsWith('on')) return;\n\n if (DOM_PROPERTIES.has(name)) {\n dom.setProperty(element, name, value);\n return;\n }\n\n if (BOOLEAN_ATTRS.has(name)) {\n if (value === true || value === '' || value === name) {\n dom.setAttribute(element, name, '');\n } else {\n dom.removeAttribute(element, name);\n }\n return;\n }\n\n if (name === 'class' || name === 'className') {\n dom.setAttribute(element, 'class', String(value ?? ''));\n return;\n }\n\n if (name === 'style' && typeof value === 'object' && value !== null) {\n const el = element as HTMLElement;\n const styles = value as Record<string, string>;\n for (const [k, v] of Object.entries(styles)) {\n el.style.setProperty(k, v);\n }\n return;\n }\n\n if (value === null || value === undefined || value === false) {\n dom.removeAttribute(element, name);\n return;\n }\n\n dom.setAttribute(element, name, String(value));\n}\n\nexport function patchProp(\n dom: DOMAdapter,\n element: Element,\n name: string,\n oldValue: unknown,\n newValue: unknown,\n): void {\n if (Object.is(oldValue, newValue)) return;\n applyProp(dom, element, name, newValue);\n}\n","/**\n * Event wiring for the renderer.\n *\n * Given a GraphNode with event descriptors, this wires DOM listeners\n * that call the handlers stored in the graph's handler registry.\n */\n\nimport type { DOMAdapter } from '@streetui/dom';\nimport type { ApplicationGraph, GraphNode } from '@streetui/graph';\nimport type { NodeInstance } from './node-instance.js';\n\nexport function wireEvents(\n dom: DOMAdapter,\n graph: ApplicationGraph,\n node: GraphNode,\n element: Element,\n instance: NodeInstance,\n): void {\n // Fast exit for event-free nodes — avoids allocating a for-of iterator over\n // an empty array on every node during a large mount/hydrate.\n if (node.events.length === 0) return;\n for (const eventDesc of node.events) {\n const handler = graph.getHandler(eventDesc.handlerKey);\n if (handler === undefined) continue;\n\n const domListener: EventListener = (domEvent: Event) => {\n // For input events, pass the current value as first arg\n if (eventDesc.type === 'input' || eventDesc.type === 'change') {\n const input = domEvent.target as HTMLInputElement;\n (handler as (v: string) => void)(input.value);\n } else if (eventDesc.type === 'submit') {\n domEvent.preventDefault();\n (handler as (e: Event) => void)(domEvent);\n } else {\n (handler as () => void)();\n }\n };\n\n dom.addEventListener(element, eventDesc.type, domListener);\n instance.trackCleanup(() => {\n dom.removeEventListener(element, eventDesc.type, domListener);\n });\n }\n}\n","/**\n * Maps semantic node types to HTML tag names.\n */\n\nimport type { SemanticNodeType } from '@streetui/core';\n\nconst TAG_MAP: Partial<Record<SemanticNodeType, string>> = {\n application: 'div',\n page: 'div',\n section: 'section',\n container: 'div',\n heading: 'h1',\n text: 'span',\n button: 'button',\n input: 'input',\n form: 'form',\n list: 'ul',\n 'list-item': 'li',\n image: 'img',\n link: 'a',\n component: 'div',\n slot: 'div',\n fragment: 'div',\n 'reactive-list': 'ul',\n // A portal renders as a neutral inline anchor <div> at its declaration site;\n // its children are relocated to a document.body container on the browser\n // (see the portal branch in mount.ts). On the server (no body) it renders\n // inline, so the anchor tag is what SSR/hydration positionally match on.\n portal: 'div',\n};\n\nexport function resolveTag(type: SemanticNodeType): string {\n return TAG_MAP[type] ?? 'div';\n}\n","/**\n * Patch — targeted DOM updates driven by signal changes.\n *\n * When a signal fires, we look up the NodeInstance and apply\n * only the changed prop — no full re-render, no tree diffing.\n */\n\nimport type { RenderContext } from './render-context.js';\nimport type { GraphNode } from '@streetui/graph';\nimport { applyProp, patchProp } from './attributes.js';\n\nexport function patchNode(\n ctx: RenderContext,\n graphNode: GraphNode,\n propKey: string,\n newValue: unknown,\n): void {\n const instance = ctx.instances.get(graphNode.id);\n if (instance === undefined) return;\n\n const domNode = instance.domNode;\n if (!ctx.dom.isElement(domNode)) return;\n\n const oldValue = graphNode.getProp(propKey);\n\n switch (propKey) {\n case 'text':\n if (!Object.is(oldValue, newValue)) {\n ctx.dom.setTextContent(domNode, String(newValue ?? ''));\n graphNode.setProp('text', String(newValue ?? ''));\n }\n break;\n case 'label':\n if (!Object.is(oldValue, newValue)) {\n ctx.dom.setTextContent(domNode, String(newValue ?? ''));\n graphNode.setProp('label', String(newValue ?? ''));\n }\n break;\n case 'disabled':\n if (newValue === true) {\n ctx.dom.setAttribute(domNode, 'disabled', '');\n } else {\n ctx.dom.removeAttribute(domNode, 'disabled');\n }\n graphNode.setProp('disabled', Boolean(newValue));\n break;\n case 'value':\n if (!Object.is(oldValue, newValue)) {\n ctx.dom.setProperty(domNode, 'value', String(newValue ?? ''));\n graphNode.setProp('value', String(newValue ?? ''));\n }\n break;\n default:\n patchProp(ctx.dom, domNode, propKey, oldValue, newValue);\n graphNode.setProp(propKey, newValue as string);\n break;\n }\n}\n","/**\n * Reconciliation — diff-based child list updates.\n *\n * When the children of a node change (e.g. a list driven by state),\n * this reconciler:\n * 1. Matches old instances to new graph nodes by key\n * 2. Reuses matched instances (updates their props)\n * 3. Applies a targeted content update to a reused item whose data changed\n * 4. Creates new instances for additions\n * 5. Removes stale instances (and prunes their handler registrations)\n * 6. Moves DOM nodes to match new order\n *\n * This is keyed reconciliation over the semantic graph — there is no virtual\n * DOM. A reused item keeps its own DOM element; only its changed content is\n * updated in place (falling back to remounting a subtree only where its shape\n * actually changed).\n */\n\nimport type { RenderContext } from './render-context.js';\nimport type { GraphNode } from '@streetui/graph';\nimport type { NodeInstance } from './node-instance.js';\nimport type { TransitionHooks } from './transition.js';\nimport { patchNode } from './patch.js';\n\nexport type MountFn = (node: GraphNode, parent: Element) => NodeInstance;\n\nexport interface ReconcileResult {\n /** Instances in the new order. */\n instances: NodeInstance[];\n /** Instances that were removed and must be disposed. */\n removed: NodeInstance[];\n /**\n * GraphNodes freshly materialised during this reconcile (new rows + rebuilt\n * changed rows). The caller detaches any of these that were not adopted as a\n * live instance's graph node, so no orphan subtree lingers in the graph index.\n */\n built?: GraphNode[];\n}\n\n/**\n * A lazy reconciliation descriptor for one reactive-list row (mirrors the DSL's\n * `ListPlanEntry`). `sig()` and `build()` are only invoked for rows that are\n * genuinely new or whose source reference changed — the whole point of the\n * plan path (spec §15).\n */\nexport interface PlanEntry {\n readonly key: string;\n readonly item: unknown;\n readonly sig: () => string;\n readonly build: () => GraphNode;\n}\n\n/**\n * Reconcile children of a container element against a new list of graph nodes.\n *\n * @param ctx Render context\n * @param parentDom The DOM parent element\n * @param oldInstances Current child instances (in order)\n * @param newNodes New graph children (in desired order)\n * @param mountFn Factory to create a new NodeInstance for a graph node\n */\nexport function reconcileChildren(\n ctx: RenderContext,\n parentDom: Element,\n oldInstances: NodeInstance[],\n newNodes: readonly GraphNode[],\n mountFn: MountFn,\n hooks?: TransitionHooks,\n): ReconcileResult {\n // Build key → old instance map\n const oldByKey = new Map<string, NodeInstance>();\n for (const inst of oldInstances) {\n const key = inst.graphNode.key ?? inst.graphNode.id;\n oldByKey.set(key, inst);\n }\n\n const newInstances: NodeInstance[] = [];\n const usedKeys = new Set<string>();\n\n for (const newNode of newNodes) {\n const key = newNode.key ?? newNode.id;\n const existing = oldByKey.get(key);\n\n if (existing !== undefined) {\n // Reuse — identity is stable, so the DOM element is preserved.\n usedKeys.add(key);\n const oldSig = existing.graphNode.getProp('_sig');\n const newSig = newNode.getProp('_sig');\n patchExistingInstance(ctx, existing, newNode);\n // Data changed but identity did not → targeted content update in place.\n if (!Object.is(oldSig, newSig)) {\n reconcileItemChildren(ctx, existing, newNode, mountFn);\n }\n newInstances.push(existing);\n } else {\n // Leave→enter cancellation (§6): if this key is currently animating out,\n // reclaim its live instance instead of mounting a duplicate.\n const reclaimed = hooks?.takeLeaving(key);\n if (reclaimed !== undefined) {\n patchExistingInstance(ctx, reclaimed, newNode);\n reconcileItemChildren(ctx, reclaimed, newNode, mountFn);\n hooks?.onEnter(reclaimed);\n newInstances.push(reclaimed);\n } else {\n // New — create and mount, then play its enter animation (if any).\n const inst = mountFn(newNode, parentDom);\n hooks?.onEnter(inst);\n newInstances.push(inst);\n }\n }\n }\n\n // Determine + remove stale instances. A removed instance that carries a\n // transition has its DOM-remove + dispose deferred to leave-animation end by\n // `beginLeave` (which then also forgets + detaches it), so it is excluded from\n // `removed` and the caller does not tear it down (§3/§7).\n const removed: NodeInstance[] = [];\n for (const inst of oldInstances) {\n const key = inst.graphNode.key ?? inst.graphNode.id;\n if (usedKeys.has(key)) continue;\n if (hooks !== undefined && hooks.beginLeave(inst)) continue;\n const parent = ctx.dom.parentNode(inst.domNode);\n if (parent !== null) ctx.dom.removeChild(parent, inst.domNode);\n inst.dispose();\n removed.push(inst);\n }\n\n // Reorder DOM nodes to match new order\n reorderDom(ctx, parentDom, newInstances);\n\n return { instances: newInstances, removed };\n}\n\n/**\n * Plan-based keyed reconciliation (spec §15 — the optimised reactive-list path).\n *\n * Identical observable result to {@link reconcileChildren}, but driven by lazy\n * {@link PlanEntry} descriptors instead of a pre-built array of GraphNodes:\n *\n * - a reused row whose `item` reference is unchanged does **zero** work — no\n * signature hash, no subtree build, no prop patch (the common case for\n * append / prepend / remove / reorder / reverse, where existing item objects\n * keep their identity);\n * - a reused row whose reference changed hashes lazily and, only on a real\n * signature change, materialises a fresh subtree for a targeted in-place\n * content update;\n * - a genuinely new key builds + mounts exactly one subtree.\n *\n * DOM reordering uses a longest-increasing-subsequence pass so the number of\n * moves is minimal (e.g. a prepend into a 10k list moves 1 node, not 10k).\n */\nexport function reconcileChildrenByPlan(\n ctx: RenderContext,\n parentDom: Element,\n oldInstances: NodeInstance[],\n plan: readonly PlanEntry[],\n mountFn: MountFn,\n hooks?: TransitionHooks,\n): ReconcileResult {\n const oldByKey = new Map<string, NodeInstance>();\n for (const inst of oldInstances) {\n oldByKey.set(inst.graphNode.key ?? inst.graphNode.id, inst);\n }\n\n const newInstances: NodeInstance[] = [];\n const usedKeys = new Set<string>();\n const built: GraphNode[] = [];\n\n for (const entry of plan) {\n const existing = oldByKey.get(entry.key);\n if (existing !== undefined) {\n usedKeys.add(entry.key);\n const oldItem = existing.graphNode.getProp('_item');\n // Identity short-circuit: same reference ⇒ data cannot have changed.\n if (!Object.is(oldItem, entry.item)) {\n const newSig = entry.sig();\n const oldSig = existing.graphNode.getProp('_sig');\n if (!Object.is(oldSig, newSig)) {\n const freshNode = entry.build();\n built.push(freshNode);\n patchExistingInstance(ctx, existing, freshNode);\n reconcileItemChildren(ctx, existing, freshNode, mountFn);\n existing.graphNode.setProp('_sig', newSig);\n }\n // Cache the new reference so the next pass can short-circuit again.\n existing.graphNode.setProp('_item', entry.item as never);\n }\n newInstances.push(existing);\n } else {\n // Leave→enter reclaim (§6/§7): a key removed then re-added mid-leave keeps\n // its identity and its live DOM node rather than mounting a duplicate.\n const reclaimed = hooks?.takeLeaving(entry.key);\n if (reclaimed !== undefined) {\n const freshNode = entry.build();\n built.push(freshNode);\n patchExistingInstance(ctx, reclaimed, freshNode);\n reconcileItemChildren(ctx, reclaimed, freshNode, mountFn);\n reclaimed.graphNode.setProp('_sig', freshNode.getProp('_sig') as never);\n reclaimed.graphNode.setProp('_item', entry.item as never);\n hooks?.onEnter(reclaimed);\n newInstances.push(reclaimed);\n } else {\n const freshNode = entry.build();\n built.push(freshNode);\n const inst = mountFn(freshNode, parentDom);\n hooks?.onEnter(inst);\n newInstances.push(inst);\n }\n }\n }\n\n // Determine + remove stale instances. Transitioned rows defer their whole\n // teardown chain to leave-animation end (§7) and are excluded from `removed`.\n const removed: NodeInstance[] = [];\n for (const inst of oldInstances) {\n const key = inst.graphNode.key ?? inst.graphNode.id;\n if (usedKeys.has(key)) continue;\n if (hooks !== undefined && hooks.beginLeave(inst)) continue;\n const parent = ctx.dom.parentNode(inst.domNode);\n if (parent !== null) ctx.dom.removeChild(parent, inst.domNode);\n inst.dispose();\n removed.push(inst);\n }\n\n // Minimal-move reorder to the desired order.\n reorderDomMinimal(ctx, parentDom, oldInstances, newInstances);\n\n return { instances: newInstances, removed, built };\n}\n\n/**\n * Minimal-move DOM reorder.\n *\n * Reused nodes retain their previous DOM slots and newly-mounted nodes sit at\n * the end. We compute the longest increasing subsequence of the reused nodes'\n * previous positions; those are already in correct relative order and stay put.\n * Every other node is inserted before its right-hand neighbour, walking\n * right-to-left. This yields exactly (n − |LIS|) `insertBefore` calls — the\n * minimum — instead of the O(n) sweep the naive reorder performs on a prepend.\n */\nfunction reorderDomMinimal(\n ctx: RenderContext,\n parentDom: Element,\n oldInstances: NodeInstance[],\n newInstances: NodeInstance[],\n): void {\n const n = newInstances.length;\n if (n === 0) return;\n\n const oldIndexOf = new Map<NodeInstance, number>();\n for (let i = 0; i < oldInstances.length; i++) oldIndexOf.set(oldInstances[i]!, i);\n\n const source = new Array<number>(n);\n let moved = false;\n let lastSeen = -1;\n for (let i = 0; i < n; i++) {\n const oi = oldIndexOf.get(newInstances[i]!);\n if (oi === undefined) {\n source[i] = -1; // freshly mounted row\n moved = true;\n } else {\n source[i] = oi;\n if (oi < lastSeen) moved = true; // an out-of-order reused row exists\n else lastSeen = oi;\n }\n }\n\n // Fast path: nothing is out of order and there are no new rows to reposition.\n if (!moved) return;\n\n const keep = longestIncreasingSubsequence(source);\n\n let refNode: Node | null = null;\n for (let i = n - 1; i >= 0; i--) {\n const domNode = newInstances[i]!.domNode;\n if (source[i] === -1 || !keep.has(i)) {\n if (ctx.dom.nextSibling(domNode) !== refNode) {\n ctx.dom.insertBefore(parentDom, domNode, refNode);\n }\n }\n refNode = domNode;\n }\n}\n\n/**\n * Indices (into `source`) forming a longest strictly-increasing subsequence,\n * ignoring `-1` entries (new rows, which always move). O(n log n) with\n * predecessor reconstruction.\n */\nfunction longestIncreasingSubsequence(source: readonly number[]): Set<number> {\n const keep = new Set<number>();\n const n = source.length;\n const tails: number[] = []; // tails[k] = source-index of smallest tail of an LIS of length k+1\n const prev = new Array<number>(n).fill(-1);\n\n for (let i = 0; i < n; i++) {\n const v = source[i]!;\n if (v < 0) continue;\n let lo = 0;\n let hi = tails.length;\n while (lo < hi) {\n const mid = (lo + hi) >> 1;\n if (source[tails[mid]!]! < v) lo = mid + 1;\n else hi = mid;\n }\n if (lo > 0) prev[i] = tails[lo - 1]!;\n tails[lo] = i;\n }\n\n let idx = tails.length > 0 ? tails[tails.length - 1]! : -1;\n while (idx >= 0) {\n keep.add(idx);\n idx = prev[idx]!;\n }\n return keep;\n}\n\n/**\n * Targeted in-place content update for a reused list item whose data changed.\n *\n * The item's DOM element is kept; only its contents are updated. Children are\n * matched positionally against the freshly-built subtree:\n * - same node type at a position → the existing child is reused and its props\n * are patched in place (e.g. a text node's text is rewritten), then we\n * recurse into its children;\n * - different type / new position → the fresh child node is reparented onto the\n * live item node and mounted;\n * - surplus old children → disposed, with DOM, subscriptions, listeners and\n * handler registrations all torn down.\n *\n * This deliberately reuses the same keyed/positional strategy rather than a\n * virtual DOM, and never destroys the item element itself.\n */\nfunction reconcileItemChildren(\n ctx: RenderContext,\n itemInstance: NodeInstance,\n newItemNode: GraphNode,\n mountFn: MountFn,\n): void {\n const el = itemInstance.domNode;\n if (!ctx.dom.isElement(el)) return;\n\n const oldChildren = [...itemInstance.children];\n const newChildNodes = [...newItemNode.children];\n const nextChildren: NodeInstance[] = [];\n const kept = new Set<NodeInstance>();\n\n for (let i = 0; i < newChildNodes.length; i++) {\n const newChild = newChildNodes[i]!;\n const oldChild = oldChildren[i];\n\n if (oldChild !== undefined && oldChild.graphNode.type === newChild.type) {\n // Reuse in place — patch this node's props and recurse into descendants.\n patchExistingInstance(ctx, oldChild, newChild);\n reconcileItemChildren(ctx, oldChild, newChild, mountFn);\n nextChildren.push(oldChild);\n kept.add(oldChild);\n } else {\n // Structural change at this position — mount the fresh child. Reparent it\n // out of the freshly-built subtree so the wholesale detach of the\n // unadopted item node (in mount.ts) does not remove this now-live node.\n itemInstance.graphNode.appendChild(newChild);\n const inst = mountFn(newChild, el);\n nextChildren.push(inst);\n }\n }\n\n // Dispose old children that were not reused (surplus or type-mismatched).\n for (const old of oldChildren) {\n if (kept.has(old)) continue;\n const parent = ctx.dom.parentNode(old.domNode);\n if (parent !== null) ctx.dom.removeChild(parent, old.domNode);\n old.dispose();\n forgetInstanceTree(ctx, old);\n ctx.graph.detachNode(old.graphNode);\n }\n\n // Restore correct DOM order within the item element.\n reorderDom(ctx, el, nextChildren);\n\n // Sync the live instance's children.\n itemInstance.children.length = 0;\n for (const c of nextChildren) itemInstance.children.push(c);\n\n // Keep the graph model's item children consistent with the reconciled order.\n for (const c of [...itemInstance.graphNode.children]) {\n itemInstance.graphNode.removeChild(c);\n }\n for (const c of nextChildren) itemInstance.graphNode.appendChild(c.graphNode);\n}\n\n/** Move a parent's DOM children to match the given instance order (minimal moves). */\nfunction reorderDom(\n ctx: RenderContext,\n parentDom: Element,\n instances: NodeInstance[],\n): void {\n let referenceNode: Node | null = null;\n for (let i = instances.length - 1; i >= 0; i--) {\n const inst = instances[i];\n if (inst === undefined) continue;\n const domNode = inst.domNode;\n const currentNext = ctx.dom.nextSibling(domNode);\n if (currentNext !== referenceNode) {\n ctx.dom.insertBefore(parentDom, domNode, referenceNode);\n }\n referenceNode = domNode;\n }\n}\n\n/** Recursively drop an instance subtree from the renderer's instance index. */\nfunction forgetInstanceTree(ctx: RenderContext, instance: NodeInstance): void {\n ctx.instances.delete(instance.graphNode.id);\n for (const child of instance.children) forgetInstanceTree(ctx, child);\n}\n\nfunction patchExistingInstance(\n ctx: RenderContext,\n instance: NodeInstance,\n newNode: GraphNode,\n): void {\n const oldNode = instance.graphNode;\n for (const [key, newVal] of Object.entries(newNode.props)) {\n const oldVal = oldNode.getProp(key);\n if (!Object.is(oldVal, newVal)) {\n patchNode(ctx, instance.graphNode, key, newVal);\n }\n }\n}\n","/**\n * CSS class-based enter/leave transition controller (§2–§8).\n *\n * This is the browser-only runtime that consumes the `__transition__<nodeId>`\n * descriptor the DSL registers (a pre-resolved {@link ResolvedTransitionLike}).\n * It is deliberately structural about that descriptor — like the renderer's\n * `__overlay__`/`__component__` handling — so the renderer takes NO compile-time\n * dependency on the DSL package.\n *\n * Engine (confirmed decision): CSS classes, no Web Animations API, no\n * browser-only API referenced at module scope. Every timer / rAF / event\n * binding is reached lazily through `globalThis` and only ever runs when\n * `dom.body() !== null` (the same SSR guard `wireOverlayBehavior` uses), so:\n * - server output is byte-identical (nothing here runs during SSR — §21);\n * - happy-dom, which dispatches no `transitionend`/`animationend`, still\n * completes deterministically via the fallback timeout (§24).\n *\n * The controller is created once per reactive container instance (reactive-list\n * or conditional) so its `leaving` map survives across reconcile passes — that\n * is what makes leave→enter reclaim (§6) and keyed-identity list leave (§7)\n * correct.\n */\n\nimport type { DOMAdapter } from '@streetui/dom';\nimport type { ApplicationGraph, GraphNode } from '@streetui/graph';\nimport type { NodeInstance } from './node-instance.js';\n\n/**\n * The renderer's structural view of the resolved transition the DSL stores in\n * `__transition__<id>`. Mirrors `@streetui/dsl`'s `ResolvedTransition` without\n * importing it (no renderer→dsl dependency).\n */\nexport interface ResolvedTransitionLike {\n readonly enterActive: readonly string[];\n readonly enterFrom: readonly string[];\n readonly enterTo: readonly string[];\n readonly leaveActive: readonly string[];\n readonly leaveFrom: readonly string[];\n readonly leaveTo: readonly string[];\n readonly appear: boolean;\n readonly duration: number;\n}\n\n/**\n * Hooks handed to the reconciler so it can (a) reclaim an instance that is\n * mid-leave when its key re-enters (leave→enter cancellation), (b) defer the\n * remove/dispose/forget/detach chain for a leaving instance until its animation\n * ends, and (c) play the enter animation for a freshly-inserted instance. When\n * no transition applies (or we are on the server) every hook degrades to the\n * pre-transition synchronous behaviour.\n */\nexport interface TransitionHooks {\n /**\n * If an instance for `key` is currently animating out, cancel its leave and\n * return it for reuse; otherwise undefined. The caller re-mounts nothing and\n * reuses the returned instance's live DOM node.\n */\n takeLeaving(key: string): NodeInstance | undefined;\n /**\n * Begin a leave animation for a removed instance. Returns true when the whole\n * teardown chain has been deferred to animation-end (caller must NOT remove,\n * dispose, forget or detach it), or false when there is no transition / no\n * browser and the caller should tear it down synchronously as before.\n */\n beginLeave(inst: NodeInstance): boolean;\n /** Play the enter animation for a freshly-inserted (or reclaimed) instance. */\n onEnter(inst: NodeInstance): void;\n}\n\n/** Read the pre-resolved transition descriptor for a node, if any. */\nexport function getResolvedTransition(\n graph: ApplicationGraph,\n nodeId: string,\n): ResolvedTransitionLike | undefined {\n const fn = graph.getHandler(`__transition__${nodeId}`) as\n | (() => ResolvedTransitionLike)\n | undefined;\n return fn === undefined ? undefined : fn();\n}\n\n// ── Browser-global access (lazy, never at module scope) ──────────────────────\n\ninterface RafHost {\n requestAnimationFrame?: (cb: () => void) => number;\n setTimeout: (cb: () => void, ms: number) => unknown;\n clearTimeout: (h: unknown) => void;\n}\n\nfunction host(): RafHost {\n return globalThis as unknown as RafHost;\n}\n\n/** Schedule a callback for the next frame (falls back to a macrotask). */\nfunction nextFrame(cb: () => void): void {\n const h = host();\n const raf = h.requestAnimationFrame;\n if (typeof raf === 'function') {\n // Double rAF: ensures the \"from\" classes have been painted before we flip\n // to the \"to\" classes, so the transition actually runs in real browsers.\n raf(() => raf(cb));\n } else {\n h.setTimeout(cb, 0);\n }\n}\n\n// ── Class list manipulation via the adapter (no classList dependency) ─────────\n\nfunction splitClass(value: string | null): string[] {\n if (value === null) return [];\n const out: string[] = [];\n for (const t of value.split(/\\s+/)) if (t.length > 0) out.push(t);\n return out;\n}\n\nfunction addClasses(dom: DOMAdapter, el: Element, classes: readonly string[]): void {\n if (classes.length === 0) return;\n const current = splitClass(dom.getAttribute(el, 'class'));\n let changed = false;\n for (const c of classes) {\n if (!current.includes(c)) {\n current.push(c);\n changed = true;\n }\n }\n if (changed) dom.setAttribute(el, 'class', current.join(' '));\n}\n\nfunction removeClasses(dom: DOMAdapter, el: Element, classes: readonly string[]): void {\n if (classes.length === 0) return;\n const current = splitClass(dom.getAttribute(el, 'class'));\n const next = current.filter((c) => !classes.includes(c));\n if (next.length !== current.length) {\n if (next.length === 0) dom.removeAttribute(el, 'class');\n else dom.setAttribute(el, 'class', next.join(' '));\n }\n}\n\n/**\n * One running enter-or-leave animation on a single element. Owns exactly one set\n * of DOM listeners + one fallback timer, and guarantees `settle`/`cancel` run\n * their cleanup at most once — no stale callbacks, no duplicate listeners, no\n * duplicate cleanup (§6).\n */\ninterface Run {\n /** Force the animation to its end synchronously (used by cancellation). */\n cancel(): void;\n}\n\nfunction startRun(\n dom: DOMAdapter,\n el: Element,\n active: readonly string[],\n from: readonly string[],\n to: readonly string[],\n duration: number,\n onDone: () => void,\n): Run {\n const h = host();\n let finished = false;\n let timer: unknown = null;\n\n const onEvent = ((e: Event): void => {\n // Ignore bubbling transition/animation events from descendants.\n if (e.target !== el) return;\n finish();\n }) as EventListener;\n\n const detach = (): void => {\n dom.removeEventListener(el, 'transitionend', onEvent);\n dom.removeEventListener(el, 'animationend', onEvent);\n if (timer !== null) {\n h.clearTimeout(timer);\n timer = null;\n }\n };\n\n const finish = (): void => {\n if (finished) return;\n finished = true;\n detach();\n // Clear all transition classes so the element rests in its natural state.\n removeClasses(dom, el, active);\n removeClasses(dom, el, to);\n removeClasses(dom, el, from);\n onDone();\n };\n\n // Phase 1: apply the starting + active classes immediately.\n addClasses(dom, el, from);\n addClasses(dom, el, active);\n\n dom.addEventListener(el, 'transitionend', onEvent);\n dom.addEventListener(el, 'animationend', onEvent);\n // Fallback completion: the safety net for elements that fire no transition\n // event (and the ONLY completion signal under happy-dom, where tests set a\n // small duration). 0 → next macrotask.\n timer = h.setTimeout(finish, duration);\n\n // Phase 2: on the next frame flip from → to so the CSS transition runs.\n nextFrame(() => {\n if (finished) return;\n removeClasses(dom, el, from);\n addClasses(dom, el, to);\n });\n\n return {\n cancel: () => {\n // Cancel = settle immediately (removes classes, clears listeners/timer)\n // but WITHOUT invoking onDone, so a cancelled leave never finalizes the\n // node it was about to destroy.\n if (finished) return;\n finished = true;\n detach();\n removeClasses(dom, el, active);\n removeClasses(dom, el, to);\n removeClasses(dom, el, from);\n },\n };\n}\n\ninterface LeavingEntry {\n readonly inst: NodeInstance;\n readonly run: Run;\n}\n\n/** Which half of a transition to play on a bare element. */\nexport type TransitionPhase = 'enter' | 'leave';\n\n/**\n * Play one enter/leave transition on a bare DOM element, outside the keyed\n * reconciler — the seam the router uses for route leave/enter (§9) and any other\n * consumer that owns a single host element rather than a reactive container.\n *\n * Reuses the exact same {@link startRun} mechanics as list/conditional\n * transitions (from+active applied immediately, next-frame flip to `to`,\n * completion on transitionend/animationend or the fallback timer), so there is\n * one transition engine, not two. The returned handle's `cancel()` settles the\n * run immediately WITHOUT invoking `onDone` — the caller uses it to abort an\n * in-flight enter when the same host is about to start leaving (rapid\n * navigation), avoiding overlapping runs/duplicate listeners on one element.\n *\n * On the server (or any non-element target) there is nothing to animate, so\n * `onDone` runs synchronously and `cancel()` is a no-op — the caller's teardown\n * still happens exactly once.\n */\nexport function runElementTransition(\n dom: DOMAdapter,\n el: Element,\n rt: ResolvedTransitionLike,\n phase: TransitionPhase,\n onDone: () => void,\n): { cancel(): void } {\n if (dom.body() === null || !dom.isElement(el)) {\n onDone();\n return { cancel: () => {} };\n }\n const active = phase === 'enter' ? rt.enterActive : rt.leaveActive;\n const from = phase === 'enter' ? rt.enterFrom : rt.leaveFrom;\n const to = phase === 'enter' ? rt.enterTo : rt.leaveTo;\n return startRun(dom, el, active, from, to, rt.duration, onDone);\n}\n\n\n/**\n * Per-container transition controller. One instance is created for each\n * reactive-list / conditional NodeInstance in {@link wireReactiveList}; its\n * `leaving` map persists across every reconcile of that container.\n */\nexport class TransitionController {\n private readonly leaving = new Map<string, LeavingEntry>();\n\n constructor(\n private readonly dom: DOMAdapter,\n private readonly graph: ApplicationGraph,\n /** Full teardown of a leaving instance (remove + dispose + forget + detach). */\n private readonly finalize: (inst: NodeInstance) => void,\n ) {}\n\n /** True only in a real DOM environment (browser). */\n private get browser(): boolean {\n return this.dom.body() !== null;\n }\n\n private keyOf(inst: NodeInstance): string {\n return inst.graphNode.key ?? inst.graphNode.id;\n }\n\n private resolved(node: GraphNode): ResolvedTransitionLike | undefined {\n return getResolvedTransition(this.graph, node.id);\n }\n\n /** Run the enter animation for `inst` if it carries a transition (browser only). */\n enter(inst: NodeInstance): void {\n if (!this.browser) return;\n const rt = this.resolved(inst.graphNode);\n if (rt === undefined) return;\n const el = inst.domNode;\n if (!this.dom.isElement(el)) return;\n startRun(this.dom, el, rt.enterActive, rt.enterFrom, rt.enterTo, rt.duration, () => {\n /* enter has no teardown; classes already cleared by the run */\n });\n }\n\n /**\n * Play `appear` for any initial child that opted into it (fresh browser mount\n * only — hydration must never animate appear, §22, and this is called only on\n * the mount path).\n */\n appear(children: readonly NodeInstance[]): void {\n if (!this.browser) return;\n for (const child of children) {\n const rt = this.resolved(child.graphNode);\n if (rt !== undefined && rt.appear) this.enter(child);\n }\n }\n\n hooks(): TransitionHooks {\n return {\n takeLeaving: (key) => {\n const entry = this.leaving.get(key);\n if (entry === undefined) return undefined;\n entry.run.cancel(); // leave→enter: stop the leave, keep the live node\n this.leaving.delete(key);\n return entry.inst;\n },\n beginLeave: (inst) => {\n if (!this.browser) return false;\n const rt = this.resolved(inst.graphNode);\n if (rt === undefined) return false;\n const el = inst.domNode;\n if (!this.dom.isElement(el)) return false;\n const key = this.keyOf(inst);\n // If a prior leave for this key is somehow still running, settle it.\n const prior = this.leaving.get(key);\n if (prior !== undefined) prior.run.cancel();\n const run = startRun(\n this.dom,\n el,\n rt.leaveActive,\n rt.leaveFrom,\n rt.leaveTo,\n rt.duration,\n () => {\n // Only finalize if THIS run is still the registered one (it may have\n // been reclaimed by a re-entering key, which cancels without done).\n const current = this.leaving.get(key);\n if (current !== undefined && current.run === run) {\n this.leaving.delete(key);\n this.finalize(inst);\n }\n },\n );\n this.leaving.set(key, { inst, run });\n return true;\n },\n onEnter: (inst) => this.enter(inst),\n };\n }\n}\n","/**\n * Initial mount — creates DOM nodes for every GraphNode and\n * attaches them into the container.\n *\n * This is a recursive depth-first walk. For each GraphNode:\n * 1. Create the DOM element (or text node)\n * 2. Apply props/attributes\n * 3. Wire events\n * 4. Wire signal subscriptions for reactive props\n * 5. Recurse into children\n * 6. Insert into the DOM\n */\n\nimport type { GraphNode, ApplicationGraph } from '@streetui/graph';\nimport type { DOMAdapter } from '@streetui/dom';\nimport {\n focusInitial,\n trapFocus,\n containFocus,\n onEscape,\n rovingMenu,\n saveFocus,\n restoreFocus,\n} from '@streetui/dom';\nimport type { RenderContext } from './render-context.js';\nimport { NodeInstance } from './node-instance.js';\nimport { applyProp } from './attributes.js';\nimport { wireEvents } from './events.js';\nimport { resolveTag } from './tag-map.js';\nimport {\n reconcileChildren,\n reconcileChildrenByPlan,\n type PlanEntry,\n} from './reconciliation.js';\nimport { TransitionController, type TransitionHooks } from './transition.js';\n\n/**\n * Prop keys handled by the per-type mount branches (or reserved internals), so\n * `applyNodeProps` must skip them to avoid double-applying. This set is\n * invariant across nodes, so it is hoisted to module scope: allocating it once\n * (rather than per node) removes N Set allocations per mount/SSR pass and the\n * GC pressure they create. Treat as read-only — never mutate.\n */\nconst SKIP_PROP_KEYS: ReadonlySet<string> = new Set([\n 'text', 'label', 'level', 'inputType', 'src', 'alt', 'href', 'external',\n 'value', 'placeholder', 'disabled', '_renderKey', 'key', 'name',\n]);\n\nexport function mountGraph(ctx: RenderContext): NodeInstance {\n return mountNode(ctx, ctx.graph.root, ctx.container);\n}\n\nexport function mountNode(\n ctx: RenderContext,\n graphNode: GraphNode,\n parentDom: Node,\n): NodeInstance {\n const { dom, graph } = ctx;\n\n // ── v1.7 static SSR fast path (SSR-only) ──────────────────────────────────\n // When a compiler-derived static SSR plan is present (server render only)\n // and this node is a maximal static-subtree root, emit its precomputed HTML\n // verbatim instead of recursively constructing ServerElement/ServerText/\n // NodeInstance for the whole subtree. `ctx.staticHTML` is always undefined on\n // the browser path, so this is a single short-circuiting check there — the\n // client hot path and its semantics are untouched (§5/§6/§23). The stored\n // string is produced by this same mount+serialize pipeline, so output is\n // byte-identical (§8). We still register ONE NodeInstance for the root so the\n // parent's children bookkeeping and post-render dispose behave normally.\n const staticHTML = ctx.staticHTML;\n if (staticHTML !== undefined && dom.createRawHTML !== undefined) {\n const precomputed = staticHTML.get(graphNode.id);\n if (precomputed !== undefined) {\n const raw = dom.createRawHTML(precomputed);\n dom.appendChild(parentDom, raw);\n const instance = new NodeInstance(graphNode, raw);\n ctx.instances.set(graphNode.id, instance);\n return instance;\n }\n }\n\n // The application root node maps to the container itself — don't create a duplicate element\n if (graphNode.type === 'application') {\n const instance = new NodeInstance(graphNode, parentDom);\n ctx.instances.set(graphNode.id, instance);\n for (const child of graphNode.children) {\n const childInstance = mountNode(ctx, child, parentDom);\n instance.addChild(childInstance);\n }\n return instance;\n }\n\n // Text-only nodes render as a <span> containing a text node\n if (graphNode.type === 'text') {\n const text = String(graphNode.getProp('text') ?? '');\n const el = dom.createElement('span');\n const textNode = dom.createTextNode(text);\n dom.appendChild(el, textNode);\n applyNodeProps(ctx, graphNode, el);\n\n // Create the live instance up front and reuse it for event wiring. The\n // previous code allocated a throwaway NodeInstance solely to satisfy\n // wireEvents' signature, wasting one NodeInstance (+ its children array and\n // CleanupRegistry) per text node — pure GC pressure on the hottest mount\n // path. wireEvents/wireSignalBindings each early-return on empty arrays.\n const instance = new NodeInstance(graphNode, el);\n ctx.instances.set(graphNode.id, instance);\n wireEvents(dom, graph, graphNode, el, instance);\n\n // Reactive text binding — only build the update closure when the node has\n // bindings. wireSignalBindings early-returns on empty stateRefs, so for a\n // static text node (the common case in a large initial render) the\n // textUpdate closure would be allocated and thrown away: avoidable GC\n // pressure on the hottest mount path.\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, textUpdate(dom, el, textNode));\n }\n\n dom.appendChild(parentDom, el);\n return instance;\n }\n\n // Heading nodes\n if (graphNode.type === 'heading') {\n const level = (graphNode.getProp('level') as number | undefined) ?? 1;\n const tag = `h${level}` as string;\n const el = dom.createElement(tag);\n const text = String(graphNode.getProp('text') ?? '');\n dom.setTextContent(el, text);\n applyNodeProps(ctx, graphNode, el);\n\n const instance = new NodeInstance(graphNode, el);\n ctx.instances.set(graphNode.id, instance);\n wireEvents(dom, graph, graphNode, el, instance);\n\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, headingUpdate(dom, el));\n }\n\n dom.appendChild(parentDom, el);\n return instance;\n }\n\n // Input nodes\n if (graphNode.type === 'input') {\n const el = dom.createElement('input') as HTMLInputElement;\n const inputType = String(graphNode.getProp('inputType') ?? 'text');\n dom.setAttribute(el, 'type', inputType);\n const placeholder = graphNode.getProp('placeholder');\n if (placeholder !== undefined) dom.setAttribute(el, 'placeholder', String(placeholder));\n const value = graphNode.getProp('value');\n if (value !== undefined) dom.setProperty(el, 'value', String(value));\n applyNodeProps(ctx, graphNode, el);\n\n const instance = new NodeInstance(graphNode, el);\n ctx.instances.set(graphNode.id, instance);\n wireEvents(dom, graph, graphNode, el, instance);\n\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, inputUpdate(dom, el));\n }\n\n dom.appendChild(parentDom, el);\n return instance;\n }\n\n // Image nodes\n if (graphNode.type === 'image') {\n const el = dom.createElement('img') as HTMLImageElement;\n const src = graphNode.getProp('src');\n const alt = graphNode.getProp('alt');\n if (src !== undefined) dom.setAttribute(el, 'src', String(src));\n if (alt !== undefined) dom.setAttribute(el, 'alt', String(alt));\n const width = graphNode.getProp('width');\n const height = graphNode.getProp('height');\n if (width !== undefined) dom.setAttribute(el, 'width', String(width));\n if (height !== undefined) dom.setAttribute(el, 'height', String(height));\n applyNodeProps(ctx, graphNode, el);\n\n const instance = new NodeInstance(graphNode, el);\n ctx.instances.set(graphNode.id, instance);\n dom.appendChild(parentDom, el);\n return instance;\n }\n\n // Link nodes\n if (graphNode.type === 'link') {\n const el = dom.createElement('a') as HTMLAnchorElement;\n const href = graphNode.getProp('href');\n const label = graphNode.getProp('label');\n const external = graphNode.getProp('external');\n if (href !== undefined) dom.setAttribute(el, 'href', String(href));\n if (label !== undefined) dom.setTextContent(el, String(label));\n if (external === true) {\n dom.setAttribute(el, 'target', '_blank');\n dom.setAttribute(el, 'rel', 'noopener noreferrer');\n }\n applyNodeProps(ctx, graphNode, el);\n\n const instance = new NodeInstance(graphNode, el);\n ctx.instances.set(graphNode.id, instance);\n wireEvents(dom, graph, graphNode, el, instance);\n dom.appendChild(parentDom, el);\n return instance;\n }\n\n // Button nodes\n if (graphNode.type === 'button') {\n const el = dom.createElement('button') as HTMLButtonElement;\n const label = graphNode.getProp('label');\n if (label !== undefined) dom.setTextContent(el, String(label));\n const disabled = graphNode.getProp('disabled');\n if (disabled === true) dom.setAttribute(el, 'disabled', '');\n applyNodeProps(ctx, graphNode, el);\n\n const instance = new NodeInstance(graphNode, el);\n ctx.instances.set(graphNode.id, instance);\n wireEvents(dom, graph, graphNode, el, instance);\n\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, buttonUpdate(dom, el));\n }\n\n dom.appendChild(parentDom, el);\n return instance;\n }\n\n // Reactive list / conditional — a container whose children are driven by a\n // Signal. Initial child subtrees are already built into the graph by the DSL;\n // on signal change we reconcile the freshly-built desired children against the\n // live DOM using the keyed reconciler (no virtual DOM). A `conditional` uses\n // the identical machinery but renders as a neutral <div> holding 0..1 branch.\n if (graphNode.type === 'reactive-list' || graphNode.type === 'conditional') {\n const tag = resolveTag(graphNode.type);\n const el = dom.createElement(tag);\n applyNodeProps(ctx, graphNode, el);\n\n const instance = new NodeInstance(graphNode, el);\n ctx.instances.set(graphNode.id, instance);\n\n for (const child of graphNode.children) {\n const childInstance = mountNode(ctx, child, el);\n instance.addChild(childInstance);\n }\n\n dom.appendChild(parentDom, el);\n wireReactiveList(ctx, graphNode, instance, el, true);\n return instance;\n }\n\n // Portal — a container whose children are relocated to a different DOM\n // location (document.body) on the browser, while a neutral inline anchor\n // stays at the declaration site. On the server there is no body, so the\n // children render inline in the anchor (deterministic HTML; hydration then\n // relocates them). This is the substrate for overlays (dialog/popover/…):\n // `wireOverlayBehavior` reads an optional `__overlay__<id>` descriptor and,\n // when present, wires focus trap/restore/containment/escape to the open\n // signal. A plain portal has no descriptor, so overlay wiring is a no-op.\n if (graphNode.type === 'portal') {\n const anchor = dom.createElement(resolveTag('portal'));\n dom.setAttribute(anchor, 'data-streetui-portal', '');\n applyNodeProps(ctx, graphNode, anchor);\n const instance = new NodeInstance(graphNode, anchor);\n ctx.instances.set(graphNode.id, instance);\n\n const body = dom.body();\n let target: Element = anchor; // SSR / no body → render inline in the anchor\n if (body !== null) {\n const portalContainer = dom.createElement('div');\n dom.setAttribute(portalContainer, 'data-streetui-portal-container', '');\n dom.appendChild(body, portalContainer);\n instance.trackCleanup(() => dom.removeChild(body, portalContainer));\n target = portalContainer;\n }\n\n for (const child of graphNode.children) {\n instance.addChild(mountNode(ctx, child, target));\n }\n\n dom.appendChild(parentDom, anchor);\n wireOverlayBehavior(ctx, graphNode, instance, target);\n return instance;\n }\n\n // Container / section / page / form / list / list-item — structural nodes\n const tag = resolveTag(graphNode.type);\n const el = dom.createElement(tag);\n applyNodeProps(ctx, graphNode, el);\n\n // Surface a reactive-list item's stable, identity-only reconciliation key as a\n // public `data-streetui-key` attribute (e.g. \"id:1\"). This exposes only the\n // identity part — never the internal `_sig` value signature, signal ids or\n // graph node ids — so a row is directly selectable and its identity is\n // inspectable across reorders and in-place data updates.\n if (graphNode.type === 'list-item') {\n const itemKey = graphNode.getProp('key');\n if (itemKey !== undefined) {\n dom.setAttribute(el, 'data-streetui-key', String(itemKey));\n }\n }\n\n const instance = new NodeInstance(graphNode, el);\n ctx.instances.set(graphNode.id, instance);\n\n // wire form submit (reuse the live instance rather than a throwaway)\n if (graphNode.type === 'form') {\n wireEvents(dom, graph, graphNode, el, instance);\n }\n\n // Recurse into children\n for (const child of graphNode.children) {\n const childInstance = mountNode(ctx, child, el);\n instance.addChild(childInstance);\n }\n\n dom.appendChild(parentDom, el);\n if (graphNode.type === 'component') wireComponentBehavior(ctx, graphNode, instance);\n return instance;\n}\n\n// ── Helpers ───────────────────────────────────────────────────────────────────\n\n/**\n * Per-node-type reactive-binding factories. Each returns the `onUpdate`\n * callback that `wireSignalBindings` invokes when a bound signal changes.\n * Extracted so both the browser mount path and the hydration path apply the\n * exact same DOM mutation semantics for each prop — no duplicated rendering\n * logic.\n */\nexport function textUpdate(\n dom: DOMAdapter,\n el: Element,\n textNode: Text,\n): (propKey: string, value: unknown) => void {\n return (propKey, value) => {\n if (propKey === 'text') {\n dom.setTextContent(textNode, String(value ?? ''));\n } else {\n applyProp(dom, el, propKey, value);\n }\n };\n}\n\nexport function headingUpdate(\n dom: DOMAdapter,\n el: Element,\n): (propKey: string, value: unknown) => void {\n return (propKey, value) => {\n if (propKey === 'text') {\n dom.setTextContent(el, String(value ?? ''));\n } else {\n applyProp(dom, el, propKey, value);\n }\n };\n}\n\nexport function inputUpdate(\n dom: DOMAdapter,\n el: Element,\n): (propKey: string, value: unknown) => void {\n return (propKey, value) => {\n if (propKey === 'value') {\n dom.setProperty(el, 'value', String(value ?? ''));\n } else {\n applyProp(dom, el, propKey, value);\n }\n };\n}\n\nexport function buttonUpdate(\n dom: DOMAdapter,\n el: Element,\n): (propKey: string, value: unknown) => void {\n return (propKey, value) => {\n if (propKey === 'label') {\n dom.setTextContent(el, String(value ?? ''));\n } else if (propKey === 'disabled') {\n if (value === true) {\n dom.setAttribute(el, 'disabled', '');\n } else {\n dom.removeAttribute(el, 'disabled');\n }\n } else {\n applyProp(dom, el, propKey, value);\n }\n };\n}\n\nexport function applyNodeProps(ctx: RenderContext, graphNode: GraphNode, el: Element): void {\n // Iterate own enumerable keys directly rather than via Object.entries, which\n // allocates a wrapper array plus one [key,value] tuple per prop — measurable\n // GC pressure when multiplied across every node in a large initial render.\n const props = graphNode.props;\n for (const key in props) {\n if (!Object.hasOwn(props, key)) continue;\n if (SKIP_PROP_KEYS.has(key)) continue;\n applyProp(ctx.dom, el, key, props[key]);\n }\n}\n\nexport function wireSignalBindings(\n ctx: RenderContext,\n graphNode: GraphNode,\n instance: NodeInstance,\n onUpdate: (propKey: string, value: unknown) => void,\n): void {\n // Fast exit for the common non-reactive node — avoids allocating a for-of\n // iterator over an empty stateRefs array on every static node.\n if (graphNode.stateRefs.length === 0) return;\n for (const stateRef of graphNode.stateRefs) {\n const signalKey = `__signal__${stateRef.signalId}`;\n const maybeSig = ctx.graph.getHandler(signalKey) as\n | { subscribe: (fn: (v: unknown) => void) => () => void; peek: () => unknown }\n | undefined;\n if (maybeSig === undefined || typeof maybeSig.subscribe !== 'function') continue;\n\n // Subscribe directly — avoids the ReadonlySignal<T> generic variance issue\n const unsub = maybeSig.subscribe((value) => {\n onUpdate(stateRef.propKey, value);\n });\n instance.trackCleanup(unsub);\n }\n}\n\n// ── Reactive list wiring ────────────────────────────────────────────────────────\n\ntype ListBuildFn = (items: unknown) => GraphNode[];\ntype ListPlanFn = (items: unknown) => PlanEntry[];\n\n/**\n * Subscribe a reactive-list instance to its driving signal. On each change the\n * DSL-registered plan factory produces lightweight per-row descriptors, which\n * are reconciled against the live DOM with the keyed, minimal-move reconciler\n * (spec §15). A `conditional` node has no plan handler and falls back to the\n * eager build factory (it only ever renders 0..1 branch, so eager is fine).\n */\nexport function wireReactiveList(\n ctx: RenderContext,\n graphNode: GraphNode,\n instance: NodeInstance,\n el: Element,\n runAppear = false,\n): void {\n const plan = ctx.graph.getHandler(`__listplan__${graphNode.id}`) as\n | ListPlanFn\n | undefined;\n const build = ctx.graph.getHandler(`__listbuild__${graphNode.id}`) as\n | ListBuildFn\n | undefined;\n if (plan === undefined && build === undefined) return;\n\n // One transition controller per reactive container, created here so its\n // leaving-instance map survives across every reconcile of this container\n // (that persistence is what makes leave→enter reclaim and keyed list-leave\n // correct — §6/§7). `finalize` runs the full deferred teardown chain when a\n // leave animation completes: DOM-remove + dispose + forget + detach, exactly\n // the work the synchronous path splits between the reconciler and the two\n // reconcile* helpers below. On the server (no body) the controller's hooks\n // no-op, so SSR is unchanged (§21).\n const controller = new TransitionController(ctx.dom, ctx.graph, (leaving) => {\n // Full teardown at leave-animation end — the same four steps the synchronous\n // path splits between the reconciler (DOM-remove + dispose) and this helper\n // (forget + detach). Deferred here because `beginLeave` excluded this\n // instance from `result.removed`, so nothing else will tear it down.\n const parent = ctx.dom.parentNode(leaving.domNode);\n if (parent !== null) ctx.dom.removeChild(parent, leaving.domNode);\n leaving.dispose();\n forgetInstance(ctx, leaving);\n ctx.graph.detachNode(leaving.graphNode);\n });\n const hooks = controller.hooks();\n\n // `appear`: animate any initial child that opted in — but ONLY on a fresh\n // browser mount, never on hydration (§22: the DOM is already present and\n // correct, so appear must not run). The hydrate path calls this with\n // `runAppear` omitted (false).\n if (runAppear) controller.appear(instance.children);\n\n for (const stateRef of graphNode.stateRefs) {\n if (stateRef.propKey !== 'items') continue;\n const sig = ctx.graph.getHandler(`__signal__${stateRef.signalId}`) as\n | { subscribe: (fn: (v: unknown) => void) => () => void }\n | undefined;\n if (sig === undefined || typeof sig.subscribe !== 'function') continue;\n\n const unsub = sig.subscribe((value) => {\n if (plan !== undefined) {\n reconcileReactiveListByPlan(ctx, graphNode, instance, el, plan(value), hooks);\n } else {\n reconcileReactiveList(ctx, graphNode, instance, el, build!(value), hooks);\n }\n });\n instance.trackCleanup(unsub);\n }\n}\n\nfunction reconcileReactiveListByPlan(\n ctx: RenderContext,\n listNode: GraphNode,\n listInstance: NodeInstance,\n listEl: Element,\n plan: PlanEntry[],\n hooks: TransitionHooks,\n): void {\n const oldInstances = [...listInstance.children];\n const result = reconcileChildrenByPlan(\n ctx,\n listEl,\n oldInstances,\n plan,\n (node, parent) => mountNode(ctx, node, parent),\n hooks,\n );\n\n // Sync the live instance's children to the reconciled order.\n listInstance.children.length = 0;\n for (const inst of result.instances) listInstance.children.push(inst);\n\n // Forget removed instances, and drop their graph nodes.\n for (const removed of result.removed) {\n forgetInstance(ctx, removed);\n ctx.graph.detachNode(removed.graphNode);\n }\n // Detach any freshly-built subtree that was not adopted as a live instance\n // (e.g. the top node of a rebuilt changed row, whose live instance keeps its\n // original graph node).\n const adopted = new Set(result.instances.map((i) => i.graphNode));\n for (const node of result.built ?? []) {\n if (!adopted.has(node)) ctx.graph.detachNode(node);\n }\n\n // Keep the graph model consistent: list node children match the new order.\n for (const child of [...listNode.children]) listNode.removeChild(child);\n for (const inst of result.instances) listNode.appendChild(inst.graphNode);\n}\n\nfunction reconcileReactiveList(\n ctx: RenderContext,\n listNode: GraphNode,\n listInstance: NodeInstance,\n listEl: Element,\n newNodes: GraphNode[],\n hooks: TransitionHooks,\n): void {\n const oldInstances = [...listInstance.children];\n const result = reconcileChildren(\n ctx,\n listEl,\n oldInstances,\n newNodes,\n (node, parent) => mountNode(ctx, node, parent),\n hooks,\n );\n\n // Sync the live instance's children to the reconciled order.\n listInstance.children.length = 0;\n for (const inst of result.instances) listInstance.children.push(inst);\n\n // Forget removed instances from the renderer index, and drop their graph\n // nodes (and any un-adopted freshly-built duplicates) from the graph index.\n for (const removed of result.removed) {\n forgetInstance(ctx, removed);\n ctx.graph.detachNode(removed.graphNode);\n }\n const adopted = new Set(result.instances.map((i) => i.graphNode));\n for (const built of newNodes) {\n if (!adopted.has(built)) ctx.graph.detachNode(built);\n }\n\n // Keep the graph model consistent: list node children match the new order.\n for (const child of [...listNode.children]) listNode.removeChild(child);\n for (const inst of result.instances) listNode.appendChild(inst.graphNode);\n}\n\n/** Recursively remove an instance subtree from the renderer's instance index. */\nfunction forgetInstance(ctx: RenderContext, instance: NodeInstance): void {\n ctx.instances.delete(instance.graphNode.id);\n for (const child of instance.children) forgetInstance(ctx, child);\n}\n\n// ── Overlay behavior wiring ─────────────────────────────────────────────────────\n\n/**\n * Opaque overlay descriptor, read from the `__overlay__<portalId>` handler that\n * the DSL registers for dialog/popover/tooltip/dropdown/toast. Declared here as\n * a local structural type (mirroring the list plan/build handler pattern) so the\n * renderer never takes a compile-time dependency on the DSL package.\n */\ninterface OverlayBehavior {\n /** Reactive open/visibility state — the same signal that drives the panel's `when()`. */\n readonly open: {\n subscribe: (fn: (v: boolean) => void) => () => void;\n peek: () => unknown;\n };\n /** Trap Tab focus within, and redirect escaped focus back inside (modal semantics). */\n readonly modal: boolean;\n /** Move focus into the panel when it opens. */\n readonly takesFocus: boolean;\n /** Wire arrow/Home/End/Enter/Space roving-focus navigation (role=\"menu\"). */\n readonly menu: boolean;\n /** Escape key invokes `onClose`. */\n readonly closeOnEscape: boolean;\n /** Restore focus to the pre-open element on close. */\n readonly restoreFocus: boolean;\n /** id of the element to focus first when opening. */\n readonly initialFocusId?: string;\n /** Requested-close callback (Escape). The app flips its own open signal here. */\n readonly onClose?: () => void;\n}\n\n/**\n * Attach overlay focus/keyboard behavior to a mounted portal. Server-safe: on\n * the server `dom.body()` is null so this returns immediately (SSR emits inert\n * markup, no focus concept). A plain portal has no `__overlay__` descriptor, so\n * this also returns immediately — the behavior is purely additive.\n *\n * The panel is mounted/unmounted by the portal's inner `when(open, …)`, whose\n * signal subscription is registered *before* this one (the conditional child is\n * mounted earlier in the portal branch). Signal subscribers fire synchronously\n * in subscription order, so on open→true the panel DOM exists before we move\n * focus into it, and on open→false the panel is torn down before we restore\n * focus. All listeners are tracked on the instance and torn down on unmount.\n */\nexport function wireOverlayBehavior(\n ctx: RenderContext,\n graphNode: GraphNode,\n instance: NodeInstance,\n target: Element,\n): void {\n const { dom, graph } = ctx;\n if (dom.body() === null) return; // server / no DOM environment\n\n const descFn = graph.getHandler(`__overlay__${graphNode.id}`) as\n | (() => OverlayBehavior)\n | undefined;\n if (descFn === undefined) return; // plain portal — no overlay behavior\n\n const desc = descFn();\n const openSig = desc.open;\n if (openSig === undefined || typeof openSig.subscribe !== 'function') return;\n\n let active: Array<() => void> = [];\n let saved: Element | null = null;\n\n const teardown = (): void => {\n for (const fn of active) fn();\n active = [];\n };\n\n const onOpenChange = (isOpen: boolean): void => {\n if (isOpen) {\n if (desc.restoreFocus) saved = saveFocus(dom);\n // Establish containment/roving BEFORE moving focus in, so that when a\n // nested modal opens it becomes the authoritative focus owner before its\n // initial focus fires — otherwise the outer modal's still-active\n // containment would pull that focus back out (§16).\n if (desc.modal) {\n active.push(trapFocus(dom, target));\n active.push(containFocus(dom, target));\n }\n if (desc.menu) {\n active.push(rovingMenu(dom, target));\n }\n if (desc.takesFocus) focusInitial(dom, target, desc.initialFocusId);\n if (desc.closeOnEscape && desc.onClose !== undefined) {\n active.push(onEscape(dom, target, desc.onClose));\n }\n } else {\n teardown();\n if (desc.restoreFocus && saved !== null) {\n restoreFocus(dom, saved);\n saved = null;\n }\n }\n };\n\n const unsub = openSig.subscribe(onOpenChange);\n instance.trackCleanup(unsub);\n instance.trackCleanup(teardown);\n\n // `subscribe` fires only on change; an overlay that is open on initial mount\n // has its panel already built into the graph, so run the open path now.\n if (openSig.peek() === true) onOpenChange(true);\n}\n\n/**\n * Wire a component instance's lifecycle (§9). Reads the optional\n * `__component__<id>` descriptor — an array of teardown callbacks the DSL's\n * `component()` collected from the setup's `ctx.effect`/`ctx.onCleanup` — and\n * routes each into `NodeInstance.trackCleanup`, so they run (children-first)\n * when the component leaves the graph. Shared by the mount and hydrate paths so\n * both attach identical ownership. A `'component'` node with no cleanups (no\n * effects/resources) registers no descriptor and this is a no-op.\n */\nexport function wireComponentBehavior(\n ctx: RenderContext,\n graphNode: GraphNode,\n instance: NodeInstance,\n): void {\n const fn = ctx.graph.getHandler(`__component__${graphNode.id}`) as\n | (() => Array<() => void>)\n | undefined;\n if (fn === undefined) return;\n for (const cleanup of fn()) instance.trackCleanup(cleanup);\n}\n","/**\n * Hydration diagnostics — dev-only, opt-in explanations of hydration mismatches.\n *\n * Hydration is self-repairing: when the server-rendered DOM does not match the\n * graph at a position, the renderer mounts a fresh subtree in place and drops\n * the offending element (see `hydrateChildren` in `hydrate.ts`). That recovery\n * is silent by design — a local mismatch must never tear down the whole app.\n *\n * During development, though, a silent repair hides a real problem (usually a\n * server/client divergence). A `HydrationDiagnosticSink` can be attached to the\n * renderer to *observe* those repairs without changing them: for every mismatch\n * the renderer reports what it expected, what it found, where, and what it did\n * to recover. Nothing is thrown, nothing is mutated differently, and when no\n * sink is attached there is zero additional work on the hydration path.\n */\n\n/** What kind of divergence the hydrator encountered at a position. */\nexport type HydrationMismatchType =\n | 'tag-mismatch' // an element existed but was the wrong tag\n | 'missing-element' // the graph expected a child the DOM did not provide\n | 'surplus-element'; // the DOM had a child the graph no longer expects\n\n/** A single, fully-described hydration divergence and the repair taken. */\nexport interface HydrationDiagnostic {\n /** The category of mismatch. */\n readonly type: HydrationMismatchType;\n /** The tag the graph expected at this position (null for a surplus element). */\n readonly expected: string | null;\n /** The tag actually found in the server DOM (null for a missing element). */\n readonly found: string | null;\n /** A human-readable path to the position, e.g. `app / page[0] / section[1]`. */\n readonly path: string;\n /** The graph node id involved, when one exists (null for surplus DOM). */\n readonly nodeId: string | null;\n /** The semantic node type involved, when one exists (null for surplus DOM). */\n readonly nodeType: string | null;\n /** The recovery action the renderer performed. */\n readonly action: string;\n /** A single-line, developer-facing summary of the whole diagnostic. */\n readonly message: string;\n}\n\n/**\n * Receives hydration diagnostics as they are discovered. Kept intentionally\n * tiny so any logger — `console`, a test collector, a `DiagnosticSink` — can\n * satisfy it. Implementations must not throw.\n */\nexport interface HydrationDiagnosticSink {\n report(diagnostic: HydrationDiagnostic): void;\n}\n\n/** Build the canonical one-line message for a diagnostic. */\nexport function formatHydrationDiagnostic(\n d: Omit<HydrationDiagnostic, 'message'>,\n): string {\n const at = ` at ${d.path}`;\n switch (d.type) {\n case 'tag-mismatch':\n return `Hydration mismatch${at} — Expected: ${d.expected} / Found: ${d.found} / Action: ${d.action}`;\n case 'missing-element':\n return `Hydration mismatch${at} — Expected: ${d.expected} / Found: (nothing) / Action: ${d.action}`;\n case 'surplus-element':\n return `Hydration mismatch${at} — Expected: (nothing) / Found: ${d.found} / Action: ${d.action}`;\n }\n}\n\n/**\n * A ready-made sink that accumulates diagnostics into an array — the shape most\n * useful for tests and for a DevTools panel. The returned `diagnostics` array is\n * appended to in-place as repairs happen.\n */\nexport function createHydrationDiagnosticCollector(): {\n readonly sink: HydrationDiagnosticSink;\n readonly diagnostics: HydrationDiagnostic[];\n} {\n const diagnostics: HydrationDiagnostic[] = [];\n return {\n diagnostics,\n sink: {\n report(d) {\n diagnostics.push(d);\n },\n },\n };\n}\n\n/**\n * A sink that forwards each diagnostic to a `console`-like logger as a single\n * warning line. Handy default when you just want the messages surfaced in dev.\n */\nexport function consoleHydrationDiagnosticSink(\n logger: { warn(message: string): void } = console,\n): HydrationDiagnosticSink {\n return {\n report(d) {\n logger.warn(d.message);\n },\n };\n}\n","/**\n * Hydration — attach a live StreetUI runtime to server-rendered HTML.\n *\n * `hydrate` walks the semantic application graph top-down against the DOM that\n * the server already produced. For every graph node it *adopts* the matching\n * existing element (creating a `NodeInstance` that points at it) and attaches\n * behavior — event listeners and signal subscriptions — using the exact same\n * helpers the browser mount path uses (`wireEvents`, `wireSignalBindings`,\n * `wireReactiveList`, and the per-type update factories). Nothing is recreated\n * when the DOM matches.\n *\n * Matching is positional and works because every non-application graph node\n * maps to exactly one element (see mount.ts). When the element at a position\n * does not match the expected tag (or is missing), only that subtree is\n * repaired: the fresh subtree is mounted and spliced into place, leaving the\n * rest of the hydrated tree untouched. A local mismatch never tears down the\n * whole app.\n */\n\nimport type { GraphNode } from '@streetui/graph';\nimport type { RenderContext } from './render-context.js';\nimport { NodeInstance } from './node-instance.js';\nimport { wireEvents } from './events.js';\nimport { resolveTag } from './tag-map.js';\nimport { formatHydrationDiagnostic } from './hydration-diagnostics.js';\nimport {\n mountNode,\n wireSignalBindings,\n wireReactiveList,\n wireOverlayBehavior,\n wireComponentBehavior,\n textUpdate,\n headingUpdate,\n inputUpdate,\n buttonUpdate,\n} from './mount.js';\n\n/** Hydrate the whole application graph against `ctx.container`. */\nexport function hydrateGraph(ctx: RenderContext): NodeInstance {\n const root = ctx.graph.root;\n // The application root maps to the container itself (no element of its own),\n // exactly as in mountNode.\n const instance = new NodeInstance(root, ctx.container);\n ctx.instances.set(root.id, instance);\n hydrateChildren(ctx, root, instance, ctx.container, 'app');\n return instance;\n}\n\n/**\n * Adopt `domNode` as the live element for `graphNode` and attach behavior.\n * The caller has already verified `domNode` matches `graphNode` (right tag).\n * `path` is the human-readable position used only for dev diagnostics.\n */\nfunction hydrateNode(\n ctx: RenderContext,\n graphNode: GraphNode,\n domNode: Element,\n path: string,\n): NodeInstance {\n const { dom, graph } = ctx;\n\n switch (graphNode.type) {\n case 'text': {\n // <span> with an inner text node. Adopt the text node (or create one if\n // the server markup somehow lacks it).\n let textNode = dom.firstChild(domNode);\n if (textNode === null || !dom.isTextNode(textNode)) {\n const created = dom.createTextNode(String(graphNode.getProp('text') ?? ''));\n dom.appendChild(domNode, created);\n textNode = created;\n }\n const instance = new NodeInstance(graphNode, domNode);\n ctx.instances.set(graphNode.id, instance);\n wireEvents(dom, graph, graphNode, domNode, instance);\n // Only build the per-type update closure when the node actually has\n // reactive bindings. wireSignalBindings early-returns on an empty\n // stateRefs list, so for a static node the `textUpdate(...)` closure would\n // be allocated and immediately discarded — pure GC pressure on the hot\n // hydration path, where the vast majority of nodes are static.\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, textUpdate(dom, domNode, textNode as Text));\n }\n return instance;\n }\n\n case 'heading': {\n const instance = new NodeInstance(graphNode, domNode);\n ctx.instances.set(graphNode.id, instance);\n wireEvents(dom, graph, graphNode, domNode, instance);\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, headingUpdate(dom, domNode));\n }\n return instance;\n }\n\n case 'input': {\n const instance = new NodeInstance(graphNode, domNode);\n ctx.instances.set(graphNode.id, instance);\n // The controlled value is already present in the server HTML (reflected as\n // the `value` attribute). Re-assert it as a live property so the element's\n // current value matches the bound signal exactly.\n const value = graphNode.getProp('value');\n if (value !== undefined) dom.setProperty(domNode, 'value', String(value));\n wireEvents(dom, graph, graphNode, domNode, instance);\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, inputUpdate(dom, domNode));\n }\n return instance;\n }\n\n case 'button': {\n const instance = new NodeInstance(graphNode, domNode);\n ctx.instances.set(graphNode.id, instance);\n wireEvents(dom, graph, graphNode, domNode, instance);\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, buttonUpdate(dom, domNode));\n }\n return instance;\n }\n\n case 'image':\n case 'link': {\n // Leaf elements with no reactive bindings or events beyond what the markup\n // already encodes; links may still carry click handlers.\n const instance = new NodeInstance(graphNode, domNode);\n ctx.instances.set(graphNode.id, instance);\n if (graphNode.type === 'link') wireEvents(dom, graph, graphNode, domNode, instance);\n return instance;\n }\n\n case 'reactive-list':\n case 'conditional': {\n // The server rendered the initial children (built into the graph at\n // compile time from the initial signal state). Adopt them positionally,\n // then subscribe for future signal changes — the same keyed reconciler as\n // the browser drives subsequent updates against the adopted instances.\n const instance = new NodeInstance(graphNode, domNode);\n ctx.instances.set(graphNode.id, instance);\n hydrateChildren(ctx, graphNode, instance, domNode, path);\n wireReactiveList(ctx, graphNode, instance, domNode);\n return instance;\n }\n\n case 'portal': {\n // The server rendered the portal's children INLINE inside the anchor\n // (no body on the server). Adopt the anchor, then — before positional\n // child hydration — relocate those inline children into a fresh\n // document.body container so their live location matches the browser\n // mount path exactly (and there is no positional mismatch). Hydrate the\n // children against the body container, then wire any overlay behavior.\n const instance = new NodeInstance(graphNode, domNode);\n ctx.instances.set(graphNode.id, instance);\n const body = dom.body();\n let target: Element = domNode;\n if (body !== null) {\n const portalContainer = dom.createElement('div');\n dom.setAttribute(portalContainer, 'data-streetui-portal-container', '');\n // `childNodes` returns a snapshot array, so moving during iteration is\n // safe. appendChild re-parents each node out of the anchor.\n for (const child of dom.childNodes(domNode)) {\n dom.appendChild(portalContainer, child);\n }\n dom.appendChild(body, portalContainer);\n instance.trackCleanup(() => dom.removeChild(body, portalContainer));\n target = portalContainer;\n }\n hydrateChildren(ctx, graphNode, instance, target, path);\n wireOverlayBehavior(ctx, graphNode, instance, target);\n return instance;\n }\n\n default: {\n // Structural nodes: container / section / page / form / list / list-item.\n const instance = new NodeInstance(graphNode, domNode);\n ctx.instances.set(graphNode.id, instance);\n if (graphNode.type === 'form') {\n wireEvents(dom, graph, graphNode, domNode, instance);\n }\n // Hydration boundary (a \"slot\" such as the router outlet): adopt the\n // element itself but leave its existing children untouched — neither\n // hydrated by this pass nor removed as surplus. Something else (e.g. the\n // router) owns and will hydrate the content already inside it. Without\n // this, an empty-in-the-graph slot would strip the server-rendered\n // content it is meant to preserve.\n if (graphNode.getProp('_hydrationBoundary') === true) {\n return instance;\n }\n hydrateChildren(ctx, graphNode, instance, domNode, path);\n if (graphNode.type === 'component') wireComponentBehavior(ctx, graphNode, instance);\n return instance;\n }\n }\n}\n\n// ── Child matching + local mismatch recovery ───────────────────────────────────\n\n/**\n * Positionally match a parent's expected child graph nodes against the actual\n * child *elements* in the DOM. Matching children are hydrated in place; a\n * mismatch (wrong tag or a missing element) triggers a local repair — the fresh\n * subtree is mounted and spliced into the correct position — without disturbing\n * sibling subtrees. Surplus DOM elements are removed.\n */\nfunction hydrateChildren(\n ctx: RenderContext,\n parentGraphNode: GraphNode,\n parentInstance: NodeInstance,\n parentDom: Element,\n parentPath: string,\n): void {\n const expected = parentGraphNode.children;\n const actual = elementChildren(ctx, parentDom);\n let cursor = 0;\n\n // The human-readable `path` is only ever consumed by hydration diagnostics,\n // which are inert unless a sink is attached. Building the\n // `${parentPath} / ${type}[${i}]` string for every child would allocate one\n // throwaway string per node on the hot path (10k+ on a large tree) for output\n // that is discarded in production. Gate the construction on the sink being\n // present; when it is absent, thread the (meaningless-but-unused) parent path\n // through unchanged so nested calls stay allocation-free too.\n const diag = ctx.hydrationDiagnostics !== undefined;\n\n for (let i = 0; i < expected.length; i++) {\n const childNode = expected[i]!;\n const want = expectedTag(ctx, childNode);\n const childPath = diag ? `${parentPath} / ${childNode.type}[${i}]` : parentPath;\n const actualEl = actual[cursor];\n\n if (\n actualEl !== undefined &&\n ctx.dom.isElement(actualEl) &&\n ctx.dom.tagName(actualEl) === want\n ) {\n // Match — adopt the existing element.\n const inst = hydrateNode(ctx, childNode, actualEl, childPath);\n parentInstance.addChild(inst);\n cursor++;\n } else {\n // Mismatch or missing — repair only this subtree. Mount fresh, then move\n // it into the correct position ahead of the offending/absent node.\n const ref = actualEl ?? null;\n const inst = mountFreshAt(ctx, childNode, parentDom, ref);\n parentInstance.addChild(inst);\n if (actualEl !== undefined) {\n // Drop the mismatched element that the fresh node replaces.\n const found = ctx.dom.isElement(actualEl) ? ctx.dom.tagName(actualEl) : null;\n reportHydrationDiagnostic(ctx, {\n type: 'tag-mismatch',\n expected: want,\n found,\n path: childPath,\n nodeId: childNode.id,\n nodeType: childNode.type,\n action: 'mounted fresh subtree in place',\n });\n ctx.dom.removeChild(parentDom, actualEl);\n cursor++;\n } else {\n reportHydrationDiagnostic(ctx, {\n type: 'missing-element',\n expected: want,\n found: null,\n path: childPath,\n nodeId: childNode.id,\n nodeType: childNode.type,\n action: 'mounted fresh subtree',\n });\n }\n }\n }\n\n // Remove any surplus server elements the graph no longer expects.\n for (let i = cursor; i < actual.length; i++) {\n const surplus = actual[i]!;\n reportHydrationDiagnostic(ctx, {\n type: 'surplus-element',\n expected: null,\n found: ctx.dom.isElement(surplus) ? ctx.dom.tagName(surplus) : null,\n path: `${parentPath} / [surplus ${i}]`,\n nodeId: null,\n nodeType: null,\n action: 'removed surplus server element',\n });\n ctx.dom.removeChild(parentDom, surplus);\n }\n}\n\n/**\n * Emit a hydration diagnostic through the (optional) sink. When no sink is\n * attached this is a single cheap `undefined` check — the production default.\n */\nfunction reportHydrationDiagnostic(\n ctx: RenderContext,\n d: {\n type: 'tag-mismatch' | 'missing-element' | 'surplus-element';\n expected: string | null;\n found: string | null;\n path: string;\n nodeId: string | null;\n nodeType: string | null;\n action: string;\n },\n): void {\n const sink = ctx.hydrationDiagnostics;\n if (sink === undefined) return;\n sink.report({ ...d, message: formatHydrationDiagnostic(d) });\n}\n\n/** Mount a fresh subtree for `node` and splice it before `ref` (or append). */\nfunction mountFreshAt(\n ctx: RenderContext,\n node: GraphNode,\n parentDom: Element,\n ref: Node | null,\n): NodeInstance {\n // mountNode appends the new subtree at the end of parentDom.\n const inst = mountNode(ctx, node, parentDom);\n if (ref !== null) {\n ctx.dom.insertBefore(parentDom, inst.domNode, ref);\n }\n return inst;\n}\n\n/** The element (not text/comment) children of a node, in order. */\nfunction elementChildren(ctx: RenderContext, parent: Element): Element[] {\n const out: Element[] = [];\n for (const node of ctx.dom.childNodes(parent)) {\n if (ctx.dom.isElement(node)) out.push(node);\n }\n return out;\n}\n\n/** The HTML tag a graph node is expected to occupy in the DOM. */\nfunction expectedTag(ctx: RenderContext, graphNode: GraphNode): string {\n switch (graphNode.type) {\n case 'text':\n return 'span';\n case 'heading': {\n const level = (graphNode.getProp('level') as number | undefined) ?? 1;\n return `h${level}`;\n }\n case 'input':\n return 'input';\n case 'image':\n return 'img';\n case 'link':\n return 'a';\n case 'button':\n return 'button';\n default:\n // reactive-list → ul, conditional → div, structural → resolveTag.\n return resolveTag(graphNode.type);\n }\n}\n","/**\n * StreetRenderHandle — the live handle returned by both `mount` and `hydrate`.\n *\n * Owns teardown for a mounted/hydrated application: disposes every NodeInstance\n * (removing event listeners and signal subscriptions) and clears the container\n * through the DOM adapter (never raw browser globals), so the same handle works\n * for browser and — in principle — server-driven teardown.\n */\n\nimport type { RenderHandle } from '@streetui/runtime';\nimport type { RenderContext } from './render-context.js';\nimport type { NodeInstance } from './node-instance.js';\n\nexport class StreetRenderHandle implements RenderHandle {\n private _disposed = false;\n private readonly _ctx: RenderContext;\n private readonly _rootInstance: NodeInstance;\n\n constructor(ctx: RenderContext, rootInstance: NodeInstance) {\n this._ctx = ctx;\n this._rootInstance = rootInstance;\n }\n\n flush(): void {\n if (this._disposed) return;\n // Signal subscriptions fire synchronously in StreetUI's state system;\n // flush() is a no-op at the renderer level — the DOM is already up to date\n // unless the scheduler is batching, in which case the scheduler calls\n // flush() after draining its queue.\n }\n\n unmount(): void {\n if (this._disposed) return;\n this._disposed = true;\n\n // Dispose all node instances (removes event listeners, signal subscriptions).\n this._rootInstance.dispose();\n\n // Remove all children from the container. Routed through the DOM adapter\n // (never `container.firstChild`/`removeChild`) so the teardown path is\n // server-safe.\n const dom = this._ctx.dom;\n const container = this._ctx.container;\n for (const child of dom.childNodes(container)) {\n dom.removeChild(container, child);\n }\n\n this._ctx.instances.clear();\n }\n}\n","/**\n * StreetUI Renderer — framework-owned DOM renderer.\n *\n * No React. No Vue. No virtual-dom. No external rendering library.\n *\n * Pipeline:\n * CompiledApplication\n * → mountGraph (creates all DOM nodes)\n * → signal subscriptions drive patchNode (targeted updates)\n * → flush() propagates any pending scheduler jobs\n * → unmount() disposes everything\n */\n\nimport type { DOMAdapter } from '@streetui/dom';\nimport { BrowserDOMAdapter } from '@streetui/dom';\nimport type { CompiledApplication } from '@streetui/compiler';\nimport type { StreetRenderer, RenderHandle } from '@streetui/runtime';\nimport { createRenderContext } from './render-context.js';\nimport { mountGraph } from './mount.js';\nimport { hydrateGraph } from './hydrate.js';\nimport { StreetRenderHandle } from './render-handle.js';\nimport type { NodeInstance } from './node-instance.js';\nimport type { HydrationDiagnosticSink } from './hydration-diagnostics.js';\n\nexport interface StreetRendererOptions {\n /** Override the DOM adapter (e.g. for testing). Defaults to BrowserDOMAdapter. */\n readonly domAdapter?: DOMAdapter;\n /**\n * Optional dev-only sink that observes hydration mismatch repairs. Attach one\n * to surface server/client divergences during development; leave it unset in\n * production so hydration does no extra work.\n */\n readonly hydrationDiagnostics?: HydrationDiagnosticSink;\n}\n\nexport class StreetRendererImpl implements StreetRenderer {\n private readonly _dom: DOMAdapter;\n private readonly _hydrationDiagnostics?: HydrationDiagnosticSink;\n\n constructor(options: StreetRendererOptions = {}) {\n this._dom = options.domAdapter ?? new BrowserDOMAdapter();\n if (options.hydrationDiagnostics !== undefined) {\n this._hydrationDiagnostics = options.hydrationDiagnostics;\n }\n }\n\n mount(compiled: CompiledApplication, container: Element): RenderHandle {\n const ctx = createRenderContext(this._dom, compiled.graph, container);\n\n // Initial mount — creates the full DOM tree\n const rootInstance = mountGraph(ctx);\n\n // Wire all signal subscriptions so that signal → DOM patches happen automatically\n this._wireSignals(ctx, rootInstance);\n\n return new StreetRenderHandle(ctx, rootInstance);\n }\n\n /**\n * Hydrate a container that already holds server-rendered HTML for this\n * application. Instead of recreating the DOM, it walks the semantic graph\n * against the existing nodes, adopting matching elements and attaching\n * behavior (events + signal subscriptions). Mismatched subtrees are locally\n * replaced. Returns the same handle type as `mount`.\n */\n hydrate(compiled: CompiledApplication, container: Element): RenderHandle {\n const ctx = createRenderContext(\n this._dom,\n compiled.graph,\n container,\n this._hydrationDiagnostics,\n );\n const rootInstance = hydrateGraph(ctx);\n this._wireSignals(ctx, rootInstance);\n return new StreetRenderHandle(ctx, rootInstance);\n }\n\n private _wireSignals(\n ctx: ReturnType<typeof createRenderContext>,\n rootInstance: NodeInstance,\n ): void {\n // Each NodeInstance already wired its own signals in mountNode via wireSignalBindings.\n // This method is a hook for any cross-cutting signal concerns at the renderer level.\n // Currently no-op — individual mount calls handle their own subscriptions.\n void ctx;\n void rootInstance;\n }\n}\n\n/**\n * Create the default StreetUI renderer using the browser's DOM APIs.\n */\nexport function createRenderer(options?: StreetRendererOptions): StreetRendererImpl {\n return new StreetRendererImpl(options);\n}\n","/**\n * SSR state transfer (dehydration) — move server-resolved data to the client.\n *\n * When the server resolves resources before rendering, their data must reach\n * the client so hydration can seed them (via `resource({ initialData })`)\n * instead of refetching. StreetUI does this with a single, framework-scoped\n * `<script>` payload rather than blindly interpolating `JSON.stringify` into\n * markup.\n *\n * Safety (v0.4 rule #16): the JSON is emitted into a\n * `<script type=\"application/json\">` block — an inert data island the browser\n * never executes — and every character that could terminate that block or be\n * reinterpreted by the HTML/JS parser is escaped to its `\\uXXXX` form. Because\n * `<` inside JSON parses back to `<`, the payload round-trips exactly\n * while being impossible to break out of. This is deterministic (stable key\n * order is the caller's responsibility) and typed at the boundary as\n * `Record<string, unknown>` — never `any`.\n */\n\nimport type { DOMAdapter } from '@streetui/dom';\n\n/** Attribute marking StreetUI's state island so the client can find it. */\nexport const STATE_MARKER_ATTR = 'data-streetui-state';\n\n/**\n * Escape a JSON string for safe embedding inside a `<script>` element:\n * < > & → HTML / `</script>` breakout and entity ambiguity\n * U+2028 / U+2029 → invalid raw in JS string literals\n * Uses code-point checks so no raw separator characters live in this source.\n */\nfunction escapeForScript(json: string): string {\n let out = '';\n for (const ch of json) {\n const code = ch.charCodeAt(0);\n if (ch === '<') out += '\\\\u003c';\n else if (ch === '>') out += '\\\\u003e';\n else if (ch === '&') out += '\\\\u0026';\n else if (code === 0x2028) out += '\\\\u2028';\n else if (code === 0x2029) out += '\\\\u2029';\n else out += ch;\n }\n return out;\n}\n\n/**\n * Serialize a state map to an HTML `<script>` island for inclusion in the\n * server-rendered document (typically just before the closing tag of the\n * mount container). Returns an empty string for an empty map.\n */\nexport function serializeState(state: Record<string, unknown>): string {\n if (Object.keys(state).length === 0) return '';\n const json = escapeForScript(JSON.stringify(state));\n return `<script type=\"application/json\" ${STATE_MARKER_ATTR}>${json}</script>`;\n}\n\n/**\n * Read the state island back on the client. Searches `root` for StreetUI's\n * state `<script>` and parses it. Returns an empty object when absent or\n * unparseable (hydration then proceeds as a cold client render). Routed through\n * the DOM adapter so it is testable and never assumes a global `document`.\n */\nexport function readState(\n dom: DOMAdapter,\n root: Element | Document,\n): Record<string, unknown> {\n const el = dom.querySelector(root, `script[${STATE_MARKER_ATTR}]`);\n if (el === null) return {};\n const text = dom.getTextContent(el);\n if (text === null || text.length === 0) return {};\n try {\n const parsed: unknown = JSON.parse(text);\n if (parsed !== null && typeof parsed === 'object') {\n return parsed as Record<string, unknown>;\n }\n return {};\n } catch {\n return {};\n }\n}\n","/**\n * Static graph analysis (v1.2, spec §3/§12/§14).\n *\n * A single post-order walk over the Semantic Application Graph that classifies\n * every node as static (no bound signals, no events, not a reactive\n * region) or dynamic, and rolls that up into whole-static-subtree flags. This\n * is COMPILE-TIME metadata only — it introduces no virtual DOM, no second tree\n * and no runtime reactive system. It is consumed by:\n * - the hydration path, to skip per-node attribute/text re-verification on\n * provably-static subtrees (§12), and\n * - the diagnostic compiler-inspection report (§14).\n *\n * The renderer's initial-mount fast path does not need this map: it already\n * skips reactive wiring per node via cheap `events.length`/`stateRefs.length`\n * guards. Keeping the analysis out of the mount hot path avoids adding lookup\n * cost (and keeps the shipped runtime lean).\n */\n\nimport type { NodeId } from '@streetui/core';\nimport type { ApplicationGraph, GraphNode } from '@streetui/graph';\n\n/** Prop keys whose bound signal drives text content rather than an attribute. */\nconst TEXT_PROP_KEYS: ReadonlySet<string> = new Set(['text', 'label', 'value']);\n\nexport interface NodeAnalysis {\n /** No bound signals, no events, and not a reactive-list/conditional region. */\n readonly isStatic: boolean;\n /** This node is static AND every descendant is a static subtree. */\n readonly isStaticSubtree: boolean;\n /** A signal is bound to this node's text/label/value content. */\n readonly hasDynamicText: boolean;\n /** A signal is bound to a non-content prop (a reactive attribute). */\n readonly hasDynamicAttr: boolean;\n /** This node wires one or more DOM event handlers. */\n readonly hasEvents: boolean;\n /** This node is a keyed reactive list. */\n readonly isList: boolean;\n /** This node is a conditional (0..1 branch) region. */\n readonly isConditional: boolean;\n}\n\nexport interface GraphAnalysisSummary {\n readonly totalNodes: number;\n readonly staticNodes: number;\n readonly staticSubtrees: number;\n readonly dynamicTextNodes: number;\n readonly dynamicAttrNodes: number;\n readonly eventNodes: number;\n readonly lists: number;\n readonly conditionals: number;\n}\n\nexport interface GraphAnalysis {\n readonly nodes: ReadonlyMap<NodeId, NodeAnalysis>;\n readonly summary: GraphAnalysisSummary;\n}\n\n/**\n * Analyze a fully-built graph. O(n) single post-order pass; allocates one small\n * record per node. Safe to skip entirely when neither hydration nor diagnostics\n * need it.\n */\nexport function analyzeGraph(graph: ApplicationGraph): GraphAnalysis {\n const nodes = new Map<NodeId, NodeAnalysis>();\n const summary = {\n totalNodes: 0, staticNodes: 0, staticSubtrees: 0, dynamicTextNodes: 0,\n dynamicAttrNodes: 0, eventNodes: 0, lists: 0, conditionals: 0,\n };\n\n const visit = (node: GraphNode): boolean => {\n // Post-order: children first so subtree rollup is exact.\n let allChildrenStatic = true;\n for (const child of node.children) {\n const childSubtreeStatic = visit(child);\n if (!childSubtreeStatic) allChildrenStatic = false;\n }\n\n let hasDynamicText = false;\n let hasDynamicAttr = false;\n for (const ref of node.stateRefs) {\n if (TEXT_PROP_KEYS.has(ref.propKey)) hasDynamicText = true;\n else hasDynamicAttr = true;\n }\n const hasEvents = node.events.length > 0;\n const isList = node.type === 'reactive-list';\n const isConditional = node.type === 'conditional';\n // A portal relocates its children to a different DOM location (document.body)\n // at mount time, so its subtree is never a contiguous inline static blob.\n // Treating it as dynamic stops the static-subtree rollup at the portal, so\n // both SSR and hydration always take the real portal mount/hydrate branch\n // (which does the relocation) rather than emitting/adopting a raw HTML blob.\n const isPortal = node.type === 'portal';\n // A component owns per-instance lifecycle wiring (a `__component__<id>`\n // cleanup handler read at mount/hydrate). Treating it as dynamic stops the\n // static-subtree rollup at the component boundary so it always takes the\n // real mount/hydrate branch (which wires cleanups) instead of collapsing\n // into a serialized raw-HTML blob that would drop that per-instance wiring.\n const isComponent = node.type === 'component';\n const isStatic =\n node.stateRefs.length === 0 && !hasEvents && !isList && !isConditional && !isPortal && !isComponent;\n const isStaticSubtree = isStatic && allChildrenStatic;\n\n nodes.set(node.id, {\n isStatic, isStaticSubtree, hasDynamicText, hasDynamicAttr,\n hasEvents, isList, isConditional,\n });\n\n summary.totalNodes += 1;\n if (isStatic) summary.staticNodes += 1;\n if (isStaticSubtree) summary.staticSubtrees += 1;\n if (hasDynamicText) summary.dynamicTextNodes += 1;\n if (hasDynamicAttr) summary.dynamicAttrNodes += 1;\n if (hasEvents) summary.eventNodes += 1;\n if (isList) summary.lists += 1;\n if (isConditional) summary.conditionals += 1;\n\n return isStaticSubtree;\n };\n\n visit(graph.root);\n return { nodes, summary };\n}\n","/**\n * Diagnostic compiler-inspection mode (v1.2, spec §14).\n *\n * Produces a machine-readable (and optionally text-formatted) description of\n * what the compiler understands about an application: which nodes are static\n * vs dynamic, which carry dynamic text or attributes, which wire events, and\n * which are conditional regions or keyed lists — plus the hydration metadata\n * derived from that classification.\n *\n * This is a DIAGNOSTIC tool. It is not part of the runtime, is not consulted\n * during mount, and is tree-shakeable out of any app that never calls it.\n */\n\nimport type { ApplicationGraph, GraphNode } from '@streetui/graph';\nimport { analyzeGraph, type GraphAnalysisSummary } from './analyze.js';\n\nexport interface InspectedCompilationNode {\n readonly id: string;\n readonly type: string;\n readonly depth: number;\n readonly classification: 'static' | 'static-subtree-root' | 'dynamic';\n readonly dynamicText: boolean;\n readonly dynamicAttrs: boolean;\n readonly events: readonly string[];\n readonly boundProps: readonly string[];\n readonly isList: boolean;\n readonly isConditional: boolean;\n /** Hydration hint: how the hydration path should treat this node. */\n readonly hydration: 'adopt-static' | 'verify-dynamic';\n}\n\nexport interface CompilerInspection {\n readonly name: string;\n readonly version: string;\n readonly summary: GraphAnalysisSummary & {\n /** Fraction of nodes provably static (0..1). */\n readonly staticRatio: number;\n };\n readonly nodes: readonly InspectedCompilationNode[];\n}\n\n/**\n * Inspect a compiled/built graph and return a structured diagnostic report.\n * Purely observational — never mutates the graph.\n */\nexport function inspectCompilation(graph: ApplicationGraph): CompilerInspection {\n const analysis = analyzeGraph(graph);\n const nodes: InspectedCompilationNode[] = [];\n\n const walk = (node: GraphNode, depth: number): void => {\n const a = analysis.nodes.get(node.id);\n if (a !== undefined) {\n const classification: InspectedCompilationNode['classification'] = a.isStaticSubtree\n ? 'static-subtree-root'\n : a.isStatic\n ? 'static'\n : 'dynamic';\n nodes.push({\n id: node.id,\n type: node.type,\n depth,\n classification,\n dynamicText: a.hasDynamicText,\n dynamicAttrs: a.hasDynamicAttr,\n events: node.events.map((e) => e.type),\n boundProps: node.stateRefs.map((r) => r.propKey),\n isList: a.isList,\n isConditional: a.isConditional,\n hydration: a.isStaticSubtree ? 'adopt-static' : 'verify-dynamic',\n });\n }\n for (const child of node.children) walk(child, depth + 1);\n };\n walk(graph.root, 0);\n\n const staticRatio =\n analysis.summary.totalNodes === 0\n ? 0\n : analysis.summary.staticNodes / analysis.summary.totalNodes;\n\n return {\n name: graph.name,\n version: graph.version,\n summary: { ...analysis.summary, staticRatio: +staticRatio.toFixed(4) },\n nodes,\n };\n}\n\n/** Render an inspection as a compact human-readable text report. */\nexport function formatInspection(inspection: CompilerInspection): string {\n const s = inspection.summary;\n const lines: string[] = [];\n lines.push(`StreetUI compiler inspection — ${inspection.name} v${inspection.version}`);\n lines.push(\n ` nodes=${s.totalNodes} static=${s.staticNodes} ` +\n `staticSubtrees=${s.staticSubtrees} dynamicText=${s.dynamicTextNodes} ` +\n `dynamicAttrs=${s.dynamicAttrNodes} events=${s.eventNodes} ` +\n `lists=${s.lists} conditionals=${s.conditionals} ` +\n `staticRatio=${(s.staticRatio * 100).toFixed(1)}%`,\n );\n for (const n of inspection.nodes) {\n const flags: string[] = [];\n if (n.dynamicText) flags.push('text');\n if (n.dynamicAttrs) flags.push('attr:' + n.boundProps.join(','));\n if (n.events.length > 0) flags.push('on:' + n.events.join(','));\n if (n.isList) flags.push('list');\n if (n.isConditional) flags.push('cond');\n lines.push(\n ` ${' '.repeat(n.depth)}${n.type}#${n.id} [${n.classification}]` +\n (flags.length > 0 ? ` {${flags.join(' ')}}` : ''),\n );\n }\n return lines.join('\\n');\n}\n","/**\n * Static SSR Plan (v1.7, spec §4/§6) — internal.\n *\n * A compiler-derived plan that precomputes the verbatim HTML of every *maximal\n * static subtree* in an application graph. During SSR, the renderer emits that\n * precomputed string directly (via `ServerDOMAdapter.createRawHTML`) instead of\n * recursively constructing a `ServerElement`/`ServerText`/`NodeInstance` for\n * every node in the subtree. On the 10k-row `/users` corpus, ~100% of the node\n * mass lives in 10,000 static 8-node row subtrees, so collapsing each row into\n * one precomputed string removes the bulk of the mount-phase construction work.\n *\n * Design constraints honoured here:\n * - §3 REUSE the existing compiler analysis (`analyzeGraph`) to classify nodes;\n * no new/expensive analysis, and nothing runs during normal `compile()`.\n * - §5/§15 Only *maximal static-subtree roots* are collapsed. A dynamic region\n * (reactive-list container, conditional, dynamic-text/attr node) is never\n * treated as static — the list itself stays dynamic; only the provably-static\n * subtree *inside* each repeated item is precomputed.\n * - §8 The precomputed HTML is produced by the SAME mount + serialize pipeline\n * as the runtime path, so full-render output is byte-identical.\n * - §19 The plan retains ONLY strings keyed by GraphNode.id. No ServerDOM node,\n * NodeInstance or application object is retained (the throwaway build tree is\n * disposed + cleared). The per-app cache is a WeakMap, so a plan is released\n * when its CompiledApplication is collected.\n * - §24 Everything here is internal: not re-exported from the `streetui` or\n * `streetui/server` runtime barrels.\n *\n * This module is only ever imported by the SSR entry (`renderToString`), which\n * is itself reachable solely through the server path, so it tree-shakes out of\n * client bundles (§20, verified by bundle measurement).\n */\n\nimport type { NodeId } from '@streetui/core';\nimport type { ApplicationGraph, GraphNode } from '@streetui/graph';\nimport type { CompiledApplication } from '@streetui/compiler';\nimport { analyzeGraph } from '@streetui/compiler/diagnostics';\nimport { ServerDOMAdapter } from '@streetui/dom';\nimport { createRenderContext } from './render-context.js';\nimport { mountNode } from './mount.js';\n\n/**\n * Internal representation of the static SSR plan: maximal static-subtree root\n * GraphNode.id → its precomputed, verbatim outer HTML. A plain `Map<string,\n * string>` is deliberate — it holds no DOM/application references (§19).\n */\nexport type StaticSSRPlan = ReadonlyMap<NodeId, string>;\n\n/**\n * Collect the ids of every *maximal* static-subtree root under `graph`.\n *\n * Walk from the root; when a node is itself a whole static subtree, it is a\n * maximal root — record it and stop (its static descendants are subsumed).\n * Otherwise descend into its children, so a dynamic node's individually-static\n * children are still captured (the mixed-tree case, §5). The `application` root\n * is never recorded: it maps onto the render container rather than emitting its\n * own element, so we always descend past it into its real top-level children.\n */\nfunction collectMaximalStaticRoots(graph: ApplicationGraph): GraphNode[] {\n const analysis = analyzeGraph(graph);\n const roots: GraphNode[] = [];\n\n const walk = (node: GraphNode): void => {\n if (node.type !== 'application') {\n const a = analysis.nodes.get(node.id);\n if (a !== undefined && a.isStaticSubtree) {\n roots.push(node);\n return;\n }\n }\n for (const child of node.children) walk(child);\n };\n\n walk(graph.root);\n return roots;\n}\n\n/**\n * Serialize the outer HTML of a single static subtree using the exact runtime\n * mount + serialize pipeline (so the bytes match a full render). The throwaway\n * tree is disposed immediately, so nothing is retained.\n */\nfunction serializeStaticSubtree(\n dom: ServerDOMAdapter,\n graph: ApplicationGraph,\n root: GraphNode,\n): string {\n const container = dom.createElement('div');\n // No `staticHTML` on this ctx → mountNode builds the subtree fully.\n const ctx = createRenderContext(dom, graph, container);\n const instance = mountNode(ctx, root, container);\n const html = dom.serializeInner(container);\n // Tear down (static subtrees open no subscriptions, but keep symmetry with\n // renderToString's lifecycle) and drop all references.\n instance.dispose();\n ctx.instances.clear();\n return html;\n}\n\n/**\n * Build the static SSR plan for a compiled application. O(n) analysis + one\n * mount/serialize per maximal static subtree. Returns an empty map when the app\n * has no static subtrees (e.g. a highly-dynamic page) — the SSR path then\n * behaves exactly as v1.6.\n */\nexport function buildStaticSSRPlan(compiled: CompiledApplication): StaticSSRPlan {\n const graph = compiled.graph;\n const roots = collectMaximalStaticRoots(graph);\n const plan = new Map<NodeId, string>();\n if (roots.length === 0) return plan;\n\n const dom = new ServerDOMAdapter();\n for (const root of roots) {\n plan.set(root.id, serializeStaticSubtree(dom, graph, root));\n }\n return plan;\n}\n\n/**\n * Per-application plan cache. A WeakMap keyed by the CompiledApplication so a\n * plan is built once and reused across renders, and is released together with\n * the compiled app it belongs to — no long-lived retention of app state (§19).\n */\nconst PLAN_CACHE = new WeakMap<CompiledApplication, StaticSSRPlan>();\n\n/** Get the cached static SSR plan for a compiled app, building it on first use. */\nexport function getStaticSSRPlan(compiled: CompiledApplication): StaticSSRPlan {\n let plan = PLAN_CACHE.get(compiled);\n if (plan === undefined) {\n plan = buildStaticSSRPlan(compiled);\n PLAN_CACHE.set(compiled, plan);\n }\n return plan;\n}\n","/**\n * Server-side rendering — `renderToString`.\n *\n * Runs the *exact same* mount pipeline used in the browser (`mountGraph`), but\n * against a `ServerDOMAdapter` that builds a lightweight in-memory node tree\n * instead of a real browser DOM. The tree is then serialized to a normal HTML\n * string. Because both browser and server share the DSL → Compiler → Graph →\n * Runtime → Renderer pipeline, there is no second, SSR-specific renderer and no\n * virtual DOM.\n *\n * Lifecycle (v0.4 rule #20): the initial synchronous mount may open signal\n * subscriptions (via `wireSignalBindings`/`wireReactiveList`). On the server\n * those would be live forever, so once the HTML is serialized we dispose the\n * root instance — tearing down every subscription and listener. SSR therefore\n * has a *render* lifecycle only; the live *runtime* lifecycle is established\n * later on the client by `hydrate`.\n */\n\nimport { ServerDOMAdapter } from '@streetui/dom';\nimport type { CompiledApplication } from '@streetui/compiler';\nimport { createRenderContext } from './render-context.js';\nimport { mountGraph } from './mount.js';\nimport { getStaticSSRPlan } from './static-ssr-plan.js';\n\nexport interface RenderToStringOptions {\n /**\n * Override the server DOM adapter (rarely needed). Defaults to a fresh\n * `ServerDOMAdapter` per call so concurrent renders never share state.\n */\n readonly domAdapter?: ServerDOMAdapter;\n /**\n * @internal — testing/benchmark knob for the v1.7 static SSR plan.\n *\n * `undefined` (default): use the per-app cached plan (build once, reuse).\n * `null`: disable the plan entirely — the exact v1.6 runtime mount path, used\n * by the byte-identity gate and A/B benchmark as the \"legacy\" baseline.\n * a map: use this explicit plan.\n *\n * Not part of the supported public API; output is byte-identical regardless\n * of this value (§8).\n */\n readonly staticPlan?: ReadonlyMap<string, string> | null;\n}\n\n/**\n * Render a compiled StreetUI application to an HTML string.\n *\n * The returned markup contains only the application's own elements (the\n * synthetic container is not emitted), so callers embed it wherever they mount\n * on the client — e.g. inside `<div id=\"app\">…</div>`.\n */\nexport function renderToString(\n compiled: CompiledApplication,\n options: RenderToStringOptions = {},\n): string {\n const dom = options.domAdapter ?? new ServerDOMAdapter();\n\n // Resolve the v1.7 static SSR plan: cached-by-default, `null` forces the v1.6\n // path, an explicit map is used as-is. Only maximal static-subtree roots are\n // collapsed; dynamic regions still mount through the runtime path (§5).\n const plan =\n options.staticPlan === null\n ? undefined\n : (options.staticPlan ?? getStaticSSRPlan(compiled));\n const staticHTML = plan !== undefined && plan.size > 0 ? plan : undefined;\n\n // Synthetic container — the application root maps onto it, and the app's\n // top-level nodes are appended directly into it (mirroring browser mount).\n const container = dom.createElement('div');\n\n const ctx = createRenderContext(dom, compiled.graph, container, undefined, staticHTML);\n const rootInstance = mountGraph(ctx);\n\n const html = dom.serializeInner(container);\n\n // Tear down any subscriptions/listeners opened during mount — the server has\n // no live runtime. (rule #20)\n rootInstance.dispose();\n ctx.instances.clear();\n\n return html;\n}\n","/**\n * Route matching — pure functions, no DOM, no reactivity.\n *\n * A pattern is matched segment-by-segment against a pathname:\n * - a literal segment must equal the path segment,\n * - a `:name` segment captures the path segment into `params.name`,\n * - a `*` segment (or a whole-pattern `*`) is a catch-all that matches the\n * remainder of the path and captures it into `params['*']`.\n *\n * Matching is intentionally small: no optional segments, no regex constraints,\n * no nested route trees. Composition of layouts is done in the DSL, not here.\n */\n\n/** Split a path into non-empty segments. `/` → [], `/a/b` → ['a','b']. */\nfunction segments(path: string): string[] {\n return path.split('/').filter((s) => s.length > 0);\n}\n\n/** Normalize a pathname: ensure a single leading slash, drop a trailing slash. */\nexport function normalizePath(path: string): string {\n let p = path.trim();\n if (p === '') return '/';\n if (!p.startsWith('/')) p = `/${p}`;\n if (p.length > 1 && p.endsWith('/')) p = p.slice(0, -1);\n return p;\n}\n\n/**\n * Try to match a single pattern against a pathname.\n * Returns the captured params on success, or `null` on no match.\n */\nexport function matchPattern(\n pattern: string,\n pathname: string,\n): Record<string, string> | null {\n // Whole-pattern wildcard: matches everything.\n if (pattern === '*') {\n return { '*': normalizePath(pathname).slice(1) };\n }\n\n const patSegs = segments(pattern);\n const pathSegs = segments(normalizePath(pathname));\n const params: Record<string, string> = {};\n\n for (let i = 0; i < patSegs.length; i++) {\n const patSeg = patSegs[i]!;\n\n // Trailing catch-all: capture the rest of the path.\n if (patSeg === '*') {\n params['*'] = pathSegs.slice(i).map((s) => decodeURIComponent(s)).join('/');\n return params;\n }\n\n const pathSeg = pathSegs[i];\n if (pathSeg === undefined) return null; // path ran out of segments\n\n if (patSeg.startsWith(':')) {\n const name = patSeg.slice(1);\n if (name === '') return null; // malformed `:` with no name\n params[name] = decodeURIComponent(pathSeg);\n continue;\n }\n\n if (patSeg !== pathSeg) return null; // literal mismatch\n }\n\n // All pattern segments consumed — the path must be fully consumed too.\n if (pathSegs.length !== patSegs.length) return null;\n return params;\n}\n\nexport interface MatchResult<R> {\n readonly route: R;\n readonly params: Record<string, string>;\n}\n\n/**\n * Match a pathname against an ordered list of routes. The first route whose\n * pattern matches wins (definition order), so more specific routes should be\n * listed before a `*` fallback.\n */\nexport function matchRoutes<R extends { path: string }>(\n routes: readonly R[],\n pathname: string,\n): MatchResult<R> | null {\n for (const route of routes) {\n const params = matchPattern(route.path, pathname);\n if (params !== null) return { route, params };\n }\n return null;\n}\n\n/** Split a `to` target into its pathname and (already-stripped) search string. */\nexport function splitTarget(to: string): { pathname: string; search: string } {\n const hashIndex = to.indexOf('#');\n const withoutHash = hashIndex >= 0 ? to.slice(0, hashIndex) : to;\n const qIndex = withoutHash.indexOf('?');\n if (qIndex < 0) return { pathname: normalizePath(withoutHash), search: '' };\n return {\n pathname: normalizePath(withoutHash.slice(0, qIndex)),\n search: withoutHash.slice(qIndex + 1),\n };\n}\n","/**\n * Router history — a small abstraction over the navigation source so the router\n * can run both in the browser (real `window.history` + `popstate`) and in tests\n * (an in-memory stack, fully deterministic, no globals).\n *\n * Internal navigation never triggers a full-page reload: the browser history\n * uses `pushState`/`replaceState` and notifies listeners synchronously.\n */\n\nexport interface RouterLocation {\n /** Pathname, always normalized with a single leading slash. */\n readonly pathname: string;\n /** Query string without the leading `?`. */\n readonly search: string;\n}\n\nexport interface RouterHistory {\n /** The current location. */\n location(): RouterLocation;\n /** Push a new entry and notify listeners. */\n push(pathname: string, search: string): void;\n /** Replace the current entry and notify listeners. */\n replace(pathname: string, search: string): void;\n /** Go back one entry. */\n back(): void;\n /** Go forward one entry. */\n forward(): void;\n /** Subscribe to location changes. Returns an unsubscribe function. */\n listen(cb: () => void): () => void;\n /** Detach any global listeners (browser only). */\n dispose(): void;\n}\n\nfunction buildLocation(pathname: string, search: string): RouterLocation {\n return { pathname, search };\n}\n\nfunction toUrl(pathname: string, search: string): string {\n return search.length > 0 ? `${pathname}?${search}` : pathname;\n}\n\n/**\n * Browser history backed by `window.history`. `pushState`/`replaceState` do not\n * emit `popstate`, so we notify listeners ourselves after those calls; genuine\n * back/forward navigation arrives via the `popstate` event.\n */\nexport function createBrowserHistory(): RouterHistory {\n const listeners = new Set<() => void>();\n const notify = (): void => {\n for (const cb of listeners) cb();\n };\n const onPopState = (): void => notify();\n window.addEventListener('popstate', onPopState);\n\n const current = (): RouterLocation => {\n const loc = window.location;\n return buildLocation(loc.pathname, loc.search.replace(/^\\?/, ''));\n };\n\n return {\n location: current,\n push(pathname, search) {\n window.history.pushState({}, '', toUrl(pathname, search));\n notify();\n },\n replace(pathname, search) {\n window.history.replaceState({}, '', toUrl(pathname, search));\n notify();\n },\n back() {\n window.history.back(); // async → emits popstate\n },\n forward() {\n window.history.forward(); // async → emits popstate\n },\n listen(cb) {\n listeners.add(cb);\n return () => listeners.delete(cb);\n },\n dispose() {\n window.removeEventListener('popstate', onPopState);\n listeners.clear();\n },\n };\n}\n\n/**\n * In-memory history for tests and non-DOM environments. Maintains an explicit\n * stack and cursor so `back()`/`forward()` are deterministic.\n */\nexport function createMemoryHistory(initial = '/'): RouterHistory {\n const listeners = new Set<() => void>();\n const notify = (): void => {\n for (const cb of listeners) cb();\n };\n\n const parse = (entry: string): RouterLocation => {\n const qIndex = entry.indexOf('?');\n if (qIndex < 0) return buildLocation(entry, '');\n return buildLocation(entry.slice(0, qIndex), entry.slice(qIndex + 1));\n };\n\n const stack: string[] = [initial];\n let index = 0;\n\n return {\n location() {\n return parse(stack[index]!);\n },\n push(pathname, search) {\n // Drop any forward entries, then append.\n stack.splice(index + 1);\n stack.push(toUrl(pathname, search));\n index = stack.length - 1;\n notify();\n },\n replace(pathname, search) {\n stack[index] = toUrl(pathname, search);\n notify();\n },\n back() {\n if (index > 0) {\n index--;\n notify();\n }\n },\n forward() {\n if (index < stack.length - 1) {\n index++;\n notify();\n }\n },\n listen(cb) {\n listeners.add(cb);\n return () => listeners.delete(cb);\n },\n dispose() {\n listeners.clear();\n },\n };\n}\n","/**\n * StreetUI Router core — renderer-agnostic.\n *\n * Holds the route table, resolves the current location into a `RouteMatch`,\n * and exposes that match as a StreetUI `signal`. Navigation is delegated to a\n * `RouterHistory`; when the location changes (via `navigate`, `back`, `forward`,\n * or a browser `popstate`) the router recomputes the match and updates the\n * signal, which is how every consumer (`isActive`, the mount integration, any\n * `derived` the app builds) stays in sync. No second reactive system.\n */\n\nimport { signal, derived, type ReadonlySignal } from '@streetui/state';\nimport type { RouterHistory } from './history.js';\nimport { createBrowserHistory } from './history.js';\nimport { matchRoutes, normalizePath, splitTarget } from './matching.js';\nimport type { RouteDefinition, RouteMatch } from './types.js';\n\nexport interface RouterOptions {\n /** The route table. Order matters — the first matching pattern wins. */\n readonly routes: readonly RouteDefinition[];\n /**\n * Navigation source. Defaults to a browser history. Pass a memory history\n * for tests or non-DOM environments.\n */\n readonly history?: RouterHistory;\n /**\n * Fallback route used when nothing else matches and no `*` route is present.\n * Defaults to a built-in 404 page (a normal StreetUI tree — no special path).\n */\n readonly notFound?: RouteDefinition;\n}\n\nexport interface NavigateOptions {\n /** Replace the current history entry instead of pushing a new one. */\n readonly replace?: boolean;\n}\n\nexport interface IsActiveOptions {\n /** Require an exact pathname match rather than a prefix match. */\n readonly exact?: boolean;\n}\n\nexport interface Router {\n /** Reactive current match. Consumers subscribe via StreetUI signals. */\n readonly currentRoute: ReadonlySignal<RouteMatch>;\n /** Navigate to a target path (may include a query string). */\n navigate(to: string, options?: NavigateOptions): void;\n /** Go back one history entry. */\n back(): void;\n /** Go forward one history entry. */\n forward(): void;\n /** Reactive predicate: is `path` the active route (or a prefix of it)? */\n isActive(path: string, options?: IsActiveOptions): ReadonlySignal<boolean>;\n /** Tear down history listeners. */\n destroy(): void;\n}\n\n/** Built-in 404 route — a normal StreetUI page tree, overridable via a `*` route. */\nconst DEFAULT_NOT_FOUND: RouteDefinition = {\n path: '*',\n builder: (page) => {\n page.section('not-found', (s) => {\n s.heading('404 — Page not found', { level: 1, id: 'not-found-title' });\n s.text('The page you were looking for does not exist.', { id: 'not-found-text' });\n s.link('Go home', { href: '/', id: 'not-found-home' });\n }, { id: 'not-found' });\n },\n};\n\nexport function createRouter(options: RouterOptions): Router {\n const routes = options.routes;\n const history = options.history ?? createBrowserHistory();\n const fallback = options.notFound ?? DEFAULT_NOT_FOUND;\n\n const resolve = (): RouteMatch => {\n const loc = history.location();\n const pathname = normalizePath(loc.pathname);\n const query = new URLSearchParams(loc.search);\n const matched = matchRoutes(routes, pathname);\n if (matched !== null) {\n return {\n path: pathname,\n pattern: matched.route.path,\n params: matched.params,\n query,\n route: matched.route,\n // A catch-all `*` match is the 404 route whether user-supplied or built-in.\n isFallback: matched.route.path === '*',\n };\n }\n // No explicit route matched — use the fallback (a `*` route if the table\n // has one, otherwise the built-in 404).\n const fallbackParams =\n matchRoutes([fallback], pathname)?.params ?? {};\n return {\n path: pathname,\n pattern: fallback.path,\n params: fallbackParams,\n query,\n route: fallback,\n isFallback: true,\n };\n };\n\n const current = signal<RouteMatch>(resolve());\n const stopListening = history.listen(() => {\n current.set(resolve());\n });\n\n const navigate = (to: string, opts: NavigateOptions = {}): void => {\n const { pathname, search } = splitTarget(to);\n if (opts.replace === true) history.replace(pathname, search);\n else history.push(pathname, search);\n };\n\n const isActive = (path: string, opts: IsActiveOptions = {}): ReadonlySignal<boolean> => {\n const target = normalizePath(path);\n const exact = opts.exact === true;\n return derived(() => {\n const activePath = current.get().path;\n if (activePath === target) return true;\n if (exact || target === '/') return false;\n return activePath.startsWith(`${target}/`);\n });\n };\n\n return {\n currentRoute: current,\n navigate,\n back: () => history.back(),\n forward: () => history.forward(),\n isActive,\n destroy: () => {\n stopListening();\n history.dispose();\n },\n };\n}\n","/**\n * StreetUI Router — DOM integration.\n *\n * `mountRouter` wires a `Router` to real DOM:\n *\n * 1. Mounts an optional persistent shell (layout + navigation) ONCE. The shell\n * declares an outlet element (see `routerOutlet`) into which route content\n * is rendered.\n * 2. Subscribes to `router.currentRoute`. On every change it disposes the\n * previous route (route-scoped `CleanupRegistry.run()` + `runtime.unmount()`)\n * and mounts the new route's compiled application into the outlet.\n * Only the outlet subtree is re-created — the shell persists.\n * 3. Intercepts clicks on internal `<a>` elements for client-side navigation.\n * External links (absolute URLs, `target=\"_blank\"`, `mailto:`/`tel:`) keep\n * their normal browser behaviour, and `link()` is used unchanged.\n *\n * Each route is an ordinary compiled StreetUI application — no special renderer\n * path, no virtual DOM, no full-application rerender on navigation.\n */\n\nimport { streetui, type PageDSL, type ContainerDSL } from '@streetui/dsl';\nimport { resolveTransition, type TransitionConfig } from '@streetui/dsl';\nimport { compile } from '@streetui/compiler';\nimport { createRuntime, type MountedApplication, type StreetRenderer } from '@streetui/runtime';\nimport { createRenderer, runElementTransition } from '@streetui/renderer';\nimport { BrowserDOMAdapter, type DOMAdapter } from '@streetui/dom';\nimport { CleanupRegistry } from '@streetui/core';\nimport type { Router } from './router.js';\nimport type { RouteContext, RouteMatch } from './types.js';\n\n/** Default id used for the route outlet element inside a shell. */\nexport const ROUTER_OUTLET_ID = 'streetui-router-outlet';\n\n/**\n * Declare the route outlet inside a shell builder. The router replaces this\n * element's contents on every navigation.\n */\nexport function routerOutlet(scope: ContainerDSL, id: string = ROUTER_OUTLET_ID): void {\n scope.container('router-outlet', () => { /* filled by the router at runtime */ }, { id });\n}\n\nexport type ShellBuilder = (shell: PageDSL, router: Router) => void;\n\nexport interface MountRouterOptions {\n /** Element to mount into. With a shell, the shell fills this; otherwise routes do. */\n readonly container: Element;\n /** Optional persistent layout. Must include a `routerOutlet(...)`. */\n readonly shell?: ShellBuilder;\n /** Id of the outlet element within the shell. Defaults to `ROUTER_OUTLET_ID`. */\n readonly outletId?: string;\n /** Override the renderer (e.g. a custom DOM adapter for tests). */\n readonly renderer?: StreetRenderer;\n /** Intercept internal `<a>` clicks for client-side navigation. Defaults to true. */\n readonly interceptLinks?: boolean;\n /**\n * Hydrate server-rendered HTML already present in the container instead of\n * mounting fresh. The shell and the *initial* route adopt the existing DOM;\n * subsequent client-side navigations mount normally. Defaults to false.\n */\n readonly hydrate?: boolean;\n /**\n * Optional enter/leave transition played on client-side navigations (§9). When\n * set, each navigation mounts the incoming route into its own host wrapper,\n * plays the enter animation on it, and defers the outgoing route's disposal\n * (route-scoped cleanup + DOM removal) until its leave animation ends — so\n * resources stay alive exactly as long as the departing DOM. History is\n * untouched (the router already navigated), and the initial mount/hydration is\n * NOT animated (§22-style: the first paint must match the server). Reuses the\n * single CSS-class transition engine — no second animation system.\n */\n readonly transition?: TransitionConfig;\n}\n\nexport interface MountedRouter {\n /** The element route content is rendered into. */\n readonly outlet: Element;\n /** Tear down the current route, the shell, link interception and the router. */\n unmount(): void;\n}\n\n/** A URL is external when it targets another origin or a non-navigational scheme. */\nfunction isExternalHref(href: string): boolean {\n return (\n /^[a-zA-Z][a-zA-Z\\d+.-]*:/.test(href) || // scheme: http:, https:, mailto:, tel:\n href.startsWith('//') // protocol-relative\n );\n}\n\nexport function mountRouter(router: Router, options: MountRouterOptions): MountedRouter {\n const { container } = options;\n const renderer = options.renderer ?? createRenderer();\n const outletId = options.outletId ?? ROUTER_OUTLET_ID;\n const interceptLinks = options.interceptLinks ?? true;\n const hydrateMode = options.hydrate ?? false;\n\n // ── 1. Mount the shell once (if any) and resolve the outlet ──────────────────\n let shellMounted: MountedApplication | null = null;\n let outlet: Element;\n\n if (options.shell !== undefined) {\n const shellApp = streetui.app({ name: 'router-shell' });\n const shellBuilder = options.shell;\n shellApp.page('shell', (page) => shellBuilder(page, router));\n const shellRuntime = createRuntime({ renderer });\n const shellCompiled = compile(shellApp);\n if (hydrateMode) {\n // The outlet is a slot the router fills. When the shell hydrates, mark the\n // outlet node as a hydration boundary so shell hydration adopts the outlet\n // element itself but preserves the server-rendered route content inside it\n // (instead of stripping it as surplus). The initial route then hydrates\n // that content node-for-node.\n for (const node of shellCompiled.graph.findAll((n) => n.getProp('id') === outletId)) {\n node.setProp('_hydrationBoundary', true);\n }\n }\n shellMounted = hydrateMode\n ? shellRuntime.hydrate(shellCompiled, container)\n : shellRuntime.mount(shellCompiled, container);\n\n const found = container.querySelector(`[id=\"${outletId}\"]`);\n if (found === null) {\n throw new Error(\n `[Router] The shell must contain a route outlet. Call routerOutlet(scope) ` +\n `(or add a container with id=\"${outletId}\") inside your shell builder.`,\n );\n }\n outlet = found;\n } else {\n outlet = container;\n }\n\n // ── 2. Route mounting / disposal ─────────────────────────────────────────────\n const routeTransition =\n options.transition !== undefined ? resolveTransition(options.transition) : undefined;\n // A DOM adapter for the transition host manipulation. Only constructed when a\n // transition is configured (browser-only feature), so SSR/headless router use\n // never touches a browser global. Manipulates the same `class` attribute the\n // reconciler-driven transitions use, via the same engine.\n const txDom: DOMAdapter | undefined =\n routeTransition !== undefined ? new BrowserDOMAdapter() : undefined;\n\n interface ActiveRoute {\n readonly registry: CleanupRegistry;\n readonly mounted: MountedApplication;\n /** The host wrapper this route's DOM lives in (transition mode only). */\n host: Element | null;\n /** In-flight enter run, cancelled if this host starts leaving (rapid nav). */\n enterRun: { cancel(): void } | null;\n }\n let active: ActiveRoute | null = null;\n // Routes whose leave animation is still running (transition mode). Kept so a\n // hard `unmount()` can settle + tear them down instead of leaking.\n const pendingLeaves = new Map<ActiveRoute, { cancel(): void }>();\n // Only the very first route render hydrates the server HTML in the outlet;\n // client-side navigations after that mount fresh.\n let firstRender = hydrateMode;\n\n /** Full synchronous teardown of a route (no transition / on leave-end). */\n const teardownRoute = (route: ActiveRoute): void => {\n // Run user-registered cleanup (effects, subscriptions) FIRST, then tear down\n // the DOM + runtime signal bindings. Both reuse existing machinery.\n route.registry.run();\n route.mounted.unmount();\n if (route.host !== null && txDom !== undefined) {\n const parent = txDom.parentNode(route.host);\n if (parent !== null) txDom.removeChild(parent, route.host);\n }\n };\n\n const disposeActive = (): void => {\n if (active === null) return;\n teardownRoute(active);\n active = null;\n };\n\n /**\n * Move whatever is currently in the outlet into a fresh host wrapper (used to\n * isolate a hydrated/initial route so it can be animated out on the first\n * client navigation). Returns the wrapper, now the sole child of the outlet.\n */\n const wrapOutletChildren = (dom: DOMAdapter): Element => {\n const host = dom.createElement('div');\n dom.setAttribute(host, 'data-streetui-route', '');\n const moved: Node[] = [];\n let child = dom.firstChild(outlet);\n while (child !== null) {\n moved.push(child);\n child = dom.nextSibling(child);\n }\n for (const n of moved) dom.appendChild(host, n);\n dom.appendChild(outlet, host);\n return host;\n };\n\n /** Build + mount (or hydrate) a route into `target`, returning its handle. */\n const buildRoute = (\n match: RouteMatch,\n target: Element,\n hydrate: boolean,\n ): ActiveRoute => {\n const registry = new CleanupRegistry();\n const ctx: RouteContext = {\n path: match.path,\n pattern: match.pattern,\n params: match.params,\n query: match.query,\n onCleanup: (fn) => registry.add(fn),\n };\n const routeApp = streetui.app({ name: `route:${match.pattern}` });\n routeApp.page('route', (page) => match.route.builder(page, ctx));\n const runtime = createRuntime({ renderer });\n const routeCompiled = compile(routeApp);\n const mounted = hydrate\n ? runtime.hydrate(routeCompiled, target)\n : runtime.mount(routeCompiled, target);\n return { registry, mounted, host: null, enterRun: null };\n };\n\n const renderRoute = (match: RouteMatch): void => {\n // Non-transitioned path — unchanged synchronous behaviour.\n if (routeTransition === undefined || txDom === undefined) {\n disposeActive();\n active = buildRoute(match, outlet, firstRender);\n firstRender = false;\n return;\n }\n\n // Transitioned path. The initial render (mount or hydrate) is NOT animated:\n // it must match the server paint, so we just place it in a host wrapper for\n // later animation and return.\n if (active === null) {\n if (firstRender) {\n // Hydrate the server HTML in place, then isolate it in a host wrapper.\n active = buildRoute(match, outlet, true);\n active.host = wrapOutletChildren(txDom);\n } else {\n const host = txDom.createElement('div');\n txDom.setAttribute(host, 'data-streetui-route', '');\n txDom.appendChild(outlet, host);\n active = buildRoute(match, host, false);\n active.host = host;\n }\n firstRender = false;\n return;\n }\n\n // Client-side navigation with a route already mounted: cross-fade.\n firstRender = false;\n const leaving = active;\n // Abort any in-flight enter on the departing host so we never run two\n // overlapping animations on one element (§6 discipline).\n leaving.enterRun?.cancel();\n leaving.enterRun = null;\n const leaveHost = leaving.host;\n\n // Mount the incoming route into a fresh host and animate it in.\n const enterHost = txDom.createElement('div');\n txDom.setAttribute(enterHost, 'data-streetui-route', '');\n txDom.appendChild(outlet, enterHost);\n const next = buildRoute(match, enterHost, false);\n next.host = enterHost;\n next.enterRun = runElementTransition(txDom, enterHost, routeTransition, 'enter', () => {\n next.enterRun = null;\n });\n active = next;\n\n // Animate the departing host out, then tear the old route down. Resources\n // (route-scoped cleanup + signal bindings) live until the leave completes.\n if (leaveHost !== null) {\n const run = runElementTransition(txDom, leaveHost, routeTransition, 'leave', () => {\n pendingLeaves.delete(leaving);\n teardownRoute(leaving);\n });\n pendingLeaves.set(leaving, run);\n } else {\n teardownRoute(leaving);\n }\n };\n\n // Initial render, then react to every route change.\n renderRoute(router.currentRoute.peek());\n const stopRouteSub = router.currentRoute.subscribe((match) => renderRoute(match));\n\n // ── 3. Client-side link interception ─────────────────────────────────────────\n const onClick = (event: Event): void => {\n if (event.defaultPrevented) return;\n const mouse = event as MouseEvent;\n if (typeof mouse.button === 'number' && mouse.button !== 0) return;\n if (mouse.metaKey || mouse.ctrlKey || mouse.shiftKey || mouse.altKey) return;\n\n const target = event.target as Element | null;\n const anchor = target?.closest?.('a') ?? null;\n if (anchor === null) return;\n\n const targetAttr = anchor.getAttribute('target');\n if (targetAttr !== null && targetAttr !== '_self') return; // _blank etc.\n\n const href = anchor.getAttribute('href');\n if (href === null || href === '' || href.startsWith('#')) return;\n if (isExternalHref(href)) return;\n\n event.preventDefault();\n router.navigate(href);\n };\n\n if (interceptLinks) {\n container.addEventListener('click', onClick);\n }\n\n // ── Teardown ─────────────────────────────────────────────────────────────────\n return {\n outlet,\n unmount() {\n if (interceptLinks) container.removeEventListener('click', onClick);\n stopRouteSub();\n // Settle any in-flight leave animations and tear their routes down.\n for (const [route, run] of pendingLeaves) {\n run.cancel();\n teardownRoute(route);\n }\n pendingLeaves.clear();\n disposeActive();\n shellMounted?.unmount();\n router.destroy();\n },\n };\n}\n","/**\n * A small, sync validation system.\n *\n * A `Validator` maps a string field value to an error message, or `undefined`\n * when the value is acceptable. This is deliberately tiny — the built-ins cover\n * the common cases (`required`, `minLength`, `maxLength`, `email`, `pattern`)\n * and anything else is just a plain function `(value: string) => string | undefined`.\n *\n * Validators for a field run in order and the FIRST error wins, so list\n * `required` first if a field is mandatory.\n *\n * Async validation is intentionally NOT part of this core. It can be layered on\n * top with `@streetui/state`'s `resource()` (kick off a resource on value\n * change and surface `resource.error` alongside the field error) without\n * destabilising the synchronous validity model here.\n */\n\nexport type Validator = (value: string) => string | undefined;\n\n/** Fails when the trimmed value is empty. */\nexport function required(message = 'This field is required'): Validator {\n return (value) => (value.trim().length === 0 ? message : undefined);\n}\n\n/** Fails when the value is shorter than `length` characters. */\nexport function minLength(length: number, message?: string): Validator {\n return (value) =>\n value.length < length\n ? (message ?? `Must be at least ${length} characters`)\n : undefined;\n}\n\n/** Fails when the value is longer than `length` characters. */\nexport function maxLength(length: number, message?: string): Validator {\n return (value) =>\n value.length > length\n ? (message ?? `Must be at most ${length} characters`)\n : undefined;\n}\n\n// Pragmatic, dependency-free email shape check (not a full RFC 5322 parser).\nconst EMAIL_RE = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\n/** Fails when a non-empty value is not a plausible email address. */\nexport function email(message = 'Enter a valid email address'): Validator {\n return (value) => (value.length === 0 || EMAIL_RE.test(value) ? undefined : message);\n}\n\n/** Fails when a non-empty value does not match `regex`. */\nexport function pattern(regex: RegExp, message = 'Invalid format'): Validator {\n return (value) => (value.length === 0 || regex.test(value) ? undefined : message);\n}\n\n/** Run a validator (or ordered list) and return the first error, if any. */\nexport function runValidators(\n value: string,\n validators: Validator | ReadonlyArray<Validator> | undefined,\n): string | undefined {\n if (validators === undefined) return undefined;\n const list = Array.isArray(validators) ? validators : [validators];\n for (const validate of list) {\n const error = validate(value);\n if (error !== undefined) return error;\n }\n return undefined;\n}\n","/**\n * Reactive form model built entirely on `@streetui/state` signals.\n *\n * There is no second state system here: every piece of form state (`values`,\n * `errors`, `touched`, `dirty`, `valid`, submission status) is a signal or a\n * derived signal, so it composes with the renderer's existing reactive bindings.\n * A field's `value` is a writable `Signal<string>`, which plugs straight into\n * the DSL's `input({ bind })` — typing updates form state and programmatic\n * updates update the input, through the one binding the renderer already wires.\n */\n\nimport {\n signal,\n derived,\n batch,\n DerivedSignal,\n type Signal,\n type ReadonlySignal,\n type Unsubscribe,\n} from '@streetui/state';\nimport { type Validator, runValidators } from './validators.js';\n\n/** Form values are a flat, typed record of string fields (HTML input values). */\nexport type FormValues = Record<string, string>;\n\nexport interface Field {\n readonly name: string;\n /** Writable value signal — pass to `input({ bind: field.value })`. */\n readonly value: Signal<string>;\n /** Current validation error, or `undefined` when the field is valid. */\n readonly error: ReadonlySignal<string | undefined>;\n /** True once the field has received a genuine user interaction. */\n readonly touched: ReadonlySignal<boolean>;\n /** True when the value differs from its initial value. */\n readonly dirty: ReadonlySignal<boolean>;\n /** True when the field has no validation error. */\n readonly valid: ReadonlySignal<boolean>;\n /** Programmatically set the value (does not mark the field touched). */\n setValue(next: string): void;\n /** Force the touched flag (defaults to true). */\n markTouched(touched?: boolean): void;\n /** Restore this field's initial value and clear its touched flag. */\n reset(): void;\n}\n\nexport type FormValidators<T extends FormValues> = {\n readonly [K in keyof T]?: Validator | ReadonlyArray<Validator>;\n};\n\nexport interface FormConfig<T extends FormValues> {\n readonly initialValues: T;\n readonly validators?: FormValidators<T>;\n /** Called by `submit()` once all fields are valid. May be async. */\n readonly onSubmit?: (values: T) => void | Promise<void>;\n}\n\nexport type SubmitStatus = 'idle' | 'submitting' | 'success' | 'error';\n\nexport interface Form<T extends FormValues> {\n readonly values: ReadonlySignal<T>;\n readonly errors: ReadonlySignal<Partial<Record<keyof T, string>>>;\n readonly touched: ReadonlySignal<Partial<Record<keyof T, boolean>>>;\n readonly dirty: ReadonlySignal<boolean>;\n readonly valid: ReadonlySignal<boolean>;\n readonly submitting: ReadonlySignal<boolean>;\n readonly submitted: ReadonlySignal<boolean>;\n readonly status: ReadonlySignal<SubmitStatus>;\n readonly submitError: ReadonlySignal<unknown>;\n /** Access the reactive state + setters for one field. */\n field<K extends keyof T & string>(name: K): Field;\n /** Merge a partial set of values in (does not mark fields touched). */\n setValues(partial: Partial<T>): void;\n /** Validate, mark all fields touched, then run `onSubmit` if valid. */\n submit(): Promise<void>;\n /** Restore initial values and clear errors/touched/dirty/submission state. */\n reset(): void;\n /** Tear down all field subscriptions and derived signals. */\n dispose(): void;\n}\n\ninterface FieldInternal {\n readonly api: Field;\n readonly value: Signal<string>;\n readonly touched: Signal<boolean>;\n readonly error: DerivedSignal<string | undefined>;\n readonly valid: DerivedSignal<boolean>;\n readonly dirty: DerivedSignal<boolean>;\n readonly initial: string;\n readonly unsub: Unsubscribe;\n}\n\n// __FORM_IMPL__\n\nexport function createForm<T extends FormValues>(config: FormConfig<T>): Form<T> {\n const names = Object.keys(config.initialValues) as Array<keyof T & string>;\n const validators = config.validators ?? ({} as FormValidators<T>);\n\n // While true, value changes originate from setValues()/reset() and must NOT\n // mark a field touched. Batch flushes run synchronously inside batch(), i.e.\n // before this flag is reset, so guarding around batch() is sound.\n let programmatic = false;\n\n const fields = new Map<string, FieldInternal>();\n\n for (const name of names) {\n // Keys come from Object.keys(initialValues), so the value is always present;\n // the annotation defeats noUncheckedIndexedAccess widening to `| undefined`.\n const initial: string = config.initialValues[name] as string;\n const value = signal<string>(initial);\n const touched = signal<boolean>(false);\n const error = derived<string | undefined>(() =>\n runValidators(value.get(), validators[name]),\n );\n const valid = derived<boolean>(() => error.get() === undefined);\n const dirty = derived<boolean>(() => value.get() !== initial);\n\n // Mark touched on the first genuine (non-programmatic) value change.\n const unsub = value.subscribe(() => {\n if (!programmatic) touched.set(true);\n });\n\n const api: Field = {\n name,\n value,\n error,\n touched,\n dirty,\n valid,\n setValue(next: string): void {\n value.set(next);\n },\n markTouched(next = true): void {\n touched.set(next);\n },\n reset(): void {\n programmatic = true;\n try {\n batch(() => {\n value.set(initial);\n touched.set(false);\n });\n } finally {\n programmatic = false;\n }\n },\n };\n\n fields.set(name, { api, value, touched, error, valid, dirty, initial, unsub });\n }\n\n const field = (name: string): FieldInternal => {\n const f = fields.get(name);\n if (f === undefined) throw new Error(`Unknown form field: ${name}`);\n return f;\n };\n\n const values = derived<T>(() => {\n const out: Record<string, string> = {};\n for (const name of names) out[name] = field(name).value.get();\n return out as T;\n });\n\n const errors = derived<Partial<Record<keyof T, string>>>(() => {\n const out: Partial<Record<keyof T, string>> = {};\n for (const name of names) {\n const e = field(name).error.get();\n if (e !== undefined) out[name] = e;\n }\n return out;\n });\n\n const touchedMap = derived<Partial<Record<keyof T, boolean>>>(() => {\n const out: Partial<Record<keyof T, boolean>> = {};\n for (const name of names) out[name] = field(name).touched.get();\n return out;\n });\n\n const dirty = derived<boolean>(() => names.some((n) => field(n).dirty.get()));\n const valid = derived<boolean>(() => names.every((n) => field(n).valid.get()));\n\n const status = signal<SubmitStatus>('idle');\n const submitting = derived<boolean>(() => status.get() === 'submitting');\n const submitted = derived<boolean>(() => status.get() === 'success');\n const submitError = signal<unknown>(undefined);\n\n function setValues(partial: Partial<T>): void {\n programmatic = true;\n try {\n batch(() => {\n for (const name of names) {\n const next = partial[name];\n if (next !== undefined) field(name).value.set(next);\n }\n });\n } finally {\n programmatic = false;\n }\n }\n\n function reset(): void {\n programmatic = true;\n try {\n batch(() => {\n for (const name of names) {\n const f = field(name);\n f.value.set(f.initial);\n f.touched.set(false);\n }\n status.set('idle');\n submitError.set(undefined);\n });\n } finally {\n programmatic = false;\n }\n }\n\n async function submit(): Promise<void> {\n // Touch every field so validation errors become visible on submit attempts.\n batch(() => {\n for (const name of names) field(name).touched.set(true);\n });\n if (!valid.peek()) {\n // Invalid — do not enter the submitting lifecycle; field errors now show.\n return;\n }\n submitError.set(undefined);\n status.set('submitting');\n try {\n await config.onSubmit?.(values.peek());\n status.set('success');\n } catch (err) {\n submitError.set(err);\n status.set('error');\n }\n }\n\n function dispose(): void {\n for (const f of fields.values()) {\n f.unsub();\n f.error.dispose();\n f.valid.dispose();\n f.dirty.dispose();\n }\n values.dispose();\n errors.dispose();\n touchedMap.dispose();\n dirty.dispose();\n valid.dispose();\n submitting.dispose();\n submitted.dispose();\n }\n\n return {\n values,\n errors,\n touched: touchedMap,\n dirty,\n valid,\n submitting,\n submitted,\n status,\n submitError,\n field: (name) => field(name).api,\n setValues,\n submit,\n reset,\n dispose,\n };\n}\n\n","/**\n * @streetui/context — build-time provider/consumer scoping.\n *\n * StreetUI builds its semantic tree synchronously, top-down, when the DSL\n * builders run. A `Context` mirrors that shape: `provide(value, run)` pushes a\n * value for the duration of the synchronous `run()` (during which the child\n * DSL builders execute and may `consume()`), then pops it. Consumers resolve\n * the *nearest* enclosing provider, falling back to the context default.\n *\n * This is deliberately NOT a second reactive system. A context value can be a\n * signal (see @streetui/state); reactivity then belongs to that signal and is\n * torn down by the normal node lifecycle when the consuming subtree unmounts —\n * the context itself holds no subscriptions and leaves no refs behind after a\n * `provide()` call returns.\n */\n\nexport interface Context<T> {\n /** Unique identity for this context (useful for debugging/inspection). */\n readonly id: symbol;\n /** The value returned by {@link consume} when no provider is active. */\n readonly defaultValue: T;\n /**\n * Provide `value` to any `consume()` calls made synchronously inside `run`.\n * The value is popped again as soon as `run` returns (even if it throws),\n * so nesting resolves to the nearest active provider.\n */\n provide<R>(value: T, run: () => R): R;\n /** Read the nearest active provider's value, or {@link defaultValue}. */\n consume(): T;\n /** True while at least one provider is active for this context. */\n hasProvider(): boolean;\n}\n\n/**\n * Create a typed context with a required default value, so `consume()` always\n * returns a `T` (never `undefined` unless `T` itself permits it).\n */\nexport function createContext<T>(defaultValue: T, description?: string): Context<T> {\n const id = Symbol(description ?? 'streetui.context');\n const stack: T[] = [];\n\n return {\n id,\n defaultValue,\n provide<R>(value: T, run: () => R): R {\n stack.push(value);\n try {\n return run();\n } finally {\n stack.pop();\n }\n },\n consume(): T {\n return stack.length > 0 ? (stack[stack.length - 1] as T) : defaultValue;\n },\n hasProvider(): boolean {\n return stack.length > 0;\n },\n };\n}\n","/**\n * Minimal, framework-native internationalization for StreetUI.\n *\n * Built entirely on `@streetui/state` signals — there is no second reactive\n * system. The active locale is a writable signal; `t()` returns a derived\n * signal that recomputes when the locale changes, so translations plug\n * straight into the DSL's reactive text bindings (`text(() => i18n.t(...).get())`\n * or `text(i18n.t(...))`).\n *\n * Translation is deterministic: a missing key resolves to the key itself, and\n * the same (locale, key, params) always produces the same string on the server\n * and the client. That determinism is what keeps `renderToString()` and\n * `hydrate()` in agreement — provided the app boots the client with the same\n * initial locale it rendered with on the server.\n */\n\nimport {\n signal,\n derived,\n type ReadonlySignal,\n type DerivedSignal,\n} from '@streetui/state';\n\n/** A flat dictionary of message templates for a single locale. */\nexport type MessageMap = Record<string, string>;\n\n/** Values allowed in interpolation params. */\nexport type InterpolationParams = Record<string, string | number>;\n\nexport interface I18nConfig<M extends MessageMap> {\n /** The initial (and server-rendered) locale. */\n readonly locale: string;\n /** Messages keyed by locale, e.g. `{ en: {...}, fr: {...} }`. */\n readonly messages: Readonly<Record<string, M>>;\n /** Locale consulted when a key is absent from the active locale. */\n readonly fallbackLocale?: string;\n}\n\nexport interface I18n<M extends MessageMap> {\n /** The active locale as a reactive, read-only signal. */\n readonly locale: ReadonlySignal<string>;\n /** Switch the active locale; all `t()`/`plural()` signals recompute. */\n setLocale(locale: string): void;\n /** The locales that have a message map, in declaration order. */\n readonly locales: ReadonlyArray<string>;\n /** Reactive translation. Returns a derived signal — call `.get()` to read. */\n t(key: keyof M & string, params?: InterpolationParams): ReadonlySignal<string>;\n /** Non-reactive translation for the current locale (a one-shot read). */\n translate(key: keyof M & string, params?: InterpolationParams): string;\n /**\n * Reactive pluralization via `Intl.PluralRules`. Selects the message whose\n * key is `${key}.${category}` (e.g. `items.one`), falling back to\n * `${key}.other`. `count` is available to interpolation as `{count}`.\n */\n plural(key: string, count: number, params?: InterpolationParams): ReadonlySignal<string>;\n /** True when the active (or fallback) locale defines `key`. */\n has(key: string): boolean;\n}\n\nconst INTERPOLATION = /\\{(\\w+)\\}/g;\n\n/** Replace `{name}` placeholders using `params`; unknown names are left intact. */\nexport function interpolate(template: string, params?: InterpolationParams): string {\n if (params === undefined) return template;\n return template.replace(INTERPOLATION, (whole, name: string) => {\n const value = params[name];\n return value === undefined ? whole : String(value);\n });\n}\n\nexport function createI18n<M extends MessageMap>(config: I18nConfig<M>): I18n<M> {\n const messages = config.messages;\n const fallback = config.fallbackLocale;\n const localeSignal = signal<string>(config.locale);\n const locales = Object.keys(messages);\n\n /** Resolve a raw template for `key` in `loc`, then the fallback locale. */\n function lookup(loc: string, key: string): string | undefined {\n const active = messages[loc];\n const hit = active === undefined ? undefined : active[key];\n if (hit !== undefined) return hit;\n if (fallback !== undefined && fallback !== loc) {\n const fb = messages[fallback];\n if (fb !== undefined) return fb[key];\n }\n return undefined;\n }\n\n function resolve(loc: string, key: string, params?: InterpolationParams): string {\n const template = lookup(loc, key);\n // Deterministic miss: echo the key so output is stable server/client.\n return template === undefined ? key : interpolate(template, params);\n }\n\n function pluralKey(loc: string, key: string, count: number): string {\n const category = new Intl.PluralRules(loc).select(count);\n if (lookup(loc, `${key}.${category}`) !== undefined) return `${key}.${category}`;\n return `${key}.other`;\n }\n\n return {\n locale: localeSignal,\n locales,\n setLocale(loc: string): void {\n localeSignal.set(loc);\n },\n t(key, params): DerivedSignal<string> {\n return derived<string>(() => resolve(localeSignal.get(), key, params));\n },\n translate(key, params): string {\n return resolve(localeSignal.peek(), key, params);\n },\n plural(key, count, params): DerivedSignal<string> {\n const merged: InterpolationParams = { count, ...(params ?? {}) };\n return derived<string>(() => {\n const loc = localeSignal.get();\n return resolve(loc, pluralKey(loc, key, count), merged);\n });\n },\n has(key: string): boolean {\n return lookup(localeSignal.peek(), key) !== undefined;\n },\n };\n}\n","/**\n * StreetUI DevTools — graph inspector and debug utilities.\n */\n\nimport { formatDiagnostic } from '@streetui/core';\nimport type { ApplicationGraph, GraphNode } from '@streetui/graph';\nimport type { CompiledApplication } from '@streetui/compiler';\n\nexport interface InspectedNode {\n id: string;\n type: string;\n key: string | undefined;\n props: Record<string, unknown>;\n eventTypes: string[];\n stateBindings: string[];\n children: InspectedNode[];\n depth: number;\n}\n\nexport function inspectGraph(graph: ApplicationGraph): InspectedNode {\n return inspectNode(graph.root, 0);\n}\n\nfunction inspectNode(node: GraphNode, depth: number): InspectedNode {\n return {\n id: node.id,\n type: node.type,\n key: node.key,\n props: { ...node.props },\n eventTypes: node.events.map(e => e.type),\n stateBindings: node.stateRefs.map(r => `${r.propKey}→${r.signalId}`),\n depth,\n children: node.children.map(c => inspectNode(c, depth + 1)),\n };\n}\n\n/** Print a human-readable tree of the graph to a string. */\nexport function printGraph(graph: ApplicationGraph): string {\n const lines: string[] = [];\n graph.walk((node, depth) => {\n const indent = ' '.repeat(depth);\n const props = Object.entries(node.props)\n .filter(([k]) => !k.startsWith('_'))\n .map(([k, v]) => `${k}=${JSON.stringify(v)}`)\n .join(', ');\n const events = node.events.length > 0\n ? ` [events: ${node.events.map(e => e.type).join(', ')}]`\n : '';\n const stateRefs = node.stateRefs.length > 0\n ? ` [signals: ${node.stateRefs.map(r => r.propKey).join(', ')}]`\n : '';\n lines.push(`${indent}<${node.type}${props ? ` ${props}` : ''}${events}${stateRefs}>`);\n });\n return lines.join('\\n');\n}\n\n/** Print compilation diagnostics to a string. */\nexport function printDiagnostics(compiled: CompiledApplication): string {\n if (compiled.diagnostics.diagnostics.length === 0) {\n return '(no diagnostics)';\n }\n return compiled.diagnostics.diagnostics.map(formatDiagnostic).join('\\n');\n}\n\n/** Returns node counts per type. */\nexport function nodeTypeStats(graph: ApplicationGraph): Record<string, number> {\n const counts: Record<string, number> = {};\n graph.walk(node => {\n counts[node.type] = (counts[node.type] ?? 0) + 1;\n });\n return counts;\n}\n\n/** A single component instance surfaced for DevTools inspection (§21). */\nexport interface InspectedComponent {\n /** The build-order node id (churns across rebuilds — not stable identity). */\n id: string;\n /** The stable, author-provided identity key passed at the call site. */\n key: string | undefined;\n /** The definition's human-readable name (from `data-streetui-component`). */\n name: string;\n /** Depth of the component node in the graph. */\n depth: number;\n /** Number of direct child nodes the component rendered. */\n childCount: number;\n}\n\n/**\n * List every `component()` instance in the graph, in document order, with its\n * stable `key`, human-readable `name` and location. Components are ordinary\n * `'component'` GraphNodes (they flow through `inspectGraph`/`printGraph`\n * already); this is the first-class, component-aware view for DevTools — it\n * reads the inspectable `data-streetui-component` name attribute the DSL sets,\n * never any internal `_`-prefixed metadata. Names/keys are stable across\n * fine-grained prop updates (which never rebuild the node).\n */\nexport function inspectComponents(graph: ApplicationGraph): InspectedComponent[] {\n const out: InspectedComponent[] = [];\n graph.walk((node, depth) => {\n if (node.type !== 'component') return;\n const name = node.props['data-streetui-component'];\n out.push({\n id: node.id,\n key: node.key,\n name: typeof name === 'string' ? name : 'Component',\n depth,\n childCount: node.children.length,\n });\n });\n return out;\n}\n\n// ── Interaction inspection (§19) ─────────────────────────────────────────────\n\n/** An overlay currently wired in the graph (dialog/popover/tooltip/…). */\nexport interface InspectedOverlay {\n /** The build-order node id of the overlay's portal host. */\n id: string;\n /** The stable author-provided key, if any. */\n key: string | undefined;\n /** Whether the overlay is open right now (peeked, no subscription). */\n open: boolean;\n /** Modal (focus-trapping) overlay? */\n modal: boolean;\n /** Does it move focus into itself on open? */\n takesFocus: boolean;\n /** Is it a roving-focus menu (role=\"menu\")? */\n menu: boolean;\n /** Does Escape close it? */\n closeOnEscape: boolean;\n /** Does it restore focus to the opener on close? */\n restoreFocus: boolean;\n /** Depth of the portal host node in the graph. */\n depth: number;\n}\n\n/** A transition currently wired on a graph node. */\nexport interface InspectedTransition {\n /** The build-order node id the transition is attached to. */\n id: string;\n /** The stable author-provided key, if any. */\n key: string | undefined;\n /** The node type the transition animates (element/portal/list-item/…). */\n nodeType: string;\n /** Fallback completion timeout in ms (the resolved `duration`). */\n duration: number;\n /** Does it animate the very first appearance (initial mount)? */\n appear: boolean;\n /** Depth of the node in the graph. */\n depth: number;\n}\n\n/** A prod-safe snapshot of the graph's interaction wiring. */\nexport interface InspectedInteractions {\n overlays: InspectedOverlay[];\n transitions: InspectedTransition[];\n}\n\n/**\n * Minimal structural views of the descriptors the DSL registers behind\n * `__overlay__<id>` / `__transition__<id>`. Duplicated here (not imported from\n * `@streetui/dsl`) so DevTools reads the wiring structurally, with no build-time\n * dependency on the DSL package — the same no-fragmentation discipline the\n * renderer already follows.\n */\ninterface OverlayDescriptorLike {\n readonly open: { peek(): boolean };\n readonly modal: boolean;\n readonly takesFocus: boolean;\n readonly menu: boolean;\n readonly closeOnEscape: boolean;\n readonly restoreFocus: boolean;\n}\ninterface ResolvedTransitionLike {\n readonly duration: number;\n readonly appear: boolean;\n}\n\n/**\n * Snapshot every overlay and transition currently wired in the graph, in\n * document order. This is the interaction-aware companion to\n * {@link inspectComponents}: it reads only the `__overlay__<id>` /\n * `__transition__<id>` handler descriptors and public graph structure — it\n * peeks the `open` signal without subscribing, retains no DOM nodes, mutates\n * nothing, and is safe to call in production. Because a departing overlay's\n * handler is pruned on detach (`_unregisterNodeHandlers`), a closed-and-removed\n * overlay simply no longer appears here.\n */\nexport function inspectInteractions(graph: ApplicationGraph): InspectedInteractions {\n const overlays: InspectedOverlay[] = [];\n const transitions: InspectedTransition[] = [];\n graph.walk((node, depth) => {\n const overlayFn = graph.getHandler(`__overlay__${node.id}`) as\n | (() => OverlayDescriptorLike)\n | undefined;\n if (overlayFn !== undefined) {\n const d = overlayFn();\n overlays.push({\n id: node.id,\n key: node.key,\n open: d.open.peek(),\n modal: d.modal,\n takesFocus: d.takesFocus,\n menu: d.menu,\n closeOnEscape: d.closeOnEscape,\n restoreFocus: d.restoreFocus,\n depth,\n });\n }\n const transitionFn = graph.getHandler(`__transition__${node.id}`) as\n | (() => ResolvedTransitionLike)\n | undefined;\n if (transitionFn !== undefined) {\n const t = transitionFn();\n transitions.push({\n id: node.id,\n key: node.key,\n nodeType: node.type,\n duration: t.duration,\n appear: t.appear,\n depth,\n });\n }\n });\n return { overlays, transitions };\n}\n\n","/**\n * DevTools foundation (v0.6, Phase 18). A single read-only entry point that\n * aggregates everything an eventual DevTools UI would need — application\n * identity, the graph tree, signal bindings, page/route surface, node\n * statistics, and diagnostics — WITHOUT introducing a second representation of\n * the graph. It reuses `inspectGraph`/`nodeTypeStats` from the inspector and\n * reads `CompiledApplication` metadata directly. This is a foundation, not a\n * UI: it returns plain data so a UI (or a test, or a CLI command) can render it.\n */\n\nimport type { CompiledApplication } from '@streetui/compiler';\nimport { formatDiagnostic } from '@streetui/core';\nimport { inspectGraph, nodeTypeStats, type InspectedNode } from './inspector.js';\n\n/** Stable identity of a compiled application. */\nexport interface ApplicationIdentity {\n readonly name: string;\n readonly version: string;\n /** Epoch millis the application was compiled. */\n readonly compiledAt: number;\n}\n\n/** A page node reachable as a direct child of the application root. */\nexport interface InspectedPage {\n readonly id: string;\n /** The page key when one was supplied in the DSL. */\n readonly key: string | undefined;\n}\n\n/** Compilation diagnostics summarised for display. */\nexport interface DiagnosticsSummary {\n readonly errors: number;\n readonly warnings: number;\n readonly messages: string[];\n}\n\n/**\n * Cheap, count-only performance snapshot (v0.7 §20). These are structural\n * counts derived from a single graph walk — NOT timings and NOT a profiler.\n * They let a DevTools panel or a CI check spot the shapes that correlate with\n * slow apps (very large graphs, deep trees, big lists, many subscriptions)\n * without measuring anything at runtime.\n */\nexport interface PerfSnapshot {\n /** Total GraphNodes in the tree (root included). */\n readonly totalNodes: number;\n /** Maximum nesting depth (root = 0). */\n readonly maxDepth: number;\n /** Total event handler registrations across all nodes. */\n readonly eventHandlers: number;\n /** Total signal→prop bindings across all nodes. */\n readonly stateBindings: number;\n /** Distinct signals referenced anywhere in the graph. */\n readonly distinctSignals: number;\n /** Largest single-node child count (a proxy for the biggest list/section). */\n readonly largestChildCount: number;\n /**\n * Number of reactive keyed-list sites driven by the optimised lazy-plan\n * reconciler (v1.1 §15/§25). Counted from the graph's `__listplan__<id>`\n * handler registrations — one per `listOf(...)` bound to a signal. These are\n * the nodes whose updates take the identity-short-circuit + LIS minimal-move\n * path, so surfacing the count lets a panel or CI check see how much of an app\n * benefits from the keyed-list engine without measuring anything at runtime.\n */\n readonly reactiveLists: number;\n}\n\n/**\n * The complete read-only snapshot of a compiled application. Everything here is\n * derived from the single `CompiledApplication` graph — no state is duplicated.\n */\nexport interface ApplicationInspection {\n readonly identity: ApplicationIdentity;\n readonly graph: InspectedNode;\n /** Count of nodes per DSL type (e.g. `{ section: 2, button: 3 }`). */\n readonly nodeStats: Record<string, number>;\n /** Unique signal ids bound anywhere in the graph, sorted. */\n readonly signals: string[];\n /** Page nodes directly under the root — the app's top-level route surface. */\n readonly pages: InspectedPage[];\n readonly diagnostics: DiagnosticsSummary;\n /** Cheap structural performance counters (v0.7 §20). */\n readonly perf: PerfSnapshot;\n}\n\n/** Walk the inspected tree once, accumulating the count-only perf snapshot. */\nfunction collectPerf(\n node: InspectedNode,\n distinctSignals: number,\n acc: { totalNodes: number; maxDepth: number; eventHandlers: number; stateBindings: number; largestChildCount: number },\n): void {\n acc.totalNodes += 1;\n if (node.depth > acc.maxDepth) acc.maxDepth = node.depth;\n acc.eventHandlers += node.eventTypes.length;\n acc.stateBindings += node.stateBindings.length;\n if (node.children.length > acc.largestChildCount) acc.largestChildCount = node.children.length;\n for (const child of node.children) collectPerf(child, distinctSignals, acc);\n}\n\n/** Collect every distinct signal id referenced by any node in the tree. */\nfunction collectSignals(node: InspectedNode, into: Set<string>): void {\n for (const binding of node.stateBindings) {\n // Bindings are formatted `propKey→signalId` by the inspector.\n const arrow = binding.indexOf('→');\n const signalId = arrow >= 0 ? binding.slice(arrow + 1) : binding;\n if (signalId.length > 0) into.add(signalId);\n }\n for (const child of node.children) collectSignals(child, into);\n}\n\n/**\n * Build the full inspection snapshot for a compiled application. Pure and\n * side-effect free — safe to call in a server, a test, or a DevTools panel.\n */\nexport function inspectApplication(compiled: CompiledApplication): ApplicationInspection {\n const graph = inspectGraph(compiled.graph);\n\n const signals = new Set<string>();\n collectSignals(graph, signals);\n\n const pages: InspectedPage[] = graph.children\n .filter((child) => child.type === 'page')\n .map((child) => ({ id: child.id, key: child.key }));\n\n const diags = compiled.diagnostics.diagnostics;\n const errors = diags.filter((d) => d.severity === 'error').length;\n\n const perfAcc = { totalNodes: 0, maxDepth: 0, eventHandlers: 0, stateBindings: 0, largestChildCount: 0 };\n collectPerf(graph, signals.size, perfAcc);\n\n // Count optimised keyed-list sites from the handler registry (one\n // `__listplan__<id>` per signal-driven `listOf`). Reading the map directly\n // keeps this a pure, count-only derivation — no second graph walk.\n let reactiveLists = 0;\n for (const key of compiled.graph.handlers.keys()) {\n if (key.startsWith('__listplan__')) reactiveLists += 1;\n }\n\n return {\n identity: {\n name: compiled.name,\n version: compiled.version,\n compiledAt: compiled.compiledAt,\n },\n graph,\n nodeStats: nodeTypeStats(compiled.graph),\n signals: [...signals].sort(),\n pages,\n diagnostics: {\n errors,\n warnings: diags.length - errors,\n messages: diags.map(formatDiagnostic),\n },\n perf: {\n totalNodes: perfAcc.totalNodes,\n maxDepth: perfAcc.maxDepth,\n eventHandlers: perfAcc.eventHandlers,\n stateBindings: perfAcc.stateBindings,\n distinctSignals: signals.size,\n largestChildCount: perfAcc.largestChildCount,\n reactiveLists,\n },\n };\n}\n","/**\n * Dev-only performance diagnostics (v0.7 §21).\n *\n * A pure, cheap, count-based check that flags graph *shapes* known to correlate\n * with slow apps — very large graphs, deep trees, oversized lists/sections, and\n * heavy reactive fan-out. It is NOT wired into mount/render and adds ZERO cost\n * to the runtime hot path; a developer (or a CLI command, or a test) calls it\n * explicitly. Thresholds are advisory and overridable.\n *\n * This intentionally reuses the counts already produced by `inspectApplication`\n * — it introduces no second graph walk of its own beyond reading that snapshot.\n */\n\nimport type { CompiledApplication } from '@streetui/compiler';\nimport { inspectApplication } from './application.js';\n\nexport interface PerfThresholds {\n /** Warn when the graph exceeds this many nodes. */\n readonly maxNodes: number;\n /** Warn when nesting depth exceeds this. */\n readonly maxDepth: number;\n /** Warn when any single node has more than this many children (big list). */\n readonly maxChildCount: number;\n /** Warn when distinct signals exceed this (reactive fan-out). */\n readonly maxSignals: number;\n}\n\nexport const DEFAULT_PERF_THRESHOLDS: PerfThresholds = {\n maxNodes: 5000,\n maxDepth: 32,\n maxChildCount: 1000,\n maxSignals: 1000,\n};\n\nexport type PerfDiagnosticCode =\n | 'large-graph'\n | 'deep-tree'\n | 'large-list'\n | 'high-signal-fanout';\n\nexport interface PerfDiagnostic {\n readonly code: PerfDiagnosticCode;\n readonly message: string;\n /** The observed count that tripped the threshold. */\n readonly observed: number;\n /** The threshold it exceeded. */\n readonly threshold: number;\n}\n\n/**\n * Return advisory performance diagnostics for a compiled application. An empty\n * array means nothing tripped a threshold. Never throws; never mutates.\n */\nexport function diagnosePerformance(\n compiled: CompiledApplication,\n thresholds: Partial<PerfThresholds> = {},\n): PerfDiagnostic[] {\n const t = { ...DEFAULT_PERF_THRESHOLDS, ...thresholds };\n const { perf } = inspectApplication(compiled);\n const out: PerfDiagnostic[] = [];\n\n if (perf.totalNodes > t.maxNodes) {\n out.push({\n code: 'large-graph',\n message: `Graph has ${perf.totalNodes} nodes (> ${t.maxNodes}); consider splitting the view or paginating.`,\n observed: perf.totalNodes,\n threshold: t.maxNodes,\n });\n }\n if (perf.maxDepth > t.maxDepth) {\n out.push({\n code: 'deep-tree',\n message: `Graph nests ${perf.maxDepth} levels deep (> ${t.maxDepth}); deep trees slow mount and reconciliation.`,\n observed: perf.maxDepth,\n threshold: t.maxDepth,\n });\n }\n if (perf.largestChildCount > t.maxChildCount) {\n out.push({\n code: 'large-list',\n message: `A single node has ${perf.largestChildCount} children (> ${t.maxChildCount}); large un-windowed lists dominate DOM cost.`,\n observed: perf.largestChildCount,\n threshold: t.maxChildCount,\n });\n }\n if (perf.distinctSignals > t.maxSignals) {\n out.push({\n code: 'high-signal-fanout',\n message: `${perf.distinctSignals} distinct signals are bound (> ${t.maxSignals}); heavy reactive fan-out increases update overhead.`,\n observed: perf.distinctSignals,\n threshold: t.maxSignals,\n });\n }\n\n return out;\n}\n","/**\n * Reactive-surface inspection for DevTools.\n *\n * These functions turn the framework's live objects — signals, resources,\n * router, forms, context, i18n — into plain, read-only snapshots suitable for a\n * DevTools panel. They never mutate anything and never subscribe; each call is a\n * one-shot `peek`. Sensitive-by-default surfaces (resource payloads, form field\n * values) are omitted unless the caller explicitly opts in, so a panel cannot\n * accidentally display tokens, passwords, or private data.\n *\n * Router/forms/context/i18n are described by *structural* interfaces rather than\n * imported types, so DevTools stays decoupled from those packages (no extra\n * dependencies) while still inspecting them when present.\n */\n\nimport {\n type ReadonlySignal,\n type ResourceStatus,\n type SignalKind,\n signalKind,\n observerCount,\n} from '@streetui/state';\n\n// ── Signals ─────────────────────────────────────────────────────────────────\n\nexport interface SignalInspection {\n /** Whether the signal is writable or a derived computation. */\n readonly kind: SignalKind;\n /** The current value (redacted if requested). */\n readonly value: unknown;\n /** Live observer count when the signal exposes it, else undefined. */\n readonly observerCount: number | undefined;\n}\n\nexport interface InspectSignalOptions {\n /**\n * Redact the value: `true` replaces it with `'[redacted]'`; a function maps\n * the raw value to whatever should be shown. Use for signals that may hold\n * sensitive data. Omitted → the value is shown as-is.\n */\n readonly redact?: boolean | ((value: unknown) => unknown);\n}\n\n/** Snapshot a signal's kind, current value, and observer count. Read-only. */\nexport function inspectSignal(\n source: ReadonlySignal<unknown>,\n options: InspectSignalOptions = {},\n): SignalInspection {\n const raw = source.peek();\n let value: unknown = raw;\n if (options.redact === true) value = '[redacted]';\n else if (typeof options.redact === 'function') value = options.redact(raw);\n\n return {\n kind: signalKind(source),\n value,\n observerCount: observerCount(source),\n };\n}\n\n// ── Resources ─────────────────────────────────────────────────────────────\n\n/** The read-only slice of a resource this module needs. */\nexport interface ResourceLike {\n readonly status: ReadonlySignal<ResourceStatus>;\n readonly data: ReadonlySignal<unknown>;\n readonly error: ReadonlySignal<unknown>;\n readonly loading: ReadonlySignal<boolean>;\n readonly isRefetching: ReadonlySignal<boolean>;\n}\n\nexport interface ResourceInspection {\n readonly status: ResourceStatus;\n readonly loading: boolean;\n readonly isRefetching: boolean;\n readonly hasData: boolean;\n readonly hasError: boolean;\n /** The error's constructor name (safe — no message/payload). */\n readonly errorName: string | undefined;\n /** The error message — only present when `includeData` is set. */\n readonly errorMessage?: string;\n /** The loaded value — only present when `includeData` is set. */\n readonly data?: unknown;\n}\n\nexport interface InspectResourceOptions {\n /**\n * Include the loaded `data` and the error `message`. Off by default because a\n * resource payload commonly carries user or secret data.\n */\n readonly includeData?: boolean;\n}\n\n/** Snapshot a resource's lifecycle. Payload/message hidden unless opted in. */\nexport function inspectResource(\n resource: ResourceLike,\n options: InspectResourceOptions = {},\n): ResourceInspection {\n const error = resource.error.peek();\n const hasError = error !== undefined && error !== null;\n const base: ResourceInspection = {\n status: resource.status.peek(),\n loading: resource.loading.peek(),\n isRefetching: resource.isRefetching.peek(),\n hasData: resource.data.peek() !== undefined,\n hasError,\n errorName: hasError ? errorConstructorName(error) : undefined,\n };\n if (options.includeData !== true) return base;\n\n return {\n ...base,\n data: resource.data.peek(),\n ...(hasError ? { errorMessage: errorMessageOf(error) } : {}),\n };\n}\n\nfunction errorConstructorName(error: unknown): string {\n if (error instanceof Error) return error.name;\n return typeof error;\n}\n\nfunction errorMessageOf(error: unknown): string {\n if (error instanceof Error) return error.message;\n return String(error);\n}\n\n// ── Router ──────────────────────────────────────────────────────────────────\n\nexport interface RouteMatchLike {\n readonly path: string;\n readonly pattern: string;\n readonly params: Readonly<Record<string, string>>;\n readonly query: URLSearchParams;\n readonly isFallback?: boolean;\n}\n\nexport interface RouterLike {\n readonly currentRoute: ReadonlySignal<RouteMatchLike>;\n}\n\nexport interface RouterInspection {\n readonly path: string;\n readonly pattern: string;\n readonly params: Record<string, string>;\n readonly query: Record<string, string>;\n readonly isFallback: boolean;\n}\n\n/** Snapshot the router's current route. Read-only. */\nexport function inspectRouter(router: RouterLike): RouterInspection {\n const match = router.currentRoute.peek();\n const query: Record<string, string> = {};\n for (const [k, v] of match.query.entries()) query[k] = v;\n return {\n path: match.path,\n pattern: match.pattern,\n params: { ...match.params },\n query,\n isFallback: match.isFallback === true,\n };\n}\n\n// ── Forms ─────────────────────────────────────────────────────────────────\n\nexport interface FormLike {\n readonly values: ReadonlySignal<Record<string, unknown>>;\n readonly errors: ReadonlySignal<Record<string, string | undefined>>;\n readonly touched: ReadonlySignal<Record<string, boolean | undefined>>;\n readonly dirty: ReadonlySignal<boolean>;\n readonly valid: ReadonlySignal<boolean>;\n readonly status: ReadonlySignal<string>;\n}\n\nexport interface FormInspection {\n readonly fields: string[];\n /** Per-field validation messages (safe — not the entered values). */\n readonly errors: Record<string, string>;\n readonly touched: Record<string, boolean>;\n readonly dirty: boolean;\n readonly valid: boolean;\n readonly status: string;\n /** Entered field values — only present when `includeValues` is set. */\n readonly values?: Record<string, unknown>;\n}\n\nexport interface InspectFormOptions {\n /**\n * Include the entered field `values`. Off by default because form fields\n * frequently hold passwords or other secrets.\n */\n readonly includeValues?: boolean;\n}\n\n/** Snapshot form validation state. Entered values hidden unless opted in. */\nexport function inspectForm(form: FormLike, options: InspectFormOptions = {}): FormInspection {\n const values = form.values.peek();\n const errorsRaw = form.errors.peek();\n const touchedRaw = form.touched.peek();\n\n const errors: Record<string, string> = {};\n for (const [k, v] of Object.entries(errorsRaw)) if (v !== undefined) errors[k] = v;\n const touched: Record<string, boolean> = {};\n for (const [k, v] of Object.entries(touchedRaw)) touched[k] = v === true;\n\n const base: FormInspection = {\n fields: Object.keys(values),\n errors,\n touched,\n dirty: form.dirty.peek(),\n valid: form.valid.peek(),\n status: form.status.peek(),\n };\n if (options.includeValues !== true) return base;\n return { ...base, values: { ...values } };\n}\n\n// ── Context ─────────────────────────────────────────────────────────────────\n\nexport interface ContextLike {\n readonly id: symbol;\n hasProvider(): boolean;\n}\n\nexport interface ContextInspection {\n /** The context's descriptive label (from its Symbol). */\n readonly description: string;\n /** Whether a provider is currently active. */\n readonly hasProvider: boolean;\n}\n\n/** Snapshot a context's identity and provider presence. No value dumped. */\nexport function inspectContext(context: ContextLike): ContextInspection {\n return {\n description: context.id.description ?? 'streetui.context',\n hasProvider: context.hasProvider(),\n };\n}\n\n// ── i18n ──────────────────────────────────────────────────────────────────\n\nexport interface I18nLike {\n readonly locale: ReadonlySignal<string>;\n readonly locales: ReadonlyArray<string>;\n has(key: string): boolean;\n}\n\nexport interface I18nInspection {\n readonly locale: string;\n readonly locales: string[];\n /** Of the probed keys, those with no translation in the active/fallback locale. */\n readonly missingKeys?: string[];\n}\n\nexport interface InspectI18nOptions {\n /** Keys to probe for presence; any absent ones are reported as missing. */\n readonly checkKeys?: readonly string[];\n}\n\n/** Snapshot i18n locale state and (optionally) missing translation keys. */\nexport function inspectI18n(i18n: I18nLike, options: InspectI18nOptions = {}): I18nInspection {\n const base: I18nInspection = {\n locale: i18n.locale.peek(),\n locales: [...i18n.locales],\n };\n if (options.checkKeys === undefined) return base;\n const missingKeys = options.checkKeys.filter((k) => !i18n.has(k));\n return { ...base, missingKeys };\n}\n","/**\n * DevTools session & panels — the first real StreetUI DevTools surface.\n *\n * This is a *headless* DevTools layer: it composes the existing read-only\n * inspection functions (`inspectApplication`, `diagnosePerformance`, and the\n * reactive inspectors) into the panels a DevTools UI shows — Application, Graph,\n * Signals, Router, Resources, Forms, Context, i18n, and Performance — and\n * returns them as plain data plus a text formatter. Any host (a browser panel, a\n * CLI command, a test) can render that data.\n *\n * Design constraints honoured here:\n * - No second graph and no second reactive system — everything is derived from\n * the one `CompiledApplication` and the app's own live signals.\n * - Explicit activation: nothing in the runtime imports this. A session only\n * exists once dev code calls `createDevTools`, so production pays no cost.\n * - Live updates use a simple explicit `refresh()` — DevTools never subscribes\n * to or instruments the reactive graph.\n * - Sensitive surfaces (resource payloads, form values) stay hidden unless the\n * caller opts in per the underlying inspectors.\n */\n\nimport type { CompiledApplication } from '@streetui/compiler';\nimport type { ReadonlySignal } from '@streetui/state';\nimport {\n inspectApplication,\n type ApplicationInspection,\n type ApplicationIdentity,\n type InspectedPage,\n} from './application.js';\nimport type { InspectedNode } from './inspector.js';\nimport { diagnosePerformance, type PerfDiagnostic, type PerfThresholds } from './diagnostics.js';\nimport {\n inspectSignal,\n inspectResource,\n inspectRouter,\n inspectForm,\n inspectContext,\n inspectI18n,\n type SignalInspection,\n type ResourceInspection,\n type RouterInspection,\n type FormInspection,\n type ContextInspection,\n type I18nInspection,\n type ResourceLike,\n type RouterLike,\n type FormLike,\n type ContextLike,\n type I18nLike,\n} from './inspect-reactive.js';\n\n// ── Panel shapes ────────────────────────────────────────────────────────────\n\nexport interface ApplicationPanel {\n readonly identity: ApplicationIdentity;\n readonly nodeCount: number;\n readonly maxDepth: number;\n readonly pages: readonly InspectedPage[];\n readonly signalCount: number;\n readonly eventHandlers: number;\n readonly stateBindings: number;\n readonly errors: number;\n readonly warnings: number;\n}\n\nexport interface SignalsPanel {\n /** Distinct signal ids referenced anywhere in the graph (structural). */\n readonly boundSignalIds: readonly string[];\n /** Live inspections for signals the app registered with DevTools, by label. */\n readonly live: Readonly<Record<string, SignalInspection>>;\n}\n\nexport interface PerformancePanel {\n readonly snapshot: ApplicationInspection['perf'];\n readonly diagnostics: readonly PerfDiagnostic[];\n}\n\n/** All panels captured at one `refresh()`. */\nexport interface DevToolsSnapshot {\n readonly application: ApplicationPanel;\n readonly graph: InspectedNode;\n readonly signals: SignalsPanel;\n readonly performance: PerformancePanel;\n readonly router?: RouterInspection;\n readonly resources?: Readonly<Record<string, ResourceInspection>>;\n readonly forms?: Readonly<Record<string, FormInspection>>;\n readonly contexts?: Readonly<Record<string, ContextInspection>>;\n readonly i18n?: I18nInspection;\n}\n\n// ── Live sources ──────────────────────────────────────────────────────────\n\n/**\n * The app's own live reactive objects, handed to DevTools explicitly so it can\n * inspect them. The compiled graph knows signal *ids* but not the live `Signal`\n * instances, so the app registers whichever surfaces it wants visible. Every\n * field is optional — a session works with none of them (structure-only).\n */\nexport interface DevToolsSources {\n /** Live signals to inspect, keyed by a human label shown in the panel. */\n readonly signals?: Readonly<Record<string, ReadonlySignal<unknown>>>;\n /** Live resources to inspect, keyed by label. */\n readonly resources?: Readonly<Record<string, ResourceLike>>;\n /** The app router, if any. */\n readonly router?: RouterLike;\n /** Live forms to inspect, keyed by label. */\n readonly forms?: Readonly<Record<string, FormLike>>;\n /** Live contexts to inspect, keyed by label. */\n readonly contexts?: Readonly<Record<string, ContextLike>>;\n /** The app i18n instance, if any. */\n readonly i18n?: I18nLike;\n}\n\nexport interface DevToolsOptions {\n /** Thresholds forwarded to `diagnosePerformance`. */\n readonly perfThresholds?: PerfThresholds;\n /**\n * Redact live signal values by default (passed to `inspectSignal`). Use in\n * shared or recorded sessions so values never reach the panel. Off by default.\n */\n readonly redactSignals?: boolean | ((value: unknown) => unknown);\n /** i18n keys to probe for missing translations, forwarded to `inspectI18n`. */\n readonly i18nCheckKeys?: readonly string[];\n}\n\n// ── Session ─────────────────────────────────────────────────────────────────\n\n/**\n * A headless DevTools session over one compiled application.\n *\n * The session holds the compiled app plus the app's registered live sources and\n * produces an immutable {@link DevToolsSnapshot} on demand. Live values are read\n * only when `refresh()` is called (explicit-refresh protocol, §7): the session\n * never subscribes to signals or instruments the reactive graph, so it adds no\n * cost to the running app between refreshes.\n */\nexport interface DevToolsSession {\n /** The most recent snapshot. Recomputed by `refresh()`. */\n readonly snapshot: DevToolsSnapshot;\n /**\n * Recompute every panel from the current live state and return the new\n * snapshot. This is the only way values change — DevTools pulls, it never\n * gets pushed to.\n */\n refresh(): DevToolsSnapshot;\n /**\n * Find a node in the graph by id and return that subtree, or `undefined`.\n * Backs a UI tree inspector's node-selection (§8) without a second graph.\n */\n selectNode(id: string): InspectedNode | undefined;\n /** Render the current snapshot as a plain-text report (for CLI/tests/logs). */\n format(): string;\n}\n\n/**\n * Create a DevTools session. Nothing in the runtime calls this — a session only\n * exists once dev code opts in, so production never pays for it.\n */\nexport function createDevTools(\n compiled: CompiledApplication,\n sources: DevToolsSources = {},\n options: DevToolsOptions = {},\n): DevToolsSession {\n let current = capture(compiled, sources, options);\n\n return {\n get snapshot() {\n return current;\n },\n refresh() {\n current = capture(compiled, sources, options);\n return current;\n },\n selectNode(id: string) {\n return findNode(current.graph, id);\n },\n format() {\n return formatSnapshot(current);\n },\n };\n}\n\n// ── Capture ───────────────────────────────────────────────────────────────\n\nfunction capture(\n compiled: CompiledApplication,\n sources: DevToolsSources,\n options: DevToolsOptions,\n): DevToolsSnapshot {\n const app: ApplicationInspection = inspectApplication(compiled);\n\n const application: ApplicationPanel = {\n identity: app.identity,\n nodeCount: app.perf.totalNodes,\n maxDepth: app.perf.maxDepth,\n pages: app.pages,\n signalCount: app.signals.length,\n eventHandlers: app.perf.eventHandlers,\n stateBindings: app.perf.stateBindings,\n errors: app.diagnostics.errors,\n warnings: app.diagnostics.warnings,\n };\n\n const live: Record<string, SignalInspection> = {};\n if (sources.signals !== undefined) {\n for (const [label, sig] of Object.entries(sources.signals)) {\n live[label] = inspectSignal(\n sig,\n options.redactSignals !== undefined ? { redact: options.redactSignals } : {},\n );\n }\n }\n const signals: SignalsPanel = { boundSignalIds: app.signals, live };\n\n const performance: PerformancePanel = {\n snapshot: app.perf,\n diagnostics: diagnosePerformance(compiled, options.perfThresholds),\n };\n\n const snapshot: DevToolsSnapshot = {\n application,\n graph: app.graph,\n signals,\n performance,\n ...(sources.router !== undefined ? { router: inspectRouter(sources.router) } : {}),\n ...(sources.resources !== undefined\n ? { resources: mapInspect(sources.resources, (r) => inspectResource(r)) }\n : {}),\n ...(sources.forms !== undefined\n ? { forms: mapInspect(sources.forms, (f) => inspectForm(f)) }\n : {}),\n ...(sources.contexts !== undefined\n ? { contexts: mapInspect(sources.contexts, (c) => inspectContext(c)) }\n : {}),\n ...(sources.i18n !== undefined\n ? {\n i18n: inspectI18n(\n sources.i18n,\n options.i18nCheckKeys !== undefined ? { checkKeys: options.i18nCheckKeys } : {},\n ),\n }\n : {}),\n };\n return snapshot;\n}\n\nfunction mapInspect<T, R>(\n source: Readonly<Record<string, T>>,\n inspect: (value: T) => R,\n): Record<string, R> {\n const out: Record<string, R> = {};\n for (const [label, value] of Object.entries(source)) out[label] = inspect(value);\n return out;\n}\n\n// ── Graph node lookup (§8) ──────────────────────────────────────────────────\n\nfunction findNode(node: InspectedNode, id: string): InspectedNode | undefined {\n if (node.id === id) return node;\n for (const child of node.children) {\n const found = findNode(child, id);\n if (found !== undefined) return found;\n }\n return undefined;\n}\n\n// ── Text formatter ────────────────────────────────────────────────────────\n\nfunction formatSnapshot(s: DevToolsSnapshot): string {\n const lines: string[] = [];\n const app = s.application;\n lines.push(`StreetUI DevTools — ${app.identity.name} v${app.identity.version}`);\n lines.push(\n `Application: ${app.nodeCount} nodes, depth ${app.maxDepth}, ${app.pages.length} page(s)`,\n );\n lines.push(\n ` signals ${app.signalCount} · handlers ${app.eventHandlers} · bindings ${app.stateBindings} · errors ${app.errors} · warnings ${app.warnings}`,\n );\n\n lines.push(`Signals: ${s.signals.boundSignalIds.length} bound in graph`);\n for (const [label, sig] of Object.entries(s.signals.live)) {\n lines.push(` ${label} [${sig.kind}] = ${format(sig.value)} · observers ${sig.observerCount ?? '?'}`);\n }\n\n if (s.router !== undefined) {\n lines.push(`Router: ${s.router.path} (${s.router.pattern})${s.router.isFallback ? ' [fallback]' : ''}`);\n }\n\n if (s.resources !== undefined) {\n lines.push('Resources:');\n for (const [label, r] of Object.entries(s.resources)) {\n lines.push(` ${label}: ${r.status}${r.loading ? ' (loading)' : ''}${r.hasError ? ` !${r.errorName}` : ''}`);\n }\n }\n\n if (s.forms !== undefined) {\n lines.push('Forms:');\n for (const [label, f] of Object.entries(s.forms)) {\n lines.push(` ${label}: ${f.valid ? 'valid' : 'invalid'} · ${f.status} · fields ${f.fields.length}`);\n }\n }\n\n if (s.contexts !== undefined) {\n lines.push('Contexts:');\n for (const [label, c] of Object.entries(s.contexts)) {\n lines.push(` ${label} (${c.description}): ${c.hasProvider ? 'provided' : 'no provider'}`);\n }\n }\n\n if (s.i18n !== undefined) {\n const missing = s.i18n.missingKeys;\n lines.push(\n `i18n: ${s.i18n.locale} of [${s.i18n.locales.join(', ')}]${missing !== undefined ? ` · missing ${missing.length}` : ''}`,\n );\n }\n\n lines.push(\n `Performance: ${s.performance.diagnostics.length} diagnostic(s), ${s.performance.snapshot.totalNodes} nodes`,\n );\n for (const d of s.performance.diagnostics) {\n lines.push(` ${d.code}: ${d.message}`);\n }\n\n return lines.join('\\n');\n}\n\nfunction format(value: unknown): string {\n if (typeof value === 'string') return JSON.stringify(value);\n if (value === null || value === undefined) return String(value);\n if (typeof value === 'object') {\n try {\n return JSON.stringify(value);\n } catch {\n return '[object]';\n }\n }\n return String(value);\n}\n","/**\n * Project-configuration surface for `streetui.config.ts`.\n *\n * The configuration *type* is single-sourced from the internal CLI module (so\n * there is exactly one authoritative `StreetUIConfig` shape). `defineConfig` is\n * the standard one-line identity helper used purely for editor type-inference on\n * the exported config object.\n *\n * This lives in its own tiny module — rather than re-exporting `defineConfig`\n * from the CLI barrel — so that importing `streetui` for application code does\n * **not** drag the CLI's build machinery (and its `esbuild` dependency) into the\n * client runtime bundle. The CLI's own `loadConfig` reads the default export of\n * `streetui.config.ts` regardless of which identity helper wrapped it, so the\n * behaviour is identical to configuring via the CLI directly.\n */\nimport type { StreetUIConfig } from '@streetui/cli';\n\nexport type { StreetUIConfig, ResolvedConfig } from '@streetui/cli';\n\n/** Identity helper that gives `streetui.config.ts` full type-checking + inference. */\nexport function defineConfig(config: StreetUIConfig): StreetUIConfig {\n return config;\n}\n"],"mappings":";AASO,IAAM,UAAU;;;AC6BvB,IAAI,kBAA2C;AAE/C,SAAS,aAAgB,UAA4B,IAAgB;AACnE,QAAM,OAAO;AACb,oBAAkB;AAClB,MAAI;AACF,WAAO,GAAG;AAAA,EACZ,UAAE;AACA,sBAAkB;AAAA,EACpB;AACF;AAKA,IAAI,cAAc;AAWlB,IAAM,kBAAkB,oBAAI,IAAmC;AAE/D,SAAS,mBAAmB,KAAsB,OAAsB;AACtE,kBAAgB,IAAI,KAAK,EAAE,QAAQ,KAAK,MAAM,CAAC;AACjD;AAEA,SAAS,cAAoB;AAC3B,QAAM,UAAU,CAAC,GAAG,gBAAgB,OAAO,CAAC;AAC5C,kBAAgB,MAAM;AACtB,aAAW,EAAE,QAAQ,KAAK,MAAM,KAAK,SAAS;AAC5C,QAAI,YAAY,KAAK;AAAA,EACvB;AACF;AAUO,IAAM,SAAN,MAAgE;AAAA,EAC3D;AAAA,EACO,eAAmC,oBAAI,IAAI;AAAA,EAC3C,aAAoC,oBAAI,IAAI;AAAA,EAE7D,YAAY,SAAY;AACtB,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAS;AACP,QAAI,oBAAoB,MAAM;AAC5B,WAAK,WAAW,IAAI,eAAe;AACnC,sBAAgB,WAAW,IAA+B;AAAA,IAC5D;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,OAAU;A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,WAAW;AACtB,eAAW,CAAC,OAAO,CAAC,KAAK,OAAO,QAAQ,EAAE,QAAQ,GAAG;AACnD,YAAM,KAAK,KAAK,KAAK,KAAK,EAAE,WAAW,MAAM,EAAE,cAAc,aAAa,aAAa,EAAE;AAAA,IAC3F;AAAA,EACF;AAEA,MAAI,EAAE,SAAS,QAAW;AACxB,UAAM,UAAU,EAAE,KAAK;AACvB,UAAM;AAAA,MACJ,SAAS,EAAE,KAAK,MAAM,QAAQ,EAAE,KAAK,QAAQ,KAAK,IAAI,CAAC,IAAI,YAAY,SAAY,iBAAc,QAAQ,MAAM,KAAK,EAAE;AAAA,IACxH;AAAA,EACF;AAEA,QAAM;AAAA,IACJ,gBAAgB,EAAE,YAAY,YAAY,MAAM,mBAAmB,EAAE,YAAY,SAAS,UAAU;AAAA,EACtG;AACA,aAAW,KAAK,EAAE,YAAY,aAAa;AACzC,UAAM,KAAK,KAAK,EAAE,IAAI,KAAK,EAAE,OAAO,EAAE;AAAA,EACxC;AAEA,SAAO,MAAM,KAAK,IAAI;AACxB;AAEA,SAAS,OAAO,OAAwB;AACtC,MAAI,OAAO,UAAU,SAAU,QAAO,KAAK,UAAU,KAAK;AAC1D,MAAI,UAAU,QAAQ,UAAU,OAAW,QAAO,OAAO,KAAK;AAC9D,MAAI,OAAO,UAAU,UAAU;AAC7B,QAAI;AACF,aAAO,KAAK,UAAU,KAAK;AAAA,IAC7B,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO,OAAO,KAAK;AACrB;;;AC7TO,SAAS,aAAa,QAAwC;AACnE,SAAO;AACT;","names":["signal","self","classes","instance","el","tag","pattern","host","valid","dirty","resource"]}
1
+ {"version":3,"sources":["../src/version.ts","../../state/src/signal.ts","../../state/src/store.ts","../../state/src/resource.ts","../../state/src/mutation.ts","../../state/src/client.ts","../../state/src/auth.ts","../../core/src/a11y-ids.ts","../../core/src/identity.ts","../../core/src/lifecycle.ts","../../core/src/environment.ts","../../core/src/diagnostics.ts","../../core/src/application.ts","../../core/src/node.ts","../../core/src/observability.ts","../../graph/src/graph-node.ts","../../graph/src/graph.ts","../../dsl/src/transition.ts","../../dsl/src/head.ts","../../dsl/src/builders.ts","../../dsl/src/component.ts","../../dsl/src/dsl.ts","../../compiler/src/validation/validator.ts","../../compiler/src/transform/transform.ts","../../compiler/src/compile.ts","../../runtime/src/node-instance.ts","../../scheduler/src/scheduler.ts","../../runtime/src/runtime.ts","../../events/src/event-types.ts","../../events/src/event-bus.ts","../../events/src/dom-bridge.ts","../../dom/src/browser-adapter.ts","../../dom/src/server-node.ts","../../dom/src/server-adapter.ts","../../dom/src/focus.ts","../../dom/src/live-region.ts","../../renderer/src/render-context.ts","../../renderer/src/node-instance.ts","../../renderer/src/attributes.ts","../../renderer/src/events.ts","../../renderer/src/tag-map.ts","../../renderer/src/patch.ts","../../renderer/src/reconciliation.ts","../../renderer/src/transition.ts","../../renderer/src/head.ts","../../renderer/src/mount.ts","../../renderer/src/hydration-diagnostics.ts","../../renderer/src/hydrate.ts","../../renderer/src/render-handle.ts","../../renderer/src/renderer.ts","../../renderer/src/dehydrate.ts","../../compiler/src/analysis/analyze.ts","../../compiler/src/analysis/inspect.ts","../../renderer/src/static-ssr-plan.ts","../../renderer/src/ssr.ts","../../router/src/matching.ts","../../router/src/history.ts","../../router/src/router.ts","../../router/src/mount-router.ts","../../forms/src/validators.ts","../../forms/src/form.ts","../../context/src/context.ts","../../i18n/src/i18n.ts","../../devtools/src/inspector.ts","../../devtools/src/application.ts","../../devtools/src/diagnostics.ts","../../devtools/src/inspect-reactive.ts","../../devtools/src/panels.ts","../../devtools/src/view.ts","../../devtools/src/devtools-report.ts","../src/config.ts"],"sourcesContent":["/**\n * The single authoritative StreetUI framework version.\n *\n * This constant is the one source of truth for the version of the shipped\n * `streetui` package. It is kept in lock-step with this package's\n * `package.json` `version` field and with the bundled CLI's reported version\n * (`streetui --version`) — the consolidated test-suite pins all three to the\n * same coordinated release so they can never silently drift apart.\n */\nexport const VERSION = '2.1.0';\n","/**\n * StreetUI reactive signals — framework-owned reactivity, no external libraries.\n *\n * Architecture:\n * Signal<T> — writable, holds a value, notifies on change\n * DerivedSignal<T> — read-only, lazily computed from other signals\n * effect() — side-effect that re-runs when dependencies change\n * batch() — run multiple updates before notifying\n */\n\nexport type Subscriber<T> = (value: T) => void;\nexport type Unsubscribe = () => void;\n\n// ── Tracking ──────────────────────────────────────────────────────────────────\n\n/**\n * Any reactive source that can have downstream consumers attached.\n * Both Signal and DerivedSignal implement this.\n */\nexport interface ReactiveSource<T> {\n get(): T;\n peek(): T;\n subscribe(fn: Subscriber<T>): Unsubscribe;\n /** Internal: remove a downstream consumer. */\n _removeConsumer(consumer: ReactiveConsumer): void;\n}\n\n/**\n * A downstream consumer (DerivedSignal or Effect) that can be invalidated\n * and can register itself as depending on a source.\n */\nexport interface ReactiveConsumer {\n _invalidate(): void;\n /** Internal: called by a source to register a dependency. */\n _addSource(src: ReactiveSource<unknown>): void;\n}\n\n/** The active consumer being tracked during a computation. */\nlet _activeConsumer: ReactiveConsumer | null = null;\n\nfunction withConsumer<T>(consumer: ReactiveConsumer, fn: () => T): T {\n const prev = _activeConsumer;\n _activeConsumer = consumer;\n try {\n return fn();\n } finally {\n _activeConsumer = prev;\n }\n}\n\n// ── Batch state (must be before Signal class so .set() can reference it) ──────\n\n/** Depth counter — batches nest; only the outermost flush propagates. */\nlet _batchDepth = 0;\n\ninterface PendingFlush {\n signal: Signal<unknown>;\n value: unknown;\n}\n\n/**\n * Keyed by signal identity — last-write-wins for each signal within a batch.\n * An ordered Map preserves first-seen insertion order for stable flush sequence.\n */\nconst _pendingFlushes = new Map<Signal<unknown>, PendingFlush>();\n\nfunction _enqueueBatchFlush(sig: Signal<unknown>, value: unknown): void {\n _pendingFlushes.set(sig, { signal: sig, value });\n}\n\nfunction _drainBatch(): void {\n const flushes = [..._pendingFlushes.values()];\n _pendingFlushes.clear();\n for (const { signal: sig, value } of flushes) {\n sig._flushBatch(value);\n }\n}\n\n// ── Signal ────────────────────────────────────────────────────────────────────\n\nexport interface ReadonlySignal<T> {\n get(): T;\n peek(): T;\n subscribe(fn: Subscriber<T>): Unsubscribe;\n}\n\nexport class Signal<T> implements ReactiveSource<T>, ReadonlySignal<T> {\n protected _value: T;\n private readonly _subscribers: Set<Subscriber<T>> = new Set();\n private readonly _consumers: Set<ReactiveConsumer> = new Set();\n\n constructor(initial: T) {\n this._value = initial;\n }\n\n get(): T {\n if (_activeConsumer !== null) {\n this._consumers.add(_activeConsumer);\n _activeConsumer._addSource(this as ReactiveSource<unknown>);\n }\n return this._value;\n }\n\n peek(): T {\n return this._value;\n }\n\n set(value: T): void {\n if (Object.is(this._value, value)) return;\n this._value = value;\n if (_batchDepth > 0) {\n // Defer notification until the batch flushes.\n // The stored value is always the latest (last-write-wins for same signal).\n _enqueueBatchFlush(this as unknown as Signal<unknown>, value);\n } else {\n this._flush(value);\n }\n }\n\n update(fn: (current: T) => T): void {\n this.set(fn(this._value));\n }\n\n subscribe(fn: Subscriber<T>): Unsubscribe {\n this._subscribers.add(fn);\n return () => { this._subscribers.delete(fn); };\n }\n\n _removeConsumer(consumer: ReactiveConsumer): void {\n this._consumers.delete(consumer);\n }\n\n /**\n * Called by the batch machinery after the batch has completed.\n * Notifies subscribers with the final coalesced value.\n */\n _flushBatch(value: unknown): void {\n this._flush(value as T);\n }\n\n private _flush(value: T): void {\n for (const sub of [...this._subscribers]) sub(value);\n for (const consumer of [...this._consumers]) consumer._invalidate();\n }\n\n /**\n * @internal DevTools inspection only. The number of live observers\n * (direct subscribers plus derived/effect consumers). Read-only; never\n * mutates reactive state.\n */\n _observerCount(): number {\n return this._subscribers.size + this._consumers.size;\n }\n}\n\n// ── DerivedSignal ─────────────────────────────────────────────────────────────\n\nexport class DerivedSignal<T> implements ReactiveSource<T>, ReactiveConsumer, ReadonlySignal<T> {\n private _value: T | undefined = undefined;\n private _dirty = true;\n private _disposed = false;\n private readonly _fn: () => T;\n private readonly _subscribers: Set<Subscriber<T>> = new Set();\n /** All upstream sources this derived currently reads from. */\n private readonly _sources: Set<ReactiveSource<unknown>> = new Set();\n /** Downstream consumers that depend on this derived. */\n private readonly _consumers: Set<ReactiveConsumer> = new Set();\n\n constructor(fn: () => T) {\n this._fn = fn;\n }\n\n get(): T {\n // Register this derived with the outer consumer if any\n if (_activeConsumer !== null) {\n this._consumers.add(_activeConsumer);\n _activeConsumer._addSource(this as ReactiveSource<unknown>);\n }\n if (this._dirty) this._recompute();\n return this._value as T;\n }\n\n peek(): T {\n if (this._dirty) this._recompute();\n return this._value as T;\n }\n\n subscribe(fn: Subscriber<T>): Unsubscribe {\n // Eagerly compute so sources track this derived as a consumer\n if (this._dirty) this._recompute();\n this._subscribers.add(fn);\n return () => { this._subscribers.delete(fn); };\n }\n\n _addSource(src: ReactiveSource<unknown>): void {\n this._sources.add(src);\n }\n\n _removeConsumer(consumer: ReactiveConsumer): void {\n this._consumers.delete(consumer);\n }\n\n _invalidate(): void {\n if (this._disposed) return;\n this._dirty = true;\n const newVal = this.peek(); // recompute\n for (const sub of [...this._subscribers]) sub(newVal);\n for (const consumer of [...this._consumers]) consumer._invalidate();\n }\n\n private _recompute(): void {\n // Detach from all current sources before re-tracking\n for (const src of this._sources) src._removeConsumer(this);\n this._sources.clear();\n\n this._value = withConsumer(this, this._fn);\n this._dirty = false;\n }\n\n dispose(): void {\n this._disposed = true;\n for (const src of this._sources) src._removeConsumer(this);\n this._sources.clear();\n this._subscribers.clear();\n this._consumers.clear();\n }\n\n /**\n * @internal DevTools inspection only. Live observers (subscribers plus\n * downstream consumers). Read-only.\n */\n _observerCount(): number {\n return this._subscribers.size + this._consumers.size;\n }\n}\n\n// ── effect ────────────────────────────────────────────────────────────────────\n\nclass Effect implements ReactiveConsumer {\n private readonly _fn: () => void | (() => void);\n private _cleanup: (() => void) | undefined = undefined;\n private _disposed = false;\n private readonly _sources: Set<ReactiveSource<unknown>> = new Set();\n\n constructor(fn: () => void | (() => void)) {\n this._fn = fn;\n this._run();\n }\n\n _addSource(src: ReactiveSource<unknown>): void {\n this._sources.add(src);\n }\n\n _invalidate(): void {\n if (this._disposed) return;\n this._run();\n }\n\n private _run(): void {\n // Detach from all current sources before re-tracking\n for (const src of this._sources) src._removeConsumer(this);\n this._sources.clear();\n\n if (typeof this._cleanup === 'function') this._cleanup();\n const result = withConsumer(this, this._fn);\n this._cleanup = typeof result === 'function' ? result : undefined;\n }\n\n dispose(): void {\n this._disposed = true;\n for (const src of this._sources) src._removeConsumer(this);\n this._sources.clear();\n if (typeof this._cleanup === 'function') this._cleanup();\n this._cleanup = undefined;\n }\n}\n\n// ── Public API ─────────────────────────────────────────────────────────────────\n\nexport function signal<T>(initial: T): Signal<T> {\n return new Signal(initial);\n}\n\nexport function derived<T>(fn: () => T): DerivedSignal<T> {\n return new DerivedSignal(fn);\n}\n\nexport function effect(fn: () => void | (() => void)): Unsubscribe {\n const e = new Effect(fn);\n return () => e.dispose();\n}\n\n/**\n * Run multiple signal updates as an atomic batch.\n *\n * Within the callback, calls to signal.set() are deferred — each signal\n * accumulates its latest value. When the outermost batch() returns,\n * each modified signal fires its subscribers exactly once with the final\n * value. Nested batch() calls are supported; the flush only runs when the\n * outermost batch exits.\n *\n * Example:\n * batch(() => {\n * count.set(1);\n * count.set(2);\n * count.set(3);\n * });\n * // subscribers see count = 3 exactly once\n */\nexport function batch(fn: () => void): void {\n _batchDepth++;\n try {\n fn();\n } finally {\n _batchDepth--;\n if (_batchDepth === 0) {\n _drainBatch();\n }\n }\n}\n\n/** True when inside a batch() call. Useful for advanced scheduling integration. */\nexport function isBatching(): boolean {\n return _batchDepth > 0;\n}\n\n// ── Inspection (read-only, DevTools-facing) ─────────────────────────────────\n\n/** Whether a signal is writable (`signal()`) or computed (`derived()`). */\nexport type SignalKind = 'writable' | 'derived';\n\n/** Classify a reactive value as writable or derived. */\nexport function signalKind(source: ReadonlySignal<unknown>): SignalKind {\n return source instanceof DerivedSignal ? 'derived' : 'writable';\n}\n\n/**\n * The number of live observers on a signal — direct subscribers plus derived\n * or effect consumers — or `undefined` if the source does not expose the count.\n * Read-only; safe for DevTools. Never mutates reactive state.\n */\nexport function observerCount(source: ReadonlySignal<unknown>): number | undefined {\n const maybe = source as { _observerCount?: () => number };\n return typeof maybe._observerCount === 'function' ? maybe._observerCount() : undefined;\n}\n","/**\n * A simple reactive store built on top of signals.\n * Useful for structured state with multiple fields.\n */\n\nimport { Signal, signal, type Subscriber, type Unsubscribe } from './signal.js';\n\nexport type StoreState = Record<string, unknown>;\n\nexport class Store<T extends StoreState> {\n private readonly _signals: Record<string, Signal<unknown>>;\n\n constructor(initial: T) {\n const signals: Record<string, Signal<unknown>> = {};\n for (const key in initial) {\n if (Object.prototype.hasOwnProperty.call(initial, key)) {\n signals[key] = signal(initial[key] as unknown);\n }\n }\n this._signals = signals;\n }\n\n get<K extends keyof T>(key: K): T[K] {\n const s = this._signals[key as string];\n if (s === undefined) {\n throw new Error(`Store: unknown key \"${String(key)}\"`);\n }\n return s.get() as T[K];\n }\n\n set<K extends keyof T>(key: K, value: T[K]): void {\n const s = this._signals[key as string];\n if (s === undefined) {\n throw new Error(`Store: unknown key \"${String(key)}\"`);\n }\n s.set(value as unknown);\n }\n\n signal<K extends keyof T>(key: K): Signal<T[K]> {\n const s = this._signals[key as string];\n if (s === undefined) {\n throw new Error(`Store: unknown key \"${String(key)}\"`);\n }\n return s as unknown as Signal<T[K]>;\n }\n\n subscribe<K extends keyof T>(key: K, fn: Subscriber<T[K]>): Unsubscribe {\n return this.signal(key).subscribe(fn);\n }\n\n getSnapshot(): T {\n const snap = {} as T;\n for (const key in this._signals) {\n if (Object.prototype.hasOwnProperty.call(this._signals, key)) {\n (snap as Record<string, unknown>)[key] = this._signals[key]?.peek();\n }\n }\n return snap;\n }\n}\n\nexport function createStore<T extends StoreState>(initial: T): Store<T> {\n return new Store(initial);\n}\n","/**\n * StreetUI async resources — framework-native asynchronous data.\n *\n * A `resource` wraps a Promise-returning loader and exposes its lifecycle as\n * ordinary StreetUI signals (status / data / error), so it composes with\n * `derived`, `effect`, `when()`, `listOf` and the renderer with no second\n * reactive system.\n *\n * State machine:\n *\n * idle ──(load)──▶ loading ──(resolve)──▶ success\n * │\n * └────(reject)──────▶ error\n *\n * Refetch keeps the previously-loaded `data` visible while `status` is\n * `'loading'` again (see `isRefetching`) — there is no separate `'refetching'`\n * status; it is expressed through `status === 'loading'` with `data` still set.\n *\n * The resource is transport-agnostic: the loader is any function returning a\n * value or a Promise. When it accepts the provided `AbortSignal`, in-flight\n * work is cancelled on `dispose()` or when a newer request supersedes it.\n */\n\nimport { signal, derived, batch, type ReadonlySignal, type Unsubscribe } from './signal.js';\n\nexport type ResourceStatus = 'idle' | 'loading' | 'success' | 'error';\n\n/** Context handed to the loader; carries an AbortSignal for cancellation. */\nexport interface ResourceLoaderContext {\n readonly signal: AbortSignal;\n}\n\n/** Any value-or-Promise producing function. Receives an abort-aware context. */\nexport type ResourceLoader<T> = (ctx: ResourceLoaderContext) => Promise<T> | T;\n\nexport interface ResourceOptions<T = unknown> {\n /** Load immediately on creation. Defaults to `true`. When `false`, stays `idle` until `refetch()`. */\n readonly immediate?: boolean;\n /**\n * Explicit reactive dependencies. When any listed signal changes, the\n * resource refetches. Dependencies are explicit (not auto-tracked from the\n * loader body) so there is no risk of an accidental infinite refetch loop.\n */\n readonly watch?: ReadonlyArray<ReadonlySignal<unknown>>;\n /**\n * Optional teardown registrar (e.g. a route's `ctx.onCleanup`). When given,\n * the resource registers its own `dispose` so it is cleaned up automatically\n * when its owner is removed.\n */\n readonly onCleanup?: (fn: () => void) => void;\n /**\n * Server-provided initial value for hydration. When present the resource\n * starts in `'success'` with this data already visible, and the initial\n * auto-load is skipped (so the client does not refetch data the server\n * already resolved). This is the client half of SSR resource transfer; the\n * server side awaits `refetch()` before serializing. Set `immediate: true`\n * explicitly to force a client refetch anyway.\n */\n readonly initialData?: T;\n /** Server-provided initial error for hydration (mirrors `initialData`). */\n readonly initialError?: unknown;\n /**\n * Explicit initial status override. Rarely needed — inferred as `'success'`\n * from `initialData` or `'error'` from `initialError`.\n */\n readonly initialStatus?: ResourceStatus;\n}\n\nexport interface Resource<T> {\n /** Reactive lifecycle status. */\n readonly status: ReadonlySignal<ResourceStatus>;\n /** The last successfully-loaded value, or `undefined` before first success. */\n readonly data: ReadonlySignal<T | undefined>;\n /** The most recent error, or `undefined` when there is none. Typed `unknown` — never `any`. */\n readonly error: ReadonlySignal<unknown>;\n /** Convenience: `status === 'loading'`. */\n readonly loading: ReadonlySignal<boolean>;\n /** Convenience: loading while previously-loaded data is still present (a refetch). */\n readonly isRefetching: ReadonlySignal<boolean>;\n /** Trigger a new request. Resolves when the request settles (or is superseded). */\n refetch(): Promise<void>;\n /** Cancel in-flight work, drop watchers, and ignore any late results. Idempotent. */\n dispose(): void;\n}\n\n/** True for an abort we initiated (so it is not surfaced as a real error). */\nfunction isAbortError(err: unknown): boolean {\n return (\n err instanceof Error && err.name === 'AbortError'\n ) || (\n typeof DOMException !== 'undefined' && err instanceof DOMException && err.name === 'AbortError'\n );\n}\n\nexport function resource<T>(loader: ResourceLoader<T>, options: ResourceOptions<T> = {}): Resource<T> {\n // Seed hydrated initial state (SSR transfer). `initialStatus` wins if given,\n // otherwise infer success/error from the provided value.\n const hasInitial =\n options.initialData !== undefined ||\n options.initialError !== undefined ||\n options.initialStatus !== undefined;\n\n const seededStatus: ResourceStatus =\n options.initialStatus ??\n (options.initialData !== undefined\n ? 'success'\n : options.initialError !== undefined\n ? 'error'\n : 'idle');\n\n const status = signal<ResourceStatus>(seededStatus);\n const data = signal<T | undefined>(options.initialData);\n const error = signal<unknown>(options.initialError);\n\n const loading = derived<boolean>(() => status.get() === 'loading');\n const isRefetching = derived<boolean>(() => status.get() === 'loading' && data.get() !== undefined);\n\n let disposed = false;\n /** Monotonic request id — only the newest request may write state (race guard). */\n let runId = 0;\n let controller: AbortController | null = null;\n\n const load = async (): Promise<void> => {\n if (disposed) return;\n\n // Supersede any in-flight request: abort it and bump the run id so its\n // eventual resolution is ignored.\n controller?.abort();\n const myRun = ++runId;\n const myController = new AbortController();\n controller = myController;\n\n // Enter loading. Preserve `data` (so a refetch keeps showing the old value)\n // and clear any previous error.\n batch(() => {\n error.set(undefined);\n status.set('loading');\n });\n\n try {\n const result = await loader({ signal: myController.signal });\n // Ignore stale or cancelled resolutions.\n if (disposed || myRun !== runId) return;\n batch(() => {\n data.set(result);\n error.set(undefined);\n status.set('success');\n });\n } catch (err) {\n if (disposed || myRun !== runId) return;\n // A self-initiated abort is not a user-visible error.\n if (isAbortError(err)) return;\n batch(() => {\n error.set(err);\n status.set('error');\n });\n }\n };\n\n const refetch = (): Promise<void> => load();\n\n // Explicit reactive dependencies: refetch when any watched signal changes.\n const watchUnsubs: Unsubscribe[] = [];\n if (options.watch !== undefined) {\n for (const dep of options.watch) {\n watchUnsubs.push(\n dep.subscribe(() => {\n if (!disposed) void load();\n }),\n );\n }\n }\n\n const dispose = (): void => {\n if (disposed) return;\n disposed = true;\n controller?.abort();\n controller = null;\n for (const unsub of watchUnsubs) unsub();\n watchUnsubs.length = 0;\n };\n\n if (options.onCleanup !== undefined) {\n options.onCleanup(dispose);\n }\n\n // Auto-load on creation unless disabled. When hydrated initial state is\n // present we skip the initial load by default (the server already resolved\n // it); an explicit `immediate: true` still forces a refetch.\n if (options.immediate === true || (options.immediate !== false && !hasInitial)) {\n void load();\n }\n\n return {\n status,\n data,\n error,\n loading,\n isRefetching,\n refetch,\n dispose,\n };\n}\n","/**\n * StreetUI mutations — framework-native asynchronous *writes*.\n *\n * A `resource` models a read: a loader that runs on creation / on demand and\n * whose value the UI observes. A `mutation` is its write-side counterpart: an\n * explicit, argument-taking async action (create / update / delete, a form\n * submit, a \"mark as done\" click) whose lifecycle is exposed as ordinary\n * StreetUI signals so it composes with `derived`, `when()`, and the renderer\n * with NO second reactive system.\n *\n * State machine (mirrors `resource`, but only ever advances on an explicit\n * `mutate()` — a mutation never runs on its own):\n *\n * idle ──(mutate)──▶ loading ──(resolve)──▶ success\n * │\n * └────(reject)──────▶ error\n *\n * There is deliberately NO global cache and NO automatic invalidation registry\n * (that would be a second state system with its own lifetime and coherency\n * rules). Invalidation is explicit and local: pass an `onSuccess` that calls the\n * `refetch()` of whichever resources the write affected. This keeps data flow\n * one-directional and readable — the write says exactly what it invalidates.\n */\n\nimport { signal, derived, batch, type ReadonlySignal } from './signal.js';\nimport type { ResourceStatus } from './resource.js';\n\n/** A mutation shares the resource status vocabulary (idle/loading/success/error). */\nexport type MutationStatus = ResourceStatus;\n\n/** The async action a mutation runs. Receives the caller's argument. */\nexport type Mutator<TArgs, TResult> = (args: TArgs) => Promise<TResult> | TResult;\n\nexport interface MutationOptions<TArgs, TResult> {\n /**\n * Run after a successful mutation, before `mutate()`'s promise resolves. The\n * natural place to invalidate reads: call the affected resources' `refetch()`.\n * May be async; its completion is awaited so callers can rely on reads being\n * up to date once `mutate()` resolves.\n */\n readonly onSuccess?: (result: TResult, args: TArgs) => void | Promise<void>;\n /** Run after a failed mutation (the thrown value is passed through). */\n readonly onError?: (error: unknown, args: TArgs) => void | Promise<void>;\n /** Run after success OR error, once the lifecycle has settled. */\n readonly onSettled?: (args: TArgs) => void | Promise<void>;\n /**\n * Optional teardown registrar (e.g. a component's `ctx.onCleanup`). When\n * given, the mutation registers its own `dispose` so late results from an\n * in-flight `mutate()` are ignored once the owner is removed.\n */\n readonly onCleanup?: (fn: () => void) => void;\n}\n\nexport interface Mutation<TArgs, TResult> {\n /** Reactive lifecycle status. */\n readonly status: ReadonlySignal<MutationStatus>;\n /** The most recent successful result, or `undefined` before first success. */\n readonly data: ReadonlySignal<TResult | undefined>;\n /** The most recent error, or `undefined` when there is none. Typed `unknown`. */\n readonly error: ReadonlySignal<unknown>;\n /** Convenience: `status === 'loading'` (an in-flight write). */\n readonly pending: ReadonlySignal<boolean>;\n /**\n * Run the mutation. Resolves with the result on success. On failure the\n * rejection is surfaced through `error`/`status` AND re-thrown, so a caller\n * that wants to react imperatively can `try/catch`; a caller that only wants\n * the reactive state can ignore the returned promise. Superseded/disposed\n * runs never write state (race guard), matching `resource`.\n */\n mutate(args: TArgs): Promise<TResult>;\n /** Reset back to `idle` with no data/error. */\n reset(): void;\n /** Ignore any in-flight result and mark the mutation inert. Idempotent. */\n dispose(): void;\n}\n\n/**\n * Create a {@link Mutation}. The zero-argument form is written\n * `mutation<void, T>(() => …)` and invoked as `mutate(undefined)`.\n */\nexport function mutation<TArgs, TResult>(\n mutator: Mutator<TArgs, TResult>,\n options: MutationOptions<TArgs, TResult> = {},\n): Mutation<TArgs, TResult> {\n const status = signal<MutationStatus>('idle');\n const data = signal<TResult | undefined>(undefined);\n const error = signal<unknown>(undefined);\n const pending = derived<boolean>(() => status.get() === 'loading');\n\n let disposed = false;\n /** Monotonic run id — only the newest mutate() may write state. */\n let runId = 0;\n\n const mutate = async (args: TArgs): Promise<TResult> => {\n if (disposed) {\n // Inert: run the action for its side effect but never touch state.\n return (await mutator(args)) as TResult;\n }\n const myRun = ++runId;\n batch(() => {\n error.set(undefined);\n status.set('loading');\n });\n\n try {\n const result = await mutator(args);\n if (!disposed && myRun === runId) {\n batch(() => {\n data.set(result);\n error.set(undefined);\n status.set('success');\n });\n }\n // Side effects run only for the newest, still-live run.\n if (!disposed && myRun === runId) {\n await options.onSuccess?.(result, args);\n await options.onSettled?.(args);\n }\n return result;\n } catch (err) {\n if (!disposed && myRun === runId) {\n batch(() => {\n error.set(err);\n status.set('error');\n });\n await options.onError?.(err, args);\n await options.onSettled?.(args);\n }\n throw err;\n }\n };\n\n const reset = (): void => {\n batch(() => {\n status.set('idle');\n data.set(undefined);\n error.set(undefined);\n });\n };\n\n const dispose = (): void => {\n disposed = true;\n };\n\n if (options.onCleanup !== undefined) options.onCleanup(dispose);\n\n return { status, data, error, pending, mutate, reset, dispose };\n}\n","/**\n * Optional HTTP data client (2.0 §17) — the integration path between StreetUI's\n * transport-agnostic `resource`/`mutation` primitives and a real backend (a\n * StreetJS server, or any HTTP/JSON API).\n *\n * This is deliberately OPTIONAL and dependency-free: it imports nothing from\n * StreetJS (or any server framework), so StreetUI's core stays independent — an\n * app that never calls `createClient` never pays for it, and StreetUI does not\n * take on a backend dependency. It is a thin, honest convenience over the\n * standard `fetch`: URL joining, JSON encode/decode, header merging, abort\n * propagation, and a typed error. All state still flows through the existing\n * `resource`/`mutation` signals — there is no cache and no second data system.\n *\n * ```ts\n * const api = createClient({ baseUrl: '/api' });\n * const users = api.resource<User[]>('/users'); // a read\n * const create = api.mutation<NewUser, User>('POST', '/users', {\n * onSuccess: () => users.refetch(), // explicit invalidation\n * });\n * ```\n */\n\nimport { resource, type Resource, type ResourceOptions } from './resource.js';\nimport { mutation, type Mutation, type MutationOptions } from './mutation.js';\n\n/** A `fetch`-compatible function. Injectable for tests / non-browser runtimes. */\nexport type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;\n\nexport interface ClientConfig {\n /** Prefix joined to every request path (e.g. `/api` or `https://x/api`). */\n readonly baseUrl?: string;\n /** Headers merged into every request (per-request headers win). */\n readonly headers?: Readonly<Record<string, string>>;\n /**\n * The fetch implementation to use. Defaults to the global `fetch`. Injecting\n * one keeps the client testable and usable where no global fetch exists.\n */\n readonly fetch?: FetchLike;\n}\n\nexport type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n\nexport interface RequestConfig {\n /** Extra headers for this request (merged over the client's). */\n readonly headers?: Readonly<Record<string, string>>;\n /** Abort signal — pass a resource/mutation loader's `ctx.signal` for cancellation. */\n readonly signal?: AbortSignal;\n /** Query parameters appended to the URL. */\n readonly query?: Readonly<Record<string, string | number | boolean>>;\n}\n\n/**\n * A failed HTTP response (non-2xx). Carries the status and the parsed body when\n * one was returned. NOTE: the body may contain server-supplied detail; the §7\n * error reporter never enumerates an error's own-properties, so `HttpError.body`\n * never leaks into a diagnostics report unless an app deliberately reads it.\n */\nexport class HttpError extends Error {\n readonly status: number;\n readonly statusText: string;\n readonly url: string;\n readonly body: unknown;\n\n constructor(status: number, statusText: string, url: string, body: unknown) {\n super(`HTTP ${status} ${statusText} for ${url}`);\n this.name = 'HttpError';\n this.status = status;\n this.statusText = statusText;\n this.url = url;\n this.body = body;\n }\n}\n\nexport interface Client {\n /** Issue a request and return the parsed JSON body (throws `HttpError` on non-2xx). */\n request<T>(method: HttpMethod, path: string, body?: unknown, config?: RequestConfig): Promise<T>;\n get<T>(path: string, config?: RequestConfig): Promise<T>;\n post<T>(path: string, body?: unknown, config?: RequestConfig): Promise<T>;\n put<T>(path: string, body?: unknown, config?: RequestConfig): Promise<T>;\n patch<T>(path: string, body?: unknown, config?: RequestConfig): Promise<T>;\n del<T>(path: string, config?: RequestConfig): Promise<T>;\n /**\n * A GET-backed {@link Resource}. The loader forwards the resource's abort\n * signal, so `dispose()`/supersede cancels the request.\n */\n resource<T>(path: string, options?: ResourceOptions<T> & { readonly query?: RequestConfig['query'] }): Resource<T>;\n /**\n * A {@link Mutation} that issues `method path` with the mutate() argument as\n * the JSON body. Pair with `onSuccess` to refetch affected resources.\n */\n mutation<TArgs, TResult>(\n method: HttpMethod,\n path: string,\n options?: MutationOptions<TArgs, TResult>,\n ): Mutation<TArgs, TResult>;\n}\n\nfunction joinUrl(baseUrl: string | undefined, path: string): string {\n if (baseUrl === undefined || baseUrl === '') return path;\n const b = baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl;\n const p = path.startsWith('/') ? path : `/${path}`;\n return `${b}${p}`;\n}\n\nfunction withQuery(url: string, query: RequestConfig['query']): string {\n if (query === undefined) return url;\n const params = new URLSearchParams();\n for (const [k, v] of Object.entries(query)) params.set(k, String(v));\n const qs = params.toString();\n if (qs === '') return url;\n return url.includes('?') ? `${url}&${qs}` : `${url}?${qs}`;\n}\n\n/** Create an optional HTTP data client. Uses global `fetch` unless one is injected. */\nexport function createClient(config: ClientConfig = {}): Client {\n const doFetch: FetchLike =\n config.fetch ??\n ((input, init) => {\n if (typeof fetch === 'undefined') {\n throw new Error('createClient: no global fetch; pass { fetch } explicitly');\n }\n return fetch(input, init);\n });\n\n async function request<T>(\n method: HttpMethod,\n path: string,\n body?: unknown,\n reqConfig: RequestConfig = {},\n ): Promise<T> {\n const url = withQuery(joinUrl(config.baseUrl, path), reqConfig.query);\n const headers: Record<string, string> = { ...config.headers, ...reqConfig.headers };\n const init: RequestInit = { method, headers };\n if (reqConfig.signal !== undefined) init.signal = reqConfig.signal;\n if (body !== undefined) {\n if (headers['Content-Type'] === undefined) headers['Content-Type'] = 'application/json';\n init.body = JSON.stringify(body);\n }\n\n const response = await doFetch(url, init);\n const parsed = await parseBody(response);\n if (!response.ok) {\n throw new HttpError(response.status, response.statusText, url, parsed);\n }\n return parsed as T;\n }\n\n return {\n request,\n get: (path, c) => request('GET', path, undefined, c),\n post: (path, b, c) => request('POST', path, b, c),\n put: (path, b, c) => request('PUT', path, b, c),\n patch: (path, b, c) => request('PATCH', path, b, c),\n del: (path, c) => request('DELETE', path, undefined, c),\n resource: <T>(path: string, options: (ResourceOptions<T> & { query?: RequestConfig['query'] }) = {}) => {\n const { query, ...resourceOptions } = options;\n return resource<T>(\n (ctx) => request<T>('GET', path, undefined, { signal: ctx.signal, ...(query !== undefined ? { query } : {}) }),\n resourceOptions,\n );\n },\n mutation: <TArgs, TResult>(method: HttpMethod, path: string, options?: MutationOptions<TArgs, TResult>) =>\n mutation<TArgs, TResult>((args) => request<TResult>(method, path, args), options ?? {}),\n };\n}\n\n/** Parse a response as JSON when it declares JSON, else as text; empty → undefined. */\nasync function parseBody(response: Response): Promise<unknown> {\n const text = await response.text();\n if (text === '') return undefined;\n const type = response.headers.get('content-type') ?? '';\n if (type.includes('application/json')) {\n try {\n return JSON.parse(text);\n } catch {\n return text;\n }\n }\n return text;\n}\n","/**\n * Optional auth session primitive (2.0 §19) — reactive authentication state for\n * building sign-in UIs and protected routes, composed entirely from the existing\n * `resource` (the \"who am I\" read) and `mutation` (logout / refresh writes).\n *\n * There is no new auth framework here and no credential handling: the app\n * supplies a `loadUser` function (however it authenticates — a StreetJS session\n * cookie, a bearer token, anything) that returns the current user or `null`. The\n * primitive turns that into the states a UI switches on — `loading`,\n * `authenticated`, `unauthenticated`, `error` — plus `refresh()` and `logout()`.\n *\n * How the pieces the spec names fit together (all EXISTING seams, no new ones):\n * - loading / unauth / auth → switch UI with `when(session.authenticated, …)`\n * etc. (the renderer's existing conditional).\n * - refresh / logout → `session.refresh()` / `session.logout()`.\n * - protected route → in a route's setup, read `session.status`; when\n * `unauthenticated`, navigate to the login route (router). Throwing inside a\n * guarded builder is caught by `errorBoundary` for an error fallback. This\n * module stays router-agnostic so core has no router dependency — the app\n * wires the navigation, exactly as with any other signal.\n */\n\nimport { signal, derived, batch, type ReadonlySignal } from './signal.js';\nimport { resource, type ResourceLoaderContext } from './resource.js';\nimport { mutation } from './mutation.js';\n\n/** The four states an auth-aware UI switches on. */\nexport type AuthStatus = 'loading' | 'authenticated' | 'unauthenticated' | 'error';\n\n/** Load the current user, or `null`/`undefined` when nobody is signed in. */\nexport type LoadUser<TUser> = (ctx: ResourceLoaderContext) => Promise<TUser | null | undefined> | TUser | null | undefined;\n\nexport interface AuthSessionConfig<TUser> {\n /** Resolve the current user (or null when unauthenticated). Abort-aware. */\n readonly loadUser: LoadUser<TUser>;\n /**\n * Perform the server-side logout (clear the cookie/token). Optional — when\n * omitted, `logout()` just re-checks the session. After it resolves the\n * session refreshes, so `loadUser` should then return null.\n */\n readonly logout?: () => Promise<void> | void;\n /** Skip the initial load; stays `loading` until the first `refresh()`. */\n readonly immediate?: boolean;\n /** Teardown registrar (e.g. a component's `ctx.onCleanup`). */\n readonly onCleanup?: (fn: () => void) => void;\n}\n\nexport interface AuthSession<TUser> {\n /** The current coarse auth state. */\n readonly status: ReadonlySignal<AuthStatus>;\n /** The signed-in user, or `undefined` when not authenticated. */\n readonly user: ReadonlySignal<TUser | undefined>;\n /** The most recent load/logout error, or `undefined`. */\n readonly error: ReadonlySignal<unknown>;\n /** `status === 'authenticated'`. */\n readonly authenticated: ReadonlySignal<boolean>;\n /** `status === 'unauthenticated'`. */\n readonly unauthenticated: ReadonlySignal<boolean>;\n /** `status === 'loading'` (the initial who-am-I is still in flight). */\n readonly loading: ReadonlySignal<boolean>;\n /** True while a `logout()` is in flight. */\n readonly loggingOut: ReadonlySignal<boolean>;\n /** Re-run `loadUser` (e.g. after a token refresh or a focus regain). */\n refresh(): Promise<void>;\n /** Run the configured server logout, then refresh (→ unauthenticated). */\n logout(): Promise<void>;\n /** Cancel in-flight work and detach. Idempotent. */\n dispose(): void;\n}\n\n/**\n * Create an {@link AuthSession}. The session starts in `loading` and resolves to\n * `authenticated`/`unauthenticated` once `loadUser` settles (unless\n * `immediate: false`).\n */\nexport function createAuthSession<TUser>(config: AuthSessionConfig<TUser>): AuthSession<TUser> {\n const session = resource<TUser | null | undefined>(\n (ctx) => config.loadUser(ctx),\n {\n ...(config.immediate !== undefined ? { immediate: config.immediate } : {}),\n ...(config.onCleanup !== undefined ? { onCleanup: config.onCleanup } : {}),\n },\n );\n\n const status = derived<AuthStatus>(() => {\n const s = session.status.get();\n const d = session.data.get();\n if (s === 'error') return 'error';\n // Never loaded yet → loading. A refetch keeps the prior state visible (no\n // flicker): data is already set, so we fall through to auth/unauth below.\n if (s === 'idle' || (s === 'loading' && d === undefined)) return 'loading';\n return d === null || d === undefined ? 'unauthenticated' : 'authenticated';\n });\n\n const user = derived<TUser | undefined>(() => {\n const d = session.data.get();\n return d === null ? undefined : d;\n });\n\n const authenticated = derived<boolean>(() => status.get() === 'authenticated');\n const unauthenticated = derived<boolean>(() => status.get() === 'unauthenticated');\n const loading = derived<boolean>(() => status.get() === 'loading');\n\n const logoutMutation = mutation<void, void>(\n async () => {\n await config.logout?.();\n },\n { onSuccess: () => session.refetch() },\n );\n\n const dispose = (): void => {\n session.dispose();\n status.dispose();\n user.dispose();\n authenticated.dispose();\n unauthenticated.dispose();\n loading.dispose();\n logoutMutation.dispose();\n };\n\n return {\n status,\n user,\n error: session.error,\n authenticated,\n unauthenticated,\n loading,\n loggingOut: logoutMutation.pending,\n refresh: () => session.refetch(),\n logout: () => logoutMutation.mutate(undefined),\n dispose,\n };\n}\n","/**\n * Deterministic accessibility id helpers.\n *\n * Accessible markup often needs stable id relationships — a `<label for>` (or\n * `aria-labelledby`) pointing at an input, an `aria-describedby` pointing at a\n * hint/error, an `aria-labelledby` on a dialog pointing at its title. Those ids\n * must be IDENTICAL on the server and the client, otherwise a hydrated subtree\n * that re-renders (e.g. a toggled `when()` branch) would compute a different id\n * than the server emitted and break the association.\n *\n * These helpers derive ids purely from a caller-supplied stable base string\n * (typically a form field name or a dialog name). They use NO incrementing\n * counter and NO randomness, so `a11yIds('email')` yields the same ids in every\n * environment and on every call — which is exactly what SSR + hydration needs.\n */\n\nconst UNSAFE = /[^A-Za-z0-9_-]+/g;\n\n/** Normalise an arbitrary base into a token safe for use in an id/selector. */\nexport function toIdToken(base: string): string {\n const token = base.trim().replace(UNSAFE, '-').replace(/^-+|-+$/g, '');\n return token.length > 0 ? token : 'field';\n}\n\nexport interface A11yIds {\n /** The normalised base token. */\n readonly base: string;\n /** Id for the primary interactive element (e.g. the input). */\n readonly input: string;\n /** Id for a label element / labelling text (target of `aria-labelledby`). */\n readonly label: string;\n /** Id for descriptive/help text (target of `aria-describedby`). */\n readonly description: string;\n /** Id for an error message element. */\n readonly error: string;\n /** Id for a title element (e.g. a dialog title; target of `aria-labelledby`). */\n readonly title: string;\n /**\n * Id for a control that triggers a popup (button/summary). Pair with\n * `controls` on the popup it opens (`ariaControls: ids.controls`,\n * `ariaExpanded: open`).\n */\n readonly trigger: string;\n /** Id for a popup/region a `trigger` controls (target of `aria-controls`). */\n readonly controls: string;\n /** Id for a subtree owned out-of-DOM-order (target of `aria-owns`). */\n readonly owns: string;\n /** Derive an arbitrary suffixed id from the same base. */\n id(suffix: string): string;\n}\n\n/**\n * Build a set of deterministic, SSR-stable ids from a base string.\n *\n * @example\n * const ids = a11yIds('email');\n * // ids.input === 'email-input', ids.label === 'email-label', ...\n * input({ bind: value, id: ids.input, ariaLabelledBy: ids.label, ariaDescribedBy: ids.error });\n * text('Email', { id: ids.label });\n *\n * @example\n * // A menu button that controls its popup, wired by shared ids:\n * const m = a11yIds('actions');\n * button('Actions', { id: m.trigger, ariaControls: m.controls, ariaExpanded: open });\n * page.dropdown('menu', { open, id: m.controls }, (d) => { … });\n */\nexport function a11yIds(base: string): A11yIds {\n const token = toIdToken(base);\n return {\n base: token,\n input: `${token}-input`,\n label: `${token}-label`,\n description: `${token}-description`,\n error: `${token}-error`,\n title: `${token}-title`,\n trigger: `${token}-trigger`,\n controls: `${token}-controls`,\n owns: `${token}-owns`,\n id: (suffix: string) => `${token}-${toIdToken(suffix)}`,\n };\n}\n","/**\n * Node and application identity utilities.\n * Every node in the semantic graph has a stable, unique identity.\n */\n\nlet _counter = 0;\n\n/** Generate a framework-internal monotonic integer ID. */\nexport function nextId(): number {\n return ++_counter;\n}\n\n/** Reset the counter (test use only). */\nexport function resetIdCounter(): void {\n _counter = 0;\n}\n\n/** Opaque branded type for node IDs. */\nexport type NodeId = string & { readonly __brand: 'NodeId' };\n\n/** Create a NodeId from a string (must be unique at call site). */\nexport function createNodeId(value: string): NodeId {\n return value as NodeId;\n}\n\n/** Generate a fresh, unique NodeId. */\nexport function generateNodeId(prefix: string = 'node'): NodeId {\n return createNodeId(`${prefix}:${nextId()}`);\n}\n\n/** Parse the prefix from a NodeId. */\nexport function nodeIdPrefix(id: NodeId): string {\n const colon = id.indexOf(':');\n return colon === -1 ? id : id.slice(0, colon);\n}\n\n/** Branded type for application IDs. */\nexport type ApplicationId = string & { readonly __brand: 'ApplicationId' };\n\n/** Generate a fresh application ID. */\nexport function generateApplicationId(name: string): ApplicationId {\n return `app:${name}:${nextId()}` as ApplicationId;\n}\n","/**\n * Application and component lifecycle primitives.\n *\n * Lifecycle phases:\n * created → mounted → active ⇄ updating → unmounting → destroyed\n */\n\nexport type LifecyclePhase =\n | 'created'\n | 'mounted'\n | 'active'\n | 'updating'\n | 'unmounting'\n | 'destroyed';\n\nexport type LifecycleHook = () => void | Promise<void>;\n\nexport class Lifecycle {\n private _phase: LifecyclePhase = 'created';\n private readonly _hooks: Map<LifecyclePhase, LifecycleHook[]> = new Map();\n\n get phase(): LifecyclePhase {\n return this._phase;\n }\n\n get isMounted(): boolean {\n return this._phase === 'mounted' || this._phase === 'active' || this._phase === 'updating';\n }\n\n get isDestroyed(): boolean {\n return this._phase === 'destroyed';\n }\n\n on(phase: LifecyclePhase, hook: LifecycleHook): () => void {\n const hooks = this._hooks.get(phase) ?? [];\n hooks.push(hook);\n this._hooks.set(phase, hooks);\n return () => {\n const current = this._hooks.get(phase);\n if (current !== undefined) {\n const idx = current.indexOf(hook);\n if (idx !== -1) current.splice(idx, 1);\n }\n };\n }\n\n async transition(to: LifecyclePhase): Promise<void> {\n this._phase = to;\n const hooks = this._hooks.get(to) ?? [];\n for (const hook of hooks) {\n await hook();\n }\n }\n\n onMount(hook: LifecycleHook): () => void {\n return this.on('mounted', hook);\n }\n\n onUnmount(hook: LifecycleHook): () => void {\n return this.on('unmounting', hook);\n }\n\n onDestroy(hook: LifecycleHook): () => void {\n return this.on('destroyed', hook);\n }\n}\n\n/** A simple cleanup registry — collect teardown functions and run them all at once. */\nexport class CleanupRegistry {\n private readonly _fns: Array<() => void> = [];\n\n add(fn: () => void): void {\n this._fns.push(fn);\n }\n\n run(): void {\n for (const fn of this._fns) {\n try {\n fn();\n } catch {\n // Best-effort cleanup; don't let one failure block others\n }\n }\n this._fns.length = 0;\n }\n}\n","/**\n * Environment detection and capability flags.\n * The framework behaves slightly differently in browser vs. server vs. test.\n *\n * We use `typeof` checks throughout to remain safe across environments\n * without depending on @types/node.\n */\n\nexport type EnvironmentKind = 'browser' | 'server' | 'worker' | 'test' | 'unknown';\n\nexport interface EnvironmentCapabilities {\n readonly hasDom: boolean;\n readonly hasWindow: boolean;\n readonly hasDocument: boolean;\n readonly isSecureContext: boolean;\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\ndeclare const process: any;\n/* eslint-enable @typescript-eslint/no-explicit-any */\n\nfunction detectEnvironment(): EnvironmentKind {\n // Explicit test override via process.env\n try {\n if (\n typeof process !== 'undefined' &&\n process !== null &&\n typeof process === 'object' &&\n (process.env?.['NODE_ENV'] === 'test' || process.env?.['VITEST'] === 'true')\n ) {\n return 'test';\n }\n } catch {\n // process may not be defined in all environments\n }\n\n if (typeof window !== 'undefined' && typeof document !== 'undefined') {\n return 'browser';\n }\n\n if (\n typeof self !== 'undefined' &&\n typeof (self as unknown as Record<string, unknown>)['importScripts'] === 'function'\n ) {\n return 'worker';\n }\n\n try {\n if (typeof process !== 'undefined' && typeof process === 'object') {\n return 'server';\n }\n } catch {\n // ignore\n }\n\n return 'unknown';\n}\n\nfunction detectCapabilities(): EnvironmentCapabilities {\n return {\n hasDom: typeof document !== 'undefined',\n hasWindow: typeof window !== 'undefined',\n hasDocument: typeof document !== 'undefined',\n isSecureContext:\n typeof window !== 'undefined'\n ? ((window as unknown as Record<string, unknown>)['isSecureContext'] === true)\n : false,\n };\n}\n\nexport class Environment {\n readonly kind: EnvironmentKind;\n readonly capabilities: EnvironmentCapabilities;\n\n constructor(kind?: EnvironmentKind) {\n this.kind = kind ?? detectEnvironment();\n this.capabilities = detectCapabilities();\n }\n\n get isBrowser(): boolean {\n return this.kind === 'browser';\n }\n\n get isServer(): boolean {\n return this.kind === 'server';\n }\n\n get isTest(): boolean {\n return this.kind === 'test';\n }\n\n get isWorker(): boolean {\n return this.kind === 'worker';\n }\n}\n\n/** The singleton environment for this execution context. */\nexport const environment = new Environment();\n","/**\n * Framework diagnostics — structured errors, warnings, and hints\n * that flow through the compiler, validator, and runtime.\n */\n\nexport type DiagnosticSeverity = 'error' | 'warning' | 'info';\n\nexport interface DiagnosticLocation {\n readonly file?: string;\n readonly line?: number;\n readonly column?: number;\n readonly nodeId?: string;\n}\n\nexport interface Diagnostic {\n readonly severity: DiagnosticSeverity;\n readonly code: string;\n readonly message: string;\n readonly location: DiagnosticLocation | undefined;\n readonly cause: unknown;\n}\n\nexport class DiagnosticError extends Error {\n readonly diagnostics: readonly Diagnostic[];\n\n constructor(diagnostics: readonly Diagnostic[]) {\n const summary = diagnostics\n .filter(d => d.severity === 'error')\n .map(d => `[${d.code}] ${d.message}`)\n .join('\\n');\n super(`StreetUI diagnostics:\\n${summary}`);\n this.name = 'DiagnosticError';\n this.diagnostics = diagnostics;\n }\n}\n\nexport class DiagnosticCollector {\n private readonly _diagnostics: Diagnostic[] = [];\n\n get diagnostics(): readonly Diagnostic[] {\n return this._diagnostics;\n }\n\n get hasErrors(): boolean {\n return this._diagnostics.some(d => d.severity === 'error');\n }\n\n get hasWarnings(): boolean {\n return this._diagnostics.some(d => d.severity === 'warning');\n }\n\n error(\n code: string,\n message: string,\n location?: DiagnosticLocation,\n cause?: unknown,\n ): void {\n this._diagnostics.push({ severity: 'error', code, message, location: location ?? undefined, cause: cause ?? undefined });\n }\n\n warn(\n code: string,\n message: string,\n location?: DiagnosticLocation,\n ): void {\n this._diagnostics.push({ severity: 'warning', code, message, location: location ?? undefined, cause: undefined });\n }\n\n info(\n code: string,\n message: string,\n location?: DiagnosticLocation,\n ): void {\n this._diagnostics.push({ severity: 'info', code, message, location: location ?? undefined, cause: undefined });\n }\n\n merge(other: DiagnosticCollector): void {\n for (const d of other.diagnostics) {\n this._diagnostics.push(d);\n }\n }\n\n throwIfErrors(): void {\n if (this.hasErrors) {\n throw new DiagnosticError(this._diagnostics);\n }\n }\n\n clear(): void {\n this._diagnostics.length = 0;\n }\n}\n\n/** Format a single diagnostic as a human-readable string. */\nexport function formatDiagnostic(d: Diagnostic): string {\n const loc = d.location !== undefined\n ? ` (${[d.location.file, d.location.line, d.location.column]\n .filter(Boolean)\n .join(':')})`\n : '';\n return `[${d.severity.toUpperCase()}] ${d.code}: ${d.message}${loc}`;\n}\n","/**\n * Top-level Application primitive.\n * Owns lifecycle, identity, and the root of the application graph.\n */\n\nimport { type ApplicationId, generateApplicationId } from './identity.js';\nimport { Lifecycle, CleanupRegistry } from './lifecycle.js';\nimport { Environment, environment as defaultEnvironment } from './environment.js';\nimport { DiagnosticCollector } from './diagnostics.js';\n\nexport interface ApplicationOptions {\n readonly name: string;\n readonly version?: string;\n readonly environment?: Environment;\n}\n\nexport class Application {\n readonly id: ApplicationId;\n readonly name: string;\n readonly version: string;\n readonly lifecycle: Lifecycle;\n readonly cleanup: CleanupRegistry;\n readonly diagnostics: DiagnosticCollector;\n readonly environment: Environment;\n\n constructor(options: ApplicationOptions) {\n this.name = options.name;\n this.version = options.version ?? '0.0.1';\n this.id = generateApplicationId(options.name);\n this.lifecycle = new Lifecycle();\n this.cleanup = new CleanupRegistry();\n this.diagnostics = new DiagnosticCollector();\n this.environment = options.environment ?? defaultEnvironment;\n }\n\n async mount(): Promise<void> {\n if (this.lifecycle.phase !== 'created') {\n throw new Error(`Application \"${this.name}\" is already mounted (phase: ${this.lifecycle.phase})`);\n }\n await this.lifecycle.transition('mounted');\n await this.lifecycle.transition('active');\n }\n\n async unmount(): Promise<void> {\n if (!this.lifecycle.isMounted) {\n return;\n }\n await this.lifecycle.transition('unmounting');\n this.cleanup.run();\n await this.lifecycle.transition('destroyed');\n }\n\n onMount(fn: () => void | Promise<void>): void {\n this.lifecycle.onMount(fn);\n }\n\n onUnmount(fn: () => void | Promise<void>): void {\n this.lifecycle.onUnmount(fn);\n }\n}\n\n/** Factory convenience wrapper. */\nexport function createApplication(options: ApplicationOptions): Application {\n return new Application(options);\n}\n","/**\n * Framework node primitives — the base abstraction for every node\n * in the Semantic Application Graph.\n */\n\nimport { type NodeId, generateNodeId } from './identity.js';\n\nexport type SemanticNodeType =\n | 'application'\n | 'page'\n | 'section'\n | 'container'\n | 'heading'\n | 'text'\n | 'button'\n | 'input'\n | 'form'\n | 'list'\n | 'list-item'\n | 'image'\n | 'link'\n | 'component'\n | 'slot'\n | 'fragment'\n | 'reactive-list'\n | 'conditional'\n | 'portal'\n | 'head';\n\nexport interface NodeMetadata {\n readonly createdAt: number;\n readonly [key: string]: unknown;\n}\n\nexport abstract class BaseNode {\n readonly id: NodeId;\n readonly type: SemanticNodeType;\n readonly metadata: NodeMetadata;\n\n constructor(type: SemanticNodeType, id?: NodeId) {\n this.type = type;\n this.id = id ?? generateNodeId(type);\n this.metadata = { createdAt: Date.now() };\n }\n\n abstract clone(): BaseNode;\n}\n","/**\n * Observability boundary — a tiny, optional logging seam plus contextual\n * framework errors.\n *\n * StreetUI never ships a telemetry service, never sends anything over the\n * network, and never logs on its own by default. Instead an application MAY\n * hand the framework a `DiagnosticSink` — any object with the log methods it\n * cares about — and the framework will route the diagnostics it already\n * produces (runtime errors, resource failures, hydration mismatches, router\n * transitions) to it. With no sink attached there is no logging and no cost.\n *\n * This is deliberately smaller than a logging library: it duplicates neither\n * `console` nor any structured-diagnostic type. It is a boundary, not a logger.\n */\n\n/**\n * Where a framework diagnostic originated. Every field is optional so a caller\n * supplies only what is meaningful for the situation. Values are intended to be\n * non-sensitive identifiers — never tokens, secrets, cookies, or form values.\n */\nexport interface DiagnosticContext {\n /** The package that produced the diagnostic, e.g. `@streetui/renderer`. */\n readonly package?: string;\n /** The operation underway, e.g. `hydrate`, `compile`, `navigate`. */\n readonly operation?: string;\n /** The graph node id involved, when applicable. */\n readonly nodeId?: string;\n /** The route path involved, when applicable. */\n readonly route?: string;\n /** A resource identifier involved, when applicable. */\n readonly resource?: string;\n /**\n * The component name involved (from a `component()` definition's `name`), when\n * the diagnostic arises inside a component. A stable identifier, never a value.\n */\n readonly component?: string;\n /**\n * A signal identifier involved (e.g. a named/derived signal's debug name),\n * when applicable. This is the signal's *identity*, never its current value —\n * signal contents may be user data and are never placed in a diagnostic.\n */\n readonly signal?: string;\n /**\n * Where in a node's lifecycle the diagnostic arose: `render` (building the\n * subtree), `effect` (a reactive effect), `setup` (a component's setup),\n * `loader` (a resource loader), `event` (a DOM handler), or `hydrate`.\n */\n readonly phase?: 'render' | 'effect' | 'setup' | 'loader' | 'event' | 'hydrate';\n /**\n * A non-sensitive DOM association for where the error surfaced, e.g.\n * `div#app` or `button.primary`. Callers must pass only structural\n * identifiers (tag / id / class) — never `textContent`, attribute *values*,\n * or anything that could carry user data.\n */\n readonly element?: string;\n}\n\n/**\n * The application-provided logging seam. Every method is optional; the\n * framework calls only the ones present. Implementations must not throw.\n */\nexport interface DiagnosticSink {\n debug?(message: string, context?: DiagnosticContext): void;\n info?(message: string, context?: DiagnosticContext): void;\n warn?(message: string, context?: DiagnosticContext): void;\n error?(message: string, context?: DiagnosticContext): void;\n}\n\n/** Format a context object as a compact ` [k=v, …]` suffix (empty when bare). */\nexport function formatDiagnosticContext(context?: DiagnosticContext): string {\n if (context === undefined) return '';\n const parts: string[] = [];\n if (context.package !== undefined) parts.push(`package=${context.package}`);\n if (context.operation !== undefined) parts.push(`operation=${context.operation}`);\n if (context.component !== undefined) parts.push(`component=${context.component}`);\n if (context.phase !== undefined) parts.push(`phase=${context.phase}`);\n if (context.nodeId !== undefined) parts.push(`node=${context.nodeId}`);\n if (context.element !== undefined) parts.push(`element=${context.element}`);\n if (context.route !== undefined) parts.push(`route=${context.route}`);\n if (context.resource !== undefined) parts.push(`resource=${context.resource}`);\n if (context.signal !== undefined) parts.push(`signal=${context.signal}`);\n return parts.length > 0 ? ` [${parts.join(', ')}]` : '';\n}\n\n/**\n * A framework error whose message carries structured, non-sensitive context so\n * a developer immediately sees which package/operation/node was involved. The\n * message never embeds a stack or environment values; production stack\n * disclosure decisions stay with the server layer.\n */\nexport class StreetFrameworkError extends Error {\n readonly context: DiagnosticContext | undefined;\n\n constructor(message: string, context?: DiagnosticContext) {\n super(`${message}${formatDiagnosticContext(context)}`);\n this.name = 'StreetFrameworkError';\n this.context = context ?? undefined;\n }\n}\n\n/** Build a `StreetFrameworkError` with the given context. */\nexport function frameworkError(\n message: string,\n context?: DiagnosticContext,\n): StreetFrameworkError {\n return new StreetFrameworkError(message, context);\n}\n\n/**\n * Route a diagnostic to a sink if it implements the matching level. Safe to\n * call with `undefined` — it simply does nothing, which is the default (no\n * logging) posture. Never throws even if the sink method does.\n */\nexport function reportDiagnostic(\n sink: DiagnosticSink | undefined,\n level: 'debug' | 'info' | 'warn' | 'error',\n message: string,\n context?: DiagnosticContext,\n): void {\n if (sink === undefined) return;\n const fn = sink[level];\n if (typeof fn !== 'function') return;\n try {\n fn.call(sink, message, context);\n } catch {\n // A misbehaving sink must never break the framework.\n }\n}\n\n/** A sink that forwards to a `console`-like object, one call per level. */\nexport function consoleDiagnosticSink(\n logger: Partial<Record<'debug' | 'info' | 'warn' | 'error', (msg: string) => void>> = console,\n): DiagnosticSink {\n return {\n debug: (m, c) => logger.debug?.(`${m}${formatDiagnosticContext(c)}`),\n info: (m, c) => logger.info?.(`${m}${formatDiagnosticContext(c)}`),\n warn: (m, c) => logger.warn?.(`${m}${formatDiagnosticContext(c)}`),\n error: (m, c) => logger.error?.(`${m}${formatDiagnosticContext(c)}`),\n };\n}\n\n// ── Production error diagnostics (2.0 §7) ─────────────────────────────────────\n\n/**\n * Options controlling how much of an error is disclosed in a report.\n *\n * Everything defaults to the SAFE (production) posture: no stack, no cause\n * chain. A stack trace can embed absolute file paths and, in some runtimes,\n * source fragments, so it is opt-in and belongs to development / trusted server\n * logging — never to a report that might reach a browser or a third party.\n */\nexport interface ErrorReportOptions {\n /** Include `error.stack` in the report. Default `false` (production-safe). */\n readonly includeStack?: boolean;\n /**\n * Follow and describe `error.cause` (recursively, up to a small depth) when\n * present. Default `false`. The cause is described with the SAME redaction\n * rules — only its name/message/(optional)stack, never arbitrary properties.\n */\n readonly includeCause?: boolean;\n}\n\n/**\n * A production-safe, serializable description of an error plus the framework\n * context in which it surfaced. This is what §7 asks a diagnostics sink to\n * receive: enough to locate the failure (component / route / resource / signal /\n * phase / DOM association via {@link DiagnosticContext}) WITHOUT any sensitive\n * data. It deliberately carries ONLY the error's class name and message (both\n * author-controlled), never enumerated own-properties (which frequently hold\n * request bodies, tokens, or user records), and the stack only when explicitly\n * opted in.\n */\nexport interface ErrorReport {\n /** The error's constructor name, e.g. `TypeError` (`Error` when unknown). */\n readonly name: string;\n /** The error's message. For a non-Error throw, its `String(...)` form. */\n readonly message: string;\n /** Whether the thrown value was a real `Error` instance. */\n readonly isError: boolean;\n /** The framework context, when supplied. */\n readonly context?: DiagnosticContext;\n /** The stack, only when `includeStack` was set and one exists. */\n readonly stack?: string;\n /** The described cause, only when `includeCause` was set and one exists. */\n readonly cause?: ErrorReport;\n}\n\nfunction describeErrorAt(\n error: unknown,\n context: DiagnosticContext | undefined,\n options: ErrorReportOptions,\n depth: number,\n): ErrorReport {\n const isError = error instanceof Error;\n const name = isError ? error.name : 'Error';\n // For a real Error, use its (author-controlled) message. For anything else,\n // stringify it — but never enumerate its properties, which may hold user data.\n const message = isError ? error.message : safeStringify(error);\n\n const report: {\n name: string;\n message: string;\n isError: boolean;\n context?: DiagnosticContext;\n stack?: string;\n cause?: ErrorReport;\n } = { name, message, isError };\n\n if (context !== undefined) report.context = context;\n if (options.includeStack === true && isError && typeof error.stack === 'string') {\n report.stack = error.stack;\n }\n if (options.includeCause === true && isError && depth < 4) {\n const cause = (error as { cause?: unknown }).cause;\n if (cause !== undefined && cause !== null) {\n report.cause = describeErrorAt(cause, undefined, options, depth + 1);\n }\n }\n return report;\n}\n\n/** Stringify a non-Error throw without ever enumerating its properties. */\nfunction safeStringify(value: unknown): string {\n if (typeof value === 'string') return value;\n if (value === null) return 'null';\n if (value === undefined) return 'undefined';\n const t = typeof value;\n if (t === 'number' || t === 'boolean' || t === 'bigint' || t === 'symbol') {\n return String(value);\n }\n // Objects/functions: report only the type + constructor name, never contents.\n const ctor =\n t === 'object' && value !== null\n ? ((value as object).constructor?.name ?? 'Object')\n : t;\n return `[non-Error ${ctor}]`;\n}\n\n/**\n * Build a {@link ErrorReport} from any thrown value and (optionally) the\n * framework {@link DiagnosticContext} it surfaced in. Production-safe by\n * default: no stack, no cause, no enumerated properties. This is a pure\n * function — it performs no logging and has no side effects, so it is safe to\n * call from any layer (an `errorBoundary` `onError`, an `asyncBoundary` error\n * branch, a resource loader `catch`).\n */\nexport function describeError(\n error: unknown,\n context?: DiagnosticContext,\n options: ErrorReportOptions = {},\n): ErrorReport {\n return describeErrorAt(error, context, options, 0);\n}\n\n/**\n * Convenience bridge: build a production-safe {@link ErrorReport} and route it\n * to a {@link DiagnosticSink} at the `error` level. The sink receives the\n * report's message and the structured {@link DiagnosticContext}; the full\n * report is returned to the caller for forwarding elsewhere (e.g. an app's own\n * crash reporter). Safe with `undefined` sink (no-op) and never throws.\n */\nexport function reportError(\n sink: DiagnosticSink | undefined,\n error: unknown,\n context?: DiagnosticContext,\n options: ErrorReportOptions = {},\n): ErrorReport {\n const report = describeError(error, context, options);\n reportDiagnostic(sink, 'error', report.message, report.context);\n return report;\n}\n","/**\n * Semantic Application Graph nodes.\n *\n * Every element in a StreetUI application is represented as a GraphNode.\n * Nodes form a tree: each has an optional parent and an ordered list of children.\n */\n\nimport { generateNodeId, type NodeId, type SemanticNodeType } from '@streetui/core';\n\n// ── Property values ───────────────────────────────────────────────────────────\n\nexport type PropValue =\n | string\n | number\n | boolean\n | null\n | undefined\n | string[]\n | number[]\n | Record<string, unknown>;\n\nexport type Props = Record<string, PropValue>;\n\n// ── Event descriptors ─────────────────────────────────────────────────────────\n\nexport interface EventDescriptor {\n readonly type: string;\n /** Reference key into the application's handler registry. */\n readonly handlerKey: string;\n}\n\n// ── State references ──────────────────────────────────────────────────────────\n\nexport interface StateRef {\n /** ID of the signal/store this node's property is bound to. */\n readonly signalId: string;\n /** The prop key on this node that is bound. */\n readonly propKey: string;\n}\n\n// ── The core graph node ───────────────────────────────────────────────────────\n\nexport interface GraphNodeData {\n readonly id: NodeId;\n readonly type: SemanticNodeType;\n readonly key: string | undefined;\n props: Props;\n events: EventDescriptor[];\n stateRefs: StateRef[];\n children: GraphNode[];\n parent: GraphNode | null;\n}\n\nexport class GraphNode implements GraphNodeData {\n readonly id: NodeId;\n readonly type: SemanticNodeType;\n readonly key: string | undefined;\n props: Props;\n events: EventDescriptor[];\n stateRefs: StateRef[];\n children: GraphNode[];\n parent: GraphNode | null;\n\n constructor(\n type: SemanticNodeType,\n options: {\n id?: NodeId;\n key?: string;\n props?: Props;\n events?: EventDescriptor[];\n stateRefs?: StateRef[];\n } = {},\n ) {\n this.type = type;\n this.id = options.id ?? generateNodeId(type);\n this.key = options.key;\n this.props = options.props ?? {};\n this.events = options.events ?? [];\n this.stateRefs = options.stateRefs ?? [];\n this.children = [];\n this.parent = null;\n }\n\n // ── Child management ────────────────────────────────────────────────────────\n\n appendChild(child: GraphNode): void {\n if (child.parent !== null) {\n child.parent.removeChild(child);\n }\n child.parent = this;\n this.children.push(child);\n }\n\n insertBefore(child: GraphNode, reference: GraphNode): void {\n const idx = this.children.indexOf(reference);\n if (idx === -1) {\n this.appendChild(child);\n return;\n }\n if (child.parent !== null) {\n child.parent.removeChild(child);\n }\n child.parent = this;\n this.children.splice(idx, 0, child);\n }\n\n removeChild(child: GraphNode): void {\n const idx = this.children.indexOf(child);\n if (idx === -1) return;\n this.children.splice(idx, 1);\n child.parent = null;\n }\n\n replaceChild(newChild: GraphNode, oldChild: GraphNode): void {\n const idx = this.children.indexOf(oldChild);\n if (idx === -1) {\n throw new Error(`GraphNode.replaceChild: oldChild is not a child of this node`);\n }\n if (newChild.parent !== null) {\n newChild.parent.removeChild(newChild);\n }\n oldChild.parent = null;\n newChild.parent = this;\n this.children.splice(idx, 1, newChild);\n }\n\n // ── Prop helpers ────────────────────────────────────────────────────────────\n\n setProp(key: string, value: PropValue): void {\n this.props = { ...this.props, [key]: value };\n }\n\n getProp<T extends PropValue = PropValue>(key: string): T | undefined {\n return this.props[key] as T | undefined;\n }\n\n // ── Event helpers ───────────────────────────────────────────────────────────\n\n addEvent(descriptor: EventDescriptor): void {\n this.events.push(descriptor);\n }\n\n removeEvent(type: string): void {\n this.events = this.events.filter(e => e.type !== type);\n }\n\n // ── Queries ─────────────────────────────────────────────────────────────────\n\n get isLeaf(): boolean {\n return this.children.length === 0;\n }\n\n get depth(): number {\n let d = 0;\n let node: GraphNode | null = this.parent;\n while (node !== null) {\n d++;\n node = node.parent;\n }\n return d;\n }\n\n get root(): GraphNode {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n let node: GraphNode = this;\n while (node.parent !== null) {\n node = node.parent;\n }\n return node;\n }\n\n /** Shallow clone — does not clone children. */\n shallowClone(): GraphNode {\n const opts: { key?: string; props: Props; events: EventDescriptor[]; stateRefs: StateRef[] } = {\n props: { ...this.props },\n events: [...this.events],\n stateRefs: [...this.stateRefs],\n };\n if (this.key !== undefined) opts.key = this.key;\n return new GraphNode(this.type, opts);\n }\n}\n","/**\n * The Semantic Application Graph.\n *\n * Holds the application root node and all its descendants.\n * Supports traversal, lookup by ID, validation, and serialization.\n */\n\nimport { type NodeId, DiagnosticCollector } from '@streetui/core';\nimport { GraphNode, type Props, type EventDescriptor } from './graph-node.js';\n\nexport interface ApplicationGraphOptions {\n readonly name: string;\n readonly version?: string;\n}\n\nexport interface HandlerFn {\n (...args: unknown[]): unknown;\n}\n\nexport class ApplicationGraph {\n readonly root: GraphNode;\n readonly name: string;\n readonly version: string;\n private readonly _nodeIndex: Map<NodeId, GraphNode> = new Map();\n /** Handler registry — maps handlerKey → actual function */\n readonly handlers: Map<string, HandlerFn> = new Map();\n\n constructor(options: ApplicationGraphOptions) {\n this.name = options.name;\n this.version = options.version ?? '0.0.1';\n this.root = new GraphNode('application', { props: { name: options.name } });\n this._nodeIndex.set(this.root.id, this.root);\n }\n\n // ── Node creation & attachment ────────────────────────────────────────────\n\n createNode(\n type: GraphNode['type'],\n options: { key?: string; props?: Props; parent?: GraphNode } = {},\n ): GraphNode {\n const nodeOpts: { key?: string; props?: Props } = {};\n if (options.key !== undefined) nodeOpts.key = options.key;\n if (options.props !== undefined) nodeOpts.props = options.props;\n const node = new GraphNode(type, nodeOpts);\n this._nodeIndex.set(node.id, node);\n if (options.parent !== undefined) {\n options.parent.appendChild(node);\n }\n return node;\n }\n\n attachNode(node: GraphNode, parent: GraphNode): void {\n this._nodeIndex.set(node.id, node);\n parent.appendChild(node);\n }\n\n detachNode(node: GraphNode): void {\n if (node.parent !== null) {\n node.parent.removeChild(node);\n }\n this._removeFromIndex(node);\n }\n\n private _removeFromIndex(node: GraphNode): void {\n this._nodeIndex.delete(node.id);\n this._unregisterNodeHandlers(node);\n for (const child of node.children) {\n this._removeFromIndex(child);\n }\n }\n\n /**\n * Remove every handler-registry entry owned by a single node. A node owns:\n * - one entry per event descriptor (its `handlerKey`),\n * - one `__signal__<signalId>` entry per state ref (signalIds are namespaced\n * by node id, so they are never shared between nodes), and\n * - a `__listbuild__<id>` entry if it is a reactive-list.\n * Called for every node in a detached subtree so removing list items (or\n * discarding freshly-built-but-unadopted item subtrees) leaves no stale\n * registrations behind.\n */\n private _unregisterNodeHandlers(node: GraphNode): void {\n for (const event of node.events) {\n this.handlers.delete(event.handlerKey);\n }\n for (const ref of node.stateRefs) {\n this.handlers.delete(`__signal__${ref.signalId}`);\n }\n this.handlers.delete(`__listbuild__${node.id}`);\n this.handlers.delete(`__listplan__${node.id}`);\n this.handlers.delete(`__overlay__${node.id}`);\n this.handlers.delete(`__component__${node.id}`);\n this.handlers.delete(`__transition__${node.id}`);\n this.handlers.delete(`__head__${node.id}`);\n }\n\n // ── Handler registry ──────────────────────────────────────────────────────\n\n registerHandler(key: string, fn: HandlerFn): void {\n this.handlers.set(key, fn);\n }\n\n getHandler(key: string): HandlerFn | undefined {\n return this.handlers.get(key);\n }\n\n /** True if a handler is currently registered under `key`. Inspection helper. */\n hasHandler(key: string): boolean {\n return this.handlers.has(key);\n }\n\n /** Number of currently-registered handlers. Inspection helper. */\n get handlerCount(): number {\n return this.handlers.size;\n }\n\n // ── Lookup ────────────────────────────────────────────────────────────────\n\n findById(id: NodeId): GraphNode | undefined {\n return this._nodeIndex.get(id);\n }\n\n findAll(predicate: (node: GraphNode) => boolean): GraphNode[] {\n const results: GraphNode[] = [];\n this._walk(this.root, node => {\n if (predicate(node)) results.push(node);\n });\n return results;\n }\n\n findByType(type: GraphNode['type']): GraphNode[] {\n return this.findAll(n => n.type === type);\n }\n\n // ── Traversal ─────────────────────────────────────────────────────────────\n\n walk(visitor: (node: GraphNode, depth: number) => void): void {\n this._walk(this.root, visitor, 0);\n }\n\n private _walk(\n node: GraphNode,\n visitor: (node: GraphNode, depth: number) => void,\n depth: number = 0,\n ): void {\n visitor(node, depth);\n for (const child of node.children) {\n this._walk(child, visitor, depth + 1);\n }\n }\n\n get nodeCount(): number {\n return this._nodeIndex.size;\n }\n\n // ── Validation ────────────────────────────────────────────────────────────\n\n validate(): DiagnosticCollector {\n const dc = new DiagnosticCollector();\n\n this.walk((node) => {\n // Validate event handler references exist\n for (const event of node.events) {\n if (!this.handlers.has(event.handlerKey)) {\n dc.warn(\n 'GRAPH_MISSING_HANDLER',\n `Node \"${node.id}\" references handler \"${event.handlerKey}\" which is not registered`,\n { nodeId: node.id },\n );\n }\n }\n\n // Validate page nodes are direct children of root\n if (node.type === 'page' && node.parent?.type !== 'application') {\n dc.error(\n 'GRAPH_PAGE_DEPTH',\n `Page node \"${node.id}\" must be a direct child of the application root`,\n { nodeId: node.id },\n );\n }\n });\n\n return dc;\n }\n\n // ── Serialization ─────────────────────────────────────────────────────────\n\n serialize(): SerializedGraph {\n return {\n name: this.name,\n version: this.version,\n root: this._serializeNode(this.root),\n };\n }\n\n private _serializeNode(node: GraphNode): SerializedNode {\n const result: SerializedNode = {\n id: node.id,\n type: node.type,\n key: node.key,\n props: node.props,\n events: node.events,\n stateRefs: node.stateRefs,\n children: node.children.map(c => this._serializeNode(c)),\n };\n return result;\n }\n}\n\nexport interface SerializedNode {\n readonly id: string;\n readonly type: string;\n readonly key: string | undefined;\n readonly props: Props;\n readonly events: EventDescriptor[];\n readonly stateRefs: unknown[];\n readonly children: SerializedNode[];\n}\n\nexport interface SerializedGraph {\n readonly name: string;\n readonly version: string;\n readonly root: SerializedNode;\n}\n","/**\n * Transition configuration (§2, §4).\n *\n * A `TransitionConfig` is a pure, declarative description of a CSS class-based\n * enter/leave transition — the engine choice for this milestone. It contains NO\n * DOM references, NO timers and NO browser-only APIs, so it is safe to build on\n * the server (where it is simply ignored — see the renderer's SSR guard) and to\n * carry on a graph handler (`__transition__<nodeId>`) alongside the existing\n * `__overlay__`/`__component__` descriptors.\n *\n * The class model follows the widely-understood enter/leave convention:\n *\n * enter: [enterActive (+ enter) whole phase] · enterFrom (start) → enterTo (end)\n * leave: [leaveActive (+ leave) whole phase] · leaveFrom (start) → leaveTo (end)\n *\n * `name` is a shorthand that expands to `${name}-enter-from`,\n * `${name}-enter-active`, `${name}-enter-to` and the leave equivalents; explicit\n * class fields override the derived ones. Because the classes are just strings,\n * SSR output is deterministic (no class is applied on the server at all — the\n * controller is browser-only), satisfying §4/§21.\n */\nexport interface TransitionConfig {\n /** Shorthand base: expands to `${name}-enter-from`, `${name}-enter-active`, … */\n readonly name?: string;\n /** Class(es) present for the whole enter phase (in addition to `enterActive`). */\n readonly enter?: string;\n /** Class(es) applied at the start of enter, removed on the next frame. */\n readonly enterFrom?: string;\n /** Class(es) present for the whole enter phase (where the CSS `transition` lives). */\n readonly enterActive?: string;\n /** Class(es) added on the next frame, removed when enter completes. */\n readonly enterTo?: string;\n /** Class(es) present for the whole leave phase (in addition to `leaveActive`). */\n readonly leave?: string;\n /** Class(es) applied at the start of leave, removed on the next frame. */\n readonly leaveFrom?: string;\n /** Class(es) present for the whole leave phase (where the CSS `transition` lives). */\n readonly leaveActive?: string;\n /** Class(es) added on the next frame, removed when leave completes. */\n readonly leaveTo?: string;\n /**\n * Also animate the very first appearance (initial mount). Hydration never\n * animates appear (the DOM is already present and correct); this only affects\n * fresh browser mounts. Defaults to false.\n */\n readonly appear?: boolean;\n /**\n * Fallback completion timeout in milliseconds. A transition normally completes\n * on the element's `transitionend`/`animationend`. This timeout is the safety\n * net for (a) transitions that fire no such event and (b) test DOMs like\n * happy-dom that dispatch no transition events at all — making tests\n * deterministic without a real browser (§24). Defaults to 1000. Use a small\n * value (or 0 → next macrotask) in tests.\n */\n readonly duration?: number;\n}\n\n/**\n * The resolved, ready-to-apply form of a {@link TransitionConfig}: each phase's\n * classes are pre-split into arrays so the controller applies/removes them with\n * no per-run string parsing. Produced once by {@link resolveTransition} at wire\n * time (browser only).\n */\nexport interface ResolvedTransition {\n /** enter classes present for the whole phase (base `enter` + `enterActive`). */\n readonly enterActive: readonly string[];\n /** enter start classes (removed next frame). */\n readonly enterFrom: readonly string[];\n /** enter end classes (added next frame). */\n readonly enterTo: readonly string[];\n readonly leaveActive: readonly string[];\n readonly leaveFrom: readonly string[];\n readonly leaveTo: readonly string[];\n readonly appear: boolean;\n readonly duration: number;\n}\n\n/** Split a class string on whitespace into a de-duplicated array (empty-safe). */\nfunction classes(value: string | undefined): string[] {\n if (value === undefined) return [];\n const out: string[] = [];\n for (const token of value.split(/\\s+/)) {\n if (token.length > 0 && !out.includes(token)) out.push(token);\n }\n return out;\n}\n\n/** Merge two class arrays, preserving order and dropping duplicates. */\nfunction merge(a: string[], b: string[]): string[] {\n const out = [...a];\n for (const token of b) if (!out.includes(token)) out.push(token);\n return out;\n}\n\n/**\n * Resolve a {@link TransitionConfig} into applied class arrays. The `name`\n * shorthand supplies defaults; any explicit field overrides the derived class\n * for that phase-slot (still merged with `enter`/`leave` base classes).\n */\nexport function resolveTransition(config: TransitionConfig): ResolvedTransition {\n const n = config.name;\n const enterActive = merge(\n classes(config.enter),\n classes(config.enterActive ?? (n !== undefined ? `${n}-enter-active` : undefined)),\n );\n const leaveActive = merge(\n classes(config.leave),\n classes(config.leaveActive ?? (n !== undefined ? `${n}-leave-active` : undefined)),\n );\n return {\n enterActive,\n enterFrom: classes(config.enterFrom ?? (n !== undefined ? `${n}-enter-from` : undefined)),\n enterTo: classes(config.enterTo ?? (n !== undefined ? `${n}-enter-to` : undefined)),\n leaveActive,\n leaveFrom: classes(config.leaveFrom ?? (n !== undefined ? `${n}-leave-from` : undefined)),\n leaveTo: classes(config.leaveTo ?? (n !== undefined ? `${n}-leave-to` : undefined)),\n appear: config.appear ?? false,\n duration: config.duration ?? 1000,\n };\n}\n\n/** Runtime brand check for a transition descriptor value. */\nexport function isTransitionConfig(value: unknown): value is TransitionConfig {\n if (value === null || typeof value !== 'object') return false;\n const o = value as Record<string, unknown>;\n // A config is meaningful only if it carries at least one class source.\n return (\n typeof o['name'] === 'string' ||\n typeof o['enter'] === 'string' ||\n typeof o['enterActive'] === 'string' ||\n typeof o['enterFrom'] === 'string' ||\n typeof o['leave'] === 'string' ||\n typeof o['leaveActive'] === 'string' ||\n typeof o['leaveFrom'] === 'string'\n );\n}\n","/**\n * Document head / metadata model (2.0 §1–§3).\n *\n * `head({...})` is a first-class StreetUI primitive for declaring document\n * metadata — title, meta, link, canonical, Open Graph, Twitter/X, robots,\n * theme-color and favicon. It is NOT a copy of another framework's API: it is\n * expressed on StreetUI's own component/graph model. A `head()` call creates a\n * `'head'` graph node (rendered as a neutral inline anchor, like a portal) and\n * registers a `__head__<nodeId>` descriptor — exactly the handler-registry\n * convention used by `__overlay__`/`__transition__`/`__component__`. The\n * renderer reads that descriptor to:\n *\n * • apply the contribution to `document.head` on the browser\n * (`wireHeadBehavior`), adopting server-emitted tags on hydration so there\n * are no duplicates, and cleaning up its own tags on unmount / route change;\n * • emit only the active graph's merged metadata as an HTML string on the\n * server (`renderHead`).\n *\n * This module is pure and DOM-free (like `transition.ts`): it defines the config\n * shape and normalises it into an ordered list of {@link HeadEntry} with stable\n * *dedup keys*. All merge/precedence/DOM work happens in the renderer, keyed by\n * these entries.\n *\n * ── Deduplication & precedence (§3) ──────────────────────────────────────────\n * Every entry carries a `dedupKey`. When several `head()` nodes are live at once\n * (e.g. an app-level default, a route-level `head()`, and a component-level\n * `head()`), the renderer merges all of their entries and, for each `dedupKey`,\n * the LAST contribution in document order wins. Document order is pre-order DFS\n * = mount order, so a `head()` declared deeper/later (a route or a component\n * nested inside the app shell) deterministically overrides an app-level default\n * for the same key. Removing that node (navigating away, unmounting the\n * component) re-exposes the previously-shadowed default. `<title>` and each\n * single-instance meta/link (description, robots, theme-color, viewport,\n * charset, canonical, favicon, and each og: or twitter: property) collapse to one\n * effective tag; generic `meta[]`/`link[]` array entries are keyed by their\n * identifying attributes so independent tags coexist.\n */\n\nimport type { ReadonlySignal, Signal } from '@streetui/state';\n\n/** A head value that may be a literal string or a reactive signal of a string. */\nexport type BindableString = string | ReadonlySignal<string> | Signal<string>;\n\n/** A single `<meta>` descriptor. Provide exactly one identifying key. */\nexport interface MetaDescriptor {\n /** `name=\"…\"` (e.g. \"description\", \"robots\", \"theme-color\", \"twitter:card\"). */\n readonly name?: string;\n /** `property=\"…\"` (e.g. \"og:title\", \"og:image\") — the Open Graph convention. */\n readonly property?: string;\n /** `http-equiv=\"…\"` (e.g. \"content-security-policy\"). */\n readonly httpEquiv?: string;\n /** `charset=\"…\"` (e.g. \"utf-8\"). Standalone; no `content`. */\n readonly charset?: string;\n /** The tag's `content`. May be reactive. */\n readonly content?: BindableString;\n}\n\n/** A single `<link>` descriptor. `rel`+`href` identify it. */\nexport interface LinkDescriptor {\n readonly rel: string;\n readonly href: string;\n readonly sizes?: string;\n readonly type?: string;\n readonly media?: string;\n readonly as?: string;\n readonly crossorigin?: string;\n readonly hreflang?: string;\n}\n\n/**\n * Declarative document metadata. Every field is optional; convenience fields\n * (title/description/canonical/robots/themeColor/viewport/charset/favicon/\n * openGraph/twitter) expand into the same normalized entries as the raw\n * `meta`/`link` arrays, with single-instance dedup keys so a later `head()`\n * cleanly overrides an earlier one.\n */\nexport interface HeadMetadata {\n /** `<title>` text. May be reactive. Single-instance (dedup key `title`). */\n readonly title?: BindableString;\n /** `<meta name=\"description\">`. May be reactive. */\n readonly description?: BindableString;\n /** `<link rel=\"canonical\">` href. */\n readonly canonical?: string;\n /** `<meta name=\"robots\">` (e.g. \"index,follow\" / \"noindex\"). */\n readonly robots?: string;\n /** `<meta name=\"theme-color\">`. */\n readonly themeColor?: string;\n /** `<meta name=\"viewport\">`. */\n readonly viewport?: string;\n /** `<meta charset>`. */\n readonly charset?: string;\n /** Favicon: a shorthand for `<link rel=\"icon\">`. String = href, or a full descriptor. */\n readonly favicon?: string | LinkDescriptor;\n /** Open Graph properties — each key `k` becomes `<meta property=\"og:k\">`. Values may be reactive. */\n readonly openGraph?: Readonly<Record<string, BindableString>>;\n /** Twitter/X card properties — each key `k` becomes `<meta name=\"twitter:k\">`. Values may be reactive. */\n readonly twitter?: Readonly<Record<string, BindableString>>;\n /** Raw `<meta>` tags (for anything the convenience fields don't cover). */\n readonly meta?: readonly MetaDescriptor[];\n /** Raw `<link>` tags (stylesheets, preload, alternate, etc.). */\n readonly link?: readonly LinkDescriptor[];\n /** `<base href>` — single-instance. */\n readonly base?: string;\n}\n\n/**\n * A normalized head tag: one `<title>`, `<meta>`, `<link>` or `<base>`. Attr\n * values and the title's text may still be reactive (`BindableString`); the\n * renderer peeks them for SSR and subscribes to them on the browser. `dedupKey`\n * is what the merge collapses on.\n */\nexport interface HeadEntry {\n readonly tag: 'title' | 'meta' | 'link' | 'base';\n readonly dedupKey: string;\n /** Static + reactive attributes (no `undefined` values). */\n readonly attrs: Readonly<Record<string, BindableString>>;\n /** Text content — only meaningful for `tag === 'title'`. */\n readonly text?: BindableString;\n}\n\n/** The value a `__head__<id>` handler returns: this node's ordered contribution. */\nexport interface HeadContribution {\n readonly entries: readonly HeadEntry[];\n}\n\nfunction metaDedupKey(m: MetaDescriptor): string | undefined {\n if (m.charset !== undefined) return 'meta:charset';\n if (m.name !== undefined) return `meta:name=${m.name}`;\n if (m.property !== undefined) return `meta:property=${m.property}`;\n if (m.httpEquiv !== undefined) return `meta:http-equiv=${m.httpEquiv}`;\n return undefined;\n}\n\nfunction metaAttrs(m: MetaDescriptor): Record<string, BindableString> {\n const attrs: Record<string, BindableString> = {};\n if (m.charset !== undefined) attrs['charset'] = m.charset;\n if (m.name !== undefined) attrs['name'] = m.name;\n if (m.property !== undefined) attrs['property'] = m.property;\n if (m.httpEquiv !== undefined) attrs['http-equiv'] = m.httpEquiv;\n if (m.content !== undefined) attrs['content'] = m.content;\n return attrs;\n}\n\nfunction linkAttrs(l: LinkDescriptor): Record<string, BindableString> {\n const attrs: Record<string, BindableString> = { rel: l.rel, href: l.href };\n if (l.sizes !== undefined) attrs['sizes'] = l.sizes;\n if (l.type !== undefined) attrs['type'] = l.type;\n if (l.media !== undefined) attrs['media'] = l.media;\n if (l.as !== undefined) attrs['as'] = l.as;\n if (l.crossorigin !== undefined) attrs['crossorigin'] = l.crossorigin;\n if (l.hreflang !== undefined) attrs['hreflang'] = l.hreflang;\n return attrs;\n}\n\n/**\n * Normalise a {@link HeadMetadata} into an ordered list of {@link HeadEntry}.\n * Emission order within one `head()` is: charset → base → title → description →\n * canonical → robots → theme-color → viewport → favicon → openGraph → twitter →\n * explicit meta[] → explicit link[]. (Merge across nodes is document order; this\n * per-node order only affects the sequence of same-priority tags.)\n */\nexport function resolveHead(config: HeadMetadata): HeadContribution {\n const entries: HeadEntry[] = [];\n\n if (config.charset !== undefined) {\n entries.push({ tag: 'meta', dedupKey: 'meta:charset', attrs: { charset: config.charset } });\n }\n if (config.base !== undefined) {\n entries.push({ tag: 'base', dedupKey: 'base', attrs: { href: config.base } });\n }\n if (config.title !== undefined) {\n entries.push({ tag: 'title', dedupKey: 'title', attrs: {}, text: config.title });\n }\n if (config.description !== undefined) {\n entries.push({\n tag: 'meta',\n dedupKey: 'meta:name=description',\n attrs: { name: 'description', content: config.description },\n });\n }\n if (config.canonical !== undefined) {\n entries.push({\n tag: 'link',\n dedupKey: 'link:rel=canonical',\n attrs: { rel: 'canonical', href: config.canonical },\n });\n }\n if (config.robots !== undefined) {\n entries.push({\n tag: 'meta',\n dedupKey: 'meta:name=robots',\n attrs: { name: 'robots', content: config.robots },\n });\n }\n if (config.themeColor !== undefined) {\n entries.push({\n tag: 'meta',\n dedupKey: 'meta:name=theme-color',\n attrs: { name: 'theme-color', content: config.themeColor },\n });\n }\n if (config.viewport !== undefined) {\n entries.push({\n tag: 'meta',\n dedupKey: 'meta:name=viewport',\n attrs: { name: 'viewport', content: config.viewport },\n });\n }\n if (config.favicon !== undefined) {\n const l: LinkDescriptor =\n typeof config.favicon === 'string' ? { rel: 'icon', href: config.favicon } : config.favicon;\n // Favicons are single-instance by rel (rel=icon), so a later head() replaces\n // an earlier icon rather than stacking a second one.\n entries.push({ tag: 'link', dedupKey: `link:rel=${l.rel}`, attrs: linkAttrs(l) });\n }\n if (config.openGraph !== undefined) {\n for (const key of Object.keys(config.openGraph)) {\n const property = `og:${key}`;\n entries.push({\n tag: 'meta',\n dedupKey: `meta:property=${property}`,\n attrs: { property, content: config.openGraph[key]! },\n });\n }\n }\n if (config.twitter !== undefined) {\n for (const key of Object.keys(config.twitter)) {\n const name = `twitter:${key}`;\n entries.push({\n tag: 'meta',\n dedupKey: `meta:name=${name}`,\n attrs: { name, content: config.twitter[key]! },\n });\n }\n }\n if (config.meta !== undefined) {\n for (const m of config.meta) {\n const key = metaDedupKey(m);\n if (key === undefined) continue; // a meta with no identifying attribute is dropped\n entries.push({ tag: 'meta', dedupKey: key, attrs: metaAttrs(m) });\n }\n }\n if (config.link !== undefined) {\n for (const l of config.link) {\n // Generic links are keyed by rel+href so multiple independent links coexist\n // (unlike canonical/icon which are single-instance by rel).\n entries.push({ tag: 'link', dedupKey: `link:rel=${l.rel}:href=${l.href}`, attrs: linkAttrs(l) });\n }\n }\n\n return { entries };\n}\n\n/** Runtime brand check for a head-contribution descriptor value. */\nexport function isHeadContribution(value: unknown): value is HeadContribution {\n return (\n value !== null &&\n typeof value === 'object' &&\n Array.isArray((value as Record<string, unknown>)['entries'])\n );\n}\n","/**\n * DSL builder implementations.\n *\n * Each builder wraps a GraphNode and provides the fluent API\n * for constructing the Semantic Application Graph via the DSL.\n *\n * Builders do NOT render anything — they only build the graph.\n */\n\nimport { ApplicationGraph, GraphNode, type Props } from '@streetui/graph';\nimport type {\n ContentDSL,\n ContainerDSL,\n SectionDSL,\n PageDSL,\n FormDSL,\n ListDSL,\n AppDSL,\n HeadingOptions,\n TextOptions,\n ButtonOptions,\n InputOptions,\n LinkOptions,\n ImageOptions,\n ContainerOptions,\n SectionOptions,\n FormOptions,\n ListOptions,\n PortalOptions,\n OverlayOptions,\n A11yOptions,\n Bindable,\n BindableText,\n TextValue,\n ErrorBoundaryOptions,\n ErrorSource,\n AsyncBoundaryBranches,\n PageBuilder,\n SectionBuilder,\n ContainerBuilder as ContainerBuilderFn,\n FormBuilder,\n ListBuilder,\n} from './dsl-types.js';\nimport type {\n ComponentContext,\n ComponentDefinition,\n ComponentRender,\n} from './component.js';\nimport type { TransitionConfig } from './transition.js';\nimport { resolveTransition } from './transition.js';\nimport type { HeadMetadata } from './head.js';\nimport { resolveHead } from './head.js';\nimport type { WhenOptions } from './dsl-types.js';\nimport { signal, derived, effect, type Signal, type ReadonlySignal, type Resource } from '@streetui/state';\n\n/**\n * A single reactive-list reconciliation descriptor (spec §15).\n *\n * Emitted by the `__listplan__<nodeId>` handler on every list change. `key` is\n * the item's identity-only reconciliation key (cheap to compute); `item` is the\n * source value *reference* used for identity short-circuiting; `sig()` computes\n * the content signature on demand (only when the reference changed); `build()`\n * materialises the full item subtree on demand (only for new/changed rows).\n */\nexport interface ListPlanEntry {\n readonly key: string;\n readonly item: unknown;\n readonly sig: () => string;\n readonly build: () => GraphNode;\n}\n\n// ── Signal helpers ────────────────────────────────────────────────────────────\n\nfunction isSignal(v: unknown): v is Signal<unknown> | ReadonlySignal<unknown> {\n return (\n v !== null &&\n typeof v === 'object' &&\n typeof (v as Record<string, unknown>)['get'] === 'function' &&\n typeof (v as Record<string, unknown>)['subscribe'] === 'function'\n );\n}\n\n/** Register a signal binding on the node and return the current static value. */\nfunction bindValue<T>(\n graph: ApplicationGraph,\n node: GraphNode,\n propKey: string,\n value: Bindable<T>,\n): T {\n if (isSignal(value)) {\n const signalId = `${node.id}:${propKey}`;\n node.stateRefs.push({ signalId, propKey });\n graph.registerHandler(`__signal__${signalId}`, value as unknown as () => unknown);\n return (value as ReadonlySignal<T>).peek();\n }\n return value as T;\n}\n\n// ── Helper to build Props from ContainerOptions ───────────────────────────────\n\n/**\n * Copy accessibility options onto a props bag as their corresponding HTML/ARIA\n * attribute names. Values are written as strings (booleans become \"true\"/\"false\"\n * rather than being dropped) so ARIA state attributes render literally. These\n * flow to the DOM via the renderer's generic attribute pass — no ARIA-specific\n * renderer code is involved.\n */\nfunction applyA11yProps(props: Props, options: A11yOptions): void {\n if (options.role !== undefined) props['role'] = options.role;\n if (options.tabIndex !== undefined) props['tabindex'] = String(options.tabIndex);\n if (options.ariaLabel !== undefined) props['aria-label'] = options.ariaLabel;\n if (options.ariaLabelledBy !== undefined) props['aria-labelledby'] = options.ariaLabelledBy;\n if (options.ariaDescribedBy !== undefined) props['aria-describedby'] = options.ariaDescribedBy;\n if (options.ariaExpanded !== undefined) props['aria-expanded'] = String(options.ariaExpanded);\n if (options.ariaControls !== undefined) props['aria-controls'] = options.ariaControls;\n if (options.ariaHidden !== undefined) props['aria-hidden'] = String(options.ariaHidden);\n if (options.ariaLive !== undefined) props['aria-live'] = options.ariaLive;\n if (options.ariaCurrent !== undefined) props['aria-current'] = String(options.ariaCurrent);\n if (options.ariaInvalid !== undefined) props['aria-invalid'] = String(options.ariaInvalid);\n if (options.ariaRequired !== undefined) props['aria-required'] = String(options.ariaRequired);\n if (options.ariaModal !== undefined) props['aria-modal'] = String(options.ariaModal);\n if (options.ariaOwns !== undefined) props['aria-owns'] = options.ariaOwns;\n if (options.ariaActiveDescendant !== undefined) props['aria-activedescendant'] = options.ariaActiveDescendant;\n if (options.ariaHasPopup !== undefined) props['aria-haspopup'] = String(options.ariaHasPopup);\n if (options.ariaSelected !== undefined) props['aria-selected'] = String(options.ariaSelected);\n}\n\n/**\n * Register a `__transition__<nodeId>` descriptor for an element that opts into a\n * CSS class-based enter/leave transition (§2). Mirrors the `__overlay__` /\n * `__component__` handler pattern: the renderer reads it (browser only) to run\n * enter on mount and to defer removal/dispose until leave completes. Pure config\n * — no DOM, no timers — so it is inert on the server and pruned by\n * `graph._unregisterNodeHandlers` (§23). A no-op when no transition is supplied.\n */\nfunction registerTransition(\n graph: ApplicationGraph,\n node: GraphNode,\n config: TransitionConfig | undefined,\n): void {\n if (config === undefined) return;\n // Resolve to the pre-split class arrays at wire time so the renderer's\n // controller consumes a plain `ResolvedTransition` and never re-parses class\n // strings per run — and so the renderer needs no compile-time dependency on\n // this DSL package (it reads the descriptor structurally, exactly like\n // `__overlay__`/`__component__`).\n const resolved = resolveTransition(config);\n graph.registerHandler(\n `__transition__${node.id}`,\n (() => resolved) as unknown as () => unknown,\n );\n}\n\nfunction containerProps(options: ContainerOptions): Props {\n const props: Props = {};\n if (options.class !== undefined) props['class'] = options.class;\n if (options.id !== undefined) props['id'] = options.id;\n if (options.key !== undefined) props['key'] = options.key;\n applyA11yProps(props, options);\n return props;\n}\n\n// ── Reactive-list item keying ──────────────────────────────────────────────────\n//\n// The `listOf` DSL signature does not take an explicit key extractor, so we\n// derive a stable reconciliation key from each item. The key combines an\n// *identity* part (so reordering the same items reuses their DOM nodes) with a\n// *value signature* (so an item whose data changed is treated as a fresh node\n// and re-rendered rather than silently kept stale by the shallow reconciler).\n\nfunction itemIdentity(item: unknown, index: number): string {\n if (item !== null && typeof item === 'object') {\n const obj = item as Record<string, unknown>;\n if ('id' in obj) return `id:${String(obj['id'])}`;\n if ('key' in obj) return `key:${String(obj['key'])}`;\n return `idx:${index}`;\n }\n return `val:${String(item)}`;\n}\n\nfunction itemValueSignature(item: unknown): string {\n try {\n return JSON.stringify(item) ?? String(item);\n } catch {\n return String(item);\n }\n}\n\n/** Content signature used to detect in-place data changes of a stable item. */\nexport function reactiveListItemSignature(item: unknown): string {\n return itemValueSignature(item);\n}\n\n/** Stable, identity-only reconciliation key for a reactive-list item. */\nexport function reactiveListItemKey(item: unknown, index: number): string {\n return itemIdentity(item, index);\n}\n\n// ── Overlay kind configuration ──────────────────────────────────────────────────\n//\n// Each overlay builder (dialog/popover/tooltip/dropdown/toast) is the same\n// portal + `when(open, …)` panel + focus/keyboard behavior, differing only in\n// ARIA role, modality, whether it takes focus, and its escape/restore defaults.\n// This table captures those differences; `_overlay` does the shared assembly.\n\ninterface OverlayKindConfig {\n /** Default ARIA role for the panel. */\n readonly role: string;\n /** Trap + contain focus (modal semantics). */\n readonly modal: boolean;\n /** Move focus into the panel when it opens. */\n readonly takesFocus: boolean;\n /** Wire arrow/Home/End/Enter/Space roving-focus navigation (role=\"menu\"). */\n readonly menu?: boolean;\n /** Emit `aria-modal=\"true\"` on the panel. */\n readonly ariaModal: boolean;\n /** Emit an `aria-live` region on the panel (announcements). */\n readonly ariaLive?: 'polite' | 'assertive';\n /** Default for `closeOnEscape` when the caller does not specify it. */\n readonly defaultCloseOnEscape: boolean;\n /** Default for `restoreFocus` when the caller does not specify it. */\n readonly defaultRestoreFocus: boolean;\n}\n\nconst OVERLAY_KINDS = {\n dialog: {\n role: 'dialog', modal: true, takesFocus: true, ariaModal: true,\n defaultCloseOnEscape: true, defaultRestoreFocus: true,\n },\n popover: {\n role: 'dialog', modal: false, takesFocus: true, ariaModal: false,\n defaultCloseOnEscape: true, defaultRestoreFocus: true,\n },\n tooltip: {\n role: 'tooltip', modal: false, takesFocus: false, ariaModal: false,\n defaultCloseOnEscape: false, defaultRestoreFocus: false,\n },\n dropdown: {\n role: 'menu', modal: false, takesFocus: true, menu: true, ariaModal: false,\n defaultCloseOnEscape: true, defaultRestoreFocus: true,\n },\n toast: {\n role: 'status', modal: false, takesFocus: false, ariaModal: false,\n ariaLive: 'polite', defaultCloseOnEscape: false, defaultRestoreFocus: false,\n },\n} as const satisfies Record<string, OverlayKindConfig>;\n\n/** The opaque descriptor the renderer reads from `__overlay__<portalId>`. */\ninterface OverlayBehaviorDescriptor {\n readonly open: ReadonlySignal<boolean>;\n readonly modal: boolean;\n readonly takesFocus: boolean;\n readonly menu: boolean;\n readonly closeOnEscape: boolean;\n readonly restoreFocus: boolean;\n readonly initialFocusId?: string;\n readonly onClose?: () => void;\n}\n\n// ── Base content builder ──────────────────────────────────────────────────────\n\nclass ContentBuilderBase implements ContentDSL {\n constructor(\n protected readonly _node: GraphNode,\n protected readonly _graph: ApplicationGraph,\n ) {}\n\n heading(text: BindableText, options: HeadingOptions = {}): void {\n const props: Props = { level: options.level ?? 1 };\n if (options.class !== undefined) props['class'] = options.class;\n if (options.id !== undefined) props['id'] = options.id;\n applyA11yProps(props, options);\n const node = this._graph.createNode('heading', { parent: this._node, props });\n const resolved = bindValue<TextValue>(this._graph, node, 'text', text);\n node.setProp('text', resolved);\n }\n\n text(content: BindableText, options: TextOptions = {}): void {\n const props: Props = {};\n if (options.class !== undefined) props['class'] = options.class;\n if (options.id !== undefined) props['id'] = options.id;\n applyA11yProps(props, options);\n const node = this._graph.createNode('text', { parent: this._node, props });\n const resolved = bindValue<TextValue>(this._graph, node, 'text', content);\n node.setProp('text', resolved);\n }\n\n button(label: BindableText, options: ButtonOptions = {}): void {\n const props: Props = {};\n if (options.class !== undefined) props['class'] = options.class;\n if (options.id !== undefined) props['id'] = options.id;\n applyA11yProps(props, options);\n const node = this._graph.createNode('button', { parent: this._node, props });\n const resolved = bindValue<TextValue>(this._graph, node, 'label', label);\n node.setProp('label', resolved);\n if (options.disabled !== undefined) {\n const resolvedDisabled = bindValue(this._graph, node, 'disabled', options.disabled);\n node.setProp('disabled', resolvedDisabled);\n }\n if (options.onClick !== undefined) {\n const handlerKey = `click:${node.id}`;\n this._graph.registerHandler(handlerKey, options.onClick as () => unknown);\n node.addEvent({ type: 'click', handlerKey });\n }\n }\n\n input(options: InputOptions = {}): void {\n const props: Props = {};\n props['inputType'] = options.type ?? 'text';\n if (options.placeholder !== undefined) props['placeholder'] = options.placeholder;\n if (options.class !== undefined) props['class'] = options.class;\n if (options.id !== undefined) props['id'] = options.id;\n applyA11yProps(props, options);\n const nodeOpts: { key?: string; props: Props; parent: GraphNode } = {\n props,\n parent: this._node,\n };\n if (options.id !== undefined) nodeOpts.key = options.id;\n const node = this._graph.createNode('input', nodeOpts);\n\n // Two-way `bind` expands to a value binding + an input write-back. The type\n // system (BoundInputOptions vs ControlledInputOptions) guarantees `bind` is\n // never combined with explicit `value`/`onInput`, so there is no ambiguity.\n const bindSignal = options.bind;\n const valueBindable: Bindable<string> | undefined =\n bindSignal !== undefined ? bindSignal : options.value;\n const inputHandler: ((value: string) => void) | undefined =\n bindSignal !== undefined ? (v: string) => bindSignal.set(v) : options.onInput;\n\n if (valueBindable !== undefined) {\n const resolved = bindValue(this._graph, node, 'value', valueBindable);\n node.setProp('value', resolved);\n }\n if (options.disabled !== undefined) {\n const resolved = bindValue(this._graph, node, 'disabled', options.disabled);\n node.setProp('disabled', resolved);\n }\n if (inputHandler !== undefined) {\n const handlerKey = `input:${node.id}`;\n this._graph.registerHandler(handlerKey, inputHandler as () => unknown);\n node.addEvent({ type: 'input', handlerKey });\n }\n if (options.onChange !== undefined) {\n const handlerKey = `change:${node.id}`;\n this._graph.registerHandler(handlerKey, options.onChange as () => unknown);\n node.addEvent({ type: 'change', handlerKey });\n }\n }\n\n image(options: ImageOptions): void {\n const props: Props = {\n src: options.src,\n alt: options.alt,\n };\n if (options.width !== undefined) props['width'] = options.width;\n if (options.height !== undefined) props['height'] = options.height;\n if (options.class !== undefined) props['class'] = options.class;\n if (options.id !== undefined) props['id'] = options.id;\n applyA11yProps(props, options);\n const nodeOpts: { key?: string; props: Props; parent: GraphNode } = {\n props,\n parent: this._node,\n };\n if (options.id !== undefined) nodeOpts.key = options.id;\n this._graph.createNode('image', nodeOpts);\n }\n\n link(label: BindableText, options: LinkOptions): void {\n const props: Props = {\n href: options.href,\n external: options.external ?? false,\n };\n if (options.class !== undefined) props['class'] = options.class;\n if (options.id !== undefined) props['id'] = options.id;\n applyA11yProps(props, options);\n const node = this._graph.createNode('link', { parent: this._node, props });\n const resolved = bindValue<TextValue>(this._graph, node, 'label', label);\n node.setProp('label', resolved);\n if (options.onClick !== undefined) {\n const handlerKey = `click:${node.id}`;\n this._graph.registerHandler(handlerKey, options.onClick as () => unknown);\n node.addEvent({ type: 'click', handlerKey });\n }\n }\n}\n\n// ── Container builder ─────────────────────────────────────────────────────────\n\nclass ContainerBuilderBase extends ContentBuilderBase implements ContainerDSL {\n section(key: string, builder: SectionBuilder, options: SectionOptions = {}): void {\n const node = this._graph.createNode('section', {\n key,\n parent: this._node,\n props: containerProps(options),\n });\n registerTransition(this._graph, node, options.transition);\n builder(new SectionBuilderImpl(node, this._graph));\n }\n\n container(key: string, builder: ContainerBuilderFn, options: ContainerOptions = {}): void {\n const node = this._graph.createNode('container', {\n key,\n parent: this._node,\n props: containerProps(options),\n });\n registerTransition(this._graph, node, options.transition);\n builder(new ContainerBuilderImpl(node, this._graph));\n }\n\n list(key: string, builder: ListBuilder, options: ListOptions = {}): void {\n const node = this._graph.createNode('list', {\n key,\n parent: this._node,\n props: containerProps(options),\n });\n registerTransition(this._graph, node, options.transition);\n builder(new ListBuilderImpl(node, this._graph));\n }\n\n listOf<T>(\n key: string,\n items: Signal<T[]> | ReadonlySignal<T[]>,\n renderItem: (item: T, index: number, content: ContentDSL) => void,\n options: ListOptions = {},\n ): void {\n const graph = this._graph;\n const node = graph.createNode('reactive-list', {\n key,\n parent: this._node,\n props: containerProps(options),\n });\n registerTransition(graph, node, options.transition);\n\n // Register the driving signal so the runtime/renderer can subscribe to it.\n const signalId = `${node.id}:items`;\n node.stateRefs.push({ signalId, propKey: 'items' });\n graph.registerHandler(`__signal__${signalId}`, items as unknown as () => unknown);\n\n // Build a single detached list-item subtree for one item. The item's\n // reconciliation `key` is identity-only, and its value signature is stored\n // in the internal `_sig` prop so the renderer can detect (and apply a\n // targeted update for) a data change on an item whose identity is stable.\n const buildItem = (item: T, index: number): GraphNode => {\n const itemKey = reactiveListItemKey(item, index);\n const itemNode = graph.createNode('list-item', {\n key: itemKey,\n // `_item` records the source item *reference* so the reconciler can\n // short-circuit unchanged rows by identity (no signature hashing); `_sig`\n // is the content signature used to detect an in-place data change when the\n // reference differs. Both are internal metadata (leading `_`) and never\n // reach the DOM.\n props: {\n key: itemKey,\n _sig: reactiveListItemSignature(item),\n // The item reference is stored as opaque internal metadata (never\n // rendered); cast through `unknown` since `T` is not a `PropValue`.\n _item: item as unknown as Props[string],\n },\n });\n renderItem(item, index, new ContainerBuilderImpl(itemNode, graph));\n // Per-item enter/leave transition (§7). Registered on every item node so a\n // freshly-built row (append/prepend/change) carries it; keyed identity is\n // unaffected because the transition descriptor is keyed by node id and the\n // row's reconciliation key is derived separately.\n registerTransition(graph, itemNode, options.itemTransition);\n return itemNode;\n };\n\n // Lazy reconciliation plan (spec §15 — the measured keyed-list hot path).\n //\n // Instead of eagerly rebuilding all N item GraphNodes (and hashing every item\n // with JSON.stringify) on *every* emission — the dominant cost of the old\n // `buildAll` path — the renderer receives lightweight descriptors and only\n // materialises a subtree for rows that are genuinely new or whose data\n // actually changed. `key` is cheap (identity only); `sig()` and `build()` are\n // thunks the reconciler calls on demand.\n const buildPlan = (raw: unknown): ListPlanEntry[] => {\n const arr = Array.isArray(raw) ? (raw as T[]) : [];\n const plan: ListPlanEntry[] = new Array(arr.length);\n for (let i = 0; i < arr.length; i++) {\n const item = arr[i]!;\n const index = i;\n plan[i] = {\n key: reactiveListItemKey(item, index),\n item,\n sig: () => reactiveListItemSignature(item),\n build: () => buildItem(item, index),\n };\n }\n return plan;\n };\n graph.registerHandler(`__listplan__${node.id}`, buildPlan as unknown as () => unknown);\n\n // Build the initial children into the graph so the first mount renders them.\n const current = isSignal(items)\n ? (items as ReadonlySignal<T[]>).peek()\n : (items as unknown as T[]);\n const initial = Array.isArray(current) ? current : [];\n initial.forEach((item, i) => {\n node.appendChild(buildItem(item, i));\n });\n }\n\n form(key: string, builder: FormBuilder, options: FormOptions = {}): void {\n const props: Props = containerProps(options);\n const node = this._graph.createNode('form', {\n key,\n parent: this._node,\n props,\n });\n registerTransition(this._graph, node, options.transition);\n if (options.onSubmit !== undefined) {\n const handlerKey = `submit:${node.id}`;\n this._graph.registerHandler(handlerKey, options.onSubmit as () => unknown);\n node.addEvent({ type: 'submit', handlerKey });\n }\n builder(new FormBuilderImpl(node, this._graph));\n }\n\n when(\n condition: Bindable<boolean>,\n builder: ContainerBuilderFn,\n elseBuilder?: ContainerBuilderFn,\n options: WhenOptions = {},\n ): void {\n const graph = this._graph;\n // A dedicated 'conditional' node reuses the reactive-list reconciliation\n // machinery (same signal subscription + keyed reconcile) but renders as a\n // neutral <div> rather than a <ul>. It holds zero or one child branch.\n const node = graph.createNode('conditional', {\n parent: this._node,\n props: containerProps({}),\n });\n\n // A transition on a `when` applies to whichever branch is mounted/removed\n // (§2). `appear` promotes the transition to a config that also animates the\n // branch present on the very first mount; the renderer distinguishes appear\n // from a reactive enter via the descriptor's `appear` flag.\n const branchTransition: TransitionConfig | undefined =\n options.transition !== undefined && options.appear === true\n ? { ...options.transition, appear: true }\n : options.transition;\n\n // Build the active branch as a single keyed container. Distinct keys for the\n // then/else branches make a flip a clean swap under the keyed reconciler.\n const buildBranch = (build: ContainerBuilderFn, tag: 'then' | 'else'): GraphNode => {\n const branchKey = `when-${tag}:${node.id}`;\n const branch = graph.createNode('container', {\n key: branchKey,\n props: { key: branchKey },\n });\n registerTransition(graph, branch, branchTransition);\n build(new ContainerBuilderImpl(branch, graph));\n return branch;\n };\n\n const buildAll = (raw: unknown): GraphNode[] => {\n if (raw) return [buildBranch(builder, 'then')];\n return elseBuilder !== undefined ? [buildBranch(elseBuilder, 'else')] : [];\n };\n\n if (isSignal(condition)) {\n const signalId = `${node.id}:items`;\n node.stateRefs.push({ signalId, propKey: 'items' });\n graph.registerHandler(`__signal__${signalId}`, condition as unknown as () => unknown);\n graph.registerHandler(`__listbuild__${node.id}`, buildAll as unknown as () => unknown);\n const current = (condition as ReadonlySignal<boolean>).peek();\n for (const child of buildAll(current)) node.appendChild(child);\n } else {\n // Static condition — resolve once at build time, no reactive wiring.\n for (const child of buildAll(condition)) node.appendChild(child);\n }\n }\n\n errorBoundary(\n id: string,\n builder: ContainerBuilderFn,\n options: ErrorBoundaryOptions,\n ): void {\n // Normalise the observed error source(s) into an array.\n const sources: ErrorSource[] =\n options.source === undefined\n ? []\n : Array.isArray(options.source)\n ? [...options.source]\n : [options.source];\n\n // The boundary's own captured error (from a synchronous build throw) and a\n // retry nonce that forces a re-evaluation even when the boolean is unchanged.\n const localError = signal<unknown>(undefined);\n const retryNonce = signal<number>(0);\n\n const readError = (): unknown => {\n const local = localError.peek();\n if (local !== undefined && local !== null) return local;\n for (const s of sources) {\n const e = s.peek();\n if (e !== undefined && e !== null) return e;\n }\n return undefined;\n };\n\n // Reactive condition: true while an error is present. Reads every input so a\n // change in any source (or a retry) re-runs the conditional.\n const hasError = derived<boolean>(() => {\n retryNonce.get();\n localError.get();\n for (const s of sources) s.get();\n return readError() !== undefined;\n });\n\n const retry = (): void => {\n localError.set(undefined);\n options.onRetry?.();\n // Force the body branch to re-attempt even if no observed value changed.\n retryNonce.update((n) => n + 1);\n };\n\n // Wrap in a container so the whole boundary is addressable and disposes as a\n // unit. `when` provides the reactive body↔fallback swap (and its cleanup).\n this.container(id, (c) => {\n c.when(\n hasError,\n // Error state → fallback. The fallback branch mounts exactly when the\n // boundary enters its error state, so this is also where the optional\n // `onError` reporting hook fires (observe-only; §6/§7).\n (fb) => {\n const currentError = readError();\n options.onError?.(currentError);\n options.fallback(fb, currentError, retry);\n },\n // Healthy state → body, guarded against synchronous build throws.\n (body) => {\n try {\n builder(body);\n } catch (err) {\n // Surface the throw as the boundary's error on the next microtask\n // (deferred to avoid re-entrant reconciliation during this build).\n queueMicrotask(() => localError.set(err));\n }\n },\n );\n }, { id });\n }\n\n asyncBoundary<T>(\n key: string,\n res: Resource<T>,\n branches: AsyncBoundaryBranches<T>,\n ): void {\n // Pure sugar over `resource` + `when` — no second async system, no new node\n // type, no renderer wiring. Three mutually-exclusive, exhaustive reactive\n // conditions select the live branch. Error wins; then resolved data (kept\n // visible during a refetch); then loading/idle.\n const isError = derived<boolean>(() => res.status.get() === 'error');\n const showSuccess = derived<boolean>(\n () => res.status.get() !== 'error' && res.data.get() !== undefined,\n );\n const showLoading = derived<boolean>(\n () => res.status.get() !== 'error' && res.data.get() === undefined,\n );\n // Narrow the data signal to `T` for the success branch. Only read inside the\n // success branch, where `data` is guaranteed present.\n const dataSignal = derived<T>(() => res.data.get() as T);\n const retry = (): void => {\n void res.refetch();\n };\n\n this.container(key, (c) => {\n c.when(isError, (fb) => branches.error?.(fb, res.error.peek(), retry));\n c.when(showSuccess, (sb) => branches.success(sb, dataSignal));\n c.when(showLoading, (lb) => branches.loading?.(lb));\n }, { key });\n }\n\n // ── Portals & overlays ──────────────────────────────────────────────────────\n\n portal(key: string, builder: ContainerBuilderFn, options: PortalOptions = {}): void {\n const node = this._graph.createNode('portal', {\n key,\n parent: this._node,\n props: containerProps(options),\n });\n builder(new ContainerBuilderImpl(node, this._graph));\n }\n\n /**\n * Declare document metadata (2.0 §1–§3). Creates a `'head'` node — a neutral,\n * empty inline anchor at this position (one node / one element, so positional\n * hydration is preserved) — and registers a `__head__<id>` descriptor holding\n * this call's normalized, dedup-keyed {@link resolveHead} contribution. The\n * renderer applies it to `document.head` on the browser (adopting server tags\n * on hydration, cleaning up on unmount / route change) and emits the active\n * graph's merged metadata as a string on the server (`renderHead`).\n *\n * Multiple `head()` nodes may be live at once (app default + route + component)\n * — the renderer merges them and, per dedup key, the last in document order\n * wins (see head.ts). No new render path: this reuses the same graph-node +\n * handler-registry convention as overlays/transitions/components.\n */\n head(metadata: HeadMetadata): void {\n const node = this._graph.createNode('head', {\n parent: this._node,\n props: { 'data-streetui-head-anchor': '' },\n });\n const contribution = resolveHead(metadata);\n this._graph.registerHandler(\n `__head__${node.id}`,\n (() => contribution) as unknown as () => unknown,\n );\n }\n\n /**\n * Shared assembly for every overlay kind: a `portal` node whose single child\n * is a `when(open, panel)` conditional. The panel container carries the\n * kind's ARIA semantics; `builder` fills it. An `__overlay__<portalId>`\n * descriptor is registered so the renderer wires focus/keyboard behavior to\n * the same `open` signal that drives the panel. Reuses existing primitives\n * (portal + when + container) — no new render path.\n */\n private _overlay(\n kind: OverlayKindConfig,\n key: string,\n options: OverlayOptions,\n builder: ContainerBuilderFn,\n ): void {\n const graph = this._graph;\n const portalNode = graph.createNode('portal', {\n key,\n parent: this._node,\n props: { key },\n });\n\n // Resolve `open` to a signal we can both bind (drives the panel's `when`)\n // and hand to the renderer (drives focus behavior). A literal is wrapped so\n // the panel still mounts/unmounts through the same reactive path.\n const openBindable = options.open;\n const openSignal: ReadonlySignal<boolean> = isSignal(openBindable)\n ? (openBindable as ReadonlySignal<boolean>)\n : signal(openBindable as boolean);\n\n // Panel a11y semantics (kind defaults, overridable via options).\n const panelOptions: ContainerOptions = {\n role: options.role ?? kind.role,\n ...(kind.ariaModal ? { ariaModal: true } : {}),\n ...(kind.ariaLive !== undefined ? { ariaLive: kind.ariaLive } : {}),\n ...(options.class !== undefined ? { class: options.class } : {}),\n ...(options.ariaLabel !== undefined ? { ariaLabel: options.ariaLabel } : {}),\n ...(options.ariaLabelledBy !== undefined ? { ariaLabelledBy: options.ariaLabelledBy } : {}),\n ...(options.ariaDescribedBy !== undefined ? { ariaDescribedBy: options.ariaDescribedBy } : {}),\n };\n\n const portalBuilder = new ContainerBuilderImpl(portalNode, graph);\n portalBuilder.when(\n openSignal,\n (panelHost) => {\n panelHost.container(`${key}__panel`, builder, panelOptions);\n },\n undefined,\n // Overlay open/close rides the panel's `when`; a transition animates the\n // panel in on open and — via the reconciler's deferred-leave — plays the\n // leave before the panel is removed (§10). Focus is restored at close-\n // request time (see wireOverlayBehavior), so it never stays trapped inside\n // a panel that is animating away.\n options.transition !== undefined ? { transition: options.transition } : {},\n );\n\n const descriptor: OverlayBehaviorDescriptor = {\n open: openSignal,\n modal: kind.modal,\n takesFocus: kind.takesFocus,\n menu: kind.menu ?? false,\n closeOnEscape: options.closeOnEscape ?? kind.defaultCloseOnEscape,\n restoreFocus: options.restoreFocus ?? kind.defaultRestoreFocus,\n ...(options.initialFocusId !== undefined ? { initialFocusId: options.initialFocusId } : {}),\n ...(options.onClose !== undefined ? { onClose: options.onClose } : {}),\n };\n graph.registerHandler(\n `__overlay__${portalNode.id}`,\n (() => descriptor) as unknown as () => unknown,\n );\n }\n\n dialog(key: string, options: OverlayOptions, builder: ContainerBuilderFn): void {\n this._overlay(OVERLAY_KINDS.dialog, key, options, builder);\n }\n\n popover(key: string, options: OverlayOptions, builder: ContainerBuilderFn): void {\n this._overlay(OVERLAY_KINDS.popover, key, options, builder);\n }\n\n tooltip(key: string, options: OverlayOptions, builder: ContainerBuilderFn): void {\n this._overlay(OVERLAY_KINDS.tooltip, key, options, builder);\n }\n\n dropdown(key: string, options: OverlayOptions, builder: ContainerBuilderFn): void {\n this._overlay(OVERLAY_KINDS.dropdown, key, options, builder);\n }\n\n toast(key: string, options: OverlayOptions, builder: ContainerBuilderFn): void {\n this._overlay(OVERLAY_KINDS.toast, key, options, builder);\n }\n\n // ── Components ────────────────────────────────────────────────────────────\n\n /**\n * Instantiate a reusable component (§3–§9). Creates a `'component'` node\n * (rendered as a `<div>` wrapper — preserves the one-node/one-element\n * positional-hydration invariant), then runs `def.setup(props, ctx)`\n * synchronously to obtain the render function and fills the component's own\n * container scope with it — structurally identical to `container`/\n * `errorBoundary`. Cleanups the setup registers via `ctx.effect`/\n * `ctx.onCleanup` are collected into a closure and exposed to the renderer\n * through a `__component__<id>` handler (mirroring `__overlay__`); the mount/\n * hydrate paths read it and route each into `NodeInstance.trackCleanup`, so\n * teardown runs (children-first) when the component leaves the graph.\n *\n * `setup` runs once per instance here at build time. When this component sits\n * inside a keyed list / conditional, a rebuild disposes the old instance\n * (running its cleanups + pruning its `__component__` entry) and re-runs this\n * method for the new node — so re-invocation is safe and leak-free.\n */\n component<P>(\n key: string,\n def: ComponentDefinition<P>,\n props: P,\n children?: ContainerBuilderFn,\n ): void {\n const graph = this._graph;\n const node = graph.createNode('component', {\n key,\n parent: this._node,\n // `data-streetui-component` is a non-underscore prop, so it reaches the\n // DOM as an attribute and is visible to DevTools (§21) — unlike the\n // internal `_`-prefixed metadata the renderer hides.\n props: { key, 'data-streetui-component': def.name },\n });\n\n // Ownership collector: every teardown the setup registers lands here and is\n // handed to the NodeInstance at mount.\n const cleanups: Array<() => void> = [];\n const ctx: ComponentContext = {\n key,\n onCleanup(fn: () => void): void {\n cleanups.push(fn);\n },\n effect(fn: () => void | (() => void)): void {\n // Reuse the EXISTING reactive engine (§8) — no new reactivity. The\n // effect runs immediately (build time, like errorBoundary's derived);\n // its unsubscribe is owned by this component.\n cleanups.push(effect(fn));\n },\n renderChildren(content: ContainerDSL): void {\n if (children !== undefined) children(content);\n },\n };\n\n // Run setup to get the render function, guarding a synchronous throw the\n // same way errorBoundary does (defer so we never re-enter reconciliation\n // during this build). A component wrapped in an errorBoundary still surfaces\n // the error through the boundary's observed sources.\n let render: ComponentRender;\n try {\n render = def.setup(props, ctx);\n render(new ContainerBuilderImpl(node, graph));\n } catch (err) {\n queueMicrotask(() => {\n throw err;\n });\n }\n\n if (cleanups.length > 0) {\n graph.registerHandler(\n `__component__${node.id}`,\n (() => cleanups) as unknown as () => unknown,\n );\n }\n }\n}\n\n// ── Concrete builder implementations ─────────────────────────────────────────\n\nexport class SectionBuilderImpl extends ContainerBuilderBase implements SectionDSL {}\nexport class ContainerBuilderImpl extends ContainerBuilderBase implements ContainerDSL {}\nexport class FormBuilderImpl extends ContainerBuilderBase implements FormDSL {}\n\nexport class ListBuilderImpl extends ContentBuilderBase implements ListDSL {\n item(key: string, builder: ContainerBuilderFn, options: ContainerOptions = {}): void {\n const node = this._graph.createNode('list-item', {\n key,\n parent: this._node,\n props: containerProps(options),\n });\n registerTransition(this._graph, node, options.transition);\n builder(new ContainerBuilderImpl(node, this._graph));\n }\n}\n\nexport class PageBuilderImpl extends ContainerBuilderBase implements PageDSL {}\n\n// ── App builder ───────────────────────────────────────────────────────────────\n\nexport class AppBuilder implements AppDSL {\n constructor(private readonly _graph: ApplicationGraph) {}\n\n page(key: string, builder: PageBuilder): void {\n const node = this._graph.createNode('page', {\n key,\n parent: this._graph.root,\n props: { key },\n });\n builder(new PageBuilderImpl(node, this._graph));\n }\n}\n","/**\n * First-class StreetUI-native components (§3–§9).\n *\n * A component is a *reusable unit that owns its own local state and lifecycle*.\n * It is NOT a virtual-DOM element, a second reactive system, or a second\n * renderer. It compiles into the EXISTING pipeline: `container.component(...)`\n * creates a reserved `'component'` GraphNode (already a `SemanticNodeType`,\n * already mapped to `<div>`), runs the component's `setup` synchronously during\n * the same build-time descent every other builder uses, and routes any cleanups\n * the setup registers into the node's `NodeInstance` at mount (so they run,\n * children-first, when the component leaves the graph).\n *\n * Design (derived from the existing DSL architecture, not copied from React/Vue):\n *\n * const UserCard = component<{ name: Signal<string> }>((props, ctx) => {\n * // ── setup: runs ONCE per instance, at build time ──\n * const open = signal(false);\n * ctx.effect(() => { ... }); // auto-disposed on unmount\n * ctx.onCleanup(() => { ... }); // explicit teardown hook\n * // ── render: fills the component's own container scope ──\n * return (content) => {\n * content.text(props.name); // fine-grained: signal prop, no re-setup\n * content.when(open, (c) => c.text('expanded'));\n * ctx.renderChildren(content); // where slotted children go (§6)\n * };\n * }, { name: 'UserCard' });\n *\n * page.component('card-1', UserCard, { name }, (slot) => slot.text('child'));\n *\n * Props are ordinary typed values (§5 — typing is a TypeScript concern, no\n * runtime schema). Passing a `Signal<T>` prop and binding it in the render body\n * gives fine-grained updates (§13) WITHOUT re-running `setup`: only the bound\n * node mutates when the signal changes. `setup` re-runs only when the component\n * is genuinely rebuilt (removed + re-created by a keyed list / conditional),\n * at which point the previous instance is disposed first — so cleanup stays\n * correct.\n */\n\nimport type { ContainerDSL, ContainerBuilder } from './dsl-types.js';\n\n/**\n * The render half of a component: fills the component's own container scope.\n * Returned by `setup` so that per-instance state created in `setup` is captured\n * by closure and the render body can read it.\n */\nexport type ComponentRender = (content: ContainerDSL) => void;\n\n/**\n * Lifecycle + composition surface handed to a component's `setup`. Local\n * reactive state is created with the EXISTING `signal`/`derived`/`effect`/\n * `batch` primitives (§8) — `ctx` only adds ownership: anything registered here\n * is torn down automatically when the component leaves the graph (§9).\n */\nexport interface ComponentContext {\n /** This instance's stable identity key (the `key` passed at the call site). */\n readonly key: string;\n /**\n * Register a teardown callback. Runs when the component unmounts (children\n * first, then this — mirroring `NodeInstance.dispose`). Use for resources,\n * `form.dispose`, subscriptions, timers, etc.\n */\n onCleanup(fn: () => void): void;\n /**\n * Run a reactive effect owned by this component. Wraps the framework's\n * `effect()`; the returned unsubscribe is auto-tracked and disposed on\n * unmount, so component effects never leak (the pain point the audit ranked\n * #1). The effect may itself return a cleanup, exactly like `effect()`.\n */\n effect(fn: () => void | (() => void)): void;\n /**\n * Render the caller-supplied children into `content` at this point (§6 native\n * child composition / slots). No-op when the call site passed no children.\n * Call it wherever the component wants its slotted content to appear.\n */\n renderChildren(content: ContainerDSL): void;\n}\n\n/**\n * A component's setup function: receives typed props and the lifecycle context,\n * creates any local state, and returns the render function. Runs synchronously\n * during the build-time descent (like `errorBoundary`'s callback), so it must be\n * SSR-safe — on the server it runs at render time and its cleanups run when the\n * SSR root is disposed.\n */\nexport type ComponentSetup<P> = (props: P, ctx: ComponentContext) => ComponentRender;\n\n/**\n * The opaque, reusable definition produced by `component(...)`. Carries the\n * `setup` and an inspectable `name`; the brand lets the builder method (and\n * DevTools) recognise a definition at runtime without a class.\n */\nexport interface ComponentDefinition<P> {\n readonly __streetui_component: true;\n readonly name: string;\n readonly setup: ComponentSetup<P>;\n}\n\n/**\n * Define a reusable component. Returns a `ComponentDefinition` you render with\n * `container.component(key, def, props, children?)`. This is a pure factory — it\n * builds no graph and runs no `setup`; instantiation happens per call site.\n *\n * @param setup Runs once per instance: create local state, return the render fn.\n * @param options.name Human-readable name for DevTools/`data-streetui-component`.\n */\nexport function component<P = Record<string, never>>(\n setup: ComponentSetup<P>,\n options: { name?: string } = {},\n): ComponentDefinition<P> {\n return {\n __streetui_component: true,\n name: options.name ?? setup.name ?? 'Component',\n setup,\n };\n}\n\n/** Runtime guard: is `value` a component definition? */\nexport function isComponentDefinition(value: unknown): value is ComponentDefinition<unknown> {\n return (\n value !== null &&\n typeof value === 'object' &&\n (value as { __streetui_component?: unknown }).__streetui_component === true\n );\n}\n\nexport type { ContainerBuilder as ComponentChildren };\n","/**\n * StreetUI DSL entry point.\n *\n * Usage:\n * import { streetui } from '@streetui/dsl';\n *\n * const app = streetui.app({ name: 'My App' });\n * app.page('home', page => {\n * page.section('hero', section => {\n * section.heading('Welcome');\n * section.button('Click me', { onClick: () => {} });\n * });\n * });\n *\n * const graph = app.build();\n */\n\nimport { ApplicationGraph } from '@streetui/graph';\nimport { AppBuilder } from './builders.js';\n\nexport interface AppOptions {\n readonly name: string;\n readonly version?: string;\n}\n\nexport class StreetApp {\n private readonly _graph: ApplicationGraph;\n private readonly _builder: AppBuilder;\n\n constructor(options: AppOptions) {\n const graphOpts: { name: string; version?: string } = { name: options.name };\n if (options.version !== undefined) graphOpts.version = options.version;\n this._graph = new ApplicationGraph(graphOpts);\n this._builder = new AppBuilder(this._graph);\n }\n\n page(key: string, builder: Parameters<AppBuilder['page']>[1]): this {\n this._builder.page(key, builder);\n return this;\n }\n\n /** Compile to ApplicationGraph — validates and returns the graph. */\n build(): ApplicationGraph {\n const dc = this._graph.validate();\n dc.throwIfErrors();\n return this._graph;\n }\n\n /** Access graph before building (useful for inspection). */\n get graph(): ApplicationGraph {\n return this._graph;\n }\n}\n\nexport interface StreetUI {\n app(options: AppOptions): StreetApp;\n}\n\nexport const streetui: StreetUI = {\n app(options: AppOptions): StreetApp {\n return new StreetApp(options);\n },\n};\n","/**\n * Compiler-phase validation of the ApplicationGraph.\n *\n * This runs after the DSL has built the graph but before the runtime\n * receives a CompiledApplication. More checks live here than in the\n * graph's own validate() because the compiler has broader context.\n */\n\nimport { DiagnosticCollector } from '@streetui/core';\nimport { ApplicationGraph, GraphNode } from '@streetui/graph';\n\nexport function validateGraph(graph: ApplicationGraph): DiagnosticCollector {\n const dc = new DiagnosticCollector();\n\n // Merge built-in graph validations\n dc.merge(graph.validate());\n\n // Must have at least one page\n const pages = graph.findByType('page');\n if (pages.length === 0) {\n dc.warn(\n 'COMPILER_NO_PAGES',\n 'Application has no pages defined. At least one page is recommended.',\n );\n }\n\n // Walk and validate individual nodes\n graph.walk((node) => {\n validateNode(node, dc);\n });\n\n return dc;\n}\n\nfunction validateNode(node: GraphNode, dc: DiagnosticCollector): void {\n switch (node.type) {\n case 'heading': {\n const text = node.getProp('text');\n if (text === undefined || text === '') {\n dc.warn('COMPILER_EMPTY_HEADING', `Heading node \"${node.id}\" has no text content`, {\n nodeId: node.id,\n });\n }\n break;\n }\n case 'image': {\n const src = node.getProp('src');\n const alt = node.getProp('alt');\n if (!src) {\n dc.error('COMPILER_IMAGE_NO_SRC', `Image node \"${node.id}\" is missing src`, {\n nodeId: node.id,\n });\n }\n if (!alt) {\n dc.warn('COMPILER_IMAGE_NO_ALT', `Image node \"${node.id}\" is missing alt text`, {\n nodeId: node.id,\n });\n }\n break;\n }\n case 'link': {\n const href = node.getProp('href');\n if (!href) {\n dc.error('COMPILER_LINK_NO_HREF', `Link node \"${node.id}\" is missing href`, {\n nodeId: node.id,\n });\n }\n break;\n }\n default:\n break;\n }\n}\n","/**\n * Graph transformation pass.\n *\n * After validation, the transformer prepares the graph for the runtime by:\n * - Resolving implicit defaults (e.g. heading level defaults to 1)\n * - Normalizing prop names\n * - Assigning deterministic render keys where missing\n * - Flattening / hoisting where beneficial\n */\n\nimport { ApplicationGraph, GraphNode } from '@streetui/graph';\n\nexport function transformGraph(graph: ApplicationGraph): void {\n graph.walk((node, depth) => {\n applyDefaults(node);\n ensureRenderKey(node, depth);\n });\n}\n\nfunction applyDefaults(node: GraphNode): void {\n switch (node.type) {\n case 'heading': {\n if (node.getProp('level') === undefined) {\n node.setProp('level', 1);\n }\n break;\n }\n case 'input': {\n if (node.getProp('inputType') === undefined) {\n node.setProp('inputType', 'text');\n }\n break;\n }\n case 'link': {\n if (node.getProp('external') === undefined) {\n node.setProp('external', false);\n }\n break;\n }\n default:\n break;\n }\n}\n\nfunction ensureRenderKey(node: GraphNode, depth: number): void {\n if (node.getProp('_renderKey') === undefined) {\n const key = node.key ?? `${node.type}:${node.id}:${depth}`;\n node.setProp('_renderKey', key);\n }\n}\n","/**\n * StreetUI compiler entry point.\n *\n * Pipeline:\n * StreetApp (DSL)\n * → ApplicationGraph (build)\n * → validate\n * → transform\n * → CompiledApplication\n */\n\nimport { DiagnosticCollector } from '@streetui/core';\nimport { type ApplicationGraph } from '@streetui/graph';\nimport { type StreetApp } from '@streetui/dsl';\nimport { validateGraph } from './validation/validator.js';\nimport { transformGraph } from './transform/transform.js';\n\nexport interface CompiledApplication {\n /** The fully built, validated, and transformed graph. */\n readonly graph: ApplicationGraph;\n /** Diagnostics accumulated during compilation. */\n readonly diagnostics: DiagnosticCollector;\n /** Metadata */\n readonly name: string;\n readonly version: string;\n readonly compiledAt: number;\n}\n\nexport interface CompileOptions {\n /** If true, compilation throws on errors. Defaults to true. */\n readonly strict?: boolean;\n /** If true, also throw on warnings. Defaults to false. */\n readonly strictWarnings?: boolean;\n}\n\n/**\n * Compile a StreetApp DSL definition into a CompiledApplication\n * ready for the runtime to execute.\n */\nexport function compile(\n app: StreetApp,\n options: CompileOptions = {},\n): CompiledApplication {\n const strict = options.strict ?? true;\n const strictWarnings = options.strictWarnings ?? false;\n const dc = new DiagnosticCollector();\n\n // 1. Build the graph from the DSL\n const graph = app.graph;\n\n // 2. Validate\n const validationDc = validateGraph(graph);\n dc.merge(validationDc);\n\n if (strict && dc.hasErrors) {\n dc.throwIfErrors();\n }\n if (strictWarnings && dc.hasWarnings) {\n throw new Error(\n `[StreetUI Compiler] Compilation failed: warnings treated as errors.\\n` +\n dc.diagnostics\n .filter(d => d.severity === 'warning')\n .map(d => ` [${d.code}] ${d.message}`)\n .join('\\n'),\n );\n }\n\n // 3. Transform\n transformGraph(graph);\n\n return {\n graph,\n diagnostics: dc,\n name: graph.name,\n version: graph.version,\n compiledAt: Date.now(),\n };\n}\n\n/**\n * Compile from a pre-built ApplicationGraph (used when the graph\n * was constructed programmatically rather than through the DSL).\n */\nexport function compileGraph(\n graph: ApplicationGraph,\n options: CompileOptions = {},\n): CompiledApplication {\n const strict = options.strict ?? true;\n const dc = new DiagnosticCollector();\n\n const validationDc = validateGraph(graph);\n dc.merge(validationDc);\n\n if (strict && dc.hasErrors) {\n dc.throwIfErrors();\n }\n\n transformGraph(graph);\n\n return {\n graph,\n diagnostics: dc,\n name: graph.name,\n version: graph.version,\n compiledAt: Date.now(),\n };\n}\n","/**\n * RuntimeNodeInstance — the runtime's live representation of a GraphNode.\n *\n * Each GraphNode in the compiled application gets a corresponding\n * RuntimeNodeInstance during mounting. The instance owns:\n * - the DOM node(s) produced for this graph node\n * - all signal subscriptions that drive updates\n * - all DOM event listeners\n * - child instances\n */\n\nimport { CleanupRegistry } from '@streetui/core';\nimport type { GraphNode } from '@streetui/graph';\nimport type { Signal, ReadonlySignal } from '@streetui/state';\n\nexport interface NodeInstanceOptions {\n readonly graphNode: GraphNode;\n readonly domNode: Node;\n}\n\nexport class RuntimeNodeInstance {\n readonly graphNode: GraphNode;\n domNode: Node;\n readonly children: RuntimeNodeInstance[] = [];\n readonly cleanup: CleanupRegistry = new CleanupRegistry();\n private _mounted = false;\n\n constructor(options: NodeInstanceOptions) {\n this.graphNode = options.graphNode;\n this.domNode = options.domNode;\n }\n\n get isMounted(): boolean {\n return this._mounted;\n }\n\n mount(): void {\n this._mounted = true;\n }\n\n unmount(): void {\n if (!this._mounted) return;\n this._mounted = false;\n for (const child of this.children) {\n child.unmount();\n }\n this.cleanup.run();\n }\n\n addChild(instance: RuntimeNodeInstance): void {\n this.children.push(instance);\n }\n\n /** Subscribe to a signal and register the unsubscribe for cleanup. */\n trackSignal<T>(\n signal: Signal<T> | ReadonlySignal<T>,\n handler: (value: T) => void,\n ): void {\n const unsub = signal.subscribe(handler);\n this.cleanup.add(unsub);\n }\n\n /** Register an arbitrary cleanup function (e.g. DOM event removal). */\n trackCleanup(fn: () => void): void {\n this.cleanup.add(fn);\n }\n}\n","/**\n * StreetUI update scheduler.\n *\n * Responsibilities:\n * - Queue update callbacks\n * - Batch synchronous enqueues into a single microtask flush\n * - Guarantee ordering: higher priority jobs flush first\n * - Prevent duplicate work for the same job key\n * - Allow synchronous flush for tests\n */\n\nexport type Priority = 'immediate' | 'normal' | 'idle';\n\nconst PRIORITY_ORDER: Record<Priority, number> = {\n immediate: 0,\n normal: 1,\n idle: 2,\n};\n\nexport interface Job {\n /** Unique key — if another job with the same key is already queued, it is replaced. */\n readonly key: string;\n readonly priority: Priority;\n readonly fn: () => void;\n}\n\n/**\n * Optional error-reporting hook (v0.9 §26/§27). Structurally compatible with\n * `@streetui/core`'s `DiagnosticSink` (the `error` method) so an application can\n * route swallowed scheduler-job failures through its own logger instead of the\n * default `console.error`. Kept as a local structural type so the scheduler\n * stays dependency-free; no network, no telemetry. When unset, behaviour is\n * exactly as before.\n */\nexport interface SchedulerDiagnostics {\n error?(message: string, context?: unknown): void;\n}\n\nexport class Scheduler {\n private readonly _queue: Map<string, Job> = new Map();\n private _flushScheduled = false;\n private _flushing = false;\n private _diagnostics: SchedulerDiagnostics | undefined = undefined;\n\n /**\n * Install an optional diagnostic sink for swallowed job errors. Pass\n * `undefined` to restore the default `console.error` reporting. Additive and\n * opt-in — the scheduler never sends anything anywhere on its own.\n */\n setDiagnostics(sink: SchedulerDiagnostics | undefined): void {\n this._diagnostics = sink;\n }\n\n /** Total jobs currently queued. */\n get size(): number {\n return this._queue.size;\n }\n\n /** True if a flush has been scheduled but not yet executed. */\n get isPending(): boolean {\n return this._flushScheduled;\n }\n\n /**\n * Enqueue a job. If a job with the same key exists, the new one replaces it\n * (allowing callers to coalesce repeated updates for the same node).\n */\n schedule(job: Job): void {\n this._queue.set(job.key, job);\n if (!this._flushScheduled && !this._flushing) {\n this._flushScheduled = true;\n this._scheduleMicrotask();\n }\n }\n\n /** Schedule multiple jobs atomically. */\n scheduleAll(jobs: readonly Job[]): void {\n for (const job of jobs) {\n this._queue.set(job.key, job);\n }\n if (!this._flushScheduled && !this._flushing && this._queue.size > 0) {\n this._flushScheduled = true;\n this._scheduleMicrotask();\n }\n }\n\n /**\n * Cancel a queued job by key. No-op if not queued.\n */\n cancel(key: string): void {\n this._queue.delete(key);\n }\n\n /**\n * Synchronously flush all queued jobs (sorted by priority).\n * Useful in tests and for immediate rendering.\n */\n flush(): void {\n if (this._flushing) return;\n this._flushScheduled = false;\n this._flushing = true;\n\n const jobs = Array.from(this._queue.values()).sort(\n (a, b) => PRIORITY_ORDER[a.priority] - PRIORITY_ORDER[b.priority],\n );\n this._queue.clear();\n\n try {\n for (const job of jobs) {\n try {\n job.fn();\n } catch (err) {\n // Isolate job failures — report and continue so remaining jobs still run.\n if (this._diagnostics?.error) {\n this._diagnostics.error(`Scheduler job \"${job.key}\" threw`, err);\n } else {\n console.error(`[Scheduler] Job \"${job.key}\" threw:`, err);\n }\n }\n }\n } finally {\n this._flushing = false;\n }\n }\n\n /** Clear all pending jobs without executing them. */\n clear(): void {\n this._queue.clear();\n this._flushScheduled = false;\n }\n\n private _scheduleMicrotask(): void {\n Promise.resolve().then(() => {\n if (this._flushScheduled) {\n this.flush();\n }\n });\n }\n}\n\n/** The shared global scheduler instance. */\nexport const scheduler = new Scheduler();\n\n/** Convenience: schedule a normal-priority job. */\nexport function scheduleUpdate(key: string, fn: () => void): void {\n scheduler.schedule({ key, priority: 'normal', fn });\n}\n\n/** Convenience: schedule an immediate-priority job. */\nexport function scheduleImmediate(key: string, fn: () => void): void {\n scheduler.schedule({ key, priority: 'immediate', fn });\n}\n\n/** Convenience: flush the global scheduler synchronously. */\nexport function flushSync(): void {\n scheduler.flush();\n}\n","/**\n * StreetUI Runtime.\n *\n * Owns:\n * - Signal binding — wires signal subscriptions to renderer update calls\n * - Event dispatch — calls registered handlers from graph events\n * - Lifecycle — orchestrates mount, update cycles, unmount\n *\n * The runtime does NOT create DOM nodes. It calls into StreetRenderer\n * for all DOM operations.\n */\n\nimport { CleanupRegistry } from '@streetui/core';\nimport type { GraphNode, ApplicationGraph } from '@streetui/graph';\nimport type { Signal, ReadonlySignal } from '@streetui/state';\nimport { Scheduler } from '@streetui/scheduler';\nimport type { CompiledApplication } from '@streetui/compiler';\nimport type { StreetRenderer, RenderHandle } from './renderer-interface.js';\n\nexport interface RuntimeOptions {\n readonly renderer: StreetRenderer;\n readonly scheduler?: Scheduler;\n}\n\nexport interface MountedApplication {\n readonly renderHandle: RenderHandle;\n readonly runtime: Runtime;\n unmount(): void;\n flush(): void;\n}\n\nexport class Runtime {\n private readonly _renderer: StreetRenderer;\n private readonly _scheduler: Scheduler;\n private readonly _cleanup: CleanupRegistry = new CleanupRegistry();\n private _renderHandle: RenderHandle | null = null;\n private _mounted = false;\n\n constructor(options: RuntimeOptions) {\n this._renderer = options.renderer;\n this._scheduler = options.scheduler ?? new Scheduler();\n }\n\n get isMounted(): boolean {\n return this._mounted;\n }\n\n /**\n * Mount the compiled application into the given DOM container.\n */\n mount(compiled: CompiledApplication, container: Element): MountedApplication {\n if (this._mounted) {\n throw new Error('[Runtime] Already mounted. Call unmount() first.');\n }\n\n // Hand off to renderer — it creates all DOM nodes\n this._renderHandle = this._renderer.mount(compiled, container);\n this._mounted = true;\n\n // Wire signal subscriptions from the graph\n this._bindSignals(compiled.graph);\n\n const self = this;\n return {\n renderHandle: this._renderHandle,\n runtime: this,\n unmount() { self.unmount(); },\n flush() { self._scheduler.flush(); },\n };\n }\n\n unmount(): void {\n if (!this._mounted) return;\n this._mounted = false;\n this._renderHandle?.unmount();\n this._renderHandle = null;\n this._cleanup.run();\n }\n\n /**\n * Hydrate a container that already holds server-rendered HTML for this\n * application. Delegates to the renderer's `hydrate` (adopting the existing\n * DOM instead of recreating it) and falls back to `mount` for renderers that\n * cannot hydrate. Signal binding is identical to `mount`, so the live client\n * lifecycle is established the same way.\n */\n hydrate(compiled: CompiledApplication, container: Element): MountedApplication {\n if (this._mounted) {\n throw new Error('[Runtime] Already mounted. Call unmount() first.');\n }\n\n this._renderHandle = this._renderer.hydrate !== undefined\n ? this._renderer.hydrate(compiled, container)\n : this._renderer.mount(compiled, container);\n this._mounted = true;\n\n this._bindSignals(compiled.graph);\n\n const self = this;\n return {\n renderHandle: this._renderHandle,\n runtime: this,\n unmount() { self.unmount(); },\n flush() { self._scheduler.flush(); },\n };\n }\n\n /**\n * Walk the graph and subscribe to all signal-bound nodes.\n * When a signal changes, schedule a renderer update for that node.\n */\n private _bindSignals(graph: ApplicationGraph): void {\n graph.walk((node) => {\n for (const stateRef of node.stateRefs) {\n const signalKey = `__signal__${stateRef.signalId}`;\n const maybeSignal = graph.getHandler(signalKey) as\n | (Signal<unknown> & ReadonlySignal<unknown>)\n | undefined;\n\n if (maybeSignal === undefined || typeof maybeSignal.subscribe !== 'function') continue;\n\n const unsub = maybeSignal.subscribe(() => {\n // Schedule a re-render update keyed to this node+prop\n this._scheduler.schedule({\n key: `update:${node.id}:${stateRef.propKey}`,\n priority: 'normal',\n fn: () => {\n // The renderer handles the actual DOM update\n this._renderHandle?.flush();\n },\n });\n });\n this._cleanup.add(unsub);\n }\n });\n }\n}\n\n/**\n * Convenience factory — create a runtime, mount, and return the handle.\n */\nexport function createRuntime(options: RuntimeOptions): Runtime {\n return new Runtime(options);\n}\n","/**\n * StreetUI event type catalogue.\n * Framework events are distinct from raw DOM events.\n */\n\nexport type StreetEventType =\n | 'click'\n | 'dblclick'\n | 'input'\n | 'change'\n | 'submit'\n | 'focus'\n | 'blur'\n | 'keydown'\n | 'keyup'\n | 'keypress'\n | 'mouseenter'\n | 'mouseleave'\n | 'mousemove'\n | 'mousedown'\n | 'mouseup'\n | 'pointerdown'\n | 'pointerup'\n | 'pointermove'\n | 'pointerenter'\n | 'pointerleave'\n | 'scroll'\n | 'resize'\n | 'mount'\n | 'unmount'\n | 'update';\n\nexport interface StreetEvent<T = unknown> {\n readonly type: StreetEventType | string;\n readonly target: unknown;\n readonly data: T | undefined;\n readonly originalEvent: Event | undefined;\n readonly timestamp: number;\n defaultPrevented: boolean;\n stopPropagation(): void;\n preventDefault(): void;\n}\n\nexport function createStreetEvent<T = unknown>(\n type: StreetEventType | string,\n target: unknown,\n data?: T,\n originalEvent?: Event,\n): StreetEvent<T> {\n let _stopped = false;\n const ev: StreetEvent<T> = {\n type,\n target,\n data: data as T | undefined,\n originalEvent: originalEvent as Event | undefined,\n timestamp: Date.now(),\n defaultPrevented: false,\n stopPropagation() { _stopped = true; },\n preventDefault() { ev.defaultPrevented = true; },\n };\n return ev;\n}\n\nexport type EventHandler<T = unknown> = (event: StreetEvent<T>) => void;\n","/**\n * Framework-internal event bus.\n * Decouples emitters from handlers across subsystems.\n */\n\nimport type { StreetEvent, EventHandler } from './event-types.js';\n\nexport class EventBus {\n private readonly _handlers: Map<string, Set<EventHandler>> = new Map();\n\n on<T = unknown>(type: string, handler: EventHandler<T>): () => void {\n let set = this._handlers.get(type);\n if (set === undefined) {\n set = new Set();\n this._handlers.set(type, set);\n }\n set.add(handler as EventHandler);\n return () => this.off(type, handler as EventHandler);\n }\n\n off<T = unknown>(type: string, handler: EventHandler<T>): void {\n this._handlers.get(type)?.delete(handler as EventHandler);\n }\n\n once<T = unknown>(type: string, handler: EventHandler<T>): () => void {\n const wrapped: EventHandler<T> = (event) => {\n handler(event);\n this.off(type, wrapped);\n };\n return this.on(type, wrapped);\n }\n\n emit<T = unknown>(event: StreetEvent<T>): void {\n const handlers = this._handlers.get(event.type);\n if (handlers === undefined) return;\n for (const h of handlers) {\n h(event as StreetEvent);\n }\n }\n\n clear(type?: string): void {\n if (type !== undefined) {\n this._handlers.delete(type);\n } else {\n this._handlers.clear();\n }\n }\n\n listenerCount(type: string): number {\n return this._handlers.get(type)?.size ?? 0;\n }\n}\n\nexport const globalEventBus = new EventBus();\n","/**\n * DOM ↔ StreetUI event bridge.\n *\n * Attaches native DOM event listeners and translates them into\n * StreetUI events dispatched to registered handlers.\n * The renderer uses this to wire events without coupling\n * DOM event mechanics into the render pipeline directly.\n */\n\nimport { createStreetEvent, type EventHandler, type StreetEventType } from './event-types.js';\n\nexport interface DomBinding {\n remove(): void;\n}\n\n/**\n * Attach a DOM event listener that fires the given StreetUI handler.\n * Returns a binding whose `remove()` detaches the listener.\n */\nexport function bindDomEvent<T extends Event = Event>(\n element: EventTarget,\n domEventType: StreetEventType | string,\n handler: EventHandler,\n options?: AddEventListenerOptions,\n): DomBinding {\n const listener = (e: T) => {\n const streetEvent = createStreetEvent(domEventType, element, undefined, e as unknown as Event);\n handler(streetEvent);\n };\n\n element.addEventListener(domEventType, listener as EventListener, options);\n\n return {\n remove() {\n element.removeEventListener(domEventType, listener as EventListener, options);\n },\n };\n}\n\n/**\n * A registry that tracks all DOM bindings for a single node,\n * making bulk teardown easy.\n */\nexport class DomEventRegistry {\n private readonly _bindings: DomBinding[] = [];\n\n bind(\n element: EventTarget,\n type: StreetEventType | string,\n handler: EventHandler,\n options?: AddEventListenerOptions,\n ): void {\n this._bindings.push(bindDomEvent(element, type, handler, options));\n }\n\n removeAll(): void {\n for (const b of this._bindings) {\n b.remove();\n }\n this._bindings.length = 0;\n }\n\n get count(): number {\n return this._bindings.length;\n }\n}\n","/**\n * Browser implementation of DOMAdapter — delegates directly to browser APIs.\n */\n\nimport type { DOMAdapter } from './adapter.js';\n\nexport class BrowserDOMAdapter implements DOMAdapter {\n createElement(tag: string, ns?: string): Element {\n if (ns !== undefined) {\n return document.createElementNS(ns, tag);\n }\n return document.createElement(tag);\n }\n\n createTextNode(data: string): Text {\n return document.createTextNode(data);\n }\n\n createComment(data: string): Comment {\n return document.createComment(data);\n }\n\n createFragment(): DocumentFragment {\n return document.createDocumentFragment();\n }\n\n appendChild(parent: Node, child: Node): void {\n parent.appendChild(child);\n }\n\n insertBefore(parent: Node, child: Node, reference: Node | null): void {\n parent.insertBefore(child, reference);\n }\n\n removeChild(parent: Node, child: Node): void {\n parent.removeChild(child);\n }\n\n replaceChild(parent: Node, newChild: Node, oldChild: Node): void {\n parent.replaceChild(newChild, oldChild);\n }\n\n setAttribute(element: Element, name: string, value: string): void {\n element.setAttribute(name, value);\n }\n\n removeAttribute(element: Element, name: string): void {\n element.removeAttribute(name);\n }\n\n getAttribute(element: Element, name: string): string | null {\n return element.getAttribute(name);\n }\n\n setProperty(element: Element, name: string, value: unknown): void {\n (element as unknown as Record<string, unknown>)[name] = value;\n }\n\n setTextContent(node: Node, text: string): void {\n node.textContent = text;\n }\n\n getTextContent(node: Node): string | null {\n return node.textContent;\n }\n\n addEventListener(\n target: EventTarget,\n type: string,\n handler: EventListener,\n options?: AddEventListenerOptions,\n ): void {\n target.addEventListener(type, handler, options);\n }\n\n removeEventListener(\n target: EventTarget,\n type: string,\n handler: EventListener,\n options?: EventListenerOptions,\n ): void {\n target.removeEventListener(type, handler, options);\n }\n\n querySelector(root: Element | Document, selector: string): Element | null {\n return root.querySelector(selector);\n }\n\n querySelectorAll(root: Element | Document, selector: string): NodeListOf<Element> {\n return root.querySelectorAll(selector);\n }\n\n getElementById(id: string): Element | null {\n return document.getElementById(id);\n }\n\n focus(element: Element): void {\n (element as unknown as { focus?: () => void }).focus?.();\n }\n\n body(): Element | null {\n return document.body ?? null;\n }\n\n head(): Element | null {\n return document.head ?? null;\n }\n\n activeElement(): Element | null {\n return document.activeElement ?? null;\n }\n\n contains(ancestor: Element, node: Node): boolean {\n return ancestor.contains(node);\n }\n\n matches(element: Element, selector: string): boolean {\n return typeof element.matches === 'function' && element.matches(selector);\n }\n\n isElement(node: Node): node is Element {\n return node.nodeType === Node.ELEMENT_NODE;\n }\n\n isTextNode(node: Node): node is Text {\n return node.nodeType === Node.TEXT_NODE;\n }\n\n tagName(element: Element): string {\n return element.tagName.toLowerCase();\n }\n\n parentNode(node: Node): Node | null {\n return node.parentNode;\n }\n\n nextSibling(node: Node): Node | null {\n return node.nextSibling;\n }\n\n firstChild(node: Node): Node | null {\n return node.firstChild;\n }\n\n childNodes(node: Node): Node[] {\n return Array.from(node.childNodes);\n }\n}\n\n// `/* @__PURE__ */`: convenience singleton, unreferenced by internal runtime\n// paths. Marking construction pure lets bundlers drop it when unused instead of\n// retaining it (and the BrowserDOMAdapter class) as an import-time side effect.\nexport const browserDOMAdapter = /* @__PURE__ */ new BrowserDOMAdapter();\n","/**\n * Server-side DOM node model.\n *\n * A tiny, dependency-free tree of plain objects that mirrors just enough of the\n * browser DOM for StreetUI's renderer to build a tree on the server and\n * serialize it to an HTML string. There is NO browser global here — these are\n * ordinary classes usable in any JavaScript environment (Node, workers, tests).\n *\n * The renderer never touches these types directly; it goes through the\n * `DOMAdapter` interface, and `ServerDOMAdapter` translates adapter calls into\n * operations on this model.\n */\n\nexport type ServerNodeKind = 'element' | 'text' | 'comment' | 'fragment' | 'raw';\n\nexport interface ServerNode {\n readonly kind: ServerNodeKind;\n parent: ServerParent | null;\n}\n\nexport type ServerParent = ServerElement | ServerFragment;\n\n/** A minimal inline-style holder mirroring `element.style.setProperty`. */\nexport class ServerStyle {\n readonly declarations = new Map<string, string>();\n setProperty(name: string, value: string): void {\n this.declarations.set(name, value);\n }\n get isEmpty(): boolean {\n return this.declarations.size === 0;\n }\n toCss(): string {\n return [...this.declarations.entries()].map(([k, v]) => `${k}: ${v}`).join('; ');\n }\n}\n\nexport class ServerText implements ServerNode {\n readonly kind = 'text' as const;\n parent: ServerParent | null = null;\n data: string;\n constructor(data: string) {\n this.data = data;\n }\n}\n\nexport class ServerComment implements ServerNode {\n readonly kind = 'comment' as const;\n parent: ServerParent | null = null;\n data: string;\n constructor(data: string) {\n this.data = data;\n }\n}\n\nexport class ServerFragment implements ServerNode {\n readonly kind = 'fragment' as const;\n parent: ServerParent | null = null;\n readonly children: ServerNode[] = [];\n}\n\n/**\n * A pre-serialized, verbatim HTML fragment (v1.7 static SSR plan).\n *\n * Emitted for provably-static subtrees whose HTML the compiler-derived static\n * SSR plan already computed once. Serializing this node copies its stored\n * string directly — it allocates no ServerElement/ServerText, no attribute Map\n * and no children array for the collapsed subtree. The stored `html` is\n * produced by the exact same mount + serialize pipeline as the runtime path, so\n * the output is byte-identical (the v1.7 byte-identity gate proves this).\n *\n * This node is SSR-only: it is created solely via `ServerDOMAdapter.createRawHTML`\n * on the server render path and never appears in a browser build.\n */\nexport class ServerRawHTML implements ServerNode {\n readonly kind = 'raw' as const;\n parent: ServerParent | null = null;\n readonly html: string;\n constructor(html: string) {\n this.html = html;\n }\n}\n\nexport class ServerElement implements ServerNode {\n readonly kind = 'element' as const;\n parent: ServerParent | null = null;\n readonly tagName: string;\n readonly attributes = new Map<string, string>();\n readonly children: ServerNode[] = [];\n\n // Lazily-allocated stores. On the 10k-row SSR corpus ~0% of elements carry JS\n // properties or inline styles (measured, §5: 1 of 80,029 elements uses\n // `properties`, 0 use `style`), so eagerly allocating a `properties` Map plus\n // a `ServerStyle` (which itself holds a Map) per element wasted ~240k\n // allocations per /users render — all in the dominant mount phase. These are\n // created on first WRITE via the `properties`/`style` getters; the serializer\n // reads the raw `_properties`/`_style` fields so a READ never forces an\n // allocation. Output is byte-identical: an unset store previously serialized\n // to nothing (empty `properties.has(...)` / `style.isEmpty`), and a null store\n // is skipped the same way.\n _properties: Map<string, unknown> | null = null;\n _style: ServerStyle | null = null;\n\n constructor(tagName: string) {\n this.tagName = tagName.toLowerCase();\n }\n\n /** JS properties set via `setProperty` (e.g. input `value`, `checked`). Allocated on first access. */\n get properties(): Map<string, unknown> {\n return (this._properties ??= new Map());\n }\n\n /** Inline-style holder mirroring `element.style`. Allocated on first access. */\n get style(): ServerStyle {\n return (this._style ??= new ServerStyle());\n }\n}\n\n// ── HTML serialization ─────────────────────────────────────────────────────────\n\n/**\n * HTML \"void\" elements — self-closing, never given a closing tag or children.\n */\nconst VOID_ELEMENTS = new Set([\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\n 'link', 'meta', 'param', 'source', 'track', 'wbr',\n]);\n\n/**\n * Element properties that should be reflected into the serialized HTML so the\n * hydrated DOM carries the same initial state. `value`/`checked` matter for\n * form controls whose live state is a JS property, not an attribute.\n */\nconst SERIALIZED_PROPERTIES: Record<string, 'attr' | 'boolean'> = {\n value: 'attr',\n checked: 'boolean',\n selected: 'boolean',\n};\n\n/**\n * Precomputed `[name, kind]` pairs of SERIALIZED_PROPERTIES. Hoisted to module\n * scope so `serializeAttributes` does not allocate a fresh entries array for\n * every element serialized (measured hot: ~80k elements on the 10k-row route).\n */\nconst SERIALIZED_PROPERTY_ENTRIES: ReadonlyArray<readonly [string, 'attr' | 'boolean']> =\n Object.entries(SERIALIZED_PROPERTIES) as Array<[string, 'attr' | 'boolean']>;\n\n// Fast-path escaping. The chained `.replace(/…/g, …)` form makes 3–4 full\n// passes and allocates an intermediate string per pass even when nothing needs\n// escaping. These variants scan once and, in the overwhelmingly common case of\n// no special character, return the input unchanged (zero allocation). Output is\n// byte-identical to the chained form (verified over the real SSR corpus).\nconst TEXT_SPECIAL = /[&<>]/;\nconst ATTR_SPECIAL = /[&<>\"]/;\n\n/** Escape text node content. */\nexport function escapeHtmlText(value: string): string {\n if (!TEXT_SPECIAL.test(value)) return value;\n let out = '';\n let last = 0;\n for (let i = 0; i < value.length; i++) {\n let esc: string;\n switch (value.charCodeAt(i)) {\n case 38: esc = '&amp;'; break; // &\n case 60: esc = '&lt;'; break; // <\n case 62: esc = '&gt;'; break; // >\n default: continue;\n }\n out += value.slice(last, i) + esc;\n last = i + 1;\n }\n return out + value.slice(last);\n}\n\n/** Escape a double-quoted attribute value. */\nexport function escapeHtmlAttr(value: string): string {\n if (!ATTR_SPECIAL.test(value)) return value;\n let out = '';\n let last = 0;\n for (let i = 0; i < value.length; i++) {\n let esc: string;\n switch (value.charCodeAt(i)) {\n case 38: esc = '&amp;'; break; // &\n case 60: esc = '&lt;'; break; // <\n case 62: esc = '&gt;'; break; // >\n case 34: esc = '&quot;'; break; // \"\n default: continue;\n }\n out += value.slice(last, i) + esc;\n last = i + 1;\n }\n return out + value.slice(last);\n}\n\nfunction serializeAttributes(el: ServerElement): string {\n const parts: string[] = [];\n\n for (const [name, value] of el.attributes) {\n if (value === '') {\n parts.push(` ${name}`);\n } else {\n parts.push(` ${name}=\"${escapeHtmlAttr(value)}\"`);\n }\n }\n\n // Read the raw backing field (may be null): most elements have no JS\n // properties, so skipping the whole loop avoids touching a store that was\n // never allocated (§5).\n const props = el._properties;\n if (props !== null) {\n for (const [name, kind] of SERIALIZED_PROPERTY_ENTRIES) {\n if (!props.has(name)) continue;\n if (el.attributes.has(name)) continue; // an explicit attribute already won\n const raw = props.get(name);\n if (kind === 'boolean') {\n if (raw === true) parts.push(` ${name}`);\n } else {\n if (raw !== undefined && raw !== null) {\n parts.push(` ${name}=\"${escapeHtmlAttr(String(raw))}\"`);\n }\n }\n }\n }\n\n const style = el._style;\n if (style !== null && !style.isEmpty && !el.attributes.has('style')) {\n parts.push(` style=\"${escapeHtmlAttr(style.toCss())}\"`);\n }\n\n return parts.join('');\n}\n\n/** Serialize a single server node (element/text/comment/fragment/raw) to HTML. */\nexport function serializeServerNode(node: ServerNode): string {\n switch (node.kind) {\n case 'text':\n return escapeHtmlText((node as ServerText).data);\n case 'comment':\n return `<!--${(node as ServerComment).data}-->`;\n case 'fragment':\n return serializeChildren(node as ServerFragment);\n case 'raw':\n // Verbatim: the string was produced by this same serializer for a static\n // subtree, so it is already correctly escaped. Copy it as-is (§8).\n return (node as ServerRawHTML).html;\n case 'element': {\n const el = node as ServerElement;\n const tag = el.tagName;\n const attrs = serializeAttributes(el);\n if (VOID_ELEMENTS.has(tag)) {\n return `<${tag}${attrs}>`;\n }\n return `<${tag}${attrs}>${serializeChildren(el)}</${tag}>`;\n }\n }\n}\n\n/** Serialize the children of an element or fragment (its \"inner HTML\"). */\nexport function serializeChildren(node: ServerElement | ServerFragment): string {\n let out = '';\n for (const child of node.children) {\n out += serializeServerNode(child);\n }\n return out;\n}\n","/**\n * Server implementation of `DOMAdapter`.\n *\n * Builds a lightweight in-memory tree (see `server-node.ts`) instead of touching\n * a real browser DOM, then lets the caller serialize it to an HTML string. It is\n * completely free of browser globals, so the exact same renderer that runs in\n * the browser can produce HTML on the server.\n *\n * The `DOMAdapter` interface is typed against the lib DOM types (`Element`,\n * `Node`, `Text`, …). Our server nodes structurally stand in for those at\n * runtime, so the boundary uses `as unknown as` casts in one place. Everything\n * inside operates on the real server-node model.\n */\n\nimport type { DOMAdapter } from './adapter.js';\nimport {\n ServerElement,\n ServerText,\n ServerComment,\n ServerFragment,\n ServerRawHTML,\n serializeChildren,\n serializeServerNode,\n type ServerNode,\n type ServerParent,\n} from './server-node.js';\n\nfunction asServer(node: unknown): ServerNode {\n return node as unknown as ServerNode;\n}\nfunction asParent(node: unknown): ServerParent {\n return node as unknown as ServerParent;\n}\n\nexport class ServerDOMAdapter implements DOMAdapter {\n createElement(tag: string, _ns?: string): Element {\n return new ServerElement(tag) as unknown as Element;\n }\n\n createTextNode(data: string): Text {\n return new ServerText(data) as unknown as Text;\n }\n\n createComment(data: string): Comment {\n return new ServerComment(data) as unknown as Comment;\n }\n\n createFragment(): DocumentFragment {\n return new ServerFragment() as unknown as DocumentFragment;\n }\n\n /**\n * Create a verbatim pre-serialized HTML node (v1.7 static SSR plan, §6).\n * Server-only: the browser adapter does not implement this, and the renderer\n * fast path only invokes it when a static SSR plan is present (SSR). The\n * stored HTML was produced by this same serializer, so it is emitted as-is.\n */\n createRawHTML(html: string): Node {\n return new ServerRawHTML(html) as unknown as Node;\n }\n\n appendChild(parent: Node, child: Node): void {\n const p = asParent(parent);\n const c = asServer(child);\n this._detach(c);\n c.parent = p;\n p.children.push(c);\n }\n\n insertBefore(parent: Node, child: Node, reference: Node | null): void {\n const p = asParent(parent);\n const c = asServer(child);\n this._detach(c);\n c.parent = p;\n if (reference === null) {\n p.children.push(c);\n return;\n }\n const ref = asServer(reference);\n const idx = p.children.indexOf(ref);\n if (idx === -1) p.children.push(c);\n else p.children.splice(idx, 0, c);\n }\n\n removeChild(parent: Node, child: Node): void {\n const p = asParent(parent);\n const c = asServer(child);\n const idx = p.children.indexOf(c);\n if (idx !== -1) {\n p.children.splice(idx, 1);\n c.parent = null;\n }\n }\n\n replaceChild(parent: Node, newChild: Node, oldChild: Node): void {\n const p = asParent(parent);\n const nc = asServer(newChild);\n const oc = asServer(oldChild);\n const idx = p.children.indexOf(oc);\n if (idx === -1) return;\n this._detach(nc);\n nc.parent = p;\n p.children.splice(idx, 1, nc);\n oc.parent = null;\n }\n\n private _detach(node: ServerNode): void {\n if (node.parent !== null) {\n const siblings = node.parent.children;\n const idx = siblings.indexOf(node);\n if (idx !== -1) siblings.splice(idx, 1);\n node.parent = null;\n }\n }\n\n setAttribute(element: Element, name: string, value: string): void {\n (element as unknown as ServerElement).attributes.set(name, value);\n }\n\n removeAttribute(element: Element, name: string): void {\n (element as unknown as ServerElement).attributes.delete(name);\n }\n\n getAttribute(element: Element, name: string): string | null {\n return (element as unknown as ServerElement).attributes.get(name) ?? null;\n }\n\n setProperty(element: Element, name: string, value: unknown): void {\n (element as unknown as ServerElement).properties.set(name, value);\n }\n\n setTextContent(node: Node, text: string): void {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n const el = n as ServerElement | ServerFragment;\n el.children.length = 0;\n const t = new ServerText(text);\n t.parent = el;\n el.children.push(t);\n } else if (n.kind === 'text') {\n (n as ServerText).data = text;\n }\n }\n\n getTextContent(node: Node): string | null {\n const n = asServer(node);\n if (n.kind === 'text') return (n as ServerText).data;\n if (n.kind === 'element' || n.kind === 'fragment') {\n let out = '';\n for (const c of (n as ServerElement | ServerFragment).children) {\n out += this.getTextContent(c as unknown as Node) ?? '';\n }\n return out;\n }\n return null;\n }\n\n // Server nodes never dispatch events — listeners are a no-op on the server.\n addEventListener(): void {\n /* no-op on the server */\n }\n removeEventListener(): void {\n /* no-op on the server */\n }\n\n querySelector(): Element | null {\n return null;\n }\n querySelectorAll(): NodeListOf<Element> {\n return [] as unknown as NodeListOf<Element>;\n }\n getElementById(): Element | null {\n return null;\n }\n\n focus(): void {\n // No focus concept on the server — intentional no-op (SSR-safe).\n }\n\n body(): Element | null {\n // No document on the server — portals degrade to inline rendering.\n return null;\n }\n\n head(): Element | null {\n // No document on the server — head metadata is emitted as a string by\n // `renderHead()` instead of being applied to a live document.head.\n return null;\n }\n\n activeElement(): Element | null {\n return null;\n }\n\n contains(_ancestor: Element, _node: Node): boolean {\n return false;\n }\n\n matches(_element: Element, _selector: string): boolean {\n return false;\n }\n\n isElement(node: Node): node is Element {\n return asServer(node).kind === 'element';\n }\n\n isTextNode(node: Node): node is Text {\n return asServer(node).kind === 'text';\n }\n\n tagName(element: Element): string {\n return (element as unknown as ServerElement).tagName;\n }\n\n parentNode(node: Node): Node | null {\n return (asServer(node).parent as unknown as Node | null) ?? null;\n }\n\n nextSibling(node: Node): Node | null {\n const n = asServer(node);\n const parent = n.parent;\n if (parent === null) return null;\n const idx = parent.children.indexOf(n);\n if (idx === -1 || idx + 1 >= parent.children.length) return null;\n return parent.children[idx + 1] as unknown as Node;\n }\n\n firstChild(node: Node): Node | null {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n const el = n as ServerElement | ServerFragment;\n return (el.children[0] as unknown as Node) ?? null;\n }\n return null;\n }\n\n childNodes(node: Node): Node[] {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n return (n as ServerElement | ServerFragment).children as unknown as Node[];\n }\n return [];\n }\n\n // ── Server-only ────────────────────────────────────────────────────────────\n\n /** Serialize a node's children (\"inner HTML\") to an HTML string. */\n serializeInner(node: Node): string {\n const n = asServer(node);\n if (n.kind === 'element' || n.kind === 'fragment') {\n return serializeChildren(n as ServerElement | ServerFragment);\n }\n return '';\n }\n\n /** Serialize a node (including itself) to an HTML string. */\n serializeOuter(node: Node): string {\n return serializeServerNode(asServer(node));\n }\n}\n\n// `/* @__PURE__ */`: this singleton is a convenience export only (no internal\n// runtime path references it). Marking construction pure lets bundlers drop it —\n// and with it the whole server serializer chain (serializeServerNode/escape/\n// VOID_ELEMENTS) — out of client bundles that never import SSR. Without this,\n// the un-annotated `new` is treated as a side effect and retained everywhere.\nexport const serverDOMAdapter = /* @__PURE__ */ new ServerDOMAdapter();\n","/**\n * Focus helpers built on the {@link DOMAdapter} abstraction.\n *\n * These are the minimal, genuinely-useful focus operations an app needs:\n * focus a specific element (e.g. the first field when a route or modal opens)\n * or focus the first focusable element inside a container (e.g. move focus\n * into a dialog). Both go through the adapter, so they are no-ops on the server\n * (`ServerDOMAdapter.querySelector` returns null / `focus` does nothing) and\n * therefore safe to call from universal code.\n */\n\nimport type { DOMAdapter } from './adapter.js';\n\n/** Default selector for natively focusable / tabbable elements. */\nexport const FOCUSABLE_SELECTOR =\n 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * Focus the element with the given id, scoped to `root`.\n * Returns true if an element was found and focused.\n */\nexport function focusById(dom: DOMAdapter, root: Element | Document, id: string): boolean {\n const el = dom.querySelector(root, `[id=\"${id}\"]`);\n if (el === null) return false;\n dom.focus(el);\n return true;\n}\n\n/**\n * Focus the first focusable element inside `container`.\n * Returns true if a focusable element was found and focused.\n */\nexport function focusFirst(\n dom: DOMAdapter,\n container: Element | Document,\n selector: string = FOCUSABLE_SELECTOR,\n): boolean {\n const el = dom.querySelector(container, selector);\n if (el === null) return false;\n dom.focus(el);\n return true;\n}\n\n/**\n * Ordered list of focusable/tabbable descendants of `container`.\n * Re-checks each candidate against the selector so elements disabled after the\n * initial query (e.g. a button toggled to `disabled`) are excluded.\n */\nexport function getFocusable(\n dom: DOMAdapter,\n container: Element,\n selector: string = FOCUSABLE_SELECTOR,\n): Element[] {\n return Array.from(dom.querySelectorAll(container, selector)).filter((el) =>\n dom.matches(el, selector),\n );\n}\n\n/**\n * Capture the currently-focused element so it can be restored later (e.g. when\n * a dialog closes). Returns null on the server or when nothing is focused.\n */\nexport function saveFocus(dom: DOMAdapter): Element | null {\n return dom.activeElement();\n}\n\n/** Restore focus to a previously {@link saveFocus}-d element. No-op if null. */\nexport function restoreFocus(dom: DOMAdapter, saved: Element | null): void {\n if (saved !== null) dom.focus(saved);\n}\n\n/**\n * Move focus into `container` on open: the element with id `initialFocusId` if\n * given and present, otherwise the first focusable element. Server-safe no-op.\n */\nexport function focusInitial(\n dom: DOMAdapter,\n container: Element,\n initialFocusId?: string,\n): void {\n if (initialFocusId !== undefined && focusById(dom, container, initialFocusId)) return;\n focusFirst(dom, container);\n}\n\n/**\n * Trap Tab / Shift+Tab focus within `container` (wrap-around at both ends).\n * Attaches a keydown listener to the container and returns a cleanup function\n * that detaches it. Server-safe: `addEventListener` is a no-op, and the returned\n * cleanup is still callable.\n */\nexport function trapFocus(dom: DOMAdapter, container: Element): () => void {\n const onKeydown = ((event: KeyboardEvent): void => {\n if (event.key !== 'Tab') return;\n const items = getFocusable(dom, container);\n if (items.length === 0) {\n event.preventDefault();\n return;\n }\n const first = items[0]!;\n const last = items[items.length - 1]!;\n const active = dom.activeElement();\n if (active === null || !dom.contains(container, active)) {\n event.preventDefault();\n dom.focus(first);\n } else if (event.shiftKey && active === first) {\n event.preventDefault();\n dom.focus(last);\n } else if (!event.shiftKey && active === last) {\n event.preventDefault();\n dom.focus(first);\n }\n }) as EventListener;\n dom.addEventListener(container, 'keydown', onKeydown);\n return () => dom.removeEventListener(container, 'keydown', onKeydown);\n}\n\n/**\n * Modal containment: if focus moves to an element outside `container`, redirect\n * it back inside. Listens on the document body (focusin bubbles there) and\n * returns a cleanup function. Server-safe no-op (body() is null).\n *\n * Nested modals (§16): every active containment pushes its container onto a\n * module-level stack, and a handler only redirects while ITS container is the\n * top of the stack — i.e. the most recently opened modal. This is the framework's\n * minimal \"focus owner\" concept: because overlay panels are relocated to\n * body-level portals (siblings, not descendants), two overlapping `containFocus`\n * handlers would otherwise fight over every `focusin`. The stack makes exactly\n * one owner authoritative at a time; cleanup pops it so the previous modal\n * resumes ownership. State is internal and torn down on cleanup — nothing is\n * retained on the graph (§18).\n */\nconst containmentStack: Element[] = [];\n\nexport function containFocus(dom: DOMAdapter, container: Element): () => void {\n const body = dom.body();\n if (body === null) return () => {};\n containmentStack.push(container);\n const onFocusIn = ((event: FocusEvent): void => {\n // Only the topmost owner enforces containment (nested-modal correctness).\n if (containmentStack[containmentStack.length - 1] !== container) return;\n const target = event.target as Node | null;\n if (target !== null && !dom.contains(container, target)) {\n focusFirst(dom, container);\n }\n }) as EventListener;\n dom.addEventListener(body, 'focusin', onFocusIn);\n return () => {\n dom.removeEventListener(body, 'focusin', onFocusIn);\n const index = containmentStack.lastIndexOf(container);\n if (index !== -1) containmentStack.splice(index, 1);\n };\n}\n\n/**\n * Invoke `handler` when Escape is pressed while focus is within `target`.\n * Returns a cleanup function. Server-safe no-op.\n */\nexport function onEscape(dom: DOMAdapter, target: Element, handler: () => void): () => void {\n const onKeydown = ((event: KeyboardEvent): void => {\n if (event.key === 'Escape') handler();\n }) as EventListener;\n dom.addEventListener(target, 'keydown', onKeydown);\n return () => dom.removeEventListener(target, 'keydown', onKeydown);\n}\n\n/**\n * Roving-focus keyboard navigation for a menu (role=\"menu\") container: the\n * arrow keys move focus between the container's focusable items (wrap-around at\n * both ends), Home/End jump to the first/last item, and Enter/Space activate\n * the currently-focused item (a native `click`, so an item's `onClick` fires).\n * `Tab` and `Escape` are deliberately left alone — the overlay layer wires\n * Escape-to-close separately and a menu does not trap Tab.\n *\n * Items are re-queried on every key (via {@link getFocusable}) so a menu whose\n * items change reactively is always navigated against the live set, and items\n * disabled after mount are skipped. Attaches a keydown listener to the\n * container and returns a cleanup function. Server-safe: `addEventListener` is\n * a no-op and the returned cleanup is still callable.\n */\nexport function rovingMenu(\n dom: DOMAdapter,\n container: Element,\n selector: string = FOCUSABLE_SELECTOR,\n): () => void {\n const onKeydown = ((event: KeyboardEvent): void => {\n const key = event.key;\n const isActivate = key === 'Enter' || key === ' ' || key === 'Spacebar';\n const isMove =\n key === 'ArrowDown' || key === 'ArrowUp' || key === 'Home' || key === 'End';\n if (!isActivate && !isMove) return;\n\n const items = getFocusable(dom, container, selector);\n if (items.length === 0) return;\n const active = dom.activeElement();\n const index = active === null ? -1 : items.indexOf(active);\n\n if (isActivate) {\n // Activating a menu item only makes sense when one is focused; otherwise\n // let the event fall through unchanged.\n if (index < 0) return;\n event.preventDefault();\n (items[index] as unknown as { click?: () => void }).click?.();\n return;\n }\n\n event.preventDefault();\n let next: number;\n if (key === 'Home') next = 0;\n else if (key === 'End') next = items.length - 1;\n else if (key === 'ArrowDown') next = index < 0 ? 0 : (index + 1) % items.length;\n else next = index <= 0 ? items.length - 1 : index - 1; // ArrowUp\n dom.focus(items[next]!);\n }) as EventListener;\n dom.addEventListener(container, 'keydown', onKeydown);\n return () => dom.removeEventListener(container, 'keydown', onKeydown);\n}\n\n","/**\n * ARIA live-region announcer (§15).\n *\n * Screen readers announce text that appears inside an `aria-live` region. The\n * naive approach — append a fresh `<div aria-live>` per message — leaks a\n * growing pile of stale nodes and (because a node inserted *already carrying*\n * its text is often not re-announced) is unreliable. This announcer instead\n * keeps exactly TWO persistent regions on `<body>` — one `polite`, one\n * `assertive` — and mutates their text to speak. Announcing clears the region\n * first and writes on a microtask so that repeating the same string still\n * triggers a DOM mutation the AT will pick up.\n *\n * Built entirely on the {@link DOMAdapter}, so it is server-safe: when\n * `dom.body()` is null (SSR / headless) construction returns an inert announcer\n * whose `announce`/`clear`/`destroy` are no-ops. There is never any SSR markup\n * for a live region — announcements are a runtime-only concept.\n */\n\nimport type { DOMAdapter } from './adapter.js';\n\nexport interface Announcer {\n /**\n * Announce `message`. `assertive` (default false) routes to the assertive\n * region (interrupts the user) instead of the polite one (waits for a pause).\n */\n announce(message: string, options?: { assertive?: boolean }): void;\n /** Clear both regions without announcing anything. */\n clear(): void;\n /** Remove both regions from the DOM. Idempotent. */\n destroy(): void;\n}\n\n/** Build the hidden, visually-clipped style shared by both regions. */\nconst VISUALLY_HIDDEN =\n 'position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0;';\n\nfunction makeRegion(dom: DOMAdapter, politeness: 'polite' | 'assertive'): Element {\n const el = dom.createElement('div');\n dom.setAttribute(el, 'aria-live', politeness);\n // `aria-atomic=true` makes the AT read the whole region on each change, so a\n // replaced message is spoken in full rather than diffed.\n dom.setAttribute(el, 'aria-atomic', 'true');\n dom.setAttribute(el, 'role', politeness === 'assertive' ? 'alert' : 'status');\n dom.setAttribute(el, 'data-streetui-live', politeness);\n dom.setAttribute(el, 'style', VISUALLY_HIDDEN);\n return el;\n}\n\n/**\n * Create a live-region announcer bound to `dom`. Idempotent per call — each\n * call owns its own pair of regions, so an app that wants a single shared\n * announcer should create one and reuse it (and `destroy()` it on teardown).\n */\nexport function createAnnouncer(dom: DOMAdapter): Announcer {\n const body = dom.body();\n if (body === null) {\n // Server / headless: nothing to announce into.\n return { announce() {}, clear() {}, destroy() {} };\n }\n\n const polite = makeRegion(dom, 'polite');\n const assertive = makeRegion(dom, 'assertive');\n dom.appendChild(body, polite);\n dom.appendChild(body, assertive);\n let destroyed = false;\n\n const write = (region: Element, message: string): void => {\n // Clear first so an identical repeat message still mutates the region (and\n // is therefore re-announced); set on a microtask so the empty→text change\n // is observed as a distinct mutation.\n dom.setTextContent(region, '');\n void Promise.resolve().then(() => {\n if (!destroyed) dom.setTextContent(region, message);\n });\n };\n\n return {\n announce(message, options): void {\n if (destroyed) return;\n write(options?.assertive === true ? assertive : polite, message);\n },\n clear(): void {\n if (destroyed) return;\n dom.setTextContent(polite, '');\n dom.setTextContent(assertive, '');\n },\n destroy(): void {\n if (destroyed) return;\n destroyed = true;\n for (const region of [polite, assertive]) {\n const parent = dom.parentNode(region);\n if (parent !== null) dom.removeChild(parent, region);\n }\n },\n };\n}\n","/**\n * RenderContext — shared state for a single mount operation.\n *\n * Passed through the render pipeline so every sub-function has access\n * to the DOM adapter, graph, and instance map without prop-drilling.\n */\n\nimport type { DOMAdapter } from '@streetui/dom';\nimport type { ApplicationGraph, GraphNode } from '@streetui/graph';\nimport type { NodeInstance } from './node-instance.js';\nimport type { HydrationDiagnosticSink } from './hydration-diagnostics.js';\nimport type { HeadManager } from './head.js';\n\nexport interface RenderContext {\n readonly dom: DOMAdapter;\n readonly graph: ApplicationGraph;\n /** Maps GraphNode.id → its live NodeInstance */\n readonly instances: Map<string, NodeInstance>;\n /** The root container element. */\n readonly container: Element;\n /**\n * Optional dev-only sink that observes hydration mismatch repairs. When\n * absent (the default) the hydration path does no extra work — this is how\n * DevTools/diagnostics stay off the production runtime path.\n */\n readonly hydrationDiagnostics?: HydrationDiagnosticSink;\n /**\n * Optional SSR-only static-subtree plan (v1.7). Maps a maximal\n * static-subtree root GraphNode.id → its precomputed, verbatim HTML string.\n * Present only on the server render path when a plan has been built; on the\n * browser mount path it is always `undefined`, so the client hot path is\n * unaffected (a single `=== undefined` check short-circuits). When a mounted\n * node's id is in this map, the renderer emits the precomputed HTML via\n * `dom.createRawHTML` instead of recursively constructing the subtree.\n */\n readonly staticHTML?: ReadonlyMap<string, string>;\n /**\n * Lazily-created coordinator for `head()` metadata nodes (2.0 §1). Created on\n * first `wireHeadBehavior` call on the browser (never on the server, where\n * `dom.head()` is null and `renderHead` emits the metadata instead). Mutable\n * because it is attached on demand; a render with no `head()` nodes never\n * allocates one.\n */\n head?: HeadManager;\n}\n\nexport function createRenderContext(\n dom: DOMAdapter,\n graph: ApplicationGraph,\n container: Element,\n hydrationDiagnostics?: HydrationDiagnosticSink,\n staticHTML?: ReadonlyMap<string, string>,\n): RenderContext {\n return {\n dom,\n graph,\n instances: new Map(),\n container,\n ...(hydrationDiagnostics !== undefined ? { hydrationDiagnostics } : {}),\n ...(staticHTML !== undefined ? { staticHTML } : {}),\n };\n}\n","/**\n * NodeInstance — the renderer's live counterpart to a GraphNode.\n *\n * Tracks the actual DOM node(s), all signal subscriptions that drive\n * targeted DOM updates, and DOM event listener teardowns.\n */\n\nimport { CleanupRegistry } from '@streetui/core';\nimport type { GraphNode } from '@streetui/graph';\nimport type { ReadonlySignal } from '@streetui/state';\n\nexport class NodeInstance {\n readonly graphNode: GraphNode;\n /** The primary DOM node for this instance (element or text node). */\n domNode: Node;\n readonly children: NodeInstance[] = [];\n readonly cleanup: CleanupRegistry = new CleanupRegistry();\n\n constructor(graphNode: GraphNode, domNode: Node) {\n this.graphNode = graphNode;\n this.domNode = domNode;\n }\n\n addChild(child: NodeInstance): void {\n this.children.push(child);\n }\n\n /** Subscribe to a signal; auto-cleanup on unmount. */\n trackSignal<T>(sig: ReadonlySignal<T>, handler: (v: T) => void): void {\n const unsub = sig.subscribe(handler);\n this.cleanup.add(unsub);\n }\n\n /** Register a raw cleanup fn (DOM event removal, etc.). */\n trackCleanup(fn: () => void): void {\n this.cleanup.add(fn);\n }\n\n dispose(): void {\n for (const child of this.children) {\n child.dispose();\n }\n this.cleanup.run();\n }\n}\n","/**\n * Attribute and property application helpers.\n *\n * Decides whether a prop should be set as a DOM attribute or a JS property,\n * handling special cases (boolean attrs, event-like props, style, class).\n */\n\nimport type { DOMAdapter } from '@streetui/dom';\n\n// Properties that must be set as JS object properties, not HTML attributes\nconst DOM_PROPERTIES = new Set([\n 'value', 'checked', 'selected', 'indeterminate',\n 'innerHTML', 'textContent', 'innerText',\n 'scrollTop', 'scrollLeft',\n]);\n\n// Boolean attributes — present means true, absent means false\nconst BOOLEAN_ATTRS = new Set([\n 'disabled', 'readonly', 'required', 'checked', 'selected',\n 'multiple', 'autofocus', 'autoplay', 'controls', 'default',\n 'defer', 'formnovalidate', 'hidden', 'ismap', 'loop',\n 'novalidate', 'open', 'reversed', 'scoped', 'seamless',\n]);\n\nexport function applyProp(\n dom: DOMAdapter,\n element: Element,\n name: string,\n value: unknown,\n): void {\n // Skip internal renderer metadata\n if (name.startsWith('_')) return;\n // Skip event handlers (handled separately)\n if (name.startsWith('on')) return;\n\n if (DOM_PROPERTIES.has(name)) {\n dom.setProperty(element, name, value);\n return;\n }\n\n if (BOOLEAN_ATTRS.has(name)) {\n if (value === true || value === '' || value === name) {\n dom.setAttribute(element, name, '');\n } else {\n dom.removeAttribute(element, name);\n }\n return;\n }\n\n if (name === 'class' || name === 'className') {\n dom.setAttribute(element, 'class', String(value ?? ''));\n return;\n }\n\n if (name === 'style' && typeof value === 'object' && value !== null) {\n const el = element as HTMLElement;\n const styles = value as Record<string, string>;\n for (const [k, v] of Object.entries(styles)) {\n el.style.setProperty(k, v);\n }\n return;\n }\n\n if (value === null || value === undefined || value === false) {\n dom.removeAttribute(element, name);\n return;\n }\n\n dom.setAttribute(element, name, String(value));\n}\n\nexport function patchProp(\n dom: DOMAdapter,\n element: Element,\n name: string,\n oldValue: unknown,\n newValue: unknown,\n): void {\n if (Object.is(oldValue, newValue)) return;\n applyProp(dom, element, name, newValue);\n}\n","/**\n * Event wiring for the renderer.\n *\n * Given a GraphNode with event descriptors, this wires DOM listeners\n * that call the handlers stored in the graph's handler registry.\n */\n\nimport type { DOMAdapter } from '@streetui/dom';\nimport type { ApplicationGraph, GraphNode } from '@streetui/graph';\nimport type { NodeInstance } from './node-instance.js';\n\nexport function wireEvents(\n dom: DOMAdapter,\n graph: ApplicationGraph,\n node: GraphNode,\n element: Element,\n instance: NodeInstance,\n): void {\n // Fast exit for event-free nodes — avoids allocating a for-of iterator over\n // an empty array on every node during a large mount/hydrate.\n if (node.events.length === 0) return;\n for (const eventDesc of node.events) {\n const handler = graph.getHandler(eventDesc.handlerKey);\n if (handler === undefined) continue;\n\n const domListener: EventListener = (domEvent: Event) => {\n // For input events, pass the current value as first arg\n if (eventDesc.type === 'input' || eventDesc.type === 'change') {\n const input = domEvent.target as HTMLInputElement;\n (handler as (v: string) => void)(input.value);\n } else if (eventDesc.type === 'submit') {\n domEvent.preventDefault();\n (handler as (e: Event) => void)(domEvent);\n } else {\n (handler as () => void)();\n }\n };\n\n dom.addEventListener(element, eventDesc.type, domListener);\n instance.trackCleanup(() => {\n dom.removeEventListener(element, eventDesc.type, domListener);\n });\n }\n}\n","/**\n * Maps semantic node types to HTML tag names.\n */\n\nimport type { SemanticNodeType } from '@streetui/core';\n\nconst TAG_MAP: Partial<Record<SemanticNodeType, string>> = {\n application: 'div',\n page: 'div',\n section: 'section',\n container: 'div',\n heading: 'h1',\n text: 'span',\n button: 'button',\n input: 'input',\n form: 'form',\n list: 'ul',\n 'list-item': 'li',\n image: 'img',\n link: 'a',\n component: 'div',\n slot: 'div',\n fragment: 'div',\n 'reactive-list': 'ul',\n // A portal renders as a neutral inline anchor <div> at its declaration site;\n // its children are relocated to a document.body container on the browser\n // (see the portal branch in mount.ts). On the server (no body) it renders\n // inline, so the anchor tag is what SSR/hydration positionally match on.\n portal: 'div',\n // A `head()` node renders as a neutral, empty inline anchor <div> at its\n // declaration site (like a portal anchor). Its actual contribution — title/\n // meta/link/etc. — is applied to `document.head` by `wireHeadBehavior` on the\n // browser, and emitted separately by `renderHead()` on the server. Keeping a\n // one-node/one-element anchor preserves positional hydration.\n head: 'div',\n};\n\nexport function resolveTag(type: SemanticNodeType): string {\n return TAG_MAP[type] ?? 'div';\n}\n","/**\n * Patch — targeted DOM updates driven by signal changes.\n *\n * When a signal fires, we look up the NodeInstance and apply\n * only the changed prop — no full re-render, no tree diffing.\n */\n\nimport type { RenderContext } from './render-context.js';\nimport type { GraphNode } from '@streetui/graph';\nimport { applyProp, patchProp } from './attributes.js';\n\nexport function patchNode(\n ctx: RenderContext,\n graphNode: GraphNode,\n propKey: string,\n newValue: unknown,\n): void {\n const instance = ctx.instances.get(graphNode.id);\n if (instance === undefined) return;\n\n const domNode = instance.domNode;\n if (!ctx.dom.isElement(domNode)) return;\n\n const oldValue = graphNode.getProp(propKey);\n\n switch (propKey) {\n case 'text':\n if (!Object.is(oldValue, newValue)) {\n ctx.dom.setTextContent(domNode, String(newValue ?? ''));\n graphNode.setProp('text', String(newValue ?? ''));\n }\n break;\n case 'label':\n if (!Object.is(oldValue, newValue)) {\n ctx.dom.setTextContent(domNode, String(newValue ?? ''));\n graphNode.setProp('label', String(newValue ?? ''));\n }\n break;\n case 'disabled':\n if (newValue === true) {\n ctx.dom.setAttribute(domNode, 'disabled', '');\n } else {\n ctx.dom.removeAttribute(domNode, 'disabled');\n }\n graphNode.setProp('disabled', Boolean(newValue));\n break;\n case 'value':\n if (!Object.is(oldValue, newValue)) {\n ctx.dom.setProperty(domNode, 'value', String(newValue ?? ''));\n graphNode.setProp('value', String(newValue ?? ''));\n }\n break;\n default:\n patchProp(ctx.dom, domNode, propKey, oldValue, newValue);\n graphNode.setProp(propKey, newValue as string);\n break;\n }\n}\n","/**\n * Reconciliation — diff-based child list updates.\n *\n * When the children of a node change (e.g. a list driven by state),\n * this reconciler:\n * 1. Matches old instances to new graph nodes by key\n * 2. Reuses matched instances (updates their props)\n * 3. Applies a targeted content update to a reused item whose data changed\n * 4. Creates new instances for additions\n * 5. Removes stale instances (and prunes their handler registrations)\n * 6. Moves DOM nodes to match new order\n *\n * This is keyed reconciliation over the semantic graph — there is no virtual\n * DOM. A reused item keeps its own DOM element; only its changed content is\n * updated in place (falling back to remounting a subtree only where its shape\n * actually changed).\n */\n\nimport type { RenderContext } from './render-context.js';\nimport type { GraphNode } from '@streetui/graph';\nimport type { NodeInstance } from './node-instance.js';\nimport type { TransitionHooks } from './transition.js';\nimport { patchNode } from './patch.js';\n\nexport type MountFn = (node: GraphNode, parent: Element) => NodeInstance;\n\nexport interface ReconcileResult {\n /** Instances in the new order. */\n instances: NodeInstance[];\n /** Instances that were removed and must be disposed. */\n removed: NodeInstance[];\n /**\n * GraphNodes freshly materialised during this reconcile (new rows + rebuilt\n * changed rows). The caller detaches any of these that were not adopted as a\n * live instance's graph node, so no orphan subtree lingers in the graph index.\n */\n built?: GraphNode[];\n}\n\n/**\n * A lazy reconciliation descriptor for one reactive-list row (mirrors the DSL's\n * `ListPlanEntry`). `sig()` and `build()` are only invoked for rows that are\n * genuinely new or whose source reference changed — the whole point of the\n * plan path (spec §15).\n */\nexport interface PlanEntry {\n readonly key: string;\n readonly item: unknown;\n readonly sig: () => string;\n readonly build: () => GraphNode;\n}\n\n/**\n * Reconcile children of a container element against a new list of graph nodes.\n *\n * @param ctx Render context\n * @param parentDom The DOM parent element\n * @param oldInstances Current child instances (in order)\n * @param newNodes New graph children (in desired order)\n * @param mountFn Factory to create a new NodeInstance for a graph node\n */\nexport function reconcileChildren(\n ctx: RenderContext,\n parentDom: Element,\n oldInstances: NodeInstance[],\n newNodes: readonly GraphNode[],\n mountFn: MountFn,\n hooks?: TransitionHooks,\n): ReconcileResult {\n // Build key → old instance map\n const oldByKey = new Map<string, NodeInstance>();\n for (const inst of oldInstances) {\n const key = inst.graphNode.key ?? inst.graphNode.id;\n oldByKey.set(key, inst);\n }\n\n const newInstances: NodeInstance[] = [];\n const usedKeys = new Set<string>();\n\n for (const newNode of newNodes) {\n const key = newNode.key ?? newNode.id;\n const existing = oldByKey.get(key);\n\n if (existing !== undefined) {\n // Reuse — identity is stable, so the DOM element is preserved.\n usedKeys.add(key);\n const oldSig = existing.graphNode.getProp('_sig');\n const newSig = newNode.getProp('_sig');\n patchExistingInstance(ctx, existing, newNode);\n // Data changed but identity did not → targeted content update in place.\n if (!Object.is(oldSig, newSig)) {\n reconcileItemChildren(ctx, existing, newNode, mountFn);\n }\n newInstances.push(existing);\n } else {\n // Leave→enter cancellation (§6): if this key is currently animating out,\n // reclaim its live instance instead of mounting a duplicate.\n const reclaimed = hooks?.takeLeaving(key);\n if (reclaimed !== undefined) {\n patchExistingInstance(ctx, reclaimed, newNode);\n reconcileItemChildren(ctx, reclaimed, newNode, mountFn);\n hooks?.onEnter(reclaimed);\n newInstances.push(reclaimed);\n } else {\n // New — create and mount, then play its enter animation (if any).\n const inst = mountFn(newNode, parentDom);\n hooks?.onEnter(inst);\n newInstances.push(inst);\n }\n }\n }\n\n // Determine + remove stale instances. A removed instance that carries a\n // transition has its DOM-remove + dispose deferred to leave-animation end by\n // `beginLeave` (which then also forgets + detaches it), so it is excluded from\n // `removed` and the caller does not tear it down (§3/§7).\n const removed: NodeInstance[] = [];\n for (const inst of oldInstances) {\n const key = inst.graphNode.key ?? inst.graphNode.id;\n if (usedKeys.has(key)) continue;\n if (hooks !== undefined && hooks.beginLeave(inst)) continue;\n const parent = ctx.dom.parentNode(inst.domNode);\n if (parent !== null) ctx.dom.removeChild(parent, inst.domNode);\n inst.dispose();\n removed.push(inst);\n }\n\n // Reorder DOM nodes to match new order\n reorderDom(ctx, parentDom, newInstances);\n\n return { instances: newInstances, removed };\n}\n\n/**\n * Plan-based keyed reconciliation (spec §15 — the optimised reactive-list path).\n *\n * Identical observable result to {@link reconcileChildren}, but driven by lazy\n * {@link PlanEntry} descriptors instead of a pre-built array of GraphNodes:\n *\n * - a reused row whose `item` reference is unchanged does **zero** work — no\n * signature hash, no subtree build, no prop patch (the common case for\n * append / prepend / remove / reorder / reverse, where existing item objects\n * keep their identity);\n * - a reused row whose reference changed hashes lazily and, only on a real\n * signature change, materialises a fresh subtree for a targeted in-place\n * content update;\n * - a genuinely new key builds + mounts exactly one subtree.\n *\n * DOM reordering uses a longest-increasing-subsequence pass so the number of\n * moves is minimal (e.g. a prepend into a 10k list moves 1 node, not 10k).\n */\nexport function reconcileChildrenByPlan(\n ctx: RenderContext,\n parentDom: Element,\n oldInstances: NodeInstance[],\n plan: readonly PlanEntry[],\n mountFn: MountFn,\n hooks?: TransitionHooks,\n): ReconcileResult {\n const oldByKey = new Map<string, NodeInstance>();\n for (const inst of oldInstances) {\n oldByKey.set(inst.graphNode.key ?? inst.graphNode.id, inst);\n }\n\n const newInstances: NodeInstance[] = [];\n const usedKeys = new Set<string>();\n const built: GraphNode[] = [];\n\n for (const entry of plan) {\n const existing = oldByKey.get(entry.key);\n if (existing !== undefined) {\n usedKeys.add(entry.key);\n const oldItem = existing.graphNode.getProp('_item');\n // Identity short-circuit: same reference ⇒ data cannot have changed.\n if (!Object.is(oldItem, entry.item)) {\n const newSig = entry.sig();\n const oldSig = existing.graphNode.getProp('_sig');\n if (!Object.is(oldSig, newSig)) {\n const freshNode = entry.build();\n built.push(freshNode);\n patchExistingInstance(ctx, existing, freshNode);\n reconcileItemChildren(ctx, existing, freshNode, mountFn);\n existing.graphNode.setProp('_sig', newSig);\n }\n // Cache the new reference so the next pass can short-circuit again.\n existing.graphNode.setProp('_item', entry.item as never);\n }\n newInstances.push(existing);\n } else {\n // Leave→enter reclaim (§6/§7): a key removed then re-added mid-leave keeps\n // its identity and its live DOM node rather than mounting a duplicate.\n const reclaimed = hooks?.takeLeaving(entry.key);\n if (reclaimed !== undefined) {\n const freshNode = entry.build();\n built.push(freshNode);\n patchExistingInstance(ctx, reclaimed, freshNode);\n reconcileItemChildren(ctx, reclaimed, freshNode, mountFn);\n reclaimed.graphNode.setProp('_sig', freshNode.getProp('_sig') as never);\n reclaimed.graphNode.setProp('_item', entry.item as never);\n hooks?.onEnter(reclaimed);\n newInstances.push(reclaimed);\n } else {\n const freshNode = entry.build();\n built.push(freshNode);\n const inst = mountFn(freshNode, parentDom);\n hooks?.onEnter(inst);\n newInstances.push(inst);\n }\n }\n }\n\n // Determine + remove stale instances. Transitioned rows defer their whole\n // teardown chain to leave-animation end (§7) and are excluded from `removed`.\n const removed: NodeInstance[] = [];\n for (const inst of oldInstances) {\n const key = inst.graphNode.key ?? inst.graphNode.id;\n if (usedKeys.has(key)) continue;\n if (hooks !== undefined && hooks.beginLeave(inst)) continue;\n const parent = ctx.dom.parentNode(inst.domNode);\n if (parent !== null) ctx.dom.removeChild(parent, inst.domNode);\n inst.dispose();\n removed.push(inst);\n }\n\n // Minimal-move reorder to the desired order.\n reorderDomMinimal(ctx, parentDom, oldInstances, newInstances);\n\n return { instances: newInstances, removed, built };\n}\n\n/**\n * Minimal-move DOM reorder.\n *\n * Reused nodes retain their previous DOM slots and newly-mounted nodes sit at\n * the end. We compute the longest increasing subsequence of the reused nodes'\n * previous positions; those are already in correct relative order and stay put.\n * Every other node is inserted before its right-hand neighbour, walking\n * right-to-left. This yields exactly (n − |LIS|) `insertBefore` calls — the\n * minimum — instead of the O(n) sweep the naive reorder performs on a prepend.\n */\nfunction reorderDomMinimal(\n ctx: RenderContext,\n parentDom: Element,\n oldInstances: NodeInstance[],\n newInstances: NodeInstance[],\n): void {\n const n = newInstances.length;\n if (n === 0) return;\n\n const oldIndexOf = new Map<NodeInstance, number>();\n for (let i = 0; i < oldInstances.length; i++) oldIndexOf.set(oldInstances[i]!, i);\n\n const source = new Array<number>(n);\n let moved = false;\n let lastSeen = -1;\n for (let i = 0; i < n; i++) {\n const oi = oldIndexOf.get(newInstances[i]!);\n if (oi === undefined) {\n source[i] = -1; // freshly mounted row\n moved = true;\n } else {\n source[i] = oi;\n if (oi < lastSeen) moved = true; // an out-of-order reused row exists\n else lastSeen = oi;\n }\n }\n\n // Fast path: nothing is out of order and there are no new rows to reposition.\n if (!moved) return;\n\n const keep = longestIncreasingSubsequence(source);\n\n let refNode: Node | null = null;\n for (let i = n - 1; i >= 0; i--) {\n const domNode = newInstances[i]!.domNode;\n if (source[i] === -1 || !keep.has(i)) {\n if (ctx.dom.nextSibling(domNode) !== refNode) {\n ctx.dom.insertBefore(parentDom, domNode, refNode);\n }\n }\n refNode = domNode;\n }\n}\n\n/**\n * Indices (into `source`) forming a longest strictly-increasing subsequence,\n * ignoring `-1` entries (new rows, which always move). O(n log n) with\n * predecessor reconstruction.\n */\nfunction longestIncreasingSubsequence(source: readonly number[]): Set<number> {\n const keep = new Set<number>();\n const n = source.length;\n const tails: number[] = []; // tails[k] = source-index of smallest tail of an LIS of length k+1\n const prev = new Array<number>(n).fill(-1);\n\n for (let i = 0; i < n; i++) {\n const v = source[i]!;\n if (v < 0) continue;\n let lo = 0;\n let hi = tails.length;\n while (lo < hi) {\n const mid = (lo + hi) >> 1;\n if (source[tails[mid]!]! < v) lo = mid + 1;\n else hi = mid;\n }\n if (lo > 0) prev[i] = tails[lo - 1]!;\n tails[lo] = i;\n }\n\n let idx = tails.length > 0 ? tails[tails.length - 1]! : -1;\n while (idx >= 0) {\n keep.add(idx);\n idx = prev[idx]!;\n }\n return keep;\n}\n\n/**\n * Targeted in-place content update for a reused list item whose data changed.\n *\n * The item's DOM element is kept; only its contents are updated. Children are\n * matched positionally against the freshly-built subtree:\n * - same node type at a position → the existing child is reused and its props\n * are patched in place (e.g. a text node's text is rewritten), then we\n * recurse into its children;\n * - different type / new position → the fresh child node is reparented onto the\n * live item node and mounted;\n * - surplus old children → disposed, with DOM, subscriptions, listeners and\n * handler registrations all torn down.\n *\n * This deliberately reuses the same keyed/positional strategy rather than a\n * virtual DOM, and never destroys the item element itself.\n */\nfunction reconcileItemChildren(\n ctx: RenderContext,\n itemInstance: NodeInstance,\n newItemNode: GraphNode,\n mountFn: MountFn,\n): void {\n const el = itemInstance.domNode;\n if (!ctx.dom.isElement(el)) return;\n\n const oldChildren = [...itemInstance.children];\n const newChildNodes = [...newItemNode.children];\n const nextChildren: NodeInstance[] = [];\n const kept = new Set<NodeInstance>();\n\n for (let i = 0; i < newChildNodes.length; i++) {\n const newChild = newChildNodes[i]!;\n const oldChild = oldChildren[i];\n\n if (oldChild !== undefined && oldChild.graphNode.type === newChild.type) {\n // Reuse in place — patch this node's props and recurse into descendants.\n patchExistingInstance(ctx, oldChild, newChild);\n reconcileItemChildren(ctx, oldChild, newChild, mountFn);\n nextChildren.push(oldChild);\n kept.add(oldChild);\n } else {\n // Structural change at this position — mount the fresh child. Reparent it\n // out of the freshly-built subtree so the wholesale detach of the\n // unadopted item node (in mount.ts) does not remove this now-live node.\n itemInstance.graphNode.appendChild(newChild);\n const inst = mountFn(newChild, el);\n nextChildren.push(inst);\n }\n }\n\n // Dispose old children that were not reused (surplus or type-mismatched).\n for (const old of oldChildren) {\n if (kept.has(old)) continue;\n const parent = ctx.dom.parentNode(old.domNode);\n if (parent !== null) ctx.dom.removeChild(parent, old.domNode);\n old.dispose();\n forgetInstanceTree(ctx, old);\n ctx.graph.detachNode(old.graphNode);\n }\n\n // Restore correct DOM order within the item element.\n reorderDom(ctx, el, nextChildren);\n\n // Sync the live instance's children.\n itemInstance.children.length = 0;\n for (const c of nextChildren) itemInstance.children.push(c);\n\n // Keep the graph model's item children consistent with the reconciled order.\n for (const c of [...itemInstance.graphNode.children]) {\n itemInstance.graphNode.removeChild(c);\n }\n for (const c of nextChildren) itemInstance.graphNode.appendChild(c.graphNode);\n}\n\n/** Move a parent's DOM children to match the given instance order (minimal moves). */\nfunction reorderDom(\n ctx: RenderContext,\n parentDom: Element,\n instances: NodeInstance[],\n): void {\n let referenceNode: Node | null = null;\n for (let i = instances.length - 1; i >= 0; i--) {\n const inst = instances[i];\n if (inst === undefined) continue;\n const domNode = inst.domNode;\n const currentNext = ctx.dom.nextSibling(domNode);\n if (currentNext !== referenceNode) {\n ctx.dom.insertBefore(parentDom, domNode, referenceNode);\n }\n referenceNode = domNode;\n }\n}\n\n/** Recursively drop an instance subtree from the renderer's instance index. */\nfunction forgetInstanceTree(ctx: RenderContext, instance: NodeInstance): void {\n ctx.instances.delete(instance.graphNode.id);\n for (const child of instance.children) forgetInstanceTree(ctx, child);\n}\n\nfunction patchExistingInstance(\n ctx: RenderContext,\n instance: NodeInstance,\n newNode: GraphNode,\n): void {\n const oldNode = instance.graphNode;\n for (const [key, newVal] of Object.entries(newNode.props)) {\n const oldVal = oldNode.getProp(key);\n if (!Object.is(oldVal, newVal)) {\n patchNode(ctx, instance.graphNode, key, newVal);\n }\n }\n}\n","/**\n * CSS class-based enter/leave transition controller (§2–§8).\n *\n * This is the browser-only runtime that consumes the `__transition__<nodeId>`\n * descriptor the DSL registers (a pre-resolved {@link ResolvedTransitionLike}).\n * It is deliberately structural about that descriptor — like the renderer's\n * `__overlay__`/`__component__` handling — so the renderer takes NO compile-time\n * dependency on the DSL package.\n *\n * Engine (confirmed decision): CSS classes, no Web Animations API, no\n * browser-only API referenced at module scope. Every timer / rAF / event\n * binding is reached lazily through `globalThis` and only ever runs when\n * `dom.body() !== null` (the same SSR guard `wireOverlayBehavior` uses), so:\n * - server output is byte-identical (nothing here runs during SSR — §21);\n * - happy-dom, which dispatches no `transitionend`/`animationend`, still\n * completes deterministically via the fallback timeout (§24).\n *\n * The controller is created once per reactive container instance (reactive-list\n * or conditional) so its `leaving` map survives across reconcile passes — that\n * is what makes leave→enter reclaim (§6) and keyed-identity list leave (§7)\n * correct.\n */\n\nimport type { DOMAdapter } from '@streetui/dom';\nimport type { ApplicationGraph, GraphNode } from '@streetui/graph';\nimport type { NodeInstance } from './node-instance.js';\n\n/**\n * The renderer's structural view of the resolved transition the DSL stores in\n * `__transition__<id>`. Mirrors `@streetui/dsl`'s `ResolvedTransition` without\n * importing it (no renderer→dsl dependency).\n */\nexport interface ResolvedTransitionLike {\n readonly enterActive: readonly string[];\n readonly enterFrom: readonly string[];\n readonly enterTo: readonly string[];\n readonly leaveActive: readonly string[];\n readonly leaveFrom: readonly string[];\n readonly leaveTo: readonly string[];\n readonly appear: boolean;\n readonly duration: number;\n}\n\n/**\n * Hooks handed to the reconciler so it can (a) reclaim an instance that is\n * mid-leave when its key re-enters (leave→enter cancellation), (b) defer the\n * remove/dispose/forget/detach chain for a leaving instance until its animation\n * ends, and (c) play the enter animation for a freshly-inserted instance. When\n * no transition applies (or we are on the server) every hook degrades to the\n * pre-transition synchronous behaviour.\n */\nexport interface TransitionHooks {\n /**\n * If an instance for `key` is currently animating out, cancel its leave and\n * return it for reuse; otherwise undefined. The caller re-mounts nothing and\n * reuses the returned instance's live DOM node.\n */\n takeLeaving(key: string): NodeInstance | undefined;\n /**\n * Begin a leave animation for a removed instance. Returns true when the whole\n * teardown chain has been deferred to animation-end (caller must NOT remove,\n * dispose, forget or detach it), or false when there is no transition / no\n * browser and the caller should tear it down synchronously as before.\n */\n beginLeave(inst: NodeInstance): boolean;\n /** Play the enter animation for a freshly-inserted (or reclaimed) instance. */\n onEnter(inst: NodeInstance): void;\n}\n\n/** Read the pre-resolved transition descriptor for a node, if any. */\nexport function getResolvedTransition(\n graph: ApplicationGraph,\n nodeId: string,\n): ResolvedTransitionLike | undefined {\n const fn = graph.getHandler(`__transition__${nodeId}`) as\n | (() => ResolvedTransitionLike)\n | undefined;\n return fn === undefined ? undefined : fn();\n}\n\n// ── Browser-global access (lazy, never at module scope) ──────────────────────\n\ninterface RafHost {\n requestAnimationFrame?: (cb: () => void) => number;\n setTimeout: (cb: () => void, ms: number) => unknown;\n clearTimeout: (h: unknown) => void;\n}\n\nfunction host(): RafHost {\n return globalThis as unknown as RafHost;\n}\n\n/** Schedule a callback for the next frame (falls back to a macrotask). */\nfunction nextFrame(cb: () => void): void {\n const h = host();\n const raf = h.requestAnimationFrame;\n if (typeof raf === 'function') {\n // Double rAF: ensures the \"from\" classes have been painted before we flip\n // to the \"to\" classes, so the transition actually runs in real browsers.\n raf(() => raf(cb));\n } else {\n h.setTimeout(cb, 0);\n }\n}\n\n// ── Class list manipulation via the adapter (no classList dependency) ─────────\n\nfunction splitClass(value: string | null): string[] {\n if (value === null) return [];\n const out: string[] = [];\n for (const t of value.split(/\\s+/)) if (t.length > 0) out.push(t);\n return out;\n}\n\nfunction addClasses(dom: DOMAdapter, el: Element, classes: readonly string[]): void {\n if (classes.length === 0) return;\n const current = splitClass(dom.getAttribute(el, 'class'));\n let changed = false;\n for (const c of classes) {\n if (!current.includes(c)) {\n current.push(c);\n changed = true;\n }\n }\n if (changed) dom.setAttribute(el, 'class', current.join(' '));\n}\n\nfunction removeClasses(dom: DOMAdapter, el: Element, classes: readonly string[]): void {\n if (classes.length === 0) return;\n const current = splitClass(dom.getAttribute(el, 'class'));\n const next = current.filter((c) => !classes.includes(c));\n if (next.length !== current.length) {\n if (next.length === 0) dom.removeAttribute(el, 'class');\n else dom.setAttribute(el, 'class', next.join(' '));\n }\n}\n\n/**\n * One running enter-or-leave animation on a single element. Owns exactly one set\n * of DOM listeners + one fallback timer, and guarantees `settle`/`cancel` run\n * their cleanup at most once — no stale callbacks, no duplicate listeners, no\n * duplicate cleanup (§6).\n */\ninterface Run {\n /** Force the animation to its end synchronously (used by cancellation). */\n cancel(): void;\n}\n\nfunction startRun(\n dom: DOMAdapter,\n el: Element,\n active: readonly string[],\n from: readonly string[],\n to: readonly string[],\n duration: number,\n onDone: () => void,\n): Run {\n const h = host();\n let finished = false;\n let timer: unknown = null;\n\n const onEvent = ((e: Event): void => {\n // Ignore bubbling transition/animation events from descendants.\n if (e.target !== el) return;\n finish();\n }) as EventListener;\n\n const detach = (): void => {\n dom.removeEventListener(el, 'transitionend', onEvent);\n dom.removeEventListener(el, 'animationend', onEvent);\n if (timer !== null) {\n h.clearTimeout(timer);\n timer = null;\n }\n };\n\n const finish = (): void => {\n if (finished) return;\n finished = true;\n detach();\n // Clear all transition classes so the element rests in its natural state.\n removeClasses(dom, el, active);\n removeClasses(dom, el, to);\n removeClasses(dom, el, from);\n onDone();\n };\n\n // Phase 1: apply the starting + active classes immediately.\n addClasses(dom, el, from);\n addClasses(dom, el, active);\n\n dom.addEventListener(el, 'transitionend', onEvent);\n dom.addEventListener(el, 'animationend', onEvent);\n // Fallback completion: the safety net for elements that fire no transition\n // event (and the ONLY completion signal under happy-dom, where tests set a\n // small duration). 0 → next macrotask.\n timer = h.setTimeout(finish, duration);\n\n // Phase 2: on the next frame flip from → to so the CSS transition runs.\n nextFrame(() => {\n if (finished) return;\n removeClasses(dom, el, from);\n addClasses(dom, el, to);\n });\n\n return {\n cancel: () => {\n // Cancel = settle immediately (removes classes, clears listeners/timer)\n // but WITHOUT invoking onDone, so a cancelled leave never finalizes the\n // node it was about to destroy.\n if (finished) return;\n finished = true;\n detach();\n removeClasses(dom, el, active);\n removeClasses(dom, el, to);\n removeClasses(dom, el, from);\n },\n };\n}\n\ninterface LeavingEntry {\n readonly inst: NodeInstance;\n readonly run: Run;\n}\n\n/** Which half of a transition to play on a bare element. */\nexport type TransitionPhase = 'enter' | 'leave';\n\n/**\n * Play one enter/leave transition on a bare DOM element, outside the keyed\n * reconciler — the seam the router uses for route leave/enter (§9) and any other\n * consumer that owns a single host element rather than a reactive container.\n *\n * Reuses the exact same {@link startRun} mechanics as list/conditional\n * transitions (from+active applied immediately, next-frame flip to `to`,\n * completion on transitionend/animationend or the fallback timer), so there is\n * one transition engine, not two. The returned handle's `cancel()` settles the\n * run immediately WITHOUT invoking `onDone` — the caller uses it to abort an\n * in-flight enter when the same host is about to start leaving (rapid\n * navigation), avoiding overlapping runs/duplicate listeners on one element.\n *\n * On the server (or any non-element target) there is nothing to animate, so\n * `onDone` runs synchronously and `cancel()` is a no-op — the caller's teardown\n * still happens exactly once.\n */\nexport function runElementTransition(\n dom: DOMAdapter,\n el: Element,\n rt: ResolvedTransitionLike,\n phase: TransitionPhase,\n onDone: () => void,\n): { cancel(): void } {\n if (dom.body() === null || !dom.isElement(el)) {\n onDone();\n return { cancel: () => {} };\n }\n const active = phase === 'enter' ? rt.enterActive : rt.leaveActive;\n const from = phase === 'enter' ? rt.enterFrom : rt.leaveFrom;\n const to = phase === 'enter' ? rt.enterTo : rt.leaveTo;\n return startRun(dom, el, active, from, to, rt.duration, onDone);\n}\n\n\n/**\n * Per-container transition controller. One instance is created for each\n * reactive-list / conditional NodeInstance in {@link wireReactiveList}; its\n * `leaving` map persists across every reconcile of that container.\n */\nexport class TransitionController {\n private readonly leaving = new Map<string, LeavingEntry>();\n\n constructor(\n private readonly dom: DOMAdapter,\n private readonly graph: ApplicationGraph,\n /** Full teardown of a leaving instance (remove + dispose + forget + detach). */\n private readonly finalize: (inst: NodeInstance) => void,\n ) {}\n\n /** True only in a real DOM environment (browser). */\n private get browser(): boolean {\n return this.dom.body() !== null;\n }\n\n private keyOf(inst: NodeInstance): string {\n return inst.graphNode.key ?? inst.graphNode.id;\n }\n\n private resolved(node: GraphNode): ResolvedTransitionLike | undefined {\n return getResolvedTransition(this.graph, node.id);\n }\n\n /** Run the enter animation for `inst` if it carries a transition (browser only). */\n enter(inst: NodeInstance): void {\n if (!this.browser) return;\n const rt = this.resolved(inst.graphNode);\n if (rt === undefined) return;\n const el = inst.domNode;\n if (!this.dom.isElement(el)) return;\n startRun(this.dom, el, rt.enterActive, rt.enterFrom, rt.enterTo, rt.duration, () => {\n /* enter has no teardown; classes already cleared by the run */\n });\n }\n\n /**\n * Play `appear` for any initial child that opted into it (fresh browser mount\n * only — hydration must never animate appear, §22, and this is called only on\n * the mount path).\n */\n appear(children: readonly NodeInstance[]): void {\n if (!this.browser) return;\n for (const child of children) {\n const rt = this.resolved(child.graphNode);\n if (rt !== undefined && rt.appear) this.enter(child);\n }\n }\n\n hooks(): TransitionHooks {\n return {\n takeLeaving: (key) => {\n const entry = this.leaving.get(key);\n if (entry === undefined) return undefined;\n entry.run.cancel(); // leave→enter: stop the leave, keep the live node\n this.leaving.delete(key);\n return entry.inst;\n },\n beginLeave: (inst) => {\n if (!this.browser) return false;\n const rt = this.resolved(inst.graphNode);\n if (rt === undefined) return false;\n const el = inst.domNode;\n if (!this.dom.isElement(el)) return false;\n const key = this.keyOf(inst);\n // If a prior leave for this key is somehow still running, settle it.\n const prior = this.leaving.get(key);\n if (prior !== undefined) prior.run.cancel();\n const run = startRun(\n this.dom,\n el,\n rt.leaveActive,\n rt.leaveFrom,\n rt.leaveTo,\n rt.duration,\n () => {\n // Only finalize if THIS run is still the registered one (it may have\n // been reclaimed by a re-entering key, which cancels without done).\n const current = this.leaving.get(key);\n if (current !== undefined && current.run === run) {\n this.leaving.delete(key);\n this.finalize(inst);\n }\n },\n );\n this.leaving.set(key, { inst, run });\n return true;\n },\n onEnter: (inst) => this.enter(inst),\n };\n }\n}\n","/**\n * Document head / metadata runtime (2.0 §1–§3).\n *\n * Two entry points, sharing the normalized {@link HeadEntry} model the DSL's\n * `head()` produces (mirrored here as a local structural type so the renderer\n * takes no compile-time dependency on the DSL package — the same convention as\n * the overlay/component descriptors):\n *\n * • `wireHeadBehavior(ctx, node, instance)` — BROWSER. Reads the\n * `__head__<id>` descriptor, registers this node's contribution with a\n * per-render {@link HeadManager} (created lazily on `ctx`), subscribes to any\n * reactive attr/text signals, and tracks cleanup on the NodeInstance so the\n * contribution is withdrawn (and the manager re-applies the merged result)\n * when the node unmounts or the route changes. Server-safe: when\n * `dom.head()` is null (SSR) it is a no-op.\n *\n * • `renderHead(compiled)` — SERVER. Walks the compiled graph in document\n * order, merges every live `head()` contribution (last-in-document-order\n * wins per dedup key — §3), and serializes the effective tags to an HTML\n * string for the caller to place inside `<head>`. Only the active graph is\n * walked, so only active-route metadata is emitted (§2). Each tag carries\n * `data-streetui-head` + `data-streetui-head-key=\"…\"` so the browser adopts\n * it on hydration instead of creating a duplicate.\n */\n\nimport type { GraphNode, ApplicationGraph } from '@streetui/graph';\nimport { ServerDOMAdapter } from '@streetui/dom';\nimport type { CompiledApplication } from '@streetui/compiler';\nimport type { DOMAdapter } from '@streetui/dom';\nimport type { RenderContext } from './render-context.js';\nimport type { NodeInstance } from './node-instance.js';\n\n/** The marker attribute stamped on every framework-managed head tag. */\nconst HEAD_MARKER = 'data-streetui-head';\n/** The attribute carrying a tag's dedup key, so hydration can match server tags. */\nconst HEAD_KEY = 'data-streetui-head-key';\n\n// ── Structural mirror of the DSL's head entry model ─────────────────────────────\n\ninterface HeadEntryLike {\n readonly tag: 'title' | 'meta' | 'link' | 'base';\n readonly dedupKey: string;\n readonly attrs: Readonly<Record<string, unknown>>;\n readonly text?: unknown;\n}\ninterface HeadContributionLike {\n readonly entries: readonly HeadEntryLike[];\n}\n\ninterface SignalLike {\n subscribe: (fn: (v: unknown) => void) => () => void;\n peek: () => unknown;\n}\n\nfunction isSignalLike(v: unknown): v is SignalLike {\n return (\n v !== null &&\n typeof v === 'object' &&\n typeof (v as Record<string, unknown>)['subscribe'] === 'function' &&\n typeof (v as Record<string, unknown>)['peek'] === 'function'\n );\n}\n\n/** Read a bindable value to its current string (peeking a signal, else stringifying). */\nfunction readValue(v: unknown): string {\n if (isSignalLike(v)) return String(v.peek() ?? '');\n return String(v ?? '');\n}\n\n/** A fully-resolved head tag: concrete strings, ready to write to the DOM/serialize. */\ninterface ResolvedTag {\n readonly tag: 'title' | 'meta' | 'link' | 'base';\n readonly attrs: Record<string, string>;\n readonly text?: string;\n}\n\nfunction resolveEntry(entry: HeadEntryLike): ResolvedTag {\n const attrs: Record<string, string> = {};\n for (const key of Object.keys(entry.attrs)) {\n attrs[key] = readValue(entry.attrs[key]);\n }\n const resolved: ResolvedTag = { tag: entry.tag, attrs };\n if (entry.tag === 'title') {\n return { ...resolved, text: readValue(entry.text) };\n }\n return resolved;\n}\n\n// ── Browser head manager ────────────────────────────────────────────────────────\n\ninterface AppliedRecord {\n el: Element;\n attrKeys: Set<string>;\n tag: string;\n}\n\n/**\n * Coordinates every live `head()` node's contribution into a single\n * `document.head`. One instance per render (lazily created on `ctx`). Merges by\n * dedup key with last-in-document-order winning, and applies the minimal diff to\n * the DOM on every register/unregister/signal change. Adopts server-emitted tags\n * on the first apply so hydration produces no duplicates.\n */\nexport class HeadManager {\n private readonly _dom: DOMAdapter;\n private readonly _head: Element;\n private readonly _contributions = new Map<string, { order: number; entries: readonly HeadEntryLike[] }>();\n private readonly _applied = new Map<string, AppliedRecord>();\n private _order = 0;\n private _adopted = false;\n\n constructor(dom: DOMAdapter, head: Element) {\n this._dom = dom;\n this._head = head;\n }\n\n /** Register (or replace) a node's contribution and re-apply the merged result. */\n register(nodeId: string, entries: readonly HeadEntryLike[]): void {\n this._contributions.set(nodeId, { order: this._order++, entries });\n this.apply();\n }\n\n /** Withdraw a node's contribution (unmount / route change) and re-apply. */\n unregister(nodeId: string): void {\n if (this._contributions.delete(nodeId)) this.apply();\n }\n\n /** Recompute the merged head and patch `document.head` to match. */\n apply(): void {\n if (!this._adopted) {\n this._adoptServerTags();\n this._adopted = true;\n }\n\n // Merge: iterate contributions in document order; per dedup key the last\n // writer wins (§3). Within a contribution, later entries win too.\n const ordered = [...this._contributions.values()].sort((a, b) => a.order - b.order);\n const merged = new Map<string, ResolvedTag>();\n for (const contribution of ordered) {\n for (const entry of contribution.entries) {\n merged.set(entry.dedupKey, resolveEntry(entry));\n }\n }\n\n // Upsert desired tags.\n for (const [key, desired] of merged) {\n const existing = this._applied.get(key);\n if (existing !== undefined && existing.tag === desired.tag) {\n this._reconcileAttrs(existing, desired);\n } else {\n if (existing !== undefined) {\n // Tag kind changed for this key (rare) — drop the old element.\n this._dom.removeChild(this._head, existing.el);\n this._applied.delete(key);\n }\n const el = this._createTag(key, desired);\n this._dom.appendChild(this._head, el);\n this._applied.set(key, { el, attrKeys: new Set(Object.keys(desired.attrs)), tag: desired.tag });\n }\n }\n\n // Remove managed tags no longer desired.\n for (const [key, record] of [...this._applied]) {\n if (!merged.has(key)) {\n this._dom.removeChild(this._head, record.el);\n this._applied.delete(key);\n }\n }\n }\n\n private _createTag(key: string, desired: ResolvedTag): Element {\n const el = this._dom.createElement(desired.tag);\n this._dom.setAttribute(el, HEAD_MARKER, '');\n this._dom.setAttribute(el, HEAD_KEY, key);\n for (const attr of Object.keys(desired.attrs)) {\n this._dom.setAttribute(el, attr, desired.attrs[attr]!);\n }\n if (desired.tag === 'title') this._dom.setTextContent(el, desired.text ?? '');\n return el;\n }\n\n private _reconcileAttrs(record: AppliedRecord, desired: ResolvedTag): void {\n const nextKeys = new Set(Object.keys(desired.attrs));\n // Remove attrs that are no longer present.\n for (const attr of record.attrKeys) {\n if (!nextKeys.has(attr)) this._dom.removeAttribute(record.el, attr);\n }\n // Set/overwrite desired attrs (idempotent when unchanged — matters on the\n // hydration adopt path, where the element is a server tag being re-asserted).\n for (const attr of nextKeys) {\n this._dom.setAttribute(record.el, attr, desired.attrs[attr]!);\n }\n if (desired.tag === 'title') this._dom.setTextContent(record.el, desired.text ?? '');\n record.attrKeys = nextKeys;\n }\n\n /**\n * Seed `_applied` from server-emitted `[data-streetui-head-key]` tags already\n * in `document.head`. The subsequent diff reuses these elements when the\n * client desires the same key (no duplicate), rewrites them if the value\n * changed, or removes them if the client graph no longer wants them.\n */\n private _adoptServerTags(): void {\n for (const child of this._dom.childNodes(this._head)) {\n if (!this._dom.isElement(child)) continue;\n const el = child as Element;\n const key = this._dom.getAttribute(el, HEAD_KEY);\n if (key === null) continue;\n this._applied.set(key, {\n el,\n attrKeys: new Set(this._attrNames(el)),\n tag: this._dom.tagName(el),\n });\n }\n }\n\n /** The framework-managed attribute names currently on a server tag. */\n private _attrNames(el: Element): string[] {\n // We cannot enumerate a live element's attributes through the minimal\n // DOMAdapter surface, so we re-assert from the desired set on first apply\n // (see `_reconcileAttrs`, which sets desired keys and removes only tracked\n // ones). Tracking the marker keys is enough to keep them from lingering.\n const names: string[] = [];\n if (this._dom.getAttribute(el, HEAD_MARKER) !== null) names.push(HEAD_MARKER);\n if (this._dom.getAttribute(el, HEAD_KEY) !== null) names.push(HEAD_KEY);\n return names;\n }\n}\n\n/** Lazily get (or create) the render's HeadManager. Null on the server. */\nfunction getHeadManager(ctx: RenderContext): HeadManager | null {\n const head = ctx.dom.head();\n if (head === null) return null; // server render pass — renderHead handles SSR\n const mutable = ctx as { head?: HeadManager };\n if (mutable.head === undefined) mutable.head = new HeadManager(ctx.dom, head);\n return mutable.head;\n}\n\n/**\n * Wire a mounted/hydrated `head` node's contribution into `document.head`.\n * Server-safe (no-op when there is no document). Shared by the mount and hydrate\n * paths so both establish identical ownership + cleanup.\n */\nexport function wireHeadBehavior(\n ctx: RenderContext,\n graphNode: GraphNode,\n instance: NodeInstance,\n): void {\n const manager = getHeadManager(ctx);\n if (manager === null) return;\n\n const descFn = ctx.graph.getHandler(`__head__${graphNode.id}`) as\n | (() => HeadContributionLike)\n | undefined;\n if (descFn === undefined) return;\n\n const contribution = descFn();\n const nodeId = graphNode.id;\n manager.register(nodeId, contribution.entries);\n\n // Subscribe to any reactive attr/text signals; a change re-applies the merged\n // head. All subscriptions + the contribution withdrawal are tracked on the\n // instance, so a route change / unmount tears them down and re-applies.\n for (const entry of contribution.entries) {\n for (const attrKey of Object.keys(entry.attrs)) {\n const v = entry.attrs[attrKey];\n if (isSignalLike(v)) {\n instance.trackCleanup(v.subscribe(() => manager.apply()));\n }\n }\n if (isSignalLike(entry.text)) {\n instance.trackCleanup(entry.text.subscribe(() => manager.apply()));\n }\n }\n\n instance.trackCleanup(() => manager.unregister(nodeId));\n}\n\n// ── Server-side head emission ─────────────────────────────────────────────────\n\n/**\n * Render the active graph's merged document metadata to an HTML string suitable\n * for placing inside `<head>`. Walks the graph in document order, merges every\n * `head()` contribution (last-in-document-order wins per dedup key), and\n * serializes each effective tag with the `data-streetui-head` marker so the\n * browser adopts it on hydration. Returns `''` when the app declares no metadata\n * — so apps that never call `head()` emit nothing extra and existing SSR output\n * is unchanged.\n */\nexport function renderHead(compiled: CompiledApplication): string {\n const graph: ApplicationGraph = compiled.graph;\n\n const merged = new Map<string, ResolvedTag>();\n graph.walk((node) => {\n if (node.type !== 'head') return;\n const descFn = graph.getHandler(`__head__${node.id}`) as\n | (() => HeadContributionLike)\n | undefined;\n if (descFn === undefined) return;\n for (const entry of descFn().entries) {\n merged.set(entry.dedupKey, resolveEntry(entry));\n }\n });\n\n if (merged.size === 0) return '';\n\n const dom = new ServerDOMAdapter();\n let out = '';\n for (const [key, desired] of merged) {\n const el = dom.createElement(desired.tag);\n dom.setAttribute(el, HEAD_MARKER, '');\n dom.setAttribute(el, HEAD_KEY, key);\n for (const attr of Object.keys(desired.attrs)) {\n dom.setAttribute(el, attr, desired.attrs[attr]!);\n }\n if (desired.tag === 'title') dom.setTextContent(el, desired.text ?? '');\n out += dom.serializeOuter(el);\n }\n return out;\n}\n","/**\n * Initial mount — creates DOM nodes for every GraphNode and\n * attaches them into the container.\n *\n * This is a recursive depth-first walk. For each GraphNode:\n * 1. Create the DOM element (or text node)\n * 2. Apply props/attributes\n * 3. Wire events\n * 4. Wire signal subscriptions for reactive props\n * 5. Recurse into children\n * 6. Insert into the DOM\n */\n\nimport type { GraphNode, ApplicationGraph } from '@streetui/graph';\nimport type { DOMAdapter } from '@streetui/dom';\nimport {\n focusInitial,\n trapFocus,\n containFocus,\n onEscape,\n rovingMenu,\n saveFocus,\n restoreFocus,\n} from '@streetui/dom';\nimport type { RenderContext } from './render-context.js';\nimport { NodeInstance } from './node-instance.js';\nimport { applyProp } from './attributes.js';\nimport { wireEvents } from './events.js';\nimport { resolveTag } from './tag-map.js';\nimport {\n reconcileChildren,\n reconcileChildrenByPlan,\n type PlanEntry,\n} from './reconciliation.js';\nimport { TransitionController, type TransitionHooks } from './transition.js';\nimport { wireHeadBehavior } from './head.js';\n\n/**\n * Prop keys handled by the per-type mount branches (or reserved internals), so\n * `applyNodeProps` must skip them to avoid double-applying. This set is\n * invariant across nodes, so it is hoisted to module scope: allocating it once\n * (rather than per node) removes N Set allocations per mount/SSR pass and the\n * GC pressure they create. Treat as read-only — never mutate.\n */\nconst SKIP_PROP_KEYS: ReadonlySet<string> = new Set([\n 'text', 'label', 'level', 'inputType', 'src', 'alt', 'href', 'external',\n 'value', 'placeholder', 'disabled', '_renderKey', 'key', 'name',\n]);\n\nexport function mountGraph(ctx: RenderContext): NodeInstance {\n return mountNode(ctx, ctx.graph.root, ctx.container);\n}\n\nexport function mountNode(\n ctx: RenderContext,\n graphNode: GraphNode,\n parentDom: Node,\n): NodeInstance {\n const { dom, graph } = ctx;\n\n // ── v1.7 static SSR fast path (SSR-only) ──────────────────────────────────\n // When a compiler-derived static SSR plan is present (server render only)\n // and this node is a maximal static-subtree root, emit its precomputed HTML\n // verbatim instead of recursively constructing ServerElement/ServerText/\n // NodeInstance for the whole subtree. `ctx.staticHTML` is always undefined on\n // the browser path, so this is a single short-circuiting check there — the\n // client hot path and its semantics are untouched (§5/§6/§23). The stored\n // string is produced by this same mount+serialize pipeline, so output is\n // byte-identical (§8). We still register ONE NodeInstance for the root so the\n // parent's children bookkeeping and post-render dispose behave normally.\n const staticHTML = ctx.staticHTML;\n if (staticHTML !== undefined && dom.createRawHTML !== undefined) {\n const precomputed = staticHTML.get(graphNode.id);\n if (precomputed !== undefined) {\n const raw = dom.createRawHTML(precomputed);\n dom.appendChild(parentDom, raw);\n const instance = new NodeInstance(graphNode, raw);\n ctx.instances.set(graphNode.id, instance);\n return instance;\n }\n }\n\n // The application root node maps to the container itself — don't create a duplicate element\n if (graphNode.type === 'application') {\n const instance = new NodeInstance(graphNode, parentDom);\n ctx.instances.set(graphNode.id, instance);\n for (const child of graphNode.children) {\n const childInstance = mountNode(ctx, child, parentDom);\n instance.addChild(childInstance);\n }\n return instance;\n }\n\n // Text-only nodes render as a <span> containing a text node\n if (graphNode.type === 'text') {\n const text = String(graphNode.getProp('text') ?? '');\n const el = dom.createElement('span');\n const textNode = dom.createTextNode(text);\n dom.appendChild(el, textNode);\n applyNodeProps(ctx, graphNode, el);\n\n // Create the live instance up front and reuse it for event wiring. The\n // previous code allocated a throwaway NodeInstance solely to satisfy\n // wireEvents' signature, wasting one NodeInstance (+ its children array and\n // CleanupRegistry) per text node — pure GC pressure on the hottest mount\n // path. wireEvents/wireSignalBindings each early-return on empty arrays.\n const instance = new NodeInstance(graphNode, el);\n ctx.instances.set(graphNode.id, instance);\n wireEvents(dom, graph, graphNode, el, instance);\n\n // Reactive text binding — only build the update closure when the node has\n // bindings. wireSignalBindings early-returns on empty stateRefs, so for a\n // static text node (the common case in a large initial render) the\n // textUpdate closure would be allocated and thrown away: avoidable GC\n // pressure on the hottest mount path.\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, textUpdate(dom, el, textNode));\n }\n\n dom.appendChild(parentDom, el);\n return instance;\n }\n\n // Heading nodes\n if (graphNode.type === 'heading') {\n const level = (graphNode.getProp('level') as number | undefined) ?? 1;\n const tag = `h${level}` as string;\n const el = dom.createElement(tag);\n const text = String(graphNode.getProp('text') ?? '');\n dom.setTextContent(el, text);\n applyNodeProps(ctx, graphNode, el);\n\n const instance = new NodeInstance(graphNode, el);\n ctx.instances.set(graphNode.id, instance);\n wireEvents(dom, graph, graphNode, el, instance);\n\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, headingUpdate(dom, el));\n }\n\n dom.appendChild(parentDom, el);\n return instance;\n }\n\n // Input nodes\n if (graphNode.type === 'input') {\n const el = dom.createElement('input') as HTMLInputElement;\n const inputType = String(graphNode.getProp('inputType') ?? 'text');\n dom.setAttribute(el, 'type', inputType);\n const placeholder = graphNode.getProp('placeholder');\n if (placeholder !== undefined) dom.setAttribute(el, 'placeholder', String(placeholder));\n const value = graphNode.getProp('value');\n if (value !== undefined) dom.setProperty(el, 'value', String(value));\n applyNodeProps(ctx, graphNode, el);\n\n const instance = new NodeInstance(graphNode, el);\n ctx.instances.set(graphNode.id, instance);\n wireEvents(dom, graph, graphNode, el, instance);\n\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, inputUpdate(dom, el));\n }\n\n dom.appendChild(parentDom, el);\n return instance;\n }\n\n // Image nodes\n if (graphNode.type === 'image') {\n const el = dom.createElement('img') as HTMLImageElement;\n const src = graphNode.getProp('src');\n const alt = graphNode.getProp('alt');\n if (src !== undefined) dom.setAttribute(el, 'src', String(src));\n if (alt !== undefined) dom.setAttribute(el, 'alt', String(alt));\n const width = graphNode.getProp('width');\n const height = graphNode.getProp('height');\n if (width !== undefined) dom.setAttribute(el, 'width', String(width));\n if (height !== undefined) dom.setAttribute(el, 'height', String(height));\n applyNodeProps(ctx, graphNode, el);\n\n const instance = new NodeInstance(graphNode, el);\n ctx.instances.set(graphNode.id, instance);\n dom.appendChild(parentDom, el);\n return instance;\n }\n\n // Link nodes\n if (graphNode.type === 'link') {\n const el = dom.createElement('a') as HTMLAnchorElement;\n const href = graphNode.getProp('href');\n const label = graphNode.getProp('label');\n const external = graphNode.getProp('external');\n if (href !== undefined) dom.setAttribute(el, 'href', String(href));\n if (label !== undefined) dom.setTextContent(el, String(label));\n if (external === true) {\n dom.setAttribute(el, 'target', '_blank');\n dom.setAttribute(el, 'rel', 'noopener noreferrer');\n }\n applyNodeProps(ctx, graphNode, el);\n\n const instance = new NodeInstance(graphNode, el);\n ctx.instances.set(graphNode.id, instance);\n wireEvents(dom, graph, graphNode, el, instance);\n\n // A link's label/href may be bound to signals (e.g. i18n `t()` in nav). Wire\n // the same signal-binding path buttons use so the text updates reactively.\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, linkUpdate(dom, el));\n }\n\n dom.appendChild(parentDom, el);\n return instance;\n }\n\n // Button nodes\n if (graphNode.type === 'button') {\n const el = dom.createElement('button') as HTMLButtonElement;\n const label = graphNode.getProp('label');\n if (label !== undefined) dom.setTextContent(el, String(label));\n const disabled = graphNode.getProp('disabled');\n if (disabled === true) dom.setAttribute(el, 'disabled', '');\n applyNodeProps(ctx, graphNode, el);\n\n const instance = new NodeInstance(graphNode, el);\n ctx.instances.set(graphNode.id, instance);\n wireEvents(dom, graph, graphNode, el, instance);\n\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, buttonUpdate(dom, el));\n }\n\n dom.appendChild(parentDom, el);\n return instance;\n }\n\n // Reactive list / conditional — a container whose children are driven by a\n // Signal. Initial child subtrees are already built into the graph by the DSL;\n // on signal change we reconcile the freshly-built desired children against the\n // live DOM using the keyed reconciler (no virtual DOM). A `conditional` uses\n // the identical machinery but renders as a neutral <div> holding 0..1 branch.\n if (graphNode.type === 'reactive-list' || graphNode.type === 'conditional') {\n const tag = resolveTag(graphNode.type);\n const el = dom.createElement(tag);\n applyNodeProps(ctx, graphNode, el);\n\n const instance = new NodeInstance(graphNode, el);\n ctx.instances.set(graphNode.id, instance);\n\n for (const child of graphNode.children) {\n const childInstance = mountNode(ctx, child, el);\n instance.addChild(childInstance);\n }\n\n dom.appendChild(parentDom, el);\n wireReactiveList(ctx, graphNode, instance, el, true);\n return instance;\n }\n\n // Portal — a container whose children are relocated to a different DOM\n // location (document.body) on the browser, while a neutral inline anchor\n // stays at the declaration site. On the server there is no body, so the\n // children render inline in the anchor (deterministic HTML; hydration then\n // relocates them). This is the substrate for overlays (dialog/popover/…):\n // `wireOverlayBehavior` reads an optional `__overlay__<id>` descriptor and,\n // when present, wires focus trap/restore/containment/escape to the open\n // signal. A plain portal has no descriptor, so overlay wiring is a no-op.\n if (graphNode.type === 'portal') {\n const anchor = dom.createElement(resolveTag('portal'));\n dom.setAttribute(anchor, 'data-streetui-portal', '');\n applyNodeProps(ctx, graphNode, anchor);\n const instance = new NodeInstance(graphNode, anchor);\n ctx.instances.set(graphNode.id, instance);\n\n const body = dom.body();\n let target: Element = anchor; // SSR / no body → render inline in the anchor\n if (body !== null) {\n const portalContainer = dom.createElement('div');\n dom.setAttribute(portalContainer, 'data-streetui-portal-container', '');\n dom.appendChild(body, portalContainer);\n instance.trackCleanup(() => dom.removeChild(body, portalContainer));\n target = portalContainer;\n }\n\n for (const child of graphNode.children) {\n instance.addChild(mountNode(ctx, child, target));\n }\n\n dom.appendChild(parentDom, anchor);\n wireOverlayBehavior(ctx, graphNode, instance, target);\n return instance;\n }\n\n // Head — a metadata node (title/meta/link/base). Renders as a neutral inline\n // anchor at the declaration site (like a portal), while its contribution is\n // applied to `document.head` by `wireHeadBehavior` (browser) or emitted by\n // `renderHead` (server). No visible children; the anchor keeps hydration\n // structurally aligned with the SSR output.\n if (graphNode.type === 'head') {\n const anchor = dom.createElement(resolveTag('head'));\n dom.setAttribute(anchor, 'data-streetui-head-anchor', '');\n applyNodeProps(ctx, graphNode, anchor);\n const instance = new NodeInstance(graphNode, anchor);\n ctx.instances.set(graphNode.id, instance);\n\n dom.appendChild(parentDom, anchor);\n wireHeadBehavior(ctx, graphNode, instance);\n return instance;\n }\n\n // Container / section / page / form / list / list-item — structural nodes\n const tag = resolveTag(graphNode.type);\n const el = dom.createElement(tag);\n applyNodeProps(ctx, graphNode, el);\n\n // Surface a reactive-list item's stable, identity-only reconciliation key as a\n // public `data-streetui-key` attribute (e.g. \"id:1\"). This exposes only the\n // identity part — never the internal `_sig` value signature, signal ids or\n // graph node ids — so a row is directly selectable and its identity is\n // inspectable across reorders and in-place data updates.\n if (graphNode.type === 'list-item') {\n const itemKey = graphNode.getProp('key');\n if (itemKey !== undefined) {\n dom.setAttribute(el, 'data-streetui-key', String(itemKey));\n }\n }\n\n const instance = new NodeInstance(graphNode, el);\n ctx.instances.set(graphNode.id, instance);\n\n // wire form submit (reuse the live instance rather than a throwaway)\n if (graphNode.type === 'form') {\n wireEvents(dom, graph, graphNode, el, instance);\n }\n\n // Recurse into children\n for (const child of graphNode.children) {\n const childInstance = mountNode(ctx, child, el);\n instance.addChild(childInstance);\n }\n\n dom.appendChild(parentDom, el);\n if (graphNode.type === 'component') wireComponentBehavior(ctx, graphNode, instance);\n return instance;\n}\n\n// ── Helpers ───────────────────────────────────────────────────────────────────\n\n/**\n * Per-node-type reactive-binding factories. Each returns the `onUpdate`\n * callback that `wireSignalBindings` invokes when a bound signal changes.\n * Extracted so both the browser mount path and the hydration path apply the\n * exact same DOM mutation semantics for each prop — no duplicated rendering\n * logic.\n */\nexport function textUpdate(\n dom: DOMAdapter,\n el: Element,\n textNode: Text,\n): (propKey: string, value: unknown) => void {\n return (propKey, value) => {\n if (propKey === 'text') {\n dom.setTextContent(textNode, String(value ?? ''));\n } else {\n applyProp(dom, el, propKey, value);\n }\n };\n}\n\nexport function headingUpdate(\n dom: DOMAdapter,\n el: Element,\n): (propKey: string, value: unknown) => void {\n return (propKey, value) => {\n if (propKey === 'text') {\n dom.setTextContent(el, String(value ?? ''));\n } else {\n applyProp(dom, el, propKey, value);\n }\n };\n}\n\nexport function inputUpdate(\n dom: DOMAdapter,\n el: Element,\n): (propKey: string, value: unknown) => void {\n return (propKey, value) => {\n if (propKey === 'value') {\n dom.setProperty(el, 'value', String(value ?? ''));\n } else {\n applyProp(dom, el, propKey, value);\n }\n };\n}\n\nexport function buttonUpdate(\n dom: DOMAdapter,\n el: Element,\n): (propKey: string, value: unknown) => void {\n return (propKey, value) => {\n if (propKey === 'label') {\n dom.setTextContent(el, String(value ?? ''));\n } else if (propKey === 'disabled') {\n if (value === true) {\n dom.setAttribute(el, 'disabled', '');\n } else {\n dom.removeAttribute(el, 'disabled');\n }\n } else {\n applyProp(dom, el, propKey, value);\n }\n };\n}\n\nexport function linkUpdate(\n dom: DOMAdapter,\n el: Element,\n): (propKey: string, value: unknown) => void {\n return (propKey, value) => {\n if (propKey === 'label') {\n dom.setTextContent(el, String(value ?? ''));\n } else if (propKey === 'href') {\n dom.setAttribute(el, 'href', String(value ?? ''));\n } else {\n applyProp(dom, el, propKey, value);\n }\n };\n}\n\nexport function applyNodeProps(ctx: RenderContext, graphNode: GraphNode, el: Element): void {\n // Iterate own enumerable keys directly rather than via Object.entries, which\n // allocates a wrapper array plus one [key,value] tuple per prop — measurable\n // GC pressure when multiplied across every node in a large initial render.\n const props = graphNode.props;\n for (const key in props) {\n if (!Object.hasOwn(props, key)) continue;\n if (SKIP_PROP_KEYS.has(key)) continue;\n applyProp(ctx.dom, el, key, props[key]);\n }\n}\n\nexport function wireSignalBindings(\n ctx: RenderContext,\n graphNode: GraphNode,\n instance: NodeInstance,\n onUpdate: (propKey: string, value: unknown) => void,\n): void {\n // Fast exit for the common non-reactive node — avoids allocating a for-of\n // iterator over an empty stateRefs array on every static node.\n if (graphNode.stateRefs.length === 0) return;\n for (const stateRef of graphNode.stateRefs) {\n const signalKey = `__signal__${stateRef.signalId}`;\n const maybeSig = ctx.graph.getHandler(signalKey) as\n | { subscribe: (fn: (v: unknown) => void) => () => void; peek: () => unknown }\n | undefined;\n if (maybeSig === undefined || typeof maybeSig.subscribe !== 'function') continue;\n\n // Subscribe directly — avoids the ReadonlySignal<T> generic variance issue\n const unsub = maybeSig.subscribe((value) => {\n onUpdate(stateRef.propKey, value);\n });\n instance.trackCleanup(unsub);\n }\n}\n\n// ── Reactive list wiring ────────────────────────────────────────────────────────\n\ntype ListBuildFn = (items: unknown) => GraphNode[];\ntype ListPlanFn = (items: unknown) => PlanEntry[];\n\n/**\n * Subscribe a reactive-list instance to its driving signal. On each change the\n * DSL-registered plan factory produces lightweight per-row descriptors, which\n * are reconciled against the live DOM with the keyed, minimal-move reconciler\n * (spec §15). A `conditional` node has no plan handler and falls back to the\n * eager build factory (it only ever renders 0..1 branch, so eager is fine).\n */\nexport function wireReactiveList(\n ctx: RenderContext,\n graphNode: GraphNode,\n instance: NodeInstance,\n el: Element,\n runAppear = false,\n): void {\n const plan = ctx.graph.getHandler(`__listplan__${graphNode.id}`) as\n | ListPlanFn\n | undefined;\n const build = ctx.graph.getHandler(`__listbuild__${graphNode.id}`) as\n | ListBuildFn\n | undefined;\n if (plan === undefined && build === undefined) return;\n\n // One transition controller per reactive container, created here so its\n // leaving-instance map survives across every reconcile of this container\n // (that persistence is what makes leave→enter reclaim and keyed list-leave\n // correct — §6/§7). `finalize` runs the full deferred teardown chain when a\n // leave animation completes: DOM-remove + dispose + forget + detach, exactly\n // the work the synchronous path splits between the reconciler and the two\n // reconcile* helpers below. On the server (no body) the controller's hooks\n // no-op, so SSR is unchanged (§21).\n const controller = new TransitionController(ctx.dom, ctx.graph, (leaving) => {\n // Full teardown at leave-animation end — the same four steps the synchronous\n // path splits between the reconciler (DOM-remove + dispose) and this helper\n // (forget + detach). Deferred here because `beginLeave` excluded this\n // instance from `result.removed`, so nothing else will tear it down.\n const parent = ctx.dom.parentNode(leaving.domNode);\n if (parent !== null) ctx.dom.removeChild(parent, leaving.domNode);\n leaving.dispose();\n forgetInstance(ctx, leaving);\n ctx.graph.detachNode(leaving.graphNode);\n });\n const hooks = controller.hooks();\n\n // `appear`: animate any initial child that opted in — but ONLY on a fresh\n // browser mount, never on hydration (§22: the DOM is already present and\n // correct, so appear must not run). The hydrate path calls this with\n // `runAppear` omitted (false).\n if (runAppear) controller.appear(instance.children);\n\n for (const stateRef of graphNode.stateRefs) {\n if (stateRef.propKey !== 'items') continue;\n const sig = ctx.graph.getHandler(`__signal__${stateRef.signalId}`) as\n | { subscribe: (fn: (v: unknown) => void) => () => void }\n | undefined;\n if (sig === undefined || typeof sig.subscribe !== 'function') continue;\n\n const unsub = sig.subscribe((value) => {\n if (plan !== undefined) {\n reconcileReactiveListByPlan(ctx, graphNode, instance, el, plan(value), hooks);\n } else {\n reconcileReactiveList(ctx, graphNode, instance, el, build!(value), hooks);\n }\n });\n instance.trackCleanup(unsub);\n }\n}\n\nfunction reconcileReactiveListByPlan(\n ctx: RenderContext,\n listNode: GraphNode,\n listInstance: NodeInstance,\n listEl: Element,\n plan: PlanEntry[],\n hooks: TransitionHooks,\n): void {\n const oldInstances = [...listInstance.children];\n const result = reconcileChildrenByPlan(\n ctx,\n listEl,\n oldInstances,\n plan,\n (node, parent) => mountNode(ctx, node, parent),\n hooks,\n );\n\n // Sync the live instance's children to the reconciled order.\n listInstance.children.length = 0;\n for (const inst of result.instances) listInstance.children.push(inst);\n\n // Forget removed instances, and drop their graph nodes.\n for (const removed of result.removed) {\n forgetInstance(ctx, removed);\n ctx.graph.detachNode(removed.graphNode);\n }\n // Detach any freshly-built subtree that was not adopted as a live instance\n // (e.g. the top node of a rebuilt changed row, whose live instance keeps its\n // original graph node).\n const adopted = new Set(result.instances.map((i) => i.graphNode));\n for (const node of result.built ?? []) {\n if (!adopted.has(node)) ctx.graph.detachNode(node);\n }\n\n // Keep the graph model consistent: list node children match the new order.\n for (const child of [...listNode.children]) listNode.removeChild(child);\n for (const inst of result.instances) listNode.appendChild(inst.graphNode);\n}\n\nfunction reconcileReactiveList(\n ctx: RenderContext,\n listNode: GraphNode,\n listInstance: NodeInstance,\n listEl: Element,\n newNodes: GraphNode[],\n hooks: TransitionHooks,\n): void {\n const oldInstances = [...listInstance.children];\n const result = reconcileChildren(\n ctx,\n listEl,\n oldInstances,\n newNodes,\n (node, parent) => mountNode(ctx, node, parent),\n hooks,\n );\n\n // Sync the live instance's children to the reconciled order.\n listInstance.children.length = 0;\n for (const inst of result.instances) listInstance.children.push(inst);\n\n // Forget removed instances from the renderer index, and drop their graph\n // nodes (and any un-adopted freshly-built duplicates) from the graph index.\n for (const removed of result.removed) {\n forgetInstance(ctx, removed);\n ctx.graph.detachNode(removed.graphNode);\n }\n const adopted = new Set(result.instances.map((i) => i.graphNode));\n for (const built of newNodes) {\n if (!adopted.has(built)) ctx.graph.detachNode(built);\n }\n\n // Keep the graph model consistent: list node children match the new order.\n for (const child of [...listNode.children]) listNode.removeChild(child);\n for (const inst of result.instances) listNode.appendChild(inst.graphNode);\n}\n\n/** Recursively remove an instance subtree from the renderer's instance index. */\nfunction forgetInstance(ctx: RenderContext, instance: NodeInstance): void {\n ctx.instances.delete(instance.graphNode.id);\n for (const child of instance.children) forgetInstance(ctx, child);\n}\n\n// ── Overlay behavior wiring ─────────────────────────────────────────────────────\n\n/**\n * Opaque overlay descriptor, read from the `__overlay__<portalId>` handler that\n * the DSL registers for dialog/popover/tooltip/dropdown/toast. Declared here as\n * a local structural type (mirroring the list plan/build handler pattern) so the\n * renderer never takes a compile-time dependency on the DSL package.\n */\ninterface OverlayBehavior {\n /** Reactive open/visibility state — the same signal that drives the panel's `when()`. */\n readonly open: {\n subscribe: (fn: (v: boolean) => void) => () => void;\n peek: () => unknown;\n };\n /** Trap Tab focus within, and redirect escaped focus back inside (modal semantics). */\n readonly modal: boolean;\n /** Move focus into the panel when it opens. */\n readonly takesFocus: boolean;\n /** Wire arrow/Home/End/Enter/Space roving-focus navigation (role=\"menu\"). */\n readonly menu: boolean;\n /** Escape key invokes `onClose`. */\n readonly closeOnEscape: boolean;\n /** Restore focus to the pre-open element on close. */\n readonly restoreFocus: boolean;\n /** id of the element to focus first when opening. */\n readonly initialFocusId?: string;\n /** Requested-close callback (Escape). The app flips its own open signal here. */\n readonly onClose?: () => void;\n}\n\n/**\n * Attach overlay focus/keyboard behavior to a mounted portal. Server-safe: on\n * the server `dom.body()` is null so this returns immediately (SSR emits inert\n * markup, no focus concept). A plain portal has no `__overlay__` descriptor, so\n * this also returns immediately — the behavior is purely additive.\n *\n * The panel is mounted/unmounted by the portal's inner `when(open, …)`, whose\n * signal subscription is registered *before* this one (the conditional child is\n * mounted earlier in the portal branch). Signal subscribers fire synchronously\n * in subscription order, so on open→true the panel DOM exists before we move\n * focus into it, and on open→false the panel is torn down before we restore\n * focus. All listeners are tracked on the instance and torn down on unmount.\n */\nexport function wireOverlayBehavior(\n ctx: RenderContext,\n graphNode: GraphNode,\n instance: NodeInstance,\n target: Element,\n): void {\n const { dom, graph } = ctx;\n if (dom.body() === null) return; // server / no DOM environment\n\n const descFn = graph.getHandler(`__overlay__${graphNode.id}`) as\n | (() => OverlayBehavior)\n | undefined;\n if (descFn === undefined) return; // plain portal — no overlay behavior\n\n const desc = descFn();\n const openSig = desc.open;\n if (openSig === undefined || typeof openSig.subscribe !== 'function') return;\n\n let active: Array<() => void> = [];\n let saved: Element | null = null;\n\n const teardown = (): void => {\n for (const fn of active) fn();\n active = [];\n };\n\n const onOpenChange = (isOpen: boolean): void => {\n if (isOpen) {\n if (desc.restoreFocus) saved = saveFocus(dom);\n // Establish containment/roving BEFORE moving focus in, so that when a\n // nested modal opens it becomes the authoritative focus owner before its\n // initial focus fires — otherwise the outer modal's still-active\n // containment would pull that focus back out (§16).\n if (desc.modal) {\n active.push(trapFocus(dom, target));\n active.push(containFocus(dom, target));\n }\n if (desc.menu) {\n active.push(rovingMenu(dom, target));\n }\n if (desc.takesFocus) focusInitial(dom, target, desc.initialFocusId);\n if (desc.closeOnEscape && desc.onClose !== undefined) {\n active.push(onEscape(dom, target, desc.onClose));\n }\n } else {\n teardown();\n if (desc.restoreFocus && saved !== null) {\n restoreFocus(dom, saved);\n saved = null;\n }\n }\n };\n\n const unsub = openSig.subscribe(onOpenChange);\n instance.trackCleanup(unsub);\n instance.trackCleanup(teardown);\n\n // `subscribe` fires only on change; an overlay that is open on initial mount\n // has its panel already built into the graph, so run the open path now.\n if (openSig.peek() === true) onOpenChange(true);\n}\n\n/**\n * Wire a component instance's lifecycle (§9). Reads the optional\n * `__component__<id>` descriptor — an array of teardown callbacks the DSL's\n * `component()` collected from the setup's `ctx.effect`/`ctx.onCleanup` — and\n * routes each into `NodeInstance.trackCleanup`, so they run (children-first)\n * when the component leaves the graph. Shared by the mount and hydrate paths so\n * both attach identical ownership. A `'component'` node with no cleanups (no\n * effects/resources) registers no descriptor and this is a no-op.\n */\nexport function wireComponentBehavior(\n ctx: RenderContext,\n graphNode: GraphNode,\n instance: NodeInstance,\n): void {\n const fn = ctx.graph.getHandler(`__component__${graphNode.id}`) as\n | (() => Array<() => void>)\n | undefined;\n if (fn === undefined) return;\n for (const cleanup of fn()) instance.trackCleanup(cleanup);\n}\n","/**\n * Hydration diagnostics — dev-only, opt-in explanations of hydration mismatches.\n *\n * Hydration is self-repairing: when the server-rendered DOM does not match the\n * graph at a position, the renderer mounts a fresh subtree in place and drops\n * the offending element (see `hydrateChildren` in `hydrate.ts`). That recovery\n * is silent by design — a local mismatch must never tear down the whole app.\n *\n * During development, though, a silent repair hides a real problem (usually a\n * server/client divergence). A `HydrationDiagnosticSink` can be attached to the\n * renderer to *observe* those repairs without changing them: for every mismatch\n * the renderer reports what it expected, what it found, where, and what it did\n * to recover. Nothing is thrown, nothing is mutated differently, and when no\n * sink is attached there is zero additional work on the hydration path.\n */\n\n/** What kind of divergence the hydrator encountered at a position. */\nexport type HydrationMismatchType =\n | 'tag-mismatch' // an element existed but was the wrong tag\n | 'missing-element' // the graph expected a child the DOM did not provide\n | 'surplus-element'; // the DOM had a child the graph no longer expects\n\n/** A single, fully-described hydration divergence and the repair taken. */\nexport interface HydrationDiagnostic {\n /** The category of mismatch. */\n readonly type: HydrationMismatchType;\n /** The tag the graph expected at this position (null for a surplus element). */\n readonly expected: string | null;\n /** The tag actually found in the server DOM (null for a missing element). */\n readonly found: string | null;\n /** A human-readable path to the position, e.g. `app / page[0] / section[1]`. */\n readonly path: string;\n /** The graph node id involved, when one exists (null for surplus DOM). */\n readonly nodeId: string | null;\n /** The semantic node type involved, when one exists (null for surplus DOM). */\n readonly nodeType: string | null;\n /** The recovery action the renderer performed. */\n readonly action: string;\n /** A single-line, developer-facing summary of the whole diagnostic. */\n readonly message: string;\n}\n\n/**\n * Receives hydration diagnostics as they are discovered. Kept intentionally\n * tiny so any logger — `console`, a test collector, a `DiagnosticSink` — can\n * satisfy it. Implementations must not throw.\n */\nexport interface HydrationDiagnosticSink {\n report(diagnostic: HydrationDiagnostic): void;\n}\n\n/** Build the canonical one-line message for a diagnostic. */\nexport function formatHydrationDiagnostic(\n d: Omit<HydrationDiagnostic, 'message'>,\n): string {\n const at = ` at ${d.path}`;\n switch (d.type) {\n case 'tag-mismatch':\n return `Hydration mismatch${at} — Expected: ${d.expected} / Found: ${d.found} / Action: ${d.action}`;\n case 'missing-element':\n return `Hydration mismatch${at} — Expected: ${d.expected} / Found: (nothing) / Action: ${d.action}`;\n case 'surplus-element':\n return `Hydration mismatch${at} — Expected: (nothing) / Found: ${d.found} / Action: ${d.action}`;\n }\n}\n\n/**\n * A ready-made sink that accumulates diagnostics into an array — the shape most\n * useful for tests and for a DevTools panel. The returned `diagnostics` array is\n * appended to in-place as repairs happen.\n */\nexport function createHydrationDiagnosticCollector(): {\n readonly sink: HydrationDiagnosticSink;\n readonly diagnostics: HydrationDiagnostic[];\n} {\n const diagnostics: HydrationDiagnostic[] = [];\n return {\n diagnostics,\n sink: {\n report(d) {\n diagnostics.push(d);\n },\n },\n };\n}\n\n/**\n * A sink that forwards each diagnostic to a `console`-like logger as a single\n * warning line. Handy default when you just want the messages surfaced in dev.\n */\nexport function consoleHydrationDiagnosticSink(\n logger: { warn(message: string): void } = console,\n): HydrationDiagnosticSink {\n return {\n report(d) {\n logger.warn(d.message);\n },\n };\n}\n","/**\n * Hydration — attach a live StreetUI runtime to server-rendered HTML.\n *\n * `hydrate` walks the semantic application graph top-down against the DOM that\n * the server already produced. For every graph node it *adopts* the matching\n * existing element (creating a `NodeInstance` that points at it) and attaches\n * behavior — event listeners and signal subscriptions — using the exact same\n * helpers the browser mount path uses (`wireEvents`, `wireSignalBindings`,\n * `wireReactiveList`, and the per-type update factories). Nothing is recreated\n * when the DOM matches.\n *\n * Matching is positional and works because every non-application graph node\n * maps to exactly one element (see mount.ts). When the element at a position\n * does not match the expected tag (or is missing), only that subtree is\n * repaired: the fresh subtree is mounted and spliced into place, leaving the\n * rest of the hydrated tree untouched. A local mismatch never tears down the\n * whole app.\n */\n\nimport type { GraphNode } from '@streetui/graph';\nimport type { RenderContext } from './render-context.js';\nimport { NodeInstance } from './node-instance.js';\nimport { wireEvents } from './events.js';\nimport { resolveTag } from './tag-map.js';\nimport { formatHydrationDiagnostic } from './hydration-diagnostics.js';\nimport { wireHeadBehavior } from './head.js';\nimport {\n mountNode,\n wireSignalBindings,\n wireReactiveList,\n wireOverlayBehavior,\n wireComponentBehavior,\n textUpdate,\n headingUpdate,\n inputUpdate,\n buttonUpdate,\n linkUpdate,\n} from './mount.js';\n\n/** Hydrate the whole application graph against `ctx.container`. */\nexport function hydrateGraph(ctx: RenderContext): NodeInstance {\n const root = ctx.graph.root;\n // The application root maps to the container itself (no element of its own),\n // exactly as in mountNode.\n const instance = new NodeInstance(root, ctx.container);\n ctx.instances.set(root.id, instance);\n hydrateChildren(ctx, root, instance, ctx.container, 'app');\n return instance;\n}\n\n/**\n * Adopt `domNode` as the live element for `graphNode` and attach behavior.\n * The caller has already verified `domNode` matches `graphNode` (right tag).\n * `path` is the human-readable position used only for dev diagnostics.\n */\nfunction hydrateNode(\n ctx: RenderContext,\n graphNode: GraphNode,\n domNode: Element,\n path: string,\n): NodeInstance {\n const { dom, graph } = ctx;\n\n switch (graphNode.type) {\n case 'text': {\n // <span> with an inner text node. Adopt the text node (or create one if\n // the server markup somehow lacks it).\n let textNode = dom.firstChild(domNode);\n if (textNode === null || !dom.isTextNode(textNode)) {\n const created = dom.createTextNode(String(graphNode.getProp('text') ?? ''));\n dom.appendChild(domNode, created);\n textNode = created;\n }\n const instance = new NodeInstance(graphNode, domNode);\n ctx.instances.set(graphNode.id, instance);\n wireEvents(dom, graph, graphNode, domNode, instance);\n // Only build the per-type update closure when the node actually has\n // reactive bindings. wireSignalBindings early-returns on an empty\n // stateRefs list, so for a static node the `textUpdate(...)` closure would\n // be allocated and immediately discarded — pure GC pressure on the hot\n // hydration path, where the vast majority of nodes are static.\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, textUpdate(dom, domNode, textNode as Text));\n }\n return instance;\n }\n\n case 'heading': {\n const instance = new NodeInstance(graphNode, domNode);\n ctx.instances.set(graphNode.id, instance);\n wireEvents(dom, graph, graphNode, domNode, instance);\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, headingUpdate(dom, domNode));\n }\n return instance;\n }\n\n case 'input': {\n const instance = new NodeInstance(graphNode, domNode);\n ctx.instances.set(graphNode.id, instance);\n // The controlled value is already present in the server HTML (reflected as\n // the `value` attribute). Re-assert it as a live property so the element's\n // current value matches the bound signal exactly.\n const value = graphNode.getProp('value');\n if (value !== undefined) dom.setProperty(domNode, 'value', String(value));\n wireEvents(dom, graph, graphNode, domNode, instance);\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, inputUpdate(dom, domNode));\n }\n return instance;\n }\n\n case 'button': {\n const instance = new NodeInstance(graphNode, domNode);\n ctx.instances.set(graphNode.id, instance);\n wireEvents(dom, graph, graphNode, domNode, instance);\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, buttonUpdate(dom, domNode));\n }\n return instance;\n }\n\n case 'image':\n case 'link': {\n // Leaf elements. Links may carry click handlers and — like buttons — a\n // label/href bound to a signal (e.g. i18n `t()` in nav), so wire the same\n // reactive binding path after adopting the server node.\n const instance = new NodeInstance(graphNode, domNode);\n ctx.instances.set(graphNode.id, instance);\n if (graphNode.type === 'link') {\n wireEvents(dom, graph, graphNode, domNode, instance);\n if (graphNode.stateRefs.length !== 0) {\n wireSignalBindings(ctx, graphNode, instance, linkUpdate(dom, domNode));\n }\n }\n return instance;\n }\n\n case 'reactive-list':\n case 'conditional': {\n // The server rendered the initial children (built into the graph at\n // compile time from the initial signal state). Adopt them positionally,\n // then subscribe for future signal changes — the same keyed reconciler as\n // the browser drives subsequent updates against the adopted instances.\n const instance = new NodeInstance(graphNode, domNode);\n ctx.instances.set(graphNode.id, instance);\n hydrateChildren(ctx, graphNode, instance, domNode, path);\n wireReactiveList(ctx, graphNode, instance, domNode);\n return instance;\n }\n\n case 'portal': {\n // The server rendered the portal's children INLINE inside the anchor\n // (no body on the server). Adopt the anchor, then — before positional\n // child hydration — relocate those inline children into a fresh\n // document.body container so their live location matches the browser\n // mount path exactly (and there is no positional mismatch). Hydrate the\n // children against the body container, then wire any overlay behavior.\n const instance = new NodeInstance(graphNode, domNode);\n ctx.instances.set(graphNode.id, instance);\n const body = dom.body();\n let target: Element = domNode;\n if (body !== null) {\n const portalContainer = dom.createElement('div');\n dom.setAttribute(portalContainer, 'data-streetui-portal-container', '');\n // `childNodes` returns a snapshot array, so moving during iteration is\n // safe. appendChild re-parents each node out of the anchor.\n for (const child of dom.childNodes(domNode)) {\n dom.appendChild(portalContainer, child);\n }\n dom.appendChild(body, portalContainer);\n instance.trackCleanup(() => dom.removeChild(body, portalContainer));\n target = portalContainer;\n }\n hydrateChildren(ctx, graphNode, instance, target, path);\n wireOverlayBehavior(ctx, graphNode, instance, target);\n return instance;\n }\n\n case 'head': {\n // The server emitted this node's metadata into `<head>` (via renderHead)\n // and left a neutral empty anchor here. Adopt the anchor, then wire the\n // head behavior: the HeadManager adopts the server `[data-streetui-head-\n // key]` tags on first apply so re-asserting this contribution produces no\n // duplicates. No children to hydrate.\n const instance = new NodeInstance(graphNode, domNode);\n ctx.instances.set(graphNode.id, instance);\n wireHeadBehavior(ctx, graphNode, instance);\n return instance;\n }\n\n default: {\n // Structural nodes: container / section / page / form / list / list-item.\n const instance = new NodeInstance(graphNode, domNode);\n ctx.instances.set(graphNode.id, instance);\n if (graphNode.type === 'form') {\n wireEvents(dom, graph, graphNode, domNode, instance);\n }\n // Hydration boundary (a \"slot\" such as the router outlet): adopt the\n // element itself but leave its existing children untouched — neither\n // hydrated by this pass nor removed as surplus. Something else (e.g. the\n // router) owns and will hydrate the content already inside it. Without\n // this, an empty-in-the-graph slot would strip the server-rendered\n // content it is meant to preserve.\n if (graphNode.getProp('_hydrationBoundary') === true) {\n return instance;\n }\n hydrateChildren(ctx, graphNode, instance, domNode, path);\n if (graphNode.type === 'component') wireComponentBehavior(ctx, graphNode, instance);\n return instance;\n }\n }\n}\n\n// ── Child matching + local mismatch recovery ───────────────────────────────────\n\n/**\n * Positionally match a parent's expected child graph nodes against the actual\n * child *elements* in the DOM. Matching children are hydrated in place; a\n * mismatch (wrong tag or a missing element) triggers a local repair — the fresh\n * subtree is mounted and spliced into the correct position — without disturbing\n * sibling subtrees. Surplus DOM elements are removed.\n */\nfunction hydrateChildren(\n ctx: RenderContext,\n parentGraphNode: GraphNode,\n parentInstance: NodeInstance,\n parentDom: Element,\n parentPath: string,\n): void {\n const expected = parentGraphNode.children;\n const actual = elementChildren(ctx, parentDom);\n let cursor = 0;\n\n // The human-readable `path` is only ever consumed by hydration diagnostics,\n // which are inert unless a sink is attached. Building the\n // `${parentPath} / ${type}[${i}]` string for every child would allocate one\n // throwaway string per node on the hot path (10k+ on a large tree) for output\n // that is discarded in production. Gate the construction on the sink being\n // present; when it is absent, thread the (meaningless-but-unused) parent path\n // through unchanged so nested calls stay allocation-free too.\n const diag = ctx.hydrationDiagnostics !== undefined;\n\n for (let i = 0; i < expected.length; i++) {\n const childNode = expected[i]!;\n const want = expectedTag(ctx, childNode);\n const childPath = diag ? `${parentPath} / ${childNode.type}[${i}]` : parentPath;\n const actualEl = actual[cursor];\n\n if (\n actualEl !== undefined &&\n ctx.dom.isElement(actualEl) &&\n ctx.dom.tagName(actualEl) === want\n ) {\n // Match — adopt the existing element.\n const inst = hydrateNode(ctx, childNode, actualEl, childPath);\n parentInstance.addChild(inst);\n cursor++;\n } else {\n // Mismatch or missing — repair only this subtree. Mount fresh, then move\n // it into the correct position ahead of the offending/absent node.\n const ref = actualEl ?? null;\n const inst = mountFreshAt(ctx, childNode, parentDom, ref);\n parentInstance.addChild(inst);\n if (actualEl !== undefined) {\n // Drop the mismatched element that the fresh node replaces.\n const found = ctx.dom.isElement(actualEl) ? ctx.dom.tagName(actualEl) : null;\n reportHydrationDiagnostic(ctx, {\n type: 'tag-mismatch',\n expected: want,\n found,\n path: childPath,\n nodeId: childNode.id,\n nodeType: childNode.type,\n action: 'mounted fresh subtree in place',\n });\n ctx.dom.removeChild(parentDom, actualEl);\n cursor++;\n } else {\n reportHydrationDiagnostic(ctx, {\n type: 'missing-element',\n expected: want,\n found: null,\n path: childPath,\n nodeId: childNode.id,\n nodeType: childNode.type,\n action: 'mounted fresh subtree',\n });\n }\n }\n }\n\n // Remove any surplus server elements the graph no longer expects.\n for (let i = cursor; i < actual.length; i++) {\n const surplus = actual[i]!;\n reportHydrationDiagnostic(ctx, {\n type: 'surplus-element',\n expected: null,\n found: ctx.dom.isElement(surplus) ? ctx.dom.tagName(surplus) : null,\n path: `${parentPath} / [surplus ${i}]`,\n nodeId: null,\n nodeType: null,\n action: 'removed surplus server element',\n });\n ctx.dom.removeChild(parentDom, surplus);\n }\n}\n\n/**\n * Emit a hydration diagnostic through the (optional) sink. When no sink is\n * attached this is a single cheap `undefined` check — the production default.\n */\nfunction reportHydrationDiagnostic(\n ctx: RenderContext,\n d: {\n type: 'tag-mismatch' | 'missing-element' | 'surplus-element';\n expected: string | null;\n found: string | null;\n path: string;\n nodeId: string | null;\n nodeType: string | null;\n action: string;\n },\n): void {\n const sink = ctx.hydrationDiagnostics;\n if (sink === undefined) return;\n sink.report({ ...d, message: formatHydrationDiagnostic(d) });\n}\n\n/** Mount a fresh subtree for `node` and splice it before `ref` (or append). */\nfunction mountFreshAt(\n ctx: RenderContext,\n node: GraphNode,\n parentDom: Element,\n ref: Node | null,\n): NodeInstance {\n // mountNode appends the new subtree at the end of parentDom.\n const inst = mountNode(ctx, node, parentDom);\n if (ref !== null) {\n ctx.dom.insertBefore(parentDom, inst.domNode, ref);\n }\n return inst;\n}\n\n/** The element (not text/comment) children of a node, in order. */\nfunction elementChildren(ctx: RenderContext, parent: Element): Element[] {\n const out: Element[] = [];\n for (const node of ctx.dom.childNodes(parent)) {\n if (ctx.dom.isElement(node)) out.push(node);\n }\n return out;\n}\n\n/** The HTML tag a graph node is expected to occupy in the DOM. */\nfunction expectedTag(ctx: RenderContext, graphNode: GraphNode): string {\n switch (graphNode.type) {\n case 'text':\n return 'span';\n case 'heading': {\n const level = (graphNode.getProp('level') as number | undefined) ?? 1;\n return `h${level}`;\n }\n case 'input':\n return 'input';\n case 'image':\n return 'img';\n case 'link':\n return 'a';\n case 'button':\n return 'button';\n default:\n // reactive-list → ul, conditional → div, structural → resolveTag.\n return resolveTag(graphNode.type);\n }\n}\n","/**\n * StreetRenderHandle — the live handle returned by both `mount` and `hydrate`.\n *\n * Owns teardown for a mounted/hydrated application: disposes every NodeInstance\n * (removing event listeners and signal subscriptions) and clears the container\n * through the DOM adapter (never raw browser globals), so the same handle works\n * for browser and — in principle — server-driven teardown.\n */\n\nimport type { RenderHandle } from '@streetui/runtime';\nimport type { RenderContext } from './render-context.js';\nimport type { NodeInstance } from './node-instance.js';\n\nexport class StreetRenderHandle implements RenderHandle {\n private _disposed = false;\n private readonly _ctx: RenderContext;\n private readonly _rootInstance: NodeInstance;\n\n constructor(ctx: RenderContext, rootInstance: NodeInstance) {\n this._ctx = ctx;\n this._rootInstance = rootInstance;\n }\n\n flush(): void {\n if (this._disposed) return;\n // Signal subscriptions fire synchronously in StreetUI's state system;\n // flush() is a no-op at the renderer level — the DOM is already up to date\n // unless the scheduler is batching, in which case the scheduler calls\n // flush() after draining its queue.\n }\n\n unmount(): void {\n if (this._disposed) return;\n this._disposed = true;\n\n // Dispose all node instances (removes event listeners, signal subscriptions).\n this._rootInstance.dispose();\n\n // Remove all children from the container. Routed through the DOM adapter\n // (never `container.firstChild`/`removeChild`) so the teardown path is\n // server-safe.\n const dom = this._ctx.dom;\n const container = this._ctx.container;\n for (const child of dom.childNodes(container)) {\n dom.removeChild(container, child);\n }\n\n this._ctx.instances.clear();\n }\n}\n","/**\n * StreetUI Renderer — framework-owned DOM renderer.\n *\n * No React. No Vue. No virtual-dom. No external rendering library.\n *\n * Pipeline:\n * CompiledApplication\n * → mountGraph (creates all DOM nodes)\n * → signal subscriptions drive patchNode (targeted updates)\n * → flush() propagates any pending scheduler jobs\n * → unmount() disposes everything\n */\n\nimport type { DOMAdapter } from '@streetui/dom';\nimport { BrowserDOMAdapter } from '@streetui/dom';\nimport type { CompiledApplication } from '@streetui/compiler';\nimport type { StreetRenderer, RenderHandle } from '@streetui/runtime';\nimport { createRenderContext } from './render-context.js';\nimport { mountGraph } from './mount.js';\nimport { hydrateGraph } from './hydrate.js';\nimport { StreetRenderHandle } from './render-handle.js';\nimport type { NodeInstance } from './node-instance.js';\nimport type { HydrationDiagnosticSink } from './hydration-diagnostics.js';\n\nexport interface StreetRendererOptions {\n /** Override the DOM adapter (e.g. for testing). Defaults to BrowserDOMAdapter. */\n readonly domAdapter?: DOMAdapter;\n /**\n * Optional dev-only sink that observes hydration mismatch repairs. Attach one\n * to surface server/client divergences during development; leave it unset in\n * production so hydration does no extra work.\n */\n readonly hydrationDiagnostics?: HydrationDiagnosticSink;\n}\n\nexport class StreetRendererImpl implements StreetRenderer {\n private readonly _dom: DOMAdapter;\n private readonly _hydrationDiagnostics?: HydrationDiagnosticSink;\n\n constructor(options: StreetRendererOptions = {}) {\n this._dom = options.domAdapter ?? new BrowserDOMAdapter();\n if (options.hydrationDiagnostics !== undefined) {\n this._hydrationDiagnostics = options.hydrationDiagnostics;\n }\n }\n\n mount(compiled: CompiledApplication, container: Element): RenderHandle {\n const ctx = createRenderContext(this._dom, compiled.graph, container);\n\n // Initial mount — creates the full DOM tree\n const rootInstance = mountGraph(ctx);\n\n // Wire all signal subscriptions so that signal → DOM patches happen automatically\n this._wireSignals(ctx, rootInstance);\n\n return new StreetRenderHandle(ctx, rootInstance);\n }\n\n /**\n * Hydrate a container that already holds server-rendered HTML for this\n * application. Instead of recreating the DOM, it walks the semantic graph\n * against the existing nodes, adopting matching elements and attaching\n * behavior (events + signal subscriptions). Mismatched subtrees are locally\n * replaced. Returns the same handle type as `mount`.\n */\n hydrate(compiled: CompiledApplication, container: Element): RenderHandle {\n const ctx = createRenderContext(\n this._dom,\n compiled.graph,\n container,\n this._hydrationDiagnostics,\n );\n const rootInstance = hydrateGraph(ctx);\n this._wireSignals(ctx, rootInstance);\n return new StreetRenderHandle(ctx, rootInstance);\n }\n\n private _wireSignals(\n ctx: ReturnType<typeof createRenderContext>,\n rootInstance: NodeInstance,\n ): void {\n // Each NodeInstance already wired its own signals in mountNode via wireSignalBindings.\n // This method is a hook for any cross-cutting signal concerns at the renderer level.\n // Currently no-op — individual mount calls handle their own subscriptions.\n void ctx;\n void rootInstance;\n }\n}\n\n/**\n * Create the default StreetUI renderer using the browser's DOM APIs.\n */\nexport function createRenderer(options?: StreetRendererOptions): StreetRendererImpl {\n return new StreetRendererImpl(options);\n}\n","/**\n * SSR state transfer (dehydration) — move server-resolved data to the client.\n *\n * When the server resolves resources before rendering, their data must reach\n * the client so hydration can seed them (via `resource({ initialData })`)\n * instead of refetching. StreetUI does this with a single, framework-scoped\n * `<script>` payload rather than blindly interpolating `JSON.stringify` into\n * markup.\n *\n * Safety (v0.4 rule #16): the JSON is emitted into a\n * `<script type=\"application/json\">` block — an inert data island the browser\n * never executes — and every character that could terminate that block or be\n * reinterpreted by the HTML/JS parser is escaped to its `\\uXXXX` form. Because\n * `<` inside JSON parses back to `<`, the payload round-trips exactly\n * while being impossible to break out of. This is deterministic (stable key\n * order is the caller's responsibility) and typed at the boundary as\n * `Record<string, unknown>` — never `any`.\n */\n\nimport type { DOMAdapter } from '@streetui/dom';\n\n/** Attribute marking StreetUI's state island so the client can find it. */\nexport const STATE_MARKER_ATTR = 'data-streetui-state';\n\n/**\n * Escape a JSON string for safe embedding inside a `<script>` element:\n * < > & → HTML / `</script>` breakout and entity ambiguity\n * U+2028 / U+2029 → invalid raw in JS string literals\n * Uses code-point checks so no raw separator characters live in this source.\n */\nfunction escapeForScript(json: string): string {\n let out = '';\n for (const ch of json) {\n const code = ch.charCodeAt(0);\n if (ch === '<') out += '\\\\u003c';\n else if (ch === '>') out += '\\\\u003e';\n else if (ch === '&') out += '\\\\u0026';\n else if (code === 0x2028) out += '\\\\u2028';\n else if (code === 0x2029) out += '\\\\u2029';\n else out += ch;\n }\n return out;\n}\n\n/**\n * Serialize a state map to an HTML `<script>` island for inclusion in the\n * server-rendered document (typically just before the closing tag of the\n * mount container). Returns an empty string for an empty map.\n */\nexport function serializeState(state: Record<string, unknown>): string {\n if (Object.keys(state).length === 0) return '';\n const json = escapeForScript(JSON.stringify(state));\n return `<script type=\"application/json\" ${STATE_MARKER_ATTR}>${json}</script>`;\n}\n\n/**\n * Read the state island back on the client. Searches `root` for StreetUI's\n * state `<script>` and parses it. Returns an empty object when absent or\n * unparseable (hydration then proceeds as a cold client render). Routed through\n * the DOM adapter so it is testable and never assumes a global `document`.\n */\nexport function readState(\n dom: DOMAdapter,\n root: Element | Document,\n): Record<string, unknown> {\n const el = dom.querySelector(root, `script[${STATE_MARKER_ATTR}]`);\n if (el === null) return {};\n const text = dom.getTextContent(el);\n if (text === null || text.length === 0) return {};\n try {\n const parsed: unknown = JSON.parse(text);\n if (parsed !== null && typeof parsed === 'object') {\n return parsed as Record<string, unknown>;\n }\n return {};\n } catch {\n return {};\n }\n}\n","/**\n * Static graph analysis (v1.2, spec §3/§12/§14).\n *\n * A single post-order walk over the Semantic Application Graph that classifies\n * every node as static (no bound signals, no events, not a reactive\n * region) or dynamic, and rolls that up into whole-static-subtree flags. This\n * is COMPILE-TIME metadata only — it introduces no virtual DOM, no second tree\n * and no runtime reactive system. It is consumed by:\n * - the hydration path, to skip per-node attribute/text re-verification on\n * provably-static subtrees (§12), and\n * - the diagnostic compiler-inspection report (§14).\n *\n * The renderer's initial-mount fast path does not need this map: it already\n * skips reactive wiring per node via cheap `events.length`/`stateRefs.length`\n * guards. Keeping the analysis out of the mount hot path avoids adding lookup\n * cost (and keeps the shipped runtime lean).\n */\n\nimport type { NodeId } from '@streetui/core';\nimport type { ApplicationGraph, GraphNode } from '@streetui/graph';\n\n/** Prop keys whose bound signal drives text content rather than an attribute. */\nconst TEXT_PROP_KEYS: ReadonlySet<string> = new Set(['text', 'label', 'value']);\n\nexport interface NodeAnalysis {\n /** No bound signals, no events, and not a reactive-list/conditional region. */\n readonly isStatic: boolean;\n /** This node is static AND every descendant is a static subtree. */\n readonly isStaticSubtree: boolean;\n /** A signal is bound to this node's text/label/value content. */\n readonly hasDynamicText: boolean;\n /** A signal is bound to a non-content prop (a reactive attribute). */\n readonly hasDynamicAttr: boolean;\n /** This node wires one or more DOM event handlers. */\n readonly hasEvents: boolean;\n /** This node is a keyed reactive list. */\n readonly isList: boolean;\n /** This node is a conditional (0..1 branch) region. */\n readonly isConditional: boolean;\n}\n\nexport interface GraphAnalysisSummary {\n readonly totalNodes: number;\n readonly staticNodes: number;\n readonly staticSubtrees: number;\n readonly dynamicTextNodes: number;\n readonly dynamicAttrNodes: number;\n readonly eventNodes: number;\n readonly lists: number;\n readonly conditionals: number;\n}\n\nexport interface GraphAnalysis {\n readonly nodes: ReadonlyMap<NodeId, NodeAnalysis>;\n readonly summary: GraphAnalysisSummary;\n}\n\n/**\n * Analyze a fully-built graph. O(n) single post-order pass; allocates one small\n * record per node. Safe to skip entirely when neither hydration nor diagnostics\n * need it.\n */\nexport function analyzeGraph(graph: ApplicationGraph): GraphAnalysis {\n const nodes = new Map<NodeId, NodeAnalysis>();\n const summary = {\n totalNodes: 0, staticNodes: 0, staticSubtrees: 0, dynamicTextNodes: 0,\n dynamicAttrNodes: 0, eventNodes: 0, lists: 0, conditionals: 0,\n };\n\n const visit = (node: GraphNode): boolean => {\n // Post-order: children first so subtree rollup is exact.\n let allChildrenStatic = true;\n for (const child of node.children) {\n const childSubtreeStatic = visit(child);\n if (!childSubtreeStatic) allChildrenStatic = false;\n }\n\n let hasDynamicText = false;\n let hasDynamicAttr = false;\n for (const ref of node.stateRefs) {\n if (TEXT_PROP_KEYS.has(ref.propKey)) hasDynamicText = true;\n else hasDynamicAttr = true;\n }\n const hasEvents = node.events.length > 0;\n const isList = node.type === 'reactive-list';\n const isConditional = node.type === 'conditional';\n // A portal relocates its children to a different DOM location (document.body)\n // at mount time, so its subtree is never a contiguous inline static blob.\n // Treating it as dynamic stops the static-subtree rollup at the portal, so\n // both SSR and hydration always take the real portal mount/hydrate branch\n // (which does the relocation) rather than emitting/adopting a raw HTML blob.\n const isPortal = node.type === 'portal';\n // A component owns per-instance lifecycle wiring (a `__component__<id>`\n // cleanup handler read at mount/hydrate). Treating it as dynamic stops the\n // static-subtree rollup at the component boundary so it always takes the\n // real mount/hydrate branch (which wires cleanups) instead of collapsing\n // into a serialized raw-HTML blob that would drop that per-instance wiring.\n const isComponent = node.type === 'component';\n // A `head` node contributes document metadata via a `__head__<id>` handler\n // wired at mount/hydrate (`wireHeadBehavior`). Treating it as dynamic stops\n // the static-subtree rollup at the head boundary so it always takes the real\n // mount/hydrate branch (which registers/cleans up the contribution) instead\n // of collapsing into a serialized raw-HTML blob that would drop that wiring.\n const isHead = node.type === 'head';\n const isStatic =\n node.stateRefs.length === 0 && !hasEvents && !isList && !isConditional && !isPortal && !isComponent && !isHead;\n const isStaticSubtree = isStatic && allChildrenStatic;\n\n nodes.set(node.id, {\n isStatic, isStaticSubtree, hasDynamicText, hasDynamicAttr,\n hasEvents, isList, isConditional,\n });\n\n summary.totalNodes += 1;\n if (isStatic) summary.staticNodes += 1;\n if (isStaticSubtree) summary.staticSubtrees += 1;\n if (hasDynamicText) summary.dynamicTextNodes += 1;\n if (hasDynamicAttr) summary.dynamicAttrNodes += 1;\n if (hasEvents) summary.eventNodes += 1;\n if (isList) summary.lists += 1;\n if (isConditional) summary.conditionals += 1;\n\n return isStaticSubtree;\n };\n\n visit(graph.root);\n return { nodes, summary };\n}\n","/**\n * Diagnostic compiler-inspection mode (v1.2, spec §14).\n *\n * Produces a machine-readable (and optionally text-formatted) description of\n * what the compiler understands about an application: which nodes are static\n * vs dynamic, which carry dynamic text or attributes, which wire events, and\n * which are conditional regions or keyed lists — plus the hydration metadata\n * derived from that classification.\n *\n * This is a DIAGNOSTIC tool. It is not part of the runtime, is not consulted\n * during mount, and is tree-shakeable out of any app that never calls it.\n */\n\nimport type { ApplicationGraph, GraphNode } from '@streetui/graph';\nimport { analyzeGraph, type GraphAnalysisSummary } from './analyze.js';\n\nexport interface InspectedCompilationNode {\n readonly id: string;\n readonly type: string;\n readonly depth: number;\n readonly classification: 'static' | 'static-subtree-root' | 'dynamic';\n readonly dynamicText: boolean;\n readonly dynamicAttrs: boolean;\n readonly events: readonly string[];\n readonly boundProps: readonly string[];\n readonly isList: boolean;\n readonly isConditional: boolean;\n /** Hydration hint: how the hydration path should treat this node. */\n readonly hydration: 'adopt-static' | 'verify-dynamic';\n}\n\nexport interface CompilerInspection {\n readonly name: string;\n readonly version: string;\n readonly summary: GraphAnalysisSummary & {\n /** Fraction of nodes provably static (0..1). */\n readonly staticRatio: number;\n };\n readonly nodes: readonly InspectedCompilationNode[];\n}\n\n/**\n * Inspect a compiled/built graph and return a structured diagnostic report.\n * Purely observational — never mutates the graph.\n */\nexport function inspectCompilation(graph: ApplicationGraph): CompilerInspection {\n const analysis = analyzeGraph(graph);\n const nodes: InspectedCompilationNode[] = [];\n\n const walk = (node: GraphNode, depth: number): void => {\n const a = analysis.nodes.get(node.id);\n if (a !== undefined) {\n const classification: InspectedCompilationNode['classification'] = a.isStaticSubtree\n ? 'static-subtree-root'\n : a.isStatic\n ? 'static'\n : 'dynamic';\n nodes.push({\n id: node.id,\n type: node.type,\n depth,\n classification,\n dynamicText: a.hasDynamicText,\n dynamicAttrs: a.hasDynamicAttr,\n events: node.events.map((e) => e.type),\n boundProps: node.stateRefs.map((r) => r.propKey),\n isList: a.isList,\n isConditional: a.isConditional,\n hydration: a.isStaticSubtree ? 'adopt-static' : 'verify-dynamic',\n });\n }\n for (const child of node.children) walk(child, depth + 1);\n };\n walk(graph.root, 0);\n\n const staticRatio =\n analysis.summary.totalNodes === 0\n ? 0\n : analysis.summary.staticNodes / analysis.summary.totalNodes;\n\n return {\n name: graph.name,\n version: graph.version,\n summary: { ...analysis.summary, staticRatio: +staticRatio.toFixed(4) },\n nodes,\n };\n}\n\n/** Render an inspection as a compact human-readable text report. */\nexport function formatInspection(inspection: CompilerInspection): string {\n const s = inspection.summary;\n const lines: string[] = [];\n lines.push(`StreetUI compiler inspection — ${inspection.name} v${inspection.version}`);\n lines.push(\n ` nodes=${s.totalNodes} static=${s.staticNodes} ` +\n `staticSubtrees=${s.staticSubtrees} dynamicText=${s.dynamicTextNodes} ` +\n `dynamicAttrs=${s.dynamicAttrNodes} events=${s.eventNodes} ` +\n `lists=${s.lists} conditionals=${s.conditionals} ` +\n `staticRatio=${(s.staticRatio * 100).toFixed(1)}%`,\n );\n for (const n of inspection.nodes) {\n const flags: string[] = [];\n if (n.dynamicText) flags.push('text');\n if (n.dynamicAttrs) flags.push('attr:' + n.boundProps.join(','));\n if (n.events.length > 0) flags.push('on:' + n.events.join(','));\n if (n.isList) flags.push('list');\n if (n.isConditional) flags.push('cond');\n lines.push(\n ` ${' '.repeat(n.depth)}${n.type}#${n.id} [${n.classification}]` +\n (flags.length > 0 ? ` {${flags.join(' ')}}` : ''),\n );\n }\n return lines.join('\\n');\n}\n","/**\n * Static SSR Plan (v1.7, spec §4/§6) — internal.\n *\n * A compiler-derived plan that precomputes the verbatim HTML of every *maximal\n * static subtree* in an application graph. During SSR, the renderer emits that\n * precomputed string directly (via `ServerDOMAdapter.createRawHTML`) instead of\n * recursively constructing a `ServerElement`/`ServerText`/`NodeInstance` for\n * every node in the subtree. On the 10k-row `/users` corpus, ~100% of the node\n * mass lives in 10,000 static 8-node row subtrees, so collapsing each row into\n * one precomputed string removes the bulk of the mount-phase construction work.\n *\n * Design constraints honoured here:\n * - §3 REUSE the existing compiler analysis (`analyzeGraph`) to classify nodes;\n * no new/expensive analysis, and nothing runs during normal `compile()`.\n * - §5/§15 Only *maximal static-subtree roots* are collapsed. A dynamic region\n * (reactive-list container, conditional, dynamic-text/attr node) is never\n * treated as static — the list itself stays dynamic; only the provably-static\n * subtree *inside* each repeated item is precomputed.\n * - §8 The precomputed HTML is produced by the SAME mount + serialize pipeline\n * as the runtime path, so full-render output is byte-identical.\n * - §19 The plan retains ONLY strings keyed by GraphNode.id. No ServerDOM node,\n * NodeInstance or application object is retained (the throwaway build tree is\n * disposed + cleared). The per-app cache is a WeakMap, so a plan is released\n * when its CompiledApplication is collected.\n * - §24 Everything here is internal: not re-exported from the `streetui` or\n * `streetui/server` runtime barrels.\n *\n * This module is only ever imported by the SSR entry (`renderToString`), which\n * is itself reachable solely through the server path, so it tree-shakes out of\n * client bundles (§20, verified by bundle measurement).\n */\n\nimport type { NodeId } from '@streetui/core';\nimport type { ApplicationGraph, GraphNode } from '@streetui/graph';\nimport type { CompiledApplication } from '@streetui/compiler';\nimport { analyzeGraph } from '@streetui/compiler/diagnostics';\nimport { ServerDOMAdapter } from '@streetui/dom';\nimport { createRenderContext } from './render-context.js';\nimport { mountNode } from './mount.js';\n\n/**\n * Internal representation of the static SSR plan: maximal static-subtree root\n * GraphNode.id → its precomputed, verbatim outer HTML. A plain `Map<string,\n * string>` is deliberate — it holds no DOM/application references (§19).\n */\nexport type StaticSSRPlan = ReadonlyMap<NodeId, string>;\n\n/**\n * Collect the ids of every *maximal* static-subtree root under `graph`.\n *\n * Walk from the root; when a node is itself a whole static subtree, it is a\n * maximal root — record it and stop (its static descendants are subsumed).\n * Otherwise descend into its children, so a dynamic node's individually-static\n * children are still captured (the mixed-tree case, §5). The `application` root\n * is never recorded: it maps onto the render container rather than emitting its\n * own element, so we always descend past it into its real top-level children.\n */\nfunction collectMaximalStaticRoots(graph: ApplicationGraph): GraphNode[] {\n const analysis = analyzeGraph(graph);\n const roots: GraphNode[] = [];\n\n const walk = (node: GraphNode): void => {\n if (node.type !== 'application') {\n const a = analysis.nodes.get(node.id);\n if (a !== undefined && a.isStaticSubtree) {\n roots.push(node);\n return;\n }\n }\n for (const child of node.children) walk(child);\n };\n\n walk(graph.root);\n return roots;\n}\n\n/**\n * Serialize the outer HTML of a single static subtree using the exact runtime\n * mount + serialize pipeline (so the bytes match a full render). The throwaway\n * tree is disposed immediately, so nothing is retained.\n */\nfunction serializeStaticSubtree(\n dom: ServerDOMAdapter,\n graph: ApplicationGraph,\n root: GraphNode,\n): string {\n const container = dom.createElement('div');\n // No `staticHTML` on this ctx → mountNode builds the subtree fully.\n const ctx = createRenderContext(dom, graph, container);\n const instance = mountNode(ctx, root, container);\n const html = dom.serializeInner(container);\n // Tear down (static subtrees open no subscriptions, but keep symmetry with\n // renderToString's lifecycle) and drop all references.\n instance.dispose();\n ctx.instances.clear();\n return html;\n}\n\n/**\n * Build the static SSR plan for a compiled application. O(n) analysis + one\n * mount/serialize per maximal static subtree. Returns an empty map when the app\n * has no static subtrees (e.g. a highly-dynamic page) — the SSR path then\n * behaves exactly as v1.6.\n */\nexport function buildStaticSSRPlan(compiled: CompiledApplication): StaticSSRPlan {\n const graph = compiled.graph;\n const roots = collectMaximalStaticRoots(graph);\n const plan = new Map<NodeId, string>();\n if (roots.length === 0) return plan;\n\n const dom = new ServerDOMAdapter();\n for (const root of roots) {\n plan.set(root.id, serializeStaticSubtree(dom, graph, root));\n }\n return plan;\n}\n\n/**\n * Per-application plan cache. A WeakMap keyed by the CompiledApplication so a\n * plan is built once and reused across renders, and is released together with\n * the compiled app it belongs to — no long-lived retention of app state (§19).\n */\nconst PLAN_CACHE = new WeakMap<CompiledApplication, StaticSSRPlan>();\n\n/** Get the cached static SSR plan for a compiled app, building it on first use. */\nexport function getStaticSSRPlan(compiled: CompiledApplication): StaticSSRPlan {\n let plan = PLAN_CACHE.get(compiled);\n if (plan === undefined) {\n plan = buildStaticSSRPlan(compiled);\n PLAN_CACHE.set(compiled, plan);\n }\n return plan;\n}\n","/**\n * Server-side rendering — `renderToString`.\n *\n * Runs the *exact same* mount pipeline used in the browser (`mountGraph`), but\n * against a `ServerDOMAdapter` that builds a lightweight in-memory node tree\n * instead of a real browser DOM. The tree is then serialized to a normal HTML\n * string. Because both browser and server share the DSL → Compiler → Graph →\n * Runtime → Renderer pipeline, there is no second, SSR-specific renderer and no\n * virtual DOM.\n *\n * Lifecycle (v0.4 rule #20): the initial synchronous mount may open signal\n * subscriptions (via `wireSignalBindings`/`wireReactiveList`). On the server\n * those would be live forever, so once the HTML is serialized we dispose the\n * root instance — tearing down every subscription and listener. SSR therefore\n * has a *render* lifecycle only; the live *runtime* lifecycle is established\n * later on the client by `hydrate`.\n */\n\nimport { ServerDOMAdapter } from '@streetui/dom';\nimport type { CompiledApplication } from '@streetui/compiler';\nimport { createRenderContext } from './render-context.js';\nimport { mountGraph } from './mount.js';\nimport { getStaticSSRPlan } from './static-ssr-plan.js';\n\nexport interface RenderToStringOptions {\n /**\n * Override the server DOM adapter (rarely needed). Defaults to a fresh\n * `ServerDOMAdapter` per call so concurrent renders never share state.\n */\n readonly domAdapter?: ServerDOMAdapter;\n /**\n * @internal — testing/benchmark knob for the v1.7 static SSR plan.\n *\n * `undefined` (default): use the per-app cached plan (build once, reuse).\n * `null`: disable the plan entirely — the exact v1.6 runtime mount path, used\n * by the byte-identity gate and A/B benchmark as the \"legacy\" baseline.\n * a map: use this explicit plan.\n *\n * Not part of the supported public API; output is byte-identical regardless\n * of this value (§8).\n */\n readonly staticPlan?: ReadonlyMap<string, string> | null;\n}\n\n/**\n * Render a compiled StreetUI application to an HTML string.\n *\n * The returned markup contains only the application's own elements (the\n * synthetic container is not emitted), so callers embed it wherever they mount\n * on the client — e.g. inside `<div id=\"app\">…</div>`.\n */\nexport function renderToString(\n compiled: CompiledApplication,\n options: RenderToStringOptions = {},\n): string {\n const dom = options.domAdapter ?? new ServerDOMAdapter();\n\n // Resolve the v1.7 static SSR plan: cached-by-default, `null` forces the v1.6\n // path, an explicit map is used as-is. Only maximal static-subtree roots are\n // collapsed; dynamic regions still mount through the runtime path (§5).\n const plan =\n options.staticPlan === null\n ? undefined\n : (options.staticPlan ?? getStaticSSRPlan(compiled));\n const staticHTML = plan !== undefined && plan.size > 0 ? plan : undefined;\n\n // Synthetic container — the application root maps onto it, and the app's\n // top-level nodes are appended directly into it (mirroring browser mount).\n const container = dom.createElement('div');\n\n const ctx = createRenderContext(dom, compiled.graph, container, undefined, staticHTML);\n const rootInstance = mountGraph(ctx);\n\n const html = dom.serializeInner(container);\n\n // Tear down any subscriptions/listeners opened during mount — the server has\n // no live runtime. (rule #20)\n rootInstance.dispose();\n ctx.instances.clear();\n\n return html;\n}\n","/**\n * Route matching — pure functions, no DOM, no reactivity.\n *\n * A pattern is matched segment-by-segment against a pathname:\n * - a literal segment must equal the path segment,\n * - a `:name` segment captures the path segment into `params.name`,\n * - a `*` segment (or a whole-pattern `*`) is a catch-all that matches the\n * remainder of the path and captures it into `params['*']`.\n *\n * Matching is intentionally small: no optional segments, no regex constraints,\n * no nested route trees. Composition of layouts is done in the DSL, not here.\n */\n\n/** Split a path into non-empty segments. `/` → [], `/a/b` → ['a','b']. */\nfunction segments(path: string): string[] {\n return path.split('/').filter((s) => s.length > 0);\n}\n\n/** Normalize a pathname: ensure a single leading slash, drop a trailing slash. */\nexport function normalizePath(path: string): string {\n let p = path.trim();\n if (p === '') return '/';\n if (!p.startsWith('/')) p = `/${p}`;\n if (p.length > 1 && p.endsWith('/')) p = p.slice(0, -1);\n return p;\n}\n\n/**\n * Try to match a single pattern against a pathname.\n * Returns the captured params on success, or `null` on no match.\n */\nexport function matchPattern(\n pattern: string,\n pathname: string,\n): Record<string, string> | null {\n // Whole-pattern wildcard: matches everything.\n if (pattern === '*') {\n return { '*': normalizePath(pathname).slice(1) };\n }\n\n const patSegs = segments(pattern);\n const pathSegs = segments(normalizePath(pathname));\n const params: Record<string, string> = {};\n\n for (let i = 0; i < patSegs.length; i++) {\n const patSeg = patSegs[i]!;\n\n // Trailing catch-all: capture the rest of the path.\n if (patSeg === '*') {\n params['*'] = pathSegs.slice(i).map((s) => decodeURIComponent(s)).join('/');\n return params;\n }\n\n const pathSeg = pathSegs[i];\n if (pathSeg === undefined) return null; // path ran out of segments\n\n if (patSeg.startsWith(':')) {\n const name = patSeg.slice(1);\n if (name === '') return null; // malformed `:` with no name\n params[name] = decodeURIComponent(pathSeg);\n continue;\n }\n\n if (patSeg !== pathSeg) return null; // literal mismatch\n }\n\n // All pattern segments consumed — the path must be fully consumed too.\n if (pathSegs.length !== patSegs.length) return null;\n return params;\n}\n\nexport interface MatchResult<R> {\n readonly route: R;\n readonly params: Record<string, string>;\n}\n\n/**\n * Match a pathname against an ordered list of routes. The first route whose\n * pattern matches wins (definition order), so more specific routes should be\n * listed before a `*` fallback.\n */\nexport function matchRoutes<R extends { path: string }>(\n routes: readonly R[],\n pathname: string,\n): MatchResult<R> | null {\n for (const route of routes) {\n const params = matchPattern(route.path, pathname);\n if (params !== null) return { route, params };\n }\n return null;\n}\n\n/** Split a `to` target into its pathname and (already-stripped) search string. */\nexport function splitTarget(to: string): { pathname: string; search: string } {\n const hashIndex = to.indexOf('#');\n const withoutHash = hashIndex >= 0 ? to.slice(0, hashIndex) : to;\n const qIndex = withoutHash.indexOf('?');\n if (qIndex < 0) return { pathname: normalizePath(withoutHash), search: '' };\n return {\n pathname: normalizePath(withoutHash.slice(0, qIndex)),\n search: withoutHash.slice(qIndex + 1),\n };\n}\n","/**\n * Router history — a small abstraction over the navigation source so the router\n * can run both in the browser (real `window.history` + `popstate`) and in tests\n * (an in-memory stack, fully deterministic, no globals).\n *\n * Internal navigation never triggers a full-page reload: the browser history\n * uses `pushState`/`replaceState` and notifies listeners synchronously.\n */\n\nexport interface RouterLocation {\n /** Pathname, always normalized with a single leading slash. */\n readonly pathname: string;\n /** Query string without the leading `?`. */\n readonly search: string;\n}\n\nexport interface RouterHistory {\n /** The current location. */\n location(): RouterLocation;\n /** Push a new entry and notify listeners. */\n push(pathname: string, search: string): void;\n /** Replace the current entry and notify listeners. */\n replace(pathname: string, search: string): void;\n /** Go back one entry. */\n back(): void;\n /** Go forward one entry. */\n forward(): void;\n /** Subscribe to location changes. Returns an unsubscribe function. */\n listen(cb: () => void): () => void;\n /** Detach any global listeners (browser only). */\n dispose(): void;\n}\n\nfunction buildLocation(pathname: string, search: string): RouterLocation {\n return { pathname, search };\n}\n\nfunction toUrl(pathname: string, search: string): string {\n return search.length > 0 ? `${pathname}?${search}` : pathname;\n}\n\n/**\n * Browser history backed by `window.history`. `pushState`/`replaceState` do not\n * emit `popstate`, so we notify listeners ourselves after those calls; genuine\n * back/forward navigation arrives via the `popstate` event.\n */\nexport function createBrowserHistory(): RouterHistory {\n const listeners = new Set<() => void>();\n const notify = (): void => {\n for (const cb of listeners) cb();\n };\n const onPopState = (): void => notify();\n window.addEventListener('popstate', onPopState);\n\n const current = (): RouterLocation => {\n const loc = window.location;\n return buildLocation(loc.pathname, loc.search.replace(/^\\?/, ''));\n };\n\n return {\n location: current,\n push(pathname, search) {\n window.history.pushState({}, '', toUrl(pathname, search));\n notify();\n },\n replace(pathname, search) {\n window.history.replaceState({}, '', toUrl(pathname, search));\n notify();\n },\n back() {\n window.history.back(); // async → emits popstate\n },\n forward() {\n window.history.forward(); // async → emits popstate\n },\n listen(cb) {\n listeners.add(cb);\n return () => listeners.delete(cb);\n },\n dispose() {\n window.removeEventListener('popstate', onPopState);\n listeners.clear();\n },\n };\n}\n\n/**\n * In-memory history for tests and non-DOM environments. Maintains an explicit\n * stack and cursor so `back()`/`forward()` are deterministic.\n */\nexport function createMemoryHistory(initial = '/'): RouterHistory {\n const listeners = new Set<() => void>();\n const notify = (): void => {\n for (const cb of listeners) cb();\n };\n\n const parse = (entry: string): RouterLocation => {\n const qIndex = entry.indexOf('?');\n if (qIndex < 0) return buildLocation(entry, '');\n return buildLocation(entry.slice(0, qIndex), entry.slice(qIndex + 1));\n };\n\n const stack: string[] = [initial];\n let index = 0;\n\n return {\n location() {\n return parse(stack[index]!);\n },\n push(pathname, search) {\n // Drop any forward entries, then append.\n stack.splice(index + 1);\n stack.push(toUrl(pathname, search));\n index = stack.length - 1;\n notify();\n },\n replace(pathname, search) {\n stack[index] = toUrl(pathname, search);\n notify();\n },\n back() {\n if (index > 0) {\n index--;\n notify();\n }\n },\n forward() {\n if (index < stack.length - 1) {\n index++;\n notify();\n }\n },\n listen(cb) {\n listeners.add(cb);\n return () => listeners.delete(cb);\n },\n dispose() {\n listeners.clear();\n },\n };\n}\n","/**\n * StreetUI Router core — renderer-agnostic.\n *\n * Holds the route table, resolves the current location into a `RouteMatch`,\n * and exposes that match as a StreetUI `signal`. Navigation is delegated to a\n * `RouterHistory`; when the location changes (via `navigate`, `back`, `forward`,\n * or a browser `popstate`) the router recomputes the match and updates the\n * signal, which is how every consumer (`isActive`, the mount integration, any\n * `derived` the app builds) stays in sync. No second reactive system.\n */\n\nimport { signal, derived, type ReadonlySignal } from '@streetui/state';\nimport type { RouterHistory } from './history.js';\nimport { createBrowserHistory } from './history.js';\nimport { matchRoutes, normalizePath, splitTarget } from './matching.js';\nimport type { RouteDefinition, RouteMatch } from './types.js';\n\nexport interface RouterOptions {\n /** The route table. Order matters — the first matching pattern wins. */\n readonly routes: readonly RouteDefinition[];\n /**\n * Navigation source. Defaults to a browser history. Pass a memory history\n * for tests or non-DOM environments.\n */\n readonly history?: RouterHistory;\n /**\n * Fallback route used when nothing else matches and no `*` route is present.\n * Defaults to a built-in 404 page (a normal StreetUI tree — no special path).\n */\n readonly notFound?: RouteDefinition;\n}\n\nexport interface NavigateOptions {\n /** Replace the current history entry instead of pushing a new one. */\n readonly replace?: boolean;\n}\n\nexport interface IsActiveOptions {\n /** Require an exact pathname match rather than a prefix match. */\n readonly exact?: boolean;\n}\n\nexport interface Router {\n /** Reactive current match. Consumers subscribe via StreetUI signals. */\n readonly currentRoute: ReadonlySignal<RouteMatch>;\n /** Navigate to a target path (may include a query string). */\n navigate(to: string, options?: NavigateOptions): void;\n /** Go back one history entry. */\n back(): void;\n /** Go forward one history entry. */\n forward(): void;\n /** Reactive predicate: is `path` the active route (or a prefix of it)? */\n isActive(path: string, options?: IsActiveOptions): ReadonlySignal<boolean>;\n /** Tear down history listeners. */\n destroy(): void;\n}\n\n/** Built-in 404 route — a normal StreetUI page tree, overridable via a `*` route. */\nconst DEFAULT_NOT_FOUND: RouteDefinition = {\n path: '*',\n builder: (page) => {\n page.section('not-found', (s) => {\n s.heading('404 — Page not found', { level: 1, id: 'not-found-title' });\n s.text('The page you were looking for does not exist.', { id: 'not-found-text' });\n s.link('Go home', { href: '/', id: 'not-found-home' });\n }, { id: 'not-found' });\n },\n};\n\nexport function createRouter(options: RouterOptions): Router {\n const routes = options.routes;\n const history = options.history ?? createBrowserHistory();\n const fallback = options.notFound ?? DEFAULT_NOT_FOUND;\n\n const resolve = (): RouteMatch => {\n const loc = history.location();\n const pathname = normalizePath(loc.pathname);\n const query = new URLSearchParams(loc.search);\n const matched = matchRoutes(routes, pathname);\n if (matched !== null) {\n return {\n path: pathname,\n pattern: matched.route.path,\n params: matched.params,\n query,\n route: matched.route,\n // A catch-all `*` match is the 404 route whether user-supplied or built-in.\n isFallback: matched.route.path === '*',\n };\n }\n // No explicit route matched — use the fallback (a `*` route if the table\n // has one, otherwise the built-in 404).\n const fallbackParams =\n matchRoutes([fallback], pathname)?.params ?? {};\n return {\n path: pathname,\n pattern: fallback.path,\n params: fallbackParams,\n query,\n route: fallback,\n isFallback: true,\n };\n };\n\n const current = signal<RouteMatch>(resolve());\n const stopListening = history.listen(() => {\n current.set(resolve());\n });\n\n const navigate = (to: string, opts: NavigateOptions = {}): void => {\n const { pathname, search } = splitTarget(to);\n if (opts.replace === true) history.replace(pathname, search);\n else history.push(pathname, search);\n };\n\n const isActive = (path: string, opts: IsActiveOptions = {}): ReadonlySignal<boolean> => {\n const target = normalizePath(path);\n const exact = opts.exact === true;\n return derived(() => {\n const activePath = current.get().path;\n if (activePath === target) return true;\n if (exact || target === '/') return false;\n return activePath.startsWith(`${target}/`);\n });\n };\n\n return {\n currentRoute: current,\n navigate,\n back: () => history.back(),\n forward: () => history.forward(),\n isActive,\n destroy: () => {\n stopListening();\n history.dispose();\n },\n };\n}\n","/**\n * StreetUI Router — DOM integration.\n *\n * `mountRouter` wires a `Router` to real DOM:\n *\n * 1. Mounts an optional persistent shell (layout + navigation) ONCE. The shell\n * declares an outlet element (see `routerOutlet`) into which route content\n * is rendered.\n * 2. Subscribes to `router.currentRoute`. On every change it disposes the\n * previous route (route-scoped `CleanupRegistry.run()` + `runtime.unmount()`)\n * and mounts the new route's compiled application into the outlet.\n * Only the outlet subtree is re-created — the shell persists.\n * 3. Intercepts clicks on internal `<a>` elements for client-side navigation.\n * External links (absolute URLs, `target=\"_blank\"`, `mailto:`/`tel:`) keep\n * their normal browser behaviour, and `link()` is used unchanged.\n *\n * Each route is an ordinary compiled StreetUI application — no special renderer\n * path, no virtual DOM, no full-application rerender on navigation.\n */\n\nimport { streetui, type PageDSL, type ContainerDSL } from '@streetui/dsl';\nimport { resolveTransition, type TransitionConfig } from '@streetui/dsl';\nimport { compile } from '@streetui/compiler';\nimport { createRuntime, type MountedApplication, type StreetRenderer } from '@streetui/runtime';\nimport { createRenderer, runElementTransition } from '@streetui/renderer';\nimport { BrowserDOMAdapter, type DOMAdapter } from '@streetui/dom';\nimport { CleanupRegistry } from '@streetui/core';\nimport type { Router } from './router.js';\nimport type { RouteContext, RouteMatch } from './types.js';\n\n/** Default id used for the route outlet element inside a shell. */\nexport const ROUTER_OUTLET_ID = 'streetui-router-outlet';\n\n/**\n * Declare the route outlet inside a shell builder. The router replaces this\n * element's contents on every navigation.\n */\nexport function routerOutlet(scope: ContainerDSL, id: string = ROUTER_OUTLET_ID): void {\n scope.container('router-outlet', () => { /* filled by the router at runtime */ }, { id });\n}\n\nexport type ShellBuilder = (shell: PageDSL, router: Router) => void;\n\nexport interface MountRouterOptions {\n /** Element to mount into. With a shell, the shell fills this; otherwise routes do. */\n readonly container: Element;\n /** Optional persistent layout. Must include a `routerOutlet(...)`. */\n readonly shell?: ShellBuilder;\n /** Id of the outlet element within the shell. Defaults to `ROUTER_OUTLET_ID`. */\n readonly outletId?: string;\n /** Override the renderer (e.g. a custom DOM adapter for tests). */\n readonly renderer?: StreetRenderer;\n /** Intercept internal `<a>` clicks for client-side navigation. Defaults to true. */\n readonly interceptLinks?: boolean;\n /**\n * Hydrate server-rendered HTML already present in the container instead of\n * mounting fresh. The shell and the *initial* route adopt the existing DOM;\n * subsequent client-side navigations mount normally. Defaults to false.\n */\n readonly hydrate?: boolean;\n /**\n * Optional enter/leave transition played on client-side navigations (§9). When\n * set, each navigation mounts the incoming route into its own host wrapper,\n * plays the enter animation on it, and defers the outgoing route's disposal\n * (route-scoped cleanup + DOM removal) until its leave animation ends — so\n * resources stay alive exactly as long as the departing DOM. History is\n * untouched (the router already navigated), and the initial mount/hydration is\n * NOT animated (§22-style: the first paint must match the server). Reuses the\n * single CSS-class transition engine — no second animation system.\n */\n readonly transition?: TransitionConfig;\n}\n\nexport interface MountedRouter {\n /** The element route content is rendered into. */\n readonly outlet: Element;\n /** Tear down the current route, the shell, link interception and the router. */\n unmount(): void;\n}\n\n/** A URL is external when it targets another origin or a non-navigational scheme. */\nfunction isExternalHref(href: string): boolean {\n return (\n /^[a-zA-Z][a-zA-Z\\d+.-]*:/.test(href) || // scheme: http:, https:, mailto:, tel:\n href.startsWith('//') // protocol-relative\n );\n}\n\nexport function mountRouter(router: Router, options: MountRouterOptions): MountedRouter {\n const { container } = options;\n const renderer = options.renderer ?? createRenderer();\n const outletId = options.outletId ?? ROUTER_OUTLET_ID;\n const interceptLinks = options.interceptLinks ?? true;\n const hydrateMode = options.hydrate ?? false;\n\n // ── 1. Mount the shell once (if any) and resolve the outlet ──────────────────\n let shellMounted: MountedApplication | null = null;\n let outlet: Element;\n\n if (options.shell !== undefined) {\n const shellApp = streetui.app({ name: 'router-shell' });\n const shellBuilder = options.shell;\n shellApp.page('shell', (page) => shellBuilder(page, router));\n const shellRuntime = createRuntime({ renderer });\n const shellCompiled = compile(shellApp);\n if (hydrateMode) {\n // The outlet is a slot the router fills. When the shell hydrates, mark the\n // outlet node as a hydration boundary so shell hydration adopts the outlet\n // element itself but preserves the server-rendered route content inside it\n // (instead of stripping it as surplus). The initial route then hydrates\n // that content node-for-node.\n for (const node of shellCompiled.graph.findAll((n) => n.getProp('id') === outletId)) {\n node.setProp('_hydrationBoundary', true);\n }\n }\n shellMounted = hydrateMode\n ? shellRuntime.hydrate(shellCompiled, container)\n : shellRuntime.mount(shellCompiled, container);\n\n const found = container.querySelector(`[id=\"${outletId}\"]`);\n if (found === null) {\n throw new Error(\n `[Router] The shell must contain a route outlet. Call routerOutlet(scope) ` +\n `(or add a container with id=\"${outletId}\") inside your shell builder.`,\n );\n }\n outlet = found;\n } else {\n outlet = container;\n }\n\n // ── 2. Route mounting / disposal ─────────────────────────────────────────────\n const routeTransition =\n options.transition !== undefined ? resolveTransition(options.transition) : undefined;\n // A DOM adapter for the transition host manipulation. Only constructed when a\n // transition is configured (browser-only feature), so SSR/headless router use\n // never touches a browser global. Manipulates the same `class` attribute the\n // reconciler-driven transitions use, via the same engine.\n const txDom: DOMAdapter | undefined =\n routeTransition !== undefined ? new BrowserDOMAdapter() : undefined;\n\n interface ActiveRoute {\n readonly registry: CleanupRegistry;\n readonly mounted: MountedApplication;\n /** The host wrapper this route's DOM lives in (transition mode only). */\n host: Element | null;\n /** In-flight enter run, cancelled if this host starts leaving (rapid nav). */\n enterRun: { cancel(): void } | null;\n }\n let active: ActiveRoute | null = null;\n // Routes whose leave animation is still running (transition mode). Kept so a\n // hard `unmount()` can settle + tear them down instead of leaking.\n const pendingLeaves = new Map<ActiveRoute, { cancel(): void }>();\n // Only the very first route render hydrates the server HTML in the outlet;\n // client-side navigations after that mount fresh.\n let firstRender = hydrateMode;\n\n /** Full synchronous teardown of a route (no transition / on leave-end). */\n const teardownRoute = (route: ActiveRoute): void => {\n // Run user-registered cleanup (effects, subscriptions) FIRST, then tear down\n // the DOM + runtime signal bindings. Both reuse existing machinery.\n route.registry.run();\n route.mounted.unmount();\n if (route.host !== null && txDom !== undefined) {\n const parent = txDom.parentNode(route.host);\n if (parent !== null) txDom.removeChild(parent, route.host);\n }\n };\n\n const disposeActive = (): void => {\n if (active === null) return;\n teardownRoute(active);\n active = null;\n };\n\n /**\n * Move whatever is currently in the outlet into a fresh host wrapper (used to\n * isolate a hydrated/initial route so it can be animated out on the first\n * client navigation). Returns the wrapper, now the sole child of the outlet.\n */\n const wrapOutletChildren = (dom: DOMAdapter): Element => {\n const host = dom.createElement('div');\n dom.setAttribute(host, 'data-streetui-route', '');\n const moved: Node[] = [];\n let child = dom.firstChild(outlet);\n while (child !== null) {\n moved.push(child);\n child = dom.nextSibling(child);\n }\n for (const n of moved) dom.appendChild(host, n);\n dom.appendChild(outlet, host);\n return host;\n };\n\n /** Build + mount (or hydrate) a route into `target`, returning its handle. */\n const buildRoute = (\n match: RouteMatch,\n target: Element,\n hydrate: boolean,\n ): ActiveRoute => {\n const registry = new CleanupRegistry();\n const ctx: RouteContext = {\n path: match.path,\n pattern: match.pattern,\n params: match.params,\n query: match.query,\n onCleanup: (fn) => registry.add(fn),\n };\n const routeApp = streetui.app({ name: `route:${match.pattern}` });\n routeApp.page('route', (page) => match.route.builder(page, ctx));\n const runtime = createRuntime({ renderer });\n const routeCompiled = compile(routeApp);\n const mounted = hydrate\n ? runtime.hydrate(routeCompiled, target)\n : runtime.mount(routeCompiled, target);\n return { registry, mounted, host: null, enterRun: null };\n };\n\n const renderRoute = (match: RouteMatch): void => {\n // Non-transitioned path — unchanged synchronous behaviour.\n if (routeTransition === undefined || txDom === undefined) {\n disposeActive();\n active = buildRoute(match, outlet, firstRender);\n firstRender = false;\n return;\n }\n\n // Transitioned path. The initial render (mount or hydrate) is NOT animated:\n // it must match the server paint, so we just place it in a host wrapper for\n // later animation and return.\n if (active === null) {\n if (firstRender) {\n // Hydrate the server HTML in place, then isolate it in a host wrapper.\n active = buildRoute(match, outlet, true);\n active.host = wrapOutletChildren(txDom);\n } else {\n const host = txDom.createElement('div');\n txDom.setAttribute(host, 'data-streetui-route', '');\n txDom.appendChild(outlet, host);\n active = buildRoute(match, host, false);\n active.host = host;\n }\n firstRender = false;\n return;\n }\n\n // Client-side navigation with a route already mounted: cross-fade.\n firstRender = false;\n const leaving = active;\n // Abort any in-flight enter on the departing host so we never run two\n // overlapping animations on one element (§6 discipline).\n leaving.enterRun?.cancel();\n leaving.enterRun = null;\n const leaveHost = leaving.host;\n\n // Mount the incoming route into a fresh host and animate it in.\n const enterHost = txDom.createElement('div');\n txDom.setAttribute(enterHost, 'data-streetui-route', '');\n txDom.appendChild(outlet, enterHost);\n const next = buildRoute(match, enterHost, false);\n next.host = enterHost;\n next.enterRun = runElementTransition(txDom, enterHost, routeTransition, 'enter', () => {\n next.enterRun = null;\n });\n active = next;\n\n // Animate the departing host out, then tear the old route down. Resources\n // (route-scoped cleanup + signal bindings) live until the leave completes.\n if (leaveHost !== null) {\n const run = runElementTransition(txDom, leaveHost, routeTransition, 'leave', () => {\n pendingLeaves.delete(leaving);\n teardownRoute(leaving);\n });\n pendingLeaves.set(leaving, run);\n } else {\n teardownRoute(leaving);\n }\n };\n\n // Initial render, then react to every route change.\n renderRoute(router.currentRoute.peek());\n const stopRouteSub = router.currentRoute.subscribe((match) => renderRoute(match));\n\n // ── 3. Client-side link interception ─────────────────────────────────────────\n const onClick = (event: Event): void => {\n if (event.defaultPrevented) return;\n const mouse = event as MouseEvent;\n if (typeof mouse.button === 'number' && mouse.button !== 0) return;\n if (mouse.metaKey || mouse.ctrlKey || mouse.shiftKey || mouse.altKey) return;\n\n const target = event.target as Element | null;\n const anchor = target?.closest?.('a') ?? null;\n if (anchor === null) return;\n\n const targetAttr = anchor.getAttribute('target');\n if (targetAttr !== null && targetAttr !== '_self') return; // _blank etc.\n\n const href = anchor.getAttribute('href');\n if (href === null || href === '' || href.startsWith('#')) return;\n if (isExternalHref(href)) return;\n\n event.preventDefault();\n router.navigate(href);\n };\n\n if (interceptLinks) {\n container.addEventListener('click', onClick);\n }\n\n // ── Teardown ─────────────────────────────────────────────────────────────────\n return {\n outlet,\n unmount() {\n if (interceptLinks) container.removeEventListener('click', onClick);\n stopRouteSub();\n // Settle any in-flight leave animations and tear their routes down.\n for (const [route, run] of pendingLeaves) {\n run.cancel();\n teardownRoute(route);\n }\n pendingLeaves.clear();\n disposeActive();\n shellMounted?.unmount();\n router.destroy();\n },\n };\n}\n","/**\n * A small, sync validation system.\n *\n * A `Validator` maps a string field value to an error message, or `undefined`\n * when the value is acceptable. This is deliberately tiny — the built-ins cover\n * the common cases (`required`, `minLength`, `maxLength`, `email`, `pattern`)\n * and anything else is just a plain function `(value: string) => string | undefined`.\n *\n * Validators for a field run in order and the FIRST error wins, so list\n * `required` first if a field is mandatory.\n *\n * Async validation is intentionally NOT part of this core. It can be layered on\n * top with `@streetui/state`'s `resource()` (kick off a resource on value\n * change and surface `resource.error` alongside the field error) without\n * destabilising the synchronous validity model here.\n */\n\nexport type Validator = (value: string) => string | undefined;\n\n/** Fails when the trimmed value is empty. */\nexport function required(message = 'This field is required'): Validator {\n return (value) => (value.trim().length === 0 ? message : undefined);\n}\n\n/** Fails when the value is shorter than `length` characters. */\nexport function minLength(length: number, message?: string): Validator {\n return (value) =>\n value.length < length\n ? (message ?? `Must be at least ${length} characters`)\n : undefined;\n}\n\n/** Fails when the value is longer than `length` characters. */\nexport function maxLength(length: number, message?: string): Validator {\n return (value) =>\n value.length > length\n ? (message ?? `Must be at most ${length} characters`)\n : undefined;\n}\n\n// Pragmatic, dependency-free email shape check (not a full RFC 5322 parser).\nconst EMAIL_RE = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\n/** Fails when a non-empty value is not a plausible email address. */\nexport function email(message = 'Enter a valid email address'): Validator {\n return (value) => (value.length === 0 || EMAIL_RE.test(value) ? undefined : message);\n}\n\n/** Fails when a non-empty value does not match `regex`. */\nexport function pattern(regex: RegExp, message = 'Invalid format'): Validator {\n return (value) => (value.length === 0 || regex.test(value) ? undefined : message);\n}\n\n/** Run a validator (or ordered list) and return the first error, if any. */\nexport function runValidators(\n value: string,\n validators: Validator | ReadonlyArray<Validator> | undefined,\n): string | undefined {\n if (validators === undefined) return undefined;\n const list = Array.isArray(validators) ? validators : [validators];\n for (const validate of list) {\n const error = validate(value);\n if (error !== undefined) return error;\n }\n return undefined;\n}\n","/**\n * Reactive form model built entirely on `@streetui/state` signals.\n *\n * There is no second state system here: every piece of form state (`values`,\n * `errors`, `touched`, `dirty`, `valid`, submission status) is a signal or a\n * derived signal, so it composes with the renderer's existing reactive bindings.\n * A field's `value` is a writable `Signal<string>`, which plugs straight into\n * the DSL's `input({ bind })` — typing updates form state and programmatic\n * updates update the input, through the one binding the renderer already wires.\n */\n\nimport {\n signal,\n derived,\n batch,\n DerivedSignal,\n type Signal,\n type ReadonlySignal,\n type Unsubscribe,\n} from '@streetui/state';\nimport { type Validator, runValidators } from './validators.js';\n\n/** Form values are a flat, typed record of string fields (HTML input values). */\nexport type FormValues = Record<string, string>;\n\nexport interface Field {\n readonly name: string;\n /** Writable value signal — pass to `input({ bind: field.value })`. */\n readonly value: Signal<string>;\n /** Current validation error, or `undefined` when the field is valid. */\n readonly error: ReadonlySignal<string | undefined>;\n /** True once the field has received a genuine user interaction. */\n readonly touched: ReadonlySignal<boolean>;\n /** True when the value differs from its initial value. */\n readonly dirty: ReadonlySignal<boolean>;\n /** True when the field has no validation error. */\n readonly valid: ReadonlySignal<boolean>;\n /** Programmatically set the value (does not mark the field touched). */\n setValue(next: string): void;\n /** Force the touched flag (defaults to true). */\n markTouched(touched?: boolean): void;\n /** Restore this field's initial value and clear its touched flag. */\n reset(): void;\n}\n\nexport type FormValidators<T extends FormValues> = {\n readonly [K in keyof T]?: Validator | ReadonlyArray<Validator>;\n};\n\nexport interface FormConfig<T extends FormValues> {\n readonly initialValues: T;\n readonly validators?: FormValidators<T>;\n /** Called by `submit()` once all fields are valid. May be async. */\n readonly onSubmit?: (values: T) => void | Promise<void>;\n}\n\nexport type SubmitStatus = 'idle' | 'submitting' | 'success' | 'error';\n\nexport interface Form<T extends FormValues> {\n readonly values: ReadonlySignal<T>;\n readonly errors: ReadonlySignal<Partial<Record<keyof T, string>>>;\n readonly touched: ReadonlySignal<Partial<Record<keyof T, boolean>>>;\n readonly dirty: ReadonlySignal<boolean>;\n readonly valid: ReadonlySignal<boolean>;\n readonly submitting: ReadonlySignal<boolean>;\n readonly submitted: ReadonlySignal<boolean>;\n readonly status: ReadonlySignal<SubmitStatus>;\n readonly submitError: ReadonlySignal<unknown>;\n /** Access the reactive state + setters for one field. */\n field<K extends keyof T & string>(name: K): Field;\n /** Merge a partial set of values in (does not mark fields touched). */\n setValues(partial: Partial<T>): void;\n /** Validate, mark all fields touched, then run `onSubmit` if valid. */\n submit(): Promise<void>;\n /** Restore initial values and clear errors/touched/dirty/submission state. */\n reset(): void;\n /** Tear down all field subscriptions and derived signals. */\n dispose(): void;\n}\n\ninterface FieldInternal {\n readonly api: Field;\n readonly value: Signal<string>;\n readonly touched: Signal<boolean>;\n readonly error: DerivedSignal<string | undefined>;\n readonly valid: DerivedSignal<boolean>;\n readonly dirty: DerivedSignal<boolean>;\n readonly initial: string;\n readonly unsub: Unsubscribe;\n}\n\n// __FORM_IMPL__\n\nexport function createForm<T extends FormValues>(config: FormConfig<T>): Form<T> {\n const names = Object.keys(config.initialValues) as Array<keyof T & string>;\n const validators = config.validators ?? ({} as FormValidators<T>);\n\n // While true, value changes originate from setValues()/reset() and must NOT\n // mark a field touched. Batch flushes run synchronously inside batch(), i.e.\n // before this flag is reset, so guarding around batch() is sound.\n let programmatic = false;\n\n const fields = new Map<string, FieldInternal>();\n\n for (const name of names) {\n // Keys come from Object.keys(initialValues), so the value is always present;\n // the annotation defeats noUncheckedIndexedAccess widening to `| undefined`.\n const initial: string = config.initialValues[name] as string;\n const value = signal<string>(initial);\n const touched = signal<boolean>(false);\n const error = derived<string | undefined>(() =>\n runValidators(value.get(), validators[name]),\n );\n const valid = derived<boolean>(() => error.get() === undefined);\n const dirty = derived<boolean>(() => value.get() !== initial);\n\n // Mark touched on the first genuine (non-programmatic) value change.\n const unsub = value.subscribe(() => {\n if (!programmatic) touched.set(true);\n });\n\n const api: Field = {\n name,\n value,\n error,\n touched,\n dirty,\n valid,\n setValue(next: string): void {\n value.set(next);\n },\n markTouched(next = true): void {\n touched.set(next);\n },\n reset(): void {\n programmatic = true;\n try {\n batch(() => {\n value.set(initial);\n touched.set(false);\n });\n } finally {\n programmatic = false;\n }\n },\n };\n\n fields.set(name, { api, value, touched, error, valid, dirty, initial, unsub });\n }\n\n const field = (name: string): FieldInternal => {\n const f = fields.get(name);\n if (f === undefined) throw new Error(`Unknown form field: ${name}`);\n return f;\n };\n\n const values = derived<T>(() => {\n const out: Record<string, string> = {};\n for (const name of names) out[name] = field(name).value.get();\n return out as T;\n });\n\n const errors = derived<Partial<Record<keyof T, string>>>(() => {\n const out: Partial<Record<keyof T, string>> = {};\n for (const name of names) {\n const e = field(name).error.get();\n if (e !== undefined) out[name] = e;\n }\n return out;\n });\n\n const touchedMap = derived<Partial<Record<keyof T, boolean>>>(() => {\n const out: Partial<Record<keyof T, boolean>> = {};\n for (const name of names) out[name] = field(name).touched.get();\n return out;\n });\n\n const dirty = derived<boolean>(() => names.some((n) => field(n).dirty.get()));\n const valid = derived<boolean>(() => names.every((n) => field(n).valid.get()));\n\n const status = signal<SubmitStatus>('idle');\n const submitting = derived<boolean>(() => status.get() === 'submitting');\n const submitted = derived<boolean>(() => status.get() === 'success');\n const submitError = signal<unknown>(undefined);\n\n function setValues(partial: Partial<T>): void {\n programmatic = true;\n try {\n batch(() => {\n for (const name of names) {\n const next = partial[name];\n if (next !== undefined) field(name).value.set(next);\n }\n });\n } finally {\n programmatic = false;\n }\n }\n\n function reset(): void {\n programmatic = true;\n try {\n batch(() => {\n for (const name of names) {\n const f = field(name);\n f.value.set(f.initial);\n f.touched.set(false);\n }\n status.set('idle');\n submitError.set(undefined);\n });\n } finally {\n programmatic = false;\n }\n }\n\n async function submit(): Promise<void> {\n // Touch every field so validation errors become visible on submit attempts.\n batch(() => {\n for (const name of names) field(name).touched.set(true);\n });\n if (!valid.peek()) {\n // Invalid — do not enter the submitting lifecycle; field errors now show.\n return;\n }\n submitError.set(undefined);\n status.set('submitting');\n try {\n await config.onSubmit?.(values.peek());\n status.set('success');\n } catch (err) {\n submitError.set(err);\n status.set('error');\n }\n }\n\n function dispose(): void {\n for (const f of fields.values()) {\n f.unsub();\n f.error.dispose();\n f.valid.dispose();\n f.dirty.dispose();\n }\n values.dispose();\n errors.dispose();\n touchedMap.dispose();\n dirty.dispose();\n valid.dispose();\n submitting.dispose();\n submitted.dispose();\n }\n\n return {\n values,\n errors,\n touched: touchedMap,\n dirty,\n valid,\n submitting,\n submitted,\n status,\n submitError,\n field: (name) => field(name).api,\n setValues,\n submit,\n reset,\n dispose,\n };\n}\n\n","/**\n * @streetui/context — build-time provider/consumer scoping.\n *\n * StreetUI builds its semantic tree synchronously, top-down, when the DSL\n * builders run. A `Context` mirrors that shape: `provide(value, run)` pushes a\n * value for the duration of the synchronous `run()` (during which the child\n * DSL builders execute and may `consume()`), then pops it. Consumers resolve\n * the *nearest* enclosing provider, falling back to the context default.\n *\n * This is deliberately NOT a second reactive system. A context value can be a\n * signal (see @streetui/state); reactivity then belongs to that signal and is\n * torn down by the normal node lifecycle when the consuming subtree unmounts —\n * the context itself holds no subscriptions and leaves no refs behind after a\n * `provide()` call returns.\n */\n\nexport interface Context<T> {\n /** Unique identity for this context (useful for debugging/inspection). */\n readonly id: symbol;\n /** The value returned by {@link consume} when no provider is active. */\n readonly defaultValue: T;\n /**\n * Provide `value` to any `consume()` calls made synchronously inside `run`.\n * The value is popped again as soon as `run` returns (even if it throws),\n * so nesting resolves to the nearest active provider.\n */\n provide<R>(value: T, run: () => R): R;\n /** Read the nearest active provider's value, or {@link defaultValue}. */\n consume(): T;\n /** True while at least one provider is active for this context. */\n hasProvider(): boolean;\n}\n\n/**\n * Create a typed context with a required default value, so `consume()` always\n * returns a `T` (never `undefined` unless `T` itself permits it).\n */\nexport function createContext<T>(defaultValue: T, description?: string): Context<T> {\n const id = Symbol(description ?? 'streetui.context');\n const stack: T[] = [];\n\n return {\n id,\n defaultValue,\n provide<R>(value: T, run: () => R): R {\n stack.push(value);\n try {\n return run();\n } finally {\n stack.pop();\n }\n },\n consume(): T {\n return stack.length > 0 ? (stack[stack.length - 1] as T) : defaultValue;\n },\n hasProvider(): boolean {\n return stack.length > 0;\n },\n };\n}\n","/**\n * Minimal, framework-native internationalization for StreetUI.\n *\n * Built entirely on `@streetui/state` signals — there is no second reactive\n * system. The active locale is a writable signal; `t()` returns a derived\n * signal that recomputes when the locale changes, so translations plug\n * straight into the DSL's reactive text bindings (`text(() => i18n.t(...).get())`\n * or `text(i18n.t(...))`).\n *\n * Translation is deterministic: a missing key resolves to the key itself, and\n * the same (locale, key, params) always produces the same string on the server\n * and the client. That determinism is what keeps `renderToString()` and\n * `hydrate()` in agreement — provided the app boots the client with the same\n * initial locale it rendered with on the server.\n */\n\nimport {\n signal,\n derived,\n type ReadonlySignal,\n type DerivedSignal,\n} from '@streetui/state';\n\n/** A flat dictionary of message templates for a single locale. */\nexport type MessageMap = Record<string, string>;\n\n/** Values allowed in interpolation params. */\nexport type InterpolationParams = Record<string, string | number>;\n\nexport interface I18nConfig<M extends MessageMap> {\n /** The initial (and server-rendered) locale. */\n readonly locale: string;\n /** Messages keyed by locale, e.g. `{ en: {...}, fr: {...} }`. */\n readonly messages: Readonly<Record<string, M>>;\n /** Locale consulted when a key is absent from the active locale. */\n readonly fallbackLocale?: string;\n}\n\nexport interface I18n<M extends MessageMap> {\n /** The active locale as a reactive, read-only signal. */\n readonly locale: ReadonlySignal<string>;\n /** Switch the active locale; all `t()`/`plural()` signals recompute. */\n setLocale(locale: string): void;\n /** The locales that have a message map, in declaration order. */\n readonly locales: ReadonlyArray<string>;\n /** Reactive translation. Returns a derived signal — call `.get()` to read. */\n t(key: keyof M & string, params?: InterpolationParams): ReadonlySignal<string>;\n /** Non-reactive translation for the current locale (a one-shot read). */\n translate(key: keyof M & string, params?: InterpolationParams): string;\n /**\n * Reactive pluralization via `Intl.PluralRules`. Selects the message whose\n * key is `${key}.${category}` (e.g. `items.one`), falling back to\n * `${key}.other`. `count` is available to interpolation as `{count}`.\n */\n plural(key: string, count: number, params?: InterpolationParams): ReadonlySignal<string>;\n /** True when the active (or fallback) locale defines `key`. */\n has(key: string): boolean;\n}\n\nconst INTERPOLATION = /\\{(\\w+)\\}/g;\n\n/** Replace `{name}` placeholders using `params`; unknown names are left intact. */\nexport function interpolate(template: string, params?: InterpolationParams): string {\n if (params === undefined) return template;\n return template.replace(INTERPOLATION, (whole, name: string) => {\n const value = params[name];\n return value === undefined ? whole : String(value);\n });\n}\n\nexport function createI18n<M extends MessageMap>(config: I18nConfig<M>): I18n<M> {\n const messages = config.messages;\n const fallback = config.fallbackLocale;\n const localeSignal = signal<string>(config.locale);\n const locales = Object.keys(messages);\n\n /** Resolve a raw template for `key` in `loc`, then the fallback locale. */\n function lookup(loc: string, key: string): string | undefined {\n const active = messages[loc];\n const hit = active === undefined ? undefined : active[key];\n if (hit !== undefined) return hit;\n if (fallback !== undefined && fallback !== loc) {\n const fb = messages[fallback];\n if (fb !== undefined) return fb[key];\n }\n return undefined;\n }\n\n function resolve(loc: string, key: string, params?: InterpolationParams): string {\n const template = lookup(loc, key);\n // Deterministic miss: echo the key so output is stable server/client.\n return template === undefined ? key : interpolate(template, params);\n }\n\n function pluralKey(loc: string, key: string, count: number): string {\n const category = new Intl.PluralRules(loc).select(count);\n if (lookup(loc, `${key}.${category}`) !== undefined) return `${key}.${category}`;\n return `${key}.other`;\n }\n\n return {\n locale: localeSignal,\n locales,\n setLocale(loc: string): void {\n localeSignal.set(loc);\n },\n t(key, params): DerivedSignal<string> {\n return derived<string>(() => resolve(localeSignal.get(), key, params));\n },\n translate(key, params): string {\n return resolve(localeSignal.peek(), key, params);\n },\n plural(key, count, params): DerivedSignal<string> {\n const merged: InterpolationParams = { count, ...(params ?? {}) };\n return derived<string>(() => {\n const loc = localeSignal.get();\n return resolve(loc, pluralKey(loc, key, count), merged);\n });\n },\n has(key: string): boolean {\n return lookup(localeSignal.peek(), key) !== undefined;\n },\n };\n}\n","/**\n * StreetUI DevTools — graph inspector and debug utilities.\n */\n\nimport { formatDiagnostic } from '@streetui/core';\nimport type { ApplicationGraph, GraphNode } from '@streetui/graph';\nimport type { CompiledApplication } from '@streetui/compiler';\n\nexport interface InspectedNode {\n id: string;\n type: string;\n key: string | undefined;\n props: Record<string, unknown>;\n eventTypes: string[];\n stateBindings: string[];\n children: InspectedNode[];\n depth: number;\n}\n\nexport function inspectGraph(graph: ApplicationGraph): InspectedNode {\n return inspectNode(graph.root, 0);\n}\n\nfunction inspectNode(node: GraphNode, depth: number): InspectedNode {\n return {\n id: node.id,\n type: node.type,\n key: node.key,\n props: { ...node.props },\n eventTypes: node.events.map(e => e.type),\n stateBindings: node.stateRefs.map(r => `${r.propKey}→${r.signalId}`),\n depth,\n children: node.children.map(c => inspectNode(c, depth + 1)),\n };\n}\n\n/** Print a human-readable tree of the graph to a string. */\nexport function printGraph(graph: ApplicationGraph): string {\n const lines: string[] = [];\n graph.walk((node, depth) => {\n const indent = ' '.repeat(depth);\n const props = Object.entries(node.props)\n .filter(([k]) => !k.startsWith('_'))\n .map(([k, v]) => `${k}=${JSON.stringify(v)}`)\n .join(', ');\n const events = node.events.length > 0\n ? ` [events: ${node.events.map(e => e.type).join(', ')}]`\n : '';\n const stateRefs = node.stateRefs.length > 0\n ? ` [signals: ${node.stateRefs.map(r => r.propKey).join(', ')}]`\n : '';\n lines.push(`${indent}<${node.type}${props ? ` ${props}` : ''}${events}${stateRefs}>`);\n });\n return lines.join('\\n');\n}\n\n/** Print compilation diagnostics to a string. */\nexport function printDiagnostics(compiled: CompiledApplication): string {\n if (compiled.diagnostics.diagnostics.length === 0) {\n return '(no diagnostics)';\n }\n return compiled.diagnostics.diagnostics.map(formatDiagnostic).join('\\n');\n}\n\n/** Returns node counts per type. */\nexport function nodeTypeStats(graph: ApplicationGraph): Record<string, number> {\n const counts: Record<string, number> = {};\n graph.walk(node => {\n counts[node.type] = (counts[node.type] ?? 0) + 1;\n });\n return counts;\n}\n\n/** A single component instance surfaced for DevTools inspection (§21). */\nexport interface InspectedComponent {\n /** The build-order node id (churns across rebuilds — not stable identity). */\n id: string;\n /** The stable, author-provided identity key passed at the call site. */\n key: string | undefined;\n /** The definition's human-readable name (from `data-streetui-component`). */\n name: string;\n /** Depth of the component node in the graph. */\n depth: number;\n /** Number of direct child nodes the component rendered. */\n childCount: number;\n}\n\n/**\n * List every `component()` instance in the graph, in document order, with its\n * stable `key`, human-readable `name` and location. Components are ordinary\n * `'component'` GraphNodes (they flow through `inspectGraph`/`printGraph`\n * already); this is the first-class, component-aware view for DevTools — it\n * reads the inspectable `data-streetui-component` name attribute the DSL sets,\n * never any internal `_`-prefixed metadata. Names/keys are stable across\n * fine-grained prop updates (which never rebuild the node).\n */\nexport function inspectComponents(graph: ApplicationGraph): InspectedComponent[] {\n const out: InspectedComponent[] = [];\n graph.walk((node, depth) => {\n if (node.type !== 'component') return;\n const name = node.props['data-streetui-component'];\n out.push({\n id: node.id,\n key: node.key,\n name: typeof name === 'string' ? name : 'Component',\n depth,\n childCount: node.children.length,\n });\n });\n return out;\n}\n\n// ── Interaction inspection (§19) ─────────────────────────────────────────────\n\n/** An overlay currently wired in the graph (dialog/popover/tooltip/…). */\nexport interface InspectedOverlay {\n /** The build-order node id of the overlay's portal host. */\n id: string;\n /** The stable author-provided key, if any. */\n key: string | undefined;\n /** Whether the overlay is open right now (peeked, no subscription). */\n open: boolean;\n /** Modal (focus-trapping) overlay? */\n modal: boolean;\n /** Does it move focus into itself on open? */\n takesFocus: boolean;\n /** Is it a roving-focus menu (role=\"menu\")? */\n menu: boolean;\n /** Does Escape close it? */\n closeOnEscape: boolean;\n /** Does it restore focus to the opener on close? */\n restoreFocus: boolean;\n /** Depth of the portal host node in the graph. */\n depth: number;\n}\n\n/** A transition currently wired on a graph node. */\nexport interface InspectedTransition {\n /** The build-order node id the transition is attached to. */\n id: string;\n /** The stable author-provided key, if any. */\n key: string | undefined;\n /** The node type the transition animates (element/portal/list-item/…). */\n nodeType: string;\n /** Fallback completion timeout in ms (the resolved `duration`). */\n duration: number;\n /** Does it animate the very first appearance (initial mount)? */\n appear: boolean;\n /** Depth of the node in the graph. */\n depth: number;\n}\n\n/** A prod-safe snapshot of the graph's interaction wiring. */\nexport interface InspectedInteractions {\n overlays: InspectedOverlay[];\n transitions: InspectedTransition[];\n}\n\n/**\n * Minimal structural views of the descriptors the DSL registers behind\n * `__overlay__<id>` / `__transition__<id>`. Duplicated here (not imported from\n * `@streetui/dsl`) so DevTools reads the wiring structurally, with no build-time\n * dependency on the DSL package — the same no-fragmentation discipline the\n * renderer already follows.\n */\ninterface OverlayDescriptorLike {\n readonly open: { peek(): boolean };\n readonly modal: boolean;\n readonly takesFocus: boolean;\n readonly menu: boolean;\n readonly closeOnEscape: boolean;\n readonly restoreFocus: boolean;\n}\ninterface ResolvedTransitionLike {\n readonly duration: number;\n readonly appear: boolean;\n}\n\n/**\n * Snapshot every overlay and transition currently wired in the graph, in\n * document order. This is the interaction-aware companion to\n * {@link inspectComponents}: it reads only the `__overlay__<id>` /\n * `__transition__<id>` handler descriptors and public graph structure — it\n * peeks the `open` signal without subscribing, retains no DOM nodes, mutates\n * nothing, and is safe to call in production. Because a departing overlay's\n * handler is pruned on detach (`_unregisterNodeHandlers`), a closed-and-removed\n * overlay simply no longer appears here.\n */\nexport function inspectInteractions(graph: ApplicationGraph): InspectedInteractions {\n const overlays: InspectedOverlay[] = [];\n const transitions: InspectedTransition[] = [];\n graph.walk((node, depth) => {\n const overlayFn = graph.getHandler(`__overlay__${node.id}`) as\n | (() => OverlayDescriptorLike)\n | undefined;\n if (overlayFn !== undefined) {\n const d = overlayFn();\n overlays.push({\n id: node.id,\n key: node.key,\n open: d.open.peek(),\n modal: d.modal,\n takesFocus: d.takesFocus,\n menu: d.menu,\n closeOnEscape: d.closeOnEscape,\n restoreFocus: d.restoreFocus,\n depth,\n });\n }\n const transitionFn = graph.getHandler(`__transition__${node.id}`) as\n | (() => ResolvedTransitionLike)\n | undefined;\n if (transitionFn !== undefined) {\n const t = transitionFn();\n transitions.push({\n id: node.id,\n key: node.key,\n nodeType: node.type,\n duration: t.duration,\n appear: t.appear,\n depth,\n });\n }\n });\n return { overlays, transitions };\n}\n\n","/**\n * DevTools foundation (v0.6, Phase 18). A single read-only entry point that\n * aggregates everything an eventual DevTools UI would need — application\n * identity, the graph tree, signal bindings, page/route surface, node\n * statistics, and diagnostics — WITHOUT introducing a second representation of\n * the graph. It reuses `inspectGraph`/`nodeTypeStats` from the inspector and\n * reads `CompiledApplication` metadata directly. This is a foundation, not a\n * UI: it returns plain data so a UI (or a test, or a CLI command) can render it.\n */\n\nimport type { CompiledApplication } from '@streetui/compiler';\nimport { formatDiagnostic } from '@streetui/core';\nimport { inspectGraph, nodeTypeStats, type InspectedNode } from './inspector.js';\n\n/** Stable identity of a compiled application. */\nexport interface ApplicationIdentity {\n readonly name: string;\n readonly version: string;\n /** Epoch millis the application was compiled. */\n readonly compiledAt: number;\n}\n\n/** A page node reachable as a direct child of the application root. */\nexport interface InspectedPage {\n readonly id: string;\n /** The page key when one was supplied in the DSL. */\n readonly key: string | undefined;\n}\n\n/** Compilation diagnostics summarised for display. */\nexport interface DiagnosticsSummary {\n readonly errors: number;\n readonly warnings: number;\n readonly messages: string[];\n}\n\n/**\n * Cheap, count-only performance snapshot (v0.7 §20). These are structural\n * counts derived from a single graph walk — NOT timings and NOT a profiler.\n * They let a DevTools panel or a CI check spot the shapes that correlate with\n * slow apps (very large graphs, deep trees, big lists, many subscriptions)\n * without measuring anything at runtime.\n */\nexport interface PerfSnapshot {\n /** Total GraphNodes in the tree (root included). */\n readonly totalNodes: number;\n /** Maximum nesting depth (root = 0). */\n readonly maxDepth: number;\n /** Total event handler registrations across all nodes. */\n readonly eventHandlers: number;\n /** Total signal→prop bindings across all nodes. */\n readonly stateBindings: number;\n /** Distinct signals referenced anywhere in the graph. */\n readonly distinctSignals: number;\n /** Largest single-node child count (a proxy for the biggest list/section). */\n readonly largestChildCount: number;\n /**\n * Number of reactive keyed-list sites driven by the optimised lazy-plan\n * reconciler (v1.1 §15/§25). Counted from the graph's `__listplan__<id>`\n * handler registrations — one per `listOf(...)` bound to a signal. These are\n * the nodes whose updates take the identity-short-circuit + LIS minimal-move\n * path, so surfacing the count lets a panel or CI check see how much of an app\n * benefits from the keyed-list engine without measuring anything at runtime.\n */\n readonly reactiveLists: number;\n}\n\n/**\n * The complete read-only snapshot of a compiled application. Everything here is\n * derived from the single `CompiledApplication` graph — no state is duplicated.\n */\nexport interface ApplicationInspection {\n readonly identity: ApplicationIdentity;\n readonly graph: InspectedNode;\n /** Count of nodes per DSL type (e.g. `{ section: 2, button: 3 }`). */\n readonly nodeStats: Record<string, number>;\n /** Unique signal ids bound anywhere in the graph, sorted. */\n readonly signals: string[];\n /** Page nodes directly under the root — the app's top-level route surface. */\n readonly pages: InspectedPage[];\n readonly diagnostics: DiagnosticsSummary;\n /** Cheap structural performance counters (v0.7 §20). */\n readonly perf: PerfSnapshot;\n}\n\n/** Walk the inspected tree once, accumulating the count-only perf snapshot. */\nfunction collectPerf(\n node: InspectedNode,\n distinctSignals: number,\n acc: { totalNodes: number; maxDepth: number; eventHandlers: number; stateBindings: number; largestChildCount: number },\n): void {\n acc.totalNodes += 1;\n if (node.depth > acc.maxDepth) acc.maxDepth = node.depth;\n acc.eventHandlers += node.eventTypes.length;\n acc.stateBindings += node.stateBindings.length;\n if (node.children.length > acc.largestChildCount) acc.largestChildCount = node.children.length;\n for (const child of node.children) collectPerf(child, distinctSignals, acc);\n}\n\n/** Collect every distinct signal id referenced by any node in the tree. */\nfunction collectSignals(node: InspectedNode, into: Set<string>): void {\n for (const binding of node.stateBindings) {\n // Bindings are formatted `propKey→signalId` by the inspector.\n const arrow = binding.indexOf('→');\n const signalId = arrow >= 0 ? binding.slice(arrow + 1) : binding;\n if (signalId.length > 0) into.add(signalId);\n }\n for (const child of node.children) collectSignals(child, into);\n}\n\n/**\n * Build the full inspection snapshot for a compiled application. Pure and\n * side-effect free — safe to call in a server, a test, or a DevTools panel.\n */\nexport function inspectApplication(compiled: CompiledApplication): ApplicationInspection {\n const graph = inspectGraph(compiled.graph);\n\n const signals = new Set<string>();\n collectSignals(graph, signals);\n\n const pages: InspectedPage[] = graph.children\n .filter((child) => child.type === 'page')\n .map((child) => ({ id: child.id, key: child.key }));\n\n const diags = compiled.diagnostics.diagnostics;\n const errors = diags.filter((d) => d.severity === 'error').length;\n\n const perfAcc = { totalNodes: 0, maxDepth: 0, eventHandlers: 0, stateBindings: 0, largestChildCount: 0 };\n collectPerf(graph, signals.size, perfAcc);\n\n // Count optimised keyed-list sites from the handler registry (one\n // `__listplan__<id>` per signal-driven `listOf`). Reading the map directly\n // keeps this a pure, count-only derivation — no second graph walk.\n let reactiveLists = 0;\n for (const key of compiled.graph.handlers.keys()) {\n if (key.startsWith('__listplan__')) reactiveLists += 1;\n }\n\n return {\n identity: {\n name: compiled.name,\n version: compiled.version,\n compiledAt: compiled.compiledAt,\n },\n graph,\n nodeStats: nodeTypeStats(compiled.graph),\n signals: [...signals].sort(),\n pages,\n diagnostics: {\n errors,\n warnings: diags.length - errors,\n messages: diags.map(formatDiagnostic),\n },\n perf: {\n totalNodes: perfAcc.totalNodes,\n maxDepth: perfAcc.maxDepth,\n eventHandlers: perfAcc.eventHandlers,\n stateBindings: perfAcc.stateBindings,\n distinctSignals: signals.size,\n largestChildCount: perfAcc.largestChildCount,\n reactiveLists,\n },\n };\n}\n","/**\n * Dev-only performance diagnostics (v0.7 §21).\n *\n * A pure, cheap, count-based check that flags graph *shapes* known to correlate\n * with slow apps — very large graphs, deep trees, oversized lists/sections, and\n * heavy reactive fan-out. It is NOT wired into mount/render and adds ZERO cost\n * to the runtime hot path; a developer (or a CLI command, or a test) calls it\n * explicitly. Thresholds are advisory and overridable.\n *\n * This intentionally reuses the counts already produced by `inspectApplication`\n * — it introduces no second graph walk of its own beyond reading that snapshot.\n */\n\nimport type { CompiledApplication } from '@streetui/compiler';\nimport { inspectApplication } from './application.js';\n\nexport interface PerfThresholds {\n /** Warn when the graph exceeds this many nodes. */\n readonly maxNodes: number;\n /** Warn when nesting depth exceeds this. */\n readonly maxDepth: number;\n /** Warn when any single node has more than this many children (big list). */\n readonly maxChildCount: number;\n /** Warn when distinct signals exceed this (reactive fan-out). */\n readonly maxSignals: number;\n}\n\nexport const DEFAULT_PERF_THRESHOLDS: PerfThresholds = {\n maxNodes: 5000,\n maxDepth: 32,\n maxChildCount: 1000,\n maxSignals: 1000,\n};\n\nexport type PerfDiagnosticCode =\n | 'large-graph'\n | 'deep-tree'\n | 'large-list'\n | 'high-signal-fanout';\n\nexport interface PerfDiagnostic {\n readonly code: PerfDiagnosticCode;\n readonly message: string;\n /** The observed count that tripped the threshold. */\n readonly observed: number;\n /** The threshold it exceeded. */\n readonly threshold: number;\n}\n\n/**\n * Return advisory performance diagnostics for a compiled application. An empty\n * array means nothing tripped a threshold. Never throws; never mutates.\n */\nexport function diagnosePerformance(\n compiled: CompiledApplication,\n thresholds: Partial<PerfThresholds> = {},\n): PerfDiagnostic[] {\n const t = { ...DEFAULT_PERF_THRESHOLDS, ...thresholds };\n const { perf } = inspectApplication(compiled);\n const out: PerfDiagnostic[] = [];\n\n if (perf.totalNodes > t.maxNodes) {\n out.push({\n code: 'large-graph',\n message: `Graph has ${perf.totalNodes} nodes (> ${t.maxNodes}); consider splitting the view or paginating.`,\n observed: perf.totalNodes,\n threshold: t.maxNodes,\n });\n }\n if (perf.maxDepth > t.maxDepth) {\n out.push({\n code: 'deep-tree',\n message: `Graph nests ${perf.maxDepth} levels deep (> ${t.maxDepth}); deep trees slow mount and reconciliation.`,\n observed: perf.maxDepth,\n threshold: t.maxDepth,\n });\n }\n if (perf.largestChildCount > t.maxChildCount) {\n out.push({\n code: 'large-list',\n message: `A single node has ${perf.largestChildCount} children (> ${t.maxChildCount}); large un-windowed lists dominate DOM cost.`,\n observed: perf.largestChildCount,\n threshold: t.maxChildCount,\n });\n }\n if (perf.distinctSignals > t.maxSignals) {\n out.push({\n code: 'high-signal-fanout',\n message: `${perf.distinctSignals} distinct signals are bound (> ${t.maxSignals}); heavy reactive fan-out increases update overhead.`,\n observed: perf.distinctSignals,\n threshold: t.maxSignals,\n });\n }\n\n return out;\n}\n","/**\n * Reactive-surface inspection for DevTools.\n *\n * These functions turn the framework's live objects — signals, resources,\n * router, forms, context, i18n — into plain, read-only snapshots suitable for a\n * DevTools panel. They never mutate anything and never subscribe; each call is a\n * one-shot `peek`. Sensitive-by-default surfaces (resource payloads, form field\n * values) are omitted unless the caller explicitly opts in, so a panel cannot\n * accidentally display tokens, passwords, or private data.\n *\n * Router/forms/context/i18n are described by *structural* interfaces rather than\n * imported types, so DevTools stays decoupled from those packages (no extra\n * dependencies) while still inspecting them when present.\n */\n\nimport {\n type ReadonlySignal,\n type ResourceStatus,\n type SignalKind,\n signalKind,\n observerCount,\n} from '@streetui/state';\n\n// ── Signals ─────────────────────────────────────────────────────────────────\n\nexport interface SignalInspection {\n /** Whether the signal is writable or a derived computation. */\n readonly kind: SignalKind;\n /** The current value (redacted if requested). */\n readonly value: unknown;\n /** Live observer count when the signal exposes it, else undefined. */\n readonly observerCount: number | undefined;\n}\n\nexport interface InspectSignalOptions {\n /**\n * Redact the value: `true` replaces it with `'[redacted]'`; a function maps\n * the raw value to whatever should be shown. Use for signals that may hold\n * sensitive data. Omitted → the value is shown as-is.\n */\n readonly redact?: boolean | ((value: unknown) => unknown);\n}\n\n/** Snapshot a signal's kind, current value, and observer count. Read-only. */\nexport function inspectSignal(\n source: ReadonlySignal<unknown>,\n options: InspectSignalOptions = {},\n): SignalInspection {\n const raw = source.peek();\n let value: unknown = raw;\n if (options.redact === true) value = '[redacted]';\n else if (typeof options.redact === 'function') value = options.redact(raw);\n\n return {\n kind: signalKind(source),\n value,\n observerCount: observerCount(source),\n };\n}\n\n// ── Resources ─────────────────────────────────────────────────────────────\n\n/** The read-only slice of a resource this module needs. */\nexport interface ResourceLike {\n readonly status: ReadonlySignal<ResourceStatus>;\n readonly data: ReadonlySignal<unknown>;\n readonly error: ReadonlySignal<unknown>;\n readonly loading: ReadonlySignal<boolean>;\n readonly isRefetching: ReadonlySignal<boolean>;\n}\n\nexport interface ResourceInspection {\n readonly status: ResourceStatus;\n readonly loading: boolean;\n readonly isRefetching: boolean;\n readonly hasData: boolean;\n readonly hasError: boolean;\n /** The error's constructor name (safe — no message/payload). */\n readonly errorName: string | undefined;\n /** The error message — only present when `includeData` is set. */\n readonly errorMessage?: string;\n /** The loaded value — only present when `includeData` is set. */\n readonly data?: unknown;\n}\n\nexport interface InspectResourceOptions {\n /**\n * Include the loaded `data` and the error `message`. Off by default because a\n * resource payload commonly carries user or secret data.\n */\n readonly includeData?: boolean;\n}\n\n/** Snapshot a resource's lifecycle. Payload/message hidden unless opted in. */\nexport function inspectResource(\n resource: ResourceLike,\n options: InspectResourceOptions = {},\n): ResourceInspection {\n const error = resource.error.peek();\n const hasError = error !== undefined && error !== null;\n const base: ResourceInspection = {\n status: resource.status.peek(),\n loading: resource.loading.peek(),\n isRefetching: resource.isRefetching.peek(),\n hasData: resource.data.peek() !== undefined,\n hasError,\n errorName: hasError ? errorConstructorName(error) : undefined,\n };\n if (options.includeData !== true) return base;\n\n return {\n ...base,\n data: resource.data.peek(),\n ...(hasError ? { errorMessage: errorMessageOf(error) } : {}),\n };\n}\n\nfunction errorConstructorName(error: unknown): string {\n if (error instanceof Error) return error.name;\n return typeof error;\n}\n\nfunction errorMessageOf(error: unknown): string {\n if (error instanceof Error) return error.message;\n return String(error);\n}\n\n// ── Router ──────────────────────────────────────────────────────────────────\n\nexport interface RouteMatchLike {\n readonly path: string;\n readonly pattern: string;\n readonly params: Readonly<Record<string, string>>;\n readonly query: URLSearchParams;\n readonly isFallback?: boolean;\n}\n\nexport interface RouterLike {\n readonly currentRoute: ReadonlySignal<RouteMatchLike>;\n}\n\nexport interface RouterInspection {\n readonly path: string;\n readonly pattern: string;\n readonly params: Record<string, string>;\n readonly query: Record<string, string>;\n readonly isFallback: boolean;\n}\n\n/** Snapshot the router's current route. Read-only. */\nexport function inspectRouter(router: RouterLike): RouterInspection {\n const match = router.currentRoute.peek();\n const query: Record<string, string> = {};\n for (const [k, v] of match.query.entries()) query[k] = v;\n return {\n path: match.path,\n pattern: match.pattern,\n params: { ...match.params },\n query,\n isFallback: match.isFallback === true,\n };\n}\n\n// ── Forms ─────────────────────────────────────────────────────────────────\n\nexport interface FormLike {\n readonly values: ReadonlySignal<Record<string, unknown>>;\n readonly errors: ReadonlySignal<Record<string, string | undefined>>;\n readonly touched: ReadonlySignal<Record<string, boolean | undefined>>;\n readonly dirty: ReadonlySignal<boolean>;\n readonly valid: ReadonlySignal<boolean>;\n readonly status: ReadonlySignal<string>;\n}\n\nexport interface FormInspection {\n readonly fields: string[];\n /** Per-field validation messages (safe — not the entered values). */\n readonly errors: Record<string, string>;\n readonly touched: Record<string, boolean>;\n readonly dirty: boolean;\n readonly valid: boolean;\n readonly status: string;\n /** Entered field values — only present when `includeValues` is set. */\n readonly values?: Record<string, unknown>;\n}\n\nexport interface InspectFormOptions {\n /**\n * Include the entered field `values`. Off by default because form fields\n * frequently hold passwords or other secrets.\n */\n readonly includeValues?: boolean;\n}\n\n/** Snapshot form validation state. Entered values hidden unless opted in. */\nexport function inspectForm(form: FormLike, options: InspectFormOptions = {}): FormInspection {\n const values = form.values.peek();\n const errorsRaw = form.errors.peek();\n const touchedRaw = form.touched.peek();\n\n const errors: Record<string, string> = {};\n for (const [k, v] of Object.entries(errorsRaw)) if (v !== undefined) errors[k] = v;\n const touched: Record<string, boolean> = {};\n for (const [k, v] of Object.entries(touchedRaw)) touched[k] = v === true;\n\n const base: FormInspection = {\n fields: Object.keys(values),\n errors,\n touched,\n dirty: form.dirty.peek(),\n valid: form.valid.peek(),\n status: form.status.peek(),\n };\n if (options.includeValues !== true) return base;\n return { ...base, values: { ...values } };\n}\n\n// ── Context ─────────────────────────────────────────────────────────────────\n\nexport interface ContextLike {\n readonly id: symbol;\n hasProvider(): boolean;\n}\n\nexport interface ContextInspection {\n /** The context's descriptive label (from its Symbol). */\n readonly description: string;\n /** Whether a provider is currently active. */\n readonly hasProvider: boolean;\n}\n\n/** Snapshot a context's identity and provider presence. No value dumped. */\nexport function inspectContext(context: ContextLike): ContextInspection {\n return {\n description: context.id.description ?? 'streetui.context',\n hasProvider: context.hasProvider(),\n };\n}\n\n// ── i18n ──────────────────────────────────────────────────────────────────\n\nexport interface I18nLike {\n readonly locale: ReadonlySignal<string>;\n readonly locales: ReadonlyArray<string>;\n has(key: string): boolean;\n}\n\nexport interface I18nInspection {\n readonly locale: string;\n readonly locales: string[];\n /** Of the probed keys, those with no translation in the active/fallback locale. */\n readonly missingKeys?: string[];\n}\n\nexport interface InspectI18nOptions {\n /** Keys to probe for presence; any absent ones are reported as missing. */\n readonly checkKeys?: readonly string[];\n}\n\n/** Snapshot i18n locale state and (optionally) missing translation keys. */\nexport function inspectI18n(i18n: I18nLike, options: InspectI18nOptions = {}): I18nInspection {\n const base: I18nInspection = {\n locale: i18n.locale.peek(),\n locales: [...i18n.locales],\n };\n if (options.checkKeys === undefined) return base;\n const missingKeys = options.checkKeys.filter((k) => !i18n.has(k));\n return { ...base, missingKeys };\n}\n","/**\n * DevTools session & panels — the first real StreetUI DevTools surface.\n *\n * This is a *headless* DevTools layer: it composes the existing read-only\n * inspection functions (`inspectApplication`, `diagnosePerformance`, and the\n * reactive inspectors) into the panels a DevTools UI shows — Application, Graph,\n * Signals, Router, Resources, Forms, Context, i18n, and Performance — and\n * returns them as plain data plus a text formatter. Any host (a browser panel, a\n * CLI command, a test) can render that data.\n *\n * Design constraints honoured here:\n * - No second graph and no second reactive system — everything is derived from\n * the one `CompiledApplication` and the app's own live signals.\n * - Explicit activation: nothing in the runtime imports this. A session only\n * exists once dev code calls `createDevTools`, so production pays no cost.\n * - Live updates use a simple explicit `refresh()` — DevTools never subscribes\n * to or instruments the reactive graph.\n * - Sensitive surfaces (resource payloads, form values) stay hidden unless the\n * caller opts in per the underlying inspectors.\n */\n\nimport type { CompiledApplication } from '@streetui/compiler';\nimport type { ReadonlySignal } from '@streetui/state';\nimport {\n inspectApplication,\n type ApplicationInspection,\n type ApplicationIdentity,\n type InspectedPage,\n} from './application.js';\nimport type { InspectedNode } from './inspector.js';\nimport {\n inspectComponents,\n inspectInteractions,\n type InspectedComponent,\n type InspectedOverlay,\n type InspectedTransition,\n} from './inspector.js';\nimport { diagnosePerformance, type PerfDiagnostic, type PerfThresholds } from './diagnostics.js';\nimport {\n inspectSignal,\n inspectResource,\n inspectRouter,\n inspectForm,\n inspectContext,\n inspectI18n,\n type SignalInspection,\n type ResourceInspection,\n type RouterInspection,\n type FormInspection,\n type ContextInspection,\n type I18nInspection,\n type ResourceLike,\n type RouterLike,\n type FormLike,\n type ContextLike,\n type I18nLike,\n} from './inspect-reactive.js';\n\n// ── Panel shapes ────────────────────────────────────────────────────────────\n\nexport interface ApplicationPanel {\n readonly identity: ApplicationIdentity;\n readonly nodeCount: number;\n readonly maxDepth: number;\n readonly pages: readonly InspectedPage[];\n readonly signalCount: number;\n readonly eventHandlers: number;\n readonly stateBindings: number;\n readonly errors: number;\n readonly warnings: number;\n}\n\nexport interface SignalsPanel {\n /** Distinct signal ids referenced anywhere in the graph (structural). */\n readonly boundSignalIds: readonly string[];\n /** Live inspections for signals the app registered with DevTools, by label. */\n readonly live: Readonly<Record<string, SignalInspection>>;\n}\n\nexport interface PerformancePanel {\n readonly snapshot: ApplicationInspection['perf'];\n readonly diagnostics: readonly PerfDiagnostic[];\n}\n\n/**\n * Compilation diagnostics for the DevTools \"Diagnostics\" panel (§8). These are\n * the compiler's own findings (errors + warnings), surfaced verbatim — not a\n * runtime error stream. Runtime/production error reports flow through the\n * separate `reportError`/`DiagnosticSink` seam in `@streetui/core` (§7).\n */\nexport interface DiagnosticsPanel {\n readonly errors: number;\n readonly warnings: number;\n readonly messages: readonly string[];\n}\n\n/** All panels captured at one `refresh()`. */\nexport interface DevToolsSnapshot {\n readonly application: ApplicationPanel;\n readonly graph: InspectedNode;\n readonly signals: SignalsPanel;\n readonly performance: PerformancePanel;\n /**\n * Component tree (§9): every `component()` instance in document order, with\n * its stable key/name/location. Read structurally from the graph — the same\n * data an app/component-tree UI panel renders.\n */\n readonly components: readonly InspectedComponent[];\n /** Overlays currently wired (§13), in graph/containment order (dialog/popover/…). */\n readonly overlays: readonly InspectedOverlay[];\n /** Transitions currently wired on nodes (§14). Structural — never interferes with lifecycle. */\n readonly transitions: readonly InspectedTransition[];\n /** Compilation diagnostics (§8). */\n readonly diagnostics: DiagnosticsPanel;\n readonly router?: RouterInspection;\n readonly resources?: Readonly<Record<string, ResourceInspection>>;\n readonly forms?: Readonly<Record<string, FormInspection>>;\n readonly contexts?: Readonly<Record<string, ContextInspection>>;\n readonly i18n?: I18nInspection;\n}\n\n// ── Live sources ──────────────────────────────────────────────────────────\n\n/**\n * The app's own live reactive objects, handed to DevTools explicitly so it can\n * inspect them. The compiled graph knows signal *ids* but not the live `Signal`\n * instances, so the app registers whichever surfaces it wants visible. Every\n * field is optional — a session works with none of them (structure-only).\n */\nexport interface DevToolsSources {\n /** Live signals to inspect, keyed by a human label shown in the panel. */\n readonly signals?: Readonly<Record<string, ReadonlySignal<unknown>>>;\n /** Live resources to inspect, keyed by label. */\n readonly resources?: Readonly<Record<string, ResourceLike>>;\n /** The app router, if any. */\n readonly router?: RouterLike;\n /** Live forms to inspect, keyed by label. */\n readonly forms?: Readonly<Record<string, FormLike>>;\n /** Live contexts to inspect, keyed by label. */\n readonly contexts?: Readonly<Record<string, ContextLike>>;\n /** The app i18n instance, if any. */\n readonly i18n?: I18nLike;\n}\n\nexport interface DevToolsOptions {\n /** Thresholds forwarded to `diagnosePerformance`. */\n readonly perfThresholds?: PerfThresholds;\n /**\n * Redact live signal values by default (passed to `inspectSignal`). Use in\n * shared or recorded sessions so values never reach the panel. Off by default.\n */\n readonly redactSignals?: boolean | ((value: unknown) => unknown);\n /** i18n keys to probe for missing translations, forwarded to `inspectI18n`. */\n readonly i18nCheckKeys?: readonly string[];\n}\n\n// ── Session ─────────────────────────────────────────────────────────────────\n\n/**\n * A headless DevTools session over one compiled application.\n *\n * The session holds the compiled app plus the app's registered live sources and\n * produces an immutable {@link DevToolsSnapshot} on demand. Live values are read\n * only when `refresh()` is called (explicit-refresh protocol, §7): the session\n * never subscribes to signals or instruments the reactive graph, so it adds no\n * cost to the running app between refreshes.\n */\nexport interface DevToolsSession {\n /** The most recent snapshot. Recomputed by `refresh()`. */\n readonly snapshot: DevToolsSnapshot;\n /**\n * Recompute every panel from the current live state and return the new\n * snapshot. This is the only way values change — DevTools pulls, it never\n * gets pushed to.\n */\n refresh(): DevToolsSnapshot;\n /**\n * Find a node in the graph by id and return that subtree, or `undefined`.\n * Backs a UI tree inspector's node-selection (§8) without a second graph.\n */\n selectNode(id: string): InspectedNode | undefined;\n /** Render the current snapshot as a plain-text report (for CLI/tests/logs). */\n format(): string;\n}\n\n/**\n * Create a DevTools session. Nothing in the runtime calls this — a session only\n * exists once dev code opts in, so production never pays for it.\n */\nexport function createDevTools(\n compiled: CompiledApplication,\n sources: DevToolsSources = {},\n options: DevToolsOptions = {},\n): DevToolsSession {\n let current = capture(compiled, sources, options);\n\n return {\n get snapshot() {\n return current;\n },\n refresh() {\n current = capture(compiled, sources, options);\n return current;\n },\n selectNode(id: string) {\n return findNode(current.graph, id);\n },\n format() {\n return formatSnapshot(current);\n },\n };\n}\n\n// ── Capture ───────────────────────────────────────────────────────────────\n\nfunction capture(\n compiled: CompiledApplication,\n sources: DevToolsSources,\n options: DevToolsOptions,\n): DevToolsSnapshot {\n const app: ApplicationInspection = inspectApplication(compiled);\n\n const application: ApplicationPanel = {\n identity: app.identity,\n nodeCount: app.perf.totalNodes,\n maxDepth: app.perf.maxDepth,\n pages: app.pages,\n signalCount: app.signals.length,\n eventHandlers: app.perf.eventHandlers,\n stateBindings: app.perf.stateBindings,\n errors: app.diagnostics.errors,\n warnings: app.diagnostics.warnings,\n };\n\n const live: Record<string, SignalInspection> = {};\n if (sources.signals !== undefined) {\n for (const [label, sig] of Object.entries(sources.signals)) {\n live[label] = inspectSignal(\n sig,\n options.redactSignals !== undefined ? { redact: options.redactSignals } : {},\n );\n }\n }\n const signals: SignalsPanel = { boundSignalIds: app.signals, live };\n\n const performance: PerformancePanel = {\n snapshot: app.perf,\n diagnostics: diagnosePerformance(compiled, options.perfThresholds),\n };\n\n // Component tree (§9) + interaction wiring (§13/§14) read structurally from\n // the one graph — no second graph, no subscriptions, nothing retained.\n const components = inspectComponents(compiled.graph);\n const interactions = inspectInteractions(compiled.graph);\n\n const diagnostics: DiagnosticsPanel = {\n errors: app.diagnostics.errors,\n warnings: app.diagnostics.warnings,\n messages: app.diagnostics.messages,\n };\n\n const snapshot: DevToolsSnapshot = {\n application,\n graph: app.graph,\n signals,\n performance,\n components,\n overlays: interactions.overlays,\n transitions: interactions.transitions,\n diagnostics,\n ...(sources.router !== undefined ? { router: inspectRouter(sources.router) } : {}),\n ...(sources.resources !== undefined\n ? { resources: mapInspect(sources.resources, (r) => inspectResource(r)) }\n : {}),\n ...(sources.forms !== undefined\n ? { forms: mapInspect(sources.forms, (f) => inspectForm(f)) }\n : {}),\n ...(sources.contexts !== undefined\n ? { contexts: mapInspect(sources.contexts, (c) => inspectContext(c)) }\n : {}),\n ...(sources.i18n !== undefined\n ? {\n i18n: inspectI18n(\n sources.i18n,\n options.i18nCheckKeys !== undefined ? { checkKeys: options.i18nCheckKeys } : {},\n ),\n }\n : {}),\n };\n return snapshot;\n}\n\nfunction mapInspect<T, R>(\n source: Readonly<Record<string, T>>,\n inspect: (value: T) => R,\n): Record<string, R> {\n const out: Record<string, R> = {};\n for (const [label, value] of Object.entries(source)) out[label] = inspect(value);\n return out;\n}\n\n// ── Graph node lookup (§8) ──────────────────────────────────────────────────\n\nfunction findNode(node: InspectedNode, id: string): InspectedNode | undefined {\n if (node.id === id) return node;\n for (const child of node.children) {\n const found = findNode(child, id);\n if (found !== undefined) return found;\n }\n return undefined;\n}\n\n// ── Text formatter ────────────────────────────────────────────────────────\n\nfunction formatSnapshot(s: DevToolsSnapshot): string {\n const lines: string[] = [];\n const app = s.application;\n lines.push(`StreetUI DevTools — ${app.identity.name} v${app.identity.version}`);\n lines.push(\n `Application: ${app.nodeCount} nodes, depth ${app.maxDepth}, ${app.pages.length} page(s)`,\n );\n lines.push(\n ` signals ${app.signalCount} · handlers ${app.eventHandlers} · bindings ${app.stateBindings} · errors ${app.errors} · warnings ${app.warnings}`,\n );\n\n lines.push(`Signals: ${s.signals.boundSignalIds.length} bound in graph`);\n for (const [label, sig] of Object.entries(s.signals.live)) {\n lines.push(` ${label} [${sig.kind}] = ${format(sig.value)} · observers ${sig.observerCount ?? '?'}`);\n }\n\n if (s.components.length > 0) {\n lines.push(`Components: ${s.components.length}`);\n for (const c of s.components) {\n lines.push(` ${' '.repeat(c.depth)}${c.name}${c.key !== undefined ? ` (#${c.key})` : ''} · children ${c.childCount}`);\n }\n }\n\n if (s.overlays.length > 0) {\n lines.push(`Overlays: ${s.overlays.length}`);\n for (const o of s.overlays) {\n const kind = o.modal ? 'modal' : o.menu ? 'menu' : o.takesFocus ? 'focusable' : 'non-modal';\n lines.push(` ${o.key ?? o.id} [${kind}] ${o.open ? 'open' : 'closed'}`);\n }\n }\n\n if (s.transitions.length > 0) {\n lines.push(`Transitions: ${s.transitions.length}`);\n for (const t of s.transitions) {\n lines.push(` ${t.key ?? t.id} on <${t.nodeType}> · ${t.duration}ms${t.appear ? ' · appear' : ''}`);\n }\n }\n\n if (s.router !== undefined) {\n lines.push(`Router: ${s.router.path} (${s.router.pattern})${s.router.isFallback ? ' [fallback]' : ''}`);\n }\n\n if (s.resources !== undefined) {\n lines.push('Resources:');\n for (const [label, r] of Object.entries(s.resources)) {\n lines.push(` ${label}: ${r.status}${r.loading ? ' (loading)' : ''}${r.hasError ? ` !${r.errorName}` : ''}`);\n }\n }\n\n if (s.forms !== undefined) {\n lines.push('Forms:');\n for (const [label, f] of Object.entries(s.forms)) {\n lines.push(` ${label}: ${f.valid ? 'valid' : 'invalid'} · ${f.status} · fields ${f.fields.length}`);\n }\n }\n\n if (s.contexts !== undefined) {\n lines.push('Contexts:');\n for (const [label, c] of Object.entries(s.contexts)) {\n lines.push(` ${label} (${c.description}): ${c.hasProvider ? 'provided' : 'no provider'}`);\n }\n }\n\n if (s.i18n !== undefined) {\n const missing = s.i18n.missingKeys;\n lines.push(\n `i18n: ${s.i18n.locale} of [${s.i18n.locales.join(', ')}]${missing !== undefined ? ` · missing ${missing.length}` : ''}`,\n );\n }\n\n lines.push(\n `Performance: ${s.performance.diagnostics.length} diagnostic(s), ${s.performance.snapshot.totalNodes} nodes`,\n );\n for (const d of s.performance.diagnostics) {\n lines.push(` ${d.code}: ${d.message}`);\n }\n\n lines.push(\n `Diagnostics: ${s.diagnostics.errors} error(s), ${s.diagnostics.warnings} warning(s)`,\n );\n for (const m of s.diagnostics.messages) {\n lines.push(` ${m}`);\n }\n\n return lines.join('\\n');\n}\n\nfunction format(value: unknown): string {\n if (typeof value === 'string') return JSON.stringify(value);\n if (value === null || value === undefined) return String(value);\n if (typeof value === 'object') {\n try {\n return JSON.stringify(value);\n } catch {\n return '[object]';\n }\n }\n return String(value);\n}\n","/**\n * DevTools view (2.0 §8) — a DOM-free HTML renderer for a {@link DevToolsSnapshot}.\n *\n * This is the \"initial UI\" layer: it turns the headless snapshot (already\n * composed from the existing read-only inspectors) into a single self-contained\n * HTML string a host can inject into a panel, an iframe, or a static report. It\n * is deliberately a *pure string builder*:\n *\n * - No DOM API is touched and nothing is mounted, so it runs anywhere (Node,\n * a worker, a test) and adds nothing to the running app.\n * - It reads ONLY the snapshot — no second graph, no reactive subscriptions,\n * no retained resource/DOM references.\n * - Every dynamic value is HTML-escaped, so an app's data (signal values that\n * the caller chose to expose, route paths, form labels) can never break out\n * of the markup.\n *\n * HONEST SCOPE: this produces markup. Whether it *renders* correctly in a real\n * browser, is accessible to a screen reader, or performs at 60fps is NOT claimed\n * here and has NOT been verified — no browser/AT is available in this\n * environment (the §24 browser gate remains BLOCKED). The value proven by tests\n * is that the string faithfully and safely reflects the snapshot.\n *\n * EFFECTS (§8): StreetUI keeps no global registry of effects (that would require\n * instrumenting the reactive runtime, which DevTools deliberately does not do).\n * The closest safe signal is each live signal's `observerCount` — the number of\n * effects/derivations currently depending on it — which the Signals section\n * shows. The view labels this honestly rather than inventing an effect list.\n */\n\nimport type { DevToolsSnapshot } from './panels.js';\n\n/** Escape a string for safe interpolation into HTML text/attribute content. */\nexport function escapeHtml(value: unknown): string {\n const s = typeof value === 'string' ? value : stringifyValue(value);\n return s\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&#39;');\n}\n\nfunction stringifyValue(value: unknown): string {\n if (value === null || value === undefined) return String(value);\n if (typeof value === 'object') {\n try {\n return JSON.stringify(value);\n } catch {\n return '[object]';\n }\n }\n return String(value);\n}\n\nfunction section(title: string, count: number | undefined, body: string): string {\n const badge = count === undefined ? '' : ` <span class=\"st-count\">${count}</span>`;\n return `<section class=\"st-panel\"><h2>${escapeHtml(title)}${badge}</h2>${body}</section>`;\n}\n\nfunction ul(items: readonly string[]): string {\n if (items.length === 0) return '<p class=\"st-empty\">(none)</p>';\n return `<ul>${items.map((i) => `<li>${i}</li>`).join('')}</ul>`;\n}\n\n/**\n * Render a snapshot to a complete, self-contained HTML document string. The\n * markup is static; call `renderDevToolsHTML(session.refresh())` again to\n * reflect new state (DevTools pulls — it is never pushed to).\n */\nexport function renderDevToolsHTML(s: DevToolsSnapshot): string {\n const app = s.application;\n const parts: string[] = [];\n\n parts.push(\n section(\n 'Application',\n undefined,\n `<p>${escapeHtml(app.identity.name)} <span class=\"st-dim\">v${escapeHtml(app.identity.version)}</span></p>` +\n `<p class=\"st-dim\">${app.nodeCount} nodes · depth ${app.maxDepth} · ${app.pages.length} page(s) · ` +\n `${app.signalCount} signals · ${app.eventHandlers} handlers · ${app.stateBindings} bindings</p>`,\n ),\n );\n\n // Component tree (§9).\n parts.push(\n section(\n 'Components',\n s.components.length,\n ul(\n s.components.map(\n (c) =>\n `<span class=\"st-depth\" style=\"--d:${c.depth}\"></span>` +\n `<code>${escapeHtml(c.name)}</code>` +\n (c.key !== undefined ? ` <span class=\"st-key\">#${escapeHtml(c.key)}</span>` : '') +\n ` <span class=\"st-dim\">${c.childCount} child(ren)</span>`,\n ),\n ),\n ),\n );\n\n // Graph / DOM association (§8): the node tree the components/elements map to.\n parts.push(section('Graph', undefined, `<pre class=\"st-tree\">${escapeHtml(renderNodeTree(s.graph))}</pre>`));\n\n // Signals + effects-as-observers (§10 / §8-effects).\n parts.push(\n section(\n 'Signals',\n s.signals.boundSignalIds.length,\n `<p class=\"st-dim\">${s.signals.boundSignalIds.length} bound in graph · ` +\n `effects shown as observer counts (no global effect registry)</p>` +\n ul(\n Object.entries(s.signals.live).map(\n ([label, sig]) =>\n `<code>${escapeHtml(label)}</code> <span class=\"st-key\">[${escapeHtml(sig.kind)}]</span>` +\n ` = <code>${escapeHtml(sig.value)}</code>` +\n ` <span class=\"st-dim\">observers ${escapeHtml(sig.observerCount ?? '?')}</span>`,\n ),\n ),\n ),\n );\n\n // Router (§11).\n if (s.router !== undefined) {\n parts.push(\n section(\n 'Router',\n undefined,\n `<p><code>${escapeHtml(s.router.path)}</code> <span class=\"st-dim\">(${escapeHtml(s.router.pattern)})` +\n `${s.router.isFallback ? ' · fallback' : ''}</span></p>`,\n ),\n );\n }\n\n // Resources (§12) — status only; no payloads retained.\n if (s.resources !== undefined) {\n parts.push(\n section(\n 'Resources',\n Object.keys(s.resources).length,\n ul(\n Object.entries(s.resources).map(\n ([label, r]) =>\n `<code>${escapeHtml(label)}</code>: ${escapeHtml(r.status)}` +\n (r.loading ? ' <span class=\"st-dim\">(loading)</span>' : '') +\n (r.hasError ? ` <span class=\"st-err\">!${escapeHtml(r.errorName)}</span>` : ''),\n ),\n ),\n ),\n );\n }\n\n // Overlays (§13) — in containment/graph order.\n parts.push(\n section(\n 'Overlays',\n s.overlays.length,\n ul(\n s.overlays.map((o) => {\n const kind = o.modal ? 'modal' : o.menu ? 'menu' : o.takesFocus ? 'focusable' : 'non-modal';\n return (\n `<code>${escapeHtml(o.key ?? o.id)}</code> <span class=\"st-key\">[${kind}]</span> ` +\n `<span class=\"st-dim\">${o.open ? 'open' : 'closed'}` +\n `${o.closeOnEscape ? ' · esc' : ''}${o.restoreFocus ? ' · restore' : ''}</span>`\n );\n }),\n ),\n ),\n );\n\n // Transitions (§14) — structural, never interfering.\n parts.push(\n section(\n 'Transitions',\n s.transitions.length,\n ul(\n s.transitions.map(\n (t) =>\n `<code>${escapeHtml(t.key ?? t.id)}</code> on <code>&lt;${escapeHtml(t.nodeType)}&gt;</code> ` +\n `<span class=\"st-dim\">${t.duration}ms${t.appear ? ' · appear' : ''}</span>`,\n ),\n ),\n ),\n );\n\n // Forms + i18n, when present.\n if (s.forms !== undefined) {\n parts.push(\n section(\n 'Forms',\n Object.keys(s.forms).length,\n ul(\n Object.entries(s.forms).map(\n ([label, f]) =>\n `<code>${escapeHtml(label)}</code>: ${f.valid ? 'valid' : 'invalid'} · ${escapeHtml(f.status)} · ${f.fields.length} field(s)`,\n ),\n ),\n ),\n );\n }\n if (s.i18n !== undefined) {\n const missing = s.i18n.missingKeys;\n parts.push(\n section(\n 'i18n',\n undefined,\n `<p><code>${escapeHtml(s.i18n.locale)}</code> of [${s.i18n.locales.map(escapeHtml).join(', ')}]` +\n `${missing !== undefined ? ` <span class=\"st-dim\">· missing ${missing.length}</span>` : ''}</p>`,\n ),\n );\n }\n\n // Performance (§15) — labelled NOT a production profiler.\n parts.push(\n section(\n 'Performance',\n s.performance.diagnostics.length,\n `<p class=\"st-dim\">Structural counts, not runtime timings — not a production profiler.</p>` +\n ul(s.performance.diagnostics.map((d) => `<code>${escapeHtml(d.code)}</code>: ${escapeHtml(d.message)}`)),\n ),\n );\n\n // Diagnostics (§8).\n parts.push(\n section(\n 'Diagnostics',\n s.diagnostics.errors + s.diagnostics.warnings,\n `<p class=\"st-dim\">${s.diagnostics.errors} error(s) · ${s.diagnostics.warnings} warning(s)</p>` +\n ul(s.diagnostics.messages.map((m) => escapeHtml(m))),\n ),\n );\n\n const title = `StreetUI DevTools — ${escapeHtml(app.identity.name)}`;\n return (\n `<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\">` +\n `<title>${title}</title><style>${DEVTOOLS_CSS}</style></head>` +\n `<body class=\"st-devtools\"><header class=\"st-header\"><h1>${title} ` +\n `<span class=\"st-dim\">v${escapeHtml(app.identity.version)}</span></h1></header>` +\n `<main>${parts.join('')}</main></body></html>`\n );\n}\n\n/** Indented plain-text tree of the inspected graph (id, type, key). */\nfunction renderNodeTree(node: DevToolsSnapshot['graph']): string {\n const lines: string[] = [];\n const walk = (n: DevToolsSnapshot['graph']): void => {\n const indent = ' '.repeat(n.depth);\n const key = n.key !== undefined ? ` #${n.key}` : '';\n lines.push(`${indent}<${n.type}${key}> ${n.id}`);\n for (const c of n.children) walk(c);\n };\n walk(node);\n return lines.join('\\n');\n}\n\n/** Minimal, self-contained styling for the view. Inlined so there is no asset. */\nconst DEVTOOLS_CSS = [\n '.st-devtools{font:13px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;margin:0;color:#e6e6e6;background:#1e1e28}',\n '.st-header{padding:12px 16px;border-bottom:1px solid #333;background:#15151c}',\n '.st-header h1{font-size:14px;margin:0}',\n 'main{padding:8px 16px}',\n '.st-panel{margin:12px 0;border:1px solid #2c2c38;border-radius:6px;overflow:hidden}',\n '.st-panel h2{font-size:12px;text-transform:uppercase;letter-spacing:.04em;margin:0;padding:6px 10px;background:#23232e}',\n '.st-panel ul{list-style:none;margin:0;padding:6px 10px}',\n '.st-panel li{padding:1px 0}',\n '.st-panel p{margin:6px 10px}',\n '.st-count{background:#3a3a4a;border-radius:10px;padding:0 7px;font-size:11px;float:right}',\n '.st-dim{color:#8a8a9a}.st-key{color:#7db4ff}.st-err{color:#ff8a8a}.st-empty{color:#6a6a7a}',\n '.st-tree{margin:6px 10px;white-space:pre;overflow:auto;color:#c8c8d4}',\n '.st-depth{display:inline-block}.st-depth{width:calc(var(--d,0)*12px)}',\n 'code{color:#d7d7e0}',\n].join('');\n","/**\n * DevTools report (2.1 §23) — the first *usable* DevTools interface: one call\n * that turns a compiled application into a complete, self-contained HTML page a\n * developer can open in a browser (or save as a static report / inject into a\n * panel or iframe).\n *\n * It is a thin, additive convenience over the pieces that already shipped in\n * 2.0 — it composes them, it adds no new capability:\n *\n * renderDevToolsReport(compiled) ≡ renderDevToolsHTML(createDevTools(compiled).snapshot)\n *\n * Properties inherited from those pieces (nothing new is introduced):\n * - DOM-free: pure string building; touches no DOM API and mounts nothing, so\n * it runs in Node, a worker, or a test.\n * - Non-mutating & non-instrumenting: reads only the compiled app plus any\n * live sources the caller passes; never subscribes to signals, never patches\n * the reactive runtime. DevTools pulls — it is never pushed to.\n * - Zero production cost: nothing in the runtime imports this; the interface\n * exists only once dev code opts in by calling it.\n *\n * HONEST SCOPE (unchanged from the view layer): this produces markup. Whether it\n * renders pixel-correctly, is screen-reader accessible, or hits 60fps in a real\n * browser is NOT claimed and has NOT been verified here — the browser/AT gates\n * are BLOCKED (no Chromium/AT in this environment). What is verified is that the\n * emitted document faithfully and safely (HTML-escaped) reflects the snapshot.\n */\n\nimport type { CompiledApplication } from '@streetui/compiler';\nimport { createDevTools, type DevToolsSources, type DevToolsOptions } from './panels.js';\nimport { renderDevToolsHTML } from './view.js';\n\n/**\n * Build a complete, self-contained DevTools HTML document for a compiled app in\n * one call. Equivalent to rendering `createDevTools(compiled, sources, options)`'s\n * current snapshot; call again to reflect new state (DevTools pulls).\n */\nexport function renderDevToolsReport(\n compiled: CompiledApplication,\n sources: DevToolsSources = {},\n options: DevToolsOptions = {},\n): string {\n const session = createDevTools(compiled, sources, options);\n return renderDevToolsHTML(session.snapshot);\n}\n","/**\n * Project-configuration surface for `streetui.config.ts`.\n *\n * The configuration *type* is single-sourced from the internal CLI module (so\n * there is exactly one authoritative `StreetUIConfig` shape). `defineConfig` is\n * the standard one-line identity helper used purely for editor type-inference on\n * the exported config object.\n *\n * This lives in its own tiny module — rather than re-exporting `defineConfig`\n * from the CLI barrel — so that importing `streetui` for application code does\n * **not** drag the CLI's build machinery (and its `esbuild` dependency) into the\n * client runtime bundle. The CLI's own `loadConfig` reads the default export of\n * `streetui.config.ts` regardless of which identity helper wrapped it, so the\n * behaviour is identical to configuring via the CLI directly.\n */\nimport type { StreetUIConfig } from '@streetui/cli';\n\nexport type { StreetUIConfig, ResolvedConfig } from '@streetui/cli';\n\n/** Identity helper that gives `streetui.config.ts` full type-checking + inference. */\nexport function defineConfig(config: StreetUIConfig): StreetUIConfig {\n return config;\n}\n"],"mappings":";AASO,IAAM,UAAU;;;AC6BvB,IAAI,kBAA2C;AAE/C,SAAS,aAAgB,UAA4B,IAAgB;AACnE,QAAM,OAAO;AACb,oBAAkB;AAClB,MAAI;AACF,WAAO,GAAG;AAAA,EACZ,UAAE;AACA,sBAAkB;AAAA,EACpB;AACF;AAKA,IAAI,cAAc;AAWlB,IAAM,kBAAkB,oBAAI,IAAmC;AAE/D,SAAS,mBAAmB,KAAsB,OAAsB;AACtE,kBAAgB,IAAI,KAAK,EAAE,QAAQ,KAAK,MAAM,CAAC;AACjD;AAEA,SAAS,cAAoB;AAC3B,QAAM,UAAU,CAAC,GAAG,gBAAgB,OAAO,CAAC;AAC5C,kBAAgB,MAAM;AACtB,aAAW,EAAE,QAAQ,KAAK,MAAM,KAAK,SAAS;AAC5C,QAAI,YAAY,KAAK;AAAA,EACvB;AACF;AAUO,IAAM,SAAN,MAAgE;AAAA,EAC3D;AAA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