@shadow-js/web 1.0.1 → 1.0.3

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 (281) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/dev/attributes.d.ts +10 -3
  3. package/dist/dev/attributes.js +27 -49
  4. package/dist/dev/attributes.js.map +1 -1
  5. package/dist/dev/class-style.d.ts +15 -6
  6. package/dist/dev/class-style.js +64 -47
  7. package/dist/dev/class-style.js.map +1 -1
  8. package/dist/dev/control-flow/dynamic.d.ts +11 -2
  9. package/dist/dev/control-flow/dynamic.js +57 -40
  10. package/dist/dev/control-flow/dynamic.js.map +1 -1
  11. package/dist/dev/control-flow/error-boundary.js +2 -2
  12. package/dist/dev/control-flow/error-boundary.js.map +1 -1
  13. package/dist/dev/control-flow/portal.d.ts +2 -2
  14. package/dist/dev/control-flow/portal.js +17 -13
  15. package/dist/dev/control-flow/portal.js.map +1 -1
  16. package/dist/dev/control-flow/suspense-list.js +2 -2
  17. package/dist/dev/control-flow/suspense-list.js.map +1 -1
  18. package/dist/dev/control-flow/suspense.js +2 -2
  19. package/dist/dev/control-flow/suspense.js.map +1 -1
  20. package/dist/dev/element.js +6 -3
  21. package/dist/dev/element.js.map +1 -1
  22. package/dist/dev/events.js +15 -44
  23. package/dist/dev/events.js.map +1 -1
  24. package/dist/dev/extend.d.ts +2 -2
  25. package/dist/dev/extend.js +2 -2
  26. package/dist/dev/insert.d.ts +26 -5
  27. package/dist/dev/insert.js +84 -45
  28. package/dist/dev/insert.js.map +1 -1
  29. package/dist/dev/internal/accessor.js +56 -0
  30. package/dist/dev/internal/accessor.js.map +1 -0
  31. package/dist/dev/internal/claim.d.ts +2 -1
  32. package/dist/dev/internal/claim.js +18 -3
  33. package/dist/dev/internal/claim.js.map +1 -1
  34. package/dist/dev/internal/css-units.js +2 -2
  35. package/dist/dev/internal/css-units.js.map +1 -1
  36. package/dist/dev/internal/diagnostics.d.ts +7 -3
  37. package/dist/dev/internal/diagnostics.js +14 -4
  38. package/dist/dev/internal/diagnostics.js.map +1 -1
  39. package/dist/dev/internal/early-events.js +20 -2
  40. package/dist/dev/internal/early-events.js.map +1 -1
  41. package/dist/dev/internal/portal-context.d.ts +9 -0
  42. package/dist/dev/internal/portal-context.js.map +1 -1
  43. package/dist/dev/internal/react-names.js +45 -71
  44. package/dist/dev/internal/react-names.js.map +1 -1
  45. package/dist/dev/internal/reconcile.js +7 -12
  46. package/dist/dev/internal/reconcile.js.map +1 -1
  47. package/dist/dev/jsx/global.d.ts +5 -2
  48. package/dist/dev/jsx/html.d.ts +1 -0
  49. package/dist/dev/resource-hints.js +4 -2
  50. package/dist/dev/resource-hints.js.map +1 -1
  51. package/dist/dev/select-value.js +5 -15
  52. package/dist/dev/select-value.js.map +1 -1
  53. package/dist/dev/server/attributes.d.ts +3 -0
  54. package/dist/dev/server/attributes.js +6 -32
  55. package/dist/dev/server/attributes.js.map +1 -1
  56. package/dist/dev/server/element.js +10 -7
  57. package/dist/dev/server/element.js.map +1 -1
  58. package/dist/dev/server/errors.js +7 -1
  59. package/dist/dev/server/errors.js.map +1 -1
  60. package/dist/dev/server/escape.js +14 -6
  61. package/dist/dev/server/escape.js.map +1 -1
  62. package/dist/dev/server/form-controls.js +5 -2
  63. package/dist/dev/server/form-controls.js.map +1 -1
  64. package/dist/dev/server/index.d.ts +2 -1
  65. package/dist/dev/server/index.js +3 -2
  66. package/dist/dev/server/portals.js +3 -0
  67. package/dist/dev/server/portals.js.map +1 -1
  68. package/dist/dev/server/raw-text.d.ts +28 -0
  69. package/dist/dev/server/raw-text.js +66 -0
  70. package/dist/dev/server/raw-text.js.map +1 -0
  71. package/dist/dev/server/render.d.ts +2 -1
  72. package/dist/dev/server/render.js +3 -3
  73. package/dist/dev/server/render.js.map +1 -1
  74. package/dist/dev/server/stream.d.ts +1 -1
  75. package/dist/dev/server/stream.js +3 -3
  76. package/dist/dev/server/stream.js.map +1 -1
  77. package/dist/dev/server.d.ts +2 -1
  78. package/dist/dev/server.js +3 -2
  79. package/dist/dev/spread.js +56 -81
  80. package/dist/dev/spread.js.map +1 -1
  81. package/dist/dev/template.js +1 -3
  82. package/dist/dev/template.js.map +1 -1
  83. package/dist/dev/view-transition.js +12 -4
  84. package/dist/dev/view-transition.js.map +1 -1
  85. package/dist/prod/attributes.js +1 -1
  86. package/dist/prod/attributes.js.map +1 -1
  87. package/dist/prod/class-style.js +1 -1
  88. package/dist/prod/class-style.js.map +1 -1
  89. package/dist/prod/control-flow/dynamic.js +1 -1
  90. package/dist/prod/control-flow/dynamic.js.map +1 -1
  91. package/dist/prod/control-flow/error-boundary.js +1 -1
  92. package/dist/prod/control-flow/error-boundary.js.map +1 -1
  93. package/dist/prod/control-flow/portal.js +1 -1
  94. package/dist/prod/control-flow/portal.js.map +1 -1
  95. package/dist/prod/control-flow/suspense-list.js +1 -1
  96. package/dist/prod/control-flow/suspense-list.js.map +1 -1
  97. package/dist/prod/control-flow/suspense.js +1 -1
  98. package/dist/prod/control-flow/suspense.js.map +1 -1
  99. package/dist/prod/element.js +1 -1
  100. package/dist/prod/element.js.map +1 -1
  101. package/dist/prod/events.js +1 -1
  102. package/dist/prod/events.js.map +1 -1
  103. package/dist/prod/extend.js +1 -1
  104. package/dist/prod/insert.js +1 -1
  105. package/dist/prod/insert.js.map +1 -1
  106. package/dist/prod/internal/accessor.js +2 -0
  107. package/dist/prod/internal/accessor.js.map +1 -0
  108. package/dist/prod/internal/claim.js +1 -1
  109. package/dist/prod/internal/claim.js.map +1 -1
  110. package/dist/prod/internal/css-units.js +1 -1
  111. package/dist/prod/internal/css-units.js.map +1 -1
  112. package/dist/prod/internal/diagnostics.js +1 -1
  113. package/dist/prod/internal/diagnostics.js.map +1 -1
  114. package/dist/prod/internal/early-events.js +1 -1
  115. package/dist/prod/internal/early-events.js.map +1 -1
  116. package/dist/prod/internal/portal-context.js.map +1 -1
  117. package/dist/prod/internal/react-names.js +1 -1
  118. package/dist/prod/internal/react-names.js.map +1 -1
  119. package/dist/prod/internal/reconcile.js +1 -1
  120. package/dist/prod/internal/reconcile.js.map +1 -1
  121. package/dist/prod/resource-hints.js +1 -1
  122. package/dist/prod/resource-hints.js.map +1 -1
  123. package/dist/prod/select-value.js +1 -1
  124. package/dist/prod/select-value.js.map +1 -1
  125. package/dist/prod/server/attributes.js +1 -1
  126. package/dist/prod/server/attributes.js.map +1 -1
  127. package/dist/prod/server/element.js +1 -1
  128. package/dist/prod/server/element.js.map +1 -1
  129. package/dist/prod/server/errors.js +1 -1
  130. package/dist/prod/server/errors.js.map +1 -1
  131. package/dist/prod/server/escape.js +1 -1
  132. package/dist/prod/server/escape.js.map +1 -1
  133. package/dist/prod/server/form-controls.js +2 -2
  134. package/dist/prod/server/form-controls.js.map +1 -1
  135. package/dist/prod/server/index.js +1 -1
  136. package/dist/prod/server/portals.js +1 -1
  137. package/dist/prod/server/portals.js.map +1 -1
  138. package/dist/prod/server/raw-text.js +2 -0
  139. package/dist/prod/server/raw-text.js.map +1 -0
  140. package/dist/prod/server/render.js +1 -1
  141. package/dist/prod/server/render.js.map +1 -1
  142. package/dist/prod/server/stream.js +1 -1
  143. package/dist/prod/server/stream.js.map +1 -1
  144. package/dist/prod/server.js +1 -1
  145. package/dist/prod/spread.js +1 -1
  146. package/dist/prod/spread.js.map +1 -1
  147. package/dist/prod/template.js +1 -1
  148. package/dist/prod/template.js.map +1 -1
  149. package/dist/prod/view-transition.js +1 -1
  150. package/dist/prod/view-transition.js.map +1 -1
  151. package/dist/server/attributes.js +1 -1
  152. package/dist/server/attributes.js.map +1 -1
  153. package/dist/server/class-style.js +1 -1
  154. package/dist/server/class-style.js.map +1 -1
  155. package/dist/server/control-flow/dynamic.js +1 -1
  156. package/dist/server/control-flow/dynamic.js.map +1 -1
  157. package/dist/server/control-flow/error-boundary.js +1 -1
  158. package/dist/server/control-flow/error-boundary.js.map +1 -1
  159. package/dist/server/control-flow/portal.js +1 -1
  160. package/dist/server/control-flow/portal.js.map +1 -1
  161. package/dist/server/control-flow/suspense-list.js +1 -1
  162. package/dist/server/control-flow/suspense-list.js.map +1 -1
  163. package/dist/server/control-flow/suspense.js +1 -1
  164. package/dist/server/control-flow/suspense.js.map +1 -1
  165. package/dist/server/element.js +1 -1
  166. package/dist/server/element.js.map +1 -1
  167. package/dist/server/events.js +1 -1
  168. package/dist/server/events.js.map +1 -1
  169. package/dist/server/extend.js +1 -1
  170. package/dist/server/insert.js +1 -1
  171. package/dist/server/insert.js.map +1 -1
  172. package/dist/server/internal/accessor.js +2 -0
  173. package/dist/server/internal/accessor.js.map +1 -0
  174. package/dist/server/internal/claim.js +1 -1
  175. package/dist/server/internal/claim.js.map +1 -1
  176. package/dist/server/internal/css-units.js +1 -1
  177. package/dist/server/internal/css-units.js.map +1 -1
  178. package/dist/server/internal/diagnostics.js +1 -1
  179. package/dist/server/internal/diagnostics.js.map +1 -1
  180. package/dist/server/internal/early-events.js +1 -1
  181. package/dist/server/internal/early-events.js.map +1 -1
  182. package/dist/server/internal/portal-context.js.map +1 -1
  183. package/dist/server/internal/react-names.js +1 -1
  184. package/dist/server/internal/react-names.js.map +1 -1
  185. package/dist/server/internal/reconcile.js +1 -1
  186. package/dist/server/internal/reconcile.js.map +1 -1
  187. package/dist/server/resource-hints.js +1 -1
  188. package/dist/server/resource-hints.js.map +1 -1
  189. package/dist/server/select-value.js +1 -1
  190. package/dist/server/select-value.js.map +1 -1
  191. package/dist/server/server/attributes.js +1 -1
  192. package/dist/server/server/attributes.js.map +1 -1
  193. package/dist/server/server/element.js +1 -1
  194. package/dist/server/server/element.js.map +1 -1
  195. package/dist/server/server/errors.js +1 -1
  196. package/dist/server/server/errors.js.map +1 -1
  197. package/dist/server/server/escape.js +1 -1
  198. package/dist/server/server/escape.js.map +1 -1
  199. package/dist/server/server/form-controls.js +2 -2
  200. package/dist/server/server/form-controls.js.map +1 -1
  201. package/dist/server/server/index.js +1 -1
  202. package/dist/server/server/portals.js +1 -1
  203. package/dist/server/server/portals.js.map +1 -1
  204. package/dist/server/server/raw-text.js +2 -0
  205. package/dist/server/server/raw-text.js.map +1 -0
  206. package/dist/server/server/render.js +1 -1
  207. package/dist/server/server/render.js.map +1 -1
  208. package/dist/server/server/stream.js +1 -1
  209. package/dist/server/server/stream.js.map +1 -1
  210. package/dist/server/server.js +1 -1
  211. package/dist/server/spread.js +1 -1
  212. package/dist/server/spread.js.map +1 -1
  213. package/dist/server/template.js +1 -1
  214. package/dist/server/template.js.map +1 -1
  215. package/dist/server/view-transition.js.map +1 -1
  216. package/dist/server-dev/attributes.js +27 -49
  217. package/dist/server-dev/attributes.js.map +1 -1
  218. package/dist/server-dev/class-style.js +64 -47
  219. package/dist/server-dev/class-style.js.map +1 -1
  220. package/dist/server-dev/control-flow/dynamic.js +22 -10
  221. package/dist/server-dev/control-flow/dynamic.js.map +1 -1
  222. package/dist/server-dev/control-flow/error-boundary.js +2 -2
  223. package/dist/server-dev/control-flow/error-boundary.js.map +1 -1
  224. package/dist/server-dev/control-flow/portal.js +17 -13
  225. package/dist/server-dev/control-flow/portal.js.map +1 -1
  226. package/dist/server-dev/control-flow/suspense-list.js +2 -2
  227. package/dist/server-dev/control-flow/suspense-list.js.map +1 -1
  228. package/dist/server-dev/control-flow/suspense.js +2 -2
  229. package/dist/server-dev/control-flow/suspense.js.map +1 -1
  230. package/dist/server-dev/element.js +3 -1
  231. package/dist/server-dev/element.js.map +1 -1
  232. package/dist/server-dev/events.js +15 -44
  233. package/dist/server-dev/events.js.map +1 -1
  234. package/dist/server-dev/extend.js +2 -2
  235. package/dist/server-dev/insert.js +84 -45
  236. package/dist/server-dev/insert.js.map +1 -1
  237. package/dist/server-dev/internal/accessor.js +56 -0
  238. package/dist/server-dev/internal/accessor.js.map +1 -0
  239. package/dist/server-dev/internal/claim.js +18 -3
  240. package/dist/server-dev/internal/claim.js.map +1 -1
  241. package/dist/server-dev/internal/css-units.js +2 -2
  242. package/dist/server-dev/internal/css-units.js.map +1 -1
  243. package/dist/server-dev/internal/diagnostics.js +14 -4
  244. package/dist/server-dev/internal/diagnostics.js.map +1 -1
  245. package/dist/server-dev/internal/early-events.js +20 -2
  246. package/dist/server-dev/internal/early-events.js.map +1 -1
  247. package/dist/server-dev/internal/portal-context.js.map +1 -1
  248. package/dist/server-dev/internal/react-names.js +45 -71
  249. package/dist/server-dev/internal/react-names.js.map +1 -1
  250. package/dist/server-dev/internal/reconcile.js +7 -12
  251. package/dist/server-dev/internal/reconcile.js.map +1 -1
  252. package/dist/server-dev/resource-hints.js +4 -2
  253. package/dist/server-dev/resource-hints.js.map +1 -1
  254. package/dist/server-dev/select-value.js +5 -15
  255. package/dist/server-dev/select-value.js.map +1 -1
  256. package/dist/server-dev/server/attributes.js +6 -32
  257. package/dist/server-dev/server/attributes.js.map +1 -1
  258. package/dist/server-dev/server/element.js +10 -7
  259. package/dist/server-dev/server/element.js.map +1 -1
  260. package/dist/server-dev/server/errors.js +7 -1
  261. package/dist/server-dev/server/errors.js.map +1 -1
  262. package/dist/server-dev/server/escape.js +14 -6
  263. package/dist/server-dev/server/escape.js.map +1 -1
  264. package/dist/server-dev/server/form-controls.js +5 -2
  265. package/dist/server-dev/server/form-controls.js.map +1 -1
  266. package/dist/server-dev/server/index.js +3 -2
  267. package/dist/server-dev/server/portals.js +3 -0
  268. package/dist/server-dev/server/portals.js.map +1 -1
  269. package/dist/server-dev/server/raw-text.js +86 -0
  270. package/dist/server-dev/server/raw-text.js.map +1 -0
  271. package/dist/server-dev/server/render.js +3 -3
  272. package/dist/server-dev/server/render.js.map +1 -1
  273. package/dist/server-dev/server/stream.js +3 -3
  274. package/dist/server-dev/server/stream.js.map +1 -1
  275. package/dist/server-dev/server.js +3 -2
  276. package/dist/server-dev/spread.js +42 -80
  277. package/dist/server-dev/spread.js.map +1 -1
  278. package/dist/server-dev/template.js +1 -3
  279. package/dist/server-dev/template.js.map +1 -1
  280. package/dist/server-dev/view-transition.js.map +1 -1
  281. package/package.json +4 -3
