@askrjs/askr 0.0.49 → 0.0.51

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 (238) hide show
  1. package/dist/bench/components/benchmark-table.js.map +1 -1
  2. package/dist/benchmark.js +5 -4
  3. package/dist/benchmark.js.map +1 -1
  4. package/dist/bin/askr-ssg.d.ts.map +1 -1
  5. package/dist/bin/askr-ssg.js.map +1 -1
  6. package/dist/boot/hydration.js.map +1 -1
  7. package/dist/boot/index.js +2 -1
  8. package/dist/boot/index.js.map +1 -1
  9. package/dist/boot/root-lifecycle.d.ts.map +1 -1
  10. package/dist/boot/root-lifecycle.js +4 -4
  11. package/dist/boot/root-lifecycle.js.map +1 -1
  12. package/dist/boot/route-startup.js.map +1 -1
  13. package/dist/common/error-boundary.d.ts +16 -0
  14. package/dist/common/error-boundary.d.ts.map +1 -0
  15. package/dist/common/invariant.js +17 -0
  16. package/dist/common/invariant.js.map +1 -0
  17. package/dist/common/jsx.d.ts +6 -2
  18. package/dist/common/jsx.d.ts.map +1 -1
  19. package/dist/common/jsx.js.map +1 -1
  20. package/dist/{dev → common}/logger.js +5 -6
  21. package/dist/common/logger.js.map +1 -0
  22. package/dist/common/vnode.d.ts +2 -2
  23. package/dist/common/vnode.d.ts.map +1 -1
  24. package/dist/common/vnode.js.map +1 -1
  25. package/dist/components/error-boundary.d.ts +2 -15
  26. package/dist/components/error-boundary.d.ts.map +1 -1
  27. package/dist/components/error-boundary.js +2 -74
  28. package/dist/components/error-boundary.js.map +1 -1
  29. package/dist/components/index.d.ts +2 -1
  30. package/dist/components/link.js +2 -0
  31. package/dist/components/link.js.map +1 -1
  32. package/dist/control/case.d.ts.map +1 -1
  33. package/dist/control/case.js +1 -0
  34. package/dist/control/case.js.map +1 -1
  35. package/dist/control/for.d.ts +3 -3
  36. package/dist/control/for.d.ts.map +1 -1
  37. package/dist/control/for.js +2 -2
  38. package/dist/control/for.js.map +1 -1
  39. package/dist/control/show.js +1 -0
  40. package/dist/control/show.js.map +1 -1
  41. package/dist/data/data-runtime.js.map +1 -1
  42. package/dist/data/invalidation.js +2 -2
  43. package/dist/data/invalidation.js.map +1 -1
  44. package/dist/data/mutation-cell.d.ts.map +1 -1
  45. package/dist/data/mutation-cell.js +1 -1
  46. package/dist/data/mutation-cell.js.map +1 -1
  47. package/dist/data/query-cell.js +2 -2
  48. package/dist/data/query-cell.js.map +1 -1
  49. package/dist/data/shared.js +1 -0
  50. package/dist/data/shared.js.map +1 -1
  51. package/dist/data/testing.js +2 -0
  52. package/dist/foundations/index.d.ts +1 -1
  53. package/dist/foundations/index.js +1 -1
  54. package/dist/foundations/state/controllable.d.ts +0 -1
  55. package/dist/foundations/state/controllable.d.ts.map +1 -1
  56. package/dist/foundations/state/controllable.js +1 -0
  57. package/dist/foundations/state/controllable.js.map +1 -1
  58. package/dist/foundations/structures/index.d.ts +1 -1
  59. package/dist/foundations/structures/index.js +2 -1
  60. package/dist/foundations/structures/portal.d.ts +2 -24
  61. package/dist/foundations/structures/portal.js +3 -187
  62. package/dist/fx/fx.js +2 -2
  63. package/dist/fx/fx.js.map +1 -1
  64. package/dist/fx/index.js +1 -0
  65. package/dist/index.d.ts +3 -3
  66. package/dist/index.js +4 -4
  67. package/dist/index.js.map +1 -1
  68. package/dist/jsx/index.d.ts +1 -1
  69. package/dist/jsx/types.d.ts +2 -2
  70. package/dist/jsx-dev-runtime.d.ts +2 -2
  71. package/dist/jsx-dev-runtime.d.ts.map +1 -1
  72. package/dist/jsx-dev-runtime.js +1 -0
  73. package/dist/jsx-dev-runtime.js.map +1 -1
  74. package/dist/jsx-runtime.d.ts +2 -2
  75. package/dist/jsx-runtime.d.ts.map +1 -1
  76. package/dist/jsx-runtime.js +1 -0
  77. package/dist/jsx-runtime.js.map +1 -1
  78. package/dist/jsx-runtime2.d.ts +1 -1
  79. package/dist/renderer/attributes.js +1 -0
  80. package/dist/renderer/attributes.js.map +1 -1
  81. package/dist/renderer/boundaries.js +5 -5
  82. package/dist/renderer/boundaries.js.map +1 -1
  83. package/dist/renderer/child-shape.js +2 -2
  84. package/dist/renderer/child-shape.js.map +1 -1
  85. package/dist/renderer/children-fastpath.js +149 -0
  86. package/dist/renderer/children-fastpath.js.map +1 -0
  87. package/dist/renderer/children.js +3 -138
  88. package/dist/renderer/children.js.map +1 -1
  89. package/dist/renderer/cleanup.js +2 -2
  90. package/dist/renderer/cleanup.js.map +1 -1
  91. package/dist/renderer/component-host-cleanup.js +1 -1
  92. package/dist/renderer/component-host-cleanup.js.map +1 -1
  93. package/dist/renderer/component-host-instances.js +1 -1
  94. package/dist/renderer/component-host-instances.js.map +1 -1
  95. package/dist/renderer/component-host.js +1 -1
  96. package/dist/renderer/component-host.js.map +1 -1
  97. package/dist/renderer/dom-host.js.map +1 -1
  98. package/dist/renderer/dom-internal.js +5 -4
  99. package/dist/renderer/dom-internal.js.map +1 -1
  100. package/dist/renderer/dom.js +2 -1
  101. package/dist/renderer/element-children.js.map +1 -1
  102. package/dist/renderer/error-boundary-dom.js +51 -2
  103. package/dist/renderer/error-boundary-dom.js.map +1 -1
  104. package/dist/renderer/evaluate-reconcile.js +6 -5
  105. package/dist/renderer/evaluate-reconcile.js.map +1 -1
  106. package/dist/renderer/evaluate.js.map +1 -1
  107. package/dist/renderer/fastpath.js +3 -2
  108. package/dist/renderer/fastpath.js.map +1 -1
  109. package/dist/renderer/for-commit-dom-map.js.map +1 -1
  110. package/dist/renderer/for-commit-removal.js +2 -2
  111. package/dist/renderer/for-commit-removal.js.map +1 -1
  112. package/dist/renderer/for-commit-reorder.js +2 -2
  113. package/dist/renderer/for-commit-reorder.js.map +1 -1
  114. package/dist/renderer/for-commit.js +3 -3
  115. package/dist/renderer/for-commit.js.map +1 -1
  116. package/dist/renderer/index.js +3 -1
  117. package/dist/renderer/index.js.map +1 -1
  118. package/dist/renderer/prop-bindings.js +4 -4
  119. package/dist/renderer/prop-bindings.js.map +1 -1
  120. package/dist/renderer/reactive-child-dom.js.map +1 -1
  121. package/dist/renderer/reactive-children.js +4 -4
  122. package/dist/renderer/reactive-children.js.map +1 -1
  123. package/dist/renderer/reconcile-fastpaths.js +2 -1
  124. package/dist/renderer/reconcile-fastpaths.js.map +1 -1
  125. package/dist/renderer/reconcile-resolution.js +3 -3
  126. package/dist/renderer/reconcile-resolution.js.map +1 -1
  127. package/dist/renderer/retained-element-rollback.js +2 -1
  128. package/dist/renderer/retained-element-rollback.js.map +1 -1
  129. package/dist/renderer/stable-patch.js +2 -3
  130. package/dist/renderer/stable-patch.js.map +1 -1
  131. package/dist/renderer/utils.js +2 -1
  132. package/dist/renderer/utils.js.map +1 -1
  133. package/dist/resources/index.js +1 -2
  134. package/dist/router/activity.d.ts.map +1 -1
  135. package/dist/router/activity.js +20 -22
  136. package/dist/router/activity.js.map +1 -1
  137. package/dist/router/authoring.js +1 -1
  138. package/dist/router/authoring.js.map +1 -1
  139. package/dist/router/index.d.ts +1 -1
  140. package/dist/router/navigate.js +1 -1
  141. package/dist/router/navigate.js.map +1 -1
  142. package/dist/router/navigation-registry.js +1 -1
  143. package/dist/router/navigation-registry.js.map +1 -1
  144. package/dist/router/navigation-targets.d.ts.map +1 -1
  145. package/dist/router/navigation-targets.js +7 -5
  146. package/dist/router/navigation-targets.js.map +1 -1
  147. package/dist/router/rendering.js +1 -0
  148. package/dist/router/rendering.js.map +1 -1
  149. package/dist/router/resolution.d.ts +1 -14
  150. package/dist/router/resolution.d.ts.map +1 -1
  151. package/dist/router/resolution.js +6 -173
  152. package/dist/router/resolution.js.map +1 -1
  153. package/dist/router/route-matching.d.ts +20 -0
  154. package/dist/router/route-matching.d.ts.map +1 -0
  155. package/dist/router/route-matching.js +175 -0
  156. package/dist/router/route-matching.js.map +1 -0
  157. package/dist/router/route.js +4 -2
  158. package/dist/router/testing.js +4 -0
  159. package/dist/runtime/access.d.ts +20 -0
  160. package/dist/runtime/access.d.ts.map +1 -0
  161. package/dist/runtime/component-cleanup.js +1 -1
  162. package/dist/runtime/component-cleanup.js.map +1 -1
  163. package/dist/runtime/component-commit.js +1 -1
  164. package/dist/runtime/component-commit.js.map +1 -1
  165. package/dist/runtime/component-internal.d.ts +1 -1
  166. package/dist/runtime/component-internal.js +1 -1
  167. package/dist/runtime/component-internal.js.map +1 -1
  168. package/dist/runtime/component-lifecycle.d.ts +1 -1
  169. package/dist/runtime/component-lifecycle.js +1 -1
  170. package/dist/runtime/component-lifecycle.js.map +1 -1
  171. package/dist/runtime/component-scope.d.ts +1 -1
  172. package/dist/runtime/dev-namespace.d.ts +31 -0
  173. package/dist/runtime/dev-namespace.d.ts.map +1 -0
  174. package/dist/runtime/error-boundary.d.ts +5 -0
  175. package/dist/runtime/error-boundary.d.ts.map +1 -0
  176. package/dist/runtime/error-boundary.js +31 -0
  177. package/dist/runtime/error-boundary.js.map +1 -0
  178. package/dist/runtime/events.d.ts +58 -0
  179. package/dist/runtime/events.d.ts.map +1 -0
  180. package/dist/runtime/events.js +1 -1
  181. package/dist/runtime/events.js.map +1 -1
  182. package/dist/runtime/execution-model.d.ts +7 -0
  183. package/dist/runtime/execution-model.d.ts.map +1 -0
  184. package/dist/runtime/fastlane.d.ts +34 -0
  185. package/dist/runtime/fastlane.d.ts.map +1 -0
  186. package/dist/runtime/for-internal.d.ts +5 -5
  187. package/dist/runtime/for-internal.d.ts.map +1 -1
  188. package/dist/runtime/for-internal.js.map +1 -1
  189. package/dist/runtime/for-signals.d.ts +1 -1
  190. package/dist/runtime/for-signals.d.ts.map +1 -1
  191. package/dist/runtime/for-signals.js +1 -1
  192. package/dist/runtime/for-signals.js.map +1 -1
  193. package/dist/runtime/for-types.d.ts +9 -0
  194. package/dist/runtime/for-types.d.ts.map +1 -0
  195. package/dist/runtime/index.d.ts +24 -0
  196. package/dist/runtime/index.js +31 -0
  197. package/dist/runtime/perf-metrics.d.ts +26 -0
  198. package/dist/runtime/perf-metrics.d.ts.map +1 -0
  199. package/dist/runtime/portal.d.ts +22 -0
  200. package/dist/runtime/portal.d.ts.map +1 -0
  201. package/dist/runtime/portal.js +213 -0
  202. package/dist/runtime/portal.js.map +1 -0
  203. package/dist/runtime/resource-cell.js +1 -1
  204. package/dist/runtime/resource-cell.js.map +1 -1
  205. package/dist/runtime/resource-operation.js +1 -1
  206. package/dist/runtime/runtime.d.ts +1 -1
  207. package/dist/runtime/scheduler.js +2 -2
  208. package/dist/runtime/scheduler.js.map +1 -1
  209. package/dist/runtime/selector-store.js +24 -0
  210. package/dist/runtime/selector-store.js.map +1 -0
  211. package/dist/runtime/selector.d.ts.map +1 -1
  212. package/dist/runtime/selector.js +3 -18
  213. package/dist/runtime/selector.js.map +1 -1
  214. package/dist/ssg/create-static-gen.js +1 -0
  215. package/dist/ssg/create-static-gen.js.map +1 -1
  216. package/dist/ssg/static-routes.js +1 -0
  217. package/dist/ssg/static-routes.js.map +1 -1
  218. package/dist/ssr/boundaries.js +2 -2
  219. package/dist/ssr/boundaries.js.map +1 -1
  220. package/dist/ssr/component-runtime.js +3 -3
  221. package/dist/ssr/component-runtime.js.map +1 -1
  222. package/dist/ssr/render-resolved.js +1 -1
  223. package/dist/ssr/render-sync.js +1 -1
  224. package/dist/ssr/render-sync.js.map +1 -1
  225. package/dist/ssr/route-policy-resolution.js +2 -1
  226. package/dist/ssr/route-policy-resolution.js.map +1 -1
  227. package/dist/ssr/route-render.js +2 -1
  228. package/dist/ssr/route-render.js.map +1 -1
  229. package/dist/testing/index.d.ts.map +1 -1
  230. package/dist/testing/index.js +3 -2
  231. package/dist/testing/index.js.map +1 -1
  232. package/package.json +4 -4
  233. package/dist/dev/invariant.js +0 -29
  234. package/dist/dev/invariant.js.map +0 -1
  235. package/dist/dev/logger.js.map +0 -1
  236. package/dist/foundations/structures/portal.d.ts.map +0 -1
  237. package/dist/foundations/structures/portal.js.map +0 -1
  238. package/dist/runtime/component-contracts.js +0 -5
