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