@twistedandy/better-carousel 1.0.0 → 1.1.1
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 +569 -363
- package/dist/better-carousel.min.js +1 -1
- package/package.json +1 -1
- package/src/scripts/autoplay.js +40 -12
- package/src/scripts/carousel.js +76 -18
- package/src/scripts/geometry.js +42 -44
- package/src/scripts/input.js +91 -53
- package/src/scripts/layout.js +76 -29
- package/src/scripts/markup.js +55 -7
- package/src/scripts/motion.js +3 -2
- package/src/scripts/navigation.js +200 -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){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})();
|
package/package.json
CHANGED
package/src/scripts/autoplay.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Each feature takes the context of a carousel (see carousel.js). It returns nothing if its option is off, or an object with remove().
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { bind, createButton, own, setAttribute, setClass } from './markup.js';
|
|
8
8
|
|
|
9
9
|
// The defaults of the "autoplay" option
|
|
10
10
|
const autoplayDefaults = { delay: 4000, stopOnInteraction: true, pauseOnHover: false, pauseOnFocus: true, stopOnLastSnap: false, playOnInit: true, instant: false, timer: null };
|
|
@@ -78,17 +78,13 @@ function pauser(root, options, change) {
|
|
|
78
78
|
function controller(context, key, options, hooks) {
|
|
79
79
|
const { api, root, container, cls, emit } = context,
|
|
80
80
|
labels = context.options.labels,
|
|
81
|
-
button =
|
|
81
|
+
button = createButton(cls.button + ' ' + cls.playButton, container, '', () => playing ? control.stop() : control.play());
|
|
82
82
|
|
|
83
83
|
let playing = false,
|
|
84
84
|
watch = null,
|
|
85
85
|
// true until the first init
|
|
86
86
|
first = true;
|
|
87
87
|
|
|
88
|
-
button.type = 'button';
|
|
89
|
-
button.setAttribute('aria-controls', container.id);
|
|
90
|
-
button.addEventListener('click', () => playing ? control.stop() : control.play());
|
|
91
|
-
|
|
92
88
|
function update() {
|
|
93
89
|
setAttribute(button, 'aria-label', playing ? labels.pause : labels.play);
|
|
94
90
|
setClass(root, cls.playing, playing);
|
|
@@ -102,10 +98,13 @@ function controller(context, key, options, hooks) {
|
|
|
102
98
|
} else if (!button.isConnected) {
|
|
103
99
|
root.append(button);
|
|
104
100
|
}
|
|
105
|
-
// Start at the first init, unless the user prefers less motion
|
|
101
|
+
// Start at the first init, unless the user prefers less motion. After a breakpoint change, the play state stays.
|
|
102
|
+
// A play() before the first init starts now, because the carousel had no size before.
|
|
106
103
|
if (first) {
|
|
107
104
|
first = false;
|
|
108
|
-
if (
|
|
105
|
+
if (playing) {
|
|
106
|
+
hooks.play();
|
|
107
|
+
} else if (context.playing?.[key] ?? (options.playOnInit && !matchMedia('(prefers-reduced-motion: reduce)').matches)) {
|
|
109
108
|
control.play();
|
|
110
109
|
}
|
|
111
110
|
}
|
|
@@ -233,12 +232,19 @@ export function autoScroll(context) {
|
|
|
233
232
|
|
|
234
233
|
const options = settings(autoScrollDefaults, 'speed', context.options.autoScroll);
|
|
235
234
|
|
|
236
|
-
// The start delay
|
|
237
|
-
let timer = 0
|
|
235
|
+
// The start delay, and true while a pointer presses the viewport
|
|
236
|
+
let timer = 0,
|
|
237
|
+
pressed = false;
|
|
238
238
|
|
|
239
239
|
const control = controller(context, 'autoScroll', options, {
|
|
240
|
-
play
|
|
240
|
+
play() {
|
|
241
|
+
presses(true);
|
|
242
|
+
wait();
|
|
243
|
+
},
|
|
241
244
|
stop() {
|
|
245
|
+
presses();
|
|
246
|
+
listen();
|
|
247
|
+
pressed = false;
|
|
242
248
|
wait(-1);
|
|
243
249
|
context.halt();
|
|
244
250
|
},
|
|
@@ -279,10 +285,32 @@ export function autoScroll(context) {
|
|
|
279
285
|
function run() {
|
|
280
286
|
timer = 0;
|
|
281
287
|
const geo = context.geo();
|
|
282
|
-
if (geo && !geo.fit && !context.dragging() && !control.paused()) {
|
|
288
|
+
if (geo && !geo.fit && !pressed && !context.dragging() && !control.paused()) {
|
|
283
289
|
context.scroll(options.direction === 'prev' ? -1 : 1, options.speed / 1000);
|
|
284
290
|
}
|
|
285
291
|
}
|
|
286
292
|
|
|
293
|
+
// While the auto scroll plays, a press stops the slides under the pointer. A release without a drag starts them again after the delay.
|
|
294
|
+
// A drag is an interaction.
|
|
295
|
+
const listen = bind(window, [['pointerup', release], ['pointercancel', release]]),
|
|
296
|
+
presses = bind(context.viewport, [['pointerdown', press]]);
|
|
297
|
+
|
|
298
|
+
function press(event) {
|
|
299
|
+
if (!event.button && !pressed) {
|
|
300
|
+
pressed = true;
|
|
301
|
+
wait(-1);
|
|
302
|
+
context.halt();
|
|
303
|
+
listen(true);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function release() {
|
|
308
|
+
pressed = false;
|
|
309
|
+
listen();
|
|
310
|
+
if (!context.dragging()) {
|
|
311
|
+
wait();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
287
315
|
return control;
|
|
288
316
|
}
|
package/src/scripts/carousel.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* It returns nothing if its option is off, or an object with remove(). remove() removes all that the feature added.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { alignOffset, clamp, compute, inView, nearestSnap, physicalSnap, progress, snapIndex, snapOfSlide, snapPosition, targetLocation } from './geometry.js';
|
|
8
|
+
import { abs, alignOffset, clamp, compute, floor, inView, nearestSnap, physicalSnap, progress, round, 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,11 +113,11 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
111
113
|
|
|
112
114
|
const api = {
|
|
113
115
|
goToSnap: (index, instant) => go(physical(index), instant),
|
|
114
|
-
goToNext: (instant) =>
|
|
115
|
-
goToPrev: (instant) =>
|
|
116
|
+
goToNext: (instant) => advance(1, instant),
|
|
117
|
+
goToPrev: (instant) => advance(-1, instant),
|
|
116
118
|
goToSlide: (index, instant) => go(physical(api.snapOfSlide(index)), instant, index),
|
|
117
|
-
canGoToNext: () =>
|
|
118
|
-
canGoToPrev: () =>
|
|
119
|
+
canGoToNext: () => can(1),
|
|
120
|
+
canGoToPrev: () => can(-1),
|
|
119
121
|
selectedSnap: () => logical(selected),
|
|
120
122
|
previousSnap: () => logical(previous),
|
|
121
123
|
selectedSlide,
|
|
@@ -143,7 +145,7 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
143
145
|
each = { node: null, index: 0, offset: 0, distance: 0, size: 0, visible: 0 },
|
|
144
146
|
/**
|
|
145
147
|
* 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.
|
|
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.
|
|
147
149
|
*/
|
|
148
150
|
context = {
|
|
149
151
|
api,
|
|
@@ -321,6 +323,8 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
321
323
|
resolved = null;
|
|
322
324
|
}
|
|
323
325
|
const keep = geo ? selectedSlide() : requested;
|
|
326
|
+
// 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() };
|
|
324
328
|
teardown(true);
|
|
325
329
|
setup();
|
|
326
330
|
requested = keep;
|
|
@@ -342,6 +346,27 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
342
346
|
nodes = slides.concat(clones);
|
|
343
347
|
written.slides.length = slides.length;
|
|
344
348
|
mutationObserver?.takeRecords();
|
|
349
|
+
|
|
350
|
+
copyObserver?.disconnect();
|
|
351
|
+
if (clones.length) {
|
|
352
|
+
copyObserver ||= new MutationObserver(onCopy);
|
|
353
|
+
slides.forEach((node) => copyObserver.observe(node, { childList: true, characterData: true, subtree: true, attributeFilter: ['class', 'src', 'srcset', 'href', 'value'] }));
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
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.
|
|
359
|
+
*
|
|
360
|
+
* @param {MutationRecord[]} records
|
|
361
|
+
*/
|
|
362
|
+
function onCopy(records) {
|
|
363
|
+
slides.forEach((node, index) => {
|
|
364
|
+
if (records.some(({ type, target }) => node.contains(target) && (type !== 'attributes' || target !== node))) {
|
|
365
|
+
for (let item = index; item < clones.length; item += slides.length) {
|
|
366
|
+
copyContent(clones[item], node);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
});
|
|
345
370
|
}
|
|
346
371
|
|
|
347
372
|
/**
|
|
@@ -371,8 +396,15 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
371
396
|
return same && options.autoHeight && geo?.axis === 'x';
|
|
372
397
|
}
|
|
373
398
|
|
|
399
|
+
// Keep the selected slide. If the page removed it, select the slide that is now at its index, or the last slide.
|
|
374
400
|
function onMutation() {
|
|
401
|
+
const old = ready ? selectedSlide() : -1,
|
|
402
|
+
node = slides[old];
|
|
375
403
|
slides = readSlides(container, options.slides);
|
|
404
|
+
if (old > -1) {
|
|
405
|
+
const index = slides.indexOf(node);
|
|
406
|
+
requested = index > -1 ? index : Math.min(old, slides.length - 1);
|
|
407
|
+
}
|
|
376
408
|
setClones(0);
|
|
377
409
|
nodes = slides;
|
|
378
410
|
changed = true;
|
|
@@ -425,17 +457,18 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
425
457
|
// With clones: 'fill', the loop fills the window
|
|
426
458
|
lastWindow = options.loop && options.clones === 'fill' ? windowSize(layout.axis) : 0;
|
|
427
459
|
|
|
428
|
-
const area = visibleArea(viewport, layout, rects.view, lastWindow),
|
|
460
|
+
const area = visibleArea(viewport, layout, rects.view, rects.pad, lastWindow),
|
|
429
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])];
|
|
430
462
|
|
|
431
463
|
// 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.
|
|
432
|
-
if (ready && values.length === signature.length && values.every((value, index) => value === signature[index] ||
|
|
464
|
+
if (ready && values.length === signature.length && values.every((value, index) => value === signature[index] || abs(value - signature[index]) < 0.5)) {
|
|
433
465
|
return false;
|
|
434
466
|
}
|
|
435
467
|
|
|
436
468
|
signature = values;
|
|
437
469
|
|
|
438
|
-
|
|
470
|
+
// After a change of the slides, onMutation() gives the slide to keep
|
|
471
|
+
const keep = ready && !changed ? selectedSlide() : requested,
|
|
439
472
|
next = compute(layout, rects, area, slides.length, options);
|
|
440
473
|
|
|
441
474
|
if (!next.snaps) {
|
|
@@ -447,8 +480,9 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
447
480
|
|
|
448
481
|
const total = geo.snaps.length;
|
|
449
482
|
|
|
450
|
-
// Before the first measure pass, selected is the logical snap of the startSnap option or of
|
|
451
|
-
|
|
483
|
+
// Before the first measure pass, selected is the logical snap of the startSnap option, of goToSnap() or of goToNext().
|
|
484
|
+
// In loop mode, a step before the first snap goes to the last snap.
|
|
485
|
+
selected = keep >= 0 ? physical(api.snapOfSlide(keep)) : Math.min(total - 1, ready ? selected : physical(snapIndex(selected, geo.logical.length, geo.period)));
|
|
452
486
|
previous = Math.min(previous, total - 1);
|
|
453
487
|
requested = keep;
|
|
454
488
|
if (!dragging) {
|
|
@@ -555,7 +589,7 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
555
589
|
*/
|
|
556
590
|
function screen(value) {
|
|
557
591
|
const scale = devicePixelRatio || 1;
|
|
558
|
-
return
|
|
592
|
+
return round(value * scale) / scale * geo.sign;
|
|
559
593
|
}
|
|
560
594
|
|
|
561
595
|
/**
|
|
@@ -599,7 +633,7 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
599
633
|
root.style.setProperty('--better-progress', progress(at, geo));
|
|
600
634
|
} else if (options.progress) {
|
|
601
635
|
const value = snapPosition(geo.snaps, at, geo.period),
|
|
602
|
-
snap =
|
|
636
|
+
snap = floor(value);
|
|
603
637
|
whole.progress = progress(at, geo);
|
|
604
638
|
whole.snap = logical(snap) + value - snap;
|
|
605
639
|
options.progress(whole, api);
|
|
@@ -652,6 +686,30 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
652
686
|
return translate(screen(value)) || '0px';
|
|
653
687
|
}
|
|
654
688
|
|
|
689
|
+
/**
|
|
690
|
+
* Find if the carousel can go one snap in a direction.
|
|
691
|
+
*
|
|
692
|
+
* @param {number} direction 1 or -1.
|
|
693
|
+
* @returns {boolean}
|
|
694
|
+
*/
|
|
695
|
+
function can(direction) {
|
|
696
|
+
return !!geo && !geo.fit && (!!geo.period || (direction > 0 ? selected < geo.snaps.length - 1 : selected > 0));
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Go one snap in a direction, if the carousel can. Before the first measure pass, keep the step in the selected snap.
|
|
701
|
+
*
|
|
702
|
+
* @param {number} direction 1 or -1.
|
|
703
|
+
* @param {boolean} [instant]
|
|
704
|
+
*/
|
|
705
|
+
function advance(direction, instant) {
|
|
706
|
+
if (!geo) {
|
|
707
|
+
go(selected + direction, instant);
|
|
708
|
+
} else if (can(direction)) {
|
|
709
|
+
step(selected, direction, instant);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
|
|
655
713
|
/**
|
|
656
714
|
* Go to the snap after a snap in a direction. In loop mode, the first snap follows the last snap.
|
|
657
715
|
*
|
|
@@ -683,7 +741,7 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
683
741
|
}
|
|
684
742
|
|
|
685
743
|
const target = targetLocation(geo.snaps[index].location, current(), geo.period, direction),
|
|
686
|
-
span =
|
|
744
|
+
span = abs(index - selected),
|
|
687
745
|
count = geo.period ? Math.min(span, geo.snaps.length - span) : span;
|
|
688
746
|
|
|
689
747
|
move(index, target, instant ? 0 : snapDuration(options.duration, count), EASE);
|
|
@@ -700,7 +758,7 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
700
758
|
function move(index, target, duration, curve) {
|
|
701
759
|
const from = halt(),
|
|
702
760
|
picked = select(index),
|
|
703
|
-
jump = !duration || geo.fit ||
|
|
761
|
+
jump = !duration || geo.fit || abs(target - from) < 0.5;
|
|
704
762
|
|
|
705
763
|
location = target;
|
|
706
764
|
|
|
@@ -740,10 +798,10 @@ export default function carousel(element, userOptions, defaults, features) {
|
|
|
740
798
|
// Start in the first period, so that the location does not grow after each pause
|
|
741
799
|
location = normalize(from, geo.period);
|
|
742
800
|
motion.loop(location, direction, geo.period / speed, geo, nodes);
|
|
743
|
-
} else if (
|
|
801
|
+
} else if (abs(to - from) > 1) {
|
|
744
802
|
free = true;
|
|
745
803
|
location = to;
|
|
746
|
-
motion.run(from, to,
|
|
804
|
+
motion.run(from, to, abs(to - from) / speed, [0, 0, 1, 1], events.has('scroll'));
|
|
747
805
|
}
|
|
748
806
|
}
|
|
749
807
|
|