@twistedandy/better-carousel 1.1.1 → 1.1.3

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.
@@ -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){return n=>e.forEach(([e,o,r])=>t[n?"addEventListener":"removeEventListener"](e,o,r))}function i(t,e){const n=document.createElement(t);return e&&(n.className=e),n}function s(t,n,o,r){const s=i("button",t);return s.type="button",e(s,"aria-label",o),s.setAttribute("aria-controls",n.id),s.addEventListener("click",r),s}function a(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 l=new WeakMap,c=new WeakMap;function d(t,e,n){const o=l.get(t)||new Set;!o.has(e)&&t.hasAttribute(e)||(o.add(e),l.set(t,o),t.getAttribute(e)!==n&&t.setAttribute(e,n))}function u(t,e){if(e&&!t.classList.contains(e)){const n=c.get(t)||new Set;t.classList.add(e),n.add(e),c.set(t,n)}}const p=new WeakSet;let f=0;const g=new Set(["template","script","style"]);function h(t,e){return[...e?t.querySelectorAll(e):t.children].filter(t=>!p.has(t)&&!g.has(t.localName))}function m(t){const e=t.cloneNode(!0);for(const t of[e,...e.querySelectorAll("[id]")])t.removeAttribute("id");return e}function v(t,e){t.replaceChildren(...m(e).childNodes)}const y={delay:4e3,stopOnInteraction:!0,pauseOnHover:!1,pauseOnFocus:!0,stopOnLastSnap:!1,playOnInit:!0,instant:!1,timer:null},x={speed:120,direction:"next",startDelay:1e3,stopOnInteraction:!0,pauseOnHover:!1,pauseOnFocus:!0,playOnInit:!0};function w(t,e,n){return{...t,..."number"==typeof n?{[e]:n}:n}}function b(n,o,r,i){const{api:a,root:l,container:c,cls:u,emit:p}=n,f=n.options.labels,g=s(u.button+" "+u.playButton,c,"",()=>h?w.stop():w.play());let h=!1,m=null,v=!0;function y(){e(g,"aria-label",h?f.pause:f.play),t(l,u.playing,h),d(c,"aria-live",h?"off":"polite")}function x(){a.isFit()?g.remove():g.isConnected||l.append(g),v&&(v=!1,h?i.play():(n.playing?.[o]??(r.playOnInit&&!matchMedia("(prefers-reduced-motion: reduce)").matches))&&w.play())}const w={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&&i.pause(m.paused())},r=new IntersectionObserver(([t])=>o("view",!t.isIntersecting)),s=[[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),s.forEach(([t,e,n])=>t.addEventListener(e,n)),{paused:()=>n.size>0,remove(){r.disconnect(),s.forEach(([t,e,n])=>t.removeEventListener(e,n))}}})(l,r),y(),i.play(),p(o.toLowerCase()+":play"))},stop(){h&&(h=!1,m.remove(),y(),i.stop(),p(o.toLowerCase()+":stop"))},isPlaying(){return h},paused(){return!h||m.paused()},remove(){w.stop(),g.remove(),delete a[o]}};return[["init",x],["reinit",x],["resize",x],...i.events].forEach(([t,e])=>n.on(t,e)),y(),a[o]=w,w}function S(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 E(t,e){return t-Math.ceil(t/e)*e}const{abs:M,floor:T,round:z}=Math;function k(t,e,n){return Math.min(n,Math.max(e,t))}function A(t,e,n){return n?(t%e+e)%e:k(t,0,e-1)}function O(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 F(t,e,n=0){let o=-1,r=1/0;return t.forEach((t,i)=>{const s=e(t,i);r-n>s&&(r=s,o=i)}),o}function P(t,e,n){const o=t-e;return n?o-z(o/n)*n:o}function C(t,e,n,o,r,i=0,s=t.length){return F(t,(t,a)=>i>a||a>=s||t.hidden?1/0:M(P(t.start+e,O(o,n,t.end-t.start,a),r)),.5)}function N(t,e,n){return Math.max(0,F(t,t=>M(P(t.location,e,n))))}function I(t,e,n,o=0){return n?o>0?t+(Math.ceil((e-.5-t)/n)-1)*n:0>o?t+(T((e+.5-t)/n)+1)*n:e+P(t,e,n):t}function _(t,{min:e,max:n,period:o}){if(o){const e=(n-t)/o;return e-T(e)}return n>e?k((n-t)/(n-e),0,1):0}function W(t,e,n,o,r){const i=[];return t.forEach((t,s)=>{const a=t.end-t.start,l=r?P(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 B(t){return"x"===t?document.documentElement.clientWidth:innerHeight}const H=new WeakMap,R=new WeakMap,D=new WeakMap;let j;function G(t,e){j||=new ResizeObserver(t=>{const e=[...new Set(t.filter(t=>{const{inlineSize:e,blockSize:n}=t.borderBoxSize[0],o=e+","+n,r=D.get(t.target)===o;return D.set(t.target,o),!r&&!H.get(t.target)?.skip(t)}).map(t=>H.get(t.target)))].filter(t=>t&&t.read());e.forEach(t=>t.write()),e.length&&(e.forEach(t=>R.get(t)?.forEach(t=>j.unobserve(t))),requestAnimationFrame(()=>e.forEach(t=>R.get(t)?.forEach(e=>H.get(e)===t&&j.observe(e)))))}),e&&R.set(e,t);for(const n of t)D.delete(n),e?(H.set(n,e),j.observe(n)):(H.delete(n),j.unobserve(n))}const q=new Map,V=new WeakMap,X=new WeakMap,K=[.25,1,.5,1],Y=[.2,.6,.35,1];function U([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>M(a))return r(e,o,s);if(1e-6>M(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 J={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},$=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"}),Q=["selected","inView","dragging","playing","first","prev","current","next","last"];function Z(...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 tt(t,...e){let n={};try{n=JSON.parse(t.dataset.carousel||"{}")}catch{}return Z(J,...e,n)}const et=new WeakMap,nt=t=>et.get(t),ot="input,textarea,select,[contenteditable]",rt=new WeakSet,it=[t=>{const{viewport:e,options:n}=t;if(!n.drag)return;let o,i,s,a=null,l=!1,c=[],d=0;const u=r(window,[["pointermove",p],["pointerup",p],["pointercancel",p]]);function p(r){if(r.pointerId!==a)return;if("pointermove"!==r.type)return c.length&&c.push([c[c.length-1][0],r.timeStamp]),f("pointerup"===r.type);const l=(r.clientX-o[0])/s.scale,u=(r.clientY-o[1])/s.scale,p=s.x?l*s.sign:u,g=s.x?u:l;if(!t.dragging()){if("mouse"!==r.pointerType&&M(g)>M(p))return f();if(M(p)<n.dragThreshold)return;i=t.halt(),d=t.selected(),t.drag(!0),e.setPointerCapture(a)}const h=t.geo(),m=i+p,v=k(m,h.min,h.max);t.hold(h.period?m:v+(m-v)/4,!0),c.push([p,r.timeStamp]),c.length>10&&c.shift()}function f(e){if(u(),a=null,!t.dragging())return;const o=t.geo(),r=t.location(),s=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})(c):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=k(p,i,s)),"number"==typeof l&&l>0&&u-1+!a>l){const t=t=>I(r[A(o+t*l,u,a)].location,e,a,t);p=k(p,t(1),t(-1))}if(!0===c)return{location:p,snap:N(r,p,a)};if(c||l){const t=N(r,p,a);return{location:I(r[t].location,p,a),snap:t}}const f=t-e;let g=0;M(n)>.3?g=0>n?1:-1:M(f)>20&&(g=0>f?1:-1);const h=A(o+g,u,a),m=r[h].location;return{location:a?I(m,g?e:t,a,h===o?0:g):m,snap:h}})({location:r,from:i,velocity:s,current:d,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?Y:K;l=!0,t.drag(!1),t.move(p.snap,p.location,((t,e,n,o)=>Math.sign(t)!==Math.sign(e)||.05>M(e)?o:k(M(t)*n[1]/n[0]/M(e),200,1200))(p.location-r,s,f,n.duration),f)}const g=r(e,[["pointerdown",e=>{l=!1;const n=t.geo();null!==a||e.button||!n||n.fit||rt.has(e)||e.target.closest(ot)||(rt.add(e),"mouse"===e.pointerType&&e.preventDefault(),a=e.pointerId,s={x:"x"===n.axis,sign:n.sign,scale:n.scale},o=[e.clientX,e.clientY],c=[],u(!0))}],["click",t=>{l&&(l=!1,t.preventDefault(),t.stopPropagation())},!0],["dragstart",t=>t.preventDefault()],["selectstart",e=>t.dragging()&&e.preventDefault()]]);return g(!0),{remove(){u(),g()}}},t=>{const{viewport:e,options:n}=t,o=!0===n.dragFree;if(!n.wheel)return;let i=0,s=0,a=!1,l=!1,c=0,d=0,u=0;function p(){c=0;const e=t.geo(),n=t.current(),o=N(e.snaps,n,e.period),r=M(I(e.snaps[o].location,n,e.period)-n)>10;t.step(o,o===d&&r?u:0)}const f=r(e,[["wheel",n=>{const r=t.geo(),f="x"===r.axis&&M(n.deltaX)>M(n.deltaY),g=f?n.deltaX*r.sign:n.deltaY;if(n.ctrlKey||!g||t.dragging())return;const h=n.timeStamp,m=200>h-i,v=M(g),y=m&&s>=v;if(i=h,s=v,a&&=m,l=m&&l||((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=M(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:g),l)return;const x=t.location(),w=g*(1===n.deltaMode?40:n.deltaMode?r.view:1);let b=x-w;r.period||(b=k(b,r.min,r.max)),.5>M(b-x)?a&&y&&n.preventDefault():(n.preventDefault(),t.emit("interact"),c||(d=t.selected()),a=!0,u=w>0?1:-1,t.move(N(r.snaps,b,r.period),b,180,K),clearTimeout(c),o||(c=setTimeout(p,150)))},{passive:!1}]]);return["init","reinit","resize"].forEach(e=>t.on(e,()=>{const e=t.geo();f(!e.fit&&("y"===e.axis||"both"===n.wheel))})),{remove(){f(),clearTimeout(c)}}},t=>{const{api:e,root:n,options:o}=t;if(!o.keys)return;const i=r(n,[["keydown",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]())}]]);return i(!0),{remove:i}},t=>{const{api:e,container:n,options:o}=t;let i=-1e4;const s=r(n,[["pointerdown",t=>{t.target.closest(ot)||(i=t.timeStamp)}],["focusin",n=>{const r=t.geo(),s=e.slideNodes().findIndex(t=>t.contains(n.target));!r||0>s||600>n.timeStamp-i||(o.focus&&!W(r.slides,t.location(),r.view,1,r.period).map(t=>t%r.count).includes(s)&&e.goToSlide(s),t.emit("slidefocus"))}]]);return s(!0),{remove:s}},n=>{const{api:o,root:r,cls:l,options:c}=n,d=c.labels,u=a(c.arrows,r),p=a(c.dots,r),f=[],g=[],h="all"!==c.dotsStyle,m=p&&i("div",h?l.dots:l.dots+" "+l.dotsAll),v=m&&i("div",l.dotsTrack);let y=new Map;if(u||p)return m&&(v.append(i("span",l.dotsMarker)),m.append(v),p.append(m)),u&&f.push(s(l.button+" "+l.prevButton,n.container,d.prev,()=>o.goToPrev()),s(l.button+" "+l.nextButton,n.container,d.next,()=>o.goToNext())),["init","reinit","resize","select","slideschanged"].forEach(t=>n.on(t,x)),{remove(){f.forEach(t=>t.remove()),m?.remove()}};function x(){const r=o.isFit(),i=r?0:o.snapProgress().length,a=o.selectedSnap();if(f.forEach((t,e)=>{if(r)t.remove();else{t.isConnected||(m?.parentNode===u?m.before(t):u.append(t));const n=!(e?o.canGoToNext():o.canGoToPrev());t.disabled!==n&&(t.disabled=n)}}),!m)return;if(2>i)return void m.remove();for(;g.length>i;)g.pop().remove(),y.delete(g.length);for(;i>g.length;){const t=g.length,e=s(l.dot,n.container,d.dot.replace("%d",t+1),()=>o.goToSnap(t));h&&(e.tabIndex=-1),g.push(e),v.append(e)}m.isConnected||p.append(m);const c=new Map;["first","prev","current","next","last"].forEach((t,e)=>{g[a+e-2]&&c.set(a+e-2,l[t])}),y.forEach((n,o)=>{c.get(o)!==n&&(t(g[o],n,!1),e(g[o],"aria-current",!1),g[o].tabIndex=h?-1:0)}),c.forEach((n,o)=>{t(g[o],n,!0),e(g[o],"aria-current",o===a&&"true"),g[o].tabIndex=0}),y=c,h&&w("--better-shift",2-(Math.max(0,a-2)+Math.min(i-1,a+2))/2),w("--better-dot",a)}function w(t,e){m.style.getPropertyValue(t)!==e+""&&m.style.setProperty(t,e)}},t=>{if(!t.options.autoplay)return;const e=t.api,n=w(y,"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=b(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=w(x,"speed",t.options.autoScroll);let n=0,o=!1;const i=b(t,"autoScroll",e,{play(){c(!0),s()},stop(){c(),l(),o=!1,s(-1),t.halt()},pause(e){e?t.halt():n||a()},events:[["settle",()=>i.isPlaying()&&s()],["resize",()=>i.isPlaying()&&!n&&a()],["interact",()=>{i.isPlaying()&&(s(-1),e.stopOnInteraction&&i.stop())}]]});function s(t){clearTimeout(n),n=t?0:setTimeout(a,e.startDelay)}function a(){n=0;const r=t.geo();!r||r.fit||o||t.dragging()||i.paused()||t.scroll("prev"===e.direction?-1:1,e.speed/1e3)}const l=r(window,[["pointerup",d],["pointercancel",d]]),c=r(t.viewport,[["pointerdown",e=>{e.button||o||(o=!0,s(-1),t.halt(),l(!0))}]]);function d(){o=!1,l(),t.dragging()||s()}return i},t=>{const{api:e,container:n}=t,o=t.options.sync;let i=null;if(!o)return;function s(n){const o=i.selectedSlide();t.follow(o),e.goToSlide(o,!0===n)}function l(){i||(i=o.goToSnap?o:nt("string"==typeof o?a(o,t.root):o),i&&(i.on("select",s),s(!0)))}t.on("init",l),t.on("reinit",l);const c=r(n,[["click",n=>{const o=t.nodes().findIndex(t=>t.contains(n.target));i&&o>-1&&i.goToSlide(o%e.slideNodes().length)}]]);return c(!0),{remove(){i?.off("select",s),c()}}}];function st(e,r={}){return((e,r,s,a)=>{const g=et.get(e);if(g)return g;let y,x,w,b,H,R,D,j,Y=[],J=[],nt=[],ot=[],rt=[],it=null,st=!1,at=!1,lt=!1,ct=[],dt=0,ut=-1,pt=0,ft=null,gt=0,ht=0,mt=0,vt=-1,yt=-1,xt=[],wt={axis:"",container:0,slides:[]},bt=!1,St=!1;const Et={goToSnap:(t,e)=>ne(Rt(t),e),goToNext:t=>te(1,t),goToPrev:t=>te(-1,t),goToSlide:(t,e)=>ne(Rt(Et.snapOfSlide(t)),e,t),canGoToNext:()=>Zt(1),canGoToPrev:()=>Zt(-1),selectedSnap:()=>Ht(ht),previousSnap:()=>Ht(mt),selectedSlide:Dt,snapOfSlide:t=>ft?Ht(((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):N(t,O(r,o,a.end-a.start,n)-a.start,i)})(ft.snaps,ft.slides,t,ft.view,ft.align,ft.period)):t,snapProgress:()=>ft?ft.logical.map(t=>_(ft.snaps[t].location,ft)):[],progress:()=>ft?_(jt(),ft):0,slideNodes:()=>Y.slice(),slidesInView:()=>xt.slice(),rootNode:()=>w,viewportNode:()=>b,containerNode:()=>H,isFit:()=>!ft||ft.fit,options:()=>y,reinit:Ct,destroy(){Pt(!1),Mt.emit("destroy")}},Mt=(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}}})(Et),Tt={read:Gt,write:Vt,skip({target:t,contentRect:{width:e}}){if(t!==b)return!1;const n=e===dt;return dt=e,n&&y.autoHeight&&"x"===ft?.axis}},zt={progress:0,snap:0},kt={node:null,index:0,offset:0,distance:0,size:0,visible:0},At={api:Et,emit:Mt.emit,on:Mt.listen,geo:()=>ft,nodes:()=>nt,selected:()=>ht,dragging:()=>bt,location:()=>St?jt():gt,current:jt,hold(t,e){gt=t,(e?se:Ut)(t),ie()},halt:le,step:ee,scroll(t,e){const n=le(),o=t>0?ft.min:ft.max;ft.period?(St=!0,gt=E(n,ft.period),j.loop(gt,t,ft.period/e,ft,nt)):M(o-n)>1&&(St=!0,gt=o,j.run(n,o,M(o-n)/e,[0,0,1,1],Mt.has("scroll")))},move(t,e,n,o){vt=-1,oe(t,e,n,o)},drag(e){bt=e,t(w,x.dragging,e),e?(Mt.emit("interact"),Mt.emit("dragstart")):Mt.emit("dragend")},follow(t){yt=t}};Et.on=Mt.on,Et.off=Mt.off;let Ot=tt(e,s,r),Lt=Ot.lazy?((t,e,n)=>{const o=!0===e?innerHeight:e,r=X.get(t)||t.getBoundingClientRect(),i=!0===e?"100%":e+"px";if(X.delete(t),r.height&&r.bottom>=-o&&r.top<=innerHeight+o)return null;let s=q.get(i);return s||(s=new IntersectionObserver(t=>t.forEach(t=>t.isIntersecting&&V.get(t.target)?.()),{rootMargin:i}),q.set(i,s)),V.set(t,n),s.observe(t),()=>{s.unobserve(t),V.delete(t)}})(e,Ot.lazy,Ct):null;return Lt?et.set(e,Et):Ft(),Et;function Ft(){if(it=((t,e)=>{const n=Object.entries(t.breakpoints||{}).map(([t,e])=>[matchMedia(t),e]);return n.forEach(([t])=>t.addEventListener("change",e)),{options:Z(t,...n.filter(([t])=>t.matches).map(([,t])=>t)),remove(){return n.forEach(([t])=>t.removeEventListener("change",e))}}})(Ot||tt(e,s,r),()=>Ct()),Ot=null,y=it.options,y.active){x=((t,e)=>{const n="string"==typeof t?$(t):{...$(t?.prefix||"better"),...t};for(const t of Q)n[t]&&(n[t]=e+n[t]);return n})(y.classes,y.state),({root:w,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 r=o.parentElement,s=r.parentElement;return p.has(r)||r.classList.contains(n.viewport)||!e.wrapper||(s=i("div"),r=i("div"),p.add(s).add(r),o.before(s),s.append(r),r.append(o)),u(s,n.root),u(r,n.viewport),u(o,n.container),d(s,"role","region"),d(s,"aria-roledescription","carousel"),s.hasAttribute("aria-labelledby")||d(s,"aria-label",e.labels.carousel),d(o,"id",o.id||"carousel-"+ ++f),d(o,"aria-live","polite"),{root:s,viewport:r,container:o}})(e,y,x));for(const t of[w,b,H])et.set(t,Et);Y=h(H,y.slides),nt=Y,ht=y.startSnap,_t(!0),Object.assign(At,{root:w,viewport:b,container:H,cls:x,options:y}),ot=a.map(t=>t(At)).filter(Boolean),j=((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:U(o)})},loop(t,e,n,o,r){return p({from:t,to:t-e*o.period,duration:n,direction:e,length:o.period,list:S(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,Qt,se,ae,(y.progress||y.offset)&&(t=>Jt(t,j.shifts(ft.sign)||wt.slides))),y.autoHeight&&u(w,x.autoHeight),b.addEventListener("scroll",ce),y.loop&&"fill"===y.clones&&addEventListener("resize",qt),y.slideChanges&&(R=new MutationObserver(Wt),R.observe(H,{childList:!0}))}}function Pt(r){if(Lt?.(),Lt=null,et.delete(e),_t(!1),R?.disconnect(),it?.remove(),it=null,x){j.stop(),ot.forEach(t=>t.remove()),Mt.clear(),ot=[],yt=-1,bt=St=!1,Nt(0),b.removeEventListener("scroll",ce),removeEventListener("resize",qt);for(const e of nt)n(e,"translate",""),e.style.removeProperty("--better-offset"),t(e,x.selected,!1),t(e,x.inView,!1),o(e);n(H,"translate",""),n(H,"willChange",""),n(b,"touchAction",""),n(b,"height",""),w.style.removeProperty("--better-progress");for(const e of["horizontal","vertical","fit","dragging"])t(w,x[e],!1);for(const t of[w,b,H])o(t),et.delete(t);((t,e,n,o,r)=>{for(const r of[t,e,n,...o])l.get(r)?.forEach(t=>r.removeAttribute(t)),c.get(r)?.forEach(t=>r.classList.remove(t)),l.delete(r),c.delete(r),""===r.getAttribute("class")&&r.removeAttribute("class");!r&&p.has(t)&&(t.before(n),t.remove())})(w,b,H,Y,r),x=ft=null,st=!1,gt=0,xt=[],ct=[],dt=0,wt={axis:"",container:0,slides:[]}}}function Ct(t){t&&(r=Z(r,t),Ot=null);const e=ft?Dt():vt;At.playing=t?null:{autoplay:Et.autoplay?.isPlaying(),autoScroll:Et.autoScroll?.isPlaying()},Pt(!0),Ft(),vt=e}function Nt(e){J.length!==e*Y.length&&(J.forEach(t=>t.remove()),J=((e,n,r)=>{const i=[];for(let s=0;n>s;s++)for(const n of e){const e=m(n);e.setAttribute("aria-hidden","true"),e.inert=!0,e.style.translate="",t(e,r,!0),o(e),p.add(e),i.push(e)}return i})(Y,e,x.clone),H.append(...J),nt=Y.concat(J),wt.slides.length=Y.length,R?.takeRecords(),D?.disconnect(),J.length&&(D||=new MutationObserver(It),Y.forEach(t=>D.observe(t,{childList:!0,characterData:!0,subtree:!0,attributeFilter:["class","src","srcset","href","value"]}))))}function It(t){Y.forEach((e,n)=>{if(t.some(({type:t,target:n})=>e.contains(n)&&("attributes"!==t||n!==e)))for(let t=n;J.length>t;t+=Y.length)v(J[t],e)})}function _t(t){G(rt),rt=t?[b,H,...nt]:[],G(rt,Tt)}function Wt(){const t=st?Dt():-1,e=Y[t];if(Y=h(H,y.slides),t>-1){const n=Y.indexOf(e);vt=n>-1?n:Math.min(t,Y.length-1)}Nt(0),nt=Y,lt=!0,_t(!0)}function Bt(t){return t%Y.length}function Ht(t){return ft?ft.map[t]??0:t}function Rt(t){return ft?((t,e,n)=>{const o=F(t.snaps,(o,r)=>t.map[r]===e?M(P(o.location,n,t.period)):1/0);return 0>o?k(e,0,t.snaps.length-1):o})(ft,t,jt()):t}function Dt(){return yt>-1?yt:ft?0>vt||Et.snapOfSlide(vt)!==Ht(ht)?Bt(ft.snaps[ht].slide):vt:Math.max(vt,0)}function jt(){return j.current()??gt}function Gt(){const t=ft?.sign||1,e=j.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,y),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&&(M(r.width-c)>=1||M(r.height-d)>=1),p=u?M(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,g=getComputedStyle(t),h=i?n.rtl?["Right","Left"]:["Left","Right"]:["Top","Bottom"],m={start:parseFloat(g["padding"+h[0]])||0,end:parseFloat(g["padding"+h[1]])||0},v=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-m.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=v.find(t=>!t.hidden)?.start||0,x=-1,w=-1,b=n.gap;return v.forEach((t,e)=>{t.hidden?t.start=t.end=y:(y=t.end,(0>x||v[x].start>t.start)&&(x=e),(0>w||t.end>v[w].end)&&(w=e))}),x>-1&&(b+=(parseFloat(getComputedStyle(e[x])["margin"+h[0]])||0)+(parseFloat(getComputedStyle(e[w])["margin"+h[1]])||0)),{view:f-m.start-m.end,slides:v,gap:b,scale:p,pad:m}})(b,nt,n,null===e?wt:{axis:wt.axis,container:t*e,slides:j.shifts(t)||wt.slides});pt=y.loop&&"fill"===y.clones?B(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,z("x"===e.axis?e.rtl?r-i.right:i.left:i.top))+o.start;return{start:-s,size:s+Math.max(n+o.end,z(r-s))}})(b,n,o.view,o.pad,pt),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(st&&i.length===ct.length&&i.every((t,e)=>t===ct[e]||.5>M(t-ct[e])))return!1;ct=i;const s=st&&!lt?Dt():vt,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,C(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)=>O(n,e,t.end-t.start,o)-t.start);i||(r?c=c.map(t=>k(t,l,a)):(a=Math.max(...c),l=Math.min(...c))),(i||"keepSnaps"!==r)&&(c=c.filter((t,e)=>!e||M(P(t,c[e-1],i))>1),i&&c.length>1&&1>=M(P(c[0],c[c.length-1],i))&&c.pop());const d=c.map(o=>({location:o,slide:C(t,o,e,n,i)})),u=(o,r,i)=>{const s=C(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,Y.length,y);if(!a.snaps)return ut=a.copies,!0;ft=a;const l=ft.snaps.length;return ht=0>s?Math.min(l-1,st?ht:Rt(A(ht,ft.logical.length,ft.period))):Rt(Et.snapOfSlide(s)),mt=Math.min(mt,l-1),vt=s,bt||(gt=I(ft.snaps[ht].location,gt,ft.period)),!0}function qt(){ft&&B(ft.axis)!==pt&&Gt()&&Vt()}function Vt(){if(ut>=0)return Nt(ut),ut=-1,ct=[],void _t(!0);St&&le();const t=j.current();null!==t&&wt.axis===ft.axis&&!ft.fit&&j.retarget(gt)?($t(t,gt),Xt(!0)):(j.stop(),Xt(bt)),((t,e)=>{t.forEach((n,o)=>{n.matches("a[href],button,input,select,textarea,[tabindex],[role]")&&!l.get(n)?.has("role")||(n.matches("div,span,section")&&d(n,"role","group"),d(n,"aria-roledescription","slide"),d(n,"aria-label",e.replace("%d",o+1).replace("%n",t.length)))})})(Y,y.labels.slide),y.resize||_t(!1),st?Mt.emit("resize"):(st=!0,Mt.emit(at?"reinit":"init"),at=!0),lt&&(lt=!1,Mt.emit("slideschanged"))}function Xt(e){const o="x"===ft.axis;t(w,x.horizontal,o),t(w,x.vertical,!o),t(w,x.fit,ft.fit),n(b,"touchAction",ft.fit?"":o?"pan-y pinch-zoom":"pan-x pinch-zoom"),n(H,"willChange",ft.fit?"":"translate"),e||Ut(ft.fit?0:gt),y.autoHeight&&n(b,"height",o?Math.max(...W(ft.slides,gt,ft.view,0,ft.period).map(t=>ft.slides[t].cross))+"px":"");const r=Dt(),i=[...new Set(W(ft.slides,gt,ft.view,y.inViewThreshold,ft.period).map(Bt))].sort((t,e)=>t-e);nt.forEach((e,n)=>t(e,x.selected,Bt(n)===r)),i.join()!==xt.join()&&(xt=i,nt.forEach((e,n)=>t(e,x.inView,i.includes(Bt(n)))),Mt.emit("slidesinview"))}function Kt(t){const e=devicePixelRatio||1;return z(t*e)/e*ft.sign}function Yt(t){return t?"x"===ft.axis?t+"px":"0 "+t+"px":""}function Ut(t){wt.axis!==ft.axis&&(nt.forEach(t=>n(t,"translate","")),wt={axis:ft.axis,container:0,slides:[]}),wt.container=Kt(t),n(H,"translate",Yt(wt.container)),$t(t,t),(y.progress||y.offset)&&Jt(t,wt.slides)}function Jt(t,e){if(!0===y.progress)w.style.setProperty("--better-progress",_(t,ft));else if(y.progress){const e=((t,e,n)=>{const o=t.length-1,r=t[0].location,i=n?r-((r-e)%n+n)%n:k(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)})(ft.snaps,t,ft.period),n=T(e);zt.progress=_(t,ft),zt.snap=Ht(n)+e-n,y.progress(zt,Et)}y.offset&&nt.forEach((n,o)=>{const r=ft.slides[o],i=r.end-r.start,s=r.start+ft.sign*(e[o]||0)+t,a=s-O(ft.align,ft.view,i,o),l=a/(i+ft.gap);!0===y.offset?n.style.setProperty("--better-offset",l):(kt.node=n,kt.index=Bt(o),kt.offset=l,kt.distance=ft.sign*a,kt.size=i,kt.visible=k((Math.min(s+i,ft.view)-Math.max(s,0))/i,0,1)||0,y.offset(kt,Et))})}function $t(t,e){const o=ft.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)})(ft.slides,t,e,ft.area.size,ft.period,ft.area.start):[];nt.forEach((t,e)=>{const r=o.length?Kt(o[e]*ft.period):0;(wt.slides[e]||0)!==r&&(wt.slides[e]=r,n(t,"translate",Yt(r)))})}function Qt(t){return Yt(Kt(t))||"0px"}function Zt(t){return!(!ft||ft.fit||!ft.period&&!(t>0?ft.snaps.length-1>ht:ht>0))}function te(t,e){ft?Zt(t)&&ee(ht,t,e):ne(ht+t,e)}function ee(t,e,n){ne(A(t+e,ft.snaps.length,ft.period),n,-1,e)}function ne(t,e,n=-1,o=0){if(Lt&&Ct(),Mt.emit("interact"),vt=n,!ft)return void(ht=t);const r=I(ft.snaps[t].location,jt(),ft.period,o),i=M(t-ht);var s,a;oe(t,r,e?0:(s=y.duration,(a=ft.period?Math.min(i,ft.snaps.length-i):i)>1?Math.min(2*s,s*(1+Math.log2(a))):s),K)}function oe(t,e,n,o){const r=le(),i=re(t),s=!n||ft.fit||.5>M(e-r);if(gt=e,s)Xt();else{const t=Mt.has("scroll")||!!ft.period&&!((t,e,n,o,r)=>{const i=o+Math.abs(n-e);return t.every(t=>r>=i+t.end-t.start)})(ft.slides,r,e,ft.area.size,ft.period);Xt(!0),t||$t(r,e),j.run(r,e,n,o,t)}i&&Mt.emit("select"),s&&ae()}function re(t){return t!==ht&&(mt=ht,ht=t,!0)}function ie(){re(N(ft.snaps,gt,ft.period))&&(Xt(!0),Mt.emit("select"))}function se(t){Ut(t),Mt.emit("scroll")}function ae(){St&&(St=!1,ie()),ft.period&&(gt=E(gt,ft.period)),Xt(),Mt.emit("settle")}function le(){const t=j.stop();return null!==t&&(gt=t,Ut(t),St&&ie()),St=!1,gt}function ce(){b.scrollLeft=b.scrollTop=0}})(e,r,st.defaults,it)}return st.defaults={},st.get=nt,st.initAll=(t,e)=>{const n=[...document.querySelectorAll(t)];return(t=>{t.forEach(t=>X.set(t,t.getBoundingClientRect()))})(n.filter(t=>!nt(t)&&tt(t,st.defaults,e).lazy)),n.map(t=>st(t,e))},st})();
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.getPropertyValue(e)!==n+""&&t.style.setProperty(e,n)}function o(t){""===t.getAttribute("style")&&t.removeAttribute("style")}function r(t,e){return n=>e.forEach(([e,o,r])=>t[n?"addEventListener":"removeEventListener"](e,o,r))}function i(t,e){const n=document.createElement(t);return e&&(n.className=e),n}function s(t,n,o,r){const s=i("button",t);return s.type="button",e(s,"aria-label",o),s.setAttribute("aria-controls",n.id),s.addEventListener("click",r),s}function a(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 l=new WeakMap,c=new WeakMap;function d(t,n,o){const r=l.get(t)||new Set;!r.has(n)&&t.hasAttribute(n)||(r.add(n),l.set(t,r),e(t,n,o))}function u(t,e){if(e&&!t.classList.contains(e)){const n=c.get(t)||new Set;t.classList.add(e),n.add(e),c.set(t,n)}}const p=new WeakSet;let f=0;const g=new Set(["template","script","style"]);function h(t,e){return[...e?t.querySelectorAll(e):t.children].filter(t=>!p.has(t)&&!g.has(t.localName))}function m(t){const e=t.cloneNode(!0),n=t.querySelectorAll("select");for(const t of[e,...e.querySelectorAll("[id],[name],[required]")])["id","name","required"].forEach(e=>t.removeAttribute(e));return e.querySelectorAll("select").forEach((t,e)=>t.selectedIndex=n[e].selectedIndex),e}function v(t,e){t.replaceChildren(...m(e).childNodes)}const x={delay:4e3,stopOnInteraction:!0,pauseOnHover:!1,pauseOnFocus:!0,stopOnLastSnap:!1,playOnInit:!0,instant:!1,timer:null},y={speed:120,direction:"next",startDelay:1e3,stopOnInteraction:!0,pauseOnHover:!1,pauseOnFocus:!0,playOnInit:!0};function w(t,e,n){return{...t,..."number"==typeof n?{[e]:n}:n}}function b(n,o,r,i){const{api:a,root:l,container:c,cls:u,emit:p}=n,f=n.options.labels,g=s(u.button+" "+u.playButton,c,"",()=>h?y.stop():y.play());let h=!1,m=null,v=!0;function x(){e(g,"aria-label",h?f.pause:f.play),t(l,u.playing,h),d(c,"aria-live",h?"off":"polite")}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&&i.pause(m.paused())},r=new IntersectionObserver(([t])=>o("view",!t.isIntersecting)),s=[[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),s.forEach(([t,e,n])=>t.addEventListener(e,n)),{paused:()=>n.size>0,remove(){r.disconnect(),s.forEach(([t,e,n])=>t.removeEventListener(e,n))}}})(l,r),x(),i.play(),p(o.toLowerCase()+":play"))},stop(){h&&(h=!1,m.remove(),x(),i.stop(),p(o.toLowerCase()+":stop"))},isPlaying(){return h},paused(){return!h||m.paused()},remove(){n.playing&&(n.playing[o]=h),y.stop(),g.remove(),delete a[o]}};return[["init reinit resize",()=>{a.isFit()?g.remove():g.isConnected||l.append(g),v&&(v=!1,h?i.play():(n.playing?.[o]??(r.playOnInit&&!matchMedia("(prefers-reduced-motion: reduce)").matches))&&y.play())}],...i.events].forEach(([t,e])=>n.on(t,e)),x(),a[o]=y,y}function S(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 E(t,e){return t-Math.ceil(t/e)*e}const{abs:M,floor:T,round:z}=Math;function k(t,e,n){return Math.min(n,Math.max(e,t))}function A(t,e,n){return n?(t%e+e)%e:k(t,0,e-1)}function L(t,e,n,o){return"function"==typeof t?t(e,n,o):"center"===t?(e-n)/2:"end"===t?e-n:0}function O(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 F(t,e,n=0){let o=-1,r=1/0;return t.forEach((t,i)=>{const s=e(t,i);r-n>s&&(r=s,o=i)}),o}function I(t,e,n){const o=t-e;return n?o-z(o/n)*n:o}function P(t,e,n,o,r,i=0,s=t.length){return F(t,(t,a)=>i>a||a>=s||t.hidden?1/0:M(I(t.start+e,L(o,n,t.end-t.start,a),r)),.5)}function C(t,e,n){return Math.max(0,F(t,t=>M(I(t.location,e,n))))}function N(t,e,n,o=0){return n?o>0?t+(Math.ceil((e-.5-t)/n)-1)*n:0>o?t+(T((e+.5-t)/n)+1)*n:e+I(t,e,n):t}function _(t,{min:e,max:n,period:o}){if(o){const e=(n-t)/o;return e-T(e)}return n>e?k((n-t)/(n-e),0,1):0}function W({slides:t,view:e,period:n},o,r){const i=[];return t.forEach((t,s)=>{const a=t.end-t.start,l=n?I(t.start+o+a/2,e/2,n)+e/2-a/2:t.start+o,c=Math.min(l+a,e)-Math.max(l,0);t.hidden||0>=c||r*a-.5>c||i.push(s)}),i}function H(t){return"x"===t?document.documentElement.clientWidth:innerHeight}const q=new WeakMap,B=new WeakMap,D=new WeakMap;let j;function R(t,e){j||=new ResizeObserver(t=>{const e=[...new Set(t.filter(t=>{const{inlineSize:e,blockSize:n}=t.borderBoxSize[0],o=e+","+n,r=D.get(t.target)===o;return D.set(t.target,o),!r&&!q.get(t.target)?.skip(t)}).map(t=>q.get(t.target)))].filter(t=>t?.read());e.forEach(t=>t.write()),e.length&&(e.forEach(t=>B.get(t)?.forEach(t=>j.unobserve(t))),requestAnimationFrame(()=>e.forEach(t=>B.get(t)?.forEach(e=>q.get(e)===t&&j.observe(e)))))}),e&&B.set(e,t);for(const n of t)D.delete(n),e?(q.set(n,e),j.observe(n)):(q.delete(n),j.unobserve(n))}const G=new Map,V=new WeakMap;let X=[];function Y(){const t=X,e=t.map(([t])=>t.getBoundingClientRect());X=[],t.forEach(([t,n,o],r)=>{const i=!0===n?innerHeight:n,s=e[r],a=V.get(t);if(!a)return;if(s.height&&s.bottom>=-i&&s.top<=innerHeight+i)return void a();let l=G.get(o);l||(l=new IntersectionObserver(t=>t.forEach(t=>t.isIntersecting&&V.get(t.target)?.()),{rootMargin:o}),G.set(o,l)),l.observe(t)})}const K=[.25,1,.5,1],J=[.2,.6,.35,1];function U([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>M(a))return r(e,o,s);if(1e-6>M(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},Z=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"}),$=["selected","inView","dragging","playing","first","prev","current","next","last"];function tt(...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 et(t,...e){let n={};try{n=JSON.parse(t.dataset.carousel||"{}")}catch{}return tt(Q,...e,n)}const nt=new WeakMap;let ot;const rt=t=>nt.get(t),it="input,textarea,select,[contenteditable]",st=new WeakSet,at=[t=>{const{viewport:e,options:n}=t;if(!n.drag)return;let o,i,s,a=null,l=!1,c=!1,d=[],u=0;const p=r(window,[["pointermove",f],["pointerup",f],["pointercancel",f]]);function f(r){if(r.pointerId!==a)return;if("pointermove"!==r.type)return d.length&&d.push([d[d.length-1][0],r.timeStamp]),g("pointerup"===r.type);const l=(r.clientX-o[0])/s.scale,c=(r.clientY-o[1])/s.scale,p=s.x?l*s.sign:c,f=s.x?c:l;if(!t.dragging()){if("mouse"!==r.pointerType&&M(f)>M(p))return g();if(M(p)<n.dragThreshold)return;i=t.halt(),u=t.selected(),t.drag(!0),e.setPointerCapture(a)}const h=t.geo(),m=i+p,v=k(m,h.min,h.max);t.hold(h.period?m:v+(m-v)/4,!0),d.push([p,r.timeStamp]),d.length>10&&d.shift()}function g(e){p(),a=null;const o=t.dragging();if(!o&&!c)return;const r=t.geo(),s=t.location(),f=e&&d.length?(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})(d):0,g=(({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=k(p,i,s)),"number"==typeof l&&l>0&&u-1+!a>l){const t=t=>N(r[A(o+t*l,u,a)].location,e,a,t);p=k(p,t(1),t(-1))}if(!0===c)return{location:p,snap:C(r,p,a)};if(c||l){const t=C(r,p,a);return{location:N(r[t].location,p,a),snap:t}}const f=t-e;let g=0;M(n)>.3?g=0>n?1:-1:M(f)>20&&(g=0>f?1:-1);const h=A(o+g,u,a),m=r[h].location;return{location:a?N(m,g?e:t,a,h===o?0:g):m,snap:h}})({...r,...n,location:s,from:i,velocity:f,current:u}),h=!0===n.dragFree?J:K;l=!0,o&&t.drag(!1),t.move(g.snap,g.location,((t,e,n,o)=>Math.sign(t)!==Math.sign(e)||.05>M(e)?o:k(M(t)*n[1]/n[0]/M(e),200,1200))(g.location-s,f,h,n.duration),h)}const h=r(e,[["pointerdown",e=>{l=!1;const n=t.geo();null!==a||e.button||!n||n.fit||st.has(e)||e.target.closest(it)||(st.add(e),"mouse"===e.pointerType&&e.preventDefault(),a=e.pointerId,s={x:"x"===n.axis,sign:n.sign,scale:n.scale},o=[e.clientX,e.clientY],d=[],c=t.moving(),c&&(i=t.halt(),u=t.selected(),t.emit("interact")),p(!0))}],["click",t=>{l&&t.detail&&(t.preventDefault(),t.stopPropagation()),l=!1},!0],["dragstart",t=>t.preventDefault()],["selectstart",e=>t.dragging()&&e.preventDefault()]]);return h(!0),{remove(){p(),h()}}},t=>{const{viewport:e,options:n}=t,o=!0===n.dragFree;if(!n.wheel)return;let i=0,s=0,a=!1,l=!1,c=0,d=0,u=0;function p(){c=0;const e=t.geo(),n=t.current(),o=C(e.snaps,n,e.period),r=M(N(e.snaps[o].location,n,e.period)-n)>10;t.step(o,o===d&&r?u:0)}const f=r(e,[["wheel",r=>{const f=t.geo(),g="x"===f.axis&&M(r.deltaX)>M(r.deltaY),h=g?r.deltaX*f.sign:r.deltaY;if(r.ctrlKey||!h||t.dragging()||"axis"===n.wheel&&"x"===f.axis&&!g)return;const m=r.timeStamp,v=200>m-i,x=M(h),y=v&&s>=x;if(i=m,s=x,a&&=v,l=v&&l||((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=M(t[s]);if(o>0?t[r]-1>e+t[i]:e>0)return!0}return!1})(r.target,e,g?"x":"y",g?r.deltaX:h),l)return;const w=t.location(),b=h*(1===r.deltaMode?40:r.deltaMode?f.view:1);let S=w-b;f.period||(S=k(S,f.min,f.max)),.5>M(S-w)?a&&y&&r.preventDefault():(r.preventDefault(),t.emit("interact"),c||(d=t.selected()),a=!0,u=b>0?1:-1,t.move(C(f.snaps,S,f.period),S,180,K),clearTimeout(c),o||(c=setTimeout(p,150)))},{passive:!1}]]);return t.on("init reinit resize",()=>{const e=t.geo();f(!e.fit&&("y"===e.axis||!0!==n.wheel))}),{remove(){f(),clearTimeout(c)}}},t=>{const{api:e,root:n,options:o}=t;if(!o.keys)return;const i=r(n,[["keydown",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.closest(it))&&e["canGoTo"+a]()&&(n.preventDefault(),e["goTo"+a]())}]]);return i(!0),{remove:i}},t=>{const{api:e,container:n,options:o}=t;let i=-1e4;const s=r(n,[["pointerdown",t=>{t.target.closest(it)||(i=t.timeStamp)}],["focusin",n=>{const r=t.geo(),s=e.slideNodes().findIndex(t=>t.contains(n.target));!r||0>s||600>n.timeStamp-i||(o.focus&&!W(r,t.location(),1).map(t=>t%r.count).includes(s)&&e.goToSlide(s),t.emit("slidefocus"))}]]);return s(!0),{remove:s}},o=>{const{api:r,root:l,cls:c,options:d}=o,u=d.labels,p=a(d.arrows,l),f=a(d.dots,l),g=[],h=[],m="all"!==d.dotsStyle,v=f&&i("div",m?c.dots:c.dots+" "+c.dotsAll),x=v&&i("div",c.dotsTrack);let y=new Map;if(p||f)return v&&(x.append(i("span",c.dotsMarker)),v.append(x),f.append(v)),p&&g.push(s(c.button+" "+c.prevButton,o.container,u.prev,()=>r.goToPrev()),s(c.button+" "+c.nextButton,o.container,u.next,()=>r.goToNext())),o.on("init reinit resize select slideschanged",()=>{const i=r.isFit(),a=i?0:o.geo().logical.length,l=r.selectedSnap();if(g.forEach((t,e)=>{if(i)t.remove();else{t.isConnected||(v?.parentNode===p?v.before(t):p.append(t));const n=!(e?r.canGoToNext():r.canGoToPrev());t.disabled!==n&&(t.disabled=n)}}),!v)return;if(2>a)return void v.remove();for(;h.length>a;)h.pop().remove(),y.delete(h.length);for(;a>h.length;){const t=h.length,e=s(c.dot,o.container,u.dot.replace("%d",t+1),()=>r.goToSnap(t));m&&(e.tabIndex=-1),h.push(e),x.append(e)}v.isConnected||f.append(v);const d=new Map;["first","prev","current","next","last"].forEach((t,e)=>{h[l+e-2]&&d.set(l+e-2,c[t])}),y.forEach((n,o)=>{d.get(o)!==n&&(t(h[o],n,!1),e(h[o],"aria-current",!1),h[o].tabIndex=m?-1:0)}),d.forEach((n,o)=>{t(h[o],n,!0),e(h[o],"aria-current",o===l&&"true"),h[o].tabIndex=0}),y=d,m&&n(v,"--better-shift",2-(Math.max(0,l-2)+Math.min(a-1,l+2))/2),n(v,"--better-dot",l)}),{remove(){g.forEach(t=>t.remove()),v?.remove()}}},t=>{if(!t.options.autoplay)return;const e=t.api,n=w(x,"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=b(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=w(y,"speed",t.options.autoScroll);let n=0,o=!1;const i=b(t,"autoScroll",e,{play(){c(!0),s()},stop(){c(),l(),o=!1,s(-1),t.halt()},pause(e){e?t.halt():n||a()},events:[["settle",()=>i.isPlaying()&&s()],["resize",()=>i.isPlaying()&&!n&&a()],["interact",()=>{i.isPlaying()&&(s(-1),e.stopOnInteraction&&i.stop())}]]});function s(t){clearTimeout(n),n=t?0:setTimeout(a,e.startDelay)}function a(){n=0;const r=t.geo();!r||r.fit||o||t.dragging()||i.paused()||t.scroll("prev"===e.direction?-1:1,e.speed/1e3)}const l=r(window,[["pointerup",d],["pointercancel",d]]),c=r(t.viewport,[["pointerdown",e=>{e.button||o||(o=!0,s(-1),t.halt(),l(!0))}]]);function d(){o=!1,l(),t.dragging()||s()}return i},t=>{const{api:e,container:n}=t,o=t.options.sync;let i=null;if(!o)return;function s(n){const o=i.selectedSlide();t.follow(o),e.goToSlide(o,!0===n)}t.on("init reinit",()=>{i||(i=o.goToSnap?o:t.find("string"==typeof o?a(o,t.root):o),i&&(i.on("select",s),s(!0)))});const l=r(n,[["click",t=>{const n=e.slideNodes().findIndex(e=>e.contains(t.target));i&&n>-1&&i.goToSlide(n)}]]);return l(!0),{remove(){i?.off("select",s),l()}}}];function lt(e,r={}){return((e,r,s,a)=>{const g=nt.get(e);if(g)return g;let x,y,w,b,q,B,D,j,J=[],Q=[],it=[],st=[],at=[],lt=null,ct=!1,dt=!1,ut=!1,pt=[],ft=0,gt=-1,ht=0,mt=null,vt=0,xt=0,yt=0,wt=-1,bt=-1,St=[],Et={axis:"",container:0,slides:[]},Mt=!1,Tt=!1;const zt={goToSnap:(t,e)=>ae(Vt(t),e),goToNext:t=>ie(1,t),goToPrev:t=>ie(-1,t),goToSlide:(t,e)=>ae(Vt(zt.snapOfSlide(t)),e,t),canGoToNext:()=>re(1),canGoToPrev:()=>re(-1),selectedSnap:()=>Gt(xt),previousSnap:()=>Gt(yt),selectedSlide:Xt,snapOfSlide:t=>mt?Gt((({snaps:t,slides:e,view:n,align:o,period:r},i)=>{const s=t.findIndex(t=>t.slide===i),a=e[i];return s>-1||!a?Math.max(s,0):C(t,L(o,n,a.end-a.start,i)-a.start,r)})(mt,t)):t,snapProgress:()=>mt?mt.logical.map(t=>_(mt.snaps[t].location,mt)):[],progress:()=>mt?_(Yt(),mt):0,slideNodes:()=>J.slice(),slidesInView:()=>St.slice(),rootNode:()=>w,viewportNode:()=>b,containerNode:()=>q,isFit:()=>!mt||mt.fit,options:()=>x,reinit:_t,destroy(){Nt(!1),kt.emit("destroy")}},kt=(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 t.split(" ").forEach(t=>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}}})(zt),At={read:Kt,write:Ut,skip({target:t,contentRect:{width:e}}){if(t!==b)return!1;const n=e===ft;return ft=e,n&&x.autoHeight&&"x"===mt?.axis}},Lt={progress:0,snap:0},Ot={node:null,index:0,offset:0,distance:0,size:0,visible:0},Ft={api:zt,emit:kt.emit,on:kt.listen,find:rt,geo:()=>mt,selected:()=>xt,dragging:()=>Mt,moving:()=>!Tt&&null!==j.current(),location:()=>Tt?Yt():vt,current:Yt,hold(t,e){vt=t,(e?ue:te)(t),de()},halt:fe,step:se,scroll(t,e){const n=fe(),o=t>0?mt.min:mt.max;mt.period?(Tt=!0,vt=E(n,mt.period),j.loop(vt,t,mt.period/e,mt,it)):M(o-n)>1&&(Tt=!0,vt=o,j.run(n,o,M(o-n)/e,[0,0,1,1],kt.has("scroll")))},move(t,e,n,o){wt=-1,le(t,e,n,o)},drag(e){Mt=e,t(w,y.dragging,e),e?(kt.emit("interact"),kt.emit("dragstart")):kt.emit("dragend")},follow(t){bt=t}};zt.on=kt.on,zt.off=kt.off;let It=et(e,s,r),Pt=It.lazy?((t,e,n)=>{const o=!0===e?"100%":e+"px";return X.length||queueMicrotask(Y),X.push([t,e,o]),V.set(t,n),()=>{G.get(o)?.unobserve(t),V.delete(t)}})(e,It.lazy,_t):null;return Pt?nt.set(e,zt):Ct(),zt;function Ct(){if(lt=((t,e)=>{const n=Object.entries(t.breakpoints||{}).map(([t,e])=>[matchMedia(t),e]);return n.forEach(([t])=>t.addEventListener("change",e)),{options:tt(t,...n.filter(([t])=>t.matches).map(([,t])=>t)),remove(){return n.forEach(([t])=>t.removeEventListener("change",e))}}})(It||et(e,s,r),()=>_t()),It=null,x=lt.options,x.active){y=((t,e)=>{const n="string"==typeof t?Z(t):{...Z(t?.prefix||"better"),...t};for(const t of $)n[t]&&(n[t]=e+n[t]);return n})(x.classes,x.state),({root:w,viewport:b,container:q}=((t,e,n)=>{let o=e.container?t.querySelector(e.container):t;o.classList.contains(n.viewport)&&(o=o.firstElementChild);let r=o.parentElement,s=r.parentElement;return p.has(r)||r.classList.contains(n.viewport)||!e.wrapper||(s=i("div"),r=i("div"),p.add(s).add(r),o.before(s),s.append(r),r.append(o)),u(s,n.root),u(r,n.viewport),u(o,n.container),d(s,"role","region"),d(s,"aria-roledescription","carousel"),s.hasAttribute("aria-labelledby")||d(s,"aria-label",e.labels.carousel),d(o,"id",o.id||"carousel-"+ ++f),d(o,"aria-live","polite"),{root:s,viewport:r,container:o}})(e,x,y));for(const t of[w,b,q])nt.set(t,zt);J=h(q,x.slides),it=J,xt=x.startSnap,Bt(!0),Object.assign(Ft,{root:w,viewport:b,container:q,cls:y,options:x}),st=a.map(t=>t(Ft)).filter(Boolean),j=((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:U(o)})},loop(t,e,n,o,r){return p({from:t,to:t-e*o.period,duration:n,direction:e,length:o.period,list:S(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)}}})(q,oe,ue,pe,(x.progress||x.offset)&&(t=>ee(t,j.shifts(mt.sign)||Et.slides))),x.autoHeight&&u(w,y.autoHeight),b.addEventListener("scroll",ge),b.addEventListener("click",he),b.addEventListener("input",qt),x.loop&&"fill"===x.clones&&addEventListener("resize",Jt),x.slideChanges&&(B=new MutationObserver(jt),B.observe(q,{childList:!0}))}}function Nt(r){if(Pt?.(),Pt=null,nt.delete(e),Bt(!1),B?.disconnect(),lt?.remove(),lt=null,y){j.stop(),st.forEach(t=>t.remove()),kt.clear(),st=[],bt=-1,Mt=Tt=!1,Wt(0),b.removeEventListener("scroll",ge),b.removeEventListener("click",he),b.removeEventListener("input",qt),removeEventListener("resize",Jt),it.forEach(Dt),n(q,"translate",""),n(q,"will-change",""),n(b,"touch-action",""),n(b,"height",""),n(w,"--better-progress","");for(const e of["horizontal","vertical","fit","dragging"])t(w,y[e],!1);for(const t of[w,b,q])o(t),nt.delete(t);((t,e,n,o,r)=>{for(const r of[t,e,n,...o])l.get(r)?.forEach(t=>r.removeAttribute(t)),c.get(r)?.forEach(t=>r.classList.remove(t)),l.delete(r),c.delete(r),""===r.getAttribute("class")&&r.removeAttribute("class");!r&&p.has(t)&&(t.before(n),t.remove())})(w,b,q,J,r),y=mt=null,ct=!1,vt=0,St=[],pt=[],ft=0,Et={axis:"",container:0,slides:[]}}}function _t(t){t&&(r=tt(r,t),It=null);const e=mt?Xt():wt;Ft.playing=t?null:{},Nt(!0),Ct(),wt=e}function Wt(e){Q.length!==e*J.length&&(Q.forEach(t=>t.remove()),Q=((e,n,r)=>{const i=[];for(let s=0;n>s;s++)for(const n of e){const e=m(n);e.setAttribute("aria-hidden","true"),e.inert=!0,e.style.translate="",t(e,r,!0),o(e),p.add(e),i.push(e)}return i})(J,e,y.clone),q.append(...Q),it=J.concat(Q),Et.slides.length=J.length,B?.takeRecords(),D?.disconnect(),Q.length&&(D||=new MutationObserver(Ht),J.forEach(t=>D.observe(t,{childList:!0,characterData:!0,subtree:!0,attributeFilter:["class","src","srcset","href","value"]}))))}function Ht(t){J.forEach((e,n)=>{if(!t||t.some(({type:t,target:n})=>e.contains(n)&&("attributes"!==t||n!==e)))for(let t=n;Q.length>t;t+=J.length)v(Q[t],e)})}function qt(){Ht()}function Bt(t){R(at),at=t?[b,q,...it]:[],R(at,At)}function Dt(e){n(e,"translate",""),n(e,"--better-offset",""),t(e,y.selected,!1),t(e,y.inView,!1),o(e)}function jt(){const t=ct?Xt():-1,e=J[t],n=new Map(J.map((t,e)=>[t,Et.slides[e]]));if(J=h(q,x.slides),t>-1){const n=J.indexOf(e);wt=n>-1?n:Math.min(t,J.length-1)}n.forEach((t,e)=>J.includes(e)||Dt(e)),Wt(0),it=J,Et.slides=J.map(t=>n.get(t)||0),pt=[],ut=!0,Bt(!0)}function Rt(t){return t%J.length}function Gt(t){return mt?mt.map[t]??0:t}function Vt(t){return mt?((t,e,n)=>{const o=F(t.snaps,(o,r)=>t.map[r]===e?M(I(o.location,n,t.period)):1/0);return 0>o?k(e,0,t.snaps.length-1):o})(mt,t,Yt()):t}function Xt(){return bt>-1?bt:mt?0>wt||zt.snapOfSlide(wt)!==Gt(xt)?Rt(mt.snaps[xt].slide):wt:Math.max(wt,0)}function Yt(){return j.current()??vt}function Kt(){const t=mt?.sign||1,e=j.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}})(q,x);ht=x.loop&&"fill"===x.clones?H(n.axis):0;const o=((t,e,n,o,r)=>{const i=t.getBoundingClientRect(),s="x"===n.axis,a=n.sign,l=o.axis===n.axis,c=l?o.container:0,d=t.offsetWidth,u=t.offsetHeight,p=!d||!u||1>M(i.width-d)&&1>M(i.height-u)?1:s?i.width/d:i.height/u,f=(s?i.width:i.height)/p,g=getComputedStyle(t),h=s?n.rtl?["Right","Left"]:["Left","Right"]:["Top","Bottom"],m={start:parseFloat(g["padding"+h[0]])||0,end:parseFloat(g["padding"+h[1]])||0},v=e.map((t,e)=>{const r=t.getBoundingClientRect(),d=(s?n.rtl?i.right-r.right:r.left-i.left:r.top-i.top)/p-m.start-a*(c+(l&&o.slides[e]||0));return{start:d,end:d+(s?r.width:r.height)/p,cross:(s?r.height:r.width)/p,hidden:!r.width&&!r.height}});let x=v.find(t=>!t.hidden)?.start||0,y=-1,w=-1,b=n.gap;v.forEach((t,e)=>{t.hidden?t.start=t.end=x:(x=t.end,(0>y||v[y].start>t.start)&&(y=e),(0>w||t.end>v[w].end)&&(w=e))}),y>-1&&(b+=(parseFloat(getComputedStyle(e[y])["margin"+h[0]])||0)+(parseFloat(getComputedStyle(e[w])["margin"+h[1]])||0));const S=f-m.start-m.end;let E=m.start,T=S+m.end;return r&&(E+=Math.max(0,z(s?n.rtl?r-i.right:i.left:i.top)),T=Math.max(T,z(r-E))),{view:S,slides:v,gap:b,scale:p,area:{start:-E,size:E+T}}})(b,it,n,null===e?Et:{axis:Et.axis,container:t*e,slides:j.shifts(t)||Et.slides},ht),r=[n.axis,n.rtl,"string"==typeof n.align&&n.align,o.view,o.gap,o.area.start,o.area.size,...o.slides.flatMap(t=>[t.start,t.end,t.cross])];if(ct&&r.length===pt.length&&r.every((t,e)=>t===pt[e]||.5>M(t-pt[e])))return!1;pt=r;const i=ct&&!ut?Xt():wt,s=function(t,e,n,o){const r=O(e.slides.slice(0,n)),i=!(r.size>e.view+1||o.autoScroll&&o.loop&&r.max),s=o.loop&&!i&&n,a=s?O(e.slides).size+e.gap:0,l=s&&o.clones&&(c=r.size+e.gap)>0?Math.max(0,Math.ceil((e.area.size+r.max)/c)-1):0;var c;if(l*n!==e.slides.length-n)return{copies:l};const d={...t,...e,fit:i,count:n,period:a,min:0,max:0};i?d.snaps=[{location:0,slide:Math.max(0,P(e.slides,0,e.view,t.align))}]:Object.assign(d,(({slides:t,view:e,align:n,slidesPerSnap:o,containScroll:r,period:i=0})=>{const s=O(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)=>L(n,e,t.end-t.start,o)-t.start);i||(r?c=c.map(t=>k(t,l,a)):(a=Math.max(...c),l=Math.min(...c))),(i||"keepSnaps"!==r)&&(c=c.filter((t,e)=>!e||M(I(t,c[e-1],i))>1),i&&c.length>1&&1>=M(I(c[0],c[c.length-1],i))&&c.pop());const d=c.map(o=>({location:o,slide:P(t,o,e,n,i)})),u=(o,r,i)=>{const s=P(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:o.slidesPerSnap,containScroll:o.containScroll,period:a}));const u=d.snaps.map((t,e)=>e).filter(t=>!l||n>d.snaps[t].slide);return d.logical=u,d.map=d.snaps.map((t,e)=>l?Math.max(0,u.findIndex(e=>d.snaps[e].slide%n===t.slide%n)):e),d}(n,o,J.length,x);if(!s.snaps)return gt=s.copies,!0;mt=s;const a=mt.snaps.length;return xt=0>i?Math.min(a-1,ct?xt:Vt(A(xt,mt.logical.length,mt.period))):Vt(zt.snapOfSlide(i)),yt=Math.min(yt,a-1),wt=i,Mt||(vt=N(mt.snaps[xt].location,vt,mt.period)),!0}function Jt(){mt&&H(mt.axis)!==ht&&Kt()&&Ut()}function Ut(){if(gt>=0)return Wt(gt),gt=-1,pt=[],void Bt(!0);Tt&&fe();const t=j.current();null!==t&&Et.axis===mt.axis&&!mt.fit&&j.retarget(vt)?(ne(t,vt),Qt(!0)):(j.stop(),Qt(Mt)),((t,e)=>{t.forEach((n,o)=>{n.matches("a[href],button,input,select,textarea,[tabindex],[role]")&&!l.get(n)?.has("role")||(n.matches("div,span,section")&&d(n,"role","group"),d(n,"aria-roledescription","slide"),d(n,"aria-label",e.replace("%d",o+1).replace("%n",t.length)))})})(J,x.labels.slide),x.resize||Bt(!1),ct?kt.emit("resize"):(ct=!0,kt.emit(dt?"reinit":"init"),dt=!0),ut&&(ut=!1,kt.emit("slideschanged"))}function Qt(e){const o="x"===mt.axis;t(w,y.horizontal,o),t(w,y.vertical,!o),t(w,y.fit,mt.fit);const r=!re(-1),i=!re(1),s=!o&&(r||i)&&(ot??=CSS.supports("touch-action","pan-up"))?r&&i?"pan-y ":r?"pan-up ":"pan-down ":"";n(b,"touch-action",mt.fit?"":o?"pan-y pinch-zoom":"pan-x "+s+"pinch-zoom"),n(q,"will-change",mt.fit?"":"translate"),e||te(mt.fit?0:vt),x.autoHeight&&n(b,"height",o?Math.max(...W(mt,vt,0).map(t=>mt.slides[t].cross))+"px":"");const a=Xt(),l=[...new Set(W(mt,vt,x.inViewThreshold).map(Rt))].sort((t,e)=>t-e);it.forEach((e,n)=>t(e,y.selected,Rt(n)===a)),l.join()!==St.join()&&(St=l,it.forEach((e,n)=>t(e,y.inView,l.includes(Rt(n)))),kt.emit("slidesinview"))}function Zt(t){const e=devicePixelRatio||1;return z(t*e)/e*mt.sign}function $t(t){return t?"x"===mt.axis?t+"px":"0 "+t+"px":""}function te(t){Et.axis!==mt.axis&&(it.forEach(t=>n(t,"translate","")),Et={axis:mt.axis,container:0,slides:[]}),Et.container=Zt(t),n(q,"translate",$t(Et.container)),ne(t,t),ee(t,Et.slides)}function ee(t,e){if(!0===x.progress)w.style.setProperty("--better-progress",_(t,mt));else if(x.progress){const e=((t,e,n)=>{const o=t.length-1,r=t[0].location,i=n?r-((r-e)%n+n)%n:k(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)})(mt.snaps,t,mt.period),n=T(e);Lt.progress=_(t,mt),Lt.snap=Gt(n)+e-n,x.progress(Lt,zt)}x.offset&&it.forEach((n,o)=>{const r=mt.slides[o],i=r.end-r.start,s=r.start+mt.sign*(e[o]||0)+t,a=s-L(mt.align,mt.view,i,o),l=a/(i+mt.gap);!0===x.offset?n.style.setProperty("--better-offset",l):(Ot.node=n,Ot.index=Rt(o),Ot.offset=l,Ot.distance=mt.sign*a,Ot.size=i,Ot.visible=k((Math.min(s+i,mt.view)-Math.max(s,0))/i,0,1)||0,x.offset(Ot,zt))})}function ne(t,e){const o=mt.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)})(mt.slides,t,e,mt.area.size,mt.period,mt.area.start):[];it.forEach((t,e)=>{const r=o.length?Zt(o[e]*mt.period):0;(Et.slides[e]||0)!==r&&(Et.slides[e]=r,n(t,"translate",$t(r)))})}function oe(t){return $t(Zt(t))||"0px"}function re(t){return!(!mt||mt.fit||!mt.period&&!(t>0?mt.snaps.length-1>xt:xt>0))}function ie(t,e){mt?re(t)&&se(xt,t,e):ae(xt+t,e)}function se(t,e,n){ae(A(t+e,mt.snaps.length,mt.period),n,-1,e)}function ae(t,e,n=-1,o=0){if(Pt&&_t(),kt.emit("interact"),wt=n,!mt)return void(xt=t);const r=N(mt.snaps[t].location,Yt(),mt.period,o),i=M(t-xt);var s,a;le(t,r,e?0:(s=x.duration,(a=mt.period?Math.min(i,mt.snaps.length-i):i)>1?Math.min(2*s,s*(1+Math.log2(a))):s),K)}function le(t,e,n,o){const r=fe(),i=ce(t),s=!n||mt.fit||.5>M(e-r);if(vt=e,s)Qt();else{const t=kt.has("scroll")||!!mt.period&&!((t,e,n,o,r)=>{const i=o+Math.abs(n-e);return t.every(t=>r>=i+t.end-t.start)})(mt.slides,r,e,mt.area.size,mt.period);Qt(!0),t||ne(r,e),j.run(r,e,n,o,t)}i&&kt.emit("select"),s&&pe()}function ce(t){return t!==xt&&(yt=xt,xt=t,!0)}function de(){ce(C(mt.snaps,vt,mt.period))&&(Qt(!0),kt.emit("select"))}function ue(t){te(t),kt.emit("scroll")}function pe(){Tt&&(Tt=!1,de()),mt.period&&(vt=E(vt,mt.period)),Qt(),kt.emit("settle")}function fe(){const t=j.stop();return null!==t&&(vt=t,te(t),Tt&&de()),Tt=!1,vt}function ge(){b.scrollLeft=b.scrollTop=0}function he(t){if(t.defaultPrevented||!Q.length||t.target!==b&&t.target!==q)return;Q.forEach(t=>t.inert=!1);const e=document.elementFromPoint(t.clientX,t.clientY),n=Q.findIndex(t=>t.contains(e)),o=t=>t?[t,...t.querySelectorAll("*")]:[];Q.forEach(t=>t.inert=!0),o(J[n%J.length])[o(Q[n]).indexOf(e)]?.dispatchEvent(new MouseEvent("click",t))}})(e,r,lt.defaults,at)}return lt.defaults={},lt.get=rt,lt.initAll=(t,e)=>[...document.querySelectorAll(t)].map(t=>lt(t,e)),lt})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twistedandy/better-carousel",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "A small and fast carousel that takes all sizes, gaps and the layout from CSS.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/index.js CHANGED
@@ -5,9 +5,7 @@
5
5
  import { autoplay, autoScroll } from './scripts/autoplay.js';
