@shadow-js/web 1.0.0 → 1.0.2

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 (349) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/dev/attributes.d.ts +10 -5
  3. package/dist/dev/attributes.js +28 -51
  4. package/dist/dev/attributes.js.map +1 -1
  5. package/dist/dev/autofocus.d.ts +0 -2
  6. package/dist/dev/autofocus.js +1 -2
  7. package/dist/dev/class-style.d.ts +6 -4
  8. package/dist/dev/class-style.js +25 -9
  9. package/dist/dev/class-style.js.map +1 -1
  10. package/dist/dev/component.d.ts +0 -2
  11. package/dist/dev/component.js +1 -2
  12. package/dist/dev/control-flow/activity.d.ts +0 -2
  13. package/dist/dev/control-flow/activity.js +1 -2
  14. package/dist/dev/control-flow/branch.js +0 -1
  15. package/dist/dev/control-flow/client-only.d.ts +0 -2
  16. package/dist/dev/control-flow/client-only.js +1 -2
  17. package/dist/dev/control-flow/dynamic.d.ts +11 -4
  18. package/dist/dev/control-flow/dynamic.js +57 -41
  19. package/dist/dev/control-flow/dynamic.js.map +1 -1
  20. package/dist/dev/control-flow/error-boundary.d.ts +0 -2
  21. package/dist/dev/control-flow/error-boundary.js +1 -2
  22. package/dist/dev/control-flow/for.d.ts +0 -2
  23. package/dist/dev/control-flow/for.js +1 -2
  24. package/dist/dev/control-flow/fragment.d.ts +0 -2
  25. package/dist/dev/control-flow/fragment.js +1 -2
  26. package/dist/dev/control-flow/hot-link.js +1 -2
  27. package/dist/dev/control-flow/index-list.d.ts +0 -2
  28. package/dist/dev/control-flow/index-list.js +1 -2
  29. package/dist/dev/control-flow/lazy.d.ts +0 -2
  30. package/dist/dev/control-flow/lazy.js +1 -2
  31. package/dist/dev/control-flow/no-hydration.d.ts +0 -2
  32. package/dist/dev/control-flow/no-hydration.js +1 -2
  33. package/dist/dev/control-flow/portal.d.ts +0 -2
  34. package/dist/dev/control-flow/portal.js +3 -2
  35. package/dist/dev/control-flow/portal.js.map +1 -1
  36. package/dist/dev/control-flow/root-errors.d.ts +0 -2
  37. package/dist/dev/control-flow/root-errors.js +1 -2
  38. package/dist/dev/control-flow/show.d.ts +0 -2
  39. package/dist/dev/control-flow/show.js +1 -2
  40. package/dist/dev/control-flow/suspense-list.d.ts +0 -2
  41. package/dist/dev/control-flow/suspense-list.js +1 -2
  42. package/dist/dev/control-flow/suspense.d.ts +0 -2
  43. package/dist/dev/control-flow/suspense.js +1 -2
  44. package/dist/dev/control-flow/switch.d.ts +0 -2
  45. package/dist/dev/control-flow/switch.js +1 -2
  46. package/dist/dev/derived.d.ts +0 -2
  47. package/dist/dev/derived.js +1 -2
  48. package/dist/dev/element.d.ts +0 -2
  49. package/dist/dev/element.js +2 -3
  50. package/dist/dev/element.js.map +1 -1
  51. package/dist/dev/events.d.ts +0 -2
  52. package/dist/dev/events.js +16 -46
  53. package/dist/dev/events.js.map +1 -1
  54. package/dist/dev/head/components.d.ts +0 -2
  55. package/dist/dev/head/components.js +1 -2
  56. package/dist/dev/head/registry.js +1 -2
  57. package/dist/dev/head/server-head.d.ts +0 -2
  58. package/dist/dev/head/server-head.js +1 -2
  59. package/dist/dev/head/sink.js +1 -2
  60. package/dist/dev/head/use-head.d.ts +0 -2
  61. package/dist/dev/head/use-head.js +1 -2
  62. package/dist/dev/head/validate.d.ts +0 -2
  63. package/dist/dev/head/validate.js +1 -2
  64. package/dist/dev/hmr.d.ts +0 -2
  65. package/dist/dev/hmr.js +1 -2
  66. package/dist/dev/hydration.d.ts +0 -2
  67. package/dist/dev/hydration.js +1 -2
  68. package/dist/dev/insert.d.ts +15 -7
  69. package/dist/dev/insert.js +36 -15
  70. package/dist/dev/insert.js.map +1 -1
  71. package/dist/dev/internal/claim.d.ts +2 -3
  72. package/dist/dev/internal/claim.js +19 -4
  73. package/dist/dev/internal/claim.js.map +1 -1
  74. package/dist/dev/internal/css-units.js +1 -2
  75. package/dist/dev/internal/diagnostics.d.ts +7 -5
  76. package/dist/dev/internal/diagnostics.js +15 -6
  77. package/dist/dev/internal/diagnostics.js.map +1 -1
  78. package/dist/dev/internal/early-events.js +21 -4
  79. package/dist/dev/internal/early-events.js.map +1 -1
  80. package/dist/dev/internal/hydration-hooks.d.ts +0 -2
  81. package/dist/dev/internal/hydration-hooks.js +0 -1
  82. package/dist/dev/internal/hydration-scope.d.ts +0 -2
  83. package/dist/dev/internal/hydration-scope.js +1 -2
  84. package/dist/dev/internal/names.d.ts +0 -2
  85. package/dist/dev/internal/names.js +1 -2
  86. package/dist/dev/internal/portal-context.d.ts +0 -2
  87. package/dist/dev/internal/portal-context.js +1 -2
  88. package/dist/dev/internal/react-names.js +26 -63
  89. package/dist/dev/internal/react-names.js.map +1 -1
  90. package/dist/dev/internal/reconcile.d.ts +0 -2
  91. package/dist/dev/internal/reconcile.js +4 -8
  92. package/dist/dev/internal/reconcile.js.map +1 -1
  93. package/dist/dev/internal/stream-context.d.ts +0 -2
  94. package/dist/dev/internal/stream-context.js +1 -2
  95. package/dist/dev/jsx/aria.d.ts +0 -2
  96. package/dist/dev/jsx/component.d.ts +0 -2
  97. package/dist/dev/jsx/events.d.ts +0 -2
  98. package/dist/dev/jsx/global.d.ts +5 -4
  99. package/dist/dev/jsx/html.d.ts +1 -2
  100. package/dist/dev/jsx/intrinsic.d.ts +0 -2
  101. package/dist/dev/jsx/mathml.d.ts +0 -2
  102. package/dist/dev/jsx/svg.d.ts +0 -2
  103. package/dist/dev/jsx/types.d.ts +0 -2
  104. package/dist/dev/jsx-runtime.d.ts +0 -2
  105. package/dist/dev/reactive.d.ts +0 -2
  106. package/dist/dev/reactive.js +1 -2
  107. package/dist/dev/render.d.ts +0 -2
  108. package/dist/dev/render.js +1 -2
  109. package/dist/dev/resource-hints.d.ts +0 -2
  110. package/dist/dev/resource-hints.js +5 -4
  111. package/dist/dev/resource-hints.js.map +1 -1
  112. package/dist/dev/select-value.d.ts +0 -2
  113. package/dist/dev/select-value.js +6 -17
  114. package/dist/dev/select-value.js.map +1 -1
  115. package/dist/dev/server/attributes.d.ts +3 -2
  116. package/dist/dev/server/attributes.js +6 -3
  117. package/dist/dev/server/attributes.js.map +1 -1
  118. package/dist/dev/server/class-style.d.ts +0 -2
  119. package/dist/dev/server/class-style.js +1 -2
  120. package/dist/dev/server/component.d.ts +0 -2
  121. package/dist/dev/server/component.js +1 -2
  122. package/dist/dev/server/derived.d.ts +0 -2
  123. package/dist/dev/server/derived.js +1 -2
  124. package/dist/dev/server/element.d.ts +0 -2
  125. package/dist/dev/server/element.js +9 -6
  126. package/dist/dev/server/element.js.map +1 -1
  127. package/dist/dev/server/errors.js +8 -3
  128. package/dist/dev/server/errors.js.map +1 -1
  129. package/dist/dev/server/escape.d.ts +0 -2
  130. package/dist/dev/server/escape.js +15 -8
  131. package/dist/dev/server/escape.js.map +1 -1
  132. package/dist/dev/server/form-controls.d.ts +0 -2
  133. package/dist/dev/server/form-controls.js +6 -4
  134. package/dist/dev/server/form-controls.js.map +1 -1
  135. package/dist/dev/server/hydration-script.d.ts +0 -2
  136. package/dist/dev/server/hydration-script.js +1 -2
  137. package/dist/dev/server/index.d.ts +2 -1
  138. package/dist/dev/server/index.js +2 -1
  139. package/dist/dev/server/node.d.ts +0 -2
  140. package/dist/dev/server/node.js +1 -2
  141. package/dist/dev/server/portals.d.ts +0 -2
  142. package/dist/dev/server/portals.js +0 -1
  143. package/dist/dev/server/raw-text.d.ts +28 -0
  144. package/dist/dev/server/raw-text.js +66 -0
  145. package/dist/dev/server/raw-text.js.map +1 -0
  146. package/dist/dev/server/render.d.ts +2 -3
  147. package/dist/dev/server/render.js +3 -4
  148. package/dist/dev/server/render.js.map +1 -1
  149. package/dist/dev/server/serialize.d.ts +0 -2
  150. package/dist/dev/server/serialize.js +1 -2
  151. package/dist/dev/server/stream.d.ts +1 -3
  152. package/dist/dev/server/stream.js +3 -4
  153. package/dist/dev/server/stream.js.map +1 -1
  154. package/dist/dev/server.d.ts +2 -1
  155. package/dist/dev/server.js +2 -1
  156. package/dist/dev/spread.d.ts +0 -2
  157. package/dist/dev/spread.js +8 -56
  158. package/dist/dev/spread.js.map +1 -1
  159. package/dist/dev/template.d.ts +0 -2
  160. package/dist/dev/template.js +1 -2
  161. package/dist/dev/view-transition.d.ts +0 -2
  162. package/dist/dev/view-transition.js +1 -2
  163. package/dist/prod/attributes.js +1 -1
  164. package/dist/prod/attributes.js.map +1 -1
  165. package/dist/prod/class-style.js +1 -1
  166. package/dist/prod/class-style.js.map +1 -1
  167. package/dist/prod/control-flow/dynamic.js +1 -1
  168. package/dist/prod/control-flow/dynamic.js.map +1 -1
  169. package/dist/prod/control-flow/portal.js +1 -1
  170. package/dist/prod/control-flow/portal.js.map +1 -1
  171. package/dist/prod/element.js +1 -1
  172. package/dist/prod/element.js.map +1 -1
  173. package/dist/prod/events.js +1 -1
  174. package/dist/prod/events.js.map +1 -1
  175. package/dist/prod/insert.js +1 -1
  176. package/dist/prod/insert.js.map +1 -1
  177. package/dist/prod/internal/claim.js +1 -1
  178. package/dist/prod/internal/claim.js.map +1 -1
  179. package/dist/prod/internal/diagnostics.js +1 -1
  180. package/dist/prod/internal/diagnostics.js.map +1 -1
  181. package/dist/prod/internal/early-events.js +1 -1
  182. package/dist/prod/internal/early-events.js.map +1 -1
  183. package/dist/prod/internal/react-names.js +1 -1
  184. package/dist/prod/internal/react-names.js.map +1 -1
  185. package/dist/prod/internal/reconcile.js +1 -1
  186. package/dist/prod/internal/reconcile.js.map +1 -1
  187. package/dist/prod/resource-hints.js +1 -1
  188. package/dist/prod/resource-hints.js.map +1 -1
  189. package/dist/prod/select-value.js +1 -1
  190. package/dist/prod/select-value.js.map +1 -1
  191. package/dist/prod/server/attributes.js +1 -1
  192. package/dist/prod/server/attributes.js.map +1 -1
  193. package/dist/prod/server/element.js +1 -1
  194. package/dist/prod/server/element.js.map +1 -1
  195. package/dist/prod/server/errors.js +1 -1
  196. package/dist/prod/server/errors.js.map +1 -1
  197. package/dist/prod/server/escape.js +1 -1
  198. package/dist/prod/server/escape.js.map +1 -1
  199. package/dist/prod/server/form-controls.js +2 -2
  200. package/dist/prod/server/form-controls.js.map +1 -1
  201. package/dist/prod/server/index.js +1 -1
  202. package/dist/prod/server/raw-text.js +2 -0
  203. package/dist/prod/server/raw-text.js.map +1 -0
  204. package/dist/prod/server/render.js +1 -1
  205. package/dist/prod/server/render.js.map +1 -1
  206. package/dist/prod/server/stream.js +1 -1
  207. package/dist/prod/server/stream.js.map +1 -1
  208. package/dist/prod/server.js +1 -1
  209. package/dist/prod/spread.js +1 -1
  210. package/dist/prod/spread.js.map +1 -1
  211. package/dist/server/attributes.js +1 -1
  212. package/dist/server/attributes.js.map +1 -1
  213. package/dist/server/class-style.js +1 -1
  214. package/dist/server/class-style.js.map +1 -1
  215. package/dist/server/control-flow/dynamic.js +1 -1
  216. package/dist/server/control-flow/dynamic.js.map +1 -1
  217. package/dist/server/control-flow/portal.js +1 -1
  218. package/dist/server/control-flow/portal.js.map +1 -1
  219. package/dist/server/element.js +1 -1
  220. package/dist/server/element.js.map +1 -1
  221. package/dist/server/events.js +1 -1
  222. package/dist/server/events.js.map +1 -1
  223. package/dist/server/insert.js +1 -1
  224. package/dist/server/insert.js.map +1 -1
  225. package/dist/server/internal/claim.js +1 -1
  226. package/dist/server/internal/claim.js.map +1 -1
  227. package/dist/server/internal/diagnostics.js +1 -1
  228. package/dist/server/internal/diagnostics.js.map +1 -1
  229. package/dist/server/internal/early-events.js +1 -1
  230. package/dist/server/internal/early-events.js.map +1 -1
  231. package/dist/server/internal/react-names.js +1 -1
  232. package/dist/server/internal/react-names.js.map +1 -1
  233. package/dist/server/internal/reconcile.js +1 -1
  234. package/dist/server/internal/reconcile.js.map +1 -1
  235. package/dist/server/resource-hints.js +1 -1
  236. package/dist/server/resource-hints.js.map +1 -1
  237. package/dist/server/select-value.js +1 -1
  238. package/dist/server/select-value.js.map +1 -1
  239. package/dist/server/server/attributes.js +1 -1
  240. package/dist/server/server/attributes.js.map +1 -1
  241. package/dist/server/server/element.js +1 -1
  242. package/dist/server/server/element.js.map +1 -1
  243. package/dist/server/server/errors.js +1 -1
  244. package/dist/server/server/errors.js.map +1 -1
  245. package/dist/server/server/escape.js +1 -1
  246. package/dist/server/server/escape.js.map +1 -1
  247. package/dist/server/server/form-controls.js +2 -2
  248. package/dist/server/server/form-controls.js.map +1 -1
  249. package/dist/server/server/index.js +1 -1
  250. package/dist/server/server/raw-text.js +2 -0
  251. package/dist/server/server/raw-text.js.map +1 -0
  252. package/dist/server/server/render.js +1 -1
  253. package/dist/server/server/render.js.map +1 -1
  254. package/dist/server/server/stream.js +1 -1
  255. package/dist/server/server/stream.js.map +1 -1
  256. package/dist/server/server.js +1 -1
  257. package/dist/server/spread.js +1 -1
  258. package/dist/server/spread.js.map +1 -1
  259. package/dist/server-dev/attributes.js +28 -51
  260. package/dist/server-dev/attributes.js.map +1 -1
  261. package/dist/server-dev/autofocus.js +1 -2
  262. package/dist/server-dev/class-style.js +25 -9
  263. package/dist/server-dev/class-style.js.map +1 -1
  264. package/dist/server-dev/component.js +1 -2
  265. package/dist/server-dev/control-flow/activity.js +1 -2
  266. package/dist/server-dev/control-flow/branch.js +0 -1
  267. package/dist/server-dev/control-flow/client-only.js +1 -2
  268. package/dist/server-dev/control-flow/dynamic.js +23 -12
  269. package/dist/server-dev/control-flow/dynamic.js.map +1 -1
  270. package/dist/server-dev/control-flow/error-boundary.js +1 -2
  271. package/dist/server-dev/control-flow/for.js +1 -2
  272. package/dist/server-dev/control-flow/fragment.js +1 -2
  273. package/dist/server-dev/control-flow/hot-link.js +1 -2
  274. package/dist/server-dev/control-flow/index-list.js +1 -2
  275. package/dist/server-dev/control-flow/lazy.js +1 -2
  276. package/dist/server-dev/control-flow/no-hydration.js +1 -2
  277. package/dist/server-dev/control-flow/portal.js +3 -2
  278. package/dist/server-dev/control-flow/portal.js.map +1 -1
  279. package/dist/server-dev/control-flow/root-errors.js +1 -2
  280. package/dist/server-dev/control-flow/show.js +1 -2
  281. package/dist/server-dev/control-flow/suspense-list.js +1 -2
  282. package/dist/server-dev/control-flow/suspense.js +1 -2
  283. package/dist/server-dev/control-flow/switch.js +1 -2
  284. package/dist/server-dev/derived.js +1 -2
  285. package/dist/server-dev/element.js +4 -3
  286. package/dist/server-dev/element.js.map +1 -1
  287. package/dist/server-dev/events.js +16 -46
  288. package/dist/server-dev/events.js.map +1 -1
  289. package/dist/server-dev/head/components.js +1 -2
  290. package/dist/server-dev/head/registry.js +1 -2
  291. package/dist/server-dev/head/server-head.js +1 -2
  292. package/dist/server-dev/head/sink.js +1 -2
  293. package/dist/server-dev/head/use-head.js +1 -2
  294. package/dist/server-dev/head/validate.js +1 -2
  295. package/dist/server-dev/hydration.js +1 -2
  296. package/dist/server-dev/insert.js +36 -15
  297. package/dist/server-dev/insert.js.map +1 -1
  298. package/dist/server-dev/internal/claim.js +19 -4
  299. package/dist/server-dev/internal/claim.js.map +1 -1
  300. package/dist/server-dev/internal/css-units.js +1 -2
  301. package/dist/server-dev/internal/diagnostics.js +15 -6
  302. package/dist/server-dev/internal/diagnostics.js.map +1 -1
  303. package/dist/server-dev/internal/early-events.js +21 -4
  304. package/dist/server-dev/internal/early-events.js.map +1 -1
  305. package/dist/server-dev/internal/hydration-hooks.js +0 -1
  306. package/dist/server-dev/internal/hydration-scope.js +1 -2
  307. package/dist/server-dev/internal/names.js +1 -2
  308. package/dist/server-dev/internal/portal-context.js +1 -2
  309. package/dist/server-dev/internal/react-names.js +26 -63
  310. package/dist/server-dev/internal/react-names.js.map +1 -1
  311. package/dist/server-dev/internal/reconcile.js +4 -8
  312. package/dist/server-dev/internal/reconcile.js.map +1 -1
  313. package/dist/server-dev/internal/stream-context.js +1 -2
  314. package/dist/server-dev/reactive.js +1 -2
  315. package/dist/server-dev/render.js +1 -2
  316. package/dist/server-dev/resource-hints.js +5 -4
  317. package/dist/server-dev/resource-hints.js.map +1 -1
  318. package/dist/server-dev/select-value.js +6 -17
  319. package/dist/server-dev/select-value.js.map +1 -1
  320. package/dist/server-dev/server/attributes.js +6 -3
  321. package/dist/server-dev/server/attributes.js.map +1 -1
  322. package/dist/server-dev/server/class-style.js +1 -2
  323. package/dist/server-dev/server/component.js +1 -2
  324. package/dist/server-dev/server/derived.js +1 -2
  325. package/dist/server-dev/server/element.js +9 -6
  326. package/dist/server-dev/server/element.js.map +1 -1
  327. package/dist/server-dev/server/errors.js +8 -3
  328. package/dist/server-dev/server/errors.js.map +1 -1
  329. package/dist/server-dev/server/escape.js +15 -8
  330. package/dist/server-dev/server/escape.js.map +1 -1
  331. package/dist/server-dev/server/form-controls.js +6 -4
  332. package/dist/server-dev/server/form-controls.js.map +1 -1
  333. package/dist/server-dev/server/hydration-script.js +1 -2
  334. package/dist/server-dev/server/index.js +2 -1
  335. package/dist/server-dev/server/node.js +1 -2
  336. package/dist/server-dev/server/portals.js +0 -1
  337. package/dist/server-dev/server/raw-text.js +86 -0
  338. package/dist/server-dev/server/raw-text.js.map +1 -0
  339. package/dist/server-dev/server/render.js +3 -4
  340. package/dist/server-dev/server/render.js.map +1 -1
  341. package/dist/server-dev/server/serialize.js +1 -2
  342. package/dist/server-dev/server/stream.js +3 -4
  343. package/dist/server-dev/server/stream.js.map +1 -1
  344. package/dist/server-dev/server.js +2 -1
  345. package/dist/server-dev/spread.js +8 -56
  346. package/dist/server-dev/spread.js.map +1 -1
  347. package/dist/server-dev/template.js +1 -2
  348. package/dist/server-dev/view-transition.js +1 -2
  349. package/package.json +3 -2
