toosoon-utils 4.2.3 → 4.3.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.
Files changed (43) hide show
  1. package/README.md +501 -603
  2. package/lib/colors.d.ts +147 -66
  3. package/lib/colors.js +149 -63
  4. package/lib/constants.js +1 -1
  5. package/lib/dom.d.ts +1 -1
  6. package/lib/dom.js +1 -1
  7. package/lib/extras/colors/Color.d.ts +406 -0
  8. package/lib/extras/colors/Color.js +546 -0
  9. package/lib/extras/colors/ColorPalette.d.ts +105 -0
  10. package/lib/extras/colors/ColorPalette.js +124 -0
  11. package/lib/extras/colors/ColorScale.d.ts +257 -0
  12. package/lib/extras/colors/ColorScale.js +347 -0
  13. package/lib/extras/colors/_ColorScale.d.ts +62 -0
  14. package/lib/extras/colors/_ColorScale.js +156 -0
  15. package/lib/extras/colors/index.d.ts +3 -0
  16. package/lib/extras/colors/index.js +3 -0
  17. package/lib/extras/frame-rate/FrameRate.d.ts +12 -9
  18. package/lib/extras/frame-rate/FrameRate.js +10 -7
  19. package/lib/extras/geometry/Vector.d.ts +1 -1
  20. package/lib/extras/geometry/Vector2.d.ts +17 -11
  21. package/lib/extras/geometry/Vector2.js +29 -23
  22. package/lib/extras/geometry/Vector3.d.ts +5 -5
  23. package/lib/extras/geometry/Vector3.js +10 -10
  24. package/lib/extras/paths/Path.d.ts +3 -3
  25. package/lib/extras/paths/Path.js +10 -10
  26. package/lib/extras/paths/PathContext.d.ts +7 -10
  27. package/lib/extras/paths/PathContext.js +79 -102
  28. package/lib/extras/paths/PathSVG.d.ts +31 -25
  29. package/lib/extras/paths/PathSVG.js +36 -39
  30. package/lib/extras/paths/index.d.ts +1 -1
  31. package/lib/geometry.d.ts +7 -7
  32. package/lib/geometry.js +13 -13
  33. package/lib/maths.d.ts +19 -13
  34. package/lib/maths.js +23 -17
  35. package/lib/prng.d.ts +4 -4
  36. package/lib/prng.js +4 -4
  37. package/lib/random.d.ts +4 -4
  38. package/lib/random.js +4 -4
  39. package/lib/strings.d.ts +14 -8
  40. package/lib/strings.js +14 -8
  41. package/lib/tsconfig.tsbuildinfo +1 -1
  42. package/lib/types.d.ts +15 -8
  43. package/package.json +14 -14
