UNPKG

@fancyapps/ui

Version:

Robust JavaScript UI Component Library

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