@brandonsoccer22/gsap-editorial-carousel 0.1.3 → 0.1.4
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/README.md +6 -1
- package/dist/index.cjs +426 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +426 -55
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/styles.css +3 -2
package/dist/index.js
CHANGED
|
@@ -55,6 +55,11 @@ function setSlidesState(slides, activeIndex, activeClass) {
|
|
|
55
55
|
slides.forEach((slide, index) => {
|
|
56
56
|
const isActive = index === activeIndex;
|
|
57
57
|
slide.setAttribute("aria-hidden", isActive ? "false" : "true");
|
|
58
|
+
if (isActive) {
|
|
59
|
+
slide.removeAttribute("inert");
|
|
60
|
+
} else {
|
|
61
|
+
slide.setAttribute("inert", "");
|
|
62
|
+
}
|
|
58
63
|
toggleClass(slide, activeClass, isActive);
|
|
59
64
|
});
|
|
60
65
|
}
|
|
@@ -139,6 +144,7 @@ function ensureDefaultAnimationsRegistered() {
|
|
|
139
144
|
},
|
|
140
145
|
opts.at
|
|
141
146
|
);
|
|
147
|
+
tl.set(el, { autoAlpha: 0 }, ">");
|
|
142
148
|
};
|
|
143
149
|
const fadeUp = ({ el, gsap: gsap3, opts, tl }) => {
|
|
144
150
|
tl.fromTo(
|
|
@@ -166,6 +172,35 @@ function ensureDefaultAnimationsRegistered() {
|
|
|
166
172
|
},
|
|
167
173
|
opts.at
|
|
168
174
|
);
|
|
175
|
+
tl.set(el, { autoAlpha: 0 }, ">");
|
|
176
|
+
};
|
|
177
|
+
const fadeDown = ({ el, gsap: gsap3, opts, tl }) => {
|
|
178
|
+
tl.fromTo(
|
|
179
|
+
el,
|
|
180
|
+
{ autoAlpha: 0, y: -24 },
|
|
181
|
+
{
|
|
182
|
+
autoAlpha: 1,
|
|
183
|
+
y: 0,
|
|
184
|
+
duration: opts.dur,
|
|
185
|
+
delay: opts.delay,
|
|
186
|
+
ease: opts.ease
|
|
187
|
+
},
|
|
188
|
+
opts.at
|
|
189
|
+
);
|
|
190
|
+
};
|
|
191
|
+
fadeDown.reverse = ({ el, gsap: gsap3, opts, tl }) => {
|
|
192
|
+
tl.to(
|
|
193
|
+
el,
|
|
194
|
+
{
|
|
195
|
+
autoAlpha: 0,
|
|
196
|
+
y: 12,
|
|
197
|
+
duration: opts.dur,
|
|
198
|
+
delay: opts.delay,
|
|
199
|
+
ease: opts.ease
|
|
200
|
+
},
|
|
201
|
+
opts.at
|
|
202
|
+
);
|
|
203
|
+
tl.set(el, { autoAlpha: 0 }, ">");
|
|
169
204
|
};
|
|
170
205
|
const slideIn = ({ el, gsap: gsap3, opts, tl }) => {
|
|
171
206
|
tl.fromTo(
|
|
@@ -193,16 +228,303 @@ function ensureDefaultAnimationsRegistered() {
|
|
|
193
228
|
},
|
|
194
229
|
opts.at
|
|
195
230
|
);
|
|
231
|
+
tl.set(el, { autoAlpha: 0 }, ">");
|
|
232
|
+
};
|
|
233
|
+
const fadeOut = ({ el, gsap: gsap3, opts, tl }) => {
|
|
234
|
+
tl.to(
|
|
235
|
+
el,
|
|
236
|
+
{
|
|
237
|
+
autoAlpha: 0,
|
|
238
|
+
duration: opts.dur,
|
|
239
|
+
delay: opts.delay,
|
|
240
|
+
ease: opts.ease
|
|
241
|
+
},
|
|
242
|
+
opts.at
|
|
243
|
+
);
|
|
244
|
+
tl.set(el, { autoAlpha: 0 }, ">");
|
|
245
|
+
};
|
|
246
|
+
fadeOut.reverse = ({ el, gsap: gsap3, opts, tl }) => {
|
|
247
|
+
tl.to(
|
|
248
|
+
el,
|
|
249
|
+
{
|
|
250
|
+
autoAlpha: 1,
|
|
251
|
+
duration: opts.dur,
|
|
252
|
+
delay: opts.delay,
|
|
253
|
+
ease: opts.ease
|
|
254
|
+
},
|
|
255
|
+
opts.at
|
|
256
|
+
);
|
|
257
|
+
};
|
|
258
|
+
const slideOut = ({ el, gsap: gsap3, opts, tl }) => {
|
|
259
|
+
tl.to(
|
|
260
|
+
el,
|
|
261
|
+
{
|
|
262
|
+
autoAlpha: 0,
|
|
263
|
+
x: opts.direction * -24,
|
|
264
|
+
duration: opts.dur,
|
|
265
|
+
delay: opts.delay,
|
|
266
|
+
ease: opts.ease
|
|
267
|
+
},
|
|
268
|
+
opts.at
|
|
269
|
+
);
|
|
270
|
+
tl.set(el, { autoAlpha: 0 }, ">");
|
|
271
|
+
};
|
|
272
|
+
slideOut.reverse = ({ el, gsap: gsap3, opts, tl }) => {
|
|
273
|
+
tl.to(
|
|
274
|
+
el,
|
|
275
|
+
{
|
|
276
|
+
autoAlpha: 1,
|
|
277
|
+
x: 0,
|
|
278
|
+
duration: opts.dur,
|
|
279
|
+
delay: opts.delay,
|
|
280
|
+
ease: opts.ease
|
|
281
|
+
},
|
|
282
|
+
opts.at
|
|
283
|
+
);
|
|
196
284
|
};
|
|
197
285
|
registerAnimations({
|
|
198
286
|
"fade-in": fadeIn,
|
|
287
|
+
"fade-down": fadeDown,
|
|
288
|
+
"fade-down-in": fadeDownIn,
|
|
289
|
+
"fade-down-out": fadeDownOut,
|
|
290
|
+
"fade-out": fadeOut,
|
|
199
291
|
"fade-up": fadeUp,
|
|
200
|
-
"
|
|
292
|
+
"fade-up-in": fadeUpIn,
|
|
293
|
+
"fade-up-out": fadeUpOut,
|
|
294
|
+
"fade-start-in": fadeStartIn,
|
|
295
|
+
"fade-start-out": fadeStartOut,
|
|
296
|
+
"fade-end-in": fadeEndIn,
|
|
297
|
+
"fade-end-out": fadeEndOut,
|
|
298
|
+
"slide-in": slideIn,
|
|
299
|
+
"slide-out": slideOut
|
|
201
300
|
});
|
|
202
301
|
}
|
|
302
|
+
var fadeUpIn = ({ el, gsap: gsap3, opts, tl }) => {
|
|
303
|
+
tl.fromTo(
|
|
304
|
+
el,
|
|
305
|
+
{ autoAlpha: 0, y: 24 },
|
|
306
|
+
{
|
|
307
|
+
autoAlpha: 1,
|
|
308
|
+
y: 0,
|
|
309
|
+
duration: opts.dur,
|
|
310
|
+
delay: opts.delay,
|
|
311
|
+
ease: opts.ease
|
|
312
|
+
},
|
|
313
|
+
opts.at
|
|
314
|
+
);
|
|
315
|
+
};
|
|
316
|
+
fadeUpIn.reverse = ({ el, gsap: gsap3, opts, tl }) => {
|
|
317
|
+
tl.to(
|
|
318
|
+
el,
|
|
319
|
+
{
|
|
320
|
+
autoAlpha: 0,
|
|
321
|
+
y: -12,
|
|
322
|
+
duration: opts.dur,
|
|
323
|
+
delay: opts.delay,
|
|
324
|
+
ease: opts.ease
|
|
325
|
+
},
|
|
326
|
+
opts.at
|
|
327
|
+
);
|
|
328
|
+
tl.set(el, { autoAlpha: 0 }, ">");
|
|
329
|
+
};
|
|
330
|
+
var fadeUpOut = ({ el, gsap: gsap3, opts, tl }) => {
|
|
331
|
+
tl.to(
|
|
332
|
+
el,
|
|
333
|
+
{
|
|
334
|
+
autoAlpha: 0,
|
|
335
|
+
y: -12,
|
|
336
|
+
duration: opts.dur,
|
|
337
|
+
delay: opts.delay,
|
|
338
|
+
ease: opts.ease
|
|
339
|
+
},
|
|
340
|
+
opts.at
|
|
341
|
+
);
|
|
342
|
+
tl.set(el, { autoAlpha: 0 }, ">");
|
|
343
|
+
};
|
|
344
|
+
fadeUpOut.reverse = ({ el, gsap: gsap3, opts, tl }) => {
|
|
345
|
+
tl.fromTo(
|
|
346
|
+
el,
|
|
347
|
+
{ autoAlpha: 0, y: 24 },
|
|
348
|
+
{
|
|
349
|
+
autoAlpha: 1,
|
|
350
|
+
y: 0,
|
|
351
|
+
duration: opts.dur,
|
|
352
|
+
delay: opts.delay,
|
|
353
|
+
ease: opts.ease
|
|
354
|
+
},
|
|
355
|
+
opts.at
|
|
356
|
+
);
|
|
357
|
+
};
|
|
358
|
+
var fadeDownIn = ({ el, gsap: gsap3, opts, tl }) => {
|
|
359
|
+
tl.fromTo(
|
|
360
|
+
el,
|
|
361
|
+
{ autoAlpha: 0, y: -24 },
|
|
362
|
+
{
|
|
363
|
+
autoAlpha: 1,
|
|
364
|
+
y: 0,
|
|
365
|
+
duration: opts.dur,
|
|
366
|
+
delay: opts.delay,
|
|
367
|
+
ease: opts.ease
|
|
368
|
+
},
|
|
369
|
+
opts.at
|
|
370
|
+
);
|
|
371
|
+
};
|
|
372
|
+
fadeDownIn.reverse = ({ el, gsap: gsap3, opts, tl }) => {
|
|
373
|
+
tl.to(
|
|
374
|
+
el,
|
|
375
|
+
{
|
|
376
|
+
autoAlpha: 0,
|
|
377
|
+
y: 12,
|
|
378
|
+
duration: opts.dur,
|
|
379
|
+
delay: opts.delay,
|
|
380
|
+
ease: opts.ease
|
|
381
|
+
},
|
|
382
|
+
opts.at
|
|
383
|
+
);
|
|
384
|
+
tl.set(el, { autoAlpha: 0 }, ">");
|
|
385
|
+
};
|
|
386
|
+
var fadeDownOut = ({ el, gsap: gsap3, opts, tl }) => {
|
|
387
|
+
tl.to(
|
|
388
|
+
el,
|
|
389
|
+
{
|
|
390
|
+
autoAlpha: 0,
|
|
391
|
+
y: 12,
|
|
392
|
+
duration: opts.dur,
|
|
393
|
+
delay: opts.delay,
|
|
394
|
+
ease: opts.ease
|
|
395
|
+
},
|
|
396
|
+
opts.at
|
|
397
|
+
);
|
|
398
|
+
tl.set(el, { autoAlpha: 0 }, ">");
|
|
399
|
+
};
|
|
400
|
+
fadeDownOut.reverse = ({ el, gsap: gsap3, opts, tl }) => {
|
|
401
|
+
tl.fromTo(
|
|
402
|
+
el,
|
|
403
|
+
{ autoAlpha: 0, y: -24 },
|
|
404
|
+
{
|
|
405
|
+
autoAlpha: 1,
|
|
406
|
+
y: 0,
|
|
407
|
+
duration: opts.dur,
|
|
408
|
+
delay: opts.delay,
|
|
409
|
+
ease: opts.ease
|
|
410
|
+
},
|
|
411
|
+
opts.at
|
|
412
|
+
);
|
|
413
|
+
};
|
|
414
|
+
var fadeStartIn = ({ el, gsap: gsap3, opts, tl }) => {
|
|
415
|
+
tl.fromTo(
|
|
416
|
+
el,
|
|
417
|
+
{ autoAlpha: 0, x: -24 },
|
|
418
|
+
{
|
|
419
|
+
autoAlpha: 1,
|
|
420
|
+
x: 0,
|
|
421
|
+
duration: opts.dur,
|
|
422
|
+
delay: opts.delay,
|
|
423
|
+
ease: opts.ease
|
|
424
|
+
},
|
|
425
|
+
opts.at
|
|
426
|
+
);
|
|
427
|
+
};
|
|
428
|
+
fadeStartIn.reverse = ({ el, gsap: gsap3, opts, tl }) => {
|
|
429
|
+
tl.to(
|
|
430
|
+
el,
|
|
431
|
+
{
|
|
432
|
+
autoAlpha: 0,
|
|
433
|
+
x: -12,
|
|
434
|
+
duration: opts.dur,
|
|
435
|
+
delay: opts.delay,
|
|
436
|
+
ease: opts.ease
|
|
437
|
+
},
|
|
438
|
+
opts.at
|
|
439
|
+
);
|
|
440
|
+
tl.set(el, { autoAlpha: 0 }, ">");
|
|
441
|
+
};
|
|
442
|
+
var fadeStartOut = ({ el, gsap: gsap3, opts, tl }) => {
|
|
443
|
+
tl.to(
|
|
444
|
+
el,
|
|
445
|
+
{
|
|
446
|
+
autoAlpha: 0,
|
|
447
|
+
x: -12,
|
|
448
|
+
duration: opts.dur,
|
|
449
|
+
delay: opts.delay,
|
|
450
|
+
ease: opts.ease
|
|
451
|
+
},
|
|
452
|
+
opts.at
|
|
453
|
+
);
|
|
454
|
+
tl.set(el, { autoAlpha: 0 }, ">");
|
|
455
|
+
};
|
|
456
|
+
fadeStartOut.reverse = ({ el, gsap: gsap3, opts, tl }) => {
|
|
457
|
+
tl.fromTo(
|
|
458
|
+
el,
|
|
459
|
+
{ autoAlpha: 0, x: -24 },
|
|
460
|
+
{
|
|
461
|
+
autoAlpha: 1,
|
|
462
|
+
x: 0,
|
|
463
|
+
duration: opts.dur,
|
|
464
|
+
delay: opts.delay,
|
|
465
|
+
ease: opts.ease
|
|
466
|
+
},
|
|
467
|
+
opts.at
|
|
468
|
+
);
|
|
469
|
+
};
|
|
470
|
+
var fadeEndIn = ({ el, gsap: gsap3, opts, tl }) => {
|
|
471
|
+
tl.fromTo(
|
|
472
|
+
el,
|
|
473
|
+
{ autoAlpha: 0, x: 24 },
|
|
474
|
+
{
|
|
475
|
+
autoAlpha: 1,
|
|
476
|
+
x: 0,
|
|
477
|
+
duration: opts.dur,
|
|
478
|
+
delay: opts.delay,
|
|
479
|
+
ease: opts.ease
|
|
480
|
+
},
|
|
481
|
+
opts.at
|
|
482
|
+
);
|
|
483
|
+
};
|
|
484
|
+
fadeEndIn.reverse = ({ el, gsap: gsap3, opts, tl }) => {
|
|
485
|
+
tl.to(
|
|
486
|
+
el,
|
|
487
|
+
{
|
|
488
|
+
autoAlpha: 0,
|
|
489
|
+
x: 12,
|
|
490
|
+
duration: opts.dur,
|
|
491
|
+
delay: opts.delay,
|
|
492
|
+
ease: opts.ease
|
|
493
|
+
},
|
|
494
|
+
opts.at
|
|
495
|
+
);
|
|
496
|
+
tl.set(el, { autoAlpha: 0 }, ">");
|
|
497
|
+
};
|
|
498
|
+
var fadeEndOut = ({ el, gsap: gsap3, opts, tl }) => {
|
|
499
|
+
tl.to(
|
|
500
|
+
el,
|
|
501
|
+
{
|
|
502
|
+
autoAlpha: 0,
|
|
503
|
+
x: 12,
|
|
504
|
+
duration: opts.dur,
|
|
505
|
+
delay: opts.delay,
|
|
506
|
+
ease: opts.ease
|
|
507
|
+
},
|
|
508
|
+
opts.at
|
|
509
|
+
);
|
|
510
|
+
tl.set(el, { autoAlpha: 0 }, ">");
|
|
511
|
+
};
|
|
512
|
+
fadeEndOut.reverse = ({ el, gsap: gsap3, opts, tl }) => {
|
|
513
|
+
tl.fromTo(
|
|
514
|
+
el,
|
|
515
|
+
{ autoAlpha: 0, x: 24 },
|
|
516
|
+
{
|
|
517
|
+
autoAlpha: 1,
|
|
518
|
+
x: 0,
|
|
519
|
+
duration: opts.dur,
|
|
520
|
+
delay: opts.delay,
|
|
521
|
+
ease: opts.ease
|
|
522
|
+
},
|
|
523
|
+
opts.at
|
|
524
|
+
);
|
|
525
|
+
};
|
|
203
526
|
|
|
204
527
|
// src/timeline.ts
|
|
205
|
-
var defaultExitDuration = 0.25;
|
|
206
528
|
function getDataNumber(el, name, fallback) {
|
|
207
529
|
const value = el.getAttribute(name);
|
|
208
530
|
if (!value) return fallback;
|
|
@@ -236,11 +558,29 @@ function findAnimationName(el) {
|
|
|
236
558
|
}
|
|
237
559
|
return null;
|
|
238
560
|
}
|
|
561
|
+
function collectExternalControls(slide, options) {
|
|
562
|
+
const root = slide.closest(options.selectors.root);
|
|
563
|
+
if (!root) return [];
|
|
564
|
+
const rootId = root.getAttribute("id");
|
|
565
|
+
const selector = `${options.selectors.prev}, ${options.selectors.next}`;
|
|
566
|
+
let candidates = [];
|
|
567
|
+
if (rootId) {
|
|
568
|
+
const scopedSelector = `${selector}[data-for="${rootId}"]`;
|
|
569
|
+
candidates = Array.from(document.querySelectorAll(scopedSelector));
|
|
570
|
+
if (!candidates.length) {
|
|
571
|
+
candidates = Array.from(root.querySelectorAll(selector));
|
|
572
|
+
}
|
|
573
|
+
} else {
|
|
574
|
+
candidates = Array.from(root.querySelectorAll(selector));
|
|
575
|
+
}
|
|
576
|
+
return candidates.filter((el) => !el.closest(options.selectors.slide));
|
|
577
|
+
}
|
|
239
578
|
function collectAnimItems(slide, options) {
|
|
240
579
|
const elements = Array.from(slide.querySelectorAll("[class]"));
|
|
580
|
+
const externalControls = collectExternalControls(slide, options);
|
|
241
581
|
const items = [];
|
|
242
|
-
elements.forEach((el) => {
|
|
243
|
-
var _a;
|
|
582
|
+
elements.concat(externalControls).forEach((el) => {
|
|
583
|
+
var _a, _b;
|
|
244
584
|
const animName = findAnimationName(el);
|
|
245
585
|
if (!animName) return;
|
|
246
586
|
const seq = Math.max(1, Math.floor(getDataNumber(el, "data-seq", 1)));
|
|
@@ -248,8 +588,11 @@ function collectAnimItems(slide, options) {
|
|
|
248
588
|
const dur = getDataNumber(el, "data-dur", options.defaults.dur);
|
|
249
589
|
const delay = getDataNumber(el, "data-delay", 0);
|
|
250
590
|
const ease = (_a = getDataString(el, "data-ease")) != null ? _a : options.defaults.ease;
|
|
591
|
+
const exitDur = getDataNumber(el, "data-exit-dur", dur);
|
|
592
|
+
const exitDelay = getDataNumber(el, "data-exit-delay", delay);
|
|
593
|
+
const exitEase = (_b = getDataString(el, "data-exit-ease")) != null ? _b : ease;
|
|
251
594
|
const at = getDataString(el, "data-at");
|
|
252
|
-
items.push({ el, animName, seq, exitSeq, dur, delay, ease, at });
|
|
595
|
+
items.push({ el, animName, seq, exitSeq, dur, delay, ease, exitDur, exitDelay, exitEase, at });
|
|
253
596
|
});
|
|
254
597
|
return items;
|
|
255
598
|
}
|
|
@@ -317,16 +660,16 @@ function buildSlideExitTimeline(slide, direction, options, gsapInstance) {
|
|
|
317
660
|
const reverseFactory = factory && "reverse" in factory ? factory.reverse : void 0;
|
|
318
661
|
const offset = (_a = parsePositionOffset(item.at)) != null ? _a : 0;
|
|
319
662
|
const position = cursor + offset;
|
|
320
|
-
let usedDuration = item.
|
|
663
|
+
let usedDuration = item.exitDur;
|
|
321
664
|
if (exitName && factory) {
|
|
322
665
|
factory({
|
|
323
666
|
el: item.el,
|
|
324
667
|
tl,
|
|
325
668
|
gsap: gsapInstance,
|
|
326
669
|
opts: {
|
|
327
|
-
dur: item.
|
|
328
|
-
delay: item.
|
|
329
|
-
ease: item.
|
|
670
|
+
dur: item.exitDur,
|
|
671
|
+
delay: item.exitDelay,
|
|
672
|
+
ease: item.exitEase,
|
|
330
673
|
direction,
|
|
331
674
|
at: position
|
|
332
675
|
}
|
|
@@ -337,27 +680,26 @@ function buildSlideExitTimeline(slide, direction, options, gsapInstance) {
|
|
|
337
680
|
tl,
|
|
338
681
|
gsap: gsapInstance,
|
|
339
682
|
opts: {
|
|
340
|
-
dur: item.
|
|
341
|
-
delay: item.
|
|
342
|
-
ease: item.
|
|
683
|
+
dur: item.exitDur,
|
|
684
|
+
delay: item.exitDelay,
|
|
685
|
+
ease: item.exitEase,
|
|
343
686
|
direction,
|
|
344
687
|
at: position
|
|
345
688
|
}
|
|
346
689
|
});
|
|
347
690
|
} else {
|
|
348
|
-
usedDuration = Math.min(item.dur, defaultExitDuration);
|
|
349
691
|
tl.to(
|
|
350
692
|
item.el,
|
|
351
693
|
{
|
|
352
694
|
autoAlpha: 0,
|
|
353
695
|
duration: usedDuration,
|
|
354
|
-
delay: item.
|
|
355
|
-
ease: item.
|
|
696
|
+
delay: item.exitDelay,
|
|
697
|
+
ease: item.exitEase
|
|
356
698
|
},
|
|
357
699
|
position
|
|
358
700
|
);
|
|
359
701
|
}
|
|
360
|
-
groupMax = Math.max(groupMax, offset + item.
|
|
702
|
+
groupMax = Math.max(groupMax, offset + item.exitDelay + usedDuration);
|
|
361
703
|
});
|
|
362
704
|
cursor += Math.max(groupMax, 0);
|
|
363
705
|
});
|
|
@@ -375,7 +717,7 @@ function prefersReducedMotion() {
|
|
|
375
717
|
// src/carousel.ts
|
|
376
718
|
var generatedDotSelector = '[data-carousel-dot="true"]';
|
|
377
719
|
function createCarousel(rootInput, options = {}) {
|
|
378
|
-
var _a, _b, _c, _d
|
|
720
|
+
var _a, _b, _c, _d;
|
|
379
721
|
ensureDefaultAnimationsRegistered();
|
|
380
722
|
const root = resolveRoot(rootInput);
|
|
381
723
|
const gsapInstance = (_a = options.gsap) != null ? _a : gsap;
|
|
@@ -403,7 +745,7 @@ function createCarousel(rootInput, options = {}) {
|
|
|
403
745
|
let currentIndex = normalizeIndex(resolved.initialIndex, slides.length, resolved.loop);
|
|
404
746
|
let animating = false;
|
|
405
747
|
setSlidesState(slides, currentIndex, resolved.classNames.activeSlide);
|
|
406
|
-
|
|
748
|
+
setAllDotsState(currentIndex);
|
|
407
749
|
const onPrevClick = (event) => {
|
|
408
750
|
event.preventDefault();
|
|
409
751
|
prev();
|
|
@@ -421,11 +763,15 @@ function createCarousel(rootInput, options = {}) {
|
|
|
421
763
|
if (!indexAttr) return;
|
|
422
764
|
const index = Number.parseInt(indexAttr, 10);
|
|
423
765
|
if (!Number.isFinite(index)) return;
|
|
424
|
-
|
|
766
|
+
if (animating) return;
|
|
767
|
+
const nextIndex = normalizeIndex(index, slides.length, resolved.loop);
|
|
768
|
+
if (nextIndex === currentIndex) return;
|
|
769
|
+
setAllDotsState(nextIndex);
|
|
770
|
+
goTo(nextIndex);
|
|
425
771
|
};
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
772
|
+
controls.prev.forEach((control) => control.addEventListener("click", onPrevClick));
|
|
773
|
+
controls.next.forEach((control) => control.addEventListener("click", onNextClick));
|
|
774
|
+
controls.dotsContainers.forEach((container) => container.addEventListener("click", onDotsClick));
|
|
429
775
|
const instance = {
|
|
430
776
|
goTo,
|
|
431
777
|
next,
|
|
@@ -435,23 +781,34 @@ function createCarousel(rootInput, options = {}) {
|
|
|
435
781
|
getCount: () => slides.length,
|
|
436
782
|
isAnimating: () => animating
|
|
437
783
|
};
|
|
438
|
-
(
|
|
784
|
+
(_d = resolved.onInit) == null ? void 0 : _d.call(resolved, instance);
|
|
439
785
|
function disableControls(disabled) {
|
|
440
786
|
toggleClass(root, resolved.classNames.animatingRoot, disabled);
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
787
|
+
controls.prev.forEach((control) => {
|
|
788
|
+
setDisabled(control, disabled, resolved.classNames.disabledControl);
|
|
789
|
+
});
|
|
790
|
+
controls.next.forEach((control) => {
|
|
791
|
+
setDisabled(control, disabled, resolved.classNames.disabledControl);
|
|
792
|
+
});
|
|
793
|
+
controls.dotsContainers.forEach((container) => {
|
|
794
|
+
setAriaDisabled(container, disabled);
|
|
795
|
+
});
|
|
796
|
+
controls.dots.forEach((dotGroup) => {
|
|
797
|
+
dotGroup.forEach((dot) => {
|
|
798
|
+
setAriaDisabled(dot, disabled);
|
|
799
|
+
toggleClass(dot, resolved.classNames.disabledControl, disabled);
|
|
800
|
+
});
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
function setAllDotsState(activeIndex) {
|
|
804
|
+
controls.dots.forEach((dotGroup) => {
|
|
805
|
+
setDotsState(dotGroup, activeIndex, resolved.classNames.activeDot);
|
|
449
806
|
});
|
|
450
807
|
}
|
|
451
808
|
function applyActiveState(nextIndex) {
|
|
452
809
|
currentIndex = nextIndex;
|
|
453
810
|
setSlidesState(slides, currentIndex, resolved.classNames.activeSlide);
|
|
454
|
-
|
|
811
|
+
setAllDotsState(currentIndex);
|
|
455
812
|
}
|
|
456
813
|
function finalizeTransition(from, to, direction) {
|
|
457
814
|
var _a2;
|
|
@@ -461,7 +818,7 @@ function createCarousel(rootInput, options = {}) {
|
|
|
461
818
|
(_a2 = resolved.onAfterChange) == null ? void 0 : _a2.call(resolved, { from, to, direction });
|
|
462
819
|
}
|
|
463
820
|
function transitionTo(nextIndex, immediate) {
|
|
464
|
-
var _a2;
|
|
821
|
+
var _a2, _b2;
|
|
465
822
|
if (animating) return;
|
|
466
823
|
if (nextIndex === currentIndex) return;
|
|
467
824
|
const from = currentIndex;
|
|
@@ -485,7 +842,7 @@ function createCarousel(rootInput, options = {}) {
|
|
|
485
842
|
})
|
|
486
843
|
);
|
|
487
844
|
state.activeTimeline = master;
|
|
488
|
-
const overlap = Math.max(0, resolved.transition.overlap);
|
|
845
|
+
const overlap = Math.max(0, (_b2 = resolved.transition.exitOverlap) != null ? _b2 : resolved.transition.overlap);
|
|
489
846
|
const enterAt = Math.max(0, exitTl.duration() - overlap);
|
|
490
847
|
master.add(exitTl, 0);
|
|
491
848
|
master.add(() => applyActiveState(to), enterAt);
|
|
@@ -501,59 +858,73 @@ function createCarousel(rootInput, options = {}) {
|
|
|
501
858
|
if (animating) return;
|
|
502
859
|
const nextIndex = resolveNextIndex(currentIndex, slides.length, resolved.loop);
|
|
503
860
|
if (nextIndex === currentIndex) return;
|
|
861
|
+
setAllDotsState(nextIndex);
|
|
504
862
|
transitionTo(nextIndex, opts == null ? void 0 : opts.immediate);
|
|
505
863
|
}
|
|
506
864
|
function prev(opts) {
|
|
507
865
|
if (animating) return;
|
|
508
866
|
const nextIndex = resolvePrevIndex(currentIndex, slides.length, resolved.loop);
|
|
509
867
|
if (nextIndex === currentIndex) return;
|
|
868
|
+
setAllDotsState(nextIndex);
|
|
510
869
|
transitionTo(nextIndex, opts == null ? void 0 : opts.immediate);
|
|
511
870
|
}
|
|
512
871
|
function destroy() {
|
|
513
|
-
var _a2
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
(
|
|
872
|
+
var _a2;
|
|
873
|
+
controls.prev.forEach((control) => control.removeEventListener("click", onPrevClick));
|
|
874
|
+
controls.next.forEach((control) => control.removeEventListener("click", onNextClick));
|
|
875
|
+
controls.dotsContainers.forEach((container) => container.removeEventListener("click", onDotsClick));
|
|
876
|
+
(_a2 = state.activeTimeline) == null ? void 0 : _a2.kill();
|
|
518
877
|
animating = false;
|
|
519
878
|
ctx.revert();
|
|
520
|
-
|
|
521
|
-
|
|
879
|
+
controls.dotsContainers.forEach((container) => {
|
|
880
|
+
container.querySelectorAll(generatedDotSelector).forEach((dot) => {
|
|
522
881
|
dot.remove();
|
|
523
882
|
});
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
883
|
+
});
|
|
884
|
+
controls.dotTemplates.forEach((template) => {
|
|
885
|
+
if (template) {
|
|
886
|
+
template.hidden = false;
|
|
887
|
+
}
|
|
888
|
+
});
|
|
528
889
|
}
|
|
529
890
|
return instance;
|
|
530
891
|
}
|
|
531
892
|
function resolveControls(root, options, slideCount) {
|
|
532
893
|
const rootId = root.getAttribute("id");
|
|
533
|
-
const
|
|
894
|
+
const queryAllWithFallback = (selector) => {
|
|
534
895
|
if (rootId) {
|
|
535
|
-
const scoped = document.
|
|
536
|
-
if (scoped) return scoped;
|
|
896
|
+
const scoped = Array.from(document.querySelectorAll(`${selector}[data-for="${rootId}"]`));
|
|
897
|
+
if (scoped.length) return scoped;
|
|
537
898
|
}
|
|
538
|
-
return
|
|
899
|
+
return qsa(root, selector);
|
|
539
900
|
};
|
|
540
|
-
const prev =
|
|
541
|
-
const next =
|
|
542
|
-
const
|
|
543
|
-
const
|
|
544
|
-
const dots =
|
|
545
|
-
|
|
901
|
+
const prev = queryAllWithFallback(options.selectors.prev);
|
|
902
|
+
const next = queryAllWithFallback(options.selectors.next);
|
|
903
|
+
const dotsContainers = queryAllWithFallback(options.selectors.dots);
|
|
904
|
+
const dotTemplates = [];
|
|
905
|
+
const dots = dotsContainers.map((container) => {
|
|
906
|
+
const template = qs(container, options.selectors.dotTemplate);
|
|
907
|
+
dotTemplates.push(template);
|
|
908
|
+
return setupDots(container, template, options, slideCount);
|
|
909
|
+
});
|
|
910
|
+
return { prev, next, dotsContainers, dotTemplates, dots };
|
|
546
911
|
}
|
|
547
912
|
function setupDots(container, template, options, slideCount) {
|
|
548
913
|
const dots = qsa(container, generatedDotSelector);
|
|
549
914
|
dots.forEach((dot) => dot.remove());
|
|
550
915
|
if (!template) return [];
|
|
551
916
|
const clones = [];
|
|
917
|
+
const disableOpacityAttr = template.getAttribute("data-carousel-disable-opacity");
|
|
552
918
|
for (let i = 0; i < slideCount; i += 1) {
|
|
553
919
|
const clone = template.cloneNode(true);
|
|
554
920
|
clone.removeAttribute("id");
|
|
555
921
|
clone.setAttribute("data-carousel-dot", "true");
|
|
556
922
|
clone.setAttribute("data-carousel-dot-index", String(i));
|
|
923
|
+
if (disableOpacityAttr !== null) {
|
|
924
|
+
clone.setAttribute("data-carousel-disable-opacity", disableOpacityAttr);
|
|
925
|
+
} else {
|
|
926
|
+
clone.removeAttribute("data-carousel-disable-opacity");
|
|
927
|
+
}
|
|
557
928
|
clone.setAttribute("aria-label", `Go to slide ${i + 1}`);
|
|
558
929
|
clone.classList.add(options.classNames.dot);
|
|
559
930
|
if (clone instanceof HTMLButtonElement && !clone.getAttribute("type")) {
|