@es-joy/jsoe 0.13.8 → 0.14.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 (67) hide show
  1. package/.eslintrc.cjs +5 -0
  2. package/.nyc_output/out.json +13027 -11984
  3. package/CHANGES.md +6 -0
  4. package/README.md +5 -4
  5. package/demo/index.js +68 -2
  6. package/dist/formats/structuredCloning.d.ts.map +1 -1
  7. package/dist/fundamentalTypes/BooleanObjectType.d.ts.map +1 -1
  8. package/dist/fundamentalTypes/NumberObjectType.d.ts.map +1 -1
  9. package/dist/fundamentalTypes/StringObjectType.d.ts.map +1 -1
  10. package/dist/fundamentalTypes/arrayType.d.ts.map +1 -1
  11. package/dist/fundamentalTypes/blobType.d.ts.map +1 -1
  12. package/dist/fundamentalTypes/dateType.d.ts.map +1 -1
  13. package/dist/fundamentalTypes/fileType.d.ts.map +1 -1
  14. package/dist/fundamentalTypes/filelistType.d.ts.map +1 -1
  15. package/dist/fundamentalTypes/mapType.d.ts.map +1 -1
  16. package/dist/fundamentalTypes/noneditableType.d.ts +6 -0
  17. package/dist/fundamentalTypes/noneditableType.d.ts.map +1 -0
  18. package/dist/fundamentalTypes/objectReferenceType.d.ts.map +1 -1
  19. package/dist/fundamentalTypes/objectType.d.ts.map +1 -1
  20. package/dist/fundamentalTypes/setType.d.ts.map +1 -1
  21. package/dist/fundamentalTypes/sparseUndefinedType.d.ts.map +1 -1
  22. package/dist/fundamentalTypes/undefinedType.d.ts.map +1 -1
  23. package/dist/index.js +432 -107
  24. package/dist/superTypes/SpecialNumberType.d.ts +2 -10
  25. package/dist/superTypes/SpecialNumberType.d.ts.map +1 -1
  26. package/dist/superTypes/SpecialRealNumberType.d.ts +2 -2
  27. package/dist/superTypes/SpecialRealNumberType.d.ts.map +1 -1
  28. package/dist/superTypes/dommatrixType.d.ts +6 -0
  29. package/dist/superTypes/dommatrixType.d.ts.map +1 -0
  30. package/dist/superTypes/dompointType.d.ts +6 -0
  31. package/dist/superTypes/dompointType.d.ts.map +1 -0
  32. package/dist/superTypes/domrectType.d.ts +6 -0
  33. package/dist/superTypes/domrectType.d.ts.map +1 -0
  34. package/dist/superTypes/errorsSpecialType.d.ts +2 -2
  35. package/dist/superTypes/errorsSpecialType.d.ts.map +1 -1
  36. package/dist/types.d.ts +27 -14
  37. package/dist/types.d.ts.map +1 -1
  38. package/dist/utils/media.d.ts.map +1 -1
  39. package/dist/vendor-imports.d.ts +1 -1
  40. package/package.json +13 -13
  41. package/src/formats/structuredCloning.js +49 -6
  42. package/src/fundamentalTypes/BooleanObjectType.js +3 -1
  43. package/src/fundamentalTypes/NumberObjectType.js +3 -1
  44. package/src/fundamentalTypes/StringObjectType.js +3 -1
  45. package/src/fundamentalTypes/arrayType.js +4 -2
  46. package/src/fundamentalTypes/blobType.js +17 -13
  47. package/src/fundamentalTypes/dateType.js +6 -2
  48. package/src/fundamentalTypes/fileType.js +14 -12
  49. package/src/fundamentalTypes/filelistType.js +3 -1
  50. package/src/fundamentalTypes/mapType.js +3 -1
  51. package/src/fundamentalTypes/noneditableType.js +87 -0
  52. package/src/fundamentalTypes/objectReferenceType.js +3 -1
  53. package/src/fundamentalTypes/objectType.js +3 -1
  54. package/src/fundamentalTypes/setType.js +3 -1
  55. package/src/fundamentalTypes/sparseUndefinedType.js +3 -1
  56. package/src/fundamentalTypes/undefinedType.js +3 -1
  57. package/src/subTypes/blobHTMLType.js +1 -1
  58. package/src/superTypes/SpecialNumberType.js +2 -8
  59. package/src/superTypes/SpecialRealNumberType.js +2 -2
  60. package/src/{fundamentalTypes → superTypes}/dommatrixType.js +63 -10
  61. package/src/{fundamentalTypes → superTypes}/dompointType.js +60 -7
  62. package/src/{fundamentalTypes → superTypes}/domrectType.js +59 -7
  63. package/src/superTypes/errorsSpecialType.js +1 -1
  64. package/src/types.js +36 -15
  65. package/src/utils/media.js +3 -2
  66. package/src/vendor-imports.js +2 -1
  67. package/vendor/typeson-registry/dist/index.js +90 -28
