@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,379 @@
1
+ "use strict";
2
+
3
+ import { registerRefresh } from "./zazz-element.ts";
4
+
5
+ interface RevealConfig {
6
+ /** Margin around the root (viewport) for IntersectionObserver. */
7
+ margin: string;
8
+ /** Visibility threshold (0–1) to trigger animations. */
9
+ threshold: number;
10
+ /** Default animation duration (ms number or CSS time string). */
11
+ duration: number | string;
12
+ /** Default animation timing function. */
13
+ ease: string;
14
+ /** Default base animation delay in milliseconds. */
15
+ wait: number;
16
+ /** Default translation distance for slide animations. */
17
+ distance: string;
18
+ /** Default delay between staggered elements in milliseconds. */
19
+ step: number;
20
+ /** Scale factor for grow animations (< 1). */
21
+ grow: number;
22
+ /** Scale factor for shrink animations (> 1). */
23
+ shrink: number;
24
+ }
25
+
26
+ interface RevealOptions {
27
+ /** Configuration options for the animation system. */
28
+ config?: Partial<RevealConfig>;
29
+ }
30
+
31
+ /**
32
+ * @fileoverview Scroll-based reveal animations.
33
+ * @description A lightweight, configurable animation system for scroll-based
34
+ * reveals and staggered animations, focused on viewport entry.
35
+ *
36
+ * @example
37
+ * <!-- Single element -->
38
+ * <div data-reveal="slide-up" data-reveal-duration="300">Content</div>
39
+ *
40
+ * @example
41
+ * <!-- Stagger group (direct children are animated) -->
42
+ * <div data-reveal-each="fade" data-reveal-step="100">
43
+ * <div>Item 1</div>
44
+ * <div>Item 2</div>
45
+ * </div>
46
+ */
47
+
48
+ /**
49
+ * @description Reads a CSS custom property from `:root` computed styles.
50
+ * @param name - Custom property name (e.g. "--ui-reveal-global-duration").
51
+ * @returns Trimmed value, or "" when unset.
52
+ */
53
+ function getRootCssVar(name: string): string {
54
+ return getComputedStyle(document.documentElement).getPropertyValue(name).trim();
55
+ }
56
+
57
+ /**
58
+ * @description Whether the engine computes stagger delays natively: reveal.css
59
+ * derives each child's `--ui-reveal-wait` from `sibling-index()`. Where
60
+ * unsupported (Firefox), `#configureStaggerGroup` falls back to writing a
61
+ * per-child `--ui-reveal-wait` inline.
62
+ */
63
+ const supportsSiblingIndex =
64
+ typeof CSS !== "undefined" && CSS.supports("top", "calc(sibling-index() * 1px)");
65
+
66
+ /**
67
+ * @description Parses a CSS time value into milliseconds.
68
+ * @param value - CSS time string (e.g. "300ms", "0.5s") or bare number string.
69
+ * @returns Duration in milliseconds.
70
+ */
71
+ function parseCssTimeMs(value: string): number {
72
+ const str = value.trim();
73
+ if (!str) return 0;
74
+ if (/^-?\d*\.?\d+ms$/.test(str)) return parseFloat(str);
75
+ if (/^-?\d*\.?\d+s$/.test(str)) return parseFloat(str) * 1000;
76
+ return parseInt(str, 10) || 0;
77
+ }
78
+
79
+ /**
80
+ * @class
81
+ * @description Initializes viewport entry animations.
82
+ *
83
+ * @example
84
+ * const reveal = new Reveal();
85
+ *
86
+ * @example
87
+ * const reveal = new Reveal({
88
+ * config: {
89
+ * duration: 400,
90
+ * ease: "ease-in-out",
91
+ * threshold: 0.3,
92
+ * margin: "100px",
93
+ * step: 40,
94
+ * },
95
+ * });
96
+ */
97
+ class Reveal {
98
+ /**
99
+ * @description Prevents automatic initialization on DOM ready.
100
+ * Assigned below (browser environments only).
101
+ */
102
+ declare static disableAutoInit: () => void;
103
+
104
+ /**
105
+ * @description Returns the auto-initialized Reveal instance, if any.
106
+ * Assigned below (browser environments only).
107
+ */
108
+ declare static getAutoInstance: () => Reveal | null;
109
+
110
+ /**
111
+ * @description Default config from `--ui-reveal-global-*` tokens in `_reveal.css`.
112
+ */
113
+ static #readDefaultConfig(): RevealConfig {
114
+ return {
115
+ margin: "0px",
116
+ threshold: 0.2,
117
+ duration: getRootCssVar("--ui-reveal-global-duration") || "400ms",
118
+ ease: getRootCssVar("--ui-reveal-global-ease") || "cubic-bezier(0.4, 0, 0.2, 1)",
119
+ wait: parseCssTimeMs(getRootCssVar("--ui-reveal-global-wait")),
120
+ distance: getRootCssVar("--ui-reveal-global-distance") || "1rem",
121
+ step: 80,
122
+ grow: parseFloat(getRootCssVar("--ui-reveal-global-grow")) || 0.97,
123
+ shrink: parseFloat(getRootCssVar("--ui-reveal-global-shrink")) || 1.03,
124
+ };
125
+ }
126
+
127
+ static get defaultConfig(): RevealConfig {
128
+ return Reveal.#readDefaultConfig();
129
+ }
130
+
131
+ #observers = new Map<string, IntersectionObserver>();
132
+
133
+ config: RevealConfig;
134
+
135
+ /**
136
+ * @description Creates a new Reveal instance.
137
+ *
138
+ * @param options - Configuration options.
139
+ */
140
+ constructor(options: RevealOptions = {}) {
141
+ this.config = { ...Reveal.defaultConfig, ...options.config };
142
+ this.init();
143
+ }
144
+
145
+ /**
146
+ * @description Gets or creates an IntersectionObserver for a given set of options.
147
+ *
148
+ * @param options - Observer options.
149
+ * @returns The observer instance.
150
+ */
151
+ #getObserver(options: IntersectionObserverInit): IntersectionObserver {
152
+ const optionsKey = JSON.stringify(options);
153
+ let observer = this.#observers.get(optionsKey);
154
+ if (!observer) {
155
+ observer = new IntersectionObserver((entries, obs) => {
156
+ entries.forEach((entry) => {
157
+ if (entry.isIntersecting) {
158
+ entry.target.classList.add("in-viewport");
159
+ obs.unobserve(entry.target);
160
+ }
161
+ });
162
+ }, options);
163
+ this.#observers.set(optionsKey, observer);
164
+ }
165
+ return observer;
166
+ }
167
+
168
+ /**
169
+ * @description Gets IntersectionObserver options for an element.
170
+ *
171
+ * @param element - The element to get options for.
172
+ * @returns Observer configuration options.
173
+ */
174
+ #getElementObserverOptions(element: HTMLElement): IntersectionObserverInit {
175
+ const margin = element.dataset.revealMargin || this.config.margin;
176
+ const threshold = parseFloat(
177
+ element.dataset.revealThreshold || this.config.threshold.toString(),
178
+ );
179
+ return {
180
+ rootMargin: margin,
181
+ threshold: Math.min(Math.max(threshold, 0), 1),
182
+ };
183
+ }
184
+
185
+ /**
186
+ * @description Normalizes a duration to a CSS time value without duplicating units.
187
+ *
188
+ * @param value - Milliseconds as a number, or a CSS time string.
189
+ * @returns A CSS time value (e.g. "300ms", "0.333s").
190
+ */
191
+ #formatTime(value: number | string): string {
192
+ const str = value.toString().trim();
193
+ if (/^-?\d*\.?\d+(ms|s)$/.test(str)) return str;
194
+ return `${Math.max(0, parseInt(str, 10) || 0)}ms`;
195
+ }
196
+
197
+ /**
198
+ * @description Sets CSS custom properties on an element when a value is provided.
199
+ *
200
+ * @param element - The element to set properties on.
201
+ * @param properties - CSS custom properties to set.
202
+ */
203
+ #setRevealProperties(
204
+ element: HTMLElement,
205
+ properties: Record<string, string | number | null | undefined>,
206
+ ): void {
207
+ Object.entries(properties).forEach(([key, value]) => {
208
+ if (value !== null && value !== undefined) {
209
+ element.style.setProperty(key, value.toString());
210
+ }
211
+ });
212
+ }
213
+
214
+ /**
215
+ * @description Configures stagger animation properties and observes child elements.
216
+ *
217
+ * The stagger delay (`base + step × position`) is computed natively where
218
+ * possible: the group carries `--ui-reveal-stagger-base`/`--ui-reveal-stagger-step`
219
+ * and each child derives its own `--ui-reveal-wait` via `sibling-index()` in
220
+ * reveal.css (reversed groups count from the end via `sibling-count()`).
221
+ * Where unsupported (Firefox), the same math runs here and lands as a
222
+ * per-child inline `--ui-reveal-wait`.
223
+ *
224
+ * @param groupElement - The parent stagger container.
225
+ */
226
+ #configureStaggerGroup(groupElement: HTMLElement): void {
227
+ const dataset = groupElement.dataset;
228
+ const groupOptions = this.#getElementObserverOptions(groupElement);
229
+ const groupObserver = this.#getObserver(groupOptions);
230
+
231
+ const groupProps = {
232
+ step: Math.max(0, parseInt(dataset.revealStep || this.config.step.toString(), 10) || 0),
233
+ duration: dataset.revealDuration
234
+ ? Math.max(0, parseInt(dataset.revealDuration, 10) || 0)
235
+ : this.config.duration,
236
+ ease: dataset.revealEase || this.config.ease,
237
+ baseWait: Math.max(0, parseInt(dataset.revealWait || this.config.wait.toString(), 10) || 0),
238
+ distance: dataset.revealDistance || this.config.distance,
239
+ order: dataset.revealOrder,
240
+ };
241
+
242
+ const childrenArray = Array.from(groupElement.children);
243
+ const sequence = groupProps.order === "reversed" ? childrenArray.reverse() : childrenArray;
244
+
245
+ if (supportsSiblingIndex) {
246
+ this.#setRevealProperties(groupElement, {
247
+ "--ui-reveal-stagger-base": `${groupProps.baseWait}ms`,
248
+ "--ui-reveal-stagger-step": `${groupProps.step}ms`,
249
+ });
250
+ }
251
+
252
+ sequence.forEach((child, i) => {
253
+ if (!(child instanceof HTMLElement)) return;
254
+
255
+ this.#setRevealProperties(child, {
256
+ "--ui-reveal-duration": this.#formatTime(groupProps.duration),
257
+ "--ui-reveal-ease": groupProps.ease,
258
+ // Fallback only: natively each child computes this in reveal.css.
259
+ "--ui-reveal-wait": supportsSiblingIndex
260
+ ? null
261
+ : `${groupProps.baseWait + groupProps.step * i}ms`,
262
+ "--ui-reveal-distance": groupProps.distance,
263
+ "--ui-reveal-scale": dataset.revealScale || null,
264
+ });
265
+
266
+ groupObserver.observe(child);
267
+ });
268
+ }
269
+
270
+ /**
271
+ * @description Configures animation properties for a single element and observes it.
272
+ *
273
+ * @param element - The element to configure and observe.
274
+ */
275
+ #configureSingleElement(element: HTMLElement): void {
276
+ const dataset = element.dataset;
277
+ const elementOptions = this.#getElementObserverOptions(element);
278
+ const elementObserver = this.#getObserver(elementOptions);
279
+
280
+ const elementDuration = dataset.revealDuration
281
+ ? Math.max(0, parseInt(dataset.revealDuration, 10) || 0)
282
+ : null;
283
+ const elementWait = dataset.revealWait
284
+ ? Math.max(0, parseInt(dataset.revealWait, 10) || 0)
285
+ : null;
286
+
287
+ this.#setRevealProperties(element, {
288
+ "--ui-reveal-duration": elementDuration !== null ? this.#formatTime(elementDuration) : null,
289
+ "--ui-reveal-wait": elementWait !== null ? this.#formatTime(elementWait) : null,
290
+ "--ui-reveal-ease": dataset.revealEase || null,
291
+ "--ui-reveal-distance": dataset.revealDistance || null,
292
+ "--ui-reveal-scale": dataset.revealScale || null,
293
+ });
294
+
295
+ elementObserver.observe(element);
296
+ }
297
+
298
+ /**
299
+ * @description Initializes the animation system by setting global CSS variables
300
+ * and configuring all animated elements.
301
+ */
302
+ init(): void {
303
+ this.#observers.forEach((observer) => observer.disconnect());
304
+ this.#observers.clear();
305
+
306
+ const rootStyle = document.documentElement.style;
307
+ rootStyle.setProperty("--ui-reveal-global-duration", this.#formatTime(this.config.duration));
308
+ rootStyle.setProperty("--ui-reveal-global-ease", this.config.ease);
309
+ rootStyle.setProperty("--ui-reveal-global-wait", this.#formatTime(this.config.wait));
310
+ rootStyle.setProperty("--ui-reveal-global-distance", this.config.distance);
311
+ rootStyle.setProperty("--ui-reveal-global-grow", this.config.grow.toString());
312
+ rootStyle.setProperty("--ui-reveal-global-shrink", this.config.shrink.toString());
313
+
314
+ document.querySelectorAll("[data-reveal]").forEach((element) => {
315
+ if (element instanceof HTMLElement) this.#configureSingleElement(element);
316
+ });
317
+
318
+ document.querySelectorAll("[data-reveal-each]").forEach((group) => {
319
+ if (group instanceof HTMLElement) this.#configureStaggerGroup(group);
320
+ });
321
+ }
322
+
323
+ /**
324
+ * @description Reinitializes the animation system after dynamically adding elements.
325
+ *
326
+ * Disconnects old observers and rescans the document.
327
+ *
328
+ * @example
329
+ * container.innerHTML = newContent;
330
+ * reveal.refresh();
331
+ */
332
+ refresh(): void {
333
+ this.init();
334
+ }
335
+ }
336
+
337
+ // Auto-initialize when DOM is ready (only in browser environment)
338
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
339
+ let autoInstance: Reveal | null | "disabled" = null;
340
+
341
+ const autoInit = () => {
342
+ if (!autoInstance) {
343
+ autoInstance = new Reveal();
344
+ }
345
+ };
346
+
347
+ if (document.readyState === "loading") {
348
+ document.addEventListener("DOMContentLoaded", autoInit);
349
+ } else {
350
+ autoInit();
351
+ }
352
+
353
+ // After a SPA <main> swap, re-scan the new content for [data-reveal] targets.
354
+ registerRefresh(() => Reveal.getAutoInstance()?.refresh());
355
+
356
+ /**
357
+ * @description Prevents automatic initialization on DOM ready.
358
+ */
359
+ Reveal.disableAutoInit = () => {
360
+ autoInstance = "disabled";
361
+ };
362
+
363
+ /**
364
+ * @description Returns the auto-initialized Reveal instance, if any.
365
+ *
366
+ * @returns The auto instance, or null when disabled or not yet created.
367
+ */
368
+ Reveal.getAutoInstance = () => {
369
+ return autoInstance === "disabled" ? null : autoInstance;
370
+ };
371
+ }
372
+
373
+ // Attach to window for the documented public API (`window.Reveal`, `new Reveal()`),
374
+ // and export for module consumers (navigation.js imports it via the main.js bundle).
375
+ if (typeof window !== "undefined") {
376
+ window.Reveal = Reveal;
377
+ }
378
+
379
+ export { Reveal };
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @fileoverview TC39 Signals wrapper: the kit reactive-state seam.
3
+ * @description Zazz bets on the TC39 Signals proposal for component state. This
4
+ * module is the only file in the kit allowed to import `signal-polyfill`;
5
+ * component scripts import `state`, `computed`, and `effect` from here, so when
6
+ * the proposal's API shifts or engines ship native signals, one file changes.
7
+ *
8
+ * Division of labor (how Zazz components use signals):
9
+ * - DOM events and observers are **input adapters**: they write into `state`.
10
+ * - `computed` holds **pure derived logic**: the unit-testable part.
11
+ * - `effect` is the **output adapter**: it writes results back to the DOM.
12
+ * Imperative concerns (timers, transition choreography, DOM construction) stay
13
+ * imperative; the DOM itself remains the source of truth for element lists.
14
+ *
15
+ * The bare `signal-polyfill` specifier resolves through the page's import map in
16
+ * browsers (pinned jsDelivr URL) and through `node_modules` in tests/bundlers.
17
+ *
18
+ * @see https://github.com/tc39/proposal-signals
19
+ * @see https://github.com/proposal-signals/signal-polyfill
20
+ */
21
+ import { Signal } from "signal-polyfill";
22
+ /**
23
+ * @description Creates a mutable signal: a reactive value read with `.get()`
24
+ * and written with `.set()`. Reads inside `computed`/`effect` are tracked.
25
+ *
26
+ * @param initialValue - The starting value.
27
+ * @param options - Signal options (e.g. a custom `equals`).
28
+ * @returns The state signal.
29
+ * @example
30
+ * const expanded = state(false);
31
+ * expanded.set(true);
32
+ */
33
+ declare function state<T>(initialValue: T, options?: Signal.Options<T>): Signal.State<T>;
34
+ /**
35
+ * @description Creates a derived signal: recomputed lazily when a tracked
36
+ * dependency changes, cached otherwise. Keep the computation pure.
37
+ *
38
+ * @param computation - Pure function deriving the value from other signals.
39
+ * @param options - Signal options (e.g. a custom `equals`).
40
+ * @returns The computed signal.
41
+ * @example
42
+ * const paused = computed(() => expanded.get() || hidden.get());
43
+ */
44
+ declare function computed<T>(computation: () => T, options?: Signal.Options<T>): Signal.Computed<T>;
45
+ /** Options for `effect`. */
46
+ interface EffectOptions {
47
+ /** Aborting disposes the effect: pass an element's controller signal. */
48
+ signal?: AbortSignal;
49
+ }
50
+ /** An effect callback returns either nothing or a cleanup function. */
51
+ type EffectCallback = () => void | (() => void);
52
+ /** The disposer `effect` returns: callable, and a `using`-compatible `Disposable`. */
53
+ type EffectDispose = (() => void) & Disposable;
54
+ /**
55
+ * @description Runs `callback` immediately, tracks every signal it reads, and
56
+ * re-runs it (batched to a microtask) whenever one changes. The callback may
57
+ * return a cleanup function, run before each re-run and on disposal.
58
+ *
59
+ * @param callback - The tracked side effect.
60
+ * @param options - Pass an element's `AbortSignal` to tie disposal to teardown.
61
+ * @returns A dispose function (idempotent; also invoked by the abort signal).
62
+ * It implements `Symbol.dispose`, so a scoped effect (TypeScript sources only)
63
+ * can be bound with `using` and disposed automatically at scope exit.
64
+ * @example
65
+ * const dispose = effect(() => {
66
+ * node.dataset.paused = String(paused.get());
67
+ * });
68
+ * @example
69
+ * using dispose = effect(() => track(count.get())); // disposed at scope exit
70
+ */
71
+ declare function effect(callback: EffectCallback, options?: EffectOptions): EffectDispose;
72
+ /**
73
+ * @namespace Signals
74
+ * @description Reactive state for Zazz components, wrapping the TC39 Signals
75
+ * polyfill. Import `state`/`computed`/`effect` from this module, never from
76
+ * `signal-polyfill` directly.
77
+ *
78
+ * @property state - Creates a mutable signal.
79
+ * @property computed - Creates a pure derived signal.
80
+ * @property effect - Runs a tracked side effect with batched re-runs.
81
+ */
82
+ declare const Signals: {
83
+ state: typeof state;
84
+ computed: typeof computed;
85
+ effect: typeof effect;
86
+ };
87
+ export { Signals, state, computed, effect };
88
+ export type { EffectCallback, EffectDispose, EffectOptions };
89
+ //# sourceMappingURL=signals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signals.d.ts","sourceRoot":"","sources":["signals.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAUzC;;;;;;;;;;GAUG;AACH,iBAAS,KAAK,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAE/E;AAED;;;;;;;;;GASG;AACH,iBAAS,QAAQ,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAE1F;AAID,4BAA4B;AAC5B,UAAU,aAAa;IACrB,yEAAyE;IACzE,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,uEAAuE;AACvE,KAAK,cAAc,GAAG,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;AAEhD,sFAAsF;AACtF,KAAK,aAAa,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,UAAU,CAAC;AA4B/C;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAS,MAAM,CAAC,QAAQ,EAAE,cAAc,EAAE,OAAO,GAAE,aAAkB,GAAG,aAAa,CAsBpF;AAID;;;;;;;;;GASG;AACH,QAAA,MAAM,OAAO;;;;CAA8B,CAAC;AAO5C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC5C,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview TC39 Signals wrapper: the kit reactive-state seam.
4
+ * @description Zazz bets on the TC39 Signals proposal for component state. This
5
+ * module is the only file in the kit allowed to import `signal-polyfill`;
6
+ * component scripts import `state`, `computed`, and `effect` from here, so when
7
+ * the proposal's API shifts or engines ship native signals, one file changes.
8
+ *
9
+ * Division of labor (how Zazz components use signals):
10
+ * - DOM events and observers are **input adapters**: they write into `state`.
11
+ * - `computed` holds **pure derived logic**: the unit-testable part.
12
+ * - `effect` is the **output adapter**: it writes results back to the DOM.
13
+ * Imperative concerns (timers, transition choreography, DOM construction) stay
14
+ * imperative; the DOM itself remains the source of truth for element lists.
15
+ *
16
+ * The bare `signal-polyfill` specifier resolves through the page's import map in
17
+ * browsers (pinned jsDelivr URL) and through `node_modules` in tests/bundlers.
18
+ *
19
+ * @see https://github.com/tc39/proposal-signals
20
+ * @see https://github.com/proposal-signals/signal-polyfill
21
+ */
22
+ import { Signal } from "signal-polyfill";
23
+ // The disposer `effect` returns implements the dispose protocol, and `using`
24
+ // compiles (target ES2022) to try/finally helpers that read this well-known
25
+ // symbol at runtime; engines without native Explicit Resource Management
26
+ // (Safari) don't define it, so give them a local stand-in.
27
+ Symbol.dispose ??= Symbol("Symbol.dispose");
28
+ // --- State and computed ---
29
+ /**
30
+ * @description Creates a mutable signal: a reactive value read with `.get()`
31
+ * and written with `.set()`. Reads inside `computed`/`effect` are tracked.
32
+ *
33
+ * @param initialValue - The starting value.
34
+ * @param options - Signal options (e.g. a custom `equals`).
35
+ * @returns The state signal.
36
+ * @example
37
+ * const expanded = state(false);
38
+ * expanded.set(true);
39
+ */
40
+ function state(initialValue, options) {
41
+ return new Signal.State(initialValue, options);
42
+ }
43
+ /**
44
+ * @description Creates a derived signal: recomputed lazily when a tracked
45
+ * dependency changes, cached otherwise. Keep the computation pure.
46
+ *
47
+ * @param computation - Pure function deriving the value from other signals.
48
+ * @param options - Signal options (e.g. a custom `equals`).
49
+ * @returns The computed signal.
50
+ * @example
51
+ * const paused = computed(() => expanded.get() || hidden.get());
52
+ */
53
+ function computed(computation, options) {
54
+ return new Signal.Computed(computation, options);
55
+ }
56
+ // The proposal deliberately ships no effect(): this is the reference
57
+ // implementation from the polyfill README: one shared Watcher notifies
58
+ // synchronously on the first dirty signal, and re-runs are batched to a
59
+ // microtask so N writes in one task trigger one re-run.
60
+ let needsEnqueue = true;
61
+ const watcher = new Signal.subtle.Watcher(() => {
62
+ if (needsEnqueue) {
63
+ needsEnqueue = false;
64
+ queueMicrotask(processPending);
65
+ }
66
+ });
67
+ /**
68
+ * @description Re-runs every dirty effect and re-arms the watcher.
69
+ *
70
+ * @private
71
+ */
72
+ function processPending() {
73
+ needsEnqueue = true;
74
+ for (const dirty of watcher.getPending()) {
75
+ dirty.get();
76
+ }
77
+ watcher.watch();
78
+ }
79
+ /**
80
+ * @description Runs `callback` immediately, tracks every signal it reads, and
81
+ * re-runs it (batched to a microtask) whenever one changes. The callback may
82
+ * return a cleanup function, run before each re-run and on disposal.
83
+ *
84
+ * @param callback - The tracked side effect.
85
+ * @param options - Pass an element's `AbortSignal` to tie disposal to teardown.
86
+ * @returns A dispose function (idempotent; also invoked by the abort signal).
87
+ * It implements `Symbol.dispose`, so a scoped effect (TypeScript sources only)
88
+ * can be bound with `using` and disposed automatically at scope exit.
89
+ * @example
90
+ * const dispose = effect(() => {
91
+ * node.dataset.paused = String(paused.get());
92
+ * });
93
+ * @example
94
+ * using dispose = effect(() => track(count.get())); // disposed at scope exit
95
+ */
96
+ function effect(callback, options = {}) {
97
+ let cleanup;
98
+ let disposed = false;
99
+ const tracked = new Signal.Computed(() => {
100
+ if (typeof cleanup === "function")
101
+ cleanup();
102
+ cleanup = callback();
103
+ });
104
+ watcher.watch(tracked);
105
+ tracked.get();
106
+ const dispose = () => {
107
+ if (disposed)
108
+ return;
109
+ disposed = true;
110
+ watcher.unwatch(tracked);
111
+ if (typeof cleanup === "function")
112
+ cleanup();
113
+ cleanup = undefined;
114
+ };
115
+ options.signal?.addEventListener("abort", dispose, { once: true });
116
+ return Object.assign(dispose, { [Symbol.dispose]: dispose });
117
+ }
118
+ // --- Public API ---
119
+ /**
120
+ * @namespace Signals
121
+ * @description Reactive state for Zazz components, wrapping the TC39 Signals
122
+ * polyfill. Import `state`/`computed`/`effect` from this module, never from
123
+ * `signal-polyfill` directly.
124
+ *
125
+ * @property state - Creates a mutable signal.
126
+ * @property computed - Creates a pure derived signal.
127
+ * @property effect - Runs a tracked side effect with batched re-runs.
128
+ */
129
+ const Signals = { state, computed, effect };
130
+ // Attach to window for the documented public API, then export for module consumers.
131
+ if (typeof window !== "undefined") {
132
+ window.Signals = Signals;
133
+ }
134
+ export { Signals, state, computed, effect };