@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,643 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Embla Carousel initialization and controls.
4
+ * @description Discovers carousel roots (`<ui-carousel>` or `.ui-carousel`),
5
+ * initializes Embla instances with optional plugins, and wires navigation,
6
+ * keyboard, and dialog-open behaviors (subscribing to `zazz:dialog-open`
7
+ * from base/dialog-lifecycle.ts; lightbox choreography lives in lightbox.ts).
8
+ *
9
+ * Structure: root is the element/class itself; parts are slots (`data-slot="carousel-<part>"`):
10
+ * - root (`<ui-carousel>` | `.ui-carousel`): Carousel container; holds all config attributes
11
+ * - `carousel-viewport`: Visible window (required)
12
+ * - `carousel-container`: Slides flex track
13
+ * - `carousel-slide`: Individual slide
14
+ * - `carousel-prev` / `carousel-next`: Navigation buttons (optional)
15
+ * - `carousel-dots` / `carousel-dot`: Dot pagination container and template dot (optional)
16
+ * - `carousel-thumbs`: Linked thumb carousel container (optional)
17
+ *
18
+ * thumb navigation (on `data-slot="carousel-thumbs"`):
19
+ * - `data-carousel-thumbs-*`: thumb carousel options (defaults: containScroll keepSnaps, dragFree true)
20
+ * - Syncs with the main carousel in the same root
21
+ *
22
+ * Lifecycle and dialog start index:
23
+ * - `data-carousel-init`: Set by script when a carousel is initialized
24
+ * - `data-carousel-start`: On a trigger; slide index to open to (pairs with commandfor)
25
+ * - `data-carousel-start-index`: Set on root by script; consumed when dialog opens
26
+ * - `data-carousel-keyboard`: Set to `"false"` to disable ArrowLeft/ArrowRight navigation
27
+ *
28
+ * Configuration (on the carousel root: `<ui-carousel>` or `.ui-carousel`):
29
+ * - `data-carousel-*`: Core Embla options
30
+ * - `data-carousel-plugins`: Space-separated plugin slugs (`autoplay`, `auto-scroll`, `class-names`)
31
+ * - `data-carousel-autoplay-*`: Autoplay plugin options (requires `autoplay` in plugins)
32
+ * - `data-carousel-auto-scroll-*`: Auto scroll plugin options (requires `auto-scroll` in plugins)
33
+ * - `data-carousel-class-names-*`: Class names plugin options (requires `class-names` in plugins)
34
+ *
35
+ * @see https://www.embla-carousel.com/docs/api/options#reference
36
+ * @see https://www.embla-carousel.com/docs/plugins/autoplay#options
37
+ * @see https://www.embla-carousel.com/docs/plugins/auto-scroll#options
38
+ * @see https://www.embla-carousel.com/docs/plugins/class-names#options
39
+ * @see https://www.embla-carousel.com/docs/plugins/ssr#options
40
+ *
41
+ * @example
42
+ * data-carousel-loop="true"
43
+ *
44
+ * @example
45
+ * data-carousel-align="start"
46
+ *
47
+ * @example
48
+ * data-carousel-plugins="autoplay" data-carousel-autoplay-delay="3000"
49
+ *
50
+ * @example
51
+ * data-carousel-plugins="auto-scroll" data-carousel-auto-scroll-speed="2"
52
+ *
53
+ * @example
54
+ * data-carousel-plugins="class-names" data-carousel-class-names-snapped="is-snapped"
55
+ *
56
+ * @example Barebones carousel (4 text slides; auto-inits on DOMContentLoaded):
57
+ * <div class="ui-carousel">
58
+ * <div data-slot="carousel-viewport">
59
+ * <div data-slot="carousel-container">
60
+ * <div data-slot="carousel-slide">Slide 1</div>
61
+ * <div data-slot="carousel-slide">Slide 2</div>
62
+ * <div data-slot="carousel-slide">Slide 3</div>
63
+ * <div data-slot="carousel-slide">Slide 4</div>
64
+ * </div>
65
+ * </div>
66
+ * <button type="button" data-slot="carousel-prev">Prev</button>
67
+ * <button type="button" data-slot="carousel-next">Next</button>
68
+ * </div>
69
+ */
70
+ import { Utils } from "./utils.js";
71
+ import { registerRefresh } from "./zazz-element.js";
72
+ // Embla ships as real ES modules: bare specifiers resolve through the page's
73
+ // import map in browsers (pinned jsDelivr URLs; see `head.ts`) and through
74
+ // node_modules in tests/bundlers. No more UMD globals, no tag-order contract.
75
+ import EmblaCarousel from "embla-carousel";
76
+ import EmblaCarouselAutoplay from "embla-carousel-autoplay";
77
+ import EmblaCarouselAutoScroll from "embla-carousel-auto-scroll";
78
+ import EmblaCarouselClassNames from "embla-carousel-class-names";
79
+ /**
80
+ * @description Parses a space-separated `data-carousel-plugins` value into
81
+ * plugin slug tokens. Empty / null / whitespace-only values yield `[]`.
82
+ *
83
+ * @param value - Raw attribute value (or `null` when absent).
84
+ * @returns Plugin slug tokens in authoring order.
85
+ */
86
+ function parseCarouselPlugins(value) {
87
+ if (!value)
88
+ return [];
89
+ return value.trim().split(/\s+/).filter(Boolean);
90
+ }
91
+ /**
92
+ * Map of plugin slug → Embla factory. Slugs match Embla package names
93
+ * (`embla-carousel-auto-scroll`, etc.).
94
+ */
95
+ const PLUGIN_BY_SLUG = {
96
+ autoplay: (node) => EmblaCarouselAutoplay(readCarouselOptions(node, "data-carousel-autoplay-")),
97
+ "auto-scroll": (node) => EmblaCarouselAutoScroll(readCarouselOptions(node, "data-carousel-auto-scroll-")),
98
+ "class-names": (node) => EmblaCarouselClassNames(readCarouselOptions(node, "data-carousel-class-names-")),
99
+ };
100
+ /**
101
+ * @description Reads a node's prefixed `data-carousel-*` attributes as an
102
+ * options object of the shape Embla (or one of its plugins) expects.
103
+ *
104
+ * Attributes are strings, so the parsed values have to be asserted into Embla's
105
+ * option types somewhere. This is that single boundary: the assertion lives
106
+ * here with its justification (Embla validates its own options at runtime)
107
+ * instead of being repeated at every call site.
108
+ *
109
+ * @param node - Element carrying the configuration attributes.
110
+ * @param prefix - Attribute prefix, e.g. `"data-carousel-autoplay-"`.
111
+ * @returns The parsed attributes, typed as `T`.
112
+ * @private
113
+ */
114
+ function readCarouselOptions(node, prefix) {
115
+ return Utils.parseDataAttributes(node, prefix);
116
+ }
117
+ // --- Active-index sync ---
118
+ /**
119
+ * @description Toggles `.is-active` on the node at `selected` and clears it
120
+ * from every other node: the shared "which one is current" marker used by
121
+ * both dot pagination and thumb navigation.
122
+ *
123
+ * @param nodes - Candidate nodes, in slide order.
124
+ * @param selected - The active index.
125
+ * @param options - Set `ariaCurrent` to also toggle `aria-current` (thumb
126
+ * navigation exposes the active thumb to assistive tech; dots don't need it,
127
+ * as their `.is-active` state is purely visual pagination).
128
+ * @private
129
+ */
130
+ function setActiveIndex(nodes, selected, options = {}) {
131
+ nodes.forEach((node, idx) => {
132
+ const active = idx === selected;
133
+ node.classList.toggle("is-active", active);
134
+ if (!options.ariaCurrent)
135
+ return;
136
+ if (active) {
137
+ node.setAttribute("aria-current", "true");
138
+ }
139
+ else {
140
+ node.removeAttribute("aria-current");
141
+ }
142
+ });
143
+ }
144
+ // --- Dot navigation ---
145
+ /**
146
+ * @description Adds dot navigation buttons and click handlers for an Embla carousel.
147
+ *
148
+ * @param emblaApi - The Embla carousel API instance.
149
+ * @param dotsNode - Container element for dot navigation.
150
+ * @param signal - Aborts the dot click listeners on teardown.
151
+ * @returns Cleanup function to remove dots.
152
+ */
153
+ const addDotBtnsAndClickHandlers = (emblaApi, dotsNode, signal) => {
154
+ if (!dotsNode)
155
+ return;
156
+ const templateDot = dotsNode.querySelector('[data-slot~="carousel-dot"]');
157
+ if (!templateDot)
158
+ return;
159
+ let dotNodes = [];
160
+ /**
161
+ * @description Creates dot buttons for each slide and binds click handlers.
162
+ *
163
+ * @private
164
+ */
165
+ const addDotBtnsWithClickHandlers = () => {
166
+ const snapCount = emblaApi.scrollSnapList().length;
167
+ dotsNode.innerHTML = "";
168
+ if (snapCount <= 1) {
169
+ dotNodes = [];
170
+ return;
171
+ }
172
+ dotNodes = [];
173
+ for (let i = 0; i < snapCount; i++) {
174
+ const dot = templateDot.cloneNode(true);
175
+ dotNodes.push(dot);
176
+ dotsNode.appendChild(dot);
177
+ dot.addEventListener("click", () => emblaApi.scrollTo(i), { signal });
178
+ }
179
+ };
180
+ /**
181
+ * @description Updates the active state of dot buttons based on the current slide.
182
+ *
183
+ * @private
184
+ */
185
+ const toggleDotBtnsActive = () => {
186
+ if (!dotNodes.length)
187
+ return;
188
+ setActiveIndex(dotNodes, emblaApi.selectedScrollSnap());
189
+ };
190
+ emblaApi
191
+ .on("init", addDotBtnsWithClickHandlers)
192
+ .on("reInit", addDotBtnsWithClickHandlers)
193
+ .on("init", toggleDotBtnsActive)
194
+ .on("reInit", toggleDotBtnsActive)
195
+ .on("select", toggleDotBtnsActive);
196
+ return () => {
197
+ dotsNode.innerHTML = "";
198
+ };
199
+ };
200
+ // --- thumb navigation ---
201
+ /**
202
+ * @description Adds click handlers on thumb slides to scroll the main carousel.
203
+ *
204
+ * @param emblaApiMain - Main carousel API instance.
205
+ * @param emblaApiThumb - thumb carousel API instance.
206
+ * @param signal - Aborts the thumb click listeners on teardown.
207
+ */
208
+ const addThumbClickHandlers = (emblaApiMain, emblaApiThumb, signal) => {
209
+ const slidesthumbs = emblaApiThumb.slideNodes();
210
+ slidesthumbs.forEach((slideNode, index) => {
211
+ slideNode.addEventListener("click", () => emblaApiMain.scrollTo(index), { signal });
212
+ });
213
+ };
214
+ /**
215
+ * @description Keeps the thumb carousel and active state in sync with the main carousel.
216
+ *
217
+ * @param emblaApiMain - Main carousel API instance.
218
+ * @param emblaApiThumb - thumb carousel API instance.
219
+ */
220
+ const addTogglethumbsActive = (emblaApiMain, emblaApiThumb) => {
221
+ const slidesthumbs = emblaApiThumb.slideNodes();
222
+ /**
223
+ * @description Scrolls thumbs to the selected snap and toggles active classes.
224
+ *
225
+ * @private
226
+ */
227
+ const toggleThumbBtnsActive = () => {
228
+ const selected = emblaApiMain.selectedScrollSnap();
229
+ emblaApiThumb.scrollTo(selected);
230
+ setActiveIndex(slidesthumbs, selected, { ariaCurrent: true });
231
+ };
232
+ emblaApiMain.on("select", toggleThumbBtnsActive);
233
+ toggleThumbBtnsActive();
234
+ };
235
+ // --- Drag-aware click suppression ---
236
+ /**
237
+ * Deadline (ms, `performance.now()`) until which invoker `command` events are
238
+ * cancelled because a carousel drag just ended. Set by bindDragClickSuppression
239
+ * for command-bearing slides (the lightbox stage) and enforced by
240
+ * initCommandDragGuard. A bare `click` guard is not enough: the native /
241
+ * polyfilled invoker opens the dialog from its own `command` dispatch.
242
+ */
243
+ let suppressCommandsUntil = 0;
244
+ /**
245
+ * @description Suppresses click activation immediately after a drag gesture.
246
+ *
247
+ * This prevents click-style actions (invoker commands, thumb navigation clicks)
248
+ * from firing when the intent was dragging the carousel.
249
+ *
250
+ * @param root - Embla root/subtree to monitor.
251
+ * @param emblaApi - Carousel instance tied to this root.
252
+ * @param clickSelector - Click targets to suppress after dragging.
253
+ * @param options - Per-carousel drag tolerance.
254
+ * @param signal - Aborts the pointer/click listeners on teardown.
255
+ */
256
+ function bindDragClickSuppression(root, emblaApi, clickSelector, options = {}, signal) {
257
+ const DRAG_THRESHOLD_PX = options.dragThresholdPx ?? 6;
258
+ const SUPPRESS_WINDOW_MS = 250;
259
+ // Slides that open a dialog (command="show-modal") also need command suppression.
260
+ const guardsCommands = clickSelector.includes("commandfor");
261
+ let pointerDown = false;
262
+ let moved = false;
263
+ let startX = 0;
264
+ let startY = 0;
265
+ let lastX = 0;
266
+ let lastY = 0;
267
+ let snapAtDown = 0;
268
+ let suppressUntil = 0;
269
+ const pointerDistance = () => Math.hypot(lastX - startX, lastY - startY);
270
+ root.addEventListener("pointerdown", (e) => {
271
+ if (!(e instanceof PointerEvent))
272
+ return;
273
+ if (e.pointerType === "mouse" && e.button !== 0)
274
+ return;
275
+ pointerDown = true;
276
+ moved = false;
277
+ startX = e.clientX;
278
+ startY = e.clientY;
279
+ lastX = e.clientX;
280
+ lastY = e.clientY;
281
+ snapAtDown = emblaApi.selectedScrollSnap();
282
+ }, { passive: true, signal });
283
+ root.addEventListener("pointermove", (e) => {
284
+ if (!pointerDown || !(e instanceof PointerEvent))
285
+ return;
286
+ lastX = e.clientX;
287
+ lastY = e.clientY;
288
+ if (moved)
289
+ return;
290
+ if (pointerDistance() >= DRAG_THRESHOLD_PX)
291
+ moved = true;
292
+ }, { passive: true, signal });
293
+ const finalizePointer = () => {
294
+ if (pointerDown && moved) {
295
+ suppressUntil = performance.now() + SUPPRESS_WINDOW_MS;
296
+ if (guardsCommands)
297
+ suppressCommandsUntil = suppressUntil;
298
+ }
299
+ pointerDown = false;
300
+ moved = false;
301
+ };
302
+ root.addEventListener("pointerup", finalizePointer, { passive: true, signal });
303
+ root.addEventListener("pointercancel", finalizePointer, { passive: true, signal });
304
+ emblaApi.on("pointerUp", finalizePointer);
305
+ // Touch/trackpad drags can move with tiny deltas. Treat Embla scroll as drag intent,
306
+ // but lightbox openers need extra tolerance so minor carousel settle does not block clicks.
307
+ emblaApi.on("scroll", () => {
308
+ if (!pointerDown)
309
+ return;
310
+ if (guardsCommands) {
311
+ if (pointerDistance() >= DRAG_THRESHOLD_PX || emblaApi.selectedScrollSnap() !== snapAtDown) {
312
+ moved = true;
313
+ }
314
+ return;
315
+ }
316
+ moved = true;
317
+ });
318
+ root.addEventListener("click", (e) => {
319
+ if (performance.now() > suppressUntil)
320
+ return;
321
+ const target = e.target instanceof Element ? e.target.closest(clickSelector) : null;
322
+ if (!target || !root.contains(target))
323
+ return;
324
+ e.preventDefault();
325
+ e.stopImmediatePropagation();
326
+ }, { capture: true, signal });
327
+ }
328
+ let commandDragGuardBound = false;
329
+ /**
330
+ * @description Cancels invoker `command` events fired right after a carousel drag.
331
+ *
332
+ * Lightbox stage slides carry `command="show-modal"`, so a drag would both scroll
333
+ * the carousel and open the dialog. The `command` event (native or polyfill) is
334
+ * the single point that runs the built-in command, and it is cancelable, so we
335
+ * preventDefault() it within the drag-suppress window. Bound once on `document` in
336
+ * the capture phase; `command` does not bubble, but capture still reaches it.
337
+ */
338
+ function initCommandDragGuard() {
339
+ if (commandDragGuardBound)
340
+ return;
341
+ commandDragGuardBound = true;
342
+ document.addEventListener("command", (e) => {
343
+ if (e.cancelable && performance.now() <= suppressCommandsUntil)
344
+ e.preventDefault();
345
+ }, true);
346
+ }
347
+ // --- Carousel initialization ---
348
+ /**
349
+ * @description Initializes a single Embla carousel root.
350
+ *
351
+ * Configures the carousel from its `data-carousel-*` attributes, wires navigation
352
+ * (prev/next, dots, thumbs), and stores the API on `root._emblaApi`. Idempotent:
353
+ * skips roots that are already initialized or inside a closed dialog (no
354
+ * measurable viewport until open).
355
+ *
356
+ * Called by `initEmblaCarousels()` for class-form (`.ui-carousel`) markup and by
357
+ * the `<ui-carousel>` web component (zazz/scripts/carousel.js) on connect.
358
+ *
359
+ * @param emblaNode - The carousel root element.
360
+ */
361
+ function initEmblaRoot(emblaNode) {
362
+ if (emblaNode.hasAttribute("data-carousel-init"))
363
+ return;
364
+ // Defer init inside closed dialogs: viewport has no measurable size until open
365
+ if (emblaNode.closest("dialog:not([open])"))
366
+ return;
367
+ emblaNode.setAttribute("data-carousel-init", "");
368
+ const emblathumbsNode = emblaNode.querySelector('[data-slot~="carousel-thumbs"]');
369
+ const emblaViewportNode = emblathumbsNode
370
+ ? emblaNode.querySelector('[data-slot~="carousel-viewport"]:not([data-slot~="carousel-thumbs"] *)')
371
+ : emblaNode.querySelector('[data-slot~="carousel-viewport"]');
372
+ const emblaPrevButtonNode = emblaNode.querySelector('[data-slot~="carousel-prev"]');
373
+ const emblaNextButtonNode = emblaNode.querySelector('[data-slot~="carousel-next"]');
374
+ const emblaDotsNode = emblaNode.querySelector('[data-slot~="carousel-dots"]');
375
+ if (!emblaViewportNode)
376
+ return;
377
+ if (!emblaViewportNode.hasAttribute("tabindex")) {
378
+ emblaViewportNode.setAttribute("tabindex", "0");
379
+ }
380
+ const apiOptions = readCarouselOptions(emblaNode, "data-carousel-");
381
+ // Keep kit-only / plugin keys out of core Embla options
382
+ Object.keys(apiOptions).forEach(function (key) {
383
+ if (key === "name" ||
384
+ key === "keyboard" ||
385
+ key === "plugins" ||
386
+ key.startsWith("autoplay") ||
387
+ key.startsWith("autoScroll") ||
388
+ key.startsWith("classNames")) {
389
+ delete apiOptions[key];
390
+ }
391
+ });
392
+ // Veto drag gestures when every slide already fits in the viewport: with a
393
+ // single snap Embla still rubber-bands on drag, which feels broken. The
394
+ // callback re-evaluates on every pointer down, so it stays correct across
395
+ // resizes/reInit. Respect an explicit data-carousel-watch-drag override.
396
+ // @see https://github.com/davidjerleke/embla-carousel/issues/416
397
+ if (!("watchDrag" in apiOptions)) {
398
+ apiOptions.watchDrag = (api) => api.canScrollPrev() || api.canScrollNext();
399
+ }
400
+ // Plugins load only when listed in data-carousel-plugins; option attrs alone
401
+ // do not enable them. Unknown slugs are ignored.
402
+ const plugins = [];
403
+ for (const slug of parseCarouselPlugins(emblaNode.getAttribute("data-carousel-plugins"))) {
404
+ const create = PLUGIN_BY_SLUG[slug];
405
+ if (!create)
406
+ continue;
407
+ plugins.push(create(emblaNode));
408
+ }
409
+ // The options come from untyped data attributes; Embla validates at runtime.
410
+ const emblaApi = EmblaCarousel(emblaViewportNode, apiOptions, plugins);
411
+ emblaNode._emblaApi = emblaApi;
412
+ // One controller per root scopes every carousel listener below; the owner
413
+ // (`<ui-carousel>` disconnectedCallback) aborts it on teardown so the DOM
414
+ // listeners are removed alongside the destroyed Embla instance.
415
+ const controller = new AbortController();
416
+ const { signal } = controller;
417
+ emblaNode._emblaController = controller;
418
+ if (emblaPrevButtonNode) {
419
+ emblaPrevButtonNode.addEventListener("click", () => emblaApi.scrollPrev(), { signal });
420
+ }
421
+ if (emblaNextButtonNode) {
422
+ emblaNextButtonNode.addEventListener("click", () => emblaApi.scrollNext(), { signal });
423
+ }
424
+ if (emblaDotsNode) {
425
+ addDotBtnsAndClickHandlers(emblaApi, emblaDotsNode, signal);
426
+ }
427
+ // Any command-bearing slide (e.g. a lightbox stage slide that opens the
428
+ // dialog) needs its click suppressed when it was really a drag.
429
+ if (emblaNode.querySelector('[data-slot~="carousel-slide"][commandfor]')) {
430
+ bindDragClickSuppression(emblaNode, emblaApi, '[data-slot~="carousel-slide"][commandfor]', { dragThresholdPx: 14 }, signal);
431
+ }
432
+ if (emblathumbsNode) {
433
+ const emblathumbsViewportNode = emblathumbsNode.querySelector('[data-slot~="carousel-viewport"]');
434
+ if (emblathumbsViewportNode) {
435
+ const thumbDefaults = { containScroll: "keepSnaps", dragFree: true };
436
+ const thumbOptions = readCarouselOptions(emblathumbsNode, "data-carousel-thumbs-");
437
+ const emblaApiThumb = EmblaCarousel(emblathumbsViewportNode, {
438
+ ...thumbDefaults,
439
+ ...thumbOptions,
440
+ });
441
+ emblaNode._emblaApiThumb = emblaApiThumb;
442
+ addThumbClickHandlers(emblaApi, emblaApiThumb, signal);
443
+ addTogglethumbsActive(emblaApi, emblaApiThumb);
444
+ bindDragClickSuppression(emblathumbsNode, emblaApiThumb, '[data-slot~="carousel-slide"]', {}, signal);
445
+ }
446
+ }
447
+ }
448
+ /**
449
+ * @description Initializes all Embla carousels within a scope.
450
+ *
451
+ * Discovers carousel elements via `:is(ui-carousel, .ui-carousel)` and configures them
452
+ * based on their data attributes. Roots managed by the `<ui-carousel>` web
453
+ * component are skipped: they initialize themselves via `connectedCallback()`.
454
+ *
455
+ * @param scope - Root element to search within. Defaults to `document`.
456
+ */
457
+ function initEmblaCarousels(scope) {
458
+ const root = scope || document;
459
+ const emblaRoots = root.querySelectorAll(":is(ui-carousel, .ui-carousel)");
460
+ emblaRoots.forEach(function (emblaNode) {
461
+ // <ui-carousel> elements own their lifecycle (init on connect, destroy
462
+ // on disconnect); double-initializing would leak a second Embla instance.
463
+ if (emblaNode.closest("ui-carousel"))
464
+ return;
465
+ initEmblaRoot(emblaNode);
466
+ });
467
+ }
468
+ // --- Dialog open subscription ---
469
+ /**
470
+ * @description Reacts to dialogs opening (via `zazz:dialog-open` from
471
+ * base/dialog-lifecycle.ts; ADR-0003) with the carousel-domain work:
472
+ * initializes class-form roots that deferred while the dialog was
473
+ * `display: none`, applies a stored `data-carousel-start-index`, and focuses
474
+ * the viewport for keyboard navigation.
475
+ *
476
+ * Listens on `document`, so it runs after any dialog- or ancestor-level
477
+ * subscriber (`<ui-carousel>` self-init, `<ui-lightbox>` choreography).
478
+ */
479
+ function initDialogOpenSubscription() {
480
+ document.addEventListener("zazz:dialog-open", function (e) {
481
+ if (!(e.target instanceof HTMLDialogElement))
482
+ return;
483
+ const dialog = e.target;
484
+ initEmblaCarousels(dialog);
485
+ const roots = dialog.querySelectorAll(":is(ui-carousel, .ui-carousel)");
486
+ roots.forEach(function (root) {
487
+ const startIndex = root.getAttribute("data-carousel-start-index");
488
+ if (startIndex != null && root._emblaApi) {
489
+ root._emblaApi.scrollTo(Number(startIndex), true);
490
+ root.removeAttribute("data-carousel-start-index");
491
+ }
492
+ const viewport = root.querySelector('[data-slot~="carousel-viewport"]');
493
+ if (viewport instanceof HTMLElement) {
494
+ viewport.focus({ preventScroll: true });
495
+ }
496
+ });
497
+ });
498
+ }
499
+ // --- Keyboard navigation ---
500
+ /**
501
+ * @description Returns the active Embla root for keyboard navigation.
502
+ *
503
+ * Prefers a carousel inside an open dialog, then the carousel containing focus.
504
+ * Respects `data-carousel-keyboard="false"`.
505
+ *
506
+ * @returns The active carousel root, or null when none applies.
507
+ * @private
508
+ */
509
+ function getActiveEmblaRoot() {
510
+ const openDialog = document.querySelector("dialog[open]");
511
+ if (openDialog) {
512
+ const dialogRoot = openDialog.querySelector(":is(ui-carousel, .ui-carousel)[data-carousel-init]");
513
+ if (dialogRoot?._emblaApi && dialogRoot.getAttribute("data-carousel-keyboard") !== "false") {
514
+ return dialogRoot;
515
+ }
516
+ }
517
+ const focusedRoot = document.activeElement?.closest(":is(ui-carousel, .ui-carousel)[data-carousel-init]");
518
+ if (focusedRoot?._emblaApi && focusedRoot.getAttribute("data-carousel-keyboard") !== "false") {
519
+ return focusedRoot;
520
+ }
521
+ return null;
522
+ }
523
+ /**
524
+ * @description Binds ArrowLeft/ArrowRight keyboard navigation for active carousels.
525
+ *
526
+ * Embla is headless: arrow keys are not built in. Opt out per carousel with
527
+ * `data-carousel-keyboard="false"`.
528
+ */
529
+ const initEmblaKeyboardNav = function () {
530
+ if (initEmblaKeyboardNav._bound)
531
+ return;
532
+ initEmblaKeyboardNav._bound = true;
533
+ document.addEventListener("keydown", function (e) {
534
+ if (e.key !== "ArrowLeft" && e.key !== "ArrowRight")
535
+ return;
536
+ if (e.defaultPrevented)
537
+ return;
538
+ const target = e.target;
539
+ if (!(target instanceof HTMLElement))
540
+ return;
541
+ if (target instanceof HTMLInputElement ||
542
+ target instanceof HTMLTextAreaElement ||
543
+ target instanceof HTMLSelectElement ||
544
+ target.isContentEditable) {
545
+ return;
546
+ }
547
+ const root = getActiveEmblaRoot();
548
+ if (!root)
549
+ return;
550
+ e.preventDefault();
551
+ if (e.key === "ArrowLeft")
552
+ root._emblaApi.scrollPrev();
553
+ else
554
+ root._emblaApi.scrollNext();
555
+ });
556
+ };
557
+ /**
558
+ * @namespace EmblaInit
559
+ * @description Public API for Embla carousel initialization and helpers.
560
+ *
561
+ * @property init - Initializes all carousels within a scope.
562
+ * @property initRoot - Initializes a single carousel root (used by `<ui-carousel>`).
563
+ * @property addDotBtnsAndClickHandlers - Wires dot pagination.
564
+ * @property addThumbClickHandlers - Wires thumb click handlers.
565
+ * @property addTogglethumbsActive - Syncs thumb active state.
566
+ */
567
+ const EmblaInit = {
568
+ init: initEmblaCarousels,
569
+ initRoot: initEmblaRoot,
570
+ addDotBtnsAndClickHandlers,
571
+ addThumbClickHandlers,
572
+ addTogglethumbsActive,
573
+ };
574
+ // --- Start index control ---
575
+ /**
576
+ * @description Stores or applies a start slide index from `[data-carousel-start]` triggers.
577
+ *
578
+ * Clicking an element with `data-carousel-start="N"` stores that index on the target
579
+ * carousel (found via `commandfor` → dialog → `:is(ui-carousel, .ui-carousel)`). The dialog
580
+ * open observer scrolls to it on open.
581
+ */
582
+ function initEmblaStartLinks() {
583
+ document.addEventListener("click", function (e) {
584
+ if (!(e.target instanceof HTMLElement))
585
+ return;
586
+ const trigger = e.target.closest("[data-carousel-start], [data-slot~='carousel-slide'][commandfor]");
587
+ if (!trigger)
588
+ return;
589
+ let index = trigger.getAttribute("data-carousel-start");
590
+ if (index == null && trigger.hasAttribute("commandfor")) {
591
+ const emblaRoot = trigger.closest(":is(ui-carousel, .ui-carousel)");
592
+ if (emblaRoot?._emblaApi) {
593
+ index = String(emblaRoot._emblaApi.selectedScrollSnap());
594
+ }
595
+ }
596
+ const dialogId = trigger.getAttribute("commandfor");
597
+ if (!dialogId)
598
+ return;
599
+ const dialog = document.getElementById(dialogId);
600
+ if (!dialog)
601
+ return;
602
+ const root = dialog.querySelector(":is(ui-carousel, .ui-carousel)");
603
+ if (!root)
604
+ return;
605
+ if (root._emblaApi) {
606
+ root._emblaApi.scrollTo(Number(index), true);
607
+ }
608
+ else if (index != null) {
609
+ root.setAttribute("data-carousel-start-index", index);
610
+ }
611
+ });
612
+ }
613
+ // Auto-initialize when DOM is ready (only in browser environment)
614
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
615
+ // After a SPA <main> swap, initialize class-form carousels in the new content
616
+ // (<ui-carousel> elements ride the swap via their own lifecycle; init() skips
617
+ // already-initialized roots and closed dialogs).
618
+ registerRefresh((scope) => initEmblaCarousels(scope));
619
+ if (document.readyState === "loading") {
620
+ document.addEventListener("DOMContentLoaded", function () {
621
+ initEmblaCarousels();
622
+ initDialogOpenSubscription();
623
+ initEmblaStartLinks();
624
+ initEmblaKeyboardNav();
625
+ initCommandDragGuard();
626
+ });
627
+ }
628
+ else {
629
+ initEmblaCarousels();
630
+ initDialogOpenSubscription();
631
+ initEmblaStartLinks();
632
+ initEmblaKeyboardNav();
633
+ initCommandDragGuard();
634
+ }
635
+ }
636
+ // Attach to window for the documented public API (`window.EmblaInit`), and export
637
+ // for module consumers (carousel.js / navigation.js import it via the main.js bundle).
638
+ if (typeof window !== "undefined") {
639
+ window.EmblaInit = EmblaInit;
640
+ }
641
+ // setActiveIndex and parseCarouselPlugins are exported for unit tests only;
642
+ // not part of the public API.
643
+ export { EmblaInit, setActiveIndex, parseCarouselPlugins };