@thednp/dommatrix 3.0.4 → 3.0.6

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 +1,514 @@
1
- export { }
1
+ //#region src/types.d.ts
2
+ /** A DOMMPoint compatible Tuple. */
3
+ interface PointTuple {
4
+ x: number;
5
+ y: number;
6
+ z: number;
7
+ w: number;
8
+ }
9
+ /** The result of **CSSMatrix.toJSON()** / **DOMMatrix.toJSON()** instance calls. */
10
+ interface JSONMatrix {
11
+ m11: number;
12
+ m12: number;
13
+ m13: number;
14
+ m14: number;
15
+ m21: number;
16
+ m22: number;
17
+ m23: number;
18
+ m24: number;
19
+ m31: number;
20
+ m32: number;
21
+ m33: number;
22
+ m34: number;
23
+ m41: number;
24
+ m42: number;
25
+ m43: number;
26
+ m44: number;
27
+ a: number;
28
+ b: number;
29
+ c: number;
30
+ d: number;
31
+ e: number;
32
+ f: number;
33
+ is2D: boolean;
34
+ isIdentity: boolean;
35
+ }
36
+ /** An array of 6 numbers representing a 2D matrix. */
37
+ type Matrix = [number, number, number, number, number, number];
38
+ /** An array of 16 numbers representing a 3D matrix. */
39
+ type Matrix3d = [number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number];
40
+ /** All CSSMatrix compatible initialization values. */
41
+ type CSSMatrixInput = string | number[] | Matrix | Matrix3d | CSSMatrix | DOMMatrix | JSONMatrix | Float32Array | Float64Array;
42
+ //#endregion
43
+ //#region src/index.d.ts
44
+ /** Checks if an array is compatible with CSSMatrix */
45
+ declare const isCompatibleArray: (array?: unknown) => array is Matrix | Matrix3d | Float32Array | Float64Array;
46
+ /** Checks if an object is compatible with CSSMatrix */
47
+ declare const isCompatibleObject: (object?: unknown) => object is CSSMatrix | DOMMatrix | JSONMatrix;
48
+ /**
49
+ * Creates a new mutable `CSSMatrix` instance given an array of 16/6 floating point values.
50
+ * This static method invalidates arrays that contain non-number elements.
51
+ *
52
+ * If the array has six values, the result is a 2D matrix; if the array has 16 values,
53
+ * the result is a 3D matrix. Otherwise, a TypeError exception is thrown.
54
+ *
55
+ * @param array an `Array` to feed values from.
56
+ * @return the resulted matrix.
57
+ */
58
+ declare const fromArray: (array: number[] | Float32Array | Float64Array) => CSSMatrix;
59
+ /**
60
+ * Creates a new mutable `CSSMatrix` instance given an existing matrix or a
61
+ * `DOMMatrix` instance which provides the values for its properties.
62
+ *
63
+ * @param m the source matrix to feed values from.
64
+ * @return the resulted matrix.
65
+ */
66
+ declare const fromMatrix: (m: CSSMatrix | DOMMatrix | JSONMatrix) => CSSMatrix;
67
+ /**
68
+ * Creates a new mutable `CSSMatrix` given any valid CSS transform string,
69
+ * or what we call `TransformList`:
70
+ *
71
+ * * `matrix(a, b, c, d, e, f)` - valid matrix() transform function
72
+ * * `matrix3d(m11, m12, m13, ...m44)` - valid matrix3d() transform function
73
+ * * `translate(tx, ty) rotateX(alpha)` - any valid transform function(s)
74
+ *
75
+ * @copyright thednp © 2021
76
+ *
77
+ * @param source valid CSS transform string syntax.
78
+ * @return the resulted matrix.
79
+ */
80
+ declare const fromString: (source: string) => CSSMatrix;
81
+ /**
82
+ * Returns an *Array* containing elements which comprise the matrix.
83
+ * The method can return either the 16 elements or the 6 elements
84
+ * depending on the value of the `is2D` parameter.
85
+ *
86
+ * @param m the source matrix to feed values from.
87
+ * @param is2D *Array* representation of the matrix
88
+ * @return an *Array* representation of the matrix
89
+ */
90
+ declare const toArray: (m: CSSMatrix | DOMMatrix | JSONMatrix, is2D?: boolean) => Matrix | Matrix3d;
91
+ /**
92
+ * Creates a new `CSSMatrix` for the translation matrix and returns it.
93
+ * This method is equivalent to the CSS `translate3d()` function.
94
+ *
95
+ * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/translate3d
96
+ *
97
+ * @param x the `x-axis` position.
98
+ * @param y the `y-axis` position.
99
+ * @param z the `z-axis` position.
100
+ * @return the resulted matrix.
101
+ */
102
+ declare const Translate: (x: number, y: number, z: number) => CSSMatrix;
103
+ /**
104
+ * Creates a new `CSSMatrix` for the rotation matrix and returns it.
105
+ *
106
+ * http://en.wikipedia.org/wiki/Rotation_matrix
107
+ *
108
+ * @param rx the `x-axis` rotation.
109
+ * @param ry the `y-axis` rotation.
110
+ * @param rz the `z-axis` rotation.
111
+ * @return the resulted matrix.
112
+ */
113
+ declare const Rotate: (rx: number, ry: number, rz: number) => CSSMatrix;
114
+ /**
115
+ * Creates a new `CSSMatrix` for the rotation matrix and returns it.
116
+ * This method is equivalent to the CSS `rotate3d()` function.
117
+ *
118
+ * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/rotate3d
119
+ *
120
+ * @param x the `x-axis` vector length.
121
+ * @param y the `y-axis` vector length.
122
+ * @param z the `z-axis` vector length.
123
+ * @param alpha the value in degrees of the rotation.
124
+ * @return the resulted matrix.
125
+ */
126
+ declare const RotateAxisAngle: (x?: number, y?: number, z?: number, alpha?: number) => CSSMatrix;
127
+ /**
128
+ * Creates a new `CSSMatrix` for the scale matrix and returns it.
129
+ * This method is equivalent to the CSS `scale3d()` function, except it doesn't
130
+ * accept {x, y, z} transform origin parameters.
131
+ *
132
+ * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/scale3d
133
+ *
134
+ * @param x the `x-axis` scale.
135
+ * @param y the `y-axis` scale.
136
+ * @param z the `z-axis` scale.
137
+ * @return the resulted matrix.
138
+ */
139
+ declare const Scale: (x: number, y: number, z: number) => CSSMatrix;
140
+ /**
141
+ * Creates a new `CSSMatrix` for the shear of both the `x-axis` and`y-axis`
142
+ * matrix and returns it. This method is equivalent to the CSS `skew()` function.
143
+ *
144
+ * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/skew
145
+ *
146
+ * @param angleX the X-angle in degrees.
147
+ * @param angleY the Y-angle in degrees.
148
+ * @return the resulted matrix.
149
+ */
150
+ declare const Skew: (angleX: number, angleY: number) => CSSMatrix;
151
+ /**
152
+ * Creates a new `CSSMatrix` for the shear of the `x-axis` rotation matrix and
153
+ * returns it. This method is equivalent to the CSS `skewX()` function.
154
+ *
155
+ * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/skewX
156
+ *
157
+ * @param angle the angle in degrees.
158
+ * @return the resulted matrix.
159
+ */
160
+ declare const SkewX: (angle: number) => CSSMatrix;
161
+ /**
162
+ * Creates a new `CSSMatrix` for the shear of the `y-axis` rotation matrix and
163
+ * returns it. This method is equivalent to the CSS `skewY()` function.
164
+ *
165
+ * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/skewY
166
+ *
167
+ * @param angle the angle in degrees.
168
+ * @return the resulted matrix.
169
+ */
170
+ declare const SkewY: (angle: number) => CSSMatrix;
171
+ /**
172
+ * Creates a new `CSSMatrix` resulted from the multiplication of two matrixes
173
+ * and returns it. Both matrixes are not changed.
174
+ *
175
+ * @param m1 the first matrix.
176
+ * @param m2 the second matrix.
177
+ * @return the resulted matrix.
178
+ */
179
+ declare const Multiply: (m1: CSSMatrix | DOMMatrix | JSONMatrix, m2: CSSMatrix | DOMMatrix | JSONMatrix) => CSSMatrix;
180
+ /**
181
+ * Creates and returns a new `DOMMatrix` compatible instance
182
+ * with equivalent instance methods.
183
+ *
184
+ * @class CSSMatrix
185
+ *
186
+ * @author thednp <https://github.com/thednp>
187
+ * @link homepage <https://thednp.github.io/dommatrix/>
188
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMMatrix
189
+ */
190
+ declare class CSSMatrix {
191
+ /** The first element of the first row, alias of `a`. */
192
+ m11: number;
193
+ /** The second element of the first row, alias of `b`. */
194
+ m12: number;
195
+ /** The third element of the first row. */
196
+ m13: number;
197
+ /** The fourth element of the first row. */
198
+ m14: number;
199
+ /** The first element of the second row, alias of `c`. */
200
+ m21: number;
201
+ /** The second element of the second row, alias of `d`. */
202
+ m22: number;
203
+ /** The third element of the second row. */
204
+ m23: number;
205
+ /** The fourth element of the second row. */
206
+ m24: number;
207
+ /** The first element of the third row. */
208
+ m31: number;
209
+ /** The second element of the third row. */
210
+ m32: number;
211
+ /** The third element of the third row. */
212
+ m33: number;
213
+ /** The fourth element of the third row. */
214
+ m34: number;
215
+ /** The first element of the fourth row, alias of `e`. */
216
+ m41: number;
217
+ /** The second element of the fourth row, alias of `f`. */
218
+ m42: number;
219
+ /** The third element of the fourth row. */
220
+ m43: number;
221
+ /** The fourth element of the fourth row. */
222
+ m44: number;
223
+ /** The first element of the first row, alias of `m11`. */
224
+ a: number;
225
+ /** The second element of the first row, alias of `m12`. */
226
+ b: number;
227
+ /** The first element of the second row, alias of `m21`. */
228
+ c: number;
229
+ /** The second element of the second row, alias of `m22`. */
230
+ d: number;
231
+ /** The first element of the fourth row, alias of `m41`. */
232
+ e: number;
233
+ /** The second element of the fourth row, alias of `m42`. */
234
+ f: number;
235
+ /** Returns a new translation matrix. See the `Translate` helper. */
236
+ static Translate: typeof Translate;
237
+ /** Returns a new rotation matrix. See the `Rotate` helper. */
238
+ static Rotate: typeof Rotate;
239
+ /** Returns a new rotation matrix about a vector. See the `RotateAxisAngle` helper. */
240
+ static RotateAxisAngle: typeof RotateAxisAngle;
241
+ /** Returns a new scale matrix. See the `Scale` helper. */
242
+ static Scale: typeof Scale;
243
+ /** Returns a new skew-X matrix. See the `SkewX` helper. */
244
+ static SkewX: typeof SkewX;
245
+ /** Returns a new skew-Y matrix. See the `SkewY` helper. */
246
+ static SkewY: typeof SkewY;
247
+ /** Returns a new skew matrix. See the `Skew` helper. */
248
+ static Skew: typeof Skew;
249
+ /** Returns the multiplication of two matrices. See the `Multiply` helper. */
250
+ static Multiply: typeof Multiply;
251
+ /** Creates a new matrix from an array of 6/16 numbers. See the `fromArray` helper. */
252
+ static fromArray: typeof fromArray;
253
+ /** Creates a new matrix from an existing matrix or a JSON object. See the `fromMatrix` helper. */
254
+ static fromMatrix: typeof fromMatrix;
255
+ /** Creates a new matrix from a CSS transform string. See the `fromString` helper. */
256
+ static fromString: typeof fromString;
257
+ /** Returns an *Array* of 6/16 values from a compatible matrix. See the `toArray` helper. */
258
+ static toArray: typeof toArray;
259
+ /** Checks if a value is a compatible 6/16 number array. See the `isCompatibleArray` helper. */
260
+ static isCompatibleArray: typeof isCompatibleArray;
261
+ /** Checks if a value is a `CSSMatrix` / `DOMMatrix` / `JSONMatrix` object. See the `isCompatibleObject` helper. */
262
+ static isCompatibleObject: typeof isCompatibleObject;
263
+ /**
264
+ * @constructor
265
+ * @param init accepts all parameter configurations:
266
+ * * valid CSS transform string,
267
+ * * CSSMatrix/DOMMatrix instance,
268
+ * * a 6/16 elements *Array*.
269
+ */
270
+ constructor(init?: CSSMatrixInput);
271
+ /**
272
+ * A `Boolean` whose value is `true` if the matrix is the identity matrix. The identity
273
+ * matrix is one in which every value is 0 except those on the main diagonal from top-left
274
+ * to bottom-right corner (in other words, where the offsets in each direction are equal).
275
+ *
276
+ * @return the current property value
277
+ */
278
+ get isIdentity(): boolean;
279
+ /**
280
+ * A `Boolean` flag whose value is `true` if the matrix was initialized as a 2D matrix
281
+ * and `false` if the matrix is 3D.
282
+ *
283
+ * @return the current property value
284
+ */
285
+ get is2D(): boolean;
286
+ /**
287
+ * The `setMatrixValue` method replaces the existing matrix with one computed
288
+ * in the browser. EG: `matrix(1,0.25,-0.25,1,0,0)`
289
+ *
290
+ * The method accepts any *Array* values, the result of
291
+ * `DOMMatrix` instance method `toFloat64Array()` / `toFloat32Array()` calls
292
+ * or `CSSMatrix` instance method `toArray()`.
293
+ *
294
+ * This method expects valid *matrix()* / *matrix3d()* string values, as well
295
+ * as other transform functions like *translateX(10px)*.
296
+ *
297
+ * @param source
298
+ * @return the matrix instance
299
+ */
300
+ setMatrixValue(source?: CSSMatrixInput): CSSMatrix;
301
+ /**
302
+ * Returns a *Float32Array* containing elements which comprise the matrix.
303
+ * The method can return either the 16 elements or the 6 elements
304
+ * depending on the value of the `is2D` parameter.
305
+ *
306
+ * @param is2D *Array* representation of the matrix
307
+ * @return an *Array* representation of the matrix
308
+ */
309
+ toFloat32Array(is2D?: boolean): Float32Array;
310
+ /**
311
+ * Returns a *Float64Array* containing elements which comprise the matrix.
312
+ * The method can return either the 16 elements or the 6 elements
313
+ * depending on the value of the `is2D` parameter.
314
+ *
315
+ * @param is2D *Array* representation of the matrix
316
+ * @return an *Array* representation of the matrix
317
+ */
318
+ toFloat64Array(is2D?: boolean): Float64Array;
319
+ /**
320
+ * Creates and returns a string representation of the matrix in `CSS` matrix syntax,
321
+ * using the appropriate `CSS` matrix notation.
322
+ *
323
+ * matrix3d *matrix3d(m11, m12, m13, m14, m21, ...)*
324
+ * matrix *matrix(a, b, c, d, e, f)*
325
+ *
326
+ * @return a string representation of the matrix
327
+ */
328
+ toString(): string;
329
+ /**
330
+ * Returns a JSON representation of the `CSSMatrix` instance, a standard *Object*
331
+ * that includes `{a,b,c,d,e,f}` and `{m11,m12,m13,..m44}` properties as well
332
+ * as the `is2D` & `isIdentity` properties.
333
+ *
334
+ * The result can also be used as a second parameter for the `fromMatrix` static method
335
+ * to load values into another matrix instance.
336
+ *
337
+ * @return an *Object* with all matrix values.
338
+ */
339
+ toJSON(): JSONMatrix;
340
+ /**
341
+ * The Multiply method returns a new CSSMatrix which is the result of this
342
+ * matrix multiplied by the passed matrix, with the passed matrix to the right.
343
+ * This matrix is not modified.
344
+ *
345
+ * @param m2 CSSMatrix
346
+ * @return The resulted matrix.
347
+ */
348
+ multiply(m2: CSSMatrix | DOMMatrix | JSONMatrix): CSSMatrix;
349
+ /**
350
+ * The translate method returns a new matrix which is this matrix post
351
+ * multiplied by a translation matrix containing the passed values. If the z
352
+ * component is undefined, a 0 value is used in its place. This matrix is not
353
+ * modified.
354
+ *
355
+ * @param x X component of the translation value.
356
+ * @param y Y component of the translation value.
357
+ * @param z Z component of the translation value.
358
+ * @return The resulted matrix
359
+ */
360
+ translate(x: number, y?: number, z?: number): CSSMatrix;
361
+ /**
362
+ * The scale method returns a new matrix which is this matrix post multiplied by
363
+ * a scale matrix containing the passed values. If the z component is undefined,
364
+ * a 1 value is used in its place. If the y component is undefined, the x
365
+ * component value is used in its place. This matrix is not modified.
366
+ *
367
+ * @param x The X component of the scale value.
368
+ * @param y The Y component of the scale value.
369
+ * @param z The Z component of the scale value.
370
+ * @return The resulted matrix
371
+ */
372
+ scale(x: number, y?: number, z?: number): CSSMatrix;
373
+ /**
374
+ * The rotate method returns a new matrix which is this matrix post multiplied
375
+ * by each of 3 rotation matrices about the major axes, first X, then Y, then Z.
376
+ * If the y and z components are undefined, the x value is used to rotate the
377
+ * object about the z axis, as though the vector (0,0,x) were passed. All
378
+ * rotation values are in degrees. This matrix is not modified.
379
+ *
380
+ * @param rx The X component of the rotation, or Z if Y and Z are null.
381
+ * @param ry The (optional) Y component of the rotation value.
382
+ * @param rz The (optional) Z component of the rotation value.
383
+ * @return The resulted matrix
384
+ */
385
+ rotate(rx: number, ry?: number, rz?: number): CSSMatrix;
386
+ /**
387
+ * The rotateAxisAngle method returns a new matrix which is this matrix post
388
+ * multiplied by a rotation matrix with the given axis and `angle`. The right-hand
389
+ * rule is used to determine the direction of rotation. All rotation values are
390
+ * in degrees. This matrix is not modified.
391
+ *
392
+ * @param x The X component of the axis vector.
393
+ * @param y The Y component of the axis vector.
394
+ * @param z The Z component of the axis vector.
395
+ * @param angle The angle of rotation about the axis vector, in degrees.
396
+ * @return The resulted matrix
397
+ */
398
+ rotateAxisAngle(x?: number, y?: number, z?: number, angle?: number): CSSMatrix;
399
+ /**
400
+ * Specifies a skew transformation along the `x-axis` by the given angle.
401
+ * This matrix is not modified.
402
+ *
403
+ * @param angle The angle amount in degrees to skew.
404
+ * @return The resulted matrix
405
+ */
406
+ skewX(angle: number): CSSMatrix;
407
+ /**
408
+ * Specifies a skew transformation along the `y-axis` by the given angle.
409
+ * This matrix is not modified.
410
+ *
411
+ * @param angle The angle amount in degrees to skew.
412
+ * @return The resulted matrix
413
+ */
414
+ skewY(angle: number): CSSMatrix;
415
+ /**
416
+ * Specifies a skew transformation along both the `x-axis` and `y-axis`.
417
+ * This matrix is not modified.
418
+ *
419
+ * @param angleX The X-angle amount in degrees to skew.
420
+ * @param angleY The angle amount in degrees to skew.
421
+ * @return The resulted matrix
422
+ */
423
+ skew(angleX: number, angleY: number): CSSMatrix;
424
+ /**
425
+ * Modifies the current matrix by post-multiplying it with another matrix.
426
+ * This is the mutable version of multiply().
427
+ *
428
+ * @param m2 The matrix to multiply with
429
+ * @return this matrix (modified)
430
+ */
431
+ multiplySelf(m2: CSSMatrix | DOMMatrix | JSONMatrix): this;
432
+ /**
433
+ * Modifies the current matrix by post-multiplying it with a translation matrix.
434
+ * This is the mutable version of translate().
435
+ *
436
+ * @param x X component of the translation value.
437
+ * @param y Y component of the translation value.
438
+ * @param z Z component of the translation value.
439
+ * @return this matrix (modified)
440
+ */
441
+ translateSelf(x: number, y?: number, z?: number): this;
442
+ /**
443
+ * Modifies the current matrix by post-multiplying it with a scale matrix.
444
+ * This is the mutable version of scale().
445
+ *
446
+ * @param x The X component of the scale value.
447
+ * @param y The Y component of the scale value.
448
+ * @param z The Z component of the scale value.
449
+ * @return this matrix (modified)
450
+ */
451
+ scaleSelf(x: number, y?: number, z?: number): this;
452
+ /**
453
+ * Modifies the current matrix by post-multiplying it with a rotation matrix.
454
+ * This is the mutable version of rotate().
455
+ *
456
+ * @param rx The X component of the rotation, or Z if Y and Z are null.
457
+ * @param ry The (optional) Y component of the rotation value.
458
+ * @param rz The (optional) Z component of the rotation value.
459
+ * @return this matrix (modified)
460
+ */
461
+ rotateSelf(rx: number, ry?: number, rz?: number): this;
462
+ /**
463
+ * Modifies the current matrix by post-multiplying it with a rotation matrix
464
+ * with the given axis and angle.
465
+ * This is the mutable version of rotateAxisAngle().
466
+ *
467
+ * @param x The X component of the axis vector.
468
+ * @param y The Y component of the axis vector.
469
+ * @param z The Z component of the axis vector.
470
+ * @param angle The angle of rotation about the axis vector, in degrees.
471
+ * @return this matrix (modified)
472
+ */
473
+ rotateAxisAngleSelf(x?: number, y?: number, z?: number, angle?: number): this;
474
+ /**
475
+ * Modifies the current matrix by post-multiplying it with a skewX matrix.
476
+ * This is the mutable version of skewX().
477
+ *
478
+ * @param angle The angle amount in degrees to skew.
479
+ * @return this matrix (modified)
480
+ */
481
+ skewXSelf(angle: number): this;
482
+ /**
483
+ * Modifies the current matrix by post-multiplying it with a skewY matrix.
484
+ * This is the mutable version of skewY().
485
+ *
486
+ * @param angle The angle amount in degrees to skew.
487
+ * @return this matrix (modified)
488
+ */
489
+ skewYSelf(angle: number): this;
490
+ /**
491
+ * Modifies the current matrix by post-multiplying it with a skew matrix.
492
+ * This is the mutable version of skew().
493
+ *
494
+ * @param angleX The X-angle amount in degrees to skew.
495
+ * @param angleY The Y-angle amount in degrees to skew.
496
+ * @return this matrix (modified)
497
+ */
498
+ skewSelf(angleX: number, angleY: number): this;
499
+ /**
500
+ * Transforms a specified vector using the matrix, returning a new
501
+ * {x,y,z,w} Tuple *Object* comprising the transformed vector.
502
+ * Neither the matrix nor the original vector are altered.
503
+ *
504
+ * The method is equivalent with `transformPoint()` method
505
+ * of the `DOMMatrix` constructor.
506
+ *
507
+ * @param t Tuple with `{x,y,z,w}` components
508
+ * @return the resulting Tuple
509
+ */
510
+ transformPoint(t: PointTuple | DOMPoint): PointTuple | DOMPoint;
511
+ }
512
+ //#endregion
513
+ export { type CSSMatrixInput, type JSONMatrix, type Matrix, type Matrix3d, type PointTuple, CSSMatrix as default };
514
+ //# sourceMappingURL=dommatrix.d.ts.map