@@ -19,6 +19,7 @@ export default class Vector2 implements Vector<Vec2> {
19
19
  * Y-axis value of this vector
20
20
  */
21
21
  y: number;
22
+ [Symbol.iterator](): Iterator<number>;
22
23
  /**
23
24
  * @param {number} [x=0] X-axis value
24
25
  * @param {number} [y=0] Y-axis value
@@ -35,7 +36,7 @@ export default class Vector2 implements Vector<Vec2> {
35
36
  /**
36
37
  * Set a given scalar value to all values of this vector
37
38
  *
38
- * @param {number} scalar Value to set for all vector values
39
+ * @param {number} scalar Value to set for all values
39
40
  * @returns {this}
40
41
  */
41
42
  setScalar(scalar: number): this;
@@ -193,13 +194,13 @@ export default class Vector2 implements Vector<Vec2> {
193
194
  */
194
195
  rotateAround(center: Vec2, angle: number): this;
195
196
  /**
196
- * Interpolate this vector values between a given vector and this vector
197
+ * Linearly interpolate this vector values towards a given vector values
197
198
  *
198
- * @param {Vector2|Point2} vector Vector to interpolate values towards
199
199
  * @param {number} t Normalized time value to interpolate
200
+ * @param {Vector2|Point2} vector Vector to interpolate values towards
200
201
  * @returns {this}
201
202
  */
202
- lerp([x, y]: Vec2, t: number): this;
203
+ lerp(t: number, [x, y]: Vec2): this;
203
204
  /**
204
205
  * Convert this vector to a unit vector
205
206
  *
@@ -311,7 +312,7 @@ export default class Vector2 implements Vector<Vec2> {
311
312
  * Set this vector values from a given array
312
313
  *
313
314
  * @param {number[]} values Values to set
314
- * @returns
315
+ * @returns {this}
315
316
  */
316
317
  fromArray([x, y]: number[]): this;
317
318
  /**
@@ -335,6 +336,16 @@ export default class Vector2 implements Vector<Vec2> {
335
336
  * @returns {Vector2}
336
337
  */
337
338
  clone(): Vector2;
339
+ /**
340
+ * X-axis value of this vector
341
+ */
342
+ set width(width: number);
343
+ get width(): number;
344
+ /**
345
+ * Y-axis value of this vector
346
+ */
347
+ set height(height: number);
348
+ get height(): number;
338
349
  /**
339
350
  * Add two vectors
340
351
  *
@@ -377,7 +388,7 @@ export default class Vector2 implements Vector<Vec2> {
377
388
  */
378
389
  static rotate([vx, vy]: Vec2, [cx, cy]: Vec2, angle: number): Point2;
379
390
  /**
380
- * Interpolate a point between two vectors
391
+ * Linearly interpolate a point between two vectors
381
392
  *
382
393
  * @param {number} t Normalized time value to interpolate
383
394
  * @param {Vector2|Point2} min Minimum boundaries
@@ -478,10 +489,5 @@ export default class Vector2 implements Vector<Vec2> {
478
489
  * @returns {Point2}
479
490
  */
480
491
  static fromCircularCoords(angle: number, radius?: number): Point2;
481
- set width(width: number);
482
- get width(): number;
483
- set height(height: number);
484
- get height(): number;
485
- [Symbol.iterator](): Iterator<number>;
486
492
  }
487
493
  export {};
@@ -18,6 +18,10 @@ export default class Vector2 {
18
18
  * Y-axis value of this vector
19
19
  */
20
20
  y;
21
+ *[Symbol.iterator]() {
22
+ yield this.x;
23
+ yield this.y;
24
+ }
21
25
  /**
22
26
  * @param {number} [x=0] X-axis value
23
27
  * @param {number} [y=0] Y-axis value
@@ -41,7 +45,7 @@ export default class Vector2 {
41
45
  /**
42
46
  * Set a given scalar value to all values of this vector
43
47
  *
44
- * @param {number} scalar Value to set for all vector values
48
+ * @param {number} scalar Value to set for all values
45
49
  * @returns {this}
46
50
  */
47
51
  setScalar(scalar) {
@@ -306,13 +310,13 @@ export default class Vector2 {
306
310
  return this.set(...Vector2.rotate(this, center, angle));
307
311
  }
308
312
  /**
309
- * Interpolate this vector values between a given vector and this vector
313
+ * Linearly interpolate this vector values towards a given vector values
310
314
  *
311
- * @param {Vector2|Point2} vector Vector to interpolate values towards
312
315
  * @param {number} t Normalized time value to interpolate
316
+ * @param {Vector2|Point2} vector Vector to interpolate values towards
313
317
  * @returns {this}
314
318
  */
315
- lerp([x, y], t) {
319
+ lerp(t, [x, y]) {
316
320
  this.x += (x - this.x) * t;
317
321
  this.y += (y - this.y) * t;
318
322
  return this;
@@ -467,7 +471,7 @@ export default class Vector2 {
467
471
  * Set this vector values from a given array
468
472
  *
469
473
  * @param {number[]} values Values to set
470
- * @returns
474
+ * @returns {this}
471
475
  */
472
476
  fromArray([x, y]) {
473
477
  this.x = x;
@@ -503,6 +507,24 @@ export default class Vector2 {
503
507
  clone() {
504
508
  return new Vector2(this.x, this.y);
505
509
  }
510
+ /**
511
+ * X-axis value of this vector
512
+ */
513
+ set width(width) {
514
+ this.x = width;
515
+ }
516
+ get width() {
517
+ return this.x;
518
+ }
519
+ /**
520
+ * Y-axis value of this vector
521
+ */
522
+ set height(height) {
523
+ this.y = height;
524
+ }
525
+ get height() {
526
+ return this.y;
527
+ }
506
528
  /**
507
529
  * Add two vectors
508
530
  *
@@ -569,7 +591,7 @@ export default class Vector2 {
569
591
  return [x, y];
570
592
  }
571
593
  /**
572
- * Interpolate a point between two vectors
594
+ * Linearly interpolate a point between two vectors
573
595
  *
574
596
  * @param {number} t Normalized time value to interpolate
575
597
  * @param {Vector2|Point2} min Minimum boundaries
@@ -639,7 +661,7 @@ export default class Vector2 {
639
661
  * @returns {number} Computed Euclidean distance
640
662
  */
641
663
  static distance(vector1, vector2) {
642
- return Math.sqrt(Vector2.squaredDistance(vector1, vector2));
664
+ return Math.sqrt(this.squaredDistance(vector1, vector2));
643
665
  }
644
666
  /**
645
667
  * Calculate the squared distance between two vectors
@@ -702,20 +724,4 @@ export default class Vector2 {
702
724
  const y = radius * Math.sin(angle);
703
725
  return [x, y];
704
726
  }
705
- set width(width) {
706
- this.x = width;
707
- }
708
- get width() {
709
- return this.x;
710
- }
711
- set height(height) {
712
- this.y = height;
713
- }
714
- get height() {
715
- return this.y;
716
- }
717
- *[Symbol.iterator]() {
718
- yield this.x;
719
- yield this.y;
720
- }
721
727
  }
@@ -23,6 +23,7 @@ export default class Vector3 implements Vector<Vec3> {
23
23
  * Z-axis value of this vector
24
24
  */
25
25
  z: number;
26
+ [Symbol.iterator](): Iterator<number>;
26
27
  /**
27
28
  * @param {number} [x=0] X-axis value
28
29
  * @param {number} [y=0] Y-axis value
@@ -198,13 +199,13 @@ export default class Vector3 implements Vector<Vec3> {
198
199
  */
199
200
  negate(): this;
200
201
  /**
201
- * Interpolate this vector values between a given vector and this vector
202
+ * Linearly interpolate this vector values towards a given vector values
202
203
  *
203
- * @param {Vector3|Point3} vector Vector to interpolate values towards
204
204
  * @param {number} t Normalized time value to interpolate
205
+ * @param {Vector3|Point3} vector Vector to interpolate values towards
205
206
  * @returns {this}
206
207
  */
207
- lerp([x, y, z]: Vec3, t: number): this;
208
+ lerp(t: number, [x, y, z]: Vec3): this;
208
209
  /**
209
210
  * Convert this vector to a unit vector
210
211
  *
@@ -384,7 +385,7 @@ export default class Vector3 implements Vector<Vec3> {
384
385
  */
385
386
  static divide([x1, y1, z1]: Vec3, [x2, y2, z2]: Vec3): Point3;
386
387
  /**
387
- * Interpolate a point between two vectors
388
+ * Linearly interpolate a point between two vectors
388
389
  *
389
390
  * @param {number} t Normalized time value to interpolate
390
391
  * @param {Vector3|Point3} min Minimum boundaries
@@ -488,6 +489,5 @@ export default class Vector3 implements Vector<Vec3> {
488
489
  * @returns {Point3}
489
490
  */
490
491
  static fromCylindricalCoords(theta: number, y: number, radius?: number): Point3;
491
- [Symbol.iterator](): Iterator<number>;
492
492
  }
493
493
  export {};
@@ -22,6 +22,11 @@ export default class Vector3 {
22
22
  * Z-axis value of this vector
23
23
  */
24
24
  z;
25
+ *[Symbol.iterator]() {
26
+ yield this.x;
27
+ yield this.y;
28
+ yield this.z;
29
+ }
25
30
  /**
26
31
  * @param {number} [x=0] X-axis value
27
32
  * @param {number} [y=0] Y-axis value
@@ -339,13 +344,13 @@ export default class Vector3 {
339
344
  return this;
340
345
  }
341
346
  /**
342
- * Interpolate this vector values between a given vector and this vector
347
+ * Linearly interpolate this vector values towards a given vector values
343
348
  *
344
- * @param {Vector3|Point3} vector Vector to interpolate values towards
345
349
  * @param {number} t Normalized time value to interpolate
350
+ * @param {Vector3|Point3} vector Vector to interpolate values towards
346
351
  * @returns {this}
347
352
  */
348
- lerp([x, y, z], t) {
353
+ lerp(t, [x, y, z]) {
349
354
  this.x += (x - this.x) * t;
350
355
  this.y += (y - this.y) * t;
351
356
  this.z += (z - this.z) * t;
@@ -618,7 +623,7 @@ export default class Vector3 {
618
623
  return [x, y, z];
619
624
  }
620
625
  /**
621
- * Interpolate a point between two vectors
626
+ * Linearly interpolate a point between two vectors
622
627
  *
623
628
  * @param {number} t Normalized time value to interpolate
624
629
  * @param {Vector3|Point3} min Minimum boundaries
@@ -691,7 +696,7 @@ export default class Vector3 {
691
696
  * @returns {number} Computed Euclidean distance
692
697
  */
693
698
  static distance(vector1, vector2) {
694
- return Math.sqrt(Vector3.squaredDistance(vector1, vector2));
699
+ return Math.sqrt(this.squaredDistance(vector1, vector2));
695
700
  }
696
701
  /**
697
702
  * Calculate the squared distance between two vectors
@@ -770,9 +775,4 @@ export default class Vector3 {
770
775
  const z = radius * Math.cos(theta);
771
776
  return [x, y, z];
772
777
  }
773
- *[Symbol.iterator]() {
774
- yield this.x;
775
- yield this.y;
776
- yield this.z;
777
- }
778
778
  }
@@ -7,13 +7,13 @@ import { type Vector, Vector2, Vector3 } from '../geometry';
7
7
  * @class Path
8
8
  * @extends Curve
9
9
  */
10
- export default class Path<V extends Vector = Vector2 | Vector3, S extends Curve<V> = Curve<V>> extends Curve<V> {
10
+ export default class Path<V extends Vector = Vector2 | Vector3, C extends Curve<V> = Curve<V>> extends Curve<V> {
11
11
  readonly isPath = true;
12
12
  readonly type: string;
13
13
  /**
14
14
  * Array of curves composing this path
15
15
  */
16
- subpaths: S[];
16
+ curves: C[];
17
17
  /**
18
18
  * Array of points composing this path
19
19
  */
@@ -30,7 +30,7 @@ export default class Path<V extends Vector = Vector2 | Vector3, S extends Curve<
30
30
  *
31
31
  * @param {Curve} curve Curve to add
32
32
  */
33
- add(curve: S): void;
33
+ add(curve: C): void;
34
34
  /**
35
35
  * Interpolate a point on this path
36
36
  *
@@ -12,7 +12,7 @@ export default class Path extends Curve {
12
12
  /**
13
13
  * Array of curves composing this path
14
14
  */
15
- subpaths = [];
15
+ curves = [];
16
16
  /**
17
17
  * Array of points composing this path
18
18
  */
@@ -31,7 +31,7 @@ export default class Path extends Curve {
31
31
  * @param {Curve} curve Curve to add
32
32
  */
33
33
  add(curve) {
34
- this.subpaths.push(curve);
34
+ this.curves.push(curve);
35
35
  }
36
36
  /**
37
37
  * Interpolate a point on this path
@@ -46,7 +46,7 @@ export default class Path extends Curve {
46
46
  while (i < curveLengths.length) {
47
47
  if (curveLengths[i] >= d) {
48
48
  const delta = curveLengths[i] - d;
49
- const curve = this.subpaths[i];
49
+ const curve = this.curves[i];
50
50
  const segmentLength = curve.getLength();
51
51
  const u = segmentLength === 0 ? 0 : 1 - delta / segmentLength;
52
52
  return curve.getPointAt(u);
@@ -54,7 +54,7 @@ export default class Path extends Curve {
54
54
  i++;
55
55
  }
56
56
  console.warn(`Path.getPoint()`, `No point found in curve.`, this);
57
- return this.subpaths[0].getPoint(0);
57
+ return this.curves[0].getPoint(0);
58
58
  }
59
59
  /**
60
60
  * Compute the curve shape into an array of points
@@ -65,8 +65,8 @@ export default class Path extends Curve {
65
65
  getPoints(divisions = 40) {
66
66
  const points = [];
67
67
  let lastPoint = null;
68
- for (let i = 0; i < this.subpaths.length; i++) {
69
- const curve = this.subpaths[i];
68
+ for (let i = 0; i < this.curves.length; i++) {
69
+ const curve = this.curves[i];
70
70
  let resolution = divisions;
71
71
  if (curve instanceof LineCurve || curve instanceof LineCurve3) {
72
72
  resolution = 1;
@@ -80,7 +80,7 @@ export default class Path extends Curve {
80
80
  else if (curve instanceof EllipseCurve) {
81
81
  resolution *= 2;
82
82
  }
83
- const pts = this.subpaths[i].getPoints(resolution);
83
+ const pts = this.curves[i].getPoints(resolution);
84
84
  for (let j = 0; j < pts.length; j++) {
85
85
  const point = pts[j];
86
86
  if (point?.equals(lastPoint))
@@ -127,13 +127,13 @@ export default class Path extends Curve {
127
127
  * @returns {number[]}
128
128
  */
129
129
  getCurveLengths() {
130
- if (this._cacheArcLengths.length === this.subpaths.length) {
130
+ if (this._cacheArcLengths.length === this.curves.length) {
131
131
  return this._cacheArcLengths;
132
132
  }
133
133
  const lengths = [];
134
134
  let sums = 0;
135
- for (let i = 0, j = this.subpaths.length; i < j; i++) {
136
- sums += this.subpaths[i].getLength();
135
+ for (let i = 0, j = this.curves.length; i < j; i++) {
136
+ sums += this.curves[i].getLength();
137
137
  lengths.push(sums);
138
138
  }
139
139
  this._cacheArcLengths = lengths;
@@ -12,8 +12,9 @@ import Path from './Path';
12
12
  export default class PathContext extends Path<Vector2> implements CanvasRenderingContext2D {
13
13
  protected _currentPosition: Vector2;
14
14
  protected _currentTransform: DOMMatrix;
15
- protected _positionTransform: DOMMatrix;
16
15
  private _transformStack;
16
+ readonly autoClose: false;
17
+ constructor();
17
18
  /**
18
19
  * Create a path from a given list of points
19
20
  *
@@ -134,7 +135,7 @@ export default class PathContext extends Path<Vector2> implements CanvasRenderin
134
135
  arc(cx: number, cy: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
135
136
  /**
136
137
  * Draw an Arc curve from the current position, tangential to the 2 segments created by both control points
137
- * Add an instance of {@link ArcCurve} to this path
138
+ * Add an instance of {@link EllipseCurve} to this path
138
139
  *
139
140
  * @param {number} x1 X-axis coordinate of the first control point
140
141
  * @param {number} y1 Y-axis coordinate of the first control point
@@ -180,22 +181,18 @@ export default class PathContext extends Path<Vector2> implements CanvasRenderin
180
181
  reset(): void;
181
182
  protected _hasCurrentPosition(): boolean;
182
183
  protected _setCurrentPosition(x: number, y: number): this;
183
- protected _transformPoint(point: Point2, matrix?: DOMMatrix): Point2;
184
- protected _transformPoints(points: Point2[], matrix?: DOMMatrix): Point2[];
185
- protected _transformVector(vector: Point2, matrix?: DOMMatrix): Point2;
186
- protected _transformEllipse(cx: number, cy: number, rx: number, ry: number, rotation: number, matrix?: DOMMatrix): [number, number, number, number, number];
187
- protected _inversePoint(point: Point2, matrix?: DOMMatrix): Point2;
184
+ protected _transformPoint(point: Point2): Point2;
185
+ protected _transformPoints(points: Point2[]): Point2[];
186
+ protected _transformVector(vector: Point2): Point2;
187
+ protected _transformEllipse(cx: number, cy: number, rx: number, ry: number, rotation: number): [number, number, number, number, number];
188
188
  protected get _translateX(): number;
189
189
  protected get _translateY(): number;
190
190
  protected get _scaleX(): number;
191
191
  protected get _scaleY(): number;
192
192
  protected get _rotation(): number;
193
- protected get _skewX(): number;
194
- protected get _skewY(): number;
195
193
  protected get _isTranslated(): boolean;
196
194
  protected get _isScaled(): boolean;
197
195
  protected get _isRotated(): boolean;
198
- protected get _isSkewed(): boolean;
199
196
  protected get _isUniform(): boolean;
200
197
  protected get _isIdentity(): boolean;
201
198
  canvas: CanvasRenderingContext2D['canvas'];