@bgub/fig-dom 0.1.0-alpha.0 → 0.1.0-alpha.2

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,"file":"index.js","names":["unsafeHTMLValue"],"sources":["../src/tree.ts","../src/bind.ts","../src/events.ts","../src/attachment.ts","../src/props.ts","../src/asset-resources.ts","../src/suspense-markers.ts","../src/view-transition.ts","../src/index.ts"],"sourcesContent":["export const htmlNamespace = \"http://www.w3.org/1999/xhtml\";\nexport const mathNamespace = \"http://www.w3.org/1998/Math/MathML\";\nexport const svgNamespace = \"http://www.w3.org/2000/svg\";\n\nexport function visitElementSubtree(\n node: Element | Text,\n visitor: (element: Element) => void,\n): void {\n if (isElementNode(node)) visitor(node);\n if (!(\"childNodes\" in node) || node.firstChild === null) return;\n\n for (const child of Array.from(node.childNodes)) {\n visitElementSubtree(child as Element | Text, visitor);\n }\n}\n\nexport function isElementNode(node: unknown): node is Element {\n return (\n typeof node === \"object\" &&\n node !== null &&\n \"nodeType\" in node &&\n node.nodeType === 1\n );\n}\n\nexport function elementName(node: unknown): string {\n if (!isElementNode(node)) return \"\";\n\n return \"localName\" in node && typeof node.localName === \"string\"\n ? node.localName.toLowerCase()\n : \"tagName\" in node && typeof node.tagName === \"string\"\n ? node.tagName.toLowerCase()\n : \"\";\n}\n\nexport function isHtmlElement(element: Element): boolean {\n return (\n !(\"namespaceURI\" in element) ||\n element.namespaceURI === null ||\n element.namespaceURI === htmlNamespace\n );\n}\n\n// Known limitation: the walk follows parentNode only and never hops shadow\n// boundaries (a ShadowRoot's parentNode is null, and there is no `.host`\n// fallback). Fig content rendered inside shadow trees is out of scope for\n// root resolution, delegated dispatch, and replay targeting; register the\n// in-shadow container as a portal target to route events explicitly.\nexport function parentOf(node: unknown): unknown {\n return typeof node === \"object\" && node !== null && \"parentNode\" in node\n ? node.parentNode\n : null;\n}\n\n// The shared \"absent prop\" predicate: null, undefined, and false all mean\n// \"not provided\" for prop-shaped values (bind, events, unsafeHTML,\n// attributes) — one authority so the prop kinds cannot drift.\nexport function isEmptyPropValue(value: unknown): boolean {\n return value === null || value === undefined || value === false;\n}\n","import { isEmptyPropValue } from \"./tree.ts\";\n\ndeclare const __FIG_DEV__: boolean | undefined;\n\nconst __DEV__ = typeof __FIG_DEV__ === \"boolean\" ? __FIG_DEV__ : false;\n\nexport type Bind<T extends Element = Element> = (\n node: T,\n signal: AbortSignal,\n) => void;\n\ninterface BindSlot {\n callback: Bind;\n controller: AbortController | null;\n // Persists for the slot's lifetime; gates the dev-only strict re-run to\n // the first attach so callback changes and re-attachments run single.\n strictRan: boolean;\n}\n\nconst bindSlots = new WeakMap<Element, BindSlot>();\n// Elements inside hidden Activity trees: binds must not run while hidden.\n// Keyed by element (not a slot flag) so a bind that first appears while its\n// element is already hidden is covered too.\nconst suspendedBindElements = new WeakSet<Element>();\n\nexport function composeBind<T extends Element = Element>(\n ...binds: Array<Bind<T> | false | null | undefined>\n): Bind<T> {\n const callbacks = binds.filter(\n (bind): bind is Bind<T> => typeof bind === \"function\",\n );\n\n return (node, signal) => {\n for (const bind of callbacks) bind(node, signal);\n };\n}\n\nexport function updateBind(element: Element, value: unknown): void {\n const callback = bindCallback(value);\n const slot = bindSlots.get(element);\n\n if (callback === null) {\n if (slot !== undefined) removeBindSlot(slot);\n bindSlots.delete(element);\n return;\n }\n\n if (slot === undefined) {\n const nextSlot: BindSlot = { callback, controller: null, strictRan: false };\n bindSlots.set(element, nextSlot);\n attachBindSlot(element, nextSlot);\n } else if (slot.callback !== callback) {\n removeBindSlot(slot);\n slot.callback = callback;\n attachBindSlot(element, slot);\n }\n}\n\nexport function attachElementBind(element: Element): void {\n const slot = bindSlots.get(element);\n if (slot !== undefined) attachBindSlot(element, slot);\n}\n\nexport function suspendBind(element: Element): void {\n suspendedBindElements.add(element);\n const slot = bindSlots.get(element);\n if (slot !== undefined) removeBindSlot(slot);\n}\n\nexport function resumeBind(element: Element): void {\n suspendedBindElements.delete(element);\n const slot = bindSlots.get(element);\n if (slot !== undefined) attachBindSlot(element, slot);\n}\n\nexport function detachElementBind(element: Element): void {\n const slot = bindSlots.get(element);\n if (slot !== undefined) {\n removeBindSlot(slot);\n bindSlots.delete(element);\n }\n}\n\nfunction attachBindSlot(element: Element, slot: BindSlot): void {\n if (\n slot.controller !== null ||\n element.parentNode === null ||\n suspendedBindElements.has(element)\n ) {\n return;\n }\n\n let runStrict = false;\n if (__DEV__) {\n // Marked before the callback so re-entrant attaches cannot re-enter the\n // strict cycle.\n runStrict = !slot.strictRan;\n slot.strictRan = true;\n }\n slot.controller = new AbortController();\n slot.callback(element, slot.controller.signal);\n if (__DEV__ && runStrict) {\n // Strict re-run: abort and re-invoke first-time binds so callbacks that\n // ignore their AbortSignal surface in development.\n removeBindSlot(slot);\n slot.controller = new AbortController();\n slot.callback(element, slot.controller.signal);\n }\n}\n\nfunction removeBindSlot(slot: BindSlot): void {\n slot.controller?.abort();\n slot.controller = null;\n}\n\nfunction bindCallback(value: unknown): Bind | null {\n if (isEmptyPropValue(value)) return null;\n if (typeof value === \"function\") return value as Bind;\n throw new Error(\"The bind prop must be a function.\");\n}\n","import {\n EARLY_EVENT_HANDLER_PROPERTY,\n EARLY_EVENT_QUEUE_PROPERTY,\n REPLAYABLE_EVENT_TYPES,\n} from \"@bgub/fig/internal\";\nimport {\n type EventPriority,\n type HydrationTargetResult,\n runWithEventPriority,\n} from \"@bgub/fig-reconciler\";\nimport {\n elementName,\n isElementNode,\n isEmptyPropValue,\n parentOf,\n} from \"./tree.ts\";\n\nexport type Container = Element | DocumentFragment;\nexport type EventOptions = Pick<AddEventListenerOptions, \"capture\" | \"passive\">;\nexport type EventCallback<E extends Event = Event> = (\n event: E,\n signal: AbortSignal,\n) => void;\ntype Batch = <T>(callback: () => T) => T;\ntype RootScope = <T>(callback: () => T) => T;\n\nexport interface EventDescriptor<E extends Event = Event> {\n readonly $$typeof: symbol;\n readonly type: string;\n readonly callback: EventCallback<E>;\n readonly options?: EventOptions;\n}\n\ninterface EventSlot {\n key: string;\n type: string;\n callback: EventCallback;\n options: Required<EventOptions>;\n controller: AbortController | null;\n element: Element | null;\n listener: EventListener | null;\n listenerTarget: Container | null;\n root: Container | null;\n}\ntype EventSlotList = Array<EventSlot | undefined>;\n\n// Snapshot of one handler invocation, extracted before any handler runs: a\n// re-entrant commit inside a handler may detach slots or swap callbacks\n// mid-dispatch, and listeners subscribed when the event fired must still\n// run exactly once with the fields they had at extraction.\ninterface DispatchEntry {\n callback: EventCallback;\n element: Element;\n root: Container | null;\n slot: EventSlot;\n type: string;\n}\n\n// Propagation is tracked per logical dispatch rather than on the event:\n// a queued replay must not inherit cancelBubble state a third-party\n// listener left on the spent native event.\ninterface PropagationState {\n immediateStopped: boolean;\n stopped: boolean;\n}\n\n// type/capture/passive are stored rather than re-parsed from the listener\n// key: event types may themselves contain the key separator (\":\").\ninterface RootListener {\n capture: boolean;\n count: number;\n listener: EventListener;\n passive: boolean;\n type: string;\n}\n\ninterface QueuedReplayableEvent {\n event: Event;\n // The logical dispatch origin (a portal target or the root), captured\n // while the target is still attached so replays keep portal bubbling.\n listenerTarget: Container | null;\n root: Container;\n type: string;\n}\n\ninterface PortalOwner {\n logicalParent: Container | Element;\n // The logical parent's listener target at registration time: the container\n // whose delegated keys this portal mirrors (an enclosing portal target, or\n // the root).\n parentTarget: Container;\n root: Container;\n}\n\n// One record per container that participates in event routing — a root, a\n// portal target, or both roles' delegated listener host. Keeping every\n// per-container datum here keeps registration, dispatch, and teardown\n// reading one structure.\ninterface ContainerRecord {\n hydrate: HydrationCallback | null;\n hydrationListeners: Array<readonly [string, EventListener]> | null;\n listeners: Map<string, RootListener>;\n portalOwner: PortalOwner | null;\n // Portal targets whose logical parent resolves to this container: this\n // container's delegated listener keys mirror onto them (cascading down\n // nested portals) so portal-inner events always have a dispatch point for\n // logical bubbling, even when no portal-inner handler shares the key.\n portals: Set<Container> | null;\n root: boolean;\n scope: RootScope | null;\n}\n\nconst EventDescriptorSymbol = Symbol.for(\"fig.event\");\nconst eventSlots = new WeakMap<Element, EventSlotList>();\nconst containerRecords = new WeakMap<Container, ContainerRecord>();\n// Keyed per (event, root): each root resolves selective hydration against\n// its own tree, so an outer root's \"none\" must not shadow a nested root's\n// \"blocked\". The inner WeakMap avoids retaining other roots' containers\n// while a queued replayable event keeps the native event alive.\nconst eventHydrationResults = new WeakMap<\n Event,\n WeakMap<Container, HydrationTargetResult>\n>();\nconst queuedReplayableEvents: QueuedReplayableEvent[] = [];\nconst discreteEvents = new Set([\n \"beforeinput\",\n \"blur\",\n \"change\",\n \"click\",\n \"contextmenu\",\n \"dblclick\",\n \"focus\",\n \"focusin\",\n \"focusout\",\n \"input\",\n \"keydown\",\n \"keyup\",\n \"mousedown\",\n \"mouseup\",\n \"pointerdown\",\n \"pointerup\",\n \"submit\",\n \"touchend\",\n \"touchstart\",\n]);\n// Shared with the server's inline early-event-capture script: both sides\n// must agree on which events queue for replay.\nconst replayableEvents = new Set<string>(REPLAYABLE_EVENT_TYPES);\nconst continuousEvents = new Set([\n \"drag\",\n \"dragover\",\n \"mousemove\",\n \"pointermove\",\n \"scroll\",\n \"touchmove\",\n \"wheel\",\n]);\nconst hydrationEvents = new Set([\n ...discreteEvents,\n ...continuousEvents,\n \"mouseenter\",\n \"mouseleave\",\n]);\n// Non-bubbling events attach directly to their element with native\n// semantics: a delegated bubble-phase root listener would never fire for\n// them in a real browser. focus/blur included — the platform's bubbling\n// variants are focusin/focusout, which delegate like any bubbling event, so\n// Fig does not emulate bubbling focus the way React does.\nconst nonDelegatedEvents = new Set([\n \"abort\",\n \"blur\",\n \"cancel\",\n \"canplay\",\n \"canplaythrough\",\n \"close\",\n \"durationchange\",\n \"emptied\",\n \"encrypted\",\n \"ended\",\n \"error\",\n \"focus\",\n \"invalid\",\n \"load\",\n \"loadeddata\",\n \"loadedmetadata\",\n \"loadstart\",\n \"mouseenter\",\n \"mouseleave\",\n \"pause\",\n \"play\",\n \"playing\",\n \"pointerenter\",\n \"pointerleave\",\n \"progress\",\n \"ratechange\",\n \"resize\",\n \"scroll\",\n \"scrollend\",\n \"seeked\",\n \"seeking\",\n \"stalled\",\n \"suspend\",\n \"timeupdate\",\n \"toggle\",\n \"volumechange\",\n \"waiting\",\n]);\nlet batch: Batch = (callback) => callback();\n\ntype HydrationCallback = (\n target: EventTarget | null,\n priority: EventPriority,\n) => HydrationTargetResult;\n\nexport function setEventBatching(nextBatch: Batch): void {\n batch = nextBatch;\n}\n\nexport function registerRoot(\n container: Container,\n hydrate?: HydrationCallback,\n scope?: RootScope,\n): void {\n const record = containerRecord(container);\n record.root = true;\n if (scope !== undefined) record.scope = scope;\n if (hydrate === undefined) return;\n\n record.hydrate = hydrate;\n ensureHydrationListeners(container, record);\n adoptEarlyEvents(container);\n}\n\ntype EarlyEventCarrier = Document & {\n [EARLY_EVENT_QUEUE_PROPERTY]?: Event[];\n [EARLY_EVENT_HANDLER_PROPERTY]?: EventListener;\n};\n\n// Events left over after each root claimed its own, kept per document so\n// later-hydrating roots (multiple containers on one page) still find theirs.\nconst unclaimedEarlyEvents = new WeakMap<Document, Event[]>();\n\n// The server's inline capture script queues replayable events that fired\n// before this bundle executed. Adopt them into the standard replay queue:\n// a discrete replay forces synchronous hydration of its target, so a\n// pre-bundle click on server-rendered content is honored as soon as the\n// drain microtask runs instead of being lost.\nfunction adoptEarlyEvents(root: Container): void {\n const carrier = (root.ownerDocument ?? root) as EarlyEventCarrier;\n let unclaimed = unclaimedEarlyEvents.get(carrier);\n\n if (unclaimed === undefined) {\n const queue = carrier[EARLY_EVENT_QUEUE_PROPERTY];\n if (!Array.isArray(queue)) return;\n\n const handler = carrier[EARLY_EVENT_HANDLER_PROPERTY];\n if (\n typeof handler === \"function\" &&\n typeof carrier.removeEventListener === \"function\"\n ) {\n for (const type of REPLAYABLE_EVENT_TYPES) {\n carrier.removeEventListener(type, handler, true);\n }\n }\n delete carrier[EARLY_EVENT_QUEUE_PROPERTY];\n delete carrier[EARLY_EVENT_HANDLER_PROPERTY];\n\n unclaimed = queue;\n unclaimedEarlyEvents.set(carrier, unclaimed);\n }\n\n let claimed = false;\n for (let index = 0; index < unclaimed.length;) {\n const event = unclaimed[index];\n if (\n replayableEvents.has(event.type) &&\n targetWithinRoot(root, event.target)\n ) {\n unclaimed.splice(index, 1);\n queueReplayableEvent(root, event.type, event);\n claimed = true;\n continue;\n }\n index += 1;\n }\n\n if (claimed) queueMicrotask(replayQueuedEvents);\n}\n\nexport function unregisterRoot(container: Container): void {\n const record = containerRecords.get(container);\n if (record === undefined) return;\n\n disableRootHydration(container);\n\n // Slot teardown normally empties this map before unmount finishes; sweep\n // whatever remains so no delegated listener outlives the root.\n for (const rootListener of record.listeners.values()) {\n container.removeEventListener(rootListener.type, rootListener.listener, {\n capture: rootListener.capture,\n });\n }\n\n // Portal teardown normally clears these during unmount; sweep stragglers\n // (nested portals hang off their parent target's record, so recurse).\n sweepPortals(container);\n\n containerRecords.delete(container);\n\n for (let index = queuedReplayableEvents.length - 1; index >= 0; index -= 1) {\n if (queuedReplayableEvents[index].root === container) {\n queuedReplayableEvents.splice(index, 1);\n }\n }\n}\n\nexport function disableRootHydration(container: Container): void {\n const record = containerRecords.get(container);\n if (record === undefined) return;\n\n record.hydrate = null;\n for (const [type, listener] of record.hydrationListeners ?? []) {\n container.removeEventListener(type, listener, { capture: true });\n }\n record.hydrationListeners = null;\n}\n\nfunction sweepPortals(target: Container): void {\n for (const portal of containerRecords.get(target)?.portals ?? []) {\n sweepPortals(portal);\n removePortalContainer(portal);\n }\n}\n\nfunction containerRecord(container: Container): ContainerRecord {\n let record = containerRecords.get(container);\n if (record === undefined) {\n record = {\n hydrate: null,\n hydrationListeners: null,\n listeners: new Map(),\n portalOwner: null,\n portals: null,\n root: false,\n scope: null,\n };\n containerRecords.set(container, record);\n }\n return record;\n}\n\n/**\n * Declares a listener for the `events` prop. Events keep their native\n * semantics: bubbling events are delegated through the Fig tree (including\n * portals), while non-bubbling events — `focus` and `blur` included — attach\n * directly to the element and fire only there. Fig does not emulate React's\n * bubbling `focus`/`blur`; to observe focus changes from an ancestor, use\n * the platform's bubbling variants, `focusin` and `focusout`.\n */\nexport function on<K extends keyof HTMLElementEventMap>(\n type: K,\n callback: EventCallback<HTMLElementEventMap[K]>,\n options?: EventOptions,\n): EventDescriptor<HTMLElementEventMap[K]>;\nexport function on<E extends Event = Event>(\n type: string,\n callback: EventCallback<E>,\n options?: EventOptions,\n): EventDescriptor<E>;\nexport function on(\n type: string,\n callback: EventCallback,\n options?: EventOptions,\n): EventDescriptor {\n return { $$typeof: EventDescriptorSymbol, type, callback, options };\n}\n\nexport function updateEvents(element: Element, value: unknown): void {\n const slots = eventSlotsFor(element);\n const descriptors = eventDescriptors(value, elementName(element));\n let location: EventLocation | null = null;\n\n for (let index = 0; index < descriptors.length; index += 1) {\n const descriptor = descriptors[index];\n if (descriptor === undefined) {\n const slot = slots[index];\n if (slot !== undefined) {\n removeEventSlot(slot);\n slots[index] = undefined;\n }\n continue;\n }\n\n const options = normalizedOptions(descriptor.options);\n const key = eventKey(descriptor.type, options);\n const slot = slots[index];\n\n if (slot === undefined) {\n location ??= eventLocationFor(element);\n slots[index] = addEventSlot(\n element,\n location.root,\n location.listenerTarget,\n descriptor,\n options,\n key,\n );\n } else if (slot.key !== key) {\n location ??= eventLocationFor(element);\n removeEventSlot(slot);\n slots[index] = addEventSlot(\n element,\n location.root,\n location.listenerTarget,\n descriptor,\n options,\n key,\n );\n } else if (slot.callback !== descriptor.callback) {\n slot.callback = descriptor.callback as EventCallback;\n }\n }\n\n for (let index = slots.length - 1; index >= descriptors.length; index -= 1) {\n const slot = slots[index];\n if (slot !== undefined) removeEventSlot(slot);\n }\n\n slots.length = descriptors.length;\n}\n\nexport function attachElementEvents(element: Element): void {\n const root = rootFor(element);\n const listenerTarget = listenerTargetFor(element);\n\n for (const slot of eventSlots.get(element) ?? []) {\n if (slot === undefined) continue;\n attachEventSlot(element, root, listenerTarget, slot);\n }\n}\n\nexport function detachElementEvents(element: Element): void {\n for (const slot of eventSlots.get(element) ?? []) {\n if (slot !== undefined) removeEventSlot(slot);\n }\n eventSlots.delete(element);\n}\n\n// Derived from listenerTargetFor so the two walks cannot disagree about\n// which container a node belongs to: the dispatch origin is the nearest\n// registered container, and its root is itself or its portal owner's root.\nexport function rootFor(\n node: Element | Text | Comment | Container,\n): Container | null {\n return eventLocationFor(node).root;\n}\n\ninterface EventLocation {\n listenerTarget: Container | null;\n root: Container | null;\n}\n\nfunction eventLocationFor(\n node: Element | Text | Comment | Container,\n): EventLocation {\n const listenerTarget = listenerTargetFor(node);\n if (listenerTarget === null) return { listenerTarget: null, root: null };\n\n const record = containerRecords.get(listenerTarget);\n return {\n listenerTarget,\n root:\n record?.portalOwner?.root ??\n (record?.root === true ? listenerTarget : null),\n };\n}\n\nexport function registerPortalContainer(\n container: Container,\n root: Container,\n logicalParent: Container | Element,\n): void {\n const record = containerRecord(container);\n const parentTarget = listenerTargetFor(logicalParent) ?? root;\n\n if (record.portalOwner !== null) {\n // Re-registration on a later commit: refresh the logical position; the\n // mirrors are already in place while the parent target is unchanged.\n if (\n record.portalOwner.root === root &&\n record.portalOwner.parentTarget === parentTarget\n ) {\n record.portalOwner = { logicalParent, parentTarget, root };\n return;\n }\n removePortalContainer(container);\n }\n\n record.portalOwner = {\n logicalParent,\n parentTarget,\n root,\n };\n\n const parentRecord = containerRecord(parentTarget);\n (parentRecord.portals ??= new Set()).add(container);\n // Mirror the logical parent target's active delegated keys (which already\n // include its own ancestors' mirrors) so events inside the portal have a\n // dispatch point for every handler along the logical ancestor chain.\n for (const mirrored of parentRecord.listeners.values()) {\n acquireRootListener(\n root,\n container,\n mirrored.type,\n mirrored.capture,\n mirrored.passive,\n );\n }\n}\n\nexport function removePortalContainer(container: Container): void {\n const record = containerRecords.get(container);\n const owner = record?.portalOwner ?? null;\n if (record === undefined || owner === null) return;\n\n record.portalOwner = null;\n\n const parentRecord = containerRecords.get(owner.parentTarget);\n if (parentRecord === undefined) return;\n parentRecord.portals?.delete(container);\n for (const key of parentRecord.listeners.keys()) {\n releaseRootListener(container, key);\n }\n}\n\nexport function replayQueuedEvents(): void {\n // Replays preserve the user's input order per root: a still-blocked entry\n // stalls later entries of ITS root only, so an independent root's\n // never-completing boundary cannot head-of-line block everyone else.\n const stalledRoots = new Set<Container>();\n\n for (let index = 0; index < queuedReplayableEvents.length;) {\n const queued = queuedReplayableEvents[index];\n\n // Liveness is checked against the logical dispatch origin: a portal\n // target lives outside the root container's DOM.\n const anchor = queued.listenerTarget ?? queued.root;\n if (!targetWithinRoot(anchor, queued.event.target)) {\n queuedReplayableEvents.splice(index, 1);\n continue;\n }\n\n // Attempt hydration even for stalled roots so later boundaries make\n // progress; only dispatch is withheld to keep ordering.\n if (hydrateQueuedEvent(queued) === \"blocked\") {\n stalledRoots.add(queued.root);\n index += 1;\n continue;\n }\n\n if (stalledRoots.has(queued.root)) {\n index += 1;\n continue;\n }\n\n queuedReplayableEvents.splice(index, 1);\n dispatchReplayedEvent(queued);\n }\n}\n\nfunction addEventSlot(\n element: Element,\n root: Container | null,\n listenerTarget: Container | null,\n descriptor: EventDescriptor,\n options: Required<EventOptions>,\n key: string,\n): EventSlot {\n const slot: EventSlot = {\n key,\n type: descriptor.type,\n callback: descriptor.callback as EventCallback,\n options,\n controller: null,\n element: null,\n listener: null,\n listenerTarget: null,\n root: null,\n };\n attachEventSlot(element, root, listenerTarget, slot);\n return slot;\n}\n\nfunction removeEventSlot(slot: EventSlot): void {\n detachEventSlot(slot);\n abortEventSlot(slot);\n}\n\nfunction dispatchRootEvent(\n root: Container,\n listenerTarget: Container,\n type: string,\n capture: boolean,\n passive: boolean,\n event: Event,\n): void {\n const targetListenerTarget = listenerTargetFor(event.target);\n if (targetListenerTarget !== listenerTarget) {\n const targetRecord =\n targetListenerTarget === null\n ? null\n : (containerRecords.get(targetListenerTarget) ?? null);\n if (targetRecord?.portalOwner?.root === root) return;\n if (!targetWithinRoot(listenerTarget, event.target)) return;\n }\n if (hydrateForEvent(root, type, event) === \"blocked\") return;\n\n const entries = extractDispatches(\n root,\n listenerTarget,\n type,\n capture,\n passive,\n event,\n );\n if (entries.length === 0) return;\n\n withPropagationState(event, false, (state) =>\n invokeDispatches(entries, event, state),\n );\n}\n\nfunction ensureHydrationListeners(\n root: Container,\n record: ContainerRecord,\n): void {\n if (record.hydrationListeners !== null) return;\n record.hydrationListeners = [];\n\n for (const type of hydrationEvents) {\n const listener = (event: Event) => hydrateForEvent(root, type, event);\n record.hydrationListeners.push([type, listener]);\n root.addEventListener(type, listener, {\n capture: true,\n passive: passiveHydrationEvent(type),\n });\n }\n}\n\nfunction hydrateForEvent(\n root: Container,\n type: string,\n event: Event,\n): HydrationTargetResult {\n const hydrate = containerRecords.get(root)?.hydrate ?? null;\n if (hydrate === null) return \"none\";\n\n let results = eventHydrationResults.get(event);\n const previousResult = results?.get(root);\n if (previousResult !== undefined) return previousResult;\n\n const priority = eventPriority(type);\n const result = runWithEventPriority(priority, () =>\n hydrate(event.target, priority),\n );\n if (results === undefined) {\n results = new WeakMap();\n eventHydrationResults.set(event, results);\n }\n results.set(root, result);\n\n // Queue only on the fresh computation: the capture hydration listener and\n // the delegated dispatch guard both land here for the same (event, root).\n if (result === \"blocked\" && replayableEvents.has(type)) {\n queueReplayableEvent(root, type, event);\n }\n\n return result;\n}\n\nfunction queueReplayableEvent(\n root: Container,\n type: string,\n event: Event,\n): void {\n queuedReplayableEvents.push({\n event,\n listenerTarget: listenerTargetFor(event.target),\n root,\n type,\n });\n}\n\nfunction hydrateQueuedEvent(\n queued: QueuedReplayableEvent,\n): HydrationTargetResult {\n const hydrate = containerRecords.get(queued.root)?.hydrate ?? null;\n if (hydrate === null) return \"none\";\n\n const priority = eventPriority(queued.type);\n return runWithEventPriority(priority, () =>\n hydrate(queued.event.target, priority),\n );\n}\n\n// Replays a queued event after selective hydration: the spent native event\n// no longer propagates, so one synthetic dispatch stands in for both phases\n// (`passive: null` matches every slot — no live root listener partitions\n// them by key here). The bubble phase extracts after capture handlers ran,\n// mirroring live DOM listener semantics; one propagation state spans both\n// phases, ignoring the spent event's stale cancelBubble.\nfunction dispatchReplayedEvent(queued: QueuedReplayableEvent): void {\n const { event, root, type } = queued;\n const listenerTarget = queued.listenerTarget ?? queued.root;\n\n withPropagationState(event, true, (state) => {\n invokeDispatches(\n extractDispatches(root, listenerTarget, type, true, null, event),\n event,\n state,\n );\n\n if (state.immediateStopped || state.stopped) return;\n\n invokeDispatches(\n extractDispatches(root, listenerTarget, type, false, null, event),\n event,\n state,\n );\n });\n}\n\nfunction extractDispatches(\n root: Container,\n listenerTarget: Container,\n type: string,\n capture: boolean,\n passive: boolean | null,\n event: Event,\n): DispatchEntry[] {\n const path = eventPath(root, listenerTarget, event);\n const entries: DispatchEntry[] = [];\n const step = capture ? -1 : 1;\n\n for (\n let index = capture ? path.length - 1 : 0;\n index >= 0 && index < path.length;\n index += step\n ) {\n const element = path[index];\n\n for (const slot of eventSlots.get(element) ?? []) {\n if (slot === undefined) continue;\n if (\n slot.root !== root ||\n slot.type !== type ||\n slot.options.capture !== capture ||\n (passive !== null && slot.options.passive !== passive)\n ) {\n continue;\n }\n\n entries.push({\n callback: slot.callback,\n element,\n root: slot.root,\n slot,\n type: slot.type,\n });\n }\n }\n\n return entries;\n}\n\nfunction invokeDispatches(\n entries: DispatchEntry[],\n event: Event,\n state: PropagationState,\n): void {\n let currentElement: Element | null = null;\n\n for (const entry of entries) {\n if (state.immediateStopped) return;\n\n // stopPropagation lets remaining handlers on the same element run and\n // skips every later element.\n if (entry.element !== currentElement) {\n if (currentElement !== null && state.stopped) return;\n currentElement = entry.element;\n }\n\n try {\n dispatchEventSlot(entry, event);\n } finally {\n // A slot detached mid-dispatch still ran — it was subscribed when the\n // event fired — but its signal must end aborted per the abort-on-removal\n // contract, even if the handler threw.\n const slot = entry.slot;\n if (slot.element === null && slot.listenerTarget === null) {\n abortEventSlot(slot);\n }\n }\n }\n}\n\nfunction dispatchEventSlot(entry: DispatchEntry, event: Event): void {\n const slot = entry.slot;\n abortEventSlot(slot);\n slot.controller = new AbortController();\n const signal = slot.controller.signal;\n\n batch(() => {\n runWithRootScope(entry.root, () =>\n runWithEventPriority(eventPriority(entry.type), () => {\n withCurrentTarget(event, entry.element, (currentEvent) => {\n entry.callback(currentEvent, signal);\n });\n }),\n );\n });\n}\n\nfunction runWithRootScope<T>(root: Container | null, callback: () => T): T {\n const scope =\n root === null ? null : (containerRecords.get(root)?.scope ?? null);\n return scope === null ? callback() : scope(callback);\n}\n\nfunction abortEventSlot(slot: EventSlot): void {\n slot.controller?.abort();\n slot.controller = null;\n}\n\nfunction eventDescriptors(\n value: unknown,\n elementType: string,\n): Array<EventDescriptor | undefined> {\n if (isEmptyPropValue(value)) return [];\n if (Array.isArray(value)) {\n const descriptors: Array<EventDescriptor | undefined> = [];\n for (const item of value) {\n if (isEmptyPropValue(item)) {\n descriptors.push(undefined);\n continue;\n }\n if (!isEventDescriptor(item)) {\n throwInvalidEventsProp(elementType);\n }\n descriptors.push(item);\n }\n return descriptors;\n }\n throwInvalidEventsProp(elementType);\n}\n\nfunction throwInvalidEventsProp(elementType: string): never {\n const target = elementType === \"\" ? \"an element\" : `<${elementType}>`;\n throw new Error(\n `The events prop on ${target} must be an array of event descriptors created with on(type, callback).`,\n );\n}\n\nfunction isEventDescriptor(value: unknown): value is EventDescriptor {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as EventDescriptor).$$typeof === EventDescriptorSymbol\n );\n}\n\nfunction eventSlotsFor(element: Element): EventSlotList {\n let slots = eventSlots.get(element);\n if (slots === undefined) {\n slots = [];\n eventSlots.set(element, slots);\n }\n return slots;\n}\n\nfunction attachEventSlot(\n element: Element,\n root: Container | null,\n listenerTarget: Container | null,\n slot: EventSlot,\n): void {\n if (direct(slot.type)) {\n attachDirectEventSlot(element, root, slot);\n } else {\n attachDelegatedEventSlot(root, listenerTarget, slot);\n }\n}\n\nfunction attachDirectEventSlot(\n element: Element,\n root: Container | null,\n slot: EventSlot,\n): void {\n // The root scopes dispatch (root.data.run and friends), same as the\n // delegated path. The first attach can run before insertion, when\n // rootFor() is still null, so a re-attach on the same element refreshes\n // the root without re-adding the DOM listener.\n if (slot.element === element) {\n if (root !== null) slot.root = root;\n return;\n }\n\n detachEventSlot(slot);\n slot.element = element;\n slot.root = root;\n slot.listener = (event) => {\n try {\n dispatchEventSlot(\n {\n callback: slot.callback,\n element,\n root: slot.root,\n slot,\n type: slot.type,\n },\n event,\n );\n } finally {\n if (slot.element === null && slot.listenerTarget === null) {\n abortEventSlot(slot);\n }\n }\n };\n element.addEventListener(slot.type, slot.listener, slot.options);\n}\n\nfunction attachDelegatedEventSlot(\n root: Container | null,\n listenerTarget: Container | null,\n slot: EventSlot,\n): void {\n if (\n root === null ||\n listenerTarget === null ||\n (slot.root === root && slot.listenerTarget === listenerTarget)\n ) {\n return;\n }\n\n detachEventSlot(slot);\n slot.root = root;\n slot.listenerTarget = listenerTarget;\n\n acquireRootListener(\n root,\n listenerTarget,\n slot.type,\n slot.options.capture,\n slot.options.passive,\n );\n}\n\nfunction acquireRootListener(\n root: Container,\n listenerTarget: Container,\n type: string,\n capture: boolean,\n passive: boolean,\n): void {\n const listeners = rootListenerMap(listenerTarget);\n const key = `${type}:${capture}:${passive}`;\n let rootListener = listeners.get(key);\n\n if (rootListener === undefined) {\n rootListener = {\n capture,\n count: 0,\n listener: (event) =>\n dispatchRootEvent(root, listenerTarget, type, capture, passive, event),\n passive,\n type,\n };\n listenerTarget.addEventListener(type, rootListener.listener, {\n capture,\n passive,\n });\n listeners.set(key, rootListener);\n\n // A key newly active on a target mirrors onto its portal targets\n // (cascading through nested portals) so portal-inner events dispatch\n // through the logical tree for it.\n for (const portal of containerRecords.get(listenerTarget)?.portals ?? []) {\n acquireRootListener(root, portal, type, capture, passive);\n }\n }\n\n rootListener.count += 1;\n}\n\nfunction releaseRootListener(listenerTarget: Container, key: string): void {\n const listeners = containerRecords.get(listenerTarget)?.listeners;\n const rootListener = listeners?.get(key);\n if (listeners === undefined || rootListener === undefined) return;\n\n rootListener.count -= 1;\n if (rootListener.count > 0) return;\n\n listenerTarget.removeEventListener(rootListener.type, rootListener.listener, {\n capture: rootListener.capture,\n });\n listeners.delete(key);\n\n // The key died on this target: drop its mirrors from the portal targets.\n for (const portal of containerRecords.get(listenerTarget)?.portals ?? []) {\n releaseRootListener(portal, key);\n }\n}\n\nfunction detachEventSlot(slot: EventSlot): void {\n detachDirectEventSlot(slot);\n detachDelegatedEventSlot(slot);\n}\n\nfunction detachDirectEventSlot(slot: EventSlot): void {\n if (slot.element === null || slot.listener === null) return;\n\n slot.element.removeEventListener(slot.type, slot.listener, {\n capture: slot.options.capture,\n });\n slot.element = null;\n slot.listener = null;\n slot.root = null;\n}\n\nfunction detachDelegatedEventSlot(slot: EventSlot): void {\n const listenerTarget = slot.listenerTarget;\n if (listenerTarget === null) return;\n\n slot.root = null;\n slot.listenerTarget = null;\n releaseRootListener(listenerTarget, rootListenerKey(slot));\n}\n\nfunction rootListenerMap(root: Container): Map<string, RootListener> {\n return containerRecord(root).listeners;\n}\n\nfunction rootListenerKey(slot: EventSlot): string {\n return `${slot.type}:${slot.options.capture}:${slot.options.passive}`;\n}\n\nfunction eventPath(\n root: Container,\n listenerTarget: Container,\n event: Event,\n): Element[] {\n const composedPath = event.composedPath?.();\n\n if (composedPath !== undefined) {\n const index = composedPath.indexOf(listenerTarget);\n if (index !== -1) {\n return [\n ...composedPath.slice(0, index).filter(isElementNode),\n ...logicalPortalPath(root, listenerTarget),\n ];\n }\n }\n\n const path: Element[] = [];\n for (let current: unknown = event.target; current !== listenerTarget;) {\n if (isElementNode(current)) path.push(current);\n current = parentOf(current);\n if (current === null) break;\n }\n\n return [...path, ...logicalPortalPath(root, listenerTarget)];\n}\n\nfunction logicalPortalPath(\n root: Container,\n listenerTarget: Container,\n): Element[] {\n const owner = containerRecords.get(listenerTarget)?.portalOwner ?? null;\n if (owner === null || owner.root !== root) return [];\n\n const path: Element[] = [];\n let cursor: unknown = owner.logicalParent;\n\n while (cursor !== null && cursor !== root) {\n // A portal container in the chain (nested portals): continue from its\n // logical parent; the target element itself is not a logical ancestor.\n if (isContainer(cursor)) {\n const hop = containerRecords.get(cursor)?.portalOwner ?? null;\n if (hop !== null && hop.root === root) {\n cursor = hop.logicalParent;\n continue;\n }\n }\n\n if (isElementNode(cursor)) path.push(cursor);\n cursor = parentOf(cursor);\n }\n\n return path;\n}\n\nfunction targetWithinRoot(\n root: Container,\n target: EventTarget | null,\n): boolean {\n for (let current: unknown = target; current !== null;) {\n if (current === root) return true;\n current = parentOf(current);\n }\n\n return false;\n}\n\nfunction listenerTargetFor(node: EventTarget | null): Container | null {\n for (let current: unknown = node; current !== null;) {\n if (isContainer(current)) {\n const record = containerRecords.get(current);\n if (\n record !== undefined &&\n (record.portalOwner !== null || record.root)\n ) {\n return current;\n }\n }\n\n current = parentOf(current);\n }\n\n return null;\n}\n\nfunction withCurrentTarget<T>(\n event: Event,\n currentTarget: Element,\n callback: (event: Event) => T,\n): T {\n const previous = Object.getOwnPropertyDescriptor(event, \"currentTarget\");\n const changed = Reflect.defineProperty(event, \"currentTarget\", {\n configurable: true,\n value: currentTarget,\n });\n\n try {\n return callback(event);\n } finally {\n if (changed) {\n if (previous === undefined) {\n delete (event as unknown as { currentTarget?: EventTarget | null })\n .currentTarget;\n } else {\n Object.defineProperty(event, \"currentTarget\", previous);\n }\n }\n }\n}\n\n// Runs one logical dispatch with its own propagation state: the stop\n// methods and the legacy cancelBubble property are patched (save/restore,\n// so nested dispatches of other events are isolated) to record into the\n// state while still driving the natives. Replays set\n// `ignoreExistingCancelBubble`: a spent event's stale cancelBubble must not\n// drop the replay, while a LIVE dispatch honors cancelBubble a sibling root\n// listener's handler already set. Stops made DURING the dispatch — method\n// calls or `event.cancelBubble = true` assignments — are observed either\n// way via the patches.\nfunction withPropagationState<T>(\n event: Event,\n ignoreExistingCancelBubble: boolean,\n callback: (state: PropagationState) => T,\n): T {\n const existingCancelBubble = event.cancelBubble === true;\n const state: PropagationState = {\n immediateStopped: false,\n stopped: !ignoreExistingCancelBubble && existingCancelBubble,\n };\n\n const restoreStop = patchEventMethod(event, \"stopPropagation\", () => {\n state.stopped = true;\n });\n const restoreImmediate = patchEventMethod(\n event,\n \"stopImmediatePropagation\",\n () => {\n state.stopped = true;\n state.immediateStopped = true;\n },\n );\n const restoreCancelBubble = patchCancelBubble(event, state);\n\n try {\n return callback(state);\n } finally {\n restoreCancelBubble();\n restoreImmediate();\n restoreStop();\n // Reflect a stop from this dispatch onto the real event once the\n // patches are gone (a legacy assignment only reached the shadow).\n if (state.stopped) event.cancelBubble = true;\n }\n}\n\nfunction patchCancelBubble(event: Event, state: PropagationState): () => void {\n const previous = Object.getOwnPropertyDescriptor(event, \"cancelBubble\");\n const changed = Reflect.defineProperty(event, \"cancelBubble\", {\n configurable: true,\n // `stopped` is seeded from the effective pre-existing value (ignored\n // for replays), so reads reflect THIS dispatch: a replay handler must\n // not observe the spent event's stale stop state.\n get: () => state.stopped,\n set(value: unknown) {\n // Per spec, assigning false does nothing.\n if (value === true) state.stopped = true;\n },\n });\n\n return () => {\n if (!changed) return;\n if (previous === undefined) {\n delete (event as unknown as Record<string, unknown>).cancelBubble;\n } else {\n Object.defineProperty(event, \"cancelBubble\", previous);\n }\n };\n}\n\nfunction patchEventMethod(\n event: Event,\n name: \"stopImmediatePropagation\" | \"stopPropagation\",\n onCall: () => void,\n): () => void {\n const native = Reflect.get(event, name);\n if (typeof native !== \"function\") return () => undefined;\n\n const previous = Object.getOwnPropertyDescriptor(event, name);\n const changed = Reflect.defineProperty(event, name, {\n configurable: true,\n value() {\n onCall();\n native.call(event);\n },\n });\n\n return () => {\n if (!changed) return;\n if (previous === undefined) {\n delete (event as unknown as Record<string, unknown>)[name];\n } else {\n Object.defineProperty(event, name, previous);\n }\n };\n}\n\nfunction normalizedOptions(options: EventOptions = {}): Required<EventOptions> {\n return {\n capture: options.capture === true,\n passive: options.passive === true,\n };\n}\n\nfunction eventKey(type: string, options: Required<EventOptions>): string {\n return `${type}:${options.capture}:${options.passive}`;\n}\n\nfunction eventPriority(type: string): EventPriority {\n if (discreteEvents.has(type)) return \"discrete\";\n if (continuousEvents.has(type)) return \"continuous\";\n return \"default\";\n}\n\nfunction passiveHydrationEvent(type: string): boolean {\n // Hydration listeners never call preventDefault, so scroll-blocking touch\n // events can stay passive alongside the continuous set.\n return (\n continuousEvents.has(type) || type === \"touchstart\" || type === \"touchend\"\n );\n}\n\nfunction direct(type: string): boolean {\n return nonDelegatedEvents.has(type);\n}\n\nfunction isContainer(node: unknown): node is Container {\n return (\n typeof node === \"object\" &&\n node !== null &&\n \"addEventListener\" in node &&\n \"childNodes\" in node\n );\n}\n","import { attachElementBind, detachElementBind } from \"./bind.ts\";\nimport { attachElementEvents, detachElementEvents } from \"./events.ts\";\nimport { visitElementSubtree } from \"./tree.ts\";\n\n// Bind and event state always attach and detach together when DOM moves in\n// or out of the live tree; a single walk keeps that pairing unforgettable\n// (a hook calling one without the other leaks signals or listeners) and\n// halves the traversal per insertion/removal.\n\nexport function attachSubtree(node: Element | Text): void {\n visitElementSubtree(node, (element) => {\n attachElementBind(element);\n attachElementEvents(element);\n });\n}\n\nexport function detachSubtree(node: Element | Text): void {\n visitElementSubtree(node, (element) => {\n detachElementBind(element);\n detachElementEvents(element);\n });\n}\n","import type { Props } from \"@bgub/fig\";\nimport { updateBind } from \"./bind.ts\";\nimport { updateEvents } from \"./events.ts\";\nimport {\n elementName,\n isElementNode,\n isEmptyPropValue,\n isHtmlElement,\n} from \"./tree.ts\";\n\ndeclare const __FIG_DEV__: boolean | undefined;\n\nconst __DEV__ = typeof __FIG_DEV__ === \"boolean\" ? __FIG_DEV__ : false;\n\ninterface SelectState {\n appliedDefault: boolean;\n applyDefaultToInsertedOptions: boolean;\n controlled: boolean;\n selectedValues: ReadonlySet<string>;\n value: unknown;\n}\n\ninterface UpdateOptions {\n hydrating?: boolean;\n // The instance's first render: the only time defaultValue/defaultChecked\n // may live-write the element's value/checked state.\n initial?: boolean;\n}\n\ntype StyleTarget = Record<string, unknown> & {\n readonly length?: number;\n item?: (index: number) => string;\n removeProperty?: (name: string) => void;\n setProperty?: (name: string, value: string) => void;\n};\n\nconst selectState = new WeakMap<Element, SelectState>();\nconst xlinkNamespace = \"http://www.w3.org/1999/xlink\";\n\nexport function updateElement(\n element: Element,\n previousProps: Props,\n nextProps: Props,\n options: UpdateOptions = {},\n): void {\n const type = elementName(element);\n const html = isHtmlElement(element);\n const names = new Set([\n ...Object.keys(previousProps),\n ...Object.keys(nextProps),\n ]);\n\n for (const name of names) {\n if (name === \"events\") {\n updateEvents(element, nextProps[name]);\n continue;\n }\n\n if (name === \"bind\") {\n updateBind(element, nextProps[name]);\n continue;\n }\n\n const previous = previousProps[name];\n const next = nextProps[name];\n\n if (name === \"unsafeHTML\") {\n if (options.hydrating === true) {\n unsafeHTMLValue(next);\n continue;\n }\n if (previous !== next) setUnsafeHTML(element, next);\n continue;\n }\n\n if (reserved(name)) {\n if (__DEV__ && event(name)) {\n warnDroppedProp(name, eventPropWarning(name, type, nextProps));\n }\n continue;\n }\n\n if (formProp(name)) {\n if (\n __DEV__ &&\n (name === \"checked\" || name === \"defaultChecked\") &&\n next !== undefined &&\n typeof next !== \"boolean\" &&\n next !== null\n ) {\n warnDroppedProp(\n `${name}:${typeof next}`,\n `The \"${name}\" prop received a ${typeof next} (${String(next)}); ` +\n \"Fig treats only `true` as checked, so this renders unchecked.\",\n );\n }\n setFormProperty(element, type, name, next, nextProps, options);\n continue;\n }\n\n if (previous === next) continue;\n if (name === \"style\") {\n if (__DEV__ && typeof next === \"string\" && next !== \"\") {\n warnDroppedProp(\n \"style:string\",\n \"The style prop must be an object of properties; string styles \" +\n \"are ignored.\",\n );\n }\n setStyle(element, previous, next);\n } else setAttribute(element, hostAttributeName(name, html), next);\n }\n\n updateSelectOptions(element, type, previousProps, nextProps, options);\n // Only option updates (value/text) can change which option a parent\n // select's stored value matches; skip the ancestor walk for everything\n // else.\n if (type === \"option\" || type === \"optgroup\") updateParentSelect(element);\n}\n\n// Dev-only, deduped by key: silently dropping a prop the author clearly\n// intended (onClick, checked={1}, string styles) is the worst failure mode —\n// nothing renders wrong, the behavior just never happens.\nconst warnedDroppedProps = new Set<string>();\n\nfunction warnDroppedProp(key: string, message: string): void {\n if (warnedDroppedProps.has(key)) return;\n warnedDroppedProps.add(key);\n console.error(message);\n}\n\nfunction eventPropWarning(name: string, type: string, props: Props): string {\n // A trailing \"Capture\" is React's capture-phase suffix, except when it is\n // part of the event name itself (onGotPointerCapture/onLostPointerCapture\n // are bubble-phase props for gotpointercapture/lostpointercapture) or is\n // the entire name (an \"onCapture\" prop would leave an empty event name).\n const capture =\n name.endsWith(\"Capture\") &&\n name.length > \"onCapture\".length &&\n name !== \"onGotPointerCapture\" &&\n name !== \"onLostPointerCapture\";\n const rawName = name.slice(2, capture ? -\"Capture\".length : undefined);\n const options = capture ? \", { capture: true }\" : \"\";\n const suggest = (eventName: string) =>\n `Fig has no \"${name}\" event props; use ` +\n `events={[on(\"${eventName}\", handler${options})]} instead.`;\n\n if (rawName === \"DoubleClick\") return suggest(\"dblclick\");\n if (rawName === \"Change\" && reactChangeUsesInputEvent(type, props)) {\n return (\n suggest(\"input\") +\n ` (React's onChange on text-editing controls fires per change like the` +\n ` native \"input\" event; on(\"change\") fires only on commit.)`\n );\n }\n return suggest(rawName.toLowerCase());\n}\n\n// React backs onChange on text-editing controls with the native \"input\"\n// event; only checkbox/radio/file inputs (and selects) match the native\n// \"change\" timing, so everything else steers to on(\"input\").\nfunction reactChangeUsesInputEvent(type: string, props: Props): boolean {\n if (type === \"textarea\") return true;\n if (type !== \"input\") return false;\n const inputType = typeof props.type === \"string\" ? props.type : \"text\";\n return (\n inputType !== \"checkbox\" && inputType !== \"radio\" && inputType !== \"file\"\n );\n}\n\nexport function hydrateElement(element: Element, nextProps: Props): void {\n // Snapshot before the update applies: updateElement writes the client\n // style prop into the same declaration and runs the bind callback (which\n // may set attributes), so a post-update enumeration could not tell\n // server-set names from client-set ones.\n const serverStyles = __DEV__ ? hydratedStyleNames(element) : [];\n const serverAttributes = __DEV__ ? attributeNames(element) : [];\n\n updateElement(element, {}, nextProps, { hydrating: true });\n\n if (__DEV__ && nextProps.suppressHydrationWarning !== true) {\n warnExtraHydratedAttributes(\n element,\n nextProps,\n serverStyles,\n serverAttributes,\n );\n }\n}\n\n// Server-only attributes and styles are preserved (extensions and internal\n// markers make removal unsafe), so surface the divergence from a pure client\n// render as a dev warning instead.\nfunction warnExtraHydratedAttributes(\n element: Element,\n nextProps: Props,\n serverStyles: readonly string[],\n serverAttributes: readonly string[],\n): void {\n if (serverAttributes.length === 0 && serverStyles.length === 0) return;\n\n const expectedAttributes = new Set<string>();\n const type = elementName(element);\n const html = isHtmlElement(element);\n\n for (const name of Object.keys(nextProps)) {\n if (name === \"events\" || name === \"bind\" || reserved(name)) continue;\n\n const attribute = hydratedAttributeName(type, name, html);\n if (attribute !== null) expectedAttributes.add(attribute);\n }\n\n const extra: string[] = [];\n for (const name of serverAttributes) {\n const attribute = hostAttributeName(name, html);\n if (attribute.startsWith(\"data-fig-\")) continue;\n if (!expectedAttributes.has(attribute)) extra.push(name);\n }\n\n extra.push(...extraHydratedStyleNames(serverStyles, nextProps.style));\n\n if (extra.length === 0) return;\n\n console.error(\n `Hydration preserved extra server attributes or styles on <${type}>: ` +\n `${extra.sort().join(\", \")}. They were preserved, so this element now ` +\n \"differs from a pure client render.\",\n );\n}\n\n// Writing the client style prop to a scratch declaration routes both name\n// sets through the same CSSOM canonicalization (shorthand expansion, name\n// casing), so server-set and client-produced names compare directly.\nfunction extraHydratedStyleNames(\n serverStyles: readonly string[],\n next: unknown,\n): string[] {\n if (serverStyles.length === 0) return [];\n\n const scratch = document.createElement(\"div\");\n setStyle(scratch, {}, next);\n const expected = new Set(hydratedStyleNames(scratch));\n\n return serverStyles\n .filter((name) => !expected.has(name))\n .map((name) => `style.${name}`);\n}\n\nfunction hydratedStyleNames(element: Element): string[] {\n const style = (element as HTMLElement).style as unknown as\n | StyleTarget\n | undefined;\n if (style === undefined) return [];\n\n if (typeof style.length === \"number\" && typeof style.item === \"function\") {\n const names: string[] = [];\n for (let index = 0; index < style.length; index += 1) {\n const name = style.item(index);\n if (name !== \"\") names.push(name);\n }\n return names;\n }\n\n return Object.keys(style).filter((name) => style[name] !== \"\");\n}\n\nfunction hydratedAttributeName(\n type: string,\n name: string,\n html: boolean,\n): string | null {\n if ((type === \"textarea\" || type === \"select\") && valueProp(name)) {\n return null;\n }\n\n if (name === \"defaultValue\") return \"value\";\n if (name === \"defaultChecked\") return \"checked\";\n return hostAttributeName(name, html);\n}\n\nfunction attributeNames(element: Element): string[] {\n const attributes = element.attributes as\n | (NamedNodeMap & Iterable<Attr>)\n | Record<string, unknown>\n | undefined;\n\n if (attributes === undefined) return [];\n\n if (\n \"length\" in attributes &&\n typeof attributes.length === \"number\" &&\n \"item\" in attributes &&\n typeof attributes.item === \"function\"\n ) {\n const names: string[] = [];\n for (let index = 0; index < attributes.length; index += 1) {\n const attribute = attributes.item(index);\n if (attribute !== null) names.push(attribute.name);\n }\n return names;\n }\n\n if (Symbol.iterator in attributes) {\n return Array.from(\n attributes as Iterable<Attr>,\n (attribute) => attribute.name,\n );\n }\n\n return Object.keys(attributes);\n}\n\nfunction setFormProperty(\n element: Element,\n type: string,\n name: string,\n next: unknown,\n nextProps: Props,\n options: UpdateOptions,\n): void {\n if (type === \"select\" && valueProp(name)) return;\n if (type === \"option\" && name === \"value\") {\n setAttribute(element, \"value\", formValue(next));\n return;\n }\n\n // Defaults live-write only on the instance's very first render (and never\n // during hydration, or when a controlling sibling prop wins): a\n // defaultValue/defaultChecked that APPEARS on a later update must not\n // clobber what the user typed or toggled since mount.\n const initial = options.initial === true && options.hydrating !== true;\n\n if (name === \"value\") {\n if (isEmptyPropValue(next)) return;\n setFormValue(element, next, type, { live: true });\n } else if (name === \"defaultValue\") {\n setFormValue(element, next, type, {\n defaultValue: true,\n live: initial && nextProps.value === undefined,\n });\n } else if (name === \"checked\") {\n if (next === undefined) return;\n setChecked(element, next, { live: true });\n } else if (name === \"defaultChecked\") {\n setChecked(element, next, {\n defaultChecked: true,\n live: initial && nextProps.checked === undefined,\n });\n }\n}\n\nfunction setFormValue(\n element: Element,\n value: unknown,\n type: string,\n options: { defaultValue?: boolean; live?: boolean },\n): void {\n const textArea = type === \"textarea\";\n const next = formValue(value);\n\n if (options.defaultValue === true && \"defaultValue\" in element) {\n (element as unknown as { defaultValue: string }).defaultValue = next ?? \"\";\n }\n if (options.defaultValue === true) {\n if (textArea) {\n element.textContent = next ?? \"\";\n } else {\n setAttribute(element, \"value\", next);\n }\n }\n\n if (options.live === true && \"value\" in element) {\n if ((element as unknown as { value: string }).value !== (next ?? \"\")) {\n (element as unknown as { value: string }).value = next ?? \"\";\n }\n } else if (options.live === true && next !== null) {\n setAttribute(element, \"value\", next);\n }\n}\n\nfunction formValue(value: unknown): string | null {\n return isEmptyPropValue(value) ? null : String(value);\n}\n\nfunction setChecked(\n element: Element,\n value: unknown,\n options: { defaultChecked?: boolean; live?: boolean },\n): void {\n const checked = value === true;\n\n // The checked content attribute IS defaultChecked's reflection, so only\n // the defaultChecked prop may touch it — a controlled `checked` writes the\n // live property alone, mirroring value/defaultValue above.\n if (options.defaultChecked === true) {\n if (\"defaultChecked\" in element) {\n (element as unknown as { defaultChecked: boolean }).defaultChecked =\n checked;\n }\n setAttribute(element, \"checked\", checked);\n }\n\n if (options.live === true && \"checked\" in element) {\n (element as unknown as { checked: boolean }).checked = checked;\n } else if (options.live === true) {\n setAttribute(element, \"checked\", checked);\n }\n}\n\nfunction setUnsafeHTML(element: Element, value: unknown): void {\n const html = unsafeHTMLValue(value);\n if (!(\"innerHTML\" in element)) return;\n\n (element as unknown as { innerHTML: string }).innerHTML = html ?? \"\";\n}\n\nfunction unsafeHTMLValue(value: unknown): string | null {\n if (isEmptyPropValue(value)) return null;\n if (typeof value === \"string\") return value;\n throw new Error(\"The unsafeHTML prop must be a string.\");\n}\n\nfunction updateSelectOptions(\n element: Element,\n type: string,\n previousProps: Props,\n nextProps: Props,\n options: UpdateOptions = {},\n): void {\n if (type !== \"select\") return;\n\n const controlled = nextProps.value !== undefined;\n const value = controlled ? nextProps.value : nextProps.defaultValue;\n if (value === undefined || value === null || value === false) {\n selectState.delete(element);\n return;\n }\n\n // A hydrating uncontrolled select trusts the server DOM's selection (the\n // user may have changed it before JS loaded); record the default as\n // applied so later updates don't re-apply it either. Controlled selects\n // still re-assert their value.\n const hydratingDefault = !controlled && options.hydrating === true;\n\n const state = selectState.get(element);\n const shouldApply =\n !hydratingDefault &&\n (controlled || (!controlled && options.initial === true));\n const nextState = {\n appliedDefault: state?.appliedDefault === true || !controlled,\n applyDefaultToInsertedOptions:\n !hydratingDefault && !controlled && options.initial === true,\n controlled,\n selectedValues: selectValues(value),\n value,\n };\n selectState.set(element, nextState);\n if (!shouldApply) return;\n\n setSelectValue(element, nextState.selectedValues);\n}\n\nexport function updateParentSelect(\n element: Element,\n applyDefault = false,\n): void {\n const select = closestParentSelect(element);\n if (select === null) return;\n\n const state = selectState.get(select);\n if (state === undefined) return;\n if (!state.controlled && state.appliedDefault && !applyDefault) return;\n if (\n !state.controlled &&\n applyDefault &&\n !state.applyDefaultToInsertedOptions\n ) {\n return;\n }\n\n setSelectValue(element, state.selectedValues);\n if (!state.controlled) {\n state.appliedDefault = true;\n }\n}\n\nfunction selectValues(value: unknown): ReadonlySet<string> {\n return new Set(Array.isArray(value) ? value.map(String) : [String(value)]);\n}\n\nfunction setSelectValue(element: Element, values: ReadonlySet<string>): void {\n if (elementName(element) === \"option\") {\n setOptionSelected(element, values);\n return;\n }\n\n forEachDescendantOption(element, (option) => {\n setOptionSelected(option, values);\n });\n}\n\nfunction setOptionSelected(option: Element, values: ReadonlySet<string>): void {\n (option as unknown as { selected: boolean }).selected = values.has(\n currentOptionValue(option),\n );\n}\n\nfunction closestParentSelect(element: Element): Element | null {\n let parent: Node | null = element.parentNode;\n while (parent !== null) {\n if (isElementNode(parent) && elementName(parent) === \"select\") {\n return parent;\n }\n parent = parent.parentNode;\n }\n\n return null;\n}\n\nfunction forEachDescendantOption(\n element: Element,\n visitor: (option: Element) => void,\n): void {\n for (let child = element.firstChild; child !== null;) {\n const next = child.nextSibling;\n if (isElementNode(child)) {\n if (elementName(child) === \"option\") {\n visitor(child);\n } else {\n forEachDescendantOption(child, visitor);\n }\n }\n child = next;\n }\n}\n\nfunction currentOptionValue(option: Element): string {\n const value = attributeValue(option, \"value\");\n if (value !== null) return value;\n\n // Spec-ish option.text: pretty-printed markup collapses to the visible\n // label, so implicit values match their authored form.\n return (option.textContent ?? \"\").replace(/\\s+/g, \" \").trim();\n}\n\nfunction attributeValue(element: Element, name: string): string | null {\n return element.getAttribute(name);\n}\n\nfunction setStyle(element: Element, previous: unknown, next: unknown): void {\n const style = (element as HTMLElement).style as unknown as\n | StyleTarget\n | undefined;\n if (style === undefined) return;\n\n const previousStyle = styleProps(previous);\n const nextStyle = styleProps(next);\n\n for (const name of Object.keys(previousStyle)) {\n if (!(name in nextStyle)) clearStyleProperty(style, name);\n }\n\n for (const [name, value] of Object.entries(nextStyle)) {\n if (value === null || value === undefined || value === false) {\n clearStyleProperty(style, name);\n } else {\n setStyleProperty(style, name, value);\n }\n }\n}\n\nfunction styleProps(value: unknown): Record<string, unknown> {\n return typeof value === \"object\" && value !== null\n ? (value as Record<string, unknown>)\n : {};\n}\n\nfunction setStyleProperty(\n style: StyleTarget,\n name: string,\n value: unknown,\n): void {\n if (typeof value === \"number\" || typeof value === \"bigint\") {\n if (__DEV__) {\n warnDroppedProp(\n `style:${name}:${typeof value}`,\n `The style property \"${name}\" received a ${typeof value} ` +\n `(${String(value)}); Fig style values must be strings, so this ` +\n \"style is ignored.\",\n );\n }\n return;\n }\n\n if (name.startsWith(\"--\") && typeof style.setProperty === \"function\") {\n style.setProperty(name, String(value));\n } else {\n style[name] = value;\n }\n}\n\nfunction clearStyleProperty(style: StyleTarget, name: string): void {\n if (name.startsWith(\"--\") && typeof style.removeProperty === \"function\") {\n style.removeProperty(name);\n } else {\n style[name] = \"\";\n }\n}\n\nfunction hostAttributeName(name: string, html: boolean): string {\n return html ? name.toLowerCase() : name;\n}\n\nfunction setAttribute(\n element: Element,\n attribute: string,\n value: unknown,\n): void {\n if (isEmptyPropValue(value)) {\n removeAttribute(element, attribute);\n return;\n }\n\n if (attribute === \"xlink:href\") {\n element.setAttributeNS(xlinkNamespace, attribute, String(value));\n return;\n }\n\n element.setAttribute(attribute, String(value));\n}\n\nfunction removeAttribute(element: Element, attribute: string): void {\n if (attribute === \"xlink:href\") {\n element.removeAttributeNS(xlinkNamespace, \"href\");\n return;\n }\n\n element.removeAttribute(attribute);\n}\n\nfunction formProp(name: string): boolean {\n return valueProp(name) || name === \"checked\" || name === \"defaultChecked\";\n}\n\nfunction valueProp(name: string): boolean {\n return name === \"value\" || name === \"defaultValue\";\n}\n\nfunction reserved(name: string): boolean {\n return (\n name === \"children\" ||\n name === \"key\" ||\n name === \"suppressHydrationWarning\" ||\n name === \"unsafeHTML\" ||\n event(name)\n );\n}\n\nfunction event(name: string): boolean {\n return /^on[A-Z]/.test(name);\n}\n","import { type FigAssetResource, type Props } from \"@bgub/fig\";\nimport {\n assetResourceFromHostAttributes,\n assetResourceFromHostProps,\n assetResourceHostAttributes,\n assetResourceKey,\n isFigAssetResource,\n} from \"@bgub/fig/internal\";\nimport { attachSubtree, detachSubtree } from \"./attachment.ts\";\nimport { updateElement } from \"./props.ts\";\nimport { elementName, isElementNode } from \"./tree.ts\";\n\n// The document/asset-resource registry: hoisted head elements (stylesheets,\n// scripts, preloads, fonts, title/meta) are found-or-created during render,\n// acquired/released with commit-phase refcounting through the hoisted host\n// hooks, and deduped against SSR output by assetResourceKey.\n\ninterface DocumentResourceEntry {\n count: number;\n element: Element;\n ready: Promise<void> | null;\n}\n\ninterface DocumentResourceMeta {\n key: string;\n kind: FigAssetResource[\"kind\"];\n}\n\nconst documentResourceRegistries = new WeakMap<\n Element,\n Map<string, DocumentResourceEntry>\n>();\nconst documentResourceMeta = new WeakMap<Element, DocumentResourceMeta>();\n\n// Render-phase find-or-create only: renders can be discarded and retried, so\n// acquisition (refcounting, head insertion) waits for commitHoistedInstance.\n// The zero-count registry entry dedupes sibling adopts within a render pass.\nexport function adoptDocumentResource(\n type: string,\n props: Props,\n): Element | null {\n const head = documentHead();\n const resource = assetResourceFromHostProps(type, props);\n if (head === null || resource === null) return null;\n\n const key = assetResourceKey(resource);\n const registry = documentResourceRegistry(head);\n const adopted = registry.get(key);\n const element =\n adopted?.element ??\n findDocumentResource(head, key) ??\n document.createElement(type);\n\n if (adopted === undefined) {\n registry.set(key, { count: 0, element, ready: null });\n documentResourceMeta.set(element, { key, kind: resource.kind });\n }\n\n return element;\n}\n\nexport function acquireDocumentResource(element: Element): Element {\n const head = documentHead();\n if (head === null) return element;\n\n const registry = documentResourceRegistry(head);\n let meta = documentResourceMeta.get(element);\n\n // Deletions commit before placements, so a sibling's release in the same\n // commit may have dropped the element from the registry; re-derive its\n // identity from its attributes and revive it.\n if (meta === undefined) {\n const resource = assetResourceFromHostAttributes(\n elementName(element),\n (name: string) => element.getAttribute(name),\n );\n if (resource === null) return element;\n meta = { key: assetResourceKey(resource), kind: resource.kind };\n documentResourceMeta.set(element, meta);\n }\n\n const entry = registry.get(meta.key);\n\n // The key already resolves to a different live element (e.g. inserted by\n // insertAssetResources while this owner's render was suspended): adopt the\n // authoritative element instead of appending a stale duplicate.\n if (entry !== undefined && entry.element !== element) {\n entry.count += 1;\n return attachDocumentResource(head, entry.element);\n }\n\n if (entry === undefined) {\n registry.set(meta.key, { count: 1, element, ready: null });\n } else {\n entry.count += 1;\n }\n\n return attachDocumentResource(head, element);\n}\n\nfunction attachDocumentResource(head: Element, element: Element): Element {\n if (element.parentNode !== head) head.appendChild(element);\n attachSubtree(element);\n return element;\n}\n\nfunction documentResourceRegistry(\n head: Element,\n): Map<string, DocumentResourceEntry> {\n let registry = documentResourceRegistries.get(head);\n if (registry === undefined) {\n registry = new Map();\n documentResourceRegistries.set(head, registry);\n }\n return registry;\n}\n\nexport function releaseDocumentResource(element: Element): void {\n const head = documentHead();\n const meta = documentResourceMeta.get(element);\n if (head === null || meta === undefined) return;\n\n const registry = documentResourceRegistries.get(head);\n const entry = registry?.get(meta.key);\n\n // An element displaced from the registry (rekey collision) is untracked:\n // remove it with its owner unless another entry still shares it.\n if (entry === undefined || entry.element !== element) {\n if (registryReferencesElement(registry, element)) return;\n documentResourceMeta.delete(element);\n if (removableResourceKind(meta.kind)) removeReleasedResource(element);\n return;\n }\n\n if (entry.count > 0) entry.count -= 1;\n if (entry.count > 0) return;\n\n // Stylesheets, scripts, and fetch hints persist once inserted: removal\n // cannot undo a load and would unstyle content that still races on it.\n // Document metadata is removed with its last owner.\n if (!removableResourceKind(meta.kind)) return;\n\n registry?.delete(meta.key);\n documentResourceMeta.delete(element);\n removeReleasedResource(element);\n}\n\nfunction removeReleasedResource(element: Element): void {\n detachSubtree(element);\n element.parentNode?.removeChild(element);\n}\n\nfunction removableResourceKind(kind: FigAssetResource[\"kind\"]): boolean {\n return kind === \"title\" || kind === \"meta\";\n}\n\nfunction registryReferencesElement(\n registry: Map<string, DocumentResourceEntry> | undefined,\n element: Element,\n): boolean {\n if (registry === undefined) return false;\n for (const entry of registry.values()) {\n if (entry.element === element) return true;\n }\n return false;\n}\n\n// Hoisted instances are shared by key, so an identity change must not mutate\n// the shared element in place: release this owner's share of the old\n// identity and adopt (or create) the element for the new one. Other owners\n// keep the old element and its attributes untouched.\nexport function updateHoistedResource(\n element: Element,\n previousProps: Props,\n nextProps: Props,\n): Element {\n const type = elementName(element);\n const resource = assetResourceFromHostProps(type, nextProps);\n const meta = documentResourceMeta.get(element);\n const key = resource === null ? null : assetResourceKey(resource);\n\n if (key === null || meta === undefined || key === meta.key) {\n updateElement(element, previousProps, nextProps);\n return element;\n }\n\n releaseDocumentResource(element);\n\n const head = documentHead();\n const entry =\n head === null ? undefined : documentResourceRegistry(head).get(key);\n const claimed =\n entry !== undefined && entry.count > 0 ? entry.element : undefined;\n const next = adoptDocumentResource(type, nextProps) ?? element;\n if (next === element) {\n // No head to adopt into; fall back to the in-place update.\n updateElement(element, previousProps, nextProps);\n return element;\n }\n\n // Style only a fresh or unclaimed element; an element other owners already\n // committed keeps its attributes (identity is key-authoritative).\n if (claimed !== next) updateElement(next, {}, nextProps);\n return acquireDocumentResource(next);\n}\n\nfunction documentHead(): Element | null {\n return typeof document !== \"undefined\" && document.head !== undefined\n ? document.head\n : null;\n}\n\nfunction findDocumentResource(head: Element, key: string): Element | null {\n for (const child of Array.from(head.childNodes)) {\n if (!isElementNode(child)) continue;\n\n const resource = assetResourceFromHostAttributes(\n child.localName,\n (name: string) => child.getAttribute(name),\n );\n if (resource !== null && assetResourceKey(resource) === key) {\n return child;\n }\n }\n\n return null;\n}\n\n/**\n * Insert render-discovered asset resources (e.g. from a payload response's\n * `getAssetResources()`) into the document head, deduped against resources\n * already inserted by SSR, a host-rendered element, or an earlier call — using\n * the same key semantics as host resources. Returns a promise that resolves once\n * every freshly inserted *critical* stylesheet has loaded or errored, so callers\n * can gate revealing the dependent content. Non-critical hints (preload,\n * preconnect, scripts, fonts, `blocking: \"none\"` stylesheets) never block.\n */\nexport function insertAssetResources(\n resources: readonly FigAssetResource[],\n): Promise<void> {\n const head = documentHead();\n if (head === null) return Promise.resolve();\n\n const registry = documentResourceRegistry(head);\n const gates: Promise<void>[] = [];\n\n for (const resource of resources) {\n if (!isFigAssetResource(resource)) continue;\n if (resource.kind === \"title\" || resource.kind === \"meta\") continue;\n\n // A font is delivered as <link rel=\"preload\" as=\"font\">, which parses back\n // to a preload resource. Normalize it to that shape so its key and DOM\n // round-trip match and it dedupes against SSR/host-rendered font preloads\n // (otherwise the font:<href> lookup key never matches the preload:font:<href>\n // a head <link> parses to, and a duplicate is appended).\n const asset = asInsertableResource(resource);\n const key = assetResourceKey(asset);\n // A registry entry only counts as present while its element is attached:\n // a discarded render can leave a detached zero-count element built from\n // host props that need not match this descriptor (media, explicit-key\n // href), so a stale entry is discarded and replaced by a fresh element\n // created from the descriptor below.\n const tracked = registry.get(key)?.element;\n const existing: Element | null =\n (tracked !== undefined && tracked.parentNode === head ? tracked : null) ??\n findDocumentResource(head, key);\n\n if (existing !== null) {\n // Already present (SSR, a host-rendered element, or a prior call):\n // adopt it into the registry for O(1) future lookups. If Fig inserted it\n // and it is still loading, dependents join that pending gate. In dev,\n // Vite may insert a CSS link first; claim that still-loading element too\n // so route reveal waits for the stylesheet instead of committing a blank\n // payload slot.\n let entry = registry.get(key);\n if (entry?.element !== existing) {\n entry = { count: 1, element: existing, ready: null };\n registry.set(key, entry);\n documentResourceMeta.set(existing, { key, kind: asset.kind });\n }\n const existingGate = gateExistingStylesheet(asset, entry, key, registry);\n if (existingGate !== null) {\n gates.push(existingGate);\n }\n continue;\n }\n\n const element = createAssetResourceElement(asset);\n const entry: DocumentResourceEntry = {\n count: 1,\n element,\n ready: null,\n };\n const gate = isCriticalStylesheet(asset)\n ? whenResourceSettled(element).then(() => {\n if (registry.get(key) === entry) entry.ready = null;\n })\n : null;\n entry.ready = gate;\n registry.set(key, entry);\n documentResourceMeta.set(element, { key, kind: asset.kind });\n head.appendChild(element);\n\n if (gate !== null) gates.push(gate);\n }\n\n return gates.length === 0\n ? Promise.resolve()\n : Promise.all(gates).then(() => undefined);\n}\n\nfunction asInsertableResource(resource: FigAssetResource): FigAssetResource {\n // Fonts share the DOM representation (and therefore the key space) of a\n // font-targeted preload; everything else is already in its own key space.\n if (resource.kind !== \"font\") return resource;\n\n return {\n as: \"font\",\n crossOrigin: resource.crossOrigin ?? \"anonymous\",\n fetchPriority: resource.fetchPriority,\n href: resource.href,\n key: resource.key,\n kind: \"preload\",\n type: resource.type,\n };\n}\n\nfunction isCriticalStylesheet(resource: FigAssetResource): boolean {\n // Client-reference stylesheets gate reveal by default; opt out with\n // blocking: \"none\". Every other kind is a hint that must never block.\n if (resource.kind !== \"stylesheet\" || resource.blocking === \"none\") {\n return false;\n }\n if (resource.media === undefined || resource.media === \"\") return true;\n // Outside browsers there is no reliable media evaluation, so keep media\n // stylesheets conservative and gate them as potentially critical.\n return typeof matchMedia !== \"function\" || matchMedia(resource.media).matches;\n}\n\nfunction gateExistingStylesheet(\n resource: FigAssetResource,\n entry: DocumentResourceEntry,\n key: string,\n registry: Map<string, DocumentResourceEntry>,\n): Promise<void> | null {\n if (!isCriticalStylesheet(resource)) return null;\n if (entry.ready !== null) return entry.ready;\n if (!isPendingStylesheetElement(entry.element)) return null;\n\n const gate = whenResourceSettled(entry.element).then(() => {\n if (registry.get(key) === entry) entry.ready = null;\n });\n entry.ready = gate;\n return gate;\n}\n\nfunction isPendingStylesheetElement(element: Element): boolean {\n return (\n element.localName === \"link\" &&\n element.getAttribute(\"rel\") === \"stylesheet\" &&\n \"sheet\" in element &&\n (element as { sheet: StyleSheet | null }).sheet === null\n );\n}\n\nfunction whenResourceSettled(element: Element): Promise<void> {\n return new Promise<void>((resolve) => {\n const settle = () => {\n element.removeEventListener(\"load\", settle);\n element.removeEventListener(\"error\", settle);\n resolve();\n };\n // Resolve on error too: a failed stylesheet must not block reveal forever.\n element.addEventListener(\"load\", settle);\n element.addEventListener(\"error\", settle);\n });\n}\n\n// The attribute set is shared with the server's registry writer, so a\n// client-inserted asset element cannot drift from its SSR counterpart.\nfunction createAssetResourceElement(resource: FigAssetResource): Element {\n const element = document.createElement(\n resource.kind === \"script\" ? \"script\" : \"link\",\n );\n\n for (const [name, value] of assetResourceHostAttributes(resource)) {\n element.setAttribute(name, value === true ? \"\" : value);\n }\n\n return element;\n}\n","import {\n SUSPENSE_CLIENT_MARKER,\n SUSPENSE_COMPLETED_MARKER,\n SUSPENSE_END_MARKER,\n SUSPENSE_PENDING_PREFIX,\n} from \"@bgub/fig/internal\";\nimport type {\n DehydratedSuspenseBoundary,\n DehydratedSuspenseError,\n} from \"@bgub/fig-reconciler\";\n\n// Parsing of the server's Suspense streaming markers (see\n// @bgub/fig/internal suspense-protocol) into dehydrated boundaries, plus the\n// DOM-range helpers that consume them.\n\ntype TextLike = Text | Comment;\n\ninterface SuspenseMarker {\n id: string | null;\n status: DehydratedSuspenseBoundary<Element, TextLike>[\"status\"];\n}\n\nexport function suspenseBoundaryFor(\n node: Element | TextLike,\n): DehydratedSuspenseBoundary<Element, TextLike> | null {\n if (!isComment(node)) return null;\n\n const marker = suspenseMarker(node);\n return marker === null ? null : suspenseBoundary(node, marker);\n}\n\nfunction suspenseBoundary(\n start: TextLike,\n initialMarker: SuspenseMarker,\n): DehydratedSuspenseBoundary<Element, TextLike> | null {\n const end = suspenseBoundaryEnd(start);\n if (end === null) return null;\n return {\n end,\n forceClientRender: false,\n id: initialMarker.id,\n start,\n get error() {\n return suspenseBoundaryError(start);\n },\n get status() {\n return suspenseMarker(start)?.status ?? initialMarker.status;\n },\n };\n}\n\nfunction suspenseMarker(node: unknown): SuspenseMarker | null {\n if (!isComment(node)) return null;\n\n if (node.data === SUSPENSE_COMPLETED_MARKER) {\n return { id: null, status: \"completed\" };\n }\n\n if (node.data === SUSPENSE_CLIENT_MARKER) {\n return { id: null, status: \"client-rendered\" };\n }\n\n const pending = node.data.startsWith(SUSPENSE_PENDING_PREFIX)\n ? node.data.slice(SUSPENSE_PENDING_PREFIX.length)\n : null;\n if (pending !== null && pending !== \"\") {\n return { id: pending, status: \"pending\" };\n }\n return null;\n}\n\nfunction suspenseBoundaryEnd(start: TextLike): TextLike | null {\n let depth = 0;\n\n for (\n let node = start.nextSibling as Element | TextLike | null;\n node !== null;\n node = node.nextSibling as Element | TextLike | null\n ) {\n if (!isComment(node)) continue;\n\n if (suspenseMarker(node) !== null) {\n depth += 1;\n continue;\n }\n\n if (node.data !== SUSPENSE_END_MARKER) continue;\n if (depth === 0) return node;\n depth -= 1;\n }\n\n return null;\n}\n\nfunction suspenseBoundaryError(\n start: TextLike,\n): DehydratedSuspenseError | null {\n const placeholder = start.nextSibling;\n if (!hasDataset(placeholder)) return null;\n\n return {\n digest: placeholder.dataset.dgst,\n message: placeholder.dataset.msg,\n };\n}\n\n// Event-target boundary discovery walks outward from the target instead of\n// searching the tree: at each ancestor level, scanning the preceding siblings\n// right-to-left, an end marker closes over a boundary that sits entirely\n// before the target, so a start marker reached at depth zero is unmatched and\n// its range encloses the target. Passing a returned start marker back in\n// resumes the search at the next enclosing boundary (needed when a marker has\n// no live fiber because it is nested inside an outer dehydrated boundary).\nexport function enclosingSuspenseBoundaryStart(\n target: unknown,\n): TextLike | null {\n if (!isNode(target)) return null;\n\n for (let node: Node | null = target; node !== null; node = node.parentNode) {\n let depth = 0;\n\n for (\n let sibling = node.previousSibling;\n sibling !== null;\n sibling = sibling.previousSibling\n ) {\n if (!isComment(sibling)) continue;\n\n if (sibling.data === SUSPENSE_END_MARKER) {\n depth += 1;\n continue;\n }\n\n if (suspenseMarker(sibling) === null) continue;\n if (depth === 0) return sibling;\n depth -= 1;\n }\n }\n\n return null;\n}\n\nexport function isWithinSuspenseBoundary(\n target: unknown,\n boundary: DehydratedSuspenseBoundary<Element, TextLike>,\n): boolean {\n if (!isNode(target)) return false;\n\n const startParent = boundary.start.parentNode;\n const endParent = boundary.end.parentNode;\n if (startParent === null && endParent === null) return false;\n\n for (let node: Node | null = target; node !== null; node = node.parentNode) {\n if (node === boundary.start || node === boundary.end) return false;\n\n if (startParent !== null && node.parentNode === startParent) {\n return isSiblingAfterStartBeforeEnd(\n node as Element | TextLike,\n boundary.start,\n boundary.end,\n );\n }\n if (\n endParent !== null &&\n endParent !== startParent &&\n node.parentNode === endParent\n ) {\n return isSiblingBeforeEnd(node as Element | TextLike, boundary.end);\n }\n }\n\n return false;\n}\n\nfunction isSiblingAfterStartBeforeEnd(\n node: Element | TextLike,\n start: Element | TextLike,\n end: Element | TextLike,\n): boolean {\n for (\n let sibling: Node | null = node;\n sibling !== null;\n sibling = sibling.previousSibling\n ) {\n if (sibling === start) return true;\n if (sibling === end) return false;\n }\n\n return false;\n}\n\nfunction isSiblingBeforeEnd(\n node: Element | TextLike,\n end: Element | TextLike,\n): boolean {\n for (\n let sibling: Node | null = node;\n sibling !== null;\n sibling = sibling.nextSibling\n ) {\n if (sibling === end) return true;\n }\n\n return false;\n}\n\nexport function removeSuspenseBoundaryRange(\n boundary: DehydratedSuspenseBoundary<Element, TextLike>,\n): void {\n for (let node: Element | TextLike | null = boundary.start; node !== null;) {\n const next = node.nextSibling as Element | TextLike | null;\n removeNode(node);\n if (node === boundary.end) return;\n node = next;\n }\n}\n\nexport function removeNode(node: Element | TextLike): void {\n node.parentNode?.removeChild(node);\n}\n\nfunction isComment(node: unknown): node is Comment {\n return (\n typeof node === \"object\" &&\n node !== null &&\n \"data\" in node &&\n \"nodeType\" in node &&\n node.nodeType === 8\n );\n}\n\nfunction hasDataset(\n node: unknown,\n): node is Element & { dataset: DOMStringMap } {\n return typeof node === \"object\" && node !== null && \"dataset\" in node;\n}\n\nfunction isNode(value: unknown): value is Node {\n return typeof value === \"object\" && value !== null && \"parentNode\" in value;\n}\n","import type { Props } from \"@bgub/fig\";\nimport { VIEW_TRANSITION_PENDING_PROPERTY } from \"@bgub/fig/internal\";\nimport type {\n ViewTransitionCommitResult,\n ViewTransitionHostConfig,\n ViewTransitionMutationResult,\n ViewTransitionSurfaceMeasurement,\n} from \"@bgub/fig-reconciler\";\nimport type { Container } from \"./events.ts\";\n\ninterface RunningViewTransition {\n finished?: Promise<unknown>;\n ready?: Promise<unknown>;\n}\n\ninterface CancellableAnimation {\n cancel(): void;\n}\n\ntype ViewTransitionDocument = Document & {\n startViewTransition?: (\n update: () => void,\n ) => RunningViewTransition | undefined;\n [VIEW_TRANSITION_PENDING_PROPERTY]?: RunningViewTransition | null;\n};\n\ninterface CssGlobal {\n CSS?: {\n escape?: (value: string) => string;\n };\n}\n\nfunction commitViewTransition(\n container: Container,\n prepareSnapshot: () => void,\n mutate: () => ViewTransitionMutationResult,\n cleanup: () => void,\n): ViewTransitionCommitResult {\n const owner = ownerDocument(container) as ViewTransitionDocument;\n const start = owner.startViewTransition;\n if (typeof start !== \"function\") return false;\n\n let didMutate = false;\n let chained = false;\n let failedBeforeMutate = false;\n let restoreRootName: (() => void) | null = null;\n let mutationResult: ViewTransitionMutationResult | null = null;\n\n const run = (): void => {\n prepareSnapshot();\n try {\n const transition = start.call(owner, () => {\n didMutate = true;\n mutationResult = mutate();\n // Before the new capture: when measurement shows every change is\n // contained in a named boundary, drop the root's own snapshot so the\n // page-wide overlay does not swallow pointer events for the\n // animation's duration.\n if (mutationResult.cancelRootSnapshot) {\n restoreRootName = cancelRootViewTransitionName(owner);\n }\n });\n if (transition !== undefined) {\n registerPendingTransition(owner, transition);\n hideCanceledSnapshots(owner, transition, () => mutationResult);\n }\n // Root-name restore waits for the transition to fully settle: putting\n // `view-transition-name: root` back on the live <html> while the\n // transition still runs can re-associate the live root with its\n // (force-hidden) captured group, which paints the page blank for the\n // rest of the animation.\n const settleAfterTransition = transition?.finished ?? transition?.ready;\n const restore = (): void => restoreRootName?.();\n if (settleAfterTransition === undefined) {\n restore();\n cleanup();\n } else {\n (transition?.ready ?? settleAfterTransition).then(cleanup, cleanup);\n settleAfterTransition.then(restore, restore);\n }\n } catch (error) {\n restoreRootName?.();\n if (!didMutate) {\n // A chained run has no caller to report a fallback to and the\n // reconciler stays frozen until mutate runs: commit unanimated.\n // A synchronous run reports `false` so the caller falls back.\n if (chained) {\n didMutate = true;\n mutate();\n } else {\n failedBeforeMutate = true;\n }\n cleanup();\n return;\n }\n cleanup();\n if (!chained) throw error;\n // Chained commit errors were already routed by the reconciler's\n // deferred-commit handling; a residual throw here is a transition\n // failure that must not vanish into the pending promise.\n setTimeout(() => {\n throw error;\n });\n }\n };\n\n // Serialize per document: starting a transition while one is running makes\n // the browser abruptly skip the running animation, and the skipped\n // transition's restore could race this one's old-state capture. The\n // reconciler normally parks eligible commits upstream (render-during-wait\n // via the adapter's suspend hook), so for fig-dom this chain is a fallback\n // for renderers that wire commit without suspend — chaining freezes the root\n // until the previous animation finishes, parking keeps rendering live.\n const pending = owner[VIEW_TRANSITION_PENDING_PROPERTY];\n const pendingSettled = pending?.finished ?? pending?.ready;\n if (pending != null && pendingSettled !== undefined) {\n chained = true;\n pendingSettled.then(run, run);\n return \"deferred\";\n }\n\n run();\n if (failedBeforeMutate) return false;\n return didMutate ? \"committed\" : \"deferred\";\n}\n\n// Remove the root element from the new capture, remembering how to restore\n// the author's inline style afterwards.\nfunction cancelRootViewTransitionName(\n owner: ViewTransitionDocument,\n): () => void {\n const element = owner.documentElement as HTMLElement | null;\n if (element === null) return () => undefined;\n\n const style = element.style as CSSStyleDeclaration & {\n viewTransitionName?: string;\n };\n const previous = style.viewTransitionName ?? \"\";\n style.viewTransitionName = \"none\";\n\n return () => {\n style.viewTransitionName = previous;\n if (element.getAttribute(\"style\") === \"\") element.removeAttribute(\"style\");\n };\n}\n\n// Old snapshots were captured before the update callback ran and cannot be\n// un-captured; once the pseudo tree exists (ready), hide the groups of\n// measurement-canceled boundaries — and the root group plus the\n// ::view-transition overlay when the whole-page snapshot was dropped — with\n// filling zero-duration animations so untouched regions stay interactive\n// while the remaining groups animate. Mirrors React's\n// cancelViewTransitionName / cancelRootViewTransitionName.\nfunction hideCanceledSnapshots(\n owner: ViewTransitionDocument,\n transition: RunningViewTransition,\n getResult: () => ViewTransitionMutationResult | null,\n): void {\n // The filled zero-duration animations outlive their pseudo tree: without\n // an explicit cancel once the transition settles they would apply to the\n // next transition's pseudo tree and hide its groups.\n const hideAnimations: CancellableAnimation[] = [];\n const cancelHideAnimations = (): void => {\n for (const animation of hideAnimations) {\n try {\n animation.cancel();\n } catch {\n // Cancelling a finished pseudo animation is best-effort.\n }\n }\n hideAnimations.length = 0;\n };\n\n const hide = (): void => {\n const result = getResult();\n if (result === null) return;\n if (result.canceledNames.length === 0 && !result.cancelRootSnapshot) {\n return;\n }\n\n const element = owner.documentElement as\n | (HTMLElement & {\n animate?: (\n keyframes: Record<string, unknown>,\n options: Record<string, unknown>,\n ) => unknown;\n })\n | null;\n if (element === null || typeof element.animate !== \"function\") return;\n\n const track = (animation: unknown): void => {\n if (\n typeof (animation as CancellableAnimation | null)?.cancel === \"function\"\n ) {\n hideAnimations.push(animation as CancellableAnimation);\n }\n };\n\n const hideGroup = (name: string): void => {\n track(\n element.animate?.(\n { opacity: [0, 0], pointerEvents: [\"none\", \"none\"] },\n {\n duration: 0,\n fill: \"forwards\",\n pseudoElement: `::view-transition-group(${name})`,\n },\n ),\n );\n };\n\n try {\n for (const name of result.canceledNames) {\n hideGroup(escapeViewTransitionName(name));\n }\n if (result.cancelRootSnapshot) {\n hideGroup(\"root\");\n track(\n element.animate(\n { height: [0, 0], width: [0, 0] },\n {\n duration: 0,\n fill: \"forwards\",\n pseudoElement: \"::view-transition\",\n },\n ),\n );\n }\n } catch {\n // Pseudo-element animation is best-effort: without it the canceled\n // snapshots fall back to the browser's default cross-fade.\n }\n };\n\n const ready = transition.ready ?? transition.finished;\n if (ready === undefined) hide();\n else ready.then(hide, () => undefined);\n\n const settled = transition.finished ?? transition.ready;\n if (settled === undefined) cancelHideAnimations();\n else settled.then(cancelHideAnimations, cancelHideAnimations);\n}\n\nfunction registerPendingTransition(\n owner: ViewTransitionDocument,\n transition: RunningViewTransition,\n): void {\n owner[VIEW_TRANSITION_PENDING_PROPERTY] = transition;\n const release = (): void => {\n if (owner[VIEW_TRANSITION_PENDING_PROPERTY] === transition) {\n owner[VIEW_TRANSITION_PENDING_PROPERTY] = null;\n }\n };\n const settled = transition.finished ?? transition.ready;\n if (settled === undefined) release();\n else settled.then(release, release);\n}\n\n// The reconciler parks eligible commits behind a running transition (the\n// shared per-document mutex — client commits and streaming reveals alike)\n// and re-schedules once it settles. Rendering continues during the park;\n// only the commit waits.\nfunction suspendOnActiveViewTransition(\n container: Container,\n onFinished: () => void,\n): boolean {\n const owner = ownerDocument(container) as ViewTransitionDocument;\n const pending = owner[VIEW_TRANSITION_PENDING_PROPERTY];\n const settled = pending?.finished ?? pending?.ready;\n if (pending == null || settled === undefined) return false;\n\n settled.then(onFinished, onFinished);\n return true;\n}\n\nfunction measureViewTransitionSurface(\n element: Element,\n): ViewTransitionSurfaceMeasurement | null {\n if (typeof element.getBoundingClientRect !== \"function\") return null;\n\n const rect = element.getBoundingClientRect();\n const view = element.ownerDocument?.defaultView ?? null;\n const inViewport =\n view === null\n ? true\n : rect.bottom >= 0 &&\n rect.right >= 0 &&\n rect.top <= view.innerHeight &&\n rect.left <= view.innerWidth;\n let absolutelyPositioned = false;\n try {\n absolutelyPositioned =\n view?.getComputedStyle(element).position === \"absolute\";\n } catch {\n // Detached elements or minimal test environments: assume static\n // positioning, the conservative choice (resizes keep the root snapshot).\n }\n\n return {\n absolutelyPositioned,\n height: rect.height,\n inViewport,\n width: rect.width,\n x: rect.left,\n y: rect.top,\n };\n}\n\nfunction applyViewTransitionName(\n element: Element,\n name: string,\n className: string | null,\n): void {\n const style = (element as HTMLElement).style as CSSStyleDeclaration & {\n viewTransitionClass?: string;\n viewTransitionName?: string;\n };\n\n style.viewTransitionName = escapeViewTransitionName(name);\n if (className !== null) style.viewTransitionClass = className;\n}\n\nfunction restoreViewTransitionName(element: Element, props: Props): void {\n const style = (element as HTMLElement).style as CSSStyleDeclaration & {\n viewTransitionClass?: string;\n viewTransitionName?: string;\n };\n const styleProp = props.style as Record<string, unknown> | undefined;\n const name =\n styleProp?.viewTransitionName ?? styleProp?.[\"view-transition-name\"];\n const className =\n styleProp?.viewTransitionClass ?? styleProp?.[\"view-transition-class\"];\n\n style.viewTransitionName = styleValue(name);\n style.viewTransitionClass = styleValue(className);\n}\n\nfunction ownerDocument(container: Container): Document {\n return \"ownerDocument\" in container && container.ownerDocument !== null\n ? container.ownerDocument\n : document;\n}\n\nfunction escapeViewTransitionName(name: string): string {\n const escape = (globalThis as CssGlobal).CSS?.escape;\n return escape === undefined ? name : escape(name);\n}\n\nfunction styleValue(value: unknown): string {\n if (typeof value === \"string\" || typeof value === \"number\") {\n return String(value).trim();\n }\n\n return \"\";\n}\n\nexport const viewTransitionHostConfig: ViewTransitionHostConfig<\n Container,\n Element\n> = {\n commit: commitViewTransition,\n apply: applyViewTransitionName,\n restore: restoreViewTransitionName,\n measure: measureViewTransitionSurface,\n suspend: suspendOnActiveViewTransition,\n};\n","import {\n createPortalNode,\n type FigNode,\n type FigPortal,\n type Key,\n type Props,\n} from \"@bgub/fig\";\nimport {\n ACTIVITY_TEMPLATE_ATTRIBUTE,\n assetResourceFromHostProps,\n validateInstanceNesting,\n validateTextNesting,\n} from \"@bgub/fig/internal\";\nimport {\n createRenderer,\n type FigRoot,\n type FigRootOptions,\n type HostConfig,\n type RecoverableErrorInfo,\n} from \"@bgub/fig-reconciler\";\nimport {\n acquireDocumentResource,\n adoptDocumentResource,\n releaseDocumentResource,\n updateHoistedResource,\n} from \"./asset-resources.ts\";\nimport { attachSubtree, detachSubtree } from \"./attachment.ts\";\nimport { composeBind, resumeBind, suspendBind } from \"./bind.ts\";\nimport {\n type Container,\n disableRootHydration,\n registerPortalContainer,\n registerRoot,\n removePortalContainer,\n replayQueuedEvents,\n setEventBatching,\n unregisterRoot,\n} from \"./events.ts\";\nimport { hydrateElement, updateElement, updateParentSelect } from \"./props.ts\";\nimport { configureDomRefreshScheduler, type RefreshUpdate } from \"./refresh.ts\";\nimport {\n enclosingSuspenseBoundaryStart,\n isWithinSuspenseBoundary,\n removeNode,\n removeSuspenseBoundaryRange,\n suspenseBoundaryFor,\n} from \"./suspense-markers.ts\";\nimport {\n elementName,\n htmlNamespace,\n isElementNode,\n isEmptyPropValue,\n mathNamespace,\n svgNamespace,\n} from \"./tree.ts\";\nimport { viewTransitionHostConfig } from \"./view-transition.ts\";\n\ntype TextLike = Text | Comment;\ntype RetriableSuspenseMarker = TextLike & { __figRetry?: () => void };\n\ninterface DomRenderer {\n batchedUpdates<T>(this: void, callback: () => T): T;\n createRoot(\n this: void,\n container: Container,\n options?: FigRootOptions,\n ): FigRoot;\n hydrateRoot(\n this: void,\n container: Container,\n children: FigNode,\n options?: FigRootOptions,\n ): FigRoot;\n hydrateTarget(\n this: void,\n container: Container,\n target: unknown,\n priority?: \"default\" | \"continuous\" | \"discrete\",\n ): \"none\" | \"hydrated\" | \"blocked\";\n flushSync<T>(this: void, callback: () => T): T;\n scheduleRefresh(this: void, update: RefreshUpdate): void;\n}\n\ndeclare const __FIG_DEV__: boolean | undefined;\n\nexport { insertAssetResources } from \"./asset-resources.ts\";\nexport type { Bind } from \"./bind.ts\";\nexport {\n type EventCallback,\n type EventDescriptor,\n type EventOptions,\n on,\n} from \"./events.ts\";\nexport type {\n EmptyPropValue,\n HostEvents,\n HostIntrinsicElements,\n HostProps,\n HostStyle,\n} from \"./jsx.ts\";\nexport { composeBind };\n\nconst __DEV__ = typeof __FIG_DEV__ === \"boolean\" ? __FIG_DEV__ : false;\n\nconst hostConfig: HostConfig<Container, Element, TextLike> = {\n createInstance: (type, props, parent) =>\n createDomElement(type, props, parent),\n createTextInstance: (text) => document.createTextNode(text),\n // The dev gates below run at call time (never at module scope, which\n // would throw on import wherever bundler defines don't apply). They must\n // stay in block form — `if (dev) { validate() }` — not early-return form:\n // esbuild only eliminates the constant branch (and with it the dom-nesting\n // module import) at parse time, before symbol retention is decided; code\n // after an `if (prod) return` keeps the import referenced and ships the\n // whole module in production bundles.\n validateInstanceNesting: (type, props, ancestors) => {\n if (__DEV__) {\n // Asset resources hoist to <head>, so their fiber position is not\n // their DOM position; the server exempts them the same way.\n if (assetResourceFromHostProps(type, props) !== null) return;\n validateInstanceNesting(type, ancestors);\n }\n },\n validateTextNesting: (text, ancestors) => {\n if (__DEV__) {\n validateTextNesting(text, ancestors);\n }\n },\n containerType: (container) =>\n isElementNode(container) ? elementName(container) : null,\n appendInitialChild: (parent, child) => {\n parent.appendChild(child);\n // Render-phase assembly: the select is not live yet, so applying its\n // default to options that assemble after it is always safe. Only\n // option-bearing children can change a selection.\n if (isElementNode(child) && optionLike(child)) {\n updateParentSelect(child, true);\n }\n },\n finalizeInitialInstance: (instance, props) =>\n updateElement(instance, {}, props, { initial: true }),\n setTextContent: (instance, text) => {\n if (instance.textContent !== text) instance.textContent = text;\n },\n getFirstHydratableChild: (parent, props) =>\n hydratableFirstChild(parent, props),\n getNextHydratableSibling: (node) =>\n skipTextSeparators(node.nextSibling as Element | TextLike | null),\n canHydrateInstance: (node, type, props) =>\n isHydratableElement(node, type, props),\n canHydrateTextInstance: (node, text, suppressHydrationWarning) =>\n isHydratableText(node) &&\n (suppressHydrationWarning === true || node.nodeValue === text),\n // Hoisted asset resources never appear at their fiber's server position\n // (the server registers them and emits nothing inline): hydration must not\n // match them against the DOM cursor, and commit acquires/releases them in\n // the head registry instead of inserting/removing at the fiber position.\n isHoistedInstance: (type, props) =>\n assetResourceFromHostProps(type, props) !== null,\n commitHoistedInstance: (instance) => acquireDocumentResource(instance),\n removeHoistedInstance: (instance) => releaseDocumentResource(instance),\n updateHoistedInstance: (instance, previousProps, nextProps) =>\n updateHoistedResource(instance, previousProps, nextProps),\n shouldCommitUpdate: (type, _previousProps, nextProps) =>\n shouldRestoreControlledFormState(type, nextProps),\n clearContainer: (container) => {\n let child = container.firstChild as Element | TextLike | null;\n\n while (child !== null) {\n const next = child.nextSibling as Element | TextLike | null;\n detachSubtree(child as Element | Text);\n container.removeChild(child);\n child = next;\n }\n\n // A cleared container (hydration-mismatch recovery) detaches every\n // queued replayable event's target; drain them.\n queueMicrotask(replayQueuedEvents);\n },\n insertBefore: (parent, child, before) => {\n parent.insertBefore(child, before);\n // Live insertion: re-assert a controlled select's value, but never\n // re-apply an uncontrolled default — the user owns the live selection\n // (defaults are mount-time only, matching React).\n if (isElementNode(child) && optionLike(child)) updateParentSelect(child);\n attachSubtree(child as Element | Text);\n },\n removeChild: (parent, child) => {\n detachSubtree(child as Element | Text);\n parent.removeChild(child);\n },\n commitTextUpdate: (text, value) => {\n if (text.nodeValue !== value) text.nodeValue = value;\n },\n commitUpdate: (instance, previousProps, nextProps) =>\n updateElement(instance, previousProps, nextProps),\n commitHydratedInstance: (instance, nextProps) =>\n hydrateElement(instance, nextProps),\n getActivityBoundary: (node) =>\n isActivityTemplate(node) ? (node as Element) : null,\n getFirstActivityHydratable: (boundary) =>\n skipTextSeparators(\n (activityTemplateContent(boundary).firstChild ?? null) as\n | Element\n | TextLike\n | null,\n ),\n commitHydratedActivityBoundary: (boundary) => {\n const parent = boundary.parentNode;\n if (parent === null) return;\n\n const content = activityTemplateContent(boundary);\n while (content.firstChild !== null) {\n parent.insertBefore(content.firstChild, boundary);\n }\n parent.removeChild(boundary);\n },\n hideInstance: (instance) => {\n suspendBind(instance);\n (instance as HTMLElement).style.setProperty(\"display\", \"none\", \"important\");\n },\n unhideInstance: (instance, props) => {\n const style = (props.style ?? {}) as Record<string, unknown>;\n const display = style.display;\n (instance as HTMLElement).style.setProperty(\n \"display\",\n typeof display === \"string\" ? display : \"\",\n );\n resumeBind(instance);\n },\n hideTextInstance: (text) => {\n text.nodeValue = \"\";\n },\n unhideTextInstance: (text, value) => {\n if (text.nodeValue !== value) text.nodeValue = value;\n },\n getSuspenseBoundary: (node) => suspenseBoundaryFor(node),\n getEnclosingSuspenseBoundaryStart: (target) =>\n enclosingSuspenseBoundaryStart(target),\n isTargetWithinSuspenseBoundary: (target, boundary) =>\n isWithinSuspenseBoundary(target, boundary),\n registerSuspenseBoundaryRetry: (boundary, retry) => {\n (boundary.start as RetriableSuspenseMarker).__figRetry = retry;\n },\n commitHydratedSuspenseBoundary: (boundary) => {\n if (boundary.status === \"completed\" && !boundary.forceClientRender) {\n removeNode(boundary.start);\n removeNode(boundary.end);\n } else {\n removeSuspenseBoundaryRange(boundary);\n }\n\n queueMicrotask(replayQueuedEvents);\n },\n removeDehydratedSuspenseBoundary: (boundary) => {\n // The replay pass drops queued events whose targets left the tree with\n // the boundary.\n removeSuspenseBoundaryRange(boundary);\n queueMicrotask(replayQueuedEvents);\n },\n completeRootHydration: (container) => {\n disableRootHydration(container as Container);\n // Non-discrete early events blocked on the pre-commit shell have no\n // boundary hook to re-drain them; root completion is their backstop.\n queueMicrotask(replayQueuedEvents);\n },\n preparePortalContainer: (container, root, logicalParent) => {\n registerPortalContainer(\n container as Container,\n root,\n logicalParent as Container | Element,\n );\n },\n removePortalContainer: (container) => {\n removePortalContainer(container as Container);\n },\n viewTransition: viewTransitionHostConfig,\n};\n\nconst renderer: DomRenderer = createRenderer(hostConfig);\nsetEventBatching(renderer.batchedUpdates);\nconfigureDomRefreshScheduler(renderer.scheduleRefresh);\n\nexport const flushSync = renderer.flushSync;\n\nexport type { FigRoot, FigRootOptions, RecoverableErrorInfo };\n\nexport function createRoot(\n container: Container,\n options?: FigRootOptions,\n): FigRoot {\n const root = renderer.createRoot(container, options);\n registerRoot(container, undefined, (callback) => root.data.run(callback));\n return withRootTeardown(root, container);\n}\n\nexport function hydrateRoot(\n container: Container,\n children: FigNode,\n options?: FigRootOptions,\n): FigRoot {\n // Registration can follow the initial hydration render: it runs\n // synchronously in this task, so no DOM event can dispatch in between.\n const root = renderer.hydrateRoot(container, children, options);\n registerRoot(\n container,\n (target, lane) => renderer.hydrateTarget(container, target, lane),\n (callback) => root.data.run(callback),\n );\n return withRootTeardown(root, container);\n}\n\n// Root event state (hydration listeners, delegated listener maps, queued\n// replayable events) lives outside the reconciler; tear it down with the\n// root so nothing dispatches against or retains an unmounted tree.\nfunction withRootTeardown(root: FigRoot, container: Container): FigRoot {\n return {\n ...root,\n unmount: () => {\n root.unmount();\n unregisterRoot(container);\n },\n };\n}\n\nexport function createPortal(\n children: FigNode,\n container: Container,\n key: Key | null = null,\n): FigPortal {\n return createPortalNode(children, container, key);\n}\n\n// Real templates hold children in a content fragment; test doubles hold\n// them directly.\nfunction activityTemplateContent(boundary: Element): ParentNode {\n return \"content\" in boundary\n ? (boundary.content as ParentNode)\n : (boundary as ParentNode);\n}\n\nfunction isActivityTemplate(node: Element | TextLike): boolean {\n return (\n elementName(node) === \"template\" &&\n \"getAttribute\" in node &&\n node.getAttribute(ACTIVITY_TEMPLATE_ATTRIBUTE) !== null\n );\n}\n\nfunction isHydratableElement(\n node: Element | TextLike,\n type: string,\n props: Props,\n): boolean {\n if (!isElementNode(node) || !(\"setAttribute\" in node)) return false;\n if (elementName(node) !== type.toLowerCase()) return false;\n return hasMatchingUnsafeHTML(node, props);\n}\n\nfunction createDomElement(\n type: string,\n props: Props,\n parent: Container | Element,\n): Element {\n const resource = adoptDocumentResource(type, props);\n if (resource !== null) return resource;\n\n const namespace = namespaceFor(type, parent);\n return namespace === htmlNamespace\n ? document.createElement(type)\n : document.createElementNS(namespace, type);\n}\n\nfunction namespaceFor(type: string, parent: Container | Element): string {\n const normalizedType = type.toLowerCase();\n if (normalizedType === \"svg\") return svgNamespace;\n if (normalizedType === \"math\") return mathNamespace;\n\n return \"namespaceURI\" in parent && elementName(parent) !== \"foreignobject\"\n ? (parent.namespaceURI ?? htmlNamespace)\n : htmlNamespace;\n}\n\nfunction hydratableFirstChild(\n parent: Container | Element,\n props?: Props,\n): Element | TextLike | null {\n if (props !== undefined && unsafeHTMLValue(props) !== null) return null;\n\n if (\n elementName(parent) === \"textarea\" &&\n props !== undefined &&\n hasManagedTextareaContent(props)\n ) {\n return null;\n }\n\n return skipTextSeparators(parent.firstChild as Element | TextLike | null);\n}\n\n// The server writes a `<!--,-->` comment between adjacent text nodes that\n// come from different fibers (browser parsing would otherwise merge them\n// into a single DOM text node while the client keeps one text fiber each —\n// see TEXT_SEPARATOR in @bgub/fig-server). The hydration cursor steps over\n// separators when advancing; only comments with exactly this data are\n// skipped, so the fig:suspense marker comments are never affected.\nconst TEXT_SEPARATOR_DATA = \",\";\n\nfunction skipTextSeparators(\n node: Element | TextLike | null,\n): Element | TextLike | null {\n let current = node;\n while (current !== null && isTextSeparator(current)) {\n current = current.nextSibling as Element | TextLike | null;\n }\n return current;\n}\n\nfunction isTextSeparator(node: Element | TextLike): boolean {\n return (\n \"nodeType\" in node &&\n node.nodeType === 8 &&\n (node as Comment).data === TEXT_SEPARATOR_DATA\n );\n}\n\nfunction hasManagedTextareaContent(props: Props): boolean {\n return props.value !== undefined || props.defaultValue !== undefined;\n}\n\nfunction unsafeHTMLValue(props: Props): unknown {\n return isEmptyPropValue(props.unsafeHTML) ? null : props.unsafeHTML;\n}\n\nfunction hasMatchingUnsafeHTML(element: Element, props: Props): boolean {\n const expected = unsafeHTMLValue(props);\n if (expected === null) return true;\n return typeof expected !== \"string\" || \"innerHTML\" in element;\n}\n\nfunction isHydratableText(node: Element | TextLike): boolean {\n if (\"nodeType\" in node && node.nodeType !== 3) return false;\n return !(\"setAttribute\" in node) && \"nodeValue\" in node;\n}\n\nfunction optionLike(element: Element): boolean {\n const name = elementName(element);\n return name === \"option\" || name === \"optgroup\";\n}\n\nfunction shouldRestoreControlledFormState(type: string, props: Props): boolean {\n return (\n (type === \"input\" || type === \"textarea\" || type === \"select\") &&\n (props.value !== undefined || props.checked !== undefined)\n );\n}\n\nexport type { Container };\n"],"mappings":"qoBAIA,SAAgB,EACd,EACA,EACM,CACN,GAAI,EAAc,CAAI,GAAG,EAAQ,CAAI,EACjC,IAAE,eAAgB,IAAS,EAAK,aAAe,MAEnD,IAAK,IAAM,KAAS,MAAM,KAAK,EAAK,UAAU,EAC5C,EAAoB,EAAyB,CAAO,CAExD,CAEA,SAAgB,EAAc,EAAgC,CAC5D,OACE,OAAO,GAAS,YAChB,GACA,aAAc,GACd,EAAK,WAAa,CAEtB,CAEA,SAAgB,EAAY,EAAuB,CAGjD,OAFK,EAAc,CAAI,EAEhB,cAAe,GAAQ,OAAO,EAAK,WAAc,SACpD,EAAK,UAAU,YAAY,EAC3B,YAAa,GAAQ,OAAO,EAAK,SAAY,SAC3C,EAAK,QAAQ,YAAY,EACzB,GAN2B,EAOnC,CAEA,SAAgB,GAAc,EAA2B,CACvD,MACE,EAAE,iBAAkB,IACpB,EAAQ,eAAiB,MACzB,EAAQ,eAAA,8BAEZ,CAOA,SAAgB,EAA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CAEA,SAAS,GAAgB,EAAuB,CAC9C,OAAO,EAAiB,EAAM,UAAU,EAAI,KAAO,EAAM,UAC3D,CAEA,SAAS,GAAsB,EAAkB,EAAuB,CACtE,IAAM,EAAW,GAAgB,CAAK,EAEtC,OADI,IAAa,MACV,OAAO,GAAa,UAAY,cAAe,CACxD,CAEA,SAAS,GAAiB,EAAmC,CAE3D,MADI,aAAc,GAAQ,EAAK,WAAa,EAAU,GAC/C,EAAE,iBAAkB,IAAS,cAAe,CACrD,CAEA,SAAS,GAAW,EAA2B,CAC7C,IAAM,EAAO,EAAY,CAAO,EAChC,OAAO,IAAS,UAAY,IAAS,UACvC,CAEA,SAAS,GAAiC,EAAc,EAAuB,CAC7E,OACG,IAAS,SAAW,IAAS,YAAc,IAAS,YACpD,EAAM,QAAU,IAAA,IAAa,EAAM,UAAY,IAAA,GAEpD"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/payload-decoder.ts","../src/payload-key.ts","../src/payload-component.ts","../src/index.ts"],"sourcesContent":["import type { AwaitedFigNode, DataResourceLoadContext } from \"@bgub/fig\";\nimport {\n assertPayloadCodecMatches,\n jsonPayloadCodec,\n loadContextCapabilities,\n} from \"@bgub/fig/internal\";\nimport {\n decodePayloadStream,\n type PayloadDecodeOptions,\n} from \"@bgub/fig/payload\";\nimport { insertAssetResources } from \"./asset-resources.ts\";\n\ndeclare const __FIG_DEV__: boolean | undefined;\n\nconst __DEV__ = typeof __FIG_DEV__ === \"boolean\" ? __FIG_DEV__ : false;\nconst noop = (): void => undefined;\n\nexport type PayloadDecoderOptions = Pick<\n PayloadDecodeOptions,\n \"prepareAssets\" | \"resolveClientReference\" | \"retainAssets\"\n>;\n\n/**\n * Decodes a validated Payload response within one data-resource generation.\n * The root becomes the entry value, streamed holes keep filling for the\n * generation's lifetime, `data` rows hydrate through its guarded capability,\n * and discovered assets enter the document with dependent reveal gates.\n */\nexport async function decodePayloadResponse(\n response: Response,\n context: DataResourceLoadContext,\n options: PayloadDecoderOptions = {},\n): Promise<AwaitedFigNode> {\n const { signal } = context;\n if (signal.aborted) {\n await response.body?.cancel().catch(noop);\n throw abortReason(signal);\n }\n if (!response.ok) {\n await response.body?.cancel().catch(noop);\n throw new Error(`Payload request failed with status ${response.status}.`);\n }\n const body = response.body;\n if (body === null) {\n throw new Error(\"Payload response did not include a body.\");\n }\n try {\n assertPayloadCodecMatches(\n jsonPayloadCodec,\n response.headers.get(\"content-type\"),\n );\n } catch (error) {\n await body.cancel().catch(noop);\n throw error;\n }\n\n const capabilities = loadContextCapabilities(context);\n return decodePayloadStream(body, {\n // Absent outside a data store: data rows are ignored rather than hydrated.\n hydrate: capabilities?.hydrate,\n onHoleError: capabilities?.attributeError,\n // Post-root failures surface through the rejected holes they strand;\n // observing the stream end keeps a failure that no longer has a pending\n // slot from being silently discarded in development.\n onStreamDone: (result) => {\n if (__DEV__ && result.status === \"failed\") {\n console.error(\n \"Payload decode failed after its root value published:\",\n result.error,\n );\n }\n },\n prepareAssets:\n options.prepareAssets ?? ((assets) => insertAssetResources(assets)),\n retainAssets: options.retainAssets,\n resolveClientReference: options.resolveClientReference,\n signal,\n });\n}\n\nfunction abortReason(signal: AbortSignal): unknown {\n return signal.reason ?? new Error(\"Payload request aborted.\");\n}\n","import type { DataResourceKeyInput } from \"@bgub/fig\";\n\nexport function encodePayloadKey(value: unknown): DataResourceKeyInput {\n const ids = new WeakMap<object, number>();\n let nextId = 1;\n\n function encode(value: unknown): DataResourceKeyInput {\n if (value === null) return null;\n if (value === undefined) return [\"undefined\"];\n if (typeof value === \"string\" || typeof value === \"boolean\") return value;\n if (typeof value === \"number\") {\n if (Number.isNaN(value)) return [\"number\", \"NaN\"];\n if (value === Infinity) return [\"number\", \"Infinity\"];\n if (value === -Infinity) return [\"number\", \"-Infinity\"];\n return Object.is(value, -0) ? [\"number\", \"-0\"] : value;\n }\n if (typeof value === \"bigint\") return [\"bigint\", value.toString()];\n if (typeof value === \"symbol\") {\n const key = Symbol.keyFor(value);\n if (key === undefined) {\n throw new Error(\"Only global Symbol.for symbols can be serialized.\");\n }\n return [\"symbol\", key];\n }\n if (typeof value === \"function\") {\n throw new Error(\"Functions cannot be serialized into the payload.\");\n }\n if (value instanceof Date) {\n const json = value.toJSON();\n if (json === null) {\n throw new Error(\"Invalid Date values cannot be serialized.\");\n }\n return [\"date\", json];\n }\n\n const existing = ids.get(value);\n if (existing !== undefined) return [\"ref\", existing];\n const id = nextId++;\n ids.set(value, id);\n\n if (Array.isArray(value)) {\n return [\"array\", id, value.map(encode)];\n }\n if (value instanceof Map) {\n return [\n \"map\",\n id,\n Array.from(value, ([key, item]) => [encode(key), encode(item)]),\n ];\n }\n if (value instanceof Set) {\n return [\"set\", id, Array.from(value, encode)];\n }\n\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) {\n throw new Error(\n `Cannot serialize ${prototype?.constructor?.name ?? \"object\"} into the payload.`,\n );\n }\n const record = value as Record<string, unknown>;\n return [\n \"object\",\n id,\n Object.keys(record)\n .sort()\n .map((key) => [key, encode(record[key])]),\n ];\n }\n\n return encode(value);\n}\n","import {\n type AwaitedFigNode,\n dataResource,\n type DataResource,\n type DataResourceKey,\n type DataResourceKeyInput,\n type FigNode,\n readData,\n} from \"@bgub/fig\";\nimport { loadContextCapabilities } from \"@bgub/fig/internal\";\nimport {\n decodePayloadResponse,\n type PayloadDecoderOptions,\n} from \"./payload-decoder.ts\";\nimport { encodePayloadKey } from \"./payload-key.ts\";\n\nexport type PayloadSource =\n | Response\n | {\n contentType: string;\n stream: ReadableStream<Uint8Array>;\n };\n\nexport interface PayloadComponentLoadContext {\n key: DataResourceKey;\n signal: AbortSignal;\n}\n\nexport interface PayloadComponentLoader<\n TProps extends object,\n> extends PayloadDecoderOptions {\n (\n props: TProps,\n context: PayloadComponentLoadContext,\n ): PayloadSource | PromiseLike<PayloadSource>;\n}\n\nexport interface PayloadComponentOptions<\n TProps extends object,\n> extends PayloadDecoderOptions {\n cacheKey?: (props: TProps) => DataResourceKeyInput;\n key: DataResourceKey;\n load: PayloadComponentLoader<TProps>;\n}\n\nexport interface PayloadComponent<TProps extends object> extends DataResource<\n [TProps],\n AwaitedFigNode\n> {\n (props: TProps & { children?: FigNode }): FigNode;\n}\n\n/**\n * Creates a renderable Payload tree backed by Fig's ordinary data store.\n */\nexport function createPayloadComponent<TProps extends object>(\n options: PayloadComponentOptions<TProps>,\n): PayloadComponent<TProps> {\n const key = (props: TProps): DataResourceKey => {\n const serialized = serializedProps(props);\n return [\n ...options.key,\n options.cacheKey === undefined ? serialized : options.cacheKey(props),\n ];\n };\n const resource = dataResource<[TProps], AwaitedFigNode>({\n debugArgs: options.cacheKey === undefined ? undefined : serializedProps,\n key,\n load: async (props, context) => {\n const source = await options.load(props, {\n key: loadContextCapabilities(context)?.key ?? key(props),\n signal: context.signal,\n });\n const response =\n source instanceof Response\n ? source\n : new Response(source.stream, {\n headers: { \"content-type\": source.contentType },\n });\n return decodePayloadResponse(response, context, {\n prepareAssets: options.prepareAssets ?? options.load.prepareAssets,\n resolveClientReference:\n options.resolveClientReference ?? options.load.resolveClientReference,\n retainAssets: options.retainAssets ?? options.load.retainAssets,\n });\n },\n });\n\n const component: PayloadComponent<TProps> = Object.assign(\n function PayloadComponent(props: TProps & { children?: FigNode }): FigNode {\n rejectChildren(props);\n return readData(component, props);\n },\n resource,\n );\n Object.defineProperty(component, \"displayName\", {\n configurable: true,\n value: `Payload(${options.key[0]})`,\n });\n\n return component;\n}\n\nfunction serializedProps<TProps extends object>(\n props: TProps,\n): DataResourceKeyInput {\n rejectChildren(props);\n return encodePayloadKey(props);\n}\n\nfunction rejectChildren(props: object): void {\n if (Object.hasOwn(props, \"children\")) {\n throw new Error(\"Payload components do not accept children.\");\n }\n}\n","import type { FigNode, FigPortal, Key } from \"@bgub/fig\";\nimport { createPortalNode } from \"@bgub/fig/internal\";\nimport type {\n FigRoot,\n FigRootOptions,\n RecoverableErrorInfo,\n} from \"@bgub/fig-reconciler\";\nimport { composeBind } from \"./bind.ts\";\nimport {\n type EventCallback,\n type EventOptions,\n on,\n} from \"./event-descriptor.ts\";\nimport { type Container, registerRoot, unregisterRoot } from \"./events.ts\";\nimport { domRenderer } from \"./renderer.ts\";\n\nexport { insertAssetResources } from \"./asset-resources.ts\";\nexport type { Bind } from \"./bind.ts\";\nexport { composeBind };\nexport { type EventCallback, type EventOptions, on };\nexport type {\n EmptyPropValue,\n HostIntrinsicElements,\n HostProps,\n HostStyle,\n} from \"./jsx.ts\";\nexport {\n createPayloadComponent,\n type PayloadComponent,\n type PayloadComponentLoadContext,\n type PayloadComponentLoader,\n type PayloadComponentOptions,\n type PayloadSource,\n} from \"./payload-component.ts\";\n\nexport type { Container, FigRoot, FigRootOptions, RecoverableErrorInfo };\n\nexport const flushSync = domRenderer.flushSync;\n\nexport function createRoot(\n container: Container,\n options?: FigRootOptions,\n): FigRoot {\n const root = domRenderer.createRoot(container, options);\n registerRoot(container, { run: (callback) => root.data.run(callback) });\n return withEventTeardown(root, container);\n}\n\nexport function hydrateRoot(\n container: Container,\n children: FigNode,\n options?: FigRootOptions,\n): FigRoot {\n const root = domRenderer.hydrateRoot(container, children, options);\n registerRoot(container, {\n hydrate: (target, priority) =>\n domRenderer.hydrateTarget(container, target, priority),\n run: (callback) => root.data.run(callback),\n });\n return withEventTeardown(root, container);\n}\n\nexport function createPortal(\n children: FigNode,\n container: Container,\n key: Key | null = null,\n): FigPortal<Container> {\n return createPortalNode(children, container, key);\n}\n\n// Event routing lives outside the reconciler, so root teardown owns both.\nfunction withEventTeardown(root: FigRoot, container: Container): FigRoot {\n return {\n ...root,\n unmount: () => {\n root.unmount();\n unregisterRoot(container);\n },\n };\n}\n"],"mappings":"gUAeA,MAAM,MAAmB,IAAA,GAazB,eAAsB,EACpB,EACA,EACA,EAAiC,CAAC,EACT,CACzB,GAAM,CAAE,UAAW,EACnB,GAAI,EAAO,QAET,MADA,MAAM,EAAS,MAAM,OAAO,CAAC,CAAC,MAAM,CAAI,EA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EACvD,IAAM,GAAa,EAAK,KAAK,IAAI,CAAQ,CAC3C,CAAC,EACM,EAAkB,EAAM,CAAS,CAC1C,CAEA,SAAgB,EACd,EACA,EACA,EAAkB,KACI,CACtB,OAAO,EAAiB,EAAU,EAAW,CAAG,CAClD,CAGA,SAAS,EAAkB,EAAe,EAA+B,CACvE,MAAO,CACL,GAAG,EACH,YAAe,CACb,EAAK,QAAQ,EACb,EAAe,CAAS,CAC1B,CACF,CACF"}
@@ -1,30 +1,8 @@
1
- import { FigNode, Key } from "@bgub/fig";
2
- import "@bgub/fig-reconciler";
1
+ import { FigNode, Key, MixinDescriptor, MixinInput } from "@bgub/fig";
3
2
  //#region src/bind.d.ts
