@shadow-js/web 1.0.6 → 1.1.1

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 (222) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/dev/attributes.d.ts +1 -2
  4. package/dist/dev/autofocus.d.ts +1 -2
  5. package/dist/dev/class-style.d.ts +1 -2
  6. package/dist/dev/component.d.ts +1 -2
  7. package/dist/dev/control-flow/activity.d.ts +1 -2
  8. package/dist/dev/control-flow/client-only.d.ts +1 -2
  9. package/dist/dev/control-flow/dynamic.d.ts +1 -2
  10. package/dist/dev/control-flow/error-boundary.d.ts +1 -2
  11. package/dist/dev/control-flow/for.d.ts +1 -2
  12. package/dist/dev/control-flow/fragment.d.ts +1 -2
  13. package/dist/dev/control-flow/index-list.d.ts +1 -2
  14. package/dist/dev/control-flow/lazy.d.ts +1 -2
  15. package/dist/dev/control-flow/no-hydration.d.ts +1 -2
  16. package/dist/dev/control-flow/portal.d.ts +1 -2
  17. package/dist/dev/control-flow/portal.js.map +1 -1
  18. package/dist/dev/control-flow/root-errors.d.ts +2 -3
  19. package/dist/dev/control-flow/show.d.ts +1 -2
  20. package/dist/dev/control-flow/suspense-list.d.ts +2 -3
  21. package/dist/dev/control-flow/suspense.d.ts +1 -2
  22. package/dist/dev/control-flow/switch.d.ts +1 -2
  23. package/dist/dev/derived.d.ts +1 -2
  24. package/dist/dev/element.d.ts +1 -2
  25. package/dist/dev/events.d.ts +1 -2
  26. package/dist/dev/extend.d.ts +9 -0
  27. package/dist/dev/head/components.d.ts +1 -2
  28. package/dist/dev/head/server-head.d.ts +2 -3
  29. package/dist/dev/head/use-head.d.ts +1 -2
  30. package/dist/dev/head/validate.d.ts +1 -2
  31. package/dist/dev/hmr.d.ts +1 -2
  32. package/dist/dev/hmr.js.map +1 -1
  33. package/dist/dev/hydration.d.ts +1 -2
  34. package/dist/dev/insert.d.ts +1 -2
  35. package/dist/dev/insert.js.map +1 -1
  36. package/dist/dev/internal/claim.d.ts +1 -2
  37. package/dist/dev/internal/diagnostics.d.ts +1 -2
  38. package/dist/dev/internal/hydration-hooks.d.ts +1 -2
  39. package/dist/dev/internal/hydration-scope.d.ts +1 -2
  40. package/dist/dev/internal/names.d.ts +1 -2
  41. package/dist/dev/internal/portal-context.d.ts +1 -2
  42. package/dist/dev/internal/reconcile.d.ts +1 -2
  43. package/dist/dev/internal/reconcile.js.map +1 -1
  44. package/dist/dev/internal/stream-context.d.ts +1 -2
  45. package/dist/dev/jsx/aria.d.ts +7 -2
  46. package/dist/dev/jsx/component.d.ts +7 -2
  47. package/dist/dev/jsx/events.d.ts +1 -2
  48. package/dist/dev/jsx/global.d.ts +11 -2
  49. package/dist/dev/jsx/html.d.ts +8 -2
  50. package/dist/dev/jsx/intrinsic.d.ts +10 -2
  51. package/dist/dev/jsx/mathml.d.ts +8 -2
  52. package/dist/dev/jsx/svg.d.ts +13 -2
  53. package/dist/dev/jsx/types.d.ts +1 -2
  54. package/dist/dev/jsx-dev-runtime.d.ts +6 -0
  55. package/dist/dev/jsx-runtime.d.ts +13 -2
  56. package/dist/dev/reactive.d.ts +1 -2
  57. package/dist/dev/render.d.ts +1 -2
  58. package/dist/dev/resource-hints.d.ts +1 -2
  59. package/dist/dev/select-value.d.ts +1 -2
  60. package/dist/dev/server/attributes.d.ts +1 -2
  61. package/dist/dev/server/class-style.d.ts +1 -2
  62. package/dist/dev/server/component.d.ts +1 -2
  63. package/dist/dev/server/derived.d.ts +1 -2
  64. package/dist/dev/server/element.d.ts +1 -2
  65. package/dist/dev/server/errors.js.map +1 -1
  66. package/dist/dev/server/escape.d.ts +1 -2
  67. package/dist/dev/server/form-controls.d.ts +1 -2
  68. package/dist/dev/server/hydration-script.d.ts +1 -2
  69. package/dist/dev/server/index.d.ts +7 -2
  70. package/dist/dev/server/index.js +2 -2
  71. package/dist/dev/server/node.d.ts +1 -2
  72. package/dist/dev/server/node.js.map +1 -1
  73. package/dist/dev/server/portals.d.ts +1 -2
  74. package/dist/dev/server/portals.js.map +1 -1
  75. package/dist/dev/server/raw-text.d.ts +1 -2
  76. package/dist/dev/server/render.d.ts +1 -2
  77. package/dist/dev/server/serialize.d.ts +1 -2
  78. package/dist/dev/server/stream.d.ts +1 -2
  79. package/dist/dev/server/stream.js.map +1 -1
  80. package/dist/dev/server.d.ts +1 -0
  81. package/dist/dev/spread.d.ts +1 -2
  82. package/dist/dev/template.d.ts +1 -2
  83. package/dist/dev/view-transition.d.ts +1 -2
  84. package/dist/prod/attributes.js.map +1 -1
  85. package/dist/prod/autofocus.js.map +1 -1
  86. package/dist/prod/class-style.js.map +1 -1
  87. package/dist/prod/component.js.map +1 -1
  88. package/dist/prod/control-flow/activity.js.map +1 -1
  89. package/dist/prod/control-flow/branch.js.map +1 -1
  90. package/dist/prod/control-flow/client-only.js.map +1 -1
  91. package/dist/prod/control-flow/dynamic.js.map +1 -1
  92. package/dist/prod/control-flow/error-boundary.js.map +1 -1
  93. package/dist/prod/control-flow/for.js.map +1 -1
  94. package/dist/prod/control-flow/fragment.js.map +1 -1
  95. package/dist/prod/control-flow/hot-link.js.map +1 -1
  96. package/dist/prod/control-flow/index-list.js.map +1 -1
  97. package/dist/prod/control-flow/lazy.js.map +1 -1
  98. package/dist/prod/control-flow/no-hydration.js.map +1 -1
  99. package/dist/prod/control-flow/portal.js.map +1 -1
  100. package/dist/prod/control-flow/root-errors.js.map +1 -1
  101. package/dist/prod/control-flow/show.js.map +1 -1
  102. package/dist/prod/control-flow/suspense-list.js.map +1 -1
  103. package/dist/prod/control-flow/suspense.js.map +1 -1
  104. package/dist/prod/control-flow/switch.js.map +1 -1
  105. package/dist/prod/derived.js.map +1 -1
  106. package/dist/prod/element.js.map +1 -1
  107. package/dist/prod/events.js.map +1 -1
  108. package/dist/prod/head/components.js.map +1 -1
  109. package/dist/prod/head/registry.js.map +1 -1
  110. package/dist/prod/head/server-head.js.map +1 -1
  111. package/dist/prod/head/sink.js.map +1 -1
  112. package/dist/prod/head/use-head.js.map +1 -1
  113. package/dist/prod/head/validate.js.map +1 -1
  114. package/dist/prod/hmr.js.map +1 -1
  115. package/dist/prod/hydration.js.map +1 -1
  116. package/dist/prod/insert.js.map +1 -1
  117. package/dist/prod/internal/accessor.js.map +1 -1
  118. package/dist/prod/internal/claim.js.map +1 -1
  119. package/dist/prod/internal/css-units.js.map +1 -1
  120. package/dist/prod/internal/diagnostics.js.map +1 -1
  121. package/dist/prod/internal/early-events.js.map +1 -1
  122. package/dist/prod/internal/hydration-hooks.js.map +1 -1
  123. package/dist/prod/internal/hydration-scope.js.map +1 -1
  124. package/dist/prod/internal/portal-context.js.map +1 -1
  125. package/dist/prod/internal/react-names.js.map +1 -1
  126. package/dist/prod/internal/reconcile.js.map +1 -1
  127. package/dist/prod/internal/stream-context.js.map +1 -1
  128. package/dist/prod/reactive.js.map +1 -1
  129. package/dist/prod/render.js.map +1 -1
  130. package/dist/prod/resource-hints.js.map +1 -1
  131. package/dist/prod/select-value.js.map +1 -1
  132. package/dist/prod/server/attributes.js.map +1 -1
  133. package/dist/prod/server/class-style.js.map +1 -1
  134. package/dist/prod/server/component.js.map +1 -1
  135. package/dist/prod/server/derived.js.map +1 -1
  136. package/dist/prod/server/element.js.map +1 -1
  137. package/dist/prod/server/errors.js.map +1 -1
  138. package/dist/prod/server/escape.js.map +1 -1
  139. package/dist/prod/server/form-controls.js.map +1 -1
  140. package/dist/prod/server/hydration-script.js.map +1 -1
  141. package/dist/prod/server/node.js.map +1 -1
  142. package/dist/prod/server/portals.js.map +1 -1
  143. package/dist/prod/server/raw-text.js.map +1 -1
  144. package/dist/prod/server/render.js.map +1 -1
  145. package/dist/prod/server/serialize.js.map +1 -1
  146. package/dist/prod/server/stream.js.map +1 -1
  147. package/dist/prod/spread.js.map +1 -1
  148. package/dist/prod/template.js.map +1 -1
  149. package/dist/prod/view-transition.js.map +1 -1
  150. package/dist/server/attributes.js.map +1 -1
  151. package/dist/server/autofocus.js.map +1 -1
  152. package/dist/server/class-style.js.map +1 -1
  153. package/dist/server/component.js.map +1 -1
  154. package/dist/server/control-flow/activity.js.map +1 -1
  155. package/dist/server/control-flow/branch.js.map +1 -1
  156. package/dist/server/control-flow/client-only.js.map +1 -1
  157. package/dist/server/control-flow/dynamic.js.map +1 -1
  158. package/dist/server/control-flow/error-boundary.js.map +1 -1
  159. package/dist/server/control-flow/for.js.map +1 -1
  160. package/dist/server/control-flow/fragment.js.map +1 -1
  161. package/dist/server/control-flow/index-list.js.map +1 -1
  162. package/dist/server/control-flow/lazy.js.map +1 -1
  163. package/dist/server/control-flow/no-hydration.js.map +1 -1
  164. package/dist/server/control-flow/portal.js.map +1 -1
  165. package/dist/server/control-flow/root-errors.js.map +1 -1
  166. package/dist/server/control-flow/show.js.map +1 -1
  167. package/dist/server/control-flow/suspense-list.js.map +1 -1
  168. package/dist/server/control-flow/suspense.js.map +1 -1
  169. package/dist/server/control-flow/switch.js.map +1 -1
  170. package/dist/server/derived.js.map +1 -1
  171. package/dist/server/element.js.map +1 -1
  172. package/dist/server/events.js.map +1 -1
  173. package/dist/server/head/components.js.map +1 -1
  174. package/dist/server/head/registry.js.map +1 -1
  175. package/dist/server/head/server-head.js.map +1 -1
  176. package/dist/server/head/sink.js.map +1 -1
  177. package/dist/server/head/use-head.js.map +1 -1
  178. package/dist/server/head/validate.js.map +1 -1
  179. package/dist/server/hydration.js.map +1 -1
  180. package/dist/server/insert.js.map +1 -1
  181. package/dist/server/internal/accessor.js.map +1 -1
  182. package/dist/server/internal/claim.js.map +1 -1
  183. package/dist/server/internal/css-units.js.map +1 -1
  184. package/dist/server/internal/diagnostics.js.map +1 -1
  185. package/dist/server/internal/early-events.js.map +1 -1
  186. package/dist/server/internal/hydration-hooks.js.map +1 -1
  187. package/dist/server/internal/hydration-scope.js.map +1 -1
  188. package/dist/server/internal/portal-context.js.map +1 -1
  189. package/dist/server/internal/react-names.js.map +1 -1
  190. package/dist/server/internal/reconcile.js.map +1 -1
  191. package/dist/server/internal/stream-context.js.map +1 -1
  192. package/dist/server/reactive.js.map +1 -1
  193. package/dist/server/render.js.map +1 -1
  194. package/dist/server/resource-hints.js.map +1 -1
  195. package/dist/server/select-value.js.map +1 -1
  196. package/dist/server/server/attributes.js.map +1 -1
  197. package/dist/server/server/class-style.js.map +1 -1
  198. package/dist/server/server/component.js.map +1 -1
  199. package/dist/server/server/derived.js.map +1 -1
  200. package/dist/server/server/element.js.map +1 -1
  201. package/dist/server/server/errors.js.map +1 -1
  202. package/dist/server/server/escape.js.map +1 -1
  203. package/dist/server/server/form-controls.js.map +1 -1
  204. package/dist/server/server/hydration-script.js.map +1 -1
  205. package/dist/server/server/node.js.map +1 -1
  206. package/dist/server/server/portals.js.map +1 -1
  207. package/dist/server/server/raw-text.js.map +1 -1
  208. package/dist/server/server/render.js.map +1 -1
  209. package/dist/server/server/serialize.js.map +1 -1
  210. package/dist/server/server/stream.js.map +1 -1
  211. package/dist/server/spread.js.map +1 -1
  212. package/dist/server/template.js.map +1 -1
  213. package/dist/server/view-transition.js.map +1 -1
  214. package/dist/server-dev/control-flow/portal.js.map +1 -1
  215. package/dist/server-dev/insert.js.map +1 -1
  216. package/dist/server-dev/internal/reconcile.js.map +1 -1
  217. package/dist/server-dev/server/errors.js.map +1 -1
  218. package/dist/server-dev/server/index.js +2 -2
  219. package/dist/server-dev/server/node.js.map +1 -1
  220. package/dist/server-dev/server/portals.js.map +1 -1
  221. package/dist/server-dev/server/stream.js.map +1 -1
  222. package/package.json +6 -6
