UNPKG

@fancyapps/ui

Version:

Robust JavaScript UI Component Library

1 lines 28.4 kB
!/*! License details at fancyapps.com/license */function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).window=e.window||{})}(this,function(e){"use strict";let t,n=function(e){if(!(e&&e instanceof Element&&e.offsetParent))return!1;let t=!1,n=!1;if(e.scrollWidth>e.clientWidth){let n=window.getComputedStyle(e).overflowX,o=-1!==n.indexOf("hidden"),i=-1!==n.indexOf("clip"),a=-1!==n.indexOf("visible");t=!o&&!i&&!a}if(e.scrollHeight>e.clientHeight){let t=window.getComputedStyle(e).overflowY,o=-1!==t.indexOf("hidden"),i=-1!==t.indexOf("clip"),a=-1!==t.indexOf("visible");n=!o&&!i&&!a}return t||n},o=function(e,t){return!e||e===document.body||t&&e===t?null:n(e)?e:o(e.parentElement,t)},i=function(e){var t=new DOMParser().parseFromString(e,"text/html").body;if(t.childElementCount>1){for(var n=document.createElement("div");t.firstChild;)n.appendChild(t.firstChild);return n}let o=t.firstChild;if(o&&!(o instanceof HTMLElement)){var n=document.createElement("div");return n.appendChild(o),n}return o},a=function(e=0,t=0,n=0){return Math.max(Math.min(t,n),e)};function r(e){return"object"==typeof e&&null!==e&&e.constructor===Object&&"[object Object]"===Object.prototype.toString.call(e)||Array.isArray(e)}function l(e,t){let n=Object.keys(e),o=Object.keys(t);return n.length===o.length&&n.every(n=>{let o=e[n],i=t[n];return"function"==typeof o?`${o}`==`${i}`:r(o)&&r(i)?l(o,i):o===i})}let s=1/60*3e3,c=function(e){for(let t of b)t.getState()===u.Running&&t.tick(x?e-x:0);x=e,w=window.requestAnimationFrame(c)},u=((f={})[f.Initializing=0]="Initializing",f[f.Running=1]="Running",f[f.Paused=2]="Paused",f[f.Completed=3]="Completed",f[f.Destroyed=4]="Destroyed",f);var f,d,h,g,m,p,v=((d=v||{})[d.Spring=0]="Spring",d[d.Ease=1]="Ease",d);let y=((h={})[h.Loop=0]="Loop",h[h.Reverse=1]="Reverse",h),b=new Set,w=null,x=0;function M(){let e=u.Initializing,t=v.Ease,n=0,o=0,i=M.Easings.Linear,r=500,f=0,d=0,h=0,g=0,m=1/0,p=.01,x=.01,E=!1,T={},L=null,S={},k={},C={},A=0,R=0,O=y.Loop,F=M.Easings.Linear,P=new Map;function I(e,...t){for(let n of P.get(e)||[])n(...t)}function Z(e){return o=0,e?L=setTimeout(()=>{z()},e):z(),X}function z(){e=u.Running,I("start",S,k)}function D(){if(e=u.Completed,C={},I("end",S),e===u.Completed)if(n<A){if(n++,O===y.Reverse){let e={...T};T={...k},k=e}Z(R)}else n=0;return X}let X={getState:function(){return e},easing:function(e){return i=e,t=v.Ease,C={},X},duration:function(e){return r=e,X},spring:function(e={}){t=v.Spring;let{velocity:n,mass:o,tension:i,friction:a,restDelta:r,restSpeed:l,maxSpeed:s,clamp:c}={velocity:0,mass:1,tension:170,friction:26,restDelta:.1,restSpeed:.1,maxSpeed:1/0,clamp:!0,...e};return f=n,d=o,h=i,g=a,x=r,p=l,m=s,E=c,C={},X},isRunning:function(){return e===u.Running},isSpring:function(){return t===v.Spring},from:function(e){return S={...e},X},to:function(e){return k=e,X},repeat:function(e,t=0,n=y.Loop,o){return A=e,R=t,O=n,F=o||i,X},on:function(e,t){return P.set(e,[...P.get(e)||[],t]),X},off:function(e,t){return P.has(e)&&P.set(e,P.get(e).filter(e=>e!==t)),X},start:function(t){return l(S,k)||(e=u.Initializing,T={...S},b.add(this),w||(w=window.requestAnimationFrame(c)),Z(t)),X},pause:function(){return L&&(clearTimeout(L),L=null),e===u.Running&&(e=u.Paused,I("pause",S)),X},end:D,tick:function(n){n>s&&(n=s),o+=n;let c=0,b=!1;if(e!==u.Running)return X;if(t===v.Ease){b=1===(c=a(0,o/r,1));let e=O===y.Reverse?F:i;for(let t in S)S[t]=T[t]+(k[t]-T[t])*e(c)}if(t===v.Spring){let e=.001*n,t=0;for(let n in S){let o=k[n],i=S[n];if(!("number"==typeof o&&!isNaN(o))||!("number"==typeof i&&!isNaN(i)))continue;if(Math.abs(o-i)<=x){S[n]=o,C[n]=0;continue}C[n]||("object"==typeof f&&"number"==typeof f[n]?C[n]=f[n]:"number"==typeof f?C[n]=f:C[n]=0);let r=C[n],l=(r=a(-1*Math.abs(m),r,Math.abs(m)))*d*g,s=Math.abs(o-i)*h;r+=((i>o?-1:1)*s-l)/d*e,i+=r*e;let c=S[n]>o?i<o:i>o,u=Math.abs(r)<p&&Math.abs(o-i)<=x;E&&c&&(u=!0),u?(i=o,r=0):t++,S[n]=i,C[n]=r}b=!t}let w={...k};return I("step",S,T,k,c),b&&e===u.Running&&l(k,w)&&(e=u.Completed,D()),X},getStartValues:function(){return T},getCurrentValues:function(){return S},getCurrentVelocities:function(){return C},getEndValues:function(){return k},destroy:function(){e=u.Destroyed,L&&(clearTimeout(L),L=null),T=S=k={},b.delete(this)}};return X}function E(e,t){let n=[];for(let o of"undefined"!=typeof TouchEvent&&e instanceof TouchEvent?e[t]:e instanceof MouseEvent&&("changedTouches"===t||"mouseup"!==e.type)?[e]:[])n.push({x:o.clientX,y:o.clientY,ts:Date.now()});return n}function T(e){return E(e,"touches")}function L(e){return E(e,"targetTouches")}function S(e){return E(e,"changedTouches")}function k(e){let t=e[0],n=e[1]||t;return{x:(t.x+n.x)/2,y:(t.y+n.y)/2,ts:n.ts}}function C(e){let t=e[0],n=e[1]||e[0];return t&&n?-1*Math.sqrt((n.x-t.x)*(n.x-t.x)+(n.y-t.y)*(n.y-t.y)):0}M.destroy=()=>{for(let e of b)e.destroy();w&&(cancelAnimationFrame(w),w=null)},M.Easings={Linear:function(e){return e},EaseIn:function(e){return 0===e?0:Math.pow(2,10*e-10)},EaseOut:function(e){return 1===e?1:1-Math.pow(2,-10*e)},EaseInOut:function(e){return 0===e?0:1===e?1:e<.5?Math.pow(2,20*e-10)/2:(2-Math.pow(2,-20*e+10))/2}};let A=e=>{e.cancelable&&e.preventDefault()},R={passive:!1},O={panThreshold:5,swipeThreshold:3,ignore:["textarea","input","select","[contenteditable]","[data-selectable]","[data-draggable]"]},F=!1,P=!0,I=(e,t)=>{let n,o,i,a={...O,...t},r=[],l=[],s=[],c=!1,u=!1,f=!1,d=!1,h=0,g=0,m=0,p=0,v=0,y=0,b=0,w=0,x=0,M=[],E=0,I=0,Z=new Map;function z(e){let t=C(l),a=C(s),f=Math.abs(b)>Math.abs(w)?b:w,d={srcEvent:i,isPanRecognized:c,isSwipeRecognized:u,firstTouch:r,previousTouch:s,currentTouch:l,deltaX:m,deltaY:p,offsetX:v,offsetY:y,velocityX:b,velocityY:w,velocity:f,angle:x,axis:o,scale:t&&a?t/a:0,center:n};for(let t of Z.get(e)||[])t(d)}function D(e){let t=e.target,n=e.composedPath()[0],o=a.ignore.join(","),i=e=>e&&(e.matches(o)||e.closest(o));if(i(t)||i(n))return!1}function X(e){let t=Date.now();if(M=M.filter(e=>!e.ts||e.ts>t-100),e&&M.push(e),b=0,w=0,M.length>3){let e=M[0],t=M[M.length-1];if(e&&t){let n=t.x-e.x,o=t.y-e.y,i=e.ts&&t.ts?t.ts-e.ts:0;i>0&&(b=Math.abs(n)>3?n/(i/30):0,w=Math.abs(o)>3?o/(i/30):0)}}}function Y(e){if(!1===D(e))return;if("undefined"!=typeof MouseEvent&&e instanceof MouseEvent){if(F)return}else F=!0;if("undefined"!=typeof MouseEvent&&e instanceof MouseEvent){if(!e.buttons||0!==e.button)return;A(e)}e instanceof MouseEvent&&(window.addEventListener("mousemove",_),window.addEventListener("mouseup",H)),window.addEventListener("blur",j),i=e,r=[...l=L(e)],s=[],g=l.length,n=k(l),1===g&&(c=!1,u=!1,f=!1),g&&X(k(l));let t=Date.now(),o=t-(h||t);d=o>0&&o<=250&&1===g,h=t,clearTimeout(E),z("start")}function _(e){if(!r.length||e.defaultPrevented||!1===D(e))return;i=e,s=[...l],l=T(e);let t=k(s),u=k(T(e));if(X(u),g=l.length,n=u,s.length===l.length?(m=u.x-t.x,p=u.y-t.y):(m=0,p=0),r.length){let e=k(r);v=u.x-e.x,y=u.y-e.y}l.length>1&&Math.abs(C(l)-C(s))>=.1&&(f=!0,z("pinch")),!c&&(c=Math.abs(v)>a.panThreshold||Math.abs(y)>a.panThreshold)&&(P=!1,clearTimeout(I),I=0,o=(x=Math.abs(180*Math.atan2(y,v)/Math.PI))>45&&x<135?"y":"x",r=[...l],s=[...l],v=0,y=0,m=0,p=0,window.getSelection()?.removeAllRanges(),z("panstart")),c&&(m||p)&&z("pan"),z("move")}function H(e){if(i=e,!r.length)return;let t=L(e),o=S(e);if(g=t.length,n=k(o),o.length&&X(k(o)),s=[...l],l=[...t],r=[...t],g>0)z("end"),c=!1,u=!1,M=[];else{let e=a.swipeThreshold;(Math.abs(b)>e||Math.abs(w)>e)&&(u=!0),c&&z("panend"),u&&z("swipe"),c||u||f||(z("tap"),d?z("doubleTap"):E=setTimeout(function(){z("singleTap")},250)),z("end"),W()}}function j(){clearTimeout(E),W(),c&&z("panend"),z("end")}function W(){F=!1,c=!1,u=!1,d=!1,g=0,M=[],l=[],s=[],r=[],m=0,p=0,v=0,y=0,b=0,w=0,x=0,o=void 0,window.removeEventListener("mousemove",_),window.removeEventListener("mouseup",H),window.removeEventListener("blur",j),P||I||(I=setTimeout(()=>{P=!0,I=0},100))}function q(e){let t=e.target;F=!1,t&&!e.defaultPrevented&&(P||(A(e),e.stopPropagation()))}let V={init:function(){return e&&(e.addEventListener("click",q,R),e.addEventListener("mousedown",Y,R),e.addEventListener("touchstart",Y,R),e.addEventListener("touchmove",_,R),e.addEventListener("touchend",H),e.addEventListener("touchcancel",H)),V},on:function(e,t){return Z.set(e,[...Z.get(e)||[],t]),V},off:function(e,t){return Z.has(e)&&Z.set(e,Z.get(e).filter(e=>e!==t)),V},isPointerDown:()=>g>0,destroy:function(){clearTimeout(E),clearTimeout(I),I=0,e&&(e.removeEventListener("click",q,R),e.removeEventListener("mousedown",Y,R),e.removeEventListener("touchstart",Y,R),e.removeEventListener("touchmove",_,R),e.removeEventListener("touchend",H),e.removeEventListener("touchcancel",H)),e=null,W()}};return V};I.isClickAllowed=()=>P;let Z={IMAGE_ERROR:"This image couldn't be loaded. <br /> Please try again later.",MOVE_UP:"Move up",MOVE_DOWN:"Move down",MOVE_LEFT:"Move left",MOVE_RIGHT:"Move right",ZOOM_IN:"Zoom in",ZOOM_OUT:"Zoom out",TOGGLE_FULL:"Toggle zoom level",TOGGLE_1TO1:"Toggle zoom level",ITERATE_ZOOM:"Toggle zoom level",ROTATE_CCW:"Rotate counterclockwise",ROTATE_CW:"Rotate clockwise",FLIP_X:"Flip horizontally",FLIP_Y:"Flip vertically",RESET:"Reset",TOGGLE_FS:"Toggle fullscreen"},z=(e,t="")=>{e&&e.classList&&t.split(" ").forEach(t=>{t&&e.classList.add(t)})},D=(e,t="")=>{e&&e.classList&&t.split(" ").forEach(t=>{t&&e.classList.remove(t)})},X=(e,t="",n)=>{e&&e.classList&&t.split(" ").forEach(t=>{t&&e.classList.toggle(t,n||!1)})},Y=1e4,_=e=>{e.cancelable&&e.preventDefault()},H=(e,t=Y)=>Math.round(((e=parseFloat(e+"")||0)+Number.EPSILON)*t)/t,j=((g={}).Reset="reset",g.Zoom="zoom",g.ZoomIn="zoomIn",g.ZoomOut="zoomOut",g.ZoomTo="zoomTo",g.ToggleCover="toggleCover",g.ToggleFull="toggleFull",g.ToggleMax="toggleMax",g.IterateZoom="iterateZoom",g.Pan="pan",g.Swipe="swipe",g.Move="move",g.MoveLeft="moveLeft",g.MoveRight="moveRight",g.MoveUp="moveUp",g.MoveDown="moveDown",g.RotateCCW="rotateCCW",g.RotateCW="rotateCW",g.FlipX="flipX",g.FlipY="flipY",g.ToggleFS="toggleFS",g),W=((m={}).Cover="cover",m.Full="full",m.Max="max",m),q={x:0,y:0,scale:1,angle:0,flipX:1,flipY:1},V=((p={})[p.Init=0]="Init",p[p.Loading=1]="Loading",p[p.Error=2]="Error",p[p.Ready=3]="Ready",p[p.Destroyed=4]="Destroyed",p),$={bounds:!0,classes:{container:"f-panzoom",wrapper:"f-panzoom__wrapper",content:"f-panzoom__content",viewport:"f-panzoom__viewport"},clickAction:j.ToggleFull,dblClickAction:!1,gestures:{},height:"auto",l10n:Z,maxScale:4,minScale:1,mouseMoveFactor:1,panMode:"drag",protected:!1,singleClickAction:!1,spinnerTpl:'<div class="f-spinner"></div>',wheelAction:j.Zoom,width:"auto"},N=0,G=0,U=0,B=(e,n={},r={})=>{let s,c,u,f,d,h,g,m,p=V.Init,v={...$,...n},y={},b={...q},w={...q},x=[];function E(e){let t=v[e];return t&&"function"==typeof t?t(eE):t}function T(){return e&&e.parentElement&&s&&p===V.Ready}let L=new Map;function C(e,...t){let n=[...L.get(e)||[]];for(let o of(v.on&&n.push(v.on[e]),n))o&&o instanceof Function&&o(eE,...t);"*"!==e&&C("*",e,...t)}function A(e){if(!T()||o(e.target))return;let t=Date.now(),n=a(-1,[-e.deltaX||0,-e.deltaY||0,-e.detail||0].reduce(function(e,t){return Math.abs(t)>Math.abs(e)?t:e}),1);C("wheel",e,n);let i=E("wheelAction");if(!i||e.defaultPrevented)return;let r=w.scale,l=r*(n>0?1.5:.5);if(i===j.Zoom){let o=100>Math.abs(e.deltaY)&&100>Math.abs(e.deltaX);if(t-G<(o?200:45))return void _(e);G=t;let i=et(),s=ea();if(H(l)<H(i)&&H(r)<=H(i)?(U+=Math.abs(n),l=i):H(l)>H(s)&&H(r)>=H(s)?(U+=Math.abs(n),l=s):(U=0,l=a(i,l,s)),U>7)return}switch(_(e),i){case j.Pan:ec(i,{srcEvent:e,deltaX:-(2*e.deltaX),deltaY:-(2*e.deltaY)});break;case j.Zoom:ec(j.ZoomTo,{srcEvent:e,scale:l,center:{x:e.clientX,y:e.clientY}});break;default:ec(i,{srcEvent:e})}}function R(n){let o=n.composedPath()[0];if(!I.isClickAllowed()||!(o&&null!==o&&o instanceof Element&&"nodeType"in o)||n.defaultPrevented||!e?.contains(o)||o.hasAttribute("disabled")||o.hasAttribute("aria-disabled")||o.hasAttribute("data-carousel-go-prev")||o.hasAttribute("data-carousel-go-next"))return;let i=o.closest("[data-panzoom-action]"),a=i?.dataset?.panzoomAction,r=i?.dataset?.panzoomValue||"";if(a){switch(_(n),a){case j.ZoomTo:case j.ZoomIn:case j.ZoomOut:ec(a,{scale:parseFloat(r||"")||void 0});break;case j.MoveLeft:case j.MoveRight:ec(a,{deltaX:parseFloat(r||"")||void 0});break;case j.MoveUp:case j.MoveDown:ec(a,{deltaY:parseFloat(r||"")||void 0});break;case j.ToggleFS:ex();break;default:ec(a)}return}if(!s?.contains(o))return;let l={srcEvent:n};if(ec(E("clickAction"),l),E("dblClickAction")){let e=Date.now(),n=e-(N||e);N=e,n>0&&n<=250?(t&&(clearTimeout(t),t=void 0),ec(E("dblClickAction"),l)):t=setTimeout(()=>{ec(E("singleClickAction"),l)},250)}}function O(e){if(m=e,!T()||!K()||b.scale<=1||w.scale<=1||(s?.dataset.animationName||"").indexOf("zoom")>-1)return;let t=Q(w.scale);if(!t)return;let{x:n,y:o}=t;ec(j.Pan,{deltaX:n-w.x,deltaY:o-w.y})}function F(){e&&(D(e,"is-loading"),e.querySelector(".f-spinner")?.remove())}function P(){if(!e||!c)return;if(F(),c instanceof HTMLImageElement&&!(c.complete&&c.naturalWidth)){p=V.Error,s?.classList.add("has-error"),C("error");return}C("loaded");let{width:t,height:n}=B();c instanceof HTMLImageElement&&(c.setAttribute("width",t+""),c.setAttribute("height",n+"")),s&&(D(s,"has-error"),c instanceof HTMLImageElement&&(s.setAttribute("width",t+""),s.setAttribute("height",n+""),s.style.aspectRatio=`${t/n||""}`)),h=M().on("start",(e,t)=>{void 0!==t.angle&&(t.angle=90*Math.round(t.angle/90)),void 0!==t.flipX&&(t.flipX=t.flipX>0?1:-1),void 0!==t.flipY&&(t.flipY=t.flipY>0?1:-1),w={...q,...t},es(),C("animationStart")}).on("pause",e=>{w={...q,...e}}).on("step",e=>{if(!T())return void h?.end();if(b={...q,...e},K()||!E("bounds")||ey()||w.scale>b.scale||w.scale<en())return void eu();let t=er(w.scale),n=!1,o=!1,i=!1,r=!1;b.x<t.x[0]&&(n=!0),b.x>t.x[1]&&(o=!0),b.y<t.y[0]&&(r=!0),b.y>t.y[1]&&(i=!0);let l=!1,s=!1,c=!1,u=!1;w.x<t.x[0]&&(l=!0),w.x>t.x[1]&&(s=!0),w.y<t.y[0]&&(u=!0),w.y>t.y[1]&&(c=!0);let f=!1;(o&&s||n&&l)&&(w.x=a(t.x[0],w.x,t.x[1]),f=!0),(i&&c||r&&u)&&(w.y=a(t.y[0],w.y,t.y[1]),f=!0),f&&h&&h.spring({tension:94,friction:17,maxSpeed:555*w.scale,restDelta:.1,restSpeed:.1,velocity:h.getCurrentVelocities()}).from(b).to(w).start(),eu()}).on("end",()=>{d?.isPointerDown()||el(),h?.isRunning()||(es(),C("animationEnd"))}),function(){let e=E("gestures");if(!e||!f||!c)return;let t=!1;d=I(f,e).on("start",e=>{if(!E("gestures")||!h||!T()||K())return;let n=e.srcEvent;(b.scale>1||e.currentTouch.length>1)&&(n?.stopPropagation(),h.pause(),t=!0),1===e.currentTouch.length&&C("touchStart")}).on("move",e=>{t&&(1!==w.scale||e.currentTouch.length>1)&&(_(e.srcEvent),e.srcEvent?.stopPropagation())}).on("pan",e=>{if(!t)return;let n=e.srcEvent;(1!==w.scale||e.currentTouch.length>1)&&(_(n),ec(j.Pan,e))}).on("swipe",e=>{t&&w.scale>1&&ec(j.Swipe,e)}).on("tap",e=>{C("click",e)}).on("singleTap",e=>{C("singleClick",e)}).on("doubleTap",e=>{C("dblClick",e)}).on("pinch",e=>{t&&(e.scale>en()?ec(j.ZoomIn,e):e.scale<en()?ec(j.ZoomOut,e):ec(j.Pan,e))}).on("end",e=>{t&&(e.currentTouch.length?(e.srcEvent.stopPropagation(),_(e.srcEvent),h?.end()):(t=!1,es(),el(),C("touchEnd")))}).init()}(),f&&(f.addEventListener("wheel",A,{passive:!1}),x.push(()=>{f?.removeEventListener("wheel",A,{passive:!1})})),e?.addEventListener("click",R),document?.addEventListener("mousemove",O),x.push(()=>{e?.removeEventListener("click",R),document?.removeEventListener("mousemove",O)});let o=Z();b={...o},w={...o},p=V.Ready,eu(),es(),C("ready"),requestAnimationFrame(()=>{F(),f&&(f.style.visibility="")})}function Z(){let e={...E("startPos")||{}},t=e.scale,n=1;n="string"==typeof t?ee(t):"number"==typeof t?t:en();let o={...q,...e,scale:n},i=K()?Q(n):void 0;if(i){let{x:e,y:t}=i;o.x=e,o.y=t}return o}function W(){let e={top:0,left:0,width:0,height:0};if(s){let t=s.getBoundingClientRect();w.angle%180==90?(e.top=t.top+.5*t.height-.5*t.width,e.left=t.left+.5*t.width-.5*t.height,e.width=t.height,e.height=t.width):(e.top=t.top,e.left=t.left,e.width=t.width,e.height=t.height)}return e}function B(){let e=E("width"),t=E("height");if(c&&"auto"===e){let t=c.getAttribute("width");e=t?parseFloat(t+""):void 0!==c.dataset.width?parseFloat(c.dataset.width+""):f instanceof HTMLImageElement?f.naturalWidth:c instanceof HTMLImageElement?c.naturalWidth:s?.getBoundingClientRect().width||0}else e="string"==typeof e?parseFloat(e):e;if(c&&"auto"===t){let e=c.getAttribute("height");t=e?parseFloat(e+""):void 0!==c.dataset.height?parseFloat(c.dataset.height+""):f instanceof HTMLImageElement?f.naturalHeight:c instanceof HTMLImageElement?c.naturalHeight:s?.getBoundingClientRect().height||0}else t="string"==typeof t?parseFloat(t):t;return{width:e,height:t}}function J(){let e=W();return{width:e.width,height:e.height}}function K(){return"mousemove"===E("panMode")&&matchMedia("(hover: hover)").matches}function Q(e){let t=m||E("event"),n=s?.getBoundingClientRect();if(!t||!n||e<=1)return{x:0,y:0};let o=(t.clientX||0)-n.left,i=(t.clientY||0)-n.top,{width:r,height:l}=J(),c=er(e);if(e>1){let t=E("mouseMoveFactor");t>1&&(e*=t)}let u=r*e,f=l*e,d=(u-r)*.5-o/r*100/100*(u-r),h=(f-l)*.5-i/l*100/100*(f-l);return{x:d=a(c.x[0],d,c.x[1]),y:h=a(c.y[0],h,c.y[1])}}function ee(t="base"){if(!e)return 1;let n=e.getBoundingClientRect(),o=W(),{width:i,height:r}=B(),l=e=>{if("number"==typeof e)return e;switch(e){case"min":case"base":return 1;case"cover":return Math.max(n.height/o.height,n.width/o.width)||1;case"full":case"max":{let e=w.angle%180==90?r:i;return e&&o.width?e/o.width:1}}},s=E("minScale"),c=E("maxScale"),u=Math.min(l("full"),l(s)),f="number"==typeof c?l("full")*c:Math.min(l("full"),l(c));switch(t){case"min":return u;case"base":return a(u,1,f);case"cover":return l("cover");case"full":return Math.min(f,l("full"));case"max":return f}}function et(){return ee("min")}function en(){return ee("base")}function eo(){return ee("cover")}function ei(){return ee("full")}function ea(){return ee("max")}function er(t){let n={x:[0,0],y:[0,0]},o=e?.getBoundingClientRect();if(!o)return n;let i=W(),a=o.width,r=o.height,l=i.width,s=i.height,c=t=void 0===t?w.scale:t,u=t;if(K()&&t>1){let e=E("mouseMoveFactor");e>1&&(l*t>a+.01&&(c*=e),s*t>r+.01&&(u*=e))}return l*=c,s*=u,t>1&&(l>a&&(n.x[0]=(a-l)*.5,n.x[1]=(l-a)*.5),n.x[0]-=(i.left-o.left)*.5,n.x[1]-=(i.left-o.left)*.5,n.x[0]-=(i.left+i.width-o.right)*.5,n.x[1]-=(i.left+i.width-o.right)*.5,s>r&&(n.y[0]=(r-s)*.5,n.y[1]=(s-r)*.5),n.y[0]-=(i.top-o.top)*.5,n.y[1]-=(i.top-o.top)*.5,n.y[0]-=(i.top+i.height-o.bottom)*.5,n.y[1]-=(i.top+i.height-o.bottom)*.5),n}function el(){if(!T()||!E("bounds")||!h)return;let e=et(),t=ea(),n=a(e,w.scale,t);if(w.scale<e-.01||w.scale>t+.01)return void ec(j.ZoomTo,{scale:n});if(h.isRunning()||ey())return;let o=er(n);w.x<o.x[0]||w.x>o.x[1]||w.y<o.y[0]||w.y>o.y[1]?(w.x=a(o.x[0],w.x,o.x[1]),w.y=a(o.y[0],w.y,o.y[1]),h.spring({tension:170,friction:17,restDelta:.001,restSpeed:.001,maxSpeed:1/0,velocity:h.getCurrentVelocities()}),h.from(b).to(w).start()):eu()}function es(t){if(!T())return;let n=ev(),o=ey(),i=eb(),a=ew(),r=ed(),l=eh();X(s,"is-fullsize",a),X(s,"is-expanded",i),X(s,"is-dragging",o),X(s,"can-drag",n),X(s,"will-zoom-in",r),X(s,"will-zoom-out",l);let c=em(),u=ep(),f=eg(),d=!T();for(let n of(t||e)?.querySelectorAll("[data-panzoom-action]")||[]){let e=n.dataset.panzoomAction,t=!1;if(d)t=!0;else switch(e){case j.ZoomIn:c||(t=!0);break;case j.ZoomOut:f||(t=!0);break;case j.ToggleFull:{u||f||(t=!0);let e=n.querySelector("g");e&&(e.style.display=a&&!t?"none":"");break}case j.IterateZoom:{c||f||(t=!0);let e=n.querySelector("g");e&&(e.style.display=c||t?"":"none");break}case j.ToggleCover:case j.ToggleMax:c||f||(t=!0)}t?(n.setAttribute("aria-disabled",""),n.setAttribute("tabindex","-1")):(n.removeAttribute("aria-disabled"),n.removeAttribute("tabindex"))}}function ec(t,n){if(!t||!e||!c||!h||!T()||t===j.Swipe&&Math.abs(h.getCurrentVelocities().scale)>.01)return;let o={...w},i={...w},r=er(K()?o.scale:b.scale),s=h.getCurrentVelocities(),u=W();n=n||{};let f=(n.currentTouch?.length||0)>1,d=n.velocityX||0,g=n.velocityY||0,m=n.center;n.srcEvent&&(m=k(S(n.srcEvent)));let p=n.deltaX||0,v=n.deltaY||0;switch(t){case j.MoveRight:p=n.deltaX||100;break;case j.MoveLeft:p=n.deltaX||-100;break;case j.MoveUp:v=n.deltaY||-100;break;case j.MoveDown:v=n.deltaY||100}let y=[];switch(t){case j.Reset:(i={...q}).scale=en();break;case j.Pan:case j.Move:case j.MoveLeft:case j.MoveRight:case j.MoveUp:case j.MoveDown:if(ey()){let e=1,t=1;i.x<=r.x[0]&&d<=0&&(e=.2*Math.max(.01,1-Math.abs(1/u.width*Math.abs(i.x-r.x[0])))),i.x>=r.x[1]&&d>=0&&(e=.2*Math.max(.01,1-Math.abs(1/u.width*Math.abs(i.x-r.x[1])))),i.y<=r.y[0]&&g<=0&&(t=.2*Math.max(.01,1-Math.abs(1/u.height*Math.abs(i.y-r.y[0])))),i.y>=r.y[1]&&g>=0&&(t=.2*Math.max(.01,1-Math.abs(1/u.height*Math.abs(i.y-r.y[1])))),i.x+=p*e,i.y+=v*t}else i.x=a(r.x[0],i.x+p,r.x[1]),i.y=a(r.y[0],i.y+v,r.y[1]);break;case j.Swipe:let x=(e=0)=>Math.sign(e)*Math.pow(Math.abs(e),1.5);i.x+=a(-1e3,x(d),1e3),i.y+=a(-1e3,x(g),1e3),g&&!d&&(i.x=a(r.x[0],i.x,r.x[1])),!g&&d&&(i.y=a(r.y[0],i.y,r.y[1])),s.x=d,s.y=g;break;case j.ZoomTo:i.scale=n.scale||1;break;case j.ZoomIn:i.scale=i.scale*(n.scale||2),f||(i.scale=Math.min(i.scale,ea()));break;case j.ZoomOut:i.scale=i.scale*(n.scale||.5),f||(i.scale=Math.max(i.scale,et()));break;case j.ToggleCover:y=[en(),eo()];break;case j.ToggleFull:y=[en(),ei()];break;case j.ToggleMax:y=[en(),ea()];break;case j.IterateZoom:y=[en(),ei(),ea()];break;case j.Zoom:let M=ei();i.scale>=M-.05?i.scale=en():i.scale=Math.min(M,i.scale*(n.scale||2));break;case j.RotateCW:i.angle+=90;break;case j.RotateCCW:i.angle-=90;break;case j.FlipX:i.flipX*=-1;break;case j.FlipY:i.flipY*=-1}if(void 0!==b.angle&&Math.abs(b.angle)>=360&&(i.angle-=360*Math.floor(b.angle/360),b.angle-=360*Math.floor(b.angle/360)),y.length){let e=y.findIndex(e=>e>i.scale+1/Y);i.scale=y[e]||y[0]}if(f&&(i.scale=a(et()*(f?.8:1),i.scale,ea()*(f?1.6:1))),K()){let e=Q(i.scale);if(e){let{x:t,y:n}=e;i.x=t,i.y=n}}else if(Math.abs(i.scale-o.scale)>1e-4){let t=0,n=0;if(m)t=m.x,n=m.y;else{let o=e.getBoundingClientRect();t=o.x+.5*o.width,n=o.y+.5*o.height}let l=t-u.left,s=n-u.top;l-=.5*u.width,s-=.5*u.height;let c=(l-o.x)/o.scale,d=(s-o.y)/o.scale;i.x=l-c*i.scale,i.y=s-d*i.scale,!f&&E("bounds")&&(r=er(i.scale),i.x=a(r.x[0],i.x,r.x[1]),i.y=a(r.y[0],i.y,r.y[1]))}if(t===j.Swipe){let e=500*i.scale;h.spring({tension:94,friction:17,maxSpeed:e,restDelta:.1,restSpeed:.1,velocity:s})}else t===j.Pan||f?h.spring({tension:900,friction:17,restDelta:.01,restSpeed:.01,maxSpeed:1}):h.spring({tension:170,friction:17,restDelta:.001,restSpeed:.001,maxSpeed:1/0,velocity:s});if(0===n.velocity||l(b,i))b={...i},w={...i},h.end(),eu(),es();else{if(l(w,i))return;h.from(b).to(i).start()}C("action",t)}function eu(){if(!c||!s||!f)return;let{width:t,height:n}=B();Object.assign(s.style,{maxWidth:`min(${t}px, 100%)`,maxHeight:`min(${n}px, 100%)`});let{x:o,y:i,width:a,height:r,scale:l,angle:u,flipX:d,flipY:h}=function(){let{width:t,height:n}=B(),{width:o,height:i}=J();if(!e)return{x:0,y:0,width:0,height:0,scale:0,flipX:0,flipY:0,angle:0,fitWidth:o,fitHeight:i,fullWidth:t,fullHeight:n};let{x:a,y:r,scale:l,angle:s,flipX:c,flipY:u}=b,f=1/ei(),d=t,h=n,g=b.scale*f,m=w.scale*f,p=Math.max(o,i),v=Math.min(o,i);t>n?(d=p,h=v):(d=v,h=p),g=t>n?p*l/t||1:p*l/n||1;let y=d?t*m:0,x=h?n*m:0,M=d&&h?t*g/y:0;return{x:a=a+.5*d-.5*y,y:r=r+.5*h-.5*x,width:y,height:x,scale:M,flipX:c,flipY:u,angle:s,fitWidth:o,fitHeight:i,fullWidth:t,fullHeight:n}}(),g=`translate(${H(o)}px, ${H(i)}px)`;1!==d||1!==h?g+=` scaleX(${H(l*d)}) scaleY(${H(l*h)})`:g+=` scale(${H(l)})`,0!==u&&(g+=` rotate(${u}deg)`),f.style.width=`${H(a)}px`,f.style.height=`${H(r)}px`,f.style.transform=`${g}`,C("render")}function ef(){let e=w.scale,t,n=E("clickAction"),o=en();if(n){let i=[];switch(n){case j.ZoomIn:o=e*(t||2);break;case j.ZoomOut:o=e*(t||.5);break;case j.ToggleCover:i=[en(),eo()];break;case j.ToggleFull:i=[en(),ei()];break;case j.ToggleMax:i=[en(),ea()];break;case j.IterateZoom:i=[en(),ei(),ea()];break;case j.Zoom:let a=ei();o=e>=a-.05?en():Math.min(a,e*(t||2))}if(i.length){let t=i.findIndex(t=>t>e+1/Y);o=i[t]||en()}}return a(et(),o,ea())}function ed(){return!!(T()&&ef()>w.scale)}function eh(){return!!(T()&&ef()<w.scale)}function eg(){return!!(T()&&w.scale>et())}function em(){return!!(T()&&w.scale<ea())}function ep(){return!!(T()&&w.scale<ei())}function ev(){return!!(T()&&eb()&&d&&!K())}function ey(){return!!(T()&&d?.isPointerDown()&&!K())}function eb(){return!!(T()&&w.scale>en())}function ew(){return!!(T()&&w.scale>=ei())}function ex(){let t="in-fullscreen",n="with-panzoom-in-fullscreen";e?.classList.toggle(t);let o=e?.classList.contains(t);o?(document.documentElement.classList.add(n),document.addEventListener("keydown",eM,!0)):(document.documentElement.classList.remove(n),document.removeEventListener("keydown",eM,!0)),eu(),C(o?"enterFS":"exitFS")}function eM(e){"Escape"!==e.key||e.defaultPrevented||ex()}let eE={canDrag:ev,canZoomIn:em,canZoomOut:eg,canZoomToFull:ep,destroy:function(){for(let e of(C("destroy"),Object.values(y)))e?.destroy(eE);for(let e of x)e();return s&&(s.style.aspectRatio="",s.style.maxWidth="",s.style.maxHeight=""),f&&(f.style.width="",f.style.height="",f.style.transform=""),s=void 0,c=void 0,f=void 0,b={...q},w={...q},h?.destroy(),h=void 0,d?.destroy(),d=void 0,p=V.Destroyed,eE},emit:C,execute:ec,getBoundaries:er,getContainer:function(){return e},getContent:function(){return c},getFullDim:B,getGestures:function(){return d},getMousemovePos:Q,getOptions:function(){return v},getPlugins:function(){return y},getScale:ee,getStartPosition:Z,getState:function(){return p},getTransform:function(e){return!0===e?w:b},getTween:function(){return h},getViewport:function(){return f},getWrapper:function(){return s},init:function(){return p=V.Init,C("init"),function(){for(let[e,t]of Object.entries({...r,...v.plugins||{}}))if(e&&!y[e]&&t instanceof Function){let n=t();n.init(eE),y[e]=n}C("initPlugins")}(),function(){let t={...$.classes,...E("classes")};if(e&&(z(e,t.container),c=e.querySelector("."+t.content))){if(c.setAttribute("draggable","false"),(s=e.querySelector("."+t.wrapper))||(z(s=document.createElement("div"),t.wrapper),c.insertAdjacentElement("beforebegin",s),s.insertAdjacentElement("afterbegin",c)),(f=e.querySelector("."+t.viewport))||(z(f=document.createElement("div"),t.viewport),f.insertAdjacentElement("afterbegin",c),s.insertAdjacentElement("beforeend",f)),(u=c.cloneNode(!0)).removeAttribute("id"),s.insertAdjacentElement("afterbegin",u),c instanceof HTMLPictureElement&&(c=c.querySelector("img")),u instanceof HTMLPictureElement&&(u=u.querySelector("img")),f instanceof HTMLPictureElement&&(f=f.querySelector("img")),f&&(f.style.visibility="hidden",E("protected"))){f.addEventListener("contextmenu",e=>{_(e)});let e=document.createElement("div");z(e,"f-panzoom__protected"),f.appendChild(e)}C("initLayout")}}(),function(){if(e&&s&&!g){let e=null;(g=new ResizeObserver(()=>{T()&&(e=e||requestAnimationFrame(()=>{T()&&(es(),el(),C("refresh")),e=null}))})).observe(s),x.push(()=>{g?.disconnect(),g=void 0,e&&(cancelAnimationFrame(e),e=null)})}}(),function(){if(!e||!c)return;if(!(c instanceof HTMLImageElement&&u instanceof HTMLImageElement))return P();let t=()=>{c&&c instanceof HTMLImageElement&&c.decode().then(()=>{P()}).catch(()=>{P()})};(p=V.Loading,e.classList.add("is-loading"),C("loading"),u.src&&u.complete)?t():(function(){if(!e||e?.querySelector(".f-spinner"))return;let t=i(E("spinnerTpl"));t&&(t.classList.add("f-spinner"),e.classList.add("is-loading"),s?.insertAdjacentElement("afterbegin",t))}(),u.addEventListener("load",t,!1),u.addEventListener("error",t,!1),x.push(()=>{u?.removeEventListener("load",t,!1),u?.removeEventListener("error",t,!1)}))}(),eE},isDragging:ey,isExpanded:eb,isFullsize:ew,isMousemoveMode:K,localize:function(e,t=[]){let n=E("l10n")||{};e=String(e).replace(/\{\{(\w+)\}\}/g,(e,t)=>n[t]||e);for(let n=0;n<t.length;n++)e=e.split(t[n][0]).join(t[n][1]);return e.replace(/\{\{(.*?)\}\}/g,(e,t)=>t)},off:function(e,t){for(let n of e instanceof Array?e:[e])L.has(n)&&L.set(n,L.get(n).filter(e=>e!==t));return eE},on:function(e,t){for(let n of e instanceof Array?e:[e])L.set(n,[...L.get(n)||[],t]);return eE},toggleFS:ex,updateControls:es,version:"6.1.7",willZoomIn:ed,willZoomOut:eh};return eE};B.l10n={en_EN:Z},B.getDefaults=()=>$,e.PANZOOM_DEFAULT_POS=q,e.Panzoom=B,e.PanzoomAction=j,e.PanzoomState=V,e.PanzoomZoomLevel=W});