@askrjs/askr 0.0.28 → 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 (451) hide show
  1. package/README.md +44 -172
  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 +22 -26
  14. package/dist/bin/askr-ssg.d.ts.map +1 -1
  15. package/dist/bin/askr-ssg.js +149 -2
  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 -23
  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 -34
  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 -56
  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 +12 -9
  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 -1
  238. package/dist/runtime/perf-metrics.js.map +1 -0
  239. package/dist/runtime/readable.d.ts +24 -18
  240. package/dist/runtime/readable.d.ts.map +1 -1
  241. package/dist/runtime/readable.js +118 -1
  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 -50
  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 +7 -5
  250. package/dist/runtime/selector.d.ts.map +1 -1
  251. package/dist/runtime/selector.js +188 -1
  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 -19
  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 +10 -10
  260. package/dist/ssg/batch-render.d.ts.map +1 -1
  261. package/dist/ssg/batch-render.js +84 -1
  262. package/dist/ssg/batch-render.js.map +1 -0
  263. package/dist/ssg/create-static-gen.d.ts +28 -29
  264. package/dist/ssg/create-static-gen.d.ts.map +1 -1
  265. package/dist/ssg/create-static-gen.js +282 -1
  266. package/dist/ssg/create-static-gen.js.map +1 -0
  267. package/dist/ssg/generate-metadata.d.ts +12 -15
  268. package/dist/ssg/generate-metadata.d.ts.map +1 -1
  269. package/dist/ssg/generate-metadata.js +94 -1
  270. package/dist/ssg/generate-metadata.js.map +1 -0
  271. package/dist/ssg/incremental-manifest.js +56 -1
  272. package/dist/ssg/incremental-manifest.js.map +1 -0
  273. package/dist/ssg/index.d.ts +8 -28
  274. package/dist/ssg/index.js +7 -1
  275. package/dist/ssg/resolve-ssg-data.d.ts +10 -13
  276. package/dist/ssg/resolve-ssg-data.d.ts.map +1 -1
  277. package/dist/ssg/resolve-ssg-data.js +46 -1
  278. package/dist/ssg/resolve-ssg-data.js.map +1 -0
  279. package/dist/ssg/route-utils.d.ts +14 -10
  280. package/dist/ssg/route-utils.d.ts.map +1 -1
  281. package/dist/ssg/route-utils.js +24 -1
  282. package/dist/ssg/route-utils.js.map +1 -0
  283. package/dist/ssg/types.d.ts +157 -144
  284. package/dist/ssg/types.d.ts.map +1 -1
  285. package/dist/ssg/write-static-files.d.ts +8 -14
  286. package/dist/ssg/write-static-files.d.ts.map +1 -1
  287. package/dist/ssg/write-static-files.js +73 -1
  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 -35
  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 +74 -72
  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 +49 -69
  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/_fs.js +0 -1
  320. package/dist/_virtual/_path.js +0 -1
  321. package/dist/_virtual/main.js +0 -1
  322. package/dist/_virtual/preload-helper.js +0 -1
  323. package/dist/bench/benchmark-entry.d.ts +0 -14
  324. package/dist/bench/benchmark-entry.d.ts.map +0 -1
  325. package/dist/common/errors.d.ts +0 -53
  326. package/dist/common/errors.d.ts.map +0 -1
  327. package/dist/common/index.d.ts +0 -14
  328. package/dist/common/index.d.ts.map +0 -1
  329. package/dist/dev/invariant.d.ts +0 -83
  330. package/dist/dev/invariant.d.ts.map +0 -1
  331. package/dist/dev/logger.d.ts +0 -13
  332. package/dist/dev/logger.d.ts.map +0 -1
  333. package/dist/dev/vite-plugin-askr.d.ts +0 -25
  334. package/dist/dev/vite-plugin-askr.d.ts.map +0 -1
  335. package/dist/dev/warnings.d.ts +0 -5
  336. package/dist/dev/warnings.d.ts.map +0 -1
  337. package/dist/for/for.d.ts +0 -16
  338. package/dist/for/for.d.ts.map +0 -1
  339. package/dist/for/for.js +0 -1
  340. package/dist/for/index.d.ts +0 -2
  341. package/dist/for/index.d.ts.map +0 -1
  342. package/dist/for/index.js +0 -1
  343. package/dist/foundations/core.d.ts +0 -23
  344. package/dist/foundations/core.d.ts.map +0 -1
  345. package/dist/foundations/core.js +0 -1
  346. package/dist/foundations/index.d.ts.map +0 -1
  347. package/dist/foundations/interactions/dismissable.d.ts +0 -58
  348. package/dist/foundations/interactions/dismissable.d.ts.map +0 -1
  349. package/dist/foundations/interactions/dismissable.js +0 -1
  350. package/dist/foundations/interactions/focusable.d.ts +0 -16
  351. package/dist/foundations/interactions/focusable.d.ts.map +0 -1
  352. package/dist/foundations/interactions/focusable.js +0 -1
  353. package/dist/foundations/interactions/hoverable.d.ts +0 -19
  354. package/dist/foundations/interactions/hoverable.d.ts.map +0 -1
  355. package/dist/foundations/interactions/hoverable.js +0 -1
  356. package/dist/foundations/interactions/index.d.ts +0 -5
  357. package/dist/foundations/interactions/index.d.ts.map +0 -1
  358. package/dist/foundations/interactions/interaction-policy.d.ts +0 -96
  359. package/dist/foundations/interactions/interaction-policy.d.ts.map +0 -1
  360. package/dist/foundations/interactions/pressable.d.ts +0 -54
  361. package/dist/foundations/interactions/pressable.d.ts.map +0 -1
  362. package/dist/foundations/interactions/roving-focus.d.ts +0 -117
  363. package/dist/foundations/interactions/roving-focus.d.ts.map +0 -1
  364. package/dist/foundations/interactions/roving-focus.js +0 -1
  365. package/dist/foundations/state/controllable.d.ts +0 -53
  366. package/dist/foundations/state/controllable.d.ts.map +0 -1
  367. package/dist/foundations/state/controllable.js +0 -1
  368. package/dist/foundations/state/index.d.ts +0 -2
  369. package/dist/foundations/state/index.d.ts.map +0 -1
  370. package/dist/foundations/structures/index.d.ts +0 -5
  371. package/dist/foundations/structures/index.d.ts.map +0 -1
  372. package/dist/foundations/structures.d.ts.map +0 -1
  373. package/dist/foundations/utilities/aria.d.ts +0 -13
  374. package/dist/foundations/utilities/aria.d.ts.map +0 -1
  375. package/dist/foundations/utilities/compose-handlers.d.ts +0 -34
  376. package/dist/foundations/utilities/compose-handlers.d.ts.map +0 -1
  377. package/dist/foundations/utilities/event-types.d.ts +0 -17
  378. package/dist/foundations/utilities/event-types.d.ts.map +0 -1
  379. package/dist/foundations/utilities/index.d.ts +0 -7
  380. package/dist/foundations/utilities/index.d.ts.map +0 -1
  381. package/dist/foundations/utilities/merge-props.d.ts +0 -2
  382. package/dist/foundations/utilities/merge-props.d.ts.map +0 -1
  383. package/dist/foundations/utilities/use-id.d.ts +0 -29
  384. package/dist/foundations/utilities/use-id.d.ts.map +0 -1
  385. package/dist/foundations/utilities/use-id.js +0 -1
  386. package/dist/fx/index.d.ts.map +0 -1
  387. package/dist/fx/noop.d.ts +0 -12
  388. package/dist/fx/noop.d.ts.map +0 -1
  389. package/dist/index.d.ts.map +0 -1
  390. package/dist/jsx/index.d.ts.map +0 -1
  391. package/dist/jsx/jsx-dev-runtime.d.ts +0 -4
  392. package/dist/jsx/jsx-dev-runtime.d.ts.map +0 -1
  393. package/dist/jsx/jsx-runtime.d.ts +0 -10
  394. package/dist/jsx/jsx-runtime.d.ts.map +0 -1
  395. package/dist/node_modules/esbuild/lib/main.js +0 -65
  396. package/dist/renderer/cleanup.d.ts +0 -28
  397. package/dist/renderer/cleanup.d.ts.map +0 -1
  398. package/dist/renderer/dom.d.ts +0 -64
  399. package/dist/renderer/dom.d.ts.map +0 -1
  400. package/dist/renderer/evaluate.d.ts +0 -4
  401. package/dist/renderer/evaluate.d.ts.map +0 -1
  402. package/dist/renderer/fastpath.d.ts +0 -7
  403. package/dist/renderer/fastpath.d.ts.map +0 -1
  404. package/dist/renderer/index.d.ts +0 -6
  405. package/dist/renderer/index.d.ts.map +0 -1
  406. package/dist/renderer/keyed.d.ts +0 -23
  407. package/dist/renderer/keyed.d.ts.map +0 -1
  408. package/dist/renderer/reconcile.d.ts +0 -88
  409. package/dist/renderer/reconcile.d.ts.map +0 -1
  410. package/dist/renderer/types.d.ts +0 -3
  411. package/dist/renderer/types.d.ts.map +0 -1
  412. package/dist/renderer/utils.d.ts +0 -63
  413. package/dist/renderer/utils.d.ts.map +0 -1
  414. package/dist/resources/index.d.ts.map +0 -1
  415. package/dist/router/index.d.ts.map +0 -1
  416. package/dist/router/match.d.ts +0 -22
  417. package/dist/router/match.d.ts.map +0 -1
  418. package/dist/runtime/dev-namespace.d.ts +0 -31
  419. package/dist/runtime/dev-namespace.d.ts.map +0 -1
  420. package/dist/runtime/events.d.ts +0 -53
  421. package/dist/runtime/events.d.ts.map +0 -1
  422. package/dist/runtime/execution-model.d.ts +0 -4
  423. package/dist/runtime/execution-model.d.ts.map +0 -1
  424. package/dist/runtime/fastlane.d.ts +0 -27
  425. package/dist/runtime/fastlane.d.ts.map +0 -1
  426. package/dist/runtime/hydration.d.ts +0 -25
  427. package/dist/runtime/hydration.d.ts.map +0 -1
  428. package/dist/runtime/perf-metrics.d.ts +0 -25
  429. package/dist/runtime/perf-metrics.d.ts.map +0 -1
  430. package/dist/runtime/resource-cell.d.ts +0 -35
  431. package/dist/runtime/resource-cell.d.ts.map +0 -1
  432. package/dist/runtime/snapshot.d.ts +0 -25
  433. package/dist/runtime/snapshot.d.ts.map +0 -1
  434. package/dist/runtime/ssr-bridge.d.ts +0 -10
  435. package/dist/runtime/ssr-bridge.d.ts.map +0 -1
  436. package/dist/ssg/discover-resources.d.ts +0 -15
  437. package/dist/ssg/discover-resources.d.ts.map +0 -1
  438. package/dist/ssg/incremental-manifest.d.ts +0 -23
  439. package/dist/ssg/incremental-manifest.d.ts.map +0 -1
  440. package/dist/ssg/index.d.ts.map +0 -1
  441. package/dist/ssr/attrs.d.ts +0 -26
  442. package/dist/ssr/attrs.d.ts.map +0 -1
  443. package/dist/ssr/create-ssr.d.ts +0 -19
  444. package/dist/ssr/create-ssr.d.ts.map +0 -1
  445. package/dist/ssr/escape.d.ts +0 -38
  446. package/dist/ssr/escape.d.ts.map +0 -1
  447. package/dist/ssr/sink.d.ts +0 -23
  448. package/dist/ssr/sink.d.ts.map +0 -1
  449. package/dist/ssr/stream-render.d.ts +0 -7
  450. package/dist/ssr/stream-render.d.ts.map +0 -1
  451. package/dist/vite/index.js +0 -4
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/runtime/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAMhD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAmBhC,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC;IAEzB,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,UAAU,CAAC;CAC/E;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAE5B,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CACzC;AAGD,eAAO,MAAM,oBAAoB,eAAkC,CAAC;AAWpE;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,CAAC,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AA,SAAqB,EAAA,QAAU,CAAA,GAAI,CAAA;;;AA3IzE;;;;;;;iBA8JgB,wBAAA,GAAA,CACd,KAAA,EAAO,YAAA,SACP,EAAA,QAAU,CAAA,GACT,CAAA;AAAA,iBAYa,aAAA,GAAA,CAAiB,YAAA,EAAc,CAAA,GAAI,OAAA,CAAQ,CAAA;AAAA,iBA0C3C,WAAA,GAAA,CAAe,OAAA,EAAS,OAAA,CAAQ,CAAA,IAAK,CAAA;AA9IrD;;;;AAAA,iBA6RgB,gBAAA,CAAA,GAAoB,YAAA;;;;;iBAgBpB,eAAA,CAAA;AA3OhB;;;AAAA,iBAoPgB,sBAAA,CAAA,GAA0B,YAAA;;;;;iBAQ1B,qBAAA,CAAA,GAAyB,YAAA"}
@@ -1 +1,205 @@
1
- import{ELEMENT_TYPE as C}from"../common/jsx.js";import{getCurrentComponentInstance as s}from"./component.js";const h=Symbol("__tempoContextFrame__");let o=null,a=null;function F(n,r){const t=o;o=n;try{return r()}finally{o=t}}function v(n,r){const t=a;a=n;try{return r()}finally{a=t}}function w(n){const r=Symbol("AskrContext");return{key:r,defaultValue:n,Scope:t=>{const e=t.value;return{$$typeof:C,type:d,props:{key:r,value:e,children:t.children},key:null}}}}function A(n){const r=o||a;if(!r)throw new Error("readContext() can only be called during component render or async resource execution. Ensure you are calling this from inside your component or resource function.");let t=r;for(;t;){const e=t.values;if(e&&e.has(n.key))return e.get(n.key);t=t.parent}return n.defaultValue}function d(n){const r=n.key,t=n.value,e=n.children,u=s(),l={parent:o||(u&&u.ownerFrame?u.ownerFrame:null),values:new Map([[r,t]])};function m(c,y,p){return{type:x,props:{fn:c,__frame:y,__owner:p}}}return Array.isArray(e)?e.map(c=>typeof c=="function"?m(c,l,s()):i(c,l)):typeof e=="function"?m(e,l,s()):e?i(e,l):null}function i(n,r){if(typeof n=="object"&&n!==null){const t=n;t[h]=r;const e=t.children;if(Array.isArray(e))for(let u=0;u<e.length;u++){const f=e[u];f&&(e[u]=i(f,r))}else e&&(t.children=i(e,r))}return n}function x(n){const{fn:r,__frame:t}=n,e=F(t,()=>r());return e?i(e,t):null}function E(){const n={parent:o,values:null};return o=n,n}function g(){o&&(o=o.parent)}function S(){return o}function b(){return o}export{h as CONTEXT_FRAME_SYMBOL,w as defineContext,S as getCurrentContextFrame,b as getTopContextSnapshot,g as popContextFrame,E as pushContextFrame,A as readContext,v as withAsyncResourceContext,F as withContext};
1
+ import { ELEMENT_TYPE, STATIC_CHILDREN } from "../common/jsx.js";
2
+ import { getCurrentComponentInstance } from "./component.js";
3
+ //#region src/runtime/context.ts
4
+ const CONTEXT_FRAME_SYMBOL = Symbol("__tempoContextFrame__");
5
+ const vnodeContextFrames = /* @__PURE__ */ new WeakMap();
6
+ function getVNodeContextFrame(node) {
7
+ if (typeof node !== "object" || node === null) return;
8
+ const objectNode = node;
9
+ return vnodeContextFrames.get(node) ?? objectNode[CONTEXT_FRAME_SYMBOL];
10
+ }
11
+ function markVNodeWithContextFrame(node, frame, overwrite = false) {
12
+ if (typeof node !== "object" || node === null) return;
13
+ if (!overwrite && getVNodeContextFrame(node)) return;
14
+ const objectNode = node;
15
+ if (Object.prototype.hasOwnProperty.call(node, CONTEXT_FRAME_SYMBOL)) try {
16
+ objectNode[CONTEXT_FRAME_SYMBOL] = frame;
17
+ return;
18
+ } catch {}
19
+ if (Object.isExtensible(node)) try {
20
+ Object.defineProperty(node, CONTEXT_FRAME_SYMBOL, {
21
+ value: frame,
22
+ writable: true,
23
+ enumerable: true,
24
+ configurable: true
25
+ });
26
+ return;
27
+ } catch {}
28
+ vnodeContextFrames.set(node, frame);
29
+ }
30
+ function isVNodeLike(value) {
31
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
32
+ const objectValue = value;
33
+ if (objectValue.$$typeof === ELEMENT_TYPE) return true;
34
+ return "type" in objectValue && ("props" in objectValue || "children" in objectValue);
35
+ }
36
+ function markContextPropValue(value, frame, overwrite) {
37
+ if (Array.isArray(value)) {
38
+ for (const item of value) markContextPropValue(item, frame, overwrite);
39
+ return;
40
+ }
41
+ if (isVNodeLike(value)) markVNodeTreeWithContextFrame(value, frame, overwrite);
42
+ }
43
+ function markVNodeTreeWithContextFrame(node, frame, overwrite = false) {
44
+ if (!frame) return node;
45
+ if (Array.isArray(node)) {
46
+ for (const child of node) markVNodeTreeWithContextFrame(child, frame, overwrite);
47
+ return node;
48
+ }
49
+ if (typeof node !== "object" || node === null) return node;
50
+ markVNodeWithContextFrame(node, frame, overwrite);
51
+ const objectNode = node;
52
+ const props = typeof objectNode.props === "object" && objectNode.props !== null ? objectNode.props : null;
53
+ const children = props?.children ?? objectNode.children;
54
+ if (Array.isArray(children)) for (const child of children) markVNodeTreeWithContextFrame(child, frame, overwrite);
55
+ else if (children) markVNodeTreeWithContextFrame(children, frame, overwrite);
56
+ if (props) {
57
+ for (const key in props) if (key !== "children") markContextPropValue(props[key], frame, overwrite);
58
+ }
59
+ return node;
60
+ }
61
+ let currentContextFrame = null;
62
+ let currentAsyncResourceFrame = null;
63
+ /**
64
+ * Execute a function within a specific context frame.
65
+ *
66
+ * CORE PRIMITIVE for context restoration:
67
+ * - Saves the current context
68
+ * - Sets the provided frame as current
69
+ * - Executes the function
70
+ * - Restores the previous context in finally
71
+ *
72
+ * This ensures no context frame remains globally active across await.
73
+ */
74
+ function withContext(frame, fn) {
75
+ const oldFrame = currentContextFrame;
76
+ currentContextFrame = frame;
77
+ try {
78
+ return fn();
79
+ } finally {
80
+ currentContextFrame = oldFrame;
81
+ }
82
+ }
83
+ /**
84
+ * Execute an async resource step within its frozen context snapshot.
85
+ *
86
+ * CRITICAL: This wrapper is applied only to synchronous execution steps of
87
+ * an async resource (the initial call). We intentionally DO NOT restore
88
+ * the resource frame for post-await continuations — continuations must not
89
+ * observe or rely on a live resource frame. This keeps semantics simple and
90
+ * deterministic: async resources see only their creation-time snapshot.
91
+ */
92
+ function withAsyncResourceContext(frame, fn) {
93
+ const oldFrame = currentAsyncResourceFrame;
94
+ currentAsyncResourceFrame = frame;
95
+ try {
96
+ return fn();
97
+ } finally {
98
+ currentAsyncResourceFrame = oldFrame;
99
+ }
100
+ }
101
+ function defineContext(defaultValue) {
102
+ const key = Symbol("AskrContext");
103
+ return {
104
+ key,
105
+ defaultValue,
106
+ Scope: (props) => {
107
+ return {
108
+ $$typeof: ELEMENT_TYPE,
109
+ type: ContextScopeComponent,
110
+ props: {
111
+ key,
112
+ value: props.value,
113
+ children: props.children
114
+ },
115
+ key: null
116
+ };
117
+ }
118
+ };
119
+ }
120
+ function preserveStaticChildrenMarker(source, target) {
121
+ if (source[STATIC_CHILDREN] === true) Object.defineProperty(target, STATIC_CHILDREN, {
122
+ value: true,
123
+ enumerable: false,
124
+ configurable: true
125
+ });
126
+ return target;
127
+ }
128
+ function readContext(context) {
129
+ const frame = currentContextFrame || currentAsyncResourceFrame;
130
+ if (!frame) throw new Error("readContext() can only be called during component render or async resource execution. Ensure you are calling this from inside your component or resource function.");
131
+ let current = frame;
132
+ while (current) {
133
+ const values = current.values;
134
+ if (values && values.has(context.key)) return values.get(context.key);
135
+ current = current.parent;
136
+ }
137
+ return context.defaultValue;
138
+ }
139
+ /**
140
+ * Internal component that manages context frame
141
+ * Used by Context.Scope to provide shadowed value to children
142
+ */
143
+ function ContextScopeComponent(props) {
144
+ const key = props["key"];
145
+ const value = props["value"];
146
+ const children = props["children"];
147
+ const instance = getCurrentComponentInstance();
148
+ const newFrame = {
149
+ parent: (() => {
150
+ if (currentContextFrame) return currentContextFrame;
151
+ if (instance && instance.ownerFrame) return instance.ownerFrame;
152
+ return null;
153
+ })(),
154
+ values: new Map([[key, value]])
155
+ };
156
+ function createFunctionChildInvoker(fn, frame, owner) {
157
+ return {
158
+ type: ContextFunctionChildInvoker,
159
+ props: {
160
+ fn,
161
+ __frame: frame,
162
+ __owner: owner
163
+ }
164
+ };
165
+ }
166
+ if (Array.isArray(children)) return preserveStaticChildrenMarker(children, children.map((child) => {
167
+ if (typeof child === "function") return createFunctionChildInvoker(child, newFrame, getCurrentComponentInstance());
168
+ return markWithFrame(child, newFrame);
169
+ }));
170
+ else if (typeof children === "function") return createFunctionChildInvoker(children, newFrame, getCurrentComponentInstance());
171
+ else if (children) return markWithFrame(children, newFrame);
172
+ return null;
173
+ }
174
+ /**
175
+ * Internal: Mark a vnode with a context frame
176
+ * The renderer will restore this frame before executing component functions
177
+ */
178
+ function markWithFrame(node, frame) {
179
+ return markVNodeTreeWithContextFrame(node, frame, true);
180
+ }
181
+ /**
182
+ * Internal helper component: executes a function-child lazily inside the
183
+ * provided frame and marks the returned subtree with that frame so later
184
+ * component executions will restore the correct context frame.
185
+ *
186
+ * SNAPSHOT SEMANTIC: The frame passed here is the snapshot captured at render
187
+ * time. Any resources created during this execution will observe this frozen
188
+ * snapshot, ensuring deterministic behavior.
189
+ */
190
+ function ContextFunctionChildInvoker(props) {
191
+ const { fn, __frame } = props;
192
+ const res = withContext(__frame, () => fn());
193
+ if (res) return markWithFrame(res, __frame);
194
+ return null;
195
+ }
196
+ /**
197
+ * Get the current context frame for inspection (used by tests/diagnostics only)
198
+ */
199
+ function getCurrentContextFrame() {
200
+ return currentContextFrame;
201
+ }
202
+ //#endregion
203
+ export { defineContext, getCurrentContextFrame, getVNodeContextFrame, markVNodeTreeWithContextFrame, readContext, withAsyncResourceContext, withContext };
204
+
205
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","names":[],"sources":["../../src/runtime/context.ts"],"sourcesContent":["/**\n * Context system: lexical scope + render-time snapshots\n *\n * CORE SEMANTIC (Option A — Snapshot-Based):\n * ============================================\n * An async resource observes the context of the render that created it.\n * Context changes only take effect via re-render, not magically mid-await.\n *\n * This ensures:\n * - Deterministic behavior\n * - Concurrency safety\n * - Replayable execution\n * - Debuggability\n *\n * INVARIANTS:\n * - readContext() only works during component render (has currentContextFrame)\n * - Each render captures a context snapshot\n * - Async continuations see the snapshot from render start (frozen)\n * - Provider (Scope) creates a new frame that shadows parent\n * - Context updates require re-render to take effect\n */\n\nimport type { JSXElement } from '../common/jsx';\nimport { ELEMENT_TYPE, STATIC_CHILDREN } from '../common/jsx';\nimport type { Props } from '../common/props';\nimport { getCurrentComponentInstance } from './component';\nimport type { ComponentInstance } from './component';\n\nexport type ContextKey = symbol;\n\n// Lightweight VNode definition used for JSX typing in this module\ntype VNode = {\n type: string;\n props?: Record<string, unknown>;\n children?: (string | VNode | null | undefined | false)[];\n};\n\n// Union of allowed render return values (text, vnode, JSX element, etc.)\ntype Renderable =\n | JSXElement\n | VNode\n | string\n | number\n | null\n | undefined\n | false;\n\nexport interface Context<T> {\n readonly key: ContextKey;\n readonly defaultValue: T;\n // A Scope is a JSX-style element factory returning a JSXElement (component invocation)\n readonly Scope: (props: { value: unknown; children?: unknown }) => JSXElement;\n}\n\nexport interface ContextFrame {\n parent: ContextFrame | null;\n // Lazily allocate `values` Map only when a provider sets values or a read occurs.\n values: Map<ContextKey, unknown> | null;\n}\n\n// Symbol to mark vnodes that need frame restoration\nexport const CONTEXT_FRAME_SYMBOL = Symbol('__tempoContextFrame__');\n\ntype ContextFrameCarrier = {\n [CONTEXT_FRAME_SYMBOL]?: ContextFrame;\n};\n\nconst vnodeContextFrames = new WeakMap<object, ContextFrame>();\n\nexport function getVNodeContextFrame(node: unknown): ContextFrame | undefined {\n if (typeof node !== 'object' || node === null) {\n return undefined;\n }\n\n const objectNode = node as ContextFrameCarrier;\n return vnodeContextFrames.get(node) ?? objectNode[CONTEXT_FRAME_SYMBOL];\n}\n\nexport function markVNodeWithContextFrame(\n node: unknown,\n frame: ContextFrame,\n overwrite = false\n): void {\n if (typeof node !== 'object' || node === null) {\n return;\n }\n\n if (!overwrite && getVNodeContextFrame(node)) {\n return;\n }\n\n const objectNode = node as ContextFrameCarrier;\n if (Object.prototype.hasOwnProperty.call(node, CONTEXT_FRAME_SYMBOL)) {\n try {\n objectNode[CONTEXT_FRAME_SYMBOL] = frame;\n return;\n } catch {\n // Fall through to WeakMap metadata when the symbol slot is readonly.\n }\n }\n\n if (Object.isExtensible(node)) {\n try {\n Object.defineProperty(node, CONTEXT_FRAME_SYMBOL, {\n value: frame,\n writable: true,\n enumerable: true,\n configurable: true,\n });\n return;\n } catch {\n // Fall through to WeakMap metadata for exotic objects/proxies.\n }\n }\n\n vnodeContextFrames.set(node, frame);\n}\n\nfunction isVNodeLike(value: unknown): boolean {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return false;\n }\n\n const objectValue = value as Record<string | symbol, unknown>;\n if (objectValue.$$typeof === ELEMENT_TYPE) {\n return true;\n }\n\n return (\n 'type' in objectValue &&\n ('props' in objectValue || 'children' in objectValue)\n );\n}\n\nfunction markContextPropValue(\n value: unknown,\n frame: ContextFrame,\n overwrite: boolean\n): void {\n if (Array.isArray(value)) {\n for (const item of value) {\n markContextPropValue(item, frame, overwrite);\n }\n return;\n }\n\n if (isVNodeLike(value)) {\n markVNodeTreeWithContextFrame(value, frame, overwrite);\n }\n}\n\nexport function markVNodeTreeWithContextFrame(\n node: unknown,\n frame: ContextFrame | null,\n overwrite = false\n): unknown {\n if (!frame) return node;\n\n if (Array.isArray(node)) {\n for (const child of node) {\n markVNodeTreeWithContextFrame(child, frame, overwrite);\n }\n return node;\n }\n\n if (typeof node !== 'object' || node === null) {\n return node;\n }\n\n markVNodeWithContextFrame(node, frame, overwrite);\n\n const objectNode = node as Record<string | symbol, unknown>;\n const props =\n typeof objectNode.props === 'object' && objectNode.props !== null\n ? (objectNode.props as Record<string, unknown>)\n : null;\n const children = (props?.children ?? objectNode.children) as unknown;\n\n if (Array.isArray(children)) {\n for (const child of children) {\n markVNodeTreeWithContextFrame(child, frame, overwrite);\n }\n } else if (children) {\n markVNodeTreeWithContextFrame(children, frame, overwrite);\n }\n\n if (props) {\n for (const key in props) {\n if (key !== 'children') {\n markContextPropValue(props[key], frame, overwrite);\n }\n }\n }\n\n return node;\n}\n\n// Global context frame stack (maintained during render)\n// INVARIANT: Must NEVER be non-null across an await boundary\nlet currentContextFrame: ContextFrame | null = null;\n\n// Async resource frame (maintained during async resource execution)\n// INVARIANT: Set only for synchronous execution steps, cleared in finally\n// This allows async resources to access their frozen render-time snapshot\nlet currentAsyncResourceFrame: ContextFrame | null = null;\n\n/**\n * Execute a function within a specific context frame.\n *\n * CORE PRIMITIVE for context restoration:\n * - Saves the current context\n * - Sets the provided frame as current\n * - Executes the function\n * - Restores the previous context in finally\n *\n * This ensures no context frame remains globally active across await.\n */\nexport function withContext<T>(frame: ContextFrame | null, fn: () => T): T {\n const oldFrame = currentContextFrame;\n currentContextFrame = frame;\n try {\n return fn();\n } finally {\n currentContextFrame = oldFrame;\n }\n}\n\n/**\n * Execute an async resource step within its frozen context snapshot.\n *\n * CRITICAL: This wrapper is applied only to synchronous execution steps of\n * an async resource (the initial call). We intentionally DO NOT restore\n * the resource frame for post-await continuations — continuations must not\n * observe or rely on a live resource frame. This keeps semantics simple and\n * deterministic: async resources see only their creation-time snapshot.\n */\nexport function withAsyncResourceContext<T>(\n frame: ContextFrame | null,\n fn: () => T\n): T {\n const oldFrame = currentAsyncResourceFrame;\n // Only set the frame for the synchronous execution step\n currentAsyncResourceFrame = frame;\n try {\n return fn();\n } finally {\n // Clear the frame to avoid exposing it across await boundaries\n currentAsyncResourceFrame = oldFrame;\n }\n}\n\nexport function defineContext<T>(defaultValue: T): Context<T> {\n const key = Symbol('AskrContext');\n\n return {\n key,\n defaultValue,\n Scope: (props: { value: unknown; children?: unknown }): JSXElement => {\n // Scope component: accepts an unknown value (tests often pass loosely typed values)\n // Cast to the expected T at the call site to preserve runtime behavior.\n const value = props.value as T;\n // Scope component: creates a new frame and renders children within it\n return {\n $$typeof: ELEMENT_TYPE,\n type: ContextScopeComponent,\n props: { key, value, children: props.children },\n key: null,\n } as JSXElement;\n },\n };\n}\n\nfunction preserveStaticChildrenMarker(\n source: readonly unknown[],\n target: unknown[]\n): unknown[] {\n if (\n (\n source as {\n [STATIC_CHILDREN]?: boolean;\n }\n )[STATIC_CHILDREN] === true\n ) {\n Object.defineProperty(target, STATIC_CHILDREN, {\n value: true,\n enumerable: false,\n configurable: true,\n });\n }\n\n return target;\n}\n\nexport function readContext<T>(context: Context<T>): T {\n // Check render frame first (components), then async resource frame (resources)\n const frame = currentContextFrame || currentAsyncResourceFrame;\n\n if (!frame) {\n throw new Error(\n 'readContext() can only be called during component render or async resource execution. ' +\n 'Ensure you are calling this from inside your component or resource function.'\n );\n }\n\n let current: ContextFrame | null = frame;\n while (current) {\n // `values` may be null when no provider has created it yet — treat as empty\n const values = current.values;\n if (values && values.has(context.key)) {\n return values.get(context.key) as T;\n }\n current = current.parent;\n }\n return context.defaultValue;\n}\n\n/**\n * Internal component that manages context frame\n * Used by Context.Scope to provide shadowed value to children\n */\nfunction ContextScopeComponent(props: Props): Renderable {\n // Extract expected properties (we accept a loose shape so this can be used as a component type)\n const key = props['key'] as ContextKey;\n const value = props['value'];\n const children = props['children'] as Renderable;\n\n // Create a new frame with this value\n const instance = getCurrentComponentInstance();\n const parentFrame: ContextFrame | null = (() => {\n // Prefer the live render frame.\n // Note: the runtime executes component functions inside an empty \"render frame\"\n // whose parent points at the nearest provider chain. Even if this frame has no\n // values, it must still be used to preserve the parent linkage.\n if (currentContextFrame) return currentContextFrame;\n\n // If there is no live render frame (should be rare), fall back to the\n // instance's owner frame.\n if (instance && instance.ownerFrame) return instance.ownerFrame;\n\n // Do NOT fall back to the async snapshot stack here: that stack represents\n // unrelated async continuations and must not affect lexical provider chaining.\n return null;\n })();\n\n const newFrame: ContextFrame = {\n parent: parentFrame,\n values: new Map([[key, value]]),\n };\n\n // Helper: create a function-child invoker node (centralized cast)\n function createFunctionChildInvoker(\n fn: () => Renderable,\n frame: ContextFrame,\n owner: ComponentInstance | null\n ): Renderable {\n return {\n type: ContextFunctionChildInvoker,\n props: { fn, __frame: frame, __owner: owner },\n } as unknown as Renderable;\n }\n\n // The renderer will set ownerFrame on child component instances when they're created.\n // We mark vnodes with the frame so the renderer knows which frame to assign.\n if (Array.isArray(children)) {\n // Mark array elements with the frame. If an element is a function-child,\n // convert it into a lazy invoker so it's executed later inside the frame.\n return preserveStaticChildrenMarker(\n children,\n children.map((child) => {\n if (typeof child === 'function') {\n return createFunctionChildInvoker(\n child as () => Renderable,\n newFrame,\n getCurrentComponentInstance()\n );\n }\n return markWithFrame(child, newFrame);\n })\n ) as unknown as Renderable;\n } else if (typeof children === 'function') {\n // If children is a function (render callback), do NOT execute it eagerly\n // during the parent render. Instead, return a small internal component\n // that will execute the function later (when it itself is rendered) and\n // will execute it within the provider frame so any reads performed during\n // that execution observe the provider's frame.\n return createFunctionChildInvoker(\n children as () => Renderable,\n newFrame,\n getCurrentComponentInstance()\n );\n } else if (children) {\n return markWithFrame(children, newFrame);\n }\n\n return null;\n}\n\n/**\n * Internal: Mark a vnode with a context frame\n * The renderer will restore this frame before executing component functions\n */\nfunction markWithFrame(node: Renderable, frame: ContextFrame): Renderable {\n return markVNodeTreeWithContextFrame(node, frame, true) as Renderable;\n}\n\n/**\n * Internal helper component: executes a function-child lazily inside the\n * provided frame and marks the returned subtree with that frame so later\n * component executions will restore the correct context frame.\n *\n * SNAPSHOT SEMANTIC: The frame passed here is the snapshot captured at render\n * time. Any resources created during this execution will observe this frozen\n * snapshot, ensuring deterministic behavior.\n */\nfunction ContextFunctionChildInvoker(props: {\n fn: () => Renderable;\n __frame: ContextFrame;\n __owner?: ComponentInstance | null;\n}): Renderable {\n const { fn, __frame } = props;\n\n // Execute the function-child within the provider frame.\n // The owner's ownerFrame is already set by the renderer when the component was created.\n // Any resources started during this execution will capture this frame as their\n // snapshot, ensuring they see the context values from this render, not future renders.\n const res = withContext(__frame, () => fn());\n\n // Mark the result so the renderer knows to set ownerFrame on child instances\n if (res) return markWithFrame(res, __frame);\n return null;\n}\n\n/**\n * Push a new context frame (for render entry)\n * Called by component runtime when render starts\n */\nexport function pushContextFrame(): ContextFrame {\n // Lazily allocate the `values` map to avoid per-render allocations when\n // components do not use context. The map will be created when a provider\n // sets a value or when a read discovers no map and needs to behave as empty.\n const frame: ContextFrame = {\n parent: currentContextFrame,\n values: null,\n };\n currentContextFrame = frame;\n return frame;\n}\n\n/**\n * Pop context frame (for render exit)\n * Called by component runtime when render ends\n */\nexport function popContextFrame(): void {\n if (currentContextFrame) {\n currentContextFrame = currentContextFrame.parent;\n }\n}\n\n/**\n * Get the current context frame for inspection (used by tests/diagnostics only)\n */\nexport function getCurrentContextFrame(): ContextFrame | null {\n return currentContextFrame;\n}\n\n/**\n * Get the top of the context snapshot stack (used by runtime when deciding\n * how to link snapshots for async continuations). Returns null if stack empty.\n */\nexport function getTopContextSnapshot(): ContextFrame | null {\n return currentContextFrame;\n}\n"],"mappings":";;;AA6DA,MAAa,uBAAuB,OAAO,wBAAwB;AAMnE,MAAM,qCAAqB,IAAI,SAA+B;AAE9D,SAAgB,qBAAqB,MAAyC;AAC5E,KAAI,OAAO,SAAS,YAAY,SAAS,KACvC;CAGF,MAAM,aAAa;AACnB,QAAO,mBAAmB,IAAI,KAAK,IAAI,WAAW;;AAGpD,SAAgB,0BACd,MACA,OACA,YAAY,OACN;AACN,KAAI,OAAO,SAAS,YAAY,SAAS,KACvC;AAGF,KAAI,CAAC,aAAa,qBAAqB,KAAK,CAC1C;CAGF,MAAM,aAAa;AACnB,KAAI,OAAO,UAAU,eAAe,KAAK,MAAM,qBAAqB,CAClE,KAAI;AACF,aAAW,wBAAwB;AACnC;SACM;AAKV,KAAI,OAAO,aAAa,KAAK,CAC3B,KAAI;AACF,SAAO,eAAe,MAAM,sBAAsB;GAChD,OAAO;GACP,UAAU;GACV,YAAY;GACZ,cAAc;GACf,CAAC;AACF;SACM;AAKV,oBAAmB,IAAI,MAAM,MAAM;;AAGrC,SAAS,YAAY,OAAyB;AAC5C,KAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,MAAM,CACrE,QAAO;CAGT,MAAM,cAAc;AACpB,KAAI,YAAY,aAAa,aAC3B,QAAO;AAGT,QACE,UAAU,gBACT,WAAW,eAAe,cAA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T,QAAO,cAAc,UAAU,SAAS;AAG1C,QAAO;;;;;;AAOT,SAAS,cAAc,MAAkB,OAAiC;AACxE,QAAO,8BAA8B,MAAM,OAAO,KAAK;;;;;;;;;;;AAYzD,SAAS,4BAA4B,OAItB;CACb,MAAM,EAAE,IAAI,YAAY;CAMxB,MAAM,MAAM,YAAY,eAAe,IAAI,CAAC;AAG5C,KAAI,IAAK,QAAO,cAAc,KAAK,QAAQ;AAC3C,QAAO;;;;;AAgCT,SAAgB,yBAA8C;AAC5D,QAAO"}
@@ -0,0 +1,43 @@
1
+ import { ComponentInstance } from "./component.js";
2
+ import { ChildScope } from "./child-scope.js";
3
+ import { ForState } from "./for.js";
4
+ import { VNode } from "../common/vnode.js";
5
+
6
+ //#region src/runtime/control.d.ts
7
+ interface MatchBranch {
8
+ key: string | number;
9
+ render: () => VNode;
10
+ when: unknown;
11
+ }
12
+ interface BranchControlStateBase {
13
+ activeKey: string | number | null;
14
+ activeScope: ChildScope | null;
15
+ activeVNodes: VNode[];
16
+ lastRemovedNodes: Node[];
17
+ parentInstance: ComponentInstance | null;
18
+ _enqueueBoundaryCommit?: (() => void) | null;
19
+ _hasPendingBoundaryCommit?: boolean;
20
+ }
21
+ interface ShowState extends BranchControlStateBase {
22
+ kind: 'show';
23
+ fallbackScope: ChildScope | null;
24
+ renderFallback: (() => VNode) | null;
25
+ renderTruthy: ((value: unknown) => VNode) | (() => VNode);
26
+ selectedValue: unknown;
27
+ truthyScope: ChildScope | null;
28
+ }
29
+ interface CaseState extends BranchControlStateBase {
30
+ kind: 'case';
31
+ fallback: (() => VNode) | null;
32
+ matches: MatchBranch[];
33
+ }
34
+ type ControlBoundaryState = ForState<unknown> | ShowState | CaseState;
35
+ declare function createShowState(value: unknown, renderTruthy: ShowState['renderTruthy'], renderFallback: ShowState['renderFallback']): ShowState;
36
+ declare function evaluateShowState(state: ShowState): VNode[];
37
+ declare function clearShowDomUpdateState(state: ShowState): void;
38
+ declare function createCaseState(matches: MatchBranch[], fallback: (() => VNode) | null): CaseState;
39
+ declare function evaluateCaseState(state: CaseState): VNode[];
40
+ declare function clearCaseDomUpdateState(state: CaseState): void;
41
+ //#endregion
42
+ export { ControlBoundaryState };
43
+ //# sourceMappingURL=control.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control.d.ts","names":[],"sources":["../../src/runtime/control.ts"],"mappings":";;;;;;UASiB,WAAA;EACf,GAAA;EACA,MAAA,QAAc,KAAA;EACd,IAAA;AAAA;AAAA,UAGQ,sBAAA;EACR,SAAA;EACA,WAAA,EAAa,UAAA;EACb,YAAA,EAAc,KAAA;EACd,gBAAA,EAAkB,IAAA;EAClB,cAAA,EAAgB,iBAAA;EAChB,sBAAA;EACA,yBAAA;AAAA;AAAA,UAGe,SAAA,SAAkB,sBAAA;EACjC,IAAA;EACA,aAAA,EAAe,UAAA;EACf,cAAA,SAAuB,KAAA;EACvB,YAAA,IAAgB,KAAA,cAAmB,KAAA,WAAgB,KAAA;EACnD,aAAA;EACA,WAAA,EAAa,UAAA;AAAA;AAAA,UAGE,SAAA,SAAkB,sBAAA;EACjC,IAAA;EACA,QAAA,SAAiB,KAAA;EACjB,OAAA,EAAS,WAAA;AAAA;AAAA,KAGC,oBAAA,GAAuB,QAAA,YAAoB,SAAA,GAAY,SAAA;AAAA,iBAkCnD,eAAA,CACd,KAAA,WACA,YAAA,EAAc,SAAA,kBACd,cAAA,EAAgB,SAAA,qBACf,SAAA;AAAA,iBAkBa,iBAAA,CAAkB,KAAA,EAAO,SAAA,GAAY,KAAA;AAAA,iBAiDrC,uBAAA,CAAwB,KAAA,EAAO,SAAA;AAAA,iBAU/B,eAAA,CACd,OAAA,EAAS,WAAA,IACT,QAAA,SAAiB,KAAA,WAChB,SAAA;AAAA,iBAea,iBAAA,CAAkB,KAAA,EAAO,SAAA,GAAY,KAAA;AAAA,iBAiCrC,uBAAA,CAAwB,KAAA,EAAO,SAAA"}
@@ -0,0 +1,125 @@
1
+ import { getCurrentInstance } from "./component.js";
2
+ import { createChildScope, disposeChildScope } from "./child-scope.js";
3
+ //#region src/runtime/control.ts
4
+ const SHOW_TRUTHY_KEY = "__show-truthy__";
5
+ const SHOW_FALLBACK_KEY = "__show-fallback__";
6
+ const CASE_FALLBACK_KEY = "__case-fallback__";
7
+ function disposeBranchScope(state, scope) {
8
+ if (!scope) return;
9
+ const removedDom = scope.dom;
10
+ disposeChildScope(scope);
11
+ if (removedDom) state.lastRemovedNodes.push(removedDom);
12
+ }
13
+ function createBranchScope(state, key) {
14
+ return createChildScope(state.parentInstance, key, () => {
15
+ if (state._enqueueBoundaryCommit) {
16
+ state._enqueueBoundaryCommit();
17
+ return;
18
+ }
19
+ state.parentInstance?._enqueueRun?.();
20
+ });
21
+ }
22
+ function createShowState(value, renderTruthy, renderFallback) {
23
+ return {
24
+ kind: "show",
25
+ activeKey: null,
26
+ activeScope: null,
27
+ activeVNodes: [],
28
+ fallbackScope: null,
29
+ lastRemovedNodes: [],
30
+ parentInstance: getCurrentInstance(),
31
+ _enqueueBoundaryCommit: null,
32
+ _hasPendingBoundaryCommit: false,
33
+ renderFallback,
34
+ renderTruthy,
35
+ selectedValue: value,
36
+ truthyScope: null
37
+ };
38
+ }
39
+ function evaluateShowState(state) {
40
+ state.lastRemovedNodes = [];
41
+ if (state.selectedValue) {
42
+ if (state.fallbackScope) {
43
+ disposeBranchScope(state, state.fallbackScope);
44
+ state.fallbackScope = null;
45
+ }
46
+ const truthyScope = state.truthyScope ?? createBranchScope(state, SHOW_TRUTHY_KEY);
47
+ state.truthyScope = truthyScope;
48
+ state.activeScope = truthyScope;
49
+ state.activeKey = SHOW_TRUTHY_KEY;
50
+ const vnode = truthyScope.render(() => state.renderTruthy(state.selectedValue));
51
+ state.activeVNodes = vnode == null || vnode === false ? [] : [vnode];
52
+ return state.activeVNodes;
53
+ }
54
+ if (state.truthyScope) {
55
+ disposeBranchScope(state, state.truthyScope);
56
+ state.truthyScope = null;
57
+ }
58
+ if (!state.renderFallback) {
59
+ if (state.fallbackScope) {
60
+ disposeBranchScope(state, state.fallbackScope);
61
+ state.fallbackScope = null;
62
+ }
63
+ state.activeKey = null;
64
+ state.activeScope = null;
65
+ state.activeVNodes = [];
66
+ return state.activeVNodes;
67
+ }
68
+ const fallbackScope = state.fallbackScope ?? createBranchScope(state, SHOW_FALLBACK_KEY);
69
+ state.fallbackScope = fallbackScope;
70
+ state.activeScope = fallbackScope;
71
+ state.activeKey = SHOW_FALLBACK_KEY;
72
+ const vnode = fallbackScope.render(state.renderFallback);
73
+ state.activeVNodes = vnode == null || vnode === false ? [] : [vnode];
74
+ return state.activeVNodes;
75
+ }
76
+ function clearShowDomUpdateState(state) {
77
+ if (state.truthyScope) state.truthyScope.needsDomUpdate = false;
78
+ if (state.fallbackScope) state.fallbackScope.needsDomUpdate = false;
79
+ state.lastRemovedNodes = [];
80
+ }
81
+ function createCaseState(matches, fallback) {
82
+ return {
83
+ kind: "case",
84
+ activeKey: null,
85
+ activeScope: null,
86
+ activeVNodes: [],
87
+ fallback,
88
+ lastRemovedNodes: [],
89
+ matches,
90
+ parentInstance: getCurrentInstance(),
91
+ _enqueueBoundaryCommit: null,
92
+ _hasPendingBoundaryCommit: false
93
+ };
94
+ }
95
+ function evaluateCaseState(state) {
96
+ state.lastRemovedNodes = [];
97
+ const selectedMatch = state.matches.find((candidate) => Boolean(candidate.when)) ?? null;
98
+ const nextKey = selectedMatch?.key ?? (state.fallback ? CASE_FALLBACK_KEY : null);
99
+ if (nextKey === null) {
100
+ if (state.activeScope) disposeBranchScope(state, state.activeScope);
101
+ state.activeKey = null;
102
+ state.activeScope = null;
103
+ state.activeVNodes = [];
104
+ return state.activeVNodes;
105
+ }
106
+ if (state.activeScope && state.activeKey !== nextKey) {
107
+ disposeBranchScope(state, state.activeScope);
108
+ state.activeScope = null;
109
+ }
110
+ const activeScope = state.activeScope ?? createBranchScope(state, nextKey);
111
+ state.activeKey = nextKey;
112
+ state.activeScope = activeScope;
113
+ const renderBranch = selectedMatch?.render ?? state.fallback;
114
+ const vnode = renderBranch ? activeScope.render(renderBranch) : null;
115
+ state.activeVNodes = vnode == null || vnode === false ? [] : [vnode];
116
+ return state.activeVNodes;
117
+ }
118
+ function clearCaseDomUpdateState(state) {
119
+ if (state.activeScope) state.activeScope.needsDomUpdate = false;
120
+ state.lastRemovedNodes = [];
121
+ }
122
+ //#endregion
123
+ export { clearCaseDomUpdateState, clearShowDomUpdateState, createCaseState, createShowState, evaluateCaseState, evaluateShowState };
124
+
125
+ //# sourceMappingURL=control.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control.js","names":[],"sources":["../../src/runtime/control.ts"],"sourcesContent":["import type { VNode } from '../common/vnode';\nimport {\n createChildScope,\n disposeChildScope,\n type ChildScope,\n} from './child-scope';\nimport { getCurrentInstance, type ComponentInstance } from './component';\nimport type { ForState } from './for';\n\nexport interface MatchBranch {\n key: string | number;\n render: () => VNode;\n when: unknown;\n}\n\ninterface BranchControlStateBase {\n activeKey: string | number | null;\n activeScope: ChildScope | null;\n activeVNodes: VNode[];\n lastRemovedNodes: Node[];\n parentInstance: ComponentInstance | null;\n _enqueueBoundaryCommit?: (() => void) | null;\n _hasPendingBoundaryCommit?: boolean;\n}\n\nexport interface ShowState extends BranchControlStateBase {\n kind: 'show';\n fallbackScope: ChildScope | null;\n renderFallback: (() => VNode) | null;\n renderTruthy: ((value: unknown) => VNode) | (() => VNode);\n selectedValue: unknown;\n truthyScope: ChildScope | null;\n}\n\nexport interface CaseState extends BranchControlStateBase {\n kind: 'case';\n fallback: (() => VNode) | null;\n matches: MatchBranch[];\n}\n\nexport type ControlBoundaryState = ForState<unknown> | ShowState | CaseState;\n\nconst SHOW_TRUTHY_KEY = '__show-truthy__';\nconst SHOW_FALLBACK_KEY = '__show-fallback__';\nconst CASE_FALLBACK_KEY = '__case-fallback__';\n\nfunction disposeBranchScope(\n state: BranchControlStateBase,\n scope: ChildScope | null\n): void {\n if (!scope) {\n return;\n }\n const removedDom = scope.dom;\n disposeChildScope(scope);\n if (removedDom) {\n state.lastRemovedNodes.push(removedDom);\n }\n}\n\nfunction createBranchScope(\n state: BranchControlStateBase,\n key: string | number\n): ChildScope {\n return createChildScope(state.parentInstance, key, () => {\n if (state._enqueueBoundaryCommit) {\n state._enqueueBoundaryCommit();\n return;\n }\n\n state.parentInstance?._enqueueRun?.();\n });\n}\n\nexport function createShowState(\n value: unknown,\n renderTruthy: ShowState['renderTruthy'],\n renderFallback: ShowState['renderFallback']\n): ShowState {\n return {\n kind: 'show',\n activeKey: null,\n activeScope: null,\n activeVNodes: [],\n fallbackScope: null,\n lastRemovedNodes: [],\n parentInstance: getCurrentInstance(),\n _enqueueBoundaryCommit: null,\n _hasPendingBoundaryCommit: false,\n renderFallback,\n renderTruthy,\n selectedValue: value,\n truthyScope: null,\n };\n}\n\nexport function evaluateShowState(state: ShowState): VNode[] {\n state.lastRemovedNodes = [];\n\n if (state.selectedValue) {\n if (state.fallbackScope) {\n disposeBranchScope(state, state.fallbackScope);\n state.fallbackScope = null;\n }\n\n const truthyScope =\n state.truthyScope ?? createBranchScope(state, SHOW_TRUTHY_KEY);\n state.truthyScope = truthyScope;\n state.activeScope = truthyScope;\n state.activeKey = SHOW_TRUTHY_KEY;\n\n const vnode = truthyScope.render(() =>\n state.renderTruthy(state.selectedValue)\n );\n state.activeVNodes = vnode == null || vnode === false ? [] : [vnode];\n return state.activeVNodes;\n }\n\n if (state.truthyScope) {\n disposeBranchScope(state, state.truthyScope);\n state.truthyScope = null;\n }\n\n if (!state.renderFallback) {\n if (state.fallbackScope) {\n disposeBranchScope(state, state.fallbackScope);\n state.fallbackScope = null;\n }\n state.activeKey = null;\n state.activeScope = null;\n state.activeVNodes = [];\n return state.activeVNodes;\n }\n\n const fallbackScope =\n state.fallbackScope ?? createBranchScope(state, SHOW_FALLBACK_KEY);\n state.fallbackScope = fallbackScope;\n state.activeScope = fallbackScope;\n state.activeKey = SHOW_FALLBACK_KEY;\n\n const vnode = fallbackScope.render(state.renderFallback);\n state.activeVNodes = vnode == null || vnode === false ? [] : [vnode];\n return state.activeVNodes;\n}\n\nexport function clearShowDomUpdateState(state: ShowState): void {\n if (state.truthyScope) {\n state.truthyScope.needsDomUpdate = false;\n }\n if (state.fallbackScope) {\n state.fallbackScope.needsDomUpdate = false;\n }\n state.lastRemovedNodes = [];\n}\n\nexport function createCaseState(\n matches: MatchBranch[],\n fallback: (() => VNode) | null\n): CaseState {\n return {\n kind: 'case',\n activeKey: null,\n activeScope: null,\n activeVNodes: [],\n fallback,\n lastRemovedNodes: [],\n matches,\n parentInstance: getCurrentInstance(),\n _enqueueBoundaryCommit: null,\n _hasPendingBoundaryCommit: false,\n };\n}\n\nexport function evaluateCaseState(state: CaseState): VNode[] {\n state.lastRemovedNodes = [];\n\n const selectedMatch =\n state.matches.find((candidate) => Boolean(candidate.when)) ?? null;\n const nextKey =\n selectedMatch?.key ?? (state.fallback ? CASE_FALLBACK_KEY : null);\n\n if (nextKey === null) {\n if (state.activeScope) {\n disposeBranchScope(state, state.activeScope);\n }\n state.activeKey = null;\n state.activeScope = null;\n state.activeVNodes = [];\n return state.activeVNodes;\n }\n\n if (state.activeScope && state.activeKey !== nextKey) {\n disposeBranchScope(state, state.activeScope);\n state.activeScope = null;\n }\n\n const activeScope = state.activeScope ?? createBranchScope(state, nextKey);\n state.activeKey = nextKey;\n state.activeScope = activeScope;\n\n const renderBranch = selectedMatch?.render ?? state.fallback;\n const vnode = renderBranch ? activeScope.render(renderBranch) : null;\n state.activeVNodes = vnode == null || vnode === false ? [] : [vnode];\n return state.activeVNodes;\n}\n\nexport function clearCaseDomUpdateState(state: CaseState): void {\n if (state.activeScope) {\n state.activeScope.needsDomUpdate = false;\n }\n state.lastRemovedNodes = [];\n}\n"],"mappings":";;;AA0CA,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB;AAE1B,SAAS,mBACP,OACA,OACM;AACN,KAAI,CAAC,MACH;CAEF,MAAM,aAAa,MAAM;AACzB,m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B;AAErC,OAAM,mBAAmB,EAAE"}
@@ -1,13 +1,16 @@
1
- import { type ReadableSource } from './readable';
2
- export interface Derived<T> extends ReadableSource<T> {
3
- (): T;
1
+ import { ReadableSource } from "./readable.js";
2
+
3
+ //#region src/runtime/derive.d.ts
4
+ interface Derived<T> extends ReadableSource<T> {
5
+ (): T;
4
6
  }
5
7
  type SnapshotSource<T> = {
6
- value: T | null;
7
- pending?: boolean;
8
- error?: Error | null;
8
+ value: T | null;
9
+ pending?: boolean;
10
+ error?: Error | null;
9
11
  };
10
- export declare function derive<TOut>(fn: () => TOut): Derived<TOut>;
11
- export declare function derive<TIn, TOut>(source: SnapshotSource<TIn> | TIn | (() => TIn), map: (value: TIn) => TOut): Derived<TOut | null>;
12
- export {};
12
+ declare function derive<TOut>(fn: () => TOut): Derived<TOut>;
13
+ declare function derive<TIn, TOut>(source: SnapshotSource<TIn> | TIn | (() => TIn), map: (value: TIn) => TOut): Derived<TOut | null>;
14
+ //#endregion
15
+ export { Derived, derive };
13
16
  //# sourceMappingURL=derive.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"derive.d.ts","sourceRoot":"","sources":["../../src/runtime/derive.ts"],"names":[],"mappings":"AAMA,OAAO,EAQL,KAAK,cAAc,EAEpB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,OAAO,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IACnD,IAAI,CAAC,CAAC;CACP;AAgBD,KAAK,cAAc,CAAC,CAAC,IAAI;IACvB,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;CACtB,CAAC;AA0LF,wBAAgB,MAAM,CAAC,IAAI,EAAE,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5D,wBAAgB,MAAM,CAAC,GAAG,EAAE,IAAI,EAC9B,MAAM,EAAE,cAAc,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAC/C,GAAG,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,GACxB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC"}
1
+ {"version":3,"file":"derive.d.ts","names":[],"sources":["../../src/runtime/derive.ts"],"mappings":";;;UAkBiB,OAAA,YAAmB,cAAA,CAAe,CAAA;EAAA,IAC7C,CAAA;AAAA;AAAA,KAiBD,cAAA;EACH,KAAA,EAAO,CAAA;EACP,OAAA;EACA,KAAA,GAAQ,KAAA;AAAA;AAAA,iBA2LM,MAAA,MAAA,CAAa,EAAA,QAAU,IAAA,GAAO,OAAA,CAAQ,IAAA;AAAA,iBAEtC,MAAA,WAAA,CACd,MAAA,EAAQ,cAAA,CAAe,GAAA,IAAO,GAAA,UAAa,GAAA,GAC3C,GAAA,GAAM,KAAA,EAAO,GAAA,KAAQ,IAAA,GACpB,OAAA,CAAQ,IAAA"}
@@ -1 +1,134 @@
1
- import{getCurrentInstance as f,claimHookIndex as _}from"./component.js";import{globalScheduler as l}from"./scheduler.js";import{withDerivedReadTracking as v,syncDerivedDependencySubscriptions as p,markReadableDerivedSubscribersDirty as y,markReactivePropsDirtySource as D,notifyReadableReaders as h,recordReadableRead as g,clearDerivedDependencySubscriptions as S}from"./readable.js";const o=new WeakMap,a=new Set;let d=!1;function m(e){let t=o.get(e);return t||(t=new Map,o.set(e,t)),t}function w(e){e._dirty=!0,!e._scheduled&&(e._scheduled=!0,a.add(e),d||(d=!0,l.enqueueInLane("derived",b)))}function b(){if(d=!1,a.size===0)return;const e=Array.from(a);a.clear();for(const t of e)t._scheduled=!1,t._dirty&&s(t,!0)}function s(e,t){if(!e._dirty&&e._hasValue)return e._value;if(e._evaluating)throw new Error("derive() cannot read itself recursively");e._evaluating=!0,e._dirty=!1,e._pendingDependencySources=new Set;const n=e._sources;let r;try{r=v(e,e._compute)}catch(c){throw e._dirty=!0,e._pendingDependencySources=void 0,c}finally{e._evaluating=!1}const i=e._pendingDependencySources??new Set;e._pendingDependencySources=void 0,p(e,n,i),e._sources=i;const u=!e._hasValue||!Object.is(e._value,r);return e._hasValue=!0,e._value=r,u&&t&&(y(e),D(e),h(e)),e._value}function C(e,t,n){const r=function(){return g(r),s(r,r._scheduled)};return r._owner=e,r._hookIndex=t,r._compute=n,r._value=void 0,r._hasValue=!1,r._dirty=!0,r._scheduled=!1,r._evaluating=!1,r._sources=new Set,r._markDirty=()=>{w(r)},r._cleanup=()=>{r._scheduled=!1,r._dirty=!1,r._hasValue=!1,a.delete(r),S(r,r._sources),r._derivedSubscribers?.clear(),r._readers?.clear()},e.cleanupFns.push(()=>{r._cleanup(),o.get(e)?.delete(t)}),r}function R(e,t,n){const r=m(e),i=r.get(t);if(i)return i._compute=n,i._dirty=!0,i;const u=C(e,t,n);return r.set(t,u),u}function k(e,t){return()=>{let n;return typeof e=="function"&&!("value"in e)?n=e():n=e?.value??e,n==null?null:t(n)}}function E(e,t){const n=f();if(!n)throw new Error("derive() can only be called during component render execution. Move derive() calls to the top level of your component function.");const r=_(n,"derive"),i=t===void 0?e:k(e,t),u=R(n,r,i);return s(u,!1),u}export{E as derive};
1
+ import { globalScheduler } from "./scheduler.js";
2
+ import { clearDerivedDependencySubscriptions, markReactivePropsDirtySource, markReadableDerivedSubscribersDirty, notifyReadableReaders, recordReadableRead, syncDerivedDependencySubscriptions, withDerivedReadTracking } from "./readable.js";
3
+ import { claimHookIndex, getCurrentInstance } from "./component.js";
4
+ //#region src/runtime/derive.ts
5
+ const deriveCells = /* @__PURE__ */ new WeakMap();
6
+ const dirtyDerivedCells = /* @__PURE__ */ new Set();
7
+ let hasPendingDerivedFlush = false;
8
+ function getDeriveStore(instance) {
9
+ let store = deriveCells.get(instance);
10
+ if (!store) {
11
+ store = /* @__PURE__ */ new Map();
12
+ deriveCells.set(instance, store);
13
+ }
14
+ return store;
15
+ }
16
+ function markDerivedCellDirty(cell) {
17
+ cell._dirty = true;
18
+ if (cell._scheduled) return;
19
+ cell._scheduled = true;
20
+ dirtyDerivedCells.add(cell);
21
+ if (!hasPendingDerivedFlush) {
22
+ hasPendingDerivedFlush = true;
23
+ globalScheduler.enqueueInLane("derived", flushDirtyDerivedCells);
24
+ }
25
+ }
26
+ function flushDirtyDerivedCells() {
27
+ hasPendingDerivedFlush = false;
28
+ if (dirtyDerivedCells.size === 0) return;
29
+ const pending = Array.from(dirtyDerivedCells);
30
+ dirtyDerivedCells.clear();
31
+ for (const cell of pending) {
32
+ cell._scheduled = false;
33
+ if (!cell._dirty) continue;
34
+ recomputeDerivedCell(cell, true);
35
+ }
36
+ }
37
+ function recomputeDerivedCell(cell, notifyDownstream) {
38
+ if (!cell._dirty && cell._hasValue) return cell._value;
39
+ if (cell._evaluating) throw new Error("derive() cannot read itself recursively");
40
+ cell._evaluating = true;
41
+ cell._dirty = false;
42
+ cell._pendingDependencySources = /* @__PURE__ */ new Set();
43
+ const prevSources = cell._sources;
44
+ let nextValue;
45
+ try {
46
+ nextValue = withDerivedReadTracking(cell, cell._compute);
47
+ } catch (error) {
48
+ cell._dirty = true;
49
+ cell._pendingDependencySources = void 0;
50
+ throw error;
51
+ } finally {
52
+ cell._evaluating = false;
53
+ }
54
+ const nextSources = cell._pendingDependencySources ?? /* @__PURE__ */ new Set();
55
+ cell._pendingDependencySources = void 0;
56
+ syncDerivedDependencySubscriptions(cell, prevSources, nextSources);
57
+ cell._sources = nextSources;
58
+ const valueChanged = !cell._hasValue || !Object.is(cell._value, nextValue);
59
+ cell._hasValue = true;
60
+ cell._value = nextValue;
61
+ if (valueChanged && notifyDownstream) {
62
+ markReadableDerivedSubscribersDirty(cell);
63
+ markReactivePropsDirtySource(cell);
64
+ notifyReadableReaders(cell);
65
+ }
66
+ return cell._value;
67
+ }
68
+ function createDerivedCell(instance, hookIndex, compute) {
69
+ const cell = function derivedGetter() {
70
+ recordReadableRead(cell);
71
+ return recomputeDerivedCell(cell, cell._scheduled);
72
+ };
73
+ cell._owner = instance;
74
+ cell._hookIndex = hookIndex;
75
+ cell._compute = compute;
76
+ cell._value = void 0;
77
+ cell._hasValue = false;
78
+ cell._dirty = true;
79
+ cell._scheduled = false;
80
+ cell._evaluating = false;
81
+ cell._sources = /* @__PURE__ */ new Set();
82
+ cell._markDirty = () => {
83
+ markDerivedCellDirty(cell);
84
+ };
85
+ cell._cleanup = () => {
86
+ cell._scheduled = false;
87
+ cell._dirty = false;
88
+ cell._hasValue = false;
89
+ dirtyDerivedCells.delete(cell);
90
+ clearDerivedDependencySubscriptions(cell, cell._sources);
91
+ cell._derivedSubscribers?.clear();
92
+ cell._readers?.clear();
93
+ };
94
+ (instance.cleanupFns ??= []).push(() => {
95
+ cell._cleanup();
96
+ deriveCells.get(instance)?.delete(hookIndex);
97
+ });
98
+ return cell;
99
+ }
100
+ function getOrCreateDerivedCell(instance, hookIndex, compute) {
101
+ const store = getDeriveStore(instance);
102
+ const existing = store.get(hookIndex);
103
+ if (existing) {
104
+ existing._compute = compute;
105
+ existing._dirty = true;
106
+ return existing;
107
+ }
108
+ const created = createDerivedCell(instance, hookIndex, compute);
109
+ store.set(hookIndex, created);
110
+ return created;
111
+ }
112
+ function createSelector(selector) {
113
+ return selector;
114
+ }
115
+ function createMappedSelector(source, map) {
116
+ return () => {
117
+ let value;
118
+ if (typeof source === "function" && !("value" in source)) value = source();
119
+ else value = source?.value ?? source;
120
+ if (value == null) return null;
121
+ return map(value);
122
+ };
123
+ }
124
+ function derive(source, map) {
125
+ const instance = getCurrentInstance();
126
+ if (!instance) throw new Error("derive() can only be called during component render execution. Move derive() calls to the top level of your component function.");
127
+ const cell = getOrCreateDerivedCell(instance, claimHookIndex(instance, "derive"), map === void 0 ? createSelector(source) : createMappedSelector(source, map));
128
+ recomputeDerivedCell(cell, false);
129
+ return cell;
130
+ }
131
+ //#endregion
132
+ export { derive };
133
+
134
+ //# sourceMappingURL=derive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derive.js","names":[],"sources":["../../src/runtime/derive.ts"],"sourcesContent":["import {\n claimHookIndex,\n getCurrentInstance,\n type ComponentInstance,\n} from './component';\nimport { globalScheduler } from './scheduler';\nimport {\n clearDerivedDependencySubscriptions,\n markReadableDerivedSubscribersDirty,\n markReactivePropsDirtySource,\n notifyReadableReaders,\n recordReadableRead,\n syncDerivedDependencySubscriptions,\n type DerivedSubscriber,\n type ReadableSource,\n withDerivedReadTracking,\n} from './readable';\n\nexport interface Derived<T> extends ReadableSource<T> {\n (): T;\n}\n\ninterface DerivedCell<T> extends Derived<T>, DerivedSubscriber {\n _owner: ComponentInstance;\n _hookIndex: number;\n _compute: () => T;\n _value: T;\n _hasValue: boolean;\n _dirty: boolean;\n _scheduled: boolean;\n _evaluating: boolean;\n _sources: Set<ReadableSource<unknown>>;\n _pendingDependencySources?: Set<ReadableSource<unknown>>;\n _cleanup(): void;\n}\n\ntype SnapshotSource<T> = {\n value: T | null;\n pending?: boolean;\n error?: Error | null;\n};\n\nconst deriveCells = new WeakMap<\n ComponentInstance,\n Map<number, DerivedCell<unknown>>\n>();\nconst dirtyDerivedCells = new Set<DerivedCell<unknown>>();\nlet hasPendingDerivedFlush = false;\n\nfunction getDeriveStore(\n instance: ComponentInstance\n): Map<number, DerivedCell<unknown>> {\n let store = deriveCells.get(instance);\n if (!store) {\n store = new Map();\n deriveCells.set(instance, store);\n }\n return store;\n}\n\nfunction markDerivedCellDirty(cell: DerivedCell<unknown>): void {\n cell._dirty = true;\n if (cell._scheduled) {\n return;\n }\n\n cell._scheduled = true;\n dirtyDerivedCells.add(cell);\n\n if (!hasPendingDerivedFlush) {\n hasPendingDerivedFlush = true;\n globalScheduler.enqueueInLane('derived', flushDirtyDerivedCells);\n }\n}\n\nfunction flushDirtyDerivedCells(): void {\n hasPendingDerivedFlush = false;\n\n if (dirtyDerivedCells.size === 0) {\n return;\n }\n\n const pending = Array.from(dirtyDerivedCells);\n dirtyDerivedCells.clear();\n\n for (const cell of pending) {\n cell._scheduled = false;\n if (!cell._dirty) {\n continue;\n }\n recomputeDerivedCell(cell, true);\n }\n}\n\nfunction recomputeDerivedCell<T>(\n cell: DerivedCell<T>,\n notifyDownstream: boolean\n): T {\n if (!cell._dirty && cell._hasValue) {\n return cell._value;\n }\n\n if (cell._evaluating) {\n throw new Error('derive() cannot read itself recursively');\n }\n\n cell._evaluating = true;\n cell._dirty = false;\n cell._pendingDependencySources = new Set();\n\n const prevSources = cell._sources;\n let nextValue: T;\n\n try {\n nextValue = withDerivedReadTracking(cell, cell._compute);\n } catch (error) {\n cell._dirty = true;\n cell._pendingDependencySources = undefined;\n throw error;\n } finally {\n cell._evaluating = false;\n }\n\n const nextSources = cell._pendingDependencySources ?? new Set();\n cell._pendingDependencySources = undefined;\n syncDerivedDependencySubscriptions(cell, prevSources, nextSources);\n cell._sources = nextSources;\n\n const valueChanged = !cell._hasValue || !Object.is(cell._value, nextValue);\n cell._hasValue = true;\n cell._value = nextValue;\n\n if (valueChanged && notifyDownstream) {\n markReadableDerivedSubscribersDirty(cell);\n markReactivePropsDirtySource(cell);\n notifyReadableReaders(cell);\n }\n\n return cell._value;\n}\n\nfunction createDerivedCell<T>(\n instance: ComponentInstance,\n hookIndex: number,\n compute: () => T\n): DerivedCell<T> {\n const cell = function derivedGetter(): T {\n recordReadableRead(cell as DerivedCell<T>);\n return recomputeDerivedCell(\n cell as DerivedCell<T>,\n (cell as DerivedCell<T>)._scheduled\n );\n } as DerivedCell<T>;\n\n cell._owner = instance;\n cell._hookIndex = hookIndex;\n cell._compute = compute;\n cell._value = undefined as T;\n cell._hasValue = false;\n cell._dirty = true;\n cell._scheduled = false;\n cell._evaluating = false;\n cell._sources = new Set();\n cell._markDirty = () => {\n markDerivedCellDirty(cell);\n };\n cell._cleanup = () => {\n cell._scheduled = false;\n cell._dirty = false;\n cell._hasValue = false;\n dirtyDerivedCells.delete(cell);\n clearDerivedDependencySubscriptions(cell, cell._sources);\n cell._derivedSubscribers?.clear();\n cell._readers?.clear();\n };\n\n (instance.cleanupFns ??= []).push(() => {\n cell._cleanup();\n deriveCells.get(instance)?.delete(hookIndex);\n });\n\n return cell;\n}\n\nfunction getOrCreateDerivedCell<T>(\n instance: ComponentInstance,\n hookIndex: number,\n compute: () => T\n): DerivedCell<T> {\n const store = getDeriveStore(instance);\n const existing = store.get(hookIndex) as DerivedCell<T> | undefined;\n if (existing) {\n existing._compute = compute;\n existing._dirty = true;\n return existing;\n }\n\n const created = createDerivedCell(instance, hookIndex, compute);\n store.set(hookIndex, created as DerivedCell<unknown>);\n return created;\n}\n\nfunction createSelector<TOut>(selector: () => TOut): () => TOut {\n return selector;\n}\n\nfunction createMappedSelector<TIn, TOut>(\n source: SnapshotSource<TIn> | TIn | (() => TIn),\n map: (value: TIn) => TOut\n): () => TOut | null {\n return () => {\n let value: TIn;\n if (typeof source === 'function' && !('value' in source)) {\n value = (source as () => TIn)();\n } else {\n value = (source as SnapshotSource<TIn>)?.value ?? (source as TIn);\n }\n\n if (value == null) {\n return null;\n }\n\n return map(value);\n };\n}\n\nexport function derive<TOut>(fn: () => TOut): Derived<TOut>;\n\nexport function derive<TIn, TOut>(\n source: SnapshotSource<TIn> | TIn | (() => TIn),\n map: (value: TIn) => TOut\n): Derived<TOut | null>;\n\nexport function derive<TIn, TOut>(\n source: SnapshotSource<TIn> | TIn | (() => TIn),\n map?: (value: TIn) => TOut\n): Derived<TOut | null> | Derived<TIn> {\n const instance = getCurrentInstance();\n if (!instance) {\n throw new Error(\n 'derive() can only be called during component render execution. ' +\n 'Move derive() calls to the top level of your component function.'\n );\n }\n\n const hookIndex = claimHookIndex(instance, 'derive');\n const compute =\n map === undefined\n ? createSelector(source as () => TIn)\n : createMappedSelector(source, map);\n\n const cell = getOrCreateDerivedCell(\n instance,\n hookIndex,\n compute as () => TOut | null | TIn\n );\n recomputeDerivedCell(cell, false);\n return cell as Derived<TOut | null> | Derived<TIn>;\n}\n"],"mappings":";;;;AA0CA,MAAM,8BAAc,IAAI,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