pts 1.0.0 → 1.0.1

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.
package/dist/pts.min.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*! Copyright © 2017-present William Ngan and contributors.
2
2
  Licensed under Apache 2.0 License.
3
3
  See https://github.com/williamngan/pts for details. */
4
- (function(){var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r},n=t({Circle:()=>s,Curve:()=>u,Line:()=>a,Polygon:()=>l,Rectangle:()=>o,Triangle:()=>c});let r=(e,t=`expected`)=>C.warn(`Group's length is less than `+t,e),i=(e,t=``)=>C.warn(`Index ${t} is out of bound in Group`,e);var a=class e{static fromAngle(e,t,n){let r=new E(new T(e),new T(e));return r[1].toAngle(t,n,!0),r}static slope(e,t){return t[0]-e[0]===0?void 0:(t[1]-e[1])/(t[0]-e[0])}static intercept(e,t){if(t[0]-e[0]!==0){let n=(t[1]-e[1])/(t[0]-e[0]),r=e[1]-n*e[0];return{slope:n,yi:r,xi:n===0?void 0:-r/n}}}static sideOfPt2D(e,t){let n=C.iterToArray(e);return(n[1][0]-n[0][0])*(t[1]-n[0][1])-(t[0]-n[0][0])*(n[1][1]-n[0][1])}static collinear(e,t,n,r=.01){let i=new T(0,0,0).to(e).$subtract(t),a=new T(0,0,0).to(e).$subtract(n),o=i.magnitudeSq()*a.magnitudeSq();return o===0||i.$cross(a).magnitudeSq()/o<=r*r}static magnitude(e){let t=C.iterToArray(e);return t.length>=2?t[1].$subtract(t[0]).magnitude():0}static magnitudeSq(e){let t=C.iterToArray(e);return t.length>=2?t[1].$subtract(t[0]).magnitudeSq():0}static perpendicularFromPt(e,t,n=!1){let r=C.iterToArray(e);if(r[0].equals(r[1]))return;let i=r[0].$subtract(r[1]),a=r[1].$subtract(t),o=a.$subtract(i.$project(a));return n?o:o.$add(t)}static distanceFromPt(t,n){let r=C.iterToArray(t),i=e.perpendicularFromPt(r,n,!0);return i?i.magnitude():r[0].$subtract(n).magnitude()}static intersectRay2D(e,t){let n=C.iterToArray(e),r=C.iterToArray(t),i=n[0],a=r[0],o=n[1][0]-i[0],s=n[1][1]-i[1],c=r[1][0]-a[0],l=r[1][1]-a[1];if(o===0&&s===0||c===0&&l===0)return;let u=o*l-s*c;if(u===0){let e=a[0]-i[0],t=a[1]-i[1];return e*s-t*o===0?new T(i[0],i[1]):void 0}let d=((a[0]-i[0])*l-(a[1]-i[1])*c)/u;return new T(i[0]+d*o,i[1]+d*s)}static intersectLine2D(t,n){let r=C.iterToArray(t),i=C.iterToArray(n),a=e.intersectRay2D(r,i);return a&&v.withinBound(a,r[0],r[1])&&v.withinBound(a,i[0],i[1])?a:void 0}static intersectLineWithRay2D(t,n){let r=C.iterToArray(t),i=C.iterToArray(n),a=e.intersectRay2D(r,i);return a&&v.withinBound(a,r[0],r[1])?a:void 0}static intersectPolygon2D(t,n,r=!1){let i=C.iterToArray(t),a=C.iterToArray(n),o=r?e.intersectLineWithRay2D:e.intersectLine2D,s=new E;for(let e=0,t=a.length;e<t;e++){let n=e===t-1?0:e+1,r=o([a[e],a[n]],i);r&&s.push(r)}return s.length>0?s:void 0}static intersectLines2D(t,n,r=!1){let i=new E,a=r?e.intersectLineWithRay2D:e.intersectLine2D;for(let e of t)for(let t of n){let n=a(e,t);n&&i.push(n)}return i}static intersectGridWithRay2D(t,n){let r=C.iterToArray(t),i=e.intercept(new T(r[0]).subtract(n),new T(r[1]).subtract(n)),a=new E;return i&&i.xi!==void 0&&a.push(new T(n[0]+i.xi,n[1])),i&&i.yi!==void 0&&a.push(new T(n[0],n[1]+i.yi)),a}static intersectGridWithLine2D(t,n){let r=C.iterToArray(t),i=e.intersectGridWithRay2D(r,n),a=new E;for(let e=0,t=i.length;e<t;e++)v.withinBound(i[e],r[0],r[1])&&a.push(i[e]);return a}static intersectRect2D(t,n){let r=C.iterToArray(t),i=C.iterToArray(n),a=v.boundingBox(E.fromPtArray(r));return o.hasIntersectRect2D(a,i)?e.intersectLines2D([r],o.sides(i)):new E}static subpoints(e,t){let n=C.iterToArray(e),r=new E;for(let e=1;e<=t;e++)r.push(v.interpolate(n[0],n[1],e/(t+1)));return r}static crop(t,n,r=0,i=!0){let a=C.iterToArray(t),s=a[+(r===0)].$subtract(a[r]);if(s.magnitudeSq()===0)return a[r];if(i){let e=s.unit().multiply(n[1]);return a[r].$add(e)}{if(n[0]===0)return a[r];let t=o.fromCenter(a[r],n),i=o.sides(t),c=0;return c=Math.abs(s[1]/s[0])>Math.abs(n[1]/n[0])?s[1]<0?0:2:s[0]<0?3:1,e.intersectRay2D(i[c],a)}}static marker(e,t,n=`arrow`,r=!0){let i=C.iterToArray(e),a=+!r,o=+!!r,s=i[a].$subtract(i[o]);if(s.magnitudeSq()===0)return new E;s.unit();let c=v.perpendicular(s).multiply(t[0]).add(i[o]);return n==`arrow`?(c.add(s.$multiply(t[1])),new E(i[o],c[0],c[1])):new E(c[0],c[1])}static toRect(e){let t=C.iterToArray(e);return new E(t[0].$min(t[1]),t[0].$max(t[1]))}},o=class e{static from(t,n,r){return e.fromTopLeft(t,n,r)}static fromTopLeft(e,t,n){let r=typeof t==`number`?[t,n==null?t:n]:t;return new E(new T(e),new T(e).add(r))}static fromCenter(e,t,n){let r=typeof t==`number`?[t/2,(n==null?t:n)/2]:new T(t).divide(2);return new E(new T(e).subtract(r),new T(e).add(r))}static toCircle(e,t=!0){return s.fromRect(e,t)}static toSquare(t,n=!1){let r=C.iterToArray(t),i=e.size(r),a=n?i.maxValue().value:i.minValue().value;return e.fromCenter(e.center(r),a,a)}static size(e){let t=C.iterToArray(e);return t[0].$max(t[1]).subtract(t[0].$min(t[1]))}static center(e){let t=C.iterToArray(e),n=t[0].$min(t[1]),r=t[0].$max(t[1]);return n.add(r.$subtract(n).divide(2))}static corners(e){let t=C.iterToArray(e),n=t[0].$min(t[1]),r=t[0].$max(t[1]);return new E(n,new T(r.x,n.y),r,new T(n.x,r.y))}static sides(t){let[n,r,i,a]=e.corners(t);return[new E(n,r),new E(r,i),new E(i,a),new E(a,n)]}static boundingBox(e){let t=C.iterToArray(e),n=C.flatten(t,!1);if(n.length===0)return new E;let r=T.make(2,1/0),i=T.make(2,-1/0);for(let e=0,t=n.length;e<t;e++){let t=n[e],a=Math.min(2,t.length);for(let e=0;e<a;e++)r[e]=Math.min(r[e],t[e]),i[e]=Math.max(i[e],t[e])}return new E(r,i)}static polygon(t){return e.corners(t)}static quadrants(t,n){let r=C.iterToArray(t),i=e.corners(r),a=n==null?e.center(r):new T(n);return i.map(e=>new E(e,a).boundingBox())}static halves(e,t=.5,n=!1){let r=C.iterToArray(e),i=r[0].$min(r[1]),a=r[0].$max(r[1]),o=n?_.lerp(i[1],a[1],t):_.lerp(i[0],a[0],t);return n?[new E(i,new T(a[0],o)),new E(new T(i[0],o),a)]:[new E(i,new T(o,a[1])),new E(new T(o,i[1]),a)]}static withinBound(e,t){let n=C.iterToArray(e);return v.withinBound(t,n[0],n[1])}static hasIntersectRect2D(e,t,n=!1){let r=C.iterToArray(e),i=C.iterToArray(t);return n&&(r=v.boundingBox(r),i=v.boundingBox(i)),!(r[0][0]>i[1][0]||i[0][0]>r[1][0]||r[0][1]>i[1][1]||i[0][1]>r[1][1])}static intersectRect2D(t,n){let r=C.iterToArray(t),i=C.iterToArray(n);return e.hasIntersectRect2D(r,i)?a.intersectLines2D(e.sides(r),e.sides(i)):new E}},s=class e{static fromRect(e,t=!1){let n=C.iterToArray(e),r=0,i=r=o.size(n).minValue().value/2;if(t){let e=o.size(n).maxValue().value/2;r=Math.sqrt(i*i+e*e)}else r=i;return new E(o.center(n),new T(r,r))}static fromTriangle(e,t=!1){return t?c.circumcircle(e):c.incircle(e)}static fromCenter(e,t){return new E(new T(e),new T(t,t))}static withinBound(e,t,n=0){let r=C.iterToArray(e),i=r[0].$subtract(t);return i.dot(i)+n<r[1].x*r[1].x}static intersectRay2D(e,t){let n=C.iterToArray(e),r=C.iterToArray(t),i=r[0].$subtract(r[1]),a=n[0].$subtract(r[0]),o=i.dot(i);if(o===0)return new E;let s=a.dot(i),c=a.dot(a)-n[1].x*n[1].x,l=s/o,u=c/o,d=l*l-u;if(d<0)return new E;{let e=Math.sqrt(d),t=-l+e,n=r[0].$subtract(i.$multiply(t));if(d===0)return new E(n);let a=-l-e;return new E(n,r[0].$subtract(i.$multiply(a)))}}static intersectLine2D(t,n){let r=C.iterToArray(t),i=C.iterToArray(n),a=e.intersectRay2D(r,i),s=new E;if(a.length>0)for(let e=0,t=a.length;e<t;e++)o.withinBound(i,a[e])&&s.push(a[e]);return s}static intersectCircle2D(e,t){let n=C.iterToArray(e),r=C.iterToArray(t),i=r[0].$subtract(n[0]),a=i.magnitudeSq(),o=Math.sqrt(a),s=n[1].x,c=r[1].x,l=s*s,u=c*c;if(o>s+c)return new E;if(o<Math.abs(s-c))return new E(n[0].clone());if(o===0)return new E;{let e=(l-u+a)/(2*o),t=Math.sqrt(l-e*e),r=i.$multiply(e/o).add(n[0]);return new E(new T(r.x+t*i.y/o,r.y-t*i.x/o),new T(r.x-t*i.y/o,r.y+t*i.x/o))}}static intersectRect2D(t,n){let r=C.iterToArray(t),i=C.iterToArray(n),a=o.sides(i),s=[];for(let t=0,n=a.length;t<n;t++){let n=e.intersectLine2D(r,a[t]);n.length>0&&s.push(n)}return C.flatten(s)}static toRect(e,t=!1){let n=C.iterToArray(e),r=n[1][0];if(t){let e=r/Math.SQRT2;return new E(n[0].$subtract(e),n[0].$add(e))}return new E(n[0].$subtract(r),n[0].$add(r))}static toTriangle(e,t=!0){let n=C.iterToArray(e);if(t){let e=-Math.PI/2,t=Math.PI*2/3,r=new E;for(let i=0;i<3;i++)r.push(n[0].clone().toAngle(e,n[1][0],!0)),e+=t;return r}return c.fromCenter(n[0],n[1][0])}},c=class e{static fromRect(e){let t=C.iterToArray(e),n=t[0].$add(t[1]).divide(2);n.y=t[0][1];let r=t[1].clone();return r.x=t[0][0],new E(n,t[1].clone(),r)}static fromCircle(e){return s.toTriangle(e,!0)}static fromCenter(t,n){return e.fromCircle(s.fromCenter(t,n))}static medial(e){let t=C.iterToArray(e);return t.length<3?r(new E,3):l.midpoints(t,!0)}static oppositeSide(e,t){let n=C.iterToArray(e);return n.length<3?r(new E,3):t===0?E.fromPtArray([n[1],n[2]]):t===1?E.fromPtArray([n[0],n[2]]):E.fromPtArray([n[0],n[1]])}static altitude(t,n){let r=C.iterToArray(t),i=e.oppositeSide(r,n);return i.length>1?new E(r[n],a.perpendicularFromPt(i,r[n])):new E}static orthocenter(t){let n=C.iterToArray(t);if(n.length<3)return r(void 0,3);let i=e.altitude(n,0),o=e.altitude(n,1);return a.intersectRay2D(i,o)}static incenter(e){let t=C.iterToArray(e);if(t.length<3)return r(void 0,3);let n=l.bisector(t,0).add(t[0]),i=l.bisector(t,1).add(t[1]);return a.intersectRay2D(new E(t[0],n),new E(t[1],i))}static incircle(t,n){let r=C.iterToArray(t),i=n||e.incenter(r);if(!i)return;let a=l.area(r),o=l.perimeter(r,!0),c=2*a/o.total;if(c>0)return s.fromCenter(i,c)}static circumcenter(t){let n=C.iterToArray(t),r=e.medial(n),i=[r[0],v.perpendicular(n[0].$subtract(r[0])).p1.$add(r[0])],o=[r[1],v.perpendicular(n[1].$subtract(r[1])).p1.$add(r[1])];return a.intersectRay2D(i,o)}static circumcircle(t,n){let r=C.iterToArray(t),i=n||e.circumcenter(r);if(!i)return;let a=r[0].$subtract(i).magnitude();return s.fromCenter(i,a)}},l=class e{static centroid(e){return v.centroid(e)}static rectangle(e,t,n){return o.corners(o.fromCenter(e,t,n))}static fromCenter(e,t,n){let r=new E;for(let i=0;i<n;i++){let a=Math.PI*2*i/n;r.push(new T(Math.cos(a)*t,Math.sin(a)*t).add(e))}return r}static lineAt(e,t){let n=C.iterToArray(e);if(t<0||t>=n.length)throw Error(`index out of the Polygon's range`);return new E(n[t],t===n.length-1?n[0]:n[t+1])}static lines(e,t=!0){let n=C.iterToArray(e);if(n.length<2)return r(new E,2);let i=t?n.length:n.length-1,a=Array(i);for(let e=0;e<i;e++){let t=new E;t[0]=n[e],t[1]=n[e===n.length-1?0:e+1],a[e]=t}return a}static midpoints(t,n=!1,r=.5){let i=e.lines(t,n),a=new E;for(let e=0,t=i.length;e<t;e++)a[e]=v.interpolate(i[e][0],i[e][1],r);return a}static adjacentSides(e,t,n=!1){let a=C.iterToArray(e);if(a.length<2)return r(new E,2);if(t<0||t>=a.length)return i(new E,t);let o=[],s=t-1;n&&s<0&&(s=a.length-1),s>=0&&o.push(new E(a[t],a[s]));let c=t+1;return n&&c>a.length-1&&(c=0),c<=a.length-1&&o.push(new E(a[t],a[c])),o}static bisector(t,n){let r=e.adjacentSides(t,n,!0);if(r.length>=2){let e=r[0][1].$subtract(r[0][0]).unit(),t=r[1][1].$subtract(r[1][0]).unit();return e.add(t).divide(2)}}static perimeter(e,t=!1){let n=C.iterToArray(e);if(n.length<2)return r(new E,2),{total:0,segments:T.make(0,0)};let i=t?n.length:n.length-1,a=T.make(i,0),o=0;for(let e=0;e<i;e++){let t=n[e],r=n[e===n.length-1?0:e+1],i=r[0]-t[0],s=r[1]-t[1],c=Math.sqrt(i*i+s*s);o+=c,a[e]=c}return{total:o,segments:a}}static area(e){let t=C.iterToArray(e);if(t.length<3)return r(0,3);let n=(e,t)=>e[0]*t[1]-e[1]*t[0],i=0;for(let e=0,r=t.length;e<r;e++)e<t.length-1?i+=n(t[e],t[e+1]):i+=n(t[e],t[0]);return Math.abs(i/2)}static convexHull(e,t=!1){let n=C.iterToArray(e);if(n.length<3)return r(new E,3);t||(n=n.slice(),n.sort((e,t)=>e[0]-t[0]));let i=(e,t,n)=>(t[0]-e[0])*(n[1]-e[1])-(n[0]-e[0])*(t[1]-e[1])>0,a=[],o=n.length-2,s=o+3;a[o]=n[2],a[s]=n[2],i(n[0],n[1],n[2])?(a[o+1]=n[0],a[o+2]=n[1]):(a[o+1]=n[1],a[o+2]=n[0]);for(let e=3,t=n.length;e<t;e++){let t=n[e];if(!(i(a[o],a[o+1],t)&&i(a[s-1],a[s],t))){for(;!i(a[o],a[o+1],t);)o+=1;for(--o,a[o]=t;!i(a[s-1],a[s],t);)--s;s+=1,a[s]=t}}let c=new E;for(let e=0;e<s-o;e++)c.push(a[o+e]);return c}static network(e,t=0){let n=C.iterToArray(e),r=[];for(let e=0,i=n.length;e<i;e++)e!=t&&r.push(new E(n[t],n[e]));return r}static nearestPt(e,t){let n=C.iterToArray(e),r=t[0],i=t[1],a=Number.MAX_VALUE,o=-1;for(let e=0,t=n.length;e<t;e++){let t=n[e][0]-r,s=n[e][1]-i,c=t*t+s*s;c<a&&(a=c,o=e)}return o}static projectAxis(e,t){let n=C.iterToArray(e),r=t.dot(n[0]),i=r;for(let e=1,a=n.length;e<a;e++){let a=t.dot(n[e]);a<r?r=a:a>i&&(i=a)}return new T(r,i)}static _axisOverlap2D(e,t,n,r){let i=n*e[0][0]+r*e[0][1],a=i;for(let t=1,o=e.length;t<o;t++){let o=n*e[t][0]+r*e[t][1];o<i?i=o:o>a&&(a=o)}let o=n*t[0][0]+r*t[0][1],s=o;for(let e=1,i=t.length;e<i;e++){let i=n*t[e][0]+r*t[e][1];i<o?o=i:i>s&&(s=i)}return i<o?o-a:i-s}static _axisOverlap(t,n,r){let i=e.projectAxis(t,r),a=e.projectAxis(n,r);return i[0]<a[0]?a[0]-i[1]:i[0]-a[1]}static hasIntersectPoint(e,t){let n=C.iterToArray(e),r=t[0],i=t[1],a=!1;for(let e=0,t=n.length;e<t;e++){let o=n[e],s=n[e===t-1?0:e+1];o[1]>i!=s[1]>i&&r<(s[0]-o[0])*(i-o[1])/(s[1]-o[1])+o[0]&&(a=!a)}return a}static hasIntersectCircle(t,n){let r=C.iterToArray(t),i=C.iterToArray(n),c=i[0],l=i[1][0],u=1/0,d=1/0,f=-1/0,p=-1/0;for(let e=0,t=r.length;e<t;e++){let t=r[e];t[0]<u&&(u=t[0]),t[0]>f&&(f=t[0]),t[1]<d&&(d=t[1]),t[1]>p&&(p=t[1])}if(c[0]+l<u||c[0]-l>f||c[1]+l<d||c[1]-l>p)return null;let m=9007199254740991,h=null,g=0,_=0,v=-1;for(let t=0,n=r.length;t<n;t++){let u=r[t],d=r[t===n-1?0:t+1],f=u[1]-d[1],p=d[0]-u[0],y=Math.sqrt(f*f+p*p);if(y===0)continue;f/=y,p/=y;let b=f*r[0][0]+p*r[0][1],x=b;for(let e=1;e<n;e++){let t=f*r[e][0]+p*r[e][1];t<b?b=t:t>x&&(x=t)}let S=f*c[0]+p*c[1],C=b<S-l?S-l-x:b-(S+l);if(C>0)return null;if(Math.abs(C)<m){let n=e.lineAt(r,t);(o.withinBound(n,a.perpendicularFromPt(n,c))||s.intersectLine2D(i,n).length>0)&&(h=n,g=f,_=p,m=Math.abs(C),v=t)}}if(!h)return null;let y=0,b=0,x=1/0;for(let e=0,t=r.length;e<t;e++){let t=c[0]-r[e][0],n=c[1]-r[e][1],i=t*t+n*n;i<x&&(x=i,y=t,b=n)}if(x>0){let e=Math.sqrt(x);y/=e,b/=e;let t=1/0,n=-1/0;for(let e=0,i=r.length;e<i;e++){let i=y*r[e][0]+b*r[e][1];i<t&&(t=i),i>n&&(n=i)}let i=y*c[0]+b*c[1];if(i-l>n||i+l<t)return null}let S=e.centroid(r);return g*(c[0]-S[0])+_*(c[1]-S[1])<0&&(g=-g,_=-_),{which:v,dist:m,normal:new T(g,_),edge:h,vertex:c}}static hasIntersectPolygon(t,n){let r=C.iterToArray(t),i=C.iterToArray(n),a=r.length,o=i.length,s=1/0,c=1/0,l=-1/0,u=-1/0;for(let e=0;e<a;e++){let t=r[e];t[0]<s&&(s=t[0]),t[0]>l&&(l=t[0]),t[1]<c&&(c=t[1]),t[1]>u&&(u=t[1])}let d=1/0,f=1/0,p=-1/0,m=-1/0;for(let e=0;e<o;e++){let t=i[e];t[0]<d&&(d=t[0]),t[0]>p&&(p=t[0]),t[1]<f&&(f=t[1]),t[1]>m&&(m=t[1])}if(s>p||d>l||c>m||f>u)return null;let h=9007199254740991,g=-1,_=0,v=0;for(let t=0,n=a+o;t<n;t++){let n=t<a?r:i,o=t<a?t:t-a,s=n[o],c=n[o===n.length-1?0:o+1],l=s[1]-c[1],u=c[0]-s[0],d=Math.sqrt(l*l+u*u);if(d===0)continue;l/=d,u/=d;let f=e._axisOverlap2D(r,i,l,u);if(f>0)return null;Math.abs(f)<h&&(h=Math.abs(f),g=t,_=l,v=u)}if(g<0)return null;let y=g<a?0:1,b=y===0?e.lineAt(r,g):e.lineAt(i,g-a),x=y===0?i:r,S=y===0?r:i,w=e.centroid(x),E=e.centroid(S);_*(w[0]-E[0])+v*(w[1]-E[1])<0&&(_=-_,v=-v);let D=9007199254740991,O=null;for(let e=0,t=x.length;e<t;e++){let t=_*(x[e][0]-E[0])+v*(x[e][1]-E[1]);t<D&&(D=t,O=x[e])}return{which:y,dist:h,normal:new T(_,v),edge:b,vertex:O}}static intersectPolygon2D(t,n){let r=C.iterToArray(t),i=C.iterToArray(n),o=e.lines(r),s=[];for(let e=0,t=o.length;e<t;e++){let t=a.intersectPolygon2D(o[e],i,!1);t&&s.push(t)}return C.flatten(s,!0)}static toRects(e){let t=[];for(let n of e)t.push(v.boundingBox(n));let n=C.flatten(t,!1);return t.unshift(v.boundingBox(n)),t}},u=class e{static getSteps(e){let t=new E;for(let n=0;n<=e;n++){let r=n/e;t.push(new T(r*r*r,r*r,r,1))}return t}static controlPoints(e,t=0,n=!1){let r=C.iterToArray(e);if(t>r.length-1)return new E;let i=e=>e<r.length-1?e:r.length-1,a=r[t];return t=n?t:t+1,new E(a,r[i(t++)],r[i(t++)],r[i(t++)])}static _weights(e,t){let n=new Float64Array((e+1)*4);for(let r=0;r<=e;r++)t(r/e,n,r*4);return n}static _evalSegment(e,t,n,r){let i=t[0],a=t[1],o=t[2],s=t[3],c=i.length>2;for(let t=0;t<=r;t++){let r=t*4,l=n[r],u=n[r+1],d=n[r+2],f=n[r+3],p=l*i[0]+u*a[0]+d*o[0]+f*s[0],m=l*i[1]+u*a[1]+d*o[1]+f*s[1];e.push(c?new T(p,m,l*i[2]+u*a[2]+d*o[2]+f*s[2]):new T(p,m))}}static _calcPt(e,t){let n=e.reduce((e,n,r)=>e+n.x*t[r],0),r=e.reduce((e,n,r)=>e+n.y*t[r],0);return e[0].length>2?new T(n,r,e.reduce((e,n,r)=>e+n.z*t[r],0)):new T(n,r)}static _stepPt(e,t,n,r,i){let a=e[0],o=e[1],s=e[2],c=e[3],l=t*a[0]+n*o[0]+r*s[0]+i*c[0],u=t*a[1]+n*o[1]+r*s[1]+i*c[1];return a.length>2?new T(l,u,t*a[2]+n*o[2]+r*s[2]+i*c[2]):new T(l,u)}static catmullRom(t,n=10){let r=C.iterToArray(t);if(r.length<2)return new E;let i=new E,a=e._weights(n,(e,t,n)=>{let r=e*e,i=r*e;t[n]=-.5*i+r-.5*e,t[n+1]=1.5*i-2.5*r+1,t[n+2]=-1.5*i+2*r+.5*e,t[n+3]=.5*i-.5*r});e._evalSegment(i,e.controlPoints(r,0,!0),a,n);let o=0;for(;o<r.length-2;){let t=e.controlPoints(r,o);t.length>0&&(e._evalSegment(i,t,a,n),o++)}return i}static catmullRomStep(t,n){let r=t[0],i=t[1],a=t[2];return e._stepPt(n,-.5*r+i-.5*a,1.5*r-2.5*i+1,-1.5*r+2*i+.5*a,.5*r-.5*i)}static cardinal(t,n=10,r=.5){let i=C.iterToArray(t);if(i.length<2)return new E;let a=new E,o=e._weights(n,(e,t,n)=>{let i=e*e,a=i*e;t[n]=r*(-a+2*i-e),t[n+1]=r*(-a+i)+(2*a-3*i+1),t[n+2]=r*(a-2*i+e)+(-2*a+3*i),t[n+3]=r*(a-i)});e._evalSegment(a,e.controlPoints(i,0,!0),o,n);let s=0;for(;s<i.length-2;){let t=e.controlPoints(i,s);t.length>0&&(e._evalSegment(a,t,o,n),s++)}return a}static cardinalStep(t,n,r=.5){let i=t[0],a=t[1],o=t[2];return e._stepPt(n,r*(-i+2*a-o),r*(-i+a)+(2*i-3*a+1),r*(i-2*a+o)+(-2*i+3*a),r*(i-a))}static bezier(t,n=10){let r=C.iterToArray(t);if(r.length<4)return new E;let i=new E,a=e._weights(n,(e,t,n)=>{let r=e*e,i=r*e;t[n]=-i+3*r-3*e+1,t[n+1]=3*i-6*r+3*e,t[n+2]=-3*i+3*r,t[n+3]=i}),o=0;for(;o<r.length-3;){let t=e.controlPoints(r,o);t.length>0&&(e._evalSegment(i,t,a,n),o+=3)}return i}static bezierStep(t,n){let r=t[0],i=t[1],a=t[2];return e._stepPt(n,-r+3*i-3*a+1,3*r-6*i+3*a,-3*r+3*i,r)}static bspline(t,n=10,r=1){let i=C.iterToArray(t);if(i.length<2)return new E;let a=new E,o=r===1?e._weights(n,(e,t,n)=>{let r=e*e,i=r*e;t[n]=-i/6+.5*r-.5*e+1/6,t[n+1]=.5*i-r+2/3,t[n+2]=-.5*i+.5*r+.5*e+1/6,t[n+3]=i/6}):e._weights(n,(e,t,n)=>{let i=e*e,a=i*e,o=2*a-3*i+1,s=-2*a+3*i;t[n]=r*(-a/6+.5*i-.5*e+1/6),t[n+1]=r*(-1.5*a+2*i-1/3)+o,t[n+2]=r*(1.5*a-2.5*i+.5*e+1/6)+s,t[n+3]=a/6*r}),s=0;for(;s<i.length-3;){let t=e.controlPoints(i,s);t.length>0&&(e._evalSegment(a,t,o,n),s++)}return a}static bsplineStep(t,n){let r=t[0],i=t[1],a=t[2];return e._stepPt(n,-r/6+.5*i-.5*a+1/6,.5*r-i+2/3,-.5*r+.5*i+.5*a+1/6,r/6)}static bsplineTensionStep(t,n,r=1){let i=t[0],a=t[1],o=t[2],s=2*i-3*a+1,c=-2*i+3*a;return e._stepPt(n,r*(-i/6+.5*a-.5*o+1/6),r*(-1.5*i+2*a-1/3)+s,r*(1.5*i-2.5*a+.5*o+1/6)+c,i/6*r)}},d=t({Mat:()=>p,Vec:()=>f}),f=class e{static add(e,t){if(typeof t==`number`)for(let n=0,r=e.length;n<r;n++)e[n]+=t;else for(let n=0,r=e.length;n<r;n++)e[n]+=t[n]||0;return e}static subtract(e,t){if(typeof t==`number`)for(let n=0,r=e.length;n<r;n++)e[n]-=t;else for(let n=0,r=e.length;n<r;n++)e[n]-=t[n]||0;return e}static multiply(e,t){if(typeof t==`number`)for(let n=0,r=e.length;n<r;n++)e[n]*=t;else{if(e.length!=t.length)throw Error(`Cannot do element-wise multiply since the array lengths don't match: ${e.toString()} multiply-with ${t.toString()}`);for(let n=0,r=e.length;n<r;n++)e[n]*=t[n]}return e}static divide(e,t){if(typeof t==`number`){if(t===0)throw Error(`Cannot divide by zero`);for(let n=0,r=e.length;n<r;n++)e[n]/=t}else{if(e.length!=t.length)throw Error(`Cannot do element-wise divide since the array lengths don't match. ${e.toString()} divide-by ${t.toString()}`);for(let n=0,r=e.length;n<r;n++)e[n]/=t[n]}return e}static dot(e,t){if(e.length!=t.length)throw Error(`Array lengths don't match`);let n=0;for(let r=0,i=e.length;r<i;r++)n+=e[r]*t[r];return n}static cross2D(e,t){return e[0]*t[1]-e[1]*t[0]}static cross(e,t){return new T(e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0])}static magnitude(t){return Math.sqrt(e.dot(t,t))}static unit(t,n=void 0){let r=n===void 0?e.magnitude(t):n;return r===0?t:e.divide(t,r)}static abs(t){return e.map(t,Math.abs)}static floor(t){return e.map(t,Math.floor)}static ceil(t){return e.map(t,Math.ceil)}static round(t){return e.map(t,Math.round)}static max(e){let t=-1/0,n=0;for(let r=0,i=e.length;r<i;r++)e[r]>=t&&(t=e[r],n=r);return{value:t,index:n}}static min(e){let t=1/0,n=0;for(let r=0,i=e.length;r<i;r++)e[r]<=t&&(t=e[r],n=r);return{value:t,index:n}}static sum(e){let t=0;for(let n=0,r=e.length;n<r;n++)t+=e[n];return t}static map(e,t){for(let n=0,r=e.length;n<r;n++)e[n]=t(e[n],n,e);return e}},p=class e{constructor(){this.reset()}get value(){return this._33}get domMatrix(){return new DOMMatrix(e.toDOMMatrix(this._33))}reset(){this._33=e.scale2DMatrix(1,1)}scale2D(t,n=[0,0]){var r,i;let a=e.scaleAt2DMatrix((r=t[0])==null?1:r,(i=t[1])==null?1:i,n);return this._33=e.multiply(this._33,a),this}rotate2D(t,n=[0,0]){let r=e.rotateAt2DMatrix(Math.cos(t),Math.sin(t),n);return this._33=e.multiply(this._33,r),this}translate2D(t){let n=e.translate2DMatrix(t[0]||0,t[1]||0);return this._33=e.multiply(this._33,n),this}shear2D(t,n=[0,0]){var r,i;let a=e.shearAt2DMatrix(Math.tan((r=t[0])==null?0:r),Math.tan((i=t[1])==null?0:i),n);return this._33=e.multiply(this._33,a),this}static add(e,t){if(typeof t!=`number`&&(e[0].length!=t[0].length||e.length!=t.length))throw Error(`Cannot add matrix if rows' and columns' size don't match.`);let n=new E,r=typeof t==`number`;for(let i=0,a=e.length;i<a;i++)n.push(e[i].$add(r?t:t[i]));return n}static multiply(t,n,r=!1,i=!1){let a=new E;if(typeof n!=`number`){if(i){if(t.length!=n.length)throw Error(`Cannot multiply matrix element-wise because the matrices' sizes don't match.`);for(let e=0,r=t.length;e<r;e++)a.push(t[e].$multiply(n[e]))}else{if(!r&&t[0].length!=n.length)throw Error(`Cannot multiply matrix if rows in matrix-a don't match columns in matrix-b.`);if(r&&t[0].length!=n[0].length)throw Error(`Cannot multiply matrix if transposed and the columns in both matrices don't match.`);r||(n=e.transpose(n));for(let e=0,r=t.length;e<r;e++){let r=T.make(n.length,0);for(let i=0,a=n.length;i<a;i++)r[i]=f.dot(t[e],n[i]);a.push(r)}}}else for(let e=0,r=t.length;e<r;e++)a.push(t[e].$multiply(n));return a}static zipSlice(e,t,n=!1){let r=[];for(let i=0,a=e.length;i<a;i++)if(e[i].length-1<t){if(n===!1)throw Error(`Index ${t} is out of bounds`);r.push(n)}else r.push(e[i][t]);return new T(r)}static zip(t,n=!1,r=!1){let i=new E,a=r?t.reduce((e,t)=>Math.max(e,t.length),0):t[0].length;for(let r=0;r<a;r++)i.push(e.zipSlice(t,r,n));return i}static transpose(t,n=!1,r=!1){return e.zip(t,n,r)}static toDOMMatrix(e){return[e[0][0],e[0][1],e[1][0],e[1][1],e[2][0],e[2][1]]}static transform2D(e,t){return new T(e[0]*t[0][0]+e[1]*t[1][0]+t[2][0],e[0]*t[0][1]+e[1]*t[1][1]+t[2][1])}static scale2DMatrix(e,t){return new E(new T(e,0,0),new T(0,t,0),new T(0,0,1))}static rotate2DMatrix(e,t){return new E(new T(e,t,0),new T(-t,e,0),new T(0,0,1))}static shear2DMatrix(e,t){return new E(new T(1,e,0),new T(t,1,0),new T(0,0,1))}static translate2DMatrix(e,t){return new E(new T(1,0,0),new T(0,1,0),new T(e,t,1))}static scaleAt2DMatrix(t,n,r){let i=e.scale2DMatrix(t,n);return i[2][0]=-r[0]*t+r[0],i[2][1]=-r[1]*n+r[1],i}static rotateAt2DMatrix(t,n,r){let i=e.rotate2DMatrix(t,n);return i[2][0]=r[0]*(1-t)+r[1]*n,i[2][1]=r[1]*(1-t)-r[0]*n,i}static shearAt2DMatrix(t,n,r){let i=e.shear2DMatrix(t,n);return i[2][0]=-r[1]*n,i[2][1]=-r[0]*t,i}static reflectAt2DMatrix(e,t){let n=a.intercept(e,t);if(n==null)return[new T([-1,0,0]),new T([0,1,0]),new T([e[0]+t[0],0,1])];{let e=n.yi,t=Math.atan(n.slope)*2,r=Math.cos(t),i=Math.sin(t);return[new T([r,i,0]),new T([i,-r,0]),new T([-e*i,e+e*r,1])]}}};function m(){let e=4022871197;return function(t){if(t){t=t.toString();for(let n=0;n<t.length;n++){e+=t.charCodeAt(n);let r=.02519603282416938*e;e=r>>>0,r-=e,r*=e,e=r>>>0,r-=e,e+=r*4294967296}return(e>>>0)*23283064365386963e-26}return e=4022871197,0}}function h(e){let t=1,n=48,r=Array(48),i=m();function a(){i();for(let e=0;e<48;e++)r[e]=i(` `);t=1,n=48}function o(e){return e=e.replace(/(^\s*)|(\s*$)/gi,``),e=e.replace(/[\x00-\x1F]/gi,``),e}function s(e){e=o(e),i(e);for(let t=0;t<e.length;t++){let n=e.charCodeAt(t).toString();for(let e=0;e<48;e++)r[e]-=i(n),r[e]<0&&(r[e]+=1)}}return a(),s(e),{random(){++n>=48&&(n=0);let e=1768863*r[n]+t*23283064365386963e-26;return r[n]=e-(t=e|0)}}}var g=t({Geom:()=>v,Num:()=>_,Range:()=>b,Shaping:()=>y}),_=class e{static equals(e,t,n=1e-5){return Math.abs(e-t)<n}static lerp(e,t,n){return(1-n)*e+n*t}static clamp(e,t,n){return Math.max(t,Math.min(n,e))}static boundValue(e,t,n){let r=Math.abs(n-t),i=(e-t)%r;return i<0&&(i+=r),i+t}static within(e,t,n){return e>=Math.min(t,n)&&e<=Math.max(t,n)}static randomRange(t,n=0){let r=t>n?t-n:n-t;return Math.min(t,n)+e.random()*r}static randomPt(t,n){let r=new T(t.length),i=n?f.subtract(n.slice(),t):t,a=n?t:new T(t.length).fill(0);for(let t=0,n=r.length;t<n;t++)r[t]=e.random()*i[t]+a[t];return r}static normalizeValue(e,t,n){let r=Math.min(t,n),i=Math.max(t,n);return(e-r)/(i-r)}static sum(e){let t=C.iterToArray(e),n=new T(t[0]);for(let e=1,r=t.length;e<r;e++)f.add(n,t[e]);return n}static average(t){let n=C.iterToArray(t);return e.sum(n).divide(n.length)}static cycle(e,t=y.sineInOut){return t(e>.5?2-e*2:e*2)}static mapToRange(e,t,n,r,i){if(t==n)throw Error(`[currMin, currMax] must define a range that is not zero`);return r+(e-t)/(n-t)*(i-r)}static seed(e){this.generator=h(e)}static random(){return this.generator?this.generator.random():Math.random()}},v=class e{static boundAngle(e){return _.boundValue(e,0,360)}static boundRadian(e){return _.boundValue(e,0,S.two_pi)}static toRadian(e){return e*S.deg_to_rad}static toDegree(e){return e*S.rad_to_deg}static boundingBox(e){let t,n;for(let r of e)if(t==null)t=r.clone(),n=r.clone();else for(let e=0,i=Math.min(t.length,r.length);e<i;e++)t[e]=Math.min(t[e],r[e]),n[e]=Math.max(n[e],r[e]);return new E(t,n)}static centroid(e){return _.average(e)}static anchor(e,t=0,n=`to`){let r=n==`to`?`subtract`:`add`,i=0;for(let n of e)typeof t==`number`?t!==i&&n[r](e[t]):n[r](t),i++}static interpolate(e,t,n=.5){let r=Math.min(e.length,t.length),i=T.make(r);for(let a=0;a<r;a++)i[a]=e[a]*(1-n)+t[a]*n;return i}static perpendicular(e,t=S.xy){let n=t[1],r=t[0],i=new T(e),a=new T(i);a[r]=-i[n],a[n]=i[r];let o=new T(i);return o[r]=i[n],o[n]=-i[r],new E(a,o)}static isPerpendicular(e,t){let n=0,r=0,i=0;for(let a=0,o=Math.min(e.length,t.length);a<o;a++)n+=e[a]*t[a],r+=e[a]*e[a],i+=t[a]*t[a];return Math.abs(n)<=S.epsilon*Math.sqrt(r*i)}static withinBound(e,t,n){for(let r=0,i=Math.min(e.length,t.length,n.length);r<i;r++)if(!_.within(e[r],t[r],n[r]))return!1;return!0}static sortEdges(t){let n=C.iterToArray(t),r=e.boundingBox(n),i=r[1].add(r[0]).divide(2),a=i[0],o=i[1];return n.sort((e,t)=>{if(e.length<2||t.length<2)throw Error(`Pt dimension cannot be less than 2`);let n=e[0]-a,r=e[1]-o,i=t[0]-a,s=t[1]-o;if(n>=0&&i<0)return 1;if(n<0&&i>=0)return-1;if(n==0&&i==0)return r>=0||s>=0?r>s?1:-1:s>r?1:-1;let c=n*s-r*i;return c<0?1:c>0?-1:n*n+r*r>i*i+s*s?1:-1})}static scale(t,n,r){let i=C.iterToArray(t[0]!==void 0&&typeof t[0]==`number`?[t]:t),a=typeof n==`number`?T.make(i[0].length,n):n;r||(r=T.make(i[0].length,0));for(let e=0,t=i.length;e<t;e++){let t=i[e];for(let e=0,n=t.length;e<n;e++)t[e]=r&&r[e]?r[e]+(t[e]-r[e])*a[e]:t[e]*a[e]}return e}static rotate2D(t,n,r,i){let a=C.iterToArray(t[0]!==void 0&&typeof t[0]==`number`?[t]:t),o=r?p.rotateAt2DMatrix:p.rotate2DMatrix;r||(r=T.make(a[0].length,0));let s=o(Math.cos(n),Math.sin(n),r);for(let e=0,t=a.length;e<t;e++){let t=i?a[e].$take(i):a[e];if(t.to(p.transform2D(t,s)),i)for(let n=0;n<i.length;n++)a[e][i[n]]=t[n]}return e}static shear2D(t,n,r,i){let a=C.iterToArray(t[0]!==void 0&&typeof t[0]==`number`?[t]:t),o=typeof n==`number`?[n,n]:n;r||(r=T.make(a[0].length,0));let s=(r?p.shearAt2DMatrix:p.shear2DMatrix)(Math.tan(o[0]),Math.tan(o[1]),r);for(let e=0,t=a.length;e<t;e++){let t=i?a[e].$take(i):a[e];if(t.to(p.transform2D(t,s)),i)for(let n=0;n<i.length;n++)a[e][i[n]]=t[n]}return e}static reflect2D(t,n,r){let i=C.iterToArray(t[0]!==void 0&&typeof t[0]==`number`?[t]:t),a=C.iterToArray(n),o=p.reflectAt2DMatrix(a[0],a[1]);for(let e=0,t=i.length;e<t;e++){let t=r?i[e].$take(r):i[e];if(t.to(p.transform2D(t,o)),r)for(let n=0;n<r.length;n++)i[e][r[n]]=t[n]}return e}static cosTable(){let t=new Float64Array(360);for(let e=0;e<360;e++)t[e]=Math.cos(e*Math.PI/180);return{table:t,cos:n=>t[Math.floor(e.boundAngle(e.toDegree(n)))]}}static sinTable(){let t=new Float64Array(360);for(let e=0;e<360;e++)t[e]=Math.sin(e*Math.PI/180);return{table:t,sin:n=>t[Math.floor(e.boundAngle(e.toDegree(n)))]}}},y=class e{static linear(e,t=1){return t*e}static quadraticIn(e,t=1){return t*e*e}static quadraticOut(e,t=1){return-t*e*(e-2)}static quadraticInOut(e,t=1){let n=e*2;return e<.5?t/2*e*e*4:-t/2*((n-1)*(n-3)-1)}static cubicIn(e,t=1){return t*e*e*e}static cubicOut(e,t=1){let n=e-1;return t*(n*n*n+1)}static cubicInOut(e,t=1){let n=e*2;return e<.5?t/2*n*n*n:t/2*((n-2)*(n-2)*(n-2)+2)}static exponentialIn(e,t=1,n=.25){return t*Math.pow(e,1/n)}static exponentialOut(e,t=1,n=.25){return t*Math.pow(e,n)}static sineIn(e,t=1){return-t*Math.cos(e*S.half_pi)+t}static sineOut(e,t=1){return t*Math.sin(e*S.half_pi)}static sineInOut(e,t=1){return-t/2*(Math.cos(Math.PI*e)-1)}static cosineApprox(e,t=1){let n=e*e,r=n*n;return t*(r*n*4/9-17*r/9+22*n/9)}static circularIn(e,t=1){return-t*(Math.sqrt(1-e*e)-1)}static circularOut(e,t=1){let n=e-1;return t*Math.sqrt(1-n*n)}static circularInOut(e,t=1){let n=e*2;return e<.5?-t/2*(Math.sqrt(1-n*n)-1):t/2*(Math.sqrt(1-(n-2)*(n-2))+1)}static elasticIn(e,t=1,n=.7){let r=e-1,i=n/S.two_pi*1.5707963267948966;return t*(-Math.pow(2,10*r)*Math.sin((r-i)*S.two_pi/n))}static elasticOut(e,t=1,n=.7){let r=n/S.two_pi*1.5707963267948966;return t*(Math.pow(2,-10*e)*Math.sin((e-r)*S.two_pi/n))+t}static elasticInOut(e,t=1,n=.6){let r=e*2,i=n/S.two_pi*1.5707963267948966;return e<.5?(--r,t*(-.5*(Math.pow(2,10*r)*Math.sin((r-i)*S.two_pi/n)))):(--r,t*(.5*(Math.pow(2,-10*r)*Math.sin((r-i)*S.two_pi/n)))+t)}static bounceIn(t,n=1){return n-e.bounceOut(1-t,n)}static bounceOut(e,t=1){return e<1/2.75?t*(7.5625*e*e):e<2/2.75?(e-=1.5/2.75,t*(7.5625*e*e+.75)):e<2.5/2.75?(e-=2.25/2.75,t*(7.5625*e*e+.9375)):(e-=2.625/2.75,t*(7.5625*e*e+.984375))}static bounceInOut(t,n=1){return t<.5?e.bounceIn(t*2,n)/2:e.bounceOut(t*2-1,n)/2+n/2}static sigmoid(e,t=1,n=10){let r=n*(e-.5);return t/(1+Math.exp(-r))}static logSigmoid(e,t=1,n=.7){n=Math.max(S.epsilon,Math.min(1-S.epsilon,n)),n=1/(1-n);let r=1/(1+Math.exp((e-.5)*n*-2)),i=1/(1+Math.exp(n)),a=1/(1+Math.exp(-n));return t*(r-i)/(a-i)}static seat(e,t=1,n=.5){return e<.5?t*Math.pow(2*e,1-n)/2:t*(1-Math.pow(2*(1-e),1-n)/2)}static quadraticBezier(e,t=1,n=[.05,.95]){let r=typeof n==`number`?n:n[0],i=typeof n==`number`?.5:n[1],a=1-2*r;a===0&&(a=S.epsilon);let o=(Math.sqrt(r*r+a*e)-r)/a;return t*((1-2*i)*(o*o)+2*i*o)}static cubicBezier(e,t=1,n=[.1,.7],r=[.9,.2]){let i=new E(new T(0,0),new T(n),new T(r),new T(1,1));return t*u.bezierStep(new T(e*e*e,e*e,e,1),u.controlPoints(i)).y}static quadraticTarget(e,t=1,n=[.2,.35]){let r=Math.min(1-S.epsilon,Math.max(S.epsilon,n[0])),i=Math.min(1,Math.max(0,n[1])),a=(1-i)/(1-r)-i/r,o=(r*r*a-i)/r,s=e*e*a-o*e;return t*Math.min(1,Math.max(0,s))}static cliff(e,t=1,n=.5){return e>n?t:0}static step(e,t,n,r,...i){let a=1/t;return e(Math.floor(n/a)*a,r,...i)}},b=class{constructor(e){this._dims=0,this._source=E.fromPtArray(e),this.calc()}get max(){return this._max.clone()}get min(){return this._min.clone()}get magnitude(){return this._mag.clone()}calc(){if(!this._source)return;let e=this._source[0].length;this._dims=e;let t=new T(e),n=new T(e),r=new T(e);for(let i=0;i<e;i++){t[i]=-1/0,n[i]=1/0,r[i]=0;let e=this._source.zipSlice(i);for(let a=0,o=e.length;a<o;a++)t[i]=Math.max(t[i],e[a]),n[i]=Math.min(n[i],e[a]),r[i]=t[i]-n[i]}return this._max=t,this._min=n,this._mag=r,this}mapTo(e,t,n){let r=new E;for(let i=0,a=this._source.length;i<a;i++){let a=this._source[i],o=new T(this._dims);for(let r=0;r<this._dims;r++)o[r]=n&&n[r]?a[r]:_.mapToRange(a[r],this._min[r],this._max[r],e,t);r.push(o)}return r}append(e,t=!0){let n=C.iterToArray(e);if(n[0].length!==this._dims)throw Error(`Dimensions don't match. ${this._dims} dimensions in Range and ${n[0].length} provided in parameter. `);return this._source=this._source.concat(n),t&&this.calc(),this}ticks(e){let t=new E;for(let n=0;n<=e;n++){let r=new T(this._dims),i=e>0?n/e:0;for(let e=0,t=this._max.length;e<t;e++)r[e]=_.lerp(this._min[e],this._max[e],i);t.push(r)}return t}},x=t({Const:()=>S,Util:()=>C});let S={xy:`xy`,yz:`yz`,xz:`xz`,xyz:`xyz`,horizontal:0,vertical:1,identical:0,right:4,bottom_right:5,bottom:6,bottom_left:7,left:8,top_left:1,top:2,top_right:3,epsilon:1e-4,max:Number.MAX_VALUE,min:Number.MIN_VALUE,pi:Math.PI,two_pi:6.283185307179586,half_pi:1.5707963267948966,quarter_pi:.7853981633974483,one_degree:.017453292519943295,rad_to_deg:57.29577951308232,deg_to_rad:.017453292519943295,gravity:9.81,newton:.10197,gaussian:.3989422804014327};var C=class e{static warnLevel(t){return t&&(e._warnLevel=t),e._warnLevel}static getArgs(t){if(t.length<1)return[];let n=[],r=Array.isArray(t[0])||ArrayBuffer.isView(t[0]);if(typeof t[0]==`number`)n=Array.prototype.slice.call(t);else if(typeof t[0]==`object`&&!r){let e=[`x`,`y`,`z`,`w`],r=t[0];for(let t=0;t<e.length&&!(r.length&&t>=r.length||!(e[t]in r));t++)n.push(r[e[t]])}else r&&(n=e.toNumericArray(t[0]));return n}static toNumericArray(e){if(Array.isArray(e))return e.slice();let t=[];for(let n=0,r=e.length;n<r;n++)t.push(e[n]);return t}static getPtLike(t){let n=t[0];return typeof n==`number`?t:t.length===1&&(Array.isArray(n)||ArrayBuffer.isView(n))?n:e.getArgs(t)}static warn(t=`error`,n=void 0){if(e.warnLevel()==`error`)throw Error(t);return e.warnLevel()==`warn`&&console.warn(t),n}static randomInt(t,n=0){return e.warn("Util.randomInt is deprecated. Please use `Num.randomRange`"),Math.floor(_.random()*t)+n}static split(e,t,n,r=!1,i=!0){let a=[],o=[],s=n||t,c=0;if(e.length<=0||s<=0)return[];for(;c<e.length;){o=[];for(let n=0;n<t;n++)if(r)o.push(e[(c+n)%e.length]);else{if(c+n>=e.length)break;o.push(e[c+n])}c+=s,(!i||i&&o.length===t)&&a.push(o)}return a}static flatten(e,t=!0){let n=t?new E:[];for(let t=0,r=e.length;t<r;t++){let r=e[t];if(Array.isArray(r))for(let e=0,t=r.length;e<t;e++)n.push(r[e]);else n.push(r)}return n}static combine(e,t,n){let r=[];for(let i=0,a=e.length;i<a;i++)for(let a=0,o=t.length;a<o;a++)r.push(n(e[i],t[a]));return r}static zip(e){let t=[];for(let n=0,r=e[0].length;n<r;n++){let r=[];for(let t=0;t<e.length;t++)r.push(e[t][n]);t.push(r)}return t}static stepper(e,t=0,n=1,r){let i=t;return function(){return i+=n,i>=e&&(i=t+(i-t)%(e-t)),r&&r(i),i}}static forRange(e,t,n=0,r=1){let i=[];for(let a=n,o=t;a<o;a+=r)i[a]=e(a);return i}static load(e,t){let n=new XMLHttpRequest;n.open(`GET`,e,!0),n.onload=function(){n.status>=200&&n.status<400?t(n.responseText,!0):t(`Server error (${n.status}) when loading "${e}"`,!1)},n.onerror=function(){t(`Unknown network error`,!1)},n.send()}static download(e,t=`pts_canvas_image`,n=`png`,r=1){let i=n===`jpg`?`jpeg`:n;e.element.toBlob(function(e){let r=document.createElement(`a`),i=URL.createObjectURL(e);r.href=i,r.download=`${t}.${n}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(i)},`image/${i}`,r)}static performance(e=10){let t=Date.now(),n=[];return function(){let r=Date.now();return n.push(r-t),n.length>e&&n.shift(),t=r,Math.floor(n.reduce((e,t)=>e+t,0)/n.length)}}static arrayCheck(t,n=2){return Array.isArray(t)&&t.length<n?(e.warn(`Requires ${n} or more Pts in this Group.`),!1):!0}static iterToArray(e){return Array.isArray(e)?e:[...e]}static isMobile(){return/iPhone|iPad|Android/i.test(navigator.userAgent)}static uniqueId(e=!1){var t;return e&&typeof crypto<`u`&&(t=crypto)!=null&&t.randomUUID?crypto.randomUUID():Date.now().toString(36)+Math.random().toString(36).substring(2)}};C._warnLevel=`mute`;var w=t({Bound:()=>D,Group:()=>E,Pt:()=>T}),T=class e extends Float32Array{constructor(...e){let t,n=e[0];t=e.length===1&&typeof n==`number`?n:e.length===0?2:e.length===1&&(Array.isArray(n)||ArrayBuffer.isView(n))?n:typeof n==`number`?e:C.getArgs(e),super(t)}static make(t,n=0,r=!1){let i=new e(t);if(n&&i.fill(n),r)for(let e=0,t=i.length;e<t;e++)i[e]=i[e]*_.random();return i}get id(){return this._id}set id(e){this._id=e}get x(){return this[0]}set x(e){this[0]=e}get y(){return this[1]}set y(e){this[1]=e}get z(){return this[2]}set z(e){this[2]=e}get w(){return this[3]}set w(e){this[3]=e}clone(){return new e(this)}equals(e,t=1e-6){for(let n=0,r=this.length;n<r;n++)if(!(Math.abs(this[n]-e[n])<=t))return!1;return!0}to(...e){let t=C.getPtLike(e);for(let e=0,n=Math.min(this.length,t.length);e<n;e++)this[e]=t[e];return this}$to(...e){return this.clone().to(...e)}toAngle(e,t,n=!1){let r=t==null?this.magnitude():t,i=[Math.cos(e)*r,Math.sin(e)*r];return n?this.add(i):this.to(i)}op(e){let t=this;return(...n)=>e(t,...n)}ops(e){let t=[];for(let n=0,r=e.length;n<r;n++)t.push(this.op(e[n]));return t}$take(t){let n=[];for(let e=0,r=t.length;e<r;e++)n.push(this[t[e]]||0);return new e(n)}$concat(...t){return new e(this.toArray().concat(C.getArgs(t)))}add(...e){return e.length===1&&typeof e[0]==`number`?f.add(this,e[0]):f.add(this,C.getPtLike(e)),this}$add(...e){return this.clone().add(...e)}subtract(...e){return e.length===1&&typeof e[0]==`number`?f.subtract(this,e[0]):f.subtract(this,C.getPtLike(e)),this}$subtract(...e){return this.clone().subtract(...e)}multiply(...e){return e.length===1&&typeof e[0]==`number`?f.multiply(this,e[0]):f.multiply(this,C.getPtLike(e)),this}$multiply(...e){return this.clone().multiply(...e)}divide(...e){return e.length===1&&typeof e[0]==`number`?f.divide(this,e[0]):f.divide(this,C.getPtLike(e)),this}$divide(...e){return this.clone().divide(...e)}magnitudeSq(){return f.dot(this,this)}magnitude(){return f.magnitude(this)}unit(e=void 0){return f.unit(this,e),this}$unit(e=void 0){return this.clone().unit(e)}dot(...e){return f.dot(this,C.getPtLike(e))}$cross2D(...e){return f.cross2D(this,C.getPtLike(e))}$cross(...e){return f.cross(this,C.getPtLike(e))}$project(...e){return this.$multiply(this.dot(...e)/this.magnitudeSq())}projectScalar(...e){return this.dot(...e)/this.magnitude()}abs(){return f.abs(this),this}$abs(){return this.clone().abs()}floor(){return f.floor(this),this}$floor(){return this.clone().floor()}ceil(){return f.ceil(this),this}$ceil(){return this.clone().ceil()}round(){return f.round(this),this}$round(){return this.clone().round()}minValue(){return f.min(this)}maxValue(){return f.max(this)}$min(...e){let t=C.getPtLike(e),n=this.clone();for(let e=0,r=Math.min(this.length,t.length);e<r;e++)n[e]=Math.min(this[e],t[e]);return n}$max(...e){let t=C.getPtLike(e),n=this.clone();for(let e=0,r=Math.min(this.length,t.length);e<r;e++)n[e]=Math.max(this[e],t[e]);return n}angle(e=S.xy){return Math.atan2(this[e[1]],this[e[0]])}angleBetween(e,t=S.xy){return v.boundRadian(this.angle(t)-e.angle(t)+Math.PI)-Math.PI}scale(t,n){return v.scale(this,t,n||e.make(this.length,0)),this}rotate2D(t,n,r){return v.rotate2D(this,t,n||e.make(this.length,0),r),this}shear2D(t,n,r){return v.shear2D(this,t,n||e.make(this.length,0),r),this}reflect2D(e,t){return v.reflect2D(this,e,t),this}toString(){return`Pt(${this.join(`, `)})`}toArray(){let e=[];for(let t=0,n=this.length;t<n;t++)e.push(this[t]);return e}toGroup(){return new E(e.make(this.length),this.clone())}toBound(){return new D(e.make(this.length),this.clone())}},E=class e extends Array{constructor(...e){super(...e)}get id(){return this._id}set id(e){this._id=e}get p1(){return this[0]}get p2(){return this[1]}get p3(){return this[2]}get p4(){return this[3]}get q1(){return this[this.length-1]}get q2(){return this[this.length-2]}get q3(){return this[this.length-3]}get q4(){return this[this.length-4]}clone(){let t=new e;for(let e=0,n=this.length;e<n;e++)t.push(this[e].clone());return t}static fromArray(t){let n=new e;for(let e of t){let t=e instanceof T?e:new T(e);n.push(t)}return n}static fromPtArray(t){return e.from(t)}split(t,n,r=!1){let i=n||t,a=[];if(this.length<=0||i<=0)return a;let o=0;for(;o<this.length;){let n=new e,s=0;for(let e=0;e<t;e++)if(r)n[s++]=this[(o+e)%this.length];else{if(o+e>=this.length)break;n[s++]=this[o+e]}o+=i,s===t&&a.push(n)}return a}insert(e,t=0){let n=C.iterToArray(e);n===this&&(n=n.slice());let r=this.length,i=n.length;if(i===0)return this;let a=Math.trunc(t)||0;a=a<0?Math.max(r+a,0):Math.min(a,r),this.length=r+i;for(let e=r-1;e>=a;e--)this[e+i]=this[e];for(let e=0;e<i;e++)this[a+e]=n[e];return this}remove(t=0,n=1){let r=t<0?[t*-1-1,n]:[t,n];return e.prototype.splice.apply(this,r)}segments(e=2,t=1,n=!1){return this.split(e,t,n)}lines(){return this.segments(2,1)}centroid(){return v.centroid(this)}boundingBox(){return v.boundingBox(this)}anchorTo(e=0){v.anchor(this,e,`to`)}anchorFrom(e=0){v.anchor(this,e,`from`)}op(e){let t=this;return(...n)=>e(t,...n)}ops(e){let t=[];for(let n=0,r=e.length;n<r;n++)t.push(this.op(e[n]));return t}interpolate(e){e=_.clamp(e,0,1);let t=this.length-1,n=1/(this.length-1),r=Math.floor(e/n);return v.interpolate(this[r],this[Math.min(this.length-1,r+1)],(e-r*n)*t)}moveBy(...e){return this.add(...e)}moveTo(...e){let t=new T(...e).subtract(this[0]);return this.moveBy(t),this}scale(e,t){for(let n=0,r=this.length;n<r;n++)v.scale(this[n],e,t||this[0]);return this}rotate2D(e,t,n){for(let r=0,i=this.length;r<i;r++)v.rotate2D(this[r],e,t||this[0],n);return this}shear2D(e,t,n){for(let r=0,i=this.length;r<i;r++)v.shear2D(this[r],e,t||this[0],n);return this}reflect2D(e,t){for(let n=0,r=this.length;n<r;n++)v.reflect2D(this[n],e,t);return this}sortByDimension(e,t=!1){return this.sort((n,r)=>t?r[e]-n[e]:n[e]-r[e])}forEachPt(e,...t){if(this.length===0)return this;if(!this[0][e])return C.warn(`${e} is not a function of Pt`),this;for(let n=0,r=this.length;n<r;n++)this[n]=this[n][e](...t);return this}_vecOp(e,t){let n=t.length===1&&typeof t[0]==`number`?t[0]:C.getPtLike(t);for(let t=0,r=this.length;t<r;t++)e(this[t],n);return this}add(...e){return this._vecOp(f.add,e)}subtract(...e){return this._vecOp(f.subtract,e)}multiply(...e){return this._vecOp(f.multiply,e)}divide(...e){return this._vecOp(f.divide,e)}$matrixAdd(e){return p.add(this,e)}$matrixMultiply(e,t=!1,n=!1){return p.multiply(this,e,t,n)}zipSlice(e,t=!1){return p.zipSlice(this,e,t)}$zip(e=void 0,t=!1){return p.zip(this,e,t)}toBound(){return D.fromGroup(this)}toString(){return`Group[ `+this.reduce((e,t)=>e+t.toString()+` `,``)+` ]`}},D=class e extends E{constructor(...e){super(...e),this._center=new T,this._size=new T,this._inited=!1,this.init()}static fromBoundingRect(t){let n=new e(new T(t.left||0,t.top||0),new T(t.right||0,t.bottom||0));return t.width&&t.height&&(n.size=new T(t.width,t.height)),n}static fromGroup(t){let n=C.iterToArray(t);if(n.length<2)throw Error(`Cannot create a Bound from a group that has less than 2 Pt`);let r=n[0],i=n[n.length-1];return new e(r instanceof T?r:new T(r),i instanceof T?i:new T(i))}init(){this.p1&&(this._size=this.p1.clone(),this._inited=!0),this.p1&&this.p2&&(this._updateSize(),this._inited=!0)}clone(){return new e(this.topLeft,this.bottomRight)}_updateSize(){let e=this[0],t=this[1],n=t?t.length:0;this._size.length!==n&&(this._size=new T(n));for(let r=0;r<n;r++)this._size[r]=Math.abs(t[r]-(e&&e[r]||0));this._updateCenter()}_updateCenter(){let e=this[0],t=this._size.length;this._center.length!==t&&(this._center=new T(t));for(let n=0;n<t;n++)this._center[n]=this._size[n]*.5+(e&&e[n]||0)}_updatePosFromTop(){this.bottomRight=this.topLeft.$add(this._size),this._updateCenter()}_updatePosFromBottom(){this.topLeft=this.bottomRight.$subtract(this._size),this._updateCenter()}_updatePosFromCenter(){let e=this._size.$multiply(.5),t=this._center;this[0]=t.$subtract(e),this[1]=t.$add(e)}get size(){return new T(this._size)}set size(e){this._size=new T(e),this._updatePosFromTop()}get center(){return new T(this._center)}set center(e){this._center=new T(e),this._updatePosFromCenter()}get topLeft(){return new T(this[0])}set topLeft(e){this[0]=new T(e),this._updateSize()}get bottomRight(){return new T(this[1])}set bottomRight(e){this[1]=new T(e),this._updateSize()}get width(){return this._size.length>0?this._size.x:0}set width(e){this._size.x=e,this._updatePosFromTop()}get height(){return this._size.length>1?this._size.y:0}set height(e){this._size.y=e,this._updatePosFromTop()}get depth(){return this._size.length>2?this._size.z:0}set depth(e){this._size.z=e,this._updatePosFromTop()}get x(){return this[0]?this[0][0]:void 0}get y(){return this[0]?this[0][1]:void 0}get z(){return this[0]?this[0][2]:void 0}get inited(){return this._inited}update(){return this._updateSize(),this}};function O(e){"@babel/helpers - typeof";return O=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},O(e)}function k(e,t){if(O(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(O(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function ee(e){var t=k(e,`string`);return O(t)==`symbol`?t:t+``}function A(e,t,n){return(t=ee(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function te(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function j(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?te(Object(n),!0).forEach(function(t){A(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):te(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var ne=t({UI:()=>I,UIButton:()=>L,UIDragger:()=>R,UIPointerActions:()=>F,UIShape:()=>P});function M(e,t,n,r){if(r<0)return!1;let i=t[0]-e[0],a=t[1]-e[1],o=i*i+a*a,s=o===0?0:Math.max(0,Math.min(1,((n[0]-e[0])*i+(n[1]-e[1])*a)/o)),c=n[0]-e[0]-s*i,l=n[1]-e[1]-s*a;return c*c+l*l<=r*r}let N={rectangle:(e,t)=>o.withinBound(e,t),circle:(e,t)=>s.withinBound(e,t),polygon:(e,t)=>l.hasIntersectPoint(e,t),line:(e,t,n)=>{var r;let i=(r=n.lineThreshold)==null?5:r;return e.length>=2&&M(e[0],e[1],t,i)},polyline:(e,t,n)=>{var r;let i=(r=n.lineThreshold)==null?5:r;for(let n=0,r=e.length-1;n<r;n++)if(M(e[n],e[n+1],t,i))return!0;return!1}},P={rectangle:`rectangle`,circle:`circle`,polygon:`polygon`,polyline:`polyline`,line:`line`},F={up:`up`,down:`down`,move:`move`,drag:`drag`,uidrag:`uidrag`,drop:`drop`,uidrop:`uidrop`,over:`over`,out:`out`,enter:`enter`,leave:`leave`,click:`click`,keydown:`keydown`,keyup:`keyup`,pointerdown:`pointerdown`,pointerup:`pointerup`,contextmenu:`contextmenu`,all:`all`};var I=class e{constructor(t,n,r={},i){this._abortCleanup={},this._holds=new Map,this._group=E.fromArray(t),this._shape=n,this._id=i===void 0?`ui_${e._counter++}`:i,this._states=r,this._actions={},this._sysActions={}}static registerShape(e,t){N[e]=t}static fromRectangle(e,t,n){return new this(e,P.rectangle,t,n)}static fromCircle(e,t,n){return new this(e,P.circle,t,n)}static fromPolygon(e,t,n){return new this(e,P.polygon,t,n)}static fromUI(e,t,n){return new this(e.group,e.shape,t||j({},e._states),n)}get id(){return this._id}set id(e){this._id=e}get group(){return this._group}set group(e){this._group=e}get shape(){return this._shape}set shape(e){this._shape=e}state(e,t){return e?t===void 0?this._states[e]:(this._states[e]=t,this):null}getState(e){return this._states[e]}setState(e,t){return this._states[e]=t,this}on(t,n,r){var i;if(!n||r!=null&&(i=r.signal)!=null&&i.aborted)return-1;this._actions[t]||(this._actions[t]=[]);let a=n,o=-1;if(r!=null&&r.once&&(a=(e,r,i,a)=>{this.off(t,o),n(e,r,i,a)}),o=e._addHandler(this._actions[t],a),r!=null&&r.signal){let e=r.signal,n=()=>this.off(t,o);e.addEventListener(`abort`,n,{once:!0}),this._abortCleanup[t]||(this._abortCleanup[t]=new Map),this._abortCleanup[t].set(o,()=>e.removeEventListener(`abort`,n))}return o}off(t,n){if(!this._actions[t])return!1;if(n===void 0){var r;return(r=this._abortCleanup[t])==null||r.forEach(e=>e()),delete this._abortCleanup[t],delete this._actions[t],!0}var i,a,o;return(i=this._abortCleanup[t])==null||(a=i.get(n))==null||a.call(i),(o=this._abortCleanup[t])==null||o.delete(n),e._removeHandler(this._actions[t],n)}listen(t,n,r){let i=!1,a=this._actions[t],o=this._sysActions[t];return(a||o)&&(this._within(n)||this._holdsType(t))&&(o&&(e._trigger(o,this,n,t,r),i=!0),a&&(e._trigger(a,this,n,t,r),i=!0)),this._actions.all&&(e._trigger(this._actions.all,this,n,t,r),i=!0),i}_holdsType(e){for(let t of this._holds.values())if(t===e)return!0;return!1}_sysOn(t,n){return this._sysActions[t]||(this._sysActions[t]=[]),e._addHandler(this._sysActions[t],n)}_sysOff(t,n){return this._sysActions[t]?e._removeHandler(this._sysActions[t],n):!1}hold(e){let t=Math.max(0,...Array.from(this._holds.keys()))+1;return this._holds.set(t,e),t}unhold(e){e===void 0?this._holds.clear():this._holds.delete(e)}static track(e,t,n,r){for(let i=0,a=e.length;i<a;i++)e[i].listen(t,n,r)}render(e){e(this._group,this._states)}toString(){return`UI ${this.group.toString()}`}_within(e){let t=N[this._shape];return t?t(this._group,e,this._states):!1}static _trigger(e,t,n,r,i){if(e)for(let a=0,o=e.length;a<o;a++)e[a]&&e[a](t,n,r,i)}static _addHandler(e,t){if(!t)return-1;for(let n=0,r=e.length;n<r;n++)if(e[n]===null)return e[n]=t,n;return e.push(t),e.length-1}static _removeHandler(e,t){return t>=0&&t<e.length&&e[t]?(e[t]=null,!0):!1}};I._counter=0;var L=class extends I{constructor(e,t,n={},r){super(e,t,n,r),this._hoverID=-1,n.hover===void 0&&(this._states.hover=!1),n.clicks===void 0&&(this._states.clicks=0);let i=F;this._sysOn(i.up,()=>{this.state(`clicks`,this._states.clicks+1)}),this._sysOn(i.move,(e,t,n,r)=>{if(this._within(t)&&!this._states.hover){this.state(`hover`,!0),I._trigger(this._actions[i.enter],this,t,i.enter,r);let e=this.hold(i.move);this._hoverID=this._sysOn(i.move,(t,n,r,a)=>{!this._within(n)&&!this.state(`dragging`)&&(this.state(`hover`,!1),I._trigger(this._actions[i.leave],this,n,i.leave,a),this._sysOff(i.move,this._hoverID),this.unhold(e))})}})}onClick(e){return this.on(F.up,e)}offClick(e){return this.off(F.up,e)}onContextMenu(e){return this.on(F.contextmenu,e)}offContextMenu(e){return this.off(F.contextmenu,e)}onHover(e,t){let n=[void 0,void 0];return e&&(n[0]=this.on(F.enter,e)),t&&(n[1]=this.on(F.leave,t)),n}offHover(e,t){let n=[!1,!1];return(e===void 0||e>=0)&&(n[0]=this.off(F.enter,e)),(t===void 0||t>=0)&&(n[1]=this.off(F.leave,t)),n}},R=class extends L{constructor(e,t,n={},r){super(e,t,n,r),this._draggingID=-1,this._dragID=-1,this._moveHoldID=-1,this._dragHoldID=-1,this._dropHoldID=-1,this._upHoldID=-1,this._outHoldID=-1,n.dragging===void 0&&(this._states.dragging=!1),n.moved===void 0&&(this._states.moved=!1),n.offset===void 0&&(this._states.offset=new T);let i=F;this._sysOn(i.down,(e,t,n,r)=>{if(this._moveHoldID===-1&&(this.state(`dragging`,!0),this.state(`offset`,new T(t).subtract(e.group[0])),this._moveHoldID=this.hold(i.move),this._dragHoldID=this.hold(i.drag),this._outHoldID=this.hold(i.out)),this._dropHoldID===-1&&(this._dropHoldID=this.hold(i.drop)),this._upHoldID===-1&&(this._upHoldID=this.hold(i.up)),this._draggingID===-1){let e=(e,t,n,r)=>{let a=n===i.drag&&r===this._lastMoveEvent;this._lastMoveEvent=n===i.move?r:void 0,!a&&this.state(`dragging`)&&(I._trigger(this._actions[i.uidrag],e,t,i.uidrag,r),this.state(`moved`,!0))};this._draggingID=this._sysOn(i.move,e),this._dragID=this._sysOn(i.drag,e)}});let a=(e,t,n,r)=>{this.state(`dragging`,!1),this._sysOff(i.move,this._draggingID),this._sysOff(i.drag,this._dragID),this._draggingID=-1,this._dragID=-1,this._lastMoveEvent=void 0,this.unhold(this._moveHoldID),this._moveHoldID=-1,this.unhold(this._dragHoldID),this._dragHoldID=-1,this.unhold(this._outHoldID),this._outHoldID=-1,this.unhold(this._dropHoldID),this._dropHoldID=-1,this.unhold(this._upHoldID),this._upHoldID=-1,this.state(`moved`)&&(I._trigger(this._actions[i.uidrop],e,t,i.uidrop,r),this.state(`moved`,!1))};this._sysOn(i.drop,a),this._sysOn(i.up,a),this._sysOn(i.out,a)}onDrag(e){return this.on(F.uidrag,e)}offDrag(e){return this.off(F.uidrag,e)}onDrop(e){return this.on(F.uidrop,e)}offDrop(e){return this.off(F.uidrop,e)}},re=t({MultiTouchSpace:()=>ae,Space:()=>ie}),ie=class{constructor(){this.id=`space`,this.bound=new D,this._time={prev:0,diff:0,end:-1,min:0},this._stopAfter=-1,this.players={},this.playerCount=0,this._animID=-1,this._fromFrame=!1,this._pause=!1,this._refresh=void 0,this._pointer=new T,this._isReady=!1,this._playing=!1,this._firstFrame=!0}refresh(e){return this._refresh=e,this}minFrameTime(e=0){return this._time.min=e,this}add(e){let t=typeof e==`function`?{animate:e}:e,n=this.playerCount++,r=t.animateID||this.id+n;return this.players[r]=t,t.animateID=r,t.resize&&this.bound.inited&&t.resize(this.bound),this._refresh===void 0&&(this._refresh=!0),this}remove(e){return delete this.players[e.animateID],this}removeAll(){return this.players={},this}play(e=0){let t=this._fromFrame;if(this._fromFrame=!1,e===0&&this._animID!==-1&&!t)return this;if(this._animID!==-1&&cancelAnimationFrame(this._animID),this._animID=requestAnimationFrame(e=>{this._fromFrame=!0;try{this.play(e)}finally{this._fromFrame=!1}}),this._pause)return this._time.prev=e,this;if(this._firstFrame)this._firstFrame=e===0&&!t,this._time.diff=0,this._time.prev=e;else{let t=e-this._time.prev;if(t<this._time.min)return this;this._time.diff=t,this._time.prev=e}try{this.playItems(e)}catch(e){throw cancelAnimationFrame(this._animID),this._animID=-1,this._playing=!1,this._firstFrame=!0,e}return this}replay(){this._time.end=-1,this.play()}playItems(e){if(this._playing=!0,this._refresh&&this.clear(),this._isReady)for(let t in this.players)this.players[t].animate&&this.players[t].animate(e,this._time.diff,this);this._stopAfter>=0&&(this._time.end=e+this._stopAfter,this._stopAfter=-1),this._time.end>=0&&e>this._time.end&&(cancelAnimationFrame(this._animID),this._animID=-1,this._playing=!1,this._firstFrame=!0)}pause(e=!1){return this._pause=!e||!this._pause,this}resume(){return this._pause=!1,this}stop(e=0){return this._stopAfter=e>0?e:-1,this._time.end=e>0?-1:e,this}_cancelAnimation(){return this._animID!==-1&&cancelAnimationFrame(this._animID),this._animID=-1,this._playing=!1,this._firstFrame=!0,this}playOnce(e=0){return this.play(),this.stop(e),this}render(e){return this._renderFunc&&this._renderFunc(e,this),this}set customRendering(e){this._renderFunc=e}get customRendering(){return this._renderFunc}get isPlaying(){return this._playing}get outerBound(){return this.bound.clone()}get innerBound(){return new D(T.make(this.size.length,0),this.size.clone())}get size(){return this.bound.size.clone()}get center(){return this.size.divide(2)}get width(){return this.bound.width}get height(){return this.bound.height}},ae=class extends ie{constructor(...e){super(...e),this._pressed=!1,this._dragged=!1,this._hasMouse=!1,this._hasTouch=!1,this._hasKeyboard=!1,this._touchPassive=!1,this._mouseDownBind=this._mouseDown.bind(this),this._mouseUpBind=this._mouseUp.bind(this),this._mouseOverBind=this._mouseOver.bind(this),this._mouseOutBind=this._mouseOut.bind(this),this._mouseMoveBind=this._mouseMove.bind(this),this._mouseClickBind=this._mouseClick.bind(this),this._contextMenuBind=this._contextMenu.bind(this),this._touchStartBind=this._touchStart.bind(this),this._touchMoveBind=this._touchMove.bind(this),this._keyDownBind=this._keyDown.bind(this),this._keyUpBind=this._keyUp.bind(this),this._trackedUIs=[],this._uiPlayer=null}get pointer(){let e=this._pointer.clone();return e.id=this._pointer.id,e}bindCanvas(e,t,n={},r){(r||this._canvas).addEventListener(e,t,n)}unbindCanvas(e,t,n={},r){(r||this._canvas).removeEventListener(e,t,n)}bindDoc(e,t,n={}){typeof document<`u`&&document.addEventListener(e,t,n)}unbindDoc(e,t,n={}){typeof document<`u`&&document.removeEventListener(e,t,n)}bindMouse(e=!0,t){if(e){if(this._hasMouse){if(this._mouseTarget===t)return this;this.bindMouse(!1)}this._mouseTarget=t,this.bindCanvas(`pointerdown`,this._mouseDownBind,{},t),this.bindCanvas(`pointerup`,this._mouseUpBind,{},t),this.bindCanvas(`pointerover`,this._mouseOverBind,{},t),this.bindCanvas(`pointerout`,this._mouseOutBind,{},t),this.bindCanvas(`pointercancel`,this._mouseOutBind,{},t),this.bindCanvas(`pointermove`,this._mouseMoveBind,{},t),this.bindCanvas(`click`,this._mouseClickBind,{},t),this.bindCanvas(`contextmenu`,this._contextMenuBind,{},t),this._hasMouse=!0}else if(this._hasMouse){let e=this._mouseTarget;this.unbindCanvas(`pointerdown`,this._mouseDownBind,{},e),this.unbindCanvas(`pointerup`,this._mouseUpBind,{},e),this.unbindCanvas(`pointerover`,this._mouseOverBind,{},e),this.unbindCanvas(`pointerout`,this._mouseOutBind,{},e),this.unbindCanvas(`pointercancel`,this._mouseOutBind,{},e),this.unbindCanvas(`pointermove`,this._mouseMoveBind,{},e),this.unbindCanvas(`click`,this._mouseClickBind,{},e),this.unbindCanvas(`contextmenu`,this._contextMenuBind,{},e),this._hasMouse=!1,this._mouseTarget=void 0}return this}bindTouch(e=!0,t=!1,n){if(e){if(this._hasTouch){if(this._touchTarget===n&&this._touchPassive===t)return this;this.bindTouch(!1)}this._touchTarget=n,this._touchPassive=t,this.bindCanvas(`touchstart`,this._touchStartBind,{passive:t},n),this.bindCanvas(`touchend`,this._mouseUpBind,{},n),this.bindCanvas(`touchmove`,this._touchMoveBind,{passive:t},n),this.bindCanvas(`touchcancel`,this._mouseOutBind,{},n),this._hasTouch=!0}else if(this._hasTouch){let e=this._touchTarget,t={passive:this._touchPassive};this.unbindCanvas(`touchstart`,this._touchStartBind,t,e),this.unbindCanvas(`touchend`,this._mouseUpBind,{},e),this.unbindCanvas(`touchmove`,this._touchMoveBind,t,e),this.unbindCanvas(`touchcancel`,this._mouseOutBind,{},e),this._hasTouch=!1,this._touchTarget=void 0}return this}bindKeyboard(e=!0,t){if(e){let e=t||document;if(this._hasKeyboard){if(this._keyboardTarget===e)return this;this.bindKeyboard(!1)}e.addEventListener(`keydown`,this._keyDownBind,{}),e.addEventListener(`keyup`,this._keyUpBind,{}),this._keyboardTarget=e,this._hasKeyboard=!0}else this._hasKeyboard&&(this._keyboardTarget.removeEventListener(`keydown`,this._keyDownBind,{}),this._keyboardTarget.removeEventListener(`keyup`,this._keyUpBind,{}),this._keyboardTarget=void 0,this._hasKeyboard=!1);return this}_unbindAll(){return this.bindMouse(!1),this.bindTouch(!1),this.bindKeyboard(!1),this}removeAll(){return this.untrack(),this._uiPlayer=null,super.removeAll()}track(e){let t=Array.isArray(e)?e:[e];for(let e=0,n=t.length;e<n;e++)this._trackedUIs.indexOf(t[e])<0&&this._trackedUIs.push(t[e]);return this._uiPlayer||(this._uiPlayer={animate:()=>{},action:(e,t,n,r)=>{I.track(this._trackedUIs,e,new T(t,n),r)}},this.add(this._uiPlayer)),this}untrack(e){let t=e===void 0?this._trackedUIs.slice():Array.isArray(e)?e:[e];for(let e=0,n=t.length;e<n;e++){let n=this._trackedUIs.indexOf(t[e]);n<0||(this._trackedUIs.splice(n,1),t[e].state(`dragging`)&&t[e].listen(F.drop,this._pointer,new Event(`pointercancel`)))}return this}_inputTransform(){if(typeof Element<`u`&&this._canvas instanceof Element){let e=this._canvas.getBoundingClientRect();return[e.left,e.top,e.width?this.width/e.width:1,e.height?this.height/e.height:1]}return[this.bound.topLeft.x-(typeof window>`u`?0:window.scrollX),this.bound.topLeft.y-(typeof window>`u`?0:window.scrollY),1,1]}touchesToPoints(e,t=`touches`){if(!e||!e[t])return[];let n=[],[r,i,a,o]=this._inputTransform();for(let s=0;s<e[t].length;s++){let c=e[t].item(s);n.push(new T((c.clientX-r)*a,(c.clientY-i)*o))}return n}_mouseAction(e,t){if(!this.isPlaying)return;let[n,r,i,a]=this._inputTransform(),o=0,s=0;if(t instanceof MouseEvent)o=(t.clientX-n)*i,s=(t.clientY-r)*a;else{let e=t.changedTouches&&t.changedTouches.length>0?t.changedTouches.item(0):null;e&&(o=(e.clientX-n)*i,s=(e.clientY-r)*a)}e&&(this._pointer.to(o,s),this._pointer.id=e);for(let n in this.players)if(this.players.hasOwnProperty(n)){let r=this.players[n];r.action&&r.action(e,o,s,t)}}_isTouchHandled(e){return`pointerType`in e&&e.pointerType===`touch`&&this._hasTouch&&e.composedPath().includes(this._touchTarget||this._canvas)}_mouseDown(e){if(this._isTouchHandled(e))return!1;if(this._mouseAction(F.down,e),this._mouseAction(F.pointerdown,e),this._pressed=!0,e.target instanceof Element)try{e.target.setPointerCapture(e.pointerId)}catch(e){}return!1}_mouseUp(e){return!this._isTouchHandled(e)&&(this._mouseAction(F.pointerup,e),this._dragged?this._mouseAction(F.drop,e):this._mouseAction(F.up,e),this._pressed=!1,this._dragged=!1,e instanceof PointerEvent&&e.target instanceof Element&&e.target.hasPointerCapture(e.pointerId)&&e.target.releasePointerCapture(e.pointerId),!1)}_mouseMove(e){return this._isTouchHandled(e)||(this._pressed?(this._dragged=!0,this._mouseAction(F.drag,e)):this._mouseAction(F.move,e)),!1}_mouseOver(e){return this._isTouchHandled(e)||this._mouseAction(F.over,e),!1}_mouseOut(e){return!this._isTouchHandled(e)&&(this._mouseAction(F.out,e),this._dragged&&this._mouseAction(F.drop,e),this._pressed=!1,this._dragged=!1,!1)}_mouseClick(e){return this._mouseAction(F.click,e),this._pressed=!1,this._dragged=!1,!1}_contextMenu(e){return this._mouseAction(F.contextmenu,e),!1}_touchMove(e){return this._mouseAction(F.move,e),this._pressed&&(this._dragged=!0,this._mouseAction(F.drag,e)),this._touchPassive||e.preventDefault(),!1}_touchStart(e){return this._mouseAction(F.down,e),this._pressed=!0,this._touchPassive||e.preventDefault(),!1}_keyDown(e){return this._keyboardAction(F.keydown,e),!1}_keyUp(e){return this._keyboardAction(F.keyup,e),!1}_keyboardAction(e,t){if(this.isPlaying){for(let n in this.players)if(this.players.hasOwnProperty(n)){let r=this.players[n];r.action&&r.action(e,+!!t.shiftKey,+!!t.altKey,t)}}}},oe=t({Font:()=>le,Form:()=>se,VisualForm:()=>ce}),se=class{constructor(){this._ready=!1}get ready(){return this._ready}},ce=class extends se{constructor(...e){super(...e),this._filled=!0,this._stroked=!0,this._font=new le(14,`sans-serif`)}get filled(){return this._filled}set filled(e){this._filled=e}get stroked(){return this._stroked}set stroked(e){this._stroked=e}get currentFont(){return this._font}_multiple(e,t,...n){if(!e)return this;for(let r=0,i=e.length;r<i;r++)this[t](e[r],...n);return this}alpha(e){return this}fill(e){return this}fillOnly(e){return this.stroke(!1),this.fill(e)}stroke(e,t,n,r){return this}strokeOnly(e,t,n,r){return this.fill(!1),this.stroke(e,t,n,r)}points(e,t,n){if(!e)return this;for(let r=0,i=e.length;r<i;r++)this.point(e[r],t,n);return this}circles(e){return this._multiple(e,`circle`)}squares(e){return this._multiple(e,`square`)}lines(e){return this._multiple(e,`line`)}polygons(e){return this._multiple(e,`polygon`)}rects(e){return this._multiple(e,`rect`)}},le=class{constructor(e=12,t=`sans-serif`,n=``,r=``,i=1.5){this.size=e,this.face=t,this.style=r,this.weight=n,this.lineHeight=i}get value(){let e=[this.style,this.weight].filter(Boolean).join(` `),t=`${this.size}px/${this.lineHeight} ${this.face}`;return e?`${e} ${t}`:t}toString(){return this.value}},ue=t({Typography:()=>de}),de=class{static textWidthEstimator(e,t=[`M`,`n`,`.`],n=[.06,.8,.14]){if(t.length!==n.length)throw Error(`textWidthEstimator: samples (${t.length}) and distribution (${n.length}) must have the same length`);let r=t.map(e),i=new T(n).dot(r);return e=>e.length*i}static charWidthCache(e){let t=new Float64Array(256).fill(NaN),n=new Map;return r=>{let i=0;for(let a=0,o=r.length;a<o;a++){let s=r.charCodeAt(a);if(s<256){let n=t[s];n!==n&&(n=e(r[a]),t[s]=n),i+=n}else{let t=r[a];s>=55296&&s<=56319&&a+1<o&&(t+=r[a+1],a++);let c=n.get(t);c===void 0&&(c=e(t),n.set(t,c)),i+=c}}return i}}static truncate(e,t,n,r=``,i){let a=t.length,o,s,c;if(i!==void 0&&!r)o=n,s=a,c=Math.min(s,Math.max(0,Math.floor(i)));else{let l=e(t);if(l<=n)return[t,a];o=n-(r?e(r):0),s=a-1,c=i===void 0?Math.min(s,Math.max(0,Math.floor(a*o/l))):Math.min(s,Math.max(0,Math.floor(i)))}let l=n=>e(t.slice(0,n))<=o,u=-1,d=0,f=s;if(o>=0){let e=c;if(l(e)){u=e,d=e+1;for(let t=1;d<=f;t*=2){let n=Math.min(f,e+t);if(!l(n)){f=n-1;break}u=n,d=n+1}}else{f=e-1;for(let t=1;d<=f;t*=2){let n=Math.max(d,e-t);if(l(n)){u=n,d=n+1;break}f=n-1}}for(;d<=f;){let e=d+f>>1;l(e)?(u=e,d=e+1):f=e-1}}if(u<0)return[``,0];if(u===a)return[t,a];let p=u;if(p>0){let e=t.charCodeAt(p-1);e>=55296&&e<=56319&&p--}return[t.slice(0,p)+r,p]}static fontSizeToBox(e=1,t=!0,n){typeof e!=`number`&&(C.warn(`Typography.fontSizeToBox(box, ratio, byHeight) is deprecated: the initial box never affected the result. Use fontSizeToBox(ratio, byHeight) instead.`),e=typeof t==`number`?t:1,t=n===void 0||n);let r=e,i=t;return e=>{let t=D.fromGroup(e);return r*(i?t.height:t.width)}}static fontSizeToThreshold(e,t=0){if(e===0)throw Error(`fontSizeToThreshold: threshold cannot be 0`);return function(n,r){let i=n*r/e;return t<0?Math.min(i,n):t>0?Math.max(i,n):i}}};function fe(e,t,n,r,i,a,o){try{var s=e[a](o),c=s.value}catch(e){n(e);return}s.done?t(c):Promise.resolve(c).then(r,i)}function z(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){fe(a,r,i,o,s,`next`,e)}function s(e){fe(a,r,i,o,s,`throw`,e)}o(void 0)})}}var pe=t({Img:()=>me}),me=class e{constructor(e=!1,t,n){var r;this._scale=1,this._loaded=!1,this._pendingLoadReject=null,this._disposed=!1,this._dataDirty=!1;let i=typeof e==`object`?e:{editable:e,space:t,crossOrigin:n};this._editable=!!i.editable,this._space=i.space,this._scale=(r=i.pixelScale)==null?this._space?this._space.pixelScale:1:r,this._img=new Image,i.crossOrigin&&(this._img.crossOrigin=`Anonymous`)}static load(t,n=!1,r,i){return new e(n,r).load(t).then(e=>(i&&i(e),e))}static loadAsync(t,n=!1,r){return z(function*(){return e.load(t,n,r)})()}static loadPattern(t,n,r=`repeat`,i=!1){return z(function*(){return(yield e.loadAsync(t,i,n)).pattern(r)})()}static blank(t,n,r){let i=new e(!0,n),a=r||(n?n.pixelScale:1);return i.initCanvas(t[0],t[1],a),i}load(e){return this._editable&&typeof document>`u`?Promise.reject(Error(`Cannot create html canvas element. document not found.`)):this._loadImageSrc(e).then(()=>{if(this._disposed)throw Error(`Img has been disposed`);return this._editable&&(this._cv||(this._cv=document.createElement(`canvas`)),this._drawToScale(this._scale,this._img),this._dataDirty=!0),this._loaded=!0,this})}_loadImageSrc(e){return this._disposed?Promise.reject(Error(`Img has been disposed`)):new Promise((t,n)=>{this._pendingLoadReject&&this._pendingLoadReject(Error(`Img loading superseded by a newer load`)),this._pendingLoadReject=n,this._img.onload=()=>{this._pendingLoadReject=null,t()},this._img.onerror=()=>{this._pendingLoadReject=null,n(Error(`Img cannot load ${e}`))},this._img.src=e})}_refreshData(){this._data=this._ctx.getImageData(0,0,this._cv.width,this._cv.height),this._dataDirty=!1}_ensureData(){(this._dataDirty||!this._data)&&this._ctx&&this._cv&&this._refreshData()}_drawToScale(e,t){let n=t.width,r=t.height;this._initCanvas(n,r,e),t&&this._ctx.drawImage(t,0,0,n,r,0,0,this._cv.width,this._cv.height)}initCanvas(e,t,n=1){this._initCanvas(e,t,n)}_initCanvas(e,t,n=1){if(!this._editable){C.warn(`Cannot initiate canvas because this Img is not set to be editable`);return}this._cv||(this._cv=document.createElement(`canvas`));let r=typeof n==`number`?[n,n]:n;this._cv.width=e*r[0],this._cv.height=t*r[1],this._ctx=this._cv.getContext(`2d`,{willReadFrequently:!0}),B.resetStyleCache(this._ctx),typeof n==`number`&&(this._scale=n),this._dataDirty=!0,this._loaded=!0}bitmap(e){let t=e?e[0]:this._cv.width,n=e?e[1]:this._cv.height;return createImageBitmap(this._cv,0,0,t,n)}pattern(e=`repeat`,t=!1){let n=this._space?this._space.ctx:void 0;return n||(this._patternCtx||(this._patternCtx=document.createElement(`canvas`).getContext(`2d`)),n=this._patternCtx),n.createPattern(t?this._cv:this._img,e)}sync(){var e=this;return z(function*(){if(e._disposed)throw Error(`Img has been disposed`);let t=e._cv;e._scale!==1&&(t=document.createElement(`canvas`),t.width=e._cv.width/e._scale,t.height=e._cv.height/e._scale,t.getContext(`2d`).drawImage(e._cv,0,0,e._cv.width,e._cv.height,0,0,t.width,t.height));let n=yield new Promise((e,n)=>{t.toBlob(t=>t?e(t):n(Error(`Img cannot export canvas to blob`)))}),r=URL.createObjectURL(n);e._objectUrl=r;try{if(yield e._loadImageSrc(r),e._disposed)throw Error(`Img has been disposed`);e._loaded=!0}finally{URL.revokeObjectURL(r),e._objectUrl=null}return e})()}pixel(t,n=!0){if(this._ensureData(),!this._data)return C.warn(`Img has no pixel data — create it as editable and wait for load`),new T(0,0,0,0);let r=typeof n==`number`?n:n?this._scale:1;return e.getPixel(this._data,[t[0]*r,t[1]*r])}setPixel(e,t,n=!0){if(this._ensureData(),!this._data)return C.warn(`Img has no pixel data — create it as editable`),this;let r=typeof n==`number`?n:n?this._scale:1,i=Math.floor(e[0]*r),a=Math.floor(e[1]*r);if(i<0||a<0||i>=this._data.width||a>=this._data.height)return this;let o=a*this._data.width*4+i*4;return this._data.data[o]=t[0],this._data.data[o+1]=t[1],this._data.data[o+2]=t[2],this._data.data[o+3]=t[3]===void 0?255:t[3],this}loadPixels(){return this._ctx?(this._refreshData(),this):(C.warn(`Img has no canvas — create it as editable`),this)}updatePixels(){return!this._ctx||!this._data?(C.warn(`Img has no canvas — create it as editable`),this):(this._ctx.putImageData(this._data,0,0),this._dataDirty=!1,this)}static getPixel(e,t){let n=new T(4);if(t[0]<0||t[1]<0||t[0]>=e.width||t[1]>=e.height)return n;let r=Math.floor(t[1])*(e.width*4)+Math.floor(t[0])*4,i=e.data;return r>i.length-4?n:(n[0]=i[r],n[1]=i[r+1],n[2]=i[r+2],n[3]=i[r+3],n)}resize(e,t=!1){let n=this._img.naturalWidth>0,r=n?this._img.naturalWidth:this._cv.width,i=n?this._img.naturalHeight:this._cv.height;if(!r||!i)return C.warn(`Img cannot resize before an image or canvas exists`),this;let a=t?e:[e[0]/r,e[1]/i],o=this._img;if(!n){let e=document.createElement(`canvas`);e.width=this._cv.width,e.height=this._cv.height,e.getContext(`2d`).drawImage(this._cv,0,0),o=e}return this._drawToScale(a,o),this._dataDirty=!0,this}crop(e){let t=this._scale;return this._ctx.getImageData(e[0][0]*t,e[0][1]*t,e.width*t,e.height*t)}filter(e){let t=this._ctx.globalCompositeOperation;return this._ctx.globalCompositeOperation=`copy`,this._ctx.filter=e,this._ctx.drawImage(this._cv,0,0),this._ctx.filter=`none`,this._ctx.globalCompositeOperation=t,this._dataDirty=!0,this}dispose(){var e;return this._disposed=!0,(e=this._pendingLoadReject)==null||e.call(this,Error(`Img has been disposed`)),this._pendingLoadReject=null,this._img&&(this._img.onload=null,this._img.onerror=null,this._img.removeAttribute(`src`)),this._objectUrl&&(URL.revokeObjectURL(this._objectUrl),this._objectUrl=null),this._cv&&this._cv.remove(),this._img&&this._img.remove(),this._cv=null,this._ctx=null,this._patternCtx=null,this._img=null,this._data=null,this._loaded=!1,this}cleanup(){this.dispose()}static fromBlob(t,n=!1,r){let i=URL.createObjectURL(t),a=new e(n,r);a._objectUrl=i;let o=()=>{URL.revokeObjectURL(i),a._objectUrl=null};return a.load(i).then(e=>(o(),e),e=>{throw o(),e})}static imageDataToBlob(e){return new Promise(function(t,n){if(typeof document>`u`){n(Error(`Cannot create html canvas element. document not found.`));return}let r=document.createElement(`canvas`);r.width=e.width,r.height=e.height,r.getContext(`2d`).putImageData(e,0,0),r.toBlob(e=>{t(e),r.remove()})})}toBase64(){return this._cv.toDataURL()}toBlob(){return new Promise(e=>{this._cv.toBlob(t=>e(t))})}getForm(){return this._editable||C.warn(`Cannot get a CanvasForm because this Img is not editable`),this._ctx?new B(this._ctx):void 0}get current(){return this._editable?this._cv:this._img}get image(){return this._img}get canvas(){return this._cv}get data(){return this._ensureData(),this._data}get ctx(){return this._ctx}get loaded(){return this._loaded}get pixelScale(){return this._scale}get imageSize(){return!this._img||!this._img.width||!this._img.height?this._cv?this.canvasSize.$divide(this._scale):new T(0,0):new T(this._img.width,this._img.height)}get canvasSize(){return new T(this._cv.width,this._cv.height)}get scaledMatrix(){let e=1/this._scale;return new p().scale2D([e,e])}},he=t({CanvasForm:()=>B,CanvasSpace:()=>ge}),ge=class extends ae{constructor(e=`pt`,t){super(),this._pixelScale=1,this._bgcolor=`#e1e9f0`,this._offscreen=!1,this._autoResize=!0,this._initialResize=!1,this._disposed=!1,this._ownsCanvas=!1,this._ownsContainer=!1;let n=null,r=!1;if(this.id=C.uniqueId(),e instanceof Element)n=e,this.id=n.id||this.id;else{let t=e||`pt`,r=t[0]===`#`||t[0]===`.`?t:`#`+t;n=document.querySelector(r),this.id=r.substr(1)}n?n.nodeName.toLowerCase()==`canvas`?(this._canvas=n,this._container=n.parentElement,this._autoResize=!1,r=!0):(this._container=n,this._canvas=this._createElement(`canvas`,this.id+`_canvas`),this._initialResize=!0):(this._ownsContainer=!0,this._container=this._createElement(`div`,this.id+`_container`),this._canvas=this._createElement(`canvas`,this.id),document.body.appendChild(this._container)),this._ctx=this._canvas.getContext(`2d`),r?this._readyTimer=window.setTimeout(()=>this._ready(t),100):(this._ownsCanvas=!0,this._readyObserver=new MutationObserver(e=>{e.forEach(e=>{if(e.type===`childList`&&e.addedNodes.length){for(let r of e.addedNodes)if(r===this._canvas){var n;this._ready(t),(n=this._readyObserver)==null||n.disconnect(),this._readyObserver=void 0;return}}})}),this._readyObserver.observe(this._container,{childList:!0}),this._container.appendChild(this._canvas))}_createElement(e=`div`,t){let n=document.createElement(e);return n.setAttribute(`id`,t),n}_ready(e){if(!this._disposed){if(this._readyTimer=void 0,!this._container)throw Error(`Cannot initiate #${this.id} element`);this._isReady=!0,this._resizeHandler(null),this.clear(this._bgcolor),this._canvas.dispatchEvent(new Event(`ready`));for(let e in this.players)this.players.hasOwnProperty(e)&&this.players[e].start&&this.players[e].start(this.bound.clone(),this);this._pointer=this.center,this._initialResize=!1,e&&e(this.bound,this._canvas)}}setup(e){if(this._bgcolor=e.bgcolor?e.bgcolor:`transparent`,this.autoResize=e.resize!=null&&e.resize,e.retina!==!1){let e=window&&window.devicePixelRatio||1;this._pixelScale=Math.max(1,e)}return e.offscreen?(this._offscreen=!0,this._offCanvas=this._createElement(`canvas`,this.id+`_offscreen`),this._offCtx=this._offCanvas.getContext(`2d`)):this._offscreen=!1,e.pixelDensity&&(this._pixelScale=e.pixelDensity),this}set autoResize(e){this._autoResize===e&&(!e||this._resizeObserver)||(this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=void 0),this._autoResize=e,e&&(this._resizeObserver=new ResizeObserver(e=>{this._resizeHandler(null)}),this._resizeObserver.observe(this._container)))}get autoResize(){return this._autoResize}resize(e,t){this.bound=e,this._canvas.width=Math.ceil(this.bound.size.x)*this._pixelScale,this._canvas.height=Math.ceil(this.bound.size.y)*this._pixelScale,this._canvas.style.width=this.bound.size.x+`px`,this._canvas.style.height=this.bound.size.y+`px`,this._offscreen&&(this._offCanvas.width=Math.ceil(this.bound.size.x)*this._pixelScale,this._offCanvas.height=Math.ceil(this.bound.size.y)*this._pixelScale),this._pixelScale!=1&&(this._ctx.scale(this._pixelScale,this._pixelScale),this._offscreen&&this._offCtx.scale(this._pixelScale,this._pixelScale)),B.resetStyleCache(this._ctx),this._offscreen&&B.resetStyleCache(this._offCtx);for(let e in this.players)if(this.players.hasOwnProperty(e)){let n=this.players[e];n.resize&&n.resize(this.bound,t)}return this.render(this._ctx),t&&!this.isPlaying&&this.playOnce(0),this}_resizeHandler(e){let t=this._autoResize||this._initialResize?this._container.getBoundingClientRect():this._canvas.getBoundingClientRect();if(t){var n,r;let i=D.fromBoundingRect(t);i.center=i.center.add(((n=window)==null?void 0:n.scrollX)||0,((r=window)==null?void 0:r.scrollY)||0),this.resize(i,e)}}set background(e){this._bgcolor=e}get background(){return this._bgcolor}get pixelScale(){return this._pixelScale}get hasOffscreen(){return this._offscreen}get offscreenCtx(){return this._offCtx}get offscreenCanvas(){return this._offCanvas}getForm(){return new B(this)}get element(){return this._canvas}get parent(){return this._container}get ready(){return this._isReady}get ctx(){return this._ctx}clear(e){e&&(this._bgcolor=e);let t=this._ctx.fillStyle,n=Math.ceil(this.pixelScale);return!this._bgcolor||this._bgcolor===`transparent`?this._ctx.clearRect(-n,-n,this._canvas.width+n,this._canvas.height+n):((this._bgcolor.indexOf(`rgba`)===0||this._bgcolor.length===9&&this._bgcolor.indexOf(`#`)===0)&&this._ctx.clearRect(-n,-n,this._canvas.width+n,this._canvas.height+n),this._ctx.fillStyle=this._bgcolor,this._ctx.fillRect(-n,-n,this._canvas.width+n,this._canvas.height+n)),this._ctx.fillStyle=t,this}clearOffscreen(e){if(this._offscreen){let t=Math.ceil(this.pixelScale);e?(this._offCtx.fillStyle=e,this._offCtx.fillRect(-t,-t,this._canvas.width+t,this._canvas.height+t)):this._offCtx.clearRect(-t,-t,this._offCanvas.width+t,this._offCanvas.height+t)}return this}playItems(e){this._isReady&&(this._ctx.save(),this._offscreen&&this._offCtx.save(),super.playItems(e),this._ctx.restore(),this._offscreen&&this._offCtx.restore(),B.resetStyleCache(this._ctx),this._offscreen&&B.resetStyleCache(this._offCtx),this.render(this._ctx))}dispose(){return this._disposed?this:(this._disposed=!0,this._readyTimer!==void 0&&(window.clearTimeout(this._readyTimer),this._readyTimer=void 0),this._readyObserver&&(this._readyObserver.disconnect(),this._readyObserver=void 0),this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=void 0),this._unbindAll(),this._cancelAnimation(),this.removeAll(),this._isReady=!1,this._ownsCanvas&&this._canvas.remove(),this._ownsContainer&&this._container.childNodes.length===0&&this._container.remove(),this)}recorder(e,t=`webm`,n=15e6){let r=this._canvas.captureStream(),i=new MediaRecorder(r,{mimeType:`video/${t}`,bitsPerSecond:n});return i.ondataavailable=function(n){let r=URL.createObjectURL(new Blob([n.data],{type:`video/${t}`}));if(typeof e==`function`)e(r);else if(e){let e=document.createElement(`a`);e.href=r,e.download=`canvas_video.${t}`,e.click(),e.remove(),setTimeout(()=>URL.revokeObjectURL(r),100)}},i}};let _e=new WeakMap;var B=class e extends ce{_cacheForCtx(){if(this._styleCacheCtx!==this._ctx){let e=_e.get(this._ctx);e||(e={},_e.set(this._ctx,e)),this._styleCache=e,this._styleCacheCtx=this._ctx}return this._styleCache}static resetStyleCache(e){let t=_e.get(e);if(t)for(let e in t)delete t[e]}_set(e,t){let n=this._cacheForCtx();n[e]!==t&&(n[e]=t,this._ctx[e]=t)}constructor(e){if(super(),this._styleCache=null,this._styleCacheCtx=null,this._style={fillStyle:`#f03`,strokeStyle:`#fff`,lineWidth:1,lineJoin:`bevel`,lineCap:`butt`,globalAlpha:1},!e)return this;let t=e=>{this._ctx=e,this._set(`fillStyle`,this._style.fillStyle),this._set(`strokeStyle`,this._style.strokeStyle),this._set(`lineJoin`,`bevel`),this._set(`font`,this._font.value),this._ready=!0};e instanceof ge?(this._space=e,this._space.ready&&this._space.ctx?t(this._space.ctx):this._space.add({start:()=>{t(this._space.ctx)}})):t(e)}get space(){return this._space}get ctx(){return this._ctx}useOffscreen(e=!0,t=!1){return t&&this._space.clearOffscreen(typeof t==`string`?t:null),this._ctx=this._space.hasOffscreen&&e?this._space.offscreenCtx:this._space.ctx,this}renderOffscreen(e=[0,0]){this._space.hasOffscreen&&this._space.ctx.drawImage(this._space.offscreenCanvas,e[0],e[1],this._space.width,this._space.height)}alpha(e){return this._set(`globalAlpha`,e),this._style.globalAlpha=e,this}fill(e){return typeof e==`boolean`?this.filled=e:(this.filled=!0,this._style.fillStyle=e,this._set(`fillStyle`,e)),this}fillOnly(e){return this.stroke(!1),this.fill(e)}stroke(e,t,n,r){return typeof e==`boolean`?this.stroked=e:(this.stroked=!0,this._style.strokeStyle=e,this._set(`strokeStyle`,e),t&&(this._set(`lineWidth`,t),this._style.lineWidth=t),n&&(this._set(`lineJoin`,n),this._style.lineJoin=n),r&&(this._set(`lineCap`,r),this._style.lineCap=r)),this}strokeOnly(e,t,n,r){return this.fill(!1),this.stroke(e,t,n,r)}applyFillStroke(e=!0,t=!0,n=1){return e&&(typeof e==`string`&&this.fill(e),this._ctx.fill()),t&&(typeof t==`string`&&this.stroke(t,n),this._ctx.stroke()),this}gradient(e){let t=[];e.length<2&&(e=[...e,[.99,`#000`],[1,`#000`]]);for(let n=0,r=e.length;n<r;n++){let r=typeof e[n]==`string`?n*(1/(e.length-1)):e[n][0],i=typeof e[n]==`string`?e[n]:e[n][1];t.push([r,i])}return(e,n)=>{let r=n?this._ctx.createRadialGradient(e[0][0],e[0][1],Math.abs(e[1][0]),n[0][0],n[0][1],Math.abs(n[1][0])):this._ctx.createLinearGradient(e[0][0],e[0][1],e[1][0],e[1][1]);for(let e=0,n=t.length;e<n;e++)r.addColorStop(t[e][0],t[e][1]);return r}}composite(e=`source-over`){return this._set(`globalCompositeOperation`,e),this}clip(){return this._ctx.clip(),this}dash(e=!0,t=0){let n=this._cacheForCtx();if(e===!1||e!==!0&&e.length===0)n.dash!==`/0`&&(n.dash=`/0`,this._ctx.setLineDash([]),this._ctx.lineDashOffset=0);else{let r=e===!0?[5,5]:e,i=`${Array.prototype.join.call(r,`,`)}/${t}`;n.dash!==i&&(n.dash=i,this._ctx.setLineDash(r),this._ctx.lineDashOffset=t)}return this}font(e,t,n,r,i){return typeof e==`number`?(this._font.size=e,i&&(this._font.face=i),t&&(this._font.weight=t),n&&(this._font.style=n),r&&(this._font.lineHeight=r)):this._font=e,this._set(`font`,this._font.value),this._estimateMode&&this.fontWidthEstimate(this._estimateMode),this}fontWidthEstimate(e=!0){if(!e)this._estimateMode=void 0,this._estimateTextWidth=void 0;else{let t=e=>this._ctx.measureText(e).width;this._estimateMode=e===!0?`sample`:e,this._estimateTextWidth=this._estimateMode===`char`?de.charWidthCache(t):de.textWidthEstimator(t)}return this}getTextWidth(e){return this._estimateTextWidth?this._estimateTextWidth(e):this._ctx.measureText(e).width}_textTruncate(e,t,n=``,r){return de.truncate(this.getTextWidth.bind(this),e,t,n,r)}_textAlign(e,t,n,r){let i=C.iterToArray(e);if(!C.arrayCheck(i))return;r||(r=o.center(i));let a=i[0][0];this._ctx.textAlign==`end`||this._ctx.textAlign==`right`?a=i[1][0]:(this._ctx.textAlign==`center`||this._ctx.textAlign==`middle`)&&(a=r[0]);let s=r[1];return t==`top`||t==`start`?s=i[0][1]:(t==`end`||t==`bottom`)&&(s=i[1][1]),n?new T(a+n[0],s+n[1]):new T(a,s)}reset(){let e=this._cacheForCtx();for(let t in this._style)this._style.hasOwnProperty(t)&&(this._ctx[t]=this._style[t],e[t]=this._style[t]);return this._font=new le(14,`sans-serif`),this._ctx.font=this._font.value,e.font=this._font.value,this}_paint(){this._filled&&this._ctx.fill(),this._stroked&&this._ctx.stroke()}static point(t,n,r=5,i=`square`){if(n){if(!e[i])throw Error(`${i} is not a static function of CanvasForm`);e[i](t,n,r)}}point(t,n=5,r=`square`){return e.point(this._ctx,t,n,r),this._paint(),this}static circle(e,t,n=10){t&&(e.beginPath(),e.arc(t[0],t[1],n,0,S.two_pi,!1),e.closePath())}circle(t){let n=C.iterToArray(t);return e.circle(this._ctx,n[0],n[1][0]),this._paint(),this}static ellipse(e,t,n,r=0,i=0,a=S.two_pi,o=!1){!t||!n||(e.beginPath(),e.ellipse(t[0],t[1],n[0],n[1],r,i,a,o))}ellipse(t,n,r=0,i=0,a=S.two_pi,o=!1){return e.ellipse(this._ctx,t,n,r,i,a,o),this._paint(),this}static arc(e,t,n,r,i,a){t&&(e.beginPath(),e.arc(t[0],t[1],n,r,i,a))}arc(t,n,r,i,a){return e.arc(this._ctx,t,n,r,i,a),this._paint(),this}static square(e,t,n){if(!t)return;let r=t[0]-n,i=t[1]-n,a=t[0]+n,o=t[1]+n;e.beginPath(),e.moveTo(r,i),e.lineTo(r,o),e.lineTo(a,o),e.lineTo(a,i),e.closePath()}square(t,n){return e.square(this._ctx,t,n),this._paint(),this}static line(e,t){if(!C.arrayCheck(t))return;e.beginPath();let n=0;if(Array.isArray(t))for(let r=0,i=t.length;r<i;r++){let i=t[r];i&&(n++>0?e.lineTo(i[0],i[1]):e.moveTo(i[0],i[1]))}else for(let r of t)r&&(n++>0?e.lineTo(r[0],r[1]):e.moveTo(r[0],r[1]))}line(t){return e.line(this._ctx,t),this._paint(),this}static polygon(t,n){C.arrayCheck(n)&&(e.line(t,n),t.closePath())}polygon(t){return e.polygon(this._ctx,t),this._paint(),this}static rect(e,t){let n=C.iterToArray(t);C.arrayCheck(n)&&(e.beginPath(),e.moveTo(n[0][0],n[0][1]),e.lineTo(n[0][0],n[1][1]),e.lineTo(n[1][0],n[1][1]),e.lineTo(n[1][0],n[0][1]),e.closePath())}rect(t){return e.rect(this._ctx,t),this._paint(),this}static image(e,t,n,r){let i=C.iterToArray(t),a;if(typeof i[0]==`number`)a=i;else if(r){let e=C.iterToArray(r);a=[e[0][0],e[0][1],e[1][0]-e[0][0],e[1][1]-e[0][1],i[0][0],i[0][1],i[1][0]-i[0][0],i[1][1]-i[0][1]]}else a=[i[0][0],i[0][1],i[1][0]-i[0][0],i[1][1]-i[0][1]];n instanceof me?n.loaded&&e.drawImage(n.image,...a):e.drawImage(n,...a)}image(t,n,r){return n instanceof me?n.loaded&&e.image(this._ctx,t,n.image,r):e.image(this._ctx,t,n,r),this}static imageData(e,t,n){let r=C.iterToArray(t);typeof r[0]==`number`?e.putImageData(n,r[0],r[1]):e.putImageData(n,r[0][0],r[0][1],0,0,r[1][0]-r[0][0],r[1][1]-r[0][1])}imageData(t,n){return e.imageData(this._ctx,t,n),this}static text(e,t,n,r){t&&e.fillText(n,t[0],t[1],r)}text(t,n,r){return e.text(this._ctx,t,n,r),this}textBox(e,t,n=`middle`,r=``,i=!0){i&&(this._ctx.textBaseline=n===`center`?`middle`:n===`start`?`top`:n===`end`?`bottom`:n);let a=o.size(e),s=this._textTruncate(t,a[0],r);return this.text(this._textAlign(e,n),s[0]),this}paragraphBox(e,t,n=1.2,r=`top`,i=!0){let a=E.fromArray(e),s=o.size(a);this._ctx.textBaseline=`top`;let c=this._font.size*n,l=Math.ceil(s[0]/Math.max(1,this.getTextWidth(`n`))),u=[],d=t;for(;d;){var f;if(i&&(u.length+1)*c>s[1])break;let e=this._textTruncate(d,s[0],``,l);e[1]>0&&(l=e[1]);let t=e[0].indexOf(`
5
- `);if(t>=0){u.push(e[0].slice(0,t)),d=d.slice(t+1);continue}let n=e[1]===d.length,r;if(n?r=void 0:d[e[1]]===` `?r=e[1]+1:(r=e[0].lastIndexOf(` `)+1,r<=0&&(r=void 0)),u.push(r===void 0?e[0]:e[0].slice(0,r)),e[1]<=0||n)break;d=d.slice((f=r)==null?e[1]:f)}let p=u.length*c,m=a;if(r==`middle`||r==`center`){let e=(s[1]-p)/2;i&&(e=Math.max(0,e)),m=new E(a[0].$add(0,e),a[1].$subtract(0,e))}else m=r==`bottom`?new E(a[0].$add(0,s[1]-p),a[1]):new E(a[0],a[0].$add(s[0],p));let h=o.center(m);for(let e=0,t=u.length;e<t;e++)this.text(this._textAlign(m,`top`,[0,e*c],h),u[e]);return this}alignText(e=`left`,t=`alphabetic`){return t==`center`&&(t=`middle`),t==`baseline`&&(t=`alphabetic`),this._ctx.textAlign=e,this._ctx.textBaseline=t,this}log(e){let t=this._ctx.measureText(e).width+20;return this.stroke(!1).fill(`rgba(0,0,0,.4)`).rect([[0,0],[t,20]]),this.fill(`#fff`).text([10,14],e),this}};let ve={triangles:new Uint32Array,neighbors:new Int32Array,hull:new Uint32Array},ye=2147483648,V=new Float64Array(8),H=0;function be(e){if(H>0)return H;let t=1;for(let n=0;n<=30;n++){let n=!0;for(let r=0;r<e;r++){let e=V[r]*t;if(e>=ye||e<=-2147483648)return 0;(e|0)!==e&&(n=!1)}if(n)return t;t*=2}return 0}function U(e,t,n,r,i,a){let o=(e-i)*(r-a),s=(t-a)*(n-i),c=o-s,l=33306690738754716e-32*(Math.abs(o)+Math.abs(s));if(c>l)return 1;if(-c>l)return-1;V[0]=e,V[1]=t,V[2]=n,V[3]=r,V[4]=i,V[5]=a;let u=be(6);return u===0?Ue(e,t,n,r,i,a):Ne((e-i)*u,(r-a)*u,(t-a)*u,(n-i)*u)}function xe(e,t,n,r,i,a,o,s){let c=e-o,l=t-s,u=n-o,d=r-s,f=i-o,p=a-s,m=u*p,h=f*d,g=c*c+l*l,_=f*l,v=c*p,y=u*u+d*d,b=c*d,x=u*l,S=f*f+p*p,C=g*(m-h)+y*(_-v)+S*(b-x),w=11102230246251577e-31*((Math.abs(m)+Math.abs(h))*g+(Math.abs(_)+Math.abs(v))*y+(Math.abs(b)+Math.abs(x))*S);if(C>w)return 1;if(-C>w)return-1;V[0]=e,V[1]=t,V[2]=n,V[3]=r,V[4]=i,V[5]=a,V[6]=o,V[7]=s;let T=be(8);return T===0?We(e,t,n,r,i,a,o,s):Ie(c*T,l*T,u*T,d*T,f*T,p*T)}let Se=262144,W=new Float64Array(8),Ce=new Float64Array(4),we=new Float64Array(4),Te=new Float64Array(4),Ee=new Float64Array(4),De=new Float64Array(4),Oe=new Float64Array(4);function G(e,t,n,r){let i=e&262143,a=e>>>18,o=t&262143,s=t>>>18;W[r]+=n*i*o,W[r+1]+=n*(i*s+a*o),W[r+2]+=n*a*s}function ke(e,t,n){for(let r=0;r<4;r++){let i=n*e[r];if(i!==0)for(let e=0;e<4;e++)W[r+e]+=i*t[e]}}function Ae(e){let t=0;for(let n=0;n<e;n++){let e=W[n]+t;t=Math.floor(e*3814697265625e-18),W[n]=e-t*Se}return t}function je(e,t){if(t!==0)return t>0?1:-1;for(let t=0;t<e;t++)if(W[t]!==0)return 1;return 0}function Me(e,t,n){if(t>=0){let r=t===0;for(let t=0;t<e;t++)n[t]=W[t],W[t]!==0&&(r=!1);return n[e]=t,+!r}let r=1;for(let t=0;t<e;t++){let e=262143-W[t]+r;r=0,e===Se&&(e=0,r=1),n[t]=e}return n[e]=-t-1+r,-1}function Ne(e,t,n,r){return W[0]=0,W[1]=0,W[2]=0,G(Math.abs(e),Math.abs(t),e<0==t<0?1:-1,0),G(Math.abs(n),Math.abs(r),n<0==r<0?-1:1,0),je(3,Ae(3))}function Pe(e,t,n){W[0]=0,W[1]=0,W[2]=0,G(Math.abs(e),Math.abs(e),1,0),G(Math.abs(t),Math.abs(t),1,0);let r=Ae(3);n[0]=W[0],n[1]=W[1],n[2]=W[2],n[3]=r}function Fe(e,t,n,r,i){return W[0]=0,W[1]=0,W[2]=0,G(Math.abs(e),Math.abs(t),e<0==t<0?1:-1,0),G(Math.abs(n),Math.abs(r),n<0==r<0?-1:1,0),Me(3,Ae(3),i)}function Ie(e,t,n,r,i,a){Pe(e,t,Ce),Pe(n,r,we),Pe(i,a,Te);let o=Fe(n,a,i,r,Ee),s=Fe(i,t,e,a,De),c=Fe(e,r,n,t,Oe);for(let e=0;e<7;e++)W[e]=0;return o!==0&&ke(Ce,Ee,o),s!==0&&ke(we,De,s),c!==0&&ke(Te,Oe,c),je(7,Ae(7))}let Le=new Float64Array(1),K=new Uint32Array(Le.buffer);Le[0]=1;let Re=+(K[1]===1072693248),ze=Re^1,Be=new Float64Array(8),Ve=new Int32Array(8);function He(e,t){let n=2147483647;for(let r=0;r<t;r++){Le[0]=e[r];let t=K[Re],i=t>>>20&2047,a=(t&1048575)*4294967296+K[ze],o=-1074;i!==0&&(a+=4503599627370496,o=i-1075),Be[r]=t>>>31?-a:a,Ve[r]=o,a!==0&&o<n&&(n=o)}let r=[];for(let e=0;e<t;e++)r.push(Be[e]===0?BigInt(0):BigInt(Be[e])<<BigInt(Ve[e]-n));return r}function Ue(e,t,n,r,i,a){V[0]=e,V[1]=t,V[2]=n,V[3]=r,V[4]=i,V[5]=a;let o=He(V,6),s=(o[0]-o[4])*(o[3]-o[5])-(o[1]-o[5])*(o[2]-o[4]),c=BigInt(0);return s>c?1:s<c?-1:0}function We(e,t,n,r,i,a,o,s){V[0]=e,V[1]=t,V[2]=n,V[3]=r,V[4]=i,V[5]=a,V[6]=o,V[7]=s;let c=He(V,8),l=c[0]-c[6],u=c[1]-c[7],d=c[2]-c[6],f=c[3]-c[7],p=c[4]-c[6],m=c[5]-c[7],h=(l*l+u*u)*(d*m-p*f)+(d*d+f*f)*(p*u-l*m)+(p*p+m*m)*(l*f-d*u),g=BigInt(0);return h>g?1:h<g?-1:0}function Ge(e,t,n){let r=1<<e,i=0;for(let e=r>>1;e>0;e>>=1){let a=(t&e)===0?0:1,o=(n&e)===0?0:1;if(i+=e*e*(3*a^o),o===0){a===1&&(t=r-1-t,n=r-1-n);let e=t;t=n,n=e}}return i}function Ke(e,t){let n=1/0,r=1/0,i=-1/0,a=-1/0;for(let o=0;o<t;o++){let t=e[2*o],s=e[2*o+1];!Number.isFinite(t)||!Number.isFinite(s)||(t<n&&(n=t),t>i&&(i=t),s<r&&(r=s),s>a&&(a=s))}let o=2;for(;o<16&&1<<2*o<16*t;)o++;let s=(1<<o)-1,c=Math.max(i-n,a-r),l=c>0&&Number.isFinite(c)?s/c:0,u=new Uint32Array(t);for(let i=0;i<t;i++){let t=e[2*i],a=e[2*i+1],c=0,d=0;Number.isFinite(t)&&Number.isFinite(a)&&(c=Math.min(s,Math.max(0,Math.floor((t-n)*l))),d=Math.min(s,Math.max(0,Math.floor((a-r)*l)))),u[i]=Ge(o,c,d)}let d=new Uint32Array(t),f=new Uint32Array(t);for(let e=0;e<t;e++)d[e]=e;let p=new Int32Array(257);for(let e=0;e<2*o;e+=8){p.fill(0);for(let n=0;n<t;n++)p[(u[n]>>>e&255)+1]++;for(let e=0;e<256;e++)p[e+1]+=p[e];for(let n=0;n<t;n++){let t=d[n];f[p[u[t]>>>e&255]++]=t}let n=d;d=f,f=n}return d}function qe(e,t=e.length>>1){if(t<3)return ve;H=Je(e,t);try{return Ye(e,t)}finally{H=0}}function Je(e,t){let n=0,r=0;for(let i=0;i<2*t;i++){let t=e[i];if(!Number.isFinite(t)||t===0)continue;Math.abs(t)>r&&(r=Math.abs(t)),Le[0]=t;let a=K[Re],o=K[ze],s=a>>>20&2047,c=s===0?-1074:s-1075,l;if(o!==0)l=31-Math.clz32(o&-o);else{let e=a&1048575|(s===0?0:1048576);l=32+(31-Math.clz32(e&-e))}let u=-(c+l);if(u>n&&(n=u),n>30)return 0}let i=Math.pow(2,n);return r*i<ye?i:0}function Ye(e,t){let n=Ke(e,t),r=-1,i=-1,a=-1,o=0;for(;o<t;o++){let t=n[o];if(Number.isFinite(e[2*t])&&Number.isFinite(e[2*t+1])){r=t,o++;break}}if(r<0)return ve;for(;o<t;o++){let t=n[o],a=e[2*t],s=e[2*t+1];if(Number.isFinite(a)&&Number.isFinite(s)&&(a!==e[2*r]||s!==e[2*r+1])){i=t,o++;break}}if(i<0)return ve;for(;o<t;o++){let t=n[o],s=e[2*t],c=e[2*t+1];if(!Number.isFinite(s)||!Number.isFinite(c))continue;let l=U(e[2*r],e[2*r+1],e[2*i],e[2*i+1],s,c);if(l!==0){if(a=t,l<0){let e=i;i=a,a=e}break}}if(a<0)return ve;let s=t,c=2*t+4,l=new Int32Array(c*3),u=new Int32Array(c*3),d=new Uint8Array(c),f=new Int32Array(c),p=new Int32Array(c),m=0,h=0,g=new Int32Array(c),_=new Int32Array(c),v=new Int32Array(c*3),y=new Int32Array(c*3),b=new Int32Array(c*3),x=new Int32Array(t+1),S=new Int32Array(t+1),C=0,w=(e,t,n)=>{let r=m>0?p[--m]:h++,i=3*r;return l[i]=e,l[i+1]=t,l[i+2]=n,d[r]=1,r},T=(e,t)=>{u[e]=t,u[t]=e},E=w(r,i,a),D=w(i,r,s),O=w(a,i,s),k=w(r,a,s);T(3*E,3*D),T(3*E+1,3*O),T(3*E+2,3*k),T(3*D+1,3*k+2),T(3*O+1,3*D+2),T(3*k+1,3*O+2);let ee=(t,n,r)=>{let i=l[3*t],a=l[3*t+1],o=e[2*i],s=e[2*i+1],c=e[2*a],u=e[2*a+1],d=U(o,s,c,u,n,r);return d===0?Math.abs(c-o)>=Math.abs(u-s)?c>o?n>o&&n<c:n<o&&n>c:u>s?r>s&&r<u:r<s&&r>u:d>0},A=(t,n,r)=>{let i=3*t;if(l[i+2]===s)return ee(t,n,r);let a=l[i],o=l[i+1],c=l[i+2];return xe(e[2*a],e[2*a+1],e[2*o],e[2*o+1],e[2*c],e[2*c+1],n,r)>0},te=(t,n,r)=>{let i=0,a=4*h+64;for(;;){let o=3*t,c=l[o],d=l[o+1],f=l[o+2],p=e[2*c],m=e[2*c+1],h=e[2*d],g=e[2*d+1];if(f===s){if(U(p,m,h,g,n,r)>0)return t;t=u[o]/3|0}else{let i=e[2*f],a=e[2*f+1];if(U(p,m,h,g,n,r)<0)t=u[o]/3|0;else if(U(h,g,i,a,n,r)<0)t=u[o+1]/3|0;else if(U(i,a,p,m,n,r)<0)t=u[o+2]/3|0;else if(n===p&&r===m||n===h&&r===g||n===i&&r===a)return-1;else return t}if(++i>a)throw Error(`Delaunay walk did not terminate`)}},j=(t,n)=>{let r=e[2*t],i=e[2*t+1],a=te(n,r,i);if(a<0)return n;C++;let o=0,c=0;for(g[o++]=a,f[a]=C;o>0;){let e=g[--o];_[c++]=e;let t=3*e;for(let e=0;e<3;e++){let n=u[t+e]/3|0;f[n]!==C&&A(n,r,i)&&(f[n]=C,g[o++]=n)}}let h=0;for(let e=0;e<c;e++){let t=3*_[e];for(let e=0;e<3;e++){let n=u[t+e];f[n/3|0]!==C&&(v[h]=l[t+e],y[h]=l[t+(e+1)%3],b[h]=n,h++)}}for(let e=0;e<c;e++)d[_[e]]=0,p[m++]=_[e];let E=-1;for(let e=0;e<h;e++){let n=v[e],r=y[e],i,a,o,c;n===s?(i=w(r,t,s),a=3*i+2,o=3*i,c=3*i+1):r===s?(i=w(t,n,s),a=3*i+1,o=3*i+2,c=3*i):(i=w(n,r,t),a=3*i,o=3*i+1,c=3*i+2,E<0&&(E=i)),T(a,b[e]),x[r]=o,S[n]=c}for(let e=0;e<h;e++){let t=y[e];T(x[t],S[t])}return E<0?n:E},ne=E;for(let o=0;o<t;o++){let t=n[o];t!==r&&t!==i&&t!==a&&(!Number.isFinite(e[2*t])||!Number.isFinite(e[2*t+1])||(ne=j(t,ne)))}let M=new Int32Array(h),N=0,P=-1;for(let e=0;e<h;e++)d[e]?l[3*e+2]===s?(M[e]=-1,P=e):M[e]=N++:M[e]=-1;let F=new Uint32Array(N*3),I=new Int32Array(N*3);for(let e=0;e<h;e++){let t=M[e];if(!(t<0))for(let n=0;n<3;n++){F[3*t+n]=l[3*e+n];let r=u[3*e+n],i=M[r/3|0];I[3*t+n]=i<0?-1:3*i+r%3}}let L=0,R=P;do L++,R=u[3*R+2]/3|0;while(R!==P);let re=new Uint32Array(L);R=P;for(let e=0;e<L;e++)re[e]=l[3*R+1],R=u[3*R+2]/3|0;return{triangles:F,neighbors:I,hull:re}}var Xe=t({Boid:()=>q,Create:()=>Ze,Delaunay:()=>ct,Flock:()=>ft,Noise:()=>it}),Ze=class{static distributeRandom(e,t,n=2){let r=new E;for(let i=0;i<t;i++){let t=[e.x+_.random()*e.width];n>1&&t.push(e.y+_.random()*e.height),n>2&&t.push(e.z+_.random()*e.depth),r.push(new T(t))}return r}static distributeLinear(e,t){if(t<=0)return new E;let n=C.iterToArray(e);if(t===1)return new E(n[0]);let r=a.subpoints(n,t-2);return r.unshift(n[0]),r.push(n[n.length-1]),r}static gridPts(e,t,n,r=[.5,.5]){if(t===0||n===0)throw Error(`grid columns and rows cannot be 0`);let i=e.size.$subtract(1).$divide(t,n),a=i.$multiply(r),o=new E;for(let r=0;r<n;r++)for(let n=0;n<t;n++)o.push(e.topLeft.$add(i.$multiply(n,r)).add(a));return o}static gridCells(e,t,n){if(t===0||n===0)throw Error(`grid columns and rows cannot be 0`);let r=e.size.$subtract(1).divide(t,n),i=[];for(let a=0;a<n;a++)for(let n=0;n<t;n++)i.push(new E(e.topLeft.$add(r.$multiply(n,a)),e.topLeft.$add(r.$multiply(n,a).add(r))));return i}static radialPts(e,t,n,r=-S.half_pi){let i=new E,a=S.two_pi/n;for(let o=0;o<n;o++)i.push(new T(e).toAngle(a*o+r,t,!0));return i}static noisePts(e,t=.01,n=.01,r=0,i=0){let a=_.random(),o=new E,s=0,c=i>0?i:r>0?r:0;for(let r of e){let e=new it(r),i=c>0?Math.floor(s/c):s,l=c>0?s%c:s;e.initNoise(t*l,n*i),e.seed(a),o.push(e),s++}return o}static delaunay(e){return ct.from(e)}static flock(e,t={}){let n=new ft;n.setup(t);for(let t of e)n.addBoid(t);return n}};let Qe=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],$e=[151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,129,22,39,253,9,98,108,110,79,113,224,232,178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180],et=$e.concat($e),tt,nt=null;function rt(e){if(e===tt&&nt)return nt;let t=e;t>0&&t<1&&(t*=65536),t=Math.floor(t),t<256&&(t|=t<<8);let n=Array(512);for(let e=0;e<256;e++){let r=e&1?$e[e]^t&255:$e[e]^t>>8&255;n[e]=n[e+256]=r}return tt=e,nt=n,n}var it=class extends T{constructor(...e){super(...e),this.perm=[],this._n=new T(.01,.01),this.perm=et}initNoise(...e){return this._n=new T(...e),this}step(e=0,t=0){return this._n.add(e,t),this}seed(e){return this.perm=rt(e),this}noise2D(){let e=this.perm,t=this._n[0],n=this._n[1],r=Math.floor(t),i=Math.floor(n),a=r&255,o=i&255,s=t-r,c=n-i,l=Qe[e[a+e[o]]%12],u=Qe[e[a+e[o+1]]%12],d=Qe[e[a+1+e[o]]%12],f=Qe[e[a+1+e[o+1]]%12],p=l[0]*s+l[1]*c,m=u[0]*s+u[1]*(c-1),h=d[0]*(s-1)+d[1]*c,g=f[0]*(s-1)+f[1]*(c-1),_=e=>e*e*e*(e*(e*6-15)+10),v=_(s),y=p+v*(h-p),b=m+v*(g-m);return y+_(c)*(b-y)}};function at(e,t,n,r,i){let a=!0;for(let o=0,s=e.length;o<s;o++){let s=e[o][0],c=e[o][1];if(s<t||s>r||c<n||c>i||!Number.isFinite(s+c)){a=!1;break}}if(a)return e;if(e.length<3){let a=new E;for(let o=0,s=e.length;o<s;o++){let s=e[o][0],c=e[o][1];s>=t&&s<=r&&c>=n&&c<=i&&a.push(e[o])}return a}let o=1e7,s=[];for(let t=0,n=e.length;t<n;t++){let n=e[t][0],r=e[t][1];Number.isFinite(n)||(n=n>0?o:-1e7),Number.isFinite(r)||(r=r>0?o:-1e7),!(Number.isNaN(n)||Number.isNaN(r))&&s.push([n,r])}let c=(e,t,n)=>{let r=[];for(let i=0,a=e.length;i<a;i++){let o=e[i===0?a-1:i-1],s=e[i],c=t(s);t(o)?c?r.push(s):r.push(n(o,s)):c&&r.push(n(o,s),s)}return r},l=(e,t,n)=>[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n];s=c(s,e=>e[0]>=t,(e,n)=>l(e,n,(t-e[0])/(n[0]-e[0]))),s=c(s,e=>e[0]<=r,(e,t)=>l(e,t,(r-e[0])/(t[0]-e[0]))),s=c(s,e=>e[1]>=n,(e,t)=>l(e,t,(n-e[1])/(t[1]-e[1]))),s=c(s,e=>e[1]<=i,(e,t)=>l(e,t,(i-e[1])/(t[1]-e[1])));let u=new E;for(let e=0,t=s.length;e<t;e++)u.push(new T(s[e]));return u}function ot(e,t,n){let r=n[0]-t[0],i=n[1]-t[1],a=t[0]+r/2,o=t[1]+i/2,s=new E;for(let t=0;t<e.length;t++){let n=e[t===0?e.length-1:t-1],c=e[t],l=(n[0]-a)*r+(n[1]-o)*i,u=(c[0]-a)*r+(c[1]-o)*i;if(l<=0!=u<=0){let e=l/(l-u);s.push(new T(n[0]+(c[0]-n[0])*e,n[1]+(c[1]-n[1])*e))}u<=0&&s.push(c)}return s}function st(e,t,n,r,i,a){let o=n-e,s=r-t,c=i-e,l=a-t,u=2*(o*l-s*c),d=o*o+s*s,f=c*c+l*l,p=(l*d-s*f)/u,m=(o*f-c*d)/u;return[e+p,t+m,Math.sqrt(p*p+m*m)]}var ct=class extends E{constructor(...e){super(...e),this._mesh=[],this._meshBuilt=!0,this._count=0,this._tri=null,this._shapes=null}delaunay(e=!0){let t=this.length;if(this._count=t,this._mesh=[],this._meshBuilt=!1,this._tri=null,this._shapes=null,t<3)return[];let n=new Float64Array(t*2);for(let e=0;e<t;e++)n[2*e]=this[e][0],n[2*e+1]=this[e][1];let r=qe(n,t);if(r.triangles.length===0)return[];this._tri=r;let i=r.triangles,a=[],o=[];for(let e=0,t=i.length;e<t;e+=3){let t=i[e],r=i[e+1],s=i[e+2],c=this._triangle(t,r,s),[l,u,d]=st(n[2*t],n[2*t+1],n[2*r],n[2*r+1],n[2*s],n[2*s+1]),f=new E(new T(l,u),new T(d,d));a.push({i:t,j:r,k:s,triangle:c,circle:f}),o.push(c)}return this._shapes=a,e?o:a}_ensureMesh(){if(!this._meshBuilt){this._meshBuilt=!0,this._mesh=[];for(let e=0;e<this._count;e++)this._mesh[e]={};if(this._shapes)for(let e=0,t=this._shapes.length;e<t;e++)this._cache(this._shapes[e])}return this._mesh}voronoi(e){let t=this._voronoiCells();if(!e)return t;let n=v.boundingBox(C.iterToArray(e)),r=n[0][0],i=n[0][1],a=n[1][0],o=n[1][1],s=new Set;if(this._tri)for(let e of this._tri.hull)s.add(e);let c=new Set;for(let e=0,n=t.length;e<n;e++){let n=`${this[e][0]},${this[e][1]}`;if(c.has(n)){t[e]=new E;continue}if(c.add(n),!s.has(e)&&t[e].length>=3){t[e]=at(t[e],r,i,a,o);continue}let l=new Set;for(let t of this.neighbors(e))for(let n of[t.i,t.j,t.k])n!==e&&l.add(n);if(l.size===0)for(let t=0;t<this.length;t++)t!==e&&l.add(t);let u=E.fromArray([[r,i],[a,i],[a,o],[r,o]]);for(let t of l)u=ot(u,this[e],this[t]);t[e]=u}return t}_voronoiCells(){let e=this._tri,t=this._shapes;if(!e||!t){let e=[],t=this._ensureMesh();for(let n=0,r=t.length;n<r;n++)e.push(this.neighborPts(n,!0));return e}let n=this._count,r=e.triangles,i=e.neighbors,a=new Int32Array(n).fill(-1);for(let e=0,t=r.length;e<t;e++){let t=r[e];(i[e]===-1||a[t]===-1)&&(a[t]=e)}let o=[];for(let e=0;e<n;e++){let n=new E,r=a[e];if(r!==-1){let e=r/3|0;for(;;){let a=r/3|0;n.push(t[a].circle[0]);let o=i[3*a+(r+2)%3];if(o===-1||(o/3|0)===e)break;r=o}}o.push(n)}return o}mesh(){return this._ensureMesh()}neighborPts(e,t=!1){let n=new E,r=this._ensureMesh();for(let t in r[e])r[e].hasOwnProperty(t)&&n.push(r[e][t].circle[0]);return t&&n.length>1?v.sortEdges(n):n}neighbors(e){let t=[],n=this._ensureMesh();for(let r in n[e])n[e].hasOwnProperty(r)&&t.push(n[e][r]);return t}_cache(e){this._mesh[e.i][`${Math.min(e.j,e.k)}-${Math.max(e.j,e.k)}`]=e,this._mesh[e.j][`${Math.min(e.i,e.k)}-${Math.max(e.i,e.k)}`]=e,this._mesh[e.k][`${Math.min(e.i,e.j)}-${Math.max(e.i,e.j)}`]=e}_superTriangle(){let e=this[0],t=this[0];for(let n=1,r=this.length;n<r;n++)e=e.$min(this[n]),t=t.$max(this[n]);let n=t.$subtract(e),r=e.$add(t).divide(2),i=Math.max(n[0],n[1]);return new E(r.$subtract(20*i,i),r.$add(0,20*i),r.$add(20*i,-i))}_triangle(e,t,n,r=this){return new E(r[e],r[t],r[n])}_circum(e,t,n,r,i=this){let a=r||this._triangle(e,t,n,i);return{i:e,j:t,k:n,triangle:a,circle:c.circumcircle(a)}}static _dedupe(e){let t=e.length;for(;t>1;){let n=e[--t],r=e[--t],i=t;for(;i>1;){let a=e[--i],o=e[--i];if(r==o&&n==a||r==a&&n==o){e.splice(t,2),e.splice(i,2);break}}}return e}};function lt(e,t,n,r){let i=t*t+n*n;if(i<=0)return;let a=r/Math.sqrt(i);e[0]+=t*a,e[1]+=n*a}let ut=2147483647,dt=-2147483648;var q=class extends T{constructor(...e){super(...e),this._vel=new T(0,0)}get velocity(){return this._vel}set velocity(e){this._vel=e}get speed(){return Math.sqrt(this._vel[0]*this._vel[0]+this._vel[1]*this._vel[1])}get heading(){return Math.atan2(this._vel[1],this._vel[0])}},ft=class extends E{constructor(...e){super(...e),this._perception=40,this._separation=20,this._cohesionWeight=1,this._alignWeight=1,this._separateWeight=1.5,this._maxSpeed=100,this._minSpeed=0,this._maxForce=200,this._boundary=`steer`,this._margin=50,this._maxTimeStep=50,this._bound=null,this._initialSpeed=void 0,this._pos=new Float32Array,this._vel=new Float32Array,this._sums=new Float32Array,this._counts=new Uint32Array,this._hashKeys=new Uint32Array,this._cellX=new Int32Array,this._cellY=new Int32Array,this._cellStart=new Uint32Array,this._cellEntries=new Uint32Array,this._steerOut=new Float32Array(2)}setup(e){return e.perception!==void 0&&(this.perception=e.perception),e.separation!==void 0&&(this.separation=e.separation),e.cohesionWeight!==void 0&&(this._cohesionWeight=e.cohesionWeight),e.alignWeight!==void 0&&(this._alignWeight=e.alignWeight),e.separateWeight!==void 0&&(this._separateWeight=e.separateWeight),e.maxSpeed!==void 0&&(this.maxSpeed=e.maxSpeed),e.minSpeed!==void 0&&(this.minSpeed=e.minSpeed),e.maxForce!==void 0&&(this._maxForce=e.maxForce),e.bound!==void 0&&(this._bound=e.bound),e.boundary!==void 0&&(this._boundary=e.boundary),e.margin!==void 0&&(this.margin=e.margin),e.maxTimeStep!==void 0&&(this.maxTimeStep=e.maxTimeStep),e.initialSpeed!==void 0&&(this._initialSpeed=e.initialSpeed),this}get perception(){return this._perception}set perception(e){this._perception=Math.max(0,e)}get separation(){return this._separation}set separation(e){this._separation=Math.max(0,e)}get cohesionWeight(){return this._cohesionWeight}set cohesionWeight(e){this._cohesionWeight=e}get alignWeight(){return this._alignWeight}set alignWeight(e){this._alignWeight=e}get separateWeight(){return this._separateWeight}set separateWeight(e){this._separateWeight=e}get maxSpeed(){return this._maxSpeed}set maxSpeed(e){this._maxSpeed=Math.max(0,e)}get minSpeed(){return this._minSpeed}set minSpeed(e){this._minSpeed=Math.max(0,e)}get maxForce(){return this._maxForce}set maxForce(e){this._maxForce=e}get bound(){return this._bound}set bound(e){this._bound=e}get boundary(){return this._boundary}set boundary(e){this._boundary=e}get margin(){return this._margin}set margin(e){this._margin=Math.max(0,e)}get maxTimeStep(){return this._maxTimeStep}set maxTimeStep(e){this._maxTimeStep=Math.max(0,e)}get initialSpeed(){return this._initialSpeed===void 0?this._maxSpeed*.5:this._initialSpeed}set initialSpeed(e){this._initialSpeed=e}addBoid(e,t){let n=e instanceof q,r=n?e:new q(e);if(t!==void 0)r.velocity[0]=t[0],r.velocity[1]=t[1];else if(!n){let e=_.random()*S.two_pi,t=this.initialSpeed;r.velocity[0]=Math.cos(e)*t,r.velocity[1]=Math.sin(e)*t}return this.push(r),this}step(e){let t=this.length;if(t===0||!(e>0))return this;let n=Math.min(e,this._maxTimeStep)/1e3;return n<=0?this:(this._ensureBuffers(t),this._gather(t),t>1&&this._perception>0?this._accumulate(t):(this._sums.fill(0,0,t*6),this._counts.fill(0,0,t)),this._integrate(t,n),this._scatter(t),this)}_ensureBuffers(e){if(this._pos.length<e*2){let t=e*2*2;this._pos=new Float32Array(t),this._vel=new Float32Array(t),this._sums=new Float32Array(t*3),this._counts=new Uint32Array(t),this._hashKeys=new Uint32Array(t),this._cellX=new Int32Array(t),this._cellY=new Int32Array(t),this._cellEntries=new Uint32Array(t)}}_gather(e){let t=this._pos,n=this._vel;for(let r=0;r<e;r++){let e=this[r],i=e.velocity;i===void 0&&(e=new q(e),i=e.velocity,this[r]=e);let a=r*2;t[a]=e[0],t[a+1]=e[1],n[a]=i[0],n[a+1]=i[1]}}_scatter(e){let t=this._pos,n=this._vel;for(let r=0;r<e;r++){let e=this[r],i=e.velocity,a=r*2;e[0]=t[a],e[1]=t[a+1],i[0]=n[a],i[1]=n[a+1]}}_accumulate(e){let t=this._pos,n=this._vel,r=this._sums,i=this._counts;r.fill(0,0,e*6),i.fill(0,0,e);let a=this._perception*this._perception,o=Math.min(this._separation,this._perception),s=o*o,c=o*.01,l=c*c,u=1/this._perception,d=16;for(;d<e*2;)d<<=1;let f=d-1;this._cellStart.length<d+1&&(this._cellStart=new Uint32Array(d+1));let p=this._hashKeys,m=this._cellX,h=this._cellY,g=this._cellStart,_=this._cellEntries;g.fill(0,0,d+1);for(let n=0;n<e;n++){let e=Math.floor(t[n*2]*u),r=Math.floor(t[n*2+1]*u);e>=-2147483647&&e<=ut&&r>=-2147483647&&r<=ut?(m[n]=e,h[n]=r):(m[n]=dt,h[n]=dt);let i=(Math.imul(m[n],2654435761)^Math.imul(h[n],2246822519))>>>0&f;p[n]=i,g[i]++}let v=0;for(let e=0;e<d;e++){let t=g[e];g[e]=v,v+=t}g[d]=v;for(let t=0;t<e;t++)_[g[p[t]]++]=t;for(let o=0;o<e;o++){let e=m[o];if(e===dt)continue;let c=h[o],u=o*2,d=t[u],p=t[u+1],v=n[u],y=n[u+1],b=o*6;for(let u=0;u<5;u++){let x=u===2?e-1:u===0||u===3?e:e+1,S=u<2?c:c+1,C=(Math.imul(x,2654435761)^Math.imul(S,2246822519))>>>0&f,w=g[C],T=C>0?g[C-1]:0;for(let e=T;e<w;e++){let c=_[e];if(m[c]!==x||h[c]!==S||u===0&&c<=o)continue;let f=c*2,g=t[f],C=t[f+1],w=g-d,T=C-p,E=w*w+T*T;if(!(E<a))continue;let D=c*6;if(r[b]+=g,r[b+1]+=C,r[D]+=d,r[D+1]+=p,r[b+2]+=n[f],r[b+3]+=n[f+1],r[D+2]+=v,r[D+3]+=y,i[o]++,i[c]++,E<s){let e=w,t=T,n=E;n===0?(e=1,t=0,n=l):n<l&&(n=l);let i=1/n,a=e*i,o=t*i;r[b+4]-=a,r[b+5]-=o,r[D+4]+=a,r[D+5]+=o}}}}}_integrate(e,t){let n=this._pos,r=this._vel,i=this._sums,a=this._counts,o=this._steerOut,s=this._maxSpeed,c=this._maxForce,l=Math.min(this._minSpeed,s),u=this._cohesionWeight,d=this._alignWeight,f=this._separateWeight,p=this._bound,m=p?this._boundary:`none`,h=m===`steer`&&this._margin>0,g=m===`wrap`,_=m===`bounce`,v=0,y=0,b=0,x=0;if(p&&m!==`none`){let e=p[0],t=p[1];v=Math.min(e[0],t[0]),y=Math.min(e[1],t[1]),b=Math.max(e[0],t[0]),x=Math.max(e[1],t[1])}let S=this._margin;for(let p=0;p<e;p++){let e=p*2,m=p*6,C=n[e],w=n[e+1],T=r[e],E=r[e+1];o[0]=0,o[1]=0;let D=a[p];D>0&&(u!==0&&lt(o,i[m]/D-C,i[m+1]/D-w,u),d!==0&&lt(o,i[m+2],i[m+3],d),f!==0&&lt(o,i[m+4],i[m+5],f));let O=0,k=0,ee=o[0]*o[0]+o[1]*o[1];if(ee>0){let e=s/Math.sqrt(ee);O=o[0]*e-T,k=o[1]*e-E;let t=O*O+k*k;if(t>c*c){let e=c/Math.sqrt(t);O*=e,k*=e}}if(h){let e=C-v,t=b-C,n=w-y,r=x-w;e<S?O+=c*(1-Math.max(e,0)/S):t<S&&(O-=c*(1-Math.max(t,0)/S)),n<S?k+=c*(1-Math.max(n,0)/S):r<S&&(k-=c*(1-Math.max(r,0)/S))}T+=O*t,E+=k*t;let A=T*T+E*E;if(A>s*s){let e=s/Math.sqrt(A);T*=e,E*=e}else if(l>0&&A<l*l){if(A>0){let e=l/Math.sqrt(A);T*=e,E*=e}else T=l,E=0}if(C+=T*t,w+=E*t,g){let e=b-v,t=x-y;e>0&&(C<v?C=b-(v-C)%e:C>b&&(C=v+(C-b)%e)),t>0&&(w<y?w=x-(y-w)%t:w>x&&(w=y+(w-x)%t))}else _&&(C<=v?(C=v,T<0&&(T=-T)):C>=b&&(C=b,T>0&&(T=-T)),w<=y?(w=y,E<0&&(E=-E)):w>=x&&(w=x,E>0&&(E=-E)));n[e]=C,n[e+1]=w,r[e]=T,r[e+1]=E}}},pt=t({Color:()=>mt}),mt=class e extends T{constructor(...e){super(...e),this._mode=`rgb`,this._isNorm=!1}static from(...t){let n=[1,1,1,1],r=C.getArgs(t);for(let e=0,t=n.length;e<t;e++)e<r.length&&(n[e]=r[e]);return new e(n)}static fromHex(t){if(t[0]==`#`&&(t=t.substr(1)),t.length<=4){let e=e=>t[e]||`F`,n=t.length===4?`${e(3)}${e(3)}`:``;t=`${e(0)}${e(0)}${e(1)}${e(1)}${e(2)}${e(2)}${n}`}let n=1;t.length===8&&(n=parseInt(t.substr(6,2),16)/255,t=t.substring(0,6));let r=parseInt(t,16);return new e(r>>16,r>>8&255,r&255,n)}static rgb(...t){return e.from(...t).toMode(`rgb`)}static hsl(...t){return e.from(...t).toMode(`hsl`)}static hsb(...t){return e.from(...t).toMode(`hsb`)}static lab(...t){return e.from(...t).toMode(`lab`)}static lch(...t){return e.from(...t).toMode(`lch`)}static luv(...t){return e.from(...t).toMode(`luv`)}static xyz(...t){return e.from(...t).toMode(`xyz`)}static oklab(...t){return e.from(...t).toMode(`oklab`)}static oklch(...t){return e.from(...t).toMode(`oklch`)}static maxValues(t){return e.ranges[t].zipSlice(1).$take([0,1,2])}get hex(){return this.toString(`hex`)}get rgb(){return this.toString(`rgb`)}get rgba(){return this.toString(`rgba`)}clone(){let t=new e(this);return t.toMode(this._mode),t._isNorm=this._isNorm,t}static _denorm(t){let n=t.clone(),r=e.ranges[n._mode];for(let e=0;e<3;e++){let t=r[e];n[e]=t[0]+n[e]*(t[1]-t[0])}return n._isNorm=!1,n}static _normOut(t){let n=e.ranges[t._mode];for(let e=0;e<3;e++){let r=n[e];t[e]=(t[e]-r[0])/(r[1]-r[0])}return t._isNorm=!0,t}toMode(t,n=!1){if(n&&t!==this._mode){let n=this._mode.toUpperCase()+`to`+t.toUpperCase();if(e[n])this.to(e[n](this,this._isNorm,this._isNorm));else throw Error(`Cannot convert color with `+n)}return this._mode=t,this}get mode(){return this._mode}get r(){return this[0]}set r(e){this[0]=e}get g(){return this[1]}set g(e){this[1]=e}get b(){return this[2]}set b(e){this[2]=e}get h(){return this._mode==`lch`||this._mode==`oklch`?this[2]:this[0]}set h(e){let t=this._mode==`lch`||this._mode==`oklch`?2:0;this[t]=e}get s(){return this[1]}set s(e){this[1]=e}get l(){return this._mode==`hsl`?this[2]:this[0]}set l(e){let t=this._mode==`hsl`?2:0;this[t]=e}get a(){return this[1]}set a(e){this[1]=e}get c(){return this[1]}set c(e){this[1]=e}get u(){return this[1]}set u(e){this[1]=e}get v(){return this[2]}set v(e){this[2]=e}set alpha(e){this.length>3&&(this[3]=e)}get alpha(){return this.length>3?this[3]:1}get normalized(){return this._isNorm}set normalized(e){this._isNorm=e}normalize(t=!0){if(this._isNorm==t)return this;let n=e.ranges[this._mode];for(let e=0;e<3;e++)this[e]=t?_.mapToRange(this[e],n[e][0],n[e][1],0,1):_.mapToRange(this[e],0,1,n[e][0],n[e][1]);return this._isNorm=t,this}$normalize(e=!0){return this.clone().normalize(e)}toString(t=`mode`){let n=this._isNorm&&t!==`mode`?e._denorm(this):this;if(t==`hex`){let e=e=>{let t=Math.floor(e).toString(16);return t.length<2?`0`+t:t};return`#${e(n[0])}${e(n[1])}${e(n[2])}`}return t==`rgba`?`rgba(${Math.floor(n[0])},${Math.floor(n[1])},${Math.floor(n[2])},${this.alpha})`:t==`rgb`?`rgb(${Math.floor(n[0])},${Math.floor(n[1])},${Math.floor(n[2])})`:`${this._mode}(${this[0]},${this[1]},${this[2]},${this.alpha})`}static RGBtoHSL(t,n=!1,r=!1){let[i,a,o]=n?t:t.$normalize(),s=Math.max(i,a,o),c=Math.min(i,a,o),l=(s+c)/2,u=l,d=l;if(s==c)l=0,u=0;else{let e=s-c;u=d>.5?e/(2-s-c):e/(s+c),l=0,s===i?l=(a-o)/e+(a<o?6:0):s===a?l=(o-i)/e+2:s===o&&(l=(i-a)/e+4)}let f=e.hsl(r?l/6:l*60,u,d,t.alpha);return r&&(f.normalized=!0),f}static HSLtoRGB(t,n=!1,r=!1){let[i,a,o]=t;n||(i/=360),i-=Math.floor(i);let s=r?1:255;if(a==0){let n=e.rgb(s*o,s*o,s*o,t.alpha);return r&&(n.normalized=!0),n}let c=o<=.5?o*(1+a):o+a-o*a,l=2*o-c,u=e=>(e=e<0?e+1:e>1?e-1:e,e*6<1?l+(c-l)*e*6:e*2<1?c:e*3<2?l+(c-l)*(2/3-e)*6:l),d=e.rgb(s*u(i+1/3),s*u(i),s*u(i-1/3),t.alpha);return r&&(d.normalized=!0),d}static RGBtoHSB(t,n=!1,r=!1){let[i,a,o]=n?t:t.$normalize(),s=Math.max(i,a,o),c=Math.min(i,a,o),l=s-c,u=0,d=s===0?0:l/s,f=s;s!=c&&(s===i?u=(a-o)/l+(a<o?6:0):s===a?u=(o-i)/l+2:s===o&&(u=(i-a)/l+4));let p=e.hsb(r?u/6:u*60,d,f,t.alpha);return r&&(p.normalized=!0),p}static HSBtoRGB(t,n=!1,r=!1){let[i,a,o]=t;n||(i/=360),i-=Math.floor(i);let s=Math.floor(i*6),c=i*6-s,l=o*(1-a),u=o*(1-c*a),d=o*(1-(1-c)*a),f=[[o,d,l],[u,o,l],[l,o,d],[l,u,o],[d,l,o],[o,l,u]][s%6],p=r?1:255,m=e.rgb(p*f[0],p*f[1],p*f[2],t.alpha);return r&&(m.normalized=!0),m}static RGBtoLAB(t,n=!1,r=!1){let i=n?e._denorm(t):t;return e.XYZtoLAB(e.RGBtoXYZ(i),!1,r)}static LABtoRGB(t,n=!1,r=!1){let i=n?e._denorm(t):t;return e.XYZtoRGB(e.LABtoXYZ(i),!1,r)}static RGBtoLCH(t,n=!1,r=!1){let i=n?e._denorm(t):t;return e.LABtoLCH(e.RGBtoLAB(i),!1,r)}static LCHtoRGB(t,n=!1,r=!1){let i=n?e._denorm(t):t;return e.LABtoRGB(e.LCHtoLAB(i),!1,r)}static RGBtoLUV(t,n=!1,r=!1){let i=n?e._denorm(t):t;return e.XYZtoLUV(e.RGBtoXYZ(i),!1,r)}static LUVtoRGB(t,n=!1,r=!1){let i=n?e._denorm(t):t;return e.XYZtoRGB(e.LUVtoXYZ(i),!1,r)}static RGBtoXYZ(t,n=!1,r=!1){let i=n?t.clone():t.$normalize();for(let e=0;e<3;e++)i[e]=i[e]>.04045?Math.pow((i[e]+.055)/1.055,2.4):i[e]/12.92,i[e]=i[e]*100;let a=e.xyz(i[0]*.4124564+i[1]*.3575761+i[2]*.1804375,i[0]*.2126729+i[1]*.7151522+i[2]*.072175,i[0]*.0193339+i[1]*.119192+i[2]*.9503041,t.alpha);return r?e._normOut(a):a}static XYZtoRGB(t,n=!1,r=!1){let[i,a,o]=n?t:t.$normalize(),s=[i*3.2406254773200533+a*-1.5372079722103187+o*-.4986285986982479,i*-.9689307147293197+a*1.8757560608852415+o*.041517523842953964,i*.055710120445510616+a*-.2040210505984867+o*1.0569959422543882];for(let e=0;e<3;e++)s[e]=s[e]>.0031308?1.055*Math.pow(s[e],1/2.4)-.055:12.92*s[e],s[e]=Math.max(0,Math.min(1,s[e])),r||(s[e]=Math.round(s[e]*255));let c=e.rgb(s[0],s[1],s[2],t.alpha);return r&&(c.normalized=!0),c}static XYZtoLAB(t,n=!1,r=!1){let i=n?e._denorm(t):t.clone();i.divide(e.D65);let a=e=>e>.008856451679035631?Math.cbrt(e):(903.2962962962963*e+16)/116,o=a(i[1]),s=e.lab(116*o-16,500*(a(i[0])-o),200*(o-a(i[2])),t.alpha);return r?e._normOut(s):s}static LABtoXYZ(t,n=!1,r=!1){let i=n?e._denorm(t):t,a=(i[0]+16)/116,o=i[1]/500+a,s=a-i[2]/200,c=216/24389,l=24389/27,u=e.D65,d=Math.pow(o,3),f=Math.pow(s,3),p=e.xyz(u[0]*(d>c?d:(116*o-16)/l),u[1]*(i[0]>l*c?Math.pow((i[0]+16)/116,3):i[0]/l),u[2]*(f>c?f:(116*s-16)/l),t.alpha);return r?e._normOut(p):p}static XYZtoLUV(t,n=!1,r=!1){let[i,a,o]=n?e._denorm(t):t,s=i+15*a+3*o,c=s===0?0:4*i/s,l=s===0?0:9*a/s;a/=100;let u=a>.008856451679035631?116*Math.cbrt(a)-16:903.2962962962963*a,d=4*e.D65[0]/(e.D65[0]+15*e.D65[1]+3*e.D65[2]),f=9*e.D65[1]/(e.D65[0]+15*e.D65[1]+3*e.D65[2]),p=e.luv(u,13*u*(c-d),13*u*(l-f),t.alpha);return r?e._normOut(p):p}static LUVtoXYZ(t,n=!1,r=!1){let[i,a,o]=n?e._denorm(t):t,s=24389/27;if(i===0){let n=e.xyz(0,0,0,t.alpha);return r?e._normOut(n):n}let c=(i+16)/116,l=i>s*.008856451679035631?c*c*c:i/s,u=4*e.D65[0]/(e.D65[0]+15*e.D65[1]+3*e.D65[2]),d=9*e.D65[1]/(e.D65[0]+15*e.D65[1]+3*e.D65[2]);a=a/(13*i)+u,o=o/(13*i)+d,l*=100;let f=-1*(9*l*a)/((a-4)*o-a*o),p=(9*l-15*o*l-o*f)/(3*o),m=e.xyz(f,l,p,t.alpha);return r?e._normOut(m):m}static LABtoLCH(t,n=!1,r=!1){let i=n?e._denorm(t):t,a=v.toDegree(v.boundRadian(Math.atan2(i[2],i[1]))),o=e.lch(i[0],Math.sqrt(i[1]*i[1]+i[2]*i[2]),a,t.alpha);return r?e._normOut(o):o}static LCHtoLAB(t,n=!1,r=!1){let i=n?e._denorm(t):t,a=v.toRadian(i[2]),o=e.lab(i[0],Math.cos(a)*i[1],Math.sin(a)*i[1],t.alpha);return r?e._normOut(o):o}static RGBtoOKLAB(t,n=!1,r=!1){let i=n?t:t.$normalize(),a=e=>e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92,o=a(i[0]),s=a(i[1]),c=a(i[2]),l=Math.cbrt(.4122214708*o+.5363325363*s+.0514459929*c),u=Math.cbrt(.2119034982*o+.6806995451*s+.1073969566*c),d=Math.cbrt(.0883024619*o+.2817188376*s+.6299787005*c),f=e.oklab(.2104542553*l+.793617785*u-.0040720468*d,1.9779984951*l-2.428592205*u+.4505937099*d,.0259040371*l+.7827717662*u-.808675766*d,t.alpha);return r?e._normOut(f):f}static OKLABtoRGB(t,n=!1,r=!1){let i=n?e._denorm(t):t,a=i[0]+.3963377774*i[1]+.2158037573*i[2],o=i[0]-.1055613458*i[1]-.0638541728*i[2],s=i[0]-.0894841775*i[1]-1.291485548*i[2],c=a*a*a,l=o*o*o,u=s*s*s,d=[4.0767416621*c-3.3077115913*l+.2309699292*u,-1.2684380046*c+2.6097574011*l-.3413193965*u,-.0041960863*c-.7034186147*l+1.707614701*u];for(let e=0;e<3;e++)d[e]=d[e]>.0031308?1.055*Math.pow(d[e],1/2.4)-.055:12.92*d[e],d[e]=Math.max(0,Math.min(1,d[e])),r||(d[e]=Math.round(d[e]*255));let f=e.rgb(d[0],d[1],d[2],t.alpha);return r&&(f.normalized=!0),f}static RGBtoOKLCH(t,n=!1,r=!1){let i=n?e._denorm(t):t;return e.OKLABtoOKLCH(e.RGBtoOKLAB(i),!1,r)}static OKLCHtoRGB(t,n=!1,r=!1){let i=n?e._denorm(t):t;return e.OKLABtoRGB(e.OKLCHtoOKLAB(i),!1,r)}static OKLABtoOKLCH(t,n=!1,r=!1){let i=n?e._denorm(t):t,a=v.toDegree(v.boundRadian(Math.atan2(i[2],i[1]))),o=e.oklch(i[0],Math.sqrt(i[1]*i[1]+i[2]*i[2]),a,t.alpha);return r?e._normOut(o):o}static OKLCHtoOKLAB(t,n=!1,r=!1){let i=n?e._denorm(t):t,a=v.toRadian(i[2]),o=e.oklab(i[0],Math.cos(a)*i[1],Math.sin(a)*i[1],t.alpha);return r?e._normOut(o):o}};mt.D65=new T(95.047,100,108.883,1),mt.ranges={rgb:new E(new T(0,255),new T(0,255),new T(0,255)),hsl:new E(new T(0,360),new T(0,1),new T(0,1)),hsb:new E(new T(0,360),new T(0,1),new T(0,1)),lab:new E(new T(0,100),new T(-128,127),new T(-128,127)),lch:new E(new T(0,100),new T(0,100),new T(0,360)),luv:new E(new T(0,100),new T(-134,220),new T(-140,122)),xyz:new E(new T(0,100),new T(0,100),new T(0,100)),oklab:new E(new T(0,1),new T(-.4,.4),new T(-.4,.4)),oklch:new E(new T(0,1),new T(0,.4),new T(0,360))};var ht=t({DOMSpace:()=>J,HTMLForm:()=>vt,HTMLSpace:()=>Y}),J=class e extends ae{constructor(t=`pt`,n){super(),this.id=`domspace`,this._autoResize=!0,this._bgcolor=`#e1e9f0`,this._css={},this._domDisposed=!1,this._ownsContainer=!1,this._resizeHandlerBound=this._resizeHandler.bind(this),this.refresh(!1);let r=null;if(this.id=`pts`,t instanceof Element)r=t,this.id=`pts_existing_space`;else{let e=t||`pt`,n=e[0]===`#`||e[0]===`.`?e:`#`+e;r=document.querySelector(n),this.id=n.substr(1)}r?(this._canvas=r,this._container=r.parentElement):(this._container=e.createElement(`div`,this.id+`_container`),this._canvas=this._createDefaultElement(this._container,this.id),document.body.appendChild(this._container),this._ownsContainer=!0),this._readyTimer=setTimeout(this._ready.bind(this,n),50)}_createDefaultElement(t,n){return e.createElement(`div`,n,t)}static createElement(e=`div`,t,n){let r=document.createElement(e);return t&&r.setAttribute(`id`,t),n&&n.appendChild&&n.appendChild(r),r}_ready(e){if(!this._domDisposed){if(!this._container)throw Error(`Cannot initiate #${this.id} element`);this._isReady=!0,this._resizeHandler(null),this.clear(this._bgcolor),this._canvas.dispatchEvent(new Event(`ready`));for(let e in this.players)this.players.hasOwnProperty(e)&&this.players[e].start&&this.players[e].start(this.bound.clone(),this);this._pointer=this.center,e&&e(this.bound,this._canvas)}}setup(e){return e.bgcolor&&(this._bgcolor=e.bgcolor),this.autoResize=e.resize!=null&&e.resize,this}getForm(){return null}set autoResize(e){this._autoResize=e,e?window.addEventListener(`resize`,this._resizeHandlerBound):(delete this._css.width,delete this._css.height,window.removeEventListener(`resize`,this._resizeHandlerBound))}get autoResize(){return this._autoResize}resize(e,t){this.bound=e,this.styles({width:`${e.width}px`,height:`${e.height}px`},!0);for(let e in this.players)if(this.players.hasOwnProperty(e)){let n=this.players[e];n.resize&&n.resize(this.bound,t)}return this}_resizeHandler(e){let t=D.fromBoundingRect(this._container.getBoundingClientRect());this._autoResize?this.styles({width:`100%`,height:`100%`},!0):this.styles({width:`${t.width}px`,height:`${t.height}px`},!0),this.resize(t,e)}get element(){return this._canvas}get parent(){return this._container}get ready(){return this._isReady}clear(e){return e&&(this.background=e),this._canvas.innerHTML=``,this}set background(e){this._bgcolor=e,this._container.style.backgroundColor=this._bgcolor}get background(){return this._bgcolor}style(e,t,n=!1){return this._css[e]=t,n&&(this._canvas.style[e]=t),this}styles(e,t=!1){for(let n in e)e.hasOwnProperty(n)&&this.style(n,e[n],t);return this}static setAttr(e,t){for(let n in t)t.hasOwnProperty(n)&&e.setAttribute(n,t[n]);return e}static getInlineStyles(e){let t=``;for(let n in e)e.hasOwnProperty(n)&&e[n]&&(t+=`${n}: ${e[n]}; `);return t}dispose(){return this._domDisposed?this:(this._domDisposed=!0,clearTimeout(this._readyTimer),this.autoResize=!1,this._unbindAll(),this._cancelAnimation(),ae.prototype.removeAll.call(this),this._isReady=!1,this._ownsContainer&&this._container.remove(),this)}},Y=class extends J{getForm(){return new vt(this)}static htmlElement(e,t,n,r=!0){if(!e||!e.appendChild)throw Error(`parent is not a valid DOM element`);let i=document.getElementById(n);return i&&!e.contains(i)&&(i=null),i||(i=document.createElement(t),i.setAttribute(`id`,n),r&&i.setAttribute(`class`,n.substring(0,n.indexOf(`-`))),e.appendChild(i)),i}remove(e){return this._container.querySelectorAll(`.`+vt.scopeID(e)).forEach(e=>{e.parentNode.removeChild(e)}),super.remove(e)}removeAll(){return this._canvas.innerHTML=``,super.removeAll()}};let gt=0,_t=0;var vt=class e extends ce{static get groupID(){return gt}static set groupID(e){gt=e}static get domID(){return _t}static set domID(e){_t=e}constructor(t){super(),this._style={filled:!0,stroked:!0,background:`#f03`,"border-color":`#fff`,color:`#000`,"border-width":`1px`,"border-radius":`0`,"border-style":`solid`,opacity:1,position:`absolute`,top:0,left:0,width:0,height:0},this._ctx={group:null,groupID:`pts`,groupCount:0,currentID:`pts0`,currentClass:``,style:{}},this._ready=!1,this._formID=0,this._space=t,this._formID=e.groupID++;let n=()=>{this._ctx.group=this._space.element,this._ctx.groupID=`pts_dom_${this._formID}`,this._ctx.style=Object.assign({},this._style),this._ready=!0};this._space.ready?n():this._space.add({start:n})}get space(){return this._space}styleTo(e,t,n=``){if(this._ctx.style[e]===void 0)throw Error(`${e} style property doesn't exist`);this._ctx.style[e]=`${t}${n}`}alpha(e){return this.styleTo(`opacity`,e),this}fill(e){return typeof e==`boolean`?(this.styleTo(`filled`,e),e||this.styleTo(`background`,`transparent`)):(this.styleTo(`filled`,!0),this.styleTo(`background`,e)),this}stroke(e,t,n,r){return typeof e==`boolean`?(this.styleTo(`stroked`,e),e||this.styleTo(`border-width`,0)):(this.styleTo(`stroked`,!0),this.styleTo(`border-color`,e),this.styleTo(`border-width`,(t||1)+`px`)),this}fillText(e){return this.styleTo(`color`,e),this}cls(e){return typeof e==`boolean`?this._ctx.currentClass=``:this._ctx.currentClass=e,this}font(e,t,n,r,i){return typeof e==`number`?(this._font.size=e,i&&(this._font.face=i),t&&(this._font.weight=t),n&&(this._font.style=n),r&&(this._font.lineHeight=r)):this._font=e,this._ctx.style.font=this._font.value,this}reset(){return this._ctx.style=Object.assign({},this._style),this._font=new le(10,`sans-serif`),this._ctx.style.font=this._font.value,this}updateScope(e,t){return this._ctx.group=t,this._ctx.groupID=e,this._ctx.groupCount=0,this.nextID(),this._ctx}scope(t){if(!t||t.animateID==null)throw Error(`item not defined or not yet added to Space`);return this.updateScope(`${e.scopeID(t)}-f${this._formID}`,this.space.element)}nextID(){return this._ctx.groupCount++,this._ctx.currentID=`${this._ctx.groupID}-${this._ctx.groupCount}`,this._ctx.currentID}static getID(t){return t.currentID||`p-${e.domID++}`}static scopeID(e){return`item-${e.animateID}`}static style(e,t){let n=[];t.filled||n.push(`background: none`),t.stroked||n.push(`border: none`);for(let e in t)if(t.hasOwnProperty(e)&&e!=`filled`&&e!=`stroked`){let r=t[e];if(r){if(!t.filled&&e.indexOf(`background`)===0||!t.stroked&&e.indexOf(`border-width`)===0)continue;n.push(`${e}: ${r}`)}}return Y.setAttr(e,{style:n.join(`;`)})}static rectStyle(e,t,n){return e.style.left=t[0]+`px`,e.style.top=t[1]+`px`,e.style.width=n[0]+`px`,e.style.height=n[1]+`px`,e}static textStyle(e,t){return e.style.left=t[0]+`px`,e.style.top=t[1]+`px`,e}static point(t,n,r=5,i=`square`){return i===`circle`?e.circle(t,n,r):e.square(t,n,r)}point(t,n=5,r=`square`){return this.nextID(),this.styleTo(`border-radius`,r==`circle`?`100%`:`0`),e.point(this._ctx,t,n,r),this}static circle(t,n,r=10){let i=Y.htmlElement(t.group,`div`,e.getID(t));return Y.setAttr(i,{class:`pts-form pts-circle ${t.currentClass}`}),e.rectStyle(t,new T(n).$subtract(r),new T(r*2,r*2)),e.style(i,t.style),i}circle(t){return this.nextID(),this.styleTo(`border-radius`,`100%`),e.circle(this._ctx,t[0],t[1][0]),this}static square(t,n,r){let i=Y.htmlElement(t.group,`div`,e.getID(t));return Y.setAttr(i,{class:`pts-form pts-square ${t.currentClass}`}),e.rectStyle(t,new T(n).$subtract(r),new T(r*2,r*2)),e.style(i,t.style),i}square(t,n){return this.nextID(),this.styleTo(`border-radius`,`0`),e.square(this._ctx,t,n),this}static rect(t,n){let r=C.iterToArray(n);if(!C.arrayCheck(r))return;let i=Y.htmlElement(t.group,`div`,e.getID(t));return Y.setAttr(i,{class:`pts-form pts-rect ${t.currentClass}`}),e.rectStyle(t,r[0],r[1]),e.style(i,t.style),i}rect(t){return this.nextID(),this.styleTo(`border-radius`,`0`),e.rect(this._ctx,t),this}static text(t,n,r){let i=Y.htmlElement(t.group,`div`,e.getID(t));return Y.setAttr(i,{class:`pts-form pts-text ${t.currentClass}`}),i.textContent=r,e.textStyle(t,n),e.style(i,t.style),i}text(t,n){return this.nextID(),e.text(this._ctx,t,n),this}log(e){return this.fill(`#000`).stroke(`#fff`,.5).text([10,14],e),this}arc(e,t,n,r,i){return C.warn(`arc is not implemented in HTMLForm`),this}line(e){return C.warn(`line is not implemented in HTMLForm`),this}polygon(e){return C.warn(`polygon is not implemented in HTMLForm`),this}},yt=t({SVGContext2D:()=>Tt,SVGForm:()=>At,SVGSpace:()=>Q});let X=`http://www.w3.org/2000/svg`,bt=new Set([`multiply`,`screen`,`overlay`,`darken`,`lighten`,`color-dodge`,`color-burn`,`hard-light`,`soft-light`,`difference`,`exclusion`,`hue`,`saturation`,`color`,`luminosity`]),xt=0;var St=class{constructor(e,t){this.stops=[],this._elem=null,this.kind=e,this.coords=t,this.id=`pts_grad_${xt++}`}addColorStop(e,t){this.stops.push([e,t]),this._elem&&this._render(this._elem)}materialize(e){if(!this._elem){if(this._elem=document.createElementNS(X,this.kind===`linear`?`linearGradient`:`radialGradient`),this._elem.setAttribute(`id`,this.id),this._elem.setAttribute(`gradientUnits`,`userSpaceOnUse`),this.kind===`linear`){let[e,t,n,r]=this.coords;J.setAttr(this._elem,{x1:e,y1:t,x2:n,y2:r})}else{let[e,t,n,r,i,a]=this.coords;J.setAttr(this._elem,{cx:r,cy:i,r:a,fx:e,fy:t}),n&&this._elem.setAttribute(`fr`,`${n}`)}this._render(this._elem)}return this._elem.parentNode!==e&&e.appendChild(this._elem),`url(#${this.id})`}_render(e){e.textContent=``;for(let[t,n]of this.stops){let r=document.createElementNS(X,`stop`);r.setAttribute(`offset`,`${t}`),r.setAttribute(`stop-color`,n),e.appendChild(r)}}};let Ct=null,wt={};var Tt=class e{constructor(e){this.fillStyle=`#f03`,this.strokeStyle=`#fff`,this.lineWidth=1,this.lineJoin=`bevel`,this.lineCap=`butt`,this.globalAlpha=1,this.globalCompositeOperation=`source-over`,this.font=`10px sans-serif`,this.textAlign=`start`,this.textBaseline=`alphabetic`,this.lineDashOffset=0,this._dash=[],this._stateStack=[],this.className=``,this._d=``,this._shapeFill=null,this._shapeStroke=null,this._shapeStrokeStyle={},this._shapePainted=!1,this._shapeClass=``,this._shapeAlpha=1,this._shapeBlend=`source-over`,this._runs=[],this._drawCount=0,this._group=null,this._defs=null,this._pool=[],this._attrCache=[],this._host=e}static _warnOnce(e,t){wt[e]||(wt[e]=!0,C.warn(t))}beginFrame(){this._runs=[],this._d=``,this._shapeFill=null,this._shapeStroke=null,this._shapePainted=!1,this._drawCount=0}get drawCount(){return this._drawCount}get group(){return this._group}commitFrame(){this._flushShape(),this._group||(this._group=document.createElementNS(X,`g`),this._group.setAttribute(`class`,`pts-svgform`),this._host.appendChild(this._group));let e=this._runs;for(let t=0;t<e.length;t++){let n=e[t],r=this._pool[t];if(!r||r.nodeName!==n.tag){let e=document.createElementNS(X,n.tag);r?this._group.replaceChild(e,r):this._group.appendChild(e),r=e,this._pool[t]=r,this._attrCache[t]={}}let i=this._attrCache[t];for(let e in i)e in n.attrs||(r.removeAttribute(e),delete i[e]);for(let e in n.attrs){let t=`${n.attrs[e]}`;i[e]!==t&&(r.setAttribute(e,t),i[e]=t)}n.tag===`text`&&r.textContent!==n.text&&(r.textContent=n.text)}for(let t=this._pool.length-1;t>=e.length;t--)this._group.removeChild(this._pool[t]),this._pool.pop(),this._attrCache.pop();if(this._defs){let t=new Set;for(let n of e)t.add(n.attrs.fill),t.add(n.attrs.stroke);for(let e of Array.from(this._defs.children))t.has(`url(#${e.id})`)||e.remove()}}get runs(){return this._runs}resetDom(){this._group=null,this._defs=null,this._pool=[],this._attrCache=[]}disposeDom(){this._group&&this._group.parentNode&&this._group.parentNode.removeChild(this._group),this._defs&&this._defs.parentNode&&this._defs.parentNode.removeChild(this._defs),this.resetDom()}beginPath(){this._flushShape(),this._d=``}closePath(){this._d+=`Z`}moveTo(e,t){this._d+=`M${Z(e)} ${Z(t)}`}lineTo(e,t){this._d+=`L${Z(e)} ${Z(t)}`}quadraticCurveTo(e,t,n,r){this._d+=`Q${Z(e)} ${Z(t)} ${Z(n)} ${Z(r)}`}bezierCurveTo(e,t,n,r,i,a){this._d+=`C${Z(e)} ${Z(t)} ${Z(n)} ${Z(r)} ${Z(i)} ${Z(a)}`}rect(e,t,n,r){this._d+=`M${Z(e)} ${Z(t)}h${Z(n)}v${Z(r)}h${Z(-n)}Z`}arc(e,t,n,r,i,a=!1){this.ellipse(e,t,n,n,0,r,i,a)}ellipse(e,t,n,r,i,a,o,s=!1){let c=s?a-o:o-a,l=c>=S.two_pi;l||(c=(c%S.two_pi+S.two_pi)%S.two_pi);let u=Math.cos(i),d=Math.sin(i),f=i=>{let a=n*Math.cos(i),o=r*Math.sin(i);return[e+a*u-o*d,t+a*d+o*u]},p=s?-1:1,m=+!s,h=Z(i*180/Math.PI),[g,_]=f(a);this._d+=this._d.length>0?`L${Z(g)} ${Z(_)}`:`M${Z(g)} ${Z(_)}`;let v=l?S.two_pi:c,y=Math.max(1,Math.ceil(v/S.pi-1e-6)),b=a;for(let e=1;e<=y;e++){let t=e===y?a+p*v:b+p*S.pi,[i,o]=f(t);this._d+=`A${Z(n)} ${Z(r)} ${h} 0 ${m} ${Z(i)} ${Z(o)}`,b=t}l&&(this._d+=`Z`)}fill(){this._shapeFill=this._resolvePaint(this.fillStyle),this._capturePaintState()}stroke(){this._shapeStroke=this._resolvePaint(this.strokeStyle),this._shapeStrokeStyle={"stroke-width":this.lineWidth,"stroke-linejoin":this.lineJoin,"stroke-linecap":this.lineCap},this._dash.length>0&&(this._shapeStrokeStyle[`stroke-dasharray`]=this._dash.join(` `),this.lineDashOffset&&(this._shapeStrokeStyle[`stroke-dashoffset`]=this.lineDashOffset)),this._capturePaintState()}_capturePaintState(){this._shapePainted=!0,this._shapeClass=this.className,this._shapeAlpha=this.globalAlpha,this._shapeBlend=this.globalCompositeOperation,this._drawCount++}fillRect(e,t,n,r){this.beginPath(),this.rect(e,t,n,r),this.fill()}clearRect(){}fillText(e,t,n,r){this._flushShape();let i=this.textAlign===`center`?`middle`:this.textAlign===`right`||this.textAlign===`end`?`end`:`start`,a=this.textBaseline===`top`?`text-before-edge`:this.textBaseline===`middle`?`central`:this.textBaseline===`bottom`?`text-after-edge`:this.textBaseline,o={x:Z(t),y:Z(n),fill:this._resolvePaint(this.fillStyle),"text-anchor":i,"dominant-baseline":a,style:`font: ${this.font}`,"pointer-events":`none`};r>0&&this.measureText(e).width>r&&(o.textLength=Z(r),o.lengthAdjust=`spacingAndGlyphs`),this._applyCommon(o),this._runs.push({tag:`text`,attrs:o,text:e}),this._drawCount++}measureText(e){return Ct||(Ct=document.createElement(`canvas`).getContext(`2d`)),Ct.font=this.font,Ct.measureText(e)}drawImage(t,n,r,i,a,...o){var s;if(o.length>0){e._warnOnce(`drawImage9`,`SVG output does not support the 9-argument (source-cropped) drawImage`);return}this._flushShape();let c=(s=t.src)==null?t.toDataURL?t.toDataURL():null:s;if(!c){e._warnOnce(`drawImageSrc`,`SVG output supports images from <img> elements or canvases only`);return}let l={href:c,x:Z(n),y:Z(r)},u=i==null?t.width:i,d=a==null?t.height:a;u!=null&&(l.width=Z(u)),d!=null&&(l.height=Z(d)),this._applyCommon(l),this._runs.push({tag:`image`,attrs:l}),this._drawCount++}putImageData(){e._warnOnce(`putImageData`,`putImageData is not supported in SVG output`)}save(){this._stateStack.push({fillStyle:this.fillStyle,strokeStyle:this.strokeStyle,lineWidth:this.lineWidth,lineJoin:this.lineJoin,lineCap:this.lineCap,globalAlpha:this.globalAlpha,globalCompositeOperation:this.globalCompositeOperation,font:this.font,textAlign:this.textAlign,textBaseline:this.textBaseline,lineDashOffset:this.lineDashOffset,_dash:this._dash.slice()})}restore(){let e=this._stateStack.pop();e&&Object.assign(this,e)}scale(){}clip(){e._warnOnce(`clip`,`clip is not yet supported in SVG output`)}setLineDash(e){this._dash=e}getLineDash(){return this._dash}createLinearGradient(e,t,n,r){return new St(`linear`,[e,t,n,r])}createRadialGradient(e,t,n,r,i,a){return new St(`radial`,[e,t,n,r,i,a])}_resolvePaint(t){return t instanceof St?(this._defs||(this._defs=document.createElementNS(X,`defs`),this._host.insertBefore(this._defs,this._host.firstChild)),t.materialize(this._defs)):typeof t==`string`?t:(e._warnOnce(`pattern`,`canvas patterns are not supported in SVG output; use CanvasSpace`),`none`)}_applyCommon(t){t.class=this.className?`pts-svgform ${this.className}`:`pts-svgform`,t.opacity=this.globalAlpha===1?1:this.globalAlpha;let n=this.globalCompositeOperation;if(n!==`source-over`){if(bt.has(n)){let e=`mix-blend-mode: ${n}`;t.style=t.style?`${t.style}; ${e}`:e}else e._warnOnce(`composite-${n}`,`composite operation "${n}" has no SVG equivalent`)}}_flushShape(){var t,n;if(!this._shapePainted||this._d.length===0){this._shapePainted=!1;return}let r={d:this._d,fill:(t=this._shapeFill)==null?`none`:t,stroke:(n=this._shapeStroke)==null?`none`:n};this._shapeStroke&&Object.assign(r,this._shapeStrokeStyle),r.class=this._shapeClass?`pts-svgform ${this._shapeClass}`:`pts-svgform`,r.opacity=this._shapeAlpha,this._shapeBlend!==`source-over`&&(bt.has(this._shapeBlend)?r.style=`mix-blend-mode: ${this._shapeBlend}`:e._warnOnce(`composite-${this._shapeBlend}`,`composite operation "${this._shapeBlend}" has no SVG equivalent`));let i=this._runs[this._runs.length-1];i&&i.tag===`path`&&Et(i.attrs,r)?(i.shapeEnds.push(i.attrs.d.length),i.attrs.d=i.attrs.d+this._d):this._runs.push({tag:`path`,attrs:r,shapeEnds:[]}),this._d=``,this._shapeFill=null,this._shapeStroke=null,this._shapePainted=!1}};function Z(e){return Math.round(e*100)/100}function Et(e,t){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(r!==`d`&&e[r]!==t[r])return!1;return!0}var Q=class e extends J{constructor(t=`pt`,n){if(super(t,n),this._bgcolor=`#999`,this._svgContexts=[],this._bgElem=null,this._svgRefresh=!0,this._canvas.nodeName.toLowerCase()!=`svg`){let t=e.svgElement(this._canvas,`svg`,`${this.id}_svg`);this._container=this._canvas,this._canvas=t}this.refresh(!0)}_createDefaultElement(t,n){return e.svgElement(t,`svg`,n)}getForm(){return new At(this)}get element(){return this._canvas}registerContext(e){this._svgContexts.push(e)}resize(t,n){return super.resize(t,n),e.setAttr(this.element,{viewBox:`0 0 ${this.bound.width} ${this.bound.height}`,width:`${this.bound.width}`,height:`${this.bound.height}`,xmlns:X,version:`1.1`}),this._updateBackground(),this}clear(e){return e&&(this._bgcolor=e),this._updateBackground(),this}_updateBackground(){let e=this._canvas;this._bgElem||(this._bgElem=document.createElementNS(X,`rect`),this._bgElem.setAttribute(`class`,`pts-svg-bg`),e.insertBefore(this._bgElem,e.firstChild)),J.setAttr(this._bgElem,{x:0,y:0,width:this.bound.width,height:this.bound.height,fill:!this._bgcolor||this._bgcolor===`transparent`?`none`:this._bgcolor})}playItems(e){let t=this._svgContexts;for(let e=0,n=t.length;e<n;e++)t[e].beginFrame();super.playItems(e);for(let e=0,n=t.length;e<n;e++)(this._svgRefresh||t[e].drawCount>0)&&t[e].commitFrame()}refresh(e){return this._svgRefresh=e,super.refresh(e)}toSVG(e=!1){let t=this._canvas;if(!e)return t.outerHTML;let n=t.cloneNode(!0),r=n.querySelectorAll(`g.pts-svgform`),i=0;for(let e of this._svgContexts){let t=r[i++];if(t){t.textContent=``;for(let n of e.runs){if(n.tag!==`path`){let e=document.createElementNS(X,n.tag);J.setAttr(e,n.attrs),n.text&&(e.textContent=n.text),t.appendChild(e);continue}let e=n.attrs.d,r=[...n.shapeEnds,e.length],i=0;for(let a of r){let r=document.createElementNS(X,`path`);J.setAttr(r,j(j({},n.attrs),{},{d:e.slice(i,a)})),t.appendChild(r),i=a}}}}return n.outerHTML}static svgElement(e,t,n){if(!e||!e.appendChild)throw Error(`parent is not a valid DOM element`);let r=document.getElementById(n);return r&&!e.contains(r)&&(r=null),r||(r=document.createElementNS(X,t),r.setAttribute(`id`,n),e.appendChild(r)),r}remove(e){return this._container.querySelectorAll(`.`+At.scopeID(e)).forEach(e=>{e.parentNode.removeChild(e)}),super.remove(e)}removeAll(){this._canvas.innerHTML=``,this._bgElem=null;for(let e of this._svgContexts)e.resetDom();return super.removeAll()}dispose(){super.dispose();for(let e of this._svgContexts)e.disposeDom();return this._svgContexts=[],this._bgElem&&this._bgElem.parentNode&&this._bgElem.parentNode.removeChild(this._bgElem),this._bgElem=null,this}};let Dt=0,Ot=0,kt={fillStyle:`fill`,strokeStyle:`stroke`,lineWidth:`stroke-width`,lineJoin:`stroke-linejoin`,lineCap:`stroke-linecap`,globalAlpha:`opacity`,font:`font`};var At=class e extends B{static get groupID(){return Dt}static set groupID(e){Dt=e}static get domID(){return Ot}static set domID(e){Ot=e}constructor(e){super(),this._formID=Dt++,this._legacyCtx={group:null,groupID:`pts`,groupCount:0,currentID:`pts0`,currentClass:``,style:{}},this._svgSpace=e,this._svgCtx=new Tt(e.element),e.registerContext(this._svgCtx),this._ctx=this._svgCtx,this._set(`fillStyle`,this._style.fillStyle),this._set(`strokeStyle`,this._style.strokeStyle),this._set(`lineJoin`,`bevel`),this._set(`font`,this._font.value),this._ready=!0,this._legacyCtx.group=e.element}_set(e,t){let n=kt[e];n&&(typeof t==`string`||typeof t==`number`)&&(this._legacyCtx.style[n]=t),super._set(e,t)}get filled(){return this._filled}set filled(e){this._filled=e,this._legacyCtx.style.filled=e}get stroked(){return this._stroked}set stroked(e){this._stroked=e,this._legacyCtx.style.stroked=e}useOffscreen(t=!0,n=!1){return e._warnOffscreen(),this}renderOffscreen(t=[0,0]){e._warnOffscreen()}static _warnOffscreen(){e._offscreenWarned||(e._offscreenWarned=!0,C.warn(`offscreen canvases are not supported in SVG output; use CanvasSpace`))}get space(){return this._svgSpace}get svgContext(){return this._svgCtx}cls(e){let t=typeof e==`boolean`?``:e;return this._legacyCtx.currentClass=t,this._svgCtx.className=t,this}updateScope(e,t){return this._legacyCtx.group=t,this._legacyCtx.groupID=e,this._legacyCtx.groupCount=0,this.nextID(),this._legacyCtx}scope(t){if(!t||t.animateID==null)throw Error(`item not defined or not yet added to Space`);return this.updateScope(`${e.scopeID(t)}-f${this._formID}`,this._svgSpace.element)}nextID(){return this._legacyCtx.groupCount++,this._legacyCtx.currentID=`${this._legacyCtx.groupID}-${this._legacyCtx.groupCount}`,this._legacyCtx.currentID}static getID(t){return t.currentID||`p-${e.domID++}`}static scopeID(e){return`item-${e.animateID}`}static style(e,t){let n=[];t.filled||n.push(`fill: none`),t.stroked||n.push(`stroke: none`);for(let e in t)if(t.hasOwnProperty(e)&&e!=`filled`&&e!=`stroked`){let r=t[e];if(r){if(!t.filled&&e.indexOf(`fill`)===0||!t.stroked&&e.indexOf(`stroke`)===0)continue;n.push(`${e}: ${r}`)}}return J.setAttr(e,{style:n.join(`;`)})}static point(t,n,r=5,i=`square`){return`style`in t?e.pointElement(t,n,r,i):B.point(t,n,r,i)}static circle(t,n,r=10){return`style`in t?e.circleElement(t,n,r):B.circle(t,n,r)}static arc(t,n,r,i,a,o){return`style`in t?e.arcElement(t,n,r,i,a,o):B.arc(t,n,r,i,a,o)}static square(t,n,r){return`style`in t?e.squareElement(t,n,r):B.square(t,n,r)}static line(t,n){return`style`in t?e.lineElement(t,n):B.line(t,n)}static polygon(t,n){return`style`in t?e.polygonElement(t,n):B.polygon(t,n)}static rect(t,n){return`style`in t?e.rectElement(t,n):B.rect(t,n)}static text(t,n,r,i){return`style`in t?e.textElement(t,n,r):B.text(t,n,r,i)}static pointElement(t,n,r=5,i=`square`){return i===`circle`?e.circleElement(t,n,r):e.squareElement(t,n,r)}static circleElement(t,n,r=10){let i=Q.svgElement(t.group,`circle`,e.getID(t));return J.setAttr(i,{cx:n[0],cy:n[1],r,class:`pts-svgform pts-circle ${t.currentClass}`}),e.style(i,t.style),i}static arcElement(t,n,r,i,a,o){let s=Q.svgElement(t.group,`path`,e.getID(t)),c=new T(n).toAngle(i,r,!0),l=new T(n).toAngle(a,r,!0),u=v.boundAngle(a)-v.boundAngle(i)>S.pi;o&&(u=!u);let d=o?`0`:`1`,f=`M ${c[0]} ${c[1]} A ${r} ${r} 0 ${u?`1`:`0`} ${d} ${l[0]} ${l[1]}`;return J.setAttr(s,{d:f,class:`pts-svgform pts-arc ${t.currentClass}`}),e.style(s,t.style),s}static squareElement(t,n,r){let i=Q.svgElement(t.group,`rect`,e.getID(t));return J.setAttr(i,{x:n[0]-r,y:n[1]-r,width:r*2,height:r*2,class:`pts-svgform pts-square ${t.currentClass}`}),e.style(i,t.style),i}static lineElement(t,n){let r=e.pointsString(n);if(r.count<2)return;if(r.count>2)return e._poly(t,r.string,!1);let i=Q.svgElement(t.group,`line`,e.getID(t)),a=C.iterToArray(n);return J.setAttr(i,{x1:a[0][0],y1:a[0][1],x2:a[1][0],y2:a[1][1],class:`pts-svgform pts-line ${t.currentClass}`}),e.style(i,t.style),i}static _poly(t,n,r=!0){let i=Q.svgElement(t.group,r?`polygon`:`polyline`,e.getID(t));return J.setAttr(i,{points:n,class:`pts-svgform pts-polygon ${t.currentClass}`}),e.style(i,t.style),i}static pointsString(e){let t=``,n=0;for(let r of e)t+=`${r[0]},${r[1]} `,n++;return{string:t,count:n}}static polygonElement(t,n){let r=e.pointsString(n);return e._poly(t,r.string,!0)}static rectElement(t,n){if(!C.arrayCheck(n))return;let r=Q.svgElement(t.group,`rect`,e.getID(t)),i=E.fromArray(n).boundingBox(),a=o.size(i);return J.setAttr(r,{x:i[0][0],y:i[0][1],width:a[0],height:a[1],class:`pts-svgform pts-rect ${t.currentClass}`}),e.style(r,t.style),r}static textElement(t,n,r){let i=Q.svgElement(t.group,`text`,e.getID(t));return J.setAttr(i,{"pointer-events":`none`,x:n[0],y:n[1],dx:0,dy:0,class:`pts-svgform pts-text ${t.currentClass}`}),i.textContent=r,e.style(i,t.style),i}};At._offscreenWarned=!1;var jt=t({Body:()=>Pt,Particle:()=>Nt,World:()=>Mt});let $=1/60;var Mt=class e{constructor(e,t=1,n=0){return this._gravity=new T,this._friction=1,this._damping=.75,this._iterations=1,this._substeps=4,this._maxTimeStep=50,this._particles=[],this._bodies=[],this._pnames=[],this._bnames=[],this._frictionStep=1,this._carry=0,this._hashKeys=new Uint32Array,this._cellStart=new Uint32Array,this._cellEntries=new Uint32Array,this._neighborKeys=new Uint32Array(9),this._bodyBounds=new Float32Array,this._bound=D.fromGroup(e),this._friction=t,this._gravity=typeof n==`number`?new T(0,n):new T(n),this}get bound(){return this._bound}set bound(e){this._bound=e}get gravity(){return this._gravity}set gravity(e){this._gravity=e}get friction(){return this._friction}set friction(e){this._friction=e}get damping(){return this._damping}set damping(e){this._damping=e}get iterations(){return this._iterations}set iterations(e){this._iterations=e}get substeps(){return this._substeps}set substeps(e){this._substeps=Math.max(1,Math.round(e))}get maxTimeStep(){return this._maxTimeStep}set maxTimeStep(e){this._maxTimeStep=Math.max(0,e)}get bodyCount(){return this._bodies.length}get particleCount(){return this._particles.length}body(e){return typeof e==`string`&&e.length>0?this._bodies[this._bnames.indexOf(e)]:typeof e==`number`&&e>=0?this._bodies[e]:void 0}particle(e){return typeof e==`string`&&e.length>0?this._particles[this._pnames.indexOf(e)]:typeof e==`number`&&e>=0?this._particles[e]:void 0}bodyIndex(e){return this._bnames.indexOf(e)}particleIndex(e){return this._pnames.indexOf(e)}update(e){let t=Math.min(e,this._maxTimeStep)+this._carry;if(this._carry=0,t>=2){let e=Math.max(1,Math.round(t*this._substeps/16.666666666666668)),n=t/1e3/e;this._frictionStep=Math.pow(this._friction,n/$);for(let t=0;t<e;t++)this._updateParticles(n),this._updateBodies(n);this._clearForces()}else t>0&&(this._carry=t);if(this._drawParticles)for(let e=0,t=this._particles.length;e<t;e++)this._drawParticles(this._particles[e],e);if(this._drawBodies)for(let e=0,t=this._bodies.length;e<t;e++)this._drawBodies(this._bodies[e],e)}drawParticles(e){this._drawParticles=e}drawBodies(e){this._drawBodies=e}add(e,t=``){return e instanceof Pt?(this._bodies.push(e),this._bnames.push(t)):(this._particles.push(e),this._pnames.push(t)),this}_index(e,t){let n=0;if(typeof t==`string`){if(n=e(t),n<0)throw Error(`Cannot find index of ${t}. You can use particleIndex() or bodyIndex() function to check existence by name.`)}else n=t;return n}removeBody(e,t=1){let n=this._index(this.bodyIndex.bind(this),e),r=n<0?[n*-1-1,t]:[n,t];return this._bodies.splice(r[0],r[1]),this._bnames.splice(r[0],r[1]),this}removeParticle(e,t=1){let n=this._index(this.particleIndex.bind(this),e),r=n<0?[n*-1-1,t]:[n,t];return this._particles.splice(r[0],r[1]),this._pnames.splice(r[0],r[1]),this}static edgeConstraint(e,t,n,r=1,i=!1){let a=1/(e.mass||1),o=1/(t.mass||1),s=a+o,c=t.$subtract(e),l=n*n,u=i?n/c.magnitude()-1:l/(c.dot(c)+l)-.5,d=c.$multiply(u*r);return e.subtract(d.$multiply(a/s)),t.add(d.$multiply(o/s)),e}static boundConstraint(t,n,r=.75){let i=v.boundingBox(n);e._boundParticle(t,i[0][0],i[0][1],i[1][0],i[1][1],r)}static _boundParticle(e,t,n,r,i,a){let o=e[0],s=e[1],c=Math.min(Math.max(o,t+e.radius),r-e.radius),l=Math.min(Math.max(s,n+e.radius),i-e.radius);if(c!==o||l!==s){let t=e.previous,n=(o-t[0])*a,r=(s-t[1])*a;t[0]=c===o?c-n:c+n,t[1]=l===s?l-r:l+r,e[0]=c,e[1]=l}}integrate(e,t,n=e.timeStep||$){let r=e.previous,i=n>0?t/n:1;if(e.lock)return i!==1&&(r[0]=e[0]-(e[0]-r[0])*i,r[1]=e[1]-(e[1]-r[1])*i),e.timeStep=t,e.verlet(t,this._frictionStep,t),e;let a=e.force,o=this._frictionStep*i,s=t*t,c=e[0],l=e[1],u=c+(c-r[0])*o+(a[0]+this._gravity[0])*s,d=l+(l-r[1])*o+(a[1]+this._gravity[1])*s;return r[0]=c,r[1]=l,e[0]=u,e[1]=d,e.timeStep=t,e}_updateParticles(t){let n=this._particles,r=n.length;if(r===0)return;let i=this._bound[0],a=this._bound[1],o=Math.min(i[0],a[0]),s=Math.min(i[1],a[1]),c=Math.max(i[0],a[0]),l=Math.max(i[1],a[1]);for(let i=0;i<r;i++){let r=n[i];this.integrate(r,t),e._boundParticle(r,o,s,c,l,this._damping)}this._collideParticles()}_collideParticles(){let e=this._particles,t=e.length;if(t<2)return;let n=0;for(let r=0;r<t;r++)e[r].radius>n&&(n=e[r].radius);if(n<=0)return;let r=1/(n*2),i=16;for(;i<t*2;)i<<=1;let a=i-1;this._cellStart.length<i+1&&(this._cellStart=new Uint32Array(i+1)),this._hashKeys.length<t&&(this._hashKeys=new Uint32Array(t*2),this._cellEntries=new Uint32Array(t*2));let o=this._hashKeys,s=this._cellStart,c=this._cellEntries;s.fill(0,0,i+1);for(let n=0;n<t;n++){let t=e[n],i=(Math.imul(Math.floor(t[0]*r),2654435761)^Math.imul(Math.floor(t[1]*r),2246822519))>>>0&a;o[n]=i,s[i]++}let l=0;for(let e=0;e<i;e++){let t=s[e];s[e]=l,l+=t}s[i]=l;for(let e=0;e<t;e++)c[s[o[e]]++]=e;let u=this._damping,d=this._neighborKeys;for(let n=0;n<t;n++){let t=e[n],i=Math.floor(t[0]*r),o=Math.floor(t[1]*r),l=0;for(let r=o-1;r<=o+1;r++){let o=Math.imul(r,2246822519);for(let r=i-1;r<=i+1;r++){let i=(Math.imul(r,2654435761)^o)>>>0&a,f=!1;for(let e=0;e<l;e++)if(d[e]===i){f=!0;break}if(f)continue;d[l++]=i;let p=s[i],m=i>0?s[i-1]:0;for(let r=m;r<p;r++){let i=c[r];i>n&&t.collide(e[i],u)}}}}}_clearForces(){for(let e=0,t=this._particles.length;e<t;e++)this._particles[e].force.fill(0);for(let e=0,t=this._bodies.length;e<t;e++){let t=this._bodies[e];for(let e=0,n=t.length;e<n;e++)t[e].force.fill(0)}}_updateBodies(t){let n=this._bodies,r=n.length;if(r===0)return;let i=this._bound[0],a=this._bound[1],o=Math.min(i[0],a[0]),s=Math.min(i[1],a[1]),c=Math.max(i[0],a[0]),l=Math.max(i[1],a[1]);for(let i=0;i<r;i++){let r=n[i];if(r)for(let n=0,i=r.length;n<i;n++){let i=r[n];this.integrate(i,t),e._boundParticle(i,o,s,c,l,this._damping)}}this._collideBodies(r);for(let e=0;e<r;e++)n[e]&&n[e].solveEdges(t,this._iterations,this._substeps)}_collideBodies(e){let t=this._bodies;this._bodyBounds.length<e*4&&(this._bodyBounds=new Float32Array(e*8));let n=this._bodyBounds;for(let r=0;r<e;r++){let e=t[r],i=1/0,a=1/0,o=-1/0,s=-1/0;if(e)for(let t=0,n=e.length;t<n;t++){let n=e[t];n[0]<i&&(i=n[0]),n[0]>o&&(o=n[0]),n[1]<a&&(a=n[1]),n[1]>s&&(s=n[1])}n[r*4]=i,n[r*4+1]=a,n[r*4+2]=o,n[r*4+3]=s}let r=this._particles,i=r.length;for(let a=0;a<e;a++){let o=t[a];if(!o)continue;let s=n[a*4],c=n[a*4+1],l=n[a*4+2],u=n[a*4+3];for(let r=a+1;r<e;r++)t[r]&&s<=n[r*4+2]&&l>=n[r*4]&&c<=n[r*4+3]&&u>=n[r*4+1]&&o.processBody(t[r]);for(let e=0;e<i;e++){let t=r[e],n=t.radius;t[0]>=s-n&&t[0]<=l+n&&t[1]>=c-n&&t[1]<=u+n&&o.processParticle(t)}}}},Nt=class extends T{constructor(...e){super(...e),this._mass=1,this._radius=0,this._force=new T,this._prev=new T,this._prevDt=0,this._lock=!1,this._prev=this.clone()}get mass(){return this._mass}set mass(e){this._mass=e}get radius(){return this._radius}set radius(e){this._radius=e}get previous(){return this._prev}set previous(e){this._prev=e}get force(){return this._force}set force(e){this._force=e}get body(){return this._body}set body(e){this._body=e}get lock(){return this._lock}set lock(e){this._lock&&!e&&this._prev.to(this),this._lock=e,this._lockPt=new T(this)}get changed(){let e=this.$subtract(this._prev);return this._prevDt>0&&this._prevDt!==$?e.multiply($/this._prevDt):e}get timeStep(){return this._prevDt}set timeStep(e){this._prevDt=e}set position(e){this.previous.to(this),this._prevDt=$,this._lock&&(this._lockPt=e),this.to(e)}size(e){return this._mass=e,this._radius=e,this}addForce(...e){return this._force.add(...e),this._force}verlet(e,t,n){if(this._lock)this.to(this._lockPt);else{let r=n||this._prevDt||e,i=e*(e+r)/2,a=t*e/r,o=this._force,s=this._prev;for(let e=0,t=this.length;e<t;e++){let t=this[e],n=(t-s[e])*a+(o[e]||0)*i;s[e]=t,this[e]=t+n}o.fill(0),this._prevDt=e}return this}hit(...e){let t=this._prev;if(this._prevDt>0&&this._prevDt!==$){let e=$/this._prevDt;for(let n=0,r=this.length;n<r;n++)t[n]=this[n]-(this[n]-t[n])*e}return this._prevDt=$,t.subtract(new T(...e).$divide(Math.sqrt(this._mass))),this}collide(e,t=1){let n=this,r=n[0]-e[0],i=n[1]-e[1],a=r*r+i*i,o=n.radius+e.radius;if(a>=o*o)return;let s=n.previous,c=e.previous,l=n[0]-s[0],u=n[1]-s[1],d=e[0]-c[0],f=e[1]-c[1],p=Math.sqrt(a),m;p<1e-6?(r=1,i=0,p=1,a=1,m=-o/2):m=(p-o)/p/2;let h=n[0]-r*m,g=n[1]-i*m,_=e[0]+r*m,v=e[1]+i*m,y=t*(r*l+i*u)/a,b=t*(r*d+i*f)/a,x=n.mass/(n.mass+e.mass),S=e.mass/(n.mass+e.mass);l+=(b-y)*r*S,u+=(b-y)*i*S,d+=(y-b)*r*x,f+=(y-b)*i*x,n[0]=h,n[1]=g,e[0]=_,e[1]=v,s[0]=h-l,s[1]=g-u,c[0]=_-d,c[1]=v-f}toString(){return`Particle: ${this[0]} ${this[1]} | previous ${this._prev[0]} ${this._prev[1]} | mass ${this._mass}`}},Pt=class e extends E{constructor(){super(),this._cs=[],this._stiff=1,this._locks={},this._mass=1,this._lambdas=new Float32Array}static fromGroup(t,n=1,r=!0,i=!0){let a=new e().init(t);return r&&a.linkAll(n),i&&a.autoMass(),a}init(e,t=1){for(let t of e){let e=new Nt(t);e.body=this,this.push(e)}return this._stiff=t,this}get mass(){return this._mass}set mass(e){this._mass=e;for(let e=0,t=this.length;e<t;e++)this[e].mass=this._mass}autoMass(){return this.mass=Math.sqrt(l.area(this))/10,this}link(e,t,n){if(e<0||e>=this.length||t<0||t>=this.length)throw Error(`index1 is not in the Group's indices`);let r=this[e].$subtract(this[t]).magnitude();return this._cs.push([e,t,r,n||this._stiff]),this}linkAll(e){let t=this.length/2,n=(e,t,n)=>{if(e===t)return;let r=this._cs;for(let n=0,i=r.length;n<i;n++){let i=r[n];if(i[0]===e&&i[1]===t||i[0]===t&&i[1]===e)return}this.link(e,t,n)};for(let r=0,i=this.length;r<i;r++){let a=r>=i-1?0:r+1;if(n(r,a,e),i>4){let a=Math.floor(t/2)+1,o=r>=i-a?r%i:r+a;n(r,o,e)}r<=t-1&&n(r,Math.min(this.length-1,r+Math.floor(t)))}}linksToLines(){let e=[];for(let t=0,n=this._cs.length;t<n;t++){let n=this._cs[t];e.push(new E(this[n[0]],this[n[1]]))}return e}processEdges(){for(let e=0,t=this._cs.length;e<t;e++){let[t,n,r,i]=this._cs[e];Mt.edgeConstraint(this[t],this[n],r,i)}}solveEdges(e,t=1,n=1){let r=this._cs,i=r.length;if(i===0)return this;this._lambdas.length<i&&(this._lambdas=new Float32Array(i));let a=this._lambdas;a.fill(0,0,i);let o=1/Math.max(1,t*n);for(let e=0;e<t;e++)for(let e=0;e<i;e++){let t=r[e],n=this[t[0]],i=this[t[1]],s=t[3],c=n.lock?0:1/(n.mass||1),l=i.lock?0:1/(i.mass||1),u=c+l;if(u===0)continue;let d=i[0]-n[0],f=i[1]-n[1],p=Math.sqrt(d*d+f*f);if(p<1e-6)continue;let m=0;if(s<1){let e=1-Math.pow(1-s,o);m=e>1e-6?u*(1-e)/e:u*1e6}let h=(-(p-t[2])-m*a[e])/(u+m);a[e]+=h;let g=h/p,_=d*g,v=f*g;n[0]-=_*c,n[1]-=v*c,i[0]+=_*l,i[1]+=v*l}return this}processBody(e){let t=this,n=e,r=l.hasIntersectPolygon(t,n);if(r){let e=r.normal.$multiply(r.dist),t,n=r.edge;t=Math.abs(n[0][0]-n[1][0])>Math.abs(n[0][1]-n[1][1])?(r.vertex[0]-e[0]-n[0][0])/(n[1][0]-n[0][0]):(r.vertex[1]-e[1]-n[0][1])/(n[1][1]-n[0][1]);let i=1/(t*t+(1-t)*(1-t)),a=r.vertex.body.mass||1,o=r.edge[0].body.mass||1,s=a/(a+o),c=o/(a+o);n[0].subtract(e.$multiply(s*(1-t)*i/2)),n[1].subtract(e.$multiply(s*t*i/2)),r.vertex.add(e.$multiply(c))}}processParticle(e){let t=this,n=e,r=l.hasIntersectCircle(t,s.fromCenter(e,e.radius));if(r){let t=r.normal.$multiply(r.dist),i,a=r.edge;i=Math.abs(a[0][0]-a[1][0])>Math.abs(a[0][1]-a[1][1])?(r.vertex[0]-t[0]-a[0][0])/(a[1][0]-a[0][0]):(r.vertex[1]-t[1]-a[0][1])/(a[1][1]-a[0][1]);let o=1/(i*i+(1-i)*(1-i)),s=n.mass||1,c=r.edge[0].body.mass||1,l=s/(s+c),u=c/(s+c);a[0].subtract(t.$multiply(l*(1-i)*o/2)),a[1].subtract(t.$multiply(l*i*o/2));let d=e.$subtract(e.previous).add(t.$multiply(u));e.previous=e.$subtract(d)}}},Ft=t({Sound:()=>Lt,Tempo:()=>It}),It=class e{constructor(e){this._listeners={},this._listenerInc=0,this.bpm=e}static fromBeat(t){return new e(6e4/t)}get bpm(){return this._bpm}set bpm(e){this._bpm=e,this._ms=6e4/this._bpm}get ms(){return this._ms}set ms(e){this._bpm=6e4/e,this._ms=e}_createID(){return`_b`+this._listenerInc++}every(e){let t=this,n=Array.isArray(e)?e[0]:e;return{start:function(r,i=0,a){let o=a||t._createID();return t._listeners[o]={name:o,beats:e,period:n,index:0,offset:i,duration:-1,count:0,continuous:!1,fn:r},this},progress:function(r,i=0,a){let o=a||t._createID();return t._listeners[o]={name:o,beats:e,period:n,index:0,offset:i,duration:-1,count:0,continuous:!0,fn:r},this}}}track(e){for(let t in this._listeners)if(this._listeners.hasOwnProperty(t)){let n=this._listeners[t],r=n.offset?e+n.offset:e,i=n.period*this._ms,a=!1;n.duration<0?(n.duration=r-r%this._ms,n.count=n.count||0,a=!0):r>n.duration+i&&(n.duration=r-r%this._ms,Array.isArray(n.beats)&&(n.index=(n.index+1)%n.beats.length,n.period=n.beats[n.index]),n.count=(n.count||0)+1,a=!0);let o;if(n.continuous){let e=_.clamp((r-n.duration)/i,0,1);o=n.fn.call(n,n.count,e,r,a)}else a&&(o=n.fn.call(n,n.count));o&&delete this._listeners[n.name]}}stop(e){this._listeners[e]&&delete this._listeners[e]}animate(e,t){this.track(e)}resize(e,t){}action(e,t,n,r){}},Lt=class e{constructor(t,n){this._playing=!1,this._volume=1,this._connected=[],this._bufferPlayed=!1,this._generated=!1,this._type=t,this._ctx=n||e._getContext()}static _getContext(){if(!e._sharedContext){let t=typeof window<`u`?window.AudioContext:void 0;if(!t)throw Error(`Your browser doesn't support Web Audio. (No AudioContext)`);e._sharedContext=new t}return e._sharedContext}static from(t,n,r=`gen`,i){let a=new e(r,n);return a._node=t,i&&(a._stream=i),a}static load(t,n=`anonymous`){return new Promise((r,i)=>{let a=new e(`file`);typeof t==`string`?(a._source=new Audio,a._source.crossOrigin=n,a._source.src=t):(a._source=t,a._source.crossOrigin=n),a._source.autoplay=!1;let o=()=>{a._source.removeEventListener(`canplaythrough`,s),i(Error(`Error loading sound: ${a._source.src||`media element`}`))},s=()=>{a._source.removeEventListener(`error`,o),a._source.addEventListener(`ended`,function(){a._playing=!1}),a._node=a._ctx.createMediaElementSource(a._source),r(a)};a._source.readyState>=4?s():(a._source.addEventListener(`error`,o,{once:!0}),a._source.addEventListener(`canplaythrough`,s,{once:!0}),a._source.readyState===0&&a._source.load())})}static loadAsBuffer(t){return z(function*(){let n=new e(`file`),r=yield fetch(t);if(!r.ok)throw Error(`Error loading sound: ${t} (status ${r.status})`);try{n.createBuffer(yield n._ctx.decodeAudioData(yield r.arrayBuffer()))}catch(e){throw Object.assign(Error(`Error decoding audio`),{cause:e})}return n})()}createBuffer(e){this._node&&(this._node.onended=null,this._node.disconnect()),this._node=this._ctx.createBufferSource(),e!==void 0&&(this._buffer=e),this._node.buffer=this._buffer,this._node.onended=()=>{this._playing=!1},this._bufferPlayed=!1,this.analyzer&&this._node.connect(this.analyzer.node);for(let e of this._connected)this._node.connect(e);return this}static generate(t,n){return new e(`gen`)._gen(t,n)}_gen(e,t){this._node&&this._node.disconnect(),this._node=this._ctx.createOscillator(),this._generated=!0;let n=this._node;return e===`custom`?(this._wave=t,n.setPeriodicWave(this._wave)):(n.type=e,n.frequency.value=t),this}static input(t){return z(function*(){let n=new e(`input`),r=t||{audio:!0,video:!1};return n._stream=yield navigator.mediaDevices.getUserMedia(r),n._node=n._ctx.createMediaStreamSource(n._stream),n})()}get ctx(){return this._ctx}get node(){return this._node}get outputNode(){return this._outputNode}get stream(){return this._stream}get source(){return this._source}get buffer(){return this._buffer}set buffer(e){this._buffer=e}get type(){return this._type}get playing(){return this._playing}get progress(){let e=0,t=0;return this._buffer?(e=this._buffer.duration,t=this._timestamp===void 0?0:this._ctx.currentTime-this._timestamp):this._source&&(e=this._source.duration,t=this._source.currentTime),e>0?_.clamp(t/e,0,1):0}get playable(){return this._type===`input`||this._type===`gen`?this._node!==void 0:!!this._buffer||this._source!==void 0&&this._source.readyState===4}get binSize(){return this.analyzer?this.analyzer.size:0}get sampleRate(){return this._ctx.sampleRate}get frequency(){let e=this._node;return this._type===`gen`&&e&&e.frequency?e.frequency.value:0}set frequency(e){let t=this._node;this._type===`gen`&&t&&t.frequency&&(t.frequency.value=e)}get volume(){return this._volume}set volume(e){this._volume=Math.max(0,e||0),this._gain&&(this._gain.gain.value=this._volume)}connect(e){return this._connected.push(e),this._node.connect(e),this}setOutputNode(e){return this._outputNode=e,this}removeOutputNode(){return this._outputNode=null,this}analyze(e=256,t=-100,n=-30,r=.8){if(this.analyzer&&this._node)try{this._node.disconnect(this.analyzer.node)}catch(e){}let i=this._ctx.createAnalyser();return i.fftSize=e*2,i.minDecibels=t,i.maxDecibels=n,i.smoothingTimeConstant=r,this.analyzer={node:i,size:i.frequencyBinCount,data:new Uint8Array(i.frequencyBinCount)},this._node.connect(this.analyzer.node),this}_domain(e){return this.analyzer?(e?this.analyzer.node.getByteTimeDomainData(this.analyzer.data):this.analyzer.node.getByteFrequencyData(this.analyzer.data),this.analyzer.data):new Uint8Array}_domainTo(e,t,n=[0,0],r=[0,0],i){let a=e?this.timeDomain():this.freqDomain(),o=i||new E,s=a.length-r[1],c=Math.max(0,s-r[0]);o.length>c&&(o.length=c);for(let e=r[0],i=0;e<s;e++,i++){let r=n[0]+t[0]*e/s,c=n[1]+t[1]*a[e]/255,l=o[i];l&&l.length>=2?(l[0]=r,l[1]=c):o[i]=new T(r,c)}return o}timeDomain(){return this._domain(!0)}timeDomainTo(e,t=[0,0],n=[0,0],r){return this._domainTo(!0,e,t,n,r)}freqDomain(){return this._domain(!1)}freqDomainTo(e,t=[0,0],n=[0,0],r){return this._domainTo(!1,e,t,n,r)}reset(){return this.stop(),this._node&&this._node.disconnect(),this._outputNode&&this._outputNode.disconnect(),this}_getGain(){return this._gain||(this._gain=this._ctx.createGain(),this._gain.gain.value=this._volume,this._gain.connect(this._ctx.destination)),this._gain}start(e=0){if(this._ctx.state===`suspended`&&this._ctx.resume(),this._type===`file`){if(this._buffer)(this._playing||this._bufferPlayed||!this._node)&&(this._playing&&this.progress<1&&this._node.stop(),this.createBuffer()),this._node.start(0,e),this._bufferPlayed=!0,this._timestamp=this._ctx.currentTime-e;else{e>0&&(this._source.currentTime=e);let t=this._source.play();t&&t.catch&&t.catch(()=>{this._source.paused&&(this._playing=!1)})}}else if(this._type===`gen`&&this._generated){if(this._playing)return this;let e=this._node;this._gen(e.type,e.type===`custom`?this._wave:e.frequency.value),this._node.start()}this.analyzer&&this._node.connect(this.analyzer.node);for(let e of this._connected)this._node.connect(e);return(this._outputNode||this._node).connect(this._getGain()),this._playing=!0,this}stop(){return this._playing?((this._outputNode||this._node).disconnect(this._gain),this._type===`file`?this._buffer?this.progress<1&&this._node.stop():this._source.pause():this._type===`gen`?this._generated&&this._node.stop():this._type===`input`&&this._stream&&this._stream.getAudioTracks().forEach(e=>e.stop()),this._playing=!1,this):this}toggle(){return this._playing?this.stop():this.start(),this}dispose(){return!this._playing&&this._stream&&this._stream.getAudioTracks().forEach(e=>e.stop()),this.reset(),this.analyzer&&(this.analyzer.node.disconnect(),this.analyzer=void 0),this._gain&&(this._gain.disconnect(),this._gain=void 0),this._connected=[],this._stream=void 0,this._source=void 0,this._buffer=void 0,this}};globalThis.Pts=j(j(j(j(j(j(j(j(j(j(j(j(j(j(j(j(j({},he),Xe),oe),d),g),n),w),re),pt),x),ht),yt),ue),jt),ne),Ft),pe),globalThis.Pts.namespace=e=>{let t=globalThis.Pts;for(let n in t)n!=`namespace`&&(e[n]=t[n])},globalThis.Pts.quickStart=(e,t=`#9ab`)=>{if(!window)return;let n=globalThis;globalThis.Pts.namespace(n);let r=typeof e==`string`&&e[0]!==`#`&&e[0]!==`.`?`#${e}`:e,i=typeof r==`string`?document.querySelector(r):r;return n.space=i&&(i.nodeName.toLowerCase()===`svg`||i.querySelector(`:scope > svg`))?new Q(r).setup({bgcolor:t,resize:!0}):new ge(r).setup({bgcolor:t,resize:!0,retina:!0}),n.form=n.space.getForm(),function(e=null,t=null,r=null,i=null){n.space.add({start:t,animate:e,resize:i,action:r}),n.space.bindMouse().bindTouch().play()}}})();
4
+ (function(){var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};let n={triangles:new Uint32Array,neighbors:new Int32Array,hull:new Uint32Array},r=2147483648,i=new Float64Array(8),a=0;function o(e){if(a>0)return a;let t=1;for(let n=0;n<=30;n++){let n=!0;for(let a=0;a<e;a++){let e=i[a]*t;if(e>=r||e<=-2147483648)return 0;(e|0)!==e&&(n=!1)}if(n)return t;t*=2}return 0}function s(e,t,n,r,a,s){let c=(e-a)*(r-s),l=(t-s)*(n-a),u=c-l,d=33306690738754716e-32*(Math.abs(c)+Math.abs(l));if(u>d)return 1;if(-u>d)return-1;i[0]=e,i[1]=t,i[2]=n,i[3]=r,i[4]=a,i[5]=s;let f=o(6);return f===0?ie(e,t,n,r,a,s):S((e-a)*f,(r-s)*f,(t-s)*f,(n-a)*f)}function c(e,t,n,r,a,s,c,l){let u=e-c,d=t-l,f=n-c,p=r-l,m=a-c,h=s-l,g=f*h,_=m*p,v=u*u+d*d,y=m*d,b=u*h,x=f*f+p*p,S=u*p,C=f*d,w=m*m+h*h,E=v*(g-_)+x*(y-b)+w*(S-C),D=11102230246251577e-31*((Math.abs(g)+Math.abs(_))*v+(Math.abs(y)+Math.abs(b))*x+(Math.abs(S)+Math.abs(C))*w);if(E>D)return 1;if(-E>D)return-1;i[0]=e,i[1]=t,i[2]=n,i[3]=r,i[4]=a,i[5]=s,i[6]=c,i[7]=l;let O=o(8);return O===0?ae(e,t,n,r,a,s,c,l):T(u*O,d*O,f*O,p*O,m*O,h*O)}let l=262144,u=new Float64Array(8),d=new Float64Array(4),f=new Float64Array(4),p=new Float64Array(4),m=new Float64Array(4),h=new Float64Array(4),g=new Float64Array(4);function _(e,t,n,r){let i=e&262143,a=e>>>18,o=t&262143,s=t>>>18;u[r]+=n*i*o,u[r+1]+=n*(i*s+a*o),u[r+2]+=n*a*s}function v(e,t,n){for(let r=0;r<4;r++){let i=n*e[r];if(i!==0)for(let e=0;e<4;e++)u[r+e]+=i*t[e]}}function y(e){let t=0;for(let n=0;n<e;n++){let e=u[n]+t;t=Math.floor(e*3814697265625e-18),u[n]=e-t*l}return t}function b(e,t){if(t!==0)return t>0?1:-1;for(let t=0;t<e;t++)if(u[t]!==0)return 1;return 0}function x(e,t,n){if(t>=0){let r=t===0;for(let t=0;t<e;t++)n[t]=u[t],u[t]!==0&&(r=!1);return n[e]=t,+!r}let r=1;for(let t=0;t<e;t++){let e=262143-u[t]+r;r=0,e===l&&(e=0,r=1),n[t]=e}return n[e]=-t-1+r,-1}function S(e,t,n,r){return u[0]=0,u[1]=0,u[2]=0,_(Math.abs(e),Math.abs(t),e<0==t<0?1:-1,0),_(Math.abs(n),Math.abs(r),n<0==r<0?-1:1,0),b(3,y(3))}function C(e,t,n){u[0]=0,u[1]=0,u[2]=0,_(Math.abs(e),Math.abs(e),1,0),_(Math.abs(t),Math.abs(t),1,0);let r=y(3);n[0]=u[0],n[1]=u[1],n[2]=u[2],n[3]=r}function w(e,t,n,r,i){return u[0]=0,u[1]=0,u[2]=0,_(Math.abs(e),Math.abs(t),e<0==t<0?1:-1,0),_(Math.abs(n),Math.abs(r),n<0==r<0?-1:1,0),x(3,y(3),i)}function T(e,t,n,r,i,a){C(e,t,d),C(n,r,f),C(i,a,p);let o=w(n,a,i,r,m),s=w(i,t,e,a,h),c=w(e,r,n,t,g);for(let e=0;e<7;e++)u[e]=0;return o!==0&&v(d,m,o),s!==0&&v(f,h,s),c!==0&&v(p,g,c),b(7,y(7))}let E=new Float64Array(1),D=new Uint32Array(E.buffer);E[0]=1;let O=+(D[1]===1072693248),k=O^1,A=new Float64Array(8),j=new Int32Array(8);function ee(e,t){let n=2147483647;for(let r=0;r<t;r++){E[0]=e[r];let t=D[O],i=t>>>20&2047,a=(t&1048575)*4294967296+D[k],o=-1074;i!==0&&(a+=4503599627370496,o=i-1075),A[r]=t>>>31?-a:a,j[r]=o,a!==0&&o<n&&(n=o)}let r=[];for(let e=0;e<t;e++)r.push(A[e]===0?BigInt(0):BigInt(A[e])<<BigInt(j[e]-n));return r}let te=BigInt(1)<<BigInt(1023),ne=BigInt(64);function re(e,t,n,r,a,o,s,c){i.set([e,t,n,r,a,o,s,c]);let[l,u,d,f,p,m,h,g]=ee(i,8),_=h-p,v=g-m,y=_*(u-m)-v*(l-p),b=y-(_*(f-m)-v*(d-p));b<BigInt(0)&&(y=-y,b=-b);let x=BigInt(0),S=b;for(;S>=te;)S>>=ne,x+=ne;return Number(y>>x)/Number(S)}function ie(e,t,n,r,a,o){i[0]=e,i[1]=t,i[2]=n,i[3]=r,i[4]=a,i[5]=o;let s=ee(i,6),c=(s[0]-s[4])*(s[3]-s[5])-(s[1]-s[5])*(s[2]-s[4]),l=BigInt(0);return c>l?1:c<l?-1:0}function ae(e,t,n,r,a,o,s,c){i[0]=e,i[1]=t,i[2]=n,i[3]=r,i[4]=a,i[5]=o,i[6]=s,i[7]=c;let l=ee(i,8),u=l[0]-l[6],d=l[1]-l[7],f=l[2]-l[6],p=l[3]-l[7],m=l[4]-l[6],h=l[5]-l[7],g=(u*u+d*d)*(f*h-m*p)+(f*f+p*p)*(m*d-u*h)+(m*m+h*h)*(u*p-f*d),_=BigInt(0);return g>_?1:g<_?-1:0}function oe(e,t,n){let r=1<<e,i=0;for(let e=r>>1;e>0;e>>=1){let a=(t&e)===0?0:1,o=(n&e)===0?0:1;if(i+=e*e*(3*a^o),o===0){a===1&&(t=r-1-t,n=r-1-n);let e=t;t=n,n=e}}return i}function se(e,t){let n=1/0,r=1/0,i=-1/0,a=-1/0;for(let o=0;o<t;o++){let t=e[2*o],s=e[2*o+1];!Number.isFinite(t)||!Number.isFinite(s)||(t<n&&(n=t),t>i&&(i=t),s<r&&(r=s),s>a&&(a=s))}let o=2;for(;o<16&&1<<2*o<16*t;)o++;let s=(1<<o)-1,c=Math.max(i-n,a-r),l=c>0&&Number.isFinite(c)?s/c:0,u=new Uint32Array(t);for(let i=0;i<t;i++){let t=e[2*i],a=e[2*i+1],c=0,d=0;Number.isFinite(t)&&Number.isFinite(a)&&(c=Math.min(s,Math.max(0,Math.floor((t-n)*l))),d=Math.min(s,Math.max(0,Math.floor((a-r)*l)))),u[i]=oe(o,c,d)}let d=new Uint32Array(t),f=new Uint32Array(t);for(let e=0;e<t;e++)d[e]=e;let p=new Int32Array(257);for(let e=0;e<2*o;e+=8){p.fill(0);for(let n=0;n<t;n++)p[(u[n]>>>e&255)+1]++;for(let e=0;e<256;e++)p[e+1]+=p[e];for(let n=0;n<t;n++){let t=d[n];f[p[u[t]>>>e&255]++]=t}let n=d;d=f,f=n}return d}function ce(e,t=e.length>>1){if(t<3)return n;a=le(e,t);try{return ue(e,t)}finally{a=0}}function le(e,t){let n=0,i=0;for(let r=0;r<2*t;r++){let t=e[r];if(!Number.isFinite(t)||t===0)continue;Math.abs(t)>i&&(i=Math.abs(t)),E[0]=t;let a=D[O],o=D[k],s=a>>>20&2047,c=s===0?-1074:s-1075,l;if(o!==0)l=31-Math.clz32(o&-o);else{let e=a&1048575|(s===0?0:1048576);l=32+(31-Math.clz32(e&-e))}let u=-(c+l);if(u>n&&(n=u),n>30)return 0}let a=Math.pow(2,n);return i*a<r?a:0}function ue(e,t){let r=se(e,t),i=-1,a=-1,o=-1,l=0;for(;l<t;l++){let t=r[l];if(Number.isFinite(e[2*t])&&Number.isFinite(e[2*t+1])){i=t,l++;break}}if(i<0)return n;for(;l<t;l++){let t=r[l],n=e[2*t],o=e[2*t+1];if(Number.isFinite(n)&&Number.isFinite(o)&&(n!==e[2*i]||o!==e[2*i+1])){a=t,l++;break}}if(a<0)return n;for(;l<t;l++){let t=r[l],n=e[2*t],c=e[2*t+1];if(!Number.isFinite(n)||!Number.isFinite(c))continue;let u=s(e[2*i],e[2*i+1],e[2*a],e[2*a+1],n,c);if(u!==0){if(o=t,u<0){let e=a;a=o,o=e}break}}if(o<0)return n;let u=t,d=2*t+4,f=new Int32Array(d*3),p=new Int32Array(d*3),m=new Uint8Array(d),h=new Int32Array(d),g=new Int32Array(d),_=0,v=0,y=new Int32Array(d),b=new Int32Array(d),x=new Int32Array(d*3),S=new Int32Array(d*3),C=new Int32Array(d*3),w=new Int32Array(t+1),T=new Int32Array(t+1),E=0,D=(e,t,n)=>{let r=_>0?g[--_]:v++,i=3*r;return f[i]=e,f[i+1]=t,f[i+2]=n,m[r]=1,r},O=(e,t)=>{p[e]=t,p[t]=e},k=D(i,a,o),A=D(a,i,u),j=D(o,a,u),ee=D(i,o,u);O(3*k,3*A),O(3*k+1,3*j),O(3*k+2,3*ee),O(3*A+1,3*ee+2),O(3*j+1,3*A+2),O(3*ee+1,3*j+2);let te=(t,n,r)=>{let i=f[3*t],a=f[3*t+1],o=e[2*i],c=e[2*i+1],l=e[2*a],u=e[2*a+1],d=s(o,c,l,u,n,r);return d===0?Math.abs(l-o)>=Math.abs(u-c)?l>o?n>o&&n<l:n<o&&n>l:u>c?r>c&&r<u:r<c&&r>u:d>0},ne=(t,n,r)=>{let i=3*t;if(f[i+2]===u)return te(t,n,r);let a=f[i],o=f[i+1],s=f[i+2];return c(e[2*a],e[2*a+1],e[2*o],e[2*o+1],e[2*s],e[2*s+1],n,r)>0},re=(t,n,r)=>{let i=0,a=4*v+64;for(;;){let o=3*t,c=f[o],l=f[o+1],d=f[o+2],m=e[2*c],h=e[2*c+1],g=e[2*l],_=e[2*l+1];if(d===u){if(s(m,h,g,_,n,r)>0)return t;t=p[o]/3|0}else{let i=e[2*d],a=e[2*d+1];if(s(m,h,g,_,n,r)<0)t=p[o]/3|0;else if(s(g,_,i,a,n,r)<0)t=p[o+1]/3|0;else if(s(i,a,m,h,n,r)<0)t=p[o+2]/3|0;else if(n===m&&r===h||n===g&&r===_||n===i&&r===a)return-1;else return t}if(++i>a)throw Error(`Delaunay walk did not terminate`)}},ie=(t,n)=>{let r=e[2*t],i=e[2*t+1],a=re(n,r,i);if(a<0)return n;E++;let o=0,s=0;for(y[o++]=a,h[a]=E;o>0;){let e=y[--o];b[s++]=e;let t=3*e;for(let e=0;e<3;e++){let n=p[t+e]/3|0;h[n]!==E&&ne(n,r,i)&&(h[n]=E,y[o++]=n)}}let c=0;for(let e=0;e<s;e++){let t=3*b[e];for(let e=0;e<3;e++){let n=p[t+e];h[n/3|0]!==E&&(x[c]=f[t+e],S[c]=f[t+(e+1)%3],C[c]=n,c++)}}for(let e=0;e<s;e++)m[b[e]]=0,g[_++]=b[e];let l=-1;for(let e=0;e<c;e++){let n=x[e],r=S[e],i,a,o,s;n===u?(i=D(r,t,u),a=3*i+2,o=3*i,s=3*i+1):r===u?(i=D(t,n,u),a=3*i+1,o=3*i+2,s=3*i):(i=D(n,r,t),a=3*i,o=3*i+1,s=3*i+2,l<0&&(l=i)),O(a,C[e]),w[r]=o,T[n]=s}for(let e=0;e<c;e++){let t=S[e];O(w[t],T[t])}return l<0?n:l},ae=k;for(let n=0;n<t;n++){let t=r[n];t!==i&&t!==a&&t!==o&&(!Number.isFinite(e[2*t])||!Number.isFinite(e[2*t+1])||(ae=ie(t,ae)))}let oe=new Int32Array(v),ce=0,le=-1;for(let e=0;e<v;e++)m[e]?f[3*e+2]===u?(oe[e]=-1,le=e):oe[e]=ce++:oe[e]=-1;let ue=new Uint32Array(ce*3),de=new Int32Array(ce*3);for(let e=0;e<v;e++){let t=oe[e];if(!(t<0))for(let n=0;n<3;n++){ue[3*t+n]=f[3*e+n];let r=p[3*e+n],i=oe[r/3|0];de[3*t+n]=i<0?-1:3*i+r%3}}let fe=0,pe=le;do fe++,pe=p[3*pe+2]/3|0;while(pe!==le);let me=new Uint32Array(fe);pe=le;for(let e=0;e<fe;e++)me[e]=f[3*pe+1],pe=p[3*pe+2]/3|0;return{triangles:ue,neighbors:de,hull:me}}let de=16384,fe=32768;function pe(e){let t=H.iterToArray(e);if(t.length===0)return[];let n=t[0];if(n!=null&&typeof n[0]==`number`)return[t];let r=Array(t.length);for(let e=0;e<t.length;e++)r[e]=H.iterToArray(t[e]);return r}function me(e,t){let n=(e<0?-e:e)+(t<0?-t:t),r=t>=0?e>=0?t/n:1-e/n:e<0?2-t/n:3+e/n;return r>=2?r-2:r+2}function he(e,t,n){var r;let i=((r=e.get(t))==null?0:r)+n;i===0?e.delete(t):e.set(t,i)}function ge(e){let t=[];for(let n=0;n<e.length&&t.length<3;n++){let r=e[n],i=!1;for(let e=0;e<t.length;e++)if(t[e][0]===r[0]&&t[e][1]===r[1]){i=!0;break}i||t.push(r)}return t.length}function _e(e,t,n,r,i){let a=n,o=r-1;for(;a<o;){let n=t[e[a+o>>1]],r=a,s=o;for(;r<=s;){for(;t[e[r]]<n;)r++;for(;t[e[s]]>n;)s--;if(r<=s){let t=e[r];e[r]=e[s],e[s]=t,r++,s--}}if(i<=s)o=s;else if(i>=r)a=r;else return}}function ve(e){let t=0;for(let n=0,r=e.length;n<r;n++){let i=e[n],a=e[n===r-1?0:n+1];t+=Math.hypot(a[0]-i[0],a[1]-i[1])}return t}function ye(e){let t=0,n=e[0];for(let r=1;r+1<e.length;r++){let i=e[r],a=e[r+1];t+=(i[0]-n[0])*(a[1]-n[1])-(a[0]-n[0])*(i[1]-n[1])}return t/2}var be=class{constructor(){this.tol=0,this.rounding=0,this.k=0,this.vx=[],this.vy=[],this.cells=new Map,this.ea=[],this.eb=[],this.es=[],this.spE=[],this.spT=[],this.spV=[],this.gu=[],this.gv=[],this.deltas=[],this.cycleArea=[],this.cycleStart=[]}origin(e){return e&1?this.gv[e>>1]:this.gu[e>>1]}target(e){return e&1?this.gu[e>>1]:this.gv[e>>1]}read(e){let t=H.iterToArray(e);t.length>0&&t[0]!=null&&typeof t[0][0]==`number`&&(t=[t]),this.k=t.length;let n=[],r=[],i=0;for(let e=0;e<t.length;e++){let a=pe(t[e]);for(let t=0;t<a.length;t++){let o=a[t];if(o.length<3)continue;let s=!0,c=i;for(let e=0,t=o.length;e<t;e++){let t=+o[e][0],n=+o[e][1];if(!(Number.isFinite(t)&&Number.isFinite(n))){s=!1;break}let r=t<0?-t:t,i=n<0?-n:n;r>c&&(c=r),i>c&&(c=i)}if(!s){H.warn(`Path skipped a ring with a non-finite coordinate`);continue}i=c,n.push(o),r.push(e)}}if(n.length===0||i===0)return!1;this.tol=i*1e-6,this.rounding=i*Number.EPSILON*8;let a=[];for(let e=0;e<n.length;e++){let t=n[e];a.length=0;let i=-1;for(let e=0,n=t.length;e<n;e++){let n=this.vertexAt(+t[e][0],+t[e][1]);n!==i&&(a.push(n),i=n)}for(;a.length>1&&a[a.length-1]===a[0];)a.pop();if(a.length>=3)for(let t=0,n=a.length;t<n;t++)this.ea.push(a[t]),this.eb.push(a[t===n-1?0:t+1]),this.es.push(r[e]);else ge(t)>=3&&H.warn(`Path dropped a ring whose points merge within the tolerance; use local coordinates for small shapes at large offsets`)}return this.ea.length>0}vertexAt(e,t,n=this.tol){let r=this.tol*64,i=e/r,a=t/r,o=Math.floor(i),s=Math.floor(a),c=n/r,l=i-o<=c?-1:0,u=+(i-o>=1-c),d=a-s<=c?-1:0,f=+(a-s>=1-c),p=n*n;for(let n=l;n<=u;n++)for(let r=d;r<=f;r++){let i=this.cells.get((o+n+de)*fe+(s+r+de));if(i)for(let n=0;n<i.length;n++){let r=i[n],a=this.vx[r]-e,o=this.vy[r]-t;if(a*a+o*o<=p)return r}}let m=this.vx.length;this.vx.push(e),this.vy.push(t);let h=(o+de)*fe+(s+de),g=this.cells.get(h);return g?g.push(m):this.cells.set(h,[m]),m}split(){let e=this.boxes(),t=this.sweep(e,this.tol,!0);if(this.spE.length>0)this.applySplits(),e=this.boxes(),this.sweep(e,0,!1);else if(t)for(let e=0;e<t.length;e+=2)this.crossPair(t[e],t[e+1]);else this.sweep(e,0,!1)}boxes(){let e=this.ea.length,t=this.vx,n=this.vy,r=new Float64Array(e),i=new Float64Array(e),a=new Float64Array(e),o=new Float64Array(e);for(let s=0;s<e;s++){let e=t[this.ea[s]],c=n[this.ea[s]],l=t[this.eb[s]],u=n[this.eb[s]];r[s]=e<l?e:l,i[s]=e<l?l:e,a[s]=c<u?c:u,o[s]=c<u?u:c}let s=new Uint32Array(e);for(let t=0;t<e;t++)s[t]=t;return s.sort((e,t)=>r[e]-r[t]),{minX:r,maxX:i,minY:a,maxY:o,order:s}}sweep(e,t,n){let{minX:r,maxX:i,minY:a,maxY:o,order:s}=e,c=n?[]:void 0;for(let l=0,u=s.length;l<u;l++){let d=s[l],f=i[d]+t,p=a[d]-t,m=o[d]+t;for(let t=l+1;t<u;t++){let i=s[t];if(r[i]>f)break;a[i]>m||o[i]<p||(n?(this.touchPair(d,i,e),c&&(c.length<524288?c.push(d,i):c=void 0)):this.crossPair(d,i))}}return c}touchPair(e,t,n){let r=this.ea[e],i=this.eb[e],a=this.ea[t],o=this.eb[t];this.inBox(r,t,n)&&this.touch(t,r,a,o),this.inBox(i,t,n)&&this.touch(t,i,a,o),this.inBox(a,e,n)&&this.touch(e,a,r,i),this.inBox(o,e,n)&&this.touch(e,o,r,i)}inBox(e,t,n){let r=this.vx[e],i=this.vy[e],a=this.tol;return r>=n.minX[t]-a&&r<=n.maxX[t]+a&&i>=n.minY[t]-a&&i<=n.maxY[t]+a}touch(e,t,n,r){if(t===n||t===r)return;let i=this.vx,a=this.vy,o=i[n],s=a[n],c=i[r]-o,l=a[r]-s,u=c*c+l*l,d=i[t]-o,f=a[t]-s,p=(d*c+f*l)/u;if(p<=0||p>=1)return;let m=c*f-l*d;m*m>this.tol*this.tol*u||this.registerSplit(e,t)}crossPair(e,t){let n=this.ea[e],r=this.eb[e],i=this.ea[t],a=this.eb[t];if(n===i||n===a||r===i||r===a)return;let o=this.vx,c=this.vy,l=o[n],u=c[n],d=o[r],f=c[r],p=o[i],m=c[i],h=o[a],g=c[a];if(s(l,u,d,f,p,m)*s(l,u,d,f,h,g)>=0||s(p,m,h,g,l,u)*s(p,m,h,g,d,f)>=0)return;let _=re(l,u,d,f,p,m,h,g),v=this.vertexAt(l+_*(d-l),u+_*(f-u),this.rounding);this.registerSplit(e,v),this.registerSplit(t,v)}applySplits(){let e=this.ea.length,t=this.spE.length,n=this.spE,r=this.spT,i=this.spV,a=new Uint32Array(t);for(let e=0;e<t;e++)a[e]=e;a.sort((e,t)=>n[e]-n[t]||r[e]-r[t]);let o=[],s=[],c=[],l=0;for(let r=0;r<e;r++){let e=this.ea[r],u=this.eb[r],d=this.es[r];for(;l<t&&n[a[l]]===r;){let t=i[a[l++]];t!==e&&(o.push(e),s.push(t),c.push(d),e=t)}e!==u&&(o.push(e),s.push(u),c.push(d))}this.ea=o,this.eb=s,this.es=c,n.length=0,r.length=0,i.length=0}registerSplit(e,t){let n=this.ea[e],r=this.eb[e];if(t===n||t===r)return;let i=this.vx[n],a=this.vy[n],o=this.vx[r]-i,s=this.vy[r]-a,c=((this.vx[t]-i)*o+(this.vy[t]-a)*s)/(o*o+s*s);c<=0||c>=1||(this.spE.push(e),this.spT.push(c),this.spV.push(t))}merge(){this.spE.length>0&&this.applySplits();let e=this.vx.length,t=new Map,n=this.gu,r=this.gv,i=this.deltas;for(let a=0,o=this.ea.length;a<o;a++){let o=this.ea[a],s=this.eb[a],c=o<s?o:s,l=o<s?s:o,u=c*e+l,d=t.get(u);d===void 0&&(d=n.length,n.push(c),r.push(l),i.push(new Map),t.set(u,d)),he(i[d],this.es[a],o===c?1:-1)}let a=0;for(let e=0,t=n.length;e<t;e++)i[e].size!==0&&(a!==e&&(n[a]=n[e],r[a]=r[e],i[a]=i[e]),a++);n.length=a,r.length=a,i.length=a}rayTree(){return this.rayIndex}expectRayQueries(e){let t=this.gu.length;if(this.rayIndex===void 0&&e>1.5*Math.log2(t+1)+1){var n;this.rayIndex=(n=this.indexRays())==null?null:n}}indexRays(){let e=this.gu.length,t=this.vx,n=this.vy,r=0,i=new Uint32Array(e);for(let t=0;t<e;t++)n[this.gu[t]]!==n[this.gv[t]]&&(i[r++]=t);if(r===0)return;let a=new Float64Array(e),o=new Float64Array(e);for(let r=0;r<e;r++)a[r]=t[this.gu[r]]+t[this.gv[r]],o[r]=n[this.gu[r]]+n[this.gv[r]];let s=(e,r)=>{let c={x0:1/0,x1:-1/0,y0:1/0,y1:-1/0,allY0:-1/0,allY1:1/0,sum:new Map};for(let a=e;a<r;a++){let e=i[a],r=this.gu[e],o=this.gv[e],s=Math.min(n[r],n[o]),l=Math.max(n[r],n[o]);c.x0=Math.min(c.x0,t[r],t[o]),c.x1=Math.max(c.x1,t[r],t[o]),c.y0=Math.min(c.y0,s),c.y1=Math.max(c.y1,l),c.allY0=Math.max(c.allY0,s),c.allY1=Math.min(c.allY1,l)}if(r-e<=8){if(c.edges=Array.from(i.subarray(e,r)),c.allY0<c.allY1)for(let e of c.edges){let t=n[this.gv[e]]>n[this.gu[e]]?-1:1;for(let[n,r]of this.deltas[e])he(c.sum,n,t*r)}}else{let t=c.x1-c.x0>=c.y1-c.y0?a:o,n=e+r>>1;if(_e(i,t,e,r,n),c.left=s(e,n),c.right=s(n,r),c.allY0<c.allY1)for(let e of[c.left,c.right])for(let[t,n]of e.sum)he(c.sum,t,n)}return c};return s(0,r)}trace(){let e=this.gu.length,t=2*e,n=this.vx.length,r=this.vx,i=this.vy,a=this.gu,o=this.gv,s=new Float64Array(t);for(let t=0;t<e;t++){let e=r[o[t]]-r[a[t]],n=i[o[t]]-i[a[t]];s[2*t]=me(e,n),s[2*t+1]=me(-e,-n)}let c=new Int32Array(n+1);for(let t=0;t<e;t++)c[a[t]+1]++,c[o[t]+1]++;for(let e=0;e<n;e++)c[e+1]+=c[e];let l=new Int32Array(t),u=c.slice(0,n);for(let t=0;t<e;t++)l[u[a[t]]++]=2*t,l[u[o[t]]++]=2*t+1;let d=new Int32Array(t);for(let e=0;e<n;e++){let t=c[e],n=c[e+1];for(let e=t+1;e<n;e++){let n=l[e],r=s[n],i=e-1;for(;i>=t&&(s[l[i]]>r||s[l[i]]===r&&this.target(l[i])>this.target(n));)l[i+1]=l[i],i--;l[i+1]=n}for(let e=t;e<n;e++)d[l[e]]=e-t}let f=new Int32Array(t);for(let e=0;e<t;e++){let t=this.target(e),n=c[t],r=c[t+1]-n,i=d[e^1];f[e]=l[n+(i===0?r-1:i-1)]}let p=new Int32Array(t).fill(-1),m=this.cycleArea,h=this.cycleStart;for(let e=0;e<t;e++){if(p[e]>=0)continue;let t=m.length,n=0,a=e;do{p[a]=t;let e=this.origin(a),o=this.target(a);n+=r[e]*i[o]-r[o]*i[e],a=f[a]}while(a!==e);m.push(n/2),h.push(e)}this.offset=c,this.out=l,this.slot=d,this.next=f,this.cycle=p}label(e=!1){let t=this.vx.length,n=this.gu.length,r=this.cycleArea.length,i=this.vx,a=this.vy,o=this.offset,s=new Int32Array(t);for(let e=0;e<t;e++)s[e]=e;let c=e=>{for(;s[e]!==e;)s[e]=s[s[e]],e=s[e];return e};for(let e=0;e<n;e++){let t=c(this.gu[e]),n=c(this.gv[e]);t!==n&&(s[t]=n)}let l=new Int32Array(t).fill(-1),u=0;for(let e=0;e<t;e++){if(o[e+1]===o[e])continue;let t=c(e),n=l[t];n<0&&u++,(n<0||i[e]<i[n]||i[e]===i[n]&&a[e]<a[n])&&(l[t]=e)}let d=new Int32Array(r),f=new Uint8Array(r),p=new Uint8Array(r),m=e?Array(r):void 0,h=new Uint8Array(r),g=this.k-1,_=new Map,v=e=>{d[e]=_.size,f[e]=+!!_.has(0),p[e]=+!!_.has(g),m&&(m[e]=new Map(_)),h[e]=1},y=(e,t)=>{let n=(e&1?1:-1)*t;for(let[t,r]of this.deltas[e>>1])he(_,t,n*r)},b=new Int32Array(r),x=new Int32Array(r),S=new Int32Array(r);u>1&&this.expectRayQueries(u);for(let e=0;e<t;e++){let t=l[e];if(t<0)continue;let n=this.out[o[t+1]-1],r=this.cycle[n];if(h[r])continue;_.clear(),u>1&&this.windingWest(t,_),v(r);let i=0;for(b[0]=r,x[0]=this.cycleStart[r],S[0]=-1;i>=0;){let e=x[i];if(e<0){S[i]>=0&&y(S[i],-1),i--;continue}let t=this.next[e];x[i]=t===this.cycleStart[b[i]]?-1:t;let n=this.cycle[e^1];h[n]||(y(e,1),v(n),i++,b[i]=n,x[i]=this.cycleStart[n],S[i]=e)}}this.count=d,this.hasFirst=f,this.hasLast=p,this.labels=m}windingWest(e,t){let n=this.vx[e],r=this.vy[e],i=this.gu,a=this.gv,o=this.vy,s=this.deltas,c=c=>{let l=i[c],u=a[c];if(l===e||u===e)return;let d=o[l],f=o[u];if(d>r==f>r||this.crossingX(l,u,r)>=n)return;let p=f>d?-1:1;for(let[e,n]of s[c])he(t,e,p*n)},l=this.rayTree();if(l===void 0){for(let e=0,t=this.gu.length;e<t;e++)c(e);return}let u=l?[l]:[];for(;u.length>0;){let e=u.pop();if(!(e.x0>=n||r<e.y0||r>=e.y1)){if(e.x1<n&&r>=e.allY0&&r<e.allY1){for(let[n,r]of e.sum)he(t,n,r);continue}if(!e.edges){u.push(e.left,e.right);continue}for(let t of e.edges)c(t)}}}crossingX(e,t,n){let r=this.vy[e],i=this.vy[t];if(r===n)return this.vx[e];if(i===n)return this.vx[t];let a=this.vx[e];return a+(n-r)*(this.vx[t]-a)/(i-r)}select(e){let t=this.cycleArea.length,n=this.k,r=new Uint8Array(t);for(let i=0;i<t;i++){let t=this.count[i],a=this.hasFirst[i]===1,o=this.hasLast[i]===1,s=!1;switch(e){case`intersect`:s=t===n;break;case`exclude`:s=(t&1)==1;break;case`minusFront`:s=a&&t===1;break;case`minusBack`:s=o&&t===1;break;case`crop`:s=o&&t>=2;break;default:s=t>0}r[i]=+!!s}return r}mergedRings(e,t){let n=t.length,r=this.cycle,i=t=>e[r[t]]===1&&e[r[t^1]]===0,a=[];for(let e=0;e<n;e++){if(t[e]>=0||!i(e))continue;let n=a.length,r=[],o=e;do{t[o]=n,r.push(o);let e=this.target(o),a=this.offset[e],s=this.offset[e+1]-a,c=this.slot[o^1],l=-1;for(let e=1;e<=s;e++){let t=this.out[a+(c-e+s)%s];if(i(t)){l=t;break}}if(l<0)break;o=l}while(o!==e);a.push(r)}return a}simpleRings(e,t){let n=new Int32Array(this.vx.length).fill(-1),r=[],i=[],a=(e,n)=>{for(let n=0;n<e.length;n++)t[e[n]]=r.length;r.push(e),i.push(n)};for(let t=0;t<e.length;t++){let r=e[t],i=[];for(let e=0;e<r.length;e++){let o=r[e],s=this.origin(o),c=n[s];if(c>=0){let e=i.splice(c);for(let t=0;t<e.length;t++)n[this.origin(e[t])]=-1;a(e,t)}n[s]=i.length,i.push(o)}for(let e=0;e<i.length;e++)n[this.origin(i[e])]=-1;a(i,t)}return{rings:r,walk:i}}faceRings(e,t){let n=[];for(let r=0,i=this.cycleArea.length;r<i;r++){if(!e[r])continue;let i=n.length,a=[],o=this.cycleStart[r],s=o;do t[s]=i,a.push(s),s=this.next[s];while(s!==o);n.push(a)}return n}assemble(e,t,n){let r=e.length,i=this.vx,a=this.vy,o=new Float64Array(r),s=new Int32Array(r);for(let t=0;t<r;t++){let n=e[t],r=0,c=this.origin(n[0]);for(let e=0;e<n.length;e++){let t=this.origin(n[e]),o=this.target(n[e]);r+=i[t]*a[o]-i[o]*a[t],(i[t]<i[c]||i[t]===i[c]&&a[t]<a[c])&&(c=t)}o[t]=r/2,s[t]=c}let c=this.tol*this.tol,l=new Int32Array(r).fill(-2),u=s,d=new Map;if(n.length>0&&n[n.length-1]!==r-1)for(let e=0;e<r;e++){let t=d.get(n[e]);t?t.push(e):d.set(n[e],[e])}for(let t of d.values()){if(t.length<2)continue;let n=s[t[0]];for(let e of t){let t=s[e];(i[t]<i[n]||i[t]===i[n]&&a[t]<a[n])&&(n=t)}for(let r of t){if(o[r]>=0)continue;let s=this.origin(e[r][0]),d=this.target(e[r][0]),f=(i[s]+i[d])/2,p=(a[s]+a[d])/2,m=-1;for(let n of t)o[n]<=c||m>=0&&o[n]>=o[m]||this.encloses(e[n],f,p)&&(m=n);m>=0?l[r]=m:u[r]=n}}let f=0;for(let e=0;e<r;e++)o[e]<0&&l[e]===-2&&f++;this.expectRayQueries(f);let p=e=>{let n=[],r=e;for(;r>=0&&o[r]<0&&l[r]===-2;)n.push(r),l[r]=-1,r=this.westHit(u[r],t);r>=0&&o[r]<0&&(r=l[r]),r>=0&&!(o[r]>c)&&(r=-1);for(let e of n)l[e]=r;return r},m=(e,t)=>Math.abs(t)<this.tol*ve(e)/2,h=new Int32Array(r).fill(-1),g=[];for(let t=0;t<r;t++)if(o[t]>c){let n=this.ring(e[t]),r=ye(n);if(r<=0||m(n,r))continue;h[t]=g.length,g.push([n])}for(let t=0;t<r;t++){if(o[t]>=-c)continue;let n=p(t);if(n>=0&&h[n]>=0){let r=this.ring(e[t]),i=ye(r);i<0&&!m(r,i)&&g[h[n]].push(r)}}return g}encloses(e,t,n){let r=this.vx,i=this.vy,a=!1;for(let o=0;o<e.length;o++){let s=this.origin(e[o]),c=this.target(e[o]),l=i[s],u=i[c];l>n!=u>n&&r[s]+(n-l)*(r[c]-r[s])/(u-l)<t&&(a=!a)}return a}westHit(e,t){let n=this.vx[e],r=this.vy[e],i=-1/0,a=-1/0,o=-1,s=this.gu,c=this.gv,l=this.vx,u=this.vy,d=d=>{if(t[2*d]<0&&t[2*d+1]<0)return;let f=s[d],p=c[d];if(f===e||p===e)return;let m=u[f],h=u[p];if(m>r==h>r)return;let g=this.crossingX(f,p,r);if(g>=n)return;let _=l[f],v=l[p],y=h>m,b=y?(v-_)/(h-m):(_-v)/(m-h);(g>i||g===i&&b>a)&&(i=g,a=b,o=t[y?2*d+1:2*d])},f=this.rayTree();if(f===void 0){for(let e=0,t=this.gu.length;e<t;e++)d(e);return o}let p=f?[f]:[];for(;p.length>0;){let e=p.pop();if(!(e.x0>=n||e.x1<i||r<e.y0||r>=e.y1)){if(!e.edges){let t=e.left,n=e.right;t.x1<n.x1?p.push(t,n):p.push(n,t);continue}for(let t of e.edges)d(t)}}return o}ring(e){let t=this.vx,n=this.vy,r=e.length,i=[];for(let t=0;t<r;t++)i.push(this.origin(e[t]));let a=[i[0]],o=(e,r,i)=>{let a=t[i]-t[e],o=n[i]-n[e],c=((t[r]-t[e])*a+(n[r]-n[e])*o)/(a*a+o*o);return c>0&&c<1&&s(t[e],n[e],t[i],n[i],t[r],n[r])===0};for(let e=1;e<r;e++){let t=i[e],n=i[e===r-1?0:e+1];o(a[a.length-1],t,n)||a.push(t)}a.length>3&&o(a[a.length-1],a[0],a[1])&&a.shift();let c=new W;for(let e=0;e<a.length;e++){let r=new U(2);r[0]=t[a[e]],r[1]=n[a[e]];let i=c[c.length-1];(!i||i[0]!==r[0]||i[1]!==r[1])&&c.push(r)}return c.length>1&&c[0][0]===c[c.length-1][0]&&c[0][1]===c[c.length-1][1]&&c.pop(),c}};function xe(e,t){let n=t===`divide`||t===`crop`,r=new be;if(!r.read(e)||(r.split(),r.merge(),r.gu.length===0))return[];r.trace(),r.label();let i=r.select(t),a=new Int32Array(2*r.gu.length).fill(-1),o=n?r.faceRings(i,a):r.mergedRings(i,a),{rings:s,walk:c}=r.simpleRings(o,a),l=r.assemble(s,a,c);if(n)return l;let u=[];for(let e=0;e<l.length;e++)for(let t=0;t<l[e].length;t++)u.push(l[e][t]);return u}var Se=t({Circle:()=>F,Curve:()=>Ee,Line:()=>N,Path:()=>Te,Polygon:()=>I,Rectangle:()=>P,Triangle:()=>we});let M=(e,t=`expected`)=>H.warn(`Group's length is less than `+t,e),Ce=(e,t=``)=>H.warn(`Index ${t} is out of bound in Group`,e);var N=class e{static fromAngle(e,t,n){let r=new W(new U(e),new U(e));return r[1].toAngle(t,n,!0),r}static slope(e,t){return t[0]-e[0]===0?void 0:(t[1]-e[1])/(t[0]-e[0])}static intercept(e,t){if(t[0]-e[0]!==0){let n=(t[1]-e[1])/(t[0]-e[0]),r=e[1]-n*e[0];return{slope:n,yi:r,xi:n===0?void 0:-r/n}}}static sideOfPt2D(e,t){let n=H.iterToArray(e);return(n[1][0]-n[0][0])*(t[1]-n[0][1])-(t[0]-n[0][0])*(n[1][1]-n[0][1])}static collinear(e,t,n,r=.01){let i=new U(0,0,0).to(e).$subtract(t),a=new U(0,0,0).to(e).$subtract(n),o=i.magnitudeSq()*a.magnitudeSq();return o===0||i.$cross(a).magnitudeSq()/o<=r*r}static magnitude(e){let t=H.iterToArray(e);return t.length>=2?t[1].$subtract(t[0]).magnitude():0}static magnitudeSq(e){let t=H.iterToArray(e);return t.length>=2?t[1].$subtract(t[0]).magnitudeSq():0}static perpendicularFromPt(e,t,n=!1){let r=H.iterToArray(e);if(r[0].equals(r[1]))return;let i=r[0].$subtract(r[1]),a=r[1].$subtract(t),o=a.$subtract(i.$project(a));return n?o:o.$add(t)}static distanceFromPt(t,n){let r=H.iterToArray(t),i=e.perpendicularFromPt(r,n,!0);return i?i.magnitude():r[0].$subtract(n).magnitude()}static intersectRay2D(e,t){let n=H.iterToArray(e),r=H.iterToArray(t),i=n[0],a=r[0],o=n[1][0]-i[0],s=n[1][1]-i[1],c=r[1][0]-a[0],l=r[1][1]-a[1];if(o===0&&s===0||c===0&&l===0)return;let u=o*l-s*c;if(u===0){let e=a[0]-i[0],t=a[1]-i[1];return e*s-t*o===0?new U(i[0],i[1]):void 0}let d=((a[0]-i[0])*l-(a[1]-i[1])*c)/u;return new U(i[0]+d*o,i[1]+d*s)}static intersectLine2D(t,n){let r=H.iterToArray(t),i=H.iterToArray(n),a=e.intersectRay2D(r,i);return a&&B.withinBound(a,r[0],r[1])&&B.withinBound(a,i[0],i[1])?a:void 0}static intersectLineWithRay2D(t,n){let r=H.iterToArray(t),i=H.iterToArray(n),a=e.intersectRay2D(r,i);return a&&B.withinBound(a,r[0],r[1])?a:void 0}static intersectPolygon2D(t,n,r=!1){let i=H.iterToArray(t),a=H.iterToArray(n),o=r?e.intersectLineWithRay2D:e.intersectLine2D,s=new W;for(let e=0,t=a.length;e<t;e++){let n=e===t-1?0:e+1,r=o([a[e],a[n]],i);r&&s.push(r)}return s.length>0?s:void 0}static intersectLines2D(t,n,r=!1){let i=new W,a=r?e.intersectLineWithRay2D:e.intersectLine2D;for(let e of t)for(let t of n){let n=a(e,t);n&&i.push(n)}return i}static intersectGridWithRay2D(t,n){let r=H.iterToArray(t),i=e.intercept(new U(r[0]).subtract(n),new U(r[1]).subtract(n)),a=new W;return i&&i.xi!==void 0&&a.push(new U(n[0]+i.xi,n[1])),i&&i.yi!==void 0&&a.push(new U(n[0],n[1]+i.yi)),a}static intersectGridWithLine2D(t,n){let r=H.iterToArray(t),i=e.intersectGridWithRay2D(r,n),a=new W;for(let e=0,t=i.length;e<t;e++)B.withinBound(i[e],r[0],r[1])&&a.push(i[e]);return a}static intersectRect2D(t,n){let r=H.iterToArray(t),i=H.iterToArray(n),a=B.boundingBox(W.fromPtArray(r));return P.hasIntersectRect2D(a,i)?e.intersectLines2D([r],P.sides(i)):new W}static subpoints(e,t){let n=H.iterToArray(e),r=new W;for(let e=1;e<=t;e++)r.push(B.interpolate(n[0],n[1],e/(t+1)));return r}static crop(t,n,r=0,i=!0){let a=H.iterToArray(t),o=a[+(r===0)].$subtract(a[r]);if(o.magnitudeSq()===0)return a[r];if(i){let e=o.unit().multiply(n[1]);return a[r].$add(e)}{if(n[0]===0)return a[r];let t=P.fromCenter(a[r],n),i=P.sides(t),s=0;return s=Math.abs(o[1]/o[0])>Math.abs(n[1]/n[0])?o[1]<0?0:2:o[0]<0?3:1,e.intersectRay2D(i[s],a)}}static marker(e,t,n=`arrow`,r=!0){let i=H.iterToArray(e),a=+!r,o=+!!r,s=i[a].$subtract(i[o]);if(s.magnitudeSq()===0)return new W;s.unit();let c=B.perpendicular(s).multiply(t[0]).add(i[o]);return n==`arrow`?(c.add(s.$multiply(t[1])),new W(i[o],c[0],c[1])):new W(c[0],c[1])}static toRect(e){let t=H.iterToArray(e);return new W(t[0].$min(t[1]),t[0].$max(t[1]))}},P=class e{static from(t,n,r){return e.fromTopLeft(t,n,r)}static fromTopLeft(e,t,n){let r=typeof t==`number`?[t,n==null?t:n]:t;return new W(new U(e),new U(e).add(r))}static fromCenter(e,t,n){let r=typeof t==`number`?[t/2,(n==null?t:n)/2]:new U(t).divide(2);return new W(new U(e).subtract(r),new U(e).add(r))}static toCircle(e,t=!0){return F.fromRect(e,t)}static toSquare(t,n=!1){let r=H.iterToArray(t),i=e.size(r),a=n?i.maxValue().value:i.minValue().value;return e.fromCenter(e.center(r),a,a)}static size(e){let t=H.iterToArray(e);return t[0].$max(t[1]).subtract(t[0].$min(t[1]))}static center(e){let t=H.iterToArray(e),n=t[0].$min(t[1]),r=t[0].$max(t[1]);return n.add(r.$subtract(n).divide(2))}static corners(e){let t=H.iterToArray(e),n=t[0].$min(t[1]),r=t[0].$max(t[1]);return new W(n,new U(r.x,n.y),r,new U(n.x,r.y))}static sides(t){let[n,r,i,a]=e.corners(t);return[new W(n,r),new W(r,i),new W(i,a),new W(a,n)]}static boundingBox(e){let t=H.iterToArray(e),n=H.flatten(t,!1);if(n.length===0)return new W;let r=U.make(2,1/0),i=U.make(2,-1/0);for(let e=0,t=n.length;e<t;e++){let t=n[e],a=Math.min(2,t.length);for(let e=0;e<a;e++)r[e]=Math.min(r[e],t[e]),i[e]=Math.max(i[e],t[e])}return new W(r,i)}static polygon(t){return e.corners(t)}static quadrants(t,n){let r=H.iterToArray(t),i=e.corners(r),a=n==null?e.center(r):new U(n);return i.map(e=>new W(e,a).boundingBox())}static halves(e,t=.5,n=!1){let r=H.iterToArray(e),i=r[0].$min(r[1]),a=r[0].$max(r[1]),o=n?z.lerp(i[1],a[1],t):z.lerp(i[0],a[0],t);return n?[new W(i,new U(a[0],o)),new W(new U(i[0],o),a)]:[new W(i,new U(o,a[1])),new W(new U(o,i[1]),a)]}static withinBound(e,t){let n=H.iterToArray(e);return B.withinBound(t,n[0],n[1])}static hasIntersectRect2D(e,t,n=!1){let r=H.iterToArray(e),i=H.iterToArray(t);return n&&(r=B.boundingBox(r),i=B.boundingBox(i)),!(r[0][0]>i[1][0]||i[0][0]>r[1][0]||r[0][1]>i[1][1]||i[0][1]>r[1][1])}static intersectRect2D(t,n){let r=H.iterToArray(t),i=H.iterToArray(n);return e.hasIntersectRect2D(r,i)?N.intersectLines2D(e.sides(r),e.sides(i)):new W}},F=class e{static fromRect(e,t=!1){let n=H.iterToArray(e),r=0,i=r=P.size(n).minValue().value/2;if(t){let e=P.size(n).maxValue().value/2;r=Math.sqrt(i*i+e*e)}else r=i;return new W(P.center(n),new U(r,r))}static fromTriangle(e,t=!1){return t?we.circumcircle(e):we.incircle(e)}static fromCenter(e,t){return new W(new U(e),new U(t,t))}static withinBound(e,t,n=0){let r=H.iterToArray(e),i=r[0].$subtract(t);return i.dot(i)+n<r[1].x*r[1].x}static intersectRay2D(e,t){let n=H.iterToArray(e),r=H.iterToArray(t),i=r[0].$subtract(r[1]),a=n[0].$subtract(r[0]),o=i.dot(i);if(o===0)return new W;let s=a.dot(i),c=a.dot(a)-n[1].x*n[1].x,l=s/o,u=c/o,d=l*l-u;if(d<0)return new W;{let e=Math.sqrt(d),t=-l+e,n=r[0].$subtract(i.$multiply(t));if(d===0)return new W(n);let a=-l-e;return new W(n,r[0].$subtract(i.$multiply(a)))}}static intersectLine2D(t,n){let r=H.iterToArray(t),i=H.iterToArray(n),a=e.intersectRay2D(r,i),o=new W;if(a.length>0)for(let e=0,t=a.length;e<t;e++)P.withinBound(i,a[e])&&o.push(a[e]);return o}static intersectCircle2D(e,t){let n=H.iterToArray(e),r=H.iterToArray(t),i=r[0].$subtract(n[0]),a=i.magnitudeSq(),o=Math.sqrt(a),s=n[1].x,c=r[1].x,l=s*s,u=c*c;if(o>s+c)return new W;if(o<Math.abs(s-c))return new W(n[0].clone());if(o===0)return new W;{let e=(l-u+a)/(2*o),t=Math.sqrt(l-e*e),r=i.$multiply(e/o).add(n[0]);return new W(new U(r.x+t*i.y/o,r.y-t*i.x/o),new U(r.x-t*i.y/o,r.y+t*i.x/o))}}static intersectRect2D(t,n){let r=H.iterToArray(t),i=H.iterToArray(n),a=P.sides(i),o=[];for(let t=0,n=a.length;t<n;t++){let n=e.intersectLine2D(r,a[t]);n.length>0&&o.push(n)}return H.flatten(o)}static toRect(e,t=!1){let n=H.iterToArray(e),r=n[1][0];if(t){let e=r/Math.SQRT2;return new W(n[0].$subtract(e),n[0].$add(e))}return new W(n[0].$subtract(r),n[0].$add(r))}static toTriangle(e,t=!0){let n=H.iterToArray(e);if(t){let e=-Math.PI/2,t=Math.PI*2/3,r=new W;for(let i=0;i<3;i++)r.push(n[0].clone().toAngle(e,n[1][0],!0)),e+=t;return r}return we.fromCenter(n[0],n[1][0])}},we=class e{static fromRect(e){let t=H.iterToArray(e),n=t[0].$add(t[1]).divide(2);n.y=t[0][1];let r=t[1].clone();return r.x=t[0][0],new W(n,t[1].clone(),r)}static fromCircle(e){return F.toTriangle(e,!0)}static fromCenter(t,n){return e.fromCircle(F.fromCenter(t,n))}static medial(e){let t=H.iterToArray(e);return t.length<3?M(new W,3):I.midpoints(t,!0)}static oppositeSide(e,t){let n=H.iterToArray(e);return n.length<3?M(new W,3):t===0?W.fromPtArray([n[1],n[2]]):t===1?W.fromPtArray([n[0],n[2]]):W.fromPtArray([n[0],n[1]])}static altitude(t,n){let r=H.iterToArray(t),i=e.oppositeSide(r,n);return i.length>1?new W(r[n],N.perpendicularFromPt(i,r[n])):new W}static orthocenter(t){let n=H.iterToArray(t);if(n.length<3)return M(void 0,3);let r=e.altitude(n,0),i=e.altitude(n,1);return N.intersectRay2D(r,i)}static incenter(e){let t=H.iterToArray(e);if(t.length<3)return M(void 0,3);let n=I.bisector(t,0).add(t[0]),r=I.bisector(t,1).add(t[1]);return N.intersectRay2D(new W(t[0],n),new W(t[1],r))}static incircle(t,n){let r=H.iterToArray(t),i=n||e.incenter(r);if(!i)return;let a=I.area(r),o=I.perimeter(r,!0),s=2*a/o.total;if(s>0)return F.fromCenter(i,s)}static circumcenter(t){let n=H.iterToArray(t),r=e.medial(n),i=[r[0],B.perpendicular(n[0].$subtract(r[0])).p1.$add(r[0])],a=[r[1],B.perpendicular(n[1].$subtract(r[1])).p1.$add(r[1])];return N.intersectRay2D(i,a)}static circumcircle(t,n){let r=H.iterToArray(t),i=n||e.circumcenter(r);if(!i)return;let a=r[0].$subtract(i).magnitude();return F.fromCenter(i,a)}},I=class e{static centroid(e){return B.centroid(e)}static rectangle(e,t,n){return P.corners(P.fromCenter(e,t,n))}static fromCenter(e,t,n){let r=new W;for(let i=0;i<n;i++){let a=Math.PI*2*i/n;r.push(new U(Math.cos(a)*t,Math.sin(a)*t).add(e))}return r}static lineAt(e,t){let n=H.iterToArray(e);if(t<0||t>=n.length)throw Error(`index out of the Polygon's range`);return new W(n[t],t===n.length-1?n[0]:n[t+1])}static lines(e,t=!0){let n=H.iterToArray(e);if(n.length<2)return M(new W,2);let r=t?n.length:n.length-1,i=Array(r);for(let e=0;e<r;e++){let t=new W;t[0]=n[e],t[1]=n[e===n.length-1?0:e+1],i[e]=t}return i}static midpoints(t,n=!1,r=.5){let i=e.lines(t,n),a=new W;for(let e=0,t=i.length;e<t;e++)a[e]=B.interpolate(i[e][0],i[e][1],r);return a}static adjacentSides(e,t,n=!1){let r=H.iterToArray(e);if(r.length<2)return M(new W,2);if(t<0||t>=r.length)return Ce(new W,t);let i=[],a=t-1;n&&a<0&&(a=r.length-1),a>=0&&i.push(new W(r[t],r[a]));let o=t+1;return n&&o>r.length-1&&(o=0),o<=r.length-1&&i.push(new W(r[t],r[o])),i}static bisector(t,n){let r=e.adjacentSides(t,n,!0);if(r.length>=2){let e=r[0][1].$subtract(r[0][0]).unit(),t=r[1][1].$subtract(r[1][0]).unit();return e.add(t).divide(2)}}static perimeter(e,t=!1){let n=H.iterToArray(e);if(n.length<2)return M(new W,2),{total:0,segments:U.make(0,0)};let r=t?n.length:n.length-1,i=U.make(r,0),a=0;for(let e=0;e<r;e++){let t=n[e],r=n[e===n.length-1?0:e+1],o=r[0]-t[0],s=r[1]-t[1],c=Math.sqrt(o*o+s*s);a+=c,i[e]=c}return{total:a,segments:i}}static area(e){let t=H.iterToArray(e);if(t.length<3)return M(0,3);let n=(e,t)=>e[0]*t[1]-e[1]*t[0],r=0;for(let e=0,i=t.length;e<i;e++)e<t.length-1?r+=n(t[e],t[e+1]):r+=n(t[e],t[0]);return Math.abs(r/2)}static convexHull(e,t=!1){let n=H.iterToArray(e);if(n.length<3)return M(new W,3);t||(n=n.slice(),n.sort((e,t)=>e[0]-t[0]));let r=(e,t,n)=>(t[0]-e[0])*(n[1]-e[1])-(n[0]-e[0])*(t[1]-e[1])>0,i=[],a=n.length-2,o=a+3;i[a]=n[2],i[o]=n[2],r(n[0],n[1],n[2])?(i[a+1]=n[0],i[a+2]=n[1]):(i[a+1]=n[1],i[a+2]=n[0]);for(let e=3,t=n.length;e<t;e++){let t=n[e];if(!(r(i[a],i[a+1],t)&&r(i[o-1],i[o],t))){for(;!r(i[a],i[a+1],t);)a+=1;for(--a,i[a]=t;!r(i[o-1],i[o],t);)--o;o+=1,i[o]=t}}let s=new W;for(let e=0;e<o-a;e++)s.push(i[a+e]);return s}static network(e,t=0){let n=H.iterToArray(e),r=[];for(let e=0,i=n.length;e<i;e++)e!=t&&r.push(new W(n[t],n[e]));return r}static nearestPt(e,t){let n=H.iterToArray(e),r=t[0],i=t[1],a=Number.MAX_VALUE,o=-1;for(let e=0,t=n.length;e<t;e++){let t=n[e][0]-r,s=n[e][1]-i,c=t*t+s*s;c<a&&(a=c,o=e)}return o}static projectAxis(e,t){let n=H.iterToArray(e),r=t.dot(n[0]),i=r;for(let e=1,a=n.length;e<a;e++){let a=t.dot(n[e]);a<r?r=a:a>i&&(i=a)}return new U(r,i)}static _axisOverlap2D(e,t,n,r){let i=n*e[0][0]+r*e[0][1],a=i;for(let t=1,o=e.length;t<o;t++){let o=n*e[t][0]+r*e[t][1];o<i?i=o:o>a&&(a=o)}let o=n*t[0][0]+r*t[0][1],s=o;for(let e=1,i=t.length;e<i;e++){let i=n*t[e][0]+r*t[e][1];i<o?o=i:i>s&&(s=i)}return i<o?o-a:i-s}static _axisOverlap(t,n,r){let i=e.projectAxis(t,r),a=e.projectAxis(n,r);return i[0]<a[0]?a[0]-i[1]:i[0]-a[1]}static hasIntersectPoint(e,t){let n=H.iterToArray(e),r=t[0],i=t[1],a=!1;for(let e=0,t=n.length;e<t;e++){let o=n[e],s=n[e===t-1?0:e+1];o[1]>i!=s[1]>i&&r<(s[0]-o[0])*(i-o[1])/(s[1]-o[1])+o[0]&&(a=!a)}return a}static hasIntersectCircle(t,n){let r=H.iterToArray(t),i=H.iterToArray(n),a=i[0],o=i[1][0],s=1/0,c=1/0,l=-1/0,u=-1/0;for(let e=0,t=r.length;e<t;e++){let t=r[e];t[0]<s&&(s=t[0]),t[0]>l&&(l=t[0]),t[1]<c&&(c=t[1]),t[1]>u&&(u=t[1])}if(a[0]+o<s||a[0]-o>l||a[1]+o<c||a[1]-o>u)return null;let d=9007199254740991,f=null,p=0,m=0,h=-1;for(let t=0,n=r.length;t<n;t++){let s=r[t],c=r[t===n-1?0:t+1],l=s[1]-c[1],u=c[0]-s[0],g=Math.sqrt(l*l+u*u);if(g===0)continue;l/=g,u/=g;let _=l*r[0][0]+u*r[0][1],v=_;for(let e=1;e<n;e++){let t=l*r[e][0]+u*r[e][1];t<_?_=t:t>v&&(v=t)}let y=l*a[0]+u*a[1],b=_<y-o?y-o-v:_-(y+o);if(b>0)return null;if(Math.abs(b)<d){let n=e.lineAt(r,t);(P.withinBound(n,N.perpendicularFromPt(n,a))||F.intersectLine2D(i,n).length>0)&&(f=n,p=l,m=u,d=Math.abs(b),h=t)}}if(!f)return null;let g=0,_=0,v=1/0;for(let e=0,t=r.length;e<t;e++){let t=a[0]-r[e][0],n=a[1]-r[e][1],i=t*t+n*n;i<v&&(v=i,g=t,_=n)}if(v>0){let e=Math.sqrt(v);g/=e,_/=e;let t=1/0,n=-1/0;for(let e=0,i=r.length;e<i;e++){let i=g*r[e][0]+_*r[e][1];i<t&&(t=i),i>n&&(n=i)}let i=g*a[0]+_*a[1];if(i-o>n||i+o<t)return null}let y=e.centroid(r);return p*(a[0]-y[0])+m*(a[1]-y[1])<0&&(p=-p,m=-m),{which:h,dist:d,normal:new U(p,m),edge:f,vertex:a}}static hasIntersectPolygon(t,n){let r=H.iterToArray(t),i=H.iterToArray(n),a=r.length,o=i.length,s=1/0,c=1/0,l=-1/0,u=-1/0;for(let e=0;e<a;e++){let t=r[e];t[0]<s&&(s=t[0]),t[0]>l&&(l=t[0]),t[1]<c&&(c=t[1]),t[1]>u&&(u=t[1])}let d=1/0,f=1/0,p=-1/0,m=-1/0;for(let e=0;e<o;e++){let t=i[e];t[0]<d&&(d=t[0]),t[0]>p&&(p=t[0]),t[1]<f&&(f=t[1]),t[1]>m&&(m=t[1])}if(s>p||d>l||c>m||f>u)return null;let h=9007199254740991,g=-1,_=0,v=0;for(let t=0,n=a+o;t<n;t++){let n=t<a?r:i,o=t<a?t:t-a,s=n[o],c=n[o===n.length-1?0:o+1],l=s[1]-c[1],u=c[0]-s[0],d=Math.sqrt(l*l+u*u);if(d===0)continue;l/=d,u/=d;let f=e._axisOverlap2D(r,i,l,u);if(f>0)return null;Math.abs(f)<h&&(h=Math.abs(f),g=t,_=l,v=u)}if(g<0)return null;let y=g<a?0:1,b=y===0?e.lineAt(r,g):e.lineAt(i,g-a),x=y===0?i:r,S=y===0?r:i,C=e.centroid(x),w=e.centroid(S);_*(C[0]-w[0])+v*(C[1]-w[1])<0&&(_=-_,v=-v);let T=9007199254740991,E=null;for(let e=0,t=x.length;e<t;e++){let t=_*(x[e][0]-w[0])+v*(x[e][1]-w[1]);t<T&&(T=t,E=x[e])}return{which:y,dist:h,normal:new U(_,v),edge:b,vertex:E}}static intersectPolygon2D(t,n){let r=H.iterToArray(t),i=H.iterToArray(n),a=e.lines(r),o=[];for(let e=0,t=a.length;e<t;e++){let t=N.intersectPolygon2D(a[e],i,!1);t&&o.push(t)}return H.flatten(o,!0)}static toRects(e){let t=[];for(let n of e)t.push(B.boundingBox(n));let n=H.flatten(t,!1);return t.unshift(B.boundingBox(n)),t}},Te=class{static unite(e){return xe(e,`unite`)}static intersect(e){return xe(e,`intersect`)}static exclude(e){return xe(e,`exclude`)}static minusFront(e){return xe(e,`minusFront`)}static minusBack(e){return xe(e,`minusBack`)}static divide(e){return xe(e,`divide`)}static crop(e){return xe(e,`crop`)}},Ee=class e{static getSteps(e){let t=new W;for(let n=0;n<=e;n++){let r=n/e;t.push(new U(r*r*r,r*r,r,1))}return t}static controlPoints(e,t=0,n=!1){let r=H.iterToArray(e);if(t>r.length-1)return new W;let i=e=>e<r.length-1?e:r.length-1,a=r[t];return t=n?t:t+1,new W(a,r[i(t++)],r[i(t++)],r[i(t++)])}static _weights(e,t){let n=new Float64Array((e+1)*4);for(let r=0;r<=e;r++)t(r/e,n,r*4);return n}static _evalSegment(e,t,n,r){let i=t[0],a=t[1],o=t[2],s=t[3],c=i.length>2;for(let t=0;t<=r;t++){let r=t*4,l=n[r],u=n[r+1],d=n[r+2],f=n[r+3],p=l*i[0]+u*a[0]+d*o[0]+f*s[0],m=l*i[1]+u*a[1]+d*o[1]+f*s[1];e.push(c?new U(p,m,l*i[2]+u*a[2]+d*o[2]+f*s[2]):new U(p,m))}}static _calcPt(e,t){let n=e.reduce((e,n,r)=>e+n.x*t[r],0),r=e.reduce((e,n,r)=>e+n.y*t[r],0);return e[0].length>2?new U(n,r,e.reduce((e,n,r)=>e+n.z*t[r],0)):new U(n,r)}static _stepPt(e,t,n,r,i){let a=e[0],o=e[1],s=e[2],c=e[3],l=t*a[0]+n*o[0]+r*s[0]+i*c[0],u=t*a[1]+n*o[1]+r*s[1]+i*c[1];return a.length>2?new U(l,u,t*a[2]+n*o[2]+r*s[2]+i*c[2]):new U(l,u)}static catmullRom(t,n=10){let r=H.iterToArray(t);if(r.length<2)return new W;let i=new W,a=e._weights(n,(e,t,n)=>{let r=e*e,i=r*e;t[n]=-.5*i+r-.5*e,t[n+1]=1.5*i-2.5*r+1,t[n+2]=-1.5*i+2*r+.5*e,t[n+3]=.5*i-.5*r});e._evalSegment(i,e.controlPoints(r,0,!0),a,n);let o=0;for(;o<r.length-2;){let t=e.controlPoints(r,o);t.length>0&&(e._evalSegment(i,t,a,n),o++)}return i}static catmullRomStep(t,n){let r=t[0],i=t[1],a=t[2];return e._stepPt(n,-.5*r+i-.5*a,1.5*r-2.5*i+1,-1.5*r+2*i+.5*a,.5*r-.5*i)}static cardinal(t,n=10,r=.5){let i=H.iterToArray(t);if(i.length<2)return new W;let a=new W,o=e._weights(n,(e,t,n)=>{let i=e*e,a=i*e;t[n]=r*(-a+2*i-e),t[n+1]=r*(-a+i)+(2*a-3*i+1),t[n+2]=r*(a-2*i+e)+(-2*a+3*i),t[n+3]=r*(a-i)});e._evalSegment(a,e.controlPoints(i,0,!0),o,n);let s=0;for(;s<i.length-2;){let t=e.controlPoints(i,s);t.length>0&&(e._evalSegment(a,t,o,n),s++)}return a}static cardinalStep(t,n,r=.5){let i=t[0],a=t[1],o=t[2];return e._stepPt(n,r*(-i+2*a-o),r*(-i+a)+(2*i-3*a+1),r*(i-2*a+o)+(-2*i+3*a),r*(i-a))}static cardinalToBezier(e,t=.5,n=0){let r=new W;if(!(n>=0)||n===1/0)return H.warn(`cardinalToBezier needs a finite alpha of 0 or more`,r);let i=H.iterToArray(e),a=i.length;if(a<2)return r;let o=i[0].length>2,s=n===0?void 0:new Float64Array(a-1);if(s)for(let e=0;e<a-1;e++){let t=i[e+1][0]-i[e][0],r=i[e+1][1]-i[e][1],a=o?i[e+1][2]-i[e][2]:0,c=Math.pow(Math.hypot(t,r,a),n);s[e]=c<1/0?c:0}let c=(e,t,n,r,i)=>{let a=new U(o?3:2);return a[0]=e[0]+t*n,a[1]=e[1]+t*r,o&&(a[2]=e[2]+t*i),a};for(let e=0;e<a;e++){let n=i[Math.max(e-1,0)],l=i[e],u=i[Math.min(e+1,a-1)],d=s?s[Math.max(e-1,0)]:1,f=s?s[Math.min(e,a-2)]:1,p=0,m=0;if(s&&d>0&&f>0){let e=2*t/(d+f);p=f/d*e,m=d/f*e}let h=s?p*(l[0]-n[0])+m*(u[0]-l[0]):t*(u[0]-n[0]),g=s?p*(l[1]-n[1])+m*(u[1]-l[1]):t*(u[1]-n[1]),_=o?s?p*(l[2]-n[2])+m*(u[2]-l[2]):t*(u[2]-n[2]):0;e>0&&r.push(c(l,-d/3,h,g,_)),r.push(new U(l)),e<a-1&&r.push(c(l,f/3,h,g,_))}return r}static bezierToCardinal(e){let t=H.iterToArray(e),n=Math.floor((t.length-1)/3),r=new W;if(n<1)return r;for(let e=0;e<=n;e++)r.push(new U(t[3*e]));return r}static bezier(t,n=10){let r=H.iterToArray(t);if(r.length<4)return new W;let i=new W,a=e._weights(n,(e,t,n)=>{let r=e*e,i=r*e;t[n]=-i+3*r-3*e+1,t[n+1]=3*i-6*r+3*e,t[n+2]=-3*i+3*r,t[n+3]=i}),o=0;for(;o<r.length-3;){let t=e.controlPoints(r,o);t.length>0&&(e._evalSegment(i,t,a,n),o+=3)}return i}static bezierStep(t,n){let r=t[0],i=t[1],a=t[2];return e._stepPt(n,-r+3*i-3*a+1,3*r-6*i+3*a,-3*r+3*i,r)}static bspline(t,n=10,r=1){let i=H.iterToArray(t);if(i.length<2)return new W;let a=new W,o=r===1?e._weights(n,(e,t,n)=>{let r=e*e,i=r*e;t[n]=-i/6+.5*r-.5*e+1/6,t[n+1]=.5*i-r+2/3,t[n+2]=-.5*i+.5*r+.5*e+1/6,t[n+3]=i/6}):e._weights(n,(e,t,n)=>{let i=e*e,a=i*e,o=2*a-3*i+1,s=-2*a+3*i;t[n]=r*(-a/6+.5*i-.5*e+1/6),t[n+1]=r*(-1.5*a+2*i-1/3)+o,t[n+2]=r*(1.5*a-2.5*i+.5*e+1/6)+s,t[n+3]=a/6*r}),s=0;for(;s<i.length-3;){let t=e.controlPoints(i,s);t.length>0&&(e._evalSegment(a,t,o,n),s++)}return a}static bsplineStep(t,n){let r=t[0],i=t[1],a=t[2];return e._stepPt(n,-r/6+.5*i-.5*a+1/6,.5*r-i+2/3,-.5*r+.5*i+.5*a+1/6,r/6)}static bsplineTensionStep(t,n,r=1){let i=t[0],a=t[1],o=t[2],s=2*i-3*a+1,c=-2*i+3*a;return e._stepPt(n,r*(-i/6+.5*a-.5*o+1/6),r*(-1.5*i+2*a-1/3)+s,r*(1.5*i-2.5*a+.5*o+1/6)+c,i/6*r)}static bsplineToBezier(e,t=1){let n=H.iterToArray(e),r=n.length,i=new W;if(r<4)return i;let a=n[0].length>2,o=t/6,s=1-2*o,c=(e,t,n,r,i,o)=>{let s=new U(a?3:2);return s[0]=r*e[0]+i*t[0]+o*n[0],s[1]=r*e[1]+i*t[1]+o*n[1],a&&(s[2]=r*e[2]+i*t[2]+o*n[2]),s};i.push(c(n[0],n[1],n[2],o,s,o));for(let e=1;e<r-2;e++){let t=n[e],r=n[e+1];i.push(c(t,r,r,s,2*o,0),c(t,r,r,2*o,s,0),c(t,r,n[e+2],o,s,o))}return i}static bezierToBspline(e){let t=H.iterToArray(e),n=Math.floor((t.length-1)/3),r=new W;if(n<1)return r;let i=t[0].length>2?3:2,a=n+1,o=new Float64Array(a*i),s=new Float64Array(a);for(let e=0;e<a;e++){let r=e===0?t[1]:e===n?t[3*n-1]:t[3*e],a=e===0||e===n?3:6;for(let t=0;t<i;t++)o[e*i+t]=a*r[t]}s[0]=2;for(let e=1;e<a;e++){let t=1/s[e-1];s[e]=(e<n?4:2)-t;for(let n=0;n<i;n++)o[e*i+n]-=t*o[(e-1)*i+n]}for(let e=0;e<i;e++)o[(a-1)*i+e]/=s[a-1];for(let e=a-2;e>=0;e--)for(let t=0;t<i;t++)o[e*i+t]=(o[e*i+t]-o[(e+1)*i+t])/s[e];let c=new U(i),l=new U(i);for(let e=0;e<i;e++)c[e]=o[i+e]-6*(t[1][e]-t[0][e]),l[e]=o[(n-1)*i+e]+6*(t[3*n][e]-t[3*n-1][e]);r.push(c);for(let e=0;e<a;e++){let t=new U(i);for(let n=0;n<i;n++)t[n]=o[e*i+n];r.push(t)}return r.push(l),r}},De=t({Mat:()=>R,Vec:()=>L}),L=class e{static add(e,t){if(typeof t==`number`)for(let n=0,r=e.length;n<r;n++)e[n]+=t;else for(let n=0,r=e.length;n<r;n++)e[n]+=t[n]||0;return e}static subtract(e,t){if(typeof t==`number`)for(let n=0,r=e.length;n<r;n++)e[n]-=t;else for(let n=0,r=e.length;n<r;n++)e[n]-=t[n]||0;return e}static multiply(e,t){if(typeof t==`number`)for(let n=0,r=e.length;n<r;n++)e[n]*=t;else{if(e.length!=t.length)throw Error(`Cannot do element-wise multiply since the array lengths don't match: ${e.toString()} multiply-with ${t.toString()}`);for(let n=0,r=e.length;n<r;n++)e[n]*=t[n]}return e}static divide(e,t){if(typeof t==`number`){if(t===0)throw Error(`Cannot divide by zero`);for(let n=0,r=e.length;n<r;n++)e[n]/=t}else{if(e.length!=t.length)throw Error(`Cannot do element-wise divide since the array lengths don't match. ${e.toString()} divide-by ${t.toString()}`);for(let n=0,r=e.length;n<r;n++)e[n]/=t[n]}return e}static dot(e,t){if(e.length!=t.length)throw Error(`Array lengths don't match`);let n=0;for(let r=0,i=e.length;r<i;r++)n+=e[r]*t[r];return n}static cross2D(e,t){return e[0]*t[1]-e[1]*t[0]}static cross(e,t){return new U(e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0])}static magnitude(t){return Math.sqrt(e.dot(t,t))}static unit(t,n=void 0){let r=n===void 0?e.magnitude(t):n;return r===0?t:e.divide(t,r)}static abs(t){return e.map(t,Math.abs)}static floor(t){return e.map(t,Math.floor)}static ceil(t){return e.map(t,Math.ceil)}static round(t){return e.map(t,Math.round)}static max(e){let t=-1/0,n=0;for(let r=0,i=e.length;r<i;r++)e[r]>=t&&(t=e[r],n=r);return{value:t,index:n}}static min(e){let t=1/0,n=0;for(let r=0,i=e.length;r<i;r++)e[r]<=t&&(t=e[r],n=r);return{value:t,index:n}}static sum(e){let t=0;for(let n=0,r=e.length;n<r;n++)t+=e[n];return t}static map(e,t){for(let n=0,r=e.length;n<r;n++)e[n]=t(e[n],n,e);return e}},R=class e{constructor(){this.reset()}get value(){return this._33}get domMatrix(){return new DOMMatrix(e.toDOMMatrix(this._33))}reset(){this._33=e.scale2DMatrix(1,1)}scale2D(t,n=[0,0]){var r,i;let a=e.scaleAt2DMatrix((r=t[0])==null?1:r,(i=t[1])==null?1:i,n);return this._33=e.multiply(this._33,a),this}rotate2D(t,n=[0,0]){let r=e.rotateAt2DMatrix(Math.cos(t),Math.sin(t),n);return this._33=e.multiply(this._33,r),this}translate2D(t){let n=e.translate2DMatrix(t[0]||0,t[1]||0);return this._33=e.multiply(this._33,n),this}shear2D(t,n=[0,0]){var r,i;let a=e.shearAt2DMatrix(Math.tan((r=t[0])==null?0:r),Math.tan((i=t[1])==null?0:i),n);return this._33=e.multiply(this._33,a),this}static add(e,t){if(typeof t!=`number`&&(e[0].length!=t[0].length||e.length!=t.length))throw Error(`Cannot add matrix if rows' and columns' size don't match.`);let n=new W,r=typeof t==`number`;for(let i=0,a=e.length;i<a;i++)n.push(e[i].$add(r?t:t[i]));return n}static multiply(t,n,r=!1,i=!1){let a=new W;if(typeof n!=`number`){if(i){if(t.length!=n.length)throw Error(`Cannot multiply matrix element-wise because the matrices' sizes don't match.`);for(let e=0,r=t.length;e<r;e++)a.push(t[e].$multiply(n[e]))}else{if(!r&&t[0].length!=n.length)throw Error(`Cannot multiply matrix if rows in matrix-a don't match columns in matrix-b.`);if(r&&t[0].length!=n[0].length)throw Error(`Cannot multiply matrix if transposed and the columns in both matrices don't match.`);r||(n=e.transpose(n));for(let e=0,r=t.length;e<r;e++){let r=U.make(n.length,0);for(let i=0,a=n.length;i<a;i++)r[i]=L.dot(t[e],n[i]);a.push(r)}}}else for(let e=0,r=t.length;e<r;e++)a.push(t[e].$multiply(n));return a}static zipSlice(e,t,n=!1){let r=[];for(let i=0,a=e.length;i<a;i++)if(e[i].length-1<t){if(n===!1)throw Error(`Index ${t} is out of bounds`);r.push(n)}else r.push(e[i][t]);return new U(r)}static zip(t,n=!1,r=!1){let i=new W,a=r?t.reduce((e,t)=>Math.max(e,t.length),0):t[0].length;for(let r=0;r<a;r++)i.push(e.zipSlice(t,r,n));return i}static transpose(t,n=!1,r=!1){return e.zip(t,n,r)}static toDOMMatrix(e){return[e[0][0],e[0][1],e[1][0],e[1][1],e[2][0],e[2][1]]}static transform2D(e,t){return new U(e[0]*t[0][0]+e[1]*t[1][0]+t[2][0],e[0]*t[0][1]+e[1]*t[1][1]+t[2][1])}static scale2DMatrix(e,t){return new W(new U(e,0,0),new U(0,t,0),new U(0,0,1))}static rotate2DMatrix(e,t){return new W(new U(e,t,0),new U(-t,e,0),new U(0,0,1))}static shear2DMatrix(e,t){return new W(new U(1,e,0),new U(t,1,0),new U(0,0,1))}static translate2DMatrix(e,t){return new W(new U(1,0,0),new U(0,1,0),new U(e,t,1))}static scaleAt2DMatrix(t,n,r){let i=e.scale2DMatrix(t,n);return i[2][0]=-r[0]*t+r[0],i[2][1]=-r[1]*n+r[1],i}static rotateAt2DMatrix(t,n,r){let i=e.rotate2DMatrix(t,n);return i[2][0]=r[0]*(1-t)+r[1]*n,i[2][1]=r[1]*(1-t)-r[0]*n,i}static shearAt2DMatrix(t,n,r){let i=e.shear2DMatrix(t,n);return i[2][0]=-r[1]*n,i[2][1]=-r[0]*t,i}static reflectAt2DMatrix(e,t){let n=N.intercept(e,t);if(n==null)return[new U([-1,0,0]),new U([0,1,0]),new U([e[0]+t[0],0,1])];{let e=n.yi,t=Math.atan(n.slope)*2,r=Math.cos(t),i=Math.sin(t);return[new U([r,i,0]),new U([i,-r,0]),new U([-e*i,e+e*r,1])]}}};function Oe(){let e=4022871197;return function(t){if(t){t=t.toString();for(let n=0;n<t.length;n++){e+=t.charCodeAt(n);let r=.02519603282416938*e;e=r>>>0,r-=e,r*=e,e=r>>>0,r-=e,e+=r*4294967296}return(e>>>0)*23283064365386963e-26}return e=4022871197,0}}function ke(e){let t=1,n=48,r=Array(48),i=Oe();function a(){i();for(let e=0;e<48;e++)r[e]=i(` `);t=1,n=48}function o(e){return e=e.replace(/(^\s*)|(\s*$)/gi,``),e=e.replace(/[\x00-\x1F]/gi,``),e}function s(e){e=o(e),i(e);for(let t=0;t<e.length;t++){let n=e.charCodeAt(t).toString();for(let e=0;e<48;e++)r[e]-=i(n),r[e]<0&&(r[e]+=1)}}return a(),s(e),{random(){++n>=48&&(n=0);let e=1768863*r[n]+t*23283064365386963e-26;return r[n]=e-(t=e|0)}}}var Ae=t({Geom:()=>B,Num:()=>z,Range:()=>Me,Shaping:()=>je}),z=class e{static equals(e,t,n=1e-5){return e===t||Math.abs(e-t)<=n}static lerp(e,t,n){return(1-n)*e+n*t}static clamp(e,t,n){return Math.max(t,Math.min(n,e))}static boundValue(e,t,n){let r=Math.abs(n-t),i=(e-t)%r;return i<0&&(i+=r),i+t}static within(e,t,n){return e>=Math.min(t,n)&&e<=Math.max(t,n)}static randomRange(t,n=0){let r=t>n?t-n:n-t;return Math.min(t,n)+e.random()*r}static randomPt(t,n){let r=new U(t.length),i=n?L.subtract(n.slice(),t):t,a=n?t:new U(t.length).fill(0);for(let t=0,n=r.length;t<n;t++)r[t]=e.random()*i[t]+a[t];return r}static normalizeValue(e,t,n){let r=Math.min(t,n),i=Math.max(t,n);return(e-r)/(i-r)}static sum(e){let t=H.iterToArray(e),n=new U(t[0]);for(let e=1,r=t.length;e<r;e++)L.add(n,t[e]);return n}static average(t){let n=H.iterToArray(t);return e.sum(n).divide(n.length)}static cycle(e,t=je.sineInOut){return t(e>.5?2-e*2:e*2)}static mapToRange(e,t,n,r,i){if(t==n)throw Error(`[currMin, currMax] must define a range that is not zero`);return r+(e-t)/(n-t)*(i-r)}static seed(e){this.generator=ke(e)}static random(){return this.generator?this.generator.random():Math.random()}},B=class e{static boundAngle(e){return z.boundValue(e,0,360)}static boundRadian(e){return z.boundValue(e,0,V.two_pi)}static toRadian(e){return e*V.deg_to_rad}static toDegree(e){return e*V.rad_to_deg}static boundingBox(e){let t,n;for(let r of e)if(t==null)t=r.clone(),n=r.clone();else for(let e=0,i=Math.min(t.length,r.length);e<i;e++)t[e]=Math.min(t[e],r[e]),n[e]=Math.max(n[e],r[e]);return new W(t,n)}static centroid(e){return z.average(e)}static anchor(e,t=0,n=`to`){let r=n==`to`?`subtract`:`add`,i=0;for(let n of e)typeof t==`number`?t!==i&&n[r](e[t]):n[r](t),i++}static interpolate(e,t,n=.5){let r=Math.min(e.length,t.length),i=U.make(r);for(let a=0;a<r;a++)i[a]=e[a]*(1-n)+t[a]*n;return i}static perpendicular(e,t=V.xy){let n=t[1],r=t[0],i=new U(e),a=new U(i);a[r]=-i[n],a[n]=i[r];let o=new U(i);return o[r]=i[n],o[n]=-i[r],new W(a,o)}static isPerpendicular(e,t){let n=0,r=0,i=0;for(let a=0,o=Math.min(e.length,t.length);a<o;a++)n+=e[a]*t[a],r+=e[a]*e[a],i+=t[a]*t[a];return Math.abs(n)<=V.epsilon*Math.sqrt(r*i)}static withinBound(e,t,n){for(let r=0,i=Math.min(e.length,t.length,n.length);r<i;r++)if(!z.within(e[r],t[r],n[r]))return!1;return!0}static sortEdges(t){let n=H.iterToArray(t),r=e.boundingBox(n),i=r[1].add(r[0]).divide(2),a=i[0],o=i[1];return n.sort((e,t)=>{if(e.length<2||t.length<2)throw Error(`Pt dimension cannot be less than 2`);let n=e[0]-a,r=e[1]-o,i=t[0]-a,s=t[1]-o;if(n>=0&&i<0)return 1;if(n<0&&i>=0)return-1;if(n==0&&i==0)return r>=0||s>=0?r>s?1:-1:s>r?1:-1;let c=n*s-r*i;return c<0?1:c>0?-1:n*n+r*r>i*i+s*s?1:-1})}static scale(t,n,r){let i=H.iterToArray(t[0]!==void 0&&typeof t[0]==`number`?[t]:t),a=typeof n==`number`?U.make(i[0].length,n):n;r||(r=U.make(i[0].length,0));for(let e=0,t=i.length;e<t;e++){let t=i[e];for(let e=0,n=t.length;e<n;e++)t[e]=r&&r[e]?r[e]+(t[e]-r[e])*a[e]:t[e]*a[e]}return e}static rotate2D(t,n,r,i){let a=H.iterToArray(t[0]!==void 0&&typeof t[0]==`number`?[t]:t),o=r?R.rotateAt2DMatrix:R.rotate2DMatrix;r||(r=U.make(a[0].length,0));let s=o(Math.cos(n),Math.sin(n),r);for(let e=0,t=a.length;e<t;e++){let t=i?a[e].$take(i):a[e];if(t.to(R.transform2D(t,s)),i)for(let n=0;n<i.length;n++)a[e][i[n]]=t[n]}return e}static shear2D(t,n,r,i){let a=H.iterToArray(t[0]!==void 0&&typeof t[0]==`number`?[t]:t),o=typeof n==`number`?[n,n]:n;r||(r=U.make(a[0].length,0));let s=(r?R.shearAt2DMatrix:R.shear2DMatrix)(Math.tan(o[0]),Math.tan(o[1]),r);for(let e=0,t=a.length;e<t;e++){let t=i?a[e].$take(i):a[e];if(t.to(R.transform2D(t,s)),i)for(let n=0;n<i.length;n++)a[e][i[n]]=t[n]}return e}static reflect2D(t,n,r){let i=H.iterToArray(t[0]!==void 0&&typeof t[0]==`number`?[t]:t),a=H.iterToArray(n),o=R.reflectAt2DMatrix(a[0],a[1]);for(let e=0,t=i.length;e<t;e++){let t=r?i[e].$take(r):i[e];if(t.to(R.transform2D(t,o)),r)for(let n=0;n<r.length;n++)i[e][r[n]]=t[n]}return e}static cosTable(){let t=new Float64Array(360);for(let e=0;e<360;e++)t[e]=Math.cos(e*Math.PI/180);return{table:t,cos:n=>t[Math.floor(e.boundAngle(e.toDegree(n)))]}}static sinTable(){let t=new Float64Array(360);for(let e=0;e<360;e++)t[e]=Math.sin(e*Math.PI/180);return{table:t,sin:n=>t[Math.floor(e.boundAngle(e.toDegree(n)))]}}},je=class e{static linear(e,t=1){return t*e}static quadraticIn(e,t=1){return t*e*e}static quadraticOut(e,t=1){return-t*e*(e-2)}static quadraticInOut(e,t=1){let n=e*2;return e<.5?t/2*e*e*4:-t/2*((n-1)*(n-3)-1)}static cubicIn(e,t=1){return t*e*e*e}static cubicOut(e,t=1){let n=e-1;return t*(n*n*n+1)}static cubicInOut(e,t=1){let n=e*2;return e<.5?t/2*n*n*n:t/2*((n-2)*(n-2)*(n-2)+2)}static exponentialIn(e,t=1,n=.25){return t*Math.pow(e,1/n)}static exponentialOut(e,t=1,n=.25){return t*Math.pow(e,n)}static sineIn(e,t=1){return-t*Math.cos(e*V.half_pi)+t}static sineOut(e,t=1){return t*Math.sin(e*V.half_pi)}static sineInOut(e,t=1){return-t/2*(Math.cos(Math.PI*e)-1)}static cosineApprox(e,t=1){let n=e*e,r=n*n;return t*(r*n*4/9-17*r/9+22*n/9)}static circularIn(e,t=1){return-t*(Math.sqrt(1-e*e)-1)}static circularOut(e,t=1){let n=e-1;return t*Math.sqrt(1-n*n)}static circularInOut(e,t=1){let n=e*2;return e<.5?-t/2*(Math.sqrt(1-n*n)-1):t/2*(Math.sqrt(1-(n-2)*(n-2))+1)}static elasticIn(e,t=1,n=.7){let r=e-1,i=n/V.two_pi*1.5707963267948966;return t*(-Math.pow(2,10*r)*Math.sin((r-i)*V.two_pi/n))}static elasticOut(e,t=1,n=.7){let r=n/V.two_pi*1.5707963267948966;return t*(Math.pow(2,-10*e)*Math.sin((e-r)*V.two_pi/n))+t}static elasticInOut(e,t=1,n=.6){let r=e*2,i=n/V.two_pi*1.5707963267948966;return e<.5?(--r,t*(-.5*(Math.pow(2,10*r)*Math.sin((r-i)*V.two_pi/n)))):(--r,t*(.5*(Math.pow(2,-10*r)*Math.sin((r-i)*V.two_pi/n)))+t)}static bounceIn(t,n=1){return n-e.bounceOut(1-t,n)}static bounceOut(e,t=1){return e<1/2.75?t*(7.5625*e*e):e<2/2.75?(e-=1.5/2.75,t*(7.5625*e*e+.75)):e<2.5/2.75?(e-=2.25/2.75,t*(7.5625*e*e+.9375)):(e-=2.625/2.75,t*(7.5625*e*e+.984375))}static bounceInOut(t,n=1){return t<.5?e.bounceIn(t*2,n)/2:e.bounceOut(t*2-1,n)/2+n/2}static sigmoid(e,t=1,n=10){let r=n*(e-.5);return t/(1+Math.exp(-r))}static logSigmoid(e,t=1,n=.7){n=Math.max(V.epsilon,Math.min(1-V.epsilon,n)),n=1/(1-n);let r=1/(1+Math.exp((e-.5)*n*-2)),i=1/(1+Math.exp(n)),a=1/(1+Math.exp(-n));return t*(r-i)/(a-i)}static seat(e,t=1,n=.5){return e<.5?t*Math.pow(2*e,1-n)/2:t*(1-Math.pow(2*(1-e),1-n)/2)}static quadraticBezier(e,t=1,n=[.05,.95]){let r=typeof n==`number`?n:n[0],i=typeof n==`number`?.5:n[1],a=1-2*r;a===0&&(a=V.epsilon);let o=(Math.sqrt(r*r+a*e)-r)/a;return t*((1-2*i)*(o*o)+2*i*o)}static cubicBezier(e,t=1,n=[.1,.7],r=[.9,.2]){let i=new W(new U(0,0),new U(n),new U(r),new U(1,1));return t*Ee.bezierStep(new U(e*e*e,e*e,e,1),Ee.controlPoints(i)).y}static quadraticTarget(e,t=1,n=[.2,.35]){let r=Math.min(1-V.epsilon,Math.max(V.epsilon,n[0])),i=Math.min(1,Math.max(0,n[1])),a=(1-i)/(1-r)-i/r,o=(r*r*a-i)/r,s=e*e*a-o*e;return t*Math.min(1,Math.max(0,s))}static cliff(e,t=1,n=.5){return e>n?t:0}static step(e,t,n,r,...i){let a=1/t;return e(Math.floor(n/a)*a,r,...i)}},Me=class{constructor(e){this._dims=0,this._source=W.fromPtArray(e),this.calc()}get max(){return this._max.clone()}get min(){return this._min.clone()}get magnitude(){return this._mag.clone()}calc(){if(!this._source)return;let e=this._source[0].length;this._dims=e;let t=new U(e),n=new U(e),r=new U(e);for(let i=0;i<e;i++){t[i]=-1/0,n[i]=1/0,r[i]=0;let e=this._source.zipSlice(i);for(let a=0,o=e.length;a<o;a++)t[i]=Math.max(t[i],e[a]),n[i]=Math.min(n[i],e[a]),r[i]=t[i]-n[i]}return this._max=t,this._min=n,this._mag=r,this}mapTo(e,t,n){let r=new W;for(let i=0,a=this._source.length;i<a;i++){let a=this._source[i],o=new U(this._dims);for(let r=0;r<this._dims;r++)o[r]=n&&n[r]?a[r]:z.mapToRange(a[r],this._min[r],this._max[r],e,t);r.push(o)}return r}append(e,t=!0){let n=H.iterToArray(e);if(n[0].length!==this._dims)throw Error(`Dimensions don't match. ${this._dims} dimensions in Range and ${n[0].length} provided in parameter. `);return this._source=this._source.concat(n),t&&this.calc(),this}ticks(e){let t=new W;for(let n=0;n<=e;n++){let r=new U(this._dims),i=e>0?n/e:0;for(let e=0,t=this._max.length;e<t;e++)r[e]=z.lerp(this._min[e],this._max[e],i);t.push(r)}return t}},Ne=t({Const:()=>V,Util:()=>H});let V={xy:`xy`,yz:`yz`,xz:`xz`,xyz:`xyz`,horizontal:0,vertical:1,identical:0,right:4,bottom_right:5,bottom:6,bottom_left:7,left:8,top_left:1,top:2,top_right:3,epsilon:1e-4,max:Number.MAX_VALUE,min:Number.MIN_VALUE,pi:Math.PI,two_pi:6.283185307179586,half_pi:1.5707963267948966,quarter_pi:.7853981633974483,one_degree:.017453292519943295,rad_to_deg:57.29577951308232,deg_to_rad:.017453292519943295,gravity:9.81,newton:.10197,gaussian:.3989422804014327};var H=class e{static warnLevel(t){return t&&(e._warnLevel=t),e._warnLevel}static getArgs(t){if(t.length<1)return[];let n=[],r=Array.isArray(t[0])||ArrayBuffer.isView(t[0]);if(typeof t[0]==`number`)n=Array.prototype.slice.call(t);else if(typeof t[0]==`object`&&!r){let e=[`x`,`y`,`z`,`w`],r=t[0];for(let t=0;t<e.length&&!(r.length&&t>=r.length||!(e[t]in r));t++)n.push(r[e[t]])}else r&&(n=e.toNumericArray(t[0]));return n}static toNumericArray(e){if(Array.isArray(e))return e.slice();let t=[];for(let n=0,r=e.length;n<r;n++)t.push(e[n]);return t}static getPtLike(t){let n=t[0];return typeof n==`number`?t:t.length===1&&(Array.isArray(n)||ArrayBuffer.isView(n))?n:e.getArgs(t)}static warn(t=`error`,n=void 0){if(e.warnLevel()==`error`)throw Error(t);return e.warnLevel()==`warn`&&console.warn(t),n}static randomInt(t,n=0){return e.warn("Util.randomInt is deprecated. Please use `Num.randomRange`"),Math.floor(z.random()*t)+n}static split(e,t,n,r=!1,i=!0){let a=[],o=[],s=n||t,c=0;if(e.length<=0||s<=0)return[];for(;c<e.length;){o=[];for(let n=0;n<t;n++)if(r)o.push(e[(c+n)%e.length]);else{if(c+n>=e.length)break;o.push(e[c+n])}c+=s,(!i||i&&o.length===t)&&a.push(o)}return a}static flatten(e,t=!0){let n=t?new W:[];for(let t=0,r=e.length;t<r;t++){let r=e[t];if(Array.isArray(r))for(let e=0,t=r.length;e<t;e++)n.push(r[e]);else n.push(r)}return n}static combine(e,t,n){let r=[];for(let i=0,a=e.length;i<a;i++)for(let a=0,o=t.length;a<o;a++)r.push(n(e[i],t[a]));return r}static zip(e){let t=[];for(let n=0,r=e[0].length;n<r;n++){let r=[];for(let t=0;t<e.length;t++)r.push(e[t][n]);t.push(r)}return t}static stepper(e,t=0,n=1,r){let i=t;return function(){return i+=n,i>=e&&(i=t+(i-t)%(e-t)),r&&r(i),i}}static forRange(e,t,n=0,r=1){let i=[];for(let a=n,o=t;a<o;a+=r)i[a]=e(a);return i}static load(e,t){let n=new XMLHttpRequest;n.open(`GET`,e,!0),n.onload=function(){n.status>=200&&n.status<400?t(n.responseText,!0):t(`Server error (${n.status}) when loading "${e}"`,!1)},n.onerror=function(){t(`Unknown network error`,!1)},n.send()}static download(e,t=`pts_canvas_image`,n=`png`,r=1){let i=n===`jpg`?`jpeg`:n;e.element.toBlob(function(e){let r=document.createElement(`a`),i=URL.createObjectURL(e);r.href=i,r.download=`${t}.${n}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(i)},`image/${i}`,r)}static performance(e=10){let t=Date.now(),n=[];return function(){let r=Date.now();return n.push(r-t),n.length>e&&n.shift(),t=r,Math.floor(n.reduce((e,t)=>e+t,0)/n.length)}}static arrayCheck(t,n=2){return Array.isArray(t)&&t.length<n?(e.warn(`Requires ${n} or more Pts in this Group.`),!1):!0}static iterToArray(e){return Array.isArray(e)?e:[...e]}static isMobile(){return/iPhone|iPad|Android/i.test(navigator.userAgent)}static uniqueId(e=!1){var t;return e&&typeof crypto<`u`&&(t=crypto)!=null&&t.randomUUID?crypto.randomUUID():Date.now().toString(36)+Math.random().toString(36).substring(2)}};H._warnLevel=`mute`;var Pe=t({Bound:()=>G,Group:()=>W,Pt:()=>U}),U=class e extends Float32Array{constructor(...e){let t,n=e[0];t=e.length===1&&typeof n==`number`?n:e.length===0?2:e.length===1&&(Array.isArray(n)||ArrayBuffer.isView(n))?n:typeof n==`number`?e:H.getArgs(e),super(t)}static make(t,n=0,r=!1){let i=new e(t);if(n&&i.fill(n),r)for(let e=0,t=i.length;e<t;e++)i[e]=i[e]*z.random();return i}get id(){return this._id}set id(e){this._id=e}get x(){return this[0]}set x(e){this[0]=e}get y(){return this[1]}set y(e){this[1]=e}get z(){return this[2]}set z(e){this[2]=e}get w(){return this[3]}set w(e){this[3]=e}clone(){return new e(this)}equals(e,t=1e-6){for(let n=0,r=this.length;n<r;n++)if(!(Math.abs(this[n]-e[n])<=t))return!1;return!0}to(...e){let t=H.getPtLike(e);for(let e=0,n=Math.min(this.length,t.length);e<n;e++)this[e]=t[e];return this}$to(...e){return this.clone().to(...e)}toAngle(e,t,n=!1){let r=t==null?this.magnitude():t,i=[Math.cos(e)*r,Math.sin(e)*r];return n?this.add(i):this.to(i)}op(e){let t=this;return(...n)=>e(t,...n)}ops(e){let t=[];for(let n=0,r=e.length;n<r;n++)t.push(this.op(e[n]));return t}$take(t){let n=[];for(let e=0,r=t.length;e<r;e++)n.push(this[t[e]]||0);return new e(n)}$concat(...t){return new e(this.toArray().concat(H.getArgs(t)))}add(...e){return e.length===1&&typeof e[0]==`number`?L.add(this,e[0]):L.add(this,H.getPtLike(e)),this}$add(...e){return this.clone().add(...e)}subtract(...e){return e.length===1&&typeof e[0]==`number`?L.subtract(this,e[0]):L.subtract(this,H.getPtLike(e)),this}$subtract(...e){return this.clone().subtract(...e)}multiply(...e){return e.length===1&&typeof e[0]==`number`?L.multiply(this,e[0]):L.multiply(this,H.getPtLike(e)),this}$multiply(...e){return this.clone().multiply(...e)}divide(...e){return e.length===1&&typeof e[0]==`number`?L.divide(this,e[0]):L.divide(this,H.getPtLike(e)),this}$divide(...e){return this.clone().divide(...e)}magnitudeSq(){return L.dot(this,this)}magnitude(){return L.magnitude(this)}unit(e=void 0){return L.unit(this,e),this}$unit(e=void 0){return this.clone().unit(e)}dot(...e){return L.dot(this,H.getPtLike(e))}$cross2D(...e){return L.cross2D(this,H.getPtLike(e))}$cross(...e){return L.cross(this,H.getPtLike(e))}$project(...e){return this.$multiply(this.dot(...e)/this.magnitudeSq())}projectScalar(...e){return this.dot(...e)/this.magnitude()}abs(){return L.abs(this),this}$abs(){return this.clone().abs()}floor(){return L.floor(this),this}$floor(){return this.clone().floor()}ceil(){return L.ceil(this),this}$ceil(){return this.clone().ceil()}round(){return L.round(this),this}$round(){return this.clone().round()}minValue(){return L.min(this)}maxValue(){return L.max(this)}$min(...e){let t=H.getPtLike(e),n=this.clone();for(let e=0,r=Math.min(this.length,t.length);e<r;e++)n[e]=Math.min(this[e],t[e]);return n}$max(...e){let t=H.getPtLike(e),n=this.clone();for(let e=0,r=Math.min(this.length,t.length);e<r;e++)n[e]=Math.max(this[e],t[e]);return n}angle(e=V.xy){return Math.atan2(this[e[1]],this[e[0]])}angleBetween(e,t=V.xy){return B.boundRadian(this.angle(t)-e.angle(t)+Math.PI)-Math.PI}scale(t,n){return B.scale(this,t,n||e.make(this.length,0)),this}rotate2D(t,n,r){return B.rotate2D(this,t,n||e.make(this.length,0),r),this}shear2D(t,n,r){return B.shear2D(this,t,n||e.make(this.length,0),r),this}reflect2D(e,t){return B.reflect2D(this,e,t),this}toString(){return`Pt(${this.join(`, `)})`}toArray(){let e=[];for(let t=0,n=this.length;t<n;t++)e.push(this[t]);return e}toGroup(){return new W(e.make(this.length),this.clone())}toBound(){return new G(e.make(this.length),this.clone())}},W=class e extends Array{constructor(...e){super(...e)}get id(){return this._id}set id(e){this._id=e}get p1(){return this[0]}get p2(){return this[1]}get p3(){return this[2]}get p4(){return this[3]}get q1(){return this[this.length-1]}get q2(){return this[this.length-2]}get q3(){return this[this.length-3]}get q4(){return this[this.length-4]}clone(){let t=new e;for(let e=0,n=this.length;e<n;e++)t.push(this[e].clone());return t}static fromArray(t){let n=new e;for(let e of t){let t=e instanceof U?e:new U(e);n.push(t)}return n}static fromPtArray(t){return e.from(t)}split(t,n,r=!1){let i=n||t,a=[];if(this.length<=0||i<=0)return a;let o=0;for(;o<this.length;){let n=new e,s=0;for(let e=0;e<t;e++)if(r)n[s++]=this[(o+e)%this.length];else{if(o+e>=this.length)break;n[s++]=this[o+e]}o+=i,s===t&&a.push(n)}return a}insert(e,t=0){let n=H.iterToArray(e);n===this&&(n=n.slice());let r=this.length,i=n.length;if(i===0)return this;let a=Math.trunc(t)||0;a=a<0?Math.max(r+a,0):Math.min(a,r),this.length=r+i;for(let e=r-1;e>=a;e--)this[e+i]=this[e];for(let e=0;e<i;e++)this[a+e]=n[e];return this}remove(t=0,n=1){let r=t<0?[t*-1-1,n]:[t,n];return e.prototype.splice.apply(this,r)}segments(e=2,t=1,n=!1){return this.split(e,t,n)}lines(){return this.segments(2,1)}centroid(){return B.centroid(this)}boundingBox(){return B.boundingBox(this)}anchorTo(e=0){B.anchor(this,e,`to`)}anchorFrom(e=0){B.anchor(this,e,`from`)}op(e){let t=this;return(...n)=>e(t,...n)}ops(e){let t=[];for(let n=0,r=e.length;n<r;n++)t.push(this.op(e[n]));return t}interpolate(e){e=z.clamp(e,0,1);let t=this.length-1,n=1/(this.length-1),r=Math.floor(e/n);return B.interpolate(this[r],this[Math.min(this.length-1,r+1)],(e-r*n)*t)}moveBy(...e){return this.add(...e)}moveTo(...e){let t=new U(...e).subtract(this[0]);return this.moveBy(t),this}scale(e,t){for(let n=0,r=this.length;n<r;n++)B.scale(this[n],e,t||this[0]);return this}rotate2D(e,t,n){for(let r=0,i=this.length;r<i;r++)B.rotate2D(this[r],e,t||this[0],n);return this}shear2D(e,t,n){for(let r=0,i=this.length;r<i;r++)B.shear2D(this[r],e,t||this[0],n);return this}reflect2D(e,t){for(let n=0,r=this.length;n<r;n++)B.reflect2D(this[n],e,t);return this}sortByDimension(e,t=!1){return this.sort((n,r)=>t?r[e]-n[e]:n[e]-r[e])}forEachPt(e,...t){if(this.length===0)return this;if(!this[0][e])return H.warn(`${e} is not a function of Pt`),this;for(let n=0,r=this.length;n<r;n++)this[n]=this[n][e](...t);return this}_vecOp(e,t){let n=t.length===1&&typeof t[0]==`number`?t[0]:H.getPtLike(t);for(let t=0,r=this.length;t<r;t++)e(this[t],n);return this}add(...e){return this._vecOp(L.add,e)}subtract(...e){return this._vecOp(L.subtract,e)}multiply(...e){return this._vecOp(L.multiply,e)}divide(...e){return this._vecOp(L.divide,e)}$matrixAdd(e){return R.add(this,e)}$matrixMultiply(e,t=!1,n=!1){return R.multiply(this,e,t,n)}zipSlice(e,t=!1){return R.zipSlice(this,e,t)}$zip(e=void 0,t=!1){return R.zip(this,e,t)}toBound(){return G.fromGroup(this)}toString(){return`Group[ `+this.reduce((e,t)=>e+t.toString()+` `,``)+` ]`}},G=class e extends W{constructor(...e){super(...e),this._center=new U,this._size=new U,this._inited=!1,this.init()}static fromBoundingRect(t){let n=new e(new U(t.left||0,t.top||0),new U(t.right||0,t.bottom||0));return t.width&&t.height&&(n.size=new U(t.width,t.height)),n}static fromGroup(t){let n=H.iterToArray(t);if(n.length<2)throw Error(`Cannot create a Bound from a group that has less than 2 Pt`);let r=n[0],i=n[n.length-1];return new e(r instanceof U?r:new U(r),i instanceof U?i:new U(i))}init(){this.p1&&(this._size=this.p1.clone(),this._inited=!0),this.p1&&this.p2&&(this._updateSize(),this._inited=!0)}clone(){return new e(this.topLeft,this.bottomRight)}_updateSize(){let e=this[0],t=this[1],n=t?t.length:0;this._size.length!==n&&(this._size=new U(n));for(let r=0;r<n;r++){let n=e&&e[r]||0;e&&t[r]<n&&(e[r]=t[r],t[r]=n,n=e[r]),this._size[r]=Math.abs(t[r]-n)}this._updateCenter()}_updateCenter(){let e=this[0],t=this._size.length;this._center.length!==t&&(this._center=new U(t));for(let n=0;n<t;n++)this._center[n]=this._size[n]*.5+(e&&e[n]||0)}_updatePosFromTop(){this.bottomRight=this.topLeft.$add(this._size),this._updateCenter()}_updatePosFromBottom(){this.topLeft=this.bottomRight.$subtract(this._size),this._updateCenter()}_updatePosFromCenter(){let e=this._size.$multiply(.5),t=this._center;this[0]=t.$subtract(e),this[1]=t.$add(e)}get size(){return new U(this._size)}set size(e){this._size=new U(e),this._updatePosFromTop()}get center(){return new U(this._center)}set center(e){this._center=new U(e),this._updatePosFromCenter()}get topLeft(){return new U(this[0])}set topLeft(e){this[0]=new U(e),this._updateSize()}get bottomRight(){return new U(this[1])}set bottomRight(e){this[1]=new U(e),this._updateSize()}get width(){return this._size.length>0?this._size.x:0}set width(e){this._size.x=e,this._updatePosFromTop()}get height(){return this._size.length>1?this._size.y:0}set height(e){this._size.y=e,this._updatePosFromTop()}get depth(){return this._size.length>2?this._size.z:0}set depth(e){this._size.z=e,this._updatePosFromTop()}get x(){return this[0]?this[0][0]:void 0}get y(){return this[0]?this[0][1]:void 0}get z(){return this[0]?this[0][2]:void 0}get inited(){return this._inited}update(){return this._updateSize(),this}};function Fe(e){"@babel/helpers - typeof";return Fe=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},Fe(e)}function Ie(e,t){if(Fe(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(Fe(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Le(e){var t=Ie(e,`string`);return Fe(t)==`symbol`?t:t+``}function Re(e,t,n){return(t=Le(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ze(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function K(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?ze(Object(n),!0).forEach(function(t){Re(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ze(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var Be=t({UI:()=>We,UIButton:()=>Ge,UIDragger:()=>Ke,UIPointerActions:()=>q,UIShape:()=>Ue});function Ve(e,t,n,r){if(r<0)return!1;let i=t[0]-e[0],a=t[1]-e[1],o=i*i+a*a,s=o===0?0:Math.max(0,Math.min(1,((n[0]-e[0])*i+(n[1]-e[1])*a)/o)),c=n[0]-e[0]-s*i,l=n[1]-e[1]-s*a;return c*c+l*l<=r*r}let He={rectangle:(e,t)=>P.withinBound(e,t),circle:(e,t)=>F.withinBound(e,t),polygon:(e,t)=>I.hasIntersectPoint(e,t),line:(e,t,n)=>{var r;let i=(r=n.lineThreshold)==null?5:r;return e.length>=2&&Ve(e[0],e[1],t,i)},polyline:(e,t,n)=>{var r;let i=(r=n.lineThreshold)==null?5:r;for(let n=0,r=e.length-1;n<r;n++)if(Ve(e[n],e[n+1],t,i))return!0;return!1}},Ue={rectangle:`rectangle`,circle:`circle`,polygon:`polygon`,polyline:`polyline`,line:`line`},q={up:`up`,down:`down`,move:`move`,drag:`drag`,uidrag:`uidrag`,drop:`drop`,uidrop:`uidrop`,over:`over`,out:`out`,enter:`enter`,leave:`leave`,click:`click`,keydown:`keydown`,keyup:`keyup`,pointerdown:`pointerdown`,pointerup:`pointerup`,contextmenu:`contextmenu`,all:`all`};var We=class e{constructor(t,n,r={},i){this._abortCleanup={},this._holds=new Map,this._group=W.fromArray(t),this._shape=n,this._id=i===void 0?`ui_${e._counter++}`:i,this._states=r,this._actions={},this._sysActions={}}static registerShape(e,t){He[e]=t}static fromRectangle(e,t,n){return new this(e,Ue.rectangle,t,n)}static fromCircle(e,t,n){return new this(e,Ue.circle,t,n)}static fromPolygon(e,t,n){return new this(e,Ue.polygon,t,n)}static fromUI(e,t,n){return new this(e.group,e.shape,t||K({},e._states),n)}get id(){return this._id}set id(e){this._id=e}get group(){return this._group}set group(e){this._group=e}get shape(){return this._shape}set shape(e){this._shape=e}state(e,t){return e?t===void 0?this._states[e]:(this._states[e]=t,this):null}getState(e){return this._states[e]}setState(e,t){return this._states[e]=t,this}on(t,n,r){var i;if(!n||r!=null&&(i=r.signal)!=null&&i.aborted)return-1;this._actions[t]||(this._actions[t]=[]);let a=n,o=-1;if(r!=null&&r.once&&(a=(e,r,i,a)=>{this.off(t,o),n(e,r,i,a)}),o=e._addHandler(this._actions[t],a),r!=null&&r.signal){let e=r.signal,n=()=>this.off(t,o);e.addEventListener(`abort`,n,{once:!0}),this._abortCleanup[t]||(this._abortCleanup[t]=new Map),this._abortCleanup[t].set(o,()=>e.removeEventListener(`abort`,n))}return o}off(t,n){if(!this._actions[t])return!1;if(n===void 0){var r;return(r=this._abortCleanup[t])==null||r.forEach(e=>e()),delete this._abortCleanup[t],delete this._actions[t],!0}var i,a,o;return(i=this._abortCleanup[t])==null||(a=i.get(n))==null||a.call(i),(o=this._abortCleanup[t])==null||o.delete(n),e._removeHandler(this._actions[t],n)}listen(t,n,r){let i=!1,a=this._actions[t],o=this._sysActions[t];return(a||o)&&(this._within(n)||this._holdsType(t))&&(o&&(e._trigger(o,this,n,t,r),i=!0),a&&(e._trigger(a,this,n,t,r),i=!0)),this._actions.all&&(e._trigger(this._actions.all,this,n,t,r),i=!0),i}_holdsType(e){for(let t of this._holds.values())if(t===e)return!0;return!1}_sysOn(t,n){return this._sysActions[t]||(this._sysActions[t]=[]),e._addHandler(this._sysActions[t],n)}_sysOff(t,n){return this._sysActions[t]?e._removeHandler(this._sysActions[t],n):!1}hold(e){let t=Math.max(0,...Array.from(this._holds.keys()))+1;return this._holds.set(t,e),t}unhold(e){e===void 0?this._holds.clear():this._holds.delete(e)}static track(e,t,n,r){for(let i=0,a=e.length;i<a;i++)e[i].listen(t,n,r)}render(e){e(this._group,this._states)}toString(){return`UI ${this.group.toString()}`}_within(e){let t=He[this._shape];return t?t(this._group,e,this._states):!1}static _trigger(e,t,n,r,i){if(e)for(let a=0,o=e.length;a<o;a++)e[a]&&e[a](t,n,r,i)}static _addHandler(e,t){if(!t)return-1;for(let n=0,r=e.length;n<r;n++)if(e[n]===null)return e[n]=t,n;return e.push(t),e.length-1}static _removeHandler(e,t){return t>=0&&t<e.length&&e[t]?(e[t]=null,!0):!1}};We._counter=0;var Ge=class extends We{constructor(e,t,n={},r){super(e,t,n,r),this._hoverID=-1,n.hover===void 0&&(this._states.hover=!1),n.clicks===void 0&&(this._states.clicks=0);let i=q;this._sysOn(i.up,()=>{this.state(`clicks`,this._states.clicks+1)}),this._sysOn(i.move,(e,t,n,r)=>{if(this._within(t)&&!this._states.hover){this.state(`hover`,!0),We._trigger(this._actions[i.enter],this,t,i.enter,r);let e=this.hold(i.move);this._hoverID=this._sysOn(i.move,(t,n,r,a)=>{!this._within(n)&&!this.state(`dragging`)&&(this.state(`hover`,!1),We._trigger(this._actions[i.leave],this,n,i.leave,a),this._sysOff(i.move,this._hoverID),this.unhold(e))})}})}onClick(e){return this.on(q.up,e)}offClick(e){return this.off(q.up,e)}onContextMenu(e){return this.on(q.contextmenu,e)}offContextMenu(e){return this.off(q.contextmenu,e)}onHover(e,t){let n=[void 0,void 0];return e&&(n[0]=this.on(q.enter,e)),t&&(n[1]=this.on(q.leave,t)),n}offHover(e,t){let n=[!1,!1];return(e===void 0||e>=0)&&(n[0]=this.off(q.enter,e)),(t===void 0||t>=0)&&(n[1]=this.off(q.leave,t)),n}},Ke=class extends Ge{constructor(e,t,n={},r){super(e,t,n,r),this._draggingID=-1,this._dragID=-1,this._moveHoldID=-1,this._dragHoldID=-1,this._dropHoldID=-1,this._upHoldID=-1,this._outHoldID=-1,n.dragging===void 0&&(this._states.dragging=!1),n.moved===void 0&&(this._states.moved=!1),n.offset===void 0&&(this._states.offset=new U);let i=q;this._sysOn(i.down,(e,t,n,r)=>{if(this._moveHoldID===-1&&(this.state(`dragging`,!0),this.state(`offset`,new U(t).subtract(e.group[0])),this._moveHoldID=this.hold(i.move),this._dragHoldID=this.hold(i.drag),this._outHoldID=this.hold(i.out)),this._dropHoldID===-1&&(this._dropHoldID=this.hold(i.drop)),this._upHoldID===-1&&(this._upHoldID=this.hold(i.up)),this._draggingID===-1){let e=(e,t,n,r)=>{let a=n===i.drag&&r===this._lastMoveEvent;this._lastMoveEvent=n===i.move?r:void 0,!a&&this.state(`dragging`)&&(We._trigger(this._actions[i.uidrag],e,t,i.uidrag,r),this.state(`moved`,!0))};this._draggingID=this._sysOn(i.move,e),this._dragID=this._sysOn(i.drag,e)}});let a=(e,t,n,r)=>{this.state(`dragging`,!1),this._sysOff(i.move,this._draggingID),this._sysOff(i.drag,this._dragID),this._draggingID=-1,this._dragID=-1,this._lastMoveEvent=void 0,this.unhold(this._moveHoldID),this._moveHoldID=-1,this.unhold(this._dragHoldID),this._dragHoldID=-1,this.unhold(this._outHoldID),this._outHoldID=-1,this.unhold(this._dropHoldID),this._dropHoldID=-1,this.unhold(this._upHoldID),this._upHoldID=-1,this.state(`moved`)&&(We._trigger(this._actions[i.uidrop],e,t,i.uidrop,r),this.state(`moved`,!1))};this._sysOn(i.drop,a),this._sysOn(i.up,a),this._sysOn(i.out,a)}onDrag(e){return this.on(q.uidrag,e)}offDrag(e){return this.off(q.uidrag,e)}onDrop(e){return this.on(q.uidrop,e)}offDrop(e){return this.off(q.uidrop,e)}},qe=t({MultiTouchSpace:()=>Ye,Space:()=>Je}),Je=class{constructor(){this.id=`space`,this.bound=new G,this._time={prev:0,diff:0,end:-1,min:0},this._stopAfter=-1,this.players={},this.playerCount=0,this._animID=-1,this._fromFrame=!1,this._pause=!1,this._refresh=void 0,this._pointer=new U,this._isReady=!1,this._playing=!1,this._firstFrame=!0}refresh(e){return this._refresh=e,this}minFrameTime(e=0){return this._time.min=e,this}add(e){let t=typeof e==`function`?{animate:e}:e,n=this.playerCount++,r=t.animateID||this.id+n;return this.players[r]=t,t.animateID=r,t.resize&&this.bound.inited&&t.resize(this.bound),this._refresh===void 0&&(this._refresh=!0),this}remove(e){return delete this.players[e.animateID],this}removeAll(){return this.players={},this}play(e=0){let t=this._fromFrame;if(this._fromFrame=!1,e===0&&this._animID!==-1&&!t)return this;if(this._animID!==-1&&cancelAnimationFrame(this._animID),this._animID=requestAnimationFrame(e=>{this._fromFrame=!0;try{this.play(e)}finally{this._fromFrame=!1}}),this._pause)return this._time.prev=e,this;if(this._firstFrame)this._firstFrame=e===0&&!t,this._time.diff=0,this._time.prev=e;else{let t=e-this._time.prev;if(t<this._time.min)return this;this._time.diff=t,this._time.prev=e}try{this.playItems(e)}catch(e){throw cancelAnimationFrame(this._animID),this._animID=-1,this._playing=!1,this._firstFrame=!0,e}return this}replay(){this._time.end=-1,this.play()}playItems(e){if(this._playing=!0,this._refresh&&this.clear(),this._isReady)for(let t in this.players)this.players[t].animate&&this.players[t].animate(e,this._time.diff,this);this._stopAfter>=0&&(this._time.end=e+this._stopAfter,this._stopAfter=-1),this._time.end>=0&&e>this._time.end&&(cancelAnimationFrame(this._animID),this._animID=-1,this._playing=!1,this._firstFrame=!0)}pause(e=!1){return this._pause=!e||!this._pause,this}resume(){return this._pause=!1,this}stop(e=0){return this._stopAfter=e>0?e:-1,this._time.end=e>0?-1:e,this}_cancelAnimation(){return this._animID!==-1&&cancelAnimationFrame(this._animID),this._animID=-1,this._playing=!1,this._firstFrame=!0,this}playOnce(e=0){return this.play(),this.stop(e),this}render(e){return this._renderFunc&&this._renderFunc(e,this),this}set customRendering(e){this._renderFunc=e}get customRendering(){return this._renderFunc}get isPlaying(){return this._playing}get outerBound(){return this.bound.clone()}get innerBound(){return new G(U.make(this.size.length,0),this.size.clone())}get size(){return this.bound.size.clone()}get center(){return this.size.divide(2)}get width(){return this.bound.width}get height(){return this.bound.height}},Ye=class extends Je{constructor(...e){super(...e),this._pressed=!1,this._dragged=!1,this._hasMouse=!1,this._hasTouch=!1,this._hasKeyboard=!1,this._touchPassive=!1,this._mouseDownBind=this._mouseDown.bind(this),this._mouseUpBind=this._mouseUp.bind(this),this._mouseOverBind=this._mouseOver.bind(this),this._mouseOutBind=this._mouseOut.bind(this),this._mouseMoveBind=this._mouseMove.bind(this),this._mouseClickBind=this._mouseClick.bind(this),this._contextMenuBind=this._contextMenu.bind(this),this._touchStartBind=this._touchStart.bind(this),this._touchMoveBind=this._touchMove.bind(this),this._keyDownBind=this._keyDown.bind(this),this._keyUpBind=this._keyUp.bind(this),this._trackedUIs=[],this._uiPlayer=null}get pointer(){let e=this._pointer.clone();return e.id=this._pointer.id,e}bindCanvas(e,t,n={},r){(r||this._canvas).addEventListener(e,t,n)}unbindCanvas(e,t,n={},r){(r||this._canvas).removeEventListener(e,t,n)}bindDoc(e,t,n={}){typeof document<`u`&&document.addEventListener(e,t,n)}unbindDoc(e,t,n={}){typeof document<`u`&&document.removeEventListener(e,t,n)}bindMouse(e=!0,t){if(e){if(this._hasMouse){if(this._mouseTarget===t)return this;this.bindMouse(!1)}this._mouseTarget=t,this.bindCanvas(`pointerdown`,this._mouseDownBind,{},t),this.bindCanvas(`pointerup`,this._mouseUpBind,{},t),this.bindCanvas(`pointerover`,this._mouseOverBind,{},t),this.bindCanvas(`pointerout`,this._mouseOutBind,{},t),this.bindCanvas(`pointercancel`,this._mouseOutBind,{},t),this.bindCanvas(`pointermove`,this._mouseMoveBind,{},t),this.bindCanvas(`click`,this._mouseClickBind,{},t),this.bindCanvas(`contextmenu`,this._contextMenuBind,{},t),this._hasMouse=!0}else if(this._hasMouse){let e=this._mouseTarget;this.unbindCanvas(`pointerdown`,this._mouseDownBind,{},e),this.unbindCanvas(`pointerup`,this._mouseUpBind,{},e),this.unbindCanvas(`pointerover`,this._mouseOverBind,{},e),this.unbindCanvas(`pointerout`,this._mouseOutBind,{},e),this.unbindCanvas(`pointercancel`,this._mouseOutBind,{},e),this.unbindCanvas(`pointermove`,this._mouseMoveBind,{},e),this.unbindCanvas(`click`,this._mouseClickBind,{},e),this.unbindCanvas(`contextmenu`,this._contextMenuBind,{},e),this._hasMouse=!1,this._mouseTarget=void 0}return this}bindTouch(e=!0,t=!1,n){if(e){if(this._hasTouch){if(this._touchTarget===n&&this._touchPassive===t)return this;this.bindTouch(!1)}this._touchTarget=n,this._touchPassive=t,this.bindCanvas(`touchstart`,this._touchStartBind,{passive:t},n),this.bindCanvas(`touchend`,this._mouseUpBind,{},n),this.bindCanvas(`touchmove`,this._touchMoveBind,{passive:t},n),this.bindCanvas(`touchcancel`,this._mouseOutBind,{},n),this._hasTouch=!0}else if(this._hasTouch){let e=this._touchTarget,t={passive:this._touchPassive};this.unbindCanvas(`touchstart`,this._touchStartBind,t,e),this.unbindCanvas(`touchend`,this._mouseUpBind,{},e),this.unbindCanvas(`touchmove`,this._touchMoveBind,t,e),this.unbindCanvas(`touchcancel`,this._mouseOutBind,{},e),this._hasTouch=!1,this._touchTarget=void 0}return this}bindKeyboard(e=!0,t){if(e){let e=t||document;if(this._hasKeyboard){if(this._keyboardTarget===e)return this;this.bindKeyboard(!1)}e.addEventListener(`keydown`,this._keyDownBind,{}),e.addEventListener(`keyup`,this._keyUpBind,{}),this._keyboardTarget=e,this._hasKeyboard=!0}else this._hasKeyboard&&(this._keyboardTarget.removeEventListener(`keydown`,this._keyDownBind,{}),this._keyboardTarget.removeEventListener(`keyup`,this._keyUpBind,{}),this._keyboardTarget=void 0,this._hasKeyboard=!1);return this}_unbindAll(){return this.bindMouse(!1),this.bindTouch(!1),this.bindKeyboard(!1),this}removeAll(){return this.untrack(),this._uiPlayer=null,super.removeAll()}track(e){let t=Array.isArray(e)?e:[e];for(let e=0,n=t.length;e<n;e++)this._trackedUIs.indexOf(t[e])<0&&this._trackedUIs.push(t[e]);return this._uiPlayer||(this._uiPlayer={animate:()=>{},action:(e,t,n,r)=>{We.track(this._trackedUIs,e,new U(t,n),r)}},this.add(this._uiPlayer)),this}untrack(e){let t=e===void 0?this._trackedUIs.slice():Array.isArray(e)?e:[e];for(let e=0,n=t.length;e<n;e++){let n=this._trackedUIs.indexOf(t[e]);n<0||(this._trackedUIs.splice(n,1),t[e].state(`dragging`)&&t[e].listen(q.drop,this._pointer,new Event(`pointercancel`)))}return this}_inputTransform(){if(typeof Element<`u`&&this._canvas instanceof Element){let e=this._canvas.getBoundingClientRect();return[e.left,e.top,e.width?this.width/e.width:1,e.height?this.height/e.height:1]}return[this.bound.topLeft.x-(typeof window>`u`?0:window.scrollX),this.bound.topLeft.y-(typeof window>`u`?0:window.scrollY),1,1]}touchesToPoints(e,t=`touches`){if(!e||!e[t])return[];let n=[],[r,i,a,o]=this._inputTransform();for(let s=0;s<e[t].length;s++){let c=e[t].item(s);n.push(new U((c.clientX-r)*a,(c.clientY-i)*o))}return n}_mouseAction(e,t){if(!this.isPlaying)return;let[n,r,i,a]=this._inputTransform(),o=0,s=0;if(t instanceof MouseEvent)o=(t.clientX-n)*i,s=(t.clientY-r)*a;else{let e=t.changedTouches&&t.changedTouches.length>0?t.changedTouches.item(0):null;e&&(o=(e.clientX-n)*i,s=(e.clientY-r)*a)}e&&(this._pointer.to(o,s),this._pointer.id=e);for(let n in this.players)if(this.players.hasOwnProperty(n)){let r=this.players[n];r.action&&r.action(e,o,s,t)}}_isTouchHandled(e){return`pointerType`in e&&e.pointerType===`touch`&&this._hasTouch&&e.composedPath().includes(this._touchTarget||this._canvas)}_mouseDown(e){if(this._isTouchHandled(e))return!1;if(this._mouseAction(q.down,e),this._mouseAction(q.pointerdown,e),this._pressed=!0,e.target instanceof Element)try{e.target.setPointerCapture(e.pointerId)}catch(e){}return!1}_mouseUp(e){return!this._isTouchHandled(e)&&(this._mouseAction(q.pointerup,e),this._dragged?this._mouseAction(q.drop,e):this._mouseAction(q.up,e),this._pressed=!1,this._dragged=!1,e instanceof PointerEvent&&e.target instanceof Element&&e.target.hasPointerCapture(e.pointerId)&&e.target.releasePointerCapture(e.pointerId),!1)}_mouseMove(e){return this._isTouchHandled(e)||(this._pressed?(this._dragged=!0,this._mouseAction(q.drag,e)):this._mouseAction(q.move,e)),!1}_mouseOver(e){return this._isTouchHandled(e)||this._mouseAction(q.over,e),!1}_mouseOut(e){return!this._isTouchHandled(e)&&(this._mouseAction(q.out,e),this._dragged&&this._mouseAction(q.drop,e),this._pressed=!1,this._dragged=!1,!1)}_mouseClick(e){return this._mouseAction(q.click,e),this._pressed=!1,this._dragged=!1,!1}_contextMenu(e){return this._mouseAction(q.contextmenu,e),!1}_touchMove(e){return this._mouseAction(q.move,e),this._pressed&&(this._dragged=!0,this._mouseAction(q.drag,e)),this._touchPassive||e.preventDefault(),!1}_touchStart(e){return this._mouseAction(q.down,e),this._pressed=!0,this._touchPassive||e.preventDefault(),!1}_keyDown(e){return this._keyboardAction(q.keydown,e),!1}_keyUp(e){return this._keyboardAction(q.keyup,e),!1}_keyboardAction(e,t){if(this.isPlaying){for(let n in this.players)if(this.players.hasOwnProperty(n)){let r=this.players[n];r.action&&r.action(e,+!!t.shiftKey,+!!t.altKey,t)}}}},Xe=t({Font:()=>$e,Form:()=>Ze,VisualForm:()=>Qe}),Ze=class{constructor(){this._ready=!1}get ready(){return this._ready}},Qe=class extends Ze{constructor(...e){super(...e),this._filled=!0,this._stroked=!0,this._font=new $e(14,`sans-serif`)}get filled(){return this._filled}set filled(e){this._filled=e}get stroked(){return this._stroked}set stroked(e){this._stroked=e}get currentFont(){return this._font}_multiple(e,t,...n){if(!e)return this;for(let r=0,i=e.length;r<i;r++)this[t](e[r],...n);return this}alpha(e){return this}fill(e){return this}fillOnly(e){return this.stroke(!1),this.fill(e)}stroke(e,t,n,r){return this}strokeOnly(e,t,n,r){return this.fill(!1),this.stroke(e,t,n,r)}points(e,t,n){if(!e)return this;for(let r=0,i=e.length;r<i;r++)this.point(e[r],t,n);return this}circles(e){return this._multiple(e,`circle`)}squares(e){return this._multiple(e,`square`)}lines(e){return this._multiple(e,`line`)}polygons(e){return this._multiple(e,`polygon`)}rects(e){return this._multiple(e,`rect`)}},$e=class{constructor(e=12,t=`sans-serif`,n=``,r=``,i=1.5){this.size=e,this.face=t,this.style=r,this.weight=n,this.lineHeight=i}get value(){let e=[this.style,this.weight].filter(Boolean).join(` `),t=`${this.size}px/${this.lineHeight} ${this.face}`;return e?`${e} ${t}`:t}toString(){return this.value}},et=t({Typography:()=>tt}),tt=class{static textWidthEstimator(e,t=[`M`,`n`,`.`],n=[.06,.8,.14]){if(t.length!==n.length)throw Error(`textWidthEstimator: samples (${t.length}) and distribution (${n.length}) must have the same length`);let r=t.map(e),i=new U(n).dot(r);return e=>e.length*i}static charWidthCache(e){let t=new Float64Array(256).fill(NaN),n=new Map;return r=>{let i=0;for(let a=0,o=r.length;a<o;a++){let s=r.charCodeAt(a);if(s<256){let n=t[s];n!==n&&(n=e(r[a]),t[s]=n),i+=n}else{let t=r[a];s>=55296&&s<=56319&&a+1<o&&(t+=r[a+1],a++);let c=n.get(t);c===void 0&&(c=e(t),n.set(t,c)),i+=c}}return i}}static truncate(e,t,n,r=``,i){let a=t.length,o,s,c;if(i!==void 0&&!r)o=n,s=a,c=Math.min(s,Math.max(0,Math.floor(i)));else{let l=e(t);if(l<=n)return[t,a];o=n-(r?e(r):0),s=a-1,c=i===void 0?Math.min(s,Math.max(0,Math.floor(a*o/l))):Math.min(s,Math.max(0,Math.floor(i)))}let l=n=>e(t.slice(0,n))<=o,u=-1,d=0,f=s;if(o>=0){let e=c;if(l(e)){u=e,d=e+1;for(let t=1;d<=f;t*=2){let n=Math.min(f,e+t);if(!l(n)){f=n-1;break}u=n,d=n+1}}else{f=e-1;for(let t=1;d<=f;t*=2){let n=Math.max(d,e-t);if(l(n)){u=n,d=n+1;break}f=n-1}}for(;d<=f;){let e=d+f>>1;l(e)?(u=e,d=e+1):f=e-1}}if(u<0)return[``,0];if(u===a)return[t,a];let p=u;if(p>0){let e=t.charCodeAt(p-1);e>=55296&&e<=56319&&p--}return[t.slice(0,p)+r,p]}static fontSizeToBox(e=1,t=!0,n){typeof e!=`number`&&(H.warn(`Typography.fontSizeToBox(box, ratio, byHeight) is deprecated: the initial box never affected the result. Use fontSizeToBox(ratio, byHeight) instead.`),e=typeof t==`number`?t:1,t=n===void 0||n);let r=e,i=t;return e=>{let t=G.fromGroup(e);return r*(i?t.height:t.width)}}static fontSizeToThreshold(e,t=0){if(e===0)throw Error(`fontSizeToThreshold: threshold cannot be 0`);return function(n,r){let i=n*r/e;return t<0?Math.min(i,n):t>0?Math.max(i,n):i}}};function nt(e,t,n,r,i,a,o){try{var s=e[a](o),c=s.value}catch(e){n(e);return}s.done?t(c):Promise.resolve(c).then(r,i)}function rt(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){nt(a,r,i,o,s,`next`,e)}function s(e){nt(a,r,i,o,s,`throw`,e)}o(void 0)})}}var it=t({Img:()=>at}),at=class e{constructor(e=!1,t,n){var r;this._scale=1,this._loaded=!1,this._pendingLoadReject=null,this._disposed=!1,this._dataDirty=!1;let i=typeof e==`object`?e:{editable:e,space:t,crossOrigin:n};this._editable=!!i.editable,this._space=i.space,this._scale=(r=i.pixelScale)==null?this._space?this._space.pixelScale:1:r,this._img=new Image,i.crossOrigin&&(this._img.crossOrigin=`Anonymous`)}static load(t,n=!1,r,i){return new e(n,r).load(t).then(e=>(i&&i(e),e))}static loadAsync(t,n=!1,r){return rt(function*(){return e.load(t,n,r)})()}static loadPattern(t,n,r=`repeat`,i=!1){return rt(function*(){return(yield e.loadAsync(t,i,n)).pattern(r)})()}static blank(t,n,r){let i=new e(!0,n),a=r||(n?n.pixelScale:1);return i.initCanvas(t[0],t[1],a),i}load(e){return this._editable&&typeof document>`u`?Promise.reject(Error(`Cannot create html canvas element. document not found.`)):this._loadImageSrc(e).then(()=>{if(this._disposed)throw Error(`Img has been disposed`);return this._editable&&(this._cv||(this._cv=document.createElement(`canvas`)),this._drawToScale(this._scale,this._img),this._dataDirty=!0),this._loaded=!0,this})}_loadImageSrc(e){return this._disposed?Promise.reject(Error(`Img has been disposed`)):new Promise((t,n)=>{this._pendingLoadReject&&this._pendingLoadReject(Error(`Img loading superseded by a newer load`)),this._pendingLoadReject=n,this._img.onload=()=>{this._pendingLoadReject=null,t()},this._img.onerror=()=>{this._pendingLoadReject=null,n(Error(`Img cannot load ${e}`))},this._img.src=e})}_refreshData(){this._data=this._ctx.getImageData(0,0,this._cv.width,this._cv.height),this._dataDirty=!1}_ensureData(){(this._dataDirty||!this._data)&&this._ctx&&this._cv&&this._refreshData()}_drawToScale(e,t){let n=t.width,r=t.height;this._initCanvas(n,r,e),t&&this._ctx.drawImage(t,0,0,n,r,0,0,this._cv.width,this._cv.height)}initCanvas(e,t,n=1){this._initCanvas(e,t,n)}_initCanvas(e,t,n=1){if(!this._editable){H.warn(`Cannot initiate canvas because this Img is not set to be editable`);return}this._cv||(this._cv=document.createElement(`canvas`));let r=typeof n==`number`?[n,n]:n;this._cv.width=e*r[0],this._cv.height=t*r[1],this._ctx=this._cv.getContext(`2d`,{willReadFrequently:!0}),J.resetStyleCache(this._ctx),typeof n==`number`&&(this._scale=n),this._dataDirty=!0,this._loaded=!0}bitmap(e){let t=e?e[0]:this._cv.width,n=e?e[1]:this._cv.height;return createImageBitmap(this._cv,0,0,t,n)}pattern(e=`repeat`,t=!1){let n=this._space?this._space.ctx:void 0;return n||(this._patternCtx||(this._patternCtx=document.createElement(`canvas`).getContext(`2d`)),n=this._patternCtx),n.createPattern(t?this._cv:this._img,e)}sync(){var e=this;return rt(function*(){if(e._disposed)throw Error(`Img has been disposed`);let t=e._cv;e._scale!==1&&(t=document.createElement(`canvas`),t.width=e._cv.width/e._scale,t.height=e._cv.height/e._scale,t.getContext(`2d`).drawImage(e._cv,0,0,e._cv.width,e._cv.height,0,0,t.width,t.height));let n=yield new Promise((e,n)=>{t.toBlob(t=>t?e(t):n(Error(`Img cannot export canvas to blob`)))}),r=URL.createObjectURL(n);e._objectUrl=r;try{if(yield e._loadImageSrc(r),e._disposed)throw Error(`Img has been disposed`);e._loaded=!0}finally{URL.revokeObjectURL(r),e._objectUrl=null}return e})()}pixel(t,n=!0){if(this._ensureData(),!this._data)return H.warn(`Img has no pixel data — create it as editable and wait for load`),new U(0,0,0,0);let r=typeof n==`number`?n:n?this._scale:1;return e.getPixel(this._data,[t[0]*r,t[1]*r])}setPixel(e,t,n=!0){if(this._ensureData(),!this._data)return H.warn(`Img has no pixel data — create it as editable`),this;let r=typeof n==`number`?n:n?this._scale:1,i=Math.floor(e[0]*r),a=Math.floor(e[1]*r);if(i<0||a<0||i>=this._data.width||a>=this._data.height)return this;let o=a*this._data.width*4+i*4;return this._data.data[o]=t[0],this._data.data[o+1]=t[1],this._data.data[o+2]=t[2],this._data.data[o+3]=t[3]===void 0?255:t[3],this}loadPixels(){return this._ctx?(this._refreshData(),this):(H.warn(`Img has no canvas — create it as editable`),this)}updatePixels(){return!this._ctx||!this._data?(H.warn(`Img has no canvas — create it as editable`),this):(this._ctx.putImageData(this._data,0,0),this._dataDirty=!1,this)}static getPixel(e,t){let n=new U(4);if(t[0]<0||t[1]<0||t[0]>=e.width||t[1]>=e.height)return n;let r=Math.floor(t[1])*(e.width*4)+Math.floor(t[0])*4,i=e.data;return r>i.length-4?n:(n[0]=i[r],n[1]=i[r+1],n[2]=i[r+2],n[3]=i[r+3],n)}resize(e,t=!1){let n=this._img.naturalWidth>0,r=n?this._img.naturalWidth:this._cv.width,i=n?this._img.naturalHeight:this._cv.height;if(!r||!i)return H.warn(`Img cannot resize before an image or canvas exists`),this;let a=t?e:[e[0]/r,e[1]/i],o=this._img;if(!n){let e=document.createElement(`canvas`);e.width=this._cv.width,e.height=this._cv.height,e.getContext(`2d`).drawImage(this._cv,0,0),o=e}return this._drawToScale(a,o),this._dataDirty=!0,this}crop(e){let t=this._scale;return this._ctx.getImageData(e[0][0]*t,e[0][1]*t,e.width*t,e.height*t)}filter(e){let t=this._ctx.globalCompositeOperation;return this._ctx.globalCompositeOperation=`copy`,this._ctx.filter=e,this._ctx.drawImage(this._cv,0,0),this._ctx.filter=`none`,this._ctx.globalCompositeOperation=t,this._dataDirty=!0,this}dispose(){var e;return this._disposed=!0,(e=this._pendingLoadReject)==null||e.call(this,Error(`Img has been disposed`)),this._pendingLoadReject=null,this._img&&(this._img.onload=null,this._img.onerror=null,this._img.removeAttribute(`src`)),this._objectUrl&&(URL.revokeObjectURL(this._objectUrl),this._objectUrl=null),this._cv&&this._cv.remove(),this._img&&this._img.remove(),this._cv=null,this._ctx=null,this._patternCtx=null,this._img=null,this._data=null,this._loaded=!1,this}cleanup(){this.dispose()}static fromBlob(t,n=!1,r){let i=URL.createObjectURL(t),a=new e(n,r);a._objectUrl=i;let o=()=>{URL.revokeObjectURL(i),a._objectUrl=null};return a.load(i).then(e=>(o(),e),e=>{throw o(),e})}static imageDataToBlob(e){return new Promise(function(t,n){if(typeof document>`u`){n(Error(`Cannot create html canvas element. document not found.`));return}let r=document.createElement(`canvas`);r.width=e.width,r.height=e.height,r.getContext(`2d`).putImageData(e,0,0),r.toBlob(e=>{t(e),r.remove()})})}toBase64(){return this._cv.toDataURL()}toBlob(){return new Promise(e=>{this._cv.toBlob(t=>e(t))})}getForm(){return this._editable||H.warn(`Cannot get a CanvasForm because this Img is not editable`),this._ctx?new J(this._ctx):void 0}get current(){return this._editable?this._cv:this._img}get image(){return this._img}get canvas(){return this._cv}get data(){return this._ensureData(),this._data}get ctx(){return this._ctx}get loaded(){return this._loaded}get pixelScale(){return this._scale}get imageSize(){return!this._img||!this._img.width||!this._img.height?this._cv?this.canvasSize.$divide(this._scale):new U(0,0):new U(this._img.width,this._img.height)}get canvasSize(){return new U(this._cv.width,this._cv.height)}get scaledMatrix(){let e=1/this._scale;return new R().scale2D([e,e])}},ot=t({CanvasForm:()=>J,CanvasSpace:()=>st}),st=class extends Ye{constructor(e=`pt`,t){super(),this._pixelScale=1,this._bgcolor=`#e1e9f0`,this._offscreen=!1,this._autoResize=!0,this._initialResize=!1,this._disposed=!1,this._ownsCanvas=!1,this._ownsContainer=!1;let n=null,r=!1;if(this.id=H.uniqueId(),e instanceof Element)n=e,this.id=n.id||this.id;else{let t=e||`pt`,r=t[0]===`#`||t[0]===`.`?t:`#`+t;n=document.querySelector(r),this.id=r.substr(1)}n?n.nodeName.toLowerCase()==`canvas`?(this._canvas=n,this._container=n.parentElement,this._autoResize=!1,r=!0):(this._container=n,this._canvas=this._createElement(`canvas`,this.id+`_canvas`),this._initialResize=!0):(this._ownsContainer=!0,this._container=this._createElement(`div`,this.id+`_container`),this._canvas=this._createElement(`canvas`,this.id),document.body.appendChild(this._container)),this._ctx=this._canvas.getContext(`2d`),r?this._readyTimer=window.setTimeout(()=>this._ready(t),100):(this._ownsCanvas=!0,this._readyObserver=new MutationObserver(e=>{e.forEach(e=>{if(e.type===`childList`&&e.addedNodes.length){for(let r of e.addedNodes)if(r===this._canvas){var n;this._ready(t),(n=this._readyObserver)==null||n.disconnect(),this._readyObserver=void 0;return}}})}),this._readyObserver.observe(this._container,{childList:!0}),this._container.appendChild(this._canvas))}_createElement(e=`div`,t){let n=document.createElement(e);return n.setAttribute(`id`,t),n}_ready(e){if(!this._disposed){if(this._readyTimer=void 0,!this._container)throw Error(`Cannot initiate #${this.id} element`);this._isReady=!0,this._resizeHandler(null),this.clear(this._bgcolor),this._canvas.dispatchEvent(new Event(`ready`));for(let e in this.players)this.players.hasOwnProperty(e)&&this.players[e].start&&this.players[e].start(this.bound.clone(),this);this._pointer=this.center,this._initialResize=!1,e&&e(this.bound,this._canvas)}}setup(e){if(this._bgcolor=e.bgcolor?e.bgcolor:`transparent`,this.autoResize=e.resize!=null&&e.resize,e.retina!==!1){let e=window&&window.devicePixelRatio||1;this._pixelScale=Math.max(1,e)}return e.offscreen?(this._offscreen=!0,this._offCanvas=this._createElement(`canvas`,this.id+`_offscreen`),this._offCtx=this._offCanvas.getContext(`2d`)):this._offscreen=!1,e.pixelDensity&&(this._pixelScale=e.pixelDensity),this}set autoResize(e){this._autoResize===e&&(!e||this._resizeObserver)||(this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=void 0),this._autoResize=e,e&&(this._resizeObserver=new ResizeObserver(e=>{this._resizeHandler(null)}),this._resizeObserver.observe(this._container)))}get autoResize(){return this._autoResize}resize(e,t){this.bound=e,this._canvas.width=Math.ceil(this.bound.size.x)*this._pixelScale,this._canvas.height=Math.ceil(this.bound.size.y)*this._pixelScale,this._canvas.style.width=this.bound.size.x+`px`,this._canvas.style.height=this.bound.size.y+`px`,this._offscreen&&(this._offCanvas.width=Math.ceil(this.bound.size.x)*this._pixelScale,this._offCanvas.height=Math.ceil(this.bound.size.y)*this._pixelScale),this._pixelScale!=1&&(this._ctx.scale(this._pixelScale,this._pixelScale),this._offscreen&&this._offCtx.scale(this._pixelScale,this._pixelScale)),J.resetStyleCache(this._ctx),this._offscreen&&J.resetStyleCache(this._offCtx);for(let e in this.players)if(this.players.hasOwnProperty(e)){let n=this.players[e];n.resize&&n.resize(this.bound,t)}return this.render(this._ctx),t&&!this.isPlaying&&this.playOnce(0),this}_resizeHandler(e){let t=this._autoResize||this._initialResize?this._container.getBoundingClientRect():this._canvas.getBoundingClientRect();if(t){var n,r;let i=G.fromBoundingRect(t);i.center=i.center.add(((n=window)==null?void 0:n.scrollX)||0,((r=window)==null?void 0:r.scrollY)||0),this.resize(i,e)}}set background(e){this._bgcolor=e}get background(){return this._bgcolor}get pixelScale(){return this._pixelScale}get hasOffscreen(){return this._offscreen}get offscreenCtx(){return this._offCtx}get offscreenCanvas(){return this._offCanvas}getForm(){return new J(this)}get element(){return this._canvas}get parent(){return this._container}get ready(){return this._isReady}get ctx(){return this._ctx}clear(e){e&&(this._bgcolor=e);let t=this._ctx.fillStyle,n=Math.ceil(this.pixelScale);return!this._bgcolor||this._bgcolor===`transparent`?this._ctx.clearRect(-n,-n,this._canvas.width+n,this._canvas.height+n):((this._bgcolor.indexOf(`rgba`)===0||this._bgcolor.length===9&&this._bgcolor.indexOf(`#`)===0)&&this._ctx.clearRect(-n,-n,this._canvas.width+n,this._canvas.height+n),this._ctx.fillStyle=this._bgcolor,this._ctx.fillRect(-n,-n,this._canvas.width+n,this._canvas.height+n)),this._ctx.fillStyle=t,this}clearOffscreen(e){if(this._offscreen){let t=Math.ceil(this.pixelScale);e?(this._offCtx.fillStyle=e,this._offCtx.fillRect(-t,-t,this._canvas.width+t,this._canvas.height+t)):this._offCtx.clearRect(-t,-t,this._offCanvas.width+t,this._offCanvas.height+t)}return this}playItems(e){this._isReady&&(this._ctx.save(),this._offscreen&&this._offCtx.save(),super.playItems(e),this._ctx.restore(),this._offscreen&&this._offCtx.restore(),J.resetStyleCache(this._ctx),this._offscreen&&J.resetStyleCache(this._offCtx),this.render(this._ctx))}dispose(){return this._disposed?this:(this._disposed=!0,this._readyTimer!==void 0&&(window.clearTimeout(this._readyTimer),this._readyTimer=void 0),this._readyObserver&&(this._readyObserver.disconnect(),this._readyObserver=void 0),this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=void 0),this._unbindAll(),this._cancelAnimation(),this.removeAll(),this._isReady=!1,this._ownsCanvas&&this._canvas.remove(),this._ownsContainer&&this._container.childNodes.length===0&&this._container.remove(),this)}recorder(e,t=`webm`,n=15e6){let r=this._canvas.captureStream(),i=new MediaRecorder(r,{mimeType:`video/${t}`,bitsPerSecond:n});return i.ondataavailable=function(n){let r=URL.createObjectURL(new Blob([n.data],{type:`video/${t}`}));if(typeof e==`function`)e(r);else if(e){let e=document.createElement(`a`);e.href=r,e.download=`canvas_video.${t}`,e.click(),e.remove(),setTimeout(()=>URL.revokeObjectURL(r),100)}},i}};let ct=new WeakMap;var J=class e extends Qe{_cacheForCtx(){if(this._styleCacheCtx!==this._ctx){let e=ct.get(this._ctx);e||(e={},ct.set(this._ctx,e)),this._styleCache=e,this._styleCacheCtx=this._ctx}return this._styleCache}static resetStyleCache(e){let t=ct.get(e);if(t)for(let e in t)delete t[e]}_set(e,t){let n=this._cacheForCtx();n[e]!==t&&(n[e]=t,this._ctx[e]=t)}constructor(e){if(super(),this._styleCache=null,this._styleCacheCtx=null,this._style={fillStyle:`#f03`,strokeStyle:`#fff`,lineWidth:1,lineJoin:`bevel`,lineCap:`butt`,globalAlpha:1},!e)return this;let t=e=>{this._ctx=e,this._set(`fillStyle`,this._style.fillStyle),this._set(`strokeStyle`,this._style.strokeStyle),this._set(`lineJoin`,`bevel`),this._set(`font`,this._font.value),this._ready=!0};e instanceof st?(this._space=e,this._space.ready&&this._space.ctx?t(this._space.ctx):this._space.add({start:()=>{t(this._space.ctx)}})):t(e)}get space(){return this._space}get ctx(){return this._ctx}useOffscreen(e=!0,t=!1){return t&&this._space.clearOffscreen(typeof t==`string`?t:null),this._ctx=this._space.hasOffscreen&&e?this._space.offscreenCtx:this._space.ctx,this}renderOffscreen(e=[0,0]){this._space.hasOffscreen&&this._space.ctx.drawImage(this._space.offscreenCanvas,e[0],e[1],this._space.width,this._space.height)}alpha(e){return this._set(`globalAlpha`,e),this._style.globalAlpha=e,this}fill(e){return typeof e==`boolean`?this.filled=e:(this.filled=!0,this._style.fillStyle=e,this._set(`fillStyle`,e)),this}fillOnly(e){return this.stroke(!1),this.fill(e)}stroke(e,t,n,r){return typeof e==`boolean`?this.stroked=e:(this.stroked=!0,this._style.strokeStyle=e,this._set(`strokeStyle`,e),t&&(this._set(`lineWidth`,t),this._style.lineWidth=t),n&&(this._set(`lineJoin`,n),this._style.lineJoin=n),r&&(this._set(`lineCap`,r),this._style.lineCap=r)),this}strokeOnly(e,t,n,r){return this.fill(!1),this.stroke(e,t,n,r)}applyFillStroke(e=!0,t=!0,n=1){return e&&(typeof e==`string`&&this.fill(e),this._ctx.fill()),t&&(typeof t==`string`&&this.stroke(t,n),this._ctx.stroke()),this}gradient(e){let t=[];e.length<2&&(e=[...e,[.99,`#000`],[1,`#000`]]);for(let n=0,r=e.length;n<r;n++){let r=typeof e[n]==`string`?n*(1/(e.length-1)):e[n][0],i=typeof e[n]==`string`?e[n]:e[n][1];t.push([r,i])}return(e,n)=>{let r=n?this._ctx.createRadialGradient(e[0][0],e[0][1],Math.abs(e[1][0]),n[0][0],n[0][1],Math.abs(n[1][0])):this._ctx.createLinearGradient(e[0][0],e[0][1],e[1][0],e[1][1]);for(let e=0,n=t.length;e<n;e++)r.addColorStop(t[e][0],t[e][1]);return r}}composite(e=`source-over`){return this._set(`globalCompositeOperation`,e),this}clip(){return this._ctx.clip(),this}dash(e=!0,t=0){let n=this._cacheForCtx();if(e===!1||e!==!0&&e.length===0)n.dash!==`/0`&&(n.dash=`/0`,this._ctx.setLineDash([]),this._ctx.lineDashOffset=0);else{let r=e===!0?[5,5]:e,i=`${Array.prototype.join.call(r,`,`)}/${t}`;n.dash!==i&&(n.dash=i,this._ctx.setLineDash(r),this._ctx.lineDashOffset=t)}return this}font(e,t,n,r,i){return typeof e==`number`?(this._font.size=e,i&&(this._font.face=i),t&&(this._font.weight=t),n&&(this._font.style=n),r&&(this._font.lineHeight=r)):this._font=e,this._set(`font`,this._font.value),this._estimateMode&&this.fontWidthEstimate(this._estimateMode),this}fontWidthEstimate(e=!0){if(!e)this._estimateMode=void 0,this._estimateTextWidth=void 0;else{let t=e=>this._ctx.measureText(e).width;this._estimateMode=e===!0?`sample`:e,this._estimateTextWidth=this._estimateMode===`char`?tt.charWidthCache(t):tt.textWidthEstimator(t)}return this}getTextWidth(e){return this._estimateTextWidth?this._estimateTextWidth(e):this._ctx.measureText(e).width}_textTruncate(e,t,n=``,r){return tt.truncate(this.getTextWidth.bind(this),e,t,n,r)}_textAlign(e,t,n,r){let i=H.iterToArray(e);if(!H.arrayCheck(i))return;r||(r=P.center(i));let a=i[0][0];this._ctx.textAlign==`end`||this._ctx.textAlign==`right`?a=i[1][0]:(this._ctx.textAlign==`center`||this._ctx.textAlign==`middle`)&&(a=r[0]);let o=r[1];return t==`top`||t==`start`?o=i[0][1]:(t==`end`||t==`bottom`)&&(o=i[1][1]),n?new U(a+n[0],o+n[1]):new U(a,o)}reset(){let e=this._cacheForCtx();for(let t in this._style)this._style.hasOwnProperty(t)&&(this._ctx[t]=this._style[t],e[t]=this._style[t]);return this._font=new $e(14,`sans-serif`),this._ctx.font=this._font.value,e.font=this._font.value,this}_paint(){this._filled&&this._ctx.fill(),this._stroked&&this._ctx.stroke()}static point(t,n,r=5,i=`square`){if(n){if(!e[i])throw Error(`${i} is not a static function of CanvasForm`);e[i](t,n,r)}}point(t,n=5,r=`square`){return e.point(this._ctx,t,n,r),this._paint(),this}static circle(e,t,n=10){t&&(e.beginPath(),e.arc(t[0],t[1],n,0,V.two_pi,!1),e.closePath())}circle(t){let n=H.iterToArray(t);return e.circle(this._ctx,n[0],n[1][0]),this._paint(),this}static ellipse(e,t,n,r=0,i=0,a=V.two_pi,o=!1){!t||!n||(e.beginPath(),e.ellipse(t[0],t[1],n[0],n[1],r,i,a,o))}ellipse(t,n,r=0,i=0,a=V.two_pi,o=!1){return e.ellipse(this._ctx,t,n,r,i,a,o),this._paint(),this}static arc(e,t,n,r,i,a){t&&(e.beginPath(),e.arc(t[0],t[1],n,r,i,a))}arc(t,n,r,i,a){return e.arc(this._ctx,t,n,r,i,a),this._paint(),this}static square(e,t,n){if(!t)return;let r=t[0]-n,i=t[1]-n,a=t[0]+n,o=t[1]+n;e.beginPath(),e.moveTo(r,i),e.lineTo(r,o),e.lineTo(a,o),e.lineTo(a,i),e.closePath()}square(t,n){return e.square(this._ctx,t,n),this._paint(),this}static line(e,t){if(!H.arrayCheck(t))return;e.beginPath();let n=0;if(Array.isArray(t))for(let r=0,i=t.length;r<i;r++){let i=t[r];i&&(n++>0?e.lineTo(i[0],i[1]):e.moveTo(i[0],i[1]))}else for(let r of t)r&&(n++>0?e.lineTo(r[0],r[1]):e.moveTo(r[0],r[1]))}line(t){let n=H.iterToArray(t);return H.arrayCheck(n)&&(e.line(this._ctx,n),this._paint()),this}static bezier(e,t){let n=H.iterToArray(t);if(!(n.length<4)){e.beginPath(),e.moveTo(n[0][0],n[0][1]);for(let t=3;t<n.length;t+=3){let r=n[t-2],i=n[t-1];e.bezierCurveTo(r[0],r[1],i[0],i[1],n[t][0],n[t][1])}}}bezier(t){let n=H.iterToArray(t);return H.arrayCheck(n,4)&&(e.bezier(this._ctx,n),this._paint()),this}static polygon(t,n){H.arrayCheck(n)&&(e.line(t,n),t.closePath())}polygon(t){let n=H.iterToArray(t);return H.arrayCheck(n)&&(e.polygon(this._ctx,n),this._paint()),this}static compound(e,t){let n=!1;for(let r of t){let t=H.iterToArray(r);if(!(t.length<2)){if(typeof t[0][0]!=`number`){H.warn(`compound expects rings of points; draw each polygon of a divide or crop result separately`);return}n||(e.beginPath(),n=!0),e.moveTo(t[0][0],t[0][1]);for(let n=1,r=t.length;n<r;n++)e.lineTo(t[n][0],t[n][1]);e.closePath()}}}compound(t){let n=[],r=!1;for(let e of t){let t=H.iterToArray(e);if(t.length>0&&typeof t[0][0]!=`number`)return H.warn(`compound expects rings of points; draw each polygon of a divide or crop result separately`,this);t.length>=2&&(r=!0),n.push(t)}return r&&(e.compound(this._ctx,n),this._paint()),this}static rect(e,t){let n=H.iterToArray(t);H.arrayCheck(n)&&(e.beginPath(),e.moveTo(n[0][0],n[0][1]),e.lineTo(n[0][0],n[1][1]),e.lineTo(n[1][0],n[1][1]),e.lineTo(n[1][0],n[0][1]),e.closePath())}rect(t){return e.rect(this._ctx,t),this._paint(),this}static image(e,t,n,r){let i=H.iterToArray(t),a;if(typeof i[0]==`number`)a=i;else if(r){let e=H.iterToArray(r);a=[e[0][0],e[0][1],e[1][0]-e[0][0],e[1][1]-e[0][1],i[0][0],i[0][1],i[1][0]-i[0][0],i[1][1]-i[0][1]]}else a=[i[0][0],i[0][1],i[1][0]-i[0][0],i[1][1]-i[0][1]];n instanceof at?n.loaded&&e.drawImage(n.image,...a):e.drawImage(n,...a)}image(t,n,r){return n instanceof at?n.loaded&&e.image(this._ctx,t,n.image,r):e.image(this._ctx,t,n,r),this}static imageData(e,t,n){let r=H.iterToArray(t);typeof r[0]==`number`?e.putImageData(n,r[0],r[1]):e.putImageData(n,r[0][0],r[0][1],0,0,r[1][0]-r[0][0],r[1][1]-r[0][1])}imageData(t,n){return e.imageData(this._ctx,t,n),this}static text(e,t,n,r){t&&e.fillText(n,t[0],t[1],r)}text(t,n,r){return e.text(this._ctx,t,n,r),this}textBox(e,t,n=`middle`,r=``,i=!0){i&&(this._ctx.textBaseline=n===`center`?`middle`:n===`start`?`top`:n===`end`?`bottom`:n);let a=P.size(e),o=this._textTruncate(t,a[0],r);return this.text(this._textAlign(e,n),o[0]),this}paragraphBox(e,t,n=1.2,r=`top`,i=!0){let a=W.fromArray(e),o=P.size(a);this._ctx.textBaseline=`top`;let s=this._font.size*n,c=Math.ceil(o[0]/Math.max(1,this.getTextWidth(`n`))),l=[],u=t;for(;u;){var d;if(i&&(l.length+1)*s>o[1])break;let e=this._textTruncate(u,o[0],``,c);e[1]>0&&(c=e[1]);let t=e[0].indexOf(`
5
+ `);if(t>=0){l.push(e[0].slice(0,t)),u=u.slice(t+1);continue}let n=e[1]===u.length,r;if(n?r=void 0:u[e[1]]===` `?r=e[1]+1:(r=e[0].lastIndexOf(` `)+1,r<=0&&(r=void 0)),l.push(r===void 0?e[0]:e[0].slice(0,r)),e[1]<=0||n)break;u=u.slice((d=r)==null?e[1]:d)}let f=l.length*s,p=a;if(r==`middle`||r==`center`){let e=(o[1]-f)/2;i&&(e=Math.max(0,e)),p=new W(a[0].$add(0,e),a[1].$subtract(0,e))}else p=r==`bottom`?new W(a[0].$add(0,o[1]-f),a[1]):new W(a[0],a[0].$add(o[0],f));let m=P.center(p);for(let e=0,t=l.length;e<t;e++)this.text(this._textAlign(p,`top`,[0,e*s],m),l[e]);return this}alignText(e=`left`,t=`alphabetic`){return t==`center`&&(t=`middle`),t==`baseline`&&(t=`alphabetic`),this._ctx.textAlign=e,this._ctx.textBaseline=t,this}log(e){let t=this._ctx.measureText(e).width+20;return this.stroke(!1).fill(`rgba(0,0,0,.4)`).rect([[0,0],[t,20]]),this.fill(`#fff`).text([10,14],e),this}},lt=t({Boid:()=>Tt,Create:()=>ut,Delaunay:()=>xt,Flock:()=>Et,Noise:()=>_t,PoissonDisk:()=>Ot}),ut=class{static distributeRandom(e,t,n=2){let r=new W;for(let i=0;i<t;i++){let t=[e.x+z.random()*e.width];n>1&&t.push(e.y+z.random()*e.height),n>2&&t.push(e.z+z.random()*e.depth),r.push(new U(t))}return r}static distributeLinear(e,t){if(t<=0)return new W;let n=H.iterToArray(e);if(t===1)return new W(n[0]);let r=N.subpoints(n,t-2);return r.unshift(n[0]),r.push(n[n.length-1]),r}static gridPts(e,t,n,r=[.5,.5]){if(t===0||n===0)throw Error(`grid columns and rows cannot be 0`);let i=e.size.$subtract(1).$divide(t,n),a=i.$multiply(r),o=new W;for(let r=0;r<n;r++)for(let n=0;n<t;n++)o.push(e.topLeft.$add(i.$multiply(n,r)).add(a));return o}static gridCells(e,t,n){if(t===0||n===0)throw Error(`grid columns and rows cannot be 0`);let r=e.size.$subtract(1).divide(t,n),i=[];for(let a=0;a<n;a++)for(let n=0;n<t;n++)i.push(new W(e.topLeft.$add(r.$multiply(n,a)),e.topLeft.$add(r.$multiply(n,a).add(r))));return i}static radialPts(e,t,n,r=-V.half_pi){let i=new W,a=V.two_pi/n;for(let o=0;o<n;o++)i.push(new U(e).toAngle(a*o+r,t,!0));return i}static noisePts(e,t=.01,n=.01,r=0,i=0){let a=z.random(),o=new W,s=0,c=i>0?i:r>0?r:0;for(let r of e){let e=new _t(r),i=c>0?Math.floor(s/c):s,l=c>0?s%c:s;e.initNoise(t*l,n*i),e.seed(a),o.push(e),s++}return o}static delaunay(e){return xt.from(e)}static flock(e,t={}){let n=new Et;n.setup(t);for(let t of e)n.addBoid(t);return n}static sampling(e,t,n={}){return new Ot().setup(e,t,n).sample()}};let dt=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],ft=[151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,129,22,39,253,9,98,108,110,79,113,224,232,178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180],pt=ft.concat(ft),mt,ht=null;function gt(e){if(e===mt&&ht)return ht;let t=e;t>0&&t<1&&(t*=65536),t=Math.floor(t),t<256&&(t|=t<<8);let n=Array(512);for(let e=0;e<256;e++){let r=e&1?ft[e]^t&255:ft[e]^t>>8&255;n[e]=n[e+256]=r}return mt=e,ht=n,n}var _t=class extends U{constructor(...e){super(...e),this.perm=[],this._n=new U(.01,.01),this.perm=pt}initNoise(...e){return this._n=new U(...e),this}step(e=0,t=0){return this._n.add(e,t),this}seed(e){return this.perm=gt(e),this}noise2D(){let e=this.perm,t=this._n[0],n=this._n[1],r=Math.floor(t),i=Math.floor(n),a=r&255,o=i&255,s=t-r,c=n-i,l=dt[e[a+e[o]]%12],u=dt[e[a+e[o+1]]%12],d=dt[e[a+1+e[o]]%12],f=dt[e[a+1+e[o+1]]%12],p=l[0]*s+l[1]*c,m=u[0]*s+u[1]*(c-1),h=d[0]*(s-1)+d[1]*c,g=f[0]*(s-1)+f[1]*(c-1),_=e=>e*e*e*(e*(e*6-15)+10),v=_(s),y=p+v*(h-p),b=m+v*(g-m);return y+_(c)*(b-y)}};function vt(e,t,n,r,i){let a=!0;for(let o=0,s=e.length;o<s;o++){let s=e[o][0],c=e[o][1];if(s<t||s>r||c<n||c>i||!Number.isFinite(s+c)){a=!1;break}}if(a)return e;if(e.length<3){let a=new W;for(let o=0,s=e.length;o<s;o++){let s=e[o][0],c=e[o][1];s>=t&&s<=r&&c>=n&&c<=i&&a.push(e[o])}return a}let o=1e7,s=[];for(let t=0,n=e.length;t<n;t++){let n=e[t][0],r=e[t][1];Number.isFinite(n)||(n=n>0?o:-1e7),Number.isFinite(r)||(r=r>0?o:-1e7),!(Number.isNaN(n)||Number.isNaN(r))&&s.push([n,r])}let c=(e,t,n)=>{let r=[];for(let i=0,a=e.length;i<a;i++){let o=e[i===0?a-1:i-1],s=e[i],c=t(s);t(o)?c?r.push(s):r.push(n(o,s)):c&&r.push(n(o,s),s)}return r},l=(e,t,n)=>[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n];s=c(s,e=>e[0]>=t,(e,n)=>l(e,n,(t-e[0])/(n[0]-e[0]))),s=c(s,e=>e[0]<=r,(e,t)=>l(e,t,(r-e[0])/(t[0]-e[0]))),s=c(s,e=>e[1]>=n,(e,t)=>l(e,t,(n-e[1])/(t[1]-e[1]))),s=c(s,e=>e[1]<=i,(e,t)=>l(e,t,(i-e[1])/(t[1]-e[1])));let u=new W;for(let e=0,t=s.length;e<t;e++)u.push(new U(s[e]));return u}function yt(e,t,n){let r=n[0]-t[0],i=n[1]-t[1],a=t[0]+r/2,o=t[1]+i/2,s=new W;for(let t=0;t<e.length;t++){let n=e[t===0?e.length-1:t-1],c=e[t],l=(n[0]-a)*r+(n[1]-o)*i,u=(c[0]-a)*r+(c[1]-o)*i;if(l<=0!=u<=0){let e=l/(l-u);s.push(new U(n[0]+(c[0]-n[0])*e,n[1]+(c[1]-n[1])*e))}u<=0&&s.push(c)}return s}function bt(e,t,n,r,i,a){let o=n-e,s=r-t,c=i-e,l=a-t,u=2*(o*l-s*c),d=o*o+s*s,f=c*c+l*l,p=(l*d-s*f)/u,m=(o*f-c*d)/u;return[e+p,t+m,Math.sqrt(p*p+m*m)]}var xt=class extends W{constructor(...e){super(...e),this._mesh=[],this._meshBuilt=!0,this._count=0,this._tri=null,this._shapes=null}delaunay(e=!0){let t=this.length;if(this._count=t,this._mesh=[],this._meshBuilt=!1,this._tri=null,this._shapes=null,t<3)return[];let n=new Float64Array(t*2);for(let e=0;e<t;e++)n[2*e]=this[e][0],n[2*e+1]=this[e][1];let r=ce(n,t);if(r.triangles.length===0)return[];this._tri=r;let i=r.triangles,a=[],o=[];for(let e=0,t=i.length;e<t;e+=3){let t=i[e],r=i[e+1],s=i[e+2],c=this._triangle(t,r,s),[l,u,d]=bt(n[2*t],n[2*t+1],n[2*r],n[2*r+1],n[2*s],n[2*s+1]),f=new W(new U(l,u),new U(d,d));a.push({i:t,j:r,k:s,triangle:c,circle:f}),o.push(c)}return this._shapes=a,e?o:a}_ensureMesh(){if(!this._meshBuilt){this._meshBuilt=!0,this._mesh=[];for(let e=0;e<this._count;e++)this._mesh[e]={};if(this._shapes)for(let e=0,t=this._shapes.length;e<t;e++)this._cache(this._shapes[e])}return this._mesh}voronoi(e){let t=this._voronoiCells();if(!e)return t;let n=B.boundingBox(H.iterToArray(e)),r=n[0][0],i=n[0][1],a=n[1][0],o=n[1][1],s=new Set;if(this._tri)for(let e of this._tri.hull)s.add(e);let c=new Set;for(let e=0,n=t.length;e<n;e++){let n=`${this[e][0]},${this[e][1]}`;if(c.has(n)){t[e]=new W;continue}if(c.add(n),!s.has(e)&&t[e].length>=3){t[e]=vt(t[e],r,i,a,o);continue}let l=new Set;for(let t of this.neighbors(e))for(let n of[t.i,t.j,t.k])n!==e&&l.add(n);if(l.size===0)for(let t=0;t<this.length;t++)t!==e&&l.add(t);let u=W.fromArray([[r,i],[a,i],[a,o],[r,o]]);for(let t of l)u=yt(u,this[e],this[t]);t[e]=u}return t}_voronoiCells(){let e=this._tri,t=this._shapes;if(!e||!t){let e=[],t=this._ensureMesh();for(let n=0,r=t.length;n<r;n++)e.push(this.neighborPts(n,!0));return e}let n=this._count,r=e.triangles,i=e.neighbors,a=new Int32Array(n).fill(-1);for(let e=0,t=r.length;e<t;e++){let t=r[e];(i[e]===-1||a[t]===-1)&&(a[t]=e)}let o=[];for(let e=0;e<n;e++){let n=new W,r=a[e];if(r!==-1){let e=r/3|0;for(;;){let a=r/3|0;n.push(t[a].circle[0]);let o=i[3*a+(r+2)%3];if(o===-1||(o/3|0)===e)break;r=o}}o.push(n)}return o}mesh(){return this._ensureMesh()}neighborPts(e,t=!1){let n=new W,r=this._ensureMesh();for(let t in r[e])r[e].hasOwnProperty(t)&&n.push(r[e][t].circle[0]);return t&&n.length>1?B.sortEdges(n):n}neighbors(e){let t=[],n=this._ensureMesh();for(let r in n[e])n[e].hasOwnProperty(r)&&t.push(n[e][r]);return t}_cache(e){this._mesh[e.i][`${Math.min(e.j,e.k)}-${Math.max(e.j,e.k)}`]=e,this._mesh[e.j][`${Math.min(e.i,e.k)}-${Math.max(e.i,e.k)}`]=e,this._mesh[e.k][`${Math.min(e.i,e.j)}-${Math.max(e.i,e.j)}`]=e}_superTriangle(){let e=this[0],t=this[0];for(let n=1,r=this.length;n<r;n++)e=e.$min(this[n]),t=t.$max(this[n]);let n=t.$subtract(e),r=e.$add(t).divide(2),i=Math.max(n[0],n[1]);return new W(r.$subtract(20*i,i),r.$add(0,20*i),r.$add(20*i,-i))}_triangle(e,t,n,r=this){return new W(r[e],r[t],r[n])}_circum(e,t,n,r,i=this){let a=r||this._triangle(e,t,n,i);return{i:e,j:t,k:n,triangle:a,circle:we.circumcircle(a)}}static _dedupe(e){let t=e.length;for(;t>1;){let n=e[--t],r=e[--t],i=t;for(;i>1;){let a=e[--i],o=e[--i];if(r==o&&n==a||r==a&&n==o){e.splice(t,2),e.splice(i,2);break}}}return e}};function St(e,t,n,r){let i=t*t+n*n;if(i<=0)return;let a=r/Math.sqrt(i);e[0]+=t*a,e[1]+=n*a}let Ct=2147483647,wt=-2147483648;var Tt=class extends U{constructor(...e){super(...e),this._vel=new U(0,0)}get velocity(){return this._vel}set velocity(e){this._vel=e}get speed(){return Math.sqrt(this._vel[0]*this._vel[0]+this._vel[1]*this._vel[1])}get heading(){return Math.atan2(this._vel[1],this._vel[0])}},Et=class extends W{constructor(...e){super(...e),this._perception=40,this._separation=20,this._cohesionWeight=1,this._alignWeight=1,this._separateWeight=1.5,this._maxSpeed=100,this._minSpeed=0,this._maxForce=200,this._boundary=`steer`,this._margin=50,this._maxTimeStep=50,this._bound=null,this._initialSpeed=void 0,this._pos=new Float32Array,this._vel=new Float32Array,this._sums=new Float32Array,this._counts=new Uint32Array,this._hashKeys=new Uint32Array,this._cellX=new Int32Array,this._cellY=new Int32Array,this._cellStart=new Uint32Array,this._cellEntries=new Uint32Array,this._steerOut=new Float32Array(2)}setup(e){return e.perception!==void 0&&(this.perception=e.perception),e.separation!==void 0&&(this.separation=e.separation),e.cohesionWeight!==void 0&&(this._cohesionWeight=e.cohesionWeight),e.alignWeight!==void 0&&(this._alignWeight=e.alignWeight),e.separateWeight!==void 0&&(this._separateWeight=e.separateWeight),e.maxSpeed!==void 0&&(this.maxSpeed=e.maxSpeed),e.minSpeed!==void 0&&(this.minSpeed=e.minSpeed),e.maxForce!==void 0&&(this._maxForce=e.maxForce),e.bound!==void 0&&(this._bound=e.bound),e.boundary!==void 0&&(this._boundary=e.boundary),e.margin!==void 0&&(this.margin=e.margin),e.maxTimeStep!==void 0&&(this.maxTimeStep=e.maxTimeStep),e.initialSpeed!==void 0&&(this._initialSpeed=e.initialSpeed),this}get perception(){return this._perception}set perception(e){this._perception=Math.max(0,e)}get separation(){return this._separation}set separation(e){this._separation=Math.max(0,e)}get cohesionWeight(){return this._cohesionWeight}set cohesionWeight(e){this._cohesionWeight=e}get alignWeight(){return this._alignWeight}set alignWeight(e){this._alignWeight=e}get separateWeight(){return this._separateWeight}set separateWeight(e){this._separateWeight=e}get maxSpeed(){return this._maxSpeed}set maxSpeed(e){this._maxSpeed=Math.max(0,e)}get minSpeed(){return this._minSpeed}set minSpeed(e){this._minSpeed=Math.max(0,e)}get maxForce(){return this._maxForce}set maxForce(e){this._maxForce=e}get bound(){return this._bound}set bound(e){this._bound=e}get boundary(){return this._boundary}set boundary(e){this._boundary=e}get margin(){return this._margin}set margin(e){this._margin=Math.max(0,e)}get maxTimeStep(){return this._maxTimeStep}set maxTimeStep(e){this._maxTimeStep=Math.max(0,e)}get initialSpeed(){return this._initialSpeed===void 0?this._maxSpeed*.5:this._initialSpeed}set initialSpeed(e){this._initialSpeed=e}addBoid(e,t){let n=e instanceof Tt,r=n?e:new Tt(e);if(t!==void 0)r.velocity[0]=t[0],r.velocity[1]=t[1];else if(!n){let e=z.random()*V.two_pi,t=this.initialSpeed;r.velocity[0]=Math.cos(e)*t,r.velocity[1]=Math.sin(e)*t}return this.push(r),this}step(e){let t=this.length;if(t===0||!(e>0))return this;let n=Math.min(e,this._maxTimeStep)/1e3;return n<=0?this:(this._ensureBuffers(t),this._gather(t),t>1&&this._perception>0?this._accumulate(t):(this._sums.fill(0,0,t*6),this._counts.fill(0,0,t)),this._integrate(t,n),this._scatter(t),this)}_ensureBuffers(e){if(this._pos.length<e*2){let t=e*2*2;this._pos=new Float32Array(t),this._vel=new Float32Array(t),this._sums=new Float32Array(t*3),this._counts=new Uint32Array(t),this._hashKeys=new Uint32Array(t),this._cellX=new Int32Array(t),this._cellY=new Int32Array(t),this._cellEntries=new Uint32Array(t)}}_gather(e){let t=this._pos,n=this._vel;for(let r=0;r<e;r++){let e=this[r],i=e.velocity;i===void 0&&(e=new Tt(e),i=e.velocity,this[r]=e);let a=r*2;t[a]=e[0],t[a+1]=e[1],n[a]=i[0],n[a+1]=i[1]}}_scatter(e){let t=this._pos,n=this._vel;for(let r=0;r<e;r++){let e=this[r],i=e.velocity,a=r*2;e[0]=t[a],e[1]=t[a+1],i[0]=n[a],i[1]=n[a+1]}}_accumulate(e){let t=this._pos,n=this._vel,r=this._sums,i=this._counts;r.fill(0,0,e*6),i.fill(0,0,e);let a=this._perception*this._perception,o=Math.min(this._separation,this._perception),s=o*o,c=o*.01,l=c*c,u=1/this._perception,d=16;for(;d<e*2;)d<<=1;let f=d-1;this._cellStart.length<d+1&&(this._cellStart=new Uint32Array(d+1));let p=this._hashKeys,m=this._cellX,h=this._cellY,g=this._cellStart,_=this._cellEntries;g.fill(0,0,d+1);for(let n=0;n<e;n++){let e=Math.floor(t[n*2]*u),r=Math.floor(t[n*2+1]*u);e>=-2147483647&&e<=Ct&&r>=-2147483647&&r<=Ct?(m[n]=e,h[n]=r):(m[n]=wt,h[n]=wt);let i=(Math.imul(m[n],2654435761)^Math.imul(h[n],2246822519))>>>0&f;p[n]=i,g[i]++}let v=0;for(let e=0;e<d;e++){let t=g[e];g[e]=v,v+=t}g[d]=v;for(let t=0;t<e;t++)_[g[p[t]]++]=t;for(let o=0;o<e;o++){let e=m[o];if(e===wt)continue;let c=h[o],u=o*2,d=t[u],p=t[u+1],v=n[u],y=n[u+1],b=o*6;for(let u=0;u<5;u++){let x=u===2?e-1:u===0||u===3?e:e+1,S=u<2?c:c+1,C=(Math.imul(x,2654435761)^Math.imul(S,2246822519))>>>0&f,w=g[C],T=C>0?g[C-1]:0;for(let e=T;e<w;e++){let c=_[e];if(m[c]!==x||h[c]!==S||u===0&&c<=o)continue;let f=c*2,g=t[f],C=t[f+1],w=g-d,T=C-p,E=w*w+T*T;if(!(E<a))continue;let D=c*6;if(r[b]+=g,r[b+1]+=C,r[D]+=d,r[D+1]+=p,r[b+2]+=n[f],r[b+3]+=n[f+1],r[D+2]+=v,r[D+3]+=y,i[o]++,i[c]++,E<s){let e=w,t=T,n=E;n===0?(e=1,t=0,n=l):n<l&&(n=l);let i=1/n,a=e*i,o=t*i;r[b+4]-=a,r[b+5]-=o,r[D+4]+=a,r[D+5]+=o}}}}}_integrate(e,t){let n=this._pos,r=this._vel,i=this._sums,a=this._counts,o=this._steerOut,s=this._maxSpeed,c=this._maxForce,l=Math.min(this._minSpeed,s),u=this._cohesionWeight,d=this._alignWeight,f=this._separateWeight,p=this._bound,m=p?this._boundary:`none`,h=m===`steer`&&this._margin>0,g=m===`wrap`,_=m===`bounce`,v=0,y=0,b=0,x=0;if(p&&m!==`none`){let e=p[0],t=p[1];v=Math.min(e[0],t[0]),y=Math.min(e[1],t[1]),b=Math.max(e[0],t[0]),x=Math.max(e[1],t[1])}let S=this._margin;for(let p=0;p<e;p++){let e=p*2,m=p*6,C=n[e],w=n[e+1],T=r[e],E=r[e+1];o[0]=0,o[1]=0;let D=a[p];D>0&&(u!==0&&St(o,i[m]/D-C,i[m+1]/D-w,u),d!==0&&St(o,i[m+2],i[m+3],d),f!==0&&St(o,i[m+4],i[m+5],f));let O=0,k=0,A=o[0]*o[0]+o[1]*o[1];if(A>0){let e=s/Math.sqrt(A);O=o[0]*e-T,k=o[1]*e-E;let t=O*O+k*k;if(t>c*c){let e=c/Math.sqrt(t);O*=e,k*=e}}if(h){let e=C-v,t=b-C,n=w-y,r=x-w;e<S?O+=c*(1-Math.max(e,0)/S):t<S&&(O-=c*(1-Math.max(t,0)/S)),n<S?k+=c*(1-Math.max(n,0)/S):r<S&&(k-=c*(1-Math.max(r,0)/S))}T+=O*t,E+=k*t;let j=T*T+E*E;if(j>s*s){let e=s/Math.sqrt(j);T*=e,E*=e}else if(l>0&&j<l*l){if(j>0){let e=l/Math.sqrt(j);T*=e,E*=e}else T=l,E=0}if(C+=T*t,w+=E*t,g){let e=b-v,t=x-y;e>0&&(C<v?C=b-(v-C)%e:C>b&&(C=v+(C-b)%e)),t>0&&(w<y?w=x-(y-w)%t:w>x&&(w=y+(w-x)%t))}else _&&(C<=v?(C=v,T<0&&(T=-T)):C>=b&&(C=b,T>0&&(T=-T)),w<=y?(w=y,E<0&&(E=-E)):w>=x&&(w=x,E>0&&(E=-E)));n[e]=C,n[e+1]=w,r[e]=T,r[e+1]=E}}};let Dt=[0,-1,1,-2,2];var Ot=class extends W{constructor(...e){super(...e),this._radius=0,this._candidates=8,this._dist=0,this._cos=1,this._sin=0,this._narrowX=!1,this._narrowY=!1,this._x0=0,this._y0=0,this._x1=0,this._y1=0,this._cell=1,this._cols=0,this._rows=0,this._grid=new Int32Array,this._active=[]}setup(e,t,n={}){var r,i,a;if(!(t>0)||!Number.isFinite(t))throw Error(`PoissonDisk radius must be a positive finite number`);let o=(r=e.x)==null?NaN:r,s=(i=e.y)==null?NaN:i,c=e.width,l=e.height,u=o+c,d=s+l;if(![o,s,u,d].every(Number.isFinite)||c<0||l<0)throw Error(`PoissonDisk bound must have a finite position and size`);if(c>0&&u<=o||l>0&&d<=s)throw Error(`PoissonDisk bound size must be representable at its position`);let f=(a=n.candidates)==null?8:a;if(!(f>=1)||!Number.isFinite(f))throw Error(`PoissonDisk candidates must be a number of at least 1`);let p=t/Math.SQRT2,m=c>0&&l>0,h=m?Math.ceil(c/p):0,g=m?Math.ceil(l/p):0;if(h*g>1<<26)throw Error(`PoissonDisk radius is too small for this bound: the grid would exceed 2^26 cells`);if(this.length=0,this._active.length=0,this._radius=t,this._candidates=Math.floor(f),this._x0=o,this._y0=s,this._x1=u,this._y1=d,this._cell=p,this._cols=h,this._rows=g,this._grid=new Int32Array(h*g).fill(-1),this._dist=t*1.001,this._cos=Math.cos(V.two_pi/this._candidates),this._sin=Math.sin(V.two_pi/this._candidates),this._narrowX=c<this._dist&&c<=l,this._narrowY=l<this._dist&&!this._narrowX,n.start!==void 0){let e=n.start;if(!this._tryAdd(Math.fround(e[0]),Math.fround(e[1])))throw Error(`PoissonDisk start point must lie on or after the bound's top-left edges and before its bottom-right edges`)}else if(h*g>0)for(;!this._tryAdd(Math.fround(o+z.random()*c),Math.fround(s+z.random()*l)););return this}get radius(){return this._radius}get candidates(){return this._candidates}get bound(){return new G(new U(this._x0,this._y0),new U(this._x1,this._y1))}get done(){return this._active.length===0}step(){let e=this._active,t=this._candidates,n=this._dist,r=this._cos,i=this._sin,a=this._x1-this._x0,o=this._y1-this._y0,s=this._narrowX,c=this._narrowY;for(;e.length>0;){let l=Math.floor(z.random()*e.length),u=this[e[l]],d=z.random()*V.two_pi,f=n*Math.cos(d),p=n*Math.sin(d),m=d<Math.PI?1:-1;for(let e=0;e<t;e++){if(s)f=this._x0+z.random()*a-u[0],p=m*Math.sqrt(Math.max(0,n*n-f*f)),m=-m;else if(c)p=this._y0+z.random()*o-u[1],f=m*Math.sqrt(Math.max(0,n*n-p*p)),m=-m;else if(e>0){let e=f*r-p*i;p=f*i+p*r,f=e}if(this._tryAdd(Math.fround(u[0]+f),Math.fround(u[1]+p)))return this[this.length-1]}e[l]=e[e.length-1],e.pop()}}sample(e=1/0){let t=Math.floor(e);for(let e=0;e<t&&this.step()!==void 0;e++);return this}_tryAdd(e,t){if(!(e>=this._x0&&e<this._x1&&t>=this._y0&&t<this._y1))return!1;let n=this._cols,r=this._rows,i=Math.min(n-1,Math.floor((e-this._x0)/this._cell)),a=Math.min(r-1,Math.floor((t-this._y0)/this._cell)),o=this._grid,s=this._radius*this._radius;for(let c of Dt){let l=a+c;if(l<0||l>=r)continue;let u=l*n,d=c===-2||c===2?1:2;for(let r of Dt){let a=i+r;if(r>d||r<-d||a<0||a>=n)continue;let c=o[u+a];if(c>=0){let n=this[c],r=n[0]-e,i=n[1]-t;if(r*r+i*i<s)return!1}}}return o[a*n+i]=this.length,this._active.push(this.length),this.push(new U(e,t)),!0}},kt=t({Color:()=>At}),At=class e extends U{constructor(...e){super(...e),this._mode=`rgb`,this._isNorm=!1}static from(...t){let n=[1,1,1,1],r=H.getArgs(t);for(let e=0,t=n.length;e<t;e++)e<r.length&&(n[e]=r[e]);return new e(n)}static fromHex(t){if(t[0]==`#`&&(t=t.substr(1)),t.length<=4){let e=e=>t[e]||`F`,n=t.length===4?`${e(3)}${e(3)}`:``;t=`${e(0)}${e(0)}${e(1)}${e(1)}${e(2)}${e(2)}${n}`}let n=1;t.length===8&&(n=parseInt(t.substr(6,2),16)/255,t=t.substring(0,6));let r=parseInt(t,16);return new e(r>>16,r>>8&255,r&255,n)}static rgb(...t){return e.from(...t).toMode(`rgb`)}static hsl(...t){return e.from(...t).toMode(`hsl`)}static hsb(...t){return e.from(...t).toMode(`hsb`)}static lab(...t){return e.from(...t).toMode(`lab`)}static lch(...t){return e.from(...t).toMode(`lch`)}static luv(...t){return e.from(...t).toMode(`luv`)}static xyz(...t){return e.from(...t).toMode(`xyz`)}static oklab(...t){return e.from(...t).toMode(`oklab`)}static oklch(...t){return e.from(...t).toMode(`oklch`)}static maxValues(t){return e.ranges[t].zipSlice(1).$take([0,1,2])}get hex(){return this.toString(`hex`)}get rgb(){return this.toString(`rgb`)}get rgba(){return this.toString(`rgba`)}clone(){let t=new e(this);return t.toMode(this._mode),t._isNorm=this._isNorm,t}static _denorm(t){let n=t.clone(),r=e.ranges[n._mode];for(let e=0;e<3;e++){let t=r[e];n[e]=t[0]+n[e]*(t[1]-t[0])}return n._isNorm=!1,n}static _normOut(t){let n=e.ranges[t._mode];for(let e=0;e<3;e++){let r=n[e];t[e]=(t[e]-r[0])/(r[1]-r[0])}return t._isNorm=!0,t}toMode(t,n=!1){if(n&&t!==this._mode){let n=this._mode.toUpperCase()+`to`+t.toUpperCase();if(e[n])this.to(e[n](this,this._isNorm,this._isNorm));else throw Error(`Cannot convert color with `+n)}return this._mode=t,this}get mode(){return this._mode}get r(){return this[0]}set r(e){this[0]=e}get g(){return this[1]}set g(e){this[1]=e}get b(){return this[2]}set b(e){this[2]=e}get h(){return this._mode==`lch`||this._mode==`oklch`?this[2]:this[0]}set h(e){let t=this._mode==`lch`||this._mode==`oklch`?2:0;this[t]=e}get s(){return this[1]}set s(e){this[1]=e}get l(){return this._mode==`hsl`?this[2]:this[0]}set l(e){let t=this._mode==`hsl`?2:0;this[t]=e}get a(){return this[1]}set a(e){this[1]=e}get c(){return this[1]}set c(e){this[1]=e}get u(){return this[1]}set u(e){this[1]=e}get v(){return this[2]}set v(e){this[2]=e}set alpha(e){this.length>3&&(this[3]=e)}get alpha(){return this.length>3?this[3]:1}get normalized(){return this._isNorm}set normalized(e){this._isNorm=e}normalize(t=!0){if(this._isNorm==t)return this;let n=e.ranges[this._mode];for(let e=0;e<3;e++)this[e]=t?z.mapToRange(this[e],n[e][0],n[e][1],0,1):z.mapToRange(this[e],0,1,n[e][0],n[e][1]);return this._isNorm=t,this}$normalize(e=!0){return this.clone().normalize(e)}toString(t=`mode`){let n=this._isNorm&&t!==`mode`?e._denorm(this):this;if(t==`hex`){let e=e=>{let t=Math.floor(e).toString(16);return t.length<2?`0`+t:t};return`#${e(n[0])}${e(n[1])}${e(n[2])}`}return t==`rgba`?`rgba(${Math.floor(n[0])},${Math.floor(n[1])},${Math.floor(n[2])},${this.alpha})`:t==`rgb`?`rgb(${Math.floor(n[0])},${Math.floor(n[1])},${Math.floor(n[2])})`:`${this._mode}(${this[0]},${this[1]},${this[2]},${this.alpha})`}static RGBtoHSL(t,n=!1,r=!1){let[i,a,o]=n?t:t.$normalize(),s=Math.max(i,a,o),c=Math.min(i,a,o),l=(s+c)/2,u=l,d=l;if(s==c)l=0,u=0;else{let e=s-c;u=d>.5?e/(2-s-c):e/(s+c),l=0,s===i?l=(a-o)/e+(a<o?6:0):s===a?l=(o-i)/e+2:s===o&&(l=(i-a)/e+4)}let f=e.hsl(r?l/6:l*60,u,d,t.alpha);return r&&(f.normalized=!0),f}static HSLtoRGB(t,n=!1,r=!1){let[i,a,o]=t;n||(i/=360),i-=Math.floor(i);let s=r?1:255;if(a==0){let n=e.rgb(s*o,s*o,s*o,t.alpha);return r&&(n.normalized=!0),n}let c=o<=.5?o*(1+a):o+a-o*a,l=2*o-c,u=e=>(e=e<0?e+1:e>1?e-1:e,e*6<1?l+(c-l)*e*6:e*2<1?c:e*3<2?l+(c-l)*(2/3-e)*6:l),d=e.rgb(s*u(i+1/3),s*u(i),s*u(i-1/3),t.alpha);return r&&(d.normalized=!0),d}static RGBtoHSB(t,n=!1,r=!1){let[i,a,o]=n?t:t.$normalize(),s=Math.max(i,a,o),c=Math.min(i,a,o),l=s-c,u=0,d=s===0?0:l/s,f=s;s!=c&&(s===i?u=(a-o)/l+(a<o?6:0):s===a?u=(o-i)/l+2:s===o&&(u=(i-a)/l+4));let p=e.hsb(r?u/6:u*60,d,f,t.alpha);return r&&(p.normalized=!0),p}static HSBtoRGB(t,n=!1,r=!1){let[i,a,o]=t;n||(i/=360),i-=Math.floor(i);let s=Math.floor(i*6),c=i*6-s,l=o*(1-a),u=o*(1-c*a),d=o*(1-(1-c)*a),f=[[o,d,l],[u,o,l],[l,o,d],[l,u,o],[d,l,o],[o,l,u]][s%6],p=r?1:255,m=e.rgb(p*f[0],p*f[1],p*f[2],t.alpha);return r&&(m.normalized=!0),m}static RGBtoLAB(t,n=!1,r=!1){let i=n?e._denorm(t):t;return e.XYZtoLAB(e.RGBtoXYZ(i),!1,r)}static LABtoRGB(t,n=!1,r=!1){let i=n?e._denorm(t):t;return e.XYZtoRGB(e.LABtoXYZ(i),!1,r)}static RGBtoLCH(t,n=!1,r=!1){let i=n?e._denorm(t):t;return e.LABtoLCH(e.RGBtoLAB(i),!1,r)}static LCHtoRGB(t,n=!1,r=!1){let i=n?e._denorm(t):t;return e.LABtoRGB(e.LCHtoLAB(i),!1,r)}static RGBtoLUV(t,n=!1,r=!1){let i=n?e._denorm(t):t;return e.XYZtoLUV(e.RGBtoXYZ(i),!1,r)}static LUVtoRGB(t,n=!1,r=!1){let i=n?e._denorm(t):t;return e.XYZtoRGB(e.LUVtoXYZ(i),!1,r)}static RGBtoXYZ(t,n=!1,r=!1){let i=n?t.clone():t.$normalize();for(let e=0;e<3;e++)i[e]=i[e]>.04045?Math.pow((i[e]+.055)/1.055,2.4):i[e]/12.92,i[e]=i[e]*100;let a=e.xyz(i[0]*.4124564+i[1]*.3575761+i[2]*.1804375,i[0]*.2126729+i[1]*.7151522+i[2]*.072175,i[0]*.0193339+i[1]*.119192+i[2]*.9503041,t.alpha);return r?e._normOut(a):a}static XYZtoRGB(t,n=!1,r=!1){let[i,a,o]=n?t:t.$normalize(),s=[i*3.2406254773200533+a*-1.5372079722103187+o*-.4986285986982479,i*-.9689307147293197+a*1.8757560608852415+o*.041517523842953964,i*.055710120445510616+a*-.2040210505984867+o*1.0569959422543882];for(let e=0;e<3;e++)s[e]=s[e]>.0031308?1.055*Math.pow(s[e],1/2.4)-.055:12.92*s[e],s[e]=Math.max(0,Math.min(1,s[e])),r||(s[e]=Math.round(s[e]*255));let c=e.rgb(s[0],s[1],s[2],t.alpha);return r&&(c.normalized=!0),c}static XYZtoLAB(t,n=!1,r=!1){let i=n?e._denorm(t):t.clone();i.divide(e.D65);let a=e=>e>.008856451679035631?Math.cbrt(e):(903.2962962962963*e+16)/116,o=a(i[1]),s=e.lab(116*o-16,500*(a(i[0])-o),200*(o-a(i[2])),t.alpha);return r?e._normOut(s):s}static LABtoXYZ(t,n=!1,r=!1){let i=n?e._denorm(t):t,a=(i[0]+16)/116,o=i[1]/500+a,s=a-i[2]/200,c=216/24389,l=24389/27,u=e.D65,d=Math.pow(o,3),f=Math.pow(s,3),p=e.xyz(u[0]*(d>c?d:(116*o-16)/l),u[1]*(i[0]>l*c?Math.pow((i[0]+16)/116,3):i[0]/l),u[2]*(f>c?f:(116*s-16)/l),t.alpha);return r?e._normOut(p):p}static XYZtoLUV(t,n=!1,r=!1){let[i,a,o]=n?e._denorm(t):t,s=i+15*a+3*o,c=s===0?0:4*i/s,l=s===0?0:9*a/s;a/=100;let u=a>.008856451679035631?116*Math.cbrt(a)-16:903.2962962962963*a,d=4*e.D65[0]/(e.D65[0]+15*e.D65[1]+3*e.D65[2]),f=9*e.D65[1]/(e.D65[0]+15*e.D65[1]+3*e.D65[2]),p=e.luv(u,13*u*(c-d),13*u*(l-f),t.alpha);return r?e._normOut(p):p}static LUVtoXYZ(t,n=!1,r=!1){let[i,a,o]=n?e._denorm(t):t,s=24389/27;if(i===0){let n=e.xyz(0,0,0,t.alpha);return r?e._normOut(n):n}let c=(i+16)/116,l=i>s*.008856451679035631?c*c*c:i/s,u=4*e.D65[0]/(e.D65[0]+15*e.D65[1]+3*e.D65[2]),d=9*e.D65[1]/(e.D65[0]+15*e.D65[1]+3*e.D65[2]);a=a/(13*i)+u,o=o/(13*i)+d,l*=100;let f=-1*(9*l*a)/((a-4)*o-a*o),p=(9*l-15*o*l-o*f)/(3*o),m=e.xyz(f,l,p,t.alpha);return r?e._normOut(m):m}static LABtoLCH(t,n=!1,r=!1){let i=n?e._denorm(t):t,a=B.toDegree(B.boundRadian(Math.atan2(i[2],i[1]))),o=e.lch(i[0],Math.sqrt(i[1]*i[1]+i[2]*i[2]),a,t.alpha);return r?e._normOut(o):o}static LCHtoLAB(t,n=!1,r=!1){let i=n?e._denorm(t):t,a=B.toRadian(i[2]),o=e.lab(i[0],Math.cos(a)*i[1],Math.sin(a)*i[1],t.alpha);return r?e._normOut(o):o}static RGBtoOKLAB(t,n=!1,r=!1){let i=n?t:t.$normalize(),a=e=>e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92,o=a(i[0]),s=a(i[1]),c=a(i[2]),l=Math.cbrt(.4122214708*o+.5363325363*s+.0514459929*c),u=Math.cbrt(.2119034982*o+.6806995451*s+.1073969566*c),d=Math.cbrt(.0883024619*o+.2817188376*s+.6299787005*c),f=e.oklab(.2104542553*l+.793617785*u-.0040720468*d,1.9779984951*l-2.428592205*u+.4505937099*d,.0259040371*l+.7827717662*u-.808675766*d,t.alpha);return r?e._normOut(f):f}static OKLABtoRGB(t,n=!1,r=!1){let i=n?e._denorm(t):t,a=i[0]+.3963377774*i[1]+.2158037573*i[2],o=i[0]-.1055613458*i[1]-.0638541728*i[2],s=i[0]-.0894841775*i[1]-1.291485548*i[2],c=a*a*a,l=o*o*o,u=s*s*s,d=[4.0767416621*c-3.3077115913*l+.2309699292*u,-1.2684380046*c+2.6097574011*l-.3413193965*u,-.0041960863*c-.7034186147*l+1.707614701*u];for(let e=0;e<3;e++)d[e]=d[e]>.0031308?1.055*Math.pow(d[e],1/2.4)-.055:12.92*d[e],d[e]=Math.max(0,Math.min(1,d[e])),r||(d[e]=Math.round(d[e]*255));let f=e.rgb(d[0],d[1],d[2],t.alpha);return r&&(f.normalized=!0),f}static RGBtoOKLCH(t,n=!1,r=!1){let i=n?e._denorm(t):t;return e.OKLABtoOKLCH(e.RGBtoOKLAB(i),!1,r)}static OKLCHtoRGB(t,n=!1,r=!1){let i=n?e._denorm(t):t;return e.OKLABtoRGB(e.OKLCHtoOKLAB(i),!1,r)}static OKLABtoOKLCH(t,n=!1,r=!1){let i=n?e._denorm(t):t,a=B.toDegree(B.boundRadian(Math.atan2(i[2],i[1]))),o=e.oklch(i[0],Math.sqrt(i[1]*i[1]+i[2]*i[2]),a,t.alpha);return r?e._normOut(o):o}static OKLCHtoOKLAB(t,n=!1,r=!1){let i=n?e._denorm(t):t,a=B.toRadian(i[2]),o=e.oklab(i[0],Math.cos(a)*i[1],Math.sin(a)*i[1],t.alpha);return r?e._normOut(o):o}};At.D65=new U(95.047,100,108.883,1),At.ranges={rgb:new W(new U(0,255),new U(0,255),new U(0,255)),hsl:new W(new U(0,360),new U(0,1),new U(0,1)),hsb:new W(new U(0,360),new U(0,1),new U(0,1)),lab:new W(new U(0,100),new U(-128,127),new U(-128,127)),lch:new W(new U(0,100),new U(0,100),new U(0,360)),luv:new W(new U(0,100),new U(-134,220),new U(-140,122)),xyz:new W(new U(0,100),new U(0,100),new U(0,100)),oklab:new W(new U(0,1),new U(-.4,.4),new U(-.4,.4)),oklch:new W(new U(0,1),new U(0,.4),new U(0,360))};var jt=t({DOMSpace:()=>Y,HTMLForm:()=>Pt,HTMLSpace:()=>X}),Y=class e extends Ye{constructor(t=`pt`,n){super(),this.id=`domspace`,this._autoResize=!0,this._bgcolor=`#e1e9f0`,this._css={},this._domDisposed=!1,this._ownsContainer=!1,this._resizeHandlerBound=this._resizeHandler.bind(this),this.refresh(!1);let r=null;if(this.id=`pts`,t instanceof Element)r=t,this.id=`pts_existing_space`;else{let e=t||`pt`,n=e[0]===`#`||e[0]===`.`?e:`#`+e;r=document.querySelector(n),this.id=n.substr(1)}r?(this._canvas=r,this._container=r.parentElement):(this._container=e.createElement(`div`,this.id+`_container`),this._canvas=this._createDefaultElement(this._container,this.id),document.body.appendChild(this._container),this._ownsContainer=!0),this._readyTimer=setTimeout(this._ready.bind(this,n),50)}_createDefaultElement(t,n){return e.createElement(`div`,n,t)}static createElement(e=`div`,t,n){let r=document.createElement(e);return t&&r.setAttribute(`id`,t),n&&n.appendChild&&n.appendChild(r),r}_ready(e){if(!this._domDisposed){if(!this._container)throw Error(`Cannot initiate #${this.id} element`);this._isReady=!0,this._resizeHandler(null),this.clear(this._bgcolor),this._canvas.dispatchEvent(new Event(`ready`));for(let e in this.players)this.players.hasOwnProperty(e)&&this.players[e].start&&this.players[e].start(this.bound.clone(),this);this._pointer=this.center,e&&e(this.bound,this._canvas)}}setup(e){return e.bgcolor&&(this._bgcolor=e.bgcolor),this.autoResize=e.resize!=null&&e.resize,this}getForm(){return null}set autoResize(e){this._autoResize=e,e?window.addEventListener(`resize`,this._resizeHandlerBound):(delete this._css.width,delete this._css.height,window.removeEventListener(`resize`,this._resizeHandlerBound))}get autoResize(){return this._autoResize}resize(e,t){this.bound=e,this.styles({width:`${e.width}px`,height:`${e.height}px`},!0);for(let e in this.players)if(this.players.hasOwnProperty(e)){let n=this.players[e];n.resize&&n.resize(this.bound,t)}return this}_resizeHandler(e){let t=G.fromBoundingRect(this._container.getBoundingClientRect());this._autoResize?this.styles({width:`100%`,height:`100%`},!0):this.styles({width:`${t.width}px`,height:`${t.height}px`},!0),this.resize(t,e)}get element(){return this._canvas}get parent(){return this._container}get ready(){return this._isReady}clear(e){return e&&(this.background=e),this._canvas.innerHTML=``,this}set background(e){this._bgcolor=e,this._container.style.backgroundColor=this._bgcolor}get background(){return this._bgcolor}style(e,t,n=!1){return this._css[e]=t,n&&(this._canvas.style[e]=t),this}styles(e,t=!1){for(let n in e)e.hasOwnProperty(n)&&this.style(n,e[n],t);return this}static setAttr(e,t){for(let n in t)t.hasOwnProperty(n)&&e.setAttribute(n,t[n]);return e}static getInlineStyles(e){let t=``;for(let n in e)e.hasOwnProperty(n)&&e[n]&&(t+=`${n}: ${e[n]}; `);return t}dispose(){return this._domDisposed?this:(this._domDisposed=!0,clearTimeout(this._readyTimer),this.autoResize=!1,this._unbindAll(),this._cancelAnimation(),Ye.prototype.removeAll.call(this),this._isReady=!1,this._ownsContainer&&this._container.remove(),this)}},X=class extends Y{getForm(){return new Pt(this)}static htmlElement(e,t,n,r=!0){if(!e||!e.appendChild)throw Error(`parent is not a valid DOM element`);let i=document.getElementById(n);return i&&!e.contains(i)&&(i=null),i||(i=document.createElement(t),i.setAttribute(`id`,n),r&&i.setAttribute(`class`,n.substring(0,n.indexOf(`-`))),e.appendChild(i)),i}remove(e){return this._container.querySelectorAll(`.`+Pt.scopeID(e)).forEach(e=>{e.parentNode.removeChild(e)}),super.remove(e)}removeAll(){return this._canvas.innerHTML=``,super.removeAll()}};let Mt=0,Nt=0;var Pt=class e extends Qe{static get groupID(){return Mt}static set groupID(e){Mt=e}static get domID(){return Nt}static set domID(e){Nt=e}constructor(t){super(),this._style={filled:!0,stroked:!0,background:`#f03`,"border-color":`#fff`,color:`#000`,"border-width":`1px`,"border-radius":`0`,"border-style":`solid`,opacity:1,position:`absolute`,top:0,left:0,width:0,height:0},this._ctx={group:null,groupID:`pts`,groupCount:0,currentID:`pts0`,currentClass:``,style:{}},this._ready=!1,this._formID=0,this._space=t,this._formID=e.groupID++;let n=()=>{this._ctx.group=this._space.element,this._ctx.groupID=`pts_dom_${this._formID}`,this._ctx.style=Object.assign({},this._style),this._ready=!0};this._space.ready?n():this._space.add({start:n})}get space(){return this._space}styleTo(e,t,n=``){if(this._ctx.style[e]===void 0)throw Error(`${e} style property doesn't exist`);this._ctx.style[e]=`${t}${n}`}alpha(e){return this.styleTo(`opacity`,e),this}fill(e){return typeof e==`boolean`?(this.styleTo(`filled`,e),e||this.styleTo(`background`,`transparent`)):(this.styleTo(`filled`,!0),this.styleTo(`background`,e)),this}stroke(e,t,n,r){return typeof e==`boolean`?(this.styleTo(`stroked`,e),e||this.styleTo(`border-width`,0)):(this.styleTo(`stroked`,!0),this.styleTo(`border-color`,e),this.styleTo(`border-width`,(t||1)+`px`)),this}fillText(e){return this.styleTo(`color`,e),this}cls(e){return typeof e==`boolean`?this._ctx.currentClass=``:this._ctx.currentClass=e,this}font(e,t,n,r,i){return typeof e==`number`?(this._font.size=e,i&&(this._font.face=i),t&&(this._font.weight=t),n&&(this._font.style=n),r&&(this._font.lineHeight=r)):this._font=e,this._ctx.style.font=this._font.value,this}reset(){return this._ctx.style=Object.assign({},this._style),this._font=new $e(10,`sans-serif`),this._ctx.style.font=this._font.value,this}updateScope(e,t){return this._ctx.group=t,this._ctx.groupID=e,this._ctx.groupCount=0,this.nextID(),this._ctx}scope(t){if(!t||t.animateID==null)throw Error(`item not defined or not yet added to Space`);return this.updateScope(`${e.scopeID(t)}-f${this._formID}`,this.space.element)}nextID(){return this._ctx.groupCount++,this._ctx.currentID=`${this._ctx.groupID}-${this._ctx.groupCount}`,this._ctx.currentID}static getID(t){return t.currentID||`p-${e.domID++}`}static scopeID(e){return`item-${e.animateID}`}static style(e,t){let n=[];t.filled||n.push(`background: none`),t.stroked||n.push(`border: none`);for(let e in t)if(t.hasOwnProperty(e)&&e!=`filled`&&e!=`stroked`){let r=t[e];if(r){if(!t.filled&&e.indexOf(`background`)===0||!t.stroked&&e.indexOf(`border-width`)===0)continue;n.push(`${e}: ${r}`)}}return X.setAttr(e,{style:n.join(`;`)})}static rectStyle(e,t,n){return e.style.left=t[0]+`px`,e.style.top=t[1]+`px`,e.style.width=n[0]+`px`,e.style.height=n[1]+`px`,e}static textStyle(e,t){return e.style.left=t[0]+`px`,e.style.top=t[1]+`px`,e}static point(t,n,r=5,i=`square`){return i===`circle`?e.circle(t,n,r):e.square(t,n,r)}point(t,n=5,r=`square`){return this.nextID(),this.styleTo(`border-radius`,r==`circle`?`100%`:`0`),e.point(this._ctx,t,n,r),this}static circle(t,n,r=10){let i=X.htmlElement(t.group,`div`,e.getID(t));return X.setAttr(i,{class:`pts-form pts-circle ${t.currentClass}`}),e.rectStyle(t,new U(n).$subtract(r),new U(r*2,r*2)),e.style(i,t.style),i}circle(t){return this.nextID(),this.styleTo(`border-radius`,`100%`),e.circle(this._ctx,t[0],t[1][0]),this}static square(t,n,r){let i=X.htmlElement(t.group,`div`,e.getID(t));return X.setAttr(i,{class:`pts-form pts-square ${t.currentClass}`}),e.rectStyle(t,new U(n).$subtract(r),new U(r*2,r*2)),e.style(i,t.style),i}square(t,n){return this.nextID(),this.styleTo(`border-radius`,`0`),e.square(this._ctx,t,n),this}static rect(t,n){let r=H.iterToArray(n);if(!H.arrayCheck(r))return;let i=X.htmlElement(t.group,`div`,e.getID(t));return X.setAttr(i,{class:`pts-form pts-rect ${t.currentClass}`}),e.rectStyle(t,r[0],r[1]),e.style(i,t.style),i}rect(t){return this.nextID(),this.styleTo(`border-radius`,`0`),e.rect(this._ctx,t),this}static text(t,n,r){let i=X.htmlElement(t.group,`div`,e.getID(t));return X.setAttr(i,{class:`pts-form pts-text ${t.currentClass}`}),i.textContent=r,e.textStyle(t,n),e.style(i,t.style),i}text(t,n){return this.nextID(),e.text(this._ctx,t,n),this}log(e){return this.fill(`#000`).stroke(`#fff`,.5).text([10,14],e),this}arc(e,t,n,r,i){return H.warn(`arc is not implemented in HTMLForm`),this}line(e){return H.warn(`line is not implemented in HTMLForm`),this}polygon(e){return H.warn(`polygon is not implemented in HTMLForm`),this}},Ft=t({SVGContext2D:()=>Vt,SVGForm:()=>Kt,SVGSpace:()=>$});let Z=`http://www.w3.org/2000/svg`,It=new Set([`multiply`,`screen`,`overlay`,`darken`,`lighten`,`color-dodge`,`color-burn`,`hard-light`,`soft-light`,`difference`,`exclusion`,`hue`,`saturation`,`color`,`luminosity`]),Lt=0;var Rt=class{constructor(e,t){this.stops=[],this._elem=null,this.kind=e,this.coords=t,this.id=`pts_grad_${Lt++}`}addColorStop(e,t){this.stops.push([e,t]),this._elem&&this._render(this._elem)}materialize(e){if(!this._elem){if(this._elem=document.createElementNS(Z,this.kind===`linear`?`linearGradient`:`radialGradient`),this._elem.setAttribute(`id`,this.id),this._elem.setAttribute(`gradientUnits`,`userSpaceOnUse`),this.kind===`linear`){let[e,t,n,r]=this.coords;Y.setAttr(this._elem,{x1:e,y1:t,x2:n,y2:r})}else{let[e,t,n,r,i,a]=this.coords;Y.setAttr(this._elem,{cx:r,cy:i,r:a,fx:e,fy:t}),n&&this._elem.setAttribute(`fr`,`${n}`)}this._render(this._elem)}return this._elem.parentNode!==e&&e.appendChild(this._elem),`url(#${this.id})`}_render(e){e.textContent=``;for(let[t,n]of this.stops){let r=document.createElementNS(Z,`stop`);r.setAttribute(`offset`,`${t}`),r.setAttribute(`stop-color`,n),e.appendChild(r)}}};let zt=null,Bt={};var Vt=class e{constructor(e){this.fillStyle=`#f03`,this.strokeStyle=`#fff`,this.lineWidth=1,this.lineJoin=`bevel`,this.lineCap=`butt`,this.globalAlpha=1,this.globalCompositeOperation=`source-over`,this.font=`10px sans-serif`,this.textAlign=`start`,this.textBaseline=`alphabetic`,this.lineDashOffset=0,this._dash=[],this._stateStack=[],this.className=``,this._d=``,this._shapeFill=null,this._shapeStroke=null,this._shapeStrokeStyle={},this._shapePainted=!1,this._shapeClass=``,this._shapeAlpha=1,this._shapeBlend=`source-over`,this._runs=[],this._drawCount=0,this._group=null,this._defs=null,this._pool=[],this._attrCache=[],this._host=e}static _warnOnce(e,t){Bt[e]||(Bt[e]=!0,H.warn(t))}beginFrame(){this._runs=[],this._d=``,this._shapeFill=null,this._shapeStroke=null,this._shapePainted=!1,this._drawCount=0}get drawCount(){return this._drawCount}get group(){return this._group}commitFrame(){this._flushShape(),this._group||(this._group=document.createElementNS(Z,`g`),this._group.setAttribute(`class`,`pts-svgform`),this._host.appendChild(this._group));let e=this._runs;for(let t=0;t<e.length;t++){let n=e[t],r=this._pool[t];if(!r||r.nodeName!==n.tag){let e=document.createElementNS(Z,n.tag);r?this._group.replaceChild(e,r):this._group.appendChild(e),r=e,this._pool[t]=r,this._attrCache[t]={}}let i=this._attrCache[t];for(let e in i)e in n.attrs||(r.removeAttribute(e),delete i[e]);for(let e in n.attrs){let t=`${n.attrs[e]}`;i[e]!==t&&(r.setAttribute(e,t),i[e]=t)}n.tag===`text`&&r.textContent!==n.text&&(r.textContent=n.text)}for(let t=this._pool.length-1;t>=e.length;t--)this._group.removeChild(this._pool[t]),this._pool.pop(),this._attrCache.pop();if(this._defs){let t=new Set;for(let n of e)t.add(n.attrs.fill),t.add(n.attrs.stroke);for(let e of Array.from(this._defs.children))t.has(`url(#${e.id})`)||e.remove()}}get runs(){return this._runs}resetDom(){this._group=null,this._defs=null,this._pool=[],this._attrCache=[]}disposeDom(){this._group&&this._group.parentNode&&this._group.parentNode.removeChild(this._group),this._defs&&this._defs.parentNode&&this._defs.parentNode.removeChild(this._defs),this.resetDom()}beginPath(){this._flushShape(),this._d=``}closePath(){this._d+=`Z`}moveTo(e,t){this._d+=`M${Q(e)} ${Q(t)}`}lineTo(e,t){this._d+=`L${Q(e)} ${Q(t)}`}quadraticCurveTo(e,t,n,r){this._d+=`Q${Q(e)} ${Q(t)} ${Q(n)} ${Q(r)}`}bezierCurveTo(e,t,n,r,i,a){this._d+=`C${Q(e)} ${Q(t)} ${Q(n)} ${Q(r)} ${Q(i)} ${Q(a)}`}rect(e,t,n,r){this._d+=`M${Q(e)} ${Q(t)}h${Q(n)}v${Q(r)}h${Q(-n)}Z`}arc(e,t,n,r,i,a=!1){this.ellipse(e,t,n,n,0,r,i,a)}ellipse(e,t,n,r,i,a,o,s=!1){let c=s?a-o:o-a,l=c>=V.two_pi;l||(c=(c%V.two_pi+V.two_pi)%V.two_pi);let u=Math.cos(i),d=Math.sin(i),f=i=>{let a=n*Math.cos(i),o=r*Math.sin(i);return[e+a*u-o*d,t+a*d+o*u]},p=s?-1:1,m=+!s,h=Q(i*180/Math.PI),[g,_]=f(a);this._d+=this._d.length>0?`L${Q(g)} ${Q(_)}`:`M${Q(g)} ${Q(_)}`;let v=l?V.two_pi:c,y=Math.max(1,Math.ceil(v/V.pi-1e-6)),b=a;for(let e=1;e<=y;e++){let t=e===y?a+p*v:b+p*V.pi,[i,o]=f(t);this._d+=`A${Q(n)} ${Q(r)} ${h} 0 ${m} ${Q(i)} ${Q(o)}`,b=t}l&&(this._d+=`Z`)}fill(){this._shapeFill=this._resolvePaint(this.fillStyle),this._capturePaintState()}stroke(){this._shapeStroke=this._resolvePaint(this.strokeStyle),this._shapeStrokeStyle={"stroke-width":this.lineWidth,"stroke-linejoin":this.lineJoin,"stroke-linecap":this.lineCap},this._dash.length>0&&(this._shapeStrokeStyle[`stroke-dasharray`]=this._dash.join(` `),this.lineDashOffset&&(this._shapeStrokeStyle[`stroke-dashoffset`]=this.lineDashOffset)),this._capturePaintState()}_capturePaintState(){this._shapePainted=!0,this._shapeClass=this.className,this._shapeAlpha=this.globalAlpha,this._shapeBlend=this.globalCompositeOperation,this._drawCount++}fillRect(e,t,n,r){this.beginPath(),this.rect(e,t,n,r),this.fill()}clearRect(){}fillText(e,t,n,r){this._flushShape();let i=this.textAlign===`center`?`middle`:this.textAlign===`right`||this.textAlign===`end`?`end`:`start`,a=this.textBaseline===`top`?`text-before-edge`:this.textBaseline===`middle`?`central`:this.textBaseline===`bottom`?`text-after-edge`:this.textBaseline,o={x:Q(t),y:Q(n),fill:this._resolvePaint(this.fillStyle),"text-anchor":i,"dominant-baseline":a,style:`font: ${this.font}`,"pointer-events":`none`};r>0&&this.measureText(e).width>r&&(o.textLength=Q(r),o.lengthAdjust=`spacingAndGlyphs`),this._applyCommon(o),this._runs.push({tag:`text`,attrs:o,text:e}),this._drawCount++}measureText(e){return zt||(zt=document.createElement(`canvas`).getContext(`2d`)),zt.font=this.font,zt.measureText(e)}drawImage(t,n,r,i,a,...o){var s;if(o.length>0){e._warnOnce(`drawImage9`,`SVG output does not support the 9-argument (source-cropped) drawImage`);return}this._flushShape();let c=(s=t.src)==null?t.toDataURL?t.toDataURL():null:s;if(!c){e._warnOnce(`drawImageSrc`,`SVG output supports images from <img> elements or canvases only`);return}let l={href:c,x:Q(n),y:Q(r)},u=i==null?t.width:i,d=a==null?t.height:a;u!=null&&(l.width=Q(u)),d!=null&&(l.height=Q(d)),this._applyCommon(l),this._runs.push({tag:`image`,attrs:l}),this._drawCount++}putImageData(){e._warnOnce(`putImageData`,`putImageData is not supported in SVG output`)}save(){this._stateStack.push({fillStyle:this.fillStyle,strokeStyle:this.strokeStyle,lineWidth:this.lineWidth,lineJoin:this.lineJoin,lineCap:this.lineCap,globalAlpha:this.globalAlpha,globalCompositeOperation:this.globalCompositeOperation,font:this.font,textAlign:this.textAlign,textBaseline:this.textBaseline,lineDashOffset:this.lineDashOffset,_dash:this._dash.slice()})}restore(){let e=this._stateStack.pop();e&&Object.assign(this,e)}scale(){}clip(){e._warnOnce(`clip`,`clip is not yet supported in SVG output`)}setLineDash(e){this._dash=e}getLineDash(){return this._dash}createLinearGradient(e,t,n,r){return new Rt(`linear`,[e,t,n,r])}createRadialGradient(e,t,n,r,i,a){return new Rt(`radial`,[e,t,n,r,i,a])}_resolvePaint(t){return t instanceof Rt?(this._defs||(this._defs=document.createElementNS(Z,`defs`),this._host.insertBefore(this._defs,this._host.firstChild)),t.materialize(this._defs)):typeof t==`string`?t:(e._warnOnce(`pattern`,`canvas patterns are not supported in SVG output; use CanvasSpace`),`none`)}_applyCommon(t){t.class=this.className?`pts-svgform ${this.className}`:`pts-svgform`,t.opacity=this.globalAlpha===1?1:this.globalAlpha;let n=this.globalCompositeOperation;if(n!==`source-over`){if(It.has(n)){let e=`mix-blend-mode: ${n}`;t.style=t.style?`${t.style}; ${e}`:e}else e._warnOnce(`composite-${n}`,`composite operation "${n}" has no SVG equivalent`)}}_flushShape(){var t,n;if(!this._shapePainted||this._d.length===0){this._shapePainted=!1;return}let r={d:this._d,fill:(t=this._shapeFill)==null?`none`:t,stroke:(n=this._shapeStroke)==null?`none`:n};this._shapeStroke&&Object.assign(r,this._shapeStrokeStyle),r.class=this._shapeClass?`pts-svgform ${this._shapeClass}`:`pts-svgform`,r.opacity=this._shapeAlpha,this._shapeBlend!==`source-over`&&(It.has(this._shapeBlend)?r.style=`mix-blend-mode: ${this._shapeBlend}`:e._warnOnce(`composite-${this._shapeBlend}`,`composite operation "${this._shapeBlend}" has no SVG equivalent`));let i=this._runs[this._runs.length-1];i&&i.tag===`path`&&Ht(i.attrs,r)?(i.shapeEnds.push(i.attrs.d.length),i.attrs.d=i.attrs.d+this._d):this._runs.push({tag:`path`,attrs:r,shapeEnds:[]}),this._d=``,this._shapeFill=null,this._shapeStroke=null,this._shapePainted=!1}};function Q(e){return Math.round(e*100)/100}function Ht(e,t){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(r!==`d`&&e[r]!==t[r])return!1;return!0}var $=class e extends Y{constructor(t=`pt`,n){if(super(t,n),this._bgcolor=`#999`,this._svgContexts=[],this._bgElem=null,this._svgRefresh=!0,this._canvas.nodeName.toLowerCase()!=`svg`){let t=e.svgElement(this._canvas,`svg`,`${this.id}_svg`);this._container=this._canvas,this._canvas=t}this.refresh(!0)}_createDefaultElement(t,n){return e.svgElement(t,`svg`,n)}getForm(){return new Kt(this)}get element(){return this._canvas}registerContext(e){this._svgContexts.push(e)}resize(t,n){return super.resize(t,n),e.setAttr(this.element,{viewBox:`0 0 ${this.bound.width} ${this.bound.height}`,width:`${this.bound.width}`,height:`${this.bound.height}`,xmlns:Z,version:`1.1`}),this._updateBackground(),this}clear(e){return e&&(this._bgcolor=e),this._updateBackground(),this}_updateBackground(){let e=this._canvas;this._bgElem||(this._bgElem=document.createElementNS(Z,`rect`),this._bgElem.setAttribute(`class`,`pts-svg-bg`),e.insertBefore(this._bgElem,e.firstChild)),Y.setAttr(this._bgElem,{x:0,y:0,width:this.bound.width,height:this.bound.height,fill:!this._bgcolor||this._bgcolor===`transparent`?`none`:this._bgcolor})}playItems(e){let t=this._svgContexts;for(let e=0,n=t.length;e<n;e++)t[e].beginFrame();super.playItems(e);for(let e=0,n=t.length;e<n;e++)(this._svgRefresh||t[e].drawCount>0)&&t[e].commitFrame()}refresh(e){return this._svgRefresh=e,super.refresh(e)}toSVG(e=!1){let t=this._canvas;if(!e)return t.outerHTML;let n=t.cloneNode(!0),r=n.querySelectorAll(`g.pts-svgform`),i=0;for(let e of this._svgContexts){let t=r[i++];if(t){t.textContent=``;for(let n of e.runs){if(n.tag!==`path`){let e=document.createElementNS(Z,n.tag);Y.setAttr(e,n.attrs),n.text&&(e.textContent=n.text),t.appendChild(e);continue}let e=n.attrs.d,r=[...n.shapeEnds,e.length],i=0;for(let a of r){let r=document.createElementNS(Z,`path`);Y.setAttr(r,K(K({},n.attrs),{},{d:e.slice(i,a)})),t.appendChild(r),i=a}}}}return n.outerHTML}static svgElement(e,t,n){if(!e||!e.appendChild)throw Error(`parent is not a valid DOM element`);let r=document.getElementById(n);return r&&!e.contains(r)&&(r=null),r||(r=document.createElementNS(Z,t),r.setAttribute(`id`,n),e.appendChild(r)),r}remove(e){return this._container.querySelectorAll(`.`+Kt.scopeID(e)).forEach(e=>{e.parentNode.removeChild(e)}),super.remove(e)}removeAll(){this._canvas.innerHTML=``,this._bgElem=null;for(let e of this._svgContexts)e.resetDom();return super.removeAll()}dispose(){super.dispose();for(let e of this._svgContexts)e.disposeDom();return this._svgContexts=[],this._bgElem&&this._bgElem.parentNode&&this._bgElem.parentNode.removeChild(this._bgElem),this._bgElem=null,this}};let Ut=0,Wt=0,Gt={fillStyle:`fill`,strokeStyle:`stroke`,lineWidth:`stroke-width`,lineJoin:`stroke-linejoin`,lineCap:`stroke-linecap`,globalAlpha:`opacity`,font:`font`};var Kt=class e extends J{static get groupID(){return Ut}static set groupID(e){Ut=e}static get domID(){return Wt}static set domID(e){Wt=e}constructor(e){super(),this._formID=Ut++,this._legacyCtx={group:null,groupID:`pts`,groupCount:0,currentID:`pts0`,currentClass:``,style:{}},this._svgSpace=e,this._svgCtx=new Vt(e.element),e.registerContext(this._svgCtx),this._ctx=this._svgCtx,this._set(`fillStyle`,this._style.fillStyle),this._set(`strokeStyle`,this._style.strokeStyle),this._set(`lineJoin`,`bevel`),this._set(`font`,this._font.value),this._ready=!0,this._legacyCtx.group=e.element}_set(e,t){let n=Gt[e];n&&(typeof t==`string`||typeof t==`number`)&&(this._legacyCtx.style[n]=t),super._set(e,t)}get filled(){return this._filled}set filled(e){this._filled=e,this._legacyCtx.style.filled=e}get stroked(){return this._stroked}set stroked(e){this._stroked=e,this._legacyCtx.style.stroked=e}useOffscreen(t=!0,n=!1){return e._warnOffscreen(),this}renderOffscreen(t=[0,0]){e._warnOffscreen()}static _warnOffscreen(){e._offscreenWarned||(e._offscreenWarned=!0,H.warn(`offscreen canvases are not supported in SVG output; use CanvasSpace`))}get space(){return this._svgSpace}get svgContext(){return this._svgCtx}cls(e){let t=typeof e==`boolean`?``:e;return this._legacyCtx.currentClass=t,this._svgCtx.className=t,this}updateScope(e,t){return this._legacyCtx.group=t,this._legacyCtx.groupID=e,this._legacyCtx.groupCount=0,this.nextID(),this._legacyCtx}scope(t){if(!t||t.animateID==null)throw Error(`item not defined or not yet added to Space`);return this.updateScope(`${e.scopeID(t)}-f${this._formID}`,this._svgSpace.element)}nextID(){return this._legacyCtx.groupCount++,this._legacyCtx.currentID=`${this._legacyCtx.groupID}-${this._legacyCtx.groupCount}`,this._legacyCtx.currentID}static getID(t){return t.currentID||`p-${e.domID++}`}static scopeID(e){return`item-${e.animateID}`}static style(e,t){let n=[];t.filled||n.push(`fill: none`),t.stroked||n.push(`stroke: none`);for(let e in t)if(t.hasOwnProperty(e)&&e!=`filled`&&e!=`stroked`){let r=t[e];if(r){if(!t.filled&&e.indexOf(`fill`)===0||!t.stroked&&e.indexOf(`stroke`)===0)continue;n.push(`${e}: ${r}`)}}return Y.setAttr(e,{style:n.join(`;`)})}static point(t,n,r=5,i=`square`){return`style`in t?e.pointElement(t,n,r,i):J.point(t,n,r,i)}static circle(t,n,r=10){return`style`in t?e.circleElement(t,n,r):J.circle(t,n,r)}static arc(t,n,r,i,a,o){return`style`in t?e.arcElement(t,n,r,i,a,o):J.arc(t,n,r,i,a,o)}static square(t,n,r){return`style`in t?e.squareElement(t,n,r):J.square(t,n,r)}static line(t,n){return`style`in t?e.lineElement(t,n):J.line(t,n)}static polygon(t,n){return`style`in t?e.polygonElement(t,n):J.polygon(t,n)}static rect(t,n){return`style`in t?e.rectElement(t,n):J.rect(t,n)}static bezier(t,n){return`style`in t?e.bezierElement(t,n):J.bezier(t,n)}static compound(t,n){return`style`in t?e.compoundElement(t,n):J.compound(t,n)}static text(t,n,r,i){return`style`in t?e.textElement(t,n,r):J.text(t,n,r,i)}static pointElement(t,n,r=5,i=`square`){return i===`circle`?e.circleElement(t,n,r):e.squareElement(t,n,r)}static circleElement(t,n,r=10){let i=$.svgElement(t.group,`circle`,e.getID(t));return Y.setAttr(i,{cx:n[0],cy:n[1],r,class:`pts-svgform pts-circle ${t.currentClass}`}),e.style(i,t.style),i}static arcElement(t,n,r,i,a,o){let s=$.svgElement(t.group,`path`,e.getID(t)),c=new U(n).toAngle(i,r,!0),l=new U(n).toAngle(a,r,!0),u=B.boundAngle(a)-B.boundAngle(i)>V.pi;o&&(u=!u);let d=o?`0`:`1`,f=`M ${c[0]} ${c[1]} A ${r} ${r} 0 ${u?`1`:`0`} ${d} ${l[0]} ${l[1]}`;return Y.setAttr(s,{d:f,class:`pts-svgform pts-arc ${t.currentClass}`}),e.style(s,t.style),s}static squareElement(t,n,r){let i=$.svgElement(t.group,`rect`,e.getID(t));return Y.setAttr(i,{x:n[0]-r,y:n[1]-r,width:r*2,height:r*2,class:`pts-svgform pts-square ${t.currentClass}`}),e.style(i,t.style),i}static lineElement(t,n){let r=e.pointsString(n);if(r.count<2)return;if(r.count>2)return e._poly(t,r.string,!1);let i=$.svgElement(t.group,`line`,e.getID(t)),a=H.iterToArray(n);return Y.setAttr(i,{x1:a[0][0],y1:a[0][1],x2:a[1][0],y2:a[1][1],class:`pts-svgform pts-line ${t.currentClass}`}),e.style(i,t.style),i}static _poly(t,n,r=!0){let i=$.svgElement(t.group,r?`polygon`:`polyline`,e.getID(t));return Y.setAttr(i,{points:n,class:`pts-svgform pts-polygon ${t.currentClass}`}),e.style(i,t.style),i}static pointsString(e){let t=``,n=0;for(let r of e)t+=`${r[0]},${r[1]} `,n++;return{string:t,count:n}}static polygonElement(t,n){let r=e.pointsString(n);return e._poly(t,r.string,!0)}static bezierElement(t,n){let r=H.iterToArray(n);if(r.length<4)return;let i=`M${r[0][0]} ${r[0][1]}`;for(let e=3;e<r.length;e+=3)i+=`C${r[e-2][0]} ${r[e-2][1]} ${r[e-1][0]} ${r[e-1][1]} ${r[e][0]} ${r[e][1]}`;return e._pathElement(t,i)}static compoundElement(t,n){let r=``;for(let e of n){let t=H.iterToArray(e);if(!(t.length<2||typeof t[0][0]!=`number`)){r+=`M${t[0][0]} ${t[0][1]}`;for(let e=1;e<t.length;e++)r+=`L${t[e][0]} ${t[e][1]}`;r+=`Z`}}if(r!==``)return e._pathElement(t,r)}static _pathElement(t,n){let r=$.svgElement(t.group,`path`,e.getID(t));return Y.setAttr(r,{d:n,class:`pts-svgform pts-path ${t.currentClass}`}),e.style(r,t.style),r}static rectElement(t,n){if(!H.arrayCheck(n))return;let r=$.svgElement(t.group,`rect`,e.getID(t)),i=W.fromArray(n).boundingBox(),a=P.size(i);return Y.setAttr(r,{x:i[0][0],y:i[0][1],width:a[0],height:a[1],class:`pts-svgform pts-rect ${t.currentClass}`}),e.style(r,t.style),r}static textElement(t,n,r){let i=$.svgElement(t.group,`text`,e.getID(t));return Y.setAttr(i,{"pointer-events":`none`,x:n[0],y:n[1],dx:0,dy:0,class:`pts-svgform pts-text ${t.currentClass}`}),i.textContent=r,e.style(i,t.style),i}};Kt._offscreenWarned=!1;var qt=t({Body:()=>Zt,Particle:()=>Xt,World:()=>Yt});let Jt=1/60;var Yt=class e{constructor(e,t=1,n=0){return this._gravity=new U,this._friction=1,this._damping=.75,this._iterations=1,this._substeps=4,this._maxTimeStep=50,this._particles=[],this._bodies=[],this._pnames=[],this._bnames=[],this._frictionStep=1,this._carry=0,this._hashKeys=new Uint32Array,this._cellStart=new Uint32Array,this._cellEntries=new Uint32Array,this._neighborKeys=new Uint32Array(9),this._bodyBounds=new Float32Array,this._bound=G.fromGroup(e),this._friction=t,this._gravity=typeof n==`number`?new U(0,n):new U(n),this}get bound(){return this._bound}set bound(e){this._bound=e}get gravity(){return this._gravity}set gravity(e){this._gravity=e}get friction(){return this._friction}set friction(e){this._friction=e}get damping(){return this._damping}set damping(e){this._damping=e}get iterations(){return this._iterations}set iterations(e){this._iterations=e}get substeps(){return this._substeps}set substeps(e){this._substeps=Math.max(1,Math.round(e))}get maxTimeStep(){return this._maxTimeStep}set maxTimeStep(e){this._maxTimeStep=Math.max(0,e)}get bodyCount(){return this._bodies.length}get particleCount(){return this._particles.length}body(e){return typeof e==`string`&&e.length>0?this._bodies[this._bnames.indexOf(e)]:typeof e==`number`&&e>=0?this._bodies[e]:void 0}particle(e){return typeof e==`string`&&e.length>0?this._particles[this._pnames.indexOf(e)]:typeof e==`number`&&e>=0?this._particles[e]:void 0}bodyIndex(e){return this._bnames.indexOf(e)}particleIndex(e){return this._pnames.indexOf(e)}update(e){let t=Math.min(e,this._maxTimeStep)+this._carry;if(this._carry=0,t>=2){let e=Math.max(1,Math.round(t*this._substeps/16.666666666666668)),n=t/1e3/e;this._frictionStep=Math.pow(this._friction,n/Jt);for(let t=0;t<e;t++)this._updateParticles(n),this._updateBodies(n);this._clearForces()}else t>0&&(this._carry=t);if(this._drawParticles)for(let e=0,t=this._particles.length;e<t;e++)this._drawParticles(this._particles[e],e);if(this._drawBodies)for(let e=0,t=this._bodies.length;e<t;e++)this._drawBodies(this._bodies[e],e)}drawParticles(e){this._drawParticles=e}drawBodies(e){this._drawBodies=e}add(e,t=``){return e instanceof Zt?(this._bodies.push(e),this._bnames.push(t)):(this._particles.push(e),this._pnames.push(t)),this}_index(e,t){let n=0;if(typeof t==`string`){if(n=e(t),n<0)throw Error(`Cannot find index of ${t}. You can use particleIndex() or bodyIndex() function to check existence by name.`)}else n=t;return n}removeBody(e,t=1){let n=this._index(this.bodyIndex.bind(this),e),r=n<0?[n*-1-1,t]:[n,t];return this._bodies.splice(r[0],r[1]),this._bnames.splice(r[0],r[1]),this}removeParticle(e,t=1){let n=this._index(this.particleIndex.bind(this),e),r=n<0?[n*-1-1,t]:[n,t];return this._particles.splice(r[0],r[1]),this._pnames.splice(r[0],r[1]),this}static edgeConstraint(e,t,n,r=1,i=!1){let a=1/(e.mass||1),o=1/(t.mass||1),s=a+o,c=t.$subtract(e),l=n*n,u=i?n/c.magnitude()-1:l/(c.dot(c)+l)-.5,d=c.$multiply(u*r);return e.subtract(d.$multiply(a/s)),t.add(d.$multiply(o/s)),e}static boundConstraint(t,n,r=.75){let i=B.boundingBox(n);e._boundParticle(t,i[0][0],i[0][1],i[1][0],i[1][1],r)}static _boundParticle(e,t,n,r,i,a){let o=e[0],s=e[1],c=Math.min(Math.max(o,t+e.radius),r-e.radius),l=Math.min(Math.max(s,n+e.radius),i-e.radius);if(c!==o||l!==s){let t=e.previous,n=(o-t[0])*a,r=(s-t[1])*a;t[0]=c===o?c-n:c+n,t[1]=l===s?l-r:l+r,e[0]=c,e[1]=l}}integrate(e,t,n=e.timeStep||Jt){let r=e.previous,i=n>0?t/n:1;if(e.lock)return i!==1&&(r[0]=e[0]-(e[0]-r[0])*i,r[1]=e[1]-(e[1]-r[1])*i),e.timeStep=t,e.verlet(t,this._frictionStep,t),e;let a=e.force,o=this._frictionStep*i,s=t*t,c=e[0],l=e[1],u=c+(c-r[0])*o+(a[0]+this._gravity[0])*s,d=l+(l-r[1])*o+(a[1]+this._gravity[1])*s;return r[0]=c,r[1]=l,e[0]=u,e[1]=d,e.timeStep=t,e}_updateParticles(t){let n=this._particles,r=n.length;if(r===0)return;let i=this._bound[0],a=this._bound[1],o=Math.min(i[0],a[0]),s=Math.min(i[1],a[1]),c=Math.max(i[0],a[0]),l=Math.max(i[1],a[1]);for(let i=0;i<r;i++){let r=n[i];this.integrate(r,t),e._boundParticle(r,o,s,c,l,this._damping)}this._collideParticles()}_collideParticles(){let e=this._particles,t=e.length;if(t<2)return;let n=0;for(let r=0;r<t;r++)e[r].radius>n&&(n=e[r].radius);if(n<=0)return;let r=1/(n*2),i=16;for(;i<t*2;)i<<=1;let a=i-1;this._cellStart.length<i+1&&(this._cellStart=new Uint32Array(i+1)),this._hashKeys.length<t&&(this._hashKeys=new Uint32Array(t*2),this._cellEntries=new Uint32Array(t*2));let o=this._hashKeys,s=this._cellStart,c=this._cellEntries;s.fill(0,0,i+1);for(let n=0;n<t;n++){let t=e[n],i=(Math.imul(Math.floor(t[0]*r),2654435761)^Math.imul(Math.floor(t[1]*r),2246822519))>>>0&a;o[n]=i,s[i]++}let l=0;for(let e=0;e<i;e++){let t=s[e];s[e]=l,l+=t}s[i]=l;for(let e=0;e<t;e++)c[s[o[e]]++]=e;let u=this._damping,d=this._neighborKeys;for(let n=0;n<t;n++){let t=e[n],i=Math.floor(t[0]*r),o=Math.floor(t[1]*r),l=0;for(let r=o-1;r<=o+1;r++){let o=Math.imul(r,2246822519);for(let r=i-1;r<=i+1;r++){let i=(Math.imul(r,2654435761)^o)>>>0&a,f=!1;for(let e=0;e<l;e++)if(d[e]===i){f=!0;break}if(f)continue;d[l++]=i;let p=s[i],m=i>0?s[i-1]:0;for(let r=m;r<p;r++){let i=c[r];i>n&&t.collide(e[i],u)}}}}}_clearForces(){for(let e=0,t=this._particles.length;e<t;e++)this._particles[e].force.fill(0);for(let e=0,t=this._bodies.length;e<t;e++){let t=this._bodies[e];for(let e=0,n=t.length;e<n;e++)t[e].force.fill(0)}}_updateBodies(t){let n=this._bodies,r=n.length;if(r===0)return;let i=this._bound[0],a=this._bound[1],o=Math.min(i[0],a[0]),s=Math.min(i[1],a[1]),c=Math.max(i[0],a[0]),l=Math.max(i[1],a[1]);for(let i=0;i<r;i++){let r=n[i];if(r)for(let n=0,i=r.length;n<i;n++){let i=r[n];this.integrate(i,t),e._boundParticle(i,o,s,c,l,this._damping)}}this._collideBodies(r);for(let e=0;e<r;e++)n[e]&&n[e].solveEdges(t,this._iterations,this._substeps)}_collideBodies(e){let t=this._bodies;this._bodyBounds.length<e*4&&(this._bodyBounds=new Float32Array(e*8));let n=this._bodyBounds;for(let r=0;r<e;r++){let e=t[r],i=1/0,a=1/0,o=-1/0,s=-1/0;if(e)for(let t=0,n=e.length;t<n;t++){let n=e[t];n[0]<i&&(i=n[0]),n[0]>o&&(o=n[0]),n[1]<a&&(a=n[1]),n[1]>s&&(s=n[1])}n[r*4]=i,n[r*4+1]=a,n[r*4+2]=o,n[r*4+3]=s}let r=this._particles,i=r.length;for(let a=0;a<e;a++){let o=t[a];if(!o)continue;let s=n[a*4],c=n[a*4+1],l=n[a*4+2],u=n[a*4+3];for(let r=a+1;r<e;r++)t[r]&&s<=n[r*4+2]&&l>=n[r*4]&&c<=n[r*4+3]&&u>=n[r*4+1]&&o.processBody(t[r]);for(let e=0;e<i;e++){let t=r[e],n=t.radius;t[0]>=s-n&&t[0]<=l+n&&t[1]>=c-n&&t[1]<=u+n&&o.processParticle(t)}}}},Xt=class extends U{constructor(...e){super(...e),this._mass=1,this._radius=0,this._force=new U,this._prev=new U,this._prevDt=0,this._lock=!1,this._prev=this.clone()}get mass(){return this._mass}set mass(e){this._mass=e}get radius(){return this._radius}set radius(e){this._radius=e}get previous(){return this._prev}set previous(e){this._prev=e}get force(){return this._force}set force(e){this._force=e}get body(){return this._body}set body(e){this._body=e}get lock(){return this._lock}set lock(e){this._lock&&!e&&this._prev.to(this),this._lock=e,this._lockPt=new U(this)}get changed(){let e=this.$subtract(this._prev);return this._prevDt>0&&this._prevDt!==Jt?e.multiply(Jt/this._prevDt):e}get timeStep(){return this._prevDt}set timeStep(e){this._prevDt=e}set position(e){this.previous.to(this),this._prevDt=Jt,this._lock&&(this._lockPt=e),this.to(e)}size(e){return this._mass=e,this._radius=e,this}addForce(...e){return this._force.add(...e),this._force}verlet(e,t,n){if(this._lock)this.to(this._lockPt);else{let r=n||this._prevDt||e,i=e*(e+r)/2,a=t*e/r,o=this._force,s=this._prev;for(let e=0,t=this.length;e<t;e++){let t=this[e],n=(t-s[e])*a+(o[e]||0)*i;s[e]=t,this[e]=t+n}o.fill(0),this._prevDt=e}return this}hit(...e){let t=this._prev;if(this._prevDt>0&&this._prevDt!==Jt){let e=Jt/this._prevDt;for(let n=0,r=this.length;n<r;n++)t[n]=this[n]-(this[n]-t[n])*e}return this._prevDt=Jt,t.subtract(new U(...e).$divide(Math.sqrt(this._mass))),this}collide(e,t=1){let n=this,r=n[0]-e[0],i=n[1]-e[1],a=r*r+i*i,o=n.radius+e.radius;if(a>=o*o)return;let s=n.previous,c=e.previous,l=n[0]-s[0],u=n[1]-s[1],d=e[0]-c[0],f=e[1]-c[1],p=Math.sqrt(a),m;p<1e-6?(r=1,i=0,p=1,a=1,m=-o/2):m=(p-o)/p/2;let h=n[0]-r*m,g=n[1]-i*m,_=e[0]+r*m,v=e[1]+i*m,y=t*(r*l+i*u)/a,b=t*(r*d+i*f)/a,x=n.mass/(n.mass+e.mass),S=e.mass/(n.mass+e.mass);l+=(b-y)*r*S,u+=(b-y)*i*S,d+=(y-b)*r*x,f+=(y-b)*i*x,n[0]=h,n[1]=g,e[0]=_,e[1]=v,s[0]=h-l,s[1]=g-u,c[0]=_-d,c[1]=v-f}toString(){return`Particle: ${this[0]} ${this[1]} | previous ${this._prev[0]} ${this._prev[1]} | mass ${this._mass}`}},Zt=class e extends W{constructor(){super(),this._cs=[],this._stiff=1,this._locks={},this._mass=1,this._lambdas=new Float32Array}static fromGroup(t,n=1,r=!0,i=!0){let a=new e().init(t);return r&&a.linkAll(n),i&&a.autoMass(),a}init(e,t=1){for(let t of e){let e=new Xt(t);e.body=this,this.push(e)}return this._stiff=t,this}get mass(){return this._mass}set mass(e){this._mass=e;for(let e=0,t=this.length;e<t;e++)this[e].mass=this._mass}autoMass(){return this.mass=Math.sqrt(I.area(this))/10,this}link(e,t,n){if(e<0||e>=this.length||t<0||t>=this.length)throw Error(`index1 is not in the Group's indices`);let r=this[e].$subtract(this[t]).magnitude();return this._cs.push([e,t,r,n||this._stiff]),this}linkAll(e){let t=this.length/2,n=(e,t,n)=>{if(e===t)return;let r=this._cs;for(let n=0,i=r.length;n<i;n++){let i=r[n];if(i[0]===e&&i[1]===t||i[0]===t&&i[1]===e)return}this.link(e,t,n)};for(let r=0,i=this.length;r<i;r++){let a=r>=i-1?0:r+1;if(n(r,a,e),i>4){let a=Math.floor(t/2)+1,o=r>=i-a?r%i:r+a;n(r,o,e)}r<=t-1&&n(r,Math.min(this.length-1,r+Math.floor(t)))}}linksToLines(){let e=[];for(let t=0,n=this._cs.length;t<n;t++){let n=this._cs[t];e.push(new W(this[n[0]],this[n[1]]))}return e}processEdges(){for(let e=0,t=this._cs.length;e<t;e++){let[t,n,r,i]=this._cs[e];Yt.edgeConstraint(this[t],this[n],r,i)}}solveEdges(e,t=1,n=1){let r=this._cs,i=r.length;if(i===0)return this;this._lambdas.length<i&&(this._lambdas=new Float32Array(i));let a=this._lambdas;a.fill(0,0,i);let o=1/Math.max(1,t*n);for(let e=0;e<t;e++)for(let e=0;e<i;e++){let t=r[e],n=this[t[0]],i=this[t[1]],s=t[3],c=n.lock?0:1/(n.mass||1),l=i.lock?0:1/(i.mass||1),u=c+l;if(u===0)continue;let d=i[0]-n[0],f=i[1]-n[1],p=Math.sqrt(d*d+f*f);if(p<1e-6)continue;let m=0;if(s<1){let e=1-Math.pow(1-s,o);m=e>1e-6?u*(1-e)/e:u*1e6}let h=(-(p-t[2])-m*a[e])/(u+m);a[e]+=h;let g=h/p,_=d*g,v=f*g;n[0]-=_*c,n[1]-=v*c,i[0]+=_*l,i[1]+=v*l}return this}processBody(e){let t=this,n=e,r=I.hasIntersectPolygon(t,n);if(r){let e=r.normal.$multiply(r.dist),t,n=r.edge;t=Math.abs(n[0][0]-n[1][0])>Math.abs(n[0][1]-n[1][1])?(r.vertex[0]-e[0]-n[0][0])/(n[1][0]-n[0][0]):(r.vertex[1]-e[1]-n[0][1])/(n[1][1]-n[0][1]);let i=1/(t*t+(1-t)*(1-t)),a=r.vertex.body.mass||1,o=r.edge[0].body.mass||1,s=a/(a+o),c=o/(a+o);n[0].subtract(e.$multiply(s*(1-t)*i/2)),n[1].subtract(e.$multiply(s*t*i/2)),r.vertex.add(e.$multiply(c))}}processParticle(e){let t=this,n=e,r=I.hasIntersectCircle(t,F.fromCenter(e,e.radius));if(r){let t=r.normal.$multiply(r.dist),i,a=r.edge;i=Math.abs(a[0][0]-a[1][0])>Math.abs(a[0][1]-a[1][1])?(r.vertex[0]-t[0]-a[0][0])/(a[1][0]-a[0][0]):(r.vertex[1]-t[1]-a[0][1])/(a[1][1]-a[0][1]);let o=1/(i*i+(1-i)*(1-i)),s=n.mass||1,c=r.edge[0].body.mass||1,l=s/(s+c),u=c/(s+c);a[0].subtract(t.$multiply(l*(1-i)*o/2)),a[1].subtract(t.$multiply(l*i*o/2));let d=e.$subtract(e.previous).add(t.$multiply(u));e.previous=e.$subtract(d)}}},Qt=t({Sound:()=>en,Tempo:()=>$t}),$t=class e{constructor(e){this._listeners={},this._listenerInc=0,this.bpm=e}static fromBeat(t){return new e(6e4/t)}get bpm(){return this._bpm}set bpm(e){this._bpm=e,this._ms=6e4/this._bpm}get ms(){return this._ms}set ms(e){this._bpm=6e4/e,this._ms=e}_createID(){return`_b`+this._listenerInc++}every(e){let t=this,n=Array.isArray(e)?e[0]:e;return{start:function(r,i=0,a){let o=a||t._createID();return t._listeners[o]={name:o,beats:e,period:n,index:0,offset:i,duration:-1,count:0,continuous:!1,fn:r},this},progress:function(r,i=0,a){let o=a||t._createID();return t._listeners[o]={name:o,beats:e,period:n,index:0,offset:i,duration:-1,count:0,continuous:!0,fn:r},this}}}track(e){for(let t in this._listeners)if(this._listeners.hasOwnProperty(t)){let n=this._listeners[t],r=n.offset?e+n.offset:e,i=n.period*this._ms,a=!1;n.duration<0?(n.duration=r-r%this._ms,n.count=n.count||0,a=!0):r>n.duration+i&&(n.duration=r-r%this._ms,Array.isArray(n.beats)&&(n.index=(n.index+1)%n.beats.length,n.period=n.beats[n.index]),n.count=(n.count||0)+1,a=!0);let o;if(n.continuous){let e=z.clamp((r-n.duration)/i,0,1);o=n.fn.call(n,n.count,e,r,a)}else a&&(o=n.fn.call(n,n.count));o&&delete this._listeners[n.name]}}stop(e){this._listeners[e]&&delete this._listeners[e]}animate(e,t){this.track(e)}resize(e,t){}action(e,t,n,r){}},en=class e{constructor(t,n){this._playing=!1,this._volume=1,this._connected=[],this._bufferPlayed=!1,this._generated=!1,this._type=t,this._ctx=n||e._getContext()}static _getContext(){if(!e._sharedContext){let t=typeof window<`u`?window.AudioContext:void 0;if(!t)throw Error(`Your browser doesn't support Web Audio. (No AudioContext)`);e._sharedContext=new t}return e._sharedContext}static from(t,n,r=`gen`,i){let a=new e(r,n);return a._node=t,i&&(a._stream=i),a}static load(t,n=`anonymous`){return new Promise((r,i)=>{let a=new e(`file`);typeof t==`string`?(a._source=new Audio,a._source.crossOrigin=n,a._source.src=t):(a._source=t,a._source.crossOrigin=n),a._source.autoplay=!1;let o=()=>{a._source.removeEventListener(`canplaythrough`,s),i(Error(`Error loading sound: ${a._source.src||`media element`}`))},s=()=>{a._source.removeEventListener(`error`,o),a._source.addEventListener(`ended`,function(){a._playing=!1}),a._node=a._ctx.createMediaElementSource(a._source),r(a)};a._source.readyState>=4?s():(a._source.addEventListener(`error`,o,{once:!0}),a._source.addEventListener(`canplaythrough`,s,{once:!0}),a._source.readyState===0&&a._source.load())})}static loadAsBuffer(t){return rt(function*(){let n=new e(`file`),r=yield fetch(t);if(!r.ok)throw Error(`Error loading sound: ${t} (status ${r.status})`);try{n.createBuffer(yield n._ctx.decodeAudioData(yield r.arrayBuffer()))}catch(e){throw Object.assign(Error(`Error decoding audio`),{cause:e})}return n})()}createBuffer(e){this._node&&(this._node.onended=null,this._node.disconnect()),this._node=this._ctx.createBufferSource(),e!==void 0&&(this._buffer=e),this._node.buffer=this._buffer,this._node.onended=()=>{this._playing=!1},this._bufferPlayed=!1,this.analyzer&&this._node.connect(this.analyzer.node);for(let e of this._connected)this._node.connect(e);return this}static generate(t,n){return new e(`gen`)._gen(t,n)}_gen(e,t){this._node&&this._node.disconnect(),this._node=this._ctx.createOscillator(),this._generated=!0;let n=this._node;return e===`custom`?(this._wave=t,n.setPeriodicWave(this._wave)):(n.type=e,n.frequency.value=t),this}static input(t){return rt(function*(){let n=new e(`input`),r=t||{audio:!0,video:!1};return n._stream=yield navigator.mediaDevices.getUserMedia(r),n._node=n._ctx.createMediaStreamSource(n._stream),n})()}get ctx(){return this._ctx}get node(){return this._node}get outputNode(){return this._outputNode}get stream(){return this._stream}get source(){return this._source}get buffer(){return this._buffer}set buffer(e){this._buffer=e}get type(){return this._type}get playing(){return this._playing}get progress(){let e=0,t=0;return this._buffer?(e=this._buffer.duration,t=this._timestamp===void 0?0:this._ctx.currentTime-this._timestamp):this._source&&(e=this._source.duration,t=this._source.currentTime),e>0?z.clamp(t/e,0,1):0}get playable(){return this._type===`input`||this._type===`gen`?this._node!==void 0:!!this._buffer||this._source!==void 0&&this._source.readyState===4}get binSize(){return this.analyzer?this.analyzer.size:0}get sampleRate(){return this._ctx.sampleRate}get frequency(){let e=this._node;return this._type===`gen`&&e&&e.frequency?e.frequency.value:0}set frequency(e){let t=this._node;this._type===`gen`&&t&&t.frequency&&(t.frequency.value=e)}get volume(){return this._volume}set volume(e){this._volume=Math.max(0,e||0),this._gain&&(this._gain.gain.value=this._volume)}connect(e){return this._connected.push(e),this._node.connect(e),this}setOutputNode(e){return this._outputNode=e,this}removeOutputNode(){return this._outputNode=null,this}analyze(e=256,t=-100,n=-30,r=.8){if(this.analyzer&&this._node)try{this._node.disconnect(this.analyzer.node)}catch(e){}let i=this._ctx.createAnalyser();return i.fftSize=e*2,i.minDecibels=t,i.maxDecibels=n,i.smoothingTimeConstant=r,this.analyzer={node:i,size:i.frequencyBinCount,data:new Uint8Array(i.frequencyBinCount)},this._node.connect(this.analyzer.node),this}_domain(e){return this.analyzer?(e?this.analyzer.node.getByteTimeDomainData(this.analyzer.data):this.analyzer.node.getByteFrequencyData(this.analyzer.data),this.analyzer.data):new Uint8Array}_domainTo(e,t,n=[0,0],r=[0,0],i){let a=e?this.timeDomain():this.freqDomain(),o=i||new W,s=a.length-r[1],c=Math.max(0,s-r[0]);o.length>c&&(o.length=c);for(let e=r[0],i=0;e<s;e++,i++){let r=n[0]+t[0]*e/s,c=n[1]+t[1]*a[e]/255,l=o[i];l&&l.length>=2?(l[0]=r,l[1]=c):o[i]=new U(r,c)}return o}timeDomain(){return this._domain(!0)}timeDomainTo(e,t=[0,0],n=[0,0],r){return this._domainTo(!0,e,t,n,r)}freqDomain(){return this._domain(!1)}freqDomainTo(e,t=[0,0],n=[0,0],r){return this._domainTo(!1,e,t,n,r)}reset(){return this.stop(),this._node&&this._node.disconnect(),this._outputNode&&this._outputNode.disconnect(),this}_getGain(){return this._gain||(this._gain=this._ctx.createGain(),this._gain.gain.value=this._volume,this._gain.connect(this._ctx.destination)),this._gain}start(e=0){if(this._ctx.state===`suspended`&&this._ctx.resume(),this._type===`file`){if(this._buffer)(this._playing||this._bufferPlayed||!this._node)&&(this._playing&&this.progress<1&&this._node.stop(),this.createBuffer()),this._node.start(0,e),this._bufferPlayed=!0,this._timestamp=this._ctx.currentTime-e;else{e>0&&(this._source.currentTime=e);let t=this._source.play();t&&t.catch&&t.catch(()=>{this._source.paused&&(this._playing=!1)})}}else if(this._type===`gen`&&this._generated){if(this._playing)return this;let e=this._node;this._gen(e.type,e.type===`custom`?this._wave:e.frequency.value),this._node.start()}this.analyzer&&this._node.connect(this.analyzer.node);for(let e of this._connected)this._node.connect(e);return(this._outputNode||this._node).connect(this._getGain()),this._playing=!0,this}stop(){return this._playing?((this._outputNode||this._node).disconnect(this._gain),this._type===`file`?this._buffer?this.progress<1&&this._node.stop():this._source.pause():this._type===`gen`?this._generated&&this._node.stop():this._type===`input`&&this._stream&&this._stream.getAudioTracks().forEach(e=>e.stop()),this._playing=!1,this):this}toggle(){return this._playing?this.stop():this.start(),this}dispose(){return!this._playing&&this._stream&&this._stream.getAudioTracks().forEach(e=>e.stop()),this.reset(),this.analyzer&&(this.analyzer.node.disconnect(),this.analyzer=void 0),this._gain&&(this._gain.disconnect(),this._gain=void 0),this._connected=[],this._stream=void 0,this._source=void 0,this._buffer=void 0,this}};globalThis.Pts=K(K(K(K(K(K(K(K(K(K(K(K(K(K(K(K(K({},ot),lt),Xe),De),Ae),Se),Pe),qe),kt),Ne),jt),Ft),et),qt),Be),Qt),it),globalThis.Pts.namespace=e=>{let t=globalThis.Pts;for(let n in t)n!=`namespace`&&(e[n]=t[n])},globalThis.Pts.quickStart=(e,t=`#9ab`)=>{if(!window)return;let n=globalThis;globalThis.Pts.namespace(n);let r=typeof e==`string`&&e[0]!==`#`&&e[0]!==`.`?`#${e}`:e,i=typeof r==`string`?document.querySelector(r):r;return n.space=i&&(i.nodeName.toLowerCase()===`svg`||i.querySelector(`:scope > svg`))?new $(r).setup({bgcolor:t,resize:!0}):new st(r).setup({bgcolor:t,resize:!0,retina:!0}),n.form=n.space.getForm(),function(e=null,t=null,r=null,i=null){n.space.add({start:t,animate:e,resize:i,action:r}),n.space.bindMouse().bindTouch().play()}}})();
6
6
  //# sourceMappingURL=pts.min.js.map