@@ -1,2 +1,2 @@
1
- const e=/^(?:alignment|baseline|clip|color|dominant|enable|fill|flood|font|glyph|image|letter|lighting|marker|mask|mix|paint|pointer|shape|stop|stroke|text|transform|unicode|vector|white|word|writing)(?=[A-Z])/,t=/* @__PURE__ */ new Set([`clipPathUnits`,`glyphRef`,`markerHeight`,`markerUnits`,`markerWidth`,`maskContentUnits`,`maskUnits`,`textLength`]);function n(n,i){if(n===`className`)return`class`;if(n===`htmlFor`)return`for`;if(n===`httpEquiv`)return`http-equiv`;if(n===`acceptCharset`)return`accept-charset`;if(!i)return n.toLowerCase();if(n.includes(`:`))return n;let a=/^xlink([A-Z].*)$/.exec(n);if(a!==null)return`xlink:${r(a[1]??``)}`;let o=/^xml([A-Z].*)$/.exec(n);return o===null?t.has(n)||!e.test(n)?n:n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`):`xml:${r(o[1]??``)}`}function r(e){return e.replace(/^[A-Z]/,e=>e.toLowerCase())}const i=/* @__PURE__ */ new Set([`key`,`suppressHydrationWarning`,`suppressContentEditableWarning`]),a=/* @__PURE__ */ new Set([`checkbox`,`radio`,`file`]);function o(e,t,n){let r=/^on[A-Z]/.test(e),i=r&&e.endsWith(`Capture`),o=e.slice(2,i?-7:void 0);if(!r)return{type:o.toLowerCase(),capture:!1,passive:!1};let s=o.toLowerCase();return s===`change`?{type:t===`textarea`||t===`input`&&(n===null||!a.has(n))?`input`:`change`,capture:i,passive:!1}:s===`focus`?{type:`focusin`,capture:i,passive:!1}:s===`blur`?{type:`focusout`,capture:i,passive:!1}:s===`doubleclick`?{type:`dblclick`,capture:i,passive:!1}:s===`wheel`?{type:`wheel`,capture:i,passive:!i}:{type:s,capture:i,passive:!1}}export{i as IGNORED_KEYS,n as attributeName,o as eventPlan};
1
+ const e=/^(?!clipPathUnits|glyphRef|marker(?:Height|Units|Width)|mask(?:Content)?Units|textLength)(?:alignment|baseline|clip|color|dominant|enable|fill|flood|font|glyph|image|letter|lighting|marker|mask|mix|paint|pointer|shape|stop|stroke|text|transform|unicode|vector|white|word|writing)(?=[A-Z])/,t=/* @__PURE__ */ new Map([[`className`,`class`],[`htmlFor`,`for`],[`httpEquiv`,`http-equiv`],[`acceptCharset`,`accept-charset`]]);function n(n,r){let i=t.get(n);if(i!==void 0)return i;if(!r)return n.toLowerCase();if(n.includes(`:`))return n;let a=/^(xlink|xml)([A-Z])(.*)$/.exec(n);return a===null?e.test(n)?n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`):n:`${a[1]}:${a[2]?.toLowerCase()}${a[3]}`}const r=/^(?:key|suppress(?:Hydration|ContentEditable)Warning)$/,i=/* @__PURE__ */ new Map([[`focus`,`focusin`],[`blur`,`focusout`],[`doubleclick`,`dblclick`]]),a=/^(?:checkbox|radio|file)$/;function o(e,t,n){let r=/^on[A-Z]/.test(e),o=r&&e.endsWith(`Capture`),s=e.slice(2,o?-7:void 0).toLowerCase(),c=s;return r&&(c=s===`change`?t===`textarea`||t===`input`&&(n===null||!a.test(n))?`input`:`change`:i.get(s)??s),{type:c,capture:o,passive:r&&s===`wheel`&&!o}}function s(e,t){return` async autofocus autoplay checked controls default defer disabled formnovalidate hidden inert ismap loop multiple muted nomodule novalidate open playsinline readonly required reversed selected `.includes(` ${e} `)&&(e!==`hidden`||t!==`until-found`)}export{r as IGNORED_KEYS,n as attributeName,o as eventPlan,s as isFlagAttribute};
2
2
  //# sourceMappingURL=react-names.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-names.js","names":["SVG_PROPERTY_FAMILY","SVG_CAMEL_ATTRIBUTES","attributeName","name","svg","xlink","lowerFirst","xml","letter","text","IGNORED_KEYS","CHANGE_ON_TYPES","eventPlan","reactSpelling","attribute","capture","base","lower","tag","type"],"sources":["../../../src/internal/react-names.ts"],"sourcesContent":["/**\n * React spellings at run time: the attribute and event names that a props object (a spread) passes\n * through. The compiler resolves the same names at build time (`packages/compiler/src/internal/\n * react-names.ts`); a test keeps the two presentation lists equal, so keep them in step.\n *\n * @internal\n */\n\n/**\n * SVG presentation attributes are CSS properties, and React spells them in camelCase (`strokeWidth` is\n * `stroke-width`). A camelCase name whose first word is one of these families is hyphenated. The\n * families are the first words of the CSS properties SVG takes as attributes, so one rule covers the\n * presentation list. The compiler's table (`packages/compiler/src/internal/react-names.ts`) lists the\n * same names, and a test checks each one.\n */\nconst SVG_PROPERTY_FAMILY =\n /^(?:alignment|baseline|clip|color|dominant|enable|fill|flood|font|glyph|image|letter|lighting|marker|mask|mix|paint|pointer|shape|stop|stroke|text|transform|unicode|vector|white|word|writing)(?=[A-Z])/;\n\n/**\n * SVG attributes that start with a property family but are not CSS properties (`clipPathUnits`,\n * `markerWidth`): they are camelCase in SVG, so they keep their case.\n */\nconst SVG_CAMEL_ATTRIBUTES: ReadonlySet<string> = new Set([\n \"clipPathUnits\",\n \"glyphRef\",\n \"markerHeight\",\n \"markerUnits\",\n \"markerWidth\",\n \"maskContentUnits\",\n \"maskUnits\",\n \"textLength\",\n]);\n\n/**\n * The attribute name for a props key on an element: HTML names are lower case (what the parser and\n * `setAttribute` write anyway, and what server markup needs); SVG presentation names are hyphenated,\n * `xlinkHref` and `xmlLang` take their prefix, and other SVG names keep their case (`viewBox`).\n * @internal\n */\nexport function attributeName(name: string, svg: boolean): string {\n if (name === \"className\") return \"class\";\n if (name === \"htmlFor\") return \"for\";\n if (name === \"httpEquiv\") return \"http-equiv\";\n if (name === \"acceptCharset\") return \"accept-charset\";\n if (!svg) return name.toLowerCase();\n if (name.includes(\":\")) return name;\n const xlink = /^xlink([A-Z].*)$/.exec(name);\n if (xlink !== null) return `xlink:${lowerFirst(xlink[1] ?? \"\")}`;\n const xml = /^xml([A-Z].*)$/.exec(name);\n if (xml !== null) return `xml:${lowerFirst(xml[1] ?? \"\")}`;\n if (SVG_CAMEL_ATTRIBUTES.has(name) || !SVG_PROPERTY_FAMILY.test(name)) return name;\n return name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n}\n\nfunction lowerFirst(text: string): string {\n return text.replace(/^[A-Z]/, (letter) => letter.toLowerCase());\n}\n\n/** Props that have no DOM form: a spread ignores them (React's `key` and hydration flags). @internal */\nexport const IGNORED_KEYS: ReadonlySet<string> = new Set([\n \"key\",\n \"suppressHydrationWarning\",\n \"suppressContentEditableWarning\",\n]);\n\n/** The DOM event for a React-spelled prop (see the compiler's `eventPlan`). @internal */\nexport interface EventPlan {\n readonly type: string;\n readonly capture: boolean;\n readonly passive: boolean;\n}\n\nconst CHANGE_ON_TYPES: ReadonlySet<string> = new Set([\"checkbox\", \"radio\", \"file\"]);\n\n/**\n * Plans the DOM event for an `on*` prop. React's spellings follow React: `onChange` is the per-edit\n * `input` event on text inputs and textareas and the `change` event on other controls; `onFocus` and\n * `onBlur` bubble as `focusin` and `focusout`; a `...Capture` suffix binds the capture phase; `onWheel`\n * is passive. A lower-case `on` spelling is the native event.\n * @internal\n */\nexport function eventPlan(attribute: string, tag: string, type: string | null): EventPlan {\n const reactSpelling = /^on[A-Z]/.test(attribute);\n const capture = reactSpelling && attribute.endsWith(\"Capture\");\n const base = attribute.slice(2, capture ? -\"Capture\".length : undefined);\n if (!reactSpelling) return { type: base.toLowerCase(), capture: false, passive: false };\n const lower = base.toLowerCase();\n if (lower === \"change\") {\n const perEdit =\n tag === \"textarea\" || (tag === \"input\" && (type === null || !CHANGE_ON_TYPES.has(type)));\n return { type: perEdit ? \"input\" : \"change\", capture, passive: false };\n }\n if (lower === \"focus\") return { type: \"focusin\", capture, passive: false };\n if (lower === \"blur\") return { type: \"focusout\", capture, passive: false };\n if (lower === \"doubleclick\") return { type: \"dblclick\", capture, passive: false };\n if (lower === \"wheel\") return { type: \"wheel\", capture, passive: !capture };\n return { type: lower, capture, passive: false };\n}\n"],"mappings":"AAeA,MAAMA,EACJ,2MAMIC,kBAA4C,IAAI,IAAI,CACxD,gBACA,WACA,eACA,cACA,cACA,mBACA,YACA,YACF,CAAC,EAQD,SAAgBC,EAAc,EAAc,EAAsB,CAChE,GAAIC,IAAS,YAAa,MAAO,QACjC,GAAIA,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U,OAAe,CAAE,KAAM,WAAY,UAAS,QAAS,EAAM,EACrEA,IAAU,cAAsB,CAAE,KAAM,WAAY,UAAS,QAAS,EAAM,EAC5EA,IAAU,QAAgB,CAAE,KAAM,QAAS,UAAS,QAAS,CAACF,CAAQ,EACnE,CAAE,KAAME,EAAO,UAAS,QAAS,EAAM,CAChD,C"}
