@askrjs/askr 0.0.27 → 0.0.29

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 (442) hide show
  1. package/README.md +55 -147
  2. package/dist/_virtual/_rolldown/runtime.js +7 -0
  3. package/dist/bench/components/benchmark-row.d.ts +20 -0
  4. package/dist/bench/components/benchmark-row.d.ts.map +1 -0
  5. package/dist/bench/components/benchmark-row.js +42 -0
  6. package/dist/bench/components/benchmark-row.js.map +1 -0
  7. package/dist/bench/components/benchmark-table.js +25 -0
  8. package/dist/bench/components/benchmark-table.js.map +1 -0
  9. package/dist/benchmark.d.ts +22 -0
  10. package/dist/benchmark.d.ts.map +1 -0
  11. package/dist/benchmark.js +64 -1
  12. package/dist/benchmark.js.map +1 -0
  13. package/dist/bin/askr-ssg.d.ts +28 -0
  14. package/dist/bin/askr-ssg.d.ts.map +1 -0
  15. package/dist/bin/askr-ssg.js +171 -0
  16. package/dist/bin/askr-ssg.js.map +1 -0
  17. package/dist/boot/index.d.ts +64 -42
  18. package/dist/boot/index.d.ts.map +1 -1
  19. package/dist/boot/index.js +416 -2
  20. package/dist/boot/index.js.map +1 -0
  21. package/dist/common/component.d.ts +14 -13
  22. package/dist/common/component.d.ts.map +1 -1
  23. package/dist/common/control.d.ts +13 -0
  24. package/dist/common/control.d.ts.map +1 -0
  25. package/dist/common/control.js +14 -0
  26. package/dist/common/control.js.map +1 -0
  27. package/dist/common/env.js +47 -0
  28. package/dist/common/env.js.map +1 -0
  29. package/dist/common/jsx.d.ts +17 -15
  30. package/dist/common/jsx.d.ts.map +1 -1
  31. package/dist/common/jsx.js +8 -1
  32. package/dist/common/jsx.js.map +1 -0
  33. package/dist/common/props.d.ts +14 -11
  34. package/dist/common/props.d.ts.map +1 -1
  35. package/dist/common/router.d.ts +190 -32
  36. package/dist/common/router.d.ts.map +1 -1
  37. package/dist/common/ssr-errors.d.ts +6 -3
  38. package/dist/common/ssr-errors.d.ts.map +1 -1
  39. package/dist/common/ssr-errors.js +16 -1
  40. package/dist/common/ssr-errors.js.map +1 -0
  41. package/dist/common/ssr.d.ts +12 -9
  42. package/dist/common/ssr.d.ts.map +1 -1
  43. package/dist/common/vnode.d.ts +17 -15
  44. package/dist/common/vnode.d.ts.map +1 -1
  45. package/dist/common/vnode.js +10 -1
  46. package/dist/common/vnode.js.map +1 -0
  47. package/dist/components/link.d.ts +37 -25
  48. package/dist/components/link.d.ts.map +1 -1
  49. package/dist/components/link.js +64 -1
  50. package/dist/components/link.js.map +1 -0
  51. package/dist/control/case.d.ts +17 -0
  52. package/dist/control/case.d.ts.map +1 -0
  53. package/dist/control/case.js +69 -0
  54. package/dist/control/case.js.map +1 -0
  55. package/dist/control/for.d.ts +23 -0
  56. package/dist/control/for.d.ts.map +1 -0
  57. package/dist/control/for.js +62 -0
  58. package/dist/control/for.js.map +1 -0
  59. package/dist/control/index.d.ts +4 -0
  60. package/dist/control/index.js +4 -0
  61. package/dist/control/shared.js +20 -0
  62. package/dist/control/shared.js.map +1 -0
  63. package/dist/control/show.d.ts +14 -0
  64. package/dist/control/show.d.ts.map +1 -0
  65. package/dist/control/show.js +33 -0
  66. package/dist/control/show.js.map +1 -0
  67. package/dist/dev/invariant.js +29 -2
  68. package/dist/dev/invariant.js.map +1 -0
  69. package/dist/dev/logger.js +37 -1
  70. package/dist/dev/logger.js.map +1 -0
  71. package/dist/foundations/icon/icon.d.ts +53 -0
  72. package/dist/foundations/icon/icon.d.ts.map +1 -0
  73. package/dist/foundations/icon/icon.js +88 -0
  74. package/dist/foundations/icon/icon.js.map +1 -0
  75. package/dist/foundations/icon/icon.types.d.ts +21 -0
  76. package/dist/foundations/icon/icon.types.d.ts.map +1 -0
  77. package/dist/foundations/index.d.ts +10 -3
  78. package/dist/foundations/index.js +9 -1
  79. package/dist/foundations/interactions/interaction-policy.js +93 -1
  80. package/dist/foundations/interactions/interaction-policy.js.map +1 -0
  81. package/dist/foundations/interactions/pressable.js +51 -1
  82. package/dist/foundations/interactions/pressable.js.map +1 -0
  83. package/dist/foundations/structures/collection.d.ts +25 -40
  84. package/dist/foundations/structures/collection.d.ts.map +1 -1
  85. package/dist/foundations/structures/collection.js +51 -1
  86. package/dist/foundations/structures/collection.js.map +1 -0
  87. package/dist/foundations/structures/layer.d.ts +47 -68
  88. package/dist/foundations/structures/layer.d.ts.map +1 -1
  89. package/dist/foundations/structures/layer.js +81 -1
  90. package/dist/foundations/structures/layer.js.map +1 -0
  91. package/dist/foundations/structures/layout.d.ts +6 -3
  92. package/dist/foundations/structures/layout.d.ts.map +1 -1
  93. package/dist/foundations/structures/layout.js +13 -1
  94. package/dist/foundations/structures/layout.js.map +1 -0
  95. package/dist/foundations/structures/portal.d.ts +17 -10
  96. package/dist/foundations/structures/portal.d.ts.map +1 -1
  97. package/dist/foundations/structures/portal.js +105 -1
  98. package/dist/foundations/structures/portal.js.map +1 -0
  99. package/dist/foundations/structures/presence.d.ts +11 -5
  100. package/dist/foundations/structures/presence.d.ts.map +1 -1
  101. package/dist/foundations/structures/presence.js +39 -1
  102. package/dist/foundations/structures/presence.js.map +1 -0
  103. package/dist/foundations/structures/slot.d.ts +11 -8
  104. package/dist/foundations/structures/slot.d.ts.map +1 -1
  105. package/dist/foundations/structures/slot.js +41 -1
  106. package/dist/foundations/structures/slot.js.map +1 -0
  107. package/dist/foundations/structures.d.ts +7 -14
  108. package/dist/foundations/structures.js +6 -1
  109. package/dist/foundations/utilities/aria.js +11 -1
  110. package/dist/foundations/utilities/aria.js.map +1 -0
  111. package/dist/foundations/utilities/compose-handlers.js +20 -1
  112. package/dist/foundations/utilities/compose-handlers.js.map +1 -0
  113. package/dist/foundations/utilities/compose-ref.d.ts +7 -4
  114. package/dist/foundations/utilities/compose-ref.d.ts.map +1 -1
  115. package/dist/foundations/utilities/compose-ref.js +18 -1
  116. package/dist/foundations/utilities/compose-ref.js.map +1 -0
  117. package/dist/foundations/utilities/merge-props.js +49 -1
  118. package/dist/foundations/utilities/merge-props.js.map +1 -0
  119. package/dist/fx/fx.d.ts +24 -21
  120. package/dist/fx/fx.d.ts.map +1 -1
  121. package/dist/fx/fx.js +212 -1
  122. package/dist/fx/fx.js.map +1 -0
  123. package/dist/fx/index.d.ts +4 -7
  124. package/dist/fx/index.js +4 -1
  125. package/dist/fx/noop.js +9 -1
  126. package/dist/fx/noop.js.map +1 -0
  127. package/dist/fx/timing.d.ts +24 -21
  128. package/dist/fx/timing.d.ts.map +1 -1
  129. package/dist/fx/timing.js +236 -1
  130. package/dist/fx/timing.js.map +1 -0
  131. package/dist/index.d.ts +21 -20
  132. package/dist/index.js +34 -1
  133. package/dist/index.js.map +1 -0
  134. package/dist/jsx/index.d.ts +1 -4
  135. package/dist/jsx/index.js +3 -1
  136. package/dist/jsx/types.d.ts +18 -25
  137. package/dist/jsx/types.d.ts.map +1 -1
  138. package/dist/jsx/types.js +1 -1
  139. package/dist/jsx/utils.d.ts +4 -3
  140. package/dist/jsx/utils.d.ts.map +1 -1
  141. package/dist/jsx/utils.js +19 -1
  142. package/dist/jsx/utils.js.map +1 -0
  143. package/dist/jsx-dev-runtime.d.ts +8 -0
  144. package/dist/jsx-dev-runtime.d.ts.map +1 -0
  145. package/dist/jsx-dev-runtime.js +32 -1
  146. package/dist/jsx-dev-runtime.js.map +1 -0
  147. package/dist/jsx-runtime.d.ts +12 -0
  148. package/dist/jsx-runtime.d.ts.map +1 -0
  149. package/dist/jsx-runtime.js +45 -1
  150. package/dist/jsx-runtime.js.map +1 -0
  151. package/dist/jsx-runtime2.d.ts +2 -0
  152. package/dist/jsx-runtime2.js +3 -0
  153. package/dist/renderer/children.js +293 -0
  154. package/dist/renderer/children.js.map +1 -0
  155. package/dist/renderer/cleanup.js +150 -1
  156. package/dist/renderer/cleanup.js.map +1 -0
  157. package/dist/renderer/dom.js +2439 -1
  158. package/dist/renderer/dom.js.map +1 -0
  159. package/dist/renderer/env.js +1 -0
  160. package/dist/renderer/evaluate.js +450 -1
  161. package/dist/renderer/evaluate.js.map +1 -0
  162. package/dist/renderer/fastpath.js +145 -1
  163. package/dist/renderer/fastpath.js.map +1 -0
  164. package/dist/renderer/index.js +24 -1
  165. package/dist/renderer/index.js.map +1 -0
  166. package/dist/renderer/keyed.js +119 -1
  167. package/dist/renderer/keyed.js.map +1 -0
  168. package/dist/renderer/reconcile.js +359 -1
  169. package/dist/renderer/reconcile.js.map +1 -0
  170. package/dist/renderer/types.js +1 -1
  171. package/dist/renderer/utils.js +220 -1
  172. package/dist/renderer/utils.js.map +1 -0
  173. package/dist/resources/index.d.ts +3 -9
  174. package/dist/resources/index.js +3 -1
  175. package/dist/router/index.d.ts +6 -10
  176. package/dist/router/index.js +5 -1
  177. package/dist/router/match.js +83 -1
  178. package/dist/router/match.js.map +1 -0
  179. package/dist/router/navigate.d.ts +20 -8
  180. package/dist/router/navigate.d.ts.map +1 -1
  181. package/dist/router/navigate.js +288 -1
  182. package/dist/router/navigate.js.map +1 -0
  183. package/dist/router/policy.d.ts +22 -0
  184. package/dist/router/policy.d.ts.map +1 -0
  185. package/dist/router/policy.js +116 -0
  186. package/dist/router/policy.js.map +1 -0
  187. package/dist/router/route-context.js +79 -0
  188. package/dist/router/route-context.js.map +1 -0
  189. package/dist/router/route.d.ts +101 -33
  190. package/dist/router/route.d.ts.map +1 -1
  191. package/dist/router/route.js +599 -1
  192. package/dist/router/route.js.map +1 -0
  193. package/dist/runtime/child-scope.d.ts +21 -0
  194. package/dist/runtime/child-scope.d.ts.map +1 -0
  195. package/dist/runtime/child-scope.js +77 -0
  196. package/dist/runtime/child-scope.js.map +1 -0
  197. package/dist/runtime/component.d.ts +67 -53
  198. package/dist/runtime/component.d.ts.map +1 -1
  199. package/dist/runtime/component.js +462 -1
  200. package/dist/runtime/component.js.map +1 -0
  201. package/dist/runtime/context.d.ts +28 -42
  202. package/dist/runtime/context.d.ts.map +1 -1
  203. package/dist/runtime/context.js +205 -1
  204. package/dist/runtime/context.js.map +1 -0
  205. package/dist/runtime/control.d.ts +43 -0
  206. package/dist/runtime/control.d.ts.map +1 -0
  207. package/dist/runtime/control.js +125 -0
  208. package/dist/runtime/control.js.map +1 -0
  209. package/dist/runtime/derive.d.ts +15 -6
  210. package/dist/runtime/derive.d.ts.map +1 -1
  211. package/dist/runtime/derive.js +134 -1
  212. package/dist/runtime/derive.js.map +1 -0
  213. package/dist/runtime/dev-namespace.js +57 -1
  214. package/dist/runtime/dev-namespace.js.map +1 -0
  215. package/dist/runtime/effect.d.ts +32 -0
  216. package/dist/runtime/effect.d.ts.map +1 -0
  217. package/dist/runtime/effect.js +146 -0
  218. package/dist/runtime/effect.js.map +1 -0
  219. package/dist/runtime/events.js +162 -1
  220. package/dist/runtime/events.js.map +1 -0
  221. package/dist/runtime/execution-model.js +15 -1
  222. package/dist/runtime/execution-model.js.map +1 -0
  223. package/dist/runtime/fastlane.js +204 -1
  224. package/dist/runtime/fastlane.js.map +1 -0
  225. package/dist/runtime/for-bench.d.ts +41 -0
  226. package/dist/runtime/for-bench.d.ts.map +1 -0
  227. package/dist/runtime/for-bench.js +173 -0
  228. package/dist/runtime/for-bench.js.map +1 -0
  229. package/dist/runtime/for.d.ts +62 -49
  230. package/dist/runtime/for.d.ts.map +1 -1
  231. package/dist/runtime/for.js +668 -1
  232. package/dist/runtime/for.js.map +1 -0
  233. package/dist/runtime/operations.d.ts +18 -15
  234. package/dist/runtime/operations.d.ts.map +1 -1
  235. package/dist/runtime/operations.js +209 -1
  236. package/dist/runtime/operations.js.map +1 -0
  237. package/dist/runtime/perf-metrics.js +64 -0
  238. package/dist/runtime/perf-metrics.js.map +1 -0
  239. package/dist/runtime/readable.d.ts +27 -0
  240. package/dist/runtime/readable.d.ts.map +1 -0
  241. package/dist/runtime/readable.js +118 -0
  242. package/dist/runtime/readable.js.map +1 -0
  243. package/dist/runtime/resource-cell.js +102 -1
  244. package/dist/runtime/resource-cell.js.map +1 -0
  245. package/dist/runtime/scheduler.d.ts +51 -35
  246. package/dist/runtime/scheduler.d.ts.map +1 -1
  247. package/dist/runtime/scheduler.js +328 -1
  248. package/dist/runtime/scheduler.js.map +1 -0
  249. package/dist/runtime/selector.d.ts +11 -0
  250. package/dist/runtime/selector.d.ts.map +1 -0
  251. package/dist/runtime/selector.js +188 -0
  252. package/dist/runtime/selector.js.map +1 -0
  253. package/dist/runtime/ssr-bridge.js +24 -1
  254. package/dist/runtime/ssr-bridge.js.map +1 -0
  255. package/dist/runtime/state.d.ts +11 -21
  256. package/dist/runtime/state.d.ts.map +1 -1
  257. package/dist/runtime/state.js +99 -1
  258. package/dist/runtime/state.js.map +1 -0
  259. package/dist/ssg/batch-render.d.ts +16 -0
  260. package/dist/ssg/batch-render.d.ts.map +1 -0
  261. package/dist/ssg/batch-render.js +84 -0
  262. package/dist/ssg/batch-render.js.map +1 -0
  263. package/dist/ssg/create-static-gen.d.ts +50 -0
  264. package/dist/ssg/create-static-gen.d.ts.map +1 -0
  265. package/dist/ssg/create-static-gen.js +282 -0
  266. package/dist/ssg/create-static-gen.js.map +1 -0
  267. package/dist/ssg/generate-metadata.d.ts +24 -0
  268. package/dist/ssg/generate-metadata.d.ts.map +1 -0
  269. package/dist/ssg/generate-metadata.js +94 -0
  270. package/dist/ssg/generate-metadata.js.map +1 -0
  271. package/dist/ssg/incremental-manifest.js +56 -0
  272. package/dist/ssg/incremental-manifest.js.map +1 -0
  273. package/dist/ssg/index.d.ts +8 -0
  274. package/dist/ssg/index.js +7 -0
  275. package/dist/ssg/resolve-ssg-data.d.ts +23 -0
  276. package/dist/ssg/resolve-ssg-data.d.ts.map +1 -0
  277. package/dist/ssg/resolve-ssg-data.js +46 -0
  278. package/dist/ssg/resolve-ssg-data.js.map +1 -0
  279. package/dist/ssg/route-utils.d.ts +16 -0
  280. package/dist/ssg/route-utils.d.ts.map +1 -0
  281. package/dist/ssg/route-utils.js +24 -0
  282. package/dist/ssg/route-utils.js.map +1 -0
  283. package/dist/ssg/types.d.ts +177 -0
  284. package/dist/ssg/types.d.ts.map +1 -0
  285. package/dist/ssg/write-static-files.d.ts +15 -0
  286. package/dist/ssg/write-static-files.d.ts.map +1 -0
  287. package/dist/ssg/write-static-files.js +73 -0
  288. package/dist/ssg/write-static-files.js.map +1 -0
  289. package/dist/ssr/attrs.js +93 -1
  290. package/dist/ssr/attrs.js.map +1 -0
  291. package/dist/ssr/context.d.ts +31 -32
  292. package/dist/ssr/context.d.ts.map +1 -1
  293. package/dist/ssr/context.js +63 -1
  294. package/dist/ssr/context.js.map +1 -0
  295. package/dist/ssr/errors.d.ts +6 -4
  296. package/dist/ssr/errors.d.ts.map +1 -1
  297. package/dist/ssr/errors.js +4 -1
  298. package/dist/ssr/errors.js.map +1 -0
  299. package/dist/ssr/escape.js +153 -1
  300. package/dist/ssr/escape.js.map +1 -0
  301. package/dist/ssr/index.d.ts +75 -46
  302. package/dist/ssr/index.d.ts.map +1 -1
  303. package/dist/ssr/index.js +543 -1
  304. package/dist/ssr/index.js.map +1 -0
  305. package/dist/ssr/render-keys.d.ts +27 -29
  306. package/dist/ssr/render-keys.d.ts.map +1 -1
  307. package/dist/ssr/render-keys.js +39 -1
  308. package/dist/ssr/render-keys.js.map +1 -0
  309. package/dist/ssr/sink.js +86 -1
  310. package/dist/ssr/sink.js.map +1 -0
  311. package/dist/ssr/stream-render.js +76 -1
  312. package/dist/ssr/stream-render.js.map +1 -0
  313. package/dist/ssr/types.d.ts +14 -13
  314. package/dist/ssr/types.d.ts.map +1 -1
  315. package/package.json +53 -48
  316. package/dist/_virtual/___vite-browser-external.js +0 -1
  317. package/dist/_virtual/__vite-browser-external.js +0 -1
  318. package/dist/_virtual/_commonjsHelpers.js +0 -1
  319. package/dist/_virtual/main.js +0 -1
  320. package/dist/_virtual/preload-helper.js +0 -1
  321. package/dist/bench/benchmark-entry.d.ts +0 -14
  322. package/dist/bench/benchmark-entry.d.ts.map +0 -1
  323. package/dist/common/errors.d.ts +0 -53
  324. package/dist/common/errors.d.ts.map +0 -1
  325. package/dist/common/index.d.ts +0 -14
  326. package/dist/common/index.d.ts.map +0 -1
  327. package/dist/dev/invariant.d.ts +0 -83
  328. package/dist/dev/invariant.d.ts.map +0 -1
  329. package/dist/dev/logger.d.ts +0 -13
  330. package/dist/dev/logger.d.ts.map +0 -1
  331. package/dist/dev/vite-plugin-askr.d.ts +0 -18
  332. package/dist/dev/vite-plugin-askr.d.ts.map +0 -1
  333. package/dist/dev/warnings.d.ts +0 -5
  334. package/dist/dev/warnings.d.ts.map +0 -1
  335. package/dist/for/for.d.ts +0 -16
  336. package/dist/for/for.d.ts.map +0 -1
  337. package/dist/for/for.js +0 -1
  338. package/dist/for/index.d.ts +0 -2
  339. package/dist/for/index.d.ts.map +0 -1
  340. package/dist/for/index.js +0 -1
  341. package/dist/foundations/core.d.ts +0 -23
  342. package/dist/foundations/core.d.ts.map +0 -1
  343. package/dist/foundations/core.js +0 -1
  344. package/dist/foundations/index.d.ts.map +0 -1
  345. package/dist/foundations/interactions/dismissable.d.ts +0 -58
  346. package/dist/foundations/interactions/dismissable.d.ts.map +0 -1
  347. package/dist/foundations/interactions/dismissable.js +0 -1
  348. package/dist/foundations/interactions/focusable.d.ts +0 -16
  349. package/dist/foundations/interactions/focusable.d.ts.map +0 -1
  350. package/dist/foundations/interactions/focusable.js +0 -1
  351. package/dist/foundations/interactions/hoverable.d.ts +0 -19
  352. package/dist/foundations/interactions/hoverable.d.ts.map +0 -1
  353. package/dist/foundations/interactions/hoverable.js +0 -1
  354. package/dist/foundations/interactions/index.d.ts +0 -5
  355. package/dist/foundations/interactions/index.d.ts.map +0 -1
  356. package/dist/foundations/interactions/interaction-policy.d.ts +0 -96
  357. package/dist/foundations/interactions/interaction-policy.d.ts.map +0 -1
  358. package/dist/foundations/interactions/pressable.d.ts +0 -54
  359. package/dist/foundations/interactions/pressable.d.ts.map +0 -1
  360. package/dist/foundations/interactions/roving-focus.d.ts +0 -117
  361. package/dist/foundations/interactions/roving-focus.d.ts.map +0 -1
  362. package/dist/foundations/interactions/roving-focus.js +0 -1
  363. package/dist/foundations/state/controllable.d.ts +0 -53
  364. package/dist/foundations/state/controllable.d.ts.map +0 -1
  365. package/dist/foundations/state/controllable.js +0 -1
  366. package/dist/foundations/state/index.d.ts +0 -2
  367. package/dist/foundations/state/index.d.ts.map +0 -1
  368. package/dist/foundations/structures/index.d.ts +0 -5
  369. package/dist/foundations/structures/index.d.ts.map +0 -1
  370. package/dist/foundations/structures.d.ts.map +0 -1
  371. package/dist/foundations/utilities/aria.d.ts +0 -13
  372. package/dist/foundations/utilities/aria.d.ts.map +0 -1
  373. package/dist/foundations/utilities/compose-handlers.d.ts +0 -34
  374. package/dist/foundations/utilities/compose-handlers.d.ts.map +0 -1
  375. package/dist/foundations/utilities/event-types.d.ts +0 -17
  376. package/dist/foundations/utilities/event-types.d.ts.map +0 -1
  377. package/dist/foundations/utilities/index.d.ts +0 -7
  378. package/dist/foundations/utilities/index.d.ts.map +0 -1
  379. package/dist/foundations/utilities/merge-props.d.ts +0 -2
  380. package/dist/foundations/utilities/merge-props.d.ts.map +0 -1
  381. package/dist/foundations/utilities/use-id.d.ts +0 -29
  382. package/dist/foundations/utilities/use-id.d.ts.map +0 -1
  383. package/dist/foundations/utilities/use-id.js +0 -1
  384. package/dist/fx/index.d.ts.map +0 -1
  385. package/dist/fx/noop.d.ts +0 -12
  386. package/dist/fx/noop.d.ts.map +0 -1
  387. package/dist/index.d.ts.map +0 -1
  388. package/dist/jsx/index.d.ts.map +0 -1
  389. package/dist/jsx/jsx-dev-runtime.d.ts +0 -4
  390. package/dist/jsx/jsx-dev-runtime.d.ts.map +0 -1
  391. package/dist/jsx/jsx-runtime.d.ts +0 -10
  392. package/dist/jsx/jsx-runtime.d.ts.map +0 -1
  393. package/dist/node_modules/esbuild/lib/main.js +0 -65
  394. package/dist/renderer/cleanup.d.ts +0 -25
  395. package/dist/renderer/cleanup.d.ts.map +0 -1
  396. package/dist/renderer/dom.d.ts +0 -62
  397. package/dist/renderer/dom.d.ts.map +0 -1
  398. package/dist/renderer/evaluate.d.ts +0 -4
  399. package/dist/renderer/evaluate.d.ts.map +0 -1
  400. package/dist/renderer/fastpath.d.ts +0 -7
  401. package/dist/renderer/fastpath.d.ts.map +0 -1
  402. package/dist/renderer/index.d.ts +0 -6
  403. package/dist/renderer/index.d.ts.map +0 -1
  404. package/dist/renderer/keyed.d.ts +0 -23
  405. package/dist/renderer/keyed.d.ts.map +0 -1
  406. package/dist/renderer/reconcile.d.ts +0 -88
  407. package/dist/renderer/reconcile.d.ts.map +0 -1
  408. package/dist/renderer/types.d.ts +0 -3
  409. package/dist/renderer/types.d.ts.map +0 -1
  410. package/dist/renderer/utils.d.ts +0 -63
  411. package/dist/renderer/utils.d.ts.map +0 -1
  412. package/dist/resources/index.d.ts.map +0 -1
  413. package/dist/router/index.d.ts.map +0 -1
  414. package/dist/router/match.d.ts +0 -22
  415. package/dist/router/match.d.ts.map +0 -1
  416. package/dist/runtime/dev-namespace.d.ts +0 -31
  417. package/dist/runtime/dev-namespace.d.ts.map +0 -1
  418. package/dist/runtime/events.d.ts +0 -52
  419. package/dist/runtime/events.d.ts.map +0 -1
  420. package/dist/runtime/execution-model.d.ts +0 -4
  421. package/dist/runtime/execution-model.d.ts.map +0 -1
  422. package/dist/runtime/fastlane.d.ts +0 -27
  423. package/dist/runtime/fastlane.d.ts.map +0 -1
  424. package/dist/runtime/hydration.d.ts +0 -25
  425. package/dist/runtime/hydration.d.ts.map +0 -1
  426. package/dist/runtime/resource-cell.d.ts +0 -35
  427. package/dist/runtime/resource-cell.d.ts.map +0 -1
  428. package/dist/runtime/snapshot.d.ts +0 -25
  429. package/dist/runtime/snapshot.d.ts.map +0 -1
  430. package/dist/runtime/ssr-bridge.d.ts +0 -10
  431. package/dist/runtime/ssr-bridge.d.ts.map +0 -1
  432. package/dist/ssr/attrs.d.ts +0 -26
  433. package/dist/ssr/attrs.d.ts.map +0 -1
  434. package/dist/ssr/create-ssr.d.ts +0 -19
  435. package/dist/ssr/create-ssr.d.ts.map +0 -1
  436. package/dist/ssr/escape.d.ts +0 -38
  437. package/dist/ssr/escape.d.ts.map +0 -1
  438. package/dist/ssr/sink.d.ts +0 -23
  439. package/dist/ssr/sink.d.ts.map +0 -1
  440. package/dist/ssr/stream-render.d.ts +0 -7
  441. package/dist/ssr/stream-render.d.ts.map +0 -1
  442. package/dist/vite/index.js +0 -3