@@ -3,7 +3,7 @@ import { claims } from "./internal/hydration-hooks.js";
3
3
  import { bindRegion, createRegion, removeRegion } from "./insert.js";
4
4
  import { attachRootErrors } from "./control-flow/root-errors.js";
5
5
  import { batch, createRoot, flushSync, untrack } from "@shadow-js/core";
6
- //#region src/render.ts
6
+ // src/render.ts
7
7
  /**
8
8
  * Mounts `code` into `container`. Creates an owner, inserts the output, flushes the effects, and
9
9
  * returns a dispose function that stops the owner and removes the nodes this call inserted. A
@@ -46,7 +46,6 @@ function render(code, container, options) {
46
46
  removeRegion(region);
47
47
  };
48
48
  }
49
- //#endregion
50
49
  export { render };
51
50
 
52
51
  //# sourceMappingURL=render.js.map
@@ -1,4 +1,3 @@
1
- //#region src/resource-hints.d.ts
2
1
  /**
3
2
  * Options of {@link preconnect}, {@link preloadModule} and {@link preinitModule}.
4
3
  * @since 1.0.0
@@ -141,5 +140,4 @@ export declare function preinit(href: string, options: PreinitOptions): void;
141
140
  * @since 1.0.0
142
141
  */
143
142
  export declare function preinitModule(href: string, options?: CrossOriginOptions): void;
144
- //#endregion
145
143
  //# sourceMappingURL=resource-hints.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { useHead } from "./head/use-head.js";
2
2
  import { isServer } from "@shadow-js/core";
3
- //#region src/resource-hints.ts
3
+ // src/resource-hints.ts
4
4
  /** Hints are page-level and only ever use http(s) URLs; anything else throws, like head tags do. */
5
5
  function checkUrl(href) {
6
6
  const url = new URL(href, "https://base.invalid");
@@ -13,7 +13,8 @@ function carries(element, attributes) {
13
13
  }
14
14
  /**
15
15
  * Inserts a hint element once: an identical element already in the head (server-rendered or added
16
- * earlier) is kept. On the server the hint joins the render's head collector, when there is one.
16
+ * earlier) is kept, and a script already anywhere in the document with the same `src` and `type` is
17
+ * not loaded again. On the server the hint joins the render's head collector, when there is one.
17
18
  */
18
19
  function hint(tag, attributes, serverTag = () => void 0) {
19
20
  if (isServer) {
@@ -21,7 +22,8 @@ function hint(tag, attributes, serverTag = () => void 0) {
21
22
  return;
22
23
  }
23
24
  if (typeof document === "undefined") return;
24
- for (const existing of document.head.querySelectorAll(tag)) if (carries(existing, attributes)) return;
25
+ const same = tag === "script" ? (existing) => existing.getAttribute("src") === attributes["src"] && (existing.getAttribute("type") ?? "") === (attributes["type"] ?? "") : (existing) => carries(existing, attributes);
26
+ for (const existing of (tag === "script" ? document : document.head).querySelectorAll(tag)) if (same(existing)) return;
25
27
  const element = document.createElement(tag);
26
28
  for (const [name, value] of Object.entries(attributes)) element.setAttribute(name, value);
27
29
  document.head.append(element);
@@ -194,7 +196,6 @@ function preinitModule(href, options) {
194
196
  ...options?.crossOrigin === void 0 ? {} : { crossorigin: options.crossOrigin }
195
197
  }));
196
198
  }
197
- //#endregion
198
199
  export { preconnect, prefetchDNS, preinit, preinitModule, preload, preloadModule };
199
200
 
