@zazz-ui/core 0.12.3 → 0.13.1
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 +46 -0
- package/README.md +8 -6
- package/dist/sri.json +52 -52
- package/dist/zazz.css +1 -1
- package/dist/zazz.js +1 -1
- package/editor/zazz.css-data.json +1238 -3564
- package/editor/zazz.html-data.json +9 -0
- package/editor/zazz.language-data.json +21 -8
- package/editor/zazz.lint-data.json +1139 -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/input/input.css +3 -2
- package/src/primitives/lightbox/lightbox.js +2 -2
- package/src/primitives/lightbox/lightbox.ts +2 -2
- 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.ts
CHANGED
|
@@ -33,15 +33,24 @@
|
|
|
33
33
|
* - `data-carousel-auto-scroll-*`: Auto scroll plugin options (requires `auto-scroll` in plugins)
|
|
34
34
|
* - `data-carousel-class-names-*`: Class names plugin options (requires `class-names` in plugins)
|
|
35
35
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* `data-carousel-
|
|
36
|
+
* Built on Embla v9 (`9.0.0-rc04`). Core options pass straight through, so they
|
|
37
|
+
* use Embla's v9 names (`data-carousel-start-snap`, `data-carousel-draggable`,
|
|
38
|
+
* `data-carousel-drag-free="snap"`, …).
|
|
39
39
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
40
|
+
* Autoplay and Auto Scroll: the kit owns their interaction handling (it sets
|
|
41
|
+
* Embla's `defaultInteraction: false`) and adds two kit-level options, read
|
|
42
|
+
* from the plugin's own prefix (`data-carousel-autoplay-*`, `data-carousel-auto-scroll-*`):
|
|
43
|
+
* - `…-play-on-init`: `"false"` leaves the plugin stopped until `play()` (default plays)
|
|
44
|
+
* - `…-stop-on-interaction`: `"false"` holds the plugin during a drag or slide focus and
|
|
45
|
+
* resumes it after; Prev/Next, the dots, the thumbs, and the arrow keys restart its
|
|
46
|
+
* delay. By default (`true`) any of those stops it for good.
|
|
47
|
+
* The kit also restarts a playing plugin after Embla's `reinit` (a resize or a
|
|
48
|
+
* breakpoint change re-creates plugins, which Embla v9 leaves stopped).
|
|
49
|
+
*
|
|
50
|
+
* @see https://www.embla-carousel.com/api/options/
|
|
51
|
+
* @see https://www.embla-carousel.com/plugins/autoplay/
|
|
52
|
+
* @see https://www.embla-carousel.com/plugins/auto-scroll/
|
|
53
|
+
* @see https://www.embla-carousel.com/plugins/class-names/
|
|
45
54
|
*
|
|
46
55
|
* @example
|
|
47
56
|
* data-carousel-loop="true"
|
|
@@ -81,9 +90,9 @@ import { registerRefresh } from "./zazz-element.ts";
|
|
|
81
90
|
import EmblaCarousel from "embla-carousel";
|
|
82
91
|
import type { EmblaCarouselType, EmblaOptionsType, EmblaPluginType } from "embla-carousel";
|
|
83
92
|
import EmblaCarouselAutoplay from "embla-carousel-autoplay";
|
|
84
|
-
import type { AutoplayOptionsType } from "embla-carousel-autoplay";
|
|
93
|
+
import type { AutoplayOptionsType, AutoplayType } from "embla-carousel-autoplay";
|
|
85
94
|
import EmblaCarouselAutoScroll from "embla-carousel-auto-scroll";
|
|
86
|
-
import type { AutoScrollOptionsType } from "embla-carousel-auto-scroll";
|
|
95
|
+
import type { AutoScrollOptionsType, AutoScrollType } from "embla-carousel-auto-scroll";
|
|
87
96
|
import EmblaCarouselClassNames from "embla-carousel-class-names";
|
|
88
97
|
import type { ClassNamesOptionsType } from "embla-carousel-class-names";
|
|
89
98
|
|
|
@@ -111,11 +120,11 @@ function parseCarouselPlugins(value: string | null): string[] {
|
|
|
111
120
|
const PLUGIN_BY_SLUG: Record<CarouselPluginSlug, (node: Element) => EmblaPluginType> = {
|
|
112
121
|
autoplay: (node) =>
|
|
113
122
|
EmblaCarouselAutoplay(
|
|
114
|
-
|
|
123
|
+
readAutoPluginOptions<AutoplayOptionsType>(node, "data-carousel-autoplay-"),
|
|
115
124
|
),
|
|
116
125
|
"auto-scroll": (node) =>
|
|
117
126
|
EmblaCarouselAutoScroll(
|
|
118
|
-
|
|
127
|
+
readAutoPluginOptions<AutoScrollOptionsType>(node, "data-carousel-auto-scroll-"),
|
|
119
128
|
),
|
|
120
129
|
"class-names": (node) =>
|
|
121
130
|
EmblaCarouselClassNames(
|
|
@@ -139,6 +148,200 @@ function readCarouselOptions<T>(node: Element, prefix: string): T {
|
|
|
139
148
|
return Utils.parseDataAttributes(node, prefix) as T;
|
|
140
149
|
}
|
|
141
150
|
|
|
151
|
+
// --- Autoplay and Auto Scroll ---
|
|
152
|
+
|
|
153
|
+
/** Kit-level options of the Autoplay and Auto Scroll plugins (not Embla's). */
|
|
154
|
+
type AutoPluginKitOptions = { playOnInit?: boolean; stopOnInteraction?: boolean };
|
|
155
|
+
|
|
156
|
+
/** The two plugins the kit drives: their `plugins()` key, attribute prefix, and interaction event. */
|
|
157
|
+
const AUTO_PLUGINS = [
|
|
158
|
+
{
|
|
159
|
+
key: "autoplay",
|
|
160
|
+
prefix: "data-carousel-autoplay-",
|
|
161
|
+
interaction: "autoplay:interaction",
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
key: "autoScroll",
|
|
165
|
+
prefix: "data-carousel-auto-scroll-",
|
|
166
|
+
interaction: "autoscroll:interaction",
|
|
167
|
+
},
|
|
168
|
+
] as const;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @description Reads an Autoplay / Auto Scroll plugin's attributes as Embla
|
|
172
|
+
* options: drops the kit-level `playOnInit` / `stopOnInteraction` and sets
|
|
173
|
+
* `defaultInteraction: false`, so the plugin reports interactions
|
|
174
|
+
* (`autoplay:interaction`) and `bindAutoPlugins` decides what they do.
|
|
175
|
+
* @private
|
|
176
|
+
*/
|
|
177
|
+
function readAutoPluginOptions<T>(node: Element, prefix: string): T {
|
|
178
|
+
const options = Utils.parseDataAttributes(node, prefix);
|
|
179
|
+
delete options.playOnInit;
|
|
180
|
+
delete options.stopOnInteraction;
|
|
181
|
+
return { ...options, defaultInteraction: false } as T;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Per-carousel manual-step handlers, one per driven plugin (see onManualNavigation). */
|
|
185
|
+
const manualStepHandlers = new WeakMap<EmblaCarouselType, Array<() => void>>();
|
|
186
|
+
|
|
187
|
+
/** Form fields Embla never starts a drag on (its DragHandler `focusNodes`). */
|
|
188
|
+
const NON_DRAG_TARGETS = ["INPUT", "SELECT", "TEXTAREA"];
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @description Whether a pointer down starts an Embla drag. Embla v9 emits
|
|
192
|
+
* `pointerdown` before its own checks, then ignores a non-primary mouse button
|
|
193
|
+
* or a press in a form field, and no `pointerup` follows; state set on such a
|
|
194
|
+
* pointer down would never clear.
|
|
195
|
+
* @private
|
|
196
|
+
*/
|
|
197
|
+
function startsDrag(evt: Event): boolean {
|
|
198
|
+
if (evt instanceof MouseEvent && evt.button !== 0) return false;
|
|
199
|
+
return !(evt.target instanceof Element && NON_DRAG_TARGETS.includes(evt.target.nodeName));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @description Drives the Autoplay and Auto Scroll plugins the way the kit
|
|
204
|
+
* documents them, on top of Embla v9's bare plugins (which neither start on
|
|
205
|
+
* their own nor survive a `reinit`):
|
|
206
|
+
* - plays on init unless `…-play-on-init="false"`;
|
|
207
|
+
* - a pointer down or slide focus stops the plugin; with
|
|
208
|
+
* `…-stop-on-interaction="false"` it only holds it, and the pointer up or
|
|
209
|
+
* focus leaving the slides resumes it;
|
|
210
|
+
* - after a `reinit` (resize, breakpoint change, `reInit()`), which re-creates
|
|
211
|
+
* the plugin stopped, resumes it if it was playing, or is still waiting to
|
|
212
|
+
* play (no second snap yet, or the carousel was inactive at a breakpoint);
|
|
213
|
+
* - registers the manual-step handler `onManualNavigation` runs.
|
|
214
|
+
*
|
|
215
|
+
* Takes the plugin instances themselves: `plugins()` is empty while the
|
|
216
|
+
* carousel is inactive (`active: false` at the current breakpoint).
|
|
217
|
+
* @private
|
|
218
|
+
*/
|
|
219
|
+
function bindAutoPlugins(
|
|
220
|
+
emblaApi: EmblaCarouselType,
|
|
221
|
+
node: Element,
|
|
222
|
+
plugins: readonly EmblaPluginType[],
|
|
223
|
+
): void {
|
|
224
|
+
const handlers: Array<() => void> = [];
|
|
225
|
+
|
|
226
|
+
for (const { key, prefix, interaction } of AUTO_PLUGINS) {
|
|
227
|
+
const plugin = plugins.find((p) => p.name === key) as AutoplayType | AutoScrollType | undefined;
|
|
228
|
+
if (!plugin) continue;
|
|
229
|
+
|
|
230
|
+
const { playOnInit, stopOnInteraction } = readCarouselOptions<AutoPluginKitOptions>(
|
|
231
|
+
node,
|
|
232
|
+
prefix,
|
|
233
|
+
);
|
|
234
|
+
const holds = stopOnInteraction === false;
|
|
235
|
+
// `pending`: should play as soon as it can. `held`: what paused it with
|
|
236
|
+
// stop-on-interaction false (its end resumes it), or "" when nothing does.
|
|
237
|
+
let pending = playOnInit !== false;
|
|
238
|
+
let held: "" | "pointer" | "focus" = "";
|
|
239
|
+
let wasPlaying = false;
|
|
240
|
+
|
|
241
|
+
const playIfPending = () => {
|
|
242
|
+
if (!pending || emblaApi.snapList().length <= 1) return;
|
|
243
|
+
// An inactive carousel never inits its plugins, and play() before init throws.
|
|
244
|
+
if (!emblaApi.internalEngine().options.active) return;
|
|
245
|
+
plugin.play();
|
|
246
|
+
// play() does nothing while the plugin itself is inactive; keep waiting then.
|
|
247
|
+
pending = !plugin.isPlaying();
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
// Embla re-creates plugins on reinit by calling destroy() then init() on the
|
|
251
|
+
// same object, and destroy() stops it; note whether it was playing first.
|
|
252
|
+
const destroy = plugin.destroy;
|
|
253
|
+
plugin.destroy = () => {
|
|
254
|
+
wasPlaying = plugin.isPlaying();
|
|
255
|
+
destroy();
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
emblaApi.on("reinit", () => {
|
|
259
|
+
pending ||= wasPlaying;
|
|
260
|
+
wasPlaying = false;
|
|
261
|
+
// A reinit mid-drag drops the drag, so its pointer up never comes.
|
|
262
|
+
if (held === "pointer") {
|
|
263
|
+
held = "";
|
|
264
|
+
pending = true;
|
|
265
|
+
}
|
|
266
|
+
if (!held) playIfPending();
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
emblaApi.on(interaction, (_api, { detail }) => {
|
|
270
|
+
const { interaction: type, originalEvent } = detail;
|
|
271
|
+
if (type === "pointerdown" || type === "slidefocus") {
|
|
272
|
+
// A pointerdown's originalEvent is Embla's event model; its detail is the DOM event.
|
|
273
|
+
const pointer = originalEvent instanceof Event ? null : originalEvent.detail;
|
|
274
|
+
if (type === "pointerdown" && pointer && !startsDrag(pointer)) return;
|
|
275
|
+
if (!plugin.isPlaying() && !held) return;
|
|
276
|
+
held = holds ? (type === "pointerdown" ? "pointer" : "focus") : "";
|
|
277
|
+
pending = false;
|
|
278
|
+
plugin.stop();
|
|
279
|
+
} else if (
|
|
280
|
+
(type === "pointerup" && held === "pointer") ||
|
|
281
|
+
(type === "slidefocusout" && held === "focus")
|
|
282
|
+
) {
|
|
283
|
+
held = "";
|
|
284
|
+
plugin.play();
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
handlers.push(() => {
|
|
289
|
+
pending = false;
|
|
290
|
+
if (holds) plugin.reset();
|
|
291
|
+
else plugin.stop();
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
playIfPending();
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (handlers.length) manualStepHandlers.set(emblaApi, handlers);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* @description The kit's own Embla plugin, placed first in the plugin list so
|
|
302
|
+
* its `pointerdown` listener runs before any other plugin's, on init and
|
|
303
|
+
* after every reinit (Embla re-registers plugins in list order):
|
|
304
|
+
* - vetoes a drag when every slide already fits (one snap): Embla would still
|
|
305
|
+
* rubber-band. Returning false cancels Embla's drag and the later listeners
|
|
306
|
+
* (Class Names' pointer-down class, the plugins' interactions). Skipped when
|
|
307
|
+
* the author set `data-carousel-draggable`.
|
|
308
|
+
* - marks a drag as a `dragging` token on the viewport, and `data-ui-dragging`
|
|
309
|
+
* on the document root for the page-wide grabbing cursor (a `body:has(…) *`
|
|
310
|
+
* rule would restyle the whole page on every DOM insertion). Cleared on
|
|
311
|
+
* pointer up and on destroy (a reinit mid-drag drops the pointer up).
|
|
312
|
+
* @private
|
|
313
|
+
*/
|
|
314
|
+
function KitDragPlugin(viewport: Element, vetoesDrag: boolean): EmblaPluginType {
|
|
315
|
+
const root = viewport.ownerDocument.documentElement;
|
|
316
|
+
let api: EmblaCarouselType | undefined;
|
|
317
|
+
|
|
318
|
+
const setDragging = (on: boolean) => {
|
|
319
|
+
setCarouselState(viewport, "dragging", on);
|
|
320
|
+
root.toggleAttribute("data-ui-dragging", on);
|
|
321
|
+
};
|
|
322
|
+
const onPointerDown = (
|
|
323
|
+
emblaApi: EmblaCarouselType,
|
|
324
|
+
{ detail }: { detail: Event },
|
|
325
|
+
): false | void => {
|
|
326
|
+
if (vetoesDrag && !emblaApi.canGoToPrev() && !emblaApi.canGoToNext()) return false;
|
|
327
|
+
if (startsDrag(detail)) setDragging(true);
|
|
328
|
+
};
|
|
329
|
+
const onPointerUp = () => setDragging(false);
|
|
330
|
+
|
|
331
|
+
return {
|
|
332
|
+
name: "zazzDrag",
|
|
333
|
+
options: {},
|
|
334
|
+
init(emblaApi) {
|
|
335
|
+
api = emblaApi;
|
|
336
|
+
emblaApi.on("pointerdown", onPointerDown).on("pointerup", onPointerUp);
|
|
337
|
+
},
|
|
338
|
+
destroy() {
|
|
339
|
+
api?.off("pointerdown", onPointerDown).off("pointerup", onPointerUp);
|
|
340
|
+
setDragging(false);
|
|
341
|
+
},
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
142
345
|
// --- Manual navigation ---
|
|
143
346
|
|
|
144
347
|
/**
|
|
@@ -146,17 +349,12 @@ function readCarouselOptions<T>(node: Element, prefix: string): T {
|
|
|
146
349
|
* user interaction for the Autoplay and Auto Scroll plugins, which on their own
|
|
147
350
|
* only count a pointer-down on the viewport. Without it the plugin's timer keeps
|
|
148
351
|
* running, and a tick that lands just after a click moves a second slide.
|
|
149
|
-
* `
|
|
352
|
+
* `stop-on-interaction` (default true) stops the plugin; `false` restarts its delay.
|
|
150
353
|
* This is the pattern Embla's own examples use for navigation buttons.
|
|
151
354
|
* @private
|
|
152
355
|
*/
|
|
153
356
|
function onManualNavigation(emblaApi: EmblaCarouselType): void {
|
|
154
|
-
const
|
|
155
|
-
for (const plugin of [autoplay, autoScroll]) {
|
|
156
|
-
if (!plugin) continue;
|
|
157
|
-
if (plugin.options.stopOnInteraction === false) plugin.reset();
|
|
158
|
-
else plugin.stop();
|
|
159
|
-
}
|
|
357
|
+
for (const handler of manualStepHandlers.get(emblaApi) ?? []) handler();
|
|
160
358
|
}
|
|
161
359
|
|
|
162
360
|
// --- Active-index sync ---
|
|
@@ -184,14 +382,15 @@ function bindSlideStates(emblaApi: EmblaCarouselType): void {
|
|
|
184
382
|
const slides = emblaApi.slideNodes();
|
|
185
383
|
const inView = new Set(emblaApi.slidesInView());
|
|
186
384
|
const snapped = new Set(
|
|
187
|
-
emblaApi.internalEngine().
|
|
385
|
+
emblaApi.internalEngine().scrollSnapList.slidesBySnap[emblaApi.selectedSnap()] ?? [],
|
|
188
386
|
);
|
|
189
387
|
slides.forEach((slide, index) => {
|
|
190
388
|
setCarouselState(slide, "in-view", inView.has(index));
|
|
191
389
|
setCarouselState(slide, "snapped", snapped.has(index));
|
|
192
390
|
});
|
|
193
391
|
};
|
|
194
|
-
emblaApi.on("
|
|
392
|
+
emblaApi.on("reinit", update).on("select", update).on("slidesinview", update);
|
|
393
|
+
update();
|
|
195
394
|
}
|
|
196
395
|
|
|
197
396
|
/**
|
|
@@ -250,7 +449,7 @@ const addDotBtnsAndClickHandlers = (
|
|
|
250
449
|
* @private
|
|
251
450
|
*/
|
|
252
451
|
const addDotBtnsWithClickHandlers = () => {
|
|
253
|
-
const snapCount = emblaApi.
|
|
452
|
+
const snapCount = emblaApi.snapList().length;
|
|
254
453
|
|
|
255
454
|
dotsNode.innerHTML = "";
|
|
256
455
|
|
|
@@ -269,7 +468,7 @@ const addDotBtnsAndClickHandlers = (
|
|
|
269
468
|
"click",
|
|
270
469
|
() => {
|
|
271
470
|
onManualNavigation(emblaApi);
|
|
272
|
-
emblaApi.
|
|
471
|
+
emblaApi.goTo(i);
|
|
273
472
|
},
|
|
274
473
|
{ signal },
|
|
275
474
|
);
|
|
@@ -283,15 +482,15 @@ const addDotBtnsAndClickHandlers = (
|
|
|
283
482
|
*/
|
|
284
483
|
const toggleDotBtnsActive = () => {
|
|
285
484
|
if (!dotNodes.length) return;
|
|
286
|
-
setActiveIndex(dotNodes, emblaApi.
|
|
485
|
+
setActiveIndex(dotNodes, emblaApi.selectedSnap());
|
|
287
486
|
};
|
|
288
487
|
|
|
289
488
|
emblaApi
|
|
290
|
-
.on("
|
|
291
|
-
.on("
|
|
292
|
-
.on("init", toggleDotBtnsActive)
|
|
293
|
-
.on("reInit", toggleDotBtnsActive)
|
|
489
|
+
.on("reinit", addDotBtnsWithClickHandlers)
|
|
490
|
+
.on("reinit", toggleDotBtnsActive)
|
|
294
491
|
.on("select", toggleDotBtnsActive);
|
|
492
|
+
addDotBtnsWithClickHandlers();
|
|
493
|
+
toggleDotBtnsActive();
|
|
295
494
|
|
|
296
495
|
return () => {
|
|
297
496
|
dotsNode.innerHTML = "";
|
|
@@ -319,7 +518,7 @@ const addThumbClickHandlers = (
|
|
|
319
518
|
"click",
|
|
320
519
|
() => {
|
|
321
520
|
onManualNavigation(emblaApiMain);
|
|
322
|
-
emblaApiMain.
|
|
521
|
+
emblaApiMain.goTo(index);
|
|
323
522
|
},
|
|
324
523
|
{ signal },
|
|
325
524
|
);
|
|
@@ -344,8 +543,8 @@ const addTogglethumbsActive = (
|
|
|
344
543
|
* @private
|
|
345
544
|
*/
|
|
346
545
|
const toggleThumbBtnsActive = () => {
|
|
347
|
-
const selected = emblaApiMain.
|
|
348
|
-
emblaApiThumb.
|
|
546
|
+
const selected = emblaApiMain.selectedSnap();
|
|
547
|
+
emblaApiThumb.goTo(selected);
|
|
349
548
|
setActiveIndex(slidesthumbs, selected, { ariaCurrent: true });
|
|
350
549
|
};
|
|
351
550
|
|
|
@@ -411,7 +610,7 @@ function bindDragClickSuppression(
|
|
|
411
610
|
startY = e.clientY;
|
|
412
611
|
lastX = e.clientX;
|
|
413
612
|
lastY = e.clientY;
|
|
414
|
-
snapAtDown = emblaApi.
|
|
613
|
+
snapAtDown = emblaApi.selectedSnap();
|
|
415
614
|
},
|
|
416
615
|
{ passive: true, signal },
|
|
417
616
|
);
|
|
@@ -440,7 +639,7 @@ function bindDragClickSuppression(
|
|
|
440
639
|
|
|
441
640
|
root.addEventListener("pointerup", finalizePointer, { passive: true, signal });
|
|
442
641
|
root.addEventListener("pointercancel", finalizePointer, { passive: true, signal });
|
|
443
|
-
emblaApi.on("
|
|
642
|
+
emblaApi.on("pointerup", finalizePointer);
|
|
444
643
|
|
|
445
644
|
// Touch/trackpad drags can move with tiny deltas. Treat Embla scroll as drag intent,
|
|
446
645
|
// but lightbox openers need extra tolerance so minor carousel settle does not block clicks.
|
|
@@ -448,7 +647,7 @@ function bindDragClickSuppression(
|
|
|
448
647
|
if (!pointerDown) return;
|
|
449
648
|
|
|
450
649
|
if (guardsCommands) {
|
|
451
|
-
if (pointerDistance() >= DRAG_THRESHOLD_PX || emblaApi.
|
|
650
|
+
if (pointerDistance() >= DRAG_THRESHOLD_PX || emblaApi.selectedSnap() !== snapAtDown) {
|
|
452
651
|
moved = true;
|
|
453
652
|
}
|
|
454
653
|
return;
|
|
@@ -551,17 +750,12 @@ function initEmblaRoot(emblaNode: Element): void {
|
|
|
551
750
|
}
|
|
552
751
|
});
|
|
553
752
|
|
|
554
|
-
// Veto drag gestures when every slide already fits in the viewport: with a
|
|
555
|
-
// single snap Embla still rubber-bands on drag, which feels broken. The
|
|
556
|
-
// callback re-evaluates on every pointer down, so it stays correct across
|
|
557
|
-
// resizes/reInit. Respect an explicit data-carousel-watch-drag override.
|
|
558
|
-
if (!("watchDrag" in apiOptions)) {
|
|
559
|
-
apiOptions.watchDrag = (api: EmblaCarouselType) => api.canScrollPrev() || api.canScrollNext();
|
|
560
|
-
}
|
|
561
|
-
|
|
562
753
|
// Plugins load only when listed in data-carousel-plugins; option attrs alone
|
|
563
754
|
// do not enable them. Unknown slugs are ignored.
|
|
564
|
-
|
|
755
|
+
// The kit's drag plugin goes first (see KitDragPlugin).
|
|
756
|
+
const plugins: EmblaPluginType[] = [
|
|
757
|
+
KitDragPlugin(emblaViewportNode, !("draggable" in apiOptions)),
|
|
758
|
+
];
|
|
565
759
|
for (const slug of parseCarouselPlugins(emblaNode.getAttribute("data-carousel-plugins"))) {
|
|
566
760
|
const create = PLUGIN_BY_SLUG[slug as CarouselPluginSlug];
|
|
567
761
|
if (!create) continue;
|
|
@@ -574,19 +768,8 @@ function initEmblaRoot(emblaNode: Element): void {
|
|
|
574
768
|
apiOptions as EmblaOptionsType,
|
|
575
769
|
plugins,
|
|
576
770
|
);
|
|
577
|
-
// Drag state is a data-carousel-state token on the viewport, and
|
|
578
|
-
// data-ui-dragging on the root for the page-wide grabbing cursor (a
|
|
579
|
-
// `body:has(…) *` rule would restyle the whole page on every DOM insertion).
|
|
580
|
-
const root = emblaNode.ownerDocument.documentElement;
|
|
581
|
-
emblaApi.on("pointerDown", () => {
|
|
582
|
-
if (emblaViewportNode) setCarouselState(emblaViewportNode, "dragging", true);
|
|
583
|
-
root.setAttribute("data-ui-dragging", "");
|
|
584
|
-
});
|
|
585
|
-
emblaApi.on("pointerUp", () => {
|
|
586
|
-
if (emblaViewportNode) setCarouselState(emblaViewportNode, "dragging", false);
|
|
587
|
-
root.removeAttribute("data-ui-dragging");
|
|
588
|
-
});
|
|
589
771
|
bindSlideStates(emblaApi);
|
|
772
|
+
bindAutoPlugins(emblaApi, emblaNode, plugins);
|
|
590
773
|
|
|
591
774
|
emblaNode._emblaApi = emblaApi;
|
|
592
775
|
|
|
@@ -602,7 +785,7 @@ function initEmblaRoot(emblaNode: Element): void {
|
|
|
602
785
|
"click",
|
|
603
786
|
() => {
|
|
604
787
|
onManualNavigation(emblaApi);
|
|
605
|
-
emblaApi.
|
|
788
|
+
emblaApi.goToPrev();
|
|
606
789
|
},
|
|
607
790
|
{ signal },
|
|
608
791
|
);
|
|
@@ -613,7 +796,7 @@ function initEmblaRoot(emblaNode: Element): void {
|
|
|
613
796
|
"click",
|
|
614
797
|
() => {
|
|
615
798
|
onManualNavigation(emblaApi);
|
|
616
|
-
emblaApi.
|
|
799
|
+
emblaApi.goToNext();
|
|
617
800
|
},
|
|
618
801
|
{ signal },
|
|
619
802
|
);
|
|
@@ -709,7 +892,7 @@ function initDialogOpenSubscription(): void {
|
|
|
709
892
|
roots.forEach(function (root) {
|
|
710
893
|
const startIndex = root.getAttribute("data-carousel-start-index");
|
|
711
894
|
if (startIndex != null && root._emblaApi) {
|
|
712
|
-
root._emblaApi.
|
|
895
|
+
root._emblaApi.goTo(Number(startIndex), true);
|
|
713
896
|
root.removeAttribute("data-carousel-start-index");
|
|
714
897
|
}
|
|
715
898
|
|
|
@@ -784,8 +967,8 @@ const initEmblaKeyboardNav: InitEmblaKeyboardNavFn = function () {
|
|
|
784
967
|
|
|
785
968
|
e.preventDefault();
|
|
786
969
|
onManualNavigation(root._emblaApi);
|
|
787
|
-
if (e.key === "ArrowLeft") root._emblaApi.
|
|
788
|
-
else root._emblaApi.
|
|
970
|
+
if (e.key === "ArrowLeft") root._emblaApi.goToPrev();
|
|
971
|
+
else root._emblaApi.goToNext();
|
|
789
972
|
});
|
|
790
973
|
};
|
|
791
974
|
|
|
@@ -829,7 +1012,7 @@ function initEmblaStartLinks(): void {
|
|
|
829
1012
|
if (index == null && trigger.hasAttribute("commandfor")) {
|
|
830
1013
|
const emblaRoot = trigger.closest(':is(ui-carousel, [data-ui~="carousel"])');
|
|
831
1014
|
if (emblaRoot?._emblaApi) {
|
|
832
|
-
index = String(emblaRoot._emblaApi.
|
|
1015
|
+
index = String(emblaRoot._emblaApi.selectedSnap());
|
|
833
1016
|
}
|
|
834
1017
|
}
|
|
835
1018
|
|
|
@@ -843,7 +1026,7 @@ function initEmblaStartLinks(): void {
|
|
|
843
1026
|
if (!root) return;
|
|
844
1027
|
|
|
845
1028
|
if (root._emblaApi) {
|
|
846
|
-
root._emblaApi.
|
|
1029
|
+
root._emblaApi.goTo(Number(index), true);
|
|
847
1030
|
} else if (index != null) {
|
|
848
1031
|
root.setAttribute("data-carousel-start-index", index);
|
|
849
1032
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kit-styling.d.ts","sourceRoot":"","sources":["kit-styling.ts"],"names":[],"mappings":"AAEA,sGAAsG;AACtG,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"kit-styling.d.ts","sourceRoot":"","sources":["kit-styling.ts"],"names":[],"mappings":"AAEA,sGAAsG;AACtG,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,EAyR1C,CAAC;AAEF,0GAA0G;AAC1G,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CA0DlE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAmLnE,CAAC"}
|