@@ -1 +1,2439 @@
1
- import{logger as Oe}from"../dev/logger.js";import"../jsx-runtime.js";import{CONTEXT_FRAME_SYMBOL as re,getCurrentContextFrame as oe,withContext as K}from"../runtime/context.js";import{getCurrentInstance as V,setCurrentComponentInstance as D,createComponentInstance as ie,renderComponentInline as se,mountInstanceInline as U}from"../runtime/component.js";import{elementListeners as h,elementReactivePropsCleanup as A,removeAllListeners as y,cleanupInstanceIfPresent as g}from"./cleanup.js";import{incDevCounter as q,getDevValue as ce,setDevValue as N}from"../runtime/dev-namespace.js";import"./types.js";import{__FOR_BOUNDARY__ as j,_isDOMElement as S}from"../common/vnode.js";import{evaluateForState as z}from"../runtime/for.js";import{keyedElements as v}from"./keyed.js";import{reconcileKeyedChildren as ae}from"./reconcile.js";import{createWrappedHandler as G,getPassiveOptions as X,isSkippedProp as $,parseEventName as Y,now as F,logFastPathDebug as I,recordFastPathStats as fe,hasNonTrivialProps as B,recordDOMReplace as le}from"./utils.js";import{globalScheduler as O}from"../runtime/scheduler.js";import{isEventDelegationEnabled as W,isDelegatedEvent as J,addDelegatedListener as Q,getDelegatedHandlersForElement as ue,removeDelegatedListener as k}from"../runtime/events.js";import{Fragment as de}from"../common/jsx.js";var P={};const pe=typeof document<"u";let H=0;function me(){const e="__COMPONENT_INSTANCE_ID";try{q(e);const t=ce(e);if(typeof t=="number"&&Number.isFinite(t))return`comp-${t}`}catch{}return H++,`comp-${H}`}function ge(e,t,n){const r=W()&&J(t);r&&Q(e,t,n,n,void 0);const o=G(n,!0),a=X(t);r||(a!==void 0?e.addEventListener(t,o,a):e.addEventListener(t,o)),h.has(e)||h.set(e,new Map),h.get(e).set(t,{handler:Z(r,e,t,o),original:n,options:a,isDelegated:r})}function Z(e,t,n,r){if(!e)return r;const o=ue(t);if(o){const a=o.get(n);if(a)return a.handler}return r}const E=new Set;let d=null,x=!1;function ye(){if(!d){d={id:"reactive-props-coordinator",lastRenderToken:0,hasPendingUpdate:!1,notifyUpdate:null,abortController:new AbortController};const e=()=>{if(!x)return;x=!1;const t=V();try{for(const n of E){if(!n.isActive)continue;for(const a of n.readStates)a._readers&&a._readers.delete(d);n.readStates.clear();const r=new Set,o={_pendingReadStates:r,_currentRenderToken:d.lastRenderToken};D(o);try{const a=n.propFn();te(n.el,n.propName,a,n.tagName),n.readStates=r}catch{}}d&&(d.lastRenderToken=(d.lastRenderToken??0)+1);for(const n of E)if(n.isActive)for(const r of n.readStates)r._readers||(r._readers=new Map),r._readers.set(d,d.lastRenderToken??0)}finally{D(t)}};d.notifyUpdate=()=>{x||(x=!0,O.isExecuting()?e():O.enqueue(e))},d._pendingFlushTask=()=>{d.hasPendingUpdate=!1,d.notifyUpdate()}}return d}function ee(e,t,n,r){const o=ye(),a={el:e,propName:t,propFn:n,tagName:r,readStates:new Set,isActive:!0};E.add(a);const s=V(),i=new Set,f={_pendingReadStates:i,_currentRenderToken:o.lastRenderToken};D(f);try{const c=n();te(e,t,c,r),a.readStates=i;for(const l of i)l._readers||(l._readers=new Map),l._readers.set(o,o.lastRenderToken??0)}finally{D(s)}return()=>{if(a.isActive=!1,E.delete(a),d)for(const c of a.readStates)c._readers&&c._readers.delete(d);a.readStates.clear(),E.size===0&&d&&(d.abortController.abort(),d=null)}}function te(e,t,n,r){if(n==null||n===!1){t==="class"||t==="className"?e.className="":e.removeAttribute(t);return}t==="class"||t==="className"?e.className=String(n):t==="value"||t==="checked"?ne(e,t,n,r):e.setAttribute(t,String(n))}function he(e,t,n){for(const r in t){const o=t[r];if(r==="ref"){Se(e,o);continue}if($(r)||o==null||o===!1)continue;const a=Y(r);if(a){ge(e,a,o);continue}if(typeof o=="function"&&!a&&r!=="ref"){const s=ee(e,r,o,n);A.has(e)||A.set(e,new Map),A.get(e).set(r,{cleanup:s,fnRef:o});continue}r==="class"||r==="className"?e.className=String(o):r==="value"||r==="checked"?ne(e,r,o,n):e.setAttribute(r,String(o))}}function Se(e,t){const n=t;if(n){if(typeof n=="function"){n(e);return}Object.isExtensible(n)&&(n.current=e)}}function ne(e,t,n,r){t==="value"?((b(r,"input")||b(r,"textarea")||b(r,"select"))&&(e.value=String(n)),e.setAttribute("value",String(n))):t==="checked"&&(b(r,"input")&&(e.checked=!!n),e.setAttribute("checked",String(!!n)))}function R(e,t,n){const r=t.key??n?.key;r!==void 0&&e.setAttribute("data-key",String(r))}function p(e){if(!pe)return null;if(typeof e=="string")return document.createTextNode(e);if(typeof e=="number")return document.createTextNode(String(e));if(!e)return null;if(Array.isArray(e)){const t=document.createDocumentFragment();for(const n of e){const r=p(n);r&&t.appendChild(r)}return t}if(typeof e=="object"&&e!==null&&"type"in e){const t=e.type,n=e.props||{};if(typeof t=="string")return Ae(e,t,n);if(typeof t=="function")return Ce(e,t,n);if(t===j)return be(e,n);if(typeof t=="symbol"&&(t===de||String(t)==="Symbol(Fragment)"))return Te(e,n)}return null}function Ae(e,t,n){const r=document.createElement(t);R(r,e,n),he(r,n,t);const o=n.children??e.children;if(o!=null)if(Array.isArray(o)){for(const a of o){const s=p(a);s&&r.appendChild(s)}}else{const a=p(o);a&&r.appendChild(a)}return r}function Ce(e,t,n){const o=e[re]||oe(),a=t;if(a.constructor.name==="AsyncFunction")throw new Error("Async components are not supported. Use resource() for async work.");let i=e.__instance;i||(i=ie(me(),a,n||{},null),e.__instance=i),o&&(i.ownerFrame=o);const f=K(o,()=>se(i));if(f instanceof Promise)throw new Error("Async components are not supported. Components must return synchronously.");const c=K(o,()=>p(f));if(c instanceof Element)return U(i,c),R(c,e,n),c;if(!c){const u=document.createComment("");return i._placeholder=u,i.mounted=!0,i.notifyUpdate=i._enqueueRun,u}const l=document.createElement("div");return l.appendChild(c),U(i,l),R(l,e,n),l}function Te(e,t){const n=document.createDocumentFragment(),r=t.children||e.children;if(r)if(Array.isArray(r))for(const o of r){const a=p(o);a&&n.appendChild(a)}else{const o=p(r);o&&n.appendChild(o)}return n}function _e(e,t){if(!S(t)||!(e instanceof Element))return!0;const n=t.type;return typeof n!="string"?!0:e.tagName.toLowerCase()!==n.toLowerCase()}function be(e,t){const n=e._forState;if(!n)return document.createDocumentFragment();const r=t.source,o=z(n,r),a=document.createDocumentFragment();for(let s=0;s<o.length;s++){const i=o[s],f=n.orderedKeys[s],c=f!=null?n.items.get(f):null;let l=null;if(c&&c._dom){const u=c._dom;_e(u,i)||(l=u)}l||(l=p(i),c&&(c._dom=l??void 0)),l&&(l instanceof Element&&C(l,i,!0),a.appendChild(l))}return a}function C(e,t,n=!0){if(!S(t))return;const r=t.props||{};R(e,t,r);const o=h.get(e);let a=null;for(const s in r){const i=r[s];if($(s))continue;const f=Y(s);if(i==null||i===!1){if(s==="class"||s==="className")e.className="";else if(f&&o?.has(f)){const c=o.get(f);c.isDelegated?k(e,f):c.options!==void 0?e.removeEventListener(f,c.handler,c.options):e.removeEventListener(f,c.handler),o.delete(f)}else e.removeAttribute(s);continue}if(typeof i=="function"&&!f&&s!=="ref"){const l=A.get(e)?.get(s);if(l&&l.fnRef===i)continue;l&&l.cleanup();const u=ee(e,s,i,t.type);A.has(e)||A.set(e,new Map),A.get(e).set(s,{cleanup:u,fnRef:i});continue}if(s==="class"||s==="className")e.className=String(i);else if(s==="value"||s==="checked")e[s]=i;else if(f){o&&o.size>0&&(a??=new Set).add(f);const c=W()&&J(f),l=o?.get(f);if(l&&l.original===i)continue;l&&(l.isDelegated?k(e,f):l.options!==void 0?e.removeEventListener(f,l.handler,l.options):e.removeEventListener(f,l.handler)),c&&Q(e,f,i,i,void 0);const u=G(i,!0),m=X(f);c||(m!==void 0?e.addEventListener(f,u,m):e.addEventListener(f,u)),h.has(e)||h.set(e,new Map),h.get(e).set(f,{handler:Z(c,e,f,u),original:i,options:m,isDelegated:c})}else e.setAttribute(s,String(i))}if(o&&o.size>0)if(a===null){for(const[s,i]of o)i.isDelegated?k(e,s):i.options!==void 0?e.removeEventListener(s,i.handler,i.options):e.removeEventListener(s,i.handler);h.delete(e)}else{for(const[s,i]of o)a.has(s)||(i.isDelegated?k(e,s):i.options!==void 0?e.removeEventListener(s,i.handler,i.options):e.removeEventListener(s,i.handler),o.delete(s));o.size===0&&h.delete(e)}if(n){const s=t.children||r.children;Ee(e,s)}}function Ee(e,t){if(t==null){for(let r=e.firstChild;r;){const o=r.nextSibling;r instanceof Element&&(y(r),g(r)),r=o}e.textContent="";return}if(!Array.isArray(t)&&(typeof t=="string"||typeof t=="number")){if(e.childNodes.length===1&&e.firstChild?.nodeType===3)e.firstChild.data=String(t);else{for(let r=e.firstChild;r;){const o=r.nextSibling;r instanceof Element&&(y(r),g(r)),r=o}e.textContent=String(t)}return}if(Array.isArray(t)&&t.length===1&&S(t[0])&&t[0].type===j){const r=t[0],o=r._forState;if(!o)throw new Error("[updateElementChildren] For boundary missing _forState");const a=(r.props||{}).source,s=z(o,a),i=v.get(e),f=ae(e,s,i||new Map);v.set(e,f);return}if(Array.isArray(t)){ve(e,t);return}for(let r=e.firstChild;r;){const o=r.nextSibling;r instanceof Element&&(y(r),g(r)),r=o}e.textContent="";const n=p(t);n&&e.appendChild(n)}function ve(e,t){const n=Array.from(e.children),r=t.some(s=>typeof s=="string"||typeof s=="number"),o=t.some(s=>S(s));if(r&&o){const s=Array.from(e.childNodes),i=Math.max(s.length,t.length);for(let f=0;f<i;f++){const c=s[f],l=t[f];if(l===void 0&&c){c.nodeType===1&&g(c),c.remove();continue}if(!c&&l!==void 0){const u=p(l);u&&e.appendChild(u);continue}if(!(!c||l===void 0)){if(typeof l=="string"||typeof l=="number")if(c.nodeType===3)c.data=String(l);else{const u=document.createTextNode(String(l));e.replaceChild(u,c)}else if(S(l))if(c.nodeType===1){const u=c;if(typeof l.type=="string")if(_(u.tagName,l.type))C(u,l);else{const m=p(l);m&&(y(u),g(u),e.replaceChild(m,c))}}else{const u=p(l);u&&e.replaceChild(u,c)}}}return}if(t.length===1&&n.length===0&&e.childNodes.length===1){const s=t[0],i=e.firstChild;if((typeof s=="string"||typeof s=="number")&&i?.nodeType===3){i.data=String(s);return}}if(n.length===0&&e.childNodes.length>0){for(let s=e.firstChild;s;){const i=s.nextSibling;s instanceof Element&&(y(s),g(s)),s=i}e.textContent=""}const a=Math.max(n.length,t.length);for(let s=0;s<a;s++){const i=n[s],f=t[s];if(f===void 0&&i){g(i),i.remove();continue}if(!i&&f!==void 0){const c=p(f);c&&e.appendChild(c);continue}if(!(!i||f===void 0))if(typeof f=="string"||typeof f=="number"){if(i instanceof Element&&i.childNodes.length>0)for(let c=i.firstChild;c;){const l=c.nextSibling;c instanceof Element&&(y(c),g(c)),c=l}i.textContent=String(f)}else if(S(f))if(typeof f.type=="string")if(_(i.tagName,f.type))C(i,f);else{const c=p(f);c&&(i instanceof Element&&y(i),g(i),e.replaceChild(c,i))}else{const c=p(f);c&&(i instanceof Element&&y(i),g(i),e.replaceChild(c,i))}else{const c=p(f);c&&(i instanceof Element&&y(i),g(i),e.replaceChild(c,i))}}}function tt(e,t){const n=t.length;let r=0,o=0;const a=F(),s=P.ASKR_FASTPATH_DEBUG==="1"||P.ASKR_FASTPATH_DEBUG==="true";for(let c=0;c<n;c++){const{key:l,vnode:u}=t[c],m=e.children[c];if(m&&S(u)&&typeof u.type=="string"){const L=u.type;if(_(m.tagName,L)){const w=u.children||u.props?.children;s&&I("positional idx",c,{chTag:m.tagName,vnodeType:L,chChildNodes:m.childNodes.length,childrenType:Array.isArray(w)?"array":typeof w}),ke(m,w,u),Ne(m,l,()=>o++),r++;continue}else s&&I("positional tag mismatch",c,{chTag:m.tagName,vnodeType:L})}else s&&I("positional missing or invalid",c,{ch:!!m});Fe(e,c,u)}const i=F()-a;Pe(e,t);const f={n,reused:r,updatedKeys:o,t:i};return fe(f,"bulkKeyedPositionalHits"),f}function ke(e,t,n){typeof t=="string"||typeof t=="number"?(T(e,String(t)),n.props&&B(n.props)&&C(e,n,!1)):Array.isArray(t)&&t.length===1&&(typeof t[0]=="string"||typeof t[0]=="number")?(T(e,String(t[0])),n.props&&B(n.props)&&C(e,n,!1)):xe(e,n)||C(e,n)}function xe(e,t){const n=t.children||t.props?.children;if(!Array.isArray(n)||n.length!==2)return!1;const r=n[0],o=n[1];if(!S(r)||!S(o)||typeof r.type!="string"||typeof o.type!="string")return!1;const a=e.children[0],s=e.children[1];if(!a||!s||!_(a.tagName,r.type)||!_(s.tagName,o.type))return!1;const i=r.children||r.props?.children,f=o.children||o.props?.children;if(typeof i=="string"||typeof i=="number")T(a,String(i));else if(Array.isArray(i)&&i.length===1&&(typeof i[0]=="string"||typeof i[0]=="number"))T(a,String(i[0]));else return!1;if(typeof f=="string"||typeof f=="number")T(s,String(f));else if(Array.isArray(f)&&f.length===1&&(typeof f[0]=="string"||typeof f[0]=="number"))T(s,String(f[0]));else return!1;return!0}function T(e,t){e.childNodes.length===1&&e.firstChild?.nodeType===3?e.firstChild.data=t:e.textContent=t}function Ne(e,t,n){try{const r=String(t);if(e.getAttribute("data-key")===r)return;e.setAttribute("data-key",r),n()}catch{}}function De(e){switch(e){case"div":return"DIV";case"span":return"SPAN";case"p":return"P";case"a":return"A";case"button":return"BUTTON";case"input":return"INPUT";case"ul":return"UL";case"ol":return"OL";case"li":return"LI";default:return null}}function b(e,t){if(e===t)return!0;const n=e.length;if(n!==t.length)return!1;for(let r=0;r<n;r++){const o=e.charCodeAt(r),a=t.charCodeAt(r);if(o===a)continue;const s=o>=65&&o<=90?o+32:o,i=a>=65&&a<=90?a+32:a;if(s!==i)return!1}return!0}function _(e,t){const n=De(t);return n!==null&&e===n?!0:b(e,t)}function Fe(e,t,n){const r=p(n);if(r){const o=e.children[t];o?(g(o),e.replaceChild(r,o)):e.appendChild(r)}}function Pe(e,t){try{const n=v.get(e),r=n?(n.clear(),n):new Map;for(let o=0;o<t.length;o++){const a=t[o].key,s=e.children[o];s&&r.set(a,s)}v.set(e,r)}catch{}}function nt(e,t){const n=F(),r=Array.from(e.childNodes),o=[];let a=0,s=0;for(let l=0;l<t.length;l++){const u=Re(t[l],r[l],o);u==="reused"?a++:u==="created"&&s++}const i=F()-n,f=Ie(e,o);v.delete(e);const c={n:t.length,reused:a,created:s,tBuild:i,tCommit:f};return Me(c),c}function Re(e,t,n){return typeof e=="string"||typeof e=="number"?Le(String(e),t,n):typeof e=="object"&&e!==null&&"type"in e?we(e,t,n):"skipped"}function Le(e,t,n){return t&&t.nodeType===3?(t.data=e,n.push(t),"reused"):(n.push(document.createTextNode(e)),"created")}function we(e,t,n){const r=e;if(typeof r.type=="string"){const a=r.type;if(t&&t.nodeType===1&&_(t.tagName,a))return C(t,e),n.push(t),"reused"}const o=p(e);return o?(n.push(o),"created"):"skipped"}function Ie(e,t){const n=Date.now(),r=document.createDocumentFragment();for(let o=0;o<t.length;o++)r.appendChild(t[o]);try{for(let o=e.firstChild;o;){const a=o.nextSibling;o instanceof Element&&y(o),g(o),o=a}}catch{}return le("bulk-text-replace"),e.replaceChildren(r),Date.now()-n}function Me(e){try{N("__LAST_BULK_TEXT_FASTPATH_STATS",e),N("__LAST_FASTPATH_STATS",e),N("__LAST_FASTPATH_COMMIT_COUNT",1),q("bulkTextFastpathHits")}catch{}}function rt(e,t){const n=Number(P.ASKR_BULK_TEXT_THRESHOLD)||1024,r=.8,o=Array.isArray(t)?t.length:0;if(o<n)return M({phase:"bulk-unkeyed-eligible",reason:"too-small",total:o,threshold:n}),!1;const a=Ke(t);if(a.componentFound!==void 0)return M({phase:"bulk-unkeyed-eligible",reason:"component-child",index:a.componentFound}),!1;const s=a.simple/o,i=s>=r&&e.childNodes.length>=o;return M({phase:"bulk-unkeyed-eligible",total:o,simple:a.simple,fraction:s,requiredFraction:r,eligible:i}),i}function Ke(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(typeof r=="string"||typeof r=="number"){t++;continue}if(typeof r=="object"&&r!==null&&"type"in r){const o=r;if(typeof o.type=="function")return{simple:t,componentFound:n};typeof o.type=="string"&&Ue(o)&&t++}}return{simple:t}}function Ue(e){const t=e.children||e.props?.children;return!!(t==null||typeof t=="string"||typeof t=="number"||Array.isArray(t)&&t.length===1&&(typeof t[0]=="string"||typeof t[0]=="number"))}function M(e){if(P.ASKR_FASTPATH_DEBUG==="1")try{N("__BULK_DIAG",e)}catch{}}export{pe as IS_DOM_AVAILABLE,p as createDOMNode,be as createForBoundary,rt as isBulkTextFastPathEligible,tt as performBulkPositionalKeyedTextUpdate,nt as performBulkTextReplace,Ee as updateElementChildren,C as updateElementFromVnode,ve as updateUnkeyedChildren};
1
+ import { __FOR_BOUNDARY__, _isDOMElement } from "../common/vnode.js";
2
+ import "./types.js";
3
+ import { getRuntimeEnv } from "../common/env.js";
4
+ import { logger } from "../dev/logger.js";
5
+ import { incrementPerfMetric } from "../runtime/perf-metrics.js";
6
+ import { globalScheduler } from "../runtime/scheduler.js";
7
+ import { Fragment, STATIC_CHILDREN } from "../common/jsx.js";
8
+ import { getCurrentContextFrame, getVNodeContextFrame, markVNodeTreeWithContextFrame, withContext } from "../runtime/context.js";
9
+ import { getDevValue, incDevCounter } from "../runtime/dev-namespace.js";
10
+ import "./env.js";
11
+ import { createMutableWrappedHandler, extractKey, getPassiveOptions, isSkippedProp, parseEventName, readElementClassName, tagNamesEqualIgnoreCase, writeElementClassName } from "./utils.js";
12
+ import { keyedElements } from "./keyed.js";
13
+ import { cleanupComponent, createComponentInstance, getCurrentInstance, mountInstanceInline, renderComponentInline, warnUnusedStateReads } from "../runtime/component.js";
14
+ import { addDelegatedListener, getDelegatedHandlerForElement, getDelegatedHandlersForElement, isDelegatedEvent, isEventDelegationEnabled, removeDelegatedListener, updateDelegatedListener } from "../runtime/events.js";
15
+ import { REACTIVE_CHILDREN_KEY, elementListeners, elementReactivePropsCleanup, removeAllListeners, removeElementListeners, removeElementReactiveProps, teardownNodeSubtree } from "./cleanup.js";
16
+ import "../jsx-runtime.js";
17
+ import { createChildScope, disposeChildScope, rerenderChildScope } from "../runtime/child-scope.js";
18
+ import { isBenchMetricScopeActive, recordBenchCounter, recordBenchEvent, recordBenchTiming, withBenchMetricScope } from "../runtime/for-bench.js";
19
+ import { clearForDomUpdateState, evaluateForState } from "../runtime/for.js";
20
+ import { clearCaseDomUpdateState, clearShowDomUpdateState, evaluateCaseState, evaluateShowState } from "../runtime/control.js";
21
+ import { reconcileKeyedChildren } from "./reconcile.js";
22
+ import { isBulkTextFastPathEligible, performBulkTextReplace } from "./children.js";
23
+ import { createFineGrainedEffect, markFineGrainedEffectsDirtySource } from "../runtime/effect.js";
24
+ //#region src/renderer/dom.ts
25
+ const reactivePropRegistry = /* @__PURE__ */ new Set();
26
+ const controlBoundaryOwners = /* @__PURE__ */ new WeakMap();
27
+ let reactiveChildScopeId = 0;
28
+ function collectReactiveScalarSequenceValue(value, normalized) {
29
+ if (isFragmentVNode(value)) return collectReactiveScalarSequenceValue(value.props?.children ?? value.children, normalized);
30
+ if (Array.isArray(value)) {
31
+ for (const child of value) if (!collectReactiveScalarSequenceValue(child, normalized)) return false;
32
+ return true;
33
+ }
34
+ if (value === null || value === void 0 || value === false) return true;
35
+ if (typeof value === "string" || typeof value === "number") {
36
+ normalized.push(String(value));
37
+ return true;
38
+ }
39
+ return false;
40
+ }
41
+ function collectReactiveScalarChildSource(children, slots, state) {
42
+ if (isFragmentVNode(children)) return collectReactiveScalarChildSource(children.props?.children ?? children.children, slots, state);
43
+ if (Array.isArray(children)) {
44
+ for (const child of children) if (!collectReactiveScalarChildSource(child, slots, state)) return false;
45
+ return true;
46
+ }
47
+ if (children === null || children === void 0 || children === false) return true;
48
+ if (typeof children === "function") {
49
+ slots.push({
50
+ kind: "dynamic",
51
+ compute: children
52
+ });
53
+ state.hasDynamic = true;
54
+ return true;
55
+ }
56
+ if (typeof children === "string" || typeof children === "number") {
57
+ slots.push({
58
+ kind: "static",
59
+ value: String(children)
60
+ });
61
+ return true;
62
+ }
63
+ return false;
64
+ }
65
+ function getReactiveScalarChildSource(children) {
66
+ const slots = [];
67
+ const state = { hasDynamic: false };
68
+ if (!collectReactiveScalarChildSource(children, slots, state)) return null;
69
+ return state.hasDynamic ? slots : null;
70
+ }
71
+ function getSingleReactiveChildBoundarySource(children) {
72
+ if (isFragmentVNode(children)) return getSingleReactiveChildBoundarySource(children.props?.children ?? children.children);
73
+ if (Array.isArray(children)) {
74
+ if (children.length !== 1) return null;
75
+ return getSingleReactiveChildBoundarySource(children[0]);
76
+ }
77
+ if (typeof children === "function") return children;
78
+ return null;
79
+ }
80
+ function collectReactiveChildBoundarySequenceSource(children, slots, state) {
81
+ if (isFragmentVNode(children)) return collectReactiveChildBoundarySequenceSource(children.props?.children ?? children.children, slots, state);
82
+ if (Array.isArray(children)) {
83
+ for (const child of children) if (!collectReactiveChildBoundarySequenceSource(child, slots, state)) return false;
84
+ return true;
85
+ }
86
+ if (children === null || children === void 0 || children === false) return true;
87
+ if (typeof children === "function") {
88
+ slots.push({
89
+ kind: "dynamic",
90
+ compute: children
91
+ });
92
+ state.dynamicCount += 1;
93
+ return true;
94
+ }
95
+ if (typeof children === "string" || typeof children === "number") {
96
+ slots.push({
97
+ kind: "static-text",
98
+ value: String(children)
99
+ });
100
+ return true;
101
+ }
102
+ if (_isDOMElement(children)) {
103
+ slots.push({
104
+ kind: "static-node",
105
+ value: children
106
+ });
107
+ return true;
108
+ }
109
+ return false;
110
+ }
111
+ function getReactiveChildBoundarySequenceSource(children) {
112
+ const slots = [];
113
+ const state = { dynamicCount: 0 };
114
+ if (!collectReactiveChildBoundarySequenceSource(children, slots, state)) return null;
115
+ return state.dynamicCount >= 1 && slots.length > 1 ? slots : null;
116
+ }
117
+ function areReactiveChildBoundarySequenceSourcesEqual(previousSource, nextSource) {
118
+ if (!Array.isArray(previousSource) || previousSource.length !== nextSource.length) return false;
119
+ for (let index = 0; index < nextSource.length; index += 1) {
120
+ const previousSlot = previousSource[index];
121
+ const nextSlot = nextSource[index];
122
+ if (!previousSlot || previousSlot.kind !== nextSlot.kind) return false;
123
+ if (nextSlot.kind === "static-text") {
124
+ if (previousSlot.kind !== "static-text" || previousSlot.value !== nextSlot.value) return false;
125
+ continue;
126
+ }
127
+ if (nextSlot.kind === "static-node") {
128
+ if (previousSlot.kind !== "static-node" || previousSlot.value !== nextSlot.value) return false;
129
+ continue;
130
+ }
131
+ if (previousSlot.kind !== "dynamic" || previousSlot.compute !== nextSlot.compute) return false;
132
+ }
133
+ return true;
134
+ }
135
+ function cleanupDetachedComponentHost(host, retainedInstance) {
136
+ removeElementListeners(host);
137
+ removeElementReactiveProps(host);
138
+ const hostInstances = host.__ASKR_INSTANCES;
139
+ if (hostInstances && hostInstances.length > 0) for (const instance of hostInstances) {
140
+ if (instance === retainedInstance) continue;
141
+ cleanupComponent(instance);
142
+ }
143
+ else if (host.__ASKR_INSTANCE && host.__ASKR_INSTANCE !== retainedInstance) cleanupComponent(host.__ASKR_INSTANCE);
144
+ const descendants = host.querySelectorAll("*");
145
+ for (let index = 0; index < descendants.length; index += 1) {
146
+ const descendant = descendants[index];
147
+ removeElementListeners(descendant);
148
+ removeElementReactiveProps(descendant);
149
+ if (descendant.__ASKR_INSTANCES?.length) {
150
+ for (const instance of descendant.__ASKR_INSTANCES) {
151
+ if (instance === retainedInstance) continue;
152
+ cleanupComponent(instance);
153
+ }
154
+ try {
155
+ delete descendant.__ASKR_INSTANCES;
156
+ } catch {}
157
+ } else if (descendant.__ASKR_INSTANCE && descendant.__ASKR_INSTANCE !== retainedInstance) {
158
+ cleanupComponent(descendant.__ASKR_INSTANCE);
159
+ try {
160
+ delete descendant.__ASKR_INSTANCE;
161
+ } catch {}
162
+ }
163
+ }
164
+ try {
165
+ delete host.__ASKR_INSTANCE;
166
+ delete host.__ASKR_INSTANCES;
167
+ delete host.__ASKR_WRAPPER_HOST;
168
+ } catch {}
169
+ }
170
+ function canUpdateReactiveChildBoundarySequenceSource(previousSource, nextSource) {
171
+ if (!Array.isArray(previousSource) || previousSource.length !== nextSource.length) return false;
172
+ for (let index = 0; index < nextSource.length; index += 1) {
173
+ const previousSlot = previousSource[index];
174
+ const nextSlot = nextSource[index];
175
+ if (!previousSlot || previousSlot.kind !== nextSlot.kind) return false;
176
+ if (nextSlot.kind === "static-text") {
177
+ if (previousSlot.kind !== "static-text" || previousSlot.value !== nextSlot.value) return false;
178
+ continue;
179
+ }
180
+ if (nextSlot.kind === "static-node") {
181
+ if (previousSlot.kind !== "static-node" || previousSlot.value !== nextSlot.value) return false;
182
+ }
183
+ }
184
+ return true;
185
+ }
186
+ function areReactiveScalarChildSourcesEqual(previousSource, nextSource) {
187
+ if (!Array.isArray(previousSource) || previousSource.length !== nextSource.length) return false;
188
+ for (let index = 0; index < nextSource.length; index += 1) {
189
+ const previousSlot = previousSource[index];
190
+ const nextSlot = nextSource[index];
191
+ if (!previousSlot || previousSlot.kind !== nextSlot.kind) return false;
192
+ if (nextSlot.kind === "static") {
193
+ if (previousSlot.kind !== "static" || previousSlot.value !== nextSlot.value) return false;
194
+ continue;
195
+ }
196
+ if (previousSlot.kind !== "dynamic" || previousSlot.compute !== nextSlot.compute) return false;
197
+ }
198
+ return true;
199
+ }
200
+ function getOrCreateElementReactiveCleanupMap(el) {
201
+ let cleanupMap = elementReactivePropsCleanup.get(el);
202
+ if (!cleanupMap) {
203
+ cleanupMap = /* @__PURE__ */ new Map();
204
+ elementReactivePropsCleanup.set(el, cleanupMap);
205
+ }
206
+ return cleanupMap;
207
+ }
208
+ function normalizeReactiveScalarSequenceValues(values) {
209
+ const normalized = [];
210
+ for (const value of values) if (!collectReactiveScalarSequenceValue(value, normalized)) return null;
211
+ return normalized;
212
+ }
213
+ function normalizeOwnedReactiveTextValue(value) {
214
+ if (typeof value === "string" || typeof value === "number") return String(value);
215
+ return null;
216
+ }
217
+ function collectReactiveChildValuesAsVNodes(values, children) {
218
+ for (const value of values) collectReactiveChildBoundaryVNodes(value, children);
219
+ }
220
+ function materializeReactiveChildBoundaryNodes(value, parentNamespace) {
221
+ const nodes = [];
222
+ const dom = createDOMNode(value, parentNamespace);
223
+ if (!dom) return nodes;
224
+ if (dom instanceof DocumentFragment) {
225
+ for (let child = dom.firstChild; child; child = dom.firstChild) {
226
+ nodes.push(child);
227
+ dom.removeChild(child);
228
+ }
229
+ return nodes;
230
+ }
231
+ nodes.push(dom);
232
+ return nodes;
233
+ }
234
+ function syncReactiveScalarTextNodes(el, slotValues, values) {
235
+ const childNodes = el.childNodes;
236
+ if (childNodes.length === values.length) {
237
+ let allText = true;
238
+ for (let index = 0; index < childNodes.length; index += 1) if (childNodes[index]?.nodeType !== Node.TEXT_NODE) {
239
+ allText = false;
240
+ break;
241
+ }
242
+ if (allText) {
243
+ for (let index = 0; index < values.length; index += 1) {
244
+ const textNode = childNodes[index];
245
+ if (textNode.data !== values[index]) textNode.data = values[index];
246
+ }
247
+ return;
248
+ }
249
+ }
250
+ const host = createReactiveChildBoundaryHost(el);
251
+ for (let node = el.firstChild; node;) {
252
+ const next = node.nextSibling;
253
+ host.appendChild(node);
254
+ node = next;
255
+ }
256
+ updateElementChildren(host, slotValues);
257
+ syncReactiveChildExpectedNodes(el, Array.from(host.childNodes));
258
+ }
259
+ function trySyncScalarChildSequenceInPlace(el, children) {
260
+ const normalized = normalizeReactiveScalarSequenceValues(children);
261
+ if (!normalized) return false;
262
+ if (el.childNodes.length !== normalized.length) return false;
263
+ for (let index = 0; index < el.childNodes.length; index += 1) if (el.childNodes[index]?.nodeType !== Node.TEXT_NODE) return false;
264
+ syncReactiveScalarTextNodes(el, children, normalized);
265
+ return true;
266
+ }
267
+ function normalizeReactiveChildBoundaryVNode(value) {
268
+ if (!isFragmentVNode(value)) return value;
269
+ const children = normalizeComponentChildren(value);
270
+ if (children.length !== 1) return value;
271
+ return normalizeReactiveChildBoundaryVNode(children[0]);
272
+ }
273
+ function isSingleRootReactiveChildBoundaryValue(value) {
274
+ if (value === null || value === void 0 || value === false) return true;
275
+ if (Array.isArray(value)) return value.length === 1 && isSingleRootReactiveChildBoundaryValue(value[0]);
276
+ if (isFragmentVNode(value)) {
277
+ const children = normalizeComponentChildren(value);
278
+ return children.length === 1 && isSingleRootReactiveChildBoundaryValue(children[0]);
279
+ }
280
+ return true;
281
+ }
282
+ function collectReactiveChildBoundaryVNodes(value, children) {
283
+ if (value === null || value === void 0 || value === false) return;
284
+ if (Array.isArray(value)) {
285
+ for (const child of value) collectReactiveChildBoundaryVNodes(child, children);
286
+ return;
287
+ }
288
+ if (isFragmentVNode(value)) {
289
+ collectReactiveChildBoundaryVNodes(value.props?.children ?? value.children, children);
290
+ return;
291
+ }
292
+ children.push(value);
293
+ }
294
+ function createReactiveChildBoundaryHost(el) {
295
+ const ownerDocument = el.ownerDocument;
296
+ return el.namespaceURI === SVG_NAMESPACE ? ownerDocument.createElementNS(SVG_NAMESPACE, "g") : ownerDocument.createElement("div");
297
+ }
298
+ function disposeReactiveChildBoundaryNodes(nodes) {
299
+ for (const node of nodes) {
300
+ if (node.parentNode) node.parentNode.removeChild(node);
301
+ if (node instanceof Element) teardownNodeSubtree(node);
302
+ }
303
+ }
304
+ function syncReactiveChildExpectedNodes(el, expectedNodes) {
305
+ const expectedNodeSet = new Set(expectedNodes);
306
+ for (let node = el.firstChild; node;) {
307
+ const next = node.nextSibling;
308
+ if (!expectedNodeSet.has(node)) {
309
+ if (node instanceof Element) teardownNodeSubtree(node);
310
+ el.removeChild(node);
311
+ }
312
+ node = next;
313
+ }
314
+ let anchor = el.firstChild;
315
+ for (const node of expectedNodes) {
316
+ if (node === anchor) {
317
+ anchor = anchor.nextSibling;
318
+ continue;
319
+ }
320
+ el.insertBefore(node, anchor);
321
+ anchor = node.nextSibling;
322
+ }
323
+ }
324
+ function commitReactiveChildBoundaryEntryNodes(el, entry) {
325
+ if (!entry.scope.needsDomUpdate) return entry.nodes;
326
+ if (entry.scope.vnode === null || entry.scope.vnode === void 0 || entry.scope.vnode === false) {
327
+ if (entry.nodes.length > 0) {
328
+ disposeReactiveChildBoundaryNodes(entry.nodes);
329
+ entry.nodes = [];
330
+ }
331
+ const dom = entry.scope.dom;
332
+ if (dom?.parentNode === el) {
333
+ if (dom instanceof Element) teardownNodeSubtree(dom);
334
+ el.removeChild(dom);
335
+ }
336
+ entry.scope.dom = void 0;
337
+ entry.scope.needsDomUpdate = false;
338
+ return entry.nodes;
339
+ }
340
+ if (!isSingleRootReactiveChildBoundaryValue(entry.scope.vnode)) {
341
+ const nextChildren = [];
342
+ collectReactiveChildBoundaryVNodes(entry.scope.vnode, nextChildren);
343
+ const host = createReactiveChildBoundaryHost(el);
344
+ for (const node of entry.nodes) host.appendChild(node);
345
+ updateElementChildren(host, nextChildren);
346
+ const nextNodes = Array.from(host.childNodes);
347
+ entry.scope.dom = void 0;
348
+ entry.scope.needsDomUpdate = false;
349
+ entry.nodes = nextNodes;
350
+ return nextNodes;
351
+ }
352
+ if (entry.nodes.length > 1) {
353
+ disposeReactiveChildBoundaryNodes(entry.nodes);
354
+ entry.nodes = [];
355
+ entry.scope.dom = void 0;
356
+ }
357
+ const nextDom = syncForItemDom(el, entry.scope, entry.scope.vnode ?? null);
358
+ if (!nextDom) {
359
+ entry.nodes = [];
360
+ entry.scope.needsDomUpdate = false;
361
+ return entry.nodes;
362
+ }
363
+ entry.nodes = [nextDom];
364
+ entry.scope.needsDomUpdate = false;
365
+ return entry.nodes;
366
+ }
367
+ function syncReactiveChildSequenceNodes(el, entries) {
368
+ const expectedNodes = [];
369
+ for (const entry of entries) {
370
+ if (entry.kind === "static") {
371
+ expectedNodes.push(...entry.nodes);
372
+ continue;
373
+ }
374
+ expectedNodes.push(...commitReactiveChildBoundaryEntryNodes(el, entry));
375
+ }
376
+ syncReactiveChildExpectedNodes(el, expectedNodes);
377
+ }
378
+ function setupReactiveScalarChild(el, source) {
379
+ let currentSource = source;
380
+ if (source.length === 1 && source[0]?.kind === "dynamic") {
381
+ let ownedTextNode = el.childNodes.length === 1 && el.firstChild?.nodeType === Node.TEXT_NODE ? el.firstChild : null;
382
+ let effectHandle = createFineGrainedEffect({
383
+ lane: "reactive",
384
+ compute: () => {
385
+ const currentSlot = currentSource[0];
386
+ if (!currentSlot || currentSlot.kind !== "dynamic") throw new Error("[Askr] Direct reactive text bindings require a single dynamic slot.");
387
+ const rawValue = currentSlot.compute();
388
+ return normalizeOwnedReactiveTextValue(rawValue) ?? rawValue;
389
+ },
390
+ commit: (value) => {
391
+ const normalized = normalizeOwnedReactiveTextValue(value);
392
+ if (normalized === null) {
393
+ ownedTextNode = null;
394
+ updateElementChildren(el, value);
395
+ return;
396
+ }
397
+ if (!ownedTextNode || el.childNodes.length !== 1 || el.firstChild !== ownedTextNode) {
398
+ updateElementChildren(el, normalized);
399
+ ownedTextNode = el.childNodes.length === 1 && el.firstChild?.nodeType === Node.TEXT_NODE ? el.firstChild : null;
400
+ }
401
+ if (!ownedTextNode) return;
402
+ if (ownedTextNode.data !== normalized) {
403
+ ownedTextNode.data = normalized;
404
+ incDevCounter("textNodeWrites");
405
+ }
406
+ },
407
+ onError: (err) => {
408
+ if (getRuntimeEnv().NODE_ENV !== "production") logger.warn("[Askr] Reactive child update failed:", err);
409
+ }
410
+ });
411
+ return {
412
+ cleanup: () => {
413
+ effectHandle?.cleanup();
414
+ effectHandle = null;
415
+ },
416
+ updateFn: (nextSource) => {
417
+ if (!effectHandle) return;
418
+ currentSource = nextSource;
419
+ effectHandle.updateCompute(() => {
420
+ const currentSlot = currentSource[0];
421
+ if (!currentSlot || currentSlot.kind !== "dynamic") throw new Error("[Askr] Direct reactive text bindings require a single dynamic slot.");
422
+ const rawValue = currentSlot.compute();
423
+ return normalizeOwnedReactiveTextValue(rawValue) ?? rawValue;
424
+ });
425
+ }
426
+ };
427
+ }
428
+ let effectHandle = createFineGrainedEffect({
429
+ lane: "reactive",
430
+ compute: () => currentSource.map((slot) => slot.kind === "static" ? slot.value : slot.compute()),
431
+ commit: (values) => {
432
+ if (!Array.isArray(values)) throw new Error("[Askr] Reactive scalar children must evaluate to a slot array.");
433
+ const normalized = normalizeReactiveScalarSequenceValues(values);
434
+ if (normalized) {
435
+ syncReactiveScalarTextNodes(el, values, normalized);
436
+ return;
437
+ }
438
+ const nextChildren = [];
439
+ collectReactiveChildValuesAsVNodes(values, nextChildren);
440
+ const host = createReactiveChildBoundaryHost(el);
441
+ for (let node = el.firstChild; node;) {
442
+ const next = node.nextSibling;
443
+ host.appendChild(node);
444
+ node = next;
445
+ }
446
+ updateElementChildren(host, nextChildren);
447
+ syncReactiveChildExpectedNodes(el, Array.from(host.childNodes));
448
+ },
449
+ equals: (previousValue, nextValue) => {
450
+ if (!Array.isArray(previousValue) || !Array.isArray(nextValue)) return false;
451
+ const previousNormalized = normalizeReactiveScalarSequenceValues(previousValue);
452
+ const nextNormalized = normalizeReactiveScalarSequenceValues(nextValue);
453
+ if (!previousNormalized || !nextNormalized) return false;
454
+ if (previousNormalized.length !== nextNormalized.length) return false;
455
+ for (let index = 0; index < previousNormalized.length; index += 1) if (previousNormalized[index] !== nextNormalized[index]) return false;
456
+ return true;
457
+ },
458
+ onError: (err) => {
459
+ if (getRuntimeEnv().NODE_ENV !== "production") logger.warn("[Askr] Reactive child update failed:", err);
460
+ }
461
+ });
462
+ return {
463
+ cleanup: () => {
464
+ effectHandle?.cleanup();
465
+ effectHandle = null;
466
+ },
467
+ updateFn: (nextSource) => {
468
+ if (!effectHandle) return;
469
+ currentSource = nextSource;
470
+ effectHandle.updateCompute(() => currentSource.map((slot) => slot.kind === "static" ? slot.value : slot.compute()));
471
+ }
472
+ };
473
+ }
474
+ function setupReactiveChildBoundary(el, childFn) {
475
+ let currentChildFn = childFn;
476
+ const entry = {
477
+ scope: createChildScope(getCurrentInstance(), `__reactive-child__:${reactiveChildScopeId += 1}`, () => {
478
+ syncReactiveChildExpectedNodes(el, commitReactiveChildBoundaryEntryNodes(el, entry));
479
+ }),
480
+ nodes: []
481
+ };
482
+ entry.scope.render(() => normalizeReactiveChildBoundaryVNode(currentChildFn()));
483
+ syncReactiveChildExpectedNodes(el, commitReactiveChildBoundaryEntryNodes(el, entry));
484
+ return {
485
+ cleanup: () => {
486
+ const dom = entry.scope.dom;
487
+ const nodes = entry.nodes;
488
+ disposeChildScope(entry.scope);
489
+ entry.nodes = [];
490
+ if (nodes.length > 0) {
491
+ disposeReactiveChildBoundaryNodes(nodes);
492
+ return;
493
+ }
494
+ if (dom?.parentNode === el) {
495
+ if (dom instanceof Element) teardownNodeSubtree(dom);
496
+ el.removeChild(dom);
497
+ }
498
+ },
499
+ updateFn: (nextValue) => {
500
+ currentChildFn = nextValue;
501
+ rerenderChildScope(entry.scope);
502
+ syncReactiveChildExpectedNodes(el, commitReactiveChildBoundaryEntryNodes(el, entry));
503
+ }
504
+ };
505
+ }
506
+ function setupReactiveChildBoundarySequence(el, source) {
507
+ let currentSource = source;
508
+ const parentInstance = getCurrentInstance();
509
+ const entries = [];
510
+ const dynamicEntries = [];
511
+ if (!currentSource.some((slot) => slot.kind === "dynamic")) throw new Error("[Askr] Reactive child boundary sequence requires at least one dynamic slot.");
512
+ const syncSequence = () => {
513
+ syncReactiveChildSequenceNodes(el, entries);
514
+ };
515
+ const parentNamespace = el.namespaceURI === SVG_NAMESPACE ? SVG_NAMESPACE : void 0;
516
+ for (let index = 0; index < currentSource.length; index += 1) {
517
+ const slot = currentSource[index];
518
+ if (!slot) continue;
519
+ if (slot.kind === "static-text") {
520
+ entries.push({
521
+ kind: "static",
522
+ nodes: [document.createTextNode(slot.value)]
523
+ });
524
+ continue;
525
+ }
526
+ if (slot.kind === "static-node") {
527
+ entries.push({
528
+ kind: "static",
529
+ nodes: materializeReactiveChildBoundaryNodes(slot.value, parentNamespace)
530
+ });
531
+ continue;
532
+ }
533
+ const dynamicEntry = {
534
+ kind: "dynamic",
535
+ scope: createChildScope(parentInstance, `__reactive-child-seq__:${reactiveChildScopeId += 1}`, syncSequence),
536
+ nodes: []
537
+ };
538
+ entries.push(dynamicEntry);
539
+ dynamicEntries.push({
540
+ index,
541
+ entry: dynamicEntry
542
+ });
543
+ }
544
+ for (const dynamicEntry of dynamicEntries) dynamicEntry.entry.scope.render(() => normalizeReactiveChildBoundaryVNode(currentSource[dynamicEntry.index].compute()));
545
+ syncSequence();
546
+ return {
547
+ cleanup: () => {
548
+ for (const dynamicEntry of dynamicEntries) {
549
+ const dom = dynamicEntry.entry.scope.dom;
550
+ const nodes = dynamicEntry.entry.nodes;
551
+ disposeChildScope(dynamicEntry.entry.scope);
552
+ if (nodes.length > 0) {
553
+ disposeReactiveChildBoundaryNodes(nodes);
554
+ continue;
555
+ }
556
+ if (dom?.parentNode === el) {
557
+ if (dom instanceof Element) teardownNodeSubtree(dom);
558
+ el.removeChild(dom);
559
+ }
560
+ }
561
+ for (const entry of entries) if (entry.kind === "static") disposeReactiveChildBoundaryNodes(entry.nodes);
562
+ },
563
+ updateFn: (nextValue) => {
564
+ currentSource = nextValue;
565
+ for (const dynamicEntry of dynamicEntries) rerenderChildScope(dynamicEntry.entry.scope);
566
+ syncSequence();
567
+ }
568
+ };
569
+ }
570
+ function syncReactiveScalarChild(el, children) {
571
+ const reactiveChildSource = getReactiveScalarChildSource(children);
572
+ const reactiveChildBoundary = getSingleReactiveChildBoundarySource(children);
573
+ const reactiveChildBoundarySequence = getReactiveChildBoundarySequenceSource(children);
574
+ const existingReactiveEntry = elementReactivePropsCleanup.get(el)?.get(REACTIVE_CHILDREN_KEY);
575
+ if (!reactiveChildSource && !reactiveChildBoundary && !reactiveChildBoundarySequence) {
576
+ if (existingReactiveEntry) {
577
+ existingReactiveEntry.cleanup();
578
+ const cleanupMap = elementReactivePropsCleanup.get(el);
579
+ cleanupMap?.delete(REACTIVE_CHILDREN_KEY);
580
+ if (cleanupMap && cleanupMap.size === 0) elementReactivePropsCleanup.delete(el);
581
+ }
582
+ return false;
583
+ }
584
+ if (reactiveChildSource && !reactiveChildBoundarySequence) {
585
+ if (existingReactiveEntry && Array.isArray(existingReactiveEntry.fnRef) && areReactiveScalarChildSourcesEqual(existingReactiveEntry.fnRef, reactiveChildSource)) return true;
586
+ if (existingReactiveEntry?.updateFn && Array.isArray(existingReactiveEntry.fnRef)) {
587
+ existingReactiveEntry.updateFn(reactiveChildSource);
588
+ existingReactiveEntry.fnRef = reactiveChildSource;
589
+ return true;
590
+ }
591
+ existingReactiveEntry?.cleanup();
592
+ try {
593
+ const reactive = setupReactiveScalarChild(el, reactiveChildSource);
594
+ getOrCreateElementReactiveCleanupMap(el).set(REACTIVE_CHILDREN_KEY, {
595
+ cleanup: reactive.cleanup,
596
+ updateFn: (nextValue) => {
597
+ reactive.updateFn(nextValue);
598
+ },
599
+ fnRef: reactiveChildSource
600
+ });
601
+ return true;
602
+ } catch (error) {
603
+ if (!reactiveChildBoundary && !reactiveChildBoundarySequence) throw error;
604
+ }
605
+ }
606
+ if (reactiveChildBoundarySequence) {
607
+ if (existingReactiveEntry && Array.isArray(existingReactiveEntry.fnRef) && areReactiveChildBoundarySequenceSourcesEqual(existingReactiveEntry.fnRef, reactiveChildBoundarySequence)) return true;
608
+ if (existingReactiveEntry?.updateFn && Array.isArray(existingReactiveEntry.fnRef) && canUpdateReactiveChildBoundarySequenceSource(existingReactiveEntry.fnRef, reactiveChildBoundarySequence)) {
609
+ existingReactiveEntry.updateFn(reactiveChildBoundarySequence);
610
+ existingReactiveEntry.fnRef = reactiveChildBoundarySequence;
611
+ return true;
612
+ }
613
+ existingReactiveEntry?.cleanup();
614
+ const reactive = setupReactiveChildBoundarySequence(el, reactiveChildBoundarySequence);
615
+ getOrCreateElementReactiveCleanupMap(el).set(REACTIVE_CHILDREN_KEY, {
616
+ cleanup: reactive.cleanup,
617
+ updateFn: reactive.updateFn,
618
+ fnRef: reactiveChildBoundarySequence
619
+ });
620
+ return true;
621
+ }
622
+ if (existingReactiveEntry?.fnRef === reactiveChildBoundary) return true;
623
+ if (existingReactiveEntry?.updateFn && !Array.isArray(existingReactiveEntry.fnRef)) {
624
+ existingReactiveEntry.updateFn(reactiveChildBoundary);
625
+ existingReactiveEntry.fnRef = reactiveChildBoundary;
626
+ return true;
627
+ }
628
+ existingReactiveEntry?.cleanup();
629
+ if (!reactiveChildBoundary) return false;
630
+ const reactive = setupReactiveChildBoundary(el, reactiveChildBoundary);
631
+ getOrCreateElementReactiveCleanupMap(el).set(REACTIVE_CHILDREN_KEY, {
632
+ cleanup: reactive.cleanup,
633
+ updateFn: reactive.updateFn,
634
+ fnRef: reactiveChildBoundary
635
+ });
636
+ return true;
637
+ }
638
+ const vnodeComponentInstances = /* @__PURE__ */ new WeakMap();
639
+ function getVNodeComponentInstance(node) {
640
+ if (typeof node !== "object" || node === null) return;
641
+ return vnodeComponentInstances.get(node) ?? node.__instance;
642
+ }
643
+ function setVNodeComponentInstance(node, instance) {
644
+ if (typeof node !== "object" || node === null) return;
645
+ const objectNode = node;
646
+ if (Object.prototype.hasOwnProperty.call(objectNode, "__instance")) try {
647
+ objectNode.__instance = instance;
648
+ return;
649
+ } catch {}
650
+ if (Object.isExtensible(objectNode)) try {
651
+ objectNode.__instance = instance;
652
+ return;
653
+ } catch {}
654
+ vnodeComponentInstances.set(objectNode, instance);
655
+ }
656
+ const IS_DOM_AVAILABLE = typeof document !== "undefined";
657
+ const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
658
+ function resolveChildNamespace(type, parentNamespace) {
659
+ if (type === "svg") return SVG_NAMESPACE;
660
+ if (parentNamespace === SVG_NAMESPACE && type !== "foreignObject") return SVG_NAMESPACE;
661
+ }
662
+ function createElementForNamespace(type, parentNamespace) {
663
+ const namespace = resolveChildNamespace(type, parentNamespace);
664
+ return namespace ? document.createElementNS(namespace, type) : document.createElement(type);
665
+ }
666
+ function getHydrationSkipBoundary(el) {
667
+ return el.closest("[data-skip-hydrate=\"true\"]");
668
+ }
669
+ function isHydrationSkipped(el) {
670
+ return getHydrationSkipBoundary(el) !== null;
671
+ }
672
+ function clearHydrationDeferredSubtree(el) {
673
+ const boundary = getHydrationSkipBoundary(el);
674
+ if (!boundary) return;
675
+ if (boundary === el) {
676
+ removeAllListeners(el);
677
+ removeElementReactiveProps(el);
678
+ }
679
+ }
680
+ let fallbackComponentInstanceId = 0;
681
+ function nextComponentInstanceId() {
682
+ const key = "__COMPONENT_INSTANCE_ID";
683
+ try {
684
+ incDevCounter(key);
685
+ const n = getDevValue(key);
686
+ if (typeof n === "number" && Number.isFinite(n)) return `comp-${n}`;
687
+ } catch {}
688
+ fallbackComponentInstanceId++;
689
+ return `comp-${fallbackComponentInstanceId}`;
690
+ }
691
+ /**
692
+ * Add an event listener to an element with tracking
693
+ * Uses event delegation when enabled (opt-out model)
694
+ */
695
+ function addTrackedListener(el, eventName, handler) {
696
+ if (isEventDelegationEnabled() && isDelegatedEvent(eventName)) {
697
+ addDelegatedListener(el, eventName, handler, handler, void 0);
698
+ if (isBenchMetricScopeActive("coldCreate")) recordBenchCounter("listenerBindings");
699
+ return;
700
+ }
701
+ const options = getPassiveOptions(eventName);
702
+ const mutableHandler = createMutableWrappedHandler(handler, true);
703
+ const trackedHandler = mutableHandler.handler;
704
+ if (options !== void 0) el.addEventListener(eventName, trackedHandler, options);
705
+ else el.addEventListener(eventName, trackedHandler);
706
+ incDevCounter("listenerAdds");
707
+ if (!elementListeners.has(el)) elementListeners.set(el, /* @__PURE__ */ new Map());
708
+ elementListeners.get(el).set(eventName, {
709
+ handler: trackedHandler,
710
+ original: handler,
711
+ options,
712
+ isDelegated: false,
713
+ updateHandler: mutableHandler?.updateHandler
714
+ });
715
+ if (isBenchMetricScopeActive("coldCreate")) recordBenchCounter("listenerBindings");
716
+ }
717
+ function markReactivePropsDirtySource(source) {
718
+ markFineGrainedEffectsDirtySource(source);
719
+ }
720
+ /**
721
+ * Set up a reactive prop that re-evaluates when its dependencies change
722
+ * Returns a cleanup function to unsubscribe
723
+ */
724
+ function setupReactiveProp(el, propName, propFn, tagName) {
725
+ const descriptor = {
726
+ el,
727
+ propName,
728
+ propFn,
729
+ tagName,
730
+ lastClassTokens: null
731
+ };
732
+ let effectHandle = null;
733
+ reactivePropRegistry.add(descriptor);
734
+ effectHandle = createFineGrainedEffect({
735
+ lane: "reactive",
736
+ compute: () => descriptor.propFn(),
737
+ commit: (value, previousValue) => {
738
+ incrementPerfMetric("reactivePropReevaluations");
739
+ applyPropValue(el, propName, value, tagName, previousValue, descriptor);
740
+ },
741
+ equals: (previousValue, nextValue) => {
742
+ if (Object.is(previousValue, nextValue)) {
743
+ incrementPerfMetric("skippedDomPropWrites");
744
+ return true;
745
+ }
746
+ return false;
747
+ },
748
+ onError: (err) => {
749
+ if (getRuntimeEnv().NODE_ENV !== "production") logger.warn("[Askr] Reactive prop update failed:", err);
750
+ }
751
+ });
752
+ if (isBenchMetricScopeActive("coldCreate")) recordBenchCounter("reactivePropsMounted");
753
+ const cleanup = () => {
754
+ reactivePropRegistry.delete(descriptor);
755
+ effectHandle?.cleanup();
756
+ effectHandle = null;
757
+ };
758
+ const updateFn = (nextFn) => {
759
+ if (!effectHandle) return;
760
+ descriptor.propFn = nextFn;
761
+ try {
762
+ effectHandle.updateCompute(nextFn);
763
+ } catch (err) {
764
+ if (getRuntimeEnv().NODE_ENV !== "production") logger.warn("[Askr] Reactive prop update failed:", err);
765
+ }
766
+ };
767
+ return {
768
+ cleanup,
769
+ updateFn
770
+ };
771
+ }
772
+ /**
773
+ * Apply a prop value to an element (helper for reactive props)
774
+ */
775
+ function applyPropValue(el, key, value, tagName, previousValue, descriptor) {
776
+ if (value === void 0 || value === null || value === false) {
777
+ if (key === "class" || key === "className") {
778
+ const previousTokens = descriptor?.lastClassTokens;
779
+ if (previousTokens && previousTokens.length > 0) {
780
+ el.classList.remove(...previousTokens);
781
+ incrementPerfMetric("classListPatchOps");
782
+ } else writeElementClassName(el, "");
783
+ if (descriptor) descriptor.lastClassTokens = [];
784
+ } else if (key === "value") applyFormControlProp(el, key, "", tagName);
785
+ else if (key === "checked") applyFormControlProp(el, key, false, tagName);
786
+ else if (key === "style") applyStylePropValue(el, null);
787
+ else el.removeAttribute(key);
788
+ return;
789
+ }
790
+ if (key === "class" || key === "className") applyClassPropValue(el, value, previousValue, descriptor);
791
+ else if (key === "style") applyStylePropValue(el, value);
792
+ else if (key === "value" || key === "checked") applyFormControlProp(el, key, value, tagName);
793
+ else el.setAttribute(key, String(value));
794
+ }
795
+ function normalizeStylePropertyName(propertyName) {
796
+ if (propertyName.startsWith("--")) return propertyName;
797
+ return propertyName.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`);
798
+ }
799
+ function collectCurrentStyleEntries(el) {
800
+ const entries = /* @__PURE__ */ new Map();
801
+ const style = el.style;
802
+ if (!style) return entries;
803
+ for (let index = 0; index < style.length; index += 1) {
804
+ const propertyName = style.item(index);
805
+ entries.set(propertyName, style.getPropertyValue(propertyName));
806
+ }
807
+ return entries;
808
+ }
809
+ function normalizeStyleEntries(value) {
810
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
811
+ const entries = /* @__PURE__ */ new Map();
812
+ for (const [key, entryValue] of Object.entries(value)) {
813
+ if (entryValue === void 0 || entryValue === null || entryValue === false) continue;
814
+ entries.set(normalizeStylePropertyName(key), String(entryValue));
815
+ }
816
+ return entries;
817
+ }
818
+ function applyStylePropValue(el, value) {
819
+ const style = el.style;
820
+ if (!style) {
821
+ if (value === null || value === void 0 || value === false) {
822
+ el.removeAttribute("style");
823
+ return;
824
+ }
825
+ el.setAttribute("style", String(value));
826
+ return;
827
+ }
828
+ if (value === null || value === void 0 || value === false) {
829
+ if (!el.getAttribute("style")) {
830
+ incrementPerfMetric("skippedDomPropWrites");
831
+ return;
832
+ }
833
+ style.cssText = "";
834
+ el.removeAttribute("style");
835
+ return;
836
+ }
837
+ if (typeof value === "string") {
838
+ if ((el.getAttribute("style") ?? "") === value) {
839
+ incrementPerfMetric("skippedDomPropWrites");
840
+ return;
841
+ }
842
+ style.cssText = value;
843
+ return;
844
+ }
845
+ const nextEntries = normalizeStyleEntries(value);
846
+ if (!nextEntries) {
847
+ const nextText = String(value);
848
+ if ((el.getAttribute("style") ?? "") === nextText) {
849
+ incrementPerfMetric("skippedDomPropWrites");
850
+ return;
851
+ }
852
+ style.cssText = nextText;
853
+ return;
854
+ }
855
+ const previousEntries = collectCurrentStyleEntries(el);
856
+ let didWrite = false;
857
+ for (const [propertyName] of previousEntries) {
858
+ if (nextEntries.has(propertyName)) continue;
859
+ style.removeProperty(propertyName);
860
+ didWrite = true;
861
+ }
862
+ for (const [propertyName, propertyValue] of nextEntries) {
863
+ if (previousEntries.get(propertyName) === propertyValue) continue;
864
+ style.setProperty(propertyName, propertyValue);
865
+ didWrite = true;
866
+ }
867
+ if (!didWrite) incrementPerfMetric("skippedDomPropWrites");
868
+ }
869
+ function tokenizeClassValue(value) {
870
+ if (typeof value !== "string") return null;
871
+ const trimmed = value.trim();
872
+ if (trimmed.length === 0) return [];
873
+ return trimmed.split(/\s+/);
874
+ }
875
+ function patchClassList(el, previousTokens, nextTokens) {
876
+ if (previousTokens.length === nextTokens.length) {
877
+ let identical = true;
878
+ for (let index = 0; index < previousTokens.length; index += 1) if (previousTokens[index] !== nextTokens[index]) {
879
+ identical = false;
880
+ break;
881
+ }
882
+ if (identical) return;
883
+ }
884
+ if (previousTokens.length === 0) {
885
+ if (nextTokens.length === 0) return;
886
+ el.classList.add(...nextTokens);
887
+ incrementPerfMetric("classListPatchOps");
888
+ return;
889
+ }
890
+ if (nextTokens.length === 0) {
891
+ el.classList.remove(...previousTokens);
892
+ incrementPerfMetric("classListPatchOps");
893
+ return;
894
+ }
895
+ if (previousTokens.length === 1 && nextTokens.length === 1) {
896
+ el.classList.remove(previousTokens[0]);
897
+ el.classList.add(nextTokens[0]);
898
+ incrementPerfMetric("classListPatchOps");
899
+ return;
900
+ }
901
+ const nextSet = new Set(nextTokens);
902
+ const previousSet = new Set(previousTokens);
903
+ for (const token of previousTokens) if (!nextSet.has(token)) el.classList.remove(token);
904
+ for (const token of nextTokens) if (!previousSet.has(token)) el.classList.add(token);
905
+ incrementPerfMetric("classListPatchOps");
906
+ }
907
+ function applyClassPropValue(el, value, previousValue, descriptor) {
908
+ const nextString = String(value);
909
+ const nextTokens = tokenizeClassValue(nextString);
910
+ const previousTokens = descriptor?.lastClassTokens ?? tokenizeClassValue(previousValue);
911
+ if (nextTokens && previousTokens) {
912
+ patchClassList(el, previousTokens, nextTokens);
913
+ if (descriptor) descriptor.lastClassTokens = nextTokens;
914
+ return;
915
+ }
916
+ writeElementClassName(el, nextString);
917
+ if (descriptor) descriptor.lastClassTokens = nextTokens;
918
+ }
919
+ /**
920
+ * Apply attributes and event listeners to an element from props
921
+ */
922
+ function applyPropsToElement(el, props, tagName) {
923
+ if (isHydrationSkipped(el)) return;
924
+ for (const key in props) {
925
+ const value = props[key];
926
+ if (key === "ref") {
927
+ applyRef(el, value);
928
+ continue;
929
+ }
930
+ if (isSkippedProp(key)) continue;
931
+ if (value === void 0 || value === null || value === false) continue;
932
+ const eventName = parseEventName(key);
933
+ if (eventName) {
934
+ addTrackedListener(el, eventName, value);
935
+ continue;
936
+ }
937
+ if (typeof value === "function" && !eventName && key !== "ref") {
938
+ const reactive = setupReactiveProp(el, key, value, tagName);
939
+ if (!elementReactivePropsCleanup.has(el)) elementReactivePropsCleanup.set(el, /* @__PURE__ */ new Map());
940
+ elementReactivePropsCleanup.get(el).set(key, {
941
+ cleanup: reactive.cleanup,
942
+ updateFn: (nextValue) => {
943
+ reactive.updateFn(nextValue);
944
+ },
945
+ fnRef: value
946
+ });
947
+ continue;
948
+ }
949
+ if (key === "class" || key === "className") writeElementClassName(el, String(value));
950
+ else if (key === "style") applyStylePropValue(el, value);
951
+ else if (key === "value" || key === "checked") applyFormControlProp(el, key, value, tagName);
952
+ else el.setAttribute(key, String(value));
953
+ }
954
+ }
955
+ function applyRef(el, ref) {
956
+ const r = ref;
957
+ if (!r) return;
958
+ if (typeof r === "function") {
959
+ r(el);
960
+ return;
961
+ }
962
+ if (Object.isExtensible(r)) r.current = el;
963
+ }
964
+ function getRenderedAttributeName(el, propName) {
965
+ let attributeName = propName;
966
+ if (propName === "className") attributeName = "class";
967
+ else if (propName === "htmlFor") attributeName = "for";
968
+ return el.namespaceURI === SVG_NAMESPACE ? attributeName : attributeName.toLowerCase();
969
+ }
970
+ function removeStaleAttributes(el, vnode, props) {
971
+ const desiredAttributes = /* @__PURE__ */ new Set();
972
+ if (extractKey(vnode) !== void 0) desiredAttributes.add("data-key");
973
+ for (const propName in props) {
974
+ if (isSkippedProp(propName)) continue;
975
+ if (parseEventName(propName)) continue;
976
+ const value = props[propName];
977
+ if (value === void 0 || value === null || value === false) continue;
978
+ desiredAttributes.add(getRenderedAttributeName(el, propName));
979
+ }
980
+ for (const attribute of Array.from(el.attributes)) if (!desiredAttributes.has(getRenderedAttributeName(el, attribute.name))) el.removeAttribute(attribute.name);
981
+ }
982
+ /**
983
+ * Apply value/checked props to form controls
984
+ */
985
+ function applyFormControlProp(el, key, value, tagName) {
986
+ if (key === "value") if (tagNamesEqualIgnoreCase(tagName, "input") || tagNamesEqualIgnoreCase(tagName, "textarea") || tagNamesEqualIgnoreCase(tagName, "select")) {
987
+ el.value = String(value);
988
+ el.setAttribute("value", String(value));
989
+ } else el.setAttribute("value", String(value));
990
+ else if (key === "checked") if (tagNamesEqualIgnoreCase(tagName, "input")) {
991
+ const checked = Boolean(value);
992
+ el.checked = checked;
993
+ if (checked) el.setAttribute("checked", "");
994
+ else el.removeAttribute("checked");
995
+ } else if (value) el.setAttribute("checked", "");
996
+ else el.removeAttribute("checked");
997
+ }
998
+ /**
999
+ * Materialize vnode key as data-key attribute
1000
+ */
1001
+ function materializeKey(el, vnode, props) {
1002
+ const rawKey = vnode.key ?? props?.key;
1003
+ const vnodeKey = rawKey === null || rawKey === void 0 ? void 0 : typeof rawKey === "symbol" ? String(rawKey) : rawKey;
1004
+ if (vnodeKey !== void 0) {
1005
+ const nextKey = String(vnodeKey);
1006
+ if (el.getAttribute("data-key") !== nextKey) el.setAttribute("data-key", nextKey);
1007
+ }
1008
+ }
1009
+ function inheritComponentKey(target, source) {
1010
+ const inheritedKey = extractKey(source);
1011
+ if (inheritedKey === void 0 || extractKey(target) !== void 0) return target;
1012
+ target.key = inheritedKey;
1013
+ if (typeof target.type === "string") {
1014
+ if (!target.props) target.props = {};
1015
+ const props = target.props;
1016
+ if (props["data-key"] === void 0) props["data-key"] = String(inheritedKey);
1017
+ }
1018
+ return target;
1019
+ }
1020
+ /**
1021
+ * Warn about missing keys on dynamic lists (dev only)
1022
+ */
1023
+ function warnMissingKeys(children) {
1024
+ if (getRuntimeEnv().NODE_ENV === "production") return;
1025
+ let hasElements = false;
1026
+ let hasKeys = false;
1027
+ for (const item of children) if (typeof item === "object" && item !== null && "type" in item) {
1028
+ if (item.type === __FOR_BOUNDARY__) continue;
1029
+ hasElements = true;
1030
+ if ((item.key ?? item.props?.key) !== void 0) {
1031
+ hasKeys = true;
1032
+ break;
1033
+ }
1034
+ }
1035
+ if (hasElements && !hasKeys) {
1036
+ const inst = getCurrentInstance();
1037
+ const warnings = inst ? inst.devWarningsEmitted ??= /* @__PURE__ */ new Set() : null;
1038
+ if (warnings?.has("missing-keys")) return;
1039
+ warnings?.add("missing-keys");
1040
+ try {
1041
+ const name = inst?.fn?.name || "<anonymous>";
1042
+ logger.warn(`Missing keys on dynamic lists in ${name}. Each child in a list should have a unique "key" prop.`);
1043
+ } catch {
1044
+ logger.warn("Missing keys on dynamic lists. Each child in a list should have a unique \"key\" prop.");
1045
+ }
1046
+ }
1047
+ }
1048
+ function hasStaticChildrenMarker(children) {
1049
+ return children[STATIC_CHILDREN] === true;
1050
+ }
1051
+ function maybeWarnMissingKeys(children) {
1052
+ if (!hasStaticChildrenMarker(children)) warnMissingKeys(children);
1053
+ }
1054
+ /**
1055
+ * Create a DOM node from a VNode
1056
+ */
1057
+ function createDOMNode(node, parentNamespace) {
1058
+ if (!IS_DOM_AVAILABLE) {
1059
+ if (getRuntimeEnv().NODE_ENV !== "production") try {
1060
+ logger.warn("[Askr] createDOMNode called in non-DOM environment");
1061
+ } catch {}
1062
+ return null;
1063
+ }
1064
+ if (typeof node === "string") {
1065
+ if (isBenchMetricScopeActive("coldCreate")) recordBenchCounter("domNodesCreated");
1066
+ return document.createTextNode(node);
1067
+ }
1068
+ if (typeof node === "number") {
1069
+ if (isBenchMetricScopeActive("coldCreate")) recordBenchCounter("domNodesCreated");
1070
+ return document.createTextNode(String(node));
1071
+ }
1072
+ if (!node) return null;
1073
+ if (Array.isArray(node)) {
1074
+ maybeWarnMissingKeys(node);
1075
+ const fragment = document.createDocumentFragment();
1076
+ for (const child of node) {
1077
+ const dom = createDOMNode(child, parentNamespace);
1078
+ if (dom) fragment.appendChild(dom);
1079
+ }
1080
+ return fragment;
1081
+ }
1082
+ if (typeof node === "object" && node !== null && "type" in node) {
1083
+ const type = node.type;
1084
+ const props = node.props || {};
1085
+ if (typeof type === "string") return createIntrinsicElement(node, type, props, parentNamespace);
1086
+ if (typeof type === "function") return createComponentElement(node, type, props, parentNamespace);
1087
+ if (type === __FOR_BOUNDARY__) return createForBoundary(node, props, parentNamespace);
1088
+ if (typeof type === "symbol" && (type === Fragment || String(type) === "Symbol(Fragment)")) return createFragmentElement(node, props, parentNamespace);
1089
+ }
1090
+ return null;
1091
+ }
1092
+ function tryGetStaticCreateChildShape(children) {
1093
+ if (children === null || children === void 0 || children === false) return { textContent: null };
1094
+ if (typeof children === "string" || typeof children === "number") return { textContent: String(children) };
1095
+ if (Array.isArray(children) && children.length === 1) {
1096
+ const child = children[0];
1097
+ if (child === null || child === void 0 || child === false) return { textContent: null };
1098
+ if (typeof child === "string" || typeof child === "number") return { textContent: String(child) };
1099
+ }
1100
+ return null;
1101
+ }
1102
+ function isStaticCreateScalarValue(value) {
1103
+ const valueType = typeof value;
1104
+ return valueType === "string" || valueType === "number" || valueType === "boolean";
1105
+ }
1106
+ function tryGetStaticCreateFastPathShape(props, children) {
1107
+ const childShape = tryGetStaticCreateChildShape(children);
1108
+ if (!childShape) return null;
1109
+ for (const key in props) {
1110
+ if (key === "ref") return null;
1111
+ if (isSkippedProp(key)) continue;
1112
+ const value = props[key];
1113
+ if (value === void 0 || value === null || value === false) continue;
1114
+ if (parseEventName(key) || !isStaticCreateScalarValue(value)) return null;
1115
+ }
1116
+ return childShape;
1117
+ }
1118
+ function applyStaticScalarPropsToElement(el, props) {
1119
+ for (const key in props) {
1120
+ if (isSkippedProp(key)) continue;
1121
+ const value = props[key];
1122
+ if (value === void 0 || value === null || value === false) continue;
1123
+ if (key === "class" || key === "className") writeElementClassName(el, String(value));
1124
+ else if (key === "style") applyStylePropValue(el, value);
1125
+ else if (key === "value" || key === "checked") el[key] = value;
1126
+ else el.setAttribute(key, String(value));
1127
+ }
1128
+ }
1129
+ /**
1130
+ * Create an intrinsic DOM element (div, span, etc.)
1131
+ */
1132
+ function createIntrinsicElement(node, type, props, parentNamespace) {
1133
+ const children = props.children ?? node.children;
1134
+ const elementNamespace = resolveChildNamespace(type, parentNamespace);
1135
+ const el = createElementForNamespace(type, parentNamespace);
1136
+ if (isBenchMetricScopeActive("coldCreate")) recordBenchCounter("domNodesCreated");
1137
+ materializeKey(el, node, props);
1138
+ const staticCreateFastPath = tryGetStaticCreateFastPathShape(props, children);
1139
+ if (staticCreateFastPath) {
1140
+ applyStaticScalarPropsToElement(el, props);
1141
+ if (staticCreateFastPath.textContent !== null) {
1142
+ el.textContent = staticCreateFastPath.textContent;
1143
+ if (isBenchMetricScopeActive("coldCreate")) recordBenchCounter("domNodesCreated");
1144
+ }
1145
+ return el;
1146
+ }
1147
+ applyPropsToElement(el, props, type);
1148
+ if (children !== null && children !== void 0) {
1149
+ const controlBoundaryVNode = getDirectControlBoundaryVNode(children);
1150
+ if (controlBoundaryVNode) {
1151
+ const controlState = getControlBoundaryState(controlBoundaryVNode);
1152
+ if (!controlState) throw new Error("[createIntrinsicElement] Control boundary missing internal state");
1153
+ registerControlBoundaryCommitOwner(el, controlState);
1154
+ }
1155
+ if (syncReactiveScalarChild(el, children)) return el;
1156
+ if (Array.isArray(children)) {
1157
+ maybeWarnMissingKeys(children);
1158
+ if (children.length > 1) {
1159
+ const childFrag = document.createDocumentFragment();
1160
+ for (const child of children) {
1161
+ const dom = createDOMNode(child, elementNamespace);
1162
+ if (dom) childFrag.appendChild(dom);
1163
+ }
1164
+ el.appendChild(childFrag);
1165
+ } else if (children.length === 1) {
1166
+ const dom = createDOMNode(children[0], elementNamespace);
1167
+ if (dom) el.appendChild(dom);
1168
+ }
1169
+ } else {
1170
+ const dom = createDOMNode(children, elementNamespace);
1171
+ if (dom) el.appendChild(dom);
1172
+ }
1173
+ }
1174
+ return el;
1175
+ }
1176
+ function findHostInstanceByType(host, type) {
1177
+ const instances = host.__ASKR_INSTANCES;
1178
+ if (instances && instances.length > 0) for (let index = instances.length - 1; index >= 0; index -= 1) {
1179
+ const instance = instances[index];
1180
+ if (instance.fn === type) return instance;
1181
+ }
1182
+ return host.__ASKR_INSTANCE?.fn === type ? host.__ASKR_INSTANCE : null;
1183
+ }
1184
+ function materializeComponentResultNode(childInstance, result, parentNamespace) {
1185
+ const dom = createDOMNode(result, parentNamespace);
1186
+ if (dom instanceof Element) {
1187
+ mountInstanceInline(childInstance, dom);
1188
+ return dom;
1189
+ }
1190
+ if (!dom) {
1191
+ const placeholder = document.createComment("");
1192
+ try {
1193
+ placeholder.__ASKR_INSTANCE = childInstance;
1194
+ } catch {}
1195
+ childInstance._placeholder = placeholder;
1196
+ childInstance.mounted = true;
1197
+ childInstance.notifyUpdate = childInstance._enqueueRun;
1198
+ childInstance.target = null;
1199
+ return placeholder;
1200
+ }
1201
+ const host = document.createElement("div");
1202
+ host.appendChild(dom);
1203
+ host.__ASKR_WRAPPER_HOST = true;
1204
+ mountInstanceInline(childInstance, host);
1205
+ return host;
1206
+ }
1207
+ function resolveNestedComponentResult(result, snapshot) {
1208
+ let currentResult = result;
1209
+ let activeSnapshot = snapshot;
1210
+ let depth = 0;
1211
+ while (_isDOMElement(currentResult) && typeof currentResult.type === "function" && depth < 16) {
1212
+ const nestedSnapshot = getVNodeContextFrame(currentResult) ?? activeSnapshot;
1213
+ const nestedInstance = createComponentInstance(nextComponentInstanceId(), currentResult.type, currentResult.props ?? {}, null);
1214
+ if (nestedSnapshot) nestedInstance.ownerFrame = nestedSnapshot;
1215
+ const nextResult = withContext(nestedSnapshot ?? null, () => renderComponentInline(nestedInstance));
1216
+ cleanupComponent(nestedInstance);
1217
+ if (nextResult instanceof Promise) throw new Error("Async components are not supported. Components must return synchronously.");
1218
+ activeSnapshot = nestedSnapshot ?? null;
1219
+ currentResult = nextResult;
1220
+ depth += 1;
1221
+ }
1222
+ return currentResult;
1223
+ }
1224
+ function resolveWrapperHostResult(host, result, snapshot) {
1225
+ let currentResult = result;
1226
+ let activeSnapshot = snapshot;
1227
+ let depth = 0;
1228
+ while (_isDOMElement(currentResult) && typeof currentResult.type === "function" && depth < 16) {
1229
+ const nestedSnapshot = getVNodeContextFrame(currentResult) ?? activeSnapshot;
1230
+ const nestedInstance = findHostInstanceByType(host, currentResult.type);
1231
+ if (!nestedInstance) break;
1232
+ nestedInstance.props = (currentResult.props ?? {}) || {};
1233
+ if (nestedSnapshot) nestedInstance.ownerFrame = nestedSnapshot;
1234
+ const nextResult = withContext(nestedSnapshot ?? null, () => renderComponentInline(nestedInstance));
1235
+ if (nextResult instanceof Promise) throw new Error("Async components are not supported. Components must return synchronously.");
1236
+ warnUnusedStateReads(nestedInstance);
1237
+ activeSnapshot = nestedSnapshot ?? null;
1238
+ currentResult = nextResult;
1239
+ depth += 1;
1240
+ }
1241
+ return markVNodeTreeWithContextFrame(currentResult, activeSnapshot);
1242
+ }
1243
+ function isFragmentVNode(node) {
1244
+ return _isDOMElement(node) && typeof node.type === "symbol" && (node.type === Fragment || String(node.type) === "Symbol(askr.fragment)");
1245
+ }
1246
+ function normalizeComponentChildren(result) {
1247
+ if (result === null || result === void 0 || result === false) return [];
1248
+ if (Array.isArray(result)) return result;
1249
+ if (isFragmentVNode(result)) {
1250
+ const children = result.props?.children ?? result.children ?? [];
1251
+ return Array.isArray(children) ? children : [children];
1252
+ }
1253
+ return [result];
1254
+ }
1255
+ function syncComponentElement(currentDom, node, type, props, parentNamespace) {
1256
+ const existingHost = currentDom instanceof Element ? currentDom : null;
1257
+ const existingInstance = existingHost ? findHostInstanceByType(existingHost, type) : null;
1258
+ if (!existingHost || !existingInstance || existingInstance.fn !== type) return null;
1259
+ const snapshot = getVNodeContextFrame(node) || getCurrentContextFrame() || existingInstance.ownerFrame || null;
1260
+ existingInstance.props = props || {};
1261
+ if (snapshot) existingInstance.ownerFrame = snapshot;
1262
+ const result = withContext(snapshot, () => renderComponentInline(existingInstance));
1263
+ if (result instanceof Promise) throw new Error("Async components are not supported. Components must return synchronously.");
1264
+ const scopedResult = markVNodeTreeWithContextFrame(result, snapshot ?? null);
1265
+ if (existingHost.__ASKR_WRAPPER_HOST) {
1266
+ updateElementChildren(existingHost, normalizeComponentChildren(resolveWrapperHostResult(existingHost, scopedResult, snapshot ?? null)));
1267
+ warnUnusedStateReads(existingInstance);
1268
+ return existingHost;
1269
+ }
1270
+ if (scopedResult && typeof scopedResult === "object" && "type" in scopedResult && typeof scopedResult.type === "string" && tagNamesEqualIgnoreCase(existingHost.tagName, scopedResult.type)) {
1271
+ withContext(snapshot, () => {
1272
+ updateElementFromVnode(existingHost, inheritComponentKey(scopedResult, node), true);
1273
+ materializeKey(existingHost, node, props);
1274
+ });
1275
+ warnUnusedStateReads(existingInstance);
1276
+ return existingHost;
1277
+ }
1278
+ const resolvedResult = resolveNestedComponentResult(scopedResult, snapshot ?? null);
1279
+ if (_isDOMElement(resolvedResult) && typeof resolvedResult.type === "string" && tagNamesEqualIgnoreCase(existingHost.tagName, resolvedResult.type)) {
1280
+ withContext(snapshot, () => {
1281
+ updateElementFromVnode(existingHost, inheritComponentKey(resolvedResult, node), true);
1282
+ materializeKey(existingHost, node, props);
1283
+ });
1284
+ warnUnusedStateReads(existingInstance);
1285
+ return existingHost;
1286
+ }
1287
+ const nextDom = materializeComponentResultNode(existingInstance, scopedResult, parentNamespace);
1288
+ if (nextDom !== existingHost && existingHost.parentNode) {
1289
+ existingHost.parentNode.replaceChild(nextDom, existingHost);
1290
+ cleanupDetachedComponentHost(existingHost, existingInstance);
1291
+ }
1292
+ warnUnusedStateReads(existingInstance);
1293
+ return nextDom;
1294
+ }
1295
+ function createComponentElement(node, type, props, parentNamespace) {
1296
+ const snapshot = getVNodeContextFrame(node) || getCurrentContextFrame();
1297
+ const componentFn = type;
1298
+ if (componentFn.constructor.name === "AsyncFunction") throw new Error("Async components are not supported. Use resource() for async work.");
1299
+ let childInstance = getVNodeComponentInstance(node);
1300
+ if (!childInstance) {
1301
+ childInstance = createComponentInstance(nextComponentInstanceId(), componentFn, props || {}, null);
1302
+ setVNodeComponentInstance(node, childInstance);
1303
+ }
1304
+ childInstance.props = props || {};
1305
+ if (snapshot) childInstance.ownerFrame = snapshot;
1306
+ const result = withContext(snapshot, () => renderComponentInline(childInstance));
1307
+ if (result instanceof Promise) throw new Error("Async components are not supported. Components must return synchronously.");
1308
+ const scopedResult = markVNodeTreeWithContextFrame(result, snapshot ?? null);
1309
+ const dom = withContext(snapshot, () => materializeComponentResultNode(childInstance, scopedResult, parentNamespace));
1310
+ warnUnusedStateReads(childInstance);
1311
+ if (dom instanceof Element) materializeKey(dom, node, props);
1312
+ return dom;
1313
+ }
1314
+ /**
1315
+ * Create a document fragment from Fragment vnode
1316
+ */
1317
+ function createFragmentElement(node, props, parentNamespace) {
1318
+ const fragment = document.createDocumentFragment();
1319
+ const children = props.children || node.children;
1320
+ if (children) if (Array.isArray(children)) {
1321
+ maybeWarnMissingKeys(children);
1322
+ for (const child of children) {
1323
+ const dom = createDOMNode(child, parentNamespace);
1324
+ if (dom) fragment.appendChild(dom);
1325
+ }
1326
+ } else {
1327
+ const dom = createDOMNode(children, parentNamespace);
1328
+ if (dom) fragment.appendChild(dom);
1329
+ }
1330
+ return fragment;
1331
+ }
1332
+ /**
1333
+ * Check if a cached DOM node can be reused for a given vnode.
1334
+ *
1335
+ * Returns true if shape has changed (i.e., DOM cannot be reused).
1336
+ * Structural check: compares DOM tagName with vnode type.
1337
+ * Do NOT rely on vnode identity (===) — vnodes are mutable.
1338
+ */
1339
+ function checkVNodeShapeChanged(dom, vnode) {
1340
+ if (!_isDOMElement(vnode)) return true;
1341
+ if (!(dom instanceof Element)) return true;
1342
+ const vnodeType = vnode.type;
1343
+ if (typeof vnodeType !== "string") return true;
1344
+ return dom.tagName.toLowerCase() !== vnodeType.toLowerCase();
1345
+ }
1346
+ function materializeChildScopeDom(vnode, parentNamespace) {
1347
+ if (vnode === null || vnode === void 0 || vnode === false) return document.createComment("");
1348
+ const dom = createDOMNode(vnode, parentNamespace);
1349
+ if (!(dom instanceof DocumentFragment)) return dom;
1350
+ const firstChild = dom.firstChild;
1351
+ const secondChild = firstChild?.nextSibling ?? null;
1352
+ if (!firstChild) return document.createComment("");
1353
+ if (secondChild) throw new Error("[askr] Child scopes must render a single DOM root node.");
1354
+ return firstChild;
1355
+ }
1356
+ function evaluateControlBoundaryState(controlState) {
1357
+ if (controlState.kind === "for") return evaluateForState(controlState);
1358
+ if (controlState.kind === "show") return evaluateShowState(controlState);
1359
+ return evaluateCaseState(controlState);
1360
+ }
1361
+ function clearControlBoundaryDomUpdateState(controlState) {
1362
+ if (controlState.kind === "for") {
1363
+ clearForDomUpdateState(controlState);
1364
+ return;
1365
+ }
1366
+ if (controlState.kind === "show") {
1367
+ clearShowDomUpdateState(controlState);
1368
+ return;
1369
+ }
1370
+ clearCaseDomUpdateState(controlState);
1371
+ }
1372
+ function getControlBoundaryState(node) {
1373
+ return node._controlState ?? node._forState ?? null;
1374
+ }
1375
+ function getDirectControlBoundaryVNode(children) {
1376
+ if (!Array.isArray(children) && _isDOMElement(children) && children.type === __FOR_BOUNDARY__) return children;
1377
+ if (Array.isArray(children) && children.length === 1 && _isDOMElement(children[0]) && children[0].type === __FOR_BOUNDARY__) return children[0];
1378
+ return null;
1379
+ }
1380
+ function getControlBoundaryCommitChildren(controlState) {
1381
+ if (controlState.kind === "for" && controlState._needsSourceReconcile) return evaluateForState(controlState);
1382
+ if (controlState.kind !== "for") {
1383
+ const activeVNode = controlState.activeScope?.vnode;
1384
+ return activeVNode == null || activeVNode === false ? [] : [activeVNode];
1385
+ }
1386
+ if (controlState.orderedKeys.length === 0) {
1387
+ const fallbackVNode = controlState.fallbackScope?.vnode;
1388
+ return fallbackVNode == null || fallbackVNode === false ? [] : [fallbackVNode];
1389
+ }
1390
+ const childrenVNodes = [];
1391
+ for (let index = 0; index < controlState.orderedKeys.length; index += 1) {
1392
+ const itemKey = controlState.orderedKeys[index];
1393
+ const itemInstance = controlState.items.get(itemKey);
1394
+ childrenVNodes.push(itemInstance?.scope.vnode ?? null);
1395
+ }
1396
+ return childrenVNodes;
1397
+ }
1398
+ function clearControlBoundaryCommitOwner(parent) {
1399
+ const owner = controlBoundaryOwners.get(parent);
1400
+ if (owner) {
1401
+ owner._enqueueBoundaryCommit = null;
1402
+ owner._hasPendingBoundaryCommit = false;
1403
+ }
1404
+ controlBoundaryOwners.delete(parent);
1405
+ }
1406
+ function registerControlBoundaryCommitOwner(parent, controlState) {
1407
+ const previousOwner = controlBoundaryOwners.get(parent);
1408
+ if (previousOwner && previousOwner !== controlState) {
1409
+ previousOwner._enqueueBoundaryCommit = null;
1410
+ previousOwner._hasPendingBoundaryCommit = false;
1411
+ }
1412
+ controlBoundaryOwners.set(parent, controlState);
1413
+ controlState._enqueueBoundaryCommit = () => {
1414
+ if (controlState._hasPendingBoundaryCommit) return;
1415
+ controlState._hasPendingBoundaryCommit = true;
1416
+ globalScheduler.enqueue(() => {
1417
+ controlState._hasPendingBoundaryCommit = false;
1418
+ if (controlBoundaryOwners.get(parent) !== controlState) return;
1419
+ commitForBoundaryChildren(parent, controlState, getControlBoundaryCommitChildren(controlState));
1420
+ });
1421
+ };
1422
+ }
1423
+ /**
1424
+ * Create DOM from For boundary - evaluates list and renders items
1425
+ *
1426
+ * CRITICAL INVARIANT:
1427
+ * DOM order MUST be reconstructed from the current vnode list on every render.
1428
+ * Reusing DOM nodes never implies preserving their position.
1429
+ *
1430
+ * This function ALWAYS returns a fragment whose child order exactly matches
1431
+ * the evaluated vnode list, even when all DOM nodes are reused.
1432
+ * Appending an existing node to the fragment is how we express reordering
1433
+ * (per DOM spec, appendChild moves already-attached nodes).
1434
+ *
1435
+ * Do NOT:
1436
+ * - Skip appending based on parentElement or existing attachment
1437
+ * - Rely on vnode identity (===) to decide DOM reuse (vnodes are mutable)
1438
+ * - Introduce fast-paths that might skip DOM reconstruction
1439
+ */
1440
+ function createForBoundary(node, props, parentNamespace) {
1441
+ const controlState = getControlBoundaryState(node);
1442
+ if (!controlState) {
1443
+ if (getRuntimeEnv().NODE_ENV !== "production") logger.warn("[Askr] Control boundary missing state");
1444
+ return document.createDocumentFragment();
1445
+ }
1446
+ const childrenVNodes = evaluateControlBoundaryState(controlState);
1447
+ const fragment = document.createDocumentFragment();
1448
+ if (controlState.kind !== "for") {
1449
+ const activeScope = controlState.activeScope;
1450
+ const vnode = childrenVNodes[0];
1451
+ if (activeScope && vnode !== void 0) {
1452
+ const dom = materializeChildScopeDom(vnode, parentNamespace);
1453
+ activeScope.dom = dom ?? void 0;
1454
+ if (dom) fragment.appendChild(dom);
1455
+ }
1456
+ clearControlBoundaryDomUpdateState(controlState);
1457
+ return fragment;
1458
+ }
1459
+ const forState = controlState;
1460
+ if (forState.orderedKeys.length === 0) {
1461
+ const fallbackScope = forState.fallbackScope;
1462
+ const fallbackVNode = childrenVNodes[0];
1463
+ if (fallbackScope && fallbackVNode !== void 0) {
1464
+ const dom = materializeChildScopeDom(fallbackVNode, parentNamespace);
1465
+ fallbackScope.dom = dom ?? void 0;
1466
+ if (dom) fragment.appendChild(dom);
1467
+ }
1468
+ clearControlBoundaryDomUpdateState(controlState);
1469
+ return fragment;
1470
+ }
1471
+ for (let i = 0; i < childrenVNodes.length; i++) {
1472
+ const childVNode = childrenVNodes[i];
1473
+ const itemKey = forState.orderedKeys[i];
1474
+ const itemInstance = itemKey != null ? forState.items.get(itemKey) : null;
1475
+ let dom = null;
1476
+ if (itemInstance && itemInstance.scope.dom) {
1477
+ const cachedDom = itemInstance.scope.dom;
1478
+ if (!checkVNodeShapeChanged(cachedDom, childVNode)) dom = cachedDom;
1479
+ }
1480
+ if (!dom) {
1481
+ dom = materializeChildScopeDom(childVNode, parentNamespace);
1482
+ if (itemInstance) itemInstance.scope.dom = dom ?? void 0;
1483
+ }
1484
+ if (dom) fragment.appendChild(dom);
1485
+ }
1486
+ clearControlBoundaryDomUpdateState(controlState);
1487
+ return fragment;
1488
+ }
1489
+ function syncForItemDom(parent, scope, vnode) {
1490
+ let dom = scope.dom ?? null;
1491
+ const parentNamespace = parent.namespaceURI === SVG_NAMESPACE ? SVG_NAMESPACE : void 0;
1492
+ if (dom && !scope.needsDomUpdate) return dom;
1493
+ if (_isDOMElement(vnode) && typeof vnode.type === "function") {
1494
+ const syncedComponentDom = syncComponentElement(dom, vnode, vnode.type, vnode.props ?? {}, parentNamespace);
1495
+ if (syncedComponentDom) {
1496
+ scope.dom = syncedComponentDom ?? void 0;
1497
+ return syncedComponentDom;
1498
+ }
1499
+ }
1500
+ if (!dom) {
1501
+ dom = materializeChildScopeDom(vnode, parentNamespace);
1502
+ scope.dom = dom ?? void 0;
1503
+ return dom;
1504
+ }
1505
+ if (dom.nodeType === 3 && (typeof vnode === "string" || typeof vnode === "number")) {
1506
+ dom.data = String(vnode);
1507
+ return dom;
1508
+ }
1509
+ if (dom.nodeType === 8 && (vnode === null || vnode === void 0 || vnode === false)) return dom;
1510
+ if (dom instanceof Element && _isDOMElement(vnode) && typeof vnode.type === "string" && tagNamesEqualIgnoreCase(dom.tagName, vnode.type)) {
1511
+ updateElementFromVnode(dom, vnode, true);
1512
+ return dom;
1513
+ }
1514
+ const nextDom = materializeChildScopeDom(vnode, parentNamespace);
1515
+ if (!nextDom) {
1516
+ if (dom.parentNode === parent) dom.parentNode.removeChild(dom);
1517
+ scope.dom = void 0;
1518
+ return null;
1519
+ }
1520
+ if (dom.parentNode === parent) parent.replaceChild(nextDom, dom);
1521
+ if (dom instanceof Element) teardownNodeSubtree(dom);
1522
+ scope.dom = nextDom;
1523
+ return nextDom;
1524
+ }
1525
+ function normalizeStableIntrinsicChildren(children) {
1526
+ if (children === null || children === void 0 || children === false) return [];
1527
+ return Array.isArray(children) ? children : [children];
1528
+ }
1529
+ function getStableIntrinsicChildren(vnode) {
1530
+ return normalizeStableIntrinsicChildren(vnode.children || vnode.props?.children);
1531
+ }
1532
+ function patchStableIntrinsicText(domNode, nextVNode) {
1533
+ if (domNode.nodeType !== 3 || typeof nextVNode !== "string" && typeof nextVNode !== "number") return false;
1534
+ const nextText = String(nextVNode);
1535
+ const textNode = domNode;
1536
+ if (textNode.data !== nextText) {
1537
+ recordBenchEvent("domTextSet");
1538
+ textNode.data = nextText;
1539
+ }
1540
+ return true;
1541
+ }
1542
+ function patchStableIntrinsicElement(dom, nextVNode) {
1543
+ if (typeof nextVNode.type !== "string" || !tagNamesEqualIgnoreCase(dom.tagName, nextVNode.type)) return false;
1544
+ updateElementFromVnode(dom, nextVNode, false);
1545
+ const nextChildren = getStableIntrinsicChildren(nextVNode);
1546
+ if (dom.childNodes.length !== nextChildren.length) return false;
1547
+ for (let index = 0; index < nextChildren.length; index += 1) {
1548
+ const nextChild = nextChildren[index];
1549
+ const currentChildNode = dom.childNodes[index];
1550
+ if (!currentChildNode) return false;
1551
+ if (patchStableIntrinsicText(currentChildNode, nextChild)) continue;
1552
+ if (currentChildNode instanceof Element && _isDOMElement(nextChild) && typeof nextChild.type === "string" && patchStableIntrinsicElement(currentChildNode, nextChild)) continue;
1553
+ return false;
1554
+ }
1555
+ return true;
1556
+ }
1557
+ function resolveStableIntrinsicPatchVNode(dom, vnode) {
1558
+ if (!_isDOMElement(vnode)) return null;
1559
+ if (typeof vnode.type === "string") return tagNamesEqualIgnoreCase(dom.tagName, vnode.type) ? vnode : null;
1560
+ if (typeof vnode.type !== "function") return null;
1561
+ const host = dom;
1562
+ const existingInstance = findHostInstanceByType(host, vnode.type);
1563
+ if (!existingInstance || existingInstance.fn !== vnode.type || host.__ASKR_WRAPPER_HOST) return null;
1564
+ const snapshot = getVNodeContextFrame(vnode) || getCurrentContextFrame() || existingInstance.ownerFrame || null;
1565
+ existingInstance.props = (vnode.props ?? {}) || {};
1566
+ if (snapshot) existingInstance.ownerFrame = snapshot;
1567
+ const result = withContext(snapshot, () => renderComponentInline(existingInstance));
1568
+ if (result instanceof Promise) throw new Error("Async components are not supported. Components must return synchronously.");
1569
+ const resolvedResult = resolveNestedComponentResult(result, snapshot ?? null);
1570
+ if (_isDOMElement(resolvedResult) && typeof resolvedResult.type === "string" && tagNamesEqualIgnoreCase(dom.tagName, resolvedResult.type)) return inheritComponentKey(resolvedResult, vnode);
1571
+ return null;
1572
+ }
1573
+ function tryPatchStableForDirtyItem(scope) {
1574
+ if (!(scope.dom instanceof Element) || scope.vnode === void 0) return false;
1575
+ const nextIntrinsic = resolveStableIntrinsicPatchVNode(scope.dom, scope.vnode);
1576
+ if (!nextIntrinsic) return false;
1577
+ const didPatch = patchStableIntrinsicElement(scope.dom, nextIntrinsic);
1578
+ const existingInstance = scope.dom.__ASKR_INSTANCE;
1579
+ if (didPatch && existingInstance) warnUnusedStateReads(existingInstance);
1580
+ return didPatch;
1581
+ }
1582
+ function removeForBoundaryNodes(parent, removedNodes) {
1583
+ if (removedNodes.length > 0 && removedNodes.length === parent.childNodes.length) {
1584
+ let canBulkClear = true;
1585
+ for (let i = 0; i < removedNodes.length; i++) if (removedNodes[i].parentNode !== parent) {
1586
+ canBulkClear = false;
1587
+ break;
1588
+ }
1589
+ if (canBulkClear) {
1590
+ for (let i = 0; i < removedNodes.length; i++) recordBenchEvent("domRemove");
1591
+ withBenchMetricScope("fullClear", () => {
1592
+ recordBenchCounter("bulkClearCommits");
1593
+ removeAllListeners(parent);
1594
+ parent.textContent = "";
1595
+ });
1596
+ return;
1597
+ }
1598
+ }
1599
+ for (let i = 0; i < removedNodes.length; i++) {
1600
+ const node = removedNodes[i];
1601
+ if (node.parentNode === parent) {
1602
+ recordBenchEvent("domRemove");
1603
+ parent.removeChild(node);
1604
+ }
1605
+ }
1606
+ }
1607
+ function syncKeyedMapFromForState(parent, forState, strategy, removedNodes) {
1608
+ const existing = keyedElements.get(parent);
1609
+ const ensureMapEntry = (map, key, element) => {
1610
+ map.set(key, element);
1611
+ const keyString = String(key);
1612
+ map.set(keyString, element);
1613
+ const keyNumber = Number(keyString);
1614
+ if (!Number.isNaN(keyNumber)) map.set(keyNumber, element);
1615
+ };
1616
+ if (strategy === "SWAP") {
1617
+ if (existing) return;
1618
+ }
1619
+ if (strategy === "NO_REORDER") {
1620
+ if (existing && removedNodes.length === 0) return;
1621
+ if (existing) {
1622
+ for (const [mapKey, element] of existing) if (element.parentNode !== parent) existing.delete(mapKey);
1623
+ if (existing.size > 0) keyedElements.set(parent, existing);
1624
+ else keyedElements.delete(parent);
1625
+ return;
1626
+ }
1627
+ }
1628
+ if (strategy === "TRUNCATE" && forState.orderedKeys.length === 0) {
1629
+ if (existing) existing.clear();
1630
+ keyedElements.delete(parent);
1631
+ return;
1632
+ }
1633
+ if (strategy === "APPEND" && existing) {
1634
+ for (let i = 0; i < forState.orderedKeys.length; i++) {
1635
+ const key = forState.orderedKeys[i];
1636
+ if (key === null || existing.has(key)) continue;
1637
+ const itemInstance = forState.items.get(key);
1638
+ if (itemInstance?.scope.dom instanceof Element) ensureMapEntry(existing, key, itemInstance.scope.dom);
1639
+ }
1640
+ if (existing.size > 0) keyedElements.set(parent, existing);
1641
+ else keyedElements.delete(parent);
1642
+ return;
1643
+ }
1644
+ const nextMap = existing ?? /* @__PURE__ */ new Map();
1645
+ nextMap.clear();
1646
+ for (let i = 0; i < forState.orderedKeys.length; i++) {
1647
+ const key = forState.orderedKeys[i];
1648
+ if (key === null) continue;
1649
+ const itemInstance = forState.items.get(key);
1650
+ if (itemInstance?.scope.dom instanceof Element) ensureMapEntry(nextMap, key, itemInstance.scope.dom);
1651
+ }
1652
+ if (nextMap.size > 0) keyedElements.set(parent, nextMap);
1653
+ else keyedElements.delete(parent);
1654
+ }
1655
+ function commitForBoundaryChildren(parent, controlState, childrenVNodes) {
1656
+ if (controlState.kind !== "for") {
1657
+ const activeScope = controlState.activeScope;
1658
+ const activeVNode = childrenVNodes[0];
1659
+ const nextDom = activeScope && activeVNode !== void 0 ? syncForItemDom(parent, activeScope, activeVNode) : null;
1660
+ for (let i = 0; i < controlState.lastRemovedNodes.length; i++) {
1661
+ const removedNode = controlState.lastRemovedNodes[i];
1662
+ if (removedNode instanceof Element) teardownNodeSubtree(removedNode);
1663
+ if (removedNode.parentNode === parent) {
1664
+ recordBenchEvent("domRemove");
1665
+ parent.removeChild(removedNode);
1666
+ }
1667
+ }
1668
+ if (nextDom) {
1669
+ if (parent.childNodes.length !== 1 || parent.firstChild !== nextDom || controlState.lastRemovedNodes.length > 0) parent.replaceChildren(nextDom);
1670
+ } else if (parent.firstChild) parent.textContent = "";
1671
+ keyedElements.delete(parent);
1672
+ clearControlBoundaryDomUpdateState(controlState);
1673
+ return;
1674
+ }
1675
+ const forState = controlState;
1676
+ const domCommitStart = performance.now();
1677
+ const hydrateExistingForDom = () => {
1678
+ const domKeyMap = getOrBuildDomKeyMap(parent);
1679
+ if (!domKeyMap) return;
1680
+ for (let i = 0; i < forState.orderedKeys.length; i++) {
1681
+ const itemKey = forState.orderedKeys[i];
1682
+ const itemInstance = forState.items.get(itemKey);
1683
+ if (!itemInstance || itemInstance.scope.dom) continue;
1684
+ const existingDom = domKeyMap.get(itemKey);
1685
+ if (!existingDom || checkVNodeShapeChanged(existingDom, childrenVNodes[i])) continue;
1686
+ itemInstance.scope.dom = existingDom;
1687
+ }
1688
+ };
1689
+ if (forState.orderedKeys.length === 0) {
1690
+ removeForBoundaryNodes(parent, forState.lastRemovedNodes);
1691
+ const fallbackScope = forState.fallbackScope;
1692
+ const fallbackVNode = childrenVNodes[0];
1693
+ const nextDom = fallbackScope && fallbackVNode !== void 0 ? syncForItemDom(parent, fallbackScope, fallbackVNode) : null;
1694
+ if (nextDom) {
1695
+ if (parent.childNodes.length !== 1 || parent.firstChild !== nextDom || forState.lastRemovedNodes.length > 0) parent.replaceChildren(nextDom);
1696
+ } else if (parent.firstChild) parent.textContent = "";
1697
+ keyedElements.delete(parent);
1698
+ forState._hasResolvedItemDom = false;
1699
+ recordBenchTiming("domCommit", performance.now() - domCommitStart);
1700
+ clearForDomUpdateState(forState);
1701
+ return;
1702
+ }
1703
+ if (!forState._hasResolvedItemDom && parent.childNodes.length > 0) hydrateExistingForDom();
1704
+ const getDirtyForIndices = () => {
1705
+ const pendingDirtyIndices = forState.pendingDirtyIndices;
1706
+ if (pendingDirtyIndices && pendingDirtyIndices.length > 0) return pendingDirtyIndices;
1707
+ const dirtyIndices = [];
1708
+ for (let index = 0; index < forState.orderedKeys.length; index += 1) {
1709
+ const itemKey = forState.orderedKeys[index];
1710
+ if (forState.items.get(itemKey)?.scope.needsDomUpdate) dirtyIndices.push(index);
1711
+ }
1712
+ return dirtyIndices;
1713
+ };
1714
+ let dirtyIndicesCache = null;
1715
+ const ensureDirtyIndices = () => {
1716
+ if (dirtyIndicesCache) return dirtyIndicesCache;
1717
+ dirtyIndicesCache = getDirtyForIndices();
1718
+ return dirtyIndicesCache;
1719
+ };
1720
+ const commitDirtyNoReorder = (dirtyIndices) => {
1721
+ if (dirtyIndices.length === 0) return;
1722
+ for (let dirtyIndex = 0; dirtyIndex < dirtyIndices.length; dirtyIndex++) {
1723
+ const i = dirtyIndices[dirtyIndex];
1724
+ const itemKey = forState.orderedKeys[i];
1725
+ const itemInstance = forState.items.get(itemKey);
1726
+ if (!itemInstance) continue;
1727
+ if (tryPatchStableForDirtyItem(itemInstance.scope)) continue;
1728
+ const dom = syncForItemDom(parent, itemInstance.scope, childrenVNodes[i]);
1729
+ if (!dom) continue;
1730
+ const anchor = parent.childNodes[i] ?? null;
1731
+ if (dom.parentNode !== parent || dom !== anchor) {
1732
+ recordBenchEvent("domInsert");
1733
+ parent.insertBefore(dom, anchor);
1734
+ }
1735
+ }
1736
+ };
1737
+ const commitPositional = () => {
1738
+ for (let i = 0; i < forState.orderedKeys.length; i++) {
1739
+ const itemKey = forState.orderedKeys[i];
1740
+ const itemInstance = forState.items.get(itemKey);
1741
+ if (!itemInstance) continue;
1742
+ const dom = syncForItemDom(parent, itemInstance.scope, childrenVNodes[i]);
1743
+ if (!dom) continue;
1744
+ if (dom.parentNode !== parent) {
1745
+ const anchor = parent.childNodes[i] ?? null;
1746
+ recordBenchEvent("domInsert");
1747
+ parent.insertBefore(dom, anchor);
1748
+ }
1749
+ }
1750
+ };
1751
+ const commitAppend = () => {
1752
+ withBenchMetricScope("coldCreate", () => {
1753
+ const fragment = parent.ownerDocument.createDocumentFragment();
1754
+ let hasPendingAppend = false;
1755
+ for (let i = 0; i < forState.orderedKeys.length; i++) {
1756
+ const itemKey = forState.orderedKeys[i];
1757
+ const itemInstance = forState.items.get(itemKey);
1758
+ if (!itemInstance) continue;
1759
+ if (itemInstance.scope.dom?.parentNode === parent && !itemInstance.scope.needsDomUpdate) continue;
1760
+ const dom = syncForItemDom(parent, itemInstance.scope, childrenVNodes[i]);
1761
+ if (!dom) continue;
1762
+ if (dom.parentNode !== parent) {
1763
+ recordBenchEvent("domInsert");
1764
+ fragment.appendChild(dom);
1765
+ hasPendingAppend = true;
1766
+ }
1767
+ }
1768
+ if (hasPendingAppend) parent.appendChild(fragment);
1769
+ });
1770
+ };
1771
+ const commitSwap = () => {
1772
+ const swapIndices = forState.pendingSwapIndices;
1773
+ if (!swapIndices) return;
1774
+ let [firstIndex, secondIndex] = swapIndices;
1775
+ if (firstIndex === secondIndex) return;
1776
+ if (firstIndex > secondIndex) [firstIndex, secondIndex] = [secondIndex, firstIndex];
1777
+ const firstKey = forState.orderedKeys[firstIndex];
1778
+ const secondKey = forState.orderedKeys[secondIndex];
1779
+ const firstItem = forState.items.get(firstKey);
1780
+ const secondItem = forState.items.get(secondKey);
1781
+ if (!firstItem || !secondItem) {
1782
+ commitReorder();
1783
+ return;
1784
+ }
1785
+ const firstDom = syncForItemDom(parent, firstItem.scope, childrenVNodes[firstIndex]);
1786
+ const secondDom = syncForItemDom(parent, secondItem.scope, childrenVNodes[secondIndex]);
1787
+ if (!firstDom || !secondDom) {
1788
+ commitReorder();
1789
+ return;
1790
+ }
1791
+ if (firstDom.parentNode !== parent || secondDom.parentNode !== parent) {
1792
+ commitReorder();
1793
+ return;
1794
+ }
1795
+ if ((firstDom.compareDocumentPosition(secondDom) & Node.DOCUMENT_POSITION_FOLLOWING) !== 0) return;
1796
+ const firstNextSibling = firstDom.nextSibling;
1797
+ recordBenchEvent("domMove");
1798
+ parent.insertBefore(firstDom, secondDom);
1799
+ recordBenchEvent("domMove");
1800
+ parent.insertBefore(secondDom, firstNextSibling);
1801
+ };
1802
+ const commitReorder = () => {
1803
+ const keys = forState.orderedKeys;
1804
+ const count = keys.length;
1805
+ if (forState.pendingMoveOnly && forState.lastRemovedNodes.length === 0) {
1806
+ const frag = parent.ownerDocument.createDocumentFragment();
1807
+ for (let i = 0; i < count; i++) {
1808
+ const itemKey = keys[i];
1809
+ const dom = forState.items.get(itemKey)?.scope.dom;
1810
+ if (!dom) return;
1811
+ recordBenchEvent(dom.parentNode === parent ? "domMove" : "domInsert");
1812
+ frag.appendChild(dom);
1813
+ }
1814
+ parent.replaceChildren(frag);
1815
+ return;
1816
+ }
1817
+ let hasExistingChild = false;
1818
+ for (let i = 0; i < count; i++) if (forState.items.get(keys[i])?.scope.dom?.parentNode === parent) {
1819
+ hasExistingChild = true;
1820
+ break;
1821
+ }
1822
+ if (!hasExistingChild) {
1823
+ withBenchMetricScope("coldCreate", () => {
1824
+ const frag = parent.ownerDocument.createDocumentFragment();
1825
+ for (let i = 0; i < count; i++) {
1826
+ const itemKey = keys[i];
1827
+ const itemInstance = forState.items.get(itemKey);
1828
+ if (!itemInstance) continue;
1829
+ const dom = syncForItemDom(parent, itemInstance.scope, childrenVNodes[i]);
1830
+ if (dom) {
1831
+ recordBenchEvent("domInsert");
1832
+ frag.appendChild(dom);
1833
+ }
1834
+ }
1835
+ recordBenchCounter("replaceChildrenCommits");
1836
+ parent.replaceChildren(frag);
1837
+ });
1838
+ return;
1839
+ }
1840
+ if (forState.lastRemovedNodes.length === 0) {
1841
+ const frag = parent.ownerDocument.createDocumentFragment();
1842
+ for (let i = 0; i < count; i++) {
1843
+ const itemKey = keys[i];
1844
+ const itemInstance = forState.items.get(itemKey);
1845
+ if (!itemInstance) continue;
1846
+ const dom = syncForItemDom(parent, itemInstance.scope, childrenVNodes[i]);
1847
+ if (!dom) continue;
1848
+ recordBenchEvent(dom.parentNode === parent ? "domMove" : "domInsert");
1849
+ frag.appendChild(dom);
1850
+ }
1851
+ parent.replaceChildren(frag);
1852
+ return;
1853
+ }
1854
+ for (let i = 0; i < count; i++) {
1855
+ const itemKey = keys[i];
1856
+ const itemInstance = forState.items.get(itemKey);
1857
+ if (!itemInstance) continue;
1858
+ const dom = syncForItemDom(parent, itemInstance.scope, childrenVNodes[i]);
1859
+ if (!dom) continue;
1860
+ const anchor = parent.childNodes[i] ?? null;
1861
+ if (dom !== anchor) {
1862
+ recordBenchEvent("domMove");
1863
+ parent.insertBefore(dom, anchor);
1864
+ }
1865
+ }
1866
+ };
1867
+ const isCurrentForDomOrder = () => {
1868
+ for (let index = 0; index < forState.orderedKeys.length; index += 1) {
1869
+ const itemKey = forState.orderedKeys[index];
1870
+ const itemInstance = forState.items.get(itemKey);
1871
+ if (!itemInstance?.scope.dom) return false;
1872
+ if (parent.childNodes[index] !== itemInstance.scope.dom) return false;
1873
+ }
1874
+ return true;
1875
+ };
1876
+ if (forState.lastCommitStrategy === "NO_REORDER" && ensureDirtyIndices().length > 0 && forState.pendingDirtyIndices === null && forState.pendingSwapIndices === null && !forState.pendingMoveOnly && forState.lastRemovedNodes.length === 0 && parent.childNodes.length === forState.orderedKeys.length) {
1877
+ if (isCurrentForDomOrder()) {
1878
+ commitDirtyNoReorder(ensureDirtyIndices());
1879
+ syncKeyedMapFromForState(parent, forState, "NO_REORDER", []);
1880
+ } else {
1881
+ commitReorder();
1882
+ syncKeyedMapFromForState(parent, forState, "FULL_KEYED", []);
1883
+ }
1884
+ recordBenchTiming("domCommit", performance.now() - domCommitStart);
1885
+ clearForDomUpdateState(forState);
1886
+ return;
1887
+ }
1888
+ switch (forState.lastCommitStrategy) {
1889
+ case "NO_REORDER":
1890
+ commitDirtyNoReorder(ensureDirtyIndices());
1891
+ break;
1892
+ case "TRUNCATE":
1893
+ commitPositional();
1894
+ break;
1895
+ case "APPEND":
1896
+ commitAppend();
1897
+ break;
1898
+ case "SWAP":
1899
+ commitSwap();
1900
+ break;
1901
+ default:
1902
+ commitReorder();
1903
+ break;
1904
+ }
1905
+ removeForBoundaryNodes(parent, forState.lastRemovedNodes);
1906
+ syncKeyedMapFromForState(parent, forState, forState.lastCommitStrategy, forState.lastRemovedNodes);
1907
+ forState._hasResolvedItemDom = true;
1908
+ recordBenchTiming("domCommit", performance.now() - domCommitStart);
1909
+ clearForDomUpdateState(forState);
1910
+ }
1911
+ /**
1912
+ * Update an existing element's attributes and children from vnode
1913
+ */
1914
+ function updateElementFromVnode(el, vnode, updateChildren = true) {
1915
+ if (!_isDOMElement(vnode)) return;
1916
+ const props = vnode.props || {};
1917
+ const domVNode = vnode;
1918
+ if (isHydrationSkipped(el)) {
1919
+ clearHydrationDeferredSubtree(el);
1920
+ return;
1921
+ }
1922
+ materializeKey(el, vnode, props);
1923
+ const existingListeners = elementListeners.get(el);
1924
+ const existingReactiveProps = elementReactivePropsCleanup.get(el);
1925
+ if ((!existingListeners || existingListeners.size === 0) && (!existingReactiveProps || existingReactiveProps.size === 0)) {
1926
+ if (hasMatchingStaticProps(el, props, vnode.type)) {
1927
+ if (updateChildren) {
1928
+ const children = vnode.children || props.children;
1929
+ if (canReuseStaticSubtree(el, domVNode)) return;
1930
+ updateElementChildren(el, children);
1931
+ }
1932
+ return;
1933
+ }
1934
+ }
1935
+ let desiredEventNames = null;
1936
+ let desiredReactivePropNames = null;
1937
+ const usesReactiveChildren = syncReactiveScalarChild(el, props.children ?? domVNode.children);
1938
+ if (usesReactiveChildren) (desiredReactivePropNames ??= /* @__PURE__ */ new Set()).add(REACTIVE_CHILDREN_KEY);
1939
+ for (const key in props) {
1940
+ const value = props[key];
1941
+ if (isSkippedProp(key)) continue;
1942
+ const eventName = parseEventName(key);
1943
+ if (value === void 0 || value === null || value === false) {
1944
+ if (key === "class" || key === "className") writeElementClassName(el, "");
1945
+ else if (key === "value") applyFormControlProp(el, key, "", vnode.type);
1946
+ else if (key === "checked") applyFormControlProp(el, key, false, vnode.type);
1947
+ else if (eventName && existingListeners?.has(eventName)) {
1948
+ const entry = existingListeners.get(eventName);
1949
+ incDevCounter("listenerRemoves");
1950
+ if (entry.isDelegated) removeDelegatedListener(el, eventName);
1951
+ else if (entry.options !== void 0) el.removeEventListener(eventName, entry.handler, entry.options);
1952
+ else el.removeEventListener(eventName, entry.handler);
1953
+ existingListeners.delete(eventName);
1954
+ } else {
1955
+ const entry = existingReactiveProps?.get(key);
1956
+ if (entry) {
1957
+ entry.cleanup();
1958
+ existingReactiveProps?.delete(key);
1959
+ } else el.removeAttribute(key);
1960
+ }
1961
+ continue;
1962
+ }
1963
+ if (typeof value === "function" && !eventName && key !== "ref") {
1964
+ const existingEntry = existingReactiveProps?.get(key);
1965
+ if (existingReactiveProps && existingReactiveProps.size > 0) (desiredReactivePropNames ??= /* @__PURE__ */ new Set()).add(key);
1966
+ if (existingEntry && existingEntry.fnRef === value) continue;
1967
+ if (existingEntry?.updateFn) {
1968
+ existingEntry.updateFn(value);
1969
+ existingEntry.fnRef = value;
1970
+ continue;
1971
+ }
1972
+ if (existingEntry) existingEntry.cleanup();
1973
+ const reactive = setupReactiveProp(el, key, value, vnode.type);
1974
+ if (!elementReactivePropsCleanup.has(el)) elementReactivePropsCleanup.set(el, /* @__PURE__ */ new Map());
1975
+ elementReactivePropsCleanup.get(el).set(key, {
1976
+ cleanup: reactive.cleanup,
1977
+ updateFn: (nextValue) => {
1978
+ reactive.updateFn(nextValue);
1979
+ },
1980
+ fnRef: value
1981
+ });
1982
+ continue;
1983
+ }
1984
+ const existingReactiveEntry = existingReactiveProps?.get(key);
1985
+ if (existingReactiveEntry) {
1986
+ existingReactiveEntry.cleanup();
1987
+ existingReactiveProps?.delete(key);
1988
+ }
1989
+ if (key === "class" || key === "className") writeElementClassName(el, String(value));
1990
+ else if (key === "style") applyStylePropValue(el, value);
1991
+ else if (key === "value" || key === "checked") applyFormControlProp(el, key, value, vnode.type);
1992
+ else if (eventName) {
1993
+ const useDelegation = isEventDelegationEnabled() && isDelegatedEvent(eventName);
1994
+ (desiredEventNames ??= /* @__PURE__ */ new Set()).add(eventName);
1995
+ if (useDelegation) {
1996
+ const existingDelegated = getDelegatedHandlerForElement(el, eventName);
1997
+ if (existingDelegated?.original === value) continue;
1998
+ if (existingDelegated && updateDelegatedListener(el, eventName, value, value, void 0)) continue;
1999
+ addDelegatedListener(el, eventName, value, value, void 0);
2000
+ continue;
2001
+ }
2002
+ const existing = existingListeners?.get(eventName);
2003
+ if (existing && existing.original === value) continue;
2004
+ if (existing) {
2005
+ if (useDelegation && existing.isDelegated && updateDelegatedListener(el, eventName, value, value, void 0)) {
2006
+ existing.handler = value;
2007
+ existing.original = value;
2008
+ existing.options = void 0;
2009
+ continue;
2010
+ }
2011
+ if (!useDelegation && !existing.isDelegated && existing.updateHandler) {
2012
+ existing.updateHandler(value);
2013
+ existing.original = value;
2014
+ continue;
2015
+ }
2016
+ if (existing.isDelegated) removeDelegatedListener(el, eventName);
2017
+ else if (existing.options !== void 0) el.removeEventListener(eventName, existing.handler, existing.options);
2018
+ else el.removeEventListener(eventName, existing.handler);
2019
+ }
2020
+ const options = getPassiveOptions(eventName);
2021
+ const mutableHandler = createMutableWrappedHandler(value, true);
2022
+ const trackedHandler = mutableHandler.handler;
2023
+ if (options !== void 0) el.addEventListener(eventName, trackedHandler, options);
2024
+ else el.addEventListener(eventName, trackedHandler);
2025
+ incDevCounter("listenerAdds");
2026
+ const listenerEntry = {
2027
+ handler: trackedHandler,
2028
+ original: value,
2029
+ options,
2030
+ isDelegated: false,
2031
+ updateHandler: mutableHandler?.updateHandler
2032
+ };
2033
+ if (!elementListeners.has(el)) elementListeners.set(el, /* @__PURE__ */ new Map());
2034
+ elementListeners.get(el).set(eventName, listenerEntry);
2035
+ } else el.setAttribute(key, String(value));
2036
+ }
2037
+ removeStaleAttributes(el, domVNode, props);
2038
+ if (existingListeners && existingListeners.size > 0) if (desiredEventNames === null) {
2039
+ existingListeners.forEach((entry, eventName) => {
2040
+ incDevCounter("listenerRemoves");
2041
+ if (entry.isDelegated) removeDelegatedListener(el, eventName);
2042
+ else if (entry.options !== void 0) el.removeEventListener(eventName, entry.handler, entry.options);
2043
+ else el.removeEventListener(eventName, entry.handler);
2044
+ });
2045
+ elementListeners.delete(el);
2046
+ } else {
2047
+ existingListeners.forEach((entry, eventName) => {
2048
+ if (!desiredEventNames.has(eventName)) {
2049
+ incDevCounter("listenerRemoves");
2050
+ if (entry.isDelegated) removeDelegatedListener(el, eventName);
2051
+ else if (entry.options !== void 0) el.removeEventListener(eventName, entry.handler, entry.options);
2052
+ else el.removeEventListener(eventName, entry.handler);
2053
+ existingListeners.delete(eventName);
2054
+ }
2055
+ });
2056
+ if (existingListeners.size === 0) elementListeners.delete(el);
2057
+ }
2058
+ const delegatedHandlers = getDelegatedHandlersForElement(el);
2059
+ if (delegatedHandlers && delegatedHandlers.size > 0) {
2060
+ if (desiredEventNames === null) for (const eventName of delegatedHandlers.keys()) removeDelegatedListener(el, eventName);
2061
+ else for (const eventName of delegatedHandlers.keys()) if (!desiredEventNames.has(eventName)) removeDelegatedListener(el, eventName);
2062
+ }
2063
+ if (existingReactiveProps && existingReactiveProps.size > 0) if (desiredReactivePropNames === null) {
2064
+ existingReactiveProps.forEach((entry) => {
2065
+ entry.cleanup();
2066
+ });
2067
+ elementReactivePropsCleanup.delete(el);
2068
+ } else {
2069
+ existingReactiveProps.forEach((entry, key) => {
2070
+ if (!desiredReactivePropNames.has(key)) {
2071
+ entry.cleanup();
2072
+ existingReactiveProps.delete(key);
2073
+ }
2074
+ });
2075
+ if (existingReactiveProps.size === 0) elementReactivePropsCleanup.delete(el);
2076
+ }
2077
+ if (updateChildren) {
2078
+ const children = vnode.children || props.children;
2079
+ if (usesReactiveChildren) return;
2080
+ updateElementChildren(el, children);
2081
+ }
2082
+ }
2083
+ function updateElementChildren(el, children) {
2084
+ const directControlBoundary = getDirectControlBoundaryVNode(children);
2085
+ if (directControlBoundary) {
2086
+ const controlState = getControlBoundaryState(directControlBoundary);
2087
+ if (!controlState) throw new Error("[updateElementChildren] Control boundary missing internal state");
2088
+ registerControlBoundaryCommitOwner(el, controlState);
2089
+ commitForBoundaryChildren(el, controlState, evaluateControlBoundaryState(controlState));
2090
+ return;
2091
+ }
2092
+ clearControlBoundaryCommitOwner(el);
2093
+ if (children === null || children === void 0) {
2094
+ for (let n = el.firstChild; n;) {
2095
+ const next = n.nextSibling;
2096
+ if (n instanceof Element) teardownNodeSubtree(n);
2097
+ n = next;
2098
+ }
2099
+ el.textContent = "";
2100
+ return;
2101
+ }
2102
+ if (!Array.isArray(children) && isFragmentVNode(children)) {
2103
+ updateUnkeyedChildren(el, normalizeComponentChildren(children));
2104
+ return;
2105
+ }
2106
+ if (!Array.isArray(children) && (typeof children === "string" || typeof children === "number")) {
2107
+ if (el.childNodes.length === 1 && el.firstChild?.nodeType === 3) {
2108
+ const s = String(children);
2109
+ const t = el.firstChild;
2110
+ if (t.data !== s) t.data = s;
2111
+ } else {
2112
+ for (let n = el.firstChild; n;) {
2113
+ const next = n.nextSibling;
2114
+ if (n instanceof Element) teardownNodeSubtree(n);
2115
+ n = next;
2116
+ }
2117
+ el.textContent = String(children);
2118
+ }
2119
+ return;
2120
+ }
2121
+ if (Array.isArray(children)) {
2122
+ if (trySyncScalarChildSequenceInPlace(el, children)) {
2123
+ keyedElements.delete(el);
2124
+ return;
2125
+ }
2126
+ if (hasKeyedVNodeChildren(children)) {
2127
+ const newKeyMap = reconcileKeyedChildren(el, children, getOrBuildDomKeyMap(el));
2128
+ keyedElements.set(el, newKeyMap);
2129
+ return;
2130
+ }
2131
+ if (isBulkTextFastPathEligible(el, children)) {
2132
+ performBulkTextReplace(el, children);
2133
+ keyedElements.delete(el);
2134
+ return;
2135
+ }
2136
+ updateUnkeyedChildren(el, children);
2137
+ return;
2138
+ }
2139
+ if (_isDOMElement(children)) {
2140
+ updateUnkeyedChildren(el, [children]);
2141
+ return;
2142
+ }
2143
+ for (let n = el.firstChild; n;) {
2144
+ const next = n.nextSibling;
2145
+ if (n instanceof Element) teardownNodeSubtree(n);
2146
+ n = next;
2147
+ }
2148
+ el.textContent = "";
2149
+ const dom = createDOMNode(children);
2150
+ if (dom) el.appendChild(dom);
2151
+ }
2152
+ function hasKeyedVNodeChildren(children) {
2153
+ for (let i = 0; i < children.length; i++) if (extractKey(children[i]) !== void 0) return true;
2154
+ return false;
2155
+ }
2156
+ function isEmptyChild(child) {
2157
+ return child === null || child === void 0 || child === false;
2158
+ }
2159
+ function getOrBuildDomKeyMap(parent) {
2160
+ let keyMap = keyedElements.get(parent);
2161
+ if (!keyMap) {
2162
+ keyMap = /* @__PURE__ */ new Map();
2163
+ for (let child = parent.firstElementChild; child; child = child.nextElementSibling) {
2164
+ const key = child.getAttribute("data-key");
2165
+ if (key !== null) {
2166
+ keyMap.set(key, child);
2167
+ const numericKey = Number(key);
2168
+ if (!Number.isNaN(numericKey)) keyMap.set(numericKey, child);
2169
+ }
2170
+ }
2171
+ if (keyMap.size > 0) keyedElements.set(parent, keyMap);
2172
+ }
2173
+ return keyMap.size > 0 ? keyMap : void 0;
2174
+ }
2175
+ function upperCommonTagName(tag) {
2176
+ switch (tag) {
2177
+ case "div": return "DIV";
2178
+ case "span": return "SPAN";
2179
+ case "p": return "P";
2180
+ case "a": return "A";
2181
+ case "button": return "BUTTON";
2182
+ case "input": return "INPUT";
2183
+ case "ul": return "UL";
2184
+ case "ol": return "OL";
2185
+ case "li": return "LI";
2186
+ default: return null;
2187
+ }
2188
+ }
2189
+ function tagsEqualIgnoreCase(elementTagName, vnodeType) {
2190
+ const upperCommon = upperCommonTagName(vnodeType);
2191
+ if (upperCommon !== null && elementTagName === upperCommon) return true;
2192
+ return tagNamesEqualIgnoreCase(elementTagName, vnodeType);
2193
+ }
2194
+ function collectStaticChildSlots(children, slots) {
2195
+ if (isFragmentVNode(children)) return collectStaticChildSlots(children.props?.children ?? children.children, slots);
2196
+ if (Array.isArray(children)) {
2197
+ for (const child of children) if (!collectStaticChildSlots(child, slots)) return false;
2198
+ return true;
2199
+ }
2200
+ if (children === null || children === void 0 || children === false) return true;
2201
+ if (typeof children === "string" || typeof children === "number") {
2202
+ slots.push({
2203
+ kind: "text",
2204
+ value: String(children)
2205
+ });
2206
+ return true;
2207
+ }
2208
+ if (_isDOMElement(children) && typeof children.type === "string") {
2209
+ slots.push({
2210
+ kind: "element",
2211
+ value: children
2212
+ });
2213
+ return true;
2214
+ }
2215
+ return false;
2216
+ }
2217
+ function getStaticChildSlots(children) {
2218
+ const slots = [];
2219
+ return collectStaticChildSlots(children, slots) ? slots : null;
2220
+ }
2221
+ function hasMatchingStaticProps(el, props, vnodeType) {
2222
+ let staticPropCount = 0;
2223
+ for (const key in props) {
2224
+ if (isSkippedProp(key)) continue;
2225
+ const value = props[key];
2226
+ if (value === void 0 || value === null || value === false) return false;
2227
+ if (parseEventName(key) || typeof value === "function") return false;
2228
+ if (key === "class" || key === "className") {
2229
+ if (readElementClassName(el) !== String(value)) return false;
2230
+ staticPropCount += 1;
2231
+ continue;
2232
+ }
2233
+ if (key === "style") {
2234
+ const styleValue = typeof value === "string" ? value.trim().replace(/;$/, "") : null;
2235
+ const domStyle = el.getAttribute("style")?.trim().replace(/;$/, "") ?? "";
2236
+ if (styleValue === null || domStyle !== styleValue) return false;
2237
+ staticPropCount += 1;
2238
+ continue;
2239
+ }
2240
+ if (key === "value" || key === "checked") {
2241
+ if (el[key] !== value) return false;
2242
+ staticPropCount += 1;
2243
+ continue;
2244
+ }
2245
+ if (key === "selected" && vnodeType === "option") {
2246
+ if (el.selected !== Boolean(value)) return false;
2247
+ staticPropCount += 1;
2248
+ continue;
2249
+ }
2250
+ if (el.getAttribute(key) !== String(value)) return false;
2251
+ staticPropCount += 1;
2252
+ }
2253
+ return el.attributes.length === staticPropCount;
2254
+ }
2255
+ function canReuseStaticSubtree(el, vnode) {
2256
+ if (typeof vnode.type !== "string" || !tagsEqualIgnoreCase(el.tagName, vnode.type)) return false;
2257
+ const props = vnode.props || {};
2258
+ if (!hasMatchingStaticProps(el, props, vnode.type)) return false;
2259
+ const slots = getStaticChildSlots(vnode.children || props.children);
2260
+ if (!slots) return false;
2261
+ if (el.childNodes.length !== slots.length) return false;
2262
+ for (let index = 0; index < slots.length; index += 1) {
2263
+ const slot = slots[index];
2264
+ const current = el.childNodes[index];
2265
+ if (!current) return false;
2266
+ if (slot.kind === "text") {
2267
+ if (current.nodeType !== 3 || current.data !== slot.value) return false;
2268
+ continue;
2269
+ }
2270
+ if (!(current instanceof Element)) return false;
2271
+ if (!canReuseStaticSubtree(current, slot.value)) return false;
2272
+ }
2273
+ return true;
2274
+ }
2275
+ function updateUnkeyedChildren(parent, newChildren) {
2276
+ const parentNamespace = parent.namespaceURI === SVG_NAMESPACE ? SVG_NAMESPACE : void 0;
2277
+ const trySyncComponentChild = (currentDom, next) => {
2278
+ if (typeof next.type !== "function") return null;
2279
+ return syncComponentElement(currentDom, next, next.type, (next.props ?? {}) || {}, parentNamespace);
2280
+ };
2281
+ const hasText = newChildren.some((c) => typeof c === "string" || typeof c === "number");
2282
+ const hasElements = newChildren.some((c) => _isDOMElement(c));
2283
+ const hasEmptyChildren = newChildren.some(isEmptyChild);
2284
+ const hasComponentChildren = newChildren.some((c) => _isDOMElement(c) && typeof c.type === "function");
2285
+ const hasNonElementDomChildren = parent.childNodes.length !== parent.children.length;
2286
+ if (!hasEmptyChildren && !hasText && !hasComponentChildren && hasElements && parent.children.length === newChildren.length) {
2287
+ const c = parent.children;
2288
+ for (let i = 0; i < newChildren.length; i++) {
2289
+ const next = newChildren[i];
2290
+ const current = c[i];
2291
+ if (!current || next === void 0) continue;
2292
+ if (_isDOMElement(next) && typeof next.type === "string") if (tagsEqualIgnoreCase(current.tagName, next.type)) updateElementFromVnode(current, next);
2293
+ else {
2294
+ const dom = createDOMNode(next, parentNamespace);
2295
+ if (dom) {
2296
+ teardownNodeSubtree(current);
2297
+ parent.replaceChild(dom, current);
2298
+ }
2299
+ }
2300
+ else if (_isDOMElement(next)) {
2301
+ const synced = trySyncComponentChild(current, next);
2302
+ if (synced && synced !== current) teardownNodeSubtree(current);
2303
+ else if (!synced) {
2304
+ const dom = createDOMNode(next, parentNamespace);
2305
+ if (dom) {
2306
+ teardownNodeSubtree(current);
2307
+ parent.replaceChild(dom, current);
2308
+ }
2309
+ }
2310
+ } else {
2311
+ const dom = createDOMNode(next, parentNamespace);
2312
+ if (dom) {
2313
+ teardownNodeSubtree(current);
2314
+ parent.replaceChild(dom, current);
2315
+ }
2316
+ }
2317
+ }
2318
+ return;
2319
+ }
2320
+ const existing = Array.from(parent.children);
2321
+ if (hasText || hasComponentChildren || hasEmptyChildren || hasNonElementDomChildren) {
2322
+ const allNodes = Array.from(parent.childNodes);
2323
+ const max = Math.max(allNodes.length, newChildren.length);
2324
+ for (let i = 0; i < max; i++) {
2325
+ const currentNode = allNodes[i];
2326
+ const next = newChildren[i];
2327
+ const nextIsEmpty = isEmptyChild(next);
2328
+ if (nextIsEmpty && currentNode) {
2329
+ teardownNodeSubtree(currentNode);
2330
+ currentNode.remove();
2331
+ continue;
2332
+ }
2333
+ if (!currentNode && !nextIsEmpty) {
2334
+ const dom = createDOMNode(next, parentNamespace);
2335
+ if (dom) parent.appendChild(dom);
2336
+ continue;
2337
+ }
2338
+ if (!currentNode || nextIsEmpty) continue;
2339
+ if (typeof next === "string" || typeof next === "number") if (currentNode.nodeType === 3) currentNode.data = String(next);
2340
+ else {
2341
+ const textNode = document.createTextNode(String(next));
2342
+ parent.replaceChild(textNode, currentNode);
2343
+ }
2344
+ else if (_isDOMElement(next)) if (currentNode.nodeType === 1) {
2345
+ const currentEl = currentNode;
2346
+ if (typeof next.type === "string") if (tagsEqualIgnoreCase(currentEl.tagName, next.type)) updateElementFromVnode(currentEl, next);
2347
+ else {
2348
+ const dom = createDOMNode(next, parentNamespace);
2349
+ if (dom) {
2350
+ teardownNodeSubtree(currentEl);
2351
+ parent.replaceChild(dom, currentNode);
2352
+ }
2353
+ }
2354
+ else {
2355
+ const synced = trySyncComponentChild(currentEl, next);
2356
+ if (synced && synced !== currentNode) teardownNodeSubtree(currentEl);
2357
+ else if (!synced) {
2358
+ const dom = createDOMNode(next, parentNamespace);
2359
+ if (dom) {
2360
+ teardownNodeSubtree(currentEl);
2361
+ parent.replaceChild(dom, currentNode);
2362
+ }
2363
+ }
2364
+ }
2365
+ } else {
2366
+ const dom = createDOMNode(next, parentNamespace);
2367
+ if (dom) parent.replaceChild(dom, currentNode);
2368
+ }
2369
+ }
2370
+ return;
2371
+ }
2372
+ if (newChildren.length === 1 && existing.length === 0 && parent.childNodes.length === 1) {
2373
+ const firstNewChild = newChildren[0];
2374
+ const firstExisting = parent.firstChild;
2375
+ if ((typeof firstNewChild === "string" || typeof firstNewChild === "number") && firstExisting?.nodeType === 3) {
2376
+ firstExisting.data = String(firstNewChild);
2377
+ return;
2378
+ }
2379
+ }
2380
+ if (existing.length === 0 && parent.childNodes.length > 0) {
2381
+ for (let n = parent.firstChild; n;) {
2382
+ const next = n.nextSibling;
2383
+ if (n instanceof Element) teardownNodeSubtree(n);
2384
+ n = next;
2385
+ }
2386
+ parent.textContent = "";
2387
+ }
2388
+ const max = Math.max(existing.length, newChildren.length);
2389
+ for (let i = 0; i < max; i++) {
2390
+ const current = existing[i];
2391
+ const next = newChildren[i];
2392
+ const nextIsEmpty = isEmptyChild(next);
2393
+ if (nextIsEmpty && current) {
2394
+ teardownNodeSubtree(current);
2395
+ current.remove();
2396
+ continue;
2397
+ }
2398
+ if (!current && !nextIsEmpty) {
2399
+ const dom = createDOMNode(next, parentNamespace);
2400
+ if (dom) parent.appendChild(dom);
2401
+ continue;
2402
+ }
2403
+ if (!current || nextIsEmpty) continue;
2404
+ if (typeof next === "string" || typeof next === "number") {
2405
+ const textNode = document.createTextNode(String(next));
2406
+ teardownNodeSubtree(current);
2407
+ parent.replaceChild(textNode, current);
2408
+ } else if (_isDOMElement(next)) if (typeof next.type === "string") if (tagsEqualIgnoreCase(current.tagName, next.type)) updateElementFromVnode(current, next);
2409
+ else {
2410
+ const dom = createDOMNode(next, parentNamespace);
2411
+ if (dom) {
2412
+ teardownNodeSubtree(current);
2413
+ parent.replaceChild(dom, current);
2414
+ }
2415
+ }
2416
+ else {
2417
+ const synced = trySyncComponentChild(current, next);
2418
+ if (synced && synced !== current) teardownNodeSubtree(current);
2419
+ else if (!synced) {
2420
+ const dom = createDOMNode(next, parentNamespace);
2421
+ if (dom) {
2422
+ teardownNodeSubtree(current);
2423
+ parent.replaceChild(dom, current);
2424
+ }
2425
+ }
2426
+ }
2427
+ else {
2428
+ const dom = createDOMNode(next);
2429
+ if (dom) {
2430
+ teardownNodeSubtree(current);
2431
+ parent.replaceChild(dom, current);
2432
+ }
2433
+ }
2434
+ }
2435
+ }
2436
+ //#endregion
2437
+ export { IS_DOM_AVAILABLE, commitForBoundaryChildren, createDOMNode, createForBoundary, markReactivePropsDirtySource, syncComponentElement, tryPatchStableForDirtyItem, updateElementChildren, updateElementFromVnode, updateUnkeyedChildren };
2438
+
2439
+ //# sourceMappingURL=dom.js.map