@@ -1 +1 @@
1
- {"version":3,"file":"children.js","names":[],"sources":["../../src/renderer/children.ts"],"sourcesContent":["import { setDevValue, incDevCounter } from '../runtime/dev-namespace';\nimport { getRuntimeEnv } from './env';\nimport { keyedElements } from './keyed';\nimport { teardownNodeSubtree } from './cleanup';\nimport { createDOMNode, updateElementFromVnode } from './dom';\nimport { _isDOMElement, type DOMElement, type VNode } from './types';\nimport {\n hasNonTrivialProps,\n logFastPathDebug,\n now,\n recordDOMReplace,\n recordFastPathStats,\n tagNamesEqualIgnoreCase,\n} from './utils';\n\nfunction upperCommonTagName(tag: string): string | null {\n switch (tag) {\n case 'div':\n return 'DIV';\n case 'span':\n return 'SPAN';\n case 'p':\n return 'P';\n case 'a':\n return 'A';\n case 'button':\n return 'BUTTON';\n case 'input':\n return 'INPUT';\n case 'ul':\n return 'UL';\n case 'ol':\n return 'OL';\n case 'li':\n return 'LI';\n default:\n return null;\n }\n}\n\nfunction tagsEqualIgnoreCase(\n elementTagName: string,\n vnodeType: string\n): boolean {\n if (elementTagName === vnodeType) return true;\n\n const upperCommon = upperCommonTagName(vnodeType);\n if (upperCommon !== null && elementTagName === upperCommon) return true;\n\n return tagNamesEqualIgnoreCase(elementTagName, vnodeType);\n}\n\nexport function performBulkPositionalKeyedTextUpdate(\n parent: Element,\n keyedVnodes: Array<{ key: string | number; vnode: VNode }>\n) {\n const total = keyedVnodes.length;\n let reused = 0;\n let updatedKeys = 0;\n const start = now();\n const env = getRuntimeEnv();\n const debugFastPath =\n env.ASKR_FASTPATH_DEBUG === '1' || env.ASKR_FASTPATH_DEBUG === 'true';\n\n for (let index = 0; index < total; index += 1) {\n const { key, vnode } = keyedVnodes[index];\n const child = parent.children[index] as Element | undefined;\n\n if (\n child &&\n _isDOMElement(vnode) &&\n typeof (vnode as DOMElement).type === 'string'\n ) {\n const vnodeType = (vnode as DOMElement).type as string;\n\n if (tagsEqualIgnoreCase(child.tagName, vnodeType)) {\n const children =\n (vnode as DOMElement).children ||\n (vnode as DOMElement).props?.children;\n\n if (debugFastPath) {\n logFastPathDebug('positional idx', index, {\n chTag: child.tagName,\n vnodeType,\n chChildNodes: child.childNodes.length,\n childrenType: Array.isArray(children) ? 'array' : typeof children,\n });\n }\n\n updateTextContent(child, children, vnode as DOMElement);\n setDataKey(child, key, () => (updatedKeys += 1));\n reused += 1;\n continue;\n }\n\n if (debugFastPath) {\n logFastPathDebug('positional tag mismatch', index, {\n chTag: child.tagName,\n vnodeType,\n });\n }\n } else if (debugFastPath) {\n logFastPathDebug('positional missing or invalid', index, { ch: !!child });\n }\n\n replaceNodeAtPosition(parent, index, vnode);\n }\n\n const elapsed = now() - start;\n updateKeyedElementsMap(parent, keyedVnodes);\n\n const stats = { n: total, reused, updatedKeys, t: elapsed } as const;\n recordFastPathStats(stats, 'bulkKeyedPositionalHits');\n\n return stats;\n}\n\nfunction updateTextContent(\n el: Element,\n children: unknown,\n vnode: DOMElement\n): void {\n if (typeof children === 'string' || typeof children === 'number') {\n setTextNodeData(el, String(children));\n if (vnode.props && hasNonTrivialProps(vnode.props)) {\n updateElementFromVnode(el, vnode, false);\n }\n return;\n }\n\n if (\n Array.isArray(children) &&\n children.length === 1 &&\n (typeof children[0] === 'string' || typeof children[0] === 'number')\n ) {\n setTextNodeData(el, String(children[0]));\n if (vnode.props && hasNonTrivialProps(vnode.props)) {\n updateElementFromVnode(el, vnode, false);\n }\n return;\n }\n\n if (!tryUpdateTwoChildTextPattern(el, vnode)) {\n updateElementFromVnode(el, vnode);\n }\n}\n\nfunction tryUpdateTwoChildTextPattern(\n parentEl: Element,\n vnode: DOMElement\n): boolean {\n const vnodeChildren = vnode.props?.children ?? vnode.children;\n if (!Array.isArray(vnodeChildren) || vnodeChildren.length !== 2) return false;\n\n const firstChild = vnodeChildren[0];\n const secondChild = vnodeChildren[1];\n if (!_isDOMElement(firstChild) || !_isDOMElement(secondChild)) return false;\n if (\n typeof firstChild.type !== 'string' ||\n typeof secondChild.type !== 'string'\n ) {\n return false;\n }\n\n const firstElement = parentEl.children[0] as Element | undefined;\n const secondElement = parentEl.children[1] as Element | undefined;\n if (!firstElement || !secondElement) return false;\n if (parentEl.children.length !== 2 || parentEl.childNodes.length !== 2) {\n return false;\n }\n\n if (!tagsEqualIgnoreCase(firstElement.tagName, firstChild.type)) return false;\n if (!tagsEqualIgnoreCase(secondElement.tagName, secondChild.type))\n return false;\n\n const firstText = (firstChild.children ||\n firstChild.props?.children) as unknown;\n const secondText = (secondChild.children ||\n secondChild.props?.children) as unknown;\n\n if (typeof firstText === 'string' || typeof firstText === 'number') {\n setTextNodeData(firstElement, String(firstText));\n } else if (\n Array.isArray(firstText) &&\n firstText.length === 1 &&\n (typeof firstText[0] === 'string' || typeof firstText[0] === 'number')\n ) {\n setTextNodeData(firstElement, String(firstText[0]));\n } else {\n return false;\n }\n\n if (typeof secondText === 'string' || typeof secondText === 'number') {\n setTextNodeData(secondElement, String(secondText));\n } else if (\n Array.isArray(secondText) &&\n secondText.length === 1 &&\n (typeof secondText[0] === 'string' || typeof secondText[0] === 'number')\n ) {\n setTextNodeData(secondElement, String(secondText[0]));\n } else {\n return false;\n }\n\n return true;\n}\n\nfunction setTextNodeData(el: Element, text: string): void {\n if (el.childNodes.length === 1 && el.firstChild?.nodeType === 3) {\n const textNode = el.firstChild as Text;\n if (textNode.data !== text) textNode.data = text;\n } else {\n el.textContent = text;\n }\n}\n\nfunction setDataKey(\n el: Element,\n key: string | number,\n onSet: () => void\n): void {\n try {\n const next = String(key);\n if (el.getAttribute('data-key') === next) return;\n el.setAttribute('data-key', next);\n onSet();\n } catch {\n // Ignore errors setting data-key\n }\n}\n\nfunction replaceNodeAtPosition(\n parent: Element,\n index: number,\n vnode: VNode\n): void {\n const dom = createDOMNode(vnode);\n if (dom) {\n const existing = parent.children[index];\n if (existing) {\n teardownNodeSubtree(existing);\n parent.replaceChild(dom, existing);\n } else {\n parent.appendChild(dom);\n }\n }\n}\n\nfunction updateKeyedElementsMap(\n parent: Element,\n keyedVnodes: Array<{ key: string | number; vnode: VNode }>\n): void {\n try {\n const existing = keyedElements.get(parent);\n const newKeyMap = existing\n ? (existing.clear(), existing)\n : new Map<string | number, Element>();\n\n for (let index = 0; index < keyedVnodes.length; index += 1) {\n const key = keyedVnodes[index].key;\n const child = parent.children[index] as Element | undefined;\n if (child) newKeyMap.set(key, child);\n }\n\n keyedElements.set(parent, newKeyMap);\n } catch {\n // Ignore errors updating key map\n }\n}\n\nexport function performBulkTextReplace(parent: Element, newChildren: VNode[]) {\n const start = now();\n const existing = Array.from(parent.childNodes);\n const finalNodes: Node[] = [];\n let reused = 0;\n let created = 0;\n\n for (let index = 0; index < newChildren.length; index += 1) {\n const result = processChildNode(\n newChildren[index],\n existing[index],\n finalNodes\n );\n if (result === 'reused') reused += 1;\n else if (result === 'created') created += 1;\n }\n\n const tBuild = now() - start;\n const tCommit = commitBulkReplace(parent, finalNodes);\n\n keyedElements.delete(parent);\n\n const stats = {\n n: newChildren.length,\n reused,\n created,\n tBuild,\n tCommit,\n } as const;\n recordBulkTextStats(stats);\n\n return stats;\n}\n\nfunction processChildNode(\n vnode: VNode,\n existingNode: ChildNode | undefined,\n finalNodes: Node[]\n): 'reused' | 'created' | 'skipped' {\n if (typeof vnode === 'string' || typeof vnode === 'number') {\n return processTextVnode(String(vnode), existingNode, finalNodes);\n }\n\n if (typeof vnode === 'object' && vnode !== null && 'type' in vnode) {\n return processElementVnode(vnode, existingNode, finalNodes);\n }\n\n return 'skipped';\n}\n\nfunction processTextVnode(\n text: string,\n existingNode: ChildNode | undefined,\n finalNodes: Node[]\n): 'reused' | 'created' {\n if (existingNode && existingNode.nodeType === 3) {\n (existingNode as Text).data = text;\n finalNodes.push(existingNode);\n return 'reused';\n }\n\n finalNodes.push(document.createTextNode(text));\n return 'created';\n}\n\nfunction processElementVnode(\n vnode: VNode,\n existingNode: ChildNode | undefined,\n finalNodes: Node[]\n): 'reused' | 'created' | 'skipped' {\n const vnodeObj = vnode as unknown as { type?: unknown };\n\n if (typeof vnodeObj.type === 'string') {\n const tag = vnodeObj.type;\n if (\n existingNode &&\n existingNode.nodeType === 1 &&\n tagsEqualIgnoreCase((existingNode as Element).tagName, tag)\n ) {\n updateElementFromVnode(existingNode as Element, vnode);\n finalNodes.push(existingNode);\n return 'reused';\n }\n }\n\n const dom = createDOMNode(vnode);\n if (dom) {\n finalNodes.push(dom);\n return 'created';\n }\n\n return 'skipped';\n}\n\nfunction commitBulkReplace(parent: Element, nodes: Node[]): number {\n const startedAt = Date.now();\n const fragment = document.createDocumentFragment();\n\n for (let index = 0; index < nodes.length; index += 1) {\n fragment.appendChild(nodes[index]);\n }\n\n try {\n for (let node = parent.firstChild; node; ) {\n const next = node.nextSibling;\n teardownNodeSubtree(node);\n node = next;\n }\n } catch {\n // SLOW PATH: cleanup failure\n }\n\n recordDOMReplace('bulk-text-replace');\n parent.replaceChildren(fragment);\n return Date.now() - startedAt;\n}\n\nfunction recordBulkTextStats(stats: {\n n: number;\n reused: number;\n created: number;\n tBuild: number;\n tCommit: number;\n}): void {\n try {\n setDevValue('__LAST_BULK_TEXT_FASTPATH_STATS', stats);\n setDevValue('__LAST_FASTPATH_STATS', stats);\n setDevValue('__LAST_FASTPATH_COMMIT_COUNT', 1);\n incDevCounter('bulkTextFastpathHits');\n } catch {\n // Ignore stats errors\n }\n}\n\nexport function isBulkTextFastPathEligible(\n parent: Element,\n newChildren: VNode[]\n) {\n const env = getRuntimeEnv();\n const threshold = Number(env.ASKR_BULK_TEXT_THRESHOLD) || 1024;\n const requiredFraction = 0.8;\n\n const total = Array.isArray(newChildren) ? newChildren.length : 0;\n\n if (total < threshold) {\n recordBulkDiag({\n phase: 'bulk-unkeyed-eligible',\n reason: 'too-small',\n total,\n threshold,\n });\n return false;\n }\n\n const result = countSimpleChildren(newChildren);\n if (result.componentFound !== undefined) {\n recordBulkDiag({\n phase: 'bulk-unkeyed-eligible',\n reason: 'component-child',\n index: result.componentFound,\n });\n return false;\n }\n\n const fraction = result.simple / total;\n const eligible =\n fraction >= requiredFraction && parent.childNodes.length >= total;\n\n recordBulkDiag({\n phase: 'bulk-unkeyed-eligible',\n total,\n simple: result.simple,\n fraction,\n requiredFraction,\n eligible,\n });\n\n return eligible;\n}\n\nfunction countSimpleChildren(children: VNode[]): {\n simple: number;\n componentFound?: number;\n} {\n let simple = 0;\n\n for (let index = 0; index < children.length; index += 1) {\n const child = children[index];\n\n if (typeof child === 'string' || typeof child === 'number') {\n simple += 1;\n continue;\n }\n\n if (typeof child === 'object' && child !== null && 'type' in child) {\n const dom = child as DOMElement;\n\n if (typeof dom.type === 'function') {\n return { simple, componentFound: index };\n }\n\n if (typeof dom.type === 'string' && isSimpleElement(dom)) {\n simple += 1;\n }\n }\n }\n\n return { simple };\n}\n\nfunction isSimpleElement(dom: DOMElement): boolean {\n const children = dom.props?.children ?? dom.children;\n\n if (children === null || children === undefined) return true;\n\n if (typeof children === 'string' || typeof children === 'number') {\n return true;\n }\n\n if (\n Array.isArray(children) &&\n children.length === 1 &&\n (typeof children[0] === 'string' || typeof children[0] === 'number')\n ) {\n return true;\n }\n\n return false;\n}\n\nfunction recordBulkDiag(data: Record<string, unknown>): void {\n const env = getRuntimeEnv();\n if (env.NODE_ENV !== 'production' || env.ASKR_FASTPATH_DEBUG === '1') {\n try {\n setDevValue('__BULK_DIAG', data);\n } catch {\n // Ignore\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAeA,SAAS,mBAAmB,KAA4B;CACtD,QAAQ,KAAR;EACE,KAAK,OACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,KACH,OAAO;EACT,KAAK,KACH,OAAO;EACT,KAAK,UACH,OAAO;EACT,KAAK,SACH,OAAO;EACT,KAAK,MACH,OAAO;EACT,KAAK,MACH,OAAO;EACT,KAAK,MACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AAEA,SAAS,oBACP,gBACA,WACS;CACT,IAAI,mBAAmB,WAAW,OAAO;CAEzC,MAAM,cAAc,mBAAmB,SAAS;CAChD,IAAI,gBAAgB,QAAQ,mBAAmB,aAAa,OAAO;CAEnE,OAAO,wBAAwB,gBAAgB,SAAS;AAC1D;AAEA,SAAg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Y,oBAAoB,OAAO,WAAW,UAAU;CAE9D,eAAe;EACb,OAAO;EACP;EACA,QAAQ,OAAO;EACf;EACA;EACA;CACF,CAAC;CAED,OAAO;AACT;AAEA,SAAS,oBAAoB,UAG3B;CACA,IAAI,SAAS;CAEb,KAAK,IAAI,QAAQ,GAAG,QAAQ,SAAS,QAAQ,SAAS,GAAG;EACvD,MAAM,QAAQ,SAAS;EAEvB,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,UAAU;GAC1D,UAAU;GACV;EACF;EAEA,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU,OAAO;GAClE,MAAM,MAAM;GAEZ,IAAI,OAAO,IAAI,SAAS,YACtB,OAAO;IAAE;IAAQ,gBAAgB;GAAM;GAGzC,IAAI,OAAO,IAAI,SAAS,YAAY,gBAAgB,GAAG,GACrD,UAAU;EAEd;CACF;CAEA,OAAO,EAAE,OAAO;AAClB;AAEA,SAAS,gBAAgB,KAA0B;CACjD,MAAM,WAAW,IAAI,OAAO,YAAY,IAAI;CAE5C,IAAI,aAAa,QAAQ,aAAa,QAAW,OAAO;CAExD,IAAI,OAAO,aAAa,YAAY,OAAO,aAAa,UACtD,OAAO;CAGT,IACE,MAAM,QAAQ,QAAQ,KACtB,SAAS,WAAW,MACnB,OAAO,SAAS,OAAO,YAAY,OAAO,SAAS,OAAO,WAE3D,OAAO;CAGT,OAAO;AACT;AAEA,SAAS,eAAe,MAAqC;CAC3D,MAAM,MAAM,cAAc;CAC1B,IAAI,IAAI,aAAa,gBAAgB,IAAI,wBAAwB,KAC/D,IAAI;EACF,YAAY,eAAe,IAAI;CACjC,QAAQ,CAER;AAEJ"}
1
+ {"version":3,"file":"children.js","names":[],"sources":["../../src/renderer/children.ts"],"sourcesContent":["import { setDevValue, incDevCounter } from '../runtime';\nimport { getRuntimeEnv } from './env';\nimport { keyedElements } from './keyed';\nimport { teardownNodeSubtree } from './cleanup';\nimport { createDOMNode, updateElementFromVnode } from './dom';\nimport { tagsEqualIgnoreCase } from './children-fastpath';\nimport type { DOMElement, VNode } from './types';\nimport { now, recordDOMReplace } from './utils';\n\nexport { performBulkPositionalKeyedTextUpdate } from './children-fastpath';\n\nexport function performBulkTextReplace(parent: Element, newChildren: VNode[]) {\n const start = now();\n const existing = Array.from(parent.childNodes);\n const finalNodes: Node[] = [];\n let reused = 0;\n let created = 0;\n\n for (let index = 0; index < newChildren.length; index += 1) {\n const result = processChildNode(\n newChildren[index],\n existing[index],\n finalNodes\n );\n if (result === 'reused') reused += 1;\n else if (result === 'created') created += 1;\n }\n\n const tBuild = now() - start;\n const tCommit = commitBulkReplace(parent, finalNodes);\n\n keyedElements.delete(parent);\n\n const stats = {\n n: newChildren.length,\n reused,\n created,\n tBuild,\n tCommit,\n } as const;\n recordBulkTextStats(stats);\n\n return stats;\n}\n\nfunction processChildNode(\n vnode: VNode,\n existingNode: ChildNode | undefined,\n finalNodes: Node[]\n): 'reused' | 'created' | 'skipped' {\n if (typeof vnode === 'string' || typeof vnode === 'number') {\n return processTextVnode(String(vnode), existingNode, finalNodes);\n }\n\n if (typeof vnode === 'object' && vnode !== null && 'type' in vnode) {\n return processElementVnode(vnode, existingNode, finalNodes);\n }\n\n return 'skipped';\n}\n\nfunction processTextVnode(\n text: string,\n existingNode: ChildNode | undefined,\n finalNodes: Node[]\n): 'reused' | 'created' {\n if (existingNode && existingNode.nodeType === 3) {\n (existingNode as Text).data = text;\n finalNodes.push(existingNode);\n return 'reused';\n }\n\n finalNodes.push(document.createTextNode(text));\n return 'created';\n}\n\nfunction processElementVnode(\n vnode: VNode,\n existingNode: ChildNode | undefined,\n finalNodes: Node[]\n): 'reused' | 'created' | 'skipped' {\n const vnodeObj = vnode as unknown as { type?: unknown };\n\n if (typeof vnodeObj.type === 'string') {\n const tag = vnodeObj.type;\n if (\n existingNode &&\n existingNode.nodeType === 1 &&\n tagsEqualIgnoreCase((existingNode as Element).tagName, tag)\n ) {\n updateElementFromVnode(existingNode as Element, vnode);\n finalNodes.push(existingNode);\n return 'reused';\n }\n }\n\n const dom = createDOMNode(vnode);\n if (dom) {\n finalNodes.push(dom);\n return 'created';\n }\n\n return 'skipped';\n}\n\nfunction commitBulkReplace(parent: Element, nodes: Node[]): number {\n const startedAt = Date.now();\n const fragment = document.createDocumentFragment();\n\n for (let index = 0; index < nodes.length; index += 1) {\n fragment.appendChild(nodes[index]);\n }\n\n try {\n for (let node = parent.firstChild; node; ) {\n const next = node.nextSibling;\n teardownNodeSubtree(node);\n node = next;\n }\n } catch {\n // SLOW PATH: cleanup failure\n }\n\n recordDOMReplace('bulk-text-replace');\n parent.replaceChildren(fragment);\n return Date.now() - startedAt;\n}\n\nfunction recordBulkTextStats(stats: {\n n: number;\n reused: number;\n created: number;\n tBuild: number;\n tCommit: number;\n}): void {\n try {\n setDevValue('__LAST_BULK_TEXT_FASTPATH_STATS', stats);\n setDevValue('__LAST_FASTPATH_STATS', stats);\n setDevValue('__LAST_FASTPATH_COMMIT_COUNT', 1);\n incDevCounter('bulkTextFastpathHits');\n } catch {\n // Ignore stats errors\n }\n}\n\nexport function isBulkTextFastPathEligible(\n parent: Element,\n newChildren: VNode[]\n) {\n const env = getRuntimeEnv();\n const threshold = Number(env.ASKR_BULK_TEXT_THRESHOLD) || 1024;\n const requiredFraction = 0.8;\n\n const total = Array.isArray(newChildren) ? newChildren.length : 0;\n\n if (total < threshold) {\n recordBulkDiag({\n phase: 'bulk-unkeyed-eligible',\n reason: 'too-small',\n total,\n threshold,\n });\n return false;\n }\n\n const result = countSimpleChildren(newChildren);\n if (result.componentFound !== undefined) {\n recordBulkDiag({\n phase: 'bulk-unkeyed-eligible',\n reason: 'component-child',\n index: result.componentFound,\n });\n return false;\n }\n\n const fraction = result.simple / total;\n const eligible =\n fraction >= requiredFraction && parent.childNodes.length >= total;\n\n recordBulkDiag({\n phase: 'bulk-unkeyed-eligible',\n total,\n simple: result.simple,\n fraction,\n requiredFraction,\n eligible,\n });\n\n return eligible;\n}\n\nfunction countSimpleChildren(children: VNode[]): {\n simple: number;\n componentFound?: number;\n} {\n let simple = 0;\n\n for (let index = 0; index < children.length; index += 1) {\n const child = children[index];\n\n if (typeof child === 'string' || typeof child === 'number') {\n simple += 1;\n continue;\n }\n\n if (typeof child === 'object' && child !== null && 'type' in child) {\n const dom = child as DOMElement;\n\n if (typeof dom.type === 'function') {\n return { simple, componentFound: index };\n }\n\n if (typeof dom.type === 'string' && isSimpleElement(dom)) {\n simple += 1;\n }\n }\n }\n\n return { simple };\n}\n\nfunction isSimpleElement(dom: DOMElement): boolean {\n const children = dom.props?.children ?? dom.children;\n\n if (children === null || children === undefined) return true;\n\n if (typeof children === 'string' || typeof children === 'number') {\n return true;\n }\n\n if (\n Array.isArray(children) &&\n children.length === 1 &&\n (typeof children[0] === 'string' || typeof children[0] === 'number')\n ) {\n return true;\n }\n\n return false;\n}\n\nfunction recordBulkDiag(data: Record<string, unknown>): void {\n const env = getRuntimeEnv();\n if (env.NODE_ENV !== 'production' || env.ASKR_FASTPATH_DEBUG === '1') {\n try {\n setDevValue('__BULK_DIAG', data);\n } catch {\n // Ignore\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAWA,SAAgB,uBAAuB,QAAiB,aAAsB;CAC5E,MAAM,QAAQ,IAAI;CAClB,MAAM,WAAW,MAAM,KAAK,OAAO,UAAU;CAC7C,MAAM,aAAqB,CAAC;CAC5B,IAAI,SAAS;CACb,IAAI,UAAU;CAEd,KAAK,IAAI,QAAQ,GAAG,QAAQ,YAAY,QAAQ,SAAS,GAAG;EAC1D,MAAM,SAAS,iBACb,YAAY,QACZ,SAAS,QACT,UACF;EACA,IAAI,WAAW,UAAU,UAAU;OAC9B,IAAI,WAAW,WAAW,WAAW;CAC5C;CAEA,MAAM,SAAS,IAAI,IAAI;CACvB,MAAM,UAAU,kBAAkB,QAAQ,UAAU;CAEpD,cAAc,OAAO,MAAM;CAE3B,MAAM,QAAQ;EACZ,GAAG,YAAY;EACf;EACA;EACA;EACA;CACF;CACA,oBAAoB,K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,MAAM,WAAW,IAAI,OAAO,YAAY,IAAI;CAE5C,IAAI,aAAa,QAAQ,aAAa,QAAW,OAAO;CAExD,IAAI,OAAO,aAAa,YAAY,OAAO,aAAa,UACtD,OAAO;CAGT,IACE,MAAM,QAAQ,QAAQ,KACtB,SAAS,WAAW,MACnB,OAAO,SAAS,OAAO,YAAY,OAAO,SAAS,OAAO,WAE3D,OAAO;CAGT,OAAO;AACT;AAEA,SAAS,eAAe,MAAqC;CAC3D,MAAM,MAAM,cAAc;CAC1B,IAAI,IAAI,aAAa,gBAAgB,IAAI,wBAAwB,KAC/D,IAAI;EACF,YAAY,eAAe,IAAI;CACjC,QAAQ,CAER;AAEJ"}
@@ -1,8 +1,8 @@
1
- import { logger } from "../dev/logger.js";
1
+ import { logger } from "../common/logger.js";
2
2
  import { incDevCounter } from "../runtime/dev-namespace.js";
3
3
  import { cleanupComponent } from "../runtime/component-cleanup.js";
4
- import "../runtime/component-contracts.js";
5
4
  import { clearDelegatedHandlersForElement, removeDelegatedListener } from "../runtime/events.js";
5
+ import "../runtime/index.js";
6
6
  //#region src/renderer/cleanup.ts
7
7
  const elementRefs = /* @__PURE__ */ new WeakMap();
8
8
  function applyRefValue(ref, value) {
@@ -1 +1 @@
1
- {"version":3,"file":"cleanup.js","names":[],"sources":["../../src/renderer/cleanup.ts"],"sourcesContent":["import {\n cleanupComponent,\n type ComponentInstance,\n} from '../runtime/component-contracts';\nimport { logger } from '../dev/logger';\nimport { incDevCounter } from '../runtime/dev-namespace';\nimport {\n clearDelegatedHandlersForElement,\n removeDelegatedListener,\n} from '../runtime/events';\n\ntype InstanceHost = Node & {\n __ASKR_INSTANCE?: unknown;\n __ASKR_INSTANCES?: unknown[];\n};\n\ntype Ref<T> =\n | ((value: T | null) => void)\n | { current: T | null }\n | null\n | undefined;\n\nexport const elementRefs = new WeakMap<Element, unknown>();\n\nfunction applyRefValue<T>(ref: unknown, value: T | null): void {\n const resolvedRef = ref as Ref<T>;\n\n if (!resolvedRef) {\n return;\n }\n\n if (typeof resolvedRef === 'function') {\n resolvedRef(value);\n return;\n }\n\n if (Object.isExtensible(resolvedRef)) {\n (resolvedRef as { current: T | null }).current = value;\n }\n}\n\nexport function updateElementRef<T extends Element>(\n element: T,\n ref: unknown\n): void {\n const previousRef = elementRefs.get(element);\n\n if (previousRef === ref) {\n return;\n }\n\n if (previousRef) {\n applyRefValue(previousRef, null);\n }\n\n if (ref) {\n applyRefValue(ref, element);\n elementRefs.set(element, ref);\n } else {\n elementRefs.delete(element);\n }\n}\n\nexport function removeElementRef(element: Element): void {\n const ref = elementRefs.get(element);\n\n if (!ref) {\n return;\n }\n\n applyRefValue(ref, null);\n elementRefs.delete(element);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Instance Cleanup Helpers\n// ─────────────────────────────────────────────────────────────────────────────\n\nfunction cleanupSingleInstance(\n node: InstanceHost,\n errors: unknown[] | null,\n strict: boolean\n): void {\n const instances = new Set<ComponentInstance>();\n\n if (Array.isArray(node.__ASKR_INSTANCES)) {\n for (const instance of node.__ASKR_INSTANCES) {\n if (instance) {\n instances.add(instance as ComponentInstance);\n }\n }\n }\n\n if (node.__ASKR_INSTANCE) {\n instances.add(node.__ASKR_INSTANCE as ComponentInstance);\n }\n\n for (const instance of instances) {\n try {\n cleanupComponent(instance);\n } catch (err) {\n if (strict) errors!.push(err);\n else logger.warn('[Askr] cleanupComponent failed:', err);\n }\n }\n\n try {\n delete node.__ASKR_INSTANCE;\n delete node.__ASKR_INSTANCES;\n } catch (e) {\n if (strict) errors!.push(e);\n }\n}\n\nfunction teardownSingleElement(\n element: Element,\n errors: unknown[] | null,\n strict: boolean\n): void {\n try {\n removeElementRef(element);\n } catch (err) {\n if (strict) errors!.push(err);\n else logger.warn('[Askr] removeElementRef failed:', err);\n }\n\n try {\n removeElementListeners(element);\n } catch (err) {\n if (strict) errors!.push(err);\n else logger.warn('[Askr] removeElementListeners failed:', err);\n }\n\n try {\n removeElementReactiveProps(element);\n } catch (err) {\n if (strict) errors!.push(err);\n else logger.warn('[Askr] removeElementReactiveProps failed:', err);\n }\n\n try {\n cleanupSingleInstance(element as InstanceHost, errors, strict);\n } catch (err) {\n if (strict) errors!.push(err);\n else logger.warn('[Askr] cleanupSingleInstance failed:', err);\n }\n}\n\n// Walk descendant elements with minimal allocations.\n// HOT PATH: used during subtree teardown (replace/unmount).\nfunction forEachDescendantElement(root: Element, visit: (el: Element) => void) {\n // Prefer TreeWalker when available; it avoids allocating a NodeList.\n try {\n const doc = root.ownerDocument;\n const createTreeWalker = doc?.createTreeWalker;\n if (typeof createTreeWalker === 'function') {\n // NodeFilter.SHOW_ELEMENT === 1\n const walker = createTreeWalker.call(doc, root, 1);\n let n = walker.firstChild();\n while (n) {\n visit(n as Element);\n n = walker.nextNode();\n }\n return;\n }\n } catch {\n // SLOW PATH: TreeWalker unavailable\n }\n\n // Fallback: querySelectorAll\n const descendants = root.querySelectorAll('*');\n for (let i = 0; i < descendants.length; i++) {\n visit(descendants[i]);\n }\n}\n\nfunction forEachDescendantNode(root: Node, visit: (node: Node) => void) {\n try {\n const doc = root.ownerDocument;\n const createTreeWalker = doc?.createTreeWalker;\n if (typeof createTreeWalker === 'function') {\n // NodeFilter.SHOW_ALL === 0xffffffff\n const walker = createTreeWalker.call(doc, root, 0xffffffff);\n let node = walker.nextNode();\n while (node) {\n visit(node);\n node = walker.nextNode();\n }\n return;\n }\n } catch {\n // SLOW PATH: TreeWalker unavailable\n }\n\n const stack = Array.from(root.childNodes).reverse();\n while (stack.length > 0) {\n const node = stack.pop()!;\n visit(node);\n for (let child = node.lastChild; child; child = child.previousSibling) {\n stack.push(child);\n }\n }\n}\n\nfunction forEachElementInSubtree(root: Element, visit: (el: Element) => void) {\n visit(root);\n forEachDescendantElement(root, visit);\n}\n\n// Track listeners so we can remove them on cleanup\nexport interface ListenerMapEntry {\n handler: EventListener;\n original: EventListener;\n eventName: string;\n options?: boolean | AddEventListenerOptions;\n isDelegated?: boolean;\n updateHandler?: (nextHandler: EventListener) => void;\n}\nexport const elementListeners = new WeakMap<\n Element,\n Map<string, ListenerMapEntry>\n>();\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Public API\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Clean up component instance attached to a DOM node\n * Accepts an optional `opts.strict` flag to surface errors instead of swallowing them.\n */\nexport function cleanupInstanceIfPresent(\n node: Node | null,\n opts?: { strict?: boolean }\n): void {\n if (!node) return;\n\n const strict = opts?.strict ?? false;\n const errors: unknown[] | null = strict ? [] : null;\n\n // Clean up the node itself\n try {\n cleanupSingleInstance(node as InstanceHost, errors, strict);\n } catch (err) {\n if (strict) errors!.push(err);\n else logger.warn('[Askr] cleanupInstanceIfPresent failed:', err);\n }\n\n // Clean up any nested instances, including null-component comment hosts.\n try {\n forEachDescendantNode(node, (descendant) => {\n try {\n cleanupSingleInstance(descendant as InstanceHost, errors, strict);\n } catch (err) {\n if (strict) errors!.push(err);\n else\n logger.warn(\n '[Askr] cleanupInstanceIfPresent descendant cleanup failed:',\n err\n );\n }\n });\n } catch (err) {\n if (strict) errors!.push(err);\n else\n logger.warn(\n '[Askr] cleanupInstanceIfPresent descendant query failed:',\n err\n );\n }\n\n if (errors && errors.length > 0) {\n throw new AggregateError(errors, 'cleanupInstanceIfPresent failed');\n }\n}\n\n// Public helper to clean up any component instances under a node. Used by\n// runtime commit logic to ensure component instances are torn down when their\n// host nodes are removed during an update.\nexport function cleanupInstancesUnder(\n node: Node | null,\n opts?: { strict?: boolean }\n): void {\n cleanupInstanceIfPresent(node, opts);\n}\n\nexport function teardownNodeSubtree(\n node: Node | null,\n opts?: { strict?: boolean }\n): void {\n if (!node) return;\n\n const strict = opts?.strict ?? false;\n const errors: unknown[] | null = strict ? [] : null;\n\n if (!(node instanceof Element)) {\n cleanupSingleInstance(node as InstanceHost, errors, strict);\n if (errors && errors.length > 0) {\n throw new AggregateError(errors, 'teardownNodeSubtree failed');\n }\n return;\n }\n\n try {\n teardownSingleElement(node, errors, strict);\n forEachDescendantNode(node, (descendant) => {\n if (descendant instanceof Element) {\n teardownSingleElement(descendant, errors, strict);\n } else {\n cleanupSingleInstance(descendant as InstanceHost, errors, strict);\n }\n });\n } catch (err) {\n if (strict) errors!.push(err);\n else logger.warn('[Askr] teardownNodeSubtree failed:', err);\n }\n\n if (errors && errors.length > 0) {\n throw new AggregateError(errors, 'teardownNodeSubtree failed');\n }\n}\n\n// Track reactive props cleanup functions and their function references\nexport interface ReactivePropCleanupEntry {\n cleanup: () => void;\n fnRef: unknown;\n restoreFn?: (nextValue: unknown) => ReactivePropCleanupEntry;\n updateFn?: (nextValue: unknown) => void;\n}\n\nexport const REACTIVE_CHILDREN_KEY = '__askr_reactive_children__';\n\nexport const elementReactivePropsCleanup = new WeakMap<\n Element,\n Map<string, ReactivePropCleanupEntry>\n>();\n\nexport function removeElementReactiveProps(element: Element): void {\n const cleanupMap = elementReactivePropsCleanup.get(element);\n if (cleanupMap) {\n for (const entry of cleanupMap.values()) {\n try {\n entry.cleanup();\n } catch (err) {\n logger.warn('[Askr] reactive prop cleanup failed:', err);\n }\n }\n elementReactivePropsCleanup.delete(element);\n }\n}\n\nexport function removeElementListeners(element: Element): void {\n const map = elementListeners.get(element);\n if (map) {\n for (const entry of map.values()) {\n incDevCounter('listenerRemoves');\n if (entry.isDelegated) {\n removeDelegatedListener(element, entry.eventName);\n } else {\n if (entry.options !== undefined)\n element.removeEventListener(\n entry.eventName,\n entry.handler,\n entry.options\n );\n else element.removeEventListener(entry.eventName, entry.handler);\n }\n }\n elementListeners.delete(element);\n }\n\n clearDelegatedHandlersForElement(element);\n}\n\nexport function removeAllListeners(root: Element | null): void {\n if (!root) return;\n\n forEachElementInSubtree(root, (el) => {\n removeElementRef(el);\n removeElementListeners(el);\n removeElementReactiveProps(el);\n });\n}\n"],"mappings":";;;;;;AAsBA,MAAa,8BAAc,IAAI,QAA0B;AAEzD,SAAS,cAAiB,KAAc,OAAuB;CAC7D,MAAM,cAAc;CAEpB,IAAI,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SACxB,sBAAsB,YAAY,QAAQ,MAAM;QAEhD,sBAAsB,YAA4B,QAAQ,MAAM;EAEpE,CAAC;CACH,SAAS,KAAK;EACZ,IAAI,QAAQ,OAAQ,KAAK,GAAG;OACvB,OAAO,KAAK,sCAAsC,GAAG;CAC5D;CAEA,IAAI,UAAU,OAAO,SAAS,GAC5B,MAAM,IAAI,eAAe,QAAQ,4BAA4B;AAEjE;AAUA,MAAa,wBAAwB;AAErC,MAAa,8CAA8B,IAAI,QAG7C;AAEF,SAAgB,2BAA2B,SAAwB;CACjE,MAAM,aAAa,4BAA4B,IAAI,OAAO;CAC1D,IAAI,YAAY;EACd,KAAK,MAAM,SAAS,WAAW,OAAO,GACpC,IAAI;GACF,MAAM,QAAQ;EAChB,SAAS,KAAK;GACZ,OAAO,KAAK,wCAAwC,GAAG;EACzD;EAEF,4BAA4B,OAAO,OAAO;CAC5C;AACF;AAEA,SAAgB,uBAAuB,SAAwB;CAC7D,MAAM,MAAM,iBAAiB,IAAI,OAAO;CACxC,IAAI,KAAK;EACP,KAAK,MAAM,SAAS,IAAI,OAAO,GAAG;GAChC,cAAc,iBAAiB;GAC/B,IAAI,MAAM,aACR,wBAAwB,SAAS,MAAM,SAAS;QAEhD,IAAI,MAAM,YAAY,QACpB,QAAQ,oBACN,MAAM,WACN,MAAM,SACN,MAAM,OACR;QACG,QAAQ,oBAAoB,MAAM,WAAW,MAAM,OAAO;EAEnE;EACA,iBAAiB,OAAO,OAAO;CACjC;CAEA,iCAAiC,OAAO;AAC1C;AAEA,SAAgB,mBAAmB,MAA4B;CAC7D,IAAI,CAAC,MAAM;CAEX,wBAAwB,OAAO,OAAO;EACpC,iBAAiB,EAAE;EACnB,uBAAuB,EAAE;EACzB,2BAA2B,EAAE;CAC/B,CAAC;AACH"}
1
+ {"version":3,"file":"cleanup.js","names":[],"sources":["../../src/renderer/cleanup.ts"],"sourcesContent":["import { cleanupComponent, type ComponentInstance } from '../runtime';\nimport { logger } from '../common/logger';\nimport { incDevCounter } from '../runtime';\nimport {\n clearDelegatedHandlersForElement,\n removeDelegatedListener,\n} from '../runtime';\n\ntype InstanceHost = Node & {\n __ASKR_INSTANCE?: unknown;\n __ASKR_INSTANCES?: unknown[];\n};\n\ntype Ref<T> =\n | ((value: T | null) => void)\n | { current: T | null }\n | null\n | undefined;\n\nexport const elementRefs = new WeakMap<Element, unknown>();\n\nfunction applyRefValue<T>(ref: unknown, value: T | null): void {\n const resolvedRef = ref as Ref<T>;\n\n if (!resolvedRef) {\n return;\n }\n\n if (typeof resolvedRef === 'function') {\n resolvedRef(value);\n return;\n }\n\n if (Object.isExtensible(resolvedRef)) {\n (resolvedRef as { current: T | null }).current = value;\n }\n}\n\nexport function updateElementRef<T extends Element>(\n element: T,\n ref: unknown\n): void {\n const previousRef = elementRefs.get(element);\n\n if (previousRef === ref) {\n return;\n }\n\n if (previousRef) {\n applyRefValue(previousRef, null);\n }\n\n if (ref) {\n applyRefValue(ref, element);\n elementRefs.set(element, ref);\n } else {\n elementRefs.delete(element);\n }\n}\n\nexport function removeElementRef(element: Element): void {\n const ref = elementRefs.get(element);\n\n if (!ref) {\n return;\n }\n\n applyRefValue(ref, null);\n elementRefs.delete(element);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Instance Cleanup Helpers\n// ─────────────────────────────────────────────────────────────────────────────\n\nfunction cleanupSingleInstance(\n node: InstanceHost,\n errors: unknown[] | null,\n strict: boolean\n): void {\n const instances = new Set<ComponentInstance>();\n\n if (Array.isArray(node.__ASKR_INSTANCES)) {\n for (const instance of node.__ASKR_INSTANCES) {\n if (instance) {\n instances.add(instance as ComponentInstance);\n }\n }\n }\n\n if (node.__ASKR_INSTANCE) {\n instances.add(node.__ASKR_INSTANCE as ComponentInstance);\n }\n\n for (const instance of instances) {\n try {\n cleanupComponent(instance);\n } catch (err) {\n if (strict) errors!.push(err);\n else logger.warn('[Askr] cleanupComponent failed:', err);\n }\n }\n\n try {\n delete node.__ASKR_INSTANCE;\n delete node.__ASKR_INSTANCES;\n } catch (e) {\n if (strict) errors!.push(e);\n }\n}\n\nfunction teardownSingleElement(\n element: Element,\n errors: unknown[] | null,\n strict: boolean\n): void {\n try {\n removeElementRef(element);\n } catch (err) {\n if (strict) errors!.push(err);\n else logger.warn('[Askr] removeElementRef failed:', err);\n }\n\n try {\n removeElementListeners(element);\n } catch (err) {\n if (strict) errors!.push(err);\n else logger.warn('[Askr] removeElementListeners failed:', err);\n }\n\n try {\n removeElementReactiveProps(element);\n } catch (err) {\n if (strict) errors!.push(err);\n else logger.warn('[Askr] removeElementReactiveProps failed:', err);\n }\n\n try {\n cleanupSingleInstance(element as InstanceHost, errors, strict);\n } catch (err) {\n if (strict) errors!.push(err);\n else logger.warn('[Askr] cleanupSingleInstance failed:', err);\n }\n}\n\n// Walk descendant elements with minimal allocations.\n// HOT PATH: used during subtree teardown (replace/unmount).\nfunction forEachDescendantElement(root: Element, visit: (el: Element) => void) {\n // Prefer TreeWalker when available; it avoids allocating a NodeList.\n try {\n const doc = root.ownerDocument;\n const createTreeWalker = doc?.createTreeWalker;\n if (typeof createTreeWalker === 'function') {\n // NodeFilter.SHOW_ELEMENT === 1\n const walker = createTreeWalker.call(doc, root, 1);\n let n = walker.firstChild();\n while (n) {\n visit(n as Element);\n n = walker.nextNode();\n }\n return;\n }\n } catch {\n // SLOW PATH: TreeWalker unavailable\n }\n\n // Fallback: querySelectorAll\n const descendants = root.querySelectorAll('*');\n for (let i = 0; i < descendants.length; i++) {\n visit(descendants[i]);\n }\n}\n\nfunction forEachDescendantNode(root: Node, visit: (node: Node) => void) {\n try {\n const doc = root.ownerDocument;\n const createTreeWalker = doc?.createTreeWalker;\n if (typeof createTreeWalker === 'function') {\n // NodeFilter.SHOW_ALL === 0xffffffff\n const walker = createTreeWalker.call(doc, root, 0xffffffff);\n let node = walker.nextNode();\n while (node) {\n visit(node);\n node = walker.nextNode();\n }\n return;\n }\n } catch {\n // SLOW PATH: TreeWalker unavailable\n }\n\n const stack = Array.from(root.childNodes).reverse();\n while (stack.length > 0) {\n const node = stack.pop()!;\n visit(node);\n for (let child = node.lastChild; child; child = child.previousSibling) {\n stack.push(child);\n }\n }\n}\n\nfunction forEachElementInSubtree(root: Element, visit: (el: Element) => void) {\n visit(root);\n forEachDescendantElement(root, visit);\n}\n\n// Track listeners so we can remove them on cleanup\nexport interface ListenerMapEntry {\n handler: EventListener;\n original: EventListener;\n eventName: string;\n options?: boolean | AddEventListenerOptions;\n isDelegated?: boolean;\n updateHandler?: (nextHandler: EventListener) => void;\n}\nexport const elementListeners = new WeakMap<\n Element,\n Map<string, ListenerMapEntry>\n>();\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Public API\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Clean up component instance attached to a DOM node\n * Accepts an optional `opts.strict` flag to surface errors instead of swallowing them.\n */\nexport function cleanupInstanceIfPresent(\n node: Node | null,\n opts?: { strict?: boolean }\n): void {\n if (!node) return;\n\n const strict = opts?.strict ?? false;\n const errors: unknown[] | null = strict ? [] : null;\n\n // Clean up the node itself\n try {\n cleanupSingleInstance(node as InstanceHost, errors, strict);\n } catch (err) {\n if (strict) errors!.push(err);\n else logger.warn('[Askr] cleanupInstanceIfPresent failed:', err);\n }\n\n // Clean up any nested instances, including null-component comment hosts.\n try {\n forEachDescendantNode(node, (descendant) => {\n try {\n cleanupSingleInstance(descendant as InstanceHost, errors, strict);\n } catch (err) {\n if (strict) errors!.push(err);\n else\n logger.warn(\n '[Askr] cleanupInstanceIfPresent descendant cleanup failed:',\n err\n );\n }\n });\n } catch (err) {\n if (strict) errors!.push(err);\n else\n logger.warn(\n '[Askr] cleanupInstanceIfPresent descendant query failed:',\n err\n );\n }\n\n if (errors && errors.length > 0) {\n throw new AggregateError(errors, 'cleanupInstanceIfPresent failed');\n }\n}\n\n// Public helper to clean up any component instances under a node. Used by\n// runtime commit logic to ensure component instances are torn down when their\n// host nodes are removed during an update.\nexport function cleanupInstancesUnder(\n node: Node | null,\n opts?: { strict?: boolean }\n): void {\n cleanupInstanceIfPresent(node, opts);\n}\n\nexport function teardownNodeSubtree(\n node: Node | null,\n opts?: { strict?: boolean }\n): void {\n if (!node) return;\n\n const strict = opts?.strict ?? false;\n const errors: unknown[] | null = strict ? [] : null;\n\n if (!(node instanceof Element)) {\n cleanupSingleInstance(node as InstanceHost, errors, strict);\n if (errors && errors.length > 0) {\n throw new AggregateError(errors, 'teardownNodeSubtree failed');\n }\n return;\n }\n\n try {\n teardownSingleElement(node, errors, strict);\n forEachDescendantNode(node, (descendant) => {\n if (descendant instanceof Element) {\n teardownSingleElement(descendant, errors, strict);\n } else {\n cleanupSingleInstance(descendant as InstanceHost, errors, strict);\n }\n });\n } catch (err) {\n if (strict) errors!.push(err);\n else logger.warn('[Askr] teardownNodeSubtree failed:', err);\n }\n\n if (errors && errors.length > 0) {\n throw new AggregateError(errors, 'teardownNodeSubtree failed');\n }\n}\n\n// Track reactive props cleanup functions and their function references\nexport interface ReactivePropCleanupEntry {\n cleanup: () => void;\n fnRef: unknown;\n restoreFn?: (nextValue: unknown) => ReactivePropCleanupEntry;\n updateFn?: (nextValue: unknown) => void;\n}\n\nexport const REACTIVE_CHILDREN_KEY = '__askr_reactive_children__';\n\nexport const elementReactivePropsCleanup = new WeakMap<\n Element,\n Map<string, ReactivePropCleanupEntry>\n>();\n\nexport function removeElementReactiveProps(element: Element): void {\n const cleanupMap = elementReactivePropsCleanup.get(element);\n if (cleanupMap) {\n for (const entry of cleanupMap.values()) {\n try {\n entry.cleanup();\n } catch (err) {\n logger.warn('[Askr] reactive prop cleanup failed:', err);\n }\n }\n elementReactivePropsCleanup.delete(element);\n }\n}\n\nexport function removeElementListeners(element: Element): void {\n const map = elementListeners.get(element);\n if (map) {\n for (const entry of map.values()) {\n incDevCounter('listenerRemoves');\n if (entry.isDelegated) {\n removeDelegatedListener(element, entry.eventName);\n } else {\n if (entry.options !== undefined)\n element.removeEventListener(\n entry.eventName,\n entry.handler,\n entry.options\n );\n else element.removeEventListener(entry.eventName, entry.handler);\n }\n }\n elementListeners.delete(element);\n }\n\n clearDelegatedHandlersForElement(element);\n}\n\nexport function removeAllListeners(root: Element | null): void {\n if (!root) return;\n\n forEachElementInSubtree(root, (el) => {\n removeElementRef(el);\n removeElementListeners(el);\n removeElementReactiveProps(el);\n });\n}\n"],"mappings":";;;;;;AAmBA,MAAa,8BAAc,IAAI,QAA0B;AAEzD,SAAS,cAAiB,KAAc,OAAuB;CAC7D,MAAM,cAAc;CAEpB,IAAI,CAAC,aACH;CAGF,IAAI,OAAO,gBAAgB,YAAY;EACrC,YAAY,KAAK;EACjB;CACF;CAEA,IAAI,OAAO,aAAa,WAAW,GACjC,YAAuC,UAAU;AAErD;AAEA,SAAgB,iBACd,SACA,KACM;CACN,MAAM,cAAc,YAAY,IAAI,OAAO;CAE3C,IAAI,gBAAgB,KAClB;CAGF,IAAI,aACF,cAAc,aAAa,IAAI;CAGjC,IAAI,KAAK;EACP,cAAc,KAAK,OAAO;EAC1B,YAAY,IAAI,SAAS,GAAG;CAC9B,OACE,YAAY,OAAO,OAAO;AAE9B;AAEA,SAAgB,iBAAiB,SAAwB;CACvD,MAAM,MAAM,YAAY,IAAI,OAAO;CAEnC,IAAI,CAAC,KACH;CAGF,cAAc,KAAK,IAAI;CACvB,YAAY,OAAO,OAAO;AAC5B;AAMA,SAAS,sBACP,MACA,QACA,QACM;CACN,MAAM,4BAAY,IAAI,IAAuB;CAE7C,IAAI,MAAM,QAAQ,KAAK,gBAAgB,GACrC;OAAK,MAAM,YAAY,KAAK,kBAC1B,IAAI,UACF,UAAU,IAAI,QAA6B;CAE/C;CAGF,IAAI,KAAK,iBACP,UAAU,IAAI,KAAK,eAAoC;CAGzD,KAAK,MAAM,YAAY,WACrB,IAAI;EACF,iBAAiB,QAAQ;CAC3B,SAAS,KAAK;EACZ,IAAI,QAAQ,OAAQ,KAAK,GAAG;OACvB,OAAO,KAAK,mCAAmC,GAAG;CACzD;CAGF,IAAI;EACF,OAAO,KAA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A,iCAAiC,OAAO;AAC1C;AAEA,SAAgB,mBAAmB,MAA4B;CAC7D,IAAI,CAAC,MAAM;CAEX,wBAAwB,OAAO,OAAO;EACpC,iBAAiB,EAAE;EACnB,uBAAuB,EAAE;EACzB,2BAA2B,EAAE;CAC/B,CAAC;AACH"}
@@ -1,5 +1,5 @@
1
1
  import { cleanupComponent } from "../runtime/component-cleanup.js";
2
- import "../runtime/component-contracts.js";
2
+ import "../runtime/index.js";
3
3
  import { removeElementListeners, removeElementReactiveProps } from "./cleanup.js";
4
4
  //#region src/renderer/component-host-cleanup.ts
5
5
  function cleanupDetachedComponentHost(host, retainedInstance) {
@@ -1 +1 @@
1
- {"version":3,"file":"component-host-cleanup.js","names":[],"sources":["../../src/renderer/component-host-cleanup.ts"],"sourcesContent":["import { cleanupComponent } from '../runtime/component-contracts';\nimport type { ComponentInstance } from '../runtime/component-contracts';\nimport { removeElementListeners, removeElementReactiveProps } from './cleanup';\nimport type { InstanceHostElement } from './dom-host';\n\nexport function cleanupDetachedComponentHost(\n host: InstanceHostElement,\n retainedInstance: ComponentInstance\n): void {\n removeElementListeners(host);\n removeElementReactiveProps(host);\n\n const hostInstances = host.__ASKR_INSTANCES;\n if (hostInstances && hostInstances.length > 0) {\n for (const instance of hostInstances) {\n if (instance === retainedInstance) continue;\n cleanupComponent(instance);\n }\n } else if (\n host.__ASKR_INSTANCE &&\n host.__ASKR_INSTANCE !== retainedInstance\n ) {\n cleanupComponent(host.__ASKR_INSTANCE);\n }\n\n const descendants = host.querySelectorAll('*');\n for (let index = 0; index < descendants.length; index += 1) {\n const descendant = descendants[index] as InstanceHostElement;\n removeElementListeners(descendant);\n removeElementReactiveProps(descendant);\n\n if (descendant.__ASKR_INSTANCES?.length) {\n for (const instance of descendant.__ASKR_INSTANCES) {\n if (instance === retainedInstance) continue;\n cleanupComponent(instance);\n }\n try {\n delete descendant.__ASKR_INSTANCES;\n } catch {\n // Ignore host cleanup failures.\n }\n } else if (\n descendant.__ASKR_INSTANCE &&\n descendant.__ASKR_INSTANCE !== retainedInstance\n ) {\n cleanupComponent(descendant.__ASKR_INSTANCE);\n try {\n delete descendant.__ASKR_INSTANCE;\n } catch {\n // Ignore host cleanup failures.\n }\n }\n }\n\n try {\n delete host.__ASKR_INSTANCE;\n delete host.__ASKR_INSTANCES;\n delete host.__ASKR_WRAPPER_HOST;\n } catch {\n // Ignore host cleanup failures.\n }\n}\n\nexport function pruneComponentHostInstances(\n host: InstanceHostElement,\n retainedInstances: Iterable<ComponentInstance>\n): void {\n const retained = new Set(retainedInstances);\n const nextInstances: ComponentInstance[] = [];\n const staleInstances = new Set<ComponentInstance>();\n\n const retainOrMarkStale = (instance: ComponentInstance | undefined) => {\n if (!instance) {\n return;\n }\n\n if (retained.has(instance)) {\n if (!nextInstances.includes(instance)) {\n nextInstances.push(instance);\n }\n return;\n }\n\n staleInstances.add(instance);\n };\n\n for (const instance of host.__ASKR_INSTANCES ?? []) {\n retainOrMarkStale(instance);\n }\n retainOrMarkStale(host.__ASKR_INSTANCE);\n\n for (const instance of staleInstances) {\n cleanupComponent(instance);\n }\n\n try {\n if (nextInstances.length > 0) {\n host.__ASKR_INSTANCES = nextInstances;\n host.__ASKR_INSTANCE = nextInstances[0];\n } else {\n delete host.__ASKR_INSTANCES;\n delete host.__ASKR_INSTANCE;\n }\n } catch {\n // Ignore host metadata cleanup failures.\n }\n}\n"],"mappings":";;;;AAKA,SAAgB,6BACd,MACA,kBACM;CACN,uBAAuB,IAAI;CAC3B,2BAA2B,IAAI;CAE/B,MAAM,gBAAgB,KAAK;CAC3B,IAAI,iBAAiB,cAAc,SAAS,GAC1C,KAAK,MAAM,YAAY,eAAe;EACpC,IAAI,aAAa,kBAAkB;EACnC,iBAAiB,QAAQ;CAC3B;MACK,IACL,KAAK,mBACL,KAAK,oBAAoB,kBAEzB,iBAAiB,KAAK,eAAe;CAGvC,MAAM,cAAc,KAAK,iBAAiB,GAAG;CAC7C,KAAK,IAAI,QAAQ,GAAG,QAAQ,YAAY,QAAQ,SAAS,GAAG;EAC1D,MAAM,aAAa,YAAY;EAC/B,uBAAuB,UAAU;EACjC,2BAA2B,UAAU;EAErC,IAAI,WAAW,kBAAkB,QAAQ;GACvC,KAAK,MAAM,YAAY,WAAW,kBAAkB;IAClD,IAAI,aAAa,kBAAkB;IACnC,iBAAiB,QAAQ;GAC3B;GACA,IAAI;IACF,OAAO,WAAW;GACpB,QAAQ,CAER;EACF,OAAO,IACL,WAAW,mBACX,WAAW,oBAAoB,kBAC/B;GACA,iBAAiB,WAAW,eAAe;GAC3C,IAAI;IACF,OAAO,WAAW;GACpB,QAAQ,CAER;EACF;CACF;CAEA,IAAI;EACF,OAAO,KAAK;EACZ,OAAO,KAAK;EACZ,OAAO,KAAK;CACd,QAAQ,CAER;AACF;AAEA,SAAgB,4BACd,MACA,mBACM;CACN,MAAM,WAAW,IAAI,IAAI,iBAAiB;CAC1C,MAAM,gBAAqC,CAAC;CAC5C,MAAM,iCAAiB,IAAI,IAAuB;CAElD,MAAM,qBAAqB,aAA4C;EACrE,IAAI,CAAC,UACH;EAGF,IAAI,SAAS,IAAI,QAAQ,GAAG;GAC1B,IAAI,CAAC,cAAc,SAAS,QAAQ,GAClC,cAAc,KAAK,QAAQ;GAE7B;EACF;EAEA,eAAe,IAAI,QAAQ;CAC7B;CAEA,KAAK,MAAM,YAAY,KAAK,oBAAoB,CAAC,GAC/C,kBAAkB,QAAQ;CAE5B,kBAAkB,KAAK,eAAe;CAEtC,KAAK,MAAM,YAAY,gBACrB,iBAAiB,QAAQ;CAG3B,IAAI;EACF,IAAI,cAAc,SAAS,GAAG;GAC5B,KAAK,mBAAmB;GACxB,KAAK,kBAAkB,cAAc;EACvC,OAAO;GACL,OAAO,KAAK;GACZ,OAAO,KAAK;EACd;CACF,QAAQ,CAER;AACF"}
1
+ {"version":3,"file":"component-host-cleanup.js","names":[],"sources":["../../src/renderer/component-host-cleanup.ts"],"sourcesContent":["import { cleanupComponent } from '../runtime';\nimport type { ComponentInstance } from '../runtime';\nimport { removeElementListeners, removeElementReactiveProps } from './cleanup';\nimport type { InstanceHostElement } from './dom-host';\n\nexport function cleanupDetachedComponentHost(\n host: InstanceHostElement,\n retainedInstance: ComponentInstance\n): void {\n removeElementListeners(host);\n removeElementReactiveProps(host);\n\n const hostInstances = host.__ASKR_INSTANCES;\n if (hostInstances && hostInstances.length > 0) {\n for (const instance of hostInstances) {\n if (instance === retainedInstance) continue;\n cleanupComponent(instance);\n }\n } else if (\n host.__ASKR_INSTANCE &&\n host.__ASKR_INSTANCE !== retainedInstance\n ) {\n cleanupComponent(host.__ASKR_INSTANCE);\n }\n\n const descendants = host.querySelectorAll('*');\n for (let index = 0; index < descendants.length; index += 1) {\n const descendant = descendants[index] as InstanceHostElement;\n removeElementListeners(descendant);\n removeElementReactiveProps(descendant);\n\n if (descendant.__ASKR_INSTANCES?.length) {\n for (const instance of descendant.__ASKR_INSTANCES) {\n if (instance === retainedInstance) continue;\n cleanupComponent(instance);\n }\n try {\n delete descendant.__ASKR_INSTANCES;\n } catch {\n // Ignore host cleanup failures.\n }\n } else if (\n descendant.__ASKR_INSTANCE &&\n descendant.__ASKR_INSTANCE !== retainedInstance\n ) {\n cleanupComponent(descendant.__ASKR_INSTANCE);\n try {\n delete descendant.__ASKR_INSTANCE;\n } catch {\n // Ignore host cleanup failures.\n }\n }\n }\n\n try {\n delete host.__ASKR_INSTANCE;\n delete host.__ASKR_INSTANCES;\n delete host.__ASKR_WRAPPER_HOST;\n } catch {\n // Ignore host cleanup failures.\n }\n}\n\nexport function pruneComponentHostInstances(\n host: InstanceHostElement,\n retainedInstances: Iterable<ComponentInstance>\n): void {\n const retained = new Set(retainedInstances);\n const nextInstances: ComponentInstance[] = [];\n const staleInstances = new Set<ComponentInstance>();\n\n const retainOrMarkStale = (instance: ComponentInstance | undefined) => {\n if (!instance) {\n return;\n }\n\n if (retained.has(instance)) {\n if (!nextInstances.includes(instance)) {\n nextInstances.push(instance);\n }\n return;\n }\n\n staleInstances.add(instance);\n };\n\n for (const instance of host.__ASKR_INSTANCES ?? []) {\n retainOrMarkStale(instance);\n }\n retainOrMarkStale(host.__ASKR_INSTANCE);\n\n for (const instance of staleInstances) {\n cleanupComponent(instance);\n }\n\n try {\n if (nextInstances.length > 0) {\n host.__ASKR_INSTANCES = nextInstances;\n host.__ASKR_INSTANCE = nextInstances[0];\n } else {\n delete host.__ASKR_INSTANCES;\n delete host.__ASKR_INSTANCE;\n }\n } catch {\n // Ignore host metadata cleanup failures.\n }\n}\n"],"mappings":";;;;AAKA,SAAgB,6BACd,MACA,kBACM;CACN,uBAAuB,IAAI;CAC3B,2BAA2B,IAAI;CAE/B,MAAM,gBAAgB,KAAK;CAC3B,IAAI,iBAAiB,cAAc,SAAS,GAC1C,KAAK,MAAM,YAAY,eAAe;EACpC,IAAI,aAAa,kBAAkB;EACnC,iBAAiB,QAAQ;CAC3B;MACK,IACL,KAAK,mBACL,KAAK,oBAAoB,kBAEzB,iBAAiB,KAAK,eAAe;CAGvC,MAAM,cAAc,KAAK,iBAAiB,GAAG;CAC7C,KAAK,IAAI,QAAQ,GAAG,QAAQ,YAAY,QAAQ,SAAS,GAAG;EAC1D,MAAM,aAAa,YAAY;EAC/B,uBAAuB,UAAU;EACjC,2BAA2B,UAAU;EAErC,IAAI,WAAW,kBAAkB,QAAQ;GACvC,KAAK,MAAM,YAAY,WAAW,kBAAkB;IAClD,IAAI,aAAa,kBAAkB;IACnC,iBAAiB,QAAQ;GAC3B;GACA,IAAI;IACF,OAAO,WAAW;GACpB,QAAQ,CAER;EACF,OAAO,IACL,WAAW,mBACX,WAAW,oBAAoB,kBAC/B;GACA,iBAAiB,WAAW,eAAe;GAC3C,IAAI;IACF,OAAO,WAAW;GACpB,QAAQ,CAER;EACF;CACF;CAEA,IAAI;EACF,OAAO,KAAK;EACZ,OAAO,KAAK;EACZ,OAAO,KAAK;CACd,QAAQ,CAER;AACF;AAEA,SAAgB,4BACd,MACA,mBACM;CACN,MAAM,WAAW,IAAI,IAAI,iBAAiB;CAC1C,MAAM,gBAAqC,CAAC;CAC5C,MAAM,iCAAiB,IAAI,IAAuB;CAElD,MAAM,qBAAqB,aAA4C;EACrE,IAAI,CAAC,UACH;EAGF,IAAI,SAAS,IAAI,QAAQ,GAAG;GAC1B,IAAI,CAAC,cAAc,SAAS,QAAQ,GAClC,cAAc,KAAK,QAAQ;GAE7B;EACF;EAEA,eAAe,IAAI,QAAQ;CAC7B;CAEA,KAAK,MAAM,YAAY,KAAK,oBAAoB,CAAC,GAC/C,kBAAkB,QAAQ;CAE5B,kBAAkB,KAAK,eAAe;CAEtC,KAAK,MAAM,YAAY,gBACrB,iBAAiB,QAAQ;CAG3B,IAAI;EACF,IAAI,cAAc,SAAS,GAAG;GAC5B,KAAK,mBAAmB;GACxB,KAAK,kBAAkB,cAAc;EACvC,OAAO;GACL,OAAO,KAAK;GACZ,OAAO,KAAK;EACd;CACF,QAAQ,CAER;AACF"}
@@ -1,6 +1,6 @@
1
1
  import { getDevValue, incDevCounter } from "../runtime/dev-namespace.js";
2
2
  import { getCurrentInstance } from "../runtime/component-scope.js";
3
- import "../runtime/component-contracts.js";
3
+ import "../runtime/index.js";
4
4
  import { extractKey } from "./utils.js";
5
5
  import { ROUTE_ROOT_COMPONENT } from "../common/router-internal.js";
6
6
  //#region src/renderer/component-host-instances.ts
@@ -1 +1 @@
1
- {"version":3,"file":"component-host-instances.js","names":[],"sources":["../../src/renderer/component-host-instances.ts"],"sourcesContent":["import { ROUTE_ROOT_COMPONENT } from '../common/router-internal';\nimport type { Props } from '../common/props';\nimport {\n getCurrentInstance,\n type ComponentInstance,\n} from '../runtime/component-contracts';\nimport { getDevValue, incDevCounter } from '../runtime/dev-namespace';\nimport type { InstanceHostElement } from './dom-host';\nimport type { DOMElement } from './types';\nimport { extractKey } from './utils';\n\nexport function isRouteRootComponentVNode(node: unknown): boolean {\n return (\n typeof node === 'object' &&\n node !== null &&\n (node as { [ROUTE_ROOT_COMPONENT]?: boolean })[ROUTE_ROOT_COMPONENT] ===\n true\n );\n}\n\nexport function inheritComponentCleanupStrict(\n instance: ComponentInstance\n): void {\n const owner = getCurrentInstance();\n if (owner) {\n instance.cleanupStrict = owner.cleanupStrict;\n }\n}\n\nconst vnodeComponentInstances = new WeakMap<object, ComponentInstance>();\n\nexport function getVNodeComponentInstance(\n node: unknown\n): ComponentInstance | undefined {\n if (typeof node !== 'object' || node === null) {\n return undefined;\n }\n\n return (\n vnodeComponentInstances.get(node) ??\n (node as { __instance?: ComponentInstance }).__instance\n );\n}\n\nexport function setVNodeComponentInstance(\n node: unknown,\n instance: ComponentInstance\n): void {\n if (typeof node !== 'object' || node === null) {\n return;\n }\n\n const objectNode = node as { __instance?: ComponentInstance };\n\n if (Object.prototype.hasOwnProperty.call(objectNode, '__instance')) {\n try {\n objectNode.__instance = instance;\n return;\n } catch {\n // Fall back to WeakMap for readonly vnode metadata.\n }\n }\n\n if (Object.isExtensible(objectNode)) {\n try {\n objectNode.__instance = instance;\n return;\n } catch {\n // Fall back to WeakMap for frozen/proxied objects.\n }\n }\n\n vnodeComponentInstances.set(objectNode, instance);\n}\n\nlet fallbackComponentInstanceId = 0;\n\nexport function nextComponentInstanceId(): string {\n const key = '__COMPONENT_INSTANCE_ID';\n try {\n incDevCounter(key);\n const n = getDevValue<number>(key);\n if (typeof n === 'number' && Number.isFinite(n)) return `comp-${n}`;\n } catch {\n // Fall through to local counter\n }\n fallbackComponentInstanceId++;\n return `comp-${fallbackComponentInstanceId}`;\n}\n\nexport function inheritComponentKey(\n target: DOMElement,\n source: DOMElement\n): DOMElement {\n const inheritedKey = extractKey(source);\n if (inheritedKey === undefined || extractKey(target) !== undefined) {\n return target;\n }\n\n target.key = inheritedKey;\n\n if (typeof target.type === 'string') {\n if (!target.props) {\n target.props = {};\n }\n\n const props = target.props as Record<string, unknown>;\n if (props['data-key'] === undefined) {\n props['data-key'] = String(inheritedKey);\n }\n }\n\n return target;\n}\n\nexport function findHostInstanceByType(\n host: InstanceHostElement,\n type: (props: Props) => unknown\n): ComponentInstance | null {\n const instances = host.__ASKR_INSTANCES;\n if (instances && instances.length > 0) {\n for (let index = instances.length - 1; index >= 0; index -= 1) {\n const instance = instances[index]!;\n if (instance.fn === type) {\n return instance;\n }\n }\n }\n\n return host.__ASKR_INSTANCE?.fn === type ? host.__ASKR_INSTANCE : null;\n}\n"],"mappings":";;;;;;AAWA,SAAgB,0BAA0B,MAAwB;CAChE,OACE,OAAO,SAAS,YAChB,SAAS,QACR,KAA8C,0BAC7C;AAEN;AAEA,SAAgB,8BACd,UACM;CACN,MAAM,QAAQ,mBAAmB;CACjC,IAAI,OACF,SAAS,gBAAgB,MAAM;AAEnC;AAEA,MAAM,0CAA0B,IAAI,QAAmC;AAEvE,SAAgB,0BACd,MAC+B;CAC/B,IAAI,OAAO,SAAS,YAAY,SAAS,MACvC;CAGF,OACE,wBAAwB,IAAI,IAAI,KAC/B,KAA4C;AAEjD;AAEA,SAAgB,0BACd,MACA,UACM;CACN,IAAI,OAAO,SAAS,YAAY,SAAS,MACvC;CAGF,MAAM,aAAa;CAEnB,IAAI,OAAO,UAAU,eAAe,KAAK,YAAY,YAAY,GAC/D,IAAI;EACF,WAAW,aAAa;EACxB;CACF,QAAQ,CAER;CAGF,IAAI,OAAO,aAAa,UAAU,GAChC,IAAI;EACF,WAAW,aAAa;EACxB;CACF,QAAQ,CAER;CAGF,wBAAwB,IAAI,YAAY,QAAQ;AAClD;AAEA,IAAI,8BAA8B;AAElC,SAAgB,0BAAkC;CAChD,MAAM,MAAM;CACZ,IAAI;EACF,cAAc,GAAG;EACjB,MAAM,IAAI,YAAoB,GAAG;EACjC,IAAI,OAAO,MAAM,YAAY,OAAO,SAAS,CAAC,GAAG,OAAO,QAAQ;CAClE,QAAQ,CAER;CACA;CACA,OAAO,QAAQ;AACjB;AAEA,SAAgB,oBACd,QACA,QACY;CACZ,MAAM,eAAe,WAAW,MAAM;CACtC,IAAI,iBAAiB,UAAa,WAAW,MAAM,MAAM,QACvD,OAAO;CAGT,OAAO,MAAM;CAEb,IAAI,OAAO,OAAO,SAAS,UAAU;EACnC,IAAI,CAAC,OAAO,OACV,OAAO,QAAQ,CAAC;EAGlB,MAAM,QAAQ,OAAO;EACrB,IAAI,MAAM,gBAAgB,QACxB,MAAM,cAAc,OAAO,YAAY;CAE3C;CAEA,OAAO;AACT;AAEA,SAAgB,uBACd,MACA,MAC0B;CAC1B,MAAM,YAAY,KAAK;CACvB,IAAI,aAAa,UAAU,SAAS,GAClC,KAAK,IAAI,QAAQ,UAAU,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG;EAC7D,MAAM,WAAW,UAAU;EAC3B,IAAI,SAAS,OAAO,MAClB,OAAO;CAEX;CAGF,OAAO,KAAK,iBAAiB,OAAO,OAAO,KAAK,kBAAkB;AACpE"}
1
+ {"version":3,"file":"component-host-instances.js","names":[],"sources":["../../src/renderer/component-host-instances.ts"],"sourcesContent":["import { ROUTE_ROOT_COMPONENT } from '../common/router-internal';\nimport type { Props } from '../common/props';\nimport { getCurrentInstance, type ComponentInstance } from '../runtime';\nimport { getDevValue, incDevCounter } from '../runtime';\nimport type { InstanceHostElement } from './dom-host';\nimport type { DOMElement } from './types';\nimport { extractKey } from './utils';\n\nexport function isRouteRootComponentVNode(node: unknown): boolean {\n return (\n typeof node === 'object' &&\n node !== null &&\n (node as { [ROUTE_ROOT_COMPONENT]?: boolean })[ROUTE_ROOT_COMPONENT] ===\n true\n );\n}\n\nexport function inheritComponentCleanupStrict(\n instance: ComponentInstance\n): void {\n const owner = getCurrentInstance();\n if (owner) {\n instance.cleanupStrict = owner.cleanupStrict;\n }\n}\n\nconst vnodeComponentInstances = new WeakMap<object, ComponentInstance>();\n\nexport function getVNodeComponentInstance(\n node: unknown\n): ComponentInstance | undefined {\n if (typeof node !== 'object' || node === null) {\n return undefined;\n }\n\n return (\n vnodeComponentInstances.get(node) ??\n (node as { __instance?: ComponentInstance }).__instance\n );\n}\n\nexport function setVNodeComponentInstance(\n node: unknown,\n instance: ComponentInstance\n): void {\n if (typeof node !== 'object' || node === null) {\n return;\n }\n\n const objectNode = node as { __instance?: ComponentInstance };\n\n if (Object.prototype.hasOwnProperty.call(objectNode, '__instance')) {\n try {\n objectNode.__instance = instance;\n return;\n } catch {\n // Fall back to WeakMap for readonly vnode metadata.\n }\n }\n\n if (Object.isExtensible(objectNode)) {\n try {\n objectNode.__instance = instance;\n return;\n } catch {\n // Fall back to WeakMap for frozen/proxied objects.\n }\n }\n\n vnodeComponentInstances.set(objectNode, instance);\n}\n\nlet fallbackComponentInstanceId = 0;\n\nexport function nextComponentInstanceId(): string {\n const key = '__COMPONENT_INSTANCE_ID';\n try {\n incDevCounter(key);\n const n = getDevValue<number>(key);\n if (typeof n === 'number' && Number.isFinite(n)) return `comp-${n}`;\n } catch {\n // Fall through to local counter\n }\n fallbackComponentInstanceId++;\n return `comp-${fallbackComponentInstanceId}`;\n}\n\nexport function inheritComponentKey(\n target: DOMElement,\n source: DOMElement\n): DOMElement {\n const inheritedKey = extractKey(source);\n if (inheritedKey === undefined || extractKey(target) !== undefined) {\n return target;\n }\n\n target.key = inheritedKey;\n\n if (typeof target.type === 'string') {\n if (!target.props) {\n target.props = {};\n }\n\n const props = target.props as Record<string, unknown>;\n if (props['data-key'] === undefined) {\n props['data-key'] = String(inheritedKey);\n }\n }\n\n return target;\n}\n\nexport function findHostInstanceByType(\n host: InstanceHostElement,\n type: (props: Props) => unknown\n): ComponentInstance | null {\n const instances = host.__ASKR_INSTANCES;\n if (instances && instances.length > 0) {\n for (let index = instances.length - 1; index >= 0; index -= 1) {\n const instance = instances[index]!;\n if (instance.fn === type) {\n return instance;\n }\n }\n }\n\n return host.__ASKR_INSTANCE?.fn === type ? host.__ASKR_INSTANCE : null;\n}\n"],"mappings":";;;;;;AAQA,SAAgB,0BAA0B,MAAwB;CAChE,OACE,OAAO,SAAS,YAChB,SAAS,QACR,KAA8C,0BAC7C;AAEN;AAEA,SAAgB,8BACd,UACM;CACN,MAAM,Q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AS,GAAG;EAC7D,MAAM,WAAW,UAAU;EAC3B,IAAI,SAAS,OAAO,MAClB,OAAO;CAEX;CAGF,OAAO,KAAK,iBAAiB,OAAO,OAAO,KAAK,kBAAkB;AACpE"}
@@ -5,7 +5,7 @@ import { getCurrentInstance } from "../runtime/component-scope.js";
5
5
  import { cleanupComponent } from "../runtime/component-cleanup.js";
6
6
  import { isPromiseLike } from "../common/promise.js";
7
7
  import { captureInlineRenderSnapshot, createComponentInstance, mountInstanceInline, renderComponentInline, warnUnusedStateReads } from "../runtime/component-internal.js";
8
- import "../runtime/component-contracts.js";
8
+ import "../runtime/index.js";
9
9
  import { tagNamesEqualIgnoreCase } from "./utils.js";
10
10
  import { materializeKey } from "./attributes.js";
11
11
  import { normalizeComponentChildren } from "./child-shape.js";
@@ -1 +1 @@
1
- {"version":3,"file":"component-host.js","names":[],"sources":["../../src/renderer/component-host.ts"],"sourcesContent":["import { isPromiseLike } from '../common/promise';\nimport type { Props } from '../common/props';\nimport {\n captureInlineRenderSnapshot,\n cleanupComponent,\n createComponentInstance,\n getCurrentInstance,\n mountInstanceInline,\n renderComponentInline,\n warnUnusedStateReads,\n type ComponentFunction,\n type ComponentInstance,\n} from '../runtime/component-contracts';\nimport {\n getCurrentContextFrame,\n getVNodeContextFrame,\n markVNodeTreeWithContextFrame,\n withContext,\n type ContextFrame,\n} from '../runtime/context';\nimport { materializeKey } from './attributes';\nimport { normalizeComponentChildren } from './child-shape';\nimport {\n cleanupDetachedComponentHost,\n pruneComponentHostInstances,\n} from './component-host-cleanup';\nimport {\n getRendererDOMHost,\n type ElementWithContext,\n type InstanceHostElement,\n} from './dom-host';\nimport {\n findHostInstanceByType,\n getVNodeComponentInstance,\n inheritComponentCleanupStrict,\n inheritComponentKey,\n isRouteRootComponentVNode,\n nextComponentInstanceId,\n setVNodeComponentInstance,\n} from './component-host-instances';\nimport { _isDOMElement, type DOMElement, type VNode } from './types';\nimport { tagNamesEqualIgnoreCase } from './utils';\nexport {\n findHostInstanceByType,\n inheritComponentCleanupStrict,\n inheritComponentKey,\n isRouteRootComponentVNode,\n nextComponentInstanceId,\n} from './component-host-instances';\nfunction materializeComponentResultNode(\n childInstance: ComponentInstance,\n result: unknown,\n parentNamespace?: string\n): Node {\n const dom = getRendererDOMHost().createDOMNode(result, parentNamespace);\n\n if (dom instanceof Element) {\n mountInstanceInline(childInstance, dom);\n return dom;\n }\n\n if (!dom) {\n const placeholder = document.createComment('');\n try {\n (\n placeholder as Comment & { __ASKR_INSTANCE?: ComponentInstance }\n ).__ASKR_INSTANCE = childInstance;\n } catch {\n // Ignore placeholder metadata failures.\n }\n childInstance._placeholder = placeholder;\n mountInstanceInline(childInstance, null);\n return placeholder;\n }\n\n const host = document.createElement('div') as InstanceHostElement;\n host.appendChild(dom);\n host.__ASKR_WRAPPER_HOST = true;\n mountInstanceInline(childInstance, host);\n return host;\n}\n\nexport function resolveNestedComponentResult(\n result: unknown,\n snapshot: ContextFrame | null,\n parentInstance: ComponentInstance | null\n): VNode {\n let currentResult = result as VNode;\n let activeSnapshot = snapshot;\n let depth = 0;\n\n while (\n _isDOMElement(currentResult) &&\n typeof currentResult.type === 'function' &&\n depth < 16\n ) {\n const nestedSnapshot =\n getVNodeContextFrame(currentResult) ?? activeSnapshot;\n const nestedInstance = createComponentInstance(\n nextComponentInstanceId(),\n currentResult.type as ComponentFunction,\n ((currentResult as DOMElement).props ?? {}) as Props,\n null\n );\n nestedInstance.isRoot = isRouteRootComponentVNode(currentResult);\n nestedInstance.parentInstance = parentInstance;\n nestedInstance.portalScope =\n parentInstance?.portalScope ?? nestedInstance.portalScope;\n inheritComponentCleanupStrict(nestedInstance);\n\n if (nestedSnapshot) {\n nestedInstance.ownerFrame = nestedSnapshot;\n }\n\n const nextResult = withContext(nestedSnapshot ?? null, () =>\n renderComponentInline(nestedInstance)\n );\n cleanupComponent(nestedInstance);\n\n if (isPromiseLike(nextResult)) {\n throw new Error(\n 'Async components are not supported. Components must return synchronously.'\n );\n }\n\n activeSnapshot = nestedSnapshot ?? null;\n currentResult = nextResult as VNode;\n depth += 1;\n }\n\n return currentResult;\n}\n\nfunction resolveHostNestedComponentResult(\n host: InstanceHostElement,\n retainedInstance: ComponentInstance,\n result: unknown,\n snapshot: ContextFrame | null,\n retainedHostInstances?: Iterable<ComponentInstance>\n): VNode {\n let currentResult = result as VNode;\n let activeSnapshot = snapshot;\n let depth = 0;\n const retainedInstances = new Set<ComponentInstance>([retainedInstance]);\n if (retainedHostInstances) {\n for (const instance of retainedHostInstances) {\n retainedInstances.add(instance);\n }\n }\n const createdInstances: ComponentInstance[] = [];\n\n while (\n _isDOMElement(currentResult) &&\n typeof currentResult.type === 'function' &&\n depth < 16\n ) {\n const nestedSnapshot =\n getVNodeContextFrame(currentResult) ?? activeSnapshot;\n let nestedInstance = findHostInstanceByType(\n host,\n currentResult.type as ComponentFunction\n );\n const hadNestedInstance = !!nestedInstance;\n\n if (!nestedInstance) {\n nestedInstance = createComponentInstance(\n nextComponentInstanceId(),\n currentResult.type as ComponentFunction,\n ((currentResult as DOMElement).props ?? {}) as Props,\n null\n );\n createdInstances.push(nestedInstance);\n }\n\n if (hadNestedInstance) {\n captureInlineRenderSnapshot(nestedInstance);\n }\n\n setVNodeComponentInstance(currentResult, nestedInstance);\n nestedInstance.isRoot = isRouteRootComponentVNode(currentResult);\n nestedInstance.parentInstance = retainedInstance;\n nestedInstance.portalScope =\n retainedInstance.portalScope ?? nestedInstance.portalScope;\n inheritComponentCleanupStrict(nestedInstance);\n nestedInstance.props =\n (((currentResult as DOMElement).props ?? {}) as Props) || {};\n\n if (nestedSnapshot) {\n nestedInstance.ownerFrame = nestedSnapshot;\n }\n\n const nextResult = withContext(nestedSnapshot ?? null, () =>\n renderComponentInline(nestedInstance)\n );\n\n if (isPromiseLike(nextResult)) {\n throw new Error(\n 'Async components are not supported. Components must return synchronously.'\n );\n }\n\n retainedInstances.add(nestedInstance);\n warnUnusedStateReads(nestedInstance);\n activeSnapshot = nestedSnapshot ?? null;\n currentResult = markVNodeTreeWithContextFrame(\n nextResult,\n activeSnapshot\n ) as VNode;\n depth += 1;\n }\n\n const previousInstances = host.__ASKR_INSTANCES ?? [];\n for (const instance of previousInstances) {\n if (!retainedInstances.has(instance)) {\n cleanupComponent(instance);\n }\n }\n\n const nextHostInstances = previousInstances.filter((instance) =>\n retainedInstances.has(instance)\n );\n for (const instance of retainedInstances) {\n if (instance.target === host && !nextHostInstances.includes(instance)) {\n nextHostInstances.push(instance);\n }\n }\n\n host.__ASKR_INSTANCES = nextHostInstances;\n host.__ASKR_INSTANCE = host.__ASKR_INSTANCES[0] ?? retainedInstance;\n\n for (const instance of createdInstances) {\n mountInstanceInline(instance, host);\n }\n\n return currentResult;\n}\n\nfunction resolveWrapperHostResult(\n host: InstanceHostElement,\n result: unknown,\n snapshot: ContextFrame | null\n): unknown {\n let currentResult = result;\n let activeSnapshot = snapshot;\n let depth = 0;\n\n while (\n _isDOMElement(currentResult) &&\n typeof currentResult.type === 'function' &&\n depth < 16\n ) {\n const nestedSnapshot =\n getVNodeContextFrame(currentResult) ?? activeSnapshot;\n const nestedInstance = findHostInstanceByType(\n host,\n currentResult.type as ComponentFunction\n );\n\n if (!nestedInstance) {\n break;\n }\n\n captureInlineRenderSnapshot(nestedInstance);\n\n nestedInstance.props =\n (((currentResult as DOMElement).props ?? {}) as Props) || {};\n nestedInstance.parentInstance = getCurrentInstance();\n nestedInstance.isRoot = isRouteRootComponentVNode(currentResult);\n nestedInstance.portalScope =\n getCurrentInstance()?.portalScope ?? nestedInstance.portalScope;\n inheritComponentCleanupStrict(nestedInstance);\n\n if (nestedSnapshot) {\n nestedInstance.ownerFrame = nestedSnapshot;\n }\n\n const nextResult = withContext(nestedSnapshot ?? null, () =>\n renderComponentInline(nestedInstance)\n );\n\n if (isPromiseLike(nextResult)) {\n throw new Error(\n 'Async components are not supported. Components must return synchronously.'\n );\n }\n\n warnUnusedStateReads(nestedInstance);\n activeSnapshot = nestedSnapshot ?? null;\n currentResult = nextResult;\n depth += 1;\n }\n\n return markVNodeTreeWithContextFrame(currentResult, activeSnapshot);\n}\n\nexport function syncComponentElement(\n currentDom: Node | null,\n node: ElementWithContext,\n type: ComponentFunction,\n props: Record<string, unknown>,\n parentNamespace?: string,\n forceChildrenUpdate = false,\n retainedHostInstances?: Iterable<ComponentInstance>\n): Node | null {\n const existingHost =\n currentDom instanceof Element ? (currentDom as InstanceHostElement) : null;\n const existingInstance = existingHost\n ? findHostInstanceByType(existingHost, type)\n : null;\n if (!existingHost) {\n return null;\n }\n\n const domHost = getRendererDOMHost();\n\n if (!existingInstance || existingInstance.fn !== type) {\n const snapshot =\n getVNodeContextFrame(node) || getCurrentContextFrame() || null;\n const hydrationInstance = createComponentInstance(\n nextComponentInstanceId(),\n type,\n props || {},\n existingHost\n );\n hydrationInstance.isRoot = isRouteRootComponentVNode(node);\n hydrationInstance.portalScope =\n getCurrentInstance()?.portalScope ?? hydrationInstance.portalScope;\n inheritComponentCleanupStrict(hydrationInstance);\n\n setVNodeComponentInstance(node, hydrationInstance);\n\n if (snapshot) {\n hydrationInstance.ownerFrame = snapshot;\n }\n\n const result = withContext(snapshot, () =>\n renderComponentInline(hydrationInstance)\n );\n if (isPromiseLike(result)) {\n throw new Error(\n 'Async components are not supported. Components must return synchronously.'\n );\n }\n\n const scopedResult = markVNodeTreeWithContextFrame(\n result,\n snapshot ?? null\n );\n\n if (\n scopedResult &&\n typeof scopedResult === 'object' &&\n 'type' in (scopedResult as DOMElement) &&\n typeof (scopedResult as DOMElement).type === 'string' &&\n tagNamesEqualIgnoreCase(\n existingHost.tagName,\n (scopedResult as DOMElement).type as string\n )\n ) {\n pruneComponentHostInstances(\n existingHost,\n retainedHostInstances\n ? [hydrationInstance, ...retainedHostInstances]\n : [hydrationInstance]\n );\n withContext(snapshot, () => {\n domHost.updateElementFromVnode(\n existingHost,\n inheritComponentKey(scopedResult as DOMElement, node),\n true,\n forceChildrenUpdate || hydrationInstance.mounted === false\n );\n materializeKey(existingHost, node, props);\n });\n mountInstanceInline(hydrationInstance, existingHost);\n itemInstanceHydrationComplete(existingHost);\n warnUnusedStateReads(hydrationInstance);\n return existingHost;\n }\n\n const resolvedResult = resolveHostNestedComponentResult(\n existingHost,\n hydrationInstance,\n scopedResult,\n snapshot ?? null,\n retainedHostInstances\n );\n if (\n _isDOMElement(resolvedResult) &&\n typeof resolvedResult.type === 'string' &&\n tagNamesEqualIgnoreCase(existingHost.tagName, resolvedResult.type)\n ) {\n withContext(snapshot, () => {\n domHost.updateElementFromVnode(\n existingHost,\n inheritComponentKey(resolvedResult, node),\n true,\n forceChildrenUpdate || hydrationInstance.mounted === false\n );\n materializeKey(existingHost, node, props);\n });\n mountInstanceInline(hydrationInstance, existingHost);\n itemInstanceHydrationComplete(existingHost);\n warnUnusedStateReads(hydrationInstance);\n return existingHost;\n }\n\n const nextDom = materializeComponentResultNode(\n hydrationInstance,\n scopedResult,\n parentNamespace\n );\n\n if (nextDom instanceof Element) {\n materializeKey(nextDom, node, props);\n }\n\n if (nextDom !== existingHost && existingHost.parentNode) {\n existingHost.parentNode.replaceChild(nextDom, existingHost);\n cleanupDetachedComponentHost(existingHost, hydrationInstance);\n }\n\n warnUnusedStateReads(hydrationInstance);\n return nextDom;\n }\n\n const snapshot =\n getVNodeContextFrame(node) ||\n getCurrentContextFrame() ||\n existingInstance.ownerFrame ||\n null;\n captureInlineRenderSnapshot(existingInstance);\n existingInstance.props = props || {};\n existingInstance.isRoot = isRouteRootComponentVNode(node);\n existingInstance.portalScope =\n getCurrentInstance()?.portalScope ?? existingInstance.portalScope;\n inheritComponentCleanupStrict(existingInstance);\n\n if (snapshot) {\n existingInstance.ownerFrame = snapshot;\n }\n\n const result = withContext(snapshot, () =>\n renderComponentInline(existingInstance)\n );\n if (isPromiseLike(result)) {\n throw new Error(\n 'Async components are not supported. Components must return synchronously.'\n );\n }\n const scopedResult = markVNodeTreeWithContextFrame(result, snapshot ?? null);\n\n if (existingHost.__ASKR_WRAPPER_HOST) {\n const wrapperResult = resolveWrapperHostResult(\n existingHost,\n scopedResult,\n snapshot ?? null\n );\n domHost.updateElementChildren(\n existingHost,\n normalizeComponentChildren(wrapperResult) as VNode[]\n );\n warnUnusedStateReads(existingInstance);\n return existingHost;\n }\n\n if (\n scopedResult &&\n typeof scopedResult === 'object' &&\n 'type' in (scopedResult as DOMElement) &&\n typeof (scopedResult as DOMElement).type === 'string' &&\n tagNamesEqualIgnoreCase(\n existingHost.tagName,\n (scopedResult as DOMElement).type as string\n )\n ) {\n pruneComponentHostInstances(\n existingHost,\n retainedHostInstances\n ? [existingInstance, ...retainedHostInstances]\n : [existingInstance]\n );\n withContext(snapshot, () => {\n domHost.updateElementFromVnode(\n existingHost,\n inheritComponentKey(scopedResult as DOMElement, node),\n true,\n forceChildrenUpdate || existingInstance.mounted === false\n );\n materializeKey(existingHost, node, props);\n });\n warnUnusedStateReads(existingInstance);\n return existingHost;\n }\n\n const resolvedResult = resolveHostNestedComponentResult(\n existingHost,\n existingInstance,\n scopedResult,\n snapshot ?? null,\n retainedHostInstances\n );\n if (\n _isDOMElement(resolvedResult) &&\n typeof resolvedResult.type === 'string' &&\n tagNamesEqualIgnoreCase(existingHost.tagName, resolvedResult.type)\n ) {\n withContext(snapshot, () => {\n domHost.updateElementFromVnode(\n existingHost,\n inheritComponentKey(resolvedResult, node),\n true,\n forceChildrenUpdate || existingInstance.mounted === false\n );\n materializeKey(existingHost, node, props);\n });\n warnUnusedStateReads(existingInstance);\n return existingHost;\n }\n\n const nextDom = materializeComponentResultNode(\n existingInstance,\n scopedResult,\n parentNamespace\n );\n\n if (nextDom instanceof Element) {\n materializeKey(nextDom, node, props);\n }\n\n if (nextDom !== existingHost && existingHost.parentNode) {\n existingHost.parentNode.replaceChild(nextDom, existingHost);\n cleanupDetachedComponentHost(existingHost, existingInstance);\n }\n\n warnUnusedStateReads(existingInstance);\n return nextDom;\n}\n\nfunction itemInstanceHydrationComplete(host: InstanceHostElement): void {\n const instance = host.__ASKR_INSTANCE;\n if (instance) {\n const scope = (\n instance as unknown as { scope?: { hydrationPending?: boolean } }\n ).scope;\n if (scope) {\n scope.hydrationPending = false;\n }\n }\n}\n\nexport function createComponentElement(\n node: ElementWithContext,\n type: (props: never) => unknown,\n props: Record<string, unknown>,\n parentNamespace?: string\n): Node {\n const frame = getVNodeContextFrame(node);\n const snapshot = frame || getCurrentContextFrame();\n\n const componentFn = type as unknown as (props: Props) => unknown;\n const isAsync = componentFn.constructor.name === 'AsyncFunction';\n\n if (isAsync) {\n throw new Error(\n 'Async components are not supported. Use resource() for async work.'\n );\n }\n\n let childInstance = getVNodeComponentInstance(node);\n const hadChildInstance = !!childInstance;\n if (!childInstance) {\n childInstance = createComponentInstance(\n nextComponentInstanceId(),\n componentFn as ComponentFunction,\n props || {},\n null\n );\n setVNodeComponentInstance(node, childInstance);\n }\n\n if (hadChildInstance) {\n captureInlineRenderSnapshot(childInstance);\n }\n\n childInstance.portalScope =\n getCurrentInstance()?.portalScope ?? childInstance.portalScope;\n childInstance.parentInstance = getCurrentInstance();\n childInstance.props = props || {};\n childInstance.isRoot = isRouteRootComponentVNode(node);\n inheritComponentCleanupStrict(childInstance);\n\n if (snapshot) {\n childInstance.ownerFrame = snapshot;\n }\n\n const result = withContext(snapshot, () =>\n renderComponentInline(childInstance)\n );\n\n if (isPromiseLike(result)) {\n throw new Error(\n 'Async components are not supported. Components must return synchronously.'\n );\n }\n\n const scopedResult = markVNodeTreeWithContextFrame(result, snapshot ?? null);\n\n const dom = withContext(snapshot, () =>\n materializeComponentResultNode(childInstance, scopedResult, parentNamespace)\n );\n\n warnUnusedStateReads(childInstance);\n\n if (dom instanceof Element) {\n materializeKey(dom, node, props);\n }\n return dom;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiDA,SAAS,+BACP,eACA,QACA,iBACM;CACN,MAAM,MAAM,mBAAmB,CAAC,CAAC,cAAc,QAAQ,eAAe;CAEtE,IAAI,eAAe,SAAS;EAC1B,oBAAoB,eAAe,GAAG;E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A+B,eAAe,cAAc,eAAe,CAC7E;CAEA,qBAAqB,aAAa;CAElC,IAAI,eAAe,SACjB,eAAe,KAAK,MAAM,KAAK;CAEjC,OAAO;AACT"}
1
+ {"version":3,"file":"component-host.js","names":[],"sources":["../../src/renderer/component-host.ts"],"sourcesContent":["import { isPromiseLike } from '../common/promise';\nimport type { Props } from '../common/props';\nimport {\n captureInlineRenderSnapshot,\n cleanupComponent,\n createComponentInstance,\n getCurrentInstance,\n mountInstanceInline,\n renderComponentInline,\n warnUnusedStateReads,\n type ComponentFunction,\n type ComponentInstance,\n} from '../runtime';\nimport {\n getCurrentContextFrame,\n getVNodeContextFrame,\n markVNodeTreeWithContextFrame,\n withContext,\n type ContextFrame,\n} from '../runtime';\nimport { materializeKey } from './attributes';\nimport { normalizeComponentChildren } from './child-shape';\nimport {\n cleanupDetachedComponentHost,\n pruneComponentHostInstances,\n} from './component-host-cleanup';\nimport {\n getRendererDOMHost,\n type ElementWithContext,\n type InstanceHostElement,\n} from './dom-host';\nimport {\n findHostInstanceByType,\n getVNodeComponentInstance,\n inheritComponentCleanupStrict,\n inheritComponentKey,\n isRouteRootComponentVNode,\n nextComponentInstanceId,\n setVNodeComponentInstance,\n} from './component-host-instances';\nimport {\n _isDOMElement,\n type DOMElement,\n type JSXComponent,\n type VNode,\n} from './types';\nimport { tagNamesEqualIgnoreCase } from './utils';\nexport {\n findHostInstanceByType,\n inheritComponentCleanupStrict,\n inheritComponentKey,\n isRouteRootComponentVNode,\n nextComponentInstanceId,\n} from './component-host-instances';\nfunction materializeComponentResultNode(\n childInstance: ComponentInstance,\n result: unknown,\n parentNamespace?: string\n): Node {\n const dom = getRendererDOMHost().createDOMNode(result, parentNamespace);\n\n if (dom instanceof Element) {\n mountInstanceInline(childInstance, dom);\n return dom;\n }\n\n if (!dom) {\n const placeholder = document.createComment('');\n try {\n (\n placeholder as Comment & { __ASKR_INSTANCE?: ComponentInstance }\n ).__ASKR_INSTANCE = childInstance;\n } catch {\n // Ignore placeholder metadata failures.\n }\n childInstance._placeholder = placeholder;\n mountInstanceInline(childInstance, null);\n return placeholder;\n }\n\n const host = document.createElement('div') as InstanceHostElement;\n host.appendChild(dom);\n host.__ASKR_WRAPPER_HOST = true;\n mountInstanceInline(childInstance, host);\n return host;\n}\n\nexport function resolveNestedComponentResult(\n result: unknown,\n snapshot: ContextFrame | null,\n parentInstance: ComponentInstance | null\n): VNode {\n let currentResult = result as VNode;\n let activeSnapshot = snapshot;\n let depth = 0;\n\n while (\n _isDOMElement(currentResult) &&\n typeof currentResult.type === 'function' &&\n depth < 16\n ) {\n const nestedSnapshot =\n getVNodeContextFrame(currentResult) ?? activeSnapshot;\n const nestedInstance = createComponentInstance(\n nextComponentInstanceId(),\n currentResult.type as ComponentFunction,\n ((currentResult as DOMElement).props ?? {}) as Props,\n null\n );\n nestedInstance.isRoot = isRouteRootComponentVNode(currentResult);\n nestedInstance.parentInstance = parentInstance;\n nestedInstance.portalScope =\n parentInstance?.portalScope ?? nestedInstance.portalScope;\n inheritComponentCleanupStrict(nestedInstance);\n\n if (nestedSnapshot) {\n nestedInstance.ownerFrame = nestedSnapshot;\n }\n\n const nextResult = withContext(nestedSnapshot ?? null, () =>\n renderComponentInline(nestedInstance)\n );\n cleanupComponent(nestedInstance);\n\n if (isPromiseLike(nextResult)) {\n throw new Error(\n 'Async components are not supported. Components must return synchronously.'\n );\n }\n\n activeSnapshot = nestedSnapshot ?? null;\n currentResult = nextResult as VNode;\n depth += 1;\n }\n\n return currentResult;\n}\n\nfunction resolveHostNestedComponentResult(\n host: InstanceHostElement,\n retainedInstance: ComponentInstance,\n result: unknown,\n snapshot: ContextFrame | null,\n retainedHostInstances?: Iterable<ComponentInstance>\n): VNode {\n let currentResult = result as VNode;\n let activeSnapshot = snapshot;\n let depth = 0;\n const retainedInstances = new Set<ComponentInstance>([retainedInstance]);\n if (retainedHostInstances) {\n for (const instance of retainedHostInstances) {\n retainedInstances.add(instance);\n }\n }\n const createdInstances: ComponentInstance[] = [];\n\n while (\n _isDOMElement(currentResult) &&\n typeof currentResult.type === 'function' &&\n depth < 16\n ) {\n const nestedSnapshot =\n getVNodeContextFrame(currentResult) ?? activeSnapshot;\n let nestedInstance = findHostInstanceByType(\n host,\n currentResult.type as ComponentFunction\n );\n const hadNestedInstance = !!nestedInstance;\n\n if (!nestedInstance) {\n nestedInstance = createComponentInstance(\n nextComponentInstanceId(),\n currentResult.type as ComponentFunction,\n ((currentResult as DOMElement).props ?? {}) as Props,\n null\n );\n createdInstances.push(nestedInstance);\n }\n\n if (hadNestedInstance) {\n captureInlineRenderSnapshot(nestedInstance);\n }\n\n setVNodeComponentInstance(currentResult, nestedInstance);\n nestedInstance.isRoot = isRouteRootComponentVNode(currentResult);\n nestedInstance.parentInstance = retainedInstance;\n nestedInstance.portalScope =\n retainedInstance.portalScope ?? nestedInstance.portalScope;\n inheritComponentCleanupStrict(nestedInstance);\n nestedInstance.props =\n (((currentResult as DOMElement).props ?? {}) as Props) || {};\n\n if (nestedSnapshot) {\n nestedInstance.ownerFrame = nestedSnapshot;\n }\n\n const nextResult = withContext(nestedSnapshot ?? null, () =>\n renderComponentInline(nestedInstance)\n );\n\n if (isPromiseLike(nextResult)) {\n throw new Error(\n 'Async components are not supported. Components must return synchronously.'\n );\n }\n\n retainedInstances.add(nestedInstance);\n warnUnusedStateReads(nestedInstance);\n activeSnapshot = nestedSnapshot ?? null;\n currentResult = markVNodeTreeWithContextFrame(\n nextResult,\n activeSnapshot\n ) as VNode;\n depth += 1;\n }\n\n const previousInstances = host.__ASKR_INSTANCES ?? [];\n for (const instance of previousInstances) {\n if (!retainedInstances.has(instance)) {\n cleanupComponent(instance);\n }\n }\n\n const nextHostInstances = previousInstances.filter((instance) =>\n retainedInstances.has(instance)\n );\n for (const instance of retainedInstances) {\n if (instance.target === host && !nextHostInstances.includes(instance)) {\n nextHostInstances.push(instance);\n }\n }\n\n host.__ASKR_INSTANCES = nextHostInstances;\n host.__ASKR_INSTANCE = host.__ASKR_INSTANCES[0] ?? retainedInstance;\n\n for (const instance of createdInstances) {\n mountInstanceInline(instance, host);\n }\n\n return currentResult;\n}\n\nfunction resolveWrapperHostResult(\n host: InstanceHostElement,\n result: unknown,\n snapshot: ContextFrame | null\n): unknown {\n let currentResult = result;\n let activeSnapshot = snapshot;\n let depth = 0;\n\n while (\n _isDOMElement(currentResult) &&\n typeof currentResult.type === 'function' &&\n depth < 16\n ) {\n const nestedSnapshot =\n getVNodeContextFrame(currentResult) ?? activeSnapshot;\n const nestedInstance = findHostInstanceByType(\n host,\n currentResult.type as ComponentFunction\n );\n\n if (!nestedInstance) {\n break;\n }\n\n captureInlineRenderSnapshot(nestedInstance);\n\n nestedInstance.props =\n (((currentResult as DOMElement).props ?? {}) as Props) || {};\n nestedInstance.parentInstance = getCurrentInstance();\n nestedInstance.isRoot = isRouteRootComponentVNode(currentResult);\n nestedInstance.portalScope =\n getCurrentInstance()?.portalScope ?? nestedInstance.portalScope;\n inheritComponentCleanupStrict(nestedInstance);\n\n if (nestedSnapshot) {\n nestedInstance.ownerFrame = nestedSnapshot;\n }\n\n const nextResult = withContext(nestedSnapshot ?? null, () =>\n renderComponentInline(nestedInstance)\n );\n\n if (isPromiseLike(nextResult)) {\n throw new Error(\n 'Async components are not supported. Components must return synchronously.'\n );\n }\n\n warnUnusedStateReads(nestedInstance);\n activeSnapshot = nestedSnapshot ?? null;\n currentResult = nextResult;\n depth += 1;\n }\n\n return markVNodeTreeWithContextFrame(currentResult, activeSnapshot);\n}\n\nexport function syncComponentElement(\n currentDom: Node | null,\n node: ElementWithContext,\n type: ComponentFunction,\n props: Record<string, unknown>,\n parentNamespace?: string,\n forceChildrenUpdate = false,\n retainedHostInstances?: Iterable<ComponentInstance>\n): Node | null {\n const existingHost =\n currentDom instanceof Element ? (currentDom as InstanceHostElement) : null;\n const existingInstance = existingHost\n ? findHostInstanceByType(existingHost, type)\n : null;\n if (!existingHost) {\n return null;\n }\n\n const domHost = getRendererDOMHost();\n\n if (!existingInstance || existingInstance.fn !== type) {\n const snapshot =\n getVNodeContextFrame(node) || getCurrentContextFrame() || null;\n const hydrationInstance = createComponentInstance(\n nextComponentInstanceId(),\n type,\n props || {},\n existingHost\n );\n hydrationInstance.isRoot = isRouteRootComponentVNode(node);\n hydrationInstance.portalScope =\n getCurrentInstance()?.portalScope ?? hydrationInstance.portalScope;\n inheritComponentCleanupStrict(hydrationInstance);\n\n setVNodeComponentInstance(node, hydrationInstance);\n\n if (snapshot) {\n hydrationInstance.ownerFrame = snapshot;\n }\n\n const result = withContext(snapshot, () =>\n renderComponentInline(hydrationInstance)\n );\n if (isPromiseLike(result)) {\n throw new Error(\n 'Async components are not supported. Components must return synchronously.'\n );\n }\n\n const scopedResult = markVNodeTreeWithContextFrame(\n result,\n snapshot ?? null\n );\n\n if (\n scopedResult &&\n typeof scopedResult === 'object' &&\n 'type' in (scopedResult as DOMElement) &&\n typeof (scopedResult as DOMElement).type === 'string' &&\n tagNamesEqualIgnoreCase(\n existingHost.tagName,\n (scopedResult as DOMElement).type as string\n )\n ) {\n pruneComponentHostInstances(\n existingHost,\n retainedHostInstances\n ? [hydrationInstance, ...retainedHostInstances]\n : [hydrationInstance]\n );\n withContext(snapshot, () => {\n domHost.updateElementFromVnode(\n existingHost,\n inheritComponentKey(scopedResult as DOMElement, node),\n true,\n forceChildrenUpdate || hydrationInstance.mounted === false\n );\n materializeKey(existingHost, node, props);\n });\n mountInstanceInline(hydrationInstance, existingHost);\n itemInstanceHydrationComplete(existingHost);\n warnUnusedStateReads(hydrationInstance);\n return existingHost;\n }\n\n const resolvedResult = resolveHostNestedComponentResult(\n existingHost,\n hydrationInstance,\n scopedResult,\n snapshot ?? null,\n retainedHostInstances\n );\n if (\n _isDOMElement(resolvedResult) &&\n typeof resolvedResult.type === 'string' &&\n tagNamesEqualIgnoreCase(existingHost.tagName, resolvedResult.type)\n ) {\n withContext(snapshot, () => {\n domHost.updateElementFromVnode(\n existingHost,\n inheritComponentKey(resolvedResult, node),\n true,\n forceChildrenUpdate || hydrationInstance.mounted === false\n );\n materializeKey(existingHost, node, props);\n });\n mountInstanceInline(hydrationInstance, existingHost);\n itemInstanceHydrationComplete(existingHost);\n warnUnusedStateReads(hydrationInstance);\n return existingHost;\n }\n\n const nextDom = materializeComponentResultNode(\n hydrationInstance,\n scopedResult,\n parentNamespace\n );\n\n if (nextDom instanceof Element) {\n materializeKey(nextDom, node, props);\n }\n\n if (nextDom !== existingHost && existingHost.parentNode) {\n existingHost.parentNode.replaceChild(nextDom, existingHost);\n cleanupDetachedComponentHost(existingHost, hydrationInstance);\n }\n\n warnUnusedStateReads(hydrationInstance);\n return nextDom;\n }\n\n const snapshot =\n getVNodeContextFrame(node) ||\n getCurrentContextFrame() ||\n existingInstance.ownerFrame ||\n null;\n captureInlineRenderSnapshot(existingInstance);\n existingInstance.props = props || {};\n existingInstance.isRoot = isRouteRootComponentVNode(node);\n existingInstance.portalScope =\n getCurrentInstance()?.portalScope ?? existingInstance.portalScope;\n inheritComponentCleanupStrict(existingInstance);\n\n if (snapshot) {\n existingInstance.ownerFrame = snapshot;\n }\n\n const result = withContext(snapshot, () =>\n renderComponentInline(existingInstance)\n );\n if (isPromiseLike(result)) {\n throw new Error(\n 'Async components are not supported. Components must return synchronously.'\n );\n }\n const scopedResult = markVNodeTreeWithContextFrame(result, snapshot ?? null);\n\n if (existingHost.__ASKR_WRAPPER_HOST) {\n const wrapperResult = resolveWrapperHostResult(\n existingHost,\n scopedResult,\n snapshot ?? null\n );\n domHost.updateElementChildren(\n existingHost,\n normalizeComponentChildren(wrapperResult) as VNode[]\n );\n warnUnusedStateReads(existingInstance);\n return existingHost;\n }\n\n if (\n scopedResult &&\n typeof scopedResult === 'object' &&\n 'type' in (scopedResult as DOMElement) &&\n typeof (scopedResult as DOMElement).type === 'string' &&\n tagNamesEqualIgnoreCase(\n existingHost.tagName,\n (scopedResult as DOMElement).type as string\n )\n ) {\n pruneComponentHostInstances(\n existingHost,\n retainedHostInstances\n ? [existingInstance, ...retainedHostInstances]\n : [existingInstance]\n );\n withContext(snapshot, () => {\n domHost.updateElementFromVnode(\n existingHost,\n inheritComponentKey(scopedResult as DOMElement, node),\n true,\n forceChildrenUpdate || existingInstance.mounted === false\n );\n materializeKey(existingHost, node, props);\n });\n warnUnusedStateReads(existingInstance);\n return existingHost;\n }\n\n const resolvedResult = resolveHostNestedComponentResult(\n existingHost,\n existingInstance,\n scopedResult,\n snapshot ?? null,\n retainedHostInstances\n );\n if (\n _isDOMElement(resolvedResult) &&\n typeof resolvedResult.type === 'string' &&\n tagNamesEqualIgnoreCase(existingHost.tagName, resolvedResult.type)\n ) {\n withContext(snapshot, () => {\n domHost.updateElementFromVnode(\n existingHost,\n inheritComponentKey(resolvedResult, node),\n true,\n forceChildrenUpdate || existingInstance.mounted === false\n );\n materializeKey(existingHost, node, props);\n });\n warnUnusedStateReads(existingInstance);\n return existingHost;\n }\n\n const nextDom = materializeComponentResultNode(\n existingInstance,\n scopedResult,\n parentNamespace\n );\n\n if (nextDom instanceof Element) {\n materializeKey(nextDom, node, props);\n }\n\n if (nextDom !== existingHost && existingHost.parentNode) {\n existingHost.parentNode.replaceChild(nextDom, existingHost);\n cleanupDetachedComponentHost(existingHost, existingInstance);\n }\n\n warnUnusedStateReads(existingInstance);\n return nextDom;\n}\n\nfunction itemInstanceHydrationComplete(host: InstanceHostElement): void {\n const instance = host.__ASKR_INSTANCE;\n if (instance) {\n const scope = (\n instance as unknown as { scope?: { hydrationPending?: boolean } }\n ).scope;\n if (scope) {\n scope.hydrationPending = false;\n }\n }\n}\n\nexport function createComponentElement(\n node: ElementWithContext,\n type: JSXComponent,\n props: Record<string, unknown>,\n parentNamespace?: string\n): Node {\n const frame = getVNodeContextFrame(node);\n const snapshot = frame || getCurrentContextFrame();\n\n const componentFn = type as unknown as (props: Props) => unknown;\n const isAsync = componentFn.constructor.name === 'AsyncFunction';\n\n if (isAsync) {\n throw new Error(\n 'Async components are not supported. Use resource() for async work.'\n );\n }\n\n let childInstance = getVNodeComponentInstance(node);\n const hadChildInstance = !!childInstance;\n if (!childInstance) {\n childInstance = createComponentInstance(\n nextComponentInstanceId(),\n componentFn as ComponentFunction,\n props || {},\n null\n );\n setVNodeComponentInstance(node, childInstance);\n }\n\n if (hadChildInstance) {\n captureInlineRenderSnapshot(childInstance);\n }\n\n childInstance.portalScope =\n getCurrentInstance()?.portalScope ?? childInstance.portalScope;\n childInstance.parentInstance = getCurrentInstance();\n childInstance.props = props || {};\n childInstance.isRoot = isRouteRootComponentVNode(node);\n inheritComponentCleanupStrict(childInstance);\n\n if (snapshot) {\n childInstance.ownerFrame = snapshot;\n }\n\n const result = withContext(snapshot, () =>\n renderComponentInline(childInstance)\n );\n\n if (isPromiseLike(result)) {\n throw new Error(\n 'Async components are not supported. Components must return synchronously.'\n );\n }\n\n const scopedResult = markVNodeTreeWithContextFrame(result, snapshot ?? null);\n\n const dom = withContext(snapshot, () =>\n materializeComponentResultNode(childInstance, scopedResult, parentNamespace)\n );\n\n warnUnusedStateReads(childInstance);\n\n if (dom instanceof Element) {\n materializeKey(dom, node, props);\n }\n return dom;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAsDA,SAAS,+BACP,eACA,QACA,iBACM;CACN,MAAM,MAAM,mBAAmB,CAAC,CAAC,cAAc,QAAQ,eAAe;CAEtE,IAAI,eAAe,SAAS;EAC1B,oBAAoB,eAAe,GAAG;EACtC,OAAO;CACT;CAEA,IAAI,CAAC,KAAK;EACR,MAAM,cAAc,SAAS,cAAc,EAAE;EAC7C,IAAI;GACF,YAEE,kBAAkB;EACtB,QAAQ,CAER;EACA,cAAc,eAAe;EAC7B,oBAAoB,eAAe,IAAI;EACvC,OAAO;CACT;CAEA,MAAM,OAAO,SAAS,cAAc,KAAK;CACzC,KAAK,YAAY,GAAG;CACpB,KAAK,sBAAsB;CAC3B,oBAAoB,eAAe,IAAI;CACvC,OAAO;AACT;AAEA,SAAgB,6BACd,QACA,UACA,gBACO;CACP,IAAI,gBAAgB;CACpB,IA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AK;CACtB,IAAI,UAAU;EACZ,MAAM,QACJ,SACA;EACF,IAAI,OACF,MAAM,mBAAmB;CAE7B;AACF;AAEA,SAAgB,uBACd,MACA,MACA,OACA,iBACM;CAEN,MAAM,WADQ,qBAAqB,IAClB,KAAS,uBAAuB;CAEjD,MAAM,cAAc;CAGpB,IAFgB,YAAY,YAAY,SAAS,iBAG/C,MAAM,IAAI,MACR,oEACF;CAGF,IAAI,gBAAgB,0BAA0B,IAAI;CAClD,MAAM,mBAAmB,CAAC,CAAC;CAC3B,IAAI,CAAC,eAAe;EAClB,gBAAgB,wBACd,wBAAwB,GACxB,aACA,SAAS,CAAC,GACV,IACF;EACA,0BAA0B,MAAM,aAAa;CAC/C;CAEA,IAAI,kBACF,4BAA4B,aAAa;CAG3C,cAAc,cACZ,mBAAmB,CAAC,EAAE,eAAe,cAAc;CACrD,cAAc,iBAAiB,mBAAmB;CAClD,cAAc,QAAQ,SAAS,CAAC;CAChC,cAAc,SAAS,0BAA0B,IAAI;CACrD,8BAA8B,aAAa;CAE3C,IAAI,UACF,cAAc,aAAa;CAG7B,MAAM,SAAS,YAAY,gBACzB,sBAAsB,aAAa,CACrC;CAEA,IAAI,cAAc,MAAM,GACtB,MAAM,IAAI,MACR,2EACF;CAGF,MAAM,eAAe,8BAA8B,QAAQ,YAAY,IAAI;CAE3E,MAAM,MAAM,YAAY,gBACtB,+BAA+B,eAAe,cAAc,eAAe,CAC7E;CAEA,qBAAqB,aAAa;CAElC,IAAI,eAAe,SACjB,eAAe,KAAK,MAAM,KAAK;CAEjC,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"dom-host.js","names":[],"sources":["../../src/renderer/dom-host.ts"],"sourcesContent":["import type {\n ComponentFunction,\n ComponentInstance,\n} from '../runtime/component-contracts';\nimport type { ContextFrame } from '../runtime/context';\nimport type { DOMElement, VNode } from './types';\n\nexport type ElementWithContext = DOMElement & {\n [key: symbol]: ContextFrame | boolean | undefined;\n __instance?: ComponentInstance;\n};\n\nexport type InstanceHostElement = Element & {\n __ASKR_INSTANCE?: ComponentInstance;\n __ASKR_INSTANCES?: ComponentInstance[];\n __ASKR_WRAPPER_HOST?: boolean;\n};\n\nexport interface RendererDOMHost {\n createDOMNode(node: unknown, parentNamespace?: string): Node | null;\n syncComponentElement(\n currentDom: Node | null,\n node: ElementWithContext,\n type: ComponentFunction,\n props: Record<string, unknown>,\n parentNamespace?: string,\n forceChildrenUpdate?: boolean,\n retainedHostInstances?: Iterable<ComponentInstance>\n ): Node | null;\n updateElementFromVnode(\n el: Element,\n vnode: VNode,\n updateChildren?: boolean,\n forceChildrenUpdate?: boolean\n ): void;\n updateElementChildren(\n el: Element,\n children: VNode | VNode[] | undefined,\n forceUpdate?: boolean\n ): void;\n tryPatchStableForDirtyItem(scope: { dom?: Node; vnode?: VNode }): boolean;\n}\n\nlet rendererDOMHost: RendererDOMHost | null = null;\n\nexport function configureRendererDOMHost(host: RendererDOMHost): void {\n rendererDOMHost = host;\n}\n\nexport function getRendererDOMHost(): RendererDOMHost {\n if (!rendererDOMHost) {\n throw new Error('[askr] Renderer DOM host is not configured.');\n }\n return rendererDOMHost;\n}\n"],"mappings":";AA2CA,IAAI,kBAA0C;AAE9C,SAAgB,yBAAyB,MAA6B;CACpE,kBAAkB;AACpB;AAEA,SAAgB,qBAAsC;CACpD,IAAI,CAAC,iBACH,MAAM,IAAI,MAAM,6CAA6C;CAE/D,OAAO;AACT"}
1
+ {"version":3,"file":"dom-host.js","names":[],"sources":["../../src/renderer/dom-host.ts"],"sourcesContent":["import type { ComponentFunction, ComponentInstance } from '../runtime';\nimport type { ContextFrame } from '../runtime';\nimport type { DOMElement, VNode } from './types';\n\nexport type ElementWithContext = DOMElement & {\n [key: symbol]: ContextFrame | boolean | undefined;\n __instance?: ComponentInstance;\n};\n\nexport type InstanceHostElement = Element & {\n __ASKR_INSTANCE?: ComponentInstance;\n __ASKR_INSTANCES?: ComponentInstance[];\n __ASKR_WRAPPER_HOST?: boolean;\n};\n\nexport interface RendererDOMHost {\n createDOMNode(node: unknown, parentNamespace?: string): Node | null;\n syncComponentElement(\n currentDom: Node | null,\n node: ElementWithContext,\n type: ComponentFunction,\n props: Record<string, unknown>,\n parentNamespace?: string,\n forceChildrenUpdate?: boolean,\n retainedHostInstances?: Iterable<ComponentInstance>\n ): Node | null;\n updateElementFromVnode(\n el: Element,\n vnode: VNode,\n updateChildren?: boolean,\n forceChildrenUpdate?: boolean\n ): void;\n updateElementChildren(\n el: Element,\n children: VNode | VNode[] | undefined,\n forceUpdate?: boolean\n ): void;\n tryPatchStableForDirtyItem(scope: { dom?: Node; vnode?: VNode }): boolean;\n}\n\nlet rendererDOMHost: RendererDOMHost | null = null;\n\nexport function configureRendererDOMHost(host: RendererDOMHost): void {\n rendererDOMHost = host;\n}\n\nexport function getRendererDOMHost(): RendererDOMHost {\n if (!rendererDOMHost) {\n throw new Error('[askr] Renderer DOM host is not configured.');\n }\n return rendererDOMHost;\n}\n"],"mappings":";AAwCA,IAAI,kBAA0C;AAE9C,SAAgB,yBAAyB,MAA6B;CACpE,kBAAkB;AACpB;AAEA,SAAgB,qBAAsC;CACpD,IAAI,CAAC,iBACH,MAAM,IAAI,MAAM,6CAA6C;CAE/D,OAAO;AACT"}
@@ -1,17 +1,18 @@
1
1
  import { __ERROR_BOUNDARY__, __FOR_BOUNDARY__, _isDOMElement } from "../common/vnode.js";
2
2
  import "./types.js";
3
3
  import { getRuntimeEnv } from "../common/env.js";
4
- import { logger } from "../dev/logger.js";
4
+ import { logger } from "../common/logger.js";
5
5
  import { Fragment } from "../common/jsx.js";
6
+ import { isBenchMetricScopeActive, recordBenchCounter } from "../runtime/for-bench.js";
7
+ import "../runtime/index.js";
6
8
  import { removeAllListeners, removeElementReactiveProps, teardownNodeSubtree, updateElementRef } from "./cleanup.js";
7
9
  import "./env.js";
8
10
  import "../jsx-runtime.js";
9
- import { isBenchMetricScopeActive, recordBenchCounter } from "../runtime/for-bench.js";
10
- import "../runtime/for.js";
11
11
  import { applyStaticScalarPropsToElement, hasMatchingStaticProps, materializeKey } from "./attributes.js";
12
12
  import { createElementForNamespace, resolveChildNamespace } from "./namespaces.js";
13
13
  import { configureBoundaryDOMHost, createForBoundary, getControlBoundaryState, getDirectControlBoundaryVNode, registerControlBoundaryCommitOwner } from "./boundaries.js";
14
- import { isBulkTextFastPathEligible, performBulkPositionalKeyedTextUpdate, performBulkTextReplace } from "./children.js";
14
+ import { performBulkPositionalKeyedTextUpdate } from "./children-fastpath.js";
15
+ import { isBulkTextFastPathEligible, performBulkTextReplace } from "./children.js";
15
16
  import { maybeWarnMissingKeys, tryGetStaticCreateFastPathShape } from "./child-shape.js";
16
17
  import { configureRendererDOMHost } from "./dom-host.js";
17
18
  import { createComponentElement, syncComponentElement } from "./component-host.js";
@@ -1 +1 @@
1
- {"version":3,"file":"dom-internal.js","names":[],"sources":["../../src/renderer/dom-internal.ts"],"sourcesContent":["import { logger } from '../dev/logger';\nimport { Fragment } from '../jsx/jsx-runtime';\nimport { isBenchMetricScopeActive, recordBenchCounter } from '../runtime/for';\nimport { __ERROR_BOUNDARY__, __FOR_BOUNDARY__ } from '../common/vnode';\nimport {\n applyStaticScalarPropsToElement,\n hasMatchingStaticProps,\n materializeKey,\n} from './attributes';\nimport {\n configureBoundaryDOMHost,\n createForBoundary,\n getControlBoundaryState,\n getDirectControlBoundaryVNode,\n registerControlBoundaryCommitOwner,\n} from './boundaries';\nimport {\n isBulkTextFastPathEligible,\n performBulkPositionalKeyedTextUpdate,\n performBulkTextReplace,\n} from './children';\nimport {\n maybeWarnMissingKeys,\n tryGetStaticCreateFastPathShape,\n} from './child-shape';\nimport {\n removeAllListeners,\n removeElementReactiveProps,\n teardownNodeSubtree,\n updateElementRef,\n} from './cleanup';\nimport { createComponentElement, syncComponentElement } from './component-host';\nimport { configureRendererDOMHost, type ElementWithContext } from './dom-host';\nimport {\n rendererReactiveChildDOMHost,\n updateElementChildren,\n updateUnkeyedChildren,\n} from './element-children';\nimport {\n createErrorBoundaryElement,\n type ErrorBoundaryVNode,\n} from './error-boundary-dom';\nimport { getRuntimeEnv } from './env';\nimport { createElementForNamespace, resolveChildNamespace } from './namespaces';\nimport {\n applyPropsToElement,\n hasTrackedElementPropBindings,\n syncElementPropBindings,\n} from './prop-bindings';\nimport { syncReactiveScalarChild } from './reactive-children';\nimport { runRetainedElementUpdate } from './retained-element-rollback';\nimport { canReuseStaticSubtree } from './static-reuse';\nimport { tryPatchStableForDirtyItem } from './stable-patch';\nimport { _isDOMElement, type DOMElement, type VNode } from './types';\n\nexport { createForBoundary, commitForBoundaryChildren } from './boundaries';\nexport { markReactivePropsDirtySource } from './prop-bindings';\nexport { setStaticChildSlotsCacheEnabled } from './static-reuse';\nexport {\n isBulkTextFastPathEligible,\n performBulkPositionalKeyedTextUpdate,\n performBulkTextReplace,\n};\nexport {\n syncComponentElement,\n updateElementChildren,\n updateUnkeyedChildren,\n tryPatchStableForDirtyItem,\n};\n\nexport const IS_DOM_AVAILABLE = typeof document !== 'undefined';\n\nfunction getHydrationSkipBoundary(el: Element): Element | null {\n return el.closest('[data-skip-hydrate=\"true\"]');\n}\n\nfunction isHydrationSkipped(el: Element): boolean {\n return getHydrationSkipBoundary(el) !== null;\n}\n\nfunction clearHydrationDeferredSubtree(el: Element): void {\n const boundary = getHydrationSkipBoundary(el);\n if (!boundary) return;\n if (boundary === el) {\n removeAllListeners(el);\n removeElementReactiveProps(el);\n }\n}\n\nexport function createDOMNode(\n node: unknown,\n parentNamespace?: string\n): Node | null {\n if (!IS_DOM_AVAILABLE) {\n if (getRuntimeEnv().NODE_ENV !== 'production') {\n try {\n logger.warn('[Askr] createDOMNode called in non-DOM environment');\n } catch {\n // ignore\n }\n }\n return null;\n }\n\n if (typeof node === 'string') {\n if (isBenchMetricScopeActive('coldCreate')) {\n recordBenchCounter('domNodesCreated');\n }\n return document.createTextNode(node);\n }\n if (typeof node === 'number') {\n if (isBenchMetricScopeActive('coldCreate')) {\n recordBenchCounter('domNodesCreated');\n }\n return document.createTextNode(String(node));\n }\n\n if (!node) {\n return null;\n }\n\n if (Array.isArray(node)) {\n maybeWarnMissingKeys(node);\n const fragment = document.createDocumentFragment();\n for (const child of node) {\n const dom = createDOMNode(child, parentNamespace);\n if (dom) fragment.appendChild(dom);\n }\n return fragment;\n }\n\n if (typeof node === 'object' && node !== null && 'type' in node) {\n const type = (node as DOMElement).type;\n const props = ((node as DOMElement).props || {}) as Record<string, unknown>;\n\n if (typeof type === 'string') {\n return createIntrinsicElement(\n node as DOMElement,\n type,\n props,\n parentNamespace\n );\n }\n\n if (typeof type === 'function') {\n return createComponentElement(\n node as ElementWithContext,\n type as (props: never) => unknown,\n props,\n parentNamespace\n );\n }\n\n if (type === __FOR_BOUNDARY__) {\n return createForBoundary(node as DOMElement, props, parentNamespace);\n }\n\n if (type === __ERROR_BOUNDARY__) {\n return createErrorBoundaryElement(\n node as ErrorBoundaryVNode,\n props,\n parentNamespace\n );\n }\n\n if (\n typeof type === 'symbol' &&\n (type === Fragment || String(type) === 'Symbol(Fragment)')\n ) {\n return createFragmentElement(node as DOMElement, props, parentNamespace);\n }\n }\n\n return null;\n}\n\nfunction createIntrinsicElement(\n node: DOMElement,\n type: string,\n props: Record<string, unknown>,\n parentNamespace?: string\n): Element {\n const children = props.children ?? node.children;\n const elementNamespace = resolveChildNamespace(type, parentNamespace);\n const el = createElementForNamespace(type, parentNamespace);\n\n if (isBenchMetricScopeActive('coldCreate')) {\n recordBenchCounter('domNodesCreated');\n }\n\n materializeKey(el, node, props);\n\n const staticCreateFastPath = tryGetStaticCreateFastPathShape(props, children);\n\n if (staticCreateFastPath) {\n applyStaticScalarPropsToElement(el, props, type);\n if (staticCreateFastPath.textContent !== null) {\n el.textContent = staticCreateFastPath.textContent;\n if (isBenchMetricScopeActive('coldCreate')) {\n recordBenchCounter('domNodesCreated');\n }\n }\n return el;\n }\n\n applyPropsToElement(el, props, type, isHydrationSkipped);\n\n if (children !== null && children !== undefined) {\n const controlBoundaryVNode = getDirectControlBoundaryVNode(children);\n if (controlBoundaryVNode) {\n const controlState = getControlBoundaryState(controlBoundaryVNode);\n if (!controlState) {\n throw new Error(\n '[createIntrinsicElement] Control boundary missing internal state'\n );\n }\n registerControlBoundaryCommitOwner(el, controlState);\n }\n\n if (syncReactiveScalarChild(el, children, rendererReactiveChildDOMHost)) {\n return el;\n }\n\n if (Array.isArray(children)) {\n maybeWarnMissingKeys(children);\n if (children.length > 1) {\n const childFrag = document.createDocumentFragment();\n for (const child of children) {\n const dom = createDOMNode(child, elementNamespace);\n if (dom) childFrag.appendChild(dom);\n }\n el.appendChild(childFrag);\n } else if (children.length === 1) {\n const dom = createDOMNode(children[0], elementNamespace);\n if (dom) el.appendChild(dom);\n }\n } else {\n const dom = createDOMNode(children, elementNamespace);\n if (dom) el.appendChild(dom);\n }\n }\n return el;\n}\n\nfunction createFragmentElement(\n node: DOMElement,\n props: Record<string, unknown>,\n parentNamespace?: string\n): DocumentFragment {\n const fragment = document.createDocumentFragment();\n const children = props.children ?? node.children;\n if (children) {\n if (Array.isArray(children)) {\n maybeWarnMissingKeys(children);\n for (const child of children) {\n const dom = createDOMNode(child, parentNamespace);\n if (dom) fragment.appendChild(dom);\n }\n } else {\n const dom = createDOMNode(children, parentNamespace);\n if (dom) fragment.appendChild(dom);\n }\n }\n return fragment;\n}\n\nexport function updateElementFromVnode(\n el: Element,\n vnode: VNode,\n updateChildren = true,\n forceChildrenUpdate = false\n): void {\n runRetainedElementUpdate(el, teardownNodeSubtree, () => {\n applyElementUpdateFromVnode(el, vnode, updateChildren, forceChildrenUpdate);\n });\n}\n\nfunction applyElementUpdateFromVnode(\n el: Element,\n vnode: VNode,\n updateChildren: boolean,\n forceChildrenUpdate: boolean\n): void {\n if (!_isDOMElement(vnode)) {\n return;\n }\n\n const props = (vnode.props || {}) as Record<string, unknown>;\n const domVNode = vnode as DOMElement;\n\n if (isHydrationSkipped(el)) {\n clearHydrationDeferredSubtree(el);\n return;\n }\n\n materializeKey(el, vnode, props);\n updateElementRef(el, props.ref);\n\n if (!hasTrackedElementPropBindings(el)) {\n if (\n !forceChildrenUpdate &&\n hasMatchingStaticProps(el, props, vnode.type as string)\n ) {\n if (updateChildren) {\n const children =\n (props.children as VNode | VNode[] | undefined) ?? vnode.children;\n if (!forceChildrenUpdate && canReuseStaticSubtree(el, domVNode)) {\n return;\n }\n updateElementChildren(el, children, forceChildrenUpdate);\n }\n return;\n }\n }\n\n const nextChildren = props.children ?? domVNode.children;\n const usesReactiveChildren = syncReactiveScalarChild(\n el,\n nextChildren,\n rendererReactiveChildDOMHost\n );\n syncElementPropBindings(el, domVNode, props, usesReactiveChildren);\n\n if (updateChildren) {\n const children =\n (props.children as VNode | VNode[] | undefined) ?? vnode.children;\n if (usesReactiveChildren) {\n return;\n }\n updateElementChildren(el, children, forceChildrenUpdate);\n }\n}\n\nconfigureRendererDOMHost({\n createDOMNode,\n syncComponentElement,\n updateElementFromVnode,\n updateElementChildren,\n tryPatchStableForDirtyItem,\n});\n\nconfigureBoundaryDOMHost({\n createDOMNode,\n syncComponentElement,\n updateElementFromVnode,\n tryPatchStableForDirtyItem,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAsEA,MAAa,mBAAmB,OAAO,aAAa;AAEpD,SAAS,yBAAyB,IAA6B;CAC7D,OAAO,GAAG,QAAQ,8BAA4B;AAChD;AAEA,SAAS,mBAAmB,IAAsB;CAChD,OAAO,yBAAyB,EAAE,MAAM;AAC1C;AAEA,SAAS,8BAA8B,IAAmB;CACxD,MAAM,WAAW,yBAAyB,EAAE;CAC5C,IAAI,CAAC,UAAU;CACf,IAAI,aAAa,IAAI;EACnB,mBAAmB,EAAE;EACrB,2BAA2B,EAAE;CAC/B;AACF;AAEA,SAAgB,cACd,MACA,iBACa;CACb,IAAI,CAAC,kBAAkB;EACrB,IAAI,cAAc,CAAC,CAAC,aAAa,cAC/B,IAAI;GACF,OAAO,KAAK,oDAAoD;EAClE,QAAQ,CAER;EAEF,OAAO;C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,cAAc,OAAO,eAAe;GAChD,IAAI,KAAK,SAAS,YAAY,GAAG;EACnC;CACF,OAAO;EACL,MAAM,MAAM,cAAc,UAAU,eAAe;EACnD,IAAI,KAAK,SAAS,YAAY,GAAG;CACnC;CAEF,OAAO;AACT;AAEA,SAAgB,uBACd,IACA,OACA,iBAAiB,MACjB,sBAAsB,OAChB;CACN,yBAAyB,IAAI,2BAA2B;EACtD,4BAA4B,IAAI,OAAO,gBAAgB,mBAAmB;CAC5E,CAAC;AACH;AAEA,SAAS,4BACP,IACA,OACA,gBACA,qBACM;CACN,IAAI,CAAC,cAAc,KAAK,GACtB;CAGF,MAAM,QAAS,MAAM,SAAS,CAAC;CAC/B,MAAM,WAAW;CAEjB,IAAI,mBAAmB,EAAE,GAAG;EAC1B,8BAA8B,EAAE;EAChC;CACF;CAEA,eAAe,IAAI,OAAO,KAAK;CAC/B,iBAAiB,IAAI,MAAM,GAAG;CAE9B,IAAI,CAAC,8BAA8B,EAAE,GACnC;MACE,CAAC,uBACD,uBAAuB,IAAI,OAAO,MAAM,IAAc,GACtD;GACA,IAAI,gBAAgB;IAClB,MAAM,WACH,MAAM,YAA4C,MAAM;IAC3D,IAAI,CAAC,uBAAuB,sBAAsB,IAAI,QAAQ,GAC5D;IAEF,sBAAsB,IAAI,UAAU,mBAAmB;GACzD;GACA;EACF;;CAIF,MAAM,uBAAuB,wBAC3B,IAFmB,MAAM,YAAY,SAAS,UAI9C,4BACF;CACA,wBAAwB,IAAI,UAAU,OAAO,oBAAoB;CAEjE,IAAI,gBAAgB;EAClB,MAAM,WACH,MAAM,YAA4C,MAAM;EAC3D,IAAI,sBACF;EAEF,sBAAsB,IAAI,UAAU,mBAAmB;CACzD;AACF;AAEA,yBAAyB;CACvB;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,yBAAyB;CACvB;CACA;CACA;CACA;AACF,CAAC"}
1
+ {"version":3,"file":"dom-internal.js","names":[],"sources":["../../src/renderer/dom-internal.ts"],"sourcesContent":["import { logger } from '../common/logger';\nimport { Fragment } from '../jsx/jsx-runtime';\nimport { isBenchMetricScopeActive, recordBenchCounter } from '../runtime';\nimport { __ERROR_BOUNDARY__, __FOR_BOUNDARY__ } from '../common/vnode';\nimport {\n applyStaticScalarPropsToElement,\n hasMatchingStaticProps,\n materializeKey,\n} from './attributes';\nimport {\n configureBoundaryDOMHost,\n createForBoundary,\n getControlBoundaryState,\n getDirectControlBoundaryVNode,\n registerControlBoundaryCommitOwner,\n} from './boundaries';\nimport {\n isBulkTextFastPathEligible,\n performBulkPositionalKeyedTextUpdate,\n performBulkTextReplace,\n} from './children';\nimport {\n maybeWarnMissingKeys,\n tryGetStaticCreateFastPathShape,\n} from './child-shape';\nimport {\n removeAllListeners,\n removeElementReactiveProps,\n teardownNodeSubtree,\n updateElementRef,\n} from './cleanup';\nimport { createComponentElement, syncComponentElement } from './component-host';\nimport { configureRendererDOMHost, type ElementWithContext } from './dom-host';\nimport {\n rendererReactiveChildDOMHost,\n updateElementChildren,\n updateUnkeyedChildren,\n} from './element-children';\nimport {\n createErrorBoundaryElement,\n type ErrorBoundaryVNode,\n} from './error-boundary-dom';\nimport { getRuntimeEnv } from './env';\nimport { createElementForNamespace, resolveChildNamespace } from './namespaces';\nimport {\n applyPropsToElement,\n hasTrackedElementPropBindings,\n syncElementPropBindings,\n} from './prop-bindings';\nimport { syncReactiveScalarChild } from './reactive-children';\nimport { runRetainedElementUpdate } from './retained-element-rollback';\nimport { canReuseStaticSubtree } from './static-reuse';\nimport { tryPatchStableForDirtyItem } from './stable-patch';\nimport {\n _isDOMElement,\n type DOMElement,\n type JSXComponent,\n type VNode,\n} from './types';\n\nexport { createForBoundary, commitForBoundaryChildren } from './boundaries';\nexport { markReactivePropsDirtySource } from './prop-bindings';\nexport { setStaticChildSlotsCacheEnabled } from './static-reuse';\nexport {\n isBulkTextFastPathEligible,\n performBulkPositionalKeyedTextUpdate,\n performBulkTextReplace,\n};\nexport {\n syncComponentElement,\n updateElementChildren,\n updateUnkeyedChildren,\n tryPatchStableForDirtyItem,\n};\n\nexport const IS_DOM_AVAILABLE = typeof document !== 'undefined';\n\nfunction getHydrationSkipBoundary(el: Element): Element | null {\n return el.closest('[data-skip-hydrate=\"true\"]');\n}\n\nfunction isHydrationSkipped(el: Element): boolean {\n return getHydrationSkipBoundary(el) !== null;\n}\n\nfunction clearHydrationDeferredSubtree(el: Element): void {\n const boundary = getHydrationSkipBoundary(el);\n if (!boundary) return;\n if (boundary === el) {\n removeAllListeners(el);\n removeElementReactiveProps(el);\n }\n}\n\nexport function createDOMNode(\n node: unknown,\n parentNamespace?: string\n): Node | null {\n if (!IS_DOM_AVAILABLE) {\n if (getRuntimeEnv().NODE_ENV !== 'production') {\n try {\n logger.warn('[Askr] createDOMNode called in non-DOM environment');\n } catch {\n // ignore\n }\n }\n return null;\n }\n\n if (typeof node === 'string') {\n if (isBenchMetricScopeActive('coldCreate')) {\n recordBenchCounter('domNodesCreated');\n }\n return document.createTextNode(node);\n }\n if (typeof node === 'number') {\n if (isBenchMetricScopeActive('coldCreate')) {\n recordBenchCounter('domNodesCreated');\n }\n return document.createTextNode(String(node));\n }\n\n if (!node) {\n return null;\n }\n\n if (Array.isArray(node)) {\n maybeWarnMissingKeys(node);\n const fragment = document.createDocumentFragment();\n for (const child of node) {\n const dom = createDOMNode(child, parentNamespace);\n if (dom) fragment.appendChild(dom);\n }\n return fragment;\n }\n\n if (typeof node === 'object' && node !== null && 'type' in node) {\n const type = (node as DOMElement).type;\n const props = ((node as DOMElement).props || {}) as Record<string, unknown>;\n\n if (typeof type === 'string') {\n return createIntrinsicElement(\n node as DOMElement,\n type,\n props,\n parentNamespace\n );\n }\n\n if (typeof type === 'function') {\n return createComponentElement(\n node as ElementWithContext,\n type as JSXComponent,\n props,\n parentNamespace\n );\n }\n\n if (type === __FOR_BOUNDARY__) {\n return createForBoundary(node as DOMElement, props, parentNamespace);\n }\n\n if (type === __ERROR_BOUNDARY__) {\n return createErrorBoundaryElement(\n node as ErrorBoundaryVNode,\n props,\n parentNamespace\n );\n }\n\n if (\n typeof type === 'symbol' &&\n (type === Fragment || String(type) === 'Symbol(Fragment)')\n ) {\n return createFragmentElement(node as DOMElement, props, parentNamespace);\n }\n }\n\n return null;\n}\n\nfunction createIntrinsicElement(\n node: DOMElement,\n type: string,\n props: Record<string, unknown>,\n parentNamespace?: string\n): Element {\n const children = props.children ?? node.children;\n const elementNamespace = resolveChildNamespace(type, parentNamespace);\n const el = createElementForNamespace(type, parentNamespace);\n\n if (isBenchMetricScopeActive('coldCreate')) {\n recordBenchCounter('domNodesCreated');\n }\n\n materializeKey(el, node, props);\n\n const staticCreateFastPath = tryGetStaticCreateFastPathShape(props, children);\n\n if (staticCreateFastPath) {\n applyStaticScalarPropsToElement(el, props, type);\n if (staticCreateFastPath.textContent !== null) {\n el.textContent = staticCreateFastPath.textContent;\n if (isBenchMetricScopeActive('coldCreate')) {\n recordBenchCounter('domNodesCreated');\n }\n }\n return el;\n }\n\n applyPropsToElement(el, props, type, isHydrationSkipped);\n\n if (children !== null && children !== undefined) {\n const controlBoundaryVNode = getDirectControlBoundaryVNode(children);\n if (controlBoundaryVNode) {\n const controlState = getControlBoundaryState(controlBoundaryVNode);\n if (!controlState) {\n throw new Error(\n '[createIntrinsicElement] Control boundary missing internal state'\n );\n }\n registerControlBoundaryCommitOwner(el, controlState);\n }\n\n if (syncReactiveScalarChild(el, children, rendererReactiveChildDOMHost)) {\n return el;\n }\n\n if (Array.isArray(children)) {\n maybeWarnMissingKeys(children);\n if (children.length > 1) {\n const childFrag = document.createDocumentFragment();\n for (const child of children) {\n const dom = createDOMNode(child, elementNamespace);\n if (dom) childFrag.appendChild(dom);\n }\n el.appendChild(childFrag);\n } else if (children.length === 1) {\n const dom = createDOMNode(children[0], elementNamespace);\n if (dom) el.appendChild(dom);\n }\n } else {\n const dom = createDOMNode(children, elementNamespace);\n if (dom) el.appendChild(dom);\n }\n }\n return el;\n}\n\nfunction createFragmentElement(\n node: DOMElement,\n props: Record<string, unknown>,\n parentNamespace?: string\n): DocumentFragment {\n const fragment = document.createDocumentFragment();\n const children = props.children ?? node.children;\n if (children) {\n if (Array.isArray(children)) {\n maybeWarnMissingKeys(children);\n for (const child of children) {\n const dom = createDOMNode(child, parentNamespace);\n if (dom) fragment.appendChild(dom);\n }\n } else {\n const dom = createDOMNode(children, parentNamespace);\n if (dom) fragment.appendChild(dom);\n }\n }\n return fragment;\n}\n\nexport function updateElementFromVnode(\n el: Element,\n vnode: VNode,\n updateChildren = true,\n forceChildrenUpdate = false\n): void {\n runRetainedElementUpdate(el, teardownNodeSubtree, () => {\n applyElementUpdateFromVnode(el, vnode, updateChildren, forceChildrenUpdate);\n });\n}\n\nfunction applyElementUpdateFromVnode(\n el: Element,\n vnode: VNode,\n updateChildren: boolean,\n forceChildrenUpdate: boolean\n): void {\n if (!_isDOMElement(vnode)) {\n return;\n }\n\n const props = (vnode.props || {}) as Record<string, unknown>;\n const domVNode = vnode as DOMElement;\n\n if (isHydrationSkipped(el)) {\n clearHydrationDeferredSubtree(el);\n return;\n }\n\n materializeKey(el, vnode, props);\n updateElementRef(el, props.ref);\n\n if (!hasTrackedElementPropBindings(el)) {\n if (\n !forceChildrenUpdate &&\n hasMatchingStaticProps(el, props, vnode.type as string)\n ) {\n if (updateChildren) {\n const children =\n (props.children as VNode | VNode[] | undefined) ?? vnode.children;\n if (!forceChildrenUpdate && canReuseStaticSubtree(el, domVNode)) {\n return;\n }\n updateElementChildren(el, children, forceChildrenUpdate);\n }\n return;\n }\n }\n\n const nextChildren = props.children ?? domVNode.children;\n const usesReactiveChildren = syncReactiveScalarChild(\n el,\n nextChildren,\n rendererReactiveChildDOMHost\n );\n syncElementPropBindings(el, domVNode, props, usesReactiveChildren);\n\n if (updateChildren) {\n const children =\n (props.children as VNode | VNode[] | undefined) ?? vnode.children;\n if (usesReactiveChildren) {\n return;\n }\n updateElementChildren(el, children, forceChildrenUpdate);\n }\n}\n\nconfigureRendererDOMHost({\n createDOMNode,\n syncComponentElement,\n updateElementFromVnode,\n updateElementChildren,\n tryPatchStableForDirtyItem,\n});\n\nconfigureBoundaryDOMHost({\n createDOMNode,\n syncComponentElement,\n updateElementFromVnode,\n tryPatchStableForDirtyItem,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,MAAa,mBAAmB,OAAO,aAAa;AAEpD,SAAS,yBAAyB,IAA6B;CAC7D,OAAO,GAAG,QAAQ,8BAA4B;AAChD;AAEA,SAAS,mBAAmB,IAAsB;CAChD,OAAO,yBAAyB,EAAE,MAAM;AAC1C;AAEA,SAAS,8BAA8B,IAAmB;CACxD,MAAM,WAAW,yBAAyB,EAAE;CAC5C,IAAI,CAAC,UAAU;CACf,IAAI,aAAa,IAAI;EACnB,mBAAmB,EAAE;EACrB,2BAA2B,EAAE;CAC/B;AACF;AAEA,SAAgB,cACd,MACA,iBACa;CACb,IAAI,CAAC,kBAAkB;EACrB,IAAI,cAAc,CAAC,CAAC,aAAa,cAC/B,IAAI;GACF,OAAO,KAAK,oDAAoD;EAClE,QAAQ,CAER;EAEF,OAAO;CACT;CAEA,IAAI,OAAO,SAAS,UAAU;EAC5B,IAAI,yBAAyB,YAAY,GACvC,mBAAmB,iBAAiB;EAEtC,OAAO,SAAS,eAAe,IAAI;CACrC;CACA,IAAI,OAAO,SAAS,UAAU;EAC5B,IAAI,yBAAyB,YAAY,GACvC,mBAAmB,iBAAiB;EAEtC,OAAO,SAAS,eAAe,OAAO,IAAI,CAAC;CAC7C;CAEA,IAAI,CAAC,MACH,OAAO;CAGT,IAAI,MAAM,QAAQ,IAAI,GAAG;EACvB,qBAAqB,IAAI;EACzB,MAAM,WAAW,SAAS,uBAAuB;EACjD,KAAK,MAAM,SAAS,MAAM;GACxB,MAAM,MAAM,cAAc,OAAO,eAAe;GAChD,IAAI,KAAK,SAAS,YAAY,GAAG;EACnC;EACA,OAAO;CACT;CAEA,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,UAAU,MAAM;EAC/D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AAI,MAAM,GAAG;CAE9B,IAAI,CAAC,8BAA8B,EAAE,GACnC;MACE,CAAC,uBACD,uBAAuB,IAAI,OAAO,MAAM,IAAc,GACtD;GACA,IAAI,gBAAgB;IAClB,MAAM,WACH,MAAM,YAA4C,MAAM;IAC3D,IAAI,CAAC,uBAAuB,sBAAsB,IAAI,QAAQ,GAC5D;IAEF,sBAAsB,IAAI,UAAU,mBAAmB;GACzD;GACA;EACF;;CAIF,MAAM,uBAAuB,wBAC3B,IAFmB,MAAM,YAAY,SAAS,UAI9C,4BACF;CACA,wBAAwB,IAAI,UAAU,OAAO,oBAAoB;CAEjE,IAAI,gBAAgB;EAClB,MAAM,WACH,MAAM,YAA4C,MAAM;EAC3D,IAAI,sBACF;EAEF,sBAAsB,IAAI,UAAU,mBAAmB;CACzD;AACF;AAEA,yBAAyB;CACvB;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,yBAAyB;CACvB;CACA;CACA;CACA;AACF,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import "./boundaries.js";
2
- import { isBulkTextFastPathEligible, performBulkPositionalKeyedTextUpdate, performBulkTextReplace } from "./children.js";
2
+ import { performBulkPositionalKeyedTextUpdate } from "./children-fastpath.js";
3
+ import { isBulkTextFastPathEligible, performBulkTextReplace } from "./children.js";
3
4
  import { syncComponentElement } from "./component-host.js";
4
5
  import { setStaticChildSlotsCacheEnabled } from "./static-reuse.js";
5
6
  import { updateElementChildren, updateUnkeyedChildren } from "./element-children.js";
@@ -1 +1 @@
1
- {"version":3,"file":"element-children.js","names":[],"sources":["../../src/renderer/element-children.ts"],"sourcesContent":["import type { ComponentFunction } from '../runtime/component-contracts';\nimport { clearControlBoundaryCommitOwner } from './boundaries';\nimport {\n commitForBoundaryChildren,\n evaluateControlBoundaryState,\n getControlBoundaryState,\n getDirectControlBoundaryVNode,\n registerControlBoundaryCommitOwner,\n trySyncControlBoundaryChild,\n} from './boundaries';\nimport { isBulkTextFastPathEligible, performBulkTextReplace } from './children';\nimport { isFragmentVNode, normalizeComponentChildren } from './child-shape';\nimport { teardownNodeSubtree } from './cleanup';\nimport { getRendererDOMHost, type ElementWithContext } from './dom-host';\nimport { keyedElements } from './keyed';\nimport { getParentNamespace } from './namespaces';\nimport {\n trySyncScalarChildSequenceInPlace,\n type ReactiveChildDOMHost,\n} from './reactive-children';\nimport { reconcileKeyedChildren } from './reconcile';\nimport { tagsEqualIgnoreCase } from './static-reuse';\nimport { _isDOMElement, type DOMElement, type VNode } from './types';\nimport { extractKey } from './utils';\n\nexport const rendererReactiveChildDOMHost: ReactiveChildDOMHost = {\n createDOMNode: (node, parentNamespace) =>\n getRendererDOMHost().createDOMNode(node, parentNamespace),\n updateElementChildren: (el, children, forceUpdate) =>\n updateElementChildren(el, children, forceUpdate),\n};\n\nexport function updateElementChildren(\n el: Element,\n children: VNode | VNode[] | undefined,\n forceUpdate = false\n): void {\n const directControlBoundary = getDirectControlBoundaryVNode(children);\n if (directControlBoundary) {\n const controlState = getControlBoundaryState(directControlBoundary);\n if (!controlState) {\n throw new Error(\n '[updateElementChildren] Control boundary missing internal state'\n );\n }\n\n registerControlBoundaryCommitOwner(el, controlState);\n const childrenVNodes = evaluateControlBoundaryState(controlState);\n commitForBoundaryChildren(el, controlState, childrenVNodes as VNode[]);\n return;\n }\n\n clearControlBoundaryCommitOwner(el);\n\n if (children === null || children === undefined) {\n for (let n = el.firstChild; n; ) {\n const next = n.nextSibling;\n teardownNodeSubtree(n);\n n = next;\n }\n el.textContent = '';\n return;\n }\n\n if (!Array.isArray(children) && isFragmentVNode(children)) {\n updateUnkeyedChildren(\n el,\n normalizeComponentChildren(children),\n forceUpdate\n );\n return;\n }\n\n if (\n !Array.isArray(children) &&\n (typeof children === 'string' || typeof children === 'number')\n ) {\n if (el.childNodes.length === 1 && el.firstChild?.nodeType === 3) {\n const s = String(children);\n const t = el.firstChild as Text;\n if (t.data !== s) t.data = s;\n } else {\n for (let n = el.firstChild; n; ) {\n const next = n.nextSibling;\n teardownNodeSubtree(n);\n n = next;\n }\n el.textContent = String(children);\n }\n return;\n }\n\n if (Array.isArray(children)) {\n const normalizedChildren = normalizeComponentChildren(children) as VNode[];\n\n if (\n trySyncScalarChildSequenceInPlace(\n el,\n normalizedChildren,\n rendererReactiveChildDOMHost\n )\n ) {\n keyedElements.delete(el);\n return;\n }\n\n if (hasKeyedVNodeChildren(normalizedChildren)) {\n const oldKeyMap = getOrBuildDomKeyMap(el);\n const newKeyMap = reconcileKeyedChildren(\n el,\n normalizedChildren,\n oldKeyMap\n );\n keyedElements.set(el, newKeyMap);\n return;\n }\n if (isBulkTextFastPathEligible(el, normalizedChildren)) {\n performBulkTextReplace(el, normalizedChildren);\n keyedElements.delete(el);\n return;\n }\n updateUnkeyedChildren(el, normalizedChildren, forceUpdate);\n return;\n }\n\n if (_isDOMElement(children)) {\n updateUnkeyedChildren(el, [children], forceUpdate);\n return;\n }\n\n for (let n = el.firstChild; n; ) {\n const next = n.nextSibling;\n teardownNodeSubtree(n);\n n = next;\n }\n el.textContent = '';\n const dom = getRendererDOMHost().createDOMNode(children);\n if (dom) el.appendChild(dom);\n}\n\nfunction hasKeyedVNodeChildren(children: VNode[]): boolean {\n for (let i = 0; i < children.length; i++) {\n if (extractKey(children[i]) !== undefined) return true;\n }\n return false;\n}\n\nfunction isEmptyChild(child: unknown): boolean {\n return child === null || child === undefined || child === false;\n}\n\nfunction getOrBuildDomKeyMap(\n parent: Element\n): Map<string | number, Element> | undefined {\n let keyMap = keyedElements.get(parent);\n if (!keyMap) {\n keyMap = new Map<string | number, Element>();\n for (\n let child = parent.firstElementChild;\n child;\n child = child.nextElementSibling\n ) {\n const key = child.getAttribute('data-key');\n if (key !== null) {\n keyMap.set(key, child);\n const numericKey = Number(key);\n if (!Number.isNaN(numericKey)) keyMap.set(numericKey, child);\n }\n }\n if (keyMap.size > 0) keyedElements.set(parent, keyMap);\n }\n return keyMap.size > 0 ? keyMap : undefined;\n}\n\nexport function updateUnkeyedChildren(\n parent: Element,\n newChildren: unknown[],\n forceUpdate = false\n): void {\n const parentNamespace = getParentNamespace(parent);\n const domHost = getRendererDOMHost();\n\n const trySyncComponentChild = (\n currentDom: Element,\n next: DOMElement\n ): Node | null => {\n if (typeof next.type !== 'function') {\n return null;\n }\n\n return domHost.syncComponentElement(\n currentDom,\n next as ElementWithContext,\n next.type as ComponentFunction,\n (((next as DOMElement).props ?? {}) as Record<string, unknown>) || {},\n parentNamespace,\n forceUpdate\n );\n };\n\n const hasText = newChildren.some(\n (c) => typeof c === 'string' || typeof c === 'number'\n );\n const hasElements = newChildren.some((c) => _isDOMElement(c));\n const hasEmptyChildren = newChildren.some(isEmptyChild);\n const hasComponentChildren = newChildren.some(\n (c) => _isDOMElement(c) && typeof (c as DOMElement).type === 'function'\n );\n const hasNonElementDomChildren =\n parent.childNodes.length !== parent.children.length;\n\n if (\n !hasEmptyChildren &&\n !hasText &&\n !hasComponentChildren &&\n !hasNonElementDomChildren &&\n hasElements &&\n parent.children.length === newChildren.length\n ) {\n const c = parent.children;\n for (let i = 0; i < newChildren.length; i++) {\n const next = newChildren[i];\n const current = c[i];\n if (!current || next === undefined) continue;\n if (_isDOMElement(next) && typeof next.type === 'string') {\n if (tagsEqualIgnoreCase(current.tagName, next.type)) {\n domHost.updateElementFromVnode(current, next, true, forceUpdate);\n } else {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) {\n teardownNodeSubtree(current);\n parent.replaceChild(dom, current);\n }\n }\n } else if (_isDOMElement(next)) {\n if (trySyncControlBoundaryChild(parent, current, next)) {\n continue;\n }\n\n const synced = trySyncComponentChild(current, next);\n if (synced && synced !== current) {\n teardownNodeSubtree(current);\n } else if (!synced) {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) {\n teardownNodeSubtree(current);\n parent.replaceChild(dom, current);\n }\n }\n } else {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) {\n teardownNodeSubtree(current);\n parent.replaceChild(dom, current);\n }\n }\n }\n return;\n }\n\n const existing = Array.from(parent.children);\n\n if (\n hasText ||\n hasComponentChildren ||\n hasEmptyChildren ||\n hasNonElementDomChildren\n ) {\n const allNodes = Array.from(parent.childNodes);\n const max = Math.max(allNodes.length, newChildren.length);\n\n for (let i = 0; i < max; i++) {\n const currentNode = allNodes[i];\n const next = newChildren[i];\n const nextIsEmpty = isEmptyChild(next);\n\n if (nextIsEmpty && currentNode) {\n teardownNodeSubtree(currentNode);\n currentNode.remove();\n continue;\n }\n\n if (!currentNode && !nextIsEmpty) {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) parent.appendChild(dom);\n continue;\n }\n\n if (!currentNode || nextIsEmpty) continue;\n\n if (typeof next === 'string' || typeof next === 'number') {\n if (currentNode.nodeType === 3) {\n (currentNode as Text).data = String(next);\n } else {\n const textNode = document.createTextNode(String(next));\n parent.replaceChild(textNode, currentNode);\n }\n } else if (_isDOMElement(next)) {\n if (currentNode.nodeType === 1) {\n const currentEl = currentNode as Element;\n if (typeof next.type === 'string') {\n if (tagsEqualIgnoreCase(currentEl.tagName, next.type)) {\n domHost.updateElementFromVnode(\n currentEl,\n next,\n true,\n forceUpdate\n );\n } else {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) {\n teardownNodeSubtree(currentEl);\n parent.replaceChild(dom, currentNode);\n }\n }\n } else {\n if (trySyncControlBoundaryChild(parent, currentNode, next)) {\n continue;\n }\n\n const synced = trySyncComponentChild(currentEl, next);\n if (synced && synced !== currentNode) {\n teardownNodeSubtree(currentEl);\n } else if (!synced) {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) {\n teardownNodeSubtree(currentEl);\n parent.replaceChild(dom, currentNode);\n }\n }\n }\n } else {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) parent.replaceChild(dom, currentNode);\n }\n }\n }\n return;\n }\n\n if (\n newChildren.length === 1 &&\n existing.length === 0 &&\n parent.childNodes.length === 1\n ) {\n const firstNewChild = newChildren[0];\n const firstExisting = parent.firstChild;\n if (\n (typeof firstNewChild === 'string' ||\n typeof firstNewChild === 'number') &&\n firstExisting?.nodeType === 3\n ) {\n (firstExisting as Text).data = String(firstNewChild);\n return;\n }\n }\n\n if (existing.length === 0 && parent.childNodes.length > 0) {\n for (let n = parent.firstChild; n; ) {\n const next = n.nextSibling;\n teardownNodeSubtree(n);\n n = next;\n }\n parent.textContent = '';\n }\n const max = Math.max(existing.length, newChildren.length);\n\n for (let i = 0; i < max; i++) {\n const current = existing[i];\n const next = newChildren[i];\n const nextIsEmpty = isEmptyChild(next);\n\n if (nextIsEmpty && current) {\n teardownNodeSubtree(current);\n current.remove();\n continue;\n }\n\n if (!current && !nextIsEmpty) {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) parent.appendChild(dom);\n continue;\n }\n\n if (!current || nextIsEmpty) continue;\n\n if (typeof next === 'string' || typeof next === 'number') {\n const textNode = document.createTextNode(String(next));\n teardownNodeSubtree(current);\n parent.replaceChild(textNode, current);\n } else if (_isDOMElement(next)) {\n if (typeof next.type === 'string') {\n if (tagsEqualIgnoreCase(current.tagName, next.type)) {\n domHost.updateElementFromVnode(current, next, true, forceUpdate);\n } else {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) {\n teardownNodeSubtree(current);\n parent.replaceChild(dom, current);\n }\n }\n } else {\n const synced = trySyncComponentChild(current, next);\n if (synced && synced !== current) {\n teardownNodeSubtree(current);\n } else if (!synced) {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) {\n teardownNodeSubtree(current);\n parent.replaceChild(dom, current);\n }\n }\n }\n } else {\n const dom = domHost.createDOMNode(next);\n if (dom) {\n teardownNodeSubtree(current);\n parent.replaceChild(dom, current);\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAyBA,MAAa,+BAAqD;CAChE,gBAAgB,MAAM,oBACpB,mBAAmB,CAAC,CAAC,cAAc,MAAM,eAAe;CAC1D,wBAAwB,IAAI,UAAU,gBACpC,sBAAsB,IAAI,UAAU,WAA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M,eAAe;GACvD,IAAI,KAAK,OAAO,YAAY,GAAG;GAC/B;EACF;EAEA,IAAI,CAAC,WAAW,aAAa;EAE7B,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU;GACxD,MAAM,WAAW,SAAS,eAAe,OAAO,IAAI,CAAC;GACrD,oBAAoB,OAAO;GAC3B,OAAO,aAAa,UAAU,OAAO;EACvC,OAAO,IAAI,cAAc,IAAI,GAC3B,IAAI,OAAO,KAAK,SAAS,UACvB,IAAI,oBAAoB,QAAQ,SAAS,KAAK,IAAI,GAChD,QAAQ,uBAAuB,SAAS,MAAM,MAAM,WAAW;OAC1D;GACL,MAAM,MAAM,QAAQ,cAAc,MAAM,eAAe;GACvD,IAAI,KAAK;IACP,oBAAoB,OAAO;IAC3B,OAAO,aAAa,KAAK,OAAO;GAClC;EACF;OACK;GACL,MAAM,SAAS,sBAAsB,SAAS,IAAI;GAClD,IAAI,UAAU,WAAW,SACvB,oBAAoB,OAAO;QACtB,IAAI,CAAC,QAAQ;IAClB,MAAM,MAAM,QAAQ,cAAc,MAAM,eAAe;IACvD,IAAI,KAAK;KACP,oBAAoB,OAAO;KAC3B,OAAO,aAAa,KAAK,OAAO;IAClC;GACF;EACF;OACK;GACL,MAAM,MAAM,QAAQ,cAAc,IAAI;GACtC,IAAI,KAAK;IACP,oBAAoB,OAAO;IAC3B,OAAO,aAAa,KAAK,OAAO;GAClC;EACF;CACF;AACF"}
1
+ {"version":3,"file":"element-children.js","names":[],"sources":["../../src/renderer/element-children.ts"],"sourcesContent":["import type { ComponentFunction } from '../runtime';\nimport { clearControlBoundaryCommitOwner } from './boundaries';\nimport {\n commitForBoundaryChildren,\n evaluateControlBoundaryState,\n getControlBoundaryState,\n getDirectControlBoundaryVNode,\n registerControlBoundaryCommitOwner,\n trySyncControlBoundaryChild,\n} from './boundaries';\nimport { isBulkTextFastPathEligible, performBulkTextReplace } from './children';\nimport { isFragmentVNode, normalizeComponentChildren } from './child-shape';\nimport { teardownNodeSubtree } from './cleanup';\nimport { getRendererDOMHost, type ElementWithContext } from './dom-host';\nimport { keyedElements } from './keyed';\nimport { getParentNamespace } from './namespaces';\nimport {\n trySyncScalarChildSequenceInPlace,\n type ReactiveChildDOMHost,\n} from './reactive-children';\nimport { reconcileKeyedChildren } from './reconcile';\nimport { tagsEqualIgnoreCase } from './static-reuse';\nimport { _isDOMElement, type DOMElement, type VNode } from './types';\nimport { extractKey } from './utils';\n\nexport const rendererReactiveChildDOMHost: ReactiveChildDOMHost = {\n createDOMNode: (node, parentNamespace) =>\n getRendererDOMHost().createDOMNode(node, parentNamespace),\n updateElementChildren: (el, children, forceUpdate) =>\n updateElementChildren(el, children, forceUpdate),\n};\n\nexport function updateElementChildren(\n el: Element,\n children: VNode | VNode[] | undefined,\n forceUpdate = false\n): void {\n const directControlBoundary = getDirectControlBoundaryVNode(children);\n if (directControlBoundary) {\n const controlState = getControlBoundaryState(directControlBoundary);\n if (!controlState) {\n throw new Error(\n '[updateElementChildren] Control boundary missing internal state'\n );\n }\n\n registerControlBoundaryCommitOwner(el, controlState);\n const childrenVNodes = evaluateControlBoundaryState(controlState);\n commitForBoundaryChildren(el, controlState, childrenVNodes as VNode[]);\n return;\n }\n\n clearControlBoundaryCommitOwner(el);\n\n if (children === null || children === undefined) {\n for (let n = el.firstChild; n; ) {\n const next = n.nextSibling;\n teardownNodeSubtree(n);\n n = next;\n }\n el.textContent = '';\n return;\n }\n\n if (!Array.isArray(children) && isFragmentVNode(children)) {\n updateUnkeyedChildren(\n el,\n normalizeComponentChildren(children),\n forceUpdate\n );\n return;\n }\n\n if (\n !Array.isArray(children) &&\n (typeof children === 'string' || typeof children === 'number')\n ) {\n if (el.childNodes.length === 1 && el.firstChild?.nodeType === 3) {\n const s = String(children);\n const t = el.firstChild as Text;\n if (t.data !== s) t.data = s;\n } else {\n for (let n = el.firstChild; n; ) {\n const next = n.nextSibling;\n teardownNodeSubtree(n);\n n = next;\n }\n el.textContent = String(children);\n }\n return;\n }\n\n if (Array.isArray(children)) {\n const normalizedChildren = normalizeComponentChildren(children) as VNode[];\n\n if (\n trySyncScalarChildSequenceInPlace(\n el,\n normalizedChildren,\n rendererReactiveChildDOMHost\n )\n ) {\n keyedElements.delete(el);\n return;\n }\n\n if (hasKeyedVNodeChildren(normalizedChildren)) {\n const oldKeyMap = getOrBuildDomKeyMap(el);\n const newKeyMap = reconcileKeyedChildren(\n el,\n normalizedChildren,\n oldKeyMap\n );\n keyedElements.set(el, newKeyMap);\n return;\n }\n if (isBulkTextFastPathEligible(el, normalizedChildren)) {\n performBulkTextReplace(el, normalizedChildren);\n keyedElements.delete(el);\n return;\n }\n updateUnkeyedChildren(el, normalizedChildren, forceUpdate);\n return;\n }\n\n if (_isDOMElement(children)) {\n updateUnkeyedChildren(el, [children], forceUpdate);\n return;\n }\n\n for (let n = el.firstChild; n; ) {\n const next = n.nextSibling;\n teardownNodeSubtree(n);\n n = next;\n }\n el.textContent = '';\n const dom = getRendererDOMHost().createDOMNode(children);\n if (dom) el.appendChild(dom);\n}\n\nfunction hasKeyedVNodeChildren(children: VNode[]): boolean {\n for (let i = 0; i < children.length; i++) {\n if (extractKey(children[i]) !== undefined) return true;\n }\n return false;\n}\n\nfunction isEmptyChild(child: unknown): boolean {\n return child === null || child === undefined || child === false;\n}\n\nfunction getOrBuildDomKeyMap(\n parent: Element\n): Map<string | number, Element> | undefined {\n let keyMap = keyedElements.get(parent);\n if (!keyMap) {\n keyMap = new Map<string | number, Element>();\n for (\n let child = parent.firstElementChild;\n child;\n child = child.nextElementSibling\n ) {\n const key = child.getAttribute('data-key');\n if (key !== null) {\n keyMap.set(key, child);\n const numericKey = Number(key);\n if (!Number.isNaN(numericKey)) keyMap.set(numericKey, child);\n }\n }\n if (keyMap.size > 0) keyedElements.set(parent, keyMap);\n }\n return keyMap.size > 0 ? keyMap : undefined;\n}\n\nexport function updateUnkeyedChildren(\n parent: Element,\n newChildren: unknown[],\n forceUpdate = false\n): void {\n const parentNamespace = getParentNamespace(parent);\n const domHost = getRendererDOMHost();\n\n const trySyncComponentChild = (\n currentDom: Element,\n next: DOMElement\n ): Node | null => {\n if (typeof next.type !== 'function') {\n return null;\n }\n\n return domHost.syncComponentElement(\n currentDom,\n next as ElementWithContext,\n next.type as ComponentFunction,\n (((next as DOMElement).props ?? {}) as Record<string, unknown>) || {},\n parentNamespace,\n forceUpdate\n );\n };\n\n const hasText = newChildren.some(\n (c) => typeof c === 'string' || typeof c === 'number'\n );\n const hasElements = newChildren.some((c) => _isDOMElement(c));\n const hasEmptyChildren = newChildren.some(isEmptyChild);\n const hasComponentChildren = newChildren.some(\n (c) => _isDOMElement(c) && typeof (c as DOMElement).type === 'function'\n );\n const hasNonElementDomChildren =\n parent.childNodes.length !== parent.children.length;\n\n if (\n !hasEmptyChildren &&\n !hasText &&\n !hasComponentChildren &&\n !hasNonElementDomChildren &&\n hasElements &&\n parent.children.length === newChildren.length\n ) {\n const c = parent.children;\n for (let i = 0; i < newChildren.length; i++) {\n const next = newChildren[i];\n const current = c[i];\n if (!current || next === undefined) continue;\n if (_isDOMElement(next) && typeof next.type === 'string') {\n if (tagsEqualIgnoreCase(current.tagName, next.type)) {\n domHost.updateElementFromVnode(current, next, true, forceUpdate);\n } else {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) {\n teardownNodeSubtree(current);\n parent.replaceChild(dom, current);\n }\n }\n } else if (_isDOMElement(next)) {\n if (trySyncControlBoundaryChild(parent, current, next)) {\n continue;\n }\n\n const synced = trySyncComponentChild(current, next);\n if (synced && synced !== current) {\n teardownNodeSubtree(current);\n } else if (!synced) {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) {\n teardownNodeSubtree(current);\n parent.replaceChild(dom, current);\n }\n }\n } else {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) {\n teardownNodeSubtree(current);\n parent.replaceChild(dom, current);\n }\n }\n }\n return;\n }\n\n const existing = Array.from(parent.children);\n\n if (\n hasText ||\n hasComponentChildren ||\n hasEmptyChildren ||\n hasNonElementDomChildren\n ) {\n const allNodes = Array.from(parent.childNodes);\n const max = Math.max(allNodes.length, newChildren.length);\n\n for (let i = 0; i < max; i++) {\n const currentNode = allNodes[i];\n const next = newChildren[i];\n const nextIsEmpty = isEmptyChild(next);\n\n if (nextIsEmpty && currentNode) {\n teardownNodeSubtree(currentNode);\n currentNode.remove();\n continue;\n }\n\n if (!currentNode && !nextIsEmpty) {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) parent.appendChild(dom);\n continue;\n }\n\n if (!currentNode || nextIsEmpty) continue;\n\n if (typeof next === 'string' || typeof next === 'number') {\n if (currentNode.nodeType === 3) {\n (currentNode as Text).data = String(next);\n } else {\n const textNode = document.createTextNode(String(next));\n parent.replaceChild(textNode, currentNode);\n }\n } else if (_isDOMElement(next)) {\n if (currentNode.nodeType === 1) {\n const currentEl = currentNode as Element;\n if (typeof next.type === 'string') {\n if (tagsEqualIgnoreCase(currentEl.tagName, next.type)) {\n domHost.updateElementFromVnode(\n currentEl,\n next,\n true,\n forceUpdate\n );\n } else {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) {\n teardownNodeSubtree(currentEl);\n parent.replaceChild(dom, currentNode);\n }\n }\n } else {\n if (trySyncControlBoundaryChild(parent, currentNode, next)) {\n continue;\n }\n\n const synced = trySyncComponentChild(currentEl, next);\n if (synced && synced !== currentNode) {\n teardownNodeSubtree(currentEl);\n } else if (!synced) {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) {\n teardownNodeSubtree(currentEl);\n parent.replaceChild(dom, currentNode);\n }\n }\n }\n } else {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) parent.replaceChild(dom, currentNode);\n }\n }\n }\n return;\n }\n\n if (\n newChildren.length === 1 &&\n existing.length === 0 &&\n parent.childNodes.length === 1\n ) {\n const firstNewChild = newChildren[0];\n const firstExisting = parent.firstChild;\n if (\n (typeof firstNewChild === 'string' ||\n typeof firstNewChild === 'number') &&\n firstExisting?.nodeType === 3\n ) {\n (firstExisting as Text).data = String(firstNewChild);\n return;\n }\n }\n\n if (existing.length === 0 && parent.childNodes.length > 0) {\n for (let n = parent.firstChild; n; ) {\n const next = n.nextSibling;\n teardownNodeSubtree(n);\n n = next;\n }\n parent.textContent = '';\n }\n const max = Math.max(existing.length, newChildren.length);\n\n for (let i = 0; i < max; i++) {\n const current = existing[i];\n const next = newChildren[i];\n const nextIsEmpty = isEmptyChild(next);\n\n if (nextIsEmpty && current) {\n teardownNodeSubtree(current);\n current.remove();\n continue;\n }\n\n if (!current && !nextIsEmpty) {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) parent.appendChild(dom);\n continue;\n }\n\n if (!current || nextIsEmpty) continue;\n\n if (typeof next === 'string' || typeof next === 'number') {\n const textNode = document.createTextNode(String(next));\n teardownNodeSubtree(current);\n parent.replaceChild(textNode, current);\n } else if (_isDOMElement(next)) {\n if (typeof next.type === 'string') {\n if (tagsEqualIgnoreCase(current.tagName, next.type)) {\n domHost.updateElementFromVnode(current, next, true, forceUpdate);\n } else {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) {\n teardownNodeSubtree(current);\n parent.replaceChild(dom, current);\n }\n }\n } else {\n const synced = trySyncComponentChild(current, next);\n if (synced && synced !== current) {\n teardownNodeSubtree(current);\n } else if (!synced) {\n const dom = domHost.createDOMNode(next, parentNamespace);\n if (dom) {\n teardownNodeSubtree(current);\n parent.replaceChild(dom, current);\n }\n }\n }\n } else {\n const dom = domHost.createDOMNode(next);\n if (dom) {\n teardownNodeSubtree(current);\n parent.replaceChild(dom, current);\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAyBA,MAAa,+BAAqD;CAChE,gBAAgB,MAAM,oBACpB,mBAAmB,CAAC,CAAC,cAAc,MAAM,eAAe;CAC1D,wBAAwB,IAAI,UAAU,gBACpC,sBAAsB,IAAI,UAAU,WAAW;AACnD;AAEA,SAAgB,sBACd,IACA,UACA,cAAc,OACR;CAC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