pts 0.12.3 → 0.12.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -106,7 +106,7 @@ type PtLike = Pt | Float32Array | number[];
106
106
  type GroupLike = Group | Pt[];
107
107
  type PtIterable = GroupLike | Pt[] | Iterable<Pt>;
108
108
  type PtLikeIterable = GroupLike | PtLike[] | Iterable<PtLike>;
109
- type AnimateCallbackFn = (time?: number, frameTime?: number, currentSpace?: any) => void;
109
+ type AnimateCallbackFn = (time: number, frameTime: number, currentSpace: any) => void;
110
110
  interface IPlayer {
111
111
  animateID?: string;
112
112
  animate?: AnimateCallbackFn;
@@ -184,8 +184,8 @@ type ITempoListener = {
184
184
  fn: Function;
185
185
  };
186
186
  type ITempoResponses = {
187
- start: (fn: ITempoStartFn, offset: number, name?: string) => string;
188
- progress: (fn: ITempoProgressFn, offset: number, name?: string) => string;
187
+ start: (fn: ITempoStartFn, offset?: number, name?: string) => ITempoResponses;
188
+ progress: (fn: ITempoProgressFn, offset?: number, name?: string) => ITempoResponses;
189
189
  };
190
190
  type ISoundAnalyzer = {
191
191
  node: AnalyserNode;
@@ -548,7 +548,7 @@ declare class Img {
548
548
  static load(src: string, editable?: boolean, space?: CanvasSpace, ready?: (img: any) => {}): Img;
549
549
  static loadAsync(src: string, editable?: boolean, space?: CanvasSpace): Promise<Img>;
550
550
  static loadPattern(src: string, space: CanvasSpace, repeat?: CanvasPatternRepetition, editable?: boolean): Promise<CanvasPattern>;
551
- static blank(size: PtLike, space: CanvasSpace, scale?: number): Img;
551
+ static blank(size: PtLike, space?: CanvasSpace, scale?: number): Img;
552
552
  load(src: string): Promise<Img>;
553
553
  protected _drawToScale(canvasScale: number | PtLike, img: HTMLImageElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas | HTMLVideoElement): void;
554
554
  initCanvas(width: number, height: number, canvasScale?: number | PtLike): void;
@@ -1033,6 +1033,7 @@ declare class Util {
1033
1033
  static arrayCheck(pts: PtLikeIterable, minRequired?: number): boolean;
1034
1034
  static iterToArray(it: Iterable<any>): any[];
1035
1035
  static isMobile(): boolean;
1036
+ static uniqueId(useCrypto?: boolean): string;
1036
1037
  }
1037
1038
 
1038
1039
  /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
package/dist/index.d.ts CHANGED
@@ -106,7 +106,7 @@ type PtLike = Pt | Float32Array | number[];
106
106
  type GroupLike = Group | Pt[];
107
107
  type PtIterable = GroupLike | Pt[] | Iterable<Pt>;
108
108
  type PtLikeIterable = GroupLike | PtLike[] | Iterable<PtLike>;
109
- type AnimateCallbackFn = (time?: number, frameTime?: number, currentSpace?: any) => void;
109
+ type AnimateCallbackFn = (time: number, frameTime: number, currentSpace: any) => void;
110
110
  interface IPlayer {
111
111
  animateID?: string;
112
112
  animate?: AnimateCallbackFn;
@@ -184,8 +184,8 @@ type ITempoListener = {
184
184
  fn: Function;
185
185
  };
186
186
  type ITempoResponses = {
187
- start: (fn: ITempoStartFn, offset: number, name?: string) => string;
188
- progress: (fn: ITempoProgressFn, offset: number, name?: string) => string;
187
+ start: (fn: ITempoStartFn, offset?: number, name?: string) => ITempoResponses;
188
+ progress: (fn: ITempoProgressFn, offset?: number, name?: string) => ITempoResponses;
189
189
  };
190
190
  type ISoundAnalyzer = {
191
191
  node: AnalyserNode;
@@ -548,7 +548,7 @@ declare class Img {
548
548
  static load(src: string, editable?: boolean, space?: CanvasSpace, ready?: (img: any) => {}): Img;
549
549
  static loadAsync(src: string, editable?: boolean, space?: CanvasSpace): Promise<Img>;
550
550
  static loadPattern(src: string, space: CanvasSpace, repeat?: CanvasPatternRepetition, editable?: boolean): Promise<CanvasPattern>;
551
- static blank(size: PtLike, space: CanvasSpace, scale?: number): Img;
551
+ static blank(size: PtLike, space?: CanvasSpace, scale?: number): Img;
552
552
  load(src: string): Promise<Img>;
553
553
  protected _drawToScale(canvasScale: number | PtLike, img: HTMLImageElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas | HTMLVideoElement): void;
554
554
  initCanvas(width: number, height: number, canvasScale?: number | PtLike): void;
@@ -1033,6 +1033,7 @@ declare class Util {
1033
1033
  static arrayCheck(pts: PtLikeIterable, minRequired?: number): boolean;
1034
1034
  static iterToArray(it: Iterable<any>): any[];
1035
1035
  static isMobile(): boolean;
1036
+ static uniqueId(useCrypto?: boolean): string;
1036
1037
  }
1037
1038
 
1038
1039
  /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
package/dist/index.js CHANGED
@@ -3250,6 +3250,13 @@ var _Util = class _Util {
3250
3250
  static isMobile() {
3251
3251
  return /iPhone|iPad|Android/i.test(navigator.userAgent);
3252
3252
  }
3253
+ /**
3254
+ * Generate a time-based unique ID or a crypto-based ID.
3255
+ * @returns
3256
+ */
3257
+ static uniqueId(useCrypto = false) {
3258
+ return useCrypto && crypto ? crypto.randomUUID() : Date.now().toString(36) + Math.random().toString(36).substring(2);
3259
+ }
3253
3260
  };
3254
3261
  _Util._warnLevel = "mute";
3255
3262
  var Util = _Util;
@@ -5557,12 +5564,12 @@ var Img = class _Img {
5557
5564
  /**
5558
5565
  * Create an editable blank image
5559
5566
  * @param size of image
5560
- * @param space Set the `CanvasSpace` reference. This is optional but will make sure the image's pixelScale match the canvas and set the context for creating pattern.
5567
+ * @param space Optionally set the `CanvasSpace` reference. This is optional but will make sure the image's pixelScale match the canvas and set the context for creating pattern.
5561
5568
  * @param scale Optionally set a specific pixel scale (density) of the image canvas.
5562
5569
  */
5563
5570
  static blank(size, space, scale) {
5564
5571
  let img = new _Img(true, space);
5565
- const s = scale ? scale : space.pixelScale;
5572
+ const s = scale ? scale : space ? space.pixelScale : 1;
5566
5573
  img.initCanvas(size[0], size[1], s);
5567
5574
  return img;
5568
5575
  }
@@ -5862,34 +5869,49 @@ var CanvasSpace2 = class extends MultiTouchSpace {
5862
5869
  this._initialResize = false;
5863
5870
  let _selector = null;
5864
5871
  let _existed = false;
5865
- this.id = "pt";
5872
+ this.id = Util.uniqueId();
5866
5873
  if (elem instanceof Element) {
5867
5874
  _selector = elem;
5868
- this.id = "pts_existing_space";
5875
+ this.id = _selector.id || this.id;
5869
5876
  } else {
5870
5877
  let id = elem;
5871
5878
  id = elem[0] === "#" || elem[0] === "." ? elem : "#" + elem;
5872
5879
  _selector = document.querySelector(id);
5873
- _existed = true;
5874
5880
  this.id = id.substr(1);
5875
5881
  }
5876
5882
  if (!_selector) {
5877
5883
  this._container = this._createElement("div", this.id + "_container");
5878
5884
  this._canvas = this._createElement("canvas", this.id);
5879
- this._container.appendChild(this._canvas);
5880
5885
  document.body.appendChild(this._container);
5881
- _existed = false;
5882
5886
  } else if (_selector.nodeName.toLowerCase() != "canvas") {
5883
5887
  this._container = _selector;
5884
5888
  this._canvas = this._createElement("canvas", this.id + "_canvas");
5885
- this._container.appendChild(this._canvas);
5886
5889
  this._initialResize = true;
5887
5890
  } else {
5888
5891
  this._canvas = _selector;
5889
5892
  this._container = _selector.parentElement;
5890
5893
  this._autoResize = false;
5894
+ _existed = true;
5895
+ }
5896
+ if (!_existed) {
5897
+ const observer = new MutationObserver((mutations) => {
5898
+ mutations.forEach((mutation) => {
5899
+ if (mutation.type === "childList" && mutation.addedNodes.length) {
5900
+ for (let node of mutation.addedNodes) {
5901
+ if (node === this._canvas) {
5902
+ this._ready(callback);
5903
+ observer.disconnect();
5904
+ return;
5905
+ }
5906
+ }
5907
+ }
5908
+ });
5909
+ });
5910
+ observer.observe(this._container, { childList: true });
5911
+ this._container.appendChild(this._canvas);
5912
+ } else {
5913
+ this._ready(callback);
5891
5914
  }
5892
- setTimeout(this._ready.bind(this, callback), 100);
5893
5915
  this._ctx = this._canvas.getContext("2d");
5894
5916
  }
5895
5917
  /**
@@ -6199,9 +6221,13 @@ var CanvasForm = class _CanvasForm extends VisualForm {
6199
6221
  };
6200
6222
  if (space instanceof CanvasSpace2) {
6201
6223
  this._space = space;
6202
- this._space.add({ start: () => {
6224
+ if (this._space.ready && this._space.ctx) {
6203
6225
  _setup(this._space.ctx);
6204
- } });
6226
+ } else {
6227
+ this._space.add({ start: () => {
6228
+ _setup(this._space.ctx);
6229
+ } });
6230
+ }
6205
6231
  } else {
6206
6232
  _setup(space);
6207
6233
  }
package/dist/index.mjs CHANGED
@@ -3182,6 +3182,13 @@ var _Util = class _Util {
3182
3182
  static isMobile() {
3183
3183
  return /iPhone|iPad|Android/i.test(navigator.userAgent);
3184
3184
  }
3185
+ /**
3186
+ * Generate a time-based unique ID or a crypto-based ID.
3187
+ * @returns
3188
+ */
3189
+ static uniqueId(useCrypto = false) {
3190
+ return useCrypto && crypto ? crypto.randomUUID() : Date.now().toString(36) + Math.random().toString(36).substring(2);
3191
+ }
3185
3192
  };
3186
3193
  _Util._warnLevel = "mute";
3187
3194
  var Util = _Util;
@@ -5489,12 +5496,12 @@ var Img = class _Img {
5489
5496
  /**
5490
5497
  * Create an editable blank image
5491
5498
  * @param size of image
5492
- * @param space Set the `CanvasSpace` reference. This is optional but will make sure the image's pixelScale match the canvas and set the context for creating pattern.
5499
+ * @param space Optionally set the `CanvasSpace` reference. This is optional but will make sure the image's pixelScale match the canvas and set the context for creating pattern.
5493
5500
  * @param scale Optionally set a specific pixel scale (density) of the image canvas.
5494
5501
  */
5495
5502
  static blank(size, space, scale) {
5496
5503
  let img = new _Img(true, space);
5497
- const s = scale ? scale : space.pixelScale;
5504
+ const s = scale ? scale : space ? space.pixelScale : 1;
5498
5505
  img.initCanvas(size[0], size[1], s);
5499
5506
  return img;
5500
5507
  }
@@ -5794,34 +5801,49 @@ var CanvasSpace2 = class extends MultiTouchSpace {
5794
5801
  this._initialResize = false;
5795
5802
  let _selector = null;
5796
5803
  let _existed = false;
5797
- this.id = "pt";
5804
+ this.id = Util.uniqueId();
5798
5805
  if (elem instanceof Element) {
5799
5806
  _selector = elem;
5800
- this.id = "pts_existing_space";
5807
+ this.id = _selector.id || this.id;
5801
5808
  } else {
5802
5809
  let id = elem;
5803
5810
  id = elem[0] === "#" || elem[0] === "." ? elem : "#" + elem;
5804
5811
  _selector = document.querySelector(id);
5805
- _existed = true;
5806
5812
  this.id = id.substr(1);
5807
5813
  }
5808
5814
  if (!_selector) {
5809
5815
  this._container = this._createElement("div", this.id + "_container");
5810
5816
  this._canvas = this._createElement("canvas", this.id);
5811
- this._container.appendChild(this._canvas);
5812
5817
  document.body.appendChild(this._container);
5813
- _existed = false;
5814
5818
  } else if (_selector.nodeName.toLowerCase() != "canvas") {
5815
5819
  this._container = _selector;
5816
5820
  this._canvas = this._createElement("canvas", this.id + "_canvas");
5817
- this._container.appendChild(this._canvas);
5818
5821
  this._initialResize = true;
5819
5822
  } else {
5820
5823
  this._canvas = _selector;
5821
5824
  this._container = _selector.parentElement;
5822
5825
  this._autoResize = false;
5826
+ _existed = true;
5827
+ }
5828
+ if (!_existed) {
5829
+ const observer = new MutationObserver((mutations) => {
5830
+ mutations.forEach((mutation) => {
5831
+ if (mutation.type === "childList" && mutation.addedNodes.length) {
5832
+ for (let node of mutation.addedNodes) {
5833
+ if (node === this._canvas) {
5834
+ this._ready(callback);
5835
+ observer.disconnect();
5836
+ return;
5837
+ }
5838
+ }
5839
+ }
5840
+ });
5841
+ });
5842
+ observer.observe(this._container, { childList: true });
5843
+ this._container.appendChild(this._canvas);
5844
+ } else {
5845
+ this._ready(callback);
5823
5846
  }
5824
- setTimeout(this._ready.bind(this, callback), 100);
5825
5847
  this._ctx = this._canvas.getContext("2d");
5826
5848
  }
5827
5849
  /**
@@ -6131,9 +6153,13 @@ var CanvasForm = class _CanvasForm extends VisualForm {
6131
6153
  };
6132
6154
  if (space instanceof CanvasSpace2) {
6133
6155
  this._space = space;
6134
- this._space.add({ start: () => {
6156
+ if (this._space.ready && this._space.ctx) {
6135
6157
  _setup(this._space.ctx);
6136
- } });
6158
+ } else {
6159
+ this._space.add({ start: () => {
6160
+ _setup(this._space.ctx);
6161
+ } });
6162
+ }
6137
6163
  } else {
6138
6164
  _setup(space);
6139
6165
  }
package/dist/pts.js CHANGED
@@ -3260,6 +3260,13 @@ See https://github.com/williamngan/pts for details. */
3260
3260
  static isMobile() {
3261
3261
  return /iPhone|iPad|Android/i.test(navigator.userAgent);
3262
3262
  }
3263
+ /**
3264
+ * Generate a time-based unique ID or a crypto-based ID.
3265
+ * @returns
3266
+ */
3267
+ static uniqueId(useCrypto = false) {
3268
+ return useCrypto && crypto ? crypto.randomUUID() : Date.now().toString(36) + Math.random().toString(36).substring(2);
3269
+ }
3263
3270
  };
3264
3271
  _Util._warnLevel = "mute";
3265
3272
  var Util = _Util;
@@ -5589,12 +5596,12 @@ See https://github.com/williamngan/pts for details. */
5589
5596
  /**
5590
5597
  * Create an editable blank image
5591
5598
  * @param size of image
5592
- * @param space Set the `CanvasSpace` reference. This is optional but will make sure the image's pixelScale match the canvas and set the context for creating pattern.
5599
+ * @param space Optionally set the `CanvasSpace` reference. This is optional but will make sure the image's pixelScale match the canvas and set the context for creating pattern.
5593
5600
  * @param scale Optionally set a specific pixel scale (density) of the image canvas.
5594
5601
  */
5595
5602
  static blank(size, space, scale) {
5596
5603
  let img = new _Img(true, space);
5597
- const s = scale ? scale : space.pixelScale;
5604
+ const s = scale ? scale : space ? space.pixelScale : 1;
5598
5605
  img.initCanvas(size[0], size[1], s);
5599
5606
  return img;
5600
5607
  }
@@ -5894,34 +5901,49 @@ See https://github.com/williamngan/pts for details. */
5894
5901
  this._initialResize = false;
5895
5902
  let _selector = null;
5896
5903
  let _existed = false;
5897
- this.id = "pt";
5904
+ this.id = Util.uniqueId();
5898
5905
  if (elem instanceof Element) {
5899
5906
  _selector = elem;
5900
- this.id = "pts_existing_space";
5907
+ this.id = _selector.id || this.id;
5901
5908
  } else {
5902
5909
  let id = elem;
5903
5910
  id = elem[0] === "#" || elem[0] === "." ? elem : "#" + elem;
5904
5911
  _selector = document.querySelector(id);
5905
- _existed = true;
5906
5912
  this.id = id.substr(1);
5907
5913
  }
5908
5914
  if (!_selector) {
5909
5915
  this._container = this._createElement("div", this.id + "_container");
5910
5916
  this._canvas = this._createElement("canvas", this.id);
5911
- this._container.appendChild(this._canvas);
5912
5917
  document.body.appendChild(this._container);
5913
- _existed = false;
5914
5918
  } else if (_selector.nodeName.toLowerCase() != "canvas") {
5915
5919
  this._container = _selector;
5916
5920
  this._canvas = this._createElement("canvas", this.id + "_canvas");
5917
- this._container.appendChild(this._canvas);
5918
5921
  this._initialResize = true;
5919
5922
  } else {
5920
5923
  this._canvas = _selector;
5921
5924
  this._container = _selector.parentElement;
5922
5925
  this._autoResize = false;
5926
+ _existed = true;
5927
+ }
5928
+ if (!_existed) {
5929
+ const observer = new MutationObserver((mutations) => {
5930
+ mutations.forEach((mutation) => {
5931
+ if (mutation.type === "childList" && mutation.addedNodes.length) {
5932
+ for (let node of mutation.addedNodes) {
5933
+ if (node === this._canvas) {
5934
+ this._ready(callback);
5935
+ observer.disconnect();
5936
+ return;
5937
+ }
5938
+ }
5939
+ }
5940
+ });
5941
+ });
5942
+ observer.observe(this._container, { childList: true });
5943
+ this._container.appendChild(this._canvas);
5944
+ } else {
5945
+ this._ready(callback);
5923
5946
  }
5924
- setTimeout(this._ready.bind(this, callback), 100);
5925
5947
  this._ctx = this._canvas.getContext("2d");
5926
5948
  }
5927
5949
  /**
@@ -6231,9 +6253,13 @@ See https://github.com/williamngan/pts for details. */
6231
6253
  };
6232
6254
  if (space instanceof CanvasSpace2) {
6233
6255
  this._space = space;
6234
- this._space.add({ start: () => {
6256
+ if (this._space.ready && this._space.ctx) {
6235
6257
  _setup(this._space.ctx);
6236
- } });
6258
+ } else {
6259
+ this._space.add({ start: () => {
6260
+ _setup(this._space.ctx);
6261
+ } });
6262
+ }
6237
6263
  } else {
6238
6264
  _setup(space);
6239
6265
  }
package/dist/pts.min.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Licensed under Apache 2.0 License.
3
3
  See https://github.com/williamngan/pts for details. */
4
4
  (()=>{var qt=Object.defineProperty;var Ft=Object.getOwnPropertySymbols;var jt=Object.prototype.hasOwnProperty,Vt=Object.prototype.propertyIsEnumerable;var Ht=(l,r,t)=>r in l?qt(l,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[r]=t,$=(l,r)=>{for(var t in r||(r={}))jt.call(r,t)&&Ht(l,t,r[t]);if(Ft)for(var t of Ft(r))Vt.call(r,t)&&Ht(l,t,r[t]);return l};var T=(l,r)=>{for(var t in r)qt(l,t,{get:r[t],enumerable:!0})};var et=(l,r,t)=>new Promise((e,i)=>{var n=a=>{try{o(t.next(a))}catch(u){i(u)}},s=a=>{try{o(t.throw(a))}catch(u){i(u)}},o=a=>a.done?e(a.value):Promise.resolve(a.value).then(n,s);o((t=t.apply(l,r)).next())});var Dt={};T(Dt,{CanvasForm:()=>Q,CanvasSpace:()=>tt});var Lt={};T(Lt,{MultiTouchSpace:()=>Y,Space:()=>at});var xt={};T(xt,{Bound:()=>G,Group:()=>d,Pt:()=>h});var wt={};T(wt,{Const:()=>w,Util:()=>m});var Pt={};T(Pt,{Geom:()=>y,Num:()=>L,Range:()=>yt,Shaping:()=>st});var _t={};T(_t,{Circle:()=>B,Curve:()=>K,Line:()=>E,Polygon:()=>S,Rectangle:()=>M,Triangle:()=>j});var gt={};T(gt,{Mat:()=>C,Vec:()=>k});var k=class l{static add(r,t){if(typeof t=="number")for(let e=0,i=r.length;e<i;e++)r[e]+=t;else for(let e=0,i=r.length;e<i;e++)r[e]+=t[e]||0;return r}static subtract(r,t){if(typeof t=="number")for(let e=0,i=r.length;e<i;e++)r[e]-=t;else for(let e=0,i=r.length;e<i;e++)r[e]-=t[e]||0;return r}static multiply(r,t){if(typeof t=="number")for(let e=0,i=r.length;e<i;e++)r[e]*=t;else{if(r.length!=t.length)throw new Error(`Cannot do element-wise multiply since the array lengths don't match: ${r.toString()} multiply-with ${t.toString()}`);for(let e=0,i=r.length;e<i;e++)r[e]*=t[e]}return r}static divide(r,t){if(typeof t=="number"){if(t===0)throw new Error("Cannot divide by zero");for(let e=0,i=r.length;e<i;e++)r[e]/=t}else{if(r.length!=t.length)throw new Error(`Cannot do element-wise divide since the array lengths don't match. ${r.toString()} divide-by ${t.toString()}`);for(let e=0,i=r.length;e<i;e++)r[e]/=t[e]}return r}static dot(r,t){if(r.length!=t.length)throw new Error("Array lengths don't match");let e=0;for(let i=0,n=r.length;i<n;i++)e+=r[i]*t[i];return e}static cross2D(r,t){return r[0]*t[1]-r[1]*t[0]}static cross(r,t){return new h(r[1]*t[2]-r[2]*t[1],r[2]*t[0]-r[0]*t[2],r[0]*t[1]-r[1]*t[0])}static magnitude(r){return Math.sqrt(l.dot(r,r))}static unit(r,t=void 0){let e=t===void 0?l.magnitude(r):t;return e===0?h.make(r.length):l.divide(r,e)}static abs(r){return l.map(r,Math.abs)}static floor(r){return l.map(r,Math.floor)}static ceil(r){return l.map(r,Math.ceil)}static round(r){return l.map(r,Math.round)}static max(r){let t=Number.MIN_VALUE,e=0;for(let i=0,n=r.length;i<n;i++)t=Math.max(t,r[i]),t===r[i]&&(e=i);return{value:t,index:e}}static min(r){let t=Number.MAX_VALUE,e=0;for(let i=0,n=r.length;i<n;i++)t=Math.min(t,r[i]),t===r[i]&&(e=i);return{value:t,index:e}}static sum(r){let t=0;for(let e=0,i=r.length;e<i;e++)t+=r[e];return t}static map(r,t){for(let e=0,i=r.length;e<i;e++)r[e]=t(r[e],e,r);return r}},C=class l{constructor(){this.reset()}get value(){return this._33}get domMatrix(){return new DOMMatrix(l.toDOMMatrix(this._33))}reset(){this._33=l.scale2DMatrix(1,1)}scale2D(r,t=[0,0]){let e=l.scaleAt2DMatrix(r[0]||1,r[1]||1,t);return this._33=l.multiply(this._33,e),this}rotate2D(r,t=[0,0]){let e=l.rotateAt2DMatrix(Math.cos(r),Math.sin(r),t);return this._33=l.multiply(this._33,e),this}translate2D(r){let t=l.translate2DMatrix(r[0]||0,r[1]||0);return this._33=l.multiply(this._33,t),this}shear2D(r,t=[0,0]){let e=l.shearAt2DMatrix(Math.tan(r[0]||0),Math.tan(r[1]||1),t);return this._33=l.multiply(this._33,e),this}static add(r,t){if(typeof t!="number"){if(r[0].length!=t[0].length)throw new Error("Cannot add matrix if rows' and columns' size don't match.");if(r.length!=t.length)throw new Error("Cannot add matrix if rows' and columns' size don't match.")}let e=new d,i=typeof t=="number";for(let n=0,s=r.length;n<s;n++)e.push(r[n].$add(i?t:t[n]));return e}static multiply(r,t,e=!1,i=!1){let n=new d;if(typeof t!="number")if(i){if(r.length!=t.length)throw new Error("Cannot multiply matrix element-wise because the matrices' sizes don't match.");for(let s=0,o=r.length;s<o;s++)n.push(r[s].$multiply(t[s]))}else{if(!e&&r[0].length!=t.length)throw new Error("Cannot multiply matrix if rows in matrix-a don't match columns in matrix-b.");if(e&&r[0].length!=t[0].length)throw new Error("Cannot multiply matrix if transposed and the columns in both matrices don't match.");e||(t=l.transpose(t));for(let s=0,o=r.length;s<o;s++){let a=h.make(t.length,0);for(let u=0,c=t.length;u<c;u++)a[u]=k.dot(r[s],t[u]);n.push(a)}}else for(let s=0,o=r.length;s<o;s++)n.push(r[s].$multiply(t));return n}static zipSlice(r,t,e=!1){let i=[];for(let n=0,s=r.length;n<s;n++){if(r[n].length-1<t&&e===!1)throw`Index ${t} is out of bounds`;i.push(r[n][t]||e)}return new h(i)}static zip(r,t=!1,e=!1){let i=new d,n=e?r.reduce((s,o)=>Math.max(s,o.length),0):r[0].length;for(let s=0;s<n;s++)i.push(l.zipSlice(r,s,t));return i}static transpose(r,t=!1,e=!1){return l.zip(r,t,e)}static toDOMMatrix(r){return[r[0][0],r[0][1],r[1][0],r[1][1],r[2][0],r[2][1]]}static transform2D(r,t){let e=r[0]*t[0][0]+r[1]*t[1][0]+t[2][0],i=r[0]*t[0][1]+r[1]*t[1][1]+t[2][1];return new h(e,i)}static scale2DMatrix(r,t){return new d(new h(r,0,0),new h(0,t,0),new h(0,0,1))}static rotate2DMatrix(r,t){return new d(new h(r,t,0),new h(-t,r,0),new h(0,0,1))}static shear2DMatrix(r,t){return new d(new h(1,r,0),new h(t,1,0),new h(0,0,1))}static translate2DMatrix(r,t){return new d(new h(1,0,0),new h(0,1,0),new h(r,t,1))}static scaleAt2DMatrix(r,t,e){let i=l.scale2DMatrix(r,t);return i[2][0]=-e[0]*r+e[0],i[2][1]=-e[1]*t+e[1],i}static rotateAt2DMatrix(r,t,e){let i=l.rotate2DMatrix(r,t);return i[2][0]=e[0]*(1-r)+e[1]*t,i[2][1]=e[1]*(1-r)-e[0]*t,i}static shearAt2DMatrix(r,t,e){let i=l.shear2DMatrix(r,t);return i[2][0]=-e[1]*t,i[2][1]=-e[0]*r,i}static reflectAt2DMatrix(r,t){let e=E.intercept(r,t);if(e==null)return[new h([-1,0,0]),new h([0,1,0]),new h([r[0]+t[0],0,1])];{let i=e.yi,n=Math.atan(e.slope)*2,s=Math.cos(n),o=Math.sin(n);return[new h([s,o,0]),new h([o,-s,0]),new h([-i*o,i+i*s,1])]}}};var N=(l,r="expected")=>m.warn("Group's length is less than "+r,l),Wt=(l,r="")=>m.warn(`Index ${r} is out of bound in Group`,l),E=class l{static fromAngle(r,t,e){let i=new d(new h(r),new h(r));return i[1].toAngle(t,e,!0),i}static slope(r,t){return t[0]-r[0]===0?void 0:(t[1]-r[1])/(t[0]-r[0])}static intercept(r,t){if(t[0]-r[0]!==0){let e=(t[1]-r[1])/(t[0]-r[0]),i=r[1]-e*r[0];return{slope:e,yi:i,xi:e===0?void 0:-i/e}}}static sideOfPt2D(r,t){let e=m.iterToArray(r);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(r,t,e,i=.01){let n=new h(0,0,0).to(r).$subtract(t),s=new h(0,0,0).to(r).$subtract(e);return n.$cross(s).divide(1e3).equals(new h(0,0,0),i)}static magnitude(r){let t=m.iterToArray(r);return t.length>=2?t[1].$subtract(t[0]).magnitude():0}static magnitudeSq(r){let t=m.iterToArray(r);return t.length>=2?t[1].$subtract(t[0]).magnitudeSq():0}static perpendicularFromPt(r,t,e=!1){let i=m.iterToArray(r);if(i[0].equals(i[1]))return;let n=i[0].$subtract(i[1]),s=i[1].$subtract(t),o=s.$subtract(n.$project(s));return e?o:o.$add(t)}static distanceFromPt(r,t){let e=m.iterToArray(r),i=l.perpendicularFromPt(e,t,!0);return i?i.magnitude():e[0].$subtract(t).magnitude()}static intersectRay2D(r,t){let e=m.iterToArray(r),i=m.iterToArray(t),n=l.intercept(e[0],e[1]),s=l.intercept(i[0],i[1]),o=e[0],a=i[0];if(n==null){if(s==null)return;let u=-s.slope*(a[0]-o[0])+a[1];return new h(o[0],u)}else if(s==null){let u=-n.slope*(o[0]-a[0])+o[1];return new h(a[0],u)}else if(s.slope!=n.slope){let u=(n.slope*o[0]-s.slope*a[0]+a[1]-o[1])/(n.slope-s.slope),c=n.slope*(u-o[0])+o[1];return new h(u,c)}else return n.yi==s.yi?new h(o[0],o[1]):void 0}static intersectLine2D(r,t){let e=m.iterToArray(r),i=m.iterToArray(t),n=l.intersectRay2D(e,i);return n&&y.withinBound(n,e[0],e[1])&&y.withinBound(n,i[0],i[1])?n:void 0}static intersectLineWithRay2D(r,t){let e=m.iterToArray(r),i=m.iterToArray(t),n=l.intersectRay2D(e,i);return n&&y.withinBound(n,e[0],e[1])?n:void 0}static intersectPolygon2D(r,t,e=!1){let i=m.iterToArray(r),n=m.iterToArray(t),s=e?l.intersectLineWithRay2D:l.intersectLine2D,o=new d;for(let a=0,u=n.length;a<u;a++){let c=a===u-1?0:a+1,f=s([n[a],n[c]],i);f&&o.push(f)}return o.length>0?o:void 0}static intersectLines2D(r,t,e=!1){let i=new d,n=e?l.intersectLineWithRay2D:l.intersectLine2D;for(let s of r)for(let o of t){let a=n(s,o);a&&i.push(a)}return i}static intersectGridWithRay2D(r,t){let e=m.iterToArray(r),i=l.intercept(new h(e[0]).subtract(t),new h(e[1]).subtract(t)),n=new d;return i&&i.xi&&n.push(new h(t[0]+i.xi,t[1])),i&&i.yi&&n.push(new h(t[0],t[1]+i.yi)),n}static intersectGridWithLine2D(r,t){let e=m.iterToArray(r),i=l.intersectGridWithRay2D(e,t),n=new d;for(let s=0,o=i.length;s<o;s++)y.withinBound(i[s],e[0],e[1])&&n.push(i[s]);return n}static intersectRect2D(r,t){let e=m.iterToArray(r),i=m.iterToArray(t),n=y.boundingBox(d.fromPtArray(e));return M.hasIntersectRect2D(n,i)?l.intersectLines2D([e],M.sides(i)):new d}static subpoints(r,t){let e=m.iterToArray(r),i=new d;for(let n=1;n<=t;n++)i.push(y.interpolate(e[0],e[1],n/(t+1)));return i}static crop(r,t,e=0,i=!0){let n=m.iterToArray(r),o=n[e===0?1:0].$subtract(n[e]);if(o[0]===0||t[0]===0)return n[e];if(i){let a=o.unit().multiply(t[1]);return n[e].$add(a)}else{let a=M.fromCenter(n[e],t),u=M.sides(a),c=0;return Math.abs(o[1]/o[0])>Math.abs(t[1]/t[0])?c=o[1]<0?0:2:c=o[0]<0?3:1,l.intersectRay2D(u[c],n)}}static marker(r,t,e="arrow",i=!0){let n=m.iterToArray(r),s=i?0:1,o=i?1:0,a=n[s].$subtract(n[o]);if(a.magnitudeSq()===0)return new d;a.unit();let u=y.perpendicular(a).multiply(t[0]).add(n[o]);return e=="arrow"?(u.add(a.$multiply(t[1])),new d(n[o],u[0],u[1])):new d(u[0],u[1])}static toRect(r){let t=m.iterToArray(r);return new d(t[0].$min(t[1]),t[0].$max(t[1]))}},M=class l{static from(r,t,e){return l.fromTopLeft(r,t,e)}static fromTopLeft(r,t,e){let i=typeof t=="number"?[t,e||t]:t;return new d(new h(r),new h(r).add(i))}static fromCenter(r,t,e){let i=typeof t=="number"?[t/2,(e||t)/2]:new h(t).divide(2);return new d(new h(r).subtract(i),new h(r).add(i))}static toCircle(r,t=!0){return B.fromRect(r,t)}static toSquare(r,t=!1){let e=m.iterToArray(r),i=l.size(e),n=t?i.maxValue().value:i.minValue().value;return l.fromCenter(l.center(e),n,n)}static size(r){let t=m.iterToArray(r);return t[0].$max(t[1]).subtract(t[0].$min(t[1]))}static center(r){let t=m.iterToArray(r),e=t[0].$min(t[1]),i=t[0].$max(t[1]);return e.add(i.$subtract(e).divide(2))}static corners(r){let t=m.iterToArray(r),e=t[0].$min(t[1]),i=t[0].$max(t[1]);return new d(e,new h(i.x,e.y),i,new h(e.x,i.y))}static sides(r){let[t,e,i,n]=l.corners(r);return[new d(t,e),new d(e,i),new d(i,n),new d(n,t)]}static boundingBox(r){let t=m.iterToArray(r),e=m.flatten(t,!1),i=h.make(2,Number.MAX_VALUE),n=h.make(2,Number.MIN_VALUE);for(let s=0,o=e.length;s<o;s++){let a=0;for(let u of e[s])if(i[a]=Math.min(i[a],u[a]),n[a]=Math.max(n[a],u[a]),++a>=2)break}return new d(i,n)}static polygon(r){return l.corners(r)}static quadrants(r,t){let e=m.iterToArray(r),i=l.corners(e),n=t!=null?new h(t):l.center(e);return i.map(s=>new d(s,n).boundingBox())}static halves(r,t=.5,e=!1){let i=m.iterToArray(r),n=i[0].$min(i[1]),s=i[0].$max(i[1]),o=e?L.lerp(n[1],s[1],t):L.lerp(n[0],s[0],t);return e?[new d(n,new h(s[0],o)),new d(new h(n[0],o),s)]:[new d(n,new h(o,s[1])),new d(new h(o,n[1]),s)]}static withinBound(r,t){let e=m.iterToArray(r);return y.withinBound(t,e[0],e[1])}static hasIntersectRect2D(r,t,e=!1){let i=m.iterToArray(r),n=m.iterToArray(t);return e&&(i=y.boundingBox(i),n=y.boundingBox(n)),!(i[0][0]>n[1][0]||n[0][0]>i[1][0]||i[0][1]>n[1][1]||n[0][1]>i[1][1])}static intersectRect2D(r,t){let e=m.iterToArray(r),i=m.iterToArray(t);return l.hasIntersectRect2D(e,i)?E.intersectLines2D(l.sides(e),l.sides(i)):new d}},B=class l{static fromRect(r,t=!1){let e=m.iterToArray(r),i=0,n=i=M.size(e).minValue().value/2;if(t){let s=M.size(e).maxValue().value/2;i=Math.sqrt(n*n+s*s)}else i=n;return new d(M.center(e),new h(i,i))}static fromTriangle(r,t=!1){return t?j.circumcircle(r):j.incircle(r)}static fromCenter(r,t){return new d(new h(r),new h(t,t))}static withinBound(r,t,e=0){let i=m.iterToArray(r),n=i[0].$subtract(t);return n.dot(n)+e<i[1].x*i[1].x}static intersectRay2D(r,t){let e=m.iterToArray(r),i=m.iterToArray(t),n=i[0].$subtract(i[1]),s=e[0].$subtract(i[0]),o=n.dot(n),a=s.dot(n),u=s.dot(s)-e[1].x*e[1].x,c=a/o,f=u/o,p=c*c-f;if(p<0)return new d;{let b=Math.sqrt(p),P=-c+b,_=i[0].$subtract(n.$multiply(P));if(p===0)return new d(_);let D=-c-b,A=i[0].$subtract(n.$multiply(D));return new d(_,A)}}static intersectLine2D(r,t){let e=m.iterToArray(r),i=m.iterToArray(t),n=l.intersectRay2D(e,i),s=new d;if(n.length>0)for(let o=0,a=n.length;o<a;o++)M.withinBound(i,n[o])&&s.push(n[o]);return s}static intersectCircle2D(r,t){let e=m.iterToArray(r),i=m.iterToArray(t),n=i[0].$subtract(e[0]),s=n.magnitudeSq(),o=Math.sqrt(s),a=e[1].x,u=i[1].x,c=a*a,f=u*u;if(o>a+u)return new d;if(o<Math.abs(a-u))return new d(e[0].clone());{let p=(c-f+s)/(2*o),b=Math.sqrt(c-p*p),P=n.$multiply(p/o).add(e[0]);return new d(new h(P.x+b*n.y/o,P.y-b*n.x/o),new h(P.x-b*n.y/o,P.y+b*n.x/o))}}static intersectRect2D(r,t){let e=m.iterToArray(r),i=m.iterToArray(t),n=M.sides(i),s=[];for(let o=0,a=n.length;o<a;o++){let u=l.intersectLine2D(e,n[o]);u.length>0&&s.push(u)}return m.flatten(s)}static toRect(r,t=!1){let e=m.iterToArray(r),i=e[1][0];if(t){let n=Math.sqrt(i*i)/2;return new d(e[0].$subtract(n),e[0].$add(n))}else return new d(e[0].$subtract(i),e[0].$add(i))}static toTriangle(r,t=!0){let e=m.iterToArray(r);if(t){let i=-Math.PI/2,n=Math.PI*2/3,s=new d;for(let o=0;o<3;o++)s.push(e[0].clone().toAngle(i,e[1][0],!0)),i+=n;return s}else return j.fromCenter(e[0],e[1][0])}},j=class l{static fromRect(r){let t=m.iterToArray(r),e=t[0].$add(t[1]).divide(2);e.y=t[0][1];let i=t[1].clone();return i.x=t[0][0],new d(e,t[1].clone(),i)}static fromCircle(r){return B.toTriangle(r,!0)}static fromCenter(r,t){return l.fromCircle(B.fromCenter(r,t))}static medial(r){let t=m.iterToArray(r);return t.length<3?N(new d,3):S.midpoints(t,!0)}static oppositeSide(r,t){let e=m.iterToArray(r);return e.length<3?N(new d,3):t===0?d.fromPtArray([e[1],e[2]]):t===1?d.fromPtArray([e[0],e[2]]):d.fromPtArray([e[0],e[1]])}static altitude(r,t){let e=m.iterToArray(r),i=l.oppositeSide(e,t);return i.length>1?new d(e[t],E.perpendicularFromPt(i,e[t])):new d}static orthocenter(r){let t=m.iterToArray(r);if(t.length<3)return N(void 0,3);let e=l.altitude(t,0),i=l.altitude(t,1);return E.intersectRay2D(e,i)}static incenter(r){let t=m.iterToArray(r);if(t.length<3)return N(void 0,3);let e=S.bisector(t,0).add(t[0]),i=S.bisector(t,1).add(t[1]);return E.intersectRay2D(new d(t[0],e),new d(t[1],i))}static incircle(r,t){let e=m.iterToArray(r),i=t||l.incenter(e),n=S.area(e),s=S.perimeter(e,!0),o=2*n/s.total;return B.fromCenter(i,o)}static circumcenter(r){let t=m.iterToArray(r),e=l.medial(t),i=[e[0],y.perpendicular(t[0].$subtract(e[0])).p1.$add(e[0])],n=[e[1],y.perpendicular(t[1].$subtract(e[1])).p1.$add(e[1])];return E.intersectRay2D(i,n)}static circumcircle(r,t){let e=m.iterToArray(r),i=t||l.circumcenter(e),n=e[0].$subtract(i).magnitude();return B.fromCenter(i,n)}},S=class l{static centroid(r){return y.centroid(r)}static rectangle(r,t,e){return M.corners(M.fromCenter(r,t,e))}static fromCenter(r,t,e){let i=new d;for(let n=0;n<e;n++){let s=Math.PI*2*n/e;i.push(new h(Math.cos(s)*t,Math.sin(s)*t).add(r))}return i}static lineAt(r,t){let e=m.iterToArray(r);if(t<0||t>=e.length)throw new Error("index out of the Polygon's range");return new d(e[t],t===e.length-1?e[0]:e[t+1])}static lines(r,t=!0){let e=m.iterToArray(r);if(e.length<2)return N(new d,2);let i=m.split(e,2,1);return t&&i.push(new d(e[e.length-1],e[0])),i.map(n=>n)}static midpoints(r,t=!1,e=.5){return l.lines(r,t).map(s=>y.interpolate(s[0],s[1],e))}static adjacentSides(r,t,e=!1){let i=m.iterToArray(r);if(i.length<2)return N(new d,2);if(t<0||t>=i.length)return Wt(new d,t);let n=[],s=t-1;e&&s<0&&(s=i.length-1),s>=0&&n.push(new d(i[t],i[s]));let o=t+1;return e&&o>i.length-1&&(o=0),o<=i.length-1&&n.push(new d(i[t],i[o])),n}static bisector(r,t){let e=l.adjacentSides(r,t,!0);if(e.length>=2){let i=e[0][1].$subtract(e[0][0]).unit(),n=e[1][1].$subtract(e[1][0]).unit();return i.add(n).divide(2)}else return}static perimeter(r,t=!1){let e=l.lines(r,t),i=0,n=h.make(e.length,0);for(let s=0,o=e.length;s<o;s++){let a=E.magnitude(e[s]);i+=a,n[s]=a}return{total:i,segments:n}}static area(r){let t=m.iterToArray(r);if(t.length<3)return N(new d,3);let e=(n,s)=>n[0]*s[1]-n[1]*s[0],i=0;for(let n=0,s=t.length;n<s;n++)n<t.length-1?i+=e(t[n],t[n+1]):i+=e(t[n],t[0]);return Math.abs(i/2)}static convexHull(r,t=!1){let e=m.iterToArray(r);if(e.length<3)return N(new d,3);t||(e=e.slice(),e.sort((u,c)=>u[0]-c[0]));let i=(u,c,f)=>(c[0]-u[0])*(f[1]-u[1])-(f[0]-u[0])*(c[1]-u[1])>0,n=[],s=e.length-2,o=s+3;n[s]=e[2],n[o]=e[2],i(e[0],e[1],e[2])?(n[s+1]=e[0],n[s+2]=e[1]):(n[s+1]=e[1],n[s+2]=e[0]);for(let u=3,c=e.length;u<c;u++){let f=e[u];if(!(i(n[s],n[s+1],f)&&i(n[o-1],n[o],f))){for(;!i(n[s],n[s+1],f);)s+=1;for(s-=1,n[s]=f;!i(n[o-1],n[o],f);)o-=1;o+=1,n[o]=f}}let a=new d;for(let u=0;u<o-s;u++)a.push(n[s+u]);return a}static network(r,t=0){let e=m.iterToArray(r),i=[];for(let n=0,s=e.length;n<s;n++)n!=t&&i.push(new d(e[t],e[n]));return i}static nearestPt(r,t){let e=Number.MAX_VALUE,i=-1,n=0;for(let s of r){let o=s.$subtract(t).magnitudeSq();o<e&&(e=o,i=n),n++}return i}static projectAxis(r,t){let e=m.iterToArray(r),i=t.dot(e[0]),n=new h(i,i);for(let s=1,o=e.length;s<o;s++)i=t.dot(e[s]),n=new h(Math.min(i,n[0]),Math.max(i,n[1]));return n}static _axisOverlap(r,t,e){let i=l.projectAxis(r,e),n=l.projectAxis(t,e);return i[0]<n[0]?n[0]-i[1]:i[0]-n[1]}static hasIntersectPoint(r,t){let e=m.iterToArray(r),i=!1;for(let n=0,s=e.length;n<s;n++){let o=l.lineAt(e,n);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]&&(i=!i)}return i}static hasIntersectCircle(r,t){let e=m.iterToArray(r),i=m.iterToArray(t),n={which:-1,dist:0,normal:null,edge:null,vertex:null},s=i[0],o=i[1][0],a=Number.MAX_SAFE_INTEGER;for(let c=0,f=e.length;c<f;c++){let p=l.lineAt(e,c),b=new h(p[0].y-p[1].y,p[1].x-p[0].x).unit(),P=new d(s.$add(b.$multiply(o)),s.$subtract(b.$multiply(o))),_=l._axisOverlap(e,P,b);if(_>0)return null;Math.abs(_)<a&&(M.withinBound(p,E.perpendicularFromPt(p,s))||B.intersectLine2D(t,p).length>0)&&(n.edge=p,n.normal=b,a=Math.abs(_),n.which=c)}return n.edge?(s.$subtract(l.centroid(e)).dot(n.normal)<0&&n.normal.multiply(-1),n.dist=a,n.vertex=s,n):null}static hasIntersectPolygon(r,t){let e=m.iterToArray(r),i=m.iterToArray(t),n={which:-1,dist:0,normal:new h,edge:new d,vertex:new h},s=Number.MAX_SAFE_INTEGER;for(let b=0,P=e.length+i.length;b<P;b++){let _=b<e.length?l.lineAt(e,b):l.lineAt(i,b-e.length),D=new h(_[0].y-_[1].y,_[1].x-_[0].x).unit(),A=l._axisOverlap(e,i,D);if(A>0)return null;Math.abs(A)<s&&(n.edge=_,n.normal=D,s=Math.abs(A),n.which=b<e.length?0:1)}n.dist=s;let o=n.which===0?i:e,a=n.which===0?e:i,u=l.centroid(o),c=l.centroid(a);u.$subtract(c).dot(n.normal)<0&&n.normal.multiply(-1);let p=Number.MAX_SAFE_INTEGER;for(let b=0,P=o.length;b<P;b++){let _=n.normal.dot(o[b].$subtract(c));_<p&&(p=_,n.vertex=o[b])}return n}static intersectPolygon2D(r,t){let e=m.iterToArray(r),i=m.iterToArray(t),n=l.lines(e),s=[];for(let o=0,a=n.length;o<a;o++){let u=E.intersectPolygon2D(n[o],i,!1);u&&s.push(u)}return m.flatten(s,!0)}static toRects(r){let t=[];for(let i of r)t.push(y.boundingBox(i));let e=m.flatten(t,!1);return t.unshift(y.boundingBox(e)),t}},K=class l{static getSteps(r){let t=new d;for(let e=0;e<=r;e++){let i=e/r;t.push(new h(i*i*i,i*i,i,1))}return t}static controlPoints(r,t=0,e=!1){let i=m.iterToArray(r);if(t>i.length-1)return new d;let n=o=>o<i.length-1?o:i.length-1,s=i[t];return t=e?t:t+1,new d(s,i[n(t++)],i[n(t++)],i[n(t++)])}static _calcPt(r,t){let e=r.reduce((n,s,o)=>n+s.x*t[o],0),i=r.reduce((n,s,o)=>n+s.y*t[o],0);if(r[0].length>2){let n=r.reduce((s,o,a)=>s+o.z*t[a],0);return new h(e,i,n)}return new h(e,i)}static catmullRom(r,t=10){let e=m.iterToArray(r);if(e.length<2)return new d;let i=new d,n=l.getSteps(t),s=l.controlPoints(e,0,!0);for(let a=0;a<=t;a++)i.push(l.catmullRomStep(n[a],s));let o=0;for(;o<e.length-2;){let a=l.controlPoints(e,o);if(a.length>0){for(let u=0;u<=t;u++)i.push(l.catmullRomStep(n[u],a));o++}}return i}static catmullRomStep(r,t){let e=new d(new h(-.5,1,-.5,0),new h(1.5,-2.5,0,1),new h(-1.5,2,.5,0),new h(.5,-.5,0,0));return l._calcPt(t,C.multiply([r],e,!0)[0])}static cardinal(r,t=10,e=.5){let i=m.iterToArray(r);if(i.length<2)return new d;let n=new d,s=l.getSteps(t),o=l.controlPoints(i,0,!0);for(let u=0;u<=t;u++)n.push(l.cardinalStep(s[u],o,e));let a=0;for(;a<i.length-2;){let u=l.controlPoints(i,a);if(u.length>0){for(let c=0;c<=t;c++)n.push(l.cardinalStep(s[c],u,e));a++}}return n}static cardinalStep(r,t,e=.5){let i=new d(new h(-1,2,-1,0),new h(-1,1,0,0),new h(1,-2,1,0),new h(1,-1,0,0)),n=C.multiply([r],i,!0)[0].multiply(e),s=2*r[0]-3*r[1]+1,o=-2*r[0]+3*r[1],a=l._calcPt(t,n);return a.x+=s*t[1].x+o*t[2].x,a.y+=s*t[1].y+o*t[2].y,a.length>2&&(a.z+=s*t[1].z+o*t[2].z),a}static bezier(r,t=10){let e=m.iterToArray(r);if(e.length<4)return new d;let i=new d,n=l.getSteps(t),s=0;for(;s<e.length-3;){let o=l.controlPoints(e,s);if(o.length>0){for(let a=0;a<=t;a++)i.push(l.bezierStep(n[a],o));s+=3}}return i}static bezierStep(r,t){let e=new d(new h(-1,3,-3,1),new h(3,-6,3,0),new h(-3,3,0,0),new h(1,0,0,0));return l._calcPt(t,C.multiply([r],e,!0)[0])}static bspline(r,t=10,e=1){let i=m.iterToArray(r);if(i.length<2)return new d;let n=new d,s=l.getSteps(t),o=0;for(;o<i.length-3;){let a=l.controlPoints(i,o);if(a.length>0){if(e!==1)for(let u=0;u<=t;u++)n.push(l.bsplineTensionStep(s[u],a,e));else for(let u=0;u<=t;u++)n.push(l.bsplineStep(s[u],a));o++}}return n}static bsplineStep(r,t){let e=new d(new h(-.16666666666666666,.5,-.5,.16666666666666666),new h(.5,-1,0,.6666666666666666),new h(-.5,.5,.5,.16666666666666666),new h(.16666666666666666,0,0,0));return l._calcPt(t,C.multiply([r],e,!0)[0])}static bsplineTensionStep(r,t,e=1){let i=new d(new h(-.16666666666666666,.5,-.5,.16666666666666666),new h(-1.5,2,0,-.3333333333333333),new h(1.5,-2.5,.5,.16666666666666666),new h(.16666666666666666,0,0,0)),n=C.multiply([r],i,!0)[0].multiply(e),s=2*r[0]-3*r[1]+1,o=-2*r[0]+3*r[1],a=l._calcPt(t,n);return a.x+=s*t[1].x+o*t[2].x,a.y+=s*t[1].y+o*t[2].y,a.length>2&&(a.z+=s*t[1].z+o*t[2].z),a}};function Xt(){let l=4022871197;return function(t){if(t){t=t.toString();for(let e=0;e<t.length;e++){l+=t.charCodeAt(e);let i=.02519603282416938*l;l=i>>>0,i-=l,i*=l,l=i>>>0,i-=l,l+=i*4294967296}return(l>>>0)*23283064365386963e-26}else l=4022871197}}function Ut(l){let r=48,t=1,e=r,i=new Array(r),n,s,o=0,a=Xt();for(n=0;n<r;n++)i[n]=a(Math.random().toString());function u(){for(a(),n=0;n<r;n++)i[n]=a(" ");t=1,e=r}function c(p){return p=p.replace(/(^\s*)|(\s*$)/gi,""),p=p.replace(/[\x00-\x1F]/gi,""),p=p.replace(/\n /,`
5
- `),p}function f(p){for(p=c(p),a(p),n=0;n<p.length;n++)for(o=p.charCodeAt(n),s=0;s<r;s++)i[s]-=a(o.toString()),i[s]<0&&(i[s]+=1)}return u(),f(l),{random(){++e>=r&&(e=0);let p=1768863*i[e]+t*23283064365386963e-26;return i[e]=p-(t=p|0)}}}var L=class l{static equals(r,t,e=1e-5){return Math.abs(r-t)<e}static lerp(r,t,e){return(1-e)*r+e*t}static clamp(r,t,e){return Math.max(t,Math.min(e,r))}static boundValue(r,t,e){let i=Math.abs(e-t),n=r%i;return n>e?n-=i:n<t&&(n+=i),n}static within(r,t,e){return r>=Math.min(t,e)&&r<=Math.max(t,e)}static randomRange(r,t=0){let e=r>t?r-t:t-r;return r+l.random()*e}static randomPt(r,t){let e=new h(r.length),i=t?k.subtract(t.slice(),r):r,n=t?r:new h(r.length).fill(0);for(let s=0,o=e.length;s<o;s++)e[s]=l.random()*i[s]+n[s];return e}static normalizeValue(r,t,e){let i=Math.min(t,e),n=Math.max(t,e);return(r-i)/(n-i)}static sum(r){let t=m.iterToArray(r),e=new h(t[0]);for(let i=1,n=t.length;i<n;i++)k.add(e,t[i]);return e}static average(r){let t=m.iterToArray(r);return l.sum(t).divide(t.length)}static cycle(r,t=st.sineInOut){return t(r>.5?2-r*2:r*2)}static mapToRange(r,t,e,i,n){if(t==e)throw new Error("[currMin, currMax] must define a range that is not zero");let s=Math.min(i,n),o=Math.max(i,n);return l.normalizeValue(r,t,e)*(o-s)+s}static seed(r){this.generator=Ut(r)}static random(){return this.generator?this.generator.random():Math.random()}},y=class l{static boundAngle(r){return L.boundValue(r,0,360)}static boundRadian(r){return L.boundValue(r,0,w.two_pi)}static toRadian(r){return r*w.deg_to_rad}static toDegree(r){return r*w.rad_to_deg}static boundingBox(r){let t,e;for(let i of r)t==null?(t=i.clone(),e=i.clone()):(t=t.$min(i),e=e.$max(i));return new d(t,e)}static centroid(r){return L.average(r)}static anchor(r,t=0,e="to"){let i=e=="to"?"subtract":"add",n=0;for(let s of r)typeof t=="number"?t!==n&&s[i](r[t]):s[i](t),n++}static interpolate(r,t,e=.5){let i=Math.min(r.length,t.length),n=h.make(i);for(let s=0;s<i;s++)n[s]=r[s]*(1-e)+t[s]*e;return n}static perpendicular(r,t=w.xy){let e=t[1],i=t[0],n=new h(r),s=new h(n);s[i]=-n[e],s[e]=n[i];let o=new h(n);return o[i]=n[e],o[e]=-n[i],new d(s,o)}static isPerpendicular(r,t){return new h(r).dot(t)===0}static withinBound(r,t,e){for(let i=0,n=Math.min(r.length,t.length,e.length);i<n;i++)if(!L.within(r[i],t[i],e[i]))return!1;return!0}static sortEdges(r){let t=m.iterToArray(r),e=l.boundingBox(t),i=e[1].add(e[0]).divide(2),n=(s,o)=>{if(s.length<2||o.length<2)throw new Error("Pt dimension cannot be less than 2");let a=s.$subtract(i),u=o.$subtract(i);if(a[0]>=0&&u[0]<0)return 1;if(a[0]<0&&u[0]>=0)return-1;if(a[0]==0&&u[0]==0)return a[1]>=0||u[1]>=0?a[1]>u[1]?1:-1:u[1]>a[1]?1:-1;let c=a.$cross2D(u);return c<0?1:c>0?-1:a[0]*a[0]+a[1]*a[1]>u[0]*u[0]+u[1]*u[1]?1:-1};return t.sort(n)}static scale(r,t,e){let i=m.iterToArray(r[0]!==void 0&&typeof r[0]=="number"?[r]:r),n=typeof t=="number"?h.make(i[0].length,t):t;e||(e=h.make(i[0].length,0));for(let s=0,o=i.length;s<o;s++){let a=i[s];for(let u=0,c=a.length;u<c;u++)a[u]=e&&e[u]?e[u]+(a[u]-e[u])*n[u]:a[u]*n[u]}return l}static rotate2D(r,t,e,i){let n=m.iterToArray(r[0]!==void 0&&typeof r[0]=="number"?[r]:r),s=e?C.rotateAt2DMatrix:C.rotate2DMatrix;e||(e=h.make(n[0].length,0));let o=Math.cos(t),a=Math.sin(t);for(let u=0,c=n.length;u<c;u++){let f=i?n[u].$take(i):n[u];if(f.to(C.transform2D(f,s(o,a,e))),i)for(let p=0;p<i.length;p++)n[u][i[p]]=f[p]}return l}static shear2D(r,t,e,i){let n=m.iterToArray(r[0]!==void 0&&typeof r[0]=="number"?[r]:r),s=typeof t=="number"?[t,t]:t;e||(e=h.make(n[0].length,0));let o=e?C.shearAt2DMatrix:C.shear2DMatrix,a=Math.tan(s[0]),u=Math.tan(s[1]);for(let c=0,f=n.length;c<f;c++){let p=i?n[c].$take(i):n[c];if(p.to(C.transform2D(p,o(a,u,e))),i)for(let b=0;b<i.length;b++)n[c][i[b]]=p[b]}return l}static reflect2D(r,t,e){let i=m.iterToArray(r[0]!==void 0&&typeof r[0]=="number"?[r]:r),n=m.iterToArray(t),s=C.reflectAt2DMatrix(n[0],n[1]);for(let o=0,a=i.length;o<a;o++){let u=e?i[o].$take(e):i[o];if(u.to(C.transform2D(u,s)),e)for(let c=0;c<e.length;c++)i[o][e[c]]=u[c]}return l}static cosTable(){let r=new Float64Array(360);for(let e=0;e<360;e++)r[e]=Math.cos(e*Math.PI/180);return{table:r,cos:e=>r[Math.floor(l.boundAngle(l.toDegree(e)))]}}static sinTable(){let r=new Float64Array(360);for(let e=0;e<360;e++)r[e]=Math.sin(e*Math.PI/180);return{table:r,sin:e=>r[Math.floor(l.boundAngle(l.toDegree(e)))]}}},st=class l{static linear(r,t=1){return t*r}static quadraticIn(r,t=1){return t*r*r}static quadraticOut(r,t=1){return-t*r*(r-2)}static quadraticInOut(r,t=1){let e=r*2;return r<.5?t/2*r*r*4:-t/2*((e-1)*(e-3)-1)}static cubicIn(r,t=1){return t*r*r*r}static cubicOut(r,t=1){let e=r-1;return t*(e*e*e+1)}static cubicInOut(r,t=1){let e=r*2;return r<.5?t/2*e*e*e:t/2*((e-2)*(e-2)*(e-2)+2)}static exponentialIn(r,t=1,e=.25){return t*Math.pow(r,1/e)}static exponentialOut(r,t=1,e=.25){return t*Math.pow(r,e)}static sineIn(r,t=1){return-t*Math.cos(r*w.half_pi)+t}static sineOut(r,t=1){return t*Math.sin(r*w.half_pi)}static sineInOut(r,t=1){return-t/2*(Math.cos(Math.PI*r)-1)}static cosineApprox(r,t=1){let e=r*r,i=e*e,n=i*e;return t*(4*n/9-17*i/9+22*e/9)}static circularIn(r,t=1){return-t*(Math.sqrt(1-r*r)-1)}static circularOut(r,t=1){let e=r-1;return t*Math.sqrt(1-e*e)}static circularInOut(r,t=1){let e=r*2;return r<.5?-t/2*(Math.sqrt(1-e*e)-1):t/2*(Math.sqrt(1-(e-2)*(e-2))+1)}static elasticIn(r,t=1,e=.7){let i=r-1,n=e/w.two_pi*1.5707963267948966;return t*(-Math.pow(2,10*i)*Math.sin((i-n)*w.two_pi/e))}static elasticOut(r,t=1,e=.7){let i=e/w.two_pi*1.5707963267948966;return t*(Math.pow(2,-10*r)*Math.sin((r-i)*w.two_pi/e))+t}static elasticInOut(r,t=1,e=.6){let i=r*2,n=e/w.two_pi*1.5707963267948966;return r<.5?(i-=1,t*(-.5*(Math.pow(2,10*i)*Math.sin((i-n)*w.two_pi/e)))):(i-=1,t*(.5*(Math.pow(2,-10*i)*Math.sin((i-n)*w.two_pi/e)))+t)}static bounceIn(r,t=1){return t-l.bounceOut(1-r,t)}static bounceOut(r,t=1){return r<1/2.75?t*(7.5625*r*r):r<2/2.75?(r-=1.5/2.75,t*(7.5625*r*r+.75)):r<2.5/2.75?(r-=2.25/2.75,t*(7.5625*r*r+.9375)):(r-=2.625/2.75,t*(7.5625*r*r+.984375))}static bounceInOut(r,t=1){return r<.5?l.bounceIn(r*2,t)/2:l.bounceOut(r*2-1,t)/2+t/2}static sigmoid(r,t=1,e=10){let i=e*(r-.5);return t/(1+Math.exp(-i))}static logSigmoid(r,t=1,e=.7){e=Math.max(w.epsilon,Math.min(1-w.epsilon,e)),e=1/(1-e);let i=1/(1+Math.exp((r-.5)*e*-2)),n=1/(1+Math.exp(e)),s=1/(1+Math.exp(-e));return t*(i-n)/(s-n)}static seat(r,t=1,e=.5){return r<.5?t*Math.pow(2*r,1-e)/2:t*(1-Math.pow(2*(1-r),1-e)/2)}static quadraticBezier(r,t=1,e=[.05,.95]){let i=typeof e!="number"?e[0]:e,n=typeof e!="number"?e[1]:.5,s=1-2*i;s===0&&(s=w.epsilon);let o=(Math.sqrt(i*i+s*r)-i)/s;return t*((1-2*n)*(o*o)+2*n*o)}static cubicBezier(r,t=1,e=[.1,.7],i=[.9,.2]){let n=new d(new h(0,0),new h(e),new h(i),new h(1,1));return t*K.bezierStep(new h(r*r*r,r*r,r,1),K.controlPoints(n)).y}static quadraticTarget(r,t=1,e=[.2,.35]){let i=Math.min(1-w.epsilon,Math.max(w.epsilon,e[0])),n=Math.min(1,Math.max(0,e[1])),s=(1-n)/(1-i)-n/i,o=(s*(i*i)-n)/i,a=s*(r*r)-o*r;return t*Math.min(1,Math.max(0,a))}static cliff(r,t=1,e=.5){return r>e?t:0}static step(r,t,e,i,...n){let s=1/t,o=Math.floor(e/s)*s;return r(o,i,...n)}},yt=class{constructor(r){this._dims=0;this._source=d.fromPtArray(r),this.calc()}get max(){return this._max.clone()}get min(){return this._min.clone()}get magnitude(){return this._mag.clone()}calc(){if(!this._source)return;let r=this._source[0].length;this._dims=r;let t=new h(r),e=new h(r),i=new h(r);for(let n=0;n<r;n++){t[n]=w.min,e[n]=w.max,i[n]=0;let s=this._source.zipSlice(n);for(let o=0,a=s.length;o<a;o++)t[n]=Math.max(t[n],s[o]),e[n]=Math.min(e[n],s[o]),i[n]=t[n]-e[n]}return this._max=t,this._min=e,this._mag=i,this}mapTo(r,t,e){let i=new d;for(let n=0,s=this._source.length;n<s;n++){let o=this._source[n],a=new h(this._dims);for(let u=0;u<this._dims;u++)a[u]=e&&e[u]?o[u]:L.mapToRange(o[u],this._min[u],this._max[u],r,t);i.push(a)}return i}append(r,t=!0){let e=m.iterToArray(r);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(r){let t=new d;for(let e=0;e<=r;e++){let i=new h(this._dims);for(let n=0,s=this._max.length;n<s;n++)i[n]=L.lerp(this._min[n],this._max[n],e/r);t.push(i)}return t}};var w={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:Number.MAX_VALUE,min:Number.MIN_VALUE,pi:Math.PI,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},H=class H{static warnLevel(r){return r&&(H._warnLevel=r),H._warnLevel}static getArgs(r){if(r.length<1)return[];let t=[],e=Array.isArray(r[0])||ArrayBuffer.isView(r[0]);if(typeof r[0]=="number")t=Array.prototype.slice.call(r);else if(typeof r[0]=="object"&&!e){let i=["x","y","z","w"],n=r[0];for(let s=0;s<i.length&&!(n.length&&s>=n.length||!(i[s]in n));s++)t.push(n[i[s]])}else e&&(t=[].slice.call(r[0]));return t}static warn(r="error",t=void 0){if(H.warnLevel()=="error")throw new Error(r);return H.warnLevel()=="warn"&&console.warn(r),t}static randomInt(r,t=0){return H.warn("Util.randomInt is deprecated. Please use `Num.randomRange`"),Math.floor(L.random()*r)+t}static split(r,t,e,i=!1,n=!0){let s=[],o=[],a=e||t,u=0;if(r.length<=0||a<=0)return[];for(;u<r.length;){o=[];for(let c=0;c<t;c++)if(i)o.push(r[(u+c)%r.length]);else{if(u+c>=r.length)break;o.push(r[u+c])}u+=a,(!n||n&&o.length===t)&&s.push(o)}return s}static flatten(r,t=!0){let e=t?new d:[];return e.concat.apply(e,r)}static combine(r,t,e){let i=[];for(let n=0,s=r.length;n<s;n++)for(let o=0,a=t.length;o<a;o++)i.push(e(r[n],t[o]));return i}static zip(r){let t=[];for(let e=0,i=r[0].length;e<i;e++){let n=[];for(let s=0;s<r.length;s++)n.push(r[s][e]);t.push(n)}return t}static stepper(r,t=0,e=1,i){let n=t;return function(){return n+=e,n>=r&&(n=t+(n-r)),i&&i(n),n}}static forRange(r,t,e=0,i=1){let n=[];for(let s=e,o=t;s<o;s+=i)n[s]=r(s);return n}static load(r,t){let e=new XMLHttpRequest;e.open("GET",r,!0),e.onload=function(){e.status>=200&&e.status<400?t(e.responseText,!0):t(`Server error (${e.status}) when loading "${r}"`,!1)},e.onerror=function(){t("Unknown network error",!1)},e.send()}static download(r,t="pts_canvas_image",e="png",i=1){let n=e==="jpg"?"jpeg":e;r.element.toBlob(function(s){let o=document.createElement("a"),a=URL.createObjectURL(s);o.href=a,o.download=`${t}.${e}`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a)},`image/${n}`,i)}static performance(r=10){let t=Date.now(),e=[];return function(){let i=Date.now();return e.push(i-t),e.length>=r&&e.shift(),t=i,Math.floor(e.reduce((n,s)=>n+s,0)/e.length)}}static arrayCheck(r,t=2){return Array.isArray(r)&&r.length<t?(H.warn(`Requires ${t} or more Pts in this Group.`),!1):!0}static iterToArray(r){return Array.isArray(r)?r:[...r]}static isMobile(){return/iPhone|iPad|Android/i.test(navigator.userAgent)}};H._warnLevel="mute";var m=H;var h=class l extends Float32Array{constructor(...r){let t;r.length===1&&typeof r[0]=="number"?t=r[0]:t=r.length>0?m.getArgs(r):[0,0],super(t)}static make(r,t=0,e=!1){let i=new Float32Array(r);if(t&&i.fill(t),e)for(let n=0,s=i.length;n<s;n++)i[n]=i[n]*L.random();return new l(i)}get id(){return this._id}set id(r){this._id=r}get x(){return this[0]}set x(r){this[0]=r}get y(){return this[1]}set y(r){this[1]=r}get z(){return this[2]}set z(r){this[2]=r}get w(){return this[3]}set w(r){this[3]=r}clone(){return new l(this)}equals(r,t=1e-6){for(let e=0,i=this.length;e<i;e++)if(Math.abs(this[e]-r[e])>t)return!1;return!0}to(...r){let t=m.getArgs(r);for(let e=0,i=Math.min(this.length,t.length);e<i;e++)this[e]=t[e];return this}$to(...r){return this.clone().to(...r)}toAngle(r,t,e=!1){let i=t!=null?t:this.magnitude(),n=[Math.cos(r)*i,Math.sin(r)*i];return e?this.add(n):this.to(n)}op(r){let t=this;return(...e)=>r(t,...e)}ops(r){let t=[];for(let e=0,i=r.length;e<i;e++)t.push(this.op(r[e]));return t}$take(r){let t=[];for(let e=0,i=r.length;e<i;e++)t.push(this[r[e]]||0);return new l(t)}$concat(...r){return new l(this.toArray().concat(m.getArgs(r)))}add(...r){return r.length===1&&typeof r[0]=="number"?k.add(this,r[0]):k.add(this,m.getArgs(r)),this}$add(...r){return this.clone().add(...r)}subtract(...r){return r.length===1&&typeof r[0]=="number"?k.subtract(this,r[0]):k.subtract(this,m.getArgs(r)),this}$subtract(...r){return this.clone().subtract(...r)}multiply(...r){return r.length===1&&typeof r[0]=="number"?k.multiply(this,r[0]):k.multiply(this,m.getArgs(r)),this}$multiply(...r){return this.clone().multiply(...r)}divide(...r){return r.length===1&&typeof r[0]=="number"?k.divide(this,r[0]):k.divide(this,m.getArgs(r)),this}$divide(...r){return this.clone().divide(...r)}magnitudeSq(){return k.dot(this,this)}magnitude(){return k.magnitude(this)}unit(r=void 0){return k.unit(this,r),this}$unit(r=void 0){return this.clone().unit(r)}dot(...r){return k.dot(this,m.getArgs(r))}$cross2D(...r){return k.cross2D(this,m.getArgs(r))}$cross(...r){return k.cross(this,m.getArgs(r))}$project(...r){return this.$multiply(this.dot(...r)/this.magnitudeSq())}projectScalar(...r){return this.dot(...r)/this.magnitude()}abs(){return k.abs(this),this}$abs(){return this.clone().abs()}floor(){return k.floor(this),this}$floor(){return this.clone().floor()}ceil(){return k.ceil(this),this}$ceil(){return this.clone().ceil()}round(){return k.round(this),this}$round(){return this.clone().round()}minValue(){return k.min(this)}maxValue(){return k.max(this)}$min(...r){let t=m.getArgs(r),e=this.clone();for(let i=0,n=Math.min(this.length,t.length);i<n;i++)e[i]=Math.min(this[i],t[i]);return e}$max(...r){let t=m.getArgs(r),e=this.clone();for(let i=0,n=Math.min(this.length,t.length);i<n;i++)e[i]=Math.max(this[i],t[i]);return e}angle(r=w.xy){return Math.atan2(this[r[1]],this[r[0]])}angleBetween(r,t=w.xy){return y.boundRadian(this.angle(t))-y.boundRadian(r.angle(t))}scale(r,t){return y.scale(this,r,t||l.make(this.length,0)),this}rotate2D(r,t,e){return y.rotate2D(this,r,t||l.make(this.length,0),e),this}shear2D(r,t,e){return y.shear2D(this,r,t||l.make(this.length,0),e),this}reflect2D(r,t){return y.reflect2D(this,r,t),this}toString(){return`Pt(${this.join(", ")})`}toArray(){return[].slice.call(this)}toGroup(){return new d(l.make(this.length),this.clone())}toBound(){return new G(l.make(this.length),this.clone())}},d=class l extends Array{constructor(...r){super(...r)}get id(){return this._id}set id(r){this._id=r}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 r=new l;for(let t=0,e=this.length;t<e;t++)r.push(this[t].clone());return r}static fromArray(r){let t=new l;for(let e of r){let i=e instanceof h?e:new h(e);t.push(i)}return t}static fromPtArray(r){return l.from(r)}split(r,t,e=!1){return m.split(this,r,t,e)}insert(r,t=0){return l.prototype.splice.apply(this,[t,0,...r]),this}remove(r=0,t=1){let e=r<0?[r*-1-1,t]:[r,t];return l.prototype.splice.apply(this,e)}segments(r=2,t=1,e=!1){return this.split(r,t,e)}lines(){return this.segments(2,1)}centroid(){return y.centroid(this)}boundingBox(){return y.boundingBox(this)}anchorTo(r=0){y.anchor(this,r,"to")}anchorFrom(r=0){y.anchor(this,r,"from")}op(r){let t=this;return(...e)=>r(t,...e)}ops(r){let t=[];for(let e=0,i=r.length;e<i;e++)t.push(this.op(r[e]));return t}interpolate(r){r=L.clamp(r,0,1);let t=this.length-1,e=1/(this.length-1),i=Math.floor(r/e);return y.interpolate(this[i],this[Math.min(this.length-1,i+1)],(r-i*e)*t)}moveBy(...r){return this.add(...r)}moveTo(...r){let t=new h(m.getArgs(r)).subtract(this[0]);return this.moveBy(t),this}scale(r,t){for(let e=0,i=this.length;e<i;e++)y.scale(this[e],r,t||this[0]);return this}rotate2D(r,t,e){for(let i=0,n=this.length;i<n;i++)y.rotate2D(this[i],r,t||this[0],e);return this}shear2D(r,t,e){for(let i=0,n=this.length;i<n;i++)y.shear2D(this[i],r,t||this[0],e);return this}reflect2D(r,t){for(let e=0,i=this.length;e<i;e++)y.reflect2D(this[e],r,t);return this}sortByDimension(r,t=!1){return this.sort((e,i)=>t?i[r]-e[r]:e[r]-i[r])}forEachPt(r,...t){if(!this[0][r])return m.warn(`${r} is not a function of Pt`),this;for(let e=0,i=this.length;e<i;e++)this[e]=this[e][r](...t);return this}add(...r){return this.forEachPt("add",...r)}subtract(...r){return this.forEachPt("subtract",...r)}multiply(...r){return this.forEachPt("multiply",...r)}divide(...r){return this.forEachPt("divide",...r)}$matrixAdd(r){return C.add(this,r)}$matrixMultiply(r,t=!1,e=!1){return C.multiply(this,r,t,e)}zipSlice(r,t=!1){return C.zipSlice(this,r,t)}$zip(r=void 0,t=!1){return C.zip(this,r,t)}toBound(){return G.fromGroup(this)}toString(){return"Group[ "+this.reduce((r,t)=>r+t.toString()+" ","")+" ]"}},G=class l extends d{constructor(...t){super(...t);this._center=new h;this._size=new h;this._topLeft=new h;this._bottomRight=new h;this._inited=!1;this.init()}static fromBoundingRect(t){let e=new l(new h(t.left||0,t.top||0),new h(t.right||0,t.bottom||0));return t.width&&t.height&&(e.size=new h(t.width,t.height)),e}static fromGroup(t){let e=m.iterToArray(t);if(e.length<2)throw new Error("Cannot create a Bound from a group that has less than 2 Pt");return new l(e[0],e[e.length-1])}init(){if(this.p1&&(this._size=this.p1.clone(),this._inited=!0),this.p1&&this.p2){let t=this.p1,e=this.p2;this.topLeft=t.$min(e),this._bottomRight=t.$max(e),this._updateSize(),this._inited=!0}}clone(){return new l(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 h(this._size)}set size(t){this._size=new h(t),this._updatePosFromTop()}get center(){return new h(this._center)}set center(t){this._center=new h(t),this._updatePosFromCenter()}get topLeft(){return new h(this._topLeft)}set topLeft(t){this._topLeft=new h(t),this[0]=this._topLeft,this._updateSize()}get bottomRight(){return new h(this._bottomRight)}set bottomRight(t){this._bottomRight=new h(t),this[1]=this._bottomRight,this._updateSize()}get width(){return this._size.length>0?this._size.x:0}set width(t){this._size.x=t,this._updatePosFromTop()}get height(){return this._size.length>1?this._size.y:0}set height(t){this._size.y=t,this._updatePosFromTop()}get depth(){return this._size.length>2?this._size.z:0}set depth(t){this._size.z=t,this._updatePosFromTop()}get x(){return this.topLeft.x}get y(){return this.topLeft.y}get z(){return this.topLeft.z}get inited(){return this._inited}update(){return this._topLeft=this[0],this._bottomRight=this[1],this._updateSize(),this}};var vt={};T(vt,{UI:()=>W,UIButton:()=>ot,UIDragger:()=>kt,UIPointerActions:()=>v,UIShape:()=>X});var X={rectangle:"rectangle",circle:"circle",polygon:"polygon",polyline:"polyline",line:"line"},v={up:"up",down:"down",move:"move",drag:"drag",uidrag:"uidrag",drop:"drop",uidrop:"uidrop",over:"over",out:"out",enter:"enter",leave:"leave",click:"click",keydown:"keydown",keyup:"keyup",pointerdown:"pointerdown",pointerup:"pointerup",contextmenu:"contextmenu",all:"all"},V=class V{constructor(r,t,e={},i){this._holds=new Map;this._group=d.fromArray(r),this._shape=t,this._id=i===void 0?`ui_${V._counter++}`:i,this._states=e,this._actions={}}static fromRectangle(r,t,e){return new this(r,X.rectangle,t,e)}static fromCircle(r,t,e){return new this(r,X.circle,t,e)}static fromPolygon(r,t,e){return new this(r,X.polygon,t,e)}static fromUI(r,t,e){return new this(r.group,r.shape,t||r._states,e)}get id(){return this._id}set id(r){this._id=r}get group(){return this._group}set group(r){this._group=r}get shape(){return this._shape}set shape(r){this._shape=r}state(r,t){return r?t!==void 0?(this._states[r]=t,this):this._states[r]:null}on(r,t){return this._actions[r]||(this._actions[r]=[]),V._addHandler(this._actions[r],t)}off(r,t){return this._actions[r]?t===void 0?(delete this._actions[r],!0):V._removeHandler(this._actions[r],t):!1}listen(r,t,e){if(this._actions[r]!==void 0){if(this._within(t)||Array.from(this._holds.values()).indexOf(r)>=0)return V._trigger(this._actions[r],this,t,r,e),!0;if(this._actions.all)return V._trigger(this._actions.all,this,t,r,e),!0}return!1}hold(r){let t=Math.max(0,...Array.from(this._holds.keys()))+1;return this._holds.set(t,r),t}unhold(r){r!==void 0?this._holds.delete(r):this._holds.clear()}static track(r,t,e,i){for(let n=0,s=r.length;n<s;n++)r[n].listen(t,e,i)}render(r){r(this._group,this._states)}toString(){return`UI ${this.group.toString}`}_within(r){let t=null;if(this._shape===X.rectangle)t=M.withinBound;else if(this._shape===X.circle)t=B.withinBound;else if(this._shape===X.polygon)t=S.hasIntersectPoint;else return!1;return t(this._group,r)}static _trigger(r,t,e,i,n){if(r)for(let s=0,o=r.length;s<o;s++)r[s]&&r[s](t,e,i,n)}static _addHandler(r,t){return t?(r.push(t),r.length-1):-1}static _removeHandler(r,t){if(t>=0&&t<r.length){let e=r.length;return r.splice(t,1),e>r.length}else return!1}};V._counter=0;var W=V,ot=class extends W{constructor(t,e,i={},n){super(t,e,i,n);this._hoverID=-1;i.hover===void 0&&(this._states.hover=!1),i.clicks===void 0&&(this._states.clicks=0);let s=v;this.on(s.up,(o,a,u,c)=>{this.state("clicks",this._states.clicks+1)}),this.on(s.move,(o,a,u,c)=>{if(this._within(a)&&!this._states.hover){this.state("hover",!0),W._trigger(this._actions[s.enter],this,a,s.enter,c);let p=this.hold(s.move);this._hoverID=this.on(s.move,(b,P)=>{!this._within(P)&&!this.state("dragging")&&(this.state("hover",!1),W._trigger(this._actions[s.leave],this,a,s.leave,c),this.off(s.move,this._hoverID),this.unhold(p))})}})}onClick(t){return this.on(v.up,t)}offClick(t){return this.off(v.up,t)}onContextMenu(t){return this.on(v.contextmenu,t)}offContextMenu(t){return this.off(v.contextmenu,t)}onHover(t,e){let i=[void 0,void 0];return t&&(i[0]=this.on(v.enter,t)),e&&(i[1]=this.on(v.leave,e)),i}offHover(t,e){let i=[!1,!1];return(t===void 0||t>=0)&&(i[0]=this.off(v.enter,t)),(e===void 0||e>=0)&&(i[1]=this.off(v.leave,e)),i}},kt=class extends ot{constructor(t,e,i={},n){super(t,e,i,n);this._draggingID=-1;this._moveHoldID=-1;this._dropHoldID=-1;this._upHoldID=-1;i.dragging===void 0&&(this._states.dragging=!1),i.moved===void 0&&(this._states.moved=!1),i.offset===void 0&&(this._states.offset=new h);let s=v;this.on(s.down,(a,u,c,f)=>{this._moveHoldID===-1&&(this.state("dragging",!0),this.state("offset",new h(u).subtract(a.group[0])),this._moveHoldID=this.hold(s.move)),this._dropHoldID===-1&&(this._dropHoldID=this.hold(s.drop)),this._upHoldID===-1&&(this._upHoldID=this.hold(s.up)),this._draggingID===-1&&(this._draggingID=this.on(s.move,(p,b)=>{this.state("dragging")&&(W._trigger(this._actions[s.uidrag],p,b,s.uidrag,f),this.state("moved",!0))}))});let o=(a,u,c,f)=>{this.state("dragging",!1),this.off(s.move,this._draggingID),this._draggingID=-1,this.unhold(this._moveHoldID),this._moveHoldID=-1,this.unhold(this._dropHoldID),this._dropHoldID=-1,this.unhold(this._upHoldID),this._upHoldID=-1,this.state("moved")&&(W._trigger(this._actions[s.uidrop],a,u,s.uidrop,f),this.state("moved",!1))};this.on(s.drop,o),this.on(s.up,o),this.on(s.out,o)}onDrag(t){return this.on(v.uidrag,t)}offDrag(t){return this.off(v.uidrag,t)}onDrop(t){return this.on(v.uidrop,t)}offDrop(t){return this.off(v.uidrop,t)}};var at=class{constructor(){this.id="space";this.bound=new G;this._time={prev:0,diff:0,end:-1,min:0};this.players={};this.playerCount=0;this._animID=-1;this._pause=!1;this._refresh=void 0;this._pointer=new h;this._isReady=!1;this._playing=!1}refresh(r){return this._refresh=r,this}minFrameTime(r=0){this._time.min=r}add(r){let t=typeof r=="function"?{animate:r}:r,e=this.playerCount++,i=t.animateID||this.id+e;return this.players[i]=t,t.animateID=i,t.resize&&this.bound.inited&&t.resize(this.bound),this._refresh===void 0&&(this._refresh=!0),this}remove(r){return delete this.players[r.animateID],this}removeAll(){return this.players={},this}play(r=0){if(!(r===0&&this._animID!==-1)){if(this._animID=requestAnimationFrame(this.play.bind(this)),this._pause)return this;if(this._time.diff=r-this._time.prev,this._time.diff<this._time.min)return this;this._time.prev=r;try{this.playItems(r)}catch(t){throw cancelAnimationFrame(this._animID),this._animID=-1,this._playing=!1,t}return this}}replay(){this._time.end=-1,this.play()}playItems(r){if(this._playing=!0,this._refresh&&this.clear(),this._isReady)for(let t in this.players)this.players[t].animate&&this.players[t].animate(r,this._time.diff,this);this._time.end>=0&&r>this._time.end&&(cancelAnimationFrame(this._animID),this._animID=-1,this._playing=!1)}pause(r=!1){return this._pause=r?!this._pause:!0,this}resume(){return this._pause=!1,this}stop(r=0){return this._time.end=r,this}playOnce(r=0){return this.play(),this.stop(r),this}render(r){return this._renderFunc&&this._renderFunc(r,this),this}set customRendering(r){this._renderFunc=r}get customRendering(){return this._renderFunc}get isPlaying(){return this._playing}get outerBound(){return this.bound.clone()}get innerBound(){return new G(h.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}},Y=class extends at{constructor(){super(...arguments);this._pressed=!1;this._dragged=!1;this._hasMouse=!1;this._hasTouch=!1;this._hasKeyboard=!1}get pointer(){let t=this._pointer.clone();return t.id=this._pointer.id,t}bindCanvas(t,e,i={},n){(n||this._canvas).addEventListener(t,e,i)}unbindCanvas(t,e,i={},n){(n||this._canvas).removeEventListener(t,e,i)}bindDoc(t,e,i={}){document&&document.addEventListener(t,e,i)}unbindDoc(t,e,i={}){document&&document.removeEventListener(t,e,i)}bindMouse(t=!0,e){return t?(this._mouseDown=this._mouseDown.bind(this),this._mouseUp=this._mouseUp.bind(this),this._mouseOver=this._mouseOver.bind(this),this._mouseOut=this._mouseOut.bind(this),this._mouseMove=this._mouseMove.bind(this),this._mouseClick=this._mouseClick.bind(this),this._contextMenu=this._contextMenu.bind(this),this.bindCanvas("pointerdown",this._mouseDown,{},e),this.bindCanvas("pointerup",this._mouseUp,{},e),this.bindCanvas("pointerover",this._mouseOver,{},e),this.bindCanvas("pointerout",this._mouseOut,{},e),this.bindCanvas("pointermove",this._mouseMove,{},e),this.bindCanvas("click",this._mouseClick,{},e),this.bindCanvas("contextmenu",this._contextMenu,{},e),this._hasMouse=!0):(this.unbindCanvas("pointerdown",this._mouseDown,{},e),this.unbindCanvas("pointerup",this._mouseUp,{},e),this.unbindCanvas("pointerover",this._mouseOver,{},e),this.unbindCanvas("pointerout",this._mouseOut,{},e),this.unbindCanvas("pointermove",this._mouseMove,{},e),this.unbindCanvas("click",this._mouseClick,{},e),this.unbindCanvas("contextmenu",this._contextMenu,{},e),this._hasMouse=!1),this}bindTouch(t=!0,e=!1,i){return t?(this.bindCanvas("touchstart",this._touchStart.bind(this),{passive:e},i),this.bindCanvas("touchend",this._mouseUp.bind(this),{},i),this.bindCanvas("touchmove",this._touchMove.bind(this),{passive:e},i),this.bindCanvas("touchcancel",this._mouseOut.bind(this),{},i),this._hasTouch=!0):(this.unbindCanvas("touchstart",this._touchStart.bind(this),{passive:e},i),this.unbindCanvas("touchend",this._mouseUp.bind(this),{},i),this.unbindCanvas("touchmove",this._touchMove.bind(this),{passive:e},i),this.unbindCanvas("touchcancel",this._mouseOut.bind(this),{},i),this._hasTouch=!1),this}bindKeyboard(t=!0){return t?(this._keyDownBind=this._keyDown.bind(this),this._keyUpBind=this._keyUp.bind(this),this.bindDoc("keydown",this._keyDownBind,{}),this.bindDoc("keyup",this._keyUpBind,{}),this._hasKeyboard=!0):(this.unbindDoc("keydown",this._keyDownBind,{}),this.unbindDoc("keyup",this._keyUpBind,{}),this._hasKeyboard=!1),this}touchesToPoints(t,e="touches"){if(!t||!t[e])return[];let i=[];for(let n=0;n<t[e].length;n++){let s=t[e].item(n);i.push(new h(s.pageX-this.bound.topLeft.x,s.pageY-this.bound.topLeft.y))}return i}_mouseAction(t,e){if(!this.isPlaying)return;let i=0,n=0;if(e instanceof MouseEvent){for(let s in this.players)if(this.players.hasOwnProperty(s)){let o=this.players[s];i=e.pageX-this.outerBound.x,n=e.pageY-this.outerBound.y,o.action&&o.action(t,i,n,e)}}else for(let s in this.players)if(this.players.hasOwnProperty(s)){let o=this.players[s],a=e.changedTouches&&e.changedTouches.length>0,u=e.changedTouches.item(0);i=a?u.pageX-this.outerBound.x:0,n=a?u.pageY-this.outerBound.y:0,o.action&&o.action(t,i,n,e)}t&&(this._pointer.to(i,n),this._pointer.id=t)}_mouseDown(t){return this._mouseAction(v.down,t),this._mouseAction(v.pointerdown,t),this._pressed=!0,t.target instanceof Element&&t.target.setPointerCapture(t.pointerId),!1}_mouseUp(t){return this._mouseAction(v.pointerup,t),this._dragged?this._mouseAction(v.drop,t):this._mouseAction(v.up,t),this._pressed=!1,this._dragged=!1,t.target instanceof Element&&t.target.releasePointerCapture(t.pointerId),!1}_mouseMove(t){return this._pressed?(this._dragged=!0,this._mouseAction(v.drag,t)):this._mouseAction(v.move,t),!1}_mouseOver(t){return this._mouseAction(v.over,t),!1}_mouseOut(t){return this._mouseAction(v.out,t),this._dragged&&this._mouseAction(v.drop,t),this._dragged=!1,!1}_mouseClick(t){return this._mouseAction(v.click,t),this._pressed=!1,this._dragged=!1,!1}_contextMenu(t){return this._mouseAction(v.contextmenu,t),!1}_touchMove(t){return this._mouseAction(v.move,t),this._pressed&&(this._dragged=!0,this._mouseAction(v.drag,t)),t.preventDefault(),!1}_touchStart(t){return this._mouseAction(v.down,t),this._pressed=!0,!1;return t.preventDefault(),!1}_keyDown(t){return this._keyboardAction(v.keydown,t),!1}_keyUp(t){return this._keyboardAction(v.keyup,t),!1}_keyboardAction(t,e){if(this.isPlaying){for(let i in this.players)if(this.players.hasOwnProperty(i)){let n=this.players[i];n.action&&n.action(t,e.shiftKey?1:0,e.altKey?1:0,e)}}}};var It={};T(It,{Font:()=>O,Form:()=>lt,VisualForm:()=>q});var lt=class{constructor(){this._ready=!1}get ready(){return this._ready}},q=class extends lt{constructor(){super(...arguments);this._filled=!0;this._stroked=!0;this._font=new O(14,"sans-serif")}get filled(){return this._filled}set filled(t){this._filled=t}get stroked(){return this._stroked}set stroked(t){this._stroked=t}get currentFont(){return this._font}_multiple(t,e,...i){if(!t)return this;for(let n=0,s=t.length;n<s;n++)this[e](t[n],...i);return this}alpha(t){return this}fill(t){return this}fillOnly(t){return this.stroke(!1),this.fill(t)}stroke(t,e,i,n){return this}strokeOnly(t,e,i,n){return this.fill(!1),this.stroke(t,e,i,n)}points(t,e,i){if(t){for(let n=0,s=t.length;n<s;n++)this.point(t[n],e,i);return this}}circles(t){return this._multiple(t,"circle")}squares(t){return this._multiple(t,"square")}lines(t){return this._multiple(t,"line")}polygons(t){return this._multiple(t,"polygon")}rects(t){return this._multiple(t,"rect")}},O=class{constructor(r=12,t="sans-serif",e="",i="",n=1.5){this.size=r,this.face=t,this.style=i,this.weight=e,this.lineHeight=n}get value(){return`${this.style} ${this.weight} ${this.size}px/${this.lineHeight} ${this.face}`}toString(){return this.value}};var Ct={};T(Ct,{Typography:()=>Z});var Z=class{static textWidthEstimator(r,t=["M","n","."],e=[.06,.8,.14]){let i=t.map(r),n=new h(e).dot(i);return s=>s.length*n}static truncate(r,t,e,i=""){let n=Math.floor(t.length*Math.min(1,e/r(t)));return n<t.length?(n=Math.max(0,n-i.length),[t.substr(0,n)+i,n]):[t,t.length]}static fontSizeToBox(r,t=1,e=!0){let i=G.fromGroup(r),n=e?i.height:i.width,s=t*n;return function(o){let a=G.fromGroup(o),u=(e?a.height:a.width)/n;return s*u}}static fontSizeToThreshold(r,t=0){return function(e,i){let n=e*i/r;return t<0?Math.min(n,e):t>0?Math.max(n,e):n}}};var Mt={};T(Mt,{Img:()=>J});var J=class l{constructor(r=!1,t,e){this._scale=1;this._loaded=!1;this._editable=r,this._space=t,this._scale=this._space?this._space.pixelScale:1,this._img=new Image,e&&(this._img.crossOrigin="Anonymous")}static load(r,t=!1,e,i){let n=new l(t,e);return n.load(r).then(s=>{i&&i(s)}),n}static loadAsync(r,t=!1,e){return et(this,null,function*(){return yield new l(t,e).load(r)})}static loadPattern(r,t,e="repeat",i=!1){return et(this,null,function*(){return(yield l.loadAsync(r,i,t)).pattern(e)})}static blank(r,t,e){let i=new l(!0,t),n=e||t.pixelScale;return i.initCanvas(r[0],r[1],n),i}load(r){return new Promise((t,e)=>{this._editable&&!document&&e("Cannot create html canvas element. document not found."),this._img.src=r,this._img.onload=()=>{this._editable&&(this._cv||(this._cv=document.createElement("canvas")),this._drawToScale(this._scale,this._img),this._data=this._ctx.getImageData(0,0,this._cv.width,this._cv.height)),this._loaded=!0,t(this)},this._img.onerror=i=>{e(i)}})}_drawToScale(r,t){let e=t.width,i=t.height;this.initCanvas(e,i,r),t&&this._ctx.drawImage(t,0,0,e,i,0,0,this._cv.width,this._cv.height)}initCanvas(r,t,e=1){if(!this._editable){console.error("Cannot initiate canvas because this Img is not set to be editable");return}this._cv||(this._cv=document.createElement("canvas"));let i=typeof e=="number"?[e,e]:e;this._cv.width=r*i[0],this._cv.height=t*i[1],this._ctx=this._cv.getContext("2d"),this._loaded=!0}bitmap(r){let t=r?r[0]:this._cv.width,e=r?r[1]:this._cv.height;return createImageBitmap(this._cv,0,0,t,e)}pattern(r="repeat",t=!1){if(!this._space)throw"Cannot find CanvasSpace ctx to create image pattern";return this._space.ctx.createPattern(t?this._cv:this._img,r)}sync(){this._scale!==1?this.bitmap().then(r=>{this._drawToScale(1/this._scale,r),this.load(this.toBase64())}):this._img.src=this.toBase64()}pixel(r,t=!0){let e=typeof t=="number"?t:t?this._scale:1;return l.getPixel(this._data,[r[0]*e,r[1]*e])}static getPixel(r,t){let e=new h(0,0,0,0);if(t[0]>=r.width||t[1]>=r.height)return e;let i=Math.floor(t[1])*(r.width*4)+Math.floor(t[0])*4,n=r.data;return i>=n.length-4?e:new h(n[i],n[i+1],n[i+2],n[i+3])}resize(r,t=!1){let e=t?r:[r[0]/this._img.naturalWidth,r[1]/this._img.naturalHeight];return this._drawToScale(e,this._img),this._data=this._ctx.getImageData(0,0,this._cv.width,this._cv.height),this}crop(r){let t=r.topLeft.scale(this._scale),e=r.size.scale(this._scale);return this._ctx.getImageData(t.x,t.y,e.x,e.y)}filter(r){return this._ctx.filter=r,this._ctx.drawImage(this._cv,0,0),this._ctx.filter="none",this}cleanup(){this._cv&&this._cv.remove(),this._img&&this._img.remove(),this._data=null}static fromBlob(r,t=!1,e){let i=URL.createObjectURL(r);return new l(t,e).load(i)}static imageDataToBlob(r){return new Promise(function(t,e){document||e("Cannot create html canvas element. document not found.");let i=document.createElement("canvas");i.width=r.width,i.height=r.height,i.getContext("2d").putImageData(r,0,0),i.toBlob(n=>{t(n),i.remove()})})}toBase64(){return this._cv.toDataURL()}toBlob(){return new Promise(r=>{this._cv.toBlob(t=>r(t))})}getForm(){return this._editable||console.error("Cannot get a CanvasForm because this Img is not editable"),this._ctx?new Q(this._ctx):void 0}get current(){return this._editable?this._cv:this._img}get image(){return this._img}get canvas(){return this._cv}get data(){return this._data}get ctx(){return this._ctx}get loaded(){return this._loaded}get pixelScale(){return this._scale}get imageSize(){return!this._img.width||!this._img.height?this.canvasSize.$divide(this._scale):new h(this._img.width,this._img.height)}get canvasSize(){return new h(this._cv.width,this._cv.height)}get scaledMatrix(){let r=1/this._scale;return new C().scale2D([r,r])}};var tt=class extends Y{constructor(t,e){super();this._pixelScale=1;this._autoResize=!0;this._bgcolor="#e1e9f0";this._offscreen=!1;this._initialResize=!1;let i=null,n=!1;if(this.id="pt",t instanceof Element)i=t,this.id="pts_existing_space";else{let s=t;s=t[0]==="#"||t[0]==="."?t:"#"+t,i=document.querySelector(s),n=!0,this.id=s.substr(1)}i?i.nodeName.toLowerCase()!="canvas"?(this._container=i,this._canvas=this._createElement("canvas",this.id+"_canvas"),this._container.appendChild(this._canvas),this._initialResize=!0):(this._canvas=i,this._container=i.parentElement,this._autoResize=!1):(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),n=!1),setTimeout(this._ready.bind(this,e),100),this._ctx=this._canvas.getContext("2d")}_createElement(t="div",e){let i=document.createElement(t);return i.setAttribute("id",e),i}_ready(t){if(!this._container)throw new Error(`Cannot initiate #${this.id} element`);this._isReady=!0,this._resizeHandler(null),this.clear(this._bgcolor),this._canvas.dispatchEvent(new Event("ready"));for(let e in this.players)this.players.hasOwnProperty(e)&&this.players[e].start&&this.players[e].start(this.bound.clone(),this);this._pointer=this.center,this._initialResize=!1,t&&t(this.bound,this._canvas)}setup(t){if(this._bgcolor=t.bgcolor?t.bgcolor:"transparent",this.autoResize=t.resize!=null?t.resize:!1,t.retina!==!1){let e=window&&window.devicePixelRatio||1,i=this._ctx.webkitBackingStorePixelRatio||this._ctx.mozBackingStorePixelRatio||this._ctx.msBackingStorePixelRatio||this._ctx.oBackingStorePixelRatio||this._ctx.backingStorePixelRatio||1;this._pixelScale=Math.max(1,e/i)}return t.offscreen?(this._offscreen=!0,this._offCanvas=this._createElement("canvas",this.id+"_offscreen"),this._offCtx=this._offCanvas.getContext("2d")):this._offscreen=!1,t.pixelDensity&&(this._pixelScale=t.pixelDensity),this}set autoResize(t){window&&(this._autoResize=t,t?window.addEventListener("resize",this._resizeHandler.bind(this)):window.removeEventListener("resize",this._resizeHandler.bind(this)))}get autoResize(){return this._autoResize}resize(t,e){this.bound=t,this._canvas.width=Math.ceil(this.bound.size.x)*this._pixelScale,this._canvas.height=Math.ceil(this.bound.size.y)*this._pixelScale,this._canvas.style.width=Math.ceil(this.bound.size.x)+"px",this._canvas.style.height=Math.ceil(this.bound.size.y)+"px",this._offscreen&&(this._offCanvas.width=Math.ceil(this.bound.size.x)*this._pixelScale,this._offCanvas.height=Math.ceil(this.bound.size.y)*this._pixelScale),this._pixelScale!=1&&(this._ctx.scale(this._pixelScale,this._pixelScale),this._offscreen&&this._offCtx.scale(this._pixelScale,this._pixelScale));for(let i in this.players)if(this.players.hasOwnProperty(i)){let n=this.players[i];n.resize&&n.resize(this.bound,e)}return this.render(this._ctx),e&&!this.isPlaying&&this.playOnce(0),this}_resizeHandler(t){if(!window)return;let e=this._autoResize||this._initialResize?this._container.getBoundingClientRect():this._canvas.getBoundingClientRect();if(e){let i=G.fromBoundingRect(e);i.center=i.center.add(window.pageXOffset,window.pageYOffset),this.resize(i,t)}}set background(t){this._bgcolor=t}get background(){return this._bgcolor}get pixelScale(){return this._pixelScale}get hasOffscreen(){return this._offscreen}get offscreenCtx(){return this._offCtx}get offscreenCanvas(){return this._offCanvas}getForm(){return new Q(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,i=Math.ceil(this.pixelScale);return!this._bgcolor||this._bgcolor==="transparent"?this._ctx.clearRect(-i,-i,this._canvas.width+i,this._canvas.height+i):((this._bgcolor.indexOf("rgba")===0||this._bgcolor.length===9&&this._bgcolor.indexOf("#")===0)&&this._ctx.clearRect(-i,-i,this._canvas.width+i,this._canvas.height+i),this._ctx.fillStyle=this._bgcolor,this._ctx.fillRect(-i,-i,this._canvas.width+i,this._canvas.height+i)),this._ctx.fillStyle=e,this}clearOffscreen(t){if(this._offscreen){let e=Math.ceil(this.pixelScale);t?(this._offCtx.fillStyle=t,this._offCtx.fillRect(-e,-e,this._canvas.width+e,this._canvas.height+e)):this._offCtx.clearRect(-e,-e,this._offCanvas.width+e,this._offCanvas.height+e)}return this}playItems(t){this._isReady&&(this._ctx.save(),this._offscreen&&this._offCtx.save(),super.playItems(t),this._ctx.restore(),this._offscreen&&this._offCtx.restore(),this.render(this._ctx))}dispose(){if(window)return window.removeEventListener("resize",this._resizeHandler.bind(this)),this.stop(),this.removeAll(),this}recorder(t,e="webm",i=15e6){let n=this._canvas.captureStream(),s=new MediaRecorder(n,{mimeType:`video/${e}`,bitsPerSecond:i});return s.ondataavailable=function(o){let a=URL.createObjectURL(new Blob([o.data],{type:`video/${e}`}));if(typeof t=="function")t(a);else if(t){let u=document.createElement("a");u.href=a,u.download=`canvas_video.${e}`,u.click(),u.remove()}},s}},Q=class l extends q{constructor(t){super();this._style={fillStyle:"#f03",strokeStyle:"#fff",lineWidth:1,lineJoin:"bevel",lineCap:"butt",globalAlpha:1};if(!t)return this;let e=i=>{this._ctx=i,this._ctx.fillStyle=this._style.fillStyle,this._ctx.strokeStyle=this._style.strokeStyle,this._ctx.lineJoin="bevel",this._ctx.font=this._font.value,this._ready=!0};t instanceof tt?(this._space=t,this._space.add({start:()=>{e(this._space.ctx)}})):e(t)}get space(){return this._space}get ctx(){return this._ctx}useOffscreen(t=!0,e=!1){return e&&this._space.clearOffscreen(typeof e=="string"?e:null),this._ctx=this._space.hasOffscreen&&t?this._space.offscreenCtx:this._space.ctx,this}renderOffscreen(t=[0,0]){this._space.hasOffscreen&&this._space.ctx.drawImage(this._space.offscreenCanvas,t[0],t[1],this._space.width,this._space.height)}alpha(t){return this._ctx.globalAlpha=t,this._style.globalAlpha=t,this}fill(t){return typeof t=="boolean"?this.filled=t:(this.filled=!0,this._style.fillStyle=t,this._ctx.fillStyle=t),this}fillOnly(t){return this.stroke(!1),this.fill(t)}stroke(t,e,i,n){return typeof t=="boolean"?this.stroked=t:(this.stroked=!0,this._style.strokeStyle=t,this._ctx.strokeStyle=t,e&&(this._ctx.lineWidth=e,this._style.lineWidth=e),i&&(this._ctx.lineJoin=i,this._style.lineJoin=i),n&&(this._ctx.lineCap=n,this._style.lineCap=n)),this}strokeOnly(t,e,i,n){return this.fill(!1),this.stroke(t,e,i,n)}applyFillStroke(t=!0,e=!0,i=1){return t&&(typeof t=="string"&&this.fill(t),this._ctx.fill()),e&&(typeof e=="string"&&this.stroke(e,i),this._ctx.stroke()),this}gradient(t){let e=[];t.length<2&&t.push([.99,"#000"],[1,"#000"]);for(let i=0,n=t.length;i<n;i++){let s=typeof t[i]=="string"?i*(1/(t.length-1)):t[i][0],o=typeof t[i]=="string"?t[i]:t[i][1];e.push([s,o])}return(i,n)=>{let s=n?this._ctx.createRadialGradient(i[0][0],i[0][1],Math.abs(i[1][0]),n[0][0],n[0][1],Math.abs(n[1][0])):this._ctx.createLinearGradient(i[0][0],i[0][1],i[1][0],i[1][1]);for(let o=0,a=e.length;o<a;o++)s.addColorStop(e[o][0],e[o][1]);return s}}composite(t="source-over"){return this._ctx.globalCompositeOperation=t,this}clip(){return this._ctx.clip(),this}dash(t=!0,e=0){return t?(t===!0&&(t=[5,5]),this._ctx.setLineDash([t[0],t[1]]),this._ctx.lineDashOffset=e):(this._ctx.setLineDash([]),this._ctx.lineDashOffset=0),this}font(t,e,i,n,s){return typeof t=="number"?(this._font.size=t,s&&(this._font.face=s),e&&(this._font.weight=e),i&&(this._font.style=i),n&&(this._font.lineHeight=n)):this._font=t,this._ctx.font=this._font.value,this._estimateTextWidth&&this.fontWidthEstimate(!0),this}fontWidthEstimate(t=!0){return this._estimateTextWidth=t?Z.textWidthEstimator(e=>this._ctx.measureText(e).width):void 0,this}getTextWidth(t){return this._estimateTextWidth?this._estimateTextWidth(t):this._ctx.measureText(t+" .").width}_textTruncate(t,e,i=""){return Z.truncate(this.getTextWidth.bind(this),t,e,i)}_textAlign(t,e,i,n){let s=m.iterToArray(t);if(!m.arrayCheck(s))return;n||(n=M.center(s));let o=s[0][0];this._ctx.textAlign=="end"||this._ctx.textAlign=="right"?o=s[1][0]:(this._ctx.textAlign=="center"||this._ctx.textAlign=="middle")&&(o=n[0]);let a=n[1];return e=="top"||e=="start"?a=s[0][1]:(e=="end"||e=="bottom")&&(a=s[1][1]),i?new h(o+i[0],a+i[1]):new h(o,a)}reset(){for(let t in this._style)this._style.hasOwnProperty(t)&&(this._ctx[t]=this._style[t]);return this._font=new O,this._ctx.font=this._font.value,this}_paint(){this._filled&&this._ctx.fill(),this._stroked&&this._ctx.stroke()}static point(t,e,i=5,n="square"){if(e){if(!l[n])throw new Error(`${n} is not a static function of CanvasForm`);l[n](t,e,i)}}point(t,e=5,i="square"){return l.point(this._ctx,t,e,i),this._paint(),this}static circle(t,e,i=10){e&&(t.beginPath(),t.arc(e[0],e[1],i,0,w.two_pi,!1),t.closePath())}circle(t){let e=m.iterToArray(t);return l.circle(this._ctx,e[0],e[1][0]),this._paint(),this}static ellipse(t,e,i,n=0,s=0,o=w.two_pi,a=!1){!e||!i||(t.beginPath(),t.ellipse(e[0],e[1],i[0],i[1],n,s,o,a))}ellipse(t,e,i=0,n=0,s=w.two_pi,o=!1){return l.ellipse(this._ctx,t,e,i,n,s,o),this._paint(),this}static arc(t,e,i,n,s,o){e&&(t.beginPath(),t.arc(e[0],e[1],i,n,s,o))}arc(t,e,i,n,s){return l.arc(this._ctx,t,e,i,n,s),this._paint(),this}static square(t,e,i){if(!e)return;let n=e[0]-i,s=e[1]-i,o=e[0]+i,a=e[1]+i;t.beginPath(),t.moveTo(n,s),t.lineTo(n,a),t.lineTo(o,a),t.lineTo(o,s),t.closePath()}square(t,e){return l.square(this._ctx,t,e),this._paint(),this}static line(t,e){if(!m.arrayCheck(e))return;let i=0;t.beginPath();for(let n of e)n&&(i++>0?t.lineTo(n[0],n[1]):t.moveTo(n[0],n[1]))}line(t){return l.line(this._ctx,t),this._paint(),this}static polygon(t,e){m.arrayCheck(e)&&(l.line(t,e),t.closePath())}polygon(t){return l.polygon(this._ctx,t),this._paint(),this}static rect(t,e){let i=m.iterToArray(e);m.arrayCheck(i)&&(t.beginPath(),t.moveTo(i[0][0],i[0][1]),t.lineTo(i[0][0],i[1][1]),t.lineTo(i[1][0],i[1][1]),t.lineTo(i[1][0],i[0][1]),t.closePath())}rect(t){return l.rect(this._ctx,t),this._paint(),this}static image(t,e,i,n){let s=m.iterToArray(e),o;if(typeof s[0]=="number")o=s;else if(n){let a=m.iterToArray(n);o=[a[0][0],a[0][1],a[1][0]-a[0][0],a[1][1]-a[0][1],s[0][0],s[0][1],s[1][0]-s[0][0],s[1][1]-s[0][1]]}else o=[s[0][0],s[0][1],s[1][0]-s[0][0],s[1][1]-s[0][1]];i instanceof J?i.loaded&&t.drawImage(i.image,...o):t.drawImage(i,...o)}image(t,e,i){return e instanceof J?e.loaded&&l.image(this._ctx,t,e.image,i):l.image(this._ctx,t,e,i),this}static imageData(t,e,i){let n=m.iterToArray(e);typeof n[0]=="number"?t.putImageData(i,n[0],n[1]):t.putImageData(i,n[0][0],n[0][1],n[0][0],n[0][1],n[1][0],n[1][1])}imageData(t,e){return l.imageData(this._ctx,t,e),this}static text(t,e,i,n){e&&t.fillText(i,e[0],e[1],n)}text(t,e,i){return l.text(this._ctx,t,e,i),this}textBox(t,e,i="middle",n="",s=!0){s&&(this._ctx.textBaseline=i);let o=M.size(t),a=this._textTruncate(e,o[0],n);return this.text(this._textAlign(t,i),a[0]),this}paragraphBox(t,e,i=1.2,n="top",s=!0){let o=m.iterToArray(t),a=M.size(o);this._ctx.textBaseline="top";let u=this._font.size*i,c=(_,D=[],A=0)=>{if(!_||s&&A*u>a[1]-u*2)return D;if(A>1e4)throw new Error("max recursion reached (10000)");let U=this._textTruncate(_,a[0],""),bt=U[0].indexOf(`
5
+ `),p}function f(p){for(p=c(p),a(p),n=0;n<p.length;n++)for(o=p.charCodeAt(n),s=0;s<r;s++)i[s]-=a(o.toString()),i[s]<0&&(i[s]+=1)}return u(),f(l),{random(){++e>=r&&(e=0);let p=1768863*i[e]+t*23283064365386963e-26;return i[e]=p-(t=p|0)}}}var L=class l{static equals(r,t,e=1e-5){return Math.abs(r-t)<e}static lerp(r,t,e){return(1-e)*r+e*t}static clamp(r,t,e){return Math.max(t,Math.min(e,r))}static boundValue(r,t,e){let i=Math.abs(e-t),n=r%i;return n>e?n-=i:n<t&&(n+=i),n}static within(r,t,e){return r>=Math.min(t,e)&&r<=Math.max(t,e)}static randomRange(r,t=0){let e=r>t?r-t:t-r;return r+l.random()*e}static randomPt(r,t){let e=new h(r.length),i=t?k.subtract(t.slice(),r):r,n=t?r:new h(r.length).fill(0);for(let s=0,o=e.length;s<o;s++)e[s]=l.random()*i[s]+n[s];return e}static normalizeValue(r,t,e){let i=Math.min(t,e),n=Math.max(t,e);return(r-i)/(n-i)}static sum(r){let t=m.iterToArray(r),e=new h(t[0]);for(let i=1,n=t.length;i<n;i++)k.add(e,t[i]);return e}static average(r){let t=m.iterToArray(r);return l.sum(t).divide(t.length)}static cycle(r,t=st.sineInOut){return t(r>.5?2-r*2:r*2)}static mapToRange(r,t,e,i,n){if(t==e)throw new Error("[currMin, currMax] must define a range that is not zero");let s=Math.min(i,n),o=Math.max(i,n);return l.normalizeValue(r,t,e)*(o-s)+s}static seed(r){this.generator=Ut(r)}static random(){return this.generator?this.generator.random():Math.random()}},y=class l{static boundAngle(r){return L.boundValue(r,0,360)}static boundRadian(r){return L.boundValue(r,0,w.two_pi)}static toRadian(r){return r*w.deg_to_rad}static toDegree(r){return r*w.rad_to_deg}static boundingBox(r){let t,e;for(let i of r)t==null?(t=i.clone(),e=i.clone()):(t=t.$min(i),e=e.$max(i));return new d(t,e)}static centroid(r){return L.average(r)}static anchor(r,t=0,e="to"){let i=e=="to"?"subtract":"add",n=0;for(let s of r)typeof t=="number"?t!==n&&s[i](r[t]):s[i](t),n++}static interpolate(r,t,e=.5){let i=Math.min(r.length,t.length),n=h.make(i);for(let s=0;s<i;s++)n[s]=r[s]*(1-e)+t[s]*e;return n}static perpendicular(r,t=w.xy){let e=t[1],i=t[0],n=new h(r),s=new h(n);s[i]=-n[e],s[e]=n[i];let o=new h(n);return o[i]=n[e],o[e]=-n[i],new d(s,o)}static isPerpendicular(r,t){return new h(r).dot(t)===0}static withinBound(r,t,e){for(let i=0,n=Math.min(r.length,t.length,e.length);i<n;i++)if(!L.within(r[i],t[i],e[i]))return!1;return!0}static sortEdges(r){let t=m.iterToArray(r),e=l.boundingBox(t),i=e[1].add(e[0]).divide(2),n=(s,o)=>{if(s.length<2||o.length<2)throw new Error("Pt dimension cannot be less than 2");let a=s.$subtract(i),u=o.$subtract(i);if(a[0]>=0&&u[0]<0)return 1;if(a[0]<0&&u[0]>=0)return-1;if(a[0]==0&&u[0]==0)return a[1]>=0||u[1]>=0?a[1]>u[1]?1:-1:u[1]>a[1]?1:-1;let c=a.$cross2D(u);return c<0?1:c>0?-1:a[0]*a[0]+a[1]*a[1]>u[0]*u[0]+u[1]*u[1]?1:-1};return t.sort(n)}static scale(r,t,e){let i=m.iterToArray(r[0]!==void 0&&typeof r[0]=="number"?[r]:r),n=typeof t=="number"?h.make(i[0].length,t):t;e||(e=h.make(i[0].length,0));for(let s=0,o=i.length;s<o;s++){let a=i[s];for(let u=0,c=a.length;u<c;u++)a[u]=e&&e[u]?e[u]+(a[u]-e[u])*n[u]:a[u]*n[u]}return l}static rotate2D(r,t,e,i){let n=m.iterToArray(r[0]!==void 0&&typeof r[0]=="number"?[r]:r),s=e?C.rotateAt2DMatrix:C.rotate2DMatrix;e||(e=h.make(n[0].length,0));let o=Math.cos(t),a=Math.sin(t);for(let u=0,c=n.length;u<c;u++){let f=i?n[u].$take(i):n[u];if(f.to(C.transform2D(f,s(o,a,e))),i)for(let p=0;p<i.length;p++)n[u][i[p]]=f[p]}return l}static shear2D(r,t,e,i){let n=m.iterToArray(r[0]!==void 0&&typeof r[0]=="number"?[r]:r),s=typeof t=="number"?[t,t]:t;e||(e=h.make(n[0].length,0));let o=e?C.shearAt2DMatrix:C.shear2DMatrix,a=Math.tan(s[0]),u=Math.tan(s[1]);for(let c=0,f=n.length;c<f;c++){let p=i?n[c].$take(i):n[c];if(p.to(C.transform2D(p,o(a,u,e))),i)for(let b=0;b<i.length;b++)n[c][i[b]]=p[b]}return l}static reflect2D(r,t,e){let i=m.iterToArray(r[0]!==void 0&&typeof r[0]=="number"?[r]:r),n=m.iterToArray(t),s=C.reflectAt2DMatrix(n[0],n[1]);for(let o=0,a=i.length;o<a;o++){let u=e?i[o].$take(e):i[o];if(u.to(C.transform2D(u,s)),e)for(let c=0;c<e.length;c++)i[o][e[c]]=u[c]}return l}static cosTable(){let r=new Float64Array(360);for(let e=0;e<360;e++)r[e]=Math.cos(e*Math.PI/180);return{table:r,cos:e=>r[Math.floor(l.boundAngle(l.toDegree(e)))]}}static sinTable(){let r=new Float64Array(360);for(let e=0;e<360;e++)r[e]=Math.sin(e*Math.PI/180);return{table:r,sin:e=>r[Math.floor(l.boundAngle(l.toDegree(e)))]}}},st=class l{static linear(r,t=1){return t*r}static quadraticIn(r,t=1){return t*r*r}static quadraticOut(r,t=1){return-t*r*(r-2)}static quadraticInOut(r,t=1){let e=r*2;return r<.5?t/2*r*r*4:-t/2*((e-1)*(e-3)-1)}static cubicIn(r,t=1){return t*r*r*r}static cubicOut(r,t=1){let e=r-1;return t*(e*e*e+1)}static cubicInOut(r,t=1){let e=r*2;return r<.5?t/2*e*e*e:t/2*((e-2)*(e-2)*(e-2)+2)}static exponentialIn(r,t=1,e=.25){return t*Math.pow(r,1/e)}static exponentialOut(r,t=1,e=.25){return t*Math.pow(r,e)}static sineIn(r,t=1){return-t*Math.cos(r*w.half_pi)+t}static sineOut(r,t=1){return t*Math.sin(r*w.half_pi)}static sineInOut(r,t=1){return-t/2*(Math.cos(Math.PI*r)-1)}static cosineApprox(r,t=1){let e=r*r,i=e*e,n=i*e;return t*(4*n/9-17*i/9+22*e/9)}static circularIn(r,t=1){return-t*(Math.sqrt(1-r*r)-1)}static circularOut(r,t=1){let e=r-1;return t*Math.sqrt(1-e*e)}static circularInOut(r,t=1){let e=r*2;return r<.5?-t/2*(Math.sqrt(1-e*e)-1):t/2*(Math.sqrt(1-(e-2)*(e-2))+1)}static elasticIn(r,t=1,e=.7){let i=r-1,n=e/w.two_pi*1.5707963267948966;return t*(-Math.pow(2,10*i)*Math.sin((i-n)*w.two_pi/e))}static elasticOut(r,t=1,e=.7){let i=e/w.two_pi*1.5707963267948966;return t*(Math.pow(2,-10*r)*Math.sin((r-i)*w.two_pi/e))+t}static elasticInOut(r,t=1,e=.6){let i=r*2,n=e/w.two_pi*1.5707963267948966;return r<.5?(i-=1,t*(-.5*(Math.pow(2,10*i)*Math.sin((i-n)*w.two_pi/e)))):(i-=1,t*(.5*(Math.pow(2,-10*i)*Math.sin((i-n)*w.two_pi/e)))+t)}static bounceIn(r,t=1){return t-l.bounceOut(1-r,t)}static bounceOut(r,t=1){return r<1/2.75?t*(7.5625*r*r):r<2/2.75?(r-=1.5/2.75,t*(7.5625*r*r+.75)):r<2.5/2.75?(r-=2.25/2.75,t*(7.5625*r*r+.9375)):(r-=2.625/2.75,t*(7.5625*r*r+.984375))}static bounceInOut(r,t=1){return r<.5?l.bounceIn(r*2,t)/2:l.bounceOut(r*2-1,t)/2+t/2}static sigmoid(r,t=1,e=10){let i=e*(r-.5);return t/(1+Math.exp(-i))}static logSigmoid(r,t=1,e=.7){e=Math.max(w.epsilon,Math.min(1-w.epsilon,e)),e=1/(1-e);let i=1/(1+Math.exp((r-.5)*e*-2)),n=1/(1+Math.exp(e)),s=1/(1+Math.exp(-e));return t*(i-n)/(s-n)}static seat(r,t=1,e=.5){return r<.5?t*Math.pow(2*r,1-e)/2:t*(1-Math.pow(2*(1-r),1-e)/2)}static quadraticBezier(r,t=1,e=[.05,.95]){let i=typeof e!="number"?e[0]:e,n=typeof e!="number"?e[1]:.5,s=1-2*i;s===0&&(s=w.epsilon);let o=(Math.sqrt(i*i+s*r)-i)/s;return t*((1-2*n)*(o*o)+2*n*o)}static cubicBezier(r,t=1,e=[.1,.7],i=[.9,.2]){let n=new d(new h(0,0),new h(e),new h(i),new h(1,1));return t*K.bezierStep(new h(r*r*r,r*r,r,1),K.controlPoints(n)).y}static quadraticTarget(r,t=1,e=[.2,.35]){let i=Math.min(1-w.epsilon,Math.max(w.epsilon,e[0])),n=Math.min(1,Math.max(0,e[1])),s=(1-n)/(1-i)-n/i,o=(s*(i*i)-n)/i,a=s*(r*r)-o*r;return t*Math.min(1,Math.max(0,a))}static cliff(r,t=1,e=.5){return r>e?t:0}static step(r,t,e,i,...n){let s=1/t,o=Math.floor(e/s)*s;return r(o,i,...n)}},yt=class{constructor(r){this._dims=0;this._source=d.fromPtArray(r),this.calc()}get max(){return this._max.clone()}get min(){return this._min.clone()}get magnitude(){return this._mag.clone()}calc(){if(!this._source)return;let r=this._source[0].length;this._dims=r;let t=new h(r),e=new h(r),i=new h(r);for(let n=0;n<r;n++){t[n]=w.min,e[n]=w.max,i[n]=0;let s=this._source.zipSlice(n);for(let o=0,a=s.length;o<a;o++)t[n]=Math.max(t[n],s[o]),e[n]=Math.min(e[n],s[o]),i[n]=t[n]-e[n]}return this._max=t,this._min=e,this._mag=i,this}mapTo(r,t,e){let i=new d;for(let n=0,s=this._source.length;n<s;n++){let o=this._source[n],a=new h(this._dims);for(let u=0;u<this._dims;u++)a[u]=e&&e[u]?o[u]:L.mapToRange(o[u],this._min[u],this._max[u],r,t);i.push(a)}return i}append(r,t=!0){let e=m.iterToArray(r);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(r){let t=new d;for(let e=0;e<=r;e++){let i=new h(this._dims);for(let n=0,s=this._max.length;n<s;n++)i[n]=L.lerp(this._min[n],this._max[n],e/r);t.push(i)}return t}};var w={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:Number.MAX_VALUE,min:Number.MIN_VALUE,pi:Math.PI,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},H=class H{static warnLevel(r){return r&&(H._warnLevel=r),H._warnLevel}static getArgs(r){if(r.length<1)return[];let t=[],e=Array.isArray(r[0])||ArrayBuffer.isView(r[0]);if(typeof r[0]=="number")t=Array.prototype.slice.call(r);else if(typeof r[0]=="object"&&!e){let i=["x","y","z","w"],n=r[0];for(let s=0;s<i.length&&!(n.length&&s>=n.length||!(i[s]in n));s++)t.push(n[i[s]])}else e&&(t=[].slice.call(r[0]));return t}static warn(r="error",t=void 0){if(H.warnLevel()=="error")throw new Error(r);return H.warnLevel()=="warn"&&console.warn(r),t}static randomInt(r,t=0){return H.warn("Util.randomInt is deprecated. Please use `Num.randomRange`"),Math.floor(L.random()*r)+t}static split(r,t,e,i=!1,n=!0){let s=[],o=[],a=e||t,u=0;if(r.length<=0||a<=0)return[];for(;u<r.length;){o=[];for(let c=0;c<t;c++)if(i)o.push(r[(u+c)%r.length]);else{if(u+c>=r.length)break;o.push(r[u+c])}u+=a,(!n||n&&o.length===t)&&s.push(o)}return s}static flatten(r,t=!0){let e=t?new d:[];return e.concat.apply(e,r)}static combine(r,t,e){let i=[];for(let n=0,s=r.length;n<s;n++)for(let o=0,a=t.length;o<a;o++)i.push(e(r[n],t[o]));return i}static zip(r){let t=[];for(let e=0,i=r[0].length;e<i;e++){let n=[];for(let s=0;s<r.length;s++)n.push(r[s][e]);t.push(n)}return t}static stepper(r,t=0,e=1,i){let n=t;return function(){return n+=e,n>=r&&(n=t+(n-r)),i&&i(n),n}}static forRange(r,t,e=0,i=1){let n=[];for(let s=e,o=t;s<o;s+=i)n[s]=r(s);return n}static load(r,t){let e=new XMLHttpRequest;e.open("GET",r,!0),e.onload=function(){e.status>=200&&e.status<400?t(e.responseText,!0):t(`Server error (${e.status}) when loading "${r}"`,!1)},e.onerror=function(){t("Unknown network error",!1)},e.send()}static download(r,t="pts_canvas_image",e="png",i=1){let n=e==="jpg"?"jpeg":e;r.element.toBlob(function(s){let o=document.createElement("a"),a=URL.createObjectURL(s);o.href=a,o.download=`${t}.${e}`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a)},`image/${n}`,i)}static performance(r=10){let t=Date.now(),e=[];return function(){let i=Date.now();return e.push(i-t),e.length>=r&&e.shift(),t=i,Math.floor(e.reduce((n,s)=>n+s,0)/e.length)}}static arrayCheck(r,t=2){return Array.isArray(r)&&r.length<t?(H.warn(`Requires ${t} or more Pts in this Group.`),!1):!0}static iterToArray(r){return Array.isArray(r)?r:[...r]}static isMobile(){return/iPhone|iPad|Android/i.test(navigator.userAgent)}static uniqueId(r=!1){return r&&crypto?crypto.randomUUID():Date.now().toString(36)+Math.random().toString(36).substring(2)}};H._warnLevel="mute";var m=H;var h=class l extends Float32Array{constructor(...r){let t;r.length===1&&typeof r[0]=="number"?t=r[0]:t=r.length>0?m.getArgs(r):[0,0],super(t)}static make(r,t=0,e=!1){let i=new Float32Array(r);if(t&&i.fill(t),e)for(let n=0,s=i.length;n<s;n++)i[n]=i[n]*L.random();return new l(i)}get id(){return this._id}set id(r){this._id=r}get x(){return this[0]}set x(r){this[0]=r}get y(){return this[1]}set y(r){this[1]=r}get z(){return this[2]}set z(r){this[2]=r}get w(){return this[3]}set w(r){this[3]=r}clone(){return new l(this)}equals(r,t=1e-6){for(let e=0,i=this.length;e<i;e++)if(Math.abs(this[e]-r[e])>t)return!1;return!0}to(...r){let t=m.getArgs(r);for(let e=0,i=Math.min(this.length,t.length);e<i;e++)this[e]=t[e];return this}$to(...r){return this.clone().to(...r)}toAngle(r,t,e=!1){let i=t!=null?t:this.magnitude(),n=[Math.cos(r)*i,Math.sin(r)*i];return e?this.add(n):this.to(n)}op(r){let t=this;return(...e)=>r(t,...e)}ops(r){let t=[];for(let e=0,i=r.length;e<i;e++)t.push(this.op(r[e]));return t}$take(r){let t=[];for(let e=0,i=r.length;e<i;e++)t.push(this[r[e]]||0);return new l(t)}$concat(...r){return new l(this.toArray().concat(m.getArgs(r)))}add(...r){return r.length===1&&typeof r[0]=="number"?k.add(this,r[0]):k.add(this,m.getArgs(r)),this}$add(...r){return this.clone().add(...r)}subtract(...r){return r.length===1&&typeof r[0]=="number"?k.subtract(this,r[0]):k.subtract(this,m.getArgs(r)),this}$subtract(...r){return this.clone().subtract(...r)}multiply(...r){return r.length===1&&typeof r[0]=="number"?k.multiply(this,r[0]):k.multiply(this,m.getArgs(r)),this}$multiply(...r){return this.clone().multiply(...r)}divide(...r){return r.length===1&&typeof r[0]=="number"?k.divide(this,r[0]):k.divide(this,m.getArgs(r)),this}$divide(...r){return this.clone().divide(...r)}magnitudeSq(){return k.dot(this,this)}magnitude(){return k.magnitude(this)}unit(r=void 0){return k.unit(this,r),this}$unit(r=void 0){return this.clone().unit(r)}dot(...r){return k.dot(this,m.getArgs(r))}$cross2D(...r){return k.cross2D(this,m.getArgs(r))}$cross(...r){return k.cross(this,m.getArgs(r))}$project(...r){return this.$multiply(this.dot(...r)/this.magnitudeSq())}projectScalar(...r){return this.dot(...r)/this.magnitude()}abs(){return k.abs(this),this}$abs(){return this.clone().abs()}floor(){return k.floor(this),this}$floor(){return this.clone().floor()}ceil(){return k.ceil(this),this}$ceil(){return this.clone().ceil()}round(){return k.round(this),this}$round(){return this.clone().round()}minValue(){return k.min(this)}maxValue(){return k.max(this)}$min(...r){let t=m.getArgs(r),e=this.clone();for(let i=0,n=Math.min(this.length,t.length);i<n;i++)e[i]=Math.min(this[i],t[i]);return e}$max(...r){let t=m.getArgs(r),e=this.clone();for(let i=0,n=Math.min(this.length,t.length);i<n;i++)e[i]=Math.max(this[i],t[i]);return e}angle(r=w.xy){return Math.atan2(this[r[1]],this[r[0]])}angleBetween(r,t=w.xy){return y.boundRadian(this.angle(t))-y.boundRadian(r.angle(t))}scale(r,t){return y.scale(this,r,t||l.make(this.length,0)),this}rotate2D(r,t,e){return y.rotate2D(this,r,t||l.make(this.length,0),e),this}shear2D(r,t,e){return y.shear2D(this,r,t||l.make(this.length,0),e),this}reflect2D(r,t){return y.reflect2D(this,r,t),this}toString(){return`Pt(${this.join(", ")})`}toArray(){return[].slice.call(this)}toGroup(){return new d(l.make(this.length),this.clone())}toBound(){return new G(l.make(this.length),this.clone())}},d=class l extends Array{constructor(...r){super(...r)}get id(){return this._id}set id(r){this._id=r}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 r=new l;for(let t=0,e=this.length;t<e;t++)r.push(this[t].clone());return r}static fromArray(r){let t=new l;for(let e of r){let i=e instanceof h?e:new h(e);t.push(i)}return t}static fromPtArray(r){return l.from(r)}split(r,t,e=!1){return m.split(this,r,t,e)}insert(r,t=0){return l.prototype.splice.apply(this,[t,0,...r]),this}remove(r=0,t=1){let e=r<0?[r*-1-1,t]:[r,t];return l.prototype.splice.apply(this,e)}segments(r=2,t=1,e=!1){return this.split(r,t,e)}lines(){return this.segments(2,1)}centroid(){return y.centroid(this)}boundingBox(){return y.boundingBox(this)}anchorTo(r=0){y.anchor(this,r,"to")}anchorFrom(r=0){y.anchor(this,r,"from")}op(r){let t=this;return(...e)=>r(t,...e)}ops(r){let t=[];for(let e=0,i=r.length;e<i;e++)t.push(this.op(r[e]));return t}interpolate(r){r=L.clamp(r,0,1);let t=this.length-1,e=1/(this.length-1),i=Math.floor(r/e);return y.interpolate(this[i],this[Math.min(this.length-1,i+1)],(r-i*e)*t)}moveBy(...r){return this.add(...r)}moveTo(...r){let t=new h(m.getArgs(r)).subtract(this[0]);return this.moveBy(t),this}scale(r,t){for(let e=0,i=this.length;e<i;e++)y.scale(this[e],r,t||this[0]);return this}rotate2D(r,t,e){for(let i=0,n=this.length;i<n;i++)y.rotate2D(this[i],r,t||this[0],e);return this}shear2D(r,t,e){for(let i=0,n=this.length;i<n;i++)y.shear2D(this[i],r,t||this[0],e);return this}reflect2D(r,t){for(let e=0,i=this.length;e<i;e++)y.reflect2D(this[e],r,t);return this}sortByDimension(r,t=!1){return this.sort((e,i)=>t?i[r]-e[r]:e[r]-i[r])}forEachPt(r,...t){if(!this[0][r])return m.warn(`${r} is not a function of Pt`),this;for(let e=0,i=this.length;e<i;e++)this[e]=this[e][r](...t);return this}add(...r){return this.forEachPt("add",...r)}subtract(...r){return this.forEachPt("subtract",...r)}multiply(...r){return this.forEachPt("multiply",...r)}divide(...r){return this.forEachPt("divide",...r)}$matrixAdd(r){return C.add(this,r)}$matrixMultiply(r,t=!1,e=!1){return C.multiply(this,r,t,e)}zipSlice(r,t=!1){return C.zipSlice(this,r,t)}$zip(r=void 0,t=!1){return C.zip(this,r,t)}toBound(){return G.fromGroup(this)}toString(){return"Group[ "+this.reduce((r,t)=>r+t.toString()+" ","")+" ]"}},G=class l extends d{constructor(...t){super(...t);this._center=new h;this._size=new h;this._topLeft=new h;this._bottomRight=new h;this._inited=!1;this.init()}static fromBoundingRect(t){let e=new l(new h(t.left||0,t.top||0),new h(t.right||0,t.bottom||0));return t.width&&t.height&&(e.size=new h(t.width,t.height)),e}static fromGroup(t){let e=m.iterToArray(t);if(e.length<2)throw new Error("Cannot create a Bound from a group that has less than 2 Pt");return new l(e[0],e[e.length-1])}init(){if(this.p1&&(this._size=this.p1.clone(),this._inited=!0),this.p1&&this.p2){let t=this.p1,e=this.p2;this.topLeft=t.$min(e),this._bottomRight=t.$max(e),this._updateSize(),this._inited=!0}}clone(){return new l(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 h(this._size)}set size(t){this._size=new h(t),this._updatePosFromTop()}get center(){return new h(this._center)}set center(t){this._center=new h(t),this._updatePosFromCenter()}get topLeft(){return new h(this._topLeft)}set topLeft(t){this._topLeft=new h(t),this[0]=this._topLeft,this._updateSize()}get bottomRight(){return new h(this._bottomRight)}set bottomRight(t){this._bottomRight=new h(t),this[1]=this._bottomRight,this._updateSize()}get width(){return this._size.length>0?this._size.x:0}set width(t){this._size.x=t,this._updatePosFromTop()}get height(){return this._size.length>1?this._size.y:0}set height(t){this._size.y=t,this._updatePosFromTop()}get depth(){return this._size.length>2?this._size.z:0}set depth(t){this._size.z=t,this._updatePosFromTop()}get x(){return this.topLeft.x}get y(){return this.topLeft.y}get z(){return this.topLeft.z}get inited(){return this._inited}update(){return this._topLeft=this[0],this._bottomRight=this[1],this._updateSize(),this}};var vt={};T(vt,{UI:()=>W,UIButton:()=>ot,UIDragger:()=>kt,UIPointerActions:()=>v,UIShape:()=>X});var X={rectangle:"rectangle",circle:"circle",polygon:"polygon",polyline:"polyline",line:"line"},v={up:"up",down:"down",move:"move",drag:"drag",uidrag:"uidrag",drop:"drop",uidrop:"uidrop",over:"over",out:"out",enter:"enter",leave:"leave",click:"click",keydown:"keydown",keyup:"keyup",pointerdown:"pointerdown",pointerup:"pointerup",contextmenu:"contextmenu",all:"all"},V=class V{constructor(r,t,e={},i){this._holds=new Map;this._group=d.fromArray(r),this._shape=t,this._id=i===void 0?`ui_${V._counter++}`:i,this._states=e,this._actions={}}static fromRectangle(r,t,e){return new this(r,X.rectangle,t,e)}static fromCircle(r,t,e){return new this(r,X.circle,t,e)}static fromPolygon(r,t,e){return new this(r,X.polygon,t,e)}static fromUI(r,t,e){return new this(r.group,r.shape,t||r._states,e)}get id(){return this._id}set id(r){this._id=r}get group(){return this._group}set group(r){this._group=r}get shape(){return this._shape}set shape(r){this._shape=r}state(r,t){return r?t!==void 0?(this._states[r]=t,this):this._states[r]:null}on(r,t){return this._actions[r]||(this._actions[r]=[]),V._addHandler(this._actions[r],t)}off(r,t){return this._actions[r]?t===void 0?(delete this._actions[r],!0):V._removeHandler(this._actions[r],t):!1}listen(r,t,e){if(this._actions[r]!==void 0){if(this._within(t)||Array.from(this._holds.values()).indexOf(r)>=0)return V._trigger(this._actions[r],this,t,r,e),!0;if(this._actions.all)return V._trigger(this._actions.all,this,t,r,e),!0}return!1}hold(r){let t=Math.max(0,...Array.from(this._holds.keys()))+1;return this._holds.set(t,r),t}unhold(r){r!==void 0?this._holds.delete(r):this._holds.clear()}static track(r,t,e,i){for(let n=0,s=r.length;n<s;n++)r[n].listen(t,e,i)}render(r){r(this._group,this._states)}toString(){return`UI ${this.group.toString}`}_within(r){let t=null;if(this._shape===X.rectangle)t=M.withinBound;else if(this._shape===X.circle)t=B.withinBound;else if(this._shape===X.polygon)t=S.hasIntersectPoint;else return!1;return t(this._group,r)}static _trigger(r,t,e,i,n){if(r)for(let s=0,o=r.length;s<o;s++)r[s]&&r[s](t,e,i,n)}static _addHandler(r,t){return t?(r.push(t),r.length-1):-1}static _removeHandler(r,t){if(t>=0&&t<r.length){let e=r.length;return r.splice(t,1),e>r.length}else return!1}};V._counter=0;var W=V,ot=class extends W{constructor(t,e,i={},n){super(t,e,i,n);this._hoverID=-1;i.hover===void 0&&(this._states.hover=!1),i.clicks===void 0&&(this._states.clicks=0);let s=v;this.on(s.up,(o,a,u,c)=>{this.state("clicks",this._states.clicks+1)}),this.on(s.move,(o,a,u,c)=>{if(this._within(a)&&!this._states.hover){this.state("hover",!0),W._trigger(this._actions[s.enter],this,a,s.enter,c);let p=this.hold(s.move);this._hoverID=this.on(s.move,(b,P)=>{!this._within(P)&&!this.state("dragging")&&(this.state("hover",!1),W._trigger(this._actions[s.leave],this,a,s.leave,c),this.off(s.move,this._hoverID),this.unhold(p))})}})}onClick(t){return this.on(v.up,t)}offClick(t){return this.off(v.up,t)}onContextMenu(t){return this.on(v.contextmenu,t)}offContextMenu(t){return this.off(v.contextmenu,t)}onHover(t,e){let i=[void 0,void 0];return t&&(i[0]=this.on(v.enter,t)),e&&(i[1]=this.on(v.leave,e)),i}offHover(t,e){let i=[!1,!1];return(t===void 0||t>=0)&&(i[0]=this.off(v.enter,t)),(e===void 0||e>=0)&&(i[1]=this.off(v.leave,e)),i}},kt=class extends ot{constructor(t,e,i={},n){super(t,e,i,n);this._draggingID=-1;this._moveHoldID=-1;this._dropHoldID=-1;this._upHoldID=-1;i.dragging===void 0&&(this._states.dragging=!1),i.moved===void 0&&(this._states.moved=!1),i.offset===void 0&&(this._states.offset=new h);let s=v;this.on(s.down,(a,u,c,f)=>{this._moveHoldID===-1&&(this.state("dragging",!0),this.state("offset",new h(u).subtract(a.group[0])),this._moveHoldID=this.hold(s.move)),this._dropHoldID===-1&&(this._dropHoldID=this.hold(s.drop)),this._upHoldID===-1&&(this._upHoldID=this.hold(s.up)),this._draggingID===-1&&(this._draggingID=this.on(s.move,(p,b)=>{this.state("dragging")&&(W._trigger(this._actions[s.uidrag],p,b,s.uidrag,f),this.state("moved",!0))}))});let o=(a,u,c,f)=>{this.state("dragging",!1),this.off(s.move,this._draggingID),this._draggingID=-1,this.unhold(this._moveHoldID),this._moveHoldID=-1,this.unhold(this._dropHoldID),this._dropHoldID=-1,this.unhold(this._upHoldID),this._upHoldID=-1,this.state("moved")&&(W._trigger(this._actions[s.uidrop],a,u,s.uidrop,f),this.state("moved",!1))};this.on(s.drop,o),this.on(s.up,o),this.on(s.out,o)}onDrag(t){return this.on(v.uidrag,t)}offDrag(t){return this.off(v.uidrag,t)}onDrop(t){return this.on(v.uidrop,t)}offDrop(t){return this.off(v.uidrop,t)}};var at=class{constructor(){this.id="space";this.bound=new G;this._time={prev:0,diff:0,end:-1,min:0};this.players={};this.playerCount=0;this._animID=-1;this._pause=!1;this._refresh=void 0;this._pointer=new h;this._isReady=!1;this._playing=!1}refresh(r){return this._refresh=r,this}minFrameTime(r=0){this._time.min=r}add(r){let t=typeof r=="function"?{animate:r}:r,e=this.playerCount++,i=t.animateID||this.id+e;return this.players[i]=t,t.animateID=i,t.resize&&this.bound.inited&&t.resize(this.bound),this._refresh===void 0&&(this._refresh=!0),this}remove(r){return delete this.players[r.animateID],this}removeAll(){return this.players={},this}play(r=0){if(!(r===0&&this._animID!==-1)){if(this._animID=requestAnimationFrame(this.play.bind(this)),this._pause)return this;if(this._time.diff=r-this._time.prev,this._time.diff<this._time.min)return this;this._time.prev=r;try{this.playItems(r)}catch(t){throw cancelAnimationFrame(this._animID),this._animID=-1,this._playing=!1,t}return this}}replay(){this._time.end=-1,this.play()}playItems(r){if(this._playing=!0,this._refresh&&this.clear(),this._isReady)for(let t in this.players)this.players[t].animate&&this.players[t].animate(r,this._time.diff,this);this._time.end>=0&&r>this._time.end&&(cancelAnimationFrame(this._animID),this._animID=-1,this._playing=!1)}pause(r=!1){return this._pause=r?!this._pause:!0,this}resume(){return this._pause=!1,this}stop(r=0){return this._time.end=r,this}playOnce(r=0){return this.play(),this.stop(r),this}render(r){return this._renderFunc&&this._renderFunc(r,this),this}set customRendering(r){this._renderFunc=r}get customRendering(){return this._renderFunc}get isPlaying(){return this._playing}get outerBound(){return this.bound.clone()}get innerBound(){return new G(h.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}},Y=class extends at{constructor(){super(...arguments);this._pressed=!1;this._dragged=!1;this._hasMouse=!1;this._hasTouch=!1;this._hasKeyboard=!1}get pointer(){let t=this._pointer.clone();return t.id=this._pointer.id,t}bindCanvas(t,e,i={},n){(n||this._canvas).addEventListener(t,e,i)}unbindCanvas(t,e,i={},n){(n||this._canvas).removeEventListener(t,e,i)}bindDoc(t,e,i={}){document&&document.addEventListener(t,e,i)}unbindDoc(t,e,i={}){document&&document.removeEventListener(t,e,i)}bindMouse(t=!0,e){return t?(this._mouseDown=this._mouseDown.bind(this),this._mouseUp=this._mouseUp.bind(this),this._mouseOver=this._mouseOver.bind(this),this._mouseOut=this._mouseOut.bind(this),this._mouseMove=this._mouseMove.bind(this),this._mouseClick=this._mouseClick.bind(this),this._contextMenu=this._contextMenu.bind(this),this.bindCanvas("pointerdown",this._mouseDown,{},e),this.bindCanvas("pointerup",this._mouseUp,{},e),this.bindCanvas("pointerover",this._mouseOver,{},e),this.bindCanvas("pointerout",this._mouseOut,{},e),this.bindCanvas("pointermove",this._mouseMove,{},e),this.bindCanvas("click",this._mouseClick,{},e),this.bindCanvas("contextmenu",this._contextMenu,{},e),this._hasMouse=!0):(this.unbindCanvas("pointerdown",this._mouseDown,{},e),this.unbindCanvas("pointerup",this._mouseUp,{},e),this.unbindCanvas("pointerover",this._mouseOver,{},e),this.unbindCanvas("pointerout",this._mouseOut,{},e),this.unbindCanvas("pointermove",this._mouseMove,{},e),this.unbindCanvas("click",this._mouseClick,{},e),this.unbindCanvas("contextmenu",this._contextMenu,{},e),this._hasMouse=!1),this}bindTouch(t=!0,e=!1,i){return t?(this.bindCanvas("touchstart",this._touchStart.bind(this),{passive:e},i),this.bindCanvas("touchend",this._mouseUp.bind(this),{},i),this.bindCanvas("touchmove",this._touchMove.bind(this),{passive:e},i),this.bindCanvas("touchcancel",this._mouseOut.bind(this),{},i),this._hasTouch=!0):(this.unbindCanvas("touchstart",this._touchStart.bind(this),{passive:e},i),this.unbindCanvas("touchend",this._mouseUp.bind(this),{},i),this.unbindCanvas("touchmove",this._touchMove.bind(this),{passive:e},i),this.unbindCanvas("touchcancel",this._mouseOut.bind(this),{},i),this._hasTouch=!1),this}bindKeyboard(t=!0){return t?(this._keyDownBind=this._keyDown.bind(this),this._keyUpBind=this._keyUp.bind(this),this.bindDoc("keydown",this._keyDownBind,{}),this.bindDoc("keyup",this._keyUpBind,{}),this._hasKeyboard=!0):(this.unbindDoc("keydown",this._keyDownBind,{}),this.unbindDoc("keyup",this._keyUpBind,{}),this._hasKeyboard=!1),this}touchesToPoints(t,e="touches"){if(!t||!t[e])return[];let i=[];for(let n=0;n<t[e].length;n++){let s=t[e].item(n);i.push(new h(s.pageX-this.bound.topLeft.x,s.pageY-this.bound.topLeft.y))}return i}_mouseAction(t,e){if(!this.isPlaying)return;let i=0,n=0;if(e instanceof MouseEvent){for(let s in this.players)if(this.players.hasOwnProperty(s)){let o=this.players[s];i=e.pageX-this.outerBound.x,n=e.pageY-this.outerBound.y,o.action&&o.action(t,i,n,e)}}else for(let s in this.players)if(this.players.hasOwnProperty(s)){let o=this.players[s],a=e.changedTouches&&e.changedTouches.length>0,u=e.changedTouches.item(0);i=a?u.pageX-this.outerBound.x:0,n=a?u.pageY-this.outerBound.y:0,o.action&&o.action(t,i,n,e)}t&&(this._pointer.to(i,n),this._pointer.id=t)}_mouseDown(t){return this._mouseAction(v.down,t),this._mouseAction(v.pointerdown,t),this._pressed=!0,t.target instanceof Element&&t.target.setPointerCapture(t.pointerId),!1}_mouseUp(t){return this._mouseAction(v.pointerup,t),this._dragged?this._mouseAction(v.drop,t):this._mouseAction(v.up,t),this._pressed=!1,this._dragged=!1,t.target instanceof Element&&t.target.releasePointerCapture(t.pointerId),!1}_mouseMove(t){return this._pressed?(this._dragged=!0,this._mouseAction(v.drag,t)):this._mouseAction(v.move,t),!1}_mouseOver(t){return this._mouseAction(v.over,t),!1}_mouseOut(t){return this._mouseAction(v.out,t),this._dragged&&this._mouseAction(v.drop,t),this._dragged=!1,!1}_mouseClick(t){return this._mouseAction(v.click,t),this._pressed=!1,this._dragged=!1,!1}_contextMenu(t){return this._mouseAction(v.contextmenu,t),!1}_touchMove(t){return this._mouseAction(v.move,t),this._pressed&&(this._dragged=!0,this._mouseAction(v.drag,t)),t.preventDefault(),!1}_touchStart(t){return this._mouseAction(v.down,t),this._pressed=!0,!1;return t.preventDefault(),!1}_keyDown(t){return this._keyboardAction(v.keydown,t),!1}_keyUp(t){return this._keyboardAction(v.keyup,t),!1}_keyboardAction(t,e){if(this.isPlaying){for(let i in this.players)if(this.players.hasOwnProperty(i)){let n=this.players[i];n.action&&n.action(t,e.shiftKey?1:0,e.altKey?1:0,e)}}}};var It={};T(It,{Font:()=>O,Form:()=>lt,VisualForm:()=>q});var lt=class{constructor(){this._ready=!1}get ready(){return this._ready}},q=class extends lt{constructor(){super(...arguments);this._filled=!0;this._stroked=!0;this._font=new O(14,"sans-serif")}get filled(){return this._filled}set filled(t){this._filled=t}get stroked(){return this._stroked}set stroked(t){this._stroked=t}get currentFont(){return this._font}_multiple(t,e,...i){if(!t)return this;for(let n=0,s=t.length;n<s;n++)this[e](t[n],...i);return this}alpha(t){return this}fill(t){return this}fillOnly(t){return this.stroke(!1),this.fill(t)}stroke(t,e,i,n){return this}strokeOnly(t,e,i,n){return this.fill(!1),this.stroke(t,e,i,n)}points(t,e,i){if(t){for(let n=0,s=t.length;n<s;n++)this.point(t[n],e,i);return this}}circles(t){return this._multiple(t,"circle")}squares(t){return this._multiple(t,"square")}lines(t){return this._multiple(t,"line")}polygons(t){return this._multiple(t,"polygon")}rects(t){return this._multiple(t,"rect")}},O=class{constructor(r=12,t="sans-serif",e="",i="",n=1.5){this.size=r,this.face=t,this.style=i,this.weight=e,this.lineHeight=n}get value(){return`${this.style} ${this.weight} ${this.size}px/${this.lineHeight} ${this.face}`}toString(){return this.value}};var Ct={};T(Ct,{Typography:()=>Z});var Z=class{static textWidthEstimator(r,t=["M","n","."],e=[.06,.8,.14]){let i=t.map(r),n=new h(e).dot(i);return s=>s.length*n}static truncate(r,t,e,i=""){let n=Math.floor(t.length*Math.min(1,e/r(t)));return n<t.length?(n=Math.max(0,n-i.length),[t.substr(0,n)+i,n]):[t,t.length]}static fontSizeToBox(r,t=1,e=!0){let i=G.fromGroup(r),n=e?i.height:i.width,s=t*n;return function(o){let a=G.fromGroup(o),u=(e?a.height:a.width)/n;return s*u}}static fontSizeToThreshold(r,t=0){return function(e,i){let n=e*i/r;return t<0?Math.min(n,e):t>0?Math.max(n,e):n}}};var Mt={};T(Mt,{Img:()=>J});var J=class l{constructor(r=!1,t,e){this._scale=1;this._loaded=!1;this._editable=r,this._space=t,this._scale=this._space?this._space.pixelScale:1,this._img=new Image,e&&(this._img.crossOrigin="Anonymous")}static load(r,t=!1,e,i){let n=new l(t,e);return n.load(r).then(s=>{i&&i(s)}),n}static loadAsync(r,t=!1,e){return et(this,null,function*(){return yield new l(t,e).load(r)})}static loadPattern(r,t,e="repeat",i=!1){return et(this,null,function*(){return(yield l.loadAsync(r,i,t)).pattern(e)})}static blank(r,t,e){let i=new l(!0,t),n=e||(t?t.pixelScale:1);return i.initCanvas(r[0],r[1],n),i}load(r){return new Promise((t,e)=>{this._editable&&!document&&e("Cannot create html canvas element. document not found."),this._img.src=r,this._img.onload=()=>{this._editable&&(this._cv||(this._cv=document.createElement("canvas")),this._drawToScale(this._scale,this._img),this._data=this._ctx.getImageData(0,0,this._cv.width,this._cv.height)),this._loaded=!0,t(this)},this._img.onerror=i=>{e(i)}})}_drawToScale(r,t){let e=t.width,i=t.height;this.initCanvas(e,i,r),t&&this._ctx.drawImage(t,0,0,e,i,0,0,this._cv.width,this._cv.height)}initCanvas(r,t,e=1){if(!this._editable){console.error("Cannot initiate canvas because this Img is not set to be editable");return}this._cv||(this._cv=document.createElement("canvas"));let i=typeof e=="number"?[e,e]:e;this._cv.width=r*i[0],this._cv.height=t*i[1],this._ctx=this._cv.getContext("2d"),this._loaded=!0}bitmap(r){let t=r?r[0]:this._cv.width,e=r?r[1]:this._cv.height;return createImageBitmap(this._cv,0,0,t,e)}pattern(r="repeat",t=!1){if(!this._space)throw"Cannot find CanvasSpace ctx to create image pattern";return this._space.ctx.createPattern(t?this._cv:this._img,r)}sync(){this._scale!==1?this.bitmap().then(r=>{this._drawToScale(1/this._scale,r),this.load(this.toBase64())}):this._img.src=this.toBase64()}pixel(r,t=!0){let e=typeof t=="number"?t:t?this._scale:1;return l.getPixel(this._data,[r[0]*e,r[1]*e])}static getPixel(r,t){let e=new h(0,0,0,0);if(t[0]>=r.width||t[1]>=r.height)return e;let i=Math.floor(t[1])*(r.width*4)+Math.floor(t[0])*4,n=r.data;return i>=n.length-4?e:new h(n[i],n[i+1],n[i+2],n[i+3])}resize(r,t=!1){let e=t?r:[r[0]/this._img.naturalWidth,r[1]/this._img.naturalHeight];return this._drawToScale(e,this._img),this._data=this._ctx.getImageData(0,0,this._cv.width,this._cv.height),this}crop(r){let t=r.topLeft.scale(this._scale),e=r.size.scale(this._scale);return this._ctx.getImageData(t.x,t.y,e.x,e.y)}filter(r){return this._ctx.filter=r,this._ctx.drawImage(this._cv,0,0),this._ctx.filter="none",this}cleanup(){this._cv&&this._cv.remove(),this._img&&this._img.remove(),this._data=null}static fromBlob(r,t=!1,e){let i=URL.createObjectURL(r);return new l(t,e).load(i)}static imageDataToBlob(r){return new Promise(function(t,e){document||e("Cannot create html canvas element. document not found.");let i=document.createElement("canvas");i.width=r.width,i.height=r.height,i.getContext("2d").putImageData(r,0,0),i.toBlob(n=>{t(n),i.remove()})})}toBase64(){return this._cv.toDataURL()}toBlob(){return new Promise(r=>{this._cv.toBlob(t=>r(t))})}getForm(){return this._editable||console.error("Cannot get a CanvasForm because this Img is not editable"),this._ctx?new Q(this._ctx):void 0}get current(){return this._editable?this._cv:this._img}get image(){return this._img}get canvas(){return this._cv}get data(){return this._data}get ctx(){return this._ctx}get loaded(){return this._loaded}get pixelScale(){return this._scale}get imageSize(){return!this._img.width||!this._img.height?this.canvasSize.$divide(this._scale):new h(this._img.width,this._img.height)}get canvasSize(){return new h(this._cv.width,this._cv.height)}get scaledMatrix(){let r=1/this._scale;return new C().scale2D([r,r])}};var tt=class extends Y{constructor(t,e){super();this._pixelScale=1;this._autoResize=!0;this._bgcolor="#e1e9f0";this._offscreen=!1;this._initialResize=!1;let i=null,n=!1;if(this.id=m.uniqueId(),t instanceof Element)i=t,this.id=i.id||this.id;else{let s=t;s=t[0]==="#"||t[0]==="."?t:"#"+t,i=document.querySelector(s),this.id=s.substr(1)}if(i?i.nodeName.toLowerCase()!="canvas"?(this._container=i,this._canvas=this._createElement("canvas",this.id+"_canvas"),this._initialResize=!0):(this._canvas=i,this._container=i.parentElement,this._autoResize=!1,n=!0):(this._container=this._createElement("div",this.id+"_container"),this._canvas=this._createElement("canvas",this.id),document.body.appendChild(this._container)),n)this._ready(e);else{let s=new MutationObserver(o=>{o.forEach(a=>{if(a.type==="childList"&&a.addedNodes.length){for(let u of a.addedNodes)if(u===this._canvas){this._ready(e),s.disconnect();return}}})});s.observe(this._container,{childList:!0}),this._container.appendChild(this._canvas)}this._ctx=this._canvas.getContext("2d")}_createElement(t="div",e){let i=document.createElement(t);return i.setAttribute("id",e),i}_ready(t){if(!this._container)throw new Error(`Cannot initiate #${this.id} element`);this._isReady=!0,this._resizeHandler(null),this.clear(this._bgcolor),this._canvas.dispatchEvent(new Event("ready"));for(let e in this.players)this.players.hasOwnProperty(e)&&this.players[e].start&&this.players[e].start(this.bound.clone(),this);this._pointer=this.center,this._initialResize=!1,t&&t(this.bound,this._canvas)}setup(t){if(this._bgcolor=t.bgcolor?t.bgcolor:"transparent",this.autoResize=t.resize!=null?t.resize:!1,t.retina!==!1){let e=window&&window.devicePixelRatio||1,i=this._ctx.webkitBackingStorePixelRatio||this._ctx.mozBackingStorePixelRatio||this._ctx.msBackingStorePixelRatio||this._ctx.oBackingStorePixelRatio||this._ctx.backingStorePixelRatio||1;this._pixelScale=Math.max(1,e/i)}return t.offscreen?(this._offscreen=!0,this._offCanvas=this._createElement("canvas",this.id+"_offscreen"),this._offCtx=this._offCanvas.getContext("2d")):this._offscreen=!1,t.pixelDensity&&(this._pixelScale=t.pixelDensity),this}set autoResize(t){window&&(this._autoResize=t,t?window.addEventListener("resize",this._resizeHandler.bind(this)):window.removeEventListener("resize",this._resizeHandler.bind(this)))}get autoResize(){return this._autoResize}resize(t,e){this.bound=t,this._canvas.width=Math.ceil(this.bound.size.x)*this._pixelScale,this._canvas.height=Math.ceil(this.bound.size.y)*this._pixelScale,this._canvas.style.width=Math.ceil(this.bound.size.x)+"px",this._canvas.style.height=Math.ceil(this.bound.size.y)+"px",this._offscreen&&(this._offCanvas.width=Math.ceil(this.bound.size.x)*this._pixelScale,this._offCanvas.height=Math.ceil(this.bound.size.y)*this._pixelScale),this._pixelScale!=1&&(this._ctx.scale(this._pixelScale,this._pixelScale),this._offscreen&&this._offCtx.scale(this._pixelScale,this._pixelScale));for(let i in this.players)if(this.players.hasOwnProperty(i)){let n=this.players[i];n.resize&&n.resize(this.bound,e)}return this.render(this._ctx),e&&!this.isPlaying&&this.playOnce(0),this}_resizeHandler(t){if(!window)return;let e=this._autoResize||this._initialResize?this._container.getBoundingClientRect():this._canvas.getBoundingClientRect();if(e){let i=G.fromBoundingRect(e);i.center=i.center.add(window.pageXOffset,window.pageYOffset),this.resize(i,t)}}set background(t){this._bgcolor=t}get background(){return this._bgcolor}get pixelScale(){return this._pixelScale}get hasOffscreen(){return this._offscreen}get offscreenCtx(){return this._offCtx}get offscreenCanvas(){return this._offCanvas}getForm(){return new Q(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,i=Math.ceil(this.pixelScale);return!this._bgcolor||this._bgcolor==="transparent"?this._ctx.clearRect(-i,-i,this._canvas.width+i,this._canvas.height+i):((this._bgcolor.indexOf("rgba")===0||this._bgcolor.length===9&&this._bgcolor.indexOf("#")===0)&&this._ctx.clearRect(-i,-i,this._canvas.width+i,this._canvas.height+i),this._ctx.fillStyle=this._bgcolor,this._ctx.fillRect(-i,-i,this._canvas.width+i,this._canvas.height+i)),this._ctx.fillStyle=e,this}clearOffscreen(t){if(this._offscreen){let e=Math.ceil(this.pixelScale);t?(this._offCtx.fillStyle=t,this._offCtx.fillRect(-e,-e,this._canvas.width+e,this._canvas.height+e)):this._offCtx.clearRect(-e,-e,this._offCanvas.width+e,this._offCanvas.height+e)}return this}playItems(t){this._isReady&&(this._ctx.save(),this._offscreen&&this._offCtx.save(),super.playItems(t),this._ctx.restore(),this._offscreen&&this._offCtx.restore(),this.render(this._ctx))}dispose(){if(window)return window.removeEventListener("resize",this._resizeHandler.bind(this)),this.stop(),this.removeAll(),this}recorder(t,e="webm",i=15e6){let n=this._canvas.captureStream(),s=new MediaRecorder(n,{mimeType:`video/${e}`,bitsPerSecond:i});return s.ondataavailable=function(o){let a=URL.createObjectURL(new Blob([o.data],{type:`video/${e}`}));if(typeof t=="function")t(a);else if(t){let u=document.createElement("a");u.href=a,u.download=`canvas_video.${e}`,u.click(),u.remove()}},s}},Q=class l extends q{constructor(t){super();this._style={fillStyle:"#f03",strokeStyle:"#fff",lineWidth:1,lineJoin:"bevel",lineCap:"butt",globalAlpha:1};if(!t)return this;let e=i=>{this._ctx=i,this._ctx.fillStyle=this._style.fillStyle,this._ctx.strokeStyle=this._style.strokeStyle,this._ctx.lineJoin="bevel",this._ctx.font=this._font.value,this._ready=!0};t instanceof tt?(this._space=t,this._space.ready&&this._space.ctx?e(this._space.ctx):this._space.add({start:()=>{e(this._space.ctx)}})):e(t)}get space(){return this._space}get ctx(){return this._ctx}useOffscreen(t=!0,e=!1){return e&&this._space.clearOffscreen(typeof e=="string"?e:null),this._ctx=this._space.hasOffscreen&&t?this._space.offscreenCtx:this._space.ctx,this}renderOffscreen(t=[0,0]){this._space.hasOffscreen&&this._space.ctx.drawImage(this._space.offscreenCanvas,t[0],t[1],this._space.width,this._space.height)}alpha(t){return this._ctx.globalAlpha=t,this._style.globalAlpha=t,this}fill(t){return typeof t=="boolean"?this.filled=t:(this.filled=!0,this._style.fillStyle=t,this._ctx.fillStyle=t),this}fillOnly(t){return this.stroke(!1),this.fill(t)}stroke(t,e,i,n){return typeof t=="boolean"?this.stroked=t:(this.stroked=!0,this._style.strokeStyle=t,this._ctx.strokeStyle=t,e&&(this._ctx.lineWidth=e,this._style.lineWidth=e),i&&(this._ctx.lineJoin=i,this._style.lineJoin=i),n&&(this._ctx.lineCap=n,this._style.lineCap=n)),this}strokeOnly(t,e,i,n){return this.fill(!1),this.stroke(t,e,i,n)}applyFillStroke(t=!0,e=!0,i=1){return t&&(typeof t=="string"&&this.fill(t),this._ctx.fill()),e&&(typeof e=="string"&&this.stroke(e,i),this._ctx.stroke()),this}gradient(t){let e=[];t.length<2&&t.push([.99,"#000"],[1,"#000"]);for(let i=0,n=t.length;i<n;i++){let s=typeof t[i]=="string"?i*(1/(t.length-1)):t[i][0],o=typeof t[i]=="string"?t[i]:t[i][1];e.push([s,o])}return(i,n)=>{let s=n?this._ctx.createRadialGradient(i[0][0],i[0][1],Math.abs(i[1][0]),n[0][0],n[0][1],Math.abs(n[1][0])):this._ctx.createLinearGradient(i[0][0],i[0][1],i[1][0],i[1][1]);for(let o=0,a=e.length;o<a;o++)s.addColorStop(e[o][0],e[o][1]);return s}}composite(t="source-over"){return this._ctx.globalCompositeOperation=t,this}clip(){return this._ctx.clip(),this}dash(t=!0,e=0){return t?(t===!0&&(t=[5,5]),this._ctx.setLineDash([t[0],t[1]]),this._ctx.lineDashOffset=e):(this._ctx.setLineDash([]),this._ctx.lineDashOffset=0),this}font(t,e,i,n,s){return typeof t=="number"?(this._font.size=t,s&&(this._font.face=s),e&&(this._font.weight=e),i&&(this._font.style=i),n&&(this._font.lineHeight=n)):this._font=t,this._ctx.font=this._font.value,this._estimateTextWidth&&this.fontWidthEstimate(!0),this}fontWidthEstimate(t=!0){return this._estimateTextWidth=t?Z.textWidthEstimator(e=>this._ctx.measureText(e).width):void 0,this}getTextWidth(t){return this._estimateTextWidth?this._estimateTextWidth(t):this._ctx.measureText(t+" .").width}_textTruncate(t,e,i=""){return Z.truncate(this.getTextWidth.bind(this),t,e,i)}_textAlign(t,e,i,n){let s=m.iterToArray(t);if(!m.arrayCheck(s))return;n||(n=M.center(s));let o=s[0][0];this._ctx.textAlign=="end"||this._ctx.textAlign=="right"?o=s[1][0]:(this._ctx.textAlign=="center"||this._ctx.textAlign=="middle")&&(o=n[0]);let a=n[1];return e=="top"||e=="start"?a=s[0][1]:(e=="end"||e=="bottom")&&(a=s[1][1]),i?new h(o+i[0],a+i[1]):new h(o,a)}reset(){for(let t in this._style)this._style.hasOwnProperty(t)&&(this._ctx[t]=this._style[t]);return this._font=new O,this._ctx.font=this._font.value,this}_paint(){this._filled&&this._ctx.fill(),this._stroked&&this._ctx.stroke()}static point(t,e,i=5,n="square"){if(e){if(!l[n])throw new Error(`${n} is not a static function of CanvasForm`);l[n](t,e,i)}}point(t,e=5,i="square"){return l.point(this._ctx,t,e,i),this._paint(),this}static circle(t,e,i=10){e&&(t.beginPath(),t.arc(e[0],e[1],i,0,w.two_pi,!1),t.closePath())}circle(t){let e=m.iterToArray(t);return l.circle(this._ctx,e[0],e[1][0]),this._paint(),this}static ellipse(t,e,i,n=0,s=0,o=w.two_pi,a=!1){!e||!i||(t.beginPath(),t.ellipse(e[0],e[1],i[0],i[1],n,s,o,a))}ellipse(t,e,i=0,n=0,s=w.two_pi,o=!1){return l.ellipse(this._ctx,t,e,i,n,s,o),this._paint(),this}static arc(t,e,i,n,s,o){e&&(t.beginPath(),t.arc(e[0],e[1],i,n,s,o))}arc(t,e,i,n,s){return l.arc(this._ctx,t,e,i,n,s),this._paint(),this}static square(t,e,i){if(!e)return;let n=e[0]-i,s=e[1]-i,o=e[0]+i,a=e[1]+i;t.beginPath(),t.moveTo(n,s),t.lineTo(n,a),t.lineTo(o,a),t.lineTo(o,s),t.closePath()}square(t,e){return l.square(this._ctx,t,e),this._paint(),this}static line(t,e){if(!m.arrayCheck(e))return;let i=0;t.beginPath();for(let n of e)n&&(i++>0?t.lineTo(n[0],n[1]):t.moveTo(n[0],n[1]))}line(t){return l.line(this._ctx,t),this._paint(),this}static polygon(t,e){m.arrayCheck(e)&&(l.line(t,e),t.closePath())}polygon(t){return l.polygon(this._ctx,t),this._paint(),this}static rect(t,e){let i=m.iterToArray(e);m.arrayCheck(i)&&(t.beginPath(),t.moveTo(i[0][0],i[0][1]),t.lineTo(i[0][0],i[1][1]),t.lineTo(i[1][0],i[1][1]),t.lineTo(i[1][0],i[0][1]),t.closePath())}rect(t){return l.rect(this._ctx,t),this._paint(),this}static image(t,e,i,n){let s=m.iterToArray(e),o;if(typeof s[0]=="number")o=s;else if(n){let a=m.iterToArray(n);o=[a[0][0],a[0][1],a[1][0]-a[0][0],a[1][1]-a[0][1],s[0][0],s[0][1],s[1][0]-s[0][0],s[1][1]-s[0][1]]}else o=[s[0][0],s[0][1],s[1][0]-s[0][0],s[1][1]-s[0][1]];i instanceof J?i.loaded&&t.drawImage(i.image,...o):t.drawImage(i,...o)}image(t,e,i){return e instanceof J?e.loaded&&l.image(this._ctx,t,e.image,i):l.image(this._ctx,t,e,i),this}static imageData(t,e,i){let n=m.iterToArray(e);typeof n[0]=="number"?t.putImageData(i,n[0],n[1]):t.putImageData(i,n[0][0],n[0][1],n[0][0],n[0][1],n[1][0],n[1][1])}imageData(t,e){return l.imageData(this._ctx,t,e),this}static text(t,e,i,n){e&&t.fillText(i,e[0],e[1],n)}text(t,e,i){return l.text(this._ctx,t,e,i),this}textBox(t,e,i="middle",n="",s=!0){s&&(this._ctx.textBaseline=i);let o=M.size(t),a=this._textTruncate(e,o[0],n);return this.text(this._textAlign(t,i),a[0]),this}paragraphBox(t,e,i=1.2,n="top",s=!0){let o=m.iterToArray(t),a=M.size(o);this._ctx.textBaseline="top";let u=this._font.size*i,c=(_,D=[],A=0)=>{if(!_||s&&A*u>a[1]-u*2)return D;if(A>1e4)throw new Error("max recursion reached (10000)");let U=this._textTruncate(_,a[0],""),bt=U[0].indexOf(`
6
6
  `);if(bt>=0)return D.push(U[0].substr(0,bt)),c(_.substr(bt+1),D,A+1);let nt=U[0].lastIndexOf(" ")+1;(nt<=0||U[1]===_.length)&&(nt=void 0);let Nt=U[0].substr(0,nt);return D.push(Nt),U[1]<=0||U[1]===_.length?D:c(_.substr(nt||U[1]),D,A+1)},f=c(e),p=f.length*u,b=o;if(n=="middle"||n=="center"){let _=(a[1]-p)/2;s&&(_=Math.max(0,_)),b=new d(o[0].$add(0,_),o[1].$subtract(0,_))}else n=="bottom"?b=new d(o[0].$add(0,a[1]-p),o[1]):b=new d(o[0],o[0].$add(a[0],p));let P=M.center(b);for(let _=0,D=f.length;_<D;_++)this.text(this._textAlign(b,"top",[0,_*u],P),f[_]);return this}alignText(t="left",e="alphabetic"){return e=="center"&&(e="middle"),e=="baseline"&&(e="alphabetic"),this._ctx.textAlign=t,this._ctx.textBaseline=e,this}log(t){let e=this._ctx.measureText(t).width+20;return this.stroke(!1).fill("rgba(0,0,0,.4)").rect([[0,0],[e,20]]),this.fill("#fff").text([10,14],t),this}};var $t={};T($t,{Create:()=>At,Delaunay:()=>mt,Noise:()=>ct});var At=class{static distributeRandom(r,t,e=2){let i=new d;for(let n=0;n<t;n++){let s=[r.x+L.random()*r.width];e>1&&s.push(r.y+L.random()*r.height),e>2&&s.push(r.z+L.random()*r.depth),i.push(new h(s))}return i}static distributeLinear(r,t){let e=m.iterToArray(r),i=E.subpoints(e,t-2);return i.unshift(e[0]),i.push(e[e.length-1]),i}static gridPts(r,t,e,i=[.5,.5]){if(t===0||e===0)throw new Error("grid columns and rows cannot be 0");let n=r.size.$subtract(1).$divide(t,e),s=n.$multiply(i),o=new d;for(let a=0;a<e;a++)for(let u=0;u<t;u++)o.push(r.topLeft.$add(n.$multiply(u,a)).add(s));return o}static gridCells(r,t,e){if(t===0||e===0)throw new Error("grid columns and rows cannot be 0");let i=r.size.$subtract(1).divide(t,e),n=[];for(let s=0;s<e;s++)for(let o=0;o<t;o++)n.push(new d(r.topLeft.$add(i.$multiply(o,s)),r.topLeft.$add(i.$multiply(o,s).add(i))));return n}static radialPts(r,t,e,i=-w.half_pi){let n=new d,s=w.two_pi/e;for(let o=0;o<e;o++)n.push(new h(r).toAngle(s*o+i,t,!0));return n}static noisePts(r,t=.01,e=.01,i=0,n=0){let s=L.random(),o=new d,a=0;for(let u of r){let c=new ct(u),f=i&&i>0?Math.floor(a/i):a,p=n&&n>0?a%n:a;c.initNoise(t*p,e*f),c.seed(s),o.push(c),a++}return o}static delaunay(r){return mt.from(r)}},ut=[[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]],ht=[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],ct=class extends h{constructor(...t){super(...t);this.perm=[];this._n=new h(.01,.01);this.perm=ht.concat(ht)}initNoise(...t){return this._n=new h(...t),this}step(t=0,e=0){return this._n.add(t,e),this}seed(t){t>0&&t<1&&(t*=65536),t=Math.floor(t),t<256&&(t|=t<<8);for(let e=0;e<255;e++){let i=e&1?ht[e]^t&255:ht[e]^t>>8&255;this.perm[e]=this.perm[e+256]=i}return this}noise2D(){let t=Math.max(0,Math.floor(this._n[0]))%255,e=Math.max(0,Math.floor(this._n[1]))%255,i=this._n[0]%255-t,n=this._n[1]%255-e,s=k.dot(ut[(t+this.perm[e])%12],[i,n,0]),o=k.dot(ut[(t+this.perm[e+1])%12],[i,n-1,0]),a=k.dot(ut[(t+1+this.perm[e])%12],[i-1,n,0]),u=k.dot(ut[(t+1+this.perm[e+1])%12],[i-1,n-1,0]),c=p=>p*p*p*(p*(p*6-15)+10),f=c(i);return L.lerp(L.lerp(s,a,f),L.lerp(o,u,f),c(n))}},mt=class l extends d{constructor(){super(...arguments);this._mesh=[]}delaunay(t=!0){if(this.length<3)return[];this._mesh=[];let e=this.length,i=[];for(let c=0;c<e;c++)i[c]=c;i.sort((c,f)=>this[f][0]-this[c][0]);let n=this.slice(),s=this._superTriangle();n=n.concat(s);let o=[this._circum(e,e+1,e+2,s)],a=[],u=[];for(let c=0,f=i.length;c<f;c++){let p=i[c],b=[],P=o.length;for(this._mesh[p]||(this._mesh[p]={});P--;){let _=o[P],D=_.circle[1][0],A=n[p].$subtract(_.circle[0]);if(A[0]>0&&A[0]*A[0]>D*D){a.push(_),u.push(_.triangle),o.splice(P,1);continue}A[0]*A[0]+A[1]*A[1]-D*D>w.epsilon||(b.push(_.i,_.j,_.j,_.k,_.k,_.i),o.splice(P,1))}for(l._dedupe(b),P=b.length;P>1;)o.push(this._circum(b[--P],b[--P],p,!1,n))}for(let c=0,f=o.length;c<f;c++){let p=o[c];p.i<e&&p.j<e&&p.k<e&&(a.push(p),u.push(p.triangle),this._cache(p))}return t?u:a}voronoi(){let t=[],e=this._mesh;for(let i=0,n=e.length;i<n;i++)t.push(this.neighborPts(i,!0));return t}mesh(){return this._mesh}neighborPts(t,e=!1){let i=new d,n=this._mesh;for(let s in n[t])n[t].hasOwnProperty(s)&&i.push(n[t][s].circle[0]);return e?y.sortEdges(i):i}neighbors(t){let e=[],i=this._mesh;for(let n in i[t])i[t].hasOwnProperty(n)&&e.push(i[t][n]);return e}_cache(t){this._mesh[t.i][`${Math.min(t.j,t.k)}-${Math.max(t.j,t.k)}`]=t,this._mesh[t.j][`${Math.min(t.i,t.k)}-${Math.max(t.i,t.k)}`]=t,this._mesh[t.k][`${Math.min(t.i,t.j)}-${Math.max(t.i,t.j)}`]=t}_superTriangle(){let t=this[0],e=this[0];for(let o=1,a=this.length;o<a;o++)t=t.$min(this[o]),e=e.$max(this[o]);let i=e.$subtract(t),n=t.$add(e).divide(2),s=Math.max(i[0],i[1]);return new d(n.$subtract(20*s,s),n.$add(0,20*s),n.$add(20*s,-s))}_triangle(t,e,i,n=this){return new d(n[t],n[e],n[i])}_circum(t,e,i,n,s=this){let o=n||this._triangle(t,e,i,s);return{i:t,j:e,k:i,triangle:o,circle:j.circumcircle(o)}}static _dedupe(t){let e=t.length;for(;e>1;){let i=t[--e],n=t[--e],s=e;for(;s>1;){let o=t[--s],a=t[--s];if(n==a&&i==o||n==o&&i==a){t.splice(e,2),t.splice(s,2);break}}}return t}};var Gt={};T(Gt,{Color:()=>Tt});var g=class g extends h{constructor(...t){super(...t);this._mode="rgb";this._isNorm=!1}static from(...t){let e=[1,1,1,1],i=m.getArgs(t);for(let n=0,s=e.length;n<s;n++)n<i.length&&(e[n]=i[n]);return new g(e)}static fromHex(t){if(t[0]=="#"&&(t=t.substr(1)),t.length<=3){let n=s=>t[s]||"F";t=`${n(0)}${n(0)}${n(1)}${n(1)}${n(2)}${n(2)}`}let e=1;t.length===8&&(e=t.substr(6)&&255/255,t=t.substring(0,6));let i=parseInt(t,16);return new g(i>>16,i>>8&255,i&255,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 i=this._mode.toUpperCase()+"to"+t.toUpperCase();if(g[i])this.to(g[i](this,this._isNorm,this._isNorm));else throw new Error("Cannot convert color with "+i)}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 this._mode=="lch"?this[2]:this[0]}set h(t){let e=this._mode=="lch"?2:0;this[e]=t}get s(){return this[1]}set s(t){this[1]=t}get l(){return this._mode=="hsl"?this[2]:this[0]}set l(t){let e=this._mode=="hsl"?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}set alpha(t){this.length>3&&(this[3]=t)}get alpha(){return this.length>3?this[3]:1}get normalized(){return this._isNorm}set normalized(t){this._isNorm=t}normalize(t=!0){if(this._isNorm==t)return this;let e=g.ranges[this._mode];for(let i=0;i<3;i++)this[i]=t?L.mapToRange(this[i],e[i][0],e[i][1],0,1):L.mapToRange(this[i],0,1,e[i][0],e[i][1]);return this._isNorm=t,this}$normalize(t=!0){return this.clone().normalize(t)}toString(t="mode"){if(t=="hex"){let e=i=>{let n=Math.floor(i).toString(16);return n.length<2?"0"+n:n};return`#${e(this[0])}${e(this[1])}${e(this[2])}`}else return t=="rgba"?`rgba(${Math.floor(this[0])},${Math.floor(this[1])},${Math.floor(this[2])},${this.alpha})`:t=="rgb"?`rgb(${Math.floor(this[0])},${Math.floor(this[1])},${Math.floor(this[2])})`:`${this._mode}(${this[0]},${this[1]},${this[2]},${this.alpha})`}static RGBtoHSL(t,e=!1,i=!1){let[n,s,o]=e?t:t.$normalize(),a=Math.max(n,s,o),u=Math.min(n,s,o),c=(a+u)/2,f=c,p=c;if(a==u)c=0,f=0;else{let b=a-u;f=p>.5?b/(2-a-u):b/(a+u),c=0,a===n?c=(s-o)/b+(s<o?6:0):a===s?c=(o-n)/b+2:a===o&&(c=(n-s)/b+4)}return g.hsl(i?c/60:c*60,f,p,t.alpha)}static HSLtoRGB(t,e=!1,i=!1){let[n,s,o]=t;if(e||(n=n/360),s==0)return g.rgb(o*255,o*255,o*255,t.alpha);let a=o<=.5?o*(1+s):o+s-o*s,u=2*o-a,c=p=>(p=p<0?p+1:p>1?p-1:p,p*6<1?u+(a-u)*p*6:p*2<1?a:p*3<2?u+(a-u)*(2/3-p)*6:u),f=i?1:255;return g.rgb(f*c(n+1/3),f*c(n),f*c(n-1/3),t.alpha)}static RGBtoHSB(t,e=!1,i=!1){let[n,s,o]=e?t:t.$normalize(),a=Math.max(n,s,o),u=Math.min(n,s,o),c=a-u,f=0,p=a===0?0:c/a,b=a;return a!=u&&(a===n?f=(s-o)/c+(s<o?6:0):a===s?f=(o-n)/c+2:a===o&&(f=(n-s)/c+4)),g.hsb(i?f/60:f*60,p,b,t.alpha)}static HSBtoRGB(t,e=!1,i=!1){let[n,s,o]=t;e||(n=n/360);let a=Math.floor(n*6),u=n*6-a,c=o*(1-s),f=o*(1-u*s),p=o*(1-(1-u)*s),P=[[o,p,c],[f,o,c],[c,o,p],[c,f,o],[p,c,o],[o,c,f]][a%6],_=i?1:255;return g.rgb(_*P[0],_*P[1],_*P[2],t.alpha)}static RGBtoLAB(t,e=!1,i=!1){let n=e?t.$normalize(!1):t;return g.XYZtoLAB(g.RGBtoXYZ(n),!1,i)}static LABtoRGB(t,e=!1,i=!1){let n=e?t.$normalize(!1):t;return g.XYZtoRGB(g.LABtoXYZ(n),!1,i)}static RGBtoLCH(t,e=!1,i=!1){let n=e?t.$normalize(!1):t;return g.LABtoLCH(g.RGBtoLAB(n),!1,i)}static LCHtoRGB(t,e=!1,i=!1){let n=e?t.$normalize(!1):t;return g.LABtoRGB(g.LCHtoLAB(n),!1,i)}static RGBtoLUV(t,e=!1,i=!1){let n=e?t.$normalize(!1):t;return g.XYZtoLUV(g.RGBtoXYZ(n),!1,i)}static LUVtoRGB(t,e=!1,i=!1){let n=e?t.$normalize(!1):t;return g.XYZtoRGB(g.LUVtoXYZ(n),!1,i)}static RGBtoXYZ(t,e=!1,i=!1){let n=e?t.clone():t.$normalize();for(let o=0;o<3;o++)n[o]=n[o]>.04045?Math.pow((n[o]+.055)/1.055,2.4):n[o]/12.92,i||(n[o]=n[o]*100);let s=g.xyz(n[0]*.4124564+n[1]*.3575761+n[2]*.1804375,n[0]*.2126729+n[1]*.7151522+n[2]*.072175,n[0]*.0193339+n[1]*.119192+n[2]*.9503041,t.alpha);return i?s.normalize():s}static XYZtoRGB(t,e=!1,i=!1){let[n,s,o]=e?t:t.$normalize(),a=[n*3.2406254773200533+s*-1.5372079722103187+o*-.4986285986982479,n*-.9689307147293197+s*1.8757560608852415+o*.041517523842953964,n*.055710120445510616+s*-.2040210505984867+o*1.0569959422543882];for(let c=0;c<3;c++)a[c]=a[c]>.0031308?1.055*Math.pow(a[c],1/2.4)-.055:12.92*a[c],a[c]=Math.max(0,Math.min(1,a[c])),i||(a[c]=Math.round(a[c]*255));let u=g.rgb(a[0],a[1],a[2],t.alpha);return i?u.normalize():u}static XYZtoLAB(t,e=!1,i=!1){let n=e?t.$normalize(!1):t.clone(),s=.00885645167,o=903.296296296;n.divide(g.D65);let a=f=>f>s?Math.pow(f,1/3):(o*f+16)/116,u=a(n[1]),c=g.lab(116*u-16,500*(a(n[0])-u),200*(u-a(n[2])),t.alpha);return i?c.normalize():c}static LABtoXYZ(t,e=!1,i=!1){let n=e?t.$normalize(!1):t,s=(n[0]+16)/116,o=n[1]/500+s,a=s-n[2]/200,u=.00885645167,c=903.296296296,f=g.D65,p=Math.pow(o,3),b=Math.pow(a,3),P=g.xyz(f[0]*(p>u?p:(116*o-16)/c),f[1]*(n[0]>c*u?Math.pow((n[0]+16)/116,3):n[0]/c),f[2]*(b>u?b:(116*a-16)/c),t.alpha);return i?P.normalize():P}static XYZtoLUV(t,e=!1,i=!1){let[n,s,o]=e?t.$normalize(!1):t,a=4*n/(n+15*s+3*o),u=9*s/(n+15*s+3*o);s=s/100,s=s>.008856?Math.pow(s,1/3):7.787*s+16/116;let c=4*g.D65[0]/(g.D65[0]+15*g.D65[1]+3*g.D65[2]),f=9*g.D65[1]/(g.D65[0]+15*g.D65[1]+3*g.D65[2]),p=116*s-16;return g.luv(p,13*p*(a-c),13*p*(u-f),t.alpha)}static LUVtoXYZ(t,e=!1,i=!1){let[n,s,o]=e?t.$normalize(!1):t,a=(n+16)/116,u=a*a*a;a=u>.008856?u:(a-16/116)/7.787;let c=4*g.D65[0]/(g.D65[0]+15*g.D65[1]+3*g.D65[2]),f=9*g.D65[1]/(g.D65[0]+15*g.D65[1]+3*g.D65[2]);s=s/(13*n)+c,o=o/(13*n)+f,a=a*100;let p=-1*(9*a*s)/((s-4)*o-s*o),b=(9*a-15*o*a-o*p)/(3*o);return g.xyz(p,a,b,t.alpha)}static LABtoLCH(t,e=!1,i=!1){let n=e?t.$normalize(!1):t,s=y.toDegree(y.boundRadian(Math.atan2(n[2],n[1])));return g.lch(n[0],Math.sqrt(n[1]*n[1]+n[2]*n[2]),s,t.alpha)}static LCHtoLAB(t,e=!1,i=!1){let n=e?t.$normalize(!1):t,s=y.toRadian(n[2]);return g.lab(n[0],Math.cos(s)*n[1],Math.sin(s)*n[1],t.alpha)}};g.D65=new h(95.047,100,108.883,1),g.ranges={rgb:new d(new h(0,255),new h(0,255),new h(0,255)),hsl:new d(new h(0,360),new h(0,1),new h(0,1)),hsb:new d(new h(0,360),new h(0,1),new h(0,1)),lab:new d(new h(0,100),new h(-128,127),new h(-128,127)),lch:new d(new h(0,100),new h(0,100),new h(0,360)),luv:new d(new h(0,100),new h(-134,220),new h(-140,122)),xyz:new d(new h(0,100),new h(0,100),new h(0,100))};var Tt=g;var Et={};T(Et,{DOMSpace:()=>z,HTMLForm:()=>rt,HTMLSpace:()=>R});var z=class l extends Y{constructor(t,e){super();this.id="domspace";this._autoResize=!0;this._bgcolor="#e1e9f0";this._css={};let i=null,n=!1;this.id="pts",t instanceof Element?(i=t,this.id="pts_existing_space"):(i=document.querySelector(t),n=!0,this.id=t.substr(1)),i?(this._canvas=i,this._container=i.parentElement):(this._container=l.createElement("div","pts_container"),this._canvas=l.createElement("div","pts_element"),this._container.appendChild(this._canvas),document.body.appendChild(this._container),n=!1),setTimeout(this._ready.bind(this,e),50)}static createElement(t="div",e,i){let n=document.createElement(t);return e&&n.setAttribute("id",e),i&&i.appendChild&&i.appendChild(n),n}_ready(t){if(!this._container)throw new Error(`Cannot initiate #${this.id} element`);this._isReady=!0,this._resizeHandler(null),this.clear(this._bgcolor),this._canvas.dispatchEvent(new Event("ready"));for(let e in this.players)this.players.hasOwnProperty(e)&&this.players[e].start&&this.players[e].start(this.bound.clone(),this);this._pointer=this.center,this.refresh(!1),t&&t(this.bound,this._canvas)}setup(t){return t.bgcolor&&(this._bgcolor=t.bgcolor),this.autoResize=t.resize!=null?t.resize:!1,this}getForm(){return null}set autoResize(t){this._autoResize=t,t?window.addEventListener("resize",this._resizeHandler.bind(this)):(delete this._css.width,delete this._css.height,window.removeEventListener("resize",this._resizeHandler.bind(this)))}get autoResize(){return this._autoResize}resize(t,e){this.bound=t,this.styles({width:`${t.width}px`,height:`${t.height}px`},!0);for(let i in this.players)if(this.players.hasOwnProperty(i)){let n=this.players[i];n.resize&&n.resize(this.bound,e)}return this}_resizeHandler(t){let e=G.fromBoundingRect(this._container.getBoundingClientRect());this._autoResize?this.styles({width:"100%",height:"100%"},!0):this.styles({width:`${e.width}px`,height:`${e.height}px`},!0),this.resize(e,t)}get element(){return this._canvas}get parent(){return this._container}get ready(){return this._isReady}clear(t){return t&&(this.background=t),this._canvas.innerHTML="",this}set background(t){this._bgcolor=t,this._container.style.backgroundColor=this._bgcolor}get background(){return this._bgcolor}style(t,e,i=!1){return this._css[t]=e,i&&(this._canvas.style[t]=e),this}styles(t,e=!1){for(let i in t)t.hasOwnProperty(i)&&this.style(i,t[i],e);return this}static setAttr(t,e){for(let i in e)e.hasOwnProperty(i)&&t.setAttribute(i,e[i]);return t}static getInlineStyles(t){let e="";for(let i in t)t.hasOwnProperty(i)&&t[i]&&(e+=`${i}: ${t[i]}; `);return e}dispose(){return window.removeEventListener("resize",this._resizeHandler.bind(this)),this.stop(),this.removeAll(),this}},R=class extends z{getForm(){return new rt(this)}static htmlElement(r,t,e,i=!0){if(!r||!r.appendChild)throw new Error("parent is not a valid DOM element");let n=document.querySelector(`#${e}`);return n||(n=document.createElement(t),n.setAttribute("id",e),i&&n.setAttribute("class",e.substring(0,e.indexOf("-"))),r.appendChild(n)),n}remove(r){return this._container.querySelectorAll("."+rt.scopeID(r)).forEach(e=>{e.parentNode.removeChild(e)}),super.remove(r)}removeAll(){return this._container.innerHTML="",super.removeAll()}},I=class I extends q{constructor(t){super();this._style={filled:!0,stroked:!0,background:"#f03","border-color":"#fff",color:"#000","border-width":"1px","border-radius":"0","border-style":"solid",opacity:1,position:"absolute",top:0,left:0,width:0,height:0};this._ctx={group:null,groupID:"pts",groupCount:0,currentID:"pts0",currentClass:"",style:{}};this._ready=!1;this._space=t,this._space.add({start:()=>{this._ctx.group=this._space.element,this._ctx.groupID="pts_dom_"+I.groupID++,this._ctx.style=Object.assign({},this._style),this._ready=!0}})}get space(){return this._space}styleTo(t,e,i=""){if(this._ctx.style[t]===void 0)throw new Error(`${t} style property doesn't exist`);this._ctx.style[t]=`${e}${i}`}alpha(t){return this.styleTo("opacity",t),this}fill(t){return typeof t=="boolean"?(this.styleTo("filled",t),t||this.styleTo("background","transparent")):(this.styleTo("filled",!0),this.styleTo("background",t)),this}stroke(t,e,i,n){return typeof t=="boolean"?(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 typeof t=="boolean"?this._ctx.currentClass="":this._ctx.currentClass=t,this}font(t,e,i,n,s){return typeof t=="number"?(this._font.size=t,s&&(this._font.face=s),e&&(this._font.weight=e),i&&(this._font.style=i),n&&(this._font.lineHeight=n)):this._font=t,this._ctx.style.font=this._font.value,this}reset(){return this._ctx.style=Object.assign({},this._style),this._font=new O(10,"sans-serif"),this._ctx.style.font=this._font.value,this}updateScope(t,e){return this._ctx.group=e,this._ctx.groupID=t,this._ctx.groupCount=0,this.nextID(),this._ctx}scope(t){if(!t||t.animateID==null)throw new Error("item not defined or not yet added to Space");return this.updateScope(I.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-${I.domID++}`}static scopeID(t){return`item-${t.animateID}`}static style(t,e){let i=[];e.filled||i.push("background: none"),e.stroked||i.push("border: none");for(let n in e)if(e.hasOwnProperty(n)&&n!="filled"&&n!="stroked"){let s=e[n];if(s){if(!e.filled&&n.indexOf("background")===0)continue;if(!e.stroked&&n.indexOf("border-width")===0)continue;i.push(`${n}: ${s}`)}}return R.setAttr(t,{style:i.join(";")})}static rectStyle(t,e,i){return t.style.left=e[0]+"px",t.style.top=e[1]+"px",t.style.width=i[0]+"px",t.style.height=i[1]+"px",t}static textStyle(t,e){return t.style.left=e[0]+"px",t.style.top=e[1]+"px",t}static point(t,e,i=5,n="square"){return n==="circle"?I.circle(t,e,i):I.square(t,e,i)}point(t,e=5,i="square"){return this.nextID(),i=="circle"&&this.styleTo("border-radius","100%"),I.point(this._ctx,t,e,i),this}static circle(t,e,i=10){let n=R.htmlElement(t.group,"div",I.getID(t));return R.setAttr(n,{class:`pts-form pts-circle ${t.currentClass}`}),I.rectStyle(t,new h(e).$subtract(i),new h(i*2,i*2)),I.style(n,t.style),n}circle(t){return this.nextID(),this.styleTo("border-radius","100%"),I.circle(this._ctx,t[0],t[1][0]),this}static square(t,e,i){let n=R.htmlElement(t.group,"div",I.getID(t));return R.setAttr(n,{class:`pts-form pts-square ${t.currentClass}`}),I.rectStyle(t,new h(e).$subtract(i),new h(i*2,i*2)),I.style(n,t.style),n}square(t,e){return this.nextID(),I.square(this._ctx,t,e),this}static rect(t,e){let i=m.iterToArray(e);if(!m.arrayCheck(i))return;let n=R.htmlElement(t.group,"div",I.getID(t));return R.setAttr(n,{class:`pts-form pts-rect ${t.currentClass}`}),I.rectStyle(t,i[0],i[1]),I.style(n,t.style),n}rect(t){return this.nextID(),this.styleTo("border-radius","0"),I.rect(this._ctx,t),this}static text(t,e,i){let n=R.htmlElement(t.group,"div",I.getID(t));return R.setAttr(n,{class:`pts-form pts-text ${t.currentClass}`}),n.textContent=i,I.textStyle(t,e),I.style(n,t.style),n}text(t,e){return this.nextID(),I.text(this._ctx,t,e),this}log(t){return this.fill("#000").stroke("#fff",.5).text([10,14],t),this}arc(t,e,i,n,s){return m.warn("arc is not implemented in HTMLForm"),this}line(t){return m.warn("line is not implemented in HTMLForm"),this}polygon(t){return m.warn("polygon is not implemented in HTMLForm"),this}};I.groupID=0,I.domID=0;var rt=I;var St={};T(St,{SVGForm:()=>it,SVGSpace:()=>F});var F=class l extends z{constructor(t,e){super(t,e);this._bgcolor="#999";if(this._canvas.nodeName.toLowerCase()!="svg"){let i=l.svgElement(this._canvas,"svg",`${this.id}_svg`);this._container=this._canvas,this._canvas=i}}getForm(){return new it(this)}get element(){return this._canvas}resize(t,e){return super.resize(t,e),l.setAttr(this.element,{viewBox:`0 0 ${this.bound.width} ${this.bound.height}`,width:`${this.bound.width}`,height:`${this.bound.height}`,xmlns:"http://www.w3.org/2000/svg",version:"1.1"}),this}static svgElement(t,e,i){if(!t||!t.appendChild)throw new Error("parent is not a valid DOM element");let n=document.querySelector(`#${i}`);return n||(n=document.createElementNS("http://www.w3.org/2000/svg",e),n.setAttribute("id",i),t.appendChild(n)),n}remove(t){return this._container.querySelectorAll("."+it.scopeID(t)).forEach(i=>{i.parentNode.removeChild(i)}),super.remove(t)}removeAll(){return this._container.innerHTML="",super.removeAll()}},x=class x extends q{constructor(t){super();this._style={filled:!0,stroked:!0,fill:"#f03",stroke:"#fff","stroke-width":1,"stroke-linejoin":"bevel","stroke-linecap":"sqaure",opacity:1};this._ctx={group:null,groupID:"pts",groupCount:0,currentID:"pts0",currentClass:"",style:{}};this._ready=!1;this._space=t,this._space.add({start:()=>{this._ctx.group=this._space.element,this._ctx.groupID="pts_svg_"+x.groupID++,this._ctx.style=Object.assign({},this._style),this._ready=!0}})}get space(){return this._space}styleTo(t,e){if(this._ctx.style[t]===void 0)throw new Error(`${t} style property doesn't exist`);this._ctx.style[t]=e}alpha(t){return this.styleTo("opacity",t),this}fill(t){return typeof t=="boolean"?this.styleTo("filled",t):(this.styleTo("filled",!0),this.styleTo("fill",t)),this}stroke(t,e,i,n){return typeof t=="boolean"?this.styleTo("stroked",t):(this.styleTo("stroked",!0),this.styleTo("stroke",t),e&&this.styleTo("stroke-width",e),i&&this.styleTo("stroke-linejoin",i),n&&this.styleTo("stroke-linecap",n)),this}cls(t){return typeof t=="boolean"?this._ctx.currentClass="":this._ctx.currentClass=t,this}font(t,e,i,n,s){return typeof t=="number"?(this._font.size=t,s&&(this._font.face=s),e&&(this._font.weight=e),i&&(this._font.style=i),n&&(this._font.lineHeight=n)):this._font=t,this._ctx.style.font=this._font.value,this}reset(){return this._ctx.style=Object.assign({},this._style),this._font=new O(10,"sans-serif"),this._ctx.style.font=this._font.value,this}updateScope(t,e){return this._ctx.group=e,this._ctx.groupID=t,this._ctx.groupCount=0,this.nextID(),this._ctx}scope(t){if(!t||t.animateID==null)throw new Error("item not defined or not yet added to Space");return this.updateScope(x.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-${x.domID++}`}static scopeID(t){return`item-${t.animateID}`}static style(t,e){let i=[];e.filled||i.push("fill: none"),e.stroked||i.push("stroke: none");for(let n in e)if(e.hasOwnProperty(n)&&n!="filled"&&n!="stroked"){let s=e[n];if(s){if(!e.filled&&n.indexOf("fill")===0)continue;if(!e.stroked&&n.indexOf("stroke")===0)continue;i.push(`${n}: ${s}`)}}return z.setAttr(t,{style:i.join(";")})}static point(t,e,i=5,n="square"){return n==="circle"?x.circle(t,e,i):x.square(t,e,i)}point(t,e=5,i="square"){return this.nextID(),x.point(this._ctx,t,e,i),this}static circle(t,e,i=10){let n=F.svgElement(t.group,"circle",x.getID(t));return z.setAttr(n,{cx:e[0],cy:e[1],r:i,class:`pts-svgform pts-circle ${t.currentClass}`}),x.style(n,t.style),n}circle(t){this.nextID();let e=m.iterToArray(t);return x.circle(this._ctx,e[0],e[1][0]),this}static arc(t,e,i,n,s,o){let a=F.svgElement(t.group,"path",x.getID(t)),u=new h(e).toAngle(n,i,!0),c=new h(e).toAngle(s,i,!0),p=y.boundAngle(s)-y.boundAngle(n)>w.pi;o&&(p=!p);let b=o?"0":"1",P=`M ${u[0]} ${u[1]} A ${i} ${i} 0 ${p?"1":"0"} ${b} ${c[0]} ${c[1]}`;return z.setAttr(a,{d:P,class:`pts-svgform pts-arc ${t.currentClass}`}),x.style(a,t.style),a}arc(t,e,i,n,s){return this.nextID(),x.arc(this._ctx,t,e,i,n,s),this}static square(t,e,i){let n=F.svgElement(t.group,"rect",x.getID(t));return z.setAttr(n,{x:e[0]-i,y:e[1]-i,width:i*2,height:i*2,class:`pts-svgform pts-square ${t.currentClass}`}),x.style(n,t.style),n}square(t,e){return this.nextID(),x.square(this._ctx,t,e),this}static line(t,e){let i=x.pointsString(e);if(i.count<2)return;if(i.count>2)return x._poly(t,i.string,!1);let n=F.svgElement(t.group,"line",x.getID(t)),s=m.iterToArray(e);return z.setAttr(n,{x1:s[0][0],y1:s[0][1],x2:s[1][0],y2:s[1][1],class:`pts-svgform pts-line ${t.currentClass}`}),x.style(n,t.style),n}line(t){return this.nextID(),x.line(this._ctx,t),this}static _poly(t,e,i=!0){let n=F.svgElement(t.group,i?"polygon":"polyline",x.getID(t));return z.setAttr(n,{points:e,class:`pts-svgform pts-polygon ${t.currentClass}`}),x.style(n,t.style),n}static pointsString(t){let e="",i=0;for(let n of t)e+=`${n[0]},${n[1]} `,i++;return{string:e,count:i}}static polygon(t,e){let i=x.pointsString(e);return x._poly(t,i.string,!0)}polygon(t){return this.nextID(),x.polygon(this._ctx,t),this}static rect(t,e){if(!m.arrayCheck(e))return;let i=F.svgElement(t.group,"rect",x.getID(t)),n=d.fromArray(e).boundingBox(),s=M.size(n);return z.setAttr(i,{x:n[0][0],y:n[0][1],width:s[0],height:s[1],class:`pts-svgform pts-rect ${t.currentClass}`}),x.style(i,t.style),i}rect(t){return this.nextID(),x.rect(this._ctx,t),this}static text(t,e,i){let n=F.svgElement(t.group,"text",x.getID(t));return z.setAttr(n,{"pointer-events":"none",x:e[0],y:e[1],dx:0,dy:0,class:`pts-svgform pts-text ${t.currentClass}`}),n.textContent=i,x.style(n,t.style),n}text(t,e){return this.nextID(),x.text(this._ctx,t,e),this}log(t){return this.fill("#000").stroke("#fff",.5).text([10,14],t),this}};x.groupID=0,x.domID=0;var it=x;var zt={};T(zt,{Body:()=>ft,Particle:()=>pt,World:()=>dt});var dt=class l{constructor(r,t=1,e=0){this._lastTime=null;this._gravity=new h;this._friction=1;this._damping=.75;this._iterations=1;this._particles=[];this._bodies=[];this._pnames=[];this._bnames=[];return this._bound=G.fromGroup(r),this._friction=t,this._gravity=typeof e=="number"?new h(0,e):new h(e),this}get bound(){return this._bound}set bound(r){this._bound=r}get gravity(){return this._gravity}set gravity(r){this._gravity=r}get friction(){return this._friction}set friction(r){this._friction=r}get damping(){return this._damping}set damping(r){this._damping=r}get iterations(){return this._iterations}set iterations(r){this._iterations=r}get bodyCount(){return this._bodies.length}get particleCount(){return this._particles.length}body(r){return typeof r=="string"&&r.length>0?this._bodies[this._bnames.indexOf(r)]:typeof r=="number"&&r>=0?this._bodies[r]:void 0}particle(r){return typeof r=="string"&&r.length>0?this._particles[this._pnames.indexOf(r)]:typeof r=="number"&&r>=0?this._particles[r]:void 0}bodyIndex(r){return this._bnames.indexOf(r)}particleIndex(r){return this._pnames.indexOf(r)}update(r){let t=r/1e3;this._updateParticles(t),this._updateBodies(t)}drawParticles(r){this._drawParticles=r}drawBodies(r){this._drawBodies=r}add(r,t=""){return r instanceof ft?(this._bodies.push(r),this._bnames.push(t)):(this._particles.push(r),this._pnames.push(t)),this}_index(r,t){let e=0;if(typeof t=="string"){if(e=r(t),e<0)throw new Error(`Cannot find index of ${t}. You can use particleIndex() or bodyIndex() function to check existence by name.`)}else e=t;return e}removeBody(r,t=1){let e=this._index(this.bodyIndex.bind(this),r),i=e<0?[e*-1-1,t]:[e,t];return this._bodies.splice(i[0],i[1]),this._bnames.splice(i[0],i[1]),this}removeParticle(r,t=1){let e=this._index(this.particleIndex.bind(this),r),i=e<0?[e*-1-1,t]:[e,t];return this._particles.splice(i[0],i[1]),this._pnames.splice(i[0],i[1]),this}static edgeConstraint(r,t,e,i=1,n=!1){let s=1/(r.mass||1),o=1/(t.mass||1),a=s+o,u=t.$subtract(r),c=e*e,f=n?e/u.magnitude()-1:c/(u.dot(u)+c)-.5,p=u.$multiply(f*i);return r.subtract(p.$multiply(s/a)),t.add(p.$multiply(o/a)),r}static boundConstraint(r,t,e=.75){let i=y.boundingBox(t),n=r.$min(i[1].subtract(r.radius)).$max(i[0].add(r.radius));if(n[0]===i[0][0]||n[0]===i[1][0]){let s=r.changed.$multiply(e);r.previous=n.$subtract(new h(-s[0],s[1]))}else if(n[1]===i[0][1]||n[1]===i[1][1]){let s=r.changed.$multiply(e);r.previous=n.$subtract(new h(s[0],-s[1]))}r.to(n)}integrate(r,t,e){return r.addForce(this._gravity),r.verlet(t,this._friction,e),r}_updateParticles(r){for(let t=0,e=this._particles.length;t<e;t++){let i=this._particles[t];this.integrate(i,r,this._lastTime),l.boundConstraint(i,this._bound,this._damping);for(let n=t+1;n<e;n++)if(t!==n){let s=this._particles[n];i.collide(s,this._damping)}this._drawParticles&&this._drawParticles(i,t)}this._lastTime=r}_updateBodies(r){for(let t=0,e=this._bodies.length;t<e;t++){let i=this._bodies[t];if(i){for(let n=0,s=i.length;n<s;n++){let o=i[n];l.boundConstraint(o,this._bound,this._damping),this.integrate(o,r,this._lastTime)}for(let n=t+1;n<e;n++)i.processBody(this._bodies[n]);for(let n=0,s=this._particles.length;n<s;n++)i.processParticle(this._particles[n]);for(let n=0;n<this._iterations;n++)i.processEdges();this._drawBodies&&this._drawBodies(i,t)}}}},pt=class extends h{constructor(...t){super(...t);this._mass=1;this._radius=0;this._force=new h;this._prev=new h;this._lock=!1;this._prev=this.clone()}get mass(){return this._mass}set mass(t){this._mass=t}get radius(){return this._radius}set radius(t){this._radius=t}get previous(){return this._prev}set previous(t){this._prev=t}get force(){return this._force}set force(t){this._force=t}get body(){return this._body}set body(t){this._body=t}get lock(){return this._lock}set lock(t){this._lock=t,this._lockPt=new h(this)}get changed(){return this.$subtract(this._prev)}set position(t){this.previous.to(this),this._lock&&(this._lockPt=t),this.to(t)}size(t){return this._mass=t,this._radius=t,this}addForce(...t){return this._force.add(...t),this._force}verlet(t,e,i){if(this._lock)this.to(this._lockPt);else{let n=i||t,s=this._force.multiply(t*(t+n)/2),o=this.changed.multiply(e*t/n).add(s);this._prev=this.clone(),this.add(o),this._force=new h}return this}hit(...t){return this._prev.subtract(new h(...t).$divide(Math.sqrt(this._mass))),this}collide(t,e=1){let i=this,n=i.$subtract(t),s=n.magnitudeSq(),o=i.radius+t.radius;if(s<o*o){let a=i.changed,u=t.changed,c=Math.sqrt(s),f=n.$multiply((c-o)/c/2),p=i.$subtract(f),b=t.$add(f);i.to(p),t.to(b);let P=e*n.dot(a)/s,_=e*n.dot(u)/s,D=i.mass/(i.mass+t.mass),A=t.mass/(i.mass+t.mass);a.add(new h(_*n[0]-P*n[0],_*n[1]-P*n[1]).$multiply(A)),u.add(new h(P*n[0]-_*n[0],P*n[1]-_*n[1]).$multiply(D)),i.previous=i.$subtract(a),t.previous=t.$subtract(u)}}toString(){return`Particle: ${this[0]} ${this[1]} | previous ${this._prev[0]} ${this._prev[1]} | mass ${this._mass}`}},ft=class l extends d{constructor(){super();this._cs=[];this._stiff=1;this._locks={};this._mass=1}static fromGroup(t,e=1,i=!0,n=!0){let s=new l().init(t);return i&&s.linkAll(e),n&&s.autoMass(),s}init(t,e=1){let i=new h;for(let n of t){let s=new pt(n);s.body=this,i.add(n),this.push(s)}return this._stiff=e,this}get mass(){return this._mass}set mass(t){this._mass=t;for(let e=0,i=this.length;e<i;e++)this[e].mass=this._mass}autoMass(){return this.mass=Math.sqrt(S.area(this))/10,this}link(t,e,i){if(t<0||t>=this.length)throw new Error("index1 is not in the Group's indices");if(e<0||e>=this.length)throw new Error("index1 is not in the Group's indices");let n=this[t].$subtract(this[e]).magnitude();return this._cs.push([t,e,n,i||this._stiff]),this}linkAll(t){let e=this.length/2;for(let i=0,n=this.length;i<n;i++){let s=i>=n-1?0:i+1;if(this.link(i,s,t),n>4){let o=Math.floor(e/2)+1,a=i>=n-o?i%n:i+o;this.link(i,a,t)}i<=e-1&&this.link(i,Math.min(this.length-1,i+Math.floor(e)))}}linksToLines(){let t=[];for(let e=0,i=this._cs.length;e<i;e++){let n=this._cs[e];t.push(new d(this[n[0]],this[n[1]]))}return t}processEdges(){for(let t=0,e=this._cs.length;t<e;t++){let[i,n,s,o]=this._cs[t];dt.edgeConstraint(this[i],this[n],s,o)}}processBody(t){let e=this,i=t,n=S.hasIntersectPolygon(e,i);if(n){let s=n.normal.$multiply(n.dist),o,a=n.edge;Math.abs(a[0][0]-a[1][0])>Math.abs(a[0][1]-a[1][1])?o=(n.vertex[0]-s[0]-a[0][0])/(a[1][0]-a[0][0]):o=(n.vertex[1]-s[1]-a[0][1])/(a[1][1]-a[0][1]);let u=1/(o*o+(1-o)*(1-o)),c=n.vertex.body.mass||1,f=n.edge[0].body.mass||1,p=c/(c+f),b=f/(c+f);a[0].subtract(s.$multiply(p*(1-o)*u/2)),a[1].subtract(s.$multiply(p*o*u/2)),n.vertex.add(s.$multiply(b))}}processParticle(t){let e=this,i=t,n=S.hasIntersectCircle(e,B.fromCenter(t,t.radius));if(n){let s=n.normal.$multiply(n.dist),o,a=n.edge;Math.abs(a[0][0]-a[1][0])>Math.abs(a[0][1]-a[1][1])?o=(n.vertex[0]-s[0]-a[0][0])/(a[1][0]-a[0][0]):o=(n.vertex[1]-s[1]-a[0][1])/(a[1][1]-a[0][1]);let u=1/(o*o+(1-o)*(1-o)),c=n.vertex.mass||i.mass||1,f=n.edge[0].body.mass||1,p=c/(c+f),b=f/(c+f);a[0].subtract(s.$multiply(p*(1-o)*u/2)),a[1].subtract(s.$multiply(p*o*u/2));let P=t.changed.add(s.$multiply(b));t.previous=t.$subtract(P)}}};var Ot={};T(Ot,{Sound:()=>Rt,Tempo:()=>Bt});var Bt=class l{constructor(r){this._listeners={};this._listenerInc=0;this.bpm=r}static fromBeat(r){return new l(6e4/r)}get bpm(){return this._bpm}set bpm(r){this._bpm=r,this._ms=6e4/this._bpm}get ms(){return this._ms}set ms(r){this._bpm=Math.floor(6e4/r),this._ms=6e4/this._bpm}_createID(r){let t="";return typeof r=="function"?t="_b"+this._listenerInc++:t=r.name||"_b"+this._listenerInc++,t}every(r){let t=this,e=Array.isArray(r)?r[0]:r;return{start:function(i,n=0,s){let o=s||t._createID(i);return t._listeners[o]={name:o,beats:r,period:e,index:0,offset:n,duration:-1,continuous:!1,fn:i},this},progress:function(i,n=0,s){let o=s||t._createID(i);return t._listeners[o]={name:o,beats:r,period:e,index:0,offset:n,duration:-1,continuous:!0,fn:i},this}}}track(r){for(let t in this._listeners)if(this._listeners.hasOwnProperty(t)){let e=this._listeners[t],i=e.offset?r+e.offset:r,n=e.period*this._ms,s=!1;i>e.duration+n&&(e.duration=i-i%this._ms,Array.isArray(e.beats)&&(e.index=(e.index+1)%e.beats.length,e.period=e.beats[e.index]),s=!0);let o=Math.max(0,Math.ceil(Math.floor(e.duration/this._ms)/e.period)),a=e.continuous?[o,L.clamp((i-e.duration)/n,0,1),i,s]:[o];(e.continuous||s)&&e.fn.apply(e,a)&&delete this._listeners[e.name]}}stop(r){this._listeners[r]&&delete this._listeners[r]}animate(r,t){this.track(r)}resize(r,t){}action(r,t,e,i){}},Rt=class l{constructor(r){this._playing=!1;this._type=r,this._createAudioContext()}_createAudioContext(){let r=window.AudioContext;if(!r)throw new Error("Your browser doesn't support Web Audio. (No AudioContext)");this._ctx=r?new r:void 0}static from(r,t,e="gen",i){let n=new l(e);return n._node=r,n._ctx=t,i&&(n._stream=i),n}static load(r,t="anonymous"){return new Promise((e,i)=>{let n=new l("file");n._source=typeof r=="string"?new Audio(r):r,n._source.autoplay=!1,n._source.crossOrigin=t,n._source.addEventListener("ended",function(){n._playing=!1}),n._source.addEventListener("error",function(){i("Error loading sound")}),n._source.addEventListener("canplaythrough",function(){n._node||(n._node=n._ctx.createMediaElementSource(n._source)),e(n)})})}static loadAsBuffer(r){return new Promise((t,e)=>{let i=new XMLHttpRequest;i.open("GET",r,!0),i.responseType="arraybuffer";let n=new l("file");i.onload=function(){n._ctx.decodeAudioData(i.response,function(s){n.createBuffer(s),t(n)},s=>e("Error decoding audio"))},i.send()})}createBuffer(r){return this._node=this._ctx.createBufferSource(),r!==void 0&&(this._buffer=r),this._node.buffer=this._buffer,this._node.onended=()=>{this._playing=!1},this}static generate(r,t){return new l("gen")._gen(r,t)}_gen(r,t){this._node=this._ctx.createOscillator();let e=this._node;return e.type=r,r==="custom"?e.setPeriodicWave(t):e.frequency.value=t,this}static input(r){return et(this,null,function*(){try{let t=new l("input");if(!t)return;let e=r||{audio:!0,video:!1};return t._stream=yield navigator.mediaDevices.getUserMedia(e),t._node=t._ctx.createMediaStreamSource(t._stream),t}catch(t){return console.error("Cannot get audio from input device."),Promise.resolve(null)}})}get ctx(){return this._ctx}get node(){return this._node}get outputNode(){return this._outputNode}get stream(){return this._stream}get source(){return this._source}get buffer(){return this._buffer}set buffer(r){this._buffer=r}get type(){return this._type}get playing(){return this._playing}get progress(){let r=0,t=0;return this._buffer?(r=this._buffer.duration,t=this._timestamp?this._ctx.currentTime-this._timestamp:0):(r=this._source.duration,t=this._source.currentTime),t/r}get playable(){return this._type==="input"?this._node!==void 0:!!this._buffer||this._source.readyState===4}get binSize(){return this.analyzer.size}get sampleRate(){return this._ctx.sampleRate}get frequency(){return this._type==="gen"?this._node.frequency.value:0}set frequency(r){this._type==="gen"&&(this._node.frequency.value=r)}connect(r){return this._node.connect(r),this}setOutputNode(r){return this._outputNode=r,this}removeOutputNode(){return this._outputNode=null,this}analyze(r=256,t=-100,e=-30,i=.8){let n=this._ctx.createAnalyser();return n.fftSize=r*2,n.minDecibels=t,n.maxDecibels=e,n.smoothingTimeConstant=i,this.analyzer={node:n,size:n.frequencyBinCount,data:new Uint8Array(n.frequencyBinCount)},this._node.connect(this.analyzer.node),this}_domain(r){return this.analyzer?(r?this.analyzer.node.getByteTimeDomainData(this.analyzer.data):this.analyzer.node.getByteFrequencyData(this.analyzer.data),this.analyzer.data):new Uint8Array(0)}_domainTo(r,t,e=[0,0],i=[0,0]){let n=r?this.timeDomain():this.freqDomain(),s=new d;for(let o=i[0],a=n.length-i[1];o<a;o++)s.push(new h(e[0]+t[0]*o/a,e[1]+t[1]*n[o]/255));return s}timeDomain(){return this._domain(!0)}timeDomainTo(r,t=[0,0],e=[0,0]){return this._domainTo(!0,r,t,e)}freqDomain(){return this._domain(!1)}freqDomainTo(r,t=[0,0],e=[0,0]){return this._domainTo(!1,r,t,e)}reset(){return this.stop(),this._node.disconnect(),this}start(r=0){return this._ctx?this._ctx.state==="suspended"&&this._ctx.resume():this._createAudioContext(),this._type==="file"?this._buffer?(this._node.start(r),this._timestamp=this._ctx.currentTime+r):(this._source.play(),r>0&&(this._source.currentTime=r)):this._type==="gen"&&(this._gen(this._node.type,this._node.frequency.value),this._node.start(),this.analyzer&&this._node.connect(this.analyzer.node)),(this._outputNode||this._node).connect(this._ctx.destination),this._playing=!0,this}stop(){return this._playing&&(this._outputNode||this._node).disconnect(this._ctx.destination),this._type==="file"?this._buffer?this.progress<1&&this._node.stop():this._source.pause():this._type==="gen"?this._node.stop():this._type==="input"&&this._stream.getAudioTracks().forEach(r=>r.stop()),this._playing=!1,this}toggle(){return this._playing?this.stop():this.start(),this}};globalThis.Pts=$($($($($($($($($($($($($($($($($({},Dt),$t),It),gt),Pt),_t),xt),Lt),Gt),wt),Et),St),Ct),zt),vt),Ot),Mt);globalThis.Pts.namespace=l=>{let r=globalThis.Pts;for(let t in r)t!="namespace"&&(l[t]=r[t])};globalThis.Pts.quickStart=(l,r="#9ab")=>{if(!window)return;let t=globalThis;return globalThis.Pts.namespace(t),t.space=new tt(l).setup({bgcolor:r,resize:!0,retina:!0}),t.form=t.space.getForm(),function(e=null,i=null,n=null,s=null){t.space.add({start:i,animate:e,resize:s,action:n}),t.space.bindMouse().bindTouch().play()}};})();
7
7
  /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
8
8
  //# sourceMappingURL=pts.min.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pts",
3
- "version": "0.12.3",
3
+ "version": "0.12.5",
4
4
  "description": "pts",
5
5
  "main": "./dist/index",
6
6
  "types": "./dist/index.d.ts",