@es-joy/jsoe 0.10.0 → 0.11.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/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGES TO `@es-joy/jsoe`
2
2
 
3
+ ## 0.11.0
4
+
5
+ - feat: support `DOMException`, `DOMPoint`, `DOMMatrix`, `DOMRect` types
6
+
3
7
  ## 0.10.0
4
8
 
5
9
  - feat: add `filelist` type
package/README.md CHANGED
@@ -30,6 +30,10 @@ Supported types include:
30
30
  - `Blob`
31
31
  - `Boolean` object
32
32
  - `Date`
33
+ - `DOMException`,
34
+ - `DOMMatrix`
35
+ - `DOMPoint`
36
+ - `DOMRect`
33
37
  - `Error`
34
38
  - `TypeError`, `RangeError`, `SyntaxError`, `ReferenceError`, `EvalError`,
35
39
  `URIError`, `AggregateError`, `InternalError`
@@ -107,10 +111,6 @@ Supported supertypes include:
107
111
  1. Web/API types
108
112
  1. imagedata, imagebitmap
109
113
  1. cryptokey
110
- 1. domexception
111
- 1. domrect
112
- 1. dompoint
113
- 1. dommatrix
114
114
  1. Our own custom derivative types? (e.g., MIDI using TypedArray)
115
115
  1. Expand subtypes
116
116
  1. String
package/demo/index.js CHANGED
@@ -341,7 +341,17 @@ setTimeout(async function () {
341
341
  }),
342
342
  new Blob(['abc'], {
343
343
  type: 'text/plain'
344
- })
344
+ }),
345
+ new DOMException('some message', 'someName'),
346
+ new DOMRect(1, 2, 3, 4),
347
+ new DOMPoint(1, 2, 3, 4),
348
+ new DOMMatrix([1, 2, 3, 4, 5, 6]),
349
+ new DOMMatrix([
350
+ 1, 2, 3, 4,
351
+ 5, 6, 7, 8,
352
+ 9, 10, 11, 12,
353
+ 13, 14, 15, 16
354
+ ])
345
355
  ],
346
356
  typeNamespace: 'demo-type-choices-only-initial-value'
347
357
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@es-joy/jsoe",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./src/index.js",
@@ -462,12 +462,11 @@ const structuredCloning = {
462
462
  'file',
463
463
  'set',
464
464
  'map',
465
- 'filelist'
466
- // Ok:
467
- // 'domexception',
468
- // 'domrect',
469
- // 'dompoint',
470
- // 'dommatrix',
465
+ 'filelist',
466
+ 'domexception',
467
+ 'domrect',
468
+ 'dompoint',
469
+ 'dommatrix'
471
470
 
472
471
  // Ok, but will need some work and/or decisions on how to present:
473
472
  // 'cryptokey',
@@ -0,0 +1,124 @@
1
+ import {$e} from '../utils/templateUtils.js';
2
+
3
+ /**
4
+ * @type {import('../types.js').TypeObject}
5
+ */
6
+ const domexceptionType = {
7
+ option: ['DOMException'],
8
+ stringRegex: /^DOMException\((.*)\)$/u,
9
+ toValue (s) {
10
+ const {message, name} = JSON.parse(s);
11
+ return {value: new DOMException(message, name)};
12
+ },
13
+ getInput ({root}) {
14
+ return /** @type {HTMLInputElement} */ ($e(root, 'input'));
15
+ },
16
+ setValue ({root, value}) {
17
+ /** @type {HTMLInputElement} */ (
18
+ $e(root, '.message')
19
+ ).value = value.message;
20
+ /** @type {HTMLInputElement} */ (
21
+ $e(root, '.name')
22
+ ).value = value.name;
23
+ },
24
+ getValue ({root}) {
25
+ const message = /** @type {HTMLInputElement} */ (
26
+ $e(root, '.message')
27
+ ).value;
28
+ const name = /** @type {HTMLInputElement} */ (
29
+ $e(root, '.name')
30
+ ).value;
31
+ return new DOMException(message, name);
32
+ },
33
+ viewUI ({value}) {
34
+ return ['div', {dataset: {type: 'domexception'}}, [
35
+ ['b', ['Message ']],
36
+ value.message,
37
+ ['br'],
38
+ ['b', ['Name ']],
39
+ value.name,
40
+ ['br'],
41
+ ['b', ['Code ']],
42
+ value.code
43
+ ]];
44
+ },
45
+ editUI ({typeNamespace, value = ''}) {
46
+ // eslint-disable-next-line @stylistic/max-len -- Long
47
+ return ['div', {dataset: {type: 'domexception'}}, /** @type {import('jamilih').JamilihChildren} */ ([
48
+ ['label', [
49
+ 'Name: ',
50
+ ['input', {
51
+ class: 'name',
52
+ name: `${typeNamespace}-domexception-name`, value
53
+ }]
54
+ ]],
55
+ ' ',
56
+ ['select', {
57
+ class: 'predefinedNames',
58
+ $on: {
59
+ /**
60
+ * @this {HTMLSelectElement}
61
+ */
62
+ change () {
63
+ /** @type {HTMLInputElement} */
64
+ ($e(
65
+ /** @type {HTMLLabelElement} */ (
66
+ this.previousElementSibling
67
+ ),
68
+ '.name'
69
+ )).value = this.value;
70
+ }
71
+ }
72
+ }, [
73
+ ['option', {value: ''}, [
74
+ '(Choose an optional predefined name)'
75
+ ]],
76
+ ...[
77
+ 'IndexSizeError',
78
+ 'HierarchyRequestError',
79
+ 'WrongDocumentError',
80
+ 'InvalidCharacterError',
81
+ 'NoModificationAllowedError',
82
+ 'NotFoundError',
83
+ 'NotSupportedError',
84
+ 'InvalidStateError',
85
+ 'InUseAttributeError',
86
+ 'SyntaxError',
87
+ 'InvalidModificationError',
88
+ 'NamespaceError',
89
+ 'InvalidAccessError',
90
+ 'TypeMismatchError',
91
+ 'SecurityError',
92
+ 'NetworkError',
93
+ 'AbortError',
94
+ 'URLMismatchError',
95
+ 'QuotaExceededError',
96
+ 'TimeoutError',
97
+ 'InvalidNodeTypeError',
98
+ 'DataCloneError',
99
+ 'EncodingError',
100
+ 'NotReadableError',
101
+ 'UnknownError',
102
+ 'ConstraintError',
103
+ 'DataError',
104
+ 'TransactionInactiveError',
105
+ 'ReadOnlyErrorVersionError',
106
+ 'OperationError',
107
+ 'NotAllowedError'
108
+ ].map((name) => {
109
+ return ['option', [name]];
110
+ })
111
+ ]],
112
+ ['br'],
113
+ ['label', [
114
+ 'Message: ',
115
+ ['input', {
116
+ class: 'message',
117
+ name: `${typeNamespace}-domexception-message`, value
118
+ }]
119
+ ]]
120
+ ])];
121
+ }
122
+ };
123
+
124
+ export default domexceptionType;
@@ -0,0 +1,357 @@
1
+ import {$e} from '../utils/templateUtils.js';
2
+
3
+ let idx = 0;
4
+
5
+ /**
6
+ * @type {import('../types.js').TypeObject}
7
+ */
8
+ const dommatrixType = {
9
+ option: ['DOMMatrix'],
10
+ stringRegex: /^DOMMatrix\((.*)\)$/u,
11
+ toValue (s) {
12
+ const o = JSON.parse(s);
13
+
14
+ const dommatrix = Object.hasOwn(o, 'a')
15
+ ? new DOMMatrix([o.a, o.b, o.c, o.d, o.e, o.f])
16
+ : new DOMMatrix([
17
+ o.m11, o.m12, o.m13, o.m14,
18
+ o.m21, o.m22, o.m23, o.m24,
19
+ o.m31, o.m32, o.m33, o.m34,
20
+ o.m41, o.m42, o.m43, o.m44
21
+ ]);
22
+
23
+ return {value: dommatrix};
24
+ },
25
+ getInput ({root}) {
26
+ return /** @type {HTMLInputElement} */ ($e(root, 'input'));
27
+ },
28
+ setValue ({root, value: o}) {
29
+ const {is2D} = o;
30
+ /** @type {HTMLInputElement} */ ($e(root, '.d2')).checked = is2D;
31
+ /** @type {HTMLInputElement} */ ($e(root, '.d3')).checked = !is2D;
32
+
33
+ /** @type {HTMLDivElement} */ (
34
+ $e(root, '.holder2d')
35
+ ).hidden = /** @type {HTMLInputElement} */ !is2D;
36
+ /** @type {HTMLDivElement} */ (
37
+ $e(root, '.holder3d')
38
+ ).hidden = /** @type {HTMLInputElement} */ is2D;
39
+
40
+ if (is2D) {
41
+ /** @type {HTMLInputElement} */ (
42
+ $e(root, '.a')
43
+ ).value = o.a;
44
+ /** @type {HTMLInputElement} */ (
45
+ $e(root, '.b')
46
+ ).value = o.b;
47
+ /** @type {HTMLInputElement} */ (
48
+ $e(root, '.c')
49
+ ).value = o.c;
50
+ /** @type {HTMLInputElement} */ (
51
+ $e(root, '.d')
52
+ ).value = o.d;
53
+ /** @type {HTMLInputElement} */ (
54
+ $e(root, '.e')
55
+ ).value = o.e;
56
+ /** @type {HTMLInputElement} */ (
57
+ $e(root, '.f')
58
+ ).value = o.f;
59
+ } else {
60
+ /** @type {HTMLInputElement} */ (
61
+ $e(root, '.m11')
62
+ ).value = o.m11;
63
+ /** @type {HTMLInputElement} */ (
64
+ $e(root, '.m12')
65
+ ).value = o.m12;
66
+ /** @type {HTMLInputElement} */ (
67
+ $e(root, '.m13')
68
+ ).value = o.m13;
69
+ /** @type {HTMLInputElement} */ (
70
+ $e(root, '.m14')
71
+ ).value = o.m14;
72
+
73
+ /** @type {HTMLInputElement} */ (
74
+ $e(root, '.m21')
75
+ ).value = o.m21;
76
+ /** @type {HTMLInputElement} */ (
77
+ $e(root, '.m22')
78
+ ).value = o.m22;
79
+ /** @type {HTMLInputElement} */ (
80
+ $e(root, '.m23')
81
+ ).value = o.m23;
82
+ /** @type {HTMLInputElement} */ (
83
+ $e(root, '.m24')
84
+ ).value = o.m24;
85
+
86
+ /** @type {HTMLInputElement} */ (
87
+ $e(root, '.m31')
88
+ ).value = o.m31;
89
+ /** @type {HTMLInputElement} */ (
90
+ $e(root, '.m32')
91
+ ).value = o.m32;
92
+ /** @type {HTMLInputElement} */ (
93
+ $e(root, '.m33')
94
+ ).value = o.m33;
95
+ /** @type {HTMLInputElement} */ (
96
+ $e(root, '.m34')
97
+ ).value = o.m34;
98
+
99
+ /** @type {HTMLInputElement} */ (
100
+ $e(root, '.m41')
101
+ ).value = o.m41;
102
+ /** @type {HTMLInputElement} */ (
103
+ $e(root, '.m42')
104
+ ).value = o.m42;
105
+ /** @type {HTMLInputElement} */ (
106
+ $e(root, '.m43')
107
+ ).value = o.m43;
108
+ /** @type {HTMLInputElement} */ (
109
+ $e(root, '.m44')
110
+ ).value = o.m44;
111
+ }
112
+ },
113
+ getValue ({root}) {
114
+ const aType = /** @type {HTMLInputElement} */ (
115
+ $e(root, '.a')
116
+ ).value;
117
+
118
+ if (aType) {
119
+ const a = Number(aType);
120
+ const b = Number(/** @type {HTMLInputElement} */ (
121
+ $e(root, '.b')
122
+ ).value);
123
+ const c = Number(/** @type {HTMLInputElement} */ (
124
+ $e(root, '.c')
125
+ ).value);
126
+ const d = Number(/** @type {HTMLInputElement} */ (
127
+ $e(root, '.d')
128
+ ).value);
129
+ const e = Number(/** @type {HTMLInputElement} */ (
130
+ $e(root, '.e')
131
+ ).value);
132
+ const f = Number(/** @type {HTMLInputElement} */ (
133
+ $e(root, '.f')
134
+ ).value);
135
+ return new DOMMatrix([a, b, c, d, e, f]);
136
+ }
137
+
138
+ const m11 = Number(/** @type {HTMLInputElement} */ (
139
+ $e(root, '.m11')
140
+ ).value);
141
+ const m12 = Number(/** @type {HTMLInputElement} */ (
142
+ $e(root, '.m12')
143
+ ).value);
144
+ const m13 = Number(/** @type {HTMLInputElement} */ (
145
+ $e(root, '.m13')
146
+ ).value);
147
+ const m14 = Number(/** @type {HTMLInputElement} */ (
148
+ $e(root, '.m14')
149
+ ).value);
150
+
151
+ const m21 = Number(/** @type {HTMLInputElement} */ (
152
+ $e(root, '.m21')
153
+ ).value);
154
+ const m22 = Number(/** @type {HTMLInputElement} */ (
155
+ $e(root, '.m22')
156
+ ).value);
157
+ const m23 = Number(/** @type {HTMLInputElement} */ (
158
+ $e(root, '.m23')
159
+ ).value);
160
+ const m24 = Number(/** @type {HTMLInputElement} */ (
161
+ $e(root, '.m24')
162
+ ).value);
163
+
164
+ const m31 = Number(/** @type {HTMLInputElement} */ (
165
+ $e(root, '.m31')
166
+ ).value);
167
+ const m32 = Number(/** @type {HTMLInputElement} */ (
168
+ $e(root, '.m32')
169
+ ).value);
170
+ const m33 = Number(/** @type {HTMLInputElement} */ (
171
+ $e(root, '.m33')
172
+ ).value);
173
+ const m34 = Number(/** @type {HTMLInputElement} */ (
174
+ $e(root, '.m34')
175
+ ).value);
176
+
177
+ const m41 = Number(/** @type {HTMLInputElement} */ (
178
+ $e(root, '.m41')
179
+ ).value);
180
+ const m42 = Number(/** @type {HTMLInputElement} */ (
181
+ $e(root, '.m42')
182
+ ).value);
183
+ const m43 = Number(/** @type {HTMLInputElement} */ (
184
+ $e(root, '.m43')
185
+ ).value);
186
+ const m44 = Number(/** @type {HTMLInputElement} */ (
187
+ $e(root, '.m44')
188
+ ).value);
189
+
190
+ return new DOMMatrix([
191
+ m11, m12, m13, m14,
192
+ m21, m22, m23, m24,
193
+ m31, m32, m33, m34,
194
+ m41, m42, m43, m44
195
+ ]);
196
+ },
197
+ viewUI ({value}) {
198
+ return ['div', {dataset: {type: 'dommatrix'}}, [
199
+ value.is2D
200
+ ? ['div', [
201
+ ['b', ['a ']],
202
+ value.a,
203
+ ['br'],
204
+ ['b', ['b ']],
205
+ value.b,
206
+ ['br'],
207
+ ['b', ['c ']],
208
+ value.c,
209
+ ['br'],
210
+ ['b', ['d ']],
211
+ value.d,
212
+ ['br'],
213
+ ['b', ['e ']],
214
+ value.e,
215
+ ['br'],
216
+ ['b', ['f ']],
217
+ value.f
218
+ ]]
219
+ : ['div', [
220
+ ['b', ['m11 ']],
221
+ value.m11,
222
+ ['br'],
223
+ ['b', ['m12 ']],
224
+ value.m12,
225
+ ['br'],
226
+ ['b', ['m13 ']],
227
+ value.m13,
228
+ ['br'],
229
+ ['b', ['m14 ']],
230
+ value.m14,
231
+ ['br'],
232
+
233
+ ['b', ['m21 ']],
234
+ value.m21,
235
+ ['br'],
236
+ ['b', ['m22 ']],
237
+ value.m22,
238
+ ['br'],
239
+ ['b', ['m23 ']],
240
+ value.m23,
241
+ ['br'],
242
+ ['b', ['m24 ']],
243
+ value.m24,
244
+ ['br'],
245
+
246
+ ['b', ['m31 ']],
247
+ value.m31,
248
+ ['br'],
249
+ ['b', ['m32 ']],
250
+ value.m32,
251
+ ['br'],
252
+ ['b', ['m33 ']],
253
+ value.m33,
254
+ ['br'],
255
+ ['b', ['m34 ']],
256
+ value.m34,
257
+ ['br'],
258
+
259
+ ['b', ['m41 ']],
260
+ value.m41,
261
+ ['br'],
262
+ ['b', ['m42 ']],
263
+ value.m42,
264
+ ['br'],
265
+ ['b', ['m43 ']],
266
+ value.m43,
267
+ ['br'],
268
+ ['b', ['m44 ']],
269
+ value.m44
270
+ ]]
271
+ ]];
272
+ },
273
+ editUI ({typeNamespace, value = {}}) {
274
+ idx++;
275
+ const {is2D} = value;
276
+ // eslint-disable-next-line @stylistic/max-len -- Long
277
+ return ['div', {dataset: {type: 'dommatrix'}}, /** @type {import('jamilih').JamilihChildren} */ ([
278
+ ['div', {
279
+ $on: {
280
+ click (e) {
281
+ const {target} = e;
282
+ /* c8 ignore next 3 */
283
+ if (/** @type {HTMLInputElement} */ (target).type !== 'radio') {
284
+ return;
285
+ }
286
+ const parent = /** @type {HTMLDivElement} */ (this.parentElement);
287
+ /** @type {HTMLDivElement} */ (
288
+ $e(parent, '.holder2d')
289
+ ).hidden = /** @type {HTMLInputElement} */ (target).value === '3d';
290
+ /** @type {HTMLDivElement} */ (
291
+ $e(parent, '.holder3d')
292
+ ).hidden = /** @type {HTMLInputElement} */ (target).value === '2d';
293
+ }
294
+ }
295
+ }, [
296
+ ['label', [
297
+ '2d',
298
+ ['input', {
299
+ class: 'd2',
300
+ type: 'radio', name: `${typeNamespace}-dommatrix-dimension-${idx}`,
301
+ value: '2d',
302
+ checked: Boolean(is2D)
303
+ }]
304
+ ]],
305
+ ' ',
306
+ ['label', [
307
+ '3d',
308
+ ['input', {
309
+ class: 'd3',
310
+ type: 'radio', name: `${typeNamespace}-dommatrix-dimension-${idx}`,
311
+ value: '3d',
312
+ checked: !is2D
313
+ }]
314
+ ]]
315
+ ]],
316
+ ['div', {
317
+ class: 'holder2d',
318
+ hidden: !is2D
319
+ }, (['a', 'b', 'c', 'd', 'e', 'f'].flatMap((label) => {
320
+ return [
321
+ ['br'],
322
+ ['label', [
323
+ label + ': ',
324
+ ['input', {
325
+ class: label,
326
+ name: `${typeNamespace}-dommatrix-${label}`,
327
+ value: value[label] ?? ''
328
+ }]
329
+ ]]
330
+ ];
331
+ })).slice(1)],
332
+ ['div', {
333
+ class: 'holder3d',
334
+ hidden: Boolean(is2D)
335
+ }, ([
336
+ 'm11', 'm12', 'm13', 'm14',
337
+ 'm21', 'm22', 'm23', 'm24',
338
+ 'm31', 'm32', 'm33', 'm34',
339
+ 'm41', 'm42', 'm43', 'm44'
340
+ ].flatMap((label) => {
341
+ return [
342
+ ['br'],
343
+ ['label', [
344
+ label + ': ',
345
+ ['input', {
346
+ class: label,
347
+ name: `${typeNamespace}-dommatrix-${label}`,
348
+ value: value[label] ?? ''
349
+ }]
350
+ ]]
351
+ ];
352
+ })).slice(1)]
353
+ ])];
354
+ }
355
+ };
356
+
357
+ export default dommatrixType;
@@ -0,0 +1,103 @@
1
+ import {$e} from '../utils/templateUtils.js';
2
+
3
+ /**
4
+ * @type {import('../types.js').TypeObject}
5
+ */
6
+ const dompointType = {
7
+ option: ['DOMPoint'],
8
+ stringRegex: /^DOMPoint\((.*)\)$/u,
9
+ toValue (s) {
10
+ const {x, y, z, w} = JSON.parse(s);
11
+ return {value: new DOMPoint(x, y, z, w)};
12
+ },
13
+ getInput ({root}) {
14
+ return /** @type {HTMLInputElement} */ ($e(root, 'input'));
15
+ },
16
+ setValue ({root, value}) {
17
+ /** @type {HTMLInputElement} */ (
18
+ $e(root, '.x')
19
+ ).value = String(value.x);
20
+ /** @type {HTMLInputElement} */ (
21
+ $e(root, '.y')
22
+ ).value = String(value.y);
23
+ /** @type {HTMLInputElement} */ (
24
+ $e(root, '.z')
25
+ ).value = String(value.z);
26
+ /** @type {HTMLInputElement} */ (
27
+ $e(root, '.w')
28
+ ).value = String(value.w);
29
+ },
30
+ getValue ({root}) {
31
+ const x = Number(/** @type {HTMLInputElement} */ (
32
+ $e(root, '.x')
33
+ ).value);
34
+ const y = Number(/** @type {HTMLInputElement} */ (
35
+ $e(root, '.y')
36
+ ).value);
37
+ const z = Number(/** @type {HTMLInputElement} */ (
38
+ $e(root, '.z')
39
+ ).value);
40
+ const w = Number(/** @type {HTMLInputElement} */ (
41
+ $e(root, '.w')
42
+ ).value);
43
+ return new DOMPoint(x, y, z, w);
44
+ },
45
+ viewUI ({value}) {
46
+ return ['div', {dataset: {type: 'dompoint'}}, [
47
+ ['b', ['x ']],
48
+ value.x,
49
+ ['br'],
50
+ ['b', ['y ']],
51
+ value.y,
52
+ ['br'],
53
+ ['b', ['z ']],
54
+ value.z,
55
+ ['br'],
56
+ ['b', ['w ']],
57
+ value.w
58
+ ]];
59
+ },
60
+ editUI ({typeNamespace, value = {
61
+ x: '',
62
+ y: '',
63
+ z: '',
64
+ w: ''
65
+ }}) {
66
+ // eslint-disable-next-line @stylistic/max-len -- Long
67
+ return ['div', {dataset: {type: 'dompoint'}}, /** @type {import('jamilih').JamilihChildren} */ ([
68
+ ['label', [
69
+ 'x: ',
70
+ ['input', {
71
+ class: 'x',
72
+ name: `${typeNamespace}-dompoint-x`, value: value.x
73
+ }]
74
+ ]],
75
+ ['br'],
76
+ ['label', [
77
+ 'y: ',
78
+ ['input', {
79
+ class: 'y',
80
+ name: `${typeNamespace}-dompoint-y`, value: value.y
81
+ }]
82
+ ]],
83
+ ['br'],
84
+ ['label', [
85
+ 'z: ',
86
+ ['input', {
87
+ class: 'z',
88
+ name: `${typeNamespace}-dompoint-z`, value: value.z
89
+ }]
90
+ ]],
91
+ ['br'],
92
+ ['label', [
93
+ 'w: ',
94
+ ['input', {
95
+ class: 'w',
96
+ name: `${typeNamespace}-dompoint-w`, value: value.w
97
+ }]
98
+ ]]
99
+ ])];
100
+ }
101
+ };
102
+
103
+ export default dompointType;