JavaScript UI component library, includes the latest Fancybox
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

1 lines
65 KiB

const t=t=>"object"==typeof t&&null!==t&&t.constructor===Object&&"[object Object]"===Object.prototype.toString.call(t),e=(i,...s)=>{const n=s.length;for(let o=0;o<n;o++){const n=s[o]||{};Object.entries(n).forEach((([s,n])=>{const o=Array.isArray(n)?[]:{};i[s]||Object.assign(i,{[s]:o}),t(n)?Object.assign(i[s],e(o,n)):Array.isArray(n)?Object.assign(i,{[s]:[...n]}):Object.assign(i,{[s]:n})}))}return i},i=function(t,e){let i=!0;return(...s)=>{i&&(i=!1,t(...s),setTimeout((()=>{i=!0}),e))}},s=(t,e)=>{let i=[];return t.childNodes.forEach((t=>{t.nodeType!==Node.ELEMENT_NODE||e&&!t.matches(e)||i.push(t)})),i},n=function(t){return(new DOMParser).parseFromString(t,"text/html").body.firstChild},o=(t,e=1e4)=>(t=parseFloat(t+"")||0,Math.round((t+Number.EPSILON)*e)/e),a=t=>`${t||""}`.split(" ").filter((t=>!!t)),r=(t,e)=>{a(e).forEach((e=>{t&&t.classList.add(e)}))},h=(t,e)=>{a(e).forEach((e=>{t&&t.classList.remove(e)}))},l=(t,e,i)=>{a(e).forEach((e=>{t&&t.classList.toggle(e,i||!1)}))},c='<div class="f-spinner"><svg viewBox="0 0 50 50"><circle cx="25" cy="25" r="20"></circle><circle cx="25" cy="25" r="20"></circle></svg></div>',d=function(t,e){return t.split(".").reduce(((t,e)=>"object"==typeof t?t[e]:void 0),e)};class u{constructor(t={}){Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"events",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),this.setOptions(t);for(const t of Object.getOwnPropertyNames(Object.getPrototypeOf(this)))t.startsWith("on")&&"function"==typeof this[t]&&(this[t]=this[t].bind(this))}setOptions(t){this.options=t?e({},this.constructor.defaults,t):{};for(const[t,e]of Object.entries(this.option("on")||{}))this.on(t,e)}option(t,...e){let i=d(t,this.options);return i&&"function"==typeof i&&(i=i.call(this,this,...e)),i}optionFor(t,e,i,...s){let n=d(e,t);var o;"string"!=typeof(o=n)||isNaN(o)||isNaN(parseFloat(o))||(n=parseFloat(n)),"true"===n&&(n=!0),"false"===n&&(n=!1),n&&"function"==typeof n&&(n=n.call(this,this,t,...s));let a=d(e,this.options);return a&&"function"==typeof a?n=a.call(this,this,t,...s,n):void 0===n&&(n=a),void 0===n?i:n}cn(t){const e=this.options.classes;return e&&e[t]||""}localize(t,e=[]){t=String(t).replace(/\{\{(\w+).?(\w+)?\}\}/g,((t,e,i)=>{let s="";return i?s=this.option(`${e[0]+e.toLowerCase().substring(1)}.l10n.${i}`):e&&(s=this.option(`l10n.${e}`)),s||(s=t),s}));for(let i=0;i<e.length;i++)t=t.split(e[i][0]).join(e[i][1]);return t=t.replace(/\{\{(.*)\}\}/,((t,e)=>e))}on(t,e){let i=[];"string"==typeof t?i=t.split(" "):Array.isArray(t)&&(i=t),this.events||(this.events=new Map),i.forEach((t=>{let i=this.events.get(t);i||(this.events.set(t,[]),i=[]),i.includes(e)||i.push(e),this.events.set(t,i)}))}off(t,e){let i=[];"string"==typeof t?i=t.split(" "):Array.isArray(t)&&(i=t),i.forEach((t=>{const i=this.events.get(t);if(Array.isArray(i)){const t=i.indexOf(e);t>-1&&i.splice(t,1)}}))}emit(t,...e){[...this.events.get(t)||[]].forEach((t=>t(this,...e))),"*"!==t&&this.emit("*",t,...e)}}Object.defineProperty(u,"version",{enumerable:!0,configurable:!0,writable:!0,value:"5.0.2"}),Object.defineProperty(u,"defaults",{enumerable:!0,configurable:!0,writable:!0,value:{}});class g extends u{constructor(t={}){super(t),Object.defineProperty(this,"plugins",{enumerable:!0,configurable:!0,writable:!0,value:{}})}attachPlugins(t={}){const e=new Map;for(const[i,s]of Object.entries(t)){const t=this.option(i),n=this.plugins[i];n||!1===t?n&&!1===t&&(n.detach(),delete this.plugins[i]):e.set(i,new s(this,t||{}))}for(const[t,i]of e)this.plugins[t]=i,i.attach();this.emit("attachPlugins")}detachPlugins(){for(const t of Object.values(this.plugins))t.detach();return this.plugins={},this.emit("detachPlugins"),this}}const p=function(t,e){return!(!t||t===document.body||e&&t===e)&&(function(t){if(!(t&&t instanceof Element&&t.offsetParent))return!1;const e=t.scrollHeight>t.clientHeight,i=window.getComputedStyle(t).overflowY,s=-1!==i.indexOf("hidden"),n=-1!==i.indexOf("visible");return e&&!s&&!n}(t)?t:p(t.parentElement,e))};class f{constructor(t){Object.defineProperty(this,"pageX",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pageY",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"clientX",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"clientY",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"time",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"nativePointer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.nativePointer=t,this.pageX=t.pageX,this.pageY=t.pageY,this.clientX=t.clientX,this.clientY=t.clientY,this.id=self.Touch&&t instanceof Touch?t.identifier:-1,this.time=Date.now()}}const m={passive:!1};class b{constructor(t,{start:e=(()=>!0),move:i=(()=>{}),end:s=(()=>{})}){Object.defineProperty(this,"element",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"startCallback",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"moveCallback",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"endCallback",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"currentPointers",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"startPointers",{enumerable:!0,configurable:!0,writable:!0,value:[]}),this.element=t,this.startCallback=e,this.moveCallback=i,this.endCallback=s;for(const t of["onPointerStart","onTouchStart","onMove","onTouchEnd","onPointerEnd","onWindowBlur"])this[t]=this[t].bind(this);this.element.addEventListener("touchstart",this.onTouchStart,m),this.element.addEventListener("touchmove",this.onMove,m),this.element.addEventListener("touchend",this.onTouchEnd),this.element.addEventListener("touchcancel",this.onTouchEnd),this.element.addEventListener("mousedown",this.onPointerStart,m)}onPointerStart(t){if(!t.buttons||0!==t.button)return;const e=new f(t);this.currentPointers.some((t=>t.id===e.id))||this.triggerPointerStart(e,t)&&(window.addEventListener("mousemove",this.onMove),window.addEventListener("mouseup",this.onPointerEnd),window.addEventListener("blur",this.onWindowBlur))}onTouchStart(t){for(const e of Array.from(t.changedTouches))this.triggerPointerStart(new f(e),t);window.addEventListener("blur",this.onWindowBlur)}onMove(t){const e=this.currentPointers.slice(),i="changedTouches"in t?Array.from(t.changedTouches).map((t=>new f(t))):[new f(t)],s=[];for(const t of i){const e=this.currentPointers.findIndex((e=>e.id===t.id));e<0||(s.push(t),this.currentPointers[e]=t)}s.length&&this.moveCallback(t,this.currentPointers.slice(),e)}onPointerEnd(t){t.buttons>0&&0!==t.button||(this.triggerPointerEnd(t,new f(t)),window.removeEventListener("mousemove",this.onMove),window.removeEventListener("mouseup",this.onPointerEnd),window.removeEventListener("blur",this.onWindowBlur))}onTouchEnd(t){for(const e of Array.from(t.changedTouches))this.triggerPointerEnd(t,new f(e))}triggerPointerStart(t,e){return!!this.startCallback(e,t,this.currentPointers.slice())&&(this.currentPointers.push(t),this.startPointers.push(t),!0)}triggerPointerEnd(t,e){const i=this.currentPointers.findIndex((t=>t.id===e.id));i<0||(this.currentPointers.splice(i,1),this.startPointers.splice(i,1),this.endCallback(t,e,this.currentPointers.slice()))}onWindowBlur(){this.clear()}clear(){for(;this.currentPointers.length;){const t=this.currentPointers[this.currentPointers.length-1];this.currentPointers.splice(this.currentPointers.length-1,1),this.startPointers.splice(this.currentPointers.length-1,1),this.endCallback(new Event("touchend",{bubbles:!0,cancelable:!0,clientX:t.clientX,clientY:t.clientY}),t,this.currentPointers.slice())}}stop(){this.element.removeEventListener("mousedown",this.onPointerStart,m),this.element.removeEventListener("touchstart",this.onTouchStart,m),this.element.removeEventListener("touchmove",this.onMove,m),this.element.removeEventListener("touchend",this.onTouchEnd),this.element.removeEventListener("touchcancel",this.onTouchEnd),window.removeEventListener("mousemove",this.onMove),window.removeEventListener("mouseup",this.onPointerEnd)}}function v(t,e){return e?Math.sqrt(Math.pow(e.clientX-t.clientX,2)+Math.pow(e.clientY-t.clientY,2)):0}function y(t,e){return e?{clientX:(t.clientX+e.clientX)/2,clientY:(t.clientY+e.clientY)/2}:t}var x;!function(t){t[t.Init=0]="Init",t[t.Error=1]="Error",t[t.Ready=2]="Ready",t[t.Panning=3]="Panning",t[t.Mousemove=4]="Mousemove",t[t.Destroy=5]="Destroy"}(x||(x={}));const w=["a","b","c","d","e","f"],P={content:null,width:"auto",height:"auto",panMode:"drag",touch:!0,dragMinThreshold:3,lockAxis:!1,mouseMoveFactor:1,mouseMoveFriction:.12,zoom:!0,pinchToZoom:!0,panOnlyZoomed:"auto",minScale:1,maxScale:2,friction:.25,dragFriction:.35,decelFriction:.05,click:"toggleZoom",dblClick:!1,wheel:"zoom",wheelLimit:7,spinner:!0,bounds:"auto",infinite:!1,rubberband:!0,bounce:!0,maxVelocity:75,transformParent:!1,classes:{content:"f-panzoom__content",isLoading:"is-loading",canZoomIn:"can-zoom_in",canZoomOut:"can-zoom_out",isDraggable:"is-draggable",isDragging:"is-dragging",inFullscreen:"in-fullscreen",htmlHasFullscreen:"with-panzoom-in-fullscreen"},l10n:{PANUP:"Move up",PANDOWN:"Move down",PANLEFT:"Move left",PANRIGHT:"Move right",ZOOMIN:"Zoom in",ZOOMOUT:"Zoom out",TOGGLEZOOM:"Toggle zoom level",TOGGLE1TO1:"Toggle zoom level",ITERATEZOOM:"Toggle zoom level",ROTATECCW:"Rotate counterclockwise",ROTATECW:"Rotate clockwise",FLIPX:"Flip horizontally",FLIPY:"Flip vertically",FITX:"Fit horizontally",FITY:"Fit vertically",RESET:"Reset",TOGGLEFS:"Toggle fullscreen"}},S=t=>t&&null!==t&&t instanceof Element&&"nodeType"in t,T={a:1,b:0,c:0,d:1,e:0,f:0};let M=null,O=null;class E extends g{get isTouchDevice(){return null===O&&(O=window.matchMedia("(hover: none)").matches),O}get isMobile(){return null===M&&(M=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)),M}get panMode(){return"mousemove"!==this.options.panMode||this.isTouchDevice?"drag":"mousemove"}get panOnlyZoomed(){const t=this.options.panOnlyZoomed;return"auto"===t?this.isTouchDevice:t}get isInfinite(){return this.option("infinite")}get angle(){return 180*Math.atan2(this.current.b,this.current.a)/Math.PI||0}get targetAngle(){return 180*Math.atan2(this.target.b,this.target.a)/Math.PI||0}get scale(){const{a:t,b:e}=this.current;return Math.sqrt(t*t+e*e)||1}get targetScale(){const{a:t,b:e}=this.target;return Math.sqrt(t*t+e*e)||1}get minScale(){return this.option("minScale")||1}get fullScale(){const{contentRect:t}=this;return t.fullWidth/t.fitWidth||1}get maxScale(){return this.fullScale*(this.option("maxScale")||1)||1}get coverScale(){const{containerRect:t,contentRect:e}=this,i=Math.max(t.height/e.fitHeight,t.width/e.fitWidth)||1;return Math.min(this.fullScale,i)}get isScaling(){return Math.abs(this.targetScale-this.scale)>1e-5&&!this.isResting}get isContentLoading(){return this.content instanceof HTMLImageElement&&!this.content.complete}get isResting(){if(this.isBouncingX||this.isBouncingY)return!1;for(const t of w){const e="e"==t||"f"===t?.001:1e-5;if(Math.abs(this.target[t]-this.current[t])>e)return!1}return!(!this.ignoreBounds&&!this.checkBounds().inBounds)}constructor(t,e={},i={}){var s;if(super(e),Object.defineProperty(this,"pointerTracker",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"resizeObserver",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"updateTimer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"clickTimer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"rAF",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"isTicking",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"friction",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"ignoreBounds",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"isBouncingX",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"isBouncingY",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"clicks",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"trackingPoints",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"wheelDelta",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"prevWheelDelta",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"prevWheelTime",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"prevMouseMoveEvent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:x.Init}),Object.defineProperty(this,"isDragging",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"container",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"content",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"spinner",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"containerRect",{enumerable:!0,configurable:!0,writable:!0,value:{width:0,height:0,innerWidth:0,innerHeight:0}}),Object.defineProperty(this,"contentRect",{enumerable:!0,configurable:!0,writable:!0,value:{top:0,right:0,bottom:0,left:0,fullWidth:0,fullHeight:0,fitWidth:0,fitHeight:0,width:0,height:0}}),Object.defineProperty(this,"dragStart",{enumerable:!0,configurable:!0,writable:!0,value:{x:0,y:0,top:0,left:0,time:0}}),Object.defineProperty(this,"dragOffset",{enumerable:!0,configurable:!0,writable:!0,value:{x:0,y:0,time:0}}),Object.defineProperty(this,"current",{enumerable:!0,configurable:!0,writable:!0,value:Object.assign({},T)}),Object.defineProperty(this,"target",{enumerable:!0,configurable:!0,writable:!0,value:Object.assign({},T)}),Object.defineProperty(this,"velocity",{enumerable:!0,configurable:!0,writable:!0,value:{a:0,b:0,c:0,d:0,e:0,f:0}}),Object.defineProperty(this,"lockedAxis",{enumerable:!0,configurable:!0,writable:!0,value:!1}),!t)throw new Error("No Element found");if(this.container=t,this.initContent(),this.attachPlugins(Object.assign(Object.assign({},E.Plugins),i)),this.emit("init"),this.isContentLoading){if(this.option("spinner")){t.classList.add(this.cn("isLoading"));const e=n(c);t.contains(this.content)?this.spinner=(null===(s=this.content.parentElement)||void 0===s?void 0:s.insertBefore(e,this.content))||null:this.spinner=t.appendChild(e)}this.emit("beforeLoad"),this.content.addEventListener("load",this.onLoad),this.content.addEventListener("error",this.onError)}else queueMicrotask((()=>{this.enable()}))}initContent(){const{container:t}=this;let e=this.option("content")||t.querySelector(`.${this.cn("content")}`);if(e||(e=t.querySelector("img")||t.firstElementChild,e&&e.classList.add(this.cn("content"))),!e)throw new Error("No content found");this.content=e}onLoad(){this.spinner&&(this.spinner.remove(),this.spinner=null),this.option("spinner")&&this.container.classList.remove(this.cn("isLoading")),this.emit("afterLoad"),this.state===x.Init&&this.enable()}onError(){this.state!==x.Destroy&&(this.spinner&&(this.spinner.remove(),this.spinner=null),this.stop(),this.detachEvents(),this.state=x.Error,this.emit("error"))}attachObserver(){var t;let e=!1;this.resizeObserver||void 0===window.ResizeObserver||(this.resizeObserver=new ResizeObserver((t=>{if(e)if(Math.abs(this.containerRect.width-t[0].contentRect.width)<.1&&Math.abs(this.containerRect.height-t[0].contentRect.height)<.1)this.updateTimer=null;else{if(this.updateTimer)return;this.onResize(),this.isMobile&&(this.updateTimer=setTimeout((()=>{this.onResize(),this.updateTimer=null}),300))}else e=!0}))),null===(t=this.resizeObserver)||void 0===t||t.observe(this.container)}detachObserver(){var t;null===(t=this.resizeObserver)||void 0===t||t.disconnect()}attachEvents(){const{container:t}=this;t.addEventListener("click",this.onClick,{passive:!1,capture:!1}),t.addEventListener("wheel",this.onWheel,{passive:!1}),this.pointerTracker=new b(t,{start:this.onPointerDown,move:this.onPointerMove,end:this.onPointerUp}),document.addEventListener("mousemove",this.onMouseMove)}detachEvents(){var t;const{container:e}=this;e.removeEventListener("click",this.onClick,{passive:!1,capture:!1}),e.removeEventListener("wheel",this.onWheel,{passive:!1}),null===(t=this.pointerTracker)||void 0===t||t.stop(),this.pointerTracker=null,document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("keydown",this.onKeydown,!0),this.clickTimer&&(clearTimeout(this.clickTimer),this.clickTimer=null),this.updateTimer&&(clearTimeout(this.updateTimer),this.updateTimer=null)}animate(){this.setTargetForce();const t=this.option("maxVelocity");for(const e of w)this.friction?(this.velocity[e]*=1-this.friction,t&&!this.isScaling&&(this.velocity[e]=Math.max(Math.min(this.velocity[e],t),-1*t)),this.current[e]+=this.velocity[e]):this.current[e]=this.target[e];this.setTransform(),this.setEdgeForce(),!this.isResting||this.isDragging?this.rAF=requestAnimationFrame((()=>this.animate())):this.stop("current")}setTargetForce(){for(const t of w)"e"===t&&this.isBouncingX||"f"===t&&this.isBouncingY||(this.velocity[t]=(1/(1-this.friction)-1)*(this.target[t]-this.current[t]))}checkBounds(t=0,e=0){const{current:i}=this,s=i.e+t,n=i.f+e,o=this.getBounds(),{x:a,y:r}=o,h=a.min,l=a.max,c=r.min,d=r.max;let u=0,g=0;return h!==1/0&&s<h?u=h-s:l!==1/0&&s>l&&(u=l-s),c!==1/0&&n<c?g=c-n:d!==1/0&&n>d&&(g=d-n),Math.abs(u)<.001&&(u=0),Math.abs(g)<.001&&(g=0),Object.assign(Object.assign({},o),{xDiff:u,yDiff:g,inBounds:!u&&!g})}clampTargetBounds(){const{target:t}=this,{x:e,y:i}=this.getBounds();e.min!==1/0&&(t.e=Math.max(t.e,e.min)),e.max!==1/0&&(t.e=Math.min(t.e,e.max)),i.min!==1/0&&(t.f=Math.max(t.f,i.min)),i.max!==1/0&&(t.f=Math.min(t.f,i.max))}calculateContentDim(t=this.current){const{content:e,contentRect:i}=this,{fitWidth:s,fitHeight:n,fullWidth:o,fullHeight:a}=i;let r=o,h=a;if(this.option("zoom")||0!==this.angle){const i=!(e instanceof HTMLImageElement)&&("none"===window.getComputedStyle(e).maxWidth||"none"===window.getComputedStyle(e).maxHeight),l=i?o:s,c=i?a:n,d=this.getMatrix(t),u=new DOMPoint(0,0).matrixTransform(d),g=new DOMPoint(0+l,0).matrixTransform(d),p=new DOMPoint(0+l,0+c).matrixTransform(d),f=new DOMPoint(0,0+c).matrixTransform(d),m=Math.abs(p.x-u.x),b=Math.abs(p.y-u.y),v=Math.abs(f.x-g.x),y=Math.abs(f.y-g.y);r=Math.max(m,v),h=Math.max(b,y)}return{contentWidth:r,contentHeight:h}}setEdgeForce(){if(this.ignoreBounds||this.isDragging||"mousemove"===this.panMode||this.targetScale<this.scale)return this.isBouncingX=!1,void(this.isBouncingY=!1);const{target:t}=this,{x:e,y:i,xDiff:s,yDiff:n}=this.checkBounds();const o=this.option("maxVelocity");let a=this.velocity.e,r=this.velocity.f;0!==s?(this.isBouncingX=!0,s*a<=0?a+=.14*s:(a=.14*s,e.min!==1/0&&(this.target.e=Math.max(t.e,e.min)),e.max!==1/0&&(this.target.e=Math.min(t.e,e.max))),o&&(a=Math.max(Math.min(a,o),-1*o))):this.isBouncingX=!1,0!==n?(this.isBouncingY=!0,n*r<=0?r+=.14*n:(r=.14*n,i.min!==1/0&&(this.target.f=Math.max(t.f,i.min)),i.max!==1/0&&(this.target.f=Math.min(t.f,i.max))),o&&(r=Math.max(Math.min(r,o),-1*o))):this.isBouncingY=!1,this.isBouncingX&&(this.velocity.e=a),this.isBouncingY&&(this.velocity.f=r)}enable(){const{content:t}=this,e=new DOMMatrixReadOnly(window.getComputedStyle(t).transform);for(const t of w)this.current[t]=this.target[t]=e[t];this.updateMetrics(),this.attachObserver(),this.attachEvents(),this.state=x.Ready,this.emit("ready")}onClick(t){var e;this.isDragging&&(null===(e=this.pointerTracker)||void 0===e||e.clear(),this.trackingPoints=[],this.startDecelAnim());const i=t.target;if(!i||t.defaultPrevented)return;if(i&&i.hasAttribute("disabled"))return t.preventDefault(),void t.stopPropagation();if((()=>{const t=window.getSelection();return t&&"Range"===t.type})()&&!i.closest("button"))return;const s=i.closest("[data-panzoom-action]"),n=i.closest("[data-panzoom-change]"),o=s||n,a=o&&S(o)?o.dataset:null;if(a){const e=a.panzoomChange,i=a.panzoomAction;if((e||i)&&t.preventDefault(),e){let t={};try{t=JSON.parse(e)}catch(t){console&&console.warn("The given data was not valid JSON")}return void this.applyChange(t)}if(i)return void(this[i]&&this[i]())}if(Math.abs(this.dragOffset.x)>3||Math.abs(this.dragOffset.y)>3)return t.preventDefault(),void t.stopPropagation();const r=this.content.getBoundingClientRect();if(this.dragStart.time&&!this.canZoomOut()&&(Math.abs(r.x-this.dragStart.x)>2||Math.abs(r.y-this.dragStart.y)>2))return;this.dragStart.time=0;const h=e=>{!this.option("zoom")||Math.abs(this.velocity.a)>.3||e&&"string"==typeof e&&/(iterateZoom)|(toggle(Zoom|Full|Cover|Max)|(zoomTo(Fit|Cover|Max)))/.test(e)&&"function"==typeof this[e]&&(t.preventDefault(),this[e]({event:t}))},l=this.option("click",t),c=this.option("dblClick",t);c?(this.clicks++,1==this.clicks&&(this.clickTimer=setTimeout((()=>{1===this.clicks?(this.emit("click",t),!t.defaultPrevented&&l&&h(l)):(this.emit("dblClick",t),t.defaultPrevented||h(c)),this.clicks=0,this.clickTimer=null}),350))):(this.emit("click",t),!t.defaultPrevented&&l&&h(l))}addTrackingPoint(t){const e=this.trackingPoints.filter((t=>t.time>Date.now()-100));e.push(t),this.trackingPoints=e}onPointerDown(t,e,i){var s;this.dragOffset={x:0,y:0,time:0},this.trackingPoints=[];const n=this.content.getBoundingClientRect();if(this.dragStart={x:n.x,y:n.y,top:n.top,left:n.left,time:Date.now()},!1===this.option("touch",t))return!1;if(this.clickTimer)return!1;if("mousemove"===this.panMode&&this.targetScale>1)return t.preventDefault(),t.stopPropagation(),!1;if(!i.length){const e=t.composedPath()[0];if(["A","TEXTAREA","OPTION","INPUT","SELECT","VIDEO"].includes(e.nodeName)||e.closest("[contenteditable]")||e.closest("[data-selectable]")||e.closest("[data-panzoom-change]")||e.closest("[data-panzoom-action]"))return!1;null===(s=window.getSelection())||void 0===s||s.removeAllRanges()}return"mousedown"===t.type&&t.preventDefault(),this.targetScale<this.minScale+1e-5?(this.stop(),this.target.e=this.current.e,this.target.f=this.current.f):this.stop("target"),this.isDragging=!0,this.addTrackingPoint(e),this.emit("touchStart",t),!0}onPointerMove(t,e,i){if(!this.isDragging)return;if(e.length<2&&this.panOnlyZoomed&&this.targetScale<=this.minScale+1e-5)return;if(this.emit("touchMove",t),t.defaultPrevented)return;this.addTrackingPoint(e[0]);const{content:s}=this,n=y(i[0],i[1]),o=y(e[0],e[1]);let a=0,r=0;if(e.length>1){const t=s.getBoundingClientRect();a=n.clientX-t.left-.5*t.width,r=n.clientY-t.top-.5*t.height}const h=v(i[0],i[1]),l=v(e[0],e[1]);let c=h?l/h:1,d=o.clientX-n.clientX,u=o.clientY-n.clientY;this.dragOffset.x+=d,this.dragOffset.y+=u,this.dragOffset.time=Date.now()-this.dragStart.time;let g=this.targetScale<this.minScale+1e-5&&this.option("lockAxis");if(g&&!this.lockedAxis)if("xy"===g||"y"===g||"touchmove"===t.type){if(Math.abs(this.dragOffset.x)<6&&Math.abs(this.dragOffset.y)<6)return void t.preventDefault();const e=Math.abs(180*Math.atan2(this.dragOffset.y,this.dragOffset.x)/Math.PI);this.lockedAxis=e>45&&e<135?"y":"x",this.dragOffset.x=0,this.dragOffset.y=0,d=0,u=0}else this.lockedAxis=g;if(p(t.target,this.content)&&(g="x",this.dragOffset.y=0),g&&"xy"!==g&&this.lockedAxis!==g&&this.targetScale<this.minScale+1e-5)return;t.cancelable&&t.preventDefault(),this.container.classList.add(this.cn("isDragging"));const f=this.checkBounds(d,u);this.option("rubberband")?("x"!==this.isInfinite&&(f.xDiff>0&&d<0||f.xDiff<0&&d>0)&&(d*=Math.max(0,.5-Math.abs(.75/this.contentRect.fitWidth*f.xDiff))),"y"!==this.isInfinite&&(f.yDiff>0&&u<0||f.yDiff<0&&u>0)&&(u*=Math.max(0,.5-Math.abs(.75/this.contentRect.fitHeight*f.yDiff)))):(f.xDiff&&(d=0),f.yDiff&&(u=0));const m=this.targetScale,b=this.minScale,x=this.maxScale;m<.5*b&&(c=Math.max(c,b)),m>1.5*x&&(c=Math.min(c,x)),"y"===this.lockedAxis&&m<b+1e-5&&(d=0),"x"===this.lockedAxis&&m<b+1e-5&&(u=0),this.applyChange({originX:a,originY:r,panX:d,panY:u,scale:c,friction:this.option("dragFriction"),ignoreBounds:!0})}onPointerUp(t,e,i){if(i.length)return this.dragOffset.x=0,this.dragOffset.y=0,void(this.trackingPoints=[]);this.container.classList.remove(this.cn("isDragging")),this.isDragging&&(this.isDragging=!1,this.addTrackingPoint(e),this.panOnlyZoomed&&this.contentRect.width-this.contentRect.fitWidth<1&&this.contentRect.height-this.contentRect.fitHeight<1&&(this.trackingPoints=[]),p(t.target,this.content)&&"y"===this.lockedAxis&&(this.trackingPoints=[]),this.emit("touchEnd",t),this.state!==x.Destroy&&(t.defaultPrevented||this.startDecelAnim()))}startDecelAnim(){this.rAF&&(cancelAnimationFrame(this.rAF),this.rAF=null),this.isBouncingX=!1,this.isBouncingY=!1;for(const t of w)this.velocity[t]=0,this.target[t]=this.current[t];const{trackingPoints:t}=this,e=t[0],i=t[t.length-1];let s=0,n=0,o=0;i&&e&&(s=i.clientX-e.clientX,n=i.clientY-e.clientY,o=i.time-e.time);let a=0,r=0,h=0,l=0,c=this.option("decelFriction");const d=this.targetScale;if((d<this.minScale-1e-5||d>this.maxScale+1e-5)&&(c=.35),o>0){h=Math.abs(s)>3?s/(o/30):0,l=Math.abs(n)>3?n/(o/30):0;const t=this.option("maxVelocity");t&&(h=Math.max(Math.min(h,t),-1*t),l=Math.max(Math.min(l,t),-1*t))}h&&(a=h/(1/(1-c)-1)),l&&(r=l/(1/(1-c)-1)),("y"===this.option("lockAxis")||"xy"===this.option("lockAxis")&&"y"===this.lockedAxis&&d<this.minScale+1e-5)&&(a=h=0),("x"===this.option("lockAxis")||"xy"===this.option("lockAxis")&&"x"===this.lockedAxis&&d<this.minScale+1e-5)&&(r=l=0);const u=this.option("dragMinThreshold")||0;Math.abs(this.dragOffset.x)<u&&Math.abs(this.dragOffset.y)<u&&(a=r=0,h=l=0),this.applyChange({panX:a,panY:r,friction:c}),this.emit("decel",h,l)}onWheel(t){const e=Date.now(),i=Math.max(-1,Math.min(1,-t.deltaY||-t.deltaX||-t.detail));if(this.prevWheelTime&&e-this.prevWheelTime<150&&this.prevWheelDelta!==i)return void t.preventDefault();if(this.prevWheelDelta=i,this.prevWheelTime=e,this.emit("wheel",t,i),"mousemove"===this.panMode)return;if(t.defaultPrevented)return;const s=this.option("wheel");"pan"===s?(t.preventDefault(),this.panOnlyZoomed&&!this.canZoomOut()||this.applyChange({panY:100*i,bounce:!1})):"zoom"===s&&!1!==this.option("zoom")&&this.zoomWithWheel(t)}onMouseMove(t){this.panWithMouse(t)}onKeydown(t){"Escape"===t.key&&this.toggleFS()}onResize(){this.updateMetrics(),this.checkBounds().inBounds||this.requestTick()}setTransform(){this.emit("beforeTransform");const{current:t,target:e,content:i,contentRect:s}=this,n=Object.assign({},T);for(const i of w){const s="e"==i||"f"===i?1e3:1e5;n[i]=o(t[i],s),Math.abs(e[i]-t[i])<("e"==i||"f"===i?.51:.001)&&(this.current[i]=e[i])}const{a:a,b:r,c:h,d:l,e:c,f:d}=n,u=`matrix(${a}, ${r}, ${h}, ${l}, ${c}, ${d})`,g=(this.option("transformParent")?i.parentElement:null)||i;if(g.style.transform===u)return;g.style.transform=u;const{contentWidth:p,contentHeight:f}=this.calculateContentDim();s.width=p,s.height=f,this.emit("afterTransform")}updateMetrics(t=!1){if(!this||this.state===x.Destroy)return;const{container:e,containerRect:i,content:s}=this,n=i.innerWidth,o=i.innerHeight,a=e.getBoundingClientRect(),r=getComputedStyle(this.container),h=a.width,l=a.height,c=parseFloat(r.paddingTop)+parseFloat(r.paddingBottom),d=parseFloat(r.paddingLeft)+parseFloat(r.paddingRight);this.containerRect={width:h,height:l,innerWidth:h-d,innerHeight:l-c};let u=this.option("width")||"auto",g=this.option("height")||"auto";"auto"===u&&(u=parseFloat(s.dataset.width||"")||(t=>{let e=0;return e=t instanceof HTMLImageElement?t.naturalWidth:t instanceof SVGElement?t.width.baseVal.value:t.offsetWidth,Math.max(e,t.scrollWidth)})(s)),"auto"===g&&(g=parseFloat(s.dataset.height||"")||(t=>{let e=0;return e=t instanceof HTMLImageElement?t.naturalHeight:t instanceof SVGElement?t.height.baseVal.value:t.offsetHeight,Math.max(e,t.scrollHeight)})(s));const p=(this.option("transformParent")?s.parentElement:null)||s,f=p.getAttribute("style")||"";p.style.setProperty("transform","none","important"),p.style.setProperty("transition","none","important"),p.style.setProperty("animation","none","important"),s instanceof HTMLImageElement&&(p.style.width="",p.style.height=""),p.offsetHeight;const m=s.getBoundingClientRect();let b=m.width,v=m.height,y=0,w=0;if(s instanceof HTMLImageElement&&({width:b,height:v,top:y,left:w}=((t,e,i,s)=>{const n=i/s;return n>t/e?(i=t,s=t/n):(i=e*n,s=e),{width:i,height:s,top:.5*(e-s),left:.5*(t-i)}})(m.width,m.height,u,g)),this.contentRect=Object.assign(Object.assign({},this.contentRect),{top:m.top-a.top+y,bottom:a.bottom-m.bottom+y,left:m.left-a.left+w,right:a.right-m.right+w,fitWidth:b,fitHeight:v,width:b,height:v,fullWidth:u,fullHeight:g}),p.style.cssText=f,s instanceof HTMLImageElement&&(p.style.width=`${b}px`,p.style.height=`${v}px`),this.setTransform(),!0!==t){let t="";Math.abs(h-n)>1&&(t+="x"),Math.abs(l-o)>1&&(t+="y"),t&&this.emit("refresh",t)}this.targetScale<this.minScale+1e-5?this.zoomTo(this.minScale,{friction:0}):this.targetScale>this.maxScale?this.zoomTo(this.maxScale,{friction:0}):this.state===x.Init||this.checkBounds().inBounds||this.requestTick(),this.updateControls()}getBounds(){const t=this.option("bounds");if("auto"!==t)return t;const{contentWidth:e,contentHeight:i}=this.calculateContentDim(this.target);let s=0,n=0,a=0,r=0;const h=this.option("infinite");if(!0===h||this.lockedAxis&&h===this.lockedAxis)s=-1/0,a=1/0,n=-1/0,r=1/0;else{let{containerRect:t,contentRect:h}=this,l=o(this.contentRect.fitWidth*this.targetScale,1e3),c=o(this.contentRect.fitHeight*this.targetScale,1e3),{innerWidth:d,innerHeight:u}=t;if(this.containerRect.width===l&&(d=t.width),this.containerRect.width===c&&(u=t.height),e>d){a=.5*(e-d),s=-1*a;let t=.5*(h.right-h.left);s+=t,a+=t}if(this.contentRect.fitWidth>d&&e<d&&(s-=.5*(this.contentRect.fitWidth-d),a-=.5*(this.contentRect.fitWidth-d)),i>u){r=.5*(i-u),n=-1*r;let t=.5*(h.bottom-h.top);n+=t,r+=t}this.contentRect.fitHeight>u&&i<u&&(s-=.5*(this.contentRect.fitHeight-u),a-=.5*(this.contentRect.fitHeight-u))}return{x:{min:s,max:a},y:{min:n,max:r}}}updateControls(){const t=this,e=t.container;let i={toggleMax:this.targetScale>this.maxScale?this.minScale:this.maxScale,toggleCover:this.targetScale>this.coverScale?this.minScale:this.coverScale,toggleZoom:this.targetScale>this.fullScale?this.minScale:this.fullScale}[this.option("click")||""]||this.minScale,s=t.canZoomIn(),n=t.canZoomOut(),o="drag"===this.panMode,a=n&&o;this.targetScale<=this.minScale&&!this.panOnlyZoomed&&(a=!0),(this.contentRect.width-this.contentRect.fitWidth>-1||this.contentRect.height-this.contentRect.fitHeight>-1)&&(a=!0),this.contentRect.width*this.targetScale<this.contentRect.fitWidth&&(a=!1),"mousemove"===this.panMode&&(a=!1);let r=s&&i>this.minScale,h=!s&&!a&&n&&i===this.minScale;l(e,this.cn("canZoomIn"),r),l(e,this.cn("canZoomOut"),h),l(e,this.cn("isDraggable"),a);for(const t of e.querySelectorAll('[data-panzoom-action="zoomIn"]'))s?(t.removeAttribute("disabled"),t.removeAttribute("tabindex")):(t.setAttribute("disabled",""),t.setAttribute("tabindex","-1"));for(const t of e.querySelectorAll('[data-panzoom-action="zoomOut"]'))n?(t.removeAttribute("disabled"),t.removeAttribute("tabindex")):(t.setAttribute("disabled",""),t.setAttribute("tabindex","-1"));for(const i of e.querySelectorAll('[data-panzoom-action="toggleZoom"],[data-panzoom-action="iterateZoom"]')){s=t.targetScale<t.fullScale-.1,s||n?(i.removeAttribute("disabled"),i.removeAttribute("tabindex")):(i.setAttribute("disabled",""),i.setAttribute("tabindex","-1"));const e=i.querySelector("g");e&&(e.style.display=t.targetScale>.9*t.fullScale?"none":"")}}panTo({x:t=this.target.e,y:e=this.target.f,scale:i=this.targetScale,friction:s=this.option("friction"),angle:n=0,originX:o=0,originY:a=0,flipX:r=!1,flipY:h=!1,ignoreBounds:l=!1}){this.state!==x.Destroy&&this.applyChange({panX:t-this.target.e,panY:e-this.target.f,scale:i/this.targetScale,angle:n,originX:o,originY:a,friction:s,flipX:r,flipY:h,ignoreBounds:l})}applyChange({panX:t=0,panY:e=0,scale:i=1,angle:s=0,originX:n=-this.current.e,originY:a=-this.current.f,friction:r=this.option("friction"),flipX:h=!1,flipY:l=!1,ignoreBounds:c=!1,bounce:d=this.option("bounce")}){if(this.state===x.Destroy)return;this.rAF&&(cancelAnimationFrame(this.rAF),this.rAF=null),this.isBouncingX=!1,this.isBouncingY=!1;for(const t of w)this.velocity[t]=0;this.friction=r||0,this.ignoreBounds=c;const{current:u}=this,g=u.e,p=u.f,f=this.getMatrix(this.target);let m=(new DOMMatrix).translate(g,p).translate(n,a).translate(t,e);if(this.option("zoom")){if(!c){const t=this.targetScale,e=this.minScale,s=this.maxScale;t*i<e&&(i=e/t),t*i>s&&(i=s/t)}m=m.scale(i)}m=m.translate(-n,-a).translate(-g,-p).multiply(f),s&&(m=m.rotate(s)),h&&(m=m.scale(-1,1)),l&&(m=m.scale(1,-1));for(const t of w)("a"==t||"d"==t)&&m[t]>this.minScale+1e-5?this.target[t]=m[t]:this.target[t]=o(m[t],1e3);(this.targetScale<this.scale||Math.abs(i-1)>.1||"mousemove"===this.panMode||!1===d)&&!c&&this.clampTargetBounds(),this.isResting||(this.state=x.Panning,this.requestTick())}stop(t=!1){if(this.state!==x.Init&&this.state!==x.Destroy){this.rAF&&(cancelAnimationFrame(this.rAF),this.rAF=null),this.isBouncingX=!1,this.isBouncingY=!1;for(const e of w)this.velocity[e]=0,"current"===t?this.current[e]=this.target[e]:"target"===t&&(this.target[e]=this.current[e]);this.setTransform(),this.isTicking&&(this.emit("endAnimation"),this.updateControls()),this.isTicking=!1,this.isDragging=!1,this.lockedAxis=!1,this.state=x.Ready}}requestTick(){this.isTicking||(this.emit("startAnimation"),this.updateControls()),this.isTicking=!0,this.rAF||(this.rAF=requestAnimationFrame((()=>this.animate())))}panWithMouse(t,e=this.option("mouseMoveFriction")){if(this.prevMouseMoveEvent=t,"mousemove"!==this.panMode||!t)return;if(this.targetScale<this.minScale+1e-5)return;this.emit("mouseMove",t);const{container:i,containerRect:s,contentRect:n}=this,o=s.width,a=s.height,r=i.getBoundingClientRect(),h=(t.clientX||0)-r.left,l=(t.clientY||0)-r.top;let{contentWidth:c,contentHeight:d}=this.calculateContentDim(this.target);const u=this.option("mouseMoveFactor");u>1&&(c!==o&&(c*=u),d!==a&&(d*=u));let g=.5*(c-o)-h/o*100/100*(c-o);g+=.5*(n.right-n.left);let p=.5*(d-a)-l/a*100/100*(d-a);p+=.5*(n.bottom-n.top),this.applyChange({panX:g-this.target.e,panY:p-this.target.f,friction:e})}zoomWithWheel(t){if(this.state===x.Destroy||this.state===x.Init)return;const e=Math.abs(t.deltaY)<100&&Math.abs(t.deltaX)<100?25:50,i=Math.max(-1,Math.min(1,-t.deltaY||-t.deltaX||-t.detail)),s=this.targetScale,n=this.maxScale,o=this.minScale;let a=s*(100+i*e)/100;a<o&&s<=o?(this.wheelDelta+=Math.abs(i),a=o):a>n&&s>=n?(this.wheelDelta+=Math.abs(i),a=n):(this.wheelDelta=0,a=Math.max(Math.min(a,n),o)),this.wheelDelta>this.option("wheelLimit")||(t.preventDefault(),a!==s&&this.zoomTo(a,{event:t}))}canZoomIn(){return this.option("zoom")&&(this.contentRect.width<this.contentRect.fitWidth||this.targetScale<this.maxScale-1e-5)}canZoomOut(){return this.option("zoom")&&this.targetScale>this.minScale+1e-5}zoomIn(t=1.25,e){this.zoomTo(this.targetScale*t,e)}zoomOut(t=.8,e){this.zoomTo(this.targetScale*t,e)}zoomToFit(t){this.zoomTo("fit",t)}zoomToCover(t){this.zoomTo("cover",t)}zoomToFull(t){this.zoomTo("full",t)}zoomToMax(t){this.zoomTo("max",t)}toggleZoom(t){this.zoomTo(this.targetScale-this.minScale<.5*(this.fullScale-this.minScale)?"full":"fit",t)}toggleMax(t){this.zoomTo(this.targetScale>.9*this.maxScale?"fit":"max",t)}toggleCover(t){this.zoomTo(this.targetScale>.9*this.coverScale?"fit":"cover",t)}iterateZoom(t){this.zoomTo("next",t)}zoomTo(t=1,{friction:e="auto",originX:i=0,originY:s=0,event:n}={}){if(this.isContentLoading||this.state===x.Destroy)return;this.stop();const{targetScale:o}=this;let a=1;if("mousemove"===this.panMode&&(n=this.prevMouseMoveEvent||n),n){const t=this.content.getBoundingClientRect(),e=n.clientX||0,o=n.clientY||0;i=e-t.left-.5*t.width,s=o-t.top-.5*t.height}const r=this.fullScale,h=this.maxScale;let l=this.coverScale;"number"==typeof t?a=t/o:("next"===t&&(r-l<.2&&(l=r),t=o<r-1e-5?"full":o<h-1e-5?"max":"fit"),a="full"===t?r/o||1:"cover"===t?l/o||1:"max"===t?h/o||1:1/o||1),e="auto"===e?a>1?.15:.25:e,this.applyChange({scale:a,originX:i,originY:s,friction:e}),n&&"mousemove"===this.panMode&&this.panWithMouse(n,e)}rotateCCW(){this.applyChange({angle:-90})}rotateCW(){this.applyChange({angle:90})}flipX(){this.applyChange({flipX:!0})}flipY(){this.applyChange({flipY:!0})}fitX(){this.stop("target");const{containerRect:t,contentRect:e,target:i}=this;this.applyChange({panX:.5*t.width-(e.left+.5*e.fitWidth)-i.e,panY:.5*t.height-(e.top+.5*e.fitHeight)-i.f,scale:t.width/e.fitWidth/this.targetScale,originX:0,originY:0,ignoreBounds:!0})}fitY(){this.stop("target");const{containerRect:t,contentRect:e,target:i}=this;this.applyChange({panX:.5*t.width-(e.left+.5*e.fitWidth)-i.e,panY:.5*t.height-(e.top+.5*e.fitHeight)-i.f,scale:t.height/e.fitHeight/this.targetScale,originX:0,originY:0,ignoreBounds:!0})}toggleFS(){const{container:t}=this,e=this.cn("inFullscreen"),i=this.cn("htmlHasFullscreen");t.classList.toggle(e);const s=t.classList.contains(e);s?(document.documentElement.classList.add(i),document.addEventListener("keydown",this.onKeydown,!0)):(document.documentElement.classList.remove(i),document.removeEventListener("keydown",this.onKeydown,!0)),this.updateMetrics(),this.emit(s?"enterFS":"exitFS")}getMatrix(t=this.current){const{a:e,b:i,c:s,d:n,e:o,f:a}=t;return new DOMMatrix([e,i,s,n,o,a])}reset(t){if(this.state!==x.Init&&this.state!==x.Destroy){this.stop("current");for(const t of w)this.target[t]=T[t];this.target.a=this.minScale,this.target.d=this.minScale,this.isResting||(this.friction=void 0===t?this.option("friction"):t,this.state=x.Panning,this.requestTick())}}destroy(){this.stop(),this.state=x.Destroy,this.detachEvents(),this.detachObserver();const{container:t,content:e}=this,i=this.option("classes")||{};for(const e of Object.values(i))t.classList.remove(e+"");e&&(e.removeEventListener("load",this.onLoad),e.removeEventListener("error",this.onError)),this.detachPlugins()}}Object.defineProperty(E,"defaults",{enumerable:!0,configurable:!0,writable:!0,value:P}),Object.defineProperty(E,"Plugins",{enumerable:!0,configurable:!0,writable:!0,value:{}});const z={viewport:null,track:null,enabled:!0,slides:[],axis:"x",transition:"fade",preload:1,slidesPerPage:"auto",initialPage:0,friction:.12,center:!0,infinite:!0,fill:!0,dragFree:!1,adaptiveHeight:!1,direction:"ltr",classes:{container:"f-carousel",viewport:"f-carousel__viewport",track:"f-carousel__track",slide:"f-carousel__slide",isLTR:"is-ltr",isRTL:"is-rtl",isHorizontal:"is-horizontal",isVertical:"is-vertical",inTransition:"in-transition",isSelected:"is-selected"},l10n:{NEXT:"Next slide",PREV:"Previous slide",GOTO:"Go to slide #%d"}};var k;!function(t){t[t.Init=0]="Init",t[t.Ready=1]="Ready",t[t.Destroy=2]="Destroy"}(k||(k={}));const R=t=>{if("string"==typeof t&&(t={html:t}),!(t instanceof String||t instanceof HTMLElement)){const e=t.thumb;void 0!==e&&("string"==typeof e&&(t.thumbSrc=e),e instanceof HTMLImageElement&&(t.thumbEl=e,t.thumbElSrc=e.src,t.thumbSrc=e.src),delete t.thumb)}return Object.assign({html:"",el:null,isDom:!1,class:"",index:-1,dim:0,gap:0,pos:0,transition:!1},t)},D=(t={})=>Object.assign({index:-1,slides:[],dim:0,pos:-1},t);class L extends u{constructor(t,e){super(e),Object.defineProperty(this,"instance",{enumerable:!0,configurable:!0,writable:!0,value:t})}attach(){}detach(){}}const A={classes:{list:"f-carousel__dots",isDynamic:"is-dynamic",hasDots:"has-dots",dot:"f-carousel__dot",isBeforePrev:"is-before-prev",isPrev:"is-prev",isCurrent:"is-current",isNext:"is-next",isAfterNext:"is-after-next"},dotTpl:'<button type="button" data-carousel-page="%i" aria-label="{{GOTO}}"><span class="f-carousel__dot" aria-hidden="true"></span></button>',dynamicFrom:11,maxCount:1/0,minCount:2};class C extends L{constructor(){super(...arguments),Object.defineProperty(this,"isDynamic",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"list",{enumerable:!0,configurable:!0,writable:!0,value:null})}onRefresh(){this.refresh()}build(){let t=this.list;return t||(t=document.createElement("ul"),r(t,this.cn("list")),t.setAttribute("role","tablist"),this.instance.container.appendChild(t),r(this.instance.container,this.cn("hasDots")),this.list=t),t}refresh(){var t;const e=this.instance.pages.length,i=Math.min(2,this.option("minCount")),s=Math.max(2e3,this.option("maxCount")),n=this.option("dynamicFrom");if(e<i||e>s)return void this.cleanup();const o="number"==typeof n&&e>5&&e>=n,a=!this.list||this.isDynamic!==o||this.list.children.length!==e;a&&this.cleanup();const c=this.build();if(l(c,this.cn("isDynamic"),!!o),a)for(let t=0;t<e;t++)c.append(this.createItem(t));let d,u=0;for(const e of[...c.children]){const i=u===this.instance.page;i&&(d=e),l(e,this.cn("isCurrent"),i),null===(t=e.children[0])||void 0===t||t.setAttribute("aria-selected",i?"true":"false");for(const t of["isBeforePrev","isPrev","isNext","isAfterNext"])h(e,this.cn(t));u++}if(d=d||c.firstChild,o&&d){const t=d.previousElementSibling,e=t&&t.previousElementSibling;r(t,this.cn("isPrev")),r(e,this.cn("isBeforePrev"));const i=d.nextElementSibling,s=i&&i.nextElementSibling;r(i,this.cn("isNext")),r(s,this.cn("isAfterNext"))}this.isDynamic=o}createItem(t=0){var e;const i=document.createElement("li");i.setAttribute("role","presentation");const s=n(this.instance.localize(this.option("dotTpl"),[["%d",t+1]]).replace(/\%i/g,t+""));return i.appendChild(s),null===(e=i.children[0])||void 0===e||e.setAttribute("role","tab"),i}cleanup(){this.list&&(this.list.remove(),this.list=null),this.isDynamic=!1,h(this.instance.container,this.cn("hasDots"))}attach(){this.instance.on(["refresh","change"],this.onRefresh)}detach(){this.instance.off(["refresh","change"],this.onRefresh),this.cleanup()}}Object.defineProperty(C,"defaults",{enumerable:!0,configurable:!0,writable:!0,value:A});class j extends L{constructor(){super(...arguments),Object.defineProperty(this,"container",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"prev",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"next",{enumerable:!0,configurable:!0,writable:!0,value:null})}onRefresh(){const t=this.instance,e=t.pages.length,i=t.page;if(e<2)return void this.cleanup();this.build();let s=this.prev,n=this.next;s&&n&&(s.removeAttribute("disabled"),n.removeAttribute("disabled"),t.isInfinite||(i<=0&&s.setAttribute("disabled",""),i>=e-1&&n.setAttribute("disabled","")))}createButton(t){const e=this.instance,i=document.createElement("button");i.setAttribute("tabindex","0"),i.setAttribute("title",e.localize(`{{${t.toUpperCase()}}}`)),r(i,this.cn("button")+" "+this.cn("next"===t?"isNext":"isPrev"));const s=e.isRTL?"next"===t?"prev":"next":t;var n;return i.innerHTML=e.localize(this.option(`${s}Tpl`)),i.dataset[`carousel${n=t,n?n.match("^[a-z]")?n.charAt(0).toUpperCase()+n.substring(1):n:""}`]="true",i}build(){let t=this.container;t||(this.container=t=document.createElement("div"),r(t,this.cn("container")),this.instance.container.appendChild(t)),this.next||(this.next=t.appendChild(this.createButton("next"))),this.prev||(this.prev=t.appendChild(this.createButton("prev")))}cleanup(){this.prev&&this.prev.remove(),this.next&&this.next.remove(),this.container&&this.container.remove(),this.prev=null,this.next=null,this.container=null}attach(){this.instance.on(["refresh","change"],this.onRefresh)}detach(){this.instance.off(["refresh","change"],this.onRefresh),this.cleanup()}}Object.defineProperty(j,"defaults",{enumerable:!0,configurable:!0,writable:!0,value:{classes:{container:"f-carousel__nav",button:"f-button",isNext:"is-next",isPrev:"is-prev"},nextTpl:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" tabindex="-1"><path d="M9 3l9 9-9 9"/></svg>',prevTpl:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" tabindex="-1"><path d="M15 3l-9 9 9 9"/></svg>'}});class F extends L{constructor(){super(...arguments),Object.defineProperty(this,"selectedIndex",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"target",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"nav",{enumerable:!0,configurable:!0,writable:!0,value:null})}addAsTargetFor(t){this.target=this.instance,this.nav=t,this.attachEvents()}addAsNavFor(t){this.nav=this.instance,this.target=t,this.attachEvents()}attachEvents(){this.nav&&this.target&&(this.nav.options.initialSlide=this.target.options.initialPage,this.nav.on("ready",this.onNavReady),this.nav.state===k.Ready&&this.onNavReady(this.nav),this.target.on("ready",this.onTargetReady),this.target.state===k.Ready&&this.onTargetReady(this.target))}onNavReady(t){t.on("createSlide",this.onNavCreateSlide),t.on("Panzoom.click",this.onNavClick),this.onTargetChange()}onTargetReady(t){t.on("change",this.onTargetChange),t.on("Panzoom.refresh",this.onTargetChange),this.onTargetChange()}onNavClick(t,e,i){var s,n;const o=i.target,{nav:a,target:r}=this;if(!a||!r||!o)return;const h=o.closest("[data-index]");if(!h)return;i.stopPropagation();const l=parseInt(h.dataset.index||"",10)||0,c=a.getPageForSlide(l);a.page!==c&&a.slideTo(c);const d=r.getPageForSlide(l);r.page!==d&&r.slideTo(d,{friction:null===(n=null===(s=this.nav)||void 0===s?void 0:s.plugins)||void 0===n?void 0:n.Sync.option("friction")}),this.markSelectedSlide(l)}onNavCreateSlide(t,e){e.index===this.selectedIndex&&this.markSelectedSlide(e.index)}onTargetChange(){const{target:t,nav:e}=this;if(!t||!e)return;if(e.state!==k.Ready||t.state!==k.Ready)return;const i=t.pages[t.page].slides[0].index,s=e.getPageForSlide(i);e.slideTo(s),this.markSelectedSlide(i)}markSelectedSlide(t){const{nav:e}=this;if(!e)return;this.selectedIndex=t,[...e.slides].filter((t=>t.el&&t.el.classList.remove("is-nav-selected")));const i=e.slides[t];i&&i.el&&i.el.classList.add("is-nav-selected")}attach(){let t=this.options.target,e=this.options.nav;t?this.addAsNavFor(t):e&&this.addAsTargetFor(e)}detach(){this.nav&&(this.nav.off("ready",this.onNavReady),this.nav.off("Panzoom.click",this.onNavClick),this.nav.off("createSlide",this.onNavCreateSlide)),this.nav=null,this.target&&(this.target.off("ready",this.onTargetReady),this.target.off("refresh",this.onTargetChange),this.target.off("change",this.onTargetChange)),this.target=null}}Object.defineProperty(F,"defaults",{enumerable:!0,configurable:!0,writable:!0,value:{friction:.35}});const H={Navigation:j,Dots:C,Sync:F};class I extends g{get axis(){return this.isHorizontal?"e":"f"}get isEnabled(){return this.state===k.Ready}get isInfinite(){let t=!1;const e=this.contentDim,i=this.viewportDim;return this.pages.length>=2&&e>1.5*i&&(t=this.option("infinite")),t}get isRTL(){return"rtl"===this.option("direction")}get isHorizontal(){return"x"===this.option("axis")}constructor(t,e={},s={}){if(super(),Object.defineProperty(this,"userOptions",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"userPlugins",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"bp",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:k.Init}),Object.defineProperty(this,"page",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"prevPage",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"container",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"viewport",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"track",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"slides",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"pages",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"panzoom",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"inTransition",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"contentDim",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"viewportDim",{enumerable:!0,configurable:!0,writable:!0,value:0}),"string"==typeof t&&(t=document.querySelector(t)),!t||!S(t))throw new Error("No Element found");this.container=t,this.slideNext=i(this.slideNext.bind(this),175),this.slidePrev=i(this.slidePrev.bind(this),175),this.userOptions=e,this.userPlugins=s,queueMicrotask((()=>{this.processOptions()}))}processOptions(){const i=e({},I.defaults,this.userOptions);let s="";const n=i.breakpoints;if(n&&t(n))for(const[o,a]of Object.entries(n))window.matchMedia(o).matches&&t(a)&&(s+=o,e(i,a));s===this.bp&&this.state!==k.Init||(this.bp=s,this.state===k.Ready&&(i.initialSlide=this.pages[this.page].slides[0].index),this.state!==k.Init&&this.destroy(),super.setOptions(i),!1===this.option("enabled")?this.attachEvents():setTimeout((()=>{this.init()}),0))}init(){this.state=k.Init,this.emit("init"),this.attachPlugins(Object.assign(Object.assign({},I.Plugins),this.userPlugins)),this.initLayout(),this.initSlides(),this.updateMetrics(),this.setInitialPosition(),this.initPanzoom(),this.attachEvents(),this.state=k.Ready,this.emit("ready")}initLayout(){const{container:t}=this,e=this.option("classes");r(t,this.cn("container")),l(t,e.isLTR,!this.isRTL),l(t,e.isRTL,this.isRTL),l(t,e.isVertical,!this.isHorizontal),l(t,e.isHorizontal,this.isHorizontal);let i=this.option("viewport")||t.querySelector(`.${e.viewport}`);i||(i=document.createElement("div"),r(i,e.viewport),i.append(...s(t,`.${e.slide}`)),t.prepend(i));let n=this.option("track")||t.querySelector(`.${e.track}`);n||(n=document.createElement("div"),r(n,e.track),n.append(...Array.from(i.childNodes))),n.setAttribute("aria-live","polite"),i.contains(n)||i.prepend(n),this.viewport=i,this.track=n,this.emit("initLayout")}initSlides(){const{track:t}=this;if(t){this.slides=[],[...s(t,`.${this.cn("slide")}`)].forEach((t=>{if(S(t)){const e=R({el:t,isDom:!0,index:this.slides.length});this.slides.push(e),this.emit("initSlide",e,this.slides.length)}}));for(let t of this.option("slides",[])){const e=R(t);e.index=this.slides.length,this.slides.push(e),this.emit("initSlide",t,this.slides.length)}this.emit("initSlides")}}setInitialPage(){let t=0;const e=this.option("initialSlide");t="number"==typeof e?this.getPageForSlide(e):parseInt(this.option("initialPage",0)+"",10)||0,this.page=t}setInitialPosition(){if(!this.track||!this.pages.length)return;let t=this.page;this.pages[t]||(this.page=t=0);const e=this.pages[t].pos*(this.isRTL&&this.isHorizontal?1:-1),i=this.isHorizontal?`${e}px`:"0",s=this.isHorizontal?"0":`${e}px`;this.track.style.transform=`translate3d(${i}, ${s}, 0) scale(1)`,this.option("adaptiveHeight")&&this.setViewportHeight()}initPanzoom(){this.panzoom&&(this.panzoom.destroy(),this.panzoom=null);const t=this.option("Panzoom")||{};this.panzoom=new E(this.viewport,e({},{content:this.track,zoom:!1,panOnlyZoomed:!1,lockAxis:this.isHorizontal?"x":"y",infinite:this.isInfinite,decelFriction:.12,click:!1,dblClick:!1,touch:t=>!(this.pages.length<2&&!t.options.infinite),bounds:()=>this.getBounds(),maxVelocity:t=>Math.abs(t.target[this.axis]-t.current[this.axis])<2*this.viewportDim?100:0},t)),this.panzoom.on("*",((t,e,...i)=>{this.emit(`Panzoom.${e}`,t,...i)})),this.panzoom.on("decel",this.onDecel),this.panzoom.on("refresh",this.onRefresh),this.panzoom.on("beforeTransform",this.onBeforeTransform),this.panzoom.on("endAnimation",this.onEndAnimation),this.panzoom.on("touchStart",((t,e)=>{this.inTransition.size&&e.preventDefault()}))}attachEvents(){const t=this.container;t&&(t.addEventListener("click",this.onClick,{passive:!1,capture:!1}),t.addEventListener("slideTo",this.onSlideTo)),window.addEventListener("resize",this.onResize)}createPages(){let t=[];const{contentDim:e,viewportDim:i}=this,s=this.option("slidesPerPage");if("number"==typeof s&&e>i){for(let e=0;e<this.slides.length;e+=s)t.push(D({index:e,slides:this.slides.slice(e,e+s)}));return t}let n=0,o=0;for(const e of this.slides)(!t.length||o+e.dim>i)&&(t.push(D()),n=t.length-1,o=0),o+=e.dim+e.gap,t[n].slides.push(e);return t}processPages(){const t=this.pages,{contentDim:e,viewportDim:i}=this,s=this.option("center"),n=this.option("fill");if(t.forEach(((t,e)=>{t.index=e,t.pos=t.slides[0].pos,t.dim=0;for(const[e,i]of t.slides.entries())t.dim+=i.dim,e<t.slides.length-1&&(t.dim+=i.gap);s&&(t.pos+=-.5*(i-t.dim))})),t.forEach(((t,s)=>{n&&!this.isInfinite&&e>i&&(t.pos=Math.max(t.pos,0),t.pos=Math.min(t.pos,e-i)),t.pos=o(t.pos,1e3),t.dim=o(t.dim,1e3)})),this.isInfinite)return t;const a=[];let r;return t.forEach((t=>{const e=Object.assign({},t);r&&e.pos===r.pos?(r.dim+=e.dim,r.slides=[...r.slides,...e.slides]):(e.index=a.length,r=e,a.push(e))})),a}getPageFromIndex(t=0){const e=this.pages.length;let i;return t=parseInt((t||0).toString())||0,i=this.isInfinite?(t%e+e)%e:Math.max(Math.min(t,this.pages.length-1),0),i}getSlideMetrics(t){const e=this.isHorizontal?"width":"height";let i=0,s=0,n=t.el;n?i=parseFloat(n.dataset[e]||"")||0:(n=document.createElement("div"),n.style.visibility="hidden",r(n,this.cn("slide")+" "+t.class),(this.track||document.body).prepend(n)),i?(n.style[e]=`${i}px`,n.style["width"===e?"height":"width"]=""):i=n.getBoundingClientRect()[e];const o=getComputedStyle(n);return"content-box"===o.boxSizing&&(this.isHorizontal?(i+=parseFloat(o.paddingLeft)||0,i+=parseFloat(o.paddingRight)||0):(i+=parseFloat(o.paddingTop)||0,i+=parseFloat(o.paddingBottom)||0)),s=parseFloat(o[this.isHorizontal?"marginRight":"marginBottom"])||0,this.isHorizontal,t.el||n.remove(),{dim:i,gap:s}}getBounds(){let t={min:0,max:0};if(this.isInfinite)t={min:-1/0,max:1/0};else if(this.pages.length){const e=this.pages[0].pos,i=this.pages[this.pages.length-1].pos;t=this.isRTL&&this.isHorizontal?{min:e,max:i}:{min:-1*i,max:-1*e}}return{x:this.isHorizontal?t:{min:0,max:0},y:this.isHorizontal?{min:0,max:0}:t}}repositionSlides(){const{viewportDim:t,contentDim:e,page:i,pages:s}=this;let n,a=0,r=0,h=0,l=0;this.panzoom?l=-1*this.panzoom.current[this.isHorizontal?"e":"f"]:s[i]&&(l=s[i].pos||0),n=this.isHorizontal?this.isRTL?"right":"left":"top",this.isRTL&&this.isHorizontal&&(l*=-1);for(const t of this.slides)t.el?("top"===n?(t.el.style.right="",t.el.style.left=""):t.el.style.top="",t.index!==a?t.el.style[n]=0===r?"":`${r}px`:t.el.style[n]="",h+=t.dim+t.gap,a++):r+=t.dim+t.gap;if(this.isInfinite&&h)for(const i of this.slides)i.el&&(o(i.pos)<o(t)&&o(i.pos+i.dim+i.gap)<o(l)&&o(l)>o(e-t)&&(i.el.style[n]=`${r+h}px`),o(i.pos+i.gap)>=o(e-t)&&o(i.pos)>o(l+t)&&o(l)<o(t)&&(i.el.style[n]=`-${h}px`));let c,d,u=[...this.inTransition];if(u.length>1&&(c=this.pages[u[0]],d=this.pages[u[1]]),c&&d){let t=0;for(const e of this.slides)e.el?this.inTransition.has(e.index)&&c.slides.indexOf(e)<0&&(e.el.style[n]=`${t+(c.pos-d.pos)}px`):t+=e.dim+e.gap}}createSlideEl(t){if(!this.track||!t)return;if(t.el)return;const e=document.createElement("div");r(e,this.cn("slide")),r(e,t.class),t.html&&(e.innerHTML=t.html);const i=[];this.slides.forEach(((t,e)=>{t.el&&i.push(e)}));const s=t.index;let n=null;if(i.length){let t=i.reduce(((t,e)=>Math.abs(e-s)<Math.abs(t-s)?e:t));n=this.slides[t]}const o=n&&n.el?n.index<t.index?n.el.nextSibling:n.el:null;this.track.insertBefore(e,this.track.contains(o)?o:null),t.el=e,this.emit("createSlide",t)}removeSlideEl(t,e=!1){const i=t.el;if(!i)return;if(h(i,this.cn("isSelected")),t.isDom&&!e)return void(i.style.left="");this.emit("removeSlide",t);const s=new CustomEvent("animationend");i.dispatchEvent(s),t.el&&t.el.remove(),t.el=null}transitionTo(t=0,e=this.option("transition")){if(!e)return!1;const{pages:i,panzoom:s}=this;t=parseInt((t||0).toString())||0;const n=this.getPageFromIndex(t);if(!s||!i[n]||i.length<2||i[this.page].slides[0].dim<this.viewportDim)return!1;const o=t>this.page?1:-1,a=this.pages[n].pos*(this.isRTL?1:-1);if(this.page===n&&a===s.target[this.axis])return!1;this.clearTransitions();const h=s.isResting;r(this.container,this.cn("inTransition"));const l=this.pages[this.page].slides[0],c=this.pages[n].slides[0];this.inTransition.add(c.index),this.createSlideEl(c);let d=l.el,u=c.el;h||"slide"===e||(e="fadeFast",d=null);const g=this.isRTL?"next":"prev",p=this.isRTL?"prev":"next";return d&&(this.inTransition.add(l.index),l.transition=e,d.addEventListener("animationend",this.onAnimationEnd),d.classList.add(`f-${e}Out`,`to-${o>0?p:g}`)),u&&(c.transition=e,u.addEventListener("animationend",this.onAnimationEnd),u.classList.add(`f-${e}In`,`from-${o>0?g:p}`)),s.panTo({x:this.isHorizontal?a:0,y:this.isHorizontal?0:a,friction:0}),this.onChange(n),!0}manageSlideVisiblity(){const t=new Set,e=new Set,i=this.getVisibleSlides(parseFloat(this.option("preload",0)+"")||0);for(const s of this.slides)i.has(s)?t.add(s):e.add(s);for(const e of this.inTransition)t.add(this.slides[e]);for(const e of t)this.createSlideEl(e),this.lazyLoadSlide(e);for(const i of e)t.has(i)||this.removeSlideEl(i);this.markSelectedSlides(),this.repositionSlides()}markSelectedSlides(){if(!this.pages[this.page]||!this.pages[this.page].slides)return;const t="aria-hidden";let e=this.cn("isSelected");if(e)for(const i of this.slides)i.el&&(i.el.dataset.index=`${i.index}`,this.pages[this.page].slides.includes(i)?(i.el.classList.contains(e)||(r(i.el,e),this.emit("selectSlide",i)),i.el.removeAttribute(t)):(i.el.classList.contains(e)&&(h(i.el,e),this.emit("unselectSlide",i)),i.el.setAttribute(t,"true")))}flipInfiniteTrack(){const t=this.panzoom;if(!t||!this.isInfinite)return;const e="x"===this.option("axis")?"e":"f",{viewportDim:i,contentDim:s}=this;let n=t.current[e],o=t.target[e]-n,a=0,r=.5*i,h=s;this.isRTL&&this.isHorizontal?(n<-r&&(a=-1,n+=h),n>h-r&&(a=1,n-=h)):(n>r&&(a=1,n-=h),n<-h+r&&(a=-1,n+=h)),a&&(t.current[e]=n,t.target[e]=n+o)}lazyLoadSlide(t){const e=this,i=t&&t.el;if(!i)return;const s=new Set;i.querySelectorAll("[data-lazy-srcset]").forEach((t=>{t instanceof HTMLImageElement&&s.add(t)})),i.querySelectorAll("[data-lazy-src]").forEach((t=>{t instanceof HTMLImageElement?s.add(t):S(t)&&(t.style.backgroundImage=`url('${t.dataset.lazySrc||""}')`)}));const o=(t,i,s)=>{s&&(s.remove(),s=null),i.complete&&(i.style.display=""),this.option("adaptiveHeight")&&t.el&&this.pages[this.page].slides.indexOf(t)>-1&&e.setViewportHeight()};for(const e of s){let i=null;e.src=e.dataset.lazySrcset||e.dataset.lazySrc||"",delete e.dataset.lazySrc,delete e.dataset.lazySrcset,e.style.display="none",e.addEventListener("error",(()=>{o(t,e,i)})),e.addEventListener("load",(()=>{o(t,e,i)})),setTimeout((()=>{!e.complete&&e.parentNode&&t.el&&(i=n(c),e.parentNode.insertBefore(i,e))}),300)}let a=i.dataset.lazySrc;a&&a.length&&(i.style.backgroundImage=`url('${a}')`)}clearTransitions(){this.inTransition.clear(),h(this.container,this.cn("inTransition"));const t=["to-prev","to-next","from-prev","from-next"];for(const e of this.slides){const i=e.el;if(i){i.removeEventListener("animationend",this.onAnimationEnd),i.classList.remove(...t);const s=e.transition;s&&i.classList.remove(`f-${s}Out`,`f-${s}In`)}}this.manageSlideVisiblity()}onAnimationEnd(t){const e=t.target,i=e?parseInt(e.dataset.index||"",10)||0:-1,s=this.slides[i],n=t.animationName;if(!e||!s||!n)return;const o=!!this.inTransition.has(i)&&s.transition;o&&n.substring(0,o.length+2)===`f-${o}`&&this.inTransition.delete(i),this.inTransition.size||this.clearTransitions(),i===this.page&&this.emit("settle")}onDecel(t,e=0,i=0){const s=this.isInfinite,n=this.isHorizontal?e:i,o=this.pages.length;if(!o)return;const a=this.option("dragFree");let r=this.page,h=0;const l=this.axis;!s&&(t.target[l],this.viewportDim);const c=t.current[l]*(this.isRTL&&this.isHorizontal?1:-1);let{pageIndex:d}=this.getPageFromPosition(c);if(a||Math.abs(n)<10){const e=t.target[l]*(this.isRTL&&this.isHorizontal?1:-1),{pageIndex:i}=this.getPageFromPosition(e);r=i}else r=this.isRTL&&this.isHorizontal?n<0?d-1:d+1:n<0?d+1:d-1,s||(r=Math.max(0,Math.min(r,this.pages.length-1)));if(s&&(h=Math.floor(r/o)||0),r=(r%o+o)%o,a&&t.dragOffset["e"===l?"x":"y"]);else{const e=this.contentDim;let i=(this.pages[r].pos+h*e)*(this.isRTL&&this.isHorizontal?1:-1);if(Math.abs(t.target[l]-i)<.1&&t.lockedAxis===("e"==l?"y":"x"))return;if(t.target[l]===i)return;t.applyChange({panX:this.isHorizontal?i-t.target.e:0,panY:this.isHorizontal?0:i-t.target.f,friction:t.option("decelFriction")})}r!==this.page&&this.onChange(r)}onClick(t){const e=t.target,i=e&&S(e)?e.dataset:null;let s;i&&(void 0!==i.carouselPage?s="slideTo":void 0!==i.carouselNext?s="slideNext":void 0!==i.carouselPrev&&(s="slidePrev")),s?(t.preventDefault(),t.stopPropagation(),e&&!e.hasAttribute("disabled")&&this[s](i&&"slideTo"===s?i.carouselPage:void 0)):this.emit("click",t)}onSlideTo(t){const e=t.detail||0;this.slideTo(this.getPageForSlide(e),{friction:0})}onChange(t,e=0){const i=this.page;this.prevPage=i,this.page=t,this.option("adaptiveHeight")&&this.setViewportHeight(),this.emit("change",t,i,e)}onRefresh(t,e=""){let i=this.contentDim,s=this.viewportDim;this.updateMetrics(),this.contentDim===i&&this.viewportDim===s||this.slideTo(this.page,{friction:0,transition:!1})}onResize(){this.option("breakpoints")&&this.processOptions()}onBeforeTransform(){this.flipInfiniteTrack(),this.manageSlideVisiblity()}onEndAnimation(){this.emit("settle")}reInit(t=null,e=null){this.destroy(),this.state=k.Init,this.userOptions=t||this.userOptions,this.userPlugins=e||this.userPlugins,this.processOptions()}slideTo(t=0,{friction:e=this.option("friction"),transition:i=this.option("transition")}={}){const s=this.panzoom,n=this.pages.length;if(!s||!n)return;if(this.transitionTo(t,i))return;const o=this.axis,a=this.getPageFromIndex(t);let r=this.pages[a].pos,h=0;if(this.isInfinite){const t=s.current[o]*(this.isRTL&&this.isHorizontal?1:-1),e=this.contentDim,i=r+e,n=r-e;Math.abs(t-i)<Math.abs(t-r)&&(r=i,h=1),Math.abs(t-n)<Math.abs(t-r)&&(r=n,h=-1)}r*=this.isRTL&&this.isHorizontal?1:-1,Math.abs(s.target[o]-r)<.1||(s.applyChange({panX:this.isHorizontal?r-s.target.e:0,panY:this.isHorizontal?0:r-s.target.f,friction:e}),this.onChange(a,h))}slideToClosest(t){if(this.panzoom){const{pageIndex:e}=this.getPageFromPosition(this.panzoom.current.e);this.slideTo(e,t)}}slideNext(){this.slideTo(this.page+1)}slidePrev(){this.slideTo(this.page-1)}prependSlide(t){var e,i;let s=Array.isArray(t)?t:[t];for(const t of s.reverse())this.slides.unshift(R(t));for(let t=0;t<this.slides.length;t++)this.slides[t].index=t;const n=(null===(e=this.pages[this.page])||void 0===e?void 0:e.pos)||0;this.page+=s.length,this.updateMetrics();const o=(null===(i=this.pages[this.page])||void 0===i?void 0:i.pos)||0;if(this.panzoom){const t=this.isRTL?n-o:o-n;this.panzoom.target.e-=t,this.panzoom.current.e-=t,this.panzoom.requestTick()}}appendSlide(t){let e=Array.isArray(t)?t:[t];for(const t of e){const e=R(t);e.index=this.slides.length,this.slides.push(e),this.emit("initSlide",t,this.slides.length)}this.updateMetrics()}removeSlide(t){const e=this.slides.length;t=(t%e+e)%e,this.removeSlideEl(this.slides[t],!0),this.slides.splice(t,1);for(let t=0;t<this.slides.length;t++)this.slides[t].index=t;this.updateMetrics(),this.slideTo(this.page,{friction:0,transition:!1})}updateMetrics(){if(!this.track)return;const t="e"===this.axis?"width":"height";let e,i=0;for(const[t,s]of this.slides.entries()){let n=0,a=0;!s.el&&e?(n=e.dim,a=e.gap):(({dim:n,gap:a}=this.getSlideMetrics(s)),e=s),s.dim=o(n,1e3),s.gap=o(a,1e3),s.pos=o(i,1e3),i+=n,(this.isInfinite||t<this.slides.length-1)&&(i+=a)}this.viewport&&(this.viewportDim=o(this.viewport.getBoundingClientRect()[t],1e3)),this.contentDim=o(i,1e3),this.panzoom&&(this.panzoom.contentRect[t]=this.contentDim,this.panzoom.contentRect["e"===this.axis?"fullWidth":"fullHeight"]=this.contentDim),this.pages=this.createPages(),this.pages=this.processPages(),this.state===k.Init&&this.setInitialPage(),this.page=Math.max(0,Math.min(this.page,this.pages.length-1)),this.manageSlideVisiblity(),this.emit("refresh")}setViewportHeight(){const{page:t,pages:e,viewport:i,isHorizontal:s}=this;if(!i||!e[t])return;let n=0;s&&this.track&&(this.track.style.height="auto",e[t].slides.forEach((t=>{t.el&&(n=Math.max(n,t.el.offsetHeight))}))),i.style.height=n?`${n}px`:""}getPageForSlide(t){for(const e of this.pages)for(const i of e.slides)if(i.index===t)return e.index;return-1}getVisibleSlides(t=0){var e;const i=new Set;let{contentDim:s,viewportDim:n,pages:a,page:r}=this;s=s+(null===(e=this.slides[this.slides.length-1])||void 0===e?void 0:e.gap)||0;let h=0;h=this.panzoom?-1*this.panzoom.current[this.axis]:a[r]&&a[r].pos||0,this.isInfinite&&(h-=Math.floor(h/s)*s),this.isRTL&&this.isHorizontal&&(h*=-1),h=o(h,1e3);const l=o(h-n*t,1e3),c=o(h+n*(t+1),1e3),d=this.isInfinite?[-1,0,1]:[0];for(const t of this.slides)for(const e of d){const n=t.pos+e*s,o=t.pos+t.dim+t.gap+e*s;n<c&&o>l&&i.add(t)}return i}getPageFromPosition(t){const{viewportDim:e,contentDim:i}=this,s=this.pages.length;let n=0,o=0;const a=this.option("center");a&&(t+=.5*e),this.isInfinite||(t=Math.max(this.slides[0].pos,Math.min(t,this.slides[this.slides.length-1].pos)));const r=i+this.slides[this.slides.length-1].gap,h=Math.floor(t/r)||0;t-=h*r;let l=this.slides[this.slides.length-1],c=this.slides.find((e=>{const i=t+(l&&!a?.5*l.dim:0);return l=e,e.pos<=i&&e.pos+e.dim+e.gap>i}));return c||(c=this.slides[this.slides.length-1]),o=this.getPageForSlide(c.index),n=o+h*s,{page:n,pageIndex:o}}destroy(){if([k.Destroy].includes(this.state))return;this.state=k.Destroy;const{container:t,viewport:e,track:i,slides:s,panzoom:n}=this,o=this.option("classes");t.removeEventListener("click",this.onClick,{passive:!1,capture:!1}),t.removeEventListener("slideTo",this.onSlideTo),window.removeEventListener("resize",this.onResize),n&&(n.destroy(),this.panzoom=null),s&&s.forEach((t=>{this.removeSlideEl(t)})),this.detachPlugins(),this.track=null,this.viewport=null,this.page=0,e&&i&&e.replaceWith(...i.childNodes);for(const[e,i]of Object.entries(o))"container"!==e&&i&&t.classList.remove(i);this.slides=[];const a=this.events.get("ready");this.events=new Map,a&&this.events.set("ready",a)}}Object.defineProperty(I,"Panzoom",{enumerable:!0,configurable:!0,writable:!0,value:E}),Object.defineProperty(I,"defaults",{enumerable:!0,configurable:!0,writable:!0,value:z}),Object.defineProperty(I,"Plugins",{enumerable:!0,configurable:!0,writable:!0,value:H});export{I as Carousel};