1
+ {"version":3,"file":"react-names.js","names":["SVG_PROPERTY_FAMILY","RENAMED","attributeName","renamed","name","svg","prefixed","letter","IGNORED_KEYS","REACT_EVENTS","CHANGE_ON_TYPES","eventPlan","reactSpelling","attribute","capture","lower","planned","tag","type","isFlagAttribute","value"],"sources":["../../../src/internal/react-names.ts"],"sourcesContent":["/**\n * React spellings at run time: the attribute and event names that a props object (a spread) passes\n * through. The compiler resolves the same names at build time (`packages/compiler/src/internal/\n * react-names.ts`); a test keeps the two presentation lists equal, so keep them in step.\n *\n * @internal\n */\n\n/**\n * SVG presentation attributes are CSS properties, and React spells them in camelCase (`strokeWidth` is\n * `stroke-width`). A camelCase name whose first word is one of these families is hyphenated. The\n * families are the first words of the CSS properties SVG takes as attributes, so one rule covers the\n * presentation list. The compiler's table (`packages/compiler/src/internal/react-names.ts`) lists the\n * same names, and a test checks each one. The exceptions are SVG attributes that start with a family but are\n * not CSS properties (`clipPathUnits`, `markerWidth`): they are camelCase in SVG, so they keep their case.\n */\nconst SVG_PROPERTY_FAMILY =\n /^(?!clipPathUnits|glyphRef|marker(?:Height|Units|Width)|mask(?:Content)?Units|textLength)(?:alignment|baseline|clip|color|dominant|enable|fill|flood|font|glyph|image|letter|lighting|marker|mask|mix|paint|pointer|shape|stop|stroke|text|transform|unicode|vector|white|word|writing)(?=[A-Z])/;\n\n/** React names whose attribute differs from the lower-cased key, in HTML and SVG alike. */\nconst RENAMED: ReadonlyMap<string, string> = new Map([\n [\"className\", \"class\"],\n [\"htmlFor\", \"for\"],\n [\"httpEquiv\", \"http-equiv\"],\n [\"acceptCharset\", \"accept-charset\"],\n]);\n\n/**\n * The attribute name for a props key on an element: HTML names are lower case (what the parser and\n * `setAttribute` write anyway, and what server markup needs); SVG presentation names are hyphenated,\n * `xlinkHref` and `xmlLang` take their prefix, and other SVG names keep their case (`viewBox`).\n * @internal\n */\nexport function attributeName(name: string, svg: boolean): string {\n const renamed = RENAMED.get(name);\n if (renamed !== undefined) return renamed;\n if (!svg) return name.toLowerCase();\n if (name.includes(\":\")) return name;\n const prefixed = /^(xlink|xml)([A-Z])(.*)$/.exec(name);\n if (prefixed !== null) return `${prefixed[1]}:${prefixed[2]?.toLowerCase()}${prefixed[3]}`;\n if (!SVG_PROPERTY_FAMILY.test(name)) return name;\n return name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n}\n\n/** Props that have no DOM form: a spread ignores them (React's `key` and hydration flags). @internal */\nexport const IGNORED_KEYS: RegExp = /^(?:key|suppress(?:Hydration|ContentEditable)Warning)$/;\n\n/** The DOM event for a React-spelled prop (see the compiler's `eventPlan`). @internal */\nexport interface EventPlan {\n readonly type: string;\n readonly capture: boolean;\n readonly passive: boolean;\n}\n\n/** React events that bubble under another name. */\nconst REACT_EVENTS: ReadonlyMap<string, string> = new Map([\n [\"focus\", \"focusin\"],\n [\"blur\", \"focusout\"],\n [\"doubleclick\", \"dblclick\"],\n]);\n\nconst CHANGE_ON_TYPES = /^(?:checkbox|radio|file)$/;\n\n/**\n * Plans the DOM event for an `on*` prop. React's spellings follow React: `onChange` is the per-edit\n * `input` event on text inputs and textareas and the `change` event on other controls; `onFocus` and\n * `onBlur` bubble as `focusin` and `focusout`; a `...Capture` suffix binds the capture phase; `onWheel`\n * is passive. A lower-case `on` spelling is the native event.\n * @internal\n */\nexport function eventPlan(attribute: string, tag: string, type: string | null): EventPlan {\n const reactSpelling = /^on[A-Z]/.test(attribute);\n const capture = reactSpelling && attribute.endsWith(\"Capture\");\n const lower = attribute.slice(2, capture ? -\"Capture\".length : undefined).toLowerCase();\n let planned = lower;\n if (reactSpelling) {\n planned =\n lower === \"change\"\n ? tag === \"textarea\" || (tag === \"input\" && (type === null || !CHANGE_ON_TYPES.test(type)))\n ? \"input\"\n : \"change\"\n : (REACT_EVENTS.get(lower) ?? lower);\n }\n return { type: planned, capture, passive: reactSpelling && lower === \"wheel\" && !capture };\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. The server and the client share this test, so a value that\n * renders a flag on one side renders it on the other. One space-separated string, not a set of\n * strings, because every bundle that spreads props carries it. A name with a space in it can match\n * two neighbors, but such a name is not a valid attribute name and both renderers refuse it before\n * they write anything.\n */\nconst BOOLEAN_ATTRIBUTES =\n \" async autofocus autoplay checked controls default defer disabled formnovalidate hidden inert \" +\n \"ismap loop multiple muted nomodule novalidate open playsinline readonly required reversed selected \";\n\n/**\n * True when a prop written under attribute name `name` is a presence flag for `value`: one of the\n * boolean attributes, except `hidden=\"until-found\"`, a keyword that only collapses the element\n * (a bare `hidden` would hide it). The client writes the flag with truthiness, as the server does.\n * @internal\n */\nexport function isFlagAttribute(name: string, value: unknown): boolean {\n return (\n BOOLEAN_ATTRIBUTES.includes(` ${name} `) && !(name === \"hidden\" && value === \"until-found\")\n );\n}\n"],"mappings":"AAgBA,MAAMA,EACJ,mSAGIC,kBAAuC,IAAI,IAAI,CACnD,CAAC,YAAa,OAAO,EACrB,CAAC,UAAW,KAAK,EACjB,CAAC,YAAa,YAAY,EAC1B,CAAC,gBAAiB,gBAAgB,CACpC,CAAC,EAQD,SAAgBC,EAAc,EAAc,EAAsB,CAChE,IAAMC,EAAUF,EAAQ,IAAIG,CAAI,EAChC,GAAID,IAAY,IAAA,GAAW,OAAOA,EAClC,GAAI,CAACE,EAAK,OAAOD,EAAK,YAAY,EAClC,GAAIA,EAAK,SAAS,GAAG,EAAG,OAAOA,EAC/B,IAAME,EAAW,2BAA2B,KAAKF,CAAI,EAGrD,OAFIE,IAAa,KACZN,EAAoB,KAAKI,CAAI,EAC3BA,EAAK,QAAQ,SAAW,GAAW,IAAIG,EAAO,YAAY,GAAG,EADxBH,EADd,GAAGE,EAAS,GAAG,GAAGA,EAAS,EAAE,EAAE,YAAY,IAAIA,EAAS,IAGxF,CAGA,MAAaE,EAAuB,yDAU9BC,kBAA4C,IAAI,IAAI,CACxD,CAAC,QAAS,SAAS,EACnB,CAAC,OAAQ,UAAU,EACnB,CAAC,cAAe,UAAU,CAC5B,CAAC,EAEKC,EAAkB,4BASxB,SAAgBC,EAAU,EAAmB,EAAa,EAAgC,CACxF,IAAMC,EAAgB,WAAW,KAAKC,CAAS,EACzCC,EAAUF,GAAiBC,EAAU,SAAS,SAAS,EACvDE,EAAQF,EAAU,MAAM,EAAGC,EAAU,GAAoB,IAAA,EAAS,CAAC,CAAC,YAAY,EAClFE,EAAUD,EASd,OARIH,IACF,EACEG,IAAU,SACNE,IAAQ,YAAeA,IAAQ,UAAYC,IAAS,MAAQ,CAACR,EAAgB,KAAKQ,CAAI,GACpF,QACA,SACDT,EAAa,IAAIM,CAAK,GAAKA,GAE7B,CAAE,KAAMC,EAAS,UAAS,QAASJ,GAAiBG,IAAU,SAAW,CAACD,CAAQ,CAC3F,CAoBA,SAAgBK,EAAgB,EAAc,EAAyB,CACrE,MACE,oMAAmB,SAAS,IAAIf,EAAK,EAAE,IAAOA,IAAS,UAAYgB,IAAU,cAEjF,C"}
@@ -1,2 +1,2 @@
1
- function e(e,t){t!==void 0&&t.parentNode===e&&e.removeChild(t)}function t(e,t,n){let r=[],i=e.map(()=>-1);for(let t=0;t<e.length;t+=1){let n=e[t]??0,a=0,o=r.length;for(;a<o;){let t=a+o>>1;(e[r[t]??0]??0)<n?a=t+1:o=t}i[t]=a>0?r[a-1]??-1:-1,r[a]=t}let a=r.length>0?r[r.length-1]??-1:-1;for(;a!==-1;)n[(e[a]??0)-t]=1,a=i[a]??-1}function n(n,r,i,a){let o=r.length,s=i.length,c=0;for(;c<o&&c<s&&r[c]===i[c];)c+=1;let l=o,u=s;for(;l>c&&u>c&&r[l-1]===i[u-1];)--l,--u;if(l===c&&u===c)return;let d=u<s?i[u]??null:a;if(u===c){for(let t=c;t<l;t+=1)e(n,r[t]);return}let f=/* @__PURE__ */ new Map;for(let e=c;e<u;e+=1){let t=i[e];t!==void 0&&f.set(t,e)}let p=[];for(let t=c;t<l;t+=1){let i=r[t];if(i===void 0)continue;let a=f.get(i);a===void 0?e(n,i):p.push(a)}if(p.length===0){for(let e=c;e<u;e+=1){let t=i[e];t!==void 0&&n.insertBefore(t,d)}return}let m=new Uint8Array(u-c);t(p,c,m);let h=typeof n.moveBefore==`function`,g=d;for(let e=u-1;e>=c;--e){let t=i[e];t!==void 0&&(m[e-c]!==1&&(h&&t.parentNode===n?n.moveBefore(t,g):n.insertBefore(t,g)),g=t)}}export{n as reconcileNodes};
1
+ function e(e,t){t!==void 0&&t.parentNode===e&&e.removeChild(t)}function t(e,t,n){let r=[],i=e.map(()=>-1);for(let t=0;t<e.length;t+=1){let n=e[t],a=0,o=r.length;for(;a<o;){let t=a+o>>1;e[r[t]]<n?a=t+1:o=t}i[t]=r[a-1]??-1,r[a]=t}let a=r.at(-1)??-1;for(;a!==-1;)n[e[a]-t]=1,a=i[a]}function n(n,r,i,a){let o=r.length,s=i.length,c=0;for(;c<o&&c<s&&r[c]===i[c];)c+=1;let l=o,u=s;for(;l>c&&u>c&&r[l-1]===i[u-1];)--l,--u;if(l===c&&u===c)return;let d=u<s?i[u]??null:a;if(u===c){for(let t=c;t<l;t+=1)e(n,r[t]);return}let f=/* @__PURE__ */ new Map;for(let e=c;e<u;e+=1){let t=i[e];t!==void 0&&f.set(t,e)}let p=[];for(let t=c;t<l;t+=1){let i=r[t],a=f.get(i);a===void 0?e(n,i):p.push(a)}if(p.length===0){for(let e of i.slice(c,u))n.insertBefore(e,d);return}let m=new Uint8Array(u-c);t(p,c,m);let h=typeof n.moveBefore==`function`,g=d;for(let e=u-1;e>=c;--e){let t=i[e];m[e-c]!==1&&(h&&t.parentNode===n?n.moveBefore(t,g):n.insertBefore(t,g)),g=t}}export{n as reconcileNodes};
2
2
  //# sourceMappingURL=reconcile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reconcile.js","names":["removeNode","node","parent","markLongestIncreasing","tails","previous","values","index","value","low","high","middle","cursor","offset","reconcileNodes","prevLength","prev","nextLength","next","head","prevTail","nextTail","before","end","target","survivors","position","stable","movable","anchorNode"],"sources":["../../../src/internal/reconcile.ts"],"sourcesContent":["/** A parent that can move a child in place (Element.prototype.moveBefore, where implemented). */\ninterface MovableParent extends Node {\n moveBefore(node: Node, child: Node | null): void;\n}\n\n/** Removes `node` only when it is still a child of `parent`, so detached nodes are ignored. */\nfunction removeNode(parent: Node, node: Node | undefined): void {\n if (node !== undefined && node.parentNode === parent) parent.removeChild(node);\n}\n\n/**\n * Marks the members of one longest strictly increasing subsequence of `values` in `marks`, where\n * `values[k]` is the target position of the k-th surviving node and `marks[v - offset]` is set for\n * target position `v`. Patience sorting: O(n log n).\n */\nfunction markLongestIncreasing(values: readonly number[], offset: number, marks: Uint8Array): void {\n // tails[k]: index into `values` of the smallest tail of an increasing run of length k + 1.\n const tails: number[] = [];\n const previous: number[] = values.map(() => -1);\n for (let index = 0; index < values.length; index += 1) {\n const value = values[index] ?? 0;\n let low = 0;\n let high = tails.length;\n while (low < high) {\n const middle = (low + high) >> 1;\n const probe = values[tails[middle] ?? 0] ?? 0;\n if (probe < value) low = middle + 1;\n else high = middle;\n }\n previous[index] = low > 0 ? (tails[low - 1] ?? -1) : -1;\n tails[low] = index;\n }\n let cursor = tails.length > 0 ? (tails[tails.length - 1] ?? -1) : -1;\n while (cursor !== -1) {\n marks[(values[cursor] ?? 0) - offset] = 1;\n cursor = previous[cursor] ?? -1;\n }\n}\n\n/**\n * Updates one region of `parent`'s children from the nodes `prev` to the nodes `next`, keeping every\n * node that stays and moving as few as possible: the list reconciliation `insert` performs for arrays\n * (and so for `For`). Use it in a custom list renderer.\n *\n * Preconditions: `prev` are the nodes this region owns, in DOM order and all children of `parent`;\n * `next` holds no duplicates; `end` is the node after the region (null for the end of `parent`).\n *\n * Strategy, in three steps:\n * 1. Trim the common prefix and suffix: appends, prepends, and removals at either end touch\n * only the nodes that changed (no move at all).\n * 2. Remove the nodes that left the value. A node that is still present is never removed.\n * 3. Place the rest from the end of `next` backwards. Nodes on a longest increasing subsequence of\n * surviving positions stay where they are; every other node is moved (or inserted) directly\n * before the node that follows it in `next`. Moves use `moveBefore` when the parent has it,\n * which keeps focus and iframe state, and `insertBefore` otherwise. Each node moves at most once,\n * and the number of moves is minimal for the surviving order.\n *\n * @param parent The parent of the region.\n * @param prev The nodes the region holds now, in DOM order, all children of `parent`.\n * @param next The nodes the region must hold, in order, without duplicates. A node of `prev` that is\n * not in `next` is removed; a node of `next` that is not in `prev` is inserted.\n * @param end The node right after the region; `null` when the region runs to the end of `parent`.\n * @example\n * import { reconcileNodes } from \"@shadow-js/web/extend\";\n *\n * const item = (text: string): HTMLLIElement =>\n * Object.assign(document.createElement(\"li\"), { textContent: text });\n * const list = document.createElement(\"ul\");\n * const a = item(\"a\");\n * const b = item(\"b\");\n * const c = item(\"c\");\n * list.append(a, b, c);\n * reconcileNodes(list, [a, b, c], [c, a], null); // removes b, moves c before a\n * @since 1.0.0\n */\nexport function reconcileNodes(\n parent: Node,\n prev: readonly Node[],\n next: readonly Node[],\n end: Node | null,\n): void {\n const prevLength = prev.length;\n const nextLength = next.length;\n\n let head = 0;\n while (head < prevLength && head < nextLength && prev[head] === next[head]) head += 1;\n let prevTail = prevLength;\n let nextTail = nextLength;\n while (prevTail > head && nextTail > head && prev[prevTail - 1] === next[nextTail - 1]) {\n prevTail -= 1;\n nextTail -= 1;\n }\n if (prevTail === head && nextTail === head) return;\n\n // Everything in the common suffix is already in place, so the middle goes before its first node.\n const before = nextTail < nextLength ? (next[nextTail] ?? null) : end;\n\n if (nextTail === head) {\n for (let index = head; index < prevTail; index += 1) removeNode(parent, prev[index]);\n return;\n }\n\n const target = new Map<Node, number>();\n for (let index = head; index < nextTail; index += 1) {\n const node = next[index];\n if (node !== undefined) target.set(node, index);\n }\n\n const survivors: number[] = [];\n for (let index = head; index < prevTail; index += 1) {\n const node = prev[index];\n if (node === undefined) continue;\n const position = target.get(node);\n if (position === undefined) removeNode(parent, node);\n else survivors.push(position);\n }\n\n if (survivors.length === 0) {\n for (let index = head; index < nextTail; index += 1) {\n const node = next[index];\n if (node !== undefined) parent.insertBefore(node, before);\n }\n return;\n }\n\n const stable = new Uint8Array(nextTail - head);\n markLongestIncreasing(survivors, head, stable);\n const movable = typeof (parent as Partial<MovableParent>).moveBefore === \"function\";\n\n let anchorNode = before;\n for (let index = nextTail - 1; index >= head; index -= 1) {\n const node = next[index];\n if (node === undefined) continue;\n if (stable[index - head] !== 1) {\n if (movable && node.parentNode === parent)\n (parent as MovableParent).moveBefore(node, anchorNode);\n else parent.insertBefore(node, anchorNode);\n }\n anchorNode = node;\n }\n}\n"],"mappings":"AAMA,SAASA,EAAW,EAAc,EAA8B,CAC1DC,IAAS,IAAA,IAAaA,EAAK,aAAeC,GAAQA,EAAO,YAAYD,CAAI,CAC/E,CAOA,SAASE,EAAsB,EAA2B,EAAgB,EAAyB,CAEjG,IAAMC,EAAkB,CAAC,EACnBC,EAAqBC,EAAO,QAAU,EAAE,EAC9C,IAAK,IAAIC,EAAQ,EAAGA,EAAQD,EAAO,OAAQ,GAAS,EAAG,CACrD,IAAME,EAAQF,EAAOC,IAAU,EAC3BE,EAAM,EACNC,EAAON,EAAM,OACjB,KAAOK,EAAMC,GAAM,CACjB,IAAMC,EAAUF,EAAMC,GAAS,GACjBJ,EAAOF,EAAMO,IAAW,IAAM,GAChCH,EAAO,EAAMG,EAAS,EAC7B,EAAOA,CACd,CACA,EAASJ,GAASE,EAAM,EAAKL,EAAMK,EAAM,IAAM,GAAM,GACrD,EAAMA,GAAOF,CACf,CACA,IAAIK,EAASR,EAAM,OAAS,EAAKA,EAAMA,EAAM,OAAS,IAAM,GAAM,GAClE,KAAOQ,IAAW,IAChB,GAAON,EAAOM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IAAMK,EAAS,IAAI,WAAWN,EAAWF,CAAI,EAC7ChB,EAAsBsB,EAAWN,EAAMQ,CAAM,EAC7C,IAAMC,EAAU,OAAQ1B,EAAkC,YAAe,WAErE2B,EAAaP,EACjB,IAAK,IAAIf,EAAQc,EAAW,EAAGd,GAASY,EAAM,IAAY,CACxD,IAAMlB,EAAOiB,EAAKX,GACdN,IAAS,IAAA,KACT0B,EAAOpB,EAAQY,KAAU,IACvBS,GAAW3B,EAAK,aAAeC,EACjCA,EAA0B,WAAWD,EAAM4B,CAAU,EAClD3B,EAAO,aAAaD,EAAM4B,CAAU,GAE3C,EAAa5B,EACf,CACF,C"}
