typeson-registry 14.6.1 → 15.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.
Files changed (70) hide show
  1. package/dist/index.js +89 -71
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.min.js +1 -1
  4. package/dist/index.min.js.map +1 -1
  5. package/dist/index.umd.cjs +84 -70
  6. package/dist/index.umd.cjs.map +1 -1
  7. package/dist/index.umd.min.cjs +1 -1
  8. package/dist/index.umd.min.cjs.map +1 -1
  9. package/dist/polyfills/SyncBlobFile.d.ts.map +1 -1
  10. package/dist/polyfills/URL.d.ts.map +1 -1
  11. package/dist/polyfills/buildCanvasPolyfills.d.ts +78 -0
  12. package/dist/polyfills/buildCanvasPolyfills.d.ts.map +1 -0
  13. package/dist/polyfills/buildFileList.d.ts +21 -0
  14. package/dist/polyfills/buildFileList.d.ts.map +1 -0
  15. package/dist/polyfills/createImageBitmap.d.ts +3 -10
  16. package/dist/polyfills/createImageBitmap.d.ts.map +1 -1
  17. package/dist/polyfills/index.d.ts +2 -1
  18. package/dist/presets/builtin.umd.cjs +1 -1
  19. package/dist/presets/builtin.umd.cjs.map +1 -1
  20. package/dist/presets/postmessage.umd.cjs.map +1 -1
  21. package/dist/presets/socketio.umd.cjs +1 -1
  22. package/dist/presets/socketio.umd.cjs.map +1 -1
  23. package/dist/presets/structured-cloning-for-storage.umd.cjs +1 -1
  24. package/dist/presets/structured-cloning-for-storage.umd.cjs.map +1 -1
  25. package/dist/presets/structured-cloning-throwing.d.ts.map +1 -1
  26. package/dist/presets/structured-cloning-throwing.umd.cjs +1 -1
  27. package/dist/presets/structured-cloning-throwing.umd.cjs.map +1 -1
  28. package/dist/presets/structured-cloning.umd.cjs +1 -1
  29. package/dist/presets/structured-cloning.umd.cjs.map +1 -1
  30. package/dist/presets/universal.umd.cjs +1 -1
  31. package/dist/presets/universal.umd.cjs.map +1 -1
  32. package/dist/types/blob.d.ts.map +1 -1
  33. package/dist/types/blob.umd.cjs.map +1 -1
  34. package/dist/types/cloneable.umd.cjs.map +1 -1
  35. package/dist/types/cryptokey.umd.cjs.map +1 -1
  36. package/dist/types/date.d.ts.map +1 -1
  37. package/dist/types/date.umd.cjs +1 -1
  38. package/dist/types/date.umd.cjs.map +1 -1
  39. package/dist/types/dommatrix.umd.cjs.map +1 -1
  40. package/dist/types/dompoint.umd.cjs.map +1 -1
  41. package/dist/types/domrect.umd.cjs.map +1 -1
  42. package/dist/types/errors.umd.cjs.map +1 -1
  43. package/dist/types/file.d.ts.map +1 -1
  44. package/dist/types/file.umd.cjs.map +1 -1
  45. package/dist/types/filelist.d.ts.map +1 -1
  46. package/dist/types/filelist.umd.cjs.map +1 -1
  47. package/dist/types/imagebitmap.d.ts.map +1 -1
  48. package/dist/types/imagebitmap.umd.cjs +1 -1
  49. package/dist/types/imagebitmap.umd.cjs.map +1 -1
  50. package/dist/types/primitive-objects.d.ts.map +1 -1
  51. package/dist/types/primitive-objects.umd.cjs.map +1 -1
  52. package/dist/types/proto.d.ts +6 -0
  53. package/dist/types/proto.d.ts.map +1 -0
  54. package/dist/types/proto.umd.cjs +2 -0
  55. package/dist/types/proto.umd.cjs.map +1 -0
  56. package/dist/types/resurrectable.umd.cjs.map +1 -1
  57. package/dist/types/typed-arrays-socketio.umd.cjs.map +1 -1
  58. package/dist/types/typed-arrays.umd.cjs.map +1 -1
  59. package/dist/utils/generateUUID.d.ts.map +1 -1
  60. package/package.json +12 -11
  61. package/polyfills/SyncBlobFile.js +1 -4
  62. package/polyfills/URL.js +2 -5
  63. package/polyfills/buildCanvasPolyfills.js +246 -0
  64. package/polyfills/buildFileList.js +74 -0
  65. package/polyfills/index.cjs +563 -186
  66. package/polyfills/index.cjs.map +1 -1
  67. package/polyfills/index.js +2 -1
  68. package/utils/generateUUID.js +0 -1
  69. package/polyfills/FileList.js +0 -51
  70. package/polyfills/createImageBitmap.js +0 -22