6
6
  import carousel, { find } from './scripts/carousel.js';
7
7
  import { drag, focus, keys, wheel } from './scripts/input.js';
8
- import { readBoxes } from './scripts/layout.js';
9
8
  import { nav, sync } from './scripts/navigation.js';
10
- import { resolve } from './scripts/options.js';
11
9
 
12
10
  // The features. Their event handlers run in this order.
13
11
  const features = [drag, wheel, keys, focus, nav, autoplay, autoScroll, sync];
@@ -41,9 +39,4 @@ BetterCarousel.get = find;
41
39
  * @param {object} [options]
42
40
  * @returns {object[]}
43
41
  */
44
- BetterCarousel.initAll = (selector, options) => {
45
- const elements = [...document.querySelectorAll(selector)];
46
- // Read the boxes of the lazy carousels before the first setup() writes. Then the reads cause one layout, not one for each carousel.
47
- readBoxes(elements.filter((element) => !find(element) && resolve(element, BetterCarousel.defaults, options).lazy));
48
- return elements.map((element) => BetterCarousel(element, options));
49
- };
42
+ BetterCarousel.initAll = (selector, options) => [...document.querySelectorAll(selector)].map((element) => BetterCarousel(element, options));
@@ -132,13 +132,17 @@ function controller(context, key, options, hooks) {
132
132
  isPlaying: () => playing,
133
133
  paused: () => !playing || watch.paused(),
134
134
  remove() {
135
+ // Keep the play state for the setup after a breakpoint change. See reinit() in carousel.js.
136
+ if (context.playing) {
137
+ context.playing[key] = playing;
138
+ }
135
139
  control.stop();
136
140
  button.remove();
137
141
  delete api[key];
138
142
  }
139
143
  };
