UNPKG

@fancyapps/ui

Version:

Robust JavaScript UI Component Library

4 lines 31 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=e=>"object"==typeof e&&null!==e&&e.constructor===Object&&"[object Object]"===Object.prototype.toString.call(e),o=function(e="",t="",n=""){return e.split(t).join(n)},i=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},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)};function s(e){return n(e)||Array.isArray(e)}function c(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}`:s(o)&&s(i)?c(o,i):o===i})}let u=1/60*3e3,f=function(e){for(let t of w)t.getState()===d.Running&&t.tick(M?e-M:0);M=e,x=window.requestAnimationFrame(f)},d=((h={})[h.Initializing=0]="Initializing",h[h.Running=1]="Running",h[h.Paused=2]="Paused",h[h.Completed=3]="Completed",h[h.Destroyed=4]="Destroyed",h);var h,g,m,p,v,y=((g=y||{})[g.Spring=0]="Spring",g[g.Ease=1]="Ease",g);let b=((m={})[m.Loop=0]="Loop",m[m.Reverse=1]="Reverse",m),w=new Set,x=null,M=0;function E(){let e=d.Initializing,t=y.Ease,n=0,o=0,i=E.Easings.Linear,a=500,r=0,s=0,h=0,g=0,m=1/0,p=.01,v=.01,M=!1,T={},L=null,S={},R={},k={},A=0,z=0,C=b.Loop,O=E.Easings.Linear,P=new Map;function F(e,...t){for(let n of P.get(e)||[])n(...t)}function I(e){return o=0,e?L=setTimeout(()=>{Z()},e):Z(),_}function Z(){e=d.Running,F("start",S,R)}function D(){if(e=d.Completed,k={},F("end",S),e===d.Completed)if(n<A){if(n++,C===b.Reverse){let e={...T};T={...R},R=e}I(z)}else n=0;return _}let _={getState:function(){return e},easing:function(e){return i=e,t=y.Ease,k={},_},duration:function(e){return a=e,_},spring:function(e={}){t=y.Spring;let{velocity:n,mass:o,tension:i,friction:a,restDelta:l,restSpeed:c,maxSpeed:u,clamp:f}={velocity:0,mass:1,tension:170,friction:26,restDelta:.1,restSpeed:.1,maxSpeed:1/0,clamp:!0,...e};return r=n,s=o,h=i,g=a,v=l,p=c,m=u,M=f,k={},_},isRunning:function(){return e===d.Running},isSpring:function(){return t===y.Spring},from:function(e){return S={...e},_},to:function(e){return R=e,_},repeat:function(e,t=0,n=b.Loop,o){return A=e,z=t,C=n,O=o||i,_},on:function(e,t){return P.set(e,[...P.get(e)||[],t]),_},off:function(e,t){return P.has(e)&&P.set(e,P.get(e).filter(e=>e!==t)),_},start:function(t){return c(S,R)||(e=d.Initializing,T={...S},w.add(this),x||(x=window.requestAnimationFrame(f)),I(t)),_},pause:function(){return L&&(clearTimeout(L),L=null),e===d.Running&&(e=d.Paused,F("pause",S)),_},end:D,tick:function(n){n>u&&(n=u),o+=n;let f=0,w=!1;if(e!==d.Running)return _;if(t===y.Ease){w=1===(f=l(0,o/a,1));let e=C===b.Reverse?O:i;for(let t in S)S[t]=T[t]+(R[t]-T[t])*e(f)}if(t===y.Spring){let e=.001*n,t=0;for(let n in S){let o=R[n],i=S[n];if(!("number"==typeof o&&!isNaN(o))||!("number"==typeof i&&!isNaN(i)))continue;if(Math.abs(o-i)<=v){S[n]=o,k[n]=0;continue}k[n]||("object"==typeof r&&"number"==typeof r[n]?k[n]=r[n]:"number"==typeof r?k[n]=r:k[n]=0);let a=k[n],c=(a=l(-1*Math.abs(m),a,Math.abs(m)))*s*g,u=Math.abs(o-i)*h;a+=((i>o?-1:1)*u-c)/s*e,i+=a*e;let f=S[n]>o?i<o:i>o,d=Math.abs(a)<p&&Math.abs(o-i)<=v;M&&f&&(d=!0),d?(i=o,a=0):t++,S[n]=i,k[n]=a}w=!t}let x={...R};return F("step",S,T,R,f),w&&e===d.Running&&c(R,x)&&(e=d.Completed,D()),_},getStartValues:function(){return T},getCurrentValues:function(){return S},getCurrentVelocities:function(){return k},getEndValues:function(){return R},destroy:function(){e=d.Destroyed,L&&(clearTimeout(L),L=null),T=S=R={},w.delete(this)}};return _}function T(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 L(e){return T(e,"touches")}function S(e){return T(e,"targetTouches")}function R(e){return T(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 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}E.destroy=()=>{for(let e of w)e.destroy();x&&(cancelAnimationFrame(x),x=null)},E.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 z=e=>{e.cancelable&&e.preventDefault()},C={passive:!1},O={panThreshold:5,swipeThreshold:3,ignore:["textarea","input","select","[contenteditable]","[data-selectable]","[data-draggable]"]},P=!1,F=!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,T=0,I=new Map;function Z(e){let t=A(l),a=A(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 I.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 _(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 X(e){if(!1===D(e))return;if("undefined"!=typeof MouseEvent&&e instanceof MouseEvent){if(P)return}else P=!0;if("undefined"!=typeof MouseEvent&&e instanceof MouseEvent){if(!e.buttons||0!==e.button)return;z(e)}e instanceof MouseEvent&&(window.addEventListener("mousemove",Y),window.addEventListener("mouseup",j)),window.addEventListener("blur",H),i=e,r=[...l=S(e)],s=[],g=l.length,n=k(l),1===g&&(c=!1,u=!1,f=!1),g&&_(k(l));let t=Date.now(),o=t-(h||t);d=o>0&&o<=250&&1===g,h=t,clearTimeout(E),Z("start")}function Y(e){if(!r.length||e.defaultPrevented||!1===D(e))return;i=e,s=[...l],l=L(e);let t=k(s),u=k(L(e));if(_(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(A(l)-A(s))>=.1&&(f=!0,Z("pinch")),!c&&(c=Math.abs(v)>a.panThreshold||Math.abs(y)>a.panThreshold)&&(F=!1,clearTimeout(T),T=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 j(e){if(i=e,!r.length)return;let t=S(e),o=R(e);if(g=t.length,n=k(o),o.length&&_(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"),q()}}function H(){clearTimeout(E),q(),c&&Z("panend"),Z("end")}function q(){P=!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",Y),window.removeEventListener("mouseup",j),window.removeEventListener("blur",H),F||T||(T=setTimeout(()=>{F=!0,T=0},100))}function $(e){let t=e.target;P=!1,t&&!e.defaultPrevented&&(F||(z(e),e.stopPropagation()))}let W={init:function(){return e&&(e.addEventListener("click",$,C),e.addEventListener("mousedown",X,C),e.addEventListener("touchstart",X,C),e.addEventListener("touchmove",Y,C),e.addEventListener("touchend",j),e.addEventListener("touchcancel",j)),W},on:function(e,t){return I.set(e,[...I.get(e)||[],t]),W},off:function(e,t){return I.has(e)&&I.set(e,I.get(e).filter(e=>e!==t)),W},isPointerDown:()=>g>0,destroy:function(){clearTimeout(E),clearTimeout(T),T=0,e&&(e.removeEventListener("click",$,C),e.removeEventListener("mousedown",X,C),e.removeEventListener("touchstart",X,C),e.removeEventListener("touchmove",Y,C),e.removeEventListener("touchend",j),e.removeEventListener("touchcancel",j)),e=null,q()}};return W};I.isClickAllowed=()=>F;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"},D=(e,t="")=>{e&&e.classList&&t.split(" ").forEach(t=>{t&&e.classList.add(t)})},_=(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,j=e=>{e.cancelable&&e.preventDefault()},H=(e,t=Y)=>Math.round(((e=parseFloat(e+"")||0)+Number.EPSILON)*t)/t,q=((p={}).Reset="reset",p.Zoom="zoom",p.ZoomIn="zoomIn",p.ZoomOut="zoomOut",p.ZoomTo="zoomTo",p.ToggleCover="toggleCover",p.ToggleFull="toggleFull",p.ToggleMax="toggleMax",p.IterateZoom="iterateZoom",p.Pan="pan",p.Swipe="swipe",p.Move="move",p.MoveLeft="moveLeft",p.MoveRight="moveRight",p.MoveUp="moveUp",p.MoveDown="moveDown",p.RotateCCW="rotateCCW",p.RotateCW="rotateCW",p.FlipX="flipX",p.FlipY="flipY",p.ToggleFS="toggleFS",p),$={x:0,y:0,scale:1,angle:0,flipX:1,flipY:1},W=((v={})[v.Init=0]="Init",v[v.Loading=1]="Loading",v[v.Error=2]="Error",v[v.Ready=3]="Ready",v[v.Destroyed=4]="Destroyed",v),V={bounds:!0,classes:{container:"f-panzoom",wrapper:"f-panzoom__wrapper",content:"f-panzoom__content",viewport:"f-panzoom__viewport"},clickAction:q.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:q.Zoom,width:"auto"},G=0,N=0,U=0,B=(e,n={},o={})=>{let i,s,u,f,d,h,g,m,p=W.Init,v={...V,...n},y={},b={...$},w={...$},x=[];function M(e){let t=v[e];return t&&"function"==typeof t?t(eE):t}function T(){return e&&e.parentElement&&i&&p===W.Ready}let L=new Map;function S(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&&S("*",e,...t)}function A(e){if(!T()||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);S("wheel",e,n);let o=M("wheelAction");if(!o||e.defaultPrevented)return;let i=w.scale,r=i*(n>0?1.5:.5);if(o===q.Zoom){let o=100>Math.abs(e.deltaY)&&100>Math.abs(e.deltaX);if(t-N<(o?200:45))return void j(e);N=t;let a=et(),s=ea();if(H(r)<H(a)&&H(i)<=H(a)?(U+=Math.abs(n),r=a):H(r)>H(s)&&H(i)>=H(s)?(U+=Math.abs(n),r=s):(U=0,r=l(a,r,s)),U>7)return}switch(j(e),o){case q.Pan:ec(o,{srcEvent:e,deltaX:-(2*e.deltaX),deltaY:-(2*e.deltaY)});break;case q.Zoom:ec(q.ZoomTo,{srcEvent:e,scale:r,center:{x:e.clientX,y:e.clientY}});break;default:ec(o,{srcEvent:e})}}function z(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 a=o.closest("[data-panzoom-action]"),r=a?.dataset?.panzoomAction,l=a?.dataset?.panzoomValue||"";if(r){switch(j(n),r){case q.ZoomTo:case q.ZoomIn:case q.ZoomOut:ec(r,{scale:parseFloat(l||"")||void 0});break;case q.MoveLeft:case q.MoveRight:ec(r,{deltaX:parseFloat(l||"")||void 0});break;case q.MoveUp:case q.MoveDown:ec(r,{deltaY:parseFloat(l||"")||void 0});break;case q.ToggleFS:ex();break;default:ec(r)}return}if(!i?.contains(o))return;let s={srcEvent:n};if(ec(M("clickAction"),s),M("dblClickAction")){let e=Date.now(),n=e-(G||e);G=e,n>0&&n<=250?(t&&(clearTimeout(t),t=void 0),ec(M("dblClickAction"),s)):t=setTimeout(()=>{ec(M("singleClickAction"),s)},250)}}function C(e){if(m=e,!T()||!K()||b.scale<=1||w.scale<=1||(i?.dataset.animationName||"").indexOf("zoom")>-1)return;let t=Q(w.scale);if(!t)return;let{x:n,y:o}=t;ec(q.Pan,{deltaX:n-w.x,deltaY:o-w.y})}function O(){e&&(_(e,"is-loading"),e.querySelector(".f-spinner")?.remove())}function P(){if(!e||!s)return;if(O(),s instanceof HTMLImageElement&&!(s.complete&&s.naturalWidth)){p=W.Error,i?.classList.add("has-error"),S("error");return}S("loaded");let{width:t,height:n}=B();s instanceof HTMLImageElement&&(s.setAttribute("width",t+""),s.setAttribute("height",n+"")),i&&(_(i,"has-error"),s instanceof HTMLImageElement&&(i.setAttribute("width",t+""),i.setAttribute("height",n+""),i.style.aspectRatio=`${t/n||""}`)),h=E().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={...$,...t},es(),S("animationStart")}).on("pause",e=>{w={...$,...e}}).on("step",e=>{if(!T())return void h?.end();if(b={...$,...e},K()||!M("bounds")||ey()||w.scale>b.scale||w.scale<en())return void eu();let t=er(w.scale),n=!1,o=!1,i=!1,a=!1;b.x<t.x[0]&&(n=!0),b.x>t.x[1]&&(o=!0),b.y<t.y[0]&&(a=!0),b.y>t.y[1]&&(i=!0);let r=!1,s=!1,c=!1,u=!1;w.x<t.x[0]&&(r=!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&&r)&&(w.x=l(t.x[0],w.x,t.x[1]),f=!0),(i&&c||a&&u)&&(w.y=l(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(),S("animationEnd"))}),function(){let e=M("gestures");if(!e||!f||!s)return;let t=!1;d=I(f,e).on("start",e=>{if(!M("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&&S("touchStart")}).on("move",e=>{t&&(1!==w.scale||e.currentTouch.length>1)&&(j(e.srcEvent),e.srcEvent?.stopPropagation())}).on("pan",e=>{if(!t)return;let n=e.srcEvent;(1!==w.scale||e.currentTouch.length>1)&&(j(n),ec(q.Pan,e))}).on("swipe",e=>{t&&w.scale>1&&ec(q.Swipe,e)}).on("tap",e=>{S("click",e)}).on("singleTap",e=>{S("singleClick",e)}).on("doubleTap",e=>{S("dblClick",e)}).on("pinch",e=>{t&&(e.scale>en()?ec(q.ZoomIn,e):e.scale<en()?ec(q.ZoomOut,e):ec(q.Pan,e))}).on("end",e=>{t&&(e.currentTouch.length?(e.srcEvent.stopPropagation(),j(e.srcEvent),h?.end()):(t=!1,es(),el(),S("touchEnd")))}).init()}(),f&&(f.addEventListener("wheel",A,{passive:!1}),x.push(()=>{f?.removeEventListener("wheel",A,{passive:!1})})),e?.addEventListener("click",z),document?.addEventListener("mousemove",C),x.push(()=>{e?.removeEventListener("click",z),document?.removeEventListener("mousemove",C)});let o=F();b={...o},w={...o},p=W.Ready,eu(),es(),S("ready"),requestAnimationFrame(()=>{O(),f&&(f.style.visibility="")})}function F(){let e={...M("startPos")||{}},t=e.scale,n=1;n="string"==typeof t?ee(t):"number"==typeof t?t:en();let o={...$,...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 Z(){let e={top:0,left:0,width:0,height:0};if(i){let t=i.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=M("width"),t=M("height");if(s&&"auto"===e){let t=s.getAttribute("width");e=t?parseFloat(t+""):void 0!==s.dataset.width?parseFloat(s.dataset.width+""):f instanceof HTMLImageElement?f.naturalWidth:s instanceof HTMLImageElement?s.naturalWidth:i?.getBoundingClientRect().width||0}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+""):f instanceof HTMLImageElement?f.naturalHeight:s instanceof HTMLImageElement?s.naturalHeight:i?.getBoundingClientRect().height||0}else t="string"==typeof t?parseFloat(t):t;return{width:e,height:t}}function J(){let e=Z();return{width:e.width,height:e.height}}function K(){return"mousemove"===M("panMode")&&matchMedia("(hover: hover)").matches}function Q(e){let t=m||M("event"),n=i?.getBoundingClientRect();if(!t||!n||e<=1)return{x:0,y:0};let o=(t.clientX||0)-n.left,a=(t.clientY||0)-n.top,{width:r,height:s}=J(),c=er(e);if(e>1){let t=M("mouseMoveFactor");t>1&&(e*=t)}let u=r*e,f=s*e,d=(u-r)*.5-o/r*100/100*(u-r),h=(f-s)*.5-a/s*100/100*(f-s);return{x:d=l(c.x[0],d,c.x[1]),y:h=l(c.y[0],h,c.y[1])}}function ee(t="base"){if(!e)return 1;let n=e.getBoundingClientRect(),o=Z(),{width:i,height:a}=B(),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=w.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 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=Z(),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=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 el(){if(!T()||!M("bounds")||!h)return;let e=et(),t=ea(),n=l(e,w.scale,t);if(w.scale<e-.01||w.scale>t+.01)return void ec(q.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=l(o.x[0],w.x,o.x[1]),w.y=l(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(),a=eb(),r=ew(),l=ed(),s=eh();X(i,"is-fullsize",r),X(i,"is-expanded",a),X(i,"is-dragging",o),X(i,"can-drag",n),X(i,"will-zoom-in",l),X(i,"will-zoom-out",s);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 q.ZoomIn:c||(t=!0);break;case q.ZoomOut:f||(t=!0);break;case q.ToggleFull:{u||f||(t=!0);let e=n.querySelector("g");e&&(e.style.display=r&&!t?"none":"");break}case q.IterateZoom:{c||f||(t=!0);let e=n.querySelector("g");e&&(e.style.display=c||t?"":"none");break}case q.ToggleCover:case q.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||!s||!h||!T()||t===q.Swipe&&Math.abs(h.getCurrentVelocities().scale)>.01)return;let o={...w},i={...w},a=er(K()?o.scale:b.scale),r=h.getCurrentVelocities(),u=Z();n=n||{};let f=(n.currentTouch?.length||0)>1,d=n.velocityX||0,g=n.velocityY||0,m=n.center;n.srcEvent&&(m=k(R(n.srcEvent)));let p=n.deltaX||0,v=n.deltaY||0;switch(t){case q.MoveRight:p=n.deltaX||100;break;case q.MoveLeft:p=n.deltaX||-100;break;case q.MoveUp:v=n.deltaY||-100;break;case q.MoveDown:v=n.deltaY||100}let y=[];switch(t){case q.Reset:(i={...$}).scale=en();break;case q.Pan:case q.Move:case q.MoveLeft:case q.MoveRight:case q.MoveUp:case q.MoveDown:if(ey()){let e=1,t=1;i.x<=a.x[0]&&d<=0&&(e=.2*Math.max(.01,1-Math.abs(1/u.width*Math.abs(i.x-a.x[0])))),i.x>=a.x[1]&&d>=0&&(e=.2*Math.max(.01,1-Math.abs(1/u.width*Math.abs(i.x-a.x[1])))),i.y<=a.y[0]&&g<=0&&(t=.2*Math.max(.01,1-Math.abs(1/u.height*Math.abs(i.y-a.y[0])))),i.y>=a.y[1]&&g>=0&&(t=.2*Math.max(.01,1-Math.abs(1/u.height*Math.abs(i.y-a.y[1])))),i.x+=p*e,i.y+=v*t}else i.x=l(a.x[0],i.x+p,a.x[1]),i.y=l(a.y[0],i.y+v,a.y[1]);break;case q.Swipe:let x=(e=0)=>Math.sign(e)*Math.pow(Math.abs(e),1.5);i.x+=l(-1e3,x(d),1e3),i.y+=l(-1e3,x(g),1e3),g&&!d&&(i.x=l(a.x[0],i.x,a.x[1])),!g&&d&&(i.y=l(a.y[0],i.y,a.y[1])),r.x=d,r.y=g;break;case q.ZoomTo:i.scale=n.scale||1;break;case q.ZoomIn:i.scale=i.scale*(n.scale||2),f||(i.scale=Math.min(i.scale,ea()));break;case q.ZoomOut:i.scale=i.scale*(n.scale||.5),f||(i.scale=Math.max(i.scale,et()));break;case q.ToggleCover:y=[en(),eo()];break;case q.ToggleFull:y=[en(),ei()];break;case q.ToggleMax:y=[en(),ea()];break;case q.IterateZoom:y=[en(),ei(),ea()];break;case q.Zoom:let E=ei();i.scale>=E-.05?i.scale=en():i.scale=Math.min(E,i.scale*(n.scale||2));break;case q.RotateCW:i.angle+=90;break;case q.RotateCCW:i.angle-=90;break;case q.FlipX:i.flipX*=-1;break;case q.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=l(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 r=t-u.left,s=n-u.top;r-=.5*u.width,s-=.5*u.height;let c=(r-o.x)/o.scale,d=(s-o.y)/o.scale;i.x=r-c*i.scale,i.y=s-d*i.scale,!f&&M("bounds")&&(a=er(i.scale),i.x=l(a.x[0],i.x,a.x[1]),i.y=l(a.y[0],i.y,a.y[1]))}if(t===q.Swipe){let e=500*i.scale;h.spring({tension:94,friction:17,maxSpeed:e,restDelta:.1,restSpeed:.1,velocity:r})}else t===q.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:r});if(0===n.velocity||c(b,i))b={...i},w={...i},h.end(),eu(),es();else{if(c(w,i))return;h.from(b).to(i).start()}S("action",t)}function eu(){if(!s||!i||!f)return;let{width:t,height:n}=B();Object.assign(i.style,{maxWidth:`min(${t}px, 100%)`,maxHeight:`min(${n}px, 100%)`});let{x:o,y:a,width:r,height:l,scale:c,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(a)}px)`;1!==d||1!==h?g+=` scaleX(${H(c*d)}) scaleY(${H(c*h)})`:g+=` scale(${H(c)})`,0!==u&&(g+=` rotate(${u}deg)`),f.style.width=`${H(r)}px`,f.style.height=`${H(l)}px`,f.style.transform=`${g}`,S("render")}function ef(){let e=w.scale,t,n=M("clickAction"),o=en();if(n){let i=[];switch(n){case q.ZoomIn:o=e*(t||2);break;case q.ZoomOut:o=e*(t||.5);break;case q.ToggleCover:i=[en(),eo()];break;case q.ToggleFull:i=[en(),ei()];break;case q.ToggleMax:i=[en(),ea()];break;case q.IterateZoom:i=[en(),ei(),ea()];break;case q.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 l(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(),S(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(S("destroy"),Object.values(y)))e?.destroy(eE);for(let e of x)e();return i&&(i.style.aspectRatio="",i.style.maxWidth="",i.style.maxHeight=""),f&&(f.style.width="",f.style.height="",f.style.transform=""),i=void 0,s=void 0,f=void 0,b={...$},w={...$},h?.destroy(),h=void 0,d?.destroy(),d=void 0,p=W.Destroyed,eE},emit:S,execute:ec,getBoundaries:er,getContainer:function(){return e},getContent:function(){return s},getFullDim:B,getGestures:function(){return d},getMousemovePos:Q,getOptions:function(){return v},getPlugins:function(){return y},getScale:ee,getStartPosition:F,getState:function(){return p},getTransform:function(e){return!0===e?w:b},getTween:function(){return h},getViewport:function(){return f},getWrapper:function(){return i},init:function(){return p=W.Init,S("init"),function(){for(let[e,t]of Object.entries({...o,...v.plugins||{}}))if(e&&!y[e]&&t instanceof Function){let n=t();n.init(eE),y[e]=n}S("initPlugins")}(),function(){let t={...V.classes,...M("classes")};if(e&&(D(e,t.container),s=e.querySelector("."+t.content))){if(s.setAttribute("draggable","false"),(i=e.querySelector("."+t.wrapper))||(D(i=document.createElement("div"),t.wrapper),s.insertAdjacentElement("beforebegin",i),i.insertAdjacentElement("afterbegin",s)),(f=e.querySelector("."+t.viewport))||(D(f=document.createElement("div"),t.viewport),f.insertAdjacentElement("afterbegin",s),i.insertAdjacentElement("beforeend",f)),(u=s.cloneNode(!0)).removeAttribute("id"),i.insertAdjacentElement("afterbegin",u),s instanceof HTMLPictureElement&&(s=s.querySelector("img")),u instanceof HTMLPictureElement&&(u=u.querySelector("img")),f instanceof HTMLPictureElement&&(f=f.querySelector("img")),f&&(f.style.visibility="hidden",M("protected"))){f.addEventListener("contextmenu",e=>{j(e)});let e=document.createElement("div");D(e,"f-panzoom__protected"),f.appendChild(e)}S("initLayout")}}(),function(){if(e&&i&&!g){let e=null;(g=new ResizeObserver(()=>{T()&&(e=e||requestAnimationFrame(()=>{T()&&(es(),el(),S("refresh")),e=null}))})).observe(i),x.push(()=>{g?.disconnect(),g=void 0,e&&(cancelAnimationFrame(e),e=null)})}}(),function(){if(!e||!s)return;if(!(s instanceof HTMLImageElement&&u instanceof HTMLImageElement))return P();let t=()=>{s&&s instanceof HTMLImageElement&&s.decode().then(()=>{P()}).catch(()=>{P()})};(p=W.Loading,e.classList.add("is-loading"),S("loading"),u.src&&u.complete)?t():(function(){if(!e||e?.querySelector(".f-spinner"))return;let t=r(M("spinnerTpl"));t&&(t.classList.add("f-spinner"),e.classList.add("is-loading"),i?.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=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.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=()=>V;let J={tpl:e=>`<img class="f-panzoom__content" ${e.srcset?'data-lazy-srcset="{{srcset}}"':""} ${e.sizes?'data-lazy-sizes="{{sizes}}"':""} data-lazy-src="{{src}}" alt="{{alt}}" />`};e.Zoomable=()=>{let e;function t(t,o){let i=e?.getOptions().Zoomable,a=(n(i)?{...J,...i}:J)[t];return a&&"function"==typeof a&&o?a(o):a}function i(){e&&!1!==e.getOptions().Zoomable&&(e.on("addSlide",l),e.on("removeSlide",s),e.on("attachSlideEl",c),e.on("click",r),e.on("change",a),e.on("ready",a))}function a(){u();let t=e?.getVisibleSlides()||[];if(t.length>1||e?.getOption("transition")==="slide")for(let n of t){let t=n.panzoomRef;t&&0>(e?.getPage().slides||[]).indexOf(n)&&t.execute(q.ZoomTo,{...t.getStartPosition()})}}function r(e,t){let n=t.target;n&&!t.defaultPrevented&&n.dataset.panzoomAction&&f(n.dataset.panzoomAction)}function l(n,i){let a=i.el;if(!e||!a||i.panzoomRef)return;let r=i.src||i.lazySrc||"",l=i.alt||i.caption||`Image #${i.index}`,s=i.srcset||i.lazySrcset||"",c=i.sizes||i.lazySizes||"";if(r&&"string"==typeof r&&!i.html&&(!i.type||"image"===i.type)){i.type="image",i.thumbSrc=i.thumbSrc||r;let e=t("tpl",i);e=o(e,"{{src}}",r+""),e=o(e,"{{srcset}}",s+""),e=o(e,"{{sizes}}",c+""),a.insertAdjacentHTML("afterbegin",e)}let f=a.querySelector(".f-panzoom__content");if(!f)return;f.setAttribute("alt",l+"");let d=B(a,{width:i.width&&"auto"!==i.width?parseFloat(i.width+""):"auto",height:i.height&&"auto"!==i.height?parseFloat(i.height+""):"auto",classes:{container:"f-zoomable"},event:()=>e?.getLastMouseMove(),spinnerTpl:()=>e?.getOption("spinnerTpl")||"",...t("Panzoom")});d.on("*",(t,n,...o)=>{e&&("loading"===n&&(i.state=0),"loaded"===n&&(i.state=1),"error"===n&&(i.state=2,e?.showError(i,"{{IMAGE_ERROR}}")),e.emit(`panzoom:${n}`,i,...o),"ready"===n&&e.emit("contentReady",i),i.index===e?.getPageIndex()&&u())}),i.panzoomRef=d}function s(e,t){t.panzoomRef&&(t.panzoomRef.destroy(),t.panzoomRef=void 0)}function c(e,t){let n=t.panzoomRef;if(n)switch(n.getState()){case W.Init:n.init();break;case W.Ready:n.execute(q.ZoomTo,{...n.getStartPosition(),velocity:0})}}function u(){let t=e?.getContainer()||void 0,n=e?.getPage()?.slides[0]?.panzoomRef;if(t)if(n)n.updateControls(t);else for(let e of t.querySelectorAll("[data-panzoom-action]")||[])e.setAttribute("aria-disabled",""),e.setAttribute("tabindex","-1")}function f(t,...n){e?.getPage().slides[0].panzoomRef?.execute(t,...n)}return{init:function(t){(e=t).on("initPlugins",i)},destroy:function(){if(e)for(let t of(e.off("initPlugins",i),e.off("addSlide",l),e.off("removeSlide",s),e.off("attachSlideEl",c),e.off("click",r),e.off("change",a),e.off("ready",a),e.getSlides()))s(e,t);e=void 0},execute:f}}});