@preline/carousel 2.4.1 → 2.5.2

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.
Files changed (3) hide show
  1. package/index.d.ts +91 -11
  2. package/index.js +6 -7
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -16,13 +16,24 @@ export interface ICollectionItem<T> {
16
16
  id: string | number;
17
17
  element: T;
18
18
  }
19
+ export type TCarouselOptionsSlidesQty = {
20
+ [key: string]: number;
21
+ };
19
22
  export interface ICarouselOptions {
20
23
  currentIndex: number;
21
24
  loadingClasses?: string | string[];
25
+ dotsItemClasses?: string;
26
+ isAutoHeight?: boolean;
22
27
  isAutoPlay?: boolean;
23
- speed?: number;
28
+ isCentered?: boolean;
29
+ isDraggable?: boolean;
24
30
  isInfiniteLoop?: boolean;
25
31
  isRTL?: boolean;
32
+ isSnap?: boolean;
33
+ hasSnapSpacers?: boolean;
34
+ slidesQty?: TCarouselOptionsSlidesQty | number;
35
+ speed?: number;
36
+ updateDelay?: number;
26
37
  }
27
38
  export interface ICarousel {
28
39
  options?: ICarouselOptions;
@@ -30,40 +41,109 @@ export interface ICarousel {
30
41
  goToPrev(): void;
31
42
  goToNext(): void;
32
43
  goTo(i: number): void;
44
+ destroy(): void;
33
45
  }
34
46
  declare class HSCarousel extends HSBasePlugin<ICarouselOptions> implements ICarousel {
47
+ private currentIndex;
48
+ private readonly loadingClasses;
49
+ private readonly dotsItemClasses;
50
+ private readonly isAutoHeight;
51
+ private readonly isAutoPlay;
52
+ private readonly isCentered;
53
+ private readonly isDraggable;
54
+ private readonly isInfiniteLoop;
55
+ private readonly isRTL;
56
+ private readonly isSnap;
57
+ private readonly hasSnapSpacers;
58
+ private readonly slidesQty;
59
+ private readonly speed;
60
+ private readonly updateDelay;
61
+ private readonly loadingClassesRemove;
62
+ private readonly loadingClassesAdd;
63
+ private readonly afterLoadingClassesAdd;
64
+ private readonly container;
35
65
  private readonly inner;
36
66
  private readonly slides;
37
67
  private readonly prev;
38
68
  private readonly next;
39
69
  private readonly dots;
70
+ private dotsItems;
71
+ private readonly info;
72
+ private readonly infoTotal;
73
+ private readonly infoCurrent;
40
74
  private sliderWidth;
41
- private currentIndex;
42
- private readonly loadingClasses;
43
- private readonly loadingClassesRemove;
44
- private readonly loadingClassesAdd;
45
- private readonly afterLoadingClassesAdd;
46
- private readonly isAutoPlay;
47
- private readonly isRTL;
48
- private readonly speed;
49
- private readonly isInfiniteLoop;
50
75
  private timer;
76
+ private isScrolling;
77
+ private isDragging;
78
+ private dragStartX;
79
+ private initialTranslateX;
51
80
  private readonly touchX;
81
+ private resizeContainer;
82
+ resizeContainerWidth: number;
83
+ private onPrevClickListener;
84
+ private onNextClickListener;
85
+ private onContainerScrollListener;
86
+ private onElementTouchStartListener;
87
+ private onElementTouchEndListener;
88
+ private onInnerMouseDownListener;
89
+ private onInnerTouchStartListener;
90
+ private onDocumentMouseMoveListener;
91
+ private onDocumentTouchMoveListener;
92
+ private onDocumentMouseUpListener;
93
+ private onDocumentTouchEndListener;
94
+ private onDotClickListener;
52
95
  constructor(el: HTMLElement, options?: ICarouselOptions);
96
+ private setIsSnap;
97
+ private prevClick;
98
+ private nextClick;
99
+ private containerScroll;
100
+ private elementTouchStart;
101
+ private elementTouchEnd;
102
+ private innerMouseDown;
103
+ private innerTouchStart;
104
+ private documentMouseMove;
105
+ private documentTouchMove;
106
+ private documentMouseUp;
107
+ private documentTouchEnd;
108
+ private dotClick;
53
109
  private init;
110
+ private initDragHandling;
111
+ private getTranslateXValue;
112
+ private removeClickEventWhileDragging;
113
+ private handleDragStart;
114
+ private handleDragMove;
115
+ private handleDragEnd;
116
+ private getEventX;
117
+ private getCurrentSlidesQty;
118
+ private buildSnapSpacers;
119
+ private initDots;
120
+ private buildDots;
121
+ private setDots;
122
+ private goToCurrentDot;
123
+ private buildInfo;
124
+ private setInfoTotal;
125
+ private setInfoCurrent;
126
+ private buildSingleDot;
127
+ private singleDotEvents;
54
128
  private observeResize;
55
129
  private calculateWidth;
56
130
  private addCurrentClass;
131
+ private setCurrentDot;
132
+ private setElementToDisabled;
133
+ private unsetElementToDisabled;
57
134
  private addDisabledClass;
58
135
  private autoPlay;
59
136
  private setTimer;
60
137
  private resetTimer;
61
138
  private detectDirection;
62
- recalculateWidth(): void;
63
139
  private calculateTransform;
140
+ private setTranslate;
141
+ private setIndex;
142
+ recalculateWidth(): void;
64
143
  goToPrev(): void;
65
144
  goToNext(): void;
66
145
  goTo(i: number): void;
146
+ destroy(): void;
67
147
  static getInstance(target: HTMLElement | string, isInstance?: boolean): HSCarousel | ICollectionItem<HSCarousel>;
68
148
  static autoInit(): void;
69
149
  }
package/index.js CHANGED
@@ -1,17 +1,16 @@
1
- !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var s=e();for(var i in s)("object"==typeof exports?exports:t)[i]=s[i]}}(self,(()=>(()=>{"use strict";var t={961:(t,e)=>{
1
+ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var i=e();for(var n in i)("object"==typeof exports?exports:t)[n]=i[n]}}(self,(()=>(()=>{"use strict";var t={223:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BREAKPOINTS=e.COMBO_BOX_ACCESSIBILITY_KEY_SET=e.SELECT_ACCESSIBILITY_KEY_SET=e.TABS_ACCESSIBILITY_KEY_SET=e.OVERLAY_ACCESSIBILITY_KEY_SET=e.DROPDOWN_ACCESSIBILITY_KEY_SET=e.POSITIONS=void 0,e.POSITIONS={auto:"auto","auto-start":"auto-start","auto-end":"auto-end",top:"top","top-left":"top-start","top-right":"top-end",bottom:"bottom","bottom-left":"bottom-start","bottom-right":"bottom-end",right:"right","right-start":"right-start","right-end":"right-end",left:"left","left-start":"left-start","left-end":"left-end"},e.DROPDOWN_ACCESSIBILITY_KEY_SET=["Escape","ArrowUp","ArrowDown","ArrowRight","ArrowLeft","Home","End","Enter"],e.OVERLAY_ACCESSIBILITY_KEY_SET=["Escape","Tab"],e.TABS_ACCESSIBILITY_KEY_SET=["ArrowUp","ArrowLeft","ArrowDown","ArrowRight","Home","End"],e.SELECT_ACCESSIBILITY_KEY_SET=["ArrowUp","ArrowLeft","ArrowDown","ArrowRight","Home","End","Escape","Enter","Space","Tab"],e.COMBO_BOX_ACCESSIBILITY_KEY_SET=["ArrowUp","ArrowLeft","ArrowDown","ArrowRight","Home","End","Escape","Enter"],e.BREAKPOINTS={xs:0,sm:640,md:768,lg:1024,xl:1280,"2xl":1536}},961:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function t(t,e,i){this.el=t,this.options=e,this.events=i,this.el=t,this.options=e,this.events={}}return t.prototype.createCollection=function(t,e){var i;t.push({id:(null===(i=null==e?void 0:e.el)||void 0===i?void 0:i.id)||t.length+1,element:e})},t.prototype.fireEvent=function(t,e){if(void 0===e&&(e=null),this.events.hasOwnProperty(t))return this.events[t](e)},t.prototype.on=function(t,e){this.events[t]=e},t}();e.default=i},268:function(t,e,i){
2
2
  /*
3
- * HSBasePlugin
4
- * @version: 2.4.1
3
+ * HSCarousel
4
+ * @version: 2.7.0
5
5
  * @author: Preline Labs Ltd.
6
6
  * @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
7
7
  * Copyright 2024 Preline Labs Ltd.
8
8
  */
9
- Object.defineProperty(e,"__esModule",{value:!0});var s=function(){function t(t,e,s){this.el=t,this.options=e,this.events=s,this.el=t,this.options=e,this.events={}}return t.prototype.createCollection=function(t,e){var s;t.push({id:(null===(s=null==e?void 0:e.el)||void 0===s?void 0:s.id)||t.length+1,element:e})},t.prototype.fireEvent=function(t,e){if(void 0===e&&(e=null),this.events.hasOwnProperty(t))return this.events[t](e)},t.prototype.on=function(t,e){this.events[t]=e},t}();e.default=s},268:function(t,e,s){
9
+ var n,s=this&&this.__extends||(n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},n(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}),r=this&&this.__assign||function(){return r=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var s in e=arguments[i])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t},r.apply(this,arguments)},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var l=i(292),a=o(i(961)),h=i(223),d=function(t){function e(e,i){var n,s,o,l,a,h=t.call(this,e,i)||this,d=e.getAttribute("data-hs-carousel"),c=d?JSON.parse(d):{},u=r(r({},c),i);return h.currentIndex=u.currentIndex||0,h.loadingClasses=u.loadingClasses?"".concat(u.loadingClasses).split(","):null,h.dotsItemClasses=u.dotsItemClasses?u.dotsItemClasses:null,h.isAutoHeight=void 0!==u.isAutoHeight&&u.isAutoHeight,h.isAutoPlay=void 0!==u.isAutoPlay&&u.isAutoPlay,h.isCentered=void 0!==u.isCentered&&u.isCentered,h.isDraggable=void 0!==u.isDraggable&&u.isDraggable,h.isInfiniteLoop=void 0!==u.isInfiniteLoop&&u.isInfiniteLoop,h.isRTL=void 0!==u.isRTL&&u.isRTL,h.isSnap=void 0!==u.isSnap&&u.isSnap,h.hasSnapSpacers=void 0===u.hasSnapSpacers||u.hasSnapSpacers,h.speed=u.speed||4e3,h.updateDelay=u.updateDelay||0,h.slidesQty=u.slidesQty||1,h.loadingClassesRemove=(null===(n=h.loadingClasses)||void 0===n?void 0:n[0])?h.loadingClasses[0].split(" "):"opacity-0",h.loadingClassesAdd=(null===(s=h.loadingClasses)||void 0===s?void 0:s[1])?h.loadingClasses[1].split(" "):"",h.afterLoadingClassesAdd=(null===(o=h.loadingClasses)||void 0===o?void 0:o[2])?h.loadingClasses[2].split(" "):"",h.container=h.el.querySelector(".hs-carousel")||null,h.inner=h.el.querySelector(".hs-carousel-body")||null,h.slides=h.el.querySelectorAll(".hs-carousel-slide")||[],h.prev=h.el.querySelector(".hs-carousel-prev")||null,h.next=h.el.querySelector(".hs-carousel-next")||null,h.dots=h.el.querySelector(".hs-carousel-pagination")||null,h.info=h.el.querySelector(".hs-carousel-info")||null,h.infoTotal=(null===(l=null==h?void 0:h.info)||void 0===l?void 0:l.querySelector(".hs-carousel-info-total"))||null,h.infoCurrent=(null===(a=null==h?void 0:h.info)||void 0===a?void 0:a.querySelector(".hs-carousel-info-current"))||null,h.sliderWidth=h.el.getBoundingClientRect().width,h.isDragging=!1,h.dragStartX=null,h.initialTranslateX=null,h.touchX={start:0,end:0},h.resizeContainer=document.querySelector("body"),h.resizeContainerWidth=0,h.init(),h}return s(e,t),e.prototype.setIsSnap=function(){var t=this,e=this.container.getBoundingClientRect(),i=e.left+e.width/2,n=null,s=null,r=1/0;Array.from(this.inner.children).forEach((function(e){var s=e.getBoundingClientRect(),o=t.inner.getBoundingClientRect(),l=s.left+s.width/2-o.left,a=Math.abs(i-(o.left+l));a<r&&(r=a,n=e)})),n&&(s=Array.from(this.slides).findIndex((function(t){return t===n}))),this.setIndex(s),this.dots&&this.setCurrentDot()},e.prototype.prevClick=function(){this.goToPrev(),this.isAutoPlay&&(this.resetTimer(),this.setTimer())},e.prototype.nextClick=function(){this.goToNext(),this.isAutoPlay&&(this.resetTimer(),this.setTimer())},e.prototype.containerScroll=function(){var t=this;clearTimeout(this.isScrolling),this.isScrolling=setTimeout((function(){t.setIsSnap()}),100)},e.prototype.elementTouchStart=function(t){this.touchX.start=t.changedTouches[0].screenX},e.prototype.elementTouchEnd=function(t){this.touchX.end=t.changedTouches[0].screenX,this.detectDirection()},e.prototype.innerMouseDown=function(t){this.handleDragStart(t)},e.prototype.innerTouchStart=function(t){this.handleDragStart(t)},e.prototype.documentMouseMove=function(t){this.handleDragMove(t)},e.prototype.documentTouchMove=function(t){this.handleDragMove(t)},e.prototype.documentMouseUp=function(){this.handleDragEnd()},e.prototype.documentTouchEnd=function(){this.handleDragEnd()},e.prototype.dotClick=function(t){this.goTo(t),this.isAutoPlay&&(this.resetTimer(),this.setTimer())},e.prototype.init=function(){var t=this;this.createCollection(window.$hsCarouselCollection,this),this.inner&&(this.calculateWidth(),this.isDraggable&&!this.isSnap&&this.initDragHandling()),this.prev&&(this.onPrevClickListener=function(){return t.prevClick()},this.prev.addEventListener("click",this.onPrevClickListener)),this.next&&(this.onNextClickListener=function(){return t.nextClick()},this.next.addEventListener("click",this.onNextClickListener)),this.dots&&this.initDots(),this.info&&this.buildInfo(),this.slides.length&&(this.addCurrentClass(),this.isInfiniteLoop||this.addDisabledClass(),this.isAutoPlay&&this.autoPlay()),setTimeout((function(){var e,i;t.isSnap&&t.setIsSnap(),t.loadingClassesRemove&&("string"==typeof t.loadingClassesRemove?t.inner.classList.remove(t.loadingClassesRemove):(e=t.inner.classList).remove.apply(e,t.loadingClassesRemove)),t.loadingClassesAdd&&("string"==typeof t.loadingClassesAdd?t.inner.classList.add(t.loadingClassesAdd):(i=t.inner.classList).add.apply(i,t.loadingClassesAdd)),t.inner&&t.afterLoadingClassesAdd&&setTimeout((function(){var e;"string"==typeof t.afterLoadingClassesAdd?t.inner.classList.add(t.afterLoadingClassesAdd):(e=t.inner.classList).add.apply(e,t.afterLoadingClassesAdd)}))}),400),this.isSnap&&(this.onContainerScrollListener=function(){return t.containerScroll()},this.container.addEventListener("scroll",this.onContainerScrollListener)),this.el.classList.add("init"),this.isSnap||(this.onElementTouchStartListener=function(e){return t.elementTouchStart(e)},this.onElementTouchEndListener=function(e){return t.elementTouchEnd(e)},this.el.addEventListener("touchstart",this.onElementTouchStartListener),this.el.addEventListener("touchend",this.onElementTouchEndListener)),this.observeResize()},e.prototype.initDragHandling=function(){var t=this,e=this.inner;this.onInnerMouseDownListener=function(e){return t.innerMouseDown(e)},this.onInnerTouchStartListener=function(e){return t.innerTouchStart(e)},this.onDocumentMouseMoveListener=function(e){return t.documentMouseMove(e)},this.onDocumentTouchMoveListener=function(e){return t.documentTouchMove(e)},this.onDocumentMouseUpListener=function(){return t.documentMouseUp()},this.onDocumentTouchEndListener=function(){return t.documentTouchEnd()},e&&(e.addEventListener("mousedown",this.onInnerMouseDownListener),e.addEventListener("touchstart",this.onInnerTouchStartListener,{passive:!0}),document.addEventListener("mousemove",this.onDocumentMouseMoveListener),document.addEventListener("touchmove",this.onDocumentTouchMoveListener,{passive:!1}),document.addEventListener("mouseup",this.onDocumentMouseUpListener),document.addEventListener("touchend",this.onDocumentTouchEndListener))},e.prototype.getTranslateXValue=function(){var t,e=window.getComputedStyle(this.inner).transform;if("none"!==e){var i=null===(t=e.match(/matrix.*\((.+)\)/))||void 0===t?void 0:t[1].split(", ");if(i){var n=parseFloat(6===i.length?i[4]:i[12]);return this.isRTL&&(n=-n),isNaN(n)||0===n?0:-n}}return 0},e.prototype.removeClickEventWhileDragging=function(t){t.preventDefault()},e.prototype.handleDragStart=function(t){t.preventDefault(),this.isDragging=!0,this.dragStartX=this.getEventX(t),this.initialTranslateX=this.isRTL?this.getTranslateXValue():-this.getTranslateXValue(),this.inner.classList.add("dragging")},e.prototype.handleDragMove=function(t){var e=this;if(this.isDragging){this.inner.querySelectorAll("a:not(.prevented-click)").forEach((function(t){t.classList.add("prevented-click"),t.addEventListener("click",e.removeClickEventWhileDragging)}));var i=this.getEventX(t)-this.dragStartX;this.isRTL&&(i=-i);var n=this.initialTranslateX+i;this.setTranslate(function(){var t=e.sliderWidth*e.slides.length/e.getCurrentSlidesQty()-e.sliderWidth,i=e.sliderWidth,s=(i-i/e.getCurrentSlidesQty())/2,r=e.isCentered?s:0;e.isCentered&&(t+=s);var o=-t;return e.isRTL?n<r?r:n>t?o:-n:n>r?r:n<-t?o:n}())}},e.prototype.handleDragEnd=function(){var t=this;if(this.isDragging){this.isDragging=!1;var e=this.sliderWidth/this.getCurrentSlidesQty(),i=this.getTranslateXValue(),n=Math.round(i/e);this.isRTL&&(n=Math.round(i/e)),this.inner.classList.remove("dragging"),setTimeout((function(){t.calculateTransform(n),t.dots&&t.setCurrentDot(),t.dragStartX=null,t.initialTranslateX=null,t.inner.querySelectorAll("a.prevented-click").forEach((function(e){e.classList.remove("prevented-click"),e.removeEventListener("click",t.removeClickEventWhileDragging)}))}))}},e.prototype.getEventX=function(t){return t instanceof MouseEvent?t.clientX:t.touches[0].clientX},e.prototype.getCurrentSlidesQty=function(){var t=this;if("object"==typeof this.slidesQty){var e=document.body.clientWidth,i=0;return Object.keys(this.slidesQty).forEach((function(n){e>=(typeof n+1=="number"?t.slidesQty[n]:h.BREAKPOINTS[n])&&(i=t.slidesQty[n])})),i}return this.slidesQty},e.prototype.buildSnapSpacers=function(){var t=this.inner.querySelector(".hs-snap-before"),e=this.inner.querySelector(".hs-snap-after");t&&t.remove(),e&&e.remove();var i=this.sliderWidth,n=i/2-i/this.getCurrentSlidesQty()/2,s=(0,l.htmlToElement)('<div class="hs-snap-before" style="height: 100%; width: '.concat(n,'px"></div>')),r=(0,l.htmlToElement)('<div class="hs-snap-after" style="height: 100%; width: '.concat(n,'px"></div>'));this.inner.prepend(s),this.inner.appendChild(r)},e.prototype.initDots=function(){this.el.querySelectorAll(".hs-carousel-pagination-item").length?this.setDots():this.buildDots(),this.dots&&this.setCurrentDot()},e.prototype.buildDots=function(){this.dots.innerHTML="";for(var t=!this.isCentered&&this.slidesQty?this.slides.length-(this.getCurrentSlidesQty()-1):this.slides.length,e=0;e<t;e++){var i=this.buildSingleDot(e);this.dots.append(i)}},e.prototype.setDots=function(){var t=this;this.dotsItems=this.dots.querySelectorAll(".hs-carousel-pagination-item"),this.dotsItems.forEach((function(e,i){var n=e.getAttribute("data-carousel-pagination-item-target");t.singleDotEvents(e,n?+n:i)}))},e.prototype.goToCurrentDot=function(){var t=this.dots,e=t.getBoundingClientRect(),i=t.scrollLeft,n=t.scrollTop,s=t.clientWidth,r=t.clientHeight,o=this.dotsItems[this.currentIndex],l=o.getBoundingClientRect(),a=l.left-e.left+i,h=a+o.clientWidth,d=l.top-e.top+n,c=d+o.clientHeight,u=i,p=n;(a<i||h>i+s)&&(u=h-s),(d<n||c>n+r)&&(p=c-r),t.scrollTo({left:u,top:p,behavior:"smooth"})},e.prototype.buildInfo=function(){this.infoTotal&&this.setInfoTotal(),this.infoCurrent&&this.setInfoCurrent()},e.prototype.setInfoTotal=function(){this.infoTotal.innerText="".concat(this.slides.length)},e.prototype.setInfoCurrent=function(){this.infoCurrent.innerText="".concat(this.currentIndex+1)},e.prototype.buildSingleDot=function(t){var e=(0,l.htmlToElement)("<span></span>");return this.dotsItemClasses&&(0,l.classToClassList)(this.dotsItemClasses,e),this.singleDotEvents(e,t),e},e.prototype.singleDotEvents=function(t,e){var i=this;this.onDotClickListener=function(){return i.dotClick(e)},t.addEventListener("click",this.onDotClickListener)},e.prototype.observeResize=function(){var t=this;new ResizeObserver((0,l.debounce)((function(e){for(var i=0,n=e;i<n.length;i++){var s=n[i].contentRect.width;s!==t.resizeContainerWidth&&(t.recalculateWidth(),t.dots&&t.initDots(),t.addCurrentClass(),t.resizeContainerWidth=s)}}),this.updateDelay)).observe(this.resizeContainer)},e.prototype.calculateWidth=function(){var t=this;this.isSnap||(this.inner.style.width="".concat(this.sliderWidth*this.slides.length/this.getCurrentSlidesQty(),"px")),this.slides.forEach((function(e){e.style.width="".concat(t.sliderWidth/t.getCurrentSlidesQty(),"px")})),this.calculateTransform()},e.prototype.addCurrentClass=function(){var t=this;if(this.isSnap)for(var e=Math.floor(this.getCurrentSlidesQty()/2),i=0;i<this.slides.length;i++){var n=this.slides[i];i<=this.currentIndex+e&&i>=this.currentIndex-e?n.classList.add("active"):n.classList.remove("active")}else{var s=this.isCentered?this.currentIndex+this.getCurrentSlidesQty()+(this.getCurrentSlidesQty()-1):this.currentIndex+this.getCurrentSlidesQty();this.slides.forEach((function(e,i){i>=t.currentIndex&&i<s?e.classList.add("active"):e.classList.remove("active")}))}},e.prototype.setCurrentDot=function(){var t=this,e=function(e,i){var n=Math.floor(t.getCurrentSlidesQty()/2);(t.isSnap&&!t.hasSnapSpacers?i===(t.getCurrentSlidesQty()%2==0?t.currentIndex-n+1:t.currentIndex-n):i===t.currentIndex)?e.classList.add("active"):e.classList.remove("active")};this.dotsItems?this.dotsItems.forEach((function(t,i){return e(t,i)})):this.dots.querySelectorAll(":scope > *").forEach((function(t,i){return e(t,i)}))},e.prototype.setElementToDisabled=function(t){t.classList.add("disabled"),"BUTTON"!==t.tagName&&"INPUT"!==t.tagName||t.setAttribute("disabled","disabled")},e.prototype.unsetElementToDisabled=function(t){t.classList.remove("disabled"),"BUTTON"!==t.tagName&&"INPUT"!==t.tagName||t.removeAttribute("disabled")},e.prototype.addDisabledClass=function(){if(!this.prev||!this.next)return!1;var t=getComputedStyle(this.inner).getPropertyValue("gap"),e=Math.floor(this.getCurrentSlidesQty()/2),i=0,n=0,s=!1,r=!1;this.isSnap?(i=this.currentIndex,n=this.hasSnapSpacers?this.slides.length-1:this.slides.length-e-1,s=this.hasSnapSpacers?0===i:this.getCurrentSlidesQty()%2==0?i-e<0:i-e==0,r=i>=n&&this.container.scrollLeft+this.container.clientWidth+(parseFloat(t)||0)>=this.container.scrollWidth):(s=0===(i=this.currentIndex),r=i>=(n=this.isCentered?this.slides.length-this.getCurrentSlidesQty()+(this.getCurrentSlidesQty()-1):this.slides.length-this.getCurrentSlidesQty())),s?(this.unsetElementToDisabled(this.next),this.setElementToDisabled(this.prev)):r?(this.unsetElementToDisabled(this.prev),this.setElementToDisabled(this.next)):(this.unsetElementToDisabled(this.prev),this.unsetElementToDisabled(this.next))},e.prototype.autoPlay=function(){this.setTimer()},e.prototype.setTimer=function(){var t=this;this.timer=setInterval((function(){t.currentIndex===t.slides.length-1?t.goTo(0):t.goToNext()}),this.speed)},e.prototype.resetTimer=function(){clearInterval(this.timer)},e.prototype.detectDirection=function(){var t=this.touchX,e=t.start,i=t.end;i<e&&this.goToNext(),i>e&&this.goToPrev()},e.prototype.calculateTransform=function(t){void 0!==t&&(this.currentIndex=t),this.currentIndex>this.slides.length-this.getCurrentSlidesQty()&&!this.isCentered&&(this.currentIndex=this.slides.length-this.getCurrentSlidesQty());var e=this.sliderWidth,i=e/this.getCurrentSlidesQty(),n=this.currentIndex*i;if(this.isSnap&&!this.isCentered&&this.container.scrollLeft<e&&this.container.scrollLeft+i/2>e&&(this.container.scrollLeft=this.container.scrollWidth),this.isCentered&&!this.isSnap){var s=(e-i)/2;if(0===this.currentIndex)n=-s;else if(this.currentIndex>=this.slides.length-this.getCurrentSlidesQty()+(this.getCurrentSlidesQty()-1)){n=this.slides.length*i-e+s}else n=this.currentIndex*i-s}this.isSnap||(this.inner.style.transform=this.isRTL?"translate(".concat(n,"px, 0px)"):"translate(".concat(-n,"px, 0px)")),this.isAutoHeight&&(this.inner.style.height="".concat(this.slides[this.currentIndex].clientHeight,"px")),this.dotsItems&&this.goToCurrentDot(),this.addCurrentClass(),this.isInfiniteLoop||this.addDisabledClass(),this.isSnap&&this.hasSnapSpacers&&this.buildSnapSpacers(),this.infoCurrent&&this.setInfoCurrent()},e.prototype.setTranslate=function(t){this.inner.style.transform=this.isRTL?"translate(".concat(-t,"px, 0px)"):"translate(".concat(t,"px, 0px)")},e.prototype.setIndex=function(t){this.currentIndex=t,this.addCurrentClass(),this.isInfiniteLoop||this.addDisabledClass()},e.prototype.recalculateWidth=function(){this.sliderWidth=this.inner.parentElement.getBoundingClientRect().width,this.calculateWidth(),this.sliderWidth!==this.inner.parentElement.getBoundingClientRect().width&&this.recalculateWidth()},e.prototype.goToPrev=function(){if(this.currentIndex>0?this.currentIndex--:this.currentIndex=this.slides.length-this.getCurrentSlidesQty(),this.isSnap){var t=this.sliderWidth/this.getCurrentSlidesQty();this.container.scrollBy({left:Math.max(-this.container.scrollLeft,-t),behavior:"smooth"}),this.addCurrentClass(),this.isInfiniteLoop||this.addDisabledClass()}else this.calculateTransform();this.dots&&this.setCurrentDot()},e.prototype.goToNext=function(){var t=this.isCentered?this.slides.length-this.getCurrentSlidesQty()+(this.getCurrentSlidesQty()-1):this.slides.length-this.getCurrentSlidesQty();if(this.currentIndex<t?this.currentIndex++:this.currentIndex=0,this.isSnap){var e=this.sliderWidth/this.getCurrentSlidesQty(),i=this.container.scrollWidth-this.container.clientWidth;this.container.scrollBy({left:Math.min(e,i-this.container.scrollLeft),behavior:"smooth"}),this.addCurrentClass(),this.isInfiniteLoop||this.addDisabledClass()}else this.calculateTransform();this.dots&&this.setCurrentDot()},e.prototype.goTo=function(t){var e=this.currentIndex;if(this.currentIndex=t,this.isSnap){var i=this.sliderWidth/this.getCurrentSlidesQty(),n=e>this.currentIndex?e-this.currentIndex:this.currentIndex-e,s=e>this.currentIndex?-i*n:i*n;this.container.scrollBy({left:s,behavior:"smooth"}),this.addCurrentClass(),this.isInfiniteLoop||this.addDisabledClass()}else this.calculateTransform();this.dots&&this.setCurrentDot()},e.prototype.destroy=function(){var t,e,i,n=this;(this.loadingClassesAdd&&("string"==typeof this.loadingClassesAdd?this.inner.classList.remove(this.loadingClassesAdd):(t=this.inner.classList).remove.apply(t,this.loadingClassesAdd)),this.inner&&this.afterLoadingClassesAdd&&setTimeout((function(){var t;"string"==typeof n.afterLoadingClassesAdd?n.inner.classList.remove(n.afterLoadingClassesAdd):(t=n.inner.classList).remove.apply(t,n.afterLoadingClassesAdd)})),this.el.classList.remove("init"),this.inner.classList.remove("dragging"),this.slides.forEach((function(t){return t.classList.remove("active")})),(null===(e=null==this?void 0:this.dotsItems)||void 0===e?void 0:e.length)&&this.dotsItems.forEach((function(t){return t.classList.remove("active")})),this.prev.classList.remove("disabled"),this.next.classList.remove("disabled"),this.inner.style.width="",this.slides.forEach((function(t){return t.style.width=""})),this.isSnap||(this.inner.style.transform=""),this.isAutoHeight&&(this.inner.style.height=""),this.prev.removeEventListener("click",this.onPrevClickListener),this.next.removeEventListener("click",this.onNextClickListener),this.container.removeEventListener("scroll",this.onContainerScrollListener),this.el.removeEventListener("touchstart",this.onElementTouchStartListener),this.el.removeEventListener("touchend",this.onElementTouchEndListener),this.inner.removeEventListener("mousedown",this.onInnerMouseDownListener),this.inner.removeEventListener("touchstart",this.onInnerTouchStartListener),document.removeEventListener("mousemove",this.onDocumentMouseMoveListener),document.removeEventListener("touchmove",this.onDocumentTouchMoveListener),document.removeEventListener("mouseup",this.onDocumentMouseUpListener),document.removeEventListener("touchend",this.onDocumentTouchEndListener),this.inner.querySelectorAll("a:not(.prevented-click)").forEach((function(t){t.classList.remove("prevented-click"),t.removeEventListener("click",n.removeClickEventWhileDragging)})),(null===(i=null==this?void 0:this.dotsItems)||void 0===i?void 0:i.length)||this.dots.querySelectorAll(":scope > *").length)&&(((null==this?void 0:this.dotsItems)||this.dots.querySelectorAll(":scope > *")).forEach((function(t){return t.removeEventListener("click",n.onDotClickListener)})),this.dots.innerHTML=null);this.inner.querySelector(".hs-snap-before").remove(),this.inner.querySelector(".hs-snap-after").remove(),this.dotsItems=null,this.isDragging=!1,this.dragStartX=null,this.initialTranslateX=null,window.$hsCarouselCollection=window.$hsCarouselCollection.filter((function(t){return t.element.el!==n.el}))},e.getInstance=function(t,e){var i=window.$hsCarouselCollection.find((function(e){return e.element.el===("string"==typeof t?document.querySelector(t):t)}));return i?e?i:i.element:null},e.autoInit=function(){window.$hsCarouselCollection||(window.$hsCarouselCollection=[]),window.$hsCarouselCollection&&(window.$hsCarouselCollection=window.$hsCarouselCollection.filter((function(t){var e=t.element;return document.contains(e.el)}))),document.querySelectorAll("[data-hs-carousel]:not(.--prevent-on-load-init)").forEach((function(t){window.$hsCarouselCollection.find((function(e){var i;return(null===(i=null==e?void 0:e.element)||void 0===i?void 0:i.el)===t}))||new e(t)}))},e}(a.default);window.addEventListener("load",(function(){d.autoInit()})),"undefined"!=typeof window&&(window.HSCarousel=d),e.default=d},292:function(t,e){
10
10
  /*
11
- * HSCarousel
12
- * @version: 2.4.1
11
+ * @version: 2.7.0
13
12
  * @author: Preline Labs Ltd.
14
13
  * @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
15
14
  * Copyright 2024 Preline Labs Ltd.
16
15
  */
17
- var i,n=this&&this.__extends||(i=function(t,e){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s])},i(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function s(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(s.prototype=e.prototype,new s)}),o=this&&this.__assign||function(){return o=Object.assign||function(t){for(var e,s=1,i=arguments.length;s<i;s++)for(var n in e=arguments[s])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},o.apply(this,arguments)},r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var l=function(t){function e(e,s){var i,n,r,l=t.call(this,e,s)||this,a=e.getAttribute("data-hs-carousel"),d=a?JSON.parse(a):{},c=o(o({},d),s);return l.currentIndex=c.currentIndex||0,l.loadingClasses=c.loadingClasses?"".concat(c.loadingClasses).split(","):null,l.loadingClassesRemove=(null===(i=l.loadingClasses)||void 0===i?void 0:i[0])?l.loadingClasses[0].split(" "):"opacity-0",l.loadingClassesAdd=(null===(n=l.loadingClasses)||void 0===n?void 0:n[1])?l.loadingClasses[1].split(" "):"",l.afterLoadingClassesAdd=(null===(r=l.loadingClasses)||void 0===r?void 0:r[2])?l.loadingClasses[2].split(" "):"",l.isAutoPlay=void 0!==c.isAutoPlay&&c.isAutoPlay,l.speed=c.speed||4e3,l.isInfiniteLoop=void 0===c.isInfiniteLoop||c.isInfiniteLoop,l.isRTL=void 0!==c.isRTL&&c.isRTL,l.inner=l.el.querySelector(".hs-carousel-body")||null,l.slides=l.el.querySelectorAll(".hs-carousel-slide")||[],l.prev=l.el.querySelector(".hs-carousel-prev")||null,l.next=l.el.querySelector(".hs-carousel-next")||null,l.dots=l.el.querySelectorAll(".hs-carousel-pagination > *")||null,l.sliderWidth=l.inner.parentElement.clientWidth,l.touchX={start:0,end:0},l.init(),l}return n(e,t),e.prototype.init=function(){var t,e,s=this;this.createCollection(window.$hsCarouselCollection,this),this.inner&&(this.calculateWidth(),this.loadingClassesRemove&&("string"==typeof this.loadingClassesRemove?this.inner.classList.remove(this.loadingClassesRemove):(t=this.inner.classList).remove.apply(t,this.loadingClassesRemove)),this.loadingClassesAdd&&("string"==typeof this.loadingClassesAdd?this.inner.classList.add(this.loadingClassesAdd):(e=this.inner.classList).add.apply(e,this.loadingClassesAdd))),this.prev&&this.prev.addEventListener("click",(function(){s.goToPrev(),s.isAutoPlay&&(s.resetTimer(),s.setTimer())})),this.next&&this.next.addEventListener("click",(function(){s.goToNext(),s.isAutoPlay&&(s.resetTimer(),s.setTimer())})),this.dots&&this.dots.forEach((function(t,e){return t.addEventListener("click",(function(){s.goTo(e),s.isAutoPlay&&(s.resetTimer(),s.setTimer())}))})),this.slides.length&&(this.addCurrentClass(),this.isInfiniteLoop||this.addDisabledClass(),this.isAutoPlay&&this.autoPlay()),this.inner&&this.afterLoadingClassesAdd&&setTimeout((function(){var t;"string"==typeof s.afterLoadingClassesAdd?s.inner.classList.add(s.afterLoadingClassesAdd):(t=s.inner.classList).add.apply(t,s.afterLoadingClassesAdd)})),this.el.classList.add("init"),this.el.addEventListener("touchstart",(function(t){s.touchX.start=t.changedTouches[0].screenX})),this.el.addEventListener("touchend",(function(t){s.touchX.end=t.changedTouches[0].screenX,s.detectDirection()})),this.observeResize()},e.prototype.observeResize=function(){var t=this;new ResizeObserver((function(){return t.recalculateWidth()})).observe(document.querySelector("body"))},e.prototype.calculateWidth=function(){var t=this;this.inner.style.width="".concat(this.sliderWidth*this.slides.length,"px"),this.inner.style.transform=this.calculateTransform(),this.slides.forEach((function(e){e.style.width="".concat(t.sliderWidth,"px")}))},e.prototype.addCurrentClass=function(){var t=this;this.slides.forEach((function(e,s){s===t.currentIndex?e.classList.add("active"):e.classList.remove("active")})),this.dots&&this.dots.forEach((function(e,s){s===t.currentIndex?e.classList.add("active"):e.classList.remove("active")}))},e.prototype.addDisabledClass=function(){if(!this.prev||!this.next)return!1;0===this.currentIndex?(this.next.classList.remove("disabled"),this.prev.classList.add("disabled")):this.currentIndex===this.slides.length-1?(this.prev.classList.remove("disabled"),this.next.classList.add("disabled")):(this.prev.classList.remove("disabled"),this.next.classList.remove("disabled"))},e.prototype.autoPlay=function(){this.setTimer()},e.prototype.setTimer=function(){var t=this;this.timer=setInterval((function(){t.currentIndex===t.slides.length-1?t.goTo(0):t.goToNext()}),this.speed)},e.prototype.resetTimer=function(){clearInterval(this.timer)},e.prototype.detectDirection=function(){var t=this.touchX,e=t.start,s=t.end;s<e&&this.goToNext(),s>e&&this.goToPrev()},e.prototype.recalculateWidth=function(){this.sliderWidth=this.inner.parentElement.clientWidth,this.calculateWidth()},e.prototype.calculateTransform=function(){var t=this.currentIndex*this.sliderWidth;return this.isRTL?"translate(".concat(t,"px, 0px)"):"translate(-".concat(t,"px, 0px)")},e.prototype.goToPrev=function(){0===this.currentIndex&&this.isInfiniteLoop?(this.currentIndex=this.slides.length-1,this.inner.style.transform=this.calculateTransform(),this.addCurrentClass()):0!==this.currentIndex&&(this.currentIndex-=1,this.inner.style.transform=this.calculateTransform(),this.addCurrentClass(),this.addDisabledClass())},e.prototype.goToNext=function(){this.currentIndex===this.slides.length-1&&this.isInfiniteLoop?(this.currentIndex=0,this.inner.style.transform=this.calculateTransform(),this.addCurrentClass()):this.currentIndex<this.slides.length-1&&(this.currentIndex+=1,this.inner.style.transform=this.calculateTransform(),this.addCurrentClass(),this.addDisabledClass())},e.prototype.goTo=function(t){this.currentIndex=t,this.inner.style.transform=this.calculateTransform(),this.addCurrentClass(),this.isInfiniteLoop||this.addDisabledClass()},e.getInstance=function(t,e){var s=window.$hsCarouselCollection.find((function(e){return e.element.el===("string"==typeof t?document.querySelector(t):t)}));return s?e?s:s.element:null},e.autoInit=function(){window.$hsCarouselCollection||(window.$hsCarouselCollection=[]),document.querySelectorAll("[data-hs-carousel]:not(.--prevent-on-load-init)").forEach((function(t){window.$hsCarouselCollection.find((function(e){var s;return(null===(s=null==e?void 0:e.element)||void 0===s?void 0:s.el)===t}))||new e(t)}))},e}(r(s(961)).default);window.addEventListener("load",(function(){l.autoInit()})),window.addEventListener("resize",(function(){if(!window.$hsCarouselCollection)return!1;window.$hsCarouselCollection.forEach((function(t){t.element.recalculateWidth()}))})),"undefined"!=typeof window&&(window.HSCarousel=l),e.default=l}},e={};var s=function s(i){var n=e[i];if(void 0!==n)return n.exports;var o=e[i]={exports:{}};return t[i].call(o.exports,o,o.exports,s),o.exports}(268);return s})()));
16
+ var i=this;Object.defineProperty(e,"__esModule",{value:!0}),e.menuSearchHistory=e.classToClassList=e.htmlToElement=e.afterTransition=e.dispatch=e.debounce=e.isJson=e.isDirectChild=e.isFormElement=e.isParentOrElementHidden=e.isEnoughSpace=e.isIpadOS=e.isIOS=e.getZIndex=e.getClassPropertyAlt=e.getClassProperty=e.stringToBoolean=void 0,e.getHighestZIndex=function(t){var e=Number.NEGATIVE_INFINITY;return t.forEach((function(t){var i=n(t);"auto"!==i&&(i=parseInt(i,10))>e&&(e=i)})),e};e.stringToBoolean=function(t){return"true"===t};e.getClassProperty=function(t,e,i){return void 0===i&&(i=""),(window.getComputedStyle(t).getPropertyValue(e)||i).replace(" ","")};e.getClassPropertyAlt=function(t,e,i){void 0===i&&(i="");var n="";return t.classList.forEach((function(t){t.includes(e)&&(n=t)})),n.match(/:(.*)]/)?n.match(/:(.*)]/)[1]:i};var n=function(t){return window.getComputedStyle(t).getPropertyValue("z-index")};e.getZIndex=n;e.isIOS=function(){return!!/iPad|iPhone|iPod/.test(navigator.platform)||navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/MacIntel/.test(navigator.platform)};e.isIpadOS=function(){return navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/MacIntel/.test(navigator.platform)};e.isDirectChild=function(t,e){for(var i=t.children,n=0;n<i.length;n++)if(i[n]===e)return!0;return!1};e.isEnoughSpace=function(t,e,i,n,s){void 0===i&&(i="auto"),void 0===n&&(n=10),void 0===s&&(s=null);var r=e.getBoundingClientRect(),o=s?s.getBoundingClientRect():null,l=window.innerHeight,a=o?r.top-o.top:r.top,h=(s?o.bottom:l)-r.bottom,d=t.clientHeight+n;return"bottom"===i?h>=d:"top"===i?a>=d:a>=d||h>=d};e.isFormElement=function(t){return t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement};var s=function(t){return!!t&&("none"===window.getComputedStyle(t).display||s(t.parentElement))};e.isParentOrElementHidden=s;e.isJson=function(t){if("string"!=typeof t)return!1;var e=t.trim()[0],i=t.trim().slice(-1);if("{"===e&&"}"===i||"["===e&&"]"===i)try{return JSON.parse(t),!0}catch(t){return!1}return!1};e.debounce=function(t,e){var n;return void 0===e&&(e=200),function(){for(var s=[],r=0;r<arguments.length;r++)s[r]=arguments[r];clearTimeout(n),n=setTimeout((function(){t.apply(i,s)}),e)}};e.dispatch=function(t,e,i){void 0===i&&(i=null);var n=new CustomEvent(t,{detail:{payload:i},bubbles:!0,cancelable:!0,composed:!1});e.dispatchEvent(n)};e.afterTransition=function(t,e){var i=function(){e(),t.removeEventListener("transitionend",i,!0)},n=window.getComputedStyle(t),s=n.getPropertyValue("transition-duration");"none"!==n.getPropertyValue("transition-property")&&parseFloat(s)>0?t.addEventListener("transitionend",i,!0):e()};e.htmlToElement=function(t){var e=document.createElement("template");return t=t.trim(),e.innerHTML=t,e.content.firstChild};e.classToClassList=function(t,e,i,n){void 0===i&&(i=" "),void 0===n&&(n="add"),t.split(i).forEach((function(t){return"add"===n?e.classList.add(t):e.classList.remove(t)}))};e.menuSearchHistory={historyIndex:-1,addHistory:function(t){this.historyIndex=t},existsInHistory:function(t){return t>this.historyIndex},clearHistory:function(){this.historyIndex=-1}}}},e={};var i=function i(n){var s=e[n];if(void 0!==s)return s.exports;var r=e[n]={exports:{}};return t[n].call(r.exports,r,r.exports,i),r.exports}(268);return i})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preline/carousel",
3
- "version": "2.4.1",
3
+ "version": "2.5.2",
4
4
  "description": "Preline UI is an open-source set of prebuilt UI components based on the utility-first Tailwind CSS framework.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",