UNPKG

@fancyapps/ui

Version:

Robust JavaScript UI Component Library

3 lines (2 loc) • 21.9 kB
/*! License details at fancyapps.com/license */ import{isPlainObject as t}from"../utils/isPlainObject.js";import{isNode as e}from"../utils/isNode.js";import{isString as n}from"../utils/isString.js";import{getScrollableParent as i}from"../utils/getScrollableParent.js";import{getDirectChildren as o}from"../utils/getDirectChildren.js";import{extend as s}from"../utils/extend.js";import{map as r}from"../utils/map.js";import{stringToHtml as l}from"../utils/strToHtml.js";import{clamp as a}from"../utils/clamp.js";import{addClass as c}from"../utils/addClass.js";import{removeClass as f}from"../utils/removeClass.js";import{toggleClass as u}from"../utils/toggleClass.js";import{Tween as d}from"../libs/tween.js";import{Gestures as p,isTouchEvent as m}from"../libs/gestures.js";import{en_EN as g}from"./l10n/en_EN.js";export{CarouselSlideContentState,CarouselState}from"./carousel.state.js";const h=t=>{t.cancelable&&t.preventDefault()},v={adaptiveHeight:!1,center:!0,classes:{container:"f-carousel",isEnabled:"is-enabled",isLTR:"is-ltr",isRTL:"is-rtl",isHorizontal:"is-horizontal",isVertical:"is-vertical",hasAdaptiveHeight:"has-adaptive-height",viewport:"f-carousel__viewport",slide:"f-carousel__slide",isSelected:"is-selected"},dragFree:!1,enabled:!0,errorTpl:'<div class="f-html">{{ERROR}}</div>',fill:!0,infinite:!0,initialPage:0,l10n:g,rtl:!1,slides:[],slidesPerPage:"auto",spinnerTpl:'<div class="f-spinner"></div>',transition:"fade",tween:{clamp:!0,mass:1,tension:160,friction:25,restDelta:1,restSpeed:1,velocity:0},vertical:!1};let b,y,E=0;const x=t=>document.getElementById(`${t.split("#").pop()}`),M=(g,w={},S={})=>{E++;let A,L,P,T,j,R=0,C={...v},H={...v},V={},O=null,$=null,D=0,I=0,q=0,k=!1,F=!1,z=!1,B="height",N=0,_=!0,G=0,X=0,Y=0,W=0,J="*",K=[],Q=[];const U=new Set;let Z=[],tt=[],et=0,nt=0,it=0;function ot(t,...e){let n=H[t];return n&&n instanceof Function?n(zt,...e):n}function st(t,e=[]){const n=ot("l10n")||{};t=String(t).replace(/\{\{(\w+)\}\}/g,(t,e)=>n[e]||t);for(let n=0;n<e.length;n++)t=t.split(e[n][0]).join(e[n][1]);return t=t.replace(/\{\{(.*?)\}\}/g,(t,e)=>e)}const rt=new Map;function lt(t,...e){const n=[...rt.get(t)||[]];H.on&&n.push(H.on[t]);for(const t of n)t&&t instanceof Function&&t(zt,...e);"click"===t&&Ct(e[0]),"*"!==t&&lt("*",t,...e)}function at(){const e=s({},v,C);let n="";const i=C.breakpoints||{};for(const[t,o]of Object.entries(i))window.matchMedia(t).matches&&(n+=t,s(e,o));if(void 0===j||n!==j){if(j=n,0!==R){let t=tt[G]?.slides[0]?.index;void 0===t&&(t=H.initialSlide),e.initialSlide=t,e.slides=[];for(const t of K)t.isVirtual&&e.slides.push(t)}qt(),H=e,!1!==ot("enabled")&&(R=0,lt("init"),function(){for(const[t,e]of Object.entries({...S,...H.plugins||{}}))if(t&&!V[t]&&e instanceof Function){const n=e();n.init(zt,M),V[t]=n}lt("initPlugins")}(),function(){if(!O)return;const e=ot("classes")||{};c(O,e.container);const n=ot("style");if(n&&t(n))for(const[t,e]of Object.entries(n))O.style.setProperty(t,e);$=Array.from(O.querySelectorAll(`.${e.viewport}`)).filter(t=>t.closest(`.${e.container}`)===O).pop()||null,$||($=document.createElement("div"),c($,e.viewport),$.append(...o(O,`.${e.slide}`)),O.insertAdjacentElement("afterbegin",$)),O.carousel=zt,lt("initLayout")}(),function(){if(!$)return;const t=ot("classes")||{};K=[],[...o($,`.${t.slide}`)].forEach(t=>{if(t.parentElement){const e=xt({el:t,isVirtual:!1,...t.dataset||{}});lt("createSlide",e),K.push(e)}}),At();for(const t of K)lt("addSlide",t);Et(ot("slides"));for(const t of K){const e=t.el;e?.parentElement===$&&(c(e,H.classes.slide),c(e,t.class),Ot(t),lt("attachSlideEl",t))}lt("initSlides")}(),Lt(),R=1,c(O,(ot("classes")||{}).isEnabled||""),It(),pt(),L=d().on("start",()=>{A&&A.isPointerDown()||(dt(),It())}).on("step",t=>{const e=N;N=t.pos,N!==e&&(_=!1,It())}).on("end",t=>{A?.isPointerDown()||(N=t.pos,L&&!k&&(N<Y||N>W)?L.spring({clamp:!0,mass:1,tension:200,friction:25,velocity:0,restDelta:1,restSpeed:1}).from({pos:N}).to({pos:a(Y,N,W)}).start():_||(_=!0,lt("settle")))}),ft(),function(){if(!O||!$)return;O.addEventListener("click",Rt),document.addEventListener("mousemove",ct),y||(y=function(t){const e=t.target;if(!(e instanceof Element))return;const n=e.closest("[data-carousel-target]"),i=n?.dataset?.carouselTarget;if(i){const e=x(i),n=e?.carousel;n?.emit("click",t)}},document.addEventListener("click",y));const t=$.getBoundingClientRect();if(et=t.height,nt=t.width,!P){let t=null;P=new ResizeObserver(()=>{t||(t=requestAnimationFrame(()=>{!function(){if(1!==R||!$)return;const t=tt.length,e=$.getBoundingClientRect(),n=e.height,i=e.width;t>1&&(z&&Math.abs(n-et)<.5||!z&&Math.abs(i-nt)<.5)||(Lt(),ft(),et=n,nt=i,z&&!et||!z&&!nt||O&&$&&(t===tt.length&&A?.isPointerDown()||(ot("dragFree")&&(k||N>Y&&N<W)?(dt(),It()):$t(G,{transition:!1}))))}(),t=null}))}),P.observe($)}}(),lt("ready"))}}function ct(t){b=t}function ft(){!1===ot("gestures")?A&&(A.destroy(),A=void 0):A||function(){const t=ot("gestures");!A&&!1!==t&&$&&(A=p($,t).on("start",t=>{if(!L)return;if(!1===ot("gestures",t))return;const{srcEvent:e}=t;z&&m(e)&&!i(e.target)&&h(e),L.pause(),L.getCurrentVelocities().pos=0;const n=tt[G]?.slides[0],o=n?.el;n&&U.has(n.index)&&o&&(N=n.offset||0,N+=(function(t){const e=window.getComputedStyle(t),n=new DOMMatrixReadOnly(e.transform);return{width:n.m41||0,height:n.m42||0}}(o)[B]||0)*(F&&!z?1:-1)),Tt(),k||(N<Y||N>W)&&L.spring({clamp:!0,mass:1,tension:500,friction:25,velocity:L.getCurrentVelocities()?.pos||0,restDelta:1,restSpeed:1}).from({pos:N}).to({pos:a(Y,N,W)}).start()}).on("move",t=>{if(!1===ot("gestures",t))return;const{srcEvent:e,axis:n,deltaX:o,deltaY:s}=t;if(m(e)&&e.touches?.length>1)return;const r=e.target,l=i(r),a=l?l.scrollHeight>l.clientHeight?"y":"x":void 0;if(l&&l!==$&&(!n||n===a))return;if(!n)return h(e),e.stopPropagation(),void e.stopImmediatePropagation();if("y"===n&&!z||"x"===n&&z)return;if(h(e),e.stopPropagation(),!L)return;const c=F&&!z?1:-1,f=z?s:o;let u=L?.isRunning()?L.getEndValues().pos:N,d=1;k||(u<=Y&&f*c<0?(d=Math.max(.01,1-(Math.abs(1/vt()*Math.abs(u-Y))||0)),d*=.2):u>=W&&f*c>0&&(d=Math.max(.01,1-(Math.abs(1/vt()*Math.abs(u-W))||0)),d*=.2)),u+=f*d*c,L.spring({clamp:!0,mass:1,tension:700,friction:25,velocity:L.getCurrentVelocities()?.pos||0,restDelta:1,restSpeed:1}).from({pos:N}).to({pos:u}).start()}).on("panstart",t=>{!1!==ot("gestures",t)&&t?.axis===(z?"y":"x")&&c($,"is-dragging")}).on("panend",t=>{!1!==ot("gestures",t)&&f($,"is-dragging")}).on("end",t=>{if(!1===ot("gestures",t))return;const{srcEvent:e,axis:n,velocityX:o,velocityY:s,currentTouch:r}=t;if(r.length>0||!L)return;const l=e.target,c=i(l),f=c?c.scrollHeight>c.clientHeight?"y":"x":void 0,u=c&&(!n||n===f);z&&m(e)&&!n&&Rt(e);const d=tt.length,p=ot("dragFree");if(!d)return;let g=u?0:ot("vertical")?s:o;n!==(z?"y":"x")&&(g=0);let h=L?.isRunning()?L.getEndValues().pos:N;const v=F&&!z?1:-1;if(u||(h+=g*(p?5:1)*v),!k&&(g*v<=0&&h<Y||g*v>=0&&h>W)){let t=0;return Math.abs(g)>0&&(t=2*Math.abs(g),t=Math.min(.3*vt(),t)),h=a(Y+-1*t,h,W+t),void L.spring({clamp:!0,mass:1,tension:380,friction:25,velocity:-1*g,restDelta:1,restSpeed:1}).from({pos:N}).to({pos:h}).start()}if(p||V.Autoscroll?.isEnabled())return void(Math.abs(g)>10?L.spring({clamp:!0,mass:1,tension:150,friction:25,velocity:-1*g,restDelta:1,restSpeed:1}).from({pos:N}).to({pos:h}).start():L.isRunning()||_||(_=!0,lt("settle")));if(!p&&!V.Autoscroll?.isEnabled()&&(!t.offsetX&&!t.offsetY||"y"===n&&!z||"x"===n&&z))return void $t(G,{transition:"tween"});let b=gt(h);Math.abs(g)>10&&b===G&&(b+=g>0?F&&!z?1:-1:F&&!z?-1:1),$t(b,{transition:"tween",tween:{velocity:-1*g}})}).init())}(),u($,"is-draggable",!!A&&tt.length>0)}function ut(t="*"){const e=[];for(const n of K)("*"===t||n.class&&n.class.includes(t)||n.el&&n.el?.classList.contains(t))&&e.push(n);T=void 0,J=t,Q=[...e]}function dt(){if(!L)return;const t=gt(L?.isRunning()?L.getEndValues().pos:N);t!==G&&(T=G,G=t,Ot(),pt(),mt(),lt("change",G,T))}function pt(){if(!O)return;for(const t of O.querySelectorAll("[data-carousel-index]"))t.innerHTML=G+"";for(const t of O.querySelectorAll("[data-carousel-page]"))t.innerHTML=G+1+"";for(const t of O.querySelectorAll("[data-carousel-pages]"))t.innerHTML=tt.length+"";const t=ot("classes")||{},e=Array.from(O.querySelectorAll("[data-carousel-go-to]")).filter(e=>e.closest(`.${t.container}`)===O);for(const t of e){parseInt(t.dataset?.carouselGoTo||"-1",10)===G?t.setAttribute("aria-current","true"):t.removeAttribute("aria-current")}for(const t of O.querySelectorAll("[data-carousel-go-prev]"))t.toggleAttribute("aria-disabled",!kt()),kt()?t.removeAttribute("tabindex"):t.setAttribute("tabindex","-1");for(const t of O.querySelectorAll("[data-carousel-go-next]"))t.toggleAttribute("aria-disabled",!Ft()),Ft()?t.removeAttribute("tabindex"):t.setAttribute("tabindex","-1");let n=!1;const i=tt[G]?.slides[0];i&&(i.downloadSrc||"image"===i.type&&i.src)&&(n=!0);for(const t of O.querySelectorAll("[data-carousel-download]"))t.toggleAttribute("aria-disabled",!n)}function mt(t){t||(t=tt[G]?.slides[0]);const e=t?.el;if(e)for(const n of e.querySelectorAll("[data-slide-index]"))n.innerHTML=t.index+1+""}function gt(t){if(!tt.length)return 0;const e=bt();let n=t;k?n-=Math.floor((t-tt[0]?.pos)/e)*e||0:n=a(tt[0]?.pos,t,tt[tt.length-1]?.pos);const i=new Map;let o=0;for(const t of tt){const s=Math.abs(t.pos-n),r=Math.abs(t.pos-n-e),l=Math.abs(t.pos-n+e),a=Math.min(s,r,l);i.set(o,a),o++}const s=i.size>0?[...i.entries()].reduce((t,e)=>e[1]<t[1]?e:t):[G,0];return parseInt(s[0])}function ht(){return it}function vt(){return D}function bt(t=!0){return Q.length?Q.reduce((t,e)=>t+e.dim,0)+(Q.length-(k&&t?0:1))*it:0}function yt(t){const e=bt(),n=vt();if(!e||!$||!n)return[];const i=[];t=void 0===t?N:t,k&&(t-=Math.floor(t/e)*e||0);let o=0;for(let s of Q){const r=(e=0)=>{i.indexOf(s)>-1||(s.pos=o-t+e||0,s.offset+e>t-s.dim-I+.51&&s.offset+e<t+n+q-.51&&i.push(s))};s.offset=o,k&&(r(e),r(-1*e)),r(),o+=s.dim+it}return i}function Et(t,e){const n=[];for(const e of Array.isArray(t)?t:[t]){const t=xt({...e,isVirtual:!0});t.el||(t.el=document.createElement("div")),lt("createSlide",t),n.push(t)}K.splice(void 0===e?K.length:e,0,...n),At();for(const t of n)lt("addSlide",t),Mt(t);return ut(J),n}function xt(t){return(n(t)||t instanceof HTMLElement)&&(t={html:t}),{index:-1,el:void 0,class:"",isVirtual:!0,dim:0,pos:0,offset:0,html:"",src:"",...t}}function Mt(t){let e=t.el;if(!t||!e)return;const n=t.html?t.html instanceof HTMLElement?t.html:l(t.html):void 0;n&&(c(n,"f-html"),t.htmlEl=n,c(e,"has-html"),e.append(n),lt("contentReady",t))}function wt(t){if(!$||!t)return;let e=t.el;if(e){if(e.setAttribute("index",t.index+""),e.parentElement!==$){let n;c(e,H.classes.slide),c(e,t.class),Ot(t);for(const e of K)if(e.index>t.index){n=e.el;break}$.insertBefore(e,n&&$.contains(n)?n:null),lt("attachSlideEl",t)}return mt(t),e}}function St(t){const e=t?.el;e&&(e.remove(),Pt(e),lt("detachSlideEl",t))}function At(){for(let t=0;t<K.length;t++){const e=K[t],n=e.el;n&&(e.index!==t&&Pt(n),n.setAttribute("index",`${t}`)),e.index=t}}function Lt(){if(!O||!$)return;F=ot("rtl"),z=ot("vertical"),B=z?"height":"width";const t=ot("classes");if(u(O,t.isLTR,!F),u(O,t.isRTL,F),u(O,t.isHorizontal,!z),u(O,t.isVertical,z),u(O,t.hasAdaptiveHeight,ot("adaptiveHeight")),D=0,I=0,q=0,it=0,$){$.childElementCount||($.style.display="grid");const t=$.getBoundingClientRect();D=$.getBoundingClientRect()[B]||0;const e=window.getComputedStyle($);it=parseFloat(e.getPropertyValue("--f-carousel-gap"))||0;"visible"===e.getPropertyValue("overflow-"+(z?"y":"x"))&&(I=Math.abs(t[z?"top":"left"]),q=Math.abs(window[z?"innerHeight":"innerWidth"]-t[z?"bottom":"right"])),$.style.display=""}if(!D)return;const n=function(){let t=0;if($){let e=document.createElement("div");e.style.display="block",c(e,H.classes.slide),$.appendChild(e),t=e.getBoundingClientRect()[B],e.remove(),e=void 0}return t}();for(const t of Q){const i=t.el;let o=0;if(!t.isVirtual&&i&&e(i)){let t=!1;i.parentElement&&i.parentElement===$||($.appendChild(i),t=!0),o=i.getBoundingClientRect()[B],t&&i.parentElement?.removeChild(i)}else o=n;t.dim=o}if(k=!1,ot("infinite")){k=!0;const t=bt();let e=D+I+q;for(let n=0;n<Q.length;n++){const i=Q[n]?.dim+it;if(t-i<e&&t-i-e<i){k=!1;break}}}!function(){if(!O)return;const t=vt(),e=bt(!1);let n=ot("slidesPerPage");n="auto"===n?1/0:parseFloat(n+""),tt=[];let i=0,o=0;for(const e of Q)(!tt.length||i+e.dim-t>.05||o>=n)&&(tt.push({index:tt.length,slides:[],dim:0,offset:0,pos:0}),i=0,o=0),tt[tt.length-1]?.slides.push(e),i+=e.dim+it,o++;const s=ot("center"),r=ot("fill");let l=0;for(const n of tt){n.dim=(n.slides.length-1)*it;for(const t of n.slides)n.dim+=t.dim;n.offset=l,n.pos=l,!1!==s&&(n.pos-=.5*(t-n.dim)),r&&!k&&e>t&&(n.pos=a(0,n.pos,e-t)),l+=n.dim+it}const c=[];let f;for(const t of tt){const e={...t};f&&Math.abs(e.pos-f.pos)<.1?(f.dim+=e.dim,f.slides=[...f.slides,...e.slides]):(f=e,e.index=c.length,c.push(e))}tt=c,G=a(0,G,tt.length-1)}(),Y=tt[0]?.pos||0,W=tt[tt.length-1]?.pos||0,0===R?function(){T=void 0,G=ot("initialPage");const t=ot("initialSlide")||void 0;void 0!==t&&(G=zt.getPageIndex(t)||0),G=a(0,G,tt.length-1),N=tt[G]?.pos||0,X=N}():X=tt[G||0]?.pos||0,lt("refresh"),pt()}function Pt(t){if(!t||!e(t))return;const n=parseInt(t.getAttribute("index")||"-1");let i="";for(const e of Array.from(t.classList)){const t=e.match(/^f-(\w+)(Out|In)$/);t&&t[1]&&(i=t[1]+"")}if(!t||!i)return;const o=[`f-${i}Out`,`f-${i}In`,"to-prev","to-next","from-prev","from-next"];t.removeEventListener("animationend",jt),f(t,o.join(" ")),U.delete(n)}function Tt(){if(!$)return;const t=U.size>0;for(const t of Q)Pt(t.el);U.clear(),t&&It()}function jt(t){"f-"===t.animationName?.substring(0,2)&&(Pt(t.target),U.size||(f(O,"in-transition"),!_&&Math.abs(zt.getPosition(!0)-X)<.5&&(_=!0,lt("settle"))),It())}function Rt(t){Ct(t),lt("click",t)}function Ct(t){if(t.defaultPrevented)return;const e=t.composedPath()[0],n=e.closest("[data-carousel-target]"),i=n?.dataset?.carouselTarget;if(i){if(x(i)!==O)return}if(e.closest("[data-carousel-go-prev]"))return h(t),void zt.prev();if(e.closest("[data-carousel-go-next]"))return h(t),void zt.next();const o=e.closest("[data-carousel-go-to]");if(o)return h(t),void zt.goTo(parseFloat(o.dataset.carouselGoTo||"")||0);if(e.closest("[data-carousel-download]")){h(t);const e=tt[G]?.slides[0];if(e&&(e.downloadSrc||"image"===e.type&&e.src)){const t=e.downloadFilename,n=document.createElement("a"),i=e.downloadSrc||e.src||"";n.href=i,n.target="_blank",n.download=t||i,n.click()}return}}function Ht(t){const e=t.el;e&&e.querySelector(".f-spinner")?.remove()}function Vt(t){const e=t.el;e&&(e.querySelector(".f-html.is-error")?.remove(),f(e,"has-error"))}function Ot(t){t||(t=tt[G]?.slides[0]);const e=t?.el;if(!e)return;let i=ot("formatCaption",t);void 0===i&&(i=t.caption),i=i||"";const o=ot("captionEl");if(o&&o instanceof HTMLElement){if(t.index!==G)return;if(n(i)&&(o.innerHTML=st(i+"")),i instanceof HTMLElement){if(i.parentElement===o)return;o.innerHTML="",i.parentElement&&(i=i.cloneNode(!0)),o.append(i)}return}if(!i)return;let s=t.captionEl||e.querySelector(".f-caption");!s&&i instanceof HTMLElement&&i.classList.contains("f-caption")&&(s=i),s||(s=document.createElement("div"),c(s,"f-caption"),n(i)?s.innerHTML=st(i+""):i instanceof HTMLElement&&(i.parentElement&&(i=i.cloneNode(!0)),s.append(i)));const r=`f-caption-${E}_${t.index}`;s.setAttribute("id",r),s.dataset.selectable="true",c(e,"has-caption"),e.setAttribute("aria-labelledby",r),t.captionEl=s,e.insertAdjacentElement("beforeend",s)}function $t(e,i={}){let{transition:o,tween:r}={transition:H.transition,tween:H.tween,...i||{}};if(!O||!L)return;const l=tt.length;if(!l)return;if(function(t,e){if(!(O&&D&&L&&e&&n(e)&&"tween"!==e))return!1;for(const t of Z)if(D-t.dim>.5)return!1;if(I>.5||q>.5)return;const i=tt.length;let o=t>G?1:-1;t=k?(t%i+i)%i:a(0,t,i-1),F&&(o*=-1);const s=tt[G]?.slides[0],r=s?.index,l=tt[t]?.slides[0],u=l?.index,d=tt[t]?.pos;if(void 0===u||void 0===r||r===u||N===d||Math.abs(D-(l?.dim||0))>1)return!1;_=!1,L.pause(),Tt(),c(O,"in-transition"),N=X=d;const p=wt(s),m=wt(l);return dt(),p&&(U.add(r),p.style.transform="",p.addEventListener("animationend",jt),f(p,H.classes.isSelected),p.inert=!1,c(p,`f-${e}Out to-${o>0?"next":"prev"}`)),m&&(U.add(u),m.style.transform="",m.addEventListener("animationend",jt),c(m,H.classes.isSelected),m.inert=!1,c(m,`f-${e}In from-${o>0?"prev":"next"}`)),It(),!0}(e,o))return;e=k?(e%l+l)%l:a(0,e,l-1);const u=tt[e||0]?.pos||0;X=u;const d=L.isRunning()?L.getEndValues().pos:N;if(Math.abs(X-d)<1)return N=X,G!==e&&(Ot(),T=G,G=e,pt(),mt(),lt("change",G,T)),It(),void(_||(_=!0,lt("settle")));if(L.pause(),Tt(),k){const t=bt(),e=Math.floor((d-tt[0]?.pos)/t)||0,n=X+e*t;X=[n+t,n,n-t].reduce(function(t,e){return Math.abs(e-d)<Math.abs(t-d)?e:t})}!1!==o&&t(r)?L.spring(s({},H.tween,r)).from({pos:N}).to({pos:X}).start():(N=X,dt(),It(),_||(_=!0,lt("settle")))}function Dt(t){let e=N;if(k&&!0!==t){const t=bt();e-=(Math.floor((N-tt[0]?.pos||0)/t)||0)*t}return e}function It(){if(!O||!$)return;Z=yt();const t=new Set,e=[],n=tt[G],i=H.setTransform;let s;for(const i of Q){const o=U.has(i.index),r=Z.indexOf(i)>-1,l=n?.slides?.indexOf(i)>-1;if(i.isVirtual&&!o&&!r)continue;let a=wt(i);if(a&&(e.push(i),l&&t.add(a),ot("adaptiveHeight")&&l)){const t=(a.lastElementChild||a).getBoundingClientRect().height;s=null==s?t:Math.max(s,t)}}$&&s&&($.style.height=`${s}px`),[...o($,`.${H.classes.slide}`)].forEach(e=>{u(e,H.classes.isSelected,t.has(e));const n=K[parseInt(e.getAttribute("index")||"-1")];if(!n)return e.remove(),void Pt(e);const o=U.has(n.index),s=Z.indexOf(n)>-1;if(n.isVirtual&&!o&&!s)return void St(n);if(e.inert=!s,!1===i)return;let l=n.pos?Math.round(1e4*n.pos)/1e4:0,a=0,c=0,f=0,d=0;o||(a=z?0:F?-1*l:l,c=z?l:0,f=r(a,0,n.dim,0,100),d=r(c,0,n.dim,0,100)),i instanceof Function&&!o?i(zt,n,{x:a,y:c,xPercent:f,yPercent:d}):e.style.transform=a||c?`translate3d(${f}%, ${d}%,0)`:""}),lt("render",e)}function qt(){O?.removeEventListener("click",Rt),document.removeEventListener("mousemove",ct),U.clear(),P?.disconnect(),P=void 0;for(const t of K){let n=t.el;n&&e(n)&&(t.state=void 0,Ht(t),Vt(t),t.isVirtual?(St(t),t.el=void 0):(Pt(n),n.style.transform="",$&&!$.contains(n)&&$.appendChild(n)))}for(const t of Object.values(V))t?.destroy();V={},A?.destroy(),A=void 0,L?.destroy(),L=void 0;for(const[t,e]of Object.entries(H.classes||{}))"container"!==t&&f(O,e);f($,"is-draggable")}function kt(){return k||G>0}function Ft(){return k||G<tt.length-1}const zt={add:function(t,e){let n=N;const i=G,o=bt(),s=L?.isRunning()?L.getEndValues().pos:N,r=o&&Math.floor((s-(tt[0]?.pos||0))/o)||0;return Et(t,e),ut(J),Lt(),L&&o&&(i===G&&(n-=r*o),n===X?N=X:L.spring({clamp:!0,mass:1,tension:300,friction:25,restDelta:1,restSpeed:1}).from({pos:n}).to({pos:X}).start()),It(),zt},canGoPrev:kt,canGoNext:Ft,destroy:function(){return lt("destroy"),window.removeEventListener("resize",at),qt(),rt.clear(),O=null,tt=[],K=[],H={...v},V={},Q=[],j=void 0,J="*",R=2,zt},emit:lt,filter:function(t="*"){return ut(t),Lt(),N=a(Y,N,W),It(),lt("filter",t),zt},getContainer:function(){return O},getGapDim:ht,getGestures:function(){return A},getLastMouseMove:function(){return b},getOption:function(t){return ot(t)},getOptions:function(){return H},getPage:function(){return tt[G]},getPageIndex:function(t){if(void 0!==t){for(const e of tt||[])for(const n of e.slides)if(n.index===t)return e.index;return-1}return G},getPageIndexFromPosition:gt,getPageProgress:function(t,e){void 0===t&&(t=G);const n=tt[t];if(!n)return t>G?-1:1;const i=bt(),o=ht();let s=n.pos,r=Dt();if(k&&!0!==e){const t=Math.floor((r-tt[0]?.pos)/i)||0;r-=t*i,s=[s+i,s,s-i].reduce(function(t,e){return Math.abs(e-r)<Math.abs(t-r)?e:t})}return(r-s)/(n.dim+o)||0},getPageVisibility:function(t){void 0===t&&(t=G);const e=tt[t];if(!e)return t>G?-1:1;const n=Dt(),i=vt();let o=e.pos;if(k){const t=bt(),e=o+(Math.floor((n-tt[0]?.pos)/t)||0)*t;o=[e+t,e,e-t].reduce(function(t,e){return Math.abs(e-n)<Math.abs(t-n)?e:t})}return o>n&&o+e.dim<n+i?1:o<n?(o+e.dim-n)/e.dim||0:o+e.dim>n+i&&(n+i-o)/e.dim||0},getPages:function(){return tt},getPlugins:function(){return V},getPosition:Dt,getSlides:function(){return K},getState:function(){return R},getTotalSlideDim:bt,getTween:function(){return L},getViewport:function(){return $},getViewportDim:vt,getVisibleSlides:function(t){return void 0===t?Z:yt(t)},goTo:$t,hasNavigated:function(){return void 0!==T},hideError:Vt,hideLoading:Ht,init:function(){if(!g||!e(g))throw new Error("No Element found");return 0!==R&&(qt(),R=0),O=g,C=w,window.removeEventListener("resize",at),C.breakpoints&&window.addEventListener("resize",at),at(),zt},isInfinite:function(){return k},isInTransition:function(){return U.size>0},isRTL:function(){return F},isSettled:function(){return _},isVertical:function(){return z},localize:st,next:function(t={}){return $t(G+1,t),zt},off:function(t,e){for(const n of t instanceof Array?t:[t])rt.has(n)&&rt.set(n,rt.get(n).filter(t=>t!==e));return zt},on:function(t,e){for(const n of t instanceof Array?t:[t])rt.set(n,[...rt.get(n)||[],e]);return zt},prev:function(t={}){return $t(G-1,t),zt},reInit:function(e={},n){return qt(),R=0,j=void 0,J="*",w=e,C=e,t(n)&&(S=n),at(),zt},remove:function(t){void 0===t&&(t=K.length-1);const e=K[t];return e&&(lt("removeSlide",e),e.el&&(Pt(e.el),e.el.remove(),e.el=void 0),K.splice(t,1),ut(J),Lt(),N=a(Y,N,W),It()),zt},setPosition:function(t){N=t,dt(),It()},showError:function(t,e){if(1===R){Ht(t),Vt(t);const n=t.el;if(n){const i=document.createElement("div");c(i,"f-html"),c(i,"is-error"),i.innerHTML=st(e||"<p>{{ERROR}}</p>"),t.htmlEl=i,c(n,"has-html has-error"),n.insertAdjacentElement("afterbegin",i),lt("contentReady",t)}}return zt},showLoading:function(t){const e=t.el,n=e?.querySelector(".f-spinner");if(!e||n)return zt;const i=ot("spinnerTpl"),o=l(i);return o&&(c(o,"f-spinner"),e.insertAdjacentElement("beforeend",o)),zt},version:"6.1.15"};return zt};M.l10n={en_EN:g},M.getDefaults=()=>v;export{M as Carousel};