@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,156 @@
1
+ //#region src/internal/hydration-scope.ts
2
+ let current = null;
3
+ /**
4
+ * Creates the scope a render or a hydration starts from: what `renderToString` and `hydrate()` put in
5
+ * effect around the app. A custom renderer that hands out hydration keys does the same.
6
+ *
7
+ * @param renderId The prefix of every key of this render. Default: `"0"`, the default `renderId` of
8
+ * the renderers.
9
+ * @returns A fresh scope whose `id` is `` `${renderId}-` ``.
10
+ * @example
11
+ * import { createRootScope, nextKey, withScope } from "@shadow-js/web/extend";
12
+ *
13
+ * const keys = withScope(createRootScope("app"), () => [nextKey(), nextKey()]);
14
+ * // ["app-0", "app-1"]
15
+ * @see withScope
16
+ * @since 1.0.0
17
+ */
18
+ function createRootScope(renderId = "0") {
19
+ return {
20
+ id: `${renderId}-`,
21
+ count: 0,
22
+ resources: 0
23
+ };
24
+ }
25
+ /**
26
+ * Returns the hydration scope in effect.
27
+ *
28
+ * @returns The current scope; `null` outside a server render, a hydration, or a {@link withScope}
29
+ * call.
30
+ * @example
31
+ * import { currentScope } from "@shadow-js/web/extend";
32
+ *
33
+ * function scopeLabel(): string {
34
+ * return currentScope()?.id ?? "no scope";
35
+ * }
36
+ * @since 1.0.0
37
+ */
38
+ function currentScope() {
39
+ return current;
40
+ }
41
+ /**
42
+ * Runs `fn` with `scope` in effect, so the keys `fn` draws come from it. The previous scope is
43
+ * restored when `fn` returns or throws.
44
+ *
45
+ * @param scope The scope to put in effect; `null` runs `fn` with no scope (no keys are drawn).
46
+ * @param fn The code to run, synchronously, once.
47
+ * @returns What `fn` returns. An error `fn` throws propagates.
48
+ * @example
49
+ * import { childScope, nextKey, withScope } from "@shadow-js/web/extend";
50
+ *
51
+ * // The keys of an isolated subtree, independent of its siblings.
52
+ * const first = withScope(childScope("0-4"), () => nextKey()); // "0-4-0"
53
+ * @see createRootScope
54
+ * @since 1.0.0
55
+ */
56
+ function withScope(scope, fn) {
57
+ const previous = current;
58
+ current = scope;
59
+ try {
60
+ return fn();
61
+ } finally {
62
+ current = previous;
63
+ }
64
+ }
65
+ /**
66
+ * Runs a component call in a scope of its own, so the keys it draws depend only on its position
67
+ * among its parent's calls: what `createComponent` does on the client and on the server. The
68
+ * component's scope takes the next number of the parent scope.
69
+ *
70
+ * @param fn The component call, run synchronously, once.
71
+ * @returns What `fn` returns. Without a scope in effect, `fn` simply runs.
72
+ * @example
73
+ * import { createRootScope, enterComponent, nextKey, withScope } from "@shadow-js/web/extend";
74
+ *
75
+ * withScope(createRootScope(), () => {
76
+ * nextKey(); // "0-0"
77
+ * return enterComponent(() => nextKey()); // "0-1-0": the component's first key
78
+ * });
79
+ * @since 1.0.0
80
+ */
81
+ function enterComponent(fn) {
82
+ const parent = current;
83
+ if (parent === null) return fn();
84
+ return withScope({
85
+ id: `${parent.id}${parent.count++}-`,
86
+ count: 0,
87
+ resources: 0
88
+ }, fn);
89
+ }
90
+ /**
91
+ * Draws the key of the next template root in the current scope: what `template()` and
92
+ * `ssrHydrationKey()` call, in the same order on the server and the client. Each call advances the
93
+ * scope.
94
+ *
95
+ * @returns The key (`"0-0"`, `"0-1"`, ...); undefined outside a scope.
96
+ * @example
97
+ * import { claimElement, nextKey } from "@shadow-js/web/extend";
98
+ *
99
+ * function createBadge(): Element {
100
+ * return claimElement(nextKey()) ?? document.createElement("span");
101
+ * }
102
+ * @see claimElement
103
+ * @since 1.0.0
104
+ */
105
+ function nextKey() {
106
+ const scope = current;
107
+ if (scope === null) return void 0;
108
+ return `${scope.id}${scope.count++}`;
109
+ }
110
+ /**
111
+ * Returns the key a resource's value is stored under in the server data, the same on the server and
112
+ * the client: the explicit key when there is one, else one drawn from the current scope.
113
+ *
114
+ * @param explicit The resource's own key. When given, the result is `` `k:${explicit}` ``, a prefix
115
+ * no generated key has. Undefined draws the next resource key of the scope.
116
+ * @returns `` `k:${explicit}` ``; otherwise the scope id, `r` and the creation index (`"0-1-r0"`);
117
+ * `"r"` outside a scope.
118
+ * @example
119
+ * import { createRootScope, resourceKey, withScope } from "@shadow-js/web/extend";
120
+ *
121
+ * withScope(createRootScope(), () => [resourceKey(undefined), resourceKey("user")]);
122
+ * // ["0-r0", "k:user"]
123
+ * @since 1.0.0
124
+ */
125
+ function resourceKey(explicit) {
126
+ if (explicit !== void 0) return `k:${explicit}`;
127
+ const scope = current;
128
+ if (scope === null) return "r";
129
+ return `${scope.id}r${scope.resources++}`;
130
+ }
131
+ /**
132
+ * Creates a fresh scope for an isolated part of the tree, such as a Suspense boundary's content or
133
+ * fallback, or a portal's content: its keys depend only on `key`, not on the siblings around it.
134
+ *
135
+ * @param key The key of the boundary (from `nextKey()`); undefined means no scope.
136
+ * @returns A scope whose `id` is `` `${key}-` ``; `null` when `key` is undefined.
137
+ * @example
138
+ * import { childScope, nextKey, withScope } from "@shadow-js/web/extend";
139
+ *
140
+ * function renderIsolated<T>(build: () => T): T {
141
+ * return withScope(childScope(nextKey()), build);
142
+ * }
143
+ * @see withScope
144
+ * @since 1.0.0
145
+ */
146
+ function childScope(key) {
147
+ return key === void 0 ? null : {
148
+ id: `${key}-`,
149
+ count: 0,
150
+ resources: 0
151
+ };
152
+ }
153
+ //#endregion
154
+ export { childScope, createRootScope, currentScope, enterComponent, nextKey, resourceKey, withScope };
155
+
156
+ //# sourceMappingURL=hydration-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hydration-scope.js","names":[],"sources":["../../../src/internal/hydration-scope.ts"],"sourcesContent":["/**\n * A hydration scope: the deterministic source of hydration keys shared by the server renderer and\n * the client hydrator. Keys depend only on the nesting and order of component calls, never on owners,\n * effects or memos, so server and client agree as long as they run the same components. Scopes are\n * created by {@link createRootScope}, {@link enterComponent} and {@link childScope}; treat their\n * fields as read-only.\n *\n * @since 1.0.0\n */\nexport interface HydrationScope {\n /** Prefix of every key allocated in this scope, ending with `-` (`\"0-\"` for a root, `\"0-3-\"` below). */\n readonly id: string;\n /** Next number handed out by this scope: component scopes and template root keys share it. */\n count: number;\n /** Number of auto-keyed resources created directly in this scope so far. */\n resources: number;\n}\n\nlet current: HydrationScope | null = null;\n\n/**\n * Creates the scope a render or a hydration starts from: what `renderToString` and `hydrate()` put in\n * effect around the app. A custom renderer that hands out hydration keys does the same.\n *\n * @param renderId The prefix of every key of this render. Default: `\"0\"`, the default `renderId` of\n * the renderers.\n * @returns A fresh scope whose `id` is `` `${renderId}-` ``.\n * @example\n * import { createRootScope, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * const keys = withScope(createRootScope(\"app\"), () => [nextKey(), nextKey()]);\n * // [\"app-0\", \"app-1\"]\n * @see withScope\n * @since 1.0.0\n */\nexport function createRootScope(renderId = \"0\"): HydrationScope {\n return { id: `${renderId}-`, count: 0, resources: 0 };\n}\n\n/**\n * Returns the hydration scope in effect.\n *\n * @returns The current scope; `null` outside a server render, a hydration, or a {@link withScope}\n * call.\n * @example\n * import { currentScope } from \"@shadow-js/web/extend\";\n *\n * function scopeLabel(): string {\n * return currentScope()?.id ?? \"no scope\";\n * }\n * @since 1.0.0\n */\nexport function currentScope(): HydrationScope | null {\n return current;\n}\n\n/**\n * Runs `fn` with `scope` in effect, so the keys `fn` draws come from it. The previous scope is\n * restored when `fn` returns or throws.\n *\n * @param scope The scope to put in effect; `null` runs `fn` with no scope (no keys are drawn).\n * @param fn The code to run, synchronously, once.\n * @returns What `fn` returns. An error `fn` throws propagates.\n * @example\n * import { childScope, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * // The keys of an isolated subtree, independent of its siblings.\n * const first = withScope(childScope(\"0-4\"), () => nextKey()); // \"0-4-0\"\n * @see createRootScope\n * @since 1.0.0\n */\nexport function withScope<T>(scope: HydrationScope | null, fn: () => T): T {\n const previous = current;\n current = scope;\n try {\n return fn();\n } finally {\n current = previous;\n }\n}\n\n/**\n * Runs a component call in a scope of its own, so the keys it draws depend only on its position\n * among its parent's calls: what `createComponent` does on the client and on the server. The\n * component's scope takes the next number of the parent scope.\n *\n * @param fn The component call, run synchronously, once.\n * @returns What `fn` returns. Without a scope in effect, `fn` simply runs.\n * @example\n * import { createRootScope, enterComponent, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * withScope(createRootScope(), () => {\n * nextKey(); // \"0-0\"\n * return enterComponent(() => nextKey()); // \"0-1-0\": the component's first key\n * });\n * @since 1.0.0\n */\nexport function enterComponent<T>(fn: () => T): T {\n const parent = current;\n if (parent === null) return fn();\n return withScope({ id: `${parent.id}${parent.count++}-`, count: 0, resources: 0 }, fn);\n}\n\n/**\n * Draws the key of the next template root in the current scope: what `template()` and\n * `ssrHydrationKey()` call, in the same order on the server and the client. Each call advances the\n * scope.\n *\n * @returns The key (`\"0-0\"`, `\"0-1\"`, ...); undefined outside a scope.\n * @example\n * import { claimElement, nextKey } from \"@shadow-js/web/extend\";\n *\n * function createBadge(): Element {\n * return claimElement(nextKey()) ?? document.createElement(\"span\");\n * }\n * @see claimElement\n * @since 1.0.0\n */\nexport function nextKey(): string | undefined {\n const scope = current;\n if (scope === null) return undefined;\n return `${scope.id}${scope.count++}`;\n}\n\n/**\n * Returns the key a resource's value is stored under in the server data, the same on the server and\n * the client: the explicit key when there is one, else one drawn from the current scope.\n *\n * @param explicit The resource's own key. When given, the result is `` `k:${explicit}` ``, a prefix\n * no generated key has. Undefined draws the next resource key of the scope.\n * @returns `` `k:${explicit}` ``; otherwise the scope id, `r` and the creation index (`\"0-1-r0\"`);\n * `\"r\"` outside a scope.\n * @example\n * import { createRootScope, resourceKey, withScope } from \"@shadow-js/web/extend\";\n *\n * withScope(createRootScope(), () => [resourceKey(undefined), resourceKey(\"user\")]);\n * // [\"0-r0\", \"k:user\"]\n * @since 1.0.0\n */\nexport function resourceKey(explicit: string | undefined): string {\n if (explicit !== undefined) return `k:${explicit}`;\n const scope = current;\n if (scope === null) return \"r\";\n return `${scope.id}r${scope.resources++}`;\n}\n\n/**\n * Creates a fresh scope for an isolated part of the tree, such as a Suspense boundary's content or\n * fallback, or a portal's content: its keys depend only on `key`, not on the siblings around it.\n *\n * @param key The key of the boundary (from `nextKey()`); undefined means no scope.\n * @returns A scope whose `id` is `` `${key}-` ``; `null` when `key` is undefined.\n * @example\n * import { childScope, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * function renderIsolated<T>(build: () => T): T {\n * return withScope(childScope(nextKey()), build);\n * }\n * @see withScope\n * @since 1.0.0\n */\nexport function childScope(key: string | undefined): HydrationScope | null {\n return key === undefined ? null : { id: `${key}-`, count: 0, resources: 0 };\n}\n"],"mappings":";AAkBA,IAAI,UAAiC;;;;;;;;;;;;;;;;AAiBrC,SAAgB,gBAAgB,WAAW,KAAqB;CAC9D,OAAO;EAAE,IAAI,GAAG,SAAS;EAAI,OAAO;EAAG,WAAW;CAAE;AACtD;;;;;;;;;;;;;;AAeA,SAAgB,eAAsC;CACpD,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,SAAgB,UAAa,OAA8B,IAAgB;CACzE,MAAM,WAAW;CACjB,UAAU;CACV,IAAI;EACF,OAAO,GAAG;CACZ,UAAU;EACR,UAAU;CACZ;AACF;;;;;;;;;;;;;;;;;AAkBA,SAAgB,eAAkB,IAAgB;CAChD,MAAM,SAAS;CACf,IAAI,WAAW,MAAM,OAAO,GAAG;CAC/B,OAAO,UAAU;EAAE,IAAI,GAAG,OAAO,KAAK,OAAO,QAAQ;EAAI,OAAO;EAAG,WAAW;CAAE,GAAG,EAAE;AACvF;;;;;;;;;;;;;;;;AAiBA,SAAgB,UAA8B;CAC5C,MAAM,QAAQ;CACd,IAAI,UAAU,MAAM,OAAO,KAAA;CAC3B,OAAO,GAAG,MAAM,KAAK,MAAM;AAC7B;;;;;;;;;;;;;;;;AAiBA,SAAgB,YAAY,UAAsC;CAChE,IAAI,aAAa,KAAA,GAAW,OAAO,KAAK;CACxC,MAAM,QAAQ;CACd,IAAI,UAAU,MAAM,OAAO;CAC3B,OAAO,GAAG,MAAM,GAAG,GAAG,MAAM;AAC9B;;;;;;;;;;;;;;;;AAiBA,SAAgB,WAAW,KAAgD;CACzE,OAAO,QAAQ,KAAA,IAAY,OAAO;EAAE,IAAI,GAAG,IAAI;EAAI,OAAO;EAAG,WAAW;CAAE;AAC5E"}
@@ -0,0 +1,35 @@
1
+ //#region src/internal/names.ts
2
+ /**
3
+ * The XHTML namespace URI: the `namespaceURI` of ordinary HTML elements.
4
+ *
5
+ * @example
6
+ * import { HTML_NS } from "@shadow-js/web/extend";
7
+ *
8
+ * const isHtml = (el: Element): boolean => el.namespaceURI === HTML_NS;
9
+ * @since 1.0.0
10
+ */
11
+ const HTML_NS = "http://www.w3.org/1999/xhtml";
12
+ /**
13
+ * The SVG namespace URI, for `createElementNS` and `namespaceURI` checks.
14
+ *
15
+ * @example
16
+ * import { SVG_NS } from "@shadow-js/web/extend";
17
+ *
18
+ * const circle = document.createElementNS(SVG_NS, "circle");
19
+ * @since 1.0.0
20
+ */
21
+ const SVG_NS = "http://www.w3.org/2000/svg";
22
+ /**
23
+ * The MathML namespace URI, for `createElementNS` and `namespaceURI` checks.
24
+ *
25
+ * @example
26
+ * import { MATHML_NS } from "@shadow-js/web/extend";
27
+ *
28
+ * const fraction = document.createElementNS(MATHML_NS, "mfrac");
29
+ * @since 1.0.0
30
+ */
31
+ const MATHML_NS = "http://www.w3.org/1998/Math/MathML";
32
+ //#endregion
33
+ export { HTML_NS, MATHML_NS, SVG_NS };
34
+
35
+ //# sourceMappingURL=names.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"names.js","names":[],"sources":["../../../src/internal/names.ts"],"sourcesContent":["/**\n * The XHTML namespace URI: the `namespaceURI` of ordinary HTML elements.\n *\n * @example\n * import { HTML_NS } from \"@shadow-js/web/extend\";\n *\n * const isHtml = (el: Element): boolean => el.namespaceURI === HTML_NS;\n * @since 1.0.0\n */\nexport const HTML_NS = \"http://www.w3.org/1999/xhtml\";\n/**\n * The SVG namespace URI, for `createElementNS` and `namespaceURI` checks.\n *\n * @example\n * import { SVG_NS } from \"@shadow-js/web/extend\";\n *\n * const circle = document.createElementNS(SVG_NS, \"circle\");\n * @since 1.0.0\n */\nexport const SVG_NS = \"http://www.w3.org/2000/svg\";\n/**\n * The MathML namespace URI, for `createElementNS` and `namespaceURI` checks.\n *\n * @example\n * import { MATHML_NS } from \"@shadow-js/web/extend\";\n *\n * const fraction = document.createElementNS(MATHML_NS, \"mfrac\");\n * @since 1.0.0\n */\nexport const MATHML_NS = \"http://www.w3.org/1998/Math/MathML\";\n\n/** `template()` flag: the markup is SVG. @internal */\nexport const TEMPLATE_SVG = 1;\n/** `template()` flag: the markup is MathML. @internal */\nexport const TEMPLATE_MATHML = 2;\n/** `template()` flag: clone with `document.importNode` (custom elements). @internal */\nexport const TEMPLATE_IMPORT_NODE = 4;\n"],"mappings":";;;;;;;;;;AASA,MAAa,UAAU;;;;;;;;;;AAUvB,MAAa,SAAS;;;;;;;;;;AAUtB,MAAa,YAAY"}
@@ -0,0 +1,28 @@
1
+ import { createContext } from "@shadow-js/core";
2
+ //#region src/internal/portal-context.ts
3
+ /**
4
+ * The context through which a server render hands portals their collector: the renderers provide it
5
+ * when they are given a `portals` option (see `createServerPortals`). A custom portal reads it on the
6
+ * server and records its markup under its hydration key, so the client's `claimPortal` adopts it.
7
+ * Its value is `null` for every other render, and in the browser, where a portal writes nothing on
8
+ * the server.
9
+ *
10
+ * @example
11
+ * import { useContext } from "@shadow-js/core";
12
+ * import { nextKey, PortalContext } from "@shadow-js/web/extend";
13
+ * import { escape } from "@shadow-js/web/server";
14
+ *
15
+ * function ServerToast(props: { text: string }): null {
16
+ * const key = nextKey();
17
+ * const sink = useContext(PortalContext);
18
+ * if (sink !== null && key !== undefined) sink.add(key, `<div role="status">${escape(props.text)}</div>`);
19
+ * return null;
20
+ * }
21
+ * @see claimPortal
22
+ * @since 1.0.0
23
+ */
24
+ const PortalContext = /* @__PURE__ */ createContext(null, { name: "Portal" });
25
+ //#endregion
26
+ export { PortalContext };
27
+
28
+ //# sourceMappingURL=portal-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal-context.js","names":[],"sources":["../../../src/internal/portal-context.ts"],"sourcesContent":["import { type Context, createContext } from \"@shadow-js/core\";\n\n/**\n * Receives the markup of the portals a server render produces: what {@link PortalContext} provides\n * when the render was given a `portals` collector.\n * @since 1.0.0\n */\nexport interface PortalSink {\n /**\n * Records the markup of the portal with hydration key `key`. A key recorded again replaces the\n * earlier markup. Throws an `SsrError` whose `code` is `SSR_PORTAL_LIMIT` past 256 portals in one\n * render.\n */\n add(key: string, html: string): void;\n}\n\n/**\n * The context through which a server render hands portals their collector: the renderers provide it\n * when they are given a `portals` option (see `createServerPortals`). A custom portal reads it on the\n * server and records its markup under its hydration key, so the client's `claimPortal` adopts it.\n * Its value is `null` for every other render, and in the browser, where a portal writes nothing on\n * the server.\n *\n * @example\n * import { useContext } from \"@shadow-js/core\";\n * import { nextKey, PortalContext } from \"@shadow-js/web/extend\";\n * import { escape } from \"@shadow-js/web/server\";\n *\n * function ServerToast(props: { text: string }): null {\n * const key = nextKey();\n * const sink = useContext(PortalContext);\n * if (sink !== null && key !== undefined) sink.add(key, `<div role=\"status\">${escape(props.text)}</div>`);\n * return null;\n * }\n * @see claimPortal\n * @since 1.0.0\n */\nexport const PortalContext: Context<PortalSink | null> =\n /* @__PURE__ */ createContext<PortalSink | null>(null, {\n name: \"Portal\",\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAqCA,MAAa,gBACK,8BAAiC,MAAM,EACrD,MAAM,SACR,CAAC"}
@@ -0,0 +1,116 @@
1
+ //#region src/internal/react-names.ts
2
+ /**
3
+ * React spellings at run time: the attribute and event names that a props object (a spread) passes
4
+ * through. The compiler resolves the same names at build time (`packages/compiler/src/internal/
5
+ * react-names.ts`); a test keeps the two presentation lists equal, so keep them in step.
6
+ *
7
+ * @internal
8
+ */
9
+ /**
10
+ * SVG presentation attributes are CSS properties, and React spells them in camelCase (`strokeWidth` is
11
+ * `stroke-width`). A camelCase name whose first word is one of these families is hyphenated. The
12
+ * families are the first words of the CSS properties SVG takes as attributes, so one rule covers the
13
+ * presentation list. The compiler's table (`packages/compiler/src/internal/react-names.ts`) lists the
14
+ * same names, and a test checks each one.
15
+ */
16
+ const SVG_PROPERTY_FAMILY = /^(?:alignment|baseline|clip|color|dominant|enable|fill|flood|font|glyph|image|letter|lighting|marker|mask|mix|paint|pointer|shape|stop|stroke|text|transform|unicode|vector|white|word|writing)(?=[A-Z])/;
17
+ /**
18
+ * SVG attributes that start with a property family but are not CSS properties (`clipPathUnits`,
19
+ * `markerWidth`): they are camelCase in SVG, so they keep their case.
20
+ */
21
+ const SVG_CAMEL_ATTRIBUTES = /* @__PURE__ */ new Set([
22
+ "clipPathUnits",
23
+ "glyphRef",
24
+ "markerHeight",
25
+ "markerUnits",
26
+ "markerWidth",
27
+ "maskContentUnits",
28
+ "maskUnits",
29
+ "textLength"
30
+ ]);
31
+ /**
32
+ * The attribute name for a props key on an element: HTML names are lower case (what the parser and
33
+ * `setAttribute` write anyway, and what server markup needs); SVG presentation names are hyphenated,
34
+ * `xlinkHref` and `xmlLang` take their prefix, and other SVG names keep their case (`viewBox`).
35
+ * @internal
36
+ */
37
+ function attributeName(name, svg) {
38
+ if (name === "className") return "class";
39
+ if (name === "htmlFor") return "for";
40
+ if (name === "httpEquiv") return "http-equiv";
41
+ if (name === "acceptCharset") return "accept-charset";
42
+ if (!svg) return name.toLowerCase();
43
+ if (name.includes(":")) return name;
44
+ const xlink = /^xlink([A-Z].*)$/.exec(name);
45
+ if (xlink !== null) return `xlink:${lowerFirst(xlink[1] ?? "")}`;
46
+ const xml = /^xml([A-Z].*)$/.exec(name);
47
+ if (xml !== null) return `xml:${lowerFirst(xml[1] ?? "")}`;
48
+ if (SVG_CAMEL_ATTRIBUTES.has(name) || !SVG_PROPERTY_FAMILY.test(name)) return name;
49
+ return name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
50
+ }
51
+ function lowerFirst(text) {
52
+ return text.replace(/^[A-Z]/, (letter) => letter.toLowerCase());
53
+ }
54
+ /** Props that have no DOM form: a spread ignores them (React's `key` and hydration flags). @internal */
55
+ const IGNORED_KEYS = /* @__PURE__ */ new Set([
56
+ "key",
57
+ "suppressHydrationWarning",
58
+ "suppressContentEditableWarning"
59
+ ]);
60
+ const CHANGE_ON_TYPES = /* @__PURE__ */ new Set([
61
+ "checkbox",
62
+ "radio",
63
+ "file"
64
+ ]);
65
+ /**
66
+ * Plans the DOM event for an `on*` prop. React's spellings follow React: `onChange` is the per-edit
67
+ * `input` event on text inputs and textareas and the `change` event on other controls; `onFocus` and
68
+ * `onBlur` bubble as `focusin` and `focusout`; a `...Capture` suffix binds the capture phase; `onWheel`
69
+ * is passive. A lower-case `on` spelling is the native event.
70
+ * @internal
71
+ */
72
+ function eventPlan(attribute, tag, type) {
73
+ const reactSpelling = /^on[A-Z]/.test(attribute);
74
+ const capture = reactSpelling && attribute.endsWith("Capture");
75
+ const base = attribute.slice(2, capture ? -7 : void 0);
76
+ if (!reactSpelling) return {
77
+ type: base.toLowerCase(),
78
+ capture: false,
79
+ passive: false
80
+ };
81
+ const lower = base.toLowerCase();
82
+ if (lower === "change") return {
83
+ type: tag === "textarea" || tag === "input" && (type === null || !CHANGE_ON_TYPES.has(type)) ? "input" : "change",
84
+ capture,
85
+ passive: false
86
+ };
87
+ if (lower === "focus") return {
88
+ type: "focusin",
89
+ capture,
90
+ passive: false
91
+ };
92
+ if (lower === "blur") return {
93
+ type: "focusout",
94
+ capture,
95
+ passive: false
96
+ };
97
+ if (lower === "doubleclick") return {
98
+ type: "dblclick",
99
+ capture,
100
+ passive: false
101
+ };
102
+ if (lower === "wheel") return {
103
+ type: "wheel",
104
+ capture,
105
+ passive: !capture
106
+ };
107
+ return {
108
+ type: lower,
109
+ capture,
110
+ passive: false
111
+ };
112
+ }
113
+ //#endregion
114
+ export { IGNORED_KEYS, attributeName, eventPlan };
115
+
116
+ //# sourceMappingURL=react-names.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-names.js","names":[],"sources":["../../../src/internal/react-names.ts"],"sourcesContent":["/**\n * React spellings at run time: the attribute and event names that a props object (a spread) passes\n * through. The compiler resolves the same names at build time (`packages/compiler/src/internal/\n * react-names.ts`); a test keeps the two presentation lists equal, so keep them in step.\n *\n * @internal\n */\n\n/**\n * SVG presentation attributes are CSS properties, and React spells them in camelCase (`strokeWidth` is\n * `stroke-width`). A camelCase name whose first word is one of these families is hyphenated. The\n * families are the first words of the CSS properties SVG takes as attributes, so one rule covers the\n * presentation list. The compiler's table (`packages/compiler/src/internal/react-names.ts`) lists the\n * same names, and a test checks each one.\n */\nconst SVG_PROPERTY_FAMILY =\n /^(?:alignment|baseline|clip|color|dominant|enable|fill|flood|font|glyph|image|letter|lighting|marker|mask|mix|paint|pointer|shape|stop|stroke|text|transform|unicode|vector|white|word|writing)(?=[A-Z])/;\n\n/**\n * SVG attributes that start with a property family but are not CSS properties (`clipPathUnits`,\n * `markerWidth`): they are camelCase in SVG, so they keep their case.\n */\nconst SVG_CAMEL_ATTRIBUTES: ReadonlySet<string> = new Set([\n \"clipPathUnits\",\n \"glyphRef\",\n \"markerHeight\",\n \"markerUnits\",\n \"markerWidth\",\n \"maskContentUnits\",\n \"maskUnits\",\n \"textLength\",\n]);\n\n/**\n * The attribute name for a props key on an element: HTML names are lower case (what the parser and\n * `setAttribute` write anyway, and what server markup needs); SVG presentation names are hyphenated,\n * `xlinkHref` and `xmlLang` take their prefix, and other SVG names keep their case (`viewBox`).\n * @internal\n */\nexport function attributeName(name: string, svg: boolean): string {\n if (name === \"className\") return \"class\";\n if (name === \"htmlFor\") return \"for\";\n if (name === \"httpEquiv\") return \"http-equiv\";\n if (name === \"acceptCharset\") return \"accept-charset\";\n if (!svg) return name.toLowerCase();\n if (name.includes(\":\")) return name;\n const xlink = /^xlink([A-Z].*)$/.exec(name);\n if (xlink !== null) return `xlink:${lowerFirst(xlink[1] ?? \"\")}`;\n const xml = /^xml([A-Z].*)$/.exec(name);\n if (xml !== null) return `xml:${lowerFirst(xml[1] ?? \"\")}`;\n if (SVG_CAMEL_ATTRIBUTES.has(name) || !SVG_PROPERTY_FAMILY.test(name)) return name;\n return name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n}\n\nfunction lowerFirst(text: string): string {\n return text.replace(/^[A-Z]/, (letter) => letter.toLowerCase());\n}\n\n/** Props that have no DOM form: a spread ignores them (React's `key` and hydration flags). @internal */\nexport const IGNORED_KEYS: ReadonlySet<string> = new Set([\n \"key\",\n \"suppressHydrationWarning\",\n \"suppressContentEditableWarning\",\n]);\n\n/** The DOM event for a React-spelled prop (see the compiler's `eventPlan`). @internal */\nexport interface EventPlan {\n readonly type: string;\n readonly capture: boolean;\n readonly passive: boolean;\n}\n\nconst CHANGE_ON_TYPES: ReadonlySet<string> = new Set([\"checkbox\", \"radio\", \"file\"]);\n\n/**\n * Plans the DOM event for an `on*` prop. React's spellings follow React: `onChange` is the per-edit\n * `input` event on text inputs and textareas and the `change` event on other controls; `onFocus` and\n * `onBlur` bubble as `focusin` and `focusout`; a `...Capture` suffix binds the capture phase; `onWheel`\n * is passive. A lower-case `on` spelling is the native event.\n * @internal\n */\nexport function eventPlan(attribute: string, tag: string, type: string | null): EventPlan {\n const reactSpelling = /^on[A-Z]/.test(attribute);\n const capture = reactSpelling && attribute.endsWith(\"Capture\");\n const base = attribute.slice(2, capture ? -\"Capture\".length : undefined);\n if (!reactSpelling) return { type: base.toLowerCase(), capture: false, passive: false };\n const lower = base.toLowerCase();\n if (lower === \"change\") {\n const perEdit =\n tag === \"textarea\" || (tag === \"input\" && (type === null || !CHANGE_ON_TYPES.has(type)));\n return { type: perEdit ? \"input\" : \"change\", capture, passive: false };\n }\n if (lower === \"focus\") return { type: \"focusin\", capture, passive: false };\n if (lower === \"blur\") return { type: \"focusout\", capture, passive: false };\n if (lower === \"doubleclick\") return { type: \"dblclick\", capture, passive: false };\n if (lower === \"wheel\") return { type: \"wheel\", capture, passive: !capture };\n return { type: lower, capture, passive: false };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAM,sBACJ;;;;;AAMF,MAAM,uCAA4C,IAAI,IAAI;CACxD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;;AAQD,SAAgB,cAAc,MAAc,KAAsB;CAChE,IAAI,SAAS,aAAa,OAAO;CACjC,IAAI,SAAS,WAAW,OAAO;CAC/B,IAAI,SAAS,aAAa,OAAO;CACjC,IAAI,SAAS,iBAAiB,OAAO;CACrC,IAAI,CAAC,KAAK,OAAO,KAAK,YAAY;CAClC,IAAI,KAAK,SAAS,GAAG,GAAG,OAAO;CAC/B,MAAM,QAAQ,mBAAmB,KAAK,IAAI;CAC1C,IAAI,UAAU,MAAM,OAAO,SAAS,WAAW,MAAM,MAAM,EAAE;CAC7D,MAAM,MAAM,iBAAiB,KAAK,IAAI;CACtC,IAAI,QAAQ,MAAM,OAAO,OAAO,WAAW,IAAI,MAAM,EAAE;CACvD,IAAI,qBAAqB,IAAI,IAAI,KAAK,CAAC,oBAAoB,KAAK,IAAI,GAAG,OAAO;CAC9E,OAAO,KAAK,QAAQ,WAAW,WAAW,IAAI,OAAO,YAAY,GAAG;AACtE;AAEA,SAAS,WAAW,MAAsB;CACxC,OAAO,KAAK,QAAQ,WAAW,WAAW,OAAO,YAAY,CAAC;AAChE;;AAGA,MAAa,+BAAoC,IAAI,IAAI;CACvD;CACA;CACA;AACF,CAAC;AASD,MAAM,kCAAuC,IAAI,IAAI;CAAC;CAAY;CAAS;AAAM,CAAC;;;;;;;;AASlF,SAAgB,UAAU,WAAmB,KAAa,MAAgC;CACxF,MAAM,gBAAgB,WAAW,KAAK,SAAS;CAC/C,MAAM,UAAU,iBAAiB,UAAU,SAAS,SAAS;CAC7D,MAAM,OAAO,UAAU,MAAM,GAAG,UAAU,KAAoB,KAAA,CAAS;CACvE,IAAI,CAAC,eAAe,OAAO;EAAE,MAAM,KAAK,YAAY;EAAG,SAAS;EAAO,SAAS;CAAM;CACtF,MAAM,QAAQ,KAAK,YAAY;CAC/B,IAAI,UAAU,UAGZ,OAAO;EAAE,MADP,QAAQ,cAAe,QAAQ,YAAY,SAAS,QAAQ,CAAC,gBAAgB,IAAI,IAAI,KAC9D,UAAU;EAAU;EAAS,SAAS;CAAM;CAEvE,IAAI,UAAU,SAAS,OAAO;EAAE,MAAM;EAAW;EAAS,SAAS;CAAM;CACzE,IAAI,UAAU,QAAQ,OAAO;EAAE,MAAM;EAAY;EAAS,SAAS;CAAM;CACzE,IAAI,UAAU,eAAe,OAAO;EAAE,MAAM;EAAY;EAAS,SAAS;CAAM;CAChF,IAAI,UAAU,SAAS,OAAO;EAAE,MAAM;EAAS;EAAS,SAAS,CAAC;CAAQ;CAC1E,OAAO;EAAE,MAAM;EAAO;EAAS,SAAS;CAAM;AAChD"}
@@ -0,0 +1,122 @@
1
+ //#region src/internal/reconcile.ts
2
+ /** Removes `node` only when it is still a child of `parent`, so detached nodes are ignored. */
3
+ function removeNode(parent, node) {
4
+ if (node !== void 0 && node.parentNode === parent) parent.removeChild(node);
5
+ }
6
+ /**
7
+ * Marks the members of one longest strictly increasing subsequence of `values` in `marks`, where
8
+ * `values[k]` is the target position of the k-th surviving node and `marks[v - offset]` is set for
9
+ * target position `v`. Patience sorting: O(n log n).
10
+ */
11
+ function markLongestIncreasing(values, offset, marks) {
12
+ const tails = [];
13
+ const previous = values.map(() => -1);
14
+ for (let index = 0; index < values.length; index += 1) {
15
+ const value = values[index] ?? 0;
16
+ let low = 0;
17
+ let high = tails.length;
18
+ while (low < high) {
19
+ const middle = low + high >> 1;
20
+ if ((values[tails[middle] ?? 0] ?? 0) < value) low = middle + 1;
21
+ else high = middle;
22
+ }
23
+ previous[index] = low > 0 ? tails[low - 1] ?? -1 : -1;
24
+ tails[low] = index;
25
+ }
26
+ let cursor = tails.length > 0 ? tails[tails.length - 1] ?? -1 : -1;
27
+ while (cursor !== -1) {
28
+ marks[(values[cursor] ?? 0) - offset] = 1;
29
+ cursor = previous[cursor] ?? -1;
30
+ }
31
+ }
32
+ /**
33
+ * Updates one region of `parent`'s children from the nodes `prev` to the nodes `next`, keeping every
34
+ * node that stays and moving as few as possible: the list reconciliation `insert` performs for arrays
35
+ * (and so for `For`). Use it in a custom list renderer.
36
+ *
37
+ * Preconditions: `prev` are the nodes this region owns, in DOM order and all children of `parent`;
38
+ * `next` holds no duplicates; `end` is the node after the region (null for the end of `parent`).
39
+ *
40
+ * Strategy, in three steps:
41
+ * 1. Trim the common prefix and suffix: appends, prepends, and removals at either end touch
42
+ * only the nodes that changed (no move at all).
43
+ * 2. Remove the nodes that left the value. A node that is still present is never removed.
44
+ * 3. Place the rest from the end of `next` backwards. Nodes on a longest increasing subsequence of
45
+ * surviving positions stay where they are; every other node is moved (or inserted) directly
46
+ * before the node that follows it in `next`. Moves use `moveBefore` when the parent has it,
47
+ * which keeps focus and iframe state, and `insertBefore` otherwise. Each node moves at most once,
48
+ * and the number of moves is minimal for the surviving order.
49
+ *
50
+ * @param parent The parent of the region.
51
+ * @param prev The nodes the region holds now, in DOM order, all children of `parent`.
52
+ * @param next The nodes the region must hold, in order, without duplicates. A node of `prev` that is
53
+ * not in `next` is removed; a node of `next` that is not in `prev` is inserted.
54
+ * @param end The node right after the region; `null` when the region runs to the end of `parent`.
55
+ * @example
56
+ * import { reconcileNodes } from "@shadow-js/web/extend";
57
+ *
58
+ * const item = (text: string): HTMLLIElement =>
59
+ * Object.assign(document.createElement("li"), { textContent: text });
60
+ * const list = document.createElement("ul");
61
+ * const a = item("a");
62
+ * const b = item("b");
63
+ * const c = item("c");
64
+ * list.append(a, b, c);
65
+ * reconcileNodes(list, [a, b, c], [c, a], null); // removes b, moves c before a
66
+ * @since 1.0.0
67
+ */
68
+ function reconcileNodes(parent, prev, next, end) {
69
+ const prevLength = prev.length;
70
+ const nextLength = next.length;
71
+ let head = 0;
72
+ while (head < prevLength && head < nextLength && prev[head] === next[head]) head += 1;
73
+ let prevTail = prevLength;
74
+ let nextTail = nextLength;
75
+ while (prevTail > head && nextTail > head && prev[prevTail - 1] === next[nextTail - 1]) {
76
+ prevTail -= 1;
77
+ nextTail -= 1;
78
+ }
79
+ if (prevTail === head && nextTail === head) return;
80
+ const before = nextTail < nextLength ? next[nextTail] ?? null : end;
81
+ if (nextTail === head) {
82
+ for (let index = head; index < prevTail; index += 1) removeNode(parent, prev[index]);
83
+ return;
84
+ }
85
+ const target = /* @__PURE__ */ new Map();
86
+ for (let index = head; index < nextTail; index += 1) {
87
+ const node = next[index];
88
+ if (node !== void 0) target.set(node, index);
89
+ }
90
+ const survivors = [];
91
+ for (let index = head; index < prevTail; index += 1) {
92
+ const node = prev[index];
93
+ if (node === void 0) continue;
94
+ const position = target.get(node);
95
+ if (position === void 0) removeNode(parent, node);
96
+ else survivors.push(position);
97
+ }
98
+ if (survivors.length === 0) {
99
+ for (let index = head; index < nextTail; index += 1) {
100
+ const node = next[index];
101
+ if (node !== void 0) parent.insertBefore(node, before);
102
+ }
103
+ return;
104
+ }
105
+ const stable = new Uint8Array(nextTail - head);
106
+ markLongestIncreasing(survivors, head, stable);
107
+ const movable = typeof parent.moveBefore === "function";
108
+ let anchorNode = before;
109
+ for (let index = nextTail - 1; index >= head; index -= 1) {
110
+ const node = next[index];
111
+ if (node === void 0) continue;
112
+ if (stable[index - head] !== 1) {
113
+ if (movable && node.parentNode === parent) parent.moveBefore(node, anchorNode);
114
+ else parent.insertBefore(node, anchorNode);
115
+ }
116
+ anchorNode = node;
117
+ }
118
+ }
119
+ //#endregion
120
+ export { reconcileNodes };
121
+
122
+ //# sourceMappingURL=reconcile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconcile.js","names":[],"sources":["../../../src/internal/reconcile.ts"],"sourcesContent":["/** A parent that can move a child in place (Element.prototype.moveBefore, where implemented). */\ninterface MovableParent extends Node {\n moveBefore(node: Node, child: Node | null): void;\n}\n\n/** Removes `node` only when it is still a child of `parent`, so detached nodes are ignored. */\nfunction removeNode(parent: Node, node: Node | undefined): void {\n if (node !== undefined && node.parentNode === parent) parent.removeChild(node);\n}\n\n/**\n * Marks the members of one longest strictly increasing subsequence of `values` in `marks`, where\n * `values[k]` is the target position of the k-th surviving node and `marks[v - offset]` is set for\n * target position `v`. Patience sorting: O(n log n).\n */\nfunction markLongestIncreasing(values: readonly number[], offset: number, marks: Uint8Array): void {\n // tails[k]: index into `values` of the smallest tail of an increasing run of length k + 1.\n const tails: number[] = [];\n const previous: number[] = values.map(() => -1);\n for (let index = 0; index < values.length; index += 1) {\n const value = values[index] ?? 0;\n let low = 0;\n let high = tails.length;\n while (low < high) {\n const middle = (low + high) >> 1;\n const probe = values[tails[middle] ?? 0] ?? 0;\n if (probe < value) low = middle + 1;\n else high = middle;\n }\n previous[index] = low > 0 ? (tails[low - 1] ?? -1) : -1;\n tails[low] = index;\n }\n let cursor = tails.length > 0 ? (tails[tails.length - 1] ?? -1) : -1;\n while (cursor !== -1) {\n marks[(values[cursor] ?? 0) - offset] = 1;\n cursor = previous[cursor] ?? -1;\n }\n}\n\n/**\n * Updates one region of `parent`'s children from the nodes `prev` to the nodes `next`, keeping every\n * node that stays and moving as few as possible: the list reconciliation `insert` performs for arrays\n * (and so for `For`). Use it in a custom list renderer.\n *\n * Preconditions: `prev` are the nodes this region owns, in DOM order and all children of `parent`;\n * `next` holds no duplicates; `end` is the node after the region (null for the end of `parent`).\n *\n * Strategy, in three steps:\n * 1. Trim the common prefix and suffix: appends, prepends, and removals at either end touch\n * only the nodes that changed (no move at all).\n * 2. Remove the nodes that left the value. A node that is still present is never removed.\n * 3. Place the rest from the end of `next` backwards. Nodes on a longest increasing subsequence of\n * surviving positions stay where they are; every other node is moved (or inserted) directly\n * before the node that follows it in `next`. Moves use `moveBefore` when the parent has it,\n * which keeps focus and iframe state, and `insertBefore` otherwise. Each node moves at most once,\n * and the number of moves is minimal for the surviving order.\n *\n * @param parent The parent of the region.\n * @param prev The nodes the region holds now, in DOM order, all children of `parent`.\n * @param next The nodes the region must hold, in order, without duplicates. A node of `prev` that is\n * not in `next` is removed; a node of `next` that is not in `prev` is inserted.\n * @param end The node right after the region; `null` when the region runs to the end of `parent`.\n * @example\n * import { reconcileNodes } from \"@shadow-js/web/extend\";\n *\n * const item = (text: string): HTMLLIElement =>\n * Object.assign(document.createElement(\"li\"), { textContent: text });\n * const list = document.createElement(\"ul\");\n * const a = item(\"a\");\n * const b = item(\"b\");\n * const c = item(\"c\");\n * list.append(a, b, c);\n * reconcileNodes(list, [a, b, c], [c, a], null); // removes b, moves c before a\n * @since 1.0.0\n */\nexport function reconcileNodes(\n parent: Node,\n prev: readonly Node[],\n next: readonly Node[],\n end: Node | null,\n): void {\n const prevLength = prev.length;\n const nextLength = next.length;\n\n let head = 0;\n while (head < prevLength && head < nextLength && prev[head] === next[head]) head += 1;\n let prevTail = prevLength;\n let nextTail = nextLength;\n while (prevTail > head && nextTail > head && prev[prevTail - 1] === next[nextTail - 1]) {\n prevTail -= 1;\n nextTail -= 1;\n }\n if (prevTail === head && nextTail === head) return;\n\n // Everything in the common suffix is already in place, so the middle goes before its first node.\n const before = nextTail < nextLength ? (next[nextTail] ?? null) : end;\n\n if (nextTail === head) {\n for (let index = head; index < prevTail; index += 1) removeNode(parent, prev[index]);\n return;\n }\n\n const target = new Map<Node, number>();\n for (let index = head; index < nextTail; index += 1) {\n const node = next[index];\n if (node !== undefined) target.set(node, index);\n }\n\n const survivors: number[] = [];\n for (let index = head; index < prevTail; index += 1) {\n const node = prev[index];\n if (node === undefined) continue;\n const position = target.get(node);\n if (position === undefined) removeNode(parent, node);\n else survivors.push(position);\n }\n\n if (survivors.length === 0) {\n for (let index = head; index < nextTail; index += 1) {\n const node = next[index];\n if (node !== undefined) parent.insertBefore(node, before);\n }\n return;\n }\n\n const stable = new Uint8Array(nextTail - head);\n markLongestIncreasing(survivors, head, stable);\n const movable = typeof (parent as Partial<MovableParent>).moveBefore === \"function\";\n\n let anchorNode = before;\n for (let index = nextTail - 1; index >= head; index -= 1) {\n const node = next[index];\n if (node === undefined) continue;\n if (stable[index - head] !== 1) {\n if (movable && node.parentNode === parent)\n (parent as MovableParent).moveBefore(node, anchorNode);\n else parent.insertBefore(node, anchorNode);\n }\n anchorNode = node;\n }\n}\n"],"mappings":";;AAMA,SAAS,WAAW,QAAc,MAA8B;CAC9D,IAAI,SAAS,KAAA,KAAa,KAAK,eAAe,QAAQ,OAAO,YAAY,IAAI;AAC/E;;;;;;AAOA,SAAS,sBAAsB,QAA2B,QAAgB,OAAyB;CAEjG,MAAM,QAAkB,CAAC;CACzB,MAAM,WAAqB,OAAO,UAAU,EAAE;CAC9C,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS,GAAG;EACrD,MAAM,QAAQ,OAAO,UAAU;EAC/B,IAAI,MAAM;EACV,IAAI,OAAO,MAAM;EACjB,OAAO,MAAM,MAAM;GACjB,MAAM,SAAU,MAAM,QAAS;GAE/B,KADc,OAAO,MAAM,WAAW,MAAM,KAChC,OAAO,MAAM,SAAS;QAC7B,OAAO;EACd;EACA,SAAS,SAAS,MAAM,IAAK,MAAM,MAAM,MAAM,KAAM;EACrD,MAAM,OAAO;CACf;CACA,IAAI,SAAS,MAAM,SAAS,IAAK,MAAM,MAAM,SAAS,MAAM,KAAM;CAClE,OAAO,WAAW,IAAI;EACpB,OAAO,OAAO,WAAW,KAAK,UAAU;EACxC,SAAS,SAAS,WAAW;CAC/B;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,eACd,QACA,MACA,MACA,KACM;CACN,MAAM,aAAa,KAAK;CACxB,MAAM,aAAa,KAAK;CAExB,IAAI,OAAO;CACX,OAAO,OAAO,cAAc,OAAO,cAAc,KAAK,UAAU,KAAK,OAAO,QAAQ;CACpF,IAAI,WAAW;CACf,IAAI,WAAW;CACf,OAAO,WAAW,QAAQ,WAAW,QAAQ,KAAK,WAAW,OAAO,KAAK,WAAW,IAAI;EACtF,YAAY;EACZ,YAAY;CACd;CACA,IAAI,aAAa,QAAQ,aAAa,MAAM;CAG5C,MAAM,SAAS,WAAW,aAAc,KAAK,aAAa,OAAQ;CAElE,IAAI,aAAa,MAAM;EACrB,KAAK,IAAI,QAAQ,MAAM,QAAQ,UAAU,SAAS,GAAG,WAAW,QAAQ,KAAK,MAAM;EACnF;CACF;CAEA,MAAM,yBAAS,IAAI,IAAkB;CACrC,KAAK,IAAI,QAAQ,MAAM,QAAQ,UAAU,SAAS,GAAG;EACnD,MAAM,OAAO,KAAK;EAClB,IAAI,SAAS,KAAA,GAAW,OAAO,IAAI,MAAM,KAAK;CAChD;CAEA,MAAM,YAAsB,CAAC;CAC7B,KAAK,IAAI,QAAQ,MAAM,QAAQ,UAAU,SAAS,GAAG;EACnD,MAAM,OAAO,KAAK;EAClB,IAAI,SAAS,KAAA,GAAW;EACxB,MAAM,WAAW,OAAO,IAAI,IAAI;EAChC,IAAI,aAAa,KAAA,GAAW,WAAW,QAAQ,IAAI;OAC9C,UAAU,KAAK,QAAQ;CAC9B;CAEA,IAAI,UAAU,WAAW,GAAG;EAC1B,KAAK,IAAI,QAAQ,MAAM,QAAQ,UAAU,SAAS,GAAG;GACnD,MAAM,OAAO,KAAK;GAClB,IAAI,SAAS,KAAA,GAAW,OAAO,aAAa,MAAM,MAAM;EAC1D;EACA;CACF;CAEA,MAAM,SAAS,IAAI,WAAW,WAAW,IAAI;CAC7C,sBAAsB,WAAW,MAAM,MAAM;CAC7C,MAAM,UAAU,OAAQ,OAAkC,eAAe;CAEzE,IAAI,aAAa;CACjB,KAAK,IAAI,QAAQ,WAAW,GAAG,SAAS,MAAM,SAAS,GAAG;EACxD,MAAM,OAAO,KAAK;EAClB,IAAI,SAAS,KAAA,GAAW;EACxB,IAAI,OAAO,QAAQ,UAAU,GAAG;GAC9B,IAAI,WAAW,KAAK,eAAe,QACjC,OAA0B,WAAW,MAAM,UAAU;QAClD,OAAO,aAAa,MAAM,UAAU;EAC3C;EACA,aAAa;CACf;AACF"}
@@ -0,0 +1,23 @@
1
+ import { createContext } from "@shadow-js/core";
2
+ //#region src/internal/stream-context.ts
3
+ /**
4
+ * The context through which `renderToStream` lets a Suspense-like boundary defer its content: a
5
+ * boundary that is pending in the shell renders its fallback between `<!--[b:ID-->` and `<!--]-->`
6
+ * and defers a {@link StreamBoundary} to the sink. Its value is `null` for every other render (the
7
+ * boundary then keeps its fallback).
8
+ *
9
+ * @example
10
+ * import { useContext } from "@shadow-js/core";
11
+ * import { StreamContext } from "@shadow-js/web/extend";
12
+ *
13
+ * function canStream(): boolean {
14
+ * // Inside a component rendered by renderToStream.
15
+ * return useContext(StreamContext) !== null;
16
+ * }
17
+ * @since 1.0.0
18
+ */
19
+ const StreamContext = /* @__PURE__ */ createContext(null, { name: "Stream" });
20
+ //#endregion
21
+ export { StreamContext };
22
+
23
+ //# sourceMappingURL=stream-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-context.js","names":[],"sources":["../../../src/internal/stream-context.ts"],"sourcesContent":["import { type Context, createContext } from \"@shadow-js/core\";\n\n/**\n * A Suspense boundary whose content was not ready when the shell rendered: `renderToStream` calls\n * `rebuild` again each time a resource settles, and streams the markup once it is complete.\n * @since 1.0.0\n */\nexport interface StreamBoundary {\n /**\n * The boundary's hydration key. The shell must wrap the fallback in `<!--[b:ID-->` and `<!--]-->`\n * comments so the streamed chunk can replace it.\n */\n readonly id: string;\n /**\n * Renders the content again. Returns its final markup, or `null` when it is still pending, in which\n * case it has deferred itself again with {@link StreamSink.defer}.\n */\n rebuild(): string | null;\n}\n\n/**\n * Receives the boundaries that are still pending during a streaming render: what\n * {@link StreamContext} provides.\n * @since 1.0.0\n */\nexport interface StreamSink {\n /** Queues `boundary` to be rebuilt when the next resource settles. */\n defer(boundary: StreamBoundary): void;\n}\n\n/**\n * The context through which `renderToStream` lets a Suspense-like boundary defer its content: a\n * boundary that is pending in the shell renders its fallback between `<!--[b:ID-->` and `<!--]-->`\n * and defers a {@link StreamBoundary} to the sink. Its value is `null` for every other render (the\n * boundary then keeps its fallback).\n *\n * @example\n * import { useContext } from \"@shadow-js/core\";\n * import { StreamContext } from \"@shadow-js/web/extend\";\n *\n * function canStream(): boolean {\n * // Inside a component rendered by renderToStream.\n * return useContext(StreamContext) !== null;\n * }\n * @since 1.0.0\n */\nexport const StreamContext: Context<StreamSink | null> =\n /* @__PURE__ */ createContext<StreamSink | null>(null, {\n name: \"Stream\",\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;AA8CA,MAAa,gBACK,8BAAiC,MAAM,EACrD,MAAM,SACR,CAAC"}
@@ -0,0 +1,85 @@
1
+ import { getOwner, onCleanup, untrack, useMemo, useRenderEffect } from "@shadow-js/core";
2
+ //#region src/reactive.ts
3
+ function effect(compute, apply) {
4
+ if (apply === void 0) useRenderEffect(compute);
5
+ else useRenderEffect(compute, apply);
6
+ }
7
+ /**
8
+ * Creates a cached derivation that recomputes only when the signals it reads change. It is core's
9
+ * `useMemo` under the short name the compiler emits.
10
+ *
11
+ * @param fn The computation. Tracked; its result is cached until a dependency changes.
12
+ * @returns An accessor for the current value.
13
+ * @example
14
+ * import { useSignal } from "@shadow-js/core";
15
+ * import { memo } from "@shadow-js/web";
16
+ *
17
+ * function setup() {
18
+ * const [count, setCount] = useSignal(2);
19
+ * const doubled = memo(() => count() * 2);
20
+ * setCount(4);
21
+ * console.log(doubled()); // 8
22
+ * }
23
+ * @see effect
24
+ * @since 1.0.0
25
+ */
26
+ function memo(fn) {
27
+ return useMemo(fn);
28
+ }
29
+ /**
30
+ * Applies a directive: calls `fn(el, arg)` untracked, so a directive or a ref never subscribes the
31
+ * surrounding effect to what it reads. A function returned by `fn` is a cleanup, run when the owner
32
+ * disposes.
33
+ *
34
+ * @param fn The directive. Receives the element and the accessor of its argument.
35
+ * @param el The element the directive applies to.
36
+ * @param arg Accessor for the directive's argument. Undefined passes `undefined` through; the
37
+ * directive reads the accessor where it wants to track it.
38
+ * @example
39
+ * import { use } from "@shadow-js/web";
40
+ *
41
+ * function tooltip(el: Element, text: () => string) {
42
+ * el.setAttribute("title", text());
43
+ * }
44
+ * const button = document.createElement("button");
45
+ * use(tooltip, button, () => "Save the draft");
46
+ * @see refTo
47
+ * @since 1.0.0
48
+ */
49
+ function use(fn, el, arg) {
50
+ const cleanup = untrack(() => fn(el, arg));
51
+ if (typeof cleanup === "function") onCleanup(cleanup);
52
+ }
53
+ /**
54
+ * Fills a ref of any form the compiler accepts. A callback is called with the element (its returned
55
+ * cleanup runs when the owner disposes). A `{ current }` object gets the element as `current`, and
56
+ * `null` once the owner is disposed, as React's `useRef` objects do. Any other value is ignored.
57
+ *
58
+ * @param target The ref value: a callback, a `{ current }` object, or anything else (ignored).
59
+ * @param el The element the ref receives.
60
+ * @example
61
+ * import { refTo } from "@shadow-js/web";
62
+ *
63
+ * const box = { current: null as HTMLDivElement | null };
64
+ * const div = document.createElement("div");
65
+ * refTo(box, div);
66
+ * console.log(box.current === div); // true
67
+ * @see use
68
+ * @since 1.0.0
69
+ */
70
+ function refTo(target, el) {
71
+ if (typeof target === "function") {
72
+ use(target, el);
73
+ return;
74
+ }
75
+ if (target === null || typeof target !== "object" || !("current" in target)) return;
76
+ const holder = target;
77
+ holder.current = el;
78
+ if (getOwner() !== null) onCleanup(() => {
79
+ holder.current = null;
80
+ });
81
+ }
82
+ //#endregion
83
+ export { effect, memo, refTo, use };
84
+
85
+ //# sourceMappingURL=reactive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactive.js","names":[],"sources":["../../src/reactive.ts"],"sourcesContent":["import {\n type Cleanup,\n getOwner,\n onCleanup,\n untrack,\n useMemo,\n useRenderEffect,\n} from \"@shadow-js/core\";\n\n/**\n * Runs `fn` as a render effect: synchronously when created, and again when the signals it reads\n * change. It is the effect the compiler emits for DOM bindings; application code usually prefers\n * `useEffect`. A function returned by `fn` is its cleanup, run before the next run and when the\n * owner disposes. It never runs on the server, and in development an effect created outside an\n * owner warns `NO_OWNER_EFFECT`.\n *\n * @param fn Tracked body. Returns an optional cleanup function.\n * @example\n * import { createRoot, useSignal } from \"@shadow-js/core\";\n * import { effect } from \"@shadow-js/web\";\n *\n * const label = document.createElement(\"span\");\n * createRoot(() => {\n * const [name] = useSignal(\"Ada\");\n * effect(() => {\n * label.textContent = name(); // runs now, and again when name changes\n * });\n * });\n * @see memo\n * @since 1.0.0\n */\nexport function effect(fn: () => void | Cleanup): void;\n/**\n * Two-form render effect: `compute` is tracked and `apply` runs untracked with the new and the\n * previous value. A function returned by `apply` is its cleanup. Use it to keep the tracked reads\n * apart from the code that writes the DOM.\n *\n * @param compute Tracked. Its result is passed to `apply`.\n * @param apply Untracked. Receives the value and the previous value (`undefined` on the first run)\n * and returns an optional cleanup function.\n * @example\n * import { createRoot, useSignal } from \"@shadow-js/core\";\n * import { effect } from \"@shadow-js/web\";\n *\n * const title = document.createElement(\"h1\");\n * createRoot(() => {\n * const [text] = useSignal(\"Hello\");\n * effect(text, (value, previous) => {\n * title.textContent = value;\n * console.log(previous); // undefined on the first run\n * });\n * });\n * @see memo\n * @since 1.0.0\n */\nexport function effect<T>(\n compute: () => T,\n apply: (value: T, previous: T | undefined) => void | Cleanup,\n): void;\nexport function effect<T>(\n compute: () => T,\n apply?: (value: T, previous: T | undefined) => void | Cleanup,\n): void {\n if (apply === undefined) useRenderEffect(compute);\n else useRenderEffect(compute, apply);\n}\n\n/**\n * Creates a cached derivation that recomputes only when the signals it reads change. It is core's\n * `useMemo` under the short name the compiler emits.\n *\n * @param fn The computation. Tracked; its result is cached until a dependency changes.\n * @returns An accessor for the current value.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { memo } from \"@shadow-js/web\";\n *\n * function setup() {\n * const [count, setCount] = useSignal(2);\n * const doubled = memo(() => count() * 2);\n * setCount(4);\n * console.log(doubled()); // 8\n * }\n * @see effect\n * @since 1.0.0\n */\nexport function memo<T>(fn: () => T): () => T {\n return useMemo<T>(fn);\n}\n\n/**\n * Applies a directive: calls `fn(el, arg)` untracked, so a directive or a ref never subscribes the\n * surrounding effect to what it reads. A function returned by `fn` is a cleanup, run when the owner\n * disposes.\n *\n * @param fn The directive. Receives the element and the accessor of its argument.\n * @param el The element the directive applies to.\n * @param arg Accessor for the directive's argument. Undefined passes `undefined` through; the\n * directive reads the accessor where it wants to track it.\n * @example\n * import { use } from \"@shadow-js/web\";\n *\n * function tooltip(el: Element, text: () => string) {\n * el.setAttribute(\"title\", text());\n * }\n * const button = document.createElement(\"button\");\n * use(tooltip, button, () => \"Save the draft\");\n * @see refTo\n * @since 1.0.0\n */\nexport function use<T>(\n fn: (el: Element, arg: () => T) => unknown,\n el: Element,\n arg?: () => T,\n): void {\n const cleanup = untrack(() => fn(el, arg as () => T));\n // A ref callback may return a cleanup (React 19): it runs when the owner of the element is disposed.\n if (typeof cleanup === \"function\") onCleanup(cleanup as Cleanup);\n}\n\n/**\n * Fills a ref of any form the compiler accepts. A callback is called with the element (its returned\n * cleanup runs when the owner disposes). A `{ current }` object gets the element as `current`, and\n * `null` once the owner is disposed, as React's `useRef` objects do. Any other value is ignored.\n *\n * @param target The ref value: a callback, a `{ current }` object, or anything else (ignored).\n * @param el The element the ref receives.\n * @example\n * import { refTo } from \"@shadow-js/web\";\n *\n * const box = { current: null as HTMLDivElement | null };\n * const div = document.createElement(\"div\");\n * refTo(box, div);\n * console.log(box.current === div); // true\n * @see use\n * @since 1.0.0\n */\nexport function refTo(target: unknown, el: Element): void {\n if (typeof target === \"function\") {\n use(target as (node: Element, arg: () => unknown) => unknown, el);\n return;\n }\n if (target === null || typeof target !== \"object\" || !(\"current\" in target)) return;\n const holder = target as { current: unknown };\n holder.current = el;\n if (getOwner() !== null) {\n onCleanup(() => {\n holder.current = null;\n });\n }\n}\n"],"mappings":";;AA2DA,SAAgB,OACd,SACA,OACM;CACN,IAAI,UAAU,KAAA,GAAW,gBAAgB,OAAO;MAC3C,gBAAgB,SAAS,KAAK;AACrC;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,KAAQ,IAAsB;CAC5C,OAAO,QAAW,EAAE;AACtB;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,IACd,IACA,IACA,KACM;CACN,MAAM,UAAU,cAAc,GAAG,IAAI,GAAc,CAAC;CAEpD,IAAI,OAAO,YAAY,YAAY,UAAU,OAAkB;AACjE;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,MAAM,QAAiB,IAAmB;CACxD,IAAI,OAAO,WAAW,YAAY;EAChC,IAAI,QAA0D,EAAE;EAChE;CACF;CACA,IAAI,WAAW,QAAQ,OAAO,WAAW,YAAY,EAAE,aAAa,SAAS;CAC7E,MAAM,SAAS;CACf,OAAO,UAAU;CACjB,IAAI,SAAS,MAAM,MACjB,gBAAgB;EACd,OAAO,UAAU;CACnB,CAAC;AAEL"}