@zazz-ui/core 0.13.0 → 0.14.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/CHANGELOG.md +93 -0
- package/README.md +5 -9
- package/dist/sri.json +34 -30
- package/dist/zazz.css +1 -1
- package/dist/zazz.js +1 -1
- package/editor/zazz.css-data.json +173 -3
- package/editor/zazz.html-data.json +138 -0
- package/editor/zazz.language-data.json +313 -125
- package/editor/zazz.lint-data.json +1501 -1383
- package/package.json +1 -5
- package/src/base/_defaults.css +1 -1
- package/src/base/_reset.css +16 -2
- package/src/base/_variables.css +43 -31
- package/src/base/carousel-scroll.d.ts +161 -0
- package/src/base/carousel-scroll.d.ts.map +1 -0
- package/src/base/carousel-scroll.js +1035 -0
- package/src/base/carousel-scroll.ts +1227 -0
- package/src/base/carousel.d.ts +34 -0
- package/src/base/carousel.d.ts.map +1 -0
- package/src/base/carousel.js +279 -0
- package/src/base/carousel.ts +292 -0
- package/src/base/dialog-lifecycle.js +1 -1
- package/src/base/dialog-lifecycle.ts +1 -1
- package/src/base/gesture.d.ts +201 -0
- package/src/base/gesture.d.ts.map +1 -0
- package/src/base/gesture.js +317 -0
- package/src/base/gesture.ts +494 -0
- package/src/base/kit-styling.d.ts.map +1 -1
- package/src/base/kit-styling.js +182 -162
- package/src/base/kit-styling.ts +182 -162
- package/src/base/utils.d.ts +1 -1
- package/src/base/utils.js +2 -2
- package/src/base/utils.ts +2 -2
- package/src/globals.d.ts +7 -30
- package/src/head.d.ts.map +1 -1
- package/src/head.js +1 -25
- package/src/head.ts +1 -25
- package/src/index.css +1 -0
- package/src/index.d.ts +6 -5
- package/src/index.d.ts.map +1 -1
- package/src/index.js +6 -5
- package/src/index.ts +6 -5
- package/src/manifest.d.ts +1 -1
- package/src/manifest.d.ts.map +1 -1
- package/src/manifest.js +25 -13
- package/src/manifest.ts +26 -14
- package/src/primitives/button/button.css +1 -1
- package/src/primitives/carousel/carousel.css +103 -20
- package/src/primitives/carousel/carousel.d.ts +4 -32
- package/src/primitives/carousel/carousel.d.ts.map +1 -1
- package/src/primitives/carousel/carousel.js +39 -14
- package/src/primitives/carousel/carousel.ts +21 -25
- package/src/primitives/dialog/dialog.css +14 -8
- package/src/primitives/drawer/drawer-indent.html +27 -0
- package/src/primitives/drawer/drawer-nested.html +72 -0
- package/src/primitives/drawer/drawer-responsive-dialog.html +44 -0
- package/src/primitives/drawer/drawer-snap.html +26 -0
- package/src/primitives/drawer/drawer.css +528 -0
- package/src/primitives/drawer/drawer.d.ts +24 -0
- package/src/primitives/drawer/drawer.d.ts.map +1 -0
- package/src/primitives/drawer/drawer.html +42 -0
- package/src/primitives/drawer/drawer.js +765 -0
- package/src/primitives/drawer/drawer.ts +823 -0
- package/src/primitives/fields/fields.css +4 -2
- package/src/primitives/input/input.css +4 -3
- package/src/primitives/input-group/input-group.css +5 -5
- package/src/primitives/lightbox/lightbox.css +2 -2
- package/src/primitives/lightbox/lightbox.d.ts.map +1 -1
- package/src/primitives/lightbox/lightbox.js +9 -8
- package/src/primitives/lightbox/lightbox.ts +9 -8
- package/src/primitives/password-group/password-group.css +5 -5
- package/src/primitives/radio/radio.css +15 -10
- package/src/primitives/slider/slider.css +2 -2
- package/src/primitives/switch/switch.css +6 -6
- package/src/primitives/tabs/tabs.css +10 -10
- package/src/primitives/toaster/toaster.css +29 -1
- package/src/primitives/toaster/toaster.d.ts.map +1 -1
- package/src/primitives/toaster/toaster.js +117 -9
- package/src/primitives/toaster/toaster.ts +136 -9
- package/src/primitives/tooltip/tooltip.css +93 -10
- package/src/base/embla.d.ts +0 -90
- package/src/base/embla.d.ts.map +0 -1
- package/src/base/embla.js +0 -878
- package/src/base/embla.ts +0 -1066
|
@@ -0,0 +1,1227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview The carousel engine: native scroll snap, plus what it lacks.
|
|
5
|
+
* @description Started per carousel root by base/carousel.ts (which documents
|
|
6
|
+
* the markup and the attributes). The viewport is a real scroll container (`scroll-snap-type: x mandatory`,
|
|
7
|
+
* set in carousel.css), so touch, trackpad, wheel, and keyboard scrolling are
|
|
8
|
+
* the browser's own: compositor-driven, no script per frame, and the content
|
|
9
|
+
* stays scrollable without JS. This module adds what the platform lacks:
|
|
10
|
+
*
|
|
11
|
+
* - **Mouse drag** (`base/gesture.ts`): a mouse press drags the track 1:1 with
|
|
12
|
+
* snapping off, rubber-bands past the ends, and on release projects the
|
|
13
|
+
* flick's velocity to a snap and scrolls there. Touch and pen are left to
|
|
14
|
+
* native scrolling (`canStart` rejects them).
|
|
15
|
+
* - **Selection**: the nearest snap, tracked from a rAF-throttled `scroll`
|
|
16
|
+
* listener and settled on `scrollend` (debounced `scroll` where missing);
|
|
17
|
+
* a click's pending target wins while its scroll is in flight.
|
|
18
|
+
* - **Loop** without clones: slides are rotated with `order` so the current
|
|
19
|
+
* one sits mid-track with neighbours on both sides, then an instant scroll
|
|
20
|
+
* compensates the shift, all while snapping and overflow are locked.
|
|
21
|
+
* Wrapped slides that are out of view are `inert`, so Tab order and the
|
|
22
|
+
* accessibility tree only skip content the user cannot see.
|
|
23
|
+
* - **Axis and direction**: every position is logical (px from the track's
|
|
24
|
+
* start edge), so a vertical track (`data-carousel-axis="y"`) and a
|
|
25
|
+
* right-to-left one (`dir="rtl"` anywhere above it) run the same code.
|
|
26
|
+
* - **Thumbs** (`linkThumbs`): a second engine on the thumb strip, drag-free
|
|
27
|
+
* by default, that keeps the selected thumb in view.
|
|
28
|
+
* - **Autoplay / auto-scroll** (`data-carousel-plugins="autoplay"` or
|
|
29
|
+
* `"auto-scroll"`), with the kit's interaction rules (see `readAutoOptions`).
|
|
30
|
+
* Both pause while the carousel is off screen or the tab is hidden.
|
|
31
|
+
* - Prev/next, dot pagination, the `in-view` / `snapped` / `active` /
|
|
32
|
+
* `playing` state tokens, and a `zazz:carousel-select` event on the root.
|
|
33
|
+
*
|
|
34
|
+
* Supported options (on the root): `data-carousel-loop`, `-align`
|
|
35
|
+
* (`start` | `center` | `end`), `-axis` (`x` | `y`), `-draggable="false"`,
|
|
36
|
+
* `-drag-free`, `-skip-snaps` (a flick may pass several snaps; default one),
|
|
37
|
+
* `-start-snap`. Thumb strips read the same names under
|
|
38
|
+
* `data-carousel-thumbs-*` on the thumbs slot.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
import { rubberBand, trackDrag } from "./gesture.ts";
|
|
42
|
+
import { Utils } from "./utils.ts";
|
|
43
|
+
|
|
44
|
+
// --- Types ---
|
|
45
|
+
|
|
46
|
+
/** The engine's public API, stored on the root as `_carousel`. */
|
|
47
|
+
interface CarouselApi {
|
|
48
|
+
/** Scrolls to a snap (or, with loop, a slide) by index. */
|
|
49
|
+
goTo(index: number, instant?: boolean): void;
|
|
50
|
+
goToNext(): void;
|
|
51
|
+
goToPrev(): void;
|
|
52
|
+
/** The current snap (or, with loop, slide) index. */
|
|
53
|
+
selectedSnap(): number;
|
|
54
|
+
/** Snap scroll positions in px from the track's start edge, in track order. */
|
|
55
|
+
snapList(): number[];
|
|
56
|
+
/** Scrolls the least distance that brings a slide fully into view. */
|
|
57
|
+
revealSlide(index: number, instant?: boolean): void;
|
|
58
|
+
/** Starts autoplay / auto-scroll, when the root lists one in `data-carousel-plugins`. */
|
|
59
|
+
play(): void;
|
|
60
|
+
stop(): void;
|
|
61
|
+
isPlaying(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Reports a manual step (Prev/Next, a dot, a thumb, an arrow key) to
|
|
64
|
+
* autoplay / auto-scroll: stops it, or with `…-stop-on-interaction="false"`
|
|
65
|
+
* restarts its delay. Call before the step.
|
|
66
|
+
*/
|
|
67
|
+
interact(): void;
|
|
68
|
+
/** True for a vertical track (`data-carousel-axis="y"`). */
|
|
69
|
+
readonly vertical: boolean;
|
|
70
|
+
/** True when the track runs right to left. */
|
|
71
|
+
readonly rtl: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Options read off the root's `data-carousel-*` attributes. */
|
|
75
|
+
interface NativeOptions {
|
|
76
|
+
loop: boolean;
|
|
77
|
+
draggable: boolean;
|
|
78
|
+
dragFree: boolean;
|
|
79
|
+
skipSnaps: boolean;
|
|
80
|
+
startSnap: number;
|
|
81
|
+
vertical: boolean;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** How one engine instance reads its options and which controls it owns. */
|
|
85
|
+
interface EngineConfig {
|
|
86
|
+
/** Attribute prefix the options are read from (default `data-carousel-`). */
|
|
87
|
+
prefix?: string;
|
|
88
|
+
/** Defaults for options the attributes leave out. */
|
|
89
|
+
defaults?: Partial<Pick<NativeOptions, "loop" | "dragFree">>;
|
|
90
|
+
/** Wire the root's prev / next / dots slots and its autoplay (false for a thumb strip). */
|
|
91
|
+
controls?: boolean;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Autoplay / auto-scroll settings (see `readAutoOptions`). */
|
|
95
|
+
interface AutoOptions {
|
|
96
|
+
mode: "autoplay" | "auto-scroll";
|
|
97
|
+
delay: number;
|
|
98
|
+
speed: number;
|
|
99
|
+
startDelay: number;
|
|
100
|
+
backward: boolean;
|
|
101
|
+
playOnInit: boolean;
|
|
102
|
+
stopOnInteraction: boolean;
|
|
103
|
+
stopOnMouseEnter: boolean;
|
|
104
|
+
stopOnLastSnap: boolean;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** One snap point: a scroll position and the slides that rest at it. */
|
|
108
|
+
interface Snap {
|
|
109
|
+
pos: number;
|
|
110
|
+
slides: number[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// --- Constants ---
|
|
114
|
+
|
|
115
|
+
/** Deceleration for projecting a release, in px/ms² (≈ a native fling's end distance). */
|
|
116
|
+
const DECELERATION = 0.0025;
|
|
117
|
+
|
|
118
|
+
/** Release speed (px/ms) that steps a snap even when the projection lands back on the start one. */
|
|
119
|
+
const STEP_VELOCITY = 0.3;
|
|
120
|
+
|
|
121
|
+
/** Where `scrollend` is missing, the quiet time that counts as settled, in ms. */
|
|
122
|
+
const SETTLE_FALLBACK_MS = 120;
|
|
123
|
+
|
|
124
|
+
/** Fastest a drag-free coast may decay (per ms), when an end cuts its distance short. */
|
|
125
|
+
const MAX_COAST_RATE = 0.02;
|
|
126
|
+
|
|
127
|
+
/** Auto-scroll `speed` is px per 60 Hz frame, scaled by real frame time. */
|
|
128
|
+
const FRAME_MS = 1000 / 60;
|
|
129
|
+
|
|
130
|
+
// --- State tokens ---
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @description Adds or removes one token of an element's `data-carousel-state`
|
|
134
|
+
* list, leaving the other tokens in place.
|
|
135
|
+
*/
|
|
136
|
+
function setCarouselState(node: Element, token: string, on: boolean): void {
|
|
137
|
+
const current = node.getAttribute("data-carousel-state") ?? "";
|
|
138
|
+
const tokens = current.split(/\s+/).filter(Boolean);
|
|
139
|
+
if (tokens.includes(token) === on) return;
|
|
140
|
+
const next = on ? [...tokens, token] : tokens.filter((t) => t !== token);
|
|
141
|
+
if (next.length) node.setAttribute("data-carousel-state", next.join(" "));
|
|
142
|
+
else node.removeAttribute("data-carousel-state");
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// --- Pure helpers ---
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @description The distance a release coasts at constant deceleration
|
|
149
|
+
* (v² / 2a), signed like the velocity.
|
|
150
|
+
*/
|
|
151
|
+
function projectRelease(velocity: number, deceleration = DECELERATION): number {
|
|
152
|
+
return (Math.sign(velocity) * velocity * velocity) / (2 * deceleration);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Index of the snap nearest to `pos`. */
|
|
156
|
+
function nearestSnap(snaps: readonly Snap[], pos: number): number {
|
|
157
|
+
let best = 0;
|
|
158
|
+
let bestDistance = Infinity;
|
|
159
|
+
snaps.forEach((snap, index) => {
|
|
160
|
+
const distance = Math.abs(snap.pos - pos);
|
|
161
|
+
if (distance < bestDistance) {
|
|
162
|
+
bestDistance = distance;
|
|
163
|
+
best = index;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
return best;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* @description Visual order for a looped track: rotates the slides so `center`
|
|
171
|
+
* has `before` slides ahead of it (by default half the track).
|
|
172
|
+
*
|
|
173
|
+
* @returns The `order` value per slide, in DOM order.
|
|
174
|
+
*/
|
|
175
|
+
function loopOrders(count: number, center: number, before = Math.floor(count / 2)): number[] {
|
|
176
|
+
return Array.from({ length: count }, (_, i) => (((i - center + before) % count) + count) % count);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @description How many slides a looped track keeps ahead of the current one:
|
|
181
|
+
* the spare slides (those not in view) split evenly around the view, so a
|
|
182
|
+
* drag or flick in either direction has the same room before an end.
|
|
183
|
+
*
|
|
184
|
+
* @param count - Slides in the track.
|
|
185
|
+
* @param perView - Slides the viewport shows at once (current included).
|
|
186
|
+
*/
|
|
187
|
+
function loopLead(count: number, perView: number): number {
|
|
188
|
+
return Math.max(1, Math.floor((count - Math.max(1, perView)) / 2));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @description How far to rotate a looped track so a step fits: the slides in
|
|
193
|
+
* view and the slides the target shows must all sit inside the track, in
|
|
194
|
+
* order. Ranges are positions along the track (`order` values); the target's
|
|
195
|
+
* may run past either end.
|
|
196
|
+
*
|
|
197
|
+
* @param count - Slides in the track.
|
|
198
|
+
* @param view - First and last position in view now.
|
|
199
|
+
* @param target - First and last position in view once the step lands.
|
|
200
|
+
* @returns Positions to rotate by (0 when the step already fits, with the
|
|
201
|
+
* span centred otherwise), or null when the span needs more slides than exist.
|
|
202
|
+
*/
|
|
203
|
+
function loopShift(
|
|
204
|
+
count: number,
|
|
205
|
+
view: { first: number; last: number },
|
|
206
|
+
target: { first: number; last: number },
|
|
207
|
+
): number | null {
|
|
208
|
+
const lo = Math.min(view.first, target.first);
|
|
209
|
+
const hi = Math.max(view.last, target.last);
|
|
210
|
+
if (lo >= 0 && hi <= count - 1) return 0;
|
|
211
|
+
const span = hi - lo + 1;
|
|
212
|
+
if (span > count) return null;
|
|
213
|
+
return Math.floor((count - span) / 2) - lo;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @description Which snap a release lands on: the one nearest to the
|
|
218
|
+
* projected position, stepping at least one snap in the flick's direction
|
|
219
|
+
* when the release was fast but the projection fell back to the start.
|
|
220
|
+
*
|
|
221
|
+
* @param velocity - Logical px/ms: positive moves the content toward the end
|
|
222
|
+
* edge, which scrolls toward the start.
|
|
223
|
+
*/
|
|
224
|
+
function releaseTarget(
|
|
225
|
+
snaps: readonly Snap[],
|
|
226
|
+
from: number,
|
|
227
|
+
projected: number,
|
|
228
|
+
velocity: number,
|
|
229
|
+
skipSnaps = false,
|
|
230
|
+
): number {
|
|
231
|
+
let target = nearestSnap(snaps, projected);
|
|
232
|
+
if (target === from && Math.abs(velocity) > STEP_VELOCITY) {
|
|
233
|
+
target = from + (velocity > 0 ? -1 : 1);
|
|
234
|
+
}
|
|
235
|
+
// a flick moves one snap at most unless `skip-snaps` is on
|
|
236
|
+
if (!skipSnaps) target = Math.min(from + 1, Math.max(from - 1, target));
|
|
237
|
+
return Math.min(snaps.length - 1, Math.max(0, target));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* @description Reads autoplay / auto-scroll from the root: the slug in
|
|
242
|
+
* `data-carousel-plugins` picks the mode (auto-scroll wins when both are
|
|
243
|
+
* listed), and its options come from that plugin's attributes:
|
|
244
|
+
* - autoplay (`data-carousel-autoplay-*`): `delay` (ms, 4000),
|
|
245
|
+
* `stop-on-last-snap` (false; otherwise wraps to the first snap).
|
|
246
|
+
* - auto-scroll (`data-carousel-auto-scroll-*`): `speed` (px per 60 Hz frame,
|
|
247
|
+
* 2), `start-delay` (ms before it moves, and before it resumes, 1000),
|
|
248
|
+
* `direction` (`forward` | `backward`). It doesn't start on its own under
|
|
249
|
+
* `prefers-reduced-motion: reduce`.
|
|
250
|
+
* - both: `play-on-init` (true), `stop-on-interaction` (true: a drag, a
|
|
251
|
+
* scroll, slide focus, or a manual step stops it for good; `false` holds it
|
|
252
|
+
* until the interaction ends), `stop-on-mouse-enter` (false).
|
|
253
|
+
*
|
|
254
|
+
* @returns The settings, or null when neither slug is listed.
|
|
255
|
+
*/
|
|
256
|
+
function readAutoOptions(root: Element): AutoOptions | null {
|
|
257
|
+
const slugs = (root.getAttribute("data-carousel-plugins") ?? "").split(/[\s,]+/);
|
|
258
|
+
const mode = slugs.includes("auto-scroll")
|
|
259
|
+
? "auto-scroll"
|
|
260
|
+
: slugs.includes("autoplay")
|
|
261
|
+
? "autoplay"
|
|
262
|
+
: null;
|
|
263
|
+
if (!mode) return null;
|
|
264
|
+
const raw = Utils.parseDataAttributes(
|
|
265
|
+
root,
|
|
266
|
+
mode === "autoplay" ? "data-carousel-autoplay-" : "data-carousel-auto-scroll-",
|
|
267
|
+
);
|
|
268
|
+
const num = (value: unknown, fallback: number) =>
|
|
269
|
+
typeof value === "number" && value >= 0 ? value : fallback;
|
|
270
|
+
return {
|
|
271
|
+
mode,
|
|
272
|
+
delay: num(raw.delay, 4000),
|
|
273
|
+
speed: num(raw.speed, 2),
|
|
274
|
+
startDelay: num(raw.startDelay, 1000),
|
|
275
|
+
backward: raw.direction === "backward",
|
|
276
|
+
playOnInit: raw.playOnInit !== false,
|
|
277
|
+
stopOnInteraction: raw.stopOnInteraction !== false,
|
|
278
|
+
stopOnMouseEnter: raw.stopOnMouseEnter === true,
|
|
279
|
+
stopOnLastSnap: raw.stopOnLastSnap === true,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// --- Engine ---
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* @description Starts the engine on a carousel root.
|
|
287
|
+
*
|
|
288
|
+
* @param root - The carousel root (`<ui-carousel>` or `[data-ui~="carousel"]`),
|
|
289
|
+
* or a thumbs slot.
|
|
290
|
+
* @param viewport - Its viewport slot.
|
|
291
|
+
* @param signal - Aborting it tears everything down.
|
|
292
|
+
* @param config - Where options come from and which controls to wire.
|
|
293
|
+
* @returns The API, or null when the markup has no container.
|
|
294
|
+
*/
|
|
295
|
+
function createCarousel(
|
|
296
|
+
root: Element,
|
|
297
|
+
viewport: HTMLElement,
|
|
298
|
+
signal: AbortSignal,
|
|
299
|
+
config: EngineConfig = {},
|
|
300
|
+
): CarouselApi | null {
|
|
301
|
+
const container = viewport.querySelector<HTMLElement>('[data-carousel-slot~="container"]');
|
|
302
|
+
if (!container) return null;
|
|
303
|
+
const slides = [
|
|
304
|
+
...container.querySelectorAll<HTMLElement>(':scope > [data-carousel-slot~="slide"]'),
|
|
305
|
+
];
|
|
306
|
+
const { prefix = "data-carousel-", defaults = {}, controls = true } = config;
|
|
307
|
+
|
|
308
|
+
const raw = Utils.parseDataAttributes(root, prefix);
|
|
309
|
+
const flag = (value: unknown, fallback: boolean) =>
|
|
310
|
+
typeof value === "boolean" ? value : fallback;
|
|
311
|
+
const options: NativeOptions = {
|
|
312
|
+
// loop needs a neighbour on each side of the current slide
|
|
313
|
+
loop: flag(raw.loop, defaults.loop ?? false) && slides.length >= 3,
|
|
314
|
+
draggable: flag(raw.draggable, true),
|
|
315
|
+
dragFree: flag(raw.dragFree, defaults.dragFree ?? false),
|
|
316
|
+
skipSnaps: flag(raw.skipSnaps, false),
|
|
317
|
+
startSnap: typeof raw.startSnap === "number" ? raw.startSnap : 0,
|
|
318
|
+
vertical: raw.axis === "y",
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
let snapsCache: Snap[] | null = null;
|
|
322
|
+
let perViewCache = 1;
|
|
323
|
+
/** Slides a resting snap shows before and after its own slide (from alignment). */
|
|
324
|
+
let reach = { back: 0, ahead: 0 };
|
|
325
|
+
let selected = -1;
|
|
326
|
+
/** A click's destination while its scroll is in flight (snap index). */
|
|
327
|
+
let pending: number | null = null;
|
|
328
|
+
/** With loop, the slide `pending` stands for (end snaps merge several slides). */
|
|
329
|
+
let pendingSlide: number | null = null;
|
|
330
|
+
let inView = new Set<number>();
|
|
331
|
+
let orders: number[] = slides.map(() => 0);
|
|
332
|
+
/** Mirrors the `gliding` token: snapping is off while the script moves the track. */
|
|
333
|
+
let gliding = false;
|
|
334
|
+
/** Mirrors the `settling` token: a loop rotation's lock. */
|
|
335
|
+
let settling = false;
|
|
336
|
+
/** A scroll asked for while settling; run once the lock lifts. */
|
|
337
|
+
let queued: (() => void) | null = null;
|
|
338
|
+
let dragging = false;
|
|
339
|
+
/** True while the auto-scroll loop is writing the scroll position. */
|
|
340
|
+
let autoScrolling = false;
|
|
341
|
+
|
|
342
|
+
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
343
|
+
const behavior = (instant?: boolean): ScrollBehavior =>
|
|
344
|
+
instant || reducedMotion.matches ? "auto" : "smooth";
|
|
345
|
+
|
|
346
|
+
// --- Axis ---
|
|
347
|
+
// Positions are logical: px from the track's start edge, growing toward the
|
|
348
|
+
// end. In RTL the start edge is the right one and `scrollLeft` runs from 0
|
|
349
|
+
// down to negative values (the spec's model, shipped in every engine).
|
|
350
|
+
|
|
351
|
+
const vertical = options.vertical;
|
|
352
|
+
const rtl = !vertical && getComputedStyle(viewport).direction === "rtl";
|
|
353
|
+
const sign = rtl ? -1 : 1;
|
|
354
|
+
const getPos = () => (vertical ? viewport.scrollTop : viewport.scrollLeft * sign);
|
|
355
|
+
const writePos = (pos: number) => {
|
|
356
|
+
if (vertical) viewport.scrollTop = pos;
|
|
357
|
+
else viewport.scrollLeft = pos * sign;
|
|
358
|
+
};
|
|
359
|
+
const scrollToPos = (pos: number, how: ScrollBehavior) =>
|
|
360
|
+
viewport.scrollTo(vertical ? { top: pos, behavior: how } : { left: pos * sign, behavior: how });
|
|
361
|
+
const clientSize = () => (vertical ? viewport.clientHeight : viewport.clientWidth);
|
|
362
|
+
const maxScroll = () =>
|
|
363
|
+
Math.max(0, (vertical ? viewport.scrollHeight : viewport.scrollWidth) - clientSize());
|
|
364
|
+
const clampPos = (pos: number) => Math.min(maxScroll(), Math.max(0, pos));
|
|
365
|
+
/** A box's start edge, in px from the viewport's start edge. */
|
|
366
|
+
const startOf = (rect: DOMRect, box: DOMRect) =>
|
|
367
|
+
vertical ? rect.top - box.top : rtl ? box.right - rect.right : rect.left - box.left;
|
|
368
|
+
const sizeOf = (rect: DOMRect) => (vertical ? rect.height : rect.width);
|
|
369
|
+
/** Pointer travel (px, on the drag axis) as logical travel. */
|
|
370
|
+
const logical = (physical: number) => (vertical ? physical : physical * sign);
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* An instant scroll. The `jumping` token sets `scroll-behavior: auto` in CSS,
|
|
374
|
+
* so the jump never inherits the viewport's smooth scrolling, whatever an
|
|
375
|
+
* engine makes of `behavior: "instant"`. Gliding and settling already set
|
|
376
|
+
* it, so their per-frame writes skip the two attribute changes.
|
|
377
|
+
*/
|
|
378
|
+
const jump = (pos: number) => {
|
|
379
|
+
if (gliding || settling) {
|
|
380
|
+
writePos(pos);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
setCarouselState(viewport, "jumping", true);
|
|
384
|
+
writePos(pos);
|
|
385
|
+
setCarouselState(viewport, "jumping", false);
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
const setGliding = (on: boolean) => {
|
|
389
|
+
gliding = on;
|
|
390
|
+
setCarouselState(viewport, "gliding", on);
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
// --- Geometry ---
|
|
394
|
+
|
|
395
|
+
/** Snap points from layout, clamped to the scroll range and merged where they coincide. */
|
|
396
|
+
const measure = (): Snap[] => {
|
|
397
|
+
const box = viewport.getBoundingClientRect();
|
|
398
|
+
const styles = getComputedStyle(viewport);
|
|
399
|
+
const padStart =
|
|
400
|
+
Number.parseFloat(
|
|
401
|
+
vertical ? styles.scrollPaddingBlockStart : styles.scrollPaddingInlineStart,
|
|
402
|
+
) || 0;
|
|
403
|
+
const padEnd =
|
|
404
|
+
Number.parseFloat(vertical ? styles.scrollPaddingBlockEnd : styles.scrollPaddingInlineEnd) ||
|
|
405
|
+
0;
|
|
406
|
+
const max = maxScroll();
|
|
407
|
+
const client = clientSize();
|
|
408
|
+
const at = getPos();
|
|
409
|
+
let firstSize = 0;
|
|
410
|
+
let firstAlign = "start";
|
|
411
|
+
const points = slides.map((slide, index) => {
|
|
412
|
+
const rect = slide.getBoundingClientRect();
|
|
413
|
+
const size = sizeOf(rect);
|
|
414
|
+
if (index === 0) firstSize = size;
|
|
415
|
+
const start = startOf(rect, box) + at;
|
|
416
|
+
// one value applies to both axes; two are `block inline`
|
|
417
|
+
const parts = getComputedStyle(slide).scrollSnapAlign.split(" ");
|
|
418
|
+
const align = vertical ? parts[0] : parts.at(-1);
|
|
419
|
+
if (index === 0) firstAlign = align ?? "start";
|
|
420
|
+
const raw =
|
|
421
|
+
align === "center"
|
|
422
|
+
? start + size / 2 - client / 2
|
|
423
|
+
: align === "end"
|
|
424
|
+
? start + size - client + padEnd
|
|
425
|
+
: start - padStart;
|
|
426
|
+
return { index, pos: Math.round(Math.min(max, Math.max(0, raw))) };
|
|
427
|
+
});
|
|
428
|
+
perViewCache = firstSize > 0 ? Math.max(1, Math.round(client / firstSize)) : 1;
|
|
429
|
+
const side = perViewCache - 1;
|
|
430
|
+
// centred slides that don't fill the view show a neighbour's edge on each side
|
|
431
|
+
const peek = firstSize * perViewCache < client - 1 ? 1 : 0;
|
|
432
|
+
reach =
|
|
433
|
+
firstAlign === "center"
|
|
434
|
+
? { back: Math.floor(perViewCache / 2) + peek, ahead: Math.floor(perViewCache / 2) + peek }
|
|
435
|
+
: firstAlign === "end"
|
|
436
|
+
? { back: side, ahead: 0 }
|
|
437
|
+
: { back: 0, ahead: side };
|
|
438
|
+
points.sort((a, b) => a.pos - b.pos);
|
|
439
|
+
const snaps: Snap[] = [];
|
|
440
|
+
for (const { index, pos } of points) {
|
|
441
|
+
const last = snaps.at(-1);
|
|
442
|
+
if (last && Math.abs(last.pos - pos) < 1) last.slides.push(index);
|
|
443
|
+
else snaps.push({ pos, slides: [index] });
|
|
444
|
+
}
|
|
445
|
+
return snaps;
|
|
446
|
+
};
|
|
447
|
+
const snaps = () => (snapsCache ??= measure());
|
|
448
|
+
const invalidate = () => {
|
|
449
|
+
snapsCache = null;
|
|
450
|
+
};
|
|
451
|
+
/** Slides in view at once, from the first slide's size. */
|
|
452
|
+
const perView = () => {
|
|
453
|
+
snaps();
|
|
454
|
+
return perViewCache;
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
/** The index the API speaks in: the snap, or with loop the slide (rotation-independent). */
|
|
458
|
+
const publicIndex = (snapIndex: number): number =>
|
|
459
|
+
options.loop ? (snaps()[snapIndex]?.slides[0] ?? 0) : snapIndex;
|
|
460
|
+
const snapOfSlide = (slide: number): number =>
|
|
461
|
+
Math.max(
|
|
462
|
+
0,
|
|
463
|
+
snaps().findIndex((snap) => snap.slides.includes(slide)),
|
|
464
|
+
);
|
|
465
|
+
|
|
466
|
+
// --- Output ---
|
|
467
|
+
|
|
468
|
+
let dots: HTMLElement[] = [];
|
|
469
|
+
const dotsNode = controls ? root.querySelector('[data-carousel-slot~="dots"]') : null;
|
|
470
|
+
const templateDot = dotsNode?.querySelector('[data-carousel-slot~="dot"]')?.cloneNode(true);
|
|
471
|
+
|
|
472
|
+
const buildDots = () => {
|
|
473
|
+
if (!dotsNode || !(templateDot instanceof HTMLElement)) return;
|
|
474
|
+
const count = options.loop ? slides.length : snaps().length;
|
|
475
|
+
if (count === dots.length) return;
|
|
476
|
+
dotsNode.replaceChildren();
|
|
477
|
+
dots = [];
|
|
478
|
+
if (count <= 1) return;
|
|
479
|
+
for (let i = 0; i < count; i++) {
|
|
480
|
+
const dot = templateDot.cloneNode(true) as HTMLElement;
|
|
481
|
+
dot.addEventListener(
|
|
482
|
+
"click",
|
|
483
|
+
() => {
|
|
484
|
+
api.interact();
|
|
485
|
+
api.goTo(i);
|
|
486
|
+
},
|
|
487
|
+
{ signal },
|
|
488
|
+
);
|
|
489
|
+
dots.push(dot);
|
|
490
|
+
}
|
|
491
|
+
dotsNode.append(...dots);
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
const render = (snapIndex: number) => {
|
|
495
|
+
const index = publicIndex(snapIndex);
|
|
496
|
+
const snapped = new Set(snaps()[snapIndex]?.slides ?? []);
|
|
497
|
+
slides.forEach((slide, i) => setCarouselState(slide, "snapped", snapped.has(i)));
|
|
498
|
+
dots.forEach((dot, i) => setCarouselState(dot, "active", i === index));
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
const select = (snapIndex: number) => {
|
|
502
|
+
if (snapIndex === selected) return;
|
|
503
|
+
selected = snapIndex;
|
|
504
|
+
render(snapIndex);
|
|
505
|
+
root.dispatchEvent(
|
|
506
|
+
new CustomEvent("zazz:carousel-select", { detail: { index: publicIndex(snapIndex) } }),
|
|
507
|
+
);
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
// --- Loop rotation ---
|
|
511
|
+
|
|
512
|
+
/** Wrapped slides (moved against DOM order) that are out of view leave Tab order. */
|
|
513
|
+
const syncInert = () => {
|
|
514
|
+
if (!options.loop) return;
|
|
515
|
+
const current = snaps()[selected]?.slides[0] ?? 0;
|
|
516
|
+
const lead = orders[current] ?? 0;
|
|
517
|
+
slides.forEach((slide, i) => {
|
|
518
|
+
const wrapped = orders[i]! < lead ? i > current : i < current;
|
|
519
|
+
slide.inert = wrapped && !inView.has(i);
|
|
520
|
+
});
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
/** Invalidates an older rotation's pending unlock when a newer one starts. */
|
|
524
|
+
let lockToken = 0;
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Reorders the track and scrolls by the anchor slide's shift so nothing
|
|
528
|
+
* visibly moves. `lock` also freezes snapping and the axis for two frames;
|
|
529
|
+
* the auto-scroll loop reorders without it.
|
|
530
|
+
*/
|
|
531
|
+
const applyOrders = (next: number[], anchorIndex: number, lock = true) => {
|
|
532
|
+
if (next.every((order, i) => order === orders[i])) return;
|
|
533
|
+
const anchor = slides[anchorIndex]!;
|
|
534
|
+
const box = viewport.getBoundingClientRect();
|
|
535
|
+
const before = startOf(anchor.getBoundingClientRect(), box);
|
|
536
|
+
// snapping off (some engines re-snap elsewhere mid-compensation) and the
|
|
537
|
+
// axis locked (iOS Safari paints the reordered frame before the scroll lands)
|
|
538
|
+
// an unlocked reorder (auto-scroll) leaves an earlier lock's unlock in place
|
|
539
|
+
const token = lock ? ++lockToken : lockToken;
|
|
540
|
+
if (lock) {
|
|
541
|
+
settling = true;
|
|
542
|
+
setCarouselState(viewport, "settling", true);
|
|
543
|
+
}
|
|
544
|
+
slides.forEach((slide, i) => {
|
|
545
|
+
if (orders[i] !== next[i]) slide.style.order = String(next[i]);
|
|
546
|
+
});
|
|
547
|
+
orders = next;
|
|
548
|
+
const shift = startOf(anchor.getBoundingClientRect(), box) - before;
|
|
549
|
+
jump(getPos() + shift);
|
|
550
|
+
invalidate();
|
|
551
|
+
if (!lock) return;
|
|
552
|
+
// Two frames: restoring overflow at once breaks the compensation in iOS
|
|
553
|
+
// Safari. A smooth scroll started under the lock is dropped by WebKit when
|
|
554
|
+
// overflow changes, so scrolls asked for meanwhile wait for the lift.
|
|
555
|
+
requestAnimationFrame(() =>
|
|
556
|
+
requestAnimationFrame(() => {
|
|
557
|
+
if (token !== lockToken) return;
|
|
558
|
+
settling = false;
|
|
559
|
+
setCarouselState(viewport, "settling", false);
|
|
560
|
+
const run = queued;
|
|
561
|
+
queued = null;
|
|
562
|
+
run?.();
|
|
563
|
+
}),
|
|
564
|
+
);
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
/** Rotates the track so `center` sits mid-track with neighbours on both sides. */
|
|
568
|
+
const rotate = (center: number, lock = true) =>
|
|
569
|
+
applyOrders(
|
|
570
|
+
loopOrders(slides.length, center, loopLead(slides.length, perView())),
|
|
571
|
+
center,
|
|
572
|
+
lock,
|
|
573
|
+
);
|
|
574
|
+
|
|
575
|
+
/** Track positions (`order`) of the first and last slide in view right now. */
|
|
576
|
+
const viewRange = () => {
|
|
577
|
+
const box = viewport.getBoundingClientRect();
|
|
578
|
+
const client = clientSize();
|
|
579
|
+
let first = Infinity;
|
|
580
|
+
let last = -Infinity;
|
|
581
|
+
slides.forEach((slide, i) => {
|
|
582
|
+
const rect = slide.getBoundingClientRect();
|
|
583
|
+
const start = startOf(rect, box);
|
|
584
|
+
if (start + sizeOf(rect) <= 1 || start >= client - 1) return;
|
|
585
|
+
first = Math.min(first, orders[i]!);
|
|
586
|
+
last = Math.max(last, orders[i]!);
|
|
587
|
+
});
|
|
588
|
+
return { first, last };
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
// --- Scroll tracking ---
|
|
592
|
+
|
|
593
|
+
let frame = 0;
|
|
594
|
+
const onScroll = () => {
|
|
595
|
+
if (holds.has("pointer")) pointerScrolled = true;
|
|
596
|
+
if (frame) return;
|
|
597
|
+
frame = requestAnimationFrame(() => {
|
|
598
|
+
frame = 0;
|
|
599
|
+
if (pending == null && !dragging) select(nearestSnap(snaps(), getPos()));
|
|
600
|
+
});
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
const settle = () => {
|
|
604
|
+
if (dragging || autoScrolling || coastFrame) return;
|
|
605
|
+
// a scrollend from an earlier scroll can land after the next one started
|
|
606
|
+
// (WebKit); acting on it would rotate the track under the new scroll
|
|
607
|
+
const target = pending == null ? null : snaps()[pending];
|
|
608
|
+
if (target && Math.abs(getPos() - target.pos) > 1) return;
|
|
609
|
+
pending = null;
|
|
610
|
+
const nearest = nearestSnap(snaps(), getPos());
|
|
611
|
+
// a glide that stopped between snaps (auto-scroll paused) lands on the
|
|
612
|
+
// nearest one before snapping resumes, or the browser would jump there
|
|
613
|
+
if (gliding && !options.dragFree && Math.abs(getPos() - snaps()[nearest]!.pos) > 1) {
|
|
614
|
+
scrollToSnap(nearest);
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
setGliding(false);
|
|
618
|
+
select(nearest);
|
|
619
|
+
if (options.loop) {
|
|
620
|
+
rotate(snaps()[selected]?.slides[0] ?? 0);
|
|
621
|
+
selected = nearestSnap(snaps(), getPos());
|
|
622
|
+
syncInert();
|
|
623
|
+
}
|
|
624
|
+
afterSettle();
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
viewport.addEventListener("scroll", onScroll, { passive: true, signal });
|
|
628
|
+
if ("onscrollend" in window) {
|
|
629
|
+
viewport.addEventListener("scrollend", settle, { signal });
|
|
630
|
+
} else {
|
|
631
|
+
let timer = 0;
|
|
632
|
+
viewport.addEventListener(
|
|
633
|
+
"scroll",
|
|
634
|
+
() => {
|
|
635
|
+
clearTimeout(timer);
|
|
636
|
+
timer = window.setTimeout(settle, SETTLE_FALLBACK_MS);
|
|
637
|
+
},
|
|
638
|
+
{ passive: true, signal },
|
|
639
|
+
);
|
|
640
|
+
signal.addEventListener("abort", () => clearTimeout(timer), { once: true });
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/** Scrolls to a snap; settles at once when there is nowhere to go (no scrollend follows). */
|
|
644
|
+
const scrollToSnap = (snapIndex: number, instant?: boolean, slide: number | null = null) => {
|
|
645
|
+
stopCoast();
|
|
646
|
+
const list = snaps();
|
|
647
|
+
const target = Math.min(list.length - 1, Math.max(0, snapIndex));
|
|
648
|
+
if (settling) {
|
|
649
|
+
// the target is already the destination, so a step asked for under the
|
|
650
|
+
// lock continues from it and the compensating scroll's scrollend is ignored
|
|
651
|
+
pending = target;
|
|
652
|
+
pendingSlide = slide;
|
|
653
|
+
select(target);
|
|
654
|
+
queued = () => scrollToSnap(snapIndex, instant, slide);
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
const pos = list[target]?.pos ?? 0;
|
|
658
|
+
if (Math.abs(getPos() - pos) < 1) {
|
|
659
|
+
settle();
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
pending = target;
|
|
663
|
+
pendingSlide = slide;
|
|
664
|
+
select(target);
|
|
665
|
+
if (instant) {
|
|
666
|
+
jump(pos);
|
|
667
|
+
settle();
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
scrollToPos(pos, behavior());
|
|
671
|
+
};
|
|
672
|
+
|
|
673
|
+
/** One step toward the end (+1) or the start (-1), from a click's pending target if any. */
|
|
674
|
+
const step = (direction: 1 | -1) => {
|
|
675
|
+
const from = pending ?? selected;
|
|
676
|
+
if (!options.loop) {
|
|
677
|
+
scrollToSnap(from + direction);
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
const count = slides.length;
|
|
681
|
+
const fromSlide = (pending != null ? pendingSlide : null) ?? publicIndex(from);
|
|
682
|
+
const slide = (fromSlide + direction + count) % count;
|
|
683
|
+
// The track is only re-centred when a scroll settles, so steps taken while
|
|
684
|
+
// one is in flight run out of slides. Rotate first when this one wouldn't
|
|
685
|
+
// fit: the rotation and its compensating scroll cancel the scroll in
|
|
686
|
+
// flight, and the new one starts from where the track visibly is.
|
|
687
|
+
const at = orders[fromSlide]! + direction;
|
|
688
|
+
const view = viewRange();
|
|
689
|
+
const shift = loopShift(count, view, { first: at - reach.back, last: at + reach.ahead });
|
|
690
|
+
// every slide is already in play between the view and the target
|
|
691
|
+
if (shift == null) return;
|
|
692
|
+
if (shift) {
|
|
693
|
+
const current = publicIndex(Math.max(0, selected));
|
|
694
|
+
pending = null;
|
|
695
|
+
applyOrders(
|
|
696
|
+
orders.map((order) => (((order + shift) % count) + count) % count),
|
|
697
|
+
Math.max(0, orders.indexOf(view.first)),
|
|
698
|
+
);
|
|
699
|
+
selected = snapOfSlide(current);
|
|
700
|
+
syncInert();
|
|
701
|
+
}
|
|
702
|
+
scrollToSnap(snapOfSlide(slide), false, slide);
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
// --- Autoplay / auto-scroll ---
|
|
706
|
+
|
|
707
|
+
const auto = controls ? readAutoOptions(root) : null;
|
|
708
|
+
/** Should play: play-on-init or play(), until stop() or a stopping interaction. */
|
|
709
|
+
let wanted = false;
|
|
710
|
+
/** What holds it with stop-on-interaction false; it resumes once this empties. */
|
|
711
|
+
const holds = new Set<"pointer" | "focus" | "hover">();
|
|
712
|
+
/** A scroll happened under the pointer hold, so its scrollend (not the pointer up) ends it. */
|
|
713
|
+
let pointerScrolled = false;
|
|
714
|
+
let onScreen = true;
|
|
715
|
+
let running = false;
|
|
716
|
+
let autoTimer = 0;
|
|
717
|
+
let autoFrame = 0;
|
|
718
|
+
let lastTick = 0;
|
|
719
|
+
let carry = 0;
|
|
720
|
+
|
|
721
|
+
const advance = () => {
|
|
722
|
+
autoTimer = 0;
|
|
723
|
+
const from = pending ?? selected;
|
|
724
|
+
if (!options.loop && from >= snaps().length - 1) {
|
|
725
|
+
if (auto?.stopOnLastSnap) {
|
|
726
|
+
wanted = false;
|
|
727
|
+
reconcile();
|
|
728
|
+
} else scrollToSnap(0);
|
|
729
|
+
} else step(1);
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
/** One auto-scroll frame: moves by speed × elapsed time and keeps a looped track rotated. */
|
|
733
|
+
const tick = (now: number) => {
|
|
734
|
+
if (!auto) return;
|
|
735
|
+
autoFrame = requestAnimationFrame(tick);
|
|
736
|
+
const elapsed = lastTick ? Math.min(50, now - lastTick) : 0;
|
|
737
|
+
lastTick = now;
|
|
738
|
+
carry += ((auto.backward ? -auto.speed : auto.speed) * elapsed) / FRAME_MS;
|
|
739
|
+
// whole px only: fractional scroll offsets round differently per engine
|
|
740
|
+
const whole = Math.trunc(carry);
|
|
741
|
+
if (!whole) return;
|
|
742
|
+
carry -= whole;
|
|
743
|
+
const next = getPos() + whole;
|
|
744
|
+
if (!options.loop && (next <= 0 || next >= maxScroll())) {
|
|
745
|
+
writePos(clampPos(next));
|
|
746
|
+
wanted = false;
|
|
747
|
+
reconcile();
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
writePos(next);
|
|
751
|
+
const nearest = nearestSnap(snaps(), getPos());
|
|
752
|
+
select(nearest);
|
|
753
|
+
if (options.loop) {
|
|
754
|
+
rotate(snaps()[nearest]?.slides[0] ?? 0, false);
|
|
755
|
+
selected = nearestSnap(snaps(), getPos());
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
const stopMotion = () => {
|
|
760
|
+
clearTimeout(autoTimer);
|
|
761
|
+
cancelAnimationFrame(autoFrame);
|
|
762
|
+
autoTimer = 0;
|
|
763
|
+
autoFrame = 0;
|
|
764
|
+
if (!autoScrolling) return;
|
|
765
|
+
autoScrolling = false;
|
|
766
|
+
settle();
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
const startMotion = () => {
|
|
770
|
+
if (!auto) return;
|
|
771
|
+
if (auto.mode === "autoplay") {
|
|
772
|
+
autoTimer = window.setTimeout(advance, auto.delay);
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
autoTimer = window.setTimeout(() => {
|
|
776
|
+
autoTimer = 0;
|
|
777
|
+
pending = null;
|
|
778
|
+
setGliding(true);
|
|
779
|
+
autoScrolling = true;
|
|
780
|
+
lastTick = 0;
|
|
781
|
+
carry = 0;
|
|
782
|
+
autoFrame = requestAnimationFrame(tick);
|
|
783
|
+
}, auto.startDelay);
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
/** Starts or stops the motion to match what should be happening; `restart` re-arms its delay. */
|
|
787
|
+
function reconcile(restart = false) {
|
|
788
|
+
const run =
|
|
789
|
+
!!auto &&
|
|
790
|
+
wanted &&
|
|
791
|
+
holds.size === 0 &&
|
|
792
|
+
onScreen &&
|
|
793
|
+
!document.hidden &&
|
|
794
|
+
maxScroll() > 0 &&
|
|
795
|
+
snaps().length > 1;
|
|
796
|
+
if (auto) setCarouselState(root, "playing", wanted);
|
|
797
|
+
if (run === running && !restart) return;
|
|
798
|
+
running = run;
|
|
799
|
+
stopMotion();
|
|
800
|
+
if (run) startMotion();
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/** Each settled scroll restarts autoplay's delay; it also ends a pointer hold. */
|
|
804
|
+
function afterSettle() {
|
|
805
|
+
if (!auto) return;
|
|
806
|
+
if (holds.delete("pointer")) {
|
|
807
|
+
reconcile();
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
if (running && auto.mode === "autoplay") {
|
|
811
|
+
clearTimeout(autoTimer);
|
|
812
|
+
autoTimer = window.setTimeout(advance, auto.delay);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/** An interaction: stops for good, or with stop-on-interaction false holds until it ends. */
|
|
817
|
+
const holdFor = (reason: "pointer" | "focus" | "hover") => {
|
|
818
|
+
if (!auto || !wanted) return;
|
|
819
|
+
if (auto.stopOnInteraction) wanted = false;
|
|
820
|
+
else holds.add(reason);
|
|
821
|
+
if (reason === "pointer") {
|
|
822
|
+
pointerScrolled = false;
|
|
823
|
+
// the user takes over mid auto-scroll: snapping back on at once, so
|
|
824
|
+
// their own scroll lands on a snap the native way
|
|
825
|
+
if (autoScrolling) {
|
|
826
|
+
cancelAnimationFrame(autoFrame);
|
|
827
|
+
autoFrame = 0;
|
|
828
|
+
autoScrolling = false;
|
|
829
|
+
setGliding(false);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
reconcile();
|
|
833
|
+
};
|
|
834
|
+
const release = (reason: "pointer" | "focus" | "hover") => {
|
|
835
|
+
if (holds.delete(reason)) reconcile();
|
|
836
|
+
};
|
|
837
|
+
|
|
838
|
+
// the user taking over ends a scripted scroll short of its target; its
|
|
839
|
+
// scrollend must then count, so the pending target goes
|
|
840
|
+
const keyboardOff = viewport.closest('[data-carousel-keyboard="false"]') !== null;
|
|
841
|
+
const onUserInput = (event: Event) => {
|
|
842
|
+
// the kit steps on arrow keys itself (carousel.ts), from the pending target
|
|
843
|
+
if (event instanceof KeyboardEvent && event.key.startsWith("Arrow") && !keyboardOff) return;
|
|
844
|
+
if (event instanceof MouseEvent && event.button !== 0) return;
|
|
845
|
+
holdFor("pointer");
|
|
846
|
+
pending = null;
|
|
847
|
+
// catching the track mid-coast stops it where it is
|
|
848
|
+
if (stopCoast()) settle();
|
|
849
|
+
};
|
|
850
|
+
for (const type of ["pointerdown", "wheel", "touchstart", "keydown"]) {
|
|
851
|
+
viewport.addEventListener(type, onUserInput, { passive: true, signal });
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
if (auto) {
|
|
855
|
+
// a tap (no scroll) ends the hold at once; a scroll ends it on settle.
|
|
856
|
+
// pointercancel means the browser took the touch for a pan: wait for that
|
|
857
|
+
viewport.addEventListener(
|
|
858
|
+
"pointerup",
|
|
859
|
+
() => {
|
|
860
|
+
if (!pointerScrolled) release("pointer");
|
|
861
|
+
},
|
|
862
|
+
{ signal },
|
|
863
|
+
);
|
|
864
|
+
viewport.addEventListener(
|
|
865
|
+
"focusin",
|
|
866
|
+
(event) => {
|
|
867
|
+
if (event.target !== viewport) holdFor("focus");
|
|
868
|
+
},
|
|
869
|
+
{ signal },
|
|
870
|
+
);
|
|
871
|
+
viewport.addEventListener(
|
|
872
|
+
"focusout",
|
|
873
|
+
(event) => {
|
|
874
|
+
if (!(event.relatedTarget instanceof Node && viewport.contains(event.relatedTarget))) {
|
|
875
|
+
release("focus");
|
|
876
|
+
}
|
|
877
|
+
},
|
|
878
|
+
{ signal },
|
|
879
|
+
);
|
|
880
|
+
if (auto.stopOnMouseEnter) {
|
|
881
|
+
root.addEventListener("mouseenter", () => holdFor("hover"), { signal });
|
|
882
|
+
root.addEventListener("mouseleave", () => release("hover"), { signal });
|
|
883
|
+
}
|
|
884
|
+
document.addEventListener("visibilitychange", () => reconcile(), { signal });
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// --- Mouse drag ---
|
|
888
|
+
|
|
889
|
+
let dragFrom = 0;
|
|
890
|
+
let dragSnap = 0;
|
|
891
|
+
|
|
892
|
+
// No page-wide drag flag: trackDrag captures the pointer on the viewport, so
|
|
893
|
+
// its own `dragging` cursor holds wherever the pointer goes. Flagging :root
|
|
894
|
+
// would restyle every element on the page at each drag start and end.
|
|
895
|
+
const setDragging = (on: boolean) => {
|
|
896
|
+
dragging = on;
|
|
897
|
+
setCarouselState(viewport, "dragging", on);
|
|
898
|
+
};
|
|
899
|
+
|
|
900
|
+
/** The drag-free coast's frame, 0 when none is running. */
|
|
901
|
+
let coastFrame = 0;
|
|
902
|
+
const stopCoast = (): boolean => {
|
|
903
|
+
if (!coastFrame) return false;
|
|
904
|
+
cancelAnimationFrame(coastFrame);
|
|
905
|
+
coastFrame = 0;
|
|
906
|
+
return true;
|
|
907
|
+
};
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* Drag-free release: the track keeps the pointer's speed and decays
|
|
911
|
+
* exponentially over the projected distance (x = target − d·e^(−kt), with
|
|
912
|
+
* k = v/d so the first frame moves at the release speed). The browser's
|
|
913
|
+
* smooth scroll would start from rest instead, a visible hitch. An end cuts
|
|
914
|
+
* the distance short, which raises k: the track brakes into the end.
|
|
915
|
+
*/
|
|
916
|
+
const coast = (velocity: number) => {
|
|
917
|
+
const from = getPos();
|
|
918
|
+
const target = clampPos(from - projectRelease(velocity));
|
|
919
|
+
const distance = target - from;
|
|
920
|
+
if (reducedMotion.matches || Math.abs(distance) < 1) {
|
|
921
|
+
settle();
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
const rate = Math.min(MAX_COAST_RATE, Math.abs(velocity) / Math.abs(distance));
|
|
925
|
+
const start = performance.now();
|
|
926
|
+
const frame = (now: number) => {
|
|
927
|
+
const left = distance * Math.exp(-rate * Math.max(0, now - start));
|
|
928
|
+
if (Math.abs(left) < 0.5) {
|
|
929
|
+
coastFrame = 0;
|
|
930
|
+
writePos(target);
|
|
931
|
+
settle();
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
writePos(target - left);
|
|
935
|
+
coastFrame = requestAnimationFrame(frame);
|
|
936
|
+
};
|
|
937
|
+
coastFrame = requestAnimationFrame(frame);
|
|
938
|
+
};
|
|
939
|
+
|
|
940
|
+
const endDrag = (velocity: number) => {
|
|
941
|
+
setDragging(false);
|
|
942
|
+
// The rubber band's translate shrinks the scrollable width while it
|
|
943
|
+
// springs back, so a release past the end rests short of it: once the
|
|
944
|
+
// spring is done, finish the last few px.
|
|
945
|
+
if (container.style.translate && getPos() >= maxScroll() - 1) {
|
|
946
|
+
container.addEventListener(
|
|
947
|
+
"transitionend",
|
|
948
|
+
() => {
|
|
949
|
+
if (!dragging && !coastFrame && pending == null) jump(maxScroll());
|
|
950
|
+
},
|
|
951
|
+
{ once: true, signal },
|
|
952
|
+
);
|
|
953
|
+
}
|
|
954
|
+
container.style.translate = "";
|
|
955
|
+
const projected = getPos() - projectRelease(velocity);
|
|
956
|
+
if (options.dragFree) {
|
|
957
|
+
coast(velocity);
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
// snapping stays off ("gliding") until the scroll ends on the snap,
|
|
961
|
+
// or re-enabling it mid-scroll would re-snap from where the glide is
|
|
962
|
+
scrollToSnap(releaseTarget(snaps(), dragSnap, projected, velocity, options.skipSnaps));
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
if (options.draggable) {
|
|
966
|
+
trackDrag(viewport, {
|
|
967
|
+
axis: vertical ? "y" : "x",
|
|
968
|
+
signal,
|
|
969
|
+
canStart: ({ pointerType }) => pointerType === "mouse" && maxScroll() > 0,
|
|
970
|
+
onStart: () => {
|
|
971
|
+
pending = null;
|
|
972
|
+
stopCoast();
|
|
973
|
+
dragFrom = getPos();
|
|
974
|
+
dragSnap = nearestSnap(snaps(), dragFrom);
|
|
975
|
+
setGliding(true);
|
|
976
|
+
setDragging(true);
|
|
977
|
+
},
|
|
978
|
+
onMove: ({ offset }) => {
|
|
979
|
+
const wanted = dragFrom - logical(offset);
|
|
980
|
+
const clamped = clampPos(wanted);
|
|
981
|
+
jump(clamped);
|
|
982
|
+
// logical overshoot: positive pushes the content away from the start edge
|
|
983
|
+
const overshoot = rubberBand(clamped - wanted, clientSize() / 4);
|
|
984
|
+
container.style.translate = !overshoot
|
|
985
|
+
? ""
|
|
986
|
+
: vertical
|
|
987
|
+
? `0 ${overshoot}px`
|
|
988
|
+
: `${overshoot * sign}px 0`;
|
|
989
|
+
},
|
|
990
|
+
onEnd: ({ velocity }) => endDrag(logical(velocity)),
|
|
991
|
+
onCancel: () => endDrag(0),
|
|
992
|
+
});
|
|
993
|
+
// a dragged image or link would start a native drag-and-drop instead
|
|
994
|
+
viewport.addEventListener("dragstart", (event) => event.preventDefault(), { signal });
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
// --- Observers ---
|
|
998
|
+
|
|
999
|
+
const inViewObserver = new IntersectionObserver(
|
|
1000
|
+
(entries) => {
|
|
1001
|
+
inView = new Set(inView);
|
|
1002
|
+
for (const entry of entries) {
|
|
1003
|
+
const index = slides.indexOf(entry.target as HTMLElement);
|
|
1004
|
+
if (entry.isIntersecting) inView.add(index);
|
|
1005
|
+
else inView.delete(index);
|
|
1006
|
+
setCarouselState(entry.target, "in-view", entry.isIntersecting);
|
|
1007
|
+
}
|
|
1008
|
+
syncInert();
|
|
1009
|
+
},
|
|
1010
|
+
// 1px in on the scroll axis: a neighbour that only touches the viewport's
|
|
1011
|
+
// edge counts as intersecting otherwise (edge-adjacent boxes do)
|
|
1012
|
+
{ root: viewport, rootMargin: vertical ? "-1px 0px" : "0px -1px" },
|
|
1013
|
+
);
|
|
1014
|
+
slides.forEach((slide) => inViewObserver.observe(slide));
|
|
1015
|
+
|
|
1016
|
+
// autoplay and auto-scroll pause while the carousel is off screen
|
|
1017
|
+
const screenObserver = auto
|
|
1018
|
+
? new IntersectionObserver(([entry]) => {
|
|
1019
|
+
onScreen = entry?.isIntersecting ?? true;
|
|
1020
|
+
reconcile();
|
|
1021
|
+
})
|
|
1022
|
+
: null;
|
|
1023
|
+
screenObserver?.observe(root);
|
|
1024
|
+
|
|
1025
|
+
// Fires once on observe too; only a real change of snap emits a select.
|
|
1026
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
1027
|
+
invalidate();
|
|
1028
|
+
buildDots();
|
|
1029
|
+
if (pending == null && !dragging && !autoScrolling) select(nearestSnap(snaps(), getPos()));
|
|
1030
|
+
// rebuilt dots and regrouped snaps need the current state redrawn
|
|
1031
|
+
render(selected);
|
|
1032
|
+
reconcile();
|
|
1033
|
+
});
|
|
1034
|
+
resizeObserver.observe(viewport);
|
|
1035
|
+
slides.forEach((slide) => resizeObserver.observe(slide));
|
|
1036
|
+
|
|
1037
|
+
// --- Controls ---
|
|
1038
|
+
|
|
1039
|
+
const api: CarouselApi = {
|
|
1040
|
+
goTo(index, instant) {
|
|
1041
|
+
scrollToSnap(options.loop ? snapOfSlide(index) : index, instant, options.loop ? index : null);
|
|
1042
|
+
},
|
|
1043
|
+
goToNext: () => step(1),
|
|
1044
|
+
goToPrev: () => step(-1),
|
|
1045
|
+
selectedSnap: () => publicIndex(Math.max(0, selected)),
|
|
1046
|
+
snapList: () => snaps().map((snap) => snap.pos),
|
|
1047
|
+
revealSlide(index, instant) {
|
|
1048
|
+
const slide = slides[index];
|
|
1049
|
+
if (!slide) return;
|
|
1050
|
+
const at = getPos();
|
|
1051
|
+
const start = startOf(slide.getBoundingClientRect(), viewport.getBoundingClientRect()) + at;
|
|
1052
|
+
const end = start + sizeOf(slide.getBoundingClientRect());
|
|
1053
|
+
const target = clampPos(
|
|
1054
|
+
start < at ? start : end > at + clientSize() ? end - clientSize() : at,
|
|
1055
|
+
);
|
|
1056
|
+
if (Math.abs(target - at) < 1) return;
|
|
1057
|
+
if (instant) jump(target);
|
|
1058
|
+
else scrollToPos(target, behavior());
|
|
1059
|
+
},
|
|
1060
|
+
play() {
|
|
1061
|
+
wanted = true;
|
|
1062
|
+
reconcile();
|
|
1063
|
+
},
|
|
1064
|
+
stop() {
|
|
1065
|
+
wanted = false;
|
|
1066
|
+
reconcile();
|
|
1067
|
+
},
|
|
1068
|
+
isPlaying: () => running,
|
|
1069
|
+
interact() {
|
|
1070
|
+
if (!auto || !wanted) return;
|
|
1071
|
+
if (auto.stopOnInteraction) {
|
|
1072
|
+
wanted = false;
|
|
1073
|
+
reconcile();
|
|
1074
|
+
} else reconcile(true);
|
|
1075
|
+
},
|
|
1076
|
+
vertical,
|
|
1077
|
+
rtl,
|
|
1078
|
+
};
|
|
1079
|
+
|
|
1080
|
+
if (controls) {
|
|
1081
|
+
for (const [slot, direction] of [
|
|
1082
|
+
["prev", -1],
|
|
1083
|
+
["next", 1],
|
|
1084
|
+
] as const) {
|
|
1085
|
+
root.querySelector(`[data-carousel-slot~="${slot}"]`)?.addEventListener(
|
|
1086
|
+
"click",
|
|
1087
|
+
() => {
|
|
1088
|
+
api.interact();
|
|
1089
|
+
step(direction);
|
|
1090
|
+
},
|
|
1091
|
+
{ signal },
|
|
1092
|
+
);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
// --- Start ---
|
|
1097
|
+
|
|
1098
|
+
setCarouselState(viewport, "free", options.dragFree);
|
|
1099
|
+
buildDots();
|
|
1100
|
+
// nothing has painted yet, so the start rotation needs no lock
|
|
1101
|
+
if (options.loop) rotate(options.startSnap % slides.length, false);
|
|
1102
|
+
const start = options.loop ? snapOfSlide(options.startSnap) : options.startSnap;
|
|
1103
|
+
jump(snaps()[start]?.pos ?? 0);
|
|
1104
|
+
select(nearestSnap(snaps(), getPos()));
|
|
1105
|
+
syncInert();
|
|
1106
|
+
if (auto) {
|
|
1107
|
+
// continuous motion never starts on its own for reduced-motion users
|
|
1108
|
+
wanted = auto.playOnInit && !(auto.mode === "auto-scroll" && reducedMotion.matches);
|
|
1109
|
+
reconcile();
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
signal.addEventListener(
|
|
1113
|
+
"abort",
|
|
1114
|
+
() => {
|
|
1115
|
+
cancelAnimationFrame(frame);
|
|
1116
|
+
cancelAnimationFrame(coastFrame);
|
|
1117
|
+
clearTimeout(autoTimer);
|
|
1118
|
+
cancelAnimationFrame(autoFrame);
|
|
1119
|
+
inViewObserver.disconnect();
|
|
1120
|
+
screenObserver?.disconnect();
|
|
1121
|
+
resizeObserver.disconnect();
|
|
1122
|
+
if (dragging) setDragging(false);
|
|
1123
|
+
for (const token of ["gliding", "settling", "free"]) {
|
|
1124
|
+
setCarouselState(viewport, token, false);
|
|
1125
|
+
}
|
|
1126
|
+
setCarouselState(root, "playing", false);
|
|
1127
|
+
container.style.translate = "";
|
|
1128
|
+
for (const slide of slides) {
|
|
1129
|
+
slide.style.order = "";
|
|
1130
|
+
slide.inert = false;
|
|
1131
|
+
setCarouselState(slide, "in-view", false);
|
|
1132
|
+
setCarouselState(slide, "snapped", false);
|
|
1133
|
+
}
|
|
1134
|
+
// put the template dot back so a re-insert can build from it again
|
|
1135
|
+
if (templateDot) dotsNode?.replaceChildren(templateDot);
|
|
1136
|
+
delete root._carousel;
|
|
1137
|
+
},
|
|
1138
|
+
{ once: true },
|
|
1139
|
+
);
|
|
1140
|
+
|
|
1141
|
+
root._carousel = api;
|
|
1142
|
+
return api;
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
// --- Thumbs ---
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* @description Runs a thumb strip on its own engine (options from
|
|
1149
|
+
* `data-carousel-thumbs-*` on the thumbs slot; drag-free by default) and links
|
|
1150
|
+
* it to the main carousel: a thumb click steps the main carousel there, and
|
|
1151
|
+
* each main selection marks its thumb (`active` token and `aria-current`) and
|
|
1152
|
+
* scrolls the strip just enough to show it.
|
|
1153
|
+
*
|
|
1154
|
+
* @param main - The main carousel's API.
|
|
1155
|
+
* @param root - The main carousel root (its `zazz:carousel-select` drives the strip).
|
|
1156
|
+
* @param thumbsNode - The thumbs slot.
|
|
1157
|
+
* @param signal - Aborting it tears the strip down.
|
|
1158
|
+
* @returns The strip's API, or null when it has no viewport or container.
|
|
1159
|
+
*/
|
|
1160
|
+
function linkThumbs(
|
|
1161
|
+
main: CarouselApi,
|
|
1162
|
+
root: Element,
|
|
1163
|
+
thumbsNode: Element,
|
|
1164
|
+
signal: AbortSignal,
|
|
1165
|
+
): CarouselApi | null {
|
|
1166
|
+
const viewport = thumbsNode.querySelector<HTMLElement>('[data-carousel-slot~="viewport"]');
|
|
1167
|
+
if (!viewport) return null;
|
|
1168
|
+
const strip = createCarousel(thumbsNode, viewport, signal, {
|
|
1169
|
+
prefix: "data-carousel-thumbs-",
|
|
1170
|
+
defaults: { dragFree: true },
|
|
1171
|
+
controls: false,
|
|
1172
|
+
});
|
|
1173
|
+
if (!strip) return null;
|
|
1174
|
+
const thumbs = [
|
|
1175
|
+
...viewport.querySelectorAll<HTMLElement>(
|
|
1176
|
+
'[data-carousel-slot~="container"] > [data-carousel-slot~="slide"]',
|
|
1177
|
+
),
|
|
1178
|
+
];
|
|
1179
|
+
thumbs.forEach((thumb, index) =>
|
|
1180
|
+
thumb.addEventListener(
|
|
1181
|
+
"click",
|
|
1182
|
+
() => {
|
|
1183
|
+
main.interact();
|
|
1184
|
+
main.goTo(index);
|
|
1185
|
+
},
|
|
1186
|
+
{ signal },
|
|
1187
|
+
),
|
|
1188
|
+
);
|
|
1189
|
+
const mark = (index: number, instant?: boolean) => {
|
|
1190
|
+
thumbs.forEach((thumb, i) => {
|
|
1191
|
+
setCarouselState(thumb, "active", i === index);
|
|
1192
|
+
if (i === index) thumb.setAttribute("aria-current", "true");
|
|
1193
|
+
else thumb.removeAttribute("aria-current");
|
|
1194
|
+
});
|
|
1195
|
+
strip.revealSlide(index, instant);
|
|
1196
|
+
};
|
|
1197
|
+
root.addEventListener(
|
|
1198
|
+
"zazz:carousel-select",
|
|
1199
|
+
(event) => mark((event as CustomEvent<{ index: number }>).detail.index),
|
|
1200
|
+
{ signal },
|
|
1201
|
+
);
|
|
1202
|
+
mark(main.selectedSnap(), true);
|
|
1203
|
+
signal.addEventListener(
|
|
1204
|
+
"abort",
|
|
1205
|
+
() => {
|
|
1206
|
+
for (const thumb of thumbs) {
|
|
1207
|
+
setCarouselState(thumb, "active", false);
|
|
1208
|
+
thumb.removeAttribute("aria-current");
|
|
1209
|
+
}
|
|
1210
|
+
},
|
|
1211
|
+
{ once: true },
|
|
1212
|
+
);
|
|
1213
|
+
return strip;
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
export {
|
|
1217
|
+
createCarousel,
|
|
1218
|
+
linkThumbs,
|
|
1219
|
+
loopLead,
|
|
1220
|
+
loopShift,
|
|
1221
|
+
loopOrders,
|
|
1222
|
+
projectRelease,
|
|
1223
|
+
readAutoOptions,
|
|
1224
|
+
releaseTarget,
|
|
1225
|
+
setCarouselState,
|
|
1226
|
+
};
|
|
1227
|
+
export type { CarouselApi };
|