glide-react 1.0.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/dist/index.mjs ADDED
@@ -0,0 +1,1994 @@
1
+ // src/index.tsx
2
+ import React4, {
3
+ forwardRef as forwardRef2,
4
+ useReducer,
5
+ useEffect,
6
+ useRef,
7
+ useCallback as useCallback3,
8
+ useImperativeHandle,
9
+ Children as Children2,
10
+ useMemo as useMemo4
11
+ } from "react";
12
+
13
+ // src/types.ts
14
+ var defaultSettings = {
15
+ accessibility: true,
16
+ adaptiveHeight: false,
17
+ arrows: true,
18
+ autoplay: false,
19
+ autoplaySpeed: 3e3,
20
+ centerMode: false,
21
+ centerPadding: "50px",
22
+ className: "",
23
+ cssEase: "ease",
24
+ dots: false,
25
+ dotsClass: "glide-dots",
26
+ draggable: true,
27
+ easing: "linear",
28
+ edgeFriction: 0.35,
29
+ fade: false,
30
+ focusOnSelect: false,
31
+ infinite: true,
32
+ initialSlide: 0,
33
+ lazyLoad: null,
34
+ pauseOnDotsHover: false,
35
+ pauseOnFocus: false,
36
+ pauseOnHover: true,
37
+ responsive: null,
38
+ rows: 1,
39
+ rtl: false,
40
+ slide: "div",
41
+ slidesPerRow: 1,
42
+ slidesToScroll: 1,
43
+ slidesToShow: 1,
44
+ speed: 500,
45
+ swipe: true,
46
+ swipeToSlide: false,
47
+ touchMove: true,
48
+ touchThreshold: 5,
49
+ useCSS: true,
50
+ useTransform: true,
51
+ variableWidth: false,
52
+ vertical: false,
53
+ verticalSwiping: false,
54
+ waitForAnimate: true,
55
+ disabled: false
56
+ };
57
+
58
+ // src/components/Track.tsx
59
+ import {
60
+ Children,
61
+ cloneElement,
62
+ isValidElement,
63
+ forwardRef,
64
+ useCallback,
65
+ useMemo
66
+ } from "react";
67
+
68
+ // src/utils/slideUtils.ts
69
+ var canUseDOM = () => !!(typeof window !== "undefined" && window.document && window.document.createElement);
70
+ var getWidth = (elem) => elem && elem.offsetWidth || 0;
71
+ var getHeight = (elem) => elem && elem.offsetHeight || 0;
72
+ function clamp(number, lowerBound, upperBound) {
73
+ return Math.max(lowerBound, Math.min(number, upperBound));
74
+ }
75
+ var getPreClones = (spec) => {
76
+ if (spec.disabled || !spec.infinite) {
77
+ return 0;
78
+ }
79
+ if (spec.variableWidth) {
80
+ return spec.slideCount || 0;
81
+ }
82
+ return (spec.slidesToShow || 1) + (spec.centerMode ? 1 : 0);
83
+ };
84
+ var getPostClones = (spec) => {
85
+ if (spec.disabled || !spec.infinite) {
86
+ return 0;
87
+ }
88
+ if (spec.variableWidth) {
89
+ return spec.slideCount || 0;
90
+ }
91
+ return (spec.slidesToShow || 1) + (spec.centerMode ? 1 : 0);
92
+ };
93
+ var getTotalSlides = (spec) => {
94
+ if (spec.slideCount === 1) {
95
+ return 1;
96
+ }
97
+ return getPreClones(spec) + (spec.slideCount || 0) + getPostClones(spec);
98
+ };
99
+ var canGoNext = (spec) => {
100
+ if (spec.infinite) {
101
+ return true;
102
+ }
103
+ const currentSlide = spec.currentSlide || 0;
104
+ const slideCount = spec.slideCount || 0;
105
+ const slidesToShow = spec.slidesToShow || 1;
106
+ if (spec.centerMode && currentSlide >= slideCount - 1) {
107
+ return false;
108
+ }
109
+ if (slideCount <= slidesToShow || currentSlide >= slideCount - slidesToShow) {
110
+ return false;
111
+ }
112
+ return true;
113
+ };
114
+ var canGoPrev = (spec) => {
115
+ if (spec.infinite) {
116
+ return true;
117
+ }
118
+ const currentSlide = spec.currentSlide || 0;
119
+ if (currentSlide <= 0) {
120
+ return false;
121
+ }
122
+ return true;
123
+ };
124
+ var getSwipeDirection = (touchObject, verticalSwiping = false) => {
125
+ const xDist = touchObject.startX - touchObject.curX;
126
+ const yDist = touchObject.startY - touchObject.curY;
127
+ const r = Math.atan2(yDist, xDist);
128
+ let swipeAngle = Math.round(r * 180 / Math.PI);
129
+ if (swipeAngle < 0) {
130
+ swipeAngle = 360 - Math.abs(swipeAngle);
131
+ }
132
+ if (swipeAngle <= 45 && swipeAngle >= 0 || swipeAngle <= 360 && swipeAngle >= 315) {
133
+ return "left";
134
+ }
135
+ if (swipeAngle >= 135 && swipeAngle <= 225) {
136
+ return "right";
137
+ }
138
+ if (verticalSwiping) {
139
+ if (swipeAngle >= 35 && swipeAngle <= 135) {
140
+ return "up";
141
+ }
142
+ return "down";
143
+ }
144
+ return "vertical";
145
+ };
146
+ var safePreventDefault = (event) => {
147
+ const passiveEvents = ["onTouchStart", "onTouchMove", "onWheel"];
148
+ const reactEvent = event;
149
+ if (reactEvent._reactName && !passiveEvents.includes(reactEvent._reactName)) {
150
+ event.preventDefault();
151
+ } else if (!reactEvent._reactName) {
152
+ try {
153
+ event.preventDefault();
154
+ } catch {
155
+ }
156
+ }
157
+ };
158
+ var swipeStart = (e, swipe, draggable) => {
159
+ if (e.target.tagName === "IMG") {
160
+ safePreventDefault(e);
161
+ }
162
+ if (!swipe || !draggable && e.type.indexOf("mouse") !== -1) {
163
+ return null;
164
+ }
165
+ const touches = "touches" in e ? e.touches : null;
166
+ return {
167
+ dragging: true,
168
+ touchObject: {
169
+ startX: touches ? touches[0].pageX : e.clientX,
170
+ startY: touches ? touches[0].pageY : e.clientY,
171
+ curX: touches ? touches[0].pageX : e.clientX,
172
+ curY: touches ? touches[0].pageY : e.clientY
173
+ }
174
+ };
175
+ };
176
+ var swipeMove = (e, spec) => {
177
+ const {
178
+ scrolling,
179
+ animating,
180
+ vertical,
181
+ swipeToSlide,
182
+ verticalSwiping,
183
+ rtl,
184
+ currentSlide,
185
+ edgeFriction,
186
+ edgeDragged,
187
+ onEdge,
188
+ swiped,
189
+ swiping,
190
+ slideCount,
191
+ slidesToScroll,
192
+ infinite,
193
+ touchObject,
194
+ swipeEvent,
195
+ listHeight,
196
+ listWidth
197
+ } = spec;
198
+ if (scrolling) return null;
199
+ if (animating) {
200
+ safePreventDefault(e);
201
+ return null;
202
+ }
203
+ if (vertical && swipeToSlide && verticalSwiping) {
204
+ safePreventDefault(e);
205
+ }
206
+ const touches = "touches" in e ? e.touches : null;
207
+ const newTouchObject = {
208
+ ...touchObject,
209
+ curX: touches ? touches[0].pageX : e.clientX,
210
+ curY: touches ? touches[0].pageY : e.clientY
211
+ };
212
+ newTouchObject.swipeLength = Math.round(
213
+ Math.sqrt(Math.pow(newTouchObject.curX - newTouchObject.startX, 2))
214
+ );
215
+ const verticalSwipeLength = Math.round(
216
+ Math.sqrt(Math.pow(newTouchObject.curY - newTouchObject.startY, 2))
217
+ );
218
+ if (!verticalSwiping && !swiping && verticalSwipeLength > 10) {
219
+ return { scrolling: true };
220
+ }
221
+ if (verticalSwiping) {
222
+ newTouchObject.swipeLength = verticalSwipeLength;
223
+ }
224
+ let positionOffset = (!rtl ? 1 : -1) * (newTouchObject.curX > newTouchObject.startX ? 1 : -1);
225
+ if (verticalSwiping) {
226
+ positionOffset = newTouchObject.curY > newTouchObject.startY ? 1 : -1;
227
+ }
228
+ const dotCount = Math.ceil(slideCount / slidesToScroll);
229
+ const swipeDirection = getSwipeDirection(newTouchObject, verticalSwiping);
230
+ let touchSwipeLength = newTouchObject.swipeLength;
231
+ const state = {};
232
+ if (!infinite) {
233
+ if (currentSlide === 0 && (swipeDirection === "right" || swipeDirection === "down") || currentSlide + 1 >= dotCount && (swipeDirection === "left" || swipeDirection === "up") || !canGoNext(spec) && (swipeDirection === "left" || swipeDirection === "up")) {
234
+ touchSwipeLength = newTouchObject.swipeLength * edgeFriction;
235
+ if (edgeDragged === false && onEdge) {
236
+ onEdge(swipeDirection);
237
+ state.edgeDragged = true;
238
+ }
239
+ }
240
+ }
241
+ if (!swiped && swipeEvent) {
242
+ swipeEvent(swipeDirection);
243
+ state.swiped = true;
244
+ }
245
+ const curLeft = getTrackLeft({
246
+ ...spec,
247
+ slideIndex: currentSlide
248
+ });
249
+ let swipeLeft;
250
+ if (!vertical) {
251
+ if (!rtl) {
252
+ swipeLeft = curLeft + touchSwipeLength * positionOffset;
253
+ } else {
254
+ swipeLeft = curLeft - touchSwipeLength * positionOffset;
255
+ }
256
+ } else {
257
+ swipeLeft = curLeft + touchSwipeLength * (listHeight / listWidth) * positionOffset;
258
+ }
259
+ if (verticalSwiping) {
260
+ swipeLeft = curLeft + touchSwipeLength * positionOffset;
261
+ }
262
+ const trackStyle = getTrackCSS({
263
+ ...spec,
264
+ left: swipeLeft
265
+ });
266
+ if (Math.abs(newTouchObject.curX - newTouchObject.startX) < Math.abs(newTouchObject.curY - newTouchObject.startY) * 0.8) {
267
+ return {
268
+ ...state,
269
+ touchObject: newTouchObject,
270
+ swipeLeft,
271
+ trackStyle
272
+ };
273
+ }
274
+ if (newTouchObject.swipeLength > 10) {
275
+ state.swiping = true;
276
+ safePreventDefault(e);
277
+ }
278
+ return {
279
+ ...state,
280
+ touchObject: newTouchObject,
281
+ swipeLeft,
282
+ trackStyle
283
+ };
284
+ };
285
+ var swipeEnd = (e, spec) => {
286
+ const {
287
+ dragging,
288
+ swipe,
289
+ touchObject,
290
+ listWidth,
291
+ touchThreshold,
292
+ verticalSwiping,
293
+ listHeight,
294
+ swipeToSlide,
295
+ scrolling,
296
+ onSwipe,
297
+ currentSlide,
298
+ infinite
299
+ } = spec;
300
+ const emptyTouchObject = { startX: 0, startY: 0, curX: 0, curY: 0 };
301
+ const state = {
302
+ dragging: false,
303
+ edgeDragged: false,
304
+ scrolling: false,
305
+ swiping: false,
306
+ swiped: false,
307
+ swipeLeft: null,
308
+ touchObject: emptyTouchObject
309
+ };
310
+ if (!dragging) {
311
+ if (swipe) safePreventDefault(e);
312
+ return state;
313
+ }
314
+ if (scrolling) {
315
+ return state;
316
+ }
317
+ if (!touchObject.swipeLength) {
318
+ return state;
319
+ }
320
+ const minSwipe = verticalSwiping ? listHeight / touchThreshold : listWidth / touchThreshold;
321
+ const swipeDirection = getSwipeDirection(touchObject, verticalSwiping);
322
+ if (touchObject.swipeLength > minSwipe) {
323
+ safePreventDefault(e);
324
+ if (onSwipe) {
325
+ onSwipe(swipeDirection);
326
+ }
327
+ let newSlide;
328
+ const activeSlide = infinite ? currentSlide : spec.targetSlide;
329
+ const slideCount = getSlideCount(spec);
330
+ switch (swipeDirection) {
331
+ case "left":
332
+ case "up":
333
+ newSlide = activeSlide + slideCount;
334
+ if (swipeToSlide) {
335
+ newSlide = checkNavigable(spec, newSlide);
336
+ }
337
+ state.triggerSlideHandler = newSlide;
338
+ state.currentDirection = 0;
339
+ break;
340
+ case "right":
341
+ case "down":
342
+ newSlide = activeSlide - slideCount;
343
+ if (swipeToSlide) {
344
+ newSlide = checkNavigable(spec, newSlide);
345
+ }
346
+ state.triggerSlideHandler = newSlide;
347
+ state.currentDirection = 1;
348
+ break;
349
+ default:
350
+ state.triggerSlideHandler = activeSlide;
351
+ }
352
+ } else {
353
+ const currentLeft = getTrackLeft({
354
+ ...spec,
355
+ slideIndex: currentSlide
356
+ });
357
+ state.trackStyle = getTrackAnimateCSS({
358
+ ...spec,
359
+ left: currentLeft
360
+ });
361
+ }
362
+ return state;
363
+ };
364
+ var getSlideCount = (spec) => {
365
+ if (spec.swipeToSlide) {
366
+ return 1;
367
+ }
368
+ return spec.slidesToScroll;
369
+ };
370
+ var getNavigableIndexes = (spec) => {
371
+ const max = spec.infinite ? spec.slideCount * 2 : spec.slideCount;
372
+ const breakpointStart = spec.infinite ? spec.slidesToShow * -1 : 0;
373
+ let counter = breakpointStart;
374
+ const indexes = [];
375
+ let breakpoint = breakpointStart;
376
+ while (breakpoint < max) {
377
+ indexes.push(breakpoint);
378
+ breakpoint = counter + spec.slidesToScroll;
379
+ counter += Math.min(spec.slidesToScroll, spec.slidesToShow);
380
+ }
381
+ return indexes;
382
+ };
383
+ var checkNavigable = (spec, index) => {
384
+ const navigables = getNavigableIndexes(spec);
385
+ let prevNavigable = 0;
386
+ if (index > navigables[navigables.length - 1]) {
387
+ return navigables[navigables.length - 1];
388
+ }
389
+ for (const nav of navigables) {
390
+ if (index < nav) {
391
+ return prevNavigable;
392
+ }
393
+ prevNavigable = nav;
394
+ }
395
+ return index;
396
+ };
397
+ var getTrackLeft = (spec) => {
398
+ if (spec.disabled) {
399
+ return 0;
400
+ }
401
+ const {
402
+ slideIndex,
403
+ infinite,
404
+ centerMode,
405
+ slideCount,
406
+ slidesToShow,
407
+ slidesToScroll,
408
+ slideWidth,
409
+ slideHeight,
410
+ fade,
411
+ vertical
412
+ } = spec;
413
+ if (fade || slideCount === 1) {
414
+ return 0;
415
+ }
416
+ let slidesToOffset = 0;
417
+ if (infinite) {
418
+ slidesToOffset = -getPreClones(spec);
419
+ if (slideCount % slidesToScroll !== 0 && slideIndex + slidesToScroll > slideCount) {
420
+ slidesToOffset = -(slideIndex > slideCount ? slidesToShow - (slideIndex - slideCount) : slideCount % slidesToScroll);
421
+ }
422
+ if (centerMode) {
423
+ slidesToOffset += Math.floor(slidesToShow / 2);
424
+ }
425
+ } else {
426
+ if (slideCount % slidesToScroll !== 0 && slideIndex + slidesToScroll > slideCount) {
427
+ slidesToOffset = slidesToShow - slideCount % slidesToScroll;
428
+ }
429
+ if (centerMode) {
430
+ slidesToOffset = Math.floor(slidesToShow / 2);
431
+ }
432
+ }
433
+ const slideOffset = slidesToOffset * slideWidth;
434
+ const verticalOffset = slidesToOffset * slideHeight;
435
+ let targetLeft;
436
+ if (!vertical) {
437
+ targetLeft = slideIndex * slideWidth * -1 + slideOffset;
438
+ } else {
439
+ targetLeft = slideIndex * slideHeight * -1 + verticalOffset;
440
+ }
441
+ return targetLeft;
442
+ };
443
+ var getTrackCSS = (spec) => {
444
+ let trackWidth;
445
+ let trackHeight;
446
+ const totalSlides = getTotalSlides(spec);
447
+ if (!spec.vertical) {
448
+ trackWidth = totalSlides * spec.slideWidth;
449
+ } else {
450
+ const trackChildren = spec.disabled ? spec.slideCount : spec.slideCount + 2 * spec.slidesToShow;
451
+ trackHeight = trackChildren * (spec.slideHeight || 0);
452
+ }
453
+ let style = {
454
+ opacity: 1,
455
+ transition: "",
456
+ WebkitTransition: ""
457
+ };
458
+ if (spec.useTransform) {
459
+ const transform = !spec.vertical ? `translate3d(${spec.left}px, 0px, 0px)` : `translate3d(0px, ${spec.left}px, 0px)`;
460
+ const msTransform = !spec.vertical ? `translateX(${spec.left}px)` : `translateY(${spec.left}px)`;
461
+ style = {
462
+ ...style,
463
+ WebkitTransform: transform,
464
+ transform,
465
+ msTransform
466
+ };
467
+ } else {
468
+ if (spec.vertical) {
469
+ style.top = spec.left;
470
+ } else {
471
+ style.left = spec.left;
472
+ }
473
+ }
474
+ if (spec.fade) {
475
+ style = { opacity: 1 };
476
+ }
477
+ if (trackWidth) {
478
+ style.width = trackWidth;
479
+ }
480
+ if (trackHeight) {
481
+ style.height = trackHeight;
482
+ }
483
+ return style;
484
+ };
485
+ var getTrackAnimateCSS = (spec) => {
486
+ const style = getTrackCSS(spec);
487
+ if (spec.useTransform) {
488
+ style.WebkitTransition = `-webkit-transform ${spec.speed}ms ${spec.cssEase}`;
489
+ style.transition = `transform ${spec.speed}ms ${spec.cssEase}`;
490
+ } else {
491
+ if (spec.vertical) {
492
+ style.transition = `top ${spec.speed}ms ${spec.cssEase}`;
493
+ } else {
494
+ style.transition = `left ${spec.speed}ms ${spec.cssEase}`;
495
+ }
496
+ }
497
+ return style;
498
+ };
499
+ var calculateSlideWidth = (listWidth, slidesToShow, centerMode, centerPadding, vertical) => {
500
+ if (vertical) {
501
+ return listWidth;
502
+ }
503
+ let centerPaddingAdj = 0;
504
+ if (centerMode) {
505
+ const paddingValue = parseInt(centerPadding, 10) || 0;
506
+ centerPaddingAdj = paddingValue * 2;
507
+ if (centerPadding.endsWith("%")) {
508
+ centerPaddingAdj = listWidth * paddingValue * 2 / 100;
509
+ }
510
+ }
511
+ return Math.ceil((listWidth - centerPaddingAdj) / slidesToShow);
512
+ };
513
+ var keyHandler = (e, accessibility, rtl) => {
514
+ if (e.target.tagName.match(/TEXTAREA|INPUT|SELECT/) || !accessibility) {
515
+ return "";
516
+ }
517
+ if (e.keyCode === 37) {
518
+ return rtl ? "next" : "previous";
519
+ }
520
+ if (e.keyCode === 39) {
521
+ return rtl ? "previous" : "next";
522
+ }
523
+ return "";
524
+ };
525
+ var lazyStartIndex = (spec) => {
526
+ return spec.currentSlide - lazySlidesOnLeft(spec);
527
+ };
528
+ var lazyEndIndex = (spec) => {
529
+ return spec.currentSlide + lazySlidesOnRight(spec);
530
+ };
531
+ var lazySlidesOnLeft = (spec) => {
532
+ if (spec.centerMode) {
533
+ return Math.floor(spec.slidesToShow / 2) + (parseInt(spec.centerPadding || "0", 10) > 0 ? 1 : 0);
534
+ }
535
+ return 0;
536
+ };
537
+ var lazySlidesOnRight = (spec) => {
538
+ if (spec.centerMode) {
539
+ return Math.floor((spec.slidesToShow - 1) / 2) + 1 + (parseInt(spec.centerPadding || "0", 10) > 0 ? 1 : 0);
540
+ }
541
+ return spec.slidesToShow;
542
+ };
543
+ var getOnDemandLazySlides = (spec) => {
544
+ const onDemandSlides = [];
545
+ const startIndex = lazyStartIndex(spec);
546
+ const endIndex = lazyEndIndex(spec);
547
+ for (let slideIndex = startIndex; slideIndex < endIndex; slideIndex++) {
548
+ if (!spec.lazyLoadedList.includes(slideIndex)) {
549
+ onDemandSlides.push(slideIndex);
550
+ }
551
+ }
552
+ return onDemandSlides;
553
+ };
554
+ var getSlideClasses = (spec) => {
555
+ let index = spec.index;
556
+ if (spec.rtl) {
557
+ index = spec.slideCount - 1 - spec.index;
558
+ }
559
+ const glideCloned = index < 0 || index >= spec.slideCount;
560
+ let glideActive = false;
561
+ let glideCenter = false;
562
+ if (spec.centerMode) {
563
+ const centerOffset = Math.floor(spec.slidesToShow / 2);
564
+ glideCenter = (index - spec.currentSlide) % spec.slideCount === 0;
565
+ if (index > spec.currentSlide - centerOffset - 1 && index <= spec.currentSlide + centerOffset) {
566
+ glideActive = true;
567
+ }
568
+ } else {
569
+ glideActive = spec.currentSlide <= index && index < spec.currentSlide + spec.slidesToShow;
570
+ }
571
+ let focusedSlide = spec.targetSlide;
572
+ if (spec.targetSlide < 0) {
573
+ focusedSlide = spec.targetSlide + spec.slideCount;
574
+ } else if (spec.targetSlide >= spec.slideCount) {
575
+ focusedSlide = spec.targetSlide - spec.slideCount;
576
+ }
577
+ const glideCurrent = index === focusedSlide;
578
+ return {
579
+ "glide-slide": true,
580
+ "glide-active": glideActive,
581
+ "glide-center": glideCenter,
582
+ "glide-cloned": glideCloned,
583
+ "glide-current": glideCurrent
584
+ };
585
+ };
586
+
587
+ // src/components/Track.tsx
588
+ import { jsx } from "react/jsx-runtime";
589
+ var getSlideStyle = (spec) => {
590
+ const style = {};
591
+ if (!spec.variableWidth) {
592
+ style.width = spec.slideWidth;
593
+ }
594
+ if (spec.fade) {
595
+ style.position = "relative";
596
+ if (spec.vertical) {
597
+ style.top = -spec.index * (spec.slideHeight || 0);
598
+ } else {
599
+ style.left = -spec.index * spec.slideWidth;
600
+ }
601
+ style.opacity = spec.currentSlide === spec.index ? 1 : 0;
602
+ style.zIndex = spec.currentSlide === spec.index ? 999 : 998;
603
+ if (spec.useCSS) {
604
+ style.transition = `opacity ${spec.speed}ms ${spec.cssEase}, visibility ${spec.speed}ms ${spec.cssEase}`;
605
+ }
606
+ }
607
+ return style;
608
+ };
609
+ var getKey = (child, fallbackKey) => {
610
+ if (isValidElement(child) && child.key !== null) {
611
+ return child.key;
612
+ }
613
+ return fallbackKey;
614
+ };
615
+ var classNames = (classes) => {
616
+ return Object.entries(classes).filter(([, value]) => value).map(([key]) => key).join(" ");
617
+ };
618
+ var Track = forwardRef(function Track2({
619
+ trackStyle,
620
+ slideWidth,
621
+ slideHeight,
622
+ slideCount,
623
+ currentSlide,
624
+ targetSlide,
625
+ slidesToShow,
626
+ slidesToScroll,
627
+ infinite,
628
+ centerMode,
629
+ centerPadding,
630
+ fade,
631
+ vertical,
632
+ variableWidth,
633
+ rtl,
634
+ disabled,
635
+ lazyLoad,
636
+ lazyLoadedList,
637
+ speed,
638
+ cssEase,
639
+ useCSS,
640
+ children,
641
+ onSlideClick,
642
+ focusOnSelect,
643
+ onMouseEnter,
644
+ onMouseOver,
645
+ onMouseLeave
646
+ }, ref) {
647
+ const spec = useMemo(
648
+ () => ({
649
+ slideCount,
650
+ slidesToShow,
651
+ slidesToScroll,
652
+ currentSlide,
653
+ targetSlide,
654
+ centerMode,
655
+ centerPadding,
656
+ infinite,
657
+ rtl,
658
+ fade,
659
+ vertical,
660
+ variableWidth,
661
+ disabled
662
+ }),
663
+ [
664
+ slideCount,
665
+ slidesToShow,
666
+ slidesToScroll,
667
+ currentSlide,
668
+ targetSlide,
669
+ centerMode,
670
+ centerPadding,
671
+ infinite,
672
+ rtl,
673
+ fade,
674
+ vertical,
675
+ variableWidth,
676
+ disabled
677
+ ]
678
+ );
679
+ const startIndex = useMemo(
680
+ () => lazyStartIndex({ currentSlide, centerMode, slidesToShow, centerPadding }),
681
+ [currentSlide, centerMode, slidesToShow, centerPadding]
682
+ );
683
+ const endIndex = useMemo(
684
+ () => lazyEndIndex({ currentSlide, centerMode, slidesToShow, centerPadding }),
685
+ [currentSlide, centerMode, slidesToShow, centerPadding]
686
+ );
687
+ const preCloneCount = useMemo(() => getPreClones(spec), [spec]);
688
+ const postCloneCount = useMemo(() => getPostClones(spec), [spec]);
689
+ const handleSlideClick = useCallback(
690
+ (index, originalOnClick) => (e) => {
691
+ if (originalOnClick) {
692
+ originalOnClick(e);
693
+ }
694
+ if (focusOnSelect && onSlideClick) {
695
+ onSlideClick(index);
696
+ }
697
+ },
698
+ [focusOnSelect, onSlideClick]
699
+ );
700
+ const slides = useMemo(() => {
701
+ const output = [];
702
+ const preCloneSlides = [];
703
+ const postCloneSlides = [];
704
+ const childrenArray = Children.toArray(children);
705
+ const childrenCount = childrenArray.length;
706
+ childrenArray.forEach((elem, index) => {
707
+ if (!isValidElement(elem)) return;
708
+ let child = elem;
709
+ if (lazyLoad) {
710
+ const shouldLoad = lazyLoadedList.includes(index);
711
+ if (!shouldLoad) {
712
+ child = /* @__PURE__ */ jsx("div", {});
713
+ }
714
+ }
715
+ const childStyle = getSlideStyle({
716
+ index,
717
+ slideWidth,
718
+ slideHeight,
719
+ fade,
720
+ vertical,
721
+ variableWidth,
722
+ currentSlide,
723
+ speed,
724
+ cssEase,
725
+ useCSS
726
+ });
727
+ const slideClasses = getSlideClasses({
728
+ index,
729
+ currentSlide,
730
+ slideCount,
731
+ slidesToShow,
732
+ centerMode,
733
+ targetSlide,
734
+ rtl
735
+ });
736
+ const existingClassName = elem.props.className || "";
737
+ const className = `${classNames(slideClasses)} ${existingClassName}`.trim();
738
+ const originalOnClick = elem.props.onClick;
739
+ output.push(
740
+ cloneElement(child, {
741
+ key: `original${getKey(child, index)}`,
742
+ "data-index": index,
743
+ className,
744
+ tabIndex: -1,
745
+ "aria-hidden": !slideClasses["glide-active"],
746
+ style: {
747
+ outline: "none",
748
+ ...elem.props.style,
749
+ ...childStyle
750
+ },
751
+ onClick: handleSlideClick(index, originalOnClick)
752
+ })
753
+ );
754
+ if (infinite && childrenCount > 1 && !fade && !disabled) {
755
+ const preCloneNo = childrenCount - index;
756
+ if (preCloneNo <= preCloneCount) {
757
+ const key = -preCloneNo;
758
+ let cloneChild = elem;
759
+ if (lazyLoad && key >= startIndex) {
760
+ cloneChild = elem;
761
+ } else if (lazyLoad) {
762
+ cloneChild = /* @__PURE__ */ jsx("div", {});
763
+ }
764
+ const cloneClasses = getSlideClasses({
765
+ index: key,
766
+ currentSlide,
767
+ slideCount,
768
+ slidesToShow,
769
+ centerMode,
770
+ targetSlide,
771
+ rtl
772
+ });
773
+ preCloneSlides.push(
774
+ cloneElement(cloneChild, {
775
+ key: `precloned${getKey(cloneChild, key)}`,
776
+ "data-index": key,
777
+ tabIndex: -1,
778
+ className: `${classNames(cloneClasses)} ${existingClassName}`.trim(),
779
+ "aria-hidden": !cloneClasses["glide-active"],
780
+ style: {
781
+ ...elem.props.style,
782
+ ...childStyle
783
+ },
784
+ onClick: handleSlideClick(index, originalOnClick)
785
+ })
786
+ );
787
+ }
788
+ if (index < postCloneCount) {
789
+ const key = childrenCount + index;
790
+ let cloneChild = elem;
791
+ if (lazyLoad && key < endIndex) {
792
+ cloneChild = elem;
793
+ } else if (lazyLoad) {
794
+ cloneChild = /* @__PURE__ */ jsx("div", {});
795
+ }
796
+ const cloneClasses = getSlideClasses({
797
+ index: key,
798
+ currentSlide,
799
+ slideCount,
800
+ slidesToShow,
801
+ centerMode,
802
+ targetSlide,
803
+ rtl
804
+ });
805
+ postCloneSlides.push(
806
+ cloneElement(cloneChild, {
807
+ key: `postcloned${getKey(cloneChild, key)}`,
808
+ "data-index": key,
809
+ tabIndex: -1,
810
+ className: `${classNames(cloneClasses)} ${existingClassName}`.trim(),
811
+ "aria-hidden": !cloneClasses["glide-active"],
812
+ style: {
813
+ ...elem.props.style,
814
+ ...childStyle
815
+ },
816
+ onClick: handleSlideClick(index, originalOnClick)
817
+ })
818
+ );
819
+ }
820
+ }
821
+ });
822
+ let result = preCloneSlides.concat(output, postCloneSlides);
823
+ if (rtl) {
824
+ result = result.reverse();
825
+ }
826
+ return result;
827
+ }, [
828
+ children,
829
+ slideWidth,
830
+ slideHeight,
831
+ slideCount,
832
+ currentSlide,
833
+ targetSlide,
834
+ slidesToShow,
835
+ slidesToScroll,
836
+ infinite,
837
+ centerMode,
838
+ centerPadding,
839
+ fade,
840
+ vertical,
841
+ variableWidth,
842
+ rtl,
843
+ disabled,
844
+ lazyLoad,
845
+ lazyLoadedList,
846
+ speed,
847
+ cssEase,
848
+ useCSS,
849
+ preCloneCount,
850
+ postCloneCount,
851
+ startIndex,
852
+ endIndex,
853
+ handleSlideClick
854
+ ]);
855
+ const baseTrackStyle = {
856
+ position: "relative",
857
+ display: fade ? "block" : "flex",
858
+ flexDirection: vertical ? "column" : "row",
859
+ ...trackStyle
860
+ };
861
+ return /* @__PURE__ */ jsx(
862
+ "div",
863
+ {
864
+ ref,
865
+ className: "glide-track",
866
+ style: baseTrackStyle,
867
+ onMouseEnter,
868
+ onMouseOver,
869
+ onMouseLeave,
870
+ children: slides
871
+ }
872
+ );
873
+ });
874
+
875
+ // src/components/Arrows.tsx
876
+ import { cloneElement as cloneElement2, isValidElement as isValidElement2 } from "react";
877
+ import { jsx as jsx2 } from "react/jsx-runtime";
878
+ var PrevArrowSVG = ({ className }) => /* @__PURE__ */ jsx2(
879
+ "svg",
880
+ {
881
+ className,
882
+ xmlns: "http://www.w3.org/2000/svg",
883
+ viewBox: "0 0 24 24",
884
+ fill: "none",
885
+ stroke: "currentColor",
886
+ strokeWidth: "2",
887
+ strokeLinecap: "round",
888
+ strokeLinejoin: "round",
889
+ style: { width: 20, height: 20 },
890
+ children: /* @__PURE__ */ jsx2("polyline", { points: "15 18 9 12 15 6" })
891
+ }
892
+ );
893
+ var NextArrowSVG = ({ className }) => /* @__PURE__ */ jsx2(
894
+ "svg",
895
+ {
896
+ className,
897
+ xmlns: "http://www.w3.org/2000/svg",
898
+ viewBox: "0 0 24 24",
899
+ fill: "none",
900
+ stroke: "currentColor",
901
+ strokeWidth: "2",
902
+ strokeLinecap: "round",
903
+ strokeLinejoin: "round",
904
+ style: { width: 20, height: 20 },
905
+ children: /* @__PURE__ */ jsx2("polyline", { points: "9 18 15 12 9 6" })
906
+ }
907
+ );
908
+ var baseArrowStyle = {
909
+ position: "absolute",
910
+ top: "50%",
911
+ transform: "translateY(-50%)",
912
+ zIndex: 10,
913
+ display: "flex",
914
+ alignItems: "center",
915
+ justifyContent: "center",
916
+ width: 40,
917
+ height: 40,
918
+ padding: 0,
919
+ border: "none",
920
+ borderRadius: "50%",
921
+ backgroundColor: "rgba(0, 0, 0, 0.5)",
922
+ color: "white",
923
+ cursor: "pointer",
924
+ transition: "background-color 0.2s, opacity 0.2s"
925
+ };
926
+ var disabledArrowStyle = {
927
+ ...baseArrowStyle,
928
+ opacity: 0.3,
929
+ cursor: "not-allowed"
930
+ };
931
+ var PrevArrow = ({
932
+ currentSlide,
933
+ slideCount,
934
+ slidesToShow,
935
+ infinite,
936
+ centerMode,
937
+ onClick,
938
+ customArrow
939
+ }) => {
940
+ const canGo = canGoPrev({
941
+ currentSlide,
942
+ infinite
943
+ });
944
+ const handleClick = (e) => {
945
+ e.preventDefault();
946
+ if (canGo) {
947
+ onClick();
948
+ }
949
+ };
950
+ if (customArrow && isValidElement2(customArrow)) {
951
+ const arrowProps = customArrow.props;
952
+ return cloneElement2(customArrow, {
953
+ onClick: handleClick,
954
+ currentSlide,
955
+ slideCount,
956
+ className: `glide-arrow glide-prev ${!canGo ? "glide-disabled" : ""} ${arrowProps.className || ""}`.trim(),
957
+ style: { ...arrowProps.style },
958
+ "aria-disabled": !canGo
959
+ });
960
+ }
961
+ return /* @__PURE__ */ jsx2(
962
+ "button",
963
+ {
964
+ type: "button",
965
+ className: `glide-arrow glide-prev ${!canGo ? "glide-disabled" : ""}`,
966
+ style: {
967
+ ...canGo ? baseArrowStyle : disabledArrowStyle,
968
+ left: 10
969
+ },
970
+ onClick: handleClick,
971
+ "aria-label": "Previous slide",
972
+ "aria-disabled": !canGo,
973
+ disabled: !canGo,
974
+ children: /* @__PURE__ */ jsx2(PrevArrowSVG, {})
975
+ }
976
+ );
977
+ };
978
+ var NextArrow = ({
979
+ currentSlide,
980
+ slideCount,
981
+ slidesToShow,
982
+ infinite,
983
+ centerMode,
984
+ onClick,
985
+ customArrow
986
+ }) => {
987
+ const canGo = canGoNext({
988
+ currentSlide,
989
+ slideCount,
990
+ slidesToShow,
991
+ infinite,
992
+ centerMode
993
+ });
994
+ const handleClick = (e) => {
995
+ e.preventDefault();
996
+ if (canGo) {
997
+ onClick();
998
+ }
999
+ };
1000
+ if (customArrow && isValidElement2(customArrow)) {
1001
+ const arrowProps = customArrow.props;
1002
+ return cloneElement2(customArrow, {
1003
+ onClick: handleClick,
1004
+ currentSlide,
1005
+ slideCount,
1006
+ className: `glide-arrow glide-next ${!canGo ? "glide-disabled" : ""} ${arrowProps.className || ""}`.trim(),
1007
+ style: { ...arrowProps.style },
1008
+ "aria-disabled": !canGo
1009
+ });
1010
+ }
1011
+ return /* @__PURE__ */ jsx2(
1012
+ "button",
1013
+ {
1014
+ type: "button",
1015
+ className: `glide-arrow glide-next ${!canGo ? "glide-disabled" : ""}`,
1016
+ style: {
1017
+ ...canGo ? baseArrowStyle : disabledArrowStyle,
1018
+ right: 10
1019
+ },
1020
+ onClick: handleClick,
1021
+ "aria-label": "Next slide",
1022
+ "aria-disabled": !canGo,
1023
+ disabled: !canGo,
1024
+ children: /* @__PURE__ */ jsx2(NextArrowSVG, {})
1025
+ }
1026
+ );
1027
+ };
1028
+
1029
+ // src/components/Dots.tsx
1030
+ import { useMemo as useMemo2 } from "react";
1031
+ import { jsx as jsx3 } from "react/jsx-runtime";
1032
+ var defaultDotsContainerStyle = {
1033
+ display: "flex",
1034
+ justifyContent: "center",
1035
+ alignItems: "center",
1036
+ listStyle: "none",
1037
+ margin: "16px 0 0",
1038
+ padding: 0,
1039
+ gap: 8
1040
+ };
1041
+ var defaultDotButtonStyle = {
1042
+ width: 10,
1043
+ height: 10,
1044
+ padding: 0,
1045
+ border: "none",
1046
+ borderRadius: "50%",
1047
+ backgroundColor: "rgba(0, 0, 0, 0.3)",
1048
+ cursor: "pointer",
1049
+ transition: "background-color 0.2s"
1050
+ };
1051
+ var activeDotButtonStyle = {
1052
+ ...defaultDotButtonStyle,
1053
+ backgroundColor: "rgba(0, 0, 0, 0.8)"
1054
+ };
1055
+ var Dots = ({
1056
+ slideCount,
1057
+ slidesToScroll,
1058
+ slidesToShow,
1059
+ currentSlide,
1060
+ infinite,
1061
+ onDotClick,
1062
+ customPaging,
1063
+ appendDots,
1064
+ dotsClass,
1065
+ onMouseEnter,
1066
+ onMouseLeave
1067
+ }) => {
1068
+ const dotCount = useMemo2(() => {
1069
+ if (infinite) {
1070
+ return Math.ceil(slideCount / slidesToScroll);
1071
+ }
1072
+ return Math.ceil((slideCount - slidesToShow) / slidesToScroll) + 1;
1073
+ }, [slideCount, slidesToScroll, slidesToShow, infinite]);
1074
+ const handleDotClick = (index) => (e) => {
1075
+ e.preventDefault();
1076
+ e.target.blur?.();
1077
+ onDotClick(index * slidesToScroll);
1078
+ };
1079
+ const dots = useMemo2(() => {
1080
+ return Array.from({ length: dotCount }).map((_, index) => {
1081
+ const isActive = index === Math.floor(currentSlide / slidesToScroll);
1082
+ const dotButton = customPaging ? customPaging(index) : /* @__PURE__ */ jsx3(
1083
+ "button",
1084
+ {
1085
+ type: "button",
1086
+ style: isActive ? activeDotButtonStyle : defaultDotButtonStyle,
1087
+ "aria-label": `Go to slide ${index + 1}`
1088
+ }
1089
+ );
1090
+ return /* @__PURE__ */ jsx3(
1091
+ "li",
1092
+ {
1093
+ className: isActive ? "glide-active" : "",
1094
+ style: { display: "inline-block" },
1095
+ children: /* @__PURE__ */ jsx3(
1096
+ "div",
1097
+ {
1098
+ onClick: handleDotClick(index),
1099
+ onKeyDown: (e) => {
1100
+ if (e.key === "Enter" || e.key === " ") {
1101
+ e.preventDefault();
1102
+ onDotClick(index * slidesToScroll);
1103
+ }
1104
+ },
1105
+ role: "button",
1106
+ tabIndex: 0,
1107
+ "aria-current": isActive ? "true" : void 0,
1108
+ children: dotButton
1109
+ }
1110
+ )
1111
+ },
1112
+ index
1113
+ );
1114
+ });
1115
+ }, [dotCount, currentSlide, slidesToScroll, customPaging, onDotClick]);
1116
+ const dotsContainer = /* @__PURE__ */ jsx3(
1117
+ "ul",
1118
+ {
1119
+ className: dotsClass,
1120
+ style: defaultDotsContainerStyle,
1121
+ onMouseEnter,
1122
+ onMouseLeave,
1123
+ children: dots
1124
+ }
1125
+ );
1126
+ if (appendDots) {
1127
+ return appendDots(dots);
1128
+ }
1129
+ return dotsContainer;
1130
+ };
1131
+
1132
+ // src/hooks/useTrack.ts
1133
+ import { useMemo as useMemo3, useCallback as useCallback2 } from "react";
1134
+ function useTrack(options) {
1135
+ const {
1136
+ currentSlide,
1137
+ slideCount,
1138
+ slidesToShow,
1139
+ slidesToScroll,
1140
+ infinite,
1141
+ centerMode,
1142
+ centerPadding,
1143
+ listWidth,
1144
+ listHeight,
1145
+ slideWidth: providedSlideWidth,
1146
+ slideHeight = 0,
1147
+ fade,
1148
+ vertical,
1149
+ variableWidth,
1150
+ useTransform,
1151
+ disabled,
1152
+ speed,
1153
+ cssEase,
1154
+ rtl,
1155
+ animating,
1156
+ swipeLeft
1157
+ } = options;
1158
+ const calculatedSlideWidth = useMemo3(() => {
1159
+ if (providedSlideWidth && providedSlideWidth > 0) {
1160
+ return providedSlideWidth;
1161
+ }
1162
+ if (listWidth <= 0) {
1163
+ return 0;
1164
+ }
1165
+ return calculateSlideWidth(listWidth, slidesToShow, centerMode, centerPadding, vertical);
1166
+ }, [providedSlideWidth, listWidth, slidesToShow, centerMode, centerPadding, vertical]);
1167
+ const preCloneCount = useMemo3(() => {
1168
+ return getPreClones({
1169
+ disabled,
1170
+ infinite,
1171
+ variableWidth,
1172
+ slideCount,
1173
+ slidesToShow,
1174
+ centerMode
1175
+ });
1176
+ }, [disabled, infinite, variableWidth, slideCount, slidesToShow, centerMode]);
1177
+ const postCloneCount = useMemo3(() => {
1178
+ return getPostClones({
1179
+ disabled,
1180
+ infinite,
1181
+ variableWidth,
1182
+ slideCount,
1183
+ slidesToShow,
1184
+ centerMode
1185
+ });
1186
+ }, [disabled, infinite, variableWidth, slideCount, slidesToShow, centerMode]);
1187
+ const totalSlides = useMemo3(() => {
1188
+ return getTotalSlides({
1189
+ slideCount,
1190
+ disabled,
1191
+ infinite,
1192
+ variableWidth,
1193
+ slidesToShow,
1194
+ centerMode
1195
+ });
1196
+ }, [slideCount, disabled, infinite, variableWidth, slidesToShow, centerMode]);
1197
+ const trackWidth = useMemo3(() => {
1198
+ if (vertical) {
1199
+ return listWidth;
1200
+ }
1201
+ return totalSlides * calculatedSlideWidth;
1202
+ }, [vertical, totalSlides, calculatedSlideWidth, listWidth]);
1203
+ const spec = useMemo3(
1204
+ () => ({
1205
+ slideIndex: currentSlide,
1206
+ infinite,
1207
+ centerMode,
1208
+ slideCount,
1209
+ slidesToShow,
1210
+ slidesToScroll,
1211
+ slideWidth: calculatedSlideWidth,
1212
+ slideHeight,
1213
+ fade,
1214
+ vertical,
1215
+ variableWidth,
1216
+ useTransform,
1217
+ disabled,
1218
+ listWidth,
1219
+ centerPadding
1220
+ }),
1221
+ [
1222
+ currentSlide,
1223
+ infinite,
1224
+ centerMode,
1225
+ slideCount,
1226
+ slidesToShow,
1227
+ slidesToScroll,
1228
+ calculatedSlideWidth,
1229
+ slideHeight,
1230
+ fade,
1231
+ vertical,
1232
+ variableWidth,
1233
+ useTransform,
1234
+ disabled,
1235
+ listWidth,
1236
+ centerPadding
1237
+ ]
1238
+ );
1239
+ const getTrackStyleForSlide = useCallback2(
1240
+ (slideIndex, animate = false) => {
1241
+ const left = getTrackLeft({
1242
+ ...spec,
1243
+ slideIndex
1244
+ });
1245
+ if (animate) {
1246
+ return getTrackAnimateCSS({
1247
+ ...spec,
1248
+ left,
1249
+ speed,
1250
+ cssEase
1251
+ });
1252
+ }
1253
+ return getTrackCSS({
1254
+ ...spec,
1255
+ left
1256
+ });
1257
+ },
1258
+ [spec, speed, cssEase]
1259
+ );
1260
+ const trackStyle = useMemo3(() => {
1261
+ if (swipeLeft !== null) {
1262
+ return getTrackCSS({
1263
+ ...spec,
1264
+ left: swipeLeft
1265
+ });
1266
+ }
1267
+ const left = getTrackLeft({
1268
+ ...spec,
1269
+ slideIndex: currentSlide
1270
+ });
1271
+ if (animating) {
1272
+ return getTrackAnimateCSS({
1273
+ ...spec,
1274
+ left,
1275
+ speed,
1276
+ cssEase
1277
+ });
1278
+ }
1279
+ return getTrackCSS({
1280
+ ...spec,
1281
+ left
1282
+ });
1283
+ }, [spec, currentSlide, animating, swipeLeft, speed, cssEase]);
1284
+ return {
1285
+ slideWidth: calculatedSlideWidth,
1286
+ trackStyle,
1287
+ preCloneCount,
1288
+ postCloneCount,
1289
+ totalSlides,
1290
+ getTrackStyleForSlide,
1291
+ trackWidth
1292
+ };
1293
+ }
1294
+
1295
+ // src/index.tsx
1296
+ import { jsx as jsx4, jsxs } from "react/jsx-runtime";
1297
+ var createInitialState = (props) => ({
1298
+ animating: false,
1299
+ autoplaying: props.autoplay ? "playing" : null,
1300
+ currentDirection: 0,
1301
+ currentLeft: null,
1302
+ currentSlide: props.initialSlide || 0,
1303
+ direction: 1,
1304
+ dragging: false,
1305
+ edgeDragged: false,
1306
+ initialized: false,
1307
+ lazyLoadedList: props.lazyLoad ? [props.initialSlide || 0] : [],
1308
+ listHeight: null,
1309
+ listWidth: null,
1310
+ scrolling: false,
1311
+ slideCount: 0,
1312
+ slideHeight: null,
1313
+ slideWidth: null,
1314
+ swipeLeft: null,
1315
+ swiped: false,
1316
+ swiping: false,
1317
+ touchObject: { startX: 0, startY: 0, curX: 0, curY: 0 },
1318
+ trackStyle: {},
1319
+ trackWidth: 0,
1320
+ targetSlide: props.initialSlide || 0
1321
+ });
1322
+ var glideReducer = (state, action) => {
1323
+ switch (action.type) {
1324
+ case "INIT":
1325
+ return { ...state, ...action.payload, initialized: true };
1326
+ case "SET_DIMENSIONS":
1327
+ return { ...state, ...action.payload };
1328
+ case "GO_TO_SLIDE":
1329
+ return {
1330
+ ...state,
1331
+ currentSlide: action.payload.slide,
1332
+ targetSlide: action.payload.slide,
1333
+ animating: action.payload.animated !== false
1334
+ };
1335
+ case "NEXT":
1336
+ case "PREV":
1337
+ return state;
1338
+ // Handled externally
1339
+ case "SET_TRACK_STYLE":
1340
+ return { ...state, trackStyle: action.payload };
1341
+ case "SWIPE_START":
1342
+ return {
1343
+ ...state,
1344
+ dragging: true,
1345
+ touchObject: action.payload
1346
+ };
1347
+ case "SWIPE_MOVE":
1348
+ return {
1349
+ ...state,
1350
+ touchObject: action.payload.touchObject,
1351
+ swipeLeft: action.payload.swipeLeft,
1352
+ trackStyle: action.payload.trackStyle,
1353
+ swiping: action.payload.swiping ?? state.swiping
1354
+ };
1355
+ case "SWIPE_END":
1356
+ return { ...state, ...action.payload };
1357
+ case "ANIMATION_END":
1358
+ return { ...state, animating: false };
1359
+ case "SET_AUTOPLAY":
1360
+ return { ...state, autoplaying: action.payload };
1361
+ case "UPDATE":
1362
+ return { ...state, ...action.payload };
1363
+ default:
1364
+ return state;
1365
+ }
1366
+ };
1367
+ var Glide = forwardRef2(function Glide2(props, ref) {
1368
+ const settings = {
1369
+ ...defaultSettings,
1370
+ ...props
1371
+ };
1372
+ const {
1373
+ accessibility,
1374
+ adaptiveHeight,
1375
+ arrows,
1376
+ autoplay,
1377
+ autoplaySpeed,
1378
+ centerMode,
1379
+ centerPadding,
1380
+ className,
1381
+ cssEase,
1382
+ dots,
1383
+ dotsClass,
1384
+ draggable,
1385
+ fade,
1386
+ focusOnSelect,
1387
+ infinite,
1388
+ initialSlide,
1389
+ lazyLoad,
1390
+ pauseOnDotsHover,
1391
+ pauseOnFocus,
1392
+ pauseOnHover,
1393
+ rtl,
1394
+ slidesToScroll,
1395
+ slidesToShow,
1396
+ speed,
1397
+ swipe,
1398
+ swipeToSlide,
1399
+ touchMove,
1400
+ touchThreshold,
1401
+ useCSS,
1402
+ useTransform,
1403
+ variableWidth,
1404
+ vertical,
1405
+ verticalSwiping,
1406
+ waitForAnimate,
1407
+ disabled,
1408
+ children,
1409
+ afterChange,
1410
+ beforeChange,
1411
+ appendDots,
1412
+ customPaging,
1413
+ nextArrow,
1414
+ prevArrow,
1415
+ onEdge,
1416
+ onInit,
1417
+ onReInit,
1418
+ onSwipe,
1419
+ swipeEvent
1420
+ } = settings;
1421
+ const listRef = useRef(null);
1422
+ const trackRef = useRef(null);
1423
+ const autoplayTimerRef = useRef(null);
1424
+ const animationEndTimeoutRef = useRef(null);
1425
+ const resizeObserverRef = useRef(null);
1426
+ const [state, dispatch] = useReducer(glideReducer, props, createInitialState);
1427
+ const {
1428
+ initialized,
1429
+ currentSlide,
1430
+ targetSlide,
1431
+ animating,
1432
+ dragging,
1433
+ swiping,
1434
+ swipeLeft,
1435
+ touchObject,
1436
+ listWidth,
1437
+ listHeight,
1438
+ slideWidth,
1439
+ slideHeight,
1440
+ lazyLoadedList,
1441
+ autoplaying,
1442
+ edgeDragged,
1443
+ swiped,
1444
+ scrolling
1445
+ } = state;
1446
+ const slideCount = Children2.count(children);
1447
+ const {
1448
+ slideWidth: calculatedSlideWidth,
1449
+ trackStyle,
1450
+ preCloneCount,
1451
+ postCloneCount,
1452
+ totalSlides,
1453
+ getTrackStyleForSlide,
1454
+ trackWidth
1455
+ } = useTrack({
1456
+ currentSlide,
1457
+ slideCount,
1458
+ slidesToShow,
1459
+ slidesToScroll,
1460
+ infinite,
1461
+ centerMode,
1462
+ centerPadding,
1463
+ listWidth: listWidth || 0,
1464
+ listHeight: listHeight || 0,
1465
+ slideWidth: slideWidth ?? void 0,
1466
+ slideHeight: slideHeight || 0,
1467
+ fade,
1468
+ vertical,
1469
+ variableWidth,
1470
+ useTransform,
1471
+ disabled,
1472
+ speed,
1473
+ cssEase,
1474
+ rtl,
1475
+ animating,
1476
+ swipeLeft
1477
+ });
1478
+ useEffect(() => {
1479
+ if (!canUseDOM() || !listRef.current) return;
1480
+ const updateDimensions = () => {
1481
+ if (!listRef.current) return;
1482
+ const newListWidth = getWidth(listRef.current);
1483
+ const newListHeight = getHeight(listRef.current);
1484
+ const firstSlide = listRef.current.querySelector('[data-index="0"]');
1485
+ const newSlideHeight = firstSlide ? getHeight(firstSlide) : null;
1486
+ dispatch({
1487
+ type: "INIT",
1488
+ payload: {
1489
+ listWidth: newListWidth,
1490
+ listHeight: newListHeight,
1491
+ slideHeight: newSlideHeight,
1492
+ slideCount
1493
+ }
1494
+ });
1495
+ };
1496
+ updateDimensions();
1497
+ resizeObserverRef.current = new ResizeObserver(updateDimensions);
1498
+ resizeObserverRef.current.observe(listRef.current);
1499
+ onInit?.();
1500
+ return () => {
1501
+ resizeObserverRef.current?.disconnect();
1502
+ };
1503
+ }, [slideCount, onInit]);
1504
+ const autoplayIterator = useCallback3(() => {
1505
+ if (autoplaying !== "playing") return;
1506
+ const nextSlideIndex = currentSlide + slidesToScroll;
1507
+ goToSlide(nextSlideIndex);
1508
+ }, [autoplaying, currentSlide, slidesToScroll]);
1509
+ useEffect(() => {
1510
+ if (!autoplay || !initialized) return;
1511
+ if (autoplaying === "playing") {
1512
+ autoplayTimerRef.current = setTimeout(autoplayIterator, autoplaySpeed);
1513
+ }
1514
+ return () => {
1515
+ if (autoplayTimerRef.current) {
1516
+ clearTimeout(autoplayTimerRef.current);
1517
+ }
1518
+ };
1519
+ }, [autoplay, autoplaying, initialized, autoplayIterator, autoplaySpeed]);
1520
+ useEffect(() => {
1521
+ if (animating) {
1522
+ animationEndTimeoutRef.current = setTimeout(() => {
1523
+ dispatch({ type: "ANIMATION_END" });
1524
+ afterChange?.(currentSlide);
1525
+ }, speed);
1526
+ }
1527
+ return () => {
1528
+ if (animationEndTimeoutRef.current) {
1529
+ clearTimeout(animationEndTimeoutRef.current);
1530
+ }
1531
+ };
1532
+ }, [animating, speed, afterChange, currentSlide]);
1533
+ const goToSlide = useCallback3(
1534
+ (slideIndex, dontAnimate = false) => {
1535
+ if (waitForAnimate && animating) return;
1536
+ let targetIndex = slideIndex;
1537
+ if (infinite) {
1538
+ if (targetIndex < 0) {
1539
+ targetIndex = slideCount + targetIndex;
1540
+ } else if (targetIndex >= slideCount) {
1541
+ targetIndex = targetIndex - slideCount;
1542
+ }
1543
+ } else {
1544
+ targetIndex = clamp(targetIndex, 0, slideCount - slidesToShow);
1545
+ }
1546
+ beforeChange?.(currentSlide, targetIndex);
1547
+ if (lazyLoad) {
1548
+ const slidesToLoad = getOnDemandLazySlides({
1549
+ currentSlide: targetIndex,
1550
+ centerMode,
1551
+ slidesToShow,
1552
+ centerPadding,
1553
+ lazyLoadedList
1554
+ });
1555
+ if (slidesToLoad.length > 0) {
1556
+ dispatch({
1557
+ type: "UPDATE",
1558
+ payload: { lazyLoadedList: [...lazyLoadedList, ...slidesToLoad] }
1559
+ });
1560
+ }
1561
+ }
1562
+ dispatch({
1563
+ type: "GO_TO_SLIDE",
1564
+ payload: { slide: targetIndex, animated: !dontAnimate }
1565
+ });
1566
+ },
1567
+ [
1568
+ waitForAnimate,
1569
+ animating,
1570
+ infinite,
1571
+ slideCount,
1572
+ slidesToShow,
1573
+ beforeChange,
1574
+ currentSlide,
1575
+ lazyLoad,
1576
+ centerMode,
1577
+ centerPadding,
1578
+ lazyLoadedList
1579
+ ]
1580
+ );
1581
+ const next = useCallback3(() => {
1582
+ goToSlide(currentSlide + slidesToScroll);
1583
+ }, [currentSlide, slidesToScroll, goToSlide]);
1584
+ const prev = useCallback3(() => {
1585
+ goToSlide(currentSlide - slidesToScroll);
1586
+ }, [currentSlide, slidesToScroll, goToSlide]);
1587
+ const goTo = useCallback3(
1588
+ (index, dontAnimate = false) => {
1589
+ goToSlide(index, dontAnimate);
1590
+ },
1591
+ [goToSlide]
1592
+ );
1593
+ const pause = useCallback3(() => {
1594
+ dispatch({ type: "SET_AUTOPLAY", payload: "paused" });
1595
+ }, []);
1596
+ const play = useCallback3(() => {
1597
+ dispatch({ type: "SET_AUTOPLAY", payload: "playing" });
1598
+ }, []);
1599
+ useImperativeHandle(
1600
+ ref,
1601
+ () => ({
1602
+ prev,
1603
+ next,
1604
+ goTo,
1605
+ pause,
1606
+ play,
1607
+ innerSlider: { state: { currentSlide } }
1608
+ }),
1609
+ [prev, next, goTo, pause, play, currentSlide]
1610
+ );
1611
+ const handleKeyDown = useCallback3(
1612
+ (e) => {
1613
+ const action = keyHandler(e, accessibility, rtl);
1614
+ if (action === "next") {
1615
+ next();
1616
+ } else if (action === "previous") {
1617
+ prev();
1618
+ }
1619
+ },
1620
+ [accessibility, rtl, next, prev]
1621
+ );
1622
+ const handleSwipeStart = useCallback3(
1623
+ (e) => {
1624
+ const result = swipeStart(e, swipe, draggable);
1625
+ if (result) {
1626
+ dispatch({ type: "SWIPE_START", payload: result.touchObject });
1627
+ }
1628
+ },
1629
+ [swipe, draggable]
1630
+ );
1631
+ const handleSwipeMove = useCallback3(
1632
+ (e) => {
1633
+ if (!dragging) return;
1634
+ const result = swipeMove(e, {
1635
+ scrolling,
1636
+ animating,
1637
+ vertical,
1638
+ swipeToSlide,
1639
+ verticalSwiping,
1640
+ rtl,
1641
+ currentSlide,
1642
+ edgeFriction: settings.edgeFriction,
1643
+ edgeDragged,
1644
+ onEdge,
1645
+ swiped,
1646
+ swiping,
1647
+ slideCount,
1648
+ slidesToScroll,
1649
+ infinite,
1650
+ touchObject,
1651
+ swipeEvent,
1652
+ listHeight: listHeight || 0,
1653
+ listWidth: listWidth || 0,
1654
+ slideWidth: calculatedSlideWidth,
1655
+ slideHeight: slideHeight || 0,
1656
+ centerMode,
1657
+ slidesToShow,
1658
+ fade,
1659
+ disabled,
1660
+ variableWidth,
1661
+ useTransform
1662
+ });
1663
+ if (result && "scrolling" in result && result.scrolling) {
1664
+ dispatch({ type: "UPDATE", payload: { scrolling: true } });
1665
+ } else if (result && "swipeLeft" in result) {
1666
+ dispatch({ type: "SWIPE_MOVE", payload: result });
1667
+ }
1668
+ },
1669
+ [
1670
+ dragging,
1671
+ scrolling,
1672
+ animating,
1673
+ vertical,
1674
+ swipeToSlide,
1675
+ verticalSwiping,
1676
+ rtl,
1677
+ currentSlide,
1678
+ settings.edgeFriction,
1679
+ edgeDragged,
1680
+ onEdge,
1681
+ swiped,
1682
+ swiping,
1683
+ slideCount,
1684
+ slidesToScroll,
1685
+ infinite,
1686
+ touchObject,
1687
+ swipeEvent,
1688
+ listHeight,
1689
+ listWidth,
1690
+ calculatedSlideWidth,
1691
+ slideHeight,
1692
+ centerMode,
1693
+ slidesToShow,
1694
+ fade,
1695
+ disabled,
1696
+ variableWidth,
1697
+ useTransform
1698
+ ]
1699
+ );
1700
+ const handleSwipeEnd = useCallback3(
1701
+ (e) => {
1702
+ const result = swipeEnd(e, {
1703
+ dragging,
1704
+ swipe,
1705
+ touchObject,
1706
+ listWidth: listWidth || 0,
1707
+ touchThreshold,
1708
+ verticalSwiping,
1709
+ listHeight: listHeight || 0,
1710
+ swipeToSlide,
1711
+ scrolling,
1712
+ onSwipe,
1713
+ targetSlide,
1714
+ currentSlide,
1715
+ infinite,
1716
+ slideCount,
1717
+ slidesToScroll,
1718
+ slidesToShow,
1719
+ slideWidth: calculatedSlideWidth,
1720
+ slideHeight: slideHeight || 0,
1721
+ centerMode,
1722
+ fade,
1723
+ disabled,
1724
+ variableWidth,
1725
+ useTransform,
1726
+ speed,
1727
+ cssEase,
1728
+ rtl,
1729
+ vertical
1730
+ });
1731
+ dispatch({
1732
+ type: "SWIPE_END",
1733
+ payload: {
1734
+ dragging: result.dragging,
1735
+ edgeDragged: result.edgeDragged,
1736
+ scrolling: result.scrolling,
1737
+ swiping: result.swiping,
1738
+ swiped: result.swiped,
1739
+ swipeLeft: result.swipeLeft,
1740
+ touchObject: result.touchObject
1741
+ }
1742
+ });
1743
+ if (result.triggerSlideHandler !== void 0) {
1744
+ goToSlide(result.triggerSlideHandler);
1745
+ } else if (result.trackStyle) {
1746
+ dispatch({ type: "SET_TRACK_STYLE", payload: result.trackStyle });
1747
+ }
1748
+ },
1749
+ [
1750
+ dragging,
1751
+ swipe,
1752
+ touchObject,
1753
+ listWidth,
1754
+ touchThreshold,
1755
+ verticalSwiping,
1756
+ listHeight,
1757
+ swipeToSlide,
1758
+ scrolling,
1759
+ onSwipe,
1760
+ targetSlide,
1761
+ currentSlide,
1762
+ infinite,
1763
+ slideCount,
1764
+ slidesToScroll,
1765
+ slidesToShow,
1766
+ calculatedSlideWidth,
1767
+ slideHeight,
1768
+ centerMode,
1769
+ fade,
1770
+ disabled,
1771
+ variableWidth,
1772
+ useTransform,
1773
+ speed,
1774
+ cssEase,
1775
+ rtl,
1776
+ vertical,
1777
+ goToSlide
1778
+ ]
1779
+ );
1780
+ const handleMouseEnter = useCallback3(() => {
1781
+ if (autoplay && pauseOnHover) {
1782
+ dispatch({ type: "SET_AUTOPLAY", payload: "hovered" });
1783
+ }
1784
+ }, [autoplay, pauseOnHover]);
1785
+ const handleMouseLeave = useCallback3(() => {
1786
+ if (autoplay && pauseOnHover && autoplaying === "hovered") {
1787
+ dispatch({ type: "SET_AUTOPLAY", payload: "playing" });
1788
+ }
1789
+ }, [autoplay, pauseOnHover, autoplaying]);
1790
+ const handleFocus = useCallback3(() => {
1791
+ if (autoplay && pauseOnFocus) {
1792
+ dispatch({ type: "SET_AUTOPLAY", payload: "focused" });
1793
+ }
1794
+ }, [autoplay, pauseOnFocus]);
1795
+ const handleBlur = useCallback3(() => {
1796
+ if (autoplay && pauseOnFocus && autoplaying === "focused") {
1797
+ dispatch({ type: "SET_AUTOPLAY", payload: "playing" });
1798
+ }
1799
+ }, [autoplay, pauseOnFocus, autoplaying]);
1800
+ const handleDotClick = useCallback3(
1801
+ (index) => {
1802
+ goToSlide(index);
1803
+ },
1804
+ [goToSlide]
1805
+ );
1806
+ const handleDotMouseEnter = useCallback3(() => {
1807
+ if (autoplay && pauseOnDotsHover) {
1808
+ dispatch({ type: "SET_AUTOPLAY", payload: "hovered" });
1809
+ }
1810
+ }, [autoplay, pauseOnDotsHover]);
1811
+ const handleDotMouseLeave = useCallback3(() => {
1812
+ if (autoplay && pauseOnDotsHover && autoplaying === "hovered") {
1813
+ dispatch({ type: "SET_AUTOPLAY", payload: "playing" });
1814
+ }
1815
+ }, [autoplay, pauseOnDotsHover, autoplaying]);
1816
+ const handleSlideClick = useCallback3(
1817
+ (index) => {
1818
+ if (focusOnSelect) {
1819
+ goToSlide(index);
1820
+ }
1821
+ },
1822
+ [focusOnSelect, goToSlide]
1823
+ );
1824
+ const sliderStyle = useMemo4(
1825
+ () => ({
1826
+ position: "relative",
1827
+ display: "block",
1828
+ boxSizing: "border-box",
1829
+ userSelect: "none",
1830
+ touchAction: vertical ? "pan-x" : "pan-y",
1831
+ WebkitTapHighlightColor: "transparent"
1832
+ }),
1833
+ [vertical]
1834
+ );
1835
+ const listStyle = useMemo4(
1836
+ () => ({
1837
+ position: "relative",
1838
+ display: "block",
1839
+ overflow: "hidden",
1840
+ margin: 0,
1841
+ padding: 0
1842
+ }),
1843
+ []
1844
+ );
1845
+ if (!initialized || !canUseDOM()) {
1846
+ return /* @__PURE__ */ jsx4("div", { className: `glide-slider ${className}`.trim(), style: sliderStyle, children: /* @__PURE__ */ jsx4("div", { className: "glide-list", style: listStyle, children: /* @__PURE__ */ jsx4("div", { className: "glide-track", style: { display: "flex" }, children: React4.Children.map(children, (child, idx) => /* @__PURE__ */ jsx4(
1847
+ "div",
1848
+ {
1849
+ className: "glide-slide",
1850
+ style: {
1851
+ width: `${100 / slidesToShow}%`,
1852
+ flexShrink: 0
1853
+ },
1854
+ children: child
1855
+ },
1856
+ idx
1857
+ )) }) }) });
1858
+ }
1859
+ return /* @__PURE__ */ jsxs(
1860
+ "div",
1861
+ {
1862
+ className: `glide-slider ${className} ${vertical ? "glide-vertical" : ""}`.trim(),
1863
+ style: sliderStyle,
1864
+ onKeyDown: handleKeyDown,
1865
+ tabIndex: accessibility ? 0 : void 0,
1866
+ onFocus: handleFocus,
1867
+ onBlur: handleBlur,
1868
+ children: [
1869
+ arrows && !disabled && /* @__PURE__ */ jsx4(
1870
+ PrevArrow,
1871
+ {
1872
+ currentSlide,
1873
+ slideCount,
1874
+ slidesToShow,
1875
+ infinite,
1876
+ centerMode,
1877
+ onClick: prev,
1878
+ customArrow: prevArrow
1879
+ }
1880
+ ),
1881
+ /* @__PURE__ */ jsx4(
1882
+ "div",
1883
+ {
1884
+ ref: listRef,
1885
+ className: "glide-list",
1886
+ style: listStyle,
1887
+ onMouseDown: touchMove ? handleSwipeStart : void 0,
1888
+ onMouseMove: touchMove && dragging ? handleSwipeMove : void 0,
1889
+ onMouseUp: touchMove ? handleSwipeEnd : void 0,
1890
+ onMouseLeave: touchMove && dragging ? handleSwipeEnd : handleMouseLeave,
1891
+ onMouseEnter: handleMouseEnter,
1892
+ onTouchStart: swipe ? handleSwipeStart : void 0,
1893
+ onTouchMove: swipe && dragging ? handleSwipeMove : void 0,
1894
+ onTouchEnd: swipe ? handleSwipeEnd : void 0,
1895
+ onTouchCancel: swipe && dragging ? handleSwipeEnd : void 0,
1896
+ children: /* @__PURE__ */ jsx4(
1897
+ Track,
1898
+ {
1899
+ ref: trackRef,
1900
+ trackStyle,
1901
+ slideWidth: calculatedSlideWidth,
1902
+ slideHeight: slideHeight || void 0,
1903
+ slideCount,
1904
+ currentSlide,
1905
+ targetSlide,
1906
+ slidesToShow,
1907
+ slidesToScroll,
1908
+ infinite,
1909
+ centerMode,
1910
+ centerPadding,
1911
+ fade,
1912
+ vertical,
1913
+ variableWidth,
1914
+ rtl,
1915
+ disabled,
1916
+ lazyLoad,
1917
+ lazyLoadedList,
1918
+ speed,
1919
+ cssEase,
1920
+ useCSS,
1921
+ focusOnSelect,
1922
+ onSlideClick: handleSlideClick,
1923
+ children
1924
+ }
1925
+ )
1926
+ }
1927
+ ),
1928
+ arrows && !disabled && /* @__PURE__ */ jsx4(
1929
+ NextArrow,
1930
+ {
1931
+ currentSlide,
1932
+ slideCount,
1933
+ slidesToShow,
1934
+ infinite,
1935
+ centerMode,
1936
+ onClick: next,
1937
+ customArrow: nextArrow
1938
+ }
1939
+ ),
1940
+ dots && !disabled && /* @__PURE__ */ jsx4(
1941
+ Dots,
1942
+ {
1943
+ slideCount,
1944
+ slidesToScroll,
1945
+ slidesToShow,
1946
+ currentSlide,
1947
+ infinite,
1948
+ onDotClick: handleDotClick,
1949
+ customPaging,
1950
+ appendDots,
1951
+ dotsClass,
1952
+ onMouseEnter: handleDotMouseEnter,
1953
+ onMouseLeave: handleDotMouseLeave
1954
+ }
1955
+ )
1956
+ ]
1957
+ }
1958
+ );
1959
+ });
1960
+ var index_default = Glide;
1961
+ export {
1962
+ Dots,
1963
+ Glide,
1964
+ NextArrow,
1965
+ PrevArrow,
1966
+ Track,
1967
+ calculateSlideWidth,
1968
+ canGoNext,
1969
+ canGoPrev,
1970
+ canUseDOM,
1971
+ clamp,
1972
+ index_default as default,
1973
+ getHeight,
1974
+ getOnDemandLazySlides,
1975
+ getPostClones,
1976
+ getPreClones,
1977
+ getSlideClasses,
1978
+ getSwipeDirection,
1979
+ getTotalSlides,
1980
+ getTrackAnimateCSS,
1981
+ getTrackCSS,
1982
+ getTrackLeft,
1983
+ getWidth,
1984
+ keyHandler,
1985
+ lazyEndIndex,
1986
+ lazySlidesOnLeft,
1987
+ lazySlidesOnRight,
1988
+ lazyStartIndex,
1989
+ safePreventDefault,
1990
+ swipeEnd,
1991
+ swipeMove,
1992
+ swipeStart,
1993
+ useTrack
1994
+ };