@es-joy/jsoe 0.13.8 → 0.15.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.
Files changed (73) hide show
  1. package/.eslintrc.cjs +7 -0
  2. package/.nyc_output/out.json +20068 -11970
  3. package/CHANGES.md +10 -0
  4. package/README.md +10 -21
  5. package/demo/index.js +79 -2
  6. package/dist/formats/indexedDBKey.d.ts.map +1 -1
  7. package/dist/formats/structuredCloning.d.ts.map +1 -1
  8. package/dist/fundamentalTypes/BooleanObjectType.d.ts.map +1 -1
  9. package/dist/fundamentalTypes/NumberObjectType.d.ts.map +1 -1
  10. package/dist/fundamentalTypes/StringObjectType.d.ts.map +1 -1
  11. package/dist/fundamentalTypes/arrayType.d.ts.map +1 -1
  12. package/dist/fundamentalTypes/blobType.d.ts.map +1 -1
  13. package/dist/fundamentalTypes/dateType.d.ts.map +1 -1
  14. package/dist/fundamentalTypes/fileType.d.ts.map +1 -1
  15. package/dist/fundamentalTypes/filelistType.d.ts.map +1 -1
  16. package/dist/fundamentalTypes/mapType.d.ts.map +1 -1
  17. package/dist/fundamentalTypes/noneditableType.d.ts +6 -0
  18. package/dist/fundamentalTypes/noneditableType.d.ts.map +1 -0
  19. package/dist/fundamentalTypes/objectReferenceType.d.ts.map +1 -1
  20. package/dist/fundamentalTypes/objectType.d.ts.map +1 -1
  21. package/dist/fundamentalTypes/setType.d.ts.map +1 -1
  22. package/dist/fundamentalTypes/sparseUndefinedType.d.ts.map +1 -1
  23. package/dist/fundamentalTypes/undefinedType.d.ts.map +1 -1
  24. package/dist/index.js +1980 -237
  25. package/dist/superTypes/SpecialNumberType.d.ts +2 -10
  26. package/dist/superTypes/SpecialNumberType.d.ts.map +1 -1
  27. package/dist/superTypes/SpecialRealNumberType.d.ts +2 -2
  28. package/dist/superTypes/SpecialRealNumberType.d.ts.map +1 -1
  29. package/dist/superTypes/buffersourceType.d.ts +8 -0
  30. package/dist/superTypes/buffersourceType.d.ts.map +1 -0
  31. package/dist/superTypes/dommatrixType.d.ts +6 -0
  32. package/dist/superTypes/dommatrixType.d.ts.map +1 -0
  33. package/dist/superTypes/dompointType.d.ts +6 -0
  34. package/dist/superTypes/dompointType.d.ts.map +1 -0
  35. package/dist/superTypes/domrectType.d.ts +6 -0
  36. package/dist/superTypes/domrectType.d.ts.map +1 -0
  37. package/dist/superTypes/errorsSpecialType.d.ts +2 -2
  38. package/dist/superTypes/errorsSpecialType.d.ts.map +1 -1
  39. package/dist/types.d.ts +29 -17
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/utils/media.d.ts.map +1 -1
  42. package/dist/vendor-imports.d.ts +1 -1
  43. package/package.json +13 -13
  44. package/src/formats/indexedDBKey.js +2 -3
  45. package/src/formats/structuredCloning.js +37 -20
  46. package/src/fundamentalTypes/BooleanObjectType.js +3 -1
  47. package/src/fundamentalTypes/NumberObjectType.js +3 -1
  48. package/src/fundamentalTypes/StringObjectType.js +3 -1
  49. package/src/fundamentalTypes/arrayType.js +4 -2
  50. package/src/fundamentalTypes/blobType.js +17 -13
  51. package/src/fundamentalTypes/dateType.js +6 -2
  52. package/src/fundamentalTypes/fileType.js +14 -12
  53. package/src/fundamentalTypes/filelistType.js +3 -1
  54. package/src/fundamentalTypes/mapType.js +3 -1
  55. package/src/fundamentalTypes/noneditableType.js +87 -0
  56. package/src/fundamentalTypes/objectReferenceType.js +3 -1
  57. package/src/fundamentalTypes/objectType.js +3 -1
  58. package/src/fundamentalTypes/setType.js +3 -1
  59. package/src/fundamentalTypes/sparseUndefinedType.js +3 -1
  60. package/src/fundamentalTypes/undefinedType.js +3 -1
  61. package/src/jsoe.css +64 -0
  62. package/src/subTypes/blobHTMLType.js +1 -1
  63. package/src/superTypes/SpecialNumberType.js +2 -8
  64. package/src/superTypes/SpecialRealNumberType.js +2 -2
  65. package/src/superTypes/buffersourceType.js +1455 -0
  66. package/src/{fundamentalTypes → superTypes}/dommatrixType.js +63 -10
  67. package/src/{fundamentalTypes → superTypes}/dompointType.js +60 -7
  68. package/src/{fundamentalTypes → superTypes}/domrectType.js +59 -7
  69. package/src/superTypes/errorsSpecialType.js +1 -1
  70. package/src/types.js +39 -22
  71. package/src/utils/media.js +3 -2
  72. package/src/vendor-imports.js +2 -1
  73. package/vendor/typeson-registry/dist/index.js +90 -28
