Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@preline/carousel

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@preline/carousel - npm Package Compare versions

Comparing version 2.4.1 to 2.5.0

74

index.d.ts

@@ -19,9 +19,20 @@ export interface IBasePlugin<O, E> {

}
export type TCarouselOptionsSlidesQty = {
[key: string]: number;
};
export interface ICarouselOptions {
currentIndex: number;
loadingClasses?: string | string[];
dotsItemClasses?: string;
isAutoHeight?: boolean;
isAutoPlay?: boolean;
speed?: number;
isCentered?: boolean;
isDraggable?: boolean;
isInfiniteLoop?: boolean;
isRTL?: boolean;
isSnap?: boolean;
hasSnapSpacers?: boolean;
slidesQty?: TCarouselOptionsSlidesQty | number;
speed?: number;
updateDelay?: number;
}

@@ -36,2 +47,20 @@ export interface ICarousel {

declare class HSCarousel extends HSBasePlugin<ICarouselOptions> implements ICarousel {
private currentIndex;
private readonly loadingClasses;
private readonly dotsItemClasses;
private readonly isAutoHeight;
private readonly isAutoPlay;
private readonly isCentered;
private readonly isDraggable;
private readonly isInfiniteLoop;
private readonly isRTL;
private readonly isSnap;
private readonly hasSnapSpacers;
private readonly slidesQty;
private readonly speed;
private readonly updateDelay;
private readonly loadingClassesRemove;
private readonly loadingClassesAdd;
private readonly afterLoadingClassesAdd;
private readonly container;
private readonly inner;

@@ -42,19 +71,42 @@ private readonly slides;

private readonly dots;
private dotsItems;
private readonly info;
private readonly infoTotal;
private readonly infoCurrent;
private sliderWidth;
private currentIndex;
private readonly loadingClasses;
private readonly loadingClassesRemove;
private readonly loadingClassesAdd;
private readonly afterLoadingClassesAdd;
private readonly isAutoPlay;
private readonly isRTL;
private readonly speed;
private readonly isInfiniteLoop;
private timer;
private isScrolling;
private isDragging;
private dragStartX;
private initialTranslateX;
private readonly touchX;
private resizeContainer;
resizeContainerWidth: number;
constructor(el: HTMLElement, options?: ICarouselOptions);
private setIsSnap;
private init;
private initDragHandling;
private getTranslateXValue;
private removeClickEventWhileDragging;
private handleDragStart;
private handleDragMove;
private handleDragEnd;
private getEventX;
private getCurrentSlidesQty;
private buildSnapSpacers;
private initDots;
private buildDots;
private setDots;
private goToCurrentDot;
private buildInfo;
private setInfoTotal;
private setInfoCurrent;
private buildSingleDot;
private singleDotEvents;
private observeResize;
private calculateWidth;
private addCurrentClass;
private setCurrentDot;
private setElementToDisabled;
private unsetElementToDisabled;
private addDisabledClass;

@@ -67,5 +119,7 @@ private autoPlay;

private calculateTransform;
private setTranslate;
goToPrev(): void;
goToNext(): void;
goTo(i: number): void;
private setIndex;
static getInstance(target: HTMLElement | string, isInstance?: boolean): HSCarousel | ICollectionItem<HSCarousel>;

@@ -72,0 +126,0 @@ static autoInit(): void;

13

index.js

@@ -1,5 +0,5 @@

!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)=>{
!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 s in i)("object"==typeof exports?exports:t)[s]=i[s]}}(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","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","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){
/*
* HSBasePlugin
* @version: 2.4.1
* HSCarousel
* @version: 2.5.0
* @author: Preline Labs Ltd.

@@ -9,6 +9,5 @@ * @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)

*/
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){
var s,n=this&&this.__extends||(s=function(t,e){return s=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])},s(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}s(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,s=arguments.length;i<s;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);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 a=i(292),l=o(i(961)),d=i(223),h=function(t){function e(e,i){var s,n,o,a,l,d=t.call(this,e,i)||this,h=e.getAttribute("data-hs-carousel"),u=h?JSON.parse(h):{},c=r(r({},u),i);return d.currentIndex=c.currentIndex||0,d.loadingClasses=c.loadingClasses?"".concat(c.loadingClasses).split(","):null,d.dotsItemClasses=c.dotsItemClasses?c.dotsItemClasses:null,d.isAutoHeight=void 0!==c.isAutoHeight&&c.isAutoHeight,d.isAutoPlay=void 0!==c.isAutoPlay&&c.isAutoPlay,d.isCentered=void 0!==c.isCentered&&c.isCentered,d.isDraggable=void 0!==c.isDraggable&&c.isDraggable,d.isInfiniteLoop=void 0!==c.isInfiniteLoop&&c.isInfiniteLoop,d.isRTL=void 0!==c.isRTL&&c.isRTL,d.isSnap=void 0!==c.isSnap&&c.isSnap,d.hasSnapSpacers=void 0===c.hasSnapSpacers||c.hasSnapSpacers,d.speed=c.speed||4e3,d.updateDelay=c.updateDelay||0,d.slidesQty=c.slidesQty||1,d.loadingClassesRemove=(null===(s=d.loadingClasses)||void 0===s?void 0:s[0])?d.loadingClasses[0].split(" "):"opacity-0",d.loadingClassesAdd=(null===(n=d.loadingClasses)||void 0===n?void 0:n[1])?d.loadingClasses[1].split(" "):"",d.afterLoadingClassesAdd=(null===(o=d.loadingClasses)||void 0===o?void 0:o[2])?d.loadingClasses[2].split(" "):"",d.container=d.el.querySelector(".hs-carousel")||null,d.inner=d.el.querySelector(".hs-carousel-body")||null,d.slides=d.el.querySelectorAll(".hs-carousel-slide")||[],d.prev=d.el.querySelector(".hs-carousel-prev")||null,d.next=d.el.querySelector(".hs-carousel-next")||null,d.dots=d.el.querySelector(".hs-carousel-pagination")||null,d.info=d.el.querySelector(".hs-carousel-info")||null,d.infoTotal=(null===(a=null==d?void 0:d.info)||void 0===a?void 0:a.querySelector(".hs-carousel-info-total"))||null,d.infoCurrent=(null===(l=null==d?void 0:d.info)||void 0===l?void 0:l.querySelector(".hs-carousel-info-current"))||null,d.sliderWidth=d.el.getBoundingClientRect().width,d.isDragging=!1,d.dragStartX=null,d.initialTranslateX=null,d.touchX={start:0,end:0},d.resizeContainer=document.querySelector("body"),d.resizeContainerWidth=0,d.init(),d}return n(e,t),e.prototype.setIsSnap=function(){var t=this,e=this.container.getBoundingClientRect(),i=e.left+e.width/2,s=null,n=null,r=1/0;Array.from(this.inner.children).forEach((function(e){var n=e.getBoundingClientRect(),o=t.inner.getBoundingClientRect(),a=n.left+n.width/2-o.left,l=Math.abs(i-(o.left+a));l<r&&(r=l,s=e)})),s&&(n=Array.from(this.slides).findIndex((function(t){return t===s}))),this.setIndex(n),this.dots&&this.setCurrentDot()},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.prev.addEventListener("click",(function(){t.goToPrev(),t.isAutoPlay&&(t.resetTimer(),t.setTimer())})),this.next&&this.next.addEventListener("click",(function(){t.goToNext(),t.isAutoPlay&&(t.resetTimer(),t.setTimer())})),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.container.addEventListener("scroll",(function(){clearTimeout(t.isScrolling),t.isScrolling=setTimeout((function(){t.setIsSnap()}),100)})),this.el.classList.add("init"),this.isSnap||(this.el.addEventListener("touchstart",(function(e){t.touchX.start=e.changedTouches[0].screenX})),this.el.addEventListener("touchend",(function(e){t.touchX.end=e.changedTouches[0].screenX,t.detectDirection()}))),this.observeResize()},e.prototype.initDragHandling=function(){var t=this.inner;t&&(t.addEventListener("mousedown",this.handleDragStart.bind(this)),t.addEventListener("touchstart",this.handleDragStart.bind(this),{passive:!0}),document.addEventListener("mousemove",this.handleDragMove.bind(this)),document.addEventListener("touchmove",this.handleDragMove.bind(this),{passive:!1}),document.addEventListener("mouseup",this.handleDragEnd.bind(this)),document.addEventListener("touchend",this.handleDragEnd.bind(this)))},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 s=parseFloat(6===i.length?i[4]:i[12]);return this.isRTL&&(s=-s),isNaN(s)||0===s?0:-s}}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 s=this.initialTranslateX+i;this.setTranslate(function(){var t=e.sliderWidth*e.slides.length/e.getCurrentSlidesQty()-e.sliderWidth,i=e.sliderWidth,n=(i-i/e.getCurrentSlidesQty())/2,r=e.isCentered?n:0;e.isCentered&&(t+=n);var o=-t;return e.isRTL?s<r?r:s>t?o:-s:s>r?r:s<-t?o:s}())}},e.prototype.handleDragEnd=function(){var t=this;if(this.isDragging){this.isDragging=!1;var e=this.sliderWidth/this.getCurrentSlidesQty(),i=this.getTranslateXValue(),s=Math.round(i/e);this.isRTL&&(s=Math.round(i/e)),this.inner.classList.remove("dragging"),setTimeout((function(){t.calculateTransform(s),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(s){e>=(typeof s+1=="number"?t.slidesQty[s]:d.BREAKPOINTS[s])&&(i=t.slidesQty[s])})),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,s=i/2-i/this.getCurrentSlidesQty()/2,n=(0,a.htmlToElement)('<div class="hs-snap-before" style="height: 100%; width: '.concat(s,'px"></div>')),r=(0,a.htmlToElement)('<div class="hs-snap-after" style="height: 100%; width: '.concat(s,'px"></div>'));this.inner.prepend(n),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 s=e.getAttribute("data-carousel-pagination-item-target");t.singleDotEvents(e,s?+s:i)}))},e.prototype.goToCurrentDot=function(){var t=this.dots,e=t.getBoundingClientRect(),i=t.scrollLeft,s=t.scrollTop,n=t.clientWidth,r=t.clientHeight,o=this.dotsItems[this.currentIndex],a=o.getBoundingClientRect(),l=a.left-e.left+i,d=l+o.clientWidth,h=a.top-e.top+s,u=h+o.clientHeight,c=i,p=s;(l<i||d>i+n)&&(c=d-n),(h<s||u>s+r)&&(p=u-r),t.scrollTo({left:c,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,a.htmlToElement)("<span></span>");return this.dotsItemClasses&&(0,a.classToClassList)(this.dotsItemClasses,e),this.singleDotEvents(e,t),e},e.prototype.singleDotEvents=function(t,e){var i=this;t.addEventListener("click",(function(){i.goTo(e),i.isAutoPlay&&(i.resetTimer(),i.setTimer())}))},e.prototype.observeResize=function(){var t=this;new ResizeObserver((0,a.debounce)((function(e){for(var i=0,s=e;i<s.length;i++){var n=s[i].contentRect.width;n!==t.resizeContainerWidth&&(t.recalculateWidth(),t.dots&&t.initDots(),t.addCurrentClass(),t.resizeContainerWidth=n)}}),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 s=this.slides[i];i<=this.currentIndex+e&&i>=this.currentIndex-e?s.classList.add("active"):s.classList.remove("active")}else{var n=this.isCentered?this.currentIndex+this.getCurrentSlidesQty()+(this.getCurrentSlidesQty()-1):this.currentIndex+this.getCurrentSlidesQty();this.slides.forEach((function(e,i){i>=t.currentIndex&&i<n?e.classList.add("active"):e.classList.remove("active")}))}},e.prototype.setCurrentDot=function(){var t=this,e=function(e,i){var s=Math.floor(t.getCurrentSlidesQty()/2);(t.isSnap&&!t.hasSnapSpacers?i===(t.getCurrentSlidesQty()%2==0?t.currentIndex-s+1:t.currentIndex-s):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,s=0,n=!1,r=!1;this.isSnap?(i=this.currentIndex,s=this.hasSnapSpacers?this.slides.length-1:this.slides.length-e-1,n=this.hasSnapSpacers?0===i:this.getCurrentSlidesQty()%2==0?i-e<0:i-e==0,r=i>=s&&this.container.scrollLeft+this.container.clientWidth+(parseFloat(t)||0)>=this.container.scrollWidth):(n=0===(i=this.currentIndex),r=i>=(s=this.isCentered?this.slides.length-this.getCurrentSlidesQty()+(this.getCurrentSlidesQty()-1):this.slides.length-this.getCurrentSlidesQty())),n?(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.recalculateWidth=function(){this.sliderWidth=this.inner.parentElement.getBoundingClientRect().width,this.calculateWidth(),this.sliderWidth!==this.inner.parentElement.getBoundingClientRect().width&&this.recalculateWidth()},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(),s=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 n=(e-i)/2;if(0===this.currentIndex)s=-n;else if(this.currentIndex>=this.slides.length-this.getCurrentSlidesQty()+(this.getCurrentSlidesQty()-1)){s=this.slides.length*i-e+n}else s=this.currentIndex*i-n}this.isSnap||(this.inner.style.transform=this.isRTL?"translate(".concat(s,"px, 0px)"):"translate(".concat(-s,"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.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(),s=e>this.currentIndex?e-this.currentIndex:this.currentIndex-e,n=e>this.currentIndex?-i*s:i*s;this.container.scrollBy({left:n,behavior:"smooth"}),this.addCurrentClass(),this.isInfiniteLoop||this.addDisabledClass()}else this.calculateTransform();this.dots&&this.setCurrentDot()},e.prototype.setIndex=function(t){this.currentIndex=t,this.addCurrentClass(),this.isInfiniteLoop||this.addDisabledClass()},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=[]),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}(l.default);window.addEventListener("load",(function(){h.autoInit()})),"undefined"!=typeof window&&(window.HSCarousel=h),e.default=h},292:function(t,e){
/*
* HSCarousel
* @version: 2.4.1
* @version: 2.5.0
* @author: Preline Labs Ltd.

@@ -18,2 +17,2 @@ * @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)

*/
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})()));
var i=this;Object.defineProperty(e,"__esModule",{value:!0}),e.menuSearchHistory=e.classToClassList=e.htmlToElement=e.afterTransition=e.dispatch=e.debounce=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=s(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 s="";return t.classList.forEach((function(t){t.includes(e)&&(s=t)})),s.match(/:(.*)]/)?s.match(/:(.*)]/)[1]:i};var s=function(t){return window.getComputedStyle(t).getPropertyValue("z-index")};e.getZIndex=s;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,s=0;s<i.length;s++)if(i[s]===e)return!0;return!1};e.isEnoughSpace=function(t,e,i,s,n){void 0===i&&(i="auto"),void 0===s&&(s=10),void 0===n&&(n=null);var r=e.getBoundingClientRect(),o=n?n.getBoundingClientRect():null,a=window.innerHeight,l=o?r.top-o.top:r.top,d=(n?o.bottom:a)-r.bottom,h=t.clientHeight+s;return"bottom"===i?d>=h:"top"===i?l>=h:l>=h||d>=h};e.isFormElement=function(t){return t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement};var n=function(t){return!!t&&("none"===window.getComputedStyle(t).display||n(t.parentElement))};e.isParentOrElementHidden=n;e.debounce=function(t,e){var s;return void 0===e&&(e=200),function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];clearTimeout(s),s=setTimeout((function(){t.apply(i,n)}),e)}};e.dispatch=function(t,e,i){void 0===i&&(i=null);var s=new CustomEvent(t,{detail:{payload:i},bubbles:!0,cancelable:!0,composed:!1});e.dispatchEvent(s)};e.afterTransition=function(t,e){var i=function(){e(),t.removeEventListener("transitionend",i,!0)},s=window.getComputedStyle(t),n=s.getPropertyValue("transition-duration");"none"!==s.getPropertyValue("transition-property")&&parseFloat(n)>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,s){void 0===i&&(i=" "),void 0===s&&(s="add"),t.split(i).forEach((function(t){return"add"===s?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(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s].call(r.exports,r,r.exports,i),r.exports}(268);return i})()));
{
"name": "@preline/carousel",
"version": "2.4.1",
"version": "2.5.0",
"description": "Preline UI is an open-source set of prebuilt UI components based on the utility-first Tailwind CSS framework.",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc