@zazz-ui/core 0.12.2 → 0.13.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.
- package/AUTHORING.md +6 -6
- package/CHANGELOG.md +51 -0
- package/README.md +8 -6
- package/dist/sri.json +53 -53
- package/dist/zazz.css +1 -1
- package/dist/zazz.js +1 -1
- package/editor/zazz.css-data.json +1254 -3556
- package/editor/zazz.html-data.json +9 -0
- package/editor/zazz.language-data.json +48 -11
- package/editor/zazz.lint-data.json +1141 -1110
- package/package.json +5 -5
- package/src/base/_defaults.css +0 -83
- package/src/base/_properties-2xl.css +0 -8
- package/src/base/_properties-active.css +0 -4
- package/src/base/_properties-checked.css +0 -4
- package/src/base/_properties-current.css +0 -4
- package/src/base/_properties-disabled.css +0 -4
- package/src/base/_properties-focus-visible.css +0 -4
- package/src/base/_properties-focus-within.css +0 -4
- package/src/base/_properties-hover.css +0 -4
- package/src/base/_properties-lg.css +0 -8
- package/src/base/_properties-md.css +0 -8
- package/src/base/_properties-open.css +0 -4
- package/src/base/_properties-sm.css +0 -8
- package/src/base/_properties-starting.css +0 -26
- package/src/base/_properties-stuck.css +0 -2
- package/src/base/_properties-xl.css +0 -8
- package/src/base/_properties.css +23 -0
- package/src/base/_utilities-box.css +1 -6
- package/src/base/_utilities-color.css +1 -1
- package/src/base/_utilities-effects.css +7 -7
- package/src/base/_utilities-flow.css +54 -11
- package/src/base/_utilities-grid.css +5 -85
- package/src/base/_utilities-tier-2xl.css +0 -4
- package/src/base/_utilities-tier-active.css +0 -2
- package/src/base/_utilities-tier-checked.css +0 -2
- package/src/base/_utilities-tier-current.css +0 -2
- package/src/base/_utilities-tier-disabled.css +0 -2
- package/src/base/_utilities-tier-focus-visible.css +0 -2
- package/src/base/_utilities-tier-focus-within.css +0 -2
- package/src/base/_utilities-tier-hover.css +0 -2
- package/src/base/_utilities-tier-lg.css +0 -4
- package/src/base/_utilities-tier-md.css +0 -4
- package/src/base/_utilities-tier-open.css +0 -2
- package/src/base/_utilities-tier-sm.css +0 -4
- package/src/base/_utilities-tier-starting.css +0 -13
- package/src/base/_utilities-tier-stuck.css +0 -1
- package/src/base/_utilities-tier-xl.css +0 -4
- package/src/base/_utilities-typography.css +4 -8
- package/src/base/embla.d.ts.map +1 -1
- package/src/base/embla.js +223 -65
- package/src/base/embla.ts +245 -62
- package/src/base/kit-styling.d.ts.map +1 -1
- package/src/base/kit-styling.js +154 -150
- package/src/base/kit-styling.ts +154 -150
- package/src/base/utilities.d.ts +23 -7
- package/src/base/utilities.d.ts.map +1 -1
- package/src/base/utilities.js +91 -22
- package/src/base/utilities.ts +101 -23
- package/src/head.js +8 -8
- package/src/head.ts +8 -8
- package/src/manifest.d.ts.map +1 -1
- package/src/manifest.js +7 -1
- package/src/manifest.ts +7 -1
- package/src/primitives/carousel/carousel.css +4 -3
- package/src/primitives/carousel/carousel.d.ts +2 -1
- package/src/primitives/carousel/carousel.d.ts.map +1 -1
- package/src/primitives/carousel/carousel.js +2 -1
- package/src/primitives/carousel/carousel.ts +2 -1
- package/src/primitives/debug/audit-core.d.ts.map +1 -1
- package/src/primitives/debug/audit-core.js +46 -4
- package/src/primitives/debug/audit-core.ts +53 -4
- package/src/primitives/lightbox/lightbox.js +2 -2
- package/src/primitives/lightbox/lightbox.ts +2 -2
- package/src/primitives/slider/slider.css +7 -2
- package/src/primitives/switch/switch.css +26 -3
- package/src/primitives/tabs/tabs-underline.html +117 -0
- package/src/primitives/tabs/tabs.css +119 -27
- package/src/primitives/toggle/toggle.css +153 -40
- package/src/primitives/utilities/flex-direction.html +1 -1
- package/src/primitives/utilities/flex-reverse.html +136 -0
- package/src/primitives/utilities/gallery.html +289 -0
- package/src/primitives/utilities/inline-flex.html +45 -0
- package/src/primitives/utilities/subgrid-col.html +109 -0
- package/src/primitives/utilities/subgrid-row.html +98 -0
- package/src/primitives/utilities/subgrid.html +135 -0
package/src/base/embla.js
CHANGED
|
@@ -32,15 +32,24 @@
|
|
|
32
32
|
* - `data-carousel-auto-scroll-*`: Auto scroll plugin options (requires `auto-scroll` in plugins)
|
|
33
33
|
* - `data-carousel-class-names-*`: Class names plugin options (requires `class-names` in plugins)
|
|
34
34
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* `data-carousel-
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
35
|
+
* Built on Embla v9 (`9.0.0-rc04`). Core options pass straight through, so they
|
|
36
|
+
* use Embla's v9 names (`data-carousel-start-snap`, `data-carousel-draggable`,
|
|
37
|
+
* `data-carousel-drag-free="snap"`, …).
|
|
38
|
+
*
|
|
39
|
+
* Autoplay and Auto Scroll: the kit owns their interaction handling (it sets
|
|
40
|
+
* Embla's `defaultInteraction: false`) and adds two kit-level options, read
|
|
41
|
+
* from the plugin's own prefix (`data-carousel-autoplay-*`, `data-carousel-auto-scroll-*`):
|
|
42
|
+
* - `…-play-on-init`: `"false"` leaves the plugin stopped until `play()` (default plays)
|
|
43
|
+
* - `…-stop-on-interaction`: `"false"` holds the plugin during a drag or slide focus and
|
|
44
|
+
* resumes it after; Prev/Next, the dots, the thumbs, and the arrow keys restart its
|
|
45
|
+
* delay. By default (`true`) any of those stops it for good.
|
|
46
|
+
* The kit also restarts a playing plugin after Embla's `reinit` (a resize or a
|
|
47
|
+
* breakpoint change re-creates plugins, which Embla v9 leaves stopped).
|
|
48
|
+
*
|
|
49
|
+
* @see https://www.embla-carousel.com/api/options/
|
|
50
|
+
* @see https://www.embla-carousel.com/plugins/autoplay/
|
|
51
|
+
* @see https://www.embla-carousel.com/plugins/auto-scroll/
|
|
52
|
+
* @see https://www.embla-carousel.com/plugins/class-names/
|
|
44
53
|
*
|
|
45
54
|
* @example
|
|
46
55
|
* data-carousel-loop="true"
|
|
@@ -96,8 +105,8 @@ function parseCarouselPlugins(value) {
|
|
|
96
105
|
* (`embla-carousel-auto-scroll`, etc.).
|
|
97
106
|
*/
|
|
98
107
|
const PLUGIN_BY_SLUG = {
|
|
99
|
-
autoplay: (node) => EmblaCarouselAutoplay(
|
|
100
|
-
"auto-scroll": (node) => EmblaCarouselAutoScroll(
|
|
108
|
+
autoplay: (node) => EmblaCarouselAutoplay(readAutoPluginOptions(node, "data-carousel-autoplay-")),
|
|
109
|
+
"auto-scroll": (node) => EmblaCarouselAutoScroll(readAutoPluginOptions(node, "data-carousel-auto-scroll-")),
|
|
101
110
|
"class-names": (node) => EmblaCarouselClassNames(readCarouselOptions(node, "data-carousel-class-names-")),
|
|
102
111
|
};
|
|
103
112
|
/**
|
|
@@ -115,26 +124,191 @@ const PLUGIN_BY_SLUG = {
|
|
|
115
124
|
function readCarouselOptions(node, prefix) {
|
|
116
125
|
return Utils.parseDataAttributes(node, prefix);
|
|
117
126
|
}
|
|
127
|
+
/** The two plugins the kit drives: their `plugins()` key, attribute prefix, and interaction event. */
|
|
128
|
+
const AUTO_PLUGINS = [
|
|
129
|
+
{
|
|
130
|
+
key: "autoplay",
|
|
131
|
+
prefix: "data-carousel-autoplay-",
|
|
132
|
+
interaction: "autoplay:interaction",
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
key: "autoScroll",
|
|
136
|
+
prefix: "data-carousel-auto-scroll-",
|
|
137
|
+
interaction: "autoscroll:interaction",
|
|
138
|
+
},
|
|
139
|
+
];
|
|
140
|
+
/**
|
|
141
|
+
* @description Reads an Autoplay / Auto Scroll plugin's attributes as Embla
|
|
142
|
+
* options: drops the kit-level `playOnInit` / `stopOnInteraction` and sets
|
|
143
|
+
* `defaultInteraction: false`, so the plugin reports interactions
|
|
144
|
+
* (`autoplay:interaction`) and `bindAutoPlugins` decides what they do.
|
|
145
|
+
* @private
|
|
146
|
+
*/
|
|
147
|
+
function readAutoPluginOptions(node, prefix) {
|
|
148
|
+
const options = Utils.parseDataAttributes(node, prefix);
|
|
149
|
+
delete options.playOnInit;
|
|
150
|
+
delete options.stopOnInteraction;
|
|
151
|
+
return { ...options, defaultInteraction: false };
|
|
152
|
+
}
|
|
153
|
+
/** Per-carousel manual-step handlers, one per driven plugin (see onManualNavigation). */
|
|
154
|
+
const manualStepHandlers = new WeakMap();
|
|
155
|
+
/** Form fields Embla never starts a drag on (its DragHandler `focusNodes`). */
|
|
156
|
+
const NON_DRAG_TARGETS = ["INPUT", "SELECT", "TEXTAREA"];
|
|
157
|
+
/**
|
|
158
|
+
* @description Whether a pointer down starts an Embla drag. Embla v9 emits
|
|
159
|
+
* `pointerdown` before its own checks, then ignores a non-primary mouse button
|
|
160
|
+
* or a press in a form field, and no `pointerup` follows; state set on such a
|
|
161
|
+
* pointer down would never clear.
|
|
162
|
+
* @private
|
|
163
|
+
*/
|
|
164
|
+
function startsDrag(evt) {
|
|
165
|
+
if (evt instanceof MouseEvent && evt.button !== 0)
|
|
166
|
+
return false;
|
|
167
|
+
return !(evt.target instanceof Element && NON_DRAG_TARGETS.includes(evt.target.nodeName));
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* @description Drives the Autoplay and Auto Scroll plugins the way the kit
|
|
171
|
+
* documents them, on top of Embla v9's bare plugins (which neither start on
|
|
172
|
+
* their own nor survive a `reinit`):
|
|
173
|
+
* - plays on init unless `…-play-on-init="false"`;
|
|
174
|
+
* - a pointer down or slide focus stops the plugin; with
|
|
175
|
+
* `…-stop-on-interaction="false"` it only holds it, and the pointer up or
|
|
176
|
+
* focus leaving the slides resumes it;
|
|
177
|
+
* - after a `reinit` (resize, breakpoint change, `reInit()`), which re-creates
|
|
178
|
+
* the plugin stopped, resumes it if it was playing, or is still waiting to
|
|
179
|
+
* play (no second snap yet, or the carousel was inactive at a breakpoint);
|
|
180
|
+
* - registers the manual-step handler `onManualNavigation` runs.
|
|
181
|
+
*
|
|
182
|
+
* Takes the plugin instances themselves: `plugins()` is empty while the
|
|
183
|
+
* carousel is inactive (`active: false` at the current breakpoint).
|
|
184
|
+
* @private
|
|
185
|
+
*/
|
|
186
|
+
function bindAutoPlugins(emblaApi, node, plugins) {
|
|
187
|
+
const handlers = [];
|
|
188
|
+
for (const { key, prefix, interaction } of AUTO_PLUGINS) {
|
|
189
|
+
const plugin = plugins.find((p) => p.name === key);
|
|
190
|
+
if (!plugin)
|
|
191
|
+
continue;
|
|
192
|
+
const { playOnInit, stopOnInteraction } = readCarouselOptions(node, prefix);
|
|
193
|
+
const holds = stopOnInteraction === false;
|
|
194
|
+
// `pending`: should play as soon as it can. `held`: what paused it with
|
|
195
|
+
// stop-on-interaction false (its end resumes it), or "" when nothing does.
|
|
196
|
+
let pending = playOnInit !== false;
|
|
197
|
+
let held = "";
|
|
198
|
+
let wasPlaying = false;
|
|
199
|
+
const playIfPending = () => {
|
|
200
|
+
if (!pending || emblaApi.snapList().length <= 1)
|
|
201
|
+
return;
|
|
202
|
+
// An inactive carousel never inits its plugins, and play() before init throws.
|
|
203
|
+
if (!emblaApi.internalEngine().options.active)
|
|
204
|
+
return;
|
|
205
|
+
plugin.play();
|
|
206
|
+
// play() does nothing while the plugin itself is inactive; keep waiting then.
|
|
207
|
+
pending = !plugin.isPlaying();
|
|
208
|
+
};
|
|
209
|
+
// Embla re-creates plugins on reinit by calling destroy() then init() on the
|
|
210
|
+
// same object, and destroy() stops it; note whether it was playing first.
|
|
211
|
+
const destroy = plugin.destroy;
|
|
212
|
+
plugin.destroy = () => {
|
|
213
|
+
wasPlaying = plugin.isPlaying();
|
|
214
|
+
destroy();
|
|
215
|
+
};
|
|
216
|
+
emblaApi.on("reinit", () => {
|
|
217
|
+
pending ||= wasPlaying;
|
|
218
|
+
wasPlaying = false;
|
|
219
|
+
// A reinit mid-drag drops the drag, so its pointer up never comes.
|
|
220
|
+
if (held === "pointer") {
|
|
221
|
+
held = "";
|
|
222
|
+
pending = true;
|
|
223
|
+
}
|
|
224
|
+
if (!held)
|
|
225
|
+
playIfPending();
|
|
226
|
+
});
|
|
227
|
+
emblaApi.on(interaction, (_api, { detail }) => {
|
|
228
|
+
const { interaction: type, originalEvent } = detail;
|
|
229
|
+
if (type === "pointerdown" || type === "slidefocus") {
|
|
230
|
+
// A pointerdown's originalEvent is Embla's event model; its detail is the DOM event.
|
|
231
|
+
const pointer = originalEvent instanceof Event ? null : originalEvent.detail;
|
|
232
|
+
if (type === "pointerdown" && pointer && !startsDrag(pointer))
|
|
233
|
+
return;
|
|
234
|
+
if (!plugin.isPlaying() && !held)
|
|
235
|
+
return;
|
|
236
|
+
held = holds ? (type === "pointerdown" ? "pointer" : "focus") : "";
|
|
237
|
+
pending = false;
|
|
238
|
+
plugin.stop();
|
|
239
|
+
}
|
|
240
|
+
else if ((type === "pointerup" && held === "pointer") ||
|
|
241
|
+
(type === "slidefocusout" && held === "focus")) {
|
|
242
|
+
held = "";
|
|
243
|
+
plugin.play();
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
handlers.push(() => {
|
|
247
|
+
pending = false;
|
|
248
|
+
if (holds)
|
|
249
|
+
plugin.reset();
|
|
250
|
+
else
|
|
251
|
+
plugin.stop();
|
|
252
|
+
});
|
|
253
|
+
playIfPending();
|
|
254
|
+
}
|
|
255
|
+
if (handlers.length)
|
|
256
|
+
manualStepHandlers.set(emblaApi, handlers);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* @description The kit's own Embla plugin, placed first in the plugin list so
|
|
260
|
+
* its `pointerdown` listener runs before any other plugin's, on init and
|
|
261
|
+
* after every reinit (Embla re-registers plugins in list order):
|
|
262
|
+
* - vetoes a drag when every slide already fits (one snap): Embla would still
|
|
263
|
+
* rubber-band. Returning false cancels Embla's drag and the later listeners
|
|
264
|
+
* (Class Names' pointer-down class, the plugins' interactions). Skipped when
|
|
265
|
+
* the author set `data-carousel-draggable`.
|
|
266
|
+
* - marks a drag as a `dragging` token on the viewport, and `data-ui-dragging`
|
|
267
|
+
* on the document root for the page-wide grabbing cursor (a `body:has(…) *`
|
|
268
|
+
* rule would restyle the whole page on every DOM insertion). Cleared on
|
|
269
|
+
* pointer up and on destroy (a reinit mid-drag drops the pointer up).
|
|
270
|
+
* @private
|
|
271
|
+
*/
|
|
272
|
+
function KitDragPlugin(viewport, vetoesDrag) {
|
|
273
|
+
const root = viewport.ownerDocument.documentElement;
|
|
274
|
+
let api;
|
|
275
|
+
const setDragging = (on) => {
|
|
276
|
+
setCarouselState(viewport, "dragging", on);
|
|
277
|
+
root.toggleAttribute("data-ui-dragging", on);
|
|
278
|
+
};
|
|
279
|
+
const onPointerDown = (emblaApi, { detail }) => {
|
|
280
|
+
if (vetoesDrag && !emblaApi.canGoToPrev() && !emblaApi.canGoToNext())
|
|
281
|
+
return false;
|
|
282
|
+
if (startsDrag(detail))
|
|
283
|
+
setDragging(true);
|
|
284
|
+
};
|
|
285
|
+
const onPointerUp = () => setDragging(false);
|
|
286
|
+
return {
|
|
287
|
+
name: "zazzDrag",
|
|
288
|
+
options: {},
|
|
289
|
+
init(emblaApi) {
|
|
290
|
+
api = emblaApi;
|
|
291
|
+
emblaApi.on("pointerdown", onPointerDown).on("pointerup", onPointerUp);
|
|
292
|
+
},
|
|
293
|
+
destroy() {
|
|
294
|
+
api?.off("pointerdown", onPointerDown).off("pointerup", onPointerUp);
|
|
295
|
+
setDragging(false);
|
|
296
|
+
},
|
|
297
|
+
};
|
|
298
|
+
}
|
|
118
299
|
// --- Manual navigation ---
|
|
119
300
|
/**
|
|
120
301
|
* @description Treats a manual step (Prev/Next, a dot, a thumb, an arrow key) as
|
|
121
302
|
* user interaction for the Autoplay and Auto Scroll plugins, which on their own
|
|
122
303
|
* only count a pointer-down on the viewport. Without it the plugin's timer keeps
|
|
123
304
|
* running, and a tick that lands just after a click moves a second slide.
|
|
124
|
-
* `
|
|
305
|
+
* `stop-on-interaction` (default true) stops the plugin; `false` restarts its delay.
|
|
125
306
|
* This is the pattern Embla's own examples use for navigation buttons.
|
|
126
307
|
* @private
|
|
127
308
|
*/
|
|
128
309
|
function onManualNavigation(emblaApi) {
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
if (!plugin)
|
|
132
|
-
continue;
|
|
133
|
-
if (plugin.options.stopOnInteraction === false)
|
|
134
|
-
plugin.reset();
|
|
135
|
-
else
|
|
136
|
-
plugin.stop();
|
|
137
|
-
}
|
|
310
|
+
for (const handler of manualStepHandlers.get(emblaApi) ?? [])
|
|
311
|
+
handler();
|
|
138
312
|
}
|
|
139
313
|
// --- Active-index sync ---
|
|
140
314
|
/**
|
|
@@ -160,13 +334,14 @@ function bindSlideStates(emblaApi) {
|
|
|
160
334
|
const update = () => {
|
|
161
335
|
const slides = emblaApi.slideNodes();
|
|
162
336
|
const inView = new Set(emblaApi.slidesInView());
|
|
163
|
-
const snapped = new Set(emblaApi.internalEngine().
|
|
337
|
+
const snapped = new Set(emblaApi.internalEngine().scrollSnapList.slidesBySnap[emblaApi.selectedSnap()] ?? []);
|
|
164
338
|
slides.forEach((slide, index) => {
|
|
165
339
|
setCarouselState(slide, "in-view", inView.has(index));
|
|
166
340
|
setCarouselState(slide, "snapped", snapped.has(index));
|
|
167
341
|
});
|
|
168
342
|
};
|
|
169
|
-
emblaApi.on("
|
|
343
|
+
emblaApi.on("reinit", update).on("select", update).on("slidesinview", update);
|
|
344
|
+
update();
|
|
170
345
|
}
|
|
171
346
|
/**
|
|
172
347
|
* @description Sets `data-carousel-state="active"` on the node at `selected` and clears it
|
|
@@ -215,7 +390,7 @@ const addDotBtnsAndClickHandlers = (emblaApi, dotsNode, signal) => {
|
|
|
215
390
|
* @private
|
|
216
391
|
*/
|
|
217
392
|
const addDotBtnsWithClickHandlers = () => {
|
|
218
|
-
const snapCount = emblaApi.
|
|
393
|
+
const snapCount = emblaApi.snapList().length;
|
|
219
394
|
dotsNode.innerHTML = "";
|
|
220
395
|
if (snapCount <= 1) {
|
|
221
396
|
dotNodes = [];
|
|
@@ -228,7 +403,7 @@ const addDotBtnsAndClickHandlers = (emblaApi, dotsNode, signal) => {
|
|
|
228
403
|
dotsNode.appendChild(dot);
|
|
229
404
|
dot.addEventListener("click", () => {
|
|
230
405
|
onManualNavigation(emblaApi);
|
|
231
|
-
emblaApi.
|
|
406
|
+
emblaApi.goTo(i);
|
|
232
407
|
}, { signal });
|
|
233
408
|
}
|
|
234
409
|
};
|
|
@@ -240,14 +415,14 @@ const addDotBtnsAndClickHandlers = (emblaApi, dotsNode, signal) => {
|
|
|
240
415
|
const toggleDotBtnsActive = () => {
|
|
241
416
|
if (!dotNodes.length)
|
|
242
417
|
return;
|
|
243
|
-
setActiveIndex(dotNodes, emblaApi.
|
|
418
|
+
setActiveIndex(dotNodes, emblaApi.selectedSnap());
|
|
244
419
|
};
|
|
245
420
|
emblaApi
|
|
246
|
-
.on("
|
|
247
|
-
.on("
|
|
248
|
-
.on("init", toggleDotBtnsActive)
|
|
249
|
-
.on("reInit", toggleDotBtnsActive)
|
|
421
|
+
.on("reinit", addDotBtnsWithClickHandlers)
|
|
422
|
+
.on("reinit", toggleDotBtnsActive)
|
|
250
423
|
.on("select", toggleDotBtnsActive);
|
|
424
|
+
addDotBtnsWithClickHandlers();
|
|
425
|
+
toggleDotBtnsActive();
|
|
251
426
|
return () => {
|
|
252
427
|
dotsNode.innerHTML = "";
|
|
253
428
|
};
|
|
@@ -265,7 +440,7 @@ const addThumbClickHandlers = (emblaApiMain, emblaApiThumb, signal) => {
|
|
|
265
440
|
slidesthumbs.forEach((slideNode, index) => {
|
|
266
441
|
slideNode.addEventListener("click", () => {
|
|
267
442
|
onManualNavigation(emblaApiMain);
|
|
268
|
-
emblaApiMain.
|
|
443
|
+
emblaApiMain.goTo(index);
|
|
269
444
|
}, { signal });
|
|
270
445
|
});
|
|
271
446
|
};
|
|
@@ -283,8 +458,8 @@ const addTogglethumbsActive = (emblaApiMain, emblaApiThumb) => {
|
|
|
283
458
|
* @private
|
|
284
459
|
*/
|
|
285
460
|
const toggleThumbBtnsActive = () => {
|
|
286
|
-
const selected = emblaApiMain.
|
|
287
|
-
emblaApiThumb.
|
|
461
|
+
const selected = emblaApiMain.selectedSnap();
|
|
462
|
+
emblaApiThumb.goTo(selected);
|
|
288
463
|
setActiveIndex(slidesthumbs, selected, { ariaCurrent: true });
|
|
289
464
|
};
|
|
290
465
|
emblaApiMain.on("select", toggleThumbBtnsActive);
|
|
@@ -336,7 +511,7 @@ function bindDragClickSuppression(root, emblaApi, clickSelector, options = {}, s
|
|
|
336
511
|
startY = e.clientY;
|
|
337
512
|
lastX = e.clientX;
|
|
338
513
|
lastY = e.clientY;
|
|
339
|
-
snapAtDown = emblaApi.
|
|
514
|
+
snapAtDown = emblaApi.selectedSnap();
|
|
340
515
|
}, { passive: true, signal });
|
|
341
516
|
root.addEventListener("pointermove", (e) => {
|
|
342
517
|
if (!pointerDown || !(e instanceof PointerEvent))
|
|
@@ -359,14 +534,14 @@ function bindDragClickSuppression(root, emblaApi, clickSelector, options = {}, s
|
|
|
359
534
|
};
|
|
360
535
|
root.addEventListener("pointerup", finalizePointer, { passive: true, signal });
|
|
361
536
|
root.addEventListener("pointercancel", finalizePointer, { passive: true, signal });
|
|
362
|
-
emblaApi.on("
|
|
537
|
+
emblaApi.on("pointerup", finalizePointer);
|
|
363
538
|
// Touch/trackpad drags can move with tiny deltas. Treat Embla scroll as drag intent,
|
|
364
539
|
// but lightbox openers need extra tolerance so minor carousel settle does not block clicks.
|
|
365
540
|
emblaApi.on("scroll", () => {
|
|
366
541
|
if (!pointerDown)
|
|
367
542
|
return;
|
|
368
543
|
if (guardsCommands) {
|
|
369
|
-
if (pointerDistance() >= DRAG_THRESHOLD_PX || emblaApi.
|
|
544
|
+
if (pointerDistance() >= DRAG_THRESHOLD_PX || emblaApi.selectedSnap() !== snapAtDown) {
|
|
370
545
|
moved = true;
|
|
371
546
|
}
|
|
372
547
|
return;
|
|
@@ -447,16 +622,12 @@ function initEmblaRoot(emblaNode) {
|
|
|
447
622
|
delete apiOptions[key];
|
|
448
623
|
}
|
|
449
624
|
});
|
|
450
|
-
// Veto drag gestures when every slide already fits in the viewport: with a
|
|
451
|
-
// single snap Embla still rubber-bands on drag, which feels broken. The
|
|
452
|
-
// callback re-evaluates on every pointer down, so it stays correct across
|
|
453
|
-
// resizes/reInit. Respect an explicit data-carousel-watch-drag override.
|
|
454
|
-
if (!("watchDrag" in apiOptions)) {
|
|
455
|
-
apiOptions.watchDrag = (api) => api.canScrollPrev() || api.canScrollNext();
|
|
456
|
-
}
|
|
457
625
|
// Plugins load only when listed in data-carousel-plugins; option attrs alone
|
|
458
626
|
// do not enable them. Unknown slugs are ignored.
|
|
459
|
-
|
|
627
|
+
// The kit's drag plugin goes first (see KitDragPlugin).
|
|
628
|
+
const plugins = [
|
|
629
|
+
KitDragPlugin(emblaViewportNode, !("draggable" in apiOptions)),
|
|
630
|
+
];
|
|
460
631
|
for (const slug of parseCarouselPlugins(emblaNode.getAttribute("data-carousel-plugins"))) {
|
|
461
632
|
const create = PLUGIN_BY_SLUG[slug];
|
|
462
633
|
if (!create)
|
|
@@ -465,21 +636,8 @@ function initEmblaRoot(emblaNode) {
|
|
|
465
636
|
}
|
|
466
637
|
// The options come from untyped data attributes; Embla validates at runtime.
|
|
467
638
|
const emblaApi = EmblaCarousel(emblaViewportNode, apiOptions, plugins);
|
|
468
|
-
// Drag state is a data-carousel-state token on the viewport, and
|
|
469
|
-
// data-ui-dragging on the root for the page-wide grabbing cursor (a
|
|
470
|
-
// `body:has(…) *` rule would restyle the whole page on every DOM insertion).
|
|
471
|
-
const root = emblaNode.ownerDocument.documentElement;
|
|
472
|
-
emblaApi.on("pointerDown", () => {
|
|
473
|
-
if (emblaViewportNode)
|
|
474
|
-
setCarouselState(emblaViewportNode, "dragging", true);
|
|
475
|
-
root.setAttribute("data-ui-dragging", "");
|
|
476
|
-
});
|
|
477
|
-
emblaApi.on("pointerUp", () => {
|
|
478
|
-
if (emblaViewportNode)
|
|
479
|
-
setCarouselState(emblaViewportNode, "dragging", false);
|
|
480
|
-
root.removeAttribute("data-ui-dragging");
|
|
481
|
-
});
|
|
482
639
|
bindSlideStates(emblaApi);
|
|
640
|
+
bindAutoPlugins(emblaApi, emblaNode, plugins);
|
|
483
641
|
emblaNode._emblaApi = emblaApi;
|
|
484
642
|
// One controller per root scopes every carousel listener below; the owner
|
|
485
643
|
// (`<ui-carousel>` disconnectedCallback) aborts it on teardown so the DOM
|
|
@@ -490,13 +648,13 @@ function initEmblaRoot(emblaNode) {
|
|
|
490
648
|
if (emblaPrevButtonNode) {
|
|
491
649
|
emblaPrevButtonNode.addEventListener("click", () => {
|
|
492
650
|
onManualNavigation(emblaApi);
|
|
493
|
-
emblaApi.
|
|
651
|
+
emblaApi.goToPrev();
|
|
494
652
|
}, { signal });
|
|
495
653
|
}
|
|
496
654
|
if (emblaNextButtonNode) {
|
|
497
655
|
emblaNextButtonNode.addEventListener("click", () => {
|
|
498
656
|
onManualNavigation(emblaApi);
|
|
499
|
-
emblaApi.
|
|
657
|
+
emblaApi.goToNext();
|
|
500
658
|
}, { signal });
|
|
501
659
|
}
|
|
502
660
|
if (emblaDotsNode) {
|
|
@@ -564,7 +722,7 @@ function initDialogOpenSubscription() {
|
|
|
564
722
|
roots.forEach(function (root) {
|
|
565
723
|
const startIndex = root.getAttribute("data-carousel-start-index");
|
|
566
724
|
if (startIndex != null && root._emblaApi) {
|
|
567
|
-
root._emblaApi.
|
|
725
|
+
root._emblaApi.goTo(Number(startIndex), true);
|
|
568
726
|
root.removeAttribute("data-carousel-start-index");
|
|
569
727
|
}
|
|
570
728
|
const viewport = root.querySelector('[data-carousel-slot~="viewport"]');
|
|
@@ -628,9 +786,9 @@ const initEmblaKeyboardNav = function () {
|
|
|
628
786
|
e.preventDefault();
|
|
629
787
|
onManualNavigation(root._emblaApi);
|
|
630
788
|
if (e.key === "ArrowLeft")
|
|
631
|
-
root._emblaApi.
|
|
789
|
+
root._emblaApi.goToPrev();
|
|
632
790
|
else
|
|
633
|
-
root._emblaApi.
|
|
791
|
+
root._emblaApi.goToNext();
|
|
634
792
|
});
|
|
635
793
|
};
|
|
636
794
|
/**
|
|
@@ -669,7 +827,7 @@ function initEmblaStartLinks() {
|
|
|
669
827
|
if (index == null && trigger.hasAttribute("commandfor")) {
|
|
670
828
|
const emblaRoot = trigger.closest(':is(ui-carousel, [data-ui~="carousel"])');
|
|
671
829
|
if (emblaRoot?._emblaApi) {
|
|
672
|
-
index = String(emblaRoot._emblaApi.
|
|
830
|
+
index = String(emblaRoot._emblaApi.selectedSnap());
|
|
673
831
|
}
|
|
674
832
|
}
|
|
675
833
|
const dialogId = trigger.getAttribute("commandfor");
|
|
@@ -682,7 +840,7 @@ function initEmblaStartLinks() {
|
|
|
682
840
|
if (!root)
|
|
683
841
|
return;
|
|
684
842
|
if (root._emblaApi) {
|
|
685
|
-
root._emblaApi.
|
|
843
|
+
root._emblaApi.goTo(Number(index), true);
|
|
686
844
|
}
|
|
687
845
|
else if (index != null) {
|
|
688
846
|
root.setAttribute("data-carousel-start-index", index);
|