@@ -132,7 +132,7 @@ function binaryButton (value, editable) {
132
132
  ['textarea', {
133
133
  class: 'view-binary'
134
134
  }, [
135
- /* c8 ignore next */
135
+ /* istanbul ignore next */
136
136
  /** @type {string|null} */ (reader.result) ?? ''
137
137
  ]]
138
138
  ])]
@@ -140,12 +140,13 @@ function binaryButton (value, editable) {
140
140
  });
141
141
  });
142
142
  // Seems not feasible to accurately simulate
143
- /* c8 ignore next 10 */
144
143
  reader.addEventListener(
145
144
  'error',
146
- /* c8 ignore next 6 */
145
+ /* istanbul ignore next */
147
146
  async function () {
147
+ /* istanbul ignore next */
148
148
  console.error(reader.error);
149
+ /* istanbul ignore next */
149
150
  await dialogs.alert(/** @type {string} */ (
150
151
  /** @type {DOMException} */ (reader.error).message
151
152
  ));
@@ -224,18 +225,19 @@ const fileType = {
224
225
  'Text source',
225
226
  ['br'],
226
227
  ['textarea', {class: 'view-text'}, [
227
- /* c8 ignore next */
228
+ /* istanbul ignore next */
228
229
  /** @type {string|null} */ (reader.result) ?? ''
229
230
  ]]
230
231
  ]));
231
232
  });
232
233
  // Seems not feasible to accurately simulate