1
+ {"version":3,"file":"reconcile.js","names":["removeNode","node","parent","markLongestIncreasing","tails","previous","values","index","value","low","high","middle","cursor","offset","reconcileNodes","prevLength","prev","nextLength","next","head","prevTail","nextTail","before","end","target","survivors","position","stable","movable","anchorNode"],"sources":["../../../src/internal/reconcile.ts"],"sourcesContent":["/** A parent that can move a child in place (Element.prototype.moveBefore, where implemented). */\ninterface MovableParent extends Node {\n moveBefore(node: Node, child: Node | null): void;\n}\n\n/** Removes `node` only when it is still a child of `parent`, so detached nodes are ignored. */\nfunction removeNode(parent: Node, node: Node | undefined): void {\n if (node !== undefined && node.parentNode === parent) parent.removeChild(node);\n}\n\n/**\n * Marks the members of one longest strictly increasing subsequence of `values` in `marks`, where\n * `values[k]` is the target position of the k-th surviving node and `marks[v - offset]` is set for\n * target position `v`. Patience sorting: O(n log n).\n */\nfunction markLongestIncreasing(values: readonly number[], offset: number, marks: Uint8Array): void {\n // tails[k]: index into `values` of the smallest tail of an increasing run of length k + 1.\n const tails: number[] = [];\n const previous: number[] = values.map(() => -1);\n for (let index = 0; index < values.length; index += 1) {\n const value = values[index] as number;\n let low = 0;\n let high = tails.length;\n while (low < high) {\n const middle = (low + high) >> 1;\n const probe = values[tails[middle] as number] as number;\n if (probe < value) low = middle + 1;\n else high = middle;\n }\n // `tails[-1]` is undefined, which reads as no predecessor.\n previous[index] = tails[low - 1] ?? -1;\n tails[low] = index;\n }\n let cursor = tails.at(-1) ?? -1;\n while (cursor !== -1) {\n marks[(values[cursor] as number) - offset] = 1;\n cursor = previous[cursor] as number;\n }\n}\n\n/**\n * Updates one region of `parent`'s children from the nodes `prev` to the nodes `next`, keeping every\n * node that stays and moving as few as possible: the list reconciliation `insert` performs for arrays\n * (and so for `For`). Use it in a custom list renderer.\n *\n * Preconditions: `prev` are the nodes this region owns, in DOM order and all children of `parent`;\n * `next` holds no duplicates; `end` is the node after the region (null for the end of `parent`).\n *\n * Strategy, in three steps:\n * 1. Trim the common prefix and suffix: appends, prepends, and removals at either end touch\n * only the nodes that changed (no move at all).\n * 2. Remove the nodes that left the value. A node that is still present is never removed.\n * 3. Place the rest from the end of `next` backwards. Nodes on a longest increasing subsequence of\n * surviving positions stay where they are; every other node is moved (or inserted) directly\n * before the node that follows it in `next`. Moves use `moveBefore` when the parent has it,\n * which keeps focus and iframe state, and `insertBefore` otherwise. Each node moves at most once,\n * and the number of moves is minimal for the surviving order.\n *\n * @param parent The parent of the region.\n * @param prev The nodes the region holds now, in DOM order, all children of `parent`.\n * @param next The nodes the region must hold, in order, without duplicates. A node of `prev` that is\n * not in `next` is removed; a node of `next` that is not in `prev` is inserted.\n * @param end The node right after the region; `null` when the region runs to the end of `parent`.\n * @example\n * import { reconcileNodes } from \"@shadow-js/web/extend\";\n *\n * const item = (text: string): HTMLLIElement =>\n * Object.assign(document.createElement(\"li\"), { textContent: text });\n * const list = document.createElement(\"ul\");\n * const a = item(\"a\");\n * const b = item(\"b\");\n * const c = item(\"c\");\n * list.append(a, b, c);\n * reconcileNodes(list, [a, b, c], [c, a], null); // removes b, moves c before a\n * @since 1.0.0\n */\nexport function reconcileNodes(\n parent: Node,\n prev: readonly Node[],\n next: readonly Node[],\n end: Node | null,\n): void {\n const prevLength = prev.length;\n const nextLength = next.length;\n\n let head = 0;\n while (head < prevLength && head < nextLength && prev[head] === next[head]) head += 1;\n let prevTail = prevLength;\n let nextTail = nextLength;\n while (prevTail > head && nextTail > head && prev[prevTail - 1] === next[nextTail - 1]) {\n prevTail -= 1;\n nextTail -= 1;\n }\n if (prevTail === head && nextTail === head) return;\n\n // Everything in the common suffix is already in place, so the middle goes before its first node.\n const before = nextTail < nextLength ? (next[nextTail] ?? null) : end;\n\n if (nextTail === head) {\n for (let index = head; index < prevTail; index += 1) removeNode(parent, prev[index]);\n return;\n }\n\n const target = new Map<Node, number>();\n for (let index = head; index < nextTail; index += 1) {\n const node = next[index];\n if (node !== undefined) target.set(node, index);\n }\n\n const survivors: number[] = [];\n for (let index = head; index < prevTail; index += 1) {\n const node = prev[index] as Node;\n const position = target.get(node);\n if (position === undefined) removeNode(parent, node);\n else survivors.push(position);\n }\n\n // Nothing survived: the new nodes go in document order. Inserting them back to front (the move loop below)\n // ends with the same tree but not the same steps, and a `<select>` picks its shown option while its options\n // arrive, so a replaced option list would show the wrong value.\n if (survivors.length === 0) {\n for (const node of next.slice(head, nextTail)) parent.insertBefore(node, before);\n return;\n }\n\n const stable = new Uint8Array(nextTail - head);\n markLongestIncreasing(survivors, head, stable);\n const movable = typeof (parent as Partial<MovableParent>).moveBefore === \"function\";\n\n let anchorNode = before;\n for (let index = nextTail - 1; index >= head; index -= 1) {\n const node = next[index] as Node;\n if (stable[index - head] !== 1) {\n if (movable && node.parentNode === parent)\n (parent as MovableParent).moveBefore(node, anchorNode);\n else parent.insertBefore(node, anchorNode);\n }\n anchorNode = node;\n }\n}\n"],"mappings":"AAMA,SAASA,EAAW,EAAc,EAA8B,CAC1DC,IAAS,IAAA,IAAaA,EAAK,aAAeC,GAAQA,EAAO,YAAYD,CAAI,CAC/E,CAOA,SAASE,EAAsB,EAA2B,EAAgB,EAAyB,CAEjG,IAAMC,EAAkB,CAAC,EACnBC,EAAqBC,EAAO,QAAU,EAAE,EAC9C,IAAK,IAAIC,EAAQ,EAAGA,EAAQD,EAAO,OAAQ,GAAS,EAAG,CACrD,IAAME,EAAQF,EA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W1B,EAAWE,EAAQD,CAAI,EAC9CwB,EAAU,KAAKC,CAAQ,CAC9B,CAKA,GAAID,EAAU,SAAW,EAAG,CAC1B,IAAK,IAAMxB,KAAQiB,EAAK,MAAMC,EAAME,CAAQ,EAAGnB,EAAO,aAAaD,EAAMqB,CAAM,EAC/E,MACF,CAEA,IAAMK,EAAS,IAAI,WAAWN,EAAWF,CAAI,EAC7ChB,EAAsBsB,EAAWN,EAAMQ,CAAM,EAC7C,IAAMC,EAAU,OAAQ1B,EAAkC,YAAe,WAErE2B,EAAaP,EACjB,IAAK,IAAIf,EAAQc,EAAW,EAAGd,GAASY,EAAM,IAAY,CACxD,IAAMlB,EAAOiB,EAAKX,GACdoB,EAAOpB,EAAQY,KAAU,IACvBS,GAAW3B,EAAK,aAAeC,EACjCA,EAA0B,WAAWD,EAAM4B,CAAU,EAClD3B,EAAO,aAAaD,EAAM4B,CAAU,GAE3C,EAAa5B,CACf,CACF,C"}
@@ -1,2 +1,2 @@
1
- import{useHead as e}from"./head/use-head.js";import{isServer as t}from"@shadow-js/core";function n(e){let t=new URL(e,`https://base.invalid`);if(t.protocol!==`https:`&&t.protocol!==`http:`)throw TypeError(`SHADOW_RESOURCE_HINT_URL`)}function r(e,t){for(let[n,r]of Object.entries(t))if(e.getAttribute(n)!==r)return!1;return!0}function i(e,n,i=()=>void 0){if(t){i();return}if(typeof document>`u`)return;for(let t of document.head.querySelectorAll(e))if(r(t,n))return;let a=document.createElement(e);for(let[e,t]of Object.entries(n))a.setAttribute(e,t);document.head.append(a)}function a(t){return()=>e({tag:`link`,props:t})}function o(e,t){n(e);let r={rel:`preconnect`,href:e,...t?.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}};i(`link`,r,a(r))}function s(e){n(e);let t={rel:`dns-prefetch`,href:e};i(`link`,t,a(t))}function c(e,t){n(e);let r={rel:`preload`,href:e,as:t.as,...t.type===void 0?{}:{type:t.type},...t.media===void 0?{}:{media:t.media},...t.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}};i(`link`,r,a(r))}function l(e,t){n(e);let r={rel:`modulepreload`,href:e,...t?.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}};i(`link`,r,a(r))}function u(e,t){if(n(e),t.as===`style`){let n={rel:`stylesheet`,href:e,...t.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}};i(`link`,n,a(n))}else i(`script`,{src:e,async:``,...t.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}},a({rel:`preload`,href:e,as:`script`}))}function d(e,t){n(e),i(`script`,{src:e,type:`module`,...t?.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}},a({rel:`modulepreload`,href:e,...t?.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}}))}export{o as preconnect,s as prefetchDNS,u as preinit,d as preinitModule,c as preload,l as preloadModule};
1
+ import{useHead as e}from"./head/use-head.js";import{isServer as t}from"@shadow-js/core";function n(e){let t=new URL(e,`https://base.invalid`);if(t.protocol!==`https:`&&t.protocol!==`http:`)throw TypeError(`SHADOW_RESOURCE_HINT_URL`)}function r(e,t){for(let[n,r]of Object.entries(t))if(e.getAttribute(n)!==r)return!1;return!0}function i(e,n,i=()=>void 0){if(t){i();return}if(typeof document>`u`)return;let a=e===`script`?e=>e.getAttribute(`src`)===n.src&&(e.getAttribute(`type`)??``)===(n.type??``):e=>r(e,n);for(let t of(e===`script`?document:document.head).querySelectorAll(e))if(a(t))return;let o=document.createElement(e);for(let[e,t]of Object.entries(n))o.setAttribute(e,t);document.head.append(o)}function a(t){return()=>e({tag:`link`,props:t})}function o(e,t){n(e);let r={rel:`preconnect`,href:e,...t?.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}};i(`link`,r,a(r))}function s(e){n(e);let t={rel:`dns-prefetch`,href:e};i(`link`,t,a(t))}function c(e,t){n(e);let r={rel:`preload`,href:e,as:t.as,...t.type===void 0?{}:{type:t.type},...t.media===void 0?{}:{media:t.media},...t.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}};i(`link`,r,a(r))}function l(e,t){n(e);let r={rel:`modulepreload`,href:e,...t?.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}};i(`link`,r,a(r))}function u(e,t){if(n(e),t.as===`style`){let n={rel:`stylesheet`,href:e,...t.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}};i(`link`,n,a(n))}else i(`script`,{src:e,async:``,...t.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}},a({rel:`preload`,href:e,as:`script`}))}function d(e,t){n(e),i(`script`,{src:e,type:`module`,...t?.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}},a({rel:`modulepreload`,href:e,...t?.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}}))}export{o as preconnect,s as prefetchDNS,u as preinit,d as preinitModule,c as preload,l as preloadModule};
2
2
  //# sourceMappingURL=resource-hints.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resource-hints.js","names":["checkUrl","url","href","carries","name","value","attributes","element","hint","isServer","serverTag","existing","tag","serverLink","useHead","preconnect","options","prefetchDNS","preload","preloadModule","preinit","preinitModule"],"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":"A,wFAoEA,SAASA,EAAS,EAAoB,CACpC,IAAMC,EAAM,IAAI,IAAIC,EAAM,sBAAsB,EAChD,GAAID,EAAI,WAAa,UAAYA,EAAI,WAAa,QAChD,MAAU,UAGJ,0BACN,CAEJ,CAGA,SAASE,EAAQ,EAAkB,EAAiC,CAClE,IAAK,GAAM,CAACC,EAAMC,KAAU,OAAO,QAAQC,CAAU,EACnD,GAAIC,EAAQ,aAAaH,CAAI,IAAMC,EAAO,MAAO,GAEnD,MAAO,EACT,CAMA,SAASG,EACP,EACA,EACA,MAA8B,IAAA,GACxB,CACN,GAAIC,EAAU,CACZC,EAAU,EACV,MACF,CACA,GAAI,OAAO,SAAa,IAAa,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,GAAIU,GAAS,cAAgB,IAAA,GAAY,CAAC,EAAI,CAAE,YAAaA,EAAQ,WAAY,CACnF,EACAR,EAAK,OAAQF,EAAYO,EAAWP,CAAU,CAAC,CACjD,CAkBA,SAAgBc,EAAQ,EAAc,EAA+B,CAEnE,GADApB,EAASE,CAAI,EACTc,EAAQ,KAAO,QAAS,CAC1B,IAAMV,EAAyB,CAC7B,IAAK,aACL,OACA,GAAIU,EAAQ,cAAgB,IAAA,GAAY,CAAC,EAAI,CAAE,YAAaA,EAAQ,WAAY,CAClF,EACAR,EAAK,OAAQF,EAAYO,EAAWP,CAAU,CAAC,CAEjD,MAMAE,EAAK,SAAU,CAJb,IAAKN,EACL,MAAO,GACP,GAAIc,EAAQ,cAAgB,IAAA,GAAY,CAAC,EAAI,CAAE,YAAaA,EAAQ,WAAY,CAE1D,EAAGH,EAAW,CAAE,IAAK,UAAW,OAAM,GAAI,QAAS,CAAC,CAAC,CAC/E,CAkBA,SAAgBQ,EAAc,EAAc,EAAoC,CAC9ErB,EAASE,CAAI,EAMbM,EACE,SACA,CANA,IAAKN,EACL,KAAM,SACN,GAAIc,GAAS,cAAgB,IAAA,GAAY,CAAC,EAAI,CAAE,YAAaA,EAAQ,WAAY,CAIxE,EACTH,EAAW,CACT,IAAK,gBACL,OACA,GAAIG,GAAS,cAAgB,IAAA,GAAY,CAAC,EAAI,CAAE,YAAaA,EAAQ,WAAY,CACnF,CAAC,CACH,CACF,C"}