200
201
  //# sourceMappingURL=resource-hints.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resource-hints.js","names":[],"sources":["../../src/resource-hints.ts"],"sourcesContent":["import { isServer } from \"@shadow-js/core\";\nimport { useHead } from \"./head/use-head\";\nimport type { HeadAttributeValue } from \"./head/validate\";\n\n/**\n * Options of {@link preconnect}, {@link preloadModule} and {@link preinitModule}.\n * @since 1.0.0\n */\nexport interface CrossOriginOptions {\n /**\n * CORS mode of the connection or request: `\"anonymous\"` sends no credentials, `\"use-credentials\"`\n * sends cookies and client certificates. Fonts and `fetch` preloads need one of them.\n * @default undefined (no `crossorigin` attribute; the browser's default for the resource applies)\n */\n readonly crossOrigin?: \"anonymous\" | \"use-credentials\";\n}\n\n/**\n * Options of {@link preload}: the destination is required, as the browser needs it to pick the\n * right request.\n * @since 1.0.0\n */\nexport interface PreloadOptions extends CrossOriginOptions {\n /**\n * The destination of the request, which the browser uses to pick its priority and headers. It\n * must match how the resource is used later, or the preloaded copy is not reused.\n */\n readonly as:\n | \"audio\"\n | \"document\"\n | \"embed\"\n | \"fetch\"\n | \"font\"\n | \"image\"\n | \"object\"\n | \"script\"\n | \"style\"\n | \"track\"\n | \"video\"\n | \"worker\";\n /**\n * MIME type, so the browser can skip unsupported formats (for example `font/woff2`).\n * @default undefined (no `type` attribute)\n */\n readonly type?: string;\n /**\n * Media query the hint applies to (for example `(min-width: 800px)`); the browser skips the\n * preload when it does not match.\n * @default undefined (no `media` attribute; the hint always applies)\n */\n readonly media?: string;\n}\n\n/**\n * Options of {@link preinit}.\n * @since 1.0.0\n */\nexport interface PreinitOptions extends CrossOriginOptions {\n /**\n * What to load: `\"style\"` inserts a stylesheet, `\"script\"` inserts an async script. Required, as\n * the two produce different elements.\n */\n readonly as: \"style\" | \"script\";\n}\n\ntype Attributes = Readonly<Record<string, string>>;\n\n/** Hints are page-level and only ever use http(s) URLs; anything else throws, like head tags do. */\nfunction checkUrl(href: string): void {\n const url = new URL(href, \"https://base.invalid\");\n if (url.protocol !== \"https:\" && url.protocol !== \"http:\") {\n throw new TypeError(\n __DEV__\n ? `resource hint: \"${href}\" must be an http(s) or relative URL`\n : \"SHADOW_RESOURCE_HINT_URL\",\n );\n }\n}\n\n/** Whether an element already carries every attribute of a hint (so the hint is already there). */\nfunction carries(element: Element, attributes: Attributes): boolean {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) return false;\n }\n return true;\n}\n\n/**\n * Inserts a hint element once: an identical element already in the head (server-rendered or added\n * earlier) is kept. On the server the hint joins the render's head collector, when there is one.\n */\nfunction hint(\n tag: \"link\" | \"script\",\n attributes: Attributes,\n serverTag: () => void = () => undefined,\n): void {\n if (isServer) {\n serverTag();\n return;\n }\n if (typeof document === \"undefined\") return;\n for (const existing of document.head.querySelectorAll(tag)) {\n if (carries(existing, attributes)) return;\n }\n const element = document.createElement(tag);\n for (const [name, value] of Object.entries(attributes)) element.setAttribute(name, value);\n document.head.append(element);\n}\n\n/** Server form of a hint: a head link (scripts cannot be head tags, see {@link preinitModule}). */\nfunction serverLink(attributes: Readonly<Record<string, HeadAttributeValue>>): () => void {\n return () => useHead({ tag: \"link\", props: attributes });\n}\n\n/**\n * Tells the browser to open a connection (DNS, TCP, TLS) to an origin the page will use soon.\n * React's `preconnect`. Calling it again for the same origin adds nothing. Works in a component, in\n * an event handler, or at module scope on the client.\n *\n * @param href An http(s) origin or URL.\n * @param options CORS mode (needed for fonts and fetch with credentials). Undefined adds no\n * `crossorigin` attribute.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or\n * relative.\n * @example\n * import { preconnect } from \"@shadow-js/web\";\n *\n * preconnect(\"https://fonts.example.com\", { crossOrigin: \"anonymous\" });\n * @see prefetchDNS\n * @see preload\n * @since 1.0.0\n */\nexport function preconnect(href: string, options?: CrossOriginOptions): void {\n checkUrl(href);\n const attributes: Attributes = {\n rel: \"preconnect\",\n href,\n ...(options?.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"link\", attributes, serverLink(attributes));\n}\n\n/**\n * Resolves an origin's DNS ahead of use. Cheaper than {@link preconnect}; React's `prefetchDNS`.\n * @param href An http(s) origin or URL.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { prefetchDNS } from \"@shadow-js/web\";\n *\n * prefetchDNS(\"https://api.example.com\");\n * @see preconnect\n * @since 1.0.0\n */\nexport function prefetchDNS(href: string): void {\n checkUrl(href);\n const attributes: Attributes = { rel: \"dns-prefetch\", href };\n hint(\"link\", attributes, serverLink(attributes));\n}\n\n/**\n * Starts fetching a resource the page will need, at high priority. The browser stores it for the\n * later request with the same URL and destination (React's `preload`).\n *\n * @param href An http(s) or relative URL.\n * @param options The destination (`as`, required) and the optional type, media and CORS mode.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { preload } from \"@shadow-js/web\";\n *\n * preload(\"/fonts/inter.woff2\", { as: \"font\", type: \"font/woff2\", crossOrigin: \"anonymous\" });\n * @see preloadModule\n * @see preinit\n * @since 1.0.0\n */\nexport function preload(href: string, options: PreloadOptions): void {\n checkUrl(href);\n const attributes: Attributes = {\n rel: \"preload\",\n href,\n as: options.as,\n ...(options.type === undefined ? {} : { type: options.type }),\n ...(options.media === undefined ? {} : { media: options.media }),\n ...(options.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"link\", attributes, serverLink(attributes));\n}\n\n/**\n * Starts loading an ES module the page will import, so the import does not wait for the module\n * graph to be discovered. React's `preloadModule`.\n * @param href An http(s) or relative URL of the module.\n * @param options CORS mode. Undefined adds no `crossorigin` attribute.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { preloadModule } from \"@shadow-js/web\";\n *\n * preloadModule(\"/chunks/editor.js\");\n * @see preinitModule\n * @see preload\n * @since 1.0.0\n */\nexport function preloadModule(href: string, options?: CrossOriginOptions): void {\n checkUrl(href);\n const attributes: Attributes = {\n rel: \"modulepreload\",\n href,\n ...(options?.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"link\", attributes, serverLink(attributes));\n}\n\n/**\n * Loads a stylesheet or script now, and keeps it applied or executed (React's `preinit`). A\n * stylesheet becomes a `<link rel=\"stylesheet\">`; a script becomes an async `<script>` in the head.\n * On the server a script can only be hinted as a preload, because head tags cannot be scripts.\n *\n * @param href An http(s) or relative URL.\n * @param options What to load (`style` or `script`, required) and the CORS mode.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { preinit } from \"@shadow-js/web\";\n *\n * preinit(\"/theme.css\", { as: \"style\" });\n * @see preload\n * @see preinitModule\n * @since 1.0.0\n */\nexport function preinit(href: string, options: PreinitOptions): void {\n checkUrl(href);\n if (options.as === \"style\") {\n const attributes: Attributes = {\n rel: \"stylesheet\",\n href,\n ...(options.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"link\", attributes, serverLink(attributes));\n return;\n }\n const attributes: Attributes = {\n src: href,\n async: \"\",\n ...(options.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"script\", attributes, serverLink({ rel: \"preload\", href, as: \"script\" }));\n}\n\n/**\n * Loads and runs an ES module now (React's `preinitModule`). On the client it inserts a\n * `<script type=\"module\">`; on the server it hints the module with `modulepreload`, since the\n * script itself is loaded by the page.\n *\n * @param href An http(s) or relative URL of the module.\n * @param options CORS mode. Undefined adds no `crossorigin` attribute.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { preinitModule } from \"@shadow-js/web\";\n *\n * preinitModule(\"/chunks/app.js\");\n * @see preloadModule\n * @see preinit\n * @since 1.0.0\n */\nexport function preinitModule(href: string, options?: CrossOriginOptions): void {\n checkUrl(href);\n const attributes: Attributes = {\n src: href,\n type: \"module\",\n ...(options?.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\n \"script\",\n attributes,\n serverLink({\n rel: \"modulepreload\",\n href,\n ...(options?.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n }),\n );\n}\n"],"mappings":";;;;AAoEA,SAAS,SAAS,MAAoB;CACpC,MAAM,MAAM,IAAI,IAAI,MAAM,sBAAsB;CAChD,IAAI,IAAI,aAAa,YAAY,IAAI,aAAa,SAChD,MAAM,IAAI,UAEJ,mBAAmB,KAAK,qCAE9B;AAEJ;;AAGA,SAAS,QAAQ,SAAkB,YAAiC;CAClE,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,UAAU,GACnD,IAAI,QAAQ,aAAa,IAAI,MAAM,OAAO,OAAO;CAEnD,OAAO;AACT;;;;;AAMA,SAAS,KACP,KACA,YACA,kBAA8B,KAAA,GACxB;CACN,IAAI,UAAU;EACZ,UAAU;EACV;CACF;CACA,IAAI,OAAO,aAAa,aAAa;CACrC,KAAK,MAAM,YAAY,SAAS,KAAK,iBAAiB,GAAG,GACvD,IAAI,QAAQ,UAAU,UAAU,GAAG;CAErC,MAAM,UAAU,SAAS,cAAc,GAAG;CAC1C,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,UAAU,GAAG,QAAQ,aAAa,MAAM,KAAK;CACxF,SAAS,KAAK,OAAO,OAAO;AAC9B;;AAGA,SAAS,WAAW,YAAsE;CACxF,aAAa,QAAQ;EAAE,KAAK;EAAQ,OAAO;CAAW,CAAC;AACzD;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,WAAW,MAAc,SAAoC;CAC3E,SA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C;EAC/C;CACF;CAMA,KAAK,UAAU;EAJb,KAAK;EACL,OAAO;EACP,GAAI,QAAQ,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;CAE1D,GAAG,WAAW;EAAE,KAAK;EAAW;EAAM,IAAI;CAAS,CAAC,CAAC;AAC/E;;;;;;;;;;;;;;;;;AAkBA,SAAgB,cAAc,MAAc,SAAoC;CAC9E,SAAS,IAAI;CAMb,KACE,UACA;EANA,KAAK;EACL,MAAM;EACN,GAAI,SAAS,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;CAIxE,GACT,WAAW;EACT,KAAK;EACL;EACA,GAAI,SAAS,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;CACnF,CAAC,CACH;AACF"}
1
+ {"version":3,"file":"resource-hints.js","names":[],"sources":["../../src/resource-hints.ts"],"sourcesContent":["import { isServer } from \"@shadow-js/core\";\nimport { useHead } from \"./head/use-head\";\nimport type { HeadAttributeValue } from \"./head/validate\";\n\n/**\n * Options of {@link preconnect}, {@link preloadModule} and {@link preinitModule}.\n * @since 1.0.0\n */\nexport interface CrossOriginOptions {\n /**\n * CORS mode of the connection or request: `\"anonymous\"` sends no credentials, `\"use-credentials\"`\n * sends cookies and client certificates. Fonts and `fetch` preloads need one of them.\n * @default undefined (no `crossorigin` attribute; the browser's default for the resource applies)\n */\n readonly crossOrigin?: \"anonymous\" | \"use-credentials\";\n}\n\n/**\n * Options of {@link preload}: the destination is required, as the browser needs it to pick the\n * right request.\n * @since 1.0.0\n */\nexport interface PreloadOptions extends CrossOriginOptions {\n /**\n * The destination of the request, which the browser uses to pick its priority and headers. It\n * must match how the resource is used later, or the preloaded copy is not reused.\n */\n readonly as:\n | \"audio\"\n | \"document\"\n | \"embed\"\n | \"fetch\"\n | \"font\"\n | \"image\"\n | \"object\"\n | \"script\"\n | \"style\"\n | \"track\"\n | \"video\"\n | \"worker\";\n /**\n * MIME type, so the browser can skip unsupported formats (for example `font/woff2`).\n * @default undefined (no `type` attribute)\n */\n readonly type?: string;\n /**\n * Media query the hint applies to (for example `(min-width: 800px)`); the browser skips the\n * preload when it does not match.\n * @default undefined (no `media` attribute; the hint always applies)\n */\n readonly media?: string;\n}\n\n/**\n * Options of {@link preinit}.\n * @since 1.0.0\n */\nexport interface PreinitOptions extends CrossOriginOptions {\n /**\n * What to load: `\"style\"` inserts a stylesheet, `\"script\"` inserts an async script. Required, as\n * the two produce different elements.\n */\n readonly as: \"style\" | \"script\";\n}\n\ntype Attributes = Readonly<Record<string, string>>;\n\n/** Hints are page-level and only ever use http(s) URLs; anything else throws, like head tags do. */\nfunction checkUrl(href: string): void {\n const url = new URL(href, \"https://base.invalid\");\n if (url.protocol !== \"https:\" && url.protocol !== \"http:\") {\n throw new TypeError(\n __DEV__\n ? `resource hint: \"${href}\" must be an http(s) or relative URL`\n : \"SHADOW_RESOURCE_HINT_URL\",\n );\n }\n}\n\n/** Whether an element already carries every attribute of a hint (so the hint is already there). */\nfunction carries(element: Element, attributes: Attributes): boolean {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) return false;\n }\n return true;\n}\n\n/**\n * Inserts a hint element once: an identical element already in the head (server-rendered or added\n * earlier) is kept, and a script already anywhere in the document with the same `src` and `type` is\n * not loaded again. On the server the hint joins the render's head collector, when there is one.\n */\nfunction hint(\n tag: \"link\" | \"script\",\n attributes: Attributes,\n serverTag: () => void = () => undefined,\n): void {\n if (isServer) {\n serverTag();\n return;\n }\n if (typeof document === \"undefined\") return;\n // A script is the same load when its URL and kind match: the page's own bundle usually sits at the end\n // of the body, and carries `defer` or `async` or neither, so the attributes of the hint are no test.\n const same =\n tag === \"script\"\n ? (existing: Element): boolean =>\n existing.getAttribute(\"src\") === attributes[\"src\"] &&\n (existing.getAttribute(\"type\") ?? \"\") === (attributes[\"type\"] ?? \"\")\n : (existing: Element): boolean => carries(existing, attributes);\n for (const existing of (tag === \"script\" ? document : document.head).querySelectorAll(tag)) {\n if (same(existing)) return;\n }\n const element = document.createElement(tag);\n for (const [name, value] of Object.entries(attributes)) element.setAttribute(name, value);\n document.head.append(element);\n}\n\n/** Server form of a hint: a head link (scripts cannot be head tags, see {@link preinitModule}). */\nfunction serverLink(attributes: Readonly<Record<string, HeadAttributeValue>>): () => void {\n return () => useHead({ tag: \"link\", props: attributes });\n}\n\n/**\n * Tells the browser to open a connection (DNS, TCP, TLS) to an origin the page will use soon.\n * React's `preconnect`. Calling it again for the same origin adds nothing. Works in a component, in\n * an event handler, or at module scope on the client.\n *\n * @param href An http(s) origin or URL.\n * @param options CORS mode (needed for fonts and fetch with credentials). Undefined adds no\n * `crossorigin` attribute.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or\n * relative.\n * @example\n * import { preconnect } from \"@shadow-js/web\";\n *\n * preconnect(\"https://fonts.example.com\", { crossOrigin: \"anonymous\" });\n * @see prefetchDNS\n * @see preload\n * @since 1.0.0\n */\nexport function preconnect(href: string, options?: CrossOriginOptions): void {\n checkUrl(href);\n const attributes: Attributes = {\n rel: \"preconnect\",\n href,\n ...(options?.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"link\", attributes, serverLink(attributes));\n}\n\n/**\n * Resolves an origin's DNS ahead of use. Cheaper than {@link preconnect}; React's `prefetchDNS`.\n * @param href An http(s) origin or URL.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { prefetchDNS } from \"@shadow-js/web\";\n *\n * prefetchDNS(\"https://api.example.com\");\n * @see preconnect\n * @since 1.0.0\n */\nexport function prefetchDNS(href: string): void {\n checkUrl(href);\n const attributes: Attributes = { rel: \"dns-prefetch\", href };\n hint(\"link\", attributes, serverLink(attributes));\n}\n\n/**\n * Starts fetching a resource the page will need, at high priority. The browser stores it for the\n * later request with the same URL and destination (React's `preload`).\n *\n * @param href An http(s) or relative URL.\n * @param options The destination (`as`, required) and the optional type, media and CORS mode.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { preload } from \"@shadow-js/web\";\n *\n * preload(\"/fonts/inter.woff2\", { as: \"font\", type: \"font/woff2\", crossOrigin: \"anonymous\" });\n * @see preloadModule\n * @see preinit\n * @since 1.0.0\n */\nexport function preload(href: string, options: PreloadOptions): void {\n checkUrl(href);\n const attributes: Attributes = {\n rel: \"preload\",\n href,\n as: options.as,\n ...(options.type === undefined ? {} : { type: options.type }),\n ...(options.media === undefined ? {} : { media: options.media }),\n ...(options.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"link\", attributes, serverLink(attributes));\n}\n\n/**\n * Starts loading an ES module the page will import, so the import does not wait for the module\n * graph to be discovered. React's `preloadModule`.\n * @param href An http(s) or relative URL of the module.\n * @param options CORS mode. Undefined adds no `crossorigin` attribute.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { preloadModule } from \"@shadow-js/web\";\n *\n * preloadModule(\"/chunks/editor.js\");\n * @see preinitModule\n * @see preload\n * @since 1.0.0\n */\nexport function preloadModule(href: string, options?: CrossOriginOptions): void {\n checkUrl(href);\n const attributes: Attributes = {\n rel: \"modulepreload\",\n href,\n ...(options?.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"link\", attributes, serverLink(attributes));\n}\n\n/**\n * Loads a stylesheet or script now, and keeps it applied or executed (React's `preinit`). A\n * stylesheet becomes a `<link rel=\"stylesheet\">`; a script becomes an async `<script>` in the head.\n * On the server a script can only be hinted as a preload, because head tags cannot be scripts.\n *\n * @param href An http(s) or relative URL.\n * @param options What to load (`style` or `script`, required) and the CORS mode.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { preinit } from \"@shadow-js/web\";\n *\n * preinit(\"/theme.css\", { as: \"style\" });\n * @see preload\n * @see preinitModule\n * @since 1.0.0\n */\nexport function preinit(href: string, options: PreinitOptions): void {\n checkUrl(href);\n if (options.as === \"style\") {\n const attributes: Attributes = {\n rel: \"stylesheet\",\n href,\n ...(options.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"link\", attributes, serverLink(attributes));\n return;\n }\n const attributes: Attributes = {\n src: href,\n async: \"\",\n ...(options.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"script\", attributes, serverLink({ rel: \"preload\", href, as: \"script\" }));\n}\n\n/**\n * Loads and runs an ES module now (React's `preinitModule`). On the client it inserts a\n * `<script type=\"module\">`; on the server it hints the module with `modulepreload`, since the\n * script itself is loaded by the page.\n *\n * @param href An http(s) or relative URL of the module.\n * @param options CORS mode. Undefined adds no `crossorigin` attribute.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { preinitModule } from \"@shadow-js/web\";\n *\n * preinitModule(\"/chunks/app.js\");\n * @see preloadModule\n * @see preinit\n * @since 1.0.0\n */\nexport function preinitModule(href: string, options?: CrossOriginOptions): void {\n checkUrl(href);\n const attributes: Attributes = {\n src: href,\n type: \"module\",\n ...(options?.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\n \"script\",\n attributes,\n serverLink({\n rel: \"modulepreload\",\n href,\n ...(options?.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n }),\n );\n}\n"],"mappings":";;;;AAoEA,SAAS,SAAS,MAAoB;CACpC,MAAM,MAAM,IAAI,IAAI,MAAM,sBAAsB;CAChD,IAAI,IAAI,aAAa,YAAY,IAAI,aAAa,SAChD,MAAM,IAAI,UAEJ,mBAAmB,KAAK,qCAE9B;AAEJ;;AAGA,SAAS,QAAQ,SAAkB,YAAiC;CAClE,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,UAAU,GACnD,I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AAa,QAAQ,YAAY;CACnF,CAAC,CACH;AACF"}
@@ -1,4 +1,3 @@
1
- //#region src/select-value.d.ts
2
1
  /**
3
2
  * Selects the options a `value` stands for. The compiler calls it for `<select value={...}>`. A
4
3
  * single value behaves like `select.value = value` (`null` and `undefined` are the empty string).
@@ -20,5 +19,4 @@
20
19
  * @since 1.0.0
21
20
  */
