@thednp/dommatrix 3.0.6 → 3.1.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.
@@ -1,6 +1,6 @@
1
1
  //#region src/index.ts
2
- /** A model for JSONMatrix */
3
- const JSON_MATRIX = {
2
+ /** The property names of a JSONMatrix, used for compatibility checks */
3
+ const JSON_KEYS = Object.keys({
4
4
  a: 1,
5
5
  b: 0,
6
6
  c: 0,
@@ -25,14 +25,14 @@ const JSON_MATRIX = {
25
25
  m44: 1,
26
26
  is2D: true,
27
27
  isIdentity: true
28
- };
28
+ });
29
29
  /** Checks if an array is compatible with CSSMatrix */
30
30
  const isCompatibleArray = (array) => {
31
31
  return (array instanceof Float64Array || array instanceof Float32Array || Array.isArray(array) && array.every((x) => typeof x === "number")) && [6, 16].some((x) => array.length === x);
32
32
  };
33
33
  /** Checks if an object is compatible with CSSMatrix */
34
34
  const isCompatibleObject = (object) => {
35
- return typeof DOMMatrix !== "undefined" && object instanceof DOMMatrix || object instanceof CSSMatrix || typeof object === "object" && Object.keys(JSON_MATRIX).every((k) => object && k in object);
35
+ return typeof DOMMatrix !== "undefined" && object instanceof DOMMatrix || object instanceof CSSMatrix || typeof object === "object" && JSON_KEYS.every((k) => object && k in object);
36
36
  };
37
37
  /**
38
38
  * Creates a new mutable `CSSMatrix` instance given an array of 16/6 floating point values.
@@ -42,80 +42,106 @@ const isCompatibleObject = (object) => {
42
42
  * the result is a 3D matrix. Otherwise, a TypeError exception is thrown.
43
43
  *
44
44
  * @param array an `Array` to feed values from.
45
+ * @param target an optional matrix instance to write the values into; when omitted
46
+ * a new matrix is returned. Used internally by `setMatrixValue` to mutate in place.
45
47
  * @return the resulted matrix.
46
48
  */
47
- const fromArray = (array) => {
48
- const m = new CSSMatrix();
49
- const a = Array.from(array);
50
- if (!isCompatibleArray(a)) throw TypeError(`CSSMatrix: "${a.join(",")}" must be an array with 6/16 numbers.`);
49
+ const fromArray = (array, target) => {
50
+ if (!isCompatibleArray(array)) throw TypeError(`CSSMatrix: "${Array.from(array).join(",")}" must be an array with 6/16 numbers.`);
51
51
  // istanbul ignore else @preserve
52
- if (a.length === 16) {
53
- const [m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44] = a;
54
- m.m11 = m11;
55
- m.a = m11;
56
- m.m21 = m21;
57
- m.c = m21;
58
- m.m31 = m31;
59
- m.m41 = m41;
60
- m.e = m41;
61
- m.m12 = m12;
62
- m.b = m12;
63
- m.m22 = m22;
64
- m.d = m22;
65
- m.m32 = m32;
66
- m.m42 = m42;
67
- m.f = m42;
68
- m.m13 = m13;
69
- m.m23 = m23;
70
- m.m33 = m33;
71
- m.m43 = m43;
72
- m.m14 = m14;
73
- m.m24 = m24;
74
- m.m34 = m34;
75
- m.m44 = m44;
76
- } else if (a.length === 6) {
77
- const [M11, M12, M21, M22, M41, M42] = a;
78
- m.m11 = M11;
79
- m.a = M11;
80
- m.m12 = M12;
81
- m.b = M12;
82
- m.m21 = M21;
83
- m.c = M21;
84
- m.m22 = M22;
85
- m.d = M22;
86
- m.m41 = M41;
87
- m.e = M41;
88
- m.m42 = M42;
89
- m.f = M42;
52
+ if (array.length === 16) {
53
+ const [m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44] = array;
54
+ return writeValues(target ?? new CSSMatrix(), m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44);
90
55
  }
91
- return m;
56
+ const [M11, M12, M21, M22, M41, M42] = array;
57
+ return writeValues(target ?? new CSSMatrix(), M11, M12, 0, 0, M21, M22, 0, 0, 0, 0, 1, 0, M41, M42, 0, 1);
58
+ };
59
+ /**
60
+ * Internal helper that writes the 16 values of a matrix into a given `CSSMatrix`
61
+ * instance. This is the single place where all 22 aliases (`a`-`f` and `m11`-`m44`)
62
+ * are written, so every write path keeps the instance monomorphic.
63
+ *
64
+ * @param target the matrix instance to write the values into.
65
+ * @param m11 the `m11` value.
66
+ * @param m12 the `m12` value.
67
+ * @param m13 the `m13` value.
68
+ * @param m14 the `m14` value.
69
+ * @param m21 the `m21` value.
70
+ * @param m22 the `m22` value.
71
+ * @param m23 the `m23` value.
72
+ * @param m24 the `m24` value.
73
+ * @param m31 the `m31` value.
74
+ * @param m32 the `m32` value.
75
+ * @param m33 the `m33` value.
76
+ * @param m34 the `m34` value.
77
+ * @param m41 the `m41` value.
78
+ * @param m42 the `m42` value.
79
+ * @param m43 the `m43` value.
80
+ * @param m44 the `m44` value.
81
+ * @return the target matrix.
82
+ */
83
+ const writeValues = (target, m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) => {
84
+ target.m11 = m11;
85
+ target.a = m11;
86
+ target.m21 = m21;
87
+ target.c = m21;
88
+ target.m31 = m31;
89
+ target.m41 = m41;
90
+ target.e = m41;
91
+ target.m12 = m12;
92
+ target.b = m12;
93
+ target.m22 = m22;
94
+ target.d = m22;
95
+ target.m32 = m32;
96
+ target.m42 = m42;
97
+ target.f = m42;
98
+ target.m13 = m13;
99
+ target.m23 = m23;
100
+ target.m33 = m33;
101
+ target.m43 = m43;
102
+ target.m14 = m14;
103
+ target.m24 = m24;
104
+ target.m34 = m34;
105
+ target.m44 = m44;
106
+ return target;
107
+ };
108
+ /**
109
+ * Creates a new mutable `CSSMatrix` instance given the 16 values of the matrix.
110
+ * This internal helper skips the validation and intermediate array steps of
111
+ * `fromArray` and is used by the fast paths of the library.
112
+ *
113
+ * @param m11 the `m11` value.
114
+ * @param m12 the `m12` value.
115
+ * @param m13 the `m13` value.
116
+ * @param m14 the `m14` value.
117
+ * @param m21 the `m21` value.
118
+ * @param m22 the `m22` value.
119
+ * @param m23 the `m23` value.
120
+ * @param m24 the `m24` value.
121
+ * @param m31 the `m31` value.
122
+ * @param m32 the `m32` value.
123
+ * @param m33 the `m33` value.
124
+ * @param m34 the `m34` value.
125
+ * @param m41 the `m41` value.
126
+ * @param m42 the `m42` value.
127
+ * @param m43 the `m43` value.
128
+ * @param m44 the `m44` value.
129
+ * @return the resulted matrix.
130
+ */
131
+ const fromValues = (m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) => {
132
+ return writeValues(new CSSMatrix(), m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44);
92
133
  };
93
134
  /**
94
135
  * Creates a new mutable `CSSMatrix` instance given an existing matrix or a
95
136
  * `DOMMatrix` instance which provides the values for its properties.
96
137
  *
97
138
  * @param m the source matrix to feed values from.
139
+ * @param target an optional matrix instance to write the values into; when omitted
140
+ * a new matrix is returned. Used internally by `setMatrixValue` to mutate in place.
98
141
  * @return the resulted matrix.
99
142
  */
100
- const fromMatrix = (m) => {
101
- if (isCompatibleObject(m)) return fromArray([
102
- m.m11,
103
- m.m12,
104
- m.m13,
105
- m.m14,
106
- m.m21,
107
- m.m22,
108
- m.m23,
109
- m.m24,
110
- m.m31,
111
- m.m32,
112
- m.m33,
113
- m.m34,
114
- m.m41,
115
- m.m42,
116
- m.m43,
117
- m.m44
118
- ]);
143
+ const fromMatrix = (m, target) => {
144
+ if (isCompatibleObject(m)) return writeValues(target ?? new CSSMatrix(), m.m11, m.m12, m.m13, m.m14, m.m21, m.m22, m.m23, m.m24, m.m31, m.m32, m.m33, m.m34, m.m41, m.m42, m.m43, m.m44);
119
145
  throw TypeError(`CSSMatrix: "${JSON.stringify(m)}" is not a DOMMatrix / CSSMatrix / JSON compatible object.`);
120
146
  };
121
147
  /**
@@ -136,8 +162,13 @@ const fromString = (source) => {
136
162
  const str = String(source).replace(/\s/g, "");
137
163
  const m = new CSSMatrix();
138
164
  const invalidStringError = `CSSMatrix: invalid transform string "${source}"`;
139
- str.split(")").filter((f) => f).forEach((tf) => {
140
- const [prop, value] = tf.split("(");
165
+ const transformFn = /([\w-]+)\(([^)]*)\)/g;
166
+ let consumed = 0;
167
+ let match;
168
+ while (match = transformFn.exec(str)) {
169
+ const prop = match[1];
170
+ const value = match[2];
171
+ consumed += match[0].length;
141
172
  if (!value) throw TypeError(invalidStringError);
142
173
  const components = value.split(",").map((n) => n.includes("rad") ? parseFloat(n) * (180 / Math.PI) : parseFloat(n));
143
174
  const [x, y, z, a] = components;
@@ -189,7 +220,8 @@ const fromString = (source) => {
189
220
  m[method](...axeValues);
190
221
  }
191
222
  else throw TypeError(invalidStringError);
192
- });
223
+ }
224
+ if (consumed !== str.length) throw TypeError(invalidStringError);
193
225
  return m;
194
226
  };
195
227
  /**
@@ -407,14 +439,16 @@ const SkewY = (angle) => {
407
439
  return Skew(0, angle);
408
440
  };
409
441
  /**
410
- * Creates a new `CSSMatrix` resulted from the multiplication of two matrixes
411
- * and returns it. Both matrixes are not changed.
442
+ * Computes the multiplication of two matrixes and stores the result into the
443
+ * third matrix argument, which is also returned. Both source matrixes are
444
+ * not changed.
412
445
  *
413
446
  * @param m1 the first matrix.
414
447
  * @param m2 the second matrix.
448
+ * @param m the matrix to store the result into.
415
449
  * @return the resulted matrix.
416
450
  */
417
- const Multiply = (m1, m2) => {
451
+ const multiplyInto = (m1, m2, m) => {
418
452
  const m11 = m2.m11 * m1.m11 + m2.m12 * m1.m21 + m2.m13 * m1.m31 + m2.m14 * m1.m41;
419
453
  const m12 = m2.m11 * m1.m12 + m2.m12 * m1.m22 + m2.m13 * m1.m32 + m2.m14 * m1.m42;
420
454
  const m13 = m2.m11 * m1.m13 + m2.m12 * m1.m23 + m2.m13 * m1.m33 + m2.m14 * m1.m43;
@@ -431,24 +465,40 @@ const Multiply = (m1, m2) => {
431
465
  const m42 = m2.m41 * m1.m12 + m2.m42 * m1.m22 + m2.m43 * m1.m32 + m2.m44 * m1.m42;
432
466
  const m43 = m2.m41 * m1.m13 + m2.m42 * m1.m23 + m2.m43 * m1.m33 + m2.m44 * m1.m43;
433
467
  const m44 = m2.m41 * m1.m14 + m2.m42 * m1.m24 + m2.m43 * m1.m34 + m2.m44 * m1.m44;
434
- return fromArray([
435
- m11,
436
- m12,
437
- m13,
438
- m14,
439
- m21,
440
- m22,
441
- m23,
442
- m24,
443
- m31,
444
- m32,
445
- m33,
446
- m34,
447
- m41,
448
- m42,
449
- m43,
450
- m44
451
- ]);
468
+ m.m11 = m11;
469
+ m.a = m11;
470
+ m.m21 = m21;
471
+ m.c = m21;
472
+ m.m31 = m31;
473
+ m.m41 = m41;
474
+ m.e = m41;
475
+ m.m12 = m12;
476
+ m.b = m12;
477
+ m.m22 = m22;
478
+ m.d = m22;
479
+ m.m32 = m32;
480
+ m.m42 = m42;
481
+ m.f = m42;
482
+ m.m13 = m13;
483
+ m.m23 = m23;
484
+ m.m33 = m33;
485
+ m.m43 = m43;
486
+ m.m14 = m14;
487
+ m.m24 = m24;
488
+ m.m34 = m34;
489
+ m.m44 = m44;
490
+ return m;
491
+ };
492
+ /**
493
+ * Creates a new `CSSMatrix` resulted from the multiplication of two matrixes
494
+ * and returns it. Both matrixes are not changed.
495
+ *
496
+ * @param m1 the first matrix.
497
+ * @param m2 the second matrix.
498
+ * @return the resulted matrix.
499
+ */
500
+ const Multiply = (m1, m2) => {
501
+ return multiplyInto(m1, m2, new CSSMatrix());
452
502
  };
453
503
  /**
454
504
  * Creates and returns a new `DOMMatrix` compatible instance
@@ -497,6 +547,11 @@ var CSSMatrix = class {
497
547
  * * a 6/16 elements *Array*.
498
548
  */
499
549
  constructor(init) {
550
+ if (init) {
551
+ if (typeof init === "string" && init.length && init !== "none") return fromString(init);
552
+ if (Array.isArray(init) || init instanceof Float64Array || init instanceof Float32Array) return fromArray(init);
553
+ if (typeof init === "object") return fromMatrix(init);
554
+ }
500
555
  this.a = 1;
501
556
  this.b = 0;
502
557
  this.c = 0;
@@ -519,7 +574,6 @@ var CSSMatrix = class {
519
574
  this.m42 = 0;
520
575
  this.m43 = 0;
521
576
  this.m44 = 1;
522
- if (init) return this.setMatrixValue(init);
523
577
  return this;
524
578
  }
525
579
  /**
@@ -552,13 +606,19 @@ var CSSMatrix = class {
552
606
  * This method expects valid *matrix()* / *matrix3d()* string values, as well
553
607
  * as other transform functions like *translateX(10px)*.
554
608
  *
609
+ * The matrix is mutated in place (the same instance is returned), matching
610
+ * the behavior of the native `DOMMatrix.setMatrixValue()`.
611
+ *
555
612
  * @param source
556
- * @return the matrix instance
613
+ * @return the current matrix instance
557
614
  */
558
615
  setMatrixValue(source) {
559
- if (typeof source === "string" && source.length && source !== "none") return fromString(source);
560
- if (Array.isArray(source) || source instanceof Float64Array || source instanceof Float32Array) return fromArray(source);
561
- if (typeof source === "object") return fromMatrix(source);
616
+ if (typeof source === "string" && source.length && source !== "none") {
617
+ const m = fromString(source);
618
+ return writeValues(this, m.m11, m.m12, m.m13, m.m14, m.m21, m.m22, m.m23, m.m24, m.m31, m.m32, m.m33, m.m34, m.m41, m.m42, m.m43, m.m44);
619
+ }
620
+ if (Array.isArray(source) || source instanceof Float64Array || source instanceof Float32Array) return fromArray(source, this);
621
+ if (typeof source === "object") return fromMatrix(source, this);
562
622
  return this;
563
623
  }
564
624
  /**
@@ -570,7 +630,31 @@ var CSSMatrix = class {
570
630
  * @return an *Array* representation of the matrix
571
631
  */
572
632
  toFloat32Array(is2D) {
573
- return Float32Array.from(toArray(this, is2D));
633
+ return is2D ? new Float32Array([
634
+ this.a,
635
+ this.b,
636
+ this.c,
637
+ this.d,
638
+ this.e,
639
+ this.f
640
+ ]) : new Float32Array([
641
+ this.m11,
642
+ this.m12,
643
+ this.m13,
644
+ this.m14,
645
+ this.m21,
646
+ this.m22,
647
+ this.m23,
648
+ this.m24,
649
+ this.m31,
650
+ this.m32,
651
+ this.m33,
652
+ this.m34,
653
+ this.m41,
654
+ this.m42,
655
+ this.m43,
656
+ this.m44
657
+ ]);
574
658
  }
575
659
  /**
576
660
  * Returns a *Float64Array* containing elements which comprise the matrix.
@@ -581,7 +665,31 @@ var CSSMatrix = class {
581
665
  * @return an *Array* representation of the matrix
582
666
  */
583
667
  toFloat64Array(is2D) {
584
- return Float64Array.from(toArray(this, is2D));
668
+ return is2D ? new Float64Array([
669
+ this.a,
670
+ this.b,
671
+ this.c,
672
+ this.d,
673
+ this.e,
674
+ this.f
675
+ ]) : new Float64Array([
676
+ this.m11,
677
+ this.m12,
678
+ this.m13,
679
+ this.m14,
680
+ this.m21,
681
+ this.m22,
682
+ this.m23,
683
+ this.m24,
684
+ this.m31,
685
+ this.m32,
686
+ this.m33,
687
+ this.m34,
688
+ this.m41,
689
+ this.m42,
690
+ this.m43,
691
+ this.m44
692
+ ]);
585
693
  }
586
694
  /**
587
695
  * Creates and returns a string representation of the matrix in `CSS` matrix syntax,
@@ -610,7 +718,28 @@ var CSSMatrix = class {
610
718
  toJSON() {
611
719
  const { is2D, isIdentity } = this;
612
720
  return {
613
- ...this,
721
+ a: this.a,
722
+ b: this.b,
723
+ c: this.c,
724
+ d: this.d,
725
+ e: this.e,
726
+ f: this.f,
727
+ m11: this.m11,
728
+ m12: this.m12,
729
+ m13: this.m13,
730
+ m14: this.m14,
731
+ m21: this.m21,
732
+ m22: this.m22,
733
+ m23: this.m23,
734
+ m24: this.m24,
735
+ m31: this.m31,
736
+ m32: this.m32,
737
+ m33: this.m33,
738
+ m34: this.m34,
739
+ m41: this.m41,
740
+ m42: this.m42,
741
+ m43: this.m43,
742
+ m44: this.m44,
614
743
  is2D,
615
744
  isIdentity
616
745
  };
@@ -638,7 +767,14 @@ var CSSMatrix = class {
638
767
  * @return The resulted matrix
639
768
  */
640
769
  translate(x, y, z) {
641
- return this.multiply(Translate(x, y ?? 0, z ?? 0));
770
+ const ty = y ?? 0;
771
+ const tz = z ?? 0;
772
+ const { m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44 } = this;
773
+ const n41 = x * m11 + ty * m21 + tz * m31 + m41;
774
+ const n42 = x * m12 + ty * m22 + tz * m32 + m42;
775
+ const n43 = x * m13 + ty * m23 + tz * m33 + m43;
776
+ const n44 = x * m14 + ty * m24 + tz * m34 + m44;
777
+ return fromValues(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, n41, n42, n43, n44);
642
778
  }
643
779
  /**
644
780
  * The scale method returns a new matrix which is this matrix post multiplied by
@@ -652,7 +788,10 @@ var CSSMatrix = class {
652
788
  * @return The resulted matrix
653
789
  */
654
790
  scale(x, y, z) {
655
- return this.multiply(Scale(x, y ?? x, z ?? 1));
791
+ const sy = y ?? x;
792
+ const sz = z ?? 1;
793
+ const { m41, m42, m43, m44 } = this;
794
+ return fromValues(this.m11 * x, this.m12 * x, this.m13 * x, this.m14 * x, this.m21 * sy, this.m22 * sy, this.m23 * sy, this.m24 * sy, this.m31 * sz, this.m32 * sz, this.m33 * sz, this.m34 * sz, m41, m42, m43, m44);
656
795
  }
657
796
  /**
658
797
  * The rotate method returns a new matrix which is this matrix post multiplied
@@ -707,7 +846,7 @@ var CSSMatrix = class {
707
846
  * @return The resulted matrix
708
847
  */
709
848
  skewX(angle) {
710
- return this.multiply(SkewX(angle));
849
+ return this.skew(angle, 0);
711
850
  }
712
851
  /**
713
852
  * Specifies a skew transformation along the `y-axis` by the given angle.
@@ -717,7 +856,7 @@ var CSSMatrix = class {
717
856
  * @return The resulted matrix
718
857
  */
719
858
  skewY(angle) {
720
- return this.multiply(SkewY(angle));
859
+ return this.skew(0, angle);
721
860
  }
722
861
  /**
723
862
  * Specifies a skew transformation along both the `x-axis` and `y-axis`.
@@ -728,7 +867,10 @@ var CSSMatrix = class {
728
867
  * @return The resulted matrix
729
868
  */
730
869
  skew(angleX, angleY) {
731
- return this.multiply(Skew(angleX, angleY));
870
+ const tX = angleX ? Math.tan(angleX * Math.PI / 180) : 0;
871
+ const tY = angleY ? Math.tan(angleY * Math.PI / 180) : 0;
872
+ const { m11, m12, m13, m14, m21, m22, m23, m24 } = this;
873
+ return fromValues(m11 + tY * m21, m12 + tY * m22, m13 + tY * m23, m14 + tY * m24, tX * m11 + m21, tX * m12 + m22, tX * m13 + m23, tX * m14 + m24, this.m31, this.m32, this.m33, this.m34, this.m41, this.m42, this.m43, this.m44);
732
874
  }
733
875
  /**
734
876
  * Modifies the current matrix by post-multiplying it with another matrix.
@@ -738,8 +880,7 @@ var CSSMatrix = class {
738
880
  * @return this matrix (modified)
739
881
  */
740
882
  multiplySelf(m2) {
741
- const result = Multiply(this, m2);
742
- Object.assign(this, result);
883
+ multiplyInto(this, m2, this);
743
884
  return this;
744
885
  }
745
886
  /**
@@ -752,7 +893,20 @@ var CSSMatrix = class {
752
893
  * @return this matrix (modified)
753
894
  */
754
895
  translateSelf(x, y, z) {
755
- return this.multiplySelf(Translate(x, y ?? 0, z ?? 0));
896
+ const ty = y ?? 0;
897
+ const tz = z ?? 0;
898
+ const { m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44 } = this;
899
+ const n41 = x * m11 + ty * m21 + tz * m31 + m41;
900
+ const n42 = x * m12 + ty * m22 + tz * m32 + m42;
901
+ const n43 = x * m13 + ty * m23 + tz * m33 + m43;
902
+ const n44 = x * m14 + ty * m24 + tz * m34 + m44;
903
+ this.m41 = n41;
904
+ this.e = n41;
905
+ this.m42 = n42;
906
+ this.f = n42;
907
+ this.m43 = n43;
908
+ this.m44 = n44;
909
+ return this;
756
910
  }
757
911
  /**
758
912
  * Modifies the current matrix by post-multiplying it with a scale matrix.
@@ -764,7 +918,25 @@ var CSSMatrix = class {
764
918
  * @return this matrix (modified)
765
919
  */
766
920
  scaleSelf(x, y, z) {
767
- return this.multiplySelf(Scale(x, y ?? x, z ?? 1));
921
+ const sy = y ?? x;
922
+ const sz = z ?? 1;
923
+ this.m11 *= x;
924
+ this.a *= x;
925
+ this.m12 *= x;
926
+ this.b *= x;
927
+ this.m13 *= x;
928
+ this.m14 *= x;
929
+ this.m21 *= sy;
930
+ this.c *= sy;
931
+ this.m22 *= sy;
932
+ this.d *= sy;
933
+ this.m23 *= sy;
934
+ this.m24 *= sy;
935
+ this.m31 *= sz;
936
+ this.m32 *= sz;
937
+ this.m33 *= sz;
938
+ this.m34 *= sz;
939
+ return this;
768
940
  }
769
941
  /**
770
942
  * Modifies the current matrix by post-multiplying it with a rotation matrix.
@@ -815,7 +987,7 @@ var CSSMatrix = class {
815
987
  * @return this matrix (modified)
816
988
  */
817
989
  skewXSelf(angle) {
818
- return this.multiplySelf(SkewX(angle));
990
+ return this.skewSelf(angle, 0);
819
991
  }
820
992
  /**
821
993
  * Modifies the current matrix by post-multiplying it with a skewY matrix.
@@ -825,7 +997,7 @@ var CSSMatrix = class {
825
997
  * @return this matrix (modified)
826
998
  */
827
999
  skewYSelf(angle) {
828
- return this.multiplySelf(SkewY(angle));
1000
+ return this.skewSelf(0, angle);
829
1001
  }
830
1002
  /**
831
1003
  * Modifies the current matrix by post-multiplying it with a skew matrix.
@@ -836,7 +1008,30 @@ var CSSMatrix = class {
836
1008
  * @return this matrix (modified)
837
1009
  */
838
1010
  skewSelf(angleX, angleY) {
839
- return this.multiplySelf(Skew(angleX, angleY));
1011
+ const tX = angleX ? Math.tan(angleX * Math.PI / 180) : 0;
1012
+ const tY = angleY ? Math.tan(angleY * Math.PI / 180) : 0;
1013
+ const { m11, m12, m13, m14, m21, m22, m23, m24 } = this;
1014
+ const n11 = m11 + tY * m21;
1015
+ const n12 = m12 + tY * m22;
1016
+ const n13 = m13 + tY * m23;
1017
+ const n14 = m14 + tY * m24;
1018
+ const n21 = tX * m11 + m21;
1019
+ const n22 = tX * m12 + m22;
1020
+ const n23 = tX * m13 + m23;
1021
+ const n24 = tX * m14 + m24;
1022
+ this.m11 = n11;
1023
+ this.a = n11;
1024
+ this.m12 = n12;
1025
+ this.b = n12;
1026
+ this.m13 = n13;
1027
+ this.m14 = n14;
1028
+ this.m21 = n21;
1029
+ this.c = n21;
1030
+ this.m22 = n22;
1031
+ this.d = n22;
1032
+ this.m23 = n23;
1033
+ this.m24 = n24;
1034
+ return this;
840
1035
  }
841
1036
  /**
842
1037
  * Transforms a specified vector using the matrix, returning a new