Permalink
Fetching contributors…
Cannot retrieve contributors at this time
7 lines (7 sloc) 87.7 KB
/*!
* pts.js 0.5.1 (minified es6) - Copyright © 2017-2018 William Ngan and contributors.
* Licensed under Apache 2.0 License.
* See https://github.com/williamngan/pts for details.
*/
(function(e,t){'object'==typeof exports&&'object'==typeof module?module.exports=t():'function'==typeof define&&define.amd?define([],t):'object'==typeof exports?exports.Pts=t():e.Pts=t()})('undefined'==typeof self?this:self,function(){return function(e){function t(i){if(n[i])return n[i].exports;var o=n[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,i){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:i})},t.n=function(e){var n=e&&e.__esModule?function(){return e['default']}:function(){return e};return t.d(n,'a',n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p='',t(t.s=0)}([function(e,t){(function(t,n){e.exports=n()})('undefined'==typeof self?this:self,function(){var e=Math.pow,n=Math.sqrt,o=Math.PI,t=Number.MIN_VALUE,i=Number.MAX_VALUE,a=Math.floor,r=Math.atan2,u=Math.max,l=Math.sin,s=Math.cos,_=Math.min,d=Math.abs;return function(e){function t(i){if(n[i])return n[i].exports;var o=n[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,i){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:i})},t.n=function(e){var n=e&&e.__esModule?function(){return e['default']}:function(){return e};return t.d(n,'a',n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p='',t(t.s=10)}([function(e,t,n){'use strict';Object.defineProperty(t,'__esModule',{value:!0});const i=n(1),o=n(3),c=n(4);t.PtBaseArray=Float32Array;class h extends t.PtBaseArray{constructor(...e){1===e.length&&'number'==typeof e[0]?super(e[0]):super(0<e.length?i.Util.getArgs(e):[0,0])}static make(e,n=0,i=!1){let o=new t.PtBaseArray(e);if(n&&o.fill(n),i)for(let e=0,t=o.length;e<t;e++)o[e]*=Math.random();return new h(o)}get id(){return this._id}set id(e){this._id=e}get x(){return this[0]}set x(e){this[0]=e}get y(){return this[1]}set y(e){this[1]=e}get z(){return this[2]}set z(e){this[2]=e}get w(){return this[3]}set w(e){this[3]=e}clone(){return new h(this)}equals(e,t=1e-6){for(let n=0,i=this.length;n<i;n++)if(d(this[n]-e[n])>t)return!1;return!0}to(...e){let t=i.Util.getArgs(e);for(let n=0,i=_(this.length,t.length);n<i;n++)this[n]=t[n];return this}$to(...e){return this.clone().to(...e)}toAngle(e,t,n=!1){let i=t==void 0?this.magnitude():t,o=[s(e)*i,l(e)*i];return n?this.add(o):this.to(o)}op(e){let t=this;return(...n)=>e(t,...n)}ops(e){let t=[];for(let n=0,i=e.length;n<i;n++)t.push(this.op(e[n]));return t}$take(e){let t=[];for(let n=0,i=e.length;n<i;n++)t.push(this[e[n]]||0);return new h(t)}$concat(...e){return new h(this.toArray().concat(i.Util.getArgs(e)))}add(...e){return 1===e.length&&'number'==typeof e[0]?c.Vec.add(this,e[0]):c.Vec.add(this,i.Util.getArgs(e)),this}$add(...e){return this.clone().add(...e)}subtract(...e){return 1===e.length&&'number'==typeof e[0]?c.Vec.subtract(this,e[0]):c.Vec.subtract(this,i.Util.getArgs(e)),this}$subtract(...e){return this.clone().subtract(...e)}multiply(...e){return 1===e.length&&'number'==typeof e[0]?c.Vec.multiply(this,e[0]):c.Vec.multiply(this,i.Util.getArgs(e)),this}$multiply(...e){return this.clone().multiply(...e)}divide(...e){return 1===e.length&&'number'==typeof e[0]?c.Vec.divide(this,e[0]):c.Vec.divide(this,i.Util.getArgs(e)),this}$divide(...e){return this.clone().divide(...e)}magnitudeSq(){return c.Vec.dot(this,this)}magnitude(){return c.Vec.magnitude(this)}unit(e=void 0){return c.Vec.unit(this,e),this}$unit(e=void 0){return this.clone().unit(e)}dot(...e){return c.Vec.dot(this,i.Util.getArgs(e))}$cross2D(...e){return c.Vec.cross2D(this,i.Util.getArgs(e))}$cross(...e){return c.Vec.cross(this,i.Util.getArgs(e))}$project(...e){return this.$multiply(this.dot(...e)/this.magnitudeSq())}projectScalar(...e){return this.dot(...e)/this.magnitude()}abs(){return c.Vec.abs(this),this}$abs(){return this.clone().abs()}floor(){return c.Vec.floor(this),this}$floor(){return this.clone().floor()}ceil(){return c.Vec.ceil(this),this}$ceil(){return this.clone().ceil()}round(){return c.Vec.round(this),this}$round(){return this.clone().round()}minValue(){return c.Vec.min(this)}maxValue(){return c.Vec.max(this)}$min(...e){let t=i.Util.getArgs(e),n=this.clone();for(let o=0,i=_(this.length,t.length);o<i;o++)n[o]=_(this[o],t[o]);return n}$max(...e){let t=i.Util.getArgs(e),n=this.clone();for(let o=0,i=_(this.length,t.length);o<i;o++)n[o]=u(this[o],t[o]);return n}angle(e=i.Const.xy){return r(this[e[1]],this[e[0]])}angleBetween(e,t=i.Const.xy){return o.Geom.boundRadian(this.angle(t))-o.Geom.boundRadian(e.angle(t))}scale(e,t){return o.Geom.scale(this,e,t||h.make(this.length,0)),this}rotate2D(e,t,n){return o.Geom.rotate2D(this,e,t||h.make(this.length,0),n),this}shear2D(e,t,n){return o.Geom.shear2D(this,e,t||h.make(this.length,0),n),this}reflect2D(e,t){return o.Geom.reflect2D(this,e,t),this}toString(){return`Pt(${this.join(', ')})`}toArray(){return[].slice.call(this)}}t.Pt=h;class p extends Array{constructor(...e){super(...e)}get id(){return this._id}set id(e){this._id=e}get p1(){return this[0]}get p2(){return this[1]}get p3(){return this[2]}get p4(){return this[3]}get q1(){return this[this.length-1]}get q2(){return this[this.length-2]}get q3(){return this[this.length-3]}get q4(){return this[this.length-4]}clone(){let e=new p;for(let t=0,n=this.length;t<n;t++)e.push(this[t].clone());return e}static fromArray(e){let t=new p;for(let n,o=0,i=e.length;o<i;o++)n=e[o]instanceof h?e[o]:new h(e[o]),t.push(n);return t}static fromPtArray(e){return p.from(e)}split(e,t,n=!1){let o=i.Util.split(this,e,t,n);return o}insert(e,t=0){return p.prototype.splice.apply(this,[t,0,...e]),this}remove(e=0,t=1){let n=0>e?[-1*e-1,t]:[e,t];return p.prototype.splice.apply(this,n)}segments(e=2,t=1,n=!1){return this.split(e,t,n)}lines(){return this.segments(2,1)}centroid(){return o.Geom.centroid(this)}boundingBox(){return o.Geom.boundingBox(this)}anchorTo(e=0){o.Geom.anchor(this,e,'to')}anchorFrom(e=0){o.Geom.anchor(this,e,'from')}op(e){let t=this;return(...n)=>e(t,...n)}ops(e){let t=[];for(let n=0,i=e.length;n<i;n++)t.push(this.op(e[n]));return t}interpolate(e){e=o.Num.clamp(e,0,1);let t=this.length-1,n=1/(this.length-1),i=a(e/n);return o.Geom.interpolate(this[i],this[_(this.length-1,i+1)],(e-i*n)*t)}moveBy(...e){return this.add(...e)}moveTo(...e){let t=new h(i.Util.getArgs(e)).subtract(this[0]);return this.moveBy(t),this}scale(e,t){for(let n=0,i=this.length;n<i;n++)o.Geom.scale(this[n],e,t||this[0]);return this}rotate2D(e,t,n){for(let r=0,i=this.length;r<i;r++)o.Geom.rotate2D(this[r],e,t||this[0],n);return this}shear2D(e,t,n){for(let r=0,i=this.length;r<i;r++)o.Geom.shear2D(this[r],e,t||this[0],n);return this}reflect2D(e,t){for(let n=0,i=this.length;n<i;n++)o.Geom.reflect2D(this[n],e,t);return this}sortByDimension(e,t=!1){return this.sort((n,i)=>t?i[e]-n[e]:n[e]-i[e])}forEachPt(e,...t){if(!this[0][e])return i.Util.warn(`${e} is not a function of Pt`),this;for(let n=0,i=this.length;n<i;n++)this[n]=this[n][e](...t);return this}add(...e){return this.forEachPt('add',...e)}subtract(...e){return this.forEachPt('subtract',...e)}multiply(...e){return this.forEachPt('multiply',...e)}divide(...e){return this.forEachPt('divide',...e)}$matrixAdd(e){return c.Mat.add(this,e)}$matrixMultiply(e,t=!1,n=!1){return c.Mat.multiply(this,e,t,n)}zipSlice(e,t=!1){return c.Mat.zipSlice(this,e,t)}$zip(e=void 0,t=!1){return c.Mat.zip(this,e,t)}toString(){return'Group[ '+this.reduce((e,t)=>e+t.toString()+' ','')+' ]'}}t.Group=p;class m extends p{constructor(...e){super(...e),this._center=new h,this._size=new h,this._topLeft=new h,this._bottomRight=new h,this._inited=!1,this.init()}static fromBoundingRect(e){let t=new m(new h(e.left||0,e.top||0),new h(e.right||0,e.bottom||0));return e.width&&e.height&&(t.size=new h(e.width,e.height)),t}static fromGroup(e){if(2>e.length)throw new Error('Cannot create a Bound from a group that has less than 2 Pt');return new m(e[0],e[e.length-1])}init(){if(this.p1&&(this._size=this.p1.clone(),this._inited=!0),this.p1&&this.p2){let e=this.p1,t=this.p2;this.topLeft=e.$min(t),this._bottomRight=e.$max(t),this._updateSize(),this._inited=!0}}clone(){return new m(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 e=this._size.$multiply(.5);this._topLeft=this._center.$subtract(e),this._bottomRight=this._center.$add(e)}get size(){return new h(this._size)}set size(e){this._size=new h(e),this._updatePosFromTop()}get center(){return new h(this._center)}set center(e){this._center=new h(e),this._updatePosFromCenter()}get topLeft(){return new h(this._topLeft)}set topLeft(e){this._topLeft=new h(e),this[0]=this._topLeft,this._updateSize()}get bottomRight(){return new h(this._bottomRight)}set bottomRight(e){this._bottomRight=new h(e),this[1]=this._bottomRight,this._updateSize()}get width(){return 0<this._size.length?this._size.x:0}set width(e){this._size.x=e,this._updatePosFromTop()}get height(){return 1<this._size.length?this._size.y:0}set height(e){this._size.y=e,this._updatePosFromTop()}get depth(){return 2<this._size.length?this._size.z:0}set depth(e){this._size.z=e,this._updatePosFromTop()}get x(){return this.topLeft.x}get y(){return this.topLeft.y}get z(){return this.topLeft.z}get inited(){return this._inited}update(){return this._topLeft=this[0],this._bottomRight=this[1],this._updateSize(),this}}t.Bound=m},function(e,n,r){'use strict';Object.defineProperty(n,'__esModule',{value:!0});const s=r(0);n.Const={xy:'xy',yz:'yz',xz:'xz',xyz:'xyz',horizontal:0,vertical:1,identical:0,right:4,bottom_right:5,bottom:6,bottom_left:7,left:8,top_left:1,top:2,top_right:3,epsilon:1e-4,max:i,min:t,pi:o,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(e){return e&&(l._warnLevel=e),l._warnLevel}static getArgs(e){if(1>e.length)return[];let t=[],n=Array.isArray(e[0])||ArrayBuffer.isView(e[0]);if('number'==typeof e[0])t=Array.prototype.slice.call(e);else if('object'==typeof e[0]&&!n){let n=['x','y','z','w'],o=e[0];for(let e=0;e<n.length&&!(o.length&&e>=o.length||!(n[e]in o));e++)t.push(o[n[e]])}else n&&(t=[].slice.call(e[0]));return t}static warn(e='error',t=void 0){if('error'==l.warnLevel())throw new Error(e);else'warn'==l.warnLevel()&&console.warn(e);return t}static randomInt(e,t=0){return a(Math.random()*e)+t}static split(e,t,n,o=!1){let r=n||t,a=[];for(let s=0;s<e.length;s++)if(!(s*r+t>e.length))a.push(e.slice(s*r,s*r+t));else if(o){let n=e.slice(s*r);n=n.concat(e.slice(0,(s*r+t)%t)),a.push(n)}else break;return a}static flatten(e,t=!0){let n=t?new s.Group:[];return n.concat.apply(n,e)}static combine(e,t,n){let o=[];for(let r=0,i=e.length;r<i;r++)for(let i=0,a=t.length;i<a;i++)o.push(n(e[r],t[i]));return o}static zip(e){let t=[];for(let n,o=0,i=e[0].length;o<i;o++){n=[];for(let t=0;t<e.length;t++)n.push(e[t][o]);t.push(n)}return t}static stepper(e,t=0,n=1,i){let o=t;return function(){return o+=n,o>=e&&(o=t+(o-e)),i&&i(o),o}}static forRange(e,t,n=0,o=1){let r=[];for(let a=n;a<t;a+=o)r[a]=e(a);return r}}l._warnLevel='mute',n.Util=l},function(e,t,r){'use strict';var a=Number.MAX_SAFE_INTEGER;Object.defineProperty(t,'__esModule',{value:!0});const c=r(1),p=r(3),P=r(0),g=r(4);let h=(e,t='expected')=>c.Util.warn('Group\'s length is less than '+t,e),m=(e,t='')=>c.Util.warn(`Index ${t} is out of bound in Group`,e);class f{static fromAngle(e,t,n){let i=new P.Group(new P.Pt(e),new P.Pt(e));return i[1].toAngle(t,n,!0),i}static slope(e,t){return 0==t[0]-e[0]?void 0:(t[1]-e[1])/(t[0]-e[0])}static intercept(e,t){if(0==t[0]-e[0])return;else{let n=(t[1]-e[1])/(t[0]-e[0]),i=e[1]-n*e[0];return{slope:n,yi:i,xi:0==n?void 0:-i/n}}}static sideOfPt2D(e,t){return(e[1][0]-e[0][0])*(t[1]-e[0][1])-(t[0]-e[0][0])*(e[1][1]-e[0][1])}static collinear(e,t,n,i=.01){let o=new P.Pt(0,0,0).to(e).$subtract(t),r=new P.Pt(0,0,0).to(e).$subtract(n);return o.$cross(r).divide(1e3).equals(new P.Pt(0,0,0),i)}static magnitude(e){return 2<=e.length?e[1].$subtract(e[0]).magnitude():0}static magnitudeSq(e){return 2<=e.length?e[1].$subtract(e[0]).magnitudeSq():0}static perpendicularFromPt(e,t,n=!1){if(!e[0].equals(e[1])){let i=e[0].$subtract(e[1]),o=e[1].$subtract(t),r=o.$subtract(i.$project(o));return n?r:r.$add(t)}}static distanceFromPt(e,t){return f.perpendicularFromPt(e,t,!0).magnitude()}static intersectRay2D(e,t){let n=f.intercept(e[0],e[1]),i=f.intercept(t[0],t[1]),o=e[0],r=t[0];if(n==void 0){if(i==void 0)return;let e=-i.slope*(r[0]-o[0])+r[1];return new P.Pt(o[0],e)}if(void 0==i){let e=-n.slope*(o[0]-r[0])+o[1];return new P.Pt(r[0],e)}if(i.slope!=n.slope){let e=(n.slope*o[0]-i.slope*r[0]+r[1]-o[1])/(n.slope-i.slope),t=n.slope*(e-o[0])+o[1];return new P.Pt(e,t)}return n.yi==i.yi?new P.Pt(o[0],o[1]):void 0}static intersectLine2D(e,t){let n=f.intersectRay2D(e,t);return n&&p.Geom.withinBound(n,e[0],e[1])&&p.Geom.withinBound(n,t[0],t[1])?n:void 0}static intersectLineWithRay2D(e,t){let n=f.intersectRay2D(e,t);return n&&p.Geom.withinBound(n,e[0],e[1])?n:void 0}static intersectPolygon2D(e,t,n=!1){let o=n?f.intersectLineWithRay2D:f.intersectLine2D,r=new P.Group;for(let a=0,i=t.length;a<i;a++){let n=a===i-1?0:a+1,s=o([t[a],t[n]],e);s&&r.push(s)}return 0<r.length?r:void 0}static intersectLines2D(e,t,n=!1){let o=new P.Group,r=n?f.intersectLineWithRay2D:f.intersectLine2D;for(let a=0,i=e.length;a<i;a++)for(let n,i=0,s=t.length;i<s;i++)n=r(e[a],t[i]),n&&o.push(n);return o}static intersectGridWithRay2D(e,n){let i=f.intercept(new P.Pt(e[0]).subtract(n),new P.Pt(e[1]).subtract(n)),t=new P.Group;return i&&i.xi&&t.push(new P.Pt(n[0]+i.xi,n[1])),i&&i.yi&&t.push(new P.Pt(n[0],n[1]+i.yi)),t}static intersectGridWithLine2D(e,t){let n=f.intersectGridWithRay2D(e,t),o=new P.Group;for(let r=0,i=n.length;r<i;r++)p.Geom.withinBound(n[r],e[0],e[1])&&o.push(n[r]);return o}static intersectRect2D(e,t){let n=p.Geom.boundingBox(P.Group.fromPtArray(e));return y.hasIntersectRect2D(n,t)?f.intersectLines2D([e],y.sides(t)):new P.Group}static subpoints(e,t){let n=new P.Group;for(let o=1;o<=t;o++)n.push(p.Geom.interpolate(e[0],e[1],o/(t+1)));return n}static crop(e,t,n=0,i=!0){let o=0===n?1:0,r=e[o].$subtract(e[n]);if(0===r[0]||0===t[0])return e[n];if(i){let i=r.unit().multiply(t[1]);return e[n].$add(i)}else{let i=y.fromCenter(e[n],t),o=y.sides(i),a=0;return a=d(r[1]/r[0])>d(t[1]/t[0])?0>r[1]?0:2:0>r[0]?3:1,f.intersectRay2D(o[a],e)}}static marker(e,n,i='arrow',o=!0){let r=o?0:1,a=o?1:0,t=e[r].$subtract(e[a]);if(0===t.magnitudeSq())return new P.Group;t.unit();let s=p.Geom.perpendicular(t).multiply(n[0]).add(e[a]);return'arrow'==i?(s.add(t.$multiply(n[1])),new P.Group(e[a],s[0],s[1])):new P.Group(s[0],s[1])}static toRect(e){return new P.Group(e[0].$min(e[1]),e[0].$max(e[1]))}}t.Line=f;class y{static from(e,t,n){return y.fromTopLeft(e,t,n)}static fromTopLeft(e,t,n){let i='number'==typeof t?[t,n||t]:t;return new P.Group(new P.Pt(e),new P.Pt(e).add(i))}static fromCenter(e,t,n){let i='number'==typeof t?[t/2,(n||t)/2]:new P.Pt(t).divide(2);return new P.Group(new P.Pt(e).subtract(i),new P.Pt(e).add(i))}static toCircle(e,t=!0){return b.fromRect(e,t)}static toSquare(e,t=!1){let n=y.size(e),i=t?n.maxValue().value:n.minValue().value;return y.fromCenter(y.center(e),i,i)}static size(e){return e[0].$max(e[1]).subtract(e[0].$min(e[1]))}static center(e){let t=e[0].$min(e[1]),n=e[0].$max(e[1]);return t.add(n.$subtract(t).divide(2))}static corners(e){let t=e[0].$min(e[1]),n=e[0].$max(e[1]);return new P.Group(t,new P.Pt(n.x,t.y),n,new P.Pt(t.x,n.y))}static sides(e){let[t,n,i,o]=y.corners(e);return[new P.Group(t,n),new P.Group(n,i),new P.Group(i,o),new P.Group(o,t)]}static boundingBox(e){let t=c.Util.flatten(e,!1),n=P.Pt.make(2,Number.MAX_VALUE),o=P.Pt.make(2,Number.MIN_VALUE);for(let r=0,i=t.length;r<i;r++)for(let e=0;2>e;e++)n[e]=_(n[e],t[r][e]),o[e]=u(o[e],t[r][e]);return new P.Group(n,o)}static polygon(e){return y.corners(e)}static quadrants(e,t){let n=y.corners(e),i=t==void 0?y.center(e):new P.Pt(t);return n.map((e)=>new P.Group(e,i).boundingBox())}static halves(e,t=.5,n=!1){let i=e[0].$min(e[1]),o=e[0].$max(e[1]),r=n?p.Num.lerp(i[1],o[1],t):p.Num.lerp(i[0],o[0],t);return n?[new P.Group(i,new P.Pt(o[0],r)),new P.Group(new P.Pt(i[0],r),o)]:[new P.Group(i,new P.Pt(r,o[1])),new P.Group(new P.Pt(r,i[1]),o)]}static withinBound(e,t){return p.Geom.withinBound(t,e[0],e[1])}static hasIntersectRect2D(e,t,n=!1){return n&&(e=p.Geom.boundingBox(e),t=p.Geom.boundingBox(t)),!(e[0][0]>t[1][0]||t[0][0]>e[1][0])&&!(e[0][1]>t[1][1]||t[0][1]>e[1][1])}static intersectRect2D(e,t){return y.hasIntersectRect2D(e,t)?f.intersectLines2D(y.sides(e),y.sides(t)):new P.Group}}t.Rectangle=y;class b{static fromRect(e,t=!1){let i=0,o=i=y.size(e).minValue().value/2;if(t){let t=y.size(e).maxValue().value/2;i=n(o*o+t*t)}else i=o;return new P.Group(y.center(e),new P.Pt(i,i))}static fromCenter(e,t){return new P.Group(new P.Pt(e),new P.Pt(t,t))}static withinBound(e,t,n=0){let i=e[0].$subtract(t);return i.dot(i)+n<e[1].x*e[1].x}static intersectRay2D(e,t){let i=t[0].$subtract(t[1]),o=e[0].$subtract(t[0]),r=i.dot(i),a=o.dot(i),s=o.dot(o)-e[1].x*e[1].x,l=a/r,d=l*l-s/r;if(0>d)return new P.Group;else{let e=n(d),o=t[0].$subtract(i.$multiply(-l+e));if(0==d)return new P.Group(o);let r=t[0].$subtract(i.$multiply(-l-e));return new P.Group(o,r)}}static intersectLine2D(e,t){let n=b.intersectRay2D(e,t),o=new P.Group;if(0<n.length)for(let e=0,i=n.length;e<i;e++)y.withinBound(t,n[e])&&o.push(n[e]);return o}static intersectCircle2D(e,t){let i=t[0].$subtract(e[0]),o=i.magnitudeSq(),r=n(o),a=e[1].x,s=t[1].x,l=a*a;if(r>a+s)return new P.Group;if(r<d(a-s))return new P.Group(e[0].clone());else{let t=(l-s*s+o)/(2*r),a=n(l-t*t),d=i.$multiply(t/r).add(e[0]);return new P.Group(new P.Pt(d.x+a*i.y/r,d.y-a*i.x/r),new P.Pt(d.x-a*i.y/r,d.y+a*i.x/r))}}static intersectRect2D(e,t){let n=y.sides(t),o=[];for(let r,a=0,i=n.length;a<i;a++)r=b.intersectLine2D(e,n[a]),0<r.length&&o.push(r);return c.Util.flatten(o)}static toRect(e,t=!1){let i=e[1][0];if(t){let t=n(i*i)/2;return new P.Group(e[0].$subtract(t),e[0].$add(t))}return new P.Group(e[0].$subtract(i),e[0].$add(i))}static toTriangle(e,t=!0){if(t){let t=-o/2,n=new P.Group;for(let r=0;3>r;r++)n.push(e[0].clone().toAngle(t,e[1][0],!0)),t+=2*o/3;return n}return x.fromCenter(e[0],e[1][0])}}t.Circle=b;class x{static fromRect(e){let t=e[0].$add(e[1]).divide(2);t.y=e[0][1];let n=e[1].clone();return n.x=e[0][0],new P.Group(t,e[1].clone(),n)}static fromCircle(e){return b.toTriangle(e,!0)}static fromCenter(e,t){return x.fromCircle(b.fromCenter(e,t))}static medial(e){return 3>e.length?h(new P.Group,3):v.midpoints(e,!0)}static oppositeSide(e,t){return 3>e.length?h(new P.Group,3):0===t?P.Group.fromPtArray([e[1],e[2]]):1===t?P.Group.fromPtArray([e[0],e[2]]):P.Group.fromPtArray([e[0],e[1]])}static altitude(e,t){let n=x.oppositeSide(e,t);return 1<n.length?new P.Group(e[t],f.perpendicularFromPt(n,e[t])):new P.Group}static orthocenter(e){if(3>e.length)return h(void 0,3);let t=x.altitude(e,0),n=x.altitude(e,1);return f.intersectRay2D(t,n)}static incenter(e){if(3>e.length)return h(void 0,3);let t=v.bisector(e,0).add(e[0]),n=v.bisector(e,1).add(e[1]);return f.intersectRay2D(new P.Group(e[0],t),new P.Group(e[1],n))}static incircle(e,t){let n=t?t:x.incenter(e),i=v.area(e),o=v.perimeter(e,!0),a=2*i/o.total;return b.fromCenter(n,a)}static circumcenter(e){let t=x.medial(e),n=[t[0],p.Geom.perpendicular(e[0].$subtract(t[0])).p1.$add(t[0])],i=[t[1],p.Geom.perpendicular(e[1].$subtract(t[1])).p1.$add(t[1])];return f.intersectRay2D(n,i)}static circumcircle(e,t){let n=t?t:x.circumcenter(e),i=e[0].$subtract(n).magnitude();return b.fromCenter(n,i)}}t.Triangle=x;class v{static centroid(e){return p.Geom.centroid(e)}static rectangle(e,t,n){return y.corners(y.fromCenter(e,t,n))}static fromCenter(e,t,n){let r=new P.Group;for(let a,d=0;d<n;d++)a=2*o*d/n,r.push(new P.Pt(s(a)*t,l(a)*t).add(e));return r}static lineAt(e,t){if(0>t||t>=e.length)throw new Error('index out of the Polygon\'s range');return new P.Group(e[t],t===e.length-1?e[0]:e[t+1])}static lines(e,t=!0){if(2>e.length)return h(new P.Group,2);let n=c.Util.split(e,2,1);return t&&n.push(new P.Group(e[e.length-1],e[0])),n.map((e)=>e)}static midpoints(e,n=!1,i=.5){if(2>e.length)return h(new P.Group,2);let t=v.lines(e,n),o=t.map((e)=>p.Geom.interpolate(e[0],e[1],i));return o}static adjacentSides(e,t,n=!1){if(2>e.length)return h(new P.Group,2);if(0>t||t>=e.length)return m(new P.Group,t);let i=[],o=t-1;n&&0>o&&(o=e.length-1),0<=o&&i.push(new P.Group(e[t],e[o]));let r=t+1;return n&&r>e.length-1&&(r=0),r<=e.length-1&&i.push(new P.Group(e[t],e[r])),i}static bisector(e,t){let n=v.adjacentSides(e,t,!0);if(2<=n.length){let e=n[0][1].$subtract(n[0][0]).unit(),t=n[1][1].$subtract(n[1][0]).unit();return e.add(t).divide(2)}}static perimeter(e,t=!1){if(2>e.length)return h(new P.Group,2);let n=v.lines(e,t),o=0,r=P.Pt.make(n.length,0);for(let a,s=0,i=n.length;s<i;s++)a=f.magnitude(n[s]),o+=a,r[s]=a;return{total:o,segments:r}}static area(e){if(3>e.length)return h(new P.Group,3);let t=(e,t)=>e[0]*t[1]-e[1]*t[0],n=0;for(let o=0,i=e.length;o<i;o++)n+=o<e.length-1?t(e[o],e[o+1]):t(e[o],e[0]);return d(n/2)}static convexHull(e,t=!1){if(3>e.length)return h(new P.Group,3);t||(e=e.slice(),e.sort((e,t)=>e[0]-t[0]));let n=(e,t,n)=>0<(t[0]-e[0])*(n[1]-e[1])-(n[0]-e[0])*(t[1]-e[1]),o=[],r=e.length-2,a=r+3;o[r]=e[2],o[a]=e[2],n(e[0],e[1],e[2])?(o[r+1]=e[0],o[r+2]=e[1]):(o[r+1]=e[1],o[r+2]=e[0]);for(let s,l=3,i=e.length;l<i;l++)if(s=e[l],!(n(o[r],o[r+1],s)&&n(o[a-1],o[a],s))){for(;!n(o[r],o[r+1],s);)r+=1;for(r-=1,o[r]=s;!n(o[a-1],o[a],s);)a-=1;a+=1,o[a]=s}let i=new P.Group;for(let n=0;n<a-r;n++)i.push(o[r+n]);return i}static network(e,t=0){let n=[];for(let o=0,i=e.length;o<i;o++)o!=t&&n.push(new P.Group(e[t],e[o]));return n}static nearestPt(e,t){let n=i,o=-1;for(let r,a=0,i=e.length;a<i;a++)r=e[a].$subtract(t).magnitudeSq(),r<n&&(n=r,o=a);return o}static projectAxis(e,t){let i=t.dot(e[0]),o=new P.Pt(i,i);for(let r=1,n=e.length;r<n;r++)i=t.dot(e[r]),o=new P.Pt(_(i,o[0]),u(i,o[1]));return o}static _axisOverlap(e,t,n){let i=v.projectAxis(e,n),o=v.projectAxis(t,n);return i[0]<o[0]?o[0]-i[1]:i[0]-o[1]}static hasIntersectPoint(e,t){let n=!1;for(let o,r=0,i=e.length;r<i;r++)o=v.lineAt(e,r),o[0][1]>t[1]!=o[1][1]>t[1]&&t[0]<(o[1][0]-o[0][0])*(t[1]-o[0][1])/(o[1][1]-o[0][1])+o[0][0]&&(n=!n);return n}static hasIntersectCircle(e,t){let n={which:-1,dist:0,normal:null,edge:null,vertex:null},o=t[0],s=t[1][0],r=a;for(let a=0,i=e.length;a<i;a++){let i=v.lineAt(e,a),l=new P.Pt(i[0].y-i[1].y,i[1].x-i[0].x).unit(),c=new P.Group(o.$add(l.$multiply(s)),o.$subtract(l.$multiply(s))),u=v._axisOverlap(e,c,l);if(0<u)return null;if(d(u)<r){let e=y.withinBound(i,f.perpendicularFromPt(i,o))||0<b.intersectLine2D(t,i).length;e&&(n.edge=i,n.normal=l,r=d(u),n.which=a)}}if(!n.edge)return null;let i=o.$subtract(v.centroid(e)).dot(n.normal);return 0>i&&n.normal.multiply(-1),n.dist=r,n.vertex=o,n}static hasIntersectPolygon(e,t){let n={which:-1,dist:0,normal:new P.Pt,edge:new P.Group,vertex:new P.Pt},o=a;for(let r=0,i=e.length+t.length;r<i;r++){let i=r<e.length?v.lineAt(e,r):v.lineAt(t,r-e.length),a=new P.Pt(i[0].y-i[1].y,i[1].x-i[0].x).unit(),s=v._axisOverlap(e,t,a);if(0<s)return null;d(s)<o&&(n.edge=i,n.normal=a,o=d(s),n.which=r<e.length?0:1)}n.dist=o;let r=0===n.which?t:e,i=0===n.which?e:t,s=v.centroid(r),l=v.centroid(i),c=s.$subtract(l).dot(n.normal);0>c&&n.normal.multiply(-1);let u=a;for(let o,a=0,i=r.length;a<i;a++)o=n.normal.dot(r[a].$subtract(l)),o<u&&(u=o,n.vertex=r[a]);return n}static intersectPolygon2D(e,t){let n=v.lines(e),o=[];for(let r,a=0,i=n.length;a<i;a++)r=f.intersectPolygon2D(n[a],t,!1),r&&o.push(r);return c.Util.flatten(o,!0)}static toRects(e){let t=e.map((e)=>p.Geom.boundingBox(e)),n=c.Util.flatten(t,!1);return t.unshift(p.Geom.boundingBox(n)),t}}t.Polygon=v;class G{static getSteps(e){let n=new P.Group;for(let o,t=0;t<=e;t++)o=t/e,n.push(new P.Pt(o*o*o,o*o,o,1));return n}static controlPoints(e,t=0,n=!1){if(t>e.length-1)return new P.Group;let i=(t)=>t<e.length-1?t:e.length-1,o=e[t];return t=n?t:t+1,new P.Group(o,e[i(t++)],e[i(t++)],e[i(t++)])}static _calcPt(e,t){let n=e.reduce((e,n,o)=>e+n.x*t[o],0),i=e.reduce((e,n,o)=>e+n.y*t[o],0);if(2<e[0].length){let o=e.reduce((e,n,o)=>e+n.z*t[o],0);return new P.Pt(n,i,o)}return new P.Pt(n,i)}static catmullRom(e,t=10){if(2>e.length)return new P.Group;let n=new P.Group,o=G.getSteps(t),r=G.controlPoints(e,0,!0);for(let a=0;a<=t;a++)n.push(G.catmullRomStep(o[a],r));for(let i=0;i<e.length-2;){let r=G.controlPoints(e,i);if(0<r.length){for(let e=0;e<=t;e++)n.push(G.catmullRomStep(o[e],r));i++}}return n}static catmullRomStep(e,t){let n=new P.Group(new P.Pt(-.5,1,-.5,0),new P.Pt(1.5,-2.5,0,1),new P.Pt(-1.5,2,.5,0),new P.Pt(.5,-.5,0,0));return G._calcPt(t,g.Mat.multiply([e],n,!0)[0])}static cardinal(e,t=10,n=.5){if(2>e.length)return new P.Group;let o=new P.Group,r=G.getSteps(t),a=G.controlPoints(e,0,!0);for(let s=0;s<=t;s++)o.push(G.cardinalStep(r[s],a,n));for(let i=0;i<e.length-2;){let a=G.controlPoints(e,i);if(0<a.length){for(let e=0;e<=t;e++)o.push(G.cardinalStep(r[e],a,n));i++}}return o}static cardinalStep(e,t,n=.5){let i=new P.Group(new P.Pt(-1,2,-1,0),new P.Pt(-1,1,0,0),new P.Pt(1,-2,1,0),new P.Pt(1,-1,0,0)),o=g.Mat.multiply([e],i,!0)[0].multiply(n),r=2*e[0]-3*e[1]+1,a=-2*e[0]+3*e[1],s=G._calcPt(t,o);return s.x+=r*t[1].x+a*t[2].x,s.y+=r*t[1].y+a*t[2].y,2<s.length&&(s.z+=r*t[1].z+a*t[2].z),s}static bezier(e,t=10){if(4>e.length)return new P.Group;let n=new P.Group,o=G.getSteps(t),i=0;for(;i<e.length-3;){let r=G.controlPoints(e,i);if(0<r.length){for(let e=0;e<=t;e++)n.push(G.bezierStep(o[e],r));i+=3}}return n}static bezierStep(e,t){let n=new P.Group(new P.Pt(-1,3,-3,1),new P.Pt(3,-6,3,0),new P.Pt(-3,3,0,0),new P.Pt(1,0,0,0));return G._calcPt(t,g.Mat.multiply([e],n,!0)[0])}static bspline(e,t=10,n=1){if(2>e.length)return new P.Group;let o=new P.Group,r=G.getSteps(t),i=0;for(;i<e.length-3;){let a=G.controlPoints(e,i);if(0<a.length){if(1!==n)for(let e=0;e<=t;e++)o.push(G.bsplineTensionStep(r[e],a,n));else for(let e=0;e<=t;e++)o.push(G.bsplineStep(r[e],a));i++}}return o}static bsplineStep(e,t){let n=new P.Group(new P.Pt(-.16666666666666666,.5,-.5,.16666666666666666),new P.Pt(.5,-1,0,.6666666666666666),new P.Pt(-.5,.5,.5,.16666666666666666),new P.Pt(.16666666666666666,0,0,0));return G._calcPt(t,g.Mat.multiply([e],n,!0)[0])}static bsplineTensionStep(e,t,n=1){let i=new P.Group(new P.Pt(-.16666666666666666,.5,-.5,.16666666666666666),new P.Pt(-1.5,2,0,-.3333333333333333),new P.Pt(1.5,-2.5,.5,.16666666666666666),new P.Pt(.16666666666666666,0,0,0)),o=g.Mat.multiply([e],i,!0)[0].multiply(n),r=2*e[0]-3*e[1]+1,a=-2*e[0]+3*e[1],s=G._calcPt(t,o);return s.x+=r*t[1].x+a*t[2].x,s.y+=r*t[1].y+a*t[2].y,2<s.length&&(s.z+=r*t[1].z+a*t[2].z),s}}t.Curve=G},function(t,i,r){'use strict';var h=Math.exp;Object.defineProperty(i,'__esModule',{value:!0});const g=r(1),p=r(2),m=r(0),f=r(4);class c{static equals(e,t,n=1e-5){return d(e-t)<n}static lerp(e,n,i){return(1-i)*e+i*n}static clamp(e,t,n){return u(t,_(n,e))}static boundValue(e,t,n){let i=d(n-t),o=e%i;return o>n?o-=i:o<t&&(o+=i),o}static within(e,t,n){return e>=_(t,n)&&e<=u(t,n)}static randomRange(e,t=0){let n=e>t?e-t:t-e;return e+Math.random()*n}static normalizeValue(e,t,n){let i=_(t,n),o=u(t,n);return(e-i)/(o-i)}static sum(e){let t=new m.Pt(e[0]);for(let n=1,i=e.length;n<i;n++)f.Vec.add(t,e[n]);return t}static average(e){return c.sum(e).divide(e.length)}static cycle(e){return(l(2*o*e)+1)/2}static mapToRange(e,t,n,i,o){if(t==n)throw new Error('[currMin, currMax] must define a range that is not zero');let r=_(i,o),a=u(i,o);return c.normalizeValue(e,t,n)*(a-r)+r}}i.Num=c;class y{static boundAngle(e){return c.boundValue(e,0,360)}static boundRadian(e){return c.boundValue(e,0,g.Const.two_pi)}static toRadian(e){return e*g.Const.deg_to_rad}static toDegree(e){return e*g.Const.rad_to_deg}static boundingBox(e){let t=e.reduce((e,t)=>e.$min(t)),n=e.reduce((e,t)=>e.$max(t));return new m.Group(t,n)}static centroid(e){return c.average(e)}static anchor(e,t=0,n='to'){let o='to'==n?'subtract':'add';for(let r=0,i=e.length;r<i;r++)'number'==typeof t?t!==r&&e[r][o](e[t]):e[r][o](t)}static interpolate(e,n,o=.5){let t=_(e.length,n.length),r=m.Pt.make(t);for(let a=0;a<t;a++)r[a]=e[a]*(1-o)+n[a]*o;return r}static perpendicular(e,t=g.Const.xy){let n=t[1],i=t[0],o=new m.Pt(e),r=new m.Pt(o);r[i]=-o[n],r[n]=o[i];let a=new m.Pt(o);return a[i]=o[n],a[n]=-o[i],new m.Group(r,a)}static isPerpendicular(e,t){return 0===new m.Pt(e).dot(t)}static withinBound(e,t,n){for(let o=0,i=_(e.length,t.length,n.length);o<i;o++)if(!c.within(e[o],t[o],n[o]))return!1;return!0}static sortEdges(e){let t=y.boundingBox(e),n=t[1].add(t[0]).divide(2);return e.sort((e,t)=>{if(2>e.length||2>t.length)throw new Error('Pt dimension cannot be less than 2');let i=e.$subtract(n),o=t.$subtract(n);if(0<=i[0]&&0>o[0])return 1;if(0>i[0]&&0<=o[0])return-1;if(0==i[0]&&0==o[0])return 0<=i[1]||0<=o[1]?i[1]>o[1]?1:-1:o[1]>i[1]?1:-1;let r=i.$cross2D(o);return 0>r?1:0<r?-1:i[0]*i[0]+i[1]*i[1]>o[0]*o[0]+o[1]*o[1]?1:-1})}static scale(e,t,n){let o=Array.isArray(e)?e:[e],i='number'==typeof t?m.Pt.make(o[0].length,t):t;n||(n=m.Pt.make(o[0].length,0));for(let r,a=0,s=o.length;a<s;a++){r=o[a];for(let e=0,t=r.length;e<t;e++)r[e]=n&&n[e]?n[e]+(r[e]-n[e])*i[e]:r[e]*i[e]}return y}static rotate2D(e,t,n,o){let r=Array.isArray(e)?e:[e],a=n?f.Mat.rotateAt2DMatrix:f.Mat.rotate2DMatrix;n||(n=m.Pt.make(r[0].length,0));let d=s(t),c=l(t);for(let s,l=0,i=r.length;l<i;l++)s=o?r[l].$take(o):r[l],s.to(f.Mat.transform2D(s,a(d,c,n)));return y}static shear2D(e,t,n,o){var i=Math.tan;let r=Array.isArray(e)?e:[e],a='number'==typeof t?[t,t]:t;n||(n=m.Pt.make(r[0].length,0));let s=n?f.Mat.shearAt2DMatrix:f.Mat.shear2DMatrix,l=i(a[0]),d=i(a[1]);for(let a,c=0,i=r.length;c<i;c++)a=o?r[c].$take(o):r[c],a.to(f.Mat.transform2D(a,s(l,d,n)));return y}static reflect2D(e,t,n){let o=Array.isArray(e)?e:[e],r=f.Mat.reflectAt2DMatrix(t[0],t[1]);for(let a,s=0,i=o.length;s<i;s++)a=n?o[s].$take(n):o[s],a.to(f.Mat.transform2D(a,r));return y}static cosTable(){let e=new Float64Array(360);for(let t=0;360>t;t++)e[t]=s(t*o/180);return{table:e,cos:(t)=>e[a(y.boundAngle(y.toDegree(t)))]}}static sinTable(){let e=new Float64Array(360);for(let t=0;360>t;t++)e[t]=l(t*o/180);return{table:e,sin:(t)=>e[a(y.boundAngle(y.toDegree(t)))]}}}i.Geom=y;class b{static linear(e,t=1){return t*e}static quadraticIn(e,t=1){return t*e*e}static quadraticOut(e,t=1){return-t*e*(e-2)}static quadraticInOut(e,t=1){let n=2*e;return .5>e?4*(t/2*e*e):-t/2*((n-1)*(n-3)-1)}static cubicIn(e,t=1){return t*e*e*e}static cubicOut(e,t=1){let n=e-1;return t*(n*n*n+1)}static cubicInOut(e,t=1){let n=2*e;return .5>e?t/2*n*n*n:t/2*((n-2)*(n-2)*(n-2)+2)}static exponentialIn(n,t=1,i=.25){return t*e(n,1/i)}static exponentialOut(n,t=1,i=.25){return t*e(n,i)}static sineIn(e,t=1){return-t*s(e*g.Const.half_pi)+t}static sineOut(e,t=1){return t*l(e*g.Const.half_pi)}static sineInOut(e,t=1){return-t/2*(s(o*e)-1)}static cosineApprox(e,t=1){let n=e*e,i=n*n;return t*(4*(i*n)/9-17*i/9+22*n/9)}static circularIn(e,t=1){return-t*(n(1-e*e)-1)}static circularOut(e,t=1){let i=e-1;return t*n(1-i*i)}static circularInOut(e,t=1){let i=2*e;return .5>e?-t/2*(n(1-i*i)-1):t/2*(n(1-(i-2)*(i-2))+1)}static elasticIn(n,t=1,i=.7){let o=n-1,r=1.5707963267948966*(i/g.Const.two_pi);return t*(-e(2,10*o)*l((o-r)*g.Const.two_pi/i))}static elasticOut(n,t=1,i=.7){let o=1.5707963267948966*(i/g.Const.two_pi);return t*(e(2,-10*n)*l((n-o)*g.Const.two_pi/i))+t}static elasticInOut(n,t=1,i=.6){let o=2*n,r=1.5707963267948966*(i/g.Const.two_pi);return .5>n?(o-=1,t*(-.5*(e(2,10*o)*l((o-r)*g.Const.two_pi/i)))):(o-=1,t*(.5*(e(2,-10*o)*l((o-r)*g.Const.two_pi/i)))+t)}static bounceIn(e,t=1){return t-b.bounceOut(1-e,t)}static bounceOut(e,t=1){return e<1/2.75?t*(7.5625*e*e):e<2/2.75?(e-=1.5/2.75,t*(7.5625*e*e+.75)):e<2.5/2.75?(e-=2.25/2.75,t*(7.5625*e*e+.9375)):(e-=2.625/2.75,t*(7.5625*e*e+.984375))}static bounceInOut(e,t=1){return .5>e?b.bounceIn(2*e,t)/2:b.bounceOut(2*e-1,t)/2+t/2}static sigmoid(e,t=1,n=10){return t/(1+h(-(n*(e-.5))))}static logSigmoid(e,t=1,n=.7){n=u(g.Const.epsilon,_(1-g.Const.epsilon,n)),n=1/(1-n);let i=1/(1+h(-2*((e-.5)*n))),o=1/(1+h(n)),r=1/(1+h(-n));return t*(i-o)/(r-o)}static seat(n,t=1,i=.5){return .5>n?t*e(2*n,1-i)/2:t*(1-e(2*(1-n),1-i)/2)}static quadraticBezier(e,t=1,i=[.05,.95]){let o='number'==typeof i?i:i[0],r='number'==typeof i?.5:i[1],a=1-2*o;0===a&&(a=g.Const.epsilon);let s=(n(o*o+a*e)-o)/a;return t*((1-2*r)*(s*s)+2*r*s)}static cubicBezier(e,t=1,n=[.1,.7],i=[.9,.2]){let o=new m.Group(new m.Pt(0,0),new m.Pt(n),new m.Pt(i),new m.Pt(1,1));return t*p.Curve.bezierStep(new m.Pt(e*e*e,e*e,e,1),p.Curve.controlPoints(o)).y}static quadraticTarget(e,t=1,n=[.2,.35]){let i=_(1-g.Const.epsilon,u(g.Const.epsilon,n[0])),o=_(1,u(0,n[1])),r=(1-o)/(1-i)-o/i;return t*_(1,u(0,r*(e*e)-(r*(i*i)-o)/i*e))}static cliff(e,t=1,n=.5){return e>n?t:0}static step(e,n,i,t,...o){let r=1/n,s=a(i/r)*r;return e(s,t,...o)}}i.Shaping=b;class x{constructor(e){this._dims=0,this._source=m.Group.fromPtArray(e),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 e=this._source[0].length;this._dims=e;let t=new m.Pt(e),n=new m.Pt(e),o=new m.Pt(e);for(let r=0;r<e;r++){t[r]=g.Const.min,n[r]=g.Const.max,o[r]=0;let e=this._source.zipSlice(r);for(let i=0,a=e.length;i<a;i++)t[r]=u(t[r],e[i]),n[r]=_(n[r],e[i]),o[r]=t[r]-n[r]}return this._max=t,this._min=n,this._mag=o,this}}mapTo(e,t,i){let o=new m.Group;for(let r=0,n=this._source.length;r<n;r++){let a=this._source[r],s=new m.Pt(this._dims);for(let n=0;n<this._dims;n++)s[n]=i&&i[n]?a[n]:c.mapToRange(a[n],this._min[n],this._max[n],e,t);o.push(s)}return o}append(e,t=!0){if(e[0].length!==this._dims)throw new Error(`Dimensions don't match. ${this._dims} dimensions in Range and ${e[0].length} provided in parameter. `);return this._source=this._source.concat(e),t&&this.calc(),this}ticks(e){let t=new m.Group;for(let n,o=0;o<=e;o++){n=new m.Pt(this._dims);for(let t=0,i=this._max.length;t<i;t++)n[t]=c.lerp(this._min[t],this._max[t],o/e);t.push(n)}return t}}i.Range=x},function(e,o,r){'use strict';Object.defineProperty(o,'__esModule',{value:!0});const d=r(0),a=r(2);class c{static add(e,t){if('number'==typeof t)for(let n=0,i=e.length;n<i;n++)e[n]+=t;else for(let n=0,i=e.length;n<i;n++)e[n]+=t[n]||0;return e}static subtract(e,t){if('number'==typeof t)for(let n=0,i=e.length;n<i;n++)e[n]-=t;else for(let n=0,i=e.length;n<i;n++)e[n]-=t[n]||0;return e}static multiply(e,t){if('number'==typeof t)for(let n=0,i=e.length;n<i;n++)e[n]*=t;else{if(e.length!=t.length)throw new Error(`Cannot do element-wise multiply since the array lengths don't match: ${e.toString()} multiply-with ${t.toString()}`);for(let n=0,i=e.length;n<i;n++)e[n]*=t[n]}return e}static divide(e,t){if('number'==typeof t){if(0===t)throw new Error('Cannot divide by zero');for(let n=0,i=e.length;n<i;n++)e[n]/=t}else{if(e.length!=t.length)throw new Error(`Cannot do element-wise divide since the array lengths don't match. ${e.toString()} divide-by ${t.toString()}`);for(let n=0,i=e.length;n<i;n++)e[n]/=t[n]}return e}static dot(e,t){if(e.length!=t.length)throw new Error('Array lengths don\'t match');let n=0;for(let o=0,i=e.length;o<i;o++)n+=e[o]*t[o];return n}static cross2D(e,t){return e[0]*t[1]-e[1]*t[0]}static cross(e,t){return new d.Pt(e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0])}static magnitude(e){return n(c.dot(e,e))}static unit(e,t=void 0){let n=t===void 0?c.magnitude(e):t;if(0===n)throw new Error('Cannot calculate unit vector because magnitude is 0');return c.divide(e,n)}static abs(e){return c.map(e,Math.abs)}static floor(e){return c.map(e,Math.floor)}static ceil(e){return c.map(e,Math.ceil)}static round(e){return c.map(e,Math.round)}static max(e){let n=t,o=0;for(let t=0,i=e.length;t<i;t++)n=u(n,e[t]),n===e[t]&&(o=t);return{value:n,index:o}}static min(e){let t=i,n=0;for(let o=0,i=e.length;o<i;o++)t=_(t,e[o]),t===e[o]&&(n=o);return{value:t,index:n}}static sum(e){let t=0;for(let n=0,i=e.length;n<i;n++)t+=e[n];return t}static map(e,t){for(let n=0,i=e.length;n<i;n++)e[n]=t(e[n],n,e);return e}}o.Vec=c;class p{static add(e,t){if('number'!=typeof t){if(e[0].length!=t[0].length)throw new Error('Cannot add matrix if rows\' and columns\' size don\'t match.');if(e.length!=t.length)throw new Error('Cannot add matrix if rows\' and columns\' size don\'t match.')}let n=new d.Group;for(let o=0,i=e.length;o<i;o++)n.push(e[o].$add('number'==typeof t?t:t[o]));return n}static multiply(e,t,n=!1,i=!1){let o=new d.Group;if(!('number'!=typeof t))for(let n=0,i=e.length;n<i;n++)o.push(e[n].$multiply(t));else if(i){if(e.length!=t.length)throw new Error('Cannot multiply matrix element-wise because the matrices\' sizes don\'t match.');for(let n=0,i=e.length;n<i;n++)o.push(e[n].$multiply(t[n]))}else{if(!n&&e[0].length!=t.length)throw new Error('Cannot multiply matrix if rows in matrix-a don\'t match columns in matrix-b.');if(n&&e[0].length!=t[0].length)throw new Error('Cannot multiply matrix if transposed and the columns in both matrices don\'t match.');n||(t=p.transpose(t));for(let n,i=0,r=e.length;i<r;i++){n=d.Pt.make(t.length,0);for(let o=0,r=t.length;o<r;o++)n[o]=c.dot(e[i],t[o]);o.push(n)}}return o}static zipSlice(e,t,n=!1){let o=[];for(let r=0,i=e.length;r<i;r++){if(e[r].length-1<t&&!1===n)throw`Index ${t} is out of bounds`;o.push(e[r][t]||n)}return new d.Pt(o)}static zip(e,t=!1,n=!1){let o=new d.Group,r=n?e.reduce((e,t)=>u(e,t.length),0):e[0].length;for(let a=0;a<r;a++)o.push(p.zipSlice(e,a,t));return o}static transpose(e,t=!1,n=!1){return p.zip(e,t,n)}static transform2D(e,t){let n=e[0]*t[0][0]+e[1]*t[1][0]+t[2][0],i=e[0]*t[0][1]+e[1]*t[1][1]+t[2][1];return new d.Pt(n,i)}static scale2DMatrix(e,t){return new d.Group(new d.Pt(e,0,0),new d.Pt(0,t,0),new d.Pt(0,0,1))}static rotate2DMatrix(e,t){return new d.Group(new d.Pt(e,t,0),new d.Pt(-t,e,0),new d.Pt(0,0,1))}static shear2DMatrix(e,t){return new d.Group(new d.Pt(1,e,0),new d.Pt(t,1,0),new d.Pt(0,0,1))}static translate2DMatrix(e,t){return new d.Group(new d.Pt(1,0,0),new d.Pt(0,1,0),new d.Pt(e,t,1))}static scaleAt2DMatrix(e,t,n){let i=p.scale2DMatrix(e,t);return i[2][0]=-n[0]*e+n[0],i[2][1]=-n[1]*t+n[1],i}static rotateAt2DMatrix(e,t,n){let i=p.rotate2DMatrix(e,t);return i[2][0]=n[0]*(1-e)+n[1]*t,i[2][1]=n[1]*(1-e)-n[0]*t,i}static shearAt2DMatrix(e,t,n){let i=p.shear2DMatrix(e,t);return i[2][0]=-n[1]*t,i[2][1]=-n[0]*e,i}static reflectAt2DMatrix(e,t){let n=a.Line.intercept(e,t);if(n==void 0)return[new d.Pt([-1,0,0]),new d.Pt([0,1,0]),new d.Pt([e[0]+t[0],0,1])];else{let e=n.yi,t=2*Math.atan(n.slope),i=s(t),o=l(t);return[new d.Pt([i,o,0]),new d.Pt([o,-i,0]),new d.Pt([-e*o,e+e*i,1])]}}}o.Mat=p},function(e,t,n){'use strict';Object.defineProperty(t,'__esModule',{value:!0});const i=n(1);class o{constructor(){this._ready=!1}get ready(){return this._ready}static _checkSize(e,t=2){return!(e.length<t)||(i.Util.warn('Requires 2 or more Pts in this Group.'),!1)}}t.Form=o;class r extends o{constructor(){super(...arguments),this._filled=!0,this._stroked=!0,this._font=new a(14,'sans-serif')}get filled(){return this._filled}set filled(e){this._filled=e}get stroked(){return this._stroked}set stroked(e){this._stroked=e}get currentFont(){return this._font}_multiple(e,t,...n){if(!e)return this;for(let o=0,i=e.length;o<i;o++)this[t](e[o],...n);return this}fill(){return this}fillOnly(e){return this.stroke(!1),this.fill(e)}stroke(){return this}strokeOnly(e,t,n,i){return this.fill(!1),this.stroke(e,t,n,i)}points(e,t,n){if(e){for(let o=0,i=e.length;o<i;o++)this.point(e[o],t,n);return this}}circles(e){return this._multiple(e,'circle')}squares(e){return this._multiple(e,'square')}lines(e){return this._multiple(e,'line')}polygons(e){return this._multiple(e,'polygon')}rects(e){return this._multiple(e,'rect')}}t.VisualForm=r;class a{constructor(e=12,t='sans-serif',n='',i='',o=1.5){this.size=e,this.face=t,this.style=i,this.weight=n,this.lineHeight=o}get value(){return`${this.style} ${this.weight} ${this.size}px/${this.lineHeight} ${this.face}`}toString(){return this.value}}t.Font=a},function(e,t,n){'use strict';Object.defineProperty(t,'__esModule',{value:!0});const o=n(0),i=n(11);class r{constructor(){this.id='space',this.bound=new o.Bound,this._time={prev:0,diff:0,end:-1},this.players={},this.playerCount=0,this._animID=-1,this._pause=!1,this._refresh=void 0,this._pointer=new o.Pt,this._isReady=!1,this._playing=!1}refresh(e){return this._refresh=e,this}add(e){let t='function'==typeof e?{animate:e}:e,n=this.playerCount++,i=this.id+n;return this.players[i]=t,t.animateID=i,t.resize&&this.bound.inited&&t.resize(this.bound),void 0===this._refresh&&(this._refresh=!0),this}remove(e){return delete this.players[e.animateID],this}removeAll(){return this.players={},this}play(e=0){if(this._animID=requestAnimationFrame(this.play.bind(this)),this._pause)return this;this._time.diff=e-this._time.prev,this._time.prev=e;try{this.playItems(e)}catch(e){throw cancelAnimationFrame(this._animID),this._playing=!1,e}return this}replay(){this._time.end=-1,this.play()}playItems(e){if(this._playing=!0,this._refresh&&this.clear(),this._isReady)for(let t in this.players)this.players[t].animate&&this.players[t].animate(e,this._time.diff,this);0<=this._time.end&&e>this._time.end&&(cancelAnimationFrame(this._animID),this._playing=!1)}pause(e=!1){return this._pause=!e||!this._pause,this}resume(){return this._pause=!1,this}stop(e=0){return this._time.end=e,this}playOnce(e=5e3){return this.play(),this.stop(e),this}render(e){return this._renderFunc&&this._renderFunc(e,this),this}set customRendering(e){this._renderFunc=e}get customRendering(){return this._renderFunc}get isPlaying(){return this._playing}get outerBound(){return this.bound.clone()}get innerBound(){return new o.Bound(o.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}}t.Space=r;class a extends r{constructor(){super(...arguments),this._pressed=!1,this._dragged=!1,this._hasMouse=!1,this._hasTouch=!1}get pointer(){let e=this._pointer.clone();return e.id=this._pointer.id,e}bindCanvas(e,t){this._canvas.addEventListener(e,t)}unbindCanvas(e,t){this._canvas.removeEventListener(e,t)}bindMouse(e=!0){return e?(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(e=!0){return e?(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(e,n='touches'){if(!e||!e[n])return[];let r=[];for(var a=0;a<e[n].length;a++){let i=e[n].item(a);r.push(new o.Pt(i.pageX-this.bound.topLeft.x,i.pageY-this.bound.topLeft.y))}return r}_mouseAction(e,t){let n=0,i=0;if(t instanceof MouseEvent){for(let o in this.players)if(this.players.hasOwnProperty(o)){let r=this.players[o];n=t.pageX-this.outerBound.x,i=t.pageY-this.outerBound.y,r.action&&r.action(e,n,i,t)}}else for(let o in this.players)if(this.players.hasOwnProperty(o)){let r=this.players[o],a=t.changedTouches&&0<t.changedTouches.length,s=t.changedTouches.item(0);n=a?s.pageX-this.outerBound.x:0,i=a?s.pageY-this.outerBound.y:0,r.action&&r.action(e,n,i,t)}e&&(this._pointer.to(n,i),this._pointer.id=e)}_mouseDown(e){return this._mouseAction(i.UIPointerActions.down,e),this._pressed=!0,!1}_mouseUp(e){return this._mouseAction(i.UIPointerActions.up,e),this._dragged&&this._mouseAction(i.UIPointerActions.down,e),this._pressed=!1,this._dragged=!1,!1}_mouseMove(e){return this._mouseAction(i.UIPointerActions.move,e),this._pressed&&(this._dragged=!0,this._mouseAction(i.UIPointerActions.drag,e)),!1}_mouseOver(e){return this._mouseAction(i.UIPointerActions.over,e),!1}_mouseOut(e){return this._mouseAction(i.UIPointerActions.out,e),this._dragged&&this._mouseAction(i.UIPointerActions.drop,e),this._dragged=!1,!1}_touchMove(e){return this._mouseMove(e),e.preventDefault(),!1}}t.MultiTouchSpace=a},function(e,t,n){'use strict';Object.defineProperty(t,'__esModule',{value:!0});const i=n(6),o=n(5),r=n(0),s=n(1),l=n(8),d=n(2);class c extends i.MultiTouchSpace{constructor(e,t){super(),this._pixelScale=1,this._autoResize=!0,this._bgcolor='#e1e9f0',this._offscreen=!1,this._initialResize=!1;var n=null,i=!1;if(this.id='pt',e instanceof Element)n=e,this.id='pts_existing_space';else{let t=e;t='#'===e[0]||'.'===e[0]?e:'#'+e,n=document.querySelector(t),i=!0,this.id=t.substr(1)}n?'canvas'==n.nodeName.toLowerCase()?(this._canvas=n,this._container=n.parentElement,this._autoResize=!1):(this._container=n,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),i=!1),setTimeout(this._ready.bind(this,t),100),this._ctx=this._canvas.getContext('2d')}_createElement(e='div',t){let n=document.createElement(e);return n.setAttribute('id',t),n}_ready(e){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,e&&e(this.bound,this._canvas)}setup(e){if(e.bgcolor&&(this._bgcolor=e.bgcolor),this.autoResize=void 0!=e.resize&&e.resize,!1!==e.retina){let e=window.devicePixelRatio||1,t=this._ctx.webkitBackingStorePixelRatio||this._ctx.mozBackingStorePixelRatio||this._ctx.msBackingStorePixelRatio||this._ctx.oBackingStorePixelRatio||this._ctx.backingStorePixelRatio||1;this._pixelScale=u(1,e/t)}return e.offscreen?(this._offscreen=!0,this._offCanvas=this._createElement('canvas',this.id+'_offscreen'),this._offCtx=this._offCanvas.getContext('2d')):this._offscreen=!1,this}set autoResize(e){this._autoResize=e,e?window.addEventListener('resize',this._resizeHandler.bind(this)):window.removeEventListener('resize',this._resizeHandler.bind(this))}get autoResize(){return this._autoResize}resize(e,t){for(let n in this.bound=e,this._canvas.width=this.bound.size.x*this._pixelScale,this._canvas.height=this.bound.size.y*this._pixelScale,this._canvas.style.width=a(this.bound.size.x)+'px',this._canvas.style.height=a(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(n)){let e=this.players[n];e.resize&&e.resize(this.bound,t)}return this.render(this._ctx),t&&!this.isPlaying&&this.playOnce(0),this}_resizeHandler(e){let t=this._autoResize||this._initialResize?this._container.getBoundingClientRect():this._canvas.getBoundingClientRect();if(t){let n=r.Bound.fromBoundingRect(t);n.center=n.center.add(window.pageXOffset,window.pageYOffset),this.resize(n,e)}}set background(e){this._bgcolor=e}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 _(this)}get element(){return this._canvas}get parent(){return this._container}get ready(){return this._isReady}get ctx(){return this._ctx}clear(e){e&&(this._bgcolor=e);let t=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=t,this}clearOffscreen(e){return this._offscreen&&(e?(this._offCtx.fillStyle=e,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(e){this._isReady&&(this._ctx.save(),this._offscreen&&this._offCtx.save(),super.playItems(e),this._ctx.restore(),this._offscreen&&this._offCtx.restore(),this.render(this._ctx))}}t.CanvasSpace=c;class _ extends o.VisualForm{constructor(e){super(),this._style={fillStyle:'#f03',strokeStyle:'#fff',lineWidth:1,lineJoin:'bevel',lineCap:'butt'},this._space=e,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(e=!0,t=!1){return t&&this._space.clearOffscreen('string'==typeof t?t:null),this._ctx=this._space.hasOffscreen&&e?this._space.offscreenCtx:this._space.ctx,this}renderOffscreen(e=[0,0]){this._space.hasOffscreen&&this._space.ctx.drawImage(this._space.offscreenCanvas,e[0],e[1],this._space.width,this._space.height)}fill(e){return'boolean'==typeof e?this.filled=e:(this.filled=!0,this._style.fillStyle=e,this._ctx.fillStyle=e),this}stroke(e,t,n,i){return'boolean'==typeof e?this.stroked=e:(this.stroked=!0,this._style.strokeStyle=e,this._ctx.strokeStyle=e,t&&(this._ctx.lineWidth=t,this._style.lineWidth=t),n&&(this._ctx.lineJoin=n,this._style.lineJoin=n),i&&(this._ctx.lineCap=i,this._style.lineCap=i)),this}font(e,t,n,i,o){return'number'==typeof e?(this._font.size=e,o&&(this._font.face=o),t&&(this._font.weight=t),n&&(this._font.style=n),i&&(this._font.lineHeight=i),this._ctx.font=this._font.value):this._font=e,this._estimateTextWidth&&this.fontWidthEstimate(!0),this}fontWidthEstimate(e=!0){return this._estimateTextWidth=e?l.Typography.textWidthEstimator((e)=>this._ctx.measureText(e).width):void 0,this}getTextWidth(e){return this._estimateTextWidth?this._estimateTextWidth(e):this._ctx.measureText(e+' .').width}_textTruncate(e,t,n=''){return l.Typography.truncate(this.getTextWidth.bind(this),e,t,n)}_textAlign(e,t,n,i){i||(i=d.Rectangle.center(e));var o=e[0][0];'end'==this._ctx.textAlign||'right'==this._ctx.textAlign?o=e[1][0]:('center'==this._ctx.textAlign||'middle'==this._ctx.textAlign)&&(o=i[0]);var a=i[1];return'top'==t||'start'==t?a=e[0][1]:('end'==t||'bottom'==t)&&(a=e[1][1]),n?new r.Pt(o+n[0],a+n[1]):new r.Pt(o,a)}reset(){for(let e in this._style)this._style.hasOwnProperty(e)&&(this._ctx[e]=this._style[e]);return this._font=new o.Font,this._ctx.font=this._font.value,this}_paint(){this._filled&&this._ctx.fill(),this._stroked&&this._ctx.stroke()}point(e,t=5,n='square'){if(e){if(!_[n])throw new Error(`${n} is not a static function of CanvasForm`);return _[n](this._ctx,e,t),this._paint(),this}}static circle(e,t,n=10){t&&(e.beginPath(),e.arc(t[0],t[1],n,0,s.Const.two_pi,!1),e.closePath())}circle(e){return _.circle(this._ctx,e[0],e[1][0]),this._paint(),this}static arc(e,t,n,i,o,r){t&&(e.beginPath(),e.arc(t[0],t[1],n,i,o,r))}arc(e,t,n,i,o){return _.arc(this._ctx,e,t,n,i,o),this._paint(),this}static square(e,t,n){if(t){let i=t[0]-n,o=t[1]-n,r=t[0]+n,a=t[1]+n;e.beginPath(),e.moveTo(i,o),e.lineTo(i,a),e.lineTo(r,a),e.lineTo(r,o),e.closePath()}}square(e,t){return _.square(this._ctx,e,t),this._paint(),this}static line(e,t){if(!(2>t.length)){e.beginPath(),e.moveTo(t[0][0],t[0][1]);for(let n=1,i=t.length;n<i;n++)t[n]&&e.lineTo(t[n][0],t[n][1])}}line(e){return _.line(this._ctx,e),this._paint(),this}static polygon(e,t){if(!(2>t.length)){e.beginPath(),e.moveTo(t[0][0],t[0][1]);for(let n=1,i=t.length;n<i;n++)t[n]&&e.lineTo(t[n][0],t[n][1]);e.closePath()}}polygon(e){return _.polygon(this._ctx,e),this._paint(),this}static rect(e,t){2>t.length||(e.beginPath(),e.moveTo(t[0][0],t[0][1]),e.lineTo(t[0][0],t[1][1]),e.lineTo(t[1][0],t[1][1]),e.lineTo(t[1][0],t[0][1]),e.closePath())}rect(e){return _.rect(this._ctx,e),this._paint(),this}static image(e,n,i=new r.Pt,o){if('number'==typeof i[0])e.drawImage(n,i[0],i[1]);else{let r=i;o?e.drawImage(n,o[0][0],o[0][1],o[1][0]-o[0][0],o[1][1]-o[0][1],r[0][0],r[0][1],r[1][0]-r[0][0],r[1][1]-r[0][1]):e.drawImage(n,r[0][0],r[0][1],r[1][0]-r[0][0],r[1][1]-r[0][1])}}image(e,t,n){return _.image(this._ctx,e,t,n),this}static text(e,t,n,i){t&&e.fillText(n,t[0],t[1],i)}text(e,t,n){return _.text(this._ctx,e,t,n),this}textBox(e,n,i='middle',o='',r=!0){r&&(this._ctx.textBaseline=i);let a=d.Rectangle.size(e),s=this._textTruncate(n,a[0],o);return this.text(this._textAlign(e,i),s[0]),this}paragraphBox(e,t,n=1.2,i='top',o=!0){let a=d.Rectangle.size(e);this._ctx.textBaseline='top';let s=this._font.size*n,l=(e,n=[],i=0)=>{if(!e)return n;if(o&&i*s>a[1]-2*s)return n;if(1e4<i)throw new Error('max recursion reached (10000)');let r=this._textTruncate(e,a[0],''),t=r[0].indexOf('\n');if(0<=t)return n.push(r[0].substr(0,t)),l(e.substr(t+1),n,i+1);let d=r[0].lastIndexOf(' ')+1;(0>=d||r[1]===e.length)&&(d=void 0);let c=r[0].substr(0,d);return n.push(c),0>=r[1]||r[1]===e.length?n:l(e.substr(d||r[1]),n,i+1)},c=l(t),p=c.length*s,_=e;if('middle'==i||'center'==i){let t=(a[1]-p)/2;o&&(t=u(0,t)),_=new r.Group(e[0].$add(0,t),e[1].$subtract(0,t))}else _='bottom'==i?new r.Group(e[0].$add(0,a[1]-p),e[1]):new r.Group(e[0],e[0].$add(a[0],p));let h=d.Rectangle.center(_);for(let r=0,a=c.length;r<a;r++)this.text(this._textAlign(_,'top',[0,r*s],h),c[r]);return this}alignText(e='left',t='alphabetic'){return'center'==t&&(t='middle'),'baseline'==t&&(t='alphabetic'),this._ctx.textAlign=e,this._ctx.textBaseline=t,this}log(e){let t=this._ctx.measureText(e).width+20;return this.stroke(!1).fill('rgba(0,0,0,.4)').rect([[0,0],[t,20]]),this.fill('#fff').text([10,14],e),this}}t.CanvasForm=_},function(e,t,n){'use strict';Object.defineProperty(t,'__esModule',{value:!0});const i=n(0);t.Typography=class{static textWidthEstimator(e,t=['M','n','.'],n=[.06,.8,.14]){let o=t.map(e),r=new i.Pt(n).dot(o);return(e)=>e.length*r}static truncate(e,t,n,i=''){let o=a(t.length*_(1,n/e(t)));return o<t.length?(o=u(0,o-i.length),[t.substr(0,o)+i,o]):[t,t.length]}static fontSizeToBox(e,t=1,n=!0){let o=n?1:0,i=e[1][o]-e[0][o];return function(e){let n=(e[1][o]-e[0][o])/i;return t*i*n}}static fontSizeToThreshold(e,t=0){return function(n,i){let o=n*i/e;return 0>t?_(o,n):0<t?u(o,n):o}}}},function(e,t,n){'use strict';Object.defineProperty(t,'__esModule',{value:!0});const i=n(6),o=n(5),r=n(1),a=n(0);class s extends i.MultiTouchSpace{constructor(e,t){super(),this.id='domspace',this._autoResize=!0,this._bgcolor='#e1e9f0',this._css={};var n=null,i=!1;this.id='pts',e instanceof Element?(n=e,this.id='pts_existing_space'):(n=document.querySelector(e),i=!0,this.id=e.substr(1)),n?(this._canvas=n,this._container=n.parentElement):(this._container=s.createElement('div','pts_container'),this._canvas=s.createElement('div','pts_element'),this._container.appendChild(this._canvas),document.body.appendChild(this._container),i=!1),setTimeout(this._ready.bind(this,t),50)}static createElement(e='div',t,n){let i=document.createElement(e);return t&&i.setAttribute('id',t),n&&n.appendChild&&n.appendChild(i),i}_ready(e){if(!this._container)throw new Error(`Cannot initiate #${this.id} element`);for(let t in this._isReady=!0,this._resizeHandler(null),this.clear(this._bgcolor),this._canvas.dispatchEvent(new Event('ready')),this.players)this.players.hasOwnProperty(t)&&this.players[t].start&&this.players[t].start(this.bound.clone(),this);this._pointer=this.center,this.refresh(!1),e&&e(this.bound,this._canvas)}setup(e){return e.bgcolor&&(this._bgcolor=e.bgcolor),this.autoResize=void 0!=e.resize&&e.resize,this}getForm(){return null}set autoResize(e){this._autoResize=e,e?window.addEventListener('resize',this._resizeHandler.bind(this)):(delete this._css.width,delete this._css.height,window.removeEventListener('resize',this._resizeHandler.bind(this)))}get autoResize(){return this._autoResize}resize(e,t){for(let n in this.bound=e,this.styles({width:`${e.width}px`,height:`${e.height}px`},!0),this.players)if(this.players.hasOwnProperty(n)){let e=this.players[n];e.resize&&e.resize(this.bound,t)}return this}_resizeHandler(e){let t=a.Bound.fromBoundingRect(this._container.getBoundingClientRect());this._autoResize?this.styles({width:'100%',height:'100%'},!0):this.styles({width:`${t.width}px`,height:`${t.height}px`},!0),this.resize(t,e)}get element(){return this._canvas}get parent(){return this._container}get ready(){return this._isReady}clear(e){return e&&(this.background=e),this._canvas.innerHTML='',this}set background(e){this._bgcolor=e,this._container.style.backgroundColor=this._bgcolor}get background(){return this._bgcolor}style(e,t,n=!1){return this._css[e]=t,n&&(this._canvas.style[e]=t),this}styles(e,t=!1){for(let n in e)e.hasOwnProperty(n)&&this.style(n,e[n],t);return this}static setAttr(e,t){for(let n in t)t.hasOwnProperty(n)&&e.setAttribute(n,t[n]);return e}static getInlineStyles(e){let t='';for(let n in e)e.hasOwnProperty(n)&&e[n]&&(t+=`${n}: ${e[n]}; `);return t}}t.DOMSpace=s;class l extends s{getForm(){return new d(this)}static htmlElement(e,t,n,i=!0){if(!e||!e.appendChild)throw new Error('parent is not a valid DOM element');let o=document.querySelector(`#${n}`);return o||(o=document.createElement(t),o.setAttribute('id',n),i&&o.setAttribute('class',n.substring(0,n.indexOf('-'))),e.appendChild(o)),o}remove(e){let t=this._container.querySelectorAll('.'+d.scopeID(e));return t.forEach((e)=>{e.parentNode.removeChild(e)}),super.remove(e)}removeAll(){return this._container.innerHTML='',super.removeAll()}}t.HTMLSpace=l;class d extends o.VisualForm{constructor(e){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=e,this._space.add({start:()=>{this._ctx.group=this._space.element,this._ctx.groupID='pts_dom_'+d.groupID++,this._ready=!0}})}get space(){return this._space}styleTo(e,t,n=''){if(this._ctx.style[e]===void 0)throw new Error(`${e} style property doesn't exist`);this._ctx.style[e]=`${t}${n}`}fill(e){return'boolean'==typeof e?(this.styleTo('filled',e),!e&&this.styleTo('background','transparent')):(this.styleTo('filled',!0),this.styleTo('background',e)),this}stroke(e,t){return'boolean'==typeof e?(this.styleTo('stroked',e),!e&&this.styleTo('border-width',0)):(this.styleTo('stroked',!0),this.styleTo('border-color',e),this.styleTo('border-width',(t||1)+'px')),this}fillText(e){return this.styleTo('color',e),this}cls(e){return this._ctx.currentClass='boolean'==typeof e?'':e,this}font(e,t,n,i,o){return'number'==typeof e?(this._font.size=e,o&&(this._font.face=o),t&&(this._font.weight=t),n&&(this._font.style=n),i&&(this._font.lineHeight=i),this._ctx.font=this._font.value):this._font=e,this}reset(){return this._ctx.style={filled:!0,stroked:!0,background:'#f03',"border-color":'#fff',"border-width":'1px'},this._font=new o.Font(14,'sans-serif'),this._ctx.font=this._font.value,this}updateScope(e,t){return this._ctx.group=t,this._ctx.groupID=e,this._ctx.groupCount=0,this.nextID(),this._ctx}scope(e){if(!e||null==e.animateID)throw new Error('item not defined or not yet added to Space');return this.updateScope(d.scopeID(e),this.space.element)}nextID(){return this._ctx.groupCount++,this._ctx.currentID=`${this._ctx.groupID}-${this._ctx.groupCount}`,this._ctx.currentID}static getID(e){return e.currentID||`p-${d.domID++}`}static scopeID(e){return`item-${e.animateID}`}static style(e,t){let n=[];for(let i in t.filled||n.push('background: none'),t.stroked||n.push('border: none'),t)if(t.hasOwnProperty(i)&&'filled'!=i&&'stroked'!=i){let e=t[i];if(e)if(!t.filled&&0===i.indexOf('background'))continue;else if(!t.stroked&&0===i.indexOf('border-width'))continue;else n.push(`${i}: ${e}`)}return l.setAttr(e,{style:n.join(';')})}static rectStyle(e,t,n){return e.style.left=t[0]+'px',e.style.top=t[1]+'px',e.style.width=n[0]+'px',e.style.height=n[1]+'px',e}static point(e,t,n=5,i='square'){return'circle'===i?d.circle(e,t,n):d.square(e,t,n)}point(e,t=5,n='square'){return this.nextID(),'circle'==n&&this.styleTo('border-radius','100%'),d.point(this._ctx,e,t,n),this}static circle(e,t,n=10){let i=l.htmlElement(e.group,'div',d.getID(e));return l.setAttr(i,{class:`pts-form pts-circle ${e.currentClass}`}),d.rectStyle(e,new a.Pt(t).$subtract(n),new a.Pt(2*n,2*n)),d.style(i,e.style),i}circle(e){return this.nextID(),this.styleTo('border-radius','100%'),d.circle(this._ctx,e[0],e[1][0]),this}static square(e,t,n){let i=l.htmlElement(e.group,'div',d.getID(e));return l.setAttr(i,{class:`pts-form pts-square ${e.currentClass}`}),d.rectStyle(e,new a.Pt(t).$subtract(n),new a.Pt(2*n,2*n)),d.style(i,e.style),i}square(e,t){return this.nextID(),d.square(this._ctx,e,t),this}static rect(e,t){if(this._checkSize(t)){let n=l.htmlElement(e.group,'div',d.getID(e));return l.setAttr(n,{class:`pts-form pts-rect ${e.currentClass}`}),d.rectStyle(e,t[0],t[1]),d.style(n,e.style),n}}rect(e){return this.nextID(),this.styleTo('border-radius','0'),d.rect(this._ctx,e),this}static text(e,t,n){let i=l.htmlElement(e.group,'div',d.getID(e));return l.setAttr(i,{position:'absolute',class:`pts-form pts-text ${e.currentClass}`,left:t[0],top:t[1]}),i.textContent=n,d.style(i,e.style),i}text(e,t){return this.nextID(),d.text(this._ctx,e,t),this}log(e){return this.fill('#000').stroke('#fff',.5).text([10,14],e),this}arc(){return r.Util.warn('arc is not implemented in HTMLForm'),this}line(){return r.Util.warn('line is not implemented in HTMLForm'),this}polygon(){return r.Util.warn('polygon is not implemented in HTMLForm'),this}}d.groupID=0,d.domID=0,t.HTMLForm=d},function(e,t,n){'use strict';function i(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}Object.defineProperty(t,'__esModule',{value:!0}),i(n(7)),i(n(12)),i(n(5)),i(n(4)),i(n(3)),i(n(2)),i(n(0)),i(n(6)),i(n(13)),i(n(1)),i(n(9)),i(n(14)),i(n(8)),i(n(15));const o=n(7);t.namespace=(t)=>{let n=e.exports;for(let e in n)'namespace'!=e&&(t[e]=n[e])},t.quickStart=(e,n='#9ab')=>{let i=window;return t.namespace(i),i.space=new o.CanvasSpace(e).setup({bgcolor:n,resize:!0,retina:!0}),i.form=i.space.getForm(),function(e=null,t=null,n=null,o=null){i.space.add({start:t,animate:e,resize:o,action:n}),i.space.bindMouse().bindTouch().play()}}},function(e,t,n){'use strict';Object.defineProperty(t,'__esModule',{value:!0});const i=n(2);var o;(function(e){e[e.Rectangle=0]='Rectangle',e[e.Circle=1]='Circle',e[e.Polygon=2]='Polygon',e[e.Polyline=3]='Polyline',e[e.Line=4]='Line'})(o=t.UIShape||(t.UIShape={})),t.UIPointerActions={up:'up',down:'down',move:'move',drag:'drag',drop:'drop',over:'over',out:'out'};class r{constructor(e,t,n,i){this.group=e,this.shape=t,this._id=i,this._states=n,this._actions={}}get id(){return this._id}set id(e){this._id=e}state(e){return this._states[e]||!1}on(e,t){return this._actions[e]=t,this}off(e){return delete this._actions[e],this}listen(e,t){return!!(void 0!==this._actions[e]&&this._trigger(t))&&(this._actions[e](t,this,e),!0)}render(e){e(this.group,this._states)}_trigger(e){let t=null;if(this.shape===o.Rectangle)t=i.Rectangle.withinBound;else if(this.shape===o.Circle)t=i.Circle.withinBound;else if(this.shape===o.Polygon)t=i.Rectangle.withinBound;else return!1;return t(this.group,e)}}t.UI=r;class a extends r{constructor(e,t,n,i){super(e,t,n,i),this._clicks=0}get clicks(){return this._clicks}onClick(e){this._clicks++,this.on(t.UIPointerActions.up,e)}onHover(e,n){this.on(t.UIPointerActions.over,e),this.on(t.UIPointerActions.out,n)}}t.UIButton=a},function(e,t,n){'use strict';Object.defineProperty(t,'__esModule',{value:!0});const o=n(0),r=n(2),s=n(1),l=n(3),d=n(4);t.Create=class{static distributeRandom(e,t,n=2){let r=new o.Group;for(let a,s=0;s<t;s++)a=[e.x+Math.random()*e.width],1<n&&a.push(e.y+Math.random()*e.height),2<n&&a.push(e.z+Math.random()*e.depth),r.push(new o.Pt(a));return r}static distributeLinear(e,t){let n=r.Line.subpoints(e,t-2);return n.unshift(e[0]),n.push(e[e.length-1]),n}static gridPts(e,t,n,i=[.5,.5]){if(0===t||0===n)throw new Error('grid columns and rows cannot be 0');let a=e.size.$subtract(1).$divide(t,n),s=a.$multiply(i),l=new o.Group;for(let o=0;o<n;o++)for(let n=0;n<t;n++)l.push(e.topLeft.$add(a.$multiply(n,o)).add(s));return l}static gridCells(e,t,n){if(0===t||0===n)throw new Error('grid columns and rows cannot be 0');let i=e.size.$subtract(1).divide(t,n),a=[];for(let s=0;s<n;s++)for(let n=0;n<t;n++)a.push(new o.Group(e.topLeft.$add(i.$multiply(n,s)),e.topLeft.$add(i.$multiply(n,s).add(i))));return a}static radialPts(e,t,n){let r=new o.Group,l=s.Const.two_pi/n;for(let a=0;a<n;a++)r.push(new o.Pt(e).toAngle(l*a-s.Const.half_pi,t,!0));return r}static noisePts(e,t=.01,n=.01,s=0,l=0){let d=Math.random(),u=new o.Group;for(let o=0,i=e.length;o<i;o++){let i=new h(e[o]),p=s&&0<s?a(o/s):o,r=l&&0<l?o%l:o;i.initNoise(t*r,n*p),i.seed(d),u.push(i)}return u}static delaunay(e){return i.from(e)}};const c=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],p=[151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,129,22,39,253,9,98,108,110,79,113,224,232,178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180];class h extends o.Pt{constructor(...e){super(...e),this.perm=[],this._n=new o.Pt(.01,.01),this.perm=p.concat(p)}initNoise(...e){this._n=new o.Pt(...e)}step(e=0,t=0){this._n.add(e,t)}seed(e){0<e&&1>e&&(e*=65536),e=a(e),256>e&&(e|=e<<8);for(let t,n=0;255>n;n++)t=1&n?p[n]^255&e:p[n]^255&e>>8,this.perm[n]=this.perm[n+256]=t}noise2D(){let e=u(0,a(this._n[0]))%255,t=u(0,a(this._n[1]))%255,n=this._n[0]%255-e,i=this._n[1]%255-t,o=d.Vec.dot(c[(e+this.perm[t])%12],[n,i,0]),r=d.Vec.dot(c[(e+this.perm[t+1])%12],[n,i-1,0]),s=d.Vec.dot(c[(e+1+this.perm[t])%12],[n-1,i,0]),p=d.Vec.dot(c[(e+1+this.perm[t+1])%12],[n-1,i-1,0]),_=(e)=>e*e*e*(e*(6*e-15)+10),h=_(n);return l.Num.lerp(l.Num.lerp(o,s,h),l.Num.lerp(r,p,h),_(i))}}t.Noise=h;class i extends o.Group{constructor(){super(...arguments),this._mesh=[]}delaunay(e=!0){if(3>this.length)return[];this._mesh=[];let t=this.length,n=[];for(let o=0;o<t;o++)n[o]=o;n.sort((e,t)=>this[t][0]-this[e][0]);let o=this.slice(),r=this._superTriangle();o=o.concat(r);let a=[this._circum(t,t+1,t+2,r)],l=[],d=[];for(let t=0,r=n.length;t<r;t++){let e=n[t],r=[],c=a.length;for(this._mesh[e]||(this._mesh[e]={});c--;){let t=a[c],n=t.circle[1][0],i=o[e].$subtract(t.circle[0]);if(0<i[0]&&i[0]*i[0]>n*n){l.push(t),d.push(t.triangle),a.splice(c,1);continue}i[0]*i[0]+i[1]*i[1]-n*n>s.Const.epsilon||(r.push(t.i,t.j,t.j,t.k,t.k,t.i),a.splice(c,1))}for(i._dedupe(r),c=r.length;1<c;)a.push(this._circum(r[--c],r[--c],e,!1,o))}for(let n,o=0,i=a.length;o<i;o++)n=a[o],n.i<t&&n.j<t&&n.k<t&&(l.push(n),d.push(n.triangle),this._cache(n));return e?d:l}voronoi(){let e=[],t=this._mesh;for(let n=0,i=t.length;n<i;n++)e.push(this.neighborPts(n,!0));return e}mesh(){return this._mesh}neighborPts(e,t=!1){let i=new o.Group,r=this._mesh;for(let n in r[e])r[e].hasOwnProperty(n)&&i.push(r[e][n].circle[0]);return t?l.Geom.sortEdges(i):i}neighbors(e){let t=[],i=this._mesh;for(let n in i[e])i[e].hasOwnProperty(n)&&t.push(i[e][n]);return t}_cache(e){this._mesh[e.i][`${_(e.j,e.k)}-${u(e.j,e.k)}`]=e,this._mesh[e.j][`${_(e.i,e.k)}-${u(e.i,e.k)}`]=e,this._mesh[e.k][`${_(e.i,e.j)}-${u(e.i,e.j)}`]=e}_superTriangle(){let e=this[0],t=this[0];for(let n=1,i=this.length;n<i;n++)e=e.$min(this[n]),t=t.$max(this[n]);let n=t.$subtract(e),i=e.$add(t).divide(2),r=u(n[0],n[1]);return new o.Group(i.$subtract(20*r,r),i.$add(0,20*r),i.$add(20*r,-r))}_triangle(e,t,n,i=this){return new o.Group(i[e],i[t],i[n])}_circum(e,n,o,a,s=this){let l=a||this._triangle(e,n,o,s);return{i:e,j:n,k:o,triangle:l,circle:r.Triangle.circumcircle(l)}}static _dedupe(e){for(let t=e.length;1<t;)for(let o=e[--t],r=e[--t],a=t;1<a;){let i=e[--a],n=e[--a];if(r==n&&o==i||r==i&&o==n){e.splice(t,2),e.splice(a,2);break}}return e}}t.Delaunay=i},function(t,i,o){'use strict';Object.defineProperty(i,'__esModule',{value:!0});const d=o(0),h=o(1),p=o(3);class m extends d.Pt{constructor(...e){super(...e),this._mode='rgb',this._isNorm=!1}static from(...e){let t=[1,1,1,1],n=h.Util.getArgs(e);for(let o=0,i=t.length;o<i;o++)o<n.length&&(t[o]=n[o]);return new m(t)}static fromHex(e){if('#'==e[0]&&(e=e.substr(1)),3>=e.length){let t=(t)=>e[t]||'F';e=`${t(0)}${t(0)}${t(1)}${t(1)}${t(2)}${t(2)}`}let t=1;8===e.length&&(t=e.substr(6)&&1,e=e.substring(0,6));let n=parseInt(e,16);return new m(n>>16,255&n>>8,255&n,t)}static rgb(...e){return m.from(...e).toMode('rgb')}static hsl(...e){return m.from(...e).toMode('hsl')}static hsb(...e){return m.from(...e).toMode('hsb')}static lab(...e){return m.from(...e).toMode('lab')}static lch(...e){return m.from(...e).toMode('lch')}static luv(...e){return m.from(...e).toMode('luv')}static xyz(...e){return m.from(...e).toMode('xyz')}static maxValues(e){return m.ranges[e].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 e=new m(this);return e.toMode(this._mode),e}toMode(e,t=!1){if(t){let t=this._mode.toUpperCase()+'to'+e.toUpperCase();if(m[t])this.to(m[t](this,this._isNorm,this._isNorm));else throw new Error('Cannot convert color with '+t)}return this._mode=e,this}get mode(){return this._mode}get r(){return this[0]}set r(e){this[0]=e}get g(){return this[1]}set g(e){this[1]=e}get b(){return this[2]}set b(e){this[2]=e}get h(){return'lch'==this._mode?this[2]:this[0]}set h(e){let t='lch'==this._mode?2:0;this[t]=e}get s(){return this[1]}set s(e){this[1]=e}get l(){return'hsl'==this._mode?this[2]:this[0]}set l(e){let t='hsl'==this._mode?2:0;this[t]=e}get a(){return this[1]}set a(e){this[1]=e}get c(){return this[1]}set c(e){this[1]=e}get u(){return this[1]}set u(e){this[1]=e}get v(){return this[2]}set v(e){this[2]=e}get alpha(){return 3<this.length?this[3]:1}get normalized(){return this._isNorm}set normalized(e){this._isNorm=e}normalize(e=!0){if(this._isNorm==e)return this;let t=m.ranges[this._mode];for(let n=0;3>n;n++)this[n]=e?p.Num.mapToRange(this[n],t[n][0],t[n][1],0,1):p.Num.mapToRange(this[n],0,1,t[n][0],t[n][1]);return this._isNorm=e,this}$normalize(e=!0){return this.clone().normalize(e)}toString(e='mode'){if('hex'==e){let e=(e)=>{let t=a(e).toString(16);return 2>t.length?'0'+t:t};return`#${e(this[0])}${e(this[1])}${e(this[2])}`}return'rgba'==e?`rgba(${a(this[0])},${a(this[1])},${a(this[2])},${this.alpha}`:'rgb'==e?`rgb(${a(this[0])},${a(this[1])},${a(this[2])}`:`${this._mode}(${this[0]},${this[1]},${this[2]},${this.alpha})`}static RGBtoHSL(e,t=!1,n=!1){let[i,o,r]=t?e:e.$normalize(),a=u(i,o,r),c=_(i,o,r),p=(a+c)/2,h=p,s=p;if(a==c)p=0,h=0;else{let e=a-c;h=.5<s?e/(2-a-c):e/(a+c),p=0,a===i?p=(o-r)/e+(o<r?6:0):a===o?p=(r-i)/e+2:a===r&&(p=(i-o)/e+4)}return m.hsl(n?p/60:60*p,h,s,e.alpha)}static HSLtoRGB(e,t=!1,n=!1){let[i,o,r]=e;if(t||(i/=360),0==o)return m.rgb(255*r,255*r,255*r,e.alpha);let a=.5>=r?r*(1+o):r+o-r*o,s=2*r-a,l=(e)=>(e=0>e?e+1:1<e?e-1:e,1>6*e?s+6*((a-s)*e):1>2*e?a:2>3*e?s+6*((a-s)*(2/3-e)):s),d=n?1:255;return m.rgb(d*l(i+1/3),d*l(i),d*l(i-1/3),e.alpha)}static RGBtoHSB(e,t=!1,n=!1){let[i,o,r]=t?e:e.$normalize(),a=u(i,o,r),l=_(i,o,r),c=a-l,d=0,p=0===a?0:c/a;return a!=l&&(a===i?d=(o-r)/c+(o<r?6:0):a===o?d=(r-i)/c+2:a===r&&(d=(i-o)/c+4)),m.hsb(n?d/60:60*d,p,a,e.alpha)}static HSBtoRGB(e,n=!1,o=!1){let[r,l,s]=e;n||(r/=360);let d=a(6*r),i=6*r-d,u=s*(1-l),p=s*(1-i*l),_=s*(1-(1-i)*l),t=[[s,_,u],[p,s,u],[u,s,_],[u,p,s],[_,u,s],[s,u,p]][d%6],c=o?1:255;return m.rgb(c*t[0],c*t[1],c*t[2],e.alpha)}static RGBtoLAB(e,t=!1,n=!1){let i=t?e.$normalize(!1):e;return m.XYZtoLAB(m.RGBtoXYZ(i),!1,n)}static LABtoRGB(e,t=!1,n=!1){let i=t?e.$normalize(!1):e;return m.XYZtoRGB(m.LABtoXYZ(i),!1,n)}static RGBtoLCH(e,t=!1,n=!1){let i=t?e.$normalize(!1):e;return m.LABtoLCH(m.RGBtoLAB(i),!1,n)}static LCHtoRGB(e,t=!1,n=!1){let i=t?e.$normalize(!1):e;return m.LABtoRGB(m.LCHtoLAB(i),!1,n)}static RGBtoLUV(e,t=!1,n=!1){let i=t?e.$normalize(!1):e;return m.XYZtoLUV(m.RGBtoXYZ(i),!1,n)}static LUVtoRGB(e,t=!1,n=!1){let i=t?e.$normalize(!1):e;return m.XYZtoRGB(m.LUVtoXYZ(i),!1,n)}static RGBtoXYZ(t,n=!1,o=!1){let r=n?t.clone():t.$normalize();for(let a=0;3>a;a++)r[a]=.04045<r[a]?e((r[a]+.055)/1.055,2.4):r[a]/12.92,o||(r[a]*=100);let i=m.xyz(.4124564*r[0]+.3575761*r[1]+.1804375*r[2],.2126729*r[0]+.7151522*r[1]+.072175*r[2],.0193339*r[0]+.119192*r[1]+.9503041*r[2],t.alpha);return o?i.normalize():i}static XYZtoRGB(t,n=!1,o=!1){let[i,r,a]=n?t:t.$normalize(),s=[3.2404542*i+-1.5371385*r+-.4985314*a,-.969266*i+1.8760108*r+.041556*a,.0556434*i+-.2040259*r+1.0572252*a];for(let r=0;3>r;r++)s[r]=0>s[r]?0:.0031308<s[r]?1.055*e(s[r],1/2.4)-.055:12.92*s[r],s[r]=u(0,_(1,s[r])),o||(s[r]=Math.round(255*s[r]));let l=m.rgb(s[0],s[1],s[2],t.alpha);return o?l.normalize():l}static XYZtoLAB(t,n=!1,i=!1){let o=n?t.$normalize(!1):t.clone();o.divide(m.D65);let r=(t)=>.008856<t?e(t,1/3):7.787*t+16/116,a=r(o[1]),s=m.lab(116*a-16,500*(r(o[0])-a),200*(a-r(o[2])),t.alpha);return i?s.normalize():s}static LABtoXYZ(e,t=!1,n=!1){let i=t?e.$normalize(!1):e,o=(i[0]+16)/116,r=i[1]/500+o,a=o-i[2]/200,s=(e)=>{let t=e*e*e;return .008856<t?t:(e-16/116)/7.787},l=m.D65,d=m.xyz(u(0,l[0]*s(r)),u(0,l[1]*s(o)),u(0,l[2]*s(a)),e.alpha);return n?d.normalize():d}static XYZtoLUV(t,n=!1,i=!1){let[o,r,a]=n?t.$normalize(!1):t,s=4*o/(o+15*r+3*a),l=9*r/(o+15*r+3*a);r/=100,r=.008856<r?e(r,1/3):7.787*r+16/116;let d=4*m.D65[0]/(m.D65[0]+15*m.D65[1]+3*m.D65[2]),c=9*m.D65[1]/(m.D65[0]+15*m.D65[1]+3*m.D65[2]),u=116*r-16;return m.luv(u,13*u*(s-d),13*u*(l-c),t.alpha)}static LUVtoXYZ(e,t=!1,n=!1){let[i,o,r]=t?e.$normalize(!1):e,a=(i+16)/116,s=a*a*a;a=.008856<s?s:(a-16/116)/7.787;let l=4*m.D65[0]/(m.D65[0]+15*m.D65[1]+3*m.D65[2]),d=9*m.D65[1]/(m.D65[0]+15*m.D65[1]+3*m.D65[2]);o=o/(13*i)+l,r=r/(13*i)+d,a*=100;let c=-1*(9*a*o)/((o-4)*r-o*r),u=(9*a-15*r*a-r*c)/(3*r);return m.xyz(c,a,u,e.alpha)}static LABtoLCH(e,t=!1,i=!1){let o=t?e.$normalize(!1):e,a=p.Geom.toDegree(p.Geom.boundRadian(r(o[2],o[1])));return m.lch(o[0],n(o[1]*o[1]+o[2]*o[2]),a,e.alpha)}static LCHtoLAB(e,t=!1,n=!1){let i=t?e.$normalize(!1):e,o=p.Geom.toRadian(i[2]);return m.lab(i[0],s(o)*i[1],l(o)*i[1],e.alpha)}}m.D65=new d.Pt(95.047,100,108.883,1),m.ranges={rgb:new d.Group(new d.Pt(0,255),new d.Pt(0,255),new d.Pt(0,255)),hsl:new d.Group(new d.Pt(0,360),new d.Pt(0,1),new d.Pt(0,1)),hsb:new d.Group(new d.Pt(0,360),new d.Pt(0,1),new d.Pt(0,1)),lab:new d.Group(new d.Pt(0,100),new d.Pt(-128,127),new d.Pt(-128,127)),lch:new d.Group(new d.Pt(0,100),new d.Pt(0,100),new d.Pt(0,360)),luv:new d.Group(new d.Pt(0,100),new d.Pt(-134,220),new d.Pt(-140,122)),xyz:new d.Group(new d.Pt(0,100),new d.Pt(0,100),new d.Pt(0,100))},i.Color=m},function(e,t,n){'use strict';Object.defineProperty(t,'__esModule',{value:!0});const i=n(5),o=n(3),r=n(1),a=n(0),s=n(2),l=n(9);class c extends l.DOMSpace{constructor(e,t){if(super(e,t),this.id='svgspace',this._bgcolor='#999','svg'!=this._canvas.nodeName.toLowerCase()){let e=c.svgElement(this._canvas,'svg',`${this.id}_svg`);this._container=this._canvas,this._canvas=e}}getForm(){return new u(this)}get element(){return this._canvas}resize(e,t){return super.resize(e,t),c.setAttr(this.element,{viewBox:`0 0 ${this.bound.width} ${this.bound.height}`,width:`${this.bound.width}`,height:`${this.bound.height}`,xmlns:'http://www.w3.org/2000/svg',version:'1.1'}),this}static svgElement(e,t,n){if(!e||!e.appendChild)throw new Error('parent is not a valid DOM element');let i=document.querySelector(`#${n}`);return i||(i=document.createElementNS('http://www.w3.org/2000/svg',t),i.setAttribute('id',n),e.appendChild(i)),i}remove(e){let t=this._container.querySelectorAll('.'+u.scopeID(e));return t.forEach((e)=>{e.parentNode.removeChild(e)}),super.remove(e)}removeAll(){return this._container.innerHTML='',super.removeAll()}}t.SVGSpace=c;class u extends i.VisualForm{constructor(e){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=e,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(e,t){if(this._ctx.style[e]===void 0)throw new Error(`${e} style property doesn't exist`);this._ctx.style[e]=t}fill(e){return'boolean'==typeof e?this.styleTo('filled',e):(this.styleTo('filled',!0),this.styleTo('fill',e)),this}stroke(e,t,n,i){return'boolean'==typeof e?this.styleTo('stroked',e):(this.styleTo('stroked',!0),this.styleTo('stroke',e),t&&this.styleTo('stroke-width',t),n&&this.styleTo('stroke-linejoin',n),i&&this.styleTo('stroke-linecap',i)),this}cls(e){return this._ctx.currentClass='boolean'==typeof e?'':e,this}font(e,t,n,i,o){return'number'==typeof e?(this._font.size=e,o&&(this._font.face=o),t&&(this._font.weight=t),n&&(this._font.style=n),i&&(this._font.lineHeight=i),this._ctx.font=this._font.value):this._font=e,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 i.Font(14,'sans-serif'),this._ctx.font=this._font.value,this}updateScope(e,t){return this._ctx.group=t,this._ctx.groupID=e,this._ctx.groupCount=0,this.nextID(),this._ctx}scope(e){if(!e||null==e.animateID)throw new Error('item not defined or not yet added to Space');return this.updateScope(u.scopeID(e),this.space.element)}nextID(){return this._ctx.groupCount++,this._ctx.currentID=`${this._ctx.groupID}-${this._ctx.groupCount}`,this._ctx.currentID}static getID(e){return e.currentID||`p-${u.domID++}`}static scopeID(e){return`item-${e.animateID}`}static style(e,t){let n=[];for(let i in t.filled||n.push('fill: none'),t.stroked||n.push('stroke: none'),t)if(t.hasOwnProperty(i)&&'filled'!=i&&'stroked'!=i){let e=t[i];if(e)if(!t.filled&&0===i.indexOf('fill'))continue;else if(!t.stroked&&0===i.indexOf('stroke'))continue;else n.push(`${i}: ${e}`)}return l.DOMSpace.setAttr(e,{style:n.join(';')})}static point(e,t,n=5,i='square'){return'circle'===i?u.circle(e,t,n):u.square(e,t,n)}point(e,t=5,n='square'){return this.nextID(),u.point(this._ctx,e,t,n),this}static circle(e,t,n=10){let i=c.svgElement(e.group,'circle',u.getID(e));return l.DOMSpace.setAttr(i,{cx:t[0],cy:t[1],r:n,class:`pts-svgform pts-circle ${e.currentClass}`}),u.style(i,e.style),i}circle(e){return this.nextID(),u.circle(this._ctx,e[0],e[1][0]),this}static arc(e,t,n,i,s,p){let _=c.svgElement(e.group,'path',u.getID(e));const h=new a.Pt(t).toAngle(i,n,!0),g=new a.Pt(t).toAngle(s,n,!0),m=o.Geom.boundAngle(s)-o.Geom.boundAngle(i);let f=!!(m>r.Const.pi);p&&(f=!f);const y=p?'0':'1',b=`M ${h[0]} ${h[1]} A ${n} ${n} 0 ${f?'1':'0'} ${y} ${g[0]} ${g[1]}`;return l.DOMSpace.setAttr(_,{d:b,class:`pts-svgform pts-arc ${e.currentClass}`}),u.style(_,e.style),_}arc(e,t,n,i,o){return this.nextID(),u.arc(this._ctx,e,t,n,i,o),this}static square(e,t,n){let i=c.svgElement(e.group,'rect',u.getID(e));return l.DOMSpace.setAttr(i,{x:t[0]-n,y:t[1]-n,width:2*n,height:2*n,class:`pts-svgform pts-square ${e.currentClass}`}),u.style(i,e.style),i}square(e,t){return this.nextID(),u.square(this._ctx,e,t),this}static line(e,t){if(this._checkSize(t)){if(2<t.length)return u._poly(e,t,!1);let n=c.svgElement(e.group,'line',u.getID(e));return l.DOMSpace.setAttr(n,{x1:t[0][0],y1:t[0][1],x2:t[1][0],y2:t[1][1],class:`pts-svgform pts-line ${e.currentClass}`}),u.style(n,e.style),n}}line(e){return this.nextID(),u.line(this._ctx,e),this}static _poly(e,t,n=!0){if(this._checkSize(t)){let i=c.svgElement(e.group,n?'polygon':'polyline',u.getID(e)),o=t.reduce((e,t)=>e+`${t[0]},${t[1]} `,'');return l.DOMSpace.setAttr(i,{points:o,class:`pts-svgform pts-polygon ${e.currentClass}`}),u.style(i,e.style),i}}static polygon(e,t){return u._poly(e,t,!0)}polygon(e){return this.nextID(),u.polygon(this._ctx,e),this}static rect(e,t){if(this._checkSize(t)){let n=c.svgElement(e.group,'rect',u.getID(e)),i=a.Group.fromArray(t).boundingBox(),o=s.Rectangle.size(i);return l.DOMSpace.setAttr(n,{x:i[0][0],y:i[0][1],width:o[0],height:o[1],class:`pts-svgform pts-rect ${e.currentClass}`}),u.style(n,e.style),n}}rect(e){return this.nextID(),u.rect(this._ctx,e),this}static text(e,t,n){let i=c.svgElement(e.group,'text',u.getID(e));return l.DOMSpace.setAttr(i,{"pointer-events":'none',x:t[0],y:t[1],dx:0,dy:0,class:`pts-svgform pts-text ${e.currentClass}`}),i.textContent=n,u.style(i,e.style),i}text(e,t){return this.nextID(),u.text(this._ctx,e,t),this}log(e){return this.fill('#000').stroke('#fff',.5).text([10,14],e),this}}u.groupID=0,u.domID=0,t.SVGForm=u},function(e,t,i){'use strict';Object.defineProperty(t,'__esModule',{value:!0});const o=i(0),r=i(2);class l{constructor(e,t=1,n=0){return this._lastTime=null,this._gravity=new o.Pt,this._friction=1,this._damping=.75,this._particles=[],this._bodies=[],this._names={p:{},b:{}},this._bound=o.Bound.fromGroup(e),this._friction=t,this._gravity='number'==typeof n?new o.Pt(0,n):new o.Pt(n),this}get gravity(){return this._gravity}set gravity(e){this._gravity=e}get friction(){return this._friction}set friction(e){this._friction=e}get damping(){return this._damping}set damping(e){this._damping=e}get bodyCount(){return this._bodies.length}get particleCount(){return this._particles.length}body(e){return this._bodies['string'==typeof e?this._names.b[e]:e]}particle(e){return this._particles['string'==typeof e?this._names.p[e]:e]}update(e){let t=e/1e3;this._updateParticles(t),this._updateBodies(t)}drawParticles(e){this._drawParticles=e}drawBodies(e){this._drawBodies=e}add(e,t){return e instanceof c?(this._bodies.push(e),t&&(this._names.b[t]=this._bodies.length-1)):(this._particles.push(e),t&&(this._names.p[t]=this._particles.length-1)),this}remove(e,t,n=1){let i=0>t?[-1*t-1,n]:[t,n];return'body'==e?this._bodies.splice(i[0],i[1]):this._particles.splice(i[0],i[1]),this}static edgeConstraint(e,t,n,i=1,o=!1){const r=1/(e.mass||1),a=1/(t.mass||1),s=r+a;let l=t.$subtract(e),c=n*n,u=o?n/l.magnitude()-1:c/(l.dot(l)+c)-.5,d=l.$multiply(u*i);return e.subtract(d.$multiply(r/s)),t.add(d.$multiply(a/s)),e}static boundConstraint(e,t,n=.75){let i=t.boundingBox(),r=e.$min(i[1].subtract(e.radius)).$max(i[0].add(e.radius));if(r[0]===i[0][0]||r[0]===i[1][0]){let t=e.changed.$multiply(n);e.previous=r.$subtract(new o.Pt(-t[0],t[1]))}else if(r[1]===i[0][1]||r[1]===i[1][1]){let t=e.changed.$multiply(n);e.previous=r.$subtract(new o.Pt(t[0],-t[1]))}e.to(r)}integrate(e,t,n){return e.addForce(this._gravity),e.verlet(t,this._friction,n),e}_updateParticles(e){for(let t,n=0,i=this._particles.length;n<i;n++){t=this._particles[n],this.integrate(t,e,this._lastTime),l.boundConstraint(t,this._bound,this._damping);for(let e=n+1;e<i;e++)if(n!==e){let n=this._particles[e];t.collide(n,this._damping)}this._drawParticles&&this._drawParticles(t,n)}this._lastTime=e}_updateBodies(e){for(let t,n=0,i=this._bodies.length;n<i;n++){t=this._bodies[n];for(let n,i=0,o=t.length;i<o;i++)n=t[i],l.boundConstraint(n,this._bound,this._damping),this.integrate(n,e,this._lastTime);for(let e=n+1;e<i;e++)t.processBody(this._bodies[e]);for(let e=0,n=this._particles.length;e<n;e++)t.processParticle(this._particles[e]);t.processEdges(),this._drawBodies&&this._drawBodies(t,n)}}}t.World=l;class s extends o.Pt{constructor(...e){super(...e),this._mass=1,this._radius=0,this._force=new o.Pt,this._prev=new o.Pt,this._lock=!1,this._prev=this.clone()}get mass(){return this._mass}set mass(e){this._mass=e}get radius(){return this._radius}set radius(e){this._radius=e}get previous(){return this._prev}set previous(e){this._prev=e}get force(){return this._force}set force(e){this._force=e}get body(){return this._body}set body(e){this._body=e}get lock(){return this._lock}set lock(e){this._lock=e,this._lockPt=new o.Pt(this)}get changed(){return this.$subtract(this._prev)}set position(e){this.previous.to(this),this._lock&&(this._lockPt=e),this.to(e)}size(e){return this._mass=e,this._radius=e,this}addForce(...e){return this._force.add(...e),this._force}verlet(e,t,n){if(this._lock)this.to(this._lockPt);else{let i=n?n:e,r=this._force.multiply(e*(e+i)/2),a=this.changed.multiply(t*e/i).add(r);this._prev=this.clone(),this.add(a),this._force=new o.Pt}return this}hit(...e){return this._prev.subtract(new o.Pt(...e).$divide(n(this._mass))),this}collide(e,t=1){let i=this,r=i.$subtract(e),a=r.magnitudeSq(),s=i.radius+e.radius;if(a<s*s){let l=i.changed,c=e.changed,u=n(a),p=r.$multiply((u-s)/u/2),d=i.$subtract(p),_=e.$add(p);i.to(d),e.to(_);let h=t*r.dot(l)/a,g=t*r.dot(c)/a,m=i.mass/(i.mass+e.mass),f=e.mass/(i.mass+e.mass);l.add(new o.Pt(g*r[0]-h*r[0],g*r[1]-h*r[1]).$multiply(f)),c.add(new o.Pt(h*r[0]-g*r[0],h*r[1]-g*r[1]).$multiply(m)),i.previous=i.$subtract(l),e.previous=e.$subtract(c)}}toString(){return`Particle: ${this[0]} ${this[1]} | previous ${this._prev[0]} ${this._prev[1]} | mass ${this._mass}`}}t.Particle=s;class c extends o.Group{constructor(){super(),this._cs=[],this._stiff=1,this._locks={},this._mass=1}static fromGroup(e,t=1,n=!0,i=!0){let o=new c().init(e);return n&&o.linkAll(t),i&&o.autoMass(),o}init(e,t=1){let n=new o.Pt;for(let o,r=0,i=e.length;r<i;r++)o=new s(e[r]),o.body=this,n.add(e[r]),this.push(o);return this._stiff=t,this}get mass(){return this._mass}set mass(e){this._mass=e;for(let t=0,n=this.length;t<n;t++)this[t].mass=this._mass}autoMass(){return this.mass=n(r.Polygon.area(this))/10,this}link(e,t,n){if(0>e||e>=this.length)throw new Error('index1 is not in the Group\'s indices');if(0>t||t>=this.length)throw new Error('index1 is not in the Group\'s indices');let i=this[e].$subtract(this[t]).magnitude();return this._cs.push([e,t,i,n||this._stiff]),this}linkAll(e){let t=this.length/2;for(let o,n=0,i=this.length;n<i;n++){if(o=n>=i-1?0:n+1,this.link(n,o,e),4<i){let o=a(t/2)+1,r=n>=i-o?n%i:n+o;this.link(n,r,e)}n<=t-1&&this.link(n,_(this.length-1,n+a(t)))}}linksToLines(){let e=[];for(let t,n=0,i=this._cs.length;n<i;n++)t=this._cs[n],e.push(new o.Group(this[t[0]],this[t[1]]));return e}processEdges(){for(let e=0,t=this._cs.length;e<t;e++){let[t,i,n,o]=this._cs[e];l.edgeConstraint(this[t],this[i],n,o)}}processBody(e){let t=this,n=r.Polygon.hasIntersectPolygon(t,e);if(n){let e,t=n.normal.$multiply(n.dist),i=n.edge;e=d(i[0][0]-i[1][0])>d(i[0][1]-i[1][1])?(n.vertex[0]-t[0]-i[0][0])/(i[1][0]-i[0][0]):(n.vertex[1]-t[1]-i[0][1])/(i[1][1]-i[0][1]);let o=1/(e*e+(1-e)*(1-e)),r=n.vertex.body.mass||1,a=n.edge[0].body.mass||1,s=r/(r+a);i[0].subtract(t.$multiply(s*(1-e)*o/2)),i[1].subtract(t.$multiply(s*e*o/2)),n.vertex.add(t.$multiply(a/(r+a)))}}processParticle(e){let t=this,n=r.Polygon.hasIntersectCircle(t,r.Circle.fromCenter(e,e.radius));if(n){let i,t=n.normal.$multiply(n.dist),o=n.edge;i=d(o[0][0]-o[1][0])>d(o[0][1]-o[1][1])?(n.vertex[0]-t[0]-o[0][0])/(o[1][0]-o[0][0]):(n.vertex[1]-t[1]-o[0][1])/(o[1][1]-o[0][1]);let r=1/(i*i+(1-i)*(1-i)),a=n.vertex.mass||e.mass||1,s=n.edge[0].body.mass||1,l=a/(a+s);o[0].subtract(t.$multiply(l*(1-i)*r/2)),o[1].subtract(t.$multiply(l*i*r/2));let c=e.changed.add(t.$multiply(s/(a+s)));e.previous=e.$subtract(c)}}}t.Body=c}])})}])});
//# sourceMappingURL=pts.min.js.map