22
21
  export declare function setSelectValue(select: HTMLSelectElement, value: unknown): void;
23
- //#endregion
24
22
  //# sourceMappingURL=select-value.d.ts.map
@@ -1,12 +1,10 @@
1
- //#region src/select-value.ts
1
+ // src/select-value.ts
2
2
  /** The values an array stands for, as strings; null and undefined entries are skipped. */
3
3
  function listed(value) {
4
- const values = /* @__PURE__ */ new Set();
5
- for (const item of value) if (item !== null && item !== void 0) values.add(String(item));
6
- return values;
4
+ return new Set(value.filter((item) => item !== null && item !== void 0).map(String));
7
5
  }
8
- /** The string a single value assigns to `select.value`; null and undefined clear the choice. */
9
- function single(value) {
6
+ /** The string a value assigns to `select.value`, `innerHTML` or `textContent`; null and undefined are empty. @internal */
7
+ function plainText(value) {
10
8
  return value === null || value === void 0 ? "" : String(value);
11
9
  }
12
10
  /**
@@ -35,17 +33,8 @@ function setSelectValue(select, value) {
35
33
  for (const option of Array.from(select.options)) option.selected = wanted.has(option.value);
36
34
  return;
37
35
  }
38
- select.value = single(value);
36
+ select.value = plainText(value);
39
37
  }
40
- /** True when the select already shows `value` the way {@link setSelectValue} would leave it. @internal */
41
- function selectShows(select, value) {
42
- if (select.multiple && Array.isArray(value)) {
43
- const wanted = listed(value);
44
- return Array.from(select.options).every((option) => option.selected === wanted.has(option.value));
45
- }
46
- return select.value === single(value);
47
- }
48
- //#endregion
49
- export { selectShows, setSelectValue };
38
+ export { plainText, setSelectValue };
50
39
 
51
40
  //# sourceMappingURL=select-value.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"select-value.js","names":[],"sources":["../../src/select-value.ts"],"sourcesContent":["/** The values an array stands for, as strings; null and undefined entries are skipped. */\nfunction listed(value: readonly unknown[]): Set<string> {\n const values = new Set<string>();\n for (const item of value) {\n if (item !== null && item !== undefined) values.add(String(item));\n }\n return values;\n}\n\n/** The string a single value assigns to `select.value`; null and undefined clear the choice. */\nfunction single(value: unknown): string {\n return value === null || value === undefined ? \"\" : String(value);\n}\n\n/**\n * Selects the options a `value` stands for. The compiler calls it for `<select value={...}>`. A\n * single value behaves like `select.value = value` (`null` and `undefined` are the empty string).\n * On a `<select multiple>` an array selects exactly the options whose value it lists and clears\n * the others. The server writes the same state as `selected` on the options (`ssrSelectValue`).\n *\n * @param select The select element; its options must already be in it.\n * @param value A string or number (written as `String(value)`), or `null`/`undefined` (written as\n * `\"\"`: an option with an empty value is selected, otherwise none). For a `multiple` select, an array of them: `null` and `undefined`\n * entries are skipped. An array on a single select is written as `String(array)`.\n * @example\n * import { setSelectValue } from \"@shadow-js/web\";\n *\n * const select = document.createElement(\"select\");\n * select.multiple = true;\n * select.append(new Option(\"A\", \"a\"), new Option(\"B\", \"b\"), new Option(\"C\", \"c\"));\n * setSelectValue(select, [\"a\", \"c\"]); // A and C selected, B cleared\n * @see ssrSelectValue\n * @since 1.0.0\n */\nexport function setSelectValue(select: HTMLSelectElement, value: unknown): void {\n if (select.multiple && Array.isArray(value)) {\n const wanted = listed(value);\n for (const option of Array.from(select.options)) option.selected = wanted.has(option.value);\n return;\n }\n select.value = single(value);\n}\n\n/** True when the select already shows `value` the way {@link setSelectValue} would leave it. @internal */\nexport function selectShows(select: HTMLSelectElement, value: unknown): boolean {\n if (select.multiple && Array.isArray(value)) {\n const wanted = listed(value);\n return Array.from(select.options).every(\n (option) => option.selected === wanted.has(option.value),\n );\n }\n return select.value === single(value);\n}\n"],"mappings":";;AACA,SAAS,OAAO,OAAwC;CACtD,MAAM,yBAAS,IAAI,IAAY;CAC/B,KAAK,MAAM,QAAQ,OACjB,IAAI,SAAS,QAAQ,SAAS,KAAA,GAAW,OAAO,IAAI,OAAO,IAAI,CAAC;CAElE,OAAO;AACT;;AAGA,SAAS,OAAO,OAAwB;CACtC,OAAO,UAAU,QAAQ,UAAU,KAAA,IAAY,KAAK,OAAO,KAAK;AAClE;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,eAAe,QAA2B,OAAsB;CAC9E,IAAI,OAAO,YAAY,MAAM,QAAQ,KAAK,GAAG;EAC3C,MAAM,SAAS,OAAO,KAAK;EAC3B,KAAK,MAAM,UAAU,MAAM,KAAK,OAAO,OAAO,GAAG,OAAO,WAAW,OAAO,IAAI,OAAO,KAAK;EAC1F;CACF;CACA,OAAO,QAAQ,OAAO,KAAK;AAC7B;;AAGA,SAAgB,YAAY,QAA2B,OAAyB;CAC9E,IAAI,OAAO,YAAY,MAAM,QAAQ,KAAK,GAAG;EAC3C,MAAM,SAAS,OAAO,KAAK;EAC3B,OAAO,MAAM,KAAK,OAAO,OAAO,CAAC,CAAC,OAC/B,WAAW,OAAO,aAAa,OAAO,IAAI,OAAO,KAAK,CACzD;CACF;CACA,OAAO,OAAO,UAAU,OAAO,KAAK;AACtC"}
1
+ {"version":3,"file":"select-value.js","names":[],"sources":["../../src/select-value.ts"],"sourcesContent":["/** The values an array stands for, as strings; null and undefined entries are skipped. */\nfunction listed(value: readonly unknown[]): Set<string> {\n return new Set(value.filter((item) => item !== null && item !== undefined).map(String));\n}\n\n/** The string a value assigns to `select.value`, `innerHTML` or `textContent`; null and undefined are empty. @internal */\nexport function plainText(value: unknown): string {\n return value === null || value === undefined ? \"\" : String(value);\n}\n\n/**\n * Selects the options a `value` stands for. The compiler calls it for `<select value={...}>`. A\n * single value behaves like `select.value = value` (`null` and `undefined` are the empty string).\n * On a `<select multiple>` an array selects exactly the options whose value it lists and clears\n * the others. The server writes the same state as `selected` on the options (`ssrSelectValue`).\n *\n * @param select The select element; its options must already be in it.\n * @param value A string or number (written as `String(value)`), or `null`/`undefined` (written as\n * `\"\"`: an option with an empty value is selected, otherwise none). For a `multiple` select, an array of them: `null` and `undefined`\n * entries are skipped. An array on a single select is written as `String(array)`.\n * @example\n * import { setSelectValue } from \"@shadow-js/web\";\n *\n * const select = document.createElement(\"select\");\n * select.multiple = true;\n * select.append(new Option(\"A\", \"a\"), new Option(\"B\", \"b\"), new Option(\"C\", \"c\"));\n * setSelectValue(select, [\"a\", \"c\"]); // A and C selected, B cleared\n * @see ssrSelectValue\n * @since 1.0.0\n */\nexport function setSelectValue(select: HTMLSelectElement, value: unknown): void {\n if (select.multiple && Array.isArray(value)) {\n const wanted = listed(value);\n for (const option of Array.from(select.options)) option.selected = wanted.has(option.value);\n return;\n }\n select.value = plainText(value);\n}\n"],"mappings":";;AACA,SAAS,OAAO,OAAwC;CACtD,OAAO,IAAI,IAAI,MAAM,QAAQ,SAAS,SAAS,QAAQ,SAAS,KAAA,CAAS,CAAC,CAAC,IAAI,MAAM,CAAC;AACxF;;AAGA,SAAgB,UAAU,OAAwB;CAChD,OAAO,UAAU,QAAQ,UAAU,KAAA,IAAY,KAAK,OAAO,KAAK;AAClE;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,eAAe,QAA2B,OAAsB;CAC9E,IAAI,OAAO,YAAY,MAAM,QAAQ,KAAK,GAAG;EAC3C,MAAM,SAAS,OAAO,KAAK;EAC3B,KAAK,MAAM,UAAU,MAAM,KAAK,OAAO,OAAO,GAAG,OAAO,WAAW,OAAO,IAAI,OAAO,KAAK;EAC1F;CACF;CACA,OAAO,QAAQ,UAAU,KAAK;AAChC"}
@@ -1,4 +1,3 @@
1
- //#region src/server/attributes.d.ts
2
1
  /**
3
2
  * Renders one attribute as markup with a leading space, or `""` when the attribute is absent: the
4
3
  * helper the compiler's server output calls for a dynamic attribute. It applies the client's value
@@ -9,6 +8,9 @@
9
8
  * `"true"` for those same names). Other values are written as `String(value)`, HTML-escaped.
10
9
  * - URL attributes whose value would run script are dropped, with the check of
11
10
  * `isUnsafeUrlAttribute` (including the SVG animation attributes `values`, `from`, `to`, `by`).
11
+ * - `srcdoc` is an HTML sink, not a URL: its value is a document the frame runs, escaped for the attribute
12
+ * and otherwise written as it is, with the trust of `innerHTML`. Sanitize it and give the frame a `sandbox`
13
+ * attribute. Development builds warn once with `SRCDOC_DYNAMIC`.
12
14
  * - `on*` names are dropped: event handlers never reach markup.
13
15
  * - Accessors are called (untracked) until a plain value remains.
14
16
  *
@@ -29,5 +31,4 @@
29
31
  * @since 1.0.0
30
32
  */
31
33
  export declare function ssrAttribute(name: string, value: unknown, isBoolean?: boolean): string;
32
- //#endregion
33
34
  //# sourceMappingURL=attributes.d.ts.map
@@ -1,6 +1,7 @@
1
+ import { SRCDOC_DYNAMIC_DETAIL, warnOnce } from "../internal/diagnostics.js";
1
2
  import { invalid } from "./errors.js";
2
3
  import { escapeHtml, resolveValue } from "./escape.js";
3
- //#region src/server/attributes.ts
4
+ // src/server/attributes.ts
4
5
  /** Names that can appear in markup: an XML-name subset without `@` or whitespace. Same as the client. */
5
6
  const ATTRIBUTE_NAME = /^[A-Za-z_:][A-Za-z0-9_:.-]*$/;
6
7
  /** Attributes whose value is a URL and is therefore checked for script schemes. Same as the client. */
@@ -10,7 +11,6 @@ const URL_ATTRIBUTES = /* @__PURE__ */ new Set([
10
11
  "action",
11
12
  "formaction",
12
13
  "xlink:href",
13
- "srcdoc",
14
14
  "poster",
15
15
  "data"
16
16
  ]);
@@ -118,6 +118,9 @@ function assertNotSymbol(value) {
118
118
  * `"true"` for those same names). Other values are written as `String(value)`, HTML-escaped.
119
119
  * - URL attributes whose value would run script are dropped, with the check of
120
120
  * `isUnsafeUrlAttribute` (including the SVG animation attributes `values`, `from`, `to`, `by`).
121
+ * - `srcdoc` is an HTML sink, not a URL: its value is a document the frame runs, escaped for the attribute
122
+ * and otherwise written as it is, with the trust of `innerHTML`. Sanitize it and give the frame a `sandbox`
123
+ * attribute. Development builds warn once with `SRCDOC_DYNAMIC`.
121
124
  * - `on*` names are dropped: event handlers never reach markup.
122
125
  * - Accessors are called (untracked) until a plain value remains.
123
126
  *
@@ -146,10 +149,10 @@ function ssrAttribute(name, value, isBoolean = false) {
146
149
  if (isBoolean) return resolved ? ` ${name}` : "";
147
150
  const text = attributeText(lowerName, resolved);
148
151
  if (text === null) return "";
152
+ if (lowerName === "srcdoc") warnOnce("SRCDOC_DYNAMIC", SRCDOC_DYNAMIC_DETAIL);
149
153
  if (isUnsafeAttributeValue(lowerName, text)) return "";
150
154
  return ` ${name}="${escapeHtml(text)}"`;
151
155
  }
152
- //#endregion
153
156
  export { BOOLEAN_ATTRIBUTES, assertAttributeName, attributeText, isEventName, isUnsafeUrl, ssrAttribute };
154
157
 
155
158
  //# sourceMappingURL=attributes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"attributes.js","names":[],"sources":["../../../src/server/attributes.ts"],"sourcesContent":["import { invalid } from \"./errors\";\nimport { escapeHtml, resolveValue } from \"./escape\";\n\n/** Names that can appear in markup: an XML-name subset without `@` or whitespace. Same as the client. */\nconst ATTRIBUTE_NAME = /^[A-Za-z_:][A-Za-z0-9_:.-]*$/;\n\n/** Attributes whose value is a URL and is therefore checked for script schemes. Same as the client. */\nconst URL_ATTRIBUTES: ReadonlySet<string> = new Set([\n \"href\",\n \"src\",\n \"action\",\n \"formaction\",\n \"xlink:href\",\n \"srcdoc\",\n \"poster\",\n \"data\",\n]);\n\n/**\n * SVG animation attributes (`animate`, `set`): with `attributeName=\"href\"` they write an `href` by animation, so their value\n * is checked like one. `values` is a `;` list and every entry is checked. Same as the client.\n */\nconst ANIMATION_VALUE_ATTRIBUTES: ReadonlySet<string> = new Set([\"values\", \"from\", \"to\", \"by\"]);\n\n/** Enumerated attributes where `false` is a real value (\"false\") rather than an absence. */\nconst ENUMERATED_ATTRIBUTES: ReadonlySet<string> = new Set([\n \"draggable\",\n \"spellcheck\",\n \"contenteditable\",\n]);\n\n/**\n * Boolean attributes that a props object writes as presence flags (`disabled: true` gives a bare\n * `disabled`). Lower-case names only.\n * @internal\n */\nexport const BOOLEAN_ATTRIBUTES: ReadonlySet<string> = new Set([\n \"async\",\n \"autofocus\",\n \"autoplay\",\n \"checked\",\n \"controls\",\n \"default\",\n \"defer\",\n \"disabled\",\n \"formnovalidate\",\n \"hidden\",\n \"inert\",\n \"ismap\",\n \"loop\",\n \"multiple\",\n \"muted\",\n \"nomodule\",\n \"novalidate\",\n \"open\",\n \"playsinline\",\n \"readonly\",\n \"required\",\n \"reversed\",\n \"selected\",\n]);\n\n/** URL prefixes (after normalization) that are never written. Same as the client. */\nconst UNSAFE_URL_PREFIXES: readonly string[] = [\"javascript:\", \"data:text/html\", \"vbscript:\"];\n\n/** Throws a TypeError unless `name` can be written as an attribute name. @internal */\nexport function assertAttributeName(name: string): void {\n if (!ATTRIBUTE_NAME.test(name)) {\n throw invalid(\"INVALID_ATTRIBUTE_NAME\", `\"${name}\" is not a valid attribute name.`);\n }\n}\n\n/** True for `on*` names, which never reach markup. Length matches the client's event test. @internal */\nexport function isEventName(lowerName: string): boolean {\n return lowerName.length > 2 && lowerName.startsWith(\"on\");\n}\n\n/** True for `aria-*`, `data-*` and the enumerated attributes: their booleans are strings. */\nfunction isStringValued(lowerName: string): boolean {\n return (\n lowerName.startsWith(\"aria-\") ||\n lowerName.startsWith(\"data-\") ||\n ENUMERATED_ATTRIBUTES.has(lowerName)\n );\n}\n\n/** Removes C0 and C1 control characters, which browsers ignore inside a URL scheme. */\nfunction stripControls(text: string): string {\n let kept = \"\";\n for (const char of text) {\n const code = char.charCodeAt(0);\n if (code > 0x1f && (code < 0x7f || code > 0x9f)) kept += char;\n }\n return kept;\n}\n\n/** True when the URL would run script, after the normalization browsers apply. @internal */\nexport function isUnsafeUrl(value: string): boolean {\n const normalized = stripControls(value).trim().toLowerCase();\n return UNSAFE_URL_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n\n/** True when `lowerName` carries a URL (or an animated one) and `value` would run script. */\nfunction isUnsafeAttributeValue(lowerName: string, value: string): boolean {\n if (URL_ATTRIBUTES.has(lowerName)) return isUnsafeUrl(value);\n return ANIMATION_VALUE_ATTRIBUTES.has(lowerName) && value.split(\";\").some(isUnsafeUrl);\n}\n\n/** Text to write for `value`, or null when the attribute is removed. Same rules as the client. @internal */\nexport function attributeText(lowerName: string, value: unknown): string | null {\n if (value === null || value === undefined) return null;\n if (value === false) return isStringValued(lowerName) ? \"false\" : null;\n if (value === true) return isStringValued(lowerName) ? \"true\" : \"\";\n return String(value);\n}\n\n/** Refuses symbols, which have no markup form and would otherwise be coerced silently. */\nfunction assertNotSymbol(value: unknown): void {\n if (typeof value === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be an attribute value.\");\n }\n}\n\n/**\n * Renders one attribute as markup with a leading space, or `\"\"` when the attribute is absent: the\n * helper the compiler's server output calls for a dynamic attribute. It applies the client's value\n * rules and URL check, so server and client agree on what is written.\n *\n * - `null`, `undefined` and `false` give `\"\"` (except `false` on `aria-*`, `data-*`, `draggable`,\n * `spellcheck` and `contenteditable`, which is written as `\"false\"`); `true` writes `=\"\"` (or\n * `\"true\"` for those same names). Other values are written as `String(value)`, HTML-escaped.\n * - URL attributes whose value would run script are dropped, with the check of\n * `isUnsafeUrlAttribute` (including the SVG animation attributes `values`, `from`, `to`, `by`).\n * - `on*` names are dropped: event handlers never reach markup.\n * - Accessors are called (untracked) until a plain value remains.\n *\n * @param name Attribute name, matching `[A-Za-z_:][A-Za-z0-9_:.-]*`. It is validated before\n * anything else, so an invalid name always throws.\n * @param value The value, or an accessor of it.\n * @param isBoolean `true` for a presence attribute such as `disabled`: a truthy value writes the bare\n * name, a falsy one writes nothing. Default: `false`.\n * @returns Markup such as `' title=\"a&amp;b\"'`, or `\"\"`.\n * @throws TypeError `INVALID_ATTRIBUTE_NAME` for an invalid name, and `UNRECOGNIZED_INSERT_VALUE`\n * when the value is a symbol.\n * @example\n * import { ssrAttribute } from \"@shadow-js/web/server\";\n *\n * ssrAttribute(\"title\", \"Tom & Jerry\"); // ' title=\"Tom &amp; Jerry\"'\n * ssrAttribute(\"disabled\", true, true); // \" disabled\"\n * ssrAttribute(\"href\", \"javascript:alert(1)\"); // \"\"\n * @since 1.0.0\n */\nexport function ssrAttribute(name: string, value: unknown, isBoolean = false): string {\n assertAttributeName(name);\n const lowerName = name.toLowerCase();\n if (isEventName(lowerName)) return \"\";\n const resolved = resolveValue(value);\n assertNotSymbol(resolved);\n if (isBoolean) return resolved ? ` ${name}` : \"\";\n const text = attributeText(lowerName, resolved);\n if (text === null) return \"\";\n if (isUnsafeAttributeValue(lowerName, text)) return \"\";\n return ` ${name}=\"${escapeHtml(text)}\"`;\n}\n"],"mappings":";;;;AAIA,MAAM,iBAAiB;;AAGvB,MAAM,iCAAsC,IAAI,IAAI;CAClD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;AAMD,MAAM,6CAAkD,IAAI,IAAI;CAAC;CAAU;CAAQ;CAAM;AAAI,CAAC;;AAG9F,MAAM,wCAA6C,IAAI,IAAI;CACzD;CACA;CACA;AACF,CAAC;;;;;;AAOD,MAAa,qCAA0C,IAAI,IAAI;CAC7D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,MAAM,sBAAyC;CAAC;CAAe;CAAkB;AAAW;;AAG5F,SAAgB,oBAAoB,MAAoB;CACtD,IAAI,CAAC,eAAe,KAAK,IAAI,GAC3B,MAAM,QAAQ,0BAA0B,IAAI,KAAK,iCAAiC;AAEtF;;AAGA,SAAgB,YAAY,WAA4B;CACtD,OAAO,UAAU,SAAS,KAAK,UAAU,WAAW,IAAI;AAC1D;;AAGA,SAAS,eAAe,WAA4B;CAClD,OACE,UAAU,WAAW,OAAO,KAC5B,UAAU,WAAW,OAAO,KAC5B,sBAAsB,IAAI,SAAS;AAEvC;;AAGA,SAAS,cAAc,MAAsB;CAC3C,IAAI,OAAO;CACX,KAAK,MAAM,QAAQ,MAAM;EACvB,MAAM,OAAO,KAAK,WAAW,CA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cesContent":["import { SRCDOC_DYNAMIC_DETAIL, warnOnce } from \"../internal/diagnostics\";\nimport { invalid } from \"./errors\";\nimport { escapeHtml, resolveValue } from \"./escape\";\n\n/** Names that can appear in markup: an XML-name subset without `@` or whitespace. Same as the client. */\nconst ATTRIBUTE_NAME = /^[A-Za-z_:][A-Za-z0-9_:.-]*$/;\n\n/** Attributes whose value is a URL and is therefore checked for script schemes. Same as the client. */\nconst URL_ATTRIBUTES: ReadonlySet<string> = new Set([\n \"href\",\n \"src\",\n \"action\",\n \"formaction\",\n \"xlink:href\",\n \"poster\",\n \"data\",\n]);\n\n/**\n * SVG animation attributes (`animate`, `set`): with `attributeName=\"href\"` they write an `href` by animation, so their value\n * is checked like one. `values` is a `;` list and every entry is checked. Same as the client.\n */\nconst ANIMATION_VALUE_ATTRIBUTES: ReadonlySet<string> = new Set([\"values\", \"from\", \"to\", \"by\"]);\n\n/** Enumerated attributes where `false` is a real value (\"false\") rather than an absence. */\nconst ENUMERATED_ATTRIBUTES: ReadonlySet<string> = new Set([\n \"draggable\",\n \"spellcheck\",\n \"contenteditable\",\n]);\n\n/**\n * Boolean attributes that a props object writes as presence flags (`disabled: true` gives a bare\n * `disabled`). Lower-case names only.\n * @internal\n */\nexport const BOOLEAN_ATTRIBUTES: ReadonlySet<string> = new Set([\n \"async\",\n \"autofocus\",\n \"autoplay\",\n \"checked\",\n \"controls\",\n \"default\",\n \"defer\",\n \"disabled\",\n \"formnovalidate\",\n \"hidden\",\n \"inert\",\n \"ismap\",\n \"loop\",\n \"multiple\",\n \"muted\",\n \"nomodule\",\n \"novalidate\",\n \"open\",\n \"playsinline\",\n \"readonly\",\n \"required\",\n \"reversed\",\n \"selected\",\n]);\n\n/** URL prefixes (after normalization) that are never written. Same as the client. */\nconst UNSAFE_URL_PREFIXES: readonly string[] = [\"javascript:\", \"data:text/html\", \"vbscript:\"];\n\n/** Throws a TypeError unless `name` can be written as an attribute name. @internal */\nexport function assertAttributeName(name: string): void {\n if (!ATTRIBUTE_NAME.test(name)) {\n throw invalid(\"INVALID_ATTRIBUTE_NAME\", `\"${name}\" is not a valid attribute name.`);\n }\n}\n\n/** True for `on*` names, which never reach markup. Length matches the client's event test. @internal */\nexport function isEventName(lowerName: string): boolean {\n return lowerName.length > 2 && lowerName.startsWith(\"on\");\n}\n\n/** True for `aria-*`, `data-*` and the enumerated attributes: their booleans are strings. */\nfunction isStringValued(lowerName: string): boolean {\n return (\n lowerName.startsWith(\"aria-\") ||\n lowerName.startsWith(\"data-\") ||\n ENUMERATED_ATTRIBUTES.has(lowerName)\n );\n}\n\n/** Removes C0 and C1 control characters, which browsers ignore inside a URL scheme. */\nfunction stripControls(text: string): string {\n let kept = \"\";\n for (const char of text) {\n const code = char.charCodeAt(0);\n if (code > 0x1f && (code < 0x7f || code > 0x9f)) kept += char;\n }\n return kept;\n}\n\n/** True when the URL would run script, after the normalization browsers apply. @internal */\nexport function isUnsafeUrl(value: string): boolean {\n const normalized = stripControls(value).trim().toLowerCase();\n return UNSAFE_URL_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n\n/** True when `lowerName` carries a URL (or an animated one) and `value` would run script. */\nfunction isUnsafeAttributeValue(lowerName: string, value: string): boolean {\n if (URL_ATTRIBUTES.has(lowerName)) return isUnsafeUrl(value);\n return ANIMATION_VALUE_ATTRIBUTES.has(lowerName) && value.split(\";\").some(isUnsafeUrl);\n}\n\n/** Text to write for `value`, or null when the attribute is removed. Same rules as the client. @internal */\nexport function attributeText(lowerName: string, value: unknown): string | null {\n if (value === null || value === undefined) return null;\n if (value === false) return isStringValued(lowerName) ? \"false\" : null;\n if (value === true) return isStringValued(lowerName) ? \"true\" : \"\";\n return String(value);\n}\n\n/** Refuses symbols, which have no markup form and would otherwise be coerced silently. */\nfunction assertNotSymbol(value: unknown): void {\n if (typeof value === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be an attribute value.\");\n }\n}\n\n/**\n * Renders one attribute as markup with a leading space, or `\"\"` when the attribute is absent: the\n * helper the compiler's server output calls for a dynamic attribute. It applies the client's value\n * rules and URL check, so server and client agree on what is written.\n *\n * - `null`, `undefined` and `false` give `\"\"` (except `false` on `aria-*`, `data-*`, `draggable`,\n * `spellcheck` and `contenteditable`, which is written as `\"false\"`); `true` writes `=\"\"` (or\n * `\"true\"` for those same names). Other values are written as `String(value)`, HTML-escaped.\n * - URL attributes whose value would run script are dropped, with the check of\n * `isUnsafeUrlAttribute` (including the SVG animation attributes `values`, `from`, `to`, `by`).\n * - `srcdoc` is an HTML sink, not a URL: its value is a document the frame runs, escaped for the attribute\n * and otherwise written as it is, with the trust of `innerHTML`. Sanitize it and give the frame a `sandbox`\n * attribute. Development builds warn once with `SRCDOC_DYNAMIC`.\n * - `on*` names are dropped: event handlers never reach markup.\n * - Accessors are called (untracked) until a plain value remains.\n *\n * @param name Attribute name, matching `[A-Za-z_:][A-Za-z0-9_:.-]*`. It is validated before\n * anything else, so an invalid name always throws.\n * @param value The value, or an accessor of it.\n * @param isBoolean `true` for a presence attribute such as `disabled`: a truthy value writes the bare\n * name, a falsy one writes nothing. Default: `false`.\n * @returns Markup such as `' title=\"a&amp;b\"'`, or `\"\"`.\n * @throws TypeError `INVALID_ATTRIBUTE_NAME` for an invalid name, and `UNRECOGNIZED_INSERT_VALUE`\n * when the value is a symbol.\n * @example\n * import { ssrAttribute } from \"@shadow-js/web/server\";\n *\n * ssrAttribute(\"title\", \"Tom & Jerry\"); // ' title=\"Tom &amp; Jerry\"'\n * ssrAttribute(\"disabled\", true, true); // \" disabled\"\n * ssrAttribute(\"href\", \"javascript:alert(1)\"); // \"\"\n * @since 1.0.0\n */\nexport function ssrAttribute(name: string, value: unknown, isBoolean = false): string {\n assertAttributeName(name);\n const lowerName = name.toLowerCase();\n if (isEventName(lowerName)) return \"\";\n const resolved = resolveValue(value);\n assertNotSymbol(resolved);\n if (isBoolean) return resolved ? ` ${name}` : \"\";\n const text = attributeText(lowerName, resolved);\n if (text === null) return \"\";\n if (__DEV__ && lowerName === \"srcdoc\") warnOnce(\"SRCDOC_DYNAMIC\", SRCDOC_DYNAMIC_DETAIL);\n if (isUnsafeAttributeValue(lowerName, text)) return \"\";\n return ` ${name}=\"${escapeHtml(text)}\"`;\n}\n"],"mappings":";;;;;AAKA,MAAM,iBAAiB;;AAGvB,MAAM,iCAAsC,IAAI,IAAI;CAClD;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;AAMD,MAAM,6CAAkD,IAAI,IAAI;CAAC;CAAU;CAAQ;CAAM;AAAI,CAAC;;AAG9F,MAAM,wCAA6C,IAAI,IAAI;CACzD;CACA;CACA;AACF,CAAC;;;;;;AAOD,MAAa,qCAA0C,IAAI,IAAI;CAC7D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,MAAM,sBAAyC;CAAC;CAAe;CAAkB;AAAW;;AAG5F,SAAgB,oBAAoB,MAAoB;CACtD,IAAI,CAAC,eAAe,KAAK,IAAI,GAC3B,MAAM,QAAQ,0BAA0B,IAAI,KAAK,iCAAiC;AAEtF;;AAGA,SAAgB,YAAY,WAA4B;CACtD,OAAO,UAAU,SAAS,KAAK,UAAU,WAAW,IAAI;AAC1D;;AAGA,SAAS,eAAe,WAA4B;CAClD,OACE,UAAU,WAAW,OAAO,KAC5B,UAAU,WAAW,OAAO,KAC5B,sBAAsB,IAAI,SAAS;AAEvC;;AAGA,SAAS,cAAc,MAAsB;CAC3C,IAAI,OAAO;CACX,KAAK,MAAM,QAAQ,MAAM;EACvB,MAAM,OAAO,KAAK,WAAW,CAAC;EAC9B,IAAI,OAAO,OAAS,OAAO,OAAQ,OAAO,MAAO,QAAQ;CAC3D;CACA,OAAO;AACT;;AAGA,SAAgB,YAAY,OAAwB;CAClD,MAAM,aAAa,cAAc,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,YAAY;CAC3D,OAAO,oBAAoB,MAAM,WAAW,WAAW,WAAW,MAAM,CAAC;AAC3E;;AAGA,SAAS,uBAAuB,WAAmB,OAAwB;CACzE,IAAI,eAAe,IAAI,SAAS,GAAG,OAAO,YAAY,KAAK;CAC3D,OAAO,2BAA2B,IAAI,SAAS,KAAK,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,WAAW;AACvF;;AAGA,SAAgB,cAAc,WAAmB,OAA+B;CAC9E,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO;CAClD,IAAI,UAAU,OAAO,OAAO,eAAe,SAAS,IAAI,UAAU;CAClE,IAAI,UAAU,MAAM,OAAO,eAAe,SAAS,IAAI,SAAS;CAChE,OAAO,OAAO,KAAK;AACrB;;AAGA,SAAS,gBAAgB,OAAsB;CAC7C,IAAI,OAAO,UAAU,UACnB,MAAM,QAAQ,6BAA6B,wCAAwC;AAEvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,aAAa,MAAc,OAAgB,YAAY,OAAe;CACpF,oBAAoB,IAAI;CACxB,MAAM,YAAY,KAAK,YAAY;CACnC,IAAI,YAAY,SAAS,GAAG,OAAO;CACnC,MAAM,WAAW,aAAa,KAAK;CACnC,gBAAgB,QAAQ;CACxB,IAAI,WAAW,OAAO,WAAW,IAAI,SAAS;CAC9C,MAAM,OAAO,cAAc,WAAW,QAAQ;CAC9C,IAAI,SAAS,MAAM,OAAO;CAC1B,IAAe,cAAc,UAAU,SAAS,kBAAkB,qBAAqB;CACvF,IAAI,uBAAuB,WAAW,IAAI,GAAG,OAAO;CACpD,OAAO,IAAI,KAAK,IAAI,WAAW,IAAI,EAAE;AACvC"}
@@ -1,4 +1,3 @@
1
- //#region src/server/class-style.d.ts
2
1
  /**
3
2
  * Renders a `class` attribute from a class value: the helper the compiler's server output calls for
4
3
  * `class`, `className` and `classList`, with the same clsx rules as the client's `className`.
@@ -42,5 +41,4 @@ export declare function ssrClass(value: unknown): string;
42
41
  * @since 1.0.0
43
42
  */
44
43
  export declare function ssrStyle(value: unknown): string;
45
- //#endregion
46
44
  //# sourceMappingURL=class-style.d.ts.map
@@ -2,7 +2,7 @@ import { cssValueText } from "../internal/css-units.js";
2
2
  import { invalid } from "./errors.js";
3
3
  import { isSsrNode } from "./node.js";
4
4
  import { escapeHtml, resolveValue } from "./escape.js";
5
- //#region src/server/class-style.ts
5
+ // src/server/class-style.ts
6
6
  /** A CSS property name: a custom property, or a lower-case name with an optional vendor dash. */
7
7
  const CSS_PROPERTY = /^(--[A-Za-z0-9_-]+|-?[a-z][a-z0-9-]*)$/;
8
8
  /**
@@ -167,7 +167,6 @@ function ssrStyle(value) {
167
167
  const text = styleText(value);
168
168
  return text === "" ? "" : ` style="${escapeHtml(text)}"`;
169
169
  }
170
- //#endregion
171
170
  export { classText, collectClasses, isSafeCssValue, ssrClass, ssrStyle, styleText, toCssProperty };
172
171
 
173
172
  //# sourceMappingURL=class-style.js.map
@@ -1,4 +1,3 @@
1
- //#region src/server/component.d.ts
2
1
  /**
3
2
  * Calls a component on the server, untracked, with its own owner and hydration scope, so the
4
3
  * hydration keys it hands out depend only on where it sits in the tree. The server twin of the client
@@ -38,5 +37,4 @@ export declare function createComponent<P>(component: (props: P) => unknown, pro
38
37
  * @since 1.0.0
39
38
  */
40
39
  export declare function memo<T>(fn: () => T): () => T;
41
- //#endregion
42
40
  //# sourceMappingURL=component.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import { currentScope, enterComponent } from "../internal/hydration-scope.js";
2
2
  import { untrack } from "@shadow-js/core";
3
3
  import { createOwner, runInScope } from "@shadow-js/core/extend";
4
- //#region src/server/component.ts
4
+ // src/server/component.ts
5
5
  /**
6
6
  * Calls a component on the server, untracked, with its own owner and hydration scope, so the
7
7
  * hydration keys it hands out depend only on where it sits in the tree. The server twin of the client
@@ -66,7 +66,6 @@ function memo(fn) {
66
66
  }
67
67
  };
68
68
  }
69
- //#endregion
70
69
  export { createComponent, memo };
71
70
 
72
71
  //# sourceMappingURL=component.js.map
@@ -1,4 +1,3 @@
1
- //#region src/server/derived.d.ts
2
1
  /**
3
2
  * The server twin of the client `Derived`: what {@link derived} returns. Nothing is reactive on the
4
3
  * server, so it holds the value computed once. Read it as `x.value` or call it as `x()`.
@@ -37,5 +36,4 @@ export interface Derived<T> {
37
36
  * @since 1.0.0
38
37
  */
39
38
  export declare function derived<T>(compute: () => T): Derived<T>;
40
- //#endregion
41
39
  //# sourceMappingURL=derived.d.ts.map
@@ -1,4 +1,4 @@
1
- //#region src/server/derived.ts
1
+ // src/server/derived.ts
2
2
  /**
3
3
  * The server twin of the client `derived`, which the compiler emits for `const x = <expression
4
4
  * reading signals>` inside a component. On the server it calls `compute` once, immediately, and
@@ -20,7 +20,6 @@ function derived(compute) {
20
20
  Object.defineProperty(read, "value", { value: current });
21
21
  return read;
22
22
  }
23
- //#endregion
24
23
  export { derived };
25
24
 
26
25
  //# sourceMappingURL=derived.js.map
@@ -1,5 +1,4 @@
1
1
  import { SsrNode } from "./node.js";
2
- //#region src/server/element.d.ts
3
2
  /**
4
3
  * Joins the static parts of a server template with its dynamic holes into trusted markup: the
5
4
  * function compiled server output calls for each element tree. Holes are inserted unchanged, so each
@@ -85,5 +84,4 @@ export declare function ssrHydrationKey(): string;
85
84
  * @since 1.0.0
86
85
  */
87
86
  export declare function ssrElement(tag: string, props: unknown, children?: unknown, needsKey?: boolean, svg?: boolean): SsrNode;
88
- //#endregion
89
87
  //# sourceMappingURL=element.d.ts.map
@@ -5,8 +5,9 @@ import { SsrNode, isSsrNode } from "./node.js";
5
5
  import { escape, escapeHtml, resolveValue } from "./escape.js";
6
6
  import { BOOLEAN_ATTRIBUTES, isEventName, ssrAttribute } from "./attributes.js";
7
7
  import { classText, ssrStyle, styleText } from "./class-style.js";
8
- import { markSelectedOptions, textareaContent } from "./form-controls.js";
9
- //#region src/server/element.ts
8
+ import { keepLeadingNewline, markSelectedOptions, textareaContent } from "./form-controls.js";
9
+ import { rawElementContent } from "./raw-text.js";
10
+ // src/server/element.ts
10
11
  /** A tag name: letters, digits and dashes, starting with a letter. Anything else could break out. */
11
12
  const TAG_NAME = /^[A-Za-z][A-Za-z0-9-]*$/;
12
13
  /** Elements that never have children or a closing tag. */
@@ -180,17 +181,20 @@ function ssrElement(tag, props, children = void 0, needsKey = false, svg = false
180
181
  if (!Object.hasOwn(props, name)) attributes += ssrAttribute(name, value, name === "checked");
181
182
  } else {
182
183
  const name = attributeName(key, svg);
183
- attributes += ssrAttribute(name, value, BOOLEAN_ATTRIBUTES.has(name));
184
+ const flag = BOOLEAN_ATTRIBUTES.has(name) && !(name === "hidden" && value === "until-found");
185
+ attributes += ssrAttribute(name, value, flag);
184
186
  }
185
187
  }
