pts 0.11.6 → 0.12.1

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.js CHANGED
@@ -88,7 +88,7 @@ __export(module_exports, {
88
88
  module.exports = __toCommonJS(module_exports);
89
89
 
90
90
  // src/LinearAlgebra.ts
91
- var Vec = class {
91
+ var Vec = class _Vec {
92
92
  /**
93
93
  * Add `b` to vector `a`.
94
94
  * @returns vector `a`
@@ -181,44 +181,44 @@ var Vec = class {
181
181
  * Magnitude of `a`.
182
182
  */
183
183
  static magnitude(a) {
184
- return Math.sqrt(Vec.dot(a, a));
184
+ return Math.sqrt(_Vec.dot(a, a));
185
185
  }
186
186
  /**
187
187
  * Unit vector of `a`. If magnitude of `a` is already known, pass it in the second paramter to optimize calculation.
188
188
  */
189
189
  static unit(a, magnitude = void 0) {
190
- let m = magnitude === void 0 ? Vec.magnitude(a) : magnitude;
190
+ const m = magnitude === void 0 ? _Vec.magnitude(a) : magnitude;
191
191
  if (m === 0)
192
192
  return Pt.make(a.length);
193
- return Vec.divide(a, m);
193
+ return _Vec.divide(a, m);
194
194
  }
195
195
  /**
196
196
  * Set `a` to its absolute value in each dimension.
197
197
  * @returns vector `a`
198
198
  */
199
199
  static abs(a) {
200
- return Vec.map(a, Math.abs);
200
+ return _Vec.map(a, Math.abs);
201
201
  }
202
202
  /**
203
203
  * Set `a` to its floor value in each dimension.
204
204
  * @returns vector `a`
205
205
  */
206
206
  static floor(a) {
207
- return Vec.map(a, Math.floor);
207
+ return _Vec.map(a, Math.floor);
208
208
  }
209
209
  /**
210
210
  * Set `a` to its ceiling value in each dimension.
211
211
  * @returns vector `a`
212
212
  */
213
213
  static ceil(a) {
214
- return Vec.map(a, Math.ceil);
214
+ return _Vec.map(a, Math.ceil);
215
215
  }
216
216
  /**
217
217
  * Set `a` to its rounded value in each dimension.
218
218
  * @returns vector `a`
219
219
  */
220
220
  static round(a) {
221
- return Vec.map(a, Math.round);
221
+ return _Vec.map(a, Math.round);
222
222
  }
223
223
  /**
224
224
  * Find the max value within a vector's dimensions.
@@ -268,7 +268,7 @@ var Vec = class {
268
268
  return a;
269
269
  }
270
270
  };
271
- var Mat = class {
271
+ var Mat = class _Mat {
272
272
  constructor() {
273
273
  this.reset();
274
274
  }
@@ -282,13 +282,13 @@ var Mat = class {
282
282
  * Convert the value of its stored 3x3 matrix to a 2D [`DOMMatrix`](https://developer.mozilla.org/en-US/docs/Web/API/DOMMatrix) instance
283
283
  */
284
284
  get domMatrix() {
285
- return new DOMMatrix(Mat.toDOMMatrix(this._33));
285
+ return new DOMMatrix(_Mat.toDOMMatrix(this._33));
286
286
  }
287
287
  /**
288
288
  * Reset the internal 3x3 matrix to its identity
289
289
  */
290
290
  reset() {
291
- this._33 = Mat.scale2DMatrix(1, 1);
291
+ this._33 = _Mat.scale2DMatrix(1, 1);
292
292
  }
293
293
  /**
294
294
  * Scale the internal 3x3 matrix. You can chain this function with other related functions.
@@ -296,8 +296,8 @@ var Mat = class {
296
296
  * @param at Optional origin location to scale from.
297
297
  */
298
298
  scale2D(val, at = [0, 0]) {
299
- const m = Mat.scaleAt2DMatrix(val[0] || 1, val[1] || 1, at);
300
- this._33 = Mat.multiply(this._33, m);
299
+ const m = _Mat.scaleAt2DMatrix(val[0] || 1, val[1] || 1, at);
300
+ this._33 = _Mat.multiply(this._33, m);
301
301
  return this;
302
302
  }
303
303
  /**
@@ -306,8 +306,8 @@ var Mat = class {
306
306
  * @param at Optional origin location to rotate from.
307
307
  */
308
308
  rotate2D(ang, at = [0, 0]) {
309
- const m = Mat.rotateAt2DMatrix(Math.cos(ang), Math.sin(ang), at);
310
- this._33 = Mat.multiply(this._33, m);
309
+ const m = _Mat.rotateAt2DMatrix(Math.cos(ang), Math.sin(ang), at);
310
+ this._33 = _Mat.multiply(this._33, m);
311
311
  return this;
312
312
  }
313
313
  /**
@@ -315,8 +315,8 @@ var Mat = class {
315
315
  * @param val [x, y] offset values
316
316
  */
317
317
  translate2D(val) {
318
- const m = Mat.translate2DMatrix(val[0] || 0, val[1] || 0);
319
- this._33 = Mat.multiply(this._33, m);
318
+ const m = _Mat.translate2DMatrix(val[0] || 0, val[1] || 0);
319
+ this._33 = _Mat.multiply(this._33, m);
320
320
  return this;
321
321
  }
322
322
  /**
@@ -325,8 +325,8 @@ var Mat = class {
325
325
  * @param at Optional origin location to scale from.
326
326
  */
327
327
  shear2D(val, at = [0, 0]) {
328
- const m = Mat.shearAt2DMatrix(Math.tan(val[0] || 0), Math.tan(val[1] || 1), at);
329
- this._33 = Mat.multiply(this._33, m);
328
+ const m = _Mat.shearAt2DMatrix(Math.tan(val[0] || 0), Math.tan(val[1] || 1), at);
329
+ this._33 = _Mat.multiply(this._33, m);
330
330
  return this;
331
331
  }
332
332
  /**
@@ -342,8 +342,8 @@ var Mat = class {
342
342
  if (a.length != b.length)
343
343
  throw new Error("Cannot add matrix if rows' and columns' size don't match.");
344
344
  }
345
- let g = new Group();
346
- let isNum = typeof b == "number";
345
+ const g = new Group();
346
+ const isNum = typeof b == "number";
347
347
  for (let i = 0, len = a.length; i < len; i++) {
348
348
  g.push(a[i].$add(isNum ? b : b[i]));
349
349
  }
@@ -358,7 +358,7 @@ var Mat = class {
358
358
  * @returns If not elementwise, this will return a new group with M Pt, each with N dimensions (M-rows, N-columns).
359
359
  */
360
360
  static multiply(a, b, transposed = false, elementwise = false) {
361
- let g = new Group();
361
+ const g = new Group();
362
362
  if (typeof b != "number") {
363
363
  if (elementwise) {
364
364
  if (a.length != b.length)
@@ -372,9 +372,9 @@ var Mat = class {
372
372
  if (transposed && a[0].length != b[0].length)
373
373
  throw new Error("Cannot multiply matrix if transposed and the columns in both matrices don't match.");
374
374
  if (!transposed)
375
- b = Mat.transpose(b);
375
+ b = _Mat.transpose(b);
376
376
  for (let ai = 0, alen = a.length; ai < alen; ai++) {
377
- let p = Pt.make(b.length, 0);
377
+ const p = Pt.make(b.length, 0);
378
378
  for (let bi = 0, blen = b.length; bi < blen; bi++) {
379
379
  p[bi] = Vec.dot(a[ai], b[bi]);
380
380
  }
@@ -395,7 +395,7 @@ var Mat = class {
395
395
  * @param defaultValue a default value to fill if index out of bound. If not provided, it will throw an error instead.
396
396
  */
397
397
  static zipSlice(g, index, defaultValue = false) {
398
- let z = [];
398
+ const z = [];
399
399
  for (let i = 0, len = g.length; i < len; i++) {
400
400
  if (g[i].length - 1 < index && defaultValue === false)
401
401
  throw `Index ${index} is out of bounds`;
@@ -410,10 +410,10 @@ var Mat = class {
410
410
  * @param useLongest If true, find the longest list of values in a Pt and use its length for zipping. Default is false, which uses the first item's length for zipping.
411
411
  */
412
412
  static zip(g, defaultValue = false, useLongest = false) {
413
- let ps = new Group();
414
- let len = useLongest ? g.reduce((a, b) => Math.max(a, b.length), 0) : g[0].length;
413
+ const ps = new Group();
414
+ const len = useLongest ? g.reduce((a, b) => Math.max(a, b.length), 0) : g[0].length;
415
415
  for (let i = 0; i < len; i++) {
416
- ps.push(Mat.zipSlice(g, i, defaultValue));
416
+ ps.push(_Mat.zipSlice(g, i, defaultValue));
417
417
  }
418
418
  return ps;
419
419
  }
@@ -421,7 +421,7 @@ var Mat = class {
421
421
  * Same as `zip` function.
422
422
  */
423
423
  static transpose(g, defaultValue = false, useLongest = false) {
424
- return Mat.zip(g, defaultValue, useLongest);
424
+ return _Mat.zip(g, defaultValue, useLongest);
425
425
  }
426
426
  static toDOMMatrix(m) {
427
427
  return [m[0][0], m[0][1], m[1][0], m[1][1], m[2][0], m[2][1]];
@@ -433,8 +433,8 @@ var Mat = class {
433
433
  * @returns a new transformed Pt
434
434
  */
435
435
  static transform2D(pt, m) {
436
- let x = pt[0] * m[0][0] + pt[1] * m[1][0] + m[2][0];
437
- let y = pt[0] * m[0][1] + pt[1] * m[1][1] + m[2][1];
436
+ const x = pt[0] * m[0][0] + pt[1] * m[1][0] + m[2][0];
437
+ const y = pt[0] * m[0][1] + pt[1] * m[1][1] + m[2][1];
438
438
  return new Pt(x, y);
439
439
  }
440
440
  /**
@@ -481,7 +481,7 @@ var Mat = class {
481
481
  * Get a matrix to scale a point from an origin point. For use in `transform2D`.
482
482
  */
483
483
  static scaleAt2DMatrix(sx, sy, at) {
484
- let m = Mat.scale2DMatrix(sx, sy);
484
+ const m = _Mat.scale2DMatrix(sx, sy);
485
485
  m[2][0] = -at[0] * sx + at[0];
486
486
  m[2][1] = -at[1] * sy + at[1];
487
487
  return m;
@@ -490,7 +490,7 @@ var Mat = class {
490
490
  * Get a matrix to rotate a point from an origin point. For use in `transform2D`.
491
491
  */
492
492
  static rotateAt2DMatrix(cosA, sinA, at) {
493
- let m = Mat.rotate2DMatrix(cosA, sinA);
493
+ const m = _Mat.rotate2DMatrix(cosA, sinA);
494
494
  m[2][0] = at[0] * (1 - cosA) + at[1] * sinA;
495
495
  m[2][1] = at[1] * (1 - cosA) - at[0] * sinA;
496
496
  return m;
@@ -499,7 +499,7 @@ var Mat = class {
499
499
  * Get a matrix to shear a point from an origin point. For use in `transform2D`.
500
500
  */
501
501
  static shearAt2DMatrix(tanX, tanY, at) {
502
- let m = Mat.shear2DMatrix(tanX, tanY);
502
+ const m = _Mat.shear2DMatrix(tanX, tanY);
503
503
  m[2][0] = -at[1] * tanY;
504
504
  m[2][1] = -at[0] * tanX;
505
505
  return m;
@@ -510,7 +510,7 @@ var Mat = class {
510
510
  * @param p1 second end point to define the reflection line
511
511
  */
512
512
  static reflectAt2DMatrix(p1, p2) {
513
- let intercept = Line.intercept(p1, p2);
513
+ const intercept = Line.intercept(p1, p2);
514
514
  if (intercept == void 0) {
515
515
  return [
516
516
  new Pt([-1, 0, 0]),
@@ -518,10 +518,10 @@ var Mat = class {
518
518
  new Pt([p1[0] + p2[0], 0, 1])
519
519
  ];
520
520
  } else {
521
- let yi = intercept.yi;
522
- let ang2 = Math.atan(intercept.slope) * 2;
523
- let cosA = Math.cos(ang2);
524
- let sinA = Math.sin(ang2);
521
+ const yi = intercept.yi;
522
+ const ang2 = Math.atan(intercept.slope) * 2;
523
+ const cosA = Math.cos(ang2);
524
+ const sinA = Math.sin(ang2);
525
525
  return [
526
526
  new Pt([cosA, sinA, 0]),
527
527
  new Pt([sinA, -cosA, 0]),
@@ -534,7 +534,7 @@ var Mat = class {
534
534
  // src/Op.ts
535
535
  var _errorLength = (obj, param = "expected") => Util.warn("Group's length is less than " + param, obj);
536
536
  var _errorOutofBound = (obj, param = "") => Util.warn(`Index ${param} is out of bound in Group`, obj);
537
- var Line = class {
537
+ var Line = class _Line {
538
538
  /**
539
539
  * Create a line that originates from an anchor point, given an angle and a magnitude.
540
540
  * @param anchor an anchor Pt
@@ -632,7 +632,7 @@ var Line = class {
632
632
  */
633
633
  static distanceFromPt(line, pt) {
634
634
  let _line = Util.iterToArray(line);
635
- let projectionVector = Line.perpendicularFromPt(_line, pt, true);
635
+ let projectionVector = _Line.perpendicularFromPt(_line, pt, true);
636
636
  if (projectionVector) {
637
637
  return projectionVector.magnitude();
638
638
  } else {
@@ -648,8 +648,8 @@ var Line = class {
648
648
  static intersectRay2D(la, lb) {
649
649
  let _la = Util.iterToArray(la);
650
650
  let _lb = Util.iterToArray(lb);
651
- let a = Line.intercept(_la[0], _la[1]);
652
- let b = Line.intercept(_lb[0], _lb[1]);
651
+ let a = _Line.intercept(_la[0], _la[1]);
652
+ let b = _Line.intercept(_lb[0], _lb[1]);
653
653
  let pa = _la[0];
654
654
  let pb = _lb[0];
655
655
  if (a == void 0) {
@@ -683,7 +683,7 @@ var Line = class {
683
683
  static intersectLine2D(la, lb) {
684
684
  let _la = Util.iterToArray(la);
685
685
  let _lb = Util.iterToArray(lb);
686
- let pt = Line.intersectRay2D(_la, _lb);
686
+ let pt = _Line.intersectRay2D(_la, _lb);
687
687
  return pt && Geom.withinBound(pt, _la[0], _la[1]) && Geom.withinBound(pt, _lb[0], _lb[1]) ? pt : void 0;
688
688
  }
689
689
  /**
@@ -695,7 +695,7 @@ var Line = class {
695
695
  static intersectLineWithRay2D(line, ray) {
696
696
  let _line = Util.iterToArray(line);
697
697
  let _ray = Util.iterToArray(ray);
698
- let pt = Line.intersectRay2D(_line, _ray);
698
+ let pt = _Line.intersectRay2D(_line, _ray);
699
699
  return pt && Geom.withinBound(pt, _line[0], _line[1]) ? pt : void 0;
700
700
  }
701
701
  /**
@@ -707,7 +707,7 @@ var Line = class {
707
707
  static intersectPolygon2D(lineOrRay, poly, sourceIsRay = false) {
708
708
  let _lineOrRay = Util.iterToArray(lineOrRay);
709
709
  let _poly = Util.iterToArray(poly);
710
- let fn = sourceIsRay ? Line.intersectLineWithRay2D : Line.intersectLine2D;
710
+ let fn = sourceIsRay ? _Line.intersectLineWithRay2D : _Line.intersectLine2D;
711
711
  let pts = new Group();
712
712
  for (let i = 0, len = _poly.length; i < len; i++) {
713
713
  let next = i === len - 1 ? 0 : i + 1;
@@ -725,7 +725,7 @@ var Line = class {
725
725
  */
726
726
  static intersectLines2D(lines1, lines2, isRay = false) {
727
727
  let group = new Group();
728
- let fn = isRay ? Line.intersectLineWithRay2D : Line.intersectLine2D;
728
+ let fn = isRay ? _Line.intersectLineWithRay2D : _Line.intersectLine2D;
729
729
  for (let l1 of lines1) {
730
730
  for (let l2 of lines2) {
731
731
  let _ip = fn(l1, l2);
@@ -743,7 +743,7 @@ var Line = class {
743
743
  */
744
744
  static intersectGridWithRay2D(ray, gridPt) {
745
745
  let _ray = Util.iterToArray(ray);
746
- let t = Line.intercept(new Pt(_ray[0]).subtract(gridPt), new Pt(_ray[1]).subtract(gridPt));
746
+ let t = _Line.intercept(new Pt(_ray[0]).subtract(gridPt), new Pt(_ray[1]).subtract(gridPt));
747
747
  let g = new Group();
748
748
  if (t && t.xi)
749
749
  g.push(new Pt(gridPt[0] + t.xi, gridPt[1]));
@@ -759,7 +759,7 @@ var Line = class {
759
759
  */
760
760
  static intersectGridWithLine2D(line, gridPt) {
761
761
  let _line = Util.iterToArray(line);
762
- let g = Line.intersectGridWithRay2D(_line, gridPt);
762
+ let g = _Line.intersectGridWithRay2D(_line, gridPt);
763
763
  let gg = new Group();
764
764
  for (let i = 0, len = g.length; i < len; i++) {
765
765
  if (Geom.withinBound(g[i], _line[0], _line[1]))
@@ -779,7 +779,7 @@ var Line = class {
779
779
  let box = Geom.boundingBox(Group.fromPtArray(_line));
780
780
  if (!Rectangle.hasIntersectRect2D(box, _rect))
781
781
  return new Group();
782
- return Line.intersectLines2D([_line], Rectangle.sides(_rect));
782
+ return _Line.intersectLines2D([_line], Rectangle.sides(_rect));
783
783
  }
784
784
  /**
785
785
  * Get evenly distributed points on a line. Similar to [`Create.distributeLinear`](#link) but excluding end points.
@@ -820,7 +820,7 @@ var Line = class {
820
820
  } else {
821
821
  sideIdx = ls[0] < 0 ? 3 : 1;
822
822
  }
823
- return Line.intersectRay2D(sides[sideIdx], _line);
823
+ return _Line.intersectRay2D(sides[sideIdx], _line);
824
824
  }
825
825
  }
826
826
  /**
@@ -856,7 +856,7 @@ var Line = class {
856
856
  return new Group(_line[0].$min(_line[1]), _line[0].$max(_line[1]));
857
857
  }
858
858
  };
859
- var Rectangle = class {
859
+ var Rectangle = class _Rectangle {
860
860
  /**
861
861
  * Create a rectangle from top-left anchor point. Same as [`Rectangle.fromTopLeft`](#link).
862
862
  * @param topLeft top-left point
@@ -865,7 +865,7 @@ var Rectangle = class {
865
865
  * @returns a Group of 2 Pts representing a rectangle
866
866
  */
867
867
  static from(topLeft, widthOrSize, height) {
868
- return Rectangle.fromTopLeft(topLeft, widthOrSize, height);
868
+ return _Rectangle.fromTopLeft(topLeft, widthOrSize, height);
869
869
  }
870
870
  /**
871
871
  * Create a rectangle given a top-left position and a size.
@@ -906,9 +906,9 @@ var Rectangle = class {
906
906
  */
907
907
  static toSquare(pts, enclose = false) {
908
908
  let _pts = Util.iterToArray(pts);
909
- let s = Rectangle.size(_pts);
909
+ let s = _Rectangle.size(_pts);
910
910
  let m = enclose ? s.maxValue().value : s.minValue().value;
911
- return Rectangle.fromCenter(Rectangle.center(_pts), m, m);
911
+ return _Rectangle.fromCenter(_Rectangle.center(_pts), m, m);
912
912
  }
913
913
  /**
914
914
  * Get the size of this rectangle as a Pt.
@@ -944,7 +944,7 @@ var Rectangle = class {
944
944
  * @returns an array of 4 Groups, each of which represents a line segment
945
945
  */
946
946
  static sides(rect) {
947
- let [p0, p1, p2, p3] = Rectangle.corners(rect);
947
+ let [p0, p1, p2, p3] = _Rectangle.corners(rect);
948
948
  return [
949
949
  new Group(p0, p1),
950
950
  new Group(p1, p2),
@@ -978,7 +978,7 @@ var Rectangle = class {
978
978
  * @param rect a Group or an Iterable<Pt> with 2 Pt representing a Rectangle
979
979
  */
980
980
  static polygon(rect) {
981
- return Rectangle.corners(rect);
981
+ return _Rectangle.corners(rect);
982
982
  }
983
983
  /**
984
984
  * Subdivide a rectangle into 4 rectangles, one for each quadrant.
@@ -987,8 +987,8 @@ var Rectangle = class {
987
987
  */
988
988
  static quadrants(rect, center) {
989
989
  let _rect = Util.iterToArray(rect);
990
- let corners = Rectangle.corners(_rect);
991
- let _center = center != void 0 ? new Pt(center) : Rectangle.center(_rect);
990
+ let corners = _Rectangle.corners(_rect);
991
+ let _center = center != void 0 ? new Pt(center) : _Rectangle.center(_rect);
992
992
  return corners.map((c) => new Group(c, _center).boundingBox());
993
993
  }
994
994
  /**
@@ -1041,12 +1041,12 @@ var Rectangle = class {
1041
1041
  static intersectRect2D(rect1, rect2) {
1042
1042
  let _rect1 = Util.iterToArray(rect1);
1043
1043
  let _rect2 = Util.iterToArray(rect2);
1044
- if (!Rectangle.hasIntersectRect2D(_rect1, _rect2))
1044
+ if (!_Rectangle.hasIntersectRect2D(_rect1, _rect2))
1045
1045
  return new Group();
1046
- return Line.intersectLines2D(Rectangle.sides(_rect1), Rectangle.sides(_rect2));
1046
+ return Line.intersectLines2D(_Rectangle.sides(_rect1), _Rectangle.sides(_rect2));
1047
1047
  }
1048
1048
  };
1049
- var Circle = class {
1049
+ var Circle = class _Circle {
1050
1050
  /**
1051
1051
  * Create a circle that either fits within, or encloses, a rectangle.
1052
1052
  * @param pts a Group or an Iterable<PtLike> with 2 Pt representing a rectangle
@@ -1137,7 +1137,7 @@ var Circle = class {
1137
1137
  static intersectLine2D(circle, line) {
1138
1138
  let _pts = Util.iterToArray(circle);
1139
1139
  let _line = Util.iterToArray(line);
1140
- let ps = Circle.intersectRay2D(_pts, _line);
1140
+ let ps = _Circle.intersectRay2D(_pts, _line);
1141
1141
  let g = new Group();
1142
1142
  if (ps.length > 0) {
1143
1143
  for (let i = 0, len = ps.length; i < len; i++) {
@@ -1190,7 +1190,7 @@ var Circle = class {
1190
1190
  let sides = Rectangle.sides(_rect);
1191
1191
  let g = [];
1192
1192
  for (let i = 0, len = sides.length; i < len; i++) {
1193
- let ps = Circle.intersectLine2D(_pts, sides[i]);
1193
+ let ps = _Circle.intersectLine2D(_pts, sides[i]);
1194
1194
  if (ps.length > 0)
1195
1195
  g.push(ps);
1196
1196
  }
@@ -1233,7 +1233,7 @@ var Circle = class {
1233
1233
  }
1234
1234
  }
1235
1235
  };
1236
- var Triangle = class {
1236
+ var Triangle = class _Triangle {
1237
1237
  /**
1238
1238
  * Create a triangle from a rectangle. The triangle will be isosceles, with the bottom of the rectangle as its base.
1239
1239
  * @param rect a Group or an Iterable<Pt> with 2 Pt representing a rectangle
@@ -1259,7 +1259,7 @@ var Triangle = class {
1259
1259
  * @param size size is the magnitude of lines from center to the triangle's vertices, like a "radius".
1260
1260
  */
1261
1261
  static fromCenter(pt, size) {
1262
- return Triangle.fromCircle(Circle.fromCenter(pt, size));
1262
+ return _Triangle.fromCircle(Circle.fromCenter(pt, size));
1263
1263
  }
1264
1264
  /**
1265
1265
  * Get the medial, which is an inner triangle formed by connecting the midpoints of this triangle's sides.
@@ -1298,7 +1298,7 @@ var Triangle = class {
1298
1298
  */
1299
1299
  static altitude(tri, index) {
1300
1300
  let _pts = Util.iterToArray(tri);
1301
- let opp = Triangle.oppositeSide(_pts, index);
1301
+ let opp = _Triangle.oppositeSide(_pts, index);
1302
1302
  if (opp.length > 1) {
1303
1303
  return new Group(_pts[index], Line.perpendicularFromPt(opp, _pts[index]));
1304
1304
  } else {
@@ -1314,8 +1314,8 @@ var Triangle = class {
1314
1314
  let _pts = Util.iterToArray(tri);
1315
1315
  if (_pts.length < 3)
1316
1316
  return _errorLength(void 0, 3);
1317
- let a = Triangle.altitude(_pts, 0);
1318
- let b = Triangle.altitude(_pts, 1);
1317
+ let a = _Triangle.altitude(_pts, 0);
1318
+ let b = _Triangle.altitude(_pts, 1);
1319
1319
  return Line.intersectRay2D(a, b);
1320
1320
  }
1321
1321
  /**
@@ -1338,7 +1338,7 @@ var Triangle = class {
1338
1338
  */
1339
1339
  static incircle(tri, center) {
1340
1340
  let _pts = Util.iterToArray(tri);
1341
- let c = center ? center : Triangle.incenter(_pts);
1341
+ let c = center ? center : _Triangle.incenter(_pts);
1342
1342
  let area = Polygon.area(_pts);
1343
1343
  let perim = Polygon.perimeter(_pts, true);
1344
1344
  let r = 2 * area / perim.total;
@@ -1351,7 +1351,7 @@ var Triangle = class {
1351
1351
  */
1352
1352
  static circumcenter(tri) {
1353
1353
  let _pts = Util.iterToArray(tri);
1354
- let md = Triangle.medial(_pts);
1354
+ let md = _Triangle.medial(_pts);
1355
1355
  let a = [md[0], Geom.perpendicular(_pts[0].$subtract(md[0])).p1.$add(md[0])];
1356
1356
  let b = [md[1], Geom.perpendicular(_pts[1].$subtract(md[1])).p1.$add(md[1])];
1357
1357
  return Line.intersectRay2D(a, b);
@@ -1363,12 +1363,12 @@ var Triangle = class {
1363
1363
  */
1364
1364
  static circumcircle(tri, center) {
1365
1365
  let _pts = Util.iterToArray(tri);
1366
- let c = center ? center : Triangle.circumcenter(_pts);
1366
+ let c = center ? center : _Triangle.circumcenter(_pts);
1367
1367
  let r = _pts[0].$subtract(c).magnitude();
1368
1368
  return Circle.fromCenter(c, r);
1369
1369
  }
1370
1370
  };
1371
- var Polygon = class {
1371
+ var Polygon = class _Polygon {
1372
1372
  /**
1373
1373
  * Get the centroid of a polygon, which is the average of all its points.
1374
1374
  * @param pts a Group or an Iterable<PtLike> representing a polygon
@@ -1432,7 +1432,7 @@ var Polygon = class {
1432
1432
  * @param t a value between 0 to 1 for interpolation. Default to 0.5 which will get the middle point.
1433
1433
  */
1434
1434
  static midpoints(poly, closePath = false, t = 0.5) {
1435
- let sides = Polygon.lines(poly, closePath);
1435
+ let sides = _Polygon.lines(poly, closePath);
1436
1436
  let mids = sides.map((s) => Geom.interpolate(s[0], s[1], t));
1437
1437
  return mids;
1438
1438
  }
@@ -1469,7 +1469,7 @@ var Polygon = class {
1469
1469
  * @returns a bisector Pt that's a normalized unit vector
1470
1470
  */
1471
1471
  static bisector(poly, index) {
1472
- let sides = Polygon.adjacentSides(poly, index, true);
1472
+ let sides = _Polygon.adjacentSides(poly, index, true);
1473
1473
  if (sides.length >= 2) {
1474
1474
  let a = sides[0][1].$subtract(sides[0][0]).unit();
1475
1475
  let b = sides[1][1].$subtract(sides[1][0]).unit();
@@ -1485,7 +1485,7 @@ var Polygon = class {
1485
1485
  * @returns an object with `total` length, and `segments` which is a Pt that stores each segment's length
1486
1486
  */
1487
1487
  static perimeter(poly, closePath = false) {
1488
- let lines = Polygon.lines(poly, closePath);
1488
+ let lines = _Polygon.lines(poly, closePath);
1489
1489
  let mag = 0;
1490
1490
  let p = Pt.make(lines.length, 0);
1491
1491
  for (let i = 0, len = lines.length; i < len; i++) {
@@ -1625,8 +1625,8 @@ var Polygon = class {
1625
1625
  * @param unitAxis unit axis
1626
1626
  */
1627
1627
  static _axisOverlap(poly1, poly2, unitAxis) {
1628
- let pa = Polygon.projectAxis(poly1, unitAxis);
1629
- let pb = Polygon.projectAxis(poly2, unitAxis);
1628
+ let pa = _Polygon.projectAxis(poly1, unitAxis);
1629
+ let pb = _Polygon.projectAxis(poly2, unitAxis);
1630
1630
  return pa[0] < pb[0] ? pb[0] - pa[1] : pa[0] - pb[1];
1631
1631
  }
1632
1632
  /**
@@ -1638,7 +1638,7 @@ var Polygon = class {
1638
1638
  let _poly = Util.iterToArray(poly);
1639
1639
  let c = false;
1640
1640
  for (let i = 0, len = _poly.length; i < len; i++) {
1641
- let ln = Polygon.lineAt(_poly, i);
1641
+ let ln = _Polygon.lineAt(_poly, i);
1642
1642
  if (ln[0][1] > pt[1] != ln[1][1] > pt[1] && pt[0] < (ln[1][0] - ln[0][0]) * (pt[1] - ln[0][1]) / (ln[1][1] - ln[0][1]) + ln[0][0]) {
1643
1643
  c = !c;
1644
1644
  }
@@ -1669,10 +1669,10 @@ var Polygon = class {
1669
1669
  let r = _circle[1][0];
1670
1670
  let minDist = Number.MAX_SAFE_INTEGER;
1671
1671
  for (let i = 0, len = _poly.length; i < len; i++) {
1672
- let edge = Polygon.lineAt(_poly, i);
1672
+ let edge = _Polygon.lineAt(_poly, i);
1673
1673
  let axis = new Pt(edge[0].y - edge[1].y, edge[1].x - edge[0].x).unit();
1674
1674
  let poly2 = new Group(c.$add(axis.$multiply(r)), c.$subtract(axis.$multiply(r)));
1675
- let dist = Polygon._axisOverlap(_poly, poly2, axis);
1675
+ let dist = _Polygon._axisOverlap(_poly, poly2, axis);
1676
1676
  if (dist > 0) {
1677
1677
  return null;
1678
1678
  } else if (Math.abs(dist) < minDist) {
@@ -1687,7 +1687,7 @@ var Polygon = class {
1687
1687
  }
1688
1688
  if (!info.edge)
1689
1689
  return null;
1690
- let dir = c.$subtract(Polygon.centroid(_poly)).dot(info.normal);
1690
+ let dir = c.$subtract(_Polygon.centroid(_poly)).dot(info.normal);
1691
1691
  if (dir < 0)
1692
1692
  info.normal.multiply(-1);
1693
1693
  info.dist = minDist;
@@ -1716,9 +1716,9 @@ var Polygon = class {
1716
1716
  };
1717
1717
  let minDist = Number.MAX_SAFE_INTEGER;
1718
1718
  for (let i = 0, plen = _poly1.length + _poly2.length; i < plen; i++) {
1719
- let edge = i < _poly1.length ? Polygon.lineAt(_poly1, i) : Polygon.lineAt(_poly2, i - _poly1.length);
1719
+ let edge = i < _poly1.length ? _Polygon.lineAt(_poly1, i) : _Polygon.lineAt(_poly2, i - _poly1.length);
1720
1720
  let axis = new Pt(edge[0].y - edge[1].y, edge[1].x - edge[0].x).unit();
1721
- let dist = Polygon._axisOverlap(_poly1, _poly2, axis);
1721
+ let dist = _Polygon._axisOverlap(_poly1, _poly2, axis);
1722
1722
  if (dist > 0) {
1723
1723
  return null;
1724
1724
  } else if (Math.abs(dist) < minDist) {
@@ -1731,8 +1731,8 @@ var Polygon = class {
1731
1731
  info.dist = minDist;
1732
1732
  let b1 = info.which === 0 ? _poly2 : _poly1;
1733
1733
  let b2 = info.which === 0 ? _poly1 : _poly2;
1734
- let c1 = Polygon.centroid(b1);
1735
- let c2 = Polygon.centroid(b2);
1734
+ let c1 = _Polygon.centroid(b1);
1735
+ let c2 = _Polygon.centroid(b2);
1736
1736
  let dir = c1.$subtract(c2).dot(info.normal);
1737
1737
  if (dir < 0)
1738
1738
  info.normal.multiply(-1);
@@ -1754,7 +1754,7 @@ var Polygon = class {
1754
1754
  static intersectPolygon2D(poly1, poly2) {
1755
1755
  let _poly1 = Util.iterToArray(poly1);
1756
1756
  let _poly2 = Util.iterToArray(poly2);
1757
- let lp = Polygon.lines(_poly1);
1757
+ let lp = _Polygon.lines(_poly1);
1758
1758
  let g = [];
1759
1759
  for (let i = 0, len = lp.length; i < len; i++) {
1760
1760
  let ins = Line.intersectPolygon2D(lp[i], _poly2, false);
@@ -1777,7 +1777,7 @@ var Polygon = class {
1777
1777
  return boxes;
1778
1778
  }
1779
1779
  };
1780
- var Curve = class {
1780
+ var Curve = class _Curve {
1781
1781
  /**
1782
1782
  * Get a precalculated coefficients per step.
1783
1783
  * @param steps number of steps
@@ -1836,17 +1836,17 @@ var Curve = class {
1836
1836
  if (_pts.length < 2)
1837
1837
  return new Group();
1838
1838
  let ps = new Group();
1839
- let ts = Curve.getSteps(steps);
1840
- let c = Curve.controlPoints(_pts, 0, true);
1839
+ let ts = _Curve.getSteps(steps);
1840
+ let c = _Curve.controlPoints(_pts, 0, true);
1841
1841
  for (let i = 0; i <= steps; i++) {
1842
- ps.push(Curve.catmullRomStep(ts[i], c));
1842
+ ps.push(_Curve.catmullRomStep(ts[i], c));
1843
1843
  }
1844
1844
  let k = 0;
1845
1845
  while (k < _pts.length - 2) {
1846
- let cp = Curve.controlPoints(_pts, k);
1846
+ let cp = _Curve.controlPoints(_pts, k);
1847
1847
  if (cp.length > 0) {
1848
1848
  for (let i = 0; i <= steps; i++) {
1849
- ps.push(Curve.catmullRomStep(ts[i], cp));
1849
+ ps.push(_Curve.catmullRomStep(ts[i], cp));
1850
1850
  }
1851
1851
  k++;
1852
1852
  }
@@ -1866,7 +1866,7 @@ var Curve = class {
1866
1866
  new Pt(-1.5, 2, 0.5, 0),
1867
1867
  new Pt(0.5, -0.5, 0, 0)
1868
1868
  );
1869
- return Curve._calcPt(ctrls, Mat.multiply([step], m, true)[0]);
1869
+ return _Curve._calcPt(ctrls, Mat.multiply([step], m, true)[0]);
1870
1870
  }
1871
1871
  /**
1872
1872
  * Create a Cardinal curve.
@@ -1880,17 +1880,17 @@ var Curve = class {
1880
1880
  if (_pts.length < 2)
1881
1881
  return new Group();
1882
1882
  let ps = new Group();
1883
- let ts = Curve.getSteps(steps);
1884
- let c = Curve.controlPoints(_pts, 0, true);
1883
+ let ts = _Curve.getSteps(steps);
1884
+ let c = _Curve.controlPoints(_pts, 0, true);
1885
1885
  for (let i = 0; i <= steps; i++) {
1886
- ps.push(Curve.cardinalStep(ts[i], c, tension));
1886
+ ps.push(_Curve.cardinalStep(ts[i], c, tension));
1887
1887
  }
1888
1888
  let k = 0;
1889
1889
  while (k < _pts.length - 2) {
1890
- let cp = Curve.controlPoints(_pts, k);
1890
+ let cp = _Curve.controlPoints(_pts, k);
1891
1891
  if (cp.length > 0) {
1892
1892
  for (let i = 0; i <= steps; i++) {
1893
- ps.push(Curve.cardinalStep(ts[i], cp, tension));
1893
+ ps.push(_Curve.cardinalStep(ts[i], cp, tension));
1894
1894
  }
1895
1895
  k++;
1896
1896
  }
@@ -1914,7 +1914,7 @@ var Curve = class {
1914
1914
  let h = Mat.multiply([step], m, true)[0].multiply(tension);
1915
1915
  let h2 = 2 * step[0] - 3 * step[1] + 1;
1916
1916
  let h3 = -2 * step[0] + 3 * step[1];
1917
- let pt = Curve._calcPt(ctrls, h);
1917
+ let pt = _Curve._calcPt(ctrls, h);
1918
1918
  pt.x += h2 * ctrls[1].x + h3 * ctrls[2].x;
1919
1919
  pt.y += h2 * ctrls[1].y + h3 * ctrls[2].y;
1920
1920
  if (pt.length > 2)
@@ -1932,13 +1932,13 @@ var Curve = class {
1932
1932
  if (_pts.length < 4)
1933
1933
  return new Group();
1934
1934
  let ps = new Group();
1935
- let ts = Curve.getSteps(steps);
1935
+ let ts = _Curve.getSteps(steps);
1936
1936
  let k = 0;
1937
1937
  while (k < _pts.length - 3) {
1938
- let c = Curve.controlPoints(_pts, k);
1938
+ let c = _Curve.controlPoints(_pts, k);
1939
1939
  if (c.length > 0) {
1940
1940
  for (let i = 0; i <= steps; i++) {
1941
- ps.push(Curve.bezierStep(ts[i], c));
1941
+ ps.push(_Curve.bezierStep(ts[i], c));
1942
1942
  }
1943
1943
  k += 3;
1944
1944
  }
@@ -1958,7 +1958,7 @@ var Curve = class {
1958
1958
  new Pt(-3, 3, 0, 0),
1959
1959
  new Pt(1, 0, 0, 0)
1960
1960
  );
1961
- return Curve._calcPt(ctrls, Mat.multiply([step], m, true)[0]);
1961
+ return _Curve._calcPt(ctrls, Mat.multiply([step], m, true)[0]);
1962
1962
  }
1963
1963
  /**
1964
1964
  * Create a basis spline (NURBS) curve.
@@ -1972,18 +1972,18 @@ var Curve = class {
1972
1972
  if (_pts.length < 2)
1973
1973
  return new Group();
1974
1974
  let ps = new Group();
1975
- let ts = Curve.getSteps(steps);
1975
+ let ts = _Curve.getSteps(steps);
1976
1976
  let k = 0;
1977
1977
  while (k < _pts.length - 3) {
1978
- let c = Curve.controlPoints(_pts, k);
1978
+ let c = _Curve.controlPoints(_pts, k);
1979
1979
  if (c.length > 0) {
1980
1980
  if (tension !== 1) {
1981
1981
  for (let i = 0; i <= steps; i++) {
1982
- ps.push(Curve.bsplineTensionStep(ts[i], c, tension));
1982
+ ps.push(_Curve.bsplineTensionStep(ts[i], c, tension));
1983
1983
  }
1984
1984
  } else {
1985
1985
  for (let i = 0; i <= steps; i++) {
1986
- ps.push(Curve.bsplineStep(ts[i], c));
1986
+ ps.push(_Curve.bsplineStep(ts[i], c));
1987
1987
  }
1988
1988
  }
1989
1989
  k++;
@@ -2004,7 +2004,7 @@ var Curve = class {
2004
2004
  new Pt(-0.5, 0.5, 0.5, 0.16666666666666666),
2005
2005
  new Pt(0.16666666666666666, 0, 0, 0)
2006
2006
  );
2007
- return Curve._calcPt(ctrls, Mat.multiply([step], m, true)[0]);
2007
+ return _Curve._calcPt(ctrls, Mat.multiply([step], m, true)[0]);
2008
2008
  }
2009
2009
  /**
2010
2010
  * Interpolate to get a point on a basis spline curve with tension.
@@ -2023,7 +2023,7 @@ var Curve = class {
2023
2023
  let h = Mat.multiply([step], m, true)[0].multiply(tension);
2024
2024
  let h2 = 2 * step[0] - 3 * step[1] + 1;
2025
2025
  let h3 = -2 * step[0] + 3 * step[1];
2026
- let pt = Curve._calcPt(ctrls, h);
2026
+ let pt = _Curve._calcPt(ctrls, h);
2027
2027
  pt.x += h2 * ctrls[1].x + h3 * ctrls[2].x;
2028
2028
  pt.y += h2 * ctrls[1].y + h3 * ctrls[2].y;
2029
2029
  if (pt.length > 2)
@@ -2034,13 +2034,13 @@ var Curve = class {
2034
2034
 
2035
2035
  // src/uheprng.ts
2036
2036
  function Mash() {
2037
- var n = 4022871197;
2038
- var mash = function(data) {
2037
+ let n = 4022871197;
2038
+ let mash = function(data) {
2039
2039
  if (data) {
2040
2040
  data = data.toString();
2041
- for (var i = 0; i < data.length; i++) {
2041
+ for (let i = 0; i < data.length; i++) {
2042
2042
  n += data.charCodeAt(i);
2043
- var h = 0.02519603282416938 * n;
2043
+ let h = 0.02519603282416938 * n;
2044
2044
  n = h >>> 0;
2045
2045
  h -= n;
2046
2046
  h *= n;
@@ -2055,12 +2055,12 @@ function Mash() {
2055
2055
  return mash;
2056
2056
  }
2057
2057
  function uheprng_default(seed) {
2058
- var o = 48;
2059
- var c = 1;
2060
- var p = o;
2061
- var s = new Array(o);
2062
- var i, j, k = 0;
2063
- var mash = Mash();
2058
+ let o = 48;
2059
+ let c = 1;
2060
+ let p = o;
2061
+ let s = new Array(o);
2062
+ let i, j, k = 0;
2063
+ let mash = Mash();
2064
2064
  for (i = 0; i < o; i++)
2065
2065
  s[i] = mash(Math.random().toString());
2066
2066
  function initState() {
@@ -2092,24 +2092,24 @@ function uheprng_default(seed) {
2092
2092
  hashString(seed);
2093
2093
  return {
2094
2094
  /**
2095
- * this (not anymore) PRIVATE (internal access only) function is the heart of the multiply-with-carry
2096
- * (MWC) PRNG algorithm. When called it returns a pseudo-random number in the form of a
2097
- * 32-bit JavaScript fraction (0.0 to <1.0) it is a PRIVATE function used by the default
2098
- * [0-1] return function, and by the random 'string(n)' function which returns 'n'
2099
- * characters from 33 to 126.
2100
- * @returns a number between 0.0 and 1.0
2101
- */
2095
+ * this (not anymore) PRIVATE (internal access only) function is the heart of the multiply-with-carry
2096
+ * (MWC) PRNG algorithm. When called it returns a pseudo-random number in the form of a
2097
+ * 32-bit JavaScript fraction (0.0 to <1.0) it is a PRIVATE function used by the default
2098
+ * [0-1] return function, and by the random 'string(n)' function which returns 'n'
2099
+ * characters from 33 to 126.
2100
+ * @returns a number between 0.0 and 1.0
2101
+ */
2102
2102
  random() {
2103
2103
  if (++p >= o)
2104
2104
  p = 0;
2105
- var t = 1768863 * s[p] + c * 23283064365386963e-26;
2105
+ let t = 1768863 * s[p] + c * 23283064365386963e-26;
2106
2106
  return s[p] = t - (c = t | 0);
2107
2107
  }
2108
2108
  };
2109
2109
  }
2110
2110
 
2111
2111
  // src/Num.ts
2112
- var Num = class {
2112
+ var Num = class _Num {
2113
2113
  /**
2114
2114
  * Check if two numbers are equal or almost equal within a threshold.
2115
2115
  * @param a number a
@@ -2145,7 +2145,7 @@ var Num = class {
2145
2145
  * @example `boundValue(361, 0, 360)` will return 1
2146
2146
  */
2147
2147
  static boundValue(val, min, max) {
2148
- let len = Math.abs(max - min);
2148
+ const len = Math.abs(max - min);
2149
2149
  let a = val % len;
2150
2150
  if (a > max)
2151
2151
  a -= len;
@@ -2168,8 +2168,8 @@ var Num = class {
2168
2168
  * @param b range value 2
2169
2169
  */
2170
2170
  static randomRange(a, b = 0) {
2171
- let r = a > b ? a - b : b - a;
2172
- return a + Num.random() * r;
2171
+ const r = a > b ? a - b : b - a;
2172
+ return a + _Num.random() * r;
2173
2173
  }
2174
2174
  /**
2175
2175
  * Get a random Pt within the range defined by either 1 or 2 Pt
@@ -2177,11 +2177,11 @@ var Num = class {
2177
2177
  * @param b optional Pt to define the end of the range
2178
2178
  */
2179
2179
  static randomPt(a, b) {
2180
- let p = new Pt(a.length);
2181
- let range = b ? Vec.subtract(b.slice(), a) : a;
2182
- let start = b ? a : new Pt(a.length).fill(0);
2180
+ const p = new Pt(a.length);
2181
+ const range = b ? Vec.subtract(b.slice(), a) : a;
2182
+ const start = b ? a : new Pt(a.length).fill(0);
2183
2183
  for (let i = 0, len = p.length; i < len; i++) {
2184
- p[i] = Num.random() * range[i] + start[i];
2184
+ p[i] = _Num.random() * range[i] + start[i];
2185
2185
  }
2186
2186
  return p;
2187
2187
  }
@@ -2192,8 +2192,8 @@ var Num = class {
2192
2192
  * @param b range value 1
2193
2193
  */
2194
2194
  static normalizeValue(n, a, b) {
2195
- let min = Math.min(a, b);
2196
- let max = Math.max(a, b);
2195
+ const min = Math.min(a, b);
2196
+ const max = Math.max(a, b);
2197
2197
  return (n - min) / (max - min);
2198
2198
  }
2199
2199
  /**
@@ -2202,8 +2202,8 @@ var Num = class {
2202
2202
  * @returns a Pt of the dimensional sums
2203
2203
  */
2204
2204
  static sum(pts) {
2205
- let _pts = Util.iterToArray(pts);
2206
- let c = new Pt(_pts[0]);
2205
+ const _pts = Util.iterToArray(pts);
2206
+ const c = new Pt(_pts[0]);
2207
2207
  for (let i = 1, len = _pts.length; i < len; i++) {
2208
2208
  Vec.add(c, _pts[i]);
2209
2209
  }
@@ -2215,8 +2215,8 @@ var Num = class {
2215
2215
  * @returns a Pt of averages
2216
2216
  */
2217
2217
  static average(pts) {
2218
- let _pts = Util.iterToArray(pts);
2219
- return Num.sum(_pts).divide(_pts.length);
2218
+ const _pts = Util.iterToArray(pts);
2219
+ return _Num.sum(_pts).divide(_pts.length);
2220
2220
  }
2221
2221
  /**
2222
2222
  * Given a value between 0 to 1, returns a value that cycles between 0 -> 1 -> 0 using the provided shaping method.
@@ -2239,9 +2239,9 @@ var Num = class {
2239
2239
  static mapToRange(n, currA, currB, targetA, targetB) {
2240
2240
  if (currA == currB)
2241
2241
  throw new Error("[currMin, currMax] must define a range that is not zero");
2242
- let min = Math.min(targetA, targetB);
2243
- let max = Math.max(targetA, targetB);
2244
- return Num.normalizeValue(n, currA, currB) * (max - min) + min;
2242
+ const min = Math.min(targetA, targetB);
2243
+ const max = Math.max(targetA, targetB);
2244
+ return _Num.normalizeValue(n, currA, currB) * (max - min) + min;
2245
2245
  }
2246
2246
  /**
2247
2247
  * Seed the pseudorandom generator.
@@ -2259,7 +2259,7 @@ var Num = class {
2259
2259
  return this.generator ? this.generator.random() : Math.random();
2260
2260
  }
2261
2261
  };
2262
- var Geom = class {
2262
+ var Geom = class _Geom {
2263
2263
  /**
2264
2264
  * Bound an angle between 0 to 360 degrees.
2265
2265
  * @param angle angle value
@@ -2295,7 +2295,7 @@ var Geom = class {
2295
2295
  */
2296
2296
  static boundingBox(pts) {
2297
2297
  let minPt, maxPt;
2298
- for (let p of pts) {
2298
+ for (const p of pts) {
2299
2299
  if (minPt == void 0) {
2300
2300
  minPt = p.clone();
2301
2301
  maxPt = p.clone();
@@ -2321,9 +2321,9 @@ var Geom = class {
2321
2321
  * @param direction a string either "to" (subtract all Pt with this anchor base), or "from" (add all Pt from this anchor base)
2322
2322
  */
2323
2323
  static anchor(pts, ptOrIndex = 0, direction = "to") {
2324
- let method = direction == "to" ? "subtract" : "add";
2324
+ const method = direction == "to" ? "subtract" : "add";
2325
2325
  let i = 0;
2326
- for (let p of pts) {
2326
+ for (const p of pts) {
2327
2327
  if (typeof ptOrIndex == "number") {
2328
2328
  if (ptOrIndex !== i)
2329
2329
  p[method](pts[ptOrIndex]);
@@ -2341,8 +2341,8 @@ var Geom = class {
2341
2341
  * @returns interpolated point as a new Pt
2342
2342
  */
2343
2343
  static interpolate(a, b, t = 0.5) {
2344
- let len = Math.min(a.length, b.length);
2345
- let d = Pt.make(len);
2344
+ const len = Math.min(a.length, b.length);
2345
+ const d = Pt.make(len);
2346
2346
  for (let i = 0; i < len; i++) {
2347
2347
  d[i] = a[i] * (1 - t) + b[i] * t;
2348
2348
  }
@@ -2354,13 +2354,13 @@ var Geom = class {
2354
2354
  * @returns an array of two Pt that are perpendicular to this Pt
2355
2355
  */
2356
2356
  static perpendicular(pt, axis = Const.xy) {
2357
- let y = axis[1];
2358
- let x = axis[0];
2359
- let p = new Pt(pt);
2360
- let pa = new Pt(p);
2357
+ const y = axis[1];
2358
+ const x = axis[0];
2359
+ const p = new Pt(pt);
2360
+ const pa = new Pt(p);
2361
2361
  pa[x] = -p[y];
2362
2362
  pa[y] = p[x];
2363
- let pb = new Pt(p);
2363
+ const pb = new Pt(p);
2364
2364
  pb[x] = p[y];
2365
2365
  pb[y] = -p[x];
2366
2366
  return new Group(pa, pb);
@@ -2389,14 +2389,14 @@ var Geom = class {
2389
2389
  * @param pts a Group or an Iterable<Pt>
2390
2390
  */
2391
2391
  static sortEdges(pts) {
2392
- let _pts = Util.iterToArray(pts);
2393
- let bounds = Geom.boundingBox(_pts);
2394
- let center = bounds[1].add(bounds[0]).divide(2);
2395
- let fn = (a, b) => {
2392
+ const _pts = Util.iterToArray(pts);
2393
+ const bounds = _Geom.boundingBox(_pts);
2394
+ const center = bounds[1].add(bounds[0]).divide(2);
2395
+ const fn = (a, b) => {
2396
2396
  if (a.length < 2 || b.length < 2)
2397
2397
  throw new Error("Pt dimension cannot be less than 2");
2398
- let da = a.$subtract(center);
2399
- let db = b.$subtract(center);
2398
+ const da = a.$subtract(center);
2399
+ const db = b.$subtract(center);
2400
2400
  if (da[0] >= 0 && db[0] < 0)
2401
2401
  return 1;
2402
2402
  if (da[0] < 0 && db[0] >= 0)
@@ -2406,7 +2406,7 @@ var Geom = class {
2406
2406
  return da[1] > db[1] ? 1 : -1;
2407
2407
  return db[1] > da[1] ? 1 : -1;
2408
2408
  }
2409
- let det = da.$cross2D(db);
2409
+ const det = da.$cross2D(db);
2410
2410
  if (det < 0)
2411
2411
  return 1;
2412
2412
  if (det > 0)
@@ -2422,17 +2422,17 @@ var Geom = class {
2422
2422
  * @param anchor optional anchor point to scale from
2423
2423
  */
2424
2424
  static scale(ps, scale, anchor) {
2425
- let pts = Util.iterToArray(ps[0] !== void 0 && typeof ps[0] == "number" ? [ps] : ps);
2426
- let scs = typeof scale == "number" ? Pt.make(pts[0].length, scale) : scale;
2425
+ const pts = Util.iterToArray(ps[0] !== void 0 && typeof ps[0] == "number" ? [ps] : ps);
2426
+ const scs = typeof scale == "number" ? Pt.make(pts[0].length, scale) : scale;
2427
2427
  if (!anchor)
2428
2428
  anchor = Pt.make(pts[0].length, 0);
2429
2429
  for (let i = 0, len = pts.length; i < len; i++) {
2430
- let p = pts[i];
2430
+ const p = pts[i];
2431
2431
  for (let k = 0, lenP = p.length; k < lenP; k++) {
2432
2432
  p[k] = anchor && anchor[k] ? anchor[k] + (p[k] - anchor[k]) * scs[k] : p[k] * scs[k];
2433
2433
  }
2434
2434
  }
2435
- return Geom;
2435
+ return _Geom;
2436
2436
  }
2437
2437
  /**
2438
2438
  * Rotate a Pt or a Group of Pts in 2D space. You may also use [`Pt.rotate2D`](#link) instance method.
@@ -2442,14 +2442,14 @@ var Geom = class {
2442
2442
  * @param axis optional axis such as "xy" (use Const.xy) to define a 2D plane, or a number array to specify indices
2443
2443
  */
2444
2444
  static rotate2D(ps, angle, anchor, axis) {
2445
- let pts = Util.iterToArray(ps[0] !== void 0 && typeof ps[0] == "number" ? [ps] : ps);
2446
- let fn = anchor ? Mat.rotateAt2DMatrix : Mat.rotate2DMatrix;
2445
+ const pts = Util.iterToArray(ps[0] !== void 0 && typeof ps[0] == "number" ? [ps] : ps);
2446
+ const fn = anchor ? Mat.rotateAt2DMatrix : Mat.rotate2DMatrix;
2447
2447
  if (!anchor)
2448
2448
  anchor = Pt.make(pts[0].length, 0);
2449
- let cos = Math.cos(angle);
2450
- let sin = Math.sin(angle);
2449
+ const cos = Math.cos(angle);
2450
+ const sin = Math.sin(angle);
2451
2451
  for (let i = 0, len = pts.length; i < len; i++) {
2452
- let p = axis ? pts[i].$take(axis) : pts[i];
2452
+ const p = axis ? pts[i].$take(axis) : pts[i];
2453
2453
  p.to(Mat.transform2D(p, fn(cos, sin, anchor)));
2454
2454
  if (axis) {
2455
2455
  for (let k = 0; k < axis.length; k++) {
@@ -2457,7 +2457,7 @@ var Geom = class {
2457
2457
  }
2458
2458
  }
2459
2459
  }
2460
- return Geom;
2460
+ return _Geom;
2461
2461
  }
2462
2462
  /**
2463
2463
  * Shear a Pt or a Group of Pts in 2D space. You may also use [`Pt.shear2D`](#link) instance method.
@@ -2467,15 +2467,15 @@ var Geom = class {
2467
2467
  * @param axis optional axis such as "xy" (use Const.xy) to define a 2D plane, or a number array to specify indices
2468
2468
  */
2469
2469
  static shear2D(ps, scale, anchor, axis) {
2470
- let pts = Util.iterToArray(ps[0] !== void 0 && typeof ps[0] == "number" ? [ps] : ps);
2471
- let s = typeof scale == "number" ? [scale, scale] : scale;
2470
+ const pts = Util.iterToArray(ps[0] !== void 0 && typeof ps[0] == "number" ? [ps] : ps);
2471
+ const s = typeof scale == "number" ? [scale, scale] : scale;
2472
2472
  if (!anchor)
2473
2473
  anchor = Pt.make(pts[0].length, 0);
2474
- let fn = anchor ? Mat.shearAt2DMatrix : Mat.shear2DMatrix;
2475
- let tanx = Math.tan(s[0]);
2476
- let tany = Math.tan(s[1]);
2474
+ const fn = anchor ? Mat.shearAt2DMatrix : Mat.shear2DMatrix;
2475
+ const tanx = Math.tan(s[0]);
2476
+ const tany = Math.tan(s[1]);
2477
2477
  for (let i = 0, len = pts.length; i < len; i++) {
2478
- let p = axis ? pts[i].$take(axis) : pts[i];
2478
+ const p = axis ? pts[i].$take(axis) : pts[i];
2479
2479
  p.to(Mat.transform2D(p, fn(tanx, tany, anchor)));
2480
2480
  if (axis) {
2481
2481
  for (let k = 0; k < axis.length; k++) {
@@ -2483,7 +2483,7 @@ var Geom = class {
2483
2483
  }
2484
2484
  }
2485
2485
  }
2486
- return Geom;
2486
+ return _Geom;
2487
2487
  }
2488
2488
  /**
2489
2489
  * Reflect a Pt or a Group of Pts along a 2D line. You may also use [`Pt.reflect2D`](#link) instance method.
@@ -2492,11 +2492,11 @@ var Geom = class {
2492
2492
  * @param axis optional axis such as "xy" (use Const.xy) to define a 2D plane, or a number array to specify indices
2493
2493
  */
2494
2494
  static reflect2D(ps, line, axis) {
2495
- let pts = Util.iterToArray(ps[0] !== void 0 && typeof ps[0] == "number" ? [ps] : ps);
2496
- let _line = Util.iterToArray(line);
2497
- let mat = Mat.reflectAt2DMatrix(_line[0], _line[1]);
2495
+ const pts = Util.iterToArray(ps[0] !== void 0 && typeof ps[0] == "number" ? [ps] : ps);
2496
+ const _line = Util.iterToArray(line);
2497
+ const mat = Mat.reflectAt2DMatrix(_line[0], _line[1]);
2498
2498
  for (let i = 0, len = pts.length; i < len; i++) {
2499
- let p = axis ? pts[i].$take(axis) : pts[i];
2499
+ const p = axis ? pts[i].$take(axis) : pts[i];
2500
2500
  p.to(Mat.transform2D(p, mat));
2501
2501
  if (axis) {
2502
2502
  for (let k = 0; k < axis.length; k++) {
@@ -2504,17 +2504,17 @@ var Geom = class {
2504
2504
  }
2505
2505
  }
2506
2506
  }
2507
- return Geom;
2507
+ return _Geom;
2508
2508
  }
2509
2509
  /**
2510
2510
  * Generate a cosine lookup table.
2511
2511
  * @returns an object with a cosine tables (array of 360 values) and a function to get cosine given a radian input.
2512
2512
  */
2513
2513
  static cosTable() {
2514
- let cos = new Float64Array(360);
2514
+ const cos = new Float64Array(360);
2515
2515
  for (let i = 0; i < 360; i++)
2516
2516
  cos[i] = Math.cos(i * Math.PI / 180);
2517
- let find = (rad) => cos[Math.floor(Geom.boundAngle(Geom.toDegree(rad)))];
2517
+ const find = (rad) => cos[Math.floor(_Geom.boundAngle(_Geom.toDegree(rad)))];
2518
2518
  return { table: cos, cos: find };
2519
2519
  }
2520
2520
  /**
@@ -2522,14 +2522,14 @@ var Geom = class {
2522
2522
  * @returns an object with a sine tables (array of 360 values) and a function to get sine value given a radian input.
2523
2523
  */
2524
2524
  static sinTable() {
2525
- let sin = new Float64Array(360);
2525
+ const sin = new Float64Array(360);
2526
2526
  for (let i = 0; i < 360; i++)
2527
2527
  sin[i] = Math.sin(i * Math.PI / 180);
2528
- let find = (rad) => sin[Math.floor(Geom.boundAngle(Geom.toDegree(rad)))];
2528
+ const find = (rad) => sin[Math.floor(_Geom.boundAngle(_Geom.toDegree(rad)))];
2529
2529
  return { table: sin, sin: find };
2530
2530
  }
2531
2531
  };
2532
- var Shaping = class {
2532
+ var Shaping = class _Shaping {
2533
2533
  /**
2534
2534
  * Linear mapping.
2535
2535
  * @param t a value between 0 to 1
@@ -2560,7 +2560,7 @@ var Shaping = class {
2560
2560
  * @param c the value to shape, default is 1
2561
2561
  */
2562
2562
  static quadraticInOut(t, c = 1) {
2563
- let dt = t * 2;
2563
+ const dt = t * 2;
2564
2564
  return t < 0.5 ? c / 2 * t * t * 4 : -c / 2 * ((dt - 1) * (dt - 3) - 1);
2565
2565
  }
2566
2566
  /**
@@ -2577,7 +2577,7 @@ var Shaping = class {
2577
2577
  * @param c the value to shape, default is 1
2578
2578
  */
2579
2579
  static cubicOut(t, c = 1) {
2580
- let dt = t - 1;
2580
+ const dt = t - 1;
2581
2581
  return c * (dt * dt * dt + 1);
2582
2582
  }
2583
2583
  /**
@@ -2586,7 +2586,7 @@ var Shaping = class {
2586
2586
  * @param c the value to shape, default is 1
2587
2587
  */
2588
2588
  static cubicInOut(t, c = 1) {
2589
- let dt = t * 2;
2589
+ const dt = t * 2;
2590
2590
  return t < 0.5 ? c / 2 * dt * dt * dt : c / 2 * ((dt - 2) * (dt - 2) * (dt - 2) + 2);
2591
2591
  }
2592
2592
  /**
@@ -2637,9 +2637,9 @@ var Shaping = class {
2637
2637
  * @param c the value to shape, default is 1
2638
2638
  */
2639
2639
  static cosineApprox(t, c = 1) {
2640
- let t2 = t * t;
2641
- let t4 = t2 * t2;
2642
- let t6 = t4 * t2;
2640
+ const t2 = t * t;
2641
+ const t4 = t2 * t2;
2642
+ const t6 = t4 * t2;
2643
2643
  return c * (4 * t6 / 9 - 17 * t4 / 9 + 22 * t2 / 9);
2644
2644
  }
2645
2645
  /**
@@ -2656,7 +2656,7 @@ var Shaping = class {
2656
2656
  * @param c the value to shape, default is 1
2657
2657
  */
2658
2658
  static circularOut(t, c = 1) {
2659
- let dt = t - 1;
2659
+ const dt = t - 1;
2660
2660
  return c * Math.sqrt(1 - dt * dt);
2661
2661
  }
2662
2662
  /**
@@ -2665,7 +2665,7 @@ var Shaping = class {
2665
2665
  * @param c the value to shape, default is 1
2666
2666
  */
2667
2667
  static circularInOut(t, c = 1) {
2668
- let dt = t * 2;
2668
+ const dt = t * 2;
2669
2669
  return t < 0.5 ? -c / 2 * (Math.sqrt(1 - dt * dt) - 1) : c / 2 * (Math.sqrt(1 - (dt - 2) * (dt - 2)) + 1);
2670
2670
  }
2671
2671
  /**
@@ -2675,8 +2675,8 @@ var Shaping = class {
2675
2675
  * @param p elastic parmeter between 0 to 1. The lower the number, the more elastic it will be. Default is 0.7.
2676
2676
  */
2677
2677
  static elasticIn(t, c = 1, p = 0.7) {
2678
- let dt = t - 1;
2679
- let s = p / Const.two_pi * 1.5707963267948966;
2678
+ const dt = t - 1;
2679
+ const s = p / Const.two_pi * 1.5707963267948966;
2680
2680
  return c * (-Math.pow(2, 10 * dt) * Math.sin((dt - s) * Const.two_pi / p));
2681
2681
  }
2682
2682
  /**
@@ -2686,7 +2686,7 @@ var Shaping = class {
2686
2686
  * @param p elastic parmeter between 0 to 1. The lower the number, the more elastic it will be. Default is 0.7.
2687
2687
  */
2688
2688
  static elasticOut(t, c = 1, p = 0.7) {
2689
- let s = p / Const.two_pi * 1.5707963267948966;
2689
+ const s = p / Const.two_pi * 1.5707963267948966;
2690
2690
  return c * (Math.pow(2, -10 * t) * Math.sin((t - s) * Const.two_pi / p)) + c;
2691
2691
  }
2692
2692
  /**
@@ -2697,7 +2697,7 @@ var Shaping = class {
2697
2697
  */
2698
2698
  static elasticInOut(t, c = 1, p = 0.6) {
2699
2699
  let dt = t * 2;
2700
- let s = p / Const.two_pi * 1.5707963267948966;
2700
+ const s = p / Const.two_pi * 1.5707963267948966;
2701
2701
  if (t < 0.5) {
2702
2702
  dt -= 1;
2703
2703
  return c * (-0.5 * (Math.pow(2, 10 * dt) * Math.sin((dt - s) * Const.two_pi / p)));
@@ -2712,7 +2712,7 @@ var Shaping = class {
2712
2712
  * @param c the value to shape, default is 1
2713
2713
  */
2714
2714
  static bounceIn(t, c = 1) {
2715
- return c - Shaping.bounceOut(1 - t, c);
2715
+ return c - _Shaping.bounceOut(1 - t, c);
2716
2716
  }
2717
2717
  /**
2718
2718
  * Bounce out, adapted from Robert Penner's [easing functions](http://robertpenner.com/easing/).
@@ -2739,7 +2739,7 @@ var Shaping = class {
2739
2739
  * @param c the value to shape, default is 1
2740
2740
  */
2741
2741
  static bounceInOut(t, c = 1) {
2742
- return t < 0.5 ? Shaping.bounceIn(t * 2, c) / 2 : Shaping.bounceOut(t * 2 - 1, c) / 2 + c / 2;
2742
+ return t < 0.5 ? _Shaping.bounceIn(t * 2, c) / 2 : _Shaping.bounceOut(t * 2 - 1, c) / 2 + c / 2;
2743
2743
  }
2744
2744
  /**
2745
2745
  * Sigmoid curve changes its shape adapted from the input value, but always returns a value between 0 to 1.
@@ -2748,7 +2748,7 @@ var Shaping = class {
2748
2748
  * @param p the larger the value, the "steeper" the curve will be. Default is 10.
2749
2749
  */
2750
2750
  static sigmoid(t, c = 1, p = 10) {
2751
- let d = p * (t - 0.5);
2751
+ const d = p * (t - 0.5);
2752
2752
  return c / (1 + Math.exp(-d));
2753
2753
  }
2754
2754
  /**
@@ -2760,9 +2760,9 @@ var Shaping = class {
2760
2760
  static logSigmoid(t, c = 1, p = 0.7) {
2761
2761
  p = Math.max(Const.epsilon, Math.min(1 - Const.epsilon, p));
2762
2762
  p = 1 / (1 - p);
2763
- let A = 1 / (1 + Math.exp((t - 0.5) * p * -2));
2764
- let B = 1 / (1 + Math.exp(p));
2765
- let C = 1 / (1 + Math.exp(-p));
2763
+ const A = 1 / (1 + Math.exp((t - 0.5) * p * -2));
2764
+ const B = 1 / (1 + Math.exp(p));
2765
+ const C = 1 / (1 + Math.exp(-p));
2766
2766
  return c * (A - B) / (C - B);
2767
2767
  }
2768
2768
  /**
@@ -2785,13 +2785,13 @@ var Shaping = class {
2785
2785
  * @param p1 a Pt object specifying the first control Pt, or a value specifying the control Pt's x position (its y position will default to 0.5). Default is `Pt(0.95, 0.95)
2786
2786
  */
2787
2787
  static quadraticBezier(t, c = 1, p = [0.05, 0.95]) {
2788
- let a = typeof p != "number" ? p[0] : p;
2789
- let b = typeof p != "number" ? p[1] : 0.5;
2788
+ const a = typeof p != "number" ? p[0] : p;
2789
+ const b = typeof p != "number" ? p[1] : 0.5;
2790
2790
  let om2a = 1 - 2 * a;
2791
2791
  if (om2a === 0) {
2792
2792
  om2a = Const.epsilon;
2793
2793
  }
2794
- let d = (Math.sqrt(a * a + om2a * t) - a) / om2a;
2794
+ const d = (Math.sqrt(a * a + om2a * t) - a) / om2a;
2795
2795
  return c * ((1 - 2 * b) * (d * d) + 2 * b * d);
2796
2796
  }
2797
2797
  /**
@@ -2802,7 +2802,7 @@ var Shaping = class {
2802
2802
  * @param p2` a Pt object specifying the second control Pt. Default is `Pt(0.9, 0.2).
2803
2803
  */
2804
2804
  static cubicBezier(t, c = 1, p1 = [0.1, 0.7], p2 = [0.9, 0.2]) {
2805
- let curve = new Group(new Pt(0, 0), new Pt(p1), new Pt(p2), new Pt(1, 1));
2805
+ const curve = new Group(new Pt(0, 0), new Pt(p1), new Pt(p2), new Pt(1, 1));
2806
2806
  return c * Curve.bezierStep(new Pt(t * t * t, t * t, t, 1), Curve.controlPoints(curve)).y;
2807
2807
  }
2808
2808
  /**
@@ -2812,11 +2812,11 @@ var Shaping = class {
2812
2812
  * @param p1` a Pt object specifying the Pt to pass through. Default is `Pt(0.2, 0.35)
2813
2813
  */
2814
2814
  static quadraticTarget(t, c = 1, p1 = [0.2, 0.35]) {
2815
- let a = Math.min(1 - Const.epsilon, Math.max(Const.epsilon, p1[0]));
2816
- let b = Math.min(1, Math.max(0, p1[1]));
2817
- let A = (1 - b) / (1 - a) - b / a;
2818
- let B = (A * (a * a) - b) / a;
2819
- let y = A * (t * t) - B * t;
2815
+ const a = Math.min(1 - Const.epsilon, Math.max(Const.epsilon, p1[0]));
2816
+ const b = Math.min(1, Math.max(0, p1[1]));
2817
+ const A = (1 - b) / (1 - a) - b / a;
2818
+ const B = (A * (a * a) - b) / a;
2819
+ const y = A * (t * t) - B * t;
2820
2820
  return c * Math.min(1, Math.max(0, y));
2821
2821
  }
2822
2822
  /**
@@ -2837,8 +2837,8 @@ var Shaping = class {
2837
2837
  * @param args optional paramters to pass to original function
2838
2838
  */
2839
2839
  static step(fn, steps, t, c, ...args) {
2840
- let s = 1 / steps;
2841
- let tt = Math.floor(t / s) * s;
2840
+ const s = 1 / steps;
2841
+ const tt = Math.floor(t / s) * s;
2842
2842
  return fn(tt, c, ...args);
2843
2843
  }
2844
2844
  };
@@ -2876,16 +2876,16 @@ var Range = class {
2876
2876
  calc() {
2877
2877
  if (!this._source)
2878
2878
  return;
2879
- let dims = this._source[0].length;
2879
+ const dims = this._source[0].length;
2880
2880
  this._dims = dims;
2881
- let max = new Pt(dims);
2882
- let min = new Pt(dims);
2883
- let mag = new Pt(dims);
2881
+ const max = new Pt(dims);
2882
+ const min = new Pt(dims);
2883
+ const mag = new Pt(dims);
2884
2884
  for (let i = 0; i < dims; i++) {
2885
2885
  max[i] = Const.min;
2886
2886
  min[i] = Const.max;
2887
2887
  mag[i] = 0;
2888
- let s = this._source.zipSlice(i);
2888
+ const s = this._source.zipSlice(i);
2889
2889
  for (let k = 0, len = s.length; k < len; k++) {
2890
2890
  max[i] = Math.max(max[i], s[k]);
2891
2891
  min[i] = Math.min(min[i], s[k]);
@@ -2904,10 +2904,10 @@ var Range = class {
2904
2904
  * @param exclude Optional boolean array where `true` means excluding the conversion in that specific dimension.
2905
2905
  */
2906
2906
  mapTo(min, max, exclude) {
2907
- let target = new Group();
2907
+ const target = new Group();
2908
2908
  for (let i = 0, len = this._source.length; i < len; i++) {
2909
- let g = this._source[i];
2910
- let n = new Pt(this._dims);
2909
+ const g = this._source[i];
2910
+ const n = new Pt(this._dims);
2911
2911
  for (let k = 0; k < this._dims; k++) {
2912
2912
  n[k] = exclude && exclude[k] ? g[k] : Num.mapToRange(g[k], this._min[k], this._max[k], min, max);
2913
2913
  }
@@ -2921,7 +2921,7 @@ var Range = class {
2921
2921
  * @param update Optional. Set the parameter to `false` if you want to append without immediately updating this Range's min and max values. Default is `true`.
2922
2922
  */
2923
2923
  append(pts, update = true) {
2924
- let _pts = Util.iterToArray(pts);
2924
+ const _pts = Util.iterToArray(pts);
2925
2925
  if (_pts[0].length !== this._dims)
2926
2926
  throw new Error(`Dimensions don't match. ${this._dims} dimensions in Range and ${_pts[0].length} provided in parameter. `);
2927
2927
  this._source = this._source.concat(_pts);
@@ -2934,9 +2934,9 @@ var Range = class {
2934
2934
  * @param count number of subdivision. For example, 10 subdivision will return 11 tick values, which include first(min) and last(max) values.
2935
2935
  */
2936
2936
  ticks(count) {
2937
- let g = new Group();
2937
+ const g = new Group();
2938
2938
  for (let i = 0; i <= count; i++) {
2939
- let p = new Pt(this._dims);
2939
+ const p = new Pt(this._dims);
2940
2940
  for (let k = 0, len = this._max.length; k < len; k++) {
2941
2941
  p[k] = Num.lerp(this._min[k], this._max[k], i / count);
2942
2942
  }
@@ -3005,7 +3005,7 @@ var Const = {
3005
3005
  /** Gaussian constant (1 / Math.sqrt(2 * Math.PI)) */
3006
3006
  gaussian: 0.3989422804014327
3007
3007
  };
3008
- var _Util = class {
3008
+ var _Util = class _Util {
3009
3009
  /**
3010
3010
  * Set a global warning level setting. If no parameter is passed, this will return the current warn-level. See [`Util.warn`](#link).
3011
3011
  * @param lv a [`WarningType`](#link) option, where "error" will throw an error, "warn" will log in console, and "mute" will ignore the error.
@@ -3100,7 +3100,7 @@ var _Util = class {
3100
3100
  * @param flattenAsGroup a boolean to specify whether the return type should be a Group or Array. Default is `true` which returns a Group.
3101
3101
  */
3102
3102
  static flatten(pts, flattenAsGroup = true) {
3103
- let arr = flattenAsGroup ? new Group() : new Array();
3103
+ let arr = flattenAsGroup ? new Group() : [];
3104
3104
  return arr.concat.apply(arr, pts);
3105
3105
  }
3106
3106
  /**
@@ -3173,7 +3173,7 @@ var _Util = class {
3173
3173
  * @param callback a function to capture the data. It receives two parameters: a `response` as string, and a `success` status as boolean.
3174
3174
  */
3175
3175
  static load(url, callback) {
3176
- var request = new XMLHttpRequest();
3176
+ let request = new XMLHttpRequest();
3177
3177
  request.open("GET", url, true);
3178
3178
  request.onload = function() {
3179
3179
  if (request.status >= 200 && request.status < 400) {
@@ -3251,11 +3251,11 @@ var _Util = class {
3251
3251
  return /iPhone|iPad|Android/i.test(navigator.userAgent);
3252
3252
  }
3253
3253
  };
3254
+ _Util._warnLevel = "mute";
3254
3255
  var Util = _Util;
3255
- Util._warnLevel = "mute";
3256
3256
 
3257
3257
  // src/Pt.ts
3258
- var Pt = class extends Float32Array {
3258
+ var Pt = class _Pt extends Float32Array {
3259
3259
  /**
3260
3260
  * Create a Pt. If no parameter is provided, this will instantiate a Pt with 2 dimensions [0, 0].
3261
3261
  * Note that `new Pt(3)` will only instantiate Pt with length of 3 (ie, same as `new Float32Array(3)` ). If you need a Pt with 1 dimension of value 3, use `new Pt([3])`.
@@ -3278,7 +3278,7 @@ var Pt = class extends Float32Array {
3278
3278
  * @param randomize if `true`, randomize the value between 0 to default value
3279
3279
  */
3280
3280
  static make(dimensions, defaultValue = 0, randomize = false) {
3281
- let p = new Float32Array(dimensions);
3281
+ const p = new Float32Array(dimensions);
3282
3282
  if (defaultValue)
3283
3283
  p.fill(defaultValue);
3284
3284
  if (randomize) {
@@ -3286,7 +3286,7 @@ var Pt = class extends Float32Array {
3286
3286
  p[i] = p[i] * Num.random();
3287
3287
  }
3288
3288
  }
3289
- return new Pt(p);
3289
+ return new _Pt(p);
3290
3290
  }
3291
3291
  /**
3292
3292
  * ID string of this Pt
@@ -3337,7 +3337,7 @@ var Pt = class extends Float32Array {
3337
3337
  * Clone this Pt and return it as a new Pt.
3338
3338
  */
3339
3339
  clone() {
3340
- return new Pt(this);
3340
+ return new _Pt(this);
3341
3341
  }
3342
3342
  /**
3343
3343
  * Check if another Pt is equal to this Pt, within a threshold.
@@ -3356,7 +3356,7 @@ var Pt = class extends Float32Array {
3356
3356
  * @param args can be either a list of numbers, an array, a Pt, or an object with {x,y,z,w} properties
3357
3357
  */
3358
3358
  to(...args) {
3359
- let p = Util.getArgs(args);
3359
+ const p = Util.getArgs(args);
3360
3360
  for (let i = 0, len = Math.min(this.length, p.length); i < len; i++) {
3361
3361
  this[i] = p[i];
3362
3362
  }
@@ -3376,8 +3376,8 @@ var Pt = class extends Float32Array {
3376
3376
  * @param anchorFromPt If `true`, add it from this Pt's current position. Default is `false` which update the position from origin (0,0). See also [`Geom.rotate2D`](#link) for rotating a point from another anchor point.
3377
3377
  */
3378
3378
  toAngle(radian, magnitude, anchorFromPt = false) {
3379
- let m = magnitude != void 0 ? magnitude : this.magnitude();
3380
- let change = [Math.cos(radian) * m, Math.sin(radian) * m];
3379
+ const m = magnitude != void 0 ? magnitude : this.magnitude();
3380
+ const change = [Math.cos(radian) * m, Math.sin(radian) * m];
3381
3381
  return anchorFromPt ? this.add(change) : this.to(change);
3382
3382
  }
3383
3383
  /**
@@ -3387,7 +3387,7 @@ var Pt = class extends Float32Array {
3387
3387
  * @returns a resulting function that takes other parameters required in `fn`
3388
3388
  */
3389
3389
  op(fn) {
3390
- let self = this;
3390
+ const self = this;
3391
3391
  return (...params) => {
3392
3392
  return fn(self, ...params);
3393
3393
  };
@@ -3399,7 +3399,7 @@ var Pt = class extends Float32Array {
3399
3399
  * @returns an array of resulting functions
3400
3400
  */
3401
3401
  ops(fns) {
3402
- let _ops = [];
3402
+ const _ops = [];
3403
3403
  for (let i = 0, len = fns.length; i < len; i++) {
3404
3404
  _ops.push(this.op(fns[i]));
3405
3405
  }
@@ -3410,18 +3410,18 @@ var Pt = class extends Float32Array {
3410
3410
  * @param axis a string such as "xy" (use Const.xy) or an array to specify indices
3411
3411
  */
3412
3412
  $take(axis) {
3413
- let p = [];
3413
+ const p = [];
3414
3414
  for (let i = 0, len = axis.length; i < len; i++) {
3415
3415
  p.push(this[axis[i]] || 0);
3416
3416
  }
3417
- return new Pt(p);
3417
+ return new _Pt(p);
3418
3418
  }
3419
3419
  /**
3420
3420
  * Concatenate this Pt with addition dimensional values and return as a new Pt.
3421
3421
  * @param args can be either a list of numbers, an array, a Pt, or an object with {x,y,z,w} properties
3422
3422
  */
3423
3423
  $concat(...args) {
3424
- return new Pt(this.toArray().concat(Util.getArgs(args)));
3424
+ return new _Pt(this.toArray().concat(Util.getArgs(args)));
3425
3425
  }
3426
3426
  /**
3427
3427
  * Add scalar or vector values to this Pt.
@@ -3616,8 +3616,8 @@ var Pt = class extends Float32Array {
3616
3616
  * @param args can be either a list of numbers, an array, a Pt, or an object with {x,y,z,w} properties
3617
3617
  */
3618
3618
  $min(...args) {
3619
- let p = Util.getArgs(args);
3620
- let m = this.clone();
3619
+ const p = Util.getArgs(args);
3620
+ const m = this.clone();
3621
3621
  for (let i = 0, len = Math.min(this.length, p.length); i < len; i++) {
3622
3622
  m[i] = Math.min(this[i], p[i]);
3623
3623
  }
@@ -3628,8 +3628,8 @@ var Pt = class extends Float32Array {
3628
3628
  * @param args can be either a list of numbers, an array, a Pt, or an object with {x,y,z,w} properties
3629
3629
  */
3630
3630
  $max(...args) {
3631
- let p = Util.getArgs(args);
3632
- let m = this.clone();
3631
+ const p = Util.getArgs(args);
3632
+ const m = this.clone();
3633
3633
  for (let i = 0, len = Math.min(this.length, p.length); i < len; i++) {
3634
3634
  m[i] = Math.max(this[i], p[i]);
3635
3635
  }
@@ -3656,7 +3656,7 @@ var Pt = class extends Float32Array {
3656
3656
  * @param anchor optional anchor point to scale from
3657
3657
  */
3658
3658
  scale(scale, anchor) {
3659
- Geom.scale(this, scale, anchor || Pt.make(this.length, 0));
3659
+ Geom.scale(this, scale, anchor || _Pt.make(this.length, 0));
3660
3660
  return this;
3661
3661
  }
3662
3662
  /**
@@ -3666,7 +3666,7 @@ var Pt = class extends Float32Array {
3666
3666
  * @param axis optional string such as "yz" to specify a 2D plane
3667
3667
  */
3668
3668
  rotate2D(angle, anchor, axis) {
3669
- Geom.rotate2D(this, angle, anchor || Pt.make(this.length, 0), axis);
3669
+ Geom.rotate2D(this, angle, anchor || _Pt.make(this.length, 0), axis);
3670
3670
  return this;
3671
3671
  }
3672
3672
  /**
@@ -3676,7 +3676,7 @@ var Pt = class extends Float32Array {
3676
3676
  * @param axis optional string such as "yz" to specify a 2D plane
3677
3677
  */
3678
3678
  shear2D(scale, anchor, axis) {
3679
- Geom.shear2D(this, scale, anchor || Pt.make(this.length, 0), axis);
3679
+ Geom.shear2D(this, scale, anchor || _Pt.make(this.length, 0), axis);
3680
3680
  return this;
3681
3681
  }
3682
3682
  /**
@@ -3704,16 +3704,16 @@ var Pt = class extends Float32Array {
3704
3704
  * Convert this Pt to a Group as new Group([0,...], pt)
3705
3705
  */
3706
3706
  toGroup() {
3707
- return new Group(Pt.make(this.length), this.clone());
3707
+ return new Group(_Pt.make(this.length), this.clone());
3708
3708
  }
3709
3709
  /**
3710
3710
  * Convert this Pt to a Bound as new Group([0,...], pt)
3711
3711
  */
3712
3712
  toBound() {
3713
- return new Bound(Pt.make(this.length), this.clone());
3713
+ return new Bound(_Pt.make(this.length), this.clone());
3714
3714
  }
3715
3715
  };
3716
- var Group = class extends Array {
3716
+ var Group = class _Group extends Array {
3717
3717
  /**
3718
3718
  * Create a Group by passing an array of [`Pt`](#link). You may also create a Group using [`Group.fromArray`](#link) or [`Group.fromPtArray`](#link).
3719
3719
  * @param args an array of Pts
@@ -3782,7 +3782,7 @@ var Group = class extends Array {
3782
3782
  * Depp clone this group and its Pts.
3783
3783
  */
3784
3784
  clone() {
3785
- let group = new Group();
3785
+ const group = new _Group();
3786
3786
  for (let i = 0, len = this.length; i < len; i++) {
3787
3787
  group.push(this[i].clone());
3788
3788
  }
@@ -3794,9 +3794,9 @@ var Group = class extends Array {
3794
3794
  * @example `Group.fromArray( [[1,2], [3,4], [5,6]] )`
3795
3795
  */
3796
3796
  static fromArray(list) {
3797
- let g = new Group();
3798
- for (let li of list) {
3799
- let p = li instanceof Pt ? li : new Pt(li);
3797
+ const g = new _Group();
3798
+ for (const li of list) {
3799
+ const p = li instanceof Pt ? li : new Pt(li);
3800
3800
  g.push(p);
3801
3801
  }
3802
3802
  return g;
@@ -3806,7 +3806,7 @@ var Group = class extends Array {
3806
3806
  * @param list an Iterable<Pt>
3807
3807
  */
3808
3808
  static fromPtArray(list) {
3809
- return Group.from(list);
3809
+ return _Group.from(list);
3810
3810
  }
3811
3811
  /**
3812
3812
  * Split this Group into an array of sub-groups.
@@ -3815,7 +3815,7 @@ var Group = class extends Array {
3815
3815
  * @param loopBack if `true`, always go through the array till the end and loop back to the beginning to complete the segments if needed
3816
3816
  */
3817
3817
  split(chunkSize, stride, loopBack = false) {
3818
- let sp = Util.split(this, chunkSize, stride, loopBack);
3818
+ const sp = Util.split(this, chunkSize, stride, loopBack);
3819
3819
  return sp;
3820
3820
  }
3821
3821
  /**
@@ -3824,7 +3824,7 @@ var Group = class extends Array {
3824
3824
  * @param index the index position to insert into
3825
3825
  */
3826
3826
  insert(pts, index = 0) {
3827
- Group.prototype.splice.apply(this, [index, 0, ...pts]);
3827
+ _Group.prototype.splice.apply(this, [index, 0, ...pts]);
3828
3828
  return this;
3829
3829
  }
3830
3830
  /**
@@ -3834,8 +3834,8 @@ var Group = class extends Array {
3834
3834
  * @returns The items that are removed.
3835
3835
  */
3836
3836
  remove(index = 0, count = 1) {
3837
- let param = index < 0 ? [index * -1 - 1, count] : [index, count];
3838
- return Group.prototype.splice.apply(this, param);
3837
+ const param = index < 0 ? [index * -1 - 1, count] : [index, count];
3838
+ return _Group.prototype.splice.apply(this, param);
3839
3839
  }
3840
3840
  /**
3841
3841
  * Split this group into an array of sub-group segments.
@@ -3886,7 +3886,7 @@ var Group = class extends Array {
3886
3886
  * @returns a resulting function that takes other parameters required in `fn`
3887
3887
  */
3888
3888
  op(fn) {
3889
- let self = this;
3889
+ const self = this;
3890
3890
  return (...params) => {
3891
3891
  return fn(self, ...params);
3892
3892
  };
@@ -3898,7 +3898,7 @@ var Group = class extends Array {
3898
3898
  * @returns an array of resulting functions
3899
3899
  */
3900
3900
  ops(fns) {
3901
- let _ops = [];
3901
+ const _ops = [];
3902
3902
  for (let i = 0, len = fns.length; i < len; i++) {
3903
3903
  _ops.push(this.op(fns[i]));
3904
3904
  }
@@ -3910,9 +3910,9 @@ var Group = class extends Array {
3910
3910
  */
3911
3911
  interpolate(t) {
3912
3912
  t = Num.clamp(t, 0, 1);
3913
- let chunk = this.length - 1;
3914
- let tc = 1 / (this.length - 1);
3915
- let idx = Math.floor(t / tc);
3913
+ const chunk = this.length - 1;
3914
+ const tc = 1 / (this.length - 1);
3915
+ const idx = Math.floor(t / tc);
3916
3916
  return Geom.interpolate(this[idx], this[Math.min(this.length - 1, idx + 1)], (t - idx * tc) * chunk);
3917
3917
  }
3918
3918
  /**
@@ -3927,7 +3927,7 @@ var Group = class extends Array {
3927
3927
  * @param args can be either a list of numbers, an array, a Pt, or an object with {x,y,z,w} properties
3928
3928
  */
3929
3929
  moveTo(...args) {
3930
- let d = new Pt(Util.getArgs(args)).subtract(this[0]);
3930
+ const d = new Pt(Util.getArgs(args)).subtract(this[0]);
3931
3931
  this.moveBy(d);
3932
3932
  return this;
3933
3933
  }
@@ -4075,7 +4075,7 @@ var Group = class extends Array {
4075
4075
  return "Group[ " + this.reduce((p, c) => p + c.toString() + " ", "") + " ]";
4076
4076
  }
4077
4077
  };
4078
- var Bound = class extends Group {
4078
+ var Bound = class _Bound extends Group {
4079
4079
  /**
4080
4080
  * Create a Bound. This is similar to the Group constructor. You can also create a Bound via the static function [`Bound.fromGroup`](#link), or alternatively via the [Group.toBound](#link) function.
4081
4081
  * @param args a list of Pt as parameters
@@ -4096,7 +4096,7 @@ var Bound = class extends Group {
4096
4096
  * @returns a Bound object
4097
4097
  */
4098
4098
  static fromBoundingRect(rect) {
4099
- let b = new Bound(new Pt(rect.left || 0, rect.top || 0), new Pt(rect.right || 0, rect.bottom || 0));
4099
+ const b = new _Bound(new Pt(rect.left || 0, rect.top || 0), new Pt(rect.right || 0, rect.bottom || 0));
4100
4100
  if (rect.width && rect.height)
4101
4101
  b.size = new Pt(rect.width, rect.height);
4102
4102
  return b;
@@ -4106,10 +4106,10 @@ var Bound = class extends Group {
4106
4106
  * @param g a Group or an Iterable<PtLike>
4107
4107
  */
4108
4108
  static fromGroup(g) {
4109
- let _g = Util.iterToArray(g);
4109
+ const _g = Util.iterToArray(g);
4110
4110
  if (_g.length < 2)
4111
4111
  throw new Error("Cannot create a Bound from a group that has less than 2 Pt");
4112
- return new Bound(_g[0], _g[_g.length - 1]);
4112
+ return new _Bound(_g[0], _g[_g.length - 1]);
4113
4113
  }
4114
4114
  /**
4115
4115
  * Initiate the bound's properties.
@@ -4120,8 +4120,8 @@ var Bound = class extends Group {
4120
4120
  this._inited = true;
4121
4121
  }
4122
4122
  if (this.p1 && this.p2) {
4123
- let a = this.p1;
4124
- let b = this.p2;
4123
+ const a = this.p1;
4124
+ const b = this.p2;
4125
4125
  this.topLeft = a.$min(b);
4126
4126
  this._bottomRight = a.$max(b);
4127
4127
  this._updateSize();
@@ -4132,7 +4132,7 @@ var Bound = class extends Group {
4132
4132
  * Clone this bound and return a new one.
4133
4133
  */
4134
4134
  clone() {
4135
- return new Bound(this._topLeft.clone(), this._bottomRight.clone());
4135
+ return new _Bound(this._topLeft.clone(), this._bottomRight.clone());
4136
4136
  }
4137
4137
  /**
4138
4138
  * Recalculte size and center.
@@ -4165,7 +4165,7 @@ var Bound = class extends Group {
4165
4165
  * Recalculate based on center position and size.
4166
4166
  */
4167
4167
  _updatePosFromCenter() {
4168
- let half = this._size.$multiply(0.5);
4168
+ const half = this._size.$multiply(0.5);
4169
4169
  this._topLeft = this._center.$subtract(half);
4170
4170
  this._bottomRight = this._center.$add(half);
4171
4171
  }
@@ -4305,7 +4305,7 @@ var UIPointerActions = {
4305
4305
  contextmenu: "contextmenu",
4306
4306
  all: "all"
4307
4307
  };
4308
- var _UI = class {
4308
+ var _UI = class _UI {
4309
4309
  /**
4310
4310
  * Create an UI element. You may also create a new UI using one of the static helper like [`UI.fromRectangle`](#link) or [`UI.fromCircle`](#link).
4311
4311
  * @param group a Group or an Iterable<PtLike> that defines the UI's appearance
@@ -4541,8 +4541,8 @@ var _UI = class {
4541
4541
  }
4542
4542
  }
4543
4543
  };
4544
+ _UI._counter = 0;
4544
4545
  var UI = _UI;
4545
- UI._counter = 0;
4546
4546
  var UIButton = class extends UI {
4547
4547
  /**
4548
4548
  * Create an UIButton. A button has 2 states, "clicks" (number) and "hover" (boolean), which you can access through [`UI.state`](#link) function. You may also create a new UIButton using one of the static helper like [`UI.fromRectangle`](#link) or [`UI.fromCircle`](#link).
@@ -4567,7 +4567,7 @@ var UIButton = class extends UI {
4567
4567
  if (hover && !this._states.hover) {
4568
4568
  this.state("hover", true);
4569
4569
  UI._trigger(this._actions[UA.enter], this, pt, UA.enter, evt);
4570
- var _capID = this.hold(UA.move);
4570
+ let _capID = this.hold(UA.move);
4571
4571
  this._hoverID = this.on(UA.move, (t, p) => {
4572
4572
  if (!this._within(p) && !this.state("dragging")) {
4573
4573
  this.state("hover", false);
@@ -4618,7 +4618,7 @@ var UIButton = class extends UI {
4618
4618
  * @returns id numbers that refer to enter/leave handlers, for use in [`UIButton.offHover`](#link) or [`UI.off`](#link).
4619
4619
  */
4620
4620
  onHover(enter, leave) {
4621
- var ids = [void 0, void 0];
4621
+ let ids = [void 0, void 0];
4622
4622
  if (enter)
4623
4623
  ids[0] = this.on(UIPointerActions.enter, enter);
4624
4624
  if (leave)
@@ -4632,7 +4632,7 @@ var UIButton = class extends UI {
4632
4632
  * @returns an array of booleans indicating whether the handlers were removed successfully
4633
4633
  */
4634
4634
  offHover(enterID, leaveID) {
4635
- var s = [false, false];
4635
+ let s = [false, false];
4636
4636
  if (enterID === void 0 || enterID >= 0)
4637
4637
  s[0] = this.off(UIPointerActions.enter, enterID);
4638
4638
  if (leaveID === void 0 || leaveID >= 0)
@@ -4775,9 +4775,9 @@ var Space = class {
4775
4775
  * @param player an [`IPlayer`](#link) object with animate function, or a callback function `fn(time, ftime)`.
4776
4776
  */
4777
4777
  add(p) {
4778
- let player = typeof p == "function" ? { animate: p } : p;
4779
- let k = this.playerCount++;
4780
- let pid = player.animateID || this.id + k;
4778
+ const player = typeof p == "function" ? { animate: p } : p;
4779
+ const k = this.playerCount++;
4780
+ const pid = player.animateID || this.id + k;
4781
4781
  this.players[pid] = player;
4782
4782
  player.animateID = pid;
4783
4783
  if (player.resize && this.bound.inited)
@@ -4844,7 +4844,7 @@ var Space = class {
4844
4844
  if (this._refresh)
4845
4845
  this.clear();
4846
4846
  if (this._isReady) {
4847
- for (let k in this.players) {
4847
+ for (const k in this.players) {
4848
4848
  if (this.players[k].animate)
4849
4849
  this.players[k].animate(time, this._time.diff, this);
4850
4850
  }
@@ -4962,7 +4962,7 @@ var MultiTouchSpace = class extends Space {
4962
4962
  * Get the mouse or touch pointer that stores the last action.
4963
4963
  */
4964
4964
  get pointer() {
4965
- let p = this._pointer.clone();
4965
+ const p = this._pointer.clone();
4966
4966
  p.id = this._pointer.id;
4967
4967
  return p;
4968
4968
  }
@@ -5014,27 +5014,21 @@ var MultiTouchSpace = class extends Space {
5014
5014
  this._mouseOut = this._mouseOut.bind(this);
5015
5015
  this._mouseMove = this._mouseMove.bind(this);
5016
5016
  this._mouseClick = this._mouseClick.bind(this);
5017
- this._pointerDown = this._pointerDown.bind(this);
5018
- this._pointerUp = this._pointerUp.bind(this);
5019
5017
  this._contextMenu = this._contextMenu.bind(this);
5020
- this.bindCanvas("mousedown", this._mouseDown, {}, customTarget);
5021
- this.bindCanvas("pointerdown", this._pointerDown, {}, customTarget);
5022
- this.bindCanvas("mouseup", this._mouseUp, {}, customTarget);
5023
- this.bindCanvas("pointerup", this._pointerUp, {}, customTarget);
5024
- this.bindCanvas("mouseover", this._mouseOver, {}, customTarget);
5025
- this.bindCanvas("mouseout", this._mouseOut, {}, customTarget);
5026
- this.bindCanvas("mousemove", this._mouseMove, {}, customTarget);
5018
+ this.bindCanvas("pointerdown", this._mouseDown, {}, customTarget);
5019
+ this.bindCanvas("pointerup", this._mouseUp, {}, customTarget);
5020
+ this.bindCanvas("pointerover", this._mouseOver, {}, customTarget);
5021
+ this.bindCanvas("pointerout", this._mouseOut, {}, customTarget);
5022
+ this.bindCanvas("pointermove", this._mouseMove, {}, customTarget);
5027
5023
  this.bindCanvas("click", this._mouseClick, {}, customTarget);
5028
5024
  this.bindCanvas("contextmenu", this._contextMenu, {}, customTarget);
5029
5025
  this._hasMouse = true;
5030
5026
  } else {
5031
- this.unbindCanvas("mousedown", this._mouseDown, {}, customTarget);
5032
- this.unbindCanvas("pointerdown", this._pointerDown, {}, customTarget);
5033
- this.unbindCanvas("mouseup", this._mouseUp, {}, customTarget);
5034
- this.unbindCanvas("pointerup", this._pointerUp, {}, customTarget);
5035
- this.unbindCanvas("mouseover", this._mouseOver, {}, customTarget);
5036
- this.unbindCanvas("mouseout", this._mouseOut, {}, customTarget);
5037
- this.unbindCanvas("mousemove", this._mouseMove, {}, customTarget);
5027
+ this.unbindCanvas("pointerdown", this._mouseDown, {}, customTarget);
5028
+ this.unbindCanvas("pointerup", this._mouseUp, {}, customTarget);
5029
+ this.unbindCanvas("pointerover", this._mouseOver, {}, customTarget);
5030
+ this.unbindCanvas("pointerout", this._mouseOut, {}, customTarget);
5031
+ this.unbindCanvas("pointermove", this._mouseMove, {}, customTarget);
5038
5032
  this.unbindCanvas("click", this._mouseClick, {}, customTarget);
5039
5033
  this.unbindCanvas("contextmenu", this._contextMenu, {}, customTarget);
5040
5034
  this._hasMouse = false;
@@ -5089,9 +5083,9 @@ var MultiTouchSpace = class extends Space {
5089
5083
  touchesToPoints(evt, which = "touches") {
5090
5084
  if (!evt || !evt[which])
5091
5085
  return [];
5092
- let ts = [];
5093
- for (var i = 0; i < evt[which].length; i++) {
5094
- let t = evt[which].item(i);
5086
+ const ts = [];
5087
+ for (let i = 0; i < evt[which].length; i++) {
5088
+ const t = evt[which].item(i);
5095
5089
  ts.push(new Pt(t.pageX - this.bound.topLeft.x, t.pageY - this.bound.topLeft.y));
5096
5090
  }
5097
5091
  return ts;
@@ -5107,9 +5101,9 @@ var MultiTouchSpace = class extends Space {
5107
5101
  return;
5108
5102
  let px = 0, py = 0;
5109
5103
  if (evt instanceof MouseEvent) {
5110
- for (let k in this.players) {
5104
+ for (const k in this.players) {
5111
5105
  if (this.players.hasOwnProperty(k)) {
5112
- let v = this.players[k];
5106
+ const v = this.players[k];
5113
5107
  px = evt.pageX - this.outerBound.x;
5114
5108
  py = evt.pageY - this.outerBound.y;
5115
5109
  if (v.action)
@@ -5117,11 +5111,11 @@ var MultiTouchSpace = class extends Space {
5117
5111
  }
5118
5112
  }
5119
5113
  } else {
5120
- for (let k in this.players) {
5114
+ for (const k in this.players) {
5121
5115
  if (this.players.hasOwnProperty(k)) {
5122
- let v = this.players[k];
5123
- let c = evt.changedTouches && evt.changedTouches.length > 0;
5124
- let touch = evt.changedTouches.item(0);
5116
+ const v = this.players[k];
5117
+ const c = evt.changedTouches && evt.changedTouches.length > 0;
5118
+ const touch = evt.changedTouches.item(0);
5125
5119
  px = c ? touch.pageX - this.outerBound.x : 0;
5126
5120
  py = c ? touch.pageY - this.outerBound.y : 0;
5127
5121
  if (v.action)
@@ -5140,11 +5134,8 @@ var MultiTouchSpace = class extends Space {
5140
5134
  */
5141
5135
  _mouseDown(evt) {
5142
5136
  this._mouseAction(UIPointerActions.down, evt);
5143
- this._pressed = true;
5144
- return false;
5145
- }
5146
- _pointerDown(evt) {
5147
5137
  this._mouseAction(UIPointerActions.pointerdown, evt);
5138
+ this._pressed = true;
5148
5139
  if (evt.target instanceof Element) {
5149
5140
  evt.target.setPointerCapture(evt.pointerId);
5150
5141
  }
@@ -5155,6 +5146,7 @@ var MultiTouchSpace = class extends Space {
5155
5146
  * @param evt
5156
5147
  */
5157
5148
  _mouseUp(evt) {
5149
+ this._mouseAction(UIPointerActions.pointerup, evt);
5158
5150
  if (this._dragged) {
5159
5151
  this._mouseAction(UIPointerActions.drop, evt);
5160
5152
  } else {
@@ -5162,15 +5154,8 @@ var MultiTouchSpace = class extends Space {
5162
5154
  }
5163
5155
  this._pressed = false;
5164
5156
  this._dragged = false;
5165
- return false;
5166
- }
5167
- _pointerUp(evt) {
5168
- this._mouseAction(UIPointerActions.pointerup, evt);
5169
5157
  if (evt.target instanceof Element) {
5170
5158
  evt.target.releasePointerCapture(evt.pointerId);
5171
- if (this._dragged)
5172
- this._mouseAction(UIPointerActions.drop, evt);
5173
- this._dragged = false;
5174
5159
  }
5175
5160
  return false;
5176
5161
  }
@@ -5179,10 +5164,11 @@ var MultiTouchSpace = class extends Space {
5179
5164
  * @param evt
5180
5165
  */
5181
5166
  _mouseMove(evt) {
5182
- this._mouseAction(UIPointerActions.move, evt);
5183
5167
  if (this._pressed) {
5184
5168
  this._dragged = true;
5185
5169
  this._mouseAction(UIPointerActions.drag, evt);
5170
+ } else {
5171
+ this._mouseAction(UIPointerActions.move, evt);
5186
5172
  }
5187
5173
  return false;
5188
5174
  }
@@ -5228,7 +5214,11 @@ var MultiTouchSpace = class extends Space {
5228
5214
  * @param evt
5229
5215
  */
5230
5216
  _touchMove(evt) {
5231
- this._mouseMove(evt);
5217
+ this._mouseAction(UIPointerActions.move, evt);
5218
+ if (this._pressed) {
5219
+ this._dragged = true;
5220
+ this._mouseAction(UIPointerActions.drag, evt);
5221
+ }
5232
5222
  evt.preventDefault();
5233
5223
  return false;
5234
5224
  }
@@ -5237,7 +5227,9 @@ var MultiTouchSpace = class extends Space {
5237
5227
  * @param evt
5238
5228
  */
5239
5229
  _touchStart(evt) {
5240
- this._mouseDown(evt);
5230
+ this._mouseAction(UIPointerActions.down, evt);
5231
+ this._pressed = true;
5232
+ return false;
5241
5233
  evt.preventDefault();
5242
5234
  return false;
5243
5235
  }
@@ -5252,9 +5244,9 @@ var MultiTouchSpace = class extends Space {
5252
5244
  _keyboardAction(type, evt) {
5253
5245
  if (!this.isPlaying)
5254
5246
  return;
5255
- for (let k in this.players) {
5247
+ for (const k in this.players) {
5256
5248
  if (this.players.hasOwnProperty(k)) {
5257
- let v = this.players[k];
5249
+ const v = this.players[k];
5258
5250
  if (v.action)
5259
5251
  v.action(type, evt.shiftKey ? 1 : 0, evt.altKey ? 1 : 0, evt);
5260
5252
  }
@@ -5503,7 +5495,7 @@ var Typography = class {
5503
5495
  };
5504
5496
 
5505
5497
  // src/Image.ts
5506
- var Img = class {
5498
+ var Img = class _Img {
5507
5499
  /**
5508
5500
  * Create an Img
5509
5501
  * @param editable Specify if you want to manipulate pixels of this image. Default is `false`.
@@ -5528,7 +5520,7 @@ var Img = class {
5528
5520
  * @param ready An optional ready callback function
5529
5521
  */
5530
5522
  static load(src, editable = false, space, ready) {
5531
- const img = new Img(editable, space);
5523
+ const img = new _Img(editable, space);
5532
5524
  img.load(src).then((res) => {
5533
5525
  if (ready)
5534
5526
  ready(res);
@@ -5544,7 +5536,7 @@ var Img = class {
5544
5536
  */
5545
5537
  static loadAsync(src, editable = false, space) {
5546
5538
  return __async(this, null, function* () {
5547
- const img = yield new Img(editable, space).load(src);
5539
+ const img = yield new _Img(editable, space).load(src);
5548
5540
  return img;
5549
5541
  });
5550
5542
  }
@@ -5558,7 +5550,7 @@ var Img = class {
5558
5550
  */
5559
5551
  static loadPattern(src, space, repeat = "repeat", editable = false) {
5560
5552
  return __async(this, null, function* () {
5561
- const img = yield Img.loadAsync(src, editable, space);
5553
+ const img = yield _Img.loadAsync(src, editable, space);
5562
5554
  return img.pattern(repeat);
5563
5555
  });
5564
5556
  }
@@ -5569,7 +5561,7 @@ var Img = class {
5569
5561
  * @param scale Optionally set a specific pixel scale (density) of the image canvas.
5570
5562
  */
5571
5563
  static blank(size, space, scale) {
5572
- let img = new Img(true, space);
5564
+ let img = new _Img(true, space);
5573
5565
  const s = scale ? scale : space.pixelScale;
5574
5566
  img.initCanvas(size[0], size[1], s);
5575
5567
  return img;
@@ -5675,7 +5667,7 @@ var Img = class {
5675
5667
  */
5676
5668
  pixel(p, rescale = true) {
5677
5669
  const s = typeof rescale == "number" ? rescale : rescale ? this._scale : 1;
5678
- return Img.getPixel(this._data, [p[0] * s, p[1] * s]);
5670
+ return _Img.getPixel(this._data, [p[0] * s, p[1] * s]);
5679
5671
  }
5680
5672
  /**
5681
5673
  * Given an ImaegData object and a position, return the RGBA pixel value at that position.
@@ -5740,7 +5732,7 @@ var Img = class {
5740
5732
  */
5741
5733
  static fromBlob(blob, editable = false, space) {
5742
5734
  let url = URL.createObjectURL(blob);
5743
- return new Img(editable, space).load(url);
5735
+ return new _Img(editable, space).load(url);
5744
5736
  }
5745
5737
  /**
5746
5738
  * Convert ImageData object to a Blob, which you can then create an Img instance via [`Img.fromBlob`](#link). Note that the resulting image's dimensions will not account for pixel density.
@@ -5868,8 +5860,8 @@ var CanvasSpace2 = class extends MultiTouchSpace {
5868
5860
  this._bgcolor = "#e1e9f0";
5869
5861
  this._offscreen = false;
5870
5862
  this._initialResize = false;
5871
- var _selector = null;
5872
- var _existed = false;
5863
+ let _selector = null;
5864
+ let _existed = false;
5873
5865
  this.id = "pt";
5874
5866
  if (elem instanceof Element) {
5875
5867
  _selector = elem;
@@ -5906,7 +5898,7 @@ var CanvasSpace2 = class extends MultiTouchSpace {
5906
5898
  * @param id element id attribute
5907
5899
  */
5908
5900
  _createElement(elem = "div", id) {
5909
- let d = document.createElement(elem);
5901
+ const d = document.createElement(elem);
5910
5902
  d.setAttribute("id", id);
5911
5903
  return d;
5912
5904
  }
@@ -5921,7 +5913,7 @@ var CanvasSpace2 = class extends MultiTouchSpace {
5921
5913
  this._resizeHandler(null);
5922
5914
  this.clear(this._bgcolor);
5923
5915
  this._canvas.dispatchEvent(new Event("ready"));
5924
- for (let k in this.players) {
5916
+ for (const k in this.players) {
5925
5917
  if (this.players.hasOwnProperty(k)) {
5926
5918
  if (this.players[k].start)
5927
5919
  this.players[k].start(this.bound.clone(), this);
@@ -5941,8 +5933,8 @@ var CanvasSpace2 = class extends MultiTouchSpace {
5941
5933
  this._bgcolor = opt.bgcolor ? opt.bgcolor : "transparent";
5942
5934
  this.autoResize = opt.resize != void 0 ? opt.resize : false;
5943
5935
  if (opt.retina !== false) {
5944
- let r1 = window ? window.devicePixelRatio || 1 : 1;
5945
- let r2 = this._ctx.webkitBackingStorePixelRatio || this._ctx.mozBackingStorePixelRatio || this._ctx.msBackingStorePixelRatio || this._ctx.oBackingStorePixelRatio || this._ctx.backingStorePixelRatio || 1;
5936
+ const r1 = window ? window.devicePixelRatio || 1 : 1;
5937
+ const r2 = this._ctx.webkitBackingStorePixelRatio || this._ctx.mozBackingStorePixelRatio || this._ctx.msBackingStorePixelRatio || this._ctx.oBackingStorePixelRatio || this._ctx.backingStorePixelRatio || 1;
5946
5938
  this._pixelScale = Math.max(1, r1 / r2);
5947
5939
  }
5948
5940
  if (opt.offscreen) {
@@ -5996,9 +5988,9 @@ var CanvasSpace2 = class extends MultiTouchSpace {
5996
5988
  this._offCtx.scale(this._pixelScale, this._pixelScale);
5997
5989
  }
5998
5990
  }
5999
- for (let k in this.players) {
5991
+ for (const k in this.players) {
6000
5992
  if (this.players.hasOwnProperty(k)) {
6001
- let p = this.players[k];
5993
+ const p = this.players[k];
6002
5994
  if (p.resize)
6003
5995
  p.resize(this.bound, evt);
6004
5996
  }
@@ -6015,9 +6007,9 @@ var CanvasSpace2 = class extends MultiTouchSpace {
6015
6007
  _resizeHandler(evt) {
6016
6008
  if (!window)
6017
6009
  return;
6018
- let b = this._autoResize || this._initialResize ? this._container.getBoundingClientRect() : this._canvas.getBoundingClientRect();
6010
+ const b = this._autoResize || this._initialResize ? this._container.getBoundingClientRect() : this._canvas.getBoundingClientRect();
6019
6011
  if (b) {
6020
- let box = Bound.fromBoundingRect(b);
6012
+ const box = Bound.fromBoundingRect(b);
6021
6013
  box.center = box.center.add(window.pageXOffset, window.pageYOffset);
6022
6014
  this.resize(box, evt);
6023
6015
  }
@@ -6160,14 +6152,14 @@ var CanvasSpace2 = class extends MultiTouchSpace {
6160
6152
  * @example `let rec = space.recorder(true); rec.start(); setTimeout( () => rec.stop(), 5000); // record 5s of video and download the file`
6161
6153
  */
6162
6154
  recorder(downloadOrCallback, filetype = "webm", bitrate = 15e6) {
6163
- let stream = this._canvas.captureStream();
6155
+ const stream = this._canvas.captureStream();
6164
6156
  const recorder = new MediaRecorder(stream, { mimeType: `video/${filetype}`, bitsPerSecond: bitrate });
6165
6157
  recorder.ondataavailable = function(d) {
6166
- let url = URL.createObjectURL(new Blob([d.data], { type: `video/${filetype}` }));
6158
+ const url = URL.createObjectURL(new Blob([d.data], { type: `video/${filetype}` }));
6167
6159
  if (typeof downloadOrCallback === "function") {
6168
6160
  downloadOrCallback(url);
6169
6161
  } else if (downloadOrCallback) {
6170
- let a = document.createElement("a");
6162
+ const a = document.createElement("a");
6171
6163
  a.href = url;
6172
6164
  a.download = `canvas_video.${filetype}`;
6173
6165
  a.click();
@@ -6177,7 +6169,7 @@ var CanvasSpace2 = class extends MultiTouchSpace {
6177
6169
  return recorder;
6178
6170
  }
6179
6171
  };
6180
- var CanvasForm = class extends VisualForm {
6172
+ var CanvasForm = class _CanvasForm extends VisualForm {
6181
6173
  /**
6182
6174
  * Create a new CanvasForm. You may also use [`CanvasSpace.getForm()`](#link) to get the default form.
6183
6175
  * @param space an instance of CanvasSpace
@@ -6254,20 +6246,20 @@ var CanvasForm = class extends VisualForm {
6254
6246
  }
6255
6247
  }
6256
6248
  /**
6257
- * Set current alpha value.
6258
- * @example `form.alpha(0.6)`
6259
- * @param a alpha value between 0 and 1
6260
- */
6249
+ * Set current alpha value.
6250
+ * @example `form.alpha(0.6)`
6251
+ * @param a alpha value between 0 and 1
6252
+ */
6261
6253
  alpha(a) {
6262
6254
  this._ctx.globalAlpha = a;
6263
6255
  this._style.globalAlpha = a;
6264
6256
  return this;
6265
6257
  }
6266
6258
  /**
6267
- * Set current fill style. Provide a valid color string such as `"#FFF"` or `"rgba(255,0,100,0.5)"` or `false` to specify no fill color.
6268
- * @example `form.fill("#F90")`, `form.fill("rgba(0,0,0,.5")`, `form.fill(false)`
6269
- * @param c fill color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle))
6270
- */
6259
+ * Set current fill style. Provide a valid color string such as `"#FFF"` or `"rgba(255,0,100,0.5)"` or `false` to specify no fill color.
6260
+ * @example `form.fill("#F90")`, `form.fill("rgba(0,0,0,.5")`, `form.fill(false)`
6261
+ * @param c fill color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle))
6262
+ */
6271
6263
  fill(c) {
6272
6264
  if (typeof c == "boolean") {
6273
6265
  this.filled = c;
@@ -6279,21 +6271,21 @@ var CanvasForm = class extends VisualForm {
6279
6271
  return this;
6280
6272
  }
6281
6273
  /**
6282
- * Set current fill style and remove stroke style.
6283
- * @param c fill color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle))
6284
- */
6274
+ * Set current fill style and remove stroke style.
6275
+ * @param c fill color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle))
6276
+ */
6285
6277
  fillOnly(c) {
6286
6278
  this.stroke(false);
6287
6279
  return this.fill(c);
6288
6280
  }
6289
6281
  /**
6290
- * Set current stroke style. Provide a valid color string or `false` to specify no stroke color.
6291
- * @example `form.stroke("#F90")`, `form.stroke("rgba(0,0,0,.5")`, `form.stroke(false)`, `form.stroke("#000", 0.5, 'round', 'square')`
6292
- * @param c stroke color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/strokeStyle))
6293
- * @param width Optional value (can be floating point) to set line width
6294
- * @param linejoin Optional string to set line joint style. Can be "miter", "bevel", or "round".
6295
- * @param linecap Optional string to set line cap style. Can be "butt", "round", or "square".
6296
- */
6282
+ * Set current stroke style. Provide a valid color string or `false` to specify no stroke color.
6283
+ * @example `form.stroke("#F90")`, `form.stroke("rgba(0,0,0,.5")`, `form.stroke(false)`, `form.stroke("#000", 0.5, 'round', 'square')`
6284
+ * @param c stroke color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/strokeStyle))
6285
+ * @param width Optional value (can be floating point) to set line width
6286
+ * @param linejoin Optional string to set line joint style. Can be "miter", "bevel", or "round".
6287
+ * @param linecap Optional string to set line cap style. Can be "butt", "round", or "square".
6288
+ */
6297
6289
  stroke(c, width, linejoin, linecap) {
6298
6290
  if (typeof c == "boolean") {
6299
6291
  this.stroked = c;
@@ -6317,24 +6309,24 @@ var CanvasForm = class extends VisualForm {
6317
6309
  return this;
6318
6310
  }
6319
6311
  /**
6320
- * Set stroke style and remove fill style.
6321
- * @param c stroke color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/strokeStyle))
6322
- * @param width Optional value (can be floating point) to set line width
6323
- * @param linejoin Optional string to set line joint style. Can be "miter", "bevel", or "round".
6324
- * @param linecap Optional string to set line cap style. Can be "butt", "round", or "square".
6325
- */
6312
+ * Set stroke style and remove fill style.
6313
+ * @param c stroke color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/strokeStyle))
6314
+ * @param width Optional value (can be floating point) to set line width
6315
+ * @param linejoin Optional string to set line joint style. Can be "miter", "bevel", or "round".
6316
+ * @param linecap Optional string to set line cap style. Can be "butt", "round", or "square".
6317
+ */
6326
6318
  strokeOnly(c, width, linejoin, linecap) {
6327
6319
  this.fill(false);
6328
6320
  return this.stroke(c, width, linejoin, linecap);
6329
6321
  }
6330
6322
  /**
6331
- * A convenient function to apply fill and/or stroke after custom drawings using canvas context (eg, `form.ctx.ellipse(...)`).
6332
- * You don't need to call this function if you're using Pts' drawing functions like `form.point` or `form.rect`
6333
- * @param filled apply fill when set to `true`
6334
- * @param stroked apply stroke when set to `true`
6335
- * @param strokeWidth optionally set a stroke width
6336
- * @example `form.ctx.beginPath(); form.ctx.ellipse(...); form.applyFillStroke();`
6337
- */
6323
+ * A convenient function to apply fill and/or stroke after custom drawings using canvas context (eg, `form.ctx.ellipse(...)`).
6324
+ * You don't need to call this function if you're using Pts' drawing functions like `form.point` or `form.rect`
6325
+ * @param filled apply fill when set to `true`
6326
+ * @param stroked apply stroke when set to `true`
6327
+ * @param strokeWidth optionally set a stroke width
6328
+ * @example `form.ctx.beginPath(); form.ctx.ellipse(...); form.applyFillStroke();`
6329
+ */
6338
6330
  applyFillStroke(filled = true, stroked = true, strokeWidth = 1) {
6339
6331
  if (filled) {
6340
6332
  if (typeof filled === "string")
@@ -6349,22 +6341,22 @@ var CanvasForm = class extends VisualForm {
6349
6341
  return this;
6350
6342
  }
6351
6343
  /**
6352
- * This function takes an array of gradient colors, and returns a function to define the areas of the gradient fill. See demo code in [CanvasForm.gradient](https://ptsjs.org/demo/?name=canvasform.textBox).
6353
- * @param stops an array of gradient stops. This can be an array of colors `["#f00", "#0f0", ...]` for evenly distributed gradient, or an array of [stop, color] like `[[0.1, "#f00"], [0.7, "#0f0"]]`
6354
- * @returns a function that takes 1 or 2 `Group` as parameters. Use a single `Group` to specify a rectangular area for linear gradient, or use 2 `Groups` to specify 2 `Circles` for radial gradient.
6355
- * @example `c1 = Circle.fromCenter(...); grad = form.gradient(["#f00", "#00f"]); form.fill( grad( c1, c2 ) ).circle( c1 )`
6356
- */
6344
+ * This function takes an array of gradient colors, and returns a function to define the areas of the gradient fill. See demo code in [CanvasForm.gradient](https://ptsjs.org/demo/?name=canvasform.textBox).
6345
+ * @param stops an array of gradient stops. This can be an array of colors `["#f00", "#0f0", ...]` for evenly distributed gradient, or an array of [stop, color] like `[[0.1, "#f00"], [0.7, "#0f0"]]`
6346
+ * @returns a function that takes 1 or 2 `Group` as parameters. Use a single `Group` to specify a rectangular area for linear gradient, or use 2 `Groups` to specify 2 `Circles` for radial gradient.
6347
+ * @example `c1 = Circle.fromCenter(...); grad = form.gradient(["#f00", "#00f"]); form.fill( grad( c1, c2 ) ).circle( c1 )`
6348
+ */
6357
6349
  gradient(stops) {
6358
- let vals = [];
6350
+ const vals = [];
6359
6351
  if (stops.length < 2)
6360
6352
  stops.push([0.99, "#000"], [1, "#000"]);
6361
6353
  for (let i = 0, len = stops.length; i < len; i++) {
6362
- let t = typeof stops[i] === "string" ? i * (1 / (stops.length - 1)) : stops[i][0];
6363
- let v = typeof stops[i] === "string" ? stops[i] : stops[i][1];
6354
+ const t = typeof stops[i] === "string" ? i * (1 / (stops.length - 1)) : stops[i][0];
6355
+ const v = typeof stops[i] === "string" ? stops[i] : stops[i][1];
6364
6356
  vals.push([t, v]);
6365
6357
  }
6366
6358
  return (area1, area2) => {
6367
- let grad = area2 ? this._ctx.createRadialGradient(area1[0][0], area1[0][1], Math.abs(area1[1][0]), area2[0][0], area2[0][1], Math.abs(area2[1][0])) : this._ctx.createLinearGradient(area1[0][0], area1[0][1], area1[1][0], area1[1][1]);
6359
+ const grad = area2 ? this._ctx.createRadialGradient(area1[0][0], area1[0][1], Math.abs(area1[1][0]), area2[0][0], area2[0][1], Math.abs(area2[1][0])) : this._ctx.createLinearGradient(area1[0][0], area1[0][1], area1[1][0], area1[1][1]);
6368
6360
  for (let i = 0, len = vals.length; i < len; i++) {
6369
6361
  grad.addColorStop(vals[i][0], vals[i][1]);
6370
6362
  }
@@ -6372,26 +6364,26 @@ var CanvasForm = class extends VisualForm {
6372
6364
  };
6373
6365
  }
6374
6366
  /**
6375
- * Set composite operation (also known as blend mode). You can also call this function without parameters to get back to default 'source-over' mode. See [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation) for the full list of operations you can use.
6376
- * @param mode a composite operation such as 'lighten', 'multiply', 'overlay', and 'color-burn'.
6377
- */
6367
+ * Set composite operation (also known as blend mode). You can also call this function without parameters to get back to default 'source-over' mode. See [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation) for the full list of operations you can use.
6368
+ * @param mode a composite operation such as 'lighten', 'multiply', 'overlay', and 'color-burn'.
6369
+ */
6378
6370
  composite(mode = "source-over") {
6379
6371
  this._ctx.globalCompositeOperation = mode;
6380
6372
  return this;
6381
6373
  }
6382
6374
  /**
6383
- * Create a clipping mask from the current path. See [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clip) for details.
6384
- */
6375
+ * Create a clipping mask from the current path. See [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clip) for details.
6376
+ */
6385
6377
  clip() {
6386
6378
  this._ctx.clip();
6387
6379
  return this;
6388
6380
  }
6389
6381
  /**
6390
- * Activate dashed stroke and set dash style. You can customize the segments and offset.
6391
- * @example `form.dash()`, `form.dash([5, 10])`, `form.dash([5, 5], 5)`, `form.dash(false)`
6392
- * @param segments Dash segments. Defaults to `true` which corresponds to `[5, 5]`. Pass `false` to deactivate dashes. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash))
6393
- * @param offset Dash offset. Defaults to 0. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset)
6394
- */
6382
+ * Activate dashed stroke and set dash style. You can customize the segments and offset.
6383
+ * @example `form.dash()`, `form.dash([5, 10])`, `form.dash([5, 5], 5)`, `form.dash(false)`
6384
+ * @param segments Dash segments. Defaults to `true` which corresponds to `[5, 5]`. Pass `false` to deactivate dashes. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash))
6385
+ * @param offset Dash offset. Defaults to 0. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset)
6386
+ */
6395
6387
  dash(segments = true, offset = 0) {
6396
6388
  if (!segments) {
6397
6389
  this._ctx.setLineDash([]);
@@ -6406,14 +6398,14 @@ var CanvasForm = class extends VisualForm {
6406
6398
  return this;
6407
6399
  }
6408
6400
  /**
6409
- * Set the current font.
6410
- * @param sizeOrFont either a number to specify font-size, or a `Font` object to specify all font properties
6411
- * @param weight Optional font-weight string such as "bold"
6412
- * @param style Optional font-style string such as "italic"
6413
- * @param lineHeight Optional line-height number suchas 1.5
6414
- * @param family Optional font-family such as "Helvetica, sans-serif"
6415
- * @example `form.font( myFont )`, `form.font(14, "bold")`
6416
- */
6401
+ * Set the current font.
6402
+ * @param sizeOrFont either a number to specify font-size, or a `Font` object to specify all font properties
6403
+ * @param weight Optional font-weight string such as "bold"
6404
+ * @param style Optional font-style string such as "italic"
6405
+ * @param lineHeight Optional line-height number suchas 1.5
6406
+ * @param family Optional font-family such as "Helvetica, sans-serif"
6407
+ * @example `form.font( myFont )`, `form.font(14, "bold")`
6408
+ */
6417
6409
  font(sizeOrFont, weight, style, lineHeight, family) {
6418
6410
  if (typeof sizeOrFont == "number") {
6419
6411
  this._font.size = sizeOrFont;
@@ -6434,49 +6426,49 @@ var CanvasForm = class extends VisualForm {
6434
6426
  return this;
6435
6427
  }
6436
6428
  /**
6437
- * Set whether to use html canvas' [`measureText`](#link) function, or a faster but less accurate heuristic function.
6438
- * @param estimate `true` to use heuristic function, or `false` to use ctx.measureText
6439
- */
6429
+ * Set whether to use html canvas' [`measureText`](#link) function, or a faster but less accurate heuristic function.
6430
+ * @param estimate `true` to use heuristic function, or `false` to use ctx.measureText
6431
+ */
6440
6432
  fontWidthEstimate(estimate = true) {
6441
6433
  this._estimateTextWidth = estimate ? Typography.textWidthEstimator((c) => this._ctx.measureText(c).width) : void 0;
6442
6434
  return this;
6443
6435
  }
6444
6436
  /**
6445
- * Get the width of this text. It will return an actual measurement or an estimate based on [`fontWidthEstimate`](#link) setting. Default is an actual measurement using canvas context's measureText.
6446
- * @param c a string of text contents
6447
- */
6437
+ * Get the width of this text. It will return an actual measurement or an estimate based on [`fontWidthEstimate`](#link) setting. Default is an actual measurement using canvas context's measureText.
6438
+ * @param c a string of text contents
6439
+ */
6448
6440
  getTextWidth(c) {
6449
6441
  return !this._estimateTextWidth ? this._ctx.measureText(c + " .").width : this._estimateTextWidth(c);
6450
6442
  }
6451
6443
  /**
6452
- * Truncate text to fit width.
6453
- * @param str text to truncate
6454
- * @param width width to fit
6455
- * @param tail text to indicate overflow such as "...". Default is empty "".
6456
- */
6444
+ * Truncate text to fit width.
6445
+ * @param str text to truncate
6446
+ * @param width width to fit
6447
+ * @param tail text to indicate overflow such as "...". Default is empty "".
6448
+ */
6457
6449
  _textTruncate(str, width, tail = "") {
6458
6450
  return Typography.truncate(this.getTextWidth.bind(this), str, width, tail);
6459
6451
  }
6460
6452
  /**
6461
- * Align text within a rectangle box.
6462
- * @param box a Group or an Iterable<PtLike> that defines a rectangular box
6463
- * @param vertical a string that specifies the vertical alignment in the box: "top", "bottom", "middle", "start", "end"
6464
- * @param offset Optional offset from the edge (like padding)
6465
- * @param center Optional center position
6466
- */
6453
+ * Align text within a rectangle box.
6454
+ * @param box a Group or an Iterable<PtLike> that defines a rectangular box
6455
+ * @param vertical a string that specifies the vertical alignment in the box: "top", "bottom", "middle", "start", "end"
6456
+ * @param offset Optional offset from the edge (like padding)
6457
+ * @param center Optional center position
6458
+ */
6467
6459
  _textAlign(box, vertical, offset, center) {
6468
- let _box = Util.iterToArray(box);
6460
+ const _box = Util.iterToArray(box);
6469
6461
  if (!Util.arrayCheck(_box))
6470
6462
  return;
6471
6463
  if (!center)
6472
6464
  center = Rectangle.center(_box);
6473
- var px = _box[0][0];
6465
+ let px = _box[0][0];
6474
6466
  if (this._ctx.textAlign == "end" || this._ctx.textAlign == "right") {
6475
6467
  px = _box[1][0];
6476
6468
  } else if (this._ctx.textAlign == "center" || this._ctx.textAlign == "middle") {
6477
6469
  px = center[0];
6478
6470
  }
6479
- var py = center[1];
6471
+ let py = center[1];
6480
6472
  if (vertical == "top" || vertical == "start") {
6481
6473
  py = _box[0][1];
6482
6474
  } else if (vertical == "end" || vertical == "bottom") {
@@ -6485,10 +6477,10 @@ var CanvasForm = class extends VisualForm {
6485
6477
  return offset ? new Pt(px + offset[0], py + offset[1]) : new Pt(px, py);
6486
6478
  }
6487
6479
  /**
6488
- * Reset the rendering context's common styles to this form's styles. This supports using multiple forms on the same canvas context.
6489
- */
6480
+ * Reset the rendering context's common styles to this form's styles. This supports using multiple forms on the same canvas context.
6481
+ */
6490
6482
  reset() {
6491
- for (let k in this._style) {
6483
+ for (const k in this._style) {
6492
6484
  if (this._style.hasOwnProperty(k)) {
6493
6485
  this._ctx[k] = this._style[k];
6494
6486
  }
@@ -6504,38 +6496,38 @@ var CanvasForm = class extends VisualForm {
6504
6496
  this._ctx.stroke();
6505
6497
  }
6506
6498
  /**
6507
- * A static function to draw a point.
6508
- * @param ctx canvas rendering context
6509
- * @param p a Pt object
6510
- * @param radius radius of the point. Default is 5.
6511
- * @param shape The shape of the point. Defaults to "square", but it can be "circle" or a custom shape function in your own implementation.
6512
- * @example `form.point( p )`, `form.point( p, 10, "circle" )`
6513
- */
6499
+ * A static function to draw a point.
6500
+ * @param ctx canvas rendering context
6501
+ * @param p a Pt object
6502
+ * @param radius radius of the point. Default is 5.
6503
+ * @param shape The shape of the point. Defaults to "square", but it can be "circle" or a custom shape function in your own implementation.
6504
+ * @example `form.point( p )`, `form.point( p, 10, "circle" )`
6505
+ */
6514
6506
  static point(ctx, p, radius = 5, shape = "square") {
6515
6507
  if (!p)
6516
6508
  return;
6517
- if (!CanvasForm[shape])
6509
+ if (!_CanvasForm[shape])
6518
6510
  throw new Error(`${shape} is not a static function of CanvasForm`);
6519
- CanvasForm[shape](ctx, p, radius);
6511
+ _CanvasForm[shape](ctx, p, radius);
6520
6512
  }
6521
6513
  /**
6522
- * Draws a point.
6523
- * @param p a Pt object
6524
- * @param radius radius of the point. Default is 5.
6525
- * @param shape The shape of the point. Defaults to "square", but it can be "circle" or a custom shape function in your own implementation.
6526
- * @example `form.point( p )`, `form.point( p, 10, "circle" )`
6527
- */
6514
+ * Draws a point.
6515
+ * @param p a Pt object
6516
+ * @param radius radius of the point. Default is 5.
6517
+ * @param shape The shape of the point. Defaults to "square", but it can be "circle" or a custom shape function in your own implementation.
6518
+ * @example `form.point( p )`, `form.point( p, 10, "circle" )`
6519
+ */
6528
6520
  point(p, radius = 5, shape = "square") {
6529
- CanvasForm.point(this._ctx, p, radius, shape);
6521
+ _CanvasForm.point(this._ctx, p, radius, shape);
6530
6522
  this._paint();
6531
6523
  return this;
6532
6524
  }
6533
6525
  /**
6534
- * A static function to draw a circle.
6535
- * @param ctx canvas rendering context
6536
- * @param pt center position of the circle
6537
- * @param radius radius of the circle
6538
- */
6526
+ * A static function to draw a circle.
6527
+ * @param ctx canvas rendering context
6528
+ * @param pt center position of the circle
6529
+ * @param radius radius of the circle
6530
+ */
6539
6531
  static circle(ctx, pt, radius = 10) {
6540
6532
  if (!pt)
6541
6533
  return;
@@ -6544,25 +6536,25 @@ var CanvasForm = class extends VisualForm {
6544
6536
  ctx.closePath();
6545
6537
  }
6546
6538
  /**
6547
- * Draw a circle. See also [`Circle.fromCenter`](#link)
6548
- * @param pts usually a Group or an Iterable<PtLike> with 2 Pt, but it can also take an array of two numeric arrays [ [position], [size] ]
6549
- */
6539
+ * Draw a circle. See also [`Circle.fromCenter`](#link)
6540
+ * @param pts usually a Group or an Iterable<PtLike> with 2 Pt, but it can also take an array of two numeric arrays [ [position], [size] ]
6541
+ */
6550
6542
  circle(pts) {
6551
- let p = Util.iterToArray(pts);
6552
- CanvasForm.circle(this._ctx, p[0], p[1][0]);
6543
+ const p = Util.iterToArray(pts);
6544
+ _CanvasForm.circle(this._ctx, p[0], p[1][0]);
6553
6545
  this._paint();
6554
6546
  return this;
6555
6547
  }
6556
6548
  /**
6557
- * A static function to draw an ellipse.
6558
- * @param ctx canvas rendering context
6559
- * @param pt center position
6560
- * @param radius radius [x, y] of the ellipse
6561
- * @param rotation rotation of the ellipse in radian. Default is 0.
6562
- * @param startAngle start angle of the ellipse. Default is 0.
6563
- * @param endAngle end angle of the ellipse. Default is 2 PI.
6564
- * @param cc an optional boolean value to specify if it should be drawn clockwise (`false`) or counter-clockwise (`true`). Default is clockwise.
6565
- */
6549
+ * A static function to draw an ellipse.
6550
+ * @param ctx canvas rendering context
6551
+ * @param pt center position
6552
+ * @param radius radius [x, y] of the ellipse
6553
+ * @param rotation rotation of the ellipse in radian. Default is 0.
6554
+ * @param startAngle start angle of the ellipse. Default is 0.
6555
+ * @param endAngle end angle of the ellipse. Default is 2 PI.
6556
+ * @param cc an optional boolean value to specify if it should be drawn clockwise (`false`) or counter-clockwise (`true`). Default is clockwise.
6557
+ */
6566
6558
  static ellipse(ctx, pt, radius, rotation = 0, startAngle = 0, endAngle = Const.two_pi, cc = false) {
6567
6559
  if (!pt || !radius)
6568
6560
  return;
@@ -6570,28 +6562,28 @@ var CanvasForm = class extends VisualForm {
6570
6562
  ctx.ellipse(pt[0], pt[1], radius[0], radius[1], rotation, startAngle, endAngle, cc);
6571
6563
  }
6572
6564
  /**
6573
- * Draw an ellipse.
6574
- * @param pt center position
6575
- * @param radius radius [x, y] of the ellipse
6576
- * @param rotation rotation of the ellipse in radian. Default is 0.
6577
- * @param startAngle start angle of the ellipse. Default is 0.
6578
- * @param endAngle end angle of the ellipse. Default is 2 PI.
6579
- * @param cc an optional boolean value to specify if it should be drawn clockwise (`false`) or counter-clockwise (`true`). Default is clockwise.
6580
- */
6565
+ * Draw an ellipse.
6566
+ * @param pt center position
6567
+ * @param radius radius [x, y] of the ellipse
6568
+ * @param rotation rotation of the ellipse in radian. Default is 0.
6569
+ * @param startAngle start angle of the ellipse. Default is 0.
6570
+ * @param endAngle end angle of the ellipse. Default is 2 PI.
6571
+ * @param cc an optional boolean value to specify if it should be drawn clockwise (`false`) or counter-clockwise (`true`). Default is clockwise.
6572
+ */
6581
6573
  ellipse(pt, radius, rotation = 0, startAngle = 0, endAngle = Const.two_pi, cc = false) {
6582
- CanvasForm.ellipse(this._ctx, pt, radius, rotation, startAngle, endAngle, cc);
6574
+ _CanvasForm.ellipse(this._ctx, pt, radius, rotation, startAngle, endAngle, cc);
6583
6575
  this._paint();
6584
6576
  return this;
6585
6577
  }
6586
6578
  /**
6587
- * A static function to draw an arc.
6588
- * @param ctx canvas rendering context
6589
- * @param pt center position
6590
- * @param radius radius of the arc circle
6591
- * @param startAngle start angle of the arc
6592
- * @param endAngle end angle of the arc
6593
- * @param cc an optional boolean value to specify if it should be drawn clockwise (`false`) or counter-clockwise (`true`). Default is clockwise.
6594
- */
6579
+ * A static function to draw an arc.
6580
+ * @param ctx canvas rendering context
6581
+ * @param pt center position
6582
+ * @param radius radius of the arc circle
6583
+ * @param startAngle start angle of the arc
6584
+ * @param endAngle end angle of the arc
6585
+ * @param cc an optional boolean value to specify if it should be drawn clockwise (`false`) or counter-clockwise (`true`). Default is clockwise.
6586
+ */
6595
6587
  static arc(ctx, pt, radius, startAngle, endAngle, cc) {
6596
6588
  if (!pt)
6597
6589
  return;
@@ -6599,31 +6591,31 @@ var CanvasForm = class extends VisualForm {
6599
6591
  ctx.arc(pt[0], pt[1], radius, startAngle, endAngle, cc);
6600
6592
  }
6601
6593
  /**
6602
- * Draw an arc.
6603
- * @param pt center position
6604
- * @param radius radius of the arc circle
6605
- * @param startAngle start angle of the arc
6606
- * @param endAngle end angle of the arc
6607
- * @param cc an optional boolean value to specify if it should be drawn clockwise (`false`) or counter-clockwise (`true`). Default is clockwise.
6608
- */
6594
+ * Draw an arc.
6595
+ * @param pt center position
6596
+ * @param radius radius of the arc circle
6597
+ * @param startAngle start angle of the arc
6598
+ * @param endAngle end angle of the arc
6599
+ * @param cc an optional boolean value to specify if it should be drawn clockwise (`false`) or counter-clockwise (`true`). Default is clockwise.
6600
+ */
6609
6601
  arc(pt, radius, startAngle, endAngle, cc) {
6610
- CanvasForm.arc(this._ctx, pt, radius, startAngle, endAngle, cc);
6602
+ _CanvasForm.arc(this._ctx, pt, radius, startAngle, endAngle, cc);
6611
6603
  this._paint();
6612
6604
  return this;
6613
6605
  }
6614
6606
  /**
6615
- * A static function to draw a square.
6616
- * @param ctx canvas rendering context
6617
- * @param pt center position of the square
6618
- * @param halfsize half size of the square
6619
- */
6607
+ * A static function to draw a square.
6608
+ * @param ctx canvas rendering context
6609
+ * @param pt center position of the square
6610
+ * @param halfsize half size of the square
6611
+ */
6620
6612
  static square(ctx, pt, halfsize) {
6621
6613
  if (!pt)
6622
6614
  return;
6623
- let x1 = pt[0] - halfsize;
6624
- let y1 = pt[1] - halfsize;
6625
- let x2 = pt[0] + halfsize;
6626
- let y2 = pt[1] + halfsize;
6615
+ const x1 = pt[0] - halfsize;
6616
+ const y1 = pt[1] - halfsize;
6617
+ const x2 = pt[0] + halfsize;
6618
+ const y2 = pt[1] + halfsize;
6627
6619
  ctx.beginPath();
6628
6620
  ctx.moveTo(x1, y1);
6629
6621
  ctx.lineTo(x1, y2);
@@ -6632,26 +6624,26 @@ var CanvasForm = class extends VisualForm {
6632
6624
  ctx.closePath();
6633
6625
  }
6634
6626
  /**
6635
- * Draw a square, given a center and its half-size.
6636
- * @param pt center Pt
6637
- * @param halfsize half-size
6638
- */
6627
+ * Draw a square, given a center and its half-size.
6628
+ * @param pt center Pt
6629
+ * @param halfsize half-size
6630
+ */
6639
6631
  square(pt, halfsize) {
6640
- CanvasForm.square(this._ctx, pt, halfsize);
6632
+ _CanvasForm.square(this._ctx, pt, halfsize);
6641
6633
  this._paint();
6642
6634
  return this;
6643
6635
  }
6644
6636
  /**
6645
- * A static function to draw a line or polyline.
6646
- * @param ctx canvas rendering context
6647
- * @param pts a Group or an Iterable<PtLike> representing a line
6648
- */
6637
+ * A static function to draw a line or polyline.
6638
+ * @param ctx canvas rendering context
6639
+ * @param pts a Group or an Iterable<PtLike> representing a line
6640
+ */
6649
6641
  static line(ctx, pts) {
6650
6642
  if (!Util.arrayCheck(pts))
6651
6643
  return;
6652
6644
  let i = 0;
6653
6645
  ctx.beginPath();
6654
- for (let it of pts) {
6646
+ for (const it of pts) {
6655
6647
  if (it) {
6656
6648
  if (i++ > 0) {
6657
6649
  ctx.lineTo(it[0], it[1]);
@@ -6662,41 +6654,41 @@ var CanvasForm = class extends VisualForm {
6662
6654
  }
6663
6655
  }
6664
6656
  /**
6665
- * Draw a line or polyline.
6666
- * @param pts a Group or an Iterable<PtLike> representing a line
6667
- */
6657
+ * Draw a line or polyline.
6658
+ * @param pts a Group or an Iterable<PtLike> representing a line
6659
+ */
6668
6660
  line(pts) {
6669
- CanvasForm.line(this._ctx, pts);
6661
+ _CanvasForm.line(this._ctx, pts);
6670
6662
  this._paint();
6671
6663
  return this;
6672
6664
  }
6673
6665
  /**
6674
- * A static function to draw a polygon.
6675
- * @param ctx canvas rendering context
6676
- * @param pts a Group or an Iterable<PtLike> representing a polygon
6677
- */
6666
+ * A static function to draw a polygon.
6667
+ * @param ctx canvas rendering context
6668
+ * @param pts a Group or an Iterable<PtLike> representing a polygon
6669
+ */
6678
6670
  static polygon(ctx, pts) {
6679
6671
  if (!Util.arrayCheck(pts))
6680
6672
  return;
6681
- CanvasForm.line(ctx, pts);
6673
+ _CanvasForm.line(ctx, pts);
6682
6674
  ctx.closePath();
6683
6675
  }
6684
6676
  /**
6685
- * Draw a polygon.
6686
- * @param pts a Group or an Iterable<PtLike> representingg a polygon
6687
- */
6677
+ * Draw a polygon.
6678
+ * @param pts a Group or an Iterable<PtLike> representingg a polygon
6679
+ */
6688
6680
  polygon(pts) {
6689
- CanvasForm.polygon(this._ctx, pts);
6681
+ _CanvasForm.polygon(this._ctx, pts);
6690
6682
  this._paint();
6691
6683
  return this;
6692
6684
  }
6693
6685
  /**
6694
- * A static function to draw a rectangle.
6695
- * @param ctx canvas rendering context
6696
- * @param pts a Group or an Iterable<PtLike> with 2 Pt specifying the top-left and bottom-right positions.
6697
- */
6686
+ * A static function to draw a rectangle.
6687
+ * @param ctx canvas rendering context
6688
+ * @param pts a Group or an Iterable<PtLike> with 2 Pt specifying the top-left and bottom-right positions.
6689
+ */
6698
6690
  static rect(ctx, pts) {
6699
- let p = Util.iterToArray(pts);
6691
+ const p = Util.iterToArray(pts);
6700
6692
  if (!Util.arrayCheck(p))
6701
6693
  return;
6702
6694
  ctx.beginPath();
@@ -6707,29 +6699,29 @@ var CanvasForm = class extends VisualForm {
6707
6699
  ctx.closePath();
6708
6700
  }
6709
6701
  /**
6710
- * Draw a rectangle.
6711
- * @param pts a Group or an Iterable<PtLike> with 2 Pt specifying the top-left and bottom-right positions.
6712
- */
6702
+ * Draw a rectangle.
6703
+ * @param pts a Group or an Iterable<PtLike> with 2 Pt specifying the top-left and bottom-right positions.
6704
+ */
6713
6705
  rect(pts) {
6714
- CanvasForm.rect(this._ctx, pts);
6706
+ _CanvasForm.rect(this._ctx, pts);
6715
6707
  this._paint();
6716
6708
  return this;
6717
6709
  }
6718
6710
  /**
6719
- * A static function to draw an image.
6720
- * @param ctx canvas rendering context
6721
- * @param img either an [Img](#link) instance or an [`CanvasImageSource`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasImageSource) instance (eg the image from `<img>`, `<video>` or `<canvas>`)
6722
- * @param ptOrRect a target area to place the image. Either a Pt or numeric array specifying a position, or a Group or an Iterable<PtLike> with 2 Pt (top-left, bottom-right) that specifies a bounding box for resizing. Default is (0,0) at top-left.
6723
- * @param orig optionally a Group or an Iterable<PtLike> with 2 Pt (top-left, bottom-right) that specifies a cropping box in the original target.
6724
- */
6711
+ * A static function to draw an image.
6712
+ * @param ctx canvas rendering context
6713
+ * @param img either an [Img](#link) instance or an [`CanvasImageSource`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasImageSource) instance (eg the image from `<img>`, `<video>` or `<canvas>`)
6714
+ * @param ptOrRect a target area to place the image. Either a Pt or numeric array specifying a position, or a Group or an Iterable<PtLike> with 2 Pt (top-left, bottom-right) that specifies a bounding box for resizing. Default is (0,0) at top-left.
6715
+ * @param orig optionally a Group or an Iterable<PtLike> with 2 Pt (top-left, bottom-right) that specifies a cropping box in the original target.
6716
+ */
6725
6717
  static image(ctx, ptOrRect, img, orig) {
6726
- let t = Util.iterToArray(ptOrRect);
6718
+ const t = Util.iterToArray(ptOrRect);
6727
6719
  let pos;
6728
6720
  if (typeof t[0] === "number") {
6729
6721
  pos = t;
6730
6722
  } else {
6731
6723
  if (orig) {
6732
- let o = Util.iterToArray(orig);
6724
+ const o = Util.iterToArray(orig);
6733
6725
  pos = [
6734
6726
  o[0][0],
6735
6727
  o[0][1],
@@ -6753,29 +6745,29 @@ var CanvasForm = class extends VisualForm {
6753
6745
  }
6754
6746
  }
6755
6747
  /**
6756
- * Draw an image.
6757
- * @param img either an [Img](#link) instance or an [`CanvasImageSource`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasImageSource) instance (eg the image from `<img>`, `<video>` or `<canvas>`)
6758
- * @param ptOrRect a target area to place the image. Either a PtLike specifying a position, or a Group or an Iterable<PtLike> with 2 Pt (top-left position, bottom-right position) that specifies a bounding box. Default is (0,0) at top-left.
6759
- * @param orig optionally a Group or an Iterable<PtLike> with 2 Pt (top-left position, bottom-right position) that specifies a cropping box in the original target.
6760
- */
6748
+ * Draw an image.
6749
+ * @param img either an [Img](#link) instance or an [`CanvasImageSource`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasImageSource) instance (eg the image from `<img>`, `<video>` or `<canvas>`)
6750
+ * @param ptOrRect a target area to place the image. Either a PtLike specifying a position, or a Group or an Iterable<PtLike> with 2 Pt (top-left position, bottom-right position) that specifies a bounding box. Default is (0,0) at top-left.
6751
+ * @param orig optionally a Group or an Iterable<PtLike> with 2 Pt (top-left position, bottom-right position) that specifies a cropping box in the original target.
6752
+ */
6761
6753
  image(ptOrRect, img, orig) {
6762
6754
  if (img instanceof Img) {
6763
6755
  if (img.loaded) {
6764
- CanvasForm.image(this._ctx, ptOrRect, img.image, orig);
6756
+ _CanvasForm.image(this._ctx, ptOrRect, img.image, orig);
6765
6757
  }
6766
6758
  } else {
6767
- CanvasForm.image(this._ctx, ptOrRect, img, orig);
6759
+ _CanvasForm.image(this._ctx, ptOrRect, img, orig);
6768
6760
  }
6769
6761
  return this;
6770
6762
  }
6771
6763
  /**
6772
- * A static function to draw ImageData on canvas
6773
- * @param ctx canvas rendering context
6774
- * @param ptOrRect a target area to place the image. Either a Pt or numeric array specifying a position, or a Group or an Iterable<PtLike> with 2 Pt (top-left, bottom-right) that specifies a bounding box for resizing. Default is (0,0) at top-left.
6775
- * @param img an ImageData object
6776
- */
6764
+ * A static function to draw ImageData on canvas
6765
+ * @param ctx canvas rendering context
6766
+ * @param ptOrRect a target area to place the image. Either a Pt or numeric array specifying a position, or a Group or an Iterable<PtLike> with 2 Pt (top-left, bottom-right) that specifies a bounding box for resizing. Default is (0,0) at top-left.
6767
+ * @param img an ImageData object
6768
+ */
6777
6769
  static imageData(ctx, ptOrRect, img) {
6778
- let t = Util.iterToArray(ptOrRect);
6770
+ const t = Util.iterToArray(ptOrRect);
6779
6771
  if (typeof t[0] === "number") {
6780
6772
  ctx.putImageData(img, t[0], t[1]);
6781
6773
  } else {
@@ -6783,74 +6775,74 @@ var CanvasForm = class extends VisualForm {
6783
6775
  }
6784
6776
  }
6785
6777
  /**
6786
- * Draw ImageData on canvas using ImageData
6787
- * @param ptOrRect a target area to place the image. Either a Pt or numeric array specifying a position, or a Group or an Iterable<PtLike> with 2 Pt (top-left, bottom-right) that specifies a bounding box for resizing. Default is (0,0) at top-left.
6788
- * @param img an ImageData object
6789
- */
6778
+ * Draw ImageData on canvas using ImageData
6779
+ * @param ptOrRect a target area to place the image. Either a Pt or numeric array specifying a position, or a Group or an Iterable<PtLike> with 2 Pt (top-left, bottom-right) that specifies a bounding box for resizing. Default is (0,0) at top-left.
6780
+ * @param img an ImageData object
6781
+ */
6790
6782
  imageData(ptOrRect, img) {
6791
- CanvasForm.imageData(this._ctx, ptOrRect, img);
6783
+ _CanvasForm.imageData(this._ctx, ptOrRect, img);
6792
6784
  return this;
6793
6785
  }
6794
6786
  /**
6795
- * A static function to draw text.
6796
- * @param ctx canvas rendering context
6797
- * @param `pt` a Point object to specify the anchor point
6798
- * @param `txt` a string of text to draw
6799
- * @param `maxWidth` specify a maximum width per line
6800
- */
6787
+ * A static function to draw text.
6788
+ * @param ctx canvas rendering context
6789
+ * @param `pt` a Point object to specify the anchor point
6790
+ * @param `txt` a string of text to draw
6791
+ * @param `maxWidth` specify a maximum width per line
6792
+ */
6801
6793
  static text(ctx, pt, txt, maxWidth) {
6802
6794
  if (!pt)
6803
6795
  return;
6804
6796
  ctx.fillText(txt, pt[0], pt[1], maxWidth);
6805
6797
  }
6806
6798
  /**
6807
- * Draw text on canvas.
6808
- * @param `pt` a Pt or numeric array to specify the anchor point
6809
- * @param `txt` text
6810
- * @param `maxWidth` specify a maximum width per line
6811
- */
6799
+ * Draw text on canvas.
6800
+ * @param `pt` a Pt or numeric array to specify the anchor point
6801
+ * @param `txt` text
6802
+ * @param `maxWidth` specify a maximum width per line
6803
+ */
6812
6804
  text(pt, txt, maxWidth) {
6813
- CanvasForm.text(this._ctx, pt, txt, maxWidth);
6805
+ _CanvasForm.text(this._ctx, pt, txt, maxWidth);
6814
6806
  return this;
6815
6807
  }
6816
6808
  /**
6817
- * Fit a single-line text in a rectangular box.
6818
- * @param box a rectangle box defined by a Group or an Iterable<Pt>
6819
- * @param txt string of text
6820
- * @param tail text to indicate overflow such as "...". Default is empty "".
6821
- * @param verticalAlign "top", "middle", or "bottom" to specify vertical alignment inside the box
6822
- * @param overrideBaseline If `true`, use the corresponding baseline as verticalAlign. If `false`, use the current canvas context's textBaseline setting. Default is `true`.
6823
- */
6809
+ * Fit a single-line text in a rectangular box.
6810
+ * @param box a rectangle box defined by a Group or an Iterable<Pt>
6811
+ * @param txt string of text
6812
+ * @param tail text to indicate overflow such as "...". Default is empty "".
6813
+ * @param verticalAlign "top", "middle", or "bottom" to specify vertical alignment inside the box
6814
+ * @param overrideBaseline If `true`, use the corresponding baseline as verticalAlign. If `false`, use the current canvas context's textBaseline setting. Default is `true`.
6815
+ */
6824
6816
  textBox(box, txt, verticalAlign = "middle", tail = "", overrideBaseline = true) {
6825
6817
  if (overrideBaseline)
6826
6818
  this._ctx.textBaseline = verticalAlign;
6827
- let size = Rectangle.size(box);
6828
- let t = this._textTruncate(txt, size[0], tail);
6819
+ const size = Rectangle.size(box);
6820
+ const t = this._textTruncate(txt, size[0], tail);
6829
6821
  this.text(this._textAlign(box, verticalAlign), t[0]);
6830
6822
  return this;
6831
6823
  }
6832
6824
  /**
6833
- * Fit multi-line text in a rectangular box. Note that this will also set canvas context's textBaseline to "top".
6834
- * @param box a Group or an Iterable<PtLike> with 2 Pt that represents a bounding box
6835
- * @param txt string of text
6836
- * @param lineHeight line height as a ratio of font size. Default is 1.2.
6837
- * @param verticalAlign "top", "middle", or "bottom" to specify vertical alignment inside the box
6838
- * @param crop a boolean to specify whether to crop text when overflowing
6839
- */
6825
+ * Fit multi-line text in a rectangular box. Note that this will also set canvas context's textBaseline to "top".
6826
+ * @param box a Group or an Iterable<PtLike> with 2 Pt that represents a bounding box
6827
+ * @param txt string of text
6828
+ * @param lineHeight line height as a ratio of font size. Default is 1.2.
6829
+ * @param verticalAlign "top", "middle", or "bottom" to specify vertical alignment inside the box
6830
+ * @param crop a boolean to specify whether to crop text when overflowing
6831
+ */
6840
6832
  paragraphBox(box, txt, lineHeight = 1.2, verticalAlign = "top", crop = true) {
6841
- let b = Util.iterToArray(box);
6842
- let size = Rectangle.size(b);
6833
+ const b = Util.iterToArray(box);
6834
+ const size = Rectangle.size(b);
6843
6835
  this._ctx.textBaseline = "top";
6844
- let lstep = this._font.size * lineHeight;
6845
- let nextLine = (sub, buffer = [], cc = 0) => {
6836
+ const lstep = this._font.size * lineHeight;
6837
+ const nextLine = (sub, buffer = [], cc = 0) => {
6846
6838
  if (!sub)
6847
6839
  return buffer;
6848
6840
  if (crop && cc * lstep > size[1] - lstep * 2)
6849
6841
  return buffer;
6850
6842
  if (cc > 1e4)
6851
6843
  throw new Error("max recursion reached (10000)");
6852
- let t = this._textTruncate(sub, size[0], "");
6853
- let newln = t[0].indexOf("\n");
6844
+ const t = this._textTruncate(sub, size[0], "");
6845
+ const newln = t[0].indexOf("\n");
6854
6846
  if (newln >= 0) {
6855
6847
  buffer.push(t[0].substr(0, newln));
6856
6848
  return nextLine(sub.substr(newln + 1), buffer, cc + 1);
@@ -6858,12 +6850,12 @@ var CanvasForm = class extends VisualForm {
6858
6850
  let dt = t[0].lastIndexOf(" ") + 1;
6859
6851
  if (dt <= 0 || t[1] === sub.length)
6860
6852
  dt = void 0;
6861
- let line = t[0].substr(0, dt);
6853
+ const line = t[0].substr(0, dt);
6862
6854
  buffer.push(line);
6863
6855
  return t[1] <= 0 || t[1] === sub.length ? buffer : nextLine(sub.substr(dt || t[1]), buffer, cc + 1);
6864
6856
  };
6865
- let lines = nextLine(txt);
6866
- let lsize = lines.length * lstep;
6857
+ const lines = nextLine(txt);
6858
+ const lsize = lines.length * lstep;
6867
6859
  let lbox = b;
6868
6860
  if (verticalAlign == "middle" || verticalAlign == "center") {
6869
6861
  let lpad = (size[1] - lsize) / 2;
@@ -6875,17 +6867,17 @@ var CanvasForm = class extends VisualForm {
6875
6867
  } else {
6876
6868
  lbox = new Group(b[0], b[0].$add(size[0], lsize));
6877
6869
  }
6878
- let center = Rectangle.center(lbox);
6870
+ const center = Rectangle.center(lbox);
6879
6871
  for (let i = 0, len = lines.length; i < len; i++) {
6880
6872
  this.text(this._textAlign(lbox, "top", [0, i * lstep], center), lines[i]);
6881
6873
  }
6882
6874
  return this;
6883
6875
  }
6884
6876
  /**
6885
- * Set text alignment and baseline (eg, vertical-align).
6886
- * @param alignment HTML canvas' textAlign option: "left", "right", "center", "start", or "end"
6887
- * @param baseline HTML canvas' textBaseline option: "top", "hanging", "middle", "alphabetic", "ideographic", "bottom". For convenience, you can also use "center" (same as "middle"), and "baseline" (same as "alphabetic")
6888
- */
6877
+ * Set text alignment and baseline (eg, vertical-align).
6878
+ * @param alignment HTML canvas' textAlign option: "left", "right", "center", "start", or "end"
6879
+ * @param baseline HTML canvas' textBaseline option: "top", "hanging", "middle", "alphabetic", "ideographic", "bottom". For convenience, you can also use "center" (same as "middle"), and "baseline" (same as "alphabetic")
6880
+ */
6889
6881
  alignText(alignment = "left", baseline = "alphabetic") {
6890
6882
  if (baseline == "center")
6891
6883
  baseline = "middle";
@@ -6896,11 +6888,11 @@ var CanvasForm = class extends VisualForm {
6896
6888
  return this;
6897
6889
  }
6898
6890
  /**
6899
- * A convenient way to draw some text on canvas for logging or debugging. It'll be draw on the top-left of the canvas as an overlay.
6900
- * @param txt text
6901
- */
6891
+ * A convenient way to draw some text on canvas for logging or debugging. It'll be draw on the top-left of the canvas as an overlay.
6892
+ * @param txt text
6893
+ */
6902
6894
  log(txt) {
6903
- let w = this._ctx.measureText(txt).width + 20;
6895
+ const w = this._ctx.measureText(txt).width + 20;
6904
6896
  this.stroke(false).fill("rgba(0,0,0,.4)").rect([[0, 0], [w, 20]]);
6905
6897
  this.fill("#fff").text([10, 14], txt);
6906
6898
  return this;
@@ -7363,7 +7355,7 @@ var Noise = class extends Pt {
7363
7355
  return Num.lerp(Num.lerp(n00, n10, tx), Num.lerp(n01, n11, tx), _fade(y));
7364
7356
  }
7365
7357
  };
7366
- var Delaunay = class extends Group {
7358
+ var Delaunay = class _Delaunay extends Group {
7367
7359
  constructor() {
7368
7360
  super(...arguments);
7369
7361
  this._mesh = [];
@@ -7410,7 +7402,7 @@ var Delaunay = class extends Group {
7410
7402
  edges.push(circum.i, circum.j, circum.j, circum.k, circum.k, circum.i);
7411
7403
  opened.splice(j, 1);
7412
7404
  }
7413
- Delaunay._dedupe(edges);
7405
+ _Delaunay._dedupe(edges);
7414
7406
  j = edges.length;
7415
7407
  while (j > 1) {
7416
7408
  opened.push(this._circum(edges[--j], edges[--j], c, false, pts));
@@ -7552,7 +7544,7 @@ var Delaunay = class extends Group {
7552
7544
  };
7553
7545
 
7554
7546
  // src/Color.ts
7555
- var _Color = class extends Pt {
7547
+ var _Color = class _Color extends Pt {
7556
7548
  /**
7557
7549
  * Create a Color. Same as creating a Pt. Optionally you may use [`Color.from`](#link) to create a color.
7558
7550
  * @param args Pt-like parameters which can be a list of numeric parameters, an array of numbers, or an object with {x,y,z,w} properties
@@ -7567,8 +7559,8 @@ var _Color = class extends Pt {
7567
7559
  * @param args Pt-like parameters which can be a list of numeric parameters, an array of numbers, or an object with {x,y,z,w} properties
7568
7560
  */
7569
7561
  static from(...args) {
7570
- let p = [1, 1, 1, 1];
7571
- let c = Util.getArgs(args);
7562
+ const p = [1, 1, 1, 1];
7563
+ const c = Util.getArgs(args);
7572
7564
  for (let i = 0, len = p.length; i < len; i++) {
7573
7565
  if (i < c.length)
7574
7566
  p[i] = c[i];
@@ -7583,7 +7575,7 @@ var _Color = class extends Pt {
7583
7575
  if (hex[0] == "#")
7584
7576
  hex = hex.substr(1);
7585
7577
  if (hex.length <= 3) {
7586
- let fn = (i) => hex[i] || "F";
7578
+ const fn = (i) => hex[i] || "F";
7587
7579
  hex = `${fn(0)}${fn(0)}${fn(1)}${fn(1)}${fn(2)}${fn(2)}`;
7588
7580
  }
7589
7581
  let alpha = 1;
@@ -7591,7 +7583,7 @@ var _Color = class extends Pt {
7591
7583
  alpha = hex.substr(6) && 255 / 255;
7592
7584
  hex = hex.substring(0, 6);
7593
7585
  }
7594
- let hexVal = parseInt(hex, 16);
7586
+ const hexVal = parseInt(hex, 16);
7595
7587
  return new _Color(hexVal >> 16, hexVal >> 8 & 255, hexVal & 255, alpha);
7596
7588
  }
7597
7589
  /**
@@ -7673,7 +7665,7 @@ var _Color = class extends Pt {
7673
7665
  * Clone this Color.
7674
7666
  */
7675
7667
  clone() {
7676
- let c = new _Color(this);
7668
+ const c = new _Color(this);
7677
7669
  c.toMode(this._mode);
7678
7670
  return c;
7679
7671
  }
@@ -7684,7 +7676,7 @@ var _Color = class extends Pt {
7684
7676
  */
7685
7677
  toMode(mode, convert = false) {
7686
7678
  if (convert) {
7687
- let fname = this._mode.toUpperCase() + "to" + mode.toUpperCase();
7679
+ const fname = this._mode.toUpperCase() + "to" + mode.toUpperCase();
7688
7680
  if (_Color[fname]) {
7689
7681
  this.to(_Color[fname](this, this._isNorm, this._isNorm));
7690
7682
  } else {
@@ -7736,7 +7728,7 @@ var _Color = class extends Pt {
7736
7728
  return this._mode == "lch" ? this[2] : this[0];
7737
7729
  }
7738
7730
  set h(n) {
7739
- let i = this._mode == "lch" ? 2 : 0;
7731
+ const i = this._mode == "lch" ? 2 : 0;
7740
7732
  this[i] = n;
7741
7733
  }
7742
7734
  /**
@@ -7755,7 +7747,7 @@ var _Color = class extends Pt {
7755
7747
  return this._mode == "hsl" ? this[2] : this[0];
7756
7748
  }
7757
7749
  set l(n) {
7758
- let i = this._mode == "hsl" ? 2 : 0;
7750
+ const i = this._mode == "hsl" ? 2 : 0;
7759
7751
  this[i] = n;
7760
7752
  }
7761
7753
  // lab, lch, luv
@@ -7821,7 +7813,7 @@ var _Color = class extends Pt {
7821
7813
  normalize(toNorm = true) {
7822
7814
  if (this._isNorm == toNorm)
7823
7815
  return this;
7824
- let ranges = _Color.ranges[this._mode];
7816
+ const ranges = _Color.ranges[this._mode];
7825
7817
  for (let i = 0; i < 3; i++) {
7826
7818
  this[i] = !toNorm ? Num.mapToRange(this[i], 0, 1, ranges[i][0], ranges[i][1]) : Num.mapToRange(this[i], ranges[i][0], ranges[i][1], 0, 1);
7827
7819
  }
@@ -7842,8 +7834,8 @@ var _Color = class extends Pt {
7842
7834
  */
7843
7835
  toString(format = "mode") {
7844
7836
  if (format == "hex") {
7845
- let _hex = (n) => {
7846
- let s = Math.floor(n).toString(16);
7837
+ const _hex = (n) => {
7838
+ const s = Math.floor(n).toString(16);
7847
7839
  return s.length < 2 ? "0" + s : s;
7848
7840
  };
7849
7841
  return `#${_hex(this[0])}${_hex(this[1])}${_hex(this[2])}`;
@@ -7863,17 +7855,17 @@ var _Color = class extends Pt {
7863
7855
  * @returns a new HSL Color
7864
7856
  */
7865
7857
  static RGBtoHSL(rgb, normalizedInput = false, normalizedOutput = false) {
7866
- let [r, g, b] = !normalizedInput ? rgb.$normalize() : rgb;
7867
- let max = Math.max(r, g, b);
7868
- let min = Math.min(r, g, b);
7858
+ const [r, g, b] = !normalizedInput ? rgb.$normalize() : rgb;
7859
+ const max = Math.max(r, g, b);
7860
+ const min = Math.min(r, g, b);
7869
7861
  let h = (max + min) / 2;
7870
7862
  let s = h;
7871
- let l = h;
7863
+ const l = h;
7872
7864
  if (max == min) {
7873
7865
  h = 0;
7874
7866
  s = 0;
7875
7867
  } else {
7876
- let d = max - min;
7868
+ const d = max - min;
7877
7869
  s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
7878
7870
  h = 0;
7879
7871
  if (max === r) {
@@ -7899,9 +7891,9 @@ var _Color = class extends Pt {
7899
7891
  h = h / 360;
7900
7892
  if (s == 0)
7901
7893
  return _Color.rgb(l * 255, l * 255, l * 255, hsl.alpha);
7902
- let q = l <= 0.5 ? l * (1 + s) : l + s - l * s;
7903
- let p = 2 * l - q;
7904
- let convert = (t) => {
7894
+ const q = l <= 0.5 ? l * (1 + s) : l + s - l * s;
7895
+ const p = 2 * l - q;
7896
+ const convert = (t) => {
7905
7897
  t = t < 0 ? t + 1 : t > 1 ? t - 1 : t;
7906
7898
  if (t * 6 < 1) {
7907
7899
  return p + (q - p) * t * 6;
@@ -7913,7 +7905,7 @@ var _Color = class extends Pt {
7913
7905
  return p;
7914
7906
  }
7915
7907
  };
7916
- let sc = normalizedOutput ? 1 : 255;
7908
+ const sc = normalizedOutput ? 1 : 255;
7917
7909
  return _Color.rgb(
7918
7910
  sc * convert(h + 1 / 3),
7919
7911
  sc * convert(h),
@@ -7929,13 +7921,13 @@ var _Color = class extends Pt {
7929
7921
  * @returns a new HSB Color
7930
7922
  */
7931
7923
  static RGBtoHSB(rgb, normalizedInput = false, normalizedOutput = false) {
7932
- let [r, g, b] = !normalizedInput ? rgb.$normalize() : rgb;
7933
- let max = Math.max(r, g, b);
7934
- let min = Math.min(r, g, b);
7935
- let d = max - min;
7924
+ const [r, g, b] = !normalizedInput ? rgb.$normalize() : rgb;
7925
+ const max = Math.max(r, g, b);
7926
+ const min = Math.min(r, g, b);
7927
+ const d = max - min;
7936
7928
  let h = 0;
7937
- let s = max === 0 ? 0 : d / max;
7938
- let v = max;
7929
+ const s = max === 0 ? 0 : d / max;
7930
+ const v = max;
7939
7931
  if (max != min) {
7940
7932
  if (max === r) {
7941
7933
  h = (g - b) / d + (g < b ? 6 : 0);
@@ -7958,12 +7950,12 @@ var _Color = class extends Pt {
7958
7950
  let [h, s, v] = hsb;
7959
7951
  if (!normalizedInput)
7960
7952
  h = h / 360;
7961
- let i = Math.floor(h * 6);
7962
- let f = h * 6 - i;
7963
- let p = v * (1 - s);
7964
- let q = v * (1 - f * s);
7965
- let t = v * (1 - (1 - f) * s);
7966
- let pick = [
7953
+ const i = Math.floor(h * 6);
7954
+ const f = h * 6 - i;
7955
+ const p = v * (1 - s);
7956
+ const q = v * (1 - f * s);
7957
+ const t = v * (1 - (1 - f) * s);
7958
+ const pick = [
7967
7959
  [v, t, p],
7968
7960
  [q, v, p],
7969
7961
  [p, v, t],
@@ -7971,8 +7963,8 @@ var _Color = class extends Pt {
7971
7963
  [t, p, v],
7972
7964
  [v, p, q]
7973
7965
  ];
7974
- let c = pick[i % 6];
7975
- let sc = normalizedOutput ? 1 : 255;
7966
+ const c = pick[i % 6];
7967
+ const sc = normalizedOutput ? 1 : 255;
7976
7968
  return _Color.rgb(
7977
7969
  sc * c[0],
7978
7970
  sc * c[1],
@@ -7988,7 +7980,7 @@ var _Color = class extends Pt {
7988
7980
  * @returns a new LAB Color
7989
7981
  */
7990
7982
  static RGBtoLAB(rgb, normalizedInput = false, normalizedOutput = false) {
7991
- let c = normalizedInput ? rgb.$normalize(false) : rgb;
7983
+ const c = normalizedInput ? rgb.$normalize(false) : rgb;
7992
7984
  return _Color.XYZtoLAB(_Color.RGBtoXYZ(c), false, normalizedOutput);
7993
7985
  }
7994
7986
  /**
@@ -7999,7 +7991,7 @@ var _Color = class extends Pt {
7999
7991
  * @returns a new RGB Color
8000
7992
  */
8001
7993
  static LABtoRGB(lab, normalizedInput = false, normalizedOutput = false) {
8002
- let c = normalizedInput ? lab.$normalize(false) : lab;
7994
+ const c = normalizedInput ? lab.$normalize(false) : lab;
8003
7995
  return _Color.XYZtoRGB(_Color.LABtoXYZ(c), false, normalizedOutput);
8004
7996
  }
8005
7997
  /**
@@ -8010,7 +8002,7 @@ var _Color = class extends Pt {
8010
8002
  * @returns a new LCH Color
8011
8003
  */
8012
8004
  static RGBtoLCH(rgb, normalizedInput = false, normalizedOutput = false) {
8013
- let c = normalizedInput ? rgb.$normalize(false) : rgb;
8005
+ const c = normalizedInput ? rgb.$normalize(false) : rgb;
8014
8006
  return _Color.LABtoLCH(_Color.RGBtoLAB(c), false, normalizedOutput);
8015
8007
  }
8016
8008
  /**
@@ -8021,7 +8013,7 @@ var _Color = class extends Pt {
8021
8013
  * @returns a new RGB Color
8022
8014
  */
8023
8015
  static LCHtoRGB(lch, normalizedInput = false, normalizedOutput = false) {
8024
- let c = normalizedInput ? lch.$normalize(false) : lch;
8016
+ const c = normalizedInput ? lch.$normalize(false) : lch;
8025
8017
  return _Color.LABtoRGB(_Color.LCHtoLAB(c), false, normalizedOutput);
8026
8018
  }
8027
8019
  /**
@@ -8032,7 +8024,7 @@ var _Color = class extends Pt {
8032
8024
  * @returns a new LUV Color
8033
8025
  */
8034
8026
  static RGBtoLUV(rgb, normalizedInput = false, normalizedOutput = false) {
8035
- let c = normalizedInput ? rgb.$normalize(false) : rgb;
8027
+ const c = normalizedInput ? rgb.$normalize(false) : rgb;
8036
8028
  return _Color.XYZtoLUV(_Color.RGBtoXYZ(c), false, normalizedOutput);
8037
8029
  }
8038
8030
  /**
@@ -8043,7 +8035,7 @@ var _Color = class extends Pt {
8043
8035
  * @returns a new RGB Color
8044
8036
  */
8045
8037
  static LUVtoRGB(luv, normalizedInput = false, normalizedOutput = false) {
8046
- let c = normalizedInput ? luv.$normalize(false) : luv;
8038
+ const c = normalizedInput ? luv.$normalize(false) : luv;
8047
8039
  return _Color.XYZtoRGB(_Color.LUVtoXYZ(c), false, normalizedOutput);
8048
8040
  }
8049
8041
  /**
@@ -8054,13 +8046,13 @@ var _Color = class extends Pt {
8054
8046
  * @returns a new XYZ Color
8055
8047
  */
8056
8048
  static RGBtoXYZ(rgb, normalizedInput = false, normalizedOutput = false) {
8057
- let c = !normalizedInput ? rgb.$normalize() : rgb.clone();
8049
+ const c = !normalizedInput ? rgb.$normalize() : rgb.clone();
8058
8050
  for (let i = 0; i < 3; i++) {
8059
8051
  c[i] = c[i] > 0.04045 ? Math.pow((c[i] + 0.055) / 1.055, 2.4) : c[i] / 12.92;
8060
8052
  if (!normalizedOutput)
8061
8053
  c[i] = c[i] * 100;
8062
8054
  }
8063
- let cc = _Color.xyz(
8055
+ const cc = _Color.xyz(
8064
8056
  c[0] * 0.4124564 + c[1] * 0.3575761 + c[2] * 0.1804375,
8065
8057
  c[0] * 0.2126729 + c[1] * 0.7151522 + c[2] * 0.072175,
8066
8058
  c[0] * 0.0193339 + c[1] * 0.119192 + c[2] * 0.9503041,
@@ -8076,8 +8068,8 @@ var _Color = class extends Pt {
8076
8068
  * @returns a new RGB Color
8077
8069
  */
8078
8070
  static XYZtoRGB(xyz, normalizedInput = false, normalizedOutput = false) {
8079
- let [x, y, z] = !normalizedInput ? xyz.$normalize() : xyz;
8080
- let rgb = [
8071
+ const [x, y, z] = !normalizedInput ? xyz.$normalize() : xyz;
8072
+ const rgb = [
8081
8073
  x * 3.2406254773200533 + y * -1.5372079722103187 + z * -0.4986285986982479,
8082
8074
  x * -0.9689307147293197 + y * 1.8757560608852415 + z * 0.041517523842953964,
8083
8075
  x * 0.055710120445510616 + y * -0.2040210505984867 + z * 1.0569959422543882
@@ -8088,7 +8080,7 @@ var _Color = class extends Pt {
8088
8080
  if (!normalizedOutput)
8089
8081
  rgb[i] = Math.round(rgb[i] * 255);
8090
8082
  }
8091
- let cc = _Color.rgb(rgb[0], rgb[1], rgb[2], xyz.alpha);
8083
+ const cc = _Color.rgb(rgb[0], rgb[1], rgb[2], xyz.alpha);
8092
8084
  return normalizedOutput ? cc.normalize() : cc;
8093
8085
  }
8094
8086
  /**
@@ -8099,13 +8091,13 @@ var _Color = class extends Pt {
8099
8091
  * @returns a new LAB Color
8100
8092
  */
8101
8093
  static XYZtoLAB(xyz, normalizedInput = false, normalizedOutput = false) {
8102
- let c = normalizedInput ? xyz.$normalize(false) : xyz.clone();
8094
+ const c = normalizedInput ? xyz.$normalize(false) : xyz.clone();
8103
8095
  const eps = 0.00885645167;
8104
8096
  const kap = 903.296296296;
8105
8097
  c.divide(_Color.D65);
8106
- let fn = (n) => n > eps ? Math.pow(n, 1 / 3) : (kap * n + 16) / 116;
8107
- let cy = fn(c[1]);
8108
- let cc = _Color.lab(
8098
+ const fn = (n) => n > eps ? Math.pow(n, 1 / 3) : (kap * n + 16) / 116;
8099
+ const cy = fn(c[1]);
8100
+ const cc = _Color.lab(
8109
8101
  116 * cy - 16,
8110
8102
  500 * (fn(c[0]) - cy),
8111
8103
  200 * (cy - fn(c[2])),
@@ -8121,16 +8113,16 @@ var _Color = class extends Pt {
8121
8113
  * @returns a new XYZ Color
8122
8114
  */
8123
8115
  static LABtoXYZ(lab, normalizedInput = false, normalizedOutput = false) {
8124
- let c = normalizedInput ? lab.$normalize(false) : lab;
8125
- let y = (c[0] + 16) / 116;
8126
- let x = c[1] / 500 + y;
8127
- let z = y - c[2] / 200;
8116
+ const c = normalizedInput ? lab.$normalize(false) : lab;
8117
+ const y = (c[0] + 16) / 116;
8118
+ const x = c[1] / 500 + y;
8119
+ const z = y - c[2] / 200;
8128
8120
  const eps = 0.00885645167;
8129
8121
  const kap = 903.296296296;
8130
- let d = _Color.D65;
8122
+ const d = _Color.D65;
8131
8123
  const xxx = Math.pow(x, 3);
8132
8124
  const zzz = Math.pow(z, 3);
8133
- let cc = _Color.xyz(
8125
+ const cc = _Color.xyz(
8134
8126
  d[0] * (xxx > eps ? xxx : (116 * x - 16) / kap),
8135
8127
  d[1] * (c[0] > kap * eps ? Math.pow((c[0] + 16) / 116, 3) : c[0] / kap),
8136
8128
  d[2] * (zzz > eps ? zzz : (116 * z - 16) / kap),
@@ -8147,13 +8139,13 @@ var _Color = class extends Pt {
8147
8139
  */
8148
8140
  static XYZtoLUV(xyz, normalizedInput = false, normalizedOutput = false) {
8149
8141
  let [x, y, z] = normalizedInput ? xyz.$normalize(false) : xyz;
8150
- let u = 4 * x / (x + 15 * y + 3 * z);
8151
- let v = 9 * y / (x + 15 * y + 3 * z);
8142
+ const u = 4 * x / (x + 15 * y + 3 * z);
8143
+ const v = 9 * y / (x + 15 * y + 3 * z);
8152
8144
  y = y / 100;
8153
8145
  y = y > 8856e-6 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
8154
- let refU = 4 * _Color.D65[0] / (_Color.D65[0] + 15 * _Color.D65[1] + 3 * _Color.D65[2]);
8155
- let refV = 9 * _Color.D65[1] / (_Color.D65[0] + 15 * _Color.D65[1] + 3 * _Color.D65[2]);
8156
- let L = 116 * y - 16;
8146
+ const refU = 4 * _Color.D65[0] / (_Color.D65[0] + 15 * _Color.D65[1] + 3 * _Color.D65[2]);
8147
+ const refV = 9 * _Color.D65[1] / (_Color.D65[0] + 15 * _Color.D65[1] + 3 * _Color.D65[2]);
8148
+ const L = 116 * y - 16;
8157
8149
  return _Color.luv(
8158
8150
  L,
8159
8151
  13 * L * (u - refU),
@@ -8171,15 +8163,15 @@ var _Color = class extends Pt {
8171
8163
  static LUVtoXYZ(luv, normalizedInput = false, normalizedOutput = false) {
8172
8164
  let [l, u, v] = normalizedInput ? luv.$normalize(false) : luv;
8173
8165
  let y = (l + 16) / 116;
8174
- let cubeY = y * y * y;
8166
+ const cubeY = y * y * y;
8175
8167
  y = cubeY > 8856e-6 ? cubeY : (y - 16 / 116) / 7.787;
8176
- let refU = 4 * _Color.D65[0] / (_Color.D65[0] + 15 * _Color.D65[1] + 3 * _Color.D65[2]);
8177
- let refV = 9 * _Color.D65[1] / (_Color.D65[0] + 15 * _Color.D65[1] + 3 * _Color.D65[2]);
8168
+ const refU = 4 * _Color.D65[0] / (_Color.D65[0] + 15 * _Color.D65[1] + 3 * _Color.D65[2]);
8169
+ const refV = 9 * _Color.D65[1] / (_Color.D65[0] + 15 * _Color.D65[1] + 3 * _Color.D65[2]);
8178
8170
  u = u / (13 * l) + refU;
8179
8171
  v = v / (13 * l) + refV;
8180
8172
  y = y * 100;
8181
- let x = -1 * (9 * y * u) / ((u - 4) * v - u * v);
8182
- let z = (9 * y - 15 * v * y - v * x) / (3 * v);
8173
+ const x = -1 * (9 * y * u) / ((u - 4) * v - u * v);
8174
+ const z = (9 * y - 15 * v * y - v * x) / (3 * v);
8183
8175
  return _Color.xyz(x, y, z, luv.alpha);
8184
8176
  }
8185
8177
  /**
@@ -8190,8 +8182,8 @@ var _Color = class extends Pt {
8190
8182
  * @returns a new LCH Color
8191
8183
  */
8192
8184
  static LABtoLCH(lab, normalizedInput = false, normalizedOutput = false) {
8193
- let c = normalizedInput ? lab.$normalize(false) : lab;
8194
- let h = Geom.toDegree(Geom.boundRadian(Math.atan2(c[2], c[1])));
8185
+ const c = normalizedInput ? lab.$normalize(false) : lab;
8186
+ const h = Geom.toDegree(Geom.boundRadian(Math.atan2(c[2], c[1])));
8195
8187
  return _Color.lch(
8196
8188
  c[0],
8197
8189
  Math.sqrt(c[1] * c[1] + c[2] * c[2]),
@@ -8207,8 +8199,8 @@ var _Color = class extends Pt {
8207
8199
  * @returns a new LAB Color
8208
8200
  */
8209
8201
  static LCHtoLAB(lch, normalizedInput = false, normalizedOutput = false) {
8210
- let c = normalizedInput ? lch.$normalize(false) : lch;
8211
- let rad = Geom.toRadian(c[2]);
8202
+ const c = normalizedInput ? lch.$normalize(false) : lch;
8203
+ const rad = Geom.toRadian(c[2]);
8212
8204
  return _Color.lab(
8213
8205
  c[0],
8214
8206
  Math.cos(rad) * c[1],
@@ -8217,13 +8209,12 @@ var _Color = class extends Pt {
8217
8209
  );
8218
8210
  }
8219
8211
  };
8220
- var Color = _Color;
8221
8212
  // XYZ property for Standard Observer 2deg, Daylight/sRGB illuminant D65
8222
- Color.D65 = new Pt(95.047, 100, 108.883, 1);
8213
+ _Color.D65 = new Pt(95.047, 100, 108.883, 1);
8223
8214
  /**
8224
8215
  * Value range for each color space
8225
8216
  */
8226
- Color.ranges = {
8217
+ _Color.ranges = {
8227
8218
  rgb: new Group(new Pt(0, 255), new Pt(0, 255), new Pt(0, 255)),
8228
8219
  hsl: new Group(new Pt(0, 360), new Pt(0, 1), new Pt(0, 1)),
8229
8220
  hsb: new Group(new Pt(0, 360), new Pt(0, 1), new Pt(0, 1)),
@@ -8232,9 +8223,10 @@ Color.ranges = {
8232
8223
  luv: new Group(new Pt(0, 100), new Pt(-134, 220), new Pt(-140, 122)),
8233
8224
  xyz: new Group(new Pt(0, 100), new Pt(0, 100), new Pt(0, 100))
8234
8225
  };
8226
+ var Color = _Color;
8235
8227
 
8236
8228
  // src/Dom.ts
8237
- var DOMSpace = class extends MultiTouchSpace {
8229
+ var DOMSpace = class _DOMSpace extends MultiTouchSpace {
8238
8230
  /**
8239
8231
  * Create a DOMSpace for HTML DOM elements
8240
8232
  * @param elem Specify an element by its "id" attribute as string, or by the element object itself. Use css to customize its appearance if needed.
@@ -8247,8 +8239,8 @@ var DOMSpace = class extends MultiTouchSpace {
8247
8239
  this._autoResize = true;
8248
8240
  this._bgcolor = "#e1e9f0";
8249
8241
  this._css = {};
8250
- var _selector = null;
8251
- var _existed = false;
8242
+ let _selector = null;
8243
+ let _existed = false;
8252
8244
  this.id = "pts";
8253
8245
  if (elem instanceof Element) {
8254
8246
  _selector = elem;
@@ -8259,8 +8251,8 @@ var DOMSpace = class extends MultiTouchSpace {
8259
8251
  this.id = elem.substr(1);
8260
8252
  }
8261
8253
  if (!_selector) {
8262
- this._container = DOMSpace.createElement("div", "pts_container");
8263
- this._canvas = DOMSpace.createElement("div", "pts_element");
8254
+ this._container = _DOMSpace.createElement("div", "pts_container");
8255
+ this._canvas = _DOMSpace.createElement("div", "pts_element");
8264
8256
  this._container.appendChild(this._canvas);
8265
8257
  document.body.appendChild(this._container);
8266
8258
  _existed = false;
@@ -8522,7 +8514,7 @@ var HTMLSpace = class extends DOMSpace {
8522
8514
  return super.removeAll();
8523
8515
  }
8524
8516
  };
8525
- var _HTMLForm = class extends VisualForm {
8517
+ var _HTMLForm = class _HTMLForm extends VisualForm {
8526
8518
  /**
8527
8519
  * Create a new `HTMLForm`. Alternatively, you can use [`HTMLSpace.getForm`](#link) function to get an instance of HTMLForm.
8528
8520
  * @param space the space to use
@@ -8941,12 +8933,12 @@ var _HTMLForm = class extends VisualForm {
8941
8933
  return this;
8942
8934
  }
8943
8935
  };
8936
+ _HTMLForm.groupID = 0;
8937
+ _HTMLForm.domID = 0;
8944
8938
  var HTMLForm = _HTMLForm;
8945
- HTMLForm.groupID = 0;
8946
- HTMLForm.domID = 0;
8947
8939
 
8948
8940
  // src/Svg.ts
8949
- var SVGSpace = class extends DOMSpace {
8941
+ var SVGSpace = class _SVGSpace extends DOMSpace {
8950
8942
  /**
8951
8943
  * Create a SVGSpace which represents a Space for SVG elements.
8952
8944
  * @param elem Specify an element by its "id" attribute as string, or by the element object itself. An element can be an existing `<svg>`, or a `<div>` container in which a new `<svg>` will be created. If left empty, a `<div id="pt_container"><svg id="pt" /></div>` will be added to DOM. Use css to customize its appearance if needed.
@@ -8957,7 +8949,7 @@ var SVGSpace = class extends DOMSpace {
8957
8949
  super(elem, callback);
8958
8950
  this._bgcolor = "#999";
8959
8951
  if (this._canvas.nodeName.toLowerCase() != "svg") {
8960
- let s = SVGSpace.svgElement(this._canvas, "svg", `${this.id}_svg`);
8952
+ let s = _SVGSpace.svgElement(this._canvas, "svg", `${this.id}_svg`);
8961
8953
  this._container = this._canvas;
8962
8954
  this._canvas = s;
8963
8955
  }
@@ -8983,7 +8975,7 @@ var SVGSpace = class extends DOMSpace {
8983
8975
  */
8984
8976
  resize(b, evt) {
8985
8977
  super.resize(b, evt);
8986
- SVGSpace.setAttr(this.element, {
8978
+ _SVGSpace.setAttr(this.element, {
8987
8979
  "viewBox": `0 0 ${this.bound.width} ${this.bound.height}`,
8988
8980
  "width": `${this.bound.width}`,
8989
8981
  "height": `${this.bound.height}`,
@@ -9028,7 +9020,7 @@ var SVGSpace = class extends DOMSpace {
9028
9020
  return super.removeAll();
9029
9021
  }
9030
9022
  };
9031
- var _SVGForm = class extends VisualForm {
9023
+ var _SVGForm = class _SVGForm extends VisualForm {
9032
9024
  /**
9033
9025
  * Create a new SVGForm. You may also use [`SVGSpace.getForm`](#link) to get a default form directly.
9034
9026
  * @param space an instance of SVGSpace
@@ -9522,12 +9514,12 @@ var _SVGForm = class extends VisualForm {
9522
9514
  return this;
9523
9515
  }
9524
9516
  };
9517
+ _SVGForm.groupID = 0;
9518
+ _SVGForm.domID = 0;
9525
9519
  var SVGForm = _SVGForm;
9526
- SVGForm.groupID = 0;
9527
- SVGForm.domID = 0;
9528
9520
 
9529
9521
  // src/Physics.ts
9530
- var World = class {
9522
+ var World = class _World {
9531
9523
  /**
9532
9524
  * Create a `World` for 2D physics simulation.
9533
9525
  * @param bound a Group or an Iterable<Pt> representing a rectangular bounding box
@@ -9615,13 +9607,10 @@ var World = class {
9615
9607
  * @returns a Body, or undefined if not found
9616
9608
  */
9617
9609
  body(id) {
9618
- let idx = id;
9619
9610
  if (typeof id === "string" && id.length > 0) {
9620
- idx = this._bnames.indexOf(id);
9611
+ return this._bodies[this._bnames.indexOf(id)];
9621
9612
  }
9622
- if (!(idx >= 0))
9623
- return void 0;
9624
- return this._bodies[idx];
9613
+ return typeof id === "number" && id >= 0 ? this._bodies[id] : void 0;
9625
9614
  }
9626
9615
  /**
9627
9616
  * Get a particle in this world by index or string id.
@@ -9629,13 +9618,10 @@ var World = class {
9629
9618
  * @returns a Particle, or undefined if not found
9630
9619
  */
9631
9620
  particle(id) {
9632
- let idx = id;
9633
9621
  if (typeof id === "string" && id.length > 0) {
9634
- idx = this._pnames.indexOf(id);
9622
+ return this._particles[this._pnames.indexOf(id)];
9635
9623
  }
9636
- if (!(idx >= 0))
9637
- return void 0;
9638
- return this._particles[idx];
9624
+ return typeof id === "number" && id >= 0 ? this._particles[id] : void 0;
9639
9625
  }
9640
9626
  /**
9641
9627
  * Given a body's name, return its index in the bodies array, or -1 if not found.
@@ -9782,7 +9768,7 @@ var World = class {
9782
9768
  for (let i = 0, len = this._particles.length; i < len; i++) {
9783
9769
  let p = this._particles[i];
9784
9770
  this.integrate(p, dt, this._lastTime);
9785
- World.boundConstraint(p, this._bound, this._damping);
9771
+ _World.boundConstraint(p, this._bound, this._damping);
9786
9772
  for (let k = i + 1; k < len; k++) {
9787
9773
  if (i !== k) {
9788
9774
  let p2 = this._particles[k];
@@ -9803,7 +9789,7 @@ var World = class {
9803
9789
  if (bds) {
9804
9790
  for (let k = 0, klen = bds.length; k < klen; k++) {
9805
9791
  let bk = bds[k];
9806
- World.boundConstraint(bk, this._bound, this._damping);
9792
+ _World.boundConstraint(bk, this._bound, this._damping);
9807
9793
  this.integrate(bk, dt, this._lastTime);
9808
9794
  }
9809
9795
  for (let k = i + 1; k < len; k++) {
@@ -9986,7 +9972,7 @@ var Particle = class extends Pt {
9986
9972
  return `Particle: ${this[0]} ${this[1]} | previous ${this._prev[0]} ${this._prev[1]} | mass ${this._mass}`;
9987
9973
  }
9988
9974
  };
9989
- var Body = class extends Group {
9975
+ var Body = class _Body extends Group {
9990
9976
  /**
9991
9977
  * Create an empty Body, this is usually followed by [`Body.init`](#link) to populate the Body. Alternatively, use static function [`Body.fromGroup`](#link) to create and initate a body directly.
9992
9978
  */
@@ -10005,7 +9991,7 @@ var Body = class extends Group {
10005
9991
  * @param autoMass Automatically calculate the mass based on the area of the polygon. Default is true.
10006
9992
  */
10007
9993
  static fromGroup(body, stiff = 1, autoLink = true, autoMass = true) {
10008
- let b = new Body().init(body);
9994
+ let b = new _Body().init(body);
10009
9995
  if (autoLink)
10010
9996
  b.linkAll(stiff);
10011
9997
  if (autoMass)
@@ -10160,7 +10146,7 @@ var Body = class extends Group {
10160
10146
  };
10161
10147
 
10162
10148
  // src/Play.ts
10163
- var Tempo = class {
10149
+ var Tempo = class _Tempo {
10164
10150
  /**
10165
10151
  * Construct a new Tempo instance by beats-per-minute. Alternatively, you can use [`Tempo.fromBeat`](#link) to create from milliseconds.
10166
10152
  * @param bpm beats per minute
@@ -10176,7 +10162,7 @@ var Tempo = class {
10176
10162
  * @param ms milliseconds per beat
10177
10163
  */
10178
10164
  static fromBeat(ms) {
10179
- return new Tempo(6e4 / ms);
10165
+ return new _Tempo(6e4 / ms);
10180
10166
  }
10181
10167
  /**
10182
10168
  * Beats-per-minute value
@@ -10218,16 +10204,16 @@ var Tempo = class {
10218
10204
  * @returns an object with chainable functions
10219
10205
  */
10220
10206
  every(beats) {
10221
- let self = this;
10222
- let p = Array.isArray(beats) ? beats[0] : beats;
10207
+ const self = this;
10208
+ const p = Array.isArray(beats) ? beats[0] : beats;
10223
10209
  return {
10224
10210
  start: function(fn, offset = 0, name) {
10225
- let id = name || self._createID(fn);
10211
+ const id = name || self._createID(fn);
10226
10212
  self._listeners[id] = { name: id, beats, period: p, index: 0, offset, duration: -1, continuous: false, fn };
10227
10213
  return this;
10228
10214
  },
10229
10215
  progress: function(fn, offset = 0, name) {
10230
- let id = name || self._createID(fn);
10216
+ const id = name || self._createID(fn);
10231
10217
  self._listeners[id] = { name: id, beats, period: p, index: 0, offset, duration: -1, continuous: true, fn };
10232
10218
  return this;
10233
10219
  }
@@ -10239,11 +10225,11 @@ var Tempo = class {
10239
10225
  * @param time current time in milliseconds
10240
10226
  */
10241
10227
  track(time) {
10242
- for (let k in this._listeners) {
10228
+ for (const k in this._listeners) {
10243
10229
  if (this._listeners.hasOwnProperty(k)) {
10244
- let li = this._listeners[k];
10245
- let _t = li.offset ? time + li.offset : time;
10246
- let ms = li.period * this._ms;
10230
+ const li = this._listeners[k];
10231
+ const _t = li.offset ? time + li.offset : time;
10232
+ const ms = li.period * this._ms;
10247
10233
  let isStart = false;
10248
10234
  if (_t > li.duration + ms) {
10249
10235
  li.duration = _t - _t % this._ms;
@@ -10253,10 +10239,10 @@ var Tempo = class {
10253
10239
  }
10254
10240
  isStart = true;
10255
10241
  }
10256
- let count = Math.max(0, Math.ceil(Math.floor(li.duration / this._ms) / li.period));
10257
- let params = li.continuous ? [count, Num.clamp((_t - li.duration) / ms, 0, 1), _t, isStart] : [count];
10242
+ const count = Math.max(0, Math.ceil(Math.floor(li.duration / this._ms) / li.period));
10243
+ const params = li.continuous ? [count, Num.clamp((_t - li.duration) / ms, 0, 1), _t, isStart] : [count];
10258
10244
  if (li.continuous || isStart) {
10259
- let done = li.fn.apply(li, params);
10245
+ const done = li.fn.apply(li, params);
10260
10246
  if (done)
10261
10247
  delete this._listeners[li.name];
10262
10248
  }
@@ -10290,7 +10276,7 @@ var Tempo = class {
10290
10276
  return;
10291
10277
  }
10292
10278
  };
10293
- var Sound = class {
10279
+ var Sound = class _Sound {
10294
10280
  // Tracking play time against ctx.currentTime
10295
10281
  /**
10296
10282
  * Construct a `Sound` instance. Usually, it's more convenient to use one of the static methods like [`Sound.load`](#function_load) or [`Sound.from`](#function_from).
@@ -10305,7 +10291,7 @@ var Sound = class {
10305
10291
  * Create an AudioContext instance. This is called internally only.
10306
10292
  */
10307
10293
  _createAudioContext() {
10308
- let _ctx = window.AudioContext;
10294
+ const _ctx = window.AudioContext;
10309
10295
  if (!_ctx)
10310
10296
  throw new Error("Your browser doesn't support Web Audio. (No AudioContext)");
10311
10297
  this._ctx = _ctx ? new _ctx() : void 0;
@@ -10319,7 +10305,7 @@ var Sound = class {
10319
10305
  * @returns a `Sound` instance
10320
10306
  */
10321
10307
  static from(node, ctx, type = "gen", stream) {
10322
- let s = new Sound(type);
10308
+ const s = new _Sound(type);
10323
10309
  s._node = node;
10324
10310
  s._ctx = ctx;
10325
10311
  if (stream)
@@ -10335,7 +10321,7 @@ var Sound = class {
10335
10321
  */
10336
10322
  static load(source, crossOrigin = "anonymous") {
10337
10323
  return new Promise((resolve, reject) => {
10338
- let s = new Sound("file");
10324
+ const s = new _Sound("file");
10339
10325
  s._source = typeof source === "string" ? new Audio(source) : source;
10340
10326
  s._source.autoplay = false;
10341
10327
  s._source.crossOrigin = crossOrigin;
@@ -10360,10 +10346,10 @@ var Sound = class {
10360
10346
  */
10361
10347
  static loadAsBuffer(url) {
10362
10348
  return new Promise((resolve, reject) => {
10363
- let request = new XMLHttpRequest();
10349
+ const request = new XMLHttpRequest();
10364
10350
  request.open("GET", url, true);
10365
10351
  request.responseType = "arraybuffer";
10366
- let s = new Sound("file");
10352
+ const s = new _Sound("file");
10367
10353
  request.onload = function() {
10368
10354
  s._ctx.decodeAudioData(request.response, function(buffer) {
10369
10355
  s.createBuffer(buffer);
@@ -10395,13 +10381,13 @@ var Sound = class {
10395
10381
  * @example `Sound.generate( 'sine', 120 )`
10396
10382
  */
10397
10383
  static generate(type, val) {
10398
- let s = new Sound("gen");
10384
+ const s = new _Sound("gen");
10399
10385
  return s._gen(type, val);
10400
10386
  }
10401
10387
  // Create the oscillator
10402
10388
  _gen(type, val) {
10403
10389
  this._node = this._ctx.createOscillator();
10404
- let osc = this._node;
10390
+ const osc = this._node;
10405
10391
  osc.type = type;
10406
10392
  if (type === "custom") {
10407
10393
  osc.setPeriodicWave(val);
@@ -10419,7 +10405,7 @@ var Sound = class {
10419
10405
  static input(constraint) {
10420
10406
  return __async(this, null, function* () {
10421
10407
  try {
10422
- let s = new Sound("input");
10408
+ const s = new _Sound("input");
10423
10409
  if (!s)
10424
10410
  return void 0;
10425
10411
  const c = constraint ? constraint : { audio: true, video: false };
@@ -10489,7 +10475,7 @@ var Sound = class {
10489
10475
  get progress() {
10490
10476
  let dur = 0;
10491
10477
  let curr = 0;
10492
- if (!!this._buffer) {
10478
+ if (this._buffer) {
10493
10479
  dur = this._buffer.duration;
10494
10480
  curr = this._timestamp ? this._ctx.currentTime - this._timestamp : 0;
10495
10481
  } else {
@@ -10561,7 +10547,7 @@ var Sound = class {
10561
10547
  * @param smooth Optional smoothing value (corresponds to `AnalyserNode.smoothingTimeConstant`)
10562
10548
  */
10563
10549
  analyze(size = 256, minDb = -100, maxDb = -30, smooth = 0.8) {
10564
- let a = this._ctx.createAnalyser();
10550
+ const a = this._ctx.createAnalyser();
10565
10551
  a.fftSize = size * 2;
10566
10552
  a.minDecibels = minDb;
10567
10553
  a.maxDecibels = maxDb;
@@ -10588,8 +10574,8 @@ var Sound = class {
10588
10574
  }
10589
10575
  // Map domain data to another range
10590
10576
  _domainTo(time, size, position = [0, 0], trim = [0, 0]) {
10591
- let data = time ? this.timeDomain() : this.freqDomain();
10592
- let g = new Group();
10577
+ const data = time ? this.timeDomain() : this.freqDomain();
10578
+ const g = new Group();
10593
10579
  for (let i = trim[0], len = data.length - trim[1]; i < len; i++) {
10594
10580
  g.push(new Pt(position[0] + size[0] * i / len, position[1] + size[1] * data[i] / 255));
10595
10581
  }
@@ -10648,7 +10634,7 @@ var Sound = class {
10648
10634
  this._ctx.resume();
10649
10635
  }
10650
10636
  if (this._type === "file") {
10651
- if (!!this._buffer) {
10637
+ if (this._buffer) {
10652
10638
  this._node.start(timeAt);
10653
10639
  this._timestamp = this._ctx.currentTime + timeAt;
10654
10640
  } else {
@@ -10673,7 +10659,7 @@ var Sound = class {
10673
10659
  if (this._playing)
10674
10660
  (this._outputNode || this._node).disconnect(this._ctx.destination);
10675
10661
  if (this._type === "file") {
10676
- if (!!this._buffer) {
10662
+ if (this._buffer) {
10677
10663
  if (this.progress < 1)
10678
10664
  this._node.stop();
10679
10665
  } else {