Files
portfolio.sorlinv.fr/www/pts.min.js
2022-11-22 15:31:36 +01:00

7 lines
111 KiB
JavaScript
Executable File

/*!
* pts.js 0.10.9 (minified es6) - Copyright © 2017-2021 William Ngan and contributors.
* Licensed under Apache 2.0 License.
* See https://github.com/williamngan/pts for details.
*/
!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(i){if(r[i])return r[i].exports;var s=r[i]={i:i,l:!1,exports:{}};return t[i].call(s.exports,s,s.exports,e),s.l=!0,s.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,i){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:i})},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,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(e.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var s in t)e.d(i,s,function(e){return t[e]}.bind(null,s));return i},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},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,r=Number.MAX_VALUE,i=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.ceil,d=Math.max;return function(t){function e(i){if(r[i])return r[i].exports;var s=r[i]={i:i,l:!1,exports:{}};return t[i].call(s.exports,s,s.exports,e),s.l=!0,s.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,i){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:i})},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,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(e.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var s in t)e.d(i,s,function(e){return t[e]}.bind(null,s));return i},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},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,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.CanvasForm=e.CanvasSpace=void 0;const i=r("./src/Space.ts"),s=r("./src/Form.ts"),n=r("./src/Pt.ts"),o=r("./src/Util.ts"),a=r("./src/Typography.ts"),l=r("./src/Op.ts"),h=r("./src/Image.ts");class u extends i.MultiTouchSpace{constructor(t,e){super(),this._pixelScale=1,this._autoResize=!0,this._bgcolor="#e1e9f0",this._offscreen=!1,this._initialResize=!1;var r=null;if(this.id="pt",t instanceof Element)r=t,this.id="pts_existing_space";else{let e=t;e="#"===t[0]||"."===t[0]?t:"#"+t,r=document.querySelector(e),this.id=e.substr(1)}r?"canvas"==r.nodeName.toLowerCase()?(this._canvas=r,this._container=r.parentElement,this._autoResize=!1):(this._container=r,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 r=document.createElement(t);return r.setAttribute("id",e),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._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=d(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,t.pixelDensity&&(this._pixelScale=t.pixelDensity),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 r in this.bound=t,this._canvas.width=c(this.bound.size.x)*this._pixelScale,this._canvas.height=c(this.bound.size.y)*this._pixelScale,this._canvas.style.width=c(this.bound.size.x)+"px",this._canvas.style.height=c(this.bound.size.y)+"px",this._offscreen&&(this._offCanvas.width=c(this.bound.size.x)*this._pixelScale,this._offCanvas.height=c(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(r)){let t=this.players[r];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 r=n.Bound.fromBoundingRect(e);r.center=r.center.add(window.pageXOffset,window.pageYOffset),this.resize(r,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,r=c(this.pixelScale);return this._bgcolor&&"transparent"!==this._bgcolor?((0===this._bgcolor.indexOf("rgba")||9===this._bgcolor.length&&0===this._bgcolor.indexOf("#"))&&this._ctx.clearRect(-r,-r,this._canvas.width+r,this._canvas.height+r),this._ctx.fillStyle=this._bgcolor,this._ctx.fillRect(-r,-r,this._canvas.width+r,this._canvas.height+r)):this._ctx.clearRect(-r,-r,this._canvas.width+r,this._canvas.height+r),this._ctx.fillStyle=e,this}clearOffscreen(t){if(this._offscreen){const e=c(this.pixelScale);t?(this._offCtx.fillStyle=t,this._offCtx.fillRect(-e,-e,this._canvas.width+e,this._canvas.height+e)):this._offCtx.clearRect(-e,-e,this._offCanvas.width+e,this._offCanvas.height+e)}return 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",r=15e6){let i=this._canvas.captureStream();const s=new MediaRecorder(i,{mimeType:"video/"+e,bitsPerSecond:r});return s.ondataavailable=function(r){let i=URL.createObjectURL(new Blob([r.data],{type:"video/"+e}));if("function"==typeof t)t(i);else if(t){let t=document.createElement("a");t.href=i,t.download="canvas_video."+e,t.click(),t.remove()}},s}}e.CanvasSpace=u;class p extends s.VisualForm{constructor(t){if(super(),this._style={fillStyle:"#f03",strokeStyle:"#fff",lineWidth:1,lineJoin:"bevel",lineCap:"butt",globalAlpha:1},!t)return this;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,r,i){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),r&&(this._ctx.lineJoin=r,this._style.lineJoin=r),i&&(this._ctx.lineCap=i,this._style.lineCap=i)),this}applyFillStroke(t=!0,e=!0,r=1){return t&&("string"==typeof t&&this.fill(t),this._ctx.fill()),e&&("string"==typeof e&&this.stroke(e,r),this._ctx.stroke()),this}gradient(t){let e=[];2>t.length&&t.push([.99,"#000"],[1,"#000"]);for(let r=0,i=t.length;r<i;r++){let i="string"==typeof t[r]?r*(1/(t.length-1)):t[r][0],s="string"==typeof t[r]?t[r]:t[r][1];e.push([i,s])}return(t,r)=>{t=t.map(t=>t.abs()),r&&r.map(t=>t.abs());let i=r?this.ctx.createRadialGradient(t[0][0],t[0][1],t[1][0],r[0][0],r[0][1],r[1][0]):this.ctx.createLinearGradient(t[0][0],t[0][1],t[1][0],t[1][1]);for(let t=0,r=e.length;t<r;t++)i.addColorStop(e[t][0],e[t][1]);return i}}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,r,i,s){return"number"==typeof t?(this._font.size=t,s&&(this._font.face=s),e&&(this._font.weight=e),r&&(this._font.style=r),i&&(this._font.lineHeight=i)):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,r=""){return a.Typography.truncate(this.getTextWidth.bind(this),t,e,r)}_textAlign(t,e,r,i){let s=o.Util.iterToArray(t);if(o.Util.arrayCheck(s)){i||(i=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=i[0]);var h=i[1];return"top"==e||"start"==e?h=s[0][1]:("end"==e||"bottom"==e)&&(h=s[1][1]),r?new n.Pt(a+r[0],h+r[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,r=5,i="square"){if(e){if(!p[i])throw new Error(i+" is not a static function of CanvasForm");p[i](t,e,r)}}point(t,e=5,r="square"){return p.point(this._ctx,t,e,r),this._paint(),this}static circle(t,e,r=10){e&&(t.beginPath(),t.arc(e[0],e[1],r,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,r,i=0,s=0,n=o.Const.two_pi,a=!1){e&&r&&(t.beginPath(),t.ellipse(e[0],e[1],r[0],r[1],i,s,n,a))}ellipse(t,e,r=0,i=0,s=o.Const.two_pi,n=!1){return p.ellipse(this._ctx,t,e,r,i,s,n),this._paint(),this}static arc(t,e,r,i,s,n){e&&(t.beginPath(),t.arc(e[0],e[1],r,i,s,n))}arc(t,e,r,i,s){return p.arc(this._ctx,t,e,r,i,s),this._paint(),this}static square(t,e,r){if(e){let i=e[0]-r,s=e[1]-r,n=e[0]+r,o=e[1]+r;t.beginPath(),t.moveTo(i,s),t.lineTo(i,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 r=0;t.beginPath();for(let i of e)i&&(0<r++?t.lineTo(i[0],i[1]):t.moveTo(i[0],i[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 r=o.Util.iterToArray(e);o.Util.arrayCheck(r)&&(t.beginPath(),t.moveTo(r[0][0],r[0][1]),t.lineTo(r[0][0],r[1][1]),t.lineTo(r[1][0],r[1][1]),t.lineTo(r[1][0],r[0][1]),t.closePath())}rect(t){return p.rect(this._ctx,t),this._paint(),this}static image(t,e,r,i){let s,n=o.Util.iterToArray(e);if("number"==typeof n[0])s=n;else if(i){let t=o.Util.iterToArray(i);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]];r instanceof h.Img?r.loaded&&t.drawImage(r.image,...s):t.drawImage(r,...s)}image(t,e,r){return e instanceof h.Img?e.loaded&&p.image(this._ctx,t,e.image,r):p.image(this._ctx,t,e,r),this}static imageData(t,e,r){let i=o.Util.iterToArray(e);"number"==typeof i[0]?t.putImageData(r,i[0],i[1]):t.putImageData(r,i[0][0],i[0][1],i[0][0],i[0][1],i[1][0],i[1][1])}imageData(t,e){return p.imageData(this._ctx,t,e),this}static text(t,e,r,i){e&&t.fillText(r,e[0],e[1],i)}text(t,e,r){return p.text(this._ctx,t,e,r),this}textBox(t,e,r="middle",i="",s=!0){s&&(this._ctx.textBaseline=r);let n=l.Rectangle.size(t),o=this._textTruncate(e,n[0],i);return this.text(this._textAlign(t,r),o[0]),this}paragraphBox(t,e,r=1.2,i="top",s=!0){let a=o.Util.iterToArray(t),h=l.Rectangle.size(a);this._ctx.textBaseline="top";let u=this._font.size*r,c=(t,e=[],r=0)=>{if(!t)return e;if(s&&r*u>h[1]-2*u)return e;if(1e4<r)throw new Error("max recursion reached (10000)");let i=this._textTruncate(t,h[0],""),n=i[0].indexOf("\n");if(0<=n)return e.push(i[0].substr(0,n)),c(t.substr(n+1),e,r+1);let o=i[0].lastIndexOf(" ")+1;(0>=o||i[1]===t.length)&&(o=void 0);let a=i[0].substr(0,o);return e.push(a),0>=i[1]||i[1]===t.length?e:c(t.substr(o||i[1]),e,r+1)},p=c(e),_=p.length*u,g=a;if("middle"==i||"center"==i){let t=(h[1]-_)/2;s&&(t=d(0,t)),g=new n.Group(a[0].$add(0,t),a[1].$subtract(0,t))}else g="bottom"==i?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,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Color=void 0;const i=r("./src/Pt.ts"),c=r("./src/Util.ts"),p=r("./src/Num.ts");class _ extends i.Pt{constructor(...t){super(...t),this._mode="rgb",this._isNorm=!1}static from(...t){let e=[1,1,1,1],r=c.Util.getArgs(t);for(let t=0,i=e.length;t<i;t++)t<r.length&&(e[t]=r[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 r=parseInt(t,16);return new _(r>>16,255&r>>8,255&r,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 r=0;3>r;r++)this[r]=t?p.Num.mapToRange(this[r],e[r][0],e[r][1],0,1):p.Num.mapToRange(this[r],0,1,e[r][0],e[r][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,r=!1){let[i,s,n]=e?t:t.$normalize(),o=d(i,s,n),a=h(i,s,n),l=(o+a)/2,u=l,c=l;if(o==a)l=0,u=0;else{let t=o-a;u=.5<c?t/(2-o-a):t/(o+a),l=0,o===i?l=(s-n)/t+(s<n?6:0):o===s?l=(n-i)/t+2:o===n&&(l=(i-s)/t+4)}return _.hsl(r?l/60:60*l,u,c,t.alpha)}static HSLtoRGB(t,e=!1,r=!1){let[i,s,n]=t;if(e||(i/=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=r?1:255;return _.rgb(h*l(i+1/3),h*l(i),h*l(i-1/3),t.alpha)}static RGBtoHSB(t,e=!1,r=!1){let[i,s,n]=e?t:t.$normalize(),o=d(i,s,n),a=h(i,s,n),l=o-a,u=0,c=0===o?0:l/o;return o!=a&&(o===i?u=(s-n)/l+(s<n?6:0):o===s?u=(n-i)/l+2:o===n&&(u=(i-s)/l+4)),_.hsb(r?u/60:60*u,c,o,t.alpha)}static HSBtoRGB(t,e=!1,r=!1){let[i,s,n]=t;e||(i/=360);let o=u(6*i),a=6*i-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=r?1:255;return _.rgb(p*d[0],p*d[1],p*d[2],t.alpha)}static RGBtoLAB(t,e=!1,r=!1){let i=e?t.$normalize(!1):t;return _.XYZtoLAB(_.RGBtoXYZ(i),!1,r)}static LABtoRGB(t,e=!1,r=!1){let i=e?t.$normalize(!1):t;return _.XYZtoRGB(_.LABtoXYZ(i),!1,r)}static RGBtoLCH(t,e=!1,r=!1){let i=e?t.$normalize(!1):t;return _.LABtoLCH(_.RGBtoLAB(i),!1,r)}static LCHtoRGB(t,e=!1,r=!1){let i=e?t.$normalize(!1):t;return _.LABtoRGB(_.LCHtoLAB(i),!1,r)}static RGBtoLUV(t,e=!1,r=!1){let i=e?t.$normalize(!1):t;return _.XYZtoLUV(_.RGBtoXYZ(i),!1,r)}static LUVtoRGB(t,e=!1,r=!1){let i=e?t.$normalize(!1):t;return _.XYZtoRGB(_.LUVtoXYZ(i),!1,r)}static RGBtoXYZ(t,e=!1,r=!1){let i=e?t.clone():t.$normalize();for(let t=0;3>t;t++)i[t]=.04045<i[t]?l((i[t]+.055)/1.055,2.4):i[t]/12.92,r||(i[t]*=100);let s=_.xyz(.4124564*i[0]+.3575761*i[1]+.1804375*i[2],.2126729*i[0]+.7151522*i[1]+.072175*i[2],.0193339*i[0]+.119192*i[1]+.9503041*i[2],t.alpha);return r?s.normalize():s}static XYZtoRGB(t,e=!1,r=!1){let[i,s,n]=e?t:t.$normalize(),o=[3.2406254773200533*i+-1.5372079722103187*s+-.4986285986982479*n,-.9689307147293197*i+1.8757560608852415*s+.041517523842953964*n,.055710120445510616*i+-.2040210505984867*s+1.0569959422543882*n];for(let t=0;3>t;t++)o[t]=.0031308<o[t]?1.055*l(o[t],1/2.4)-.055:12.92*o[t],o[t]=d(0,h(1,o[t])),r||(o[t]=Math.round(255*o[t]));let a=_.rgb(o[0],o[1],o[2],t.alpha);return r?a.normalize():a}static XYZtoLAB(t,e=!1,r=!1){let i=e?t.$normalize(!1):t.clone();i.divide(_.D65);let s=t=>t>.00885645167?l(t,1/3):(903.296296296*t+16)/116,n=s(i[1]),o=_.lab(116*n-16,500*(s(i[0])-n),200*(n-s(i[2])),t.alpha);return r?o.normalize():o}static LABtoXYZ(t,e=!1,r=!1){let i=e?t.$normalize(!1):t,s=(i[0]+16)/116,n=i[1]/500+s,o=s-i[2]/200;const a=.00885645167,h=903.296296296;let u=_.D65;const c=l(n,3),d=l(o,3);let p=_.xyz(u[0]*(c>a?c:(116*n-16)/h),u[1]*(i[0]>h*a?l((i[0]+16)/116,3):i[0]/h),u[2]*(d>a?d:(116*o-16)/h),t.alpha);return r?p.normalize():p}static XYZtoLUV(t,e=!1,r=!1){let[i,s,n]=e?t.$normalize(!1):t,o=4*i/(i+15*s+3*n),a=9*s/(i+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,r=!1){let[i,s,n]=e?t.$normalize(!1):t,o=(i+16)/116,a=o*o*o;o=.008856<a?a:(o-16/116)/7.787,s=s/(13*i)+4*_.D65[0]/(_.D65[0]+15*_.D65[1]+3*_.D65[2]),n=n/(13*i)+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,r=!1){let i=e?t.$normalize(!1):t,s=p.Geom.toDegree(p.Geom.boundRadian(a(i[2],i[1])));return _.lch(i[0],o(i[1]*i[1]+i[2]*i[2]),s,t.alpha)}static LCHtoLAB(t,e=!1,r=!1){let i=e?t.$normalize(!1):t,o=p.Geom.toRadian(i[2]);return _.lab(i[0],n(o)*i[1],s(o)*i[1],t.alpha)}}e.Color=_,_.D65=new i.Pt(95.047,100,108.883,1),_.ranges={rgb:new i.Group(new i.Pt(0,255),new i.Pt(0,255),new i.Pt(0,255)),hsl:new i.Group(new i.Pt(0,360),new i.Pt(0,1),new i.Pt(0,1)),hsb:new i.Group(new i.Pt(0,360),new i.Pt(0,1),new i.Pt(0,1)),lab:new i.Group(new i.Pt(0,100),new i.Pt(-128,127),new i.Pt(-128,127)),lch:new i.Group(new i.Pt(0,100),new i.Pt(0,100),new i.Pt(0,360)),luv:new i.Group(new i.Pt(0,100),new i.Pt(-134,220),new i.Pt(-140,122)),xyz:new i.Group(new i.Pt(0,100),new i.Pt(0,100),new i.Pt(0,100))}},"./src/Create.ts":function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Delaunay=e.Noise=e.Create=void 0;const i=r("./src/Pt.ts"),s=r("./src/Op.ts"),n=r("./src/Util.ts"),o=r("./src/Num.ts"),a=r("./src/LinearAlgebra.ts");e.Create=class{static distributeRandom(t,e,r=2){let s=new i.Group;for(let n,a=0;a<e;a++)n=[t.x+o.Num.random()*t.width],1<r&&n.push(t.y+o.Num.random()*t.height),2<r&&n.push(t.z+o.Num.random()*t.depth),s.push(new i.Pt(n));return s}static distributeLinear(t,e){let r=n.Util.iterToArray(t),i=s.Line.subpoints(r,e-2);return i.unshift(r[0]),i.push(r[r.length-1]),i}static gridPts(t,e,r,s=[.5,.5]){if(0===e||0===r)throw new Error("grid columns and rows cannot be 0");let n=t.size.$subtract(1).$divide(e,r),o=n.$multiply(s),a=new i.Group;for(let i=0;i<r;i++)for(let r=0;r<e;r++)a.push(t.topLeft.$add(n.$multiply(r,i)).add(o));return a}static gridCells(t,e,r){if(0===e||0===r)throw new Error("grid columns and rows cannot be 0");let s=t.size.$subtract(1).divide(e,r),n=[];for(let o=0;o<r;o++)for(let r=0;r<e;r++)n.push(new i.Group(t.topLeft.$add(s.$multiply(r,o)),t.topLeft.$add(s.$multiply(r,o).add(s))));return n}static radialPts(t,e,r,s=-n.Const.half_pi){let o=new i.Group,a=n.Const.two_pi/r;for(let n=0;n<r;n++)o.push(new i.Pt(t).toAngle(a*n+s,e,!0));return o}static noisePts(t,e=.01,r=.01,s=0,n=0){let a=o.Num.random(),l=new i.Group,h=0;for(let i of t){let t=new p(i),o=s&&0<s?u(h/s):h,c=n&&0<n?h%n:h;t.initNoise(e*c,r*o),t.seed(a),l.push(t),h++}return l}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]],c=[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 i.Pt{constructor(...t){super(...t),this.perm=[],this._n=new i.Pt(.01,.01),this.perm=c.concat(c)}initNoise(...t){return this._n=new i.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,r=0;255>r;r++)e=1&r?c[r]^255&t:c[r]^255&t>>8,this.perm[r]=this.perm[r+256]=e;return this}noise2D(){let t=d(0,u(this._n[0]))%255,e=d(0,u(this._n[1]))%255,r=this._n[0]%255-t,i=this._n[1]%255-e,s=a.Vec.dot(l[(t+this.perm[e])%12],[r,i,0]),n=a.Vec.dot(l[(t+this.perm[e+1])%12],[r,i-1,0]),h=a.Vec.dot(l[(t+1+this.perm[e])%12],[r-1,i,0]),c=a.Vec.dot(l[(t+1+this.perm[e+1])%12],[r-1,i-1,0]),p=t=>t*t*t*(t*(6*t-15)+10),_=p(r);return o.Num.lerp(o.Num.lerp(s,h,_),o.Num.lerp(n,c,_),p(i))}}e.Noise=p;class _ extends i.Group{constructor(){super(...arguments),this._mesh=[]}delaunay(t=!0){if(3>this.length)return[];this._mesh=[];let e=this.length,r=[];for(let t=0;t<e;t++)r[t]=t;r.sort((t,e)=>this[e][0]-this[t][0]);let i=this.slice(),s=this._superTriangle();i=i.concat(s);let o=[this._circum(e,e+1,e+2,s)],a=[],l=[];for(let t=0,e=r.length;t<e;t++){let e=r[t],s=[],h=o.length;for(this._mesh[e]||(this._mesh[e]={});h--;){let t=o[h],r=t.circle[1][0],u=i[e].$subtract(t.circle[0]);0<u[0]&&u[0]*u[0]>r*r?(a.push(t),l.push(t.triangle),o.splice(h,1)):u[0]*u[0]+u[1]*u[1]-r*r>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,i))}for(let t,r=0,i=o.length;r<i;r++)t=o[r],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,r=this._mesh.length;e<r;e++)t.push(this.neighborPts(e,!0));return t}mesh(){return this._mesh}neighborPts(t,e=!1){let r=new i.Group,s=this._mesh;for(let e in s[t])s[t].hasOwnProperty(e)&&r.push(s[t][e].circle[0]);return e?o.Geom.sortEdges(r):r}neighbors(t){let e=[],r=this._mesh;for(let i in r[t])r[t].hasOwnProperty(i)&&e.push(r[t][i]);return e}_cache(t){this._mesh[t.i][`${h(t.j,t.k)}-${d(t.j,t.k)}`]=t,this._mesh[t.j][`${h(t.i,t.k)}-${d(t.i,t.k)}`]=t,this._mesh[t.k][`${h(t.i,t.j)}-${d(t.i,t.j)}`]=t}_superTriangle(){let t=this[0],e=this[0];for(let r=1,i=this.length;r<i;r++)t=t.$min(this[r]),e=e.$max(this[r]);let r=e.$subtract(t),s=t.$add(e).divide(2),n=d(r[0],r[1]);return new i.Group(s.$subtract(20*n,n),s.$add(0,20*n),s.$add(20*n,-n))}_triangle(t,e,r,s=this){return new i.Group(s[t],s[e],s[r])}_circum(t,e,r,i,n=this){let o=i||this._triangle(t,e,r,n);return{i:t,j:e,k:r,triangle:o,circle:s.Triangle.circumcircle(o)}}static _dedupe(t){for(let e=t.length;1<e;)for(let r=t[--e],i=t[--e],s=e;1<s;){let n=t[--s],o=t[--s];if(i==o&&r==n||i==n&&r==o){t.splice(e,2),t.splice(s,2);break}}return t}}e.Delaunay=_},"./src/Dom.ts":function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.HTMLForm=e.HTMLSpace=e.DOMSpace=void 0;const i=r("./src/Space.ts"),s=r("./src/Form.ts"),n=r("./src/Util.ts"),o=r("./src/Pt.ts");class a extends i.MultiTouchSpace{constructor(t,e){super(),this.id="domspace",this._autoResize=!0,this._bgcolor="#e1e9f0",this._css={};var r=null;this.id="pts",t instanceof Element?(r=t,this.id="pts_existing_space"):(r=document.querySelector(t),this.id=t.substr(1)),r?(this._canvas=r,this._container=r.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,r){let i=document.createElement(t);return e&&i.setAttribute("id",e),r&&r.appendChild&&r.appendChild(i),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.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 r in this.bound=t,this.styles({width:t.width+"px",height:t.height+"px"},!0),this.players)if(this.players.hasOwnProperty(r)){let t=this.players[r];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,r=!1){return this._css[t]=e,r&&(this._canvas.style[t]=e),this}styles(t,e=!1){for(let r in t)t.hasOwnProperty(r)&&this.style(r,t[r],e);return this}static setAttr(t,e){for(let r in e)e.hasOwnProperty(r)&&t.setAttribute(r,e[r]);return t}static getInlineStyles(t){let e="";for(let r in t)t.hasOwnProperty(r)&&t[r]&&(e+=`${r}: ${t[r]}; `);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,r,i=!0){if(!t||!t.appendChild)throw new Error("parent is not a valid DOM element");let s=document.querySelector("#"+r);return s||(s=document.createElement(e),s.setAttribute("id",r),i&&s.setAttribute("class",r.substring(0,r.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,r=""){if(void 0===this._ctx.style[t])throw new Error(t+" style property doesn't exist");this._ctx.style[t]=`${e}${r}`}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,r,i,s){return"number"==typeof t?(this._font.size=t,s&&(this._font.face=s),e&&(this._font.weight=e),r&&(this._font.style=r),i&&(this._font.lineHeight=i)):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 r=[];for(let t in e.filled||r.push("background: none"),e.stroked||r.push("border: none"),e)if(e.hasOwnProperty(t)&&"filled"!=t&&"stroked"!=t){let i=e[t];if(i){if(!e.filled&&0===t.indexOf("background"))continue;if(!e.stroked&&0===t.indexOf("border-width"))continue;r.push(`${t}: ${i}`)}}return l.setAttr(t,{style:r.join(";")})}static rectStyle(t,e,r){return t.style.left=e[0]+"px",t.style.top=e[1]+"px",t.style.width=r[0]+"px",t.style.height=r[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,r=5,i="square"){return"circle"===i?h.circle(t,e,r):h.square(t,e,r)}point(t,e=5,r="square"){return this.nextID(),"circle"==r&&this.styleTo("border-radius","100%"),h.point(this._ctx,t,e,r),this}static circle(t,e,r=10){let i=l.htmlElement(t.group,"div",h.getID(t));return l.setAttr(i,{class:"pts-form pts-circle "+t.currentClass}),h.rectStyle(t,new o.Pt(e).$subtract(r),new o.Pt(2*r,2*r)),h.style(i,t.style),i}circle(t){return this.nextID(),this.styleTo("border-radius","100%"),h.circle(this._ctx,t[0],t[1][0]),this}static square(t,e,r){let i=l.htmlElement(t.group,"div",h.getID(t));return l.setAttr(i,{class:"pts-form pts-square "+t.currentClass}),h.rectStyle(t,new o.Pt(e).$subtract(r),new o.Pt(2*r,2*r)),h.style(i,t.style),i}square(t,e){return this.nextID(),h.square(this._ctx,t,e),this}static rect(t,e){let r=n.Util.iterToArray(e);if(n.Util.arrayCheck(r)){let e=l.htmlElement(t.group,"div",h.getID(t));return l.setAttr(e,{class:"pts-form pts-rect "+t.currentClass}),h.rectStyle(t,r[0],r[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,r){let i=l.htmlElement(t.group,"div",h.getID(t));return l.setAttr(i,{class:"pts-form pts-text "+t.currentClass}),i.textContent=r,h.textStyle(t,e),h.style(i,t.style),i}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 r{constructor(){this._ready=!1}get ready(){return this._ready}}e.Form=r,e.VisualForm=class extends r{constructor(){super(...arguments),this._filled=!0,this._stroked=!0,this._font=new i(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,...r){if(!t)return this;for(let i=0,s=t.length;i<s;i++)this[e](t[i],...r);return this}alpha(){return this}fill(){return this}fillOnly(t){return this.stroke(!1),this.fill(t)}stroke(){return this}strokeOnly(t,e,r,i){return this.fill(!1),this.stroke(t,e,r,i)}points(t,e,r){if(t){for(let i=0,s=t.length;i<s;i++)this.point(t[i],e,r);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 i{constructor(t=12,e="sans-serif",r="",i="",s=1.5){this.size=t,this.face=e,this.style=i,this.weight=r,this.lineHeight=s}get value(){return`${this.style} ${this.weight} ${this.size}px/${this.lineHeight} ${this.face}`}toString(){return this.value}}e.Font=i},"./src/Image.ts":function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Img=void 0;const i=r("./src/Pt.ts");class s{constructor(t=!1,e=1,r){this._scale=1,this._loaded=!1,this._editable=t,this._scale=e,this._img=new Image,r&&(this._img.crossOrigin="Anonymous")}static load(t,e=!1,r=1,i){let n=new s(e,r);return n.load(t).then(t=>{i&&i(t)}),n}load(t){return new Promise((e,r)=>{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=>{r(t)}})}_drawToScale(t,e){const r="number"==typeof t?[t,t]:t,i=e.width,s=e.height;this._cv.width=i*r[0],this._cv.height=s*r[1],this._ctx=this._cv.getContext("2d"),e&&this._ctx.drawImage(e,0,0,i,s,0,0,this._cv.width,this._cv.height)}bitmap(t){const e=t?t[0]:this._cv.width,r=t?t[1]:this._cv.height;return createImageBitmap(this._cv,0,0,e,r)}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 r="number"==typeof e?e:e?this._scale:1;return s.getPixel(this._data,[t[0]*r,t[1]*r])}static getPixel(t,e){const r=new i.Pt(0,0,0,0);if(e[0]>=t.width||e[1]>=t.height)return r;const s=u(e[1])*(4*t.width)+4*u(e[0]),n=t.data;return s>=n.length-4?r:new i.Pt(n[s],n[s+1],n[s+2],n[s+3])}resize(t,e=!1){let r=e?t:[t[0]/this._img.naturalWidth,t[1]/this._img.naturalHeight];return this._drawToScale(r,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),r=t.size.scale(this._scale);return this._ctx.getImageData(e.x,e.y,r.x,r.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,r=1){let i=URL.createObjectURL(t);return new s(e,r).load(i)}static imageDataToBlob(t){return new Promise((function(e){let r=document.createElement("canvas");r.width=t.width,r.height=t.height,r.getContext("2d").putImageData(t,0,0),r.toBlob(t=>{e(t),r.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 i.Pt(this._img.width,this._img.height)}get canvasSize(){return new i.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 c{static add(t,e){if("number"==typeof e)for(let r=0,i=t.length;r<i;r++)t[r]+=e;else for(let r=0,i=t.length;r<i;r++)t[r]+=e[r]||0;return t}static subtract(t,e){if("number"==typeof e)for(let r=0,i=t.length;r<i;r++)t[r]-=e;else for(let r=0,i=t.length;r<i;r++)t[r]-=e[r]||0;return t}static multiply(t,e){if("number"==typeof e)for(let r=0,i=t.length;r<i;r++)t[r]*=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 r=0,i=t.length;r<i;r++)t[r]*=e[r]}return t}static divide(t,e){if("number"==typeof e){if(0===e)throw new Error("Cannot divide by zero");for(let r=0,i=t.length;r<i;r++)t[r]/=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 r=0,i=t.length;r<i;r++)t[r]/=e[r]}return t}static dot(t,e){if(t.length!=e.length)throw new Error("Array lengths don't match");let r=0;for(let i=0,s=t.length;i<s;i++)r+=t[i]*e[i];return r}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(c.dot(t,t))}static unit(t,e){let r=void 0===e?c.magnitude(t):e;return 0===r?l.Pt.make(t.length):c.divide(t,r)}static abs(t){return c.map(t,Math.abs)}static floor(t){return c.map(t,Math.floor)}static ceil(t){return c.map(t,Math.ceil)}static round(t){return c.map(t,Math.round)}static max(t){let e=i,r=0;for(let i=0,s=t.length;i<s;i++)e=d(e,t[i]),e===t[i]&&(r=i);return{value:e,index:r}}static min(t){let e=r,i=0;for(let r=0,s=t.length;r<s;r++)e=h(e,t[r]),e===t[r]&&(i=r);return{value:e,index:i}}static sum(t){let e=0;for(let r=0,i=t.length;r<i;r++)e+=t[r];return e}static map(t,e){for(let r=0,i=t.length;r<i;r++)t[r]=e(t[r],r,t);return t}}e.Vec=c;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 r=new l.Group;for(let i=0,s=t.length;i<s;i++)r.push(t[i].$add("number"==typeof e?e:e[i]));return r}static multiply(t,e,r=!1,i=!1){let s=new l.Group;if("number"==typeof e)for(let r=0,i=t.length;r<i;r++)s.push(t[r].$multiply(e));else if(i){if(t.length!=e.length)throw new Error("Cannot multiply matrix element-wise because the matrices' sizes don't match.");for(let r=0,i=t.length;r<i;r++)s.push(t[r].$multiply(e[r]))}else{if(!r&&t[0].length!=e.length)throw new Error("Cannot multiply matrix if rows in matrix-a don't match columns in matrix-b.");if(r&&t[0].length!=e[0].length)throw new Error("Cannot multiply matrix if transposed and the columns in both matrices don't match.");r||(e=p.transpose(e));for(let r,i=0,n=t.length;i<n;i++){r=l.Pt.make(e.length,0);for(let s=0,n=e.length;s<n;s++)r[s]=c.dot(t[i],e[s]);s.push(r)}}return s}static zipSlice(t,e,r=!1){let i=[];for(let s=0,n=t.length;s<n;s++){if(t[s].length-1<e&&!1===r)throw`Index ${e} is out of bounds`;i.push(t[s][e]||r)}return new l.Pt(i)}static zip(t,e=!1,r=!1){let i=new l.Group,s=r?t.reduce((t,e)=>d(t,e.length),0):t[0].length;for(let r=0;r<s;r++)i.push(p.zipSlice(t,r,e));return i}static transpose(t,e=!1,r=!1){return p.zip(t,e,r)}static transform2D(t,e){let r=t[0]*e[0][0]+t[1]*e[1][0]+e[2][0],i=t[0]*e[0][1]+t[1]*e[1][1]+e[2][1];return new l.Pt(r,i)}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,r){let i=p.scale2DMatrix(t,e);return i[2][0]=-r[0]*t+r[0],i[2][1]=-r[1]*e+r[1],i}static rotateAt2DMatrix(t,e,r){let i=p.rotate2DMatrix(t,e);return i[2][0]=r[0]*(1-t)+r[1]*e,i[2][1]=r[1]*(1-t)-r[0]*e,i}static shearAt2DMatrix(t,e,r){let i=p.shear2DMatrix(t,e);return i[2][0]=-r[1]*e,i[2][1]=-r[0]*t,i}static reflectAt2DMatrix(t,e){let r=u.Line.intercept(t,e);if(null==r)return[new l.Pt([-1,0,0]),new l.Pt([0,1,0]),new l.Pt([t[0]+e[0],0,1])];{let t=r.yi,e=2*Math.atan(r.slope),i=n(e),o=s(e);return[new l.Pt([i,o,0]),new l.Pt([o,-i,0]),new l.Pt([-t*o,t+t*i,1])]}}}e.Mat=p},"./src/Num.ts":function(r,i,a){"use strict";var c=Math.exp;Object.defineProperty(i,"__esModule",{value:!0}),i.Range=i.Shaping=i.Geom=i.Num=void 0;const p=a("./src/Util.ts"),_=a("./src/Op.ts"),g=a("./src/Pt.ts"),f=a("./src/LinearAlgebra.ts"),m=a("./src/uheprng.ts");class y{static equals(t,r,i=1e-5){return e(t-r)<i}static lerp(t,e,r){return(1-r)*t+r*e}static clamp(t,e,r){return d(e,h(r,t))}static boundValue(t,r,i){let s=e(i-r),n=t%s;return n>i?n-=s:n<r&&(n+=s),n}static within(t,e,r){return t>=h(e,r)&&t<=d(e,r)}static randomRange(t,e=0){let r=t>e?t-e:e-t;return t+y.random()*r}static randomPt(t,e){let r=new g.Pt(t.length),i=e?f.Vec.subtract(e,t):t,s=e?t:new g.Pt(t.length).fill(0);for(let t=0,e=r.length;t<e;t++)r[t]=y.random()*i[t]+s[t];return r}static normalizeValue(t,e,r){let i=h(e,r);return(t-i)/(d(e,r)-i)}static sum(t){let e=p.Util.iterToArray(t),r=new g.Pt(e[0]);for(let t=1,i=e.length;t<i;t++)f.Vec.add(r,e[t]);return r}static average(t){let e=p.Util.iterToArray(t);return y.sum(e).divide(e.length)}static cycle(t,e=b.sineInOut){return e(.5<t?2-2*t:2*t)}static mapToRange(t,e,r,i,s){if(e==r)throw new Error("[currMin, currMax] must define a range that is not zero");let n=h(i,s),o=d(i,s);return y.normalizeValue(t,e,r)*(o-n)+n}static seed(t){this.generator=m.default(t)}static random(){return this.generator?this.generator.random():Math.random()}}i.Num=y;class w{static boundAngle(t){return y.boundValue(t,0,360)}static boundRadian(t){return y.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,r;for(let i of t)null==e?(e=i.clone(),r=i.clone()):(e=e.$min(i),r=r.$max(i));return new g.Group(e,r)}static centroid(t){return y.average(t)}static anchor(t,e=0,r="to"){let i="to"==r?"subtract":"add",s=0;for(let r of t)"number"==typeof e?e!==s&&r[i](t[e]):r[i](e),s++}static interpolate(t,e,r=.5){let i=h(t.length,e.length),s=g.Pt.make(i);for(let n=0;n<i;n++)s[n]=t[n]*(1-r)+e[n]*r;return s}static perpendicular(t,e=p.Const.xy){let r=e[1],i=e[0],s=new g.Pt(t),n=new g.Pt(s);n[i]=-s[r],n[r]=s[i];let o=new g.Pt(s);return o[i]=s[r],o[r]=-s[i],new g.Group(n,o)}static isPerpendicular(t,e){return 0===new g.Pt(t).dot(e)}static withinBound(t,e,r){for(let i=0,s=h(t.length,e.length,r.length);i<s;i++)if(!y.within(t[i],e[i],r[i]))return!1;return!0}static sortEdges(t){let e=p.Util.iterToArray(t),r=w.boundingBox(e),i=r[1].add(r[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 r=t.$subtract(i),s=e.$subtract(i);if(0<=r[0]&&0>s[0])return 1;if(0>r[0]&&0<=s[0])return-1;if(0==r[0]&&0==s[0])return 0<=r[1]||0<=s[1]?r[1]>s[1]?1:-1:s[1]>r[1]?1:-1;let n=r.$cross2D(s);return 0>n?1:0<n?-1:r[0]*r[0]+r[1]*r[1]>s[0]*s[0]+s[1]*s[1]?1:-1})}static scale(t,e,r){let i=p.Util.iterToArray(void 0!==t[0]&&"number"==typeof t[0]?[t]:t),s="number"==typeof e?g.Pt.make(i[0].length,e):e;r||(r=g.Pt.make(i[0].length,0));for(let t,e=0,n=i.length;e<n;e++){t=i[e];for(let e=0,i=t.length;e<i;e++)t[e]=r&&r[e]?r[e]+(t[e]-r[e])*s[e]:t[e]*s[e]}return w}static rotate2D(t,e,r,i){let o=p.Util.iterToArray(void 0!==t[0]&&"number"==typeof t[0]?[t]:t),a=r?f.Mat.rotateAt2DMatrix:f.Mat.rotate2DMatrix;r||(r=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=i?o[e].$take(i):o[e],t.to(f.Mat.transform2D(t,a(l,h,r))),i)for(let r=0;r<i.length;r++)o[e][i[r]]=t[r];return w}static shear2D(t,e,r,i){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;r||(r=g.Pt.make(n[0].length,0));let a=r?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=i?n[e].$take(i):n[e],t.to(f.Mat.transform2D(t,a(l,h,r))),i)for(let r=0;r<i.length;r++)n[e][i[r]]=t[r];return w}static reflect2D(t,e,r){let i=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=i.length;e<s;e++)if(t=r?i[e].$take(r):i[e],t.to(f.Mat.transform2D(t,n)),r)for(let s=0;s<r.length;s++)i[e][r[s]]=t[s];return w}static cosTable(){let e=new Float64Array(360);for(let r=0;360>r;r++)e[r]=n(r*t/180);return{table:e,cos:t=>e[u(w.boundAngle(w.toDegree(t)))]}}static sinTable(){let e=new Float64Array(360);for(let r=0;360>r;r++)e[r]=s(r*t/180);return{table:e,sin:t=>e[u(w.boundAngle(w.toDegree(t)))]}}}i.Geom=w;class b{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 r=2*t;return.5>t?e/2*t*t*4:-e/2*((r-1)*(r-3)-1)}static cubicIn(t,e=1){return e*t*t*t}static cubicOut(t,e=1){let r=t-1;return e*(r*r*r+1)}static cubicInOut(t,e=1){let r=2*t;return.5>t?e/2*r*r*r:e/2*((r-2)*(r-2)*(r-2)+2)}static exponentialIn(t,e=1,r=.25){return e*l(t,1/r)}static exponentialOut(t,e=1,r=.25){return e*l(t,r)}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,r=1){return-r/2*(n(t*e)-1)}static cosineApprox(t,e=1){let r=t*t,i=r*r;return e*(i*r*4/9-17*i/9+22*r/9)}static circularIn(t,e=1){return-e*(o(1-t*t)-1)}static circularOut(t,e=1){let r=t-1;return e*o(1-r*r)}static circularInOut(t,e=1){let r=2*t;return.5>t?-e/2*(o(1-r*r)-1):e/2*(o(1-(r-2)*(r-2))+1)}static elasticIn(t,e=1,r=.7){let i=t-1,n=r/p.Const.two_pi*1.5707963267948966;return e*(-l(2,10*i)*s((i-n)*p.Const.two_pi/r))}static elasticOut(t,e=1,r=.7){let i=r/p.Const.two_pi*1.5707963267948966;return e*(l(2,-10*t)*s((t-i)*p.Const.two_pi/r))+e}static elasticInOut(t,e=1,r=.6){let i=2*t,n=r/p.Const.two_pi*1.5707963267948966;return.5>t?(i-=1,e*(l(2,10*i)*s((i-n)*p.Const.two_pi/r)*-.5)):(i-=1,e*(l(2,-10*i)*s((i-n)*p.Const.two_pi/r)*.5)+e)}static bounceIn(t,e=1){return e-b.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?b.bounceIn(2*t,e)/2:b.bounceOut(2*t-1,e)/2+e/2}static sigmoid(t,e=1,r=10){return e/(1+c(-r*(t-.5)))}static logSigmoid(t,e=1,r=.7){r=d(p.Const.epsilon,h(1-p.Const.epsilon,r));let i=1/(1+c((t-.5)*(r=1/(1-r))*-2)),s=1/(1+c(r));return e*(i-s)/(1/(1+c(-r))-s)}static seat(t,e=1,r=.5){return.5>t?e*l(2*t,1-r)/2:e*(1-l(2*(1-t),1-r)/2)}static quadraticBezier(t,e=1,r=[.05,.95]){let i="number"==typeof r?r:r[0],s="number"==typeof r?.5:r[1],n=1-2*i;0===n&&(n=p.Const.epsilon);let a=(o(i*i+n*t)-i)/n;return e*(a*a*(1-2*s)+2*s*a)}static cubicBezier(t,e=1,r=[.1,.7],i=[.9,.2]){let s=new g.Group(new g.Pt(0,0),new g.Pt(r),new g.Pt(i),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,r=[.2,.35]){let i=h(1-p.Const.epsilon,d(p.Const.epsilon,r[0])),s=h(1,d(0,r[1])),n=(1-s)/(1-i)-s/i;return e*h(1,d(0,n*(t*t)-(n*(i*i)-s)/i*t))}static cliff(t,e=1,r=.5){return t>r?e:0}static step(t,e,r,i,...s){let n=1/e;return t(u(r/n)*n,i,...s)}}i.Shaping=b,i.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),r=new g.Pt(t),i=new g.Pt(t);for(let s=0;s<t;s++){e[s]=p.Const.min,r[s]=p.Const.max,i[s]=0;let t=this._source.zipSlice(s);for(let n=0,o=t.length;n<o;n++)e[s]=d(e[s],t[n]),r[s]=h(r[s],t[n]),i[s]=e[s]-r[s]}return this._max=e,this._min=r,this._mag=i,this}}mapTo(t,e,r){let i=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 i=0;i<this._dims;i++)o[i]=r&&r[i]?n[i]:y.mapToRange(n[i],this._min[i],this._max[i],t,e);i.push(o)}return i}append(t,e=!0){let r=p.Util.iterToArray(t);if(r[0].length!==this._dims)throw new Error(`Dimensions don't match. ${this._dims} dimensions in Range and ${r[0].length} provided in parameter. `);return this._source=this._source.concat(r),e&&this.calc(),this}ticks(t){let e=new g.Group;for(let r,i=0;i<=t;i++){r=new g.Pt(this._dims);for(let e=0,s=this._max.length;e<s;e++)r[e]=y.lerp(this._min[e],this._max[e],i/t);e.push(r)}return e}}},"./src/Op.ts":function(i,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 c=l("./src/Util.ts"),p=l("./src/Num.ts"),_=l("./src/Pt.ts"),g=l("./src/LinearAlgebra.ts");let f=(t,e="expected")=>c.Util.warn("Group's length is less than "+e,t);class m{static fromAngle(t,e,r){let i=new _.Group(new _.Pt(t),new _.Pt(t));return i[1].toAngle(e,r,!0),i}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 r=(e[1]-t[1])/(e[0]-t[0]),i=t[1]-r*t[0];return{slope:r,yi:i,xi:0==r?void 0:-i/r}}}static sideOfPt2D(t,e){let r=c.Util.iterToArray(t);return(r[1][0]-r[0][0])*(e[1]-r[0][1])-(e[0]-r[0][0])*(r[1][1]-r[0][1])}static collinear(t,e,r,i=.01){let s=new _.Pt(0,0,0).to(t).$subtract(e),n=new _.Pt(0,0,0).to(t).$subtract(r);return s.$cross(n).divide(1e3).equals(new _.Pt(0,0,0),i)}static magnitude(t){let e=c.Util.iterToArray(t);return 2<=e.length?e[1].$subtract(e[0]).magnitude():0}static magnitudeSq(t){let e=c.Util.iterToArray(t);return 2<=e.length?e[1].$subtract(e[0]).magnitudeSq():0}static perpendicularFromPt(t,e,r=!1){let i=c.Util.iterToArray(t);if(!i[0].equals(i[1])){let t=i[0].$subtract(i[1]),s=i[1].$subtract(e),n=s.$subtract(t.$project(s));return r?n:n.$add(e)}}static distanceFromPt(t,e){let r=c.Util.iterToArray(t),i=m.perpendicularFromPt(r,e,!0);return i?i.magnitude():r[0].$subtract(e).magnitude()}static intersectRay2D(t,e){let r=c.Util.iterToArray(t),i=c.Util.iterToArray(e),s=m.intercept(r[0],r[1]),n=m.intercept(i[0],i[1]),o=r[0],a=i[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 r=c.Util.iterToArray(t),i=c.Util.iterToArray(e),s=m.intersectRay2D(r,i);return s&&p.Geom.withinBound(s,r[0],r[1])&&p.Geom.withinBound(s,i[0],i[1])?s:void 0}static intersectLineWithRay2D(t,e){let r=c.Util.iterToArray(t),i=c.Util.iterToArray(e),s=m.intersectRay2D(r,i);return s&&p.Geom.withinBound(s,r[0],r[1])?s:void 0}static intersectPolygon2D(t,e,r=!1){let i=c.Util.iterToArray(t),s=c.Util.iterToArray(e),n=r?m.intersectLineWithRay2D:m.intersectLine2D,o=new _.Group;for(let t=0,e=s.length;t<e;t++){let r=t===e-1?0:t+1,a=n([s[t],s[r]],i);a&&o.push(a)}return 0<o.length?o:void 0}static intersectLines2D(t,e,r=!1){let i=new _.Group,s=r?m.intersectLineWithRay2D:m.intersectLine2D;for(let r of t)for(let t of e){let e=s(r,t);e&&i.push(e)}return i}static intersectGridWithRay2D(t,e){let r=c.Util.iterToArray(t),i=m.intercept(new _.Pt(r[0]).subtract(e),new _.Pt(r[1]).subtract(e)),s=new _.Group;return i&&i.xi&&s.push(new _.Pt(e[0]+i.xi,e[1])),i&&i.yi&&s.push(new _.Pt(e[0],e[1]+i.yi)),s}static intersectGridWithLine2D(t,e){let r=c.Util.iterToArray(t),i=m.intersectGridWithRay2D(r,e),s=new _.Group;for(let t=0,e=i.length;t<e;t++)p.Geom.withinBound(i[t],r[0],r[1])&&s.push(i[t]);return s}static intersectRect2D(t,e){let r=c.Util.iterToArray(t),i=c.Util.iterToArray(e),s=p.Geom.boundingBox(_.Group.fromPtArray(r));return y.hasIntersectRect2D(s,i)?m.intersectLines2D([r],y.sides(i)):new _.Group}static subpoints(t,e){let r=c.Util.iterToArray(t),i=new _.Group;for(let t=1;t<=e;t++)i.push(p.Geom.interpolate(r[0],r[1],t/(e+1)));return i}static crop(t,r,i=0,s=!0){let n=c.Util.iterToArray(t),o=n[0===i?1:0].$subtract(n[i]);if(0===o[0]||0===r[0])return n[i];if(s){let t=o.unit().multiply(r[1]);return n[i].$add(t)}{let t=y.fromCenter(n[i],r),s=y.sides(t),a=0;return a=e(o[1]/o[0])>e(r[1]/r[0])?0>o[1]?0:2:0>o[0]?3:1,m.intersectRay2D(s[a],n)}}static marker(t,e,r="arrow",i=!0){let s=c.Util.iterToArray(t),n=i?1:0,o=s[i?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"==r?(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=c.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,r){return y.fromTopLeft(t,e,r)}static fromTopLeft(t,e,r){let i="number"==typeof e?[e,r||e]:e;return new _.Group(new _.Pt(t),new _.Pt(t).add(i))}static fromCenter(t,e,r){let i="number"==typeof e?[e/2,(r||e)/2]:new _.Pt(e).divide(2);return new _.Group(new _.Pt(t).subtract(i),new _.Pt(t).add(i))}static toCircle(t,e=!0){return w.fromRect(t,e)}static toSquare(t,e=!1){let r=c.Util.iterToArray(t),i=y.size(r),s=e?i.maxValue().value:i.minValue().value;return y.fromCenter(y.center(r),s,s)}static size(t){let e=c.Util.iterToArray(t);return e[0].$max(e[1]).subtract(e[0].$min(e[1]))}static center(t){let e=c.Util.iterToArray(t),r=e[0].$min(e[1]),i=e[0].$max(e[1]);return r.add(i.$subtract(r).divide(2))}static corners(t){let e=c.Util.iterToArray(t),r=e[0].$min(e[1]),i=e[0].$max(e[1]);return new _.Group(r,new _.Pt(i.x,r.y),i,new _.Pt(r.x,i.y))}static sides(t){let[e,r,i,s]=y.corners(t);return[new _.Group(e,r),new _.Group(r,i),new _.Group(i,s),new _.Group(s,e)]}static boundingBox(t){let e=c.Util.iterToArray(t),r=c.Util.flatten(e,!1),i=_.Pt.make(2,Number.MAX_VALUE),s=_.Pt.make(2,Number.MIN_VALUE);for(let t,e=0,n=r.length;e<n;e++){t=0;for(let n of r[e])if(i[t]=h(i[t],n[t]),s[t]=d(s[t],n[t]),2<=++t)break}return new _.Group(i,s)}static polygon(t){return y.corners(t)}static quadrants(t,e){let r=c.Util.iterToArray(t),i=y.corners(r),s=null==e?y.center(r):new _.Pt(e);return i.map(t=>new _.Group(t,s).boundingBox())}static halves(t,e=.5,r=!1){let i=c.Util.iterToArray(t),s=i[0].$min(i[1]),n=i[0].$max(i[1]),o=r?p.Num.lerp(s[1],n[1],e):p.Num.lerp(s[0],n[0],e);return r?[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 r=c.Util.iterToArray(t);return p.Geom.withinBound(e,r[0],r[1])}static hasIntersectRect2D(t,e,r=!1){let i=c.Util.iterToArray(t),s=c.Util.iterToArray(e);return r&&(i=p.Geom.boundingBox(i),s=p.Geom.boundingBox(s)),!(i[0][0]>s[1][0]||s[0][0]>i[1][0]||i[0][1]>s[1][1]||s[0][1]>i[1][1])}static intersectRect2D(t,e){let r=c.Util.iterToArray(t),i=c.Util.iterToArray(e);return y.hasIntersectRect2D(r,i)?m.intersectLines2D(y.sides(r),y.sides(i)):new _.Group}}a.Rectangle=y;class w{static fromRect(t,e=!1){let r=c.Util.iterToArray(t),i=0,s=i=y.size(r).minValue().value/2;if(e){let t=y.size(r).maxValue().value/2;i=o(s*s+t*t)}else i=s;return new _.Group(y.center(r),new _.Pt(i,i))}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,r=0){let i=c.Util.iterToArray(t),s=i[0].$subtract(e);return s.dot(s)+r<i[1].x*i[1].x}static intersectRay2D(t,e){let r=c.Util.iterToArray(t),i=c.Util.iterToArray(e),s=i[0].$subtract(i[1]),n=r[0].$subtract(i[0]),a=s.dot(s),l=n.dot(s)/a,h=l*l-(n.dot(n)-r[1].x*r[1].x)/a;if(0>h)return new _.Group;{let t=o(h),e=i[0].$subtract(s.$multiply(-l+t));if(0==h)return new _.Group(e);let r=i[0].$subtract(s.$multiply(-l-t));return new _.Group(e,r)}}static intersectLine2D(t,e){let r=c.Util.iterToArray(t),i=c.Util.iterToArray(e),s=w.intersectRay2D(r,i),n=new _.Group;if(0<s.length)for(let t=0,e=s.length;t<e;t++)y.withinBound(i,s[t])&&n.push(s[t]);return n}static intersectCircle2D(t,r){let i=c.Util.iterToArray(t),s=c.Util.iterToArray(r),n=s[0].$subtract(i[0]),a=n.magnitudeSq(),l=o(a),h=i[1].x,u=s[1].x,d=h*h;if(l>h+u)return new _.Group;if(l<e(h-u))return new _.Group(i[0].clone());{let t=(d-u*u+a)/(2*l),e=o(d-t*t),r=n.$multiply(t/l).add(i[0]);return new _.Group(new _.Pt(r.x+e*n.y/l,r.y-e*n.x/l),new _.Pt(r.x-e*n.y/l,r.y+e*n.x/l))}}static intersectRect2D(t,e){let r=c.Util.iterToArray(t),i=c.Util.iterToArray(e),s=y.sides(i),n=[];for(let t,e=0,i=s.length;e<i;e++)t=w.intersectLine2D(r,s[e]),0<t.length&&n.push(t);return c.Util.flatten(n)}static toRect(t,e=!1){let r=c.Util.iterToArray(t),i=r[1][0];if(e){let t=o(i*i)/2;return new _.Group(r[0].$subtract(t),r[0].$add(t))}return new _.Group(r[0].$subtract(i),r[0].$add(i))}static toTriangle(e,r=!0){let i=c.Util.iterToArray(e);if(r){let e=-t/2,r=new _.Group;for(let s=0;3>s;s++)r.push(i[0].clone().toAngle(e,i[1][0],!0)),e+=2*t/3;return r}return b.fromCenter(i[0],i[1][0])}}a.Circle=w;class b{static fromRect(t){let e=c.Util.iterToArray(t),r=e[0].$add(e[1]).divide(2);r.y=e[0][1];let i=e[1].clone();return i.x=e[0][0],new _.Group(r,e[1].clone(),i)}static fromCircle(t){return w.toTriangle(t,!0)}static fromCenter(t,e){return b.fromCircle(w.fromCenter(t,e))}static medial(t){let e=c.Util.iterToArray(t);return 3>e.length?f(new _.Group,3):x.midpoints(e,!0)}static oppositeSide(t,e){let r=c.Util.iterToArray(t);return 3>r.length?f(new _.Group,3):0===e?_.Group.fromPtArray([r[1],r[2]]):1===e?_.Group.fromPtArray([r[0],r[2]]):_.Group.fromPtArray([r[0],r[1]])}static altitude(t,e){let r=c.Util.iterToArray(t),i=b.oppositeSide(r,e);return 1<i.length?new _.Group(r[e],m.perpendicularFromPt(i,r[e])):new _.Group}static orthocenter(t){let e=c.Util.iterToArray(t);if(3>e.length)return f(void 0,3);let r=b.altitude(e,0),i=b.altitude(e,1);return m.intersectRay2D(r,i)}static incenter(t){let e=c.Util.iterToArray(t);if(3>e.length)return f(void 0,3);let r=x.bisector(e,0).add(e[0]),i=x.bisector(e,1).add(e[1]);return m.intersectRay2D(new _.Group(e[0],r),new _.Group(e[1],i))}static incircle(t,e){let r=c.Util.iterToArray(t),i=e||b.incenter(r),s=2*x.area(r)/x.perimeter(r,!0).total;return w.fromCenter(i,s)}static circumcenter(t){let e=c.Util.iterToArray(t),r=b.medial(e),i=[r[0],p.Geom.perpendicular(e[0].$subtract(r[0])).p1.$add(r[0])],s=[r[1],p.Geom.perpendicular(e[1].$subtract(r[1])).p1.$add(r[1])];return m.intersectRay2D(i,s)}static circumcircle(t,e){let r=c.Util.iterToArray(t),i=e||b.circumcenter(r),s=r[0].$subtract(i).magnitude();return w.fromCenter(i,s)}}a.Triangle=b;class x{static centroid(t){return p.Geom.centroid(t)}static rectangle(t,e,r){return y.corners(y.fromCenter(t,e,r))}static fromCenter(e,r,i){let o=new _.Group;for(let a,l=0;l<i;l++)a=2*t*l/i,o.push(new _.Pt(n(a)*r,s(a)*r).add(e));return o}static lineAt(t,e){let r=c.Util.iterToArray(t);if(0>e||e>=r.length)throw new Error("index out of the Polygon's range");return new _.Group(r[e],e===r.length-1?r[0]:r[e+1])}static lines(t,e=!0){let r=c.Util.iterToArray(t);if(2>r.length)return f(new _.Group,2);let i=c.Util.split(r,2,1);return e&&i.push(new _.Group(r[r.length-1],r[0])),i.map(t=>t)}static midpoints(t,e=!1,r=.5){return x.lines(t,e).map(t=>p.Geom.interpolate(t[0],t[1],r))}static adjacentSides(t,e,r=!1){let i=c.Util.iterToArray(t);if(2>i.length)return f(new _.Group,2);if(0>e||e>=i.length)return((t,e="")=>c.Util.warn(`Index ${e} is out of bound in Group`,t))(new _.Group,e);let s=[],n=e-1;r&&0>n&&(n=i.length-1),0<=n&&s.push(new _.Group(i[e],i[n]));let o=e+1;return r&&o>i.length-1&&(o=0),o<=i.length-1&&s.push(new _.Group(i[e],i[o])),s}static bisector(t,e){let r=x.adjacentSides(t,e,!0);if(2<=r.length){let t=r[0][1].$subtract(r[0][0]).unit(),e=r[1][1].$subtract(r[1][0]).unit();return t.add(e).divide(2)}}static perimeter(t,e=!1){let r=x.lines(t,e),i=0,s=_.Pt.make(r.length,0);for(let t,e=0,n=r.length;e<n;e++)t=m.magnitude(r[e]),i+=t,s[e]=t;return{total:i,segments:s}}static area(t){let r=c.Util.iterToArray(t);if(3>r.length)return f(new _.Group,3);let i=(t,e)=>t[0]*e[1]-t[1]*e[0],s=0;for(let t=0,e=r.length;t<e;t++)s+=t<r.length-1?i(r[t],r[t+1]):i(r[t],r[0]);return e(s/2)}static convexHull(t,e=!1){let r=c.Util.iterToArray(t);if(3>r.length)return f(new _.Group,3);e||(r=r.slice(),r.sort((t,e)=>t[0]-e[0]));let i=(t,e,r)=>0<(e[0]-t[0])*(r[1]-t[1])-(r[0]-t[0])*(e[1]-t[1]),s=[],n=r.length-2,o=n+3;s[n]=r[2],s[o]=r[2],i(r[0],r[1],r[2])?(s[n+1]=r[0],s[n+2]=r[1]):(s[n+1]=r[1],s[n+2]=r[0]);for(let t,e=3,a=r.length;e<a;e++)if(t=r[e],!i(s[n],s[n+1],t)||!i(s[o-1],s[o],t)){for(;!i(s[n],s[n+1],t);)n+=1;for(n-=1,s[n]=t;!i(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 r=c.Util.iterToArray(t),i=[];for(let t=0,s=r.length;t<s;t++)t!=e&&i.push(new _.Group(r[e],r[t]));return i}static nearestPt(t,e){let i=r,s=-1,n=0;for(let r of t){let t=r.$subtract(e).magnitudeSq();t<i&&(i=t,s=n),n++}return s}static projectAxis(t,e){let r=c.Util.iterToArray(t),i=e.dot(r[0]),s=new _.Pt(i,i);for(let t=1,n=r.length;t<n;t++)i=e.dot(r[t]),s=new _.Pt(h(i,s[0]),d(i,s[1]));return s}static _axisOverlap(t,e,r){let i=x.projectAxis(t,r),s=x.projectAxis(e,r);return i[0]<s[0]?s[0]-i[1]:i[0]-s[1]}static hasIntersectPoint(t,e){let r=c.Util.iterToArray(t),i=!1;for(let t,s=0,n=r.length;s<n;s++)t=x.lineAt(r,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]&&(i=!i);return i}static hasIntersectCircle(t,r){let i=c.Util.iterToArray(t),s=c.Util.iterToArray(r),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=i.length;t<s;t++){let s=x.lineAt(i,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(i,u,h);if(0<c)return null;e(c)<l&&(y.withinBound(s,m.perpendicularFromPt(s,o))||0<w.intersectLine2D(r,s).length)&&(n.edge=s,n.normal=h,l=e(c),n.which=t)}return n.edge?(0>o.$subtract(x.centroid(i)).dot(n.normal)&&n.normal.multiply(-1),n.dist=l,n.vertex=o,n):null}static hasIntersectPolygon(t,r){let i=c.Util.iterToArray(t),s=c.Util.iterToArray(r),n={which:-1,dist:0,normal:new _.Pt,edge:new _.Group,vertex:new _.Pt},o=u;for(let t=0,r=i.length+s.length;t<r;t++){let r=t<i.length?x.lineAt(i,t):x.lineAt(s,t-i.length),a=new _.Pt(r[0].y-r[1].y,r[1].x-r[0].x).unit(),l=x._axisOverlap(i,s,a);if(0<l)return null;e(l)<o&&(n.edge=r,n.normal=a,o=e(l),n.which=t<i.length?0:1)}n.dist=o;let a=0===n.which?s:i,l=0===n.which?i:s,h=x.centroid(a),d=x.centroid(l);0>h.$subtract(d).dot(n.normal)&&n.normal.multiply(-1);let p=u;for(let t,e=0,r=a.length;e<r;e++)t=n.normal.dot(a[e].$subtract(d)),t<p&&(p=t,n.vertex=a[e]);return n}static intersectPolygon2D(t,e){let r=c.Util.iterToArray(t),i=c.Util.iterToArray(e),s=x.lines(r),n=[];for(let t,e=0,r=s.length;e<r;e++)t=m.intersectPolygon2D(s[e],i,!1),t&&n.push(t);return c.Util.flatten(n,!0)}static toRects(t){let e=[];for(let r of t)e.push(p.Geom.boundingBox(r));let r=c.Util.flatten(e,!1);return e.unshift(p.Geom.boundingBox(r)),e}}a.Polygon=x;class v{static getSteps(t){let e=new _.Group;for(let r,i=0;i<=t;i++)r=i/t,e.push(new _.Pt(r*r*r,r*r,r,1));return e}static controlPoints(t,e=0,r=!1){let i=c.Util.iterToArray(t);if(e>i.length-1)return new _.Group;let s=t=>t<i.length-1?t:i.length-1,n=i[e];return e=r?e:e+1,new _.Group(n,i[s(e++)],i[s(e++)],i[s(e++)])}static _calcPt(t,e){let r=t.reduce((t,r,i)=>t+r.x*e[i],0),i=t.reduce((t,r,i)=>t+r.y*e[i],0);if(2<t[0].length){let s=t.reduce((t,r,i)=>t+r.z*e[i],0);return new _.Pt(r,i,s)}return new _.Pt(r,i)}static catmullRom(t,e=10){let r=c.Util.iterToArray(t);if(2>r.length)return new _.Group;let i=new _.Group,s=v.getSteps(e),n=v.controlPoints(r,0,!0);for(let t=0;t<=e;t++)i.push(v.catmullRomStep(s[t],n));for(let t,n=0;n<r.length-2;)if(t=v.controlPoints(r,n),0<t.length){for(let r=0;r<=e;r++)i.push(v.catmullRomStep(s[r],t));n++}return i}static catmullRomStep(t,e){let r=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],r,!0)[0])}static cardinal(t,e=10,r=.5){let i=c.Util.iterToArray(t);if(2>i.length)return new _.Group;let s=new _.Group,n=v.getSteps(e),o=v.controlPoints(i,0,!0);for(let t=0;t<=e;t++)s.push(v.cardinalStep(n[t],o,r));for(let t,o=0;o<i.length-2;)if(t=v.controlPoints(i,o),0<t.length){for(let i=0;i<=e;i++)s.push(v.cardinalStep(n[i],t,r));o++}return s}static cardinalStep(t,e,r=.5){let i=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],i,!0)[0].multiply(r),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 r=c.Util.iterToArray(t);if(4>r.length)return new _.Group;let i=new _.Group,s=v.getSteps(e),n=0;for(;n<r.length-3;){let t=v.controlPoints(r,n);if(0<t.length){for(let r=0;r<=e;r++)i.push(v.bezierStep(s[r],t));n+=3}}return i}static bezierStep(t,e){let r=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],r,!0)[0])}static bspline(t,e=10,r=1){let i=c.Util.iterToArray(t);if(2>i.length)return new _.Group;let s=new _.Group,n=v.getSteps(e),o=0;for(;o<i.length-3;){let t=v.controlPoints(i,o);if(0<t.length){if(1!==r)for(let i=0;i<=e;i++)s.push(v.bsplineTensionStep(n[i],t,r));else for(let r=0;r<=e;r++)s.push(v.bsplineStep(n[r],t));o++}}return s}static bsplineStep(t,e){let r=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],r,!0)[0])}static bsplineTensionStep(t,e,r=1){let i=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],i,!0)[0].multiply(r),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,r,i){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.Body=r.Particle=r.World=void 0;const s=i("./src/Pt.ts"),n=i("./src/Op.ts"),a=i("./src/Num.ts");class l{constructor(t,e=1,r=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 r?new s.Pt(0,r):new s.Pt(r),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 r=0;if("string"!=typeof e)r=e;else if(r=t(e),0>r)throw new Error(`Cannot find index of ${e}. You can use particleIndex() or bodyIndex() function to check existence by name.`);return r}removeBody(t,e=1){const r=this._index(this.bodyIndex.bind(this),t),i=0>r?[-1*r-1,e]:[r,e];return this._bodies.splice(i[0],i[1]),this._bnames.splice(i[0],i[1]),this}removeParticle(t,e=1){const r=this._index(this.particleIndex.bind(this),t),i=0>r?[-1*r-1,e]:[r,e];return this._particles.splice(i[0],i[1]),this._pnames.splice(i[0],i[1]),this}static edgeConstraint(t,e,r,i=1,s=!1){const n=1/(t.mass||1),o=1/(e.mass||1),a=n+o;let l=e.$subtract(t),h=r*r,u=s?r/l.magnitude()-1:h/(l.dot(l)+h)-.5,c=l.$multiply(u*i);return t.subtract(c.$multiply(n/a)),e.add(c.$multiply(o/a)),t}static boundConstraint(t,e,r=.75){let i=a.Geom.boundingBox(e),n=t.$min(i[1].subtract(t.radius)).$max(i[0].add(t.radius));if(n[0]===i[0][0]||n[0]===i[1][0]){let e=t.changed.$multiply(r);t.previous=n.$subtract(new s.Pt(-e[0],e[1]))}else if(n[1]===i[0][1]||n[1]===i[1][1]){let e=t.changed.$multiply(r);t.previous=n.$subtract(new s.Pt(e[0],-e[1]))}t.to(n)}integrate(t,e,r){return t.addForce(this._gravity),t.verlet(e,this._friction,r),t}_updateParticles(t){for(let e,r=0,i=this._particles.length;r<i;r++){e=this._particles[r],this.integrate(e,t,this._lastTime),l.boundConstraint(e,this._bound,this._damping);for(let t=r+1;t<i;t++)if(r!==t){let r=this._particles[t];e.collide(r,this._damping)}this._drawParticles&&this._drawParticles(e,r)}this._lastTime=t}_updateBodies(t){for(let e,r=0,i=this._bodies.length;r<i;r++)if(e=this._bodies[r],e){for(let r,i=0,s=e.length;i<s;i++)r=e[i],l.boundConstraint(r,this._bound,this._damping),this.integrate(r,t,this._lastTime);for(let t=r+1;t<i;t++)e.processBody(this._bodies[t]);for(let t=0,r=this._particles.length;t<r;t++)e.processParticle(this._particles[t]);e.processEdges(),this._drawBodies&&this._drawBodies(e,r)}}}r.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,r){if(this._lock)this.to(this._lockPt);else{let i=r||t,n=this._force.multiply(t*(t+i)/2),o=this.changed.multiply(e*t/i).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 r=this,i=r.$subtract(t),n=i.magnitudeSq(),a=r.radius+t.radius;if(n<a*a){let l=r.changed,h=t.changed,u=o(n),c=i.$multiply((u-a)/u/2),d=r.$subtract(c),p=t.$add(c);r.to(d),t.to(p);let _=e*i.dot(l)/n,g=e*i.dot(h)/n,f=r.mass/(r.mass+t.mass),m=t.mass/(r.mass+t.mass);l.add(new s.Pt(g*i[0]-_*i[0],g*i[1]-_*i[1]).$multiply(m)),h.add(new s.Pt(_*i[0]-g*i[0],_*i[1]-g*i[1]).$multiply(f)),r.previous=r.$subtract(l),t.previous=t.$subtract(h)}}toString(){return`Particle: ${this[0]} ${this[1]} | previous ${this._prev[0]} ${this._prev[1]} | mass ${this._mass}`}}r.Particle=c;class d extends s.Group{constructor(){super(),this._cs=[],this._stiff=1,this._locks={},this._mass=1}static fromGroup(t,e=1,r=!0,i=!0){let s=(new d).init(t);return r&&s.linkAll(e),i&&s.autoMass(),s}init(t,e=1){let r=new s.Pt;for(let e of t){let t=new c(e);t.body=this,r.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,r){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 i=this[t].$subtract(this[e]).magnitude();return this._cs.push([t,e,i,r||this._stiff]),this}linkAll(t){let e=this.length/2;for(let r,i=0,s=this.length;i<s;i++){if(r=i>=s-1?0:i+1,this.link(i,r,t),4<s){let r=u(e/2)+1,n=i>=s-r?i%s:i+r;this.link(i,n,t)}i<=e-1&&this.link(i,h(this.length-1,i+u(e)))}}linksToLines(){let t=[];for(let e,r=0,i=this._cs.length;r<i;r++)e=this._cs[r],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,r,i,s]=this._cs[t];l.edgeConstraint(this[e],this[r],i,s)}}processBody(t){let r=n.Polygon.hasIntersectPolygon(this,t);if(r){let t,i=r.normal.$multiply(r.dist),s=r.edge;t=e(s[0][0]-s[1][0])>e(s[0][1]-s[1][1])?(r.vertex[0]-i[0]-s[0][0])/(s[1][0]-s[0][0]):(r.vertex[1]-i[1]-s[0][1])/(s[1][1]-s[0][1]);let n=1/(t*t+(1-t)*(1-t)),o=r.vertex.body.mass||1,a=r.edge[0].body.mass||1,l=o/(o+a);s[0].subtract(i.$multiply(l*(1-t)*n/2)),s[1].subtract(i.$multiply(l*t*n/2)),r.vertex.add(i.$multiply(a/(o+a)))}}processParticle(t){let r=n.Polygon.hasIntersectCircle(this,n.Circle.fromCenter(t,t.radius));if(r){let i,s=r.normal.$multiply(r.dist),n=r.edge;i=e(n[0][0]-n[1][0])>e(n[0][1]-n[1][1])?(r.vertex[0]-s[0]-n[0][0])/(n[1][0]-n[0][0]):(r.vertex[1]-s[1]-n[0][1])/(n[1][1]-n[0][1]);let o=1/(i*i+(1-i)*(1-i)),a=r.vertex.mass||t.mass||1,l=r.edge[0].body.mass||1,h=a/(a+l);n[0].subtract(s.$multiply(h*(1-i)*o/2)),n[1].subtract(s.$multiply(h*i*o/2));let u=t.changed.add(s.$multiply(l/(a+l)));t.previous=t.$subtract(u)}}}r.Body=d},"./src/Play.ts":function(t,e,r){"use strict";var i=this&&this.__awaiter||function(t,e,r,i){function s(t){return t instanceof r?t:new r((function(e){e(t)}))}return new(r||(r=Promise))((function(r,n){function o(t){try{l(i.next(t))}catch(t){n(t)}}function a(t){try{l(i.throw(t))}catch(t){n(t)}}function l(t){t.done?r(t.value):s(t.value).then(o,a)}l((i=i.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.Sound=e.Tempo=void 0;const s=r("./src/Pt.ts"),n=r("./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,r=Array.isArray(t)?t[0]:t;return{start:function(i,s=0,n){let o=n||e._createID(i);return e._listeners[o]={name:o,beats:t,period:r,index:0,offset:s,duration:-1,continuous:!1,fn:i},this},progress:function(i,s=0,n){let o=n||e._createID(i);return e._listeners[o]={name:o,beats:t,period:r,index:0,offset:s,duration:-1,continuous:!0,fn:i},this}}}track(t){for(let e in this._listeners)if(this._listeners.hasOwnProperty(e)){let r=this._listeners[e],i=r.offset?t+r.offset:t,s=r.period*this._ms,o=!1;i>r.duration+s&&(r.duration=i-i%this._ms,Array.isArray(r.beats)&&(r.index=(r.index+1)%r.beats.length,r.period=r.beats[r.index]),o=!0);let a=d(0,c(u(r.duration/this._ms)/r.period)),l=r.continuous?[a,n.Num.clamp((i-r.duration)/s,0,1),i,o]:[a];(r.continuous||o)&&r.fn.apply(r,l)&&delete this._listeners[r.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,r="gen",i){let s=new a(r);return s._node=t,s._ctx=e,i&&(s._stream=i),s}static load(t,e="anonymous"){return new Promise((r,i)=>{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(){i("Error loading sound")})),s._source.addEventListener("canplaythrough",(function(){s._node=s._ctx.createMediaElementSource(s._source),r(s)}))})}static loadAsBuffer(t){return new Promise((e,r)=>{let i=new XMLHttpRequest;i.open("GET",t,!0),i.responseType="arraybuffer";let s=new a("file");i.onload=function(){s._ctx.decodeAudioData(i.response,(function(t){s.createBuffer(t),e(s)}),()=>r("Error decoding audio"))},i.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 r=this._node;return r.type=t,"custom"===t?r.setPeriodicWave(e):r.frequency.value=e,this}static input(t){return i(this,void 0,void 0,(function*(){try{let e=new a("input");if(!e)return;const r=t||{audio:!0,video:!1};return e._stream=yield navigator.mediaDevices.getUserMedia(r),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,r=-30,i=.8){let s=this._ctx.createAnalyser();return s.fftSize=2*t,s.minDecibels=e,s.maxDecibels=r,s.smoothingTimeConstant=i,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,r=[0,0],i=[0,0]){let n=t?this.timeDomain():this.freqDomain(),o=new s.Group;for(let t=i[0],a=n.length-i[1];t<a;t++)o.push(new s.Pt(r[0]+e[0]*t/a,r[1]+e[1]*n[t]/255));return o}timeDomain(){return this._domain(!0)}timeDomainTo(t,e=[0,0],r=[0,0]){return this._domainTo(!0,t,e,r)}freqDomain(){return this._domain(!1)}freqDomainTo(t,e=[0,0],r=[0,0]){return this._domainTo(!1,t,e,r)}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,r,i){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.Bound=r.Group=r.Pt=void 0;const o=i("./src/Util.ts"),l=i("./src/Num.ts"),c=i("./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,r=!1){let i=new Float32Array(t);if(e&&i.fill(e),r)for(let t=0,e=i.length;t<e;t++)i[t]*=l.Num.random();return new p(i)}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,r=1e-6){for(let i=0,s=this.length;i<s;i++)if(e(this[i]-t[i])>r)return!1;return!0}to(...t){let e=o.Util.getArgs(t);for(let t=0,r=h(this.length,e.length);t<r;t++)this[t]=e[t];return this}$to(...t){return this.clone().to(...t)}toAngle(t,e,r=!1){let i=null==e?this.magnitude():e,o=[n(t)*i,s(t)*i];return r?this.add(o):this.to(o)}op(t){let e=this;return(...r)=>t(e,...r)}ops(t){let e=[];for(let r=0,i=t.length;r<i;r++)e.push(this.op(t[r]));return e}$take(t){let e=[];for(let r=0,i=t.length;r<i;r++)e.push(this[t[r]]||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]?c.Vec.add(this,t[0]):c.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]?c.Vec.subtract(this,t[0]):c.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]?c.Vec.multiply(this,t[0]):c.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]?c.Vec.divide(this,t[0]):c.Vec.divide(this,o.Util.getArgs(t)),this}$divide(...t){return this.clone().divide(...t)}magnitudeSq(){return c.Vec.dot(this,this)}magnitude(){return c.Vec.magnitude(this)}unit(t){return c.Vec.unit(this,t),this}$unit(t){return this.clone().unit(t)}dot(...t){return c.Vec.dot(this,o.Util.getArgs(t))}$cross2D(...t){return c.Vec.cross2D(this,o.Util.getArgs(t))}$cross(...t){return c.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 c.Vec.abs(this),this}$abs(){return this.clone().abs()}floor(){return c.Vec.floor(this),this}$floor(){return this.clone().floor()}ceil(){return c.Vec.ceil(this),this}$ceil(){return this.clone().ceil()}round(){return c.Vec.round(this),this}$round(){return this.clone().round()}minValue(){return c.Vec.min(this)}maxValue(){return c.Vec.max(this)}$min(...t){let e=o.Util.getArgs(t),r=this.clone();for(let t=0,i=h(this.length,e.length);t<i;t++)r[t]=h(this[t],e[t]);return r}$max(...t){let e=o.Util.getArgs(t),r=this.clone();for(let t=0,i=h(this.length,e.length);t<i;t++)r[t]=d(this[t],e[t]);return r}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,r){return l.Geom.rotate2D(this,t,e||p.make(this.length,0),r),this}shear2D(t,e,r){return l.Geom.shear2D(this,t,e||p.make(this.length,0),r),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())}}r.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,r=this.length;e<r;e++)t.push(this[e].clone());return t}static fromArray(t){let e=new _;for(let r of t){let t=r instanceof p?r:new p(r);e.push(t)}return e}static fromPtArray(t){return _.from(t)}split(t,e,r=!1){return o.Util.split(this,t,e,r)}insert(t,e=0){return _.prototype.splice.apply(this,[e,0,...t]),this}remove(t=0,e=1){let r=0>t?[-1*t-1,e]:[t,e];return _.prototype.splice.apply(this,r)}segments(t=2,e=1,r=!1){return this.split(t,e,r)}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(...r)=>t(e,...r)}ops(t){let e=[];for(let r=0,i=t.length;r<i;r++)e.push(this.op(t[r]));return e}interpolate(t){t=l.Num.clamp(t,0,1);let e=this.length-1,r=1/(this.length-1),i=u(t/r);return l.Geom.interpolate(this[i],this[h(this.length-1,i+1)],(t-i*r)*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 r=0,i=this.length;r<i;r++)l.Geom.scale(this[r],t,e||this[0]);return this}rotate2D(t,e,r){for(let i=0,s=this.length;i<s;i++)l.Geom.rotate2D(this[i],t,e||this[0],r);return this}shear2D(t,e,r){for(let i=0,s=this.length;i<s;i++)l.Geom.shear2D(this[i],t,e||this[0],r);return this}reflect2D(t,e){for(let r=0,i=this.length;r<i;r++)l.Geom.reflect2D(this[r],t,e);return this}sortByDimension(t,e=!1){return this.sort((r,i)=>e?i[t]-r[t]:r[t]-i[t])}forEachPt(t,...e){if(!this[0][t])return o.Util.warn(t+" is not a function of Pt"),this;for(let r=0,i=this.length;r<i;r++)this[r]=this[r][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 c.Mat.add(this,t)}$matrixMultiply(t,e=!1,r=!1){return c.Mat.multiply(this,t,e,r)}zipSlice(t,e=!1){return c.Mat.zipSlice(this,t,e)}$zip(t,e=!1){return c.Mat.zip(this,t,e)}toString(){return"Group[ "+this.reduce((t,e)=>t+e.toString()+" ","")+" ]"}}r.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}}r.Bound=g},"./src/Space.ts":function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.MultiTouchSpace=e.Space=void 0;const i=r("./src/Pt.ts"),s=r("./src/UI.ts");class n{constructor(){this.id="space",this.bound=new i.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 i.Pt,this._isReady=!1,this._playing=!1}refresh(t){return this._refresh=t,this}add(t){let e="function"==typeof t?{animate:t}:t,r=this.playerCount++,i=this.id+r;return this.players[i]=e,e.animateID=i,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=0){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 i.Bound(i.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,r={}){this._canvas.addEventListener(t,e,r)}unbindCanvas(t,e,r={}){this._canvas.removeEventListener(t,e,r)}bindMouse(t=!0){return t?(this._mouseDown=this._mouseDown.bind(this),this._mouseUp=this._mouseUp.bind(this),this._mouseOver=this._mouseOver.bind(this),this._mouseOut=this._mouseOut.bind(this),this._mouseMove=this._mouseMove.bind(this),this._mouseClick=this._mouseClick.bind(this),this._contextMenu=this._contextMenu.bind(this),this.bindCanvas("mousedown",this._mouseDown),this.bindCanvas("mouseup",this._mouseUp),this.bindCanvas("mouseover",this._mouseOver),this.bindCanvas("mouseout",this._mouseOut),this.bindCanvas("mousemove",this._mouseMove),this.bindCanvas("click",this._mouseClick),this.bindCanvas("contextmenu",this._contextMenu),this._hasMouse=!0):(this.unbindCanvas("mousedown",this._mouseDown),this.unbindCanvas("mouseup",this._mouseUp),this.unbindCanvas("mouseover",this._mouseOver),this.unbindCanvas("mouseout",this._mouseOut),this.unbindCanvas("mousemove",this._mouseMove),this.unbindCanvas("click",this._mouseClick),this.unbindCanvas("contextmenu",this._contextMenu),this._hasMouse=!1),this}bindTouch(t=!0,e=!1){return t?(this.bindCanvas("touchstart",this._touchStart.bind(this),{passive:e}),this.bindCanvas("touchend",this._mouseUp.bind(this)),this.bindCanvas("touchmove",this._touchMove.bind(this),{passive:e}),this.bindCanvas("touchcancel",this._mouseOut.bind(this)),this._hasTouch=!0):(this.unbindCanvas("touchstart",this._touchStart.bind(this),{passive:e}),this.unbindCanvas("touchend",this._mouseUp.bind(this)),this.unbindCanvas("touchmove",this._touchMove.bind(this),{passive:e}),this.unbindCanvas("touchcancel",this._mouseOut.bind(this)),this._hasTouch=!1),this}touchesToPoints(t,e="touches"){if(!t||!t[e])return[];let r=[];for(var s=0;s<t[e].length;s++){let n=t[e].item(s);r.push(new i.Pt(n.pageX-this.bound.topLeft.x,n.pageY-this.bound.topLeft.y))}return r}_mouseAction(t,e){let r=0,i=0;if(e instanceof MouseEvent){for(let s in this.players)if(this.players.hasOwnProperty(s)){let n=this.players[s];r=e.pageX-this.outerBound.x,i=e.pageY-this.outerBound.y,n.action&&n.action(t,r,i,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);r=o?a.pageX-this.outerBound.x:0,i=o?a.pageY-this.outerBound.y:0,n.action&&n.action(t,r,i,e)}t&&(this._pointer.to(r,i),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,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.SVGForm=e.SVGSpace=void 0;const i=r("./src/Form.ts"),s=r("./src/Num.ts"),n=r("./src/Util.ts"),o=r("./src/Pt.ts"),a=r("./src/Op.ts"),l=r("./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,r){if(!t||!t.appendChild)throw new Error("parent is not a valid DOM element");let i=document.querySelector("#"+r);return i||(i=document.createElementNS("http://www.w3.org/2000/svg",e),i.setAttribute("id",r),t.appendChild(i)),i}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 i.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,r,i){return"boolean"==typeof t?this.styleTo("stroked",t):(this.styleTo("stroked",!0),this.styleTo("stroke",t),e&&this.styleTo("stroke-width",e),r&&this.styleTo("stroke-linejoin",r),i&&this.styleTo("stroke-linecap",i)),this}cls(t){return this._ctx.currentClass="boolean"==typeof t?"":t,this}font(t,e,r,i,s){return"number"==typeof t?(this._font.size=t,s&&(this._font.face=s),e&&(this._font.weight=e),r&&(this._font.style=r),i&&(this._font.lineHeight=i)):this._font=t,this._ctx.style.font=this._font.value,this}reset(){return this._ctx.style=Object.assign({},this._style),this._font=new i.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 r=[];for(let t in e.filled||r.push("fill: none"),e.stroked||r.push("stroke: none"),e)if(e.hasOwnProperty(t)&&"filled"!=t&&"stroked"!=t){let i=e[t];if(i){if(!e.filled&&0===t.indexOf("fill"))continue;if(!e.stroked&&0===t.indexOf("stroke"))continue;r.push(`${t}: ${i}`)}}return l.DOMSpace.setAttr(t,{style:r.join(";")})}static point(t,e,r=5,i="square"){return"circle"===i?u.circle(t,e,r):u.square(t,e,r)}point(t,e=5,r="square"){return this.nextID(),u.point(this._ctx,t,e,r),this}static circle(t,e,r=10){let i=h.svgElement(t.group,"circle",u.getID(t));return l.DOMSpace.setAttr(i,{cx:e[0],cy:e[1],r:r,class:"pts-svgform pts-circle "+t.currentClass}),u.style(i,t.style),i}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,r,i,a,c){let d=h.svgElement(t.group,"path",u.getID(t));const p=new o.Pt(e).toAngle(i,r,!0),_=new o.Pt(e).toAngle(a,r,!0);let g=!!(s.Geom.boundAngle(a)-s.Geom.boundAngle(i)>n.Const.pi);c&&(g=!g);const f=c?"0":"1",m=`M ${p[0]} ${p[1]} A ${r} ${r} 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,r,i,s){return this.nextID(),u.arc(this._ctx,t,e,r,i,s),this}static square(t,e,r){let i=h.svgElement(t.group,"rect",u.getID(t));return l.DOMSpace.setAttr(i,{x:e[0]-r,y:e[1]-r,width:2*r,height:2*r,class:"pts-svgform pts-square "+t.currentClass}),u.style(i,t.style),i}square(t,e){return this.nextID(),u.square(this._ctx,t,e),this}static line(t,e){let r=u.pointsString(e);if(!(2>r.count)){if(2<r.count)return u._poly(t,r.string,!1);let i=h.svgElement(t.group,"line",u.getID(t)),s=n.Util.iterToArray(e);return l.DOMSpace.setAttr(i,{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(i,t.style),i}}line(t){return this.nextID(),u.line(this._ctx,t),this}static _poly(t,e,r=!0){let i=h.svgElement(t.group,r?"polygon":"polyline",u.getID(t));return l.DOMSpace.setAttr(i,{points:e,class:"pts-svgform pts-polygon "+t.currentClass}),u.style(i,t.style),i}static pointsString(t){let e="",r=0;for(let i of t)e+=`${i[0]},${i[1]} `,r++;return{string:e,count:r}}static polygon(t,e){let r=u.pointsString(e);return u._poly(t,r.string,!0)}polygon(t){return this.nextID(),u.polygon(this._ctx,t),this}static rect(t,e){if(n.Util.arrayCheck(e)){let r=h.svgElement(t.group,"rect",u.getID(t)),i=o.Group.fromArray(e).boundingBox(),s=a.Rectangle.size(i);return l.DOMSpace.setAttr(r,{x:i[0][0],y:i[0][1],width:s[0],height:s[1],class:"pts-svgform pts-rect "+t.currentClass}),u.style(r,t.style),r}}rect(t){return this.nextID(),u.rect(this._ctx,t),this}static text(t,e,r){let i=h.svgElement(t.group,"text",u.getID(t));return l.DOMSpace.setAttr(i,{"pointer-events":"none",x:e[0],y:e[1],dx:0,dy:0,class:"pts-svgform pts-text "+t.currentClass}),i.textContent=r,u.style(i,t.style),i}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,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Typography=void 0;const i=r("./src/Pt.ts");e.Typography=class{static textWidthEstimator(t,e=["M","n","."],r=[.06,.8,.14]){let s=e.map(t),n=new i.Pt(r).dot(s);return t=>t.length*n}static truncate(t,e,r,i=""){let s=u(e.length*h(1,r/t(e)));return s<e.length?(s=d(0,s-i.length),[e.substr(0,s)+i,s]):[e,e.length]}static fontSizeToBox(t,e=1,r=!0){let s=i.Bound.fromGroup(t),n=r?s.height:s.width;return function(t){let s=i.Bound.fromGroup(t),o=(r?s.height:s.width)/n;return e*n*o}}static fontSizeToThreshold(t,e=0){return function(r,i){let s=r*i/t;return 0>e?h(s,r):0<e?d(s,r):s}}}},"./src/UI.ts":function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.UIDragger=e.UIButton=e.UI=e.UIPointerActions=e.UIShape=void 0;const i=r("./src/Pt.ts"),s=r("./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,r={},s){this._holds=new Map,this._group=i.Group.fromArray(t),this._shape=e,this._id=void 0===s?"ui_"+n._counter++:s,this._states=r,this._actions={}}static fromRectangle(t,r,i){return new this(t,e.UIShape.rectangle,r,i)}static fromCircle(t,r,i){return new this(t,e.UIShape.circle,r,i)}static fromPolygon(t,r,i){return new this(t,e.UIShape.polygon,r,i)}static fromUI(t,e,r){return new this(t.group,t.shape,e||t._states,r)}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,r){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,r),!0;if(this._actions.all)return n._trigger(this._actions.all,this,e,t,r),!0}return!1}hold(t){let e=d(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,r,i){for(let s=0,n=t.length;s<n;s++)t[s].listen(e,r,i)}render(t){t(this._group,this._states)}toString(){return"UI "+this.group.toString}_within(t){let r=null;if(this._shape===e.UIShape.rectangle)r=s.Rectangle.withinBound;else if(this._shape===e.UIShape.circle)r=s.Circle.withinBound;else{if(this._shape!==e.UIShape.polygon)return!1;r=s.Polygon.hasIntersectPoint}return r(this._group,t)}static _trigger(t,e,r,i,s){if(t)for(let n=0,o=t.length;n<o;n++)t[n]&&t[n](e,r,i,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 r=t.length;return t.splice(e,1),r>t.length}return!1}}e.UI=n,n._counter=0;class o extends n{constructor(t,r,i={},s){super(t,r,i,s),this._hoverID=-1,void 0===i.hover&&(this._states.hover=!1),void 0===i.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,r,i)=>{if(this._within(e)&&!this._states.hover){this.state("hover",!0),n._trigger(this._actions[o.enter],this,e,o.enter,i);var s=this.hold(o.move);this._hoverID=this.on(o.move,(t,r)=>{this._within(r)||this.state("dragging")||(this.state("hover",!1),n._trigger(this._actions[o.leave],this,e,o.leave,i),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,r){var i=[void 0,void 0];return t&&(i[0]=this.on(e.UIPointerActions.enter,t)),r&&(i[1]=this.on(e.UIPointerActions.leave,r)),i}offHover(t,r){var i=[!1,!1];return(void 0===t||0<=t)&&(i[0]=this.off(e.UIPointerActions.enter,t)),(void 0===r||0<=r)&&(i[1]=this.off(e.UIPointerActions.leave,r)),i}}e.UIButton=o,e.UIDragger=class extends o{constructor(t,r,s={},o){super(t,r,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 i.Pt);const a=e.UIPointerActions;this.on(a.down,(t,e,r,s)=>{-1===this._moveHoldID&&(this.state("dragging",!0),this.state("offset",new i.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,r,i)=>{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,i),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/Num.ts"),a=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:r,min:i,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 l{static warnLevel(t){return t&&(l._warnLevel=t),l._warnLevel}static getArgs(t){if(1>t.length)return[];let e=[],r=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]||r)r&&(e=[].slice.call(t[0]));else{let r=["x","y","z","w"],i=t[0];for(let t=0;t<r.length&&!(i.length&&t>=i.length)&&r[t]in i;t++)e.push(i[r[t]])}return e}static warn(t="error",e){if("error"==l.warnLevel())throw new Error(t);return"warn"==l.warnLevel()&&console.warn(t),e}static randomInt(t,e=0){return l.warn("Util.randomInt is deprecated. Please use `Num.randomRange`"),u(o.Num.random()*t)+e}static split(t,e,r,i=!1,s=!0){let n=[],o=[],a=r||e,l=0;if(0>=t.length||0>=a)return[];for(;l<t.length;){o=[];for(let r=0;r<e;r++)if(i)o.push(t[(l+r)%t.length]);else{if(l+r>=t.length)break;o.push(t[l+r])}l+=a,(!s||s&&o.length===e)&&n.push(o)}return n}static flatten(t,e=!0){let r=e?new a.Group:[];return r.concat.apply(r,t)}static combine(t,e,r){let i=[];for(let s=0,n=t.length;s<n;s++)for(let n=0,o=e.length;n<o;n++)i.push(r(t[s],e[n]));return i}static zip(t){let e=[];for(let r,i=0,s=t[0].length;i<s;i++){r=[];for(let e=0;e<t.length;e++)r.push(t[e][i]);e.push(r)}return e}static stepper(t,e=0,r=1,i){let s=e;return function(){return s+=r,s>=t&&(s=e+(s-t)),i&&i(s),s}}static forRange(t,e,r=0,i=1){let s=[];for(let n=r;n<e;n+=i)s[n]=t(n);return s}static load(t,e){var r=new XMLHttpRequest;r.open("GET",t,!0),r.onload=function(){200<=r.status&&400>r.status?e(r.responseText,!0):e(`Server error (${r.status}) when loading "${t}"`,!1)},r.onerror=function(){e("Unknown network error",!1)},r.send()}static performance(t=10){let e=Date.now(),r=[];return function(){const i=Date.now();return r.push(i-e),r.length>=t&&r.shift(),e=i,u(r.reduce((t,e)=>t+e,0)/r.length)}}static arrayCheck(t,e=2){return!(Array.isArray(t)&&t.length<e&&(l.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=l,l._warnLevel="mute"},"./src/_lib.ts":function(t,e,r){"use strict";var i=this&&this.__createBinding||(Object.create?function(t,e,r,i){void 0===i&&(i=r),Object.defineProperty(t,i,{enumerable:!0,get:function(){return e[r]}})}:function(t,e,r,i){void 0===i&&(i=r),t[i]=e[r]}),s=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||i(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),e.quickStart=e.namespace=void 0,s(r("./src/Canvas.ts"),e),s(r("./src/Create.ts"),e),s(r("./src/Form.ts"),e),s(r("./src/LinearAlgebra.ts"),e),s(r("./src/Num.ts"),e),s(r("./src/Op.ts"),e),s(r("./src/Pt.ts"),e),s(r("./src/Space.ts"),e),s(r("./src/Color.ts"),e),s(r("./src/Util.ts"),e),s(r("./src/Dom.ts"),e),s(r("./src/Svg.ts"),e),s(r("./src/Typography.ts"),e),s(r("./src/Physics.ts"),e),s(r("./src/UI.ts"),e),s(r("./src/Play.ts"),e),s(r("./src/Image.ts"),e),s(r("./src/Types.ts"),e);const n=r("./src/Canvas.ts");e.namespace=e=>{let r=t.exports;for(let t in r)"namespace"!=t&&(e[t]=r[t])},e.quickStart=(t,r="#9ab")=>{if(!window)return;let i=window;return e.namespace(i),i.space=new n.CanvasSpace(t).setup({bgcolor:r,resize:!0,retina:!0}),i.form=i.space.getForm(),function(t=null,e=null,r=null,s=null){i.space.add({start:e,animate:t,resize:s,action:r}),i.space.bindMouse().bindTouch().play()}}},"./src/uheprng.ts":function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e,r,i=48,s=1,n=i,o=Array(i),a=0,l=function(){var t=4022871197;return function(e){if(e){e=e.toString();for(var r=0;r<e.length;r++){var i=.02519603282416938*(t+=e.charCodeAt(r));i-=t=i>>>0,t=(i*=t)>>>0,t+=4294967296*(i-=t)}return 2.3283064365386963e-10*(t>>>0)}t=4022871197}}();for(e=0;e<i;e++)o[e]=l(Math.random().toString());return function(){for(l(),e=0;e<i;e++)o[e]=l(" ");s=1,n=i}(),function(t){for(t=function(t){return t=(t=(t=t.replace(/(^\s*)|(\s*$)/gi,"")).replace(/[\x00-\x1F]/gi,"")).replace(/\n /,"\n")}(t),l(t),e=0;e<t.length;e++)for(a=t.charCodeAt(e),r=0;r<i;r++)o[r]-=l(a.toString()),0>o[r]&&(o[r]+=1)}(t),{random(){++n>=i&&(n=0);var t=1768863*o[n]+2.3283064365386963e-10*s;return o[n]=t-(s=0|t)}}}}})}()}])}));
//# sourceMappingURL=pts.min.js.map