186
188
  if (classes.length > 0) attributes += ` class="${escapeHtml(classes.join(" "))}"`;
187
189
  if (style !== "") attributes += ssrStyle(style);
188
190
  if (VOID_ELEMENTS.has(lowerTag)) return new SsrNode(`<${tag}${attributes}>`);
189
- let content = innerHtml !== void 0 ? innerHtml : escape(children === void 0 ? propsChildren(props) : children);
191
+ const raw = !svg && (lowerTag === "script" || lowerTag === "style");
192
+ const given = children === void 0 ? propsChildren(props) : children;
193
+ let content = innerHtml !== void 0 ? innerHtml : raw ? rawElementContent(lowerTag, given) : escape(given);
190
194
  if (innerHtml === void 0 && (hasValue || hasFallback)) {
191
195
  const value = hasValue ? control.value : control.fallback;
192
196
  content = isTextarea ? textareaContent(value) : markSelectedOptions(value, content);
193
- }
197
+ } else if (isTextarea && innerHtml === void 0) content = keepLeadingNewline(content);
194
198
  return new SsrNode(`<${tag}${attributes}>${content}</${tag}>`);
195
199
  }
196
200
  /** The `children` of a spread props object (read once, so a getter runs once), or undefined. */
@@ -210,7 +214,6 @@ function plainHtml(value) {
210
214
  if (typeof value === "symbol") throw invalid("UNRECOGNIZED_INSERT_VALUE", "A symbol cannot be innerHTML.");
211
215
  return String(value);
212
216
  }
