@zazz-ui/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/LICENSE +21 -0
  3. package/README.md +61 -0
  4. package/dist/sri.json +75 -0
  5. package/dist/zazz.css +1 -0
  6. package/dist/zazz.js +1 -0
  7. package/examples/about.html +590 -0
  8. package/examples/components.html +1040 -0
  9. package/examples/forms.html +511 -0
  10. package/examples/index.html +268 -0
  11. package/examples/layout.html +320 -0
  12. package/examples/products.html +846 -0
  13. package/examples/responsive.html +339 -0
  14. package/package.json +85 -0
  15. package/src/base/_layers.css +12 -0
  16. package/src/base/_layout.css +568 -0
  17. package/src/base/_reset.css +515 -0
  18. package/src/base/_typography.css +495 -0
  19. package/src/base/_utilities.css +6628 -0
  20. package/src/base/_variables.css +682 -0
  21. package/src/base/_view-transitions.css +103 -0
  22. package/src/base/command-score.d.ts +12 -0
  23. package/src/base/command-score.d.ts.map +1 -0
  24. package/src/base/command-score.js +151 -0
  25. package/src/base/command-score.ts +192 -0
  26. package/src/base/dialog-lifecycle.d.ts +11 -0
  27. package/src/base/dialog-lifecycle.d.ts.map +1 -0
  28. package/src/base/dialog-lifecycle.js +65 -0
  29. package/src/base/dialog-lifecycle.ts +80 -0
  30. package/src/base/embla.d.ts +90 -0
  31. package/src/base/embla.d.ts.map +1 -0
  32. package/src/base/embla.js +643 -0
  33. package/src/base/embla.ts +791 -0
  34. package/src/base/hotkeys.d.ts +82 -0
  35. package/src/base/hotkeys.d.ts.map +1 -0
  36. package/src/base/hotkeys.js +141 -0
  37. package/src/base/hotkeys.ts +195 -0
  38. package/src/base/navigation.d.ts +2 -0
  39. package/src/base/navigation.d.ts.map +1 -0
  40. package/src/base/navigation.js +136 -0
  41. package/src/base/navigation.ts +151 -0
  42. package/src/base/reveal.d.ts +80 -0
  43. package/src/base/reveal.d.ts.map +1 -0
  44. package/src/base/reveal.js +305 -0
  45. package/src/base/reveal.ts +379 -0
  46. package/src/base/signals.d.ts +89 -0
  47. package/src/base/signals.d.ts.map +1 -0
  48. package/src/base/signals.js +134 -0
  49. package/src/base/signals.ts +164 -0
  50. package/src/base/typeahead.d.ts +105 -0
  51. package/src/base/typeahead.d.ts.map +1 -0
  52. package/src/base/typeahead.js +411 -0
  53. package/src/base/typeahead.ts +500 -0
  54. package/src/base/utils.d.ts +56 -0
  55. package/src/base/utils.d.ts.map +1 -0
  56. package/src/base/utils.js +88 -0
  57. package/src/base/utils.ts +98 -0
  58. package/src/base/zazz-element.d.ts +44 -0
  59. package/src/base/zazz-element.d.ts.map +1 -0
  60. package/src/base/zazz-element.js +59 -0
  61. package/src/base/zazz-element.ts +73 -0
  62. package/src/globals.d.ts +148 -0
  63. package/src/head.d.ts +95 -0
  64. package/src/head.d.ts.map +1 -0
  65. package/src/head.js +311 -0
  66. package/src/head.ts +433 -0
  67. package/src/index.css +71 -0
  68. package/src/index.d.ts +36 -0
  69. package/src/index.d.ts.map +1 -0
  70. package/src/index.js +35 -0
  71. package/src/index.ts +36 -0
  72. package/src/manifest.d.ts +90 -0
  73. package/src/manifest.d.ts.map +1 -0
  74. package/src/manifest.js +614 -0
  75. package/src/manifest.ts +667 -0
  76. package/src/primitives/accordion/accordion.css +104 -0
  77. package/src/primitives/accordion/accordion.html +69 -0
  78. package/src/primitives/alert-dialog/alert-dialog.css +38 -0
  79. package/src/primitives/alert-dialog/alert-dialog.html +53 -0
  80. package/src/primitives/autocomplete/autocomplete-groups.html +77 -0
  81. package/src/primitives/autocomplete/autocomplete.css +114 -0
  82. package/src/primitives/autocomplete/autocomplete.d.ts +30 -0
  83. package/src/primitives/autocomplete/autocomplete.d.ts.map +1 -0
  84. package/src/primitives/autocomplete/autocomplete.html +66 -0
  85. package/src/primitives/autocomplete/autocomplete.js +41 -0
  86. package/src/primitives/autocomplete/autocomplete.ts +46 -0
  87. package/src/primitives/avatar/avatar.html +44 -0
  88. package/src/primitives/badge/badge-icon.html +36 -0
  89. package/src/primitives/badge/badge.css +251 -0
  90. package/src/primitives/badge/badge.html +7 -0
  91. package/src/primitives/breadcrumbs/breadcrumbs.html +9 -0
  92. package/src/primitives/button/button-icon-only.html +84 -0
  93. package/src/primitives/button/button-icon.html +82 -0
  94. package/src/primitives/button/button.css +319 -0
  95. package/src/primitives/button/button.html +8 -0
  96. package/src/primitives/button-group/button-group-vertical.html +6 -0
  97. package/src/primitives/button-group/button-group.css +94 -0
  98. package/src/primitives/button-group/button-group.html +64 -0
  99. package/src/primitives/card/card-subgrid.html +118 -0
  100. package/src/primitives/card/card.html +53 -0
  101. package/src/primitives/carousel/carousel.css +61 -0
  102. package/src/primitives/carousel/carousel.d.ts +16 -0
  103. package/src/primitives/carousel/carousel.d.ts.map +1 -0
  104. package/src/primitives/carousel/carousel.html +315 -0
  105. package/src/primitives/carousel/carousel.js +73 -0
  106. package/src/primitives/carousel/carousel.ts +84 -0
  107. package/src/primitives/checkbox/checkbox-tasklist.html +71 -0
  108. package/src/primitives/checkbox/checkbox.css +82 -0
  109. package/src/primitives/checkbox/checkbox.d.ts +21 -0
  110. package/src/primitives/checkbox/checkbox.d.ts.map +1 -0
  111. package/src/primitives/checkbox/checkbox.html +17 -0
  112. package/src/primitives/checkbox/checkbox.js +190 -0
  113. package/src/primitives/checkbox/checkbox.ts +219 -0
  114. package/src/primitives/combobox/combobox-multiselect.html +91 -0
  115. package/src/primitives/combobox/combobox.css +307 -0
  116. package/src/primitives/combobox/combobox.d.ts +100 -0
  117. package/src/primitives/combobox/combobox.d.ts.map +1 -0
  118. package/src/primitives/combobox/combobox.html +73 -0
  119. package/src/primitives/combobox/combobox.js +503 -0
  120. package/src/primitives/combobox/combobox.ts +559 -0
  121. package/src/primitives/command/command-actions.d.ts +31 -0
  122. package/src/primitives/command/command-actions.d.ts.map +1 -0
  123. package/src/primitives/command/command-actions.html +89 -0
  124. package/src/primitives/command/command-actions.js +70 -0
  125. package/src/primitives/command/command-actions.ts +77 -0
  126. package/src/primitives/command/command-dialog.html +77 -0
  127. package/src/primitives/command/command.css +151 -0
  128. package/src/primitives/command/command.d.ts +52 -0
  129. package/src/primitives/command/command.d.ts.map +1 -0
  130. package/src/primitives/command/command.html +119 -0
  131. package/src/primitives/command/command.js +146 -0
  132. package/src/primitives/command/command.ts +157 -0
  133. package/src/primitives/dialog/dialog-with-form.html +200 -0
  134. package/src/primitives/dialog/dialog.css +229 -0
  135. package/src/primitives/dialog/dialog.html +90 -0
  136. package/src/primitives/fields/fields.css +278 -0
  137. package/src/primitives/input/input-icon-leading.html +19 -0
  138. package/src/primitives/input/input-icon-trailing.html +18 -0
  139. package/src/primitives/input/input.css +114 -0
  140. package/src/primitives/input/input.html +61 -0
  141. package/src/primitives/input-group/input-group-password-group.html +108 -0
  142. package/src/primitives/input-group/input-group.css +215 -0
  143. package/src/primitives/input-group/input-group.html +132 -0
  144. package/src/primitives/kbd/kbd-group.html +18 -0
  145. package/src/primitives/kbd/kbd.css +87 -0
  146. package/src/primitives/kbd/kbd.html +7 -0
  147. package/src/primitives/lightbox/lightbox.css +459 -0
  148. package/src/primitives/lightbox/lightbox.d.ts +7 -0
  149. package/src/primitives/lightbox/lightbox.d.ts.map +1 -0
  150. package/src/primitives/lightbox/lightbox.html +665 -0
  151. package/src/primitives/lightbox/lightbox.js +96 -0
  152. package/src/primitives/lightbox/lightbox.ts +113 -0
  153. package/src/primitives/menu/menu-interest.html +52 -0
  154. package/src/primitives/menu/menu.css +55 -0
  155. package/src/primitives/menu/menu.d.ts +38 -0
  156. package/src/primitives/menu/menu.d.ts.map +1 -0
  157. package/src/primitives/menu/menu.html +70 -0
  158. package/src/primitives/menu/menu.js +117 -0
  159. package/src/primitives/menu/menu.ts +131 -0
  160. package/src/primitives/menubar/menubar-help-search.html +103 -0
  161. package/src/primitives/menubar/menubar.html +166 -0
  162. package/src/primitives/meter/meter.css +178 -0
  163. package/src/primitives/meter/meter.html +38 -0
  164. package/src/primitives/mobile-menu/mobile-menu.css +145 -0
  165. package/src/primitives/mobile-menu/mobile-menu.html +614 -0
  166. package/src/primitives/navigation-menu/navigation-menu-featured.html +76 -0
  167. package/src/primitives/navigation-menu/navigation-menu-icon-grid.html +158 -0
  168. package/src/primitives/navigation-menu/navigation-menu-interest.html +103 -0
  169. package/src/primitives/navigation-menu/navigation-menu-megamenu.html +141 -0
  170. package/src/primitives/navigation-menu/navigation-menu-simple.html +96 -0
  171. package/src/primitives/navigation-menu/navigation-menu.css +295 -0
  172. package/src/primitives/navigation-menu/navigation-menu.html +576 -0
  173. package/src/primitives/otp/otp.css +126 -0
  174. package/src/primitives/otp/otp.d.ts +89 -0
  175. package/src/primitives/otp/otp.d.ts.map +1 -0
  176. package/src/primitives/otp/otp.html +22 -0
  177. package/src/primitives/otp/otp.js +226 -0
  178. package/src/primitives/otp/otp.ts +279 -0
  179. package/src/primitives/password-group/password-group.css +238 -0
  180. package/src/primitives/password-group/password-group.d.ts +25 -0
  181. package/src/primitives/password-group/password-group.d.ts.map +1 -0
  182. package/src/primitives/password-group/password-group.html +109 -0
  183. package/src/primitives/password-group/password-group.js +76 -0
  184. package/src/primitives/password-group/password-group.ts +95 -0
  185. package/src/primitives/popover/popover.css +233 -0
  186. package/src/primitives/progress/progress-indeterminate.html +1 -0
  187. package/src/primitives/progress/progress.css +105 -0
  188. package/src/primitives/progress/progress.html +7 -0
  189. package/src/primitives/prose/prose.html +65 -0
  190. package/src/primitives/radio/radio.css +84 -0
  191. package/src/primitives/radio/radio.html +17 -0
  192. package/src/primitives/reveal/reveal.css +167 -0
  193. package/src/primitives/select/multiselect.d.ts +43 -0
  194. package/src/primitives/select/multiselect.d.ts.map +1 -0
  195. package/src/primitives/select/multiselect.js +147 -0
  196. package/src/primitives/select/multiselect.ts +188 -0
  197. package/src/primitives/select/select-align.html +49 -0
  198. package/src/primitives/select/select-multiple.html +12 -0
  199. package/src/primitives/select/select-sides.html +65 -0
  200. package/src/primitives/select/select.css +481 -0
  201. package/src/primitives/select/select.html +16 -0
  202. package/src/primitives/separator/separator.css +49 -0
  203. package/src/primitives/separator/separator.html +16 -0
  204. package/src/primitives/slider/slider.css +122 -0
  205. package/src/primitives/slider/slider.html +1 -0
  206. package/src/primitives/switch/switch.css +126 -0
  207. package/src/primitives/switch/switch.html +13 -0
  208. package/src/primitives/table/table-alternating.html +36 -0
  209. package/src/primitives/table/table-grid.html +30 -0
  210. package/src/primitives/table/table-size-sm.html +26 -0
  211. package/src/primitives/table/table.css +158 -0
  212. package/src/primitives/table/table.html +45 -0
  213. package/src/primitives/tabs/tabs.css +328 -0
  214. package/src/primitives/tabs/tabs.d.ts +35 -0
  215. package/src/primitives/tabs/tabs.d.ts.map +1 -0
  216. package/src/primitives/tabs/tabs.html +75 -0
  217. package/src/primitives/tabs/tabs.js +84 -0
  218. package/src/primitives/tabs/tabs.ts +93 -0
  219. package/src/primitives/textarea/textarea.css +78 -0
  220. package/src/primitives/textarea/textarea.html +10 -0
  221. package/src/primitives/toaster/toaster.css +309 -0
  222. package/src/primitives/toaster/toaster.d.ts +138 -0
  223. package/src/primitives/toaster/toaster.d.ts.map +1 -0
  224. package/src/primitives/toaster/toaster.html +77 -0
  225. package/src/primitives/toaster/toaster.js +736 -0
  226. package/src/primitives/toaster/toaster.ts +823 -0
  227. package/src/primitives/toggle/toggle.css +295 -0
  228. package/src/primitives/toggle/toggle.html +68 -0
  229. package/src/primitives/toggle-group/toggle-group-multiple.html +14 -0
  230. package/src/primitives/toggle-group/toggle-group-vertical.html +14 -0
  231. package/src/primitives/toggle-group/toggle-group.css +73 -0
  232. package/src/primitives/toggle-group/toggle-group.html +53 -0
  233. package/src/primitives/toolbar/toolbar.html +45 -0
  234. package/src/primitives/tooltip/tooltip-disabled.html +19 -0
  235. package/src/primitives/tooltip/tooltip-sides.html +57 -0
  236. package/src/primitives/tooltip/tooltip-with-kbd.html +31 -0
  237. package/src/primitives/tooltip/tooltip.css +235 -0
  238. package/src/primitives/tooltip/tooltip.html +12 -0
  239. package/src/primitives/utilities/aspect-ratio.html +17 -0
  240. package/src/primitives/utilities/basis.html +27 -0
  241. package/src/primitives/utilities/col-span.html +23 -0
  242. package/src/primitives/utilities/compose.html +19 -0
  243. package/src/primitives/utilities/flex-align.html +26 -0
  244. package/src/primitives/utilities/flex-direction.html +36 -0
  245. package/src/primitives/utilities/flex-grow.html +17 -0
  246. package/src/primitives/utilities/gap.html +62 -0
  247. package/src/primitives/utilities/grid-cols.html +20 -0
  248. package/src/primitives/utilities/grid-pile.html +5 -0
  249. package/src/primitives/utilities/grid-responsive.html +31 -0
  250. package/src/primitives/utilities/margin-auto.html +13 -0
  251. package/src/primitives/utilities/object-fit.html +41 -0
  252. package/src/primitives/utilities/order.html +17 -0
  253. package/src/primitives/utilities/overflow.html +26 -0
  254. package/src/primitives/utilities/padding-compose.html +23 -0
  255. package/src/primitives/utilities/padding.html +30 -0
  256. package/src/primitives/utilities/position.html +13 -0
  257. package/src/primitives/utilities/responsive-flex.html +22 -0
  258. package/src/primitives/utilities/responsive-grid.html +31 -0
  259. package/src/primitives/utilities/size.html +22 -0
  260. package/src/primitives/utilities/width.html +22 -0
