@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
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @fileoverview Data attribute and value parsing utilities.
5
+ * @description Shared helpers for converting HTML data-attribute strings into
6
+ * typed JavaScript values.
7
+ *
8
+ * This is a **public, consumer-facing** surface (`window.Utils`, documented at
9
+ * /docs/components/utils), not just kit plumbing: data-attribute configuration
10
+ * is the kit's documented pattern for authoring a component
11
+ * (CONVENTIONS.scripts.md), so anyone writing a component in the Zazz idiom
12
+ * needs this exact parser to match kit behaviour. Keep it here rather than
13
+ * folding it into a caller — see docs/adr/0004-keep-utils-public.md.
14
+ *
15
+ * Callers that need a typed result should wrap it at their own boundary (see
16
+ * `readCarouselOptions` in embla.ts) rather than narrowing at each call.
17
+ */
18
+
19
+ // --- Data type conversion ---
20
+
21
+ /**
22
+ * @description Converts string values to their appropriate JavaScript types.
23
+ *
24
+ * @param value - The string value to convert.
25
+ * @returns Converted value in the appropriate type.
26
+ *
27
+ * @example
28
+ * parseValue("true"); // true
29
+ * parseValue("42"); // 42
30
+ * parseValue("[1,2,3]"); // [1, 2, 3]
31
+ * parseValue("hello"); // "hello"
32
+ */
33
+ function parseValue(value: string): boolean | number | unknown[] | string {
34
+ if (value === "true") return true;
35
+ if (value === "false") return false;
36
+
37
+ if (!Number.isNaN(Number(value)) && value.trim() !== "") return Number(value);
38
+
39
+ if (value.startsWith("[") && value.endsWith("]")) {
40
+ try {
41
+ return JSON.parse(value);
42
+ } catch {
43
+ return value;
44
+ }
45
+ }
46
+
47
+ return value;
48
+ }
49
+
50
+ // --- Data attribute parsing ---
51
+
52
+ /**
53
+ * @description Extracts and parses data attributes with a specific prefix from a DOM node.
54
+ *
55
+ * Converts kebab-case attribute names to camelCase object keys.
56
+ *
57
+ * @param node - The DOM element to extract attributes from.
58
+ * @param prefix - The attribute prefix to look for (e.g. `"data-carousel-"`).
59
+ * @returns Object with camelCase keys and parsed values.
60
+ *
61
+ * @example
62
+ * // <div data-carousel-auto-play="true" data-carousel-slide-count="5">
63
+ * parseDataAttributes(element, "data-carousel-");
64
+ * // { autoPlay: true, slideCount: 5 }
65
+ */
66
+ const parseDataAttributes = (node: Element, prefix: string): Record<string, unknown> => {
67
+ const options: Record<string, unknown> = {};
68
+
69
+ for (const attr of node.attributes) {
70
+ if (attr.name.startsWith(prefix)) {
71
+ const key = attr.name.replace(prefix, "").replace(/-([a-z])/g, (_, c) => c.toUpperCase());
72
+
73
+ options[key] = parseValue(attr.value);
74
+ }
75
+ }
76
+
77
+ return options;
78
+ };
79
+
80
+ /**
81
+ * @namespace Utils
82
+ * @description Shared DOM and data-attribute parsing utilities.
83
+ *
84
+ * @property parseValue - Converts string values to typed values.
85
+ * @property parseDataAttributes - Parses prefixed data attributes on a node.
86
+ */
87
+ const Utils = {
88
+ parseValue,
89
+ parseDataAttributes,
90
+ };
91
+
92
+ // Attach to window for the documented public API (`window.Utils`), and export
93
+ // for module consumers (embla.js imports it via the main.js bundle).
94
+ if (typeof window !== "undefined") {
95
+ window.Utils = Utils;
96
+ }
97
+
98
+ export { Utils };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @fileoverview The component runtime: a thin base element + the refresh registry.
3
+ * @description Two small pieces every behavioral component shares:
4
+ *
5
+ * **`ZazzElement`** owns the lifecycle envelope each HTML web component used to
6
+ * repeat: the `AbortController`, the reconnect guard, teardown-on-disconnect.
7
+ * Subclasses implement `setup(signal)` (bind everything with `{ signal }`) and,
8
+ * only when they hold resources an abort can't release, `teardown()`.
9
+ * Deliberately thin: anything beyond the envelope belongs in the component.
10
+ *
11
+ * **`defineZazzElement(tag, cls)`** is the registration guard (safe under
12
+ * double script loads). Only behavioral components register; the CSS-only
13
+ * tag forms (`ui-tooltip`, `ui-accordion`, `ui-button-group`,
14
+ * `ui-toggle-group`) stay unregistered by design (ADR-0001).
15
+ *
16
+ * **The refresh registry** replaces hand-listing components in navigation.ts:
17
+ * a module whose work is scoped to page content (reveal observer, class-form
18
+ * carousel init) registers a refresh hook; after a SPA `<main>` swap the
19
+ * navigation module calls `refreshAll(newMain)` and never names a component.
20
+ * Custom elements do not need hooks: their lifecycle rides the swap natively.
21
+ */
22
+ /** Base class for Zazz HTML web components: lifecycle envelope only. */
23
+ declare abstract class ZazzElement extends HTMLElement {
24
+ #private;
25
+ connectedCallback(): void;
26
+ disconnectedCallback(): void;
27
+ /** Bind listeners, observers, and effects here: always with `{ signal }`. */
28
+ protected abstract setup(signal: AbortSignal): void;
29
+ /** Release what an abort can't (third-party instances, stamped attributes). */
30
+ protected teardown?(): void;
31
+ }
32
+ /** Registers a custom element, guarded against double script loads. */
33
+ declare function defineZazzElement(tag: string, cls: CustomElementConstructor): void;
34
+ type RefreshHook = (scope: Element) => void;
35
+ /**
36
+ * @description Registers a hook to re-scan swapped-in content (SPA `<main>`
37
+ * replacement). Hooks must be idempotent: already-initialized nodes are the
38
+ * hook's own job to skip.
39
+ */
40
+ declare function registerRefresh(hook: RefreshHook): void;
41
+ /** @description Runs every registered refresh hook against a swapped-in scope. */
42
+ declare function refreshAll(scope: Element): void;
43
+ export { ZazzElement, defineZazzElement, registerRefresh, refreshAll };
44
+ //# sourceMappingURL=zazz-element.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zazz-element.d.ts","sourceRoot":"","sources":["zazz-element.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,wEAAwE;AACxE,uBAAe,WAAY,SAAQ,WAAW;;IAG5C,iBAAiB,IAAI,IAAI,CAIxB;IAED,oBAAoB,IAAI,IAAI,CAI3B;IAED,6EAA6E;IAC7E,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IAEpD,+EAA+E;IAC/E,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC;CAC7B;AAED,uEAAuE;AACvE,iBAAS,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,wBAAwB,GAAG,IAAI,CAG3E;AAID,KAAK,WAAW,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;AAG5C;;;;GAIG;AACH,iBAAS,eAAe,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAEhD;AAED,kFAAkF;AAClF,iBAAS,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAExC;AAED,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview The component runtime: a thin base element + the refresh registry.
4
+ * @description Two small pieces every behavioral component shares:
5
+ *
6
+ * **`ZazzElement`** owns the lifecycle envelope each HTML web component used to
7
+ * repeat: the `AbortController`, the reconnect guard, teardown-on-disconnect.
8
+ * Subclasses implement `setup(signal)` (bind everything with `{ signal }`) and,
9
+ * only when they hold resources an abort can't release, `teardown()`.
10
+ * Deliberately thin: anything beyond the envelope belongs in the component.
11
+ *
12
+ * **`defineZazzElement(tag, cls)`** is the registration guard (safe under
13
+ * double script loads). Only behavioral components register; the CSS-only
14
+ * tag forms (`ui-tooltip`, `ui-accordion`, `ui-button-group`,
15
+ * `ui-toggle-group`) stay unregistered by design (ADR-0001).
16
+ *
17
+ * **The refresh registry** replaces hand-listing components in navigation.ts:
18
+ * a module whose work is scoped to page content (reveal observer, class-form
19
+ * carousel init) registers a refresh hook; after a SPA `<main>` swap the
20
+ * navigation module calls `refreshAll(newMain)` and never names a component.
21
+ * Custom elements do not need hooks: their lifecycle rides the swap natively.
22
+ */
23
+ /** Base class for Zazz HTML web components: lifecycle envelope only. */
24
+ class ZazzElement extends HTMLElement {
25
+ #controller = null;
26
+ connectedCallback() {
27
+ if (this.#controller)
28
+ return;
29
+ this.#controller = new AbortController();
30
+ this.setup(this.#controller.signal);
31
+ }
32
+ disconnectedCallback() {
33
+ this.#controller?.abort();
34
+ this.#controller = null;
35
+ this.teardown?.();
36
+ }
37
+ }
38
+ /** Registers a custom element, guarded against double script loads. */
39
+ function defineZazzElement(tag, cls) {
40
+ if (typeof window === "undefined")
41
+ return;
42
+ if (!customElements.get(tag))
43
+ customElements.define(tag, cls);
44
+ }
45
+ const refreshHooks = [];
46
+ /**
47
+ * @description Registers a hook to re-scan swapped-in content (SPA `<main>`
48
+ * replacement). Hooks must be idempotent: already-initialized nodes are the
49
+ * hook's own job to skip.
50
+ */
51
+ function registerRefresh(hook) {
52
+ refreshHooks.push(hook);
53
+ }
54
+ /** @description Runs every registered refresh hook against a swapped-in scope. */
55
+ function refreshAll(scope) {
56
+ for (const hook of refreshHooks)
57
+ hook(scope);
58
+ }
59
+ export { ZazzElement, defineZazzElement, registerRefresh, refreshAll };
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @fileoverview The component runtime: a thin base element + the refresh registry.
5
+ * @description Two small pieces every behavioral component shares:
6
+ *
7
+ * **`ZazzElement`** owns the lifecycle envelope each HTML web component used to
8
+ * repeat: the `AbortController`, the reconnect guard, teardown-on-disconnect.
9
+ * Subclasses implement `setup(signal)` (bind everything with `{ signal }`) and,
10
+ * only when they hold resources an abort can't release, `teardown()`.
11
+ * Deliberately thin: anything beyond the envelope belongs in the component.
12
+ *
13
+ * **`defineZazzElement(tag, cls)`** is the registration guard (safe under
14
+ * double script loads). Only behavioral components register; the CSS-only
15
+ * tag forms (`ui-tooltip`, `ui-accordion`, `ui-button-group`,
16
+ * `ui-toggle-group`) stay unregistered by design (ADR-0001).
17
+ *
18
+ * **The refresh registry** replaces hand-listing components in navigation.ts:
19
+ * a module whose work is scoped to page content (reveal observer, class-form
20
+ * carousel init) registers a refresh hook; after a SPA `<main>` swap the
21
+ * navigation module calls `refreshAll(newMain)` and never names a component.
22
+ * Custom elements do not need hooks: their lifecycle rides the swap natively.
23
+ */
24
+
25
+ /** Base class for Zazz HTML web components: lifecycle envelope only. */
26
+ abstract class ZazzElement extends HTMLElement {
27
+ #controller: AbortController | null = null;
28
+
29
+ connectedCallback(): void {
30
+ if (this.#controller) return;
31
+ this.#controller = new AbortController();
32
+ this.setup(this.#controller.signal);
33
+ }
34
+
35
+ disconnectedCallback(): void {
36
+ this.#controller?.abort();
37
+ this.#controller = null;
38
+ this.teardown?.();
39
+ }
40
+
41
+ /** Bind listeners, observers, and effects here: always with `{ signal }`. */
42
+ protected abstract setup(signal: AbortSignal): void;
43
+
44
+ /** Release what an abort can't (third-party instances, stamped attributes). */
45
+ protected teardown?(): void;
46
+ }
47
+
48
+ /** Registers a custom element, guarded against double script loads. */
49
+ function defineZazzElement(tag: string, cls: CustomElementConstructor): void {
50
+ if (typeof window === "undefined") return;
51
+ if (!customElements.get(tag)) customElements.define(tag, cls);
52
+ }
53
+
54
+ // --- Refresh registry ---
55
+
56
+ type RefreshHook = (scope: Element) => void;
57
+ const refreshHooks: RefreshHook[] = [];
58
+
59
+ /**
60
+ * @description Registers a hook to re-scan swapped-in content (SPA `<main>`
61
+ * replacement). Hooks must be idempotent: already-initialized nodes are the
62
+ * hook's own job to skip.
63
+ */
64
+ function registerRefresh(hook: RefreshHook): void {
65
+ refreshHooks.push(hook);
66
+ }
67
+
68
+ /** @description Runs every registered refresh hook against a swapped-in scope. */
69
+ function refreshAll(scope: Element): void {
70
+ for (const hook of refreshHooks) hook(scope);
71
+ }
72
+
73
+ export { ZazzElement, defineZazzElement, registerRefresh, refreshAll };
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Ambient types for Zazz runtime scripts.
3
+ * Cross-script globals (Utils, element classes) are declared here so
4
+ * checkJs can validate files that reference them across module boundaries.
5
+ */
6
+
7
+ // Embla loads as real ES modules (see base/embla.ts imports); these aliases
8
+ // keep the shared names other scripts reference pointing at the real types.
9
+ type EmblaCarouselType = import("embla-carousel").EmblaCarouselType;
10
+ type EmblaPlugin = import("embla-carousel").EmblaPluginType;
11
+
12
+ interface UtilsNamespace {
13
+ parseValue(value: string): boolean | number | unknown[] | string;
14
+ parseDataAttributes(node: Element, prefix: string): Record<string, unknown>;
15
+ }
16
+
17
+ interface Element {
18
+ /** @internal Set by embla.js on carousel root elements. */
19
+ _emblaApi?: EmblaCarouselType;
20
+ /** @internal Set by embla.js when a thumb carousel is linked. */
21
+ _emblaApiThumb?: EmblaCarouselType;
22
+ /** @internal Set by embla.js; aborts all per-carousel listeners on teardown. */
23
+ _emblaController?: AbortController;
24
+ }
25
+
26
+ interface InitEmblaKeyboardNavFn {
27
+ (): void;
28
+ _bound?: boolean;
29
+ }
30
+
31
+ /** @see https://developer.mozilla.org/en-US/docs/Web/API/Navigation_API */
32
+ interface NavigationDestination {
33
+ url: string;
34
+ }
35
+
36
+ interface NavigateEvent extends Event {
37
+ canIntercept: boolean;
38
+ hashChange: boolean;
39
+ downloadRequest: unknown;
40
+ formData: FormData | null;
41
+ destination: NavigationDestination;
42
+ intercept(options: { handler: () => Promise<void> }): void;
43
+ scroll(): void;
44
+ }
45
+
46
+ interface Navigation extends EventTarget {
47
+ addEventListener(type: "navigate", listener: (event: NavigateEvent) => void): void;
48
+ }
49
+
50
+ /**
51
+ * Invoker Commands API (command/commandfor). Native in Chromium 135+; the
52
+ * invokers polyfill dispatches a compatible event. Declared here (as interface
53
+ * merges) until lib.dom ships it.
54
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CommandEvent
55
+ */
56
+ interface CommandEvent extends Event {
57
+ readonly command: string;
58
+ readonly source: Element | null;
59
+ }
60
+
61
+ interface HTMLElementEventMap {
62
+ command: CommandEvent;
63
+ /** Dialog lifecycle events emitted by base/dialog-lifecycle.ts (ADR-0003). */
64
+ "zazz:dialog-open": Event;
65
+ "zazz:dialog-close": Event;
66
+ }
67
+
68
+ interface DocumentEventMap {
69
+ "zazz:dialog-open": Event;
70
+ "zazz:dialog-close": Event;
71
+ }
72
+
73
+ interface RevealInstance {
74
+ init(): void;
75
+ refresh(): void;
76
+ config: object;
77
+ }
78
+
79
+ interface RevealConstructor {
80
+ new (options?: object): RevealInstance;
81
+ disableAutoInit(): void;
82
+ getAutoInstance(): RevealInstance | null;
83
+ defaultConfig: object;
84
+ }
85
+
86
+ /** Toast content and behavior (see toaster.js for the authoritative JSDoc). */
87
+ interface ToastAction {
88
+ label: string;
89
+ onClick?: (event: MouseEvent) => void;
90
+ }
91
+
92
+ interface ToastOptions {
93
+ title?: string;
94
+ description?: string;
95
+ variant?: "success" | "info" | "warning" | "destructive";
96
+ duration?: number;
97
+ action?: ToastAction;
98
+ closeButton?: boolean;
99
+ region?: string | Element;
100
+ }
101
+
102
+ interface ToasterNamespace {
103
+ toast(options?: ToastOptions | string): string | null;
104
+ success(message: string, options?: ToastOptions): string | null;
105
+ info(message: string, options?: ToastOptions): string | null;
106
+ warning(message: string, options?: ToastOptions): string | null;
107
+ error(message: string, options?: ToastOptions): string | null;
108
+ dismiss(id?: string): void;
109
+ }
110
+
111
+ /** Reactive-state API (see signals.js for the authoritative JSDoc). */
112
+ interface SignalsNamespace {
113
+ state<T>(
114
+ initialValue: T,
115
+ options?: import("signal-polyfill").Signal.Options<T>,
116
+ ): import("signal-polyfill").Signal.State<T>;
117
+ computed<T>(
118
+ computation: () => T,
119
+ options?: import("signal-polyfill").Signal.Options<T>,
120
+ ): import("signal-polyfill").Signal.Computed<T>;
121
+ effect(callback: () => void | (() => void), options?: { signal?: AbortSignal }): () => void;
122
+ }
123
+
124
+ interface Window {
125
+ navigation: Navigation;
126
+ Utils: UtilsNamespace;
127
+ /** Set by signals.js — the TC39 signals wrapper (state/computed/effect). */
128
+ Signals: SignalsNamespace;
129
+ Reveal: RevealConstructor;
130
+ /** Set by toaster.js — the imperative toast API. */
131
+ Toaster: ToasterNamespace;
132
+ EmblaInit: {
133
+ init: (scope?: Document | Element) => void;
134
+ initRoot: (emblaNode: Element) => void;
135
+ addDotBtnsAndClickHandlers: (
136
+ emblaApi: EmblaCarouselType,
137
+ dotsNode: Element,
138
+ ) => (() => void) | undefined;
139
+ addThumbClickHandlers: (
140
+ emblaApiMain: EmblaCarouselType,
141
+ emblaApiThumb: EmblaCarouselType,
142
+ ) => void;
143
+ addTogglethumbsActive: (
144
+ emblaApiMain: EmblaCarouselType,
145
+ emblaApiThumb: EmblaCarouselType,
146
+ ) => void;
147
+ };
148
+ }
package/src/head.d.ts ADDED
@@ -0,0 +1,95 @@
1
+ /** One pinned third-party file served from jsDelivr. */
2
+ interface CdnDependency {
3
+ /** npm package name: doubles as the import-map specifier for ESM deps. */
4
+ name: string;
5
+ /** Exact pinned version. Bump deliberately; then refresh `integrity`. */
6
+ version: string;
7
+ /** Static file within the package (never a generated `/+esm` bundle). */
8
+ file: string;
9
+ /**
10
+ * `sha384` SRI hash of the pinned file. Regenerate after a version bump:
11
+ * `curl -sL <url> | openssl dgst -sha384 -binary | openssl base64 -A`
12
+ */
13
+ integrity: string;
14
+ }
15
+ /**
16
+ * @description Builds the pinned jsDelivr URL for a dependency.
17
+ *
18
+ * @param dep - The dependency entry.
19
+ * @returns The versioned URL.
20
+ * @private
21
+ */
22
+ declare function cdnUrl(dep: CdnDependency): string;
23
+ /**
24
+ * ES-module dependencies the kit's module graph imports by bare specifier.
25
+ * The import map points each specifier at its pinned static file; in tests and
26
+ * bundlers the same specifiers resolve from `node_modules` instead (the
27
+ * versions here must match the installed packages: `head.test.ts` pins that).
28
+ */
29
+ declare const ESM_DEPENDENCIES: readonly CdnDependency[];
30
+ /**
31
+ * Feature polyfills loaded as script tags ahead of the kit module: the Popover
32
+ * API (menus, tooltips, the toaster region) and Invoker Commands
33
+ * (`command`/`commandfor`). Native in current engines (2026); the polyfills
34
+ * keep older browsers consistent.
35
+ */
36
+ declare const POLYFILLS: readonly CdnDependency[];
37
+ /** CDN mode for `buildHead` — kit files served from jsDelivr (ticket 06). */
38
+ export interface CdnHeadOptions {
39
+ /** Exact published `@zazz-ui/core` version (`"0.1.0"`; never a dist-tag). */
40
+ version: string;
41
+ /**
42
+ * Granular grain: the primitives this page uses. Their dependency closure
43
+ * (via the kit manifest) decides which css/js files load. Omit for the
44
+ * bundle grain (`dist/zazz.css` + `dist/zazz.js`, whole kit, two requests).
45
+ */
46
+ primitives?: string[];
47
+ /**
48
+ * The version's `dist/sri.json` contents (package-relative path → sha384).
49
+ * When provided, every kit URL gets `integrity` + `crossorigin` (links and
50
+ * script tags directly; transitive module imports via the import map's
51
+ * `integrity` section). Omitted → plain pinned URLs.
52
+ */
53
+ sri?: Record<string, string>;
54
+ }
55
+ /** Options for `buildHead`. */
56
+ export interface HeadOptions {
57
+ /**
58
+ * URL prefix to the kit's `src/` contents, no trailing slash — where
59
+ * `index.css` and `index.js` live. Default `"./zazz"` (the documented copy
60
+ * location); the docs preview iframe passes `"/zazz/src"`.
61
+ */
62
+ base?: string;
63
+ /**
64
+ * Serve the kit from jsDelivr instead of a local copy: pinned, optionally
65
+ * SRI-checked URLs into the published package. Mutually exclusive with
66
+ * `base`.
67
+ */
68
+ cdn?: CdnHeadOptions;
69
+ /**
70
+ * Load component behavior: the import map, the polyfills, and the
71
+ * `index.js` module. `false` renders a style-only head. Default `true`.
72
+ */
73
+ scripts?: boolean;
74
+ /** Geist font loading; `false` skips the block entirely. Default `"swap"`. */
75
+ fontDisplay?: "swap" | "optional" | false;
76
+ /** Include the inline theme-persistence script (last in head). Default `true`. */
77
+ theme?: boolean;
78
+ }
79
+ /**
80
+ * @description Builds the canonical Zazz `<head>` contents: meta tags, fonts,
81
+ * the single stylesheet link, and (unless `scripts: false`) the import map,
82
+ * polyfills, and `index.js` module tag, ending with the theme script. Page
83
+ * specifics (`<title>`, prefetch hints, override stylesheets) belong after
84
+ * this block, outside the contract.
85
+ *
86
+ * @param options - See `HeadOptions`.
87
+ * @returns The head markup (no surrounding `<head>` tag).
88
+ * @example
89
+ * buildHead(); // full head for "./zazz"
90
+ * buildHead({ base: "/zazz/src", scripts: false, fontDisplay: "optional" });
91
+ */
92
+ export declare function buildHead(options?: HeadOptions): string;
93
+ export { ESM_DEPENDENCIES, POLYFILLS, cdnUrl };
94
+ export type { CdnDependency };
95
+ //# sourceMappingURL=head.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"head.d.ts","sourceRoot":"","sources":["head.ts"],"names":[],"mappings":"AA8BA,wDAAwD;AACxD,UAAU,aAAa;IACrB,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB;AA2CD;;;;;;GAMG;AACH,iBAAS,MAAM,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAE1C;AAED;;;;;GAKG;AACH,QAAA,MAAM,gBAAgB,EAAE,SAAS,aAAa,EA+B7C,CAAC;AAEF;;;;;GAKG;AACH,QAAA,MAAM,SAAS,EAAE,SAAS,aAAa,EAatC,CAAC;AAkFF,6EAA6E;AAC7E,MAAM,WAAW,cAAc;IAC7B,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED,+BAA+B;AAC/B,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8EAA8E;IAC9E,WAAW,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,KAAK,CAAC;IAC1C,kFAAkF;IAClF,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,WAAgB,GAAG,MAAM,CAoC3D;AAqGD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;AAC/C,YAAY,EAAE,aAAa,EAAE,CAAC"}