140
144
 
141
- [['init', show], ['reinit', show], ['resize', show], ...hooks.events].forEach(([event, handler]) => context.on(event, handler));
145
+ [['init reinit resize', show], ...hooks.events].forEach(([names, handler]) => context.on(names, handler));
142
146
  update();
143
147
  api[key] = control;
144
148
 
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import { abs, alignOffset, clamp, compute, floor, inView, nearestSnap, physicalSnap, progress, round, snapIndex, snapOfSlide, snapPosition, targetLocation } from './geometry.js';
9
- import { observeSize, readLayout, readRects, visibleArea, waitNear, windowSize } from './layout.js';
9
+ import { observeSize, readLayout, readRects, waitNear, windowSize } from './layout.js';
10
10
  import { normalize, pathFits, placement } from './loop.js';
11
11
  import { addClass, build, cleanStyle, copyContent, copySlides, labelSlides, readSlides, restore, setClass, setStyle } from './markup.js';
12
12
  import { animator, EASE, snapDuration } from './motion.js';
@@ -15,6 +15,9 @@ import { breakpoints, classNames, merge, resolve } from './options.js';
15
15
  // The instance of each root, viewport and container
16
16
  const registry = new WeakMap();
17
17
 
18
+ // true if the browser supports the pan-up and pan-down values of touch-action
19
+ let directional;
20
+
18
21
  /**
19
22
  * Get the carousel of a root, a viewport or a container.
20
23
  *
@@ -25,7 +28,7 @@ export const find = (element) => registry.get(element);
25
28
 
26
29
  /**
27
30
  * Make an event emitter. A handler gets (api, name), as in Embla.
28
- * The handlers of the features run before the handlers of the page, and clear() removes them.
31
+ * The handlers of the features run before the handlers of the page, and clear() removes them. listen() takes event names with spaces between them.
29
32
  *
30
33
  * @param {object} api
31
34
  * @returns {{on: Function, off: Function, listen: Function, clear: Function, emit: Function, has: Function}}
@@ -44,7 +47,7 @@ function emitter(api) {
44
47
  user[name]?.delete(handler);
45
48
  return api;
46
49
  },
47
- listen: (name, handler) => add(own, name, handler),
50
+ listen: (names, handler) => names.split(' ').forEach((name) => add(own, name, handler)),
48
51
  clear: () => Object.values(own).forEach((set) => set.clear()),
49
52
  emit(name) {
50
53
  own[name]?.forEach((handler) => handler(api, name));
@@ -121,7 +124,7 @@ export default function carousel(element, userOptions, defaults, features) {
121
124
  selectedSnap: () => logical(selected),
122
125
  previousSnap: () => logical(previous),
123
126
  selectedSlide,
124
- snapOfSlide: (index) => geo ? logical(snapOfSlide(geo.snaps, geo.slides, index, geo.view, geo.align, geo.period)) : index,
127
+ snapOfSlide: (index) => geo ? logical(snapOfSlide(geo, index)) : index,
125
128
  snapProgress: () => geo ? geo.logical.map((index) => progress(geo.snaps[index].location, geo)) : [],
126
129
  progress: () => geo ? progress(current(), geo) : 0,
127
130
  slideNodes: () => slides.slice(),
@@ -145,19 +148,23 @@ export default function carousel(element, userOptions, defaults, features) {
145
148
  each = { node: null, index: 0, offset: 0, distance: 0, size: 0, visible: 0 },
146
149
  /**
147
150
  * What the features share: the API, the events, and the state and the actions of the carousel.
148
- * 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.
151
+ * setup() adds root, viewport, container, cls and options. reinit() adds playing: an object where the autoplay and the auto scroll
152
+ * keep their play state for the next setup after a breakpoint change.
149
153
  */
