@shadow-js/web 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (611) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +21 -0
  3. package/README.md +190 -2
  4. package/dist/dev/attributes.d.ts +90 -0
  5. package/dist/dev/attributes.js +196 -0
  6. package/dist/dev/attributes.js.map +1 -0
  7. package/dist/dev/autofocus.d.ts +32 -0
  8. package/dist/dev/autofocus.js +45 -0
  9. package/dist/dev/autofocus.js.map +1 -0
  10. package/dist/dev/class-style.d.ts +89 -0
  11. package/dist/dev/class-style.js +197 -0
  12. package/dist/dev/class-style.js.map +1 -0
  13. package/dist/dev/component.d.ts +23 -0
  14. package/dist/dev/component.js +42 -0
  15. package/dist/dev/component.js.map +1 -0
  16. package/dist/dev/control-flow/activity.d.ts +58 -0
  17. package/dist/dev/control-flow/activity.js +136 -0
  18. package/dist/dev/control-flow/activity.js.map +1 -0
  19. package/dist/dev/control-flow/branch.js +104 -0
  20. package/dist/dev/control-flow/branch.js.map +1 -0
  21. package/dist/dev/control-flow/client-only.d.ts +48 -0
  22. package/dist/dev/control-flow/client-only.js +50 -0
  23. package/dist/dev/control-flow/client-only.js.map +1 -0
  24. package/dist/dev/control-flow/dynamic.d.ts +82 -0
  25. package/dist/dev/control-flow/dynamic.js +134 -0
  26. package/dist/dev/control-flow/dynamic.js.map +1 -0
  27. package/dist/dev/control-flow/error-boundary.d.ts +72 -0
  28. package/dist/dev/control-flow/error-boundary.js +115 -0
  29. package/dist/dev/control-flow/error-boundary.js.map +1 -0
  30. package/dist/dev/control-flow/for.d.ts +80 -0
  31. package/dist/dev/control-flow/for.js +23 -0
  32. package/dist/dev/control-flow/for.js.map +1 -0
  33. package/dist/dev/control-flow/fragment.d.ts +38 -0
  34. package/dist/dev/control-flow/fragment.js +31 -0
  35. package/dist/dev/control-flow/fragment.js.map +1 -0
  36. package/dist/dev/control-flow/hot-link.js +64 -0
  37. package/dist/dev/control-flow/hot-link.js.map +1 -0
  38. package/dist/dev/control-flow/index-list.d.ts +48 -0
  39. package/dist/dev/control-flow/index-list.js +31 -0
  40. package/dist/dev/control-flow/index-list.js.map +1 -0
  41. package/dist/dev/control-flow/index.d.ts +15 -0
  42. package/dist/dev/control-flow/lazy.d.ts +58 -0
  43. package/dist/dev/control-flow/lazy.js +64 -0
  44. package/dist/dev/control-flow/lazy.js.map +1 -0
  45. package/dist/dev/control-flow/no-hydration.d.ts +39 -0
  46. package/dist/dev/control-flow/no-hydration.js +58 -0
  47. package/dist/dev/control-flow/no-hydration.js.map +1 -0
  48. package/dist/dev/control-flow/portal.d.ts +69 -0
  49. package/dist/dev/control-flow/portal.js +134 -0
  50. package/dist/dev/control-flow/portal.js.map +1 -0
  51. package/dist/dev/control-flow/root-errors.d.ts +25 -0
  52. package/dist/dev/control-flow/root-errors.js +33 -0
  53. package/dist/dev/control-flow/root-errors.js.map +1 -0
  54. package/dist/dev/control-flow/show.d.ts +101 -0
  55. package/dist/dev/control-flow/show.js +18 -0
  56. package/dist/dev/control-flow/show.js.map +1 -0
  57. package/dist/dev/control-flow/suspense-list.d.ts +65 -0
  58. package/dist/dev/control-flow/suspense-list.js +105 -0
  59. package/dist/dev/control-flow/suspense-list.js.map +1 -0
  60. package/dist/dev/control-flow/suspense.d.ts +53 -0
  61. package/dist/dev/control-flow/suspense.js +102 -0
  62. package/dist/dev/control-flow/suspense.js.map +1 -0
  63. package/dist/dev/control-flow/switch.d.ts +85 -0
  64. package/dist/dev/control-flow/switch.js +90 -0
  65. package/dist/dev/control-flow/switch.js.map +1 -0
  66. package/dist/dev/derived.d.ts +52 -0
  67. package/dist/dev/derived.js +34 -0
  68. package/dist/dev/derived.js.map +1 -0
  69. package/dist/dev/element.d.ts +40 -0
  70. package/dist/dev/element.js +105 -0
  71. package/dist/dev/element.js.map +1 -0
  72. package/dist/dev/events.d.ts +87 -0
  73. package/dist/dev/events.js +265 -0
  74. package/dist/dev/events.js.map +1 -0
  75. package/dist/dev/extend.d.ts +12 -0
  76. package/dist/dev/extend.js +12 -0
  77. package/dist/dev/head/components.d.ts +137 -0
  78. package/dist/dev/head/components.js +170 -0
  79. package/dist/dev/head/components.js.map +1 -0
  80. package/dist/dev/head/registry.js +68 -0
  81. package/dist/dev/head/registry.js.map +1 -0
  82. package/dist/dev/head/server-head.d.ts +54 -0
  83. package/dist/dev/head/server-head.js +76 -0
  84. package/dist/dev/head/server-head.js.map +1 -0
  85. package/dist/dev/head/sink.js +96 -0
  86. package/dist/dev/head/sink.js.map +1 -0
  87. package/dist/dev/head/use-head.d.ts +35 -0
  88. package/dist/dev/head/use-head.js +84 -0
  89. package/dist/dev/head/use-head.js.map +1 -0
  90. package/dist/dev/head/validate.d.ts +85 -0
  91. package/dist/dev/head/validate.js +268 -0
  92. package/dist/dev/head/validate.js.map +1 -0
  93. package/dist/dev/hmr.d.ts +82 -0
  94. package/dist/dev/hmr.js +124 -0
  95. package/dist/dev/hmr.js.map +1 -0
  96. package/dist/dev/hydration.d.ts +61 -0
  97. package/dist/dev/hydration.js +120 -0
  98. package/dist/dev/hydration.js.map +1 -0
  99. package/dist/dev/index.d.ts +45 -0
  100. package/dist/dev/index.js +34 -0
  101. package/dist/dev/insert.d.ts +97 -0
  102. package/dist/dev/insert.js +357 -0
  103. package/dist/dev/insert.js.map +1 -0
  104. package/dist/dev/internal/claim.d.ts +106 -0
  105. package/dist/dev/internal/claim.js +357 -0
  106. package/dist/dev/internal/claim.js.map +1 -0
  107. package/dist/dev/internal/css-units.js +26 -0
  108. package/dist/dev/internal/css-units.js.map +1 -0
  109. package/dist/dev/internal/diagnostics.d.ts +30 -0
  110. package/dist/dev/internal/diagnostics.js +38 -0
  111. package/dist/dev/internal/diagnostics.js.map +1 -0
  112. package/dist/dev/internal/early-events.js +76 -0
  113. package/dist/dev/internal/early-events.js.map +1 -0
  114. package/dist/dev/internal/hydration-hooks.d.ts +43 -0
  115. package/dist/dev/internal/hydration-hooks.js +27 -0
  116. package/dist/dev/internal/hydration-hooks.js.map +1 -0
  117. package/dist/dev/internal/hydration-scope.d.ts +131 -0
  118. package/dist/dev/internal/hydration-scope.js +156 -0
  119. package/dist/dev/internal/hydration-scope.js.map +1 -0
  120. package/dist/dev/internal/names.d.ts +33 -0
  121. package/dist/dev/internal/names.js +35 -0
  122. package/dist/dev/internal/names.js.map +1 -0
  123. package/dist/dev/internal/portal-context.d.ts +39 -0
  124. package/dist/dev/internal/portal-context.js +28 -0
  125. package/dist/dev/internal/portal-context.js.map +1 -0
  126. package/dist/dev/internal/react-names.js +116 -0
  127. package/dist/dev/internal/react-names.js.map +1 -0
  128. package/dist/dev/internal/reconcile.d.ts +40 -0
  129. package/dist/dev/internal/reconcile.js +122 -0
  130. package/dist/dev/internal/reconcile.js.map +1 -0
  131. package/dist/dev/internal/stream-context.d.ts +47 -0
  132. package/dist/dev/internal/stream-context.js +23 -0
  133. package/dist/dev/internal/stream-context.js.map +1 -0
  134. package/dist/dev/jsx/aria.d.ts +72 -0
  135. package/dist/dev/jsx/component.d.ts +89 -0
  136. package/dist/dev/jsx/events.d.ts +364 -0
  137. package/dist/dev/jsx/global.d.ts +211 -0
  138. package/dist/dev/jsx/html.d.ts +879 -0
  139. package/dist/dev/jsx/intrinsic.d.ts +59 -0
  140. package/dist/dev/jsx/mathml.d.ts +186 -0
  141. package/dist/dev/jsx/svg.d.ts +607 -0
  142. package/dist/dev/jsx/types.d.ts +176 -0
  143. package/dist/dev/jsx-dev-runtime.d.ts +10 -0
  144. package/dist/dev/jsx-dev-runtime.js +0 -0
  145. package/dist/dev/jsx-runtime.d.ts +94 -0
  146. package/dist/dev/jsx-runtime.js +0 -0
  147. package/dist/dev/reactive.d.ts +110 -0
  148. package/dist/dev/reactive.js +85 -0
  149. package/dist/dev/reactive.js.map +1 -0
  150. package/dist/dev/render.d.ts +36 -0
  151. package/dist/dev/render.js +52 -0
  152. package/dist/dev/render.js.map +1 -0
  153. package/dist/dev/resource-hints.d.ts +145 -0
  154. package/dist/dev/resource-hints.js +200 -0
  155. package/dist/dev/resource-hints.js.map +1 -0
  156. package/dist/dev/select-value.d.ts +24 -0
  157. package/dist/dev/select-value.js +51 -0
  158. package/dist/dev/select-value.js.map +1 -0
  159. package/dist/dev/server/attributes.d.ts +33 -0
  160. package/dist/dev/server/attributes.js +155 -0
  161. package/dist/dev/server/attributes.js.map +1 -0
  162. package/dist/dev/server/class-style.d.ts +46 -0
  163. package/dist/dev/server/class-style.js +173 -0
  164. package/dist/dev/server/class-style.js.map +1 -0
  165. package/dist/dev/server/component.d.ts +42 -0
  166. package/dist/dev/server/component.js +72 -0
  167. package/dist/dev/server/component.js.map +1 -0
  168. package/dist/dev/server/derived.d.ts +41 -0
  169. package/dist/dev/server/derived.js +26 -0
  170. package/dist/dev/server/derived.js.map +1 -0
  171. package/dist/dev/server/element.d.ts +89 -0
  172. package/dist/dev/server/element.js +216 -0
  173. package/dist/dev/server/element.js.map +1 -0
  174. package/dist/dev/server/errors.js +26 -0
  175. package/dist/dev/server/errors.js.map +1 -0
  176. package/dist/dev/server/escape.d.ts +30 -0
  177. package/dist/dev/server/escape.js +119 -0
  178. package/dist/dev/server/escape.js.map +1 -0
  179. package/dist/dev/server/form-controls.d.ts +50 -0
  180. package/dist/dev/server/form-controls.js +193 -0
  181. package/dist/dev/server/form-controls.js.map +1 -0
  182. package/dist/dev/server/hydration-script.d.ts +65 -0
  183. package/dist/dev/server/hydration-script.js +59 -0
  184. package/dist/dev/server/hydration-script.js.map +1 -0
  185. package/dist/dev/server/index.d.ts +16 -0
  186. package/dist/dev/server/index.js +16 -0
  187. package/dist/dev/server/node.d.ts +13 -0
  188. package/dist/dev/server/node.js +21 -0
  189. package/dist/dev/server/node.js.map +1 -0
  190. package/dist/dev/server/portals.d.ts +46 -0
  191. package/dist/dev/server/portals.js +99 -0
  192. package/dist/dev/server/portals.js.map +1 -0
  193. package/dist/dev/server/render.d.ts +129 -0
  194. package/dist/dev/server/render.js +256 -0
  195. package/dist/dev/server/render.js.map +1 -0
  196. package/dist/dev/server/serialize.d.ts +45 -0
  197. package/dist/dev/server/serialize.js +315 -0
  198. package/dist/dev/server/serialize.js.map +1 -0
  199. package/dist/dev/server/stream.d.ts +94 -0
  200. package/dist/dev/server/stream.js +235 -0
  201. package/dist/dev/server/stream.js.map +1 -0
  202. package/dist/dev/server.d.ts +16 -0
  203. package/dist/dev/server.js +16 -0
  204. package/dist/dev/spread.d.ts +49 -0
  205. package/dist/dev/spread.js +296 -0
  206. package/dist/dev/spread.js.map +1 -0
  207. package/dist/dev/template.d.ts +26 -0
  208. package/dist/dev/template.js +120 -0
  209. package/dist/dev/template.js.map +1 -0
  210. package/dist/dev/view-transition.d.ts +97 -0
  211. package/dist/dev/view-transition.js +121 -0
  212. package/dist/dev/view-transition.js.map +1 -0
  213. package/dist/prod/attributes.js +2 -0
  214. package/dist/prod/attributes.js.map +1 -0
  215. package/dist/prod/autofocus.js +2 -0
  216. package/dist/prod/autofocus.js.map +1 -0
  217. package/dist/prod/class-style.js +2 -0
  218. package/dist/prod/class-style.js.map +1 -0
  219. package/dist/prod/component.js +2 -0
  220. package/dist/prod/component.js.map +1 -0
  221. package/dist/prod/control-flow/activity.js +2 -0
  222. package/dist/prod/control-flow/activity.js.map +1 -0
  223. package/dist/prod/control-flow/branch.js +2 -0
  224. package/dist/prod/control-flow/branch.js.map +1 -0
  225. package/dist/prod/control-flow/client-only.js +2 -0
  226. package/dist/prod/control-flow/client-only.js.map +1 -0
  227. package/dist/prod/control-flow/dynamic.js +2 -0
  228. package/dist/prod/control-flow/dynamic.js.map +1 -0
  229. package/dist/prod/control-flow/error-boundary.js +2 -0
  230. package/dist/prod/control-flow/error-boundary.js.map +1 -0
  231. package/dist/prod/control-flow/for.js +2 -0
  232. package/dist/prod/control-flow/for.js.map +1 -0
  233. package/dist/prod/control-flow/fragment.js +2 -0
  234. package/dist/prod/control-flow/fragment.js.map +1 -0
  235. package/dist/prod/control-flow/hot-link.js +2 -0
  236. package/dist/prod/control-flow/hot-link.js.map +1 -0
  237. package/dist/prod/control-flow/index-list.js +2 -0
  238. package/dist/prod/control-flow/index-list.js.map +1 -0
  239. package/dist/prod/control-flow/lazy.js +2 -0
  240. package/dist/prod/control-flow/lazy.js.map +1 -0
  241. package/dist/prod/control-flow/no-hydration.js +2 -0
  242. package/dist/prod/control-flow/no-hydration.js.map +1 -0
  243. package/dist/prod/control-flow/portal.js +2 -0
  244. package/dist/prod/control-flow/portal.js.map +1 -0
  245. package/dist/prod/control-flow/root-errors.js +2 -0
  246. package/dist/prod/control-flow/root-errors.js.map +1 -0
  247. package/dist/prod/control-flow/show.js +2 -0
  248. package/dist/prod/control-flow/show.js.map +1 -0
  249. package/dist/prod/control-flow/suspense-list.js +2 -0
  250. package/dist/prod/control-flow/suspense-list.js.map +1 -0
  251. package/dist/prod/control-flow/suspense.js +2 -0
  252. package/dist/prod/control-flow/suspense.js.map +1 -0
  253. package/dist/prod/control-flow/switch.js +2 -0
  254. package/dist/prod/control-flow/switch.js.map +1 -0
  255. package/dist/prod/derived.js +2 -0
  256. package/dist/prod/derived.js.map +1 -0
  257. package/dist/prod/element.js +2 -0
  258. package/dist/prod/element.js.map +1 -0
  259. package/dist/prod/events.js +2 -0
  260. package/dist/prod/events.js.map +1 -0
  261. package/dist/prod/extend.js +1 -0
  262. package/dist/prod/head/components.js +2 -0
  263. package/dist/prod/head/components.js.map +1 -0
  264. package/dist/prod/head/registry.js +2 -0
  265. package/dist/prod/head/registry.js.map +1 -0
  266. package/dist/prod/head/server-head.js +2 -0
  267. package/dist/prod/head/server-head.js.map +1 -0
  268. package/dist/prod/head/sink.js +2 -0
  269. package/dist/prod/head/sink.js.map +1 -0
  270. package/dist/prod/head/use-head.js +2 -0
  271. package/dist/prod/head/use-head.js.map +1 -0
  272. package/dist/prod/head/validate.js +2 -0
  273. package/dist/prod/head/validate.js.map +1 -0
  274. package/dist/prod/hmr.js +2 -0
  275. package/dist/prod/hmr.js.map +1 -0
  276. package/dist/prod/hydration.js +2 -0
  277. package/dist/prod/hydration.js.map +1 -0
  278. package/dist/prod/index.js +1 -0
  279. package/dist/prod/insert.js +2 -0
  280. package/dist/prod/insert.js.map +1 -0
  281. package/dist/prod/internal/claim.js +2 -0
  282. package/dist/prod/internal/claim.js.map +1 -0
  283. package/dist/prod/internal/css-units.js +2 -0
  284. package/dist/prod/internal/css-units.js.map +1 -0
  285. package/dist/prod/internal/diagnostics.js +2 -0
  286. package/dist/prod/internal/diagnostics.js.map +1 -0
  287. package/dist/prod/internal/early-events.js +2 -0
  288. package/dist/prod/internal/early-events.js.map +1 -0
  289. package/dist/prod/internal/hydration-hooks.js +2 -0
  290. package/dist/prod/internal/hydration-hooks.js.map +1 -0
  291. package/dist/prod/internal/hydration-scope.js +2 -0
  292. package/dist/prod/internal/hydration-scope.js.map +1 -0
  293. package/dist/prod/internal/names.js +2 -0
  294. package/dist/prod/internal/names.js.map +1 -0
  295. package/dist/prod/internal/portal-context.js +2 -0
  296. package/dist/prod/internal/portal-context.js.map +1 -0
  297. package/dist/prod/internal/react-names.js +2 -0
  298. package/dist/prod/internal/react-names.js.map +1 -0
  299. package/dist/prod/internal/reconcile.js +2 -0
  300. package/dist/prod/internal/reconcile.js.map +1 -0
  301. package/dist/prod/internal/stream-context.js +2 -0
  302. package/dist/prod/internal/stream-context.js.map +1 -0
  303. package/dist/prod/jsx-dev-runtime.js +0 -0
  304. package/dist/prod/jsx-runtime.js +0 -0
  305. package/dist/prod/reactive.js +2 -0
  306. package/dist/prod/reactive.js.map +1 -0
  307. package/dist/prod/render.js +2 -0
  308. package/dist/prod/render.js.map +1 -0
  309. package/dist/prod/resource-hints.js +2 -0
  310. package/dist/prod/resource-hints.js.map +1 -0
  311. package/dist/prod/select-value.js +2 -0
  312. package/dist/prod/select-value.js.map +1 -0
  313. package/dist/prod/server/attributes.js +2 -0
  314. package/dist/prod/server/attributes.js.map +1 -0
  315. package/dist/prod/server/class-style.js +2 -0
  316. package/dist/prod/server/class-style.js.map +1 -0
  317. package/dist/prod/server/component.js +2 -0
  318. package/dist/prod/server/component.js.map +1 -0
  319. package/dist/prod/server/derived.js +2 -0
  320. package/dist/prod/server/derived.js.map +1 -0
  321. package/dist/prod/server/element.js +2 -0
  322. package/dist/prod/server/element.js.map +1 -0
  323. package/dist/prod/server/errors.js +2 -0
  324. package/dist/prod/server/errors.js.map +1 -0
  325. package/dist/prod/server/escape.js +2 -0
  326. package/dist/prod/server/escape.js.map +1 -0
  327. package/dist/prod/server/form-controls.js +3 -0
  328. package/dist/prod/server/form-controls.js.map +1 -0
  329. package/dist/prod/server/hydration-script.js +2 -0
  330. package/dist/prod/server/hydration-script.js.map +1 -0
  331. package/dist/prod/server/index.js +1 -0
  332. package/dist/prod/server/node.js +2 -0
  333. package/dist/prod/server/node.js.map +1 -0
  334. package/dist/prod/server/portals.js +2 -0
  335. package/dist/prod/server/portals.js.map +1 -0
  336. package/dist/prod/server/render.js +2 -0
  337. package/dist/prod/server/render.js.map +1 -0
  338. package/dist/prod/server/serialize.js +2 -0
  339. package/dist/prod/server/serialize.js.map +1 -0
  340. package/dist/prod/server/stream.js +2 -0
  341. package/dist/prod/server/stream.js.map +1 -0
  342. package/dist/prod/server.js +1 -0
  343. package/dist/prod/spread.js +2 -0
  344. package/dist/prod/spread.js.map +1 -0
  345. package/dist/prod/template.js +2 -0
  346. package/dist/prod/template.js.map +1 -0
  347. package/dist/prod/view-transition.js +2 -0
  348. package/dist/prod/view-transition.js.map +1 -0
  349. package/dist/server/attributes.js +2 -0
  350. package/dist/server/attributes.js.map +1 -0
  351. package/dist/server/autofocus.js +2 -0
  352. package/dist/server/autofocus.js.map +1 -0
  353. package/dist/server/class-style.js +2 -0
  354. package/dist/server/class-style.js.map +1 -0
  355. package/dist/server/component.js +2 -0
  356. package/dist/server/component.js.map +1 -0
  357. package/dist/server/control-flow/activity.js +2 -0
  358. package/dist/server/control-flow/activity.js.map +1 -0
  359. package/dist/server/control-flow/branch.js +2 -0
  360. package/dist/server/control-flow/branch.js.map +1 -0
  361. package/dist/server/control-flow/client-only.js +2 -0
  362. package/dist/server/control-flow/client-only.js.map +1 -0
  363. package/dist/server/control-flow/dynamic.js +2 -0
  364. package/dist/server/control-flow/dynamic.js.map +1 -0
  365. package/dist/server/control-flow/error-boundary.js +2 -0
  366. package/dist/server/control-flow/error-boundary.js.map +1 -0
  367. package/dist/server/control-flow/for.js +2 -0
  368. package/dist/server/control-flow/for.js.map +1 -0
  369. package/dist/server/control-flow/fragment.js +2 -0
  370. package/dist/server/control-flow/fragment.js.map +1 -0
  371. package/dist/server/control-flow/index-list.js +2 -0
  372. package/dist/server/control-flow/index-list.js.map +1 -0
  373. package/dist/server/control-flow/lazy.js +2 -0
  374. package/dist/server/control-flow/lazy.js.map +1 -0
  375. package/dist/server/control-flow/no-hydration.js +2 -0
  376. package/dist/server/control-flow/no-hydration.js.map +1 -0
  377. package/dist/server/control-flow/portal.js +2 -0
  378. package/dist/server/control-flow/portal.js.map +1 -0
  379. package/dist/server/control-flow/root-errors.js +2 -0
  380. package/dist/server/control-flow/root-errors.js.map +1 -0
  381. package/dist/server/control-flow/show.js +2 -0
  382. package/dist/server/control-flow/show.js.map +1 -0
  383. package/dist/server/control-flow/suspense-list.js +2 -0
  384. package/dist/server/control-flow/suspense-list.js.map +1 -0
  385. package/dist/server/control-flow/suspense.js +2 -0
  386. package/dist/server/control-flow/suspense.js.map +1 -0
  387. package/dist/server/control-flow/switch.js +2 -0
  388. package/dist/server/control-flow/switch.js.map +1 -0
  389. package/dist/server/derived.js +2 -0
  390. package/dist/server/derived.js.map +1 -0
  391. package/dist/server/element.js +2 -0
  392. package/dist/server/element.js.map +1 -0
  393. package/dist/server/events.js +2 -0
  394. package/dist/server/events.js.map +1 -0
  395. package/dist/server/extend.js +1 -0
  396. package/dist/server/head/components.js +2 -0
  397. package/dist/server/head/components.js.map +1 -0
  398. package/dist/server/head/registry.js +2 -0
  399. package/dist/server/head/registry.js.map +1 -0
  400. package/dist/server/head/server-head.js +2 -0
  401. package/dist/server/head/server-head.js.map +1 -0
  402. package/dist/server/head/sink.js +2 -0
  403. package/dist/server/head/sink.js.map +1 -0
  404. package/dist/server/head/use-head.js +2 -0
  405. package/dist/server/head/use-head.js.map +1 -0
  406. package/dist/server/head/validate.js +2 -0
  407. package/dist/server/head/validate.js.map +1 -0
  408. package/dist/server/hydration.js +2 -0
  409. package/dist/server/hydration.js.map +1 -0
  410. package/dist/server/index.js +1 -0
  411. package/dist/server/insert.js +2 -0
  412. package/dist/server/insert.js.map +1 -0
  413. package/dist/server/internal/claim.js +2 -0
  414. package/dist/server/internal/claim.js.map +1 -0
  415. package/dist/server/internal/css-units.js +2 -0
  416. package/dist/server/internal/css-units.js.map +1 -0
  417. package/dist/server/internal/diagnostics.js +2 -0
  418. package/dist/server/internal/diagnostics.js.map +1 -0
  419. package/dist/server/internal/early-events.js +2 -0
  420. package/dist/server/internal/early-events.js.map +1 -0
  421. package/dist/server/internal/hydration-hooks.js +2 -0
  422. package/dist/server/internal/hydration-hooks.js.map +1 -0
  423. package/dist/server/internal/hydration-scope.js +2 -0
  424. package/dist/server/internal/hydration-scope.js.map +1 -0
  425. package/dist/server/internal/names.js +2 -0
  426. package/dist/server/internal/names.js.map +1 -0
  427. package/dist/server/internal/portal-context.js +2 -0
  428. package/dist/server/internal/portal-context.js.map +1 -0
  429. package/dist/server/internal/react-names.js +2 -0
  430. package/dist/server/internal/react-names.js.map +1 -0
  431. package/dist/server/internal/reconcile.js +2 -0
  432. package/dist/server/internal/reconcile.js.map +1 -0
  433. package/dist/server/internal/stream-context.js +2 -0
  434. package/dist/server/internal/stream-context.js.map +1 -0
  435. package/dist/server/reactive.js +2 -0
  436. package/dist/server/reactive.js.map +1 -0
  437. package/dist/server/render.js +2 -0
  438. package/dist/server/render.js.map +1 -0
  439. package/dist/server/resource-hints.js +2 -0
  440. package/dist/server/resource-hints.js.map +1 -0
  441. package/dist/server/select-value.js +2 -0
  442. package/dist/server/select-value.js.map +1 -0
  443. package/dist/server/server/attributes.js +2 -0
  444. package/dist/server/server/attributes.js.map +1 -0
  445. package/dist/server/server/class-style.js +2 -0
  446. package/dist/server/server/class-style.js.map +1 -0
  447. package/dist/server/server/component.js +2 -0
  448. package/dist/server/server/component.js.map +1 -0
  449. package/dist/server/server/derived.js +2 -0
  450. package/dist/server/server/derived.js.map +1 -0
  451. package/dist/server/server/element.js +2 -0
  452. package/dist/server/server/element.js.map +1 -0
  453. package/dist/server/server/errors.js +2 -0
  454. package/dist/server/server/errors.js.map +1 -0
  455. package/dist/server/server/escape.js +2 -0
  456. package/dist/server/server/escape.js.map +1 -0
  457. package/dist/server/server/form-controls.js +3 -0
  458. package/dist/server/server/form-controls.js.map +1 -0
  459. package/dist/server/server/hydration-script.js +2 -0
  460. package/dist/server/server/hydration-script.js.map +1 -0
  461. package/dist/server/server/index.js +1 -0
  462. package/dist/server/server/node.js +2 -0
  463. package/dist/server/server/node.js.map +1 -0
  464. package/dist/server/server/portals.js +2 -0
  465. package/dist/server/server/portals.js.map +1 -0
  466. package/dist/server/server/render.js +2 -0
  467. package/dist/server/server/render.js.map +1 -0
  468. package/dist/server/server/serialize.js +2 -0
  469. package/dist/server/server/serialize.js.map +1 -0
  470. package/dist/server/server/stream.js +2 -0
  471. package/dist/server/server/stream.js.map +1 -0
  472. package/dist/server/server.js +1 -0
  473. package/dist/server/spread.js +2 -0
  474. package/dist/server/spread.js.map +1 -0
  475. package/dist/server/template.js +2 -0
  476. package/dist/server/template.js.map +1 -0
  477. package/dist/server/view-transition.js +2 -0
  478. package/dist/server/view-transition.js.map +1 -0
  479. package/dist/server-dev/attributes.js +196 -0
  480. package/dist/server-dev/attributes.js.map +1 -0
  481. package/dist/server-dev/autofocus.js +45 -0
  482. package/dist/server-dev/autofocus.js.map +1 -0
  483. package/dist/server-dev/class-style.js +197 -0
  484. package/dist/server-dev/class-style.js.map +1 -0
  485. package/dist/server-dev/component.js +42 -0
  486. package/dist/server-dev/component.js.map +1 -0
  487. package/dist/server-dev/control-flow/activity.js +41 -0
  488. package/dist/server-dev/control-flow/activity.js.map +1 -0
  489. package/dist/server-dev/control-flow/branch.js +104 -0
  490. package/dist/server-dev/control-flow/branch.js.map +1 -0
  491. package/dist/server-dev/control-flow/client-only.js +50 -0
  492. package/dist/server-dev/control-flow/client-only.js.map +1 -0
  493. package/dist/server-dev/control-flow/dynamic.js +106 -0
  494. package/dist/server-dev/control-flow/dynamic.js.map +1 -0
  495. package/dist/server-dev/control-flow/error-boundary.js +115 -0
  496. package/dist/server-dev/control-flow/error-boundary.js.map +1 -0
  497. package/dist/server-dev/control-flow/for.js +23 -0
  498. package/dist/server-dev/control-flow/for.js.map +1 -0
  499. package/dist/server-dev/control-flow/fragment.js +31 -0
  500. package/dist/server-dev/control-flow/fragment.js.map +1 -0
  501. package/dist/server-dev/control-flow/hot-link.js +57 -0
  502. package/dist/server-dev/control-flow/hot-link.js.map +1 -0
  503. package/dist/server-dev/control-flow/index-list.js +31 -0
  504. package/dist/server-dev/control-flow/index-list.js.map +1 -0
  505. package/dist/server-dev/control-flow/lazy.js +64 -0
  506. package/dist/server-dev/control-flow/lazy.js.map +1 -0
  507. package/dist/server-dev/control-flow/no-hydration.js +40 -0
  508. package/dist/server-dev/control-flow/no-hydration.js.map +1 -0
  509. package/dist/server-dev/control-flow/portal.js +134 -0
  510. package/dist/server-dev/control-flow/portal.js.map +1 -0
  511. package/dist/server-dev/control-flow/root-errors.js +33 -0
  512. package/dist/server-dev/control-flow/root-errors.js.map +1 -0
  513. package/dist/server-dev/control-flow/show.js +18 -0
  514. package/dist/server-dev/control-flow/show.js.map +1 -0
  515. package/dist/server-dev/control-flow/suspense-list.js +100 -0
  516. package/dist/server-dev/control-flow/suspense-list.js.map +1 -0
  517. package/dist/server-dev/control-flow/suspense.js +119 -0
  518. package/dist/server-dev/control-flow/suspense.js.map +1 -0
  519. package/dist/server-dev/control-flow/switch.js +90 -0
  520. package/dist/server-dev/control-flow/switch.js.map +1 -0
  521. package/dist/server-dev/derived.js +34 -0
  522. package/dist/server-dev/derived.js.map +1 -0
  523. package/dist/server-dev/element.js +66 -0
  524. package/dist/server-dev/element.js.map +1 -0
  525. package/dist/server-dev/events.js +265 -0
  526. package/dist/server-dev/events.js.map +1 -0
  527. package/dist/server-dev/extend.js +12 -0
  528. package/dist/server-dev/head/components.js +170 -0
  529. package/dist/server-dev/head/components.js.map +1 -0
  530. package/dist/server-dev/head/registry.js +68 -0
  531. package/dist/server-dev/head/registry.js.map +1 -0
  532. package/dist/server-dev/head/server-head.js +76 -0
  533. package/dist/server-dev/head/server-head.js.map +1 -0
  534. package/dist/server-dev/head/sink.js +96 -0
  535. package/dist/server-dev/head/sink.js.map +1 -0
  536. package/dist/server-dev/head/use-head.js +84 -0
  537. package/dist/server-dev/head/use-head.js.map +1 -0
  538. package/dist/server-dev/head/validate.js +268 -0
  539. package/dist/server-dev/head/validate.js.map +1 -0
  540. package/dist/server-dev/hydration.js +120 -0
  541. package/dist/server-dev/hydration.js.map +1 -0
  542. package/dist/server-dev/index.js +34 -0
  543. package/dist/server-dev/insert.js +357 -0
  544. package/dist/server-dev/insert.js.map +1 -0
  545. package/dist/server-dev/internal/claim.js +357 -0
  546. package/dist/server-dev/internal/claim.js.map +1 -0
  547. package/dist/server-dev/internal/css-units.js +26 -0
  548. package/dist/server-dev/internal/css-units.js.map +1 -0
  549. package/dist/server-dev/internal/diagnostics.js +38 -0
  550. package/dist/server-dev/internal/diagnostics.js.map +1 -0
  551. package/dist/server-dev/internal/early-events.js +76 -0
  552. package/dist/server-dev/internal/early-events.js.map +1 -0
  553. package/dist/server-dev/internal/hydration-hooks.js +27 -0
  554. package/dist/server-dev/internal/hydration-hooks.js.map +1 -0
  555. package/dist/server-dev/internal/hydration-scope.js +156 -0
  556. package/dist/server-dev/internal/hydration-scope.js.map +1 -0
  557. package/dist/server-dev/internal/names.js +35 -0
  558. package/dist/server-dev/internal/names.js.map +1 -0
  559. package/dist/server-dev/internal/portal-context.js +28 -0
  560. package/dist/server-dev/internal/portal-context.js.map +1 -0
  561. package/dist/server-dev/internal/react-names.js +116 -0
  562. package/dist/server-dev/internal/react-names.js.map +1 -0
  563. package/dist/server-dev/internal/reconcile.js +122 -0
  564. package/dist/server-dev/internal/reconcile.js.map +1 -0
  565. package/dist/server-dev/internal/stream-context.js +23 -0
  566. package/dist/server-dev/internal/stream-context.js.map +1 -0
  567. package/dist/server-dev/reactive.js +85 -0
  568. package/dist/server-dev/reactive.js.map +1 -0
  569. package/dist/server-dev/render.js +52 -0
  570. package/dist/server-dev/render.js.map +1 -0
  571. package/dist/server-dev/resource-hints.js +200 -0
  572. package/dist/server-dev/resource-hints.js.map +1 -0
  573. package/dist/server-dev/select-value.js +51 -0
  574. package/dist/server-dev/select-value.js.map +1 -0
  575. package/dist/server-dev/server/attributes.js +155 -0
  576. package/dist/server-dev/server/attributes.js.map +1 -0
  577. package/dist/server-dev/server/class-style.js +173 -0
  578. package/dist/server-dev/server/class-style.js.map +1 -0
  579. package/dist/server-dev/server/component.js +72 -0
  580. package/dist/server-dev/server/component.js.map +1 -0
  581. package/dist/server-dev/server/derived.js +26 -0
  582. package/dist/server-dev/server/derived.js.map +1 -0
  583. package/dist/server-dev/server/element.js +216 -0
  584. package/dist/server-dev/server/element.js.map +1 -0
  585. package/dist/server-dev/server/errors.js +26 -0
  586. package/dist/server-dev/server/errors.js.map +1 -0
  587. package/dist/server-dev/server/escape.js +119 -0
  588. package/dist/server-dev/server/escape.js.map +1 -0
  589. package/dist/server-dev/server/form-controls.js +193 -0
  590. package/dist/server-dev/server/form-controls.js.map +1 -0
  591. package/dist/server-dev/server/hydration-script.js +59 -0
  592. package/dist/server-dev/server/hydration-script.js.map +1 -0
  593. package/dist/server-dev/server/index.js +16 -0
  594. package/dist/server-dev/server/node.js +21 -0
  595. package/dist/server-dev/server/node.js.map +1 -0
  596. package/dist/server-dev/server/portals.js +99 -0
  597. package/dist/server-dev/server/portals.js.map +1 -0
  598. package/dist/server-dev/server/render.js +256 -0
  599. package/dist/server-dev/server/render.js.map +1 -0
  600. package/dist/server-dev/server/serialize.js +315 -0
  601. package/dist/server-dev/server/serialize.js.map +1 -0
  602. package/dist/server-dev/server/stream.js +235 -0
  603. package/dist/server-dev/server/stream.js.map +1 -0
  604. package/dist/server-dev/server.js +16 -0
  605. package/dist/server-dev/spread.js +296 -0
  606. package/dist/server-dev/spread.js.map +1 -0
  607. package/dist/server-dev/template.js +120 -0
  608. package/dist/server-dev/template.js.map +1 -0
  609. package/dist/server-dev/view-transition.js +90 -0
  610. package/dist/server-dev/view-transition.js.map +1 -0
  611. package/package.json +136 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spread.js","names":["innerHtmlValue","value","plainText","FORBIDDEN_NAMES","isEventKey","key","nameOf","colon","asRecord","readEntries","entries","props","hasValue","IGNORED_KEYS","textarea","runRefCleanup","cleanup","state","untrack","applyKey","callRef","el","autoFocus","applyClass","svg","style","classList","plan","eventPlan","handler","unbind","bindEvent","setSelectValue","LIVE_PROPERTIES","liveDiffers","STRING_PROPERTIES","writeKey","setAttribute","setBoolAttribute","wire","attributeName","setAttributeNS","selectShows","live","clearKey","applyEntries","current","spread","read","skipChildren","initial","claims","region","createRegion","bindRegion","onCleanup","useRenderEffect","isSVG"],"sources":["../../src/spread.ts"],"sourcesContent":["import { onCleanup, untrack, useRenderEffect } from \"@shadow-js/core\";\nimport { setAttribute, setAttributeNS, setBoolAttribute } from \"./attributes\";\nimport { autoFocus } from \"./autofocus\";\nimport { applyClass, classList, style } from \"./class-style\";\nimport { bindEvent } from \"./events\";\nimport { bindRegion, createRegion } from \"./insert\";\nimport { claims } from \"./internal/hydration-hooks\";\nimport { attributeName, eventPlan, IGNORED_KEYS } from \"./internal/react-names\";\nimport { selectShows, setSelectValue } from \"./select-value\";\n\n/** The namespace of `xlink:` attributes (SVG's legacy links). */\nconst XLINK_NS = \"http://www.w3.org/1999/xlink\";\n\n/** The HTML of a `dangerouslySetInnerHTML` value (`{ __html }`); null and undefined mean empty. */\nfunction innerHtmlValue(value: unknown): string {\n if (value === null || typeof value !== \"object\") return \"\";\n return plainText(Reflect.get(value, \"__html\"));\n}\n\n/** Keys that would reach a prototype if written as properties. Ignored everywhere. */\nconst FORBIDDEN_NAMES = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/** Mutable bookkeeping for one spread: the values last applied and the event bindings. */\ninterface SpreadState {\n readonly values: Map<string, unknown>;\n readonly unbinders: Map<string, () => void>;\n styleValue: unknown;\n classListValue: Record<string, unknown> | undefined;\n /** Cleanup returned by the `ref` callback currently applied (React 19 ref cleanup). */\n refCleanup: (() => void) | undefined;\n /** `autoFocus` acts on the first application only, as React applies it once at commit. */\n autoFocused?: boolean;\n}\n\n/** True for `on*` keys, which bind event handlers. */\nfunction isEventKey(key: string): boolean {\n return key.length > 2 && key.startsWith(\"on\");\n}\n\n/** The name after a `prop:`, `attr:` or `bool:` namespace, or the whole key. */\nfunction nameOf(key: string): string {\n const colon = key.indexOf(\":\");\n return colon === -1 ? key : key.slice(colon + 1);\n}\n\n/** Narrows an object value to a record of keys; arrays and primitives are not class maps. */\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n return value as Record<string, unknown>;\n}\n\n/** Text for innerHTML and textContent: null and undefined become the empty string. */\nfunction plainText(value: unknown): string {\n return value === null || value === undefined ? \"\" : String(value);\n}\n\n/** Reads every prop except children, inside the render effect so each read is tracked. */\nfunction readEntries(props: unknown, textarea: boolean): Array<[string, unknown]> {\n const entries: Array<[string, unknown]> = [];\n if (props === null || typeof props !== \"object\") return entries;\n let value: unknown;\n let hasValue = false;\n for (const key of Object.keys(props)) {\n if (FORBIDDEN_NAMES.has(nameOf(key)) || IGNORED_KEYS.has(key)) continue;\n if (key === \"children\") {\n // A textarea's children are its value (the server writes them as its content): a text node\n // child would not follow the data once the user has typed.\n if (textarea) {\n value = Reflect.get(props, key);\n hasValue = true;\n }\n continue;\n }\n entries.push([key, Reflect.get(props, key)]);\n }\n if (hasValue && !entries.some(([key]) => key === \"value\")) entries.push([\"value\", value]);\n return entries;\n}\n\n/** Runs and forgets the cleanup the last ref callback returned, if any. */\nfunction runRefCleanup(state: SpreadState): void {\n const cleanup = state.refCleanup;\n if (cleanup === undefined) return;\n state.refCleanup = undefined;\n untrack(cleanup);\n}\n\n/** Applies one prop that is new or changed. */\nfunction applyKey(\n el: Element,\n key: string,\n value: unknown,\n state: SpreadState,\n svg: boolean,\n): void {\n if (key === \"ref\") {\n // The ref that was replaced is undone first: its cleanup runs, as for a ref attribute.\n runRefCleanup(state);\n if (typeof value === \"function\") {\n const callRef = value as (node: Element) => unknown;\n const cleanup = untrack(() => callRef(el));\n if (typeof cleanup === \"function\") state.refCleanup = cleanup as () => void;\n }\n return;\n }\n if (key === \"autoFocus\") {\n if (!state.autoFocused) {\n state.autoFocused = true;\n autoFocus(el, value);\n }\n return;\n }\n if (key === \"class\" || key === \"className\") {\n applyClass(el, value, svg);\n return;\n }\n if (key === \"style\") {\n state.styleValue = style(el as HTMLElement | SVGElement, value, state.styleValue);\n return;\n }\n if (key === \"classList\") {\n state.classListValue = classList(el, asRecord(value), state.classListValue);\n return;\n }\n if (isEventKey(key)) {\n state.unbinders.get(key)?.();\n state.unbinders.delete(key);\n // React's spelling: `onChange`, `onFocus`, `...Capture` and passive `onWheel` bind as React does.\n const plan = eventPlan(key, el.localName, el.getAttribute(\"type\")?.toLowerCase() ?? null);\n const handler =\n plan.passive && typeof value === \"function\" ? { handleEvent: value, passive: true } : value;\n const unbind = bindEvent(el, plan.type, handler, true, plan.capture);\n if (unbind !== undefined) state.unbinders.set(key, unbind);\n return;\n }\n if (key === \"innerHTML\") {\n el.innerHTML = plainText(value);\n return;\n }\n if (key === \"dangerouslySetInnerHTML\") {\n el.innerHTML = innerHtmlValue(value);\n return;\n }\n if (key === \"textContent\") {\n el.textContent = plainText(value);\n return;\n }\n if (!svg && (key === \"value\" || key === \"defaultValue\") && el instanceof HTMLSelectElement) {\n // A select's value may be an array (`multiple`).\n setSelectValue(el, value);\n return;\n }\n if (!svg && LIVE_PROPERTIES.has(key) && key in el) {\n // State the user changes (a typed value, a toggled box) lives in the property; the attribute is\n // only the default, and writing it stops the element following the data once it is dirty.\n liveDiffers(el, key, value, svg) &&\n Reflect.set(el, key, STRING_PROPERTIES.has(key) ? (value ?? \"\") : Boolean(value));\n // An input's `value` attribute is its default (what a form reset restores) and what the server\n // wrote; keep it equal to the live value like server markup, so both renders match.\n if (key === \"value\" && el instanceof HTMLInputElement) {\n el.defaultValue = plainText(value);\n }\n return;\n }\n writeKey(el, key, value, svg);\n}\n\n/**\n * Writes one prop by its key: a `prop:` property, an `attr:` or `bool:` attribute, or an attribute\n * under its React name. An `undefined` value removes the attribute or resets the property, which is how\n * {@link clearKey} undoes a prop.\n */\nfunction writeKey(el: Element, key: string, value: unknown, svg: boolean): void {\n if (key.startsWith(\"prop:\")) {\n Reflect.set(el, key.slice(5), value);\n } else if (key.startsWith(\"attr:\")) {\n setAttribute(el, key.slice(5), value);\n } else if (key.startsWith(\"bool:\")) {\n setBoolAttribute(el, key.slice(5), value);\n } else {\n const wire = attributeName(key, svg);\n if (wire.startsWith(\"xlink:\")) setAttributeNS(el, XLINK_NS, wire, value);\n else setAttribute(el, wire, value);\n }\n}\n\n/** Props written as element properties, like the compiler does for the same names in JSX. */\nconst LIVE_PROPERTIES: ReadonlySet<string> = new Set([\n \"value\",\n \"checked\",\n \"selected\",\n \"muted\",\n \"indeterminate\",\n \"defaultValue\",\n \"defaultChecked\",\n]);\n/** The properties of {@link LIVE_PROPERTIES} that hold text; the others are booleans. */\nconst STRING_PROPERTIES: ReadonlySet<string> = new Set([\"value\", \"defaultValue\"]);\n\n/**\n * True when a live property (typed value, toggled box) no longer matches the value last applied, so\n * an unchanged prop is written again and the element follows the data.\n */\nfunction liveDiffers(el: Element, key: string, value: unknown, svg: boolean): boolean {\n if (svg || !LIVE_PROPERTIES.has(key) || !(key in el)) return false;\n if (key === \"value\" && el instanceof HTMLSelectElement) return !selectShows(el, value);\n const live = Reflect.get(el, key);\n return STRING_PROPERTIES.has(key) ? live !== plainText(value) : live !== Boolean(value);\n}\n\n/** Undoes a prop that disappeared from the props object. */\nfunction clearKey(el: Element, key: string, state: SpreadState, svg: boolean): void {\n if (key === \"ref\") {\n runRefCleanup(state);\n return;\n }\n // A focus request is not a state: removing the prop does not unfocus the element.\n if (key === \"autoFocus\") return;\n if (key === \"class\" || key === \"className\") {\n applyClass(el, undefined, svg);\n return;\n }\n if (key === \"style\") {\n state.styleValue = style(el as HTMLElement | SVGElement, undefined, state.styleValue);\n return;\n }\n if (key === \"classList\") {\n state.classListValue = classList(el, undefined, state.classListValue);\n return;\n }\n if (isEventKey(key)) {\n state.unbinders.get(key)?.();\n state.unbinders.delete(key);\n return;\n }\n if (key === \"innerHTML\" || key === \"dangerouslySetInnerHTML\" || key === \"textContent\") {\n el.textContent = \"\";\n return;\n }\n if (!svg && LIVE_PROPERTIES.has(key) && key in el) {\n Reflect.set(el, key, STRING_PROPERTIES.has(key) ? \"\" : false);\n return;\n }\n writeKey(el, key, undefined, svg);\n}\n\n/**\n * Applies the entries that changed since the last run and undoes the ones that disappeared.\n * Unchanged values are skipped by identity, so only changed keys touch the DOM.\n */\nfunction applyEntries(\n el: Element,\n entries: Array<[string, unknown]>,\n state: SpreadState,\n svg: boolean,\n): void {\n const current = new Set<string>();\n for (const [key, value] of entries) {\n current.add(key);\n if (\n state.values.has(key) &&\n Object.is(state.values.get(key), value) &&\n !liveDiffers(el, key, value, svg)\n )\n continue;\n state.values.set(key, value);\n applyKey(el, key, value, state, svg);\n }\n for (const key of [...state.values.keys()]) {\n if (current.has(key)) continue;\n state.values.delete(key);\n clearKey(el, key, state, svg);\n }\n}\n\n/**\n * Applies a whole props object to an element and keeps it in sync: the helper compiled JSX calls for\n * `{...props}` on an element. The props are read inside a render effect, so a getter (or the props\n * accessor) that changes rewrites only the keys whose values changed, and a key that disappears is\n * undone. Event listeners and the last `ref` cleanup are released when the owner is disposed.\n *\n * Keys: `class`/`className`, `classList` and `style` use the class and style helpers; `ref` is called\n * untracked with the element (a returned function is its cleanup); `on*` keys bind with React's\n * spelling (`onChange` on a text input is `input`, `onFocus` is `focusin`, `...Capture` listens\n * in the capture phase, `onWheel` is passive), delegated when the event allows it; `prop:` writes a\n * property, `attr:` and `bool:` an attribute; `innerHTML`, `dangerouslySetInnerHTML` and\n * `textContent` set the content; `value`, `checked`, `selected`, `muted`, `indeterminate`,\n * `defaultValue` and `defaultChecked` are written as properties and re-applied when the user changed\n * them; `autoFocus` applies once. Other keys are attributes, with React names mapped (`htmlFor` is\n * `for`, SVG `strokeWidth` is `stroke-width`). `key`, `suppressHydrationWarning`,\n * `suppressContentEditableWarning`, `__proto__`, `constructor` and `prototype` are ignored.\n *\n * @param el Target element.\n * @param props A props object, or a function returning one (read in the effect). `null` and other\n * values do nothing.\n * @param isSVG `true` for SVG elements: `class` is written as an attribute and SVG names are mapped.\n * Default: `false`.\n * @param skipChildren `true` ignores `children` (the compiler sets it when the JSX has its own\n * children). Default: `false`, which inserts `children` as the element's content; on a `<textarea>`,\n * `children` is its value instead.\n * @throws TypeError `INVALID_ATTRIBUTE_NAME` for an attribute name that is not valid, and\n * `SHADOW_EVENT_HANDLER` for an `on*` value that is not a handler.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { spread } from \"@shadow-js/web\";\n *\n * function SaveButton() {\n * const [busy] = useSignal(false);\n * const button = document.createElement(\"button\");\n * spread(button, {\n * class: \"btn\",\n * onClick: () => console.log(\"save\"),\n * get disabled() { return busy(); },\n * children: \"Save\",\n * });\n * return button;\n * }\n * @see element\n * @since 1.0.0\n */\nexport function spread(el: Element, props: unknown, isSVG = false, skipChildren = false): void {\n if (props === null || (typeof props !== \"object\" && typeof props !== \"function\")) return;\n // A function is an accessor of the props (`{...props.attrs}` compiles to one): read it inside\n // the effects below so the element follows it.\n const read = (): unknown => (typeof props === \"function\" ? (props as () => unknown)() : props);\n const textarea = el.localName === \"textarea\";\n if (!skipChildren && !textarea) {\n // Spread children own the whole element; ssrElement may emit their text without region markers.\n const initial = claims.current.isClaiming()\n ? (claims.current.takeRegion(el, null) ?? Array.from(el.childNodes))\n : undefined;\n const region = createRegion(el, null, initial);\n bindRegion(region, () => (read() as { readonly children?: unknown } | null)?.children);\n }\n const state: SpreadState = {\n values: new Map(),\n unbinders: new Map(),\n styleValue: undefined,\n classListValue: undefined,\n refCleanup: undefined,\n };\n // Native listeners come off with the owner, even if the element outlives it.\n onCleanup(() => {\n for (const unbind of state.unbinders.values()) unbind();\n state.unbinders.clear();\n runRefCleanup(state);\n });\n useRenderEffect(\n () => readEntries(read(), textarea),\n (entries) => {\n applyEntries(el, entries, state, isSVG);\n },\n );\n}\n"],"mappings":"A,mlBAcA,SAASA,EAAe,EAAwB,CAE9C,OADsB,OAAOC,GAAU,WAAnCA,EAAoD,GACjDC,EAAU,QAAQ,IAAID,EAAO,QAAQ,CAAC,CAC/C,CAGA,MAAME,kBAAkB,IAAI,IAAI,CAAC,YAAa,cAAe,WAAW,CAAC,EAezE,SAASC,EAAW,EAAsB,CACxC,OAAOC,EAAI,OAAS,GAAKA,EAAI,WAAW,IAAI,CAC9C,CAGA,SAASC,EAAO,EAAqB,CACnC,IAAMC,EAAQF,EAAI,QAAQ,GAAG,EAC7B,OAAOE,IAAU,GAAKF,EAAMA,EAAI,MAAME,EAAQ,CAAC,CACjD,CAGA,SAASC,EAAS,EAAqD,CACrE,GAAsB,OAAOP,GAAU,UAAnCA,GAA+C,OAAM,QAAQA,CAAK,EACtE,OAAOA,CACT,CAGA,SAASC,EAAU,EAAwB,CACzC,OAAOD,GAAU,KAA8B,GAAK,OAAOA,CAAK,CAClE,CAGA,SAASQ,EAAY,EAAgB,EAA6C,CAChF,IAAMC,EAAoC,CAAC,EAC3C,GAAsB,OAAOC,GAAU,WAAnCA,EAA6C,OAAOD,EACxD,IAAIT,EACAW,EAAW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AM,UAAU,MAAM,EACtBF,EAAcE,CAAK,CACrB,CAAC,EACDuC,MACQ/C,EAAYuC,EAAK,EAAGlC,CAAQ,EACjC,GAAY,CACX+B,EAAaxB,EAAIX,EAASO,EAAOwC,CAAK,CACxC,CACF,CACF,C"}