package/src/head.js ADDED
@@ -0,0 +1,311 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Canonical `<head>` contract for Zazz pages.
4
+ * @description The single owner of everything a Zazz page loads before its own
5
+ * content: meta tags, the Geist fonts block, the one `index.css` stylesheet
6
+ * link, the feature polyfills, the third-party **import map**, the `index.js`
7
+ * module tag, and the theme-persistence script. The docs preview iframe, the
8
+ * kit's example pages (via `scripts/generate-heads.mjs`), and the docs page
9
+ * that teaches head structure all render from this module: there is no other
10
+ * copy to drift.
11
+ *
12
+ * This is a Node/server-side string builder (used at build/render time), not a
13
+ * browser runtime module; it attaches nothing to `window`.
14
+ *
15
+ * Third-party policy: one CDN provider (jsDelivr), exact pinned versions,
16
+ * static package files only (never dynamically generated `/+esm` bundles,
17
+ * as jsDelivr regenerates those when its bundler toolchain updates, which would
18
+ * silently invalidate SRI hashes), `sha384` integrity on every URL. ES modules
19
+ * resolve through the import map; classic polyfills load as plain script tags.
20
+ *
21
+ * @example
22
+ * import { buildHead } from "@zazz-ui/core/head";
23
+ * const head = buildHead({ base: "./zazz" });
24
+ */
25
+ import { PRIMITIVES, resolveClosure } from "./manifest.js";
26
+ /** The one CDN provider for every third-party resource. */
27
+ const CDN = "https://cdn.jsdelivr.net/npm";
28
+ /** The kit's own published package name (CDN mode serves files out of it). */
29
+ const PACKAGE_NAME = "@zazz-ui/core";
30
+ /**
31
+ * Exact-version pin required in every kit CDN URL. SRI hashes are per-byte,
32
+ * so floating specs (`latest`, `0.3`) would break integrity on each release —
33
+ * and unpinned URLs defeat jsDelivr's permanent caching (ticket 06).
34
+ */
35
+ const EXACT_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
36
+ /**
37
+ * Base stylesheets in the exact order `src/index.css` loads them around the
38
+ * primitive imports: `PRE` before (layer declaration first), `POST` after
39
+ * (utilities and layout stay the final normal override layer). The granular
40
+ * CDN head mirrors this split; `head.test.ts` guards it against `index.css`.
41
+ */
42
+ const BASE_CSS_PRE = [
43
+ "base/_layers.css",
44
+ "base/_variables.css",
45
+ "base/_reset.css",
46
+ "base/_typography.css",
47
+ "base/_view-transitions.css",
48
+ ];
49
+ const BASE_CSS_POST = ["base/_utilities.css", "base/_layout.css"];
50
+ /**
51
+ * Core runtime modules reached by relative import from primitive scripts
52
+ * (never via their own script tag, except `dialog-lifecycle`, which is a
53
+ * side-effect module the granular head loads explicitly). Listed so the
54
+ * import map's `integrity` section can cover their transitive loads.
55
+ */
56
+ const CORE_RUNTIME_JS = [
57
+ "base/dialog-lifecycle.js",
58
+ "base/utils.js",
59
+ "base/signals.js",
60
+ "base/zazz-element.js",
61
+ ];
62
+ /**
63
+ * @description Builds the pinned jsDelivr URL for a dependency.
64
+ *
65
+ * @param dep - The dependency entry.
66
+ * @returns The versioned URL.
67
+ * @private
68
+ */
69
+ function cdnUrl(dep) {
70
+ return `${CDN}/${dep.name}@${dep.version}/${dep.file}`;
71
+ }
72
+ /**
73
+ * ES-module dependencies the kit's module graph imports by bare specifier.
74
+ * The import map points each specifier at its pinned static file; in tests and
75
+ * bundlers the same specifiers resolve from `node_modules` instead (the
76
+ * versions here must match the installed packages: `head.test.ts` pins that).
77
+ */
78
+ const ESM_DEPENDENCIES = [
79
+ {
80
+ name: "signal-polyfill",
81
+ version: "0.2.2",
82
+ file: "dist/index.js",
83
+ integrity: "sha384-0OqM7OXGT6Oz1z98u/geiFn/FUyz4iWexkXHCvbIGXRRDXl6bp6IKc0j78AQ6DEK",
84
+ },
85
+ {
86
+ name: "embla-carousel",
87
+ version: "8.6.0",
88
+ file: "esm/embla-carousel.esm.js",
89
+ integrity: "sha384-GXjfyU1fSHHeweoYd3rwo7OBKYtkq+JcsDoe8VDRc6znCty2ZTzyVvX1DwqCE+9t",
90
+ },
91
+ {
92
+ name: "embla-carousel-autoplay",
93
+ version: "8.6.0",
94
+ file: "esm/embla-carousel-autoplay.esm.js",
95
+ integrity: "sha384-AX49yBc7zd/CT8ZqNMRiiqqVSV9xfxb27VwEGziPioT3wL4k4C5BW2qwefdWuN4J",
96
+ },
97
+ {
98
+ name: "embla-carousel-auto-scroll",
99
+ version: "8.6.0",
100
+ file: "esm/embla-carousel-auto-scroll.esm.js",
101
+ integrity: "sha384-SPdnL1eic73WfM72zFEf0RJ5PdUC7TL3Yb5jOl1JC3/l4D7EsVxwO8wFnnezlMSu",
102
+ },
103
+ {
104
+ name: "embla-carousel-class-names",
105
+ version: "8.6.0",
106
+ file: "esm/embla-carousel-class-names.esm.js",
107
+ integrity: "sha384-ZWno/FqzYeWE5Ils19GIhep1AZ5bMl0mp9wmm6baTJE4+pjMjOdTnE55SjUQAdVh",
108
+ },
109
+ ];
110
+ /**
111
+ * Feature polyfills loaded as script tags ahead of the kit module: the Popover
112
+ * API (menus, tooltips, the toaster region) and Invoker Commands
113
+ * (`command`/`commandfor`). Native in current engines (2026); the polyfills
114
+ * keep older browsers consistent.
115
+ */
116
+ const POLYFILLS = [
117
+ {
118
+ name: "@oddbird/popover-polyfill",
119
+ version: "0.7.2",
120
+ file: "dist/popover.min.js",
121
+ integrity: "sha384-pOVHoXRgxuaWHCRM4KSyfyfRTmdxgjVo1Ux78ZKJ+GjUz4zIzXiTa8XXuDF1R1Sd",
122
+ },
123
+ {
124
+ name: "invokers",
125
+ version: "2.2.2",
126
+ file: "dist/esm/production/compatible.js",
127
+ integrity: "sha384-7vRXDaS2mcW7LheGSA/rxBwIQNEqmWj0OLEOta/+mvw+9Uf5w1vplA5qg8kLQ99u",
128
+ },
129
+ ];
130
+ // --- Head fragments ---
131
+ /**
132
+ * @description Renders the Geist fonts block (preconnect + preload + stylesheet).
133
+ *
134
+ * @param display - The `font-display` strategy for the Google Fonts request.
135
+ * @returns The fonts markup.
136
+ * @private
137
+ */
138
+ function fontsBlock(display) {
139
+ return `<!-- Google Fonts: Geist + Geist Mono (preconnect so the CSS request starts early) -->
140
+ <link rel="preconnect" href="https://fonts.googleapis.com">
141
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
142
+ <link rel="preload" as="font" type="font/woff2" crossorigin href="https://fonts.gstatic.com/s/geist/v5/gyByhwUxId8gMEwcGFWNOITd.woff2">
143
+ <link href="https://fonts.googleapis.com/css2?family=Geist+Mono:ital,wght@0,100..900;1,100..900&family=Geist:ital,wght@0,100..900;1,100..900&display=${display}" rel="stylesheet">`;
144
+ }
145
+ /**
146
+ * @description Renders the import map that resolves the kit's bare specifiers
147
+ * (`signal-polyfill`, `embla-carousel`, …) to pinned jsDelivr URLs, with an
148
+ * `integrity` section covering every mapped file.
149
+ *
150
+ * @returns The import-map script tag.
151
+ * @private
152
+ */
153
+ function importMapBlock(extraIntegrity = {}) {
154
+ const imports = {};
155
+ const integrity = { ...extraIntegrity };
156
+ for (const dep of ESM_DEPENDENCIES) {
157
+ const url = cdnUrl(dep);
158
+ imports[dep.name] = url;
159
+ integrity[url] = dep.integrity;
160
+ }
161
+ const json = JSON.stringify({ imports, integrity }, null, 2);
162
+ return `<!-- Import map: bare specifiers in Zazz scripts resolve to pinned, SRI-checked files -->
163
+ <script type="importmap">
164
+ ${json}
165
+ </script>`;
166
+ }
167
+ /**
168
+ * @description Renders the polyfill script tags. The popover polyfill is a
169
+ * classic script; the invokers compatibility build is a module. Both are
170
+ * deferred, so they execute in document order ahead of `index.js`.
171
+ *
172
+ * @returns The polyfill markup.
173
+ * @private
174
+ */
175
+ function polyfillsBlock() {
176
+ const [popover, invokers] = POLYFILLS;
177
+ return `<!-- Polyfills: Popover API + Invoker Commands (command/commandfor) -->
178
+ <script src="${cdnUrl(popover)}" integrity="${popover.integrity}" crossorigin="anonymous" defer></script>
179
+ <script type="module" src="${cdnUrl(invokers)}" integrity="${invokers.integrity}" crossorigin="anonymous" defer></script>`;
180
+ }
181
+ /**
182
+ * The theme-persistence script. Runs inline (no `defer`) while the parser is
183
+ * still in `<head>`, so `.dark` lands on `<html>` before first paint. The
184
+ * try/catch covers contexts where storage access throws (sandboxed iframes,
185
+ * blocked site data).
186
+ */
187
+ const THEME_SCRIPT = `<!-- Theme: apply the persisted (or preferred) scheme before first paint -->
188
+ <script>
189
+ (() => {
190
+ try {
191
+ const storedTheme = localStorage.getItem("theme");
192
+ const prefersDark = matchMedia("(prefers-color-scheme: dark)").matches;
193
+ const theme = storedTheme ?? (prefersDark ? "dark" : "light");
194
+ document.documentElement.classList.toggle("dark", theme === "dark");
195
+ } catch {
196
+ document.documentElement.classList.toggle(
197
+ "dark",
198
+ matchMedia("(prefers-color-scheme: dark)").matches,
199
+ );
200
+ }
201
+ })();
202
+ </script>`;
203
+ /**
204
+ * @description Builds the canonical Zazz `<head>` contents: meta tags, fonts,
205
+ * the single stylesheet link, and (unless `scripts: false`) the import map,
206
+ * polyfills, and `index.js` module tag, ending with the theme script. Page
207
+ * specifics (`<title>`, prefetch hints, override stylesheets) belong after
208
+ * this block, outside the contract.
209
+ *
210
+ * @param options - See `HeadOptions`.
211
+ * @returns The head markup (no surrounding `<head>` tag).
212
+ * @example
213
+ * buildHead(); // full head for "./zazz"
214
+ * buildHead({ base: "/zazz/src", scripts: false, fontDisplay: "optional" });
215
+ */
216
+ export function buildHead(options = {}) {
217
+ const { base = "./zazz", cdn, scripts = true, fontDisplay = "swap", theme = true } = options;
218
+ const parts = [
219
+ `<meta charset="utf-8">`,
220
+ `<meta name="viewport" content="width=device-width, initial-scale=1">`,
221
+ `<!-- Paint the right theme (background, form controls, scrollbars) before CSS loads -->`,
222
+ `<meta name="color-scheme" content="light dark">`,
223
+ ];
224
+ if (fontDisplay !== false)
225
+ parts.push(fontsBlock(fontDisplay));
226
+ if (cdn) {
227
+ parts.push(...cdnBlocks(cdn, scripts));
228
+ }
229
+ else {
230
+ parts.push(`<!-- Zazz styles: one bundle (index.css @imports every layer in cascade order) -->`, `<link rel="stylesheet" href="${base}/index.css">`);
231
+ if (scripts) {
232
+ parts.push(
233
+ // The import map must precede EVERY module load — including the
234
+ // modulepreload hint — or the browser rejects it and bare specifiers fail.
235
+ importMapBlock(), `<link rel="modulepreload" href="${base}/index.js">`, polyfillsBlock(), `<!-- Zazz behavior: one ES module imports every component script in dependency order -->`, `<script type="module" src="${base}/index.js"></script>`);
236
+ }
237
+ }
238
+ if (theme)
239
+ parts.push(THEME_SCRIPT);
240
+ return parts.join("\n");
241
+ }
242
+ // --- CDN mode ---
243
+ /**
244
+ * @description Renders the style/behavior blocks for CDN mode: the bundle
245
+ * grain (two `dist/` requests, whole kit) or, when `primitives` is given, the
246
+ * granular grain — base layers in cascade order, the dependency closure's
247
+ * stylesheets, and one module tag per closure script (relative imports between
248
+ * kit files resolve natively on jsDelivr; only bare specifiers need the map).
249
+ *
250
+ * @param cdn - The CDN options (exact version, optional primitives + sri).
251
+ * @param scripts - Whether behavior loads at all (`HeadOptions.scripts`).
252
+ * @returns The head fragments between the fonts block and the theme script.
253
+ * @private
254
+ */
255
+ function cdnBlocks(cdn, scripts) {
256
+ const { version, primitives, sri } = cdn;
257
+ if (!EXACT_VERSION.test(version)) {
258
+ throw new Error(`CDN URLs must pin an exact version (got "${version}"); ` +
259
+ `dist-tags and ranges break SRI and permanent caching`);
260
+ }
261
+ const url = (path) => `${CDN}/${PACKAGE_NAME}@${version}/${path}`;
262
+ const attrs = (path) => {
263
+ const hash = sri?.[path];
264
+ return hash ? ` integrity="${hash}" crossorigin="anonymous"` : "";
265
+ };
266
+ const parts = [];
267
+ if (!primitives) {
268
+ parts.push(`<!-- Zazz styles: the whole kit, one request -->`, `<link rel="stylesheet" href="${url("dist/zazz.css")}"${attrs("dist/zazz.css")}>`);
269
+ if (scripts) {
270
+ parts.push(importMapBlock(), `<link rel="modulepreload" href="${url("dist/zazz.js")}"${attrs("dist/zazz.js")}>`, polyfillsBlock(), `<!-- Zazz behavior: the whole kit, one module -->`, `<script type="module" src="${url("dist/zazz.js")}"${attrs("dist/zazz.js")}></script>`);
271
+ }
272
+ return parts;
273
+ }
274
+ const closure = resolveClosure(primitives);
275
+ const css = [
276
+ ...BASE_CSS_PRE,
277
+ ...closure.flatMap((name) => PRIMITIVES[name]?.css ?? []),
278
+ ...BASE_CSS_POST,
279
+ ];
280
+ parts.push(`<!-- Zazz styles: base layers, then ${closure.join(", ")} in cascade order -->`, ...css.map((path) => `<link rel="stylesheet" href="${url(`src/${path}`)}"${attrs(`src/${path}`)}>`));
281
+ if (scripts) {
282
+ // Side-effect modules need their own tag (nothing imports them); the rest
283
+ // of each primitive's chain loads through native relative imports. The
284
+ // core dialog-lifecycle module always leads: dialogs, menus, and popovers
285
+ // assume its lifecycle events. Polyfills stay in even for css-only
286
+ // closures — tooltip/dialog/menu styles ride on the Popover API and
287
+ // Invoker Commands.
288
+ const scriptFiles = [
289
+ ...new Set([
290
+ "base/dialog-lifecycle.js",
291
+ ...closure.flatMap((name) => {
292
+ const entry = PRIMITIVES[name];
293
+ return entry ? [...entry.base, ...entry.js] : [];
294
+ }),
295
+ ]),
296
+ ];
297
+ // Transitively imported core modules never get a tag, so their integrity
298
+ // rides in the import map's integrity section instead.
299
+ const transitive = {};
300
+ if (sri) {
301
+ for (const path of CORE_RUNTIME_JS) {
302
+ const hash = sri[`src/${path}`];
303
+ if (hash)
304
+ transitive[url(`src/${path}`)] = hash;
305
+ }
306
+ }
307
+ parts.push(importMapBlock(transitive), polyfillsBlock(), `<!-- Zazz behavior: side-effect modules by tag; the rest via module imports -->`, ...scriptFiles.map((path) => `<script type="module" src="${url(`src/${path}`)}"${attrs(`src/${path}`)}></script>`));
308
+ }
309
+ return parts;
310
+ }
311
+ export { ESM_DEPENDENCIES, POLYFILLS, cdnUrl };