1
+ {"version":3,"file":"resource-hints.js","names":["checkUrl","url","href","carries","name","value","attributes","element","hint","isServer","serverTag","same","tag","existing","\"src\"","\"type\"","serverLink","useHead","preconnect","options","prefetchDNS","preload","preloadModule","preinit","preinitModule"],"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":"A,wFAoEA,SAASA,EAAS,EAAoB,CACpC,IAAMC,EAAM,IAAI,IAAIC,EAAM,sBAAsB,EAChD,GAAID,EAAI,WAAa,UAAYA,EAAI,WAAa,QAChD,MAAU,UAGJ,0BACN,CAEJ,CAGA,SAASE,EAAQ,EAAkB,EAAiC,CAClE,IAAK,GAAM,CAACC,EAAMC,KAAU,OAAO,QAAQC,CAAU,EACnD,GAAIC,EAAQ,aAAaH,CAAI,IAAMC,EAAO,MAAO,GAEnD,MAAO,EACT,CAOA,SAASG,EACP,EACA,EACA,MAA8B,IAAA,GACxB,CACN,GAAIC,EAAU,CACZC,EAAU,EACV,MACF,CACA,GAAI,OAAO,SAAa,IAAa,OAGrC,IAAMC,EACJC,IAAQ,SACH,GACCC,EAAS,aAAa,KAAK,IAAMP,EAAWQ,MAC3CD,EAAS,aAAa,MAAM,GAAK,OAASP,EAAWS,MAAW,IAClE,GAA+BZ,EAAQU,EAAUP,CAAU,EAClE,IAAK,IAAMO,KAAaD,IAAQ,SAAW,SAAW,SAAS,KAAA,CAAM,iBAAiBA,CAAG,EACvF,GAAID,EAAKE,CAAQ,EAAG,OAEtB,IAAMN,EAAU,SAAS,cAAcK,CAAG,EAC1C,IAAK,GAAM,CAACR,EAAMC,KAAU,OAAO,QAAQC,CAAU,EAAGC,EAAQ,aAAaH,EAAMC,CAAK,EACxF,SAAS,KAAK,OAAOE,CAAO,CAC9B,CAGA,SAASS,EAAW,EAAsE,CACxF,UAAaC,EAAQ,CAAE,IAAK,OAAQ,MAAOX,CAAW,CAAC,CACzD,CAoBA,SAAgBY,EAAW,EAAc,EAAoC,CAC3ElB,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AMAE,EAAK,SAAU,CAJb,IAAKN,EACL,MAAO,GACP,GAAIiB,EAAQ,cAAgB,IAAA,GAAY,CAAC,EAAI,CAAE,YAAaA,EAAQ,WAAY,CAE1D,EAAGH,EAAW,CAAE,IAAK,UAAW,OAAM,GAAI,QAAS,CAAC,CAAC,CAC/E,CAkBA,SAAgBQ,EAAc,EAAc,EAAoC,CAC9ExB,EAASE,CAAI,EAMbM,EACE,SACA,CANA,IAAKN,EACL,KAAM,SACN,GAAIiB,GAAS,cAAgB,IAAA,GAAY,CAAC,EAAI,CAAE,YAAaA,EAAQ,WAAY,CAIxE,EACTH,EAAW,CACT,IAAK,gBACL,OACA,GAAIG,GAAS,cAAgB,IAAA,GAAY,CAAC,EAAI,CAAE,YAAaA,EAAQ,WAAY,CACnF,CAAC,CACH,CACF,C"}
@@ -1,2 +1,2 @@
1
- function e(e){let t=/* @__PURE__ */ new Set;for(let n of e)n!=null&&t.add(String(n));return t}function t(e){return e==null?``:String(e)}function n(n,r){if(n.multiple&&Array.isArray(r)){let t=e(r);for(let e of Array.from(n.options))e.selected=t.has(e.value)}else n.value=t(r)}function r(n,r){if(n.multiple&&Array.isArray(r)){let t=e(r);return Array.from(n.options).every(e=>e.selected===t.has(e.value))}return n.value===t(r)}export{r as selectShows,n as setSelectValue};
1
+ function e(e){return new Set(e.filter(e=>e!=null).map(String))}function t(e){return e==null?``:String(e)}function n(n,r){if(n.multiple&&Array.isArray(r)){let t=e(r);for(let e of Array.from(n.options))e.selected=t.has(e.value)}else n.value=t(r)}export{t as plainText,n as setSelectValue};
2
2
  //# sourceMappingURL=select-value.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"select-value.js","names":["listed","values","item","value","single","setSelectValue","select","wanted","option","selectShows"],"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,SAASA,EAAO,EAAwC,CACtD,IAAMC,kBAAS,IAAI,IACnB,IAAK,IAAMC,KAAQC,EACbD,GAAS,MAA4BD,EAAO,IAAI,OAAOC,CAAI,CAAC,EAElE,OAAOD,CACT,CAGA,SAASG,EAAO,EAAwB,CACtC,OAAOD,GAAU,KAA8B,GAAK,OAAOA,CAAK,CAClE,CAsBA,SAAgBE,EAAe,EAA2B,EAAsB,CAC9E,GAAIC,EAAO,UAAY,MAAM,QAAQH,CAAK,EAAG,CAC3C,IAAMI,EAASP,EAAOG,CAAK,EAC3B,IAAK,IAAMK,KAAU,MAAM,KAAKF,EAAO,OAAO,EAAG,EAAO,SAAWC,EAAO,IAAIC,EAAO,KAAK,CAE5F,KACA,GAAO,MAAQJ,EAAOD,CAAK,CAC7B,CAGA,SAAgBM,EAAY,EAA2B,EAAyB,CAC9E,GAAIH,EAAO,UAAY,MAAM,QAAQH,CAAK,EAAG,CAC3C,IAAMI,EAASP,EAAOG,CAAK,EAC3B,OAAO,MAAM,KAAKG,EAAO,OAAO,CAAC,CAAC,MAC/B,GAAWE,EAAO,WAAaD,EAAO,IAAIC,EAAO,KAAK,CACzD,CACF,CACA,OAAOF,EAAO,QAAUF,EAAOD,CAAK,CACtC,C"}
1
+ {"version":3,"file":"select-value.js","names":["listed","value","item","plainText","setSelectValue","select","wanted","option"],"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,SAASA,EAAO,EAAwC,CACtD,OAAO,IAAI,IAAIC,EAAM,OAAQ,GAASC,GAAS,IAA0B,CAAC,CAAC,IAAI,MAAM,CAAC,CACxF,CAGA,SAAgBC,EAAU,EAAwB,CAChD,OAAOF,GAAU,KAA8B,GAAK,OAAOA,CAAK,CAClE,CAsBA,SAAgBG,EAAe,EAA2B,EAAsB,CAC9E,GAAIC,EAAO,UAAY,MAAM,QAAQJ,CAAK,EAAG,CAC3C,IAAMK,EAASN,EAAOC,CAAK,EAC3B,IAAK,IAAMM,KAAU,MAAM,KAAKF,EAAO,OAAO,EAAG,EAAO,SAAWC,EAAO,IAAIC,EAAO,KAAK,CAE5F,KACA,GAAO,MAAQJ,EAAUF,CAAK,CAChC,C"}
@@ -1,2 +1,2 @@
1
- import{invalid as e}from"./errors.js";import{escapeHtml as t,resolveValue as n}from"./escape.js";const r=/^[A-Za-z_:][A-Za-z0-9_:.-]*$/,i=/* @__PURE__ */ new Set([`href`,`src`,`action`,`formaction`,`xlink:href`,`srcdoc`,`poster`,`data`]),a=/* @__PURE__ */ new Set([`values`,`from`,`to`,`by`]),o=/* @__PURE__ */ new Set([`draggable`,`spellcheck`,`contenteditable`]),s=/* @__PURE__ */ new Set([`async`,`autofocus`,`autoplay`,`checked`,`controls`,`default`,`defer`,`disabled`,`formnovalidate`,`hidden`,`inert`,`ismap`,`loop`,`multiple`,`muted`,`nomodule`,`novalidate`,`open`,`playsinline`,`readonly`,`required`,`reversed`,`selected`]),c=[`javascript:`,`data:text/html`,`vbscript:`];function l(t){if(!r.test(t))throw e(`INVALID_ATTRIBUTE_NAME`,`"${t}" is not a valid attribute name.`)}function u(e){return e.length>2&&e.startsWith(`on`)}function d(e){return e.startsWith(`aria-`)||e.startsWith(`data-`)||o.has(e)}function f(e){let t=``;for(let n of e){let e=n.charCodeAt(0);e>31&&(e<127||e>159)&&(t+=n)}return t}function p(e){let t=f(e).trim().toLowerCase();return c.some(e=>t.startsWith(e))}function m(e,t){return i.has(e)?p(t):a.has(e)&&t.split(`;`).some(p)}function h(e,t){return t==null?null:t===!1?d(e)?`false`:null:t===!0?d(e)?`true`:``:String(t)}function g(t){if(typeof t==`symbol`)throw e(`UNRECOGNIZED_INSERT_VALUE`,`A symbol cannot be an attribute value.`)}function _(e,r,i=!1){l(e);let a=e.toLowerCase();if(u(a))return``;let o=n(r);if(g(o),i)return o?` ${e}`:``;let s=h(a,o);return s===null||m(a,s)?``:` ${e}="${t(s)}"`}export{s as BOOLEAN_ATTRIBUTES,l as assertAttributeName,h as attributeText,u as isEventName,p as isUnsafeUrl,_ as ssrAttribute};
1
+ import{invalid as e}from"./errors.js";import{escapeHtml as t,resolveValue as n}from"./escape.js";const r=/^[A-Za-z_:][A-Za-z0-9_:.-]*$/,i=/* @__PURE__ */ new Set([`href`,`src`,`action`,`formaction`,`xlink:href`,`poster`,`data`]),a=/* @__PURE__ */ new Set([`values`,`from`,`to`,`by`]),o=/* @__PURE__ */ new Set([`draggable`,`spellcheck`,`contenteditable`]),s=[`javascript:`,`data:text/html`,`vbscript:`];function c(t){if(!r.test(t))throw e(`INVALID_ATTRIBUTE_NAME`,`"${t}" is not a valid attribute name.`)}function l(e){return e.length>2&&e.startsWith(`on`)}function u(e){return e.startsWith(`aria-`)||e.startsWith(`data-`)||o.has(e)}function d(e){let t=``;for(let n of e){let e=n.charCodeAt(0);e>31&&(e<127||e>159)&&(t+=n)}return t}function f(e){let t=d(e).trim().toLowerCase();return s.some(e=>t.startsWith(e))}function p(e,t){return i.has(e)?f(t):a.has(e)&&t.split(`;`).some(f)}function m(e,t){return t==null?null:t===!1?u(e)?`false`:null:t===!0?u(e)?`true`:``:String(t)}function h(t){if(typeof t==`symbol`)throw e(`UNRECOGNIZED_INSERT_VALUE`,`A symbol cannot be an attribute value.`)}function g(e,r,i=!1){c(e);let a=e.toLowerCase();if(l(a))return``;let o=n(r);if(h(o),i)return o?` ${e}`:``;let s=m(a,o);return s===null||p(a,s)?``:` ${e}="${t(s)}"`}export{c as assertAttributeName,m as attributeText,l as isEventName,f as isUnsafeUrl,g as ssrAttribute};
2
2
  //# sourceMappingURL=attributes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"attributes.js","names":["ATTRIBUTE_NAME","URL_ATTRIBUTES","ANIMATION_VALUE_ATTRIBUTES","ENUMERATED_ATTRIBUTES","BOOLEAN_ATTRIBUTES","UNSAFE_URL_PREFIXES","assertAttributeName","name","invalid","isEventName","lowerName","isStringValued","stripControls","kept","char","text","code","isUnsafeUrl","normalized","value","prefix","isUnsafeAttributeValue","attributeText","assertNotSymbol","ssrAttribute","resolved","resolveValue","isBoolean","escapeHtml"],"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":"A,iGAIA,MAAMA,EAAiB,+BAGjBC,kBAAsC,IAAI,IAAI,CAClD,OACA,MACA,SACA,aACA,aACA,SACA,SACA,MACF,CAAC,EAMKC,kBAAkD,IAAI,IAAI,CAAC,SAAU,OAAQ,KAAM,IAAI,CAAC,EAGxFC,kBAA6C,IAAI,IAAI,CACzD,YACA,aACA,iBACF,CAAC,EAOYC,kBAA0C,IAAI,IAAI,CAC7D,QACA,YACA,WACA,UACA,WACA,UACA,QACA,WACA,iBACA,SACA,QACA,QACA,OACA,WACA,QACA,WACA,aACA,OACA,cACA,WACA,WACA,WACA,UACF,CAAC,EAGKC,EAAyC,CAAC,cAAe,iBAAkB,WAAW,EAG5F,SAAgBC,EAAoB,EAAoB,CACtD,GAAI,CAACN,EAAe,KAAKO,CAAI,EAC3B,MAAMC,EAAQ,yBAA0B,IAAID,EAAK,iCAAiC,CAEtF,CAGA,SAAgBE,EAAY,EAA4B,CACtD,OAAOC,EAAU,OAAS,GAAKA,EAAU,WAAW,IAAI,CAC1D,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V,IAAS,MACTM,EAAuBX,EAAWK,CAAI,EAAU,GAC7C,IAAIR,EAAK,IAAIqB,EAAWb,CAAI,EAAE,EACvC,C"}