4
- type Bind<T extends Element = Element> = (node: T, signal: AbortSignal) => void;
3
+ type Bind<T extends Element = Element> = (node: T, signal: AbortSignal) => undefined;
5
4
  declare function composeBind<T extends Element = Element>(...binds: Array<Bind<T> | false | null | undefined>): Bind<T>;
6
5
  //#endregion
7
- //#region src/events.d.ts
8
- type Container = Element | DocumentFragment;
9
- type EventOptions = Pick<AddEventListenerOptions, "capture" | "passive">;
10
- type EventCallback<E extends Event = Event> = (event: E, signal: AbortSignal) => void;
11
- interface EventDescriptor<E extends Event = Event> {
12
- readonly $$typeof: symbol;
13
- readonly type: string;
14
- readonly callback: EventCallback<E>;
15
- readonly options?: EventOptions;
16
- }
17
- /**
18
- * Declares a listener for the `events` prop. Events keep their native
19
- * semantics: bubbling events are delegated through the Fig tree (including
20
- * portals), while non-bubbling events — `focus` and `blur` included — attach
21
- * directly to the element and fire only there. Fig does not emulate React's
22
- * bubbling `focus`/`blur`; to observe focus changes from an ancestor, use
23
- * the platform's bubbling variants, `focusin` and `focusout`.
24
- */
25
- declare function on<K extends keyof HTMLElementEventMap>(type: K, callback: EventCallback<HTMLElementEventMap[K]>, options?: EventOptions): EventDescriptor<HTMLElementEventMap[K]>;
26
- declare function on<E extends Event = Event>(type: string, callback: EventCallback<E>, options?: EventOptions): EventDescriptor<E>;
27
- //#endregion
28
6
  //#region src/jsx-attributes.generated.d.ts
