pts.min.js 109 KB

1234567
  1. /*!
  2. * pts.js 0.10.5 (minified es6) - Copyright © 2017-2021 William Ngan and contributors.
  3. * Licensed under Apache 2.0 License.
  4. * See https://github.com/williamngan/pts for details.
  5. */
  6. !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Pts=e():t.Pts=e()}(this,(function(){return function(t){function e(r){if(i[r])return i[r].exports;var s=i[r]={i:r,l:!1,exports:{}};return t[r].call(s.exports,s,s.exports,e),s.l=!0,s.exports}var i={};return e.m=t,e.c=i,e.d=function(t,i,r){e.o(t,i)||Object.defineProperty(t,i,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,i){if(1&i&&(t=e(t)),8&i)return t;if(4&i&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&i&&"string"!=typeof t)for(var s in t)e.d(r,s,function(e){return t[e]}.bind(null,s));return r},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t){t.exports=function(){var t=Math.PI,e=Math.abs,i=Number.MAX_VALUE,r=Number.MIN_VALUE,s=Math.sin,n=Math.cos,o=Math.sqrt,a=Math.atan2,l=Math.pow,h=Math.min,u=Math.floor,c=Math.max;return function(t){function e(r){if(i[r])return i[r].exports;var s=i[r]={i:r,l:!1,exports:{}};return t[r].call(s.exports,s,s.exports,e),s.l=!0,s.exports}var i={};return e.m=t,e.c=i,e.d=function(t,i,r){e.o(t,i)||Object.defineProperty(t,i,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,i){if(1&i&&(t=e(t)),8&i)return t;if(4&i&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&i&&"string"!=typeof t)for(var s in t)e.d(r,s,function(e){return t[e]}.bind(null,s));return r},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s="./src/_lib.ts")}({"./src/Canvas.ts":function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.CanvasForm=e.CanvasSpace=void 0;const r=i("./src/Space.ts"),s=i("./src/Form.ts"),n=i("./src/Pt.ts"),o=i("./src/Util.ts"),a=i("./src/Typography.ts"),l=i("./src/Op.ts"),h=i("./src/Image.ts");class d extends r.MultiTouchSpace{constructor(t,e){super(),this._pixelScale=1,this._autoResize=!0,this._bgcolor="#e1e9f0",this._offscreen=!1,this._initialResize=!1;var i=null;if(this.id="pt",t instanceof Element)i=t,this.id="pts_existing_space";else{let e=t;e="#"===t[0]||"."===t[0]?t:"#"+t,i=document.querySelector(e),this.id=e.substr(1)}i?"canvas"==i.nodeName.toLowerCase()?(this._canvas=i,this._container=i.parentElement,this._autoResize=!1):(this._container=i,this._canvas=this._createElement("canvas",this.id+"_canvas"),this._container.appendChild(this._canvas),this._initialResize=!0):(this._container=this._createElement("div",this.id+"_container"),this._canvas=this._createElement("canvas",this.id),this._container.appendChild(this._canvas),document.body.appendChild(this._container)),setTimeout(this._ready.bind(this,e),100),this._ctx=this._canvas.getContext("2d")}_createElement(t="div",e){let i=document.createElement(t);return i.setAttribute("id",e),i}_ready(t){if(!this._container)throw new Error(`Cannot initiate #${this.id} element`);for(let t in this._isReady=!0,this._resizeHandler(null),this.clear(this._bgcolor),this._canvas.dispatchEvent(new Event("ready")),this.players)this.players.hasOwnProperty(t)&&this.players[t].start&&this.players[t].start(this.bound.clone(),this);this._pointer=this.center,this._initialResize=!1,t&&t(this.bound,this._canvas)}setup(t){if(this._bgcolor=t.bgcolor?t.bgcolor:"transparent",this.autoResize=null!=t.resize&&t.resize,!1!==t.retina){let t=window&&window.devicePixelRatio||1,e=this._ctx.webkitBackingStorePixelRatio||this._ctx.mozBackingStorePixelRatio||this._ctx.msBackingStorePixelRatio||this._ctx.oBackingStorePixelRatio||this._ctx.backingStorePixelRatio||1;this._pixelScale=c(1,t/e)}return t.offscreen?(this._offscreen=!0,this._offCanvas=this._createElement("canvas",this.id+"_offscreen"),this._offCtx=this._offCanvas.getContext("2d")):this._offscreen=!1,this}set autoResize(t){window&&(this._autoResize=t,t?window.addEventListener("resize",this._resizeHandler.bind(this)):window.removeEventListener("resize",this._resizeHandler.bind(this)))}get autoResize(){return this._autoResize}resize(t,e){for(let i in this.bound=t,this._canvas.width=this.bound.size.x*this._pixelScale,this._canvas.height=this.bound.size.y*this._pixelScale,this._canvas.style.width=u(this.bound.size.x)+"px",this._canvas.style.height=u(this.bound.size.y)+"px",this._offscreen&&(this._offCanvas.width=this.bound.size.x*this._pixelScale,this._offCanvas.height=this.bound.size.y*this._pixelScale),1!=this._pixelScale&&(this._ctx.scale(this._pixelScale,this._pixelScale),this._offscreen&&this._offCtx.scale(this._pixelScale,this._pixelScale)),this.players)if(this.players.hasOwnProperty(i)){let t=this.players[i];t.resize&&t.resize(this.bound,e)}return this.render(this._ctx),e&&!this.isPlaying&&this.playOnce(0),this}_resizeHandler(t){if(window){let e=this._autoResize||this._initialResize?this._container.getBoundingClientRect():this._canvas.getBoundingClientRect();if(e){let i=n.Bound.fromBoundingRect(e);i.center=i.center.add(window.pageXOffset,window.pageYOffset),this.resize(i,t)}}}set background(t){this._bgcolor=t}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 p(this)}get element(){return this._canvas}get parent(){return this._container}get ready(){return this._isReady}get ctx(){return this._ctx}clear(t){t&&(this._bgcolor=t);const e=this._ctx.fillStyle;return this._bgcolor&&"transparent"!==this._bgcolor?((0===this._bgcolor.indexOf("rgba")||9===this._bgcolor.length&&0===this._bgcolor.indexOf("#"))&&this._ctx.clearRect(-1,-1,this._canvas.width+1,this._canvas.height+1),this._ctx.fillStyle=this._bgcolor,this._ctx.fillRect(-1,-1,this._canvas.width+1,this._canvas.height+1)):this._ctx.clearRect(-1,-1,this._canvas.width+1,this._canvas.height+1),this._ctx.fillStyle=e,this}clearOffscreen(t){return this._offscreen&&(t?(this._offCtx.fillStyle=t,this._offCtx.fillRect(-1,-1,this._canvas.width+1,this._canvas.height+1)):this._offCtx.clearRect(-1,-1,this._offCanvas.width+1,this._offCanvas.height+1)),this}playItems(t){this._isReady&&(this._ctx.save(),this._offscreen&&this._offCtx.save(),super.playItems(t),this._ctx.restore(),this._offscreen&&this._offCtx.restore(),this.render(this._ctx))}dispose(){if(window)return window.removeEventListener("resize",this._resizeHandler.bind(this)),this.stop(),this.removeAll(),this}recorder(t,e="webm",i=15e6){let r=this._canvas.captureStream();const s=new MediaRecorder(r,{mimeType:"video/"+e,bitsPerSecond:i});return s.ondataavailable=function(i){let r=URL.createObjectURL(new Blob([i.data],{type:"video/"+e}));if("function"==typeof t)t(r);else if(t){let t=document.createElement("a");t.href=r,t.download="canvas_video."+e,t.click(),t.remove()}},s}}e.CanvasSpace=d;class p extends s.VisualForm{constructor(t){super(),this._style={fillStyle:"#f03",strokeStyle:"#fff",lineWidth:1,lineJoin:"bevel",lineCap:"butt",globalAlpha:1};const e=t=>{this._ctx=t,this._ctx.fillStyle=this._style.fillStyle,this._ctx.strokeStyle=this._style.strokeStyle,this._ctx.lineJoin="bevel",this._ctx.font=this._font.value,this._ready=!0};t instanceof CanvasRenderingContext2D?e(t):(this._space=t,this._space.add({start:()=>{e(this._space.ctx)}}))}get space(){return this._space}get ctx(){return this._space.ctx}useOffscreen(t=!0,e=!1){return e&&this._space.clearOffscreen("string"==typeof e?e:null),this._ctx=this._space.hasOffscreen&&t?this._space.offscreenCtx:this._space.ctx,this}renderOffscreen(t=[0,0]){this._space.hasOffscreen&&this._space.ctx.drawImage(this._space.offscreenCanvas,t[0],t[1],this._space.width,this._space.height)}alpha(t){return this._ctx.globalAlpha=t,this._style.globalAlpha=t,this}fill(t){return"boolean"==typeof t?this.filled=t:(this.filled=!0,this._style.fillStyle=t,this._ctx.fillStyle=t),this}stroke(t,e,i,r){return"boolean"==typeof t?this.stroked=t:(this.stroked=!0,this._style.strokeStyle=t,this._ctx.strokeStyle=t,e&&(this._ctx.lineWidth=e,this._style.lineWidth=e),i&&(this._ctx.lineJoin=i,this._style.lineJoin=i),r&&(this._ctx.lineCap=r,this._style.lineCap=r)),this}gradient(t){let e=[];2>t.length&&t.push([.99,"#000"],[1,"#000"]);for(let i=0,r=t.length;i<r;i++){let r="string"==typeof t[i]?i*(1/(t.length-1)):t[i][0],s="string"==typeof t[i]?t[i]:t[i][1];e.push([r,s])}return(t,i)=>{t=t.map(t=>t.abs()),i&&i.map(t=>t.abs());let r=i?this.ctx.createRadialGradient(t[0][0],t[0][1],t[1][0],i[0][0],i[0][1],i[1][0]):this.ctx.createLinearGradient(t[0][0],t[0][1],t[1][0],t[1][1]);for(let t=0,i=e.length;t<i;t++)r.addColorStop(e[t][0],e[t][1]);return r}}composite(t="source-over"){return this.ctx.globalCompositeOperation=t,this}clip(){return this.ctx.clip(),this}dash(t=!0,e=0){return t?(!0===t&&(t=[5,5]),this._ctx.setLineDash([t[0],t[1]]),this._ctx.lineDashOffset=e):(this._ctx.setLineDash([]),this._ctx.lineDashOffset=0),this}font(t,e,i,r,s){return"number"==typeof t?(this._font.size=t,s&&(this._font.face=s),e&&(this._font.weight=e),i&&(this._font.style=i),r&&(this._font.lineHeight=r)):this._font=t,this._ctx.font=this._font.value,this._estimateTextWidth&&this.fontWidthEstimate(!0),this}fontWidthEstimate(t=!0){return this._estimateTextWidth=t?a.Typography.textWidthEstimator(t=>this._ctx.measureText(t).width):void 0,this}getTextWidth(t){return this._estimateTextWidth?this._estimateTextWidth(t):this._ctx.measureText(t+" .").width}_textTruncate(t,e,i=""){return a.Typography.truncate(this.getTextWidth.bind(this),t,e,i)}_textAlign(t,e,i,r){let s=o.Util.iterToArray(t);if(o.Util.arrayCheck(s)){r||(r=l.Rectangle.center(s));var a=s[0][0];"end"==this._ctx.textAlign||"right"==this._ctx.textAlign?a=s[1][0]:("center"==this._ctx.textAlign||"middle"==this._ctx.textAlign)&&(a=r[0]);var h=r[1];return"top"==e||"start"==e?h=s[0][1]:("end"==e||"bottom"==e)&&(h=s[1][1]),i?new n.Pt(a+i[0],h+i[1]):new n.Pt(a,h)}}reset(){for(let t in this._style)this._style.hasOwnProperty(t)&&(this._ctx[t]=this._style[t]);return this._font=new s.Font,this._ctx.font=this._font.value,this}_paint(){this._filled&&this._ctx.fill(),this._stroked&&this._ctx.stroke()}static point(t,e,i=5,r="square"){if(e){if(!p[r])throw new Error(r+" is not a static function of CanvasForm");p[r](t,e,i)}}point(t,e=5,i="square"){return p.point(this._ctx,t,e,i),this._paint(),this}static circle(t,e,i=10){e&&(t.beginPath(),t.arc(e[0],e[1],i,0,o.Const.two_pi,!1),t.closePath())}circle(t){let e=o.Util.iterToArray(t);return p.circle(this._ctx,e[0],e[1][0]),this._paint(),this}static ellipse(t,e,i,r=0,s=0,n=o.Const.two_pi,a=!1){e&&i&&(t.beginPath(),t.ellipse(e[0],e[1],i[0],i[1],r,s,n,a))}ellipse(t,e,i=0,r=0,s=o.Const.two_pi,n=!1){return p.ellipse(this._ctx,t,e,i,r,s,n),this._paint(),this}static arc(t,e,i,r,s,n){e&&(t.beginPath(),t.arc(e[0],e[1],i,r,s,n))}arc(t,e,i,r,s){return p.arc(this._ctx,t,e,i,r,s),this._paint(),this}static square(t,e,i){if(e){let r=e[0]-i,s=e[1]-i,n=e[0]+i,o=e[1]+i;t.beginPath(),t.moveTo(r,s),t.lineTo(r,o),t.lineTo(n,o),t.lineTo(n,s),t.closePath()}}square(t,e){return p.square(this._ctx,t,e),this._paint(),this}static line(t,e){if(o.Util.arrayCheck(e)){let i=0;t.beginPath();for(let r of e)r&&(0<i++?t.lineTo(r[0],r[1]):t.moveTo(r[0],r[1]))}}line(t){return p.line(this._ctx,t),this._paint(),this}static polygon(t,e){o.Util.arrayCheck(e)&&(p.line(t,e),t.closePath())}polygon(t){return p.polygon(this._ctx,t),this._paint(),this}static rect(t,e){let i=o.Util.iterToArray(e);o.Util.arrayCheck(i)&&(t.beginPath(),t.moveTo(i[0][0],i[0][1]),t.lineTo(i[0][0],i[1][1]),t.lineTo(i[1][0],i[1][1]),t.lineTo(i[1][0],i[0][1]),t.closePath())}rect(t){return p.rect(this._ctx,t),this._paint(),this}static image(t,e,i,r){let s,n=o.Util.iterToArray(e);if("number"==typeof n[0])s=n;else if(r){let t=o.Util.iterToArray(r);s=[t[0][0],t[0][1],t[1][0]-t[0][0],t[1][1]-t[0][1],n[0][0],n[0][1],n[1][0]-n[0][0],n[1][1]-n[0][1]]}else s=[n[0][0],n[0][1],n[1][0]-n[0][0],n[1][1]-n[0][1]];i instanceof h.Img?i.loaded&&t.drawImage(i.image,...s):t.drawImage(i,...s)}image(t,e,i){return e instanceof h.Img?e.loaded&&p.image(this._ctx,t,e.image,i):p.image(this._ctx,t,e,i),this}static imageData(t,e,i){let r=o.Util.iterToArray(e);"number"==typeof r[0]?t.putImageData(i,r[0],r[1]):t.putImageData(i,r[0][0],r[0][1],r[0][0],r[0][1],r[1][0],r[1][1])}imageData(t,e){return p.imageData(this._ctx,t,e),this}static text(t,e,i,r){e&&t.fillText(i,e[0],e[1],r)}text(t,e,i){return p.text(this._ctx,t,e,i),this}textBox(t,e,i="middle",r="",s=!0){s&&(this._ctx.textBaseline=i);let n=l.Rectangle.size(t),o=this._textTruncate(e,n[0],r);return this.text(this._textAlign(t,i),o[0]),this}paragraphBox(t,e,i=1.2,r="top",s=!0){let a=o.Util.iterToArray(t),h=l.Rectangle.size(a);this._ctx.textBaseline="top";let u=this._font.size*i,d=(t,e=[],i=0)=>{if(!t)return e;if(s&&i*u>h[1]-2*u)return e;if(1e4<i)throw new Error("max recursion reached (10000)");let r=this._textTruncate(t,h[0],""),n=r[0].indexOf("\n");if(0<=n)return e.push(r[0].substr(0,n)),d(t.substr(n+1),e,i+1);let o=r[0].lastIndexOf(" ")+1;(0>=o||r[1]===t.length)&&(o=void 0);let a=r[0].substr(0,o);return e.push(a),0>=r[1]||r[1]===t.length?e:d(t.substr(o||r[1]),e,i+1)},p=d(e),_=p.length*u,g=a;if("middle"==r||"center"==r){let t=(h[1]-_)/2;s&&(t=c(0,t)),g=new n.Group(a[0].$add(0,t),a[1].$subtract(0,t))}else g="bottom"==r?new n.Group(a[0].$add(0,h[1]-_),a[1]):new n.Group(a[0],a[0].$add(h[0],_));let f=l.Rectangle.center(g);for(let t=0,e=p.length;t<e;t++)this.text(this._textAlign(g,"top",[0,t*u],f),p[t]);return this}alignText(t="left",e="alphabetic"){return"center"==e&&(e="middle"),"baseline"==e&&(e="alphabetic"),this._ctx.textAlign=t,this._ctx.textBaseline=e,this}log(t){let e=this._ctx.measureText(t).width+20;return this.stroke(!1).fill("rgba(0,0,0,.4)").rect([[0,0],[e,20]]),this.fill("#fff").text([10,14],t),this}}e.CanvasForm=p},"./src/Color.ts":function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Color=void 0;const r=i("./src/Pt.ts"),d=i("./src/Util.ts"),p=i("./src/Num.ts");class _ extends r.Pt{constructor(...t){super(...t),this._mode="rgb",this._isNorm=!1}static from(...t){let e=[1,1,1,1],i=d.Util.getArgs(t);for(let t=0,r=e.length;t<r;t++)t<i.length&&(e[t]=i[t]);return new _(e)}static fromHex(t){if("#"==t[0]&&(t=t.substr(1)),3>=t.length){let e=e=>t[e]||"F";t=`${e(0)}${e(0)}${e(1)}${e(1)}${e(2)}${e(2)}`}let e=1;8===t.length&&(e=t.substr(6)&&1,t=t.substring(0,6));let i=parseInt(t,16);return new _(i>>16,255&i>>8,255&i,e)}static rgb(...t){return _.from(...t).toMode("rgb")}static hsl(...t){return _.from(...t).toMode("hsl")}static hsb(...t){return _.from(...t).toMode("hsb")}static lab(...t){return _.from(...t).toMode("lab")}static lch(...t){return _.from(...t).toMode("lch")}static luv(...t){return _.from(...t).toMode("luv")}static xyz(...t){return _.from(...t).toMode("xyz")}static maxValues(t){return _.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 _(this);return t.toMode(this._mode),t}toMode(t,e=!1){if(e){let e=this._mode.toUpperCase()+"to"+t.toUpperCase();if(!_[e])throw new Error("Cannot convert color with "+e);this.to(_[e](this,this._isNorm,this._isNorm))}return this._mode=t,this}get mode(){return this._mode}get r(){return this[0]}set r(t){this[0]=t}get g(){return this[1]}set g(t){this[1]=t}get b(){return this[2]}set b(t){this[2]=t}get h(){return"lch"==this._mode?this[2]:this[0]}set h(t){this["lch"==this._mode?2:0]=t}get s(){return this[1]}set s(t){this[1]=t}get l(){return"hsl"==this._mode?this[2]:this[0]}set l(t){this["hsl"==this._mode?2:0]=t}get a(){return this[1]}set a(t){this[1]=t}get c(){return this[1]}set c(t){this[1]=t}get u(){return this[1]}set u(t){this[1]=t}get v(){return this[2]}set v(t){this[2]=t}set alpha(t){3<this.length&&(this[3]=t)}get alpha(){return 3<this.length?this[3]:1}get normalized(){return this._isNorm}set normalized(t){this._isNorm=t}normalize(t=!0){if(this._isNorm==t)return this;let e=_.ranges[this._mode];for(let i=0;3>i;i++)this[i]=t?p.Num.mapToRange(this[i],e[i][0],e[i][1],0,1):p.Num.mapToRange(this[i],0,1,e[i][0],e[i][1]);return this._isNorm=t,this}$normalize(t=!0){return this.clone().normalize(t)}toString(t="mode"){if("hex"==t){let t=t=>{let e=u(t).toString(16);return 2>e.length?"0"+e:e};return`#${t(this[0])}${t(this[1])}${t(this[2])}`}return"rgba"==t?`rgba(${u(this[0])},${u(this[1])},${u(this[2])},${this.alpha})`:"rgb"==t?`rgb(${u(this[0])},${u(this[1])},${u(this[2])})`:`${this._mode}(${this[0]},${this[1]},${this[2]},${this.alpha})`}static RGBtoHSL(t,e=!1,i=!1){let[r,s,n]=e?t:t.$normalize(),o=c(r,s,n),a=h(r,s,n),l=(o+a)/2,u=l,d=l;if(o==a)l=0,u=0;else{let t=o-a;u=.5<d?t/(2-o-a):t/(o+a),l=0,o===r?l=(s-n)/t+(s<n?6:0):o===s?l=(n-r)/t+2:o===n&&(l=(r-s)/t+4)}return _.hsl(i?l/60:60*l,u,d,t.alpha)}static HSLtoRGB(t,e=!1,i=!1){let[r,s,n]=t;if(e||(r/=360),0==s)return _.rgb(255*n,255*n,255*n,t.alpha);let o=.5>=n?n*(1+s):n+s-n*s,a=2*n-o,l=t=>1>6*(t=0>t?t+1:1<t?t-1:t)?a+(o-a)*t*6:1>2*t?o:2>3*t?a+(o-a)*(2/3-t)*6:a,h=i?1:255;return _.rgb(h*l(r+1/3),h*l(r),h*l(r-1/3),t.alpha)}static RGBtoHSB(t,e=!1,i=!1){let[r,s,n]=e?t:t.$normalize(),o=c(r,s,n),a=h(r,s,n),l=o-a,u=0,d=0===o?0:l/o;return o!=a&&(o===r?u=(s-n)/l+(s<n?6:0):o===s?u=(n-r)/l+2:o===n&&(u=(r-s)/l+4)),_.hsb(i?u/60:60*u,d,o,t.alpha)}static HSBtoRGB(t,e=!1,i=!1){let[r,s,n]=t;e||(r/=360);let o=u(6*r),a=6*r-o,l=n*(1-s),h=n*(1-a*s),c=n*(1-(1-a)*s),d=[[n,c,l],[h,n,l],[l,n,c],[l,h,n],[c,l,n],[n,l,h]][o%6],p=i?1:255;return _.rgb(p*d[0],p*d[1],p*d[2],t.alpha)}static RGBtoLAB(t,e=!1,i=!1){let r=e?t.$normalize(!1):t;return _.XYZtoLAB(_.RGBtoXYZ(r),!1,i)}static LABtoRGB(t,e=!1,i=!1){let r=e?t.$normalize(!1):t;return _.XYZtoRGB(_.LABtoXYZ(r),!1,i)}static RGBtoLCH(t,e=!1,i=!1){let r=e?t.$normalize(!1):t;return _.LABtoLCH(_.RGBtoLAB(r),!1,i)}static LCHtoRGB(t,e=!1,i=!1){let r=e?t.$normalize(!1):t;return _.LABtoRGB(_.LCHtoLAB(r),!1,i)}static RGBtoLUV(t,e=!1,i=!1){let r=e?t.$normalize(!1):t;return _.XYZtoLUV(_.RGBtoXYZ(r),!1,i)}static LUVtoRGB(t,e=!1,i=!1){let r=e?t.$normalize(!1):t;return _.XYZtoRGB(_.LUVtoXYZ(r),!1,i)}static RGBtoXYZ(t,e=!1,i=!1){let r=e?t.clone():t.$normalize();for(let t=0;3>t;t++)r[t]=.04045<r[t]?l((r[t]+.055)/1.055,2.4):r[t]/12.92,i||(r[t]*=100);let s=_.xyz(.4124564*r[0]+.3575761*r[1]+.1804375*r[2],.2126729*r[0]+.7151522*r[1]+.072175*r[2],.0193339*r[0]+.119192*r[1]+.9503041*r[2],t.alpha);return i?s.normalize():s}static XYZtoRGB(t,e=!1,i=!1){let[r,s,n]=e?t:t.$normalize(),o=[3.2404542*r+-1.5371385*s+-.4985314*n,-.969266*r+1.8760108*s+.041556*n,.0556434*r+-.2040259*s+1.0572252*n];for(let t=0;3>t;t++)o[t]=0>o[t]?0:.0031308<o[t]?1.055*l(o[t],1/2.4)-.055:12.92*o[t],o[t]=c(0,h(1,o[t])),i||(o[t]=Math.round(255*o[t]));let a=_.rgb(o[0],o[1],o[2],t.alpha);return i?a.normalize():a}static XYZtoLAB(t,e=!1,i=!1){let r=e?t.$normalize(!1):t.clone();r.divide(_.D65);let s=t=>.008856<t?l(t,1/3):7.787*t+16/116,n=s(r[1]),o=_.lab(116*n-16,500*(s(r[0])-n),200*(n-s(r[2])),t.alpha);return i?o.normalize():o}static LABtoXYZ(t,e=!1,i=!1){let r=e?t.$normalize(!1):t,s=(r[0]+16)/116,n=r[1]/500+s,o=s-r[2]/200,a=t=>{let e=t*t*t;return.008856<e?e:(t-16/116)/7.787},l=_.D65,h=_.xyz(c(0,l[0]*a(n)),c(0,l[1]*a(s)),c(0,l[2]*a(o)),t.alpha);return i?h.normalize():h}static XYZtoLUV(t,e=!1,i=!1){let[r,s,n]=e?t.$normalize(!1):t,o=4*r/(r+15*s+3*n),a=9*s/(r+15*s+3*n);s/=100,s=.008856<s?l(s,1/3):7.787*s+16/116;let h=4*_.D65[0]/(_.D65[0]+15*_.D65[1]+3*_.D65[2]),u=9*_.D65[1]/(_.D65[0]+15*_.D65[1]+3*_.D65[2]),c=116*s-16;return _.luv(c,13*c*(o-h),13*c*(a-u),t.alpha)}static LUVtoXYZ(t,e=!1,i=!1){let[r,s,n]=e?t.$normalize(!1):t,o=(r+16)/116,a=o*o*o;o=.008856<a?a:(o-16/116)/7.787,s=s/(13*r)+4*_.D65[0]/(_.D65[0]+15*_.D65[1]+3*_.D65[2]),n=n/(13*r)+9*_.D65[1]/(_.D65[0]+15*_.D65[1]+3*_.D65[2]),o*=100;let l=9*o*s*-1/((s-4)*n-s*n),h=(9*o-15*n*o-n*l)/(3*n);return _.xyz(l,o,h,t.alpha)}static LABtoLCH(t,e=!1,i=!1){let r=e?t.$normalize(!1):t,s=p.Geom.toDegree(p.Geom.boundRadian(a(r[2],r[1])));return _.lch(r[0],o(r[1]*r[1]+r[2]*r[2]),s,t.alpha)}static LCHtoLAB(t,e=!1,i=!1){let r=e?t.$normalize(!1):t,o=p.Geom.toRadian(r[2]);return _.lab(r[0],n(o)*r[1],s(o)*r[1],t.alpha)}}e.Color=_,_.D65=new r.Pt(95.047,100,108.883,1),_.ranges={rgb:new r.Group(new r.Pt(0,255),new r.Pt(0,255),new r.Pt(0,255)),hsl:new r.Group(new r.Pt(0,360),new r.Pt(0,1),new r.Pt(0,1)),hsb:new r.Group(new r.Pt(0,360),new r.Pt(0,1),new r.Pt(0,1)),lab:new r.Group(new r.Pt(0,100),new r.Pt(-128,127),new r.Pt(-128,127)),lch:new r.Group(new r.Pt(0,100),new r.Pt(0,100),new r.Pt(0,360)),luv:new r.Group(new r.Pt(0,100),new r.Pt(-134,220),new r.Pt(-140,122)),xyz:new r.Group(new r.Pt(0,100),new r.Pt(0,100),new r.Pt(0,100))}},"./src/Create.ts":function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Delaunay=e.Noise=e.Create=void 0;const r=i("./src/Pt.ts"),s=i("./src/Op.ts"),n=i("./src/Util.ts"),o=i("./src/Num.ts"),a=i("./src/LinearAlgebra.ts");e.Create=class{static distributeRandom(t,e,i=2){let s=new r.Group;for(let n,o=0;o<e;o++)n=[t.x+Math.random()*t.width],1<i&&n.push(t.y+Math.random()*t.height),2<i&&n.push(t.z+Math.random()*t.depth),s.push(new r.Pt(n));return s}static distributeLinear(t,e){let i=n.Util.iterToArray(t),r=s.Line.subpoints(i,e-2);return r.unshift(i[0]),r.push(i[i.length-1]),r}static gridPts(t,e,i,s=[.5,.5]){if(0===e||0===i)throw new Error("grid columns and rows cannot be 0");let n=t.size.$subtract(1).$divide(e,i),o=n.$multiply(s),a=new r.Group;for(let r=0;r<i;r++)for(let i=0;i<e;i++)a.push(t.topLeft.$add(n.$multiply(i,r)).add(o));return a}static gridCells(t,e,i){if(0===e||0===i)throw new Error("grid columns and rows cannot be 0");let s=t.size.$subtract(1).divide(e,i),n=[];for(let o=0;o<i;o++)for(let i=0;i<e;i++)n.push(new r.Group(t.topLeft.$add(s.$multiply(i,o)),t.topLeft.$add(s.$multiply(i,o).add(s))));return n}static radialPts(t,e,i,s=-n.Const.half_pi){let o=new r.Group,a=n.Const.two_pi/i;for(let n=0;n<i;n++)o.push(new r.Pt(t).toAngle(a*n+s,e,!0));return o}static noisePts(t,e=.01,i=.01,s=0,n=0){let o=Math.random(),a=new r.Group,l=0;for(let r of t){let t=new p(r),h=s&&0<s?u(l/s):l,c=n&&0<n?l%n:l;t.initNoise(e*c,i*h),t.seed(o),a.push(t),l++}return a}static delaunay(t){return _.from(t)}};const l=[[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]],d=[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];class p extends r.Pt{constructor(...t){super(...t),this.perm=[],this._n=new r.Pt(.01,.01),this.perm=d.concat(d)}initNoise(...t){return this._n=new r.Pt(...t),this}step(t=0,e=0){return this._n.add(t,e),this}seed(t){0<t&&1>t&&(t*=65536),256>(t=u(t))&&(t|=t<<8);for(let e,i=0;255>i;i++)e=1&i?d[i]^255&t:d[i]^255&t>>8,this.perm[i]=this.perm[i+256]=e;return this}noise2D(){let t=c(0,u(this._n[0]))%255,e=c(0,u(this._n[1]))%255,i=this._n[0]%255-t,r=this._n[1]%255-e,s=a.Vec.dot(l[(t+this.perm[e])%12],[i,r,0]),n=a.Vec.dot(l[(t+this.perm[e+1])%12],[i,r-1,0]),h=a.Vec.dot(l[(t+1+this.perm[e])%12],[i-1,r,0]),d=a.Vec.dot(l[(t+1+this.perm[e+1])%12],[i-1,r-1,0]),p=t=>t*t*t*(t*(6*t-15)+10),_=p(i);return o.Num.lerp(o.Num.lerp(s,h,_),o.Num.lerp(n,d,_),p(r))}}e.Noise=p;class _ extends r.Group{constructor(){super(...arguments),this._mesh=[]}delaunay(t=!0){if(3>this.length)return[];this._mesh=[];let e=this.length,i=[];for(let t=0;t<e;t++)i[t]=t;i.sort((t,e)=>this[e][0]-this[t][0]);let r=this.slice(),s=this._superTriangle();r=r.concat(s);let o=[this._circum(e,e+1,e+2,s)],a=[],l=[];for(let t=0,e=i.length;t<e;t++){let e=i[t],s=[],h=o.length;for(this._mesh[e]||(this._mesh[e]={});h--;){let t=o[h],i=t.circle[1][0],u=r[e].$subtract(t.circle[0]);0<u[0]&&u[0]*u[0]>i*i?(a.push(t),l.push(t.triangle),o.splice(h,1)):u[0]*u[0]+u[1]*u[1]-i*i>n.Const.epsilon||(s.push(t.i,t.j,t.j,t.k,t.k,t.i),o.splice(h,1))}for(_._dedupe(s),h=s.length;1<h;)o.push(this._circum(s[--h],s[--h],e,!1,r))}for(let t,i=0,r=o.length;i<r;i++)t=o[i],t.i<e&&t.j<e&&t.k<e&&(a.push(t),l.push(t.triangle),this._cache(t));return t?l:a}voronoi(){let t=[];for(let e=0,i=this._mesh.length;e<i;e++)t.push(this.neighborPts(e,!0));return t}mesh(){return this._mesh}neighborPts(t,e=!1){let i=new r.Group,s=this._mesh;for(let e in s[t])s[t].hasOwnProperty(e)&&i.push(s[t][e].circle[0]);return e?o.Geom.sortEdges(i):i}neighbors(t){let e=[],i=this._mesh;for(let r in i[t])i[t].hasOwnProperty(r)&&e.push(i[t][r]);return e}_cache(t){this._mesh[t.i][`${h(t.j,t.k)}-${c(t.j,t.k)}`]=t,this._mesh[t.j][`${h(t.i,t.k)}-${c(t.i,t.k)}`]=t,this._mesh[t.k][`${h(t.i,t.j)}-${c(t.i,t.j)}`]=t}_superTriangle(){let t=this[0],e=this[0];for(let i=1,r=this.length;i<r;i++)t=t.$min(this[i]),e=e.$max(this[i]);let i=e.$subtract(t),s=t.$add(e).divide(2),n=c(i[0],i[1]);return new r.Group(s.$subtract(20*n,n),s.$add(0,20*n),s.$add(20*n,-n))}_triangle(t,e,i,s=this){return new r.Group(s[t],s[e],s[i])}_circum(t,e,i,r,n=this){let o=r||this._triangle(t,e,i,n);return{i:t,j:e,k:i,triangle:o,circle:s.Triangle.circumcircle(o)}}static _dedupe(t){for(let e=t.length;1<e;)for(let i=t[--e],r=t[--e],s=e;1<s;){let n=t[--s],o=t[--s];if(r==o&&i==n||r==n&&i==o){t.splice(e,2),t.splice(s,2);break}}return t}}e.Delaunay=_},"./src/Dom.ts":function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.HTMLForm=e.HTMLSpace=e.DOMSpace=void 0;const r=i("./src/Space.ts"),s=i("./src/Form.ts"),n=i("./src/Util.ts"),o=i("./src/Pt.ts");class a extends r.MultiTouchSpace{constructor(t,e){super(),this.id="domspace",this._autoResize=!0,this._bgcolor="#e1e9f0",this._css={};var i=null;this.id="pts",t instanceof Element?(i=t,this.id="pts_existing_space"):(i=document.querySelector(t),this.id=t.substr(1)),i?(this._canvas=i,this._container=i.parentElement):(this._container=a.createElement("div","pts_container"),this._canvas=a.createElement("div","pts_element"),this._container.appendChild(this._canvas),document.body.appendChild(this._container)),setTimeout(this._ready.bind(this,e),50)}static createElement(t="div",e,i){let r=document.createElement(t);return e&&r.setAttribute("id",e),i&&i.appendChild&&i.appendChild(r),r}_ready(t){if(!this._container)throw new Error(`Cannot initiate #${this.id} element`);for(let t in this._isReady=!0,this._resizeHandler(null),this.clear(this._bgcolor),this._canvas.dispatchEvent(new Event("ready")),this.players)this.players.hasOwnProperty(t)&&this.players[t].start&&this.players[t].start(this.bound.clone(),this);this._pointer=this.center,this.refresh(!1),t&&t(this.bound,this._canvas)}setup(t){return t.bgcolor&&(this._bgcolor=t.bgcolor),this.autoResize=null!=t.resize&&t.resize,this}getForm(){return null}set autoResize(t){this._autoResize=t,t?window.addEventListener("resize",this._resizeHandler.bind(this)):(delete this._css.width,delete this._css.height,window.removeEventListener("resize",this._resizeHandler.bind(this)))}get autoResize(){return this._autoResize}resize(t,e){for(let i in this.bound=t,this.styles({width:t.width+"px",height:t.height+"px"},!0),this.players)if(this.players.hasOwnProperty(i)){let t=this.players[i];t.resize&&t.resize(this.bound,e)}return this}_resizeHandler(t){let e=o.Bound.fromBoundingRect(this._container.getBoundingClientRect());this._autoResize?this.styles({width:"100%",height:"100%"},!0):this.styles({width:e.width+"px",height:e.height+"px"},!0),this.resize(e,t)}get element(){return this._canvas}get parent(){return this._container}get ready(){return this._isReady}clear(t){return t&&(this.background=t),this._canvas.innerHTML="",this}set background(t){this._bgcolor=t,this._container.style.backgroundColor=this._bgcolor}get background(){return this._bgcolor}style(t,e,i=!1){return this._css[t]=e,i&&(this._canvas.style[t]=e),this}styles(t,e=!1){for(let i in t)t.hasOwnProperty(i)&&this.style(i,t[i],e);return this}static setAttr(t,e){for(let i in e)e.hasOwnProperty(i)&&t.setAttribute(i,e[i]);return t}static getInlineStyles(t){let e="";for(let i in t)t.hasOwnProperty(i)&&t[i]&&(e+=`${i}: ${t[i]}; `);return e}dispose(){return window.removeEventListener("resize",this._resizeHandler.bind(this)),this.stop(),this.removeAll(),this}}e.DOMSpace=a;class l extends a{getForm(){return new h(this)}static htmlElement(t,e,i,r=!0){if(!t||!t.appendChild)throw new Error("parent is not a valid DOM element");let s=document.querySelector("#"+i);return s||(s=document.createElement(e),s.setAttribute("id",i),r&&s.setAttribute("class",i.substring(0,i.indexOf("-"))),t.appendChild(s)),s}remove(t){return this._container.querySelectorAll("."+h.scopeID(t)).forEach(t=>{t.parentNode.removeChild(t)}),super.remove(t)}removeAll(){return this._container.innerHTML="",super.removeAll()}}e.HTMLSpace=l;class h extends s.VisualForm{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._space=t,this._space.add({start:()=>{this._ctx.group=this._space.element,this._ctx.groupID="pts_dom_"+h.groupID++,this._ctx.style=Object.assign({},this._style),this._ready=!0}})}get space(){return this._space}styleTo(t,e,i=""){if(void 0===this._ctx.style[t])throw new Error(t+" style property doesn't exist");this._ctx.style[t]=`${e}${i}`}alpha(t){return this.styleTo("opacity",t),this}fill(t){return"boolean"==typeof t?(this.styleTo("filled",t),!t&&this.styleTo("background","transparent")):(this.styleTo("filled",!0),this.styleTo("background",t)),this}stroke(t,e){return"boolean"==typeof t?(this.styleTo("stroked",t),!t&&this.styleTo("border-width",0)):(this.styleTo("stroked",!0),this.styleTo("border-color",t),this.styleTo("border-width",(e||1)+"px")),this}fillText(t){return this.styleTo("color",t),this}cls(t){return this._ctx.currentClass="boolean"==typeof t?"":t,this}font(t,e,i,r,s){return"number"==typeof t?(this._font.size=t,s&&(this._font.face=s),e&&(this._font.weight=e),i&&(this._font.style=i),r&&(this._font.lineHeight=r)):this._font=t,this._ctx.style.font=this._font.value,this}reset(){return this._ctx.style=Object.assign({},this._style),this._font=new s.Font(10,"sans-serif"),this._ctx.style.font=this._font.value,this}updateScope(t,e){return this._ctx.group=e,this._ctx.groupID=t,this._ctx.groupCount=0,this.nextID(),this._ctx}scope(t){if(!t||null==t.animateID)throw new Error("item not defined or not yet added to Space");return this.updateScope(h.scopeID(t),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-"+h.domID++}static scopeID(t){return"item-"+t.animateID}static style(t,e){let i=[];for(let t in e.filled||i.push("background: none"),e.stroked||i.push("border: none"),e)if(e.hasOwnProperty(t)&&"filled"!=t&&"stroked"!=t){let r=e[t];if(r){if(!e.filled&&0===t.indexOf("background"))continue;if(!e.stroked&&0===t.indexOf("border-width"))continue;i.push(`${t}: ${r}`)}}return l.setAttr(t,{style:i.join(";")})}static rectStyle(t,e,i){return t.style.left=e[0]+"px",t.style.top=e[1]+"px",t.style.width=i[0]+"px",t.style.height=i[1]+"px",t}static textStyle(t,e){return t.style.left=e[0]+"px",t.style.top=e[1]+"px",t}static point(t,e,i=5,r="square"){return"circle"===r?h.circle(t,e,i):h.square(t,e,i)}point(t,e=5,i="square"){return this.nextID(),"circle"==i&&this.styleTo("border-radius","100%"),h.point(this._ctx,t,e,i),this}static circle(t,e,i=10){let r=l.htmlElement(t.group,"div",h.getID(t));return l.setAttr(r,{class:"pts-form pts-circle "+t.currentClass}),h.rectStyle(t,new o.Pt(e).$subtract(i),new o.Pt(2*i,2*i)),h.style(r,t.style),r}circle(t){return this.nextID(),this.styleTo("border-radius","100%"),h.circle(this._ctx,t[0],t[1][0]),this}static square(t,e,i){let r=l.htmlElement(t.group,"div",h.getID(t));return l.setAttr(r,{class:"pts-form pts-square "+t.currentClass}),h.rectStyle(t,new o.Pt(e).$subtract(i),new o.Pt(2*i,2*i)),h.style(r,t.style),r}square(t,e){return this.nextID(),h.square(this._ctx,t,e),this}static rect(t,e){let i=n.Util.iterToArray(e);if(n.Util.arrayCheck(i)){let e=l.htmlElement(t.group,"div",h.getID(t));return l.setAttr(e,{class:"pts-form pts-rect "+t.currentClass}),h.rectStyle(t,i[0],i[1]),h.style(e,t.style),e}}rect(t){return this.nextID(),this.styleTo("border-radius","0"),h.rect(this._ctx,t),this}static text(t,e,i){let r=l.htmlElement(t.group,"div",h.getID(t));return l.setAttr(r,{class:"pts-form pts-text "+t.currentClass}),r.textContent=i,h.textStyle(t,e),h.style(r,t.style),r}text(t,e){return this.nextID(),h.text(this._ctx,t,e),this}log(t){return this.fill("#000").stroke("#fff",.5).text([10,14],t),this}arc(){return n.Util.warn("arc is not implemented in HTMLForm"),this}line(){return n.Util.warn("line is not implemented in HTMLForm"),this}polygon(){return n.Util.warn("polygon is not implemented in HTMLForm"),this}}e.HTMLForm=h,h.groupID=0,h.domID=0},"./src/Form.ts":function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Font=e.VisualForm=e.Form=void 0;class i{constructor(){this._ready=!1}get ready(){return this._ready}}e.Form=i,e.VisualForm=class extends i{constructor(){super(...arguments),this._filled=!0,this._stroked=!0,this._font=new r(14,"sans-serif")}get filled(){return this._filled}set filled(t){this._filled=t}get stroked(){return this._stroked}set stroked(t){this._stroked=t}get currentFont(){return this._font}_multiple(t,e,...i){if(!t)return this;for(let r=0,s=t.length;r<s;r++)this[e](t[r],...i);return this}alpha(){return this}fill(){return this}fillOnly(t){return this.stroke(!1),this.fill(t)}stroke(){return this}strokeOnly(t,e,i,r){return this.fill(!1),this.stroke(t,e,i,r)}points(t,e,i){if(t){for(let r=0,s=t.length;r<s;r++)this.point(t[r],e,i);return this}}circles(t){return this._multiple(t,"circle")}squares(t){return this._multiple(t,"square")}lines(t){return this._multiple(t,"line")}polygons(t){return this._multiple(t,"polygon")}rects(t){return this._multiple(t,"rect")}};class r{constructor(t=12,e="sans-serif",i="",r="",s=1.5){this.size=t,this.face=e,this.style=r,this.weight=i,this.lineHeight=s}get value(){return`${this.style} ${this.weight} ${this.size}px/${this.lineHeight} ${this.face}`}toString(){return this.value}}e.Font=r},"./src/Image.ts":function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Img=void 0;const r=i("./src/Pt.ts");class s{constructor(t=!1,e=1,i){this._scale=1,this._loaded=!1,this._editable=t,this._scale=e,this._img=new Image,i&&(this._img.crossOrigin="Anonymous")}static load(t,e=!1,i=1,r){let n=new s(e,i);return n.load(t).then(t=>{r&&r(t)}),n}load(t){return new Promise((e,i)=>{this._img.src=t,this._img.onload=()=>{this._editable&&(!this._cv&&(this._cv=document.createElement("canvas")),this._drawToScale(this._scale,this._img),this._data=this._ctx.getImageData(0,0,this._cv.width,this._cv.height)),this._loaded=!0,e(this)},this._img.onerror=t=>{i(t)}})}_drawToScale(t,e){const i="number"==typeof t?[t,t]:t,r=e.width,s=e.height;this._cv.width=r*i[0],this._cv.height=s*i[1],this._ctx=this._cv.getContext("2d"),e&&this._ctx.drawImage(e,0,0,r,s,0,0,this._cv.width,this._cv.height)}bitmap(t){const e=t?t[0]:this._cv.width,i=t?t[1]:this._cv.height;return createImageBitmap(this._cv,0,0,e,i)}sync(){1===this._scale?this._img.src=this.toBase64():this.bitmap().then(t=>{this._drawToScale(1/this._scale,t),this.load(this.toBase64())})}pixel(t,e=!0){const i="number"==typeof e?e:e?this._scale:1;return s.getPixel(this._data,[t[0]*i,t[1]*i])}static getPixel(t,e){const i=new r.Pt(0,0,0,0);if(e[0]>=t.width||e[1]>=t.height)return i;const s=u(e[1])*(4*t.width)+4*u(e[0]),n=t.data;return s>=n.length-4?i:new r.Pt(n[s],n[s+1],n[s+2],n[s+3])}resize(t,e=!1){let i=e?t:[t[0]/this._img.naturalWidth,t[1]/this._img.naturalHeight];return this._drawToScale(i,this._img),this._data=this._ctx.getImageData(0,0,this._cv.width,this._cv.height),this}crop(t){let e=t.topLeft.scale(this._scale),i=t.size.scale(this._scale);return this._ctx.getImageData(e.x,e.y,i.x,i.y)}filter(t){return this._ctx.filter=t,this._ctx.drawImage(this._cv,0,0),this._ctx.filter="none",this}cleanup(){this._cv&&this._cv.remove(),this._img&&this._img.remove(),this._data=null}static fromBlob(t,e=!1,i=1){let r=URL.createObjectURL(t);return new s(e,i).load(r)}static imageDataToBlob(t){return new Promise((function(e){let i=document.createElement("canvas");i.width=t.width,i.height=t.height,i.getContext("2d").putImageData(t,0,0),i.toBlob(t=>{e(t),i.remove()})}))}toBase64(){return this._cv.toDataURL()}toBlob(){return new Promise(t=>{this._cv.toBlob(e=>t(e))})}get current(){return this._editable?this._cv:this._img}get image(){return this._img}get canvas(){return this._cv}get data(){return this._data}get ctx(){return this._ctx}get loaded(){return this._loaded}get pixelScale(){return this._scale}get imageSize(){return new r.Pt(this._img.width,this._img.height)}get canvasSize(){return new r.Pt(this._cv.width,this._cv.height)}}e.Img=s},"./src/LinearAlgebra.ts":function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Mat=e.Vec=void 0;const l=a("./src/Pt.ts"),u=a("./src/Op.ts");class d{static add(t,e){if("number"==typeof e)for(let i=0,r=t.length;i<r;i++)t[i]+=e;else for(let i=0,r=t.length;i<r;i++)t[i]+=e[i]||0;return t}static subtract(t,e){if("number"==typeof e)for(let i=0,r=t.length;i<r;i++)t[i]-=e;else for(let i=0,r=t.length;i<r;i++)t[i]-=e[i]||0;return t}static multiply(t,e){if("number"==typeof e)for(let i=0,r=t.length;i<r;i++)t[i]*=e;else{if(t.length!=e.length)throw new Error(`Cannot do element-wise multiply since the array lengths don't match: ${t.toString()} multiply-with ${e.toString()}`);for(let i=0,r=t.length;i<r;i++)t[i]*=e[i]}return t}static divide(t,e){if("number"==typeof e){if(0===e)throw new Error("Cannot divide by zero");for(let i=0,r=t.length;i<r;i++)t[i]/=e}else{if(t.length!=e.length)throw new Error(`Cannot do element-wise divide since the array lengths don't match. ${t.toString()} divide-by ${e.toString()}`);for(let i=0,r=t.length;i<r;i++)t[i]/=e[i]}return t}static dot(t,e){if(t.length!=e.length)throw new Error("Array lengths don't match");let i=0;for(let r=0,s=t.length;r<s;r++)i+=t[r]*e[r];return i}static cross2D(t,e){return t[0]*e[1]-t[1]*e[0]}static cross(t,e){return new l.Pt(t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0])}static magnitude(t){return o(d.dot(t,t))}static unit(t,e){let i=void 0===e?d.magnitude(t):e;return 0===i?l.Pt.make(t.length):d.divide(t,i)}static abs(t){return d.map(t,Math.abs)}static floor(t){return d.map(t,Math.floor)}static ceil(t){return d.map(t,Math.ceil)}static round(t){return d.map(t,Math.round)}static max(t){let e=r,i=0;for(let r=0,s=t.length;r<s;r++)e=c(e,t[r]),e===t[r]&&(i=r);return{value:e,index:i}}static min(t){let e=i,r=0;for(let i=0,s=t.length;i<s;i++)e=h(e,t[i]),e===t[i]&&(r=i);return{value:e,index:r}}static sum(t){let e=0;for(let i=0,r=t.length;i<r;i++)e+=t[i];return e}static map(t,e){for(let i=0,r=t.length;i<r;i++)t[i]=e(t[i],i,t);return t}}e.Vec=d;class p{static add(t,e){if("number"!=typeof e){if(t[0].length!=e[0].length)throw new Error("Cannot add matrix if rows' and columns' size don't match.");if(t.length!=e.length)throw new Error("Cannot add matrix if rows' and columns' size don't match.")}let i=new l.Group;for(let r=0,s=t.length;r<s;r++)i.push(t[r].$add("number"==typeof e?e:e[r]));return i}static multiply(t,e,i=!1,r=!1){let s=new l.Group;if("number"==typeof e)for(let i=0,r=t.length;i<r;i++)s.push(t[i].$multiply(e));else if(r){if(t.length!=e.length)throw new Error("Cannot multiply matrix element-wise because the matrices' sizes don't match.");for(let i=0,r=t.length;i<r;i++)s.push(t[i].$multiply(e[i]))}else{if(!i&&t[0].length!=e.length)throw new Error("Cannot multiply matrix if rows in matrix-a don't match columns in matrix-b.");if(i&&t[0].length!=e[0].length)throw new Error("Cannot multiply matrix if transposed and the columns in both matrices don't match.");i||(e=p.transpose(e));for(let i,r=0,n=t.length;r<n;r++){i=l.Pt.make(e.length,0);for(let s=0,n=e.length;s<n;s++)i[s]=d.dot(t[r],e[s]);s.push(i)}}return s}static zipSlice(t,e,i=!1){let r=[];for(let s=0,n=t.length;s<n;s++){if(t[s].length-1<e&&!1===i)throw`Index ${e} is out of bounds`;r.push(t[s][e]||i)}return new l.Pt(r)}static zip(t,e=!1,i=!1){let r=new l.Group,s=i?t.reduce((t,e)=>c(t,e.length),0):t[0].length;for(let i=0;i<s;i++)r.push(p.zipSlice(t,i,e));return r}static transpose(t,e=!1,i=!1){return p.zip(t,e,i)}static transform2D(t,e){let i=t[0]*e[0][0]+t[1]*e[1][0]+e[2][0],r=t[0]*e[0][1]+t[1]*e[1][1]+e[2][1];return new l.Pt(i,r)}static scale2DMatrix(t,e){return new l.Group(new l.Pt(t,0,0),new l.Pt(0,e,0),new l.Pt(0,0,1))}static rotate2DMatrix(t,e){return new l.Group(new l.Pt(t,e,0),new l.Pt(-e,t,0),new l.Pt(0,0,1))}static shear2DMatrix(t,e){return new l.Group(new l.Pt(1,t,0),new l.Pt(e,1,0),new l.Pt(0,0,1))}static translate2DMatrix(t,e){return new l.Group(new l.Pt(1,0,0),new l.Pt(0,1,0),new l.Pt(t,e,1))}static scaleAt2DMatrix(t,e,i){let r=p.scale2DMatrix(t,e);return r[2][0]=-i[0]*t+i[0],r[2][1]=-i[1]*e+i[1],r}static rotateAt2DMatrix(t,e,i){let r=p.rotate2DMatrix(t,e);return r[2][0]=i[0]*(1-t)+i[1]*e,r[2][1]=i[1]*(1-t)-i[0]*e,r}static shearAt2DMatrix(t,e,i){let r=p.shear2DMatrix(t,e);return r[2][0]=-i[1]*e,r[2][1]=-i[0]*t,r}static reflectAt2DMatrix(t,e){let i=u.Line.intercept(t,e);if(null==i)return[new l.Pt([-1,0,0]),new l.Pt([0,1,0]),new l.Pt([t[0]+e[0],0,1])];{let t=i.yi,e=2*Math.atan(i.slope),r=n(e),o=s(e);return[new l.Pt([r,o,0]),new l.Pt([o,-r,0]),new l.Pt([-t*o,t+t*r,1])]}}}e.Mat=p},"./src/Num.ts":function(i,r,a){"use strict";var d=Math.exp;Object.defineProperty(r,"__esModule",{value:!0}),r.Range=r.Shaping=r.Geom=r.Num=void 0;const p=a("./src/Util.ts"),_=a("./src/Op.ts"),g=a("./src/Pt.ts"),f=a("./src/LinearAlgebra.ts");class m{static equals(t,i,r=1e-5){return e(t-i)<r}static lerp(t,e,i){return(1-i)*t+i*e}static clamp(t,e,i){return c(e,h(i,t))}static boundValue(t,i,r){let s=e(r-i),n=t%s;return n>r?n-=s:n<i&&(n+=s),n}static within(t,e,i){return t>=h(e,i)&&t<=c(e,i)}static randomRange(t,e=0){let i=t>e?t-e:e-t;return t+Math.random()*i}static randomPt(t,e){let i=new g.Pt(t.length),r=e?f.Vec.subtract(e,t):t,s=e?t:new g.Pt(t.length).fill(0);for(let t=0,e=i.length;t<e;t++)i[t]=Math.random()*r[t]+s[t];return i}static normalizeValue(t,e,i){let r=h(e,i);return(t-r)/(c(e,i)-r)}static sum(t){let e=p.Util.iterToArray(t),i=new g.Pt(e[0]);for(let t=1,r=e.length;t<r;t++)f.Vec.add(i,e[t]);return i}static average(t){let e=p.Util.iterToArray(t);return m.sum(e).divide(e.length)}static cycle(t,e=w.sineInOut){return e(.5<t?2-2*t:2*t)}static mapToRange(t,e,i,r,s){if(e==i)throw new Error("[currMin, currMax] must define a range that is not zero");let n=h(r,s),o=c(r,s);return m.normalizeValue(t,e,i)*(o-n)+n}}r.Num=m;class y{static boundAngle(t){return m.boundValue(t,0,360)}static boundRadian(t){return m.boundValue(t,0,p.Const.two_pi)}static toRadian(t){return t*p.Const.deg_to_rad}static toDegree(t){return t*p.Const.rad_to_deg}static boundingBox(t){let e,i;for(let r of t)null==e?(e=r.clone(),i=r.clone()):(e=e.$min(r),i=i.$max(r));return new g.Group(e,i)}static centroid(t){return m.average(t)}static anchor(t,e=0,i="to"){let r="to"==i?"subtract":"add",s=0;for(let i of t)"number"==typeof e?e!==s&&i[r](t[e]):i[r](e),s++}static interpolate(t,e,i=.5){let r=h(t.length,e.length),s=g.Pt.make(r);for(let n=0;n<r;n++)s[n]=t[n]*(1-i)+e[n]*i;return s}static perpendicular(t,e=p.Const.xy){let i=e[1],r=e[0],s=new g.Pt(t),n=new g.Pt(s);n[r]=-s[i],n[i]=s[r];let o=new g.Pt(s);return o[r]=s[i],o[i]=-s[r],new g.Group(n,o)}static isPerpendicular(t,e){return 0===new g.Pt(t).dot(e)}static withinBound(t,e,i){for(let r=0,s=h(t.length,e.length,i.length);r<s;r++)if(!m.within(t[r],e[r],i[r]))return!1;return!0}static sortEdges(t){let e=p.Util.iterToArray(t),i=y.boundingBox(e),r=i[1].add(i[0]).divide(2);return e.sort((t,e)=>{if(2>t.length||2>e.length)throw new Error("Pt dimension cannot be less than 2");let i=t.$subtract(r),s=e.$subtract(r);if(0<=i[0]&&0>s[0])return 1;if(0>i[0]&&0<=s[0])return-1;if(0==i[0]&&0==s[0])return 0<=i[1]||0<=s[1]?i[1]>s[1]?1:-1:s[1]>i[1]?1:-1;let n=i.$cross2D(s);return 0>n?1:0<n?-1:i[0]*i[0]+i[1]*i[1]>s[0]*s[0]+s[1]*s[1]?1:-1})}static scale(t,e,i){let r=p.Util.iterToArray(void 0!==t[0]&&"number"==typeof t[0]?[t]:t),s="number"==typeof e?g.Pt.make(r[0].length,e):e;i||(i=g.Pt.make(r[0].length,0));for(let t,e=0,n=r.length;e<n;e++){t=r[e];for(let e=0,r=t.length;e<r;e++)t[e]=i&&i[e]?i[e]+(t[e]-i[e])*s[e]:t[e]*s[e]}return y}static rotate2D(t,e,i,r){let o=p.Util.iterToArray(void 0!==t[0]&&"number"==typeof t[0]?[t]:t),a=i?f.Mat.rotateAt2DMatrix:f.Mat.rotate2DMatrix;i||(i=g.Pt.make(o[0].length,0));let l=n(e),h=s(e);for(let t,e=0,s=o.length;e<s;e++)if(t=r?o[e].$take(r):o[e],t.to(f.Mat.transform2D(t,a(l,h,i))),r)for(let i=0;i<r.length;i++)o[e][r[i]]=t[i];return y}static shear2D(t,e,i,r){var s=Math.tan;let n=p.Util.iterToArray(void 0!==t[0]&&"number"==typeof t[0]?[t]:t),o="number"==typeof e?[e,e]:e;i||(i=g.Pt.make(n[0].length,0));let a=i?f.Mat.shearAt2DMatrix:f.Mat.shear2DMatrix,l=s(o[0]),h=s(o[1]);for(let t,e=0,s=n.length;e<s;e++)if(t=r?n[e].$take(r):n[e],t.to(f.Mat.transform2D(t,a(l,h,i))),r)for(let i=0;i<r.length;i++)n[e][r[i]]=t[i];return y}static reflect2D(t,e,i){let r=p.Util.iterToArray(void 0!==t[0]&&"number"==typeof t[0]?[t]:t),s=p.Util.iterToArray(e),n=f.Mat.reflectAt2DMatrix(s[0],s[1]);for(let t,e=0,s=r.length;e<s;e++)if(t=i?r[e].$take(i):r[e],t.to(f.Mat.transform2D(t,n)),i)for(let s=0;s<i.length;s++)r[e][i[s]]=t[s];return y}static cosTable(){let e=new Float64Array(360);for(let i=0;360>i;i++)e[i]=n(i*t/180);return{table:e,cos:t=>e[u(y.boundAngle(y.toDegree(t)))]}}static sinTable(){let e=new Float64Array(360);for(let i=0;360>i;i++)e[i]=s(i*t/180);return{table:e,sin:t=>e[u(y.boundAngle(y.toDegree(t)))]}}}r.Geom=y;class w{static linear(t,e=1){return e*t}static quadraticIn(t,e=1){return e*t*t}static quadraticOut(t,e=1){return-e*t*(t-2)}static quadraticInOut(t,e=1){let i=2*t;return.5>t?e/2*t*t*4:-e/2*((i-1)*(i-3)-1)}static cubicIn(t,e=1){return e*t*t*t}static cubicOut(t,e=1){let i=t-1;return e*(i*i*i+1)}static cubicInOut(t,e=1){let i=2*t;return.5>t?e/2*i*i*i:e/2*((i-2)*(i-2)*(i-2)+2)}static exponentialIn(t,e=1,i=.25){return e*l(t,1/i)}static exponentialOut(t,e=1,i=.25){return e*l(t,i)}static sineIn(t,e=1){return-e*n(t*p.Const.half_pi)+e}static sineOut(t,e=1){return e*s(t*p.Const.half_pi)}static sineInOut(e,i=1){return-i/2*(n(t*e)-1)}static cosineApprox(t,e=1){let i=t*t,r=i*i;return e*(r*i*4/9-17*r/9+22*i/9)}static circularIn(t,e=1){return-e*(o(1-t*t)-1)}static circularOut(t,e=1){let i=t-1;return e*o(1-i*i)}static circularInOut(t,e=1){let i=2*t;return.5>t?-e/2*(o(1-i*i)-1):e/2*(o(1-(i-2)*(i-2))+1)}static elasticIn(t,e=1,i=.7){let r=t-1,n=i/p.Const.two_pi*1.5707963267948966;return e*(-l(2,10*r)*s((r-n)*p.Const.two_pi/i))}static elasticOut(t,e=1,i=.7){let r=i/p.Const.two_pi*1.5707963267948966;return e*(l(2,-10*t)*s((t-r)*p.Const.two_pi/i))+e}static elasticInOut(t,e=1,i=.6){let r=2*t,n=i/p.Const.two_pi*1.5707963267948966;return.5>t?(r-=1,e*(l(2,10*r)*s((r-n)*p.Const.two_pi/i)*-.5)):(r-=1,e*(l(2,-10*r)*s((r-n)*p.Const.two_pi/i)*.5)+e)}static bounceIn(t,e=1){return e-w.bounceOut(1-t,e)}static bounceOut(t,e=1){return t<1/2.75?e*(7.5625*t*t):t<2/2.75?e*(7.5625*(t-=1.5/2.75)*t+.75):t<2.5/2.75?e*(7.5625*(t-=2.25/2.75)*t+.9375):e*(7.5625*(t-=2.625/2.75)*t+.984375)}static bounceInOut(t,e=1){return.5>t?w.bounceIn(2*t,e)/2:w.bounceOut(2*t-1,e)/2+e/2}static sigmoid(t,e=1,i=10){return e/(1+d(-i*(t-.5)))}static logSigmoid(t,e=1,i=.7){i=c(p.Const.epsilon,h(1-p.Const.epsilon,i));let r=1/(1+d((t-.5)*(i=1/(1-i))*-2)),s=1/(1+d(i));return e*(r-s)/(1/(1+d(-i))-s)}static seat(t,e=1,i=.5){return.5>t?e*l(2*t,1-i)/2:e*(1-l(2*(1-t),1-i)/2)}static quadraticBezier(t,e=1,i=[.05,.95]){let r="number"==typeof i?i:i[0],s="number"==typeof i?.5:i[1],n=1-2*r;0===n&&(n=p.Const.epsilon);let a=(o(r*r+n*t)-r)/n;return e*(a*a*(1-2*s)+2*s*a)}static cubicBezier(t,e=1,i=[.1,.7],r=[.9,.2]){let s=new g.Group(new g.Pt(0,0),new g.Pt(i),new g.Pt(r),new g.Pt(1,1));return e*_.Curve.bezierStep(new g.Pt(t*t*t,t*t,t,1),_.Curve.controlPoints(s)).y}static quadraticTarget(t,e=1,i=[.2,.35]){let r=h(1-p.Const.epsilon,c(p.Const.epsilon,i[0])),s=h(1,c(0,i[1])),n=(1-s)/(1-r)-s/r;return e*h(1,c(0,n*(t*t)-(n*(r*r)-s)/r*t))}static cliff(t,e=1,i=.5){return t>i?e:0}static step(t,e,i,r,...s){let n=1/e;return t(u(i/n)*n,r,...s)}}r.Shaping=w,r.Range=class{constructor(t){this._dims=0,this._source=g.Group.fromPtArray(t),this.calc()}get max(){return this._max.clone()}get min(){return this._min.clone()}get magnitude(){return this._mag.clone()}calc(){if(this._source){let t=this._source[0].length;this._dims=t;let e=new g.Pt(t),i=new g.Pt(t),r=new g.Pt(t);for(let s=0;s<t;s++){e[s]=p.Const.min,i[s]=p.Const.max,r[s]=0;let t=this._source.zipSlice(s);for(let n=0,o=t.length;n<o;n++)e[s]=c(e[s],t[n]),i[s]=h(i[s],t[n]),r[s]=e[s]-i[s]}return this._max=e,this._min=i,this._mag=r,this}}mapTo(t,e,i){let r=new g.Group;for(let s=0,n=this._source.length;s<n;s++){let n=this._source[s],o=new g.Pt(this._dims);for(let r=0;r<this._dims;r++)o[r]=i&&i[r]?n[r]:m.mapToRange(n[r],this._min[r],this._max[r],t,e);r.push(o)}return r}append(t,e=!0){let i=p.Util.iterToArray(t);if(i[0].length!==this._dims)throw new Error(`Dimensions don't match. ${this._dims} dimensions in Range and ${i[0].length} provided in parameter. `);return this._source=this._source.concat(i),e&&this.calc(),this}ticks(t){let e=new g.Group;for(let i,r=0;r<=t;r++){i=new g.Pt(this._dims);for(let e=0,s=this._max.length;e<s;e++)i[e]=m.lerp(this._min[e],this._max[e],r/t);e.push(i)}return e}}},"./src/Op.ts":function(r,a,l){"use strict";var u=Number.MAX_SAFE_INTEGER;Object.defineProperty(a,"__esModule",{value:!0}),a.Curve=a.Polygon=a.Triangle=a.Circle=a.Rectangle=a.Line=void 0;const d=l("./src/Util.ts"),p=l("./src/Num.ts"),_=l("./src/Pt.ts"),g=l("./src/LinearAlgebra.ts");let f=(t,e="expected")=>d.Util.warn("Group's length is less than "+e,t);class m{static fromAngle(t,e,i){let r=new _.Group(new _.Pt(t),new _.Pt(t));return r[1].toAngle(e,i,!0),r}static slope(t,e){return 0==e[0]-t[0]?void 0:(e[1]-t[1])/(e[0]-t[0])}static intercept(t,e){if(0!=e[0]-t[0]){let i=(e[1]-t[1])/(e[0]-t[0]),r=t[1]-i*t[0];return{slope:i,yi:r,xi:0==i?void 0:-r/i}}}static sideOfPt2D(t,e){let i=d.Util.iterToArray(t);return(i[1][0]-i[0][0])*(e[1]-i[0][1])-(e[0]-i[0][0])*(i[1][1]-i[0][1])}static collinear(t,e,i,r=.01){let s=new _.Pt(0,0,0).to(t).$subtract(e),n=new _.Pt(0,0,0).to(t).$subtract(i);return s.$cross(n).divide(1e3).equals(new _.Pt(0,0,0),r)}static magnitude(t){let e=d.Util.iterToArray(t);return 2<=e.length?e[1].$subtract(e[0]).magnitude():0}static magnitudeSq(t){let e=d.Util.iterToArray(t);return 2<=e.length?e[1].$subtract(e[0]).magnitudeSq():0}static perpendicularFromPt(t,e,i=!1){let r=d.Util.iterToArray(t);if(!r[0].equals(r[1])){let t=r[0].$subtract(r[1]),s=r[1].$subtract(e),n=s.$subtract(t.$project(s));return i?n:n.$add(e)}}static distanceFromPt(t,e){let i=d.Util.iterToArray(t),r=m.perpendicularFromPt(i,e,!0);return r?r.magnitude():i[0].$subtract(e).magnitude()}static intersectRay2D(t,e){let i=d.Util.iterToArray(t),r=d.Util.iterToArray(e),s=m.intercept(i[0],i[1]),n=m.intercept(r[0],r[1]),o=i[0],a=r[0];if(null==s){if(null==n)return;let t=-n.slope*(a[0]-o[0])+a[1];return new _.Pt(o[0],t)}if(null==n){let t=-s.slope*(o[0]-a[0])+o[1];return new _.Pt(a[0],t)}if(n.slope!=s.slope){let t=(s.slope*o[0]-n.slope*a[0]+a[1]-o[1])/(s.slope-n.slope),e=s.slope*(t-o[0])+o[1];return new _.Pt(t,e)}return s.yi==n.yi?new _.Pt(o[0],o[1]):void 0}static intersectLine2D(t,e){let i=d.Util.iterToArray(t),r=d.Util.iterToArray(e),s=m.intersectRay2D(i,r);return s&&p.Geom.withinBound(s,i[0],i[1])&&p.Geom.withinBound(s,r[0],r[1])?s:void 0}static intersectLineWithRay2D(t,e){let i=d.Util.iterToArray(t),r=d.Util.iterToArray(e),s=m.intersectRay2D(i,r);return s&&p.Geom.withinBound(s,i[0],i[1])?s:void 0}static intersectPolygon2D(t,e,i=!1){let r=d.Util.iterToArray(t),s=d.Util.iterToArray(e),n=i?m.intersectLineWithRay2D:m.intersectLine2D,o=new _.Group;for(let t=0,e=s.length;t<e;t++){let i=t===e-1?0:t+1,a=n([s[t],s[i]],r);a&&o.push(a)}return 0<o.length?o:void 0}static intersectLines2D(t,e,i=!1){let r=new _.Group,s=i?m.intersectLineWithRay2D:m.intersectLine2D;for(let i of t)for(let t of e){let e=s(i,t);e&&r.push(e)}return r}static intersectGridWithRay2D(t,e){let i=d.Util.iterToArray(t),r=m.intercept(new _.Pt(i[0]).subtract(e),new _.Pt(i[1]).subtract(e)),s=new _.Group;return r&&r.xi&&s.push(new _.Pt(e[0]+r.xi,e[1])),r&&r.yi&&s.push(new _.Pt(e[0],e[1]+r.yi)),s}static intersectGridWithLine2D(t,e){let i=d.Util.iterToArray(t),r=m.intersectGridWithRay2D(i,e),s=new _.Group;for(let t=0,e=r.length;t<e;t++)p.Geom.withinBound(r[t],i[0],i[1])&&s.push(r[t]);return s}static intersectRect2D(t,e){let i=d.Util.iterToArray(t),r=d.Util.iterToArray(e),s=p.Geom.boundingBox(_.Group.fromPtArray(i));return y.hasIntersectRect2D(s,r)?m.intersectLines2D([i],y.sides(r)):new _.Group}static subpoints(t,e){let i=d.Util.iterToArray(t),r=new _.Group;for(let t=1;t<=e;t++)r.push(p.Geom.interpolate(i[0],i[1],t/(e+1)));return r}static crop(t,i,r=0,s=!0){let n=d.Util.iterToArray(t),o=n[0===r?1:0].$subtract(n[r]);if(0===o[0]||0===i[0])return n[r];if(s){let t=o.unit().multiply(i[1]);return n[r].$add(t)}{let t=y.fromCenter(n[r],i),s=y.sides(t),a=0;return a=e(o[1]/o[0])>e(i[1]/i[0])?0>o[1]?0:2:0>o[0]?3:1,m.intersectRay2D(s[a],n)}}static marker(t,e,i="arrow",r=!0){let s=d.Util.iterToArray(t),n=r?1:0,o=s[r?0:1].$subtract(s[n]);if(0===o.magnitudeSq())return new _.Group;o.unit();let a=p.Geom.perpendicular(o).multiply(e[0]).add(s[n]);return"arrow"==i?(a.add(o.$multiply(e[1])),new _.Group(s[n],a[0],a[1])):new _.Group(a[0],a[1])}static toRect(t){let e=d.Util.iterToArray(t);return new _.Group(e[0].$min(e[1]),e[0].$max(e[1]))}}a.Line=m;class y{static from(t,e,i){return y.fromTopLeft(t,e,i)}static fromTopLeft(t,e,i){let r="number"==typeof e?[e,i||e]:e;return new _.Group(new _.Pt(t),new _.Pt(t).add(r))}static fromCenter(t,e,i){let r="number"==typeof e?[e/2,(i||e)/2]:new _.Pt(e).divide(2);return new _.Group(new _.Pt(t).subtract(r),new _.Pt(t).add(r))}static toCircle(t,e=!0){return w.fromRect(t,e)}static toSquare(t,e=!1){let i=d.Util.iterToArray(t),r=y.size(i),s=e?r.maxValue().value:r.minValue().value;return y.fromCenter(y.center(i),s,s)}static size(t){let e=d.Util.iterToArray(t);return e[0].$max(e[1]).subtract(e[0].$min(e[1]))}static center(t){let e=d.Util.iterToArray(t),i=e[0].$min(e[1]),r=e[0].$max(e[1]);return i.add(r.$subtract(i).divide(2))}static corners(t){let e=d.Util.iterToArray(t),i=e[0].$min(e[1]),r=e[0].$max(e[1]);return new _.Group(i,new _.Pt(r.x,i.y),r,new _.Pt(i.x,r.y))}static sides(t){let[e,i,r,s]=y.corners(t);return[new _.Group(e,i),new _.Group(i,r),new _.Group(r,s),new _.Group(s,e)]}static boundingBox(t){let e=d.Util.iterToArray(t),i=d.Util.flatten(e,!1),r=_.Pt.make(2,Number.MAX_VALUE),s=_.Pt.make(2,Number.MIN_VALUE);for(let t,e=0,n=i.length;e<n;e++){t=0;for(let n of i[e])if(r[t]=h(r[t],n[t]),s[t]=c(s[t],n[t]),2<=++t)break}return new _.Group(r,s)}static polygon(t){return y.corners(t)}static quadrants(t,e){let i=d.Util.iterToArray(t),r=y.corners(i),s=null==e?y.center(i):new _.Pt(e);return r.map(t=>new _.Group(t,s).boundingBox())}static halves(t,e=.5,i=!1){let r=d.Util.iterToArray(t),s=r[0].$min(r[1]),n=r[0].$max(r[1]),o=i?p.Num.lerp(s[1],n[1],e):p.Num.lerp(s[0],n[0],e);return i?[new _.Group(s,new _.Pt(n[0],o)),new _.Group(new _.Pt(s[0],o),n)]:[new _.Group(s,new _.Pt(o,n[1])),new _.Group(new _.Pt(o,s[1]),n)]}static withinBound(t,e){let i=d.Util.iterToArray(t);return p.Geom.withinBound(e,i[0],i[1])}static hasIntersectRect2D(t,e,i=!1){let r=d.Util.iterToArray(t),s=d.Util.iterToArray(e);return i&&(r=p.Geom.boundingBox(r),s=p.Geom.boundingBox(s)),!(r[0][0]>s[1][0]||s[0][0]>r[1][0]||r[0][1]>s[1][1]||s[0][1]>r[1][1])}static intersectRect2D(t,e){let i=d.Util.iterToArray(t),r=d.Util.iterToArray(e);return y.hasIntersectRect2D(i,r)?m.intersectLines2D(y.sides(i),y.sides(r)):new _.Group}}a.Rectangle=y;class w{static fromRect(t,e=!1){let i=d.Util.iterToArray(t),r=0,s=r=y.size(i).minValue().value/2;if(e){let t=y.size(i).maxValue().value/2;r=o(s*s+t*t)}else r=s;return new _.Group(y.center(i),new _.Pt(r,r))}static fromTriangle(t,e=!1){return e?b.circumcircle(t):b.incircle(t)}static fromCenter(t,e){return new _.Group(new _.Pt(t),new _.Pt(e,e))}static withinBound(t,e,i=0){let r=d.Util.iterToArray(t),s=r[0].$subtract(e);return s.dot(s)+i<r[1].x*r[1].x}static intersectRay2D(t,e){let i=d.Util.iterToArray(t),r=d.Util.iterToArray(e),s=r[0].$subtract(r[1]),n=i[0].$subtract(r[0]),a=s.dot(s),l=n.dot(s)/a,h=l*l-(n.dot(n)-i[1].x*i[1].x)/a;if(0>h)return new _.Group;{let t=o(h),e=r[0].$subtract(s.$multiply(-l+t));if(0==h)return new _.Group(e);let i=r[0].$subtract(s.$multiply(-l-t));return new _.Group(e,i)}}static intersectLine2D(t,e){let i=d.Util.iterToArray(t),r=d.Util.iterToArray(e),s=w.intersectRay2D(i,r),n=new _.Group;if(0<s.length)for(let t=0,e=s.length;t<e;t++)y.withinBound(r,s[t])&&n.push(s[t]);return n}static intersectCircle2D(t,i){let r=d.Util.iterToArray(t),s=d.Util.iterToArray(i),n=s[0].$subtract(r[0]),a=n.magnitudeSq(),l=o(a),h=r[1].x,u=s[1].x,c=h*h;if(l>h+u)return new _.Group;if(l<e(h-u))return new _.Group(r[0].clone());{let t=(c-u*u+a)/(2*l),e=o(c-t*t),i=n.$multiply(t/l).add(r[0]);return new _.Group(new _.Pt(i.x+e*n.y/l,i.y-e*n.x/l),new _.Pt(i.x-e*n.y/l,i.y+e*n.x/l))}}static intersectRect2D(t,e){let i=d.Util.iterToArray(t),r=d.Util.iterToArray(e),s=y.sides(r),n=[];for(let t,e=0,r=s.length;e<r;e++)t=w.intersectLine2D(i,s[e]),0<t.length&&n.push(t);return d.Util.flatten(n)}static toRect(t,e=!1){let i=d.Util.iterToArray(t),r=i[1][0];if(e){let t=o(r*r)/2;return new _.Group(i[0].$subtract(t),i[0].$add(t))}return new _.Group(i[0].$subtract(r),i[0].$add(r))}static toTriangle(e,i=!0){let r=d.Util.iterToArray(e);if(i){let e=-t/2,i=new _.Group;for(let s=0;3>s;s++)i.push(r[0].clone().toAngle(e,r[1][0],!0)),e+=2*t/3;return i}return b.fromCenter(r[0],r[1][0])}}a.Circle=w;class b{static fromRect(t){let e=d.Util.iterToArray(t),i=e[0].$add(e[1]).divide(2);i.y=e[0][1];let r=e[1].clone();return r.x=e[0][0],new _.Group(i,e[1].clone(),r)}static fromCircle(t){return w.toTriangle(t,!0)}static fromCenter(t,e){return b.fromCircle(w.fromCenter(t,e))}static medial(t){let e=d.Util.iterToArray(t);return 3>e.length?f(new _.Group,3):x.midpoints(e,!0)}static oppositeSide(t,e){let i=d.Util.iterToArray(t);return 3>i.length?f(new _.Group,3):0===e?_.Group.fromPtArray([i[1],i[2]]):1===e?_.Group.fromPtArray([i[0],i[2]]):_.Group.fromPtArray([i[0],i[1]])}static altitude(t,e){let i=d.Util.iterToArray(t),r=b.oppositeSide(i,e);return 1<r.length?new _.Group(i[e],m.perpendicularFromPt(r,i[e])):new _.Group}static orthocenter(t){let e=d.Util.iterToArray(t);if(3>e.length)return f(void 0,3);let i=b.altitude(e,0),r=b.altitude(e,1);return m.intersectRay2D(i,r)}static incenter(t){let e=d.Util.iterToArray(t);if(3>e.length)return f(void 0,3);let i=x.bisector(e,0).add(e[0]),r=x.bisector(e,1).add(e[1]);return m.intersectRay2D(new _.Group(e[0],i),new _.Group(e[1],r))}static incircle(t,e){let i=d.Util.iterToArray(t),r=e||b.incenter(i),s=2*x.area(i)/x.perimeter(i,!0).total;return w.fromCenter(r,s)}static circumcenter(t){let e=d.Util.iterToArray(t),i=b.medial(e),r=[i[0],p.Geom.perpendicular(e[0].$subtract(i[0])).p1.$add(i[0])],s=[i[1],p.Geom.perpendicular(e[1].$subtract(i[1])).p1.$add(i[1])];return m.intersectRay2D(r,s)}static circumcircle(t,e){let i=d.Util.iterToArray(t),r=e||b.circumcenter(i),s=i[0].$subtract(r).magnitude();return w.fromCenter(r,s)}}a.Triangle=b;class x{static centroid(t){return p.Geom.centroid(t)}static rectangle(t,e,i){return y.corners(y.fromCenter(t,e,i))}static fromCenter(e,i,r){let o=new _.Group;for(let a,l=0;l<r;l++)a=2*t*l/r,o.push(new _.Pt(n(a)*i,s(a)*i).add(e));return o}static lineAt(t,e){let i=d.Util.iterToArray(t);if(0>e||e>=i.length)throw new Error("index out of the Polygon's range");return new _.Group(i[e],e===i.length-1?i[0]:i[e+1])}static lines(t,e=!0){let i=d.Util.iterToArray(t);if(2>i.length)return f(new _.Group,2);let r=d.Util.split(i,2,1);return e&&r.push(new _.Group(i[i.length-1],i[0])),r.map(t=>t)}static midpoints(t,e=!1,i=.5){return x.lines(t,e).map(t=>p.Geom.interpolate(t[0],t[1],i))}static adjacentSides(t,e,i=!1){let r=d.Util.iterToArray(t);if(2>r.length)return f(new _.Group,2);if(0>e||e>=r.length)return((t,e="")=>d.Util.warn(`Index ${e} is out of bound in Group`,t))(new _.Group,e);let s=[],n=e-1;i&&0>n&&(n=r.length-1),0<=n&&s.push(new _.Group(r[e],r[n]));let o=e+1;return i&&o>r.length-1&&(o=0),o<=r.length-1&&s.push(new _.Group(r[e],r[o])),s}static bisector(t,e){let i=x.adjacentSides(t,e,!0);if(2<=i.length){let t=i[0][1].$subtract(i[0][0]).unit(),e=i[1][1].$subtract(i[1][0]).unit();return t.add(e).divide(2)}}static perimeter(t,e=!1){let i=x.lines(t,e),r=0,s=_.Pt.make(i.length,0);for(let t,e=0,n=i.length;e<n;e++)t=m.magnitude(i[e]),r+=t,s[e]=t;return{total:r,segments:s}}static area(t){let i=d.Util.iterToArray(t);if(3>i.length)return f(new _.Group,3);let r=(t,e)=>t[0]*e[1]-t[1]*e[0],s=0;for(let t=0,e=i.length;t<e;t++)s+=t<i.length-1?r(i[t],i[t+1]):r(i[t],i[0]);return e(s/2)}static convexHull(t,e=!1){let i=d.Util.iterToArray(t);if(3>i.length)return f(new _.Group,3);e||(i=i.slice(),i.sort((t,e)=>t[0]-e[0]));let r=(t,e,i)=>0<(e[0]-t[0])*(i[1]-t[1])-(i[0]-t[0])*(e[1]-t[1]),s=[],n=i.length-2,o=n+3;s[n]=i[2],s[o]=i[2],r(i[0],i[1],i[2])?(s[n+1]=i[0],s[n+2]=i[1]):(s[n+1]=i[1],s[n+2]=i[0]);for(let t,e=3,a=i.length;e<a;e++)if(t=i[e],!r(s[n],s[n+1],t)||!r(s[o-1],s[o],t)){for(;!r(s[n],s[n+1],t);)n+=1;for(n-=1,s[n]=t;!r(s[o-1],s[o],t);)o-=1;o+=1,s[o]=t}let a=new _.Group;for(let t=0;t<o-n;t++)a.push(s[n+t]);return a}static network(t,e=0){let i=d.Util.iterToArray(t),r=[];for(let t=0,s=i.length;t<s;t++)t!=e&&r.push(new _.Group(i[e],i[t]));return r}static nearestPt(t,e){let r=i,s=-1,n=0;for(let i of t){let t=i.$subtract(e).magnitudeSq();t<r&&(r=t,s=n),n++}return s}static projectAxis(t,e){let i=d.Util.iterToArray(t),r=e.dot(i[0]),s=new _.Pt(r,r);for(let t=1,n=i.length;t<n;t++)r=e.dot(i[t]),s=new _.Pt(h(r,s[0]),c(r,s[1]));return s}static _axisOverlap(t,e,i){let r=x.projectAxis(t,i),s=x.projectAxis(e,i);return r[0]<s[0]?s[0]-r[1]:r[0]-s[1]}static hasIntersectPoint(t,e){let i=d.Util.iterToArray(t),r=!1;for(let t,s=0,n=i.length;s<n;s++)t=x.lineAt(i,s),t[0][1]>e[1]!=t[1][1]>e[1]&&e[0]<(t[1][0]-t[0][0])*(e[1]-t[0][1])/(t[1][1]-t[0][1])+t[0][0]&&(r=!r);return r}static hasIntersectCircle(t,i){let r=d.Util.iterToArray(t),s=d.Util.iterToArray(i),n={which:-1,dist:0,normal:null,edge:null,vertex:null},o=s[0],a=s[1][0],l=u;for(let t=0,s=r.length;t<s;t++){let s=x.lineAt(r,t),h=new _.Pt(s[0].y-s[1].y,s[1].x-s[0].x).unit(),u=new _.Group(o.$add(h.$multiply(a)),o.$subtract(h.$multiply(a))),c=x._axisOverlap(r,u,h);if(0<c)return null;e(c)<l&&(y.withinBound(s,m.perpendicularFromPt(s,o))||0<w.intersectLine2D(i,s).length)&&(n.edge=s,n.normal=h,l=e(c),n.which=t)}return n.edge?(0>o.$subtract(x.centroid(r)).dot(n.normal)&&n.normal.multiply(-1),n.dist=l,n.vertex=o,n):null}static hasIntersectPolygon(t,i){let r=d.Util.iterToArray(t),s=d.Util.iterToArray(i),n={which:-1,dist:0,normal:new _.Pt,edge:new _.Group,vertex:new _.Pt},o=u;for(let t=0,i=r.length+s.length;t<i;t++){let i=t<r.length?x.lineAt(r,t):x.lineAt(s,t-r.length),a=new _.Pt(i[0].y-i[1].y,i[1].x-i[0].x).unit(),l=x._axisOverlap(r,s,a);if(0<l)return null;e(l)<o&&(n.edge=i,n.normal=a,o=e(l),n.which=t<r.length?0:1)}n.dist=o;let a=0===n.which?s:r,l=0===n.which?r:s,h=x.centroid(a),c=x.centroid(l);0>h.$subtract(c).dot(n.normal)&&n.normal.multiply(-1);let p=u;for(let t,e=0,i=a.length;e<i;e++)t=n.normal.dot(a[e].$subtract(c)),t<p&&(p=t,n.vertex=a[e]);return n}static intersectPolygon2D(t,e){let i=d.Util.iterToArray(t),r=d.Util.iterToArray(e),s=x.lines(i),n=[];for(let t,e=0,i=s.length;e<i;e++)t=m.intersectPolygon2D(s[e],r,!1),t&&n.push(t);return d.Util.flatten(n,!0)}static toRects(t){let e=[];for(let i of t)e.push(p.Geom.boundingBox(i));let i=d.Util.flatten(e,!1);return e.unshift(p.Geom.boundingBox(i)),e}}a.Polygon=x;class v{static getSteps(t){let e=new _.Group;for(let i,r=0;r<=t;r++)i=r/t,e.push(new _.Pt(i*i*i,i*i,i,1));return e}static controlPoints(t,e=0,i=!1){let r=d.Util.iterToArray(t);if(e>r.length-1)return new _.Group;let s=t=>t<r.length-1?t:r.length-1,n=r[e];return e=i?e:e+1,new _.Group(n,r[s(e++)],r[s(e++)],r[s(e++)])}static _calcPt(t,e){let i=t.reduce((t,i,r)=>t+i.x*e[r],0),r=t.reduce((t,i,r)=>t+i.y*e[r],0);if(2<t[0].length){let s=t.reduce((t,i,r)=>t+i.z*e[r],0);return new _.Pt(i,r,s)}return new _.Pt(i,r)}static catmullRom(t,e=10){let i=d.Util.iterToArray(t);if(2>i.length)return new _.Group;let r=new _.Group,s=v.getSteps(e),n=v.controlPoints(i,0,!0);for(let t=0;t<=e;t++)r.push(v.catmullRomStep(s[t],n));for(let t,n=0;n<i.length-2;)if(t=v.controlPoints(i,n),0<t.length){for(let i=0;i<=e;i++)r.push(v.catmullRomStep(s[i],t));n++}return r}static catmullRomStep(t,e){let i=new _.Group(new _.Pt(-.5,1,-.5,0),new _.Pt(1.5,-2.5,0,1),new _.Pt(-1.5,2,.5,0),new _.Pt(.5,-.5,0,0));return v._calcPt(e,g.Mat.multiply([t],i,!0)[0])}static cardinal(t,e=10,i=.5){let r=d.Util.iterToArray(t);if(2>r.length)return new _.Group;let s=new _.Group,n=v.getSteps(e),o=v.controlPoints(r,0,!0);for(let t=0;t<=e;t++)s.push(v.cardinalStep(n[t],o,i));for(let t,o=0;o<r.length-2;)if(t=v.controlPoints(r,o),0<t.length){for(let r=0;r<=e;r++)s.push(v.cardinalStep(n[r],t,i));o++}return s}static cardinalStep(t,e,i=.5){let r=new _.Group(new _.Pt(-1,2,-1,0),new _.Pt(-1,1,0,0),new _.Pt(1,-2,1,0),new _.Pt(1,-1,0,0)),s=g.Mat.multiply([t],r,!0)[0].multiply(i),n=2*t[0]-3*t[1]+1,o=-2*t[0]+3*t[1],a=v._calcPt(e,s);return a.x+=n*e[1].x+o*e[2].x,a.y+=n*e[1].y+o*e[2].y,2<a.length&&(a.z+=n*e[1].z+o*e[2].z),a}static bezier(t,e=10){let i=d.Util.iterToArray(t);if(4>i.length)return new _.Group;let r=new _.Group,s=v.getSteps(e),n=0;for(;n<i.length-3;){let t=v.controlPoints(i,n);if(0<t.length){for(let i=0;i<=e;i++)r.push(v.bezierStep(s[i],t));n+=3}}return r}static bezierStep(t,e){let i=new _.Group(new _.Pt(-1,3,-3,1),new _.Pt(3,-6,3,0),new _.Pt(-3,3,0,0),new _.Pt(1,0,0,0));return v._calcPt(e,g.Mat.multiply([t],i,!0)[0])}static bspline(t,e=10,i=1){let r=d.Util.iterToArray(t);if(2>r.length)return new _.Group;let s=new _.Group,n=v.getSteps(e),o=0;for(;o<r.length-3;){let t=v.controlPoints(r,o);if(0<t.length){if(1!==i)for(let r=0;r<=e;r++)s.push(v.bsplineTensionStep(n[r],t,i));else for(let i=0;i<=e;i++)s.push(v.bsplineStep(n[i],t));o++}}return s}static bsplineStep(t,e){let i=new _.Group(new _.Pt(-.16666666666666666,.5,-.5,.16666666666666666),new _.Pt(.5,-1,0,.6666666666666666),new _.Pt(-.5,.5,.5,.16666666666666666),new _.Pt(.16666666666666666,0,0,0));return v._calcPt(e,g.Mat.multiply([t],i,!0)[0])}static bsplineTensionStep(t,e,i=1){let r=new _.Group(new _.Pt(-.16666666666666666,.5,-.5,.16666666666666666),new _.Pt(-1.5,2,0,-.3333333333333333),new _.Pt(1.5,-2.5,.5,.16666666666666666),new _.Pt(.16666666666666666,0,0,0)),s=g.Mat.multiply([t],r,!0)[0].multiply(i),n=2*t[0]-3*t[1]+1,o=-2*t[0]+3*t[1],a=v._calcPt(e,s);return a.x+=n*e[1].x+o*e[2].x,a.y+=n*e[1].y+o*e[2].y,2<a.length&&(a.z+=n*e[1].z+o*e[2].z),a}}a.Curve=v},"./src/Physics.ts":function(t,i,r){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Body=i.Particle=i.World=void 0;const s=r("./src/Pt.ts"),n=r("./src/Op.ts"),a=r("./src/Num.ts");class l{constructor(t,e=1,i=0){return this._lastTime=null,this._gravity=new s.Pt,this._friction=1,this._damping=.75,this._particles=[],this._bodies=[],this._pnames=[],this._bnames=[],this._bound=s.Bound.fromGroup(t),this._friction=e,this._gravity="number"==typeof i?new s.Pt(0,i):new s.Pt(i),this}get bound(){return this._bound}set bound(t){this._bound=t}get gravity(){return this._gravity}set gravity(t){this._gravity=t}get friction(){return this._friction}set friction(t){this._friction=t}get damping(){return this._damping}set damping(t){this._damping=t}get bodyCount(){return this._bodies.length}get particleCount(){return this._particles.length}body(t){let e=t;return"string"==typeof t&&0<t.length&&(e=this._bnames.indexOf(t)),0<=e?this._bodies[e]:void 0}particle(t){let e=t;return"string"==typeof t&&0<t.length&&(e=this._pnames.indexOf(t)),0<=e?this._particles[e]:void 0}bodyIndex(t){return this._bnames.indexOf(t)}particleIndex(t){return this._pnames.indexOf(t)}update(t){let e=t/1e3;this._updateParticles(e),this._updateBodies(e)}drawParticles(t){this._drawParticles=t}drawBodies(t){this._drawBodies=t}add(t,e=""){return t instanceof d?(this._bodies.push(t),this._bnames.push(e)):(this._particles.push(t),this._pnames.push(e)),this}_index(t,e){let i=0;if("string"!=typeof e)i=e;else if(i=t(e),0>i)throw new Error(`Cannot find index of ${e}. You can use particleIndex() or bodyIndex() function to check existence by name.`);return i}removeBody(t,e=1){const i=this._index(this.bodyIndex.bind(this),t),r=0>i?[-1*i-1,e]:[i,e];return this._bodies.splice(r[0],r[1]),this._bnames.splice(r[0],r[1]),this}removeParticle(t,e=1){const i=this._index(this.particleIndex.bind(this),t),r=0>i?[-1*i-1,e]:[i,e];return this._particles.splice(r[0],r[1]),this._pnames.splice(r[0],r[1]),this}static edgeConstraint(t,e,i,r=1,s=!1){const n=1/(t.mass||1),o=1/(e.mass||1),a=n+o;let l=e.$subtract(t),h=i*i,u=s?i/l.magnitude()-1:h/(l.dot(l)+h)-.5,c=l.$multiply(u*r);return t.subtract(c.$multiply(n/a)),e.add(c.$multiply(o/a)),t}static boundConstraint(t,e,i=.75){let r=a.Geom.boundingBox(e),n=t.$min(r[1].subtract(t.radius)).$max(r[0].add(t.radius));if(n[0]===r[0][0]||n[0]===r[1][0]){let e=t.changed.$multiply(i);t.previous=n.$subtract(new s.Pt(-e[0],e[1]))}else if(n[1]===r[0][1]||n[1]===r[1][1]){let e=t.changed.$multiply(i);t.previous=n.$subtract(new s.Pt(e[0],-e[1]))}t.to(n)}integrate(t,e,i){return t.addForce(this._gravity),t.verlet(e,this._friction,i),t}_updateParticles(t){for(let e,i=0,r=this._particles.length;i<r;i++){e=this._particles[i],this.integrate(e,t,this._lastTime),l.boundConstraint(e,this._bound,this._damping);for(let t=i+1;t<r;t++)if(i!==t){let i=this._particles[t];e.collide(i,this._damping)}this._drawParticles&&this._drawParticles(e,i)}this._lastTime=t}_updateBodies(t){for(let e,i=0,r=this._bodies.length;i<r;i++)if(e=this._bodies[i],e){for(let i,r=0,s=e.length;r<s;r++)i=e[r],l.boundConstraint(i,this._bound,this._damping),this.integrate(i,t,this._lastTime);for(let t=i+1;t<r;t++)e.processBody(this._bodies[t]);for(let t=0,i=this._particles.length;t<i;t++)e.processParticle(this._particles[t]);e.processEdges(),this._drawBodies&&this._drawBodies(e,i)}}}i.World=l;class c extends s.Pt{constructor(...t){super(...t),this._mass=1,this._radius=0,this._force=new s.Pt,this._prev=new s.Pt,this._lock=!1,this._prev=this.clone()}get mass(){return this._mass}set mass(t){this._mass=t}get radius(){return this._radius}set radius(t){this._radius=t}get previous(){return this._prev}set previous(t){this._prev=t}get force(){return this._force}set force(t){this._force=t}get body(){return this._body}set body(t){this._body=t}get lock(){return this._lock}set lock(t){this._lock=t,this._lockPt=new s.Pt(this)}get changed(){return this.$subtract(this._prev)}set position(t){this.previous.to(this),this._lock&&(this._lockPt=t),this.to(t)}size(t){return this._mass=t,this._radius=t,this}addForce(...t){return this._force.add(...t),this._force}verlet(t,e,i){if(this._lock)this.to(this._lockPt);else{let r=i||t,n=this._force.multiply(t*(t+r)/2),o=this.changed.multiply(e*t/r).add(n);this._prev=this.clone(),this.add(o),this._force=new s.Pt}return this}hit(...t){return this._prev.subtract(new s.Pt(...t).$divide(o(this._mass))),this}collide(t,e=1){let i=this,r=i.$subtract(t),n=r.magnitudeSq(),a=i.radius+t.radius;if(n<a*a){let l=i.changed,h=t.changed,u=o(n),c=r.$multiply((u-a)/u/2),d=i.$subtract(c),p=t.$add(c);i.to(d),t.to(p);let _=e*r.dot(l)/n,g=e*r.dot(h)/n,f=i.mass/(i.mass+t.mass),m=t.mass/(i.mass+t.mass);l.add(new s.Pt(g*r[0]-_*r[0],g*r[1]-_*r[1]).$multiply(m)),h.add(new s.Pt(_*r[0]-g*r[0],_*r[1]-g*r[1]).$multiply(f)),i.previous=i.$subtract(l),t.previous=t.$subtract(h)}}toString(){return`Particle: ${this[0]} ${this[1]} | previous ${this._prev[0]} ${this._prev[1]} | mass ${this._mass}`}}i.Particle=c;class d extends s.Group{constructor(){super(),this._cs=[],this._stiff=1,this._locks={},this._mass=1}static fromGroup(t,e=1,i=!0,r=!0){let s=(new d).init(t);return i&&s.linkAll(e),r&&s.autoMass(),s}init(t,e=1){let i=new s.Pt;for(let e of t){let t=new c(e);t.body=this,i.add(e),this.push(t)}return this._stiff=e,this}get mass(){return this._mass}set mass(t){this._mass=t;for(let t=0,e=this.length;t<e;t++)this[t].mass=this._mass}autoMass(){return this.mass=o(n.Polygon.area(this))/10,this}link(t,e,i){if(0>t||t>=this.length)throw new Error("index1 is not in the Group's indices");if(0>e||e>=this.length)throw new Error("index1 is not in the Group's indices");let r=this[t].$subtract(this[e]).magnitude();return this._cs.push([t,e,r,i||this._stiff]),this}linkAll(t){let e=this.length/2;for(let i,r=0,s=this.length;r<s;r++){if(i=r>=s-1?0:r+1,this.link(r,i,t),4<s){let i=u(e/2)+1,n=r>=s-i?r%s:r+i;this.link(r,n,t)}r<=e-1&&this.link(r,h(this.length-1,r+u(e)))}}linksToLines(){let t=[];for(let e,i=0,r=this._cs.length;i<r;i++)e=this._cs[i],t.push(new s.Group(this[e[0]],this[e[1]]));return t}processEdges(){for(let t=0,e=this._cs.length;t<e;t++){let[e,i,r,s]=this._cs[t];l.edgeConstraint(this[e],this[i],r,s)}}processBody(t){let i=n.Polygon.hasIntersectPolygon(this,t);if(i){let t,r=i.normal.$multiply(i.dist),s=i.edge;t=e(s[0][0]-s[1][0])>e(s[0][1]-s[1][1])?(i.vertex[0]-r[0]-s[0][0])/(s[1][0]-s[0][0]):(i.vertex[1]-r[1]-s[0][1])/(s[1][1]-s[0][1]);let n=1/(t*t+(1-t)*(1-t)),o=i.vertex.body.mass||1,a=i.edge[0].body.mass||1,l=o/(o+a);s[0].subtract(r.$multiply(l*(1-t)*n/2)),s[1].subtract(r.$multiply(l*t*n/2)),i.vertex.add(r.$multiply(a/(o+a)))}}processParticle(t){let i=n.Polygon.hasIntersectCircle(this,n.Circle.fromCenter(t,t.radius));if(i){let r,s=i.normal.$multiply(i.dist),n=i.edge;r=e(n[0][0]-n[1][0])>e(n[0][1]-n[1][1])?(i.vertex[0]-s[0]-n[0][0])/(n[1][0]-n[0][0]):(i.vertex[1]-s[1]-n[0][1])/(n[1][1]-n[0][1]);let o=1/(r*r+(1-r)*(1-r)),a=i.vertex.mass||t.mass||1,l=i.edge[0].body.mass||1,h=a/(a+l);n[0].subtract(s.$multiply(h*(1-r)*o/2)),n[1].subtract(s.$multiply(h*r*o/2));let u=t.changed.add(s.$multiply(l/(a+l)));t.previous=t.$subtract(u)}}}i.Body=d},"./src/Play.ts":function(t,e,i){"use strict";var r=this&&this.__awaiter||function(t,e,i,r){function s(t){return t instanceof i?t:new i((function(e){e(t)}))}return new(i||(i=Promise))((function(i,n){function o(t){try{l(r.next(t))}catch(t){n(t)}}function a(t){try{l(r.throw(t))}catch(t){n(t)}}function l(t){t.done?i(t.value):s(t.value).then(o,a)}l((r=r.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.Sound=e.Tempo=void 0;const s=i("./src/Pt.ts"),n=i("./src/Num.ts");class o{constructor(t){this._listeners={},this._listenerInc=0,this.bpm=t}static fromBeat(t){return new o(6e4/t)}get bpm(){return this._bpm}set bpm(t){this._bpm=t,this._ms=6e4/this._bpm}get ms(){return this._ms}set ms(t){this._bpm=u(6e4/t),this._ms=6e4/this._bpm}_createID(t){let e="";return e="function"==typeof t?"_b"+this._listenerInc++:t.name||"_b"+this._listenerInc++,e}every(t){let e=this,i=Array.isArray(t)?t[0]:t;return{start:function(r,s=0,n){let o=n||e._createID(r);return e._listeners[o]={name:o,beats:t,period:i,index:0,offset:s,duration:-1,continuous:!1,fn:r},this},progress:function(r,s=0,n){let o=n||e._createID(r);return e._listeners[o]={name:o,beats:t,period:i,index:0,offset:s,duration:-1,continuous:!0,fn:r},this}}}track(t){for(let e in this._listeners)if(this._listeners.hasOwnProperty(e)){let i=this._listeners[e],r=i.offset?t+i.offset:t,s=i.period*this._ms,o=!1;r>i.duration+s&&(i.duration=r-r%this._ms,Array.isArray(i.beats)&&(i.index=(i.index+1)%i.beats.length,i.period=i.beats[i.index]),o=!0);let a=c(0,Math.ceil(u(i.duration/this._ms)/i.period)),l=i.continuous?[a,n.Num.clamp((r-i.duration)/s,0,1),r,o]:[a];(i.continuous||o)&&i.fn.apply(i,l)&&delete this._listeners[i.name]}}stop(t){this._listeners[t]&&delete this._listeners[t]}animate(t){this.track(t)}resize(){}action(){}}e.Tempo=o;class a{constructor(t){this._playing=!1,this._type=t;let e=window.AudioContext||window.webkitAudioContext||!1;if(!e)throw new Error("Your browser doesn't support Web Audio. (No AudioContext)");this._ctx=e?new e:void 0}static from(t,e,i="gen",r){let s=new a(i);return s._node=t,s._ctx=e,r&&(s._stream=r),s}static load(t,e="anonymous"){return new Promise((i,r)=>{let s=new a("file");s._source="string"==typeof t?new Audio(t):t,s._source.autoplay=!1,s._source.crossOrigin=e,s._source.addEventListener("ended",(function(){s._playing=!1})),s._source.addEventListener("error",(function(){r("Error loading sound")})),s._source.addEventListener("canplaythrough",(function(){s._node=s._ctx.createMediaElementSource(s._source),i(s)}))})}static loadAsBuffer(t){return new Promise((e,i)=>{let r=new XMLHttpRequest;r.open("GET",t,!0),r.responseType="arraybuffer";let s=new a("file");r.onload=function(){s._ctx.decodeAudioData(r.response,(function(t){s.createBuffer(t),e(s)}),()=>i("Error decoding audio"))},r.send()})}createBuffer(t){return this._node=this._ctx.createBufferSource(),void 0!==t&&(this._buffer=t),this._node.buffer=this._buffer,this._node.onended=()=>{this._playing=!1},this}static generate(t,e){return new a("gen")._gen(t,e)}_gen(t,e){this._node=this._ctx.createOscillator();let i=this._node;return i.type=t,"custom"===t?i.setPeriodicWave(e):i.frequency.value=e,this}static input(t){return r(this,void 0,void 0,(function*(){try{let e=new a("input");if(!e)return;const i=t||{audio:!0,video:!1};return e._stream=yield navigator.mediaDevices.getUserMedia(i),e._node=e._ctx.createMediaStreamSource(e._stream),e}catch(t){return console.error("Cannot get audio from input device."),Promise.resolve(null)}}))}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(t){this._buffer=t}get type(){return this._type}get playing(){return this._playing}get progress(){let t=0,e=0;return this._buffer?(t=this._buffer.duration,e=this._timestamp?this._ctx.currentTime-this._timestamp:0):(t=this._source.duration,e=this._source.currentTime),e/t}get playable(){return"input"===this._type?void 0!==this._node:!!this._buffer||4===this._source.readyState}get binSize(){return this.analyzer.size}get sampleRate(){return this._ctx.sampleRate}get frequency(){return"gen"===this._type?this._node.frequency.value:0}set frequency(t){"gen"===this._type&&(this._node.frequency.value=t)}connect(t){return this._node.connect(t),this}setOutputNode(t){return this._outputNode=t,this}removeOutputNode(){return this._outputNode=null,this}analyze(t=256,e=-100,i=-30,r=.8){let s=this._ctx.createAnalyser();return s.fftSize=2*t,s.minDecibels=e,s.maxDecibels=i,s.smoothingTimeConstant=r,this.analyzer={node:s,size:s.frequencyBinCount,data:new Uint8Array(s.frequencyBinCount)},this._node.connect(this.analyzer.node),this}_domain(t){return this.analyzer?(t?this.analyzer.node.getByteTimeDomainData(this.analyzer.data):this.analyzer.node.getByteFrequencyData(this.analyzer.data),this.analyzer.data):new Uint8Array(0)}_domainTo(t,e,i=[0,0],r=[0,0]){let n=t?this.timeDomain():this.freqDomain(),o=new s.Group;for(let t=r[0],a=n.length-r[1];t<a;t++)o.push(new s.Pt(i[0]+e[0]*t/a,i[1]+e[1]*n[t]/255));return o}timeDomain(){return this._domain(!0)}timeDomainTo(t,e=[0,0],i=[0,0]){return this._domainTo(!0,t,e,i)}freqDomain(){return this._domain(!1)}freqDomainTo(t,e=[0,0],i=[0,0]){return this._domainTo(!1,t,e,i)}reset(){return this.stop(),this._node.disconnect(),this}start(t=0){return"suspended"===this._ctx.state&&this._ctx.resume(),"file"===this._type?this._buffer?(this._node.start(t),this._timestamp=this._ctx.currentTime+t):(this._source.play(),0<t&&(this._source.currentTime=t)):"gen"===this._type&&(this._gen(this._node.type,this._node.frequency.value),this._node.start(),this.analyzer&&this._node.connect(this.analyzer.node)),(this._outputNode||this._node).connect(this._ctx.destination),this._playing=!0,this}stop(){return this._playing&&(this._outputNode||this._node).disconnect(this._ctx.destination),"file"===this._type?this._buffer?1>this.progress&&this._node.stop():this._source.pause():"gen"===this._type?this._node.stop():"input"===this._type&&this._stream.getAudioTracks().forEach(t=>t.stop()),this._playing=!1,this}toggle(){return this._playing?this.stop():this.start(),this}}e.Sound=a},"./src/Pt.ts":function(t,i,r){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Bound=i.Group=i.Pt=void 0;const o=r("./src/Util.ts"),l=r("./src/Num.ts"),d=r("./src/LinearAlgebra.ts");class p extends Float32Array{constructor(...t){1===t.length&&"number"==typeof t[0]?super(t[0]):super(0<t.length?o.Util.getArgs(t):[0,0])}static make(t,e=0,i=!1){let r=new Float32Array(t);if(e&&r.fill(e),i)for(let t=0,e=r.length;t<e;t++)r[t]*=Math.random();return new p(r)}get id(){return this._id}set id(t){this._id=t}get x(){return this[0]}set x(t){this[0]=t}get y(){return this[1]}set y(t){this[1]=t}get z(){return this[2]}set z(t){this[2]=t}get w(){return this[3]}set w(t){this[3]=t}clone(){return new p(this)}equals(t,i=1e-6){for(let r=0,s=this.length;r<s;r++)if(e(this[r]-t[r])>i)return!1;return!0}to(...t){let e=o.Util.getArgs(t);for(let t=0,i=h(this.length,e.length);t<i;t++)this[t]=e[t];return this}$to(...t){return this.clone().to(...t)}toAngle(t,e,i=!1){let r=null==e?this.magnitude():e,o=[n(t)*r,s(t)*r];return i?this.add(o):this.to(o)}op(t){let e=this;return(...i)=>t(e,...i)}ops(t){let e=[];for(let i=0,r=t.length;i<r;i++)e.push(this.op(t[i]));return e}$take(t){let e=[];for(let i=0,r=t.length;i<r;i++)e.push(this[t[i]]||0);return new p(e)}$concat(...t){return new p(this.toArray().concat(o.Util.getArgs(t)))}add(...t){return 1===t.length&&"number"==typeof t[0]?d.Vec.add(this,t[0]):d.Vec.add(this,o.Util.getArgs(t)),this}$add(...t){return this.clone().add(...t)}subtract(...t){return 1===t.length&&"number"==typeof t[0]?d.Vec.subtract(this,t[0]):d.Vec.subtract(this,o.Util.getArgs(t)),this}$subtract(...t){return this.clone().subtract(...t)}multiply(...t){return 1===t.length&&"number"==typeof t[0]?d.Vec.multiply(this,t[0]):d.Vec.multiply(this,o.Util.getArgs(t)),this}$multiply(...t){return this.clone().multiply(...t)}divide(...t){return 1===t.length&&"number"==typeof t[0]?d.Vec.divide(this,t[0]):d.Vec.divide(this,o.Util.getArgs(t)),this}$divide(...t){return this.clone().divide(...t)}magnitudeSq(){return d.Vec.dot(this,this)}magnitude(){return d.Vec.magnitude(this)}unit(t){return d.Vec.unit(this,t),this}$unit(t){return this.clone().unit(t)}dot(...t){return d.Vec.dot(this,o.Util.getArgs(t))}$cross2D(...t){return d.Vec.cross2D(this,o.Util.getArgs(t))}$cross(...t){return d.Vec.cross(this,o.Util.getArgs(t))}$project(...t){return this.$multiply(this.dot(...t)/this.magnitudeSq())}projectScalar(...t){return this.dot(...t)/this.magnitude()}abs(){return d.Vec.abs(this),this}$abs(){return this.clone().abs()}floor(){return d.Vec.floor(this),this}$floor(){return this.clone().floor()}ceil(){return d.Vec.ceil(this),this}$ceil(){return this.clone().ceil()}round(){return d.Vec.round(this),this}$round(){return this.clone().round()}minValue(){return d.Vec.min(this)}maxValue(){return d.Vec.max(this)}$min(...t){let e=o.Util.getArgs(t),i=this.clone();for(let t=0,r=h(this.length,e.length);t<r;t++)i[t]=h(this[t],e[t]);return i}$max(...t){let e=o.Util.getArgs(t),i=this.clone();for(let t=0,r=h(this.length,e.length);t<r;t++)i[t]=c(this[t],e[t]);return i}angle(t=o.Const.xy){return a(this[t[1]],this[t[0]])}angleBetween(t,e=o.Const.xy){return l.Geom.boundRadian(this.angle(e))-l.Geom.boundRadian(t.angle(e))}scale(t,e){return l.Geom.scale(this,t,e||p.make(this.length,0)),this}rotate2D(t,e,i){return l.Geom.rotate2D(this,t,e||p.make(this.length,0),i),this}shear2D(t,e,i){return l.Geom.shear2D(this,t,e||p.make(this.length,0),i),this}reflect2D(t,e){return l.Geom.reflect2D(this,t,e),this}toString(){return`Pt(${this.join(", ")})`}toArray(){return[].slice.call(this)}toGroup(){return new _(p.make(this.length),this.clone())}toBound(){return new g(p.make(this.length),this.clone())}}i.Pt=p;class _ extends Array{constructor(...t){super(...t)}get id(){return this._id}set id(t){this._id=t}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 _;for(let e=0,i=this.length;e<i;e++)t.push(this[e].clone());return t}static fromArray(t){let e=new _;for(let i of t){let t=i instanceof p?i:new p(i);e.push(t)}return e}static fromPtArray(t){return _.from(t)}split(t,e,i=!1){return o.Util.split(this,t,e,i)}insert(t,e=0){return _.prototype.splice.apply(this,[e,0,...t]),this}remove(t=0,e=1){let i=0>t?[-1*t-1,e]:[t,e];return _.prototype.splice.apply(this,i)}segments(t=2,e=1,i=!1){return this.split(t,e,i)}lines(){return this.segments(2,1)}centroid(){return l.Geom.centroid(this)}boundingBox(){return l.Geom.boundingBox(this)}anchorTo(t=0){l.Geom.anchor(this,t,"to")}anchorFrom(t=0){l.Geom.anchor(this,t,"from")}op(t){let e=this;return(...i)=>t(e,...i)}ops(t){let e=[];for(let i=0,r=t.length;i<r;i++)e.push(this.op(t[i]));return e}interpolate(t){t=l.Num.clamp(t,0,1);let e=this.length-1,i=1/(this.length-1),r=u(t/i);return l.Geom.interpolate(this[r],this[h(this.length-1,r+1)],(t-r*i)*e)}moveBy(...t){return this.add(...t)}moveTo(...t){let e=new p(o.Util.getArgs(t)).subtract(this[0]);return this.moveBy(e),this}scale(t,e){for(let i=0,r=this.length;i<r;i++)l.Geom.scale(this[i],t,e||this[0]);return this}rotate2D(t,e,i){for(let r=0,s=this.length;r<s;r++)l.Geom.rotate2D(this[r],t,e||this[0],i);return this}shear2D(t,e,i){for(let r=0,s=this.length;r<s;r++)l.Geom.shear2D(this[r],t,e||this[0],i);return this}reflect2D(t,e){for(let i=0,r=this.length;i<r;i++)l.Geom.reflect2D(this[i],t,e);return this}sortByDimension(t,e=!1){return this.sort((i,r)=>e?r[t]-i[t]:i[t]-r[t])}forEachPt(t,...e){if(!this[0][t])return o.Util.warn(t+" is not a function of Pt"),this;for(let i=0,r=this.length;i<r;i++)this[i]=this[i][t](...e);return this}add(...t){return this.forEachPt("add",...t)}subtract(...t){return this.forEachPt("subtract",...t)}multiply(...t){return this.forEachPt("multiply",...t)}divide(...t){return this.forEachPt("divide",...t)}$matrixAdd(t){return d.Mat.add(this,t)}$matrixMultiply(t,e=!1,i=!1){return d.Mat.multiply(this,t,e,i)}zipSlice(t,e=!1){return d.Mat.zipSlice(this,t,e)}$zip(t,e=!1){return d.Mat.zip(this,t,e)}toString(){return"Group[ "+this.reduce((t,e)=>t+e.toString()+" ","")+" ]"}}i.Group=_;class g extends _{constructor(...t){super(...t),this._center=new p,this._size=new p,this._topLeft=new p,this._bottomRight=new p,this._inited=!1,this.init()}static fromBoundingRect(t){let e=new g(new p(t.left||0,t.top||0),new p(t.right||0,t.bottom||0));return t.width&&t.height&&(e.size=new p(t.width,t.height)),e}static fromGroup(t){let e=o.Util.iterToArray(t);if(2>e.length)throw new Error("Cannot create a Bound from a group that has less than 2 Pt");return new g(e[0],e[e.length-1])}init(){if(this.p1&&(this._size=this.p1.clone(),this._inited=!0),this.p1&&this.p2){let t=this.p1,e=this.p2;this.topLeft=t.$min(e),this._bottomRight=t.$max(e),this._updateSize(),this._inited=!0}}clone(){return new g(this._topLeft.clone(),this._bottomRight.clone())}_updateSize(){this._size=this._bottomRight.$subtract(this._topLeft).abs(),this._updateCenter()}_updateCenter(){this._center=this._size.$multiply(.5).add(this._topLeft)}_updatePosFromTop(){this._bottomRight=this._topLeft.$add(this._size),this._updateCenter()}_updatePosFromBottom(){this._topLeft=this._bottomRight.$subtract(this._size),this._updateCenter()}_updatePosFromCenter(){let t=this._size.$multiply(.5);this._topLeft=this._center.$subtract(t),this._bottomRight=this._center.$add(t)}get size(){return new p(this._size)}set size(t){this._size=new p(t),this._updatePosFromTop()}get center(){return new p(this._center)}set center(t){this._center=new p(t),this._updatePosFromCenter()}get topLeft(){return new p(this._topLeft)}set topLeft(t){this._topLeft=new p(t),this[0]=this._topLeft,this._updateSize()}get bottomRight(){return new p(this._bottomRight)}set bottomRight(t){this._bottomRight=new p(t),this[1]=this._bottomRight,this._updateSize()}get width(){return 0<this._size.length?this._size.x:0}set width(t){this._size.x=t,this._updatePosFromTop()}get height(){return 1<this._size.length?this._size.y:0}set height(t){this._size.y=t,this._updatePosFromTop()}get depth(){return 2<this._size.length?this._size.z:0}set depth(t){this._size.z=t,this._updatePosFromTop()}get x(){return this.topLeft.x}get y(){return this.topLeft.y}get z(){return this.topLeft.z}get inited(){return this._inited}update(){return this._topLeft=this[0],this._bottomRight=this[1],this._updateSize(),this}}i.Bound=g},"./src/Space.ts":function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.MultiTouchSpace=e.Space=void 0;const r=i("./src/Pt.ts"),s=i("./src/UI.ts");class n{constructor(){this.id="space",this.bound=new r.Bound,this._time={prev:0,diff:0,end:-1},this.players={},this.playerCount=0,this._animID=-1,this._pause=!1,this._refresh=void 0,this._pointer=new r.Pt,this._isReady=!1,this._playing=!1}refresh(t){return this._refresh=t,this}add(t){let e="function"==typeof t?{animate:t}:t,i=this.playerCount++,r=this.id+i;return this.players[r]=e,e.animateID=r,e.resize&&this.bound.inited&&e.resize(this.bound),void 0===this._refresh&&(this._refresh=!0),this}remove(t){return delete this.players[t.animateID],this}removeAll(){return this.players={},this}play(t=0){if(0!==t||-1===this._animID){if(this._animID=requestAnimationFrame(this.play.bind(this)),this._pause)return this;this._time.diff=t-this._time.prev,this._time.prev=t;try{this.playItems(t)}catch(t){throw cancelAnimationFrame(this._animID),this._animID=-1,this._playing=!1,t}return this}}replay(){this._time.end=-1,this.play()}playItems(t){if(this._playing=!0,this._refresh&&this.clear(),this._isReady)for(let e in this.players)this.players[e].animate&&this.players[e].animate(t,this._time.diff,this);0<=this._time.end&&t>this._time.end&&(cancelAnimationFrame(this._animID),this._animID=-1,this._playing=!1)}pause(t=!1){return this._pause=!t||!this._pause,this}resume(){return this._pause=!1,this}stop(t=0){return this._time.end=t,this}playOnce(t=5e3){return this.play(),this.stop(t),this}render(t){return this._renderFunc&&this._renderFunc(t,this),this}set customRendering(t){this._renderFunc=t}get customRendering(){return this._renderFunc}get isPlaying(){return this._playing}get outerBound(){return this.bound.clone()}get innerBound(){return new r.Bound(r.Pt.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}}e.Space=n,e.MultiTouchSpace=class extends n{constructor(){super(...arguments),this._pressed=!1,this._dragged=!1,this._hasMouse=!1,this._hasTouch=!1}get pointer(){let t=this._pointer.clone();return t.id=this._pointer.id,t}bindCanvas(t,e,i={}){this._canvas.addEventListener(t,e,i)}unbindCanvas(t,e){this._canvas.removeEventListener(t,e)}bindMouse(t=!0){return t?(this.bindCanvas("mousedown",this._mouseDown.bind(this)),this.bindCanvas("mouseup",this._mouseUp.bind(this)),this.bindCanvas("mouseover",this._mouseOver.bind(this)),this.bindCanvas("mouseout",this._mouseOut.bind(this)),this.bindCanvas("mousemove",this._mouseMove.bind(this)),this.bindCanvas("click",this._mouseClick.bind(this)),this.bindCanvas("contextmenu",this._contextMenu.bind(this)),this._hasMouse=!0):(this.unbindCanvas("mousedown",this._mouseDown.bind(this)),this.unbindCanvas("mouseup",this._mouseUp.bind(this)),this.unbindCanvas("mouseover",this._mouseOver.bind(this)),this.unbindCanvas("mouseout",this._mouseOut.bind(this)),this.unbindCanvas("mousemove",this._mouseMove.bind(this)),this.unbindCanvas("click",this._mouseClick.bind(this)),this.unbindCanvas("contextmenu",this._contextMenu.bind(this)),this._hasMouse=!1),this}bindTouch(t=!0){return t?(this.bindCanvas("touchstart",this._touchStart.bind(this),{passive:!0}),this.bindCanvas("touchend",this._mouseUp.bind(this)),this.bindCanvas("touchmove",this._touchMove.bind(this),{passive:!0}),this.bindCanvas("touchcancel",this._mouseOut.bind(this)),this._hasTouch=!0):(this.unbindCanvas("touchstart",this._touchStart.bind(this)),this.unbindCanvas("touchend",this._mouseUp.bind(this)),this.unbindCanvas("touchmove",this._touchMove.bind(this)),this.unbindCanvas("touchcancel",this._mouseOut.bind(this)),this._hasTouch=!1),this}touchesToPoints(t,e="touches"){if(!t||!t[e])return[];let i=[];for(var s=0;s<t[e].length;s++){let n=t[e].item(s);i.push(new r.Pt(n.pageX-this.bound.topLeft.x,n.pageY-this.bound.topLeft.y))}return i}_mouseAction(t,e){let i=0,r=0;if(e instanceof MouseEvent){for(let s in this.players)if(this.players.hasOwnProperty(s)){let n=this.players[s];i=e.pageX-this.outerBound.x,r=e.pageY-this.outerBound.y,n.action&&n.action(t,i,r,e)}}else for(let s in this.players)if(this.players.hasOwnProperty(s)){let n=this.players[s],o=e.changedTouches&&0<e.changedTouches.length,a=e.changedTouches.item(0);i=o?a.pageX-this.outerBound.x:0,r=o?a.pageY-this.outerBound.y:0,n.action&&n.action(t,i,r,e)}t&&(this._pointer.to(i,r),this._pointer.id=t)}_mouseDown(t){return this._mouseAction(s.UIPointerActions.down,t),this._pressed=!0,!1}_mouseUp(t){return this._dragged?this._mouseAction(s.UIPointerActions.drop,t):this._mouseAction(s.UIPointerActions.up,t),this._pressed=!1,this._dragged=!1,!1}_mouseMove(t){return this._mouseAction(s.UIPointerActions.move,t),this._pressed&&(this._dragged=!0,this._mouseAction(s.UIPointerActions.drag,t)),!1}_mouseOver(t){return this._mouseAction(s.UIPointerActions.over,t),!1}_mouseOut(t){return this._mouseAction(s.UIPointerActions.out,t),this._dragged&&this._mouseAction(s.UIPointerActions.drop,t),this._dragged=!1,!1}_mouseClick(t){return this._mouseAction(s.UIPointerActions.click,t),this._pressed=!1,this._dragged=!1,!1}_contextMenu(t){return this._mouseAction(s.UIPointerActions.contextmenu,t),!1}_touchMove(t){return this._mouseMove(t),t.preventDefault(),!1}_touchStart(t){return this._mouseDown(t),t.preventDefault(),!1}}},"./src/Svg.ts":function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.SVGForm=e.SVGSpace=void 0;const r=i("./src/Form.ts"),s=i("./src/Num.ts"),n=i("./src/Util.ts"),o=i("./src/Pt.ts"),a=i("./src/Op.ts"),l=i("./src/Dom.ts");class h extends l.DOMSpace{constructor(t,e){if(super(t,e),this._bgcolor="#999","svg"!=this._canvas.nodeName.toLowerCase()){let t=h.svgElement(this._canvas,"svg",this.id+"_svg");this._container=this._canvas,this._canvas=t}}getForm(){return new u(this)}get element(){return this._canvas}resize(t,e){return super.resize(t,e),h.setAttr(this.element,{viewBox:`0 0 ${this.bound.width} ${this.bound.height}`,width:""+this.bound.width,height:""+this.bound.height,xmlns:"http://www.w3.org/2000/svg",version:"1.1"}),this}static svgElement(t,e,i){if(!t||!t.appendChild)throw new Error("parent is not a valid DOM element");let r=document.querySelector("#"+i);return r||(r=document.createElementNS("http://www.w3.org/2000/svg",e),r.setAttribute("id",i),t.appendChild(r)),r}remove(t){return this._container.querySelectorAll("."+u.scopeID(t)).forEach(t=>{t.parentNode.removeChild(t)}),super.remove(t)}removeAll(){return this._container.innerHTML="",super.removeAll()}}e.SVGSpace=h;class u extends r.VisualForm{constructor(t){super(),this._style={filled:!0,stroked:!0,fill:"#f03",stroke:"#fff","stroke-width":1,"stroke-linejoin":"bevel","stroke-linecap":"sqaure",opacity:1},this._ctx={group:null,groupID:"pts",groupCount:0,currentID:"pts0",currentClass:"",style:{}},this._ready=!1,this._space=t,this._space.add({start:()=>{this._ctx.group=this._space.element,this._ctx.groupID="pts_svg_"+u.groupID++,this._ctx.style=Object.assign({},this._style),this._ready=!0}})}get space(){return this._space}styleTo(t,e){if(void 0===this._ctx.style[t])throw new Error(t+" style property doesn't exist");this._ctx.style[t]=e}alpha(t){return this.styleTo("opacity",t),this}fill(t){return"boolean"==typeof t?this.styleTo("filled",t):(this.styleTo("filled",!0),this.styleTo("fill",t)),this}stroke(t,e,i,r){return"boolean"==typeof t?this.styleTo("stroked",t):(this.styleTo("stroked",!0),this.styleTo("stroke",t),e&&this.styleTo("stroke-width",e),i&&this.styleTo("stroke-linejoin",i),r&&this.styleTo("stroke-linecap",r)),this}cls(t){return this._ctx.currentClass="boolean"==typeof t?"":t,this}font(t,e,i,r,s){return"number"==typeof t?(this._font.size=t,s&&(this._font.face=s),e&&(this._font.weight=e),i&&(this._font.style=i),r&&(this._font.lineHeight=r)):this._font=t,this._ctx.style.font=this._font.value,this}reset(){return this._ctx.style=Object.assign({},this._style),this._font=new r.Font(10,"sans-serif"),this._ctx.style.font=this._font.value,this}updateScope(t,e){return this._ctx.group=e,this._ctx.groupID=t,this._ctx.groupCount=0,this.nextID(),this._ctx}scope(t){if(!t||null==t.animateID)throw new Error("item not defined or not yet added to Space");return this.updateScope(u.scopeID(t),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-"+u.domID++}static scopeID(t){return"item-"+t.animateID}static style(t,e){let i=[];for(let t in e.filled||i.push("fill: none"),e.stroked||i.push("stroke: none"),e)if(e.hasOwnProperty(t)&&"filled"!=t&&"stroked"!=t){let r=e[t];if(r){if(!e.filled&&0===t.indexOf("fill"))continue;if(!e.stroked&&0===t.indexOf("stroke"))continue;i.push(`${t}: ${r}`)}}return l.DOMSpace.setAttr(t,{style:i.join(";")})}static point(t,e,i=5,r="square"){return"circle"===r?u.circle(t,e,i):u.square(t,e,i)}point(t,e=5,i="square"){return this.nextID(),u.point(this._ctx,t,e,i),this}static circle(t,e,i=10){let r=h.svgElement(t.group,"circle",u.getID(t));return l.DOMSpace.setAttr(r,{cx:e[0],cy:e[1],r:i,class:"pts-svgform pts-circle "+t.currentClass}),u.style(r,t.style),r}circle(t){this.nextID();let e=n.Util.iterToArray(t);return u.circle(this._ctx,e[0],e[1][0]),this}static arc(t,e,i,r,a,c){let d=h.svgElement(t.group,"path",u.getID(t));const p=new o.Pt(e).toAngle(r,i,!0),_=new o.Pt(e).toAngle(a,i,!0);let g=!!(s.Geom.boundAngle(a)-s.Geom.boundAngle(r)>n.Const.pi);c&&(g=!g);const f=c?"0":"1",m=`M ${p[0]} ${p[1]} A ${i} ${i} 0 ${g?"1":"0"} ${f} ${_[0]} ${_[1]}`;return l.DOMSpace.setAttr(d,{d:m,class:"pts-svgform pts-arc "+t.currentClass}),u.style(d,t.style),d}arc(t,e,i,r,s){return this.nextID(),u.arc(this._ctx,t,e,i,r,s),this}static square(t,e,i){let r=h.svgElement(t.group,"rect",u.getID(t));return l.DOMSpace.setAttr(r,{x:e[0]-i,y:e[1]-i,width:2*i,height:2*i,class:"pts-svgform pts-square "+t.currentClass}),u.style(r,t.style),r}square(t,e){return this.nextID(),u.square(this._ctx,t,e),this}static line(t,e){let i=u.pointsString(e);if(!(2>i.count)){if(2<i.count)return u._poly(t,i.string,!1);let r=h.svgElement(t.group,"line",u.getID(t)),s=n.Util.iterToArray(e);return l.DOMSpace.setAttr(r,{x1:s[0][0],y1:s[0][1],x2:s[1][0],y2:s[1][1],class:"pts-svgform pts-line "+t.currentClass}),u.style(r,t.style),r}}line(t){return this.nextID(),u.line(this._ctx,t),this}static _poly(t,e,i=!0){let r=h.svgElement(t.group,i?"polygon":"polyline",u.getID(t));return l.DOMSpace.setAttr(r,{points:e,class:"pts-svgform pts-polygon "+t.currentClass}),u.style(r,t.style),r}static pointsString(t){let e="",i=0;for(let r of t)e+=`${r[0]},${r[1]} `,i++;return{string:e,count:i}}static polygon(t,e){let i=u.pointsString(e);return u._poly(t,i.string,!0)}polygon(t){return this.nextID(),u.polygon(this._ctx,t),this}static rect(t,e){if(n.Util.arrayCheck(e)){let i=h.svgElement(t.group,"rect",u.getID(t)),r=o.Group.fromArray(e).boundingBox(),s=a.Rectangle.size(r);return l.DOMSpace.setAttr(i,{x:r[0][0],y:r[0][1],width:s[0],height:s[1],class:"pts-svgform pts-rect "+t.currentClass}),u.style(i,t.style),i}}rect(t){return this.nextID(),u.rect(this._ctx,t),this}static text(t,e,i){let r=h.svgElement(t.group,"text",u.getID(t));return l.DOMSpace.setAttr(r,{"pointer-events":"none",x:e[0],y:e[1],dx:0,dy:0,class:"pts-svgform pts-text "+t.currentClass}),r.textContent=i,u.style(r,t.style),r}text(t,e){return this.nextID(),u.text(this._ctx,t,e),this}log(t){return this.fill("#000").stroke("#fff",.5).text([10,14],t),this}}e.SVGForm=u,u.groupID=0,u.domID=0},"./src/Types.ts":function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0})},"./src/Typography.ts":function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Typography=void 0;const r=i("./src/Pt.ts");e.Typography=class{static textWidthEstimator(t,e=["M","n","."],i=[.06,.8,.14]){let s=e.map(t),n=new r.Pt(i).dot(s);return t=>t.length*n}static truncate(t,e,i,r=""){let s=u(e.length*h(1,i/t(e)));return s<e.length?(s=c(0,s-r.length),[e.substr(0,s)+r,s]):[e,e.length]}static fontSizeToBox(t,e=1,i=!0){let s=r.Bound.fromGroup(t),n=i?s.height:s.width;return function(t){let s=r.Bound.fromGroup(t),o=(i?s.height:s.width)/n;return e*n*o}}static fontSizeToThreshold(t,e=0){return function(i,r){let s=i*r/t;return 0>e?h(s,i):0<e?c(s,i):s}}}},"./src/UI.ts":function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.UIDragger=e.UIButton=e.UI=e.UIPointerActions=e.UIShape=void 0;const r=i("./src/Pt.ts"),s=i("./src/Op.ts");e.UIShape={rectangle:"rectangle",circle:"circle",polygon:"polygon",polyline:"polyline",line:"line"},e.UIPointerActions={up:"up",down:"down",move:"move",drag:"drag",uidrag:"uidrag",drop:"drop",uidrop:"uidrop",over:"over",out:"out",enter:"enter",leave:"leave",click:"click",contextmenu:"contextmenu",all:"all"};class n{constructor(t,e,i={},s){this._holds=new Map,this._group=r.Group.fromArray(t),this._shape=e,this._id=void 0===s?"ui_"+n._counter++:s,this._states=i,this._actions={}}static fromRectangle(t,i,r){return new this(t,e.UIShape.rectangle,i,r)}static fromCircle(t,i,r){return new this(t,e.UIShape.circle,i,r)}static fromPolygon(t,i,r){return new this(t,e.UIShape.polygon,i,r)}static fromUI(t,e,i){return new this(t.group,t.shape,e||t._states,i)}get id(){return this._id}set id(t){this._id=t}get group(){return this._group}set group(t){this._group=t}get shape(){return this._shape}set shape(t){this._shape=t}state(t,e){return t?void 0===e?this._states[t]:(this._states[t]=e,this):null}on(t,e){return this._actions[t]||(this._actions[t]=[]),n._addHandler(this._actions[t],e)}off(t,e){return!!this._actions[t]&&(void 0===e?(delete this._actions[t],!0):n._removeHandler(this._actions[t],e))}listen(t,e,i){if(void 0!==this._actions[t]){if(this._within(e)||0<=Array.from(this._holds.values()).indexOf(t))return n._trigger(this._actions[t],this,e,t,i),!0;if(this._actions.all)return n._trigger(this._actions.all,this,e,t,i),!0}return!1}hold(t){let e=c(0,...Array.from(this._holds.keys()))+1;return this._holds.set(e,t),e}unhold(t){void 0===t?this._holds.clear():this._holds.delete(t)}static track(t,e,i,r){for(let s=0,n=t.length;s<n;s++)t[s].listen(e,i,r)}render(t){t(this._group,this._states)}toString(){return"UI "+this.group.toString}_within(t){let i=null;if(this._shape===e.UIShape.rectangle)i=s.Rectangle.withinBound;else if(this._shape===e.UIShape.circle)i=s.Circle.withinBound;else{if(this._shape!==e.UIShape.polygon)return!1;i=s.Polygon.hasIntersectPoint}return i(this._group,t)}static _trigger(t,e,i,r,s){if(t)for(let n=0,o=t.length;n<o;n++)t[n]&&t[n](e,i,r,s)}static _addHandler(t,e){return e?(t.push(e),t.length-1):-1}static _removeHandler(t,e){if(0<=e&&e<t.length){let i=t.length;return t.splice(e,1),i>t.length}return!1}}e.UI=n,n._counter=0;class o extends n{constructor(t,i,r={},s){super(t,i,r,s),this._hoverID=-1,void 0===r.hover&&(this._states.hover=!1),void 0===r.clicks&&(this._states.clicks=0);const o=e.UIPointerActions;this.on(o.up,()=>{this.state("clicks",this._states.clicks+1)}),this.on(o.move,(t,e,i,r)=>{if(this._within(e)&&!this._states.hover){this.state("hover",!0),n._trigger(this._actions[o.enter],this,e,o.enter,r);var s=this.hold(o.move);this._hoverID=this.on(o.move,(t,i)=>{this._within(i)||this.state("dragging")||(this.state("hover",!1),n._trigger(this._actions[o.leave],this,e,o.leave,r),this.off(o.move,this._hoverID),this.unhold(s))})}})}onClick(t){return this.on(e.UIPointerActions.up,t)}offClick(t){return this.off(e.UIPointerActions.up,t)}onContextMenu(t){return this.on(e.UIPointerActions.contextmenu,t)}offContextMenu(t){return this.off(e.UIPointerActions.contextmenu,t)}onHover(t,i){var r=[void 0,void 0];return t&&(r[0]=this.on(e.UIPointerActions.enter,t)),i&&(r[1]=this.on(e.UIPointerActions.leave,i)),r}offHover(t,i){var r=[!1,!1];return(void 0===t||0<=t)&&(r[0]=this.off(e.UIPointerActions.enter,t)),(void 0===i||0<=i)&&(r[1]=this.off(e.UIPointerActions.leave,i)),r}}e.UIButton=o,e.UIDragger=class extends o{constructor(t,i,s={},o){super(t,i,s,o),this._draggingID=-1,this._moveHoldID=-1,this._dropHoldID=-1,this._upHoldID=-1,void 0===s.dragging&&(this._states.dragging=!1),void 0===s.moved&&(this._states.moved=!1),void 0===s.offset&&(this._states.offset=new r.Pt);const a=e.UIPointerActions;this.on(a.down,(t,e,i,s)=>{-1===this._moveHoldID&&(this.state("dragging",!0),this.state("offset",new r.Pt(e).subtract(t.group[0])),this._moveHoldID=this.hold(a.move)),-1===this._dropHoldID&&(this._dropHoldID=this.hold(a.drop)),-1===this._upHoldID&&(this._upHoldID=this.hold(a.up)),-1===this._draggingID&&(this._draggingID=this.on(a.move,(t,e)=>{this.state("dragging")&&(n._trigger(this._actions[a.uidrag],t,e,a.uidrag,s),this.state("moved",!0))}))});const l=(t,e,i,r)=>{this.state("dragging",!1),this.off(a.move,this._draggingID),this._draggingID=-1,this.unhold(this._moveHoldID),this._moveHoldID=-1,this.unhold(this._dropHoldID),this._dropHoldID=-1,this.unhold(this._upHoldID),this._upHoldID=-1,this.state("moved")&&(n._trigger(this._actions[a.uidrop],t,e,a.uidrop,r),this.state("moved",!1))};this.on(a.drop,l),this.on(a.up,l),this.on(a.out,l)}onDrag(t){return this.on(e.UIPointerActions.uidrag,t)}offDrag(t){return this.off(e.UIPointerActions.uidrag,t)}onDrop(t){return this.on(e.UIPointerActions.uidrop,t)}offDrop(t){return this.off(e.UIPointerActions.uidrop,t)}}},"./src/Util.ts":function(e,s,n){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.Util=s.Const=void 0;const o=n("./src/Pt.ts");s.Const={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:i,min:r,pi:t,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};class a{static warnLevel(t){return t&&(a._warnLevel=t),a._warnLevel}static getArgs(t){if(1>t.length)return[];let e=[],i=Array.isArray(t[0])||ArrayBuffer.isView(t[0]);if("number"==typeof t[0])e=Array.prototype.slice.call(t);else if("object"!=typeof t[0]||i)i&&(e=[].slice.call(t[0]));else{let i=["x","y","z","w"],r=t[0];for(let t=0;t<i.length&&!(r.length&&t>=r.length)&&i[t]in r;t++)e.push(r[i[t]])}return e}static warn(t="error",e){if("error"==a.warnLevel())throw new Error(t);return"warn"==a.warnLevel()&&console.warn(t),e}static randomInt(t,e=0){return a.warn("Util.randomInt is deprecated. Please use `Num.randomRange`"),u(Math.random()*t)+e}static split(t,e,i,r=!1,s=!0){let n=[],o=[],a=i||e,l=0;if(0>=t.length||0>=a)return[];for(;l<t.length;){o=[];for(let i=0;i<e;i++)if(r)o.push(t[(l+i)%t.length]);else{if(l+i>=t.length)break;o.push(t[l+i])}l+=a,(!s||s&&o.length===e)&&n.push(o)}return n}static flatten(t,e=!0){let i=e?new o.Group:[];return i.concat.apply(i,t)}static combine(t,e,i){let r=[];for(let s=0,n=t.length;s<n;s++)for(let n=0,o=e.length;n<o;n++)r.push(i(t[s],e[n]));return r}static zip(t){let e=[];for(let i,r=0,s=t[0].length;r<s;r++){i=[];for(let e=0;e<t.length;e++)i.push(t[e][r]);e.push(i)}return e}static stepper(t,e=0,i=1,r){let s=e;return function(){return s+=i,s>=t&&(s=e+(s-t)),r&&r(s),s}}static forRange(t,e,i=0,r=1){let s=[];for(let n=i;n<e;n+=r)s[n]=t(n);return s}static load(t,e){var i=new XMLHttpRequest;i.open("GET",t,!0),i.onload=function(){200<=i.status&&400>i.status?e(i.responseText,!0):e(`Server error (${i.status}) when loading "${t}"`,!1)},i.onerror=function(){e("Unknown network error",!1)},i.send()}static performance(t=10){let e=Date.now(),i=[];return function(){const r=Date.now();return i.push(r-e),i.length>=t&&i.shift(),e=r,u(i.reduce((t,e)=>t+e,0)/i.length)}}static arrayCheck(t,e=2){return!(Array.isArray(t)&&t.length<e&&(a.warn(`Requires ${e} or more Pts in this Group.`),1))}static iterToArray(t){return Array.isArray(t)?t:[...t]}static isMobile(){return/iPhone|iPad|Android/i.test(navigator.userAgent)}}s.Util=a,a._warnLevel="mute"},"./src/_lib.ts":function(t,e,i){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i),Object.defineProperty(t,r,{enumerable:!0,get:function(){return e[i]}})}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),e.quickStart=e.namespace=void 0,s(i("./src/Canvas.ts"),e),s(i("./src/Create.ts"),e),s(i("./src/Form.ts"),e),s(i("./src/LinearAlgebra.ts"),e),s(i("./src/Num.ts"),e),s(i("./src/Op.ts"),e),s(i("./src/Pt.ts"),e),s(i("./src/Space.ts"),e),s(i("./src/Color.ts"),e),s(i("./src/Util.ts"),e),s(i("./src/Dom.ts"),e),s(i("./src/Svg.ts"),e),s(i("./src/Typography.ts"),e),s(i("./src/Physics.ts"),e),s(i("./src/UI.ts"),e),s(i("./src/Play.ts"),e),s(i("./src/Image.ts"),e),s(i("./src/Types.ts"),e);const n=i("./src/Canvas.ts");e.namespace=e=>{let i=t.exports;for(let t in i)"namespace"!=t&&(e[t]=i[t])},e.quickStart=(t,i="#9ab")=>{if(!window)return;let r=window;return e.namespace(r),r.space=new n.CanvasSpace(t).setup({bgcolor:i,resize:!0,retina:!0}),r.form=r.space.getForm(),function(t=null,e=null,i=null,s=null){r.space.add({start:e,animate:t,resize:s,action:i}),r.space.bindMouse().bindTouch().play()}}}})}()}])}));
  7. //# sourceMappingURL=pts.min.js.map