(function(X,R){typeof exports=="object"&&typeof module<"u"?R(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],R):(X=typeof globalThis<"u"?globalThis:X||self,R(X.ReactPanzoom={},X.React))})(this,function(X,R){"use strict";const L=e=>({current:e}),ie={EFFECT:"effect",REF:"ref",STATE:"state"};let Le=null;const se=[],bt=()=>se[se.length-1],Nt=(e,t)=>{se.push(e),Le=t},Et=()=>se.pop(),Mt=()=>Le,j={get:bt,getInitializationId:Mt,push:Nt,pop:Et},Ct=(e,t,n)=>{const o={batchTimeoutRender:null,it:0,hooks:[],render:()=>{o.unmounted||(j.push(o,e),o.it=0,t(o.props),j.pop())},props:{},unmounted:!1},r=()=>{o.unmounted||(o.unmounted=!0,o.hooks.forEach(s=>{s.type===ie.EFFECT&&s.onUnmount&&s.onUnmount()}))},i=s=>{const l=n?n(s):s;let c=!1;return Object.entries(l).forEach(([u,d])=>{if(d===void 0)return;const a=o.props[u];a&&typeof a=="object"&&"current"in a?a.current=d:(o.props[u]=d,c=!0)}),c};return{context:o,render:o.render,unmount:r,updateProps:i}},wt=(e=0)=>(t,n)=>Ct(e,t,n),St=e=>{e.forEach(t=>{t.render()})},Pt=(e,t)=>{for(let n=0;n{const n=j.get(),o=n.it;n.it++;let r=n.hooks[o];if(!r){const s=e();r={type:ie.EFFECT,deps:t,onUnmount:s},n.hooks[o]=r;return}if(Pt(r.deps,t))return;r.onUnmount&&r.onUnmount();const i=e();r.onUnmount=i,r.deps=t},be={},Ne=(e,t)=>{v(()=>{const n=`${j.getInitializationId()}.${e}`;return be[n]=t,()=>{delete be[n]}},[t])},Ee=e=>be[`${j.getInitializationId()}.${e}`],W=e=>{const t=j.get(),n=t.it;t.it++;let o=t.hooks[n];if(!o){const r={current:e||null};return o={type:ie.REF,value:r},t.hooks[n]=o,r}return o.value},ce=e=>{const t=j.get(),n=t.it;t.it++;let o=t.hooks[n];const r=i=>{o.value=i,clearTimeout(t.batchTimeoutRender),t.batchTimeoutRender=setTimeout(t.render,0)};return o?[o.value,r]:(o={type:ie.STATE,value:e},t.hooks[n]=o,[e,r])},Ye="elements",B=()=>Ee(Ye),It=()=>{const e=W({}),t=W(null),n=W({}),o=W();Ne(Ye,{elementsRef:e,elementsInMoveRef:t,elementsUpdatePositionApiRef:n,lastElementMouseMoveEventRef:o})},_=30,$t="panzoom-core",At="panzoom-core-element",Tt=20,le=15,Wt=15,Ot=15,kt=250,Zt=20,Lt=30,Yt=.125,Xt=.04,Ht=.3,Ut=5,jt=1,Xe=1e4,Bt=20,He=1,Dt=5,Ft=300,Jt={width:"100%",height:"100%",overflow:"hidden","touch-action":"none","-webkit-font-smoothing":"antialiased"},Vt={position:"relative",overflow:"hidden","transform-origin":"0 0","pointer-events":"none"},_t={"user-select":"none"},qt={display:"inline-block",position:"absolute",left:"0px",top:"0px","pointer-events":"all"},Qt={position:"absolute",width:"100%",height:"100%",left:"0px",top:"0px","z-index":"2147483647"},Ue={"background-color":"#ccc",opacity:"0.5"},Gt=(e,t)=>{var n,o;document.body.classList.add(t),(o=(n=e==null?void 0:e.parentNode)==null?void 0:n.classList)==null||o.add(`${t}-in`)},Kt=(e,t)=>{var n,o;document.body.classList.remove(t),document.body.getAttribute("class")||document.body.removeAttribute("class"),(o=(n=e==null?void 0:e.parentNode)==null?void 0:n.classList)==null||o.remove(`${t}-in`)},D={add:Gt,remove:Kt},F=()=>window,je=e=>"touches"in e?e.touches.length>1:!1,q=(e,t,n)=>(t.forEach(o=>{e.addEventListener(o,n)}),()=>{t.forEach(o=>{e.removeEventListener(o,n)})}),ee=(e,t)=>q(e,["mousedown","touchstart"],t),te=(e,t)=>{const n=q(F(),["mouseup"],t),o=q(e,["touchend","touchcancel"],t);return()=>{n(),o()}},Q=e=>{const t=q(F(),["mousemove"],e),n=r=>{je(r)||e(r)},o=q(F(),["touchmove"],n);return()=>{t(),o()}},Be=(e,t)=>q(e,["contextmenu"],t),H=e=>{const{touches:t}=e;if(t)return{clientX:t[0].clientX,clientY:t[0].clientY};const n=e;return{clientX:n.clientX,clientY:n.clientY}},O=({position:e,zoom:t})=>t?`translate(${e.x}px, ${e.y}px) scale(${t})`:`translate(${e.x}px, ${e.y}px)`,De=()=>{const e=()=>{e.done=!0};return e.done=!1,e},Me=({elementsRef:e,elementsInMove:t,onElementsChange:n,produceNextPosition:o})=>{const r={},i=()=>{let c=null;const u=(d,a)=>{c!==null&&Math.abs(d-a)>=Math.abs(c)||(c=d-a,u.value=c)};return u.value=c,u},s=i(),l=i();Object.entries(t).forEach(([c,u])=>{const d=e.current[c],a=o(u,d);s(d.position.x,a.x),l(d.position.y,a.y)}),Object.entries(t).forEach(([c])=>{const u=e.current[c],d={x:u.position.x-s.value,y:u.position.y-l.value};r[c]=d,u.position=d,u.node.current.style.transform=O({position:d})}),n&&n(r)},x=e=>e.getBoundingClientRect(),ue=e=>{const t=(n,o)=>{for(let r=e;r&&!(!r||o&&o(r));r=r.parentNode)n(r)};return{forEachToWindow:n=>{t(n)},forEach:n=>{t(n,o=>o===document.body)}}},de=e=>{const t=e.parentNode,n={x:0,y:0};return ue(t.parentNode).forEachToWindow(o=>{n.x+=o.scrollLeft||0,n.y+=o.scrollTop||0}),n},G=({elementNode:e,childNode:t,x:n,y:o,zoom:r})=>{const i=x(e),s=x(t),l=(s.width-i.width)/r,c=(s.height-i.height)/r,u={x:n,y:o};return u.x<0?u.x=0:u.x>l&&(u.x=l),u.y<0?u.y=0:u.y>c&&(u.y=c),u},Fe="panzoom",$=()=>Ee(Fe),en=e=>{Ne(Fe,e)},tn=(e,t)=>{const n=e.parentNode;return{apiRef:L(null),blockMovingRef:L(!1),boundary:t.boundary,childNode:e,className:t.className||"panzoom-core",containerNode:n,disabled:t.disabled||!1,disabledElements:t.disabledElements||!1,disabledScrollHorizontal:t.disabledScrollHorizontal===void 0?!0:t.disabledScrollHorizontal,disabledScrollVertical:t.disabledScrollVertical===void 0?!0:t.disabledScrollVertical,disabledUserSelect:t.disabledUserSelect||!1,disabledZoom:t.disabledZoom||!1,disabledMove:t.disabledMove||!1,elementsAutoMoveAtEdge:t.elementsAutoMoveAtEdge===void 0?!0:t.elementsAutoMoveAtEdge,onContextMenuRef:L(t.onContextMenu),onContainerChangeRef:L(t.onContainerChange),onContainerClickRef:L(t.onContainerClick),onContainerPositionChangeRef:L(t.onContainerPositionChange),onContainerZoomChangeRef:L(t.onContainerZoomChange),onElementsChangeRef:L(t.onElementsChange),positionRef:L({x:0,y:0}),selecting:t.selecting||!1,scrollSpeed:t.scrollSpeed||Lt,width:t.width||"100%",height:t.height||"100%",zoomRef:L(t.zoomInitial||He),zoomInitial:t.zoomInitial||He,zoomMin:t.zoomMin||Ht,zoomMax:t.zoomMax||Ut,zoomPosition:t.zoomPosition,zoomSpeed:t.zoomSpeed||jt}},Ce=()=>["boundary","className","disabled","disabledElements","disabledMove","disabledScrollHorizontal","disabledScrollVertical","disabledUserSelect","disabledZoom","elementsAutoMoveAtEdge","onElementsChange","onContextMenu","onContainerChange","onContainerClick","onContainerPositionChange","onContainerZoomChange","selecting","scrollSpeed","width","height","zoomInitial","zoomMax","zoomMin","zoomPosition","zoomSpeed"],nn=e=>{const t={},n=Ce();return Object.entries(e).forEach(([o,r])=>{!n.includes(o)||r===void 0||(typeof r=="function"?t[`${o}Ref`]=r:t[o]=r)}),t},Je=()=>{const{childNode:e,containerNode:t,zoomRef:n}=$();return(o,r)=>{const i=H(o),s=x(t),l=x(r),c=de(e);return{x:(i.clientX-l.left+s.left+c.x)/n.current,y:(i.clientY-l.top+s.top+c.y)/n.current}}},Ve=()=>{const{childNode:e,positionRef:t,zoomRef:n}=$();return(o,r,i)=>{const s=H(o),l=de(e);return G({elementNode:i,childNode:e,x:(s.clientX-t.current.x+l.x)/n.current-r.x,y:(s.clientY-t.current.y+l.y)/n.current-r.y,zoom:n.current})}},J=(e,t)=>{const n=t.trim().split(" ").filter(o=>o);return n.forEach(o=>{e.classList.add(o)}),()=>{n.forEach(o=>{e.classList.remove(o)}),e.className||e.removeAttribute("class")}},_e=e=>{e.getAttribute("style")||e.removeAttribute("style")},V=(e,t)=>(Object.entries(t).forEach(([n,o])=>{e.style.setProperty(n,o)}),()=>{Object.entries(t).forEach(([n])=>{e.style.removeProperty(n)}),_e(e)});let qe=2;const Qe=e=>{qe+=1,e.style.zIndex=qe.toString()},we=()=>{const e=x(document.body),t=F();return!e.width||!e.height?{width:t.innerWidth,height:t.innerHeight}:{width:Math.min(e.width,t.innerWidth),height:Math.min(e.height,t.innerHeight)}},ae=e=>{const t=x(e.parentNode),n=we(),o=[n.width-(t.left<0?0:t.left),t.right],r=[n.height-(t.top<0?0:t.top),t.bottom];ue(e.parentNode).forEach(l=>{if(!l.getBoundingClientRect)return;const c=x(l);c.right>0&&o.push(c.right-c.left),c.bottom>0&&r.push(c.bottom-c.top)});let i=Math.min(...o),s=Math.min(...r);return i<0&&(i=0),s<0&&(s=0),[i,s]},Ge=e=>{const[t]=ae(e),n=x(e),o=x(e.parentNode),r=Math.max(o.left,0);return n.right-t-r},on=(e,t)=>{const n=x(e),o=x(e.parentNode),r=t.current.x+n.width;return r+o.left>0&&r>=0&&Ge(e)<=0},Ke=e=>{const[,t]=ae(e),n=x(e),o=x(e.parentNode),r=Math.max(o.top,0);return n.bottom-t-r},rn=(e,t)=>{const n=x(e),o=x(e.parentNode),r=t.current.y+n.height;return r+o.top>0&&r>=0&&Ke(e)<=0},sn=(e,t)=>{const n=de(e),o=x(e.parentNode),[r]=ae(e);return t.current.x+o.left>=0&&t.current.x>=0&&t.current.x{const n=de(e),o=x(e.parentNode),[,r]=ae(e);return t.current.y+o.top>=0&&t.current.y>=0&&t.current.ye.clientHeight"scrollX"in e&&"scrollY"in e,Se=e=>{if(et(e)){const n=e;return{x:n.scrollX||0,y:n.scrollY||0}}const t=e;return{x:t.scrollLeft||0,y:t.scrollTop||0}},tt=(e,t)=>{if(et(e))e.scrollBy(t.x,t.y);else{const n=e;n.scrollLeft+=t.x,n.scrollTop+=t.y}return Se(e)},un=(e,t,n)=>{const o=e.parentNode,r=x(o),i=we(),s=t<0&&r.right>0&&i.width>r.right,l=t>0&&r.left>=0,c=s||l,u=n<0&&r.bottom>0&&i.height>r.bottom,d=n>0&&r.top>=0,a=u||d,f={x:t,y:n};return c&&a||ue(o.parentNode).forEachToWindow(m=>{if(ln(m)){if(!c){let h=Se(m);const p=h.x;h=tt(m,{x:-f.x,y:0}),f.x+=h.x-p}if(!a){let h=Se(m);const p=h.y;h=tt(m,{x:0,y:-f.y}),f.y+=h.y-p}}}),f},dn=({childNode:e,positionRef:t,addPosition:n,zoomRef:o})=>{const r=un(e,n.x,n.y);if(t.current={x:t.current.x+r.x,y:t.current.y+r.y},r.y<0){const i=Ke(e);i<-r.y&&(t.current.y+=-r.y-i)}else r.y>0&&t.current.y>0&&(t.current.y=0);if(r.x<0){const i=Ge(e);i<-r.x&&(t.current.x+=-r.x-i)}else r.x>0&&t.current.x>0&&(t.current.x=0);e.style.transform=O({position:t.current,zoom:o.current})},an=(e,t)=>{const n=x(e),o=x(e.parentNode),r=o.left>0?o.left:0,i=o.top>0?o.top:0,s=we();let l=n.left-r;l<0&&(l=0);let c=n.top-i;c<0&&(c=0);const u=[s.width-r,n.right,o.right-_,o.right-o.left],d=[s.height-i,n.bottom,o.bottom-_,o.bottom-o.top];ue(e.parentNode).forEach(y=>{if(!y.getBoundingClientRect)return;const g=x(y);g.right>0&&u.push(g.right-r),g.bottom>0&&d.push(g.bottom-i)});const a=Math.min(...u),f=Math.min(...d),m=t.clientX-r,h=t.clientY-i,p={top:!1,bottom:!1,left:!1,right:!1};return l+_>m?p.left=!0:m+_>a&&(p.right=!0),c+_>h?p.top=!0:h+_>f&&(p.bottom=!0),p},mn=()=>{const{childNode:e,onElementsChangeRef:t,positionRef:n,zoomRef:o}=$(),{elementsRef:r,lastElementMouseMoveEventRef:i}=B();return s=>{const l=setInterval(()=>{if(!i.current||!e)return;const c={x:0,y:0},u=an(e,i.current);u.left&&!me.left(e,n)?c.x=le:u.right&&!me.right(e,n)&&(c.x=-le),u.top&&!me.top(e,n)?c.y=le:u.bottom&&!me.bottom(e,n)&&(c.y=-le),!(!c.x&&!c.y)&&(dn({childNode:e,positionRef:n,addPosition:c,zoomRef:o}),Me({elementsRef:r,elementsInMove:s,produceNextPosition:(d,a)=>G({elementNode:a.node.current,childNode:e,x:a.position.x-c.x/o.current,y:a.position.y-c.y/o.current,zoom:o.current}),onElementsChange:t.current}))},Tt);return()=>{clearInterval(l),i.current=null}}},nt=e=>`${e}px`,ot=({className:e,elementNode:t,cb:n,onAfterResize:o,resizerNode:r})=>{ee(r,i=>{if(i.button)return;i.preventDefault(),i.stopPropagation();const s=J(t,`${e}--resizing`),l=n(i);let c=null;c=te(r,()=>{s(),l(),c(),o()}),Qe(t)})},rt=()=>{const e=document.createElement("div");return e.style.position="absolute",e},hn=({childNode:e,className:t,elementNode:n,elementsRef:o,id:r,onAfterResize:i,onStartResizing:s,resizedMaxWidth:l,resizedMinWidth:c,resizerWidth:u,zoomRef:d})=>{const a=rt();return a.style.left="0px",a.style.top="0px",a.style.width=nt(u),a.style.height="100%",a.style.cursor="w-resize",ot({className:t,elementNode:n,resizerNode:a,cb:f=>{const m=H(f),h=e.getBoundingClientRect(),p=F().getComputedStyle(n),y=new DOMMatrixReadOnly(p.transform),g=n.getBoundingClientRect();let z=(g.right-h.left)/d.current;return l&&l{const N=H(S),b={x:N.clientX-m.clientX,y:N.clientY-m.clientY};let M=g.width/d.current-b.x/d.current;c&&Mz&&(b.x+=(M-z)*d.current,M=z),n.style.width=`${M}px`;const E=G({elementNode:n,childNode:e,x:y.e+b.x/d.current,y:y.f,zoom:d.current});c&&M{n.removeChild(a)}},fn=({childNode:e,className:t,elementNode:n,elementsRef:o,id:r,onAfterResize:i,onStartResizing:s,resizedMaxWidth:l,resizedMinWidth:c,resizerWidth:u,zoomRef:d})=>{const a=rt();return a.style.right="0px",a.style.top="0px",a.style.width=nt(u),a.style.height="100%",a.style.cursor="e-resize",ot({className:t,elementNode:n,resizerNode:a,cb:f=>{const m=H(f),h=n.getBoundingClientRect(),p=e.getBoundingClientRect();let y=(p.right-h.left)/d.current;return l&&l{const z=H(g),S={x:z.clientX-m.clientX,y:z.clientY-m.clientY};let N=h.width/d.current+S.x/d.current;if(c&&Ny&&(N=y),n.style.width=`${N}px`;const b=G({elementNode:n,childNode:e,x:(h.x-p.x)/d.current,y:(h.y-p.y)/d.current,zoom:d.current});n.style.transform=O({position:b}),o.current[r].position=b})},onAfterResize:i}),n.appendChild(a),()=>{n.removeChild(a)}},pn=(e,t)=>{const{childNode:n,className:o,zoomRef:r}=$(),{elementsRef:i}=B(),s=`${o}--element-resizing`,l=W();l.current=t.onAfterResize;const c=W();c.current=t.onStartResizing,v(()=>{if(t.disabled||!t.resizable)return;const u=t.resizedMinWidth||Ot,d=t.resizerWidth||Wt,a=()=>{D.add(n,s),c.current&&c.current({id:t.id})},f=()=>{D.remove(n,s),l.current&&l.current({id:t.id})},m=hn({childNode:n,elementNode:e,elementsRef:i,...t,onAfterResize:f,onStartResizing:a,resizedMinWidth:u,resizerWidth:d,zoomRef:r}),h=fn({childNode:n,elementNode:e,elementsRef:i,...t,onAfterResize:f,onStartResizing:a,resizedMinWidth:u,resizerWidth:d,zoomRef:r});return()=>{m(),h()}},[s,t.className,t.disabled,t.resizable,t.resizedMaxWidth,t.resizedMinWidth,t.resizerWidth])},yn=e=>({id:t,className:n=At,disabled:o,disabledMove:r,draggableSelector:i,followers:s=[],x:l=0,y:c=0,family:u,height:d,onAfterResize:a,onContextMenu:f,onStartResizing:m,onClick:h,onMouseUp:p,resizable:y,resizerWidth:g,resizedMaxWidth:z,resizedMinWidth:S,width:N})=>{if(!t)throw new Error("'id' prop for element can't be undefined");const b=Je(),M=Ve(),E=mn(),[C,k]=ce(null),{elementsInMoveRef:P}=B(),w=A=>{k(A),P.current=A};pn(e,{className:n,disabled:o,id:t,onAfterResize:a,onStartResizing:m,resizable:y,resizerWidth:g,resizedMaxWidth:z,resizedMinWidth:S});const{blockMovingRef:Z,boundary:ne,childNode:I,className:ye,disabledElements:oe,elementsAutoMoveAtEdge:xt,onElementsChangeRef:vt}=$(),ge=`${ye}--element-moving`,{elementsRef:K,elementsUpdatePositionApiRef:Rt,lastElementMouseMoveEventRef:Kn}=B(),Te=W();Te.current=h;const We=W();We.current=p;const Oe=W();Oe.current=f,v(()=>(Rt.current[t]=w,()=>{e.style.transform=null,e.style.zIndex=null,delete K.current[t],delete Rt.current[t]}),[]),v(()=>{const A={x:l,y:c};e.style.transform=O({position:A}),K.current[t]={family:u,id:t,node:{current:e},position:A}},[t,l,c]),v(()=>{const A=K.current[t];A&&(A.family=u)},[u]),v(()=>{if(o||oe)return;const A=T=>i&&!T.target.closest(i),ze=T=>{if(T.button||A(T))return;const re=b(T,e),ve=De();if(Te.current&&Te.current({id:t,family:u,e:T,stop:ve,...re}),T.preventDefault(),T.stopPropagation(),ve.done||r)return;const Y=Object.values(K.current).filter(U=>U.id===t||u&&U.family===u||s.includes(U.id));w(Y.reduce((U,Re)=>(U[Re.id]=b(T,Re.node.current),U),{})),Qe(e)},xe=T=>{if(!Oe.current||A(T))return;const re=b(T,e);Oe.current({id:t,family:u,e:T,...re})},ke=ee(e,ze),Ze=Be(e,xe);return()=>{ke(),Ze()}},[o,oe,r,i,u,JSON.stringify(s),JSON.stringify(ne),t,ge]),v(()=>{if(!C)return;D.add(I,ge);let A=null;xt&&(A=E(C));let ze={};const xe=Y=>{ze=Y,vt.current&&vt.current(Y)},ke=Y=>{if(Z.current||Y.buttons===0){w(null);return}Kn.current=H(Y),Me({elementsRef:K,elementsInMove:C,produceNextPosition:(U,Re)=>M(Y,U,Re.node.current),onElementsChange:xe})},Ze=Y=>{We.current&&We.current({id:t,family:u,e:Y,...K.current[t].position}),w(null),D.remove(I,ge)},T=setInterval(()=>{xe(ze)},kt),re=te(e,Ze),ve=Q(ke);return()=>{A&&A(),re(),ve(),clearInterval(T),D.remove(I,ge)}},[xt,C]),v(()=>V(e,qt),[]),v(()=>J(e,`${n} ${n}--id-${t}`),[n,t]),v(()=>{if(o)return J(e,`${n}--disabled`)},[n,o]),v(()=>{e.style.width=N===void 0?null:`${N}px`},[N]),v(()=>{e.style.height=d===void 0?null:`${d}px`},[d])},gn=e=>{const t=[];return{add:(n,o)=>{const r=yn(n),i=e(r);return i.updateProps(o),t.push(i),i.render(),{destroy:()=>{i.unmount();const s=t.findIndex(l=>l===i);s<0||t.splice(s,1)},setOptions:s=>{i.updateProps(s),i.render()}}},queue:t,unmount:()=>{t.forEach(n=>{n.unmount()})}}},he=e=>typeof e=="number"?`${e}px`:e,it=()=>{const{containerNode:e,positionRef:t}=$();return n=>{const o=H(n),r=x(e);return{x:o.clientX-r.left-(t.current.x||0),y:o.clientY-r.top-(t.current.y||0)}}},st="select",Pe=()=>Ee(st),zn=()=>{const[e,t]=ce(null),{boundary:n,setBoundary:o,selectRef:r,expandingRef:i}=Pe(),s=W(),{childNode:l,selecting:c,zoomRef:u}=$(),d=it(),a=(f,m)=>{const h=x(l),p=d(f);p.x<0?p.x=0:p.x>h.width&&(p.x=h.width),p.y<0?p.y=0:p.y>h.height&&(p.y=h.height);const y={width:(p.x-m.x)/u.current,height:(p.y-m.y)/u.current,left:m.x/u.current,top:m.y/u.current};y.width<0&&(y.width=-y.width,y.left-=y.width),y.height<0&&(y.height=-y.height,y.top-=y.height),y.right=y.left+y.width,y.bottom=y.top+y.height,i.current.style.transform=`translate(${y.left}px, ${y.top}px)`,i.current.style.width=`${y.width}px`,i.current.style.height=`${y.height}px`,s.current=y};return v(()=>{if(e||n||!c)return;const f=m=>{m.preventDefault(),m.stopPropagation();const h=d(m);t(h),a(m,h)};return r.current.addEventListener("mousedown",f),()=>{r.current.removeEventListener("mousedown",f)}},[n,e,c]),v(()=>{if(!e||n)return;const f=p=>{a(p,e),t(null),o(s.current)},m=Q(p=>a(p,e)),h=te(F(),f);return()=>{m(),h()}},[n,e]),{expanding:e,boundary:n}},fe=e=>typeof e=="string"?parseInt(e,10):e,xn=(e,t)=>{const n={};return Object.entries(t).forEach(([o,r])=>{r.position.x>=fe(e.left)&&r.position.x<=fe(e.right)&&r.position.y>=fe(e.top)&&r.position.y<=fe(e.bottom)&&(n[o]=r)}),n},vn=e=>{const t={};return Object.entries(e).forEach(([n,o])=>{t[n]={...o.position}}),t},Rn=()=>{const{boundary:e}=Pe(),{childNode:t,onElementsChangeRef:n,zoomRef:o}=$(),{elementsRef:r}=B(),i=W();return v(()=>{if(!e)return;const s=xn(e,r.current),l=vn(s);let c=null;return i.current=u=>{c||(c=u);const d={};Object.entries(s).forEach(([a,f])=>{const m=l[a],{node:h}=f,p=G({elementNode:f.node.current,childNode:t,x:m.x+(u.x-c.x),y:m.y+(u.y-c.y),zoom:o.current});r.current[f.id].position=p,d[a]=p,h.current.style.transform=`translate(${p.x}px, ${p.y}px)`}),n.current&&n.current(d)},()=>{i.current=null}},[e]),i},bn=()=>{const e=Rn(),{boundary:t,setBoundary:n,movingRef:o,selectRef:r,move:i,setMove:s}=Pe(),l=Je(),c=Ve();v(()=>{if(!t)return;const u=m=>{m.preventDefault(),m.stopPropagation(),n(null)},d=m=>{m.preventDefault(),m.stopPropagation();const h=l(m,r.current),p={x:h.x-t.left,y:h.y-t.top};s(p)},a=ee(r.current,u),f=ee(o.current,d);return()=>{a(),f()}},[t]),v(()=>{if(!i)return;const u=m=>{m.preventDefault(),m.stopPropagation();const h=c(m,i,o.current);o.current.style.transform=`translate(${h.x}px, ${h.y}px)`,e.current(h)},d=()=>{s(null),n(null)},a=Q(u),f=te(F(),d);return()=>{a(),f()}},[t,i])},Nn=()=>{const{childNode:e,selecting:t}=$(),n=W(),o=W(),r=W(),[i,s]=ce(null),[l,c]=ce(null);Ne(st,{boundary:i,setBoundary:s,expandingRef:n,movingRef:o,selectRef:r,move:l,setMove:c}),v(()=>{r.current=document.createElement("div"),V(r.current,Qt),n.current=document.createElement("div"),V(n.current,Ue),o.current=document.createElement("div")},[]);const{expanding:u}=zn();v(()=>{if(t)return e.appendChild(r.current),()=>{e.removeChild(r.current)}},[t]),v(()=>{if(!i)return;const d={...Ue,transform:`translate(${i.left}px, ${i.top}px)`,width:he(i.width),height:he(i.height)},a=V(o.current,d);return r.current.appendChild(o.current),()=>{a(),r.current.removeChild(o.current)}},[i]),v(()=>{if(u&&!i)return r.current.appendChild(n.current),()=>{r.current.removeChild(n.current)}},[u&&!i]),bn()},En=({elementsRef:e})=>()=>e.current,ct=({id:e,elementsRef:t,position:n})=>{const o=t.current[e];o&&(o.node.current.style.transform=O({position:n}),o.position=n)},Mn=({elementsRef:e,onElementsChangeRef:t})=>(n,o)=>{ct({id:n,elementsRef:e,position:o}),t.current&&t.current({[n]:o})},Cn=({elementsRef:e})=>(t,n)=>{ct({id:t,elementsRef:e,position:n})},wn=({elementsRef:e,elementsUpdatePositionApiRef:t})=>(n,o)=>{if(!e.current[n])return null;const r=t.current[n];return r?(r({[n]:o||{x:0,y:0}}),()=>{const i=t.current[n];i&&i(null)}):null},Ie=e=>({...e.current}),Sn=({childNode:e,positionRef:t,zoomRef:n})=>(o,r)=>{const i=t;return i.current?i.current={x:t.current.x+o,y:t.current.y+r}:i.current={x:o,y:r},e.style.transform=O({position:t.current,zoom:n.current}),Ie(t)},Pn=["containerWidth","containerHeight","childWidth","childHeight"],In=(e,t={})=>{if(typeof e=="number"||!Number.isNaN(parseInt(e,10)))return e;const n=[],o=[];let r="";const i=l=>l.endsWith("px")?parseInt(l.replace("px",""),10):parseInt(l,10),s=()=>{Pn.includes(r)?n.push(t[r]):n.push(i(r)),r=""};for(let l=0;l{const r=Math.max(o.height-n.height,0);if(e.top===void 0&&e.bottom===void 0)return t;if(e.top!==void 0&&e.bottom===void 0)return Math.max(t,e.top-r);if(e.top===void 0&&e.bottom!==void 0)return Math.min(t,e.bottom-o.height+r);const i=e.top-r;if(ts?s:t},An=({boundary:e,x:t,parentSize:n,childSize:o})=>{const r=Math.max(o.width-n.width,0);if(e.left===void 0&&e.right===void 0)return t;if(e.left!==void 0&&e.right===void 0)return Math.max(t,e.left-r);if(e.left===void 0&&e.right!==void 0)return Math.min(t,e.right-o.width+r);const i=e.left-r;if(ts?s:t},Tn=({boundary:e,parentSize:t,childSize:n})=>{if(!e)return{top:void 0,right:void 0,bottom:void 0,left:void 0};const o={containerWidth:t.width,containerHeight:t.height,childWidth:n.width,childHeight:n.height},r={top:0,left:0,right:"containerWidth",bottom:"containerHeight"};return["top","left","right","bottom"].reduce((i,s)=>{const l=e===!0?void 0:e[s],c=In(l===void 0?r[s]:l,o);return{...i,[s]:c}},{})},pe=({boundary:e,x:t,y:n,parentSize:o,childSize:r})=>{const i=Tn({boundary:e,parentSize:o,childSize:r}),s={};return s.x=An({boundary:i,x:t,parentSize:o,childSize:r}),s.y=$n({boundary:i,y:n,parentSize:o,childSize:r}),s},lt=({positionRef:e})=>()=>Ie(e),ut=({boundary:e,childNode:t,containerNode:n,positionRef:o,zoomRef:r})=>(i,s)=>{const l=x(n),c=pe({boundary:e,x:i,y:s,parentSize:l,childSize:x(t)}),u=o;u.current=c,t.style.transform=O({position:o.current,zoom:r.current})},Wn=({childNode:e,positionRef:t,zoomRef:n})=>()=>{const o=n,r=t;o.current=1,r.current={x:0,y:0},e.style.transform=O({position:t.current,zoom:n.current})},dt=e=>Math.round(e*Xe)/Xe,$e=({zoomRef:e})=>()=>e.current,Ae=({childNode:e,positionRef:t,zoomMax:n,zoomMin:o,zoomRef:r})=>i=>{const s=r;s.current=dt(i),s.currentn&&(s.current=n),e.style.transform=O({position:t.current,zoom:r.current}),e.style.setProperty("--zoom",r.current.toString())},On=({childNode:e,positionRef:t,zoomMax:n,zoomMin:o,zoomRef:r})=>i=>{Ae({childNode:e,positionRef:t,zoomMax:n,zoomMin:o,zoomRef:r})($e({zoomRef:r})()+i)},kn=({childNode:e,positionRef:t,zoomMax:n,zoomMin:o,zoomRef:r})=>i=>{Ae({childNode:e,positionRef:t,zoomMax:n,zoomMin:o,zoomRef:r})($e({zoomRef:r})()-i)},Zn=()=>{const{onContainerChangeRef:e,onContainerPositionChangeRef:t,onContainerZoomChangeRef:n,positionRef:o,zoomRef:r}=$(),i=({position:l,zoom:c})=>{const u={position:Ie(o),zoom:r.current};l&&e.current&&e.current(u),l&&t.current&&t.current(u),c&&n.current&&n.current(u)},s=(l,c)=>(...u)=>{const d=l(...u);return i(c),d};return{withEventAll:l=>s(l,{position:!0,zoom:!0}),withEventPosition:l=>s(l,{position:!0,zoom:!1}),withEventZoom:l=>s(l,{position:!1,zoom:!0})}},Ln=()=>{const{apiRef:e,boundary:t,childNode:n,containerNode:o,onElementsChangeRef:r,positionRef:i,zoomMax:s,zoomMin:l,zoomRef:c}=$(),{elementsRef:u,elementsInMoveRef:d,elementsUpdatePositionApiRef:a}=B(),{withEventAll:f,withEventPosition:m,withEventZoom:h}=Zn();e.current={childNode:n,move:m(Sn({childNode:n,positionRef:i,zoomRef:c})),getElements:En({elementsRef:u}),getElementsInMove:()=>d.current||{},grabElement:wn({elementsRef:u,elementsUpdatePositionApiRef:a}),goBackToBoundary:()=>{const p=lt({positionRef:i})();m(ut({boundary:t,childNode:n,containerNode:o,positionRef:i,zoomRef:c}))(p.x,p.y)},updateElementPosition:Mn({elementsRef:u,onElementsChangeRef:r}),updateElementPositionSilent:Cn({elementsRef:u,onElementsChangeRef:r}),getPosition:lt({positionRef:i}),setPosition:m(ut({boundary:t,childNode:n,containerNode:o,positionRef:i,zoomRef:c})),getZoom:$e({zoomRef:c}),setZoom:h(Ae({childNode:n,positionRef:i,zoomMax:s,zoomMin:l,zoomRef:c})),zoomIn:h(On({childNode:n,positionRef:i,zoomMax:s,zoomMin:l,zoomRef:c})),zoomOut:h(kn({childNode:n,positionRef:i,zoomMax:s,zoomMin:l,zoomRef:c})),reset:f(Wn({childNode:n,positionRef:i,zoomRef:c}))}},Yn=()=>{const{blockMovingRef:e,boundary:t,childNode:n,containerNode:o,className:r,disabled:i,disabledMove:s,onContextMenuRef:l,onContainerChangeRef:c,onContainerClickRef:u,onContainerPositionChangeRef:d,positionRef:a,zoomRef:f}=$(),m=it(),h=`${r}--grabbing`;v(()=>{let p=null,y=null,g=null;const z=()=>{document.body.style.userSelect=null,_e(document.body),D.remove(n,h),p=null},S=()=>{y&&(y(),y=null),g&&(g(),g=null)},N=()=>{z(),S()},b=P=>{if(e.current)return;if(!p||P.buttons===0){N();return}n.style.transition=null;const w=x(o),Z=H(P),ne=pe({boundary:t,x:Z.clientX-w.left-p.x,y:Z.clientY-w.top-p.y,parentSize:w,childSize:x(n)});a.current=ne,n.style.transform=O({position:a.current,zoom:f.current});const I={position:{...a.current},zoom:f.current};c.current&&c.current(I),d.current&&d.current(I)},M=P=>{if(P.button)return;const w=m(P),Z=De();u.current&&u.current({e:P,x:w.x/f.current,y:w.y/f.current,stop:Z}),!(i||s||Z.done)&&(document.body.style.userSelect="none",D.add(n,h),p=w,S(),y=te(o,N),g=Q(b))},E=P=>{if(!l.current)return;const w=m(P);l.current({e:P,x:w.x/f.current,y:w.y/f.current})},C=ee(o,M),k=Be(o,E);return()=>{z(),S(),C(),k()}},[t,i,s])},Xn=()=>{const{boundary:e,childNode:t,containerNode:n,disabledScrollHorizontal:o,disabledScrollVertical:r,onContainerChangeRef:i,onContainerPositionChangeRef:s,onElementsChangeRef:l,positionRef:c,scrollSpeed:u,zoomRef:d}=$(),{elementsRef:a,elementsInMoveRef:f}=B();v(()=>{if(o&&r)return;let m=0;const h=p=>{const y=new Date().getTime();if(y-m0,M=x(n),E=pe({boundary:e,x:b?z.x-S:z.x+S,y:b?z.y-N:z.y+N,parentSize:M,childSize:x(t)});c.current=E,t.style.transform=O({position:E,zoom:d.current});const C={position:E,zoom:d.current};i.current&&i.current(C),s.current&&s.current(C);const k={x:b?z.x-E.x:E.x-z.x,y:b?z.y-E.y:E.y-z.y},P=f.current;P&&Me({elementsRef:a,elementsInMove:P,produceNextPosition:(w,Z)=>G({elementNode:Z.node.current,childNode:t,x:Z.position.x+(b?k.x:-k.x)/g,y:Z.position.y+(b?k.y:-k.y)/g,zoom:d.current}),onElementsChange:l.current})};return n.addEventListener("wheel",h),()=>{n.removeEventListener("wheel",h)}},[JSON.stringify(e),o,r,u])},Hn=({e,isTouchEvent:t,zoomRef:n,zoomSpeed:o,zoomMin:r,zoomMax:i})=>{const s=1+o*(t?Xt:Yt);return dt((()=>{if(!e.deltaY)return n.current;if(e.deltaY<0){const c=n.current*s;return i&&c>=i?i:c}const l=n.current/s;return r&&l<=r?r:l})())},Un=e=>{const t=Math.abs(e.item(0).clientX-e.item(1).clientX),n=Math.abs(e.item(0).clientY-e.item(1).clientY);return Math.sqrt(t*t+n*n)},jn=()=>{let e=null,t={};return[n=>{for(let l=0;le?-1:1;return e=i,{deltaY:s,clientX:o,clientY:r,isTouchEvent:!0}},n=>{n&&(t={}),e=null}]},at=(e,t)=>{let n=!1,o;const r=(...i)=>{n||(e(...i),n=!0,o=setTimeout(()=>{n=!1},t))};return r.cancel=()=>{clearTimeout(o)},r},Bn=({e,parentRect:t,zoomPosition:n})=>{const o={x:e.clientX-t.left,y:e.clientY-t.top};return n&&(n.x==="center"?o.x=t.width/2:n.x!==void 0&&(o.x=n.x),n.y==="center"?o.y=t.height/2:n.y!==void 0&&(o.y=n.y)),o},Dn=()=>{const{blockMovingRef:e,boundary:t,childNode:n,containerNode:o,disabled:r,disabledZoom:i,positionRef:s,onContainerChangeRef:l,onContainerZoomChangeRef:c,zoomInitial:u,zoomMax:d,zoomMin:a,zoomPosition:f,zoomRef:m,zoomSpeed:h}=$(),p=[JSON.stringify(t),r,i,u,h,d,a,f==null?void 0:f.x,f==null?void 0:f.y];return v(()=>{if(r||i)return;const[y,g]=jn();let z=null;const S=C=>{const k=x(n),P=x(o);C.isTouchEvent&&(clearTimeout(z),z=setTimeout(()=>{e.current=!1},Ft),e.current=!0);const w=Bn({e:C,parentRect:P,zoomPosition:f}),Z=(w.x-s.current.x)/m.current,ne=(w.y-s.current.y)/m.current,I=Hn({e:C,isTouchEvent:C.isTouchEvent,zoomRef:m,zoomSpeed:h,zoomMin:a,zoomMax:d}),ye=m.current;m.current=I;const oe=pe({boundary:t,x:w.x-Z*I,y:w.y-ne*I,parentSize:P,childSize:{width:k.width*(I/ye),height:k.height*(I/ye)}});s.current=oe,n.style.transform=O({position:oe,zoom:I}),n.style.setProperty("--zoom",I.toString()),l.current&&l.current({position:{...s.current},zoom:I}),c.current&&c.current({zoom:I,position:{...s.current}})},N=at(S,Bt),b=at(S,Dt),M=C=>{C.preventDefault(),N(C)},E=C=>{je(C)&&b(y(C))};return o.addEventListener("touchmove",E),o.addEventListener("touchup",g),o.addEventListener("touchend",g),o.addEventListener("touchcancel",g),o.addEventListener("wheel",M),()=>{o.removeEventListener("touchmove",E),o.removeEventListener("touchup",g),o.removeEventListener("touchend",g),o.removeEventListener("touchcancel",g),b.cancel(),o.removeEventListener("wheel",M),N.cancel()}},p),m},Fn=()=>{const{childNode:e,className:t=$t,containerNode:n,disabledUserSelect:o,height:r,positionRef:i,selecting:s,width:l,zoomRef:c}=$();Yn(),Dn(),Ln(),Xn(),v(()=>{const u={...Vt,height:he(r),width:he(l),transform:O({position:i.current,zoom:c.current}),"--zoom":c.current.toString()};return V(e,u)},[l,r]),v(()=>{e.setAttribute("draggable","false");const u=V(n,Jt);return()=>{e.removeAttribute("draggable"),u()}},[]),v(()=>{if(s)return e.style.pointerEvents="all",()=>{e.style.pointerEvents=null}},[s]),v(()=>{if(!t)return;const u=J(e,`${t}__in`),d=J(n,t);return()=>{u(),d()}},[t]),v(()=>{if(!(!t||!s))return J(n,`${t}--selecting`)},[t,s]),v(()=>{if(!o)return;const u=J(n,`${t}--disabled-user-select`),d=V(e,_t);return()=>{u(),d()}},[t,o])};let mt=1;const ht=(e,t={})=>{const n=wt(mt),o=n(en,nn);o.context.props=tn(e,t);const r=gn(n),i=n(It),s=n(Fn),l=n(Nn),c=()=>St([o,i,s,...r.queue,l]),u=f=>{o.updateProps(f)&&c()},d=()=>{r.unmount(),i.unmount(),l.unmount(),s.unmount(),o.unmount()};c();const a=o.context.props.apiRef;return mt++,{addElement:r.add,destroy:d,setOptions:u,...a.current}},ft=R.createContext({}),pt=(e,t)=>{const n=R.useRef(!1);R.useEffect(()=>{if(!n.current){n.current=!0;return}return e()},t)},yt=({allowedProps:e,apiRef:t,children:n,props:o})=>{const r=R.useRef(),i=R.useRef(),s=R.useRef(null),[l,c]=R.useState(!1),u=e.map(f=>o[f]);pt(()=>{s.current&&s.current.setOptions(o)},u),R.useImperativeHandle(l?t:void 0,()=>s.current,[l]);const d=R.useMemo(()=>({initialized:l,panZoomRef:s}),[l]),a=R.createElement(ft.Provider,{value:d},R.createElement("div",{ref:i},R.createElement("div",{ref:r},n)));return{childRef:r,parentRef:i,panZoomRef:s,render:a,setInitialized:c}},Jn=Ce(),Vn=({apiRef:e,children:t,...n})=>{const{childRef:o,panZoomRef:r,render:i,setInitialized:s}=yt({allowedProps:Jn,apiRef:e,children:t,props:n});return R.useLayoutEffect(()=>(r.current=ht(o.current,{...n,className:n.className||"react-panzoom"}),r.current.setOptions(n),s(!0),r.current.destroy),[]),i},gt=R.forwardRef((e,t)=>R.createElement(Vn,{...e,apiRef:t}));gt.displayName="PanZoom";const _n=({children:e,className:t,disabled:n,disabledMove:o,draggableSelector:r,family:i,followers:s,height:l,id:c,onAfterResize:u,onClick:d,onContextMenu:a,onMouseUp:f,onStartResizing:m,resizable:h,resizedMaxWidth:p,resizedMinWidth:y,resizerWidth:g,width:z,x:S,y:N})=>{const b=R.useRef(),M=R.useRef(),{initialized:E,panZoomRef:C}=R.useContext(ft),k={className:t||"react-panzoom-element",id:c,disabled:n,disabledMove:o,draggableSelector:r,family:i,followers:s,height:l,onAfterResize:u,onClick:d,onContextMenu:a,onMouseUp:f,onStartResizing:m,resizable:h,resizedMaxWidth:p,resizedMinWidth:y,resizerWidth:g,width:z,x:S,y:N};return R.useLayoutEffect(()=>{if(E)return M.current=C.current.addElement(b.current,k),M.current.destroy},[E]),pt(()=>{!E||!M.current||M.current.setOptions(k)},[n,o,r,i,E,JSON.stringify(s),l,c,u,d,a,f,m,h,p,y,g,z,S,N]),R.createElement("div",{ref:b},e)},qn=["boundary"],Qn=Ce().filter(e=>!qn.includes(e)),Gn=({apiRef:e,children:t,cover:n,onCoverLoad:o,...r})=>{const{childRef:i,parentRef:s,panZoomRef:l,render:c,setInitialized:u}=yt({apiRef:e,allowedProps:Qn,children:t,props:r});return R.useLayoutEffect(()=>{u(!1);const d=new Image;d.src=n;let a=!1;const f=()=>{if(a)return;a=!0;const y=s.current.parentNode.getBoundingClientRect(),g={width:d.naturalWidth,height:d.naturalHeight},z=Math.max(y.width/g.width,y.height/g.height);i.current.style.backgroundImage=`url('${n}')`,l.current=ht(i.current,{...r,boundary:!0,className:r.className||"react-panzoom-with-cover",width:g.width,height:g.height,zoomInitial:z,zoomMin:z,zoomMax:r.zoomMax*z}),e&&"current"in e&&(e.current=l.current),u(!0),o&&o()},m=setInterval(()=>{d.naturalWidth>0&&d.naturalHeight>0&&(f(),clearInterval(m))},100),h=()=>{f(),clearInterval(m)};return d.addEventListener("load",h),()=>{clearInterval(m),d.removeEventListener("load",h),l.current&&(l.current.destroy(),l.current=null)}},[n]),c},zt=R.forwardRef((e,t)=>R.createElement(Gn,{...e,apiRef:t}));zt.displayName="PanZoomWithCover",X.Element=_n,X.PanZoomWithCover=zt,X.default=gt,Object.defineProperties(X,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});