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