typeson-registry 13.1.0 → 13.2.1

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.
@@ -1110,6 +1110,79 @@
1110
1110
 
1111
1111
  // See also typed-arrays!
1112
1112
 
1113
+ /* globals AudioData -- Polyfills */
1114
+
1115
+ /**
1116
+ * @type {import('typeson').TypeSpecSet}
1117
+ */
1118
+ var audiodata = {
1119
+ audiodata: {
1120
+ test: function test(x) {
1121
+ return toStringTag(x) === 'AudioData';
1122
+ },
1123
+ replace: function replace(audioData) {
1124
+ var format = audioData.format,
1125
+ sampleRate = audioData.sampleRate,
1126
+ numberOfFrames = audioData.numberOfFrames,
1127
+ numberOfChannels = audioData.numberOfChannels,
1128
+ timestamp = audioData.timestamp;
1129
+
1130
+ // 2. Determine plane layout based on audio format
1131
+ var isPlanar = format.endsWith('-planar');
1132
+ var numPlanes = isPlanar ? numberOfChannels : 1;
1133
+
1134
+ // 3. Per the AudioData API, planes are laid out back-to-back
1135
+ // within a single buffer, so compute their sizes up front
1136
+ var planeSizes = [];
1137
+ var totalSize = 0;
1138
+ for (var i = 0; i < numPlanes; i++) {
1139
+ var size = audioData.allocationSize({
1140
+ planeIndex: i
1141
+ });
1142
+ planeSizes.push(size);
1143
+ totalSize += size;
1144
+ }
1145
+
1146
+ // 4. Copy the raw binary data out of each plane into its slot
1147
+ var data = new ArrayBuffer(totalSize);
1148
+ var offset = 0;
1149
+ for (var _i = 0; _i < numPlanes; _i++) {
1150
+ var planeView = new Uint8Array(data, offset, planeSizes[_i]);
1151
+ audioData.copyTo(planeView, {
1152
+ planeIndex: _i
1153
+ });
1154
+ offset += planeSizes[_i];
1155
+ }
1156
+
1157
+ // 5. Return a clean, serializable manifest
1158
+ return {
1159
+ format: format,
1160
+ sampleRate: sampleRate,
1161
+ numberOfFrames: numberOfFrames,
1162
+ numberOfChannels: numberOfChannels,
1163
+ timestamp: timestamp,
1164
+ data: data
1165
+ };
1166
+ },
1167
+ revive: function revive(_ref) {
1168
+ var format = _ref.format,
1169
+ sampleRate = _ref.sampleRate,
1170
+ numberOfFrames = _ref.numberOfFrames,
1171
+ numberOfChannels = _ref.numberOfChannels,
1172
+ timestamp = _ref.timestamp,
1173
+ data = _ref.data;
1174
+ return new AudioData({
1175
+ format: format,
1176
+ sampleRate: sampleRate,
1177
+ numberOfFrames: numberOfFrames,
1178
+ numberOfChannels: numberOfChannels,
1179
+ timestamp: timestamp,
1180
+ data: new Uint8Array(data)
1181
+ });
1182
+ }
1183
+ }
1184
+ };
1185
+
1113
1186
  /**
1114
1187
  * @type {import('typeson').TypeSpecSet}
1115
1188
  */
@@ -1967,7 +2040,7 @@
1967
2040
  return 'FileList';
1968
2041
  }
1969
2042
  }]);
1970
- }();
2043
+ }(); // @ts-ignore Override API
1971
2044
  return new FileList(o);
1972
2045
  }
1973
2046
  }
@@ -2792,7 +2865,35 @@
2792
2865
  typeof DOMRect !== 'undefined' ? domrect : [], /* c8 ignore next */
2793
2866
  typeof DOMPoint !== 'undefined' ? dompoint : [], /* c8 ignore next */
2794
2867
  typeof DOMQuad !== 'undefined' ? domquad : [], /* c8 ignore next */
2795
- typeof DOMMatrix !== 'undefined' ? dommatrix : []);
2868
+ typeof DOMMatrix !== 'undefined' ? dommatrix : [], /* c8 ignore next */
2869
+ typeof AudioData !== 'undefined' ? audiodata : []);
2870
+
2871
+ /**
2872
+ * @param {BufferSource} buffer
2873
+ * @returns {boolean}
2874
+ */
2875
+ function isBufferDetached(buffer) {
2876
+ // Use the standard property if available
2877
+ // @ts-expect-error - More recent API
2878
+ if (typeof buffer.detached === 'boolean') {
2879
+ // @ts-expect-error - More recent API
2880
+ return buffer.detached;
2881
+ }
2882
+ /* c8 ignore next 14 -- Older browsers */
2883
+
2884
+ // Fallback check via byteLength and constructor test
2885
+ if (buffer.byteLength !== 0) {
2886
+ return false;
2887
+ }
2888
+ try {
2889
+ // @ts-expect-error Ok
2890
+ // eslint-disable-next-line no-new -- Throwaway
2891
+ new Uint8Array(buffer);
2892
+ return false;
2893
+ } catch (_unused) {
2894
+ return true;
2895
+ }
2896
+ }
2796
2897
 
2797
2898
  /**
2798
2899
  * @type {import('typeson').Preset}
@@ -2801,13 +2902,11 @@
2801
2902
  checkDataCloneException: {
2802
2903
  test: function test(val) {
2803
2904
  // Should also throw with:
2804
- // 1. `IsDetachedBuffer` (a process not called within the
2805
- // ECMAScript spec)
2806
- // 2. `IsCallable` (covered by `typeof === 'function'` or a
2905
+ // 1. `IsCallable` (covered by `typeof === 'function'` or a
2807
2906
  // function's `toStringTag`)
2808
- // 3. internal slots besides [[Prototype]] or [[Extensible]] (e.g.,
2907
+ // 2. internal slots besides [[Prototype]] or [[Extensible]] (e.g.,
2809
2908
  // [[PromiseState]] or [[WeakMapData]])
2810
- // 4. exotic object (e.g., `Proxy`) (unless an `%ObjectPrototype%`
2909
+ // 3. exotic object (e.g., `Proxy`) (unless an `%ObjectPrototype%`
2811
2910
  // intrinsic object) (which does not have default
2812
2911
  // behavior for one or more of the essential internal methods
2813
2912
  // that are limited to the following for non-function objects
@@ -2843,7 +2942,10 @@
2843
2942
  // HTML-SPECIFIC
2844
2943
  'Event',
2845
2944
  // Also in Node `worker_threads` (currently experimental)
2846
- 'MessageChannel'].includes(stringTag) || (
2945
+ 'MessageChannel'].includes(stringTag) ||
2946
+ // 1. `IsDetachedBuffer` (a process not called within the
2947
+ // ECMAScript spec)
2948
+ ['ArrayBuffer', 'DataView', 'Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array', 'Float64Array', 'BigInt64Array', 'BigUint64Array'].includes(stringTag) && isBufferDetached(val) || (
2847
2949
  /*
2848
2950
  // isClosed is no longer documented
2849
2951
  ((stringTag === 'Blob' || stringTag === 'File') &&
@@ -2879,6 +2981,7 @@
2879
2981
  exports.Undefined = Undefined;
2880
2982
  exports.arrayNonindexKeys = arrayNonindexKeys;
2881
2983
  exports.arraybuffer = arraybuffer;
2984
+ exports.audiodata = audiodata;
2882
2985
  exports.bigint = bigint;
2883
2986
  exports.bigintObject = bigintObject;
2884
2987
  exports.blob = blob;