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