1
+ {"version":3,"file":"attributes.js","names":["ATTRIBUTE_NAME","URL_ATTRIBUTES","ANIMATION_VALUE_ATTRIBUTES","ENUMERATED_ATTRIBUTES","UNSAFE_URL_PREFIXES","assertAttributeName","name","invalid","isEventName","lowerName","isStringValued","stripControls","kept","char","text","code","isUnsafeUrl","normalized","value","prefix","isUnsafeAttributeValue","attributeText","assertNotSymbol","ssrAttribute","resolved","resolveValue","isBoolean","escapeHtml"],"sources":["../../../src/server/attributes.ts"],"sourcesContent":["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/** 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":"A,iGAKA,MAAMA,EAAiB,+BAGjBC,kBAAsC,IAAI,IAAI,CAClD,OACA,MACA,SACA,aACA,aACA,SACA,MACF,CAAC,EAMKC,kBAAkD,IAAI,IAAI,CAAC,SAAU,OAAQ,KAAM,IAAI,CAAC,EAGxFC,kBAA6C,IAAI,IAAI,CACzD,YACA,aACA,iBACF,CAAC,EAGKC,EAAyC,CAAC,cAAe,iBAAkB,WAAW,EAG5F,SAAgBC,EAAoB,EAAoB,CACtD,GAAI,CAACL,EAAe,KAAKM,CAAI,EAC3B,MAAMC,EAAQ,yBAA0B,IAAID,EAAK,iCAAiC,CAEtF,CAGA,SAAgBE,EAAY,EAA4B,CACtD,OAAOC,EAAU,OAAS,GAAKA,EAAU,WAAW,IAAI,CAC1D,CAGA,SAASC,EAAe,EAA4B,CAClD,OACED,EAAU,WAAW,OAAO,GAC5BA,EAAU,WAAW,OAAO,GAC5BN,EAAsB,IAAIM,CAAS,CAEvC,CAGA,SAASE,EAAc,EAAsB,CAC3C,IAAIC,EAAO,GACX,IAAK,IAAMC,KAAQC,EAAM,CACvB,IAAMC,EAAOF,EAAK,WAAW,CAAC,EAC1BE,EAAO,KAASA,EAAO,KAAQA,EAAO,OAAO,GAAQF,EAC3D,CACA,OAAOD,CACT,CAGA,SAAgBI,EAAY,EAAwB,CAClD,IAAMC,EAAaN,EAAcO,CAAK,CAAC,CAAC,KAAK,CAAC,CAAC,YAAY,EAC3D,OAAOd,EAAoB,KAAM,GAAWa,EAAW,WAAWE,CAAM,CAAC,CAC3E,CAGA,SAASC,EAAuB,EAAmB,EAAwB,CAEzE,OADInB,EAAe,IAAIQ,CAAS,EAAUO,EAAYE,CAAK,EACpDhB,EAA2B,IAAIO,CAAS,GAAKS,EAAM,MAAM,GAAG,CAAC,CAAC,KAAKF,CAAW,CACvF,CAGA,SAAgBK,EAAc,EAAmB,EAA+B,CAI9E,OAHIH,GAAU,KAAoC,KAC9CA,IAAU,GAAcR,EAAeD,CAAS,EAAI,QAAU,KAC9DS,IAAU,GAAaR,EAAeD,CAAS,EAAI,OAAS,GACzD,OAAOS,CAAK,CACrB,CAGA,SAASI,EAAgB,EAAsB,CAC7C,GAAI,OAAOJ,GAAU,SACnB,MAAMX,EAAQ,4BAA6B,wCAAwC,CAEvF,CAkCA,SAAgBgB,EAAa,EAAc,EAAgB,EAAY,GAAe,CACpFlB,EAAoBC,CAAI,EACxB,IAAMG,EAAYH,EAAK,YAAY,EACnC,GAAIE,EAAYC,CAAS,EAAG,MAAO,GACnC,IAAMe,EAAWC,EAAaP,CAAK,EAEnC,GADAI,EAAgBE,CAAQ,EACpBE,EAAW,OAAOF,EAAW,IAAIlB,IAAS,GAC9C,IAAMQ,EAAOO,EAAcZ,EAAWe,CAAQ,EAI9C,OAHIV,IAAS,MAETM,EAAuBX,EAAWK,CAAI,EAAU,GAC7C,IAAIR,EAAK,IAAIqB,EAAWb,CAAI,EAAE,EACvC,C"}
@@ -1,2 +1,2 @@
1
- import{nextKey as e}from"../internal/hydration-scope.js";import{IGNORED_KEYS as t,attributeName as n}from"../internal/react-names.js";import{invalid as r}from"./errors.js";import{SsrNode as i,isSsrNode as a}from"./node.js";import{escape as o,escapeHtml as s,resolveValue as c}from"./escape.js";import{BOOLEAN_ATTRIBUTES as l,isEventName as u,ssrAttribute as d}from"./attributes.js";import{classText as f,ssrStyle as p,styleText as m}from"./class-style.js";import{markSelectedOptions as h,textareaContent as g}from"./form-controls.js";const _=/^[A-Za-z][A-Za-z0-9-]*$/,v=/* @__PURE__ */ new Set([`area`,`base`,`br`,`col`,`command`,`embed`,`hr`,`img`,`input`,`keygen`,`link`,`meta`,`param`,`source`,`track`,`wbr`]),y=/* @__PURE__ */ new Set([`__proto__`,`constructor`,`prototype`,`children`,`ref`]);function b(e){if(typeof e==`object`&&e)return Reflect.get(e,`__html`)}function x(e,...t){if(!Array.isArray(e)||e.length!==t.length+1)throw TypeError(`ssr(): parts must have one more entry than there are holes.`);let n=e[0]??``;for(let r=0;r<t.length;r+=1){let i=t[r];if(typeof i==`string`)n+=i;else if(a(i))n+=i.t;else throw TypeError(`ssr(): a hole must be an escaped string or an SsrNode.`);n+=e[r+1]??``}return new i(n)}function S(e){if(typeof e!=`string`)throw TypeError(`ssrRaw(): the markup must be a string.`);return new i(e)}function C(){let t=e();return t===void 0?``:` data-hk="${s(t)}"`}function w(e,a,x=void 0,S=!1,w=!1){if(typeof e!=`string`||!_.test(e))throw r(`INVALID_TAG_NAME`,`"${String(e)}" is not a valid tag name.`);let O=e.toLowerCase(),k=O===`select`,A=O===`textarea`,j={},M=!1,N=!1,P=S?C():``,F=[],I=``,L;if(typeof a==`object`&&a)for(let e of Object.keys(a)){if(y.has(e)||t.has(e)||e===`ref`||e.startsWith(`on:`)||e.startsWith(`use:`)||e.startsWith(`prop:`)||u(e)||S&&e===`data-hk`)continue;let r=c(Reflect.get(a,e));if(e===`class`||e===`className`){let e=f(r);e!==``&&F.push(e)}else if(e===`classList`)E(r,F);else if(e===`style`)I=m(r);else if(e===`innerHTML`)L=D(r);else if(e===`dangerouslySetInnerHTML`)L=D(c(b(r)));else if((k||A)&&e===`value`)j.value=r,M=!0;else if((k||A)&&e===`defaultValue`)j.fallback=r,N=!0;else if(e.startsWith(`attr:`))P+=d(e.slice(5),r);else if(e.startsWith(`bool:`))P+=d(e.slice(5),r,!0);else if(e===`defaultValue`||e===`defaultChecked`){let t=e===`defaultValue`?`value`:`checked`;Object.hasOwn(a,t)||(P+=d(t,r,t===`checked`))}else{let t=n(e,w);P+=d(t,r,l.has(t))}}if(F.length>0&&(P+=` class="${s(F.join(` `))}"`),I!==``&&(P+=p(I)),v.has(O))return new i(`<${e}${P}>`);let R=L===void 0?o(x===void 0?T(a):x):L;if(L===void 0&&(M||N)){let e=M?j.value:j.fallback;R=A?g(e):h(e,R)}return new i(`<${e}${P}>${R}</${e}>`)}function T(e){if(typeof e==`object`&&e)return Reflect.get(e,`children`)}function E(e,t){if(typeof e==`object`&&e&&!Array.isArray(e))for(let n of Object.keys(e))n!==``&&c(Reflect.get(e,n))&&t.push(n)}function D(e){if(e==null)return``;if(a(e))return e.t;if(typeof e==`symbol`)throw r(`UNRECOGNIZED_INSERT_VALUE`,`A symbol cannot be innerHTML.`);return String(e)}export{x as ssr,w as ssrElement,C as ssrHydrationKey,S as ssrRaw};
1
+ import{nextKey as e}from"../internal/hydration-scope.js";import{IGNORED_KEYS as t,attributeName as n,isFlagAttribute as r}from"../internal/react-names.js";import{invalid as i}from"./errors.js";import{SsrNode as a,isSsrNode as o}from"./node.js";import{escape as s,escapeHtml as c,resolveValue as l}from"./escape.js";import{isEventName as u,ssrAttribute as d}from"./attributes.js";import{classText as f,ssrStyle as p,styleText as m}from"./class-style.js";import{keepLeadingNewline as h,markSelectedOptions as g,textareaContent as _}from"./form-controls.js";import{rawElementContent as v}from"./raw-text.js";const y=/^[A-Za-z][A-Za-z0-9-]*$/,b=/* @__PURE__ */ new Set([`area`,`base`,`br`,`col`,`command`,`embed`,`hr`,`img`,`input`,`keygen`,`link`,`meta`,`param`,`source`,`track`,`wbr`]),x=/* @__PURE__ */ new Set([`__proto__`,`constructor`,`prototype`,`children`,`ref`]);function S(e){if(typeof e==`object`&&e)return Reflect.get(e,`__html`)}function C(e,...t){if(!Array.isArray(e)||e.length!==t.length+1)throw TypeError(`ssr(): parts must have one more entry than there are holes.`);let n=e[0]??``;for(let r=0;r<t.length;r+=1){let i=t[r];if(typeof i==`string`)n+=i;else if(o(i))n+=i.t;else throw TypeError(`ssr(): a hole must be an escaped string or an SsrNode.`);n+=e[r+1]??``}return new a(n)}function w(e){if(typeof e!=`string`)throw TypeError(`ssrRaw(): the markup must be a string.`);return new a(e)}function T(){let t=e();return t===void 0?``:` data-hk="${c(t)}"`}function E(e,o,C=void 0,w=!1,E=!1){if(typeof e!=`string`||!y.test(e))throw i(`INVALID_TAG_NAME`,`"${String(e)}" is not a valid tag name.`);let A=e.toLowerCase(),j=A===`select`,M=A===`textarea`,N={},P=!1,F=!1,I=w?T():``,L=[],R=``,z;if(typeof o==`object`&&o)for(let e of Object.keys(o)){if(x.has(e)||t.test(e)||e===`ref`||e.startsWith(`on:`)||e.startsWith(`use:`)||e.startsWith(`prop:`)||u(e)||w&&e===`data-hk`)continue;let i=l(Reflect.get(o,e));if(e===`class`||e===`className`){let e=f(i);e!==``&&L.push(e)}else if(e===`classList`)O(i,L);else if(e===`style`)R=m(i);else if(e===`innerHTML`)z=k(i);else if(e===`dangerouslySetInnerHTML`)z=k(l(S(i)));else if((j||M)&&e===`value`)N.value=i,P=!0;else if((j||M)&&e===`defaultValue`)N.fallback=i,F=!0;else if(e.startsWith(`attr:`))I+=d(e.slice(5),i);else if(e.startsWith(`bool:`))I+=d(e.slice(5),i,!0);else if(e===`defaultValue`||e===`defaultChecked`){let t=e===`defaultValue`?`value`:`checked`;Object.hasOwn(o,t)||(I+=d(t,i,t===`checked`))}else{let t=n(e,E);I+=d(t,i,r(t,i))}}if(L.length>0&&(I+=` class="${c(L.join(` `))}"`),R!==``&&(I+=p(R)),b.has(A))return new a(`<${e}${I}>`);let B=!E&&(A===`script`||A===`style`),V=C===void 0?D(o):C,H=z===void 0?B?v(A,V):s(V):z;if(z===void 0&&(P||F)){let e=P?N.value:N.fallback;H=M?_(e):g(e,H)}else(M||A===`pre`||A===`listing`)&&z===void 0&&(H=h(H));return new a(`<${e}${I}>${H}</${e}>`)}function D(e){if(typeof e==`object`&&e)return Reflect.get(e,`children`)}function O(e,t){if(typeof e==`object`&&e&&!Array.isArray(e))for(let n of Object.keys(e))n!==``&&l(Reflect.get(e,n))&&t.push(n)}function k(e){if(e==null)return``;if(o(e))return e.t;if(typeof e==`symbol`)throw i(`UNRECOGNIZED_INSERT_VALUE`,`A symbol cannot be innerHTML.`);return String(e)}export{C as ssr,E as ssrElement,T as ssrHydrationKey,w as ssrRaw};
2
2
  //# sourceMappingURL=element.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"element.js","names":["TAG_NAME","VOID_ELEMENTS","SKIPPED_KEYS","innerHtmlOfValue","value","ssr","holes","parts","html","index","hole","isSsrNode","SsrNode","ssrRaw","ssrHydrationKey","key","nextKey","escapeHtml","ssrElement","tag","invalid","lowerTag","isSelect","isTextarea","control","hasValue","hasFallback","attributes","needsKey","classes","style","innerHtml","props","IGNORED_KEYS","isEventName","resolveValue","text","classText","collectTruthyKeys","styleText","plainHtml","ssrAttribute","name","attributeName","svg","BOOLEAN_ATTRIBUTES","ssrStyle","content","escape","children","propsChildren","textareaContent","markSelectedOptions","out"],"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":"A,shBAWA,MAAMA,EAAW,0BAGXC,kBAAqC,IAAI,IAAI,CACjD,OACA,OACA,KACA,MACA,UACA,QACA,KACA,MACA,QACA,SACA,OACA,OACA,QACA,SACA,QACA,KACF,CAAC,EAGKC,kBAAoC,IAAI,IAAI,CAChD,YACA,cACA,YACA,WACA,KACF,CAAC,EAGD,SAASC,EAAiB,EAAyB,CACjD,GAAsB,OAAOC,GAAU,UAAnCA,EACJ,OAAO,QAAQ,IAAIA,EAAO,QAAQ,CACpC,CAsBA,SAAgBC,EAAI,EAA0B,GAAGC,EAA2B,CAC1E,GAAI,CAAC,MAAM,QAAQC,CAAK,GAAKA,EAAM,SAAWD,EAAM,OAAS,EAC3D,MAAU,UAAU,6DAA6D,EAEnF,IAAIE,EAAOD,EAAM,IAAM,GACvB,IAAK,IAAIE,EAAQ,EAAGA,EAAQH,EAAM,OAAQ,GAAS,EAAG,CACpD,IAAMI,EAAOJ,EAAMG,GACnB,GAAI,OAAOC,GAAS,SAAU,GAAQA,OACjC,GAAIC,EAAUD,CAAI,EAAG,GAAQA,EAAK,OAClC,MAAU,UAAU,wDAAwD,EACjF,GAAQH,EAAME,EAAQ,IAAM,EAC9B,CACA,OAAO,IAAIG,EAAQJ,CAAI,CACzB,CAiBA,SAAgBK,EAAO,EAAuB,CAC5C,GAAI,OAAOL,GA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B,EAAQ,IAAI5B,EAAI,EAAE,CAC/D,CAGA,SAAS+B,EAAc,EAAyB,CAC9C,GAAsB,OAAOlB,GAAU,UAAnCA,EACJ,OAAO,QAAQ,IAAIA,EAAO,UAAU,CACtC,CAGA,SAASM,EAAkB,EAAgB,EAAqB,CAC9D,GAAsB,OAAOlC,GAAU,UAAnCA,GAA+C,OAAM,QAAQA,CAAK,EACtE,IAAK,IAAMW,KAAO,OAAO,KAAKX,CAAK,EAC7BW,IAAQ,IAAMoB,EAAa,QAAQ,IAAI/B,EAAOW,CAAG,CAAC,GAAGsC,EAAI,KAAKtC,CAAG,CAEzE,CAGA,SAASyB,EAAU,EAAwB,CACzC,GAAIpC,GAAU,KAA6B,MAAO,GAClD,GAAIO,EAAUP,CAAK,EAAG,OAAOA,EAAM,EACnC,GAAI,OAAOA,GAAU,SACnB,MAAMgB,EAAQ,4BAA6B,+BAA+B,EAC5E,OAAO,OAAOhB,CAAK,CACrB,C"}
1
+ {"version":3,"file":"element.js","names":["TAG_NAME","VOID_ELEMENTS","SKIPPED_KEYS","innerHtmlOfValue","value","ssr","holes","parts","html","index","hole","isSsrNode","SsrNode","ssrRaw","ssrHydrationKey","key","nextKey","escapeHtml","ssrElement","tag","invalid","lowerTag","isSelect","isTextarea","control","hasValue","hasFallback","attributes","needsKey","classes","style","innerHtml","props","IGNORED_KEYS","isEventName","resolveValue","text","classText","collectTruthyKeys","styleText","plainHtml","ssrAttribute","name","attributeName","svg","isFlagAttribute","ssrStyle","raw","given","children","propsChildren","content","rawElementContent","escape","textareaContent","markSelectedOptions","keepLeadingNewline","out"],"sources":["../../../src/server/element.ts"],"sourcesContent":["import { nextKey } from \"../internal/hydration-scope\";\nimport { attributeName, IGNORED_KEYS, isFlagAttribute } from \"../internal/react-names\";\nimport { 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.test(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, isFlagAttribute(name, value));\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 (\n (isTextarea || lowerTag === \"pre\" || lowerTag === \"listing\") &&\n innerHtml === undefined\n ) {\n // The parser drops one line break right after these start tags (a textarea's children are its\n // value, as on the client): write one more so the content is read as it was given.\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":"A,6lBAYA,MAAMA,EAAW,0BAGXC,kBAAqC,IAAI,IAAI,CACjD,OACA,OACA,KACA,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C7BW,IAAQ,IAAMoB,EAAa,QAAQ,IAAI/B,EAAOW,CAAG,CAAC,GAAG0C,EAAI,KAAK1C,CAAG,CAEzE,CAGA,SAASyB,EAAU,EAAwB,CACzC,GAAIpC,GAAU,KAA6B,MAAO,GAClD,GAAIO,EAAUP,CAAK,EAAG,OAAOA,EAAM,EACnC,GAAI,OAAOA,GAAU,SACnB,MAAMgB,EAAQ,4BAA6B,+BAA+B,EAC5E,OAAO,OAAOhB,CAAK,CACrB,C"}
@@ -1,2 +1,2 @@
1
- var e=class extends Error{code;constructor(e,t){super(`SHADOW_${e}`),this.name=`SsrError`,this.code=e}};function t(e,t){return/* @__PURE__ */ TypeError(`SHADOW_${e}`)}export{e as SsrError,t as invalid};
1
+ var e=class extends Error{code;constructor(e,t){super(`SHADOW_${e}`),this.name=`SsrError`,this.code=e}};function t(e,t){return/* @__PURE__ */ TypeError(`SHADOW_${e}`)}const n=2147483647;export{n as MAX_TIMER_MS,e as SsrError,t as invalid};
2
2
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":["SsrError","code","invalid"],"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,IAAaA,EAAb,cAA8B,KAAM,CAClC,KACA,YAAY,EAAoB,EAAgB,CAC9C,MAA+C,UAAUC,GAAM,EAC/D,KAAK,KAAO,WACZ,KAAK,KAAOA,CACd,CACF,EAOA,SAAgBC,EAAQ,EAAc,EAA2B,CAC/D,MAAO,gBAAI,UAAmD,UAAUD,GAAM,CAChF,C"}
1
+ {"version":3,"file":"errors.js","names":["SsrError","code","invalid","MAX_TIMER_MS"],"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,IAAaA,EAAb,cAA8B,KAAM,CAClC,KACA,YAAY,EAAoB,EAAgB,CAC9C,MAA+C,UAAUC,GAAM,EAC/D,KAAK,KAAO,WACZ,KAAK,KAAOA,CACd,CACF,EAOA,SAAgBC,EAAQ,EAAc,EAA2B,CAC/D,MAAO,gBAAI,UAAmD,UAAUD,GAAM,CAChF,CAOA,MAAaE,EAAe,W"}
@@ -1,2 +1,2 @@
1
- import{invalid as e}from"./errors.js";import{isSsrNode as t}from"./node.js";import{untrack as n}from"@shadow-js/core";const r={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`},i=/[&<>"']/g;function a(e){return e.replace(i,e=>r[e]??e)}function o(e){let t=e;for(let e=0;typeof t==`function`;e+=1){if(e>=1e3)throw TypeError(`An accessor returns accessors more than 1000 levels deep.`);t=n(t)}return t}function s(n,r){if(n!=null&&typeof n!=`boolean`){if(typeof n==`string`)r.push(a(n));else if(typeof n==`number`||typeof n==`bigint`)r.push(String(n));else{if(typeof n==`symbol`)throw e(`UNRECOGNIZED_INSERT_VALUE`,`A symbol cannot be rendered.`);t(n)?r.push(n.t):typeof n!=`object`&&r.push(a(String(n)))}}}function c(e){let t=[],n=[],r=[],i=/* @__PURE__ */ new Set,a=e;for(;;){let e=o(a);if(Array.isArray(e)){if(i.has(e))throw TypeError(`escape(): an array contains itself.`);i.add(e),n.push(e),r.push(0)}else s(e,t);let c,l=!1;for(;!l&&n.length>0;){let e=n.length-1,t=n[e],a=r[e]??0;if(t===void 0)break;a<t.length?(r[e]=a+1,c=t[a],l=!0):(n.pop(),r.pop(),i.delete(t))}if(!l)return t.join(``);a=c}}export{c as escape,a as escapeHtml,o as resolveValue};
1
+ import{invalid as e}from"./errors.js";import{isSsrNode as t}from"./node.js";import{untrack as n}from"@shadow-js/core";const r={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`},i=/[&<>"']/g;function a(e){return e.replace(i,e=>r[e]??e)}function o(e){let t=e;for(let e=0;typeof t==`function`;e+=1){if(e>=1e3)throw TypeError(`An accessor returns accessors more than 1000 levels deep.`);t=n(t)}return t}function s(n,r,i){if(n!=null&&typeof n!=`boolean`){if(typeof n==`string`)r.push(i(n));else if(typeof n==`number`||typeof n==`bigint`)r.push(String(n));else{if(typeof n==`symbol`)throw e(`UNRECOGNIZED_INSERT_VALUE`,`A symbol cannot be rendered.`);t(n)?r.push(n.t):typeof n!=`object`&&r.push(i(String(n)))}}}function c(e){return l(e,a)}function l(e,t){let n=[],r=[],i=[],a=/* @__PURE__ */ new Set,c=e;for(;;){let e=o(c);if(Array.isArray(e)){if(a.has(e))throw TypeError(`escape(): an array contains itself.`);a.add(e),r.push(e),i.push(0)}else s(e,n,t);let l,u=!1;for(;!u&&r.length>0;){let e=r.length-1,t=r[e],n=i[e]??0;if(t===void 0)break;n<t.length?(i[e]=n+1,l=t[n],u=!0):(r.pop(),i.pop(),a.delete(t))}if(!u)return n.join(``);c=l}}export{c as escape,a as escapeHtml,l as render,o as resolveValue};
2
2
  //# sourceMappingURL=escape.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"escape.js","names":["accessor","HTML_ESCAPES","HTML_SPECIAL","escapeHtml","text","char","resolveValue","current","value","layer","untrack","appendLeaf","out","invalid","isSsrNode","escape","frames","cursors","open","item","resolved","next","found","top","frame","cursor"],"sources":["../../../src/server/escape.ts"],"sourcesContent":["import { untrack } from \"@shadow-js/core\";\nimport { invalid } from \"./errors\";\nimport { isSsrNode } from \"./node\";\n\nconst HTML_ESCAPES: Readonly<Record<string, string>> = {\n \"&\": \"&amp;\",\n \"<\": \"&lt;\",\n \">\": \"&gt;\",\n '\"': \"&quot;\",\n \"'\": \"&#39;\",\n};\n\nconst HTML_SPECIAL = /[&<>\"']/g;\n\n/** Longest chain of accessors that returns accessors; longer chains are a bug in user code. */\nconst MAX_ACCESSOR_LAYERS = 1000;\n\n/**\n * Escapes the five HTML-significant characters. Escaping `&` too means entity-looking text is\n * written literally, and the result is safe in text and in quoted attribute values alike.\n * @internal\n */\nexport function escapeHtml(text: string): string {\n return text.replace(HTML_SPECIAL, (char) => HTML_ESCAPES[char] ?? char);\n}\n\n/**\n * Calls accessors until a plain value remains. Accessors run untracked; a chain longer than\n * {@link MAX_ACCESSOR_LAYERS} throws instead of looping.\n * @internal\n */\nexport function resolveValue(value: unknown): unknown {\n let current = value;\n for (let layer = 0; typeof current === \"function\"; layer += 1) {\n if (layer >= MAX_ACCESSOR_LAYERS) {\n throw new TypeError(\"An accessor returns accessors more than 1000 levels deep.\");\n }\n const accessor = current as () => unknown;\n current = untrack(accessor);\n }\n return current;\n}\n\n/** Writes the markup for one resolved value that is not an array. */\nfunction appendLeaf(value: unknown, out: string[]): void {\n if (value === null || value === undefined || typeof value === \"boolean\") return;\n if (typeof value === \"string\") {\n out.push(escapeHtml(value));\n return;\n }\n // Numbers and bigints never contain markup characters.\n if (typeof value === \"number\" || typeof value === \"bigint\") {\n out.push(String(value));\n return;\n }\n if (typeof value === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be rendered.\");\n }\n if (isSsrNode(value)) {\n out.push(value.t);\n return;\n }\n // Any other object is not trusted markup. Dev fails loudly; production renders nothing.\n if (typeof value === \"object\") {\n if (__DEV__) {\n throw invalid(\n \"UNRECOGNIZED_INSERT_VALUE\",\n \"A plain object cannot be rendered. Use a string, a number, an array or an SsrNode.\",\n );\n }\n return;\n }\n out.push(escapeHtml(String(value)));\n}\n\n/**\n * Converts any value a JSX child may hold to escaped HTML: the helper compiled server output calls\n * for every dynamic child, and what the renderers call on the app's result.\n *\n * - Strings are escaped (`& < > \" '`); numbers and bigints are written as they are; `null`,\n * `undefined` and booleans render nothing.\n * - `SsrNode` values (from `ssr`, `ssrRaw` and the other helpers) pass through unchanged: they were\n * escaped when they were built.\n * - Accessors are called (untracked) and their result is rendered; a chain of more than 1000\n * accessors returning accessors throws.\n * - Arrays are flattened in order, with an explicit stack, so nesting depth is not limited by the\n * call stack.\n * - Plain objects throw in development builds and render nothing in production builds.\n *\n * @param value The value to render.\n * @returns The escaped markup.\n * @throws TypeError when an array contains itself, for a symbol (`UNRECOGNIZED_INSERT_VALUE`), for an\n * object that is not an `SsrNode` (`UNRECOGNIZED_INSERT_VALUE`, development builds only), and for an\n * accessor chain deeper than 1000.\n * @example\n * import { escape } from \"@shadow-js/web/server\";\n *\n * const name = () => \"<Ada>\";\n * escape([\"Hello, \", name, null, 3]); // \"Hello, &lt;Ada&gt;3\"\n * @since 1.0.0\n */\n// biome-ignore lint/suspicious/noShadowRestrictedNames: the name \"escape\" is part of the compiler contract (SSR output).\nexport function escape(value: unknown): string {\n const out: string[] = [];\n const frames: unknown[][] = [];\n const cursors: number[] = [];\n const open = new Set<unknown[]>();\n let item: unknown = value;\n for (;;) {\n const resolved = resolveValue(item);\n if (Array.isArray(resolved)) {\n if (open.has(resolved)) throw new TypeError(\"escape(): an array contains itself.\");\n open.add(resolved);\n frames.push(resolved);\n cursors.push(0);\n } else {\n appendLeaf(resolved, out);\n }\n // Find the next item, closing every array that has no items left.\n let next: unknown;\n let found = false;\n while (!found && frames.length > 0) {\n const top = frames.length - 1;\n const frame = frames[top];\n const cursor = cursors[top] ?? 0;\n if (frame === undefined) break;\n if (cursor < frame.length) {\n cursors[top] = cursor + 1;\n next = frame[cursor];\n found = true;\n } else {\n frames.pop();\n cursors.pop();\n open.delete(frame);\n }\n }\n if (!found) return out.join(\"\");\n item = next;\n }\n}\n"],"mappings":"A,sHAIA,MAAMC,EAAiD,CACrD,IAAK,QACL,IAAK,OACL,IAAK,OACL,IAAK,SACL,IAAK,OACP,EAEMC,EAAe,WAUrB,SAAgBC,EAAW,EAAsB,CAC/C,OAAOC,EAAK,QAAQF,EAAe,GAASD,EAAaI,IAASA,CAAI,CACxE,CAOA,SAAgBC,EAAa,EAAyB,CACpD,IAAIC,EAAUC,EACd,IAAK,IAAIC,EAAQ,EAAG,OAAOF,GAAY,WAAY,GAAS,EAAG,CAC7D,GAAIE,GAAS,IACX,MAAU,UAAU,2DAA2D,EAGjF,EAAUC,EAAQV,CAAQ,CAC5B,CACA,OAAOO,CACT,CAGA,SAASI,EAAW,EAAgB,EAAqB,CACvD,GAAIH,GAAU,MAA+B,OAAOA,GAAU,UAC9D,IAAI,OAAOA,GAAU,SACnBI,EAAI,KAAKT,EAAWK,CAAK,CAAC,OAI5B,GAAI,OAAOA,GAAU,UAAY,OAAOA,GAAU,SAChDI,EAAI,KAAK,OAAOJ,CAAK,CAAC,MAGxB,IAAI,OAAOA,GAAU,SACnB,MAAMK,EAAQ,4BAA6B,8BAA8B,EAEvEC,EAAUN,CAAK,EACjBI,EAAI,KAAKJ,EAAM,CAAC,EAId,OAAOA,GAAU,UASrBI,EAAI,KAAKT,EAAW,OAAOK,CAAK,CAAC,CAAC,CAhByC,CAP3E,CAwBF,CA6BA,SAAgBO,EAAO,EAAwB,CAC7C,IAAMH,EAAgB,CAAC,EACjBI,EAAsB,CAAC,EACvBC,EAAoB,CAAC,EACrBC,kBAAO,IAAI,IACbC,EAAgBX,EACpB,OAAS,CACP,IAAMY,EAAWd,EAAaa,CAAI,EAClC,GAAI,MAAM,QAAQC,CAAQ,EAAG,CAC3B,GAAIF,EAAK,IAAIE,CAAQ,EAAG,MAAU,UAAU,qCAAqC,EACjFF,EAAK,IAAIE,CAAQ,EACjBJ,EAAO,KAAKI,CAAQ,EACpBH,EAAQ,KAAK,CAAC,CAChB,MACEN,EAAWS,EAAUR,CAAG,EAG1B,IAAIS,EACAC,EAAQ,GACZ,KAAO,CAACA,GAASN,EAAO,OAAS,GAAG,CAClC,IAAMO,EAAMP,EAAO,OAAS,EACtBQ,EAAQR,EAAOO,GACfE,EAASR,EAAQM,IAAQ,EAC/B,GAAIC,IAAU,IAAA,GAAW,MACrBC,EAASD,EAAM,QACjB,EAAQD,GAAOE,EAAS,EACxB,EAAOD,EAAMC,GACb,EAAQ,KAERT,EAAO,IAAI,EACXC,EAAQ,IAAI,EACZC,EAAK,OAAOM,CAAK,EAErB,CACA,GAAI,CAACF,EAAO,OAAOV,EAAI,KAAK,EAAE,EAC9B,EAAOS,CACT,CACF,C"}
1
+ {"version":3,"file":"escape.js","names":["accessor","HTML_ESCAPES","HTML_SPECIAL","escapeHtml","text","char","resolveValue","current","value","layer","untrack","appendLeaf","out","invalid","isSsrNode","escape","render","frames","cursors","open","item","resolved","next","found","top","frame","cursor"],"sources":["../../../src/server/escape.ts"],"sourcesContent":["import { untrack } from \"@shadow-js/core\";\nimport { invalid } from \"./errors\";\nimport { isSsrNode } from \"./node\";\n\nconst HTML_ESCAPES: Readonly<Record<string, string>> = {\n \"&\": \"&amp;\",\n \"<\": \"&lt;\",\n \">\": \"&gt;\",\n '\"': \"&quot;\",\n \"'\": \"&#39;\",\n};\n\nconst HTML_SPECIAL = /[&<>\"']/g;\n\n/** Longest chain of accessors that returns accessors; longer chains are a bug in user code. */\nconst MAX_ACCESSOR_LAYERS = 1000;\n\n/**\n * Escapes the five HTML-significant characters. Escaping `&` too means entity-looking text is\n * written literally, and the result is safe in text and in quoted attribute values alike.\n * @internal\n */\nexport function escapeHtml(text: string): string {\n return text.replace(HTML_SPECIAL, (char) => HTML_ESCAPES[char] ?? char);\n}\n\n/**\n * Calls accessors until a plain value remains. Accessors run untracked; a chain longer than\n * {@link MAX_ACCESSOR_LAYERS} throws instead of looping.\n * @internal\n */\nexport function resolveValue(value: unknown): unknown {\n let current = value;\n for (let layer = 0; typeof current === \"function\"; layer += 1) {\n if (layer >= MAX_ACCESSOR_LAYERS) {\n throw new TypeError(\"An accessor returns accessors more than 1000 levels deep.\");\n }\n const accessor = current as () => unknown;\n current = untrack(accessor);\n }\n return current;\n}\n\n/** Writes the markup for one resolved value that is not an array; `text` encodes the text of a string. */\nfunction appendLeaf(value: unknown, out: string[], text: (value: string) => string): void {\n if (value === null || value === undefined || typeof value === \"boolean\") return;\n if (typeof value === \"string\") {\n out.push(text(value));\n return;\n }\n // Numbers and bigints never contain markup characters.\n if (typeof value === \"number\" || typeof value === \"bigint\") {\n out.push(String(value));\n return;\n }\n if (typeof value === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be rendered.\");\n }\n if (isSsrNode(value)) {\n out.push(value.t);\n return;\n }\n // Any other object is not trusted markup. Dev fails loudly; production renders nothing.\n if (typeof value === \"object\") {\n if (__DEV__) {\n throw invalid(\n \"UNRECOGNIZED_INSERT_VALUE\",\n \"A plain object cannot be rendered. Use a string, a number, an array or an SsrNode.\",\n );\n }\n return;\n }\n out.push(text(String(value)));\n}\n\n/**\n * Converts any value a JSX child may hold to escaped HTML: the helper compiled server output calls\n * for every dynamic child, and what the renderers call on the app's result.\n *\n * - Strings are escaped (`& < > \" '`); numbers and bigints are written as they are; `null`,\n * `undefined` and booleans render nothing.\n * - `SsrNode` values (from `ssr`, `ssrRaw` and the other helpers) pass through unchanged: they were\n * escaped when they were built.\n * - Accessors are called (untracked) and their result is rendered; a chain of more than 1000\n * accessors returning accessors throws.\n * - Arrays are flattened in order, with an explicit stack, so nesting depth is not limited by the\n * call stack.\n * - Plain objects throw in development builds and render nothing in production builds.\n *\n * @param value The value to render.\n * @returns The escaped markup.\n * @throws TypeError when an array contains itself, for a symbol (`UNRECOGNIZED_INSERT_VALUE`), for an\n * object that is not an `SsrNode` (`UNRECOGNIZED_INSERT_VALUE`, development builds only), and for an\n * accessor chain deeper than 1000.\n * @example\n * import { escape } from \"@shadow-js/web/server\";\n *\n * const name = () => \"<Ada>\";\n * escape([\"Hello, \", name, null, 3]); // \"Hello, &lt;Ada&gt;3\"\n * @since 1.0.0\n */\n// biome-ignore lint/suspicious/noShadowRestrictedNames: the name \"escape\" is part of the compiler contract (SSR output).\nexport function escape(value: unknown): string {\n return render(value, escapeHtml);\n}\n\n/**\n * {@link escape} with the encoding of strings left to the caller: the walk over accessors, arrays and\n * trusted nodes that every kind of text shares (an element's text is encoded one way, a script's another).\n * @internal\n */\nexport function render(value: unknown, text: (value: string) => string): string {\n const out: string[] = [];\n const frames: unknown[][] = [];\n const cursors: number[] = [];\n const open = new Set<unknown[]>();\n let item: unknown = value;\n for (;;) {\n const resolved = resolveValue(item);\n if (Array.isArray(resolved)) {\n if (open.has(resolved)) throw new TypeError(\"escape(): an array contains itself.\");\n open.add(resolved);\n frames.push(resolved);\n cursors.push(0);\n } else {\n appendLeaf(resolved, out, text);\n }\n // Find the next item, closing every array that has no items left.\n let next: unknown;\n let found = false;\n while (!found && frames.length > 0) {\n const top = frames.length - 1;\n const frame = frames[top];\n const cursor = cursors[top] ?? 0;\n if (frame === undefined) break;\n if (cursor < frame.length) {\n cursors[top] = cursor + 1;\n next = frame[cursor];\n found = true;\n } else {\n frames.pop();\n cursors.pop();\n open.delete(frame);\n }\n }\n if (!found) return out.join(\"\");\n item = next;\n }\n}\n"],"mappings":"A,sHAIA,MAAMC,EAAiD,CACrD,IAAK,QACL,IAAK,OACL,IAAK,OACL,IAAK,SACL,IAAK,OACP,EAEMC,EAAe,WAUrB,SAAgBC,EAAW,EAAsB,CAC/C,OAAOC,EAAK,QAAQF,EAAe,GAASD,EAAaI,IAASA,CAAI,CACxE,CAOA,SAAgBC,EAAa,EAAyB,CACpD,IAAIC,EAAUC,EACd,IAAK,IAAIC,EAAQ,EAAG,OAAOF,GAAY,WAAY,GAAS,EAAG,CAC7D,GAAIE,GAAS,IACX,MAAU,UAAU,2DAA2D,EAGjF,EAAUC,EAAQV,CAAQ,CAC5B,CACA,OAAOO,CACT,CAGA,SAASI,EAAW,EAAgB,EAAe,EAAuC,CACxF,GAAIH,GAAU,MAA+B,OAAOA,GAAU,UAC9D,IAAI,OAAOA,GAAU,SACnBI,EAAI,KAAKR,EAAKI,CAAK,CAAC,OAItB,GAAI,OAAOA,GAAU,UAAY,OAAOA,GAAU,SAChDI,EAAI,KAAK,OAAOJ,CAAK,CAAC,MAGxB,IAAI,OAAOA,GAAU,SACnB,MAAMK,EAAQ,4BAA6B,8BAA8B,EAEvEC,EAAUN,CAAK,EACjBI,EAAI,KAAKJ,EAAM,CAAC,EAId,OAAOA,GAAU,UASrBI,EAAI,KAAKR,EAAK,OAAOI,CAAK,CAAC,CAAC,CAhB+C,CAP3E,CAwBF,CA6BA,SAAgBO,EAAO,EAAwB,CAC7C,OAAOC,EAAOR,EAAOL,CAAU,CACjC,CAOA,SAAgBa,EAAO,EAAgB,EAAyC,CAC9E,IAAMJ,EAAgB,CAAC,EACjBK,EAAsB,CAAC,EACvBC,EAAoB,CAAC,EACrBC,kBAAO,IAAI,IACbC,EAAgBZ,EACpB,OAAS,CACP,IAAMa,EAAWf,EAAac,CAAI,EAClC,GAAI,MAAM,QAAQC,CAAQ,EAAG,CAC3B,GAAIF,EAAK,IAAIE,CAAQ,EAAG,MAAU,UAAU,qCAAqC,EACjFF,EAAK,IAAIE,CAAQ,EACjBJ,EAAO,KAAKI,CAAQ,EACpBH,EAAQ,KAAK,CAAC,CAChB,MACEP,EAAWU,EAAUT,EAAKR,CAAI,EAGhC,IAAIkB,EACAC,EAAQ,GACZ,KAAO,CAACA,GAASN,EAAO,OAAS,GAAG,CAClC,IAAMO,EAAMP,EAAO,OAAS,EACtBQ,EAAQR,EAAOO,GACfE,EAASR,EAAQM,IAAQ,EAC/B,GAAIC,IAAU,IAAA,GAAW,MACrBC,EAASD,EAAM,QACjB,EAAQD,GAAOE,EAAS,EACxB,EAAOD,EAAMC,GACb,EAAQ,KAERT,EAAO,IAAI,EACXC,EAAQ,IAAI,EACZC,EAAK,OAAOM,CAAK,EAErB,CACA,GAAI,CAACF,EAAO,OAAOX,EAAI,KAAK,EAAE,EAC9B,EAAOU,CACT,CACF,C"}
@@ -1,3 +1,3 @@
1
- import{invalid as e}from"./errors.js";import{SsrNode as t}from"./node.js";import{escape as n,escapeHtml as r,resolveValue as i}from"./escape.js";function a(t){if(typeof t==`symbol`)throw e(`UNRECOGNIZED_INSERT_VALUE`,`A symbol cannot be a form control value.`);return t==null?``:String(t)}function o(e){let t=r(a(i(e))),n=t.charAt(0);return n===`
2
- `||n===`\r`?`\n${t}`:t}function s(e){return new t(o(e))}function c(e){let t=i(e);if(!Array.isArray(t))return{values:/* @__PURE__ */ new Set([a(t)]),many:!1};let n=/* @__PURE__ */ new Set;for(let e of t){let t=i(e);t!=null&&n.add(a(t))}return{values:n,many:!0}}const l=/[ \t\n\f\r]+/g,u=/&(?:#(\d+)|#x([0-9a-f]+)|(amp|lt|gt|quot|apos|nbsp));/gi,d={amp:`&`,lt:`<`,gt:`>`,quot:`"`,apos:`'`,nbsp:`\xA0`},f=/<!--[\s\S]*?-->|<[^>]*>/g;function p(e){return e.replace(u,(e,t,n,r)=>{if(r!==void 0)return d[r.toLowerCase()]??e;let i=t===void 0?Number.parseInt(n??``,16):Number(t);return Number.isInteger(i)&&i>=0&&i<=1114111&&!(i>=55296&&i<=57343)?String.fromCodePoint(i):e})}function m(e,t){let n=``;for(let r=t;r<e.length;r+=1){let t=e.charAt(r);if(n!==``)t===n&&(n=``);else if(t===`"`||t===`'`)n=t;else if(t===`>`)return r}return-1}function h(e,t,n){n.lastIndex=t;let r=n.exec(e);return p(e.slice(t,r===null?e.length:r.index).replace(f,``)).replace(l,` `).trim()}function g(e,t){let n=``,r=0,i=0,a=!1,o=/* @__PURE__ */ RegExp(`\\s+([^\\s"'<>/=]+)(?:\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s"'=<>\`]+)))?`,`g`),s=/* @__PURE__ */ RegExp(`<\\/?(?:option|optgroup)(?=[\\s/>])`,`gi`);for(;;){let c=e.indexOf(`<option`,i);if(c===-1)break;let l=c+7;if(i=l,!/[\s/>]/.test(e.charAt(l)))continue;let u=m(e,l);if(u===-1)break;let d=e.slice(l,u),f,g=-1,_=-1;o.lastIndex=0;for(let e=o.exec(d);e!==null;e=o.exec(d)){let t=(e[1]??``).toLowerCase();t===`selected`?(g=e.index,_=e.index+e[0].length):t===`value`&&f===void 0&&(f=p(e[2]??e[3]??e[4]??``))}let v=(t.many||!a)&&t.values.has(f??h(e,u+1,s));if(v&&(a=!0),v&&g===-1){let t=d.endsWith(`/`)?d.length-1:d.length;n+=`${e.slice(r,l+t)} selected`,r=l+t}else!v&&g!==-1&&(n+=e.slice(r,l+g),r=l+_);i=u}return r===0?e:n+e.slice(r)}function _(e,r){return new t(v(e,n(r)))}function v(e,t){return g(t,c(e))}export{v as markSelectedOptions,_ as ssrSelectValue,s as ssrTextArea,o as textareaContent};
1
+ import{invalid as e}from"./errors.js";import{SsrNode as t}from"./node.js";import{escape as n,escapeHtml as r,resolveValue as i}from"./escape.js";function a(t){if(typeof t==`symbol`)throw e(`UNRECOGNIZED_INSERT_VALUE`,`A symbol cannot be a form control value.`);return t==null?``:String(t)}function o(e){return s(r(a(i(e))))}function s(e){let t=e.charAt(0);return t===`
2
+ `||t===`\r`?`\n${e}`:e}function c(e){return new t(o(e))}function l(e){let t=i(e);if(!Array.isArray(t))return{values:/* @__PURE__ */ new Set([a(t)]),many:!1};let n=/* @__PURE__ */ new Set;for(let e of t){let t=i(e);t!=null&&n.add(a(t))}return{values:n,many:!0}}const u=/[ \t\n\f\r]+/g,d=/&(?:#(\d+)|#x([0-9a-f]+)|(amp|lt|gt|quot|apos|nbsp));/gi,f={amp:`&`,lt:`<`,gt:`>`,quot:`"`,apos:`'`,nbsp:`\xA0`},p=/<!--[\s\S]*?-->|<[^>]*>/g;function m(e){return e.replace(d,(e,t,n,r)=>{if(r!==void 0)return f[r.toLowerCase()]??e;let i=t===void 0?Number.parseInt(n??``,16):Number(t);return Number.isInteger(i)&&i>=0&&i<=1114111&&!(i>=55296&&i<=57343)?String.fromCodePoint(i):e})}function h(e,t){let n=``;for(let r=t;r<e.length;r+=1){let t=e.charAt(r);if(n!==``)t===n&&(n=``);else if(t===`"`||t===`'`)n=t;else if(t===`>`)return r}return-1}function g(e,t,n){n.lastIndex=t;let r=n.exec(e);return m(e.slice(t,r===null?e.length:r.index).replace(p,``)).replace(u,` `).trim()}function _(e,t){let n=``,r=0,i=0,a=!1,o=/* @__PURE__ */ RegExp(`\\s+([^\\s"'<>/=]+)(?:\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s"'=<>\`]+)))?`,`g`),s=/* @__PURE__ */ RegExp(`<\\/?(?:option|optgroup)(?=[\\s/>])`,`gi`);for(;;){let c=e.indexOf(`<option`,i);if(c===-1)break;let l=c+7;if(i=l,!/[\s/>]/.test(e.charAt(l)))continue;let u=h(e,l);if(u===-1)break;let d=e.slice(l,u),f,p=-1,_=-1;o.lastIndex=0;for(let e=o.exec(d);e!==null;e=o.exec(d)){let t=(e[1]??``).toLowerCase();t===`selected`?(p=e.index,_=e.index+e[0].length):t===`value`&&f===void 0&&(f=m(e[2]??e[3]??e[4]??``))}let v=(t.many||!a)&&t.values.has(f??g(e,u+1,s));if(v&&(a=!0),v&&p===-1){let t=d.endsWith(`/`)?d.length-1:d.length;n+=`${e.slice(r,l+t)} selected`,r=l+t}else!v&&p!==-1&&(n+=e.slice(r,l+p),r=l+_);i=u}return r===0?e:n+e.slice(r)}function v(e,r){return new t(y(e,n(r)))}function y(e,t){return _(t,l(e))}export{s as keepLeadingNewline,y as markSelectedOptions,v as ssrSelectValue,c as ssrTextArea,o as textareaContent};
3
3
  //# sourceMappingURL=form-controls.js.map