diff --git a/dist/es2015/UI.js b/dist/es2015/UI.js index 0a86f648..358c989f 100644 --- a/dist/es2015/UI.js +++ b/dist/es2015/UI.js @@ -41,7 +41,7 @@ export class UI { this._states[key] = value; return this; } - return this._states[key] || null; + return this._states[key]; } on(key, fn) { if (!this._actions[key]) @@ -144,10 +144,10 @@ export class UIButton extends UI { constructor(group, shape, states = {}, id) { super(group, shape, states, id); this._hoverID = -1; - if (!states.hover) - states.hover = false; - if (!states.clicks) - states.hover = 0; + if (states.hover === undefined) + this._states['hover'] = false; + if (states.clicks === undefined) + this._states['clicks'] = 0; const UA = UIPointerActions; this.on(UA.up, (target, pt, type) => { this.state('clicks', this._states.clicks + 1); @@ -197,10 +197,10 @@ export class UIDragger extends UIButton { super(group, shape, states, id); this._draggingID = -1; this._moveHoldID = -1; - if (!states.dragging) - states.dragging = false; - if (!states.offset) - states.offset = new Pt(group[0]); + if (states.dragging === undefined) + this._states['dragging'] = false; + if (states.offset === undefined) + this._states['offset'] = new Pt(); const UA = UIPointerActions; this.on(UA.down, (target, pt, type) => { this.state('dragging', true); diff --git a/dist/es5.js b/dist/es5.js index 07c3968b..c96cd479 100644 --- a/dist/es5.js +++ b/dist/es5.js @@ -1,5 +1,5 @@ /*! - * pts.js 0.6.5 - Copyright © 2017-2018 William Ngan and contributors. + * pts.js 0.6.6 - Copyright © 2017-2018 William Ngan and contributors. * Licensed under Apache 2.0 License. * See https://github.com/williamngan/pts for details. */ @@ -7373,7 +7373,7 @@ var UI = function () { this._states[key] = value; return this; } - return this._states[key] || null; + return this._states[key]; } }, { key: "on", @@ -7547,8 +7547,8 @@ var UIButton = function (_UI) { var _this = _possibleConstructorReturn(this, (UIButton.__proto__ || Object.getPrototypeOf(UIButton)).call(this, group, shape, states, id)); _this._hoverID = -1; - if (!states.hover) states.hover = false; - if (!states.clicks) states.hover = 0; + if (states.hover === undefined) _this._states['hover'] = false; + if (states.clicks === undefined) _this._states['clicks'] = 0; var UA = exports.UIPointerActions; _this.on(UA.up, function (target, pt, type) { _this.state('clicks', _this._states.clicks + 1); @@ -7618,8 +7618,8 @@ var UIDragger = function (_UIButton) { _this2._draggingID = -1; _this2._moveHoldID = -1; - if (!states.dragging) states.dragging = false; - if (!states.offset) states.offset = new Pt_1.Pt(group[0]); + if (states.dragging === undefined) _this2._states['dragging'] = false; + if (states.offset === undefined) _this2._states['offset'] = new Pt_1.Pt(); var UA = exports.UIPointerActions; _this2.on(UA.down, function (target, pt, type) { _this2.state('dragging', true); diff --git a/dist/files/UI.js b/dist/files/UI.js index 7952375a..3e95ff1b 100644 --- a/dist/files/UI.js +++ b/dist/files/UI.js @@ -43,7 +43,7 @@ class UI { this._states[key] = value; return this; } - return this._states[key] || null; + return this._states[key]; } on(key, fn) { if (!this._actions[key]) @@ -147,10 +147,10 @@ class UIButton extends UI { constructor(group, shape, states = {}, id) { super(group, shape, states, id); this._hoverID = -1; - if (!states.hover) - states.hover = false; - if (!states.clicks) - states.hover = 0; + if (states.hover === undefined) + this._states['hover'] = false; + if (states.clicks === undefined) + this._states['clicks'] = 0; const UA = exports.UIPointerActions; this.on(UA.up, (target, pt, type) => { this.state('clicks', this._states.clicks + 1); @@ -201,10 +201,10 @@ class UIDragger extends UIButton { super(group, shape, states, id); this._draggingID = -1; this._moveHoldID = -1; - if (!states.dragging) - states.dragging = false; - if (!states.offset) - states.offset = new Pt_1.Pt(group[0]); + if (states.dragging === undefined) + this._states['dragging'] = false; + if (states.offset === undefined) + this._states['offset'] = new Pt_1.Pt(); const UA = exports.UIPointerActions; this.on(UA.down, (target, pt, type) => { this.state('dragging', true); diff --git a/dist/index.js b/dist/index.js index e08a50d7..3d01f711 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,5 +1,5 @@ /*! - * pts.js 0.6.5 - Copyright © 2017-2018 William Ngan and contributors. + * pts.js 0.6.6 - Copyright © 2017-2018 William Ngan and contributors. * Licensed under Apache 2.0 License. * See https://github.com/williamngan/pts for details. */ @@ -5056,7 +5056,7 @@ class UI { this._states[key] = value; return this; } - return this._states[key] || null; + return this._states[key]; } on(key, fn) { if (!this._actions[key]) @@ -5160,10 +5160,10 @@ class UIButton extends UI { constructor(group, shape, states = {}, id) { super(group, shape, states, id); this._hoverID = -1; - if (!states.hover) - states.hover = false; - if (!states.clicks) - states.hover = 0; + if (states.hover === undefined) + this._states['hover'] = false; + if (states.clicks === undefined) + this._states['clicks'] = 0; const UA = exports.UIPointerActions; this.on(UA.up, (target, pt, type) => { this.state('clicks', this._states.clicks + 1); @@ -5214,10 +5214,10 @@ class UIDragger extends UIButton { super(group, shape, states, id); this._draggingID = -1; this._moveHoldID = -1; - if (!states.dragging) - states.dragging = false; - if (!states.offset) - states.offset = new Pt_1.Pt(group[0]); + if (states.dragging === undefined) + this._states['dragging'] = false; + if (states.offset === undefined) + this._states['offset'] = new Pt_1.Pt(); const UA = exports.UIPointerActions; this.on(UA.down, (target, pt, type) => { this.state('dragging', true); diff --git a/dist/pts.js b/dist/pts.js index ef2832ac..a386a8d7 100644 --- a/dist/pts.js +++ b/dist/pts.js @@ -1,5 +1,5 @@ /*! - * pts.js 0.6.5 - Copyright © 2017-2018 William Ngan and contributors. + * pts.js 0.6.6 - Copyright © 2017-2018 William Ngan and contributors. * Licensed under Apache 2.0 License. * See https://github.com/williamngan/pts for details. */ @@ -5056,7 +5056,7 @@ class UI { this._states[key] = value; return this; } - return this._states[key] || null; + return this._states[key]; } on(key, fn) { if (!this._actions[key]) @@ -5160,10 +5160,10 @@ class UIButton extends UI { constructor(group, shape, states = {}, id) { super(group, shape, states, id); this._hoverID = -1; - if (!states.hover) - states.hover = false; - if (!states.clicks) - states.hover = 0; + if (states.hover === undefined) + this._states['hover'] = false; + if (states.clicks === undefined) + this._states['clicks'] = 0; const UA = exports.UIPointerActions; this.on(UA.up, (target, pt, type) => { this.state('clicks', this._states.clicks + 1); @@ -5214,10 +5214,10 @@ class UIDragger extends UIButton { super(group, shape, states, id); this._draggingID = -1; this._moveHoldID = -1; - if (!states.dragging) - states.dragging = false; - if (!states.offset) - states.offset = new Pt_1.Pt(group[0]); + if (states.dragging === undefined) + this._states['dragging'] = false; + if (states.offset === undefined) + this._states['offset'] = new Pt_1.Pt(); const UA = exports.UIPointerActions; this.on(UA.down, (target, pt, type) => { this.state('dragging', true); diff --git a/dist/pts.min.js b/dist/pts.min.js index b4496ac1..98752e64 100644 --- a/dist/pts.min.js +++ b/dist/pts.min.js @@ -1,7 +1,7 @@ /*! - * pts.js 0.6.5 (minified es6) - Copyright © 2017-2018 William Ngan and contributors. + * pts.js 0.6.6 (minified es6) - Copyright © 2017-2018 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()}(window,function(){return function(t){function e(s){if(r[s])return r[s].exports;var i=r[s]={i:s,l:!1,exports:{}};return t[s].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,s){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:s})},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 s=Object.create(null);if(e.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var i in t)e.d(s,i,function(e){return t[e]}.bind(null,i));return s},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){window,t.exports=function(){var t=Math.PI,e=Math.abs,r=Number.MAX_VALUE,s=Number.MIN_VALUE,i=Math.sin,n=Math.cos,o=Math.sqrt,l=Math.atan2,h=Math.pow,a=Math.min,u=Math.floor,c=Math.max;return function(t){function e(s){if(r[s])return r[s].exports;var i=r[s]={i:s,l:!1,exports:{}};return t[s].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,s){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:s})},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 s=Object.create(null);if(e.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var i in t)e.d(s,i,function(e){return t[e]}.bind(null,i));return s},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});const s=r("./src/Space.ts"),i=r("./src/Form.ts"),n=r("./src/Pt.ts"),o=r("./src/Util.ts"),l=r("./src/Typography.ts"),h=r("./src/Op.ts");e.CanvasSpace=class extends s.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(t.bgcolor&&(this._bgcolor=t.bgcolor),this.autoResize=void 0!=t.resize&&t.resize,!1!==t.retina){let t=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){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=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._ctx.translate(.5,.5),this._offscreen&&(this._offCtx.scale(this._pixelScale,this._pixelScale),this._offCtx.translate(.5,.5))),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){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 a(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);let e=this._ctx.fillStyle;return this._bgcolor&&"transparent"!=this._bgcolor?(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))}};class a extends i.VisualForm{constructor(t){super(),this._style={fillStyle:"#f03",strokeStyle:"#fff",lineWidth:1,lineJoin:"bevel",lineCap:"butt"},this._space=t,this._space.add({start:()=>{this._ctx=this._space.ctx,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}})}get space(){return this._space}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)}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,s){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),s&&(this._ctx.lineCap=s,this._style.lineCap=s)),this}font(t,e,r,s,i){return"number"==typeof t?(this._font.size=t,i&&(this._font.face=i),e&&(this._font.weight=e),r&&(this._font.style=r),s&&(this._font.lineHeight=s),this._ctx.font=this._font.value):this._font=t,this._estimateTextWidth&&this.fontWidthEstimate(!0),this}fontWidthEstimate(t=!0){return this._estimateTextWidth=t?l.Typography.textWidthEstimator(t=>this._ctx.measureText(t).width):void 0,this}getTextWidth(t){return this._estimateTextWidth?this._estimateTextWidth(t):this._ctx.measureText(t+" .").width}_textTruncate(t,e,r=""){return l.Typography.truncate(this.getTextWidth.bind(this),t,e,r)}_textAlign(t,e,r,s){s||(s=h.Rectangle.center(t));var i=t[0][0];"end"==this._ctx.textAlign||"right"==this._ctx.textAlign?i=t[1][0]:("center"==this._ctx.textAlign||"middle"==this._ctx.textAlign)&&(i=s[0]);var o=s[1];return"top"==e||"start"==e?o=t[0][1]:("end"==e||"bottom"==e)&&(o=t[1][1]),r?new n.Pt(i+r[0],o+r[1]):new n.Pt(i,o)}reset(){for(let t in this._style)this._style.hasOwnProperty(t)&&(this._ctx[t]=this._style[t]);return this._font=new i.Font,this._ctx.font=this._font.value,this}_paint(){this._filled&&this._ctx.fill(),this._stroked&&this._ctx.stroke()}point(t,e=5,r="square"){if(t){if(!a[r])throw new Error(`${r} is not a static function of CanvasForm`);return a[r](this._ctx,t,e),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){return a.circle(this._ctx,t[0],t[1][0]),this._paint(),this}static arc(t,e,r,s,i,n){e&&(t.beginPath(),t.arc(e[0],e[1],r,s,i,n))}arc(t,e,r,s,i){return a.arc(this._ctx,t,e,r,s,i),this._paint(),this}static square(t,e,r){if(e){let s=e[0]-r,i=e[1]-r,n=e[0]+r,o=e[1]+r;t.beginPath(),t.moveTo(s,i),t.lineTo(s,o),t.lineTo(n,o),t.lineTo(n,i),t.closePath()}}square(t,e){return a.square(this._ctx,t,e),this._paint(),this}static line(t,e){if(!(2>e.length)){t.beginPath(),t.moveTo(e[0][0],e[0][1]);for(let r=1,s=e.length;re.length)){t.beginPath(),t.moveTo(e[0][0],e[0][1]);for(let r=1,s=e.length;re.length||(t.beginPath(),t.moveTo(e[0][0],e[0][1]),t.lineTo(e[0][0],e[1][1]),t.lineTo(e[1][0],e[1][1]),t.lineTo(e[1][0],e[0][1]),t.closePath())}rect(t){return a.rect(this._ctx,t),this._paint(),this}static image(t,e,r=new n.Pt,s){if("number"==typeof r[0])t.drawImage(e,r[0],r[1]);else{let i=r;s?t.drawImage(e,s[0][0],s[0][1],s[1][0]-s[0][0],s[1][1]-s[0][1],i[0][0],i[0][1],i[1][0]-i[0][0],i[1][1]-i[0][1]):t.drawImage(e,i[0][0],i[0][1],i[1][0]-i[0][0],i[1][1]-i[0][1])}}image(t,e,r){return a.image(this._ctx,t,e,r),this}static text(t,e,r,s){e&&t.fillText(r,e[0],e[1],s)}text(t,e,r){return a.text(this._ctx,t,e,r),this}textBox(t,e,r="middle",s="",i=!0){i&&(this._ctx.textBaseline=r);let n=h.Rectangle.size(t),o=this._textTruncate(e,n[0],s);return this.text(this._textAlign(t,r),o[0]),this}paragraphBox(t,e,r=1.2,s="top",i=!0){let o=h.Rectangle.size(t);this._ctx.textBaseline="top";let l=this._font.size*r,a=(t,e=[],r=0)=>{if(!t)return e;if(i&&r*l>o[1]-2*l)return e;if(1e4=h||s[1]===t.length)&&(h=void 0);let u=s[0].substr(0,h);return e.push(u),0>=s[1]||s[1]===t.length?e:a(t.substr(h||s[1]),e,r+1)},u=a(e),d=u.length*l,p=t;if("middle"==s||"center"==s){let e=(o[1]-d)/2;i&&(e=c(0,e)),p=new n.Group(t[0].$add(0,e),t[1].$subtract(0,e))}else p="bottom"==s?new n.Group(t[0].$add(0,o[1]-d),t[1]):new n.Group(t[0],t[0].$add(o[0],d));let g=h.Rectangle.center(p);for(let t=0,e=u.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 g(r>>16,255&r>>8,255&r,e)}static rgb(...t){return g.from(...t).toMode("rgb")}static hsl(...t){return g.from(...t).toMode("hsl")}static hsb(...t){return g.from(...t).toMode("hsb")}static lab(...t){return g.from(...t).toMode("lab")}static lch(...t){return g.from(...t).toMode("lch")}static luv(...t){return g.from(...t).toMode("luv")}static xyz(...t){return g.from(...t).toMode("xyz")}static maxValues(t){return g.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 g(this);return t.toMode(this._mode),t}toMode(t,e=!1){if(e){let e=this._mode.toUpperCase()+"to"+t.toUpperCase();if(!g[e])throw new Error("Cannot convert color with "+e);this.to(g[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){let e="lch"==this._mode?2:0;this[e]=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){let e="hsl"==this._mode?2:0;this[e]=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}get alpha(){return 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[s,i,n]=e?t:t.$normalize(),o=c(s,i,n),l=a(s,i,n),h=(o+l)/2,u=h,d=h;if(o==l)h=0,u=0;else{let t=o-l;u=.5=n?n*(1+i):n+i-n*i,l=2*n-o,h=t=>(t=0>t?t+1:16*t?l+(o-l)*t*6:1>2*t?o:2>3*t?l+(o-l)*(2/3-t)*6:l),a=r?1:255;return g.rgb(a*h(s+1/3),a*h(s),a*h(s-1/3),t.alpha)}static RGBtoHSB(t,e=!1,r=!1){let[s,i,n]=e?t:t.$normalize(),o=c(s,i,n),l=a(s,i,n),h=o-l,u=0,d=0===o?0:h/o;return o!=l&&(o===s?u=(i-n)/h+(it;t++)s[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,r=0;255>r;r++)e=1&r?d[r]^255&t:d[r]^255&t>>8,this.perm[r]=this.perm[r+256]=e}noise2D(){let t=c(0,u(this._n[0]))%255,e=c(0,u(this._n[1]))%255,r=this._n[0]%255-t,s=this._n[1]%255-e,i=l.Vec.dot(h[(t+this.perm[e])%12],[r,s,0]),n=l.Vec.dot(h[(t+this.perm[e+1])%12],[r,s-1,0]),a=l.Vec.dot(h[(t+1+this.perm[e])%12],[r-1,s,0]),d=l.Vec.dot(h[(t+1+this.perm[e+1])%12],[r-1,s-1,0]),p=t=>t*t*t*(t*(6*t-15)+10),g=p(r);return o.Num.lerp(o.Num.lerp(i,a,g),o.Num.lerp(n,d,g),p(s))}}e.Noise=p;class g extends s.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 s=this.slice(),i=this._superTriangle();s=s.concat(i);let o=[this._circum(e,e+1,e+2,i)],l=[],h=[];for(let t=0,e=r.length;tr*r?(l.push(t),h.push(t.triangle),o.splice(a,1)):u[0]*u[0]+u[1]*u[1]-r*r>n.Const.epsilon||(i.push(t.i,t.j,t.j,t.k,t.k,t.i),o.splice(a,1))}for(g._dedupe(i),a=i.length;1{t.parentNode.removeChild(t)}),super.remove(t)}removeAll(){return this._container.innerHTML="",super.removeAll()}}e.HTMLSpace=h;class a extends i.VisualForm{constructor(t){super(),this._ctx={group:null,groupID:"pts",groupCount:0,currentID:"pts0",currentClass:"",style:{filled:!0,stroked:!0,background:"#f03","border-color":"#fff",color:"#000","border-width":"1px","border-radius":"0","border-style":"solid",position:"absolute",top:0,left:0,width:0,height:0},font:"11px sans-serif",fontSize:11,fontFamily:"sans-serif"},this._ready=!1,this._space=t,this._space.add({start:()=>{this._ctx.group=this._space.element,this._ctx.groupID="pts_dom_"+a.groupID++,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}`}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,s,i){return"number"==typeof t?(this._font.size=t,i&&(this._font.face=i),e&&(this._font.weight=e),r&&(this._font.style=r),s&&(this._font.lineHeight=s),this._ctx.font=this._font.value):this._font=t,this}reset(){return this._ctx.style={filled:!0,stroked:!0,background:"#f03","border-color":"#fff","border-width":"1px"},this._font=new i.Font(14,"sans-serif"),this._ctx.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(a.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-${a.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 s=e[t];if(s){if(!e.filled&&0===t.indexOf("background"))continue;if(!e.stroked&&0===t.indexOf("border-width"))continue;r.push(`${t}: ${s}`)}}return h.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 point(t,e,r=5,s="square"){return"circle"===s?a.circle(t,e,r):a.square(t,e,r)}point(t,e=5,r="square"){return this.nextID(),"circle"==r&&this.styleTo("border-radius","100%"),a.point(this._ctx,t,e,r),this}static circle(t,e,r=10){let s=h.htmlElement(t.group,"div",a.getID(t));return h.setAttr(s,{class:`pts-form pts-circle ${t.currentClass}`}),a.rectStyle(t,new o.Pt(e).$subtract(r),new o.Pt(2*r,2*r)),a.style(s,t.style),s}circle(t){return this.nextID(),this.styleTo("border-radius","100%"),a.circle(this._ctx,t[0],t[1][0]),this}static square(t,e,r){let s=h.htmlElement(t.group,"div",a.getID(t));return h.setAttr(s,{class:`pts-form pts-square ${t.currentClass}`}),a.rectStyle(t,new o.Pt(e).$subtract(r),new o.Pt(2*r,2*r)),a.style(s,t.style),s}square(t,e){return this.nextID(),a.square(this._ctx,t,e),this}static rect(t,e){if(this._checkSize(e)){let r=h.htmlElement(t.group,"div",a.getID(t));return h.setAttr(r,{class:`pts-form pts-rect ${t.currentClass}`}),a.rectStyle(t,e[0],e[1]),a.style(r,t.style),r}}rect(t){return this.nextID(),this.styleTo("border-radius","0"),a.rect(this._ctx,t),this}static text(t,e,r){let s=h.htmlElement(t.group,"div",a.getID(t));return h.setAttr(s,{position:"absolute",class:`pts-form pts-text ${t.currentClass}`,left:e[0],top:e[1]}),s.textContent=r,a.style(s,t.style),s}text(t,e){return this.nextID(),a.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}}a.groupID=0,a.domID=0,e.HTMLForm=a},"./src/Form.ts":function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=r("./src/Util.ts");class i{constructor(){this._ready=!1}get ready(){return this._ready}static _checkSize(t,e=2){return!(t.lengthc(t,e.length),0):t[0].length;for(let r=0;rs?n-=i:n=a(e,r)&&t<=c(e,r)}static randomRange(t,e=0){let r=t>e?t-e:e-t;return t+Math.random()*r}static normalizeValue(t,e,r){let s=a(e,r),i=c(e,r);return(t-s)/(i-s)}static sum(t){let e=new f.Pt(t[0]);for(let r=1,s=t.length;rt.$min(e)),r=t.reduce((t,e)=>t.$max(e));return new f.Group(e,r)}static centroid(t){return m.average(t)}static anchor(t,e=0,r="to"){let s="to"==r?"subtract":"add";for(let r=0,i=t.length;r{if(2>t.length||2>e.length)throw new Error("Pt dimension cannot be less than 2");let s=t.$subtract(r),i=e.$subtract(r);if(0<=s[0]&&0>i[0])return 1;if(0>s[0]&&0<=i[0])return-1;if(0==s[0]&&0==i[0])return 0<=s[1]||0<=i[1]?s[1]>i[1]?1:-1:i[1]>s[1]?1:-1;let n=s.$cross2D(i);return 0>n?1:0i[0]*i[0]+i[1]*i[1]?1:-1})}static scale(t,e,r){let s=Array.isArray(t)?t:[t],i="number"==typeof e?f.Pt.make(s[0].length,e):e;r||(r=f.Pt.make(s[0].length,0));for(let t,e=0,n=s.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]=i(r*t/180);return{table:e,sin:t=>e[u(w.boundAngle(w.toDegree(t)))]}}}s.Geom=w;class y{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*h(t,1/r)}static exponentialOut(t,e=1,r=.25){return e*h(t,r)}static sineIn(t,e=1){return-e*n(t*p.Const.half_pi)+e}static sineOut(t,e=1){return e*i(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,s=r*r;return e*(s*r*4/9-17*s/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 s=t-1,n=r/p.Const.two_pi*1.5707963267948966;return e*(-h(2,10*s)*i((s-n)*p.Const.two_pi/r))}static elasticOut(t,e=1,r=.7){let s=r/p.Const.two_pi*1.5707963267948966;return e*(h(2,-10*t)*i((t-s)*p.Const.two_pi/r))+e}static elasticInOut(t,e=1,r=.6){let s=2*t,n=r/p.Const.two_pi*1.5707963267948966;return.5>t?e*(h(2,10*(s-=1))*i((s-n)*p.Const.two_pi/r)*-.5):e*(h(2,-10*(s-=1))*i((s-n)*p.Const.two_pi/r)*.5)+e}static bounceIn(t,e=1){return e-y.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?y.bounceIn(2*t,e)/2:y.bounceOut(2*t-1,e)/2+e/2}static sigmoid(t,e=1,r=10){return e/(1+d(-r*(t-.5)))}static logSigmoid(t,e=1,r=.7){r=c(p.Const.epsilon,a(1-p.Const.epsilon,r));let s=1/(1+d((t-.5)*(r=1/(1-r))*-2)),i=1/(1+d(r)),n=1/(1+d(-r));return e*(s-i)/(n-i)}static seat(t,e=1,r=.5){return.5>t?e*h(2*t,1-r)/2:e*(1-h(2*(1-t),1-r)/2)}static quadraticBezier(t,e=1,r=[.05,.95]){let s="number"==typeof r?r:r[0],i="number"==typeof r?.5:r[1],n=1-2*s;0===n&&(n=p.Const.epsilon);let l=(o(s*s+n*t)-s)/n;return e*(l*l*(1-2*i)+2*i*l)}static cubicBezier(t,e=1,r=[.1,.7],s=[.9,.2]){let i=new f.Group(new f.Pt(0,0),new f.Pt(r),new f.Pt(s),new f.Pt(1,1));return e*g.Curve.bezierStep(new f.Pt(t*t*t,t*t,t,1),g.Curve.controlPoints(i)).y}static quadraticTarget(t,e=1,r=[.2,.35]){let s=a(1-p.Const.epsilon,c(p.Const.epsilon,r[0])),i=a(1,c(0,r[1])),n=(1-i)/(1-s)-i/s;return e*a(1,c(0,n*(t*t)-(n*(s*s)-i)/s*t))}static cliff(t,e=1,r=.5){return t>r?e:0}static step(t,e,r,s,...i){let n=1/e,o=u(r/n)*n;return t(o,s,...i)}}s.Shaping=y,s.Range=class{constructor(t){this._dims=0,this._source=f.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 f.Pt(t),r=new f.Pt(t),s=new f.Pt(t);for(let i=0;id.Util.warn("Group's length is less than "+e,t),m=(t,e="")=>d.Util.warn(`Index ${e} is out of bound in Group`,t);class w{static fromAngle(t,e,r){let s=new g.Group(new g.Pt(t),new g.Pt(t));return s[1].toAngle(e,r,!0),s}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]),s=t[1]-r*t[0];return{slope:r,yi:s,xi:0==r?void 0:-s/r}}}static sideOfPt2D(t,e){return(t[1][0]-t[0][0])*(e[1]-t[0][1])-(e[0]-t[0][0])*(t[1][1]-t[0][1])}static collinear(t,e,r,s=.01){let i=new g.Pt(0,0,0).to(t).$subtract(e),n=new g.Pt(0,0,0).to(t).$subtract(r);return i.$cross(n).divide(1e3).equals(new g.Pt(0,0,0),s)}static magnitude(t){return 2<=t.length?t[1].$subtract(t[0]).magnitude():0}static magnitudeSq(t){return 2<=t.length?t[1].$subtract(t[0]).magnitudeSq():0}static perpendicularFromPt(t,e,r=!1){if(!t[0].equals(t[1])){let s=t[0].$subtract(t[1]),i=t[1].$subtract(e),n=i.$subtract(s.$project(i));return r?n:n.$add(e)}}static distanceFromPt(t,e){return w.perpendicularFromPt(t,e,!0).magnitude()}static intersectRay2D(t,e){let r=w.intercept(t[0],t[1]),s=w.intercept(e[0],e[1]),i=t[0],n=e[0];if(void 0==r){if(void 0==s)return;let t=-s.slope*(n[0]-i[0])+n[1];return new g.Pt(i[0],t)}if(void 0==s){let t=-r.slope*(i[0]-n[0])+i[1];return new g.Pt(n[0],t)}if(s.slope!=r.slope){let t=(r.slope*i[0]-s.slope*n[0]+n[1]-i[1])/(r.slope-s.slope),e=r.slope*(t-i[0])+i[1];return new g.Pt(t,e)}return r.yi==s.yi?new g.Pt(i[0],i[1]):void 0}static intersectLine2D(t,e){let r=w.intersectRay2D(t,e);return r&&p.Geom.withinBound(r,t[0],t[1])&&p.Geom.withinBound(r,e[0],e[1])?r:void 0}static intersectLineWithRay2D(t,e){let r=w.intersectRay2D(t,e);return r&&p.Geom.withinBound(r,t[0],t[1])?r:void 0}static intersectPolygon2D(t,e,r=!1){let s=r?w.intersectLineWithRay2D:w.intersectLine2D,i=new g.Group;for(let r=0,n=e.length;re(r[1]/r[0])?0>o[1]?0:2:0>o[0]?3:1,w.intersectRay2D(n[l],t)}}static marker(t,e,r="arrow",s=!0){let i=s?0:1,n=s?1:0,o=t[i].$subtract(t[n]);if(0===o.magnitudeSq())return new g.Group;o.unit();let l=p.Geom.perpendicular(o).multiply(e[0]).add(t[n]);return"arrow"==r?(l.add(o.$multiply(e[1])),new g.Group(t[n],l[0],l[1])):new g.Group(l[0],l[1])}static toRect(t){return new g.Group(t[0].$min(t[1]),t[0].$max(t[1]))}}l.Line=w;class y{static from(t,e,r){return y.fromTopLeft(t,e,r)}static fromTopLeft(t,e,r){let s="number"==typeof e?[e,r||e]:e;return new g.Group(new g.Pt(t),new g.Pt(t).add(s))}static fromCenter(t,e,r){let s="number"==typeof e?[e/2,(r||e)/2]:new g.Pt(e).divide(2);return new g.Group(new g.Pt(t).subtract(s),new g.Pt(t).add(s))}static toCircle(t,e=!0){return b.fromRect(t,e)}static toSquare(t,e=!1){let r=y.size(t),s=e?r.maxValue().value:r.minValue().value;return y.fromCenter(y.center(t),s,s)}static size(t){return t[0].$max(t[1]).subtract(t[0].$min(t[1]))}static center(t){let e=t[0].$min(t[1]),r=t[0].$max(t[1]);return e.add(r.$subtract(e).divide(2))}static corners(t){let e=t[0].$min(t[1]),r=t[0].$max(t[1]);return new g.Group(e,new g.Pt(r.x,e.y),r,new g.Pt(e.x,r.y))}static sides(t){let[e,r,s,i]=y.corners(t);return[new g.Group(e,r),new g.Group(r,s),new g.Group(s,i),new g.Group(i,e)]}static boundingBox(t){let e=d.Util.flatten(t,!1),r=g.Pt.make(2,Number.MAX_VALUE),s=g.Pt.make(2,Number.MIN_VALUE);for(let t=0,i=e.length;ti;i++)r[i]=a(r[i],e[t][i]),s[i]=c(s[i],e[t][i]);return new g.Group(r,s)}static polygon(t){return y.corners(t)}static quadrants(t,e){let r=y.corners(t),s=void 0==e?y.center(t):new g.Pt(e);return r.map(t=>new g.Group(t,s).boundingBox())}static halves(t,e=.5,r=!1){let s=t[0].$min(t[1]),i=t[0].$max(t[1]),n=r?p.Num.lerp(s[1],i[1],e):p.Num.lerp(s[0],i[0],e);return r?[new g.Group(s,new g.Pt(i[0],n)),new g.Group(new g.Pt(s[0],n),i)]:[new g.Group(s,new g.Pt(n,i[1])),new g.Group(new g.Pt(n,s[1]),i)]}static withinBound(t,e){return p.Geom.withinBound(e,t[0],t[1])}static hasIntersectRect2D(t,e,r=!1){return r&&(t=p.Geom.boundingBox(t),e=p.Geom.boundingBox(e)),!(t[0][0]>e[1][0]||e[0][0]>t[1][0]||t[0][1]>e[1][1]||e[0][1]>t[1][1])}static intersectRect2D(t,e){return y.hasIntersectRect2D(t,e)?w.intersectLines2D(y.sides(t),y.sides(e)):new g.Group}}l.Rectangle=y;class b{static fromRect(t,e=!1){let r=0,s=r=y.size(t).minValue().value/2;if(e){let e=y.size(t).maxValue().value/2;r=o(s*s+e*e)}else r=s;return new g.Group(y.center(t),new g.Pt(r,r))}static fromTriangle(t,e=!1){return e?x.circumcircle(t):x.incircle(t)}static fromCenter(t,e){return new g.Group(new g.Pt(t),new g.Pt(e,e))}static withinBound(t,e,r=0){let s=t[0].$subtract(e);return s.dot(s)+ra)return new g.Group;{let t=o(a),s=e[0].$subtract(r.$multiply(-h+t));if(0==a)return new g.Group(s);let i=e[0].$subtract(r.$multiply(-h-t));return new g.Group(s,i)}}static intersectLine2D(t,e){let r=b.intersectRay2D(t,e),s=new g.Group;if(0l+h)return new g.Group;if(ni;i++)s.push(e[0].clone().toAngle(r,e[1][0],!0)),r+=2*t/3;return s}return x.fromCenter(e[0],e[1][0])}}l.Circle=b;class x{static fromRect(t){let e=t[0].$add(t[1]).divide(2);e.y=t[0][1];let r=t[1].clone();return r.x=t[0][0],new g.Group(e,t[1].clone(),r)}static fromCircle(t){return b.toTriangle(t,!0)}static fromCenter(t,e){return x.fromCircle(b.fromCenter(t,e))}static medial(t){return 3>t.length?_(new g.Group,3):v.midpoints(t,!0)}static oppositeSide(t,e){return 3>t.length?_(new g.Group,3):0===e?g.Group.fromPtArray([t[1],t[2]]):1===e?g.Group.fromPtArray([t[0],t[2]]):g.Group.fromPtArray([t[0],t[1]])}static altitude(t,e){let r=x.oppositeSide(t,e);return 1t.length)return _(void 0,3);let e=x.altitude(t,0),r=x.altitude(t,1);return w.intersectRay2D(e,r)}static incenter(t){if(3>t.length)return _(void 0,3);let e=v.bisector(t,0).add(t[0]),r=v.bisector(t,1).add(t[1]);return w.intersectRay2D(new g.Group(t[0],e),new g.Group(t[1],r))}static incircle(t,e){let r=e||x.incenter(t),s=v.area(t),i=v.perimeter(t,!0),n=2*s/i.total;return b.fromCenter(r,n)}static circumcenter(t){let e=x.medial(t),r=[e[0],p.Geom.perpendicular(t[0].$subtract(e[0])).p1.$add(e[0])],s=[e[1],p.Geom.perpendicular(t[1].$subtract(e[1])).p1.$add(e[1])];return w.intersectRay2D(r,s)}static circumcircle(t,e){let r=e||x.circumcenter(t),s=t[0].$subtract(r).magnitude();return b.fromCenter(r,s)}}l.Triangle=x;class v{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,s){let o=new g.Group;for(let l,h=0;he||e>=t.length)throw new Error("index out of the Polygon's range");return new g.Group(t[e],e===t.length-1?t[0]:t[e+1])}static lines(t,e=!0){if(2>t.length)return _(new g.Group,2);let r=d.Util.split(t,2,1);return e&&r.push(new g.Group(t[t.length-1],t[0])),r.map(t=>t)}static midpoints(t,e=!1,r=.5){if(2>t.length)return _(new g.Group,2);let s=v.lines(t,e),i=s.map(t=>p.Geom.interpolate(t[0],t[1],r));return i}static adjacentSides(t,e,r=!1){if(2>t.length)return _(new g.Group,2);if(0>e||e>=t.length)return m(new g.Group,e);let s=[],i=e-1;r&&0>i&&(i=t.length-1),0<=i&&s.push(new g.Group(t[e],t[i]));let n=e+1;return r&&n>t.length-1&&(n=0),n<=t.length-1&&s.push(new g.Group(t[e],t[n])),s}static bisector(t,e){let r=v.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){if(2>t.length)return _(new g.Group,2);let r=v.lines(t,e),s=0,i=g.Pt.make(r.length,0);for(let t,e=0,n=r.length;et.length)return _(new g.Group,3);let r=(t,e)=>t[0]*e[1]-t[1]*e[0],s=0;for(let e=0,i=t.length;et.length)return _(new g.Group,3);e||(t=t.slice()).sort((t,e)=>t[0]-e[0]);let r=(t,e,r)=>0<(e[0]-t[0])*(r[1]-t[1])-(r[0]-t[0])*(e[1]-t[1]),s=[],i=t.length-2,n=i+3;s[i]=t[2],s[n]=t[2],r(t[0],t[1],t[2])?(s[i+1]=t[0],s[i+2]=t[1]):(s[i+1]=t[1],s[i+2]=t[0]);for(let e,o=3,l=t.length;oe[1]!=s[1][1]>e[1]&&e[0]<(s[1][0]-s[0][0])*(e[1]-s[0][1])/(s[1][1]-s[0][1])+s[0][0]&&(r=!r);return r}static hasIntersectCircle(t,r){let s={which:-1,dist:0,normal:null,edge:null,vertex:null},i=r[0],n=r[1][0],o=u;for(let l=0,h=t.length;ll&&s.normal.multiply(-1),s.dist=o,s.vertex=i,s}static hasIntersectPolygon(t,r){let s={which:-1,dist:0,normal:new g.Pt,edge:new g.Group,vertex:new g.Pt},i=u;for(let n=0,o=t.length+r.length;na&&s.normal.multiply(-1);let c=u;for(let t,e=0,r=n.length;ep.Geom.boundingBox(t)),r=d.Util.flatten(e,!1);return e.unshift(p.Geom.boundingBox(r)),e}}l.Polygon=v;class P{static getSteps(t){let e=new g.Group;for(let r,s=0;s<=t;s++)r=s/t,e.push(new g.Pt(r*r*r,r*r,r,1));return e}static controlPoints(t,e=0,r=!1){if(e>t.length-1)return new g.Group;let s=e=>et+r.x*e[s],0),s=t.reduce((t,r,s)=>t+r.y*e[s],0);if(2t+r.z*e[s],0);return new g.Pt(r,s,i)}return new g.Pt(r,s)}static catmullRom(t,e=10){if(2>t.length)return new g.Group;let r=new g.Group,s=P.getSteps(e),i=P.controlPoints(t,0,!0);for(let t=0;t<=e;t++)r.push(P.catmullRomStep(s[t],i));for(let i,n=0;nt.length)return new g.Group;let s=new g.Group,i=P.getSteps(e),n=P.controlPoints(t,0,!0);for(let t=0;t<=e;t++)s.push(P.cardinalStep(i[t],n,r));for(let n,o=0;ot.length)return new g.Group;let r=new g.Group,s=P.getSteps(e),i=0;for(;it.length)return new g.Group;let s=new g.Group,i=P.getSteps(e),n=0;for(;n(r=t(e)))throw new Error("Cannot find index of "+e);return r}removeBody(t,e=1){const r=this._index(this.bodyIndex.bind(this),t),s=0>r?[-1*r-1,e]:[r,e];return this._bodies.splice(s[0],s[1]),this._bnames.splice(s[0],s[1]),this}removeParticle(t,e=1){const r=this._index(this.particleIndex.bind(this),t),s=0>r?[-1*r-1,e]:[r,e];return this._particles.splice(s[0],s[1]),this._pnames.splice(s[0],s[1]),this}static edgeConstraint(t,e,r,s=1,i=!1){const n=1/(t.mass||1),o=1/(e.mass||1),l=n+o;let h=e.$subtract(t),a=r*r,u=i?r/h.magnitude()-1:a/(h.dot(h)+a)-.5,c=h.$multiply(u*s);return t.subtract(c.$multiply(n/l)),e.add(c.$multiply(o/l)),t}static boundConstraint(t,e,r=.75){let s=e.boundingBox(),n=t.$min(s[1].subtract(t.radius)).$max(s[0].add(t.radius));if(n[0]===s[0][0]||n[0]===s[1][0]){let e=t.changed.$multiply(r);t.previous=n.$subtract(new i.Pt(-e[0],e[1]))}else if(n[1]===s[0][1]||n[1]===s[1][1]){let e=t.changed.$multiply(r);t.previous=n.$subtract(new i.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,s=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 s=this[t].$subtract(this[e]).magnitude();return this._cs.push([t,e,s,r||this._stiff]),this}linkAll(t){let e=this.length/2;for(let r,s=0,i=this.length;s=i-1?0:s+1,this.link(s,r,t),4=i-r?s%i:s+r;this.link(s,n,t)}s<=e-1&&this.link(s,a(this.length-1,s+u(e)))}}linksToLines(){let t=[];for(let e,r=0,s=this._cs.length;re(i[0][1]-i[1][1])?(r.vertex[0]-s[0]-i[0][0])/(i[1][0]-i[0][0]):(r.vertex[1]-s[1]-i[0][1])/(i[1][1]-i[0][1]))*t+(1-t)*(1-t)),o=r.vertex.body.mass||1,l=r.edge[0].body.mass||1,h=o/(o+l);i[0].subtract(s.$multiply(h*(1-t)*n/2)),i[1].subtract(s.$multiply(h*t*n/2)),r.vertex.add(s.$multiply(l/(o+l)))}}processParticle(t){let r=n.Polygon.hasIntersectCircle(this,n.Circle.fromCenter(t,t.radius));if(r){let s,i=r.normal.$multiply(r.dist),n=r.edge,o=1/((s=e(n[0][0]-n[1][0])>e(n[0][1]-n[1][1])?(r.vertex[0]-i[0]-n[0][0])/(n[1][0]-n[0][0]):(r.vertex[1]-i[1]-n[0][1])/(n[1][1]-n[0][1]))*s+(1-s)*(1-s)),l=r.vertex.mass||t.mass||1,h=r.edge[0].body.mass||1,a=l/(l+h);n[0].subtract(i.$multiply(a*(1-s)*o/2)),n[1].subtract(i.$multiply(a*s*o/2));let u=t.changed.add(i.$multiply(h/(l+h)));t.previous=t.$subtract(u)}}}r.Body=c},"./src/Pt.ts":function(t,r,s){"use strict";Object.defineProperty(r,"__esModule",{value:!0});const o=s("./src/Util.ts"),h=s("./src/Num.ts"),d=s("./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=a(this.length,e.length);tt(e,...r)}ops(t){let e=[];for(let r=0,s=t.length;rt?[-1*t-1,e]:[t,e];return g.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 h.Geom.centroid(this)}boundingBox(){return h.Geom.boundingBox(this)}anchorTo(t=0){h.Geom.anchor(this,t,"to")}anchorFrom(t=0){h.Geom.anchor(this,t,"from")}op(t){let e=this;return(...r)=>t(e,...r)}ops(t){let e=[];for(let r=0,s=t.length;re?s[t]-r[t]:r[t]-s[t])}forEachPt(t,...e){if(!this[0][t])return o.Util.warn(`${t} is not a function of Pt`),this;for(let r=0,s=this.length;rt+e.toString()+" ","")+" ]"}}r.Group=g;class f extends g{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 f(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){if(2>t.length)throw new Error("Cannot create a Bound from a group that has less than 2 Pt");return new f(t[0],t[t.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 f(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._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 s.Bound(s.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){this._canvas.addEventListener(t,e)}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._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._hasMouse=!1),this}bindTouch(t=!0){return t?(this.bindCanvas("touchstart",this._mouseDown.bind(this)),this.bindCanvas("touchend",this._mouseUp.bind(this)),this.bindCanvas("touchmove",this._touchMove.bind(this)),this.bindCanvas("touchcancel",this._mouseOut.bind(this)),this._hasTouch=!0):(this.unbindCanvas("touchstart",this._mouseDown.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 r=[];for(var i=0;i{t.parentNode.removeChild(t)}),super.remove(t)}removeAll(){return this._container.innerHTML="",super.removeAll()}}e.SVGSpace=a;class u extends s.VisualForm{constructor(t){super(),this._ctx={group:null,groupID:"pts",groupCount:0,currentID:"pts0",currentClass:"",style:{filled:!0,stroked:!0,fill:"#f03",stroke:"#fff","stroke-width":1,"stroke-linejoin":"bevel","stroke-linecap":"sqaure"},font:"11px sans-serif",fontSize:11,fontFamily:"sans-serif"},this._ready=!1,this._space=t,this._space.add({start:()=>{this._ctx.group=this._space.element,this._ctx.groupID="pts_svg_"+u.groupID++,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}fill(t){return"boolean"==typeof t?this.styleTo("filled",t):(this.styleTo("filled",!0),this.styleTo("fill",t)),this}stroke(t,e,r,s){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),s&&this.styleTo("stroke-linecap",s)),this}cls(t){return this._ctx.currentClass="boolean"==typeof t?"":t,this}font(t,e,r,s,i){return"number"==typeof t?(this._font.size=t,i&&(this._font.face=i),e&&(this._font.weight=e),r&&(this._font.style=r),s&&(this._font.lineHeight=s),this._ctx.font=this._font.value):this._font=t,this}reset(){return this._ctx.style={filled:!0,stroked:!0,fill:"#f03",stroke:"#fff","stroke-width":1,"stroke-linejoin":"bevel","stroke-linecap":"sqaure"},this._font=new s.Font(14,"sans-serif"),this._ctx.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 s=e[t];if(s){if(!e.filled&&0===t.indexOf("fill"))continue;if(!e.stroked&&0===t.indexOf("stroke"))continue;r.push(`${t}: ${s}`)}}return h.DOMSpace.setAttr(t,{style:r.join(";")})}static point(t,e,r=5,s="square"){return"circle"===s?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 s=a.svgElement(t.group,"circle",u.getID(t));return h.DOMSpace.setAttr(s,{cx:e[0],cy:e[1],r:r,class:`pts-svgform pts-circle ${t.currentClass}`}),u.style(s,t.style),s}circle(t){return this.nextID(),u.circle(this._ctx,t[0],t[1][0]),this}static arc(t,e,r,s,l,c){let d=a.svgElement(t.group,"path",u.getID(t));const p=new o.Pt(e).toAngle(s,r,!0),g=new o.Pt(e).toAngle(l,r,!0),f=i.Geom.boundAngle(l)-i.Geom.boundAngle(s);let _=!!(f>n.Const.pi);c&&(_=!_);const m=c?"0":"1",w=`M ${p[0]} ${p[1]} A ${r} ${r} 0 ${_?"1":"0"} ${m} ${g[0]} ${g[1]}`;return h.DOMSpace.setAttr(d,{d:w,class:`pts-svgform pts-arc ${t.currentClass}`}),u.style(d,t.style),d}arc(t,e,r,s,i){return this.nextID(),u.arc(this._ctx,t,e,r,s,i),this}static square(t,e,r){let s=a.svgElement(t.group,"rect",u.getID(t));return h.DOMSpace.setAttr(s,{x:e[0]-r,y:e[1]-r,width:2*r,height:2*r,class:`pts-svgform pts-square ${t.currentClass}`}),u.style(s,t.style),s}square(t,e){return this.nextID(),u.square(this._ctx,t,e),this}static line(t,e){if(this._checkSize(e)){if(2t+`${e[0]},${e[1]} `,"");return h.DOMSpace.setAttr(s,{points:i,class:`pts-svgform pts-polygon ${t.currentClass}`}),u.style(s,t.style),s}}static polygon(t,e){return u._poly(t,e,!0)}polygon(t){return this.nextID(),u.polygon(this._ctx,t),this}static rect(t,e){if(this._checkSize(e)){let r=a.svgElement(t.group,"rect",u.getID(t)),s=o.Group.fromArray(e).boundingBox(),i=l.Rectangle.size(s);return h.DOMSpace.setAttr(r,{x:s[0][0],y:s[0][1],width:i[0],height:i[1],class:`pts-svgform pts-rect ${t.currentClass}`}),u.style(r,t.style),r}}rect(t){return this.nextID(),u.rect(this._ctx,t),this}static text(t,e,r){let s=a.svgElement(t.group,"text",u.getID(t));return h.DOMSpace.setAttr(s,{"pointer-events":"none",x:e[0],y:e[1],dx:0,dy:0,class:`pts-svgform pts-text ${t.currentClass}`}),s.textContent=r,u.style(s,t.style),s}text(t,e){return this.nextID(),u.text(this._ctx,t,e),this}log(t){return this.fill("#000").stroke("#fff",.5).text([10,14],t),this}}u.groupID=0,u.domID=0,e.SVGForm=u},"./src/Typography.ts":function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=r("./src/Pt.ts");e.Typography=class{static textWidthEstimator(t,e=["M","n","."],r=[.06,.8,.14]){let i=e.map(t),n=new s.Pt(r).dot(i);return t=>t.length*n}static truncate(t,e,r,s=""){let i=u(e.length*a(1,r/t(e)));return ie?a(i,r):0t.length}return!1}}n._counter=0,e.UI=n;class o extends n{constructor(t,r,s={},i){super(t,r,s,i),this._hoverID=-1,s.hover||(s.hover=!1),s.clicks||(s.hover=0);const o=e.UIPointerActions;this.on(o.up,()=>{this.state("clicks",this._states.clicks+1)}),this.on(o.move,(t,e)=>{let r=this._within(e);if(r&&!this._states.hover){this.state("hover",!0),n._trigger(this._actions[o.enter],this,e,o.enter);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),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)}onHover(t,r){var s=[void 0,void 0];return t&&(s[0]=this.on(e.UIPointerActions.enter,t)),r&&(s[1]=this.on(e.UIPointerActions.leave,r)),s}offHover(t,r){var s=[!1,!1];return(void 0===t||0<=t)&&(s[0]=this.off(e.UIPointerActions.enter,t)),(void 0===r||0<=r)&&(s[1]=this.off(e.UIPointerActions.leave,r)),s}}e.UIButton=o,e.UIDragger=class extends o{constructor(t,r,i={},o){super(t,r,i,o),this._draggingID=-1,this._moveHoldID=-1,i.dragging||(i.dragging=!1),i.offset||(i.offset=new s.Pt(t[0]));const l=e.UIPointerActions;this.on(l.down,(t,e)=>{this.state("dragging",!0),this.state("offset",new s.Pt(e).subtract(t.group[0])),this._moveHoldID=this.hold(l.move),this._draggingID=this.on(l.move,(t,e)=>{this.state("dragging")&&n._trigger(this._actions[l.uidrag],t,e,l.uidrag)})}),this.on(l.up,(t,e,r)=>{this.state("dragging",!1),this.off(l.move,this._draggingID),this.unhold(this._moveHoldID),n._trigger(this._actions[l.drop],t,e,r)})}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.drop,t)}offDrop(t){return this.off(e.UIPointerActions.drop,t)}}},"./src/Util.ts":function(e,i,n){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const o=n("./src/Pt.ts");i.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:s,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"],s=t[0];for(let t=0;t=s.length)&&r[t]in s;t++)e.push(s[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 u(Math.random()*t)+e}static split(t,e,r,s=!1){let i=r||e,n=[];for(let r=0;rt.length){if(!s)break;{let s=t.slice(r*i);s=s.concat(t.slice(0,(r*i+e)%e)),n.push(s)}}else n.push(t.slice(r*i,r*i+e));return n}static flatten(t,e=!0){let r=e?new o.Group:[];return r.concat.apply(r,t)}static combine(t,e,r){let s=[];for(let i=0,n=t.length;i=t&&(i=e+(i-t)),s&&s(i),i}}static forRange(t,e,r=0,s=1){let i=[];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()}}l._warnLevel="mute",i.Util=l},"./src/_lib.ts":function(t,e,r){"use strict";function s(t){for(var r in t)e.hasOwnProperty(r)||(e[r]=t[r])}Object.defineProperty(e,"__esModule",{value:!0}),s(r("./src/Canvas.ts")),s(r("./src/Create.ts")),s(r("./src/Form.ts")),s(r("./src/LinearAlgebra.ts")),s(r("./src/Num.ts")),s(r("./src/Op.ts")),s(r("./src/Pt.ts")),s(r("./src/Space.ts")),s(r("./src/Color.ts")),s(r("./src/Util.ts")),s(r("./src/Dom.ts")),s(r("./src/Svg.ts")),s(r("./src/Typography.ts")),s(r("./src/Physics.ts")),s(r("./src/UI.ts"));const i=r("./src/Canvas.ts");e.namespace=(e=>{let r=t.exports;for(let t in r)"namespace"!=t&&(e[t]=r[t])}),e.quickStart=((t,r="#9ab")=>{let s=window;return e.namespace(s),s.space=new i.CanvasSpace(t).setup({bgcolor:r,resize:!0,retina:!0}),s.form=s.space.getForm(),function(t=null,e=null,r=null,i=null){s.space.add({start:e,animate:t,resize:i,action:r}),s.space.bindMouse().bindTouch().play()}})}})}()}])}); +!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()}(window,function(){return function(t){function e(s){if(r[s])return r[s].exports;var i=r[s]={i:s,l:!1,exports:{}};return t[s].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,s){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:s})},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 s=Object.create(null);if(e.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var i in t)e.d(s,i,function(e){return t[e]}.bind(null,i));return s},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){window,t.exports=function(){var t=Math.PI,e=Math.abs,r=Number.MAX_VALUE,s=Number.MIN_VALUE,i=Math.sin,n=Math.cos,o=Math.sqrt,l=Math.atan2,h=Math.pow,a=Math.min,u=Math.floor,c=Math.max;return function(t){function e(s){if(r[s])return r[s].exports;var i=r[s]={i:s,l:!1,exports:{}};return t[s].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,s){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:s})},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 s=Object.create(null);if(e.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var i in t)e.d(s,i,function(e){return t[e]}.bind(null,i));return s},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});const s=r("./src/Space.ts"),i=r("./src/Form.ts"),n=r("./src/Pt.ts"),o=r("./src/Util.ts"),l=r("./src/Typography.ts"),h=r("./src/Op.ts");e.CanvasSpace=class extends s.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(t.bgcolor&&(this._bgcolor=t.bgcolor),this.autoResize=void 0!=t.resize&&t.resize,!1!==t.retina){let t=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){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=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._ctx.translate(.5,.5),this._offscreen&&(this._offCtx.scale(this._pixelScale,this._pixelScale),this._offCtx.translate(.5,.5))),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){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 a(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);let e=this._ctx.fillStyle;return this._bgcolor&&"transparent"!=this._bgcolor?(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))}};class a extends i.VisualForm{constructor(t){super(),this._style={fillStyle:"#f03",strokeStyle:"#fff",lineWidth:1,lineJoin:"bevel",lineCap:"butt"},this._space=t,this._space.add({start:()=>{this._ctx=this._space.ctx,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}})}get space(){return this._space}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)}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,s){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),s&&(this._ctx.lineCap=s,this._style.lineCap=s)),this}font(t,e,r,s,i){return"number"==typeof t?(this._font.size=t,i&&(this._font.face=i),e&&(this._font.weight=e),r&&(this._font.style=r),s&&(this._font.lineHeight=s),this._ctx.font=this._font.value):this._font=t,this._estimateTextWidth&&this.fontWidthEstimate(!0),this}fontWidthEstimate(t=!0){return this._estimateTextWidth=t?l.Typography.textWidthEstimator(t=>this._ctx.measureText(t).width):void 0,this}getTextWidth(t){return this._estimateTextWidth?this._estimateTextWidth(t):this._ctx.measureText(t+" .").width}_textTruncate(t,e,r=""){return l.Typography.truncate(this.getTextWidth.bind(this),t,e,r)}_textAlign(t,e,r,s){s||(s=h.Rectangle.center(t));var i=t[0][0];"end"==this._ctx.textAlign||"right"==this._ctx.textAlign?i=t[1][0]:("center"==this._ctx.textAlign||"middle"==this._ctx.textAlign)&&(i=s[0]);var o=s[1];return"top"==e||"start"==e?o=t[0][1]:("end"==e||"bottom"==e)&&(o=t[1][1]),r?new n.Pt(i+r[0],o+r[1]):new n.Pt(i,o)}reset(){for(let t in this._style)this._style.hasOwnProperty(t)&&(this._ctx[t]=this._style[t]);return this._font=new i.Font,this._ctx.font=this._font.value,this}_paint(){this._filled&&this._ctx.fill(),this._stroked&&this._ctx.stroke()}point(t,e=5,r="square"){if(t){if(!a[r])throw new Error(`${r} is not a static function of CanvasForm`);return a[r](this._ctx,t,e),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){return a.circle(this._ctx,t[0],t[1][0]),this._paint(),this}static arc(t,e,r,s,i,n){e&&(t.beginPath(),t.arc(e[0],e[1],r,s,i,n))}arc(t,e,r,s,i){return a.arc(this._ctx,t,e,r,s,i),this._paint(),this}static square(t,e,r){if(e){let s=e[0]-r,i=e[1]-r,n=e[0]+r,o=e[1]+r;t.beginPath(),t.moveTo(s,i),t.lineTo(s,o),t.lineTo(n,o),t.lineTo(n,i),t.closePath()}}square(t,e){return a.square(this._ctx,t,e),this._paint(),this}static line(t,e){if(!(2>e.length)){t.beginPath(),t.moveTo(e[0][0],e[0][1]);for(let r=1,s=e.length;re.length)){t.beginPath(),t.moveTo(e[0][0],e[0][1]);for(let r=1,s=e.length;re.length||(t.beginPath(),t.moveTo(e[0][0],e[0][1]),t.lineTo(e[0][0],e[1][1]),t.lineTo(e[1][0],e[1][1]),t.lineTo(e[1][0],e[0][1]),t.closePath())}rect(t){return a.rect(this._ctx,t),this._paint(),this}static image(t,e,r=new n.Pt,s){if("number"==typeof r[0])t.drawImage(e,r[0],r[1]);else{let i=r;s?t.drawImage(e,s[0][0],s[0][1],s[1][0]-s[0][0],s[1][1]-s[0][1],i[0][0],i[0][1],i[1][0]-i[0][0],i[1][1]-i[0][1]):t.drawImage(e,i[0][0],i[0][1],i[1][0]-i[0][0],i[1][1]-i[0][1])}}image(t,e,r){return a.image(this._ctx,t,e,r),this}static text(t,e,r,s){e&&t.fillText(r,e[0],e[1],s)}text(t,e,r){return a.text(this._ctx,t,e,r),this}textBox(t,e,r="middle",s="",i=!0){i&&(this._ctx.textBaseline=r);let n=h.Rectangle.size(t),o=this._textTruncate(e,n[0],s);return this.text(this._textAlign(t,r),o[0]),this}paragraphBox(t,e,r=1.2,s="top",i=!0){let o=h.Rectangle.size(t);this._ctx.textBaseline="top";let l=this._font.size*r,a=(t,e=[],r=0)=>{if(!t)return e;if(i&&r*l>o[1]-2*l)return e;if(1e4=h||s[1]===t.length)&&(h=void 0);let u=s[0].substr(0,h);return e.push(u),0>=s[1]||s[1]===t.length?e:a(t.substr(h||s[1]),e,r+1)},u=a(e),d=u.length*l,p=t;if("middle"==s||"center"==s){let e=(o[1]-d)/2;i&&(e=c(0,e)),p=new n.Group(t[0].$add(0,e),t[1].$subtract(0,e))}else p="bottom"==s?new n.Group(t[0].$add(0,o[1]-d),t[1]):new n.Group(t[0],t[0].$add(o[0],d));let g=h.Rectangle.center(p);for(let t=0,e=u.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 g(r>>16,255&r>>8,255&r,e)}static rgb(...t){return g.from(...t).toMode("rgb")}static hsl(...t){return g.from(...t).toMode("hsl")}static hsb(...t){return g.from(...t).toMode("hsb")}static lab(...t){return g.from(...t).toMode("lab")}static lch(...t){return g.from(...t).toMode("lch")}static luv(...t){return g.from(...t).toMode("luv")}static xyz(...t){return g.from(...t).toMode("xyz")}static maxValues(t){return g.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 g(this);return t.toMode(this._mode),t}toMode(t,e=!1){if(e){let e=this._mode.toUpperCase()+"to"+t.toUpperCase();if(!g[e])throw new Error("Cannot convert color with "+e);this.to(g[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){let e="lch"==this._mode?2:0;this[e]=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){let e="hsl"==this._mode?2:0;this[e]=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}get alpha(){return 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[s,i,n]=e?t:t.$normalize(),o=c(s,i,n),l=a(s,i,n),h=(o+l)/2,u=h,d=h;if(o==l)h=0,u=0;else{let t=o-l;u=.5=n?n*(1+i):n+i-n*i,l=2*n-o,h=t=>(t=0>t?t+1:16*t?l+(o-l)*t*6:1>2*t?o:2>3*t?l+(o-l)*(2/3-t)*6:l),a=r?1:255;return g.rgb(a*h(s+1/3),a*h(s),a*h(s-1/3),t.alpha)}static RGBtoHSB(t,e=!1,r=!1){let[s,i,n]=e?t:t.$normalize(),o=c(s,i,n),l=a(s,i,n),h=o-l,u=0,d=0===o?0:h/o;return o!=l&&(o===s?u=(i-n)/h+(it;t++)s[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,r=0;255>r;r++)e=1&r?d[r]^255&t:d[r]^255&t>>8,this.perm[r]=this.perm[r+256]=e}noise2D(){let t=c(0,u(this._n[0]))%255,e=c(0,u(this._n[1]))%255,r=this._n[0]%255-t,s=this._n[1]%255-e,i=l.Vec.dot(h[(t+this.perm[e])%12],[r,s,0]),n=l.Vec.dot(h[(t+this.perm[e+1])%12],[r,s-1,0]),a=l.Vec.dot(h[(t+1+this.perm[e])%12],[r-1,s,0]),d=l.Vec.dot(h[(t+1+this.perm[e+1])%12],[r-1,s-1,0]),p=t=>t*t*t*(t*(6*t-15)+10),g=p(r);return o.Num.lerp(o.Num.lerp(i,a,g),o.Num.lerp(n,d,g),p(s))}}e.Noise=p;class g extends s.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 s=this.slice(),i=this._superTriangle();s=s.concat(i);let o=[this._circum(e,e+1,e+2,i)],l=[],h=[];for(let t=0,e=r.length;tr*r?(l.push(t),h.push(t.triangle),o.splice(a,1)):u[0]*u[0]+u[1]*u[1]-r*r>n.Const.epsilon||(i.push(t.i,t.j,t.j,t.k,t.k,t.i),o.splice(a,1))}for(g._dedupe(i),a=i.length;1{t.parentNode.removeChild(t)}),super.remove(t)}removeAll(){return this._container.innerHTML="",super.removeAll()}}e.HTMLSpace=h;class a extends i.VisualForm{constructor(t){super(),this._ctx={group:null,groupID:"pts",groupCount:0,currentID:"pts0",currentClass:"",style:{filled:!0,stroked:!0,background:"#f03","border-color":"#fff",color:"#000","border-width":"1px","border-radius":"0","border-style":"solid",position:"absolute",top:0,left:0,width:0,height:0},font:"11px sans-serif",fontSize:11,fontFamily:"sans-serif"},this._ready=!1,this._space=t,this._space.add({start:()=>{this._ctx.group=this._space.element,this._ctx.groupID="pts_dom_"+a.groupID++,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}`}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,s,i){return"number"==typeof t?(this._font.size=t,i&&(this._font.face=i),e&&(this._font.weight=e),r&&(this._font.style=r),s&&(this._font.lineHeight=s),this._ctx.font=this._font.value):this._font=t,this}reset(){return this._ctx.style={filled:!0,stroked:!0,background:"#f03","border-color":"#fff","border-width":"1px"},this._font=new i.Font(14,"sans-serif"),this._ctx.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(a.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-${a.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 s=e[t];if(s){if(!e.filled&&0===t.indexOf("background"))continue;if(!e.stroked&&0===t.indexOf("border-width"))continue;r.push(`${t}: ${s}`)}}return h.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 point(t,e,r=5,s="square"){return"circle"===s?a.circle(t,e,r):a.square(t,e,r)}point(t,e=5,r="square"){return this.nextID(),"circle"==r&&this.styleTo("border-radius","100%"),a.point(this._ctx,t,e,r),this}static circle(t,e,r=10){let s=h.htmlElement(t.group,"div",a.getID(t));return h.setAttr(s,{class:`pts-form pts-circle ${t.currentClass}`}),a.rectStyle(t,new o.Pt(e).$subtract(r),new o.Pt(2*r,2*r)),a.style(s,t.style),s}circle(t){return this.nextID(),this.styleTo("border-radius","100%"),a.circle(this._ctx,t[0],t[1][0]),this}static square(t,e,r){let s=h.htmlElement(t.group,"div",a.getID(t));return h.setAttr(s,{class:`pts-form pts-square ${t.currentClass}`}),a.rectStyle(t,new o.Pt(e).$subtract(r),new o.Pt(2*r,2*r)),a.style(s,t.style),s}square(t,e){return this.nextID(),a.square(this._ctx,t,e),this}static rect(t,e){if(this._checkSize(e)){let r=h.htmlElement(t.group,"div",a.getID(t));return h.setAttr(r,{class:`pts-form pts-rect ${t.currentClass}`}),a.rectStyle(t,e[0],e[1]),a.style(r,t.style),r}}rect(t){return this.nextID(),this.styleTo("border-radius","0"),a.rect(this._ctx,t),this}static text(t,e,r){let s=h.htmlElement(t.group,"div",a.getID(t));return h.setAttr(s,{position:"absolute",class:`pts-form pts-text ${t.currentClass}`,left:e[0],top:e[1]}),s.textContent=r,a.style(s,t.style),s}text(t,e){return this.nextID(),a.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}}a.groupID=0,a.domID=0,e.HTMLForm=a},"./src/Form.ts":function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=r("./src/Util.ts");class i{constructor(){this._ready=!1}get ready(){return this._ready}static _checkSize(t,e=2){return!(t.lengthc(t,e.length),0):t[0].length;for(let r=0;rs?n-=i:n=a(e,r)&&t<=c(e,r)}static randomRange(t,e=0){let r=t>e?t-e:e-t;return t+Math.random()*r}static normalizeValue(t,e,r){let s=a(e,r),i=c(e,r);return(t-s)/(i-s)}static sum(t){let e=new f.Pt(t[0]);for(let r=1,s=t.length;rt.$min(e)),r=t.reduce((t,e)=>t.$max(e));return new f.Group(e,r)}static centroid(t){return m.average(t)}static anchor(t,e=0,r="to"){let s="to"==r?"subtract":"add";for(let r=0,i=t.length;r{if(2>t.length||2>e.length)throw new Error("Pt dimension cannot be less than 2");let s=t.$subtract(r),i=e.$subtract(r);if(0<=s[0]&&0>i[0])return 1;if(0>s[0]&&0<=i[0])return-1;if(0==s[0]&&0==i[0])return 0<=s[1]||0<=i[1]?s[1]>i[1]?1:-1:i[1]>s[1]?1:-1;let n=s.$cross2D(i);return 0>n?1:0i[0]*i[0]+i[1]*i[1]?1:-1})}static scale(t,e,r){let s=Array.isArray(t)?t:[t],i="number"==typeof e?f.Pt.make(s[0].length,e):e;r||(r=f.Pt.make(s[0].length,0));for(let t,e=0,n=s.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]=i(r*t/180);return{table:e,sin:t=>e[u(w.boundAngle(w.toDegree(t)))]}}}s.Geom=w;class y{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*h(t,1/r)}static exponentialOut(t,e=1,r=.25){return e*h(t,r)}static sineIn(t,e=1){return-e*n(t*p.Const.half_pi)+e}static sineOut(t,e=1){return e*i(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,s=r*r;return e*(s*r*4/9-17*s/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 s=t-1,n=r/p.Const.two_pi*1.5707963267948966;return e*(-h(2,10*s)*i((s-n)*p.Const.two_pi/r))}static elasticOut(t,e=1,r=.7){let s=r/p.Const.two_pi*1.5707963267948966;return e*(h(2,-10*t)*i((t-s)*p.Const.two_pi/r))+e}static elasticInOut(t,e=1,r=.6){let s=2*t,n=r/p.Const.two_pi*1.5707963267948966;return.5>t?e*(h(2,10*(s-=1))*i((s-n)*p.Const.two_pi/r)*-.5):e*(h(2,-10*(s-=1))*i((s-n)*p.Const.two_pi/r)*.5)+e}static bounceIn(t,e=1){return e-y.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?y.bounceIn(2*t,e)/2:y.bounceOut(2*t-1,e)/2+e/2}static sigmoid(t,e=1,r=10){return e/(1+d(-r*(t-.5)))}static logSigmoid(t,e=1,r=.7){r=c(p.Const.epsilon,a(1-p.Const.epsilon,r));let s=1/(1+d((t-.5)*(r=1/(1-r))*-2)),i=1/(1+d(r)),n=1/(1+d(-r));return e*(s-i)/(n-i)}static seat(t,e=1,r=.5){return.5>t?e*h(2*t,1-r)/2:e*(1-h(2*(1-t),1-r)/2)}static quadraticBezier(t,e=1,r=[.05,.95]){let s="number"==typeof r?r:r[0],i="number"==typeof r?.5:r[1],n=1-2*s;0===n&&(n=p.Const.epsilon);let l=(o(s*s+n*t)-s)/n;return e*(l*l*(1-2*i)+2*i*l)}static cubicBezier(t,e=1,r=[.1,.7],s=[.9,.2]){let i=new f.Group(new f.Pt(0,0),new f.Pt(r),new f.Pt(s),new f.Pt(1,1));return e*g.Curve.bezierStep(new f.Pt(t*t*t,t*t,t,1),g.Curve.controlPoints(i)).y}static quadraticTarget(t,e=1,r=[.2,.35]){let s=a(1-p.Const.epsilon,c(p.Const.epsilon,r[0])),i=a(1,c(0,r[1])),n=(1-i)/(1-s)-i/s;return e*a(1,c(0,n*(t*t)-(n*(s*s)-i)/s*t))}static cliff(t,e=1,r=.5){return t>r?e:0}static step(t,e,r,s,...i){let n=1/e,o=u(r/n)*n;return t(o,s,...i)}}s.Shaping=y,s.Range=class{constructor(t){this._dims=0,this._source=f.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 f.Pt(t),r=new f.Pt(t),s=new f.Pt(t);for(let i=0;id.Util.warn("Group's length is less than "+e,t),m=(t,e="")=>d.Util.warn(`Index ${e} is out of bound in Group`,t);class w{static fromAngle(t,e,r){let s=new g.Group(new g.Pt(t),new g.Pt(t));return s[1].toAngle(e,r,!0),s}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]),s=t[1]-r*t[0];return{slope:r,yi:s,xi:0==r?void 0:-s/r}}}static sideOfPt2D(t,e){return(t[1][0]-t[0][0])*(e[1]-t[0][1])-(e[0]-t[0][0])*(t[1][1]-t[0][1])}static collinear(t,e,r,s=.01){let i=new g.Pt(0,0,0).to(t).$subtract(e),n=new g.Pt(0,0,0).to(t).$subtract(r);return i.$cross(n).divide(1e3).equals(new g.Pt(0,0,0),s)}static magnitude(t){return 2<=t.length?t[1].$subtract(t[0]).magnitude():0}static magnitudeSq(t){return 2<=t.length?t[1].$subtract(t[0]).magnitudeSq():0}static perpendicularFromPt(t,e,r=!1){if(!t[0].equals(t[1])){let s=t[0].$subtract(t[1]),i=t[1].$subtract(e),n=i.$subtract(s.$project(i));return r?n:n.$add(e)}}static distanceFromPt(t,e){return w.perpendicularFromPt(t,e,!0).magnitude()}static intersectRay2D(t,e){let r=w.intercept(t[0],t[1]),s=w.intercept(e[0],e[1]),i=t[0],n=e[0];if(void 0==r){if(void 0==s)return;let t=-s.slope*(n[0]-i[0])+n[1];return new g.Pt(i[0],t)}if(void 0==s){let t=-r.slope*(i[0]-n[0])+i[1];return new g.Pt(n[0],t)}if(s.slope!=r.slope){let t=(r.slope*i[0]-s.slope*n[0]+n[1]-i[1])/(r.slope-s.slope),e=r.slope*(t-i[0])+i[1];return new g.Pt(t,e)}return r.yi==s.yi?new g.Pt(i[0],i[1]):void 0}static intersectLine2D(t,e){let r=w.intersectRay2D(t,e);return r&&p.Geom.withinBound(r,t[0],t[1])&&p.Geom.withinBound(r,e[0],e[1])?r:void 0}static intersectLineWithRay2D(t,e){let r=w.intersectRay2D(t,e);return r&&p.Geom.withinBound(r,t[0],t[1])?r:void 0}static intersectPolygon2D(t,e,r=!1){let s=r?w.intersectLineWithRay2D:w.intersectLine2D,i=new g.Group;for(let r=0,n=e.length;re(r[1]/r[0])?0>o[1]?0:2:0>o[0]?3:1,w.intersectRay2D(n[l],t)}}static marker(t,e,r="arrow",s=!0){let i=s?0:1,n=s?1:0,o=t[i].$subtract(t[n]);if(0===o.magnitudeSq())return new g.Group;o.unit();let l=p.Geom.perpendicular(o).multiply(e[0]).add(t[n]);return"arrow"==r?(l.add(o.$multiply(e[1])),new g.Group(t[n],l[0],l[1])):new g.Group(l[0],l[1])}static toRect(t){return new g.Group(t[0].$min(t[1]),t[0].$max(t[1]))}}l.Line=w;class y{static from(t,e,r){return y.fromTopLeft(t,e,r)}static fromTopLeft(t,e,r){let s="number"==typeof e?[e,r||e]:e;return new g.Group(new g.Pt(t),new g.Pt(t).add(s))}static fromCenter(t,e,r){let s="number"==typeof e?[e/2,(r||e)/2]:new g.Pt(e).divide(2);return new g.Group(new g.Pt(t).subtract(s),new g.Pt(t).add(s))}static toCircle(t,e=!0){return b.fromRect(t,e)}static toSquare(t,e=!1){let r=y.size(t),s=e?r.maxValue().value:r.minValue().value;return y.fromCenter(y.center(t),s,s)}static size(t){return t[0].$max(t[1]).subtract(t[0].$min(t[1]))}static center(t){let e=t[0].$min(t[1]),r=t[0].$max(t[1]);return e.add(r.$subtract(e).divide(2))}static corners(t){let e=t[0].$min(t[1]),r=t[0].$max(t[1]);return new g.Group(e,new g.Pt(r.x,e.y),r,new g.Pt(e.x,r.y))}static sides(t){let[e,r,s,i]=y.corners(t);return[new g.Group(e,r),new g.Group(r,s),new g.Group(s,i),new g.Group(i,e)]}static boundingBox(t){let e=d.Util.flatten(t,!1),r=g.Pt.make(2,Number.MAX_VALUE),s=g.Pt.make(2,Number.MIN_VALUE);for(let t=0,i=e.length;ti;i++)r[i]=a(r[i],e[t][i]),s[i]=c(s[i],e[t][i]);return new g.Group(r,s)}static polygon(t){return y.corners(t)}static quadrants(t,e){let r=y.corners(t),s=void 0==e?y.center(t):new g.Pt(e);return r.map(t=>new g.Group(t,s).boundingBox())}static halves(t,e=.5,r=!1){let s=t[0].$min(t[1]),i=t[0].$max(t[1]),n=r?p.Num.lerp(s[1],i[1],e):p.Num.lerp(s[0],i[0],e);return r?[new g.Group(s,new g.Pt(i[0],n)),new g.Group(new g.Pt(s[0],n),i)]:[new g.Group(s,new g.Pt(n,i[1])),new g.Group(new g.Pt(n,s[1]),i)]}static withinBound(t,e){return p.Geom.withinBound(e,t[0],t[1])}static hasIntersectRect2D(t,e,r=!1){return r&&(t=p.Geom.boundingBox(t),e=p.Geom.boundingBox(e)),!(t[0][0]>e[1][0]||e[0][0]>t[1][0]||t[0][1]>e[1][1]||e[0][1]>t[1][1])}static intersectRect2D(t,e){return y.hasIntersectRect2D(t,e)?w.intersectLines2D(y.sides(t),y.sides(e)):new g.Group}}l.Rectangle=y;class b{static fromRect(t,e=!1){let r=0,s=r=y.size(t).minValue().value/2;if(e){let e=y.size(t).maxValue().value/2;r=o(s*s+e*e)}else r=s;return new g.Group(y.center(t),new g.Pt(r,r))}static fromTriangle(t,e=!1){return e?x.circumcircle(t):x.incircle(t)}static fromCenter(t,e){return new g.Group(new g.Pt(t),new g.Pt(e,e))}static withinBound(t,e,r=0){let s=t[0].$subtract(e);return s.dot(s)+ra)return new g.Group;{let t=o(a),s=e[0].$subtract(r.$multiply(-h+t));if(0==a)return new g.Group(s);let i=e[0].$subtract(r.$multiply(-h-t));return new g.Group(s,i)}}static intersectLine2D(t,e){let r=b.intersectRay2D(t,e),s=new g.Group;if(0l+h)return new g.Group;if(ni;i++)s.push(e[0].clone().toAngle(r,e[1][0],!0)),r+=2*t/3;return s}return x.fromCenter(e[0],e[1][0])}}l.Circle=b;class x{static fromRect(t){let e=t[0].$add(t[1]).divide(2);e.y=t[0][1];let r=t[1].clone();return r.x=t[0][0],new g.Group(e,t[1].clone(),r)}static fromCircle(t){return b.toTriangle(t,!0)}static fromCenter(t,e){return x.fromCircle(b.fromCenter(t,e))}static medial(t){return 3>t.length?_(new g.Group,3):v.midpoints(t,!0)}static oppositeSide(t,e){return 3>t.length?_(new g.Group,3):0===e?g.Group.fromPtArray([t[1],t[2]]):1===e?g.Group.fromPtArray([t[0],t[2]]):g.Group.fromPtArray([t[0],t[1]])}static altitude(t,e){let r=x.oppositeSide(t,e);return 1t.length)return _(void 0,3);let e=x.altitude(t,0),r=x.altitude(t,1);return w.intersectRay2D(e,r)}static incenter(t){if(3>t.length)return _(void 0,3);let e=v.bisector(t,0).add(t[0]),r=v.bisector(t,1).add(t[1]);return w.intersectRay2D(new g.Group(t[0],e),new g.Group(t[1],r))}static incircle(t,e){let r=e||x.incenter(t),s=v.area(t),i=v.perimeter(t,!0),n=2*s/i.total;return b.fromCenter(r,n)}static circumcenter(t){let e=x.medial(t),r=[e[0],p.Geom.perpendicular(t[0].$subtract(e[0])).p1.$add(e[0])],s=[e[1],p.Geom.perpendicular(t[1].$subtract(e[1])).p1.$add(e[1])];return w.intersectRay2D(r,s)}static circumcircle(t,e){let r=e||x.circumcenter(t),s=t[0].$subtract(r).magnitude();return b.fromCenter(r,s)}}l.Triangle=x;class v{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,s){let o=new g.Group;for(let l,h=0;he||e>=t.length)throw new Error("index out of the Polygon's range");return new g.Group(t[e],e===t.length-1?t[0]:t[e+1])}static lines(t,e=!0){if(2>t.length)return _(new g.Group,2);let r=d.Util.split(t,2,1);return e&&r.push(new g.Group(t[t.length-1],t[0])),r.map(t=>t)}static midpoints(t,e=!1,r=.5){if(2>t.length)return _(new g.Group,2);let s=v.lines(t,e),i=s.map(t=>p.Geom.interpolate(t[0],t[1],r));return i}static adjacentSides(t,e,r=!1){if(2>t.length)return _(new g.Group,2);if(0>e||e>=t.length)return m(new g.Group,e);let s=[],i=e-1;r&&0>i&&(i=t.length-1),0<=i&&s.push(new g.Group(t[e],t[i]));let n=e+1;return r&&n>t.length-1&&(n=0),n<=t.length-1&&s.push(new g.Group(t[e],t[n])),s}static bisector(t,e){let r=v.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){if(2>t.length)return _(new g.Group,2);let r=v.lines(t,e),s=0,i=g.Pt.make(r.length,0);for(let t,e=0,n=r.length;et.length)return _(new g.Group,3);let r=(t,e)=>t[0]*e[1]-t[1]*e[0],s=0;for(let e=0,i=t.length;et.length)return _(new g.Group,3);e||(t=t.slice()).sort((t,e)=>t[0]-e[0]);let r=(t,e,r)=>0<(e[0]-t[0])*(r[1]-t[1])-(r[0]-t[0])*(e[1]-t[1]),s=[],i=t.length-2,n=i+3;s[i]=t[2],s[n]=t[2],r(t[0],t[1],t[2])?(s[i+1]=t[0],s[i+2]=t[1]):(s[i+1]=t[1],s[i+2]=t[0]);for(let e,o=3,l=t.length;oe[1]!=s[1][1]>e[1]&&e[0]<(s[1][0]-s[0][0])*(e[1]-s[0][1])/(s[1][1]-s[0][1])+s[0][0]&&(r=!r);return r}static hasIntersectCircle(t,r){let s={which:-1,dist:0,normal:null,edge:null,vertex:null},i=r[0],n=r[1][0],o=u;for(let l=0,h=t.length;ll&&s.normal.multiply(-1),s.dist=o,s.vertex=i,s}static hasIntersectPolygon(t,r){let s={which:-1,dist:0,normal:new g.Pt,edge:new g.Group,vertex:new g.Pt},i=u;for(let n=0,o=t.length+r.length;na&&s.normal.multiply(-1);let c=u;for(let t,e=0,r=n.length;ep.Geom.boundingBox(t)),r=d.Util.flatten(e,!1);return e.unshift(p.Geom.boundingBox(r)),e}}l.Polygon=v;class P{static getSteps(t){let e=new g.Group;for(let r,s=0;s<=t;s++)r=s/t,e.push(new g.Pt(r*r*r,r*r,r,1));return e}static controlPoints(t,e=0,r=!1){if(e>t.length-1)return new g.Group;let s=e=>et+r.x*e[s],0),s=t.reduce((t,r,s)=>t+r.y*e[s],0);if(2t+r.z*e[s],0);return new g.Pt(r,s,i)}return new g.Pt(r,s)}static catmullRom(t,e=10){if(2>t.length)return new g.Group;let r=new g.Group,s=P.getSteps(e),i=P.controlPoints(t,0,!0);for(let t=0;t<=e;t++)r.push(P.catmullRomStep(s[t],i));for(let i,n=0;nt.length)return new g.Group;let s=new g.Group,i=P.getSteps(e),n=P.controlPoints(t,0,!0);for(let t=0;t<=e;t++)s.push(P.cardinalStep(i[t],n,r));for(let n,o=0;ot.length)return new g.Group;let r=new g.Group,s=P.getSteps(e),i=0;for(;it.length)return new g.Group;let s=new g.Group,i=P.getSteps(e),n=0;for(;n(r=t(e)))throw new Error("Cannot find index of "+e);return r}removeBody(t,e=1){const r=this._index(this.bodyIndex.bind(this),t),s=0>r?[-1*r-1,e]:[r,e];return this._bodies.splice(s[0],s[1]),this._bnames.splice(s[0],s[1]),this}removeParticle(t,e=1){const r=this._index(this.particleIndex.bind(this),t),s=0>r?[-1*r-1,e]:[r,e];return this._particles.splice(s[0],s[1]),this._pnames.splice(s[0],s[1]),this}static edgeConstraint(t,e,r,s=1,i=!1){const n=1/(t.mass||1),o=1/(e.mass||1),l=n+o;let h=e.$subtract(t),a=r*r,u=i?r/h.magnitude()-1:a/(h.dot(h)+a)-.5,c=h.$multiply(u*s);return t.subtract(c.$multiply(n/l)),e.add(c.$multiply(o/l)),t}static boundConstraint(t,e,r=.75){let s=e.boundingBox(),n=t.$min(s[1].subtract(t.radius)).$max(s[0].add(t.radius));if(n[0]===s[0][0]||n[0]===s[1][0]){let e=t.changed.$multiply(r);t.previous=n.$subtract(new i.Pt(-e[0],e[1]))}else if(n[1]===s[0][1]||n[1]===s[1][1]){let e=t.changed.$multiply(r);t.previous=n.$subtract(new i.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,s=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 s=this[t].$subtract(this[e]).magnitude();return this._cs.push([t,e,s,r||this._stiff]),this}linkAll(t){let e=this.length/2;for(let r,s=0,i=this.length;s=i-1?0:s+1,this.link(s,r,t),4=i-r?s%i:s+r;this.link(s,n,t)}s<=e-1&&this.link(s,a(this.length-1,s+u(e)))}}linksToLines(){let t=[];for(let e,r=0,s=this._cs.length;re(i[0][1]-i[1][1])?(r.vertex[0]-s[0]-i[0][0])/(i[1][0]-i[0][0]):(r.vertex[1]-s[1]-i[0][1])/(i[1][1]-i[0][1]))*t+(1-t)*(1-t)),o=r.vertex.body.mass||1,l=r.edge[0].body.mass||1,h=o/(o+l);i[0].subtract(s.$multiply(h*(1-t)*n/2)),i[1].subtract(s.$multiply(h*t*n/2)),r.vertex.add(s.$multiply(l/(o+l)))}}processParticle(t){let r=n.Polygon.hasIntersectCircle(this,n.Circle.fromCenter(t,t.radius));if(r){let s,i=r.normal.$multiply(r.dist),n=r.edge,o=1/((s=e(n[0][0]-n[1][0])>e(n[0][1]-n[1][1])?(r.vertex[0]-i[0]-n[0][0])/(n[1][0]-n[0][0]):(r.vertex[1]-i[1]-n[0][1])/(n[1][1]-n[0][1]))*s+(1-s)*(1-s)),l=r.vertex.mass||t.mass||1,h=r.edge[0].body.mass||1,a=l/(l+h);n[0].subtract(i.$multiply(a*(1-s)*o/2)),n[1].subtract(i.$multiply(a*s*o/2));let u=t.changed.add(i.$multiply(h/(l+h)));t.previous=t.$subtract(u)}}}r.Body=c},"./src/Pt.ts":function(t,r,s){"use strict";Object.defineProperty(r,"__esModule",{value:!0});const o=s("./src/Util.ts"),h=s("./src/Num.ts"),d=s("./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=a(this.length,e.length);tt(e,...r)}ops(t){let e=[];for(let r=0,s=t.length;rt?[-1*t-1,e]:[t,e];return g.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 h.Geom.centroid(this)}boundingBox(){return h.Geom.boundingBox(this)}anchorTo(t=0){h.Geom.anchor(this,t,"to")}anchorFrom(t=0){h.Geom.anchor(this,t,"from")}op(t){let e=this;return(...r)=>t(e,...r)}ops(t){let e=[];for(let r=0,s=t.length;re?s[t]-r[t]:r[t]-s[t])}forEachPt(t,...e){if(!this[0][t])return o.Util.warn(`${t} is not a function of Pt`),this;for(let r=0,s=this.length;rt+e.toString()+" ","")+" ]"}}r.Group=g;class f extends g{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 f(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){if(2>t.length)throw new Error("Cannot create a Bound from a group that has less than 2 Pt");return new f(t[0],t[t.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 f(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._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 s.Bound(s.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){this._canvas.addEventListener(t,e)}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._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._hasMouse=!1),this}bindTouch(t=!0){return t?(this.bindCanvas("touchstart",this._mouseDown.bind(this)),this.bindCanvas("touchend",this._mouseUp.bind(this)),this.bindCanvas("touchmove",this._touchMove.bind(this)),this.bindCanvas("touchcancel",this._mouseOut.bind(this)),this._hasTouch=!0):(this.unbindCanvas("touchstart",this._mouseDown.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 r=[];for(var i=0;i{t.parentNode.removeChild(t)}),super.remove(t)}removeAll(){return this._container.innerHTML="",super.removeAll()}}e.SVGSpace=a;class u extends s.VisualForm{constructor(t){super(),this._ctx={group:null,groupID:"pts",groupCount:0,currentID:"pts0",currentClass:"",style:{filled:!0,stroked:!0,fill:"#f03",stroke:"#fff","stroke-width":1,"stroke-linejoin":"bevel","stroke-linecap":"sqaure"},font:"11px sans-serif",fontSize:11,fontFamily:"sans-serif"},this._ready=!1,this._space=t,this._space.add({start:()=>{this._ctx.group=this._space.element,this._ctx.groupID="pts_svg_"+u.groupID++,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}fill(t){return"boolean"==typeof t?this.styleTo("filled",t):(this.styleTo("filled",!0),this.styleTo("fill",t)),this}stroke(t,e,r,s){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),s&&this.styleTo("stroke-linecap",s)),this}cls(t){return this._ctx.currentClass="boolean"==typeof t?"":t,this}font(t,e,r,s,i){return"number"==typeof t?(this._font.size=t,i&&(this._font.face=i),e&&(this._font.weight=e),r&&(this._font.style=r),s&&(this._font.lineHeight=s),this._ctx.font=this._font.value):this._font=t,this}reset(){return this._ctx.style={filled:!0,stroked:!0,fill:"#f03",stroke:"#fff","stroke-width":1,"stroke-linejoin":"bevel","stroke-linecap":"sqaure"},this._font=new s.Font(14,"sans-serif"),this._ctx.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 s=e[t];if(s){if(!e.filled&&0===t.indexOf("fill"))continue;if(!e.stroked&&0===t.indexOf("stroke"))continue;r.push(`${t}: ${s}`)}}return h.DOMSpace.setAttr(t,{style:r.join(";")})}static point(t,e,r=5,s="square"){return"circle"===s?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 s=a.svgElement(t.group,"circle",u.getID(t));return h.DOMSpace.setAttr(s,{cx:e[0],cy:e[1],r:r,class:`pts-svgform pts-circle ${t.currentClass}`}),u.style(s,t.style),s}circle(t){return this.nextID(),u.circle(this._ctx,t[0],t[1][0]),this}static arc(t,e,r,s,l,c){let d=a.svgElement(t.group,"path",u.getID(t));const p=new o.Pt(e).toAngle(s,r,!0),g=new o.Pt(e).toAngle(l,r,!0),f=i.Geom.boundAngle(l)-i.Geom.boundAngle(s);let _=!!(f>n.Const.pi);c&&(_=!_);const m=c?"0":"1",w=`M ${p[0]} ${p[1]} A ${r} ${r} 0 ${_?"1":"0"} ${m} ${g[0]} ${g[1]}`;return h.DOMSpace.setAttr(d,{d:w,class:`pts-svgform pts-arc ${t.currentClass}`}),u.style(d,t.style),d}arc(t,e,r,s,i){return this.nextID(),u.arc(this._ctx,t,e,r,s,i),this}static square(t,e,r){let s=a.svgElement(t.group,"rect",u.getID(t));return h.DOMSpace.setAttr(s,{x:e[0]-r,y:e[1]-r,width:2*r,height:2*r,class:`pts-svgform pts-square ${t.currentClass}`}),u.style(s,t.style),s}square(t,e){return this.nextID(),u.square(this._ctx,t,e),this}static line(t,e){if(this._checkSize(e)){if(2t+`${e[0]},${e[1]} `,"");return h.DOMSpace.setAttr(s,{points:i,class:`pts-svgform pts-polygon ${t.currentClass}`}),u.style(s,t.style),s}}static polygon(t,e){return u._poly(t,e,!0)}polygon(t){return this.nextID(),u.polygon(this._ctx,t),this}static rect(t,e){if(this._checkSize(e)){let r=a.svgElement(t.group,"rect",u.getID(t)),s=o.Group.fromArray(e).boundingBox(),i=l.Rectangle.size(s);return h.DOMSpace.setAttr(r,{x:s[0][0],y:s[0][1],width:i[0],height:i[1],class:`pts-svgform pts-rect ${t.currentClass}`}),u.style(r,t.style),r}}rect(t){return this.nextID(),u.rect(this._ctx,t),this}static text(t,e,r){let s=a.svgElement(t.group,"text",u.getID(t));return h.DOMSpace.setAttr(s,{"pointer-events":"none",x:e[0],y:e[1],dx:0,dy:0,class:`pts-svgform pts-text ${t.currentClass}`}),s.textContent=r,u.style(s,t.style),s}text(t,e){return this.nextID(),u.text(this._ctx,t,e),this}log(t){return this.fill("#000").stroke("#fff",.5).text([10,14],t),this}}u.groupID=0,u.domID=0,e.SVGForm=u},"./src/Typography.ts":function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const s=r("./src/Pt.ts");e.Typography=class{static textWidthEstimator(t,e=["M","n","."],r=[.06,.8,.14]){let i=e.map(t),n=new s.Pt(r).dot(i);return t=>t.length*n}static truncate(t,e,r,s=""){let i=u(e.length*a(1,r/t(e)));return ie?a(i,r):0t.length}return!1}}n._counter=0,e.UI=n;class o extends n{constructor(t,r,s={},i){super(t,r,s,i),this._hoverID=-1,void 0===s.hover&&(this._states.hover=!1),void 0===s.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)=>{let r=this._within(e);if(r&&!this._states.hover){this.state("hover",!0),n._trigger(this._actions[o.enter],this,e,o.enter);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),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)}onHover(t,r){var s=[void 0,void 0];return t&&(s[0]=this.on(e.UIPointerActions.enter,t)),r&&(s[1]=this.on(e.UIPointerActions.leave,r)),s}offHover(t,r){var s=[!1,!1];return(void 0===t||0<=t)&&(s[0]=this.off(e.UIPointerActions.enter,t)),(void 0===r||0<=r)&&(s[1]=this.off(e.UIPointerActions.leave,r)),s}}e.UIButton=o,e.UIDragger=class extends o{constructor(t,r,i={},o){super(t,r,i,o),this._draggingID=-1,this._moveHoldID=-1,void 0===i.dragging&&(this._states.dragging=!1),void 0===i.offset&&(this._states.offset=new s.Pt);const l=e.UIPointerActions;this.on(l.down,(t,e)=>{this.state("dragging",!0),this.state("offset",new s.Pt(e).subtract(t.group[0])),this._moveHoldID=this.hold(l.move),this._draggingID=this.on(l.move,(t,e)=>{this.state("dragging")&&n._trigger(this._actions[l.uidrag],t,e,l.uidrag)})}),this.on(l.up,(t,e,r)=>{this.state("dragging",!1),this.off(l.move,this._draggingID),this.unhold(this._moveHoldID),n._trigger(this._actions[l.drop],t,e,r)})}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.drop,t)}offDrop(t){return this.off(e.UIPointerActions.drop,t)}}},"./src/Util.ts":function(e,i,n){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const o=n("./src/Pt.ts");i.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:s,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"],s=t[0];for(let t=0;t=s.length)&&r[t]in s;t++)e.push(s[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 u(Math.random()*t)+e}static split(t,e,r,s=!1){let i=r||e,n=[];for(let r=0;rt.length){if(!s)break;{let s=t.slice(r*i);s=s.concat(t.slice(0,(r*i+e)%e)),n.push(s)}}else n.push(t.slice(r*i,r*i+e));return n}static flatten(t,e=!0){let r=e?new o.Group:[];return r.concat.apply(r,t)}static combine(t,e,r){let s=[];for(let i=0,n=t.length;i=t&&(i=e+(i-t)),s&&s(i),i}}static forRange(t,e,r=0,s=1){let i=[];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()}}l._warnLevel="mute",i.Util=l},"./src/_lib.ts":function(t,e,r){"use strict";function s(t){for(var r in t)e.hasOwnProperty(r)||(e[r]=t[r])}Object.defineProperty(e,"__esModule",{value:!0}),s(r("./src/Canvas.ts")),s(r("./src/Create.ts")),s(r("./src/Form.ts")),s(r("./src/LinearAlgebra.ts")),s(r("./src/Num.ts")),s(r("./src/Op.ts")),s(r("./src/Pt.ts")),s(r("./src/Space.ts")),s(r("./src/Color.ts")),s(r("./src/Util.ts")),s(r("./src/Dom.ts")),s(r("./src/Svg.ts")),s(r("./src/Typography.ts")),s(r("./src/Physics.ts")),s(r("./src/UI.ts"));const i=r("./src/Canvas.ts");e.namespace=(e=>{let r=t.exports;for(let t in r)"namespace"!=t&&(e[t]=r[t])}),e.quickStart=((t,r="#9ab")=>{let s=window;return e.namespace(s),s.space=new i.CanvasSpace(t).setup({bgcolor:r,resize:!0,retina:!0}),s.form=s.space.getForm(),function(t=null,e=null,r=null,i=null){s.space.add({start:e,animate:t,resize:i,action:r}),s.space.bindMouse().bindTouch().play()}})}})}()}])}); //# sourceMappingURL=pts.min.js.map \ No newline at end of file diff --git a/docs/json/class/UI_UIButton.json b/docs/json/class/UI_UIButton.json index a71ebd32..7347f90e 100644 --- a/docs/json/class/UI_UIButton.json +++ b/docs/json/class/UI_UIButton.json @@ -268,7 +268,7 @@ "source": [ [ "UI.ts", - 369, + 370, 10 ] ], @@ -298,7 +298,7 @@ "source": [ [ "UI.ts", - 394, + 395, 10 ] ], @@ -370,7 +370,7 @@ "source": [ [ "UI.ts", - 359, + 360, 9 ] ], @@ -400,7 +400,7 @@ "source": [ [ "UI.ts", - 380, + 381, 9 ] ], diff --git a/docs/json/class/UI_UIDragger.json b/docs/json/class/UI_UIDragger.json index c97d93b7..bdc9cf0e 100644 --- a/docs/json/class/UI_UIDragger.json +++ b/docs/json/class/UI_UIDragger.json @@ -3,7 +3,7 @@ "source": [ [ "UI.ts", - 407, + 408, 22 ] ], @@ -16,7 +16,7 @@ "source": [ [ "UI.ts", - 410, + 411, 34 ] ], @@ -26,7 +26,7 @@ "inherits": false, "signatures": [ { - "comment": "Create a dragger which has all the states in UIButton, with additional \"dragging\" (boolean) and \"offset\" (Pt) states. (See [`UI.state`](#link)) You may also create a new UIDragger using one of the static helper like [`UI.fromRectangle`](#link) or [`UI.fromCircle`](#link).", + "comment": "Create a dragger which has all the states in UIButton, with additional \"dragging\" (a boolean indicating whether it's currently being dragged) and \"offset\" (a Pt representing the offset between this UI's position and the pointer's position when dragged) states. (See [`UI.state`](#link)) You may also create a new UIDragger using one of the static helper like [`UI.fromRectangle`](#link) or [`UI.fromCircle`](#link).", "returns": "UIDragger", "returns_comment": false, "parameters": [ @@ -268,7 +268,7 @@ "source": [ [ "UI.ts", - 369, + 370, 10 ] ], @@ -298,7 +298,7 @@ "source": [ [ "UI.ts", - 466, + 467, 9 ] ], @@ -328,7 +328,7 @@ "source": [ [ "UI.ts", - 486, + 487, 9 ] ], @@ -358,7 +358,7 @@ "source": [ [ "UI.ts", - 394, + 395, 10 ] ], @@ -430,7 +430,7 @@ "source": [ [ "UI.ts", - 359, + 360, 9 ] ], @@ -460,7 +460,7 @@ "source": [ [ "UI.ts", - 456, + 457, 8 ] ], @@ -490,7 +490,7 @@ "source": [ [ "UI.ts", - 476, + 477, 8 ] ], @@ -520,7 +520,7 @@ "source": [ [ "UI.ts", - 380, + 381, 9 ] ],