@fictjs/runtime 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +46 -0
  2. package/dist/advanced.cjs +9 -9
  3. package/dist/advanced.d.cts +5 -5
  4. package/dist/advanced.d.ts +5 -5
  5. package/dist/advanced.js +4 -4
  6. package/dist/{effect-DAzpH7Mm.d.ts → binding-DUEukRxl.d.cts} +35 -24
  7. package/dist/{effect-DAzpH7Mm.d.cts → binding-DqxS9ZQf.d.ts} +35 -24
  8. package/dist/{chunk-WRU3IZOA.js → chunk-2JRPPCG7.js} +3 -3
  9. package/dist/{chunk-TLDT76RV.js → chunk-DKA2I6ET.js} +3 -3
  10. package/dist/{chunk-FSCBL7RI.cjs → chunk-EQ5E4WOV.cjs} +702 -534
  11. package/dist/chunk-EQ5E4WOV.cjs.map +1 -0
  12. package/dist/{chunk-7YQK3XKY.js → chunk-F4RVNXOL.js} +687 -519
  13. package/dist/chunk-F4RVNXOL.js.map +1 -0
  14. package/dist/{chunk-PRF4QG73.cjs → chunk-I4GKKAAY.cjs} +469 -248
  15. package/dist/chunk-I4GKKAAY.cjs.map +1 -0
  16. package/dist/{chunk-HHDHQGJY.cjs → chunk-K3DH5SD5.cjs} +17 -17
  17. package/dist/{chunk-HHDHQGJY.cjs.map → chunk-K3DH5SD5.cjs.map} +1 -1
  18. package/dist/chunk-P4TZLFV6.js +768 -0
  19. package/dist/chunk-P4TZLFV6.js.map +1 -0
  20. package/dist/{chunk-4LCHQ7U4.js → chunk-R6FINS25.js} +318 -97
  21. package/dist/chunk-R6FINS25.js.map +1 -0
  22. package/dist/chunk-SZLJCQFZ.cjs +768 -0
  23. package/dist/chunk-SZLJCQFZ.cjs.map +1 -0
  24. package/dist/{chunk-CEV6TO5U.cjs → chunk-V7BC64W2.cjs} +8 -8
  25. package/dist/{chunk-CEV6TO5U.cjs.map → chunk-V7BC64W2.cjs.map} +1 -1
  26. package/dist/{context-BFbHf9nC.d.cts → devtools-C4Hgfa-S.d.ts} +47 -35
  27. package/dist/{context-C4vBQbb4.d.ts → devtools-CMxlJUTx.d.cts} +47 -35
  28. package/dist/index.cjs +42 -42
  29. package/dist/index.d.cts +5 -5
  30. package/dist/index.d.ts +5 -5
  31. package/dist/index.dev.js +233 -28
  32. package/dist/index.dev.js.map +1 -1
  33. package/dist/index.js +3 -3
  34. package/dist/internal-list.cjs +12 -0
  35. package/dist/internal-list.cjs.map +1 -0
  36. package/dist/internal-list.d.cts +2 -0
  37. package/dist/internal-list.d.ts +2 -0
  38. package/dist/internal-list.js +12 -0
  39. package/dist/internal-list.js.map +1 -0
  40. package/dist/internal.cjs +6 -746
  41. package/dist/internal.cjs.map +1 -1
  42. package/dist/internal.d.cts +7 -75
  43. package/dist/internal.d.ts +7 -75
  44. package/dist/internal.js +12 -752
  45. package/dist/internal.js.map +1 -1
  46. package/dist/jsx-dev-runtime.d.cts +671 -0
  47. package/dist/jsx-dev-runtime.d.ts +671 -0
  48. package/dist/jsx-runtime.d.cts +671 -0
  49. package/dist/jsx-runtime.d.ts +671 -0
  50. package/dist/list-BBzsJhrm.d.ts +71 -0
  51. package/dist/list-_NJCcjl1.d.cts +71 -0
  52. package/dist/loader.cjs +99 -16
  53. package/dist/loader.cjs.map +1 -1
  54. package/dist/loader.d.cts +17 -3
  55. package/dist/loader.d.ts +17 -3
  56. package/dist/loader.js +92 -9
  57. package/dist/loader.js.map +1 -1
  58. package/dist/{props-84UJeWO8.d.cts → props--zJ4ebbT.d.cts} +3 -3
  59. package/dist/{props-BRhFK50f.d.ts → props-BAGR7j-j.d.ts} +3 -3
  60. package/dist/{resume-i-A3EFox.d.cts → resume-C5IKAIdh.d.ts} +5 -3
  61. package/dist/{resume-CqeQ3v_q.d.ts → resume-DPZxmA95.d.cts} +5 -3
  62. package/dist/{scope-D3DpsfoG.d.ts → scope-CuImnvh1.d.ts} +1 -1
  63. package/dist/{scope-DlCBL1Ft.d.cts → scope-Dq5hOu7c.d.cts} +1 -1
  64. package/dist/{signal-C4ISF17w.d.cts → signal-Z4KkDk9h.d.cts} +12 -1
  65. package/dist/{signal-C4ISF17w.d.ts → signal-Z4KkDk9h.d.ts} +12 -1
  66. package/package.json +9 -2
  67. package/src/binding.ts +113 -36
  68. package/src/cycle-guard.ts +3 -3
  69. package/src/devtools.ts +19 -2
  70. package/src/dom.ts +58 -4
  71. package/src/effect.ts +5 -5
  72. package/src/hooks.ts +13 -5
  73. package/src/internal/list.ts +7 -0
  74. package/src/internal.ts +1 -0
  75. package/src/lifecycle.ts +41 -3
  76. package/src/list-helpers.ts +1 -1
  77. package/src/loader.ts +128 -12
  78. package/src/resume.ts +6 -3
  79. package/src/signal.ts +200 -20
  80. package/src/transition.ts +9 -3
  81. package/dist/chunk-4LCHQ7U4.js.map +0 -1
  82. package/dist/chunk-7YQK3XKY.js.map +0 -1
  83. package/dist/chunk-FSCBL7RI.cjs.map +0 -1
  84. package/dist/chunk-PRF4QG73.cjs.map +0 -1
  85. /package/dist/{chunk-WRU3IZOA.js.map → chunk-2JRPPCG7.js.map} +0 -0
  86. /package/dist/{chunk-TLDT76RV.js.map → chunk-DKA2I6ET.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/reconcile.ts","../src/list-helpers.ts"],"sourcesContent":["/**\n * Fict DOM Reconciliation\n *\n * Efficient array reconciliation algorithm based on udomdiff.\n * https://github.com/WebReflection/udomdiff\n *\n * This algorithm uses a 5-step strategy:\n * 1. Common prefix - skip matching nodes at start\n * 2. Common suffix - skip matching nodes at end\n * 3. Append - insert remaining new nodes\n * 4. Remove - remove remaining old nodes\n * 5. Swap/Map fallback - handle complex rearrangements\n *\n * Most real-world updates (95%+) use fast paths without building a Map.\n */\n\n/**\n * Reconcile two arrays of DOM nodes, efficiently updating the DOM.\n *\n * @param parentNode - The parent element containing the nodes\n * @param a - The old array of nodes (currently in DOM)\n * @param b - The new array of nodes (target state)\n *\n * **Note:** This function may mutate the input array `a` during the swap\n * optimization (step 5a). If you need to preserve the original array,\n * pass a shallow copy: `reconcileArrays(parent, [...oldNodes], newNodes)`.\n *\n * @example\n * ```ts\n * const oldNodes = [node1, node2, node3]\n * const newNodes = [node1, node4, node3] // node2 replaced with node4\n * reconcileArrays(parent, oldNodes, newNodes)\n * ```\n */\nexport default function reconcileArrays(parentNode: ParentNode, a: Node[], b: Node[]): void {\n const bLength = b.length\n let aEnd = a.length\n let bEnd = bLength\n let aStart = 0\n let bStart = 0\n const after = aEnd > 0 ? a[aEnd - 1]!.nextSibling : null\n let map: Map<Node, number> | null = null\n\n while (aStart < aEnd || bStart < bEnd) {\n // 1. Common prefix - nodes match at start\n if (a[aStart] === b[bStart]) {\n aStart++\n bStart++\n continue\n }\n\n // 2. Common suffix - nodes match at end\n while (a[aEnd - 1] === b[bEnd - 1]) {\n aEnd--\n bEnd--\n }\n\n // 3. Append - old array exhausted, insert remaining new nodes\n if (aEnd === aStart) {\n const node: Node | null =\n bEnd < bLength ? (bStart ? b[bStart - 1]!.nextSibling : (b[bEnd - bStart] ?? null)) : after\n\n const count = bEnd - bStart\n const doc = (parentNode as Node).ownerDocument\n if (count > 1 && doc) {\n const frag = doc.createDocumentFragment()\n for (let i = bStart; i < bEnd; i++) {\n frag.appendChild(b[i]!)\n }\n parentNode.insertBefore(frag, node)\n bStart = bEnd\n } else {\n while (bStart < bEnd) {\n parentNode.insertBefore(b[bStart++]!, node)\n }\n }\n }\n // 4. Remove - new array exhausted, remove remaining old nodes\n else if (bEnd === bStart) {\n while (aStart < aEnd) {\n const nodeToRemove = a[aStart]!\n if (!map || !map.has(nodeToRemove)) {\n nodeToRemove.parentNode?.removeChild(nodeToRemove)\n }\n aStart++\n }\n }\n // 5a. Swap backward - detect backward swap pattern\n else if (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]) {\n const node = a[--aEnd]!.nextSibling\n parentNode.insertBefore(b[bStart++]!, a[aStart++]!.nextSibling)\n parentNode.insertBefore(b[--bEnd]!, node)\n // Update reference in old array for potential future matches\n a[aEnd] = b[bEnd]!\n }\n // 5b. Map fallback - use Map for complex rearrangements\n else {\n // Build map on first use (lazy initialization)\n if (!map) {\n map = new Map()\n let i = bStart\n while (i < bEnd) {\n map.set(b[i]!, i++)\n }\n }\n\n const index = map.get(a[aStart]!)\n\n if (index != null) {\n if (bStart < index && index < bEnd) {\n // Check for longest increasing subsequence\n let i = aStart\n let sequence = 1\n let t: number | undefined\n\n while (++i < aEnd && i < bEnd) {\n t = map.get(a[i]!)\n if (t == null || t !== index + sequence) break\n sequence++\n }\n\n // Use optimal strategy based on sequence length\n if (sequence > index - bStart) {\n // Sequence is long enough - insert nodes before current\n const node = a[aStart]!\n while (bStart < index) {\n parentNode.insertBefore(b[bStart++]!, node)\n }\n } else {\n // Short sequence - replace\n parentNode.replaceChild(b[bStart++]!, a[aStart++]!)\n }\n } else {\n aStart++\n }\n } else {\n // Node not in new array - remove it\n const nodeToRemove = a[aStart++]!\n nodeToRemove.parentNode?.removeChild(nodeToRemove)\n }\n }\n }\n}\n\n/**\n * Simple reconciliation for keyed lists.\n * Uses the same algorithm but works with keyed blocks.\n *\n * @param parentNode - The parent element\n * @param oldNodes - Old nodes in DOM order\n * @param newNodes - New nodes in target order\n */\nexport function reconcileNodes(parentNode: ParentNode, oldNodes: Node[], newNodes: Node[]): void {\n reconcileArrays(parentNode, oldNodes, newNodes)\n}\n","/**\n * List Helpers for Compiler-Generated Fine-Grained Updates\n *\n * These helpers are used by the compiler to generate efficient keyed list rendering.\n * They provide low-level primitives for DOM node manipulation without rebuilding.\n */\n\nimport { createElement } from './dom'\nimport { createRenderEffect } from './effect'\nimport { isHydratingActive, withHydrationRange } from './hydration'\nimport {\n createRootContext,\n destroyRoot,\n flushOnMount,\n getCurrentRoot,\n popRoot,\n pushRoot,\n type RootContext,\n} from './lifecycle'\nimport { insertNodesBefore, removeNodes, toNodeArray } from './node-ops'\nimport reconcileArrays from './reconcile'\nimport { __fictIsHydrating, __fictIsSSR } from './resume'\nimport { batch } from './scheduler'\nimport { createSignal, effectScope, flush, setActiveSub, type Signal } from './signal'\nimport type { FictNode } from './types'\n\n// Re-export shared DOM helpers for compiler-generated code\nexport { insertNodesBefore, removeNodes, toNodeArray }\n\nconst isDev =\n typeof __DEV__ !== 'undefined'\n ? __DEV__\n : typeof process !== 'undefined' && process.env?.NODE_ENV !== 'production'\n\nconst isShadowRoot = (node: Node): node is ShadowRoot =>\n typeof ShadowRoot !== 'undefined' && node instanceof ShadowRoot\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * A keyed block represents a single item in a list with its associated DOM nodes and state\n */\ninterface KeyedBlock<T = unknown> {\n /** Unique key for this block */\n key: string | number\n /** DOM nodes belonging to this block */\n nodes: Node[]\n /** Root context for lifecycle management */\n root: RootContext\n /** Signal containing the current item value */\n item: Signal<T>\n /** Signal containing the current index */\n index: Signal<number>\n /** Last raw item value assigned to this block */\n rawItem: T\n /** Last raw index value assigned to this block */\n rawIndex: number\n}\n\n/**\n * Container for managing keyed list blocks\n */\ninterface KeyedListContainer<T = unknown> {\n /** Start marker comment node */\n startMarker: Comment\n /** End marker comment node */\n endMarker: Comment\n /** Map of key to block */\n blocks: Map<string | number, KeyedBlock<T>>\n /** Scratch map reused for the next render */\n nextBlocks: Map<string | number, KeyedBlock<T>>\n /** Current nodes in DOM order (including markers) */\n currentNodes: Node[]\n /** Next-frame node buffer to avoid reallocations */\n nextNodes: Node[]\n /** Ordered blocks in current DOM order */\n orderedBlocks: KeyedBlock<T>[]\n /** Next-frame ordered block buffer to avoid reallocations */\n nextOrderedBlocks: KeyedBlock<T>[]\n /** Track position of keys in the ordered buffer to handle duplicates */\n orderedIndexByKey: Map<string | number, number>\n /** Cleanup function */\n dispose: () => void\n}\n\n/**\n * Binding handle returned by createKeyedList for compiler-generated code\n */\nexport interface KeyedListBinding {\n /** Document fragment placeholder inserted by the compiler/runtime */\n marker: Comment | DocumentFragment\n /** Start marker comment node */\n startMarker: Comment\n /** End marker comment node */\n endMarker: Comment\n /** Flush pending items - call after markers are inserted into DOM */\n flush?: () => void\n /** Cleanup function */\n dispose: () => void\n}\n\ntype FineGrainedRenderItem<T> = (\n itemSig: Signal<T>,\n indexSig: Signal<number>,\n key: string | number,\n) => Node[]\n\n// ============================================================================\n// DOM Manipulation Primitives\n// ============================================================================\n\n/**\n * Move nodes to a position before the anchor node.\n * This is optimized to avoid unnecessary DOM operations.\n *\n * @param parent - Parent node to move nodes within\n * @param nodes - Array of nodes to move\n * @param anchor - Node to insert before (or null for end)\n */\nexport function moveNodesBefore(parent: Node, nodes: Node[], anchor: Node | null): void {\n // Insert in reverse order to maintain correct sequence\n // This way each node becomes the new anchor for the next\n for (let i = nodes.length - 1; i >= 0; i--) {\n const node = nodes[i]!\n if (!node || !(node instanceof Node)) {\n const message = isDev ? 'Invalid node in moveNodesBefore' : 'FICT:E_NODE'\n throw new Error(message)\n }\n // Only move if not already in correct position\n if (node.nextSibling !== anchor) {\n if (node.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {\n parent.ownerDocument.adoptNode(node)\n }\n try {\n parent.insertBefore(node, anchor)\n } catch (e: any) {\n if (parent.ownerDocument) {\n try {\n const clone = parent.ownerDocument.importNode(node, true)\n parent.insertBefore(clone, anchor)\n // Update the nodes array with the clone to maintain correct references.\n // This ensures future operations (like removal or reordering) work correctly.\n nodes[i] = clone\n if (isDev) {\n console.warn(\n `[fict] Node cloning fallback triggered during list reordering. ` +\n `This may indicate cross-document node insertion. ` +\n `The node reference has been updated to the clone.`,\n )\n }\n anchor = clone\n continue\n } catch {\n // Clone fallback failed\n }\n }\n throw e\n }\n }\n anchor = node\n }\n}\n\n/**\n * Remove an array of nodes from the DOM\n *\n * @param nodes - Array of nodes to remove\n */\n// Number.MAX_SAFE_INTEGER is 2^53 - 1, but we reset earlier to avoid any precision issues\nconst MAX_SAFE_VERSION = 0x1fffffffffffff // 2^53 - 1\n\nexport function createVersionedSignalAccessor<T>(initialValue: T): Signal<T> {\n let current = initialValue\n let version = 0\n const track = createSignal(version)\n\n function accessor(value?: T): T | void {\n if (arguments.length === 0) {\n track()\n return current\n }\n current = value as T\n // This is safe because we only care about version changes, not absolute values\n version = version >= MAX_SAFE_VERSION ? 1 : version + 1\n track(version)\n }\n\n return accessor as Signal<T>\n}\n\n// ============================================================================\n// Keyed List Container\n// ============================================================================\n\n/**\n * Create a container for managing a keyed list.\n * This sets up the marker nodes and provides cleanup.\n *\n * @returns Container object with markers, blocks map, and dispose function\n */\nfunction createKeyedListContainer<T = unknown>(\n startOverride?: Comment,\n endOverride?: Comment,\n): KeyedListContainer<T> {\n const startMarker = startOverride ?? document.createComment('fict:list:start')\n const endMarker = endOverride ?? document.createComment('fict:list:end')\n\n const dispose = () => {\n // Clean up all blocks\n for (const block of container.blocks.values()) {\n destroyRoot(block.root)\n // Nodes are removed by parent disposal or specific cleanup if needed\n // But for list disposal, we just clear the container\n }\n container.blocks.clear()\n container.nextBlocks.clear()\n\n // Remove nodes (including markers)\n // Check if markers are still in DOM before using Range\n if (!startMarker.parentNode || !endMarker.parentNode) {\n // Markers already removed, nothing to do\n container.currentNodes = []\n container.nextNodes = []\n container.orderedBlocks.length = 0\n container.nextOrderedBlocks.length = 0\n container.orderedIndexByKey.clear()\n return\n }\n const range = document.createRange()\n range.setStartBefore(startMarker)\n range.setEndAfter(endMarker)\n range.deleteContents()\n\n // Clear cache\n container.currentNodes = []\n container.nextNodes = []\n container.nextBlocks.clear()\n container.orderedBlocks.length = 0\n container.nextOrderedBlocks.length = 0\n container.orderedIndexByKey.clear()\n }\n\n const container: KeyedListContainer<T> = {\n startMarker,\n endMarker,\n blocks: new Map<string | number, KeyedBlock<T>>(),\n nextBlocks: new Map<string | number, KeyedBlock<T>>(),\n currentNodes: [startMarker, endMarker],\n nextNodes: [],\n orderedBlocks: [],\n nextOrderedBlocks: [],\n orderedIndexByKey: new Map<string | number, number>(),\n dispose,\n }\n\n return container\n}\n\n// ============================================================================\n// Block Creation Helpers\n// ============================================================================\n\n/**\n * Create a new keyed block with the given render function\n *\n * @param key - Unique key for this block\n * @param item - Initial item value\n * @param index - Initial index\n * @param render - Function that creates the DOM nodes and sets up bindings\n * @returns New KeyedBlock\n */\nfunction createKeyedBlock<T>(\n key: string | number,\n item: T,\n index: number,\n render: (item: Signal<T>, index: Signal<number>, key: string | number) => Node[],\n needsIndex = true,\n hostRoot?: RootContext,\n): KeyedBlock<T> {\n // Use versioned signal for all item types; avoid diffing proxy overhead for objects\n const itemSig = createVersionedSignalAccessor(item)\n\n const indexSig = needsIndex\n ? createSignal<number>(index)\n : (((next?: number) => {\n if (arguments.length === 0) return index\n index = next as number\n return index\n }) as Signal<number>)\n const root = createRootContext(hostRoot)\n const prevRoot = pushRoot(root)\n // maintaining proper cleanup chain. The scope will be disposed when\n // the root is destroyed, ensuring nested effects are properly cleaned up.\n let nodes: Node[] = []\n let scopeDispose: (() => void) | undefined\n\n // First, isolate from parent effect to prevent child effects from being\n // purged when the outer effect (e.g., performDiff) re-runs\n const prevSub = setActiveSub(undefined)\n\n try {\n // Create an effectScope that will track all effects created during render\n scopeDispose = effectScope(() => {\n const rendered = render(itemSig, indexSig, key)\n // If render returns real DOM nodes/arrays, preserve them to avoid\n // reparenting side-effects (tests may pre-insert them).\n if (\n rendered instanceof Node ||\n (Array.isArray(rendered) && rendered.every(n => n instanceof Node))\n ) {\n nodes = toNodeArray(rendered)\n } else {\n const element = createElement(rendered as unknown as FictNode)\n nodes = toNodeArray(element)\n }\n })\n\n // Register the scope cleanup with the root so effects are cleaned up\n // when the block is destroyed\n if (scopeDispose) {\n root.cleanups.push(scopeDispose)\n }\n } finally {\n setActiveSub(prevSub)\n popRoot(prevRoot)\n }\n\n return {\n key,\n nodes,\n root,\n item: itemSig,\n index: indexSig,\n rawItem: item,\n rawIndex: index,\n }\n}\n\n// ============================================================================\n// Utilities\n// ============================================================================\n\n/**\n * Check if a node is between two markers\n */\nexport function isNodeBetweenMarkers(\n node: Node,\n startMarker: Comment,\n endMarker: Comment,\n): boolean {\n let current: Node | null = startMarker.nextSibling\n while (current && current !== endMarker) {\n if (current === node) return true\n current = current.nextSibling\n }\n return false\n}\n\nfunction reorderBySwap<T>(\n parent: ParentNode & Node,\n first: KeyedBlock<T>,\n second: KeyedBlock<T>,\n): boolean {\n if (first === second) return false\n const firstNodes = first.nodes\n const secondNodes = second.nodes\n if (firstNodes.length === 0 || secondNodes.length === 0) return false\n const lastFirst = firstNodes[firstNodes.length - 1]!\n const lastSecond = secondNodes[secondNodes.length - 1]!\n const afterFirst = lastFirst.nextSibling\n const afterSecond = lastSecond.nextSibling\n moveNodesBefore(parent, firstNodes, afterSecond)\n moveNodesBefore(parent, secondNodes, afterFirst)\n return true\n}\n\nfunction getLISIndices(sequence: number[]): number[] {\n const predecessors = new Array<number>(sequence.length)\n const result: number[] = []\n\n for (let i = 0; i < sequence.length; i++) {\n const value = sequence[i]!\n if (value < 0) {\n predecessors[i] = -1\n continue\n }\n\n let low = 0\n let high = result.length\n while (low < high) {\n const mid = (low + high) >> 1\n if (sequence[result[mid]!]! < value) {\n low = mid + 1\n } else {\n high = mid\n }\n }\n\n predecessors[i] = low > 0 ? result[low - 1]! : -1\n if (low === result.length) {\n result.push(i)\n } else {\n result[low] = i\n }\n }\n\n const lis: number[] = new Array(result.length)\n let k = result.length > 0 ? result[result.length - 1]! : -1\n for (let i = result.length - 1; i >= 0; i--) {\n lis[i] = k\n k = predecessors[k]!\n }\n return lis\n}\n\nfunction reorderByLIS<T>(\n parent: ParentNode & Node,\n endMarker: Comment,\n prev: KeyedBlock<T>[],\n next: KeyedBlock<T>[],\n): boolean {\n const positions = new Map<KeyedBlock<T>, number>()\n for (let i = 0; i < prev.length; i++) {\n positions.set(prev[i]!, i)\n }\n\n const sequence = new Array<number>(next.length)\n for (let i = 0; i < next.length; i++) {\n const position = positions.get(next[i]!)\n if (position === undefined) return false\n sequence[i] = position\n }\n\n const lisIndices = getLISIndices(sequence)\n if (lisIndices.length === sequence.length) return true\n\n const inLIS = new Array<boolean>(sequence.length).fill(false)\n for (let i = 0; i < lisIndices.length; i++) {\n inLIS[lisIndices[i]!] = true\n }\n\n let anchor: Node | null = endMarker\n let moved = false\n for (let i = next.length - 1; i >= 0; i--) {\n const block = next[i]!\n const nodes = block.nodes\n if (nodes.length === 0) continue\n if (inLIS[i]) {\n anchor = nodes[0]!\n continue\n }\n moveNodesBefore(parent, nodes, anchor)\n anchor = nodes[0]!\n moved = true\n }\n\n return moved\n}\n\n// ============================================================================\n// High-Level List Binding (for compiler-generated code)\n// ============================================================================\n\n/**\n * Create a keyed list binding with automatic diffing and DOM updates.\n * This is used by compiler-generated code for efficient list rendering.\n *\n * @param getItems - Function that returns the current array of items\n * @param keyFn - Function to extract unique key from each item\n * @param renderItem - Function that creates DOM nodes for each item\n * @returns Binding handle with markers and dispose function\n */\nexport function createKeyedList<T>(\n getItems: () => T[],\n keyFn: (item: T, index: number) => string | number,\n renderItem: FineGrainedRenderItem<T>,\n needsIndex?: boolean,\n startMarker?: Comment,\n endMarker?: Comment,\n): KeyedListBinding {\n const resolvedNeedsIndex =\n arguments.length >= 4 ? !!needsIndex : renderItem.length > 1 /* has index param */\n return createFineGrainedKeyedList(\n getItems,\n keyFn,\n renderItem,\n resolvedNeedsIndex,\n startMarker,\n endMarker,\n )\n}\n\nfunction createFineGrainedKeyedList<T>(\n getItems: () => T[],\n keyFn: (item: T, index: number) => string | number,\n renderItem: FineGrainedRenderItem<T>,\n needsIndex: boolean,\n startOverride?: Comment,\n endOverride?: Comment,\n): KeyedListBinding {\n const container = createKeyedListContainer<T>(startOverride, endOverride)\n const hostRoot = getCurrentRoot()\n const useProvided = !!(startOverride && endOverride)\n const fragment = useProvided ? container.startMarker : document.createDocumentFragment()\n if (!useProvided) {\n ;(fragment as DocumentFragment).append(container.startMarker, container.endMarker)\n }\n let disposed = false\n let effectDispose: (() => void) | undefined\n let connectObserver: MutationObserver | null = null\n let effectStarted = false\n let startScheduled = false\n let initialHydrating = __fictIsHydrating()\n\n const collectBetween = (): Node[] => {\n const nodes: Node[] = []\n let cursor = container.startMarker.nextSibling\n while (cursor && cursor !== container.endMarker) {\n nodes.push(cursor)\n cursor = cursor.nextSibling\n }\n return nodes\n }\n\n const getConnectedParent = (): (ParentNode & Node) | null => {\n const endParent = container.endMarker.parentNode\n const startParent = container.startMarker.parentNode\n if (\n endParent &&\n startParent &&\n endParent === startParent &&\n (endParent as Node).nodeType !== 11\n ) {\n const parentNode = endParent as ParentNode & Node\n if ('isConnected' in parentNode && !parentNode.isConnected) return null\n return parentNode\n }\n if (endParent && startParent && endParent === startParent && isShadowRoot(endParent as Node)) {\n const shadowRoot = endParent as ShadowRoot\n const host = shadowRoot.host\n if ('isConnected' in host && !host.isConnected) return null\n return shadowRoot as unknown as ParentNode & Node\n }\n return null\n }\n\n const performDiff = () => {\n if (disposed) return\n // During SSR, render synchronously without waiting for DOM connection\n const isSSR = __fictIsSSR()\n const parent = isSSR\n ? (container.startMarker.parentNode as (ParentNode & Node) | null)\n : getConnectedParent()\n if (!parent) return\n batch(() => {\n const oldBlocks = container.blocks\n const newBlocks = container.nextBlocks\n const prevOrderedBlocks = container.orderedBlocks\n const nextOrderedBlocks = container.nextOrderedBlocks\n const orderedIndexByKey = container.orderedIndexByKey\n const newItems = getItems()\n\n if (initialHydrating && isHydratingActive()) {\n initialHydrating = false\n newBlocks.clear()\n nextOrderedBlocks.length = 0\n orderedIndexByKey.clear()\n\n if (newItems.length === 0) {\n oldBlocks.clear()\n prevOrderedBlocks.length = 0\n container.currentNodes = [container.startMarker, container.endMarker]\n container.nextNodes.length = 0\n return\n }\n\n const createdBlocks: KeyedBlock<T>[] = []\n withHydrationRange(\n container.startMarker.nextSibling,\n container.endMarker,\n parent.ownerDocument ?? document,\n () => {\n for (let index = 0; index < newItems.length; index++) {\n const item = newItems[index]!\n const key = keyFn(item, index)\n if (newBlocks.has(key)) {\n if (isDev) {\n console.warn(\n `[fict] Duplicate key \"${String(key)}\" detected in list hydration. ` +\n `Each item should have a unique key.`,\n )\n }\n const existing = newBlocks.get(key)\n if (existing) {\n destroyRoot(existing.root)\n removeNodes(existing.nodes)\n }\n }\n const block = createKeyedBlock<T>(key, item, index, renderItem, needsIndex, hostRoot)\n createdBlocks.push(block)\n newBlocks.set(key, block)\n orderedIndexByKey.set(key, nextOrderedBlocks.length)\n nextOrderedBlocks.push(block)\n }\n },\n )\n\n container.blocks = newBlocks\n container.nextBlocks = oldBlocks\n container.orderedBlocks = nextOrderedBlocks\n container.nextOrderedBlocks = prevOrderedBlocks\n oldBlocks.clear()\n prevOrderedBlocks.length = 0\n container.currentNodes = [container.startMarker, ...collectBetween(), container.endMarker]\n container.nextNodes.length = 0\n\n for (const block of createdBlocks) {\n if (newBlocks.get(block.key) === block) {\n flushOnMount(block.root)\n }\n }\n\n return\n }\n\n if (newItems.length === 0) {\n if (oldBlocks.size > 0) {\n // Destroy all block roots first\n for (const block of oldBlocks.values()) {\n destroyRoot(block.root)\n }\n // Use Range.deleteContents for efficient bulk DOM removal\n const range = document.createRange()\n range.setStartAfter(container.startMarker)\n range.setEndBefore(container.endMarker)\n range.deleteContents()\n }\n oldBlocks.clear()\n newBlocks.clear()\n prevOrderedBlocks.length = 0\n nextOrderedBlocks.length = 0\n orderedIndexByKey.clear()\n container.currentNodes.length = 0\n container.currentNodes.push(container.startMarker, container.endMarker)\n container.nextNodes.length = 0\n return\n }\n\n const prevCount = prevOrderedBlocks.length\n if (prevCount > 0 && newItems.length === prevCount && orderedIndexByKey.size === prevCount) {\n let stableOrder = true\n const seen = new Set<string | number>()\n for (let i = 0; i < prevCount; i++) {\n const item = newItems[i]!\n const key = keyFn(item, i)\n if (seen.has(key) || prevOrderedBlocks[i]!.key !== key) {\n stableOrder = false\n break\n }\n seen.add(key)\n }\n if (stableOrder) {\n for (let i = 0; i < prevCount; i++) {\n const item = newItems[i]!\n const block = prevOrderedBlocks[i]!\n if (block.rawItem !== item) {\n block.rawItem = item\n block.item(item)\n }\n if (needsIndex && block.rawIndex !== i) {\n block.rawIndex = i\n block.index(i)\n }\n }\n return\n }\n }\n\n newBlocks.clear()\n nextOrderedBlocks.length = 0\n orderedIndexByKey.clear()\n const createdBlocks: KeyedBlock<T>[] = []\n let appendCandidate = prevCount > 0 && newItems.length >= prevCount\n const appendedBlocks: KeyedBlock<T>[] = []\n let mismatchCount = 0\n let mismatchFirst = -1\n let mismatchSecond = -1\n let hasDuplicateKey = false\n\n // Phase 1: Build new blocks map (reuse or create)\n newItems.forEach((item, index) => {\n const key = keyFn(item, index)\n // Micro-optimization: single Map.get instead of has+get\n let block = oldBlocks.get(key)\n const existed = block !== undefined\n\n if (block) {\n if (block.rawItem !== item) {\n block.rawItem = item\n block.item(item)\n }\n if (needsIndex && block.rawIndex !== index) {\n block.rawIndex = index\n block.index(index)\n }\n }\n\n if (block) {\n // Reusing existing block from oldBlocks\n newBlocks.set(key, block)\n oldBlocks.delete(key)\n } else {\n // If newBlocks already has this key (duplicate key case), clean up the previous block\n const existingBlock = newBlocks.get(key)\n if (existingBlock) {\n if (isDev) {\n console.warn(\n `[fict] Duplicate key \"${String(key)}\" detected in list rendering. ` +\n `Each item should have a unique key. The previous item with this key will be replaced.`,\n )\n }\n destroyRoot(existingBlock.root)\n removeNodes(existingBlock.nodes)\n }\n // Create new block\n block = createKeyedBlock<T>(key, item, index, renderItem, needsIndex, hostRoot)\n createdBlocks.push(block)\n }\n\n const resolvedBlock = block\n\n newBlocks.set(key, resolvedBlock)\n\n // Micro-optimization: single Map.get instead of checking position multiple times\n const position = orderedIndexByKey.get(key)\n if (position !== undefined) {\n appendCandidate = false\n hasDuplicateKey = true\n const prior = nextOrderedBlocks[position]\n if (prior && prior !== resolvedBlock) {\n destroyRoot(prior.root)\n removeNodes(prior.nodes)\n }\n nextOrderedBlocks[position] = resolvedBlock\n } else {\n if (appendCandidate) {\n if (index < prevCount) {\n if (!prevOrderedBlocks[index] || prevOrderedBlocks[index]!.key !== key) {\n appendCandidate = false\n }\n } else if (existed) {\n appendCandidate = false\n }\n }\n const nextIndex = nextOrderedBlocks.length\n orderedIndexByKey.set(key, nextIndex)\n nextOrderedBlocks.push(resolvedBlock)\n if (\n mismatchCount < 3 &&\n (nextIndex >= prevCount || prevOrderedBlocks[nextIndex] !== resolvedBlock)\n ) {\n if (mismatchCount === 0) {\n mismatchFirst = nextIndex\n } else if (mismatchCount === 1) {\n mismatchSecond = nextIndex\n }\n mismatchCount++\n }\n }\n\n if (appendCandidate && index >= prevCount) {\n appendedBlocks.push(resolvedBlock)\n }\n })\n\n const canAppend =\n appendCandidate &&\n prevCount > 0 &&\n newItems.length > prevCount &&\n oldBlocks.size === 0 &&\n appendedBlocks.length > 0\n if (canAppend) {\n const appendedNodes: Node[] = []\n for (const block of appendedBlocks) {\n for (let i = 0; i < block.nodes.length; i++) {\n appendedNodes.push(block.nodes[i]!)\n }\n }\n if (appendedNodes.length > 0) {\n insertNodesBefore(parent, appendedNodes, container.endMarker)\n const currentNodes = container.currentNodes\n currentNodes.pop()\n for (let i = 0; i < appendedNodes.length; i++) {\n currentNodes.push(appendedNodes[i]!)\n }\n currentNodes.push(container.endMarker)\n }\n\n container.blocks = newBlocks\n container.nextBlocks = oldBlocks\n container.orderedBlocks = nextOrderedBlocks\n container.nextOrderedBlocks = prevOrderedBlocks\n for (const block of createdBlocks) {\n if (newBlocks.get(block.key) === block) {\n flushOnMount(block.root)\n }\n }\n return\n }\n\n // Phase 2: Remove old blocks that are no longer in the list\n if (oldBlocks.size > 0) {\n for (const block of oldBlocks.values()) {\n destroyRoot(block.root)\n removeNodes(block.nodes)\n }\n oldBlocks.clear()\n }\n\n const canReorderInPlace =\n createdBlocks.length === 0 &&\n oldBlocks.size === 0 &&\n nextOrderedBlocks.length === prevOrderedBlocks.length\n\n let skipReconcile = false\n let updateNodeBuffer = true\n\n if (canReorderInPlace && nextOrderedBlocks.length > 0 && !hasDuplicateKey) {\n if (mismatchCount === 0) {\n skipReconcile = true\n updateNodeBuffer = false\n } else if (\n mismatchCount === 2 &&\n prevOrderedBlocks[mismatchFirst] === nextOrderedBlocks[mismatchSecond] &&\n prevOrderedBlocks[mismatchSecond] === nextOrderedBlocks[mismatchFirst]\n ) {\n if (\n reorderBySwap(\n parent,\n prevOrderedBlocks[mismatchFirst]!,\n prevOrderedBlocks[mismatchSecond]!,\n )\n ) {\n skipReconcile = true\n }\n } else if (\n reorderByLIS(parent, container.endMarker, prevOrderedBlocks, nextOrderedBlocks)\n ) {\n skipReconcile = true\n }\n }\n\n // Phase 3: Reconcile DOM with buffered node arrays\n if (!skipReconcile && (newBlocks.size > 0 || container.currentNodes.length > 0)) {\n const prevNodes = container.currentNodes\n const nextNodes = container.nextNodes\n nextNodes.length = 0\n nextNodes.push(container.startMarker)\n\n for (let i = 0; i < nextOrderedBlocks.length; i++) {\n const nodes = nextOrderedBlocks[i]!.nodes\n for (let j = 0; j < nodes.length; j++) {\n nextNodes.push(nodes[j]!)\n }\n }\n\n nextNodes.push(container.endMarker)\n\n reconcileArrays(parent, prevNodes, nextNodes)\n\n // Swap buffers to reuse arrays on next diff\n container.currentNodes = nextNodes\n container.nextNodes = prevNodes\n } else if (skipReconcile && updateNodeBuffer) {\n const prevNodes = container.currentNodes\n const nextNodes = container.nextNodes\n nextNodes.length = 0\n nextNodes.push(container.startMarker)\n for (let i = 0; i < nextOrderedBlocks.length; i++) {\n const nodes = nextOrderedBlocks[i]!.nodes\n for (let j = 0; j < nodes.length; j++) {\n nextNodes.push(nodes[j]!)\n }\n }\n nextNodes.push(container.endMarker)\n container.currentNodes = nextNodes\n container.nextNodes = prevNodes\n }\n\n // Swap block maps for reuse\n container.blocks = newBlocks\n container.nextBlocks = oldBlocks\n container.orderedBlocks = nextOrderedBlocks\n container.nextOrderedBlocks = prevOrderedBlocks\n for (const block of createdBlocks) {\n if (newBlocks.get(block.key) === block) {\n flushOnMount(block.root)\n }\n }\n })\n }\n\n const disconnectObserver = () => {\n connectObserver?.disconnect()\n connectObserver = null\n }\n\n const ensureEffectStarted = (): boolean => {\n if (disposed || effectStarted) return effectStarted\n // During SSR, render synchronously without waiting for DOM connection\n const isSSR = __fictIsSSR()\n const parent = isSSR\n ? (container.startMarker.parentNode as (ParentNode & Node) | null)\n : getConnectedParent()\n if (!parent) return false\n const start = () => {\n effectDispose = createRenderEffect(performDiff)\n effectStarted = true\n }\n if (hostRoot) {\n const prev = pushRoot(hostRoot)\n try {\n start()\n } finally {\n popRoot(prev)\n }\n } else {\n start()\n }\n return true\n }\n\n const waitForConnection = () => {\n if (connectObserver || typeof MutationObserver === 'undefined') return\n const root = container.startMarker.getRootNode?.() ?? document\n const shadowRoot =\n root && root.nodeType === 11 && isShadowRoot(root as Node) ? (root as ShadowRoot) : null\n connectObserver = new MutationObserver(() => {\n if (disposed) return\n if (getConnectedParent()) {\n disconnectObserver()\n if (ensureEffectStarted()) {\n flush()\n }\n }\n })\n connectObserver.observe(document, { childList: true, subtree: true })\n if (shadowRoot) {\n connectObserver.observe(shadowRoot, { childList: true, subtree: true })\n }\n }\n\n const scheduleStart = () => {\n if (startScheduled || disposed || effectStarted) return\n startScheduled = true\n const run = () => {\n startScheduled = false\n if (!ensureEffectStarted()) {\n waitForConnection()\n }\n }\n if (typeof queueMicrotask === 'function') {\n queueMicrotask(run)\n } else {\n Promise.resolve()\n .then(run)\n .catch(() => undefined)\n }\n }\n\n scheduleStart()\n\n return {\n get marker() {\n scheduleStart()\n return fragment\n },\n startMarker: container.startMarker,\n endMarker: container.endMarker,\n // Flush pending items - call after markers are inserted into DOM\n flush: () => {\n if (disposed) return\n scheduleStart()\n if (ensureEffectStarted()) {\n flush()\n } else {\n waitForConnection()\n }\n },\n dispose: () => {\n disposed = true\n effectDispose?.()\n disconnectObserver()\n container.dispose()\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAkCe,SAAR,gBAAiC,YAAwB,GAAW,GAAiB;AAC1F,QAAM,UAAU,EAAE;AAClB,MAAI,OAAO,EAAE;AACb,MAAI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pE,QAAI,YAAY;AACd,sBAAgB,QAAQ,YAAY,EAAE,WAAW,MAAM,SAAS,KAAK,CAAC;AAAA,IACxE;AAAA,EACF;AAEA,QAAM,gBAAgB,MAAM;AAC1B,QAAI,kBAAkB,YAAY,cAAe;AACjD,qBAAiB;AACjB,UAAM,MAAM,MAAM;AAChB,uBAAiB;AACjB,UAAI,CAAC,oBAAoB,GAAG;AAC1B,0BAAkB;AAAA,MACpB;AAAA,IACF;AACA,QAAI,OAAO,mBAAmB,YAAY;AACxC,qBAAe,GAAG;AAAA,IACpB,OAAO;AACL,cAAQ,QAAQ,EACb,KAAK,GAAG,EACR,MAAM,MAAM,MAAS;AAAA,IAC1B;AAAA,EACF;AAEA,gBAAc;AAEd,SAAO;AAAA,IACL,IAAI,SAAS;AACX,oBAAc;AACd,aAAO;AAAA,IACT;AAAA,IACA,aAAa,UAAU;AAAA,IACvB,WAAW,UAAU;AAAA;AAAA,IAErB,OAAO,MAAM;AACX,UAAI,SAAU;AACd,oBAAc;AACd,UAAI,oBAAoB,GAAG;AACzB,cAAM;AAAA,MACR,OAAO;AACL,0BAAkB;AAAA,MACpB;AAAA,IACF;AAAA,IACA,SAAS,MAAM;AACb,iBAAW;AACX,sBAAgB;AAChB,yBAAmB;AACnB,gBAAU,QAAQ;AAAA,IACpB;AAAA,EACF;AACF;","names":["createdBlocks"]}
@@ -40,7 +40,90 @@ import {
40
40
  setTransitionContext,
41
41
  signal,
42
42
  untrack
43
- } from "./chunk-7YQK3XKY.js";
43
+ } from "./chunk-F4RVNXOL.js";
44
+
45
+ // src/transition.ts
46
+ function startTransition(fn) {
47
+ const prev = setTransitionContext(true);
48
+ try {
49
+ fn();
50
+ } finally {
51
+ setTransitionContext(prev);
52
+ scheduleFlush();
53
+ }
54
+ }
55
+ function useTransition() {
56
+ const pending = signal(false);
57
+ let pendingCount = 0;
58
+ const beginPending = () => {
59
+ pendingCount += 1;
60
+ if (pendingCount === 1) {
61
+ pending(true);
62
+ }
63
+ };
64
+ const endPending = () => {
65
+ if (pendingCount === 0) return;
66
+ pendingCount -= 1;
67
+ if (pendingCount === 0) {
68
+ pending(false);
69
+ }
70
+ };
71
+ const start = (fn) => {
72
+ beginPending();
73
+ let result;
74
+ let thrown;
75
+ let didThrow = false;
76
+ startTransition(() => {
77
+ try {
78
+ result = fn();
79
+ } catch (err) {
80
+ thrown = err;
81
+ didThrow = true;
82
+ }
83
+ });
84
+ if (didThrow) {
85
+ endPending();
86
+ throw thrown;
87
+ }
88
+ if (result && typeof result.then === "function") {
89
+ void Promise.resolve(result).catch((error) => {
90
+ if (typeof console !== "undefined" && typeof console.error === "function") {
91
+ console.error("[fict/transition] Async transition failed.", error);
92
+ }
93
+ }).finally(() => {
94
+ endPending();
95
+ });
96
+ return;
97
+ }
98
+ if (typeof queueMicrotask === "function") {
99
+ queueMicrotask(endPending);
100
+ } else {
101
+ Promise.resolve().then(endPending);
102
+ }
103
+ };
104
+ return [() => pending(), start];
105
+ }
106
+ function useDeferredValue(getValue) {
107
+ const deferredValue = signal(getValue());
108
+ createEffect(() => {
109
+ const newValue = getValue();
110
+ const currentDeferred = untrack(() => deferredValue());
111
+ if (currentDeferred !== newValue) {
112
+ startTransition(() => {
113
+ deferredValue(newValue);
114
+ });
115
+ }
116
+ });
117
+ return () => deferredValue();
118
+ }
119
+
120
+ // src/scheduler.ts
121
+ function batch2(fn) {
122
+ return batch(fn);
123
+ }
124
+ function untrack2(fn) {
125
+ return untrack(fn);
126
+ }
44
127
 
45
128
  // src/jsx.ts
46
129
  var Fragment = Symbol("Fragment");
@@ -247,85 +330,6 @@ function resolvePath(root, path) {
247
330
  return current;
248
331
  }
249
332
 
250
- // src/transition.ts
251
- function startTransition(fn) {
252
- const prev = setTransitionContext(true);
253
- try {
254
- fn();
255
- } finally {
256
- setTransitionContext(prev);
257
- scheduleFlush();
258
- }
259
- }
260
- function useTransition() {
261
- const pending = signal(false);
262
- let pendingCount = 0;
263
- const beginPending = () => {
264
- pendingCount += 1;
265
- if (pendingCount === 1) {
266
- pending(true);
267
- }
268
- };
269
- const endPending = () => {
270
- if (pendingCount === 0) return;
271
- pendingCount -= 1;
272
- if (pendingCount === 0) {
273
- pending(false);
274
- }
275
- };
276
- const start = (fn) => {
277
- beginPending();
278
- let result;
279
- let thrown;
280
- let didThrow = false;
281
- startTransition(() => {
282
- try {
283
- result = fn();
284
- } catch (err) {
285
- thrown = err;
286
- didThrow = true;
287
- }
288
- });
289
- if (didThrow) {
290
- endPending();
291
- throw thrown;
292
- }
293
- if (result && typeof result.then === "function") {
294
- Promise.resolve(result).finally(() => {
295
- endPending();
296
- });
297
- return;
298
- }
299
- if (typeof queueMicrotask === "function") {
300
- queueMicrotask(endPending);
301
- } else {
302
- Promise.resolve().then(endPending);
303
- }
304
- };
305
- return [() => pending(), start];
306
- }
307
- function useDeferredValue(getValue) {
308
- const deferredValue = signal(getValue());
309
- createEffect(() => {
310
- const newValue = getValue();
311
- const currentDeferred = untrack(() => deferredValue());
312
- if (currentDeferred !== newValue) {
313
- startTransition(() => {
314
- deferredValue(newValue);
315
- });
316
- }
317
- });
318
- return () => deferredValue();
319
- }
320
-
321
- // src/scheduler.ts
322
- function batch2(fn) {
323
- return batch(fn);
324
- }
325
- function untrack2(fn) {
326
- return untrack(fn);
327
- }
328
-
329
333
  // src/hydration.ts
330
334
  var hydrationStack = [];
331
335
  function withHydration(root, fn) {
@@ -1375,7 +1379,8 @@ function assignProp(node, prop2, value, prev, isSVG, skipRef, props) {
1375
1379
  function toPropertyName(name) {
1376
1380
  return name.toLowerCase().replace(/-([a-z])/g, (_, w) => w.toUpperCase());
1377
1381
  }
1378
- function createConditional(condition, renderTrue, createElementFn, renderFalse, startOverride, endOverride) {
1382
+ function createConditional(condition, renderTrue, createElementFn, renderFalse, startOverride, endOverride, options) {
1383
+ const trackBranchReads = options?.trackBranchReads === true;
1379
1384
  const useProvided = !!(startOverride && endOverride);
1380
1385
  const startMarker = useProvided ? startOverride : document.createComment("fict:cond:start");
1381
1386
  const endMarker = useProvided ? endOverride : document.createComment("fict:cond:end");
@@ -1425,7 +1430,7 @@ function createConditional(condition, renderTrue, createElementFn, renderFalse,
1425
1430
  endMarker,
1426
1431
  parent.ownerDocument ?? document,
1427
1432
  () => {
1428
- const output = untrack(render3);
1433
+ const output = trackBranchReads ? render3() : untrack(render3);
1429
1434
  if (output == null || output === false) {
1430
1435
  return;
1431
1436
  }
@@ -1456,10 +1461,96 @@ function createConditional(condition, renderTrue, createElementFn, renderFalse,
1456
1461
  }
1457
1462
  return;
1458
1463
  }
1459
- if (lastCondition === cond && currentNodes.length > 0) {
1460
- return;
1461
- }
1462
- if (lastCondition === cond && lastCondition === false && renderFalse === void 0) {
1464
+ if (!trackBranchReads) {
1465
+ if (lastCondition === cond && currentNodes.length > 0) {
1466
+ return;
1467
+ }
1468
+ if (lastCondition === cond && lastCondition === false && renderFalse === void 0) {
1469
+ return;
1470
+ }
1471
+ } else if (lastCondition === cond) {
1472
+ const render3 = cond ? renderTrue : renderFalse;
1473
+ if (!render3) {
1474
+ return;
1475
+ }
1476
+ let patched = false;
1477
+ const scratchRoot = createRootContext(hostRoot);
1478
+ const prevScratch = pushRoot(scratchRoot);
1479
+ let handledPatchError = false;
1480
+ let scratchOutput = null;
1481
+ try {
1482
+ const output = render3();
1483
+ scratchOutput = output;
1484
+ if (output != null && output !== false) {
1485
+ if (currentNodes.length === 1) {
1486
+ patched = patchNode(currentNodes[0] ?? null, output);
1487
+ }
1488
+ if (!patched && Array.isArray(output)) {
1489
+ patched = _patchFragmentChildren(currentNodes, output);
1490
+ }
1491
+ if (!patched && _isFragmentVNode(output)) {
1492
+ patched = _patchFragmentChildren(currentNodes, output.props?.children);
1493
+ }
1494
+ }
1495
+ } catch (err) {
1496
+ if (handleSuspend(err, scratchRoot)) {
1497
+ handledPatchError = true;
1498
+ return;
1499
+ }
1500
+ if (handleError(err, { source: "renderChild" }, scratchRoot)) {
1501
+ handledPatchError = true;
1502
+ return;
1503
+ }
1504
+ throw err;
1505
+ } finally {
1506
+ popRoot(prevScratch);
1507
+ }
1508
+ if (handledPatchError) {
1509
+ destroyRoot(scratchRoot);
1510
+ return;
1511
+ }
1512
+ if (patched) {
1513
+ destroyRoot(scratchRoot);
1514
+ return;
1515
+ }
1516
+ lastCondition = cond;
1517
+ if (currentRoot) {
1518
+ destroyRoot(currentRoot);
1519
+ currentRoot = null;
1520
+ }
1521
+ removeNodes(currentNodes);
1522
+ currentNodes = [];
1523
+ const prev2 = pushRoot(scratchRoot);
1524
+ let handledError2 = false;
1525
+ try {
1526
+ if (scratchOutput == null || scratchOutput === false) {
1527
+ return;
1528
+ }
1529
+ const el = createElementFn(scratchOutput);
1530
+ const nodes = toNodeArray(el);
1531
+ insertNodesBefore(parent, nodes, endMarker);
1532
+ currentNodes = nodes;
1533
+ } catch (err) {
1534
+ if (handleSuspend(err, scratchRoot)) {
1535
+ handledError2 = true;
1536
+ destroyRoot(scratchRoot);
1537
+ return;
1538
+ }
1539
+ if (handleError(err, { source: "renderChild" }, scratchRoot)) {
1540
+ handledError2 = true;
1541
+ destroyRoot(scratchRoot);
1542
+ return;
1543
+ }
1544
+ throw err;
1545
+ } finally {
1546
+ popRoot(prev2);
1547
+ if (!handledError2) {
1548
+ flushOnMount(scratchRoot);
1549
+ currentRoot = scratchRoot;
1550
+ } else {
1551
+ currentRoot = null;
1552
+ }
1553
+ }
1463
1554
  return;
1464
1555
  }
1465
1556
  lastCondition = cond;
@@ -1477,7 +1568,7 @@ function createConditional(condition, renderTrue, createElementFn, renderFalse,
1477
1568
  const prev = pushRoot(root);
1478
1569
  let handledError = false;
1479
1570
  try {
1480
- const output = untrack(render2);
1571
+ const output = trackBranchReads ? render2() : untrack(render2);
1481
1572
  if (output == null || output === false) {
1482
1573
  return;
1483
1574
  }
@@ -1603,6 +1694,96 @@ function createPortal(container, render2, createElementFn) {
1603
1694
  dispose: portalDispose
1604
1695
  };
1605
1696
  }
1697
+ function patchElement(el, output) {
1698
+ if (output && typeof output === "object" && !(output instanceof Node)) {
1699
+ const vnode = output;
1700
+ if (typeof vnode.type === "string" && vnode.type.toLowerCase() === el.tagName.toLowerCase()) {
1701
+ const children = vnode.props?.children;
1702
+ const props = vnode.props ?? {};
1703
+ for (const [key, value] of Object.entries(props)) {
1704
+ if (key === "children" || key === "key") continue;
1705
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null || value === void 0) {
1706
+ if (key === "class" || key === "className") {
1707
+ el.setAttribute("class", value === false || value === null ? "" : String(value));
1708
+ } else if (key === "style" && typeof value === "string") {
1709
+ ;
1710
+ el.style.cssText = value;
1711
+ } else if (value === false || value === null || value === void 0) {
1712
+ el.removeAttribute(key);
1713
+ } else if (value === true) {
1714
+ el.setAttribute(key, "");
1715
+ } else {
1716
+ el.setAttribute(key, String(value));
1717
+ }
1718
+ }
1719
+ }
1720
+ if (typeof children === "string" || typeof children === "number" || children === null || children === void 0 || children === false) {
1721
+ el.textContent = children === null || children === void 0 || children === false ? "" : String(children);
1722
+ return true;
1723
+ }
1724
+ if (children && typeof children === "object" && !Array.isArray(children) && !(children instanceof Node)) {
1725
+ const childVNode = children;
1726
+ if (typeof childVNode.type === "string") {
1727
+ const childEl = el.querySelector(childVNode.type);
1728
+ if (childEl && patchElement(childEl, children)) {
1729
+ return true;
1730
+ }
1731
+ }
1732
+ }
1733
+ return false;
1734
+ }
1735
+ }
1736
+ return false;
1737
+ }
1738
+ function patchNode(currentNode, nextOutput) {
1739
+ if (!currentNode) return false;
1740
+ if (currentNode instanceof Text && (nextOutput === null || nextOutput === void 0 || nextOutput === false || typeof nextOutput === "string" || typeof nextOutput === "number" || nextOutput instanceof Text)) {
1741
+ const nextText = nextOutput instanceof Text ? nextOutput.data : nextOutput === null || nextOutput === void 0 || nextOutput === false ? "" : String(nextOutput);
1742
+ currentNode.data = nextText;
1743
+ return true;
1744
+ }
1745
+ if (currentNode instanceof Element && patchElement(currentNode, nextOutput)) {
1746
+ return true;
1747
+ }
1748
+ if (nextOutput instanceof Node && currentNode === nextOutput) {
1749
+ return true;
1750
+ }
1751
+ return false;
1752
+ }
1753
+ function _isFragmentVNode(value) {
1754
+ return value != null && typeof value === "object" && !(value instanceof Node) && value.type === Fragment;
1755
+ }
1756
+ function normalizeChildren(children, result = []) {
1757
+ if (children === void 0) {
1758
+ return result;
1759
+ }
1760
+ if (Array.isArray(children)) {
1761
+ for (const child of children) {
1762
+ normalizeChildren(child, result);
1763
+ }
1764
+ return result;
1765
+ }
1766
+ if (children === null || children === false) {
1767
+ return result;
1768
+ }
1769
+ if (_isFragmentVNode(children)) {
1770
+ return normalizeChildren(children.props?.children, result);
1771
+ }
1772
+ result.push(children);
1773
+ return result;
1774
+ }
1775
+ function _patchFragmentChildren(nodes, children) {
1776
+ const normalized = normalizeChildren(children);
1777
+ if (normalized.length !== nodes.length) {
1778
+ return false;
1779
+ }
1780
+ for (let i = 0; i < normalized.length; i++) {
1781
+ if (!patchNode(nodes[i], normalized[i])) {
1782
+ return false;
1783
+ }
1784
+ }
1785
+ return true;
1786
+ }
1606
1787
 
1607
1788
  // src/props.ts
1608
1789
  var PROP_GETTER_MARKER2 = Symbol.for("fict:prop-getter");
@@ -1819,6 +2000,32 @@ var SVG_NS = "http://www.w3.org/2000/svg";
1819
2000
  var MATHML_NS = "http://www.w3.org/1998/Math/MathML";
1820
2001
  var isDev2 = typeof __DEV__ !== "undefined" ? __DEV__ : typeof process !== "undefined" && process.env?.NODE_ENV !== "production";
1821
2002
  var nextComponentId = 1;
2003
+ function collectComponentMountElements(node) {
2004
+ if (node instanceof DocumentFragment) {
2005
+ return Array.from(node.childNodes).filter(
2006
+ (child) => child instanceof HTMLElement
2007
+ );
2008
+ }
2009
+ if (node instanceof HTMLElement) {
2010
+ if (node.hasAttribute("data-fict-host")) {
2011
+ const children = Array.from(node.children).filter(
2012
+ (child) => child instanceof HTMLElement
2013
+ );
2014
+ if (children.length > 0) return children;
2015
+ }
2016
+ return [node];
2017
+ }
2018
+ return [];
2019
+ }
2020
+ function annotateComponentElements(elements, componentId, componentName) {
2021
+ for (const element of elements) {
2022
+ element.setAttribute("data-fict-component", componentName);
2023
+ element.setAttribute("data-fict-component-id", String(componentId));
2024
+ const annotated = element;
2025
+ annotated.__fict_component_id__ = componentId;
2026
+ annotated.__fict_component_name__ = componentName;
2027
+ }
2028
+ }
1822
2029
  function render(view, container) {
1823
2030
  const root = createRootContext();
1824
2031
  const prev = pushRoot(root);
@@ -1949,10 +2156,11 @@ function createElementWithContext(node, namespace) {
1949
2156
  });
1950
2157
  const props = createPropsProxy(baseProps);
1951
2158
  const hook = isDev2 ? getDevtoolsHook() : void 0;
2159
+ const componentName = vnode.type.name || "Anonymous";
1952
2160
  const parentId = hook ? __fictGetCurrentComponentId() : void 0;
1953
2161
  const componentId = hook ? nextComponentId++ : void 0;
1954
2162
  if (hook?.registerComponent && componentId !== void 0) {
1955
- hook.registerComponent(componentId, vnode.type.name || "Anonymous", parentId);
2163
+ hook.registerComponent(componentId, componentName, parentId);
1956
2164
  }
1957
2165
  const ctx = __fictPushContext();
1958
2166
  if (componentId !== void 0) {
@@ -1963,9 +2171,13 @@ function createElementWithContext(node, namespace) {
1963
2171
  }
1964
2172
  try {
1965
2173
  const rendered = vnode.type(props);
2174
+ let mountElements;
2175
+ if (hook && componentId !== void 0) {
2176
+ hook.componentRender?.(componentId);
2177
+ }
1966
2178
  if (hook && componentId !== void 0) {
1967
2179
  onMount(() => {
1968
- hook.componentMount?.(componentId);
2180
+ hook.componentMount?.(componentId, mountElements);
1969
2181
  });
1970
2182
  onCleanup(() => hook.componentUnmount?.(componentId));
1971
2183
  }
@@ -1988,9 +2200,18 @@ function createElementWithContext(node, namespace) {
1988
2200
  } else {
1989
2201
  host.appendChild(content);
1990
2202
  }
2203
+ if (hook && componentId !== void 0) {
2204
+ mountElements = collectComponentMountElements(host);
2205
+ annotateComponentElements(mountElements, componentId, componentName);
2206
+ }
1991
2207
  return host;
1992
2208
  }
1993
- return createElementWithContext(rendered, namespace);
2209
+ const componentRoot = createElementWithContext(rendered, namespace);
2210
+ if (hook && componentId !== void 0) {
2211
+ mountElements = collectComponentMountElements(componentRoot);
2212
+ annotateComponentElements(mountElements, componentId, componentName);
2213
+ }
2214
+ return componentRoot;
1994
2215
  } catch (err) {
1995
2216
  if (handleSuspend(err)) {
1996
2217
  return document.createComment("fict:suspend");
@@ -2350,19 +2571,19 @@ function eventNameFromProp(key) {
2350
2571
  }
2351
2572
 
2352
2573
  export {
2574
+ startTransition,
2575
+ useTransition,
2576
+ useDeferredValue,
2577
+ batch2 as batch,
2578
+ untrack2 as untrack,
2579
+ Fragment,
2353
2580
  withHydrationRange,
2354
2581
  isHydratingActive,
2355
- Fragment,
2356
2582
  toNodeArray,
2357
2583
  insertNodesBefore,
2358
2584
  removeNodes,
2359
2585
  getSlotEnd,
2360
2586
  resolvePath,
2361
- startTransition,
2362
- useTransition,
2363
- useDeferredValue,
2364
- batch2 as batch,
2365
- untrack2 as untrack,
2366
2587
  isReactive,
2367
2588
  nonReactive,
2368
2589
  reactive,
@@ -2407,4 +2628,4 @@ export {
2407
2628
  createElement,
2408
2629
  template
2409
2630
  };
2410
- //# sourceMappingURL=chunk-4LCHQ7U4.js.map
2631
+ //# sourceMappingURL=chunk-R6FINS25.js.map