@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,170 @@
1
+ import { useHead } from "./use-head.js";
2
+ //#region src/head/components.ts
3
+ /** Text of a value that may be an accessor. Anything but text or an array of text throws. */
4
+ function partText(value) {
5
+ if (typeof value === "string") return value;
6
+ if (typeof value === "number") return String(value);
7
+ if (value === void 0 || value === null || value === false) return "";
8
+ throw new TypeError("ShadowJS head: Title children must be text.");
9
+ }
10
+ /** The text a Title shows. An accessor is called once, so its reads are tracked by the caller. */
11
+ function textOf(value) {
12
+ const resolved = typeof value === "function" ? value() : value;
13
+ if (Array.isArray(resolved)) return resolved.map(partText).join("");
14
+ return partText(resolved);
15
+ }
16
+ /** The style key of a prop: absent stays absent, a non-empty string is kept, anything else throws. */
17
+ function keyOf(value) {
18
+ if (value === void 0 || value === null) return void 0;
19
+ if (typeof value === "string" && value !== "") return value;
20
+ throw new TypeError("ShadowJS head: a key must be a non-empty string.");
21
+ }
22
+ /** One attribute value from a prop: strings, numbers and booleans are kept, the rest is an error. */
23
+ function attributeValue(value) {
24
+ if (value === void 0 || value === null || value === false) return void 0;
25
+ if (value === true) return true;
26
+ if (typeof value === "string") return value;
27
+ if (typeof value === "number") return value;
28
+ throw new TypeError("ShadowJS head: attribute values must be strings, numbers or booleans.");
29
+ }
30
+ /**
31
+ * The attributes of a component's props, reading each prop (so a getter is tracked by the
32
+ * caller). `skip` lists props that are not attributes.
33
+ */
34
+ function attributesOf(props, skip) {
35
+ const entries = [];
36
+ for (const key of Object.keys(props)) {
37
+ if (skip.includes(key)) continue;
38
+ entries.push([key, attributeValue(Reflect.get(props, key))]);
39
+ }
40
+ return Object.fromEntries(entries);
41
+ }
42
+ /** A tag with attributes and no text, of the given name. */
43
+ function attributeTag(tag, props, skip) {
44
+ return {
45
+ tag,
46
+ props: attributesOf(props, skip)
47
+ };
48
+ }
49
+ /**
50
+ * Sets the document title. The last registered Title wins; removing it restores the one below, or
51
+ * the original title when none is left.
52
+ *
53
+ * @param props The title text.
54
+ * @returns Always null: nothing is rendered in place.
55
+ * @throws TypeError (production message `SHADOW_HEAD_TITLE_TEXT`) when the children are not text.
56
+ * @example
57
+ * import { Title } from "@shadow-js/web";
58
+ *
59
+ * function Home() {
60
+ * return <Title>Home | Blog</Title>;
61
+ * }
62
+ * @see useHead
63
+ * @since 1.0.0
64
+ */
65
+ function Title(props) {
66
+ useHead(() => ({
67
+ tag: "title",
68
+ children: textOf(props.children)
69
+ }));
70
+ return null;
71
+ }
72
+ /**
73
+ * Registers a `<meta>`. Identity follows name, property, http-equiv or charset, so the last
74
+ * description wins. Children are ignored: a meta carries no text.
75
+ *
76
+ * @param props Attributes, such as `name` and `content`.
77
+ * @returns Always null: nothing is rendered in place.
78
+ * @throws TypeError (production message `SHADOW_HEAD_ATTRIBUTE_VALUE`) for an attribute value that
79
+ * is not a string, number or boolean, and for an invalid attribute name or an event attribute
80
+ * (see {@link normalizeTags}).
81
+ * @example
82
+ * import { Meta } from "@shadow-js/web";
83
+ *
84
+ * function About() {
85
+ * return <Meta name="description" content="About us" />;
86
+ * }
87
+ * @see useHead
88
+ * @since 1.0.0
89
+ */
90
+ function Meta(props) {
91
+ useHead(() => attributeTag("meta", props, ["children"]));
92
+ return null;
93
+ }
94
+ /**
95
+ * Registers a `<link>`. Icons are keyed by rel, sizes and type; preloads and stylesheets by rel,
96
+ * href and as; other links are append-only.
97
+ *
98
+ * @param props Attributes, such as `rel` and `href`.
99
+ * @returns Always null: nothing is rendered in place.
100
+ * @throws TypeError (production message `SHADOW_HEAD_ATTRIBUTE_VALUE`) for an attribute value that
101
+ * is not a string, number or boolean, and for an invalid attribute name or an event attribute
102
+ * (see {@link normalizeTags}).
103
+ * @example
104
+ * import { Link } from "@shadow-js/web";
105
+ *
106
+ * function Page() {
107
+ * return <Link rel="stylesheet" href="/site.css" />;
108
+ * }
109
+ * @see useHead
110
+ * @since 1.0.0
111
+ */
112
+ function Link(props) {
113
+ useHead(() => attributeTag("link", props, ["children"]));
114
+ return null;
115
+ }
116
+ /**
117
+ * Registers a `<style>` with the given CSS text. A `key` makes it replace an earlier style with the
118
+ * same key; without one, every style stays.
119
+ *
120
+ * @param props The CSS as `children`, an optional `key`, and attributes such as `media`.
121
+ * @returns Always null: nothing is rendered in place.
122
+ * @throws TypeError (production message `SHADOW_HEAD_KEY`) when `key` is not a non-empty string.
123
+ * @example
124
+ * import { Style } from "@shadow-js/web";
125
+ *
126
+ * function Theme() {
127
+ * return <Style key="theme">{"body { margin: 0 }"}</Style>;
128
+ * }
129
+ * @see useHead
130
+ * @since 1.0.0
131
+ */
132
+ function Style(props) {
133
+ useHead(() => {
134
+ const attributes = attributesOf(props, ["children", "key"]);
135
+ const text = props.children === void 0 ? void 0 : textOf(props.children);
136
+ const key = keyOf(props.key);
137
+ return {
138
+ tag: "style",
139
+ props: attributes,
140
+ ...text === void 0 ? {} : { children: text },
141
+ ...key === void 0 ? {} : { key }
142
+ };
143
+ });
144
+ return null;
145
+ }
146
+ /**
147
+ * Registers the document `<base>`. There is one; the last registration wins. Base is placed first
148
+ * in the head, as browsers expect.
149
+ *
150
+ * @param props Attributes, such as `href`.
151
+ * @returns Always null: nothing is rendered in place.
152
+ * @throws TypeError (production message `SHADOW_HEAD_ATTRIBUTE_VALUE`) for an attribute value that
153
+ * is not a string, number or boolean.
154
+ * @example
155
+ * import { Base } from "@shadow-js/web";
156
+ *
157
+ * function Shell() {
158
+ * return <Base href="/app/" />;
159
+ * }
160
+ * @see useHead
161
+ * @since 1.0.0
162
+ */
163
+ function Base(props) {
164
+ useHead(() => attributeTag("base", props, ["children"]));
165
+ return null;
166
+ }
167
+ //#endregion
168
+ export { Base, Link, Meta, Style, Title };
169
+
170
+ //# sourceMappingURL=components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.js","names":[],"sources":["../../../src/head/components.ts"],"sourcesContent":["import { useHead } from \"./use-head\";\nimport type { HeadAttributeValue, HeadTag, HeadTagName } from \"./validate\";\n\n/**\n * Props of {@link Title}.\n * @since 1.0.0\n */\nexport interface TitleProps {\n /**\n * The title text: a string, a number, an array of those, or an accessor returning them. `null`,\n * `undefined` and `false` count as empty text; anything else throws a TypeError.\n * @default undefined (the title is the empty string)\n */\n readonly children?: unknown;\n}\n\n/**\n * Props of {@link Meta}, {@link Link} and {@link Base}: every prop is an attribute, and a function\n * value is read reactively.\n * @since 1.0.0\n */\nexport interface HeadAttributeProps {\n /**\n * One attribute of the tag. A string or number is written as text, `true` as an empty attribute,\n * and `false`, `null` or `undefined` omit it. Any other value throws a TypeError.\n */\n readonly [attribute: string]: unknown;\n}\n\n/**\n * Props of {@link Style}: the CSS text and an optional key that replaces an earlier style with the\n * same key.\n * @since 1.0.0\n */\nexport interface StyleProps {\n /**\n * The CSS text: a string, a number, an array of those, or an accessor returning them.\n * @default undefined (the style has no text)\n */\n readonly children?: unknown;\n /**\n * Identity of the style: a later style with the same key replaces an earlier one. Must be a\n * non-empty string.\n * @default undefined (the style has no identity and always stays)\n */\n readonly key?: unknown;\n /** One attribute of the `<style>` element, such as `media`, with the same rules as {@link HeadAttributeProps}. */\n readonly [attribute: string]: unknown;\n}\n\n/** Text of a value that may be an accessor. Anything but text or an array of text throws. */\nfunction partText(value: unknown): string {\n if (typeof value === \"string\") return value;\n if (typeof value === \"number\") return String(value);\n if (value === undefined || value === null || value === false) return \"\";\n throw new TypeError(\n __DEV__ ? \"ShadowJS head: Title children must be text.\" : \"SHADOW_HEAD_TITLE_TEXT\",\n );\n}\n\n/** The text a Title shows. An accessor is called once, so its reads are tracked by the caller. */\nfunction textOf(value: unknown): string {\n const resolved = typeof value === \"function\" ? (value as () => unknown)() : value;\n if (Array.isArray(resolved)) return (resolved as unknown[]).map(partText).join(\"\");\n return partText(resolved);\n}\n\n/** The style key of a prop: absent stays absent, a non-empty string is kept, anything else throws. */\nfunction keyOf(value: unknown): string | undefined {\n if (value === undefined || value === null) return undefined;\n if (typeof value === \"string\" && value !== \"\") return value;\n throw new TypeError(\n __DEV__ ? \"ShadowJS head: a key must be a non-empty string.\" : \"SHADOW_HEAD_KEY\",\n );\n}\n\n/** One attribute value from a prop: strings, numbers and booleans are kept, the rest is an error. */\nfunction attributeValue(value: unknown): HeadAttributeValue {\n if (value === undefined || value === null || value === false) return undefined;\n if (value === true) return true;\n if (typeof value === \"string\") return value;\n if (typeof value === \"number\") return value;\n throw new TypeError(\n __DEV__\n ? \"ShadowJS head: attribute values must be strings, numbers or booleans.\"\n : \"SHADOW_HEAD_ATTRIBUTE_VALUE\",\n );\n}\n\n/**\n * The attributes of a component's props, reading each prop (so a getter is tracked by the\n * caller). `skip` lists props that are not attributes.\n */\nfunction attributesOf(props: object, skip: readonly string[]): Record<string, HeadAttributeValue> {\n const entries: Array<[string, HeadAttributeValue]> = [];\n for (const key of Object.keys(props)) {\n if (skip.includes(key)) continue;\n entries.push([key, attributeValue(Reflect.get(props, key))]);\n }\n return Object.fromEntries(entries);\n}\n\n/** A tag with attributes and no text, of the given name. */\nfunction attributeTag(tag: HeadTagName, props: object, skip: readonly string[]): HeadTag {\n return { tag, props: attributesOf(props, skip) };\n}\n\n/**\n * Sets the document title. The last registered Title wins; removing it restores the one below, or\n * the original title when none is left.\n *\n * @param props The title text.\n * @returns Always null: nothing is rendered in place.\n * @throws TypeError (production message `SHADOW_HEAD_TITLE_TEXT`) when the children are not text.\n * @example\n * import { Title } from \"@shadow-js/web\";\n *\n * function Home() {\n * return <Title>Home | Blog</Title>;\n * }\n * @see useHead\n * @since 1.0.0\n */\nexport function Title(props: TitleProps): null {\n useHead((): HeadTag => ({ tag: \"title\", children: textOf(props.children) }));\n return null;\n}\n\n/**\n * Registers a `<meta>`. Identity follows name, property, http-equiv or charset, so the last\n * description wins. Children are ignored: a meta carries no text.\n *\n * @param props Attributes, such as `name` and `content`.\n * @returns Always null: nothing is rendered in place.\n * @throws TypeError (production message `SHADOW_HEAD_ATTRIBUTE_VALUE`) for an attribute value that\n * is not a string, number or boolean, and for an invalid attribute name or an event attribute\n * (see {@link normalizeTags}).\n * @example\n * import { Meta } from \"@shadow-js/web\";\n *\n * function About() {\n * return <Meta name=\"description\" content=\"About us\" />;\n * }\n * @see useHead\n * @since 1.0.0\n */\nexport function Meta(props: HeadAttributeProps): null {\n useHead(() => attributeTag(\"meta\", props, [\"children\"]));\n return null;\n}\n\n/**\n * Registers a `<link>`. Icons are keyed by rel, sizes and type; preloads and stylesheets by rel,\n * href and as; other links are append-only.\n *\n * @param props Attributes, such as `rel` and `href`.\n * @returns Always null: nothing is rendered in place.\n * @throws TypeError (production message `SHADOW_HEAD_ATTRIBUTE_VALUE`) for an attribute value that\n * is not a string, number or boolean, and for an invalid attribute name or an event attribute\n * (see {@link normalizeTags}).\n * @example\n * import { Link } from \"@shadow-js/web\";\n *\n * function Page() {\n * return <Link rel=\"stylesheet\" href=\"/site.css\" />;\n * }\n * @see useHead\n * @since 1.0.0\n */\nexport function Link(props: HeadAttributeProps): null {\n useHead(() => attributeTag(\"link\", props, [\"children\"]));\n return null;\n}\n\n/**\n * Registers a `<style>` with the given CSS text. A `key` makes it replace an earlier style with the\n * same key; without one, every style stays.\n *\n * @param props The CSS as `children`, an optional `key`, and attributes such as `media`.\n * @returns Always null: nothing is rendered in place.\n * @throws TypeError (production message `SHADOW_HEAD_KEY`) when `key` is not a non-empty string.\n * @example\n * import { Style } from \"@shadow-js/web\";\n *\n * function Theme() {\n * return <Style key=\"theme\">{\"body { margin: 0 }\"}</Style>;\n * }\n * @see useHead\n * @since 1.0.0\n */\nexport function Style(props: StyleProps): null {\n useHead((): HeadTag => {\n const attributes = attributesOf(props, [\"children\", \"key\"]);\n const text = props.children === undefined ? undefined : textOf(props.children);\n const key = keyOf(props.key);\n return {\n tag: \"style\",\n props: attributes,\n ...(text === undefined ? {} : { children: text }),\n ...(key === undefined ? {} : { key }),\n };\n });\n return null;\n}\n\n/**\n * Registers the document `<base>`. There is one; the last registration wins. Base is placed first\n * in the head, as browsers expect.\n *\n * @param props Attributes, such as `href`.\n * @returns Always null: nothing is rendered in place.\n * @throws TypeError (production message `SHADOW_HEAD_ATTRIBUTE_VALUE`) for an attribute value that\n * is not a string, number or boolean.\n * @example\n * import { Base } from \"@shadow-js/web\";\n *\n * function Shell() {\n * return <Base href=\"/app/\" />;\n * }\n * @see useHead\n * @since 1.0.0\n */\nexport function Base(props: HeadAttributeProps): null {\n useHead(() => attributeTag(\"base\", props, [\"children\"]));\n return null;\n}\n"],"mappings":";;;AAmDA,SAAS,SAAS,OAAwB;CACxC,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,OAAO,UAAU,UAAU,OAAO,OAAO,KAAK;CAClD,IAAI,UAAU,KAAA,KAAa,UAAU,QAAQ,UAAU,OAAO,OAAO;CACrE,MAAM,IAAI,UACE,6CACZ;AACF;;AAGA,SAAS,OAAO,OAAwB;CACtC,MAAM,WAAW,OAAO,UAAU,aAAc,MAAwB,IAAI;CAC5E,IAAI,MAAM,QAAQ,QAAQ,GAAG,OAAQ,SAAuB,IAAI,QAAQ,CAAC,CAAC,KAAK,EAAE;CACjF,OAAO,SAAS,QAAQ;AAC1B;;AAGA,SAAS,MAAM,OAAoC;CACjD,IAAI,UAAU,KAAA,KAAa,UAAU,MAAM,OAAO,KAAA;CAClD,IAAI,OAAO,UAAU,YAAY,UAAU,IAAI,OAAO;CACtD,MAAM,IAAI,UACE,kDACZ;AACF;;AAGA,SAAS,eAAe,OAAoC;CAC1D,IAAI,UAAU,KAAA,KAAa,UAAU,QAAQ,UAAU,OAAO,OAAO,KAAA;CACrE,IAAI,UAAU,MAAM,OAAO;CAC3B,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,MAAM,IAAI,UAEJ,uEAEN;AACF;;;;;AAMA,SAAS,aAAa,OAAe,MAA6D;CAChG,MAAM,UAA+C,CAAC;CACtD,KAAK,MAAM,OAAO,OAAO,KAAK,KAAK,GAAG;EACpC,IAAI,KAAK,SAAS,GAAG,GAAG;EACxB,QAAQ,KAAK,CAAC,KAAK,eAAe,QAAQ,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC;CAC7D;CACA,OAAO,OAAO,YAAY,OAAO;AACnC;;AAGA,SAAS,aAAa,KAAkB,OAAe,MAAkC;CACvF,OAAO;EAAE;EAAK,OAAO,aAAa,OAAO,IAAI;CAAE;AACjD;;;;;;;;;;;;;;;;;AAkBA,SAAgB,MAAM,OAAyB;CAC7C,eAAwB;EAAE,KAAK;EAAS,UAAU,OAAO,MAAM,QAAQ;CAAE,EAAE;CAC3E,OAAO;AACT;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,KAAK,OAAiC;CACpD,cAAc,aAAa,QAAQ,OAAO,CAAC,UAAU,CAAC,CAAC;CACvD,OAAO;AACT;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,KAAK,OAAiC;CACpD,cAAc,aAAa,QAAQ,OAAO,CAAC,UAAU,CAAC,CAAC;CACvD,OAAO;AACT;;;;;;;;;;;;;;;;;AAkBA,SAAgB,MAAM,OAAyB;CAC7C,cAAuB;EACrB,MAAM,aAAa,aAAa,OAAO,CAAC,YAAY,KAAK,CAAC;EAC1D,MAAM,OAAO,MAAM,aAAa,KAAA,IAAY,KAAA,IAAY,OAAO,MAAM,QAAQ;EAC7E,MAAM,MAAM,MAAM,MAAM,GAAG;EAC3B,OAAO;GACL,KAAK;GACL,OAAO;GACP,GAAI,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU,KAAK;GAC/C,GAAI,QAAQ,KAAA,IAAY,CAAC,IAAI,EAAE,IAAI;EACrC;CACF,CAAC;CACD,OAAO;AACT;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,KAAK,OAAiC;CACpD,cAAc,aAAa,QAAQ,OAAO,CAAC,UAAU,CAAC,CAAC;CACvD,OAAO;AACT"}
@@ -0,0 +1,68 @@
1
+ //#region src/head/registry.ts
2
+ const noop = () => void 0;
3
+ /**
4
+ * Creates an empty head registry. `onChange` runs after every effective add or removal, so the
5
+ * owner of the DOM can schedule one update for a whole batch.
6
+ *
7
+ * @param onChange Called after the registry changes.
8
+ * @returns A registry with no winners.
9
+ * @internal
10
+ * @since 1.0.0
11
+ */
12
+ function createHeadRegistry(onChange) {
13
+ const stacks = /* @__PURE__ */ new Map();
14
+ let appendOnly = 0;
15
+ return {
16
+ add(tags) {
17
+ if (tags.length === 0) return noop;
18
+ const entries = [];
19
+ for (const tag of tags) {
20
+ let slot = tag.identity;
21
+ if (slot === void 0) {
22
+ slot = `#${appendOnly}`;
23
+ appendOnly += 1;
24
+ }
25
+ let stack = stacks.get(slot);
26
+ if (stack === void 0) {
27
+ stack = [];
28
+ stacks.set(slot, stack);
29
+ }
30
+ const entry = {
31
+ slot,
32
+ tag
33
+ };
34
+ stack.push(entry);
35
+ entries.push(entry);
36
+ }
37
+ onChange();
38
+ let removed = false;
39
+ return () => {
40
+ if (removed) return;
41
+ removed = true;
42
+ for (const entry of entries) {
43
+ const stack = stacks.get(entry.slot);
44
+ if (stack === void 0) continue;
45
+ const index = stack.indexOf(entry);
46
+ if (index !== -1) stack.splice(index, 1);
47
+ if (stack.length === 0) stacks.delete(entry.slot);
48
+ }
49
+ onChange();
50
+ };
51
+ },
52
+ winners() {
53
+ const winners = [];
54
+ for (const [slot, stack] of stacks) {
55
+ const top = stack[stack.length - 1];
56
+ if (top !== void 0) winners.push({
57
+ slot,
58
+ tag: top.tag
59
+ });
60
+ }
61
+ return winners;
62
+ }
63
+ };
64
+ }
65
+ //#endregion
66
+ export { createHeadRegistry };
67
+
68
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","names":[],"sources":["../../../src/head/registry.ts"],"sourcesContent":["import type { NormalizedTag } from \"./validate\";\n\n/**\n * One rendered head element: the slot it occupies (its identity, or a unique key for an\n * append-only tag) and the tag that currently wins that slot.\n * @internal\n */\nexport interface HeadWinner {\n readonly slot: string;\n readonly tag: NormalizedTag;\n}\n\n/**\n * The pure head registry: no DOM, no signals. Every registration joins the stack of its identity;\n * the top of each stack is the winner. Removing a registration takes it out of its stack, so the\n * one below it wins again.\n * @internal\n */\nexport interface HeadRegistry {\n /**\n * Registers a group of tags. The returned function removes them again; calling it twice is a\n * no-op.\n */\n add(tags: readonly NormalizedTag[]): () => void;\n /** The winning tag of every slot, in the order each slot first appeared. */\n winners(): HeadWinner[];\n}\n\ninterface Entry {\n readonly slot: string;\n readonly tag: NormalizedTag;\n}\n\nconst noop = (): void => undefined;\n\n/**\n * Creates an empty head registry. `onChange` runs after every effective add or removal, so the\n * owner of the DOM can schedule one update for a whole batch.\n *\n * @param onChange Called after the registry changes.\n * @returns A registry with no winners.\n * @internal\n * @since 1.0.0\n */\nexport function createHeadRegistry(onChange: () => void): HeadRegistry {\n const stacks = new Map<string, Entry[]>();\n let appendOnly = 0;\n return {\n add(tags: readonly NormalizedTag[]): () => void {\n if (tags.length === 0) return noop;\n const entries: Entry[] = [];\n for (const tag of tags) {\n let slot = tag.identity;\n if (slot === undefined) {\n slot = `#${appendOnly}`;\n appendOnly += 1;\n }\n let stack = stacks.get(slot);\n if (stack === undefined) {\n stack = [];\n stacks.set(slot, stack);\n }\n const entry: Entry = { slot, tag };\n stack.push(entry);\n entries.push(entry);\n }\n onChange();\n let removed = false;\n return (): void => {\n if (removed) return;\n removed = true;\n for (const entry of entries) {\n const stack = stacks.get(entry.slot);\n if (stack === undefined) continue;\n const index = stack.indexOf(entry);\n if (index !== -1) stack.splice(index, 1);\n if (stack.length === 0) stacks.delete(entry.slot);\n }\n onChange();\n };\n },\n winners(): HeadWinner[] {\n const winners: HeadWinner[] = [];\n for (const [slot, stack] of stacks) {\n const top = stack[stack.length - 1];\n if (top !== undefined) winners.push({ slot, tag: top.tag });\n }\n return winners;\n },\n };\n}\n"],"mappings":";AAiCA,MAAM,aAAmB,KAAA;;;;;;;;;;AAWzB,SAAgB,mBAAmB,UAAoC;CACrE,MAAM,yBAAS,IAAI,IAAqB;CACxC,IAAI,aAAa;CACjB,OAAO;EACL,IAAI,MAA4C;GAC9C,IAAI,KAAK,WAAW,GAAG,OAAO;GAC9B,MAAM,UAAmB,CAAC;GAC1B,KAAK,MAAM,OAAO,MAAM;IACtB,IAAI,OAAO,IAAI;IACf,IAAI,SAAS,KAAA,GAAW;KACtB,OAAO,IAAI;KACX,cAAc;IAChB;IACA,IAAI,QAAQ,OAAO,IAAI,IAAI;IAC3B,IAAI,UAAU,KAAA,GAAW;KACvB,QAAQ,CAAC;KACT,OAAO,IAAI,MAAM,KAAK;IACxB;IACA,MAAM,QAAe;KAAE;KAAM;IAAI;IACjC,MAAM,KAAK,KAAK;IAChB,QAAQ,KAAK,KAAK;GACpB;GACA,SAAS;GACT,IAAI,UAAU;GACd,aAAmB;IACjB,IAAI,SAAS;IACb,UAAU;IACV,KAAK,MAAM,SAAS,SAAS;KAC3B,MAAM,QAAQ,OAAO,IAAI,MAAM,IAAI;KACnC,IAAI,UAAU,KAAA,GAAW;KACzB,MAAM,QAAQ,MAAM,QAAQ,KAAK;KACjC,IAAI,UAAU,IAAI,MAAM,OAAO,OAAO,CAAC;KACvC,IAAI,MAAM,WAAW,GAAG,OAAO,OAAO,MAAM,IAAI;IAClD;IACA,SAAS;GACX;EACF;EACA,UAAwB;GACtB,MAAM,UAAwB,CAAC;GAC/B,KAAK,MAAM,CAAC,MAAM,UAAU,QAAQ;IAClC,MAAM,MAAM,MAAM,MAAM,SAAS;IACjC,IAAI,QAAQ,KAAA,GAAW,QAAQ,KAAK;KAAE;KAAM,KAAK,IAAI;IAAI,CAAC;GAC5D;GACA,OAAO;EACT;CACF;AACF"}
@@ -0,0 +1,54 @@
1
+ import { NormalizedTag } from "./validate.js";
2
+ import { Context } from "@shadow-js/core";
3
+ //#region src/head/server-head.d.ts
4
+ /**
5
+ * The head of one server render: what `useHead`, `<Title>`, `<Meta>`, `<Link>`, `<Style>` and
6
+ * `<Base>` registered while the app rendered. Pass it to a render function through its `head`
7
+ * option, then write {@link ServerHead.html} into the document's `<head>`.
8
+ *
9
+ * Tags follow the same rules as in the browser: the last registration of an identity wins
10
+ * (`title`, `meta` by name, ...), append-only tags all stay. Every tag carries the marker the
11
+ * browser's head sink looks for, so the client adopts the server's elements instead of adding
12
+ * duplicates.
13
+ * @since 1.0.0
14
+ */
15
+ export interface ServerHead {
16
+ /** Registers tags. Used by `useHead`; the returned function removes them again. */
17
+ add(tags: readonly NormalizedTag[]): () => void;
18
+ /** Forgets every registration. Multi-pass renders call this before each pass. */
19
+ clear(): void;
20
+ /**
21
+ * The markup of the winning tags, in registration order. With a `nonce`, every `<style>` carries
22
+ * it, so the page's Content-Security-Policy (`style-src 'nonce-...'`) accepts the styles. Throws a
23
+ * TypeError when the text of a style contains a closing style tag.
24
+ *
25
+ * @param options `nonce` is added to every `<style>`. Default: no options, so no nonce.
26
+ */
27
+ html(options?: {
28
+ readonly nonce?: string;
29
+ }): string;
30
+ /** The winning tags, for hosts that build the head themselves. */
31
+ tags(): readonly NormalizedTag[];
32
+ }
33
+ /**
34
+ * Creates an empty server head collector.
35
+ *
36
+ * @returns A collector to pass as the `head` option of `renderToString`, `renderToStringAsync` or
37
+ * `renderToStream`.
38
+ * @example
39
+ * import { createComponent, Title } from "@shadow-js/web";
40
+ * import { createServerHead, renderToString } from "@shadow-js/web/server";
41
+ *
42
+ * function App() {
43
+ * return Title({ children: "Home" });
44
+ * }
45
+ *
46
+ * const head = createServerHead();
47
+ * const html = renderToString(() => createComponent(App, {}), { head });
48
+ * const page = `<!doctype html><head>${head.html()}</head><body>${html}</body>`;
49
+ * @see useHead
50
+ * @since 1.0.0
51
+ */
52
+ export declare function createServerHead(): ServerHead;
53
+ //#endregion
54
+ //# sourceMappingURL=server-head.d.ts.map
@@ -0,0 +1,76 @@
1
+ import { escapeHtml } from "../server/escape.js";
2
+ import { createHeadRegistry } from "./registry.js";
3
+ import { HEAD_KEY, HEAD_MARKER } from "./validate.js";
4
+ import { createContext } from "@shadow-js/core";
5
+ //#region src/head/server-head.ts
6
+ /** Elements that never have content or a closing tag. */
7
+ const VOID_TAGS = /* @__PURE__ */ new Set([
8
+ "meta",
9
+ "link",
10
+ "base"
11
+ ]);
12
+ /** The collector `useHead` writes to while a render is running; null outside a render with `head`. @internal */
13
+ const ServerHeadContext = /* @__PURE__ */ createContext(null, { name: "ServerHead" });
14
+ /** Markup of one tag. Text and attribute values are escaped; `</style` cannot appear in a style. */
15
+ function tagHtml(tag, nonce) {
16
+ let attributes = ` ${HEAD_MARKER}`;
17
+ if (tag.key !== void 0) attributes += ` ${HEAD_KEY}="${escapeHtml(tag.key)}"`;
18
+ for (const [name, value] of tag.attributes) attributes += value === "" ? ` ${name}` : ` ${name}="${escapeHtml(value)}"`;
19
+ if (VOID_TAGS.has(tag.tag)) return `<${tag.tag}${attributes}>`;
20
+ const text = tag.text ?? "";
21
+ if (tag.tag === "style") {
22
+ if (/<\/style/i.test(text)) throw new TypeError("ShadowJS head: style text may not contain a closing style tag.");
23
+ return `<style${nonce === void 0 ? attributes : `${attributes} nonce="${escapeHtml(nonce)}"`}>${text}</style>`;
24
+ }
25
+ return `<${tag.tag}${attributes}>${escapeHtml(text)}</${tag.tag}>`;
26
+ }
27
+ /**
28
+ * Creates an empty server head collector.
29
+ *
30
+ * @returns A collector to pass as the `head` option of `renderToString`, `renderToStringAsync` or
31
+ * `renderToStream`.
32
+ * @example
33
+ * import { createComponent, Title } from "@shadow-js/web";
34
+ * import { createServerHead, renderToString } from "@shadow-js/web/server";
35
+ *
36
+ * function App() {
37
+ * return Title({ children: "Home" });
38
+ * }
39
+ *
40
+ * const head = createServerHead();
41
+ * const html = renderToString(() => createComponent(App, {}), { head });
42
+ * const page = `<!doctype html><head>${head.html()}</head><body>${html}</body>`;
43
+ * @see useHead
44
+ * @since 1.0.0
45
+ */
46
+ function createServerHead() {
47
+ let registry = createHeadRegistry(() => void 0);
48
+ return {
49
+ add: (tags) => registry.add(tags),
50
+ clear() {
51
+ registry = createHeadRegistry(() => void 0);
52
+ },
53
+ html: (options) => registry.winners().map((winner) => tagHtml(winner.tag, options?.nonce)).join(""),
54
+ tags: () => registry.winners().map((winner) => winner.tag)
55
+ };
56
+ }
57
+ /**
58
+ * Runs `fn` with `head` as the collector `useHead` writes to. Server renderers call it around the
59
+ * app; with no collector `fn` runs as is. @internal
60
+ */
61
+ function runWithServerHead(head, fn) {
62
+ if (head === void 0) return fn();
63
+ const holder = {};
64
+ ServerHeadContext({
65
+ value: head,
66
+ get children() {
67
+ holder.value = fn();
68
+ return null;
69
+ }
70
+ });
71
+ return holder.value;
72
+ }
73
+ //#endregion
74
+ export { ServerHeadContext, createServerHead, runWithServerHead };
75
+
76
+ //# sourceMappingURL=server-head.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-head.js","names":[],"sources":["../../../src/head/server-head.ts"],"sourcesContent":["import { type Context, createContext } from \"@shadow-js/core\";\nimport { escapeHtml } from \"../server/escape\";\nimport { createHeadRegistry, type HeadRegistry } from \"./registry\";\nimport { HEAD_KEY, HEAD_MARKER, type NormalizedTag } from \"./validate\";\n\n/** Elements that never have content or a closing tag. */\nconst VOID_TAGS: ReadonlySet<string> = new Set([\"meta\", \"link\", \"base\"]);\n\n/**\n * The head of one server render: what `useHead`, `<Title>`, `<Meta>`, `<Link>`, `<Style>` and\n * `<Base>` registered while the app rendered. Pass it to a render function through its `head`\n * option, then write {@link ServerHead.html} into the document's `<head>`.\n *\n * Tags follow the same rules as in the browser: the last registration of an identity wins\n * (`title`, `meta` by name, ...), append-only tags all stay. Every tag carries the marker the\n * browser's head sink looks for, so the client adopts the server's elements instead of adding\n * duplicates.\n * @since 1.0.0\n */\nexport interface ServerHead {\n /** Registers tags. Used by `useHead`; the returned function removes them again. */\n add(tags: readonly NormalizedTag[]): () => void;\n /** Forgets every registration. Multi-pass renders call this before each pass. */\n clear(): void;\n /**\n * The markup of the winning tags, in registration order. With a `nonce`, every `<style>` carries\n * it, so the page's Content-Security-Policy (`style-src 'nonce-...'`) accepts the styles. Throws a\n * TypeError when the text of a style contains a closing style tag.\n *\n * @param options `nonce` is added to every `<style>`. Default: no options, so no nonce.\n */\n html(options?: { readonly nonce?: string }): string;\n /** The winning tags, for hosts that build the head themselves. */\n tags(): readonly NormalizedTag[];\n}\n\n/** The collector `useHead` writes to while a render is running; null outside a render with `head`. @internal */\nexport const ServerHeadContext: Context<ServerHead | null> =\n /* @__PURE__ */ createContext<ServerHead | null>(null, { name: \"ServerHead\" });\n\n/** Markup of one tag. Text and attribute values are escaped; `</style` cannot appear in a style. */\nfunction tagHtml(tag: NormalizedTag, nonce: string | undefined): string {\n let attributes = ` ${HEAD_MARKER}`;\n if (tag.key !== undefined) attributes += ` ${HEAD_KEY}=\"${escapeHtml(tag.key)}\"`;\n for (const [name, value] of tag.attributes) {\n attributes += value === \"\" ? ` ${name}` : ` ${name}=\"${escapeHtml(value)}\"`;\n }\n if (VOID_TAGS.has(tag.tag)) return `<${tag.tag}${attributes}>`;\n const text = tag.text ?? \"\";\n if (tag.tag === \"style\") {\n if (/<\\/style/i.test(text)) {\n throw new TypeError(\"ShadowJS head: style text may not contain a closing style tag.\");\n }\n const withNonce =\n nonce === undefined ? attributes : `${attributes} nonce=\"${escapeHtml(nonce)}\"`;\n return `<style${withNonce}>${text}</style>`;\n }\n return `<${tag.tag}${attributes}>${escapeHtml(text)}</${tag.tag}>`;\n}\n\n/**\n * Creates an empty server head collector.\n *\n * @returns A collector to pass as the `head` option of `renderToString`, `renderToStringAsync` or\n * `renderToStream`.\n * @example\n * import { createComponent, Title } from \"@shadow-js/web\";\n * import { createServerHead, renderToString } from \"@shadow-js/web/server\";\n *\n * function App() {\n * return Title({ children: \"Home\" });\n * }\n *\n * const head = createServerHead();\n * const html = renderToString(() => createComponent(App, {}), { head });\n * const page = `<!doctype html><head>${head.html()}</head><body>${html}</body>`;\n * @see useHead\n * @since 1.0.0\n */\nexport function createServerHead(): ServerHead {\n let registry: HeadRegistry = createHeadRegistry(() => undefined);\n return {\n add: (tags) => registry.add(tags),\n clear() {\n registry = createHeadRegistry(() => undefined);\n },\n html: (options) =>\n registry\n .winners()\n .map((winner) => tagHtml(winner.tag, options?.nonce))\n .join(\"\"),\n tags: () => registry.winners().map((winner) => winner.tag),\n };\n}\n\n/**\n * Runs `fn` with `head` as the collector `useHead` writes to. Server renderers call it around the\n * app; with no collector `fn` runs as is. @internal\n */\nexport function runWithServerHead<T>(head: ServerHead | undefined, fn: () => T): T {\n if (head === undefined) return fn();\n const holder: { value?: T } = {};\n ServerHeadContext({\n value: head,\n get children() {\n holder.value = fn();\n return null;\n },\n });\n return holder.value as T;\n}\n"],"mappings":";;;;;;AAMA,MAAM,4BAAiC,IAAI,IAAI;CAAC;CAAQ;CAAQ;AAAM,CAAC;;AA+BvE,MAAa,oBACK,8BAAiC,MAAM,EAAE,MAAM,aAAa,CAAC;;AAG/E,SAAS,QAAQ,KAAoB,OAAmC;CACtE,IAAI,aAAa,IAAI;CACrB,IAAI,IAAI,QAAQ,KAAA,GAAW,cAAc,IAAI,SAAS,IAAI,WAAW,IAAI,GAAG,EAAE;CAC9E,KAAK,MAAM,CAAC,MAAM,UAAU,IAAI,YAC9B,cAAc,UAAU,KAAK,IAAI,SAAS,IAAI,KAAK,IAAI,WAAW,KAAK,EAAE;CAE3E,IAAI,UAAU,IAAI,IAAI,GAAG,GAAG,OAAO,IAAI,IAAI,MAAM,WAAW;CAC5D,MAAM,OAAO,IAAI,QAAQ;CACzB,IAAI,IAAI,QAAQ,SAAS;EACvB,IAAI,YAAY,KAAK,IAAI,GACvB,MAAM,IAAI,UAAU,gEAAgE;EAItF,OAAO,SADL,UAAU,KAAA,IAAY,aAAa,GAAG,WAAW,UAAU,WAAW,KAAK,EAAE,GACrD,GAAG,KAAK;CACpC;CACA,OAAO,IAAI,IAAI,MAAM,WAAW,GAAG,WAAW,IAAI,EAAE,IAAI,IAAI,IAAI;AAClE;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,mBAA+B;CAC7C,IAAI,WAAyB,yBAAyB,KAAA,CAAS;CAC/D,OAAO;EACL,MAAM,SAAS,SAAS,IAAI,IAAI;EAChC,QAAQ;GACN,WAAW,yBAAyB,KAAA,CAAS;EAC/C;EACA,OAAO,YACL,SACG,QAAQ,CAAC,CACT,KAAK,WAAW,QAAQ,OAAO,KAAK,SAAS,KAAK,CAAC,CAAC,CACpD,KAAK,EAAE;EACZ,YAAY,SAAS,QAAQ,CAAC,CAAC,KAAK,WAAW,OAAO,GAAG;CAC3D;AACF;;;;;AAMA,SAAgB,kBAAqB,MAA8B,IAAgB;CACjF,IAAI,SAAS,KAAA,GAAW,OAAO,GAAG;CAClC,MAAM,SAAwB,CAAC;CAC/B,kBAAkB;EAChB,OAAO;EACP,IAAI,WAAW;GACb,OAAO,QAAQ,GAAG;GAClB,OAAO;EACT;CACF,CAAC;CACD,OAAO,OAAO;AAChB"}
@@ -0,0 +1,96 @@
1
+ import { HEAD_KEY, HEAD_MARKER, identityOfElement } from "./validate.js";
2
+ //#region src/head/sink.ts
3
+ /** Removes or restores one element the sink owned. Elements already gone are ignored. */
4
+ function release(head, record) {
5
+ const el = record.el;
6
+ if (el.parentNode !== head) return;
7
+ if (el.localName === "title" && !record.created) {
8
+ if (record.restoreText !== void 0 && el.textContent !== record.restoreText) el.textContent = record.restoreText;
9
+ return;
10
+ }
11
+ el.remove();
12
+ }
13
+ /**
14
+ * Finds an element to adopt for a slot, or returns undefined. Only identity-keyed slots adopt. A
15
+ * server-rendered element carries the marker, and a page title or base is adopted even without it,
16
+ * because the browser shows that one, so it must be the one that changes.
17
+ */
18
+ function adoptable(head, slot, tag, claimed) {
19
+ if (tag.identity === void 0) return void 0;
20
+ for (const candidate of Array.from(head.querySelectorAll(tag.tag))) {
21
+ if (claimed.has(candidate)) continue;
22
+ if (identityOfElement(candidate) !== slot) continue;
23
+ if (candidate.hasAttribute("data-shadow-head") || tag.tag === "title") return candidate;
24
+ }
25
+ }
26
+ /** Takes over an existing element for a slot, or creates and marks a new one. */
27
+ function acquire(doc, slot, tag, claimed) {
28
+ const head = doc.head;
29
+ const existing = adoptable(head, slot, tag, claimed);
30
+ if (existing !== void 0) return {
31
+ el: existing,
32
+ created: false,
33
+ restoreText: tag.tag === "title" ? existing.textContent : void 0,
34
+ attributes: []
35
+ };
36
+ const el = doc.createElement(tag.tag);
37
+ el.setAttribute(HEAD_MARKER, "");
38
+ if (tag.key !== void 0) el.setAttribute(HEAD_KEY, tag.key);
39
+ if (tag.tag === "base") head.insertBefore(el, head.firstChild);
40
+ else head.appendChild(el);
41
+ return {
42
+ el,
43
+ created: true,
44
+ restoreText: void 0,
45
+ attributes: []
46
+ };
47
+ }
48
+ /** Writes the attributes and text of `tag` to its element, touching only what changed. */
49
+ function sync(record, tag) {
50
+ const el = record.el;
51
+ const wanted = new Map(tag.attributes);
52
+ for (const [name] of record.attributes) if (!wanted.has(name)) el.removeAttribute(name);
53
+ for (const [name, value] of tag.attributes) if (el.getAttribute(name) !== value) el.setAttribute(name, value);
54
+ record.attributes = tag.attributes;
55
+ if (tag.tag === "title" || tag.tag === "style") {
56
+ const text = tag.text ?? "";
57
+ if (el.textContent !== text) el.textContent = text;
58
+ }
59
+ }
60
+ /**
61
+ * Creates the DOM sink for one document. The returned function makes `document.head` show the
62
+ * given winners: it releases elements whose slot is gone, adopts or creates the rest and updates
63
+ * them in place. It is called once per batch of registrations, so one call is one DOM pass.
64
+ *
65
+ * @param doc The document whose head is written.
66
+ * @returns A function that applies a list of winners.
67
+ * @internal
68
+ * @since 1.0.0
69
+ */
70
+ function createDomHeadSink(doc) {
71
+ const owned = /* @__PURE__ */ new Map();
72
+ return (winners) => {
73
+ const head = doc.head;
74
+ const wanted = new Set(winners.map((winner) => winner.slot));
75
+ for (const [slot, record] of owned) {
76
+ if (wanted.has(slot) && record.el.parentNode === head) continue;
77
+ owned.delete(slot);
78
+ release(head, record);
79
+ }
80
+ const claimed = /* @__PURE__ */ new Set();
81
+ for (const record of owned.values()) claimed.add(record.el);
82
+ for (const winner of winners) {
83
+ let record = owned.get(winner.slot);
84
+ if (record === void 0) {
85
+ record = acquire(doc, winner.slot, winner.tag, claimed);
86
+ owned.set(winner.slot, record);
87
+ claimed.add(record.el);
88
+ }
89
+ sync(record, winner.tag);
90
+ }
91
+ };
92
+ }
93
+ //#endregion
94
+ export { createDomHeadSink };
95
+
96
+ //# sourceMappingURL=sink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sink.js","names":[],"sources":["../../../src/head/sink.ts"],"sourcesContent":["import type { HeadWinner } from \"./registry\";\nimport { HEAD_KEY, HEAD_MARKER, identityOfElement, type NormalizedTag } from \"./validate\";\n\n/**\n * What the sink knows about one element it writes. `created` elements are removed on release;\n * adopted ones are removed too unless they are titles, where the original text comes back.\n */\ninterface Owned {\n readonly el: Element;\n readonly created: boolean;\n /** Text an adopted title had before the sink took it over. */\n readonly restoreText: string | undefined;\n /** Attributes last written, so the next write can remove the ones that disappeared. */\n attributes: ReadonlyArray<readonly [string, string]>;\n}\n\n/** Removes or restores one element the sink owned. Elements already gone are ignored. */\nfunction release(head: HTMLHeadElement, record: Owned): void {\n const el = record.el;\n if (el.parentNode !== head) return;\n if (el.localName === \"title\" && !record.created) {\n if (record.restoreText !== undefined && el.textContent !== record.restoreText) {\n el.textContent = record.restoreText;\n }\n return;\n }\n el.remove();\n}\n\n/**\n * Finds an element to adopt for a slot, or returns undefined. Only identity-keyed slots adopt. A\n * server-rendered element carries the marker, and a page title or base is adopted even without it,\n * because the browser shows that one, so it must be the one that changes.\n */\nfunction adoptable(\n head: HTMLHeadElement,\n slot: string,\n tag: NormalizedTag,\n claimed: Set<Element>,\n): Element | undefined {\n if (tag.identity === undefined) return undefined;\n for (const candidate of Array.from(head.querySelectorAll(tag.tag))) {\n if (claimed.has(candidate)) continue;\n if (identityOfElement(candidate) !== slot) continue;\n if (candidate.hasAttribute(HEAD_MARKER) || tag.tag === \"title\") return candidate;\n }\n return undefined;\n}\n\n/** Takes over an existing element for a slot, or creates and marks a new one. */\nfunction acquire(doc: Document, slot: string, tag: NormalizedTag, claimed: Set<Element>): Owned {\n const head = doc.head;\n const existing = adoptable(head, slot, tag, claimed);\n if (existing !== undefined) {\n const restoreText = tag.tag === \"title\" ? existing.textContent : undefined;\n return { el: existing, created: false, restoreText, attributes: [] };\n }\n const el = doc.createElement(tag.tag);\n el.setAttribute(HEAD_MARKER, \"\");\n if (tag.key !== undefined) el.setAttribute(HEAD_KEY, tag.key);\n if (tag.tag === \"base\") head.insertBefore(el, head.firstChild);\n else head.appendChild(el);\n return { el, created: true, restoreText: undefined, attributes: [] };\n}\n\n/** Writes the attributes and text of `tag` to its element, touching only what changed. */\nfunction sync(record: Owned, tag: NormalizedTag): void {\n const el = record.el;\n const wanted = new Map<string, string>(tag.attributes);\n for (const [name] of record.attributes) {\n if (!wanted.has(name)) el.removeAttribute(name);\n }\n for (const [name, value] of tag.attributes) {\n if (el.getAttribute(name) !== value) el.setAttribute(name, value);\n }\n record.attributes = tag.attributes;\n if (tag.tag === \"title\" || tag.tag === \"style\") {\n const text = tag.text ?? \"\";\n if (el.textContent !== text) el.textContent = text;\n }\n}\n\n/**\n * Creates the DOM sink for one document. The returned function makes `document.head` show the\n * given winners: it releases elements whose slot is gone, adopts or creates the rest and updates\n * them in place. It is called once per batch of registrations, so one call is one DOM pass.\n *\n * @param doc The document whose head is written.\n * @returns A function that applies a list of winners.\n * @internal\n * @since 1.0.0\n */\nexport function createDomHeadSink(doc: Document): (winners: readonly HeadWinner[]) => void {\n const owned = new Map<string, Owned>();\n return (winners: readonly HeadWinner[]): void => {\n const head = doc.head;\n const wanted = new Set(winners.map((winner) => winner.slot));\n for (const [slot, record] of owned) {\n if (wanted.has(slot) && record.el.parentNode === head) continue;\n owned.delete(slot);\n release(head, record);\n }\n const claimed = new Set<Element>();\n for (const record of owned.values()) claimed.add(record.el);\n for (const winner of winners) {\n let record = owned.get(winner.slot);\n if (record === undefined) {\n record = acquire(doc, winner.slot, winner.tag, claimed);\n owned.set(winner.slot, record);\n claimed.add(record.el);\n }\n sync(record, winner.tag);\n }\n };\n}\n"],"mappings":";;;AAiBA,SAAS,QAAQ,MAAuB,QAAqB;CAC3D,MAAM,KAAK,OAAO;CAClB,IAAI,GAAG,eAAe,MAAM;CAC5B,IAAI,GAAG,cAAc,WAAW,CAAC,OAAO,SAAS;EAC/C,IAAI,OAAO,gBAAgB,KAAA,KAAa,GAAG,gBAAgB,OAAO,aAChE,GAAG,cAAc,OAAO;EAE1B;CACF;CACA,GAAG,OAAO;AACZ;;;;;;AAOA,SAAS,UACP,MACA,MACA,KACA,SACqB;CACrB,IAAI,IAAI,aAAa,KAAA,GAAW,OAAO,KAAA;CACvC,KAAK,MAAM,aAAa,MAAM,KAAK,KAAK,iBAAiB,IAAI,GAAG,CAAC,GAAG;EAClE,IAAI,QAAQ,IAAI,SAAS,GAAG;EAC5B,IAAI,kBAAkB,SAAS,MAAM,MAAM;EAC3C,IAAI,UAAU,aAAA,kBAAwB,KAAK,IAAI,QAAQ,SAAS,OAAO;CACzE;AAEF;;AAGA,SAAS,QAAQ,KAAe,MAAc,KAAoB,SAA8B;CAC9F,MAAM,OAAO,IAAI;CACjB,MAAM,WAAW,UAAU,MAAM,MAAM,KAAK,OAAO;CACnD,IAAI,aAAa,KAAA,GAEf,OAAO;EAAE,IAAI;EAAU,SAAS;EAAO,aADnB,IAAI,QAAQ,UAAU,SAAS,cAAc,KAAA;EACb,YAAY,CAAC;CAAE;CAErE,MAAM,KAAK,IAAI,cAAc,IAAI,GAAG;CACpC,GAAG,aAAa,aAAa,EAAE;CAC/B,IAAI,IAAI,QAAQ,KAAA,GAAW,GAAG,aAAa,UAAU,IAAI,GAAG;CAC5D,IAAI,IAAI,QAAQ,QAAQ,KAAK,aAAa,IAAI,KAAK,UAAU;MACxD,KAAK,YAAY,EAAE;CACxB,OAAO;EAAE;EAAI,SAAS;EAAM,aAAa,KAAA;EAAW,YAAY,CAAC;CAAE;AACrE;;AAGA,SAAS,KAAK,QAAe,KAA0B;CACrD,MAAM,KAAK,OAAO;CAClB,MAAM,SAAS,IAAI,IAAoB,IAAI,UAAU;CACrD,KAAK,MAAM,CAAC,SAAS,OAAO,YAC1B,IAAI,CAAC,OAAO,IAAI,IAAI,GAAG,GAAG,gBAAgB,IAAI;CAEhD,KAAK,MAAM,CAAC,MAAM,UAAU,IAAI,YAC9B,IAAI,GAAG,aAAa,IAAI,MAAM,OAAO,GAAG,aAAa,MAAM,KAAK;CAElE,OAAO,aAAa,IAAI;CACxB,IAAI,IAAI,QAAQ,WAAW,IAAI,QAAQ,SAAS;EAC9C,MAAM,OAAO,IAAI,QAAQ;EACzB,IAAI,GAAG,gBAAgB,MAAM,GAAG,cAAc;CAChD;AACF;;;;;;;;;;;AAYA,SAAgB,kBAAkB,KAAyD;CACzF,MAAM,wBAAQ,IAAI,IAAmB;CACrC,QAAQ,YAAyC;EAC/C,MAAM,OAAO,IAAI;EACjB,MAAM,SAAS,IAAI,IAAI,QAAQ,KAAK,WAAW,OAAO,IAAI,CAAC;EAC3D,KAAK,MAAM,CAAC,MAAM,WAAW,OAAO;GAClC,IAAI,OAAO,IAAI,IAAI,KAAK,OAAO,GAAG,eAAe,MAAM;GACvD,MAAM,OAAO,IAAI;GACjB,QAAQ,MAAM,MAAM;EACtB;EACA,MAAM,0BAAU,IAAI,IAAa;EACjC,KAAK,MAAM,UAAU,MAAM,OAAO,GAAG,QAAQ,IAAI,OAAO,EAAE;EAC1D,KAAK,MAAM,UAAU,SAAS;GAC5B,IAAI,SAAS,MAAM,IAAI,OAAO,IAAI;GAClC,IAAI,WAAW,KAAA,GAAW;IACxB,SAAS,QAAQ,KAAK,OAAO,MAAM,OAAO,KAAK,OAAO;IACtD,MAAM,IAAI,OAAO,MAAM,MAAM;IAC7B,QAAQ,IAAI,OAAO,EAAE;GACvB;GACA,KAAK,QAAQ,OAAO,GAAG;EACzB;CACF;AACF"}
@@ -0,0 +1,35 @@
1
+ import { HeadInput } from "./validate.js";
2
+ //#region src/head/use-head.d.ts
3
+ /**
4
+ * Registers head tags for the lifetime of the current owner. Each registration joins the stack of
5
+ * its identity: `title` and `base` are singletons, `meta` is keyed by its name, property,
6
+ * http-equiv or charset (and media), icons by rel, sizes and type, resource links by rel, href and
7
+ * as, and styles by key. The last registration of an identity wins; disposing it restores the one
8
+ * below. Append-only tags (no identity) all stay. Passing a function re-registers when its
9
+ * dependencies change. On the client the registrations are written to `document.head` after the
10
+ * render phase of a flush, in one pass per flush. On the server the tags go to the render's `head`
11
+ * collector (see `createServerHead`), read once; without one, or outside an owner, nothing is
12
+ * registered.
13
+ *
14
+ * @param input One tag, several tags, or a function returning them. `null`, `undefined` and `false`
15
+ * register nothing.
16
+ * @throws TypeError for an invalid tag description (see {@link normalizeTags}); on the client the
17
+ * error is raised in the registration's render effect and goes to the owner's error handler.
18
+ * In development builds, calling it on the client with no owner does not throw: it warns
19
+ * `HEAD_OUTSIDE_OWNER` and registers nothing.
20
+ * @example
21
+ * import { useSignal } from "@shadow-js/core";
22
+ * import { useHead } from "@shadow-js/web";
23
+ *
24
+ * function Post() {
25
+ * const [post] = useSignal({ title: "Hello" });
26
+ * useHead(() => ({ tag: "title", children: `${post().title} | Blog` }));
27
+ * return null;
28
+ * }
29
+ * @see Title
30
+ * @see Meta
31
+ * @since 1.0.0
32
+ */
33
+ export declare function useHead(input: HeadInput | (() => HeadInput)): void;
34
+ //#endregion
35
+ //# sourceMappingURL=use-head.d.ts.map
@@ -0,0 +1,84 @@
1
+ import { createHeadRegistry } from "./registry.js";
2
+ import { normalizeTags } from "./validate.js";
3
+ import { ServerHeadContext } from "./server-head.js";
4
+ import { createDomHeadSink } from "./sink.js";
5
+ import { createRoot, getOwner, isServer, untrack, useContext, useEffect, useRenderEffect, useSignal } from "@shadow-js/core";
6
+ //#region src/head/use-head.ts
7
+ /** One registry per document, shared by every `useHead` call on it. */
8
+ const registries = /* @__PURE__ */ new WeakMap();
9
+ /**
10
+ * Creates the registry for a document and the deferred effect that writes it to the head. The
11
+ * effect is detached: it lives as long as the document, not as long as the first caller. It runs
12
+ * in the user-effect queue, so every registration made in one flush produces one DOM pass.
13
+ */
14
+ function createRegistryFor(doc) {
15
+ return createRoot(() => {
16
+ const [version, bump] = useSignal(0);
17
+ const registry = createHeadRegistry(() => {
18
+ bump((count) => count + 1);
19
+ });
20
+ const apply = createDomHeadSink(doc);
21
+ useEffect(() => {
22
+ version();
23
+ return registry.winners();
24
+ }, (winners) => {
25
+ apply(winners);
26
+ });
27
+ return registry;
28
+ }, { detached: true });
29
+ }
30
+ /** The registry of a document, created on first use. */
31
+ function registryFor(doc) {
32
+ const known = registries.get(doc);
33
+ if (known !== void 0) return known;
34
+ const registry = createRegistryFor(doc);
35
+ registries.set(doc, registry);
36
+ return registry;
37
+ }
38
+ /**
39
+ * Registers head tags for the lifetime of the current owner. Each registration joins the stack of
40
+ * its identity: `title` and `base` are singletons, `meta` is keyed by its name, property,
41
+ * http-equiv or charset (and media), icons by rel, sizes and type, resource links by rel, href and
42
+ * as, and styles by key. The last registration of an identity wins; disposing it restores the one
43
+ * below. Append-only tags (no identity) all stay. Passing a function re-registers when its
44
+ * dependencies change. On the client the registrations are written to `document.head` after the
45
+ * render phase of a flush, in one pass per flush. On the server the tags go to the render's `head`
46
+ * collector (see `createServerHead`), read once; without one, or outside an owner, nothing is
47
+ * registered.
48
+ *
49
+ * @param input One tag, several tags, or a function returning them. `null`, `undefined` and `false`
50
+ * register nothing.
51
+ * @throws TypeError for an invalid tag description (see {@link normalizeTags}); on the client the
52
+ * error is raised in the registration's render effect and goes to the owner's error handler.
53
+ * In development builds, calling it on the client with no owner does not throw: it warns
54
+ * `HEAD_OUTSIDE_OWNER` and registers nothing.
55
+ * @example
56
+ * import { useSignal } from "@shadow-js/core";
57
+ * import { useHead } from "@shadow-js/web";
58
+ *
59
+ * function Post() {
60
+ * const [post] = useSignal({ title: "Hello" });
61
+ * useHead(() => ({ tag: "title", children: `${post().title} | Blog` }));
62
+ * return null;
63
+ * }
64
+ * @see Title
65
+ * @see Meta
66
+ * @since 1.0.0
67
+ */
68
+ function useHead(input) {
69
+ if (isServer) {
70
+ const collector = getOwner() === null ? null : useContext(ServerHeadContext);
71
+ if (collector !== null) collector.add(normalizeTags(untrack(() => typeof input === "function" ? input() : input)));
72
+ return;
73
+ }
74
+ if (getOwner() === null) {
75
+ console.warn("[shadow HEAD_OUTSIDE_OWNER] useHead() needs an owner; nothing was registered.");
76
+ return;
77
+ }
78
+ const registry = registryFor(document);
79
+ useRenderEffect(() => normalizeTags(typeof input === "function" ? input() : input), (tags) => registry.add(tags));
80
+ }
81
+ //#endregion
82
+ export { useHead };
83
+
84
+ //# sourceMappingURL=use-head.js.map