@ue-too/board 0.7.1 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,9 +49,9 @@ export default class Board {
49
49
  private _touchInputTracker;
50
50
  private _canvasSizeUpdateQueue;
51
51
  private lastUpdateTime;
52
- constructor(canvas?: HTMLCanvasElement);
52
+ constructor(canvas?: HTMLCanvasElement, debug?: boolean);
53
53
  private syncViewPortDimensions;
54
- attach(canvas: HTMLCanvasElement): void;
54
+ attach(canvas: HTMLCanvasElement, debug?: boolean): void;
55
55
  /**
56
56
  * @group LifeCycle
57
57
  * @description This function is used to clean up the board. It removes all the event listeners and disconnects the resize observer and the attribute observer.
package/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{PointCal as t}from"@ue-too/math";import{TemplateStateMachine as e,TemplateState as o,NO_OP as i}from"@ue-too/being";class n{constructor(){this.observers=[]}subscribe(t,e){if(this.observers.push(t),e?.signal){if(e.signal.aborted)return this.observers=this.observers.filter(e=>e!==t),()=>{};const o=()=>{this.observers=this.observers.filter(e=>e!==t),e.signal?.removeEventListener("abort",o)};e.signal.addEventListener("abort",o)}return()=>{this.observers=this.observers.filter(e=>e!==t)}}notify(...t){this.observers.forEach(e=>queueMicrotask(()=>e(...t)))}}class a{constructor(){this.observers=[]}subscribe(t,e){if(this.observers.push(t),e?.signal){if(e.signal.aborted)return this.observers=this.observers.filter(e=>e!==t),()=>{};const o=()=>{this.observers=this.observers.filter(e=>e!==t),e.signal?.removeEventListener("abort",o)};e.signal.addEventListener("abort",o)}return()=>{this.observers=this.observers.filter(e=>e!==t)}}notify(...t){this.observers.forEach(e=>e(...t))}}class s{constructor(){this.pan=new n,this.zoom=new n,this.rotate=new n,this.all=new n}notifyPan(t,e){this.pan.notify(t,e),this.all.notify({type:"pan",diff:t.diff},e)}notifyZoom(t,e){this.zoom.notify(t,e),this.all.notify({type:"zoom",deltaZoomAmount:t.deltaZoomAmount},e)}notifyRotate(t,e){this.rotate.notify(t,e),this.all.notify({type:"rotate",deltaRotation:t.deltaRotation},e)}on(t,e,o){switch(t){case"pan":return this.pan.subscribe(e,o);case"zoom":return this.zoom.subscribe(e,o);case"rotate":return this.rotate.subscribe(e,o);case"all":return this.all.subscribe(e,o);default:throw new Error(`Invalid event name: ${t}`)}}}function r(t,e,o,i){const n=t.a,a=t.b;t.c,t.d;const s=t.e,r=t.f,h=-Math.atan2(a,n),c=Math.sqrt(n*n+a*a)/e;let l=[s,r];l=[l[0]/e,l[1]/e],l=[l[0]-o/2,l[1]-i/2];const u=Math.cos(h),d=Math.sin(h);l=[u*l[0]-d*l[1],d*l[0]+u*l[1]],l=[l[0]/c,l[1]/c];return{position:{x:-l[0],y:-l[1]},zoom:c,rotation:h}}function h(t,e,o,i,n,a){const s=c({a:i,b:0,c:0,d:i,e:0,f:0},{a:1,b:0,c:0,d:1,e:n/2,f:a/2}),r=Math.cos(-o),h=Math.sin(-o),l=c(s,{a:r,b:h,c:-h,d:r,e:0,f:0}),u=c(l,{a:e,b:0,c:0,d:e,e:0,f:0});return c(u,{a:1,b:0,c:0,d:1,e:-t.x,f:-t.y})}function c(t,e){const o=t.a,i=t.b,n=t.c,a=t.d,s=t.e,r=t.f,h=e.a,c=e.b,l=e.c,u=e.d,d=e.e,m=e.f;return{a:o*h+n*c,b:i*h+a*c,c:o*l+n*u,d:i*l+a*u,e:o*d+n*m+s,f:i*d+a*m+r}}function l(t){const{a:e,b:o,c:i,d:n,e:a,f:s}=t,r={x:a,y:s},h=e*n-o*i;if(Math.abs(h)<1e-10)throw new Error("Matrix is singular and cannot be decomposed");const c=Math.atan2(o,e),l=Math.cos(c),u=Math.sin(c),d=e*l+o*u,m=i*-u+n*l;let p=c,_=d,y=m;for(d<0&&(_=-d,p+=Math.PI),m<0&&(y=-m,p+=Math.PI);p>Math.PI;)p-=2*Math.PI;for(;p<-Math.PI;)p+=2*Math.PI;return{translation:r,rotation:p,scale:{x:_,y:y}}}function u(t,e,o){const i=Math.cos(e),n=Math.sin(e);return{a:o.x*i,b:o.x*n,c:-o.y*n,d:o.y*i,e:t.x,f:t.y}}function d(t){const{a:e,b:o,c:i,d:n,e:a,f:s}=t,r={x:a,y:s},h=e,c=i,l=o,u=n,d=h*h+l*l,m=h*c+l*u,p=m,_=c*c+u*u,y=d+_,f=y*y-4*(d*_-m*p);if(f<0)throw new Error("Invalid transformation matrix");const g=Math.sqrt(f),v=(y+g)/2,x=(y-g)/2,b=Math.sqrt(Math.max(0,v)),T={x:b,y:Math.sqrt(Math.max(0,x))};let P=0;if(b>1e-10){const t=m,e=v-d,o=x-_,i=p,n=Math.sqrt(t*t+o*o),a=Math.sqrt(e*e+i*i);if(n>1e-10&&a>1e-10){const e=t/n,i=o/n,a=(h*e+c*i)/b,s=(l*e+u*i)/b;P=Math.atan2(s,a)}}return{translation:r,rotation:P,scale:T}}function m(e,o,i,n,a,s){let r={x:i/2,y:n/2},h=t.subVector(o,r);return h=t.multiplyVectorByScalar(h,1/a),h=t.rotatePoint(h,s),t.addVector(e,h)}function p(e,o,i,n,a,s){let r={x:o/2,y:i/2},h=t.subVector(e,r);return h=t.multiplyVectorByScalar(h,1/a),h=t.rotatePoint(h,s),t.addVector(n,h)}function _(e,o,i,n){const a=t.multiplyVectorByScalar(e,1/i),s=t.rotatePoint(a,n);return t.addVector(s,o)}function y(e,o,i,n){const a=t.subVector(e,o),s=t.multiplyVectorByScalar(a,i);return t.rotatePoint(s,-n)}function f(e,o,i,n,a,s){let r={x:o/2,y:i/2},h=t.subVector(e,n);return h=t.rotatePoint(h,-s),h=t.multiplyVectorByScalar(h,a),t.addVector(r,h)}function g(t,e,o,i,n,a){const s=f(t,e,o,i,n,a);return!(s.x<0||s.x>e||s.y<0||s.y>o)}function v(e,o,i){return t.multiplyVectorByScalar(t.rotatePoint(e,i),1/o)}function x(e,o,i){return t.multiplyVectorByScalar(t.rotatePoint(e,-i),o)}function b(e,o,i,n){const a=t.multiplyVectorByScalar(o,1/i),s=t.rotatePoint(a,n);return t.subVector(e,s)}function T(t,e,o){const i=Math.cos(o),n=Math.sin(o),a=c({a:1,b:0,c:0,d:1,e:t.x,f:t.y},{a:i,b:n,c:-n,d:i,e:0,f:0});return c(a,{a:1/e,b:0,c:0,d:1/e,e:0,f:0})}function P(t,e){return{x:t.x*e.a+t.y*e.c+e.e,y:t.x*e.b+t.y*e.d+e.f}}function w(t,e){if(null==e)return!0;let o=!1,i=!1,n=!1,a=!1;return(null==e.max||null==e.max.x||t.x<=e.max.x)&&(i=!0),(null==e.min||null==e.min.x||t.x>=e.min.x)&&(o=!0),(null==e.max||null==e.max.y||t.y<=e.max.y)&&(n=!0),(null==e.min||null==e.min.y||t.y>=e.min.y)&&(a=!0),o&&i&&n&&a}function C(t){if(null==t)return!0;const e=t.min?.x,o=t.max?.x;if(null!=e&&null!=o&&e>=o)return!1;const i=t.min?.y,n=t.max?.y;return!(null!=i&&null!=n&&i>=n)}function I(t){return null!=t&&(null!=t.max&&null!=t.min&&(null!=t.max.x&&null!=t.max.y&&null!=t.min.x&&null!=t.min.y))}function B(t,e){if(w(t,e)||null==e)return t;let o={x:t.x,y:t.y},i=e.min;return null!=i&&(null!=i.x&&(o.x=Math.max(o.x,i.x)),null!=i.y&&(o.y=Math.max(o.y,i.y))),i=e.max,null!=i&&(null!=i.x&&(o.x=Math.min(o.x,i.x)),null!=i.y&&(o.y=Math.min(o.y,i.y))),o}function R(t){if(null!=t&&null!=t.min&&null!=t.max&&null!=t.min.x&&null!=t.max.x)return t.max.x-t.min.x}function S(t){const e=R(t);return null!=e?e/2:void 0}function M(t){if(null!=t&&null!=t.min&&null!=t.max&&null!=t.min.y&&null!=t.max.y)return t.max.y-t.min.y}function O(t){const e=M(t);return null!=e?e/2:void 0}function A(e,o,i,n,a,s){if(null==n)return e;let r=m(e,{x:0,y:i},o,i,a,s),h=m(e,{x:0,y:0},o,i,a,s),c=m(e,{x:o,y:i},o,i,a,s),l=m(e,{x:o,y:0},o,i,a,s),u=B(r,n),d=B(c,n),p=B(h,n),_=B(l,n),y=[t.subVector(u,r),t.subVector(d,c),t.subVector(p,h),t.subVector(_,l)],f=Math.abs(y[0].x),g=Math.abs(y[0].y),v=y[0];return y.forEach(t=>{Math.abs(t.x)>f&&(f=Math.abs(t.x),v.x=t.x),Math.abs(t.y)>g&&(g=Math.abs(t.y),v.y=t.y)}),t.addVector(e,v)}function E(t){return void 0===t||!(void 0!==t.min&&void 0!==t.max&&t.min>t.max)}function z(t,e){return V(t,e)||void 0===e||(e.max&&(t=Math.min(e.max,t)),e.min&&(t=Math.max(e.min,t))),t}function V(t,e){return void 0===e||!(t<=0||void 0!==e&&(void 0!==e.max&&e.max<t||void 0!==e.min&&e.min>t))}function k(t,e){if(U(t,e)||void 0===e)return t;t=Z(t);const o=H(e.start,t),i=H(e.end,t);if(e.ccw&&(o<0||i>0)||!e.ccw&&(o>0||i<0)){if(Math.abs(o)===Math.abs(i))return e.startAsTieBreaker?e.start:e.end;return Math.abs(o)<Math.abs(i)?e.start:e.end}return t}function U(t,e){if(void 0===e)return!0;if(Z(e.start)===Z(e.end))return!0;if(Z(e.start+.01)===Z(e.end+.01))return!0;const o=Z(t),i=H(e.start,o),n=H(e.end,o);return!(e.ccw&&(i<0||n>0)||!e.ccw&&(i>0||n<0))}function L(t,e){if(Z(e.start)===Z(e.end))return!0;if(Z(e.start+.01)===Z(e.end+.01))return!0;let o=Z(t)-Z(e.start);o<0&&(o+=2*Math.PI),!e.positiveDirection&&o>0&&(o=2*Math.PI-o);let i=Z(e.end)-Z(e.start);return i<0&&(i+=2*Math.PI),!e.positiveDirection&&i>0&&(i=2*Math.PI-i),i>=o}function Z(t){return t=((t%=2*Math.PI)+2*Math.PI)%(2*Math.PI)}function H(t,e){t=Z(t);let o=(e=Z(e))-t;return o>Math.PI&&(o=-(2*Math.PI-o)),o<-Math.PI&&(o+=2*Math.PI),o}function N(t){return t*Math.PI/180}function D(t){return 180*t/Math.PI}class W{constructor(t=1e3,e=1e3,o={x:0,y:0},i=0,n=1,a={min:{x:-1e4,y:-1e4},max:{x:1e4,y:1e4}},s={min:.1,max:10},r=void 0){this._position=o,this._zoomLevel=n,this._rotation=i,this._viewPortHeight=e,this._viewPortWidth=t,this._zoomBoundaries=s,this._rotationBoundaries=r,this._boundaries=a}get boundaries(){return this._boundaries}set boundaries(t){this._boundaries=t}get viewPortWidth(){return this._viewPortWidth}set viewPortWidth(t){this._viewPortWidth=t}get viewPortHeight(){return this._viewPortHeight}set viewPortHeight(t){this._viewPortHeight=t}get position(){return this._position}setPosition(e){if(!w(e,this._boundaries))return!1;const o=t.subVector(e,this._position);return!(t.magnitude(o)<1e-9&&t.magnitude(o)<1/this._zoomLevel)&&(this._position=e,!0)}get zoomLevel(){return this._zoomLevel}get zoomBoundaries(){return this._zoomBoundaries}set zoomBoundaries(t){if(void 0!==t&&void 0!==t.min&&void 0!==t.max&&t.min>t.max){let e=t.max;t.max=t.min,t.min=e}this._zoomBoundaries=t}setMaxZoomLevel(t){return null==this._zoomBoundaries&&(this._zoomBoundaries={min:void 0,max:void 0}),!(null!=this._zoomBoundaries.min&&this._zoomBoundaries.min>t||this._zoomLevel>t)&&(this._zoomBoundaries.max=t,!0)}setMinZoomLevel(t){return null==this._zoomBoundaries&&(this._zoomBoundaries={min:void 0,max:void 0}),!(null!=this._zoomBoundaries.max&&this._zoomBoundaries.max<t)&&(this._zoomBoundaries.min=t,this._zoomLevel<t&&(this._zoomLevel=t),!0)}setZoomLevel(t){return!!V(t,this._zoomBoundaries)&&((void 0===this._zoomBoundaries||void 0===this._zoomBoundaries.max||z(t,this._zoomBoundaries)!=this._zoomBoundaries.max||this._zoomLevel!=this._zoomBoundaries.max)&&((void 0===this._zoomBoundaries||void 0===this._zoomBoundaries.min||z(t,this._zoomBoundaries)!=this._zoomBoundaries.min||this._zoomLevel!=this._zoomBoundaries.min)&&(this._zoomLevel=t,!0)))}get rotation(){return this._rotation}get rotationBoundaries(){return this._rotationBoundaries}set rotationBoundaries(t){if(void 0!==t&&void 0!==t.start&&void 0!==t.end&&t.start>t.end){let e=t.end;t.end=t.start,t.start=e}this._rotationBoundaries=t}getTransform(t,e){if(void 0!==this.currentCachedTransform&&this.currentCachedTransform.devicePixelRatio===t&&this.currentCachedTransform.alignCoorindate===e&&this.currentCachedTransform.position.x===this._position.x&&this.currentCachedTransform.position.y===this._position.y&&this.currentCachedTransform.rotation===this._rotation&&this.currentCachedTransform.zoomLevel===this._zoomLevel&&this.currentCachedTransform.viewPortWidth===this._viewPortWidth&&this.currentCachedTransform.viewPortHeight===this._viewPortHeight)return{...this.currentCachedTransform.transform,cached:!0};const o=t*this._viewPortWidth/2,i=t*this._viewPortHeight/2,n=-this._position.x,a=e?-this._position.y:this._position.y,s=t,r=this._zoomLevel,h=e?-this._rotation:this._rotation,c=Math.sin(h),l=Math.cos(h),u=r*s*l,d=r*s*c,m=-s*r*c,p=r*s*l,_=s*r*l*n-s*r*c*a+o,y=s*r*c*n+s*r*l*a+i;return this.currentCachedTransform={transform:{a:u,b:d,c:m,d:p,e:_,f:y},position:this._position,rotation:this._rotation,zoomLevel:this._zoomLevel,alignCoorindate:e,devicePixelRatio:t,viewPortWidth:this._viewPortWidth,viewPortHeight:this._viewPortHeight},{a:u,b:d,c:m,d:p,e:_,f:y,cached:!1}}getTRS(t,e){return l(this.getTransform(t,e))}setUsingTransformationMatrix(t){const e=r(t,this._viewPortWidth,this._viewPortHeight,this._zoomLevel);this.setPosition(e.position),this.setRotation(e.rotation),this.setZoomLevel(e.zoom)}setRotation(t){return!!U(t,this._rotationBoundaries)&&(t=Z(t),(void 0===this._rotationBoundaries||void 0===this._rotationBoundaries.end||k(t,this._rotationBoundaries)!=this._rotationBoundaries.end||this._rotation!=this._rotationBoundaries.end)&&((void 0===this._rotationBoundaries||void 0===this._rotationBoundaries.start||k(t,this._rotationBoundaries)!=this._rotationBoundaries.start||this._rotation!=this._rotationBoundaries.start)&&(this._rotation=t,!0)))}getCameraOriginInWindow(t){return t}convertFromViewPort2WorldSpace(t){return _(t,this._position,this._zoomLevel,this._rotation)}convertFromWorld2ViewPort(t){return y(t,this._position,this._zoomLevel,this._rotation)}invertFromWorldSpace2ViewPort(e){let o={x:this.viewPortWidth/2,y:this._viewPortHeight/2},i=t.subVector(e,this._position);return i=t.rotatePoint(i,-this._rotation),i=t.multiplyVectorByScalar(i,this._zoomLevel),t.addVector(o,i)}setHorizontalBoundaries(t,e){if(t>e){let o=e;e=t,t=o}null==this._boundaries&&(this._boundaries={min:{x:void 0,y:void 0},max:{x:void 0,y:void 0}}),null==this._boundaries.min&&(this._boundaries.min={x:void 0,y:void 0}),null==this._boundaries.max&&(this._boundaries.max={x:void 0,y:void 0}),this._boundaries.min.x=t,this._boundaries.max.x=e}setVerticalBoundaries(t,e){if(t>e){let o=e;e=t,t=o}null==this._boundaries&&(this._boundaries={min:{x:void 0,y:void 0},max:{x:void 0,y:void 0}}),null==this._boundaries.min&&(this._boundaries.min={x:void 0,y:void 0}),null==this._boundaries.max&&(this._boundaries.max={x:void 0,y:void 0}),this._boundaries.min.y=t,this._boundaries.max.y=e}}const F=1e3,q=1e3,j={min:.1,max:10},G={min:{x:-1e4,y:-1e4},max:{x:1e4,y:1e4}},Y=void 0;class X{constructor(t=1e3,e=1e3,o={x:0,y:0},i=0,n=1,a=G,r=j,h=Y){this._baseCamera=new W(t,e,o,i,n,a,r,h),this._observer=new s}get boundaries(){return this._baseCamera.boundaries}set boundaries(t){this._baseCamera.boundaries=t}get viewPortWidth(){return this._baseCamera.viewPortWidth}set viewPortWidth(t){this._baseCamera.viewPortWidth=t}get viewPortHeight(){return this._baseCamera.viewPortHeight}set viewPortHeight(t){this._baseCamera.viewPortHeight=t}get position(){return this._baseCamera.position}setPosition(e){const o={...this._baseCamera.position};return!!this._baseCamera.setPosition(e)&&(this._observer.notifyPan({diff:t.subVector(e,o)},{position:this._baseCamera.position,rotation:this._baseCamera.rotation,zoomLevel:this._baseCamera.zoomLevel}),!0)}get zoomLevel(){return this._baseCamera.zoomLevel}get zoomBoundaries(){return this._baseCamera.zoomBoundaries}set zoomBoundaries(t){this._baseCamera.zoomBoundaries=t}setMaxZoomLevel(t){const e=this._baseCamera.zoomLevel;return!!this._baseCamera.setMaxZoomLevel(t)&&(this._observer.notifyZoom({deltaZoomAmount:t-e},{position:this._baseCamera.position,rotation:this._baseCamera.rotation,zoomLevel:this._baseCamera.zoomLevel}),!0)}setMinZoomLevel(t){return!!this._baseCamera.setMinZoomLevel(t)}setZoomLevel(t){return!!this._baseCamera.setZoomLevel(t)}get rotation(){return this._baseCamera.rotation}get rotationBoundaries(){return this._baseCamera.rotationBoundaries}set rotationBoundaries(t){this._baseCamera.rotationBoundaries=t}getTransform(t,e=!0){return this._baseCamera.getTransform(t,e)}setRotation(t){const e=this._baseCamera.rotation;return!!this._baseCamera.setRotation(t)&&(this._observer.notifyRotate({deltaRotation:t-e},{position:this._baseCamera.position,rotation:this._baseCamera.rotation,zoomLevel:this._baseCamera.zoomLevel}),!0)}getCameraOriginInWindow(t){return t}convertFromViewPort2WorldSpace(t){return _(t,this._baseCamera.position,this._baseCamera.zoomLevel,this._baseCamera.rotation)}convertFromWorld2ViewPort(t){return y(t,this._baseCamera.position,this._baseCamera.zoomLevel,this._baseCamera.rotation)}invertFromWorldSpace2ViewPort(e){let o={x:this._baseCamera.viewPortWidth/2,y:this._baseCamera.viewPortHeight/2},i=t.subVector(e,this._baseCamera.position);return i=t.rotatePoint(i,-this._baseCamera.rotation),i=t.multiplyVectorByScalar(i,this._baseCamera.zoomLevel),t.addVector(o,i)}setHorizontalBoundaries(t,e){if(t>e){let o=e;e=t,t=o}null==this._baseCamera.boundaries&&(this._baseCamera.boundaries={min:void 0,max:void 0}),null==this._baseCamera.boundaries.min&&(this._baseCamera.boundaries.min={x:void 0,y:void 0}),null==this._baseCamera.boundaries.max&&(this._baseCamera.boundaries.max={x:void 0,y:void 0}),this._baseCamera.boundaries.min.x=t,this._baseCamera.boundaries.max.x=e}setVerticalBoundaries(t,e){if(t>e){let o=e;e=t,t=o}null==this._baseCamera.boundaries&&(this._baseCamera.boundaries={min:void 0,max:void 0}),null==this._baseCamera.boundaries.min&&(this._baseCamera.boundaries.min={x:void 0,y:void 0}),null==this._baseCamera.boundaries.max&&(this._baseCamera.boundaries.max={x:void 0,y:void 0}),this._baseCamera.boundaries.min.y=t,this._baseCamera.boundaries.max.y=e}on(t,e,o){return this._observer.on(t,e,o)}getTRS(t,e){return this._baseCamera.getTRS(t,e)}}class K{constructor(t,e){this._disabled=!1,this._canvas=e,this.bindFunctions(),this._abortController=new AbortController,this._stateMachine=t,this._keyfirstPressed=new Map}get disabled(){return this._disabled}set disabled(t){this._disabled=t}get stateMachine(){return this._stateMachine}addEventListeners(t){null!=this._canvas&&(this._canvas.addEventListener("pointerdown",this.pointerDownHandler,{signal:t}),this._canvas.addEventListener("pointerup",this.pointerUpHandler,{signal:t}),this._canvas.addEventListener("pointermove",this.pointerMoveHandler,{signal:t}),this._canvas.addEventListener("wheel",this.scrollHandler,{signal:t}),window.addEventListener("keydown",this.keypressHandler,{signal:t}),window.addEventListener("keyup",this.keyupHandler,{signal:t}))}setUp(){this._abortController.signal.aborted&&(this._abortController=new AbortController),this.addEventListeners(this._abortController.signal)}tearDown(){this._abortController.abort(),this._abortController=new AbortController}bindFunctions(){this.pointerDownHandler=this.pointerDownHandler.bind(this),this.pointerUpHandler=this.pointerUpHandler.bind(this),this.pointerMoveHandler=this.pointerMoveHandler.bind(this),this.scrollHandler=this.scrollHandler.bind(this),this.keypressHandler=this.keypressHandler.bind(this),this.keyupHandler=this.keyupHandler.bind(this)}pointerDownHandler(t){this._disabled||(0!==t.button||"mouse"!==t.pointerType?1!==t.button||"mouse"!==t.pointerType||this.stateMachine.happens("middlePointerDown",{x:t.clientX,y:t.clientY}):this.stateMachine.happens("leftPointerDown",{x:t.clientX,y:t.clientY}))}pointerUpHandler(t){this._disabled||(0!==t.button||"mouse"!==t.pointerType?1!==t.button||"mouse"!==t.pointerType||this.stateMachine.happens("middlePointerUp",{x:t.clientX,y:t.clientY}):this.stateMachine.happens("leftPointerUp",{x:t.clientX,y:t.clientY}))}pointerMoveHandler(t){this._disabled||(1!==t.buttons||"mouse"!==t.pointerType?4!==t.buttons||"mouse"!==t.pointerType?this.stateMachine.happens("pointerMove",{x:t.clientX,y:t.clientY}):this.stateMachine.happens("middlePointerMove",{x:t.clientX,y:t.clientY}):this.stateMachine.happens("leftPointerMove",{x:t.clientX,y:t.clientY}))}scrollHandler(t){this._disabled||(t.preventDefault(),t.ctrlKey?this.stateMachine.happens("scrollWithCtrl",{x:t.clientX,y:t.clientY,deltaX:t.deltaX,deltaY:t.deltaY}):this.stateMachine.happens("scroll",{deltaX:t.deltaX,deltaY:t.deltaY}))}keypressHandler(t){t.target===document.body&&(this._keyfirstPressed.has(t.key)||(this._keyfirstPressed.set(t.key,!0)," "===t.key&&this.stateMachine.happens("spacebarDown")))}keyupHandler(t){this._keyfirstPressed.has(t.key)&&this._keyfirstPressed.delete(t.key)," "===t.key&&this.stateMachine.happens("spacebarUp")}attach(t){this.tearDown(),this._canvas=t,this.setUp()}}class ${constructor(t,e){this._panDisabled=!1,this._zoomDisabled=!1,this._rotateDisabled=!1,this._canvas=e,this._disabled=!1,this.touchSM=t,this._abortController=new AbortController,this.bindListeners()}get touchStateMachine(){return this.touchSM}bindListeners(){this.touchstartHandler=this.touchstartHandler.bind(this),this.touchendHandler=this.touchendHandler.bind(this),this.touchcancelHandler=this.touchcancelHandler.bind(this),this.touchmoveHandler=this.touchmoveHandler.bind(this)}enableStrategy(){this._disabled=!1}disableStrategy(){this._disabled=!0}setUp(){null!=this._canvas&&(this._abortController.signal.aborted&&(this._abortController=new AbortController),this._canvas.addEventListener("touchstart",this.touchstartHandler,{signal:this._abortController.signal}),this._canvas.addEventListener("touchend",this.touchendHandler,{signal:this._abortController.signal}),this._canvas.addEventListener("touchcancel",this.touchcancelHandler,{signal:this._abortController.signal}),this._canvas.addEventListener("touchmove",this.touchmoveHandler,{signal:this._abortController.signal}))}tearDown(){this._abortController.abort(),this._abortController=new AbortController}get disabled(){return this._disabled}get panDisabled(){return this._panDisabled}set panDisabled(t){this._panDisabled=t}get zoomDisabled(){return this._zoomDisabled}set zoomDisabled(t){this._zoomDisabled=t}get rotateDisabled(){return this._rotateDisabled}set rotateDisabled(t){this._rotateDisabled=t}touchstartHandler(t){if(this._disabled)return;const e=[];for(let o=0;o<t.changedTouches.length;o++)e.push({ident:t.changedTouches[o].identifier,x:t.changedTouches[o].clientX,y:t.changedTouches[o].clientY});this.touchSM.happens("touchstart",{points:e}),t.preventDefault()}touchcancelHandler(t){if(this._disabled)return;const e=[];for(let o=0;o<t.changedTouches.length;o++)e.push({ident:t.changedTouches[o].identifier,x:t.changedTouches[o].clientX,y:t.changedTouches[o].clientY});this.touchSM.happens("touchend",{points:e})}touchendHandler(t){if(this._disabled)return;const e=[];for(let o=0;o<t.changedTouches.length;o++)e.push({ident:t.changedTouches[o].identifier,x:t.changedTouches[o].clientX,y:t.changedTouches[o].clientY});this.touchSM.happens("touchend",{points:e})}touchmoveHandler(t){if(this._disabled)return;t.preventDefault();const e=[];for(let o=0;o<t.targetTouches.length;o++)e.push({ident:t.targetTouches[o].identifier,x:t.targetTouches[o].clientX,y:t.targetTouches[o].clientY});this.touchSM.happens("touchmove",{points:e})}attach(t){this.tearDown(),this._canvas=t,this.setUp()}}function J(t){const e=Math.cos(Math.PI/6),o=Math.cos(Math.PI/3);return{x:t.x*e-t.y*e,y:t.x*o+t.y*o+(t.z??0)}}function Q(t){if(t<=0)return 0;let e=0;if(t<1){let o=1;for(;o>t;)o/=10,e--}else{let o=1;for(;10*o<=t;)o*=10,e++}return e}function tt(...t){const e=Array.isArray(t[0])?t[0]:t;return(t,...o)=>e.reduce((t,e)=>e(t,...o),t)}class et{constructor(t){this._observers=new a,this.resizeObserver=new ResizeObserver((t=>{for(const e of t){const t=ot(e.target.getBoundingClientRect(),window.getComputedStyle(e.target));it(this.lastRect,t)&&(this.publishPositionUpdate(t),this.lastRect=t)}}).bind(this)),this.intersectionObserver=new IntersectionObserver((t=>{if(void 0!==this.lastRect)for(const e of t)if(e.isIntersecting){const t=ot(e.boundingClientRect,window.getComputedStyle(e.target));it(this.lastRect,t)&&(this.publishPositionUpdate(t),this.lastRect=t)}}).bind(this)),this.attributeCallBack=this.attributeCallBack.bind(this),this.mutationObserver=new MutationObserver(this.attributeCallBack),t&&this.attach(t)}dispose(){this.resizeObserver.disconnect(),this.intersectionObserver.disconnect(),this.mutationObserver.disconnect(),this.scrollHandler&&window.removeEventListener("scroll",this.scrollHandler),this.resizeHandler&&window.removeEventListener("resize",this.resizeHandler)}attach(t){this.dispose(),this.resizeObserver.observe(t),this.intersectionObserver.observe(t),this.mutationObserver.observe(t,{attributes:!0,attributeFilter:["width","height","style"]});const e=ot(t.getBoundingClientRect(),window.getComputedStyle(t));this.lastRect=e,this.scrollHandler=(()=>{if(void 0===this.lastRect)return;const e=ot(t.getBoundingClientRect(),window.getComputedStyle(t));it(this.lastRect,e)&&(this.publishPositionUpdate(e),this.lastRect=e)}).bind(this),this.resizeHandler=(()=>{if(void 0===this.lastRect)return;const e=ot(t.getBoundingClientRect(),window.getComputedStyle(t));it(this.lastRect,e)&&(this.publishPositionUpdate(e),this.lastRect=e)}).bind(this),window.addEventListener("scroll",this.scrollHandler,{passive:!0}),window.addEventListener("resize",this.resizeHandler,{passive:!0})}publishPositionUpdate(t){this._observers.notify(t)}onPositionUpdate(t,e){return this._observers.subscribe(t,e)}attributeCallBack(t,e){for(let e of t)if("attributes"===e.type)if("width"===e.attributeName){const t=e.target;t.style.width=t.width/window.devicePixelRatio+"px";const o=ot(e.target.getBoundingClientRect(),window.getComputedStyle(e.target));it(this.lastRect,o)&&(this.publishPositionUpdate(o),this.lastRect=o)}else if("height"===e.attributeName){const t=e.target;t.style.height=t.height/window.devicePixelRatio+"px";const o=ot(t.getBoundingClientRect(),window.getComputedStyle(e.target));it(this.lastRect,o)&&(this.publishPositionUpdate(o),this.lastRect=o)}else if("style"===e.attributeName){const t=e.target,o=parseFloat(e.target.style.width),i=parseFloat(e.target.style.height),n=o*window.devicePixelRatio,a=i*window.devicePixelRatio;n!=t.width&&(t.width=n),a!=t.height&&(t.height=a);const s=ot(e.target.getBoundingClientRect(),window.getComputedStyle(e.target));it(this.lastRect,s)&&(this.publishPositionUpdate(s),this.lastRect=s)}}}function ot(t,e){const o=parseFloat(e.paddingLeft),i=parseFloat(e.paddingTop),n=parseFloat(e.paddingRight),a=parseFloat(e.paddingBottom),s=parseFloat(e.borderLeftWidth),r=parseFloat(e.borderTopWidth),h=parseFloat(e.borderRightWidth),c=parseFloat(e.borderBottomWidth),l=t.left+o+s,u=t.top+i+r,d=t.width-o-n-s-h,m=t.height-i-a-r-c;return new DOMRect(l,u,d,m)}function it(t,e){return void 0===t||(t.top!==e.top||t.left!==e.left||t.width!==e.width||t.height!==e.height)}const nt={fillRect:[1],strokeRect:[1],fillText:[2],strokeText:[1],lineTo:[1],moveTo:[1],quadraticCurveTo:[1,3],bezierCurveTo:[1,3,5],arc:[1],drawImage:[2],rect:[1],roundRect:[1]};function at(t){return new Proxy(t,{get(t,e,o){const i=Reflect.get(t,e,t);return"string"==typeof e&&e in nt&&"function"==typeof i?function(...o){const n=[...o];if("drawImage"===e&&9===o.length){const e=st(o);return i.apply(t,e)}{const t=nt[e];for(const e of t)e<n.length&&(n[e]=-n[e]);"drawImage"===e&&5===o.length&&(n[2]-=n[4])}return i.apply(t,n)}:"function"==typeof i?function(...e){return i.apply(t,e)}:i},set:(t,e,o)=>Reflect.set(t,e,o)})}function st(t){if(9!==t.length)return t;const e=[...t],o=t[0].height;return void 0!==o&&(e[2]=o-e[2],e[6]=-e[6],e[6]-=e[8],e[4]=-e[4]),e}function rt(t,e,o,i,n,a="red"){let s=n/2;s/=o,t.beginPath(),t.strokeStyle=a,t.lineWidth=2/o,i?(t.moveTo(e.x-s,e.y),t.lineTo(e.x+s,e.y),t.moveTo(e.x,e.y-s),t.lineTo(e.x,e.y+s)):(t.moveTo(e.x-s,-e.y),t.lineTo(e.x+s,-e.y),t.moveTo(e.x,-e.y-s),t.lineTo(e.x,-e.y+s)),t.stroke(),t.lineWidth=3}function ht(t,e,o){if(!I(e))return;const i=R(e),n=M(e),a=null==e?void 0:e.min,s=null==a?void 0:a.x,r=null==a?void 0:a.y;null!=s&&null!=r&&null!=i&&null!=n&&(t.beginPath(),t.strokeStyle="blue",t.lineWidth=100,o?t.roundRect(s,r,i,n,5):t.roundRect(s,-r,i,-n,5),t.stroke(),t.lineWidth=3,t.strokeStyle="black")}function ct(t,e,o,i){if(!I(e))return;const n=R(e),a=M(e),s=null==e?void 0:e.min,r=null==s?void 0:s.x,h=null==s?void 0:s.y;null!=r&&null!=h&&null!=n&&null!=a&&(t.lineWidth=1/o,t.beginPath(),t.strokeStyle="rgba(87, 173, 72, 0.8)",t.moveTo(0,0),i?t.lineTo(0,h+a):t.lineTo(0,-h-a),t.stroke(),t.beginPath(),t.strokeStyle="rgba(220, 59, 59, 0.8)",t.moveTo(0,0),t.lineTo(r+n,0),t.stroke(),t.strokeStyle="black")}function lt(e,o,i,n,a,s,r){let h=t.unitVectorFromA2B(o,i),c=t.unitVectorFromA2B(n,o),l=t.distanceBetweenPoints(o,i);t.distanceBetweenPoints(o,n);let u=Q(l),d=Math.pow(10,u)/10,m=Math.ceil(o.x/d)*d,p=Math.floor(i.x/d)*d,_=s?Math.floor(o.y/d)*d:Math.ceil(n.y/d)*d,y=s?Math.ceil(n.y/d)*d:Math.floor(o.y/d)*d;for(let i=m;i<=p;i+=d){const a=t.addVector({x:i,y:o.y},t.multiplyVectorByScalar(h,d)),s=t.addVector({x:i,y:n.y},t.multiplyVectorByScalar(h,d));e.beginPath(),e.strokeStyle="black",e.fillStyle="black",e.lineWidth=.5/r,e.moveTo(a.x,a.y),e.lineTo(s.x,s.y),e.stroke()}for(let n=_;n<=y;n+=d){const a=t.addVector({x:o.x,y:n},t.multiplyVectorByScalar(c,d)),s=t.addVector({x:i.x,y:n},t.multiplyVectorByScalar(c,d));e.beginPath(),e.strokeStyle="black",e.fillStyle="black",e.lineWidth=.5/r,e.moveTo(a.x,a.y),e.lineTo(s.x,s.y),e.stroke()}}function ut(e,o,i,n,a,s,r){let h=t.unitVectorFromA2B(o,i),c=t.unitVectorFromA2B(n,o),l=Q(t.distanceBetweenPoints(o,i)),u=Math.pow(10,l),d=u/2,m=u/10,p=1;l<=0&&(p=Math.pow(10,1-l));let _=Math.ceil(o.x/u)*u,y=Math.floor(i.x/u)*u,f=s?Math.ceil(o.y/u)*u:Math.floor(n.y/u)*u;s?Math.floor(n.y/u):Math.ceil(o.y/u);let g=Math.ceil(o.x/d)*d,v=Math.floor(i.x/d)*d,x=s?Math.ceil(o.y/d)*d:Math.floor(n.y/d)*d,b=s?Math.floor(n.y/d)*d:Math.ceil(o.y/d)*d,T=Math.ceil(o.x/m)*m,P=Math.floor(i.x/m)*m,w=s?Math.ceil(o.y/m)*m:Math.floor(n.y/m)*m,C=s?Math.floor(n.y/m)*m:Math.ceil(o.y/m)*m,I=d*r,B=m*r;e.font=`bold ${20/r}px Helvetica`;const R=e.measureText(""+-(d+g)),S=R.fontBoundingBoxAscent+R.fontBoundingBoxDescent,M=e.measureText(""+-(m+T)),O=M.fontBoundingBoxAscent+M.fontBoundingBoxDescent,A=Math.ceil((y-_)/u);for(let i=0;i<=A;i++){const n=_+i*u;e.beginPath(),e.strokeStyle="black",e.fillStyle="black",e.lineWidth=5/r;let a=t.addVector({x:n,y:o.y},t.multiplyVectorByScalar(c,50/r));s?e.moveTo(a.x,a.y):e.moveTo(a.x,-a.y),a=t.addVector({x:n,y:o.y},t.multiplyVectorByScalar(c,-50/r)),s?e.lineTo(a.x,a.y):e.lineTo(a.x,-a.y),e.textAlign="center",e.textBaseline="middle",e.font=`bold ${20/r}px Helvetica`;const h=e.measureText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`),l=h.fontBoundingBoxAscent+h.fontBoundingBoxDescent;s?(a=t.addVector(a,{x:0,y:l/2+.2*l}),e.fillText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`,a.x,a.y)):(a=t.addVector(a,{x:0,y:-l/2-.2*l}),e.fillText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`,a.x,-a.y)),e.stroke()}const E=Math.ceil((y-_)/u);for(let i=0;i<=E;i++){const n=f+i*u;e.beginPath(),e.strokeStyle="black",e.fillStyle="black",e.lineWidth=5/r;let a=t.addVector({x:o.x,y:n},t.multiplyVectorByScalar(h,-50/r));s?e.moveTo(a.x,a.y):e.moveTo(a.x,-a.y),a=t.addVector({x:o.x,y:n},t.multiplyVectorByScalar(h,50/r)),s?e.lineTo(a.x,a.y):e.lineTo(a.x,-a.y),e.textAlign="center",e.textBaseline="middle",e.font=`bold ${20/r}px Helvetica`;const c=e.measureText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`);a=t.addVector(a,{x:c.width/2+.3*c.width,y:0}),s?e.fillText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`,a.x,a.y):e.fillText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`,a.x,-a.y),e.stroke()}const z=Math.ceil((v-g)/d);for(let i=0;i<=z;i++){const n=g+i*d;if(Math.floor(n*p)%Math.floor(u*p)==0)continue;e.beginPath(),e.strokeStyle="black",e.fillStyle="black",e.lineWidth=3/r;let a=t.addVector({x:n,y:o.y},t.multiplyVectorByScalar(c,25/r));s?e.moveTo(a.x,a.y):e.moveTo(a.x,-a.y),a=t.addVector({x:n,y:o.y},t.multiplyVectorByScalar(c,-25/r)),s?e.lineTo(a.x,a.y):e.lineTo(a.x,-a.y),e.font=15/r+"px Helvetica";const h=e.measureText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`);if(I>2*R.width){e.textAlign="center",e.textBaseline="middle";const o=h.fontBoundingBoxAscent+h.fontBoundingBoxDescent;s?a=t.addVector(a,{x:0,y:o/2+.2*o}):(a=t.addVector(a,{x:0,y:-o/2-.2*o}),a=t.flipYAxis(a)),e.fillText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`,a.x,a.y)}e.stroke()}const V=Math.ceil((b-x)/d);for(let i=0;i<=V;i++){const n=x+i*d;if(Math.floor(n*p)%Math.floor(u*p)==0)continue;e.beginPath(),e.strokeStyle="black",e.fillStyle="black",e.lineWidth=3/r;let a=t.addVector({x:o.x,y:n},t.multiplyVectorByScalar(h,-25/r));s?e.moveTo(a.x,a.y):e.moveTo(a.x,-a.y),a=t.addVector({x:o.x,y:n},t.multiplyVectorByScalar(h,25/r)),s?e.lineTo(a.x,a.y):e.lineTo(a.x,-a.y),e.font=18/r+"px Helvetica";const c=e.measureText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`);c.fontBoundingBoxAscent,c.fontBoundingBoxDescent,I>2*S&&(e.textAlign="center",e.textBaseline="middle",a=t.addVector(a,{x:c.width/2+.3*c.width,y:0}),s||(a=t.flipYAxis(a)),e.fillText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`,a.x,a.y)),e.stroke()}const k=Math.ceil((P-T)/m);for(let i=0;i<=k;i++){const n=T+i*m;if(Math.floor(n*p)%Math.floor(u*p)==0||Math.floor(n*p)%Math.floor(d*p)==0)continue;e.beginPath(),e.strokeStyle="black",e.fillStyle="black",e.lineWidth=1/r;let a=t.addVector({x:n,y:o.y},t.multiplyVectorByScalar(c,12.5/r));s?e.moveTo(a.x,a.y):e.moveTo(a.x,-a.y),a=t.addVector({x:n,y:o.y},t.multiplyVectorByScalar(c,-12.5/r)),s?e.lineTo(a.x,a.y):e.lineTo(a.x,-a.y),e.font=10/r+"px Helvetica";const h=e.measureText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`);if(B>2*M.width){e.textAlign="center",e.textBaseline="middle";const o=h.fontBoundingBoxAscent+h.fontBoundingBoxDescent;s?a=t.addVector(a,{x:0,y:o/2+.2*o}):(a=t.addVector(a,{x:0,y:-o/2-.2*o}),a=t.flipYAxis(a)),e.fillText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`,a.x,a.y)}e.stroke()}const U=Math.ceil((C-w)/m);for(let i=0;i<=U;i++){const n=w+i*m;if(Math.floor(n*p)%Math.floor(u*p)==0||Math.floor(n*p)%Math.floor(d*p)==0)continue;e.beginPath(),e.strokeStyle="black",e.fillStyle="black",e.lineWidth=1/r;let a=t.addVector({x:o.x,y:n},t.multiplyVectorByScalar(h,-12.5/r));s?e.moveTo(a.x,a.y):e.moveTo(a.x,-a.y),a=t.addVector({x:o.x,y:n},t.multiplyVectorByScalar(h,12.5/r)),s?e.lineTo(a.x,a.y):e.lineTo(a.x,-a.y),e.font=12/r+"px Helvetica";const c=e.measureText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`);c.fontBoundingBoxAscent,c.fontBoundingBoxDescent,B>2*O&&(e.textAlign="center",e.textBaseline="middle",a=t.addVector(a,{x:c.width/2+.3*c.width,y:0}),s||(a=t.flipYAxis(a)),e.fillText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`,a.x,a.y)),e.stroke()}}function dt(t,e,o,i,n=20,a="red"){n/=o,t.font=20/o+"px Arial",t.fillStyle=a,i?t.fillText(`x: ${e.x.toFixed(2)}, y: ${e.y.toFixed(2)}`,e.x+n,e.y+n):t.fillText(`x: ${e.x.toFixed(2)}, y: ${e.y.toFixed(2)}`,e.x+n,-e.y-n),t.fillStyle="black"}function mt(t,e,o){t.beginPath(),t.strokeStyle="rgba(87, 173, 72, 0.8)",o?t.arc(e.x,e.y,5,0,2*Math.PI):t.arc(e.x,-e.y,5,0,2*Math.PI),t.stroke(),t.strokeStyle="black"}function pt(e,o,i,n,a=1,s=.3){const r=t.distanceBetweenPoints(i,n),h=10<r*o*.5?10/o:.5*r,c=r-h,l=t.linearInterpolation(i,n,c/r);e.beginPath(),e.lineWidth=a/o,e.moveTo(i.x,i.y),e.lineTo(l.x,l.y),e.stroke();const u=t.rotatePoint(t.unitVectorFromA2B(n,i),Math.PI/2),d=t.addVector(l,t.multiplyVectorByScalar(u,.5*h)),m=t.subVector(l,t.multiplyVectorByScalar(u,.5*h));e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(d.x,d.y),e.lineTo(m.x,m.y),e.closePath(),e.fill()}const _t=30,yt=9,ft=15,gt=10,vt=2.5,xt=20,bt=10;function Tt(t,e,o,i,n,a){const{minMajorTickValue:s,maxMajorTickValue:r,majorTickStep:h,minMinTickValue:c,maxMaxTickValue:l,minTickStep:u,minHalfTickValue:d,maxHalfTickValue:m,halfTickStep:p,calibrationMultiplier:_,normalizedOrderOfMagnitude:y}=Ct(e.x,o.x);t.save(),t.strokeStyle="red";for(let o=s;o<=r;o+=h){wt(t,a,{x:o*_,y:e.y},n?_t/a:-30/a,o*_,{textOffset:n?10/a:-10/a,fontSize:20})}for(let o=c;o<=l;o+=u){if(o%h===0)continue;if(o%p===0)continue;wt(t,a,{x:o*_,y:e.y},n?9/a:-9/a,o)}for(let o=d;o<=m;o+=p){if(o%h===0)continue;wt(t,a,{x:o*_,y:e.y},n?15/a:-15/a,o*_,{textOffset:n?vt/a:-2.5/a,fontSize:10,color:"red"})}t.restore();const{minMajorTickValue:f,maxMajorTickValue:g,majorTickStep:v,minMinTickValue:x,maxMaxTickValue:b,minTickStep:T,minHalfTickValue:P,maxHalfTickValue:w,halfTickStep:C,calibrationMultiplier:I}=Ct(e.y,i.y,y);t.save(),t.strokeStyle="green";for(let o=f;o<=g;o+=v){Pt(t,a,{x:e.x,y:o*I},_t/a,o,{textOffset:10/a,fontSize:20})}for(let o=P;o<=w;o+=C){if(o%v===0)continue;Pt(t,a,{x:e.x,y:o*I},15/a,o,{textOffset:vt/a,fontSize:10})}for(let o=x;o<=b;o+=T){if(o%v===0)continue;Pt(t,a,{x:e.x,y:o*I},9/a,o)}t.restore()}function Pt(t,e,o,i,n,a){const s=void 0!==a;if(t.save(),t.lineWidth=1/e,t.beginPath(),t.moveTo(o.x,o.y),t.lineTo(o.x+i,o.y),t.stroke(),t.restore(),!s)return;const r=a.color??"green";t.save(),t.textAlign="left",t.textBaseline="middle",t.fillStyle=r,t.font=a.fontSize/e+"px Arial";const h=n%1==0?n:n.toFixed(2);t.fillText(`${h}`,o.x+i+a.textOffset,o.y),t.restore()}function wt(t,e,o,i,n,a){const s=void 0!==a;if(t.save(),t.lineWidth=1/e,t.beginPath(),t.moveTo(o.x,o.y),t.lineTo(o.x,o.y+i),t.stroke(),t.restore(),!s)return;const r=a.color??"red";t.save(),t.textAlign="center",t.textBaseline="top",t.fillStyle=r,t.font=a.fontSize/e+"px Arial";const h=n%1==0?n:n.toFixed(2);t.fillText(`${h}`,o.x,o.y+i+a.textOffset),t.restore()}function Ct(t,e,o){const i=Math.min(t,e),n=Math.max(t,e),a=o||Q(n-i),s=Math.max(1,a),r=Math.pow(10,s-a),h=(t>0?Math.floor(i*r/Math.pow(10,s)):Math.ceil(i*r/Math.pow(10,s)))*Math.pow(10,s),c=(e>0?Math.floor(n*r/Math.pow(10,s)):Math.ceil(n*r/Math.pow(10,s)))*Math.pow(10,s),l=Math.pow(10,s),u=s-1,d=l/2;return{minMajorTickValue:h,maxMajorTickValue:c,majorTickStep:l,minMinTickValue:(t>0?Math.floor(i*r/Math.pow(10,u)):Math.ceil(i*r/Math.pow(10,u)))*Math.pow(10,u),maxMaxTickValue:(e>0?Math.floor(n*r/Math.pow(10,u)):Math.ceil(n*r/Math.pow(10,u)))*Math.pow(10,u),minTickStep:Math.pow(10,u),minHalfTickValue:(t>0?Math.floor(i*r/d):Math.ceil(i*r/d))*d,maxHalfTickValue:(e>0?Math.floor(n*r/d):Math.ceil(n*r/d))*d,halfTickStep:d,calibrationMultiplier:1/r,normalizedOrderOfMagnitude:s}}function It(t,e,o,i){const n=R(t),a=M(t);if(null==n||null==a)return;let s=e/Math.abs(n*Math.cos(i)),r=e/Math.abs(a*Math.cos(i)),h=o/Math.abs(n*Math.sin(i)),c=o/Math.abs(a*Math.sin(i));s==1/0&&(s=0),r==1/0&&(r=0),h==1/0&&(h=0),c==1/0&&(c=0);const l=o/a,u=e/n;return Math.max(l,u,s,r,h,c)}function Bt(t,e){return null!=e&&(null==t||e!=1/0&&(void 0!==t&&(null==t.min||e>t.min)))}function Rt(t,e,o,i){const n=R(t);if(null==n)return;const a=Math.abs(n*Math.cos(i)),s=Math.abs(n*Math.sin(i));if(e/a==1/0)return o/s;return Math.max(e/a,o/s)}function St(t,e,o,i){const n=M(t);if(null==n)return;const a=e/Math.abs(n*Math.cos(i)),s=o/Math.abs(n*Math.sin(i));if(s==1/0)return a;return Math.max(a,s)}function Mt(t,e,o){return o.clampZoom?z(t,e.zoomBoundaries):t}function Ot(t,e,o){if(!o.clampZoom)return t;let i=e.zoomLevel+t;return i=z(i,e.zoomBoundaries),t=i-e.zoomLevel}function At(t,e,o){return o.restrictZoom?e.zoomLevel:t}function Et(t,e,o){return o.restrictZoom?0:t}function zt(){return tt(Mt,At)}function Vt(){return tt(Ot,Et)}function kt(){return tt(Lt,Ht)}function Ut(){return tt(Zt,Nt)}function Lt(e,o,i){let n=t.subVector(e,o.position);if(n=Dt(n,o,i),0===n.x&&0===n.y)return e;return t.addVector(o.position,n)}function Zt(t,e,o){return t=Dt(t,e,o)}function Ht(t,e,o){if(!o.clampTranslation)return t;let i=B(t,e.boundaries);return o.limitEntireViewPort&&(i=A(t,e.viewPortWidth,e.viewPortHeight,e.boundaries,e.zoomLevel,e.rotation)),i}function Nt(e,o,i){if(!i.clampTranslation)return e;let n=t.subVector(B(t.addVector(o.position,e),o.boundaries),o.position);return i.limitEntireViewPort&&(n=t.subVector(A(t.addVector(o.position,e),o.viewPortWidth,o.viewPortHeight,o.boundaries,o.zoomLevel,o.rotation),o.position)),n}function Dt(e,o,i){if(i.restrictXTranslation&&i.restrictYTranslation)return{x:0,y:0};if(i.restrictRelativeXTranslation&&i.restrictRelativeYTranslation)return{x:0,y:0};if(i.restrictXTranslation&&(e.x=0),i.restrictYTranslation&&(e.y=0),i.restrictRelativeXTranslation){const i=t.rotatePoint({x:0,y:1},o.rotation),n=t.dotProduct(i,e);e=t.multiplyVectorByScalar(i,n)}if(i.restrictRelativeYTranslation){const i=t.rotatePoint({x:1,y:0},o.rotation),n=t.dotProduct(i,e);e=t.multiplyVectorByScalar(i,n)}return e}function Wt(e,o){return t.multiplyVectorByScalar(t.rotatePoint(e,o.rotation),1/o.zoomLevel)}function Ft(t,e,o){if(!o.clampRotation)return t;const i=k(Z(e.rotation+t),e.rotationBoundaries);return H(e.rotation,i)}function qt(t,e,o){return o.restrictRotation?0:t}function jt(t,e,o){if(!o.clampRotation)return t;return k(t,e.rotationBoundaries)}function Gt(t,e,o){return o.restrictRotation?e.rotation:t}function Yt(){return tt(qt,Ft)}function Xt(){return tt(Gt,jt)}class Kt{constructor(){this.nextPosition=null,this.delta={x:0,y:0},this.queuePositionUpdateCount=0,this.queuePositionUpdateToCount=0,this.queuePositionUpdateByCount=0,this.lastUpdateCount=0,this.observable=new n}queuePositionUpdate(t,e){this.queuePositionUpdateCount++,this.queuePositionUpdateTo({x:t,y:e})}queuePositionUpdateTo(t){this.queuePositionUpdateToCount++,this.nextPosition={...t},this.delta={x:0,y:0}}queuePositionUpdateBy(t){this.queuePositionUpdateByCount++,null===this.nextPosition?this.delta={x:this.delta.x+t.x,y:this.delta.y+t.y}:this.nextPosition={x:this.nextPosition.x+t.x,y:this.nextPosition.y+t.y}}processQueuedUpdates(){if(this.lastUpdateCount=this.queuePositionUpdateCount+this.queuePositionUpdateToCount+this.queuePositionUpdateByCount,this.queuePositionUpdateCount=0,this.queuePositionUpdateToCount=0,this.queuePositionUpdateByCount=0,null!==this.nextPosition){const t={...this.nextPosition,type:"destination"};return this.nextPosition=null,this.delta={x:0,y:0},this.observable.notify(t),t}if(0!==this.delta.x||0!==this.delta.y){const t={...this.delta,type:"delta"};return this.delta={x:0,y:0},this.observable.notify(t),t}return null}subscribe(t,e){return this.observable.subscribe(t,e)}getDebugInfo(){return{lastUpdateTotalCalls:this.lastUpdateCount,queuePositionUpdateCalls:this.queuePositionUpdateCount,queuePositionUpdateToCalls:this.queuePositionUpdateToCount,queuePositionUpdateByCalls:this.queuePositionUpdateByCount}}}class $t{constructor(){this.nextRotation=null,this.delta=0,this.queueRotationUpdateCount=0,this.queueRotationUpdateToCount=0,this.queueRotationUpdateByCount=0,this.lastUpdateCount=0,this.observable=new n}queueRotationUpdate(t){this.queueRotationUpdateCount++,this.queueRotationUpdateTo(t)}queueRotationUpdateTo(t){this.queueRotationUpdateToCount++,this.nextRotation=t,this.delta=0}queueRotationUpdateBy(t){this.queueRotationUpdateByCount++,null===this.nextRotation?this.delta=this.delta+t:this.nextRotation=this.nextRotation+t}processQueuedUpdates(){if(this.lastUpdateCount=this.queueRotationUpdateCount+this.queueRotationUpdateToCount+this.queueRotationUpdateByCount,this.queueRotationUpdateCount=0,this.queueRotationUpdateToCount=0,this.queueRotationUpdateByCount=0,null!==this.nextRotation){const t={destination:this.nextRotation,type:"destination"};return this.nextRotation=null,this.delta=0,this.observable.notify(t),t}if(0!==this.delta){const t={delta:this.delta,type:"delta"};return this.delta=0,this.observable.notify(t),t}return null}subscribe(t,e){return this.observable.subscribe(t,e)}getDebugInfo(){return{lastUpdateTotalCalls:this.lastUpdateCount,queueRotationUpdateCalls:this.queueRotationUpdateCount,queueRotationUpdateToCalls:this.queueRotationUpdateToCount,queueRotationUpdateByCalls:this.queueRotationUpdateByCount}}}class Jt{constructor(){this.nextZoom=null,this.anchor=null,this.delta=0,this.anchorCoordinateSystem="viewport",this.queueZoomUpdateCount=0,this.queueZoomUpdateToCount=0,this.lastUpdateCount=0,this.observable=new n}queueZoomUpdateTo(t,e){"world"===this.anchorCoordinateSystem&&(this.anchorCoordinateSystem="viewport",this.nextZoom=null,this.delta=0),this.anchor=e??null,this.nextZoom=t,0!==this.delta&&(this.delta=0)}queueZoomUpdateBy(t,e){"world"===this.anchorCoordinateSystem&&(this.anchorCoordinateSystem="viewport",this.nextZoom=null,this.delta=0),null===this.nextZoom?this.delta+=t:this.nextZoom+=t,this.anchor=e??null}queueZoomByAtWorld(t,e){"viewport"===this.anchorCoordinateSystem&&(this.anchorCoordinateSystem="world",this.nextZoom=null,this.delta=0),this.anchor=e,null===this.nextZoom?this.delta+=t:this.nextZoom+=t}queueZoomToAtWorld(t,e){"viewport"===this.anchorCoordinateSystem&&(this.anchorCoordinateSystem="world",this.nextZoom=null,this.delta=0),this.anchor=e,this.nextZoom=t,0!==this.delta&&(this.delta=0)}processQueuedUpdates(){if(null===this.nextZoom&&0===this.delta)return null;const t=this.delta,e=this.nextZoom,o=this.anchor;return this.delta=0,this.nextZoom=null,this.anchor=null,0!==t?{anchorCoordinateSystem:this.anchorCoordinateSystem,update:{type:"delta",delta:t,anchor:o??void 0}}:{anchorCoordinateSystem:this.anchorCoordinateSystem,update:{type:"destination",destination:e??0,anchor:o??void 0}}}subscribe(t,e){return this.observable.subscribe(t,e)}getDebugInfo(){return{lastUpdateTotalCalls:this.lastUpdateCount,queueZoomUpdateCalls:this.queueZoomUpdateCount,queueZoomUpdateToCalls:this.queueZoomUpdateToCount}}}class Qt{constructor(t,e=new X){this._panBy=Ut(),this._panTo=kt(),this._zoomTo=zt(),this._zoomBy=Vt(),this._rotateBy=Yt(),this._rotateTo=Xt(),this._config={...t,restrictRotation:!1,clampRotation:!0},this._camera=e,this._positionBatcher=new Kt,this._zoomBatcher=new Jt,this._rotationBatcher=new $t}zoomToAt(t,e){this._zoomBatcher.queueZoomUpdateTo(t,e)}zoomByAt(t,e){this._zoomBatcher.queueZoomUpdateBy(t,e)}zoomTo(t){this._zoomBatcher.queueZoomUpdateTo(t)}zoomBy(t){this._zoomBatcher.queueZoomUpdateBy(t)}zoomToAtWorld(t,e){this._zoomBatcher.queueZoomToAtWorld(t,e)}zoomByAtWorld(t,e){this._zoomBatcher.queueZoomByAtWorld(t,e)}_actualPanByWorld(e){const o=this._panBy(e,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,o))}_actualPanToWorld(t){const e=this._panTo(t,this._camera,this._config);this._camera.setPosition(e)}panByWorld(t){this._positionBatcher.queuePositionUpdateBy(t)}panByViewPort(e){const o=t.multiplyVectorByScalar(t.rotatePoint(e,this._camera.rotation),1/this._camera.zoomLevel);this._positionBatcher.queuePositionUpdateBy(o)}panToWorld(t){this._positionBatcher.queuePositionUpdateTo(t)}panToViewPort(t){const e=this._camera.convertFromViewPort2WorldSpace(t);this._positionBatcher.queuePositionUpdateTo(e)}rotateBy(t){this._rotationBatcher.queueRotationUpdateBy(t)}rotateTo(t){this._rotationBatcher.queueRotationUpdateTo(t)}set limitEntireViewPort(t){this._config.limitEntireViewPort=t}get limitEntireViewPort(){return this._config.limitEntireViewPort}get camera(){return this._camera}get config(){return this._config}set config(t){this._config={...t}}updatePosition(){const t=this._positionBatcher.processQueuedUpdates();if(null!=t)switch(t.type){case"destination":this._actualPanToWorld(t);break;case"delta":this._actualPanByWorld(t);break;default:throw new Error("Invalid position update type")}}updateZoom(){const t=this._zoomBatcher.processQueuedUpdates();if(null!=t)if("world"===t.anchorCoordinateSystem)switch(t.update.type){case"destination":if(t.update.anchor)this._zoomToAtWorld(t.update.destination,t.update.anchor);else{const e=this._zoomTo(t.update.destination,this._camera,this._config);this._camera.setZoomLevel(e)}break;case"delta":if(t.update.anchor)this._zoomByAtWorld(t.update.delta,t.update.anchor);else{const e=this._zoomBy(t.update.delta,this._camera,this._config);this._camera.setZoomLevel(this._camera.zoomLevel+e)}}else switch(t.update.type){case"destination":if(t.update.anchor)this._zoomToAtViewPort(t.update.destination,t.update.anchor);else{const e=this._zoomTo(t.update.destination,this._camera,this._config);this._camera.setZoomLevel(e)}break;case"delta":if(t.update.anchor)this._zoomByAtViewPort(t.update.delta,t.update.anchor);else{const e=this._zoomBy(t.update.delta,this._camera,this._config);this._camera.setZoomLevel(this._camera.zoomLevel+e)}}}updateRotation(){const t=this._rotationBatcher.processQueuedUpdates();if(null!=t)switch(t.type){case"destination":const e=this._rotateTo(t.destination,this._camera,this._config);this._camera.setRotation(e);break;case"delta":const o=this._rotateBy(t.delta,this._camera,this._config);this._camera.setRotation(this._camera.rotation+o);break;default:throw new Error("Invalid rotation update type")}}update(){this.updateZoom(),this.updatePosition(),this.updateRotation()}_zoomToAtViewPort(e,o){const i=this._camera.convertFromViewPort2WorldSpace(o),n=this._zoomTo(e,this._camera,this._config);this._camera.setZoomLevel(n);const a=this._camera.convertFromViewPort2WorldSpace(o),s=t.subVector(i,a),r=this._panBy(s,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,r))}_zoomToAtWorld(e,o){let i=this._camera.convertFromWorld2ViewPort(o);const n=this._zoomTo(e,this._camera,this._config);this._camera.setZoomLevel(n);let a=this._camera.convertFromWorld2ViewPort(o);const s=t.subVector(i,a),r=this._panBy(s,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,r))}_zoomByAtViewPort(e,o){const i=this._camera.convertFromViewPort2WorldSpace(o),n=this._zoomBy(e,this._camera,this._config);this._camera.setZoomLevel(this._camera.zoomLevel+n);const a=this._camera.convertFromViewPort2WorldSpace(o),s=t.subVector(i,a),r=this._panBy(s,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,r))}_zoomByAtWorld(e,o){let i=this._camera.convertFromWorld2ViewPort(o);const n=this._zoomBy(e,this._camera,this._config);this._camera.setZoomLevel(this._camera.zoomLevel+n);let a=this._camera.convertFromWorld2ViewPort(o);const s=v(t.subVector(i,a),this._camera.zoomLevel,this._camera.rotation),r=this._panBy(s,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,r))}configure(t){this._config={...this._config,...t}}cleanup(){}setup(){}}function te(t){return new Qt({limitEntireViewPort:!0,restrictRelativeXTranslation:!1,restrictRelativeYTranslation:!1,restrictXTranslation:!1,restrictYTranslation:!1,restrictZoom:!1,clampTranslation:!0,clampZoom:!0},t)}class ee{constructor(t,e=new X){this._panBy=Ut(),this._panTo=kt(),this._zoomTo=zt(),this._zoomBy=Vt(),this._rotateBy=Yt(),this._rotateTo=Xt(),this._config={...t,restrictRotation:!1,clampRotation:!0},this._camera=e}zoomToAt(e,o){let i=this._camera.convertFromViewPort2WorldSpace(o);const n=this._zoomTo(e,this._camera,this._config);this._camera.setZoomLevel(n);let a=this._camera.convertFromViewPort2WorldSpace(o);const s=t.subVector(i,a),r=this._panBy(s,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,r))}zoomByAt(e,o){let i=this._camera.convertFromViewPort2WorldSpace(o);const n=this._zoomBy(e,this._camera,this._config);this._camera.setZoomLevel(this._camera.zoomLevel+n);let a=this._camera.convertFromViewPort2WorldSpace(o);const s=t.subVector(i,a),r=this._panBy(s,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,r))}zoomTo(t){this._zoomTo(t,this._camera,this._config)}zoomBy(t){this._zoomBy(t,this._camera,this._config)}zoomToAtWorld(e,o){let i=this._camera.convertFromWorld2ViewPort(o);const n=this._zoomTo(e,this._camera,this._config);this._camera.setZoomLevel(n);let a=this._camera.convertFromWorld2ViewPort(o);const s=v(t.subVector(a,i),this._camera.zoomLevel,this._camera.rotation),r=this._panBy(s,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,r))}zoomByAtWorld(e,o){let i=this._camera.convertFromWorld2ViewPort(o);const n=this._zoomBy(e,this._camera,this._config);this._camera.setZoomLevel(this._camera.zoomLevel+n);let a=this._camera.convertFromWorld2ViewPort(o);const s=v(t.subVector(a,i),this._camera.zoomLevel,this._camera.rotation),r=this._panBy(s,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,r))}panByViewPort(e){const o=t.multiplyVectorByScalar(t.rotatePoint(e,this._camera.rotation),1/this._camera.zoomLevel);this.panByWorld(o)}panByWorld(e){const o=this._panBy(e,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,o))}panToWorld(t){const e=this._panTo(t,this._camera,this._config);this._camera.setPosition(e)}panToViewPort(t){const e=this._camera.convertFromViewPort2WorldSpace(t);this.panToWorld(e)}rotateBy(t){const e=this._rotateBy(t,this._camera,this._config);this._camera.setRotation(this._camera.rotation+e)}rotateTo(t){const e=this._rotateTo(t,this._camera,this._config);this._camera.setRotation(e)}set limitEntireViewPort(t){this._config.limitEntireViewPort=t}get limitEntireViewPort(){return this._config.limitEntireViewPort}get camera(){return this._camera}set camera(t){this._camera=t}get config(){return this._config}set config(t){this._config={...t}}configure(t){this._config={...this._config,...t}}cleanup(){}setup(){}update(){}}function oe(t){return new ee({limitEntireViewPort:!0,restrictRelativeXTranslation:!1,restrictRelativeYTranslation:!1,restrictXTranslation:!1,restrictYTranslation:!1,restrictZoom:!1,clampTranslation:!0,clampZoom:!0},t)}class ie{constructor(t=oe(new X)){this._cameraRig=t}notifyPanInput(t){this._cameraRig.panByViewPort(t)}notifyZoomInput(t,e){this._cameraRig.zoomByAt(t,e)}notifyRotationInput(t){this._cameraRig.rotateBy(t)}}function ne(t){const e=oe(t);return new ie(e)}function ae(t){return new ie(t)}class se extends e{constructor(t,e,o){super(t,e,o)}notifyPanInput(t){this.happens("userPanByInput",{diff:t})}notifyPanToAnimationInput(t){this.happens("transitionPanToInput",{target:t})}initateTransition(){this.happens("initateTransition")}set limitEntireViewPort(t){this._context.limitEntireViewPort=t}get limitEntireViewPort(){return this._context.limitEntireViewPort}}class re extends o{constructor(){super(),this.eventReactions={userPanByInput:{action:this.userPanByInputHandler,defaultTargetState:"ACCEPTING_USER_INPUT"},userPanToInput:{action:this.userPanToInputHandler,defaultTargetState:"ACCEPTING_USER_INPUT"},lockedOnObjectPanByInput:{action:this.lockedOnObjectPanByInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"},lockedOnObjectPanToInput:{action:this.lockedOnObjectPanToInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"},initateTransition:{action:i,defaultTargetState:"TRANSITION"}}}userPanByInputHandler(t,e){t.panByViewPort(e.diff)}userPanToInputHandler(t,e){t.panToWorld(e.target)}lockedOnObjectPanByInputHandler(t,e){t.panByViewPort(e.diff)}lockedOnObjectPanToInputHandler(t,e){t.panToWorld(e.target)}}class he extends o{constructor(){super(),this.eventReactions={userPanByInput:{action:this.userPanByInputHandler,defaultTargetState:"ACCEPTING_USER_INPUT"},userPanToInput:{action:this.userPanToInputHandler,defaultTargetState:"ACCEPTING_USER_INPUT"},transitionPanByInput:{action:this.transitionPanByInputHandler,defaultTargetState:"TRANSITION"},transitionPanToInput:{action:this.transitionPanToInputHandler,defaultTargetState:"TRANSITION"},lockedOnObjectPanByInput:{action:this.lockedOnObjectPanByInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"},lockedOnObjectPanToInput:{action:this.lockedOnObjectPanToInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"}}}userPanByInputHandler(t,e){return t.panByViewPort(e.diff),"ACCEPTING_USER_INPUT"}userPanToInputHandler(t,e){return t.panToWorld(e.target),"ACCEPTING_USER_INPUT"}transitionPanByInputHandler(t,e){return t.panByViewPort(e.diff),"TRANSITION"}transitionPanToInputHandler(t,e){return t.panToWorld(e.target),"TRANSITION"}lockedOnObjectPanByInputHandler(t,e){return t.panByViewPort(e.diff),"LOCKED_ON_OBJECT"}lockedOnObjectPanToInputHandler(t,e){return t.panToWorld(e.target),"LOCKED_ON_OBJECT"}}class ce extends o{constructor(){super(),this.eventReactions={unlock:{action:i,defaultTargetState:"ACCEPTING_USER_INPUT"},lockedOnObjectPanByInput:{action:this.lockedOnObjectPanByInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"},lockedOnObjectPanToInput:{action:this.lockedOnObjectPanToInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"}}}lockedOnObjectPanByInputHandler(t,e){t.panByViewPort(e.diff)}lockedOnObjectPanToInputHandler(t,e){t.panToWorld(e.target)}}function le(){return{ACCEPTING_USER_INPUT:new re,TRANSITION:new he,LOCKED_ON_OBJECT:new ce}}function ue(t){return new se(le(),"ACCEPTING_USER_INPUT",t)}class de extends o{constructor(){super(...arguments),this._eventReactions={userZoomByAtInput:{action:this.userZoomByAtInput,defaultTargetState:"ACCEPTING_USER_INPUT"},userZoomToAtInput:{action:this.userZoomToAtInput,defaultTargetState:"ACCEPTING_USER_INPUT"},initiateTransition:{action:i,defaultTargetState:"TRANSITION"}}}get eventReactions(){return this._eventReactions}userZoomByAtInput(t,e){t.zoomByAt(e.deltaZoom,e.anchorPoint)}userZoomToAtInput(t,e){t.zoomToAt(e.targetZoom,e.anchorPoint)}}class me extends o{constructor(){super(),this._eventReactions={lockedOnObjectZoomByAtInput:{action:this.lockedOnObjectZoomByAtInput,defaultTargetState:"LOCKED_ON_OBJECT"},lockedOnObjectZoomToAtInput:{action:this.lockedOnObjectZoomToAtInput,defaultTargetState:"LOCKED_ON_OBJECT"},transitionZoomByAtInput:{action:this.transitionZoomByAtInput,defaultTargetState:"TRANSITION"},transitionZoomToAtInput:{action:this.transitionZoomToAtInput,defaultTargetState:"TRANSITION"},transitionZoomToAtCenterInput:{action:this.transitionZoomToAtCenterInput,defaultTargetState:"TRANSITION"},transitionZoomToAtWorldInput:{action:this.transitionZoomToAtWorldInput,defaultTargetState:"TRANSITION"},userZoomByAtInput:{action:this.userZoomByAtInput,defaultTargetState:"ACCEPTING_USER_INPUT"},userZoomToAtInput:{action:this.userZoomToAtInput,defaultTargetState:"ACCEPTING_USER_INPUT"}}}get eventReactions(){return this._eventReactions}lockedOnObjectZoomByAtInput(t,e){t.zoomBy(e.deltaZoom)}lockedOnObjectZoomToAtInput(t,e){t.zoomTo(e.targetZoom)}userZoomByAtInput(t,e){t.zoomByAt(e.deltaZoom,e.anchorPoint)}userZoomToAtInput(t,e){t.zoomToAt(e.targetZoom,e.anchorPoint)}transitionZoomByAtInput(t,e){t.zoomByAt(e.deltaZoom,e.anchorPoint)}transitionZoomByAtCenterInput(t,e){t.zoomBy(e.deltaZoom)}transitionZoomToAtInput(t,e){t.zoomToAt(e.targetZoom,e.anchorPoint)}transitionZoomToAtCenterInput(t,e){t.zoomTo(e.targetZoom)}transitionZoomToAtWorldInput(t,e){t.zoomToAtWorld(e.targetZoom,e.anchorPoint)}}class pe extends o{constructor(){super(),this._eventReactions={lockedOnObjectZoomByAtInput:{action:this.lockedOnObjectZoomByAtInput,defaultTargetState:"LOCKED_ON_OBJECT"},lockedOnObjectZoomToAtInput:{action:this.lockedOnObjectZoomToAtInput,defaultTargetState:"LOCKED_ON_OBJECT"},userZoomByAtInput:{action:this.userZoomByAtInput,defaultTargetState:"ACCEPTING_USER_INPUT"},userZoomToAtInput:{action:this.userZoomToAtInput,defaultTargetState:"ACCEPTING_USER_INPUT"}}}get eventReactions(){return this._eventReactions}lockedOnObjectZoomByAtInput(t,e){t.zoomByAt(e.deltaZoom,e.anchorPoint)}lockedOnObjectZoomToAtInput(t,e){t.zoomToAt(e.targetZoom,e.anchorPoint)}userZoomByAtInput(t,e){t.zoomByAt(e.deltaZoom,e.anchorPoint)}userZoomToAtInput(t,e){t.zoomToAt(e.targetZoom,e.anchorPoint)}}class _e extends e{constructor(t,e,o){super(t,e,o)}notifyZoomByAtInput(t,e){this.happens("userZoomByAtInput",{deltaZoom:t,anchorPoint:e})}notifyZoomByAtInputAnimation(t,e){this.happens("transitionZoomByAtInput",{deltaZoom:t,anchorPoint:e})}notifyZoomToAtCenterInput(t,e){this.happens("transitionZoomToAtCenterInput",{targetZoom:t,anchorPoint:e})}notifyZoomToAtWorldInput(t,e){this.happens("transitionZoomToAtWorldInput",{targetZoom:t,anchorPoint:e})}initateTransition(){this.happens("initiateTransition")}}function ye(){return{ACCEPTING_USER_INPUT:new de,TRANSITION:new me,LOCKED_ON_OBJECT:new pe}}function fe(t){return new _e(ye(),"ACCEPTING_USER_INPUT",t)}class ge extends e{constructor(t,e,o){super(t,e,o)}notifyRotateByInput(t){this.happens("userRotateByInput",{diff:t})}notifyRotateToAnimationInput(t){this.happens("transitionRotateToInput",{target:t})}initateTransition(){this.happens("initateTransition")}}class ve extends o{constructor(){super(),this.eventReactions={userRotateByInput:{action:this.userRotateByInputHandler,defaultTargetState:"ACCEPTING_USER_INPUT"},userRotateToInput:{action:this.userRotateToInputHandler,defaultTargetState:"ACCEPTING_USER_INPUT"},lockedOnObjectRotateByInput:{action:this.lockedOnObjectRotateByInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"},lockedOnObjectRotateToInput:{action:this.lockedOnObjectRotateToInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"},initateTransition:{action:i,defaultTargetState:"TRANSITION"}}}userRotateByInputHandler(t,e){t.rotateBy(e.diff)}userRotateToInputHandler(t,e){t.rotateTo(e.target)}lockedOnObjectRotateByInputHandler(t,e){t.rotateBy(e.diff)}lockedOnObjectRotateToInputHandler(t,e){t.rotateTo(e.target)}}class xe extends o{constructor(){super(),this.eventReactions={userRotateByInput:{action:this.userRotateByInputHandler,defaultTargetState:"ACCEPTING_USER_INPUT"},userRotateToInput:{action:this.userRotateToInputHandler,defaultTargetState:"ACCEPTING_USER_INPUT"},transitionRotateByInput:{action:this.transitionRotateByInputHandler,defaultTargetState:"TRANSITION"},transitionRotateToInput:{action:this.transitionRotateToInputHandler,defaultTargetState:"TRANSITION"},lockedOnObjectRotateByInput:{action:this.lockedOnObjectRotateByInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"},lockedOnObjectRotateToInput:{action:this.lockedOnObjectRotateToInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"}}}userRotateByInputHandler(t,e){return t.rotateBy(e.diff),"ACCEPTING_USER_INPUT"}userRotateToInputHandler(t,e){return t.rotateTo(e.target),"ACCEPTING_USER_INPUT"}transitionRotateByInputHandler(t,e){return t.rotateBy(e.diff),"TRANSITION"}transitionRotateToInputHandler(t,e){return t.rotateTo(e.target),"TRANSITION"}lockedOnObjectRotateByInputHandler(t,e){return t.rotateBy(e.diff),"LOCKED_ON_OBJECT"}lockedOnObjectRotateToInputHandler(t,e){return t.rotateTo(e.target),"LOCKED_ON_OBJECT"}}class be extends o{constructor(){super(),this.eventReactions={unlock:{action:i,defaultTargetState:"ACCEPTING_USER_INPUT"},lockedOnObjectRotateByInput:{action:this.lockedOnObjectRotateByInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"},lockedOnObjectRotateToInput:{action:this.lockedOnObjectRotateToInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"}}}lockedOnObjectRotateByInputHandler(t,e){t.rotateBy(e.diff)}lockedOnObjectRotateToInputHandler(t,e){t.rotateTo(e.target)}}function Te(){return{ACCEPTING_USER_INPUT:new ve,TRANSITION:new xe,LOCKED_ON_OBJECT:new be}}function Pe(t){return new ge(Te(),"ACCEPTING_USER_INPUT",t)}class we{constructor(t,e,o){this._panStateMachine=t,this._zoomStateMachine=e,this._rotateStateMachine=o}notifyPanToAnimationInput(t){this._panStateMachine.notifyPanToAnimationInput(t)}notifyPanInput(t){this._panStateMachine.notifyPanInput(t)}notifyZoomInput(t,e){this._zoomStateMachine.notifyZoomByAtInput(t,e)}notifyRotateByInput(t){this._rotateStateMachine.notifyRotateByInput(t)}notifyRotateToAnimationInput(t){this._rotateStateMachine.notifyRotateToAnimationInput(t)}notifyZoomInputAnimation(t,e={x:0,y:0}){this._zoomStateMachine.notifyZoomToAtCenterInput(t,e)}notifyZoomInputAnimationWorld(t,e={x:0,y:0}){this._zoomStateMachine.notifyZoomToAtWorldInput(t,e)}notifyRotationInput(t){console.error("Rotation input is not implemented")}initatePanTransition(){this._panStateMachine.initateTransition()}initateZoomTransition(){this._zoomStateMachine.initateTransition()}initateRotateTransition(){this._rotateStateMachine.initateTransition()}get rotateStateMachine(){return this._rotateStateMachine}get panStateMachine(){return this._panStateMachine}get zoomStateMachine(){return this._zoomStateMachine}}function Ce(t){const e=oe(t),o=ue(e),i=fe(e),n=Pe(e);return new we(o,i,n)}function Ie(t){const e=ue(t),o=fe(t),i=Pe(t);return new we(e,o,i)}class Be{constructor(t){this.pan=new n,this.zoom=new n,this.rotate=new n,this.all=new n,this._cameraMux=t}notifyPan(t){this._cameraMux.notifyPanInput(t),this.pan.notify({diff:t}),this.all.notify({type:"pan",diff:t})}notifyZoom(t,e){this._cameraMux.notifyZoomInput(t,e),this.zoom.notify({deltaZoomAmount:t,anchorPoint:e}),this.all.notify({type:"zoom",deltaZoomAmount:t,anchorPoint:e})}notifyRotate(t){this._cameraMux.notifyRotationInput(t),this.rotate.notify({deltaRotation:t}),this.all.notify({type:"rotate",deltaRotation:t})}on(t,e){switch(t){case"pan":return this.pan.subscribe(e);case"zoom":return this.zoom.subscribe(e);case"rotate":return this.rotate.subscribe(e);case"all":return this.all.subscribe(e);default:throw new Error("Invalid raw user input event name")}}get cameraMux(){return this._cameraMux}set cameraMux(t){this._cameraMux=t}}function Re(t){return new Be(ne(t))}class Se{constructor(t){this.pan=new n,this.zoom=new n,this.rotate=new n,this.all=new n,this.webWorker=t}notifyPan(t){this.webWorker.postMessage({type:"notifyUserInput",payload:{type:"pan",diff:t}}),this.pan.notify({diff:t}),this.all.notify({type:"pan",diff:t})}notifyZoom(t,e){this.webWorker.postMessage({type:"notifyUserInput",payload:{type:"zoom",deltaZoomAmount:t,anchorPoint:e}}),this.zoom.notify({deltaZoomAmount:t,anchorPoint:e}),this.all.notify({type:"zoom",deltaZoomAmount:t,anchorPoint:e})}notifyRotate(t){this.webWorker.postMessage({type:"notifyUserInput",payload:{type:"rotate",deltaRotation:t}}),this.rotate.notify({deltaRotation:t}),this.all.notify({type:"rotate",deltaRotation:t})}on(t,e){switch(t){case"pan":return this.pan.subscribe(e);case"zoom":return this.zoom.subscribe(e);case"rotate":return this.rotate.subscribe(e);case"all":return this.all.subscribe(e);default:throw new Error("Invalid raw user input event name")}}}var Me;!function(t){t.GRAB="grab",t.DEFAULT="default",t.GRABBING="grabbing"}(Me||(Me={}));class Oe{constructor(){this.width=0,this.height=0,this.position={x:0,y:0},this.setCursor=i,this.dimensions={width:0,height:0,position:{x:0,y:0}},this.detached=!1,this.tearDown=i}}class Ae{constructor(t){this._width=0,this._height=0,this._position={x:0,y:0},this._postMessageFunction=t}get dimensions(){return{width:this._width,height:this._height,position:this._position}}tearDown(){}set width(t){this._width=t}set height(t){this._height=t}set position(t){this._position=t}get width(){return this._width}get height(){return this._height}get position(){return this._position}setCursor(t){this._postMessageFunction({type:"setCursor",style:t})}get detached(){return!1}}class Ee{constructor(t){if(this._width=0,this._height=0,this._position={x:0,y:0},this._internalSizeUpdateObservable=new a,t){const e=ot(t.getBoundingClientRect(),window.getComputedStyle(t));this._width=e.width,this._height=e.height,this._position={x:e.left,y:e.top},this._canvas=t}this._canvasPositionDimensionPublisher=new et(t),this._canvasPositionDimensionPublisher.onPositionUpdate(t=>{null!=this._canvas?(this._width=t.width,this._height=t.height,this._position={x:t.left,y:t.top},this._internalSizeUpdateObservable.notify({width:this._width,height:this._height,position:this._position})):console.log("is not attached to any canvas should not have getting any updates")})}subscribe(t,e){return this._internalSizeUpdateObservable.subscribe(t,e)}notify(...t){this._internalSizeUpdateObservable.notify(...t)}get detached(){return void 0===this._canvas}get dimensions(){return{width:this._width,height:this._height,position:this._position}}get width(){return this._width}setWidth(t){this._canvas&&(this._canvas.width=t*window.devicePixelRatio,this._canvas.style.width=t+"px")}setHeight(t){this._canvas&&(this._canvas.height=t*window.devicePixelRatio,this._canvas.style.height=t+"px")}get height(){return this._height}get position(){return this._position}setCursor(t){this._canvas&&(this._canvas.style.cursor=t)}tearDown(){this._canvasPositionDimensionPublisher.dispose()}attach(t){this._canvasPositionDimensionPublisher.attach(t),this._canvas=t;const e=ot(t.getBoundingClientRect(),window.getComputedStyle(t));this._canvas.width=e.width*window.devicePixelRatio,this._canvas.height=e.height*window.devicePixelRatio,this._canvas.style.width=e.width+"px",this._canvas.style.height=e.height+"px",this._width=e.width,this._height=e.height,this._position={x:e.left,y:e.top},this._internalSizeUpdateObservable.notify({width:this._width,height:this._height,position:this._position})}logCanvasTrueSize(){void 0!==this._canvas&&(console.log("canvas true size"),console.log("style width",this._canvas.style.width),console.log("style height",this._canvas.style.height),console.log("width",this._canvas.width),console.log("height",this._canvas.height),console.log("proxy width",this._width),console.log("proxy height",this._height))}}class ze{constructor(t,e,o){const i=t.getBoundingClientRect();this._canvas=t,this._webWorker=e;const n=ot(i,window.getComputedStyle(t));this._width=n.width,this._height=n.height,this._position={x:n.left,y:n.top},this._webWorker.postMessage({type:"setCanvasDimensions",width:i.width,height:i.height,position:{x:i.left,y:i.top}}),o.onPositionUpdate(t=>{this._width=t.width,this._height=t.height,this._position={x:t.left,y:t.top},this._webWorker.postMessage({type:"updateCanvasDimensions",width:t.width,height:t.height,position:{x:t.left,y:t.top}})}),this._canvasDiemsionPublisher=o}get width(){return this._width}get height(){return this._height}tearDown(){this._canvasDiemsionPublisher.dispose()}get position(){return this._position}get dimensions(){return{width:this._width,height:this._height,position:this._position}}get detached(){return!1}setCursor(t){this._canvas.style.cursor=t}}class Ve{constructor(){this.alignCoordinateSystem=!1,this.canvas=new Oe,this.initialCursorPosition={x:0,y:0},this.toggleOnEdgeAutoCameraInput=i,this.toggleOffEdgeAutoCameraInput=i,this.setCursorPosition=i}notifyOnPan(t){}notifyOnZoom(t,e){}notifyOnRotate(t){}setInitialCursorPosition(t){}cleanup(){}setup(){}cancelCurrentAction(){}}class ke{constructor(t,e,o){this._padding=50,this._alignCoordinateSystem=!0,this._canvasOperator=t,this._inputPublisher=e,this._initialCursorPosition={x:0,y:0},this._edgeAutoCameraInput=o}get alignCoordinateSystem(){return this._alignCoordinateSystem}get canvas(){return this._canvasOperator}get initialCursorPosition(){return this._initialCursorPosition}set alignCoordinateSystem(t){this._alignCoordinateSystem=t}notifyOnPan(t){this._inputPublisher.notifyPan(t)}notifyOnZoom(t,e){this._inputPublisher.notifyZoom(t,e)}notifyOnRotate(t){this._inputPublisher.notifyRotate(t)}cancelCurrentAction(){this._initialCursorPosition={x:0,y:0}}setInitialCursorPosition(t){this._initialCursorPosition=t}toggleOnEdgeAutoCameraInput(){this._edgeAutoCameraInput.toggleOn()}toggleOffEdgeAutoCameraInput(){this._edgeAutoCameraInput.toggleOff()}setCursorPosition(t){if(function(t,e,o){return t.x<=e.left+o||t.x>=e.left+e.width-o||t.y<=e.top+o||t.y>=e.top+e.height-o}(t,{left:this._canvasOperator.dimensions.position.x,top:this._canvasOperator.dimensions.position.y,width:this._canvasOperator.dimensions.width,height:this._canvasOperator.dimensions.height},this._padding)){const e=function(t,e,o){if(t.x<=e.left+o)return"left";if(t.x>=e.left+e.width-o)return"right";return"none"}(t,{left:this._canvasOperator.dimensions.position.x,top:this._canvasOperator.dimensions.position.y,width:this._canvasOperator.dimensions.width,height:this._canvasOperator.dimensions.height},this._padding),o=function(t,e,o){if(t.y<=e.top+o)return"up";if(t.y>=e.top+e.height-o)return"down";return"none"}(t,{left:this._canvasOperator.dimensions.position.x,top:this._canvasOperator.dimensions.position.y,width:this._canvasOperator.dimensions.width,height:this._canvasOperator.dimensions.height},this._padding);this._edgeAutoCameraInput.setDirection(e,o)}else this._edgeAutoCameraInput.setDirection("none","none")}cleanup(){}setup(){}}class Ue{constructor(t,e){this._touchPointsMap=new Map,this._canvas=t,this._inputPublisher=e,this._alignCoordinateSystem=!0}addTouchPoints(t){t.forEach(t=>{this._touchPointsMap.set(t.ident,{...t})})}removeTouchPoints(t){t.forEach(t=>{this._touchPointsMap.has(t)&&this._touchPointsMap.delete(t)})}getCurrentTouchPointsCount(){return this._touchPointsMap.size}getInitialTouchPointsPositions(t){const e=[];return t.forEach(t=>{if(this._touchPointsMap.has(t)){const o=this._touchPointsMap.get(t);o&&e.push(o)}}),e}updateTouchPoints(t){t.forEach(t=>{this._touchPointsMap.has(t.ident)&&this._touchPointsMap.set(t.ident,{...t})})}notifyOnPan(t){this._inputPublisher.notifyPan(t)}notifyOnZoom(t,e){this._inputPublisher.notifyZoom(t,e)}get alignCoordinateSystem(){return this._alignCoordinateSystem}set alignCoordinateSystem(t){this._alignCoordinateSystem=t}get canvas(){return this._canvas}cleanup(){}setup(){}}class Le extends o{constructor(){super(...arguments),this._eventReactions={touchstart:{action:this.touchstart,defaultTargetState:"IDLE"},touchend:{action:this.touchend,defaultTargetState:"IDLE"}},this._guards={touchPointsCount:(t=>2===t.getCurrentTouchPointsCount()).bind(this)},this._eventGuards={touchstart:[{guard:"touchPointsCount",target:"PENDING"}],touchend:[{guard:"touchPointsCount",target:"PENDING"}]}}get eventReactions(){return this._eventReactions}touchstart(t,e){t.addTouchPoints(e.points)}touchend(t,e){t.removeTouchPoints(e.points.map(t=>t.ident))}}class Ze extends o{constructor(){super(...arguments),this._eventReactions={touchstart:{action:this.touchstart,defaultTargetState:"IDLE"},touchend:{action:this.touchend,defaultTargetState:"IDLE"},touchmove:{action:this.touchmove,defaultTargetState:"IN_PROGRESS"}}}get eventReactions(){return this._eventReactions}touchstart(t,e){t.addTouchPoints(e.points)}touchend(t,e){t.removeTouchPoints(e.points.map(t=>t.ident))}touchmove(e,o){const i=o.points.map(t=>t.ident),n=e.getInitialTouchPointsPositions(i),a=o.points,s=t.distanceBetweenPoints(n[0],n[1]),r=t.distanceBetweenPoints(a[0],a[1]),h=t.linearInterpolation(n[0],n[1],.5),c=t.linearInterpolation(a[0],a[1],.5),l=t.subVector(h,c),u={x:e.canvas.position.x+e.canvas.width/2,y:e.canvas.position.y+e.canvas.height/2},d=t.subVector(h,u);let m=Math.abs(r-s)>t.distanceBetweenPoints(h,c)?"ZOOMING":"PANNING";switch(e.updateTouchPoints(a),m){case"ZOOMING":e.notifyOnZoom(.005*(r-s),d);break;case"PANNING":e.notifyOnPan(l);break;default:console.warn("Unknown panZoom state",m)}}}class He extends o{constructor(){super(...arguments),this._eventReactions={touchmove:{action:this.touchmove,defaultTargetState:"IN_PROGRESS"},touchend:{action:this.touchend,defaultTargetState:"IDLE"},touchstart:{action:()=>"IDLE",defaultTargetState:"IDLE"}}}get eventReactions(){return this._eventReactions}touchmove(e,o){const i=o.points.map(t=>t.ident),n=e.getInitialTouchPointsPositions(i),a=o.points,s=t.distanceBetweenPoints(n[0],n[1]),r=t.distanceBetweenPoints(a[0],a[1]),h=t.linearInterpolation(n[0],n[1],.5),c=t.linearInterpolation(a[0],a[1],.5),l=t.subVector(h,c),u={x:e.canvas.position.x+e.canvas.width/2,y:e.canvas.position.y+e.canvas.height/2},d=t.subVector(h,u);let m=Math.abs(r-s)>t.distanceBetweenPoints(h,c)?"ZOOMING":"PANNING";switch(e.updateTouchPoints(a),m){case"ZOOMING":e.alignCoordinateSystem||(d.y=-d.y),e.notifyOnZoom(.005*-(s-r),d);break;case"PANNING":e.alignCoordinateSystem||(l.y=-l.y),e.notifyOnPan(l);break;default:console.warn("Unknown panZoom state",m)}}touchend(t,e){t.removeTouchPoints(e.points.map(t=>t.ident))}}function Ne(t){return new e({IDLE:new Le,PENDING:new Ze,IN_PROGRESS:new He},"IDLE",t)}function De(e,o){const i=o.getBoundingClientRect(),n={x:i.left+(i.right-i.left)/2,y:i.top+(i.bottom-i.top)/2};return t.subVector(e,n)}function We(e,o){const i={x:o.position.x+o.width/2,y:o.position.y+o.height/2};return t.subVector(e,i)}function Fe(e,o){const i={x:o.position.x+o.width/2,y:o.position.y+o.height/2};return t.subVector(e,i)}class qe extends o{constructor(){super(),this._guards={isIdle:()=>!0},this._eventGuards={},this._eventReactions={spacebarDown:{action:this.spacebarDownHandler,defaultTargetState:"READY_TO_PAN_VIA_SPACEBAR"},scroll:{action:this.scrollHandler,defaultTargetState:"IDLE"},scrollWithCtrl:{action:this.scrollWithCtrlHandler,defaultTargetState:"IDLE"},middlePointerDown:{action:this.middlePointerDownHandler,defaultTargetState:"READY_TO_PAN_VIA_SCROLL_WHEEL"},disable:{action:i,defaultTargetState:"DISABLED"},pointerMove:{action:this.pointerMoveHandler,defaultTargetState:"IDLE"}}}get eventReactions(){return this._eventReactions}uponEnter(t){t.canvas.setCursor(Me.DEFAULT)}scrollHandler(t,e){const o={...e};t.alignCoordinateSystem||(o.deltaY=-o.deltaY),t.notifyOnPan({x:o.deltaX,y:o.deltaY})}scrollWithCtrlHandler(t,e){let o=.005;Math.abs(e.deltaY)>100&&(o=5e-4);const i=e.deltaY*o,n=Fe({x:e.x,y:e.y},t.canvas);t.alignCoordinateSystem||(n.y=-n.y),t.notifyOnZoom(-5*i,n)}spacebarDownHandler(t,e){}middlePointerDownHandler(t,e){t.setInitialCursorPosition({x:e.x,y:e.y})}pointerMoveHandler(t,e){t.setCursorPosition(e)}}class je extends o{constructor(){super(),this.leftPointerMove=((t,e)=>{const o=De({x:e.x,y:e.y},t.canvas);t.setSelectionEndPoint(o),t.toggleSelectionBox(!0)}).bind(this),this._eventReactions={leftPointerUp:{action:()=>"IDLE",defaultTargetState:"IDLE"},leftPointerMove:{action:this.leftPointerMove,defaultTargetState:"SELECTING"},disable:{action:i,defaultTargetState:"DISABLED"}}}get eventReactions(){return this._eventReactions}}class Ge extends o{constructor(){super()}uponEnter(t){t.canvas.setCursor(Me.DEFAULT)}get eventReactions(){return{enable:{action:i,defaultTargetState:"IDLE"}}}}class Ye extends o{constructor(){super(),this._eventReactions={spacebarUp:{action:i,defaultTargetState:"IDLE"},leftPointerDown:{action:this.leftPointerDownHandler,defaultTargetState:"INITIAL_PAN"},disable:{action:t=>t.cancelCurrentAction(),defaultTargetState:"DISABLED"},leftPointerMove:{action:i,defaultTargetState:"READY_TO_PAN_VIA_SPACEBAR"}}}uponEnter(t){t.canvas.setCursor(Me.GRAB)}get eventReactions(){return this._eventReactions}leftPointerDownHandler(t,e){t.setInitialCursorPosition({x:e.x,y:e.y})}}class Xe extends o{constructor(){super(),this._eventReactions={leftPointerUp:{action:i,defaultTargetState:"READY_TO_PAN_VIA_SPACEBAR"},leftPointerMove:{action:this.leftPointerMoveHandler,defaultTargetState:"PAN"},spacebarUp:{action:()=>"IDLE",defaultTargetState:"IDLE"},leftPointerDown:{action:()=>"PAN",defaultTargetState:"PAN"}}}get eventReactions(){return this._eventReactions}uponEnter(t){t.canvas.setCursor(Me.GRABBING)}leftPointerMoveHandler(t,e){const o={x:t.initialCursorPosition.x-e.x,y:t.initialCursorPosition.y-e.y};t.alignCoordinateSystem||(o.y=-o.y),t.notifyOnPan(o),t.setInitialCursorPosition({x:e.x,y:e.y})}}class Ke extends o{constructor(){super(),this._eventReactions={middlePointerUp:{action:i,defaultTargetState:"IDLE"},middlePointerMove:{action:i,defaultTargetState:"PAN_VIA_SCROLL_WHEEL"}}}get eventReactions(){return this._eventReactions}uponEnter(t){t.canvas.setCursor(Me.GRABBING)}}class $e extends o{constructor(){super(),this._eventReactions={leftPointerUp:{action:i,defaultTargetState:"READY_TO_PAN_VIA_SPACEBAR"},leftPointerMove:{action:this.leftPointerMoveHandler,defaultTargetState:"PAN"},spacebarUp:{action:i,defaultTargetState:"IDLE"}}}get eventReactions(){return this._eventReactions}uponEnter(t){t.canvas.setCursor(Me.GRABBING)}beforeExit(t){t.canvas.setCursor(Me.DEFAULT)}leftPointerMoveHandler(t,e){const o={x:t.initialCursorPosition.x-e.x,y:t.initialCursorPosition.y-e.y};t.alignCoordinateSystem||(o.y=-o.y),t.notifyOnPan(o),t.setInitialCursorPosition({x:e.x,y:e.y})}}class Je extends o{constructor(){super(...arguments),this._eventReactions={middlePointerUp:{action:i,defaultTargetState:"IDLE"},middlePointerMove:{action:this.middlePointerMoveHandler,defaultTargetState:"PAN_VIA_SCROLL_WHEEL"}}}get eventReactions(){return this._eventReactions}middlePointerMoveHandler(t,e){const o={x:t.initialCursorPosition.x-e.x,y:t.initialCursorPosition.y-e.y};t.alignCoordinateSystem||(o.y=-o.y),t.notifyOnPan(o),t.setInitialCursorPosition({x:e.x,y:e.y})}uponEnter(t){t.canvas.setCursor(Me.GRABBING)}}class Qe extends o{constructor(){super()}get eventReactions(){return{}}}function to(t){const o={IDLE:new qe,READY_TO_PAN_VIA_SPACEBAR:new Ye,INITIAL_PAN:new Xe,PAN:new $e,READY_TO_PAN_VIA_SCROLL_WHEEL:new Ke,PAN_VIA_SCROLL_WHEEL:new Je,DISABLED:new Ge};return new e(o,"IDLE",t)}class eo extends e{constructor(t){super({IDLE:new Qe,READY_TO_PAN_VIA_SPACEBAR:new Qe,INITIAL_PAN:new Qe,PAN:new Qe,READY_TO_PAN_VIA_SCROLL_WHEEL:new Qe,PAN_VIA_SCROLL_WHEEL:new Qe,DISABLED:new Ge},"IDLE",new Ve),this._webworker=t}happens(...t){return this._webworker.postMessage({type:"kmtInputStateMachine",event:t[0],payload:t[1]}),{handled:!0,nextState:"IDLE"}}}class oo{constructor(t){this._state="idle",this._speed=100,this._horizontalDirection="none",this._verticalDirection="none",this._cameraMux=t}toggleOff(){this._state="idle"}toggleOn(){this._state="moving"}setDirection(t,e){this._horizontalDirection=t,this._verticalDirection=e}update(e){if("idle"===this._state)return;const o={x:"left"===this._horizontalDirection?-1:"right"===this._horizontalDirection?1:0,y:"up"===this._verticalDirection?-1:"down"===this._verticalDirection?1:0},i=this._speed*e,n=t.multiplyVectorByScalar(o,i);this._cameraMux.notifyPanInput(n)}}class io{constructor(t){this._alignCoordinateSystem=!0,this._fullScreen=!1,this._canvasSizeUpdateQueue=void 0,this.lastUpdateTime=0;const e=new X;e.boundaries={min:{x:-5e3,y:-5e3},max:{x:5e3,y:5e3}},this.bindFunctions(),this._canvasProxy=new Ee(t),this._canvasProxy.subscribe(t=>{this._canvasSizeUpdateQueue=t}),this.cameraRig=new ee({limitEntireViewPort:!0,restrictRelativeXTranslation:!1,restrictRelativeYTranslation:!1,restrictXTranslation:!1,restrictYTranslation:!1,restrictZoom:!1,clampTranslation:!0,clampZoom:!0},e),this.boardInputPublisher=new Be(Ie(this.cameraRig)),this._edgeAutoCameraInput=new oo(this.boardInputPublisher.cameraMux),this._observableInputTracker=new ke(this._canvasProxy,this.boardInputPublisher,this._edgeAutoCameraInput),this._touchInputTracker=new Ue(this._canvasProxy,this.boardInputPublisher);const o=to(this._observableInputTracker),i=Ne(this._touchInputTracker);this._kmtParser=new K(o,t),this._touchParser=new $(i,t),null!=t&&(console.log("canvas exists on creation of board"),this.attach(t),this.syncViewPortDimensions({width:t.width,height:t.height}))}syncViewPortDimensions(t){this.camera.viewPortHeight=t.height,this.camera.viewPortWidth=t.width}attach(t){const e=t.getContext("2d");null!=e?(this._kmtParser.attach(t),this._touchParser.attach(t),this._canvasProxy.attach(t),this.limitEntireViewPort&&this.syncCameraZoomLevel(this._canvasProxy.dimensions),this._context=e,this._reversedContext=at(this._context)):console.error("new canvas context is null")}tearDown(){this._kmtParser.tearDown(),this._touchParser.tearDown(),this._canvasProxy.tearDown()}bindFunctions(){this.step=this.step.bind(this)}get width(){return this._canvasProxy.width}get height(){return this._canvasProxy.height}set alignCoordinateSystem(t){this._alignCoordinateSystem=t,this._observableInputTracker.alignCoordinateSystem=t,this._touchInputTracker.alignCoordinateSystem=t}get alignCoordinateSystem(){return this._alignCoordinateSystem}get fullScreen(){return this._fullScreen}set fullScreen(t){this._fullScreen=t,this._fullScreen&&(this._canvasProxy.setWidth(window.innerWidth),this._canvasProxy.setHeight(window.innerHeight))}get context(){return this._alignCoordinateSystem?this._context:this._reversedContext}set limitEntireViewPort(t){this.cameraRig.limitEntireViewPort=t,this._canvasProxy.detached||t&&this.syncCameraZoomLevel(this._canvasProxy.dimensions)}get limitEntireViewPort(){return this.cameraRig.limitEntireViewPort}set kmtParser(t){this._kmtParser.tearDown(),t.setUp(),this._kmtParser=t}get kmtParser(){return this._kmtParser}set touchParser(t){this._touchParser.tearDown(),t.setUp(),this._touchParser=t}get touchParser(){return this._touchParser}get camera(){return this.cameraRig.camera}set camera(t){this._canvasProxy.detached||(t.viewPortHeight=this._canvasProxy.height/window.devicePixelRatio,t.viewPortWidth=this._canvasProxy.width/window.devicePixelRatio),this.cameraRig.camera=t}get cameraMux(){return this.boardInputPublisher.cameraMux}set cameraMux(t){this.boardInputPublisher.cameraMux=t}get cameraMovementOnMouseEdge(){return this._edgeAutoCameraInput}step(t){if(this._canvasProxy.detached||null==this._context)return;this.cameraRig.update();let e=t-this.lastUpdateTime;this.lastUpdateTime=t,e/=1e3,this._context.reset(),this._context.clearRect(0,0,this._canvasProxy.width*window.devicePixelRatio,this._canvasProxy.height*window.devicePixelRatio),!this._fullScreen||this._canvasProxy.width==window.innerWidth&&this._canvasProxy.height==window.innerHeight||(this._canvasProxy.setWidth(window.innerWidth),this._canvasProxy.setHeight(window.innerHeight)),null!=this._canvasSizeUpdateQueue&&(this.syncViewPortDimensions(this._canvasSizeUpdateQueue),this.syncCameraZoomLevel(this._canvasSizeUpdateQueue),this._canvasSizeUpdateQueue=void 0),this._edgeAutoCameraInput.update(e);const o=this.camera.getTransform(window.devicePixelRatio,this._alignCoordinateSystem);this._context.setTransform(o.a,o.b,o.c,o.d,o.e,o.f)}convertWindowPoint2WorldCoord(e){const o=this._canvasProxy.dimensions,i={x:o.position.x+o.width/2,y:o.position.y+o.height/2},n=t.subVector(e,i);return this._alignCoordinateSystem||(n.y=-n.y),this.camera.convertFromViewPort2WorldSpace(n)}on(t,e){return this.camera.on(t,e)}onInput(t,e){return this.boardInputPublisher.on(t,e)}get maxHalfTransHeight(){return O(this.camera.boundaries)}get maxHalfTransWidth(){return S(this.camera.boundaries)}syncCameraZoomLevel(t){if(this.limitEntireViewPort){const e=It(this.camera.boundaries,t.width,t.height,this.camera.rotation);null!=e&&Bt(this.camera.zoomBoundaries,e)&&this.camera.setMinZoomLevel(e)}}setMaxTransWidthWithFixedMinBoundary(t){const e=this.camera.boundaries,o=null==e?void 0:e.min,i=null==o?void 0:o.x;if(null==i?this.camera.setHorizontalBoundaries(-t,t):this.camera.setHorizontalBoundaries(i,i+2*t),this.limitEntireViewPort){const t=Rt(this.camera.boundaries,this.camera.viewPortWidth,this.camera.viewPortHeight,this.camera.rotation);Bt(this.camera.zoomBoundaries,t)&&this.camera.setMinZoomLevel(t)}}setMaxTransWidthWithFixedMaxBoundary(t){const e=this.camera.boundaries,o=null==e?void 0:e.max,i=null==o?void 0:o.x;if(null==i?this.camera.setHorizontalBoundaries(-t,t):this.camera.setHorizontalBoundaries(i-2*t,i),this.limitEntireViewPort){const t=Rt(this.camera.boundaries,this.camera.viewPortWidth,this.camera.viewPortHeight,this.camera.rotation);Bt(this.camera.zoomBoundaries,t)&&this.camera.setMinZoomLevel(t)}}get restrictRelativeXTranslation(){return this.cameraRig.config.restrictRelativeXTranslation}get restrictRelativeYTranslation(){return this.cameraRig.config.restrictRelativeYTranslation}get restrictXTranslation(){return this.cameraRig.config.restrictXTranslation}get restrictYTranslation(){return this.cameraRig.config.restrictYTranslation}set restrictRelativeXTranslation(t){this.cameraRig.config.restrictRelativeXTranslation=t}set restrictRelativeYTranslation(t){this.cameraRig.configure({restrictRelativeYTranslation:t})}set restrictXTranslation(t){this.cameraRig.configure({restrictXTranslation:t})}set restrictYTranslation(t){this.cameraRig.configure({restrictYTranslation:t})}get restrictZoom(){return this.cameraRig.config.restrictZoom}set restrictZoom(t){this.cameraRig.configure({restrictZoom:t})}get restrictRotation(){return this.cameraRig.config.restrictRotation}set restrictRotation(t){this.cameraRig.configure({restrictRotation:t})}get clampTranslation(){return this.cameraRig.config.clampTranslation}set clampTranslation(t){this.cameraRig.configure({clampTranslation:t})}get clampZoom(){return this.cameraRig.config.clampZoom}set clampZoom(t){this.cameraRig.configure({clampZoom:t})}get clampRotation(){return this.cameraRig.config.clampRotation}set clampRotation(t){this.cameraRig.configure({clampRotation:t})}getCameraRig(){return this.cameraRig}}export{re as AcceptingUserInputState,n as AsyncObservable,io as Board,we as CameraMuxWithAnimationAndLock,Kt as CameraPositionUpdateBatcher,Qt as CameraRigWithUpdateBatcher,$t as CameraRotationUpdateBatcher,s as CameraUpdatePublisher,Jt as CameraZoomUpdateBatcher,Ae as CanvasCacheInWebWorker,et as CanvasPositionDimensionPublisher,Ee as CanvasProxy,Me as CursorStyle,G as DEFAULT_BOARD_CAMERA_BOUNDARIES,Y as DEFAULT_BOARD_CAMERA_ROTATION_BOUNDARIES,q as DEFAULT_BOARD_CAMERA_VIEWPORT_HEIGHT,F as DEFAULT_BOARD_CAMERA_VIEWPORT_WIDTH,j as DEFAULT_BOARD_CAMERA_ZOOM_BOUNDARIES,X as DefaultBoardCamera,ee as DefaultCameraRig,Ge as DisabledState,Oe as DummyCanvas,Ve as DummyKmtInputContext,oo as EdgeAutoCameraInput,ft as HALF_TICK_LENGTH,Le as IdleState,He as InProgressState,Xe as InitialPanState,Qe as KmtEmptyState,qe as KmtIdleState,eo as KmtInputStateMachineWebWorkerProxy,ce as LockedOnObjectState,_t as MAJOR_TICK_LENGTH,yt as MINOR_TICK_LENGTH,ke as ObservableInputTracker,se as PanControlStateMachine,$e as PanState,Je as PanViaScrollWheelState,Ze as PendingState,Be as RawUserInputPublisher,Se as RawUserInputPublisherWithWebWorkerRelay,Ke as ReadyToPanViaScrollWheelState,Ye as ReadyToPanViaSpaceBarState,je as ReadyToSelectState,ie as Relay,ge as RotateControlStateMachine,ve as RotationAcceptingUserInputState,be as RotationLockedOnObjectState,xe as RotationTransitionState,a as SynchronousObservable,bt as TEXT_HALF_TICK_FONT_SIZE,vt as TEXT_HALF_TICK_OFFSET,xt as TEXT_MAJOR_TICK_FONT_SIZE,gt as TEXT_MAJOR_TICK_OFFSET,Ue as TouchInputTracker,he as TransitionState,K as VanillaKMTEventParser,$ as VanillaTouchEventParser,ze as WorkerRelayCanvas,de as ZoomAcceptingUserInputState,_e as ZoomControlStateMachine,pe as ZoomLockedOnObjectState,me as ZoomTransitionState,H as angleSpan,I as boundariesFullyDefined,Q as calculateOrderOfMagnitude,Ct as calculateTickValues,b as cameraPositionToGet,Nt as clampByHandler,B as clampPoint,A as clampPointEntireViewPort,Ft as clampRotateByHandler,jt as clampRotateToHandler,k as clampRotation,Ht as clampToHandler,Ot as clampZoomByHandler,z as clampZoomLevel,Mt as clampZoomToHandler,y as convert2ViewPortSpaceAnchorAtCenter,p as convert2WorldSpace,_ as convert2WorldSpaceAnchorAtCenter,m as convert2WorldSpaceWRT,P as convert2WorldSpaceWithTransformationMatrix,v as convertDeltaInViewPortToWorldSpace,x as convertDeltaInWorldToViewPortSpace,Dt as convertDeltaToComplyWithRestriction,De as convertFromWindow2ViewPort,Fe as convertFromWindow2ViewPortCanvasOperator,We as convertFromWindow2ViewPortWithCanvasOperator,Wt as convertUserInputDeltaToCameraDelta,h as createCameraMatrix,Ce as createCameraMuxWithAnimationAndLock,Ie as createCameraMuxWithAnimationAndLockWithCameraRig,ne as createDefaultCameraMux,ae as createDefaultCameraMuxWithCameraRig,oe as createDefaultCameraRig,te as createDefaultCameraRigWithUpdateBatcher,Ut as createDefaultPanByHandler,ue as createDefaultPanControlStateMachine,le as createDefaultPanControlStates,kt as createDefaultPanToHandler,Re as createDefaultRawUserInputPublisher,Yt as createDefaultRotateByHandler,Pe as createDefaultRotateControlStateMachine,Te as createDefaultRotateControlStates,Xt as createDefaultRotateToHandler,Vt as createDefaultZoomByOnlyHandler,fe as createDefaultZoomControlStateMachine,ye as createDefaultZoomControlStates,zt as createDefaultZoomToOnlyHandler,tt as createHandlerChain,to as createKmtInputStateMachine,u as createTRSMatrix,Ne as createTouchInputStateMachine,r as decomposeCameraMatrix,l as decomposeTRS,d as decomposeTRSSVD,N as deg2rad,pt as drawArrow,ct as drawAxis,ht as drawBoundingBox,rt as drawCrossHair,lt as drawGrid,dt as drawPositionText,mt as drawReferenceCircle,Tt as drawRuler,ut as drawRulerLegacy,ot as getTrueRect,O as halfTranslationHeightOf,S as halfTranslationWidthOf,f as invertFromWorldSpace,st as invertYAxisForDrawImageWith9Args,C as isValidBoundaries,E as isValidZoomLevelLimits,It as minZoomLevelBaseOnDimensions,St as minZoomLevelBaseOnHeight,Rt as minZoomLevelBaseOnWidth,c as multiplyMatrix,Z as normalizeAngleZero2TwoPI,J as pointConversion,g as pointIsInViewPort,D as rad2deg,Zt as restrictPanByHandler,Lt as restrictPanToHandler,qt as restrictRotateByHandler,Gt as restrictRotateToHandler,Et as restrictZoomByHandler,At as restrictZoomToHandler,at as reverseYAxis,L as rotationWithinBoundary,U as rotationWithinLimits,T as transformationMatrixFromCamera,M as translationHeightOf,R as translationWidthOf,w as withinBoundaries,Bt as zoomLevelBoundariesShouldUpdate,V as zoomLevelWithinLimits};
1
+ import{PointCal as t}from"@ue-too/math";import{TemplateStateMachine as e,TemplateState as o,NO_OP as i}from"@ue-too/being";class n{constructor(){this.observers=[]}subscribe(t,e){if(this.observers.push(t),e?.signal){if(e.signal.aborted)return this.observers=this.observers.filter(e=>e!==t),()=>{};const o=()=>{this.observers=this.observers.filter(e=>e!==t),e.signal?.removeEventListener("abort",o)};e.signal.addEventListener("abort",o)}return()=>{this.observers=this.observers.filter(e=>e!==t)}}notify(...t){this.observers.forEach(e=>queueMicrotask(()=>e(...t)))}}class a{constructor(){this.observers=[]}subscribe(t,e){if(this.observers.push(t),e?.signal){if(e.signal.aborted)return this.observers=this.observers.filter(e=>e!==t),()=>{};const o=()=>{this.observers=this.observers.filter(e=>e!==t),e.signal?.removeEventListener("abort",o)};e.signal.addEventListener("abort",o)}return()=>{this.observers=this.observers.filter(e=>e!==t)}}notify(...t){this.observers.forEach(e=>e(...t))}}class s{constructor(){this.pan=new n,this.zoom=new n,this.rotate=new n,this.all=new n}notifyPan(t,e){this.pan.notify(t,e),this.all.notify({type:"pan",diff:t.diff},e)}notifyZoom(t,e){this.zoom.notify(t,e),this.all.notify({type:"zoom",deltaZoomAmount:t.deltaZoomAmount},e)}notifyRotate(t,e){this.rotate.notify(t,e),this.all.notify({type:"rotate",deltaRotation:t.deltaRotation},e)}on(t,e,o){switch(t){case"pan":return this.pan.subscribe(e,o);case"zoom":return this.zoom.subscribe(e,o);case"rotate":return this.rotate.subscribe(e,o);case"all":return this.all.subscribe(e,o);default:throw new Error(`Invalid event name: ${t}`)}}}function r(t,e,o,i){const n=t.a,a=t.b;t.c,t.d;const s=t.e,r=t.f,h=-Math.atan2(a,n),c=Math.sqrt(n*n+a*a)/e;let l=[s,r];l=[l[0]/e,l[1]/e],l=[l[0]-o/2,l[1]-i/2];const u=Math.cos(h),d=Math.sin(h);l=[u*l[0]-d*l[1],d*l[0]+u*l[1]],l=[l[0]/c,l[1]/c];return{position:{x:-l[0],y:-l[1]},zoom:c,rotation:h}}function h(t,e,o,i,n,a){const s=c({a:i,b:0,c:0,d:i,e:0,f:0},{a:1,b:0,c:0,d:1,e:n/2,f:a/2}),r=Math.cos(-o),h=Math.sin(-o),l=c(s,{a:r,b:h,c:-h,d:r,e:0,f:0}),u=c(l,{a:e,b:0,c:0,d:e,e:0,f:0});return c(u,{a:1,b:0,c:0,d:1,e:-t.x,f:-t.y})}function c(t,e){const o=t.a,i=t.b,n=t.c,a=t.d,s=t.e,r=t.f,h=e.a,c=e.b,l=e.c,u=e.d,d=e.e,m=e.f;return{a:o*h+n*c,b:i*h+a*c,c:o*l+n*u,d:i*l+a*u,e:o*d+n*m+s,f:i*d+a*m+r}}function l(t){const{a:e,b:o,c:i,d:n,e:a,f:s}=t,r={x:a,y:s},h=e*n-o*i;if(Math.abs(h)<1e-10)throw new Error("Matrix is singular and cannot be decomposed");const c=Math.atan2(o,e),l=Math.cos(c),u=Math.sin(c),d=e*l+o*u,m=i*-u+n*l;let p=c,_=d,y=m;for(d<0&&(_=-d,p+=Math.PI),m<0&&(y=-m,p+=Math.PI);p>Math.PI;)p-=2*Math.PI;for(;p<-Math.PI;)p+=2*Math.PI;return{translation:r,rotation:p,scale:{x:_,y:y}}}function u(t,e,o){const i=Math.cos(e),n=Math.sin(e);return{a:o.x*i,b:o.x*n,c:-o.y*n,d:o.y*i,e:t.x,f:t.y}}function d(t){const{a:e,b:o,c:i,d:n,e:a,f:s}=t,r={x:a,y:s},h=e,c=i,l=o,u=n,d=h*h+l*l,m=h*c+l*u,p=m,_=c*c+u*u,y=d+_,f=y*y-4*(d*_-m*p);if(f<0)throw new Error("Invalid transformation matrix");const g=Math.sqrt(f),v=(y+g)/2,x=(y-g)/2,b=Math.sqrt(Math.max(0,v)),T={x:b,y:Math.sqrt(Math.max(0,x))};let P=0;if(b>1e-10){const t=m,e=v-d,o=x-_,i=p,n=Math.sqrt(t*t+o*o),a=Math.sqrt(e*e+i*i);if(n>1e-10&&a>1e-10){const e=t/n,i=o/n,a=(h*e+c*i)/b,s=(l*e+u*i)/b;P=Math.atan2(s,a)}}return{translation:r,rotation:P,scale:T}}function m(e,o,i,n,a,s){let r={x:i/2,y:n/2},h=t.subVector(o,r);return h=t.multiplyVectorByScalar(h,1/a),h=t.rotatePoint(h,s),t.addVector(e,h)}function p(e,o,i,n,a,s){let r={x:o/2,y:i/2},h=t.subVector(e,r);return h=t.multiplyVectorByScalar(h,1/a),h=t.rotatePoint(h,s),t.addVector(n,h)}function _(e,o,i,n){const a=t.multiplyVectorByScalar(e,1/i),s=t.rotatePoint(a,n);return t.addVector(s,o)}function y(e,o,i,n){const a=t.subVector(e,o),s=t.multiplyVectorByScalar(a,i);return t.rotatePoint(s,-n)}function f(e,o,i,n,a,s){let r={x:o/2,y:i/2},h=t.subVector(e,n);return h=t.rotatePoint(h,-s),h=t.multiplyVectorByScalar(h,a),t.addVector(r,h)}function g(t,e,o,i,n,a){const s=f(t,e,o,i,n,a);return!(s.x<0||s.x>e||s.y<0||s.y>o)}function v(e,o,i){return t.multiplyVectorByScalar(t.rotatePoint(e,i),1/o)}function x(e,o,i){return t.multiplyVectorByScalar(t.rotatePoint(e,-i),o)}function b(e,o,i,n){const a=t.multiplyVectorByScalar(o,1/i),s=t.rotatePoint(a,n);return t.subVector(e,s)}function T(t,e,o){const i=Math.cos(o),n=Math.sin(o),a=c({a:1,b:0,c:0,d:1,e:t.x,f:t.y},{a:i,b:n,c:-n,d:i,e:0,f:0});return c(a,{a:1/e,b:0,c:0,d:1/e,e:0,f:0})}function P(t,e){return{x:t.x*e.a+t.y*e.c+e.e,y:t.x*e.b+t.y*e.d+e.f}}function w(t,e){if(null==e)return!0;let o=!1,i=!1,n=!1,a=!1;return(null==e.max||null==e.max.x||t.x<=e.max.x)&&(i=!0),(null==e.min||null==e.min.x||t.x>=e.min.x)&&(o=!0),(null==e.max||null==e.max.y||t.y<=e.max.y)&&(n=!0),(null==e.min||null==e.min.y||t.y>=e.min.y)&&(a=!0),o&&i&&n&&a}function C(t){if(null==t)return!0;const e=t.min?.x,o=t.max?.x;if(null!=e&&null!=o&&e>=o)return!1;const i=t.min?.y,n=t.max?.y;return!(null!=i&&null!=n&&i>=n)}function I(t){return null!=t&&(null!=t.max&&null!=t.min&&(null!=t.max.x&&null!=t.max.y&&null!=t.min.x&&null!=t.min.y))}function B(t,e){if(w(t,e)||null==e)return t;let o={x:t.x,y:t.y},i=e.min;return null!=i&&(null!=i.x&&(o.x=Math.max(o.x,i.x)),null!=i.y&&(o.y=Math.max(o.y,i.y))),i=e.max,null!=i&&(null!=i.x&&(o.x=Math.min(o.x,i.x)),null!=i.y&&(o.y=Math.min(o.y,i.y))),o}function R(t){if(null!=t&&null!=t.min&&null!=t.max&&null!=t.min.x&&null!=t.max.x)return t.max.x-t.min.x}function S(t){const e=R(t);return null!=e?e/2:void 0}function M(t){if(null!=t&&null!=t.min&&null!=t.max&&null!=t.min.y&&null!=t.max.y)return t.max.y-t.min.y}function O(t){const e=M(t);return null!=e?e/2:void 0}function A(e,o,i,n,a,s){if(null==n)return e;let r=m(e,{x:0,y:i},o,i,a,s),h=m(e,{x:0,y:0},o,i,a,s),c=m(e,{x:o,y:i},o,i,a,s),l=m(e,{x:o,y:0},o,i,a,s),u=B(r,n),d=B(c,n),p=B(h,n),_=B(l,n),y=[t.subVector(u,r),t.subVector(d,c),t.subVector(p,h),t.subVector(_,l)],f=Math.abs(y[0].x),g=Math.abs(y[0].y),v=y[0];return y.forEach(t=>{Math.abs(t.x)>f&&(f=Math.abs(t.x),v.x=t.x),Math.abs(t.y)>g&&(g=Math.abs(t.y),v.y=t.y)}),t.addVector(e,v)}function E(t){return void 0===t||!(void 0!==t.min&&void 0!==t.max&&t.min>t.max)}function z(t,e){return V(t,e)||void 0===e||(e.max&&(t=Math.min(e.max,t)),e.min&&(t=Math.max(e.min,t))),t}function V(t,e){return void 0===e||!(t<=0||void 0!==e&&(void 0!==e.max&&e.max<t||void 0!==e.min&&e.min>t))}function k(t,e){if(L(t,e)||void 0===e)return t;t=U(t);const o=H(e.start,t),i=H(e.end,t);if(e.ccw&&(o<0||i>0)||!e.ccw&&(o>0||i<0)){if(Math.abs(o)===Math.abs(i))return e.startAsTieBreaker?e.start:e.end;return Math.abs(o)<Math.abs(i)?e.start:e.end}return t}function L(t,e){if(void 0===e)return!0;if(U(e.start)===U(e.end))return!0;if(U(e.start+.01)===U(e.end+.01))return!0;const o=U(t),i=H(e.start,o),n=H(e.end,o);return!(e.ccw&&(i<0||n>0)||!e.ccw&&(i>0||n<0))}function Z(t,e){if(U(e.start)===U(e.end))return!0;if(U(e.start+.01)===U(e.end+.01))return!0;let o=U(t)-U(e.start);o<0&&(o+=2*Math.PI),!e.positiveDirection&&o>0&&(o=2*Math.PI-o);let i=U(e.end)-U(e.start);return i<0&&(i+=2*Math.PI),!e.positiveDirection&&i>0&&(i=2*Math.PI-i),i>=o}function U(t){return t=((t%=2*Math.PI)+2*Math.PI)%(2*Math.PI)}function H(t,e){t=U(t);let o=(e=U(e))-t;return o>Math.PI&&(o=-(2*Math.PI-o)),o<-Math.PI&&(o+=2*Math.PI),o}function N(t){return t*Math.PI/180}function D(t){return 180*t/Math.PI}class W{constructor(t=1e3,e=1e3,o={x:0,y:0},i=0,n=1,a={min:{x:-1e4,y:-1e4},max:{x:1e4,y:1e4}},s={min:.1,max:10},r=void 0){this._position=o,this._zoomLevel=n,this._rotation=i,this._viewPortHeight=e,this._viewPortWidth=t,this._zoomBoundaries=s,this._rotationBoundaries=r,this._boundaries=a}get boundaries(){return this._boundaries}set boundaries(t){this._boundaries=t}get viewPortWidth(){return this._viewPortWidth}set viewPortWidth(t){this._viewPortWidth=t}get viewPortHeight(){return this._viewPortHeight}set viewPortHeight(t){this._viewPortHeight=t}get position(){return this._position}setPosition(e){if(!w(e,this._boundaries))return!1;const o=t.subVector(e,this._position);return!(t.magnitude(o)<1e-9&&t.magnitude(o)<1/this._zoomLevel)&&(this._position=e,!0)}get zoomLevel(){return this._zoomLevel}get zoomBoundaries(){return this._zoomBoundaries}set zoomBoundaries(t){const e={...t};if(void 0!==e&&void 0!==e.min&&void 0!==e.max&&e.min>e.max){let t=e.max;e.max=e.min,e.min=t}this._zoomBoundaries=e}setMaxZoomLevel(t){return null==this._zoomBoundaries&&(this._zoomBoundaries={min:void 0,max:void 0}),!(null!=this._zoomBoundaries.min&&this._zoomBoundaries.min>t||this._zoomLevel>t)&&(this._zoomBoundaries.max=t,console.trace("setMaxZoomLevel",t),!0)}setMinZoomLevel(t){return null==this._zoomBoundaries&&(this._zoomBoundaries={min:void 0,max:void 0}),!(null!=this._zoomBoundaries.max&&this._zoomBoundaries.max<t)&&(this._zoomBoundaries.min=t,this._zoomLevel<t&&(this._zoomLevel=t),console.trace("setMinZoomLevel",t),!0)}setZoomLevel(t){return!!V(t,this._zoomBoundaries)&&((void 0===this._zoomBoundaries||void 0===this._zoomBoundaries.max||z(t,this._zoomBoundaries)!=this._zoomBoundaries.max||this._zoomLevel!=this._zoomBoundaries.max)&&((void 0===this._zoomBoundaries||void 0===this._zoomBoundaries.min||z(t,this._zoomBoundaries)!=this._zoomBoundaries.min||this._zoomLevel!=this._zoomBoundaries.min)&&(this._zoomLevel=t,!0)))}get rotation(){return this._rotation}get rotationBoundaries(){return this._rotationBoundaries}set rotationBoundaries(t){if(void 0!==t&&void 0!==t.start&&void 0!==t.end&&t.start>t.end){let e=t.end;t.end=t.start,t.start=e}this._rotationBoundaries=t}getTransform(t,e){if(void 0!==this.currentCachedTransform&&this.currentCachedTransform.devicePixelRatio===t&&this.currentCachedTransform.alignCoorindate===e&&this.currentCachedTransform.position.x===this._position.x&&this.currentCachedTransform.position.y===this._position.y&&this.currentCachedTransform.rotation===this._rotation&&this.currentCachedTransform.zoomLevel===this._zoomLevel&&this.currentCachedTransform.viewPortWidth===this._viewPortWidth&&this.currentCachedTransform.viewPortHeight===this._viewPortHeight)return{...this.currentCachedTransform.transform,cached:!0};const o=t*this._viewPortWidth/2,i=t*this._viewPortHeight/2,n=-this._position.x,a=e?-this._position.y:this._position.y,s=t,r=this._zoomLevel,h=e?-this._rotation:this._rotation,c=Math.sin(h),l=Math.cos(h),u=r*s*l,d=r*s*c,m=-s*r*c,p=r*s*l,_=s*r*l*n-s*r*c*a+o,y=s*r*c*n+s*r*l*a+i;return this.currentCachedTransform={transform:{a:u,b:d,c:m,d:p,e:_,f:y},position:this._position,rotation:this._rotation,zoomLevel:this._zoomLevel,alignCoorindate:e,devicePixelRatio:t,viewPortWidth:this._viewPortWidth,viewPortHeight:this._viewPortHeight},{a:u,b:d,c:m,d:p,e:_,f:y,cached:!1}}getTRS(t,e){return l(this.getTransform(t,e))}setUsingTransformationMatrix(t){const e=r(t,this._viewPortWidth,this._viewPortHeight,this._zoomLevel);this.setPosition(e.position),this.setRotation(e.rotation),this.setZoomLevel(e.zoom)}setRotation(t){return!!L(t,this._rotationBoundaries)&&(t=U(t),(void 0===this._rotationBoundaries||void 0===this._rotationBoundaries.end||k(t,this._rotationBoundaries)!=this._rotationBoundaries.end||this._rotation!=this._rotationBoundaries.end)&&((void 0===this._rotationBoundaries||void 0===this._rotationBoundaries.start||k(t,this._rotationBoundaries)!=this._rotationBoundaries.start||this._rotation!=this._rotationBoundaries.start)&&(this._rotation=t,!0)))}getCameraOriginInWindow(t){return t}convertFromViewPort2WorldSpace(t){return _(t,this._position,this._zoomLevel,this._rotation)}convertFromWorld2ViewPort(t){return y(t,this._position,this._zoomLevel,this._rotation)}invertFromWorldSpace2ViewPort(e){let o={x:this.viewPortWidth/2,y:this._viewPortHeight/2},i=t.subVector(e,this._position);return i=t.rotatePoint(i,-this._rotation),i=t.multiplyVectorByScalar(i,this._zoomLevel),t.addVector(o,i)}setHorizontalBoundaries(t,e){if(t>e){let o=e;e=t,t=o}null==this._boundaries&&(this._boundaries={min:{x:void 0,y:void 0},max:{x:void 0,y:void 0}}),null==this._boundaries.min&&(this._boundaries.min={x:void 0,y:void 0}),null==this._boundaries.max&&(this._boundaries.max={x:void 0,y:void 0}),this._boundaries.min.x=t,this._boundaries.max.x=e}setVerticalBoundaries(t,e){if(t>e){let o=e;e=t,t=o}null==this._boundaries&&(this._boundaries={min:{x:void 0,y:void 0},max:{x:void 0,y:void 0}}),null==this._boundaries.min&&(this._boundaries.min={x:void 0,y:void 0}),null==this._boundaries.max&&(this._boundaries.max={x:void 0,y:void 0}),this._boundaries.min.y=t,this._boundaries.max.y=e}}const F=1e3,q=1e3,j={min:.1,max:10},G={min:{x:-1e4,y:-1e4},max:{x:1e4,y:1e4}},Y=void 0;class X{constructor(t=1e3,e=1e3,o={x:0,y:0},i=0,n=1,a=G,r=j,h=Y){this._baseCamera=new W(t,e,o,i,n,a,r,h),this._observer=new s}get boundaries(){return this._baseCamera.boundaries}set boundaries(t){this._baseCamera.boundaries=t}get viewPortWidth(){return this._baseCamera.viewPortWidth}set viewPortWidth(t){this._baseCamera.viewPortWidth=t}get viewPortHeight(){return this._baseCamera.viewPortHeight}set viewPortHeight(t){this._baseCamera.viewPortHeight=t}get position(){return this._baseCamera.position}setPosition(e){const o={...this._baseCamera.position};return!!this._baseCamera.setPosition(e)&&(this._observer.notifyPan({diff:t.subVector(e,o)},{position:this._baseCamera.position,rotation:this._baseCamera.rotation,zoomLevel:this._baseCamera.zoomLevel}),!0)}get zoomLevel(){return this._baseCamera.zoomLevel}get zoomBoundaries(){return this._baseCamera.zoomBoundaries}set zoomBoundaries(t){this._baseCamera.zoomBoundaries=t}setMaxZoomLevel(t){const e=this._baseCamera.zoomLevel;return!!this._baseCamera.setMaxZoomLevel(t)&&(this._observer.notifyZoom({deltaZoomAmount:t-e},{position:this._baseCamera.position,rotation:this._baseCamera.rotation,zoomLevel:this._baseCamera.zoomLevel}),!0)}setMinZoomLevel(t){return!!this._baseCamera.setMinZoomLevel(t)}setZoomLevel(t){const e=this._baseCamera.zoomLevel;return!!this._baseCamera.setZoomLevel(t)&&(this._observer.notifyZoom({deltaZoomAmount:this._baseCamera.zoomLevel-e},{position:this._baseCamera.position,rotation:this._baseCamera.rotation,zoomLevel:this._baseCamera.zoomLevel}),!0)}get rotation(){return this._baseCamera.rotation}get rotationBoundaries(){return this._baseCamera.rotationBoundaries}set rotationBoundaries(t){this._baseCamera.rotationBoundaries=t}getTransform(t,e=!0){return this._baseCamera.getTransform(t,e)}setRotation(t){const e=this._baseCamera.rotation;return!!this._baseCamera.setRotation(t)&&(this._observer.notifyRotate({deltaRotation:t-e},{position:this._baseCamera.position,rotation:this._baseCamera.rotation,zoomLevel:this._baseCamera.zoomLevel}),!0)}getCameraOriginInWindow(t){return t}convertFromViewPort2WorldSpace(t){return _(t,this._baseCamera.position,this._baseCamera.zoomLevel,this._baseCamera.rotation)}convertFromWorld2ViewPort(t){return y(t,this._baseCamera.position,this._baseCamera.zoomLevel,this._baseCamera.rotation)}invertFromWorldSpace2ViewPort(e){let o={x:this._baseCamera.viewPortWidth/2,y:this._baseCamera.viewPortHeight/2},i=t.subVector(e,this._baseCamera.position);return i=t.rotatePoint(i,-this._baseCamera.rotation),i=t.multiplyVectorByScalar(i,this._baseCamera.zoomLevel),t.addVector(o,i)}setHorizontalBoundaries(t,e){if(t>e){let o=e;e=t,t=o}null==this._baseCamera.boundaries&&(this._baseCamera.boundaries={min:void 0,max:void 0}),null==this._baseCamera.boundaries.min&&(this._baseCamera.boundaries.min={x:void 0,y:void 0}),null==this._baseCamera.boundaries.max&&(this._baseCamera.boundaries.max={x:void 0,y:void 0}),this._baseCamera.boundaries.min.x=t,this._baseCamera.boundaries.max.x=e}setVerticalBoundaries(t,e){if(t>e){let o=e;e=t,t=o}null==this._baseCamera.boundaries&&(this._baseCamera.boundaries={min:void 0,max:void 0}),null==this._baseCamera.boundaries.min&&(this._baseCamera.boundaries.min={x:void 0,y:void 0}),null==this._baseCamera.boundaries.max&&(this._baseCamera.boundaries.max={x:void 0,y:void 0}),this._baseCamera.boundaries.min.y=t,this._baseCamera.boundaries.max.y=e}on(t,e,o){return this._observer.on(t,e,o)}getTRS(t,e){return this._baseCamera.getTRS(t,e)}}class K{constructor(t,e){this._disabled=!1,this._canvas=e,this.bindFunctions(),this._abortController=new AbortController,this._stateMachine=t,this._keyfirstPressed=new Map}get disabled(){return this._disabled}set disabled(t){this._disabled=t}get stateMachine(){return this._stateMachine}addEventListeners(t){null!=this._canvas&&(this._canvas.addEventListener("pointerdown",this.pointerDownHandler,{signal:t}),this._canvas.addEventListener("pointerup",this.pointerUpHandler,{signal:t}),this._canvas.addEventListener("pointermove",this.pointerMoveHandler,{signal:t}),this._canvas.addEventListener("wheel",this.scrollHandler,{signal:t}),window.addEventListener("keydown",this.keypressHandler,{signal:t}),window.addEventListener("keyup",this.keyupHandler,{signal:t}))}setUp(){this._abortController.signal.aborted&&(this._abortController=new AbortController),this.addEventListeners(this._abortController.signal)}tearDown(){this._abortController.abort(),this._abortController=new AbortController}bindFunctions(){this.pointerDownHandler=this.pointerDownHandler.bind(this),this.pointerUpHandler=this.pointerUpHandler.bind(this),this.pointerMoveHandler=this.pointerMoveHandler.bind(this),this.scrollHandler=this.scrollHandler.bind(this),this.keypressHandler=this.keypressHandler.bind(this),this.keyupHandler=this.keyupHandler.bind(this)}pointerDownHandler(t){this._disabled||(0!==t.button||"mouse"!==t.pointerType?1!==t.button||"mouse"!==t.pointerType||this.stateMachine.happens("middlePointerDown",{x:t.clientX,y:t.clientY}):this.stateMachine.happens("leftPointerDown",{x:t.clientX,y:t.clientY}))}pointerUpHandler(t){this._disabled||(0!==t.button||"mouse"!==t.pointerType?1!==t.button||"mouse"!==t.pointerType||this.stateMachine.happens("middlePointerUp",{x:t.clientX,y:t.clientY}):this.stateMachine.happens("leftPointerUp",{x:t.clientX,y:t.clientY}))}pointerMoveHandler(t){this._disabled||(1!==t.buttons||"mouse"!==t.pointerType?4!==t.buttons||"mouse"!==t.pointerType?this.stateMachine.happens("pointerMove",{x:t.clientX,y:t.clientY}):this.stateMachine.happens("middlePointerMove",{x:t.clientX,y:t.clientY}):this.stateMachine.happens("leftPointerMove",{x:t.clientX,y:t.clientY}))}scrollHandler(t){this._disabled||(t.preventDefault(),t.ctrlKey?this.stateMachine.happens("scrollWithCtrl",{x:t.clientX,y:t.clientY,deltaX:t.deltaX,deltaY:t.deltaY}):this.stateMachine.happens("scroll",{deltaX:t.deltaX,deltaY:t.deltaY}))}keypressHandler(t){t.target===document.body&&(this._keyfirstPressed.has(t.key)||(this._keyfirstPressed.set(t.key,!0)," "===t.key&&this.stateMachine.happens("spacebarDown")))}keyupHandler(t){this._keyfirstPressed.has(t.key)&&this._keyfirstPressed.delete(t.key)," "===t.key&&this.stateMachine.happens("spacebarUp")}attach(t){this.tearDown(),this._canvas=t,this.setUp()}}class ${constructor(t,e){this._panDisabled=!1,this._zoomDisabled=!1,this._rotateDisabled=!1,this._canvas=e,this._disabled=!1,this.touchSM=t,this._abortController=new AbortController,this.bindListeners()}get touchStateMachine(){return this.touchSM}bindListeners(){this.touchstartHandler=this.touchstartHandler.bind(this),this.touchendHandler=this.touchendHandler.bind(this),this.touchcancelHandler=this.touchcancelHandler.bind(this),this.touchmoveHandler=this.touchmoveHandler.bind(this)}enableStrategy(){this._disabled=!1}disableStrategy(){this._disabled=!0}setUp(){null!=this._canvas&&(this._abortController.signal.aborted&&(this._abortController=new AbortController),this._canvas.addEventListener("touchstart",this.touchstartHandler,{signal:this._abortController.signal}),this._canvas.addEventListener("touchend",this.touchendHandler,{signal:this._abortController.signal}),this._canvas.addEventListener("touchcancel",this.touchcancelHandler,{signal:this._abortController.signal}),this._canvas.addEventListener("touchmove",this.touchmoveHandler,{signal:this._abortController.signal}))}tearDown(){this._abortController.abort(),this._abortController=new AbortController}get disabled(){return this._disabled}get panDisabled(){return this._panDisabled}set panDisabled(t){this._panDisabled=t}get zoomDisabled(){return this._zoomDisabled}set zoomDisabled(t){this._zoomDisabled=t}get rotateDisabled(){return this._rotateDisabled}set rotateDisabled(t){this._rotateDisabled=t}touchstartHandler(t){if(this._disabled)return;const e=[];for(let o=0;o<t.changedTouches.length;o++)e.push({ident:t.changedTouches[o].identifier,x:t.changedTouches[o].clientX,y:t.changedTouches[o].clientY});this.touchSM.happens("touchstart",{points:e}),t.preventDefault()}touchcancelHandler(t){if(this._disabled)return;const e=[];for(let o=0;o<t.changedTouches.length;o++)e.push({ident:t.changedTouches[o].identifier,x:t.changedTouches[o].clientX,y:t.changedTouches[o].clientY});this.touchSM.happens("touchend",{points:e})}touchendHandler(t){if(this._disabled)return;const e=[];for(let o=0;o<t.changedTouches.length;o++)e.push({ident:t.changedTouches[o].identifier,x:t.changedTouches[o].clientX,y:t.changedTouches[o].clientY});this.touchSM.happens("touchend",{points:e})}touchmoveHandler(t){if(this._disabled)return;t.preventDefault();const e=[];for(let o=0;o<t.targetTouches.length;o++)e.push({ident:t.targetTouches[o].identifier,x:t.targetTouches[o].clientX,y:t.targetTouches[o].clientY});this.touchSM.happens("touchmove",{points:e})}attach(t){this.tearDown(),this._canvas=t,this.setUp()}}function J(t){const e=Math.cos(Math.PI/6),o=Math.cos(Math.PI/3);return{x:t.x*e-t.y*e,y:t.x*o+t.y*o+(t.z??0)}}function Q(t){if(t<=0)return 0;let e=0;if(t<1){let o=1;for(;o>t;)o/=10,e--}else{let o=1;for(;10*o<=t;)o*=10,e++}return e}function tt(...t){const e=Array.isArray(t[0])?t[0]:t;return(t,...o)=>e.reduce((t,e)=>e(t,...o),t)}class et{constructor(t){this._observers=new a,this.resizeObserver=new ResizeObserver((t=>{for(const e of t){const t=ot(e.target.getBoundingClientRect(),window.getComputedStyle(e.target));it(this.lastRect,t)&&(this.publishPositionUpdate(t),this.lastRect=t)}}).bind(this)),this.intersectionObserver=new IntersectionObserver((t=>{if(void 0!==this.lastRect)for(const e of t)if(e.isIntersecting){const t=ot(e.boundingClientRect,window.getComputedStyle(e.target));it(this.lastRect,t)&&(this.publishPositionUpdate(t),this.lastRect=t)}}).bind(this)),this.attributeCallBack=this.attributeCallBack.bind(this),this.mutationObserver=new MutationObserver(this.attributeCallBack),t&&this.attach(t)}dispose(){this.resizeObserver.disconnect(),this.intersectionObserver.disconnect(),this.mutationObserver.disconnect(),this.scrollHandler&&window.removeEventListener("scroll",this.scrollHandler),this.resizeHandler&&window.removeEventListener("resize",this.resizeHandler)}attach(t){this.dispose(),this.resizeObserver.observe(t),this.intersectionObserver.observe(t),this.mutationObserver.observe(t,{attributes:!0,attributeFilter:["width","height","style"]});const e=ot(t.getBoundingClientRect(),window.getComputedStyle(t));this.lastRect=e,this.scrollHandler=(()=>{if(void 0===this.lastRect)return;const e=ot(t.getBoundingClientRect(),window.getComputedStyle(t));it(this.lastRect,e)&&(this.publishPositionUpdate(e),this.lastRect=e)}).bind(this),this.resizeHandler=(()=>{if(void 0===this.lastRect)return;const e=ot(t.getBoundingClientRect(),window.getComputedStyle(t));it(this.lastRect,e)&&(this.publishPositionUpdate(e),this.lastRect=e)}).bind(this),window.addEventListener("scroll",this.scrollHandler,{passive:!0}),window.addEventListener("resize",this.resizeHandler,{passive:!0})}publishPositionUpdate(t){this._observers.notify(t)}onPositionUpdate(t,e){return this._observers.subscribe(t,e)}attributeCallBack(t,e){for(let e of t)if("attributes"===e.type)if("width"===e.attributeName){const t=e.target;t.style.width=t.width/window.devicePixelRatio+"px";const o=ot(e.target.getBoundingClientRect(),window.getComputedStyle(e.target));it(this.lastRect,o)&&(this.publishPositionUpdate(o),this.lastRect=o)}else if("height"===e.attributeName){const t=e.target;t.style.height=t.height/window.devicePixelRatio+"px";const o=ot(t.getBoundingClientRect(),window.getComputedStyle(e.target));it(this.lastRect,o)&&(this.publishPositionUpdate(o),this.lastRect=o)}else if("style"===e.attributeName){const t=e.target,o=parseFloat(e.target.style.width),i=parseFloat(e.target.style.height),n=o*window.devicePixelRatio,a=i*window.devicePixelRatio;n!=t.width&&(t.width=n),a!=t.height&&(t.height=a);const s=ot(e.target.getBoundingClientRect(),window.getComputedStyle(e.target));it(this.lastRect,s)&&(this.publishPositionUpdate(s),this.lastRect=s)}}}function ot(t,e){const o=parseFloat(e.paddingLeft),i=parseFloat(e.paddingTop),n=parseFloat(e.paddingRight),a=parseFloat(e.paddingBottom),s=parseFloat(e.borderLeftWidth),r=parseFloat(e.borderTopWidth),h=parseFloat(e.borderRightWidth),c=parseFloat(e.borderBottomWidth),l=t.left+o+s,u=t.top+i+r,d=t.width-o-n-s-h,m=t.height-i-a-r-c;return new DOMRect(l,u,d,m)}function it(t,e){return void 0===t||(t.top!==e.top||t.left!==e.left||t.width!==e.width||t.height!==e.height)}const nt={fillRect:[1],strokeRect:[1],fillText:[2],strokeText:[1],lineTo:[1],moveTo:[1],quadraticCurveTo:[1,3],bezierCurveTo:[1,3,5],arc:[1],drawImage:[2],rect:[1],roundRect:[1]};function at(t){return new Proxy(t,{get(t,e,o){const i=Reflect.get(t,e,t);return"string"==typeof e&&e in nt&&"function"==typeof i?function(...o){const n=[...o];if("drawImage"===e&&9===o.length){const e=st(o);return i.apply(t,e)}{const t=nt[e];for(const e of t)e<n.length&&(n[e]=-n[e]);"drawImage"===e&&5===o.length&&(n[2]-=n[4])}return i.apply(t,n)}:"function"==typeof i?function(...e){return i.apply(t,e)}:i},set:(t,e,o)=>Reflect.set(t,e,o)})}function st(t){if(9!==t.length)return t;const e=[...t],o=t[0].height;return void 0!==o&&(e[2]=o-e[2],e[6]=-e[6],e[6]-=e[8],e[4]=-e[4]),e}function rt(t,e,o,i,n,a="red"){let s=n/2;s/=o,t.beginPath(),t.strokeStyle=a,t.lineWidth=2/o,i?(t.moveTo(e.x-s,e.y),t.lineTo(e.x+s,e.y),t.moveTo(e.x,e.y-s),t.lineTo(e.x,e.y+s)):(t.moveTo(e.x-s,-e.y),t.lineTo(e.x+s,-e.y),t.moveTo(e.x,-e.y-s),t.lineTo(e.x,-e.y+s)),t.stroke(),t.lineWidth=3}function ht(t,e,o){if(!I(e))return;const i=R(e),n=M(e),a=null==e?void 0:e.min,s=null==a?void 0:a.x,r=null==a?void 0:a.y;null!=s&&null!=r&&null!=i&&null!=n&&(t.beginPath(),t.strokeStyle="blue",t.lineWidth=100,o?t.roundRect(s,r,i,n,5):t.roundRect(s,-r,i,-n,5),t.stroke(),t.lineWidth=3,t.strokeStyle="black")}function ct(t,e,o,i){if(!I(e))return;const n=R(e),a=M(e),s=null==e?void 0:e.min,r=null==s?void 0:s.x,h=null==s?void 0:s.y;null!=r&&null!=h&&null!=n&&null!=a&&(t.lineWidth=1/o,t.beginPath(),t.strokeStyle="rgba(87, 173, 72, 0.8)",t.moveTo(0,0),i?t.lineTo(0,h+a):t.lineTo(0,-h-a),t.stroke(),t.beginPath(),t.strokeStyle="rgba(220, 59, 59, 0.8)",t.moveTo(0,0),t.lineTo(r+n,0),t.stroke(),t.strokeStyle="black")}function lt(e,o,i,n,a,s,r){let h=t.unitVectorFromA2B(o,i),c=t.unitVectorFromA2B(n,o),l=t.distanceBetweenPoints(o,i);t.distanceBetweenPoints(o,n);let u=Q(l),d=Math.pow(10,u)/10,m=Math.ceil(o.x/d)*d,p=Math.floor(i.x/d)*d,_=s?Math.floor(o.y/d)*d:Math.ceil(n.y/d)*d,y=s?Math.ceil(n.y/d)*d:Math.floor(o.y/d)*d;for(let i=m;i<=p;i+=d){const a=t.addVector({x:i,y:o.y},t.multiplyVectorByScalar(h,d)),s=t.addVector({x:i,y:n.y},t.multiplyVectorByScalar(h,d));e.beginPath(),e.strokeStyle="black",e.fillStyle="black",e.lineWidth=.5/r,e.moveTo(a.x,a.y),e.lineTo(s.x,s.y),e.stroke()}for(let n=_;n<=y;n+=d){const a=t.addVector({x:o.x,y:n},t.multiplyVectorByScalar(c,d)),s=t.addVector({x:i.x,y:n},t.multiplyVectorByScalar(c,d));e.beginPath(),e.strokeStyle="black",e.fillStyle="black",e.lineWidth=.5/r,e.moveTo(a.x,a.y),e.lineTo(s.x,s.y),e.stroke()}}function ut(e,o,i,n,a,s,r){let h=t.unitVectorFromA2B(o,i),c=t.unitVectorFromA2B(n,o),l=Q(t.distanceBetweenPoints(o,i)),u=Math.pow(10,l),d=u/2,m=u/10,p=1;l<=0&&(p=Math.pow(10,1-l));let _=Math.ceil(o.x/u)*u,y=Math.floor(i.x/u)*u,f=s?Math.ceil(o.y/u)*u:Math.floor(n.y/u)*u;s?Math.floor(n.y/u):Math.ceil(o.y/u);let g=Math.ceil(o.x/d)*d,v=Math.floor(i.x/d)*d,x=s?Math.ceil(o.y/d)*d:Math.floor(n.y/d)*d,b=s?Math.floor(n.y/d)*d:Math.ceil(o.y/d)*d,T=Math.ceil(o.x/m)*m,P=Math.floor(i.x/m)*m,w=s?Math.ceil(o.y/m)*m:Math.floor(n.y/m)*m,C=s?Math.floor(n.y/m)*m:Math.ceil(o.y/m)*m,I=d*r,B=m*r;e.font=`bold ${20/r}px Helvetica`;const R=e.measureText(""+-(d+g)),S=R.fontBoundingBoxAscent+R.fontBoundingBoxDescent,M=e.measureText(""+-(m+T)),O=M.fontBoundingBoxAscent+M.fontBoundingBoxDescent,A=Math.ceil((y-_)/u);for(let i=0;i<=A;i++){const n=_+i*u;e.beginPath(),e.strokeStyle="black",e.fillStyle="black",e.lineWidth=5/r;let a=t.addVector({x:n,y:o.y},t.multiplyVectorByScalar(c,50/r));s?e.moveTo(a.x,a.y):e.moveTo(a.x,-a.y),a=t.addVector({x:n,y:o.y},t.multiplyVectorByScalar(c,-50/r)),s?e.lineTo(a.x,a.y):e.lineTo(a.x,-a.y),e.textAlign="center",e.textBaseline="middle",e.font=`bold ${20/r}px Helvetica`;const h=e.measureText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`),l=h.fontBoundingBoxAscent+h.fontBoundingBoxDescent;s?(a=t.addVector(a,{x:0,y:l/2+.2*l}),e.fillText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`,a.x,a.y)):(a=t.addVector(a,{x:0,y:-l/2-.2*l}),e.fillText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`,a.x,-a.y)),e.stroke()}const E=Math.ceil((y-_)/u);for(let i=0;i<=E;i++){const n=f+i*u;e.beginPath(),e.strokeStyle="black",e.fillStyle="black",e.lineWidth=5/r;let a=t.addVector({x:o.x,y:n},t.multiplyVectorByScalar(h,-50/r));s?e.moveTo(a.x,a.y):e.moveTo(a.x,-a.y),a=t.addVector({x:o.x,y:n},t.multiplyVectorByScalar(h,50/r)),s?e.lineTo(a.x,a.y):e.lineTo(a.x,-a.y),e.textAlign="center",e.textBaseline="middle",e.font=`bold ${20/r}px Helvetica`;const c=e.measureText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`);a=t.addVector(a,{x:c.width/2+.3*c.width,y:0}),s?e.fillText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`,a.x,a.y):e.fillText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`,a.x,-a.y),e.stroke()}const z=Math.ceil((v-g)/d);for(let i=0;i<=z;i++){const n=g+i*d;if(Math.floor(n*p)%Math.floor(u*p)==0)continue;e.beginPath(),e.strokeStyle="black",e.fillStyle="black",e.lineWidth=3/r;let a=t.addVector({x:n,y:o.y},t.multiplyVectorByScalar(c,25/r));s?e.moveTo(a.x,a.y):e.moveTo(a.x,-a.y),a=t.addVector({x:n,y:o.y},t.multiplyVectorByScalar(c,-25/r)),s?e.lineTo(a.x,a.y):e.lineTo(a.x,-a.y),e.font=15/r+"px Helvetica";const h=e.measureText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`);if(I>2*R.width){e.textAlign="center",e.textBaseline="middle";const o=h.fontBoundingBoxAscent+h.fontBoundingBoxDescent;s?a=t.addVector(a,{x:0,y:o/2+.2*o}):(a=t.addVector(a,{x:0,y:-o/2-.2*o}),a=t.flipYAxis(a)),e.fillText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`,a.x,a.y)}e.stroke()}const V=Math.ceil((b-x)/d);for(let i=0;i<=V;i++){const n=x+i*d;if(Math.floor(n*p)%Math.floor(u*p)==0)continue;e.beginPath(),e.strokeStyle="black",e.fillStyle="black",e.lineWidth=3/r;let a=t.addVector({x:o.x,y:n},t.multiplyVectorByScalar(h,-25/r));s?e.moveTo(a.x,a.y):e.moveTo(a.x,-a.y),a=t.addVector({x:o.x,y:n},t.multiplyVectorByScalar(h,25/r)),s?e.lineTo(a.x,a.y):e.lineTo(a.x,-a.y),e.font=18/r+"px Helvetica";const c=e.measureText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`);c.fontBoundingBoxAscent,c.fontBoundingBoxDescent,I>2*S&&(e.textAlign="center",e.textBaseline="middle",a=t.addVector(a,{x:c.width/2+.3*c.width,y:0}),s||(a=t.flipYAxis(a)),e.fillText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`,a.x,a.y)),e.stroke()}const k=Math.ceil((P-T)/m);for(let i=0;i<=k;i++){const n=T+i*m;if(Math.floor(n*p)%Math.floor(u*p)==0||Math.floor(n*p)%Math.floor(d*p)==0)continue;e.beginPath(),e.strokeStyle="black",e.fillStyle="black",e.lineWidth=1/r;let a=t.addVector({x:n,y:o.y},t.multiplyVectorByScalar(c,12.5/r));s?e.moveTo(a.x,a.y):e.moveTo(a.x,-a.y),a=t.addVector({x:n,y:o.y},t.multiplyVectorByScalar(c,-12.5/r)),s?e.lineTo(a.x,a.y):e.lineTo(a.x,-a.y),e.font=10/r+"px Helvetica";const h=e.measureText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`);if(B>2*M.width){e.textAlign="center",e.textBaseline="middle";const o=h.fontBoundingBoxAscent+h.fontBoundingBoxDescent;s?a=t.addVector(a,{x:0,y:o/2+.2*o}):(a=t.addVector(a,{x:0,y:-o/2-.2*o}),a=t.flipYAxis(a)),e.fillText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`,a.x,a.y)}e.stroke()}const L=Math.ceil((C-w)/m);for(let i=0;i<=L;i++){const n=w+i*m;if(Math.floor(n*p)%Math.floor(u*p)==0||Math.floor(n*p)%Math.floor(d*p)==0)continue;e.beginPath(),e.strokeStyle="black",e.fillStyle="black",e.lineWidth=1/r;let a=t.addVector({x:o.x,y:n},t.multiplyVectorByScalar(h,-12.5/r));s?e.moveTo(a.x,a.y):e.moveTo(a.x,-a.y),a=t.addVector({x:o.x,y:n},t.multiplyVectorByScalar(h,12.5/r)),s?e.lineTo(a.x,a.y):e.lineTo(a.x,-a.y),e.font=12/r+"px Helvetica";const c=e.measureText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`);c.fontBoundingBoxAscent,c.fontBoundingBoxDescent,B>2*O&&(e.textAlign="center",e.textBaseline="middle",a=t.addVector(a,{x:c.width/2+.3*c.width,y:0}),s||(a=t.flipYAxis(a)),e.fillText(`${Math.abs(n)%1==0?n.toFixed(0):n.toFixed(2)}`,a.x,a.y)),e.stroke()}}function dt(t,e,o,i,n=20,a="red"){n/=o,t.font=20/o+"px Arial",t.fillStyle=a,i?t.fillText(`x: ${e.x.toFixed(2)}, y: ${e.y.toFixed(2)}`,e.x+n,e.y+n):t.fillText(`x: ${e.x.toFixed(2)}, y: ${e.y.toFixed(2)}`,e.x+n,-e.y-n),t.fillStyle="black"}function mt(t,e,o){t.beginPath(),t.strokeStyle="rgba(87, 173, 72, 0.8)",o?t.arc(e.x,e.y,5,0,2*Math.PI):t.arc(e.x,-e.y,5,0,2*Math.PI),t.stroke(),t.strokeStyle="black"}function pt(e,o,i,n,a=1,s=.3){const r=t.distanceBetweenPoints(i,n),h=10<r*o*.5?10/o:.5*r,c=r-h,l=t.linearInterpolation(i,n,c/r);e.beginPath(),e.lineWidth=a/o,e.moveTo(i.x,i.y),e.lineTo(l.x,l.y),e.stroke();const u=t.rotatePoint(t.unitVectorFromA2B(n,i),Math.PI/2),d=t.addVector(l,t.multiplyVectorByScalar(u,.5*h)),m=t.subVector(l,t.multiplyVectorByScalar(u,.5*h));e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(d.x,d.y),e.lineTo(m.x,m.y),e.closePath(),e.fill()}const _t=30,yt=9,ft=15,gt=10,vt=2.5,xt=20,bt=10;function Tt(t,e,o,i,n,a){const{minMajorTickValue:s,maxMajorTickValue:r,majorTickStep:h,minMinTickValue:c,maxMaxTickValue:l,minTickStep:u,minHalfTickValue:d,maxHalfTickValue:m,halfTickStep:p,calibrationMultiplier:_,normalizedOrderOfMagnitude:y}=Ct(e.x,o.x);t.save(),t.strokeStyle="red";for(let o=s;o<=r;o+=h){wt(t,a,{x:o*_,y:e.y},n?_t/a:-30/a,o*_,{textOffset:n?10/a:-10/a,fontSize:20})}for(let o=c;o<=l;o+=u){if(o%h===0)continue;if(o%p===0)continue;wt(t,a,{x:o*_,y:e.y},n?9/a:-9/a,o)}for(let o=d;o<=m;o+=p){if(o%h===0)continue;wt(t,a,{x:o*_,y:e.y},n?15/a:-15/a,o*_,{textOffset:n?vt/a:-2.5/a,fontSize:10,color:"red"})}t.restore();const{minMajorTickValue:f,maxMajorTickValue:g,majorTickStep:v,minMinTickValue:x,maxMaxTickValue:b,minTickStep:T,minHalfTickValue:P,maxHalfTickValue:w,halfTickStep:C,calibrationMultiplier:I}=Ct(e.y,i.y,y);t.save(),t.strokeStyle="green";for(let o=f;o<=g;o+=v){Pt(t,a,{x:e.x,y:o*I},_t/a,o,{textOffset:10/a,fontSize:20})}for(let o=P;o<=w;o+=C){if(o%v===0)continue;Pt(t,a,{x:e.x,y:o*I},15/a,o,{textOffset:vt/a,fontSize:10})}for(let o=x;o<=b;o+=T){if(o%v===0)continue;Pt(t,a,{x:e.x,y:o*I},9/a,o)}t.restore()}function Pt(t,e,o,i,n,a){const s=void 0!==a;if(t.save(),t.lineWidth=1/e,t.beginPath(),t.moveTo(o.x,o.y),t.lineTo(o.x+i,o.y),t.stroke(),t.restore(),!s)return;const r=a.color??"green";t.save(),t.textAlign="left",t.textBaseline="middle",t.fillStyle=r,t.font=a.fontSize/e+"px Arial";const h=n%1==0?n:n.toFixed(2);t.fillText(`${h}`,o.x+i+a.textOffset,o.y),t.restore()}function wt(t,e,o,i,n,a){const s=void 0!==a;if(t.save(),t.lineWidth=1/e,t.beginPath(),t.moveTo(o.x,o.y),t.lineTo(o.x,o.y+i),t.stroke(),t.restore(),!s)return;const r=a.color??"red";t.save(),t.textAlign="center",t.textBaseline="top",t.fillStyle=r,t.font=a.fontSize/e+"px Arial";const h=n%1==0?n:n.toFixed(2);t.fillText(`${h}`,o.x,o.y+i+a.textOffset),t.restore()}function Ct(t,e,o){const i=Math.min(t,e),n=Math.max(t,e),a=o||Q(n-i),s=Math.max(1,a),r=Math.pow(10,s-a),h=(t>0?Math.floor(i*r/Math.pow(10,s)):Math.ceil(i*r/Math.pow(10,s)))*Math.pow(10,s),c=(e>0?Math.floor(n*r/Math.pow(10,s)):Math.ceil(n*r/Math.pow(10,s)))*Math.pow(10,s),l=Math.pow(10,s),u=s-1,d=l/2;return{minMajorTickValue:h,maxMajorTickValue:c,majorTickStep:l,minMinTickValue:(t>0?Math.floor(i*r/Math.pow(10,u)):Math.ceil(i*r/Math.pow(10,u)))*Math.pow(10,u),maxMaxTickValue:(e>0?Math.floor(n*r/Math.pow(10,u)):Math.ceil(n*r/Math.pow(10,u)))*Math.pow(10,u),minTickStep:Math.pow(10,u),minHalfTickValue:(t>0?Math.floor(i*r/d):Math.ceil(i*r/d))*d,maxHalfTickValue:(e>0?Math.floor(n*r/d):Math.ceil(n*r/d))*d,halfTickStep:d,calibrationMultiplier:1/r,normalizedOrderOfMagnitude:s}}function It(t,e,o,i){const n=R(t),a=M(t);if(console.log("width",n),console.log("height",a),null==n||null==a)return;let s=e/Math.abs(n*Math.cos(i)),r=e/Math.abs(a*Math.cos(i)),h=o/Math.abs(n*Math.sin(i)),c=o/Math.abs(a*Math.sin(i));s==1/0&&(s=0),r==1/0&&(r=0),h==1/0&&(h=0),c==1/0&&(c=0);const l=o/a,u=e/n;return Math.max(l,u,s,r,h,c)}function Bt(t,e){return null!=e&&(null==t||e!=1/0&&(void 0!==t&&(null==t.min||e>t.min)))}function Rt(t,e,o,i){const n=R(t);if(null==n)return;const a=Math.abs(n*Math.cos(i)),s=Math.abs(n*Math.sin(i));if(e/a==1/0)return o/s;return Math.max(e/a,o/s)}function St(t,e,o,i){const n=M(t);if(null==n)return;const a=e/Math.abs(n*Math.cos(i)),s=o/Math.abs(n*Math.sin(i));if(s==1/0)return a;return Math.max(a,s)}function Mt(t,e,o){return o.clampZoom?z(t,e.zoomBoundaries):t}function Ot(t,e,o){if(!o.clampZoom)return t;let i=e.zoomLevel+t;return i=z(i,e.zoomBoundaries),t=i-e.zoomLevel}function At(t,e,o){return o.restrictZoom?e.zoomLevel:t}function Et(t,e,o){return o.restrictZoom?0:t}function zt(){return tt(Mt,At)}function Vt(){return tt(Ot,Et)}function kt(){return tt(Zt,Ht)}function Lt(){return tt(Ut,Nt)}function Zt(e,o,i){let n=t.subVector(e,o.position);if(n=Dt(n,o,i),0===n.x&&0===n.y)return e;return t.addVector(o.position,n)}function Ut(t,e,o){return t=Dt(t,e,o)}function Ht(t,e,o){if(!o.clampTranslation)return t;let i=B(t,e.boundaries);return o.limitEntireViewPort&&(i=A(t,e.viewPortWidth,e.viewPortHeight,e.boundaries,e.zoomLevel,e.rotation)),i}function Nt(e,o,i){if(!i.clampTranslation)return e;let n=t.subVector(B(t.addVector(o.position,e),o.boundaries),o.position);return i.limitEntireViewPort&&(n=t.subVector(A(t.addVector(o.position,e),o.viewPortWidth,o.viewPortHeight,o.boundaries,o.zoomLevel,o.rotation),o.position)),n}function Dt(e,o,i){if(i.restrictXTranslation&&i.restrictYTranslation)return{x:0,y:0};if(i.restrictRelativeXTranslation&&i.restrictRelativeYTranslation)return{x:0,y:0};if(i.restrictXTranslation&&(e.x=0),i.restrictYTranslation&&(e.y=0),i.restrictRelativeXTranslation){const i=t.rotatePoint({x:0,y:1},o.rotation),n=t.dotProduct(i,e);e=t.multiplyVectorByScalar(i,n)}if(i.restrictRelativeYTranslation){const i=t.rotatePoint({x:1,y:0},o.rotation),n=t.dotProduct(i,e);e=t.multiplyVectorByScalar(i,n)}return e}function Wt(e,o){return t.multiplyVectorByScalar(t.rotatePoint(e,o.rotation),1/o.zoomLevel)}function Ft(t,e,o){if(!o.clampRotation)return t;const i=k(U(e.rotation+t),e.rotationBoundaries);return H(e.rotation,i)}function qt(t,e,o){return o.restrictRotation?0:t}function jt(t,e,o){if(!o.clampRotation)return t;return k(t,e.rotationBoundaries)}function Gt(t,e,o){return o.restrictRotation?e.rotation:t}function Yt(){return tt(qt,Ft)}function Xt(){return tt(Gt,jt)}class Kt{constructor(){this.nextPosition=null,this.delta={x:0,y:0},this.queuePositionUpdateCount=0,this.queuePositionUpdateToCount=0,this.queuePositionUpdateByCount=0,this.lastUpdateCount=0,this.observable=new n}queuePositionUpdate(t,e){this.queuePositionUpdateCount++,this.queuePositionUpdateTo({x:t,y:e})}queuePositionUpdateTo(t){this.queuePositionUpdateToCount++,this.nextPosition={...t},this.delta={x:0,y:0}}queuePositionUpdateBy(t){this.queuePositionUpdateByCount++,null===this.nextPosition?this.delta={x:this.delta.x+t.x,y:this.delta.y+t.y}:this.nextPosition={x:this.nextPosition.x+t.x,y:this.nextPosition.y+t.y}}processQueuedUpdates(){if(this.lastUpdateCount=this.queuePositionUpdateCount+this.queuePositionUpdateToCount+this.queuePositionUpdateByCount,this.queuePositionUpdateCount=0,this.queuePositionUpdateToCount=0,this.queuePositionUpdateByCount=0,null!==this.nextPosition){const t={...this.nextPosition,type:"destination"};return this.nextPosition=null,this.delta={x:0,y:0},this.observable.notify(t),t}if(0!==this.delta.x||0!==this.delta.y){const t={...this.delta,type:"delta"};return this.delta={x:0,y:0},this.observable.notify(t),t}return null}subscribe(t,e){return this.observable.subscribe(t,e)}getDebugInfo(){return{lastUpdateTotalCalls:this.lastUpdateCount,queuePositionUpdateCalls:this.queuePositionUpdateCount,queuePositionUpdateToCalls:this.queuePositionUpdateToCount,queuePositionUpdateByCalls:this.queuePositionUpdateByCount}}}class $t{constructor(){this.nextRotation=null,this.delta=0,this.queueRotationUpdateCount=0,this.queueRotationUpdateToCount=0,this.queueRotationUpdateByCount=0,this.lastUpdateCount=0,this.observable=new n}queueRotationUpdate(t){this.queueRotationUpdateCount++,this.queueRotationUpdateTo(t)}queueRotationUpdateTo(t){this.queueRotationUpdateToCount++,this.nextRotation=t,this.delta=0}queueRotationUpdateBy(t){this.queueRotationUpdateByCount++,null===this.nextRotation?this.delta=this.delta+t:this.nextRotation=this.nextRotation+t}processQueuedUpdates(){if(this.lastUpdateCount=this.queueRotationUpdateCount+this.queueRotationUpdateToCount+this.queueRotationUpdateByCount,this.queueRotationUpdateCount=0,this.queueRotationUpdateToCount=0,this.queueRotationUpdateByCount=0,null!==this.nextRotation){const t={destination:this.nextRotation,type:"destination"};return this.nextRotation=null,this.delta=0,this.observable.notify(t),t}if(0!==this.delta){const t={delta:this.delta,type:"delta"};return this.delta=0,this.observable.notify(t),t}return null}subscribe(t,e){return this.observable.subscribe(t,e)}getDebugInfo(){return{lastUpdateTotalCalls:this.lastUpdateCount,queueRotationUpdateCalls:this.queueRotationUpdateCount,queueRotationUpdateToCalls:this.queueRotationUpdateToCount,queueRotationUpdateByCalls:this.queueRotationUpdateByCount}}}class Jt{constructor(){this.nextZoom=null,this.anchor=null,this.delta=0,this.anchorCoordinateSystem="viewport",this.queueZoomUpdateCount=0,this.queueZoomUpdateToCount=0,this.lastUpdateCount=0,this.observable=new n}queueZoomUpdateTo(t,e){"world"===this.anchorCoordinateSystem&&(this.anchorCoordinateSystem="viewport",this.nextZoom=null,this.delta=0),this.anchor=e??null,this.nextZoom=t,0!==this.delta&&(this.delta=0)}queueZoomUpdateBy(t,e){"world"===this.anchorCoordinateSystem&&(this.anchorCoordinateSystem="viewport",this.nextZoom=null,this.delta=0),null===this.nextZoom?this.delta+=t:this.nextZoom+=t,this.anchor=e??null}queueZoomByAtWorld(t,e){"viewport"===this.anchorCoordinateSystem&&(this.anchorCoordinateSystem="world",this.nextZoom=null,this.delta=0),this.anchor=e,null===this.nextZoom?this.delta+=t:this.nextZoom+=t}queueZoomToAtWorld(t,e){"viewport"===this.anchorCoordinateSystem&&(this.anchorCoordinateSystem="world",this.nextZoom=null,this.delta=0),this.anchor=e,this.nextZoom=t,0!==this.delta&&(this.delta=0)}processQueuedUpdates(){if(null===this.nextZoom&&0===this.delta)return null;const t=this.delta,e=this.nextZoom,o=this.anchor;return this.delta=0,this.nextZoom=null,this.anchor=null,0!==t?{anchorCoordinateSystem:this.anchorCoordinateSystem,update:{type:"delta",delta:t,anchor:o??void 0}}:{anchorCoordinateSystem:this.anchorCoordinateSystem,update:{type:"destination",destination:e??0,anchor:o??void 0}}}subscribe(t,e){return this.observable.subscribe(t,e)}getDebugInfo(){return{lastUpdateTotalCalls:this.lastUpdateCount,queueZoomUpdateCalls:this.queueZoomUpdateCount,queueZoomUpdateToCalls:this.queueZoomUpdateToCount}}}class Qt{constructor(t,e=new X){this._panBy=Lt(),this._panTo=kt(),this._zoomTo=zt(),this._zoomBy=Vt(),this._rotateBy=Yt(),this._rotateTo=Xt(),this._config={...t,restrictRotation:!1,clampRotation:!0},this._camera=e,this._positionBatcher=new Kt,this._zoomBatcher=new Jt,this._rotationBatcher=new $t}zoomToAt(t,e){this._zoomBatcher.queueZoomUpdateTo(t,e)}zoomByAt(t,e){this._zoomBatcher.queueZoomUpdateBy(t,e)}zoomTo(t){this._zoomBatcher.queueZoomUpdateTo(t)}zoomBy(t){this._zoomBatcher.queueZoomUpdateBy(t)}zoomToAtWorld(t,e){this._zoomBatcher.queueZoomToAtWorld(t,e)}zoomByAtWorld(t,e){this._zoomBatcher.queueZoomByAtWorld(t,e)}_actualPanByWorld(e){const o=this._panBy(e,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,o))}_actualPanToWorld(t){const e=this._panTo(t,this._camera,this._config);this._camera.setPosition(e)}panByWorld(t){this._positionBatcher.queuePositionUpdateBy(t)}panByViewPort(e){const o=t.multiplyVectorByScalar(t.rotatePoint(e,this._camera.rotation),1/this._camera.zoomLevel);this._positionBatcher.queuePositionUpdateBy(o)}panToWorld(t){this._positionBatcher.queuePositionUpdateTo(t)}panToViewPort(t){const e=this._camera.convertFromViewPort2WorldSpace(t);this._positionBatcher.queuePositionUpdateTo(e)}rotateBy(t){this._rotationBatcher.queueRotationUpdateBy(t)}rotateTo(t){this._rotationBatcher.queueRotationUpdateTo(t)}set limitEntireViewPort(t){this._config.limitEntireViewPort=t}get limitEntireViewPort(){return this._config.limitEntireViewPort}get camera(){return this._camera}get config(){return this._config}set config(t){this._config={...t}}updatePosition(){const t=this._positionBatcher.processQueuedUpdates();if(null!=t)switch(t.type){case"destination":this._actualPanToWorld(t);break;case"delta":this._actualPanByWorld(t);break;default:throw new Error("Invalid position update type")}}updateZoom(){const t=this._zoomBatcher.processQueuedUpdates();if(null!=t)if("world"===t.anchorCoordinateSystem)switch(t.update.type){case"destination":if(t.update.anchor)this._zoomToAtWorld(t.update.destination,t.update.anchor);else{const e=this._zoomTo(t.update.destination,this._camera,this._config);this._camera.setZoomLevel(e)}break;case"delta":if(t.update.anchor)this._zoomByAtWorld(t.update.delta,t.update.anchor);else{const e=this._zoomBy(t.update.delta,this._camera,this._config);this._camera.setZoomLevel(this._camera.zoomLevel+e)}}else switch(t.update.type){case"destination":if(t.update.anchor)this._zoomToAtViewPort(t.update.destination,t.update.anchor);else{const e=this._zoomTo(t.update.destination,this._camera,this._config);this._camera.setZoomLevel(e)}break;case"delta":if(t.update.anchor)this._zoomByAtViewPort(t.update.delta,t.update.anchor);else{const e=this._zoomBy(t.update.delta,this._camera,this._config);this._camera.setZoomLevel(this._camera.zoomLevel+e)}}}updateRotation(){const t=this._rotationBatcher.processQueuedUpdates();if(null!=t)switch(t.type){case"destination":const e=this._rotateTo(t.destination,this._camera,this._config);this._camera.setRotation(e);break;case"delta":const o=this._rotateBy(t.delta,this._camera,this._config);this._camera.setRotation(this._camera.rotation+o);break;default:throw new Error("Invalid rotation update type")}}update(){this.updateZoom(),this.updatePosition(),this.updateRotation()}_zoomToAtViewPort(e,o){const i=this._camera.convertFromViewPort2WorldSpace(o),n=this._zoomTo(e,this._camera,this._config);this._camera.setZoomLevel(n);const a=this._camera.convertFromViewPort2WorldSpace(o),s=t.subVector(i,a),r=this._panBy(s,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,r))}_zoomToAtWorld(e,o){let i=this._camera.convertFromWorld2ViewPort(o);const n=this._zoomTo(e,this._camera,this._config);this._camera.setZoomLevel(n);let a=this._camera.convertFromWorld2ViewPort(o);const s=t.subVector(i,a),r=this._panBy(s,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,r))}_zoomByAtViewPort(e,o){const i=this._camera.convertFromViewPort2WorldSpace(o),n=this._zoomBy(e,this._camera,this._config);this._camera.setZoomLevel(this._camera.zoomLevel+n);const a=this._camera.convertFromViewPort2WorldSpace(o),s=t.subVector(i,a),r=this._panBy(s,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,r))}_zoomByAtWorld(e,o){let i=this._camera.convertFromWorld2ViewPort(o);const n=this._zoomBy(e,this._camera,this._config);this._camera.setZoomLevel(this._camera.zoomLevel+n);let a=this._camera.convertFromWorld2ViewPort(o);const s=v(t.subVector(i,a),this._camera.zoomLevel,this._camera.rotation),r=this._panBy(s,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,r))}configure(t){this._config={...this._config,...t}}cleanup(){}setup(){}}function te(t){return new Qt({limitEntireViewPort:!0,restrictRelativeXTranslation:!1,restrictRelativeYTranslation:!1,restrictXTranslation:!1,restrictYTranslation:!1,restrictZoom:!1,clampTranslation:!0,clampZoom:!0},t)}class ee{constructor(t,e=new X){this._panBy=Lt(),this._panTo=kt(),this._zoomTo=zt(),this._zoomBy=Vt(),this._rotateBy=Yt(),this._rotateTo=Xt(),this._config={...t,restrictRotation:!1,clampRotation:!0},this._camera=e}zoomToAt(e,o){let i=this._camera.convertFromViewPort2WorldSpace(o);const n=this._zoomTo(e,this._camera,this._config);this._camera.setZoomLevel(n);let a=this._camera.convertFromViewPort2WorldSpace(o);const s=t.subVector(i,a),r=this._panBy(s,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,r))}zoomByAt(e,o){const i=e*this._camera.zoomLevel;let n=this._camera.convertFromViewPort2WorldSpace(o);const a=this._zoomBy(i,this._camera,this._config);this._camera.setZoomLevel(this._camera.zoomLevel+a);let s=this._camera.convertFromViewPort2WorldSpace(o);const r=t.subVector(n,s),h=this._panBy(r,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,h))}zoomTo(t){this._zoomTo(t,this._camera,this._config)}zoomBy(t){this._zoomBy(t,this._camera,this._config)}zoomToAtWorld(e,o){let i=this._camera.convertFromWorld2ViewPort(o);const n=this._zoomTo(e,this._camera,this._config);this._camera.setZoomLevel(n);let a=this._camera.convertFromWorld2ViewPort(o);const s=v(t.subVector(a,i),this._camera.zoomLevel,this._camera.rotation),r=this._panBy(s,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,r))}zoomByAtWorld(e,o){let i=this._camera.convertFromWorld2ViewPort(o);const n=this._zoomBy(e,this._camera,this._config);this._camera.setZoomLevel(this._camera.zoomLevel+n);let a=this._camera.convertFromWorld2ViewPort(o);const s=v(t.subVector(a,i),this._camera.zoomLevel,this._camera.rotation),r=this._panBy(s,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,r))}panByViewPort(e){const o=t.multiplyVectorByScalar(t.rotatePoint(e,this._camera.rotation),1/this._camera.zoomLevel);this.panByWorld(o)}panByWorld(e){const o=this._panBy(e,this._camera,this._config);this._camera.setPosition(t.addVector(this._camera.position,o))}panToWorld(t){const e=this._panTo(t,this._camera,this._config);this._camera.setPosition(e)}panToViewPort(t){const e=this._camera.convertFromViewPort2WorldSpace(t);this.panToWorld(e)}rotateBy(t){const e=this._rotateBy(t,this._camera,this._config);this._camera.setRotation(this._camera.rotation+e)}rotateTo(t){const e=this._rotateTo(t,this._camera,this._config);this._camera.setRotation(e)}set limitEntireViewPort(t){this._config.limitEntireViewPort=t}get limitEntireViewPort(){return this._config.limitEntireViewPort}get camera(){return this._camera}set camera(t){this._camera=t}get config(){return this._config}set config(t){this._config={...t}}configure(t){this._config={...this._config,...t}}cleanup(){}setup(){}update(){}}function oe(t){return new ee({limitEntireViewPort:!0,restrictRelativeXTranslation:!1,restrictRelativeYTranslation:!1,restrictXTranslation:!1,restrictYTranslation:!1,restrictZoom:!1,clampTranslation:!0,clampZoom:!0},t)}class ie{constructor(t=oe(new X)){this._cameraRig=t}notifyPanInput(t){this._cameraRig.panByViewPort(t)}notifyZoomInput(t,e){this._cameraRig.zoomByAt(t,e)}notifyRotationInput(t){this._cameraRig.rotateBy(t)}}function ne(t){const e=oe(t);return new ie(e)}function ae(t){return new ie(t)}class se extends e{constructor(t,e,o){super(t,e,o)}notifyPanInput(t){this.happens("userPanByInput",{diff:t})}notifyPanToAnimationInput(t){this.happens("transitionPanToInput",{target:t})}initateTransition(){this.happens("initateTransition")}set limitEntireViewPort(t){this._context.limitEntireViewPort=t}get limitEntireViewPort(){return this._context.limitEntireViewPort}}class re extends o{constructor(){super(),this.eventReactions={userPanByInput:{action:this.userPanByInputHandler,defaultTargetState:"ACCEPTING_USER_INPUT"},userPanToInput:{action:this.userPanToInputHandler,defaultTargetState:"ACCEPTING_USER_INPUT"},lockedOnObjectPanByInput:{action:this.lockedOnObjectPanByInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"},lockedOnObjectPanToInput:{action:this.lockedOnObjectPanToInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"},initateTransition:{action:i,defaultTargetState:"TRANSITION"}}}userPanByInputHandler(t,e){t.panByViewPort(e.diff)}userPanToInputHandler(t,e){t.panToWorld(e.target)}lockedOnObjectPanByInputHandler(t,e){t.panByViewPort(e.diff)}lockedOnObjectPanToInputHandler(t,e){t.panToWorld(e.target)}}class he extends o{constructor(){super(),this.eventReactions={userPanByInput:{action:this.userPanByInputHandler,defaultTargetState:"ACCEPTING_USER_INPUT"},userPanToInput:{action:this.userPanToInputHandler,defaultTargetState:"ACCEPTING_USER_INPUT"},transitionPanByInput:{action:this.transitionPanByInputHandler,defaultTargetState:"TRANSITION"},transitionPanToInput:{action:this.transitionPanToInputHandler,defaultTargetState:"TRANSITION"},lockedOnObjectPanByInput:{action:this.lockedOnObjectPanByInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"},lockedOnObjectPanToInput:{action:this.lockedOnObjectPanToInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"}}}userPanByInputHandler(t,e){return t.panByViewPort(e.diff),"ACCEPTING_USER_INPUT"}userPanToInputHandler(t,e){return t.panToWorld(e.target),"ACCEPTING_USER_INPUT"}transitionPanByInputHandler(t,e){return t.panByViewPort(e.diff),"TRANSITION"}transitionPanToInputHandler(t,e){return t.panToWorld(e.target),"TRANSITION"}lockedOnObjectPanByInputHandler(t,e){return t.panByViewPort(e.diff),"LOCKED_ON_OBJECT"}lockedOnObjectPanToInputHandler(t,e){return t.panToWorld(e.target),"LOCKED_ON_OBJECT"}}class ce extends o{constructor(){super(),this.eventReactions={unlock:{action:i,defaultTargetState:"ACCEPTING_USER_INPUT"},lockedOnObjectPanByInput:{action:this.lockedOnObjectPanByInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"},lockedOnObjectPanToInput:{action:this.lockedOnObjectPanToInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"}}}lockedOnObjectPanByInputHandler(t,e){t.panByViewPort(e.diff)}lockedOnObjectPanToInputHandler(t,e){t.panToWorld(e.target)}}function le(){return{ACCEPTING_USER_INPUT:new re,TRANSITION:new he,LOCKED_ON_OBJECT:new ce}}function ue(t){return new se(le(),"ACCEPTING_USER_INPUT",t)}class de extends o{constructor(){super(...arguments),this._eventReactions={userZoomByAtInput:{action:this.userZoomByAtInput,defaultTargetState:"ACCEPTING_USER_INPUT"},userZoomToAtInput:{action:this.userZoomToAtInput,defaultTargetState:"ACCEPTING_USER_INPUT"},initiateTransition:{action:i,defaultTargetState:"TRANSITION"}}}get eventReactions(){return this._eventReactions}userZoomByAtInput(t,e){t.zoomByAt(e.deltaZoom,e.anchorPoint)}userZoomToAtInput(t,e){t.zoomToAt(e.targetZoom,e.anchorPoint)}}class me extends o{constructor(){super(),this._eventReactions={lockedOnObjectZoomByAtInput:{action:this.lockedOnObjectZoomByAtInput,defaultTargetState:"LOCKED_ON_OBJECT"},lockedOnObjectZoomToAtInput:{action:this.lockedOnObjectZoomToAtInput,defaultTargetState:"LOCKED_ON_OBJECT"},transitionZoomByAtInput:{action:this.transitionZoomByAtInput,defaultTargetState:"TRANSITION"},transitionZoomToAtInput:{action:this.transitionZoomToAtInput,defaultTargetState:"TRANSITION"},transitionZoomToAtCenterInput:{action:this.transitionZoomToAtCenterInput,defaultTargetState:"TRANSITION"},transitionZoomToAtWorldInput:{action:this.transitionZoomToAtWorldInput,defaultTargetState:"TRANSITION"},userZoomByAtInput:{action:this.userZoomByAtInput,defaultTargetState:"ACCEPTING_USER_INPUT"},userZoomToAtInput:{action:this.userZoomToAtInput,defaultTargetState:"ACCEPTING_USER_INPUT"}}}get eventReactions(){return this._eventReactions}lockedOnObjectZoomByAtInput(t,e){t.zoomBy(e.deltaZoom)}lockedOnObjectZoomToAtInput(t,e){t.zoomTo(e.targetZoom)}userZoomByAtInput(t,e){t.zoomByAt(e.deltaZoom,e.anchorPoint)}userZoomToAtInput(t,e){t.zoomToAt(e.targetZoom,e.anchorPoint)}transitionZoomByAtInput(t,e){t.zoomByAt(e.deltaZoom,e.anchorPoint)}transitionZoomByAtCenterInput(t,e){t.zoomBy(e.deltaZoom)}transitionZoomToAtInput(t,e){t.zoomToAt(e.targetZoom,e.anchorPoint)}transitionZoomToAtCenterInput(t,e){t.zoomTo(e.targetZoom)}transitionZoomToAtWorldInput(t,e){t.zoomToAtWorld(e.targetZoom,e.anchorPoint)}}class pe extends o{constructor(){super(),this._eventReactions={lockedOnObjectZoomByAtInput:{action:this.lockedOnObjectZoomByAtInput,defaultTargetState:"LOCKED_ON_OBJECT"},lockedOnObjectZoomToAtInput:{action:this.lockedOnObjectZoomToAtInput,defaultTargetState:"LOCKED_ON_OBJECT"},userZoomByAtInput:{action:this.userZoomByAtInput,defaultTargetState:"ACCEPTING_USER_INPUT"},userZoomToAtInput:{action:this.userZoomToAtInput,defaultTargetState:"ACCEPTING_USER_INPUT"}}}get eventReactions(){return this._eventReactions}lockedOnObjectZoomByAtInput(t,e){t.zoomByAt(e.deltaZoom,e.anchorPoint)}lockedOnObjectZoomToAtInput(t,e){t.zoomToAt(e.targetZoom,e.anchorPoint)}userZoomByAtInput(t,e){t.zoomByAt(e.deltaZoom,e.anchorPoint)}userZoomToAtInput(t,e){t.zoomToAt(e.targetZoom,e.anchorPoint)}}class _e extends e{constructor(t,e,o){super(t,e,o)}notifyZoomByAtInput(t,e){this.happens("userZoomByAtInput",{deltaZoom:t,anchorPoint:e})}notifyZoomByAtInputAnimation(t,e){this.happens("transitionZoomByAtInput",{deltaZoom:t,anchorPoint:e})}notifyZoomToAtCenterInput(t,e){this.happens("transitionZoomToAtCenterInput",{targetZoom:t,anchorPoint:e})}notifyZoomToAtWorldInput(t,e){this.happens("transitionZoomToAtWorldInput",{targetZoom:t,anchorPoint:e})}initateTransition(){this.happens("initiateTransition")}}function ye(){return{ACCEPTING_USER_INPUT:new de,TRANSITION:new me,LOCKED_ON_OBJECT:new pe}}function fe(t){return new _e(ye(),"ACCEPTING_USER_INPUT",t)}class ge extends e{constructor(t,e,o){super(t,e,o)}notifyRotateByInput(t){this.happens("userRotateByInput",{diff:t})}notifyRotateToAnimationInput(t){this.happens("transitionRotateToInput",{target:t})}initateTransition(){this.happens("initateTransition")}}class ve extends o{constructor(){super(),this.eventReactions={userRotateByInput:{action:this.userRotateByInputHandler,defaultTargetState:"ACCEPTING_USER_INPUT"},userRotateToInput:{action:this.userRotateToInputHandler,defaultTargetState:"ACCEPTING_USER_INPUT"},lockedOnObjectRotateByInput:{action:this.lockedOnObjectRotateByInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"},lockedOnObjectRotateToInput:{action:this.lockedOnObjectRotateToInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"},initateTransition:{action:i,defaultTargetState:"TRANSITION"}}}userRotateByInputHandler(t,e){t.rotateBy(e.diff)}userRotateToInputHandler(t,e){t.rotateTo(e.target)}lockedOnObjectRotateByInputHandler(t,e){t.rotateBy(e.diff)}lockedOnObjectRotateToInputHandler(t,e){t.rotateTo(e.target)}}class xe extends o{constructor(){super(),this.eventReactions={userRotateByInput:{action:this.userRotateByInputHandler,defaultTargetState:"ACCEPTING_USER_INPUT"},userRotateToInput:{action:this.userRotateToInputHandler,defaultTargetState:"ACCEPTING_USER_INPUT"},transitionRotateByInput:{action:this.transitionRotateByInputHandler,defaultTargetState:"TRANSITION"},transitionRotateToInput:{action:this.transitionRotateToInputHandler,defaultTargetState:"TRANSITION"},lockedOnObjectRotateByInput:{action:this.lockedOnObjectRotateByInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"},lockedOnObjectRotateToInput:{action:this.lockedOnObjectRotateToInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"}}}userRotateByInputHandler(t,e){return t.rotateBy(e.diff),"ACCEPTING_USER_INPUT"}userRotateToInputHandler(t,e){return t.rotateTo(e.target),"ACCEPTING_USER_INPUT"}transitionRotateByInputHandler(t,e){return t.rotateBy(e.diff),"TRANSITION"}transitionRotateToInputHandler(t,e){return t.rotateTo(e.target),"TRANSITION"}lockedOnObjectRotateByInputHandler(t,e){return t.rotateBy(e.diff),"LOCKED_ON_OBJECT"}lockedOnObjectRotateToInputHandler(t,e){return t.rotateTo(e.target),"LOCKED_ON_OBJECT"}}class be extends o{constructor(){super(),this.eventReactions={unlock:{action:i,defaultTargetState:"ACCEPTING_USER_INPUT"},lockedOnObjectRotateByInput:{action:this.lockedOnObjectRotateByInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"},lockedOnObjectRotateToInput:{action:this.lockedOnObjectRotateToInputHandler,defaultTargetState:"LOCKED_ON_OBJECT"}}}lockedOnObjectRotateByInputHandler(t,e){t.rotateBy(e.diff)}lockedOnObjectRotateToInputHandler(t,e){t.rotateTo(e.target)}}function Te(){return{ACCEPTING_USER_INPUT:new ve,TRANSITION:new xe,LOCKED_ON_OBJECT:new be}}function Pe(t){return new ge(Te(),"ACCEPTING_USER_INPUT",t)}class we{constructor(t,e,o){this._panStateMachine=t,this._zoomStateMachine=e,this._rotateStateMachine=o}notifyPanToAnimationInput(t){this._panStateMachine.notifyPanToAnimationInput(t)}notifyPanInput(t){this._panStateMachine.notifyPanInput(t)}notifyZoomInput(t,e){this._zoomStateMachine.notifyZoomByAtInput(t,e)}notifyRotateByInput(t){this._rotateStateMachine.notifyRotateByInput(t)}notifyRotateToAnimationInput(t){this._rotateStateMachine.notifyRotateToAnimationInput(t)}notifyZoomInputAnimation(t,e={x:0,y:0}){this._zoomStateMachine.notifyZoomToAtCenterInput(t,e)}notifyZoomInputAnimationWorld(t,e={x:0,y:0}){this._zoomStateMachine.notifyZoomToAtWorldInput(t,e)}notifyRotationInput(t){console.error("Rotation input is not implemented")}initatePanTransition(){this._panStateMachine.initateTransition()}initateZoomTransition(){this._zoomStateMachine.initateTransition()}initateRotateTransition(){this._rotateStateMachine.initateTransition()}get rotateStateMachine(){return this._rotateStateMachine}get panStateMachine(){return this._panStateMachine}get zoomStateMachine(){return this._zoomStateMachine}}function Ce(t){const e=oe(t),o=ue(e),i=fe(e),n=Pe(e);return new we(o,i,n)}function Ie(t){const e=ue(t),o=fe(t),i=Pe(t);return new we(e,o,i)}class Be{constructor(t){this.pan=new n,this.zoom=new n,this.rotate=new n,this.all=new n,this._cameraMux=t}notifyPan(t){this._cameraMux.notifyPanInput(t),this.pan.notify({diff:t}),this.all.notify({type:"pan",diff:t})}notifyZoom(t,e){this._cameraMux.notifyZoomInput(t,e),this.zoom.notify({deltaZoomAmount:t,anchorPoint:e}),this.all.notify({type:"zoom",deltaZoomAmount:t,anchorPoint:e})}notifyRotate(t){this._cameraMux.notifyRotationInput(t),this.rotate.notify({deltaRotation:t}),this.all.notify({type:"rotate",deltaRotation:t})}on(t,e){switch(t){case"pan":return this.pan.subscribe(e);case"zoom":return this.zoom.subscribe(e);case"rotate":return this.rotate.subscribe(e);case"all":return this.all.subscribe(e);default:throw new Error("Invalid raw user input event name")}}get cameraMux(){return this._cameraMux}set cameraMux(t){this._cameraMux=t}}function Re(t){return new Be(ne(t))}class Se{constructor(t){this.pan=new n,this.zoom=new n,this.rotate=new n,this.all=new n,this.webWorker=t}notifyPan(t){this.webWorker.postMessage({type:"notifyUserInput",payload:{type:"pan",diff:t}}),this.pan.notify({diff:t}),this.all.notify({type:"pan",diff:t})}notifyZoom(t,e){this.webWorker.postMessage({type:"notifyUserInput",payload:{type:"zoom",deltaZoomAmount:t,anchorPoint:e}}),this.zoom.notify({deltaZoomAmount:t,anchorPoint:e}),this.all.notify({type:"zoom",deltaZoomAmount:t,anchorPoint:e})}notifyRotate(t){this.webWorker.postMessage({type:"notifyUserInput",payload:{type:"rotate",deltaRotation:t}}),this.rotate.notify({deltaRotation:t}),this.all.notify({type:"rotate",deltaRotation:t})}on(t,e){switch(t){case"pan":return this.pan.subscribe(e);case"zoom":return this.zoom.subscribe(e);case"rotate":return this.rotate.subscribe(e);case"all":return this.all.subscribe(e);default:throw new Error("Invalid raw user input event name")}}}var Me;!function(t){t.GRAB="grab",t.DEFAULT="default",t.GRABBING="grabbing"}(Me||(Me={}));class Oe{constructor(){this.width=0,this.height=0,this.position={x:0,y:0},this.setCursor=i,this.dimensions={width:0,height:0,position:{x:0,y:0}},this.detached=!1,this.tearDown=i}}class Ae{constructor(t){this._width=0,this._height=0,this._position={x:0,y:0},this._postMessageFunction=t}get dimensions(){return{width:this._width,height:this._height,position:this._position}}tearDown(){}set width(t){this._width=t}set height(t){this._height=t}set position(t){this._position=t}get width(){return this._width}get height(){return this._height}get position(){return this._position}setCursor(t){this._postMessageFunction({type:"setCursor",style:t})}get detached(){return!1}}class Ee{constructor(t){if(this._width=0,this._height=0,this._position={x:0,y:0},this._internalSizeUpdateObservable=new a,t){const e=ot(t.getBoundingClientRect(),window.getComputedStyle(t));this._width=e.width,this._height=e.height,this._position={x:e.left,y:e.top},this._canvas=t}this._canvasPositionDimensionPublisher=new et(t),this._canvasPositionDimensionPublisher.onPositionUpdate(t=>{null!=this._canvas?(this._width=t.width,this._height=t.height,this._position={x:t.left,y:t.top},this._internalSizeUpdateObservable.notify({width:this._width,height:this._height,position:this._position})):console.log("is not attached to any canvas should not have getting any updates")})}subscribe(t,e){return this._internalSizeUpdateObservable.subscribe(t,e)}notify(...t){this._internalSizeUpdateObservable.notify(...t)}get detached(){return void 0===this._canvas}get dimensions(){return{width:this._width,height:this._height,position:this._position}}get width(){return this._width}setWidth(t){this._canvas&&(this._canvas.width=t*window.devicePixelRatio,this._canvas.style.width=t+"px")}setHeight(t){this._canvas&&(this._canvas.height=t*window.devicePixelRatio,this._canvas.style.height=t+"px")}get height(){return this._height}get position(){return this._position}setCursor(t){this._canvas&&(this._canvas.style.cursor=t)}tearDown(){this._canvasPositionDimensionPublisher.dispose()}attach(t){this._canvasPositionDimensionPublisher.attach(t),this._canvas=t;const e=ot(t.getBoundingClientRect(),window.getComputedStyle(t));this._canvas.width=e.width*window.devicePixelRatio,this._canvas.height=e.height*window.devicePixelRatio,this._canvas.style.width=e.width+"px",this._canvas.style.height=e.height+"px",this._width=e.width,this._height=e.height,this._position={x:e.left,y:e.top},this._internalSizeUpdateObservable.notify({width:this._width,height:this._height,position:this._position})}logCanvasTrueSize(){void 0!==this._canvas&&(console.log("canvas true size"),console.log("style width",this._canvas.style.width),console.log("style height",this._canvas.style.height),console.log("width",this._canvas.width),console.log("height",this._canvas.height),console.log("proxy width",this._width),console.log("proxy height",this._height))}}class ze{constructor(t,e,o){const i=t.getBoundingClientRect();this._canvas=t,this._webWorker=e;const n=ot(i,window.getComputedStyle(t));this._width=n.width,this._height=n.height,this._position={x:n.left,y:n.top},this._webWorker.postMessage({type:"setCanvasDimensions",width:i.width,height:i.height,position:{x:i.left,y:i.top}}),o.onPositionUpdate(t=>{this._width=t.width,this._height=t.height,this._position={x:t.left,y:t.top},this._webWorker.postMessage({type:"updateCanvasDimensions",width:t.width,height:t.height,position:{x:t.left,y:t.top}})}),this._canvasDiemsionPublisher=o}get width(){return this._width}get height(){return this._height}tearDown(){this._canvasDiemsionPublisher.dispose()}get position(){return this._position}get dimensions(){return{width:this._width,height:this._height,position:this._position}}get detached(){return!1}setCursor(t){this._canvas.style.cursor=t}}class Ve{constructor(){this.alignCoordinateSystem=!1,this.canvas=new Oe,this.initialCursorPosition={x:0,y:0},this.toggleOnEdgeAutoCameraInput=i,this.toggleOffEdgeAutoCameraInput=i,this.setCursorPosition=i}notifyOnPan(t){}notifyOnZoom(t,e){}notifyOnRotate(t){}setInitialCursorPosition(t){}cleanup(){}setup(){}cancelCurrentAction(){}}class ke{constructor(t,e,o){this._padding=50,this._alignCoordinateSystem=!0,this._canvasOperator=t,this._inputPublisher=e,this._initialCursorPosition={x:0,y:0},this._edgeAutoCameraInput=o}get alignCoordinateSystem(){return this._alignCoordinateSystem}get canvas(){return this._canvasOperator}get initialCursorPosition(){return this._initialCursorPosition}set alignCoordinateSystem(t){this._alignCoordinateSystem=t}notifyOnPan(t){this._inputPublisher.notifyPan(t)}notifyOnZoom(t,e){this._inputPublisher.notifyZoom(t,e)}notifyOnRotate(t){this._inputPublisher.notifyRotate(t)}cancelCurrentAction(){this._initialCursorPosition={x:0,y:0}}setInitialCursorPosition(t){this._initialCursorPosition=t}toggleOnEdgeAutoCameraInput(){this._edgeAutoCameraInput.toggleOn()}toggleOffEdgeAutoCameraInput(){this._edgeAutoCameraInput.toggleOff()}setCursorPosition(t){if(function(t,e,o){return t.x<=e.left+o||t.x>=e.left+e.width-o||t.y<=e.top+o||t.y>=e.top+e.height-o}(t,{left:this._canvasOperator.dimensions.position.x,top:this._canvasOperator.dimensions.position.y,width:this._canvasOperator.dimensions.width,height:this._canvasOperator.dimensions.height},this._padding)){const e=function(t,e,o){if(t.x<=e.left+o)return"left";if(t.x>=e.left+e.width-o)return"right";return"none"}(t,{left:this._canvasOperator.dimensions.position.x,top:this._canvasOperator.dimensions.position.y,width:this._canvasOperator.dimensions.width,height:this._canvasOperator.dimensions.height},this._padding),o=function(t,e,o){if(t.y<=e.top+o)return"up";if(t.y>=e.top+e.height-o)return"down";return"none"}(t,{left:this._canvasOperator.dimensions.position.x,top:this._canvasOperator.dimensions.position.y,width:this._canvasOperator.dimensions.width,height:this._canvasOperator.dimensions.height},this._padding);this._edgeAutoCameraInput.setDirection(e,o)}else this._edgeAutoCameraInput.setDirection("none","none")}cleanup(){}setup(){}}class Le{constructor(t,e){this._touchPointsMap=new Map,this._canvas=t,this._inputPublisher=e,this._alignCoordinateSystem=!0}addTouchPoints(t){t.forEach(t=>{this._touchPointsMap.set(t.ident,{...t})})}removeTouchPoints(t){t.forEach(t=>{this._touchPointsMap.has(t)&&this._touchPointsMap.delete(t)})}getCurrentTouchPointsCount(){return this._touchPointsMap.size}getInitialTouchPointsPositions(t){const e=[];return t.forEach(t=>{if(this._touchPointsMap.has(t)){const o=this._touchPointsMap.get(t);o&&e.push(o)}}),e}updateTouchPoints(t){t.forEach(t=>{this._touchPointsMap.has(t.ident)&&this._touchPointsMap.set(t.ident,{...t})})}notifyOnPan(t){this._inputPublisher.notifyPan(t)}notifyOnZoom(t,e){this._inputPublisher.notifyZoom(t,e)}get alignCoordinateSystem(){return this._alignCoordinateSystem}set alignCoordinateSystem(t){this._alignCoordinateSystem=t}get canvas(){return this._canvas}cleanup(){}setup(){}}class Ze extends o{constructor(){super(...arguments),this._eventReactions={touchstart:{action:this.touchstart,defaultTargetState:"IDLE"},touchend:{action:this.touchend,defaultTargetState:"IDLE"}},this._guards={touchPointsCount:(t=>2===t.getCurrentTouchPointsCount()).bind(this)},this._eventGuards={touchstart:[{guard:"touchPointsCount",target:"PENDING"}],touchend:[{guard:"touchPointsCount",target:"PENDING"}]}}get eventReactions(){return this._eventReactions}touchstart(t,e){t.addTouchPoints(e.points)}touchend(t,e){t.removeTouchPoints(e.points.map(t=>t.ident))}}class Ue extends o{constructor(){super(...arguments),this._eventReactions={touchstart:{action:this.touchstart,defaultTargetState:"IDLE"},touchend:{action:this.touchend,defaultTargetState:"IDLE"},touchmove:{action:this.touchmove,defaultTargetState:"IN_PROGRESS"}}}get eventReactions(){return this._eventReactions}touchstart(t,e){t.addTouchPoints(e.points)}touchend(t,e){t.removeTouchPoints(e.points.map(t=>t.ident))}touchmove(e,o){const i=o.points.map(t=>t.ident),n=e.getInitialTouchPointsPositions(i),a=o.points,s=t.distanceBetweenPoints(n[0],n[1]),r=t.distanceBetweenPoints(a[0],a[1]),h=t.linearInterpolation(n[0],n[1],.5),c=t.linearInterpolation(a[0],a[1],.5),l=t.subVector(h,c),u={x:e.canvas.position.x+e.canvas.width/2,y:e.canvas.position.y+e.canvas.height/2},d=t.subVector(h,u);let m=Math.abs(r-s)>t.distanceBetweenPoints(h,c)?"ZOOMING":"PANNING";switch(e.updateTouchPoints(a),m){case"ZOOMING":e.notifyOnZoom(.005*(r-s),d);break;case"PANNING":e.notifyOnPan(l);break;default:console.warn("Unknown panZoom state",m)}}}class He extends o{constructor(){super(...arguments),this._eventReactions={touchmove:{action:this.touchmove,defaultTargetState:"IN_PROGRESS"},touchend:{action:this.touchend,defaultTargetState:"IDLE"},touchstart:{action:()=>"IDLE",defaultTargetState:"IDLE"}}}get eventReactions(){return this._eventReactions}touchmove(e,o){const i=o.points.map(t=>t.ident),n=e.getInitialTouchPointsPositions(i),a=o.points,s=t.distanceBetweenPoints(n[0],n[1]),r=t.distanceBetweenPoints(a[0],a[1]),h=t.linearInterpolation(n[0],n[1],.5),c=t.linearInterpolation(a[0],a[1],.5),l=t.subVector(h,c),u={x:e.canvas.position.x+e.canvas.width/2,y:e.canvas.position.y+e.canvas.height/2},d=t.subVector(h,u);let m=Math.abs(r-s)>t.distanceBetweenPoints(h,c)?"ZOOMING":"PANNING";switch(e.updateTouchPoints(a),m){case"ZOOMING":e.alignCoordinateSystem||(d.y=-d.y),e.notifyOnZoom(.005*-(s-r),d);break;case"PANNING":e.alignCoordinateSystem||(l.y=-l.y),e.notifyOnPan(l);break;default:console.warn("Unknown panZoom state",m)}}touchend(t,e){t.removeTouchPoints(e.points.map(t=>t.ident))}}function Ne(t){return new e({IDLE:new Ze,PENDING:new Ue,IN_PROGRESS:new He},"IDLE",t)}function De(e,o){const i=o.getBoundingClientRect(),n={x:i.left+(i.right-i.left)/2,y:i.top+(i.bottom-i.top)/2};return t.subVector(e,n)}function We(e,o){const i={x:o.position.x+o.width/2,y:o.position.y+o.height/2};return t.subVector(e,i)}function Fe(e,o){const i={x:o.position.x+o.width/2,y:o.position.y+o.height/2};return t.subVector(e,i)}class qe extends o{constructor(){super(),this._guards={isIdle:()=>!0},this._eventGuards={},this._eventReactions={spacebarDown:{action:this.spacebarDownHandler,defaultTargetState:"READY_TO_PAN_VIA_SPACEBAR"},scroll:{action:this.scrollHandler,defaultTargetState:"IDLE"},scrollWithCtrl:{action:this.scrollWithCtrlHandler,defaultTargetState:"IDLE"},middlePointerDown:{action:this.middlePointerDownHandler,defaultTargetState:"READY_TO_PAN_VIA_SCROLL_WHEEL"},disable:{action:i,defaultTargetState:"DISABLED"},pointerMove:{action:this.pointerMoveHandler,defaultTargetState:"IDLE"}}}get eventReactions(){return this._eventReactions}uponEnter(t){t.canvas.setCursor(Me.DEFAULT)}scrollHandler(t,e){const o={...e};t.alignCoordinateSystem||(o.deltaY=-o.deltaY),t.notifyOnPan({x:o.deltaX,y:o.deltaY})}scrollWithCtrlHandler(t,e){let o=.005;Math.abs(e.deltaY)>100&&(o=5e-4);const i=e.deltaY*o,n=Fe({x:e.x,y:e.y},t.canvas);t.alignCoordinateSystem||(n.y=-n.y),t.notifyOnZoom(-5*i,n)}spacebarDownHandler(t,e){}middlePointerDownHandler(t,e){t.setInitialCursorPosition({x:e.x,y:e.y})}pointerMoveHandler(t,e){t.setCursorPosition(e)}}class je extends o{constructor(){super(),this.leftPointerMove=((t,e)=>{const o=De({x:e.x,y:e.y},t.canvas);t.setSelectionEndPoint(o),t.toggleSelectionBox(!0)}).bind(this),this._eventReactions={leftPointerUp:{action:()=>"IDLE",defaultTargetState:"IDLE"},leftPointerMove:{action:this.leftPointerMove,defaultTargetState:"SELECTING"},disable:{action:i,defaultTargetState:"DISABLED"}}}get eventReactions(){return this._eventReactions}}class Ge extends o{constructor(){super()}uponEnter(t){t.canvas.setCursor(Me.DEFAULT),t.toggleOnEdgeAutoCameraInput()}beforeExit(t){t.toggleOffEdgeAutoCameraInput()}get eventReactions(){return{enable:{action:i,defaultTargetState:"IDLE"},pointerMove:{action:(t,e)=>{t.setCursorPosition({x:e.x,y:e.y})}}}}}class Ye extends o{constructor(){super(),this._eventReactions={spacebarUp:{action:i,defaultTargetState:"IDLE"},leftPointerDown:{action:this.leftPointerDownHandler,defaultTargetState:"INITIAL_PAN"},disable:{action:t=>t.cancelCurrentAction(),defaultTargetState:"DISABLED"},leftPointerMove:{action:i,defaultTargetState:"READY_TO_PAN_VIA_SPACEBAR"}}}uponEnter(t){t.canvas.setCursor(Me.GRAB)}get eventReactions(){return this._eventReactions}leftPointerDownHandler(t,e){t.setInitialCursorPosition({x:e.x,y:e.y})}}class Xe extends o{constructor(){super(),this._eventReactions={leftPointerUp:{action:i,defaultTargetState:"READY_TO_PAN_VIA_SPACEBAR"},leftPointerMove:{action:this.leftPointerMoveHandler,defaultTargetState:"PAN"},spacebarUp:{action:()=>"IDLE",defaultTargetState:"IDLE"},leftPointerDown:{action:()=>"PAN",defaultTargetState:"PAN"}}}get eventReactions(){return this._eventReactions}uponEnter(t){t.canvas.setCursor(Me.GRABBING)}leftPointerMoveHandler(t,e){const o={x:t.initialCursorPosition.x-e.x,y:t.initialCursorPosition.y-e.y};t.alignCoordinateSystem||(o.y=-o.y),t.notifyOnPan(o),t.setInitialCursorPosition({x:e.x,y:e.y})}}class Ke extends o{constructor(){super(),this._eventReactions={middlePointerUp:{action:i,defaultTargetState:"IDLE"},middlePointerMove:{action:i,defaultTargetState:"PAN_VIA_SCROLL_WHEEL"}}}get eventReactions(){return this._eventReactions}uponEnter(t){t.canvas.setCursor(Me.GRABBING)}}class $e extends o{constructor(){super(),this._eventReactions={leftPointerUp:{action:i,defaultTargetState:"READY_TO_PAN_VIA_SPACEBAR"},leftPointerMove:{action:this.leftPointerMoveHandler,defaultTargetState:"PAN"},spacebarUp:{action:i,defaultTargetState:"IDLE"}}}get eventReactions(){return this._eventReactions}uponEnter(t){t.canvas.setCursor(Me.GRABBING)}beforeExit(t){t.canvas.setCursor(Me.DEFAULT)}leftPointerMoveHandler(t,e){const o={x:t.initialCursorPosition.x-e.x,y:t.initialCursorPosition.y-e.y};t.alignCoordinateSystem||(o.y=-o.y),t.notifyOnPan(o),t.setInitialCursorPosition({x:e.x,y:e.y})}}class Je extends o{constructor(){super(...arguments),this._eventReactions={middlePointerUp:{action:i,defaultTargetState:"IDLE"},middlePointerMove:{action:this.middlePointerMoveHandler,defaultTargetState:"PAN_VIA_SCROLL_WHEEL"}}}get eventReactions(){return this._eventReactions}middlePointerMoveHandler(t,e){const o={x:t.initialCursorPosition.x-e.x,y:t.initialCursorPosition.y-e.y};t.alignCoordinateSystem||(o.y=-o.y),t.notifyOnPan(o),t.setInitialCursorPosition({x:e.x,y:e.y})}uponEnter(t){t.canvas.setCursor(Me.GRABBING)}}class Qe extends o{constructor(){super()}get eventReactions(){return{}}}function to(t){const o={IDLE:new qe,READY_TO_PAN_VIA_SPACEBAR:new Ye,INITIAL_PAN:new Xe,PAN:new $e,READY_TO_PAN_VIA_SCROLL_WHEEL:new Ke,PAN_VIA_SCROLL_WHEEL:new Je,DISABLED:new Ge};return new e(o,"IDLE",t)}class eo extends e{constructor(t){super({IDLE:new Qe,READY_TO_PAN_VIA_SPACEBAR:new Qe,INITIAL_PAN:new Qe,PAN:new Qe,READY_TO_PAN_VIA_SCROLL_WHEEL:new Qe,PAN_VIA_SCROLL_WHEEL:new Qe,DISABLED:new Ge},"IDLE",new Ve),this._webworker=t}happens(...t){return this._webworker.postMessage({type:"kmtInputStateMachine",event:t[0],payload:t[1]}),{handled:!0,nextState:"IDLE"}}}class oo{constructor(t){this._state="idle",this._speed=100,this._horizontalDirection="none",this._verticalDirection="none",this._cameraMux=t}toggleOff(){this._state="idle"}toggleOn(){this._state="moving"}setDirection(t,e){this._horizontalDirection=t,this._verticalDirection=e}update(e){if("idle"===this._state)return;const o={x:"left"===this._horizontalDirection?-1:"right"===this._horizontalDirection?1:0,y:"up"===this._verticalDirection?-1:"down"===this._verticalDirection?1:0},i=this._speed*e,n=t.multiplyVectorByScalar(o,i);this._cameraMux.notifyPanInput(n)}}class io{constructor(t,e=!1){this._alignCoordinateSystem=!0,this._fullScreen=!1,this._canvasSizeUpdateQueue=void 0,this.lastUpdateTime=0;const o=new X,i=5e4;o.boundaries={min:{x:-5e4,y:-5e4},max:{x:i,y:i}},this.bindFunctions(),this._canvasProxy=new Ee(t),this._canvasProxy.subscribe(t=>{this._canvasSizeUpdateQueue=t}),this.cameraRig=new ee({limitEntireViewPort:!0,restrictRelativeXTranslation:!1,restrictRelativeYTranslation:!1,restrictXTranslation:!1,restrictYTranslation:!1,restrictZoom:!1,clampTranslation:!0,clampZoom:!0},o),this.boardInputPublisher=new Be(Ie(this.cameraRig)),this._edgeAutoCameraInput=new oo(this.boardInputPublisher.cameraMux),this._observableInputTracker=new ke(this._canvasProxy,this.boardInputPublisher,this._edgeAutoCameraInput),this._touchInputTracker=new Le(this._canvasProxy,this.boardInputPublisher);const n=to(this._observableInputTracker),a=Ne(this._touchInputTracker);this._kmtParser=new K(n,t),this._touchParser=new $(a,t),null!=t&&(console.log("canvas exists on creation of board"),this.attach(t,e),this.syncViewPortDimensions({width:t.width,height:t.height}))}syncViewPortDimensions(t){this.camera.viewPortHeight=t.height,this.camera.viewPortWidth=t.width}attach(t,e=!1){const o=t.getContext("2d",{willReadFrequently:e});null!=o?(this._kmtParser.attach(t),this._touchParser.attach(t),this._canvasProxy.attach(t),this.limitEntireViewPort&&this.syncCameraZoomLevel(this._canvasProxy.dimensions),this._context=o,this._reversedContext=at(this._context)):console.error("new canvas context is null")}tearDown(){this._kmtParser.tearDown(),this._touchParser.tearDown(),this._canvasProxy.tearDown()}bindFunctions(){this.step=this.step.bind(this)}get width(){return this._canvasProxy.width}get height(){return this._canvasProxy.height}set alignCoordinateSystem(t){this._alignCoordinateSystem=t,this._observableInputTracker.alignCoordinateSystem=t,this._touchInputTracker.alignCoordinateSystem=t}get alignCoordinateSystem(){return this._alignCoordinateSystem}get fullScreen(){return this._fullScreen}set fullScreen(t){this._fullScreen=t,this._fullScreen&&(this._canvasProxy.setWidth(window.innerWidth),this._canvasProxy.setHeight(window.innerHeight))}get context(){return this._alignCoordinateSystem?this._context:this._reversedContext}set limitEntireViewPort(t){this.cameraRig.limitEntireViewPort=t,this._canvasProxy.detached||t&&this.syncCameraZoomLevel(this._canvasProxy.dimensions)}get limitEntireViewPort(){return this.cameraRig.limitEntireViewPort}set kmtParser(t){this._kmtParser.tearDown(),t.setUp(),this._kmtParser=t}get kmtParser(){return this._kmtParser}set touchParser(t){this._touchParser.tearDown(),t.setUp(),this._touchParser=t}get touchParser(){return this._touchParser}get camera(){return this.cameraRig.camera}set camera(t){this._canvasProxy.detached||(t.viewPortHeight=this._canvasProxy.height/window.devicePixelRatio,t.viewPortWidth=this._canvasProxy.width/window.devicePixelRatio),this.cameraRig.camera=t}get cameraMux(){return this.boardInputPublisher.cameraMux}set cameraMux(t){this.boardInputPublisher.cameraMux=t}get cameraMovementOnMouseEdge(){return this._edgeAutoCameraInput}step(t){if(this._canvasProxy.detached||null==this._context)return;this.cameraRig.update();let e=t-this.lastUpdateTime;this.lastUpdateTime=t,e/=1e3,this._context.reset(),this._context.clearRect(0,0,this._canvasProxy.width*window.devicePixelRatio,this._canvasProxy.height*window.devicePixelRatio),!this._fullScreen||this._canvasProxy.width==window.innerWidth&&this._canvasProxy.height==window.innerHeight||(this._canvasProxy.setWidth(window.innerWidth),this._canvasProxy.setHeight(window.innerHeight)),null!=this._canvasSizeUpdateQueue&&(this.syncViewPortDimensions(this._canvasSizeUpdateQueue),this.syncCameraZoomLevel(this._canvasSizeUpdateQueue),this._canvasSizeUpdateQueue=void 0),this._edgeAutoCameraInput.update(e);const o=this.camera.getTransform(window.devicePixelRatio,this._alignCoordinateSystem);this._context.setTransform(o.a,o.b,o.c,o.d,o.e,o.f)}convertWindowPoint2WorldCoord(e){const o=this._canvasProxy.dimensions,i={x:o.position.x+o.width/2,y:o.position.y+o.height/2},n=t.subVector(e,i);return this._alignCoordinateSystem||(n.y=-n.y),this.camera.convertFromViewPort2WorldSpace(n)}on(t,e){return this.camera.on(t,e)}onInput(t,e){return this.boardInputPublisher.on(t,e)}get maxHalfTransHeight(){return O(this.camera.boundaries)}get maxHalfTransWidth(){return S(this.camera.boundaries)}syncCameraZoomLevel(t){if(this.limitEntireViewPort){const e=It(this.camera.boundaries,t.width,t.height,this.camera.rotation);console.log("canvasDimensions",t),console.log("zoom boundaries",this.camera.zoomBoundaries),console.log("boundaries",this.camera.boundaries),console.log("targetMinZoomLevel",e),null!=e&&Bt(this.camera.zoomBoundaries,e)&&this.camera.setMinZoomLevel(e)}}setMaxTransWidthWithFixedMinBoundary(t){const e=this.camera.boundaries,o=null==e?void 0:e.min,i=null==o?void 0:o.x;if(null==i?this.camera.setHorizontalBoundaries(-t,t):this.camera.setHorizontalBoundaries(i,i+2*t),this.limitEntireViewPort){const t=Rt(this.camera.boundaries,this.camera.viewPortWidth,this.camera.viewPortHeight,this.camera.rotation);Bt(this.camera.zoomBoundaries,t)&&this.camera.setMinZoomLevel(t)}}setMaxTransWidthWithFixedMaxBoundary(t){const e=this.camera.boundaries,o=null==e?void 0:e.max,i=null==o?void 0:o.x;if(null==i?this.camera.setHorizontalBoundaries(-t,t):this.camera.setHorizontalBoundaries(i-2*t,i),this.limitEntireViewPort){const t=Rt(this.camera.boundaries,this.camera.viewPortWidth,this.camera.viewPortHeight,this.camera.rotation);Bt(this.camera.zoomBoundaries,t)&&this.camera.setMinZoomLevel(t)}}get restrictRelativeXTranslation(){return this.cameraRig.config.restrictRelativeXTranslation}get restrictRelativeYTranslation(){return this.cameraRig.config.restrictRelativeYTranslation}get restrictXTranslation(){return this.cameraRig.config.restrictXTranslation}get restrictYTranslation(){return this.cameraRig.config.restrictYTranslation}set restrictRelativeXTranslation(t){this.cameraRig.config.restrictRelativeXTranslation=t}set restrictRelativeYTranslation(t){this.cameraRig.configure({restrictRelativeYTranslation:t})}set restrictXTranslation(t){this.cameraRig.configure({restrictXTranslation:t})}set restrictYTranslation(t){this.cameraRig.configure({restrictYTranslation:t})}get restrictZoom(){return this.cameraRig.config.restrictZoom}set restrictZoom(t){this.cameraRig.configure({restrictZoom:t})}get restrictRotation(){return this.cameraRig.config.restrictRotation}set restrictRotation(t){this.cameraRig.configure({restrictRotation:t})}get clampTranslation(){return this.cameraRig.config.clampTranslation}set clampTranslation(t){this.cameraRig.configure({clampTranslation:t})}get clampZoom(){return this.cameraRig.config.clampZoom}set clampZoom(t){this.cameraRig.configure({clampZoom:t})}get clampRotation(){return this.cameraRig.config.clampRotation}set clampRotation(t){this.cameraRig.configure({clampRotation:t})}getCameraRig(){return this.cameraRig}}export{re as AcceptingUserInputState,n as AsyncObservable,io as Board,we as CameraMuxWithAnimationAndLock,Kt as CameraPositionUpdateBatcher,Qt as CameraRigWithUpdateBatcher,$t as CameraRotationUpdateBatcher,s as CameraUpdatePublisher,Jt as CameraZoomUpdateBatcher,Ae as CanvasCacheInWebWorker,et as CanvasPositionDimensionPublisher,Ee as CanvasProxy,Me as CursorStyle,G as DEFAULT_BOARD_CAMERA_BOUNDARIES,Y as DEFAULT_BOARD_CAMERA_ROTATION_BOUNDARIES,q as DEFAULT_BOARD_CAMERA_VIEWPORT_HEIGHT,F as DEFAULT_BOARD_CAMERA_VIEWPORT_WIDTH,j as DEFAULT_BOARD_CAMERA_ZOOM_BOUNDARIES,X as DefaultBoardCamera,ee as DefaultCameraRig,Ge as DisabledState,Oe as DummyCanvas,Ve as DummyKmtInputContext,oo as EdgeAutoCameraInput,ft as HALF_TICK_LENGTH,Ze as IdleState,He as InProgressState,Xe as InitialPanState,Qe as KmtEmptyState,qe as KmtIdleState,eo as KmtInputStateMachineWebWorkerProxy,ce as LockedOnObjectState,_t as MAJOR_TICK_LENGTH,yt as MINOR_TICK_LENGTH,ke as ObservableInputTracker,se as PanControlStateMachine,$e as PanState,Je as PanViaScrollWheelState,Ue as PendingState,Be as RawUserInputPublisher,Se as RawUserInputPublisherWithWebWorkerRelay,Ke as ReadyToPanViaScrollWheelState,Ye as ReadyToPanViaSpaceBarState,je as ReadyToSelectState,ie as Relay,ge as RotateControlStateMachine,ve as RotationAcceptingUserInputState,be as RotationLockedOnObjectState,xe as RotationTransitionState,a as SynchronousObservable,bt as TEXT_HALF_TICK_FONT_SIZE,vt as TEXT_HALF_TICK_OFFSET,xt as TEXT_MAJOR_TICK_FONT_SIZE,gt as TEXT_MAJOR_TICK_OFFSET,Le as TouchInputTracker,he as TransitionState,K as VanillaKMTEventParser,$ as VanillaTouchEventParser,ze as WorkerRelayCanvas,de as ZoomAcceptingUserInputState,_e as ZoomControlStateMachine,pe as ZoomLockedOnObjectState,me as ZoomTransitionState,H as angleSpan,I as boundariesFullyDefined,Q as calculateOrderOfMagnitude,Ct as calculateTickValues,b as cameraPositionToGet,Nt as clampByHandler,B as clampPoint,A as clampPointEntireViewPort,Ft as clampRotateByHandler,jt as clampRotateToHandler,k as clampRotation,Ht as clampToHandler,Ot as clampZoomByHandler,z as clampZoomLevel,Mt as clampZoomToHandler,y as convert2ViewPortSpaceAnchorAtCenter,p as convert2WorldSpace,_ as convert2WorldSpaceAnchorAtCenter,m as convert2WorldSpaceWRT,P as convert2WorldSpaceWithTransformationMatrix,v as convertDeltaInViewPortToWorldSpace,x as convertDeltaInWorldToViewPortSpace,Dt as convertDeltaToComplyWithRestriction,De as convertFromWindow2ViewPort,Fe as convertFromWindow2ViewPortCanvasOperator,We as convertFromWindow2ViewPortWithCanvasOperator,Wt as convertUserInputDeltaToCameraDelta,h as createCameraMatrix,Ce as createCameraMuxWithAnimationAndLock,Ie as createCameraMuxWithAnimationAndLockWithCameraRig,ne as createDefaultCameraMux,ae as createDefaultCameraMuxWithCameraRig,oe as createDefaultCameraRig,te as createDefaultCameraRigWithUpdateBatcher,Lt as createDefaultPanByHandler,ue as createDefaultPanControlStateMachine,le as createDefaultPanControlStates,kt as createDefaultPanToHandler,Re as createDefaultRawUserInputPublisher,Yt as createDefaultRotateByHandler,Pe as createDefaultRotateControlStateMachine,Te as createDefaultRotateControlStates,Xt as createDefaultRotateToHandler,Vt as createDefaultZoomByOnlyHandler,fe as createDefaultZoomControlStateMachine,ye as createDefaultZoomControlStates,zt as createDefaultZoomToOnlyHandler,tt as createHandlerChain,to as createKmtInputStateMachine,u as createTRSMatrix,Ne as createTouchInputStateMachine,r as decomposeCameraMatrix,l as decomposeTRS,d as decomposeTRSSVD,N as deg2rad,pt as drawArrow,ct as drawAxis,ht as drawBoundingBox,rt as drawCrossHair,lt as drawGrid,dt as drawPositionText,mt as drawReferenceCircle,Tt as drawRuler,ut as drawRulerLegacy,ot as getTrueRect,O as halfTranslationHeightOf,S as halfTranslationWidthOf,f as invertFromWorldSpace,st as invertYAxisForDrawImageWith9Args,C as isValidBoundaries,E as isValidZoomLevelLimits,It as minZoomLevelBaseOnDimensions,St as minZoomLevelBaseOnHeight,Rt as minZoomLevelBaseOnWidth,c as multiplyMatrix,U as normalizeAngleZero2TwoPI,J as pointConversion,g as pointIsInViewPort,D as rad2deg,Ut as restrictPanByHandler,Zt as restrictPanToHandler,qt as restrictRotateByHandler,Gt as restrictRotateToHandler,Et as restrictZoomByHandler,At as restrictZoomToHandler,at as reverseYAxis,Z as rotationWithinBoundary,L as rotationWithinLimits,T as transformationMatrixFromCamera,M as translationHeightOf,R as translationWidthOf,w as withinBoundaries,Bt as zoomLevelBoundariesShouldUpdate,V as zoomLevelWithinLimits};
2
2
  //# sourceMappingURL=index.js.map