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