213
- //#endregion
214
217
  export { ssr, ssrElement, ssrHydrationKey, ssrRaw };
215
218
 
216
219
  //# sourceMappingURL=element.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"element.js","names":[],"sources":["../../../src/server/element.ts"],"sourcesContent":["import { nextKey } from \"../internal/hydration-scope\";\nimport { attributeName, IGNORED_KEYS } from \"../internal/react-names\";\nimport { BOOLEAN_ATTRIBUTES, isEventName, ssrAttribute } from \"./attributes\";\nimport { classText, ssrStyle, styleText } from \"./class-style\";\nimport { invalid } from \"./errors\";\n// biome-ignore lint/suspicious/noShadowRestrictedNames: the name \"escape\" is part of the compiler contract (SSR output).\nimport { escape, escapeHtml, resolveValue } from \"./escape\";\nimport { markSelectedOptions, textareaContent } from \"./form-controls\";\nimport { isSsrNode, SsrNode } from \"./node\";\n\n/** A tag name: letters, digits and dashes, starting with a letter. Anything else could break out. */\nconst TAG_NAME = /^[A-Za-z][A-Za-z0-9-]*$/;\n\n/** Elements that never have children or a closing tag. */\nconst VOID_ELEMENTS: ReadonlySet<string> = new Set([\n \"area\",\n \"base\",\n \"br\",\n \"col\",\n \"command\",\n \"embed\",\n \"hr\",\n \"img\",\n \"input\",\n \"keygen\",\n \"link\",\n \"meta\",\n \"param\",\n \"source\",\n \"track\",\n \"wbr\",\n]);\n\n/** Keys that never become attributes: they are handled elsewhere or would reach a prototype. */\nconst SKIPPED_KEYS: ReadonlySet<string> = new Set([\n \"__proto__\",\n \"constructor\",\n \"prototype\",\n \"children\",\n \"ref\",\n]);\n\n/** The HTML of a `dangerouslySetInnerHTML` value (`{ __html }`): null and undefined are empty. */\nfunction innerHtmlOfValue(value: unknown): unknown {\n if (value === null || typeof value !== \"object\") return undefined;\n return Reflect.get(value, \"__html\");\n}\n\n/**\n * Joins the static parts of a server template with its dynamic holes into trusted markup: the\n * function compiled server output calls for each element tree. Holes are inserted unchanged, so each\n * must already be escaped (the output of `escape`, `ssrAttribute`, `ssrClass`, ...) or an `SsrNode`;\n * any other value throws, so a raw user value cannot reach the markup.\n *\n * @param parts The static markup, one more entry than there are holes.\n * @param holes The dynamic parts: strings produced by the escaping helpers, or `SsrNode` values.\n * @returns The markup as a trusted `SsrNode`, which `escape` writes without encoding.\n * @throws TypeError when `parts` is not an array of `holes.length + 1` entries, or when a hole is not\n * a string or an `SsrNode`.\n * @example\n * import { escape, renderToString, ssr } from \"@shadow-js/web/server\";\n *\n * const name = \"<Ada>\";\n * const html = renderToString(() => ssr([\"<p>Hello, \", \"</p>\"], escape(name)));\n * // \"<p>Hello, &lt;Ada&gt;</p>\"\n * @see ssrRaw\n * @since 1.0.0\n */\nexport function ssr(parts: readonly string[], ...holes: unknown[]): SsrNode {\n if (!Array.isArray(parts) || parts.length !== holes.length + 1) {\n throw new TypeError(\"ssr(): parts must have one more entry than there are holes.\");\n }\n let html = parts[0] ?? \"\";\n for (let index = 0; index < holes.length; index += 1) {\n const hole = holes[index];\n if (typeof hole === \"string\") html += hole;\n else if (isSsrNode(hole)) html += hole.t;\n else throw new TypeError(\"ssr(): a hole must be an escaped string or an SsrNode.\");\n html += parts[index + 1] ?? \"\";\n }\n return new SsrNode(html);\n}\n\n/**\n * Marks a string as trusted markup that `escape` and `ssr` insert unchanged. Only use it for markup\n * the application wrote itself, never for user input.\n *\n * @param html The markup, inserted unchanged.\n * @returns The markup as a trusted `SsrNode`.\n * @throws TypeError when `html` is not a string.\n * @example\n * import { renderToString, ssrRaw } from \"@shadow-js/web/server\";\n *\n * const html = renderToString(() => [\"<b>escaped</b>\", ssrRaw(\"<!-- build 42 -->\")]);\n * // \"&lt;b&gt;escaped&lt;/b&gt;<!-- build 42 -->\"\n * @see ssr\n * @since 1.0.0\n */\nexport function ssrRaw(html: string): SsrNode {\n if (typeof html !== \"string\") throw new TypeError(\"ssrRaw(): the markup must be a string.\");\n return new SsrNode(html);\n}\n\n/**\n * Draws the next hydration key of the current scope and returns it as a `data-hk` attribute, such as\n * `' data-hk=\"0-0\"'`: compiled server output calls it for the root element of each template, and\n * the client's `hydrate()` claims the element by that key. Calls must happen in the same order as on\n * the client, so call it only where the compiler would.\n *\n * @returns Markup for the `data-hk` attribute, or `\"\"` outside a server render (no key is drawn).\n * @example\n * import { renderToString, ssr, ssrHydrationKey } from \"@shadow-js/web/server\";\n *\n * const html = renderToString(() => ssr([\"<div\", \">x</div>\"], ssrHydrationKey()));\n * // '<div data-hk=\"0-0\">x</div>'\n * @since 1.0.0\n */\nexport function ssrHydrationKey(): string {\n const key = nextKey();\n return key === undefined ? \"\" : ` data-hk=\"${escapeHtml(key)}\"`;\n}\n\n/**\n * Renders an element from a props object: what compiled server output calls for an element with a\n * spread (`<div {...props} />`), and the server half of `Dynamic` and `element`. It writes the same\n * markup the client's `spread` produces.\n *\n * `class`, `className`, `classList` and `style` are combined into one `class` and one `style`\n * attribute; other keys are attributes, with React names mapped (`htmlFor` is `for`) and HTML boolean\n * attributes (`disabled`, `checked`, ...) written as bare names. `ref`, `children`, `on*` keys and the\n * `on:`, `use:` and `prop:` prefixes are skipped; `attr:` and `bool:` select the attribute and presence\n * forms. `innerHTML` and `dangerouslySetInnerHTML` are written unescaped as the content. On a\n * `textarea` the `value` (or `defaultValue`) is the content; on a `select` it marks the matching\n * `<option selected>` (an array for `multiple`); on other elements `defaultValue` and `defaultChecked`\n * are the `value` and `checked` attributes. Void elements (`img`, `input`, ...) get no content.\n *\n * @param tag Element name: letters, digits and dashes, starting with a letter.\n * @param props The props object (each getter is read once), or `null`.\n * @param children The content, escaped unless it is an `SsrNode`. Undefined (the default) uses the\n * `children` prop.\n * @param needsKey `true` writes the hydration key of this template root first. Default: `false`.\n * @param svg `true` for an SVG element: SVG presentation names are hyphenated (`strokeWidth` is\n * `stroke-width`), other names keep their case. Default: `false`.\n * @returns The element as a trusted `SsrNode`.\n * @throws TypeError `INVALID_TAG_NAME` for an invalid tag, `INVALID_ATTRIBUTE_NAME` for an invalid\n * attribute name, and the errors of {@link ssrAttribute}, `ssrClass` and `ssrStyle` for invalid values.\n * @example\n * import { renderToString, ssrElement } from \"@shadow-js/web/server\";\n *\n * const props = { id: \"save\", disabled: true, class: [\"btn\", { primary: true }], children: \"Save\" };\n * const html = renderToString(() => ssrElement(\"button\", props));\n * // '<button id=\"save\" disabled class=\"btn primary\">Save</button>'\n * @since 1.0.0\n */\nexport function ssrElement(\n tag: string,\n props: unknown,\n children: unknown = undefined,\n needsKey = false,\n svg = false,\n): SsrNode {\n if (typeof tag !== \"string\" || !TAG_NAME.test(tag)) {\n throw invalid(\"INVALID_TAG_NAME\", `\"${String(tag)}\" is not a valid tag name.`);\n }\n const lowerTag = tag.toLowerCase();\n // A browser ignores `value` on these: a textarea's value is its content, a select's value is the\n // `selected` flag of its options. The props are read once and applied to the content below.\n const isSelect = lowerTag === \"select\";\n const isTextarea = lowerTag === \"textarea\";\n const control: { value?: unknown; fallback?: unknown } = {};\n let hasValue = false;\n let hasFallback = false;\n let attributes = needsKey ? ssrHydrationKey() : \"\";\n const classes: string[] = [];\n let style = \"\";\n let innerHtml: string | undefined;\n if (props !== null && typeof props === \"object\") {\n for (const key of Object.keys(props)) {\n if (SKIPPED_KEYS.has(key) || IGNORED_KEYS.has(key)) continue;\n if (\n key === \"ref\" ||\n key.startsWith(\"on:\") ||\n key.startsWith(\"use:\") ||\n key.startsWith(\"prop:\")\n )\n continue;\n if (isEventName(key)) continue;\n if (needsKey && key === \"data-hk\") continue;\n const value = resolveValue(Reflect.get(props, key));\n if (key === \"class\" || key === \"className\") {\n const text = classText(value);\n if (text !== \"\") classes.push(text);\n } else if (key === \"classList\") {\n collectTruthyKeys(value, classes);\n } else if (key === \"style\") {\n style = styleText(value);\n } else if (key === \"innerHTML\") {\n innerHtml = plainHtml(value);\n } else if (key === \"dangerouslySetInnerHTML\") {\n innerHtml = plainHtml(resolveValue(innerHtmlOfValue(value)));\n } else if ((isSelect || isTextarea) && key === \"value\") {\n control.value = value;\n hasValue = true;\n } else if ((isSelect || isTextarea) && key === \"defaultValue\") {\n control.fallback = value;\n hasFallback = true;\n } else if (key.startsWith(\"attr:\")) {\n attributes += ssrAttribute(key.slice(5), value);\n } else if (key.startsWith(\"bool:\")) {\n attributes += ssrAttribute(key.slice(5), value, true);\n } else if (key === \"defaultValue\" || key === \"defaultChecked\") {\n // The attributes of the same name in HTML are the defaults: `value` and `checked`.\n const name = key === \"defaultValue\" ? \"value\" : \"checked\";\n if (!Object.hasOwn(props, name))\n attributes += ssrAttribute(name, value, name === \"checked\");\n } else {\n const name = attributeName(key, svg);\n attributes += ssrAttribute(name, value, BOOLEAN_ATTRIBUTES.has(name));\n }\n }\n }\n if (classes.length > 0) attributes += ` class=\"${escapeHtml(classes.join(\" \"))}\"`;\n if (style !== \"\") attributes += ssrStyle(style);\n if (VOID_ELEMENTS.has(lowerTag)) return new SsrNode(`<${tag}${attributes}>`);\n // Like the DOM `spread`: a `children` prop supplies the content unless the element wrote its own.\n let content =\n innerHtml !== undefined\n ? innerHtml\n : escape(children === undefined ? propsChildren(props) : children);\n if (innerHtml === undefined && (hasValue || hasFallback)) {\n const value = hasValue ? control.value : control.fallback;\n content = isTextarea ? textareaContent(value) : markSelectedOptions(value, content);\n }\n return new SsrNode(`<${tag}${attributes}>${content}</${tag}>`);\n}\n\n/** The `children` of a spread props object (read once, so a getter runs once), or undefined. */\nfunction propsChildren(props: unknown): unknown {\n if (props === null || typeof props !== \"object\") return undefined;\n return Reflect.get(props, \"children\");\n}\n\n/** Class names whose key is truthy, from a `classList` object. */\nfunction collectTruthyKeys(value: unknown, out: string[]): void {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return;\n for (const key of Object.keys(value)) {\n if (key !== \"\" && resolveValue(Reflect.get(value, key))) out.push(key);\n }\n}\n\n/** Raw HTML text for `innerHTML`: null and undefined become \"\", an SsrNode its markup. */\nfunction plainHtml(value: unknown): string {\n if (value === null || value === undefined) return \"\";\n if (isSsrNode(value)) return value.t;\n if (typeof value === \"symbol\")\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be innerHTML.\");\n return String(value);\n}\n"],"mappings":";;;;;;;;;;AAWA,MAAM,WAAW;;A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AAI,KAAK,GAAG;AAEzE;;AAGA,SAAS,UAAU,OAAwB;CACzC,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO;CAClD,IAAI,UAAU,KAAK,GAAG,OAAO,MAAM;CACnC,IAAI,OAAO,UAAU,UACnB,MAAM,QAAQ,6BAA6B,+BAA+B;CAC5E,OAAO,OAAO,KAAK;AACrB"}