package/src/types.js CHANGED
@@ -38,9 +38,10 @@ import fileType from './fundamentalTypes/fileType.js';
38
38
  import filelistType from './fundamentalTypes/filelistType.js';
39
39
  import blobType from './fundamentalTypes/blobType.js';
40
40
  import domexceptionType from './fundamentalTypes/domexceptionType.js';
41
- import domrectType from './fundamentalTypes/domrectType.js';
42
- import dompointType from './fundamentalTypes/dompointType.js';
43
- import dommatrixType from './fundamentalTypes/dommatrixType.js';
41
+ import domrectType from './superTypes/domrectType.js';
42
+ import dompointType from './superTypes/dompointType.js';
43
+ import dommatrixType from './superTypes/dommatrixType.js';
44
+ import noneditableType from './fundamentalTypes/noneditableType.js';
44
45
 
45
46
  /**
46
47
  * Utility to retrieve the property value given a legend element.
@@ -266,6 +267,16 @@ export const getPropertyValueFromLegend = (legend) => {
266
267
  * ) => void} TypeObjectSetValue
267
268
  */
268
269
 
270
+ /**
271
+ * @typedef {(
272
+ * s: string, info?: RootInfo
273
+ * ) => {
274
+ * value?: StructuredCloneValue,
275
+ * remnant?: string,
276
+ * assign?: false
277
+ * }} ToValue
278
+ */
279
+
269
280
  /**
270
281
  * @typedef {object} TypeObject
271
282
  * @property {[
@@ -295,13 +306,7 @@ export const getPropertyValueFromLegend = (legend) => {
295
306
  * check whether this subtype matches
296
307
  * @property {string} [superType] The greater fundamental type to which
297
308
  * the type belongs
298
- * @property {(
299
- * s: string, info?: RootInfo
300
- * ) => {
301
- * value?: StructuredCloneValue,
302
- * remnant?: string,
303
- * assign?: false
304
- * }} toValue Converts from string to value. May use
309
+ * @property {ToValue} [toValue] Converts from string to value. May use
305
310
  * `stringRegex` to find components.
306
311
  * @property {(info: {
307
312
  * root: HTMLDivElement,
@@ -370,9 +375,15 @@ export const getPropertyValueFromLegend = (legend) => {
370
375
  * "int8array"|"uint8array"|"uint8clampedarray"|"int16array"|"uint16array"|
371
376
  * "int32array"|"uint32array"|"float32array"|"float64array"|"ValidDate"|
372
377
  * "arrayNonindexKeys"|"error"|"errors"|"blob"|"domexception"|"domrect"|
373
- * "dompoint"|"dommatrix"} AvailableType
378
+ * "dompoint"|"dommatrix"|"resurrectable"} AvailableType
374
379
  */
375
380
 
381
+ /**
382
+ * @typedef {TypeObject & {
383
+ * childTypes: string[]
384
+ * }} SuperTypeObject
385
+ */
386
+
376
387
  /**
377
388
  *
378
389
  */
