"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const X=1e4;function T(i,t={}){i.style.imageRendering="pixelated";const o=t.container??i.parentNode,a=t.onResize??(()=>{}),s=t.downscale??1;let c=null,r=null,l=null;function u(g){let{width:n,height:h}=o.getBoundingClientRect?.()??{width:o.clientWidth,height:o.clientHeight};if(n=n*g/s,h=h*g/s,D(n,.001)&&D(h,.001)?(n=Math.round(n),h=Math.round(h)):(n=Math.ceil(n),h=Math.ceil(h)),!(n===c&&h===r&&g===l)){if(c=n,r=h,l=g,n>X||h>X)throw new Error(`Prevented resizing canvas to ${n}x${h}; is the container missing "overflow: hidden" or "width"/"height"?`);i.width=n,i.height=h,i.style.width=`${n/g*s}px`,i.style.height=`${h/g*s}px`,a(i,n,h)}}let x=L(i,g=>{u(g)}),d=new ResizeObserver(g=>{u(window.devicePixelRatio??1)});return d.observe(o,{box:"border-box"}),setTimeout(()=>{u(window.devicePixelRatio??1)},0),function(){d&&(d.disconnect(),d=null),x&&(x(),x=null)}}function L(i,t,e=!1){let o=!0,a;function s(){let c=window.devicePixelRatio??1;(c*100).toFixed(0),!o&&e&&t(c,i),o=!1,a=matchMedia(`(resolution: ${c}dppx)`),a.addEventListener("change",s,{once:!0})}return s(),function(){a.removeEventListener("change",s)}}function R(i){return new C(i)}function m(i,t={}){const e=new Map,o=t.downscale??1;let a=null,s=[];function c(){return window.devicePixelRatio??1}function r(n,h,_){return[(_.clientX-n.x)*h/o,(_.clientY-n.y)*h/o]}function l(n){t.preventDefault&&n.preventDefault();let h=c(),_=i.getBoundingClientRect();const[S,p]=r(_,h,n);let f={x:S,y:p,click_x:S,click_y:p,dx:0,dy:0,type:n.pointerType,id:n.pointerId,buttons:n.buttons,pressure:n.pressure,coalesced:[]};e.set(n.pointerId,f),t.onDown?.(f,e)}function u(n){t.preventDefault&&n.preventDefault();let h=c(),_=i.getBoundingClientRect();const[S,p]=r(_,h,n);if(e.has(n.pointerId)){let f=z(e,n.pointerId);f.dx=S-f.x,f.dy=p-f.y,f.x=S,f.y=p,f.coalesced=n.getCoalescedEvents().map(y=>{const[M,v]=r(_,h,y);return{x:M,y:v,pressure:y.pressure}}),f.pressure=n.pressure,a===null&&(a=setTimeout(()=>{try{t.onMove?.(s,e)}finally{s=[],a=null}},0)),s.push(f)}}function x(n){t.preventDefault&&n.preventDefault();let h=e.get(n.pointerId);if(!h)return;let _=c(),S=i.getBoundingClientRect(),p=(n.clientX-S.x)*_/o,f=(n.clientY-S.y)*_/o;h.dx=p-h.x,h.dy=f-h.y,h.x=p,h.y=f,h.coalesced=n.getCoalescedEvents().map(y=>{const[M,v]=r(S,_,y);return{x:M,y:v,pressure:y.pressure}}),h.pressure=n.pressure,e.delete(n.pointerId),t.onUp?.(h,e)}function d(n){const h=e.get(n.pointerId);e.delete(n.pointerId),t.onUp?.(h,e)}i.addEventListener("pointerdown",l),i.addEventListener("pointermove",u),i.addEventListener("pointerup",x),i.addEventListener("pointerout",x),i.addEventListener("pointercancel",d);function g(n){n.preventDefault()}return t.preventDefault&&i.addEventListener("touchmove",g,{passive:!1}),function(){i.removeEventListener("pointerdown",l),i.removeEventListener("pointermove",u),i.removeEventListener("pointup",x),i.removeEventListener("pointercancel",d),t.preventDefault&&i.removeEventListener("touchmove",g,{passive:!1})}}class P{constructor(t){this.dx=t?.dx||0,this.dy=t?.dy||0,this.logScale=t?.scale?Math.log2(t.scale):0,this.logMinScale=t?.minScale?Math.log2(t.minScale):-1/0,this.logMaxScale=t?.maxScale?Math.log2(t.maxScale):1/0,this.lastValues=[0,0,1],this.round=t.round}_getValues(t,e=0,o=0){let a=0,s=0,c=0,r=0;for(const d of t.values())a+=d.x,s+=d.y,c+=d.x*d.x,r+=d.y*d.y;const l=t.size;if(l<=1)return[a-e,s-o,1];const u=c/(l-1)-a*a/(l*(l-1)),x=r/(l-1)-s*s/(l*(l-1));return[a/l-e,s/l-o,Math.sqrt(u+x)]}get scale(){return Math.pow(2,this.logScale)}getState(t=0,e=0){return this.round?new Y(Math.round(this.dx+t),Math.round(this.dy+e),this.logScale):new Y(this.dx+t,this.dy+e,this.logScale)}move(t,e=0,o=0){const a=this._getValues(t,e,o);let s=Math.log2(a[2]/this.lastValues[2]);(Number.isNaN(s)||!Number.isFinite(s))&&(s=0);const c=this.logScale;this.logScale+=s,this.logScale<=this.logMinScale&&(this.logScale=this.logMinScale),this.logScale>=this.logMaxScale&&(this.logScale=this.logMaxScale);const r=Math.pow(2,this.logScale-c);this.dx=(this.dx-this.lastValues[0])*r+a[0],this.dy=(this.dy-this.lastValues[1])*r+a[1],this.lastValues=a}zoom(t,e=0,o=0){const a=this.logScale;this.logScale+=Math.log2(t),this.logScale<=this.logMinScale&&(this.logScale=this.logMinScale),this.logScale>=this.logMaxScale&&(this.logScale=this.logMaxScale);const s=Math.pow(2,this.logScale-a);this.dx=(this.dx-e)*s+e,this.dy=(this.dy-o)*s+o}update(t,e=0,o=0){this.lastValues=this._getValues(t,e,o)}}class Y{constructor(t,e,o){this.dx=t,this.dy=e,this.logScale=o,this.scale=Math.pow(2,o)}get(t,e){return[t*this.scale+this.dx,e*this.scale+this.dy]}inverse(t,e){return[(t-this.dx)/this.scale,(e-this.dy)/this.scale]}}function I(i,t){const e=new P(t),o=t?.wheelSensitivity??.005,a=t?.emSize??12,s=t?.pageSize??t?.emSize??12;setTimeout(()=>t?.onUpdate?.(e.getState()),0);const c=m(i,{downscale:t.downscale,preventDefault:!0,onDown(l,u){e.update(u)},onUp(l,u){e.update(u)},onMove(l,u){e.move(u),t?.onUpdate?.(e.getState())}}),r=i.addEventListener("wheel",l=>{const u=window.devicePixelRatio||1,x=i.getBoundingClientRect();let d=-l.deltaY;l.deltaMode===WheelEvent.DOM_DELTA_LINE?d*=a:l.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(d*=s),e.zoom(Math.pow(2,d*o*u),(l.clientX-x.x)*u,(l.clientY-x.y)*u),t?.onUpdate?.(e.getState())});return function(){i.removeEventListener(r),c()}}const w=Object.freeze({DEFAULT:0,INSIDE:1,OUTSIDE:2});class C{constructor(t){if(this.canvas=t,this.context=t.getContext("2d"),!this.context)throw new Error("Couldn't get 2d canvas context");this.context.imageSmoothingEnabled=!1,this._scaleX=this.context.getTransform().m11,this._scaleY=this.context.getTransform().m22,this._lineWidth=this.context.lineWidth}get fillStyle(){return this.context.fillStyle}set fillStyle(t){this.context.fillStyle=t}get strokeStyle(){return this.context.strokeStyle}set strokeStyle(t){this.context.strokeStyle=t}get lineWidth(){return this.context.lineWidth}set lineWidth(t){this.context.lineWidth=t}lineWidthDelta(t=w.DEFAULT){return t===w.INSIDE?[this.context.lineWidth/2*this._scaleX,this.context.lineWidth/2*this._scaleY]:t===w.OUTSIDE?[this.context.lineWidth/-2*this._scaleX,this.context.lineWidth/-2*this._scaleY]:[E(this.context.lineWidth/2*this._scaleX),E(this.context.lineWidth/2*this._scaleY)]}get perfectLineWidth(){const t=Math.round(this.context.lineWidth*this._scaleX)/this._scaleX,e=Math.round(this.context.lineWidth*this._scaleY)/this._scaleY;return this._scaleX===this._scaleY||b(t*this._scaleY)