233
- /* c8 ignore next 10 */
234
234
  reader.addEventListener(
235
235
  'error',
236
- /* c8 ignore next 6 */
236
+ /* istanbul ignore next */
237
237
  function () {
238
+ /* istanbul ignore next */
238
239
  console.error(reader.error);
240
+ /* istanbul ignore next */
239
241
  div.append(
240
242
  /** @type {DOMException} */ (reader.error).message
241
243
  );
@@ -548,7 +550,7 @@ const fileType = {
548
550
  * @this {HTMLInputElement}
549
551
  */
550
552
  change () {
551
- /* c8 ignore next 3 -- TS */
553
+ /* istanbul ignore if -- TS */
552
554
  if (!this.files) {
553
555
  return;
554
556
  }
@@ -696,7 +698,7 @@ const fileType = {
696
698
 
697
699
  if (constraints) {
698
700
  const mediaStream = await getUserMedia(constraints);
699
- /* c8 ignore next 4 */
701
+ /* istanbul ignore if */
700
702
  if (!mediaStream) {
701
703
  await dialogs.alert('Error getting user media');
702
704
  return;
@@ -744,7 +746,7 @@ const fileType = {
744
746
  const mediaStream = await startScreenCapture(
745
747
  screenShareConstraints
746
748
  );
747
- /* c8 ignore next 4 */
749
+ /* istanbul ignore if */
748
750
  if (!mediaStream) {
749
751
  await dialogs.alert('Error getting user media');
750
752
  return;
@@ -829,7 +831,7 @@ const fileType = {
829
831
  'video.previewMedia'
830
832
  ));
831
833
 
832
- /* c8 ignore next 4 */
834
+ /* istanbul ignore if */
833
835
  if (!previewMedia.srcObject) {
834
836
  dialogs.alert('No stream found to record');
835
837
  return;
@@ -862,7 +864,7 @@ const fileType = {
862
864
 
863
865
  try {
864
866
  mediaRecorder.start();
865
- /* c8 ignore next 4 */
867
+ /* istanbul ignore if */
866
868
  } catch (err) {
867
869
  dialogs.alert('Error starting media recorder');
868
870
  return;
@@ -1002,7 +1004,7 @@ const fileType = {
1002
1004
  ($e(videoContainer, 'img.photo'));
1003
1005
 
1004
1006
  canvas.toBlob((blob) => {
1005
- /* c8 ignore next 4 */
1007
+ /* istanbul ignore if */
1006
1008
  if (!blob) {
1007
1009
  dialogs.alert('Error converting canvas to Blob');
1008
1010
  return;
@@ -12,7 +12,9 @@ const filelistType = {
12
12
  stringRegexEnd: /^\)/u,
13
13
 
14
14
  toValue (...args) {
15
- return arrayType.toValue.apply(this, args);
15
+ return /** @type {import('../types.js').ToValue} */ (
16
+ arrayType.toValue
17
+ ).apply(this, args);
16
18
  },
17
19
  getValue (...args) {
18
20
  return arrayType.getValue.apply(this, args);
@@ -11,7 +11,9 @@ const mapType = {
11
11
  stringRegexBegin: /^Map\(/u,
12
12
  stringRegexEnd: /^\)/u,
13
13
  toValue (...args) {
14
- return arrayType.toValue.apply(this, args);
14
+ return /** @type {import('../types.js').ToValue} */ (
15
+ arrayType.toValue
16
+ ).apply(this, args);
15
17
  },
16
18
  getValue (...args) {
17
19
  return arrayType.getValue.apply(this, args);
@@ -0,0 +1,87 @@
1
+ import {toStringTag} from '../vendor-imports.js';
2
+ import {$e} from '../utils/templateUtils.js';
3
+
4
+ /**
5
+ * @type {import('../types.js').TypeObject}
6
+ */
7
+ const noneditableType = {
8
+ // Ideally, we would remove the option,
9
+ // but edit forms currently need a pull-down option
10
+ option: ['Non-editable'],
11
+ getInput ({root}) {
12
+ return /** @type {HTMLButtonElement} */ ($e(root, 'button'));
13
+ },
14
+ setValue ({root, value}) {
15
+ /** @type {HTMLButtonElement & {$value: any}} */ (
16
+ this.getInput({root})
17
+ ).$value = value;
18
+ /** @type {HTMLSpanElement} */ (
19
+ $e(root, '.stringTag')
20
+ ).textContent = value === undefined
21
+ ? '(None)'
22
+ : toStringTag(value);
23
+ },
24
+ getValue ({root}) {
25
+ return /** @type {HTMLButtonElement & {$value: any}} */ (
26
+ this.getInput({root})
27
+ ).$value;
28
+ },
29
+ validate ({root}) {
30
+ const val = /** @type {HTMLButtonElement & {$value: any}} */ (
31
+ this.getInput({root})
32
+ ).$value;
33
+ return {
34
+ message: 'The non-editable type is only for passing on ' +
35
+ 'pre-existing content that is unknown or currently unsupported',
36
+ valid: val !== undefined
37
+ };
38
+ },
39
+ viewUI ({value}) {
40
+ return ['div', {dataset: {type: 'resurrectable'}}, [
41
+ ['b', {class: 'emphasis'}, ['Non-editable']],
42
+ ['span', {
43
+ title: 'There is no current support for editing this element\'s ' +
44
+ 'type, but its contents will be passed on transparently.'
45
+ }, ['?']],
46
+ ['b', ['String tag: ']],
47
+ toStringTag(value)
48
+ ]];
49
+ },
50
+ editUI ({typeNamespace, value}) {
51
+ return ['div', {dataset: {type: 'resurrectable'}}, [
52
+ ['a', {
53
+ // eslint-disable-next-line no-script-url -- Safe
54
+ href: 'javascript:void(0)',
55
+ $on: {
56
+ click (e) {
57
+ e.preventDefault();
58
+ }
59
+ },
60
+ title: 'There is no current support for editing this element\'s ' +
61
+ 'type, but its contents will be passed on transparently.'
62
+ }, ['?']],
63
+ ' ',
64
+ ['button', {
65
+ $on: {
66
+ click (e) {
67
+ e.preventDefault();
68
+ console.log(/** @type {HTMLButtonElement & {$value: any}} */ (
69
+ this
70
+ ).$value);
71
+ }
72
+ },
73
+ name: `${typeNamespace}-resurrectable`,
74
+ $custom: {
75
+ $value: value
76
+ }
77
+ }, [
78
+ 'Non-editable'
79
+ ]],
80
+ ['br'],
81
+ ['b', ['String tag: ']],
82
+ ['span', {class: 'stringTag'}, [value ? toStringTag(value) : '(None)']]
83
+ ]];
84
+ }
85
+ };
86
+
87
+ export default noneditableType;
@@ -8,7 +8,9 @@ const objectReferenceType = {
8
8
  type: 'object',
9
9
  stringRegex: /^objectRef\((?:|\/[^)]*)\)$/u,
10
10
  toValue (...args) {
11
- return arrayReferenceType.toValue.apply(this, args);
11
+ return /** @type {import('../types.js').ToValue} */ (
12
+ arrayReferenceType.toValue
13
+ ).apply(this, args);
12
14
  },
13
15
  resolveReference (...args) {
14
16
  return arrayReferenceType.resolveReference?.apply(
@@ -9,7 +9,9 @@ const objectType = {
9
9
  stringRegexBegin: /^\{/u,
10
10
  stringRegexEnd: /^\}/u,
11
11
  toValue (...args) {
12
- return arrayType.toValue.apply(this, args);
12
+ return /** @type {import('../types.js').ToValue} */ (
13
+ arrayType.toValue
14
+ ).apply(this, args);
13
15
  },
14
16
  getValue (...args) {
15
17
  return arrayType.getValue.apply(this, args);
@@ -11,7 +11,9 @@ const setType = {
11
11
  stringRegexBegin: /^Set\(/u,
12
12
  stringRegexEnd: /^\)/u,
13
13
  toValue (...args) {
14
- return arrayType.toValue.apply(this, args);
14
+ return /** @type {import('../types.js').ToValue} */ (
15
+ arrayType.toValue
16
+ ).apply(this, args);
15
17
  },
16
18
  getValue (...args) {
17
19
  return arrayType.getValue.apply(this, args);
@@ -18,7 +18,9 @@ const sparseUndefinedType = {
18
18
  return {value: undefined};
19
19
  },
20
20
  getValue () {
21
- return this.toValue('').value;
21
+ return /** @type {import('../types.js').ToValue} */ (
22
+ this.toValue
23
+ )('').value;
22
24
  },
23
25
  /* istanbul ignore next -- Catching instead of this placeholder */
24
26
  viewUI (/* {value} */) {
@@ -10,7 +10,9 @@ const undefinedType = {
10
10
  return {value: undefined};
11
11
  },
12
12
  getValue () {
13
- return this.toValue('').value;
13
+ return /** @type {import('../types.js').ToValue} */ (
14
+ this.toValue
15
+ )('').value;
14
16
  },
15
17
  viewUI (/* {value} */) {
16
18
  return ['i', {dataset: {type: 'undef'}}, ['undefined']];
package/src/jsoe.css CHANGED
@@ -105,6 +105,70 @@ video.recordedMedia {
105
105
  background-color: lightgray;
106
106
  }
107
107
 
108
+ [data-type="buffersource"] {
109
+ background-color: beige;
110
+ }
111
+
108
112
  [class^="propertyName-"] {
109
113
  background-color: yellow;
110
114
  }
115
+
116
+ .typedArrayArea {
117
+ overflow: auto;
118
+ max-height: 250px;
119
+ }
120
+
121
+ /* -128 to 127 */
122
+ .typedArray-Int8Array {
123
+ width: 45px;
124
+ }
125
+
126
+ /* 0 to 255 */
127
+ .typedArray-Uint8Array {
128
+ width: 45px;
129
+ }
130
+
131
+ /* 0 to 255 */
132
+ .typedArray-Uint8ClampedArray {
133
+ width: 45px;
134
+ }
135
+
136
+ /* -32768 to 32767 */
137
+ .typedArray-Int16Array {
138
+ width: 65px;
139
+ }
140
+
141
+ /* 0 to 65535 */
142
+ .typedArray-Uint16Array {
143
+ width: 65px;
144
+ }
145
+
146
+ /* -2147483648 to 2147483647 */
147
+ .typedArray-Int32Array {
148
+ width: 100px;
149
+ }
150
+
151
+ /* 0 to 4294967295 */
152
+ .typedArray-Uint32Array {
153
+ width: 100px;
154
+ }
155
+
156
+ /* -3.4e38 to 3.4e38 */
157
+ .typedArray-Float32Array {
158
+ width: 120px;
159
+ }
160
+
161
+ /* -1.8e308 to 1.8e308 */
162
+ .typedArray-Float64Array {
163
+ width: 120px;
164
+ }
165
+
166
+ /* -2^63 to 2^63 - 1 */
167
+ .typedArray-BigInt64Array {
168
+ width: 120px;
169
+ }
170
+
171
+ /* 0 to 2^64 - 1 */
172
+ .typedArray-BigUint64Array {
173
+ width: 120px;
174
+ }
@@ -58,7 +58,7 @@ const blobHTMLType = {
58
58
  );
59
59
  },
60
60
  getValue ({root}) {
61
- return this.toValue(
61
+ return /** @type {import('../types.js').ToValue} */ (this.toValue)(
62
62
  'data:text/html,' + /** @type {SCEditorTextarea} */ (
63
63
  this.getInput({root})
64
64
  ).sceditorInstance.val()
@@ -1,13 +1,7 @@
1
1
  import {$e} from '../utils/templateUtils.js';
2
2
 
3
3
  /**
4
- * @typedef {import('../types.js').TypeObject & {
5
- * childTypes: string[]
6
- * }} SuperTypeObject
7
- */
8
-
9
- /**
10
- * @type {SuperTypeObject}
4
+ * @type {import('../types.js').SuperTypeObject}
11
5
  */
12
6
  const SpecialNumberSuperType = {
13
7
  option: ['Special Number', {title: '`NaN`, `Infinity`, `-Infinity`, `-0`'}],
@@ -32,7 +26,7 @@ const SpecialNumberSuperType = {
32
26
  return /** @type {HTMLSelectElement} */ ($e(root, 'select'));
33
27
  },
34
28
  getValue ({root}) {
35
- return this.toValue(
29
+ return /** @type {import('../types.js').ToValue} */ (this.toValue)(
36
30
  /** @type {Required<import('../types.js').TypeObject>} */ (
37
31
  this
38
32
  ).getSelect({root}).value
@@ -1,7 +1,7 @@
1
1
  import {$e} from '../utils/templateUtils.js';
2
2
 
3
3
  /**
4
- * @type {import('./SpecialNumberType.js').SuperTypeObject}
4
+ * @type {import('../types.js').SuperTypeObject}
5
5
  */
6
6
  const SpecialRealNumberSuperType = {
7
7
  option: ['Special Real Number', {title: '`Infinity`, `-Infinity`, `-0`'}],
@@ -20,7 +20,7 @@ const SpecialRealNumberSuperType = {
20
20
  return /** @type {HTMLSelectElement} */ ($e(root, 'select'));
21
21
  },
22
22
  getValue ({root}) {
23
- return this.toValue(
23
+ return /** @type {import('../types.js').ToValue} */ (this.toValue)(
24
24
  /** @type {Required<import('../types.js').TypeObject>} */ (
25
25
  this
26
26
  ).getSelect({root}).value