29
7
  type HtmlGlobalAttributeName = "accesskey" | "autocapitalize" | "autocorrect" | "autofocus" | "class" | "contenteditable" | "dir" | "draggable" | "enterkeyhint" | "exportparts" | "hidden" | "id" | "inert" | "inputmode" | "is" | "itemid" | "itemprop" | "itemref" | "itemscope" | "itemtype" | "lang" | "nonce" | "part" | "popover" | "slot" | "spellcheck" | "style" | "tabindex" | "title" | "translate" | "writingsuggestions";
30
8
  interface HtmlAttributeNameByTag {
@@ -208,12 +186,11 @@ interface SvgAttributeNameByTag {
208
186
  type EmptyPropValue = false | null | undefined;
209
187
  type AttributeValue = string | number | true | EmptyPropValue;
210
188
  type HostStyle = Readonly<Record<string, string | EmptyPropValue>>;
211
- type HostEvents = ReadonlyArray<EventDescriptor<any> | EmptyPropValue>;
212
189
  interface FigHostProps<E extends Element> {
213
190
  bind?: Bind<E> | EmptyPropValue;
214
191
  children?: FigNode;
215
- events?: HostEvents | EmptyPropValue;
216
192
  key?: Key | null;
193
+ mix?: MixinInput;
217
194
  style?: HostStyle | EmptyPropValue;
218
195
  suppressHydrationWarning?: boolean | null;
219
196
  unsafeHTML?: string | EmptyPropValue;
@@ -256,7 +233,7 @@ type HtmlHostProps<Tag extends string, E extends Element> = HostProps<E, Tag ext
256
233
  type SvgHostProps<Tag extends string, E extends Element> = HostProps<E, Tag extends keyof SvgAttributeNameByTag ? SvgAttributes<Tag> : SvgGlobalAttributeName | FigGlobalAttributeName | SvgLegacyAttributeName>;
257
234
  type OpenHtmlHostProps<E extends Element> = HostProps<E, HtmlGlobalAttributeName | FigGlobalAttributeName>;
258
235
  interface OpenHostProps<E extends Element> extends FigHostProps<E>, ReactHabitTraps {
259
- [attribute: string]: FigNode | HostStyle | HostEvents | Bind<E>;
236
+ [attribute: string]: FigNode | HostStyle | MixinDescriptor | ReadonlyArray<MixinInput> | 0n | Bind<E>;
260
237
  }
261
238
  //#endregion
262
239
  //#region src/jsx.d.ts
@@ -267,4 +244,4 @@ type HostIntrinsicElements = HtmlHostPropsByTag<HTMLElementTagNameMap> & SvgHost
267
244
  [customElement: `${string}-${string}`]: OpenHostProps<HTMLElement>;
268
245
  };
269
246
  //#endregion
270
- export { HostStyle as a, EventDescriptor as c, Bind as d, composeBind as f, HostProps as i, EventOptions as l, EmptyPropValue as n, Container as o, HostEvents as r, EventCallback as s, HostIntrinsicElements as t, on as u };
247
+ export { Bind as a, HostStyle as i, EmptyPropValue as n, composeBind as o, HostProps as r, HostIntrinsicElements as t };
@@ -1,4 +1,4 @@
1
- import { t as HostIntrinsicElements } from "./jsx-C3Y2wps3.js";
1
+ import { t as HostIntrinsicElements } from "./jsx-C3owhMDw.js";
2
2
  import { FigNode, Key } from "@bgub/fig";
3
3
  import { Fragment, jsx, jsxDEV, jsxs } from "@bgub/fig/jsx-runtime";
4
4
  //#region src/jsx-runtime.d.ts
@@ -0,0 +1,2 @@
1
+ let e=null,t=null;function n(n){if(e=n,t!==null){let e=t;t=null;for(let t of e)n(t)}}function r(n){if(e===null){(t??=[]).push(n);return}e(n)}export{r as n,n as t};
2
+ //# sourceMappingURL=refresh-internal-B05aFp_T.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refresh-internal-B05aFp_T.js","names":[],"sources":["../src/refresh-internal.ts"],"sourcesContent":["import type { RefreshUpdate } from \"@bgub/fig-reconciler/refresh\";\n\nlet scheduleDomRefresh: ((update: RefreshUpdate) => void) | null = null;\n\n// Updates that arrive before the @bgub/fig-dom main entry has evaluated (it\n// configures the scheduler as a module side effect). A code-split app can load\n// this entry first, and dropping those updates would silently skip a refresh.\nlet pendingUpdates: RefreshUpdate[] | null = null;\n\nexport function configureDomRefreshScheduler(\n scheduleRefresh: (update: RefreshUpdate) => void,\n): void {\n scheduleDomRefresh = scheduleRefresh;\n\n if (pendingUpdates !== null) {\n const updates = pendingUpdates;\n pendingUpdates = null;\n for (const update of updates) scheduleRefresh(update);\n }\n}\n\nexport function scheduleRefresh(update: RefreshUpdate): void {\n if (scheduleDomRefresh === null) {\n (pendingUpdates ??= []).push(update);\n return;\n }\n\n scheduleDomRefresh(update);\n}\n"],"mappings":"AAEA,IAAI,EAA+D,KAK/D,EAAyC,KAE7C,SAAgB,EACd,EACM,CAGN,GAFA,EAAqB,EAEjB,IAAmB,KAAM,CAC3B,IAAM,EAAU,EAChB,EAAiB,KACjB,IAAK,IAAM,KAAU,EAAS,EAAgB,CAAM,CACtD,CACF,CAEA,SAAgB,EAAgB,EAA6B,CAC3D,GAAI,IAAuB,KAAM,EAC9B,IAAmB,CAAC,EAAA,CAAG,KAAK,CAAM,EACnC,MACF,CAEA,EAAmB,CAAM,CAC3B"}
package/dist/refresh.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { RefreshFamily, RefreshUpdate } from "@bgub/fig-reconciler/refresh";
2
- //#region src/refresh.d.ts
3
- declare function configureDomRefreshScheduler(scheduleRefresh: (update: RefreshUpdate) => void): void;
4
- declare function scheduleRefresh(update: RefreshUpdate): void;
1
+ import { RefreshFamily, RefreshUpdate, RefreshUpdate as RefreshUpdate$1 } from "@bgub/fig-reconciler/refresh";
2
+ //#region src/refresh-internal.d.ts
3
+ declare function scheduleRefresh(update: RefreshUpdate$1): void;
5
4
  //#endregion
6
- export { type RefreshFamily, type RefreshUpdate, configureDomRefreshScheduler, scheduleRefresh };
5
+ export { type RefreshFamily, type RefreshUpdate, scheduleRefresh };
package/dist/refresh.js CHANGED
@@ -1,2 +1 @@
1
- let e=null,t=null;function n(n){if(e=n,t!==null){let e=t;t=null;for(let t of e)n(t)}}function r(n){if(e===null){(t??=[]).push(n);return}e(n)}export{n as configureDomRefreshScheduler,r as scheduleRefresh};
2
- //# sourceMappingURL=refresh.js.map
1
+ import{n as e}from"./refresh-internal-B05aFp_T.js";export{e as scheduleRefresh};
@@ -0,0 +1,2 @@
1
+ import{t as e}from"./refresh-internal-B05aFp_T.js";import{ACTIVITY_TEMPLATE_ATTRIBUTE as t,EARLY_EVENT_HANDLER_PROPERTY as n,EARLY_EVENT_QUEUE_PROPERTY as r,HYDRATION_SKIP_ATTRIBUTE as i,REPLAYABLE_EVENT_TYPES as a,SUSPENSE_CLIENT_MARKER as o,SUSPENSE_COMPLETED_MARKER as s,SUSPENSE_END_MARKER as c,SUSPENSE_PENDING_PREFIX as l,TEXT_SEPARATOR_DATA as u,assetResourceFromHostAttributes as ee,assetResourceFromHostProps as d,assetResourceHostAttributes as f,assetResourceKey as p,isFigAssetResource as te,markClientOnlyHostBehavior as ne,mixinSlot as re}from"@bgub/fig/internal";import{createMixin as ie}from"@bgub/fig";import{createRenderer as ae,runWithEventPriority as oe}from"@bgub/fig-reconciler";function se(e,t){if(!m(e))return;let n=[];ce(e,n);for(let e of n)t(e)}function ce(e,t){t.push(e);for(let n=e.firstChild;n!==null;n=n.nextSibling)m(n)&&ce(n,t)}function m(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===1}function h(e){return m(e)?`localName`in e&&typeof e.localName==`string`?e.localName.toLowerCase():`tagName`in e&&typeof e.tagName==`string`?e.tagName.toLowerCase():``:``}function le(e){return e.namespaceURI===null||e.namespaceURI===`http://www.w3.org/1999/xhtml`}function g(e){return typeof e==`object`&&e&&`parentNode`in e?e.parentNode:null}function _(e){return e==null||e===!1}const v=new WeakMap,y=new WeakSet;function ue(...e){let t=e.filter(e=>typeof e==`function`);return(e,n)=>{for(let r of t)r(e,n)}}function de(e,t){let n=ge(t),r=v.get(e);if(n===null){r!==void 0&&x(r),v.delete(e);return}if(r===void 0){let t={callback:n,controller:null,strictRan:!1};v.set(e,t),b(e,t)}else r.callback!==n&&(x(r),r.callback=n,b(e,r))}function fe(e){let t=v.get(e);t!==void 0&&b(e,t)}function pe(e){y.add(e);let t=v.get(e);t!==void 0&&x(t)}function me(e){y.delete(e);let t=v.get(e);t!==void 0&&b(e,t)}function he(e){let t=v.get(e);t!==void 0&&(x(t),v.delete(e))}function b(e,t){t.controller!==null||e.parentNode===null||y.has(e)||(t.controller=new AbortController,t.callback(e,t.controller.signal))}function x(e){e.controller?.abort(),e.controller=null}function ge(e){if(_(e))return null;if(typeof e==`function`)return e;throw Error(`The bind prop must be a function.`)}const S=Symbol.for(`fig.native-event-descriptors`),_e=ie((e,t,n,r)=>{ne(e,`on()`);let i=e.props,a=i[S];a===void 0&&(a=[],Object.defineProperty(i,S,{configurable:!0,value:a})),a.push({callback:n,options:r,slot:re(e),type:t})});function ve(e,t,n){return _e(e,t,n)}const ye=[];function be(e){return e[S]??ye}function xe(e,t,n){let r=C(e,`currentTarget`,{value:t});try{return n(e)}finally{r()}}function Se(e,t,n){let r={immediateStopped:!1,stopped:!t&&e.cancelBubble===!0},i=Ce(e,`stopPropagation`,()=>{r.stopped=!0}),a=Ce(e,`stopImmediatePropagation`,()=>{r.stopped=!0,r.immediateStopped=!0}),o=C(e,`cancelBubble`,{get:()=>r.stopped,set(e){e===!0&&(r.stopped=!0)}});try{return n(r)}finally{o(),a(),i(),r.stopped&&(e.cancelBubble=!0)}}function Ce(e,t,n){let r=Reflect.get(e,t);return typeof r==`function`?C(e,t,{value(){n(),r.call(e)}}):we}function C(e,t,n){let r=Object.getOwnPropertyDescriptor(e,t);return Reflect.defineProperty(e,t,{configurable:!0,...n})?r===void 0?()=>{Reflect.deleteProperty(e,t)}:()=>{Reflect.defineProperty(e,t,r)}:we}function we(){}const w=new WeakMap,T=new WeakMap,Te=new WeakMap,E=[],Ee=new Set(a),De=new Set([`beforeinput`,`blur`,`change`,`click`,`contextmenu`,`dblclick`,`focus`,`focusin`,`focusout`,`input`,`keydown`,`keyup`,`mousedown`,`mouseup`,`pointerdown`,`pointerup`,`submit`,`touchend`,`touchstart`]),Oe=new Set([`drag`,`dragover`,`mousemove`,`pointermove`,`scroll`,`touchmove`,`wheel`]),ke=new Set([...De,...Oe,`mouseenter`,`mouseleave`]),Ae=new Set(`abort.blur.cancel.canplay.canplaythrough.close.durationchange.emptied.encrypted.ended.error.focus.invalid.load.loadeddata.loadedmetadata.loadstart.mouseenter.mouseleave.pause.play.playing.pointerenter.pointerleave.progress.ratechange.resize.scroll.scrollend.seeked.seeking.stalled.suspend.timeupdate.toggle.volumechange.waiting`.split(`.`));let je=e=>e();function Me(e){je=e}function Ne(e,t){let n=D(e);n.run=t.run,t.hydrate!==void 0&&(n.hydrate=t.hydrate,Ke(e,n),Fe(e))}const Pe=new WeakMap;function Fe(e){let t=e.ownerDocument??e,i=Pe.get(t);if(i===void 0){let e=t[r];if(!Array.isArray(e))return;let o=t[n];if(typeof o==`function`&&typeof t.removeEventListener==`function`)for(let e of a)t.removeEventListener(e,o,!0);delete t[r],delete t[n],i=e,Pe.set(t,i)}let o=!1;for(let t=0;t<i.length;){let n=i[t];if(Ee.has(n.type)&&L(e,n.target)){i.splice(t,1),Je(e,n.type,n),o=!0;continue}t+=1}o&&queueMicrotask(k)}function Ie(e){let t=T.get(e);if(t!==void 0){Le(e);for(let n of t.listeners.values())e.removeEventListener(n.type,n.listener,n.capture);Re(e),T.delete(e);for(let t=E.length-1;t>=0;--t)E[t].root===e&&E.splice(t,1)}}function Le(e){let t=T.get(e);if(!(t===void 0||t.run===null)){t.hydrate=null;for(let[n,r]of t.hydrationListeners??[])e.removeEventListener(n,r,!0);t.hydrationListeners=null}}function Re(e){for(let t of T.get(e)?.portals??[])Re(t),O(t)}function D(e){let t=T.get(e);return t===void 0&&(t={hydrate:null,hydrationListeners:null,listeners:new Map,portalOwner:null,portals:null,run:null},T.set(e,t)),t}function ze(e,t){let n=w.get(e)??[];if(n.length===0&&t.length===0)return;let r=new Map;for(let e of n)r.set(e.slot,e);let i=[],a=null;for(let n of t){let t=n.options?.capture===!0,o=n.options?.passive===!0,s=r.get(n.slot);r.delete(n.slot),s===void 0||s.type!==n.type||s.capture!==t||s.passive!==o?(a??=He(e),s!==void 0&&A(s),s=We(e,a.root,a.listenerTarget,n,t,o)):s.callback!==n.callback&&(s.callback=n.callback),i.push(s)}for(let e of r.values())A(e);i.length===0?w.delete(e):w.set(e,i)}function Be(e){let t=w.get(e);if(t===void 0)return;let{listenerTarget:n,root:r}=He(e);for(let i of t)$e(e,r,n,i)}function Ve(e){let t=w.get(e);if(t!==void 0){for(let e of t)A(e);w.delete(e)}}function He(e){let t=R(e);if(t===null)return{listenerTarget:null,root:null};let n=T.get(t);return n===void 0?{listenerTarget:null,root:null}:{listenerTarget:t,root:n.portalOwner?.root??(n.run===null?null:t)}}function Ue(e,t,n){let r=D(e),i=R(n)??t;if(r.portalOwner!==null){if(r.portalOwner.root===t&&r.portalOwner.parentTarget===i){r.portalOwner={logicalParent:n,parentTarget:i,root:t};return}O(e)}r.portalOwner={logicalParent:n,parentTarget:i,root:t};let a=D(i);(a.portals??=new Set).add(e);for(let n of a.listeners.values())P(t,e,n.type,n.capture,n.passive)}function O(e){let t=T.get(e);if(!t?.portalOwner)return;let n=t.portalOwner;t.portalOwner=null;let r=T.get(n.parentTarget);if(r!==void 0){r.portals?.delete(e);for(let t of r.listeners.keys())F(e,t)}}function k(){let e=new Set;for(let t=0;t<E.length;){let n=E[t];if(!L(n.listenerTarget??n.root,n.event.target)){E.splice(t,1);continue}if(Ye(n)===`blocked`){e.add(n.root),t+=1;continue}if(e.has(n.root)){t+=1;continue}E.splice(t,1),Xe(n)}}function We(e,t,n,r,i,a){let o={attachment:null,capture:i,callback:r.callback,controller:null,passive:a,slot:r.slot,type:r.type};return $e(e,t,n,o),o}function A(e){I(e),N(e)}function Ge(e,t,n,r,i,a){let o=R(a.target);if(o!==t&&((o===null?null:T.get(o)??null)?.portalOwner?.root===e||!L(t,a.target))||qe(e,n,a)===`blocked`)return;let s=j(e,t,n,r,i,a);s.length!==0&&Se(a,!1,e=>M(s,a,e))}function Ke(e,t){if(t.hydrationListeners===null){t.hydrationListeners=[];for(let n of ke){let r=t=>qe(e,n,t);t.hydrationListeners.push([n,r]),e.addEventListener(n,r,{capture:!0,passive:at(n)})}}}function qe(e,t,n){let r=T.get(e)?.hydrate??null;if(r===null)return`none`;let i=Te.get(n),a=i?.get(e);if(a!==void 0)return a;let o=z(t),s=oe(o,()=>r(n.target,o));return i===void 0&&(i=new WeakMap,Te.set(n,i)),i.set(e,s),s===`blocked`&&Ee.has(t)&&Je(e,t,n),s}function Je(e,t,n){E.push({event:n,listenerTarget:R(n.target),root:e,type:t})}function Ye(e){let t=T.get(e.root)?.hydrate??null;if(t===null)return`none`;let n=z(e.type);return oe(n,()=>t(e.event.target,n))}function Xe(e){let{event:t,root:n,type:r}=e,i=e.listenerTarget??e.root;Se(t,!0,e=>{M(j(n,i,r,!0,null,t),t,e),!(e.immediateStopped||e.stopped)&&M(j(n,i,r,!1,null,t),t,e)})}function j(e,t,n,r,i,a){let o=rt(e,t,a),s=[],c=r?-1:1;for(let t=r?o.length-1:0;t>=0&&t<o.length;t+=c){let a=o[t],c=w.get(a);if(c!==void 0)for(let t of c){let o=nt(t);o!==e||t.type!==n||t.capture!==r||i!==null&&t.passive!==i||s.push({callback:t.callback,element:a,root:o,slot:t})}}return s}function M(e,t,n){let r=null;for(let i of e){if(n.immediateStopped)return;if(i.element!==r){if(r!==null&&n.stopped)return;r=i.element}try{Ze(i,t)}finally{let e=i.slot;e.attachment===null&&N(e)}}}function Ze(e,t){let n=e.slot;N(n),n.controller=new AbortController;let r=n.controller.signal;je(()=>{Qe(e.root,()=>oe(z(n.type),()=>{xe(t,e.element,t=>{e.callback(t,r)})}))})}function Qe(e,t){let n=e===null?null:T.get(e)?.run??null;return n===null?t():n(t)}function N(e){e.controller?.abort(),e.controller=null}function $e(e,t,n,r){Ae.has(r.type)?et(e,t,r):tt(t,n,r)}function et(e,t,n){let r=n.attachment;if(r!==null){if(`element`in r&&r.element===e){t!==null&&(r.root=t);return}I(n)}let i=t=>{try{Ze({callback:n.callback,element:e,root:nt(n),slot:n},t)}finally{n.attachment===null&&N(n)}};n.attachment={element:e,listener:i,root:t},e.addEventListener(n.type,i,{capture:n.capture,passive:n.passive})}function tt(e,t,n){if(e===null||t===null)return;let r=n.attachment;r!==null&&`listenerTarget`in r&&r.root===e&&r.listenerTarget===t||(I(n),n.attachment={listenerTarget:t,root:e},P(e,t,n.type,n.capture,n.passive))}function P(e,t,n,r,i){let a=D(t).listeners,o=`${n}:${r}:${i}`,s=a.get(o);if(s===void 0){s={capture:r,count:0,listener:a=>Ge(e,t,n,r,i,a),passive:i,type:n},t.addEventListener(n,s.listener,{capture:r,passive:i}),a.set(o,s);for(let a of T.get(t)?.portals??[])P(e,a,n,r,i)}s.count+=1}function F(e,t){let n=T.get(e)?.listeners,r=n?.get(t);if(!(n===void 0||r===void 0)&&(--r.count,!(r.count>0))){e.removeEventListener(r.type,r.listener,r.capture),n.delete(t);for(let n of T.get(e)?.portals??[])F(n,t)}}function I(e){let t=e.attachment;t!==null&&(e.attachment=null,`element`in t?t.element.removeEventListener(e.type,t.listener,e.capture):F(t.listenerTarget,`${e.type}:${e.capture}:${e.passive}`))}function nt(e){return e.attachment?.root??null}function rt(e,t,n){let r=[],i=n.composedPath?.();if(i!==void 0){let n=i.indexOf(t);if(n!==-1){for(let e=0;e<n;e+=1){let t=i[e];m(t)&&r.push(t)}return it(r,e,t),r}}for(let e=n.target;e!==t&&(m(e)&&r.push(e),e=g(e),e!==null););return it(r,e,t),r}function it(e,t,n){let r=T.get(n)?.portalOwner??null;if(r===null||r.root!==t)return;let i=r.logicalParent;for(;i!==null&&i!==t;){if(ot(i)){let e=T.get(i)?.portalOwner??null;if(e!==null&&e.root===t){i=e.logicalParent;continue}}m(i)&&e.push(i),i=g(i)}}function L(e,t){for(let n=t;n!==null;){if(n===e)return!0;n=g(n)}return!1}function R(e){for(let t=e;t!==null;){if(ot(t)){let e=T.get(t);if(e!==void 0&&(e.portalOwner!==null||e.run!==null))return t}t=g(t)}return null}function z(e){return De.has(e)?`discrete`:Oe.has(e)?`continuous`:`default`}function at(e){return Oe.has(e)||e===`touchstart`||e===`touchend`}function ot(e){return typeof e==`object`&&!!e&&`addEventListener`in e&&`childNodes`in e}function st(e){se(e,e=>{fe(e),Be(e)})}function B(e){se(e,e=>{he(e),Ve(e)})}const V=new WeakMap;function ct(e){return xt(e)||e===`checked`||e===`defaultChecked`}function lt(e,t,n,r,i,a){if(t===`select`&&xt(n))return;if(t===`option`&&n===`value`){W(e,`value`,U(r));return}let o=a.initial===!0&&a.hydrating!==!0;n===`value`?_(r)||pt(e,r):n===`defaultValue`?ft(e,r,t,o&&i.value===void 0):n===`checked`?r!==void 0&&gt(e,r):n===`defaultChecked`&&ht(e,r,o&&i.checked===void 0)}function ut(e,t,n,r){if(t!==`select`)return;let i=n.value!==void 0,a=i?n.value:n.defaultValue;if(_(a)){V.delete(e);return}let o=!i&&r.hydrating===!0,s={appliedDefault:V.get(e)?.appliedDefault===!0||!i,applyDefaultToInsertedOptions:!o&&!i&&r.initial===!0,controlled:i,selectedValues:Array.isArray(a)?new Set(a.map(String)):String(a)};V.set(e,s),!o&&(i||r.initial===!0)&&_t(e,s.selectedValues)}function H(e,t=!1){let n=yt(e);if(n===null)return;let r=V.get(n);r!==void 0&&(!r.controlled&&r.appliedDefault&&!t||!r.controlled&&t&&!r.applyDefaultToInsertedOptions||(_t(e,r.selectedValues),r.controlled||(r.appliedDefault=!0)))}function dt(e,t){return(e===`input`||e===`textarea`||e===`select`)&&(t.value!==void 0||t.checked!==void 0)}function ft(e,t,n,r){let i=U(t),a=i??``;`defaultValue`in e&&(e.defaultValue=a),n===`textarea`?e.textContent=a:W(e,`value`,i),r&&`value`in e&&mt(e,a)}function pt(e,t){let n=U(t);n!==null&&(`value`in e?mt(e,n):W(e,`value`,n))}function mt(e,t){let n=e;n.value!==t&&(n.value=t)}function ht(e,t,n){let r=t===!0;`defaultChecked`in e&&(e.defaultChecked=r),W(e,`checked`,r),n&&gt(e,t)}function gt(e,t){let n=t===!0;`checked`in e?e.checked=n:W(e,`checked`,n)}function U(e){return _(e)?null:String(e)}function _t(e,t){if(h(e)===`option`){vt(e,t);return}bt(e,e=>{vt(e,t)})}function vt(e,t){let n=e.getAttribute(`value`)??(e.textContent??``).replace(/\s+/g,` `).trim();e.selected=typeof t==`string`?n===t:t.has(n)}function yt(e){let t=e.parentNode;for(;t!==null;){if(m(t)&&h(t)===`select`)return t;t=t.parentNode}return null}function bt(e,t){for(let n=e.firstChild;n!==null;){let e=n.nextSibling;m(n)&&(h(n)===`option`?t(n):bt(n,t)),n=e}}function xt(e){return e===`value`||e===`defaultValue`}function W(e,t,n){_(n)?e.removeAttribute(t):e.setAttribute(t,String(n))}function St(e,t,n){let r=e.style;if(r===void 0)return;let i=Ct(t),a=Ct(n);for(let e of Object.keys(i))e in a||Tt(r,e);for(let[e,t]of Object.entries(a))_(t)?Tt(r,e):wt(r,e,t)}function Ct(e){return typeof e==`object`&&e?e:{}}function wt(e,t,n){typeof n==`number`||typeof n==`bigint`||(t.startsWith(`--`)&&typeof e.setProperty==`function`?e.setProperty(t,String(n)):e[t]=n)}function Tt(e,t){t.startsWith(`--`)&&typeof e.removeProperty==`function`?e.removeProperty(t):e[t]=``}const Et=`http://www.w3.org/1999/xlink`;function G(e,t,n,r={}){(`mix`in t||`mix`in n)&&ze(e,be(n));let i=h(e),a=le(e),o=Object.keys(t);for(let e in n)Object.hasOwn(n,e)&&!Object.hasOwn(t,e)&&o.push(e);for(let s of o){let o=t[s],c=n[s];if(s!==`mix`){if(s===`bind`){o!==c&&de(e,c);continue}if(s===`unsafeHTML`){r.hydrating===!0?kt(c):o!==c&&Ot(e,c);continue}if(!Nt(s)){if(ct(s)){lt(e,i,s,c,n,r);continue}o!==c&&(s===`style`?St(e,o,c):jt(e,At(s,a),c))}}}ut(e,i,n,r),(i===`option`||i===`optgroup`)&&H(e)}function Dt(e,t){G(e,{},t,{hydrating:!0})}function Ot(e,t){let n=kt(t);`innerHTML`in e&&(e.innerHTML=n??``)}function kt(e){if(_(e))return null;if(typeof e==`string`)return e;throw Error(`The unsafeHTML prop must be a string.`)}function At(e,t){return t?e.toLowerCase():e}function jt(e,t,n){if(_(n)){Mt(e,t);return}if(t===`xlink:href`){e.setAttributeNS(Et,t,String(n));return}e.setAttribute(t,String(n))}function Mt(e,t){if(t===`xlink:href`){e.removeAttributeNS(Et,`href`);return}e.removeAttribute(t)}function Nt(e){return e===`children`||e===`key`||e===`mix`||e===`suppressHydrationWarning`||e===`unsafeHTML`||Pt(e)}function Pt(e){return/^on[A-Z]/.test(e)}var Ft=class{element;resourceKind;kind=`metadata`;byOwner=new Map;rendered=null;winner;constructor(e,t,n,r){this.element=e,this.resourceKind=t,this.winner=n,this.byOwner.set(n,r),this.applyWinner()}acquire(e,t){let n=!this.byOwner.has(e);this.byOwner.set(e,t),n&&(this.winner=e),this.winner===e&&this.applyWinner()}update(e,t){if(!this.byOwner.has(e))throw Error(`Expected a live metadata claim.`);this.byOwner.set(e,t),this.winner===e&&this.applyWinner()}release(e){if(!this.byOwner.delete(e))return`retained`;if(this.byOwner.size===0)return`empty`;if(this.winner!==e)return`retained`;let t=null;for(let e of this.byOwner.keys())t=e;if(t===null)throw Error(`Expected a live metadata claim.`);return this.winner=t,this.applyWinner(),`retained`}applyWinner(){let e=this.byOwner.get(this.winner);if(e===void 0)throw Error(`Expected a live metadata claim.`);G(this.element,this.rendered??{},e),this.resourceKind===`title`&&(this.element.textContent=It(e.children)),this.rendered=e}};function It(e){return e==null||typeof e==`boolean`?``:typeof e==`string`||typeof e==`number`?String(e):Array.isArray(e)?e.map(It).join(``):``}const Lt=new WeakMap,K=new WeakMap;function Rt(e,t,n){let r=J();if(r===null)return;let i=Gt(e),a=Gt(t);for(let[e]of i)a.has(e)||Jt(r,e,n);for(let[e,t]of a)i.has(e)?(t.kind===`title`||t.kind===`meta`)&&qt(r,e,t,n):Kt(r,t,n)}function zt(e,t){let n=J(),r=d(e,t);if(n===null||r===null)return null;let i=p(r);if(Y(r)){let t=document.createElement(e);return K.set(t,{key:i,kind:r.kind}),t}let a=n.entries.get(i);if(a?.kind===`metadata`)throw Error(`Expected a persistent resource entry.`);let o=a?.element??X(n,i)??document.createElement(e);return a===void 0&&(n.entries.set(i,{count:0,element:o,kind:`persistent`,ready:null}),K.set(o,{key:i,kind:r.kind})),o}function Bt(e,t,n){let r=J();if(r===null)return e;let i=d(h(e),t);return i!==null&&Y(i)?Yt(r,i,t,n,e):Vt(r,e)}function Vt(e,t){let n=K.get(t);if(n===void 0){let e=rn(t);if(e===null)return t;n={key:p(e),kind:e.kind},K.set(t,n)}let r=e.entries.get(n.key);if(r?.kind===`metadata`)throw Error(`Expected a persistent resource entry.`);return r!==void 0&&r.element!==t?(r.count+=1,$t(e,r.element)):(r===void 0?e.entries.set(n.key,{count:1,element:t,kind:`persistent`,ready:null}):r.count+=1,$t(e,t))}function q(e,t){let n=J(),r=K.get(e);if(n===null||r===void 0)return;let i=n.entries.get(r.key);if(i?.kind===`metadata`){Xt(n,r.key,i,t);return}if(r.kind===`title`||r.kind===`meta`){K.delete(e),an(e);return}Ht(n,e)}function Ht(e,t){let n=K.get(t);if(n===void 0)return;let r=e.entries.get(n.key);if(r===void 0||r.element!==t){if(tn(e,t))return;K.delete(t);return}if(r.kind!==`persistent`)throw Error(`Expected a persistent resource entry.`);r.count>0&&--r.count}function Ut(e,t,n,r){let i=h(e),a=d(i,n),o=K.get(e);if(a===null)return e;let s=p(a),c=J();if(c===null)return G(e,t,n),e;let l=o===void 0?void 0:c.entries.get(o.key);if(l?.kind===`metadata`){if(!Y(a)||s===o?.key)return l.update(r,Y(a)?Qt(a,n):n),l.element;q(e,r);let t=document.createElement(i);return G(t,{},n),a.kind===`title`&&(t.textContent=a.value),K.set(t,{key:p(a),kind:a.kind}),Yt(c,a,n,r,t)}if(o===void 0||s===o.key)return G(e,t,n),e;q(e,r);let u=c.entries.get(s),ee=u?.kind===`persistent`&&u.count>0?u.element:void 0,f=zt(i,n)??e;return f===e?(G(e,t,n),e):(ee!==f&&G(f,{},n),Bt(f,n,r))}function Wt(e){let t=J();if(t===null)return Promise.resolve();let n=[];for(let r of e){if(!te(r)||r.kind===`title`||r.kind===`meta`)continue;let e=sn(r),i=p(e),a=t.entries.get(i)?.element,o=(a?.parentNode===t.head?a:null)??X(t,i);if(o!==null){let r=t.entries.get(i);if(r?.kind===`metadata`)throw Error(`Expected a persistent resource entry.`);r?.element!==o&&(r={count:1,element:o,kind:`persistent`,ready:null},t.entries.set(i,r),K.set(o,{key:i,kind:e.kind}));let a=nn(t,e,i,r);a!==null&&n.push(a);continue}let s=dn(e),c={count:1,element:s,kind:`persistent`,ready:null};c.ready=cn(e)?un(s).then(()=>{t.entries.get(i)===c&&(c.ready=null)}):null,t.entries.set(i,c),K.set(s,{key:i,kind:e.kind}),en(t,s),c.ready!==null&&n.push(c.ready)}return n.length===0?Promise.resolve():Promise.all(n).then(()=>void 0)}function J(){if(typeof document>`u`||document.head==null)return null;let e=Lt.get(document.head);return e===void 0&&(e={entries:new Map,head:document.head},Lt.set(document.head,e)),e}function Gt(e){let t=new Map;if(e===null)return t;let n=Array.isArray(e)?e:[e];for(let e of n){if(!te(e))continue;let n=sn(e),r=p(n);(!t.has(r)||Y(n))&&t.set(r,n)}return t}function Kt(e,t,n){if(Y(t)){Yt(e,t,Zt(t),n);return}let r=p(t),i=e.entries.get(r);if(i?.kind===`metadata`)throw Error(`Expected a persistent resource entry.`);let a=i?.element,o=a??X(e,r)??dn(t);a===void 0&&(e.entries.set(r,{count:0,element:o,kind:`persistent`,ready:null}),K.set(o,{key:r,kind:t.kind})),Vt(e,o)}function qt(e,t,n,r){let i=e.entries.get(t);if(i===void 0){Kt(e,n,r);return}if(i.kind!==`metadata`)throw Error(`Expected a metadata resource entry.`);i.update(r,Zt(n))}function Jt(e,t,n){let r=e.entries.get(t);r!==void 0&&(r.kind===`metadata`?Xt(e,t,r,n):Ht(e,r.element))}function Yt(e,t,n,r,i){let a=p(t),o=Qt(t,n),s=e.entries.get(a);if(s?.kind===`persistent`)throw Error(`Expected a metadata resource entry.`);if(s===void 0){let n=X(e,a)??i??document.createElement(t.kind);s=new Ft(n,t.kind,r,o),e.entries.set(a,s),K.set(n,{key:a,kind:t.kind})}else s.acquire(r,o);return $t(e,s.element)}function Xt(e,t,n,r){n.release(r)!==`retained`&&(e.entries.delete(t),K.delete(n.element),an(n.element))}function Zt(e){return e.kind===`title`?{children:e.value}:{charset:e.charset,content:e.content,"data-fig-resource-key":e.key,"http-equiv":e[`http-equiv`],name:e.name,property:e.property}}function Qt(e,t){return e.kind===`title`?{...t,children:e.value}:t}function Y(e){return e.kind===`title`||e.kind===`meta`}function $t(e,t){return t.parentNode!==e.head&&en(e,t),st(t),t}function en(e,t){let n=on(t);if(n===null){e.head.appendChild(t);return}let r=!1;for(let i=e.head.firstChild;i!==null;i=i.nextSibling){let a=m(i)?on(i):null;if(a!==null){if(a===n)r=!0;else if(r){e.head.insertBefore(t,i);return}}}e.head.appendChild(t)}function X(e,t){for(let n=e.head.firstChild;n!==null;n=n.nextSibling)if(m(n)){let e=rn(n);if(e!==null&&p(e)===t)return n}return null}function tn(e,t){for(let n of e.entries.values())if(n.element===t)return!0;return!1}function nn(e,t,n,r){if(!cn(t))return null;if(r.ready!==null)return r.ready;if(!ln(r.element))return null;let i=un(r.element).then(()=>{e.entries.get(n)===r&&(r.ready=null)});return r.ready=i,i}function rn(e){return ee(h(e),t=>e.getAttribute(t))}function an(e){B(e),e.parentNode?.removeChild(e)}function on(e){if(h(e)!==`link`)return null;let t=rn(e);return t?.kind===`stylesheet`?t.precedence??``:null}function sn(e){return e.kind===`font`?{as:`font`,crossorigin:e.crossorigin??`anonymous`,fetchpriority:e.fetchpriority,href:e.href,key:e.key,kind:`preload`,type:e.type}:e}function cn(e){return e.kind!==`stylesheet`||e.blocking===`none`?!1:e.media===void 0||e.media===``||typeof matchMedia!=`function`||matchMedia(e.media).matches}function ln(e){return h(e)===`link`&&e.getAttribute(`rel`)===`stylesheet`&&`sheet`in e&&e.sheet===null}function un(e){return new Promise(t=>{let n=()=>{e.removeEventListener(`load`,n),e.removeEventListener(`error`,n),t()};e.addEventListener(`load`,n),e.addEventListener(`error`,n)})}function dn(e){let t=document.createElement(e.kind===`script`?`script`:`link`);for(let[n,r]of f(e))t.setAttribute(n,r===!0?``:r);return t}function fn(e){if(!Q(e))return null;let t=Z(e);return t===null?null:pn(e,t)}function pn(e,t){let n=mn(e);return n===null?null:{end:n,forceClientRender:!1,id:t.id,start:e,get error(){return hn(e)},get status(){return Z(e)?.status??t.status}}}function Z(e){if(!Q(e))return null;if(e.data===s)return{id:null,status:`completed`};if(e.data===o)return{id:null,status:`client-rendered`};let t=e.data.startsWith(l)?e.data.slice(l.length):null;return t!==null&&t!==``?{id:t,status:`pending`}:null}function mn(e){let t=0;for(let n=e.nextSibling;n!==null;n=n.nextSibling)if(Q(n)){if(Z(n)!==null){t+=1;continue}if(n.data===c){if(t===0)return n;--t}}return null}function hn(e){let t=e.nextSibling;return Sn(t)?{digest:t.dataset.dgst,message:t.dataset.msg}:null}function gn(e){if(!Cn(e))return null;for(let t=e;t!==null;t=t.parentNode){let e=0;for(let n=t.previousSibling;n!==null;n=n.previousSibling)if(Q(n)){if(n.data===c){e+=1;continue}if(Z(n)!==null){if(e===0)return n;--e}}}return null}function _n(e,t){if(!Cn(e))return!1;let n=t.start.parentNode,r=t.end.parentNode;if(n===null&&r===null)return!1;for(let i=e;i!==null;i=i.parentNode){if(i===t.start||i===t.end)return!1;if(n!==null&&i.parentNode===n)return vn(i,t.start,t.end);if(r!==null&&r!==n&&i.parentNode===r)return yn(i,t.end)}return!1}function vn(e,t,n){for(let r=e;r!==null;r=r.previousSibling){if(r===t)return!0;if(r===n)return!1}return!1}function yn(e,t){for(let n=e;n!==null;n=n.nextSibling)if(n===t)return!0;return!1}function bn(e){for(let t=e.start;t!==null;){let n=t.nextSibling;if(xn(t),t===e.end)return;t=n}}function xn(e){e.parentNode?.removeChild(e)}function Q(e){return typeof e==`object`&&!!e&&`data`in e&&`nodeType`in e&&e.nodeType===8}function Sn(e){return typeof e==`object`&&!!e&&`dataset`in e}function Cn(e){return typeof e==`object`&&!!e&&`parentNode`in e}function wn(e){return e.nodeType===9}const Tn=ae({createInstance:kn,createTextInstance:e=>document.createTextNode(e),validateInstanceNesting:(e,t,n)=>{},validateTextNesting:(e,t)=>{},containerType:e=>m(e)?h(e):null,appendInitialChild:(e,t)=>{e.appendChild(t),m(t)&&Rn(t)&&H(t,!0)},finalizeInitialInstance:(e,t)=>G(e,{},t,{initial:!0}),setTextContent:(e,t)=>{e.textContent!==t&&(e.textContent=t)},getFirstHydratableChild:jn,getNextHydratableSibling:e=>$(e.nextSibling),canHydrateInstance:On,canHydrateTextInstance:(e,t,n)=>Ln(e)&&(n===!0||e.nodeValue===t),canRetainHydrationTail:e=>{let t=h(e);return t===`html`||t===`head`||t===`body`},resolveHoistedInstance:(e,t,n)=>An(e,n)===`http://www.w3.org/1999/xhtml`?zt(e,t):null,commitHoistedInstance:Bt,commitAssetResources:Rt,removeHoistedInstance:q,updateHoistedInstance:Ut,shouldCommitUpdate:(e,t,n)=>dt(e,n),clearContainer:e=>{let t=e.firstChild;for(;t!==null;){let n=t.nextSibling;t.nodeType!==10&&(B(t),e.removeChild(t)),t=n}queueMicrotask(k)},insertBefore:(e,t,n)=>{e.insertBefore(t,n),m(t)&&Rn(t)&&H(t),st(t)},removeChild:(e,t)=>{B(t),e.removeChild(t)},commitTextUpdate:(e,t)=>{e.nodeValue!==t&&(e.nodeValue=t)},commitUpdate:G,commitHydratedInstance:Dt,getActivityBoundary:Dn,getFirstActivityHydratable:e=>$(En(e).firstChild??null),commitHydratedActivityBoundary:e=>{let t=e.parentNode;if(t===null)return;let n=En(e);for(;n.firstChild!==null;)t.insertBefore(n.firstChild,e);t.removeChild(e)},hideInstance:e=>{pe(e),e.style.setProperty(`display`,`none`,`important`)},unhideInstance:(e,t)=>{let n=t.style?.display;e.style.setProperty(`display`,typeof n==`string`?n:``),me(e)},hideTextInstance:e=>{e.nodeValue=``},unhideTextInstance:(e,t)=>{e.nodeValue!==t&&(e.nodeValue=t)},getSuspenseBoundary:fn,getEnclosingSuspenseBoundaryStart:gn,isTargetWithinSuspenseBoundary:_n,shouldRecoverSuspenseMismatchAtRoot:(e,t)=>wn(e)&&_n(e.documentElement,t),registerSuspenseBoundaryRetry:(e,t)=>{e.start.__figRetry=t},commitHydratedSuspenseBoundary:e=>{e.status===`completed`&&!e.forceClientRender?(xn(e.start),xn(e.end)):bn(e),queueMicrotask(k)},removeDehydratedSuspenseBoundary:e=>{bn(e),queueMicrotask(k)},completeRootHydration:e=>{Le(e),queueMicrotask(k)},preparePortalContainer:Ue,removePortalContainer:O});Me(Tn.batchedUpdates),e(Tn.scheduleRefresh);function En(e){return`content`in e?e.content:e}function Dn(e){return m(e)&&h(e)===`template`&&e.getAttribute(t)!==null?e:null}function On(e,t,n){return!m(e)||!(`setAttribute`in e)||h(e)!==t.toLowerCase()?!1:In(e,n)}function kn(e,t,n){let r=An(e,n);return r===`http://www.w3.org/1999/xhtml`?document.createElement(e):document.createElementNS(r,e)}function An(e,t){let n=e.toLowerCase();return n===`svg`?`http://www.w3.org/2000/svg`:n===`math`?`http://www.w3.org/1998/Math/MathML`:`namespaceURI`in t&&h(t)!==`foreignobject`?t.namespaceURI??`http://www.w3.org/1999/xhtml`:`http://www.w3.org/1999/xhtml`}function jn(e,t){return t!==void 0&&Fn(t)!==null||h(e)===`textarea`&&t!==void 0&&Pn(t)?null:$(e.firstChild)}function $(e){let t=e;for(;t!==null&&(Nn(t)||t.nodeType===10||Mn(t));)t=t.nextSibling;return t}function Mn(e){return m(e)&&e.getAttribute(i)!==null}function Nn(e){return e.nodeType===8&&e.nodeValue===u}function Pn(e){return e.value!==void 0||e.defaultValue!==void 0}function Fn(e){return _(e.unsafeHTML)?null:e.unsafeHTML}function In(e,t){let n=Fn(t);return n===null||typeof n!=`string`||`innerHTML`in e}function Ln(e){return e.nodeType===3}function Rn(e){let t=h(e);return t===`option`||t===`optgroup`}export{ve as a,Ie as i,Wt as n,ue as o,Ne as r,Tn as t};
2
+ //# sourceMappingURL=renderer-HA5C4hQE.js.map