@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,69 @@
1
+ //#region src/control-flow/portal.d.ts
2
+ /**
3
+ * Props of {@link Portal}.
4
+ * @since 1.0.0
5
+ */
6
+ export interface PortalProps {
7
+ /**
8
+ * The element that receives the content, or a function returning it (read reactively). A null
9
+ * target, or a function that returns null or undefined, renders nothing and warns once in
10
+ * development (`PORTAL_TARGET_MISSING`).
11
+ * @default document.body (when the prop is omitted)
12
+ */
13
+ readonly mount?: Element | null | (() => Element | null | undefined);
14
+ /**
15
+ * Put the content in a shadow root of the mount, created once and reused. A portal with a shadow
16
+ * root is not server-rendered; the browser creates it.
17
+ * @default false
18
+ */
19
+ readonly useShadow?: boolean;
20
+ /**
21
+ * Reserved for namespace handling. Nodes are inserted as they were created, so the flag does not
22
+ * change the output yet.
23
+ * @default false
24
+ */
25
+ readonly isSVG?: boolean;
26
+ /**
27
+ * The content: a node, text, an array, or an accessor returning them.
28
+ * @default undefined (nothing is rendered)
29
+ */
30
+ readonly children?: unknown;
31
+ }
32
+ /**
33
+ * Renders `children` into another part of the document, without a wrapper: the content nodes are
34
+ * inserted directly into the mount element (or its shadow root). Nothing is left at the call site.
35
+ * Disposing the owner removes exactly the nodes the portal inserted; nodes that were already in the
36
+ * mount stay. A reactive `mount` moves the content, and static nodes keep their identity while they
37
+ * move.
38
+ *
39
+ * On the server the content is rendered into the render's `portals` collector (see
40
+ * `createServerPortals`), and the document emits it at the end of `<body>`. When the browser hydrates
41
+ * the portal it adopts that markup instead of creating it again, moving it into the mount if the mount
42
+ * is not `body`. A portal with `useShadow` is not server-rendered; the browser creates it.
43
+ *
44
+ * Events follow the DOM tree. Delegated handlers inside the content fire when the mount is in the
45
+ * document, because the document listener sees the event bubble past the mount. Handlers on
46
+ * elements that wrap the call site do not fire.
47
+ *
48
+ * @param props See {@link PortalProps}.
49
+ * @returns Always null: the portal renders nothing in place.
50
+ * @example
51
+ * import { Portal } from "@shadow-js/web";
52
+ *
53
+ * function Modal() {
54
+ * return <div role="dialog">Hello</div>;
55
+ * }
56
+ *
57
+ * function App() {
58
+ * return (
59
+ * <Portal mount={document.getElementById("modal-root")}>
60
+ * <Modal />
61
+ * </Portal>
62
+ * );
63
+ * }
64
+ * @see Dynamic
65
+ * @since 1.0.0
66
+ */
67
+ export declare function Portal(props: PortalProps): null;
68
+ //#endregion
69
+ //# sourceMappingURL=portal.d.ts.map
@@ -0,0 +1,134 @@
1
+ import { childScope, nextKey, withScope } from "../internal/hydration-scope.js";
2
+ import { claims } from "../internal/hydration-hooks.js";
3
+ import { bindRegion, createRegion, removeRegion } from "../insert.js";
4
+ import { PortalContext } from "../internal/portal-context.js";
5
+ import { renderServerPortal } from "../server/portals.js";
6
+ import { createRoot, isServer, onCleanup, useContext, useRenderEffect } from "@shadow-js/core";
7
+ //#region src/control-flow/portal.ts
8
+ /** Appends `node` to `target`, moving it in place when the target supports `moveBefore`. */
9
+ function appendMoved(target, node) {
10
+ if (typeof target.moveBefore === "function") target.moveBefore(node, null);
11
+ else target.appendChild(node);
12
+ }
13
+ /** The shadow root of an element, attached once when the element has none. */
14
+ function shadowRootOf(host) {
15
+ return host.shadowRoot ?? host.attachShadow({ mode: "open" });
16
+ }
17
+ /** The mount target of a `mount` prop: the default body, the element, or the function's result. */
18
+ function resolveMount(mount) {
19
+ if (mount === void 0) return document.body;
20
+ return (typeof mount === "function" ? mount() : mount) ?? null;
21
+ }
22
+ /**
23
+ * Renders `children` into another part of the document, without a wrapper: the content nodes are
24
+ * inserted directly into the mount element (or its shadow root). Nothing is left at the call site.
25
+ * Disposing the owner removes exactly the nodes the portal inserted; nodes that were already in the
26
+ * mount stay. A reactive `mount` moves the content, and static nodes keep their identity while they
27
+ * move.
28
+ *
29
+ * On the server the content is rendered into the render's `portals` collector (see
30
+ * `createServerPortals`), and the document emits it at the end of `<body>`. When the browser hydrates
31
+ * the portal it adopts that markup instead of creating it again, moving it into the mount if the mount
32
+ * is not `body`. A portal with `useShadow` is not server-rendered; the browser creates it.
33
+ *
34
+ * Events follow the DOM tree. Delegated handlers inside the content fire when the mount is in the
35
+ * document, because the document listener sees the event bubble past the mount. Handlers on
36
+ * elements that wrap the call site do not fire.
37
+ *
38
+ * @param props See {@link PortalProps}.
39
+ * @returns Always null: the portal renders nothing in place.
40
+ * @example
41
+ * import { Portal } from "@shadow-js/web";
42
+ *
43
+ * function Modal() {
44
+ * return <div role="dialog">Hello</div>;
45
+ * }
46
+ *
47
+ * function App() {
48
+ * return (
49
+ * <Portal mount={document.getElementById("modal-root")}>
50
+ * <Modal />
51
+ * </Portal>
52
+ * );
53
+ * }
54
+ * @see Dynamic
55
+ * @since 1.0.0
56
+ */
57
+ function Portal(props) {
58
+ const key = nextKey();
59
+ const sink = useContext(PortalContext);
60
+ if (isServer || sink !== null) {
61
+ if (props.useShadow !== true) renderServerPortal(key, () => props.children, sink);
62
+ return null;
63
+ }
64
+ let mounted;
65
+ let warned = false;
66
+ let adopted = claims.current.claimPortal(key);
67
+ /** Stops the content's effects, then removes its nodes. Safe to call when nothing is mounted. */
68
+ const unmount = () => {
69
+ const current = mounted;
70
+ if (current === void 0) return;
71
+ mounted = void 0;
72
+ current.stopEffects();
73
+ removeRegion(current.region);
74
+ };
75
+ /** Creates the content region in `host`, adopting the nodes that are already there. */
76
+ const mountInto = (host, initial, mode) => {
77
+ const region = createRegion(host, null, initial);
78
+ return {
79
+ host,
80
+ region,
81
+ stopEffects: createRoot((dispose) => {
82
+ const bind = () => {
83
+ bindRegion(region, () => props.children);
84
+ };
85
+ if (mode === "plain") bind();
86
+ else if (mode === "claimed") withScope(childScope(key), bind);
87
+ else claims.current.withoutClaiming(() => withScope(childScope(key), bind));
88
+ return dispose;
89
+ })
90
+ };
91
+ };
92
+ /** Moves the content to `target`. The nodes move first, then the children are bound again. */
93
+ const moveTo = (target) => {
94
+ const previous = mounted;
95
+ if (previous === void 0) {
96
+ const initial = adopted ?? [];
97
+ let mode = "plain";
98
+ if (adopted !== void 0) mode = "claimed";
99
+ else if (key !== void 0 && claims.current.isClaiming()) mode = "unclaimed";
100
+ adopted = void 0;
101
+ for (const node of initial) if (node.parentNode !== target) appendMoved(target, node);
102
+ mounted = mountInto(target, initial, mode);
103
+ return;
104
+ }
105
+ const nodes = previous.region.nodes.filter((node) => node.parentNode === previous.host);
106
+ previous.stopEffects();
107
+ for (const node of nodes) appendMoved(target, node);
108
+ mounted = mountInto(target, nodes, "plain");
109
+ };
110
+ useRenderEffect(() => {
111
+ return {
112
+ host: resolveMount(props.mount),
113
+ shadow: props.useShadow === true
114
+ };
115
+ }, ({ host, shadow }) => {
116
+ if (host === null) {
117
+ unmount();
118
+ if (!warned) {
119
+ warned = true;
120
+ console.warn("[shadow PORTAL_TARGET_MISSING] Portal has no mount element; nothing is rendered.");
121
+ }
122
+ return;
123
+ }
124
+ const target = shadow ? shadowRootOf(host) : host;
125
+ if (mounted !== void 0 && mounted.host === target) return;
126
+ moveTo(target);
127
+ });
128
+ onCleanup(unmount);
129
+ return null;
130
+ }
131
+ //#endregion
132
+ export { Portal };
133
+
134
+ //# sourceMappingURL=portal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal.js","names":[],"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":";;;;;;;;AAiEA,SAAS,YAAY,QAAc,MAAkB;CACnD,IAAI,OAAQ,OAAgC,eAAe,YACzD,OAAwB,WAAW,MAAM,IAAI;MAE7C,OAAO,YAAY,IAAI;AAE3B;;AAGA,SAAS,aAAa,MAA2B;CAC/C,OAAO,KAAK,cAAc,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAC9D;;AAGA,SAAS,aAAa,OAA6C;CACjE,IAAI,UAAU,KAAA,GAAW,OAAO,SAAS;CAEzC,QADc,OAAO,UAAU,aAAa,MAAM,IAAI,UACtC;AAClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,OAAO,OAA0B;CAI/C,MAAM,MAAM,QAAQ;CAGpB,MAAM,OAAO,WAAW,aAAa;CACrC,IAAI,YAAY,SAAS,MAAM;EAC7B,IAAI,MAAM,cAAc,MAAM,mBAAmB,WAAW,MAAM,UAAU,IAAI;EAChF,OAAO;CACT;CACA,IAAI;CACJ,IAAI,SAAS;CAEb,IAAI,UAA8B,OAAO,QAAQ,YAAY,GAAG;;CAGhE,MAAM,gBAAsB;EAC1B,MAAM,UAAU;EAChB,IAAI,YAAY,KAAA,GAAW;EAC3B,UAAU,KAAA;EACV,QAAQ,YAAY;EACpB,aAAa,QAAQ,MAAM;CAC7B;;CAGA,MAAM,aAAa,MAAY,SAAiB,SAA6B;EAC3E,MAAM,SAAS,aAAa,MAAM,MAAM,OAAO;EAU/C,OAAO;GAAE;GAAM;GAAQ,aATH,YAAY,YAAY;IAC1C,MAAM,aAAmB;KACvB,WAAW,cAAc,MAAM,QAAQ;IACzC;IACA,IAAI,SAAS,SAAS,KAAK;SACtB,IAAI,SAAS,WAAW,UAAU,WAAW,GAAG,GAAG,IAAI;SACvD,OAAO,QAAQ,sBAAsB,UAAU,WAAW,GAAG,GAAG,IAAI,CAAC;IAC1E,OAAO;GACT,CACiC;EAAE;CACrC;;CAGA,MAAM,UAAU,WAAuB;EACrC,MAAM,WAAW;EACjB,IAAI,aAAa,KAAA,GAAW;GAC1B,MAAM,UAAU,WAAW,CAAC;GAC5B,IAAI,OAAkB;GACtB,IAAI,YAAY,KAAA,GAAW,OAAO;QAC7B,IAAI,QAAQ,KAAA,KAAa,OAAO,QAAQ,WAAW,GAAG,OAAO;GAClE,UAAU,KAAA;GACV,KAAK,MAAM,QAAQ,SACjB,IAAI,KAAK,eAAe,QAAQ,YAAY,QAAQ,IAAI;GAE1D,UAAU,UAAU,QAAQ,SAAS,IAAI;GACzC;EACF;EACA,MAAM,QAAQ,SAAS,OAAO,MAAM,QAAQ,SAAS,KAAK,eAAe,SAAS,IAAI;EACtF,SAAS,YAAY;EACrB,KAAK,MAAM,QAAQ,OAAO,YAAY,QAAQ,IAAI;EAClD,UAAU,UAAU,QAAQ,OAAO,OAAO;CAC5C;CAEA,sBACQ;EAGJ,OAAO;GAAE,MAFI,aAAa,MAAM,KAEpB;GAAG,QADA,MAAM,cAAc;EACb;CACxB,IACC,EAAE,MAAM,aAAa;EACpB,IAAI,SAAS,MAAM;GACjB,QAAQ;GACR,IAAe,CAAC,QAAQ;IACtB,SAAS;IACT,QAAQ,KACN,kFACF;GACF;GACA;EACF;EACA,MAAM,SAAe,SAAS,aAAa,IAAI,IAAI;EACnD,IAAI,YAAY,KAAA,KAAa,QAAQ,SAAS,QAAQ;EACtD,OAAO,MAAM;CACf,CACF;CACA,UAAU,OAAO;CACjB,OAAO;AACT"}
@@ -0,0 +1,25 @@
1
+ import { Owner } from "@shadow-js/core";
2
+ //#region src/control-flow/root-errors.d.ts
3
+ /**
4
+ * The error reporters a root was rendered or hydrated with (see `RenderOptions` and `HydrateOptions`).
5
+ * @since 1.0.0
6
+ */
7
+ export interface RootErrorOptions {
8
+ /**
9
+ * Receives an error that no error boundary took. The root then does not rethrow it.
10
+ * @default undefined (no reporter; an error no boundary takes follows the default handling)
11
+ */
12
+ readonly onUncaughtError?: (error: unknown) => void;
13
+ /**
14
+ * Receives an error an `ErrorBoundary` caught (its fallback is shown).
15
+ * @default undefined (no reporter)
16
+ */
17
+ readonly onCaughtError?: (error: unknown) => void;
18
+ /**
19
+ * Receives a hydration mismatch that was repaired on the client. Only `hydrate` reports these.
20
+ * @default undefined (no reporter)
21
+ */
22
+ readonly onRecoverableError?: (error: unknown) => void;
23
+ }
24
+ //#endregion
25
+ //# sourceMappingURL=root-errors.d.ts.map
@@ -0,0 +1,33 @@
1
+ import { getOwner } from "@shadow-js/core";
2
+ //#region src/control-flow/root-errors.ts
3
+ /**
4
+ * The key the reporters are stored under in an owner's context map. A symbol the context map inherits
5
+ * (as a Provider's value is inherited), so every node below the root sees it, detached roots included.
6
+ * A plain value rather than a context: a context would bring its Provider into every bundle.
7
+ */
8
+ const ROOT_ERRORS = /* @__PURE__ */ Symbol("RootErrors");
9
+ /**
10
+ * Attaches the options to the root that is being created (called inside its `createRoot`). The reporters
11
+ * go into the root's context map, and an `onUncaughtError` becomes the root's error handler (a fresh root
12
+ * has none, so it is the only one).
13
+ * @internal
14
+ */
15
+ function attachRootErrors(options) {
16
+ const root = getOwner();
17
+ if (root === null) return;
18
+ const map = Object.create(root.context);
19
+ map[ROOT_ERRORS] = options;
20
+ root.context = map;
21
+ if (options.onUncaughtError !== void 0) root.errorHandlers = [options.onUncaughtError];
22
+ }
23
+ /**
24
+ * The reporters of the nearest root above `owner`, or undefined when no root was given options.
25
+ * @internal
26
+ */
27
+ function rootErrorsOf(owner) {
28
+ return owner?.context?.[ROOT_ERRORS];
29
+ }
30
+ //#endregion
31
+ export { attachRootErrors, rootErrorsOf };
32
+
33
+ //# sourceMappingURL=root-errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root-errors.js","names":[],"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":";;;;;;;AA6BA,MAAM,cAAsC,uBAAO,YAAY;;;;;;;AAQ/D,SAAgB,iBAAiB,SAAiC;CAChE,MAAM,OAAO,SAAS;CACtB,IAAI,SAAS,MAAM;CACnB,MAAM,MAAM,OAAO,OAAO,KAAK,OAAO;CACtC,IAAI,eAAe;CACnB,KAAK,UAAU;CACf,IAAI,QAAQ,oBAAoB,KAAA,GAAW,KAAK,gBAAgB,CAAC,QAAQ,eAAe;AAC1F;;;;;AAMA,SAAgB,aAAa,OAAmD;CAC9E,OAAO,OAAO,UAAU;AAC1B"}
@@ -0,0 +1,101 @@
1
+ import { JsxChild } from "../jsx/types.js";
2
+ import { Accessor } from "@shadow-js/core";
3
+ //#region src/control-flow/show.d.ts
4
+ /** What `when` accepts: the value, or any falsy stand-in (`0` and `""` count as falsy). */
5
+ type ShowCondition<T> = T | undefined | null | false | 0 | "";
6
+ /** Props shared by both forms of {@link Show}. */
7
+ interface ShowBaseProps<T> {
8
+ /** The condition. The children are shown while it is truthy. */
9
+ readonly when: ShowCondition<T>;
10
+ /**
11
+ * Shown while `when` is falsy. Read lazily, only when it is needed.
12
+ * @default undefined (a falsy `when` renders nothing)
13
+ */
14
+ readonly fallback?: unknown;
15
+ }
16
+ /**
17
+ * Keyed form: the children are rebuilt whenever the identity of `when` changes and a callback
18
+ * child receives the value itself.
19
+ * @since 1.0.0
20
+ */
21
+ export interface ShowKeyedProps<T> extends ShowBaseProps<T> {
22
+ /** Must be `true` in this form: a change of the identity of `when` rebuilds the children. */
23
+ readonly keyed: true;
24
+ /**
25
+ * Plain content, an accessor, or a callback `(item) => content` called untracked in the branch.
26
+ * @default undefined (a truthy `when` renders nothing)
27
+ */
28
+ readonly children?: JsxChild | (() => unknown) | ((item: NonNullable<T>) => unknown);
29
+ }
30
+ /**
31
+ * Default form: the branch is rebuilt only when the truthiness of `when` changes. A callback child
32
+ * receives an accessor of the latest truthy value; reading it after `when` became falsy throws a
33
+ * TypeError, except while the branch is being torn down.
34
+ * @since 1.0.0
35
+ */
36
+ export interface ShowAccessorProps<T> extends ShowBaseProps<T> {
37
+ /**
38
+ * Absent or `false` in this form: the children are rebuilt only when the truthiness of `when`
39
+ * changes.
40
+ * @default false
41
+ */
42
+ readonly keyed?: false;
43
+ /**
44
+ * Plain content, an accessor, or a callback `(item) => content` called untracked in the branch.
45
+ * @default undefined (a truthy `when` renders nothing)
46
+ */
47
+ readonly children?: JsxChild | (() => unknown) | ((item: Accessor<NonNullable<T>>) => unknown);
48
+ }
49
+ /**
50
+ * Props of {@link Show}.
51
+ * @since 1.0.0
52
+ */
53
+ export type ShowProps<T> = ShowKeyedProps<T> | ShowAccessorProps<T>;
54
+ /**
55
+ * The same props with untyped `children`, for code that forwards children it does not know the
56
+ * shape of (a wrapper component's own `props.children`).
57
+ * @since 1.0.0
58
+ */
59
+ export interface ShowLooseProps<T> extends ShowBaseProps<T> {
60
+ /**
61
+ * Same meaning as in {@link ShowKeyedProps}: `true` rebuilds the children when the identity of
62
+ * `when` changes.
63
+ * @default false
64
+ */
65
+ readonly keyed?: boolean;
66
+ /**
67
+ * Plain content, an accessor, or a callback, as in {@link ShowProps}.
68
+ * @default undefined (a truthy `when` renders nothing)
69
+ */
70
+ readonly children?: unknown;
71
+ }
72
+ /**
73
+ * Shows `children` while `when` is truthy, and `fallback` otherwise. The branch is rebuilt only
74
+ * when the truthiness of `when` changes (or, with `keyed`, when its identity changes).
75
+ *
76
+ * `when` follows JavaScript truthiness: `0`, `""`, `null`, `undefined` and `false` show the
77
+ * fallback. While `fallback` is not given, a falsy `when` renders nothing.
78
+ *
79
+ * @param props See {@link ShowProps}.
80
+ * @returns An accessor of the current branch's content. The DOM runtime's `insert` consumes it.
81
+ * @example
82
+ * import { useSignal } from "@shadow-js/core";
83
+ * import { Show } from "@shadow-js/web";
84
+ *
85
+ * function Greeting() {
86
+ * const [user] = useSignal<{ name: string } | null>(null);
87
+ * return (
88
+ * <Show when={user()} fallback={<p>Sign in</p>}>
89
+ * {(u) => <p>Hello {u().name}</p>}
90
+ * </Show>
91
+ * );
92
+ * }
93
+ * @see Switch
94
+ * @see ErrorBoundary
95
+ * @since 1.0.0
96
+ */
97
+ export declare function Show<T>(props: ShowProps<T>): Accessor<unknown>;
98
+ export declare function Show<T>(props: ShowLooseProps<T>): Accessor<unknown>;
99
+ //#endregion
100
+ export {};
101
+ //# sourceMappingURL=show.d.ts.map
@@ -0,0 +1,18 @@
1
+ import { createBranches } from "./branch.js";
2
+ //#region src/control-flow/show.ts
3
+ function Show(props) {
4
+ return createBranches("Show", () => {
5
+ const when = props.when;
6
+ return {
7
+ index: when ? 0 : -1,
8
+ keyed: props.keyed === true,
9
+ when,
10
+ read: () => props.when,
11
+ body: () => props.children
12
+ };
13
+ }, () => props.fallback);
14
+ }
15
+ //#endregion
16
+ export { Show };
17
+
18
+ //# sourceMappingURL=show.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"show.js","names":[],"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":";;AAyGA,SAAgB,KAAQ,OAA6C;CACnE,OAAO,eACL,cACM;EACJ,MAAM,OAAO,MAAM;EACnB,OAAO;GACL,OAAO,OAAO,IAAA;GACd,OAAO,MAAM,UAAU;GACvB;GACA,YAAY,MAAM;GAClB,YAAY,MAAM;EACpB;CACF,SACM,MAAM,QACd;AACF"}
@@ -0,0 +1,65 @@
1
+ import { Accessor, Context } from "@shadow-js/core";
2
+ //#region src/control-flow/suspense-list.d.ts
3
+ /**
4
+ * Props of {@link SuspenseList}.
5
+ * @since 1.0.0
6
+ */
7
+ export interface SuspenseListProps {
8
+ /**
9
+ * `"forwards"`: boundaries reveal in order, each after the ones before it. `"backwards"`: the
10
+ * same from the last one. `"together"`: all at once, when the last one is ready. Without it each
11
+ * boundary reveals on its own. Read reactively.
12
+ * @default undefined (each boundary reveals as soon as its own data is ready)
13
+ */
14
+ readonly revealOrder?: "forwards" | "backwards" | "together" | undefined;
15
+ /**
16
+ * What the boundaries that are still waiting show: `"collapsed"` only the next fallback in
17
+ * order, `"hidden"` none. Applies to `forwards` and `backwards`; the default shows every fallback.
18
+ * @default undefined (every waiting boundary shows its fallback)
19
+ */
20
+ readonly tail?: "collapsed" | "hidden" | undefined;
21
+ /**
22
+ * The content, with the `<Suspense>` boundaries to coordinate anywhere below it.
23
+ * @default undefined (renders nothing)
24
+ */
25
+ readonly children?: unknown;
26
+ }
27
+ /**
28
+ * Coordinates the `<Suspense>` boundaries below it so a page of independent loads reveals in a
29
+ * calm order instead of popping in at random.
30
+ *
31
+ * @param props See {@link SuspenseListProps}.
32
+ * @returns An accessor of the children, rendered with the list's coordination in context.
33
+ * @example
34
+ * import { Suspense, SuspenseList } from "@shadow-js/web";
35
+ *
36
+ * function Skeleton() {
37
+ * return <p>Loading...</p>;
38
+ * }
39
+ *
40
+ * function Profile() {
41
+ * return <p>Profile</p>;
42
+ * }
43
+ *
44
+ * function Feed() {
45
+ * return <p>Feed</p>;
46
+ * }
47
+ *
48
+ * function Page() {
49
+ * return (
50
+ * <SuspenseList revealOrder="forwards" tail="collapsed">
51
+ * <Suspense fallback={<Skeleton />}>
52
+ * <Profile />
53
+ * </Suspense>
54
+ * <Suspense fallback={<Skeleton />}>
55
+ * <Feed />
56
+ * </Suspense>
57
+ * </SuspenseList>
58
+ * );
59
+ * }
60
+ * @see Suspense
61
+ * @since 1.0.0
62
+ */
63
+ export declare function SuspenseList(props: SuspenseListProps): Accessor<unknown>;
64
+ //#endregion
65
+ //# sourceMappingURL=suspense-list.d.ts.map
@@ -0,0 +1,105 @@
1
+ import { createContext, onCleanup, useContext } from "@shadow-js/core";
2
+ import { createSignalNode, readSignal, writeSignal } from "@shadow-js/core/extend";
3
+ //#region src/control-flow/suspense-list.ts
4
+ /** The enclosing list, or null. @internal */
5
+ const SuspenseListContext = /* @__PURE__ */ createContext(null, { name: "SuspenseList" });
6
+ /**
7
+ * Coordinates the `<Suspense>` boundaries below it so a page of independent loads reveals in a
8
+ * calm order instead of popping in at random.
9
+ *
10
+ * @param props See {@link SuspenseListProps}.
11
+ * @returns An accessor of the children, rendered with the list's coordination in context.
12
+ * @example
13
+ * import { Suspense, SuspenseList } from "@shadow-js/web";
14
+ *
15
+ * function Skeleton() {
16
+ * return <p>Loading...</p>;
17
+ * }
18
+ *
19
+ * function Profile() {
20
+ * return <p>Profile</p>;
21
+ * }
22
+ *
23
+ * function Feed() {
24
+ * return <p>Feed</p>;
25
+ * }
26
+ *
27
+ * function Page() {
28
+ * return (
29
+ * <SuspenseList revealOrder="forwards" tail="collapsed">
30
+ * <Suspense fallback={<Skeleton />}>
31
+ * <Profile />
32
+ * </Suspense>
33
+ * <Suspense fallback={<Skeleton />}>
34
+ * <Feed />
35
+ * </Suspense>
36
+ * </SuspenseList>
37
+ * );
38
+ * }
39
+ * @see Suspense
40
+ * @since 1.0.0
41
+ */
42
+ function SuspenseList(props) {
43
+ const changes = createSignalNode(0, false);
44
+ const slots = [];
45
+ const touch = () => {
46
+ writeSignal(changes, 0, { allowInMemo: true });
47
+ };
48
+ return SuspenseListContext({
49
+ value: { register(ready) {
50
+ const entry = { ready };
51
+ slots.push(entry);
52
+ touch();
53
+ onCleanup(() => {
54
+ const index = slots.indexOf(entry);
55
+ if (index !== -1) slots.splice(index, 1);
56
+ touch();
57
+ });
58
+ const position = () => {
59
+ readSignal(changes);
60
+ return slots.indexOf(entry);
61
+ };
62
+ const reveal = () => {
63
+ const index = position();
64
+ if (index === -1) return false;
65
+ switch (props.revealOrder) {
66
+ case "together": return slots.every((slot) => slot.ready());
67
+ case "forwards": return slots.slice(0, index + 1).every((slot) => slot.ready());
68
+ case "backwards": return slots.slice(index).every((slot) => slot.ready());
69
+ default: return ready();
70
+ }
71
+ };
72
+ const showFallback = () => {
73
+ if (reveal()) return false;
74
+ const order = props.revealOrder;
75
+ if (!(order === "forwards" || order === "backwards")) return true;
76
+ if (props.tail === "hidden") return false;
77
+ if (props.tail !== "collapsed") return true;
78
+ const index = position();
79
+ const ordered = order === "backwards" ? [...slots].reverse() : slots;
80
+ const wanted = order === "backwards" ? slots.length - 1 - index : index;
81
+ for (let i = 0; i < ordered.length; i += 1) {
82
+ const candidate = ordered[i];
83
+ if (candidate !== void 0 && !candidate.ready()) return i === wanted;
84
+ }
85
+ return false;
86
+ };
87
+ return {
88
+ reveal,
89
+ showFallback
90
+ };
91
+ } },
92
+ get children() {
93
+ return props.children;
94
+ }
95
+ });
96
+ }
97
+ /** The slot of the nearest list for a boundary created now, or null outside a list. @internal */
98
+ function registerInList(ready) {
99
+ const list = useContext(SuspenseListContext);
100
+ return list === null ? null : list.register(ready);
101
+ }
102
+ //#endregion
103
+ export { SuspenseList, SuspenseListContext, registerInList };
104
+
105
+ //# sourceMappingURL=suspense-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suspense-list.js","names":[],"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":";;;;AAkBA,MAAa,sBACK,8BAAwC,MAAM,EAAE,MAAM,eAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DxF,SAAgB,aAAa,OAA6C;CAExE,MAAM,UAAU,iBAAyB,GAAG,KAAK;CACjD,MAAM,QAAkD,CAAC;CACzD,MAAM,cAAoB;EACxB,YAAY,SAAS,GAAG,EAAE,aAAa,KAAK,CAAC;CAC/C;CAmDA,OAAO,oBAAoB;EACzB,OAAO,EAjDP,SAAS,OAAO;GACd,MAAM,QAAQ,EAAE,MAAM;GACtB,MAAM,KAAK,KAAK;GAChB,MAAM;GACN,gBAAgB;IACd,MAAM,QAAQ,MAAM,QAAQ,KAAK;IACjC,IAAI,UAAU,IAAI,MAAM,OAAO,OAAO,CAAC;IACvC,MAAM;GACR,CAAC;GACD,MAAM,iBAAyB;IAC7B,WAAW,OAAO;IAClB,OAAO,MAAM,QAAQ,KAAK;GAC5B;GACA,MAAM,eAAwB;IAC5B,MAAM,QAAQ,SAAS;IACvB,IAAI,UAAU,IAAI,OAAO;IACzB,QAAQ,MAAM,aAAd;KACE,KAAK,YACH,OAAO,MAAM,OAAO,SAAS,KAAK,MAAM,CAAC;KAC3C,KAAK,YACH,OAAO,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,OAAO,SAAS,KAAK,MAAM,CAAC;KAC/D,KAAK,aACH,OAAO,MAAM,MAAM,KAAK,CAAC,CAAC,OAAO,SAAS,KAAK,MAAM,CAAC;KACxD,SACE,OAAO,MAAM;IACjB;GACF;GACA,MAAM,qBAA8B;IAClC,IAAI,OAAO,GAAG,OAAO;IACrB,MAAM,QAAQ,MAAM;IAEpB,IAAI,EADe,UAAU,cAAc,UAAU,cACpC,OAAO;IACxB,IAAI,MAAM,SAAS,UAAU,OAAO;IACpC,IAAI,MAAM,SAAS,aAAa,OAAO;IAEvC,MAAM,QAAQ,SAAS;IACvB,MAAM,UAAU,UAAU,cAAc,CAAC,GAAG,KAAK,CAAC,CAAC,QAAQ,IAAI;IAC/D,MAAM,SAAS,UAAU,cAAc,MAAM,SAAS,IAAI,QAAQ;IAClE,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK,GAAG;KAC1C,MAAM,YAAY,QAAQ;KAC1B,IAAI,cAAc,KAAA,KAAa,CAAC,UAAU,MAAM,GAAG,OAAO,MAAM;IAClE;IACA,OAAO;GACT;GACA,OAAO;IAAE;IAAQ;GAAa;EAChC,EAIW;EACX,IAAI,WAAW;GACb,OAAO,MAAM;EACf;CACF,CAAC;AACH;;AAGA,SAAgB,eAAe,OAA+C;CAC5E,MAAM,OAAO,WAAW,mBAAmB;CAC3C,OAAO,SAAS,OAAO,OAAO,KAAK,SAAS,KAAK;AACnD"}