1
+ {"version":3,"file":"element.js","names":[],"sources":["../../../src/server/element.ts"],"sourcesContent":["import { nextKey } from \"../internal/hydration-scope\";\nimport { attributeName, IGNORED_KEYS } from \"../internal/react-names\";\nimport { BOOLEAN_ATTRIBUTES, isEventName, ssrAttribute } from \"./attributes\";\nimport { classText, ssrStyle, styleText } from \"./class-style\";\nimport { invalid } from \"./errors\";\n// biome-ignore lint/suspicious/noShadowRestrictedNames: the name \"escape\" is part of the compiler contract (SSR output).\nimport { escape, escapeHtml, resolveValue } from \"./escape\";\nimport { keepLeadingNewline, markSelectedOptions, textareaContent } from \"./form-controls\";\nimport { isSsrNode, SsrNode } from \"./node\";\nimport { rawElementContent } from \"./raw-text\";\n\n/** A tag name: letters, digits and dashes, starting with a letter. Anything else could break out. */\nconst TAG_NAME = /^[A-Za-z][A-Za-z0-9-]*$/;\n\n/** Elements that never have children or a closing tag. */\nconst VOID_ELEMENTS: ReadonlySet<string> = new Set([\n \"area\",\n \"base\",\n \"br\",\n \"col\",\n \"command\",\n \"embed\",\n \"hr\",\n \"img\",\n \"input\",\n \"keygen\",\n \"link\",\n \"meta\",\n \"param\",\n \"source\",\n \"track\",\n \"wbr\",\n]);\n\n/** Keys that never become attributes: they are handled elsewhere or would reach a prototype. */\nconst SKIPPED_KEYS: ReadonlySet<string> = new Set([\n \"__proto__\",\n \"constructor\",\n \"prototype\",\n \"children\",\n \"ref\",\n]);\n\n/** The HTML of a `dangerouslySetInnerHTML` value (`{ __html }`): null and undefined are empty. */\nfunction innerHtmlOfValue(value: unknown): unknown {\n if (value === null || typeof value !== \"object\") return undefined;\n return Reflect.get(value, \"__html\");\n}\n\n/**\n * Joins the static parts of a server template with its dynamic holes into trusted markup: the\n * function compiled server output calls for each element tree. Holes are inserted unchanged, so each\n * must already be escaped (the output of `escape`, `ssrAttribute`, `ssrClass`, ...) or an `SsrNode`;\n * any other value throws, so a raw user value cannot reach the markup.\n *\n * @param parts The static markup, one more entry than there are holes.\n * @param holes The dynamic parts: strings produced by the escaping helpers, or `SsrNode` values.\n * @returns The markup as a trusted `SsrNode`, which `escape` writes without encoding.\n * @throws TypeError when `parts` is not an array of `holes.length + 1` entries, or when a hole is not\n * a string or an `SsrNode`.\n * @example\n * import { escape, renderToString, ssr } from \"@shadow-js/web/server\";\n *\n * const name = \"<Ada>\";\n * const html = renderToString(() => ssr([\"<p>Hello, \", \"</p>\"], escape(name)));\n * // \"<p>Hello, &lt;Ada&gt;</p>\"\n * @see ssrRaw\n * @since 1.0.0\n */\nexport function ssr(parts: readonly string[], ...holes: unknown[]): SsrNode {\n if (!Array.isArray(parts) || parts.length !== holes.length + 1) {\n throw new TypeError(\"ssr(): parts must have one more entry than there are holes.\");\n }\n let html = parts[0] ?? \"\";\n for (let index = 0; index < holes.length; index += 1) {\n const hole = holes[index];\n if (typeof hole === \"string\") html += hole;\n else if (isSsrNode(hole)) html += hole.t;\n else throw new TypeError(\"ssr(): a hole must be an escaped string or an SsrNode.\");\n html += parts[index + 1] ?? \"\";\n }\n return new SsrNode(html);\n}\n\n/**\n * Marks a string as trusted markup that `escape` and `ssr` insert unchanged. Only use it for markup\n * the application wrote itself, never for user input.\n *\n * @param html The markup, inserted unchanged.\n * @returns The markup as a trusted `SsrNode`.\n * @throws TypeError when `html` is not a string.\n * @example\n * import { renderToString, ssrRaw } from \"@shadow-js/web/server\";\n *\n * const html = renderToString(() => [\"<b>escaped</b>\", ssrRaw(\"<!-- build 42 -->\")]);\n * // \"&lt;b&gt;escaped&lt;/b&gt;<!-- build 42 -->\"\n * @see ssr\n * @since 1.0.0\n */\nexport function ssrRaw(html: string): SsrNode {\n if (typeof html !== \"string\") throw new TypeError(\"ssrRaw(): the markup must be a string.\");\n return new SsrNode(html);\n}\n\n/**\n * Draws the next hydration key of the current scope and returns it as a `data-hk` attribute, such as\n * `' data-hk=\"0-0\"'`: compiled server output calls it for the root element of each template, and\n * the client's `hydrate()` claims the element by that key. Calls must happen in the same order as on\n * the client, so call it only where the compiler would.\n *\n * @returns Markup for the `data-hk` attribute, or `\"\"` outside a server render (no key is drawn).\n * @example\n * import { renderToString, ssr, ssrHydrationKey } from \"@shadow-js/web/server\";\n *\n * const html = renderToString(() => ssr([\"<div\", \">x</div>\"], ssrHydrationKey()));\n * // '<div data-hk=\"0-0\">x</div>'\n * @since 1.0.0\n */\nexport function ssrHydrationKey(): string {\n const key = nextKey();\n return key === undefined ? \"\" : ` data-hk=\"${escapeHtml(key)}\"`;\n}\n\n/**\n * Renders an element from a props object: what compiled server output calls for an element with a\n * spread (`<div {...props} />`), and the server half of `Dynamic` and `element`. It writes the same\n * markup the client's `spread` produces.\n *\n * `class`, `className`, `classList` and `style` are combined into one `class` and one `style`\n * attribute; other keys are attributes, with React names mapped (`htmlFor` is `for`) and HTML boolean\n * attributes (`disabled`, `checked`, ...) written as bare names. `ref`, `children`, `on*` keys and the\n * `on:`, `use:` and `prop:` prefixes are skipped; `attr:` and `bool:` select the attribute and presence\n * forms. `innerHTML` and `dangerouslySetInnerHTML` are written unescaped as the content. On a\n * `textarea` the `value` (or `defaultValue`) is the content; on a `select` it marks the matching\n * `<option selected>` (an array for `multiple`); on other elements `defaultValue` and `defaultChecked`\n * are the `value` and `checked` attributes. Void elements (`img`, `input`, ...) get no content.\n *\n * @param tag Element name: letters, digits and dashes, starting with a letter.\n * @param props The props object (each getter is read once), or `null`.\n * @param children The content, escaped unless it is an `SsrNode`. Undefined (the default) uses the\n * `children` prop.\n * @param needsKey `true` writes the hydration key of this template root first. Default: `false`.\n * @param svg `true` for an SVG element: SVG presentation names are hyphenated (`strokeWidth` is\n * `stroke-width`), other names keep their case. Default: `false`.\n * @returns The element as a trusted `SsrNode`.\n * @throws TypeError `INVALID_TAG_NAME` for an invalid tag, `INVALID_ATTRIBUTE_NAME` for an invalid\n * attribute name, and the errors of {@link ssrAttribute}, `ssrClass` and `ssrStyle` for invalid values.\n * @example\n * import { renderToString, ssrElement } from \"@shadow-js/web/server\";\n *\n * const props = { id: \"save\", disabled: true, class: [\"btn\", { primary: true }], children: \"Save\" };\n * const html = renderToString(() => ssrElement(\"button\", props));\n * // '<button id=\"save\" disabled class=\"btn primary\">Save</button>'\n * @since 1.0.0\n */\nexport function ssrElement(\n tag: string,\n props: unknown,\n children: unknown = undefined,\n needsKey = false,\n svg = false,\n): SsrNode {\n if (typeof tag !== \"string\" || !TAG_NAME.test(tag)) {\n throw invalid(\"INVALID_TAG_NAME\", `\"${String(tag)}\" is not a valid tag name.`);\n }\n const lowerTag = tag.toLowerCase();\n // A browser ignores `value` on these: a textarea's value is its content, a select's value is the\n // `selected` flag of its options. The props are read once and applied to the content below.\n const isSelect = lowerTag === \"select\";\n const isTextarea = lowerTag === \"textarea\";\n const control: { value?: unknown; fallback?: unknown } = {};\n let hasValue = false;\n let hasFallback = false;\n let attributes = needsKey ? ssrHydrationKey() : \"\";\n const classes: string[] = [];\n let style = \"\";\n let innerHtml: string | undefined;\n if (props !== null && typeof props === \"object\") {\n for (const key of Object.keys(props)) {\n if (SKIPPED_KEYS.has(key) || IGNORED_KEYS.has(key)) continue;\n if (\n key === \"ref\" ||\n key.startsWith(\"on:\") ||\n key.startsWith(\"use:\") ||\n key.startsWith(\"prop:\")\n )\n continue;\n if (isEventName(key)) continue;\n if (needsKey && key === \"data-hk\") continue;\n const value = resolveValue(Reflect.get(props, key));\n if (key === \"class\" || key === \"className\") {\n const text = classText(value);\n if (text !== \"\") classes.push(text);\n } else if (key === \"classList\") {\n collectTruthyKeys(value, classes);\n } else if (key === \"style\") {\n style = styleText(value);\n } else if (key === \"innerHTML\") {\n innerHtml = plainHtml(value);\n } else if (key === \"dangerouslySetInnerHTML\") {\n innerHtml = plainHtml(resolveValue(innerHtmlOfValue(value)));\n } else if ((isSelect || isTextarea) && key === \"value\") {\n control.value = value;\n hasValue = true;\n } else if ((isSelect || isTextarea) && key === \"defaultValue\") {\n control.fallback = value;\n hasFallback = true;\n } else if (key.startsWith(\"attr:\")) {\n attributes += ssrAttribute(key.slice(5), value);\n } else if (key.startsWith(\"bool:\")) {\n attributes += ssrAttribute(key.slice(5), value, true);\n } else if (key === \"defaultValue\" || key === \"defaultChecked\") {\n // The attributes of the same name in HTML are the defaults: `value` and `checked`.\n const name = key === \"defaultValue\" ? \"value\" : \"checked\";\n if (!Object.hasOwn(props, name))\n attributes += ssrAttribute(name, value, name === \"checked\");\n } else {\n const name = attributeName(key, svg);\n // `hidden=\"until-found\"` is a keyword, not a flag: a bare `hidden` would hide what it should only collapse.\n const flag =\n BOOLEAN_ATTRIBUTES.has(name) && !(name === \"hidden\" && value === \"until-found\");\n attributes += ssrAttribute(name, value, flag);\n }\n }\n }\n if (classes.length > 0) attributes += ` class=\"${escapeHtml(classes.join(\" \"))}\"`;\n if (style !== \"\") attributes += ssrStyle(style);\n if (VOID_ELEMENTS.has(lowerTag)) return new SsrNode(`<${tag}${attributes}>`);\n // Like the DOM `spread`: a `children` prop supplies the content unless the element wrote its own.\n // The text of a script or a style is raw (no entities), so it is written as it is and checked instead.\n const raw = !svg && (lowerTag === \"script\" || lowerTag === \"style\");\n const given = children === undefined ? propsChildren(props) : children;\n let content =\n innerHtml !== undefined ? innerHtml : raw ? rawElementContent(lowerTag, given) : escape(given);\n if (innerHtml === undefined && (hasValue || hasFallback)) {\n const value = hasValue ? control.value : control.fallback;\n content = isTextarea ? textareaContent(value) : markSelectedOptions(value, content);\n } else if (isTextarea && innerHtml === undefined) {\n // The children of a textarea are its value (as on the client): keep a first line break the parser drops.\n content = keepLeadingNewline(content);\n }\n return new SsrNode(`<${tag}${attributes}>${content}</${tag}>`);\n}\n\n/** The `children` of a spread props object (read once, so a getter runs once), or undefined. */\nfunction propsChildren(props: unknown): unknown {\n if (props === null || typeof props !== \"object\") return undefined;\n return Reflect.get(props, \"children\");\n}\n\n/** Class names whose key is truthy, from a `classList` object. */\nfunction collectTruthyKeys(value: unknown, out: string[]): void {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return;\n for (const key of Object.keys(value)) {\n if (key !== \"\" && resolveValue(Reflect.get(value, key))) out.push(key);\n }\n}\n\n/** Raw HTML text for `innerHTML`: null and undefined become \"\", an SsrNode its markup. */\nfunction plainHtml(value: unknown): string {\n if (value === null || value === undefined) return \"\";\n if (isSsrNode(value)) return value.t;\n if (typeof value === \"symbol\")\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be innerHTML.\");\n return String(value);\n}\n"],"mappings":";;;;;;;;;;;AAYA,MAAM,WAAW;;AAGjB,MAAM,gCAAqC,IAAI,IAAI;CACjD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,MAAM,+BAAoC,IAAI,IAAI;CAChD;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,SAAS,iBAAiB,OAAyB;CACjD,IAAI,UAAU,QAAQ,OAAO,UAAU,UAAU,OAAO,KAAA;CACxD,OAAO,QAAQ,IAAI,OAAO,QAAQ;AACpC;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,IAAI,OAA0B,GAAG,OAA2B;CAC1E,IAAI,CAAC,MAAM,QAAQ,KAAK,KAAK,MAAM,WAAW,MAAM,SAAS,GAC3D,MAAM,IAAI,UAAU,6DAA6D;CAEnF,IAAI,OAAO,MAAM,MAAM;CACvB,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS,GAAG;EACpD,MAAM,OAAO,MAAM;EACnB,IAAI,OAAO,SAAS,UAAU,QAAQ;OACjC,IAAI,UAAU,IAAI,GAAG,QAAQ,KAAK;OAClC,MAAM,IAAI,UAAU,wDAA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IAAI;CAC9D,IAAI,UACF,cAAc,KAAA,IAAY,YAAY,MAAM,kBAAkB,UAAU,KAAK,IAAI,OAAO,KAAK;CAC/F,IAAI,cAAc,KAAA,MAAc,YAAY,cAAc;EACxD,MAAM,QAAQ,WAAW,QAAQ,QAAQ,QAAQ;EACjD,UAAU,aAAa,gBAAgB,KAAK,IAAI,oBAAoB,OAAO,OAAO;CACpF,OAAO,IAAI,cAAc,cAAc,KAAA,GAErC,UAAU,mBAAmB,OAAO;CAEtC,OAAO,IAAI,QAAQ,IAAI,MAAM,WAAW,GAAG,QAAQ,IAAI,IAAI,EAAE;AAC/D;;AAGA,SAAS,cAAc,OAAyB;CAC9C,IAAI,UAAU,QAAQ,OAAO,UAAU,UAAU,OAAO,KAAA;CACxD,OAAO,QAAQ,IAAI,OAAO,UAAU;AACtC;;AAGA,SAAS,kBAAkB,OAAgB,KAAqB;CAC9D,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG;CACzE,KAAK,MAAM,OAAO,OAAO,KAAK,KAAK,GACjC,IAAI,QAAQ,MAAM,aAAa,QAAQ,IAAI,OAAO,GAAG,CAAC,GAAG,IAAI,KAAK,GAAG;AAEzE;;AAGA,SAAS,UAAU,OAAwB;CACzC,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO;CAClD,IAAI,UAAU,KAAK,GAAG,OAAO,MAAM;CACnC,IAAI,OAAO,UAAU,UACnB,MAAM,QAAQ,6BAA6B,+BAA+B;CAC5E,OAAO,OAAO,KAAK;AACrB"}
@@ -1,4 +1,4 @@
1
- //#region src/server/errors.ts
1
+ // src/server/errors.ts
2
2
  /**
3
3
  * Error thrown by the server renderer, carrying a stable code. Dev builds carry the full text;
4
4
  * production builds keep only the code (the same split as core's diagnostics).
@@ -20,7 +20,12 @@ var SsrError = class extends Error {
20
20
  function invalid(code, detail) {
21
21
  return /* @__PURE__ */ new TypeError(`[shadow ${code}] ${detail}`);
