/*! * pts.js 0.10.5 (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(r){if(i[r])return i[r].exports;var s=i[r]={i:r,l:!1,exports:{}};return t[r].call(s.exports,s,s.exports,e),s.l=!0,s.exports}var i={};return e.m=t,e.c=i,e.d=function(t,i,r){e.o(t,i)||Object.defineProperty(t,i,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,i){if(1&i&&(t=e(t)),8&i)return t;if(4&i&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&i&&"string"!=typeof t)for(var s in t)e.d(r,s,function(e){return t[e]}.bind(null,s));return r},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t){t.exports=function(){var t=Math.PI,e=Math.abs,i=Number.MAX_VALUE,r=Number.MIN_VALUE,s=Math.sin,n=Math.cos,o=Math.sqrt,a=Math.atan2,l=Math.pow,h=Math.min,u=Math.floor,c=Math.max;return function(t){function e(r){if(i[r])return i[r].exports;var s=i[r]={i:r,l:!1,exports:{}};return t[r].call(s.exports,s,s.exports,e),s.l=!0,s.exports}var i={};return e.m=t,e.c=i,e.d=function(t,i,r){e.o(t,i)||Object.defineProperty(t,i,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,i){if(1&i&&(t=e(t)),8&i)return t;if(4&i&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&i&&"string"!=typeof t)for(var s in t)e.d(r,s,function(e){return t[e]}.bind(null,s));return r},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s="./src/_lib.ts")}({"./src/Canvas.ts":function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.CanvasForm=e.CanvasSpace=void 0;const r=i("./src/Space.ts"),s=i("./src/Form.ts"),n=i("./src/Pt.ts"),o=i("./src/Util.ts"),a=i("./src/Typography.ts"),l=i("./src/Op.ts"),h=i("./src/Image.ts");class d extends r.MultiTouchSpace{constructor(t,e){super(),this._pixelScale=1,this._autoResize=!0,this._bgcolor="#e1e9f0",this._offscreen=!1,this._initialResize=!1;var i=null;if(this.id="pt",t instanceof Element)i=t,this.id="pts_existing_space";else{let e=t;e="#"===t[0]||"."===t[0]?t:"#"+t,i=document.querySelector(e),this.id=e.substr(1)}i?"canvas"==i.nodeName.toLowerCase()?(this._canvas=i,this._container=i.parentElement,this._autoResize=!1):(this._container=i,this._canvas=this._createElement("canvas",this.id+"_canvas"),this._container.appendChild(this._canvas),this._initialResize=!0):(this._container=this._createElement("div",this.id+"_container"),this._canvas=this._createElement("canvas",this.id),this._container.appendChild(this._canvas),document.body.appendChild(this._container)),setTimeout(this._ready.bind(this,e),100),this._ctx=this._canvas.getContext("2d")}_createElement(t="div",e){let i=document.createElement(t);return i.setAttribute("id",e),i}_ready(t){if(!this._container)throw new Error(`Cannot initiate #${this.id} element`);for(let t in this._isReady=!0,this._resizeHandler(null),this.clear(this._bgcolor),this._canvas.dispatchEvent(new Event("ready")),this.players)this.players.hasOwnProperty(t)&&this.players[t].start&&this.players[t].start(this.bound.clone(),this);this._pointer=this.center,this._initialResize=!1,t&&t(this.bound,this._canvas)}setup(t){if(this._bgcolor=t.bgcolor?t.bgcolor:"transparent",this.autoResize=null!=t.resize&&t.resize,!1!==t.retina){let t=window&&window.devicePixelRatio||1,e=this._ctx.webkitBackingStorePixelRatio||this._ctx.mozBackingStorePixelRatio||this._ctx.msBackingStorePixelRatio||this._ctx.oBackingStorePixelRatio||this._ctx.backingStorePixelRatio||1;this._pixelScale=c(1,t/e)}return t.offscreen?(this._offscreen=!0,this._offCanvas=this._createElement("canvas",this.id+"_offscreen"),this._offCtx=this._offCanvas.getContext("2d")):this._offscreen=!1,this}set autoResize(t){window&&(this._autoResize=t,t?window.addEventListener("resize",this._resizeHandler.bind(this)):window.removeEventListener("resize",this._resizeHandler.bind(this)))}get autoResize(){return this._autoResize}resize(t,e){for(let i in this.bound=t,this._canvas.width=this.bound.size.x*this._pixelScale,this._canvas.height=this.bound.size.y*this._pixelScale,this._canvas.style.width=u(this.bound.size.x)+"px",this._canvas.style.height=u(this.bound.size.y)+"px",this._offscreen&&(this._offCanvas.width=this.bound.size.x*this._pixelScale,this._offCanvas.height=this.bound.size.y*this._pixelScale),1!=this._pixelScale&&(this._ctx.scale(this._pixelScale,this._pixelScale),this._offscreen&&this._offCtx.scale(this._pixelScale,this._pixelScale)),this.players)if(this.players.hasOwnProperty(i)){let t=this.players[i];t.resize&&t.resize(this.bound,e)}return this.render(this._ctx),e&&!this.isPlaying&&this.playOnce(0),this}_resizeHandler(t){if(window){let e=this._autoResize||this._initialResize?this._container.getBoundingClientRect():this._canvas.getBoundingClientRect();if(e){let i=n.Bound.fromBoundingRect(e);i.center=i.center.add(window.pageXOffset,window.pageYOffset),this.resize(i,t)}}}set background(t){this._bgcolor=t}get background(){return this._bgcolor}get pixelScale(){return this._pixelScale}get hasOffscreen(){return this._offscreen}get offscreenCtx(){return this._offCtx}get offscreenCanvas(){return this._offCanvas}getForm(){return new p(this)}get element(){return this._canvas}get parent(){return this._container}get ready(){return this._isReady}get ctx(){return this._ctx}clear(t){t&&(this._bgcolor=t);const e=this._ctx.fillStyle;return this._bgcolor&&"transparent"!==this._bgcolor?((0===this._bgcolor.indexOf("rgba")||9===this._bgcolor.length&&0===this._bgcolor.indexOf("#"))&&this._ctx.clearRect(-1,-1,this._canvas.width+1,this._canvas.height+1),this._ctx.fillStyle=this._bgcolor,this._ctx.fillRect(-1,-1,this._canvas.width+1,this._canvas.height+1)):this._ctx.clearRect(-1,-1,this._canvas.width+1,this._canvas.height+1),this._ctx.fillStyle=e,this}clearOffscreen(t){return this._offscreen&&(t?(this._offCtx.fillStyle=t,this._offCtx.fillRect(-1,-1,this._canvas.width+1,this._canvas.height+1)):this._offCtx.clearRect(-1,-1,this._offCanvas.width+1,this._offCanvas.height+1)),this}playItems(t){this._isReady&&(this._ctx.save(),this._offscreen&&this._offCtx.save(),super.playItems(t),this._ctx.restore(),this._offscreen&&this._offCtx.restore(),this.render(this._ctx))}dispose(){if(window)return window.removeEventListener("resize",this._resizeHandler.bind(this)),this.stop(),this.removeAll(),this}recorder(t,e="webm",i=15e6){let r=this._canvas.captureStream();const s=new MediaRecorder(r,{mimeType:"video/"+e,bitsPerSecond:i});return s.ondataavailable=function(i){let r=URL.createObjectURL(new Blob([i.data],{type:"video/"+e}));if("function"==typeof t)t(r);else if(t){let t=document.createElement("a");t.href=r,t.download="canvas_video."+e,t.click(),t.remove()}},s}}e.CanvasSpace=d;class p extends s.VisualForm{constructor(t){super(),this._style={fillStyle:"#f03",strokeStyle:"#fff",lineWidth:1,lineJoin:"bevel",lineCap:"butt",globalAlpha:1};const e=t=>{this._ctx=t,this._ctx.fillStyle=this._style.fillStyle,this._ctx.strokeStyle=this._style.strokeStyle,this._ctx.lineJoin="bevel",this._ctx.font=this._font.value,this._ready=!0};t instanceof CanvasRenderingContext2D?e(t):(this._space=t,this._space.add({start:()=>{e(this._space.ctx)}}))}get space(){return this._space}get ctx(){return this._space.ctx}useOffscreen(t=!0,e=!1){return e&&this._space.clearOffscreen("string"==typeof e?e:null),this._ctx=this._space.hasOffscreen&&t?this._space.offscreenCtx:this._space.ctx,this}renderOffscreen(t=[0,0]){this._space.hasOffscreen&&this._space.ctx.drawImage(this._space.offscreenCanvas,t[0],t[1],this._space.width,this._space.height)}alpha(t){return this._ctx.globalAlpha=t,this._style.globalAlpha=t,this}fill(t){return"boolean"==typeof t?this.filled=t:(this.filled=!0,this._style.fillStyle=t,this._ctx.fillStyle=t),this}stroke(t,e,i,r){return"boolean"==typeof t?this.stroked=t:(this.stroked=!0,this._style.strokeStyle=t,this._ctx.strokeStyle=t,e&&(this._ctx.lineWidth=e,this._style.lineWidth=e),i&&(this._ctx.lineJoin=i,this._style.lineJoin=i),r&&(this._ctx.lineCap=r,this._style.lineCap=r)),this}gradient(t){let e=[];2>t.length&&t.push([.99,"#000"],[1,"#000"]);for(let i=0,r=t.length;i{t=t.map(t=>t.abs()),i&&i.map(t=>t.abs());let r=i?this.ctx.createRadialGradient(t[0][0],t[0][1],t[1][0],i[0][0],i[0][1],i[1][0]):this.ctx.createLinearGradient(t[0][0],t[0][1],t[1][0],t[1][1]);for(let t=0,i=e.length;tthis._ctx.measureText(t).width):void 0,this}getTextWidth(t){return this._estimateTextWidth?this._estimateTextWidth(t):this._ctx.measureText(t+" .").width}_textTruncate(t,e,i=""){return a.Typography.truncate(this.getTextWidth.bind(this),t,e,i)}_textAlign(t,e,i,r){let s=o.Util.iterToArray(t);if(o.Util.arrayCheck(s)){r||(r=l.Rectangle.center(s));var a=s[0][0];"end"==this._ctx.textAlign||"right"==this._ctx.textAlign?a=s[1][0]:("center"==this._ctx.textAlign||"middle"==this._ctx.textAlign)&&(a=r[0]);var h=r[1];return"top"==e||"start"==e?h=s[0][1]:("end"==e||"bottom"==e)&&(h=s[1][1]),i?new n.Pt(a+i[0],h+i[1]):new n.Pt(a,h)}}reset(){for(let t in this._style)this._style.hasOwnProperty(t)&&(this._ctx[t]=this._style[t]);return this._font=new s.Font,this._ctx.font=this._font.value,this}_paint(){this._filled&&this._ctx.fill(),this._stroked&&this._ctx.stroke()}static point(t,e,i=5,r="square"){if(e){if(!p[r])throw new Error(r+" is not a static function of CanvasForm");p[r](t,e,i)}}point(t,e=5,i="square"){return p.point(this._ctx,t,e,i),this._paint(),this}static circle(t,e,i=10){e&&(t.beginPath(),t.arc(e[0],e[1],i,0,o.Const.two_pi,!1),t.closePath())}circle(t){let e=o.Util.iterToArray(t);return p.circle(this._ctx,e[0],e[1][0]),this._paint(),this}static ellipse(t,e,i,r=0,s=0,n=o.Const.two_pi,a=!1){e&&i&&(t.beginPath(),t.ellipse(e[0],e[1],i[0],i[1],r,s,n,a))}ellipse(t,e,i=0,r=0,s=o.Const.two_pi,n=!1){return p.ellipse(this._ctx,t,e,i,r,s,n),this._paint(),this}static arc(t,e,i,r,s,n){e&&(t.beginPath(),t.arc(e[0],e[1],i,r,s,n))}arc(t,e,i,r,s){return p.arc(this._ctx,t,e,i,r,s),this._paint(),this}static square(t,e,i){if(e){let r=e[0]-i,s=e[1]-i,n=e[0]+i,o=e[1]+i;t.beginPath(),t.moveTo(r,s),t.lineTo(r,o),t.lineTo(n,o),t.lineTo(n,s),t.closePath()}}square(t,e){return p.square(this._ctx,t,e),this._paint(),this}static line(t,e){if(o.Util.arrayCheck(e)){let i=0;t.beginPath();for(let r of e)r&&(0{if(!t)return e;if(s&&i*u>h[1]-2*u)return e;if(1e4=o||r[1]===t.length)&&(o=void 0);let a=r[0].substr(0,o);return e.push(a),0>=r[1]||r[1]===t.length?e:d(t.substr(o||r[1]),e,i+1)},p=d(e),_=p.length*u,g=a;if("middle"==r||"center"==r){let t=(h[1]-_)/2;s&&(t=c(0,t)),g=new n.Group(a[0].$add(0,t),a[1].$subtract(0,t))}else g="bottom"==r?new n.Group(a[0].$add(0,h[1]-_),a[1]):new n.Group(a[0],a[0].$add(h[0],_));let f=l.Rectangle.center(g);for(let t=0,e=p.length;t=t.length){let e=e=>t[e]||"F";t=`${e(0)}${e(0)}${e(1)}${e(1)}${e(2)}${e(2)}`}let e=1;8===t.length&&(e=t.substr(6)&&1,t=t.substring(0,6));let i=parseInt(t,16);return new _(i>>16,255&i>>8,255&i,e)}static rgb(...t){return _.from(...t).toMode("rgb")}static hsl(...t){return _.from(...t).toMode("hsl")}static hsb(...t){return _.from(...t).toMode("hsb")}static lab(...t){return _.from(...t).toMode("lab")}static lch(...t){return _.from(...t).toMode("lch")}static luv(...t){return _.from(...t).toMode("luv")}static xyz(...t){return _.from(...t).toMode("xyz")}static maxValues(t){return _.ranges[t].zipSlice(1).$take([0,1,2])}get hex(){return this.toString("hex")}get rgb(){return this.toString("rgb")}get rgba(){return this.toString("rgba")}clone(){let t=new _(this);return t.toMode(this._mode),t}toMode(t,e=!1){if(e){let e=this._mode.toUpperCase()+"to"+t.toUpperCase();if(!_[e])throw new Error("Cannot convert color with "+e);this.to(_[e](this,this._isNorm,this._isNorm))}return this._mode=t,this}get mode(){return this._mode}get r(){return this[0]}set r(t){this[0]=t}get g(){return this[1]}set g(t){this[1]=t}get b(){return this[2]}set b(t){this[2]=t}get h(){return"lch"==this._mode?this[2]:this[0]}set h(t){this["lch"==this._mode?2:0]=t}get s(){return this[1]}set s(t){this[1]=t}get l(){return"hsl"==this._mode?this[2]:this[0]}set l(t){this["hsl"==this._mode?2:0]=t}get a(){return this[1]}set a(t){this[1]=t}get c(){return this[1]}set c(t){this[1]=t}get u(){return this[1]}set u(t){this[1]=t}get v(){return this[2]}set v(t){this[2]=t}set alpha(t){3i;i++)this[i]=t?p.Num.mapToRange(this[i],e[i][0],e[i][1],0,1):p.Num.mapToRange(this[i],0,1,e[i][0],e[i][1]);return this._isNorm=t,this}$normalize(t=!0){return this.clone().normalize(t)}toString(t="mode"){if("hex"==t){let t=t=>{let e=u(t).toString(16);return 2>e.length?"0"+e:e};return`#${t(this[0])}${t(this[1])}${t(this[2])}`}return"rgba"==t?`rgba(${u(this[0])},${u(this[1])},${u(this[2])},${this.alpha})`:"rgb"==t?`rgb(${u(this[0])},${u(this[1])},${u(this[2])})`:`${this._mode}(${this[0]},${this[1]},${this[2]},${this.alpha})`}static RGBtoHSL(t,e=!1,i=!1){let[r,s,n]=e?t:t.$normalize(),o=c(r,s,n),a=h(r,s,n),l=(o+a)/2,u=l,d=l;if(o==a)l=0,u=0;else{let t=o-a;u=.5=n?n*(1+s):n+s-n*s,a=2*n-o,l=t=>1>6*(t=0>t?t+1:12*t?o:2>3*t?a+(o-a)*(2/3-t)*6:a,h=i?1:255;return _.rgb(h*l(r+1/3),h*l(r),h*l(r-1/3),t.alpha)}static RGBtoHSB(t,e=!1,i=!1){let[r,s,n]=e?t:t.$normalize(),o=c(r,s,n),a=h(r,s,n),l=o-a,u=0,d=0===o?0:l/o;return o!=a&&(o===r?u=(s-n)/l+(st;t++)r[t]=.04045t;t++)o[t]=0>o[t]?0:.0031308.008856{let e=t*t*t;return.008856t&&(t*=65536),256>(t=u(t))&&(t|=t<<8);for(let e,i=0;255>i;i++)e=1&i?d[i]^255&t:d[i]^255&t>>8,this.perm[i]=this.perm[i+256]=e;return this}noise2D(){let t=c(0,u(this._n[0]))%255,e=c(0,u(this._n[1]))%255,i=this._n[0]%255-t,r=this._n[1]%255-e,s=a.Vec.dot(l[(t+this.perm[e])%12],[i,r,0]),n=a.Vec.dot(l[(t+this.perm[e+1])%12],[i,r-1,0]),h=a.Vec.dot(l[(t+1+this.perm[e])%12],[i-1,r,0]),d=a.Vec.dot(l[(t+1+this.perm[e+1])%12],[i-1,r-1,0]),p=t=>t*t*t*(t*(6*t-15)+10),_=p(i);return o.Num.lerp(o.Num.lerp(s,h,_),o.Num.lerp(n,d,_),p(r))}}e.Noise=p;class _ extends r.Group{constructor(){super(...arguments),this._mesh=[]}delaunay(t=!0){if(3>this.length)return[];this._mesh=[];let e=this.length,i=[];for(let t=0;tthis[e][0]-this[t][0]);let r=this.slice(),s=this._superTriangle();r=r.concat(s);let o=[this._circum(e,e+1,e+2,s)],a=[],l=[];for(let t=0,e=i.length;ti*i?(a.push(t),l.push(t.triangle),o.splice(h,1)):u[0]*u[0]+u[1]*u[1]-i*i>n.Const.epsilon||(s.push(t.i,t.j,t.j,t.k,t.k,t.i),o.splice(h,1))}for(_._dedupe(s),h=s.length;1{t.parentNode.removeChild(t)}),super.remove(t)}removeAll(){return this._container.innerHTML="",super.removeAll()}}e.HTMLSpace=l;class h extends s.VisualForm{constructor(t){super(),this._style={filled:!0,stroked:!0,background:"#f03","border-color":"#fff",color:"#000","border-width":"1px","border-radius":"0","border-style":"solid",opacity:1,position:"absolute",top:0,left:0,width:0,height:0},this._ctx={group:null,groupID:"pts",groupCount:0,currentID:"pts0",currentClass:"",style:{}},this._ready=!1,this._space=t,this._space.add({start:()=>{this._ctx.group=this._space.element,this._ctx.groupID="pts_dom_"+h.groupID++,this._ctx.style=Object.assign({},this._style),this._ready=!0}})}get space(){return this._space}styleTo(t,e,i=""){if(void 0===this._ctx.style[t])throw new Error(t+" style property doesn't exist");this._ctx.style[t]=`${e}${i}`}alpha(t){return this.styleTo("opacity",t),this}fill(t){return"boolean"==typeof t?(this.styleTo("filled",t),!t&&this.styleTo("background","transparent")):(this.styleTo("filled",!0),this.styleTo("background",t)),this}stroke(t,e){return"boolean"==typeof t?(this.styleTo("stroked",t),!t&&this.styleTo("border-width",0)):(this.styleTo("stroked",!0),this.styleTo("border-color",t),this.styleTo("border-width",(e||1)+"px")),this}fillText(t){return this.styleTo("color",t),this}cls(t){return this._ctx.currentClass="boolean"==typeof t?"":t,this}font(t,e,i,r,s){return"number"==typeof t?(this._font.size=t,s&&(this._font.face=s),e&&(this._font.weight=e),i&&(this._font.style=i),r&&(this._font.lineHeight=r)):this._font=t,this._ctx.style.font=this._font.value,this}reset(){return this._ctx.style=Object.assign({},this._style),this._font=new s.Font(10,"sans-serif"),this._ctx.style.font=this._font.value,this}updateScope(t,e){return this._ctx.group=e,this._ctx.groupID=t,this._ctx.groupCount=0,this.nextID(),this._ctx}scope(t){if(!t||null==t.animateID)throw new Error("item not defined or not yet added to Space");return this.updateScope(h.scopeID(t),this.space.element)}nextID(){return this._ctx.groupCount++,this._ctx.currentID=`${this._ctx.groupID}-${this._ctx.groupCount}`,this._ctx.currentID}static getID(t){return t.currentID||"p-"+h.domID++}static scopeID(t){return"item-"+t.animateID}static style(t,e){let i=[];for(let t in e.filled||i.push("background: none"),e.stroked||i.push("border: none"),e)if(e.hasOwnProperty(t)&&"filled"!=t&&"stroked"!=t){let r=e[t];if(r){if(!e.filled&&0===t.indexOf("background"))continue;if(!e.stroked&&0===t.indexOf("border-width"))continue;i.push(`${t}: ${r}`)}}return l.setAttr(t,{style:i.join(";")})}static rectStyle(t,e,i){return t.style.left=e[0]+"px",t.style.top=e[1]+"px",t.style.width=i[0]+"px",t.style.height=i[1]+"px",t}static textStyle(t,e){return t.style.left=e[0]+"px",t.style.top=e[1]+"px",t}static point(t,e,i=5,r="square"){return"circle"===r?h.circle(t,e,i):h.square(t,e,i)}point(t,e=5,i="square"){return this.nextID(),"circle"==i&&this.styleTo("border-radius","100%"),h.point(this._ctx,t,e,i),this}static circle(t,e,i=10){let r=l.htmlElement(t.group,"div",h.getID(t));return l.setAttr(r,{class:"pts-form pts-circle "+t.currentClass}),h.rectStyle(t,new o.Pt(e).$subtract(i),new o.Pt(2*i,2*i)),h.style(r,t.style),r}circle(t){return this.nextID(),this.styleTo("border-radius","100%"),h.circle(this._ctx,t[0],t[1][0]),this}static square(t,e,i){let r=l.htmlElement(t.group,"div",h.getID(t));return l.setAttr(r,{class:"pts-form pts-square "+t.currentClass}),h.rectStyle(t,new o.Pt(e).$subtract(i),new o.Pt(2*i,2*i)),h.style(r,t.style),r}square(t,e){return this.nextID(),h.square(this._ctx,t,e),this}static rect(t,e){let i=n.Util.iterToArray(e);if(n.Util.arrayCheck(i)){let e=l.htmlElement(t.group,"div",h.getID(t));return l.setAttr(e,{class:"pts-form pts-rect "+t.currentClass}),h.rectStyle(t,i[0],i[1]),h.style(e,t.style),e}}rect(t){return this.nextID(),this.styleTo("border-radius","0"),h.rect(this._ctx,t),this}static text(t,e,i){let r=l.htmlElement(t.group,"div",h.getID(t));return l.setAttr(r,{class:"pts-form pts-text "+t.currentClass}),r.textContent=i,h.textStyle(t,e),h.style(r,t.style),r}text(t,e){return this.nextID(),h.text(this._ctx,t,e),this}log(t){return this.fill("#000").stroke("#fff",.5).text([10,14],t),this}arc(){return n.Util.warn("arc is not implemented in HTMLForm"),this}line(){return n.Util.warn("line is not implemented in HTMLForm"),this}polygon(){return n.Util.warn("polygon is not implemented in HTMLForm"),this}}e.HTMLForm=h,h.groupID=0,h.domID=0},"./src/Form.ts":function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Font=e.VisualForm=e.Form=void 0;class i{constructor(){this._ready=!1}get ready(){return this._ready}}e.Form=i,e.VisualForm=class extends i{constructor(){super(...arguments),this._filled=!0,this._stroked=!0,this._font=new r(14,"sans-serif")}get filled(){return this._filled}set filled(t){this._filled=t}get stroked(){return this._stroked}set stroked(t){this._stroked=t}get currentFont(){return this._font}_multiple(t,e,...i){if(!t)return this;for(let r=0,s=t.length;r{r&&r(t)}),n}load(t){return new Promise((e,i)=>{this._img.src=t,this._img.onload=()=>{this._editable&&(!this._cv&&(this._cv=document.createElement("canvas")),this._drawToScale(this._scale,this._img),this._data=this._ctx.getImageData(0,0,this._cv.width,this._cv.height)),this._loaded=!0,e(this)},this._img.onerror=t=>{i(t)}})}_drawToScale(t,e){const i="number"==typeof t?[t,t]:t,r=e.width,s=e.height;this._cv.width=r*i[0],this._cv.height=s*i[1],this._ctx=this._cv.getContext("2d"),e&&this._ctx.drawImage(e,0,0,r,s,0,0,this._cv.width,this._cv.height)}bitmap(t){const e=t?t[0]:this._cv.width,i=t?t[1]:this._cv.height;return createImageBitmap(this._cv,0,0,e,i)}sync(){1===this._scale?this._img.src=this.toBase64():this.bitmap().then(t=>{this._drawToScale(1/this._scale,t),this.load(this.toBase64())})}pixel(t,e=!0){const i="number"==typeof e?e:e?this._scale:1;return s.getPixel(this._data,[t[0]*i,t[1]*i])}static getPixel(t,e){const i=new r.Pt(0,0,0,0);if(e[0]>=t.width||e[1]>=t.height)return i;const s=u(e[1])*(4*t.width)+4*u(e[0]),n=t.data;return s>=n.length-4?i:new r.Pt(n[s],n[s+1],n[s+2],n[s+3])}resize(t,e=!1){let i=e?t:[t[0]/this._img.naturalWidth,t[1]/this._img.naturalHeight];return this._drawToScale(i,this._img),this._data=this._ctx.getImageData(0,0,this._cv.width,this._cv.height),this}crop(t){let e=t.topLeft.scale(this._scale),i=t.size.scale(this._scale);return this._ctx.getImageData(e.x,e.y,i.x,i.y)}filter(t){return this._ctx.filter=t,this._ctx.drawImage(this._cv,0,0),this._ctx.filter="none",this}cleanup(){this._cv&&this._cv.remove(),this._img&&this._img.remove(),this._data=null}static fromBlob(t,e=!1,i=1){let r=URL.createObjectURL(t);return new s(e,i).load(r)}static imageDataToBlob(t){return new Promise((function(e){let i=document.createElement("canvas");i.width=t.width,i.height=t.height,i.getContext("2d").putImageData(t,0,0),i.toBlob(t=>{e(t),i.remove()})}))}toBase64(){return this._cv.toDataURL()}toBlob(){return new Promise(t=>{this._cv.toBlob(e=>t(e))})}get current(){return this._editable?this._cv:this._img}get image(){return this._img}get canvas(){return this._cv}get data(){return this._data}get ctx(){return this._ctx}get loaded(){return this._loaded}get pixelScale(){return this._scale}get imageSize(){return new r.Pt(this._img.width,this._img.height)}get canvasSize(){return new r.Pt(this._cv.width,this._cv.height)}}e.Img=s},"./src/LinearAlgebra.ts":function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Mat=e.Vec=void 0;const l=a("./src/Pt.ts"),u=a("./src/Op.ts");class d{static add(t,e){if("number"==typeof e)for(let i=0,r=t.length;ic(t,e.length),0):t[0].length;for(let i=0;ir?n-=s:n=h(e,i)&&t<=c(e,i)}static randomRange(t,e=0){let i=t>e?t-e:e-t;return t+Math.random()*i}static randomPt(t,e){let i=new g.Pt(t.length),r=e?f.Vec.subtract(e,t):t,s=e?t:new g.Pt(t.length).fill(0);for(let t=0,e=i.length;t{if(2>t.length||2>e.length)throw new Error("Pt dimension cannot be less than 2");let i=t.$subtract(r),s=e.$subtract(r);if(0<=i[0]&&0>s[0])return 1;if(0>i[0]&&0<=s[0])return-1;if(0==i[0]&&0==s[0])return 0<=i[1]||0<=s[1]?i[1]>s[1]?1:-1:s[1]>i[1]?1:-1;let n=i.$cross2D(s);return 0>n?1:0s[0]*s[0]+s[1]*s[1]?1:-1})}static scale(t,e,i){let r=p.Util.iterToArray(void 0!==t[0]&&"number"==typeof t[0]?[t]:t),s="number"==typeof e?g.Pt.make(r[0].length,e):e;i||(i=g.Pt.make(r[0].length,0));for(let t,e=0,n=r.length;ei;i++)e[i]=n(i*t/180);return{table:e,cos:t=>e[u(y.boundAngle(y.toDegree(t)))]}}static sinTable(){let e=new Float64Array(360);for(let i=0;360>i;i++)e[i]=s(i*t/180);return{table:e,sin:t=>e[u(y.boundAngle(y.toDegree(t)))]}}}r.Geom=y;class w{static linear(t,e=1){return e*t}static quadraticIn(t,e=1){return e*t*t}static quadraticOut(t,e=1){return-e*t*(t-2)}static quadraticInOut(t,e=1){let i=2*t;return.5>t?e/2*t*t*4:-e/2*((i-1)*(i-3)-1)}static cubicIn(t,e=1){return e*t*t*t}static cubicOut(t,e=1){let i=t-1;return e*(i*i*i+1)}static cubicInOut(t,e=1){let i=2*t;return.5>t?e/2*i*i*i:e/2*((i-2)*(i-2)*(i-2)+2)}static exponentialIn(t,e=1,i=.25){return e*l(t,1/i)}static exponentialOut(t,e=1,i=.25){return e*l(t,i)}static sineIn(t,e=1){return-e*n(t*p.Const.half_pi)+e}static sineOut(t,e=1){return e*s(t*p.Const.half_pi)}static sineInOut(e,i=1){return-i/2*(n(t*e)-1)}static cosineApprox(t,e=1){let i=t*t,r=i*i;return e*(r*i*4/9-17*r/9+22*i/9)}static circularIn(t,e=1){return-e*(o(1-t*t)-1)}static circularOut(t,e=1){let i=t-1;return e*o(1-i*i)}static circularInOut(t,e=1){let i=2*t;return.5>t?-e/2*(o(1-i*i)-1):e/2*(o(1-(i-2)*(i-2))+1)}static elasticIn(t,e=1,i=.7){let r=t-1,n=i/p.Const.two_pi*1.5707963267948966;return e*(-l(2,10*r)*s((r-n)*p.Const.two_pi/i))}static elasticOut(t,e=1,i=.7){let r=i/p.Const.two_pi*1.5707963267948966;return e*(l(2,-10*t)*s((t-r)*p.Const.two_pi/i))+e}static elasticInOut(t,e=1,i=.6){let r=2*t,n=i/p.Const.two_pi*1.5707963267948966;return.5>t?(r-=1,e*(l(2,10*r)*s((r-n)*p.Const.two_pi/i)*-.5)):(r-=1,e*(l(2,-10*r)*s((r-n)*p.Const.two_pi/i)*.5)+e)}static bounceIn(t,e=1){return e-w.bounceOut(1-t,e)}static bounceOut(t,e=1){return t<1/2.75?e*(7.5625*t*t):t<2/2.75?e*(7.5625*(t-=1.5/2.75)*t+.75):t<2.5/2.75?e*(7.5625*(t-=2.25/2.75)*t+.9375):e*(7.5625*(t-=2.625/2.75)*t+.984375)}static bounceInOut(t,e=1){return.5>t?w.bounceIn(2*t,e)/2:w.bounceOut(2*t-1,e)/2+e/2}static sigmoid(t,e=1,i=10){return e/(1+d(-i*(t-.5)))}static logSigmoid(t,e=1,i=.7){i=c(p.Const.epsilon,h(1-p.Const.epsilon,i));let r=1/(1+d((t-.5)*(i=1/(1-i))*-2)),s=1/(1+d(i));return e*(r-s)/(1/(1+d(-i))-s)}static seat(t,e=1,i=.5){return.5>t?e*l(2*t,1-i)/2:e*(1-l(2*(1-t),1-i)/2)}static quadraticBezier(t,e=1,i=[.05,.95]){let r="number"==typeof i?i:i[0],s="number"==typeof i?.5:i[1],n=1-2*r;0===n&&(n=p.Const.epsilon);let a=(o(r*r+n*t)-r)/n;return e*(a*a*(1-2*s)+2*s*a)}static cubicBezier(t,e=1,i=[.1,.7],r=[.9,.2]){let s=new g.Group(new g.Pt(0,0),new g.Pt(i),new g.Pt(r),new g.Pt(1,1));return e*_.Curve.bezierStep(new g.Pt(t*t*t,t*t,t,1),_.Curve.controlPoints(s)).y}static quadraticTarget(t,e=1,i=[.2,.35]){let r=h(1-p.Const.epsilon,c(p.Const.epsilon,i[0])),s=h(1,c(0,i[1])),n=(1-s)/(1-r)-s/r;return e*h(1,c(0,n*(t*t)-(n*(r*r)-s)/r*t))}static cliff(t,e=1,i=.5){return t>i?e:0}static step(t,e,i,r,...s){let n=1/e;return t(u(i/n)*n,r,...s)}}r.Shaping=w,r.Range=class{constructor(t){this._dims=0,this._source=g.Group.fromPtArray(t),this.calc()}get max(){return this._max.clone()}get min(){return this._min.clone()}get magnitude(){return this._mag.clone()}calc(){if(this._source){let t=this._source[0].length;this._dims=t;let e=new g.Pt(t),i=new g.Pt(t),r=new g.Pt(t);for(let s=0;sd.Util.warn("Group's length is less than "+e,t);class m{static fromAngle(t,e,i){let r=new _.Group(new _.Pt(t),new _.Pt(t));return r[1].toAngle(e,i,!0),r}static slope(t,e){return 0==e[0]-t[0]?void 0:(e[1]-t[1])/(e[0]-t[0])}static intercept(t,e){if(0!=e[0]-t[0]){let i=(e[1]-t[1])/(e[0]-t[0]),r=t[1]-i*t[0];return{slope:i,yi:r,xi:0==i?void 0:-r/i}}}static sideOfPt2D(t,e){let i=d.Util.iterToArray(t);return(i[1][0]-i[0][0])*(e[1]-i[0][1])-(e[0]-i[0][0])*(i[1][1]-i[0][1])}static collinear(t,e,i,r=.01){let s=new _.Pt(0,0,0).to(t).$subtract(e),n=new _.Pt(0,0,0).to(t).$subtract(i);return s.$cross(n).divide(1e3).equals(new _.Pt(0,0,0),r)}static magnitude(t){let e=d.Util.iterToArray(t);return 2<=e.length?e[1].$subtract(e[0]).magnitude():0}static magnitudeSq(t){let e=d.Util.iterToArray(t);return 2<=e.length?e[1].$subtract(e[0]).magnitudeSq():0}static perpendicularFromPt(t,e,i=!1){let r=d.Util.iterToArray(t);if(!r[0].equals(r[1])){let t=r[0].$subtract(r[1]),s=r[1].$subtract(e),n=s.$subtract(t.$project(s));return i?n:n.$add(e)}}static distanceFromPt(t,e){let i=d.Util.iterToArray(t),r=m.perpendicularFromPt(i,e,!0);return r?r.magnitude():i[0].$subtract(e).magnitude()}static intersectRay2D(t,e){let i=d.Util.iterToArray(t),r=d.Util.iterToArray(e),s=m.intercept(i[0],i[1]),n=m.intercept(r[0],r[1]),o=i[0],a=r[0];if(null==s){if(null==n)return;let t=-n.slope*(a[0]-o[0])+a[1];return new _.Pt(o[0],t)}if(null==n){let t=-s.slope*(o[0]-a[0])+o[1];return new _.Pt(a[0],t)}if(n.slope!=s.slope){let t=(s.slope*o[0]-n.slope*a[0]+a[1]-o[1])/(s.slope-n.slope),e=s.slope*(t-o[0])+o[1];return new _.Pt(t,e)}return s.yi==n.yi?new _.Pt(o[0],o[1]):void 0}static intersectLine2D(t,e){let i=d.Util.iterToArray(t),r=d.Util.iterToArray(e),s=m.intersectRay2D(i,r);return s&&p.Geom.withinBound(s,i[0],i[1])&&p.Geom.withinBound(s,r[0],r[1])?s:void 0}static intersectLineWithRay2D(t,e){let i=d.Util.iterToArray(t),r=d.Util.iterToArray(e),s=m.intersectRay2D(i,r);return s&&p.Geom.withinBound(s,i[0],i[1])?s:void 0}static intersectPolygon2D(t,e,i=!1){let r=d.Util.iterToArray(t),s=d.Util.iterToArray(e),n=i?m.intersectLineWithRay2D:m.intersectLine2D,o=new _.Group;for(let t=0,e=s.length;te(i[1]/i[0])?0>o[1]?0:2:0>o[0]?3:1,m.intersectRay2D(s[a],n)}}static marker(t,e,i="arrow",r=!0){let s=d.Util.iterToArray(t),n=r?1:0,o=s[r?0:1].$subtract(s[n]);if(0===o.magnitudeSq())return new _.Group;o.unit();let a=p.Geom.perpendicular(o).multiply(e[0]).add(s[n]);return"arrow"==i?(a.add(o.$multiply(e[1])),new _.Group(s[n],a[0],a[1])):new _.Group(a[0],a[1])}static toRect(t){let e=d.Util.iterToArray(t);return new _.Group(e[0].$min(e[1]),e[0].$max(e[1]))}}a.Line=m;class y{static from(t,e,i){return y.fromTopLeft(t,e,i)}static fromTopLeft(t,e,i){let r="number"==typeof e?[e,i||e]:e;return new _.Group(new _.Pt(t),new _.Pt(t).add(r))}static fromCenter(t,e,i){let r="number"==typeof e?[e/2,(i||e)/2]:new _.Pt(e).divide(2);return new _.Group(new _.Pt(t).subtract(r),new _.Pt(t).add(r))}static toCircle(t,e=!0){return w.fromRect(t,e)}static toSquare(t,e=!1){let i=d.Util.iterToArray(t),r=y.size(i),s=e?r.maxValue().value:r.minValue().value;return y.fromCenter(y.center(i),s,s)}static size(t){let e=d.Util.iterToArray(t);return e[0].$max(e[1]).subtract(e[0].$min(e[1]))}static center(t){let e=d.Util.iterToArray(t),i=e[0].$min(e[1]),r=e[0].$max(e[1]);return i.add(r.$subtract(i).divide(2))}static corners(t){let e=d.Util.iterToArray(t),i=e[0].$min(e[1]),r=e[0].$max(e[1]);return new _.Group(i,new _.Pt(r.x,i.y),r,new _.Pt(i.x,r.y))}static sides(t){let[e,i,r,s]=y.corners(t);return[new _.Group(e,i),new _.Group(i,r),new _.Group(r,s),new _.Group(s,e)]}static boundingBox(t){let e=d.Util.iterToArray(t),i=d.Util.flatten(e,!1),r=_.Pt.make(2,Number.MAX_VALUE),s=_.Pt.make(2,Number.MIN_VALUE);for(let t,e=0,n=i.length;enew _.Group(t,s).boundingBox())}static halves(t,e=.5,i=!1){let r=d.Util.iterToArray(t),s=r[0].$min(r[1]),n=r[0].$max(r[1]),o=i?p.Num.lerp(s[1],n[1],e):p.Num.lerp(s[0],n[0],e);return i?[new _.Group(s,new _.Pt(n[0],o)),new _.Group(new _.Pt(s[0],o),n)]:[new _.Group(s,new _.Pt(o,n[1])),new _.Group(new _.Pt(o,s[1]),n)]}static withinBound(t,e){let i=d.Util.iterToArray(t);return p.Geom.withinBound(e,i[0],i[1])}static hasIntersectRect2D(t,e,i=!1){let r=d.Util.iterToArray(t),s=d.Util.iterToArray(e);return i&&(r=p.Geom.boundingBox(r),s=p.Geom.boundingBox(s)),!(r[0][0]>s[1][0]||s[0][0]>r[1][0]||r[0][1]>s[1][1]||s[0][1]>r[1][1])}static intersectRect2D(t,e){let i=d.Util.iterToArray(t),r=d.Util.iterToArray(e);return y.hasIntersectRect2D(i,r)?m.intersectLines2D(y.sides(i),y.sides(r)):new _.Group}}a.Rectangle=y;class w{static fromRect(t,e=!1){let i=d.Util.iterToArray(t),r=0,s=r=y.size(i).minValue().value/2;if(e){let t=y.size(i).maxValue().value/2;r=o(s*s+t*t)}else r=s;return new _.Group(y.center(i),new _.Pt(r,r))}static fromTriangle(t,e=!1){return e?b.circumcircle(t):b.incircle(t)}static fromCenter(t,e){return new _.Group(new _.Pt(t),new _.Pt(e,e))}static withinBound(t,e,i=0){let r=d.Util.iterToArray(t),s=r[0].$subtract(e);return s.dot(s)+ih)return new _.Group;{let t=o(h),e=r[0].$subtract(s.$multiply(-l+t));if(0==h)return new _.Group(e);let i=r[0].$subtract(s.$multiply(-l-t));return new _.Group(e,i)}}static intersectLine2D(t,e){let i=d.Util.iterToArray(t),r=d.Util.iterToArray(e),s=w.intersectRay2D(i,r),n=new _.Group;if(0h+u)return new _.Group;if(ls;s++)i.push(r[0].clone().toAngle(e,r[1][0],!0)),e+=2*t/3;return i}return b.fromCenter(r[0],r[1][0])}}a.Circle=w;class b{static fromRect(t){let e=d.Util.iterToArray(t),i=e[0].$add(e[1]).divide(2);i.y=e[0][1];let r=e[1].clone();return r.x=e[0][0],new _.Group(i,e[1].clone(),r)}static fromCircle(t){return w.toTriangle(t,!0)}static fromCenter(t,e){return b.fromCircle(w.fromCenter(t,e))}static medial(t){let e=d.Util.iterToArray(t);return 3>e.length?f(new _.Group,3):x.midpoints(e,!0)}static oppositeSide(t,e){let i=d.Util.iterToArray(t);return 3>i.length?f(new _.Group,3):0===e?_.Group.fromPtArray([i[1],i[2]]):1===e?_.Group.fromPtArray([i[0],i[2]]):_.Group.fromPtArray([i[0],i[1]])}static altitude(t,e){let i=d.Util.iterToArray(t),r=b.oppositeSide(i,e);return 1e.length)return f(void 0,3);let i=b.altitude(e,0),r=b.altitude(e,1);return m.intersectRay2D(i,r)}static incenter(t){let e=d.Util.iterToArray(t);if(3>e.length)return f(void 0,3);let i=x.bisector(e,0).add(e[0]),r=x.bisector(e,1).add(e[1]);return m.intersectRay2D(new _.Group(e[0],i),new _.Group(e[1],r))}static incircle(t,e){let i=d.Util.iterToArray(t),r=e||b.incenter(i),s=2*x.area(i)/x.perimeter(i,!0).total;return w.fromCenter(r,s)}static circumcenter(t){let e=d.Util.iterToArray(t),i=b.medial(e),r=[i[0],p.Geom.perpendicular(e[0].$subtract(i[0])).p1.$add(i[0])],s=[i[1],p.Geom.perpendicular(e[1].$subtract(i[1])).p1.$add(i[1])];return m.intersectRay2D(r,s)}static circumcircle(t,e){let i=d.Util.iterToArray(t),r=e||b.circumcenter(i),s=i[0].$subtract(r).magnitude();return w.fromCenter(r,s)}}a.Triangle=b;class x{static centroid(t){return p.Geom.centroid(t)}static rectangle(t,e,i){return y.corners(y.fromCenter(t,e,i))}static fromCenter(e,i,r){let o=new _.Group;for(let a,l=0;le||e>=i.length)throw new Error("index out of the Polygon's range");return new _.Group(i[e],e===i.length-1?i[0]:i[e+1])}static lines(t,e=!0){let i=d.Util.iterToArray(t);if(2>i.length)return f(new _.Group,2);let r=d.Util.split(i,2,1);return e&&r.push(new _.Group(i[i.length-1],i[0])),r.map(t=>t)}static midpoints(t,e=!1,i=.5){return x.lines(t,e).map(t=>p.Geom.interpolate(t[0],t[1],i))}static adjacentSides(t,e,i=!1){let r=d.Util.iterToArray(t);if(2>r.length)return f(new _.Group,2);if(0>e||e>=r.length)return((t,e="")=>d.Util.warn(`Index ${e} is out of bound in Group`,t))(new _.Group,e);let s=[],n=e-1;i&&0>n&&(n=r.length-1),0<=n&&s.push(new _.Group(r[e],r[n]));let o=e+1;return i&&o>r.length-1&&(o=0),o<=r.length-1&&s.push(new _.Group(r[e],r[o])),s}static bisector(t,e){let i=x.adjacentSides(t,e,!0);if(2<=i.length){let t=i[0][1].$subtract(i[0][0]).unit(),e=i[1][1].$subtract(i[1][0]).unit();return t.add(e).divide(2)}}static perimeter(t,e=!1){let i=x.lines(t,e),r=0,s=_.Pt.make(i.length,0);for(let t,e=0,n=i.length;ei.length)return f(new _.Group,3);let r=(t,e)=>t[0]*e[1]-t[1]*e[0],s=0;for(let t=0,e=i.length;ti.length)return f(new _.Group,3);e||(i=i.slice(),i.sort((t,e)=>t[0]-e[0]));let r=(t,e,i)=>0<(e[0]-t[0])*(i[1]-t[1])-(i[0]-t[0])*(e[1]-t[1]),s=[],n=i.length-2,o=n+3;s[n]=i[2],s[o]=i[2],r(i[0],i[1],i[2])?(s[n+1]=i[0],s[n+2]=i[1]):(s[n+1]=i[1],s[n+2]=i[0]);for(let t,e=3,a=i.length;ee[1]!=t[1][1]>e[1]&&e[0]<(t[1][0]-t[0][0])*(e[1]-t[0][1])/(t[1][1]-t[0][1])+t[0][0]&&(r=!r);return r}static hasIntersectCircle(t,i){let r=d.Util.iterToArray(t),s=d.Util.iterToArray(i),n={which:-1,dist:0,normal:null,edge:null,vertex:null},o=s[0],a=s[1][0],l=u;for(let t=0,s=r.length;to.$subtract(x.centroid(r)).dot(n.normal)&&n.normal.multiply(-1),n.dist=l,n.vertex=o,n):null}static hasIntersectPolygon(t,i){let r=d.Util.iterToArray(t),s=d.Util.iterToArray(i),n={which:-1,dist:0,normal:new _.Pt,edge:new _.Group,vertex:new _.Pt},o=u;for(let t=0,i=r.length+s.length;th.$subtract(c).dot(n.normal)&&n.normal.multiply(-1);let p=u;for(let t,e=0,i=a.length;er.length-1)return new _.Group;let s=t=>tt+i.x*e[r],0),r=t.reduce((t,i,r)=>t+i.y*e[r],0);if(2t+i.z*e[r],0);return new _.Pt(i,r,s)}return new _.Pt(i,r)}static catmullRom(t,e=10){let i=d.Util.iterToArray(t);if(2>i.length)return new _.Group;let r=new _.Group,s=v.getSteps(e),n=v.controlPoints(i,0,!0);for(let t=0;t<=e;t++)r.push(v.catmullRomStep(s[t],n));for(let t,n=0;nr.length)return new _.Group;let s=new _.Group,n=v.getSteps(e),o=v.controlPoints(r,0,!0);for(let t=0;t<=e;t++)s.push(v.cardinalStep(n[t],o,i));for(let t,o=0;oi.length)return new _.Group;let r=new _.Group,s=v.getSteps(e),n=0;for(;nr.length)return new _.Group;let s=new _.Group,n=v.getSteps(e),o=0;for(;oi)throw new Error(`Cannot find index of ${e}. You can use particleIndex() or bodyIndex() function to check existence by name.`);return i}removeBody(t,e=1){const i=this._index(this.bodyIndex.bind(this),t),r=0>i?[-1*i-1,e]:[i,e];return this._bodies.splice(r[0],r[1]),this._bnames.splice(r[0],r[1]),this}removeParticle(t,e=1){const i=this._index(this.particleIndex.bind(this),t),r=0>i?[-1*i-1,e]:[i,e];return this._particles.splice(r[0],r[1]),this._pnames.splice(r[0],r[1]),this}static edgeConstraint(t,e,i,r=1,s=!1){const n=1/(t.mass||1),o=1/(e.mass||1),a=n+o;let l=e.$subtract(t),h=i*i,u=s?i/l.magnitude()-1:h/(l.dot(l)+h)-.5,c=l.$multiply(u*r);return t.subtract(c.$multiply(n/a)),e.add(c.$multiply(o/a)),t}static boundConstraint(t,e,i=.75){let r=a.Geom.boundingBox(e),n=t.$min(r[1].subtract(t.radius)).$max(r[0].add(t.radius));if(n[0]===r[0][0]||n[0]===r[1][0]){let e=t.changed.$multiply(i);t.previous=n.$subtract(new s.Pt(-e[0],e[1]))}else if(n[1]===r[0][1]||n[1]===r[1][1]){let e=t.changed.$multiply(i);t.previous=n.$subtract(new s.Pt(e[0],-e[1]))}t.to(n)}integrate(t,e,i){return t.addForce(this._gravity),t.verlet(e,this._friction,i),t}_updateParticles(t){for(let e,i=0,r=this._particles.length;it||t>=this.length)throw new Error("index1 is not in the Group's indices");if(0>e||e>=this.length)throw new Error("index1 is not in the Group's indices");let r=this[t].$subtract(this[e]).magnitude();return this._cs.push([t,e,r,i||this._stiff]),this}linkAll(t){let e=this.length/2;for(let i,r=0,s=this.length;r=s-1?0:r+1,this.link(r,i,t),4=s-i?r%s:r+i;this.link(r,n,t)}r<=e-1&&this.link(r,h(this.length-1,r+u(e)))}}linksToLines(){let t=[];for(let e,i=0,r=this._cs.length;ie(s[0][1]-s[1][1])?(i.vertex[0]-r[0]-s[0][0])/(s[1][0]-s[0][0]):(i.vertex[1]-r[1]-s[0][1])/(s[1][1]-s[0][1]);let n=1/(t*t+(1-t)*(1-t)),o=i.vertex.body.mass||1,a=i.edge[0].body.mass||1,l=o/(o+a);s[0].subtract(r.$multiply(l*(1-t)*n/2)),s[1].subtract(r.$multiply(l*t*n/2)),i.vertex.add(r.$multiply(a/(o+a)))}}processParticle(t){let i=n.Polygon.hasIntersectCircle(this,n.Circle.fromCenter(t,t.radius));if(i){let r,s=i.normal.$multiply(i.dist),n=i.edge;r=e(n[0][0]-n[1][0])>e(n[0][1]-n[1][1])?(i.vertex[0]-s[0]-n[0][0])/(n[1][0]-n[0][0]):(i.vertex[1]-s[1]-n[0][1])/(n[1][1]-n[0][1]);let o=1/(r*r+(1-r)*(1-r)),a=i.vertex.mass||t.mass||1,l=i.edge[0].body.mass||1,h=a/(a+l);n[0].subtract(s.$multiply(h*(1-r)*o/2)),n[1].subtract(s.$multiply(h*r*o/2));let u=t.changed.add(s.$multiply(l/(a+l)));t.previous=t.$subtract(u)}}}i.Body=d},"./src/Play.ts":function(t,e,i){"use strict";var r=this&&this.__awaiter||function(t,e,i,r){function s(t){return t instanceof i?t:new i((function(e){e(t)}))}return new(i||(i=Promise))((function(i,n){function o(t){try{l(r.next(t))}catch(t){n(t)}}function a(t){try{l(r.throw(t))}catch(t){n(t)}}function l(t){t.done?i(t.value):s(t.value).then(o,a)}l((r=r.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.Sound=e.Tempo=void 0;const s=i("./src/Pt.ts"),n=i("./src/Num.ts");class o{constructor(t){this._listeners={},this._listenerInc=0,this.bpm=t}static fromBeat(t){return new o(6e4/t)}get bpm(){return this._bpm}set bpm(t){this._bpm=t,this._ms=6e4/this._bpm}get ms(){return this._ms}set ms(t){this._bpm=u(6e4/t),this._ms=6e4/this._bpm}_createID(t){let e="";return e="function"==typeof t?"_b"+this._listenerInc++:t.name||"_b"+this._listenerInc++,e}every(t){let e=this,i=Array.isArray(t)?t[0]:t;return{start:function(r,s=0,n){let o=n||e._createID(r);return e._listeners[o]={name:o,beats:t,period:i,index:0,offset:s,duration:-1,continuous:!1,fn:r},this},progress:function(r,s=0,n){let o=n||e._createID(r);return e._listeners[o]={name:o,beats:t,period:i,index:0,offset:s,duration:-1,continuous:!0,fn:r},this}}}track(t){for(let e in this._listeners)if(this._listeners.hasOwnProperty(e)){let i=this._listeners[e],r=i.offset?t+i.offset:t,s=i.period*this._ms,o=!1;r>i.duration+s&&(i.duration=r-r%this._ms,Array.isArray(i.beats)&&(i.index=(i.index+1)%i.beats.length,i.period=i.beats[i.index]),o=!0);let a=c(0,Math.ceil(u(i.duration/this._ms)/i.period)),l=i.continuous?[a,n.Num.clamp((r-i.duration)/s,0,1),r,o]:[a];(i.continuous||o)&&i.fn.apply(i,l)&&delete this._listeners[i.name]}}stop(t){this._listeners[t]&&delete this._listeners[t]}animate(t){this.track(t)}resize(){}action(){}}e.Tempo=o;class a{constructor(t){this._playing=!1,this._type=t;let e=window.AudioContext||window.webkitAudioContext||!1;if(!e)throw new Error("Your browser doesn't support Web Audio. (No AudioContext)");this._ctx=e?new e:void 0}static from(t,e,i="gen",r){let s=new a(i);return s._node=t,s._ctx=e,r&&(s._stream=r),s}static load(t,e="anonymous"){return new Promise((i,r)=>{let s=new a("file");s._source="string"==typeof t?new Audio(t):t,s._source.autoplay=!1,s._source.crossOrigin=e,s._source.addEventListener("ended",(function(){s._playing=!1})),s._source.addEventListener("error",(function(){r("Error loading sound")})),s._source.addEventListener("canplaythrough",(function(){s._node=s._ctx.createMediaElementSource(s._source),i(s)}))})}static loadAsBuffer(t){return new Promise((e,i)=>{let r=new XMLHttpRequest;r.open("GET",t,!0),r.responseType="arraybuffer";let s=new a("file");r.onload=function(){s._ctx.decodeAudioData(r.response,(function(t){s.createBuffer(t),e(s)}),()=>i("Error decoding audio"))},r.send()})}createBuffer(t){return this._node=this._ctx.createBufferSource(),void 0!==t&&(this._buffer=t),this._node.buffer=this._buffer,this._node.onended=()=>{this._playing=!1},this}static generate(t,e){return new a("gen")._gen(t,e)}_gen(t,e){this._node=this._ctx.createOscillator();let i=this._node;return i.type=t,"custom"===t?i.setPeriodicWave(e):i.frequency.value=e,this}static input(t){return r(this,void 0,void 0,(function*(){try{let e=new a("input");if(!e)return;const i=t||{audio:!0,video:!1};return e._stream=yield navigator.mediaDevices.getUserMedia(i),e._node=e._ctx.createMediaStreamSource(e._stream),e}catch(t){return console.error("Cannot get audio from input device."),Promise.resolve(null)}}))}get ctx(){return this._ctx}get node(){return this._node}get outputNode(){return this._outputNode}get stream(){return this._stream}get source(){return this._source}get buffer(){return this._buffer}set buffer(t){this._buffer=t}get type(){return this._type}get playing(){return this._playing}get progress(){let t=0,e=0;return this._buffer?(t=this._buffer.duration,e=this._timestamp?this._ctx.currentTime-this._timestamp:0):(t=this._source.duration,e=this._source.currentTime),e/t}get playable(){return"input"===this._type?void 0!==this._node:!!this._buffer||4===this._source.readyState}get binSize(){return this.analyzer.size}get sampleRate(){return this._ctx.sampleRate}get frequency(){return"gen"===this._type?this._node.frequency.value:0}set frequency(t){"gen"===this._type&&(this._node.frequency.value=t)}connect(t){return this._node.connect(t),this}setOutputNode(t){return this._outputNode=t,this}removeOutputNode(){return this._outputNode=null,this}analyze(t=256,e=-100,i=-30,r=.8){let s=this._ctx.createAnalyser();return s.fftSize=2*t,s.minDecibels=e,s.maxDecibels=i,s.smoothingTimeConstant=r,this.analyzer={node:s,size:s.frequencyBinCount,data:new Uint8Array(s.frequencyBinCount)},this._node.connect(this.analyzer.node),this}_domain(t){return this.analyzer?(t?this.analyzer.node.getByteTimeDomainData(this.analyzer.data):this.analyzer.node.getByteFrequencyData(this.analyzer.data),this.analyzer.data):new Uint8Array(0)}_domainTo(t,e,i=[0,0],r=[0,0]){let n=t?this.timeDomain():this.freqDomain(),o=new s.Group;for(let t=r[0],a=n.length-r[1];tthis.progress&&this._node.stop():this._source.pause():"gen"===this._type?this._node.stop():"input"===this._type&&this._stream.getAudioTracks().forEach(t=>t.stop()),this._playing=!1,this}toggle(){return this._playing?this.stop():this.start(),this}}e.Sound=a},"./src/Pt.ts":function(t,i,r){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Bound=i.Group=i.Pt=void 0;const o=r("./src/Util.ts"),l=r("./src/Num.ts"),d=r("./src/LinearAlgebra.ts");class p extends Float32Array{constructor(...t){1===t.length&&"number"==typeof t[0]?super(t[0]):super(0i)return!1;return!0}to(...t){let e=o.Util.getArgs(t);for(let t=0,i=h(this.length,e.length);tt(e,...i)}ops(t){let e=[];for(let i=0,r=t.length;it?[-1*t-1,e]:[t,e];return _.prototype.splice.apply(this,i)}segments(t=2,e=1,i=!1){return this.split(t,e,i)}lines(){return this.segments(2,1)}centroid(){return l.Geom.centroid(this)}boundingBox(){return l.Geom.boundingBox(this)}anchorTo(t=0){l.Geom.anchor(this,t,"to")}anchorFrom(t=0){l.Geom.anchor(this,t,"from")}op(t){let e=this;return(...i)=>t(e,...i)}ops(t){let e=[];for(let i=0,r=t.length;ie?r[t]-i[t]:i[t]-r[t])}forEachPt(t,...e){if(!this[0][t])return o.Util.warn(t+" is not a function of Pt"),this;for(let i=0,r=this.length;it+e.toString()+" ","")+" ]"}}i.Group=_;class g extends _{constructor(...t){super(...t),this._center=new p,this._size=new p,this._topLeft=new p,this._bottomRight=new p,this._inited=!1,this.init()}static fromBoundingRect(t){let e=new g(new p(t.left||0,t.top||0),new p(t.right||0,t.bottom||0));return t.width&&t.height&&(e.size=new p(t.width,t.height)),e}static fromGroup(t){let e=o.Util.iterToArray(t);if(2>e.length)throw new Error("Cannot create a Bound from a group that has less than 2 Pt");return new g(e[0],e[e.length-1])}init(){if(this.p1&&(this._size=this.p1.clone(),this._inited=!0),this.p1&&this.p2){let t=this.p1,e=this.p2;this.topLeft=t.$min(e),this._bottomRight=t.$max(e),this._updateSize(),this._inited=!0}}clone(){return new g(this._topLeft.clone(),this._bottomRight.clone())}_updateSize(){this._size=this._bottomRight.$subtract(this._topLeft).abs(),this._updateCenter()}_updateCenter(){this._center=this._size.$multiply(.5).add(this._topLeft)}_updatePosFromTop(){this._bottomRight=this._topLeft.$add(this._size),this._updateCenter()}_updatePosFromBottom(){this._topLeft=this._bottomRight.$subtract(this._size),this._updateCenter()}_updatePosFromCenter(){let t=this._size.$multiply(.5);this._topLeft=this._center.$subtract(t),this._bottomRight=this._center.$add(t)}get size(){return new p(this._size)}set size(t){this._size=new p(t),this._updatePosFromTop()}get center(){return new p(this._center)}set center(t){this._center=new p(t),this._updatePosFromCenter()}get topLeft(){return new p(this._topLeft)}set topLeft(t){this._topLeft=new p(t),this[0]=this._topLeft,this._updateSize()}get bottomRight(){return new p(this._bottomRight)}set bottomRight(t){this._bottomRight=new p(t),this[1]=this._bottomRight,this._updateSize()}get width(){return 0this._time.end&&(cancelAnimationFrame(this._animID),this._animID=-1,this._playing=!1)}pause(t=!1){return this._pause=!t||!this._pause,this}resume(){return this._pause=!1,this}stop(t=0){return this._time.end=t,this}playOnce(t=5e3){return this.play(),this.stop(t),this}render(t){return this._renderFunc&&this._renderFunc(t,this),this}set customRendering(t){this._renderFunc=t}get customRendering(){return this._renderFunc}get isPlaying(){return this._playing}get outerBound(){return this.bound.clone()}get innerBound(){return new r.Bound(r.Pt.make(this.size.length,0),this.size.clone())}get size(){return this.bound.size.clone()}get center(){return this.size.divide(2)}get width(){return this.bound.width}get height(){return this.bound.height}}e.Space=n,e.MultiTouchSpace=class extends n{constructor(){super(...arguments),this._pressed=!1,this._dragged=!1,this._hasMouse=!1,this._hasTouch=!1}get pointer(){let t=this._pointer.clone();return t.id=this._pointer.id,t}bindCanvas(t,e,i={}){this._canvas.addEventListener(t,e,i)}unbindCanvas(t,e){this._canvas.removeEventListener(t,e)}bindMouse(t=!0){return t?(this.bindCanvas("mousedown",this._mouseDown.bind(this)),this.bindCanvas("mouseup",this._mouseUp.bind(this)),this.bindCanvas("mouseover",this._mouseOver.bind(this)),this.bindCanvas("mouseout",this._mouseOut.bind(this)),this.bindCanvas("mousemove",this._mouseMove.bind(this)),this.bindCanvas("click",this._mouseClick.bind(this)),this.bindCanvas("contextmenu",this._contextMenu.bind(this)),this._hasMouse=!0):(this.unbindCanvas("mousedown",this._mouseDown.bind(this)),this.unbindCanvas("mouseup",this._mouseUp.bind(this)),this.unbindCanvas("mouseover",this._mouseOver.bind(this)),this.unbindCanvas("mouseout",this._mouseOut.bind(this)),this.unbindCanvas("mousemove",this._mouseMove.bind(this)),this.unbindCanvas("click",this._mouseClick.bind(this)),this.unbindCanvas("contextmenu",this._contextMenu.bind(this)),this._hasMouse=!1),this}bindTouch(t=!0){return t?(this.bindCanvas("touchstart",this._touchStart.bind(this),{passive:!0}),this.bindCanvas("touchend",this._mouseUp.bind(this)),this.bindCanvas("touchmove",this._touchMove.bind(this),{passive:!0}),this.bindCanvas("touchcancel",this._mouseOut.bind(this)),this._hasTouch=!0):(this.unbindCanvas("touchstart",this._touchStart.bind(this)),this.unbindCanvas("touchend",this._mouseUp.bind(this)),this.unbindCanvas("touchmove",this._touchMove.bind(this)),this.unbindCanvas("touchcancel",this._mouseOut.bind(this)),this._hasTouch=!1),this}touchesToPoints(t,e="touches"){if(!t||!t[e])return[];let i=[];for(var s=0;s{t.parentNode.removeChild(t)}),super.remove(t)}removeAll(){return this._container.innerHTML="",super.removeAll()}}e.SVGSpace=h;class u extends r.VisualForm{constructor(t){super(),this._style={filled:!0,stroked:!0,fill:"#f03",stroke:"#fff","stroke-width":1,"stroke-linejoin":"bevel","stroke-linecap":"sqaure",opacity:1},this._ctx={group:null,groupID:"pts",groupCount:0,currentID:"pts0",currentClass:"",style:{}},this._ready=!1,this._space=t,this._space.add({start:()=>{this._ctx.group=this._space.element,this._ctx.groupID="pts_svg_"+u.groupID++,this._ctx.style=Object.assign({},this._style),this._ready=!0}})}get space(){return this._space}styleTo(t,e){if(void 0===this._ctx.style[t])throw new Error(t+" style property doesn't exist");this._ctx.style[t]=e}alpha(t){return this.styleTo("opacity",t),this}fill(t){return"boolean"==typeof t?this.styleTo("filled",t):(this.styleTo("filled",!0),this.styleTo("fill",t)),this}stroke(t,e,i,r){return"boolean"==typeof t?this.styleTo("stroked",t):(this.styleTo("stroked",!0),this.styleTo("stroke",t),e&&this.styleTo("stroke-width",e),i&&this.styleTo("stroke-linejoin",i),r&&this.styleTo("stroke-linecap",r)),this}cls(t){return this._ctx.currentClass="boolean"==typeof t?"":t,this}font(t,e,i,r,s){return"number"==typeof t?(this._font.size=t,s&&(this._font.face=s),e&&(this._font.weight=e),i&&(this._font.style=i),r&&(this._font.lineHeight=r)):this._font=t,this._ctx.style.font=this._font.value,this}reset(){return this._ctx.style=Object.assign({},this._style),this._font=new r.Font(10,"sans-serif"),this._ctx.style.font=this._font.value,this}updateScope(t,e){return this._ctx.group=e,this._ctx.groupID=t,this._ctx.groupCount=0,this.nextID(),this._ctx}scope(t){if(!t||null==t.animateID)throw new Error("item not defined or not yet added to Space");return this.updateScope(u.scopeID(t),this.space.element)}nextID(){return this._ctx.groupCount++,this._ctx.currentID=`${this._ctx.groupID}-${this._ctx.groupCount}`,this._ctx.currentID}static getID(t){return t.currentID||"p-"+u.domID++}static scopeID(t){return"item-"+t.animateID}static style(t,e){let i=[];for(let t in e.filled||i.push("fill: none"),e.stroked||i.push("stroke: none"),e)if(e.hasOwnProperty(t)&&"filled"!=t&&"stroked"!=t){let r=e[t];if(r){if(!e.filled&&0===t.indexOf("fill"))continue;if(!e.stroked&&0===t.indexOf("stroke"))continue;i.push(`${t}: ${r}`)}}return l.DOMSpace.setAttr(t,{style:i.join(";")})}static point(t,e,i=5,r="square"){return"circle"===r?u.circle(t,e,i):u.square(t,e,i)}point(t,e=5,i="square"){return this.nextID(),u.point(this._ctx,t,e,i),this}static circle(t,e,i=10){let r=h.svgElement(t.group,"circle",u.getID(t));return l.DOMSpace.setAttr(r,{cx:e[0],cy:e[1],r:i,class:"pts-svgform pts-circle "+t.currentClass}),u.style(r,t.style),r}circle(t){this.nextID();let e=n.Util.iterToArray(t);return u.circle(this._ctx,e[0],e[1][0]),this}static arc(t,e,i,r,a,c){let d=h.svgElement(t.group,"path",u.getID(t));const p=new o.Pt(e).toAngle(r,i,!0),_=new o.Pt(e).toAngle(a,i,!0);let g=!!(s.Geom.boundAngle(a)-s.Geom.boundAngle(r)>n.Const.pi);c&&(g=!g);const f=c?"0":"1",m=`M ${p[0]} ${p[1]} A ${i} ${i} 0 ${g?"1":"0"} ${f} ${_[0]} ${_[1]}`;return l.DOMSpace.setAttr(d,{d:m,class:"pts-svgform pts-arc "+t.currentClass}),u.style(d,t.style),d}arc(t,e,i,r,s){return this.nextID(),u.arc(this._ctx,t,e,i,r,s),this}static square(t,e,i){let r=h.svgElement(t.group,"rect",u.getID(t));return l.DOMSpace.setAttr(r,{x:e[0]-i,y:e[1]-i,width:2*i,height:2*i,class:"pts-svgform pts-square "+t.currentClass}),u.style(r,t.style),r}square(t,e){return this.nextID(),u.square(this._ctx,t,e),this}static line(t,e){let i=u.pointsString(e);if(!(2>i.count)){if(2t.length*n}static truncate(t,e,i,r=""){let s=u(e.length*h(1,i/t(e)));return se?h(s,i):0t.length}return!1}}e.UI=n,n._counter=0;class o extends n{constructor(t,i,r={},s){super(t,i,r,s),this._hoverID=-1,void 0===r.hover&&(this._states.hover=!1),void 0===r.clicks&&(this._states.clicks=0);const o=e.UIPointerActions;this.on(o.up,()=>{this.state("clicks",this._states.clicks+1)}),this.on(o.move,(t,e,i,r)=>{if(this._within(e)&&!this._states.hover){this.state("hover",!0),n._trigger(this._actions[o.enter],this,e,o.enter,r);var s=this.hold(o.move);this._hoverID=this.on(o.move,(t,i)=>{this._within(i)||this.state("dragging")||(this.state("hover",!1),n._trigger(this._actions[o.leave],this,e,o.leave,r),this.off(o.move,this._hoverID),this.unhold(s))})}})}onClick(t){return this.on(e.UIPointerActions.up,t)}offClick(t){return this.off(e.UIPointerActions.up,t)}onContextMenu(t){return this.on(e.UIPointerActions.contextmenu,t)}offContextMenu(t){return this.off(e.UIPointerActions.contextmenu,t)}onHover(t,i){var r=[void 0,void 0];return t&&(r[0]=this.on(e.UIPointerActions.enter,t)),i&&(r[1]=this.on(e.UIPointerActions.leave,i)),r}offHover(t,i){var r=[!1,!1];return(void 0===t||0<=t)&&(r[0]=this.off(e.UIPointerActions.enter,t)),(void 0===i||0<=i)&&(r[1]=this.off(e.UIPointerActions.leave,i)),r}}e.UIButton=o,e.UIDragger=class extends o{constructor(t,i,s={},o){super(t,i,s,o),this._draggingID=-1,this._moveHoldID=-1,this._dropHoldID=-1,this._upHoldID=-1,void 0===s.dragging&&(this._states.dragging=!1),void 0===s.moved&&(this._states.moved=!1),void 0===s.offset&&(this._states.offset=new r.Pt);const a=e.UIPointerActions;this.on(a.down,(t,e,i,s)=>{-1===this._moveHoldID&&(this.state("dragging",!0),this.state("offset",new r.Pt(e).subtract(t.group[0])),this._moveHoldID=this.hold(a.move)),-1===this._dropHoldID&&(this._dropHoldID=this.hold(a.drop)),-1===this._upHoldID&&(this._upHoldID=this.hold(a.up)),-1===this._draggingID&&(this._draggingID=this.on(a.move,(t,e)=>{this.state("dragging")&&(n._trigger(this._actions[a.uidrag],t,e,a.uidrag,s),this.state("moved",!0))}))});const l=(t,e,i,r)=>{this.state("dragging",!1),this.off(a.move,this._draggingID),this._draggingID=-1,this.unhold(this._moveHoldID),this._moveHoldID=-1,this.unhold(this._dropHoldID),this._dropHoldID=-1,this.unhold(this._upHoldID),this._upHoldID=-1,this.state("moved")&&(n._trigger(this._actions[a.uidrop],t,e,a.uidrop,r),this.state("moved",!1))};this.on(a.drop,l),this.on(a.up,l),this.on(a.out,l)}onDrag(t){return this.on(e.UIPointerActions.uidrag,t)}offDrag(t){return this.off(e.UIPointerActions.uidrag,t)}onDrop(t){return this.on(e.UIPointerActions.uidrop,t)}offDrop(t){return this.off(e.UIPointerActions.uidrop,t)}}},"./src/Util.ts":function(e,s,n){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.Util=s.Const=void 0;const o=n("./src/Pt.ts");s.Const={xy:"xy",yz:"yz",xz:"xz",xyz:"xyz",horizontal:0,vertical:1,identical:0,right:4,bottom_right:5,bottom:6,bottom_left:7,left:8,top_left:1,top:2,top_right:3,epsilon:1e-4,max:i,min:r,pi:t,two_pi:6.283185307179586,half_pi:1.5707963267948966,quarter_pi:.7853981633974483,one_degree:.017453292519943295,rad_to_deg:57.29577951308232,deg_to_rad:.017453292519943295,gravity:9.81,newton:.10197,gaussian:.3989422804014327};class a{static warnLevel(t){return t&&(a._warnLevel=t),a._warnLevel}static getArgs(t){if(1>t.length)return[];let e=[],i=Array.isArray(t[0])||ArrayBuffer.isView(t[0]);if("number"==typeof t[0])e=Array.prototype.slice.call(t);else if("object"!=typeof t[0]||i)i&&(e=[].slice.call(t[0]));else{let i=["x","y","z","w"],r=t[0];for(let t=0;t=r.length)&&i[t]in r;t++)e.push(r[i[t]])}return e}static warn(t="error",e){if("error"==a.warnLevel())throw new Error(t);return"warn"==a.warnLevel()&&console.warn(t),e}static randomInt(t,e=0){return a.warn("Util.randomInt is deprecated. Please use `Num.randomRange`"),u(Math.random()*t)+e}static split(t,e,i,r=!1,s=!0){let n=[],o=[],a=i||e,l=0;if(0>=t.length||0>=a)return[];for(;l=t.length)break;o.push(t[l+i])}l+=a,(!s||s&&o.length===e)&&n.push(o)}return n}static flatten(t,e=!0){let i=e?new o.Group:[];return i.concat.apply(i,t)}static combine(t,e,i){let r=[];for(let s=0,n=t.length;s=t&&(s=e+(s-t)),r&&r(s),s}}static forRange(t,e,i=0,r=1){let s=[];for(let n=i;ni.status?e(i.responseText,!0):e(`Server error (${i.status}) when loading "${t}"`,!1)},i.onerror=function(){e("Unknown network error",!1)},i.send()}static performance(t=10){let e=Date.now(),i=[];return function(){const r=Date.now();return i.push(r-e),i.length>=t&&i.shift(),e=r,u(i.reduce((t,e)=>t+e,0)/i.length)}}static arrayCheck(t,e=2){return!(Array.isArray(t)&&t.length{let i=t.exports;for(let t in i)"namespace"!=t&&(e[t]=i[t])},e.quickStart=(t,i="#9ab")=>{if(!window)return;let r=window;return e.namespace(r),r.space=new n.CanvasSpace(t).setup({bgcolor:i,resize:!0,retina:!0}),r.form=r.space.getForm(),function(t=null,e=null,i=null,s=null){r.space.add({start:e,animate:t,resize:s,action:i}),r.space.bindMouse().bindTouch().play()}}}})}()}])})); //# sourceMappingURL=pts.min.js.map