@@ -1 +1 @@
1
- {"version":3,"file":"hydration-scope.js","names":["current","createRootScope","renderId","currentScope","withScope","previous","scope","fn","enterComponent","parent","nextKey","resourceKey","explicit","childScope","key"],"sources":["../../../src/internal/hydration-scope.ts"],"sourcesContent":["/**\n * A hydration scope: the deterministic source of hydration keys shared by the server renderer and\n * the client hydrator. Keys depend only on the nesting and order of component calls, never on owners,\n * effects or memos, so server and client agree as long as they run the same components. Scopes are\n * created by {@link createRootScope}, {@link enterComponent} and {@link childScope}; treat their\n * fields as read-only.\n *\n * @since 1.0.0\n */\nexport interface HydrationScope {\n /** Prefix of every key allocated in this scope, ending with `-` (`\"0-\"` for a root, `\"0-3-\"` below). */\n readonly id: string;\n /** Next number handed out by this scope: component scopes and template root keys share it. */\n count: number;\n /** Number of auto-keyed resources created directly in this scope so far. */\n resources: number;\n}\n\nlet current: HydrationScope | null = null;\n\n/**\n * Creates the scope a render or a hydration starts from: what `renderToString` and `hydrate()` put in\n * effect around the app. A custom renderer that hands out hydration keys does the same.\n *\n * @param renderId The prefix of every key of this render. Default: `\"0\"`, the default `renderId` of\n * the renderers.\n * @returns A fresh scope whose `id` is `` `${renderId}-` ``.\n * @example\n * import { createRootScope, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * const keys = withScope(createRootScope(\"app\"), () => [nextKey(), nextKey()]);\n * // [\"app-0\", \"app-1\"]\n * @see withScope\n * @since 1.0.0\n */\nexport function createRootScope(renderId = \"0\"): HydrationScope {\n return { id: `${renderId}-`, count: 0, resources: 0 };\n}\n\n/**\n * Returns the hydration scope in effect.\n *\n * @returns The current scope; `null` outside a server render, a hydration, or a {@link withScope}\n * call.\n * @example\n * import { currentScope } from \"@shadow-js/web/extend\";\n *\n * function scopeLabel(): string {\n * return currentScope()?.id ?? \"no scope\";\n * }\n * @since 1.0.0\n */\nexport function currentScope(): HydrationScope | null {\n return current;\n}\n\n/**\n * Runs `fn` with `scope` in effect, so the keys `fn` draws come from it. The previous scope is\n * restored when `fn` returns or throws.\n *\n * @param scope The scope to put in effect; `null` runs `fn` with no scope (no keys are drawn).\n * @param fn The code to run, synchronously, once.\n * @returns What `fn` returns. An error `fn` throws propagates.\n * @example\n * import { childScope, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * // The keys of an isolated subtree, independent of its siblings.\n * const first = withScope(childScope(\"0-4\"), () => nextKey()); // \"0-4-0\"\n * @see createRootScope\n * @since 1.0.0\n */\nexport function withScope<T>(scope: HydrationScope | null, fn: () => T): T {\n const previous = current;\n current = scope;\n try {\n return fn();\n } finally {\n current = previous;\n }\n}\n\n/**\n * Runs a component call in a scope of its own, so the keys it draws depend only on its position\n * among its parent's calls: what `createComponent` does on the client and on the server. The\n * component's scope takes the next number of the parent scope.\n *\n * @param fn The component call, run synchronously, once.\n * @returns What `fn` returns. Without a scope in effect, `fn` simply runs.\n * @example\n * import { createRootScope, enterComponent, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * withScope(createRootScope(), () => {\n * nextKey(); // \"0-0\"\n * return enterComponent(() => nextKey()); // \"0-1-0\": the component's first key\n * });\n * @since 1.0.0\n */\nexport function enterComponent<T>(fn: () => T): T {\n const parent = current;\n if (parent === null) return fn();\n return withScope({ id: `${parent.id}${parent.count++}-`, count: 0, resources: 0 }, fn);\n}\n\n/**\n * Draws the key of the next template root in the current scope: what `template()` and\n * `ssrHydrationKey()` call, in the same order on the server and the client. Each call advances the\n * scope.\n *\n * @returns The key (`\"0-0\"`, `\"0-1\"`, ...); undefined outside a scope.\n * @example\n * import { claimElement, nextKey } from \"@shadow-js/web/extend\";\n *\n * function createBadge(): Element {\n * return claimElement(nextKey()) ?? document.createElement(\"span\");\n * }\n * @see claimElement\n * @since 1.0.0\n */\nexport function nextKey(): string | undefined {\n const scope = current;\n if (scope === null) return undefined;\n return `${scope.id}${scope.count++}`;\n}\n\n/**\n * Returns the key a resource's value is stored under in the server data, the same on the server and\n * the client: the explicit key when there is one, else one drawn from the current scope.\n *\n * @param explicit The resource's own key. When given, the result is `` `k:${explicit}` ``, a prefix\n * no generated key has. Undefined draws the next resource key of the scope.\n * @returns `` `k:${explicit}` ``; otherwise the scope id, `r` and the creation index (`\"0-1-r0\"`);\n * `\"r\"` outside a scope.\n * @example\n * import { createRootScope, resourceKey, withScope } from \"@shadow-js/web/extend\";\n *\n * withScope(createRootScope(), () => [resourceKey(undefined), resourceKey(\"user\")]);\n * // [\"0-r0\", \"k:user\"]\n * @since 1.0.0\n */\nexport function resourceKey(explicit: string | undefined): string {\n if (explicit !== undefined) return `k:${explicit}`;\n const scope = current;\n if (scope === null) return \"r\";\n return `${scope.id}r${scope.resources++}`;\n}\n\n/**\n * Creates a fresh scope for an isolated part of the tree, such as a Suspense boundary's content or\n * fallback, or a portal's content: its keys depend only on `key`, not on the siblings around it.\n *\n * @param key The key of the boundary (from `nextKey()`); undefined means no scope.\n * @returns A scope whose `id` is `` `${key}-` ``; `null` when `key` is undefined.\n * @example\n * import { childScope, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * function renderIsolated<T>(build: () => T): T {\n * return withScope(childScope(nextKey()), build);\n * }\n * @see withScope\n * @since 1.0.0\n */\nexport function childScope(key: string | undefined): HydrationScope | null {\n return key === undefined ? null : { id: `${key}-`, count: 0, resources: 0 };\n}\n"],"mappings":"AAkBA,IAAIA,EAAiC,KAiBrC,SAAgBC,EAAgB,EAAW,IAAqB,CAC9D,MAAO,CAAE,GAAI,GAAGC,EAAS,GAAI,MAAO,EAAG,UAAW,CAAE,CACtD,CAeA,SAAgBC,GAAsC,CACpD,OAAOH,CACT,CAiBA,SAAgBI,EAAa,EAA8B,EAAgB,CACzE,IAAMC,EAAWL,EACjB,EAAUM,EACV,GAAI,CACF,OAAOC,EAAG,CACZ,QAAU,CACR,EAAUF,CACZ,CACF,CAkBA,SAAgBG,EAAkB,EAAgB,CAChD,IAAMC,EAAST,EAEf,OADIS,IAAW,KAAaF,EAAG,EACxBH,EAAU,CAAE,GAAI,GAAGK,EAAO,KAAK,EAAO,QAAQ,GAAI,MAAO,EAAG,UAAW,CAAE,EAAGF,CAAE,CACvF,CAiBA,SAAgBG,GAA8B,CAC5C,IAAMJ,EAAQN,EACd,GAAIM,IAAU,KACd,MAAO,GAAGA,EAAM,KAAK,EAAM,SAC7B,CAiBA,SAAgBK,EAAY,EAAsC,CAChE,GAAIC,IAAa,IAAA,GAAW,MAAO,KAAKA,IACxC,IAAMN,EAAQN,EAEd,OADIM,IAAU,KAAa,IACpB,GAAGA,EAAM,GAAG,GAAG,EAAM,aAC9B,CAiBA,SAAgBO,EAAW,EAAgD,CACzE,OAAOC,IAAQ,IAAA,GAAY,KAAO,CAAE,GAAI,GAAGA,EAAI,GAAI,MAAO,EAAG,UAAW,CAAE,CAC5E,C"}
1
+ {"version":3,"file":"hydration-scope.js","names":["current","createRootScope","renderId","currentScope","withScope","scope","fn","previous","enterComponent","parent","nextKey","resourceKey","explicit","childScope","key"],"sources":["../../../src/internal/hydration-scope.ts"],"sourcesContent":["/**\n * A hydration scope: the deterministic source of hydration keys shared by the server renderer and\n * the client hydrator. Keys depend only on the nesting and order of component calls, never on owners,\n * effects or memos, so server and client agree as long as they run the same components. Scopes are\n * created by {@link createRootScope}, {@link enterComponent} and {@link childScope}; treat their\n * fields as read-only.\n *\n * @since 1.0.0\n */\nexport interface HydrationScope {\n /** Prefix of every key allocated in this scope, ending with `-` (`\"0-\"` for a root, `\"0-3-\"` below). */\n readonly id: string;\n /** Next number handed out by this scope: component scopes and template root keys share it. */\n count: number;\n /** Number of auto-keyed resources created directly in this scope so far. */\n resources: number;\n}\n\nlet current: HydrationScope | null = null;\n\n/**\n * Creates the scope a render or a hydration starts from: what `renderToString` and `hydrate()` put in\n * effect around the app. A custom renderer that hands out hydration keys does the same.\n *\n * @param renderId The prefix of every key of this render. Default: `\"0\"`, the default `renderId` of\n * the renderers.\n * @returns A fresh scope whose `id` is `` `${renderId}-` ``.\n * @example\n * import { createRootScope, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * const keys = withScope(createRootScope(\"app\"), () => [nextKey(), nextKey()]);\n * // [\"app-0\", \"app-1\"]\n * @see withScope\n * @since 1.0.0\n */\nexport function createRootScope(renderId = \"0\"): HydrationScope {\n return { id: `${renderId}-`, count: 0, resources: 0 };\n}\n\n/**\n * Returns the hydration scope in effect.\n *\n * @returns The current scope; `null` outside a server render, a hydration, or a {@link withScope}\n * call.\n * @example\n * import { currentScope } from \"@shadow-js/web/extend\";\n *\n * function scopeLabel(): string {\n * return currentScope()?.id ?? \"no scope\";\n * }\n * @since 1.0.0\n */\nexport function currentScope(): HydrationScope | null {\n return current;\n}\n\n/**\n * Runs `fn` with `scope` in effect, so the keys `fn` draws come from it. The previous scope is\n * restored when `fn` returns or throws.\n *\n * @param scope The scope to put in effect; `null` runs `fn` with no scope (no keys are drawn).\n * @param fn The code to run, synchronously, once.\n * @returns What `fn` returns. An error `fn` throws propagates.\n * @example\n * import { childScope, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * // The keys of an isolated subtree, independent of its siblings.\n * const first = withScope(childScope(\"0-4\"), () => nextKey()); // \"0-4-0\"\n * @see createRootScope\n * @since 1.0.0\n */\nexport function withScope<T>(scope: HydrationScope | null, fn: () => T): T {\n const previous = current;\n current = scope;\n try {\n return fn();\n } finally {\n current = previous;\n }\n}\n\n/**\n * Runs a component call in a scope of its own, so the keys it draws depend only on its position\n * among its parent's calls: what `createComponent` does on the client and on the server. The\n * component's scope takes the next number of the parent scope.\n *\n * @param fn The component call, run synchronously, once.\n * @returns What `fn` returns. Without a scope in effect, `fn` simply runs.\n * @example\n * import { createRootScope, enterComponent, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * withScope(createRootScope(), () => {\n * nextKey(); // \"0-0\"\n * return enterComponent(() => nextKey()); // \"0-1-0\": the component's first key\n * });\n * @since 1.0.0\n */\nexport function enterComponent<T>(fn: () => T): T {\n const parent = current;\n if (parent === null) return fn();\n return withScope({ id: `${parent.id}${parent.count++}-`, count: 0, resources: 0 }, fn);\n}\n\n/**\n * Draws the key of the next template root in the current scope: what `template()` and\n * `ssrHydrationKey()` call, in the same order on the server and the client. Each call advances the\n * scope.\n *\n * @returns The key (`\"0-0\"`, `\"0-1\"`, ...); undefined outside a scope.\n * @example\n * import { claimElement, nextKey } from \"@shadow-js/web/extend\";\n *\n * function createBadge(): Element {\n * return claimElement(nextKey()) ?? document.createElement(\"span\");\n * }\n * @see claimElement\n * @since 1.0.0\n */\nexport function nextKey(): string | undefined {\n const scope = current;\n if (scope === null) return undefined;\n return `${scope.id}${scope.count++}`;\n}\n\n/**\n * Returns the key a resource's value is stored under in the server data, the same on the server and\n * the client: the explicit key when there is one, else one drawn from the current scope.\n *\n * @param explicit The resource's own key. When given, the result is `` `k:${explicit}` ``, a prefix\n * no generated key has. Undefined draws the next resource key of the scope.\n * @returns `` `k:${explicit}` ``; otherwise the scope id, `r` and the creation index (`\"0-1-r0\"`);\n * `\"r\"` outside a scope.\n * @example\n * import { createRootScope, resourceKey, withScope } from \"@shadow-js/web/extend\";\n *\n * withScope(createRootScope(), () => [resourceKey(undefined), resourceKey(\"user\")]);\n * // [\"0-r0\", \"k:user\"]\n * @since 1.0.0\n */\nexport function resourceKey(explicit: string | undefined): string {\n if (explicit !== undefined) return `k:${explicit}`;\n const scope = current;\n if (scope === null) return \"r\";\n return `${scope.id}r${scope.resources++}`;\n}\n\n/**\n * Creates a fresh scope for an isolated part of the tree, such as a Suspense boundary's content or\n * fallback, or a portal's content: its keys depend only on `key`, not on the siblings around it.\n *\n * @param key The key of the boundary (from `nextKey()`); undefined means no scope.\n * @returns A scope whose `id` is `` `${key}-` ``; `null` when `key` is undefined.\n * @example\n * import { childScope, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * function renderIsolated<T>(build: () => T): T {\n * return withScope(childScope(nextKey()), build);\n * }\n * @see withScope\n * @since 1.0.0\n */\nexport function childScope(key: string | undefined): HydrationScope | null {\n return key === undefined ? null : { id: `${key}-`, count: 0, resources: 0 };\n}\n"],"mappings":"AAkBA,IAAIA,EAAiC,KAiBrC,SAAgBC,EAAgBC,EAAW,IAAqB,CAC9D,MAAO,CAAE,GAAI,GAAGA,EAAS,GAAI,MAAO,EAAG,UAAW,CAAE,CACtD,CAeA,SAAgBC,GAAsC,CACpD,OAAOH,CACT,CAiBA,SAAgBI,EAAaC,EAA8BC,EAAgB,CACzE,IAAMC,EAAWP,EACjBA,EAAUK,EACV,GAAI,CACF,OAAOC,EAAG,CACZ,QAAU,CACRN,EAAUO,CACZ,CACF,CAkBA,SAAgBC,EAAkBF,EAAgB,CAChD,IAAMG,EAAST,EAEf,OADIS,IAAW,KAAaH,EAAG,EACxBF,EAAU,CAAE,GAAI,GAAGK,EAAO,KAAKA,EAAO,QAAQ,GAAI,MAAO,EAAG,UAAW,CAAE,EAAGH,CAAE,CACvF,CAiBA,SAAgBI,GAA8B,CAC5C,IAAML,EAAQL,EACd,GAAIK,IAAU,KACd,MAAO,GAAGA,EAAM,KAAKA,EAAM,SAC7B,CAiBA,SAAgBM,EAAYC,EAAsC,CAChE,GAAIA,IAAa,IAAA,GAAW,MAAO,KAAKA,IACxC,IAAMP,EAAQL,EAEd,OADIK,IAAU,KAAa,IACpB,GAAGA,EAAM,GAAG,GAAGA,EAAM,aAC9B,CAiBA,SAAgBQ,EAAWC,EAAgD,CACzE,OAAOA,IAAQ,IAAA,GAAY,KAAO,CAAE,GAAI,GAAGA,EAAI,GAAI,MAAO,EAAG,UAAW,CAAE,CAC5E,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"portal-context.js","names":["PortalContext"],"sources":["../../../src/internal/portal-context.ts"],"sourcesContent":["import { type Context, createContext } from \"@shadow-js/core\";\n\n/**\n * Receives the markup of the portals a server render produces: what {@link PortalContext} provides\n * when the render was given a `portals` collector.\n * @since 1.0.0\n */\nexport interface PortalSink {\n /**\n * Records the markup of the portal with hydration key `key`. A key recorded again replaces the\n * earlier markup. Throws an `SsrError` whose `code` is `SSR_PORTAL_LIMIT` past 256 portals in one\n * render.\n */\n add(key: string, html: string): void;\n /**\n * Renders a `Portal`'s content into this sink under hydration key `key`. The collectors the\n * renderers provide have it; `Portal` calls it instead of importing the markup writer, so the\n * browser bundle of an app that uses `Portal` does not carry server rendering code. A sink without\n * it receives nothing from `Portal`.\n * @param key The portal's key, `undefined` when the render has no scope (nothing is written).\n * @param children Reads the content: a thunk, because it must be built inside the portal's scope.\n */\n render?(key: string | undefined, children: () => unknown): void;\n}\n\n/**\n * The context through which a server render hands portals their collector: the renderers provide it\n * when they are given a `portals` option (see `createServerPortals`). A custom portal reads it on the\n * server and records its markup under its hydration key, so the client's `claimPortal` adopts it.\n * Its value is `null` for every other render, and in the browser, where a portal writes nothing on\n * the server.\n *\n * @example\n * import { useContext } from \"@shadow-js/core\";\n * import { nextKey, PortalContext } from \"@shadow-js/web/extend\";\n * import { escape } from \"@shadow-js/web/server\";\n *\n * function ServerToast(props: { text: string }): null {\n * const key = nextKey();\n * const sink = useContext(PortalContext);\n * if (sink !== null && key !== undefined) sink.add(key, `<div role=\"status\">${escape(props.text)}</div>`);\n * return null;\n * }\n * @see claimPortal\n * @since 1.0.0\n */\nexport const PortalContext: Context<PortalSink | null> =\n /* @__PURE__ */ createContext<PortalSink | null>(null, {\n name: \"Portal\",\n });\n"],"mappings":"A,gDA8CA,MAAaA,EACK,kBAAiC,KAAM,CACrD,KAAM,QACR,CAAC,E"}
1
+ {"version":3,"file":"portal-context.js","names":["createContext","PortalContext"],"sources":["../../../src/internal/portal-context.ts"],"sourcesContent":["import { type Context, createContext } from \"@shadow-js/core\";\n\n/**\n * Receives the markup of the portals a server render produces: what {@link PortalContext} provides\n * when the render was given a `portals` collector.\n * @since 1.0.0\n */\nexport interface PortalSink {\n /**\n * Records the markup of the portal with hydration key `key`. A key recorded again replaces the\n * earlier markup. Throws an `SsrError` whose `code` is `SSR_PORTAL_LIMIT` past 256 portals in one\n * render.\n */\n add(key: string, html: string): void;\n /**\n * Renders a `Portal`'s content into this sink under hydration key `key`. The collectors the\n * renderers provide have it; `Portal` calls it instead of importing the markup writer, so the\n * browser bundle of an app that uses `Portal` does not carry server rendering code. A sink without\n * it receives nothing from `Portal`.\n * @param key The portal's key, `undefined` when the render has no scope (nothing is written).\n * @param children Reads the content: a thunk, because it must be built inside the portal's scope.\n */\n render?(key: string | undefined, children: () => unknown): void;\n}\n\n/**\n * The context through which a server render hands portals their collector: the renderers provide it\n * when they are given a `portals` option (see `createServerPortals`). A custom portal reads it on the\n * server and records its markup under its hydration key, so the client's `claimPortal` adopts it.\n * Its value is `null` for every other render, and in the browser, where a portal writes nothing on\n * the server.\n *\n * @example\n * import { useContext } from \"@shadow-js/core\";\n * import { nextKey, PortalContext } from \"@shadow-js/web/extend\";\n * import { escape } from \"@shadow-js/web/server\";\n *\n * function ServerToast(props: { text: string }): null {\n * const key = nextKey();\n * const sink = useContext(PortalContext);\n * if (sink !== null && key !== undefined) sink.add(key, `<div role=\"status\">${escape(props.text)}</div>`);\n * return null;\n * }\n * @see claimPortal\n * @since 1.0.0\n */\nexport const PortalContext: Context<PortalSink | null> =\n /* @__PURE__ */ createContext<PortalSink | null>(null, {\n name: \"Portal\",\n });\n"],"mappings":"A,gDA8CA,MAAaC,EACKD,kBAAiC,KAAM,CACrD,KAAM,QACR,CAAC,E"}
@@ -1 +1 @@
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
+ {"version":3,"file":"react-names.js","names":["SVG_PROPERTY_FAMILY","RENAMED","attributeName","name","svg","renamed","prefixed","letter","IGNORED_KEYS","REACT_EVENTS","CHANGE_ON_TYPES","eventPlan","attribute","tag","type","reactSpelling","capture","lower","planned","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,EAAcC,EAAcC,EAAsB,CAChE,IAAMC,EAAUJ,EAAQ,IAAIE,CAAI,EAChC,GAAIE,IAAY,IAAA,GAAW,OAAOA,EAClC,GAAI,CAACD,EAAK,OAAOD,EAAK,YAAY,EAClC,GAAIA,EAAK,SAAS,GAAG,EAAG,OAAOA,EAC/B,IAAMG,EAAW,2BAA2B,KAAKH,CAAI,EAGrD,OAFIG,IAAa,KACZN,EAAoB,KAAKG,CAAI,EAC3BA,EAAK,QAAQ,SAAWI,GAAW,IAAIA,EAAO,YAAY,GAAG,EADxBJ,EADd,GAAGG,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,EAAUC,EAAmBC,EAAaC,EAAgC,CACxF,IAAMC,EAAgB,WAAW,KAAKH,CAAS,EACzCI,EAAUD,GAAiBH,EAAU,SAAS,SAAS,EACvDK,EAAQL,EAAU,MAAM,EAAGI,EAAU,GAAoB,IAAA,EAAS,CAAC,CAAC,YAAY,EAClFE,EAAUD,EASd,OARIF,IACFG,EACED,IAAU,SACNJ,IAAQ,YAAeA,IAAQ,UAAYC,IAAS,MAAQ,CAACJ,EAAgB,KAAKI,CAAI,GACpF,QACA,SACDL,EAAa,IAAIQ,CAAK,GAAKA,GAE7B,CAAE,KAAMC,EAASF,UAAS,QAASD,GAAiBE,IAAU,SAAW,CAACD,CAAQ,CAC3F,CAoBA,SAAgBG,EAAgBhB,EAAciB,EAAyB,CACrE,MACE,oMAAmB,SAAS,IAAIjB,EAAK,EAAE,IAAOA,IAAS,UAAYiB,IAAU,cAEjF,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"reconcile.js","names":["keepFocus","root","at","active","run","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/**\n * Runs `run`, which moves nodes in the tree of `at` without `moveBefore`: a browser blurs a focused\n * element that `insertBefore` moves, so a focused element of that tree that lost the focus gets it\n * back, without scrolling. A text control keeps its selection across the move, and `focus()` keeps\n * it. The focused element is read once, before `run`.\n * @internal\n */\nexport function keepFocus(at: Node, run: () => void): void {\n const root = at.getRootNode() as Partial<DocumentOrShadowRoot>;\n const active = root.activeElement as HTMLElement | null | undefined;\n run();\n if (active != null && root.activeElement !== active) active.focus({ preventScroll: true });\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 (a focused element that the move\n * blurred gets the focus back). 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 // Without moveBefore, insertBefore blurs a focused element it moves: the focused element is read once\n // for the pass and gets the focus back (without scrolling) when the moves took it.\n const root = parent.getRootNode() as Partial<DocumentOrShadowRoot>;\n const active = movable ? null : (root.activeElement as HTMLElement | null | undefined);\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 if (active != null && root.activeElement !== active) active.focus({ preventScroll: true });\n}\n"],"mappings":"AAYA,SAAgBA,EAAU,EAAU,EAAuB,CACzD,IAAMC,EAAOC,EAAG,YAAY,EACtBC,EAASF,EAAK,cACpBG,EAAI,EACAD,GAAU,MAAQF,EAAK,gBAAkBE,GAAQA,EAAO,MAAM,CAAE,cAAe,EAAK,CAAC,CAC3F,CAGA,SAASE,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,GACjBE,EAAM,EACNC,EAAON,EAAM,OACjB,KAAOK,EAAMC,GAAM,CACjB,IAAMC,EAAUF,EAAMC,GAAS,EACjBJ,EAAOF,EAAMO,IACfH,EAAO,EAAMG,EAAS,EAC7B,EAAOA,CACd,CAEA,EAASJ,GAASH,EAAMK,EAAM,IAAM,GACpC,EAAMA,GAAOF,CACf,CACA,IAAIK,EAASR,EAAM,GAAG,EAAE,GAAK,GAC7B,KAAOQ,IAAW,IAChB,EAAON,EAAOM,GAAqBC,GAAU,EAC7C,EAASR,EAASO,EAEtB,CAuCA,SAAgBE,EACd,EACA,EACA,EACA,EACM,CACN,IAA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,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,CACIH,GAAU,MAAQF,EAAK,gBAAkBE,GAAQA,EAAO,MAAM,CAAE,cAAe,EAAK,CAAC,CAC3F,C"}
1
+ {"version":3,"file":"reconcile.js","names":["keepFocus","at","run","root","active","removeNode","parent","node","markLongestIncreasing","values","offset","marks","tails","previous","index","value","low","high","middle","cursor","reconcileNodes","prev","next","end","prevLength","nextLength","head","prevTail","nextTail","before","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/**\n * Runs `run`, which moves nodes in the tree of `at` without `moveBefore`: a browser blurs a focused\n * element that `insertBefore` moves, so a focused element of that tree that lost the focus gets it\n * back, without scrolling. A text control keeps its selection across the move, and `focus()` keeps\n * it. The focused element is read once, before `run`.\n * @internal\n */\nexport function keepFocus(at: Node, run: () => void): void {\n const root = at.getRootNode() as Partial<DocumentOrShadowRoot>;\n const active = root.activeElement as HTMLElement | null | undefined;\n run();\n if (active != null && root.activeElement !== active) active.focus({ preventScroll: true });\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 (a focused element that the move\n * blurred gets the focus back). 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 // Without moveBefore, insertBefore blurs a focused element it moves: the focused element is read once\n // for the pass and gets the focus back (without scrolling) when the moves took it.\n const root = parent.getRootNode() as Partial<DocumentOrShadowRoot>;\n const active = movable ? null : (root.activeElement as HTMLElement | null | undefined);\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 if (active != null && root.activeElement !== active) active.focus({ preventScroll: true });\n}\n"],"mappings":"AAYA,SAAgBA,EAAUC,EAAUC,EAAuB,CACzD,IAAMC,EAAOF,EAAG,YAAY,EACtBG,EAASD,EAAK,cACpBD,EAAI,EACAE,GAAU,MAAQD,EAAK,gBAAkBC,GAAQA,EAAO,MAAM,CAAE,cAAe,EAAK,CAAC,CAC3F,CAGA,SAASC,EAAWC,EAAcC,EAA8B,CAC1DA,IAAS,IAAA,IAAaA,EAAK,aAAeD,GAAQA,EAAO,YAAYC,CAAI,CAC/E,CAOA,SAASC,EAAsBC,EAA2BC,EAAgBC,EAAyB,CAEjG,IAAMC,EAAkB,CAAC,EACnBC,EAAqBJ,EAAO,QAAU,EAAE,EAC9C,IAAK,IAAIK,EAAQ,EAAGA,EAAQL,EAAO,OAAQK,GAAS,EAAG,CACrD,IAAMC,EAAQN,EAAOK,GACjBE,EAAM,EACNC,EAAOL,EAAM,OACjB,KAAOI,EAAMC,GAAM,CACjB,IAAMC,EAAUF,EAAMC,GAAS,EACjBR,EAAOG,EAAMM,IACfH,EAAOC,EAAME,EAAS,EAC7BD,EAAOC,CACd,CAEAL,EAASC,GAASF,EAAMI,EAAM,IAAM,GACpCJ,EAAMI,GAAOF,CACf,CACA,IAAIK,EAASP,EAAM,GAAG,EAAE,GAAK,GAC7B,KAAOO,IAAW,IAChBR,EAAOF,EAAOU,GAAqBT,GAAU,EAC7CS,EAASN,EAASM,EAEtB,CAuCA,SAAgBC,EACdd,EACAe,EACAC,EACAC,EACM,CACN,IAAMC,EAAaH,EAAK,OAClBI,EAAaH,EAAK,OAEpBI,EAAO,EACX,KAAOA,EAAOF,GAAcE,EAAOD,GAAcJ,EAAKK,KAAUJ,EAAKI,IAAOA,GAAQ,EACpF,IAAIC,E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,aAAeD,EAChCA,EAAyB,WAAWC,EAAM4B,CAAU,EAClD7B,EAAO,aAAaC,EAAM4B,CAAU,GAE3CA,EAAa5B,CACf,CACIH,GAAU,MAAQD,EAAK,gBAAkBC,GAAQA,EAAO,MAAM,CAAE,cAAe,EAAK,CAAC,CAC3F,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"stream-context.js","names":["StreamContext"],"sources":["../../../src/internal/stream-context.ts"],"sourcesContent":["import { type Context, createContext } from \"@shadow-js/core\";\n\n/**\n * A Suspense boundary whose content was not ready when the shell rendered: `renderToStream` calls\n * `rebuild` again each time a resource settles, and streams the markup once it is complete.\n * @since 1.0.0\n */\nexport interface StreamBoundary {\n /**\n * The boundary's hydration key. The shell must wrap the fallback in `<!--[b:ID-->` and `<!--]-->`\n * comments so the streamed chunk can replace it.\n */\n readonly id: string;\n /**\n * Renders the content again. Returns its final markup, or `null` when it is still pending, in which\n * case it has deferred itself again with {@link StreamSink.defer}.\n */\n rebuild(): string | null;\n}\n\n/**\n * Receives the boundaries that are still pending during a streaming render: what\n * {@link StreamContext} provides.\n * @since 1.0.0\n */\nexport interface StreamSink {\n /** Queues `boundary` to be rebuilt when the next resource settles. */\n defer(boundary: StreamBoundary): void;\n}\n\n/**\n * The context through which `renderToStream` lets a Suspense-like boundary defer its content: a\n * boundary that is pending in the shell renders its fallback between `<!--[b:ID-->` and `<!--]-->`\n * and defers a {@link StreamBoundary} to the sink. Its value is `null` for every other render (the\n * boundary then keeps its fallback).\n *\n * @example\n * import { useContext } from \"@shadow-js/core\";\n * import { StreamContext } from \"@shadow-js/web/extend\";\n *\n * function canStream(): boolean {\n * // Inside a component rendered by renderToStream.\n * return useContext(StreamContext) !== null;\n * }\n * @since 1.0.0\n */\nexport const StreamContext: Context<StreamSink | null> =\n /* @__PURE__ */ createContext<StreamSink | null>(null, {\n name: \"Stream\",\n });\n"],"mappings":"A,gDA8CA,MAAaA,EACK,kBAAiC,KAAM,CACrD,KAAM,QACR,CAAC,E"}
1
+ {"version":3,"file":"stream-context.js","names":["createContext","StreamContext"],"sources":["../../../src/internal/stream-context.ts"],"sourcesContent":["import { type Context, createContext } from \"@shadow-js/core\";\n\n/**\n * A Suspense boundary whose content was not ready when the shell rendered: `renderToStream` calls\n * `rebuild` again each time a resource settles, and streams the markup once it is complete.\n * @since 1.0.0\n */\nexport interface StreamBoundary {\n /**\n * The boundary's hydration key. The shell must wrap the fallback in `<!--[b:ID-->` and `<!--]-->`\n * comments so the streamed chunk can replace it.\n */\n readonly id: string;\n /**\n * Renders the content again. Returns its final markup, or `null` when it is still pending, in which\n * case it has deferred itself again with {@link StreamSink.defer}.\n */\n rebuild(): string | null;\n}\n\n/**\n * Receives the boundaries that are still pending during a streaming render: what\n * {@link StreamContext} provides.\n * @since 1.0.0\n */\nexport interface StreamSink {\n /** Queues `boundary` to be rebuilt when the next resource settles. */\n defer(boundary: StreamBoundary): void;\n}\n\n/**\n * The context through which `renderToStream` lets a Suspense-like boundary defer its content: a\n * boundary that is pending in the shell renders its fallback between `<!--[b:ID-->` and `<!--]-->`\n * and defers a {@link StreamBoundary} to the sink. Its value is `null` for every other render (the\n * boundary then keeps its fallback).\n *\n * @example\n * import { useContext } from \"@shadow-js/core\";\n * import { StreamContext } from \"@shadow-js/web/extend\";\n *\n * function canStream(): boolean {\n * // Inside a component rendered by renderToStream.\n * return useContext(StreamContext) !== null;\n * }\n * @since 1.0.0\n */\nexport const StreamContext: Context<StreamSink | null> =\n /* @__PURE__ */ createContext<StreamSink | null>(null, {\n name: \"Stream\",\n });\n"],"mappings":"A,gDA8CA,MAAaC,EACKD,kBAAiC,KAAM,CACrD,KAAM,QACR,CAAC,E"}
@@ -1 +1 @@
1
- {"version":3,"file":"reactive.js","names":["effect","apply","useRenderEffect","compute","memo","useMemo","fn","use","cleanup","untrack","el","arg","onCleanup","refTo","target","holder","getOwner"],"sources":["../../src/reactive.ts"],"sourcesContent":["import {\n type Cleanup,\n getOwner,\n onCleanup,\n untrack,\n useMemo,\n useRenderEffect,\n} from \"@shadow-js/core\";\n\n/**\n * Runs `fn` as a render effect: synchronously when created, and again when the signals it reads\n * change. It is the effect the compiler emits for DOM bindings; application code usually prefers\n * `useEffect`. A function returned by `fn` is its cleanup, run before the next run and when the\n * owner disposes. It never runs on the server, and in development an effect created outside an\n * owner warns `NO_OWNER_EFFECT`.\n *\n * @param fn Tracked body. Returns an optional cleanup function.\n * @example\n * import { createRoot, useSignal } from \"@shadow-js/core\";\n * import { effect } from \"@shadow-js/web\";\n *\n * const label = document.createElement(\"span\");\n * createRoot(() => {\n * const [name] = useSignal(\"Ada\");\n * effect(() => {\n * label.textContent = name(); // runs now, and again when name changes\n * });\n * });\n * @see memo\n * @since 1.0.0\n */\nexport function effect(fn: () => void | Cleanup): void;\n/**\n * Two-form render effect: `compute` is tracked and `apply` runs untracked with the new and the\n * previous value. A function returned by `apply` is its cleanup. Use it to keep the tracked reads\n * apart from the code that writes the DOM.\n *\n * @param compute Tracked. Its result is passed to `apply`.\n * @param apply Untracked. Receives the value and the previous value (`undefined` on the first run)\n * and returns an optional cleanup function.\n * @example\n * import { createRoot, useSignal } from \"@shadow-js/core\";\n * import { effect } from \"@shadow-js/web\";\n *\n * const title = document.createElement(\"h1\");\n * createRoot(() => {\n * const [text] = useSignal(\"Hello\");\n * effect(text, (value, previous) => {\n * title.textContent = value;\n * console.log(previous); // undefined on the first run\n * });\n * });\n * @see memo\n * @since 1.0.0\n */\nexport function effect<T>(\n compute: () => T,\n apply: (value: T, previous: T | undefined) => void | Cleanup,\n): void;\nexport function effect<T>(\n compute: () => T,\n apply?: (value: T, previous: T | undefined) => void | Cleanup,\n): void {\n if (apply === undefined) useRenderEffect(compute);\n else useRenderEffect(compute, apply);\n}\n\n/**\n * Creates a cached derivation that recomputes only when the signals it reads change. It is core's\n * `useMemo` under the short name the compiler emits.\n *\n * @param fn The computation. Tracked; its result is cached until a dependency changes.\n * @returns An accessor for the current value.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { memo } from \"@shadow-js/web\";\n *\n * function setup() {\n * const [count, setCount] = useSignal(2);\n * const doubled = memo(() => count() * 2);\n * setCount(4);\n * console.log(doubled()); // 8\n * }\n * @see effect\n * @since 1.0.0\n */\nexport function memo<T>(fn: () => T): () => T {\n return useMemo<T>(fn);\n}\n\n/**\n * Applies a directive: calls `fn(el, arg)` untracked, so a directive or a ref never subscribes the\n * surrounding effect to what it reads. A function returned by `fn` is a cleanup, run when the owner\n * disposes.\n *\n * @param fn The directive. Receives the element and the accessor of its argument.\n * @param el The element the directive applies to.\n * @param arg Accessor for the directive's argument. Undefined passes `undefined` through; the\n * directive reads the accessor where it wants to track it.\n * @example\n * import { use } from \"@shadow-js/web\";\n *\n * function tooltip(el: Element, text: () => string) {\n * el.setAttribute(\"title\", text());\n * }\n * const button = document.createElement(\"button\");\n * use(tooltip, button, () => \"Save the draft\");\n * @see refTo\n * @since 1.0.0\n */\nexport function use<T>(\n fn: (el: Element, arg: () => T) => unknown,\n el: Element,\n arg?: () => T,\n): void {\n const cleanup = untrack(() => fn(el, arg as () => T));\n // A ref callback may return a cleanup (React 19): it runs when the owner of the element is disposed.\n if (typeof cleanup === \"function\") onCleanup(cleanup as Cleanup);\n}\n\n/**\n * Fills a ref of any form the compiler accepts. A callback is called with the element (its returned\n * cleanup runs when the owner disposes). A `{ current }` object gets the element as `current`, and\n * `null` once the owner is disposed, as React's `useRef` objects do. Any other value is ignored.\n *\n * @param target The ref value: a callback, a `{ current }` object, or anything else (ignored).\n * @param el The element the ref receives.\n * @example\n * import { refTo } from \"@shadow-js/web\";\n *\n * const box = { current: null as HTMLDivElement | null };\n * const div = document.createElement(\"div\");\n * refTo(box, div);\n * console.log(box.current === div); // true\n * @see use\n * @since 1.0.0\n */\nexport function refTo(target: unknown, el: Element): void {\n if (typeof target === \"function\") {\n use(target as (node: Element, arg: () => unknown) => unknown, el);\n return;\n }\n if (target === null || typeof target !== \"object\" || !(\"current\" in target)) return;\n const holder = target as { current: unknown };\n holder.current = el;\n if (getOwner() !== null) {\n onCleanup(() => {\n holder.current = null;\n });\n }\n}\n"],"mappings":"A,yGA2DA,SAAgBA,EACd,EACA,EACM,CACFC,IAAU,IAAA,GAAWC,EAAgBC,CAAO,EAC3CD,EAAgBC,EAASF,CAAK,CACrC,CAqBA,SAAgBG,EAAQ,EAAsB,CAC5C,OAAOC,EAAWC,CAAE,CACtB,CAsBA,SAAgBC,EACd,EACA,EACA,EACM,CACN,IAAMC,EAAUC,MAAcH,EAAGI,EAAIC,CAAc,CAAC,EAEhD,OAAOH,GAAY,YAAYI,EAAUJ,CAAkB,CACjE,CAmBA,SAAgBK,EAAM,EAAiB,EAAmB,CACxD,GAAI,OAAOC,GAAW,WAAY,CAChCP,EAAIO,EAA0DJ,CAAE,EAChE,MACF,CACA,GAAuB,OAAOI,GAAW,WAArCA,GAAiD,EAAE,YAAaA,GAAS,OAC7E,IAAMC,EAASD,EACf,EAAO,QAAUJ,EACbM,EAAS,IAAM,MACjBJ,MAAgB,CACd,EAAO,QAAU,IACnB,CAAC,CAEL,C"}
1
+ {"version":3,"file":"reactive.js","names":["getOwner","onCleanup","untrack","useMemo","useRenderEffect","effect","compute","apply","memo","fn","use","el","arg","cleanup","refTo","target","holder"],"sources":["../../src/reactive.ts"],"sourcesContent":["import {\n type Cleanup,\n getOwner,\n onCleanup,\n untrack,\n useMemo,\n useRenderEffect,\n} from \"@shadow-js/core\";\n\n/**\n * Runs `fn` as a render effect: synchronously when created, and again when the signals it reads\n * change. It is the effect the compiler emits for DOM bindings; application code usually prefers\n * `useEffect`. A function returned by `fn` is its cleanup, run before the next run and when the\n * owner disposes. It never runs on the server, and in development an effect created outside an\n * owner warns `NO_OWNER_EFFECT`.\n *\n * @param fn Tracked body. Returns an optional cleanup function.\n * @example\n * import { createRoot, useSignal } from \"@shadow-js/core\";\n * import { effect } from \"@shadow-js/web\";\n *\n * const label = document.createElement(\"span\");\n * createRoot(() => {\n * const [name] = useSignal(\"Ada\");\n * effect(() => {\n * label.textContent = name(); // runs now, and again when name changes\n * });\n * });\n * @see memo\n * @since 1.0.0\n */\nexport function effect(fn: () => void | Cleanup): void;\n/**\n * Two-form render effect: `compute` is tracked and `apply` runs untracked with the new and the\n * previous value. A function returned by `apply` is its cleanup. Use it to keep the tracked reads\n * apart from the code that writes the DOM.\n *\n * @param compute Tracked. Its result is passed to `apply`.\n * @param apply Untracked. Receives the value and the previous value (`undefined` on the first run)\n * and returns an optional cleanup function.\n * @example\n * import { createRoot, useSignal } from \"@shadow-js/core\";\n * import { effect } from \"@shadow-js/web\";\n *\n * const title = document.createElement(\"h1\");\n * createRoot(() => {\n * const [text] = useSignal(\"Hello\");\n * effect(text, (value, previous) => {\n * title.textContent = value;\n * console.log(previous); // undefined on the first run\n * });\n * });\n * @see memo\n * @since 1.0.0\n */\nexport function effect<T>(\n compute: () => T,\n apply: (value: T, previous: T | undefined) => void | Cleanup,\n): void;\nexport function effect<T>(\n compute: () => T,\n apply?: (value: T, previous: T | undefined) => void | Cleanup,\n): void {\n if (apply === undefined) useRenderEffect(compute);\n else useRenderEffect(compute, apply);\n}\n\n/**\n * Creates a cached derivation that recomputes only when the signals it reads change. It is core's\n * `useMemo` under the short name the compiler emits.\n *\n * @param fn The computation. Tracked; its result is cached until a dependency changes.\n * @returns An accessor for the current value.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { memo } from \"@shadow-js/web\";\n *\n * function setup() {\n * const [count, setCount] = useSignal(2);\n * const doubled = memo(() => count() * 2);\n * setCount(4);\n * console.log(doubled()); // 8\n * }\n * @see effect\n * @since 1.0.0\n */\nexport function memo<T>(fn: () => T): () => T {\n return useMemo<T>(fn);\n}\n\n/**\n * Applies a directive: calls `fn(el, arg)` untracked, so a directive or a ref never subscribes the\n * surrounding effect to what it reads. A function returned by `fn` is a cleanup, run when the owner\n * disposes.\n *\n * @param fn The directive. Receives the element and the accessor of its argument.\n * @param el The element the directive applies to.\n * @param arg Accessor for the directive's argument. Undefined passes `undefined` through; the\n * directive reads the accessor where it wants to track it.\n * @example\n * import { use } from \"@shadow-js/web\";\n *\n * function tooltip(el: Element, text: () => string) {\n * el.setAttribute(\"title\", text());\n * }\n * const button = document.createElement(\"button\");\n * use(tooltip, button, () => \"Save the draft\");\n * @see refTo\n * @since 1.0.0\n */\nexport function use<T>(\n fn: (el: Element, arg: () => T) => unknown,\n el: Element,\n arg?: () => T,\n): void {\n const cleanup = untrack(() => fn(el, arg as () => T));\n // A ref callback may return a cleanup (React 19): it runs when the owner of the element is disposed.\n if (typeof cleanup === \"function\") onCleanup(cleanup as Cleanup);\n}\n\n/**\n * Fills a ref of any form the compiler accepts. A callback is called with the element (its returned\n * cleanup runs when the owner disposes). A `{ current }` object gets the element as `current`, and\n * `null` once the owner is disposed, as React's `useRef` objects do. Any other value is ignored.\n *\n * @param target The ref value: a callback, a `{ current }` object, or anything else (ignored).\n * @param el The element the ref receives.\n * @example\n * import { refTo } from \"@shadow-js/web\";\n *\n * const box = { current: null as HTMLDivElement | null };\n * const div = document.createElement(\"div\");\n * refTo(box, div);\n * console.log(box.current === div); // true\n * @see use\n * @since 1.0.0\n */\nexport function refTo(target: unknown, el: Element): void {\n if (typeof target === \"function\") {\n use(target as (node: Element, arg: () => unknown) => unknown, el);\n return;\n }\n if (target === null || typeof target !== \"object\" || !(\"current\" in target)) return;\n const holder = target as { current: unknown };\n holder.current = el;\n if (getOwner() !== null) {\n onCleanup(() => {\n holder.current = null;\n });\n }\n}\n"],"mappings":"A,yGA2DA,SAAgBK,EACdC,EACAC,EACM,CACFA,IAAU,IAAA,GAAWH,EAAgBE,CAAO,EAC3CF,EAAgBE,EAASC,CAAK,CACrC,CAqBA,SAAgBC,EAAQC,EAAsB,CAC5C,OAAON,EAAWM,CAAE,CACtB,CAsBA,SAAgBC,EACdD,EACAE,EACAC,EACM,CACN,IAAMC,EAAUX,MAAcO,EAAGE,EAAIC,CAAc,CAAC,EAEhD,OAAOC,GAAY,YAAYZ,EAAUY,CAAkB,CACjE,CAmBA,SAAgBC,EAAMC,EAAiBJ,EAAmB,CACxD,GAAI,OAAOI,GAAW,WAAY,CAChCL,EAAIK,EAA0DJ,CAAE,EAChE,MACF,CACA,GAAuB,OAAOI,GAAW,WAArCA,GAAiD,EAAE,YAAaA,GAAS,OAC7E,IAAMC,EAASD,EACfC,EAAO,QAAUL,EACbX,EAAS,IAAM,MACjBC,MAAgB,CACde,EAAO,QAAU,IACnB,CAAC,CAEL,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"render.js","names":["render","region","createRegion","container","stop","disposed","teardown","removeRegion","claims","withScope","batch","createRoot","dispose","options","attachRootErrors","bindRegion","untrack","code","flushSync","error","cleanupError"],"sources":["../../src/render.ts"],"sourcesContent":["import { batch, createRoot, flushSync, untrack } from \"@shadow-js/core\";\nimport { attachRootErrors, type RootErrorOptions } from \"./control-flow/root-errors\";\nimport { bindRegion, createRegion, removeRegion } from \"./insert\";\nimport { claims } from \"./internal/hydration-hooks\";\nimport { withScope } from \"./internal/hydration-scope\";\n\n/**\n * Options of {@link render}: the error reporters of the root.\n * @since 1.0.0\n */\nexport type RenderOptions = RootErrorOptions;\n\n/**\n * Mounts `code` into `container`. Creates an owner, inserts the output, flushes the effects, and\n * returns a dispose function that stops the owner and removes the nodes this call inserted. A\n * second render into the same container appends after the first.\n *\n * @param code Runs once, untracked, to build the tree (a component call, a node, text or an array).\n * Return an accessor (for example `() => count`) from it to make the root content reactive.\n * @param container Element, Document or DocumentFragment that receives the output.\n * @param options The root's error reporters (`onUncaughtError`, `onCaughtError`). Undefined sets\n * no reporter.\n * @returns A dispose function, safe to call more than once.\n * @example\n * import { createComponent, render } from \"@shadow-js/web\";\n *\n * function App() {\n * return \"Hello\";\n * }\n *\n * const dispose = render(\n * () => createComponent(App, {}),\n * document.getElementById(\"root\") as Element,\n * );\n * dispose(); // stops the root and removes the text it inserted\n * @see hydrate\n * @since 1.0.0\n */\nexport function render(\n code: () => unknown,\n container: Element | Document | DocumentFragment,\n options?: RenderOptions,\n): () => void {\n const region = createRegion(container, null, undefined);\n let stop: (() => void) | undefined;\n let disposed = false;\n const teardown = (): void => {\n if (disposed) return;\n disposed = true;\n stop?.();\n removeRegion(region);\n };\n // One batch around the build: effects (and anything a resource's batch would flush mid-build)\n // wait until the whole tree exists, so a Suspense boundary knows what is pending before its\n // content's effects are considered.\n // A fresh root never consumes the enclosing hydration pass's nodes or key sequence.\n try {\n claims.current.withoutClaiming(() =>\n withScope(null, () =>\n batch(() =>\n createRoot((dispose) => {\n stop = dispose;\n // An error nothing else took ends here; with onUncaughtError it is reported instead of thrown.\n if (options !== undefined) attachRootErrors(options);\n // The component tree is built once; only accessors inside the result stay reactive.\n bindRegion(region, untrack(code));\n }),\n ),\n ),\n );\n flushSync();\n } catch (error) {\n // The caller gets no dispose function from a render that throws (an effect of the first flush failed),\n // so the root must not stay alive with its DOM and effects.\n try {\n teardown();\n } catch (cleanupError) {\n throw new AggregateError(\n [error, cleanupError],\n __DEV__ ? \"render() failed and so did its teardown.\" : \"SHADOW_RENDER_ERRORS\",\n );\n }\n throw error;\n }\n return teardown;\n}\n"],"mappings":"A,mVAsCA,SAAgBA,EACd,EACA,EACA,EACY,CACZ,IAAMC,EAASC,EAAaC,EAAW,KAAM,IAAA,EAAS,EAClDC,EACAC,EAAW,GACTC,MAAuB,CACvBD,IACJ,EAAW,GACXD,IAAO,EACPG,EAAaN,CAAM,EACrB,EAKA,GAAI,CACFO,EAAO,QAAQ,oBACbC,EAAU,SACRC,MACEC,EAAY,GAAY,CACtB,EAAOC,EAEHC,IAAY,IAAA,IAAWC,EAAiBD,CAAO,EAEnDE,EAAWd,EAAQe,EAAQC,CAAI,CAAC,CAClC,CAAC,CACH,CACF,CACF,EACAC,EAAU,CACZ,OAASC,EAAO,CAGd,GAAI,CACFb,EAAS,CACX,OAASc,EAAc,CACrB,MAAU,eACR,CAACD,EAAOC,CAAY,EACmC,sBACzD,CACF,CACA,MAAMD,CACR,CACA,OAAOb,CACT,C"}
1
+ {"version":3,"file":"render.js","names":["attachRootErrors","bindRegion","createRegion","removeRegion","claims","withScope","batch","createRoot","flushSync","untrack","render","code","container","options","region","stop","disposed","teardown","dispose","error","cleanupError"],"sources":["../../src/render.ts"],"sourcesContent":["import { batch, createRoot, flushSync, untrack } from \"@shadow-js/core\";\nimport { attachRootErrors, type RootErrorOptions } from \"./control-flow/root-errors\";\nimport { bindRegion, createRegion, removeRegion } from \"./insert\";\nimport { claims } from \"./internal/hydration-hooks\";\nimport { withScope } from \"./internal/hydration-scope\";\n\n/**\n * Options of {@link render}: the error reporters of the root.\n * @since 1.0.0\n */\nexport type RenderOptions = RootErrorOptions;\n\n/**\n * Mounts `code` into `container`. Creates an owner, inserts the output, flushes the effects, and\n * returns a dispose function that stops the owner and removes the nodes this call inserted. A\n * second render into the same container appends after the first.\n *\n * @param code Runs once, untracked, to build the tree (a component call, a node, text or an array).\n * Return an accessor (for example `() => count`) from it to make the root content reactive.\n * @param container Element, Document or DocumentFragment that receives the output.\n * @param options The root's error reporters (`onUncaughtError`, `onCaughtError`). Undefined sets\n * no reporter.\n * @returns A dispose function, safe to call more than once.\n * @example\n * import { createComponent, render } from \"@shadow-js/web\";\n *\n * function App() {\n * return \"Hello\";\n * }\n *\n * const dispose = render(\n * () => createComponent(App, {}),\n * document.getElementById(\"root\") as Element,\n * );\n * dispose(); // stops the root and removes the text it inserted\n * @see hydrate\n * @since 1.0.0\n */\nexport function render(\n code: () => unknown,\n container: Element | Document | DocumentFragment,\n options?: RenderOptions,\n): () => void {\n const region = createRegion(container, null, undefined);\n let stop: (() => void) | undefined;\n let disposed = false;\n const teardown = (): void => {\n if (disposed) return;\n disposed = true;\n stop?.();\n removeRegion(region);\n };\n // One batch around the build: effects (and anything a resource's batch would flush mid-build)\n // wait until the whole tree exists, so a Suspense boundary knows what is pending before its\n // content's effects are considered.\n // A fresh root never consumes the enclosing hydration pass's nodes or key sequence.\n try {\n claims.current.withoutClaiming(() =>\n withScope(null, () =>\n batch(() =>\n createRoot((dispose) => {\n stop = dispose;\n // An error nothing else took ends here; with onUncaughtError it is reported instead of thrown.\n if (options !== undefined) attachRootErrors(options);\n // The component tree is built once; only accessors inside the result stay reactive.\n bindRegion(region, untrack(code));\n }),\n ),\n ),\n );\n flushSync();\n } catch (error) {\n // The caller gets no dispose function from a render that throws (an effect of the first flush failed),\n // so the root must not stay alive with its DOM and effects.\n try {\n teardown();\n } catch (cleanupError) {\n throw new AggregateError(\n [error, cleanupError],\n __DEV__ ? \"render() failed and so did its teardown.\" : \"SHADOW_RENDER_ERRORS\",\n );\n }\n throw error;\n }\n return teardown;\n}\n"],"mappings":"A,mVAsCA,SAAgBU,EACdC,EACAC,EACAC,EACY,CACZ,IAAMC,EAASZ,EAAaU,EAAW,KAAM,IAAA,EAAS,EAClDG,EACAC,EAAW,GACTC,MAAuB,CACvBD,IACJA,EAAW,GACXD,IAAO,EACPZ,EAAaW,CAAM,EACrB,EAKA,GAAI,CACFV,EAAO,QAAQ,oBACbC,EAAU,SACRC,MACEC,EAAYW,GAAY,CACtBH,EAAOG,EAEHL,IAAY,IAAA,IAAWb,EAAiBa,CAAO,EAEnDZ,EAAWa,EAAQL,EAAQE,CAAI,CAAC,CAClC,CAAC,CACH,CACF,CACF,EACAH,EAAU,CACZ,OAASW,EAAO,CAGd,GAAI,CACFF,EAAS,CACX,OAASG,EAAc,CACrB,MAAU,eACR,CAACD,EAAOC,CAAY,EACmC,sBACzD,CACF,CACA,MAAMD,CACR,CACA,OAAOF,CACT,C"}
@@ -1 +1 @@
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,SA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EAAYU,EAAWV,CAAU,CAAC,CAEjD,MAMAE,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
+ {"version":3,"file":"resource-hints.js","names":["useHead","isServer","checkUrl","href","url","carries","element","attributes","name","value","hint","tag","serverTag","same","existing","\"src\"","\"type\"","serverLink","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,SAASE,EAASC,EAAoB,CACpC,IAAMC,EAAM,IAAI,IAAID,EAAM,sBAAsB,EAChD,GAAIC,EAAI,WAAa,UAAYA,EAAI,WAAa,QAChD,MAA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GAAS,cAAgB,IAAA,GAAY,CAAC,EAAI,CAAE,YAAaA,EAAQ,WAAY,CAIxE,EACTF,EAAW,CACT,IAAK,gBACLd,OACA,GAAIgB,GAAS,cAAgB,IAAA,GAAY,CAAC,EAAI,CAAE,YAAaA,EAAQ,WAAY,CACnF,CAAC,CACH,CACF,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"select-value.js","names":["bound","listed","value","item","plainText","setSelectValue","select","keepWatchingCommits","apply","wanted","option"],"sources":["../../src/select-value.ts"],"sourcesContent":["import { keepWatchingCommits } from \"./insert\";\n\n/** The value each select was last given, which it takes again when its options change (see {@link setSelectValue}). */\nconst bound = new WeakMap<HTMLSelectElement, unknown>();\n\n/** 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`). The select\n * takes the value again whenever the nodes inside it change (the options of a `<For>`, a `<Show>` or an optgroup), so\n * options that arrive or are replaced after the value keep it selected.\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 // Options that arrive or are replaced after this call (a `<For>` inside the select) leave the browser's own pick, the\n // first option: the select takes its value again after each commit to its children, as React's does.\n if (!bound.has(select)) keepWatchingCommits(select, () => apply(select, bound.get(select)));\n bound.set(select, value);\n apply(select, value);\n}\n\nfunction apply(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":"A,kDAGA,MAAMA,kBAAQ,IAAI,QAGlB,SAASC,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,CAwBA,SAAgBG,EAAe,EAA2B,EAAsB,CAGzEL,EAAM,IAAIM,CAAM,GAAGC,EAAoBD,MAAcE,EAAMF,EAAQN,EAAM,IAAIM,CAAM,CAAC,CAAC,EAC1FN,EAAM,IAAIM,EAAQJ,CAAK,EACvBM,EAAMF,EAAQJ,CAAK,CACrB,CAEA,SAASM,EAAM,EAA2B,EAAsB,CAC9D,GAAIF,EAAO,UAAY,MAAM,QAAQJ,CAAK,EAAG,CAC3C,IAAMO,EAASR,EAAOC,CAAK,EAC3B,IAAK,IAAMQ,KAAU,MAAM,KAAKJ,EAAO,OAAO,EAAG,EAAO,SAAWG,EAAO,IAAIC,EAAO,KAAK,CAE5F,KACA,GAAO,MAAQN,EAAUF,CAAK,CAChC,C"}
1
+ {"version":3,"file":"select-value.js","names":["keepWatchingCommits","bound","listed","value","item","plainText","setSelectValue","select","apply","wanted","option"],"sources":["../../src/select-value.ts"],"sourcesContent":["import { keepWatchingCommits } from \"./insert\";\n\n/** The value each select was last given, which it takes again when its options change (see {@link setSelectValue}). */\nconst bound = new WeakMap<HTMLSelectElement, unknown>();\n\n/** 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`). The select\n * takes the value again whenever the nodes inside it change (the options of a `<For>`, a `<Show>` or an optgroup), so\n * options that arrive or are replaced after the value keep it selected.\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 // Options that arrive or are replaced after this call (a `<For>` inside the select) leave the browser's own pick, the\n // first option: the select takes its value again after each commit to its children, as React's does.\n if (!bound.has(select)) keepWatchingCommits(select, () => apply(select, bound.get(select)));\n bound.set(select, value);\n apply(select, value);\n}\n\nfunction apply(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":"A,kDAGA,MAAMC,kBAAQ,IAAI,QAGlB,SAASC,EAAOC,EAAwC,CACtD,OAAO,IAAI,IAAIA,EAAM,OAAQC,GAASA,GAAS,IAA0B,CAAC,CAAC,IAAI,MAAM,CAAC,CACxF,CAGA,SAAgBC,EAAUF,EAAwB,CAChD,OAAOA,GAAU,KAA8B,GAAK,OAAOA,CAAK,CAClE,CAwBA,SAAgBG,EAAeC,EAA2BJ,EAAsB,CAGzEF,EAAM,IAAIM,CAAM,GAAGP,EAAoBO,MAAcC,EAAMD,EAAQN,EAAM,IAAIM,CAAM,CAAC,CAAC,EAC1FN,EAAM,IAAIM,EAAQJ,CAAK,EACvBK,EAAMD,EAAQJ,CAAK,CACrB,CAEA,SAASK,EAAMD,EAA2BJ,EAAsB,CAC9D,GAAII,EAAO,UAAY,MAAM,QAAQJ,CAAK,EAAG,CAC3C,IAAMM,EAASP,EAAOC,CAAK,EAC3B,IAAK,IAAMO,KAAU,MAAM,KAAKH,EAAO,OAAO,EAAGG,EAAO,SAAWD,EAAO,IAAIC,EAAO,KAAK,CAE5F,KACAH,GAAO,MAAQF,EAAUF,CAAK,CAChC,C"}
@@ -1 +1 @@
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,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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
+ {"version":3,"file":"attributes.js","names":["invalid","escapeHtml","resolveValue","ATTRIBUTE_NAME","URL_ATTRIBUTES","ANIMATION_VALUE_ATTRIBUTES","ENUMERATED_ATTRIBUTES","UNSAFE_URL_PREFIXES","assertAttributeName","name","isEventName","lowerName","isStringValued","stripControls","text","kept","char","code","isUnsafeUrl","value","normalized","prefix","isUnsafeAttributeValue","attributeText","assertNotSymbol","ssrAttribute","isBoolean","resolved"],"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,MAAMG,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,EAAoBC,EAAoB,CACtD,GAAI,CAACN,EAAe,KAAKM,CAAI,EAC3B,MAAMT,EAAQ,yBAA0B,IAAIS,EAAK,iCAAiC,CAEtF,CAGA,SAAgBC,EAAYC,EAA4B,CACtD,OAAOA,EAAU,OAAS,GAAKA,EAAU,WAAW,IAAI,CAC1D,CAGA,SAASC,EAAeD,EAA4B,CAClD,OACEA,EAAU,WAAW,OAAO,GAC5BA,EAAU,WAAW,OAAO,GAC5BL,EAAsB,IAAIK,CAAS,CAEvC,CAGA,SAASE,EAAcC,EAAsB,CAC3C,IAAIC,EAAO,GACX,IAAK,IAAMC,KAAQF,EAAM,CACvB,IAAMG,EAAOD,EAAK,WAAW,CAAC,EAC1BC,EAAO,KAASA,EAAO,KAAQA,EAAO,OAAOF,GAAQC,EAC3D,CACA,OAAOD,CACT,CAGA,SAAgBG,EAAYC,EAAwB,CAClD,IAAMC,EAAaP,EAAcM,CAAK,CAAC,CAAC,KAAK,CAAC,CAAC,YAAY,EAC3D,OAAOZ,EAAoB,KAAMc,GAAWD,EAAW,WAAWC,CAAM,CAAC,CAC3E,CAGA,SAASC,EAAuBX,EAAmBQ,EAAwB,CAEzE,OADIf,EAAe,IAAIO,CAAS,EAAUO,EAAYC,CAAK,EACpDd,EAA2B,IAAIM,CAAS,GAAKQ,EAAM,MAAM,GAAG,CAAC,CAAC,KAAKD,CAAW,CACvF,CAGA,SAAgBK,EAAcZ,EAAmBQ,EAA+B,CAI9E,OAHIA,GAAU,KAAoC,KAC9CA,IAAU,GAAcP,EAAeD,CAAS,EAAI,QAAU,KAC9DQ,IAAU,GAAaP,EAAeD,CAAS,EAAI,OAAS,GACzD,OAAOQ,CAAK,CACrB,CAGA,SAASK,EAAgBL,EAAsB,CAC7C,GAAI,OAAOA,GAAU,SACnB,MAAMnB,EAAQ,4BAA6B,wCAAwC,CAEvF,CAkCA,SAAgByB,EAAahB,EAAcU,EAAgBO,EAAY,GAAe,CACpFlB,EAAoBC,CAAI,EACxB,IAAME,EAAYF,EAAK,YAAY,EACnC,GAAIC,EAAYC,CAAS,EAAG,MAAO,GACnC,IAAMgB,EAAWzB,EAAaiB,CAAK,EAEnC,GADAK,EAAgBG,CAAQ,EACpBD,EAAW,OAAOC,EAAW,IAAIlB,IAAS,GAC9C,IAAMK,EAAOS,EAAcZ,EAAWgB,CAAQ,EAI9C,OAHIb,IAAS,MAETQ,EAAuBX,EAAWG,CAAI,EAAU,GAC7C,IAAIL,EAAK,IAAIR,EAAWa,CAAI,EAAE,EACvC,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"class-style.js","names":["CSS_PROPERTY","collectClasses","frames","root","cursors","open","top","frame","cursor","done","item","resolveValue","parts","invalid","record","key","classText","resolved","value","ssrClass","text","escapeHtml","toCssProperty","name","kebab","letter","isSafeCssValue","quote","depth","escaped","char","collectDeclarations","source","out","isSsrNode","property","cssValueText","styleText","declarations","ssrStyle"],"sources":["../../../src/server/class-style.ts"],"sourcesContent":["import { cssValueText } from \"../internal/css-units\";\nimport { invalid } from \"./errors\";\nimport { escapeHtml, resolveValue } from \"./escape\";\nimport { isSsrNode } from \"./node\";\n\n/** A CSS property name: a custom property, or a lower-case name with an optional vendor dash. */\nconst CSS_PROPERTY = /^(--[A-Za-z0-9_-]+|-?[a-z][a-z0-9-]*)$/;\n\n/**\n * Appends the class names found in `root` to `parts`, clsx-style. Iterative: array nesting depth\n * is controlled by the caller, so it must not reach the call stack.\n * @internal\n */\nexport function collectClasses(root: unknown, parts: string[]): void {\n const frames: unknown[][] = [[root]];\n const cursors: number[] = [0];\n const open = new Set<unknown[]>();\n while (frames.length > 0) {\n const top = frames.length - 1;\n const frame = frames[top];\n const cursor = cursors[top] ?? 0;\n if (frame === undefined || cursor >= frame.length) {\n const done = frames.pop();\n if (done !== undefined) open.delete(done);\n cursors.pop();\n continue;\n }\n cursors[top] = cursor + 1;\n const item = resolveValue(frame[cursor]);\n if (Array.isArray(item)) {\n if (open.has(item)) throw new TypeError(\"A class array contains itself.\");\n open.add(item);\n frames.push(item);\n cursors.push(0);\n } else if (typeof item === \"string\") {\n if (item !== \"\") parts.push(item);\n } else if (typeof item === \"number\") {\n if (item !== 0 && !Number.isNaN(item)) parts.push(String(item));\n } else if (typeof item === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be a class name.\");\n } else if (item !== null && typeof item === \"object\") {\n const record = item as Record<string, unknown>;\n for (const key of Object.keys(record)) {\n if (key !== \"\" && resolveValue(record[key])) parts.push(key);\n }\n }\n }\n}\n\n/**\n * The class text for a class value, or \"\" when there is none. A string is used as it is.\n * @internal\n */\nexport function classText(value: unknown): string {\n const resolved = resolveValue(value);\n if (typeof resolved === \"string\") return resolved;\n if (resolved === null || resolved === undefined || resolved === false) return \"\";\n const parts: string[] = [];\n collectClasses(resolved, parts);\n return parts.join(\" \");\n}\n\n/**\n * Renders a `class` attribute from a class value: the helper the compiler's server output calls for\n * `class`, `className` and `classList`, with the same clsx rules as the client's `className`.\n *\n * @param value A string (used as is), or an array or object: non-empty strings, numbers other than\n * `0` and `NaN`, nested arrays, and the keys of objects whose value is truthy. Accessors, also\n * inside arrays and as object values, are called. `null`, `undefined` and `false` give no class.\n * @returns Markup such as `' class=\"a b\"'` (HTML-escaped), or `\"\"` when there are no classes.\n * @throws TypeError when an array contains itself, and `UNRECOGNIZED_INSERT_VALUE` for a symbol.\n * @example\n * import { ssrClass } from \"@shadow-js/web/server\";\n *\n * ssrClass([\"card\", { \"card--active\": true, hidden: false }]); // ' class=\"card card--active\"'\n * ssrClass(null); // \"\"\n * @see ssrStyle\n * @since 1.0.0\n */\nexport function ssrClass(value: unknown): string {\n const text = classText(value);\n return text === \"\" ? \"\" : ` class=\"${escapeHtml(text)}\"`;\n}\n\n/** Converts a camelCase style name to CSS, keeping custom properties; `ms` gets its dash. @internal */\nexport function toCssProperty(name: string): string {\n if (name.startsWith(\"--\")) return name;\n const kebab = name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n return kebab.startsWith(\"ms-\") ? `-${kebab}` : kebab;\n}\n\n/**\n * True when a value cannot end its own declaration. A `;`, `{` or `}` outside quotes and\n * parentheses would start another declaration or rule, so such a value is dropped. Unbalanced\n * quotes or parentheses are dropped too, because they would swallow the declarations after them.\n * @internal\n */\nexport function isSafeCssValue(text: string): boolean {\n let quote = \"\";\n let depth = 0;\n let escaped = false;\n for (const char of text) {\n if (escaped) {\n escaped = false;\n } else if (char === \"\\\\\") {\n escaped = true;\n } else if (quote !== \"\") {\n if (char === quote) quote = \"\";\n } else if (char === '\"' || char === \"'\") {\n quote = char;\n } else if (char === \"(\") {\n depth += 1;\n } else if (char === \")\") {\n depth = Math.max(0, depth - 1);\n } else if ((char === \";\" || char === \"{\" || char === \"}\") && depth === 0) {\n return false;\n }\n }\n return quote === \"\" && depth === 0 && !escaped;\n}\n\n/** Declarations for one style source, appended to `out` as raw (unescaped) CSS text. */\nfunction collectDeclarations(source: unknown, out: string[]): void {\n const value = resolveValue(source);\n if (value === null || value === undefined || value === false) return;\n if (typeof value === \"string\") {\n if (value !== \"\") out.push(value);\n return;\n }\n if (typeof value !== \"object\" || isSsrNode(value)) {\n throw invalid(\n \"UNRECOGNIZED_INSERT_VALUE\",\n \"A style must be a string, an object or an array of them.\",\n );\n }\n if (Array.isArray(value)) {\n for (const item of value) {\n const resolved = resolveValue(item);\n if (Array.isArray(resolved)) {\n throw new TypeError(\"ssrStyle(): a style array may not contain another array.\");\n }\n collectDeclarations(resolved, out);\n }\n return;\n }\n for (const key of Object.keys(value)) {\n const property = toCssProperty(key);\n if (!CSS_PROPERTY.test(property)) {\n throw invalid(\"INVALID_STYLE_PROPERTY\", `\"${key}\" is not a valid CSS property name.`);\n }\n const resolved = resolveValue(Reflect.get(value, key));\n if (resolved === null || resolved === undefined || resolved === false) continue;\n if (typeof resolved === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be a style value.\");\n }\n const text = cssValueText(property, resolved);\n if (!isSafeCssValue(text)) continue;\n out.push(`${property}:${text}`);\n }\n}\n\n/**\n * The declarations of a style value, joined with `;`, or \"\" when there are none. Later\n * declarations win in CSS, so earlier and later sources can be combined in order.\n * @internal\n */\nexport function styleText(value: unknown): string {\n const declarations: string[] = [];\n collectDeclarations(value, declarations);\n return declarations.join(\";\");\n}\n\n/**\n * Renders a `style` attribute from a style value: the helper the compiler's server output calls for\n * `style` and `style:` attributes. Sources in an array are written in order, so a later declaration\n * wins in CSS.\n *\n * @param value A string (written as is), an object of properties, or an array of strings and\n * objects (not nested). Object keys are camelCase (converted to kebab-case, `msTransform` gives\n * `-ms-transform`), kebab-case, or custom properties (`--gap`, kept). `null`, `undefined` and `false`\n * values are skipped; a number is in pixels unless it is `0`, the property is unitless (`opacity`,\n * `zIndex`, ...) or a custom property, as in React. A value that could end its own declaration (a\n * `;`, `{` or `}` outside quotes and parentheses, or an unbalanced quote or parenthesis) is dropped.\n * @returns Markup such as `' style=\"color:red\"'` (HTML-escaped), or `\"\"` when there is nothing to\n * write.\n * @throws TypeError `INVALID_STYLE_PROPERTY` for an invalid property name, `UNRECOGNIZED_INSERT_VALUE`\n * for a symbol or a value that is not a string, object or array, and a TypeError for a nested array.\n * @example\n * import { ssrStyle } from \"@shadow-js/web/server\";\n *\n * ssrStyle({ backgroundColor: \"red\", width: 10, \"--gap\": \"4px\" });\n * // ' style=\"background-color:red;width:10px;--gap:4px\"'\n * ssrStyle([{ color: \"red\" }, \"color: blue\"]); // the later declaration wins\n * @see ssrClass\n * @since 1.0.0\n */\nexport function ssrStyle(value: unknown): string {\n const text = styleText(value);\n return text === \"\" ? \"\" : ` style=\"${escapeHtml(text)}\"`;\n}\n"],"mappings":"A,+LAMA,MAAMA,EAAe,yCAOrB,SAAgBC,EAAe,EAAe,EAAuB,CACnE,IAAMC,EAAsB,CAAC,CAACC,CAAI,CAAC,EAC7BC,EAAoB,CAAC,CAAC,EACtBC,kBAAO,IAAI,IACjB,KAAOH,EAAO,OAAS,GAAG,CACxB,IAAMI,EAAMJ,EAAO,OAAS,EACtBK,EAAQL,EAAOI,GACfE,EAASJ,EAAQE,IAAQ,EAC/B,GAAIC,IAAU,IAAA,IAAaC,GAAUD,EAAM,OAAQ,CACjD,IAAME,EAAOP,EAAO,IAAI,EACpBO,IAAS,IAAA,IAAWJ,EAAK,OAAOI,CAAI,EACxCL,EAAQ,IAAI,EACZ,QACF,CACA,EAAQE,GAAOE,EAAS,EACxB,IAAME,EAAOC,EAAaJ,EAAMC,EAAO,EACvC,GAAI,MAAM,QAAQE,CAAI,EAAG,CACvB,GAAIL,EAAK,IAAIK,CAAI,EAAG,MAAU,UAAU,gCAAgC,EACxEL,EAAK,IAAIK,CAAI,EACbR,EAAO,KAAKQ,CAAI,EAChBN,EAAQ,KAAK,CAAC,CAChB,MAAO,GAAI,OAAOM,GAAS,SACrBA,IAAS,IAAIE,EAAM,KAAKF,CAAI,OAC3B,GAAI,OAAOA,GAAS,SACrBA,IAAS,GAAK,CAAC,OAAO,MAAMA,CAAI,GAAGE,EAAM,KAAK,OAAOF,CAAI,CAA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"}
1
+ {"version":3,"file":"class-style.js","names":["cssValueText","invalid","escapeHtml","resolveValue","isSsrNode","CSS_PROPERTY","collectClasses","root","parts","frames","cursors","open","top","frame","cursor","done","item","record","key","classText","value","resolved","ssrClass","text","toCssProperty","name","kebab","letter","isSafeCssValue","quote","depth","escaped","char","collectDeclarations","source","out","property","styleText","declarations","ssrStyle"],"sources":["../../../src/server/class-style.ts"],"sourcesContent":["import { cssValueText } from \"../internal/css-units\";\nimport { invalid } from \"./errors\";\nimport { escapeHtml, resolveValue } from \"./escape\";\nimport { isSsrNode } from \"./node\";\n\n/** A CSS property name: a custom property, or a lower-case name with an optional vendor dash. */\nconst CSS_PROPERTY = /^(--[A-Za-z0-9_-]+|-?[a-z][a-z0-9-]*)$/;\n\n/**\n * Appends the class names found in `root` to `parts`, clsx-style. Iterative: array nesting depth\n * is controlled by the caller, so it must not reach the call stack.\n * @internal\n */\nexport function collectClasses(root: unknown, parts: string[]): void {\n const frames: unknown[][] = [[root]];\n const cursors: number[] = [0];\n const open = new Set<unknown[]>();\n while (frames.length > 0) {\n const top = frames.length - 1;\n const frame = frames[top];\n const cursor = cursors[top] ?? 0;\n if (frame === undefined || cursor >= frame.length) {\n const done = frames.pop();\n if (done !== undefined) open.delete(done);\n cursors.pop();\n continue;\n }\n cursors[top] = cursor + 1;\n const item = resolveValue(frame[cursor]);\n if (Array.isArray(item)) {\n if (open.has(item)) throw new TypeError(\"A class array contains itself.\");\n open.add(item);\n frames.push(item);\n cursors.push(0);\n } else if (typeof item === \"string\") {\n if (item !== \"\") parts.push(item);\n } else if (typeof item === \"number\") {\n if (item !== 0 && !Number.isNaN(item)) parts.push(String(item));\n } else if (typeof item === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be a class name.\");\n } else if (item !== null && typeof item === \"object\") {\n const record = item as Record<string, unknown>;\n for (const key of Object.keys(record)) {\n if (key !== \"\" && resolveValue(record[key])) parts.push(key);\n }\n }\n }\n}\n\n/**\n * The class text for a class value, or \"\" when there is none. A string is used as it is.\n * @internal\n */\nexport function classText(value: unknown): string {\n const resolved = resolveValue(value);\n if (typeof resolved === \"string\") return resolved;\n if (resolved === null || resolved === undefined || resolved === false) return \"\";\n const parts: string[] = [];\n collectClasses(resolved, parts);\n return parts.join(\" \");\n}\n\n/**\n * Renders a `class` attribute from a class value: the helper the compiler's server output calls for\n * `class`, `className` and `classList`, with the same clsx rules as the client's `className`.\n *\n * @param value A string (used as is), or an array or object: non-empty strings, numbers other than\n * `0` and `NaN`, nested arrays, and the keys of objects whose value is truthy. Accessors, also\n * inside arrays and as object values, are called. `null`, `undefined` and `false` give no class.\n * @returns Markup such as `' class=\"a b\"'` (HTML-escaped), or `\"\"` when there are no classes.\n * @throws TypeError when an array contains itself, and `UNRECOGNIZED_INSERT_VALUE` for a symbol.\n * @example\n * import { ssrClass } from \"@shadow-js/web/server\";\n *\n * ssrClass([\"card\", { \"card--active\": true, hidden: false }]); // ' class=\"card card--active\"'\n * ssrClass(null); // \"\"\n * @see ssrStyle\n * @since 1.0.0\n */\nexport function ssrClass(value: unknown): string {\n const text = classText(value);\n return text === \"\" ? \"\" : ` class=\"${escapeHtml(text)}\"`;\n}\n\n/** Converts a camelCase style name to CSS, keeping custom properties; `ms` gets its dash. @internal */\nexport function toCssProperty(name: string): string {\n if (name.startsWith(\"--\")) return name;\n const kebab = name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n return kebab.startsWith(\"ms-\") ? `-${kebab}` : kebab;\n}\n\n/**\n * True when a value cannot end its own declaration. A `;`, `{` or `}` outside quotes and\n * parentheses would start another declaration or rule, so such a value is dropped. Unbalanced\n * quotes or parentheses are dropped too, because they would swallow the declarations after them.\n * @internal\n */\nexport function isSafeCssValue(text: string): boolean {\n let quote = \"\";\n let depth = 0;\n let escaped = false;\n for (const char of text) {\n if (escaped) {\n escaped = false;\n } else if (char === \"\\\\\") {\n escaped = true;\n } else if (quote !== \"\") {\n if (char === quote) quote = \"\";\n } else if (char === '\"' || char === \"'\") {\n quote = char;\n } else if (char === \"(\") {\n depth += 1;\n } else if (char === \")\") {\n depth = Math.max(0, depth - 1);\n } else if ((char === \";\" || char === \"{\" || char === \"}\") && depth === 0) {\n return false;\n }\n }\n return quote === \"\" && depth === 0 && !escaped;\n}\n\n/** Declarations for one style source, appended to `out` as raw (unescaped) CSS text. */\nfunction collectDeclarations(source: unknown, out: string[]): void {\n const value = resolveValue(source);\n if (value === null || value === undefined || value === false) return;\n if (typeof value === \"string\") {\n if (value !== \"\") out.push(value);\n return;\n }\n if (typeof value !== \"object\" || isSsrNode(value)) {\n throw invalid(\n \"UNRECOGNIZED_INSERT_VALUE\",\n \"A style must be a string, an object or an array of them.\",\n );\n }\n if (Array.isArray(value)) {\n for (const item of value) {\n const resolved = resolveValue(item);\n if (Array.isArray(resolved)) {\n throw new TypeError(\"ssrStyle(): a style array may not contain another array.\");\n }\n collectDeclarations(resolved, out);\n }\n return;\n }\n for (const key of Object.keys(value)) {\n const property = toCssProperty(key);\n if (!CSS_PROPERTY.test(property)) {\n throw invalid(\"INVALID_STYLE_PROPERTY\", `\"${key}\" is not a valid CSS property name.`);\n }\n const resolved = resolveValue(Reflect.get(value, key));\n if (resolved === null || resolved === undefined || resolved === false) continue;\n if (typeof resolved === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be a style value.\");\n }\n const text = cssValueText(property, resolved);\n if (!isSafeCssValue(text)) continue;\n out.push(`${property}:${text}`);\n }\n}\n\n/**\n * The declarations of a style value, joined with `;`, or \"\" when there are none. Later\n * declarations win in CSS, so earlier and later sources can be combined in order.\n * @internal\n */\nexport function styleText(value: unknown): string {\n const declarations: string[] = [];\n collectDeclarations(value, declarations);\n return declarations.join(\";\");\n}\n\n/**\n * Renders a `style` attribute from a style value: the helper the compiler's server output calls for\n * `style` and `style:` attributes. Sources in an array are written in order, so a later declaration\n * wins in CSS.\n *\n * @param value A string (written as is), an object of properties, or an array of strings and\n * objects (not nested). Object keys are camelCase (converted to kebab-case, `msTransform` gives\n * `-ms-transform`), kebab-case, or custom properties (`--gap`, kept). `null`, `undefined` and `false`\n * values are skipped; a number is in pixels unless it is `0`, the property is unitless (`opacity`,\n * `zIndex`, ...) or a custom property, as in React. A value that could end its own declaration (a\n * `;`, `{` or `}` outside quotes and parentheses, or an unbalanced quote or parenthesis) is dropped.\n * @returns Markup such as `' style=\"color:red\"'` (HTML-escaped), or `\"\"` when there is nothing to\n * write.\n * @throws TypeError `INVALID_STYLE_PROPERTY` for an invalid property name, `UNRECOGNIZED_INSERT_VALUE`\n * for a symbol or a value that is not a string, object or array, and a TypeError for a nested array.\n * @example\n * import { ssrStyle } from \"@shadow-js/web/server\";\n *\n * ssrStyle({ backgroundColor: \"red\", width: 10, \"--gap\": \"4px\" });\n * // ' style=\"background-color:red;width:10px;--gap:4px\"'\n * ssrStyle([{ color: \"red\" }, \"color: blue\"]); // the later declaration wins\n * @see ssrClass\n * @since 1.0.0\n */\nexport function ssrStyle(value: unknown): string {\n const text = styleText(value);\n return text === \"\" ? \"\" : ` style=\"${escapeHtml(text)}\"`;\n}\n"],"mappings":"A,+LAMA,MAAMK,EAAe,yCAOrB,SAAgBC,EAAeC,EAAeC,EAAuB,CACnE,IAAMC,EAAsB,CAAC,CAACF,CAAI,CAAC,EAC7BG,EAAoB,CAAC,CAAC,EACtBC,kBAAO,IAAI,IACjB,KAAOF,EAAO,OAAS,GAAG,CACxB,IAAMG,EAAMH,EAAO,OAAS,EACtBI,EAAQJ,EAAOG,GACfE,EAASJ,EAAQE,IAAQ,EAC/B,GAAIC,IAAU,IAAA,IAAaC,GAAUD,EAAM,OAAQ,CACjD,IAAME,EAAON,EAAO,IAAI,EACpBM,IAAS,IAAA,IAAWJ,EAAK,OAAOI,CAAI,EACxCL,EAAQ,IAAI,EACZ,QACF,CACAA,EAAQE,GAAOE,EAAS,EACxB,IAAME,EAAOb,EAAaU,EAAMC,EAAO,EACvC,GAAI,MAA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aoC,EAAUf,CAAQ,EACvCO,EAAeL,CAAI,GACxBY,EAAI,KAAK,GAAGC,EAAS,GAAGb,GAAM,CAChC,CAzBE,CALF,CA+BF,CAOA,SAAgBc,EAAUjB,EAAwB,CAChD,IAAMkB,EAAyB,CAAC,EAEhC,OADAL,EAAoBb,EAAOkB,CAAY,EAChCA,EAAa,KAAK,GAAG,CAC9B,CA0BA,SAAgBC,EAASnB,EAAwB,CAC/C,IAAMG,EAAOc,EAAUjB,CAAK,EAC5B,OAAOG,IAAS,GAAK,GAAK,WAAWrB,EAAWqB,CAAI,EAAE,EACxD,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"component.js","names":["createComponent","component","enterComponent","owner","createOwner","currentScope","runInScope","props","memo","slot","running","value","untrack","fn"],"sources":["../../../src/server/component.ts"],"sourcesContent":["import { untrack } from \"@shadow-js/core\";\nimport { createOwner, runInScope } from \"@shadow-js/core/extend\";\nimport { currentScope, enterComponent } from \"../internal/hydration-scope\";\n\n/**\n * Calls a component on the server, untracked, with its own owner and hydration scope, so the\n * hydration keys it hands out depend only on where it sits in the tree. The server twin of the client\n * `createComponent`: compiled server output calls it for `<Component />`, and a hand-written render\n * entry calls it for the root component.\n *\n * @param component The component function.\n * @param props The props object; reactive props are getters.\n * @returns Whatever the component returns.\n * @throws TypeError when `component` is not a function. An error the component throws propagates.\n * @example\n * import { createComponent, renderToString } from \"@shadow-js/web/server\";\n *\n * function Card(props: { title: string }) {\n * return <h2>{props.title}</h2>;\n * }\n * const html = renderToString(() => createComponent(Card, { title: \"Hello\" }));\n * @since 1.0.0\n */\nexport function createComponent<P>(component: (props: P) => unknown, props: P): unknown {\n if (typeof component !== \"function\") {\n throw new TypeError(\"createComponent(): the component must be a function.\");\n }\n return enterComponent(() => {\n // The same owner structure as the browser, so `useId` prefixes agree (see the DOM createComponent).\n const owner = createOwner();\n owner.idPrefix = currentScope()?.id;\n // One scope switch (owner in, listener off): deep component trees are bounded by the call stack.\n return runInScope({ owner, listener: null }, () => component(props));\n });\n}\n\n/**\n * The server twin of `memo`: nothing is reactive during a server render, so it computes once, on the\n * first read, and returns the cached value on every later read. A call that throws is not cached\n * (the next read runs `fn` again).\n *\n * @param fn The computation; runs untracked, on the first read.\n * @returns An accessor of the cached value.\n * @throws TypeError from the accessor when `fn` reads the accessor itself while it runs, instead of\n * recursing. An error `fn` throws propagates from the read.\n * @example\n * import { memo } from \"@shadow-js/web/server\";\n *\n * const items = [3, 1, 2];\n * const sorted = memo(() => [...items].sort());\n * sorted(); // [1, 2, 3], computed now\n * sorted(); // the same array, cached\n * @since 1.0.0\n */\nexport function memo<T>(fn: () => T): () => T {\n let slot: { readonly value: T } | undefined;\n let running = false;\n return () => {\n if (slot !== undefined) return slot.value;\n if (running) throw new TypeError(\"memo(): the computation read itself.\");\n running = true;\n try {\n const value = untrack(fn);\n slot = { value };\n return value;\n } finally {\n running = false;\n }\n };\n}\n"],"mappings":"A,iMAuBA,SAAgBA,EAAmB,EAAkC,EAAmB,CACtF,GAAI,OAAOC,GAAc,WACvB,MAAU,UAAU,sDAAsD,EAE5E,OAAOC,MAAqB,CAE1B,IAAMC,EAAQC,EAAY,EAG1B,MAFA,GAAM,SAAWC,EAAa,CAAC,EAAE,GAE1BC,EAAW,CAAE,QAAO,SAAU,IAAK,MAASL,EAAUM,CAAK,CAAC,CACrE,CAAC,CACH,CAoBA,SAAgBC,EAAQ,EAAsB,CAC5C,IAAIC,EACAC,EAAU,GACd,UAAa,CACX,GAAID,IAAS,IAAA,GAAW,OAAOA,EAAK,MACpC,GAAIC,EAAS,MAAU,UAAU,sCAAsC,EACvE,EAAU,GACV,GAAI,CACF,IAAMC,EAAQC,EAAQC,CAAE,EAExB,MADA,GAAO,CAAE,OAAM,EACRF,CACT,QAAU,CACR,EAAU,EACZ,CACF,CACF,C"}
1
+ {"version":3,"file":"component.js","names":["currentScope","enterComponent","untrack","createOwner","runInScope","createComponent","component","props","owner","memo","fn","slot","running","value"],"sources":["../../../src/server/component.ts"],"sourcesContent":["import { untrack } from \"@shadow-js/core\";\nimport { createOwner, runInScope } from \"@shadow-js/core/extend\";\nimport { currentScope, enterComponent } from \"../internal/hydration-scope\";\n\n/**\n * Calls a component on the server, untracked, with its own owner and hydration scope, so the\n * hydration keys it hands out depend only on where it sits in the tree. The server twin of the client\n * `createComponent`: compiled server output calls it for `<Component />`, and a hand-written render\n * entry calls it for the root component.\n *\n * @param component The component function.\n * @param props The props object; reactive props are getters.\n * @returns Whatever the component returns.\n * @throws TypeError when `component` is not a function. An error the component throws propagates.\n * @example\n * import { createComponent, renderToString } from \"@shadow-js/web/server\";\n *\n * function Card(props: { title: string }) {\n * return <h2>{props.title}</h2>;\n * }\n * const html = renderToString(() => createComponent(Card, { title: \"Hello\" }));\n * @since 1.0.0\n */\nexport function createComponent<P>(component: (props: P) => unknown, props: P): unknown {\n if (typeof component !== \"function\") {\n throw new TypeError(\"createComponent(): the component must be a function.\");\n }\n return enterComponent(() => {\n // The same owner structure as the browser, so `useId` prefixes agree (see the DOM createComponent).\n const owner = createOwner();\n owner.idPrefix = currentScope()?.id;\n // One scope switch (owner in, listener off): deep component trees are bounded by the call stack.\n return runInScope({ owner, listener: null }, () => component(props));\n });\n}\n\n/**\n * The server twin of `memo`: nothing is reactive during a server render, so it computes once, on the\n * first read, and returns the cached value on every later read. A call that throws is not cached\n * (the next read runs `fn` again).\n *\n * @param fn The computation; runs untracked, on the first read.\n * @returns An accessor of the cached value.\n * @throws TypeError from the accessor when `fn` reads the accessor itself while it runs, instead of\n * recursing. An error `fn` throws propagates from the read.\n * @example\n * import { memo } from \"@shadow-js/web/server\";\n *\n * const items = [3, 1, 2];\n * const sorted = memo(() => [...items].sort());\n * sorted(); // [1, 2, 3], computed now\n * sorted(); // the same array, cached\n * @since 1.0.0\n */\nexport function memo<T>(fn: () => T): () => T {\n let slot: { readonly value: T } | undefined;\n let running = false;\n return () => {\n if (slot !== undefined) return slot.value;\n if (running) throw new TypeError(\"memo(): the computation read itself.\");\n running = true;\n try {\n const value = untrack(fn);\n slot = { value };\n return value;\n } finally {\n running = false;\n }\n };\n}\n"],"mappings":"A,iMAuBA,SAAgBK,EAAmBC,EAAkCC,EAAmB,CACtF,GAAI,OAAOD,GAAc,WACvB,MAAU,UAAU,sDAAsD,EAE5E,OAAOL,MAAqB,CAE1B,IAAMO,EAAQL,EAAY,EAG1B,MAFAK,GAAM,SAAWR,EAAa,CAAC,EAAE,GAE1BI,EAAW,CAAEI,QAAO,SAAU,IAAK,MAASF,EAAUC,CAAK,CAAC,CACrE,CAAC,CACH,CAoBA,SAAgBE,EAAQC,EAAsB,CAC5C,IAAIC,EACAC,EAAU,GACd,UAAa,CACX,GAAID,IAAS,IAAA,GAAW,OAAOA,EAAK,MACpC,GAAIC,EAAS,MAAU,UAAU,sCAAsC,EACvEA,EAAU,GACV,GAAI,CACF,IAAMC,EAAQX,EAAQQ,CAAE,EAExB,MADAC,GAAO,CAAEE,OAAM,EACRA,CACT,QAAU,CACRD,EAAU,EACZ,CACF,CACF,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"derived.js","names":["derived","current","compute","read","args"],"sources":["../../../src/server/derived.ts"],"sourcesContent":["/**\n * The server twin of the client `Derived`: what {@link derived} returns. Nothing is reactive on the\n * server, so it holds the value computed once. Read it as `x.value` or call it as `x()`.\n *\n * @example\n * import { derived } from \"@shadow-js/web/server\";\n *\n * const total = derived(() => 20 * 3);\n * total.value; // 60\n * total(); // 60\n * @see derived\n * @since 1.0.0\n */\nexport interface Derived<T> {\n /**\n * Returns the value. When the value is a function, calls it with `args` and returns its result\n * instead, so a derived function stays callable.\n */\n (...args: unknown[]): unknown;\n /** The value `compute` returned. */\n readonly value: T;\n}\n\n/**\n * The server twin of the client `derived`, which the compiler emits for `const x = <expression\n * reading signals>` inside a component. On the server it calls `compute` once, immediately, and\n * returns a constant {@link Derived}.\n *\n * @param compute The computation. Runs once, when `derived` is called; an error it throws propagates.\n * @returns A {@link Derived} holding the result.\n * @example\n * import { derived } from \"@shadow-js/web/server\";\n *\n * const greeting = derived(() => (name: string) => `Hello, ${name}`);\n * greeting(\"Ada\"); // \"Hello, Ada\": a derived function stays callable\n * @see Derived\n * @since 1.0.0\n */\nexport function derived<T>(compute: () => T): Derived<T> {\n const current = compute();\n const read = ((...args: unknown[]): unknown =>\n typeof current === \"function\"\n ? (current as (...a: unknown[]) => unknown)(...args)\n : current) as {\n (...args: unknown[]): unknown;\n value: T;\n };\n Object.defineProperty(read, \"value\", { value: current });\n return read as Derived<T>;\n}\n"],"mappings":"AAsCA,SAAgBA,EAAW,EAA8B,CACvD,IAAMC,EAAUC,EAAQ,EAClBC,IAAS,GAAGC,IAChB,OAAOH,GAAY,WACdA,EAAyC,GAAGG,CAAI,EACjDH,GAKN,OADA,OAAO,eAAeE,EAAM,QAAS,CAAE,MAAOF,CAAQ,CAAC,EAChDE,CACT,C"}
1
+ {"version":3,"file":"derived.js","names":["derived","compute","current","read","args"],"sources":["../../../src/server/derived.ts"],"sourcesContent":["/**\n * The server twin of the client `Derived`: what {@link derived} returns. Nothing is reactive on the\n * server, so it holds the value computed once. Read it as `x.value` or call it as `x()`.\n *\n * @example\n * import { derived } from \"@shadow-js/web/server\";\n *\n * const total = derived(() => 20 * 3);\n * total.value; // 60\n * total(); // 60\n * @see derived\n * @since 1.0.0\n */\nexport interface Derived<T> {\n /**\n * Returns the value. When the value is a function, calls it with `args` and returns its result\n * instead, so a derived function stays callable.\n */\n (...args: unknown[]): unknown;\n /** The value `compute` returned. */\n readonly value: T;\n}\n\n/**\n * The server twin of the client `derived`, which the compiler emits for `const x = <expression\n * reading signals>` inside a component. On the server it calls `compute` once, immediately, and\n * returns a constant {@link Derived}.\n *\n * @param compute The computation. Runs once, when `derived` is called; an error it throws propagates.\n * @returns A {@link Derived} holding the result.\n * @example\n * import { derived } from \"@shadow-js/web/server\";\n *\n * const greeting = derived(() => (name: string) => `Hello, ${name}`);\n * greeting(\"Ada\"); // \"Hello, Ada\": a derived function stays callable\n * @see Derived\n * @since 1.0.0\n */\nexport function derived<T>(compute: () => T): Derived<T> {\n const current = compute();\n const read = ((...args: unknown[]): unknown =>\n typeof current === \"function\"\n ? (current as (...a: unknown[]) => unknown)(...args)\n : current) as {\n (...args: unknown[]): unknown;\n value: T;\n };\n Object.defineProperty(read, \"value\", { value: current });\n return read as Derived<T>;\n}\n"],"mappings":"AAsCA,SAAgBA,EAAWC,EAA8B,CACvD,IAAMC,EAAUD,EAAQ,EAClBE,IAAS,GAAGC,IAChB,OAAOF,GAAY,WACdA,EAAyC,GAAGE,CAAI,EACjDF,GAKN,OADA,OAAO,eAAeC,EAAM,QAAS,CAAE,MAAOD,CAAQ,CAAC,EAChDC,CACT,C"}
@@ -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","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,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,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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":["nextKey","IGNORED_KEYS","attributeName","isFlagAttribute","isEventName","ssrAttribute","classText","ssrStyle","styleText","invalid","escape","escapeHtml","resolveValue","keepLeadingNewline","markSelectedOptions","textareaContent","SsrNode","isSsrNode","rawElementContent","TAG_NAME","VOID_ELEMENTS","SKIPPED_KEYS","innerHtmlOfValue","value","ssr","parts","holes","html","index","hole","ssrRaw","ssrHydrationKey","key","ssrElement","tag","props","children","needsKey","svg","lowerTag","isSelect","isTextarea","control","hasValue","hasFallback","attributes","classes","style","innerHtml","text","collectTruthyKeys","plainHtml","name","raw","given","propsChildren","content","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,MAAMmB,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,EAAiBC,EAAyB,CACjD,GAAsB,OAAOA,GAAU,UAAnCA,EACJ,OAAO,QAAQ,IAAIA,EAAO,QAAQ,CACpC,CAsBA,SAAgBC,EAAIC,EAA0B,GAAGC,EAA2B,CAC1E,GAAI,CAAC,MAAM,QAAQD,CAAK,GAAKA,EAAM,SAAWC,EAAM,OAAS,EAC3D,MAAU,UAAU,6DAA6D,EAEnF,IAAIC,EAAOF,EAAM,IAAM,GACvB,IAAK,IAAIG,EAAQ,EAAG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