@fancyapps/ui
Version:
Robust JavaScript UI Component Library
3 lines (2 loc) • 20.6 kB
JavaScript
/*! License details at fancyapps.com/license */
import{isString as e}from"../utils/isString.js";import{isNode as t}from"../utils/isNode.js";import{getScrollableParent as n}from"../utils/getScrollableParent.js";import{stringToHtml as o}from"../utils/strToHtml.js";import{clamp as i}from"../utils/clamp.js";import{Tween as s}from"../libs/tween.js";import{getMidpoint as a,getChangedPosition as r,Gestures as l}from"../libs/gestures.js";import{en_EN as c}from"./l10n/en_EN.js";import{addClass as u}from"../utils/addClass.js";import{removeClass as d}from"../utils/removeClass.js";import{toggleClass as f}from"../utils/toggleClass.js";import{isEqual as g}from"../utils/isEqual.js";const h=e=>{e.cancelable&&e.preventDefault()},m=(e,t=1e4)=>(e=parseFloat(e+"")||0,Math.round((e+Number.EPSILON)*t)/t),p=e=>e instanceof HTMLImageElement;var v,b;!function(e){e.Reset="reset",e.Zoom="zoom",e.ZoomIn="zoomIn",e.ZoomOut="zoomOut",e.ZoomTo="zoomTo",e.ToggleCover="toggleCover",e.ToggleFull="toggleFull",e.ToggleMax="toggleMax",e.IterateZoom="iterateZoom",e.Pan="pan",e.Swipe="swipe",e.Move="move",e.MoveLeft="moveLeft",e.MoveRight="moveRight",e.MoveUp="moveUp",e.MoveDown="moveDown",e.RotateCCW="rotateCCW",e.RotateCW="rotateCW",e.FlipX="flipX",e.FlipY="flipY",e.ToggleFS="toggleFS"}(v||(v={})),function(e){e.Cover="cover",e.Full="full",e.Max="max"}(b||(b={}));const y={x:0,y:0,scale:1,angle:0,flipX:1,flipY:1},x={bounds:!0,classes:{container:"f-panzoom",wrapper:"f-panzoom__wrapper",content:"f-panzoom__content",viewport:"f-panzoom__viewport"},clickAction:v.ToggleFull,dblClickAction:!1,gestures:{},height:"auto",l10n:c,maxScale:4,minScale:1,mouseMoveFactor:1,panMode:"drag",protected:!1,singleClickAction:!1,spinnerTpl:'<div class="f-spinner"></div>',wheelAction:v.Zoom,width:"auto"};let w,M=0,j=0,E=0;const S=(c,b={},S={})=>{let k,O,T,A,C,F,Z,L,P=0,X=Object.assign(Object.assign({},x),b),Y={},R=Object.assign({},y),z=Object.assign({},y);const D=[];function I(e){let t=X[e];return t&&"function"==typeof t?t(je):t}function W(){return c&&c.parentElement&&k&&3===P}const $=new Map;function q(e,...t){const n=[...$.get(e)||[]];X.on&&n.push(X.on[e]);for(const e of n)e&&e instanceof Function&&e(je,...t);"*"!==e&&q("*",e,...t)}function H(e){if(!W())return;const t=e.target;if(n(t))return;const o=Date.now(),s=[-e.deltaX||0,-e.deltaY||0,-e.detail||0].reduce(function(e,t){return Math.abs(t)>Math.abs(e)?t:e}),a=i(-1,s,1);q("wheel",e,a);const r=I("wheelAction");if(!r)return;if(e.defaultPrevented)return;const l=z.scale;let c=l*(a>0?1.5:.5);if(r===v.Zoom){const t=Math.abs(e.deltaY)<100&&Math.abs(e.deltaX)<100;if(o-j<(t?200:45))return void h(e);j=o;const n=ne(),s=se();if(m(c)<m(n)&&m(l)<=m(n)?(E+=Math.abs(a),c=n):m(c)>m(s)&&m(l)>=m(s)?(E+=Math.abs(a),c=s):(E=0,c=i(n,c,s)),E>7)return}switch(h(e),r){case v.Pan:ce(r,{srcEvent:e,deltaX:2*-e.deltaX,deltaY:2*-e.deltaY});break;case v.Zoom:ce(v.ZoomTo,{srcEvent:e,scale:c,center:{x:e.clientX,y:e.clientY}});break;default:ce(r,{srcEvent:e})}}function _(e){var n,o;const i=e.composedPath()[0];if(!l.isClickAllowed())return;if(!t(i)||e.defaultPrevented)return;if(!(null==c?void 0:c.contains(i)))return;if(i.hasAttribute("disabled")||i.hasAttribute("aria-disabled")||i.hasAttribute("data-carousel-go-prev")||i.hasAttribute("data-carousel-go-next"))return;const s=i.closest("[data-panzoom-action]"),a=null===(n=null==s?void 0:s.dataset)||void 0===n?void 0:n.panzoomAction,r=(null===(o=null==s?void 0:s.dataset)||void 0===o?void 0:o.panzoomValue)||"";if(a){switch(h(e),a){case v.ZoomTo:case v.ZoomIn:case v.ZoomOut:ce(a,{scale:parseFloat(r||"")||void 0});break;case v.MoveLeft:case v.MoveRight:ce(a,{deltaX:parseFloat(r||"")||void 0});break;case v.MoveUp:case v.MoveDown:ce(a,{deltaY:parseFloat(r||"")||void 0});break;case v.ToggleFS:we();break;default:ce(a)}return}if(!(null==k?void 0:k.contains(i)))return;const u={srcEvent:e};if(ce(I("clickAction"),u),I("dblClickAction")){const e=Date.now(),t=e-(M||e);M=e,t>0&&t<=250?(w&&(clearTimeout(w),w=void 0),ce(I("dblClickAction"),u)):w=setTimeout(()=>{ce(I("singleClickAction"),u)},250)}}function B(e){if(L=e,!W()||!Q())return;if(R.scale<=1||z.scale<=1)return;if(((null==k?void 0:k.dataset.animationName)||"").indexOf("zoom")>-1)return;const t=ee(z.scale);if(!t)return;const{x:n,y:o}=t;ce(v.Pan,{deltaX:n-z.x,deltaY:o-z.y})}function N(){var e;c&&(d(c,"is-loading"),null===(e=c.querySelector(".f-spinner"))||void 0===e||e.remove())}function V(){if(!c||!O)return;if(N(),p(O)&&(!O.complete||!O.naturalWidth))return P=2,null==k||k.classList.add("has-error"),void q("error");q("loaded");const{width:e,height:t}=J();p(O)&&(O.setAttribute("width",e+""),O.setAttribute("height",t+"")),k&&(d(k,"has-error"),p(O)&&(k.setAttribute("width",e+""),k.setAttribute("height",t+""),k.style.aspectRatio=`${e/t||""}`)),F=s().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),z=Object.assign(Object.assign({},y),t),le(),q("animationStart")}).on("pause",e=>{z=Object.assign(Object.assign({},y),e)}).on("step",e=>{if(!W())return void(null==F||F.end());if(R=Object.assign(Object.assign({},y),e),Q()||!I("bounds")||be()||z.scale>R.scale||z.scale<oe())return void ue();const t=ae(z.scale);let n=!1,o=!1,s=!1,a=!1;R.x<t.x[0]&&(n=!0),R.x>t.x[1]&&(o=!0),R.y<t.y[0]&&(a=!0),R.y>t.y[1]&&(s=!0);let r=!1,l=!1,c=!1,u=!1;z.x<t.x[0]&&(r=!0),z.x>t.x[1]&&(l=!0),z.y<t.y[0]&&(u=!0),z.y>t.y[1]&&(c=!0);let d=!1;(o&&l||n&&r)&&(z.x=i(t.x[0],z.x,t.x[1]),d=!0),(s&&c||a&&u)&&(z.y=i(t.y[0],z.y,t.y[1]),d=!0),d&&F&&F.spring({tension:94,friction:17,maxSpeed:555*z.scale,restDelta:.1,restSpeed:.1,velocity:F.getCurrentVelocities()}).from(R).to(z).start(),ue()}).on("end",()=>{(null==C?void 0:C.isPointerDown())||re(),(null==F?void 0:F.isRunning())||(le(),q("animationEnd"))}),function(){const e=I("gestures");if(!e)return;if(!A||!O)return;let t=!1;C=l(A,e).on("start",e=>{if(!I("gestures"))return;if(!F)return;if(!W()||Q())return;const n=e.srcEvent;(R.scale>1||e.currentTouch.length>1)&&(null==n||n.stopPropagation(),F.pause(),t=!0),1===e.currentTouch.length&&q("touchStart")}).on("move",e=>{var n;t&&(1!==z.scale||e.currentTouch.length>1)&&(h(e.srcEvent),null===(n=e.srcEvent)||void 0===n||n.stopPropagation())}).on("pan",e=>{if(!t)return;const n=e.srcEvent;(1!==z.scale||e.currentTouch.length>1)&&(h(n),ce(v.Pan,e))}).on("swipe",e=>{t&&z.scale>1&&ce(v.Swipe,e)}).on("tap",e=>{q("click",e)}).on("singleTap",e=>{q("singleClick",e)}).on("doubleTap",e=>{q("dblClick",e)}).on("pinch",e=>{t&&(e.scale>oe()?ce(v.ZoomIn,e):e.scale<oe()?ce(v.ZoomOut,e):ce(v.Pan,e))}).on("end",e=>{t&&(e.currentTouch.length?(e.srcEvent.stopPropagation(),h(e.srcEvent),null==F||F.end()):(t=!1,le(),re(),q("touchEnd")))}).init()}(),A&&(A.addEventListener("wheel",H,{passive:!1}),D.push(()=>{null==A||A.removeEventListener("wheel",H,{passive:!1})})),null==c||c.addEventListener("click",_),null===document||void 0===document||document.addEventListener("mousemove",B),D.push(()=>{null==c||c.removeEventListener("click",_),null===document||void 0===document||document.removeEventListener("mousemove",B)});const n=U();R=Object.assign({},n),z=Object.assign({},n),P=3,ue(),le(),q("ready"),requestAnimationFrame(()=>{3===P&&(N(),A&&(A.style.visibility=""))})}function U(){const e=Object.assign({},I("startPos")||{});let t=e.scale,n=1;n="string"==typeof t?te(t):"number"==typeof t?t:oe();const o=Object.assign(Object.assign(Object.assign({},y),e),{scale:n}),i=Q()?ee(n):void 0;if(i){const{x:e,y:t}=i;o.x=e,o.y=t}return o}function G(){const e={top:0,left:0,width:0,height:0};if(k){const t=k.getBoundingClientRect();z.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 J(){let t=I("width"),n=I("height");if(O&&"auto"===t){const e=O.getAttribute("width");t=e?parseFloat(e+""):void 0!==O.dataset.width?parseFloat(O.dataset.width+""):p(A)?A.naturalWidth:p(O)?O.naturalWidth:(null==k?void 0:k.getBoundingClientRect().width)||0}else t=e(t)?parseFloat(t):t;if(O&&"auto"===n){const e=O.getAttribute("height");n=e?parseFloat(e+""):void 0!==O.dataset.height?parseFloat(O.dataset.height+""):p(A)?A.naturalHeight:p(O)?O.naturalHeight:(null==k?void 0:k.getBoundingClientRect().height)||0}else n=e(n)?parseFloat(n):n;return{width:t,height:n}}function K(){const e=G();return{width:e.width,height:e.height}}function Q(){return"mousemove"===I("panMode")&&matchMedia("(hover: hover)").matches}function ee(e){const t=L||I("event"),n=null==k?void 0:k.getBoundingClientRect();if(!t||!n||e<=1)return{x:0,y:0};const o=(t.clientX||0)-n.left,s=(t.clientY||0)-n.top,{width:a,height:r}=K(),l=ae(e);if(e>1){const t=I("mouseMoveFactor");t>1&&(e*=t)}let c=a*e,u=r*e,d=.5*(c-a)-o/a*100/100*(c-a),f=.5*(u-r)-s/r*100/100*(u-r);return d=i(l.x[0],d,l.x[1]),f=i(l.y[0],f,l.y[1]),{x:d,y:f}}function te(e){if(!e)return z.scale;if(!c)return 1;const t=c.getBoundingClientRect(),n=G(),{width:o,height:s}=J(),a=e=>{if("number"==typeof e)return e;switch(e){case"min":case"base":return 1;case"cover":return Math.max(t.height/n.height,t.width/n.width)||1;case"full":case"max":{const e=z.angle%180==90?s:o;return e&&n.width?e/n.width:1}}},r=I("minScale"),l=I("maxScale"),u=Math.min(a("full"),a(r)),d="number"==typeof l?a("full")*l:Math.min(a("full"),a(l));switch(e){case"min":return u;case"base":return i(u,1,d);case"cover":return a("cover");case"full":return Math.min(d,a("full"));case"max":return d}}function ne(){return te("min")}function oe(){return te("base")}function ie(){return te("full")}function se(){return te("max")}function ae(e){const t={x:[0,0],y:[0,0]},n=null==c?void 0:c.getBoundingClientRect();if(!n)return t;const o=G(),i=n.width,s=n.height;let a=o.width,r=o.height,l=e=void 0===e?z.scale:e,u=e;if(Q()&&e>1){const t=I("mouseMoveFactor");t>1&&(a*e>i+.01&&(l*=t),r*e>s+.01&&(u*=t))}return a*=l,r*=u,e>1&&(a>i&&(t.x[0]=.5*(i-a),t.x[1]=.5*(a-i)),t.x[0]-=.5*(o.left-n.left),t.x[1]-=.5*(o.left-n.left),t.x[0]-=.5*(o.left+o.width-n.right),t.x[1]-=.5*(o.left+o.width-n.right),r>s&&(t.y[0]=.5*(s-r),t.y[1]=.5*(r-s)),t.y[0]-=.5*(o.top-n.top),t.y[1]-=.5*(o.top-n.top),t.y[0]-=.5*(o.top+o.height-n.bottom),t.y[1]-=.5*(o.top+o.height-n.bottom)),t}function re(){if(!W())return;if(!I("bounds"))return;if(!F)return;const e=ne(),t=se(),n=i(e,z.scale,t);if(z.scale<e-.01||z.scale>t+.01)return void ce(v.ZoomTo,{scale:n});if(F.isRunning())return;if(be())return;const o=ae(n);z.x<o.x[0]||z.x>o.x[1]||z.y<o.y[0]||z.y>o.y[1]?(z.x=i(o.x[0],z.x,o.x[1]),z.y=i(o.y[0],z.y,o.y[1]),F.spring({tension:170,friction:17,restDelta:.001,restSpeed:.001,maxSpeed:1/0,velocity:F.getCurrentVelocities()}),F.from(R).to(z).start()):ue()}function le(e){var t;if(!W())return;const n=ve(),o=be(),i=ye(),s=xe(),a=fe(),r=ge();f(k,"is-fullsize",s),f(k,"is-expanded",i),f(k,"is-dragging",o),f(k,"can-drag",n),f(k,"will-zoom-in",a),f(k,"will-zoom-out",r);const l=me(),u=pe(),d=he(),g=!W();for(const n of(null===(t=e||c)||void 0===t?void 0:t.querySelectorAll("[data-panzoom-action]"))||[]){const e=n.dataset.panzoomAction;let t=!1;if(g)t=!0;else switch(e){case v.ZoomIn:l||(t=!0);break;case v.ZoomOut:d||(t=!0);break;case v.ToggleFull:{u||d||(t=!0);const e=n.querySelector("g");e&&(e.style.display=s&&!t?"none":"");break}case v.IterateZoom:{l||d||(t=!0);const e=n.querySelector("g");e&&(e.style.display=l||t?"":"none");break}case v.ToggleCover:case v.ToggleMax:l||d||(t=!0)}t?(n.setAttribute("aria-disabled",""),n.setAttribute("tabindex","-1")):(n.removeAttribute("aria-disabled"),n.removeAttribute("tabindex"))}}function ce(e,t){var n;if(!(e&&c&&O&&F&&W()))return;if(e===v.Swipe&&Math.abs(F.getCurrentVelocities().scale)>.01)return;const o=Object.assign({},z);let s=Object.assign({},z),l=ae(Q()?o.scale:R.scale);const u=F.getCurrentVelocities(),d=G(),f=((null===(n=(t=t||{}).currentTouch)||void 0===n?void 0:n.length)||0)>1,h=t.velocityX||0,m=t.velocityY||0;let p=t.center;t.srcEvent&&(p=a(r(t.srcEvent)));let b=t.deltaX||0,x=t.deltaY||0;switch(e){case v.MoveRight:b=t.deltaX||100;break;case v.MoveLeft:b=t.deltaX||-100;break;case v.MoveUp:x=t.deltaY||-100;break;case v.MoveDown:x=t.deltaY||100}let w=[];if("number"==typeof e)s.scale=e;else switch(e){case v.Reset:s=Object.assign({},y),s.scale=oe();break;case v.ZoomTo:case v.ZoomIn:case v.ZoomOut:case v.ToggleCover:case v.ToggleFull:case v.ToggleMax:case v.IterateZoom:case v.Zoom:s.scale=de(e,t);break;case v.Pan:case v.Move:case v.MoveLeft:case v.MoveRight:case v.MoveUp:case v.MoveDown:if(be()){let e=1,t=1;s.x<=l.x[0]&&h<=0&&(e=Math.max(.01,1-Math.abs(1/d.width*Math.abs(s.x-l.x[0]))),e*=.2),s.x>=l.x[1]&&h>=0&&(e=Math.max(.01,1-Math.abs(1/d.width*Math.abs(s.x-l.x[1]))),e*=.2),s.y<=l.y[0]&&m<=0&&(t=Math.max(.01,1-Math.abs(1/d.height*Math.abs(s.y-l.y[0]))),t*=.2),s.y>=l.y[1]&&m>=0&&(t=Math.max(.01,1-Math.abs(1/d.height*Math.abs(s.y-l.y[1]))),t*=.2),s.x+=b*e,s.y+=x*t}else s.x=i(l.x[0],s.x+b,l.x[1]),s.y=i(l.y[0],s.y+x,l.y[1]);break;case v.Swipe:const n=(e=0)=>Math.sign(e)*Math.pow(Math.abs(e),1.5);s.x+=i(-1e3,n(h),1e3),s.y+=i(-1e3,n(m),1e3),m&&!h&&(s.x=i(l.x[0],s.x,l.x[1])),!m&&h&&(s.y=i(l.y[0],s.y,l.y[1])),u.x=h,u.y=m;break;case v.RotateCW:s.angle+=90;break;case v.RotateCCW:s.angle-=90;break;case v.FlipX:s.flipX*=-1;break;case v.FlipY:s.flipY*=-1}if(void 0!==R.angle&&Math.abs(R.angle)>=360&&(s.angle-=360*Math.floor(R.angle/360),R.angle-=360*Math.floor(R.angle/360)),w.length){const e=w.findIndex(e=>e>s.scale+1e-4);s.scale=w[e]||w[0]}if(f&&(s.scale=i(ne()*(f?.8:1),s.scale,se()*(f?1.6:1))),Q()){const e=ee(s.scale);if(e){const{x:t,y:n}=e;s.x=t,s.y=n}}else if(Math.abs(s.scale-o.scale)>1e-4){let e=0,t=0;if(p)e=p.x,t=p.y;else{const n=c.getBoundingClientRect();e=n.x+.5*n.width,t=n.y+.5*n.height}let n=e-d.left,a=t-d.top;n-=.5*d.width,a-=.5*d.height;const r=(n-o.x)/o.scale,u=(a-o.y)/o.scale;s.x=n-r*s.scale,s.y=a-u*s.scale,!f&&I("bounds")&&(l=ae(s.scale),s.x=i(l.x[0],s.x,l.x[1]),s.y=i(l.y[0],s.y,l.y[1]))}if(e===v.Swipe){let e=94,t=17,n=500*s.scale,o=u;F.spring({tension:e,friction:t,maxSpeed:n,restDelta:.1,restSpeed:.1,velocity:o})}else e===v.Pan||f?F.spring({tension:900,friction:17,restDelta:.01,restSpeed:.01,maxSpeed:1}):F.spring({tension:170,friction:17,restDelta:.001,restSpeed:.001,maxSpeed:1/0,velocity:u});if(0===t.velocity||g(R,s))R=Object.assign({},s),z=Object.assign({},s),F.end(),ue(),le();else{if(g(z,s))return;F.from(R).to(s).start()}q("action",e)}function ue(){if(!O||!k||!A)return;const{width:e,height:t}=J();Object.assign(k.style,{maxWidth:`min(${e}px, 100%)`,maxHeight:`min(${t}px, 100%)`});const n=function(){const{width:e,height:t}=J(),{width:n,height:o}=K();if(!c)return{x:0,y:0,width:0,height:0,scale:0,flipX:0,flipY:0,angle:0,fitWidth:n,fitHeight:o,fullWidth:e,fullHeight:t};let{x:i,y:s,scale:a,angle:r,flipX:l,flipY:u}=R,d=1/ie(),f=e,g=t,h=R.scale*d,m=z.scale*d;const p=Math.max(n,o),v=Math.min(n,o);e>t?(f=p,g=v):(f=v,g=p);h=e>t?p*a/e||1:p*a/t||1;let b=f?e*m:0,y=g?t*m:0,x=f&&g?e*h/b:0;return i=i+.5*f-.5*b,s=s+.5*g-.5*y,{x:i,y:s,width:b,height:y,scale:x,flipX:l,flipY:u,angle:r,fitWidth:n,fitHeight:o,fullWidth:e,fullHeight:t}}(),{x:o,y:i,width:s,height:a,scale:r,angle:l,flipX:u,flipY:d}=n;let f=`translate(${m(o)}px, ${m(i)}px)`;f+=1!==u||1!==d?` scaleX(${m(r*u)}) scaleY(${m(r*d)})`:` scale(${m(r)})`,0!==l&&(f+=` rotate(${l}deg)`),A.style.width=`${m(s)}px`,A.style.height=`${m(a)}px`,A.style.transform=`${f}`,q("render")}function de(e=I("clickAction"),t={}){let n=z.scale,o=oe(),s=[];if("number"==typeof e)o=e;else if(e){switch(e){case v.ZoomTo:o=t.scale||1;break;case v.ZoomIn:o=n*(t.scale||2);break;case v.ZoomOut:o=n*(t.scale||.5);break;case v.ToggleCover:s=[oe(),te("cover")];break;case v.ToggleFull:s=[oe(),ie()];break;case v.ToggleMax:s=[oe(),se()];break;case v.IterateZoom:s=[oe(),ie(),se()];break;case v.Zoom:const e=ie();o=n>=e-.05?oe():Math.min(e,n*(t.scale||2))}if(s.length){const e=s.findIndex(e=>e>n+1e-4);o=s[e]||oe()}}return e!==v.ZoomTo&&(o=i(ne(),o,se())),o}function fe(){return!!(W()&&de()>z.scale)}function ge(){return!!(W()&&de()<z.scale)}function he(){return!!(W()&&z.scale>ne())}function me(){return!!(W()&&z.scale<se())}function pe(){return!!(W()&&z.scale<ie())}function ve(){return!(!(W()&&ye()&&C)||Q())}function be(){return!(!W()||!(null==C?void 0:C.isPointerDown())||Q())}function ye(){return!!(W()&&z.scale>oe())}function xe(){return!!(W()&&z.scale>=ie())}function we(){const e="in-fullscreen",t="with-panzoom-in-fullscreen";null==c||c.classList.toggle(e);const n=null==c?void 0:c.classList.contains(e);n?(document.documentElement.classList.add(t),document.addEventListener("keydown",Me,!0)):(document.documentElement.classList.remove(t),document.removeEventListener("keydown",Me,!0)),ue(),q(n?"enterFS":"exitFS")}function Me(e){"Escape"!==e.key||e.defaultPrevented||we()}const je={canDrag:ve,canZoomIn:me,canZoomOut:he,canZoomToFull:pe,destroy:function(){q("destroy");for(const e of Object.values(Y))null==e||e.destroy(je);for(const e of D)e();return k&&(k.style.aspectRatio="",k.style.maxWidth="",k.style.maxHeight=""),A&&(A.style.width="",A.style.height="",A.style.transform=""),k=void 0,O=void 0,A=void 0,R=Object.assign({},y),z=Object.assign({},y),null==F||F.destroy(),F=void 0,null==C||C.destroy(),C=void 0,P=4,je},emit:q,execute:ce,getBoundaries:ae,getContainer:function(){return c},getContent:function(){return O},getFullDim:J,getGestures:function(){return C},getMousemovePos:ee,getOptions:function(){return X},getPlugins:function(){return Y},getScale:te,getStartPosition:U,getState:function(){return P},getTransform:function(e){return!0===e?z:R},getTween:function(){return F},getViewport:function(){return A},getWrapper:function(){return k},init:function(){return P=0,q("init"),function(){for(const[e,t]of Object.entries(Object.assign(Object.assign({},S),X.plugins||{})))if(e&&!Y[e]&&t instanceof Function){const n=t();n.init(je),Y[e]=n}q("initPlugins")}(),function(){var e,t,n;const o=Object.assign(Object.assign({},x.classes),I("classes"));if(!c)return;u(c,o.container);const i=null===(e=o.content)||void 0===e?void 0:e.split(" ").shift();i&&(O=c.querySelector(`.${i}`));if(!O)return;O.setAttribute("draggable","false");const s=null===(t=o.wrapper)||void 0===t?void 0:t.split(" ").shift();s&&(k=c.querySelector(`.${s}`));k||(k=document.createElement("div"),u(k,o.wrapper),O.insertAdjacentElement("beforebegin",k),k.insertAdjacentElement("afterbegin",O));const a=null===(n=o.viewport)||void 0===n?void 0:n.split(" ").shift();a&&(A=c.querySelector(`.${a}`));A||(A=document.createElement("div"),u(A,o.viewport),A.insertAdjacentElement("afterbegin",O),k.insertAdjacentElement("beforeend",A));T=O.cloneNode(!0),T.removeAttribute("id"),k.insertAdjacentElement("afterbegin",T),O instanceof HTMLPictureElement&&(O=O.querySelector("img"));T instanceof HTMLPictureElement&&(T=T.querySelector("img"));A instanceof HTMLPictureElement&&(A=A.querySelector("img"));if(A&&(A.style.visibility="hidden",I("protected"))){A.addEventListener("contextmenu",e=>{h(e)});const e=document.createElement("div");u(e,"f-panzoom__protected"),A.appendChild(e)}q("initLayout")}(),function(){if(c&&k&&!Z){let e=null;Z=new ResizeObserver(()=>{W()&&(e=e||requestAnimationFrame(()=>{W()&&(le(),re(),q("refresh")),e=null}))}),Z.observe(k),D.push(()=>{null==Z||Z.disconnect(),Z=void 0,e&&(cancelAnimationFrame(e),e=null)})}}(),function(){if(!c||!O)return;if(!p(O)||!p(T))return void V();const e=()=>{O&&p(O)&&O.decode().then(()=>{V()}).catch(()=>{V()})};if(P=1,c.classList.add("is-loading"),q("loading"),T.src&&T.complete)return void e();(function(){if(!c)return;if(null==c?void 0:c.querySelector(".f-spinner"))return;const e=I("spinnerTpl"),t=o(e);t&&(t.classList.add("f-spinner"),c.classList.add("is-loading"),null==k||k.insertAdjacentElement("afterbegin",t))})(),T.addEventListener("load",e,!1),T.addEventListener("error",e,!1),D.push(()=>{null==T||T.removeEventListener("load",e,!1),null==T||T.removeEventListener("error",e,!1)})}(),je},isDragging:be,isExpanded:ye,isFullsize:xe,isMousemoveMode:Q,localize:function(e,t=[]){const n=I("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(const n of e instanceof Array?e:[e])$.has(n)&&$.set(n,$.get(n).filter(e=>e!==t));return je},on:function(e,t){for(const n of e instanceof Array?e:[e])$.set(n,[...$.get(n)||[],t]);return je},toggleFS:we,updateControls:le,version:"6.1.11",willZoomIn:fe,willZoomOut:ge};return je};S.l10n={en_EN:c},S.getDefaults=()=>x;export{y as PANZOOM_DEFAULT_POS,S as Panzoom,v as PanzoomAction,b as PanzoomZoomLevel};