@twistedandy/better-carousel 1.0.0 → 1.1.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 +12 -11
- package/dist/better-carousel.js +459 -261
- package/dist/better-carousel.min.js +1 -1
- package/package.json +1 -1
- package/src/scripts/autoplay.js +39 -5
- package/src/scripts/carousel.js +44 -8
- package/src/scripts/geometry.js +9 -6
- package/src/scripts/input.js +61 -9
- package/src/scripts/layout.js +76 -23
- package/src/scripts/markup.js +25 -5
- package/src/scripts/navigation.js +209 -209
- package/src/types/better-carousel.d.ts +232 -232
|
@@ -1 +1 @@
|
|
|
1
|
-
var BetterCarousel=(()=>{"use strict";function t(t,e,n){e&&t.classList.contains(e)!==!!n&&t.classList.toggle(e,!!n)}function e(t,e,n){t.getAttribute(e)!==(n||null)&&(n?t.setAttribute(e,n):t.removeAttribute(e))}function n(t,e,n){t.style[e]!==n&&(t.style[e]=n)}function o(t){""===t.getAttribute("style")&&t.removeAttribute("style")}function r(t,e){const n=document.createElement(t);return e&&(n.className=e),n}function i(t,e){if("string"==typeof t){for(let n=e;n;n=n.parentElement){const e=n.querySelector(t);if(e)return e}return null}return!0===t?e:t||null}const s=new WeakMap,a=new WeakMap;function l(t,e,n){const o=s.get(t)||new Set;!o.has(e)&&t.hasAttribute(e)||(o.add(e),s.set(t,o),t.getAttribute(e)!==n&&t.setAttribute(e,n))}function c(t,e){if(e&&!t.classList.contains(e)){const n=a.get(t)||new Set;t.classList.add(e),n.add(e),a.set(t,n)}}const d=new WeakSet;let u=0;function p(t,e){return[...e?t.querySelectorAll(e):t.children].filter(t=>!d.has(t))}const f={delay:4e3,stopOnInteraction:!0,pauseOnHover:!1,pauseOnFocus:!0,stopOnLastSnap:!1,playOnInit:!0,instant:!1,timer:null},g={speed:120,direction:"next",startDelay:1e3,stopOnInteraction:!0,pauseOnHover:!1,pauseOnFocus:!0,playOnInit:!0};function h(t,e,n){return{...t,..."number"==typeof n?{[e]:n}:n}}function m(n,o,i,s){const{api:a,root:c,container:d,cls:u,emit:p}=n,f=n.options.labels,g=r("button",u.button+" "+u.playButton);let h=!1,m=null,v=!0;function b(){e(g,"aria-label",h?f.pause:f.play),t(c,u.playing,h),l(d,"aria-live",h?"off":"polite")}function x(){a.isFit()?g.remove():g.isConnected||c.append(g),v&&(v=!1,i.playOnInit&&!matchMedia("(prefers-reduced-motion: reduce)").matches&&y.play())}g.type="button",g.setAttribute("aria-controls",d.id),g.addEventListener("click",()=>h?y.stop():y.play());const y={play(){h||(h=!0,m=((t,e)=>{const n=new Set,o=(t,e)=>{const o=n.size;n[e?"add":"delete"](t),!o!=!n.size&&s.pause(m.paused())},r=new IntersectionObserver(([t])=>o("view",!t.isIntersecting)),i=[[document,"visibilitychange",()=>o("tab",document.hidden)],[t,"pointerenter",t=>o("mouse",e.pauseOnHover&&"mouse"===t.pointerType)],[t,"pointerleave",()=>o("mouse",!1)],[t,"focusin",t=>o("focus",e.pauseOnFocus&&t.target.matches(":focus-visible"))],[t,"focusout",e=>o("focus",t.contains(e.relatedTarget)&&n.has("focus"))]];return r.observe(t),i.forEach(([t,e,n])=>t.addEventListener(e,n)),{paused:()=>n.size>0,remove(){r.disconnect(),i.forEach(([t,e,n])=>t.removeEventListener(e,n))}}})(c,i),b(),s.play(),p(o.toLowerCase()+":play"))},stop(){h&&(h=!1,m.remove(),b(),s.stop(),p(o.toLowerCase()+":stop"))},isPlaying(){return h},paused(){return!h||m.paused()},remove(){y.stop(),g.remove(),delete a[o]}};return[["init",x],["reinit",x],["resize",x],...s.events].forEach(([t,e])=>n.on(t,e)),b(),a[o]=y,y}function v(t,e,n,o,r,i=0){return t.map(t=>{const s=(i+n/2-e-(t.start+t.end)/2)/o,a=Math.round(s);return{k:a,offset:r>0?a+.5-s:s-a+.5}})}function b(t,e){return t-Math.ceil(t/e)*e}function x(t,e,n){return Math.min(n,Math.max(e,t))}function y(t,e,n){return n?(t%e+e)%e:x(t,0,e-1)}function w(t,e,n,o){return"function"==typeof t?t(e,n,o):"center"===t?(e-n)/2:"end"===t?e-n:0}function M(t){let e=1/0,n=-1/0,o=0;for(const r of t)e=Math.min(e,r.start),n=Math.max(n,r.end),o=Math.max(o,r.end-r.start);return{start:e,end:n,size:n-e,max:o}}function E(t,e,n){const o=t-e;return n?o-Math.round(o/n)*n:o}function S(t,e,n,o,r,i=0,s=t.length){let a=-1,l=1/0;return t.forEach((t,c)=>{const d=Math.abs(E(t.start+e,w(o,n,t.end-t.start,c),r));c>=i&&s>c&&l-.5>d&&(l=d,a=c)}),a}function L(t,e,n){let o=0,r=1/0;return t.forEach((t,i)=>{const s=Math.abs(E(t.location,e,n));r>s&&(r=s,o=i)}),o}function T(t,e,n,o=0){return n?o>0?t+(Math.ceil((e-.5-t)/n)-1)*n:0>o?t+(Math.floor((e+.5-t)/n)+1)*n:e+E(t,e,n):t}function k(t,{min:e,max:n,period:o}){if(o){const e=(n-t)/o;return e-Math.floor(e)}return n>e?x((n-t)/(n-e),0,1):0}function z(t,e,n,o,r){const i=[];return t.forEach((t,s)=>{const a=t.end-t.start,l=r?E(t.start+e+a/2,n/2,r)+n/2-a/2:t.start+e,c=Math.min(l+a,n)-Math.max(l,0);c>0&&c>=o*a-.5&&i.push(s)}),i}function A(t){return"x"===t?document.documentElement.clientWidth:innerHeight}const O=new WeakMap;let P;function C(t,e){P||=new ResizeObserver(t=>{[...new Set(t.filter(t=>!O.get(t.target)?.skip(t)).map(t=>O.get(t.target)))].filter(t=>t&&t.read()).forEach(t=>t.write())});for(const n of t)e?(O.set(n,e),P.observe(n)):(O.delete(n),P.unobserve(n))}const F=new Map,I=new WeakMap,N=new WeakMap,_=[.25,1,.5,1],B=[.2,.6,.35,1];function R([t,e,n,o]){const r=(t,e,n)=>((1+3*t-3*e)*n+3*e-6*t)*n*n+3*t*n;return i=>{if(0>=i||i>=1)return i>0?1:0;let s=i;for(let a=0;6>a;a++){const a=r(t,n,s)-i,l=3*(1+3*t-3*n)*s*s+2*(3*n-6*t)*s+3*t;if(1e-5>Math.abs(a))return r(e,o,s);if(1e-6>Math.abs(l))break;s-=a/l}let a=0,l=1;for(s=i;l-a>1e-5;)r(t,n,s)<i?a=s:l=s,s=(a+l)/2;return r(e,o,s)}}const H={axis:"auto",align:"auto",dir:"auto",loop:!1,dragFree:!1,dragFriction:1,containScroll:"trimSnaps",slidesPerSnap:1,skipSnaps:!0,dragThreshold:10,duration:400,startSnap:0,lazy:!1,drag:!0,wheel:!0,keys:!0,resize:!0,slideChanges:!0,focus:!0,inViewThreshold:0,active:!0,breakpoints:{},container:null,slides:null,wrapper:!0,arrows:!0,dots:!0,dotsStyle:"zoom",labels:{carousel:"Carousel",slide:"%d of %n",prev:"Previous slide",next:"Next slide",dot:"Go to slide %d",play:"Start the slide show",pause:"Stop the slide show"},classes:null,state:"",sync:null,clones:"auto",autoplay:!1,autoScroll:!1,autoHeight:!1,progress:!1,offset:!1},j=t=>({root:t,viewport:t+"_viewport",container:t+"_container",fit:t+"_fit",horizontal:t+"_horizontal",vertical:t+"_vertical",autoHeight:t+"_auto_height",button:t+"_button",prevButton:t+"_prev",nextButton:t+"_next",dots:t+"_dots",dotsTrack:t+"_dots_track",dotsMarker:t+"_dots_marker",dotsAll:t+"_dots_all",dot:t+"_dot",playButton:t+"_play",clone:"clone",selected:"selected",inView:"",dragging:"dragging",playing:"playing",first:"first",prev:"prev",current:"current",next:"next",last:"last"}),D=["selected","inView","dragging","playing","first","prev","current","next","last"];function G(...t){const e={};for(const n of t)for(const t in n){const o=n[t],r=e[t];e[t]=o&&r&&"object"==typeof o&&"object"==typeof r&&o.constructor===Object&&r.constructor===Object?{...r,...o}:o}return e}function W(t,...e){let n={};try{n=JSON.parse(t.dataset.carousel||"{}")}catch{}return G(H,...e,n)}const V=new WeakMap,q=t=>V.get(t),K="input,textarea,select,[contenteditable]",X=[t=>{const{viewport:e,options:n}=t;if(!n.drag)return;let o,r,i,s=null,a=!1,l=[],c=0;const d=t=>["pointermove","pointerup","pointercancel"].forEach(e=>window[t](e,p));function u(e){a=!1;const n=t.geo();null!==s||e.button||!n||n.fit||e.target.closest(K)||("mouse"===e.pointerType&&e.preventDefault(),s=e.pointerId,i={x:"x"===n.axis,sign:n.sign},o=[e.clientX,e.clientY],l=[],d("addEventListener"))}function p(a){if(a.pointerId!==s)return;if("pointermove"!==a.type)return l.length&&l.push([l[l.length-1][0],a.timeStamp]),f("pointerup"===a.type);const d=a.clientX-o[0],u=a.clientY-o[1],p=i.x?d*i.sign:u,g=i.x?u:d;if(!t.dragging()){if("mouse"!==a.pointerType&&Math.abs(g)>Math.abs(p))return f();if(n.dragThreshold>Math.abs(p))return;r=t.halt(),c=t.selected(),t.drag(!0),e.setPointerCapture(s)}const h=t.geo(),m=r+p,v=x(m,h.min,h.max);t.hold(h.period?m:v+(m-v)/4,!0),l.push([p,a.timeStamp]),l.length>10&&l.shift()}function f(e){if(d("removeEventListener"),s=null,!t.dragging())return;const o=t.geo(),i=t.location(),u=e?(t=>{const e=t[t.length-1],n=t.find(t=>100>=e[1]-t[1]),o=e[1]-n[1];return o>0?(e[0]-n[0])/o:0})(l):0,p=(({location:t,from:e,velocity:n,current:o,snaps:r,min:i,max:s,period:a,skipSnaps:l,dragFree:c,dragFriction:d=1})=>{const u=r.length;let p=t+325*n/d;if(a||(p=x(p,i,s)),"number"==typeof l&&l>0&&u-1+!a>l){const t=t=>T(r[y(o+t*l,u,a)].location,e,a,t);p=x(p,t(1),t(-1))}if(!0===c)return{location:p,snap:L(r,p,a)};if(c||l){const t=L(r,p,a);return{location:T(r[t].location,p,a),snap:t}}const f=t-e;let g=0;Math.abs(n)>.3?g=0>n?1:-1:Math.abs(f)>20&&(g=0>f?1:-1);const h=y(o+g,u,a),m=r[h].location;return{location:a?T(m,g?e:t,a,h===o?0:g):m,snap:h}})({location:i,from:r,velocity:u,current:c,snaps:o.snaps,min:o.min,max:o.max,period:o.period,skipSnaps:n.skipSnaps,dragFree:n.dragFree,dragFriction:n.dragFriction}),f=!0===n.dragFree?B:_;a=!0,t.drag(!1),t.move(p.snap,p.location,((t,e,n,o)=>Math.sign(t)!==Math.sign(e)||.05>Math.abs(e)?o:x(Math.abs(t)*n[1]/n[0]/Math.abs(e),200,1200))(p.location-i,u,f,n.duration),f)}function g(t){a&&(a=!1,t.preventDefault(),t.stopPropagation())}const h=t=>t.preventDefault(),m=e=>t.dragging()&&e.preventDefault();return e.addEventListener("pointerdown",u),e.addEventListener("click",g,!0),e.addEventListener("dragstart",h),e.addEventListener("selectstart",m),{remove(){d("removeEventListener"),e.removeEventListener("pointerdown",u),e.removeEventListener("click",g,!0),e.removeEventListener("dragstart",h),e.removeEventListener("selectstart",m)}}},t=>{const{viewport:e,options:n}=t,o=!0===n.dragFree;if(!n.wheel)return;let r=0,i=0,s=0,a=0,l=0;function c(e){const n=t.geo(),c="x"===n.axis&&Math.abs(e.deltaX)>Math.abs(e.deltaY)?e.deltaX*n.sign:e.deltaY;if(e.ctrlKey||!c||t.dragging())return;const u=e.timeStamp,p=200>u-r,f=t.location(),g=c*(1===e.deltaMode?40:e.deltaMode?n.view:1);let h=f-g;n.period||(h=x(h,n.min,n.max)),r=u,.5>Math.abs(h-f)?p&&1e3>u-i&&e.preventDefault():(e.preventDefault(),t.emit("interact"),s||(a=t.selected()),i=u,l=g>0?1:-1,t.move(L(n.snaps,h,n.period),h,180,_),clearTimeout(s),o||(s=setTimeout(d,150)))}function d(){s=0;const e=t.geo(),n=t.current(),o=L(e.snaps,n,e.period),r=Math.abs(T(e.snaps[o].location,n,e.period)-n)>10;t.step(o,o===a&&r?l:0)}function u(){const o=t.geo();e[o.fit||"y"!==o.axis&&"both"!==n.wheel?"removeEventListener":"addEventListener"]("wheel",c,{passive:!1})}return["init","reinit","resize"].forEach(e=>t.on(e,u)),{remove(){e.removeEventListener("wheel",c),clearTimeout(s)}}},t=>{const{api:e,root:n,options:o}=t;if(o.keys)return n.addEventListener("keydown",r),{remove(){n.removeEventListener("keydown",r)}};function r(n){const o=t.geo(),{key:r,target:i}=n,s=o&&!o.fit&&("y"===o.axis?{ArrowUp:-1,ArrowDown:1}:{ArrowLeft:-o.sign,ArrowRight:o.sign})[r],a=s>0?"Next":"Prev";s&&!(n.altKey||n.ctrlKey||n.metaKey||n.shiftKey||i.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(i.tagName))&&e["canGoTo"+a]()&&(n.preventDefault(),e["goTo"+a]())}},t=>{const{api:e,container:n,options:o}=t;let r=-1e4;function i(t){t.target.closest(K)||(r=t.timeStamp)}function s(n){const i=t.geo(),s=e.slideNodes().findIndex(t=>t.contains(n.target));!i||0>s||600>n.timeStamp-r||(o.focus&&!z(i.slides,t.location(),i.view,1,i.period).map(t=>t%i.count).includes(s)&&e.goToSlide(s),t.emit("slidefocus"))}return n.addEventListener("pointerdown",i),n.addEventListener("focusin",s),{remove(){n.removeEventListener("pointerdown",i),n.removeEventListener("focusin",s)}}},n=>{const{api:o,root:s,cls:a,options:l}=n,c=l.labels,d=i(l.arrows,s),u=i(l.dots,s),p=[],f=[],g="all"!==l.dotsStyle,h=u&&r("div",g?a.dots:a.dots+" "+a.dotsAll),m=h&&r("div",a.dotsTrack);let v=new Map;if(d||u)return h&&(m.append(r("span",a.dotsMarker)),h.append(m),u.append(h)),d&&[["prev","goToPrev"],["next","goToNext"]].forEach(([t,e])=>{const i=r("button",a.button+" "+a[t+"Button"]);i.type="button",i.setAttribute("aria-label",c[t]),i.setAttribute("aria-controls",n.container.id),i.addEventListener("click",()=>o[e]()),p.push(i)}),["init","reinit","resize","select","slideschanged"].forEach(t=>n.on(t,b)),{remove(){p.forEach(t=>t.remove()),h?.remove()}};function b(){const i=o.isFit(),s=i?0:o.snapProgress().length,l=o.selectedSnap();if(p.forEach((t,e)=>{if(i)t.remove();else{t.isConnected||(h?.parentNode===d?h.before(t):d.append(t));const n=!(e?o.canGoToNext():o.canGoToPrev());t.disabled!==n&&(t.disabled=n)}}),!h)return;if(2>s)return void h.remove();for(;f.length>s;)f.pop().remove(),v.delete(f.length);for(;s>f.length;){const t=r("button",a.dot),e=f.length;t.type="button",t.setAttribute("aria-label",c.dot.replace("%d",e+1)),t.setAttribute("aria-controls",n.container.id),g&&(t.tabIndex=-1),t.addEventListener("click",()=>o.goToSnap(e)),f.push(t),m.append(t)}h.isConnected||u.append(h);const b=new Map;["first","prev","current","next","last"].forEach((t,e)=>{f[l+e-2]&&b.set(l+e-2,a[t])}),v.forEach((n,o)=>{b.get(o)!==n&&(t(f[o],n,!1),e(f[o],"aria-current",!1),f[o].tabIndex=g?-1:0)}),b.forEach((n,o)=>{t(f[o],n,!0),e(f[o],"aria-current",o===l&&"true"),f[o].tabIndex=0}),v=b,g&&x("--better-shift",2-(Math.max(0,l-2)+Math.min(s-1,l+2))/2),x("--better-dot",l)}function x(t,e){h.style.getPropertyValue(t)!==e+""&&h.style.setProperty(t,e)}},t=>{if(!t.options.autoplay)return;const e=t.api,n=h(f,"delay",t.options.autoplay);let o=0,r=null,i=!1;function s(){clearTimeout(o),r?.(),r=null}function a(){if(s(),!c.paused()&&!e.isFit()){const t=e.slideNodes()[e.selectedSlide()]?.dataset.delay||n.delay,i=+(Array.isArray(t)?t[e.selectedSnap()]:t);o=setTimeout(l,i),r=n.timer?.(i,e)}}function l(){s(),i=!0,e.canGoToNext()?e.goToNext(n.instant):n.stopOnLastSnap?c.stop():e.goToSnap(0,n.instant),i=!1}const c=m(t,"autoplay",n,{play:a,stop:s,pause:a,events:[["settle",a],["interact",()=>{i||(s(),n.stopOnInteraction&&c.stop())}]]});return c.reset=a,c},t=>{if(!t.options.autoScroll)return;const e=h(g,"speed",t.options.autoScroll);let n=0;const o=m(t,"autoScroll",e,{play:r,stop(){r(-1),t.halt()},pause(e){e?t.halt():n||i()},events:[["settle",()=>o.isPlaying()&&r()],["resize",()=>o.isPlaying()&&!n&&i()],["interact",()=>{o.isPlaying()&&(r(-1),e.stopOnInteraction&&o.stop())}]]});function r(t){clearTimeout(n),n=t?0:setTimeout(i,e.startDelay)}function i(){n=0;const r=t.geo();!r||r.fit||t.dragging()||o.paused()||t.scroll("prev"===e.direction?-1:1,e.speed/1e3)}return o},t=>{const{api:e,container:n}=t,o=t.options.sync;let r=null;if(o)return t.on("init",l),t.on("reinit",l),n.addEventListener("click",a),{remove(){r?.off("select",s),n.removeEventListener("click",a)}};function s(n){const o=r.selectedSlide();t.follow(o),e.goToSlide(o,!0===n)}function a(n){const o=t.nodes().findIndex(t=>t.contains(n.target));r&&o>-1&&r.goToSlide(o%e.slideNodes().length)}function l(){r||(r=o.goToSnap?o:q("string"==typeof o?i(o,t.root):o),r&&(r.on("select",s),s(!0)))}}];function Y(e,i={}){return((e,i,f,g)=>{const h=V.get(e);if(h)return h;let m,O,P,B,H,q,K,X=[],Y=[],U=[],J=[],$=[],Q=null,Z=!1,tt=!1,et=!1,nt=[],ot=0,rt=-1,it=0,st=null,at=0,lt=0,ct=0,dt=-1,ut=-1,pt=[],ft={axis:"",container:0,slides:[]},gt=!1,ht=!1;const mt={goToSnap:(t,e)=>Kt(Ct(t),e),goToNext:t=>mt.canGoToNext()&&qt(lt,1,t),goToPrev:t=>mt.canGoToPrev()&&qt(lt,-1,t),goToSlide:(t,e)=>Kt(Ct(mt.snapOfSlide(t)),e,t),canGoToNext:()=>!(!st||st.fit||!st.period&<>=st.snaps.length-1),canGoToPrev:()=>!(!st||st.fit||!st.period&&0>=lt),selectedSnap:()=>Pt(lt),previousSnap:()=>Pt(ct),selectedSlide:Ft,snapOfSlide:t=>st?Pt(((t,e,n,o,r,i)=>{const s=t.findIndex(t=>t.slide===n),a=e[n];return s>-1||!a?Math.max(s,0):L(t,w(r,o,a.end-a.start,n)-a.start,i)})(st.snaps,st.slides,t,st.view,st.align,st.period)):t,snapProgress:()=>st?st.logical.map(t=>k(st.snaps[t].location,st)):[],progress:()=>st?k(It(),st):0,slideNodes:()=>X.slice(),slidesInView:()=>pt.slice(),rootNode:()=>P,viewportNode:()=>B,containerNode:()=>H,isFit:()=>!st||st.fit,options:()=>m,reinit:Tt,destroy(){Lt(!1),vt.emit("destroy")}},vt=(t=>{const e={},n={},o=(t,e,n)=>(t[e]||=new Set).add(n);return{on:(n,r)=>(o(e,n,r),t),off:(n,o)=>(e[n]?.delete(o),t),listen(t,e){return o(n,t,e)},clear(){return Object.values(n).forEach(t=>t.clear())},emit(o){n[o]?.forEach(e=>e(t,o)),e[o]?.forEach(e=>e(t,o))},has(t){return!!e[t]?.size}}})(mt),bt={read:Nt,write:Bt,skip({target:t,contentRect:{width:e}}){if(t!==B)return!1;const n=e===ot;return ot=e,n&&m.autoHeight&&"x"===st?.axis}},xt={progress:0,snap:0},yt={node:null,index:0,offset:0,distance:0,size:0,visible:0},wt={api:mt,emit:vt.emit,on:vt.listen,geo:()=>st,nodes:()=>U,selected:()=>lt,dragging:()=>gt,location:()=>ht?It():at,current:It,hold(t,e){at=t,(e?Jt:Dt)(t),Ut()},halt:Qt,step:qt,scroll(t,e){const n=Qt(),o=t>0?st.min:st.max;st.period?(ht=!0,at=b(n,st.period),K.loop(at,t,st.period/e,st,U)):Math.abs(o-n)>1&&(ht=!0,at=o,K.run(n,o,Math.abs(o-n)/e,[0,0,1,1],vt.has("scroll")))},move(t,e,n,o){dt=-1,Xt(t,e,n,o)},drag(e){gt=e,t(P,O.dragging,e),e?(vt.emit("interact"),vt.emit("dragstart")):vt.emit("dragend")},follow(t){ut=t}};mt.on=vt.on,mt.off=vt.off;let Mt=W(e,f,i),Et=Mt.lazy?((t,e,n)=>{const o=!0===e?innerHeight:e,r=N.get(t)||t.getBoundingClientRect(),i=!0===e?"100%":e+"px";if(N.delete(t),r.height&&r.bottom>=-o&&r.top<=innerHeight+o)return null;let s=F.get(i);return s||(s=new IntersectionObserver(t=>t.forEach(t=>t.isIntersecting&&I.get(t.target)?.()),{rootMargin:i}),F.set(i,s)),I.set(t,n),s.observe(t),()=>{s.unobserve(t),I.delete(t)}})(e,Mt.lazy,Tt):null;return Et?V.set(e,mt):St(),mt;function St(){if(Q=((t,e)=>{const n=Object.entries(t.breakpoints||{}).map(([t,e])=>[matchMedia(t),e]);return n.forEach(([t])=>t.addEventListener("change",e)),{options:G(t,...n.filter(([t])=>t.matches).map(([,t])=>t)),remove(){return n.forEach(([t])=>t.removeEventListener("change",e))}}})(Mt||W(e,f,i),()=>Tt()),Mt=null,m=Q.options,m.active){O=((t,e)=>{const n="string"==typeof t?j(t):{...j(t?.prefix||"better"),...t};for(const t of D)n[t]&&(n[t]=e+n[t]);return n})(m.classes,m.state),({root:P,viewport:B,container:H}=((t,e,n)=>{let o=e.container?t.querySelector(e.container):t;o.classList.contains(n.viewport)&&(o=o.firstElementChild);let i=o.parentElement,s=i.parentElement;return d.has(i)||i.classList.contains(n.viewport)||!e.wrapper||(s=r("div"),i=r("div"),d.add(s).add(i),o.before(s),s.append(i),i.append(o)),c(s,n.root),c(i,n.viewport),c(o,n.container),l(s,"role","region"),l(s,"aria-roledescription","carousel"),s.hasAttribute("aria-labelledby")||l(s,"aria-label",e.labels.carousel),l(o,"id",o.id||"carousel-"+ ++u),l(o,"aria-live","polite"),{root:s,viewport:i,container:o}})(e,m,O));for(const t of[P,B,H])V.set(t,mt);X=p(H,m.slides),U=X,lt=m.startSnap,zt(!0),Object.assign(wt,{root:P,viewport:B,container:H,cls:O,options:m}),J=g.map(t=>t(wt)).filter(Boolean),K=((t,e,n,o,r)=>{let i=null;const s=()=>i.animations?i.animations[0].currentTime||0:performance.now()-i.start,a=()=>i&&i.from+(i.to-i.from)*i.ease(s()/i.duration);function l(){if(!i.animations&&s()>=i.duration)return c();i.raf=requestAnimationFrame(l),(i.animations?r:n)(a())}function c(){const t=i.to;d(),n(t),o()}function d(){const t=a();return i&&(i.animations?.forEach(t=>t.cancel()),cancelAnimationFrame(i.raf),i=null),t}function u(n){const o=t.animate([{translate:e(i.from)},{translate:e(i.to)}],{duration:i.duration,easing:"cubic-bezier("+i.curve+")",fill:"forwards"});o.currentTime=n,o.onfinish=c,i.animations=[o]}function p(n,o){if(d(),i=n,n.list){const r={duration:n.duration,iterations:1/0},i=document.timeline.currentTime,{from:s,to:a,length:l,direction:c}=n;n.animations=[t.animate([{translate:e(s)},{translate:e(a)}],r),...o.map((t,o)=>{const{k:i,offset:s}=n.list[o],a=e(i*l),d=e((i+c)*l);return t.animate([{translate:a},{translate:a,offset:s},{translate:d,offset:s},{translate:d}],r)})],n.animations.forEach(t=>t.startTime=i)}else n.script?n.start=performance.now():u(0);(n.script||r)&&(n.raf=requestAnimationFrame(l))}return{run(t,e,n,o,r){return p({from:t,to:e,duration:n,curve:o,script:r,ease:R(o)})},loop(t,e,n,o,r){return p({from:t,to:t-e*o.period,duration:n,direction:e,length:o.period,list:v(o.slides,t,o.area.size,o.period,e,o.area.start),ease(t){return t%1}},r)},retarget(t){if(!i||i.list)return!1;if(t!==i.to&&(i.to=t,i.animations)){const t=s();i.animations[0].cancel(),u(t)}return!0},stop:d,current:a,shifts(t){if(!i?.list)return null;const e=s()/i.duration%1;return i.list.map(({k:n,offset:o})=>t*(o>e?n:n+i.direction)*i.length)}}})(H,Vt,Jt,$t,(m.progress||m.offset)&&(t=>Gt(t,K.shifts(st.sign)||ft.slides))),m.autoHeight&&c(P,O.autoHeight),B.addEventListener("scroll",Zt),m.loop&&"fill"===m.clones&&addEventListener("resize",_t),m.slideChanges&&(q=new MutationObserver(At),q.observe(H,{childList:!0}))}}function Lt(r){if(Et?.(),Et=null,V.delete(e),zt(!1),q?.disconnect(),Q?.remove(),Q=null,O){K.stop(),J.forEach(t=>t.remove()),vt.clear(),J=[],ut=-1,gt=ht=!1,kt(0),B.removeEventListener("scroll",Zt),removeEventListener("resize",_t);for(const e of U)n(e,"translate",""),e.style.removeProperty("--better-offset"),t(e,O.selected,!1),t(e,O.inView,!1),o(e);n(H,"translate",""),n(H,"willChange",""),n(B,"touchAction",""),n(B,"height",""),P.style.removeProperty("--better-progress");for(const e of["horizontal","vertical","fit","dragging"])t(P,O[e],!1);for(const t of[P,B,H])o(t),V.delete(t);((t,e,n,o,r)=>{for(const r of[t,e,n,...o])s.get(r)?.forEach(t=>r.removeAttribute(t)),a.get(r)?.forEach(t=>r.classList.remove(t)),s.delete(r),a.delete(r),""===r.getAttribute("class")&&r.removeAttribute("class");!r&&d.has(t)&&(t.before(n),t.remove())})(P,B,H,X,r),O=st=null,Z=!1,at=0,pt=[],nt=[],ot=0,ft={axis:"",container:0,slides:[]}}}function Tt(t){t&&(i=G(i,t),Mt=null);const e=st?Ft():dt;Lt(!0),St(),dt=e}function kt(e){Y.length!==e*X.length&&(Y.forEach(t=>t.remove()),Y=((e,n,r)=>{const i=[];for(let s=0;n>s;s++)for(const n of e){const e=n.cloneNode(!0);for(const t of[e,...e.querySelectorAll("[id]")])t.removeAttribute("id");e.setAttribute("aria-hidden","true"),e.inert=!0,e.style.translate="",t(e,r,!0),o(e),d.add(e),i.push(e)}return i})(X,e,O.clone),H.append(...Y),U=X.concat(Y),ft.slides.length=X.length,q?.takeRecords())}function zt(t){C($),$=t?[B,H,...U]:[],C($,bt)}function At(){X=p(H,m.slides),kt(0),U=X,et=!0,zt(!0)}function Ot(t){return t%X.length}function Pt(t){return st?st.map[t]??0:t}function Ct(t){return st?((t,e,n)=>{let o=-1,r=1/0;return t.snaps.forEach((i,s)=>{const a=Math.abs(E(i.location,n,t.period));t.map[s]===e&&r>a&&(r=a,o=s)}),0>o?x(e,0,t.snaps.length-1):o})(st,t,It()):t}function Ft(){return ut>-1?ut:st?0>dt||mt.snapOfSlide(dt)!==Pt(lt)?Ot(st.snaps[lt].slide):dt:Math.max(dt,0)}function It(){return K.current()??at}function Nt(){const t=st?.sign||1,e=K.current(),n=((t,e)=>{const n=getComputedStyle(t),o=n.display,r=n.justifyContent;let i=e.axis;"auto"===i&&(i="x",o.includes("grid")?i=n.gridAutoFlow.startsWith("column")?"x":"y":o.includes("flex")&&n.flexDirection.startsWith("column")&&"nowrap"===n.flexWrap&&(i="y"));let s=e.align;"auto"===s&&(s="center"===r?"center":"flex-end"===r||"end"===r||"x"===i&&"right"===r?"end":"start");const a="x"===i&&("auto"===e.dir?"rtl"===n.direction:"rtl"===e.dir);return{axis:i,align:s,rtl:a,sign:a?-1:1,gap:parseFloat("x"===i?n.columnGap:n.rowGap)||0}})(H,m),o=((t,e,n,o)=>{const r=t.getBoundingClientRect(),i="x"===n.axis,s=n.sign,a=o.axis===n.axis,l=a?o.container:0;let c=0,d=0;const u=e.map((t,e)=>{const c=t.getBoundingClientRect(),d=(i?n.rtl?r.right-c.right:c.left-r.left:c.top-r.top)-s*(l+(a&&o.slides[e]||0));return{start:d,end:d+(i?c.width:c.height),cross:i?c.height:c.width}});u.forEach((t,e)=>{u[c].start>t.start&&(c=e),t.end>u[d].end&&(d=e)});let p=n.gap;if(u.length){const t=i?n.rtl?["Right","Left"]:["Left","Right"]:["Top","Bottom"];p+=(parseFloat(getComputedStyle(e[c])["margin"+t[0]])||0)+(parseFloat(getComputedStyle(e[d])["margin"+t[1]])||0)}return{view:i?r.width:r.height,slides:u,gap:p}})(B,U,n,null===e?ft:{axis:ft.axis,container:t*e,slides:K.shifts(t)||ft.slides});it=m.loop&&"fill"===m.clones?A(n.axis):0;const r=((t,e,n,o)=>{if(!o)return{start:0,size:n};const r=t.getBoundingClientRect(),i=Math.max(0,Math.round("x"===e.axis?e.rtl?o-r.right:r.left:r.top));return{start:-i,size:i+Math.max(n,Math.round(o-i))}})(B,n,o.view,it),i=[n.axis,n.rtl,"string"==typeof n.align&&n.align,o.view,o.gap,r.start,r.size,...o.slides.flatMap(t=>[t.start,t.end,t.cross])];if(Z&&i.length===nt.length&&i.every((t,e)=>t===nt[e]||.5>Math.abs(t-nt[e])))return!1;nt=i;const s=Z?Ft():dt,a=function(t,e,n,o,r){const i=M(e.slides.slice(0,o)),s=!(i.size>e.view+1||r.autoScroll&&r.loop),a=r.loop&&!s&&o,l=a?M(e.slides).size+e.gap:0,c=a&&r.clones&&(d=i.size+e.gap)>0?Math.max(0,Math.ceil((n.size+i.max)/d)-1):0;var d;if(c*o!==e.slides.length-o)return{copies:c};const u={...t,...e,area:n,fit:s,count:o,period:l,min:0,max:0};s?u.snaps=[{location:0,slide:S(e.slides,0,e.view,t.align)}]:Object.assign(u,(({slides:t,view:e,align:n,slidesPerSnap:o,containScroll:r,period:i=0})=>{const s=M(t);let a=-s.start||0,l=e-s.end,c=((t,e,n)=>{const o=[];let r,i=0;for(const s of t)r&&("auto"===n?r&&e+1>=s.end-r.start:n>i)?(r.end=Math.max(r.end,s.end),i++):(r={start:s.start,end:s.end},o.push(r),i=1);return o})((t=>{const e=t.map((t,e)=>e).sort((e,n)=>t[e].start-t[n].start||e-n),n=[];let o;for(const r of e){const e=t[r];o&&1>=e.start-o.start?o.end=Math.max(o.end,e.end):(o={start:e.start,end:e.end},n.push(o))}return n})(t),e,o).map((t,o)=>w(n,e,t.end-t.start,o)-t.start);i||(r?c=c.map(t=>x(t,l,a)):(a=Math.max(...c),l=Math.min(...c))),(i||"keepSnaps"!==r)&&(c=c.filter((t,e)=>!e||Math.abs(E(t,c[e-1],i))>1),i&&c.length>1&&1>=Math.abs(E(c[0],c[c.length-1],i))&&c.pop());const d=c.map(o=>({location:o,slide:S(t,o,e,n,i)})),u=(o,r,i)=>{const s=S(t,o.location,e,n,0,r,i);o.slide=s>-1?s:o.slide};if(!i&&d.length>1){const e=d[0],n=d[d.length-1];d[1].slide>e.slide||u(e,0,d[1].slide),n.slide>d[d.length-2].slide||u(n,d[d.length-2].slide+1,t.length)}return{snaps:d,min:l,max:i?c[0]:a}})({...e,align:t.align,slidesPerSnap:r.slidesPerSnap,containScroll:r.containScroll,period:l}));const p=u.snaps.map((t,e)=>e).filter(t=>!c||o>u.snaps[t].slide);return u.logical=p,u.map=u.snaps.map((t,e)=>c?Math.max(0,p.findIndex(e=>u.snaps[e].slide%o===t.slide%o)):e),u}(n,o,r,X.length,m);if(!a.snaps)return rt=a.copies,!0;st=a;const l=st.snaps.length;return lt=0>s?Math.min(l-1,Z?lt:Ct(lt)):Ct(mt.snapOfSlide(s)),ct=Math.min(ct,l-1),dt=s,gt||(at=T(st.snaps[lt].location,at,st.period)),!0}function _t(){st&&A(st.axis)!==it&&Nt()&&Bt()}function Bt(){if(rt>=0)return kt(rt),rt=-1,nt=[],void zt(!0);ht&&Qt();const t=K.current();null!==t&&ft.axis===st.axis&&!st.fit&&K.retarget(at)?(Wt(t,at),Rt(!0)):(K.stop(),Rt(gt)),((t,e)=>{t.forEach((n,o)=>{n.matches("a[href],button,input,select,textarea,[tabindex],[role]")&&!s.get(n)?.has("role")||(n.matches("div,span,section")&&l(n,"role","group"),l(n,"aria-roledescription","slide"),l(n,"aria-label",e.replace("%d",o+1).replace("%n",t.length)))})})(X,m.labels.slide),m.resize||zt(!1),Z?vt.emit("resize"):(Z=!0,vt.emit(tt?"reinit":"init"),tt=!0),et&&(et=!1,vt.emit("slideschanged"))}function Rt(e){const o="x"===st.axis;t(P,O.horizontal,o),t(P,O.vertical,!o),t(P,O.fit,st.fit),n(B,"touchAction",st.fit?"":o?"pan-y pinch-zoom":"pan-x pinch-zoom"),n(H,"willChange",st.fit?"":"translate"),e||Dt(st.fit?0:at),m.autoHeight&&n(B,"height",o?Math.max(...z(st.slides,at,st.view,0,st.period).map(t=>st.slides[t].cross))+"px":"");const r=Ft(),i=[...new Set(z(st.slides,at,st.view,m.inViewThreshold,st.period).map(Ot))].sort((t,e)=>t-e);U.forEach((e,n)=>t(e,O.selected,Ot(n)===r)),i.join()!==pt.join()&&(pt=i,U.forEach((e,n)=>t(e,O.inView,i.includes(Ot(n)))),vt.emit("slidesinview"))}function Ht(t){const e=devicePixelRatio||1;return Math.round(t*e)/e*st.sign}function jt(t){return t?"x"===st.axis?t+"px":"0 "+t+"px":""}function Dt(t){ft.axis!==st.axis&&(U.forEach(t=>n(t,"translate","")),ft={axis:st.axis,container:0,slides:[]}),ft.container=Ht(t),n(H,"translate",jt(ft.container)),Wt(t,t),(m.progress||m.offset)&&Gt(t,ft.slides)}function Gt(t,e){if(!0===m.progress)P.style.setProperty("--better-progress",k(t,st));else if(m.progress){const e=((t,e,n)=>{const o=t.length-1,r=t[0].location,i=n?r-((r-e)%n+n)%n:x(e,t[o].location,r);let s=0;for(;o>s&&t[s+1].location>=i;)s++;const a=t[s].location,l=o>s?t[s+1].location:r-n;return s+(a>l?(a-i)/(a-l):0)})(st.snaps,t,st.period),n=Math.floor(e);xt.progress=k(t,st),xt.snap=Pt(n)+e-n,m.progress(xt,mt)}m.offset&&U.forEach((n,o)=>{const r=st.slides[o],i=r.end-r.start,s=r.start+st.sign*(e[o]||0)+t,a=s-w(st.align,st.view,i,o),l=a/(i+st.gap);!0===m.offset?n.style.setProperty("--better-offset",l):(yt.node=n,yt.index=Ot(o),yt.offset=l,yt.distance=st.sign*a,yt.size=i,yt.visible=x((Math.min(s+i,st.view)-Math.max(s,0))/i,0,1)||0,m.offset(yt,mt))})}function Wt(t,e){const o=st.period?((t,e,n,o,r,i=0)=>{const s=i+(o-e-n)/2;return t.map(t=>Math.round((s-(t.start+t.end)/2)/r)||0)})(st.slides,t,e,st.area.size,st.period,st.area.start):[];U.forEach((t,e)=>{const r=o.length?Ht(o[e]*st.period):0;(ft.slides[e]||0)!==r&&(ft.slides[e]=r,n(t,"translate",jt(r)))})}function Vt(t){return jt(Ht(t))||"0px"}function qt(t,e,n){Kt(y(t+e,st.snaps.length,st.period),n,-1,e)}function Kt(t,e,n=-1,o=0){if(Et&&Tt(),vt.emit("interact"),dt=n,!st)return void(lt=t);const r=T(st.snaps[t].location,It(),st.period,o),i=Math.abs(t-lt);var s,a;Xt(t,r,e?0:(s=m.duration,(a=st.period?Math.min(i,st.snaps.length-i):i)>1?Math.min(2*s,s*(1+Math.log2(a))):s),_)}function Xt(t,e,n,o){const r=Qt(),i=Yt(t),s=!n||st.fit||.5>Math.abs(e-r);if(at=e,s)Rt();else{const t=vt.has("scroll")||!!st.period&&!((t,e,n,o,r)=>{const i=o+Math.abs(n-e);return t.every(t=>r>=i+t.end-t.start)})(st.slides,r,e,st.area.size,st.period);Rt(!0),t||Wt(r,e),K.run(r,e,n,o,t)}i&&vt.emit("select"),s&&$t()}function Yt(t){return t!==lt&&(ct=lt,lt=t,!0)}function Ut(){Yt(L(st.snaps,at,st.period))&&(Rt(!0),vt.emit("select"))}function Jt(t){Dt(t),vt.emit("scroll")}function $t(){ht&&(ht=!1,Ut()),st.period&&(at=b(at,st.period)),Rt(),vt.emit("settle")}function Qt(){const t=K.stop();return null!==t&&(at=t,Dt(t),ht&&Ut()),ht=!1,at}function Zt(){B.scrollLeft=B.scrollTop=0}})(e,i,Y.defaults,X)}return Y.defaults={},Y.get=q,Y.initAll=(t,e)=>{const n=[...document.querySelectorAll(t)];return(t=>{t.forEach(t=>N.set(t,t.getBoundingClientRect()))})(n.filter(t=>!q(t)&&W(t,Y.defaults,e).lazy)),n.map(t=>Y(t,e))},Y})();
|
|
1
|
+
var BetterCarousel=(()=>{"use strict";function t(t,e,n){e&&t.classList.contains(e)!==!!n&&t.classList.toggle(e,!!n)}function e(t,e,n){t.getAttribute(e)!==(n||null)&&(n?t.setAttribute(e,n):t.removeAttribute(e))}function n(t,e,n){t.style[e]!==n&&(t.style[e]=n)}function o(t){""===t.getAttribute("style")&&t.removeAttribute("style")}function r(t,e){const n=document.createElement(t);return e&&(n.className=e),n}function i(t,e){if("string"==typeof t){for(let n=e;n;n=n.parentElement){const e=n.querySelector(t);if(e)return e}return null}return!0===t?e:t||null}const s=new WeakMap,a=new WeakMap;function l(t,e,n){const o=s.get(t)||new Set;!o.has(e)&&t.hasAttribute(e)||(o.add(e),s.set(t,o),t.getAttribute(e)!==n&&t.setAttribute(e,n))}function c(t,e){if(e&&!t.classList.contains(e)){const n=a.get(t)||new Set;t.classList.add(e),n.add(e),a.set(t,n)}}const d=new WeakSet;let u=0;const p=new Set(["template","script","style"]);function f(t,e){return[...e?t.querySelectorAll(e):t.children].filter(t=>!d.has(t)&&!p.has(t.localName))}function h(t){for(const e of[t,...t.querySelectorAll("[id]")])e.removeAttribute("id")}function g(t,e){const n=e.cloneNode(!0);h(n),t.replaceChildren(...n.childNodes)}const m={delay:4e3,stopOnInteraction:!0,pauseOnHover:!1,pauseOnFocus:!0,stopOnLastSnap:!1,playOnInit:!0,instant:!1,timer:null},v={speed:120,direction:"next",startDelay:1e3,stopOnInteraction:!0,pauseOnHover:!1,pauseOnFocus:!0,playOnInit:!0};function b(t,e,n){return{...t,..."number"==typeof n?{[e]:n}:n}}function y(n,o,i,s){const{api:a,root:c,container:d,cls:u,emit:p}=n,f=n.options.labels,h=r("button",u.button+" "+u.playButton);let g=!1,m=null,v=!0;function b(){e(h,"aria-label",g?f.pause:f.play),t(c,u.playing,g),l(d,"aria-live",g?"off":"polite")}function y(){a.isFit()?h.remove():h.isConnected||c.append(h),v&&(v=!1,g?s.play():(n.playing?.[o]??(i.playOnInit&&!matchMedia("(prefers-reduced-motion: reduce)").matches))&&x.play())}h.type="button",h.setAttribute("aria-controls",d.id),h.addEventListener("click",()=>g?x.stop():x.play());const x={play(){g||(g=!0,m=((t,e)=>{const n=new Set,o=(t,e)=>{const o=n.size;n[e?"add":"delete"](t),!o!=!n.size&&s.pause(m.paused())},r=new IntersectionObserver(([t])=>o("view",!t.isIntersecting)),i=[[document,"visibilitychange",()=>o("tab",document.hidden)],[t,"pointerenter",t=>o("mouse",e.pauseOnHover&&"mouse"===t.pointerType)],[t,"pointerleave",()=>o("mouse",!1)],[t,"focusin",t=>o("focus",e.pauseOnFocus&&t.target.matches(":focus-visible"))],[t,"focusout",e=>o("focus",t.contains(e.relatedTarget)&&n.has("focus"))]];return r.observe(t),i.forEach(([t,e,n])=>t.addEventListener(e,n)),{paused:()=>n.size>0,remove(){r.disconnect(),i.forEach(([t,e,n])=>t.removeEventListener(e,n))}}})(c,i),b(),s.play(),p(o.toLowerCase()+":play"))},stop(){g&&(g=!1,m.remove(),b(),s.stop(),p(o.toLowerCase()+":stop"))},isPlaying(){return g},paused(){return!g||m.paused()},remove(){x.stop(),h.remove(),delete a[o]}};return[["init",y],["reinit",y],["resize",y],...s.events].forEach(([t,e])=>n.on(t,e)),b(),a[o]=x,x}function x(t,e,n,o,r,i=0){return t.map(t=>{const s=(i+n/2-e-(t.start+t.end)/2)/o,a=Math.round(s);return{k:a,offset:r>0?a+.5-s:s-a+.5}})}function w(t,e){return t-Math.ceil(t/e)*e}function M(t,e,n){return Math.min(n,Math.max(e,t))}function E(t,e,n){return n?(t%e+e)%e:M(t,0,e-1)}function S(t,e,n,o){return"function"==typeof t?t(e,n,o):"center"===t?(e-n)/2:"end"===t?e-n:0}function L(t){let e=1/0,n=-1/0,o=0;for(const r of t)r.hidden||(e=Math.min(e,r.start),n=Math.max(n,r.end),o=Math.max(o,r.end-r.start));return{start:e,end:n,size:n-e,max:o}}function T(t,e,n){const o=t-e;return n?o-Math.round(o/n)*n:o}function k(t,e,n,o,r,i=0,s=t.length){let a=-1,l=1/0;return t.forEach((t,c)=>{const d=Math.abs(T(t.start+e,S(o,n,t.end-t.start,c),r));c>=i&&s>c&&!t.hidden&&l-.5>d&&(l=d,a=c)}),a}function z(t,e,n){let o=0,r=1/0;return t.forEach((t,i)=>{const s=Math.abs(T(t.location,e,n));r>s&&(r=s,o=i)}),o}function A(t,e,n,o=0){return n?o>0?t+(Math.ceil((e-.5-t)/n)-1)*n:0>o?t+(Math.floor((e+.5-t)/n)+1)*n:e+T(t,e,n):t}function O(t,{min:e,max:n,period:o}){if(o){const e=(n-t)/o;return e-Math.floor(e)}return n>e?M((n-t)/(n-e),0,1):0}function P(t,e,n,o,r){const i=[];return t.forEach((t,s)=>{const a=t.end-t.start,l=r?T(t.start+e+a/2,n/2,r)+n/2-a/2:t.start+e,c=Math.min(l+a,n)-Math.max(l,0);t.hidden||0>=c||o*a-.5>c||i.push(s)}),i}function F(t){return"x"===t?document.documentElement.clientWidth:innerHeight}const C=new WeakMap,N=new WeakMap,I=new WeakMap;let _;function W(t,e){_||=new ResizeObserver(t=>{const e=[...new Set(t.filter(t=>{const{inlineSize:e,blockSize:n}=t.borderBoxSize[0],o=e+","+n,r=I.get(t.target)===o;return I.set(t.target,o),!r&&!C.get(t.target)?.skip(t)}).map(t=>C.get(t.target)))].filter(t=>t&&t.read());e.forEach(t=>t.write()),e.length&&(e.forEach(t=>N.get(t)?.forEach(t=>_.unobserve(t))),requestAnimationFrame(()=>e.forEach(t=>N.get(t)?.forEach(e=>C.get(e)===t&&_.observe(e)))))}),e&&N.set(e,t);for(const n of t)I.delete(n),e?(C.set(n,e),_.observe(n)):(C.delete(n),_.unobserve(n))}const B=new Map,H=new WeakMap,R=new WeakMap,D=[.25,1,.5,1],j=[.2,.6,.35,1];function G([t,e,n,o]){const r=(t,e,n)=>((1+3*t-3*e)*n+3*e-6*t)*n*n+3*t*n;return i=>{if(0>=i||i>=1)return i>0?1:0;let s=i;for(let a=0;6>a;a++){const a=r(t,n,s)-i,l=3*(1+3*t-3*n)*s*s+2*(3*n-6*t)*s+3*t;if(1e-5>Math.abs(a))return r(e,o,s);if(1e-6>Math.abs(l))break;s-=a/l}let a=0,l=1;for(s=i;l-a>1e-5;)r(t,n,s)<i?a=s:l=s,s=(a+l)/2;return r(e,o,s)}}const q={axis:"auto",align:"auto",dir:"auto",loop:!1,dragFree:!1,dragFriction:1,containScroll:"trimSnaps",slidesPerSnap:1,skipSnaps:!0,dragThreshold:10,duration:400,startSnap:0,lazy:!1,drag:!0,wheel:!0,keys:!0,resize:!0,slideChanges:!0,focus:!0,inViewThreshold:0,active:!0,breakpoints:{},container:null,slides:null,wrapper:!0,arrows:!0,dots:!0,dotsStyle:"zoom",labels:{carousel:"Carousel",slide:"%d of %n",prev:"Previous slide",next:"Next slide",dot:"Go to slide %d",play:"Start the slide show",pause:"Stop the slide show"},classes:null,state:"",sync:null,clones:"auto",autoplay:!1,autoScroll:!1,autoHeight:!1,progress:!1,offset:!1},V=t=>({root:t,viewport:t+"_viewport",container:t+"_container",fit:t+"_fit",horizontal:t+"_horizontal",vertical:t+"_vertical",autoHeight:t+"_auto_height",button:t+"_button",prevButton:t+"_prev",nextButton:t+"_next",dots:t+"_dots",dotsTrack:t+"_dots_track",dotsMarker:t+"_dots_marker",dotsAll:t+"_dots_all",dot:t+"_dot",playButton:t+"_play",clone:"clone",selected:"selected",inView:"",dragging:"dragging",playing:"playing",first:"first",prev:"prev",current:"current",next:"next",last:"last"}),X=["selected","inView","dragging","playing","first","prev","current","next","last"];function K(...t){const e={};for(const n of t)for(const t in n){const o=n[t],r=e[t];e[t]=o&&r&&"object"==typeof o&&"object"==typeof r&&o.constructor===Object&&r.constructor===Object?{...r,...o}:o}return e}function Y(t,...e){let n={};try{n=JSON.parse(t.dataset.carousel||"{}")}catch{}return K(q,...e,n)}const U=new WeakMap,J=t=>U.get(t),$="input,textarea,select,[contenteditable]",Q=new WeakSet,Z=[t=>{const{viewport:e,options:n}=t;if(!n.drag)return;let o,r,i,s=null,a=!1,l=[],c=0;const d=t=>["pointermove","pointerup","pointercancel"].forEach(e=>window[t](e,p));function u(e){a=!1;const n=t.geo();null!==s||e.button||!n||n.fit||Q.has(e)||e.target.closest($)||(Q.add(e),"mouse"===e.pointerType&&e.preventDefault(),s=e.pointerId,i={x:"x"===n.axis,sign:n.sign,scale:n.scale},o=[e.clientX,e.clientY],l=[],d("addEventListener"))}function p(a){if(a.pointerId!==s)return;if("pointermove"!==a.type)return l.length&&l.push([l[l.length-1][0],a.timeStamp]),f("pointerup"===a.type);const d=(a.clientX-o[0])/i.scale,u=(a.clientY-o[1])/i.scale,p=i.x?d*i.sign:u,h=i.x?u:d;if(!t.dragging()){if("mouse"!==a.pointerType&&Math.abs(h)>Math.abs(p))return f();if(n.dragThreshold>Math.abs(p))return;r=t.halt(),c=t.selected(),t.drag(!0),e.setPointerCapture(s)}const g=t.geo(),m=r+p,v=M(m,g.min,g.max);t.hold(g.period?m:v+(m-v)/4,!0),l.push([p,a.timeStamp]),l.length>10&&l.shift()}function f(e){if(d("removeEventListener"),s=null,!t.dragging())return;const o=t.geo(),i=t.location(),u=e?(t=>{const e=t[t.length-1],n=t.find(t=>100>=e[1]-t[1]),o=e[1]-n[1];return o>0?(e[0]-n[0])/o:0})(l):0,p=(({location:t,from:e,velocity:n,current:o,snaps:r,min:i,max:s,period:a,skipSnaps:l,dragFree:c,dragFriction:d=1})=>{const u=r.length;let p=t+325*n/d;if(a||(p=M(p,i,s)),"number"==typeof l&&l>0&&u-1+!a>l){const t=t=>A(r[E(o+t*l,u,a)].location,e,a,t);p=M(p,t(1),t(-1))}if(!0===c)return{location:p,snap:z(r,p,a)};if(c||l){const t=z(r,p,a);return{location:A(r[t].location,p,a),snap:t}}const f=t-e;let h=0;Math.abs(n)>.3?h=0>n?1:-1:Math.abs(f)>20&&(h=0>f?1:-1);const g=E(o+h,u,a),m=r[g].location;return{location:a?A(m,h?e:t,a,g===o?0:h):m,snap:g}})({location:i,from:r,velocity:u,current:c,snaps:o.snaps,min:o.min,max:o.max,period:o.period,skipSnaps:n.skipSnaps,dragFree:n.dragFree,dragFriction:n.dragFriction}),f=!0===n.dragFree?j:D;a=!0,t.drag(!1),t.move(p.snap,p.location,((t,e,n,o)=>Math.sign(t)!==Math.sign(e)||.05>Math.abs(e)?o:M(Math.abs(t)*n[1]/n[0]/Math.abs(e),200,1200))(p.location-i,u,f,n.duration),f)}function h(t){a&&(a=!1,t.preventDefault(),t.stopPropagation())}const g=t=>t.preventDefault(),m=e=>t.dragging()&&e.preventDefault();return e.addEventListener("pointerdown",u),e.addEventListener("click",h,!0),e.addEventListener("dragstart",g),e.addEventListener("selectstart",m),{remove(){d("removeEventListener"),e.removeEventListener("pointerdown",u),e.removeEventListener("click",h,!0),e.removeEventListener("dragstart",g),e.removeEventListener("selectstart",m)}}},t=>{const{viewport:e,options:n}=t,o=!0===n.dragFree;if(!n.wheel)return;let r=0,i=0,s=!1,a=!1,l=0,c=0,d=0;function u(n){const u=t.geo(),f="x"===u.axis&&Math.abs(n.deltaX)>Math.abs(n.deltaY),h=f?n.deltaX*u.sign:n.deltaY;if(n.ctrlKey||!h||t.dragging())return;const g=n.timeStamp,m=200>g-r,v=Math.abs(h),b=m&&i>=v;if(i=v,m||(s=!1),m&&a||((t,e,n,o)=>{const[r,i,s,a]="x"===n?["scrollWidth","clientWidth","scrollLeft","overflowX"]:["scrollHeight","clientHeight","scrollTop","overflowY"];for(;t&&t!==e;t=t.parentElement)if(t[r]>t[i]&&/auto|scroll/.test(getComputedStyle(t)[a])){const e=Math.abs(t[s]);if(o>0?t[r]-1>e+t[i]:e>0)return!0}return!1})(n.target,e,f?"x":"y",f?n.deltaX:h))return a=!0,void(r=g);a=!1;const y=t.location(),x=h*(1===n.deltaMode?40:n.deltaMode?u.view:1);let w=y-x;u.period||(w=M(w,u.min,u.max)),r=g,.5>Math.abs(w-y)?s&&b&&n.preventDefault():(n.preventDefault(),t.emit("interact"),l||(c=t.selected()),s=!0,d=x>0?1:-1,t.move(z(u.snaps,w,u.period),w,180,D),clearTimeout(l),o||(l=setTimeout(p,150)))}function p(){l=0;const e=t.geo(),n=t.current(),o=z(e.snaps,n,e.period),r=Math.abs(A(e.snaps[o].location,n,e.period)-n)>10;t.step(o,o===c&&r?d:0)}function f(){const o=t.geo();e[o.fit||"y"!==o.axis&&"both"!==n.wheel?"removeEventListener":"addEventListener"]("wheel",u,{passive:!1})}return["init","reinit","resize"].forEach(e=>t.on(e,f)),{remove(){e.removeEventListener("wheel",u),clearTimeout(l)}}},t=>{const{api:e,root:n,options:o}=t;if(o.keys)return n.addEventListener("keydown",r),{remove(){n.removeEventListener("keydown",r)}};function r(n){const o=t.geo(),{key:r,target:i}=n,s=o&&!o.fit&&("y"===o.axis?{ArrowUp:-1,ArrowDown:1}:{ArrowLeft:-o.sign,ArrowRight:o.sign})[r],a=s>0?"Next":"Prev";s&&!(n.altKey||n.ctrlKey||n.metaKey||n.shiftKey||i.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(i.tagName))&&e["canGoTo"+a]()&&(n.preventDefault(),e["goTo"+a]())}},t=>{const{api:e,container:n,options:o}=t;let r=-1e4;function i(t){t.target.closest($)||(r=t.timeStamp)}function s(n){const i=t.geo(),s=e.slideNodes().findIndex(t=>t.contains(n.target));!i||0>s||600>n.timeStamp-r||(o.focus&&!P(i.slides,t.location(),i.view,1,i.period).map(t=>t%i.count).includes(s)&&e.goToSlide(s),t.emit("slidefocus"))}return n.addEventListener("pointerdown",i),n.addEventListener("focusin",s),{remove(){n.removeEventListener("pointerdown",i),n.removeEventListener("focusin",s)}}},n=>{const{api:o,root:s,cls:a,options:l}=n,c=l.labels,d=i(l.arrows,s),u=i(l.dots,s),p=[],f=[],h="all"!==l.dotsStyle,g=u&&r("div",h?a.dots:a.dots+" "+a.dotsAll),m=g&&r("div",a.dotsTrack);let v=new Map;if(d||u)return g&&(m.append(r("span",a.dotsMarker)),g.append(m),u.append(g)),d&&[["prev","goToPrev"],["next","goToNext"]].forEach(([t,e])=>{const i=r("button",a.button+" "+a[t+"Button"]);i.type="button",i.setAttribute("aria-label",c[t]),i.setAttribute("aria-controls",n.container.id),i.addEventListener("click",()=>o[e]()),p.push(i)}),["init","reinit","resize","select","slideschanged"].forEach(t=>n.on(t,b)),{remove(){p.forEach(t=>t.remove()),g?.remove()}};function b(){const i=o.isFit(),s=i?0:o.snapProgress().length,l=o.selectedSnap();if(p.forEach((t,e)=>{if(i)t.remove();else{t.isConnected||(g?.parentNode===d?g.before(t):d.append(t));const n=!(e?o.canGoToNext():o.canGoToPrev());t.disabled!==n&&(t.disabled=n)}}),!g)return;if(2>s)return void g.remove();for(;f.length>s;)f.pop().remove(),v.delete(f.length);for(;s>f.length;){const t=r("button",a.dot),e=f.length;t.type="button",t.setAttribute("aria-label",c.dot.replace("%d",e+1)),t.setAttribute("aria-controls",n.container.id),h&&(t.tabIndex=-1),t.addEventListener("click",()=>o.goToSnap(e)),f.push(t),m.append(t)}g.isConnected||u.append(g);const b=new Map;["first","prev","current","next","last"].forEach((t,e)=>{f[l+e-2]&&b.set(l+e-2,a[t])}),v.forEach((n,o)=>{b.get(o)!==n&&(t(f[o],n,!1),e(f[o],"aria-current",!1),f[o].tabIndex=h?-1:0)}),b.forEach((n,o)=>{t(f[o],n,!0),e(f[o],"aria-current",o===l&&"true"),f[o].tabIndex=0}),v=b,h&&y("--better-shift",2-(Math.max(0,l-2)+Math.min(s-1,l+2))/2),y("--better-dot",l)}function y(t,e){g.style.getPropertyValue(t)!==e+""&&g.style.setProperty(t,e)}},t=>{if(!t.options.autoplay)return;const e=t.api,n=b(m,"delay",t.options.autoplay);let o=0,r=null,i=!1;function s(){clearTimeout(o),r?.(),r=null}function a(){if(s(),!c.paused()&&!e.isFit()){const t=e.slideNodes()[e.selectedSlide()]?.dataset.delay||n.delay,i=+(Array.isArray(t)?t[e.selectedSnap()]:t);o=setTimeout(l,i),r=n.timer?.(i,e)}}function l(){s(),i=!0,e.canGoToNext()?e.goToNext(n.instant):n.stopOnLastSnap?c.stop():e.goToSnap(0,n.instant),i=!1}const c=y(t,"autoplay",n,{play:a,stop:s,pause:a,events:[["settle",a],["interact",()=>{i||(s(),n.stopOnInteraction&&c.stop())}]]});return c.reset=a,c},t=>{if(!t.options.autoScroll)return;const e=b(v,"speed",t.options.autoScroll);let n=0,o=!1;const r=y(t,"autoScroll",e,{play:i,stop(){i(-1),t.halt()},pause(e){e?t.halt():n||s()},events:[["settle",()=>r.isPlaying()&&i()],["resize",()=>r.isPlaying()&&!n&&s()],["interact",()=>{r.isPlaying()&&(i(-1),e.stopOnInteraction&&r.stop())}]]});function i(t){clearTimeout(n),n=t?0:setTimeout(s,e.startDelay)}function s(){n=0;const i=t.geo();!i||i.fit||o||t.dragging()||r.paused()||t.scroll("prev"===e.direction?-1:1,e.speed/1e3)}const a=t=>["pointerup","pointercancel"].forEach(e=>window[t](e,c));function l(e){e.button||!r.isPlaying()||o||(o=!0,i(-1),t.halt(),a("addEventListener"))}function c(){o=!1,a("removeEventListener"),r.isPlaying()&&!t.dragging()&&i()}const{viewport:d}=t,u=r.remove;return d.addEventListener("pointerdown",l),r.remove=()=>{d.removeEventListener("pointerdown",l),a("removeEventListener"),u()},r},t=>{const{api:e,container:n}=t,o=t.options.sync;let r=null;if(o)return t.on("init",l),t.on("reinit",l),n.addEventListener("click",a),{remove(){r?.off("select",s),n.removeEventListener("click",a)}};function s(n){const o=r.selectedSlide();t.follow(o),e.goToSlide(o,!0===n)}function a(n){const o=t.nodes().findIndex(t=>t.contains(n.target));r&&o>-1&&r.goToSlide(o%e.slideNodes().length)}function l(){r||(r=o.goToSnap?o:J("string"==typeof o?i(o,t.root):o),r&&(r.on("select",s),s(!0)))}}];function tt(e,i={}){return((e,i,p,m)=>{const v=U.get(e);if(v)return v;let b,y,C,N,I,_,j,q,J=[],$=[],Q=[],Z=[],tt=[],et=null,nt=!1,ot=!1,rt=!1,it=[],st=0,at=-1,lt=0,ct=null,dt=0,ut=0,pt=0,ft=-1,ht=-1,gt=[],mt={axis:"",container:0,slides:[]},vt=!1,bt=!1;const yt={goToSnap:(t,e)=>Jt(_t(t),e),goToNext:t=>ct?yt.canGoToNext()&&Ut(ut,1,t):Jt(ut+1,t),goToPrev:t=>ct?yt.canGoToPrev()&&Ut(ut,-1,t):Jt(ut-1,t),goToSlide:(t,e)=>Jt(_t(yt.snapOfSlide(t)),e,t),canGoToNext:()=>!(!ct||ct.fit||!ct.period&&ut>=ct.snaps.length-1),canGoToPrev:()=>!(!ct||ct.fit||!ct.period&&0>=ut),selectedSnap:()=>It(ut),previousSnap:()=>It(pt),selectedSlide:Wt,snapOfSlide:t=>ct?It(((t,e,n,o,r,i)=>{const s=t.findIndex(t=>t.slide===n),a=e[n];return s>-1||!a?Math.max(s,0):z(t,S(r,o,a.end-a.start,n)-a.start,i)})(ct.snaps,ct.slides,t,ct.view,ct.align,ct.period)):t,snapProgress:()=>ct?ct.logical.map(t=>O(ct.snaps[t].location,ct)):[],progress:()=>ct?O(Bt(),ct):0,slideNodes:()=>J.slice(),slidesInView:()=>gt.slice(),rootNode:()=>C,viewportNode:()=>N,containerNode:()=>I,isFit:()=>!ct||ct.fit,options:()=>b,reinit:At,destroy(){zt(!1),xt.emit("destroy")}},xt=(t=>{const e={},n={},o=(t,e,n)=>(t[e]||=new Set).add(n);return{on:(n,r)=>(o(e,n,r),t),off:(n,o)=>(e[n]?.delete(o),t),listen(t,e){return o(n,t,e)},clear(){return Object.values(n).forEach(t=>t.clear())},emit(o){n[o]?.forEach(e=>e(t,o)),e[o]?.forEach(e=>e(t,o))},has(t){return!!e[t]?.size}}})(yt),wt={read:Ht,write:Dt,skip({target:t,contentRect:{width:e}}){if(t!==N)return!1;const n=e===st;return st=e,n&&b.autoHeight&&"x"===ct?.axis}},Mt={progress:0,snap:0},Et={node:null,index:0,offset:0,distance:0,size:0,visible:0},St={api:yt,emit:xt.emit,on:xt.listen,geo:()=>ct,nodes:()=>Q,selected:()=>ut,dragging:()=>vt,location:()=>bt?Bt():dt,current:Bt,hold(t,e){dt=t,(e?te:Vt)(t),Zt()},halt:ne,step:Ut,scroll(t,e){const n=ne(),o=t>0?ct.min:ct.max;ct.period?(bt=!0,dt=w(n,ct.period),q.loop(dt,t,ct.period/e,ct,Q)):Math.abs(o-n)>1&&(bt=!0,dt=o,q.run(n,o,Math.abs(o-n)/e,[0,0,1,1],xt.has("scroll")))},move(t,e,n,o){ft=-1,$t(t,e,n,o)},drag(e){vt=e,t(C,y.dragging,e),e?(xt.emit("interact"),xt.emit("dragstart")):xt.emit("dragend")},follow(t){ht=t}};yt.on=xt.on,yt.off=xt.off;let Lt=Y(e,p,i),Tt=Lt.lazy?((t,e,n)=>{const o=!0===e?innerHeight:e,r=R.get(t)||t.getBoundingClientRect(),i=!0===e?"100%":e+"px";if(R.delete(t),r.height&&r.bottom>=-o&&r.top<=innerHeight+o)return null;let s=B.get(i);return s||(s=new IntersectionObserver(t=>t.forEach(t=>t.isIntersecting&&H.get(t.target)?.()),{rootMargin:i}),B.set(i,s)),H.set(t,n),s.observe(t),()=>{s.unobserve(t),H.delete(t)}})(e,Lt.lazy,At):null;return Tt?U.set(e,yt):kt(),yt;function kt(){if(et=((t,e)=>{const n=Object.entries(t.breakpoints||{}).map(([t,e])=>[matchMedia(t),e]);return n.forEach(([t])=>t.addEventListener("change",e)),{options:K(t,...n.filter(([t])=>t.matches).map(([,t])=>t)),remove(){return n.forEach(([t])=>t.removeEventListener("change",e))}}})(Lt||Y(e,p,i),()=>At()),Lt=null,b=et.options,b.active){y=((t,e)=>{const n="string"==typeof t?V(t):{...V(t?.prefix||"better"),...t};for(const t of X)n[t]&&(n[t]=e+n[t]);return n})(b.classes,b.state),({root:C,viewport:N,container:I}=((t,e,n)=>{let o=e.container?t.querySelector(e.container):t;o.classList.contains(n.viewport)&&(o=o.firstElementChild);let i=o.parentElement,s=i.parentElement;return d.has(i)||i.classList.contains(n.viewport)||!e.wrapper||(s=r("div"),i=r("div"),d.add(s).add(i),o.before(s),s.append(i),i.append(o)),c(s,n.root),c(i,n.viewport),c(o,n.container),l(s,"role","region"),l(s,"aria-roledescription","carousel"),s.hasAttribute("aria-labelledby")||l(s,"aria-label",e.labels.carousel),l(o,"id",o.id||"carousel-"+ ++u),l(o,"aria-live","polite"),{root:s,viewport:i,container:o}})(e,b,y));for(const t of[C,N,I])U.set(t,yt);J=f(I,b.slides),Q=J,ut=b.startSnap,Ft(!0),Object.assign(St,{root:C,viewport:N,container:I,cls:y,options:b}),Z=m.map(t=>t(St)).filter(Boolean),q=((t,e,n,o,r)=>{let i=null;const s=()=>i.animations?i.animations[0].currentTime||0:performance.now()-i.start,a=()=>i&&i.from+(i.to-i.from)*i.ease(s()/i.duration);function l(){if(!i.animations&&s()>=i.duration)return c();i.raf=requestAnimationFrame(l),(i.animations?r:n)(a())}function c(){const t=i.to;d(),n(t),o()}function d(){const t=a();return i&&(i.animations?.forEach(t=>t.cancel()),cancelAnimationFrame(i.raf),i=null),t}function u(n){const o=t.animate([{translate:e(i.from)},{translate:e(i.to)}],{duration:i.duration,easing:"cubic-bezier("+i.curve+")",fill:"forwards"});o.currentTime=n,o.onfinish=c,i.animations=[o]}function p(n,o){if(d(),i=n,n.list){const r={duration:n.duration,iterations:1/0},i=document.timeline.currentTime,{from:s,to:a,length:l,direction:c}=n;n.animations=[t.animate([{translate:e(s)},{translate:e(a)}],r),...o.map((t,o)=>{const{k:i,offset:s}=n.list[o],a=e(i*l),d=e((i+c)*l);return t.animate([{translate:a},{translate:a,offset:s},{translate:d,offset:s},{translate:d}],r)})],n.animations.forEach(t=>t.startTime=i)}else n.script?n.start=performance.now():u(0);(n.script||r)&&(n.raf=requestAnimationFrame(l))}return{run(t,e,n,o,r){return p({from:t,to:e,duration:n,curve:o,script:r,ease:G(o)})},loop(t,e,n,o,r){return p({from:t,to:t-e*o.period,duration:n,direction:e,length:o.period,list:x(o.slides,t,o.area.size,o.period,e,o.area.start),ease(t){return t%1}},r)},retarget(t){if(!i||i.list)return!1;if(t!==i.to&&(i.to=t,i.animations)){const t=s();i.animations[0].cancel(),u(t)}return!0},stop:d,current:a,shifts(t){if(!i?.list)return null;const e=s()/i.duration%1;return i.list.map(({k:n,offset:o})=>t*(o>e?n:n+i.direction)*i.length)}}})(I,Yt,te,ee,(b.progress||b.offset)&&(t=>Xt(t,q.shifts(ct.sign)||mt.slides))),b.autoHeight&&c(C,y.autoHeight),N.addEventListener("scroll",oe),b.loop&&"fill"===b.clones&&addEventListener("resize",Rt),b.slideChanges&&(_=new MutationObserver(Ct),_.observe(I,{childList:!0}))}}function zt(r){if(Tt?.(),Tt=null,U.delete(e),Ft(!1),_?.disconnect(),et?.remove(),et=null,y){q.stop(),Z.forEach(t=>t.remove()),xt.clear(),Z=[],ht=-1,vt=bt=!1,Ot(0),N.removeEventListener("scroll",oe),removeEventListener("resize",Rt);for(const e of Q)n(e,"translate",""),e.style.removeProperty("--better-offset"),t(e,y.selected,!1),t(e,y.inView,!1),o(e);n(I,"translate",""),n(I,"willChange",""),n(N,"touchAction",""),n(N,"height",""),C.style.removeProperty("--better-progress");for(const e of["horizontal","vertical","fit","dragging"])t(C,y[e],!1);for(const t of[C,N,I])o(t),U.delete(t);((t,e,n,o,r)=>{for(const r of[t,e,n,...o])s.get(r)?.forEach(t=>r.removeAttribute(t)),a.get(r)?.forEach(t=>r.classList.remove(t)),s.delete(r),a.delete(r),""===r.getAttribute("class")&&r.removeAttribute("class");!r&&d.has(t)&&(t.before(n),t.remove())})(C,N,I,J,r),y=ct=null,nt=!1,dt=0,gt=[],it=[],st=0,mt={axis:"",container:0,slides:[]}}}function At(t){t&&(i=K(i,t),Lt=null);const e=ct?Wt():ft;St.playing=t?null:{autoplay:yt.autoplay?.isPlaying(),autoScroll:yt.autoScroll?.isPlaying()},zt(!0),kt(),ft=e}function Ot(e){$.length!==e*J.length&&($.forEach(t=>t.remove()),$=((e,n,r)=>{const i=[];for(let s=0;n>s;s++)for(const n of e){const e=n.cloneNode(!0);h(e),e.setAttribute("aria-hidden","true"),e.inert=!0,e.style.translate="",t(e,r,!0),o(e),d.add(e),i.push(e)}return i})(J,e,y.clone),I.append(...$),Q=J.concat($),mt.slides.length=J.length,_?.takeRecords(),j?.disconnect(),$.length&&(j||=new MutationObserver(Pt),J.forEach(t=>j.observe(t,{childList:!0,characterData:!0,subtree:!0,attributeFilter:["class","src","srcset","href","value"]}))))}function Pt(t){new Set(t.filter(t=>"attributes"!==t.type||!J.includes(t.target)).map(({target:t})=>J.find(e=>e.contains(t)))).forEach(t=>{for(let e=J.indexOf(t);t&&$.length>e;e+=J.length)g($[e],t)})}function Ft(t){W(tt),tt=t?[N,I,...Q]:[],W(tt,wt)}function Ct(){const t=nt?Wt():-1,e=J[t];if(J=f(I,b.slides),t>-1){const n=J.indexOf(e);ft=n>-1?n:Math.min(t,J.length-1)}Ot(0),Q=J,rt=!0,Ft(!0)}function Nt(t){return t%J.length}function It(t){return ct?ct.map[t]??0:t}function _t(t){return ct?((t,e,n)=>{let o=-1,r=1/0;return t.snaps.forEach((i,s)=>{const a=Math.abs(T(i.location,n,t.period));t.map[s]===e&&r>a&&(r=a,o=s)}),0>o?M(e,0,t.snaps.length-1):o})(ct,t,Bt()):t}function Wt(){return ht>-1?ht:ct?0>ft||yt.snapOfSlide(ft)!==It(ut)?Nt(ct.snaps[ut].slide):ft:Math.max(ft,0)}function Bt(){return q.current()??dt}function Ht(){const t=ct?.sign||1,e=q.current(),n=((t,e)=>{const n=getComputedStyle(t),o=n.display,r=n.justifyContent;let i=e.axis;"auto"===i&&(i="x",o.includes("grid")?i=n.gridAutoFlow.startsWith("column")?"x":"y":o.includes("flex")&&n.flexDirection.startsWith("column")&&"nowrap"===n.flexWrap&&(i="y"));let s=e.align;"auto"===s&&(s="center"===r?"center":"flex-end"===r||"end"===r||"x"===i&&"right"===r?"end":"start");const a="x"===i&&("auto"===e.dir?"rtl"===n.direction:"rtl"===e.dir);return{axis:i,align:s,rtl:a,sign:a?-1:1,gap:parseFloat("x"===i?n.columnGap:n.rowGap)||0}})(I,b),o=((t,e,n,o)=>{const r=t.getBoundingClientRect(),i="x"===n.axis,s=n.sign,a=o.axis===n.axis,l=a?o.container:0,c=t.offsetWidth,d=t.offsetHeight,u=c&&d&&(Math.abs(r.width-c)>=1||Math.abs(r.height-d)>=1),p=u?Math.abs(c-d)>1?(c*r.width-d*r.height)/(c*c-d*d):r.width/c:1,f=u?i?c:d:i?r.width:r.height,h=getComputedStyle(t),[g,m]=i?n.rtl?["Right","Left"]:["Left","Right"]:["Top","Bottom"],v={start:parseFloat(h["padding"+g])||0,end:parseFloat(h["padding"+m])||0},b=e.map((t,e)=>{const c=t.getBoundingClientRect(),d=(i?n.rtl?r.right-c.right:c.left-r.left:c.top-r.top)/p-v.start-s*(l+(a&&o.slides[e]||0));return{start:d,end:d+(i?c.width:c.height)/p,cross:(i?c.height:c.width)/p,hidden:!c.width&&!c.height}});let y=b.find(t=>!t.hidden)?.start||0;for(const t of b)t.hidden?t.start=t.end=y:y=t.end;let x=Math.max(0,b.findIndex(t=>!t.hidden)),w=x;b.forEach((t,e)=>{t.hidden||(b[x].start>t.start&&(x=e),t.end>b[w].end&&(w=e))});let M=n.gap;if(b.length){const t=i?n.rtl?["Right","Left"]:["Left","Right"]:["Top","Bottom"];M+=(parseFloat(getComputedStyle(e[x])["margin"+t[0]])||0)+(parseFloat(getComputedStyle(e[w])["margin"+t[1]])||0)}return{view:f-v.start-v.end,slides:b,gap:M,scale:p,pad:v}})(N,Q,n,null===e?mt:{axis:mt.axis,container:t*e,slides:q.shifts(t)||mt.slides});lt=b.loop&&"fill"===b.clones?F(n.axis):0;const r=((t,e,n,o,r)=>{if(!r)return{start:-o.start,size:o.start+n+o.end};const i=t.getBoundingClientRect(),s=Math.max(0,Math.round("x"===e.axis?e.rtl?r-i.right:i.left:i.top))+o.start;return{start:-s,size:s+Math.max(n+o.end,Math.round(r-s))}})(N,n,o.view,o.pad,lt),i=[n.axis,n.rtl,"string"==typeof n.align&&n.align,o.view,o.gap,r.start,r.size,...o.slides.flatMap(t=>[t.start,t.end,t.cross])];if(nt&&i.length===it.length&&i.every((t,e)=>t===it[e]||.5>Math.abs(t-it[e])))return!1;it=i;const s=nt&&!rt?Wt():ft,a=function(t,e,n,o,r){const i=L(e.slides.slice(0,o)),s=!(i.size>e.view+1||r.autoScroll&&r.loop),a=r.loop&&!s&&o,l=a?L(e.slides).size+e.gap:0,c=a&&r.clones&&(d=i.size+e.gap)>0?Math.max(0,Math.ceil((n.size+i.max)/d)-1):0;var d;if(c*o!==e.slides.length-o)return{copies:c};const u={...t,...e,area:n,fit:s,count:o,period:l,min:0,max:0};s?u.snaps=[{location:0,slide:Math.max(0,k(e.slides,0,e.view,t.align))}]:Object.assign(u,(({slides:t,view:e,align:n,slidesPerSnap:o,containScroll:r,period:i=0})=>{const s=L(t);let a=-s.start||0,l=e-s.end,c=((t,e,n)=>{const o=[];let r,i=0;for(const s of t)r&&("auto"===n?r&&e+1>=s.end-r.start:n>i)?(r.end=Math.max(r.end,s.end),i++):(r={start:s.start,end:s.end},o.push(r),i=1);return o})((t=>{const e=t.map((t,e)=>e).filter(e=>!t[e].hidden).sort((e,n)=>t[e].start-t[n].start||e-n),n=[];let o;for(const r of e){const e=t[r];o&&1>=e.start-o.start?o.end=Math.max(o.end,e.end):(o={start:e.start,end:e.end},n.push(o))}return n})(t),e,o).map((t,o)=>S(n,e,t.end-t.start,o)-t.start);i||(r?c=c.map(t=>M(t,l,a)):(a=Math.max(...c),l=Math.min(...c))),(i||"keepSnaps"!==r)&&(c=c.filter((t,e)=>!e||Math.abs(T(t,c[e-1],i))>1),i&&c.length>1&&1>=Math.abs(T(c[0],c[c.length-1],i))&&c.pop());const d=c.map(o=>({location:o,slide:k(t,o,e,n,i)})),u=(o,r,i)=>{const s=k(t,o.location,e,n,0,r,i);o.slide=s>-1?s:o.slide};if(!i&&d.length>1){const e=d[0],n=d[d.length-1];d[1].slide>e.slide||u(e,0,d[1].slide),n.slide>d[d.length-2].slide||u(n,d[d.length-2].slide+1,t.length)}return{snaps:d,min:l,max:i?c[0]:a}})({...e,align:t.align,slidesPerSnap:r.slidesPerSnap,containScroll:r.containScroll,period:l}));const p=u.snaps.map((t,e)=>e).filter(t=>!c||o>u.snaps[t].slide);return u.logical=p,u.map=u.snaps.map((t,e)=>c?Math.max(0,p.findIndex(e=>u.snaps[e].slide%o===t.slide%o)):e),u}(n,o,r,J.length,b);if(!a.snaps)return at=a.copies,!0;ct=a;const l=ct.snaps.length,c=ct.logical.length;return ut=0>s?Math.min(l-1,nt?ut:_t(ct.period?(ut%c+c)%c:Math.max(ut,0))):_t(yt.snapOfSlide(s)),pt=Math.min(pt,l-1),ft=s,vt||(dt=A(ct.snaps[ut].location,dt,ct.period)),!0}function Rt(){ct&&F(ct.axis)!==lt&&Ht()&&Dt()}function Dt(){if(at>=0)return Ot(at),at=-1,it=[],void Ft(!0);bt&&ne();const t=q.current();null!==t&&mt.axis===ct.axis&&!ct.fit&&q.retarget(dt)?(Kt(t,dt),jt(!0)):(q.stop(),jt(vt)),((t,e)=>{t.forEach((n,o)=>{n.matches("a[href],button,input,select,textarea,[tabindex],[role]")&&!s.get(n)?.has("role")||(n.matches("div,span,section")&&l(n,"role","group"),l(n,"aria-roledescription","slide"),l(n,"aria-label",e.replace("%d",o+1).replace("%n",t.length)))})})(J,b.labels.slide),b.resize||Ft(!1),nt?xt.emit("resize"):(nt=!0,xt.emit(ot?"reinit":"init"),ot=!0),rt&&(rt=!1,xt.emit("slideschanged"))}function jt(e){const o="x"===ct.axis;t(C,y.horizontal,o),t(C,y.vertical,!o),t(C,y.fit,ct.fit),n(N,"touchAction",ct.fit?"":o?"pan-y pinch-zoom":"pan-x pinch-zoom"),n(I,"willChange",ct.fit?"":"translate"),e||Vt(ct.fit?0:dt),b.autoHeight&&n(N,"height",o?Math.max(...P(ct.slides,dt,ct.view,0,ct.period).map(t=>ct.slides[t].cross))+"px":"");const r=Wt(),i=[...new Set(P(ct.slides,dt,ct.view,b.inViewThreshold,ct.period).map(Nt))].sort((t,e)=>t-e);Q.forEach((e,n)=>t(e,y.selected,Nt(n)===r)),i.join()!==gt.join()&&(gt=i,Q.forEach((e,n)=>t(e,y.inView,i.includes(Nt(n)))),xt.emit("slidesinview"))}function Gt(t){const e=devicePixelRatio||1;return Math.round(t*e)/e*ct.sign}function qt(t){return t?"x"===ct.axis?t+"px":"0 "+t+"px":""}function Vt(t){mt.axis!==ct.axis&&(Q.forEach(t=>n(t,"translate","")),mt={axis:ct.axis,container:0,slides:[]}),mt.container=Gt(t),n(I,"translate",qt(mt.container)),Kt(t,t),(b.progress||b.offset)&&Xt(t,mt.slides)}function Xt(t,e){if(!0===b.progress)C.style.setProperty("--better-progress",O(t,ct));else if(b.progress){const e=((t,e,n)=>{const o=t.length-1,r=t[0].location,i=n?r-((r-e)%n+n)%n:M(e,t[o].location,r);let s=0;for(;o>s&&t[s+1].location>=i;)s++;const a=t[s].location,l=o>s?t[s+1].location:r-n;return s+(a>l?(a-i)/(a-l):0)})(ct.snaps,t,ct.period),n=Math.floor(e);Mt.progress=O(t,ct),Mt.snap=It(n)+e-n,b.progress(Mt,yt)}b.offset&&Q.forEach((n,o)=>{const r=ct.slides[o],i=r.end-r.start,s=r.start+ct.sign*(e[o]||0)+t,a=s-S(ct.align,ct.view,i,o),l=a/(i+ct.gap);!0===b.offset?n.style.setProperty("--better-offset",l):(Et.node=n,Et.index=Nt(o),Et.offset=l,Et.distance=ct.sign*a,Et.size=i,Et.visible=M((Math.min(s+i,ct.view)-Math.max(s,0))/i,0,1)||0,b.offset(Et,yt))})}function Kt(t,e){const o=ct.period?((t,e,n,o,r,i=0)=>{const s=i+(o-e-n)/2;return t.map(t=>Math.round((s-(t.start+t.end)/2)/r)||0)})(ct.slides,t,e,ct.area.size,ct.period,ct.area.start):[];Q.forEach((t,e)=>{const r=o.length?Gt(o[e]*ct.period):0;(mt.slides[e]||0)!==r&&(mt.slides[e]=r,n(t,"translate",qt(r)))})}function Yt(t){return qt(Gt(t))||"0px"}function Ut(t,e,n){Jt(E(t+e,ct.snaps.length,ct.period),n,-1,e)}function Jt(t,e,n=-1,o=0){if(Tt&&At(),xt.emit("interact"),ft=n,!ct)return void(ut=t);const r=A(ct.snaps[t].location,Bt(),ct.period,o),i=Math.abs(t-ut);var s,a;$t(t,r,e?0:(s=b.duration,(a=ct.period?Math.min(i,ct.snaps.length-i):i)>1?Math.min(2*s,s*(1+Math.log2(a))):s),D)}function $t(t,e,n,o){const r=ne(),i=Qt(t),s=!n||ct.fit||.5>Math.abs(e-r);if(dt=e,s)jt();else{const t=xt.has("scroll")||!!ct.period&&!((t,e,n,o,r)=>{const i=o+Math.abs(n-e);return t.every(t=>r>=i+t.end-t.start)})(ct.slides,r,e,ct.area.size,ct.period);jt(!0),t||Kt(r,e),q.run(r,e,n,o,t)}i&&xt.emit("select"),s&&ee()}function Qt(t){return t!==ut&&(pt=ut,ut=t,!0)}function Zt(){Qt(z(ct.snaps,dt,ct.period))&&(jt(!0),xt.emit("select"))}function te(t){Vt(t),xt.emit("scroll")}function ee(){bt&&(bt=!1,Zt()),ct.period&&(dt=w(dt,ct.period)),jt(),xt.emit("settle")}function ne(){const t=q.stop();return null!==t&&(dt=t,Vt(t),bt&&Zt()),bt=!1,dt}function oe(){N.scrollLeft=N.scrollTop=0}})(e,i,tt.defaults,Z)}return tt.defaults={},tt.get=J,tt.initAll=(t,e)=>{const n=[...document.querySelectorAll(t)];return(t=>{t.forEach(t=>R.set(t,t.getBoundingClientRect()))})(n.filter(t=>!J(t)&&Y(t,tt.defaults,e).lazy)),n.map(t=>tt(t,e))},tt})();
|
package/package.json
CHANGED
package/src/scripts/autoplay.js
CHANGED
|
@@ -102,10 +102,13 @@ function controller(context, key, options, hooks) {
|
|
|
102
102
|
} else if (!button.isConnected) {
|
|
103
103
|
root.append(button);
|
|
104
104
|
}
|
|
105
|
-
// Start at the first init, unless the user prefers less motion
|
|
105
|
+
// Start at the first init, unless the user prefers less motion. After a breakpoint change, the play state stays.
|
|
106
|
+
// A play() before the first init starts now, because the carousel had no size before.
|
|
106
107
|
if (first) {
|
|
107
108
|
first = false;
|
|
108
|
-
if (
|
|
109
|
+
if (playing) {
|
|
110
|
+
hooks.play();
|
|
111
|
+
} else if (context.playing?.[key] ?? (options.playOnInit && !matchMedia('(prefers-reduced-motion: reduce)').matches)) {
|
|
109
112
|
control.play();
|
|
110
113
|
}
|
|
111
114
|
}
|
|
@@ -233,8 +236,9 @@ export function autoScroll(context) {
|
|
|
233
236
|
|
|
234
237
|
const options = settings(autoScrollDefaults, 'speed', context.options.autoScroll);
|
|
235
238
|
|
|
236
|
-
// The start delay
|
|
237
|
-
let timer = 0
|
|
239
|
+
// The start delay, and true while a pointer presses the viewport
|
|
240
|
+
let timer = 0,
|
|
241
|
+
pressed = false;
|
|
238
242
|
|
|
239
243
|
const control = controller(context, 'autoScroll', options, {
|
|
240
244
|
play: wait,
|
|
@@ -279,10 +283,40 @@ export function autoScroll(context) {
|
|
|
279
283
|
function run() {
|
|
280
284
|
timer = 0;
|
|
281
285
|
const geo = context.geo();
|
|
282
|
-
if (geo && !geo.fit && !context.dragging() && !control.paused()) {
|
|
286
|
+
if (geo && !geo.fit && !pressed && !context.dragging() && !control.paused()) {
|
|
283
287
|
context.scroll(options.direction === 'prev' ? -1 : 1, options.speed / 1000);
|
|
284
288
|
}
|
|
285
289
|
}
|
|
286
290
|
|
|
291
|
+
// A press stops the slides under the pointer. A release without a drag starts them again after the delay. A drag is an interaction.
|
|
292
|
+
const listen = (method) => ['pointerup', 'pointercancel'].forEach((name) => window[method](name, release));
|
|
293
|
+
|
|
294
|
+
function press(event) {
|
|
295
|
+
if (!event.button && control.isPlaying() && !pressed) {
|
|
296
|
+
pressed = true;
|
|
297
|
+
wait(-1);
|
|
298
|
+
context.halt();
|
|
299
|
+
listen('addEventListener');
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function release() {
|
|
304
|
+
pressed = false;
|
|
305
|
+
listen('removeEventListener');
|
|
306
|
+
if (control.isPlaying() && !context.dragging()) {
|
|
307
|
+
wait();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const { viewport } = context,
|
|
312
|
+
remove = control.remove;
|
|
313
|
+
|
|
314
|
+
viewport.addEventListener('pointerdown', press);
|
|
315
|
+
control.remove = () => {
|
|
316
|
+
viewport.removeEventListener('pointerdown', press);
|
|
317
|
+
listen('removeEventListener');
|
|
318
|
+
remove();
|
|
319
|
+
};
|
|
320
|
+
|
|
287
321
|
return control;
|
|
288
322
|
}
|
package/src/scripts/carousel.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { alignOffset, clamp, compute, inView, nearestSnap, physicalSnap, progress, snapIndex, snapOfSlide, snapPosition, targetLocation } from './geometry.js';
|
|
9
9
|
import { observeSize, readLayout, readRects, visibleArea, waitNear, windowSize } from './layout.js';
|
|
10
10
|
import { normalize, pathFits, placement } from './loop.js';
|
|
11
|
-
import { addClass, build, cleanStyle, copySlides, labelSlides, readSlides, restore, setClass, setStyle } from './markup.js';
|
|
11
|
+
import { addClass, build, cleanStyle, copyContent, copySlides, labelSlides, readSlides, restore, setClass, setStyle } from './markup.js';
|
|
12
12
|
import { animator, EASE, snapDuration } from './motion.js';
|
|
13
13
|
import { breakpoints, classNames, merge, resolve } from './options.js';
|
|
14
14
|
|
|
@@ -85,6 +85,8 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
85
85
|
// The observers and the measure state
|
|
86
86
|
let observed = [],
|
|
87
87
|
mutationObserver,
|
|
88
|
+
// Watches the content of the slides while the carousel has clones
|
|
89
|
+
copyObserver,
|
|
88
90
|
media = null,
|
|
89
91
|
ready = false,
|
|
90
92
|
started = false,
|
|
@@ -111,8 +113,9 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
111
113
|
|
|
112
114
|
const api = {
|
|
113
115
|
goToSnap: (index, instant) => go(physical(index), instant),
|
|
114
|
-
|
|
115
|
-
|
|
116
|
+
// Before the first measure pass, keep the step in the selected snap
|
|
117
|
+
goToNext: (instant) => geo ? api.canGoToNext() && step(selected, 1, instant) : go(selected + 1, instant),
|
|
118
|
+
goToPrev: (instant) => geo ? api.canGoToPrev() && step(selected, -1, instant) : go(selected - 1, instant),
|
|
116
119
|
goToSlide: (index, instant) => go(physical(api.snapOfSlide(index)), instant, index),
|
|
117
120
|
canGoToNext: () => !!geo && !geo.fit && (!!geo.period || selected < geo.snaps.length - 1),
|
|
118
121
|
canGoToPrev: () => !!geo && !geo.fit && (!!geo.period || selected > 0),
|
|
@@ -143,7 +146,7 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
143
146
|
each = { node: null, index: 0, offset: 0, distance: 0, size: 0, visible: 0 },
|
|
144
147
|
/**
|
|
145
148
|
* What the features share: the API, the events, and the state and the actions of the carousel.
|
|
146
|
-
* setup() adds root, viewport, container, cls and options.
|
|
149
|
+
* setup() adds root, viewport, container, cls and options. reinit() adds playing: the play state of the autoplay and the auto scroll before a breakpoint change.
|
|
147
150
|
*/
|
|
148
151
|
context = {
|
|
149
152
|
api,
|
|
@@ -321,6 +324,8 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
321
324
|
resolved = null;
|
|
322
325
|
}
|
|
323
326
|
const keep = geo ? selectedSlide() : requested;
|
|
327
|
+
// After a breakpoint change, the new autoplay and auto scroll keep the play state. New options start them again.
|
|
328
|
+
context.playing = newOptions ? null : { autoplay: api.autoplay?.isPlaying(), autoScroll: api.autoScroll?.isPlaying() };
|
|
324
329
|
teardown(true);
|
|
325
330
|
setup();
|
|
326
331
|
requested = keep;
|
|
@@ -342,6 +347,27 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
342
347
|
nodes = slides.concat(clones);
|
|
343
348
|
written.slides.length = slides.length;
|
|
344
349
|
mutationObserver?.takeRecords();
|
|
350
|
+
|
|
351
|
+
copyObserver?.disconnect();
|
|
352
|
+
if (clones.length) {
|
|
353
|
+
copyObserver ||= new MutationObserver(onCopy);
|
|
354
|
+
slides.forEach((node) => copyObserver.observe(node, { childList: true, characterData: true, subtree: true, attributeFilter: ['class', 'src', 'srcset', 'href', 'value'] }));
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Copy a changed slide into its clones. The carousel writes the classes of the slides, so a change of a slide's own attributes does not count.
|
|
360
|
+
*
|
|
361
|
+
* @param {MutationRecord[]} records
|
|
362
|
+
*/
|
|
363
|
+
function onCopy(records) {
|
|
364
|
+
const changed = new Set(records.filter((record) => record.type !== 'attributes' || !slides.includes(record.target)).map(({ target }) => slides.find((node) => node.contains(target))));
|
|
365
|
+
|
|
366
|
+
changed.forEach((node) => {
|
|
367
|
+
for (let index = slides.indexOf(node); node && index < clones.length; index += slides.length) {
|
|
368
|
+
copyContent(clones[index], node);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
345
371
|
}
|
|
346
372
|
|
|
347
373
|
/**
|
|
@@ -371,8 +397,15 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
371
397
|
return same && options.autoHeight && geo?.axis === 'x';
|
|
372
398
|
}
|
|
373
399
|
|
|
400
|
+
// Keep the selected slide. If the page removed it, select the slide that is now at its index, or the last slide.
|
|
374
401
|
function onMutation() {
|
|
402
|
+
const old = ready ? selectedSlide() : -1,
|
|
403
|
+
node = slides[old];
|
|
375
404
|
slides = readSlides(container, options.slides);
|
|
405
|
+
if (old > -1) {
|
|
406
|
+
const index = slides.indexOf(node);
|
|
407
|
+
requested = index > -1 ? index : Math.min(old, slides.length - 1);
|
|
408
|
+
}
|
|
376
409
|
setClones(0);
|
|
377
410
|
nodes = slides;
|
|
378
411
|
changed = true;
|
|
@@ -425,7 +458,7 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
425
458
|
// With clones: 'fill', the loop fills the window
|
|
426
459
|
lastWindow = options.loop && options.clones === 'fill' ? windowSize(layout.axis) : 0;
|
|
427
460
|
|
|
428
|
-
const area = visibleArea(viewport, layout, rects.view, lastWindow),
|
|
461
|
+
const area = visibleArea(viewport, layout, rects.view, rects.pad, lastWindow),
|
|
429
462
|
values = [layout.axis, layout.rtl, typeof layout.align === 'string' && layout.align, rects.view, rects.gap, area.start, area.size, ...rects.slides.flatMap((slide) => [slide.start, slide.end, slide.cross])];
|
|
430
463
|
|
|
431
464
|
// A change of less than 0.5 px is not a change. During a motion, the rects have small errors, because the browser and bezier() round the easing differently.
|
|
@@ -435,7 +468,8 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
435
468
|
|
|
436
469
|
signature = values;
|
|
437
470
|
|
|
438
|
-
|
|
471
|
+
// After a change of the slides, onMutation() gives the slide to keep
|
|
472
|
+
const keep = ready && !changed ? selectedSlide() : requested,
|
|
439
473
|
next = compute(layout, rects, area, slides.length, options);
|
|
440
474
|
|
|
441
475
|
if (!next.snaps) {
|
|
@@ -447,8 +481,10 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
447
481
|
|
|
448
482
|
const total = geo.snaps.length;
|
|
449
483
|
|
|
450
|
-
// Before the first measure pass, selected is the logical snap of the startSnap option or of
|
|
451
|
-
|
|
484
|
+
// Before the first measure pass, selected is the logical snap of the startSnap option, of goToSnap() or of goToNext().
|
|
485
|
+
// In loop mode, a step before the first snap goes to the last snap.
|
|
486
|
+
const count = geo.logical.length;
|
|
487
|
+
selected = keep >= 0 ? physical(api.snapOfSlide(keep)) : Math.min(total - 1, ready ? selected : physical(geo.period ? (selected % count + count) % count : Math.max(selected, 0)));
|
|
452
488
|
previous = Math.min(previous, total - 1);
|
|
453
489
|
requested = keep;
|
|
454
490
|
if (!dragging) {
|
package/src/scripts/geometry.js
CHANGED
|
@@ -60,6 +60,9 @@ export function bounds(slides) {
|
|
|
60
60
|
max = 0;
|
|
61
61
|
|
|
62
62
|
for (const slide of slides) {
|
|
63
|
+
if (slide.hidden) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
63
66
|
start = Math.min(start, slide.start);
|
|
64
67
|
end = Math.max(end, slide.end);
|
|
65
68
|
max = Math.max(max, slide.end - slide.start);
|
|
@@ -69,14 +72,14 @@ export function bounds(slides) {
|
|
|
69
72
|
}
|
|
70
73
|
|
|
71
74
|
/**
|
|
72
|
-
* Put the slides that start at the same position (1 px or less) into one column.
|
|
75
|
+
* Put the slides that start at the same position (1 px or less) into one column. A hidden slide is in no column.
|
|
73
76
|
* In a flex row, one column has one slide. In a grid, a column can have more slides.
|
|
74
77
|
*
|
|
75
78
|
* @param {Array<{start: number, end: number}>} slides
|
|
76
79
|
* @returns {Array<{start: number, end: number}>} The columns, sorted by start.
|
|
77
80
|
*/
|
|
78
81
|
export function columns(slides) {
|
|
79
|
-
const order = slides.map((slide, index) => index).sort((a, b) => slides[a].start - slides[b].start || a - b),
|
|
82
|
+
const order = slides.map((slide, index) => index).filter((index) => !slides[index].hidden).sort((a, b) => slides[a].start - slides[b].start || a - b),
|
|
80
83
|
list = [];
|
|
81
84
|
|
|
82
85
|
let column;
|
|
@@ -202,7 +205,7 @@ export function snaps({ slides, view, align, slidesPerSnap, containScroll, perio
|
|
|
202
205
|
/**
|
|
203
206
|
* Find the slide whose anchor is nearest to the align point at a location.
|
|
204
207
|
* The anchor is the start for 'start', the center for 'center' and the end for 'end'.
|
|
205
|
-
* If two slides have the same distance, the lower index wins.
|
|
208
|
+
* If two slides have the same distance, the lower index wins. A hidden slide is never the active slide.
|
|
206
209
|
*
|
|
207
210
|
* @param {Array<{start: number, end: number}>} slides
|
|
208
211
|
* @param {number} location
|
|
@@ -219,7 +222,7 @@ export function activeSlide(slides, location, view, align, period, from = 0, to
|
|
|
219
222
|
|
|
220
223
|
slides.forEach((slide, index) => {
|
|
221
224
|
const value = Math.abs(distance(slide.start + location, alignOffset(align, view, slide.end - slide.start, index), period));
|
|
222
|
-
if (index >= from && index < to && value < gap - 0.5) {
|
|
225
|
+
if (index >= from && index < to && !slide.hidden && value < gap - 0.5) {
|
|
223
226
|
gap = value;
|
|
224
227
|
best = index;
|
|
225
228
|
}
|
|
@@ -331,7 +334,7 @@ export function inView(slides, location, view, threshold, period) {
|
|
|
331
334
|
start = period ? distance(slide.start + location + size / 2, view / 2, period) + view / 2 - size / 2 : slide.start + location,
|
|
332
335
|
visible = Math.min(start + size, view) - Math.max(start, 0);
|
|
333
336
|
|
|
334
|
-
if (visible > 0 && visible >= threshold * size - 0.5) {
|
|
337
|
+
if (!slide.hidden && visible > 0 && visible >= threshold * size - 0.5) {
|
|
335
338
|
result.push(index);
|
|
336
339
|
}
|
|
337
340
|
});
|
|
@@ -392,7 +395,7 @@ export function compute(layout, rects, area, count, options) {
|
|
|
392
395
|
const geo = { ...layout, ...rects, area, fit, count, period, min: 0, max: 0 };
|
|
393
396
|
|
|
394
397
|
if (fit) {
|
|
395
|
-
geo.snaps = [{ location: 0, slide: activeSlide(rects.slides, 0, rects.view, layout.align) }];
|
|
398
|
+
geo.snaps = [{ location: 0, slide: Math.max(0, activeSlide(rects.slides, 0, rects.view, layout.align)) }];
|
|
396
399
|
} else {
|
|
397
400
|
Object.assign(geo, snaps({ ...rects, align: layout.align, slidesPerSnap: options.slidesPerSnap, containScroll: options.containScroll, period }));
|
|
398
401
|
}
|
package/src/scripts/input.js
CHANGED
|
@@ -10,6 +10,9 @@ import { EASE, GLIDE } from './motion.js';
|
|
|
10
10
|
// The targets that keep their own pointer behavior
|
|
11
11
|
const fields = 'input,textarea,select,[contenteditable]';
|
|
12
12
|
|
|
13
|
+
// The pointerdown events that a carousel took for a drag
|
|
14
|
+
const claimed = new WeakSet();
|
|
15
|
+
|
|
13
16
|
// The duration of the motion for one wheel event, in ms
|
|
14
17
|
const WHEEL = 180;
|
|
15
18
|
|
|
@@ -138,17 +141,21 @@ export function drag(context) {
|
|
|
138
141
|
|
|
139
142
|
const geo = context.geo();
|
|
140
143
|
|
|
141
|
-
|
|
144
|
+
// In nested carousels, the inner carousel gets the press first and claims it
|
|
145
|
+
if (pointer !== null || event.button || !geo || geo.fit || claimed.has(event) || event.target.closest(fields)) {
|
|
142
146
|
return;
|
|
143
147
|
}
|
|
144
148
|
|
|
149
|
+
claimed.add(event);
|
|
150
|
+
|
|
145
151
|
// Stop the text selection and the native image drag
|
|
146
152
|
if (event.pointerType === 'mouse') {
|
|
147
153
|
event.preventDefault();
|
|
148
154
|
}
|
|
149
155
|
|
|
150
156
|
pointer = event.pointerId;
|
|
151
|
-
|
|
157
|
+
// In a parent with a CSS scale, one px of the pointer is not one px of the carousel
|
|
158
|
+
axis = { x: geo.axis === 'x', sign: geo.sign, scale: geo.scale };
|
|
152
159
|
start = [event.clientX, event.clientY];
|
|
153
160
|
samples = [];
|
|
154
161
|
listen('addEventListener');
|
|
@@ -167,8 +174,8 @@ export function drag(context) {
|
|
|
167
174
|
return end(event.type === 'pointerup');
|
|
168
175
|
}
|
|
169
176
|
|
|
170
|
-
const dx = event.clientX - start[0],
|
|
171
|
-
dy = event.clientY - start[1],
|
|
177
|
+
const dx = (event.clientX - start[0]) / axis.scale,
|
|
178
|
+
dy = (event.clientY - start[1]) / axis.scale,
|
|
172
179
|
main = axis.x ? dx * axis.sign : dy,
|
|
173
180
|
cross = axis.x ? dy : dx;
|
|
174
181
|
|
|
@@ -254,6 +261,31 @@ export function drag(context) {
|
|
|
254
261
|
};
|
|
255
262
|
}
|
|
256
263
|
|
|
264
|
+
/**
|
|
265
|
+
* Find an element between a node and the viewport that can scroll in a direction.
|
|
266
|
+
*
|
|
267
|
+
* @param {Element} node The target of the wheel event.
|
|
268
|
+
* @param {Element} viewport
|
|
269
|
+
* @param {string} axis 'x' or 'y'.
|
|
270
|
+
* @param {number} delta The wheel delta on the axis.
|
|
271
|
+
* @returns {boolean}
|
|
272
|
+
*/
|
|
273
|
+
function scrolls(node, viewport, axis, delta) {
|
|
274
|
+
const [size, client, position, overflow] = axis === 'x' ? ['scrollWidth', 'clientWidth', 'scrollLeft', 'overflowX'] : ['scrollHeight', 'clientHeight', 'scrollTop', 'overflowY'];
|
|
275
|
+
|
|
276
|
+
for (; node && node !== viewport; node = node.parentElement) {
|
|
277
|
+
// Read the style only for an element with more content than space
|
|
278
|
+
if (node[size] > node[client] && /auto|scroll/.test(getComputedStyle(node)[overflow])) {
|
|
279
|
+
const at = Math.abs(node[position]);
|
|
280
|
+
if (delta > 0 ? at + node[client] < node[size] - 1 : at > 0) {
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
|
|
257
289
|
/**
|
|
258
290
|
* Make the wheel input of a viewport: in a vertical carousel, and with wheel: 'both' also in a horizontal carousel. The carousel follows
|
|
259
291
|
* the wheel distance with a short motion on the compositor. When the wheel stops, the carousel goes to a snap. At the first and the last
|
|
@@ -271,9 +303,12 @@ export function wheel(context) {
|
|
|
271
303
|
return;
|
|
272
304
|
}
|
|
273
305
|
|
|
274
|
-
// The time of the last wheel event, and
|
|
306
|
+
// The time and the delta size of the last wheel event, and true if the gesture moved the carousel
|
|
275
307
|
let time = 0,
|
|
276
|
-
|
|
308
|
+
last = 0,
|
|
309
|
+
held = false,
|
|
310
|
+
// true while a gesture scrolls an element in a slide
|
|
311
|
+
inner = false,
|
|
277
312
|
// The timer that finds the end of a gesture
|
|
278
313
|
timer = 0,
|
|
279
314
|
// The selected snap at the gesture start, and the direction of the last step
|
|
@@ -291,7 +326,24 @@ export function wheel(context) {
|
|
|
291
326
|
|
|
292
327
|
const now = event.timeStamp,
|
|
293
328
|
gesture = now - time < 200,
|
|
294
|
-
|
|
329
|
+
size = Math.abs(delta),
|
|
330
|
+
// A delta that does not grow is the inertia of the gesture, not a new push
|
|
331
|
+
inertia = gesture && size <= last;
|
|
332
|
+
|
|
333
|
+
last = size;
|
|
334
|
+
if (!gesture) {
|
|
335
|
+
held = false;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// An element in a slide that can scroll in the wheel direction scrolls, also for the rest of its gesture
|
|
339
|
+
if ((gesture && inner) || scrolls(event.target, viewport, side ? 'x' : 'y', side ? event.deltaX : delta)) {
|
|
340
|
+
inner = true;
|
|
341
|
+
time = now;
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
inner = false;
|
|
345
|
+
|
|
346
|
+
const base = context.location(),
|
|
295
347
|
path = delta * (event.deltaMode === 1 ? 40 : event.deltaMode ? geo.view : 1);
|
|
296
348
|
|
|
297
349
|
let target = base - path;
|
|
@@ -303,7 +355,7 @@ export function wheel(context) {
|
|
|
303
355
|
|
|
304
356
|
// At the end, the page scrolls. The inertia of a gesture that moved the carousel does not scroll the page.
|
|
305
357
|
if (Math.abs(target - base) < 0.5) {
|
|
306
|
-
if (
|
|
358
|
+
if (held && inertia) {
|
|
307
359
|
event.preventDefault();
|
|
308
360
|
}
|
|
309
361
|
return;
|
|
@@ -315,7 +367,7 @@ export function wheel(context) {
|
|
|
315
367
|
if (!timer) {
|
|
316
368
|
snap = context.selected();
|
|
317
369
|
}
|
|
318
|
-
|
|
370
|
+
held = true;
|
|
319
371
|
direction = path > 0 ? 1 : -1;
|
|
320
372
|
context.move(nearestSnap(geo.snaps, target, geo.period), target, WHEEL, EASE);
|
|
321
373
|
|