150
154
  context = {
151
155
  api,
152
156
  emit: events.emit,
153
- // Listen to an event until the teardown
157
+ // Listen to events, such as 'init reinit', until the teardown
154
158
  on: events.listen,
159
+ // Get the carousel of an element, for the sync option
160
+ find,
155
161
 
156
162
  // The state
157
163
  geo: () => geo,
158
- nodes: () => nodes,
159
164
  selected: () => selected,
160
165
  dragging: () => dragging,
166
+ // true while a motion to a location runs, such as a goToSnap() motion or a glide. The auto scroll is not such a motion.
167
+ moving: () => !free && motion.current() !== null,
161
168
  // The location at rest or at the end of the motion. During a free motion, the location now.
162
169
  location: () => free ? current() : location,
163
170
  current,
@@ -192,8 +199,7 @@ export default function carousel(element, userOptions, defaults, features) {
192
199
  api.on = events.on;
193
200
  api.off = events.off;
194
201
 
195
- // The options of the first setup. The lazy option: a carousel that is not near the screen waits. A carousel near the screen starts now:
196
- // a start after the first paint adds the arrows and the dots in view, and this moves the page (CLS).
202
+ // The options of the first setup. The lazy option: the carousel waits, and waitNear() starts it before the first paint if it is near the screen.
197
203
  let resolved = resolve(element, defaults, userOptions),
198
204
  waiting = resolved.lazy ? waitNear(element, resolved.lazy, reinit) : null;
199
205
 
@@ -240,6 +246,8 @@ export default function carousel(element, userOptions, defaults, features) {
240
246
  }
241
247
 
242
248
  viewport.addEventListener('scroll', onScroll);
249
+ viewport.addEventListener('click', onClick);
250
+ viewport.addEventListener('input', onInput);
243
251
  if (options.loop && options.clones === 'fill') {
244
252
  addEventListener('resize', onWindow);
245
253
  }
@@ -276,21 +284,17 @@ export default function carousel(element, userOptions, defaults, features) {
276
284
  dragging = free = false;
277
285
  setClones(0);
278
286
  viewport.removeEventListener('scroll', onScroll);
287
+ viewport.removeEventListener('click', onClick);
288
+ viewport.removeEventListener('input', onInput);
279
289
  removeEventListener('resize', onWindow);
280
290
 
281
- for (const node of nodes) {
282
- setStyle(node, 'translate', '');
283
- node.style.removeProperty('--better-offset');
284
- setClass(node, cls.selected, false);
285
- setClass(node, cls.inView, false);
286
- cleanStyle(node);
287
- }
291
+ nodes.forEach(clean);
288
292
 
289
293
  setStyle(container, 'translate', '');
290
- setStyle(container, 'willChange', '');
291
- setStyle(viewport, 'touchAction', '');
294
+ setStyle(container, 'will-change', '');
295
+ setStyle(viewport, 'touch-action', '');
292
296
  setStyle(viewport, 'height', '');
293
- root.style.removeProperty('--better-progress');
297
+ setStyle(root, '--better-progress', '');
294
298
 
295
299
  for (const name of ['horizontal', 'vertical', 'fit', 'dragging']) {
296
300
  setClass(root, cls[name], false);
@@ -324,7 +328,7 @@ export default function carousel(element, userOptions, defaults, features) {
324
328
  }
325
329
  const keep = geo ? selectedSlide() : requested;
326
330
  // After a breakpoint change, the new autoplay and auto scroll keep the play state. New options start them again.
327
- context.playing = newOptions ? null : { autoplay: api.autoplay?.isPlaying(), autoScroll: api.autoScroll?.isPlaying() };
331
+ context.playing = newOptions ? null : {};
328
332
  teardown(true);
329
333
  setup();
330
334
  requested = keep;
@@ -355,13 +359,15 @@ export default function carousel(element, userOptions, defaults, features) {
355
359
  }
356
360
 
357
361
  /**
358
- * 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.
362
+ * Copy a changed slide into its clones, for example after the page changed a text or an image source. The carousel writes the classes
363
+ * of the slides, so a change of a slide's own attributes does not count. A style change does not count: a "progress" or an "offset"
364
+ * callback can write the styles of the elements in the slides on each frame.
359
365
  *
360
- * @param {MutationRecord[]} records
366
+ * @param {MutationRecord[]} [records] With no records, copy all slides.
361
367
  */
362
368
  function onCopy(records) {
363
369
  slides.forEach((node, index) => {
364
- if (records.some(({ type, target }) => node.contains(target) && (type !== 'attributes' || target !== node))) {
370
+ if (!records || records.some(({ type, target }) => node.contains(target) && (type !== 'attributes' || target !== node))) {
365
371
  for (let item = index; item < clones.length; item += slides.length) {
366
372
  copyContent(clones[item], node);
367
373
  }
@@ -369,6 +375,11 @@ export default function carousel(element, userOptions, defaults, features) {
369
375
  });
370
376
  }
371
377
 
378
+ // A form field changes its value or its check with no mutation. A checked radio also changes the radios of its group in other slides, so copy all slides.
379
+ function onInput() {
380
+ onCopy();
381
+ }
382
+
372
383
  /**
373
384
  * Watch the size of the viewport, the container and the slides.
374
385
  *
@@ -396,17 +407,37 @@ export default function carousel(element, userOptions, defaults, features) {
396
407
  return same && options.autoHeight && geo?.axis === 'x';
397
408
  }
398
409
 
410
+ /**
411
+ * Remove the styles and the classes that the carousel wrote on a slide or a clone.
412
+ *
413
+ * @param {HTMLElement} node
414
+ */
415
+ function clean(node) {
416
+ setStyle(node, 'translate', '');
417
+ setStyle(node, '--better-offset', '');
418
+ setClass(node, cls.selected, false);
419
+ setClass(node, cls.inView, false);
420
+ cleanStyle(node);
421
+ }
422
+
399
423
  // Keep the selected slide. If the page removed it, select the slide that is now at its index, or the last slide.
424
+ // The loop shift of a slide stays with the slide at its new index, because the measure pass subtracts it from the slide box.
425
+ // A new slide can have the same size as the slide that it replaced, so the measure pass must not skip.
400
426
  function onMutation() {
401
427
  const old = ready ? selectedSlide() : -1,
402
- node = slides[old];
428
+ node = slides[old],
429
+ shifts = new Map(slides.map((item, index) => [item, written.slides[index]]));
403
430
  slides = readSlides(container, options.slides);
404
431
  if (old > -1) {
405
432
  const index = slides.indexOf(node);
406
433
  requested = index > -1 ? index : Math.min(old, slides.length - 1);
407
434
  }
435
+ // A removed slide can come back later, for example after a sort. It must not keep a loop shift.
436
+ shifts.forEach((shift, item) => slides.includes(item) || clean(item));
408
437
  setClones(0);
409
438
  nodes = slides;
439
+ written.slides = slides.map((item) => shifts.get(item) || 0);
440
+ signature = [];
410
441
  changed = true;
411
442
  observe(true);
412
443
  }
@@ -450,15 +481,14 @@ export default function carousel(element, userOptions, defaults, features) {
450
481
  function measure() {
451
482
  const sign = geo?.sign || 1,
452
483
  at = motion.current(),
453
- layout = readLayout(container, options),
454
- // The translate values that show now: the written values, or the values of a motion
455
- rects = readRects(viewport, nodes, layout, at === null ? written : { axis: written.axis, container: sign * at, slides: motion.shifts(sign) || written.slides });
484
+ layout = readLayout(container, options);
456
485
 
457
486
  // With clones: 'fill', the loop fills the window
458
487
  lastWindow = options.loop && options.clones === 'fill' ? windowSize(layout.axis) : 0;
459
488
 
460
- const area = visibleArea(viewport, layout, rects.view, rects.pad, lastWindow),
461
- 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])];
489
+ // The translate values that show now: the written values, or the values of a motion
490
+ const rects = readRects(viewport, nodes, layout, at === null ? written : { axis: written.axis, container: sign * at, slides: motion.shifts(sign) || written.slides }, lastWindow),
491
+ values = [layout.axis, layout.rtl, typeof layout.align === 'string' && layout.align, rects.view, rects.gap, rects.area.start, rects.area.size, ...rects.slides.flatMap((slide) => [slide.start, slide.end, slide.cross])];
462
492
 
463
493
  // 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.
464
494
  if (ready && values.length === signature.length && values.every((value, index) => value === signature[index] || abs(value - signature[index]) < 0.5)) {
@@ -469,7 +499,7 @@ export default function carousel(element, userOptions, defaults, features) {
469
499
 
470
500
  // After a change of the slides, onMutation() gives the slide to keep
471
501
  const keep = ready && !changed ? selectedSlide() : requested,
472
- next = compute(layout, rects, area, slides.length, options);
502
+ next = compute(layout, rects, slides.length, options);
473
503
 
474
504
  if (!next.snaps) {
475
505
  pending = next.copies;
@@ -557,8 +587,13 @@ export default function carousel(element, userOptions, defaults, features) {
557
587
  setClass(root, cls.horizontal, x);
558
588
  setClass(root, cls.vertical, !x);
559
589
  setClass(root, cls.fit, geo.fit);
560
- setStyle(viewport, 'touchAction', geo.fit ? '' : x ? 'pan-y pinch-zoom' : 'pan-x pinch-zoom');
561
- setStyle(container, 'willChange', geo.fit ? '' : 'translate');
590
+ // A touch can scroll the page across the axis. At the first or the last snap of a vertical carousel, it can also scroll the page up
591
+ // or down. Safari has no pan-up and pan-down, so there the carousel keeps the touch.
592
+ const first = !can(-1),
593
+ last = !can(1),
594
+ edge = !x && (first || last) && (directional ??= CSS.supports('touch-action', 'pan-up')) ? (first && last ? 'pan-y ' : first ? 'pan-up ' : 'pan-down ') : '';
595
+ setStyle(viewport, 'touch-action', geo.fit ? '' : x ? 'pan-y pinch-zoom' : 'pan-x ' + edge + 'pinch-zoom');
596
+ setStyle(container, 'will-change', geo.fit ? '' : 'translate');
562
597
 
563
598
  if (!keep) {
564
599
  write(geo.fit ? 0 : location);
@@ -566,11 +601,11 @@ export default function carousel(element, userOptions, defaults, features) {
566
601
 
567
602
  // Auto height: the height of the tallest slide in view at the target location
568
603
  if (options.autoHeight) {
569
- setStyle(viewport, 'height', x ? Math.max(...inView(geo.slides, location, geo.view, 0, geo.period).map((index) => geo.slides[index].cross)) + 'px' : '');
604
+ setStyle(viewport, 'height', x ? Math.max(...inView(geo, location, 0).map((index) => geo.slides[index].cross)) + 'px' : '');
570
605
  }
571
606
 
572
607
  const chosen = selectedSlide(),
573
- list = [...new Set(inView(geo.slides, location, geo.view, options.inViewThreshold, geo.period).map(original))].sort((a, b) => a - b);
608
+ list = [...new Set(inView(geo, location, options.inViewThreshold).map(original))].sort((a, b) => a - b);
574
609
 
575
610
  nodes.forEach((node, index) => setClass(node, cls.selected, original(index) === chosen));
576
611
 
@@ -616,9 +651,7 @@ export default function carousel(element, userOptions, defaults, features) {
616
651
  written.container = screen(value);
617
652
  setStyle(container, 'translate', translate(written.container));
618
653
  place(value, value);
619
- if (options.progress || options.offset) {
620
- track(value, written.slides);
621
- }
654
+ track(value, written.slides);
622
655
  }
623
656
 
624
657
  /**
@@ -889,4 +922,25 @@ export default function carousel(element, userOptions, defaults, features) {
889
922
  function onScroll() {
890
923
  viewport.scrollLeft = viewport.scrollTop = 0;
891
924
  }
925
+
926
+ /**
927
+ * Pass a click on a clone to the same element in its slide. A clone is inert, so the click goes to the viewport or the container.
928
+ * A click after a drag is cancelled, and it does not pass.
929
+ *
930
+ * @param {MouseEvent} event
931
+ */
932
+ function onClick(event) {
933
+ if (event.defaultPrevented || !clones.length || (event.target !== viewport && event.target !== container)) {
934
+ return;
935
+ }
936
+
937
+ // Find the element under the pointer in the clones, and the element at the same place in the slide
938
+ clones.forEach((node) => node.inert = false);
939
+ const node = document.elementFromPoint(event.clientX, event.clientY),
940
+ index = clones.findIndex((clone) => clone.contains(node)),
941
+ all = (item) => item ? [item, ...item.querySelectorAll('*')] : [];
942
+ clones.forEach((item) => item.inert = true);
943
+
944
+ all(slides[index % slides.length])[all(clones[index]).indexOf(node)]?.dispatchEvent(new MouseEvent('click', event));
945
+ }
892
946
  }
@@ -249,15 +249,11 @@ export function activeSlide(slides, location, view, align, period, from = 0, to
249
249
  /**
250
250
  * Find the snap of a slide: the snap whose active slide it is, or the snap nearest to the raw location of the slide.
251
251
  *
252
- * @param {Array<{location: number, slide: number}>} list The snaps.
253
- * @param {Array<{start: number, end: number}>} slides
252
+ * @param {{snaps: Array<{location: number, slide: number}>, slides: Array<{start: number, end: number}>, view: number, align: string|Function, period?: number}} geo
254
253
  * @param {number} index The slide index.
255
- * @param {number} view
256
- * @param {string|Function} align
257
- * @param {number} [period]
258
254
  * @returns {number} The snap index.
259
255
  */
260
- export function snapOfSlide(list, slides, index, view, align, period) {
256
+ export function snapOfSlide({ snaps: list, slides, view, align, period }, index) {
261
257
  const found = list.findIndex((snap) => snap.slide === index),
262
258
  slide = slides[index];
263
259
 
@@ -323,14 +319,12 @@ export function progress(location, { min, max, period }) {
323
319
  /**
324
320
  * Find the slides that show at a location.
325
321
  *
326
- * @param {Array<{start: number, end: number}>} slides
322
+ * @param {{slides: Array<{start: number, end: number}>, view: number, period?: number}} geo
327
323
  * @param {number} location
328
- * @param {number} view
329
324
  * @param {number} threshold The part of a slide that must show, from 0 to 1. With 0, any part is enough.
330
- * @param {number} [period]
331
325
  * @returns {number[]} The slide indexes.
332
326
  */
333
- export function inView(slides, location, view, threshold, period) {
327
+ export function inView({ slides, view, period }, location, threshold) {
334
328
  const result = [];
335
329
 
336
330
  slides.forEach((slide, index) => {
@@ -377,26 +371,27 @@ export function snapPosition(list, location, period) {
377
371
  * With clones, a logical snap is a snap whose active slide is an original slide.
378
372
  *
379
373
  * @param {object} layout The result of readLayout().
380
- * @param {{view: number, slides: Array<{start: number, end: number}>, gap: number}} rects The result of readRects(). The slides after the first count slides are clones.
381
- * @param {{start: number, size: number}} area The result of visibleArea().
374
+ * @param {{view: number, slides: Array<{start: number, end: number}>, gap: number, area: {start: number, size: number}}} rects The result of readRects().
375
+ * The slides after the first count slides are clones.
382
376
  * @param {number} count The number of original slides.
383
377
  * @param {object} options The options of the carousel.
384
378
  * @returns {object} The geometry. If the carousel needs a different number of clones, only { copies }: the number of copies of all slides.
385
379
  * map gives the logical snap of each snap.
386
380
  */
387
- export function compute(layout, rects, area, count, options) {
381
+ export function compute(layout, rects, count, options) {
388
382
  const content = bounds(rects.slides.slice(0, count)),
389
- fit = content.size <= rects.view + 1 && !(options.autoScroll && options.loop),
383
+ // The auto scroll with the loop never fits, unless no slide shows, for example in a hidden tab
384
+ fit = content.size <= rects.view + 1 && !(options.autoScroll && options.loop && content.max),
390
385
  loop = options.loop && !fit && count,
391
386
  // The loop period: the distance from the first slide start to the same point in the next copy of the slides
392
387
  period = loop ? bounds(rects.slides).size + rects.gap : 0,
393
- copies = loop && options.clones ? cloneCount(content.size + rects.gap, area.size, content.max) : 0;
388
+ copies = loop && options.clones ? cloneCount(content.size + rects.gap, rects.area.size, content.max) : 0;
394
389
 
395
390
  if (copies * count !== rects.slides.length - count) {
396
391
  return { copies };
397
392
  }
398
393
 
399
- const geo = { ...layout, ...rects, area, fit, count, period, min: 0, max: 0 };
394
+ const geo = { ...layout, ...rects, fit, count, period, min: 0, max: 0 };
400
395
 
401
396
  if (fit) {
402
397
  geo.snaps = [{ location: 0, slide: Math.max(0, activeSlide(rects.slides, 0, rects.view, layout.align)) }];