package/dist/index.js CHANGED
@@ -332,8 +332,7 @@ const blob = {
332
332
  req.open('GET', URL.createObjectURL(b), false); // Sync
333
333
  req.send();
334
334
 
335
- // Seems not feasible to accurately simulate
336
- /* c8 ignore next 3 */
335
+ /* c8 ignore next 3 -- Seems not feasible to accurately simulate */
337
336
  if (req.status !== 200 && req.status !== 0) {
338
337
  throw new Error('Bad Blob access: ' + req.status);
339
338
  }
@@ -365,8 +364,8 @@ const blob = {
365
364
  )
366
365
  });
367
366
  });
368
- // Seems not feasible to accurately simulate
369
- /* c8 ignore next 3 */
367
+ // eslint-disable-next-line @stylistic/max-len -- Long
368
+ /* c8 ignore next 3 -- Seems not feasible to accurately simulate */
370
369
  reader.addEventListener('error', () => {
371
370
  reject(reader.error);
372
371
  });
@@ -386,7 +385,6 @@ const blob = {
386
385
  * @returns {string}
387
386
  */
388
387
  function generateUUID () { // Adapted from original: public domain/MIT: https://stackoverflow.com/a/8809472/271577
389
- /* c8 ignore next */
390
388
  let d = Date.now();
391
389
 
392
390
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replaceAll(/[xy]/gu, function (c) {
@@ -447,8 +445,8 @@ const cryptokey = {
447
445
  let jwk;
448
446
  try {
449
447
  jwk = await crypto.subtle.exportKey('jwk', key);
450
- // Our format should be valid and our key extractable
451
- /* c8 ignore next 4 */
448
+ // eslint-disable-next-line @stylistic/max-len -- Long
449
+ /* c8 ignore next 4 -- Our format should be valid and our key extractable */
452
450
  } catch (err) {
453
451
  reject(err);
454
452
  return;
@@ -550,16 +548,10 @@ const date = {
550
548
  test (x) { return toStringTag(x) === 'Date'; },
551
549
  replace (dt) {
552
550
  const time = dt.getTime();
553
- if (Number.isNaN(time)) {
554
- return 'NaN';
555
- }
556
- return time;
551
+ return Number.isNaN(time) ? 'NaN' : time;
557
552
  },
558
553
  revive (time) {
559
- if (time === 'NaN') {
560
- return new Date(NaN);
561
- }
562
- return new Date(time);
554
+ return new Date(time === 'NaN' ? NaN : time);
563
555
  }
564
556
  }
565
557
  };
@@ -591,11 +583,11 @@ const domexception = {
591
583
  */
592
584
  const dommatrix = {};
593
585
 
594
- /* c8 ignore next */
586
+ /* c8 ignore next -- Later support */
595
587
  if (typeof DOMMatrix !== 'undefined') {
596
588
  create$5(DOMMatrix);
597
589
  }
598
- /* c8 ignore next */
590
+ /* c8 ignore next -- Later support */
599
591
  if (typeof DOMMatrixReadOnly !== 'undefined') {
600
592
  create$5(DOMMatrixReadOnly);
601
593
  }
@@ -658,11 +650,11 @@ function create$5 (Ctor) {
658
650
  */
659
651
  const dompoint = {};
660
652
 
661
- /* c8 ignore next */
653
+ /* c8 ignore next -- Later support */
662
654
  if (typeof DOMPoint !== 'undefined') {
663
655
  create$4(DOMPoint);
664
656
  }
665
- /* c8 ignore next */
657
+ /* c8 ignore next -- Later support */
666
658
  if (typeof DOMPointReadOnly !== 'undefined') {
667
659
  create$4(DOMPointReadOnly);
668
660
  }
@@ -717,11 +709,11 @@ const domquad = {
717
709
  */
718
710
  const domrect = {};
719
711
 
720
- /* c8 ignore next */
712
+ /* c8 ignore next -- Later support */
721
713
  if (typeof DOMRect !== 'undefined') {
722
714
  create$3(DOMRect);
723
715
  }
724
- /* c8 ignore next */
716
+ /* c8 ignore next -- Later support */
725
717
  if (typeof DOMRectReadOnly !== 'undefined') {
726
718
  create$3(DOMRectReadOnly);
727
719
  }
@@ -861,12 +853,12 @@ const errors = {};
861
853
  EvalError, URIError
862
854
  ].forEach((error) => create$2(error));
863
855
 
864
- /* c8 ignore next 3 */
856
+ /* c8 ignore next 3 -- Later support */
865
857
  if (typeof AggregateError !== 'undefined') {
866
858
  create$2(AggregateError);
867
859
  }
868
860
 
869
- /* c8 ignore next 5 */
861
+ /* c8 ignore next 5 -- Non-standard */
870
862
  // @ts-expect-error Non-standard
871
863
  if (typeof InternalError === 'function') {
872
864
  // @ts-expect-error Non-standard
@@ -951,8 +943,7 @@ const file = {
951
943
  req.open('GET', URL.createObjectURL(f), false); // Sync
952
944
  req.send();
953
945
 
954
- // Seems not feasible to accurately simulate
955
- /* c8 ignore next 3 */
946
+ /* c8 ignore next 3 -- Seems not feasible to accurately simulate */
956
947
  if (req.status !== 200 && req.status !== 0) {
957
948
  throw new Error('Bad File access: ' + req.status);
958
949
  }
@@ -988,8 +979,8 @@ const file = {
988
979
  lastModified: f.lastModified
989
980
  });
990
981
  });
991
- // Seems not feasible to accurately simulate
992
- /* c8 ignore next 3 */
982
+ // eslint-disable-next-line @stylistic/max-len -- Long
983
+ /* c8 ignore next 3 -- Seems not feasible to accurately simulate */
993
984
  reader.addEventListener('error', function () {
994
985
  reject(reader.error);
995
986
  });
@@ -1045,6 +1036,7 @@ const filelist = {
1045
1036
  }
1046
1037
  }
1047
1038
 
1039
+ // eslint-disable-next-line jsdoc/ts-ban-ts-comment -- TS 6/7
1048
1040
  // @ts-ignore Override API
1049
1041
  return new FileList(o);
1050
1042
  }
@@ -1072,8 +1064,7 @@ const idbkeyrange = {
1072
1064
  };
1073
1065
 
1074
1066
  /* globals document, OffscreenCanvas, createImageBitmap -- Polyfills */
1075
- // `ImageBitmap` is browser / DOM specific. It also can only work
1076
- // same-domain (or CORS)
1067
+ // `ImageBitmap` can only work same-domain (or CORS) in the browser
1077
1068
 
1078
1069
 
1079
1070
  /**
@@ -1082,10 +1073,7 @@ const idbkeyrange = {
1082
1073
  const imagebitmap = {
1083
1074
  imagebitmap: {
1084
1075
  test (x) {
1085
- return toStringTag(x) === 'ImageBitmap' ||
1086
- // In Node, our polyfill sets the dataset on a canvas
1087
- // element as JSDom no longer allows overriding toStringTag
1088
- (x && x.dataset && x.dataset.toStringTag === 'ImageBitmap');
1076
+ return toStringTag(x) === 'ImageBitmap';
1089
1077
  },
1090
1078
  replace (bm) {
1091
1079
  const canvas = document.createElement('canvas');
@@ -1099,8 +1087,8 @@ const imagebitmap = {
1099
1087
  },
1100
1088
  revive (o) {
1101
1089
  const canvas = typeof OffscreenCanvas === 'undefined'
1090
+ /* c8 ignore next -- Older environments */
1102
1091
  ? document.createElement('canvas')
1103
- /* c8 ignore next -- Browser only */
1104
1092
  : new OffscreenCanvas(o.width, o.height);
1105
1093
  /*
1106
1094
  var req = new XMLHttpRequest();
@@ -1117,14 +1105,19 @@ const imagebitmap = {
1117
1105
  const img = document.createElement('img');
1118
1106
  // The onload is needed by some browsers per https://stackoverflow.com/a/4776378/271577
1119
1107
  img.addEventListener('load', function () {
1120
- ctx.drawImage(img, 0, 0);
1108
+ try {
1109
+ ctx.drawImage(img, 0, 0);
1110
+ } catch {
1111
+ // Issues on Node
1112
+ }
1121
1113
  });
1122
1114
  img.src = o.dataURL;
1115
+
1123
1116
  // Works in contexts allowing an `ImageBitmap` (We might use
1124
1117
  // `OffscreenCanvas.transferToBitmap` when supported)
1125
1118
  return typeof OffscreenCanvas === 'undefined'
1119
+ /* c8 ignore next 3 -- Older environments */
1126
1120
  ? canvas
1127
- /* c8 ignore next 3 -- Browser only */
1128
1121
  : /** @type {OffscreenCanvas} */ (
1129
1122
  canvas
1130
1123
  ).transferToImageBitmap();
@@ -1145,7 +1138,7 @@ const imagebitmap = {
1145
1138
  try {
1146
1139
  const resp = await createImageBitmap(canvas);
1147
1140
  resolve(resp);
1148
- /* c8 ignore next 3 */
1141
+ /* c8 ignore next 3 -- How to simulate? */
1149
1142
  } catch (err) {
1150
1143
  reject(err);
1151
1144
  }
@@ -1409,10 +1402,7 @@ const primitiveObjects = {
1409
1402
  if (n === '-Infinity') {
1410
1403
  return new Number(-Infinity);
1411
1404
  }
1412
- if (n === '-0') {
1413
- return new Number(-0);
1414
- }
1415
- return new Number(n);
1405
+ return new Number(n === '-0' ? -0 : n);
1416
1406
  }
1417
1407
  }
1418
1408
  };
@@ -1647,11 +1637,11 @@ if (typeof Int8Array === 'function') {
1647
1637
  Float64Array,
1648
1638
  ...(typeof BigInt64Array === 'function'
1649
1639
  ? [BigInt64Array, BigUint64Array]
1650
- /* c8 ignore next */
1640
+ /* c8 ignore next -- Later support */
1651
1641
  : []),
1652
1642
  ...(typeof Float16Array === 'function'
1653
1643
  ? [Float16Array]
1654
- /* c8 ignore next */
1644
+ /* c8 ignore next -- Later support */
1655
1645
  : [])
1656
1646
  ].forEach((TypedArray) => create$1(TypedArray));
1657
1647
  }
@@ -1755,11 +1745,11 @@ if (typeof Int8Array === 'function') {
1755
1745
  Float64Array,
1756
1746
  ...(typeof BigInt64Array === 'function'
1757
1747
  ? [BigInt64Array, BigUint64Array]
1758
- /* c8 ignore next */
1748
+ /* c8 ignore next -- Later support */
1759
1749
  : []),
1760
1750
  ...(typeof Float16Array === 'function'
1761
1751
  ? [Float16Array]
1762
- /* c8 ignore next */
1752
+ /* c8 ignore next -- Later support */
1763
1753
  : [])
1764
1754
  ].forEach((TypedArray) => create(TypedArray));
1765
1755
  }
@@ -2013,20 +2003,20 @@ const expObj$1 = [
2013
2003
  date, error, errors, regexp
2014
2004
  ].concat(
2015
2005
  // ES2015 (ES6)
2016
- /* c8 ignore next */
2006
+ /* c8 ignore next -- ES6+ */
2017
2007
  typeof Map === 'function' ? map : [],
2018
- /* c8 ignore next */
2008
+ /* c8 ignore next -- ES6+ */
2019
2009
  typeof Set === 'function' ? set : [],
2020
- /* c8 ignore next */
2010
+ /* c8 ignore next -- Later support */
2021
2011
  typeof ArrayBuffer === 'function' ? arraybuffer : [],
2022
- /* c8 ignore next */
2012
+ /* c8 ignore next -- Later support */
2023
2013
  typeof Uint8Array === 'function' ? typedArrays : [],
2024
- /* c8 ignore next */
2014
+ /* c8 ignore next -- Later support */
2025
2015
  typeof DataView === 'function' ? dataview : [],
2026
- /* c8 ignore next */
2016
+ /* c8 ignore next -- Later support */
2027
2017
  typeof Intl !== 'undefined' ? intlTypes : [],
2028
2018
 
2029
- /* c8 ignore next */
2019
+ /* c8 ignore next -- Later support */
2030
2020
  typeof BigInt !== 'undefined' ? [bigint, bigintObject] : []
2031
2021
  );
2032
2022
 
@@ -2116,41 +2106,41 @@ const expObj = [
2116
2106
  errors
2117
2107
  ].concat(
2118
2108
  // ES2015 (ES6)
2119
- /* c8 ignore next */
2109
+ /* c8 ignore next -- ES6+ */
2120
2110
  typeof Map === 'function' ? map : [],
2121
- /* c8 ignore next */
2111
+ /* c8 ignore next -- ES6+ */
2122
2112
  typeof Set === 'function' ? set : [],
2123
- /* c8 ignore next */
2113
+ /* c8 ignore next -- Later support */
2124
2114
  typeof ArrayBuffer === 'function' ? arraybuffer : [],
2125
- /* c8 ignore next */
2115
+ /* c8 ignore next -- Later support */
2126
2116
  typeof Uint8Array === 'function' ? typedArrays : [],
2127
- /* c8 ignore next */
2117
+ /* c8 ignore next -- Later support */
2128
2118
  typeof DataView === 'function' ? dataview : [],
2129
- /* c8 ignore next */
2119
+ /* c8 ignore next -- Later support */
2130
2120
  typeof crypto !== 'undefined' ? cryptokey : [],
2131
- /* c8 ignore next */
2121
+ /* c8 ignore next -- Later support */
2132
2122
  typeof BigInt !== 'undefined' ? [bigint, bigintObject] : [],
2133
- /* c8 ignore next */
2123
+ /* c8 ignore next -- Later support */
2134
2124
  typeof DOMException !== 'undefined' ? domexception : [],
2135
- /* c8 ignore next */
2125
+ /* c8 ignore next -- Later support */
2136
2126
  typeof QuotaExceededError !== 'undefined' ? quotaexceedederror : [],
2137
- /* c8 ignore next */
2127
+ /* c8 ignore next -- Later support */
2138
2128
  typeof WebTransportError !== 'undefined' ? webtransporterror : [],
2139
- /* c8 ignore next */
2129
+ /* c8 ignore next -- Later support */
2140
2130
  typeof DOMRect !== 'undefined' ? domrect : [],
2141
- /* c8 ignore next */
2131
+ /* c8 ignore next -- Later support */
2142
2132
  typeof DOMPoint !== 'undefined' ? dompoint : [],
2143
- /* c8 ignore next */
2133
+ /* c8 ignore next -- Later support */
2144
2134
  typeof DOMQuad !== 'undefined' ? domquad : [],
2145
- /* c8 ignore next */
2135
+ /* c8 ignore next -- Later support */
2146
2136
  typeof DOMMatrix !== 'undefined' ? dommatrix : [],
2147
- /* c8 ignore next */
2137
+ /* c8 ignore next -- Later support */
2148
2138
  typeof AudioData !== 'undefined' ? audiodata : [],
2149
- /* c8 ignore next */
2139
+ /* c8 ignore next -- Later support */
2150
2140
  typeof EncodedAudioChunk !== 'undefined' ? encodedaudiochunk : [],
2151
- /* c8 ignore next */
2141
+ /* c8 ignore next -- Later support */
2152
2142
  typeof EncodedVideoChunk !== 'undefined' ? encodedvideochunk : [],
2153
- /* c8 ignore next */
2143
+ /* c8 ignore next -- Later support */
2154
2144
  typeof VideoFrame !== 'undefined' ? videoframe : []
2155
2145
  );
2156
2146
 
@@ -2229,12 +2219,40 @@ const structuredCloningThrowing = expObj.concat({
2229
2219
  // WeakSet instances have an extra slot ([[WeakSetData]])
2230
2220
  // but not throwing in Chrome `postMessage`
2231
2221
  'WeakSet',
2222
+ // WeakRef instances have an extra slot
2223
+ // ([[WeakRefTarget]])
2224
+ 'WeakRef',
2225
+ // FinalizationRegistry instances have extra internal
2226
+ // slots (e.g., [[Cells]])
2227
+ 'FinalizationRegistry',
2228
+ // Generator objects have an extra slot
2229
+ // ([[GeneratorState]])
2230
+ 'Generator',
2231
+ // Async generator objects have an extra slot
2232
+ // ([[AsyncGeneratorState]])
2233
+ 'AsyncGenerator',
2234
+ // Built-in iterator result objects have internal slots
2235
+ // tied to the collection/string being iterated
2236
+ 'String Iterator', 'Array Iterator',
2237
+ 'Map Iterator', 'Set Iterator', 'RegExp String Iterator',
2238
+ // `Intl` objects (e.g., `Intl.Collator`) all have
2239
+ // internal slots and are not structured-cloneable
2240
+ 'Intl.Collator', 'Intl.DateTimeFormat',
2241
+ 'Intl.DisplayNames', 'Intl.DurationFormat',
2242
+ 'Intl.ListFormat', 'Intl.Locale', 'Intl.NumberFormat',
2243
+ 'Intl.PluralRules', 'Intl.RelativeTimeFormat',
2244
+ 'Intl.Segmenter',
2232
2245
 
2233
2246
  // HTML-SPECIFIC
2234
2247
  'Event',
2235
2248
  // Also in Node `worker_threads` (currently experimental)
2236
2249
  'MessageChannel',
2237
- 'MessagePort'
2250
+ 'MessagePort',
2251
+ // Streams are Transferable but not Serializable, so
2252
+ // cloning them (as opposed to transferring) throws
2253
+ 'ReadableStream', 'WritableStream', 'TransformStream',
2254
+ // Also Transferable but not Serializable
2255
+ 'OffscreenCanvas'
2238
2256
  ].includes(stringTag) ||
2239
2257
  // Node's native `worker_threads` `MessageChannel`/
2240
2258
  // `MessagePort` don't set `Symbol.toStringTag` per