@@ -0,0 +1,2 @@
1
+ import{MATHML_NS as e}from"./internal/names.js";import{nextKey as t}from"./internal/hydration-scope.js";import{claims as n}from"./internal/hydration-hooks.js";function r(e,t){let n=document,r=e=>{let r=n.createElementNS(t,e.localName);for(let t of Array.from(e.attributes))r.setAttribute(t.name,t.value);return r},i=r(e),a=[[e,i]];for(;a.length>0;){let e=a.pop();if(e===void 0)break;let[t,i]=e;for(let e of Array.from(t.childNodes))if(e instanceof Element){let t=r(e);i.appendChild(t),a.push([e,t])}else e instanceof Text&&i.appendChild(n.createTextNode(e.data))}return i}function i(t,n){let i=document.createElement(`template`),a=n&1?`svg`:n&2?`math`:null;if(a===null)return i.innerHTML=t,Array.from(i.content.childNodes);i.innerHTML=`<${a}>${t}</${a}>`;let o=i.content.firstChild;return o instanceof Element?a===`math`&&o.namespaceURI!==`http://www.w3.org/1998/Math/MathML`?Array.from(r(o,e).childNodes):Array.from(o.childNodes):[]}function a(e,r=0){let a=!!(r&4),o,s=e=>a?document.importNode(e,!0):e.cloneNode(!0);return()=>{let a=n.current.claimElement(t());if(a!==null)return a;let c=o??=i(e,r);if(c.length===1){let[e]=c;if(e!==void 0)return s(e)}let l=document.createDocumentFragment();for(let e of c)l.appendChild(s(e));return l}}export{a as template};
2
+ //# sourceMappingURL=template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template.js","names":["inNamespace","doc","copyOf","copy","namespace","element","attribute","root","source","stack","pair","from","to","child","parse","holder","wrapper","flags","html","MATHML_NS","template","importNode","roots","node","claimed","claims","nextKey","parsed","only","fragment"],"sources":["../../src/template.ts"],"sourcesContent":["import { checkClaimedTag } from \"./internal/claim\";\nimport { warnOnce } from \"./internal/diagnostics\";\nimport { claims } from \"./internal/hydration-hooks\";\nimport { nextKey } from \"./internal/hydration-scope\";\nimport { MATHML_NS, TEMPLATE_IMPORT_NODE, TEMPLATE_MATHML, TEMPLATE_SVG } from \"./internal/names\";\n\n/** One start tag: its name, then its attribute text (group 1). */\nconst START_TAG =\n /<[a-zA-Z][^\\s/>]*((?:\\s+[^\\s\"'>/=]+(?:\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s\"'>]+))?)*)\\s*\\/?>/g;\n/** One attribute inside the attribute text of a start tag: its name (group 1). */\nconst ATTRIBUTE = /([^\\s\"'>/=]+)(?:\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s\"'>]+))?/g;\n\n/**\n * Development check for the markup a template is parsed from. The HTML parser keeps the first of two\n * same-named attributes and drops the rest, so `class` and `className` on one element (both compiled\n * to `class`) lose one silently. Warns `DUPLICATE_CLASS_ATTRIBUTE` once; the first attribute still wins.\n */\nfunction warnDuplicateClass(html: string): void {\n for (const tag of html.matchAll(START_TAG)) {\n const attributes = [...(tag[1] ?? \"\").matchAll(ATTRIBUTE)];\n const classes = attributes.filter((match) => match[1]?.toLowerCase() === \"class\");\n if (classes.length < 2) continue;\n const name = /^<([^\\s/>]+)/.exec(tag[0])?.[1] ?? \"element\";\n warnOnce(\n \"DUPLICATE_CLASS_ATTRIBUTE\",\n `<${name}> has two class attributes (class and className both write class). The parser drops the second; keep one.`,\n );\n return;\n }\n}\n\n/**\n * Copies an element subtree into `namespace`, iteratively. Used only when the engine parsed a\n * MathML wrapper as HTML (some DOM implementations do not parse foreign content).\n */\nfunction inNamespace(source: Element, namespace: string): Element {\n const doc = document;\n const copyOf = (element: Element): Element => {\n const copy = doc.createElementNS(namespace, element.localName);\n for (const attribute of Array.from(element.attributes)) {\n copy.setAttribute(attribute.name, attribute.value);\n }\n return copy;\n };\n const root = copyOf(source);\n const stack: Array<[Element, Element]> = [[source, root]];\n while (stack.length > 0) {\n const pair = stack.pop();\n if (pair === undefined) break;\n const [from, to] = pair;\n for (const child of Array.from(from.childNodes)) {\n if (child instanceof Element) {\n const copy = copyOf(child);\n to.appendChild(copy);\n stack.push([child, copy]);\n } else if (child instanceof Text) {\n to.appendChild(doc.createTextNode(child.data));\n }\n }\n }\n return root;\n}\n\n/** Parses the markup once and returns its top-level nodes. SVG and MathML are parsed in a wrapper. */\nfunction parse(html: string, flags: number): Node[] {\n if (__DEV__) warnDuplicateClass(html);\n const holder = document.createElement(\"template\");\n const wrapper =\n (flags & TEMPLATE_SVG) !== 0 ? \"svg\" : (flags & TEMPLATE_MATHML) !== 0 ? \"math\" : null;\n if (wrapper === null) {\n holder.innerHTML = html;\n return Array.from(holder.content.childNodes);\n }\n holder.innerHTML = `<${wrapper}>${html}</${wrapper}>`;\n const root = holder.content.firstChild;\n if (!(root instanceof Element)) return [];\n if (wrapper === \"math\" && root.namespaceURI !== MATHML_NS) {\n return Array.from(inNamespace(root, MATHML_NS).childNodes);\n }\n return Array.from(root.childNodes);\n}\n\n/**\n * Turns a static HTML string into a factory of fresh DOM copies: the helper compiled JSX uses for the\n * static part of every element tree. The markup is parsed on the first call and cloned on every call\n * after that, so creating a template touches no DOM. Each call draws the next hydration key; during\n * `hydrate()` it returns the server's element for that key instead of a clone.\n *\n * @param html Markup of one or more sibling roots. It is trusted: it is parsed as written, never\n * escaped.\n * @param flags Bit set: `1` parses the content inside `<svg>` so it gets the SVG namespace, `2` does\n * the same for MathML, `4` clones with `document.importNode` (needed for custom elements).\n * Default: `0` (HTML, `cloneNode`).\n * @returns A function that returns a new, detached node on every call: the root itself when the\n * markup has one root, otherwise a `DocumentFragment` holding the roots.\n * @example\n * import { template } from \"@shadow-js/web\";\n *\n * const makeCard = template(`<div class=\"card\"><h2></h2></div>`);\n * const card = makeCard() as HTMLDivElement;\n * (card.firstChild as HTMLElement).textContent = \"Title\";\n * document.body.append(card);\n * @since 1.0.0\n */\nexport function template(html: string, flags = 0): () => Node {\n const importNode = (flags & TEMPLATE_IMPORT_NODE) !== 0;\n let roots: Node[] | undefined;\n // Development holds the parsed roots weakly: the browser never frees an evaluated module, so a\n // hot-updated template would otherwise keep its parsed copy alive for the whole session. Only the\n // `__DEV__` branches reach this helper and `weakRoots`, so production builds carry neither.\n let weakRoots: WeakRef<Node[]> | undefined;\n const devRoots = (): Node[] => {\n const live = weakRoots?.deref();\n if (live !== undefined) return live;\n const fresh = parse(html, flags);\n weakRoots = new WeakRef(fresh);\n return fresh;\n };\n const copy = (node: Node): Node =>\n importNode ? document.importNode(node, true) : node.cloneNode(true);\n return () => {\n // While hydrating, the next template root is the server's element, not a clone.\n const claimed = claims.current.claimElement(nextKey());\n if (claimed !== null) {\n if (__DEV__) {\n // The template's only root names the tag the server element must have.\n const parsed = devRoots();\n const [only] = parsed;\n if (parsed.length === 1 && only instanceof Element)\n checkClaimedTag(claimed, only.localName);\n }\n return claimed;\n }\n // biome-ignore lint/suspicious/noAssignInExpressions: the first call parses the template once; the assignment is the cache.\n const parsed = __DEV__ ? devRoots() : (roots ??= parse(html, flags));\n if (parsed.length === 1) {\n const [only] = parsed;\n if (only !== undefined) return copy(only);\n }\n const fragment = document.createDocumentFragment();\n for (const root of parsed) fragment.appendChild(copy(root));\n return fragment;\n };\n}\n"],"mappings":"A,+JAmCA,SAASA,EAAY,EAAiB,EAA4B,CAChE,IAAMC,EAAM,SACNC,EAAU,GAA8B,CAC5C,IAAMC,EAAOF,EAAI,gBAAgBG,EAAWC,EAAQ,SAAS,EAC7D,IAAK,IAAMC,KAAa,MAAM,KAAKD,EAAQ,UAAU,EACnDF,EAAK,aAAaG,EAAU,KAAMA,EAAU,KAAK,EAEnD,OAAOH,CACT,EACMI,EAAOL,EAAOM,CAAM,EACpBC,EAAmC,CAAC,CAACD,EAAQD,CAAI,CAAC,EACxD,KAAOE,EAAM,OAAS,GAAG,CACvB,IAAMC,EAAOD,EAAM,IAAI,EACvB,GAAIC,IAAS,IAAA,GAAW,MACxB,GAAM,CAACC,EAAMC,GAAMF,EACnB,IAAK,IAAMG,KA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,EAAKI,CAAI,CAAC,EAC1D,OAAOsB,CACT,CACF,C"}
@@ -0,0 +1,2 @@
1
+ import{flushSync as e,untrack as t,useEffect as n,useId as r}from"@shadow-js/core";function i(t,n){let r=typeof document>`u`?void 0:document;if(r===void 0||typeof r.startViewTransition!=`function`){try{e(t)}catch(e){return Promise.reject(e)}return Promise.resolve()}let i,a=()=>{try{e(t)}catch(e){i={error:e}}},o=n?.types;return r.startViewTransition(o===void 0||o.length===0?a:{update:a,types:[...o]}).finished.then(()=>{if(i!==void 0)throw i.error})}function a(e){let i,a=!1,c=()=>(a||(a=!0,i=t(()=>e.children)),i),l=document.createTextNode(``),u=document.createTextNode(``),d=e.name===!0?`vt-${r()}`:void 0;return n(()=>{let t=o(l,u);t!==null&&(s(t,`view-transition-name`,d??(typeof e.name==`string`?e.name:void 0)),s(t,`view-transition-class`,e.class))}),()=>[l,c(),u]}function o(e,t){for(let n=e.nextSibling;n!==null&&n!==t;n=n.nextSibling)if(n.nodeType===1)return n;return null}function s(e,t,n){n===void 0||n===``?e.style.removeProperty(t):e.style.setProperty(t,n)}export{a as ViewTransition,i as startViewTransition};
2
+ //# sourceMappingURL=view-transition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view-transition.js","names":["startViewTransition","doc","flushSync","update","error","failure","callback","types","options","ViewTransition","built","ready","contentValue","untrack","props","start","end","generated","useId","useEffect","element","firstElementBetween","setOrClear","node","value","property"],"sources":["../../src/view-transition.ts"],"sourcesContent":["import { type Accessor, flushSync, untrack, useEffect, useId } from \"@shadow-js/core\";\n\n/** The subset of `Document` the View Transitions API adds (not yet in every TypeScript lib). */\ntype ViewTransitionDocument = Document & {\n startViewTransition?: (callback: (() => void) | { update: () => void; types?: string[] }) => {\n finished: Promise<unknown>;\n };\n};\n\n/**\n * Options of {@link startViewTransition}.\n * @since 1.0.0\n */\nexport interface ViewTransitionOptions {\n /**\n * Transition types for this update. CSS selects phases with `:active-view-transition-type(name)`,\n * so one update can animate differently from another (for example forward and back navigation).\n * Ignored where the browser has no View Transitions API.\n * @default undefined (no types: the update runs as a plain transition)\n */\n readonly types?: readonly string[];\n}\n\n/**\n * Runs `update` inside a browser view transition, so the change animates from the old screen to the\n * new one, and resolves when the animation has finished. Without the API (older browsers, or a\n * server) the update runs at once and the promise resolves. Motion preferences are handled by the\n * browser and by the CSS of the page (`prefers-reduced-motion`).\n *\n * The update runs synchronously inside the transition's callback, flushed with {@link flushSync},\n * so the new DOM is what the browser captures. An error thrown by the update rejects the promise.\n *\n * @param update Changes the state the page shows. Called once, synchronously inside the transition\n * (or at once without the API).\n * @param options `types` for CSS phase selectors; see {@link ViewTransitionOptions}. Undefined\n * starts a transition without types.\n * @returns A promise that resolves when the transition has finished (or at once without the API).\n * It rejects with the error `update` threw.\n * @throws Nothing synchronously. An error thrown by `update` rejects the returned promise.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { startViewTransition } from \"@shadow-js/web\";\n *\n * const [, setPage] = useSignal(\"home\");\n * async function openSettings() {\n * await startViewTransition(() => setPage(\"settings\"), { types: [\"forward\"] });\n * }\n * @see ViewTransition\n * @since 1.0.0\n */\nexport function startViewTransition(\n update: () => void,\n options?: ViewTransitionOptions,\n): Promise<void> {\n const doc = typeof document === \"undefined\" ? undefined : (document as ViewTransitionDocument);\n if (doc === undefined || typeof doc.startViewTransition !== \"function\") {\n try {\n flushSync(update);\n } catch (error) {\n return Promise.reject(error);\n }\n return Promise.resolve();\n }\n let failure: { readonly error: unknown } | undefined;\n const callback = (): void => {\n try {\n flushSync(update);\n } catch (error) {\n failure = { error };\n }\n };\n const types = options?.types;\n const transition = doc.startViewTransition(\n types === undefined || types.length === 0 ? callback : { update: callback, types: [...types] },\n );\n return transition.finished.then(() => {\n if (failure !== undefined) throw failure.error;\n });\n}\n\n/**\n * Props of {@link ViewTransition}.\n * @since 1.0.0\n */\nexport interface ViewTransitionProps {\n /**\n * The transition name (`view-transition-name`). Elements with the same name in the old and the new\n * screen are animated as one (`share`); an element that appears or disappears with a name animates\n * in (`enter`) or out (`exit`). `true` makes a unique name.\n * @default undefined (no inline `view-transition-name` is set on the element)\n */\n readonly name?: string | true;\n /**\n * The transition class (`view-transition-class`), to style a group of named elements at once.\n * @default undefined (no inline `view-transition-class` is set)\n */\n readonly class?: string;\n /**\n * The content. Its first element receives the name and class.\n * @default undefined (renders nothing)\n */\n readonly children?: unknown;\n}\n\n/**\n * Gives the first element of its children a view transition name and class, so the browser animates\n * that element between the old and the new screen: it enters (an element that appears with the name),\n * exits (one that disappears), updates (the same name with new content) and shares (the same name on\n * both screens, moved or resized). The phases are the browser's own; select them in CSS with\n * `::view-transition-old(name)`, `::view-transition-new(name)` and `:active-view-transition-type()`.\n * `exit=\"none\"` is not offered: the browser decides an exit before the update runs.\n *\n * No wrapper element is added. Without the browser API the name and class are only styles, so the\n * component renders correctly everywhere.\n *\n * @param props See {@link ViewTransitionProps}.\n * @returns An accessor of the content (two anchors and the children).\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { ViewTransition } from \"@shadow-js/web\";\n *\n * function Hero() {\n * const [src] = useSignal(\"/hero.png\");\n * return (\n * <ViewTransition name=\"hero\">\n * <img src={src()} />\n * </ViewTransition>\n * );\n * }\n * @see startViewTransition\n * @since 1.0.0\n */\nexport function ViewTransition(props: ViewTransitionProps): Accessor<unknown> {\n if (__SERVER__) return () => props.children;\n // Built once, when the parent first renders it (as Activity does): the server builds it at the same point.\n let built: unknown;\n let ready = false;\n const contentValue = (): unknown => {\n if (!ready) {\n ready = true;\n built = untrack(() => props.children);\n }\n return built;\n };\n const start = document.createTextNode(\"\");\n const end = document.createTextNode(\"\");\n const generated = props.name === true ? `vt-${useId()}` : undefined;\n // Runs after the DOM is committed, so the element it styles exists.\n useEffect(() => {\n const element = firstElementBetween(start, end);\n if (element === null) return;\n const name = generated ?? (typeof props.name === \"string\" ? props.name : undefined);\n setOrClear(element, \"view-transition-name\", name);\n setOrClear(element, \"view-transition-class\", props.class);\n });\n return () => [start, contentValue(), end];\n}\n\n/** The first element between two anchors, or null. */\nfunction firstElementBetween(start: Node, end: Node): HTMLElement | null {\n for (let node = start.nextSibling; node !== null && node !== end; node = node.nextSibling) {\n if (node.nodeType === 1) return node as HTMLElement;\n }\n return null;\n}\n\nfunction setOrClear(element: HTMLElement, property: string, value: string | undefined): void {\n if (value === undefined || value === \"\") element.style.removeProperty(property);\n else element.style.setProperty(property, value);\n}\n"],"mappings":"A,mFAkDA,SAAgBA,EACd,EACA,EACe,CACf,IAAMC,EAAM,OAAO,SAAa,IAAc,IAAA,GAAa,SAC3D,GAAIA,IAAQ,IAAA,IAAa,OAAOA,EAAI,qBAAwB,WAAY,CACtE,GAAI,CACFC,EAAUC,CAAM,CAClB,OAASC,EAAO,CACd,OAAO,QAAQ,OAAOA,CAAK,CAC7B,CACA,OAAO,QAAQ,QAAQ,CACzB,CACA,IAAIC,EACEC,MAAuB,CAC3B,GAAI,CACFJ,EAAUC,CAAM,CAClB,OAASC,EAAO,CACd,EAAU,CAAE,OAAM,CACpB,CACF,EACMG,EAAQC,GAAS,MAIvB,OAHmBP,EAAI,oBACrBM,IAAU,IAAA,IAAaA,EAAM,SAAW,EAAID,EAAW,CAAE,OAAQA,EAAU,MAAO,CAAC,GAAGC,CAAK,CAAE,CAE/E,CAAC,CAAC,SAAS,SAAW,CACpC,GAAIF,IAAY,IAAA,GAAW,MAAMA,EAAQ,KAC3C,CAAC,CACH,CAsDA,SAAgBI,EAAe,EAA+C,CAG5E,IAAIC,EACAC,EAAQ,GACNC,OACCD,IACH,EAAQ,GACR,EAAQE,MAAcC,EAAM,QAAQ,GAE/BJ,GAEHK,EAAQ,SAAS,eAAe,EAAE,EAClCC,EAAM,SAAS,eAAe,EAAE,EAChCC,EAAYH,EAAM,OAAS,GAAO,MAAMI,EAAM,IAAM,IAAA,GAS1D,OAPAC,MAAgB,CACd,IAAMC,EAAUC,EAAoBN,EAAOC,CAAG,EAC1CI,IAAY,OAEhBE,EAAWF,EAAS,uBADPH,IAAc,OAAOH,EAAM,MAAS,SAAWA,EAAM,KAAO,IAAA,GACzB,EAChDQ,EAAWF,EAAS,wBAAyBN,EAAM,KAAK,EAC1D,CAAC,MACY,CAACC,EAAOH,EAAa,EAAGI,CAAG,CAC1C,CAGA,SAASK,EAAoB,EAAa,EAA+B,CACvE,IAAK,IAAIE,EAAOR,EAAM,YAAaQ,IAAS,MAAQA,IAASP,EAAK,EAAOO,EAAK,YAC5E,GAAIA,EAAK,WAAa,EAAG,OAAOA,EAElC,OAAO,IACT,CAEA,SAASD,EAAW,EAAsB,EAAkB,EAAiC,CACvFE,IAAU,IAAA,IAAaA,IAAU,GAAIJ,EAAQ,MAAM,eAAeK,CAAQ,EACzEL,EAAQ,MAAM,YAAYK,EAAUD,CAAK,CAChD,C"}
@@ -0,0 +1,2 @@
1
+ import{invalidAttributeName as e}from"./internal/diagnostics.js";const t=/^[A-Za-z_:][A-Za-z0-9_:.-]*$/,n=/* @__PURE__ */ new Set([`href`,`src`,`action`,`formaction`,`xlink:href`,`srcdoc`,`poster`,`data`,`values`,`from`,`to`,`by`]),r=/* @__PURE__ */ new Set([`draggable`,`spellcheck`,`contenteditable`]),i=[`javascript:`,`data:text/html`,`vbscript:`];function a(n){if(!t.test(n))throw e(n)}function o(e){return e.startsWith(`aria-`)||e.startsWith(`data-`)||r.has(e)}function s(e){let t=``;for(let n of e){let e=n.charCodeAt(0);e>31&&(e<127||e>159)&&(t+=n)}return t}function c(e){let t=s(e).trim().toLowerCase();return i.some(e=>t.startsWith(e))}function l(e,t){let r=e.toLowerCase();return n.has(r)?r===`values`?t.split(`;`).some(c):c(t):!1}function u(e,t){return t==null?null:t===!1?o(e)?`false`:null:t===!0?o(e)?`true`:``:String(t)}function d(e){let t=e.indexOf(`:`);return t===-1?e:e.slice(t+1)}function f(e,t,n,r){let i=n.toLowerCase(),a=u(i,r);a===null?t===null?e.removeAttribute(n):e.removeAttributeNS(t,d(n)):l(i,a)?`${n}`:t===null?e.getAttribute(n)!==a&&e.setAttribute(n,a):e.getAttributeNS(t,d(n))!==a&&e.setAttributeNS(t,n,a)}function p(e,t,n){a(t),f(e,null,t,n)}function m(e,t,n,r){a(n),f(e,t===``?null:t,n,r)}function h(e,t,n){a(t);let r=e.hasAttribute(t);n?r||e.setAttribute(t,``):r&&e.removeAttribute(t)}export{a as assertAttributeName,l as isUnsafeUrlAttribute,p as setAttribute,m as setAttributeNS,h as setBoolAttribute};
2
+ //# sourceMappingURL=attributes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.js","names":["ATTRIBUTE_NAME","URL_ATTRIBUTES","ENUMERATED_ATTRIBUTES","UNSAFE_URL_PREFIXES","assertAttributeName","name","invalidAttributeName","isStringValued","lowerName","stripControls","kept","char","text","code","isUnsafeUrl","normalized","value","prefix","isUnsafeUrlAttribute","attributeText","localPart","colon","qualified","commit","namespace","el","setAttribute","setAttributeNS","setBoolAttribute","present"],"sources":["../../src/attributes.ts"],"sourcesContent":["import { invalidAttributeName, warnOnce } from \"./internal/diagnostics\";\n\n/** Names that can appear in markup: an XML-name subset without `@` or whitespace. */\nconst ATTRIBUTE_NAME = /^[A-Za-z_:][A-Za-z0-9_:.-]*$/;\n\n/**\n * Attributes whose value is a URL and therefore checked for script schemes. The SVG animation values\n * (`animate`, `set`) are checked too: with `attributeName=\"href\"` they write an `href` by animation.\n */\nconst URL_ATTRIBUTES = new Set([\n \"href\",\n \"src\",\n \"action\",\n \"formaction\",\n \"xlink:href\",\n \"srcdoc\",\n \"poster\",\n \"data\",\n \"values\",\n \"from\",\n \"to\",\n \"by\",\n]);\n\n/** Enumerated attributes where `false` is a real value (\"false\") rather than an absence. */\nconst ENUMERATED_ATTRIBUTES = new Set([\"draggable\", \"spellcheck\", \"contenteditable\"]);\n\n/** URL prefixes (after normalization) that are never written. */\nconst UNSAFE_URL_PREFIXES = [\"javascript:\", \"data:text/html\", \"vbscript:\"];\n\n/**\n * Throws a TypeError unless `name` is a valid attribute name. Runs for every name, including the\n * ones that come from spread, so no unvalidated name reaches `setAttribute`.\n * @internal\n */\nexport function assertAttributeName(name: string): void {\n if (!ATTRIBUTE_NAME.test(name)) throw invalidAttributeName(name);\n}\n\n/** True for `aria-*`, `data-*` and the enumerated attributes: their boolean values are strings. */\nfunction isStringValued(lowerName: string): boolean {\n return (\n lowerName.startsWith(\"aria-\") ||\n lowerName.startsWith(\"data-\") ||\n ENUMERATED_ATTRIBUTES.has(lowerName)\n );\n}\n\n/** Removes C0 and C1 control characters. Written as a loop so no control character appears in a regex. */\nfunction stripControls(text: string): string {\n let kept = \"\";\n for (const char of text) {\n const code = char.charCodeAt(0);\n if (code > 0x1f && (code < 0x7f || code > 0x9f)) kept += char;\n }\n return kept;\n}\n\n/** True when the URL would run script: browsers ignore the controls and case that hide the scheme. */\nfunction isUnsafeUrl(value: string): boolean {\n const normalized = stripControls(value).trim().toLowerCase();\n return UNSAFE_URL_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n\n/**\n * Reports whether writing `value` to the attribute `name` would run script: the URL check that\n * {@link setAttribute}, the head registry and the server renderer share. Use it in a custom renderer\n * before writing a URL that came from user data. URL attributes (`href`, `src`, `action`,\n * `formaction`, `xlink:href`, `srcdoc`, `poster`, `data`) are unsafe when, after removing control\n * characters, trimming and lowercasing, they start with `javascript:`, `data:text/html` or\n * `vbscript:`. The SVG animation attributes `values`, `from`, `to` and `by` are checked the same way,\n * each `;`-separated entry of `values` on its own.\n *\n * @param name Attribute name, in any case.\n * @param value The text that would be written.\n * @returns `true` when the value must not be written; `false` for every other attribute or value.\n * @example\n * import { isUnsafeUrlAttribute } from \"@shadow-js/web/extend\";\n *\n * isUnsafeUrlAttribute(\"href\", \" JavaScript:alert(1)\"); // true\n * isUnsafeUrlAttribute(\"href\", \"https://example.com\"); // false\n * isUnsafeUrlAttribute(\"title\", \"javascript:alert(1)\"); // false: not a URL attribute\n * @see setAttribute\n * @since 1.0.0\n */\nexport function isUnsafeUrlAttribute(name: string, value: string): boolean {\n const lowerName = name.toLowerCase();\n if (!URL_ATTRIBUTES.has(lowerName)) return false;\n // `values` is a `;` list: every entry is a URL of its own.\n return lowerName === \"values\" ? value.split(\";\").some(isUnsafeUrl) : isUnsafeUrl(value);\n}\n\n/** Text to write for `value`, or null when the attribute must be removed. */\nfunction attributeText(lowerName: string, value: unknown): string | null {\n if (value === null || value === undefined) return null;\n if (value === false) return isStringValued(lowerName) ? \"false\" : null;\n if (value === true) return isStringValued(lowerName) ? \"true\" : \"\";\n return String(value);\n}\n\n/** The part of a qualified name after the prefix (`xlink:href` gives `href`). */\nfunction localPart(qualified: string): string {\n const colon = qualified.indexOf(\":\");\n return colon === -1 ? qualified : qualified.slice(colon + 1);\n}\n\n/** Writes or removes one attribute, applying the value rules and the URL check. */\nfunction commit(el: Element, namespace: string | null, qualified: string, value: unknown): void {\n const lowerName = qualified.toLowerCase();\n const text = attributeText(lowerName, value);\n if (text === null) {\n if (namespace === null) el.removeAttribute(qualified);\n else el.removeAttributeNS(namespace, localPart(qualified));\n return;\n }\n if (isUnsafeUrlAttribute(lowerName, text)) {\n warnOnce(\"UNSAFE_URL_BLOCKED\", `Blocked a script URL in the \"${qualified}\" attribute.`);\n return;\n }\n if (namespace === null) {\n if (el.getAttribute(qualified) !== text) el.setAttribute(qualified, text);\n } else if (el.getAttributeNS(namespace, localPart(qualified)) !== text) {\n el.setAttributeNS(namespace, qualified, text);\n }\n}\n\n/**\n * Sets or removes one attribute with the JSX value rules: the helper compiled templates call for a\n * dynamic attribute, also usable on elements you create yourself. The DOM is touched only when the\n * text changes. A URL attribute whose value would run script (see {@link isUnsafeUrlAttribute}) is\n * left unchanged, and development builds warn once with `UNSAFE_URL_BLOCKED`.\n *\n * @param el Target element.\n * @param name Attribute name. It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.\n * @param value `null`, `undefined` and `false` remove the attribute, except that `false` writes\n * `\"false\"` for `aria-*`, `data-*`, `draggable`, `spellcheck` and `contenteditable`. `true` writes\n * `\"\"` (or `\"true\"` for those same names). Any other value is written as `String(value)`.\n * @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.\n * @example\n * import { setAttribute } from \"@shadow-js/web\";\n *\n * const link = document.createElement(\"a\");\n * setAttribute(link, \"href\", \"https://example.com\");\n * setAttribute(link, \"aria-hidden\", false); // aria-hidden=\"false\"\n * setAttribute(link, \"title\", null); // removes title\n * @see setBoolAttribute\n * @see setAttributeNS\n * @since 1.0.0\n */\nexport function setAttribute(el: Element, name: string, value: unknown): void {\n assertAttributeName(name);\n commit(el, null, name, value);\n}\n\n/**\n * Sets or removes a namespaced attribute such as `xlink:href` or `xml:lang`, with the value rules\n * and the URL check of {@link setAttribute}. Removal uses the local part of the name (`href` for\n * `xlink:href`).\n *\n * @param el Target element.\n * @param namespace Namespace URI. `\"\"` means no namespace, which behaves exactly like\n * {@link setAttribute}.\n * @param name Qualified name (`prefix:local`). It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.\n * @param value The value, with the same rules as {@link setAttribute}.\n * @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.\n * @example\n * import { setAttributeNS } from \"@shadow-js/web\";\n *\n * const XLINK = \"http://www.w3.org/1999/xlink\";\n * const use = document.createElementNS(\"http://www.w3.org/2000/svg\", \"use\");\n * setAttributeNS(use, XLINK, \"xlink:href\", \"#icon-star\");\n * setAttributeNS(use, XLINK, \"xlink:href\", null); // removes it\n * @see setAttribute\n * @since 1.0.0\n */\nexport function setAttributeNS(el: Element, namespace: string, name: string, value: unknown): void {\n assertAttributeName(name);\n commit(el, namespace === \"\" ? null : namespace, name, value);\n}\n\n/**\n * Sets or removes a presence (boolean) attribute such as `disabled` or `hidden`: the helper compiled\n * templates call for the `bool:` prefix. A truthy value sets the attribute to `\"\"`, a falsy value\n * removes it; the DOM is touched only when presence changes. No URL check applies.\n *\n * @param el Target element.\n * @param name Attribute name, such as `disabled`. It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.\n * @param value Any value: only its truthiness is read.\n * @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.\n * @example\n * import { setBoolAttribute } from \"@shadow-js/web\";\n *\n * const button = document.createElement(\"button\");\n * setBoolAttribute(button, \"disabled\", true); // disabled=\"\"\n * setBoolAttribute(button, \"disabled\", 0); // removed\n * @see setAttribute\n * @since 1.0.0\n */\nexport function setBoolAttribute(el: Element, name: string, value: unknown): void {\n assertAttributeName(name);\n const present = el.hasAttribute(name);\n if (value) {\n if (!present) el.setAttribute(name, \"\");\n } else if (present) {\n el.removeAttribute(name);\n }\n}\n"],"mappings":"A,iEAGA,MAAMA,EAAiB,+BAMjBC,kBAAiB,IAAI,IAAI,CAC7B,OACA,MACA,SACA,aACA,aACA,SACA,SACA,OACA,SACA,OACA,KACA,IACF,CAAC,EAGKC,kBAAwB,IAAI,IAAI,CAAC,YAAa,aAAc,iBAAiB,CAAC,EAG9EC,EAAsB,CAAC,cAAe,iBAAkB,WAAW,EAOzE,SAAgBC,EAAoB,EAAoB,CACtD,GAAI,CAACJ,EAAe,KAAKK,CAAI,EAAG,MAAMC,EAAqBD,CAAI,CACjE,CAGA,SAASE,EAAe,EAA4B,CAClD,OACEC,EAAU,WAAW,OAAO,GAC5BA,EAAU,WAAW,OAAO,GAC5BN,EAAsB,IAAIM,CAAS,CAEvC,CAGA,SAASC,EAAc,EAAsB,CAC3C,IAAIC,EAAO,GACX,IAAK,IAAMC,KAAQC,EAAM,CACvB,IAAMC,EAAOF,EAAK,WAAW,CAAC,EAC1BE,EAAO,KAASA,EAAO,KAAQA,EAAO,OAAO,GAAQF,EAC3D,CACA,OAAOD,CACT,CAGA,SAASI,EAAY,EAAwB,CAC3C,IAAMC,EAAaN,EAAcO,CAAK,CAAC,CAAC,KAAK,CAAC,CAAC,YAAY,EAC3D,OAAOb,EAAoB,KAAM,GAAWY,EAAW,WAAWE,CAAM,CAAC,CAC3E,CAuBA,SAAgBC,EAAqB,EAAc,EAAwB,CACzE,IAAMV,EA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B,EAAoBC,CAAI,EACxB,IAAMwB,EAAUJ,EAAG,aAAapB,CAAI,EAChCW,EACGa,GAASJ,EAAG,aAAapB,EAAM,EAAE,EAC7BwB,GACTJ,EAAG,gBAAgBpB,CAAI,CAE3B,C"}
@@ -0,0 +1,2 @@
1
+ import{onMount as e}from"@shadow-js/core";import{isHydrating as t}from"@shadow-js/core/extend";function n(n,r){if(!r)return;let i=t();e(()=>{let e=n.ownerDocument,t=e.activeElement,r=!i||t===null||t===e.body;n.isConnected&&r&&(n instanceof HTMLElement||n instanceof SVGElement)&&n.focus()})}export{n as autoFocus};
2
+ //# sourceMappingURL=autofocus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autofocus.js","names":["autoFocus","enabled","hydrating","isHydrating","onMount","doc","el","active","free"],"sources":["../../src/autofocus.ts"],"sourcesContent":["import { onMount } from \"@shadow-js/core\";\nimport { isHydrating } from \"@shadow-js/core/extend\";\n\n/**\n * Focuses an element written with `autoFocus` (React parity) once it is inserted into the document\n * by a client render or update. The compiler calls this for an `autoFocus` attribute and for\n * `autoFocus` keys of a spread, so an app that never uses `autoFocus` never reaches this code. Call it\n * yourself only for elements you create by hand, inside an owner (a component or a root): the focus\n * is requested with `onMount`, so development builds warn with `NO_OWNER_EFFECT` without one.\n *\n * The rules, which match React's for `autoFocus`:\n * - Once per element: the focus is requested when the element is created, after the owner has been\n * flushed. Moving the element later (a keyed reorder) does not focus it again.\n * - An element that is not connected when its owner flushes (a detached root) is not focused.\n * - During hydration the server markup already carries `autofocus`, so the element focuses only when\n * nothing else has the focus (the document's active element is the body or null). A user's focus\n * is never taken away by hydration.\n *\n * @param el The element. Only `HTMLElement` and `SVGElement` are focused; for any other element, and\n * for one that cannot take focus, the call does nothing.\n * @param enabled The `autoFocus` value: falsy values (`false`, `undefined`, `\"\"`, `0`) do nothing.\n * @example\n * import { autoFocus, render } from \"@shadow-js/web\";\n *\n * render(() => {\n * const input = document.createElement(\"input\");\n * autoFocus(input, true); // focused once the root has mounted it\n * return input;\n * }, document.body);\n * @since 1.0.0\n */\nexport function autoFocus(el: Element, enabled: unknown): void {\n if (!enabled) return;\n const hydrating = isHydrating();\n onMount(() => {\n const doc = el.ownerDocument;\n const active = doc.activeElement;\n // Hydration focuses only when nothing has the focus: the body or no element.\n const free = !hydrating || active === null || active === doc.body;\n if (el.isConnected && free && (el instanceof HTMLElement || el instanceof SVGElement)) {\n el.focus();\n }\n });\n}\n"],"mappings":"A,+FA+BA,SAAgBA,EAAU,EAAa,EAAwB,CAC7D,GAAI,CAACC,EAAS,OACd,IAAMC,EAAYC,EAAY,EAC9BC,MAAc,CACZ,IAAMC,EAAMC,EAAG,cACTC,EAASF,EAAI,cAEbG,EAAO,CAACN,GAAaK,IAAW,MAAQA,IAAWF,EAAI,KACzDC,EAAG,aAAeE,IAASF,aAAc,aAAeA,aAAc,aACxEA,EAAG,MAAM,CAEb,CAAC,CACH,C"}
@@ -0,0 +1,2 @@
1
+ import{cssValueText as e}from"./internal/css-units.js";import{HTML_NS as t}from"./internal/names.js";function n(e,t){let n=[[e]],r=[0],i=/* @__PURE__ */ new Set;for(;n.length>0;){let e=n.length-1,a=n[e],o=r[e]??0;if(a===void 0||o>=a.length){let e=n.pop();e!==void 0&&i.delete(e),r.pop();continue}r[e]=o+1;let s=a[o];if(Array.isArray(s)){if(i.has(s))throw TypeError(`SHADOW_CLASS_CYCLE`);i.add(s),n.push(s),r.push(0)}else if(typeof s==`string`)s!==``&&t.push(s);else if(typeof s==`number`)s!==0&&!Number.isNaN(s)&&t.push(String(s));else if(typeof s==`object`&&s){let e=s;for(let n of Object.keys(e))e[n]&&n!==``&&t.push(n)}}}function r(e){if(typeof e==`string`)return e;if(e==null||e===!1)return null;let t=[];return n(e,t),t.join(` `)}function i(e,t,n){let i=r(t);i===null?e.removeAttribute(`class`):n?e.getAttribute(`class`)!==i&&e.setAttribute(`class`,i):e.className!==i&&(e.className=i)}function a(e,n){i(e,n,e.namespaceURI!==t)}function o(e){if(typeof e==`object`&&e&&!Array.isArray(e))return e}function s(e,t,n){let r=t??{},i=n??{},a=/* @__PURE__ */ new Set([...Object.keys(i),...Object.keys(r)]);for(let t of a){let n=!!r[t];if(n!==!!i[t])for(let r of t.split(/\s+/))r!==``&&e.classList.toggle(r,n)}return r}function c(e){if(e.startsWith(`--`))return e;let t=e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);return t.startsWith(`ms-`)?`-${t}`:t}function l(t,n,r){let i=c(n);r==null||r===!1?t.style.removeProperty(i):t.style.setProperty(i,e(i,r))}function u(e,t,n){if(t==null||t===!1)return e.removeAttribute(`style`),t;if(typeof t!=`object`)return e.style.cssText=String(t),t;let r={...t},i=o(n)??{};typeof n==`string`&&(e.style.cssText=``);let a=/* @__PURE__ */ new Set([...Object.keys(i),...Object.keys(r)]);for(let t of a)Object.is(i[t],r[t])||l(e,t,r[t]);return r}export{i as applyClass,s as classList,a as className,l as setStyleProperty,u as style,c as toCssProperty};
2
+ //# sourceMappingURL=class-style.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class-style.js","names":["collectClasses","frames","root","cursors","active","top","frame","cursor","done","item","parts","record","key","classText","value","applyClass","text","el","svg","className","HTML_NS","asRecord","classList","next","before","prev","keys","now","token","toCssProperty","name","kebab","letter","setStyleProperty","property","cssValueText","style"],"sources":["../../src/class-style.ts"],"sourcesContent":["import { cssValueText } from \"./internal/css-units\";\nimport { HTML_NS } from \"./internal/names\";\n\n/** Appends the truthy class names of `value` (strings, numbers, nested arrays, objects) to `parts`. */\nfunction collectClasses(root: unknown, parts: string[]): void {\n // Explicit frames instead of recursion: array nesting depth is controlled by the user.\n const frames: unknown[][] = [[root]];\n const cursors: number[] = [0];\n const active = new Set<unknown[]>();\n while (frames.length > 0) {\n const top = frames.length - 1;\n const frame = frames[top];\n const cursor = cursors[top] ?? 0;\n if (frame === undefined || cursor >= frame.length) {\n const done = frames.pop();\n if (done !== undefined) active.delete(done);\n cursors.pop();\n continue;\n }\n cursors[top] = cursor + 1;\n const item = frame[cursor];\n if (Array.isArray(item)) {\n if (active.has(item))\n throw new TypeError(\n __DEV__ ? \"className(): a class array contains itself.\" : \"SHADOW_CLASS_CYCLE\",\n );\n active.add(item);\n frames.push(item);\n cursors.push(0);\n } else if (typeof item === \"string\") {\n if (item !== \"\") parts.push(item);\n } else if (typeof item === \"number\") {\n if (item !== 0 && !Number.isNaN(item)) parts.push(String(item));\n } else if (item !== null && typeof item === \"object\") {\n const record = item as Record<string, unknown>;\n for (const key of Object.keys(record)) {\n if (record[key] && key !== \"\") parts.push(key);\n }\n }\n }\n}\n\n/** Class text for `value`, or null when the class attribute must be removed. */\nfunction classText(value: unknown): string | null {\n if (typeof value === \"string\") return value;\n if (value === null || value === undefined || value === false) return null;\n const parts: string[] = [];\n collectClasses(value, parts);\n return parts.join(\" \");\n}\n\n/**\n * Writes a class value. `svg` selects the attribute path, which SVG and MathML need because their\n * `className` is not a plain string.\n * @internal\n */\nexport function applyClass(el: Element, value: unknown, svg: boolean): void {\n const text = classText(value);\n if (text === null) {\n el.removeAttribute(\"class\");\n return;\n }\n if (svg) {\n if (el.getAttribute(\"class\") !== text) el.setAttribute(\"class\", text);\n } else if (el.className !== text) {\n el.className = text;\n }\n}\n\n/**\n * Replaces the whole `class` of an element: the helper compiled templates call for `class` and\n * `className`. HTML elements are written through `className`; SVG and MathML elements (whose\n * `className` is not a plain string) through the `class` attribute. The DOM is touched only when\n * the text changes.\n *\n * @param el Target element.\n * @param value A string is used as is. Arrays and objects are clsx-style: non-empty strings,\n * numbers other than `0` and `NaN`, nested arrays, and the keys of objects whose value is truthy,\n * joined with spaces. `null`, `undefined` and `false` remove the attribute.\n * @throws TypeError `SHADOW_CLASS_CYCLE` when an array contains itself (directly or through a nested\n * array).\n * @example\n * import { className } from \"@shadow-js/web\";\n *\n * const card = document.createElement(\"div\");\n * className(card, [\"card\", { \"card--active\": true, \"card--muted\": false }]);\n * card.className; // \"card card--active\"\n * @see classList\n * @since 1.0.0\n */\nexport function className(el: Element, value: unknown): void {\n applyClass(el, value, el.namespaceURI !== HTML_NS);\n}\n\n/** Narrows an object value to a record of keys; arrays and primitives are not class maps. */\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n return value as Record<string, unknown>;\n}\n\n/**\n * Toggles individual classes from an object: the helper compiled templates call for `classList`.\n * Unlike {@link className}, it leaves classes it did not set alone: only keys whose truthiness\n * changed relative to `prev` are touched. A key may hold several space-separated names. Keys that\n * disappeared from `value` are switched off.\n *\n * @param el Target element.\n * @param value Map from class names to truthiness. `undefined` switches off every class `prev` had on.\n * @param prev The map returned by the previous call. Undefined (the first call) means no class was\n * on yet.\n * @returns The map now in effect (`value`, or `{}` for undefined), to pass back as `prev` next time.\n * @example\n * import { classList } from \"@shadow-js/web\";\n *\n * const el = document.createElement(\"li\");\n * let prev = classList(el, { active: true, \"is-new pulse\": true });\n * prev = classList(el, { active: false }, prev); // removes active, is-new and pulse\n * @see className\n * @since 1.0.0\n */\nexport function classList(\n el: Element,\n value: Record<string, unknown> | undefined,\n prev?: Record<string, unknown>,\n): Record<string, unknown> {\n const next: Record<string, unknown> = value ?? {};\n const before: Record<string, unknown> = prev ?? {};\n const keys = new Set([...Object.keys(before), ...Object.keys(next)]);\n for (const key of keys) {\n const now = Boolean(next[key]);\n const was = Boolean(before[key]);\n if (now === was) continue;\n for (const token of key.split(/\\s+/)) {\n if (token !== \"\") el.classList.toggle(token, now);\n }\n }\n return next;\n}\n\n/**\n * Converts a camelCase style name to a CSS property name. Custom properties are kept as they are,\n * and vendor prefixes map to `-webkit-` and `-ms-`.\n * @internal\n */\nexport function toCssProperty(name: string): string {\n if (name.startsWith(\"--\")) return name;\n const kebab = name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n return kebab.startsWith(\"ms-\") ? `-${kebab}` : kebab;\n}\n\n/**\n * Sets or removes one inline style property: the helper compiled templates call for the `style:`\n * prefix. Other inline properties are left alone.\n *\n * @param el HTML or SVG element.\n * @param name CSS property in camelCase (`backgroundColor`, `msTransform` gives `-ms-transform`) or\n * kebab-case, or a custom property (`--accent`, kept as is).\n * @param value `null`, `undefined` and `false` remove the property. A number is in pixels, as in\n * React, unless it is `0`, the property is unitless (`opacity`, `zIndex`, `flexGrow`, `lineHeight`,\n * ...) or a custom property. Any other value is written as `String(value)`.\n * @example\n * import { setStyleProperty } from \"@shadow-js/web\";\n *\n * const el = document.createElement(\"div\");\n * setStyleProperty(el, \"marginTop\", 8); // margin-top: 8px\n * setStyleProperty(el, \"--accent\", \"rebeccapurple\");\n * setStyleProperty(el, \"opacity\", 0.5); // unitless\n * @see style\n * @since 1.0.0\n */\nexport function setStyleProperty(el: HTMLElement | SVGElement, name: string, value: unknown): void {\n const property = toCssProperty(name);\n if (value === null || value === undefined || value === false) {\n el.style.removeProperty(property);\n } else {\n el.style.setProperty(property, cssValueText(property, value));\n }\n}\n\n/**\n * Sets the inline style of an element: the helper compiled templates call for a `style` attribute.\n * An object is diffed against `prev` so that only changed properties are written, each with the\n * rules of {@link setStyleProperty}; properties that disappeared are removed.\n *\n * @param el HTML or SVG element.\n * @param value An object of properties (camelCase, kebab-case or custom names). A string replaces\n * `cssText`. `null`, `undefined` and `false` remove the `style` attribute.\n * @param prev The value returned by the previous call. Undefined (the first call) diffs against an\n * empty style. When it is a string, `cssText` is cleared before the object is written.\n * @returns What to pass back as `prev` next time: a shallow copy of an object value, otherwise\n * `value` itself.\n * @example\n * import { style } from \"@shadow-js/web\";\n *\n * const el = document.createElement(\"div\");\n * let prev = style(el, { color: \"red\", width: 120 }); // width: 120px\n * prev = style(el, { color: \"blue\" }, prev); // writes color, removes width\n * @see setStyleProperty\n * @since 1.0.0\n */\nexport function style(el: HTMLElement | SVGElement, value: unknown, prev?: unknown): unknown {\n if (value === null || value === undefined || value === false) {\n el.removeAttribute(\"style\");\n return value;\n }\n if (typeof value !== \"object\") {\n el.style.cssText = String(value);\n return value;\n }\n const next = { ...(value as Record<string, unknown>) };\n const before = asRecord(prev) ?? {};\n if (typeof prev === \"string\") el.style.cssText = \"\";\n const keys = new Set([...Object.keys(before), ...Object.keys(next)]);\n for (const key of keys) {\n if (Object.is(before[key], next[key])) continue;\n setStyleProperty(el, key, next[key]);\n }\n return next;\n}\n"],"mappings":"A,qGAIA,SAASA,EAAe,EAAe,EAAuB,CAE5D,IAAMC,EAAsB,CAAC,CAACC,CAAI,CAAC,EAC7BC,EAAoB,CAAC,CAAC,EACtBC,kBAAS,IAAI,IACnB,KAAOH,EAAO,OAAS,GAAG,CACxB,IAAMI,EAAMJ,EAAO,OAAS,EACtBK,EAAQL,EAAOI,GACfE,EAASJ,EAAQE,IAAQ,EAC/B,GAAIC,IAAU,IAAA,IAAaC,GAAUD,EAAM,OAAQ,CACjD,IAAME,EAAOP,EAAO,IAAI,EACpBO,IAAS,IAAA,IAAWJ,EAAO,OAAOI,CAAI,EAC1CL,EAAQ,IAAI,EACZ,QACF,CACA,EAAQE,GAAOE,EAAS,EACxB,IAAME,EAAOH,EAAMC,GACnB,GAAI,MAAM,QAAQE,CAAI,EAAG,CACvB,GAAIL,EAAO,IAAIK,CAAI,EACjB,MAAU,UACkD,oBAC5D,EACFL,EAAO,IAAIK,CAAI,EACfR,EAAO,KAAKQ,CAAI,EAChBN,EAAQ,KAAK,CAAC,CAChB,MAAO,GAAI,OAAOM,GAAS,SACrBA,IAAS,IAAIC,EAAM,KAAKD,CAAI,OAC3B,GAAI,OAAOA,GAAS,SACrBA,IAAS,GAAK,CAAC,OAAO,MAAMA,CAAI,GAAGC,EAAM,KAAK,OAAOD,CAAI,CAAC,OACzD,GAAqB,OAAOA,GAAS,UAAjCA,EAA2C,CACpD,IAAME,EAASF,EACf,IAAK,IAAMG,KAAO,OAAO,KAAKD,CAAM,EAC9BA,EAAOC,IAAQA,IAAQ,IAAIF,EAAM,KAAKE,CAAG,CAEjD,CACF,CACF,CAGA,SAASC,EAAU,EAA+B,CAChD,GAAI,OAA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sBA,SAAgBE,EAAiB,EAA8B,EAAc,EAAsB,CACjG,IAAMC,EAAWL,EAAcC,CAAI,EAC/BhB,GAAU,MAA+BA,IAAU,GACrDG,EAAG,MAAM,eAAeiB,CAAQ,EAEhCjB,EAAG,MAAM,YAAYiB,EAAUC,EAAaD,EAAUpB,CAAK,CAAC,CAEhE,CAuBA,SAAgBsB,EAAM,EAA8B,EAAgB,EAAyB,CAC3F,GAAItB,GAAU,MAA+BA,IAAU,GAErD,OADAG,EAAG,gBAAgB,OAAO,EACnBH,EAET,GAAI,OAAOA,GAAU,SAEnB,MADA,GAAG,MAAM,QAAU,OAAOA,CAAK,EACxBA,EAET,IAAMS,EAAO,CAAE,GAAIT,CAAkC,EAC/CU,EAASH,EAASI,CAAI,GAAK,CAAC,EAC9B,OAAOA,GAAS,WAAU,EAAG,MAAM,QAAU,IACjD,IAAMC,kBAAO,IAAI,IAAI,CAAC,GAAG,OAAO,KAAKF,CAAM,EAAG,GAAG,OAAO,KAAKD,CAAI,CAAC,CAAC,EACnE,IAAK,IAAMX,KAAOc,EACZ,OAAO,GAAGF,EAAOZ,GAAMW,EAAKX,EAAI,GACpCqB,EAAiBhB,EAAIL,EAAKW,EAAKX,EAAI,EAErC,OAAOW,CACT,C"}
@@ -0,0 +1,2 @@
1
+ import{currentScope as e,enterComponent as t}from"./internal/hydration-scope.js";import{createOwner as n,runInScope as r}from"@shadow-js/core/extend";function i(i,a,o){return t(()=>{let t=n();return t.idPrefix=e()?.id,r({owner:t,listener:null},()=>i(a))})}export{i as createComponent};
2
+ //# sourceMappingURL=component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.js","names":["createComponent","enterComponent","owner","createOwner","currentScope","runInScope","component","props"],"sources":["../../src/component.ts"],"sourcesContent":["import {\n addCleanup,\n createOwner,\n DEVTOOLS_EVENT,\n devtoolsReport,\n runInScope,\n} from \"@shadow-js/core/extend\";\nimport { currentScope, enterComponent } from \"./internal/hydration-scope\";\n\n/** Dev-only: the name each component was created with, for devtools. Weak, so components are not kept alive. */\nconst componentNames = new WeakMap<object, string>();\n\n/**\n * Calls a component untracked, under a new owner that is a child of the current one: cleanups and\n * effects it creates are disposed with the enclosing scope. The name, given in development builds,\n * is recorded for devtools.\n *\n * @param component The component function.\n * @param props The props object (usually with getters for reactive props).\n * @param name Optional devtools name.\n * @returns Whatever the component returns.\n * @example\n * import { createComponent } from \"@shadow-js/web\";\n *\n * function Counter(props: { start: number }) {\n * return `Count: ${props.start}`;\n * }\n *\n * const view = createComponent(Counter, { start: 0 }, \"Counter\");\n * @since 1.0.0\n */\nexport function createComponent<P>(\n component: (props: P) => unknown,\n props: P,\n name?: string,\n): unknown {\n if (__DEV__ && name !== undefined) componentNames.set(component, name);\n return enterComponent(() => {\n // Every component runs under an owner of its own: devtools attribute updates to it, and\n // `useId` uses its hydration-scope key as a prefix, so ids agree between server and browser\n // even though the browser creates more owners (effects) than the server does.\n const owner = createOwner();\n owner.idPrefix = currentScope()?.id;\n // One scope switch (owner in, listener off): deep component trees are bounded by the call stack.\n const result = runInScope({ owner, listener: null }, () => component(props));\n if (__DEV__) {\n devtoolsReport(\n DEVTOOLS_EVENT.COMPONENT_MOUNTED,\n owner,\n componentNames.get(component),\n result,\n );\n addCleanup(owner, () => devtoolsReport(DEVTOOLS_EVENT.COMPONENT_UNMOUNTED, owner));\n }\n return result;\n });\n}\n\n/**\n * The devtools name recorded for a component in development builds, if any.\n * @internal\n */\nexport function componentName(component: object): string | undefined {\n return componentNames.get(component);\n}\n"],"mappings":"A,sJA+BA,SAAgBA,EACd,EACA,EACA,EACS,CAET,OAAOC,MAAqB,CAI1B,IAAMC,EAAQC,EAAY,EAa1B,MAZA,GAAM,SAAWC,EAAa,CAAC,EAAE,GAElBC,EAAW,CAAE,QAAO,SAAU,IAAK,MAASC,EAAUC,CAAK,CAU9D,CACd,CAAC,CACH,C"}
@@ -0,0 +1,2 @@
1
+ import"@shadow-js/core";import"@shadow-js/core/extend";function e(e){return()=>e.children}export{e as Activity};
2
+ //# sourceMappingURL=activity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activity.js","names":["Activity","props"],"sources":["../../../src/control-flow/activity.ts"],"sourcesContent":["import {\n type Accessor,\n runWithOwner,\n untrack,\n useEffect,\n useRenderEffect,\n useSignal,\n} from \"@shadow-js/core\";\nimport { createOwner, pauseOwner, resumeOwner } from \"@shadow-js/core/extend\";\n\n/**\n * `visible` shows the children; `hidden` keeps them alive (state, DOM and focus) but out of sight.\n * @since 1.0.0\n */\nexport type ActivityMode = \"visible\" | \"hidden\";\n\n/**\n * Props of {@link Activity}.\n * @since 1.0.0\n */\nexport interface ActivityProps {\n /**\n * `\"visible\"` shows the children; `\"hidden\"` keeps them alive but out of sight. Changing it\n * does not rebuild the children and may be reactive.\n * @default \"visible\"\n */\n readonly mode?: ActivityMode;\n /**\n * The content. Built once, when the parent first renders the Activity.\n * @default undefined (the Activity renders nothing)\n */\n readonly children?: unknown;\n}\n\n/** What a hidden Activity changed in the DOM, so showing it restores exactly that. */\ninterface Stash {\n readonly elements: Array<readonly [HTMLElement, string]>;\n readonly texts: Array<{ readonly text: Text; readonly parent: Node; readonly next: Node | null }>;\n readonly scrolls: Array<readonly [Element, number, number]>;\n readonly focus: Element | null;\n}\n\n/**\n * Hides the nodes between two anchors without removing them. Top-level elements get\n * `display: none` (their own state, subtree and listeners are untouched). Top-level text nodes are\n * detached (a text node cannot be hidden) and put back in order when shown. Scroll offsets and the\n * focused element are remembered, because `display: none` loses both.\n */\nfunction stashBetween(start: Node, end: Node): Stash | undefined {\n const parent = start.parentNode;\n if (parent === null) return undefined;\n const elements: Array<readonly [HTMLElement, string]> = [];\n const texts: Stash[\"texts\"][number][] = [];\n const scrolls: Array<readonly [Element, number, number]> = [];\n const active = document.activeElement;\n let focus: Element | null = null;\n let node: Node | null = start.nextSibling;\n while (node !== null && node !== end) {\n const next: Node | null = node.nextSibling;\n if (node.nodeType === 1) {\n const element = node as HTMLElement;\n elements.push([element, element.style.display]);\n element.style.display = \"none\";\n for (const scrollable of [element, ...Array.from(element.querySelectorAll(\"*\"))]) {\n if (scrollable.scrollTop !== 0 || scrollable.scrollLeft !== 0) {\n scrolls.push([scrollable, scrollable.scrollTop, scrollable.scrollLeft]);\n }\n }\n if (active !== null && element.contains(active)) focus = active;\n } else if (node.nodeType === 3) {\n texts.push({ text: node as Text, parent, next });\n parent.removeChild(node);\n }\n node = next;\n }\n return { elements, texts, scrolls, focus };\n}\n\n/** Puts back what {@link stashBetween} changed. Texts are restored last-to-first, so each finds its next. */\nfunction restore(stash: Stash, end: Node): void {\n for (let i = stash.texts.length - 1; i >= 0; i -= 1) {\n const entry = stash.texts[i];\n if (entry === undefined || entry.text.parentNode !== null) continue;\n const before = entry.next !== null && entry.next.parentNode === entry.parent ? entry.next : end;\n entry.parent.insertBefore(entry.text, before);\n }\n for (const [element, display] of stash.elements) element.style.display = display;\n for (const [element, top, left] of stash.scrolls) {\n element.scrollTop = top;\n element.scrollLeft = left;\n }\n const focus = stash.focus;\n if (focus instanceof HTMLElement && focus.isConnected) focus.focus({ preventScroll: true });\n}\n\n/**\n * Keeps its children alive while hidden: `mode=\"hidden\"` removes them from sight but keeps their state,\n * their DOM nodes and their focus and scroll position. Hidden content is paused: its effects run their\n * cleanups and wait, its memos keep their last value, and its DOM does not update. Updates that arrive\n * while hidden are applied once, when the content is shown again.\n *\n * Use it for tabs, wizards and routes you want back instantly. A hidden Activity mounted hidden renders\n * its DOM once (so it is ready to show) and runs no effects until it is shown. The server renders the\n * children without hiding them; the client hides them once it hydrates.\n *\n * @param props See {@link ActivityProps}.\n * @returns An accessor of the content (two anchors and the children).\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { Activity } from \"@shadow-js/web\";\n *\n * function Chat() {\n * return <p>Chat</p>;\n * }\n *\n * function Tabs() {\n * const [tab] = useSignal(\"chat\");\n * return (\n * <Activity mode={tab() === \"chat\" ? \"visible\" : \"hidden\"}>\n * <Chat />\n * </Activity>\n * );\n * }\n * @see Show\n * @since 1.0.0\n */\nexport function Activity(props: ActivityProps): Accessor<unknown> {\n if (__SERVER__) return () => props.children;\n // The content lives under its own owner, so pausing it reaches every effect and memo it created.\n const content = createOwner();\n // Built when the parent first reads it, not here: the server builds children at the same point of the\n // render, which keeps hydration keys equal on both sides.\n let built: unknown;\n let ready = false;\n const contentValue = (): unknown => {\n if (!ready) {\n ready = true;\n built = runWithOwner(content, () => untrack(() => props.children));\n }\n return built;\n };\n // Empty text anchors bound the content: the DOM range the visibility code hides and shows.\n const start = document.createTextNode(\"\");\n const end = document.createTextNode(\"\");\n const [hidden, setHidden] = useSignal(false);\n let paused = false;\n // Pausing happens in the render phase, before the content's own effects can run.\n useRenderEffect(\n () => props.mode === \"hidden\",\n (isHidden) => {\n if (isHidden === paused) return;\n paused = isHidden;\n if (isHidden) pauseOwner(content);\n else resumeOwner(content);\n setHidden(isHidden);\n },\n );\n // Runs after the DOM is committed (a user effect), so the nodes it hides exist.\n let stash: Stash | undefined;\n useEffect(() => {\n if (hidden()) {\n if (stash === undefined) stash = stashBetween(start, end);\n } else if (stash !== undefined) {\n const previous = stash;\n stash = undefined;\n restore(previous, end);\n }\n });\n return () => [start, contentValue(), end];\n}\n"],"mappings":"A,uDA8HA,SAAgBA,EAAS,EAAyC,CAChD,UAAaC,EAAM,QA0CrC,C"}
@@ -0,0 +1,2 @@
1
+ import{createRoot as e,getOwner as t,onCleanup as n,untrack as r,useMemo as i}from"@shadow-js/core";import{transitionHooks as a}from"@shadow-js/core/extend";function o(e,t){return e.index===t.index?e.index===-1||!e.keyed||e.when===t.when:!1}function s(s,c,l){let u,d={live:void 0},f,p=t(),m=i(()=>{let e=c();u=e;let t=d.live;return t!==void 0&&e.index===t.owned.index&&(t.owned.value=e.when),e},{equals:o}),h=e=>()=>{if(e.disposing)return e.value;let t=r(m);if(t.index!==e.index)throw TypeError(`SHADOW_STALE_ACCESSOR`);return(u??t).read()},g=(e,t,n)=>{if(e.index===-1)return r(l);let a=e.body();if(typeof a!=`function`)return a;if(a.length===0)return i(()=>a(),{allowWrites:!0,lazy:!n});let o=a;return r(()=>o(e.keyed?e.when:h(t)))};return i(()=>{let t=m();if(f===void 0&&d.live!==void 0&&(f=a()?.slotSwap(d,g,o,p)),f?.step(t))return d.live?.result;d.live!==void 0&&(d.live.owned.disposing=!1),d.live=void 0;let r={index:t.index,value:t.when,disposing:!1},i=g(t,r,!1);return e(()=>{n(()=>{r.disposing=!0})}),d.live={choice:t,owned:r,result:i},i},{allowWrites:!0})}export{s as createBranches};
2
+ //# sourceMappingURL=branch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"branch.js","names":["sameChoice","a","b","createBranches","latest","state","swap","owner","getOwner","selection","useMemo","next","select","live","accessorFor","owned","current","untrack","produce","choice","fallback","body","eager","callback","transitionHooks","result","createRoot","onCleanup"],"sources":["../../../src/control-flow/branch.ts"],"sourcesContent":["import { type Accessor, createRoot, getOwner, onCleanup, untrack, useMemo } from \"@shadow-js/core\";\nimport {\n type SlotBranch,\n type SlotOwned,\n type SlotState,\n type SlotSwap,\n transitionHooks,\n} from \"@shadow-js/core/extend\";\n\n/**\n * Branch index meaning \"no branch is selected\": the fallback is shown.\n * @internal\n */\nexport const FALLBACK = -1;\n\n/**\n * One selection made by a control-flow component.\n *\n * - `index` names the chosen branch, or {@link FALLBACK}.\n * - `keyed` and `when` decide whether a change of selection rebuilds the branch.\n * - `read` reads the condition reactively; the callback child's accessor argument uses it.\n * - `body` reads the branch's children getter. It is read tracked: a compiled `children` getter\n * that is a plain reactive expression (`{count()}`) must update the output. Creating child JSX\n * reads nothing here, because components and bindings track inside their own computations.\n *\n * @internal\n * @since 1.0.0\n */\nexport interface Choice {\n /** The chosen branch: a zero-based position, or {@link FALLBACK} when no branch is chosen. */\n readonly index: number;\n /** True when a change of `when` (by identity) rebuilds the branch even if `index` is the same. */\n readonly keyed: boolean;\n /** The value of the condition at selection time; a keyed callback child receives it. */\n readonly when: unknown;\n /** Reads the current value of the condition, tracked; backs the callback child's accessor. */\n readonly read: () => unknown;\n /** Reads the chosen branch's children (content, an accessor, or a callback), tracked. */\n readonly body: () => unknown;\n}\n\n/** Bookkeeping for the branch that is on screen. */\ntype Rendered = SlotOwned;\n\n/** A branch on screen, or one a transition builds (see the transition layer in core's concurrency.ts). */\ntype Live = SlotBranch<Choice>;\n\n/**\n * Whether two selections describe the same rendered output. Non-keyed branches only care about\n * which branch is chosen, which is the same as comparing truthiness of the condition. Keyed\n * branches also rebuild when the condition's identity changes. The fallback never rebuilds.\n */\nfunction sameChoice(a: Choice, b: Choice): boolean {\n if (a.index !== b.index) return false;\n return a.index === FALLBACK || !a.keyed || a.when === b.when;\n}\n\n/**\n * Builds the accessor behind `Show` and `Switch`. The selection memo decides which branch is chosen;\n * the output memo commits it.\n *\n * Ordinary changes build the branch inside the output memo: the memo's teardown removes the previous\n * branch first. A change made during a transition, while a branch is on screen, is handled by the\n * transition layer (core's `slotSwap`, reached through `transitionHooks`), created by the first such change: it builds the\n * new branch under a hold and commits it once its reads have settled. Until then the shown branch stays\n * on screen, its DOM untouched, and nothing is built twice. Apps that never change a shown branch in a\n * transition never create that layer.\n *\n * Teardown ordering: the owner of a branch is marked `disposing` before it is torn down, so a cleanup\n * that reads the callback's accessor learns that the branch is going away and gets the last truthy\n * value instead of a stale-accessor error.\n *\n * @param name Component name used in diagnostics.\n * @param select Tracked selection; runs inside the selection memo.\n * @param fallback Reads the fallback lazily, untracked, only when it is shown.\n * @returns The output accessor.\n * @throws TypeError (production message `SHADOW_STALE_ACCESSOR`) from the accessor handed to a\n * callback child, when it is read after its branch was replaced.\n * @internal\n * @since 1.0.0\n */\nexport function createBranches(\n name: string,\n select: () => Choice,\n fallback: () => unknown,\n): Accessor<unknown> {\n /** Selection computed most recently; its `read` is always current, unlike the held value. */\n let latest: Choice | undefined;\n /** The branch on screen, and what the output last returned. The transition layer reads and writes it. */\n const state: SlotState<Choice> = { live: undefined };\n /** The transition layer, created by the first transition that replaces the branch on screen. */\n let swap: SlotSwap<Choice> | undefined;\n /** The slot's owner: the transition layer's holder for the branches it builds lives under it. */\n const owner = getOwner();\n\n const pick = (): Choice => {\n const next = select();\n latest = next;\n const live: Live | undefined = state.live;\n if (live !== undefined && next.index === live.owned.index) live.owned.value = next.when;\n return next;\n };\n const selection = useMemo<Choice>(pick, { equals: sameChoice });\n\n const accessorFor = (owned: Rendered): (() => unknown) => {\n return () => {\n if (owned.disposing) return owned.value;\n const current = untrack(selection);\n if (current.index !== owned.index) {\n throw new TypeError(\n __DEV__\n ? `ShadowJS ${name}: stale accessor. The branch was replaced; read the accessor only while its condition is truthy.`\n : \"SHADOW_STALE_ACCESSOR\",\n );\n }\n return (latest ?? current).read();\n };\n };\n\n /**\n * The value a branch (or the fallback) produces. `eager` evaluates a zero-argument accessor now (a\n * transition build needs to see whether a read was held); otherwise it is evaluated when rendered.\n */\n const produce = (choice: Choice, owned: Rendered, eager: boolean): unknown => {\n if (choice.index === FALLBACK) return untrack(fallback);\n const body = choice.body();\n if (typeof body !== \"function\") return body;\n // A zero-argument function is an accessor. Returned as it is, the renderer would call it in an\n // effect outside this branch, so an error it throws would escape the boundary around the Show\n // (STATUS: ErrorBoundary does not catch a Show function child). A memo owned here evaluates it\n // inside the branch, where the nearest error handler applies.\n if (body.length === 0) {\n // Lazy outside a transition: the parent evaluates it when it renders, so a deep chain of\n // branches is built in that render rather than inside this one.\n return useMemo<unknown>(() => (body as () => unknown)(), {\n allowWrites: true,\n lazy: !eager,\n });\n }\n const callback = body as (value: unknown) => unknown;\n return untrack(() => callback(choice.keyed ? choice.when : accessorFor(owned)));\n };\n\n return useMemo<unknown>(\n () => {\n const choice = selection();\n if (swap === undefined && state.live !== undefined) {\n swap = transitionHooks()?.slotSwap(state, produce, sameChoice, owner);\n }\n if (swap?.step(choice)) return state.live?.result;\n\n // The usual path: the previous branch was torn down by this memo (its teardown marked it disposing;\n // the flag is cleared again, so a stale accessor throws). Build the next one here.\n if (state.live !== undefined) state.live.owned.disposing = false;\n state.live = undefined;\n const owned: Rendered = { index: choice.index, value: choice.when, disposing: false };\n const result = produce(choice, owned, false);\n // Created last, so it is the newest child: the memo's teardown marks the branch first.\n createRoot(() => {\n onCleanup(() => {\n owned.disposing = true;\n });\n });\n state.live = { choice, owned, result };\n return result;\n },\n { allowWrites: true },\n );\n}\n"],"mappings":"A,6JAoDA,SAASA,EAAW,EAAW,EAAoB,CAEjD,OADIC,EAAE,QAAUC,EAAE,MACXD,EAAE,QAAA,IAAsB,CAACA,EAAE,OAASA,EAAE,OAASC,EAAE,KADxB,EAElC,CA0BA,SAAgBC,EACd,EACA,EACA,EACmB,CAEnB,IAAIC,EAEEC,EAA2B,CAAE,KAAM,IAAA,EAAU,EAE/CC,EAEEC,EAAQC,EAAS,EASjBC,EAAYC,MAPS,CACzB,IAAMC,EAAOC,EAAO,EACpB,EAASD,EACT,IAAME,EAAyBR,EAAM,KAErC,OADIQ,IAAS,IAAA,IAAaF,EAAK,QAAUE,EAAK,MAAM,QAAO,EAAK,MAAM,MAAQF,EAAK,MAC5EA,CACT,EACwC,CAAE,OAAQX,CAAW,CAAC,EAExDc,EAAe,OACN,CACX,GAAIC,EAAM,UAAW,OAAOA,EAAM,MAClC,IAAMC,EAAUC,EAAQR,CAAS,EACjC,GAAIO,EAAQ,QAAUD,EAAM,MAC1B,MAAU,UAGJ,uBACN,EAEF,OAAQX,GAAUY,EAAA,CAAS,KAAK,CAClC,EAOIE,GAAW,EAAgB,EAAiB,IAA4B,CAC5E,GAAIC,EAAO,QAAA,GAAoB,OAAOF,EAAQG,CAAQ,EACtD,IAAMC,EAAOF,EAAO,KAAK,EACzB,GAAI,OAAOE,GAAS,WAAY,OAAOA,EAKvC,GAAIA,EAAK,SAAW,EAGlB,OAAOX,MAAwBW,EAAuB,EAAG,CACvD,YAAa,GACb,KAAM,CAACC,CACT,CAAC,EAEH,IAAMC,EAAWF,EACjB,OAAOJ,MAAcM,EAASJ,EAAO,MAAQA,EAAO,KAAOL,EAAYC,CAAK,CAAC,CAAC,CAChF,EAEA,OAAOL,MACC,CACJ,IAAMS,EAASV,EAAU,EAIzB,GAHIH,IAAS,IAAA,IAAaD,EAAM,OAAS,IAAA,KACvC,EAAOmB,EAAgB,CAAC,EAAE,SAASnB,EAAOa,EAASlB,EAAYO,CAAK,GAElED,GAAM,KAAKa,CAAM,EAAG,OAAOd,EAAM,MAAM,OAIvCA,EAAM,OAAS,IAAA,KAAW,EAAM,KAAK,MAAM,UAAY,IAC3D,EAAM,KAAO,IAAA,GACb,IAAMU,EAAkB,CAAE,MAAOI,EAAO,MAAO,MAAOA,EAAO,KAAM,UAAW,EAAM,EAC9EM,EAASP,EAAQC,EAAQJ,EAAO,EAAK,EAQ3C,OANAW,MAAiB,CACfC,MAAgB,CACd,EAAM,UAAY,EACpB,CAAC,CACH,CAAC,EACD,EAAM,KAAO,CAAE,SAAQ,QAAO,QAAO,EAC9BF,CACT,EACA,CAAE,YAAa,EAAK,CACtB,CACF,C"}
@@ -0,0 +1,2 @@
1
+ import{Show as e}from"./show.js";import{onMount as t,useSignal as n}from"@shadow-js/core";function r(r){let[i,a]=n(!1);return t(()=>{a(!0)}),e({get when(){return i()},get fallback(){return r.fallback},get children(){return r.children}})}export{r as ClientOnly};
2
+ //# sourceMappingURL=client-only.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-only.js","names":["ClientOnly","mounted","setMounted","useSignal","onMount","Show","props"],"sources":["../../../src/control-flow/client-only.ts"],"sourcesContent":["import { type Accessor, onMount, useSignal } from \"@shadow-js/core\";\nimport type { JsxChild } from \"../jsx/types\";\nimport { Show } from \"./show\";\n\n/**\n * Props of {@link ClientOnly}.\n * @since 1.0.0\n */\nexport interface ClientOnlyProps {\n /**\n * Rendered on the server and while the page hydrates, until the browser has mounted.\n * @default undefined (nothing is rendered until mount)\n */\n readonly fallback?: JsxChild;\n /**\n * Rendered in the browser only, after mount.\n * @default undefined (nothing is rendered after mount either)\n */\n readonly children?: JsxChild | (() => unknown);\n}\n\n/**\n * Renders `children` in the browser only. The server (and the first client pass, which must match\n * the server's markup) renders `fallback`; once mounted, the children replace it. Use it for\n * content that depends on browser state: `window`, `localStorage`, media queries, charts.\n *\n * @param props See {@link ClientOnlyProps}.\n * @returns An accessor of the current content: the fallback until mount, then the children.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { ClientOnly } from \"@shadow-js/web\";\n *\n * function Chart(props: { data: number[] }) {\n * return <canvas data-points={props.data.length} />;\n * }\n *\n * function Report() {\n * const [rows] = useSignal([1, 2, 3]);\n * return (\n * <ClientOnly fallback={<p>Loading chart...</p>}>\n * <Chart data={rows()} />\n * </ClientOnly>\n * );\n * }\n * @see Show\n * @since 1.0.0\n */\nexport function ClientOnly(props: ClientOnlyProps): Accessor<unknown> {\n const [mounted, setMounted] = useSignal(false);\n // Never runs on the server, so the server always renders the fallback.\n onMount(() => {\n setMounted(true);\n });\n return Show({\n get when() {\n return mounted();\n },\n get fallback() {\n return props.fallback;\n },\n get children() {\n return props.children;\n },\n });\n}\n"],"mappings":"A,0FA+CA,SAAgBA,EAAW,EAA2C,CACpE,GAAM,CAACC,EAASC,GAAcC,EAAU,EAAK,EAK7C,OAHAC,MAAc,CACZF,EAAW,EAAI,CACjB,CAAC,EACMG,EAAK,CACV,IAAI,MAAO,CACT,OAAOJ,EAAQ,CACjB,EACA,IAAI,UAAW,CACb,OAAOK,EAAM,QACf,EACA,IAAI,UAAW,CACb,OAAOA,EAAM,QACf,CACF,CAAC,CACH,C"}
@@ -0,0 +1,2 @@
1
+ import{createComponent as e}from"../component.js";import{ssrElement as t,ssrRaw as n}from"../server/element.js";import{mergeProps as r,splitProps as i,untrack as a,useMemo as o}from"@shadow-js/core";const s=/^[a-z][a-z0-9-]*$/i,c=/* @__PURE__ */ new Set([`script`]);function l(e,r){let i=e.toLowerCase();if(!s.test(e)||c.has(i))throw TypeError(`SHADOW_DYNAMIC_TAG`);return t(e,r,()=>{let{children:e}=r;return e===void 0?void 0:[n(`<!--[-->`),e,n(`<!--]-->`)]},!0)}function u(t,n){if(!t)return null;if(typeof t==`string`)return l(t,n);if(typeof t==`function`)return e(t,n);throw TypeError(`SHADOW_DYNAMIC_COMPONENT`)}function d(e){let[,t]=i(e,[`component`]);return o(()=>{let n=e.component;return a(()=>u(n,t))},{allowWrites:!0})}function f(e,t={}){return d(r({get component(){return e()}},t))}export{d as Dynamic,f as createDynamic};
2
+ //# sourceMappingURL=dynamic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamic.js","names":["TAG_PATTERN","DENIED_TAGS","buildElement","lower","tag","ssrElement","props","children","ssrRaw","buildTarget","target","createComponent","Dynamic","rest","splitProps","useMemo","untrack","createDynamic","mergeProps","component"],"sources":["../../../src/control-flow/dynamic.ts"],"sourcesContent":["import { mergeProps, splitProps, untrack, useMemo } from \"@shadow-js/core\";\nimport { createComponent } from \"../component\";\nimport { bindRegion, claims, createRegion, nextKey, SVG_NS } from \"../extend\";\nimport { ssrElement, ssrRaw } from \"../server/element\";\nimport { spread } from \"../spread\";\n\n/**\n * A component function or a tag name, as {@link Dynamic} accepts it. The props of a function are\n * checked by the caller.\n * @since 1.0.0\n */\nexport type DynamicComponent = string | ((props: never) => unknown);\n\n/**\n * Everything `component` may be: a component, a tag name, or `undefined`, `null` or `false`, which\n * render nothing.\n * @since 1.0.0\n */\nexport type DynamicTarget = DynamicComponent | undefined | null | false;\n\n/**\n * Props of {@link Dynamic}: `component` plus the props of whatever it renders. Every other prop\n * passes through, reactive getters included.\n * @since 1.0.0\n */\nexport interface DynamicProps<C extends DynamicTarget = DynamicTarget> {\n /** The component to render, a tag name, or a falsy value for nothing. */\n readonly component: C;\n /** Any other prop is passed to the rendered component or set on the element, still reactive. */\n readonly [prop: string]: unknown;\n}\n\n/** Tag names that take the SVG namespace. Anything else is HTML. */\nconst SVG_TAGS: ReadonlySet<string> = new Set([\n \"svg\",\n \"g\",\n \"path\",\n \"circle\",\n \"ellipse\",\n \"line\",\n \"polygon\",\n \"polyline\",\n \"rect\",\n \"text\",\n \"tspan\",\n \"textpath\",\n \"defs\",\n \"use\",\n \"symbol\",\n \"marker\",\n \"clippath\",\n \"mask\",\n \"pattern\",\n \"lineargradient\",\n \"radialgradient\",\n \"stop\",\n \"filter\",\n]);\n\n/** Shape of a tag name: a letter, then letters, digits or dashes. Anything else is refused. */\nconst TAG_PATTERN = /^[a-z][a-z0-9-]*$/i;\n\n/** Tags refused in any letter case: a script would bypass CSP nonces and Trusted Types. */\nconst DENIED_TAGS: ReadonlySet<string> = new Set([\"script\"]);\n\n/**\n * Creates an element for a validated tag name and applies the props to it, children included.\n * The namespace comes from the tag: SVG-only names get the SVG namespace, the rest are HTML.\n * On the server it renders the element as markup (with the hydration key and the children region\n * the client adopts); while hydrating it claims that element instead of creating one.\n */\nfunction buildElement(tag: string, props: object): unknown {\n const lower = tag.toLowerCase();\n if (!TAG_PATTERN.test(tag) || DENIED_TAGS.has(lower)) {\n throw new TypeError(__DEV__ ? \"ShadowJS Dynamic: invalid tag\" : \"SHADOW_DYNAMIC_TAG\");\n }\n if (__SERVER__) {\n // The children are read lazily, after `ssrElement` took the element's hydration key: the client\n // claims the element first and builds its children second, so the keys must be drawn in that\n // order here too, or a component inside the element and every sibling after it would miss.\n return ssrElement(\n tag,\n props,\n () => {\n const { children } = props as { children?: unknown };\n return children === undefined\n ? undefined\n : [ssrRaw(\"<!--[-->\"), children, ssrRaw(\"<!--]-->\")];\n },\n true,\n );\n }\n const svg = SVG_TAGS.has(lower);\n const claimed = claims.current.claimElement(nextKey());\n const el = claimed ?? (svg ? document.createElementNS(SVG_NS, tag) : document.createElement(tag));\n // Attributes through spread; children through insert, which adopts the server's children region.\n spread(el, props, svg, true);\n const region = createRegion(el, null, claims.current.takeRegion(el, null));\n bindRegion(region, () => (props as { children?: unknown }).children);\n return el;\n}\n\n/**\n * Renders one value of `component`: nothing for a falsy value, an element for a tag name, the\n * component's result for a function. Anything else is a TypeError.\n */\nfunction buildTarget(target: unknown, props: object): unknown {\n if (!target) return null;\n if (typeof target === \"string\") return buildElement(target, props);\n if (typeof target === \"function\") {\n return createComponent(target as (props: object) => unknown, props);\n }\n throw new TypeError(\n __DEV__\n ? \"ShadowJS Dynamic: component must be a string, a function, or a falsy value.\"\n : \"SHADOW_DYNAMIC_COMPONENT\",\n );\n}\n\n/**\n * Renders a component function or an element chosen by a tag name, and re-renders when\n * `component` changes. Only `component` is tracked: the rest of the props are passed through\n * reactive, so changing them updates the rendered output without rebuilding it. Swapping\n * `component` disposes the old subtree, cleanups included, and builds the new one once. A falsy\n * `component` renders nothing.\n *\n * Tag names are checked against `^[a-z][a-z0-9-]*$` (case-insensitive) and `script` is refused, so\n * data-driven tags cannot inject markup. SVG-only names (`circle`, `path`, `svg`, ...) are created\n * in the SVG namespace.\n *\n * @param props `component` and the props of what it renders.\n * @returns An accessor of the rendered output, to be inserted by the caller.\n * @throws TypeError for an invalid tag name or a component that is neither a string nor a function\n * (at read time, which is when the caller inserts it).\n * @example\n * import { createRoot, useSignal } from \"@shadow-js/core\";\n * import { Dynamic, insert } from \"@shadow-js/web\";\n *\n * const parent = document.createElement(\"div\");\n * createRoot(() => {\n * const [level] = useSignal(1);\n * insert(\n * parent,\n * Dynamic({\n * get component() {\n * return level() === 1 ? \"h1\" : \"h2\";\n * },\n * children: \"Title\",\n * }),\n * );\n * });\n * @see createDynamic\n * @since 1.0.0\n */\nexport function Dynamic<C extends DynamicTarget>(props: DynamicProps<C>): () => unknown {\n const [, rest] = splitProps(props, [\"component\"]);\n // The component is built inside this memo, so its setup (or a ref, or a directive) may write signals.\n return useMemo(\n (): unknown => {\n const target: unknown = props.component;\n return untrack(() => buildTarget(target, rest));\n },\n { allowWrites: true },\n );\n}\n\n/**\n * Function form of {@link Dynamic}, for code that is not JSX: renders what `component()` returns (a\n * component, a tag name or a falsy value) with `props`, and follows it when it changes.\n *\n * @param component Accessor of the target.\n * @param props The props of what it renders (reactive getters stay reactive).\n * @returns An accessor of the rendered output.\n * @example\n * import { createRoot, useSignal } from \"@shadow-js/core\";\n * import { createDynamic, insert } from \"@shadow-js/web\";\n *\n * const parent = document.createElement(\"div\");\n * createRoot(() => {\n * const [level] = useSignal(1);\n * insert(parent, createDynamic(() => (level() === 1 ? \"h1\" : \"h2\"), { children: \"Title\" }));\n * });\n * @see Dynamic\n * @since 1.0.0\n */\nexport function createDynamic<C extends DynamicTarget>(\n component: () => C,\n props: object = {},\n): () => unknown {\n return Dynamic(\n mergeProps(\n {\n get component(): C {\n return component();\n },\n },\n props,\n ) as DynamicProps<C>,\n );\n}\n"],"mappings":"A,uMA4DA,MAAMA,EAAc,qBAGdC,kBAAmC,IAAI,IAAI,CAAC,QAAQ,CAAC,EAQ3D,SAASC,EAAa,EAAa,EAAwB,CACzD,IAAMC,EAAQC,EAAI,YAAY,EAC9B,GAAI,CAACJ,EAAY,KAAKI,CAAG,GAAKH,EAAY,IAAIE,CAAK,EACjD,MAAU,UAAsD,oBAAoB,EAMpF,OAAOE,EACLD,EACAE,MACM,CACJ,GAAM,CAAE,YAAaA,EACrB,OAAOC,IAAa,IAAA,GAChB,IAAA,GACA,CAACC,EAAO,UAAU,EAAGD,EAAUC,EAAO,UAAU,CAAC,CACvD,EACA,EACF,CAUJ,CAMA,SAASC,EAAY,EAAiB,EAAwB,CAC5D,GAAI,CAACC,EAAQ,OAAO,KACpB,GAAI,OAAOA,GAAW,SAAU,OAAOR,EAAaQ,EAAQJ,CAAK,EACjE,GAAI,OAAOI,GAAW,WACpB,OAAOC,EAAgBD,EAAsCJ,CAAK,EAEpE,MAAU,UAGJ,0BACN,CACF,CAqCA,SAAgBM,EAAiC,EAAuC,CACtF,GAAM,EAAGC,GAAQC,EAAWR,EAAO,CAAC,WAAW,CAAC,EAEhD,OAAOS,MACU,CACb,IAAML,EAAkBJ,EAAM,UAC9B,OAAOU,MAAcP,EAAYC,EAAQG,CAAI,CAAC,CAChD,EACA,CAAE,YAAa,EAAK,CACtB,CACF,CAqBA,SAAgBI,EACd,EACA,EAAgB,CAAC,EACF,CACf,OAAOL,EACLM,EACE,CACE,IAAI,WAAe,CACjB,OAAOC,EAAU,CACnB,CACF,EACAb,CACF,CACF,CACF,C"}
@@ -0,0 +1,2 @@
1
+ import{currentScope as e,withScope as t}from"../internal/hydration-scope.js";import{rootErrorsOf as n}from"./root-errors.js";import{catchError as r,createRoot as i,getOwner as a,onCleanup as o,untrack as s,useMemo as c,useSignal as l}from"@shadow-js/core";import{createSignalNode as u,handleError as d,readSignal as f,writeSignal as p}from"@shadow-js/core/extend";function m(m){let h=u(void 0,Object.is),g=a(),_=n(g),v=e(),y=v===null?null:{id:v.id,count:v.count,resources:v.resources},b=()=>f(h),x=e=>{p(h,e,{allowInMemo:!0})},[S,C]=l(0,{equals:!1}),w=!0,T=!1,E,D=()=>{w&&(x(void 0),C(e=>e+1))},O=e=>{w&&(_?.onCaughtError?.(e),T?E===void 0&&(E={error:e}):x({error:e}))},k=()=>{let e=E;return E=void 0,e},A=e=>{let t=m.fallback;if(typeof t!=`function`)return t;try{return s(()=>t(e,D))}catch(e){d(e,g);return}},j=()=>{T=!0;try{S();let e=b()??k();if(e!==void 0)return A(e.error);let t=i(e=>({dispose:e,value:r(()=>s(()=>m.children),O)})),n=k();return n===void 0?t.value:(t.dispose(),A(n.error))}finally{i(()=>{o(()=>{T=!0})}),T=!1}},M=c(()=>y===null?j():t({...y},j),{allowWrites:!0});return i(()=>{o(()=>{w=!1})}),M}export{m as ErrorBoundary};
2
+ //# sourceMappingURL=error-boundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-boundary.js","names":["ErrorBoundary","failureCell","createSignalNode","parentOwner","getOwner","roots","rootErrorsOf","live","currentScope","origin","failure","readSignal","setFailure","writeSignal","next","version","setVersion","useSignal","alive","busy","pending","reset","count","report","error","takePending","captured","fallbackFor","fallback","props","untrack","thrown","handleError","build","current","scope","createRoot","catchError","creation","onCleanup","body","useMemo","withScope"],"sources":["../../../src/control-flow/error-boundary.ts"],"sourcesContent":["import {\n type Accessor,\n catchError,\n createRoot,\n getOwner,\n onCleanup,\n untrack,\n useMemo,\n useSignal,\n} from \"@shadow-js/core\";\nimport { createSignalNode, handleError, readSignal, writeSignal } from \"@shadow-js/core/extend\";\nimport { currentScope, type HydrationScope, withScope } from \"../extend\";\nimport type { JsxChild } from \"../jsx/types\";\nimport { attachHotModules, createHotLink, type HotLink } from \"./hot-link\";\nimport { rootErrorsOf } from \"./root-errors\";\n\n/**\n * Props of {@link ErrorBoundary}.\n * @since 1.0.0\n */\nexport interface ErrorBoundaryProps {\n /**\n * Shown after an error. A function is called untracked as `(error, reset)`; any other value is\n * shown as is.\n */\n readonly fallback: JsxChild | ((error: unknown, reset: () => void) => unknown);\n /**\n * The protected content, read untracked when the children are built.\n * @default undefined (nothing is protected; the boundary renders nothing)\n */\n readonly children?: JsxChild | (() => unknown);\n}\n\n/**\n * {@link ErrorBoundaryProps} with untyped members, for code that forwards a fallback or children it\n * does not know the shape of.\n * @since 1.0.0\n */\nexport interface ErrorBoundaryLooseProps {\n /** Shown after an error; the same contract as {@link ErrorBoundaryProps.fallback}. */\n readonly fallback: unknown;\n /**\n * The protected content; the same contract as {@link ErrorBoundaryProps.children}.\n * @default undefined (nothing is protected; the boundary renders nothing)\n */\n readonly children?: unknown;\n}\n\n/** A caught error, wrapped so that any thrown value (including `undefined`) is representable. */\ninterface Failure {\n readonly error: unknown;\n}\n\n/**\n * Renders `children`. If they throw while being created, or any effect, memo or cleanup inside\n * them throws later, the children are disposed and `fallback` is rendered instead. A function\n * fallback receives the error and a `reset` that rebuilds the children from scratch.\n *\n * Errors raised while the boundary is building or tearing down its children are captured and\n * never write a signal, because writing inside a memo is an error. Late errors write the failure\n * signal, which re-runs the boundary. After the boundary is disposed, late errors are dropped.\n * Errors thrown by the fallback are not caught by this boundary; they reach the parent.\n *\n * @param props See {@link ErrorBoundaryProps}.\n * @returns An accessor of the current content (children or fallback).\n * @throws Nothing itself. An error from the children is shown through `fallback`, and an error\n * thrown by a function `fallback` goes to the enclosing boundary or the root's error handler.\n * @example\n * import { ErrorBoundary } from \"@shadow-js/web\";\n *\n * function Dashboard() {\n * return <p>Dashboard</p>;\n * }\n *\n * function Page() {\n * return (\n * <ErrorBoundary\n * fallback={(error, reset) => (\n * <button onClick={reset}>Retry after: {String(error)}</button>\n * )}\n * >\n * <Dashboard />\n * </ErrorBoundary>\n * );\n * }\n * @see Suspense\n * @since 1.0.0\n */\nexport function ErrorBoundary(props: ErrorBoundaryProps): Accessor<unknown>;\nexport function ErrorBoundary(props: ErrorBoundaryLooseProps): Accessor<unknown>;\nexport function ErrorBoundary(props: ErrorBoundaryLooseProps): Accessor<unknown> {\n // An extension-API cell: a failure is boundary state, written from places a plain write refuses\n // (a sibling boundary's fallback throwing while its memo computes).\n const failureCell = createSignalNode<Failure | undefined>(undefined, Object.is);\n /** Where an error of this boundary's own fallback goes: the boundary that encloses it. */\n const parentOwner = getOwner();\n // The root's reporters (render/hydrate options): an error this boundary takes is reported to them.\n const roots = rootErrorsOf(parentOwner);\n /** The hydration scope at creation (a copy of its counts), or null outside a hydration or server render. */\n const live = currentScope();\n const origin: HydrationScope | null =\n live === null ? null : { id: live.id, count: live.count, resources: live.resources };\n const failure = (): Failure | undefined => readSignal(failureCell);\n const setFailure = (next: Failure | undefined): void => {\n writeSignal(failureCell, next, { allowInMemo: true });\n };\n /** Bumped by reset(): forces a rebuild even when no failure was recorded. */\n const [version, setVersion] = useSignal(0, { equals: false });\n /** False once the boundary's owner is disposed. */\n let alive = true;\n /** True while the body memo is building or tearing down children; errors are captured then. */\n let busy = false;\n /** An error captured while busy, consumed by the next body computation. */\n let pending: Failure | undefined;\n\n const reset = (): void => {\n if (!alive) return;\n setFailure(undefined);\n setVersion((count) => count + 1);\n };\n\n /**\n * Dev only: the modules the children were built from. While the fallback is shown, a hot update of one of\n * them resets the boundary, so the edit that fixes the error shows the children without a retry.\n */\n const hot: HotLink | undefined = __DEV__\n ? createHotLink(() => {\n reset();\n })\n : undefined;\n\n const report = (error: unknown): void => {\n if (!alive) return;\n roots?.onCaughtError?.(error);\n if (busy) {\n if (pending === undefined) pending = { error };\n return;\n }\n setFailure({ error });\n };\n\n /** Returns the captured error and clears it. A function, so TypeScript does not narrow the variable. */\n const takePending = (): Failure | undefined => {\n const captured = pending;\n pending = undefined;\n return captured;\n };\n\n const fallbackFor = (error: unknown): unknown => {\n const fallback = props.fallback;\n if (typeof fallback !== \"function\") return fallback;\n try {\n return untrack(() =>\n (fallback as (error: unknown, reset: () => void) => unknown)(error, reset),\n );\n } catch (thrown) {\n // A failing fallback is not this boundary's business: hand it to the enclosing boundary now.\n // Left to the memo it would only surface when a consumer outside that boundary reads it.\n handleError(thrown, parentOwner);\n return undefined;\n }\n };\n\n /** Builds the children or the fallback, as the current failure state says. */\n const build = (): unknown => {\n busy = true;\n try {\n version();\n const current = failure() ?? takePending();\n if (current !== undefined) {\n hot?.arm();\n return fallbackFor(current.error);\n }\n\n hot?.modules.clear();\n const scope = createRoot((dispose) => {\n if (hot !== undefined) attachHotModules(hot.modules);\n return {\n dispose,\n value: catchError(() => untrack(() => props.children), report),\n };\n });\n const creation = takePending();\n if (creation !== undefined) {\n scope.dispose();\n hot?.arm();\n return fallbackFor(creation.error);\n }\n hot?.disarm();\n return scope.value;\n } finally {\n // Newest child of the body memo: its cleanup marks the teardown before any child cleanup runs.\n createRoot(() => {\n onCleanup(() => {\n busy = true;\n });\n });\n busy = false;\n }\n // Children and the fallback are built here; their setup may write signals.\n };\n // Every build starts from the hydration scope the boundary was created in (a copy, so the count\n // is the same each time). A rebuild during a hydration pass then numbers its templates as the\n // first build did, so it claims the server's elements instead of missing keys.\n const body = useMemo<unknown>(\n () => (origin === null ? build() : withScope({ ...origin }, build)),\n { allowWrites: true },\n );\n\n // Created after the body memo, so it is the newest child of the owner and is disposed first.\n createRoot(() => {\n onCleanup(() => {\n alive = false;\n hot?.disarm();\n });\n });\n return body;\n}\n"],"mappings":"A,4WA0FA,SAAgBA,EAAc,EA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OANIa,IAAa,IAAA,GAMVH,EAAM,OALXA,EAAM,QAAQ,EAEPR,EAAYW,EAAS,KAAK,EAIrC,QAAU,CAERF,MAAiB,CACfG,MAAgB,CACd,EAAO,EACT,CAAC,CACH,CAAC,EACD,EAAO,EACT,CAEF,EAIMC,EAAOC,MACJhC,IAAW,KAAOwB,EAAM,EAAIS,EAAU,CAAE,GAAGjC,CAAO,EAAGwB,CAAK,EACjE,CAAE,YAAa,EAAK,CACtB,EASA,OANAG,MAAiB,CACfG,MAAgB,CACd,EAAQ,EAEV,CAAC,CACH,CAAC,EACMC,CACT,C"}
@@ -0,0 +1,2 @@
1
+ import{mapArray as e,untrack as t}from"@shadow-js/core";function n(e,n,r){return t(()=>e.children)(n,r)}function r(t){let r=()=>t.each,i=()=>t.fallback,a=t.key;return a===void 0?e(r,(e,r)=>n(t,e,r),{fallback:i}):e(r,(e,r)=>n(t,e,r),{key:a,fallback:i})}export{r as For};
2
+ //# sourceMappingURL=for.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"for.js","names":["renderRow","untrack","props","item","index","For","list","fallback","keyOf","mapArray"],"sources":["../../../src/control-flow/for.ts"],"sourcesContent":["import { type Accessor, mapArray, untrack } from \"@shadow-js/core\";\n\n/**\n * Props of {@link For} without `key`: rows are matched by item reference.\n * @since 1.0.0\n */\nexport interface ForUnkeyedProps<T> {\n /**\n * The list to render. `null`, `undefined` and `false` count as an empty list. Read lazily, inside\n * the list memo, so it is tracked.\n */\n readonly each: readonly T[] | null | undefined | false;\n /**\n * Shown while the list is empty. Read lazily.\n * @default undefined (an empty list renders nothing)\n */\n readonly fallback?: unknown;\n /**\n * Absent in this form: rows are matched by item reference. Pass `key` to match by key.\n * No default: omit it for reference matching.\n */\n readonly key?: undefined;\n /** Called once per row, untracked. The callback receives the item value. */\n readonly children: (item: T, index: () => number) => unknown;\n}\n\n/**\n * Props of {@link For} with `key`: rows are matched by `key(item)`.\n * @since 1.0.0\n */\nexport interface ForKeyedProps<T> {\n /**\n * The list to render. `null`, `undefined` and `false` count as an empty list. Read lazily, inside\n * the list memo, so it is tracked.\n */\n readonly each: readonly T[] | null | undefined | false;\n /**\n * Shown while the list is empty. Read lazily.\n * @default undefined (an empty list renders nothing)\n */\n readonly fallback?: unknown;\n /** Identifies each item. A new object under the same key updates the row's `item()`. */\n readonly key: (item: T) => unknown;\n /** Called once per row, untracked. The callback receives an accessor of the item. */\n readonly children: (item: () => T, index: () => number) => unknown;\n}\n\n/**\n * Props of {@link For}.\n * @since 1.0.0\n */\nexport type ForProps<T> = ForUnkeyedProps<T> | ForKeyedProps<T>;\n\n/**\n * Calls the row callback. `props.children` is read untracked, once per row.\n * @internal\n */\nfunction renderRow(props: { readonly children: unknown }, item: unknown, index: () => number) {\n const render = untrack(() => props.children) as (item: unknown, index: () => number) => unknown;\n return render(item, index);\n}\n\n/**\n * Renders one row per item. Rows whose key survives an update keep their DOM and state; only\n * changed items create or dispose rows. The list is read lazily, inside the list memo.\n *\n * Whether rows are keyed is decided when `For` is created: it reads `key` once. When the list\n * is empty and `fallback` is not given, the result is `[undefined]`, which renders nothing.\n *\n * @param props See {@link ForUnkeyedProps} and {@link ForKeyedProps}.\n * @returns An accessor of the row values, in input order.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { For } from \"@shadow-js/web\";\n *\n * function TodoList() {\n * const [todos] = useSignal([{ id: 1, title: \"Write docs\" }]);\n * return (\n * <ul>\n * <For each={todos()} key={(todo) => todo.id} fallback={<li>Nothing to do</li>}>\n * {(todo) => <li>{todo().title}</li>}\n * </For>\n * </ul>\n * );\n * }\n * @see Index\n * @since 1.0.0\n */\nexport function For<T>(props: ForKeyedProps<T>): Accessor<unknown[]>;\nexport function For<T>(props: ForUnkeyedProps<T>): Accessor<unknown[]>;\nexport function For<T>(props: ForProps<T>): Accessor<unknown[]> {\n const list = (): readonly T[] | null | undefined | false => props.each;\n const fallback = (): unknown => props.fallback;\n const keyOf = props.key;\n if (keyOf === undefined) {\n return mapArray(list, (item: T, index: () => number) => renderRow(props, item, index), {\n fallback,\n });\n }\n return mapArray(list, (item: () => T, index: () => number) => renderRow(props, item, index), {\n key: keyOf,\n fallback,\n });\n}\n"],"mappings":"A,wDAyDA,SAASA,EAAU,EAAuC,EAAe,EAAqB,CAE5F,OADeC,MAAcC,EAAM,QACvB,CAAC,CAACC,EAAMC,CAAK,CAC3B,CA8BA,SAAgBC,EAAO,EAAyC,CAC9D,IAAMC,MAAsDJ,EAAM,KAC5DK,MAA0BL,EAAM,SAChCM,EAAQN,EAAM,IAMpB,OALIM,IAAU,IAAA,GACLC,EAASH,GAAO,EAAS,IAAwBN,EAAUE,EAAOC,EAAMC,CAAK,EAAG,CACrF,UACF,CAAC,EAEIK,EAASH,GAAO,EAAe,IAAwBN,EAAUE,EAAOC,EAAMC,CAAK,EAAG,CAC3F,IAAKI,EACL,UACF,CAAC,CACH,C"}
@@ -0,0 +1,2 @@
1
+ function e(e){return e.children}export{e as Fragment};
2
+ //# sourceMappingURL=fragment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fragment.js","names":["Fragment","props"],"sources":["../../../src/control-flow/fragment.ts"],"sourcesContent":["/**\n * Props of {@link Fragment}.\n * @since 1.0.0\n */\nexport interface FragmentProps {\n /**\n * The children to group.\n * @default undefined (the Fragment renders nothing)\n */\n readonly children?: unknown;\n}\n\n/**\n * A no-op wrapper: returns `props.children` untouched, so the children are created by the caller's\n * getter exactly as if no wrapper existed. Use it to group several children under one element.\n *\n * @param props The children to group.\n * @returns `props.children`, unchanged.\n * @example\n * import { Fragment } from \"@shadow-js/web\";\n *\n * function Header() {\n * return <h1>Title</h1>;\n * }\n *\n * function Page() {\n * return (\n * <Fragment>\n * <Header />\n * <p>Body</p>\n * </Fragment>\n * );\n * }\n * @since 1.0.0\n */\nexport function Fragment(props: FragmentProps): unknown {\n return props.children;\n}\n"],"mappings":"AAmCA,SAAgBA,EAAS,EAA+B,CACtD,OAAOC,EAAM,QACf,C"}
@@ -0,0 +1,2 @@
1
+ import{indexArray as e,untrack as t}from"@shadow-js/core";function n(n){return e(()=>n.each,(e,r)=>t(()=>n.children)(e,r),{fallback:()=>n.fallback})}export{n as Index};
2
+ //# sourceMappingURL=index-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-list.js","names":["Index","indexArray","props","untrack","item","index"],"sources":["../../../src/control-flow/index-list.ts"],"sourcesContent":["import { type Accessor, indexArray, untrack } from \"@shadow-js/core\";\n\n/**\n * Props of {@link Index}.\n * @since 1.0.0\n */\nexport interface IndexProps<T> {\n /**\n * The list to render. `null`, `undefined` and `false` count as an empty list. Read lazily, so it\n * is tracked.\n */\n readonly each: readonly T[] | null | undefined | false;\n /**\n * Shown while the list is empty. Read lazily.\n * @default undefined (an empty list renders nothing)\n */\n readonly fallback?: unknown;\n /**\n * Called once per position, untracked. The item is an accessor that follows the value at this\n * position; the index is a plain number, because a position never changes.\n */\n readonly children: (item: () => T, index: number) => unknown;\n}\n\n/**\n * Renders one row per position. Rows are created and removed only when the length changes; the\n * row at position `i` stays, and its item accessor follows the value at `i`. Use it for\n * primitive lists where identity does not matter.\n *\n * @param props See {@link IndexProps}.\n * @returns An accessor of the row values, in input order.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { Index } from \"@shadow-js/web\";\n *\n * function Cells() {\n * const [values] = useSignal([10, 20, 30]);\n * return (\n * <ul>\n * <Index each={values()}>{(value, index) => <li>{`${index}: ${value()}`}</li>}</Index>\n * </ul>\n * );\n * }\n * @see For\n * @since 1.0.0\n */\nexport function Index<T>(props: IndexProps<T>): Accessor<unknown[]> {\n return indexArray(\n () => props.each,\n (item: () => T, index: number) => untrack(() => props.children)(item, index),\n { fallback: () => props.fallback },\n );\n}\n"],"mappings":"A,0DA8CA,SAAgBA,EAAS,EAA2C,CAClE,OAAOC,MACCC,EAAM,MACX,EAAe,IAAkBC,MAAcD,EAAM,QAAQ,CAAC,CAACE,EAAMC,CAAK,EAC3E,CAAE,aAAgBH,EAAM,QAAS,CACnC,CACF,C"}
@@ -0,0 +1,2 @@
1
+ import{untrack as e,useMemo as t,useResource as n}from"@shadow-js/core";function r(r){let i,a,o=()=>(i===void 0&&(i=r().then(e=>(a=e.default,e.default),e=>{throw i=void 0,e})),i),s=(r=>{if(a!==void 0){let n=a;return t(()=>e(()=>n(r)),{allowWrites:!0})}let i=n(()=>o());return t(()=>{let t=i();return t===void 0?void 0:e(()=>t(r))},{allowWrites:!0})});return s.preload=o,s}export{r as lazy};
2
+ //# sourceMappingURL=lazy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy.js","names":["lazy","pending","loaded","load","loader","module","error","Lazy","component","useMemo","untrack","props","resource","useResource"],"sources":["../../../src/control-flow/lazy.ts"],"sourcesContent":["import { type Accessor, untrack, useMemo, useResource } from \"@shadow-js/core\";\n\ntype ComponentFunction<P> = (props: P) => unknown;\n\n/**\n * A component made by {@link lazy}: call it (or write it in JSX) like any component, and use\n * `preload` to start the load early.\n * @since 1.0.0\n */\nexport interface LazyComponent<P> {\n /**\n * Renders the loaded component with `props`. While the code is loading the result is empty and the\n * nearest `<Suspense>` shows its fallback; without a boundary nothing is rendered until the load\n * resolves.\n */\n (props: P): Accessor<unknown>;\n /**\n * Starts loading without rendering and resolves to the component. Calls share one load, so the\n * loader runs once. A failed load is not cached: the next call or render loads again.\n */\n preload(): Promise<ComponentFunction<P>>;\n}\n\n/**\n * Defines a component whose code is loaded on first render. While loading, the nearest\n * `<Suspense>` shows its fallback; a failed load throws to the nearest `<ErrorBoundary>` and the\n * next render retries.\n *\n * @param loader Returns a promise of a module whose `default` export is the component, such as\n * `() => import(\"./chart\")`. Called at most once while its load succeeds.\n * @returns A {@link LazyComponent}.\n * @throws Nothing synchronously. A rejected load surfaces as an error when the component's output\n * is read, so the nearest `<ErrorBoundary>` takes it; `preload()` rejects with the same error.\n * @example\n * import { lazy, Suspense } from \"@shadow-js/web\";\n *\n * function Chart(props: { title: string }) {\n * return <h2>{props.title}</h2>;\n * }\n *\n * // In an app the loader is `() => import(\"./chart\")`.\n * const LazyChart = lazy(() => Promise.resolve({ default: Chart }));\n *\n * function Page() {\n * return (\n * <Suspense fallback={<p>Loading...</p>}>\n * <LazyChart title=\"Sales\" />\n * </Suspense>\n * );\n * }\n * @see Suspense\n * @see ErrorBoundary\n * @since 1.0.0\n */\nexport function lazy<P>(\n loader: () => Promise<{ default: ComponentFunction<P> }>,\n): LazyComponent<P> {\n let pending: Promise<ComponentFunction<P>> | undefined;\n let loaded: ComponentFunction<P> | undefined;\n\n const load = (): Promise<ComponentFunction<P>> => {\n if (pending === undefined) {\n pending = loader().then(\n (module) => {\n loaded = module.default;\n return module.default;\n },\n (error: unknown) => {\n pending = undefined;\n throw error;\n },\n );\n }\n return pending;\n };\n\n const Lazy = ((props: P): Accessor<unknown> => {\n if (loaded !== undefined) {\n const component = loaded;\n return useMemo(() => untrack(() => component(props)), { allowWrites: true });\n }\n const resource = useResource(() => load());\n return useMemo(\n () => {\n const component = resource();\n return component === undefined ? undefined : untrack(() => component(props));\n },\n { allowWrites: true },\n );\n }) as LazyComponent<P>;\n Lazy.preload = load;\n return Lazy;\n}\n"],"mappings":"A,wEAsDA,SAAgBA,EACd,EACkB,CAClB,IAAIC,EACAC,EAEEC,OACAF,IAAY,IAAA,KACd,EAAUG,EAAO,CAAC,CAAC,KAChB,IACC,EAASC,EAAO,QACTA,EAAO,SAEf,GAAmB,CAElB,KADA,GAAU,IAAA,GACJC,CACR,CACF,GAEKL,GAGHM,GAAS,GAAgC,CAC7C,GAAIL,IAAW,IAAA,GAAW,CACxB,IAAMM,EAAYN,EAClB,OAAOO,MAAcC,MAAcF,EAAUG,CAAK,CAAC,EAAG,CAAE,YAAa,EAAK,CAAC,CAC7E,CACA,IAAMC,EAAWC,MAAkBV,EAAK,CAAC,EACzC,OAAOM,MACC,CACJ,IAAMD,EAAYI,EAAS,EAC3B,OAAOJ,IAAc,IAAA,GAAY,IAAA,GAAYE,MAAcF,EAAUG,CAAK,CAAC,CAC7E,EACA,CAAE,YAAa,EAAK,CACtB,CACF,GAEA,MADA,GAAK,QAAUR,EACRI,CACT,C"}
@@ -0,0 +1,2 @@
1
+ import{nextKey as e,withScope as t}from"../internal/hydration-scope.js";import{ssrRaw as n}from"../server/element.js";function r(r){let i=e();{let e=t(null,()=>r.children);return()=>[n(`<!--nh:${i??``}-->`),e,n(`<!--/nh-->`)]}}export{r as NoHydration};
2
+ //# sourceMappingURL=no-hydration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-hydration.js","names":["NoHydration","key","nextKey","built","withScope","props","ssrRaw"],"sources":["../../../src/control-flow/no-hydration.ts"],"sourcesContent":["import type { Accessor } from \"@shadow-js/core\";\nimport { claims, nextKey, withScope } from \"../extend\";\nimport { ssrRaw } from \"../server/element\";\n\n/** The nodes between `<!--nh:KEY-->` and its `<!--/nh-->` in the lifted regions, or undefined when the server sent none. */\nfunction findStatic(\n key: string | undefined,\n regions: readonly (readonly Node[])[] | undefined,\n): Node[] | undefined {\n if (key === undefined || regions === undefined) return undefined;\n for (const region of regions) {\n const open = region.findIndex(\n (node) => node.nodeType === 8 && (node as Comment).data === `nh:${key}`,\n );\n if (open === -1) continue;\n const nodes: Node[] = [];\n let depth = 1;\n for (let i = open + 1; i < region.length; i += 1) {\n const node = region[i] as Node;\n if (node.nodeType === 8) {\n const data = (node as Comment).data;\n if (data.startsWith(\"nh:\")) depth += 1;\n else if (data === \"/nh\" && --depth === 0) break;\n }\n nodes.push(node);\n }\n return nodes;\n }\n return undefined;\n}\n\n/**\n * Props of {@link NoHydration}.\n * @since 1.0.0\n */\nexport interface NoHydrationProps {\n /**\n * The static content. Rendered by the server without hydration keys and left untouched by the\n * browser's hydration pass.\n * @default undefined (renders nothing)\n */\n readonly children?: unknown;\n}\n\n/**\n * Content the browser never hydrates: the server renders it without hydration keys, and while the\n * page hydrates the browser leaves that markup exactly as it is (no code runs for it, no event\n * handlers or reactivity are attached). Use it for static, heavy markup such as rendered\n * documentation or a long article. Rendered by the browser alone (a client-side navigation), its\n * children render normally.\n *\n * @param props See {@link NoHydrationProps}.\n * @returns An accessor of the content: the children, or the server's own nodes while the browser hydrates.\n * @example\n * import { NoHydration } from \"@shadow-js/web\";\n *\n * function Docs(props: { html: string }) {\n * return (\n * <NoHydration>\n * <article innerHTML={props.html} />\n * </NoHydration>\n * );\n * }\n * @see ClientOnly\n * @since 1.0.0\n */\nexport function NoHydration(props: NoHydrationProps): Accessor<unknown> {\n // The component has its own scope, so this key does not move the keys of its siblings.\n const key = nextKey();\n if (__SERVER__) {\n // No scope for the content: the keys of what is rendered inside are not handed out.\n const built = withScope(null, () => props.children);\n return () => [ssrRaw(`<!--nh:${key ?? \"\"}-->`), built, ssrRaw(\"<!--/nh-->\")];\n }\n if (claims.current.isClaiming()) {\n // Hydrating: the server's nodes between the markers are handed to the region as they are.\n const kept = findStatic(key, claims.current.liftedRegions());\n if (kept !== undefined) return () => kept;\n // No markers from the server (the root of the container): render on the client, claiming nothing.\n return () => claims.current.withoutClaiming(() => props.children);\n }\n return () => props.children;\n}\n"],"mappings":"A,sHAkEA,SAAgBA,EAAY,EAA4C,CAEtE,IAAMC,EAAMC,EAAQ,EACJ,CAEd,IAAMC,EAAQC,EAAU,SAAYC,EAAM,QAAQ,EAClD,UAAa,CAACC,EAAO,UAAUL,GAAO,GAAG,IAAI,EAAGE,EAAOG,EAAO,YAAY,CAAC,CAC7E,CASF,C"}
@@ -0,0 +1,2 @@
1
+ import{childScope as e,nextKey as t,withScope as n}from"../internal/hydration-scope.js";import{claims as r}from"../internal/hydration-hooks.js";import{bindRegion as i,createRegion as a,removeRegion as o}from"../insert.js";import{PortalContext as s}from"../internal/portal-context.js";import{renderServerPortal as c}from"../server/portals.js";import{createRoot as l,isServer as u,onCleanup as d,useContext as f,useRenderEffect as p}from"@shadow-js/core";function m(e,t){typeof e.moveBefore==`function`?e.moveBefore(t,null):e.appendChild(t)}function h(e){return e.shadowRoot??e.attachShadow({mode:`open`})}function g(e){return e===void 0?document.body:(typeof e==`function`?e():e)??null}function _(_){let v=t(),y=f(s);if(u||y!==null)return _.useShadow!==!0&&c(v,()=>_.children,y),null;let b,x=r.current.claimPortal(v),S=()=>{let e=b;e!==void 0&&(b=void 0,e.stopEffects(),o(e.region))},C=(t,o,s)=>{let c=a(t,null,o);return{host:t,region:c,stopEffects:l(t=>{let a=()=>{i(c,()=>_.children)};return s===`plain`?a():s===`claimed`?n(e(v),a):r.current.withoutClaiming(()=>n(e(v),a)),t})}},w=e=>{let t=b;if(t===void 0){let t=x??[],n=`plain`;x===void 0?v!==void 0&&r.current.isClaiming()&&(n=`unclaimed`):n=`claimed`,x=void 0;for(let n of t)n.parentNode!==e&&m(e,n);b=C(e,t,n);return}let n=t.region.nodes.filter(e=>e.parentNode===t.host);t.stopEffects();for(let t of n)m(e,t);b=C(e,n,`plain`)};return p(()=>({host:g(_.mount),shadow:_.useShadow===!0}),({host:e,shadow:t})=>{if(e===null){S();return}let n=t?h(e):e;(b===void 0||b.host!==n)&&w(n)}),d(S),null}export{_ as Portal};
2
+ //# sourceMappingURL=portal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal.js","names":["appendMoved","target","node","shadowRootOf","host","resolveMount","mount","Portal","key","nextKey","sink","useContext","PortalContext","isServer","props","renderServerPortal","mounted","adopted","claims","unmount","current","removeRegion","mountInto","region","createRegion","initial","createRoot","bind","bindRegion","mode","withScope","childScope","dispose","moveTo","previous","nodes","useRenderEffect","shadow","onCleanup"],"sources":["../../../src/control-flow/portal.ts"],"sourcesContent":["import { createRoot, isServer, onCleanup, useContext, useRenderEffect } from \"@shadow-js/core\";\nimport {\n bindRegion,\n childScope,\n claims,\n createRegion,\n nextKey,\n PortalContext,\n type Region,\n removeRegion,\n withScope,\n} from \"../extend\";\nimport { renderServerPortal } from \"../server/portals\";\n\n/**\n * Props of {@link Portal}.\n * @since 1.0.0\n */\nexport interface PortalProps {\n /**\n * The element that receives the content, or a function returning it (read reactively). A null\n * target, or a function that returns null or undefined, renders nothing and warns once in\n * development (`PORTAL_TARGET_MISSING`).\n * @default document.body (when the prop is omitted)\n */\n readonly mount?: Element | null | (() => Element | null | undefined);\n /**\n * Put the content in a shadow root of the mount, created once and reused. A portal with a shadow\n * root is not server-rendered; the browser creates it.\n * @default false\n */\n readonly useShadow?: boolean;\n /**\n * Reserved for namespace handling. Nodes are inserted as they were created, so the flag does not\n * change the output yet.\n * @default false\n */\n readonly isSVG?: boolean;\n /**\n * The content: a node, text, an array, or an accessor returning them.\n * @default undefined (nothing is rendered)\n */\n readonly children?: unknown;\n}\n\n/** What the portal holds while content is mounted: where it is, its region, and its effects. */\ninterface Mounted {\n readonly host: Node;\n readonly region: Region;\n /** Stops the content's effects. The nodes stay where they are. */\n readonly stopEffects: () => void;\n}\n\n/**\n * How the content of a mount is built. `claimed`: the server markup is adopted (the templates claim\n * it). `unclaimed`: hydrating, but the server sent nothing for this portal, so it is built fresh.\n */\ntype MountMode = \"plain\" | \"claimed\" | \"unclaimed\";\n\n/** A node that can be moved in place (`Element.prototype.moveBefore`, where implemented). */\ninterface MovableNode extends Node {\n moveBefore(node: Node, child: Node | null): void;\n}\n\n/** Appends `node` to `target`, moving it in place when the target supports `moveBefore`. */\nfunction appendMoved(target: Node, node: Node): void {\n if (typeof (target as Partial<MovableNode>).moveBefore === \"function\") {\n (target as MovableNode).moveBefore(node, null);\n } else {\n target.appendChild(node);\n }\n}\n\n/** The shadow root of an element, attached once when the element has none. */\nfunction shadowRootOf(host: Element): ShadowRoot {\n return host.shadowRoot ?? host.attachShadow({ mode: \"open\" });\n}\n\n/** The mount target of a `mount` prop: the default body, the element, or the function's result. */\nfunction resolveMount(mount: PortalProps[\"mount\"]): Element | null {\n if (mount === undefined) return document.body;\n const value = typeof mount === \"function\" ? mount() : mount;\n return value ?? null;\n}\n\n/**\n * Renders `children` into another part of the document, without a wrapper: the content nodes are\n * inserted directly into the mount element (or its shadow root). Nothing is left at the call site.\n * Disposing the owner removes exactly the nodes the portal inserted; nodes that were already in the\n * mount stay. A reactive `mount` moves the content, and static nodes keep their identity while they\n * move.\n *\n * On the server the content is rendered into the render's `portals` collector (see\n * `createServerPortals`), and the document emits it at the end of `<body>`. When the browser hydrates\n * the portal it adopts that markup instead of creating it again, moving it into the mount if the mount\n * is not `body`. A portal with `useShadow` is not server-rendered; the browser creates it.\n *\n * Events follow the DOM tree. Delegated handlers inside the content fire when the mount is in the\n * document, because the document listener sees the event bubble past the mount. Handlers on\n * elements that wrap the call site do not fire.\n *\n * @param props See {@link PortalProps}.\n * @returns Always null: the portal renders nothing in place.\n * @example\n * import { Portal } from \"@shadow-js/web\";\n *\n * function Modal() {\n * return <div role=\"dialog\">Hello</div>;\n * }\n *\n * function App() {\n * return (\n * <Portal mount={document.getElementById(\"modal-root\")}>\n * <Modal />\n * </Portal>\n * );\n * }\n * @see Dynamic\n * @since 1.0.0\n */\nexport function Portal(props: PortalProps): null {\n // The key of this portal's server block, taken at the call site on the server and in the browser\n // alike. The content renders in a scope of its own (`childScope`), so the keys of the siblings do\n // not depend on whether the content rendered.\n const key = nextKey();\n // A server render provides the portal collector (`renderToString` and friends), so it is recognized\n // by the collector as well as by the build's `isServer` flag: the same server code runs in both.\n const sink = useContext(PortalContext);\n if (isServer || sink !== null) {\n if (props.useShadow !== true) renderServerPortal(key, () => props.children, sink);\n return null;\n }\n let mounted: Mounted | undefined;\n let warned = false;\n // The server block of this portal, taken out of the markers while hydrating; used by the first mount.\n let adopted: Node[] | undefined = claims.current.claimPortal(key);\n\n /** Stops the content's effects, then removes its nodes. Safe to call when nothing is mounted. */\n const unmount = (): void => {\n const current = mounted;\n if (current === undefined) return;\n mounted = undefined;\n current.stopEffects();\n removeRegion(current.region);\n };\n\n /** Creates the content region in `host`, adopting the nodes that are already there. */\n const mountInto = (host: Node, initial: Node[], mode: MountMode): Mounted => {\n const region = createRegion(host, null, initial);\n const stopEffects = createRoot((dispose) => {\n const bind = (): void => {\n bindRegion(region, () => props.children);\n };\n if (mode === \"plain\") bind();\n else if (mode === \"claimed\") withScope(childScope(key), bind);\n else claims.current.withoutClaiming(() => withScope(childScope(key), bind));\n return dispose;\n });\n return { host, region, stopEffects };\n };\n\n /** Moves the content to `target`. The nodes move first, then the children are bound again. */\n const moveTo = (target: Node): void => {\n const previous = mounted;\n if (previous === undefined) {\n const initial = adopted ?? [];\n let mode: MountMode = \"plain\";\n if (adopted !== undefined) mode = \"claimed\";\n else if (key !== undefined && claims.current.isClaiming()) mode = \"unclaimed\";\n adopted = undefined;\n for (const node of initial) {\n if (node.parentNode !== target) appendMoved(target, node);\n }\n mounted = mountInto(target, initial, mode);\n return;\n }\n const nodes = previous.region.nodes.filter((node) => node.parentNode === previous.host);\n previous.stopEffects();\n for (const node of nodes) appendMoved(target, node);\n mounted = mountInto(target, nodes, \"plain\");\n };\n\n useRenderEffect(\n () => {\n const host = resolveMount(props.mount);\n const shadow = props.useShadow === true;\n return { host, shadow };\n },\n ({ host, shadow }) => {\n if (host === null) {\n unmount();\n if (__DEV__ && !warned) {\n warned = true;\n console.warn(\n \"[shadow PORTAL_TARGET_MISSING] Portal has no mount element; nothing is rendered.\",\n );\n }\n return;\n }\n const target: Node = shadow ? shadowRootOf(host) : host;\n if (mounted !== undefined && mounted.host === target) return;\n moveTo(target);\n },\n );\n onCleanup(unmount);\n return null;\n}\n"],"mappings":"A,qcAiEA,SAASA,EAAY,EAAc,EAAkB,CAC/C,OAAQC,EAAgC,YAAe,WACzDA,EAAwB,WAAWC,EAAM,IAAI,EAE7CD,EAAO,YAAYC,CAAI,CAE3B,CAGA,SAASC,EAAa,EAA2B,CAC/C,OAAOC,EAAK,YAAcA,EAAK,aAAa,CAAE,KAAM,MAAO,CAAC,CAC9D,CAGA,SAASC,EAAa,EAA6C,CAGjE,OAFIC,IAAU,IAAA,GAAkB,SAAS,MAC3B,OAAOA,GAAU,WAAaA,EAAM,EAAIA,IACtC,IAClB,CAqCA,SAAgBC,EAAO,EAA0B,CAI/C,IAAMC,EAAMC,E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AAUrB,EAAQkC,EAAO,OAAO,CAC5C,EAyBA,OAvBAC,OAIW,CAAE,KAFI/B,EAAaS,EAAM,KAEpB,EAAG,OADAA,EAAM,YAAc,EACb,IAEvB,CAAE,OAAM,YAAa,CACpB,GAAIV,IAAS,KAAM,CACjBe,EAAQ,EAOR,MACF,CACA,IAAMlB,EAAeoC,EAASlC,EAAaC,CAAI,EAAIA,GAC/CY,IAAY,IAAA,IAAaA,EAAQ,OAASf,IAC9CgC,EAAOhC,CAAM,CACf,CACF,EACAqC,EAAUnB,CAAO,EACV,IACT,C"}
@@ -0,0 +1,2 @@
1
+ import{getOwner as e}from"@shadow-js/core";const t=/* @__PURE__ */ Symbol(`RootErrors`);function n(n){let r=e();if(r===null)return;let i=Object.create(r.context);i[t]=n,r.context=i,n.onUncaughtError!==void 0&&(r.errorHandlers=[n.onUncaughtError])}function r(e){return e?.context?.[t]}export{n as attachRootErrors,r as rootErrorsOf};
2
+ //# sourceMappingURL=root-errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root-errors.js","names":["ROOT_ERRORS","attachRootErrors","root","getOwner","map","options","rootErrorsOf","owner"],"sources":["../../../src/control-flow/root-errors.ts"],"sourcesContent":["import { getOwner, type Owner } from \"@shadow-js/core\";\n\n/**\n * The error reporters a root was rendered or hydrated with (see `RenderOptions` and `HydrateOptions`).\n * @since 1.0.0\n */\nexport interface RootErrorOptions {\n /**\n * Receives an error that no error boundary took. The root then does not rethrow it.\n * @default undefined (no reporter; an error no boundary takes follows the default handling)\n */\n readonly onUncaughtError?: (error: unknown) => void;\n /**\n * Receives an error an `ErrorBoundary` caught (its fallback is shown).\n * @default undefined (no reporter)\n */\n readonly onCaughtError?: (error: unknown) => void;\n /**\n * Receives a hydration mismatch that was repaired on the client. Only `hydrate` reports these.\n * @default undefined (no reporter)\n */\n readonly onRecoverableError?: (error: unknown) => void;\n}\n\n/**\n * The key the reporters are stored under in an owner's context map. A symbol the context map inherits\n * (as a Provider's value is inherited), so every node below the root sees it, detached roots included.\n * A plain value rather than a context: a context would bring its Provider into every bundle.\n */\nconst ROOT_ERRORS: symbol = /* @__PURE__ */ Symbol(\"RootErrors\");\n\n/**\n * Attaches the options to the root that is being created (called inside its `createRoot`). The reporters\n * go into the root's context map, and an `onUncaughtError` becomes the root's error handler (a fresh root\n * has none, so it is the only one).\n * @internal\n */\nexport function attachRootErrors(options: RootErrorOptions): void {\n const root = getOwner();\n if (root === null) return;\n const map = Object.create(root.context) as Record<symbol, unknown>;\n map[ROOT_ERRORS] = options;\n root.context = map;\n if (options.onUncaughtError !== undefined) root.errorHandlers = [options.onUncaughtError];\n}\n\n/**\n * The reporters of the nearest root above `owner`, or undefined when no root was given options.\n * @internal\n */\nexport function rootErrorsOf(owner: Owner | null): RootErrorOptions | undefined {\n return owner?.context?.[ROOT_ERRORS] as RootErrorOptions | undefined;\n}\n"],"mappings":"A,2CA6BA,MAAMA,EAAsC,uBAAO,YAAY,EAQ/D,SAAgBC,EAAiB,EAAiC,CAChE,IAAMC,EAAOC,EAAS,EACtB,GAAID,IAAS,KAAM,OACnB,IAAME,EAAM,OAAO,OAAOF,EAAK,OAAO,EACtC,EAAIF,GAAeK,EACnB,EAAK,QAAUD,EACXC,EAAQ,kBAAoB,IAAA,KAAW,EAAK,cAAgB,CAACA,EAAQ,eAAe,EAC1F,CAMA,SAAgBC,EAAa,EAAmD,CAC9E,OAAOC,GAAO,UAAUP,EAC1B,C"}
@@ -0,0 +1,2 @@
1
+ import{createBranches as e}from"./branch.js";function t(t){return e(`Show`,()=>{let e=t.when;return{index:e?0:-1,keyed:t.keyed===!0,when:e,read:()=>t.when,body:()=>t.children}},()=>t.fallback)}export{t as Show};
2
+ //# sourceMappingURL=show.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"show.js","names":["Show","createBranches","when","props"],"sources":["../../../src/control-flow/show.ts"],"sourcesContent":["import type { Accessor } from \"@shadow-js/core\";\nimport type { JsxChild } from \"../jsx/types\";\nimport { createBranches, FALLBACK } from \"./branch\";\n\n/** What `when` accepts: the value, or any falsy stand-in (`0` and `\"\"` count as falsy). */\ntype ShowCondition<T> = T | undefined | null | false | 0 | \"\";\n\n/** Props shared by both forms of {@link Show}. */\ninterface ShowBaseProps<T> {\n /** The condition. The children are shown while it is truthy. */\n readonly when: ShowCondition<T>;\n /**\n * Shown while `when` is falsy. Read lazily, only when it is needed.\n * @default undefined (a falsy `when` renders nothing)\n */\n readonly fallback?: unknown;\n}\n\n/**\n * Keyed form: the children are rebuilt whenever the identity of `when` changes and a callback\n * child receives the value itself.\n * @since 1.0.0\n */\nexport interface ShowKeyedProps<T> extends ShowBaseProps<T> {\n /** Must be `true` in this form: a change of the identity of `when` rebuilds the children. */\n readonly keyed: true;\n /**\n * Plain content, an accessor, or a callback `(item) => content` called untracked in the branch.\n * @default undefined (a truthy `when` renders nothing)\n */\n readonly children?: JsxChild | (() => unknown) | ((item: NonNullable<T>) => unknown);\n}\n\n/**\n * Default form: the branch is rebuilt only when the truthiness of `when` changes. A callback child\n * receives an accessor of the latest truthy value; reading it after `when` became falsy throws a\n * TypeError, except while the branch is being torn down.\n * @since 1.0.0\n */\nexport interface ShowAccessorProps<T> extends ShowBaseProps<T> {\n /**\n * Absent or `false` in this form: the children are rebuilt only when the truthiness of `when`\n * changes.\n * @default false\n */\n readonly keyed?: false;\n /**\n * Plain content, an accessor, or a callback `(item) => content` called untracked in the branch.\n * @default undefined (a truthy `when` renders nothing)\n */\n readonly children?: JsxChild | (() => unknown) | ((item: Accessor<NonNullable<T>>) => unknown);\n}\n\n/**\n * Props of {@link Show}.\n * @since 1.0.0\n */\nexport type ShowProps<T> = ShowKeyedProps<T> | ShowAccessorProps<T>;\n\n/**\n * The same props with untyped `children`, for code that forwards children it does not know the\n * shape of (a wrapper component's own `props.children`).\n * @since 1.0.0\n */\nexport interface ShowLooseProps<T> extends ShowBaseProps<T> {\n /**\n * Same meaning as in {@link ShowKeyedProps}: `true` rebuilds the children when the identity of\n * `when` changes.\n * @default false\n */\n readonly keyed?: boolean;\n /**\n * Plain content, an accessor, or a callback, as in {@link ShowProps}.\n * @default undefined (a truthy `when` renders nothing)\n */\n readonly children?: unknown;\n}\n\n/**\n * Shows `children` while `when` is truthy, and `fallback` otherwise. The branch is rebuilt only\n * when the truthiness of `when` changes (or, with `keyed`, when its identity changes).\n *\n * `when` follows JavaScript truthiness: `0`, `\"\"`, `null`, `undefined` and `false` show the\n * fallback. While `fallback` is not given, a falsy `when` renders nothing.\n *\n * @param props See {@link ShowProps}.\n * @returns An accessor of the current branch's content. The DOM runtime's `insert` consumes it.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { Show } from \"@shadow-js/web\";\n *\n * function Greeting() {\n * const [user] = useSignal<{ name: string } | null>(null);\n * return (\n * <Show when={user()} fallback={<p>Sign in</p>}>\n * {(u) => <p>Hello {u().name}</p>}\n * </Show>\n * );\n * }\n * @see Switch\n * @see ErrorBoundary\n * @since 1.0.0\n */\nexport function Show<T>(props: ShowProps<T>): Accessor<unknown>;\nexport function Show<T>(props: ShowLooseProps<T>): Accessor<unknown>;\nexport function Show<T>(props: ShowLooseProps<T>): Accessor<unknown> {\n return createBranches(\n \"Show\",\n () => {\n const when = props.when;\n return {\n index: when ? 0 : FALLBACK,\n keyed: props.keyed === true,\n when,\n read: () => props.when,\n body: () => props.children,\n };\n },\n () => props.fallback,\n );\n}\n"],"mappings":"A,6CAyGA,SAAgBA,EAAQ,EAA6C,CACnE,OAAOC,EACL,WACM,CACJ,IAAMC,EAAOC,EAAM,KACnB,MAAO,CACL,MAAOD,EAAO,EAAA,GACd,MAAOC,EAAM,QAAU,GACvB,OACA,SAAYA,EAAM,KAClB,SAAYA,EAAM,QACpB,CACF,MACMA,EAAM,QACd,CACF,C"}
@@ -0,0 +1,2 @@
1
+ import{createContext as e,onCleanup as t}from"@shadow-js/core";import{createSignalNode as n,readSignal as r,writeSignal as i}from"@shadow-js/core/extend";const a=/* @__PURE__ */ e(null,{name:`SuspenseList`});function o(e){let o=n(0,!1),s=[],c=()=>{i(o,0,{allowInMemo:!0})};return a({value:{register(n){let i={ready:n};s.push(i),c(),t(()=>{let e=s.indexOf(i);e!==-1&&s.splice(e,1),c()});let a=()=>(r(o),s.indexOf(i)),l=()=>{let t=a();if(t===-1)return!1;switch(e.revealOrder){case`together`:return s.every(e=>e.ready());case`forwards`:return s.slice(0,t+1).every(e=>e.ready());case`backwards`:return s.slice(t).every(e=>e.ready());default:return n()}};return{reveal:l,showFallback:()=>{if(l())return!1;let t=e.revealOrder;if(t!==`forwards`&&t!==`backwards`)return!0;if(e.tail===`hidden`)return!1;if(e.tail!==`collapsed`)return!0;let n=a(),r=t===`backwards`?[...s].reverse():s,i=t===`backwards`?s.length-1-n:n;for(let e=0;e<r.length;e+=1){let t=r[e];if(t!==void 0&&!t.ready())return e===i}return!1}}}},get children(){return e.children}})}export{o as SuspenseList,a as SuspenseListContext};
2
+ //# sourceMappingURL=suspense-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suspense-list.js","names":["SuspenseListContext","SuspenseList","changes","createSignalNode","slots","touch","writeSignal","entry","onCleanup","index","position","readSignal","reveal","props","slot","ready","order","ordered","wanted","i","candidate"],"sources":["../../../src/control-flow/suspense-list.ts"],"sourcesContent":["import { type Accessor, type Context, createContext, onCleanup, useContext } from \"@shadow-js/core\";\nimport { createSignalNode, readSignal, writeSignal } from \"@shadow-js/core/extend\";\n\n/** What a `<Suspense>` inside a list learns about its place: when to show content and a fallback. @internal */\nexport interface SuspenseListSlot {\n /** True when this boundary may show its content now (it is ready and the order allows it). */\n reveal(): boolean;\n /** True when this boundary should show its fallback while it waits. */\n showFallback(): boolean;\n}\n\n/** Provided by `<SuspenseList>` to the boundaries below it. @internal */\nexport interface SuspenseListState {\n /** Registers a boundary, in creation order; `ready` reports that its own data has loaded. */\n register(ready: () => boolean): SuspenseListSlot;\n}\n\n/** The enclosing list, or null. @internal */\nexport const SuspenseListContext: Context<SuspenseListState | null> =\n /* @__PURE__ */ createContext<SuspenseListState | null>(null, { name: \"SuspenseList\" });\n\n/**\n * Props of {@link SuspenseList}.\n * @since 1.0.0\n */\nexport interface SuspenseListProps {\n /**\n * `\"forwards\"`: boundaries reveal in order, each after the ones before it. `\"backwards\"`: the\n * same from the last one. `\"together\"`: all at once, when the last one is ready. Without it each\n * boundary reveals on its own. Read reactively.\n * @default undefined (each boundary reveals as soon as its own data is ready)\n */\n readonly revealOrder?: \"forwards\" | \"backwards\" | \"together\" | undefined;\n /**\n * What the boundaries that are still waiting show: `\"collapsed\"` only the next fallback in\n * order, `\"hidden\"` none. Applies to `forwards` and `backwards`; the default shows every fallback.\n * @default undefined (every waiting boundary shows its fallback)\n */\n readonly tail?: \"collapsed\" | \"hidden\" | undefined;\n /**\n * The content, with the `<Suspense>` boundaries to coordinate anywhere below it.\n * @default undefined (renders nothing)\n */\n readonly children?: unknown;\n}\n\n/**\n * Coordinates the `<Suspense>` boundaries below it so a page of independent loads reveals in a\n * calm order instead of popping in at random.\n *\n * @param props See {@link SuspenseListProps}.\n * @returns An accessor of the children, rendered with the list's coordination in context.\n * @example\n * import { Suspense, SuspenseList } from \"@shadow-js/web\";\n *\n * function Skeleton() {\n * return <p>Loading...</p>;\n * }\n *\n * function Profile() {\n * return <p>Profile</p>;\n * }\n *\n * function Feed() {\n * return <p>Feed</p>;\n * }\n *\n * function Page() {\n * return (\n * <SuspenseList revealOrder=\"forwards\" tail=\"collapsed\">\n * <Suspense fallback={<Skeleton />}>\n * <Profile />\n * </Suspense>\n * <Suspense fallback={<Skeleton />}>\n * <Feed />\n * </Suspense>\n * </SuspenseList>\n * );\n * }\n * @see Suspense\n * @since 1.0.0\n */\nexport function SuspenseList(props: SuspenseListProps): Accessor<unknown> {\n // The set of boundaries changes as they are created and disposed; `changes` tells readers.\n const changes = createSignalNode<number>(0, false);\n const slots: Array<{ readonly ready: () => boolean }> = [];\n const touch = (): void => {\n writeSignal(changes, 0, { allowInMemo: true });\n };\n\n const state: SuspenseListState = {\n register(ready) {\n const entry = { ready };\n slots.push(entry);\n touch();\n onCleanup(() => {\n const index = slots.indexOf(entry);\n if (index !== -1) slots.splice(index, 1);\n touch();\n });\n const position = (): number => {\n readSignal(changes);\n return slots.indexOf(entry);\n };\n const reveal = (): boolean => {\n const index = position();\n if (index === -1) return false;\n switch (props.revealOrder) {\n case \"together\":\n return slots.every((slot) => slot.ready());\n case \"forwards\":\n return slots.slice(0, index + 1).every((slot) => slot.ready());\n case \"backwards\":\n return slots.slice(index).every((slot) => slot.ready());\n default:\n return ready();\n }\n };\n const showFallback = (): boolean => {\n if (reveal()) return false;\n const order = props.revealOrder;\n const sequential = order === \"forwards\" || order === \"backwards\";\n if (!sequential) return true;\n if (props.tail === \"hidden\") return false;\n if (props.tail !== \"collapsed\") return true;\n // Only the next boundary in order that is not revealed yet shows its fallback.\n const index = position();\n const ordered = order === \"backwards\" ? [...slots].reverse() : slots;\n const wanted = order === \"backwards\" ? slots.length - 1 - index : index;\n for (let i = 0; i < ordered.length; i += 1) {\n const candidate = ordered[i];\n if (candidate !== undefined && !candidate.ready()) return i === wanted;\n }\n return false;\n };\n return { reveal, showFallback };\n },\n };\n\n return SuspenseListContext({\n value: state,\n get children() {\n return props.children;\n },\n }) as Accessor<unknown>;\n}\n\n/** The slot of the nearest list for a boundary created now, or null outside a list. @internal */\nexport function registerInList(ready: () => boolean): SuspenseListSlot | null {\n const list = useContext(SuspenseListContext);\n return list === null ? null : list.register(ready);\n}\n"],"mappings":"A,0JAkBA,MAAaA,EACK,kBAAwC,KAAM,CAAE,KAAM,cAAe,CAAC,EA+DxF,SAAgBC,EAAa,EAA6C,CAExE,IAAMC,EAAUC,EAAyB,EAAG,EAAK,EAC3CC,EAAkD,CAAC,EACnDC,MAAoB,CACxBC,EAAYJ,EAAS,EAAG,CAAE,YAAa,EAAK,CAAC,CAC/C,EAmDA,OAAOF,EAAoB,CACzB,MAAO,CAjDP,SAAS,EAAO,CACd,IAAMO,EAAQ,CAAE,OAAM,EACtBH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@ -0,0 +1,2 @@
1
+ import{childScope as e,nextKey as t,withScope as n}from"../internal/hydration-scope.js";import{escape as r}from"../server/escape.js";import{ssrRaw as i}from"../server/element.js";import{StreamContext as a}from"../internal/stream-context.js";import{SuspenseContext as o,getOwner as s,runWithOwner as c,useContext as l}from"@shadow-js/core";import{createOwner as u,createSignalNode as d,readSignal as f,transitionHooks as p,writeSignal as m}from"@shadow-js/core/extend";function h(){let e=d(0,Object.is),t,n=!1,r=t=>{m(e,e.value+t,{allowInMemo:!0})};return{tracker:{increment:()=>r(1),decrement:()=>{r(-1),e.value===0&&t?.release()},hold:()=>n?(t??=p()?.boundaryHold(),t?.engage()===!0):!1},count:()=>f(e),holding:()=>t?.holding()===!0,revealed:()=>{n=!0}}}function g(r){let i=t(),{tracker:a,count:s,holding:l,revealed:d}=h(),f=u();return f.gate=()=>s()>0||!1,_(r,i,s,c(f,()=>n(e(i),()=>o({value:a,get children(){return r.children}}))))}function _(t,u,d,f){let p=e(u===void 0?void 0:`${u}f`);if(d()===0)return f;let m=l(a);if(m===null||u===void 0)return()=>n(p,()=>t.fallback);let g=s(),_={id:u,rebuild:()=>{let i=h(),a=c(g,()=>n(e(u),()=>o({value:i.tracker,get children(){return t.children}})));return i.count()>0?(m.defer(_),null):r(a())}};return m.defer(_),()=>[i(`<!--[b:${u}-->`),n(p,()=>t.fallback),i(`<!--]-->`)]}export{g as Suspense};
2
+ //# sourceMappingURL=suspense.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suspense.js","names":["createTracker","pending","createSignalNode","hold","shown","adjust","writeSignal","by","transitionHooks","readSignal","Suspense","key","nextKey","boundary","createOwner","count","suspenseOnServer","props","runWithOwner","withScope","childScope","SuspenseContext","tracker","fallbackScope","content","sink","useContext","StreamContext","owner","getOwner","next","rebuilt","escape","ssrRaw"],"sources":["../../../src/control-flow/suspense.ts"],"sourcesContent":["import {\n type Accessor,\n getOwner,\n runWithOwner,\n SuspenseContext,\n type SuspenseTracker,\n useContext,\n useMemo,\n} from \"@shadow-js/core\";\nimport {\n type BoundaryHold,\n createOwner,\n createSignalNode,\n readSignal,\n transitionHooks,\n writeSignal,\n} from \"@shadow-js/core/extend\";\nimport { childScope, nextKey, StreamContext, withScope } from \"../extend\";\nimport { ssrRaw } from \"../server/element\";\n// biome-ignore lint/suspicious/noShadowRestrictedNames: `escape` is the compiler's SSR helper name.\nimport { escape } from \"../server/escape\";\nimport { registerInList } from \"./suspense-list\";\n\n/**\n * Props of {@link Suspense}.\n * @since 1.0.0\n */\nexport interface SuspenseProps {\n /**\n * Shown while any resource read inside the boundary is loading for the first time.\n * @default undefined (a pending boundary renders nothing)\n */\n fallback?: unknown;\n /**\n * The content. Created once, under the boundary, and kept alive while the fallback is visible.\n * @default undefined (renders nothing)\n */\n children?: unknown;\n}\n\n/** What a boundary tracks: its pending reads, and whether a transition holds its content. */\ninterface Tracking {\n readonly tracker: SuspenseTracker;\n readonly count: () => number;\n /** True while a transition waits for data and the boundary keeps showing its content. */\n readonly holding: () => boolean;\n /** Called when the boundary first shows its content: only then can a transition hold it. */\n readonly revealed: () => void;\n}\n\n/**\n * A counter the resources of one boundary report to (see {@link SuspenseTracker}), and the hold a\n * transition takes on the boundary. A transition that reads pending data while the boundary shows\n * content does not bring the fallback back: its readers keep their previous values, the boundary\n * keeps its content, and the readers run again when the count returns to zero.\n */\nfunction createTracker(): Tracking {\n // Counted with an extension-API cell: a resource may be read (and so hold this boundary) while a\n // memo computes, where a plain write would be rejected.\n const pending = createSignalNode<number>(0, Object.is);\n // The hold a transition takes on this boundary. Only a transition read creates it (core keeps the\n // machinery of holds behind its transition hooks); the boundary's memo reads the count before it\n // reads the hold, so it runs again when the count reaches zero (the release).\n let hold: BoundaryHold | undefined;\n let shown = false;\n const adjust = (by: number): void => {\n writeSignal(pending, pending.value + by, { allowInMemo: true });\n };\n const tracker: SuspenseTracker = {\n increment: () => adjust(1),\n decrement: () => {\n adjust(-1);\n if (pending.value === 0) hold?.release();\n },\n hold: (): boolean => {\n if (!shown) return false;\n hold ??= transitionHooks()?.boundaryHold();\n return hold?.engage() === true;\n },\n };\n return {\n tracker,\n count: () => readSignal(pending),\n holding: () => hold?.holding() === true,\n revealed: () => {\n shown = true;\n },\n };\n}\n\n/**\n * Shows `fallback` while resources read inside it are loading for the first time. The children\n * are created once and stay alive (with their state) while the fallback is visible; the boundary\n * only switches what is displayed. Nested boundaries each track their own resources.\n *\n * On the server a boundary renders its fallback when its data is not ready (`renderToString`), or\n * streams the content later (`renderToStream`). Content and fallback get their own hydration key\n * space, so what a boundary renders never shifts the keys of its siblings.\n *\n * @param props See {@link SuspenseProps}.\n * @returns An accessor of what the boundary shows: the fallback while a resource is pending, the\n * children otherwise.\n * @example\n * import { useResource } from \"@shadow-js/core\";\n * import { Suspense } from \"@shadow-js/web\";\n *\n * function Profile() {\n * const name = useResource(() => Promise.resolve(\"Ada\"));\n * return <p>{name()}</p>;\n * }\n *\n * function Page() {\n * return (\n * <Suspense fallback={<p>Loading...</p>}>\n * <Profile />\n * </Suspense>\n * );\n * }\n * @see SuspenseList\n * @see ErrorBoundary\n * @since 1.0.0\n */\nexport function Suspense(props: SuspenseProps): Accessor<unknown> {\n const key = nextKey();\n const { tracker, count, holding, revealed } = createTracker();\n // The content lives under its own owner, whose gate holds back user effects and `onMount` until\n // the boundary has resolved once. Render effects (DOM bindings) are never held.\n // Inside a <SuspenseList> the boundary also waits for its turn to be revealed.\n const slot = __SERVER__ ? null : registerInList(() => count() === 0);\n const boundary = createOwner();\n boundary.gate = () => count() > 0 || (slot !== null && !slot.reveal());\n const content = runWithOwner(boundary, () =>\n withScope(childScope(key), () =>\n SuspenseContext({\n value: tracker,\n get children() {\n return props.children;\n },\n }),\n ),\n );\n if (__SERVER__) return suspenseOnServer(props, key, count, content as () => unknown);\n const fallbackScope = childScope(key === undefined ? undefined : `${key}f`);\n return useMemo<unknown>(\n (previous) => {\n // Read first: the memo depends on the count even while held, so it runs again when the hold ends.\n count();\n // A transition holds the boundary: the content stays as it was (the same value, so no DOM change).\n if (holding() && previous !== undefined) return previous;\n if (slot === null) {\n if (count() > 0) return withScope(fallbackScope, () => props.fallback);\n revealed();\n return (content as () => unknown)();\n }\n if (count() === 0 && slot.reveal()) {\n revealed();\n return (content as () => unknown)();\n }\n return slot.showFallback() ? withScope(fallbackScope, () => props.fallback) : null;\n },\n { allowWrites: true },\n );\n}\n\n/** Server behavior: ready content, a fallback, or a fallback plus a deferred stream chunk. */\nfunction suspenseOnServer(\n props: SuspenseProps,\n key: string | undefined,\n count: () => number,\n content: () => unknown,\n): Accessor<unknown> {\n const fallbackScope = childScope(key === undefined ? undefined : `${key}f`);\n if (count() === 0) return content;\n const sink = useContext(StreamContext);\n if (sink === null || key === undefined) {\n return () => withScope(fallbackScope, () => props.fallback);\n }\n const owner = getOwner();\n const boundary = {\n id: key,\n rebuild: (): string | null => {\n const next = createTracker();\n const rebuilt = runWithOwner(owner, () =>\n withScope(childScope(key), () =>\n SuspenseContext({\n value: next.tracker,\n get children() {\n return props.children;\n },\n }),\n ),\n );\n if (next.count() > 0) {\n sink.defer(boundary);\n return null;\n }\n return escape((rebuilt as () => unknown)());\n },\n };\n sink.defer(boundary);\n // The markers delimit the region the stream later replaces; hydration strips them.\n return () => [\n ssrRaw(`<!--[b:${key}-->`),\n withScope(fallbackScope, () => props.fallback),\n ssrRaw(\"<!--]-->\"),\n ];\n}\n"],"mappings":"A,odAwDA,SAASA,GAA0B,CAGjC,IAAMC,EAAUC,EAAyB,EAAG,OAAO,EAAE,EAIjDC,EACAC,EAAQ,GACNC,EAAU,GAAqB,CACnCC,EAAYL,EAASA,EAAQ,MAAQM,EAAI,CAAE,YAAa,EAAK,CAAC,CAChE,EAaA,MAAO,CACL,QAAA,CAZA,cAAiBF,EAAO,CAAC,EACzB,cAAiB,CACfA,EAAO,EAAE,EACLJ,EAAQ,QAAU,GAAGE,GAAM,QAAQ,CACzC,EACA,SACOC,GACL,IAASI,EAAgB,CAAC,EAAE,aAAa,EAClCL,G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