@thednp/dommatrix 2.0.0-alpha2 → 2.0.0

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/.eslintrc.cjs ADDED
@@ -0,0 +1,224 @@
1
+ module.exports = {
2
+ "env": {
3
+ "browser": true,
4
+ "es6": true
5
+ },
6
+ "extends": [
7
+ "plugin:@typescript-eslint/recommended",
8
+ "plugin:@typescript-eslint/recommended-requiring-type-checking",
9
+ ],
10
+ "parser": "@typescript-eslint/parser",
11
+ "parserOptions": {
12
+ "project": "tsconfig.json",
13
+ "sourceType": "module"
14
+ },
15
+ "plugins": [
16
+ "eslint-plugin-jsdoc",
17
+ "eslint-plugin-prefer-arrow",
18
+ // "eslint-plugin-react",
19
+ "@typescript-eslint",
20
+ "prettier"
21
+ ],
22
+ "root": true,
23
+ "rules": {
24
+ "prettier/prettier": "error",
25
+ "@typescript-eslint/adjacent-overload-signatures": "error",
26
+ "@typescript-eslint/array-type": [
27
+ "error",
28
+ {
29
+ "default": "array"
30
+ }
31
+ ],
32
+ "@typescript-eslint/ban-types": [
33
+ "error",
34
+ {
35
+ "types": {
36
+ "Object": {
37
+ "message": "Avoid using the `Object` type. Did you mean `object`?"
38
+ },
39
+ "Function": {
40
+ "message": "Avoid using the `Function` type. Prefer a specific function type, like `() => void`."
41
+ },
42
+ "Boolean": {
43
+ "message": "Avoid using the `Boolean` type. Did you mean `boolean`?"
44
+ },
45
+ "Number": {
46
+ "message": "Avoid using the `Number` type. Did you mean `number`?"
47
+ },
48
+ "String": {
49
+ "message": "Avoid using the `String` type. Did you mean `string`?"
50
+ },
51
+ "Symbol": {
52
+ "message": "Avoid using the `Symbol` type. Did you mean `symbol`?"
53
+ }
54
+ }
55
+ }
56
+ ],
57
+ "@typescript-eslint/consistent-type-assertions": "error",
58
+ "@typescript-eslint/dot-notation": "error",
59
+ "@typescript-eslint/explicit-function-return-type": "off",
60
+ "@typescript-eslint/explicit-module-boundary-types": "off",
61
+ "@typescript-eslint/indent": "off",
62
+ "@typescript-eslint/member-delimiter-style": [
63
+ "off",
64
+ {
65
+ "multiline": {
66
+ "delimiter": "none",
67
+ "requireLast": true
68
+ },
69
+ "singleline": {
70
+ "delimiter": "semi",
71
+ "requireLast": false
72
+ }
73
+ }
74
+ ],
75
+ // "@typescript-eslint/naming-convention": "error", // keep the original namespace
76
+ "@typescript-eslint/no-empty-function": "error",
77
+ "@typescript-eslint/no-empty-interface": "error",
78
+ "@typescript-eslint/no-explicit-any": "off",
79
+ "@typescript-eslint/no-misused-new": "error",
80
+ "@typescript-eslint/no-namespace": "error",
81
+ "@typescript-eslint/no-parameter-properties": "off",
82
+ "@typescript-eslint/no-shadow": [
83
+ "error",
84
+ {
85
+ "hoist": "all"
86
+ }
87
+ ],
88
+ "@typescript-eslint/no-unused-expressions": "error",
89
+ "@typescript-eslint/no-use-before-define": "off",
90
+ "@typescript-eslint/no-var-requires": "error",
91
+ "@typescript-eslint/prefer-for-of": "error",
92
+ "@typescript-eslint/prefer-function-type": "error",
93
+ "@typescript-eslint/prefer-namespace-keyword": "error",
94
+ "@typescript-eslint/quotes": "off",
95
+ "@typescript-eslint/semi": [
96
+ "off",
97
+ null
98
+ ],
99
+ "@typescript-eslint/triple-slash-reference": [
100
+ "error",
101
+ {
102
+ "path": "always",
103
+ "types": "prefer-import",
104
+ "lib": "always"
105
+ }
106
+ ],
107
+ "@typescript-eslint/type-annotation-spacing": "off",
108
+ "@typescript-eslint/typedef": "off",
109
+ "@typescript-eslint/unified-signatures": "error",
110
+ "arrow-parens": [
111
+ "off",
112
+ "always"
113
+ ],
114
+ "brace-style": [
115
+ "off",
116
+ "off"
117
+ ],
118
+ "comma-dangle": "off",
119
+ "complexity": "off",
120
+ "constructor-super": "error",
121
+ "dot-notation": "off",
122
+ "eol-last": "off",
123
+ "eqeqeq": [
124
+ "error",
125
+ "smart"
126
+ ],
127
+ "guard-for-in": "error",
128
+ "id-denylist": [
129
+ "error",
130
+ "any",
131
+ "Number",
132
+ "number",
133
+ "String",
134
+ "string",
135
+ "Boolean",
136
+ "boolean",
137
+ "Undefined",
138
+ "undefined"
139
+ ],
140
+ "id-match": "error",
141
+ "indent": "off",
142
+ "jsdoc/check-alignment": "error",
143
+ "jsdoc/check-indentation": "error",
144
+ "jsdoc/newline-after-description": "error",
145
+ "linebreak-style": "off",
146
+ "max-classes-per-file": [
147
+ "error",
148
+ 1
149
+ ],
150
+ "max-len": "off",
151
+ "new-parens": "off",
152
+ "newline-per-chained-call": "off",
153
+ "no-bitwise": "error",
154
+ "no-caller": "error",
155
+ "no-cond-assign": "error",
156
+ "no-console": "error",
157
+ "no-debugger": "error",
158
+ "no-empty": "error",
159
+ "no-empty-function": "off",
160
+ "no-eval": "error",
161
+ "no-extra-semi": "off",
162
+ "no-fallthrough": "off",
163
+ "no-invalid-this": "off",
164
+ "no-irregular-whitespace": "off",
165
+ "no-multiple-empty-lines": "off",
166
+ "no-new-wrappers": "error",
167
+ "no-shadow": "off",
168
+ "no-throw-literal": "error",
169
+ "no-trailing-spaces": "off",
170
+ "no-undef-init": "error",
171
+ "no-underscore-dangle": "off",
172
+ "no-unsafe-finally": "error",
173
+ "no-unused-expressions": "off",
174
+ "no-unused-labels": "error",
175
+ "no-use-before-define": "off",
176
+ "no-var": "error",
177
+ "object-shorthand": "error",
178
+ "one-var": [
179
+ "error",
180
+ "never"
181
+ ],
182
+ "padded-blocks": [
183
+ "off",
184
+ {
185
+ "blocks": "never"
186
+ },
187
+ {
188
+ "allowSingleLineBlocks": true
189
+ }
190
+ ],
191
+ "prefer-arrow/prefer-arrow-functions": "error",
192
+ "prefer-const": "error",
193
+ "quote-props": "off",
194
+ "quotes": "off",
195
+ "radix": "error",
196
+ // "react/jsx-curly-spacing": "off",
197
+ // "react/jsx-equals-spacing": "off",
198
+ // "react/jsx-tag-spacing": [
199
+ // "off",
200
+ // {
201
+ // "afterOpening": "allow",
202
+ // "closingSlash": "allow"
203
+ // }
204
+ // ],
205
+ // "react/jsx-wrap-multilines": "off",
206
+ "semi": "off",
207
+ "space-before-function-paren": "off",
208
+ "space-in-parens": [
209
+ "off",
210
+ "never"
211
+ ],
212
+ "spaced-comment": [
213
+ "error",
214
+ "always",
215
+ {
216
+ "markers": [
217
+ "/"
218
+ ]
219
+ }
220
+ ],
221
+ "use-isnan": "error",
222
+ "valid-typeof": "off"
223
+ }
224
+ };
package/.lgtm.yml ADDED
@@ -0,0 +1,9 @@
1
+ extraction:
2
+ javascript:
3
+ index:
4
+ exclude:
5
+ - coverage
6
+ - cypress
7
+ - docs
8
+ - experiments
9
+ - node_modules
@@ -0,0 +1,15 @@
1
+ {
2
+ "arrowParens": "avoid",
3
+ "bracketSpacing": true,
4
+ "endOfLine": "lf",
5
+ "bracketSameLine": false,
6
+ "jsxSingleQuote": false,
7
+ "printWidth": 120,
8
+ "proseWrap": "preserve",
9
+ "quoteProps": "as-needed",
10
+ "semi": true,
11
+ "singleQuote": true,
12
+ "tabWidth": 2,
13
+ "trailingComma": "all",
14
+ "useTabs": false
15
+ }
@@ -0,0 +1,299 @@
1
+ /// <reference types="cypress" />
2
+
3
+ import CSSMatrix from '../../src/index';
4
+ import type { Matrix, Matrix3d } from '../../src/types';
5
+ import testSamples from '../fixtures/testSamples';
6
+
7
+ describe('DOMMatrix Class Test', () => {
8
+
9
+ beforeEach(() => {
10
+ cy.visit('cypress/test.html')
11
+ });
12
+
13
+ it('Test init with no parameter, expect same output as native DOMMatrix', () => {
14
+ const css = new CSSMatrix();
15
+ const css1 = new CSSMatrix().setMatrixValue();
16
+ const dom = new DOMMatrix();
17
+ cy.wrap(css).as('css')
18
+ .get('@css').its('is2D').should('equal', dom.is2D)
19
+ .get('@css').its('isIdentity').should('equal', dom.isIdentity)
20
+ .get('@css').should(($this) => {
21
+ expect(JSON.stringify($this)).to.equal(JSON.stringify(dom));
22
+ expect(JSON.stringify($this)).to.equal(JSON.stringify(css1));
23
+ })
24
+ });
25
+
26
+ it('Test init with invalid array, expect error', () => {
27
+ const test = [0.906308, 0.0839613, -0.414194, 0.00103549, 0, 0.980067, 0.198669, -0.000496673, 0.422618, -0.180056, 0.888242, -0.0022206, 0, 0, 0, 'NaN'];
28
+ try {
29
+ // @ts-ignore
30
+ CSSMatrix.fromArray(test);
31
+ } catch (err) {
32
+ expect(err).to.be.instanceOf(TypeError);
33
+ expect(err).to.have.property('message', `CSSMatrix: "${test}" must be an array with 6/16 numbers.`);
34
+ }
35
+
36
+ const test1 = [0.9659, 0.25879, -0.2588, 0.9659, -1.53961, 'NaN'];
37
+ try {
38
+ // @ts-ignore
39
+ CSSMatrix.fromArray(test1);
40
+ } catch (err) {
41
+ expect(err).to.be.instanceOf(TypeError);
42
+ expect(err).to.have.property('message', `CSSMatrix: "${test1}" must be an array with 6/16 numbers.`);
43
+ }
44
+
45
+ });
46
+
47
+ it('Test init with incomplete array, expect error', () => {
48
+ const test = [0.906308, 0.0839613, -0.414194, 0.00103549, 0, 0.980067, 0.198669, -0.000496673, 0.422618, -0.180056, 0.888242, -0.0022206, 0, 0, 0];
49
+ try {
50
+ CSSMatrix.fromArray(test);
51
+ } catch (err) {
52
+ expect(err).to.be.instanceOf(TypeError);
53
+ expect(err).to.have.property('message', `CSSMatrix: "${test}" must be an array with 6/16 numbers.`);
54
+ }
55
+ });
56
+
57
+ it('Test init with incompatible CSSMatrix, DOMMatrix, JSON object', () => {
58
+ // const css1 = {a: 0.94, b: 0.25, c: -0.25, d: 0.95, e: 0, f: 0, m11: 0.93, m12: 0.25, m13: -0.25, m14: 0, m21: -0.25, m22: 0.95, m23: 0, m24: 0, m31: 0.2, m32: 0.05, m33: 0.95, m34: 0, m41: 0, m42: 0, m43: 0, m44: 1};
59
+ const css1 = {a: 0.94, b: 0.25, c: -0.25, d: 0.95, e: 0, f: 0, m11: 0.93, m12: 0.25, m13: -0.25, m14: 0, m21: -0.25, m22: 0.95, m23: 0, m24: 0, m31: 0.2, m32: 0.05, m33: 0.95, m34: 0, m41: 0, m42: 0, m43: 0, m44: 1};
60
+ const css2 = {m11: 0.93, m12: 0.25, m13: -0.25, m14: 0, m21: -0.25, m22: 0.95, m23: 0, m24: 0, m31: 0.2, m32: 0.05, m33: 0.95, m34: 0, m41: 0, m42: 0, m43: 0, m44: 1};
61
+ const css3 = {a: 0.94, b: 0.25, c: -0.25, d: 0.95, e: 0, f: 0};
62
+
63
+ [css1, css2, css3].forEach((c) => {
64
+ try {
65
+ // @ts-ignore
66
+ new CSSMatrix(c);
67
+ } catch (err) {
68
+ expect(err).to.be.instanceOf(TypeError);
69
+ expect(err).to.have.property('message', `CSSMatrix: "${JSON.stringify(c)}" is not a DOMMatrix / CSSMatrix / JSON compatible object.`);
70
+ }
71
+ })
72
+ });
73
+
74
+ it('Test init compatible CSSMatrix, DOMMatrix, JSON object', () => {
75
+ const css = new CSSMatrix().rotate(15, 15);
76
+ const dom = new DOMMatrix().rotate(15, 15);
77
+
78
+ cy.wrap(new CSSMatrix(css)).as('cc')
79
+ .get('@cc').its('is2D').should('equal', css.is2D)
80
+ .get('@cc').its('is2D').should('equal', new CSSMatrix(dom).is2D)
81
+ .get('@cc').its('isIdentity').should('equal', css.isIdentity)
82
+ .get('@cc').its('isIdentity').should('equal', new CSSMatrix(dom).isIdentity);
83
+
84
+ cy.wrap(css.toJSON()).as('js')
85
+ .get('@js').its('is2D').should('equal', css.is2D)
86
+ .get('@js').its('is2D').should('equal', new CSSMatrix(dom).is2D)
87
+ .get('@js').its('isIdentity').should('equal', css.isIdentity)
88
+ .get('@js').its('isIdentity').should('equal', new CSSMatrix(dom).isIdentity)
89
+ });
90
+
91
+ it('Test specific private methods', () => {
92
+ cy.log('CSSMatrix.rotateAxisAngle specific error').then(() => {
93
+ try {
94
+ // @ts-ignore
95
+ new CSSMatrix().rotateAxisAngle('a','true','wombat','05');
96
+ } catch (err) {
97
+ expect(err).to.be.instanceOf(TypeError);
98
+ expect(err).to.have.property('message', 'CSSMatrix: expecting 4 values');
99
+ }
100
+ });
101
+
102
+ cy.log('CSSMatrix.rotate').then(() => {
103
+ const d1 = new DOMMatrix().rotate(15);
104
+ const m1 = new CSSMatrix().rotate(15);
105
+
106
+ cy.get('.bg-primary').then(($el) => {
107
+ $el[0].style.transform = m1.toString();
108
+ })
109
+ .get('.bg-secondary').then(($el) => {
110
+ $el[0].style.transform = d1.toString();
111
+ })
112
+ expect(m1.isIdentity).to.equal(d1.isIdentity);
113
+ expect(m1.is2D).to.equal(d1.is2D);
114
+ expect(m1.toFloat32Array()).to.deep.equal(d1.toFloat32Array());
115
+ expect(m1.toFloat64Array()).to.deep.equal(d1.toFloat64Array());
116
+ });
117
+
118
+ cy.log('CSSMatrix.rotate(x:25, y:15)').then(() => {
119
+ const d2 = new DOMMatrix().rotate(25,15);
120
+ const m2 = new CSSMatrix().rotate(25,15);
121
+ cy.get('.bg-primary').then(($el) => {
122
+ $el[0].style.transform = m2.toString();
123
+ })
124
+ .get('.bg-secondary').then(($el) => {
125
+ $el[0].style.transform = d2.toString();
126
+ })
127
+
128
+ expect(m2.isIdentity).to.equal(d2.isIdentity);
129
+ expect(m2.is2D).to.equal(d2.is2D);
130
+ expect(m2.toFloat32Array()).to.deep.equal(d2.toFloat32Array());
131
+ expect(m2.toFloat64Array()).to.deep.equal(d2.toFloat64Array());
132
+ });
133
+
134
+ cy.log('CSSMatrix.translate(x:150)').then(() => {
135
+ const d3 = new DOMMatrix().translate(150);
136
+ const m3 = new CSSMatrix().translate(150);
137
+
138
+ cy.get('.bg-primary').then(($el) => {
139
+ $el[0].style.transform = m3.toString();
140
+ })
141
+ .get('.bg-secondary').then(($el) => {
142
+ $el[0].style.transform = d3.toString();
143
+ })
144
+ expect(m3.isIdentity).to.equal(d3.isIdentity);
145
+ expect(m3.is2D).to.equal(d3.is2D);
146
+ expect(m3.toFloat32Array()).to.deep.equal(d3.toFloat32Array());
147
+ expect(m3.toFloat64Array()).to.deep.equal(d3.toFloat64Array());
148
+ });
149
+
150
+ cy.log('CSSMatrix.skew(x:15, y:-20)').then(() => {
151
+ const d4 = new DOMMatrix('skew(15deg, -20deg)');
152
+ const m4 = new CSSMatrix().skew(15, -20);
153
+ cy.log('In this test we\'re addapting to the output of the native DOMMatrix method since it doesn\'t support the skew() method itself.')
154
+ .get('.bg-primary').then(($el) => {
155
+ $el[0].style.transform = m4.toString();
156
+ })
157
+ .get('.bg-secondary').then(($el) => {
158
+ $el[0].style.transform = d4.toString();
159
+ })
160
+ expect(m4.isIdentity).to.equal(d4.isIdentity);
161
+ expect(m4.is2D).to.equal(d4.is2D);
162
+ expect(m4.toFloat32Array()).to.deep.equal(d4.toFloat32Array());
163
+ expect(m4.toFloat64Array()).to.deep.equal(d4.toFloat64Array());
164
+ });
165
+
166
+ cy.log('CSSMatrix.scale(x:1.3)').then(() => {
167
+ const d5 = new DOMMatrix().scale(1.3);
168
+ const m5 = new CSSMatrix().scale(1.3);
169
+ cy.get('.bg-primary').then(($el) => {
170
+ $el[0].style.transform = m5.toString();
171
+ })
172
+ .get('.bg-secondary').then(($el) => {
173
+ $el[0].style.transform = d5.toString();
174
+ })
175
+ expect(m5.isIdentity).to.equal(d5.isIdentity);
176
+ expect(m5.is2D).to.equal(d5.is2D);
177
+ expect(m5.toFloat32Array()).to.deep.equal(d5.toFloat32Array());
178
+ expect(m5.toFloat64Array()).to.deep.equal(d5.toFloat64Array());
179
+ });
180
+
181
+ cy.log('CSSMatrix.scale(x:1.3,y:1.8)').then(() => {
182
+ const d6 = new DOMMatrix().scale(1.3,1.8);
183
+ const m6 = new CSSMatrix().scale(1.3,1.8);
184
+ cy.get('.bg-primary').then(($el) => {
185
+ $el[0].style.transform = m6.toString();
186
+ })
187
+ .get('.bg-secondary').then(($el) => {
188
+ $el[0].style.transform = d6.toString();
189
+ })
190
+ expect(m6.isIdentity).to.equal(d6.isIdentity);
191
+ expect(m6.is2D).to.equal(d6.is2D);
192
+ expect(m6.toFloat32Array()).to.deep.equal(d6.toFloat32Array());
193
+ expect(m6.toFloat64Array()).to.deep.equal(d6.toFloat64Array());
194
+ });
195
+
196
+ cy.log('CSSMatrix.transformPoint').then(() => {
197
+ const p1 = new DOMPoint(15, 20, 35, 1);
198
+ const p2 = { x: 15, y: 20, z: 35, w: 1};
199
+ const dp = new DOMMatrix().rotate(15).translate(15, 15);
200
+ const mp = new CSSMatrix().rotate(15).translate(15, 15);
201
+
202
+ cy.log('For some reason the native DOMMatrix again falsely claims **is2D** to be true');
203
+ expect(mp.isIdentity).to.equal(dp.isIdentity);
204
+ expect(mp.is2D).to.equal(dp.is2D);
205
+ expect(mp.toFloat32Array()).to.deep.equal(dp.toFloat32Array());
206
+ expect(mp.toFloat64Array()).to.deep.equal(dp.toFloat64Array());
207
+ expect(mp.transformPoint(p1)).to.deep.equal(dp.transformPoint(p1));
208
+ expect(mp.transformPoint(p2)).to.deep.equal(dp.transformPoint(p2).toJSON());
209
+ });
210
+ });
211
+
212
+ it('Test init a 6 values array', () => {
213
+ const test = [0.9659, 0.25879, -0.2588, 0.9659, -1.53961, -1.53961] as Matrix;
214
+ const m1 = new CSSMatrix(test);
215
+ // const m2 = new CSSMatrix(...test);
216
+ const m3 = new CSSMatrix([...test]);
217
+ const m4 = new DOMMatrix(test);
218
+
219
+ expect(m1.toFloat64Array()).to.deep.equal(m3.toFloat64Array())
220
+ expect(m1.toFloat64Array()).to.deep.equal(m4.toFloat64Array())
221
+ });
222
+
223
+ it('Test init a 16 values array', () => {
224
+ const test = [0.852, 0.153, 0.186, -0.0004, -0.092, 0.869, -0.266, 0.0006, -0.25, 0.258, 0.933, -0.002, 0, 0, 0, 1] as Matrix3d;
225
+ const m1 = new CSSMatrix(test);
226
+ // const m2 = new CSSMatrix(...test);
227
+ const m3 = new CSSMatrix([...test]);
228
+ const m4 = new DOMMatrix(test);
229
+
230
+ expect(m1.toFloat32Array()).to.deep.equal(m3.toFloat32Array())
231
+ expect(m1.toFloat32Array()).to.deep.equal(m4.toFloat32Array())
232
+ });
233
+
234
+ it('Test static methods', () => {
235
+ const m = new CSSMatrix();
236
+ const source = {a: 1};
237
+ const source1 = 'wombat(1)';
238
+ const source2 = 'skew()';
239
+ const source3 = 'translate(wombat)';
240
+
241
+ expect(CSSMatrix.fromMatrix(m)).to.deep.equal(m);
242
+ expect(CSSMatrix.fromMatrix(m.toJSON())).to.deep.equal(m);
243
+
244
+ try {
245
+ // @ts-ignore
246
+ CSSMatrix.fromString(source);
247
+ } catch (err) {
248
+ expect(err).to.be.instanceOf(TypeError);
249
+ expect(err).to.have.property('message', `CSSMatrix: "${JSON.stringify(source)}" is not a string.`);
250
+ }
251
+
252
+ try {
253
+ CSSMatrix.fromString(source1);
254
+ } catch (err) {
255
+ expect(err).to.be.instanceOf(TypeError);
256
+ expect(err).to.have.property('message', `CSSMatrix: invalid transform string "${source1}"`);
257
+ }
258
+
259
+ try {
260
+ CSSMatrix.fromString(source2);
261
+ } catch (err) {
262
+ expect(err).to.be.instanceOf(TypeError);
263
+ expect(err).to.have.property('message', `CSSMatrix: invalid transform string "${source2}"`);
264
+ }
265
+
266
+ try {
267
+ CSSMatrix.fromString(source3);
268
+ } catch (err) {
269
+ expect(err).to.be.instanceOf(TypeError);
270
+ expect(err).to.have.property('message', `CSSMatrix: invalid transform string "${source3}"`);
271
+ }
272
+ });
273
+
274
+ Object.keys(testSamples).forEach((test) => {
275
+ it(`Test string input ${test}, expect same output as native DOMMatrix`, () => {
276
+ const str = testSamples[test];
277
+ const css = new CSSMatrix(str);
278
+ const dom = new DOMMatrix(str);
279
+
280
+ cy.get('.bg-primary').then(($el) => {
281
+ $el[0].style.transform = css.toString();
282
+ });
283
+ cy.get('.bg-secondary').then(($el) => {
284
+ $el[0].style.transform = dom.toString();
285
+ });
286
+ cy.log('Due to the nature of the native DOMMatrix RegExp, for consistency reasons we\'re rounding numbers to 6 decimals in this test.')
287
+
288
+ expect(Array.from(css.toFloat32Array()).map(x=> Math.floor(x * 10**6) / 10**6))
289
+ .to.deep.equal(Array.from(dom.toFloat32Array()).map(x=> Math.floor(x * 10**6) / 10**6));
290
+
291
+ cy.wrap(css).as('css')
292
+ .log('The native `DOMMatrix` is a little weird when it comes to rotateAxisAngle, it falsely claims the identity matrix is NOT `is2D`')
293
+ .get('@css').its('isIdentity').should((isIdentity) => expect(isIdentity).to.equal(dom.isIdentity))
294
+ .get('@css').its('is2D').should((test === 'rotate3d1' ? 'not.equal' : 'equal'), dom.is2D);
295
+ });
296
+ })
297
+
298
+
299
+ });
@@ -0,0 +1,32 @@
1
+ export default {
2
+ skew: 'skew(25deg)',
3
+ skewX: 'skewX(25deg)',
4
+ skewY: 'skewY(-25deg)',
5
+ skew2d: 'skew(15deg, 25deg)',
6
+ skewsX0: 'skew(15deg, 0)',
7
+ skews0Y: 'skew(0, 25deg)',
8
+ skews3: 'skew(35deg, -45deg)',
9
+ rotate: 'rotate(25deg)',
10
+ rotateX: 'rotateX(-25deg)',
11
+ rotateY: 'rotateY(25deg)',
12
+ rotate3d: 'rotate3d(0.1,1.5,0.7,25deg)',
13
+ rotate3d1: 'rotate3d(0,0,0,20deg)',
14
+ translate: 'translate(25px)',
15
+ translateX: 'translateX(25px)',
16
+ translateY: 'translateY(25px)',
17
+ translateZ: 'translateZ(25px)',
18
+ translate2d: 'translate(25px, 15px)',
19
+ translate3D: 'translate3d(25px, 15px, 5px)',
20
+ scale: 'scale(1.25)',
21
+ scaleX: 'scaleX(1.515)',
22
+ scaleY: 'scaleY(1.155)',
23
+ scaleZ: 'scaleZ(1.153)',
24
+ scale3D: 'scale3d(1.15, 1.51, 2)',
25
+ regular: 'perspective(400px) translate(150px, 200px) rotateX(0.2rad) rotateY(25deg)',
26
+ matrix: 'matrix(0.9659, 0.2588, -0.2588, 0.9659, -1.5396, -1.5396) translate(15px)',
27
+ matrix3d: 'matrix3d(0.852, 0.153, 0.186, -0.0004, -0.092, 0.869, -0.266, 0.0006, -0.25, 0.258, 0.933, -0.002, 0, 0, 0, 1)',
28
+ combo: 'translate(25px, 15px) matrix(0.984807, -0.173648, 0.173648, 0.984807, 0, 0)',
29
+ combo1: 'skewX(0.3rad) skewY(10deg) translate3d(15px,15px, -15px) matrix(0.984807, -0.173648, 0.173648, 0.984807, 0, 0)',
30
+ combo2: 'perspective(800px) scale(0.9,1.1) rotateX(15deg) rotate(-0.125rad) skewX(-5deg) rotate3d(0.1,1.5,0.7,25deg) skewY(-0.2rad)',
31
+ combo3: 'perspective(1200px) rotateY(-175deg) rotate(-0.125rad) scale3d(0.9,1.1,0.75) skewX(-0.2rad) rotate3d(0.1,1.5,0.7,25deg) skewY(-5deg) matrix(0.9659, 0.2588, -0.2588, 0.9659, -1.5396, -1.5396)'
32
+ }
@@ -0,0 +1,50 @@
1
+ // sources
2
+ // * https://github.com/enketo/enketo-express/blob/master/tools/esbuild-plugin-istanbul.js
3
+ 'use strict';
4
+ import esbuild from 'esbuild';
5
+ import { promises } from 'fs';
6
+ import { createInstrumenter } from 'istanbul-lib-instrument';
7
+ import { extname, sep } from 'path';
8
+ import tsCompile from './tsCompile';
9
+
10
+ // import Cypress settings
11
+ const sourceFolder = 'src';
12
+ const [name] = process.cwd().split(sep).slice(-1);
13
+
14
+ const sourceFilter = `${name}${sep}${sourceFolder}`;
15
+ const instrumenter = createInstrumenter({
16
+ compact: false,
17
+ esModules: true,
18
+ preserveComments: true,
19
+ autoWrap: true,
20
+ });
21
+
22
+ const createEsbuildIstanbulPlugin = (): esbuild.Plugin => {
23
+ return {
24
+ name: 'istanbul',
25
+ setup(build: esbuild.PluginBuild) {
26
+ build.onLoad(
27
+ { filter: /\.(ts|tsx)$/ },
28
+ async ({ path }: esbuild.OnLoadArgs): Promise<{ contents: string } & Record<string, any>> => {
29
+
30
+ if (!path.includes(sourceFilter)) {
31
+ // console.log("> compiling typescript %s for output build", path);
32
+ const contents = await promises.readFile(path, 'utf8');
33
+ return {
34
+ contents: ['.ts', '.tsx'].includes(extname(path)) ? tsCompile(path).outputText : contents,
35
+ };
36
+ }
37
+
38
+ // console.log("🧡 instrumenting %s for output coverage", path);
39
+ const { outputText, sourceMap } = tsCompile(path);
40
+
41
+ return {
42
+ contents: instrumenter.instrumentSync(outputText, path, sourceMap),
43
+ };
44
+ },
45
+ );
46
+ },
47
+ };
48
+ };
49
+
50
+ export default createEsbuildIstanbulPlugin;
@@ -0,0 +1,34 @@
1
+ // compile.ts
2
+ import TypeScript from 'typescript';
3
+ import { basename } from 'path';
4
+ import { RawSourceMap } from 'source-map';
5
+ import { readFileSync } from 'fs';
6
+
7
+ export default function tsCompile(
8
+ path: string,
9
+ ops?: Partial<TypeScript.TranspileOptions>,
10
+ ): TypeScript.TranspileOutput & { sourceMap: RawSourceMap } {
11
+ // Default options -- you could also perform a merge, or use the project tsconfig.json
12
+ const options: TypeScript.TranspileOptions = Object.assign(
13
+ {
14
+ compilerOptions: {
15
+ allowJs: true,
16
+ esModuleInterop: true,
17
+ removeComments: false,
18
+ target: 99, // ESNext
19
+ allowSyntheticDefaultImports: true,
20
+ isolatedModules: true,
21
+ noEmitHelpers: true,
22
+ sourceMap: true,
23
+ } as Partial<TypeScript.CompilerOptions>,
24
+ },
25
+ ops,
26
+ );
27
+ const contents = readFileSync(path, { encoding: 'utf8' });
28
+ const { outputText, sourceMapText } = TypeScript.transpileModule(contents, options);
29
+ const sourceMap: RawSourceMap = JSON.parse(sourceMapText || '');
30
+ sourceMap.file = basename(path);
31
+ sourceMap.sources = [basename(path)];
32
+
33
+ return { outputText, sourceMap, sourceMapText };
34
+ }