/*! * 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{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;tthis._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{if(!t)return e;if(s&&r*u>h[1]-2*u)return e;if(1e4=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=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){3r;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=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=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+(st;t++)i[t]=.04045t;t++)o[t]=.0031308t>.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=.008856t&&(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;tthis[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;tr*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{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{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;rd(t,e.length),0):t[0].length;for(let r=0;ri?n-=s:n=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{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:0s[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;er;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;sc.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;te(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;enew _.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)+rh)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(0h+u)return new _.Group;if(ls;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 1e.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;le||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;er.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;tr.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;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]&&(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;to.$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;th.$subtract(d).dot(n.normal)&&n.normal.multiply(-1);let p=u;for(let t,e=0,r=a.length;ei.length-1)return new _.Group;let s=t=>tt+r.x*e[i],0),i=t.reduce((t,r,i)=>t+r.y*e[i],0);if(2t+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;ni.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;or.length)return new _.Group;let i=new _.Group,s=v.getSteps(e),n=0;for(;ni.length)return new _.Group;let s=new _.Group,n=v.getSteps(e),o=0;for(;or)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;rt||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-1?0:i+1,this.link(i,r,t),4=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;re(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];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,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(0r)return!1;return!0}to(...t){let e=o.Util.getArgs(t);for(let t=0,r=h(this.length,e.length);tt(e,...r)}ops(t){let e=[];for(let r=0,i=t.length;rt?[-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;re?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;rt+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 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=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.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(2t.length*n}static truncate(t,e,r,i=""){let s=u(e.length*h(1,r/t(e)));return se?h(s,r):0t.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=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)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=t&&(s=e+(s-t)),i&&i(s),s}}static forRange(t,e,r=0,i=1){let s=[];for(let n=r;nr.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{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>>0,t=(i*=t)>>>0,t+=4294967296*(i-=t)}return 2.3283064365386963e-10*(t>>>0)}t=4022871197}}();for(e=0;eo[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