@@ -436,6 +447,8 @@ class Types {
436
447
  dompoint: dompointType,
437
448
  dommatrix: dommatrixType,
438
449
 
450
+ resurrectable: noneditableType,
451
+
439
452
  arraybuffer: {
440
453
  option: ['ArrayBuffer']
441
454
  },
@@ -594,6 +607,7 @@ class Types {
594
607
  // Ensure `stateObj` remains a reference if present
595
608
  return typeObject.getValue({
596
609
  root,
610
+ /* istanbul ignore next -- Guard */
597
611
  stateObj: stateObj ?? {
598
612
  types: this
599
613
  },
@@ -638,11 +652,12 @@ class Types {
638
652
 
639
653
  /** @type {GetOptionForType} */
640
654
  getOptionForType (type) {
655
+ const availableType = /** @type {TypeObject} */ (
656
+ this.availableTypes[type]
657
+ );
641
658
  /** @type {[string, {value?: AvailableType, title?: string}?]} */
642
659
  const optInfo = [
643
- ...(/** @type {TypeObject} */ (
644
- this.availableTypes[type]
645
- )).option
660
+ ...availableType.option
646
661
  ];
647
662
  optInfo[1] = {value: type, ...(optInfo[1])};
648
663
  return /** @type {[string, {value: AvailableType, title?: string}]} */ (
@@ -658,6 +673,7 @@ class Types {
658
673
  if (!typesForFormatAndState) {
659
674
  throw new Error('Unexpected type for format and state');
660
675
  }
676
+
661
677
  return typesForFormatAndState.map((type) => {
662
678
  return this.getOptionForType(type);
663
679
  });
@@ -840,7 +856,12 @@ class Types {
840
856
  // console.log('s0', s, '::', remnant, match);
841
857
  let valObj;
842
858
  try {
843
- valObj = /** @type {TypeObject} */ (found[1]).toValue(
859
+ const typeObj = /** @type {TypeObject} */ (found[1]);
860
+ /* istanbul ignore if -- TS guard */
861
+ if (!typeObj.toValue) {
862
+ throw new Error('Type has no `toValue` method');
863
+ }
864
+ valObj = typeObj.toValue(
844
865
  mtch.groups?.innerContent || innerContent || s, {
845
866
  types: this,
846
867
  format,
@@ -75,9 +75,10 @@ async function getUserMedia (constraints) {
75
75
  let stream = null;
76
76
  try {
77
77
  stream = await navigator.mediaDevices.getUserMedia(constraints);
78
- /* c8 ignore next 4 */
79
78
  } catch (err) {
79
+ /* istanbul ignore next */
80
80
  console.error('err', err);
81
+ /* istanbul ignore next */
81
82
  return null;
82
83
  }
83
84
  return stream;
@@ -93,8 +94,8 @@ async function startScreenCapture (displayMediaOptions) {
93
94
  try {
94
95
  captureStream =
95
96
  await navigator.mediaDevices.getDisplayMedia(displayMediaOptions);
96
- /* c8 ignore next 3 */
97
97
  } catch (err) {
98
+ /* istanbul ignore next */
98
99
  console.error(`Error: ${err}`);
99
100
  }
100
101
  return captureStream;
@@ -2,6 +2,7 @@ export {jml, body, nbsp, $} from 'jamilih';
2
2
  // export {jml, body, nbsp, $} from '../node_modules/jamilih/dist/jml-es.js';
3
3
 
4
4
  export {
5
- getJSONType, Typeson, unescapeKeyPathComponent, structuredCloningThrowing
5
+ getJSONType, Typeson, unescapeKeyPathComponent, structuredCloningThrowing,
6
+ resurrectable, toStringTag
6
7
  } from 'typeson-registry';
7
8
  // } from '../node_modules/typeson-registry/dist/index.js';
@@ -500,14 +500,29 @@ const domexception = {
500
500
  }
501
501
  };
502
502
 
503
- /* globals DOMMatrix */
503
+ /* globals DOMMatrix, DOMMatrixReadOnly */
504
504
 
505
505
  /**
506
506
  * @type {import('typeson').TypeSpecSet}
507
507
  */
508
- const dommatrix = {
509
- dommatrix: {
510
- test (x) { return toStringTag(x) === 'DOMMatrix'; },
508
+ const dommatrix = {};
509
+
510
+ /* c8 ignore next */
511
+ if (typeof DOMMatrix !== 'undefined') {
512
+ create$5(DOMMatrix);
513
+ }
514
+ /* c8 ignore next */
515
+ if (typeof DOMMatrixReadOnly !== 'undefined') {
516
+ create$5(DOMMatrixReadOnly);
517
+ }
518
+
519
+ /**
520
+ * @param {typeof DOMMatrix|typeof DOMMatrixReadOnly} Ctor
521
+ * @returns {void}
522
+ */
523
+ function create$5 (Ctor) {
524
+ dommatrix[Ctor.name.toLowerCase()] = {
525
+ test (x) { return toStringTag(x) === Ctor.name; },
511
526
  replace (dm) {
512
527
  if (dm.is2D) {
513
528
  return {
@@ -540,26 +555,41 @@ const dommatrix = {
540
555
  },
541
556
  revive (o) {
542
557
  if (Object.hasOwn(o, 'a')) {
543
- return new DOMMatrix([o.a, o.b, o.c, o.d, o.e, o.f]);
558
+ return new Ctor([o.a, o.b, o.c, o.d, o.e, o.f]);
544
559
  }
545
- return new DOMMatrix([
560
+ return new Ctor([
546
561
  o.m11, o.m12, o.m13, o.m14,
547
562
  o.m21, o.m22, o.m23, o.m24,
548
563
  o.m31, o.m32, o.m33, o.m34,
549
564
  o.m41, o.m42, o.m43, o.m44
550
565
  ]);
551
566
  }
552
- }
553
- };
567
+ };
568
+ }
554
569
 
555
- /* globals DOMPoint */
570
+ /* globals DOMPoint, DOMPointReadOnly */
556
571
 
557
572
  /**
558
573
  * @type {import('typeson').TypeSpecSet}
559
574
  */
560
- const dompoint = {
561
- dompoint: {
562
- test (x) { return toStringTag(x) === 'DOMPoint'; },
575
+ const dompoint = {};
576
+
577
+ /* c8 ignore next */
578
+ if (typeof DOMPoint !== 'undefined') {
579
+ create$4(DOMPoint);
580
+ }
581
+ /* c8 ignore next */
582
+ if (typeof DOMPointReadOnly !== 'undefined') {
583
+ create$4(DOMPointReadOnly);
584
+ }
585
+
586
+ /**
587
+ * @param {typeof DOMPoint|typeof DOMPointReadOnly} Ctor
588
+ * @returns {void}
589
+ */
590
+ function create$4 (Ctor) {
591
+ dompoint[Ctor.name.toLowerCase()] = {
592
+ test (x) { return toStringTag(x) === Ctor.name; },
563
593
  replace (dp) {
564
594
  return {
565
595
  x: dp.x,
@@ -569,19 +599,56 @@ const dompoint = {
569
599
  };
570
600
  },
571
601
  revive ({x, y, z, w}) {
572
- return new DOMPoint(x, y, z, w);
602
+ return new Ctor(x, y, z, w);
603
+ }
604
+ };
605
+ }
606
+
607
+ /* globals DOMQuad */
608
+
609
+ /**
610
+ * @type {import('typeson').TypeSpecSet}
611
+ */
612
+ const domquad = {
613
+ domquad: {
614
+ test (x) { return toStringTag(x) === 'DOMQuad'; },
615
+ replace (dp) {
616
+ return {
617
+ p1: dp.p1,
618
+ p2: dp.p2,
619
+ p3: dp.p3,
620
+ p4: dp.p4
621
+ };
622
+ },
623
+ revive ({p1, p2, p3, p4}) {
624
+ return new DOMQuad(p1, p2, p3, p4);
573
625
  }
574
626
  }
575
627
  };
576
628
 
577
- /* globals DOMRect */
629
+ /* globals DOMRect, DOMRectReadOnly */
578
630
 
579
631
  /**
580
632
  * @type {import('typeson').TypeSpecSet}
581
633
  */
582
- const domrect = {
583
- domrect: {
584
- test (x) { return toStringTag(x) === 'DOMRect'; },
634
+ const domrect = {};
635
+
636
+ /* c8 ignore next */
637
+ if (typeof DOMRect !== 'undefined') {
638
+ create$3(DOMRect);
639
+ }
640
+ /* c8 ignore next */
641
+ if (typeof DOMRectReadOnly !== 'undefined') {
642
+ create$3(DOMRectReadOnly);
643
+ }
644
+
645
+ /**
646
+ * @param {typeof DOMRect|typeof DOMRectReadOnly} Ctor
647
+ * @returns {void}
648
+ */
649
+ function create$3 (Ctor) {
650
+ domrect[Ctor.name.toLowerCase()] = {
651
+ test (x) { return toStringTag(x) === Ctor.name; },
585
652
  replace (dr) {
586
653
  return {
587
654
  x: dr.x,
@@ -591,10 +658,10 @@ const domrect = {
591
658
  };
592
659
  },
593
660
  revive ({x, y, width, height}) {
594
- return new DOMRect(x, y, width, height);
661
+ return new Ctor(x, y, width, height);
595
662
  }
596
- }
597
- };
663
+ };
664
+ }
598
665
 
599
666
  /**
600
667
  * @type {import('typeson').TypeSpecSet}
@@ -719,12 +786,6 @@ function create$2 (Ctor) {
719
786
  e.lineNumber = obj.lineNumber;
720
787
  e.columnNumber = obj.columnNumber;
721
788
 
722
- /* c8 ignore next 6 */
723
- if (isAggregateError) {
724
- /** @type {AggregateError} */ (
725
- e
726
- ).errors = obj.errors;
727
- }
728
789
  return e;
729
790
  }
730
791
  };
@@ -1604,6 +1665,8 @@ const expObj = [
1604
1665
  /* c8 ignore next */
1605
1666
  typeof DOMPoint !== 'undefined' ? dompoint : [],
1606
1667
  /* c8 ignore next */
1668
+ typeof DOMQuad !== 'undefined' ? domquad : [],
1669
+ /* c8 ignore next */
1607
1670
  typeof DOMMatrix !== 'undefined' ? dommatrix : []
1608
1671
  );
1609
1672
 
@@ -1673,7 +1736,6 @@ const structuredCloningThrowing = expObj.concat({
1673
1736
  typeof val.nodeType === 'number' &&
1674
1737
  typeof val.insertBefore === 'function')
1675
1738
  ) {
1676
- alert(stringTag);
1677
1739
  throw new DOMException(
1678
1740
  'The object cannot be cloned.', 'DataCloneError'
1679
1741
  );
@@ -1700,5 +1762,5 @@ const universal = [
1700
1762
  // built-in into ecmasript standard.
1701
1763
  ];
1702
1764
 
1703
- export { u as JSON_TYPES, c as Typeson, e as TypesonPromise, s as Undefined, arrayNonindexKeys, arraybuffer, bigint, bigintObject, blob, expObj$1 as builtin, cloneable, cryptokey, dataview, date, domexception, dommatrix, dompoint, domrect, error, errors, escapeKeyPathComponent, file, filelist, getByKeyPath, getJSONType, hasConstructorOf, imagebitmap, imagedata, infinity, intlTypes, isObject, isPlainObject, isThenable, isUserObject, map, nan, negativeInfinity, negativeZero, nonbuiltinIgnore, postmessage, primitiveObjects, regexp, resurrectable, set, setAtKeyPath, socketio, sparseUndefined, specialNumbers, expObj as structuredCloning, structuredCloningThrowing, toStringTag, typedArrays, typedArraysSocketIO as typedArraysSocketio, undef$1 as undef, undef as undefPreset, unescapeKeyPathComponent, universal, userObject };
1765
+ export { u as JSON_TYPES, c as Typeson, e as TypesonPromise, s as Undefined, arrayNonindexKeys, arraybuffer, bigint, bigintObject, blob, expObj$1 as builtin, cloneable, cryptokey, dataview, date, domexception, dommatrix, dompoint, domquad, domrect, error, errors, escapeKeyPathComponent, file, filelist, getByKeyPath, getJSONType, hasConstructorOf, imagebitmap, imagedata, infinity, intlTypes, isObject, isPlainObject, isThenable, isUserObject, map, nan, negativeInfinity, negativeZero, nonbuiltinIgnore, postmessage, primitiveObjects, regexp, resurrectable, set, setAtKeyPath, socketio, sparseUndefined, specialNumbers, expObj as structuredCloning, structuredCloningThrowing, toStringTag, typedArrays, typedArraysSocketIO as typedArraysSocketio, undef$1 as undef, undef as undefPreset, unescapeKeyPathComponent, universal, userObject };
1704
1766
  //# sourceMappingURL=index.js.map