22
22
  }
23
- //#endregion
24
- export { SsrError, invalid };
23
+ /**
24
+ * The longest delay `setTimeout` honors: larger values fire after one millisecond. A budget above it
25
+ * (`Number.MAX_SAFE_INTEGER` for "no limit") is clamped here instead of ending every render at once.
26
+ * @internal
27
+ */
28
+ const MAX_TIMER_MS = 2147483647;
29
+ export { MAX_TIMER_MS, SsrError, invalid };
25
30
 
26
31
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../../../src/server/errors.ts"],"sourcesContent":["/** Diagnostic codes raised by the server renderer. @internal */\nexport type SsrErrorCode = \"SSR_BOUNDARY_WATERFALL\" | \"SSR_PORTAL_LIMIT\" | \"SSR_TIMEOUT\";\n\n/**\n * Error thrown by the server renderer, carrying a stable code. Dev builds carry the full text;\n * production builds keep only the code (the same split as core's diagnostics).\n * @internal\n */\nexport class SsrError extends Error {\n readonly code: SsrErrorCode;\n constructor(code: SsrErrorCode, detail: string) {\n super(__DEV__ ? `[shadow ${code}] ${detail}` : `SHADOW_${code}`);\n this.name = \"SsrError\";\n this.code = code;\n }\n}\n\n/**\n * A TypeError for input the renderer refuses: a value that could become unsafe markup, or a\n * malformed argument. Dev builds carry the detail; production builds keep the code.\n * @internal\n */\nexport function invalid(code: string, detail: string): TypeError {\n return new TypeError(__DEV__ ? `[shadow ${code}] ${detail}` : `SHADOW_${code}`);\n}\n"],"mappings":";;;;;;AAQA,IAAa,WAAb,cAA8B,MAAM;CAClC;CACA,YAAY,MAAoB,QAAgB;EAC9C,MAAgB,WAAW,KAAK,IAAI,QAA2B;EAC/D,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;;;;;AAOA,SAAgB,QAAQ,MAAc,QAA2B;CAC/D,uBAAO,IAAI,UAAoB,WAAW,KAAK,IAAI,QAA2B;AAChF"}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../../../src/server/errors.ts"],"sourcesContent":["/** Diagnostic codes raised by the server renderer. @internal */\nexport type SsrErrorCode = \"SSR_BOUNDARY_WATERFALL\" | \"SSR_PORTAL_LIMIT\" | \"SSR_TIMEOUT\";\n\n/**\n * Error thrown by the server renderer, carrying a stable code. Dev builds carry the full text;\n * production builds keep only the code (the same split as core's diagnostics).\n * @internal\n */\nexport class SsrError extends Error {\n readonly code: SsrErrorCode;\n constructor(code: SsrErrorCode, detail: string) {\n super(__DEV__ ? `[shadow ${code}] ${detail}` : `SHADOW_${code}`);\n this.name = \"SsrError\";\n this.code = code;\n }\n}\n\n/**\n * A TypeError for input the renderer refuses: a value that could become unsafe markup, or a\n * malformed argument. Dev builds carry the detail; production builds keep the code.\n * @internal\n */\nexport function invalid(code: string, detail: string): TypeError {\n return new TypeError(__DEV__ ? `[shadow ${code}] ${detail}` : `SHADOW_${code}`);\n}\n\n/**\n * The longest delay `setTimeout` honors: larger values fire after one millisecond. A budget above it\n * (`Number.MAX_SAFE_INTEGER` for \"no limit\") is clamped here instead of ending every render at once.\n * @internal\n */\nexport const MAX_TIMER_MS = 2_147_483_647;\n"],"mappings":";;;;;;AAQA,IAAa,WAAb,cAA8B,MAAM;CAClC;CACA,YAAY,MAAoB,QAAgB;EAC9C,MAAgB,WAAW,KAAK,IAAI,QAA2B;EAC/D,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;;;;;AAOA,SAAgB,QAAQ,MAAc,QAA2B;CAC/D,uBAAO,IAAI,UAAoB,WAAW,KAAK,IAAI,QAA2B;AAChF;;;;;;AAOA,MAAa,eAAe"}
@@ -1,4 +1,3 @@
1
- //#region src/server/escape.d.ts
2
1
  /**
3
2
  * Converts any value a JSX child may hold to escaped HTML: the helper compiled server output calls
4
3
  * for every dynamic child, and what the renderers call on the app's result.
@@ -26,5 +25,4 @@
26
25
  * @since 1.0.0
27
26
  */
28
27
  export declare function escape(value: unknown): string;
29
- //#endregion
30
28
  //# sourceMappingURL=escape.d.ts.map