lazer-slider 1.1.9 → 1.2.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/README.md +36 -28
- package/dist/index.cjs +1 -10
- package/dist/index.d.cts +15 -9
- package/dist/index.d.ts +15 -9
- package/dist/index.js +1 -10
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ A lightweight, accessible slider with smooth scroll-to-snap animations, drag-to-
|
|
|
10
10
|
- **Vertical & Horizontal** - Support for both horizontal and vertical slider directions
|
|
11
11
|
- **Loop Mode** - Infinite loop navigation
|
|
12
12
|
- **Autoplay** - Automatic slide advancement with pause on hover
|
|
13
|
-
- **
|
|
13
|
+
- **Auto-Scroll** - Continuous smooth scrolling with drag interaction and seamless infinite loop
|
|
14
14
|
- **Automatic Bullets** - Auto-generate navigation bullets from slides
|
|
15
15
|
- **Thumbs Gallery** - Auto-generate thumbnail navigation from slide images
|
|
16
16
|
- **Accessible** - Full ARIA support, keyboard navigation (arrow keys)
|
|
@@ -130,12 +130,16 @@ slider.unload()
|
|
|
130
130
|
| `autoplay` | `boolean` | `false` | Enable automatic slide advancement |
|
|
131
131
|
| `autoplayInterval` | `number` | `3000` | Autoplay interval in milliseconds |
|
|
132
132
|
| `pauseOnHover` | `boolean` | `true` | Pause autoplay on hover/touch |
|
|
133
|
-
| `
|
|
134
|
-
| `
|
|
135
|
-
| `
|
|
133
|
+
| `autoScroll` | `boolean` | `false` | Enable auto-scroll (continuous scrolling, implicitly enables loop) |
|
|
134
|
+
| `autoScrollSpeed` | `number` | `50` | Auto-scroll speed in pixels per second |
|
|
135
|
+
| `autoScrollDirection` | `'forward' \| 'backward'` | `'forward'` | Auto-scroll direction |
|
|
136
|
+
| `autoScrollStartDelay` | `number` | `0` | Delay in ms before auto-scroll starts or resumes after interaction |
|
|
137
|
+
| `stopOnInteraction` | `boolean` | `false` | Permanently stop auto-scroll after user drag (call `play()` to restart) |
|
|
138
|
+
| `stopOnMouseEnter` | `boolean` | `true` | Pause auto-scroll when mouse hovers over the slider |
|
|
139
|
+
| `stopOnFocusIn` | `boolean` | `true` | Pause auto-scroll when a slide receives keyboard focus |
|
|
136
140
|
| `easing` | `EasingFunction` | `easeOutExpo` | Custom easing function |
|
|
137
141
|
|
|
138
|
-
> **Note:** When `
|
|
142
|
+
> **Note:** When `autoScroll` is enabled, loop mode is automatically enabled. Auto-scroll integrates with drag-to-scroll: dragging pauses the scroll, and it resumes after the drag ends (unless `stopOnInteraction` is `true`).
|
|
139
143
|
|
|
140
144
|
### Scrollbar (Optional)
|
|
141
145
|
|
|
@@ -181,9 +185,9 @@ slider.goToIndex(2)
|
|
|
181
185
|
slider.next()
|
|
182
186
|
slider.prev()
|
|
183
187
|
|
|
184
|
-
// Autoplay/
|
|
185
|
-
slider.play() // Start autoplay or
|
|
186
|
-
slider.pause() // Stop autoplay or
|
|
188
|
+
// Autoplay/Auto-scroll control
|
|
189
|
+
slider.play() // Start autoplay or auto-scroll
|
|
190
|
+
slider.pause() // Stop autoplay or auto-scroll
|
|
187
191
|
|
|
188
192
|
// Recalculate dimensions (call after DOM changes)
|
|
189
193
|
slider.refresh()
|
|
@@ -273,34 +277,38 @@ const slider = createSlider({
|
|
|
273
277
|
})
|
|
274
278
|
```
|
|
275
279
|
|
|
276
|
-
###
|
|
280
|
+
### Auto-Scroll
|
|
277
281
|
|
|
278
|
-
Create a continuous scrolling
|
|
282
|
+
Create a continuous scrolling effect with seamless infinite loop. Perfect for ticker-style content, logos, or announcements. Integrates with drag-to-scroll for smooth user interaction.
|
|
279
283
|
|
|
280
284
|
```typescript
|
|
281
|
-
const
|
|
282
|
-
feed: document.querySelector('.
|
|
283
|
-
slides: [...document.querySelectorAll('.
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
285
|
+
const ticker = createSlider({
|
|
286
|
+
feed: document.querySelector('.ticker-feed'),
|
|
287
|
+
slides: [...document.querySelectorAll('.ticker-item')],
|
|
288
|
+
autoScroll: true,
|
|
289
|
+
autoScrollSpeed: 80, // 80 pixels per second
|
|
290
|
+
autoScrollDirection: 'forward', // or 'backward'
|
|
291
|
+
enableDragToScroll: true, // Users can drag to interact
|
|
292
|
+
autoScrollStartDelay: 1000, // Resume 1s after interaction
|
|
293
|
+
stopOnMouseEnter: true // Pause on hover (default)
|
|
288
294
|
})
|
|
289
295
|
|
|
290
296
|
// Control programmatically
|
|
291
|
-
|
|
292
|
-
|
|
297
|
+
ticker.pause() // Stop auto-scroll
|
|
298
|
+
ticker.play() // Resume auto-scroll
|
|
293
299
|
```
|
|
294
300
|
|
|
295
301
|
**Key Features:**
|
|
296
|
-
- Continuous smooth scrolling (not
|
|
297
|
-
- Frame-rate independent animation for consistent speed
|
|
298
|
-
- Automatic
|
|
299
|
-
-
|
|
300
|
-
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
302
|
+
- Continuous smooth scrolling using `requestAnimationFrame` (not CSS animations)
|
|
303
|
+
- Frame-rate independent animation for consistent speed across devices
|
|
304
|
+
- Automatic loop clone management for seamless infinite scrolling
|
|
305
|
+
- Drag interaction support: dragging pauses auto-scroll, resumes after release
|
|
306
|
+
- Pause on hover, touch, and keyboard focus
|
|
307
|
+
- Configurable resume delay after user interaction
|
|
308
|
+
- `stopOnInteraction` mode for one-time auto-scroll that stops after user engagement
|
|
309
|
+
|
|
310
|
+
**When to use Auto-Scroll vs Autoplay:**
|
|
311
|
+
- **Auto-Scroll**: For continuous ticker-style scrolling (news tickers, logo carousels, announcements)
|
|
304
312
|
- **Autoplay**: For slide-by-slide carousel navigation (image galleries, product showcases)
|
|
305
313
|
|
|
306
314
|
### Vertical Slider
|
|
@@ -696,7 +704,7 @@ import {
|
|
|
696
704
|
type ScrollParams,
|
|
697
705
|
type ScrollStartParams,
|
|
698
706
|
type SliderDirection,
|
|
699
|
-
type
|
|
707
|
+
type AutoScrollDirection
|
|
700
708
|
} from 'lazer-slider'
|
|
701
709
|
```
|
|
702
710
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1 @@
|
|
|
1
|
-
'use strict';var C={MIN_DURATION:400,MAX_DURATION:1e3,SPEED_FACTOR:1.5,SCROLL_END_DELAY:50,THUMB_UPDATE_DELAY:500},ye="(min-width: 64rem)",O=()=>window.matchMedia(ye).matches;var N=e=>e===1?1:1-Math.pow(2,-10*e),H=e=>1-Math.pow(1-e,3),Le=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2,ge=e=>1-(1-e)*(1-e),Ae=e=>e;var Me=()=>`slider-${Math.random().toString(36).substring(2,9)}`,ee=e=>{let{feed:t,prevSlideButton:o,nextSlideButton:l,thumbs:r,slides:a}=e;t.id||(t.id=Me()),t.setAttribute("role","region"),t.setAttribute("aria-label","Carousel"),t.setAttribute("aria-roledescription","carousel"),t.removeAttribute("tabindex"),a.forEach((i,s)=>{i.setAttribute("role","group"),i.setAttribute("aria-roledescription","slide"),i.setAttribute("aria-label",`Slide ${s+1} of ${a.length}`);}),o&&(o.setAttribute("aria-label","Previous slide"),o.setAttribute("aria-controls",t.id),o.setAttribute("tabindex","0"),o.tagName!=="BUTTON"&&o.setAttribute("role","button")),l&&(l.setAttribute("aria-label","Next slide"),l.setAttribute("aria-controls",t.id),l.setAttribute("tabindex","0"),l.tagName!=="BUTTON"&&l.setAttribute("role","button")),r?.length&&r.forEach((i,s)=>{i.tagName!=="BUTTON"&&i.setAttribute("role","button"),i.setAttribute("aria-label",`Go to slide ${s+1}`),i.setAttribute("tabindex","0"),i.setAttribute("aria-controls",t.id);});},z=(e,t,o)=>{if(!e)return;!t&&e===document.activeElement&&o&&o.focus();let l="opacity 0.3s ease",r=t?"1":"0";Object.assign(e.style,{opacity:r,transition:l,pointerEvents:t?"auto":"none"}),t?(e.removeAttribute("aria-hidden"),e.setAttribute("tabindex","0")):(e.setAttribute("aria-hidden","true"),e.setAttribute("tabindex","-1")),t?e.style.visibility="visible":setTimeout(()=>{e.style.opacity==="0"&&(e.style.visibility="hidden");},300);},F=(e,t,o="active")=>{e?.length&&e.forEach((l,r)=>{let a=r===t;l.classList.toggle(o,a),l.setAttribute("aria-selected",a.toString());});},te=(e,t,o,l,r="horizontal")=>{let a=r==="vertical",i=a?"ArrowUp":"ArrowLeft",s=a?"ArrowDown":"ArrowRight";e.addEventListener("keydown",f=>{switch(f.key){case i:f.preventDefault(),t();break;case s:f.preventDefault(),o();break}},{signal:l}),e.hasAttribute("tabindex")||e.setAttribute("tabindex","0");};var A={FRICTION:.94,MIN_VELOCITY:.3,MOMENTUM_RATIO:.8,VELOCITY_SMOOTHING:.4,EDGE_RESISTANCE:.3,MAX_EDGE_OVERSCROLL:100,SHORT_SWIPE_VELOCITY:.5,BOUNCE_DURATION:400},xe=()=>({isDragging:false,startX:0,startY:0,startScrollLeft:0,startScrollTop:0,velocity:0,lastX:0,lastY:0,lastTime:0,momentumId:null}),Ie=()=>({...xe(),velocityHistory:[],dragDistance:0,dragStartTime:0}),$=(e,t,o="horizontal")=>{let l=e.getBoundingClientRect(),r=o==="vertical",a=r?l.top:l.left,i=null,s=1/0;for(let f of t){if(f.offsetParent===null)continue;let m=f.getBoundingClientRect(),h=r?m.top:m.left,n=Math.abs(a-h);n<s&&(s=n,i=f);}return i},De=(e,t,o,l="horizontal")=>{let r=e.getBoundingClientRect(),a=l==="vertical",i=a?r.top:r.left,s=t.filter(d=>d.offsetParent!==null);if(s.length===0)return null;let f=0,m=1/0;s.forEach((d,E)=>{let S=d.getBoundingClientRect(),P=a?S.top:S.left,w=Math.abs(i-P);w<m&&(m=w,f=E);});let h=2,n=f;return Math.abs(o)>h&&(o>0?n=Math.min(f+1,s.length-1):n=Math.max(f-1,0)),s[n]??null},Ce=e=>{if(e.length===0)return 0;let t=0,o=0;return e.forEach((l,r)=>{let a=r+1;t+=l*a,o+=a;}),t/o},He=(e,t,o,l,r,a="horizontal",i=false)=>{let s=a==="vertical",f=e.velocity*A.MOMENTUM_RATIO,m=()=>{if(Math.abs(f)<A.MIN_VELOCITY){e.momentumId=null;let E=$(t,o,a);if(E){let S=s?E.offsetTop:E.offsetLeft;l(S,H);}r?.(E);return}let h=s?t.scrollHeight-t.clientHeight:t.scrollWidth-t.clientWidth,d=(s?t.scrollTop:t.scrollLeft)+f;i||(d<0||d>h)&&(f*=.5),s?t.scrollTop=Math.max(0,Math.min(h,d)):t.scrollLeft=Math.max(0,Math.min(h,d)),f*=A.FRICTION,e.momentumId=requestAnimationFrame(m);};e.momentumId=requestAnimationFrame(m);},re=e=>"touches"in e?e.touches[0]?.clientX??0:e.clientX,oe=e=>"touches"in e?e.touches[0]?.clientY??0:e.clientY,we=(e,t)=>t==="vertical"?oe(e):re(e),le=e=>{let {feed:t,slides:o,abortSignal:l,smoothScrollTo:r,onDragEnd:a,direction:i="horizontal",loop:s=false,touchRatio:f=1,shortSwipeThreshold:m=300,swipeDistanceThreshold:h=10}=e,n=Ie(),d=i==="vertical",E=()=>{if(!s)return o;let y=[],g=t.children;for(let M=0;M<g.length;M++){let L=g[M];(o.includes(L)||L.hasAttribute("data-lazer-clone"))&&y.push(L);}return y.length>0?y:o},S=0,w=()=>{S=d?t.scrollHeight-t.clientHeight:t.scrollWidth-t.clientWidth,d?t.clientHeight:t.clientWidth;},q=y=>{n.momentumId!==null&&(cancelAnimationFrame(n.momentumId),n.momentumId=null),w(),n.isDragging=true,n.startX=re(y),n.startY=oe(y),n.startScrollLeft=t.scrollLeft,n.startScrollTop=t.scrollTop,n.velocity=0,n.lastX=n.startX,n.lastY=n.startY,n.lastTime=performance.now(),n.velocityHistory=[],n.dragDistance=0,n.dragStartTime=performance.now(),t.style.userSelect="none",t.style.cursor="grabbing",t.classList.add("is-dragging"),y.type==="mousedown"&&y.preventDefault();},B=y=>{if(!n.isDragging)return;let g=we(y,i),M=d?n.startY:n.startX,L=d?n.lastY:n.lastX,c=d?n.startScrollTop:n.startScrollLeft,u=performance.now(),T=u-n.lastTime,b=(M-g)*f,p=c+b;if(n.dragDistance=Math.abs(b),!s){if(p<0){let v=Math.abs(p),x=1-Math.min(v/A.MAX_EDGE_OVERSCROLL,1)*(1-A.EDGE_RESISTANCE);p=-v*x;}else if(p>S){let v=p-S,x=1-Math.min(v/A.MAX_EDGE_OVERSCROLL,1)*(1-A.EDGE_RESISTANCE);p=S+v*x;}}if(d?t.scrollTop=p:t.scrollLeft=p,T>0){let v=(L-g)/T*16;if(n.velocityHistory.length>0){let x=n.velocity;n.velocity=x*(1-A.VELOCITY_SMOOTHING)+v*A.VELOCITY_SMOOTHING;}else n.velocity=v;n.velocityHistory.push(v),n.velocityHistory.length>5&&n.velocityHistory.shift();}d?n.lastY=g:n.lastX=g,n.lastTime=u,y.type==="touchmove"&&y.preventDefault();},R=()=>{if(!n.isDragging)return;n.isDragging=false,t.style.userSelect="",t.style.cursor="",t.classList.remove("is-dragging");let g=performance.now()-n.dragStartTime<m&&n.dragDistance>h,M=Ce(n.velocityHistory),L=E();if(!s){let c=d?t.scrollTop:t.scrollLeft;if(c<0||c>S){let u=c<0?0:S,T=c,b=performance.now(),p=()=>{let v=performance.now()-b,x=Math.min(v/A.BOUNCE_DURATION,1),_=H(x),I=T+(u-T)*_;if(d?t.scrollTop=I:t.scrollLeft=I,x<1)requestAnimationFrame(p);else {let D=$(t,L,i);if(D){let Ee=d?D.offsetTop:D.offsetLeft;r(Ee,H);}a?.(D);}};requestAnimationFrame(p);return}}if(g||Math.abs(M)>A.SHORT_SWIPE_VELOCITY){let c=De(t,L,M,i);if(c){let u=d?c.offsetTop:c.offsetLeft;r(u,H),a?.(c);}else a?.(null);}else if(Math.abs(n.velocity)>1)He(n,t,L,r,a,i,s);else {let c=$(t,L,i);if(c){let u=d?c.offsetTop:c.offsetLeft;r(u,H);}a?.(c);}};return t.addEventListener("mousedown",q,{signal:l}),document.addEventListener("mousemove",B,{signal:l}),document.addEventListener("mouseup",R,{signal:l}),t.addEventListener("touchstart",q,{passive:true,signal:l}),t.addEventListener("touchmove",B,{passive:false,signal:l}),t.addEventListener("touchend",R,{signal:l}),t.addEventListener("touchcancel",R,{signal:l}),document.addEventListener("mouseleave",R,{signal:l}),t.style.cursor="grab",n},ie=e=>{e.momentumId!==null&&(cancelAnimationFrame(e.momentumId),e.momentumId=null);};var G=({bulletsContainer:e,slides:t,bulletClass:o,bulletActiveClass:l,feedId:r})=>{if(!e||!(e instanceof HTMLElement))throw new Error("Invalid bulletsContainer: must be a valid HTMLElement");if(!Array.isArray(t)||t.length===0)throw new Error("Invalid slides: must be a non-empty array");if(!r||typeof r!="string")throw new Error("Invalid feedId: must be a non-empty string");if(!o||typeof o!="string")throw new Error("Invalid bulletClass: must be a non-empty string");e.innerHTML="",e.setAttribute("role","tablist"),e.setAttribute("aria-label","Slide navigation");let a=t.map((s,f)=>({slide:s,originalIndex:f})).filter(({slide:s})=>s.offsetParent!==null);return a.length===0?(console.warn("No visible slides found"),[]):a.map(({slide:s,originalIndex:f},m)=>{let h=document.createElement("button");return h.type="button",h.classList.add(o),m===0&&h.classList.add(l),h.setAttribute("role","tab"),h.setAttribute("aria-selected",m===0?"true":"false"),h.setAttribute("aria-controls",r),h.setAttribute("aria-label",`Go to slide ${m+1}`),h.setAttribute("data-slide-index",String(m)),e.appendChild(h),h})};var X=({thumbsContainer:e,slides:t,thumbClass:o,thumbActiveClass:l,feedId:r,thumbImageSelector:a="img",thumbSize:i})=>{if(!e||!(e instanceof HTMLElement))throw new Error("Invalid thumbsContainer: must be a valid HTMLElement");if(!Array.isArray(t)||t.length===0)throw new Error("Invalid slides: must be a non-empty array");if(!r||typeof r!="string")throw new Error("Invalid feedId: must be a non-empty string");if(!o||typeof o!="string")throw new Error("Invalid thumbClass: must be a non-empty string");e.innerHTML="",e.setAttribute("role","tablist"),e.setAttribute("aria-label","Slide thumbnails");let s=t.map((m,h)=>({slide:m,originalIndex:h})).filter(({slide:m})=>m.offsetParent!==null);return s.length===0?(console.warn("No visible slides found"),[]):s.map(({slide:m,originalIndex:h},n)=>{let d=document.createElement("button");d.type="button",d.classList.add(o),n===0&&d.classList.add(l);let E=m.querySelector(a);if(E?.src){let S=document.createElement("img");S.src=E.src,S.alt=E.alt||`Slide ${n+1} thumbnail`,S.draggable=false,i&&(S.style.width=`${i.width}px`,S.style.height=`${i.height}px`,S.style.objectFit="cover"),d.appendChild(S);}return d.setAttribute("role","tab"),d.setAttribute("aria-selected",n===0?"true":"false"),d.setAttribute("aria-controls",r),d.setAttribute("aria-label",`Go to slide ${n+1}`),d.setAttribute("data-slide-index",String(n)),e.appendChild(d),d})};var ne=()=>({initialized:false,clonedSlides:[],styleElement:null}),ae=()=>{let e=document.getElementById("lazer-marquee-keyframes");if(e)return e;let t=document.createElement("style");return t.id="lazer-marquee-keyframes",t.textContent=`
|
|
2
|
-
@keyframes lazer-marquee-scroll {
|
|
3
|
-
0% {
|
|
4
|
-
transform: translateX(0);
|
|
5
|
-
}
|
|
6
|
-
100% {
|
|
7
|
-
transform: translateX(-50%);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
`,document.head.appendChild(t),t},Re=(e,t)=>{t.initialized||(t.styleElement=ae(),e.feed.style.display="flex",e.feed.style.willChange="transform",e.slides.forEach(o=>{let l=o.cloneNode(true);l.setAttribute("data-lazer-marquee-clone","true"),l.setAttribute("aria-hidden","true"),e.feed.appendChild(l),t.clonedSlides.push(l);}),t.initialized=true);},se=e=>{e.initialized&&(e.clonedSlides.forEach(t=>{t.remove();}),e.clonedSlides=[],e.initialized=false);},Oe=(e,t)=>{ae(),requestAnimationFrame(()=>{let o=e.feed.scrollWidth,l=e.marqueeSpeed??50,r=e.marqueeDirection??"left",a=o/2;if(a<=0||l<=0){console.warn("[lazer-slider] Invalid marquee values:",{distance:a,speed:l,scrollWidth:o});return}let f=`lazer-marquee-scroll ${a/l}s linear infinite ${r==="right"?"reverse":"normal"}`;e.feed.style.animation="none",e.feed.offsetWidth,e.feed.style.animation=f,e.feed.style.animationPlayState=t.marqueePaused?"paused":"running";});},W=(e,t)=>{Oe(e,t);},ce=(e,t)=>{t.feed.style.animation="",t.feed.style.animationPlayState="",t.feed.style.transform="",t.feed.style.willChange="";},k=(e,t)=>{e.marqueePaused=true,t.feed.style.animationPlayState="paused";},V=(e,t)=>{e.marqueePaused=false,t.feed.style.animationPlayState="running";},de=(e,t,o)=>{e.marquee&&(Re(e,o),W(e,t));},ue=(e,t,o)=>{!e.marquee||e.pauseOnHover===false||(e.feed.addEventListener("mouseenter",()=>k(t,e),{signal:o}),e.feed.addEventListener("mouseleave",()=>V(t,e),{signal:o}),e.feed.addEventListener("touchstart",()=>k(t,e),{passive:true,signal:o}),e.feed.addEventListener("touchend",()=>V(t,e),{signal:o}));};var me=e=>({initialized:false,clonedSlides:[],realSlides:[...e],clonesPerSide:0}),Pe=e=>{let t=O()?e.desktopSlidesPerView:e.mobileSlidesPerView;return !t||t==="auto"?1:Math.ceil(t)},fe=(e,t,o)=>{if(!e.loop||t.initialized)return;let l=t.realSlides,r=Pe(e);t.clonesPerSide=r;for(let a=l.length-r;a<l.length;a++){let i=l[a];if(!i)continue;let s=i.cloneNode(true);s.setAttribute("data-lazer-clone","prepend"),s.setAttribute("aria-hidden","true"),e.feed.insertBefore(s,e.feed.firstChild),t.clonedSlides.push(s);}for(let a=0;a<r;a++){let i=l[a];if(!i)continue;let s=i.cloneNode(true);s.setAttribute("data-lazer-clone","append"),s.setAttribute("aria-hidden","true"),e.feed.appendChild(s),t.clonedSlides.push(s);}requestAnimationFrame(()=>{let a=l[0];a&&(o?e.feed.scrollTop=a.offsetTop:e.feed.scrollLeft=a.offsetLeft);}),t.initialized=true;},U=(e,t,o,l,r,a,i)=>{if(!t.loop||!o.initialized)return;a(true);let s=o.realSlides,f=s.length;if(e==="next"){let m=s[0];m&&(l?t.feed.scrollTop=m.offsetTop:t.feed.scrollLeft=m.offsetLeft),r(0);}else {let m=s[f-1];m&&(l?t.feed.scrollTop=m.offsetTop:t.feed.scrollLeft=m.offsetLeft),r(f-1);}requestAnimationFrame(()=>{requestAnimationFrame(()=>{a(false),i();});});},pe=e=>{e.initialized&&(e.clonedSlides.forEach(t=>{t.remove();}),e.clonedSlides=[],e.initialized=false,e.clonesPerSide=0);};var j=(e,t,o)=>{if(t.autoplayIntervalId)return;let l=e.autoplayInterval??3e3;t.autoplayIntervalId=setInterval(()=>{t.autoplayPaused||o("next");},l);},K=e=>{e.autoplayIntervalId&&(clearInterval(e.autoplayIntervalId),e.autoplayIntervalId=null);},Se=e=>{e.autoplayPaused=true;},he=e=>{e.autoplayPaused=false;},be=(e,t,o)=>{!e.autoplay||e.pauseOnHover===false||(e.feed.addEventListener("mouseenter",()=>Se(t),{signal:o}),e.feed.addEventListener("mouseleave",()=>he(t),{signal:o}),e.feed.addEventListener("touchstart",()=>Se(t),{passive:true,signal:o}),e.feed.addEventListener("touchend",()=>he(t),{signal:o}));};var Q=(e,t,o)=>{if(e.scrollbarThumb)if(o){let l=t.height/e.feed.scrollHeight*100;e.scrollbarThumb.style.height=`${l}%`,e.scrollbarThumb.style.width="";}else {let l=t.width/e.feed.scrollWidth*100;e.scrollbarThumb.style.width=`${l}%`,e.scrollbarThumb.style.height="";}},Te=(e,t)=>{if(!(!e.scrollbarThumb||!e.scrollbarTrack))if(t){let o=e.scrollbarTrack.getBoundingClientRect().height,l=e.scrollbarThumb.getBoundingClientRect().height,r=o-l,a=e.feed.scrollHeight-e.feed.clientHeight,i=a>0?e.feed.scrollTop/a:0;e.scrollbarThumb.style.transform=`translateY(${r*i}px)`;}else {let o=e.scrollbarTrack.getBoundingClientRect().width,l=e.scrollbarThumb.getBoundingClientRect().width,r=o-l,a=e.feed.scrollWidth-e.feed.clientWidth,i=a>0?e.feed.scrollLeft/a:0;e.scrollbarThumb.style.transform=`translateX(${r*i}px)`;}};var J=(e,t,o,l=N,r)=>{let a=o?e.scrollTop:e.scrollLeft,i=Math.abs(t-a),s=Math.min(C.MAX_DURATION,Math.max(C.MIN_DURATION,i/C.SPEED_FACTOR)),f=performance.now(),m=h=>{let n=(h-f)/s,d=Math.min(n,1),E=l(d),S=a+(t-a)*E;o?e.scrollTop=S:e.scrollLeft=S,d<1?requestAnimationFrame(m):(o?e.scrollTop=t:e.scrollLeft=t,r?.());};requestAnimationFrame(m);},Y=e=>e.filter(t=>t.offsetParent!==null),Z=(e,t,o)=>{let l=o?e.desktopSlidesPerView:e.mobileSlidesPerView,r=e.slideGap??0;if(r>0&&(e.feed.style.gap=`${r}px`),!l||l==="auto"){e.slides.forEach(s=>{s.style.flex="",s.style.minWidth="",s.style.minHeight="";});return}let i=`calc((100% - ${r*(l-1)}px) / ${l})`;t?e.slides.forEach(s=>{s.style.flex=`0 0 ${i}`,s.style.minHeight=i,s.style.minWidth="";}):e.slides.forEach(s=>{s.style.flex=`0 0 ${i}`,s.style.minWidth=i,s.style.minHeight="";});},ve=(e,t,o,l)=>{let r=l?e.clientHeight:e.clientWidth;return !t||o!==r?{rect:e.getBoundingClientRect(),size:r}:{rect:t,size:o}};var qe=e=>{if(!e.feed)throw new Error("lazer-slider: feed element is required");if(!e.slides?.length)throw new Error("lazer-slider: slides array is required and must not be empty");if(e.feed.id||(e.feed.id=`lazer-slider-feed-${Math.random().toString(36).substr(2,9)}`),e.bulletsContainer&&!e.thumbs){let c=G({bulletsContainer:e.bulletsContainer,slides:e.slides,bulletClass:e.bulletsClass??"slider-bullet",bulletActiveClass:e.bulletsActiveClass??"active",feedId:e.feed.id});e.thumbs=c;}if(e.thumbsContainer&&!e.thumbs){let c=X({thumbsContainer:e.thumbsContainer,slides:e.slides,thumbClass:e.thumbsClass??"slider-thumb",thumbActiveClass:e.thumbsActiveClass??"active",feedId:e.feed.id,thumbImageSelector:e.thumbImageSelector??"img",thumbSize:e.thumbSize});e.thumbs=c;}let t=e.direction??"horizontal",o=t==="vertical",l=e.easing??N,r={currentSlideIndex:0,isScrolling:false,ticking:false,cachedFeedRect:null,lastWidth:0,updateThumbTimeout:null,scrollEndTimeout:null,abortController:new AbortController,autoplayIntervalId:null,autoplayPaused:false,marqueePaused:false,isLoopRepositioning:false},a=null,i=me(e.slides),s=ne(),f=()=>{let c=ve(e.feed,r.cachedFeedRect,r.lastWidth,o);return r.cachedFeedRect=c.rect,r.lastWidth=c.size,c.rect},m=(c,u)=>{J(e.feed,c,o,l,u);},h=(c,u)=>{J(e.feed,c,o,u??l);},n=()=>{if(r.isLoopRepositioning)return;let c=f(),u,T,b;if(o?(u=e.feed.scrollTop<=1,T=e.feed.scrollTop+c.height>=e.feed.scrollHeight-1,b=e.feed.scrollHeight<=c.height):(u=e.feed.scrollLeft<=1,T=e.feed.scrollLeft+c.width>=e.feed.scrollWidth-1,b=e.feed.scrollWidth<=c.width),e.scrollbarTrack&&(e.scrollbarTrack.style.display=b?"none":"block"),e.loop){z(e.prevSlideButton,!b,e.feed),z(e.nextSlideButton,!b,e.feed);return}z(e.prevSlideButton,!u&&!b,e.feed),z(e.nextSlideButton,!T&&!b,e.feed);},d=()=>{let c=f(),u=i.initialized?i.realSlides:Y(e.slides),T=u.filter(b=>{let p=b.getBoundingClientRect(),v=20;return o?p.bottom>c.top+v&&p.top<c.bottom-v:p.right>c.left+v&&p.left<c.right-v});if(T.length&&T[0]){let b=u.indexOf(T[0]);if(b!==-1){r.currentSlideIndex=b;let p=o?e.feed.scrollTop:e.feed.scrollLeft;e.onScroll?.({currentScroll:p,currentSlideIndex:r.currentSlideIndex});}}},E=c=>{if(!e.thumbs)return;let u=e.thumbs.indexOf(c);if(u===-1||!e.slides[u])return;r.currentSlideIndex=u,F(e.thumbs,u),r.isScrolling=true,r.updateThumbTimeout&&clearTimeout(r.updateThumbTimeout),r.updateThumbTimeout=setTimeout(()=>{r.isScrolling=false;},C.THUMB_UPDATE_DELAY);let T=o?e.slides[u].offsetTop:e.slides[u].offsetLeft;m(T);},S=c=>{let u=i.initialized?i.realSlides:Y(e.slides),T=O()?e.desktopSlidesPerScroll??1:e.mobileSlidesPerScroll??1,b=u.length;d();let p,v=false;if(c==="prev")if(e.loop&&i.initialized&&r.currentSlideIndex===0){let I=i.clonedSlides.filter(D=>D.getAttribute("data-lazer-clone")==="prepend");p=I[I.length-1],v=true;}else r.currentSlideIndex=Math.max(0,r.currentSlideIndex-T),p=u[r.currentSlideIndex];else e.loop&&i.initialized&&r.currentSlideIndex>=b-1?(p=i.clonedSlides.filter(D=>D.getAttribute("data-lazer-clone")==="append")[0],v=true):(r.currentSlideIndex=Math.min(b-1,r.currentSlideIndex+T),p=u[r.currentSlideIndex]);if(!p)return;let x=o?e.feed.scrollTop:e.feed.scrollLeft;e.onScrollStart?.({currentScroll:x,target:p,direction:c});let _=o?p.offsetTop:p.offsetLeft;v?m(_,()=>{U(c,e,i,o,I=>{r.currentSlideIndex=I;},I=>{r.isLoopRepositioning=I;},n);}):m(_);},P=()=>{Te(e,o),n(),d(),r.isScrolling||F(e.thumbs,r.currentSlideIndex),r.scrollEndTimeout&&clearTimeout(r.scrollEndTimeout),r.scrollEndTimeout=setTimeout(()=>{r.isScrolling=false;let c=o?e.feed.scrollTop:e.feed.scrollLeft;e.onScrollEnd?.({currentScroll:c,currentSlideIndex:r.currentSlideIndex});},C.SCROLL_END_DELAY);},w=()=>{r.ticking||(requestAnimationFrame(()=>{P(),r.ticking=false;}),r.ticking=true);},q=()=>{r.cachedFeedRect=null,y();},B=()=>{let{signal:c}=r.abortController;window.addEventListener("resize",q),e.feed.addEventListener("scroll",w,{passive:true,signal:c}),e.prevSlideButton&&e.prevSlideButton.addEventListener("click",()=>S("prev"),{signal:c}),e.nextSlideButton&&e.nextSlideButton.addEventListener("click",()=>S("next"),{signal:c}),e.thumbs?.length&&(e.thumbs[0]?.classList.add("active"),e.thumbs.forEach(u=>{u.addEventListener("click",()=>E(u),{signal:c});})),te(e.feed,()=>S("prev"),()=>S("next"),c,t),e.enableDragToScroll!==false&&(a=le({feed:e.feed,slides:e.slides,abortSignal:c,smoothScrollTo:h,onDragEnd:u=>{if(u&&e.loop&&i.initialized){let T=u.getAttribute("data-lazer-clone");if(T){let b=T==="append"?"next":"prev";setTimeout(()=>{U(b,e,i,o,p=>{r.currentSlideIndex=p;},p=>{r.isLoopRepositioning=p;},n);},50);}}d(),F(e.thumbs,r.currentSlideIndex);},direction:t,loop:e.loop})),be(e,r,c),ue(e,r,c);},R=c=>{let u=i.initialized?i.realSlides:Y(e.slides),T=Math.max(0,Math.min(c,u.length-1)),b=u[T];if(!b)return;r.currentSlideIndex=T,F(e.thumbs,T);let p=o?b.offsetTop:b.offsetLeft;m(p);},y=()=>{r.cachedFeedRect=null,Z(e,o,O()),Q(e,f(),o),n(),e.marquee&&!r.marqueePaused&&W(e,r);},g=()=>{K(r),ce(r,e),r.abortController.abort(),window.removeEventListener("resize",q),r.updateThumbTimeout&&clearTimeout(r.updateThumbTimeout),r.scrollEndTimeout&&clearTimeout(r.scrollEndTimeout),a&&ie(a),pe(i),se(s),r.cachedFeedRect=null;},M=()=>{e.marquee?r.marqueePaused?V(r,e):W(e,r):e.autoplay&&j(e,r,S);},L=()=>{e.marquee?k(r,e):K(r);};return ee(e),Z(e,o,O()),e.marquee?de(e,r,s):(fe(e,i,o),e.autoplay&&j(e,r,S)),n(),B(),Q(e,f(),o),{goToIndex:R,refresh:y,unload:g,play:M,pause:L,next:()=>S("next"),prev:()=>S("prev")}};exports.createSlider=qe;exports.easeInOutCubic=Le;exports.easeOutCubic=H;exports.easeOutExpo=N;exports.easeOutQuad=ge;exports.generateBullets=G;exports.generateThumbs=X;exports.linear=Ae;
|
|
1
|
+
'use strict';var H={MIN_DURATION:400,MAX_DURATION:1e3,SPEED_FACTOR:1.5,SCROLL_END_DELAY:50,THUMB_UPDATE_DELAY:500},ve="(min-width: 64rem)",N=()=>window.matchMedia(ve).matches;var k=e=>e===1?1:1-Math.pow(2,-10*e),w=e=>1-Math.pow(1-e,3),Ee=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2,Le=e=>1-(1-e)*(1-e),Ae=e=>e;var ye=()=>`slider-${Math.random().toString(36).substring(2,9)}`,le=e=>{let{feed:t,prevSlideButton:l,nextSlideButton:i,thumbs:o,slides:c}=e;t.id||(t.id=ye()),t.setAttribute("role","region"),t.setAttribute("aria-label","Carousel"),t.setAttribute("aria-roledescription","carousel"),t.removeAttribute("tabindex"),c.forEach((r,a)=>{r.setAttribute("role","group"),r.setAttribute("aria-roledescription","slide"),r.setAttribute("aria-label",`Slide ${a+1} of ${c.length}`);}),l&&(l.setAttribute("aria-label","Previous slide"),l.setAttribute("aria-controls",t.id),l.setAttribute("tabindex","0"),l.tagName!=="BUTTON"&&l.setAttribute("role","button")),i&&(i.setAttribute("aria-label","Next slide"),i.setAttribute("aria-controls",t.id),i.setAttribute("tabindex","0"),i.tagName!=="BUTTON"&&i.setAttribute("role","button")),o?.length&&o.forEach((r,a)=>{r.tagName!=="BUTTON"&&r.setAttribute("role","button"),r.setAttribute("aria-label",`Go to slide ${a+1}`),r.setAttribute("tabindex","0"),r.setAttribute("aria-controls",t.id);});},W=(e,t,l)=>{if(!e)return;!t&&e===document.activeElement&&l&&l.focus();let i="opacity 0.3s ease",o=t?"1":"0";Object.assign(e.style,{opacity:o,transition:i,pointerEvents:t?"auto":"none"}),t?(e.removeAttribute("aria-hidden"),e.setAttribute("tabindex","0")):(e.setAttribute("aria-hidden","true"),e.setAttribute("tabindex","-1")),t?e.style.visibility="visible":setTimeout(()=>{e.style.opacity==="0"&&(e.style.visibility="hidden");},300);},F=(e,t,l="active")=>{e?.length&&e.forEach((i,o)=>{let c=o===t;i.classList.toggle(l,c),i.setAttribute("aria-selected",c.toString());});},re=(e,t,l,i,o="horizontal")=>{let c=o==="vertical",r=c?"ArrowUp":"ArrowLeft",a=c?"ArrowDown":"ArrowRight";e.addEventListener("keydown",u=>{switch(u.key){case r:u.preventDefault(),t();break;case a:u.preventDefault(),l();break}},{signal:i}),e.hasAttribute("tabindex")||e.setAttribute("tabindex","0");};var D={FRICTION:.94,MIN_VELOCITY:.3,MOMENTUM_RATIO:.8,VELOCITY_SMOOTHING:.4,EDGE_RESISTANCE:.3,MAX_EDGE_OVERSCROLL:100,SHORT_SWIPE_VELOCITY:.5,BOUNCE_DURATION:400},ge=()=>({isDragging:false,startX:0,startY:0,startScrollLeft:0,startScrollTop:0,velocity:0,lastX:0,lastY:0,lastTime:0,momentumId:null}),xe=()=>({...ge(),velocityHistory:[],dragDistance:0,dragStartTime:0}),$=(e,t,l="horizontal")=>{let i=e.getBoundingClientRect(),o=l==="vertical",c=o?i.top:i.left,r=null,a=1/0;for(let u of t){if(u.offsetParent===null)continue;let f=u.getBoundingClientRect(),p=o?f.top:f.left,E=Math.abs(c-p);E<a&&(a=E,r=u);}return r},Ie=(e,t,l,i="horizontal")=>{let o=e.getBoundingClientRect(),c=i==="vertical",r=c?o.top:o.left,a=t.filter(n=>n.offsetParent!==null);if(a.length===0)return null;let u=0,f=1/0;a.forEach((n,S)=>{let L=n.getBoundingClientRect(),v=c?L.top:L.left,O=Math.abs(r-v);O<f&&(f=O,u=S);});let p=2,E=u;return Math.abs(l)>p&&(l>0?E=Math.min(u+1,a.length-1):E=Math.max(u-1,0)),a[E]??null},Me=e=>{if(e.length===0)return 0;let t=0,l=0;return e.forEach((i,o)=>{let c=o+1;t+=i*c,l+=c;}),t/l},De=(e,t,l,i,o,c="horizontal",r=false)=>{let a=c==="vertical",u=e.velocity*D.MOMENTUM_RATIO,f=()=>{if(Math.abs(u)<D.MIN_VELOCITY){e.momentumId=null;let S=$(t,l,c);if(S){let L=a?S.offsetTop:S.offsetLeft;i(L,w);}o?.(S);return}let p=a?t.scrollHeight-t.clientHeight:t.scrollWidth-t.clientWidth,n=(a?t.scrollTop:t.scrollLeft)+u;r||(n<0||n>p)&&(u*=.5),a?t.scrollTop=Math.max(0,Math.min(p,n)):t.scrollLeft=Math.max(0,Math.min(p,n)),u*=D.FRICTION,e.momentumId=requestAnimationFrame(f);};e.momentumId=requestAnimationFrame(f);},ie=e=>"touches"in e?e.touches[0]?.clientX??0:e.clientX,ne=e=>"touches"in e?e.touches[0]?.clientY??0:e.clientY,Ce=(e,t)=>t==="vertical"?ne(e):ie(e),ae=e=>{let {feed:t,slides:l,abortSignal:i,smoothScrollTo:o,onDragStart:c,onDragEnd:r,direction:a="horizontal",loop:u=false,touchRatio:f=1,shortSwipeThreshold:p=300,swipeDistanceThreshold:E=10}=e,n=xe(),S=a==="vertical",L=()=>{if(!u)return l;let A=[],M=t.children;for(let C=0;C<M.length;C++){let x=M[C];(l.includes(x)||x.hasAttribute("data-lazer-clone"))&&A.push(x);}return A.length>0?A:l},v=0,U=()=>{v=S?t.scrollHeight-t.clientHeight:t.scrollWidth-t.clientWidth,S?t.clientHeight:t.clientWidth;},B=A=>{n.momentumId!==null&&(cancelAnimationFrame(n.momentumId),n.momentumId=null),U(),c?.(),n.isDragging=true,n.startX=ie(A),n.startY=ne(A),n.startScrollLeft=t.scrollLeft,n.startScrollTop=t.scrollTop,n.velocity=0,n.lastX=n.startX,n.lastY=n.startY,n.lastTime=performance.now(),n.velocityHistory=[],n.dragDistance=0,n.dragStartTime=performance.now(),t.style.userSelect="none",t.style.cursor="grabbing",t.classList.add("is-dragging"),A.type==="mousedown"&&A.preventDefault();},X=A=>{if(!n.isDragging)return;let M=Ce(A,a),C=S?n.startY:n.startX,x=S?n.lastY:n.lastX,s=S?n.startScrollTop:n.startScrollLeft,d=performance.now(),b=d-n.lastTime,h=(C-M)*f,m=s+h;if(n.dragDistance=Math.abs(h),!u){if(m<0){let T=Math.abs(m),y=1-Math.min(T/D.MAX_EDGE_OVERSCROLL,1)*(1-D.EDGE_RESISTANCE);m=-T*y;}else if(m>v){let T=m-v,y=1-Math.min(T/D.MAX_EDGE_OVERSCROLL,1)*(1-D.EDGE_RESISTANCE);m=v+T*y;}}if(S?t.scrollTop=m:t.scrollLeft=m,b>0){let T=(x-M)/b*16;if(n.velocityHistory.length>0){let y=n.velocity;n.velocity=y*(1-D.VELOCITY_SMOOTHING)+T*D.VELOCITY_SMOOTHING;}else n.velocity=T;n.velocityHistory.push(T),n.velocityHistory.length>5&&n.velocityHistory.shift();}S?n.lastY=M:n.lastX=M,n.lastTime=d,A.type==="touchmove"&&A.preventDefault();},P=()=>{if(!n.isDragging)return;n.isDragging=false,t.style.userSelect="",t.style.cursor="",t.classList.remove("is-dragging");let M=performance.now()-n.dragStartTime<p&&n.dragDistance>E,C=Me(n.velocityHistory),x=L();if(!u){let s=S?t.scrollTop:t.scrollLeft;if(s<0||s>v){let d=s<0?0:v,b=s,h=performance.now(),m=()=>{let T=performance.now()-h,y=Math.min(T/D.BOUNCE_DURATION,1),R=w(y),g=b+(d-b)*R;if(S?t.scrollTop=g:t.scrollLeft=g,y<1)requestAnimationFrame(m);else {let I=$(t,x,a);if(I){let Te=S?I.offsetTop:I.offsetLeft;o(Te,w);}r?.(I);}};requestAnimationFrame(m);return}}if(M||Math.abs(C)>D.SHORT_SWIPE_VELOCITY){let s=Ie(t,x,C,a);if(s){let d=S?s.offsetTop:s.offsetLeft;o(d,w),r?.(s);}else r?.(null);}else if(Math.abs(n.velocity)>1&&!n.isLoopDragHandled)De(n,t,x,o,r,a,u);else {let s=$(t,x,a);if(!n.isLoopDragHandled){if(s){let d=S?s.offsetTop:s.offsetLeft;o(d,w);}r?.(s);}}};return t.addEventListener("mousedown",B,{signal:i}),document.addEventListener("mousemove",X,{signal:i}),document.addEventListener("mouseup",P,{signal:i}),t.addEventListener("touchstart",B,{passive:true,signal:i}),t.addEventListener("touchmove",X,{passive:false,signal:i}),t.addEventListener("touchend",P,{signal:i}),t.addEventListener("touchcancel",P,{signal:i}),document.addEventListener("mouseleave",P,{signal:i}),t.style.cursor="grab",n},ce=e=>{e.momentumId!==null&&(cancelAnimationFrame(e.momentumId),e.momentumId=null);};var q=({bulletsContainer:e,slides:t,bulletClass:l,bulletActiveClass:i,feedId:o})=>{if(!e||!(e instanceof HTMLElement))throw new Error("Invalid bulletsContainer: must be a valid HTMLElement");if(!Array.isArray(t)||t.length===0)throw new Error("Invalid slides: must be a non-empty array");if(!o||typeof o!="string")throw new Error("Invalid feedId: must be a non-empty string");if(!l||typeof l!="string")throw new Error("Invalid bulletClass: must be a non-empty string");e.innerHTML="",e.setAttribute("role","tablist"),e.setAttribute("aria-label","Slide navigation");let c=t.map((a,u)=>({slide:a,originalIndex:u})).filter(({slide:a})=>a.offsetParent!==null);return c.length===0?(console.warn("No visible slides found"),[]):c.map(({slide:a,originalIndex:u},f)=>{let p=document.createElement("button");return p.type="button",p.classList.add(l),f===0&&p.classList.add(i),p.setAttribute("role","tab"),p.setAttribute("aria-selected",f===0?"true":"false"),p.setAttribute("aria-controls",o),p.setAttribute("aria-label",`Go to slide ${f+1}`),p.setAttribute("data-slide-index",String(f)),e.appendChild(p),p})};var j=({thumbsContainer:e,slides:t,thumbClass:l,thumbActiveClass:i,feedId:o,thumbImageSelector:c="img",thumbSize:r})=>{if(!e||!(e instanceof HTMLElement))throw new Error("Invalid thumbsContainer: must be a valid HTMLElement");if(!Array.isArray(t)||t.length===0)throw new Error("Invalid slides: must be a non-empty array");if(!o||typeof o!="string")throw new Error("Invalid feedId: must be a non-empty string");if(!l||typeof l!="string")throw new Error("Invalid thumbClass: must be a non-empty string");e.innerHTML="",e.setAttribute("role","tablist"),e.setAttribute("aria-label","Slide thumbnails");let a=t.map((f,p)=>({slide:f,originalIndex:p})).filter(({slide:f})=>f.offsetParent!==null);return a.length===0?(console.warn("No visible slides found"),[]):a.map(({slide:f,originalIndex:p},E)=>{let n=document.createElement("button");n.type="button",n.classList.add(l),E===0&&n.classList.add(i);let S=f.querySelector(c);if(S?.src){let L=document.createElement("img");L.src=S.src,L.alt=S.alt||`Slide ${E+1} thumbnail`,L.draggable=false,r&&(L.style.width=`${r.width}px`,L.style.height=`${r.height}px`,L.style.objectFit="cover"),n.appendChild(L);}return n.setAttribute("role","tab"),n.setAttribute("aria-selected",E===0?"true":"false"),n.setAttribute("aria-controls",o),n.setAttribute("aria-label",`Go to slide ${E+1}`),n.setAttribute("data-slide-index",String(E)),e.appendChild(n),n})};var _=(e,t,l,i)=>{if(t.autoScrollAnimationId!==null)return;t.autoScrollPaused=false,t.autoScrollStopped=false,t.autoScrollLastTimestamp=performance.now();let o=e.autoScrollSpeed??50,c=e.autoScrollDirection??"forward",r=a=>{if(t.autoScrollPaused||t.autoScrollStopped){t.autoScrollAnimationId=null;return}let u=a-t.autoScrollLastTimestamp;t.autoScrollLastTimestamp=a,u>100&&(u=100);let f=o*(u/1e3);c==="backward"&&(f=-f),i?e.feed.scrollTop+=f:e.feed.scrollLeft+=f,Re(e,l,i,c),t.autoScrollAnimationId=requestAnimationFrame(r);};t.autoScrollAnimationId=requestAnimationFrame(r);},Re=(e,t,l,i)=>{if(!t.initialized||t.realSlides.length===0)return;let o=e.feed;if(i==="forward"){let c=l?o.scrollHeight-o.clientHeight:o.scrollWidth-o.clientWidth;if((l?o.scrollTop:o.scrollLeft)>=c-1){let a=t.realSlides[0];a&&(l?o.scrollTop=a.offsetTop:o.scrollLeft=a.offsetLeft);}}else if((l?o.scrollTop:o.scrollLeft)<=1){let r=t.realSlides[t.realSlides.length-1];r&&(l?o.scrollTop=r.offsetTop:o.scrollLeft=r.offsetLeft);}},K=e=>{e.autoScrollAnimationId!==null&&(cancelAnimationFrame(e.autoScrollAnimationId),e.autoScrollAnimationId=null),e.autoScrollResumeTimeout!==null&&(clearTimeout(e.autoScrollResumeTimeout),e.autoScrollResumeTimeout=null);},z=e=>{e.autoScrollPaused=true,e.autoScrollAnimationId!==null&&(cancelAnimationFrame(e.autoScrollAnimationId),e.autoScrollAnimationId=null);},G=(e,t,l,i)=>{t.autoScrollStopped||(t.autoScrollLastTimestamp=performance.now(),t.autoScrollPaused=false,t.autoScrollAnimationId===null&&_(e,t,l,i));},Y=(e,t,l,i)=>{if(t.autoScrollStopped)return;t.autoScrollResumeTimeout!==null&&clearTimeout(t.autoScrollResumeTimeout);let o=e.autoScrollStartDelay??0;o>0?t.autoScrollResumeTimeout=setTimeout(()=>{t.autoScrollResumeTimeout=null,G(e,t,l,i);},o):G(e,t,l,i);},se=(e,t,l,i,o)=>{if(!e.autoScroll)return;let c=e.stopOnMouseEnter!==false,r=e.stopOnFocusIn!==false;c&&(e.feed.addEventListener("mouseenter",()=>z(t),{signal:o}),e.feed.addEventListener("mouseleave",()=>Y(e,t,l,i),{signal:o})),r&&(e.feed.addEventListener("focusin",()=>z(t),{signal:o}),e.feed.addEventListener("focusout",()=>Y(e,t,l,i),{signal:o})),e.feed.addEventListener("touchstart",()=>z(t),{passive:true,signal:o}),e.feed.addEventListener("touchend",()=>Y(e,t,l,i),{signal:o});};var de=e=>({initialized:false,clonedSlides:[],realSlides:[...e],clonesPerSide:0}),He=e=>{let t=N()?e.desktopSlidesPerView:e.mobileSlidesPerView;if(e.autoScroll){let l=!t||t==="auto"?3:Math.ceil(t)+1;return Math.min(l,e.slides.length)}return !t||t==="auto"?1:Math.ceil(t)},Q=(e,t,l)=>{if(!e.loop||t.initialized)return;let i=t.realSlides,o=He(e);t.clonesPerSide=o;for(let c=i.length-o;c<i.length;c++){let r=i[c];if(!r)continue;let a=r.cloneNode(true);a.setAttribute("data-lazer-clone","prepend"),a.setAttribute("aria-hidden","true"),e.feed.insertBefore(a,e.feed.firstChild),t.clonedSlides.push(a);}for(let c=0;c<o;c++){let r=i[c];if(!r)continue;let a=r.cloneNode(true);a.setAttribute("data-lazer-clone","append"),a.setAttribute("aria-hidden","true"),e.feed.appendChild(a),t.clonedSlides.push(a);}requestAnimationFrame(()=>{let c=i[0];c&&(l?e.feed.scrollTop=c.offsetTop:e.feed.scrollLeft=c.offsetLeft);}),t.initialized=true;},ue=(e,t,l,i,o,c,r)=>{if(!t.loop||!l.initialized)return;c(true);let a=l.realSlides,u=a.length;if(e==="next"){let f=a[0];f&&(i?t.feed.scrollTop=f.offsetTop:t.feed.scrollLeft=f.offsetLeft),o(0);}else {let f=a[u-1];f&&(i?t.feed.scrollTop=f.offsetTop:t.feed.scrollLeft=f.offsetLeft),o(u-1);}requestAnimationFrame(()=>{requestAnimationFrame(()=>{c(false),r();});});},fe=e=>{e.initialized&&(e.clonedSlides.forEach(t=>{t.remove();}),e.clonedSlides=[],e.initialized=false,e.clonesPerSide=0);};var J=(e,t,l)=>{if(t.autoplayIntervalId)return;let i=e.autoplayInterval??3e3;t.autoplayIntervalId=setInterval(()=>{t.autoplayPaused||l("next");},i);},Z=e=>{e.autoplayIntervalId&&(clearInterval(e.autoplayIntervalId),e.autoplayIntervalId=null);},me=e=>{e.autoplayPaused=true;},pe=e=>{e.autoplayPaused=false;},Se=(e,t,l)=>{!e.autoplay||e.pauseOnHover===false||(e.feed.addEventListener("mouseenter",()=>me(t),{signal:l}),e.feed.addEventListener("mouseleave",()=>pe(t),{signal:l}),e.feed.addEventListener("touchstart",()=>me(t),{passive:true,signal:l}),e.feed.addEventListener("touchend",()=>pe(t),{signal:l}));};var ee=(e,t,l)=>{if(e.scrollbarThumb)if(l){let i=t.height/e.feed.scrollHeight*100;e.scrollbarThumb.style.height=`${i}%`,e.scrollbarThumb.style.width="";}else {let i=t.width/e.feed.scrollWidth*100;e.scrollbarThumb.style.width=`${i}%`,e.scrollbarThumb.style.height="";}},he=(e,t)=>{if(!(!e.scrollbarThumb||!e.scrollbarTrack))if(t){let l=e.scrollbarTrack.getBoundingClientRect().height,i=e.scrollbarThumb.getBoundingClientRect().height,o=l-i,c=e.feed.scrollHeight-e.feed.clientHeight,r=c>0?e.feed.scrollTop/c:0;e.scrollbarThumb.style.transform=`translateY(${o*r}px)`;}else {let l=e.scrollbarTrack.getBoundingClientRect().width,i=e.scrollbarThumb.getBoundingClientRect().width,o=l-i,c=e.feed.scrollWidth-e.feed.clientWidth,r=c>0?e.feed.scrollLeft/c:0;e.scrollbarThumb.style.transform=`translateX(${o*r}px)`;}};var te=(e,t,l,i=k,o,c)=>{let r=l?e.scrollTop:e.scrollLeft,a=Math.abs(t-r),u=Math.min(H.MAX_DURATION,Math.max(H.MIN_DURATION,a/H.SPEED_FACTOR)),f=performance.now(),p=E=>{if(c?.cancelled)return;let n=(E-f)/u,S=Math.min(n,1),L=i(S),v=r+(t-r)*L;l?e.scrollTop=v:e.scrollLeft=v,S<1?requestAnimationFrame(p):(l?e.scrollTop=t:e.scrollLeft=t,o?.());};requestAnimationFrame(p);},V=e=>e.filter(t=>t.offsetParent!==null),oe=(e,t,l)=>{let i=l?e.desktopSlidesPerView:e.mobileSlidesPerView,o=e.slideGap??0;if(o>0&&(e.feed.style.gap=`${o}px`),!i||i==="auto"){e.slides.forEach(a=>{a.style.flex="",a.style.minWidth="",a.style.minHeight="";});return}let r=`calc((100% - ${o*(i-1)}px) / ${i})`;t?e.slides.forEach(a=>{a.style.flex=`0 0 ${r}`,a.style.minHeight=r,a.style.minWidth="";}):e.slides.forEach(a=>{a.style.flex=`0 0 ${r}`,a.style.minWidth=r,a.style.minHeight="";});},be=(e,t,l,i)=>{let o=i?e.clientHeight:e.clientWidth;return !t||l!==o?{rect:e.getBoundingClientRect(),size:o}:{rect:t,size:l}};var we=e=>{if(!e.feed)throw new Error("lazer-slider: feed element is required");if(!e.slides?.length)throw new Error("lazer-slider: slides array is required and must not be empty");if(e.feed.id||(e.feed.id=`lazer-slider-feed-${Math.random().toString(36).substr(2,9)}`),e.bulletsContainer&&!e.thumbs){let s=q({bulletsContainer:e.bulletsContainer,slides:e.slides,bulletClass:e.bulletsClass??"slider-bullet",bulletActiveClass:e.bulletsActiveClass??"active",feedId:e.feed.id});e.thumbs=s;}if(e.thumbsContainer&&!e.thumbs){let s=j({thumbsContainer:e.thumbsContainer,slides:e.slides,thumbClass:e.thumbsClass??"slider-thumb",thumbActiveClass:e.thumbsActiveClass??"active",feedId:e.feed.id,thumbImageSelector:e.thumbImageSelector??"img",thumbSize:e.thumbSize});e.thumbs=s;}let t=e.direction??"horizontal",l=t==="vertical",i=e.easing??k,o={currentSlideIndex:0,isScrolling:false,ticking:false,cachedFeedRect:null,lastWidth:0,updateThumbTimeout:null,scrollEndTimeout:null,abortController:new AbortController,autoplayIntervalId:null,autoplayPaused:false,autoScrollAnimationId:null,autoScrollPaused:false,autoScrollLastTimestamp:0,autoScrollStopped:false,autoScrollResumeTimeout:null,isLoopRepositioning:false},c=null,r=de(e.slides),a={cancelled:false},u=null,f=()=>{let s=be(e.feed,o.cachedFeedRect,o.lastWidth,l);return o.cachedFeedRect=s.rect,o.lastWidth=s.size,s.rect},p=(s,d)=>{te(e.feed,s,l,i,d);},E=(s,d)=>{a.cancelled=true,a={cancelled:false},te(e.feed,s,l,d??i,void 0,a);},n=()=>{if(o.isLoopRepositioning)return;let s=f(),d,b,h;if(l?(d=e.feed.scrollTop<=1,b=e.feed.scrollTop+s.height>=e.feed.scrollHeight-1,h=e.feed.scrollHeight<=s.height):(d=e.feed.scrollLeft<=1,b=e.feed.scrollLeft+s.width>=e.feed.scrollWidth-1,h=e.feed.scrollWidth<=s.width),e.scrollbarTrack&&(e.scrollbarTrack.style.display=h?"none":"block"),e.loop){W(e.prevSlideButton,!h,e.feed),W(e.nextSlideButton,!h,e.feed);return}W(e.prevSlideButton,!d&&!h,e.feed),W(e.nextSlideButton,!b&&!h,e.feed);},S=()=>{let s=f(),d=r.initialized?r.realSlides:V(e.slides),b=d.filter(h=>{let m=h.getBoundingClientRect(),T=20;return l?m.bottom>s.top+T&&m.top<s.bottom-T:m.right>s.left+T&&m.left<s.right-T});if(b.length&&b[0]){let h=d.indexOf(b[0]);if(h!==-1){o.currentSlideIndex=h;let m=l?e.feed.scrollTop:e.feed.scrollLeft;e.onScroll?.({currentScroll:m,currentSlideIndex:o.currentSlideIndex});}}},L=s=>{if(!e.thumbs)return;let d=e.thumbs.indexOf(s);if(d===-1||!e.slides[d])return;o.currentSlideIndex=d,F(e.thumbs,d),o.isScrolling=true,o.updateThumbTimeout&&clearTimeout(o.updateThumbTimeout),o.updateThumbTimeout=setTimeout(()=>{o.isScrolling=false;},H.THUMB_UPDATE_DELAY);let b=l?e.slides[d].offsetTop:e.slides[d].offsetLeft;p(b);},v=s=>{let d=r.initialized?r.realSlides:V(e.slides),b=N()?e.desktopSlidesPerScroll??1:e.mobileSlidesPerScroll??1,h=d.length;S();let m,T=false;if(s==="prev")if(e.loop&&r.initialized&&o.currentSlideIndex===0){let g=r.clonedSlides.filter(I=>I.getAttribute("data-lazer-clone")==="prepend");m=g[g.length-1],T=true;}else o.currentSlideIndex=Math.max(0,o.currentSlideIndex-b),m=d[o.currentSlideIndex];else e.loop&&r.initialized&&o.currentSlideIndex>=h-1?(m=r.clonedSlides.filter(I=>I.getAttribute("data-lazer-clone")==="append")[0],T=true):(o.currentSlideIndex=Math.min(h-1,o.currentSlideIndex+b),m=d[o.currentSlideIndex]);if(!m)return;let y=l?e.feed.scrollTop:e.feed.scrollLeft;e.onScrollStart?.({currentScroll:y,target:m,direction:s});let R=l?m.offsetTop:m.offsetLeft;T?p(R,()=>{ue(s,e,r,l,g=>{o.currentSlideIndex=g;},g=>{o.isLoopRepositioning=g;},n);}):p(R);},O=()=>{he(e,l),n(),S(),o.isScrolling||F(e.thumbs,o.currentSlideIndex),o.scrollEndTimeout&&clearTimeout(o.scrollEndTimeout),o.scrollEndTimeout=setTimeout(()=>{o.isScrolling=false;let s=l?e.feed.scrollTop:e.feed.scrollLeft;e.onScrollEnd?.({currentScroll:s,currentSlideIndex:o.currentSlideIndex});},H.SCROLL_END_DELAY);},U=()=>{o.ticking||(requestAnimationFrame(()=>{O(),o.ticking=false;}),o.ticking=true);},B=()=>{let s=o.currentSlideIndex;o.cachedFeedRect=null;let d=()=>{let h=(r.initialized?r.realSlides:V(e.slides))[s];if(h){let m=l?h.offsetTop:h.offsetLeft;l?e.feed.scrollTop=m:e.feed.scrollLeft=m;}};d(),u&&clearTimeout(u),u=setTimeout(()=>{A(),d();},150);},X=()=>{let{signal:s}=o.abortController;window.addEventListener("resize",B),e.feed.addEventListener("scroll",U,{passive:true,signal:s}),e.prevSlideButton&&e.prevSlideButton.addEventListener("click",()=>v("prev"),{signal:s}),e.nextSlideButton&&e.nextSlideButton.addEventListener("click",()=>v("next"),{signal:s}),e.thumbs?.length&&(e.thumbs[0]?.classList.add("active"),e.thumbs.forEach(d=>{d.addEventListener("click",()=>L(d),{signal:s});})),re(e.feed,()=>v("prev"),()=>v("next"),s,t),e.enableDragToScroll!==false&&(c=ae({feed:e.feed,slides:e.slides,abortSignal:s,smoothScrollTo:E,onDragStart:()=>{e.autoScroll&&z(o);},onDragEnd:d=>{let b=d?.getAttribute("data-lazer-clone");if(!!(b&&e.loop&&r.initialized)&&d){let m=r.realSlides,T=0,y;if(b==="prepend"){let g=r.clonedSlides.filter(I=>I.getAttribute("data-lazer-clone")==="prepend").indexOf(d);T=m.length-r.clonesPerSide+g,y=m[T];}else if(b==="append"){let g=r.clonedSlides.filter(I=>I.getAttribute("data-lazer-clone")==="append").indexOf(d);T=g,y=m[g];}if(y){o.currentSlideIndex=T;let R=l?y.offsetTop:y.offsetLeft;setTimeout(()=>{a.cancelled=true,l?e.feed.scrollTop=R:e.feed.scrollLeft=R;},H.MIN_DURATION),F(e.thumbs,o.currentSlideIndex);}}else S(),F(e.thumbs,o.currentSlideIndex);e.autoScroll&&!o.autoScrollStopped&&(e.stopOnInteraction?o.autoScrollStopped=true:Y(e,o,r,l));},direction:t,loop:e.loop})),Se(e,o,s),se(e,o,r,l,s);},P=s=>{let d=r.initialized?r.realSlides:V(e.slides),b=Math.max(0,Math.min(s,d.length-1)),h=d[b];if(!h)return;o.currentSlideIndex=b,F(e.thumbs,b);let m=l?h.offsetTop:h.offsetLeft;p(m);},A=()=>{o.cachedFeedRect=null,oe(e,l,N()),ee(e,f(),l),n(),e.autoScroll&&!o.autoScrollPaused&&!o.autoScrollStopped&&(K(o),_(e,o,r,l));},M=()=>{Z(o),K(o),o.abortController.abort(),window.removeEventListener("resize",B),o.updateThumbTimeout&&clearTimeout(o.updateThumbTimeout),o.scrollEndTimeout&&clearTimeout(o.scrollEndTimeout),u&&clearTimeout(u),c&&ce(c),fe(r),o.cachedFeedRect=null;},C=()=>{e.autoScroll?(o.autoScrollStopped=false,o.autoScrollPaused?G(e,o,r,l):_(e,o,r,l)):e.autoplay&&J(e,o,v);},x=()=>{e.autoScroll?z(o):Z(o);};if(le(e),oe(e,l,N()),e.autoScroll){e.loop=true,Q(e,r,l);let s=e.autoScrollStartDelay??0;s>0?o.autoScrollResumeTimeout=setTimeout(()=>{o.autoScrollResumeTimeout=null,_(e,o,r,l);},s):requestAnimationFrame(()=>{requestAnimationFrame(()=>{_(e,o,r,l);});});}else Q(e,r,l),e.autoplay&&J(e,o,v);return n(),X(),ee(e,f(),l),{goToIndex:P,refresh:A,unload:M,play:C,pause:x,next:()=>v("next"),prev:()=>v("prev")}};exports.createSlider=we;exports.easeInOutCubic=Ee;exports.easeOutCubic=w;exports.easeOutExpo=k;exports.easeOutQuad=Le;exports.generateBullets=q;exports.generateThumbs=j;exports.linear=Ae;
|
package/dist/index.d.cts
CHANGED
|
@@ -11,9 +11,9 @@ type SliderNavDirection = 'prev' | 'next';
|
|
|
11
11
|
*/
|
|
12
12
|
type SliderDirection = 'horizontal' | 'vertical';
|
|
13
13
|
/**
|
|
14
|
-
* Direction of
|
|
14
|
+
* Direction of auto-scroll
|
|
15
15
|
*/
|
|
16
|
-
type
|
|
16
|
+
type AutoScrollDirection = 'forward' | 'backward';
|
|
17
17
|
/**
|
|
18
18
|
* Parameters passed to scroll start callback
|
|
19
19
|
*/
|
|
@@ -51,9 +51,13 @@ interface SliderSettings {
|
|
|
51
51
|
autoplay?: boolean;
|
|
52
52
|
autoplayInterval?: number;
|
|
53
53
|
pauseOnHover?: boolean;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
autoScroll?: boolean;
|
|
55
|
+
autoScrollSpeed?: number;
|
|
56
|
+
autoScrollDirection?: AutoScrollDirection;
|
|
57
|
+
autoScrollStartDelay?: number;
|
|
58
|
+
stopOnInteraction?: boolean;
|
|
59
|
+
stopOnMouseEnter?: boolean;
|
|
60
|
+
stopOnFocusIn?: boolean;
|
|
57
61
|
easing?: EasingFunction;
|
|
58
62
|
onScrollStart?: (params: ScrollStartParams) => void;
|
|
59
63
|
onScroll?: (params: ScrollParams) => void;
|
|
@@ -84,9 +88,11 @@ interface SliderState {
|
|
|
84
88
|
abortController: AbortController;
|
|
85
89
|
autoplayIntervalId: ReturnType<typeof setInterval> | null;
|
|
86
90
|
autoplayPaused: boolean;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
autoScrollAnimationId: number | null;
|
|
92
|
+
autoScrollPaused: boolean;
|
|
93
|
+
autoScrollLastTimestamp: number;
|
|
94
|
+
autoScrollStopped: boolean;
|
|
95
|
+
autoScrollResumeTimeout: ReturnType<typeof setTimeout> | null;
|
|
90
96
|
isLoopRepositioning: boolean;
|
|
91
97
|
}
|
|
92
98
|
/**
|
|
@@ -164,4 +170,4 @@ interface GenerateThumbsParams {
|
|
|
164
170
|
}
|
|
165
171
|
declare const generateThumbs: ({ thumbsContainer, slides, thumbClass, thumbActiveClass, feedId, thumbImageSelector, thumbSize }: GenerateThumbsParams) => HTMLElement[];
|
|
166
172
|
|
|
167
|
-
export { type
|
|
173
|
+
export { type AutoScrollDirection, type DragState, type EasingFunction, type ScrollParams, type ScrollStartParams, type Slider, type SliderDirection, type SliderNavDirection, type SliderSettings, type SliderState, createSlider, easeInOutCubic, easeOutCubic, easeOutExpo, easeOutQuad, generateBullets, generateThumbs, linear };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,9 +11,9 @@ type SliderNavDirection = 'prev' | 'next';
|
|
|
11
11
|
*/
|
|
12
12
|
type SliderDirection = 'horizontal' | 'vertical';
|
|
13
13
|
/**
|
|
14
|
-
* Direction of
|
|
14
|
+
* Direction of auto-scroll
|
|
15
15
|
*/
|
|
16
|
-
type
|
|
16
|
+
type AutoScrollDirection = 'forward' | 'backward';
|
|
17
17
|
/**
|
|
18
18
|
* Parameters passed to scroll start callback
|
|
19
19
|
*/
|
|
@@ -51,9 +51,13 @@ interface SliderSettings {
|
|
|
51
51
|
autoplay?: boolean;
|
|
52
52
|
autoplayInterval?: number;
|
|
53
53
|
pauseOnHover?: boolean;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
autoScroll?: boolean;
|
|
55
|
+
autoScrollSpeed?: number;
|
|
56
|
+
autoScrollDirection?: AutoScrollDirection;
|
|
57
|
+
autoScrollStartDelay?: number;
|
|
58
|
+
stopOnInteraction?: boolean;
|
|
59
|
+
stopOnMouseEnter?: boolean;
|
|
60
|
+
stopOnFocusIn?: boolean;
|
|
57
61
|
easing?: EasingFunction;
|
|
58
62
|
onScrollStart?: (params: ScrollStartParams) => void;
|
|
59
63
|
onScroll?: (params: ScrollParams) => void;
|
|
@@ -84,9 +88,11 @@ interface SliderState {
|
|
|
84
88
|
abortController: AbortController;
|
|
85
89
|
autoplayIntervalId: ReturnType<typeof setInterval> | null;
|
|
86
90
|
autoplayPaused: boolean;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
autoScrollAnimationId: number | null;
|
|
92
|
+
autoScrollPaused: boolean;
|
|
93
|
+
autoScrollLastTimestamp: number;
|
|
94
|
+
autoScrollStopped: boolean;
|
|
95
|
+
autoScrollResumeTimeout: ReturnType<typeof setTimeout> | null;
|
|
90
96
|
isLoopRepositioning: boolean;
|
|
91
97
|
}
|
|
92
98
|
/**
|
|
@@ -164,4 +170,4 @@ interface GenerateThumbsParams {
|
|
|
164
170
|
}
|
|
165
171
|
declare const generateThumbs: ({ thumbsContainer, slides, thumbClass, thumbActiveClass, feedId, thumbImageSelector, thumbSize }: GenerateThumbsParams) => HTMLElement[];
|
|
166
172
|
|
|
167
|
-
export { type
|
|
173
|
+
export { type AutoScrollDirection, type DragState, type EasingFunction, type ScrollParams, type ScrollStartParams, type Slider, type SliderDirection, type SliderNavDirection, type SliderSettings, type SliderState, createSlider, easeInOutCubic, easeOutCubic, easeOutExpo, easeOutQuad, generateBullets, generateThumbs, linear };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1 @@
|
|
|
1
|
-
var C={MIN_DURATION:400,MAX_DURATION:1e3,SPEED_FACTOR:1.5,SCROLL_END_DELAY:50,THUMB_UPDATE_DELAY:500},ye="(min-width: 64rem)",O=()=>window.matchMedia(ye).matches;var N=e=>e===1?1:1-Math.pow(2,-10*e),H=e=>1-Math.pow(1-e,3),Le=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2,ge=e=>1-(1-e)*(1-e),Ae=e=>e;var Me=()=>`slider-${Math.random().toString(36).substring(2,9)}`,ee=e=>{let{feed:t,prevSlideButton:o,nextSlideButton:l,thumbs:r,slides:a}=e;t.id||(t.id=Me()),t.setAttribute("role","region"),t.setAttribute("aria-label","Carousel"),t.setAttribute("aria-roledescription","carousel"),t.removeAttribute("tabindex"),a.forEach((i,s)=>{i.setAttribute("role","group"),i.setAttribute("aria-roledescription","slide"),i.setAttribute("aria-label",`Slide ${s+1} of ${a.length}`);}),o&&(o.setAttribute("aria-label","Previous slide"),o.setAttribute("aria-controls",t.id),o.setAttribute("tabindex","0"),o.tagName!=="BUTTON"&&o.setAttribute("role","button")),l&&(l.setAttribute("aria-label","Next slide"),l.setAttribute("aria-controls",t.id),l.setAttribute("tabindex","0"),l.tagName!=="BUTTON"&&l.setAttribute("role","button")),r?.length&&r.forEach((i,s)=>{i.tagName!=="BUTTON"&&i.setAttribute("role","button"),i.setAttribute("aria-label",`Go to slide ${s+1}`),i.setAttribute("tabindex","0"),i.setAttribute("aria-controls",t.id);});},z=(e,t,o)=>{if(!e)return;!t&&e===document.activeElement&&o&&o.focus();let l="opacity 0.3s ease",r=t?"1":"0";Object.assign(e.style,{opacity:r,transition:l,pointerEvents:t?"auto":"none"}),t?(e.removeAttribute("aria-hidden"),e.setAttribute("tabindex","0")):(e.setAttribute("aria-hidden","true"),e.setAttribute("tabindex","-1")),t?e.style.visibility="visible":setTimeout(()=>{e.style.opacity==="0"&&(e.style.visibility="hidden");},300);},F=(e,t,o="active")=>{e?.length&&e.forEach((l,r)=>{let a=r===t;l.classList.toggle(o,a),l.setAttribute("aria-selected",a.toString());});},te=(e,t,o,l,r="horizontal")=>{let a=r==="vertical",i=a?"ArrowUp":"ArrowLeft",s=a?"ArrowDown":"ArrowRight";e.addEventListener("keydown",f=>{switch(f.key){case i:f.preventDefault(),t();break;case s:f.preventDefault(),o();break}},{signal:l}),e.hasAttribute("tabindex")||e.setAttribute("tabindex","0");};var A={FRICTION:.94,MIN_VELOCITY:.3,MOMENTUM_RATIO:.8,VELOCITY_SMOOTHING:.4,EDGE_RESISTANCE:.3,MAX_EDGE_OVERSCROLL:100,SHORT_SWIPE_VELOCITY:.5,BOUNCE_DURATION:400},xe=()=>({isDragging:false,startX:0,startY:0,startScrollLeft:0,startScrollTop:0,velocity:0,lastX:0,lastY:0,lastTime:0,momentumId:null}),Ie=()=>({...xe(),velocityHistory:[],dragDistance:0,dragStartTime:0}),$=(e,t,o="horizontal")=>{let l=e.getBoundingClientRect(),r=o==="vertical",a=r?l.top:l.left,i=null,s=1/0;for(let f of t){if(f.offsetParent===null)continue;let m=f.getBoundingClientRect(),h=r?m.top:m.left,n=Math.abs(a-h);n<s&&(s=n,i=f);}return i},De=(e,t,o,l="horizontal")=>{let r=e.getBoundingClientRect(),a=l==="vertical",i=a?r.top:r.left,s=t.filter(d=>d.offsetParent!==null);if(s.length===0)return null;let f=0,m=1/0;s.forEach((d,E)=>{let S=d.getBoundingClientRect(),P=a?S.top:S.left,w=Math.abs(i-P);w<m&&(m=w,f=E);});let h=2,n=f;return Math.abs(o)>h&&(o>0?n=Math.min(f+1,s.length-1):n=Math.max(f-1,0)),s[n]??null},Ce=e=>{if(e.length===0)return 0;let t=0,o=0;return e.forEach((l,r)=>{let a=r+1;t+=l*a,o+=a;}),t/o},He=(e,t,o,l,r,a="horizontal",i=false)=>{let s=a==="vertical",f=e.velocity*A.MOMENTUM_RATIO,m=()=>{if(Math.abs(f)<A.MIN_VELOCITY){e.momentumId=null;let E=$(t,o,a);if(E){let S=s?E.offsetTop:E.offsetLeft;l(S,H);}r?.(E);return}let h=s?t.scrollHeight-t.clientHeight:t.scrollWidth-t.clientWidth,d=(s?t.scrollTop:t.scrollLeft)+f;i||(d<0||d>h)&&(f*=.5),s?t.scrollTop=Math.max(0,Math.min(h,d)):t.scrollLeft=Math.max(0,Math.min(h,d)),f*=A.FRICTION,e.momentumId=requestAnimationFrame(m);};e.momentumId=requestAnimationFrame(m);},re=e=>"touches"in e?e.touches[0]?.clientX??0:e.clientX,oe=e=>"touches"in e?e.touches[0]?.clientY??0:e.clientY,we=(e,t)=>t==="vertical"?oe(e):re(e),le=e=>{let {feed:t,slides:o,abortSignal:l,smoothScrollTo:r,onDragEnd:a,direction:i="horizontal",loop:s=false,touchRatio:f=1,shortSwipeThreshold:m=300,swipeDistanceThreshold:h=10}=e,n=Ie(),d=i==="vertical",E=()=>{if(!s)return o;let y=[],g=t.children;for(let M=0;M<g.length;M++){let L=g[M];(o.includes(L)||L.hasAttribute("data-lazer-clone"))&&y.push(L);}return y.length>0?y:o},S=0,w=()=>{S=d?t.scrollHeight-t.clientHeight:t.scrollWidth-t.clientWidth,d?t.clientHeight:t.clientWidth;},q=y=>{n.momentumId!==null&&(cancelAnimationFrame(n.momentumId),n.momentumId=null),w(),n.isDragging=true,n.startX=re(y),n.startY=oe(y),n.startScrollLeft=t.scrollLeft,n.startScrollTop=t.scrollTop,n.velocity=0,n.lastX=n.startX,n.lastY=n.startY,n.lastTime=performance.now(),n.velocityHistory=[],n.dragDistance=0,n.dragStartTime=performance.now(),t.style.userSelect="none",t.style.cursor="grabbing",t.classList.add("is-dragging"),y.type==="mousedown"&&y.preventDefault();},B=y=>{if(!n.isDragging)return;let g=we(y,i),M=d?n.startY:n.startX,L=d?n.lastY:n.lastX,c=d?n.startScrollTop:n.startScrollLeft,u=performance.now(),T=u-n.lastTime,b=(M-g)*f,p=c+b;if(n.dragDistance=Math.abs(b),!s){if(p<0){let v=Math.abs(p),x=1-Math.min(v/A.MAX_EDGE_OVERSCROLL,1)*(1-A.EDGE_RESISTANCE);p=-v*x;}else if(p>S){let v=p-S,x=1-Math.min(v/A.MAX_EDGE_OVERSCROLL,1)*(1-A.EDGE_RESISTANCE);p=S+v*x;}}if(d?t.scrollTop=p:t.scrollLeft=p,T>0){let v=(L-g)/T*16;if(n.velocityHistory.length>0){let x=n.velocity;n.velocity=x*(1-A.VELOCITY_SMOOTHING)+v*A.VELOCITY_SMOOTHING;}else n.velocity=v;n.velocityHistory.push(v),n.velocityHistory.length>5&&n.velocityHistory.shift();}d?n.lastY=g:n.lastX=g,n.lastTime=u,y.type==="touchmove"&&y.preventDefault();},R=()=>{if(!n.isDragging)return;n.isDragging=false,t.style.userSelect="",t.style.cursor="",t.classList.remove("is-dragging");let g=performance.now()-n.dragStartTime<m&&n.dragDistance>h,M=Ce(n.velocityHistory),L=E();if(!s){let c=d?t.scrollTop:t.scrollLeft;if(c<0||c>S){let u=c<0?0:S,T=c,b=performance.now(),p=()=>{let v=performance.now()-b,x=Math.min(v/A.BOUNCE_DURATION,1),_=H(x),I=T+(u-T)*_;if(d?t.scrollTop=I:t.scrollLeft=I,x<1)requestAnimationFrame(p);else {let D=$(t,L,i);if(D){let Ee=d?D.offsetTop:D.offsetLeft;r(Ee,H);}a?.(D);}};requestAnimationFrame(p);return}}if(g||Math.abs(M)>A.SHORT_SWIPE_VELOCITY){let c=De(t,L,M,i);if(c){let u=d?c.offsetTop:c.offsetLeft;r(u,H),a?.(c);}else a?.(null);}else if(Math.abs(n.velocity)>1)He(n,t,L,r,a,i,s);else {let c=$(t,L,i);if(c){let u=d?c.offsetTop:c.offsetLeft;r(u,H);}a?.(c);}};return t.addEventListener("mousedown",q,{signal:l}),document.addEventListener("mousemove",B,{signal:l}),document.addEventListener("mouseup",R,{signal:l}),t.addEventListener("touchstart",q,{passive:true,signal:l}),t.addEventListener("touchmove",B,{passive:false,signal:l}),t.addEventListener("touchend",R,{signal:l}),t.addEventListener("touchcancel",R,{signal:l}),document.addEventListener("mouseleave",R,{signal:l}),t.style.cursor="grab",n},ie=e=>{e.momentumId!==null&&(cancelAnimationFrame(e.momentumId),e.momentumId=null);};var G=({bulletsContainer:e,slides:t,bulletClass:o,bulletActiveClass:l,feedId:r})=>{if(!e||!(e instanceof HTMLElement))throw new Error("Invalid bulletsContainer: must be a valid HTMLElement");if(!Array.isArray(t)||t.length===0)throw new Error("Invalid slides: must be a non-empty array");if(!r||typeof r!="string")throw new Error("Invalid feedId: must be a non-empty string");if(!o||typeof o!="string")throw new Error("Invalid bulletClass: must be a non-empty string");e.innerHTML="",e.setAttribute("role","tablist"),e.setAttribute("aria-label","Slide navigation");let a=t.map((s,f)=>({slide:s,originalIndex:f})).filter(({slide:s})=>s.offsetParent!==null);return a.length===0?(console.warn("No visible slides found"),[]):a.map(({slide:s,originalIndex:f},m)=>{let h=document.createElement("button");return h.type="button",h.classList.add(o),m===0&&h.classList.add(l),h.setAttribute("role","tab"),h.setAttribute("aria-selected",m===0?"true":"false"),h.setAttribute("aria-controls",r),h.setAttribute("aria-label",`Go to slide ${m+1}`),h.setAttribute("data-slide-index",String(m)),e.appendChild(h),h})};var X=({thumbsContainer:e,slides:t,thumbClass:o,thumbActiveClass:l,feedId:r,thumbImageSelector:a="img",thumbSize:i})=>{if(!e||!(e instanceof HTMLElement))throw new Error("Invalid thumbsContainer: must be a valid HTMLElement");if(!Array.isArray(t)||t.length===0)throw new Error("Invalid slides: must be a non-empty array");if(!r||typeof r!="string")throw new Error("Invalid feedId: must be a non-empty string");if(!o||typeof o!="string")throw new Error("Invalid thumbClass: must be a non-empty string");e.innerHTML="",e.setAttribute("role","tablist"),e.setAttribute("aria-label","Slide thumbnails");let s=t.map((m,h)=>({slide:m,originalIndex:h})).filter(({slide:m})=>m.offsetParent!==null);return s.length===0?(console.warn("No visible slides found"),[]):s.map(({slide:m,originalIndex:h},n)=>{let d=document.createElement("button");d.type="button",d.classList.add(o),n===0&&d.classList.add(l);let E=m.querySelector(a);if(E?.src){let S=document.createElement("img");S.src=E.src,S.alt=E.alt||`Slide ${n+1} thumbnail`,S.draggable=false,i&&(S.style.width=`${i.width}px`,S.style.height=`${i.height}px`,S.style.objectFit="cover"),d.appendChild(S);}return d.setAttribute("role","tab"),d.setAttribute("aria-selected",n===0?"true":"false"),d.setAttribute("aria-controls",r),d.setAttribute("aria-label",`Go to slide ${n+1}`),d.setAttribute("data-slide-index",String(n)),e.appendChild(d),d})};var ne=()=>({initialized:false,clonedSlides:[],styleElement:null}),ae=()=>{let e=document.getElementById("lazer-marquee-keyframes");if(e)return e;let t=document.createElement("style");return t.id="lazer-marquee-keyframes",t.textContent=`
|
|
2
|
-
@keyframes lazer-marquee-scroll {
|
|
3
|
-
0% {
|
|
4
|
-
transform: translateX(0);
|
|
5
|
-
}
|
|
6
|
-
100% {
|
|
7
|
-
transform: translateX(-50%);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
`,document.head.appendChild(t),t},Re=(e,t)=>{t.initialized||(t.styleElement=ae(),e.feed.style.display="flex",e.feed.style.willChange="transform",e.slides.forEach(o=>{let l=o.cloneNode(true);l.setAttribute("data-lazer-marquee-clone","true"),l.setAttribute("aria-hidden","true"),e.feed.appendChild(l),t.clonedSlides.push(l);}),t.initialized=true);},se=e=>{e.initialized&&(e.clonedSlides.forEach(t=>{t.remove();}),e.clonedSlides=[],e.initialized=false);},Oe=(e,t)=>{ae(),requestAnimationFrame(()=>{let o=e.feed.scrollWidth,l=e.marqueeSpeed??50,r=e.marqueeDirection??"left",a=o/2;if(a<=0||l<=0){console.warn("[lazer-slider] Invalid marquee values:",{distance:a,speed:l,scrollWidth:o});return}let f=`lazer-marquee-scroll ${a/l}s linear infinite ${r==="right"?"reverse":"normal"}`;e.feed.style.animation="none",e.feed.offsetWidth,e.feed.style.animation=f,e.feed.style.animationPlayState=t.marqueePaused?"paused":"running";});},W=(e,t)=>{Oe(e,t);},ce=(e,t)=>{t.feed.style.animation="",t.feed.style.animationPlayState="",t.feed.style.transform="",t.feed.style.willChange="";},k=(e,t)=>{e.marqueePaused=true,t.feed.style.animationPlayState="paused";},V=(e,t)=>{e.marqueePaused=false,t.feed.style.animationPlayState="running";},de=(e,t,o)=>{e.marquee&&(Re(e,o),W(e,t));},ue=(e,t,o)=>{!e.marquee||e.pauseOnHover===false||(e.feed.addEventListener("mouseenter",()=>k(t,e),{signal:o}),e.feed.addEventListener("mouseleave",()=>V(t,e),{signal:o}),e.feed.addEventListener("touchstart",()=>k(t,e),{passive:true,signal:o}),e.feed.addEventListener("touchend",()=>V(t,e),{signal:o}));};var me=e=>({initialized:false,clonedSlides:[],realSlides:[...e],clonesPerSide:0}),Pe=e=>{let t=O()?e.desktopSlidesPerView:e.mobileSlidesPerView;return !t||t==="auto"?1:Math.ceil(t)},fe=(e,t,o)=>{if(!e.loop||t.initialized)return;let l=t.realSlides,r=Pe(e);t.clonesPerSide=r;for(let a=l.length-r;a<l.length;a++){let i=l[a];if(!i)continue;let s=i.cloneNode(true);s.setAttribute("data-lazer-clone","prepend"),s.setAttribute("aria-hidden","true"),e.feed.insertBefore(s,e.feed.firstChild),t.clonedSlides.push(s);}for(let a=0;a<r;a++){let i=l[a];if(!i)continue;let s=i.cloneNode(true);s.setAttribute("data-lazer-clone","append"),s.setAttribute("aria-hidden","true"),e.feed.appendChild(s),t.clonedSlides.push(s);}requestAnimationFrame(()=>{let a=l[0];a&&(o?e.feed.scrollTop=a.offsetTop:e.feed.scrollLeft=a.offsetLeft);}),t.initialized=true;},U=(e,t,o,l,r,a,i)=>{if(!t.loop||!o.initialized)return;a(true);let s=o.realSlides,f=s.length;if(e==="next"){let m=s[0];m&&(l?t.feed.scrollTop=m.offsetTop:t.feed.scrollLeft=m.offsetLeft),r(0);}else {let m=s[f-1];m&&(l?t.feed.scrollTop=m.offsetTop:t.feed.scrollLeft=m.offsetLeft),r(f-1);}requestAnimationFrame(()=>{requestAnimationFrame(()=>{a(false),i();});});},pe=e=>{e.initialized&&(e.clonedSlides.forEach(t=>{t.remove();}),e.clonedSlides=[],e.initialized=false,e.clonesPerSide=0);};var j=(e,t,o)=>{if(t.autoplayIntervalId)return;let l=e.autoplayInterval??3e3;t.autoplayIntervalId=setInterval(()=>{t.autoplayPaused||o("next");},l);},K=e=>{e.autoplayIntervalId&&(clearInterval(e.autoplayIntervalId),e.autoplayIntervalId=null);},Se=e=>{e.autoplayPaused=true;},he=e=>{e.autoplayPaused=false;},be=(e,t,o)=>{!e.autoplay||e.pauseOnHover===false||(e.feed.addEventListener("mouseenter",()=>Se(t),{signal:o}),e.feed.addEventListener("mouseleave",()=>he(t),{signal:o}),e.feed.addEventListener("touchstart",()=>Se(t),{passive:true,signal:o}),e.feed.addEventListener("touchend",()=>he(t),{signal:o}));};var Q=(e,t,o)=>{if(e.scrollbarThumb)if(o){let l=t.height/e.feed.scrollHeight*100;e.scrollbarThumb.style.height=`${l}%`,e.scrollbarThumb.style.width="";}else {let l=t.width/e.feed.scrollWidth*100;e.scrollbarThumb.style.width=`${l}%`,e.scrollbarThumb.style.height="";}},Te=(e,t)=>{if(!(!e.scrollbarThumb||!e.scrollbarTrack))if(t){let o=e.scrollbarTrack.getBoundingClientRect().height,l=e.scrollbarThumb.getBoundingClientRect().height,r=o-l,a=e.feed.scrollHeight-e.feed.clientHeight,i=a>0?e.feed.scrollTop/a:0;e.scrollbarThumb.style.transform=`translateY(${r*i}px)`;}else {let o=e.scrollbarTrack.getBoundingClientRect().width,l=e.scrollbarThumb.getBoundingClientRect().width,r=o-l,a=e.feed.scrollWidth-e.feed.clientWidth,i=a>0?e.feed.scrollLeft/a:0;e.scrollbarThumb.style.transform=`translateX(${r*i}px)`;}};var J=(e,t,o,l=N,r)=>{let a=o?e.scrollTop:e.scrollLeft,i=Math.abs(t-a),s=Math.min(C.MAX_DURATION,Math.max(C.MIN_DURATION,i/C.SPEED_FACTOR)),f=performance.now(),m=h=>{let n=(h-f)/s,d=Math.min(n,1),E=l(d),S=a+(t-a)*E;o?e.scrollTop=S:e.scrollLeft=S,d<1?requestAnimationFrame(m):(o?e.scrollTop=t:e.scrollLeft=t,r?.());};requestAnimationFrame(m);},Y=e=>e.filter(t=>t.offsetParent!==null),Z=(e,t,o)=>{let l=o?e.desktopSlidesPerView:e.mobileSlidesPerView,r=e.slideGap??0;if(r>0&&(e.feed.style.gap=`${r}px`),!l||l==="auto"){e.slides.forEach(s=>{s.style.flex="",s.style.minWidth="",s.style.minHeight="";});return}let i=`calc((100% - ${r*(l-1)}px) / ${l})`;t?e.slides.forEach(s=>{s.style.flex=`0 0 ${i}`,s.style.minHeight=i,s.style.minWidth="";}):e.slides.forEach(s=>{s.style.flex=`0 0 ${i}`,s.style.minWidth=i,s.style.minHeight="";});},ve=(e,t,o,l)=>{let r=l?e.clientHeight:e.clientWidth;return !t||o!==r?{rect:e.getBoundingClientRect(),size:r}:{rect:t,size:o}};var qe=e=>{if(!e.feed)throw new Error("lazer-slider: feed element is required");if(!e.slides?.length)throw new Error("lazer-slider: slides array is required and must not be empty");if(e.feed.id||(e.feed.id=`lazer-slider-feed-${Math.random().toString(36).substr(2,9)}`),e.bulletsContainer&&!e.thumbs){let c=G({bulletsContainer:e.bulletsContainer,slides:e.slides,bulletClass:e.bulletsClass??"slider-bullet",bulletActiveClass:e.bulletsActiveClass??"active",feedId:e.feed.id});e.thumbs=c;}if(e.thumbsContainer&&!e.thumbs){let c=X({thumbsContainer:e.thumbsContainer,slides:e.slides,thumbClass:e.thumbsClass??"slider-thumb",thumbActiveClass:e.thumbsActiveClass??"active",feedId:e.feed.id,thumbImageSelector:e.thumbImageSelector??"img",thumbSize:e.thumbSize});e.thumbs=c;}let t=e.direction??"horizontal",o=t==="vertical",l=e.easing??N,r={currentSlideIndex:0,isScrolling:false,ticking:false,cachedFeedRect:null,lastWidth:0,updateThumbTimeout:null,scrollEndTimeout:null,abortController:new AbortController,autoplayIntervalId:null,autoplayPaused:false,marqueePaused:false,isLoopRepositioning:false},a=null,i=me(e.slides),s=ne(),f=()=>{let c=ve(e.feed,r.cachedFeedRect,r.lastWidth,o);return r.cachedFeedRect=c.rect,r.lastWidth=c.size,c.rect},m=(c,u)=>{J(e.feed,c,o,l,u);},h=(c,u)=>{J(e.feed,c,o,u??l);},n=()=>{if(r.isLoopRepositioning)return;let c=f(),u,T,b;if(o?(u=e.feed.scrollTop<=1,T=e.feed.scrollTop+c.height>=e.feed.scrollHeight-1,b=e.feed.scrollHeight<=c.height):(u=e.feed.scrollLeft<=1,T=e.feed.scrollLeft+c.width>=e.feed.scrollWidth-1,b=e.feed.scrollWidth<=c.width),e.scrollbarTrack&&(e.scrollbarTrack.style.display=b?"none":"block"),e.loop){z(e.prevSlideButton,!b,e.feed),z(e.nextSlideButton,!b,e.feed);return}z(e.prevSlideButton,!u&&!b,e.feed),z(e.nextSlideButton,!T&&!b,e.feed);},d=()=>{let c=f(),u=i.initialized?i.realSlides:Y(e.slides),T=u.filter(b=>{let p=b.getBoundingClientRect(),v=20;return o?p.bottom>c.top+v&&p.top<c.bottom-v:p.right>c.left+v&&p.left<c.right-v});if(T.length&&T[0]){let b=u.indexOf(T[0]);if(b!==-1){r.currentSlideIndex=b;let p=o?e.feed.scrollTop:e.feed.scrollLeft;e.onScroll?.({currentScroll:p,currentSlideIndex:r.currentSlideIndex});}}},E=c=>{if(!e.thumbs)return;let u=e.thumbs.indexOf(c);if(u===-1||!e.slides[u])return;r.currentSlideIndex=u,F(e.thumbs,u),r.isScrolling=true,r.updateThumbTimeout&&clearTimeout(r.updateThumbTimeout),r.updateThumbTimeout=setTimeout(()=>{r.isScrolling=false;},C.THUMB_UPDATE_DELAY);let T=o?e.slides[u].offsetTop:e.slides[u].offsetLeft;m(T);},S=c=>{let u=i.initialized?i.realSlides:Y(e.slides),T=O()?e.desktopSlidesPerScroll??1:e.mobileSlidesPerScroll??1,b=u.length;d();let p,v=false;if(c==="prev")if(e.loop&&i.initialized&&r.currentSlideIndex===0){let I=i.clonedSlides.filter(D=>D.getAttribute("data-lazer-clone")==="prepend");p=I[I.length-1],v=true;}else r.currentSlideIndex=Math.max(0,r.currentSlideIndex-T),p=u[r.currentSlideIndex];else e.loop&&i.initialized&&r.currentSlideIndex>=b-1?(p=i.clonedSlides.filter(D=>D.getAttribute("data-lazer-clone")==="append")[0],v=true):(r.currentSlideIndex=Math.min(b-1,r.currentSlideIndex+T),p=u[r.currentSlideIndex]);if(!p)return;let x=o?e.feed.scrollTop:e.feed.scrollLeft;e.onScrollStart?.({currentScroll:x,target:p,direction:c});let _=o?p.offsetTop:p.offsetLeft;v?m(_,()=>{U(c,e,i,o,I=>{r.currentSlideIndex=I;},I=>{r.isLoopRepositioning=I;},n);}):m(_);},P=()=>{Te(e,o),n(),d(),r.isScrolling||F(e.thumbs,r.currentSlideIndex),r.scrollEndTimeout&&clearTimeout(r.scrollEndTimeout),r.scrollEndTimeout=setTimeout(()=>{r.isScrolling=false;let c=o?e.feed.scrollTop:e.feed.scrollLeft;e.onScrollEnd?.({currentScroll:c,currentSlideIndex:r.currentSlideIndex});},C.SCROLL_END_DELAY);},w=()=>{r.ticking||(requestAnimationFrame(()=>{P(),r.ticking=false;}),r.ticking=true);},q=()=>{r.cachedFeedRect=null,y();},B=()=>{let{signal:c}=r.abortController;window.addEventListener("resize",q),e.feed.addEventListener("scroll",w,{passive:true,signal:c}),e.prevSlideButton&&e.prevSlideButton.addEventListener("click",()=>S("prev"),{signal:c}),e.nextSlideButton&&e.nextSlideButton.addEventListener("click",()=>S("next"),{signal:c}),e.thumbs?.length&&(e.thumbs[0]?.classList.add("active"),e.thumbs.forEach(u=>{u.addEventListener("click",()=>E(u),{signal:c});})),te(e.feed,()=>S("prev"),()=>S("next"),c,t),e.enableDragToScroll!==false&&(a=le({feed:e.feed,slides:e.slides,abortSignal:c,smoothScrollTo:h,onDragEnd:u=>{if(u&&e.loop&&i.initialized){let T=u.getAttribute("data-lazer-clone");if(T){let b=T==="append"?"next":"prev";setTimeout(()=>{U(b,e,i,o,p=>{r.currentSlideIndex=p;},p=>{r.isLoopRepositioning=p;},n);},50);}}d(),F(e.thumbs,r.currentSlideIndex);},direction:t,loop:e.loop})),be(e,r,c),ue(e,r,c);},R=c=>{let u=i.initialized?i.realSlides:Y(e.slides),T=Math.max(0,Math.min(c,u.length-1)),b=u[T];if(!b)return;r.currentSlideIndex=T,F(e.thumbs,T);let p=o?b.offsetTop:b.offsetLeft;m(p);},y=()=>{r.cachedFeedRect=null,Z(e,o,O()),Q(e,f(),o),n(),e.marquee&&!r.marqueePaused&&W(e,r);},g=()=>{K(r),ce(r,e),r.abortController.abort(),window.removeEventListener("resize",q),r.updateThumbTimeout&&clearTimeout(r.updateThumbTimeout),r.scrollEndTimeout&&clearTimeout(r.scrollEndTimeout),a&&ie(a),pe(i),se(s),r.cachedFeedRect=null;},M=()=>{e.marquee?r.marqueePaused?V(r,e):W(e,r):e.autoplay&&j(e,r,S);},L=()=>{e.marquee?k(r,e):K(r);};return ee(e),Z(e,o,O()),e.marquee?de(e,r,s):(fe(e,i,o),e.autoplay&&j(e,r,S)),n(),B(),Q(e,f(),o),{goToIndex:R,refresh:y,unload:g,play:M,pause:L,next:()=>S("next"),prev:()=>S("prev")}};export{qe as createSlider,Le as easeInOutCubic,H as easeOutCubic,N as easeOutExpo,ge as easeOutQuad,G as generateBullets,X as generateThumbs,Ae as linear};
|
|
1
|
+
var H={MIN_DURATION:400,MAX_DURATION:1e3,SPEED_FACTOR:1.5,SCROLL_END_DELAY:50,THUMB_UPDATE_DELAY:500},ve="(min-width: 64rem)",N=()=>window.matchMedia(ve).matches;var k=e=>e===1?1:1-Math.pow(2,-10*e),w=e=>1-Math.pow(1-e,3),Ee=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2,Le=e=>1-(1-e)*(1-e),Ae=e=>e;var ye=()=>`slider-${Math.random().toString(36).substring(2,9)}`,le=e=>{let{feed:t,prevSlideButton:l,nextSlideButton:i,thumbs:o,slides:c}=e;t.id||(t.id=ye()),t.setAttribute("role","region"),t.setAttribute("aria-label","Carousel"),t.setAttribute("aria-roledescription","carousel"),t.removeAttribute("tabindex"),c.forEach((r,a)=>{r.setAttribute("role","group"),r.setAttribute("aria-roledescription","slide"),r.setAttribute("aria-label",`Slide ${a+1} of ${c.length}`);}),l&&(l.setAttribute("aria-label","Previous slide"),l.setAttribute("aria-controls",t.id),l.setAttribute("tabindex","0"),l.tagName!=="BUTTON"&&l.setAttribute("role","button")),i&&(i.setAttribute("aria-label","Next slide"),i.setAttribute("aria-controls",t.id),i.setAttribute("tabindex","0"),i.tagName!=="BUTTON"&&i.setAttribute("role","button")),o?.length&&o.forEach((r,a)=>{r.tagName!=="BUTTON"&&r.setAttribute("role","button"),r.setAttribute("aria-label",`Go to slide ${a+1}`),r.setAttribute("tabindex","0"),r.setAttribute("aria-controls",t.id);});},W=(e,t,l)=>{if(!e)return;!t&&e===document.activeElement&&l&&l.focus();let i="opacity 0.3s ease",o=t?"1":"0";Object.assign(e.style,{opacity:o,transition:i,pointerEvents:t?"auto":"none"}),t?(e.removeAttribute("aria-hidden"),e.setAttribute("tabindex","0")):(e.setAttribute("aria-hidden","true"),e.setAttribute("tabindex","-1")),t?e.style.visibility="visible":setTimeout(()=>{e.style.opacity==="0"&&(e.style.visibility="hidden");},300);},F=(e,t,l="active")=>{e?.length&&e.forEach((i,o)=>{let c=o===t;i.classList.toggle(l,c),i.setAttribute("aria-selected",c.toString());});},re=(e,t,l,i,o="horizontal")=>{let c=o==="vertical",r=c?"ArrowUp":"ArrowLeft",a=c?"ArrowDown":"ArrowRight";e.addEventListener("keydown",u=>{switch(u.key){case r:u.preventDefault(),t();break;case a:u.preventDefault(),l();break}},{signal:i}),e.hasAttribute("tabindex")||e.setAttribute("tabindex","0");};var D={FRICTION:.94,MIN_VELOCITY:.3,MOMENTUM_RATIO:.8,VELOCITY_SMOOTHING:.4,EDGE_RESISTANCE:.3,MAX_EDGE_OVERSCROLL:100,SHORT_SWIPE_VELOCITY:.5,BOUNCE_DURATION:400},ge=()=>({isDragging:false,startX:0,startY:0,startScrollLeft:0,startScrollTop:0,velocity:0,lastX:0,lastY:0,lastTime:0,momentumId:null}),xe=()=>({...ge(),velocityHistory:[],dragDistance:0,dragStartTime:0}),$=(e,t,l="horizontal")=>{let i=e.getBoundingClientRect(),o=l==="vertical",c=o?i.top:i.left,r=null,a=1/0;for(let u of t){if(u.offsetParent===null)continue;let f=u.getBoundingClientRect(),p=o?f.top:f.left,E=Math.abs(c-p);E<a&&(a=E,r=u);}return r},Ie=(e,t,l,i="horizontal")=>{let o=e.getBoundingClientRect(),c=i==="vertical",r=c?o.top:o.left,a=t.filter(n=>n.offsetParent!==null);if(a.length===0)return null;let u=0,f=1/0;a.forEach((n,S)=>{let L=n.getBoundingClientRect(),v=c?L.top:L.left,O=Math.abs(r-v);O<f&&(f=O,u=S);});let p=2,E=u;return Math.abs(l)>p&&(l>0?E=Math.min(u+1,a.length-1):E=Math.max(u-1,0)),a[E]??null},Me=e=>{if(e.length===0)return 0;let t=0,l=0;return e.forEach((i,o)=>{let c=o+1;t+=i*c,l+=c;}),t/l},De=(e,t,l,i,o,c="horizontal",r=false)=>{let a=c==="vertical",u=e.velocity*D.MOMENTUM_RATIO,f=()=>{if(Math.abs(u)<D.MIN_VELOCITY){e.momentumId=null;let S=$(t,l,c);if(S){let L=a?S.offsetTop:S.offsetLeft;i(L,w);}o?.(S);return}let p=a?t.scrollHeight-t.clientHeight:t.scrollWidth-t.clientWidth,n=(a?t.scrollTop:t.scrollLeft)+u;r||(n<0||n>p)&&(u*=.5),a?t.scrollTop=Math.max(0,Math.min(p,n)):t.scrollLeft=Math.max(0,Math.min(p,n)),u*=D.FRICTION,e.momentumId=requestAnimationFrame(f);};e.momentumId=requestAnimationFrame(f);},ie=e=>"touches"in e?e.touches[0]?.clientX??0:e.clientX,ne=e=>"touches"in e?e.touches[0]?.clientY??0:e.clientY,Ce=(e,t)=>t==="vertical"?ne(e):ie(e),ae=e=>{let {feed:t,slides:l,abortSignal:i,smoothScrollTo:o,onDragStart:c,onDragEnd:r,direction:a="horizontal",loop:u=false,touchRatio:f=1,shortSwipeThreshold:p=300,swipeDistanceThreshold:E=10}=e,n=xe(),S=a==="vertical",L=()=>{if(!u)return l;let A=[],M=t.children;for(let C=0;C<M.length;C++){let x=M[C];(l.includes(x)||x.hasAttribute("data-lazer-clone"))&&A.push(x);}return A.length>0?A:l},v=0,U=()=>{v=S?t.scrollHeight-t.clientHeight:t.scrollWidth-t.clientWidth,S?t.clientHeight:t.clientWidth;},B=A=>{n.momentumId!==null&&(cancelAnimationFrame(n.momentumId),n.momentumId=null),U(),c?.(),n.isDragging=true,n.startX=ie(A),n.startY=ne(A),n.startScrollLeft=t.scrollLeft,n.startScrollTop=t.scrollTop,n.velocity=0,n.lastX=n.startX,n.lastY=n.startY,n.lastTime=performance.now(),n.velocityHistory=[],n.dragDistance=0,n.dragStartTime=performance.now(),t.style.userSelect="none",t.style.cursor="grabbing",t.classList.add("is-dragging"),A.type==="mousedown"&&A.preventDefault();},X=A=>{if(!n.isDragging)return;let M=Ce(A,a),C=S?n.startY:n.startX,x=S?n.lastY:n.lastX,s=S?n.startScrollTop:n.startScrollLeft,d=performance.now(),b=d-n.lastTime,h=(C-M)*f,m=s+h;if(n.dragDistance=Math.abs(h),!u){if(m<0){let T=Math.abs(m),y=1-Math.min(T/D.MAX_EDGE_OVERSCROLL,1)*(1-D.EDGE_RESISTANCE);m=-T*y;}else if(m>v){let T=m-v,y=1-Math.min(T/D.MAX_EDGE_OVERSCROLL,1)*(1-D.EDGE_RESISTANCE);m=v+T*y;}}if(S?t.scrollTop=m:t.scrollLeft=m,b>0){let T=(x-M)/b*16;if(n.velocityHistory.length>0){let y=n.velocity;n.velocity=y*(1-D.VELOCITY_SMOOTHING)+T*D.VELOCITY_SMOOTHING;}else n.velocity=T;n.velocityHistory.push(T),n.velocityHistory.length>5&&n.velocityHistory.shift();}S?n.lastY=M:n.lastX=M,n.lastTime=d,A.type==="touchmove"&&A.preventDefault();},P=()=>{if(!n.isDragging)return;n.isDragging=false,t.style.userSelect="",t.style.cursor="",t.classList.remove("is-dragging");let M=performance.now()-n.dragStartTime<p&&n.dragDistance>E,C=Me(n.velocityHistory),x=L();if(!u){let s=S?t.scrollTop:t.scrollLeft;if(s<0||s>v){let d=s<0?0:v,b=s,h=performance.now(),m=()=>{let T=performance.now()-h,y=Math.min(T/D.BOUNCE_DURATION,1),R=w(y),g=b+(d-b)*R;if(S?t.scrollTop=g:t.scrollLeft=g,y<1)requestAnimationFrame(m);else {let I=$(t,x,a);if(I){let Te=S?I.offsetTop:I.offsetLeft;o(Te,w);}r?.(I);}};requestAnimationFrame(m);return}}if(M||Math.abs(C)>D.SHORT_SWIPE_VELOCITY){let s=Ie(t,x,C,a);if(s){let d=S?s.offsetTop:s.offsetLeft;o(d,w),r?.(s);}else r?.(null);}else if(Math.abs(n.velocity)>1&&!n.isLoopDragHandled)De(n,t,x,o,r,a,u);else {let s=$(t,x,a);if(!n.isLoopDragHandled){if(s){let d=S?s.offsetTop:s.offsetLeft;o(d,w);}r?.(s);}}};return t.addEventListener("mousedown",B,{signal:i}),document.addEventListener("mousemove",X,{signal:i}),document.addEventListener("mouseup",P,{signal:i}),t.addEventListener("touchstart",B,{passive:true,signal:i}),t.addEventListener("touchmove",X,{passive:false,signal:i}),t.addEventListener("touchend",P,{signal:i}),t.addEventListener("touchcancel",P,{signal:i}),document.addEventListener("mouseleave",P,{signal:i}),t.style.cursor="grab",n},ce=e=>{e.momentumId!==null&&(cancelAnimationFrame(e.momentumId),e.momentumId=null);};var q=({bulletsContainer:e,slides:t,bulletClass:l,bulletActiveClass:i,feedId:o})=>{if(!e||!(e instanceof HTMLElement))throw new Error("Invalid bulletsContainer: must be a valid HTMLElement");if(!Array.isArray(t)||t.length===0)throw new Error("Invalid slides: must be a non-empty array");if(!o||typeof o!="string")throw new Error("Invalid feedId: must be a non-empty string");if(!l||typeof l!="string")throw new Error("Invalid bulletClass: must be a non-empty string");e.innerHTML="",e.setAttribute("role","tablist"),e.setAttribute("aria-label","Slide navigation");let c=t.map((a,u)=>({slide:a,originalIndex:u})).filter(({slide:a})=>a.offsetParent!==null);return c.length===0?(console.warn("No visible slides found"),[]):c.map(({slide:a,originalIndex:u},f)=>{let p=document.createElement("button");return p.type="button",p.classList.add(l),f===0&&p.classList.add(i),p.setAttribute("role","tab"),p.setAttribute("aria-selected",f===0?"true":"false"),p.setAttribute("aria-controls",o),p.setAttribute("aria-label",`Go to slide ${f+1}`),p.setAttribute("data-slide-index",String(f)),e.appendChild(p),p})};var j=({thumbsContainer:e,slides:t,thumbClass:l,thumbActiveClass:i,feedId:o,thumbImageSelector:c="img",thumbSize:r})=>{if(!e||!(e instanceof HTMLElement))throw new Error("Invalid thumbsContainer: must be a valid HTMLElement");if(!Array.isArray(t)||t.length===0)throw new Error("Invalid slides: must be a non-empty array");if(!o||typeof o!="string")throw new Error("Invalid feedId: must be a non-empty string");if(!l||typeof l!="string")throw new Error("Invalid thumbClass: must be a non-empty string");e.innerHTML="",e.setAttribute("role","tablist"),e.setAttribute("aria-label","Slide thumbnails");let a=t.map((f,p)=>({slide:f,originalIndex:p})).filter(({slide:f})=>f.offsetParent!==null);return a.length===0?(console.warn("No visible slides found"),[]):a.map(({slide:f,originalIndex:p},E)=>{let n=document.createElement("button");n.type="button",n.classList.add(l),E===0&&n.classList.add(i);let S=f.querySelector(c);if(S?.src){let L=document.createElement("img");L.src=S.src,L.alt=S.alt||`Slide ${E+1} thumbnail`,L.draggable=false,r&&(L.style.width=`${r.width}px`,L.style.height=`${r.height}px`,L.style.objectFit="cover"),n.appendChild(L);}return n.setAttribute("role","tab"),n.setAttribute("aria-selected",E===0?"true":"false"),n.setAttribute("aria-controls",o),n.setAttribute("aria-label",`Go to slide ${E+1}`),n.setAttribute("data-slide-index",String(E)),e.appendChild(n),n})};var _=(e,t,l,i)=>{if(t.autoScrollAnimationId!==null)return;t.autoScrollPaused=false,t.autoScrollStopped=false,t.autoScrollLastTimestamp=performance.now();let o=e.autoScrollSpeed??50,c=e.autoScrollDirection??"forward",r=a=>{if(t.autoScrollPaused||t.autoScrollStopped){t.autoScrollAnimationId=null;return}let u=a-t.autoScrollLastTimestamp;t.autoScrollLastTimestamp=a,u>100&&(u=100);let f=o*(u/1e3);c==="backward"&&(f=-f),i?e.feed.scrollTop+=f:e.feed.scrollLeft+=f,Re(e,l,i,c),t.autoScrollAnimationId=requestAnimationFrame(r);};t.autoScrollAnimationId=requestAnimationFrame(r);},Re=(e,t,l,i)=>{if(!t.initialized||t.realSlides.length===0)return;let o=e.feed;if(i==="forward"){let c=l?o.scrollHeight-o.clientHeight:o.scrollWidth-o.clientWidth;if((l?o.scrollTop:o.scrollLeft)>=c-1){let a=t.realSlides[0];a&&(l?o.scrollTop=a.offsetTop:o.scrollLeft=a.offsetLeft);}}else if((l?o.scrollTop:o.scrollLeft)<=1){let r=t.realSlides[t.realSlides.length-1];r&&(l?o.scrollTop=r.offsetTop:o.scrollLeft=r.offsetLeft);}},K=e=>{e.autoScrollAnimationId!==null&&(cancelAnimationFrame(e.autoScrollAnimationId),e.autoScrollAnimationId=null),e.autoScrollResumeTimeout!==null&&(clearTimeout(e.autoScrollResumeTimeout),e.autoScrollResumeTimeout=null);},z=e=>{e.autoScrollPaused=true,e.autoScrollAnimationId!==null&&(cancelAnimationFrame(e.autoScrollAnimationId),e.autoScrollAnimationId=null);},G=(e,t,l,i)=>{t.autoScrollStopped||(t.autoScrollLastTimestamp=performance.now(),t.autoScrollPaused=false,t.autoScrollAnimationId===null&&_(e,t,l,i));},Y=(e,t,l,i)=>{if(t.autoScrollStopped)return;t.autoScrollResumeTimeout!==null&&clearTimeout(t.autoScrollResumeTimeout);let o=e.autoScrollStartDelay??0;o>0?t.autoScrollResumeTimeout=setTimeout(()=>{t.autoScrollResumeTimeout=null,G(e,t,l,i);},o):G(e,t,l,i);},se=(e,t,l,i,o)=>{if(!e.autoScroll)return;let c=e.stopOnMouseEnter!==false,r=e.stopOnFocusIn!==false;c&&(e.feed.addEventListener("mouseenter",()=>z(t),{signal:o}),e.feed.addEventListener("mouseleave",()=>Y(e,t,l,i),{signal:o})),r&&(e.feed.addEventListener("focusin",()=>z(t),{signal:o}),e.feed.addEventListener("focusout",()=>Y(e,t,l,i),{signal:o})),e.feed.addEventListener("touchstart",()=>z(t),{passive:true,signal:o}),e.feed.addEventListener("touchend",()=>Y(e,t,l,i),{signal:o});};var de=e=>({initialized:false,clonedSlides:[],realSlides:[...e],clonesPerSide:0}),He=e=>{let t=N()?e.desktopSlidesPerView:e.mobileSlidesPerView;if(e.autoScroll){let l=!t||t==="auto"?3:Math.ceil(t)+1;return Math.min(l,e.slides.length)}return !t||t==="auto"?1:Math.ceil(t)},Q=(e,t,l)=>{if(!e.loop||t.initialized)return;let i=t.realSlides,o=He(e);t.clonesPerSide=o;for(let c=i.length-o;c<i.length;c++){let r=i[c];if(!r)continue;let a=r.cloneNode(true);a.setAttribute("data-lazer-clone","prepend"),a.setAttribute("aria-hidden","true"),e.feed.insertBefore(a,e.feed.firstChild),t.clonedSlides.push(a);}for(let c=0;c<o;c++){let r=i[c];if(!r)continue;let a=r.cloneNode(true);a.setAttribute("data-lazer-clone","append"),a.setAttribute("aria-hidden","true"),e.feed.appendChild(a),t.clonedSlides.push(a);}requestAnimationFrame(()=>{let c=i[0];c&&(l?e.feed.scrollTop=c.offsetTop:e.feed.scrollLeft=c.offsetLeft);}),t.initialized=true;},ue=(e,t,l,i,o,c,r)=>{if(!t.loop||!l.initialized)return;c(true);let a=l.realSlides,u=a.length;if(e==="next"){let f=a[0];f&&(i?t.feed.scrollTop=f.offsetTop:t.feed.scrollLeft=f.offsetLeft),o(0);}else {let f=a[u-1];f&&(i?t.feed.scrollTop=f.offsetTop:t.feed.scrollLeft=f.offsetLeft),o(u-1);}requestAnimationFrame(()=>{requestAnimationFrame(()=>{c(false),r();});});},fe=e=>{e.initialized&&(e.clonedSlides.forEach(t=>{t.remove();}),e.clonedSlides=[],e.initialized=false,e.clonesPerSide=0);};var J=(e,t,l)=>{if(t.autoplayIntervalId)return;let i=e.autoplayInterval??3e3;t.autoplayIntervalId=setInterval(()=>{t.autoplayPaused||l("next");},i);},Z=e=>{e.autoplayIntervalId&&(clearInterval(e.autoplayIntervalId),e.autoplayIntervalId=null);},me=e=>{e.autoplayPaused=true;},pe=e=>{e.autoplayPaused=false;},Se=(e,t,l)=>{!e.autoplay||e.pauseOnHover===false||(e.feed.addEventListener("mouseenter",()=>me(t),{signal:l}),e.feed.addEventListener("mouseleave",()=>pe(t),{signal:l}),e.feed.addEventListener("touchstart",()=>me(t),{passive:true,signal:l}),e.feed.addEventListener("touchend",()=>pe(t),{signal:l}));};var ee=(e,t,l)=>{if(e.scrollbarThumb)if(l){let i=t.height/e.feed.scrollHeight*100;e.scrollbarThumb.style.height=`${i}%`,e.scrollbarThumb.style.width="";}else {let i=t.width/e.feed.scrollWidth*100;e.scrollbarThumb.style.width=`${i}%`,e.scrollbarThumb.style.height="";}},he=(e,t)=>{if(!(!e.scrollbarThumb||!e.scrollbarTrack))if(t){let l=e.scrollbarTrack.getBoundingClientRect().height,i=e.scrollbarThumb.getBoundingClientRect().height,o=l-i,c=e.feed.scrollHeight-e.feed.clientHeight,r=c>0?e.feed.scrollTop/c:0;e.scrollbarThumb.style.transform=`translateY(${o*r}px)`;}else {let l=e.scrollbarTrack.getBoundingClientRect().width,i=e.scrollbarThumb.getBoundingClientRect().width,o=l-i,c=e.feed.scrollWidth-e.feed.clientWidth,r=c>0?e.feed.scrollLeft/c:0;e.scrollbarThumb.style.transform=`translateX(${o*r}px)`;}};var te=(e,t,l,i=k,o,c)=>{let r=l?e.scrollTop:e.scrollLeft,a=Math.abs(t-r),u=Math.min(H.MAX_DURATION,Math.max(H.MIN_DURATION,a/H.SPEED_FACTOR)),f=performance.now(),p=E=>{if(c?.cancelled)return;let n=(E-f)/u,S=Math.min(n,1),L=i(S),v=r+(t-r)*L;l?e.scrollTop=v:e.scrollLeft=v,S<1?requestAnimationFrame(p):(l?e.scrollTop=t:e.scrollLeft=t,o?.());};requestAnimationFrame(p);},V=e=>e.filter(t=>t.offsetParent!==null),oe=(e,t,l)=>{let i=l?e.desktopSlidesPerView:e.mobileSlidesPerView,o=e.slideGap??0;if(o>0&&(e.feed.style.gap=`${o}px`),!i||i==="auto"){e.slides.forEach(a=>{a.style.flex="",a.style.minWidth="",a.style.minHeight="";});return}let r=`calc((100% - ${o*(i-1)}px) / ${i})`;t?e.slides.forEach(a=>{a.style.flex=`0 0 ${r}`,a.style.minHeight=r,a.style.minWidth="";}):e.slides.forEach(a=>{a.style.flex=`0 0 ${r}`,a.style.minWidth=r,a.style.minHeight="";});},be=(e,t,l,i)=>{let o=i?e.clientHeight:e.clientWidth;return !t||l!==o?{rect:e.getBoundingClientRect(),size:o}:{rect:t,size:l}};var we=e=>{if(!e.feed)throw new Error("lazer-slider: feed element is required");if(!e.slides?.length)throw new Error("lazer-slider: slides array is required and must not be empty");if(e.feed.id||(e.feed.id=`lazer-slider-feed-${Math.random().toString(36).substr(2,9)}`),e.bulletsContainer&&!e.thumbs){let s=q({bulletsContainer:e.bulletsContainer,slides:e.slides,bulletClass:e.bulletsClass??"slider-bullet",bulletActiveClass:e.bulletsActiveClass??"active",feedId:e.feed.id});e.thumbs=s;}if(e.thumbsContainer&&!e.thumbs){let s=j({thumbsContainer:e.thumbsContainer,slides:e.slides,thumbClass:e.thumbsClass??"slider-thumb",thumbActiveClass:e.thumbsActiveClass??"active",feedId:e.feed.id,thumbImageSelector:e.thumbImageSelector??"img",thumbSize:e.thumbSize});e.thumbs=s;}let t=e.direction??"horizontal",l=t==="vertical",i=e.easing??k,o={currentSlideIndex:0,isScrolling:false,ticking:false,cachedFeedRect:null,lastWidth:0,updateThumbTimeout:null,scrollEndTimeout:null,abortController:new AbortController,autoplayIntervalId:null,autoplayPaused:false,autoScrollAnimationId:null,autoScrollPaused:false,autoScrollLastTimestamp:0,autoScrollStopped:false,autoScrollResumeTimeout:null,isLoopRepositioning:false},c=null,r=de(e.slides),a={cancelled:false},u=null,f=()=>{let s=be(e.feed,o.cachedFeedRect,o.lastWidth,l);return o.cachedFeedRect=s.rect,o.lastWidth=s.size,s.rect},p=(s,d)=>{te(e.feed,s,l,i,d);},E=(s,d)=>{a.cancelled=true,a={cancelled:false},te(e.feed,s,l,d??i,void 0,a);},n=()=>{if(o.isLoopRepositioning)return;let s=f(),d,b,h;if(l?(d=e.feed.scrollTop<=1,b=e.feed.scrollTop+s.height>=e.feed.scrollHeight-1,h=e.feed.scrollHeight<=s.height):(d=e.feed.scrollLeft<=1,b=e.feed.scrollLeft+s.width>=e.feed.scrollWidth-1,h=e.feed.scrollWidth<=s.width),e.scrollbarTrack&&(e.scrollbarTrack.style.display=h?"none":"block"),e.loop){W(e.prevSlideButton,!h,e.feed),W(e.nextSlideButton,!h,e.feed);return}W(e.prevSlideButton,!d&&!h,e.feed),W(e.nextSlideButton,!b&&!h,e.feed);},S=()=>{let s=f(),d=r.initialized?r.realSlides:V(e.slides),b=d.filter(h=>{let m=h.getBoundingClientRect(),T=20;return l?m.bottom>s.top+T&&m.top<s.bottom-T:m.right>s.left+T&&m.left<s.right-T});if(b.length&&b[0]){let h=d.indexOf(b[0]);if(h!==-1){o.currentSlideIndex=h;let m=l?e.feed.scrollTop:e.feed.scrollLeft;e.onScroll?.({currentScroll:m,currentSlideIndex:o.currentSlideIndex});}}},L=s=>{if(!e.thumbs)return;let d=e.thumbs.indexOf(s);if(d===-1||!e.slides[d])return;o.currentSlideIndex=d,F(e.thumbs,d),o.isScrolling=true,o.updateThumbTimeout&&clearTimeout(o.updateThumbTimeout),o.updateThumbTimeout=setTimeout(()=>{o.isScrolling=false;},H.THUMB_UPDATE_DELAY);let b=l?e.slides[d].offsetTop:e.slides[d].offsetLeft;p(b);},v=s=>{let d=r.initialized?r.realSlides:V(e.slides),b=N()?e.desktopSlidesPerScroll??1:e.mobileSlidesPerScroll??1,h=d.length;S();let m,T=false;if(s==="prev")if(e.loop&&r.initialized&&o.currentSlideIndex===0){let g=r.clonedSlides.filter(I=>I.getAttribute("data-lazer-clone")==="prepend");m=g[g.length-1],T=true;}else o.currentSlideIndex=Math.max(0,o.currentSlideIndex-b),m=d[o.currentSlideIndex];else e.loop&&r.initialized&&o.currentSlideIndex>=h-1?(m=r.clonedSlides.filter(I=>I.getAttribute("data-lazer-clone")==="append")[0],T=true):(o.currentSlideIndex=Math.min(h-1,o.currentSlideIndex+b),m=d[o.currentSlideIndex]);if(!m)return;let y=l?e.feed.scrollTop:e.feed.scrollLeft;e.onScrollStart?.({currentScroll:y,target:m,direction:s});let R=l?m.offsetTop:m.offsetLeft;T?p(R,()=>{ue(s,e,r,l,g=>{o.currentSlideIndex=g;},g=>{o.isLoopRepositioning=g;},n);}):p(R);},O=()=>{he(e,l),n(),S(),o.isScrolling||F(e.thumbs,o.currentSlideIndex),o.scrollEndTimeout&&clearTimeout(o.scrollEndTimeout),o.scrollEndTimeout=setTimeout(()=>{o.isScrolling=false;let s=l?e.feed.scrollTop:e.feed.scrollLeft;e.onScrollEnd?.({currentScroll:s,currentSlideIndex:o.currentSlideIndex});},H.SCROLL_END_DELAY);},U=()=>{o.ticking||(requestAnimationFrame(()=>{O(),o.ticking=false;}),o.ticking=true);},B=()=>{let s=o.currentSlideIndex;o.cachedFeedRect=null;let d=()=>{let h=(r.initialized?r.realSlides:V(e.slides))[s];if(h){let m=l?h.offsetTop:h.offsetLeft;l?e.feed.scrollTop=m:e.feed.scrollLeft=m;}};d(),u&&clearTimeout(u),u=setTimeout(()=>{A(),d();},150);},X=()=>{let{signal:s}=o.abortController;window.addEventListener("resize",B),e.feed.addEventListener("scroll",U,{passive:true,signal:s}),e.prevSlideButton&&e.prevSlideButton.addEventListener("click",()=>v("prev"),{signal:s}),e.nextSlideButton&&e.nextSlideButton.addEventListener("click",()=>v("next"),{signal:s}),e.thumbs?.length&&(e.thumbs[0]?.classList.add("active"),e.thumbs.forEach(d=>{d.addEventListener("click",()=>L(d),{signal:s});})),re(e.feed,()=>v("prev"),()=>v("next"),s,t),e.enableDragToScroll!==false&&(c=ae({feed:e.feed,slides:e.slides,abortSignal:s,smoothScrollTo:E,onDragStart:()=>{e.autoScroll&&z(o);},onDragEnd:d=>{let b=d?.getAttribute("data-lazer-clone");if(!!(b&&e.loop&&r.initialized)&&d){let m=r.realSlides,T=0,y;if(b==="prepend"){let g=r.clonedSlides.filter(I=>I.getAttribute("data-lazer-clone")==="prepend").indexOf(d);T=m.length-r.clonesPerSide+g,y=m[T];}else if(b==="append"){let g=r.clonedSlides.filter(I=>I.getAttribute("data-lazer-clone")==="append").indexOf(d);T=g,y=m[g];}if(y){o.currentSlideIndex=T;let R=l?y.offsetTop:y.offsetLeft;setTimeout(()=>{a.cancelled=true,l?e.feed.scrollTop=R:e.feed.scrollLeft=R;},H.MIN_DURATION),F(e.thumbs,o.currentSlideIndex);}}else S(),F(e.thumbs,o.currentSlideIndex);e.autoScroll&&!o.autoScrollStopped&&(e.stopOnInteraction?o.autoScrollStopped=true:Y(e,o,r,l));},direction:t,loop:e.loop})),Se(e,o,s),se(e,o,r,l,s);},P=s=>{let d=r.initialized?r.realSlides:V(e.slides),b=Math.max(0,Math.min(s,d.length-1)),h=d[b];if(!h)return;o.currentSlideIndex=b,F(e.thumbs,b);let m=l?h.offsetTop:h.offsetLeft;p(m);},A=()=>{o.cachedFeedRect=null,oe(e,l,N()),ee(e,f(),l),n(),e.autoScroll&&!o.autoScrollPaused&&!o.autoScrollStopped&&(K(o),_(e,o,r,l));},M=()=>{Z(o),K(o),o.abortController.abort(),window.removeEventListener("resize",B),o.updateThumbTimeout&&clearTimeout(o.updateThumbTimeout),o.scrollEndTimeout&&clearTimeout(o.scrollEndTimeout),u&&clearTimeout(u),c&&ce(c),fe(r),o.cachedFeedRect=null;},C=()=>{e.autoScroll?(o.autoScrollStopped=false,o.autoScrollPaused?G(e,o,r,l):_(e,o,r,l)):e.autoplay&&J(e,o,v);},x=()=>{e.autoScroll?z(o):Z(o);};if(le(e),oe(e,l,N()),e.autoScroll){e.loop=true,Q(e,r,l);let s=e.autoScrollStartDelay??0;s>0?o.autoScrollResumeTimeout=setTimeout(()=>{o.autoScrollResumeTimeout=null,_(e,o,r,l);},s):requestAnimationFrame(()=>{requestAnimationFrame(()=>{_(e,o,r,l);});});}else Q(e,r,l),e.autoplay&&J(e,o,v);return n(),X(),ee(e,f(),l),{goToIndex:P,refresh:A,unload:M,play:C,pause:x,next:()=>v("next"),prev:()=>v("prev")}};export{we as createSlider,Ee as easeInOutCubic,w as easeOutCubic,k as easeOutExpo,Le as easeOutQuad,q as generateBullets,j as generateThumbs,Ae as linear};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lazer-slider",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A lightweight, accessible slider with smooth scroll-to-snap animations and drag-to-scroll support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "tsup && cp src/styles/lazer-slider.css dist/",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:watch": "vitest",
|
|
23
25
|
"prepare": "npm run build"
|
|
24
26
|
},
|
|
25
27
|
"keywords": [
|
|
@@ -38,8 +40,10 @@
|
|
|
38
40
|
"author": "Cesar Devs",
|
|
39
41
|
"license": "UNLICENSED",
|
|
40
42
|
"devDependencies": {
|
|
43
|
+
"jsdom": "^25.0.0",
|
|
41
44
|
"tsup": "^8.0.0",
|
|
42
|
-
"typescript": "^5.0.0"
|
|
45
|
+
"typescript": "^5.0.0",
|
|
46
|
+
"vitest": "^3.0.0"
|
|
43
47
|
},
|
|
44
48
|
"repository": {
|
|
45
49
|
"type": "git",
|