@loaders.gl/splats 5.0.0-alpha.11 → 5.0.0-alpha.13

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 (60) hide show
  1. package/LICENSE +1 -1
  2. package/dist/dist.dev.js +1307 -1717
  3. package/dist/dist.min.js +33 -33
  4. package/dist/index.cjs +223 -907
  5. package/dist/index.cjs.map +3 -3
  6. package/dist/ksplat-loader-types.d.ts +1 -1
  7. package/dist/ksplat-loader-types.d.ts.map +1 -1
  8. package/dist/ksplat-loader-types.js +1 -1
  9. package/dist/ksplat-loader.d.ts +1 -1
  10. package/dist/ksplat-loader.d.ts.map +1 -1
  11. package/dist/lib/parse-ksplat.d.ts +1 -1
  12. package/dist/lib/parse-ksplat.d.ts.map +1 -1
  13. package/dist/lib/parse-rad-chunk.d.ts +3 -1
  14. package/dist/lib/parse-rad-chunk.d.ts.map +1 -1
  15. package/dist/lib/parse-rad-chunk.js +4 -0
  16. package/dist/lib/parse-rad-chunk.js.map +1 -1
  17. package/dist/lib/parse-splat.d.ts +1 -1
  18. package/dist/lib/parse-splat.d.ts.map +1 -1
  19. package/dist/lib/parse-spz.d.ts +1 -1
  20. package/dist/lib/parse-spz.d.ts.map +1 -1
  21. package/dist/lib/splats-arrow-table.d.ts +1 -1
  22. package/dist/lib/splats-arrow-table.d.ts.map +1 -1
  23. package/dist/rad-loader-types.js +1 -1
  24. package/dist/rad-loader.d.ts +1 -1
  25. package/dist/rad-loader.d.ts.map +1 -1
  26. package/dist/rad-loader.js +1 -1
  27. package/dist/rad-loader.js.map +1 -1
  28. package/dist/rad-source-loader.d.ts +3 -3
  29. package/dist/rad-source-loader.d.ts.map +1 -1
  30. package/dist/rad-source-loader.js +5 -3
  31. package/dist/rad-source-loader.js.map +1 -1
  32. package/dist/splat-loader-types.d.ts +1 -1
  33. package/dist/splat-loader-types.d.ts.map +1 -1
  34. package/dist/splat-loader-types.js +1 -1
  35. package/dist/splat-loader.d.ts +1 -1
  36. package/dist/splat-loader.d.ts.map +1 -1
  37. package/dist/spz-loader-types.d.ts +1 -1
  38. package/dist/spz-loader-types.d.ts.map +1 -1
  39. package/dist/spz-loader-types.js +1 -1
  40. package/dist/spz-loader.d.ts +1 -1
  41. package/dist/spz-loader.d.ts.map +1 -1
  42. package/dist/types.d.ts +1 -1
  43. package/dist/types.d.ts.map +1 -1
  44. package/package.json +5 -7
  45. package/src/ksplat-loader-types.ts +2 -2
  46. package/src/ksplat-loader.ts +2 -2
  47. package/src/lib/parse-ksplat.ts +1 -1
  48. package/src/lib/parse-rad-chunk.ts +6 -1
  49. package/src/lib/parse-splat.ts +1 -1
  50. package/src/lib/parse-spz.ts +1 -1
  51. package/src/lib/splats-arrow-table.ts +1 -1
  52. package/src/rad-loader-types.ts +1 -1
  53. package/src/rad-loader.ts +2 -1
  54. package/src/rad-source-loader.ts +6 -3
  55. package/src/splat-loader-types.ts +2 -2
  56. package/src/splat-loader.ts +2 -2
  57. package/src/splats-format.ts +1 -1
  58. package/src/spz-loader-types.ts +2 -2
  59. package/src/spz-loader.ts +2 -2
  60. package/src/types.ts +1 -1
package/dist/index.cjs CHANGED
@@ -5,12 +5,12 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __esm = (fn, res, err2) => function __init() {
9
- if (err2) throw err2[0];
8
+ var __esm = (fn, res, err) => function __init() {
9
+ if (err) throw err[0];
10
10
  try {
11
11
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
12
12
  } catch (e) {
13
- throw err2 = [e], e;
13
+ throw err = [e], e;
14
14
  }
15
15
  };
16
16
  var __export = (target, all) => {
@@ -81,7 +81,7 @@ var init_splats_format = __esm({
81
81
  }
82
82
  });
83
83
 
84
- // ../loader-utils/src/lib/log-utils/log.ts
84
+ // ../core/src/loader-utils/lib/log-utils/log.ts
85
85
  function createLog() {
86
86
  const log2 = new import_log.Log({ id: "loaders.gl" });
87
87
  globalThis.loaders ||= {};
@@ -93,27 +93,26 @@ function createLog() {
93
93
  }
94
94
  var import_log, VERSION, version, log;
95
95
  var init_log = __esm({
96
- "../loader-utils/src/lib/log-utils/log.ts"() {
96
+ "../core/src/loader-utils/lib/log-utils/log.ts"() {
97
97
  "use strict";
98
- import_log = require("@probe.gl/log");
98
+ import_log = require("probe.gl/log");
99
99
  VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
100
100
  version = VERSION[0] >= "0" && VERSION[0] <= "9" ? `v${VERSION}` : "";
101
101
  log = createLog();
102
102
  }
103
103
  });
104
104
 
105
- // ../loader-utils/src/lib/javascript-utils/is-type.ts
106
- var isObject, isPureObject, isSharedArrayBuffer;
105
+ // ../core/src/loader-utils/lib/javascript-utils/is-type.ts
106
+ var isObject, isPureObject;
107
107
  var init_is_type = __esm({
108
- "../loader-utils/src/lib/javascript-utils/is-type.ts"() {
108
+ "../core/src/loader-utils/lib/javascript-utils/is-type.ts"() {
109
109
  "use strict";
110
110
  isObject = (value) => value !== null && typeof value === "object";
111
111
  isPureObject = (value) => isObject(value) && value.constructor === {}.constructor;
112
- isSharedArrayBuffer = (value) => typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer;
113
112
  }
114
113
  });
115
114
 
116
- // ../loader-utils/src/lib/option-utils/merge-options.ts
115
+ // ../core/src/loader-utils/lib/option-utils/merge-options.ts
117
116
  function mergeOptions(baseOptions, newOptions) {
118
117
  return mergeOptionsRecursively(baseOptions || {}, newOptions);
119
118
  }
@@ -136,38 +135,25 @@ function mergeOptionsRecursively(baseOptions, newOptions, level = 0) {
136
135
  return options;
137
136
  }
138
137
  var init_merge_options = __esm({
139
- "../loader-utils/src/lib/option-utils/merge-options.ts"() {
138
+ "../core/src/loader-utils/lib/option-utils/merge-options.ts"() {
140
139
  "use strict";
141
140
  init_is_type();
142
141
  }
143
142
  });
144
143
 
145
- // ../loader-utils/src/lib/module-utils/js-module-utils.ts
144
+ // ../core/src/loader-utils/lib/module-utils/js-module-utils.ts
146
145
  function registerJSModules(modules) {
147
146
  globalThis.loaders ||= {};
148
147
  globalThis.loaders.modules ||= {};
149
148
  Object.assign(globalThis.loaders.modules, modules);
150
149
  }
151
- function getJSModule(name, caller) {
152
- var _a, _b;
153
- const module2 = (_b = (_a = globalThis.loaders) == null ? void 0 : _a.modules) == null ? void 0 : _b[name];
154
- if (!module2) {
155
- throw new Error(`${caller}: ${name} library not installed`);
156
- }
157
- return module2;
158
- }
159
- function getJSModuleOrNull(name) {
160
- var _a, _b;
161
- const module2 = (_b = (_a = globalThis.loaders) == null ? void 0 : _a.modules) == null ? void 0 : _b[name];
162
- return module2 || null;
163
- }
164
150
  var init_js_module_utils = __esm({
165
- "../loader-utils/src/lib/module-utils/js-module-utils.ts"() {
151
+ "../core/src/loader-utils/lib/module-utils/js-module-utils.ts"() {
166
152
  "use strict";
167
153
  }
168
154
  });
169
155
 
170
- // ../loader-utils/src/lib/binary-utils/array-buffer-utils.ts
156
+ // ../core/src/loader-utils/lib/binary-utils/array-buffer-utils.ts
171
157
  function concatenateArrayBuffers(...sources) {
172
158
  return concatenateArrayBuffersFromArray(sources);
173
159
  }
@@ -185,12 +171,12 @@ function concatenateArrayBuffersFromArray(sources) {
185
171
  return result.buffer;
186
172
  }
187
173
  var init_array_buffer_utils = __esm({
188
- "../loader-utils/src/lib/binary-utils/array-buffer-utils.ts"() {
174
+ "../core/src/loader-utils/lib/binary-utils/array-buffer-utils.ts"() {
189
175
  "use strict";
190
176
  }
191
177
  });
192
178
 
193
- // ../loader-utils/src/lib/iterators/async-iteration.ts
179
+ // ../core/src/loader-utils/lib/iterators/async-iteration.ts
194
180
  async function concatenateArrayBuffersAsync(asyncIterator) {
195
181
  const arrayBuffers = [];
196
182
  for await (const chunk of asyncIterator) {
@@ -215,13 +201,13 @@ function copyFromBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength -
215
201
  return copy.buffer;
216
202
  }
217
203
  var init_async_iteration = __esm({
218
- "../loader-utils/src/lib/iterators/async-iteration.ts"() {
204
+ "../core/src/loader-utils/lib/iterators/async-iteration.ts"() {
219
205
  "use strict";
220
206
  init_array_buffer_utils();
221
207
  }
222
208
  });
223
209
 
224
- // ../loader-utils/src/lib/request-utils/authentication.ts
210
+ // ../core/src/loader-utils/lib/request-utils/authentication.ts
225
211
  function resolveCredentials(credentials, authentications = []) {
226
212
  if (credentials.every(isAuthentication)) return credentials;
227
213
  return credentials.map((credential, index) => {
@@ -258,12 +244,12 @@ function isAuthentication(credential) {
258
244
  return (credential.type === "header" || credential.type === "query-parameter") && typeof credential.name === "string" && (typeof credential.token === "string" || typeof credential.token === "function") && Array.isArray(credential.refreshStatusCodes);
259
245
  }
260
246
  var init_authentication = __esm({
261
- "../loader-utils/src/lib/request-utils/authentication.ts"() {
247
+ "../core/src/loader-utils/lib/request-utils/authentication.ts"() {
262
248
  "use strict";
263
249
  }
264
250
  });
265
251
 
266
- // ../loader-utils/src/lib/request-utils/request-credentials.ts
252
+ // ../core/src/loader-utils/lib/request-utils/request-credentials.ts
267
253
  function createAuthenticatedFetch(options) {
268
254
  const suppliedFetch = options.fetch || ((url, requestOptions) => fetch(url, requestOptions));
269
255
  const existingMetadata = suppliedFetch[AUTHENTICATED_FETCH];
@@ -493,7 +479,7 @@ function createAbortError() {
493
479
  }
494
480
  var AUTHENTICATED_FETCH, refreshPromises;
495
481
  var init_request_credentials = __esm({
496
- "../loader-utils/src/lib/request-utils/request-credentials.ts"() {
482
+ "../core/src/loader-utils/lib/request-utils/request-credentials.ts"() {
497
483
  "use strict";
498
484
  init_authentication();
499
485
  AUTHENTICATED_FETCH = /* @__PURE__ */ Symbol("loaders.gl.authenticated-fetch");
@@ -501,7 +487,7 @@ var init_request_credentials = __esm({
501
487
  }
502
488
  });
503
489
 
504
- // ../loader-utils/src/lib/path-utils/file-aliases.ts
490
+ // ../core/src/loader-utils/lib/path-utils/file-aliases.ts
505
491
  function resolvePath(filename) {
506
492
  for (const alias in fileAliases) {
507
493
  if (filename.startsWith(alias)) {
@@ -516,41 +502,14 @@ function resolvePath(filename) {
516
502
  }
517
503
  var pathPrefix, fileAliases;
518
504
  var init_file_aliases = __esm({
519
- "../loader-utils/src/lib/path-utils/file-aliases.ts"() {
505
+ "../core/src/loader-utils/lib/path-utils/file-aliases.ts"() {
520
506
  "use strict";
521
507
  pathPrefix = "";
522
508
  fileAliases = {};
523
509
  }
524
510
  });
525
511
 
526
- // ../loader-utils/src/lib/binary-utils/memory-conversion-utils.ts
527
- function ensureArrayBuffer(bufferSource) {
528
- if (bufferSource instanceof ArrayBuffer) {
529
- return bufferSource;
530
- }
531
- if (isSharedArrayBuffer(bufferSource)) {
532
- return copyToArrayBuffer2(bufferSource);
533
- }
534
- const { buffer, byteOffset, byteLength } = bufferSource;
535
- if (buffer instanceof ArrayBuffer && byteOffset === 0 && byteLength === buffer.byteLength) {
536
- return buffer;
537
- }
538
- return copyToArrayBuffer2(buffer, byteOffset, byteLength);
539
- }
540
- function copyToArrayBuffer2(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
541
- const view = new Uint8Array(buffer, byteOffset, byteLength);
542
- const copy = new Uint8Array(view.length);
543
- copy.set(view);
544
- return copy.buffer;
545
- }
546
- var init_memory_conversion_utils = __esm({
547
- "../loader-utils/src/lib/binary-utils/memory-conversion-utils.ts"() {
548
- "use strict";
549
- init_is_type();
550
- }
551
- });
552
-
553
- // ../loader-utils/src/lib/sources/data-source.ts
512
+ // ../core/src/loader-utils/lib/sources/data-source.ts
554
513
  function getFetchFunction(options) {
555
514
  return getAuthenticatedFetch(options);
556
515
  }
@@ -602,7 +561,7 @@ function unavailableCoreApiMethod(methodName) {
602
561
  }
603
562
  var UNAVAILABLE_CORE_API, DataSource;
604
563
  var init_data_source = __esm({
605
- "../loader-utils/src/lib/sources/data-source.ts"() {
564
+ "../core/src/loader-utils/lib/sources/data-source.ts"() {
606
565
  "use strict";
607
566
  init_merge_options();
608
567
  init_file_aliases();
@@ -693,24 +652,22 @@ var init_data_source = __esm({
693
652
  }
694
653
  });
695
654
 
696
- // ../loader-utils/src/index.ts
697
- var init_src = __esm({
698
- "../loader-utils/src/index.ts"() {
655
+ // ../core/src/loader-utils/index.ts
656
+ var init_loader_utils = __esm({
657
+ "../core/src/loader-utils/index.ts"() {
699
658
  "use strict";
700
659
  init_js_module_utils();
701
- init_js_module_utils();
702
660
  init_async_iteration();
703
- init_memory_conversion_utils();
704
661
  init_data_source();
705
662
  }
706
663
  });
707
664
 
708
665
  // ../compression/src/lib/compression.ts
709
- var CompressionTransform, Compressor, Decompressor, Compression;
666
+ var CompressionTransform, Decompressor;
710
667
  var init_compression = __esm({
711
668
  "../compression/src/lib/compression.ts"() {
712
669
  "use strict";
713
- init_src();
670
+ init_loader_utils();
714
671
  CompressionTransform = class {
715
672
  /** Preloads any dynamic libraries. May enable sync functions */
716
673
  async preload(modules = {}) {
@@ -728,26 +685,6 @@ var init_compression = __esm({
728
685
  return error;
729
686
  }
730
687
  };
731
- Compressor = class extends CompressionTransform {
732
- constructor(options) {
733
- super();
734
- this.compressBatches = this.compressBatches.bind(this);
735
- }
736
- /** Asynchronously compresses data. */
737
- async compress(input) {
738
- await this.preload();
739
- return this.compressSync(input);
740
- }
741
- /** Synchronously compresses data. */
742
- compressSync(input) {
743
- throw new Error(`${this.name}: sync compression not supported`);
744
- }
745
- /** Compresses batches. */
746
- async *compressBatches(asyncIterator) {
747
- const input = await this.concatenate(asyncIterator);
748
- yield this.compress(input);
749
- }
750
- };
751
688
  Decompressor = class extends CompressionTransform {
752
689
  constructor(options) {
753
690
  super();
@@ -768,112 +705,6 @@ var init_compression = __esm({
768
705
  yield this.decompress(input);
769
706
  }
770
707
  };
771
- Compression = class extends Compressor {
772
- constructor(options) {
773
- super(options);
774
- this.decompressBatches = this.decompressBatches.bind(this);
775
- }
776
- /** Asynchronously decompresses data. */
777
- async decompress(input, size) {
778
- await this.preload();
779
- return this.decompressSync(input, size);
780
- }
781
- /** Synchronously decompresses data. */
782
- decompressSync(input, size) {
783
- throw new Error(`${this.name}: sync decompression not supported`);
784
- }
785
- /** Decompresses batches. */
786
- async *decompressBatches(asyncIterator) {
787
- const input = await this.concatenate(asyncIterator);
788
- yield this.decompress(input);
789
- }
790
- };
791
- }
792
- });
793
-
794
- // ../compression/src/lib/compression-stream.ts
795
- async function compressWithNativeCompressionStream(input, format) {
796
- const outputBatches = compressBatchesWithNativeCompressionStream([input], format);
797
- return outputBatches ? await concatenateBatches(outputBatches) : null;
798
- }
799
- function compressBatchesWithNativeCompressionStream(inputBatches, format) {
800
- const compressionStream = createNativeCompressionStream(format);
801
- return compressionStream ? transformBatches(inputBatches, compressionStream) : null;
802
- }
803
- function createNativeCompressionStream(format) {
804
- if (typeof globalThis.CompressionStream === "undefined") {
805
- return null;
806
- }
807
- try {
808
- const CompressionStreamConstructor = globalThis.CompressionStream;
809
- return new CompressionStreamConstructor(format);
810
- } catch (error) {
811
- if (error instanceof TypeError || (error == null ? void 0 : error.name) === "TypeError") {
812
- return null;
813
- }
814
- throw error;
815
- }
816
- }
817
- async function* transformBatches(inputBatches, compressionStream) {
818
- const writer = compressionStream.writable.getWriter();
819
- const reader = compressionStream.readable.getReader();
820
- const writePromise = writeBatches(inputBatches, writer);
821
- writePromise.catch(() => {
822
- });
823
- let outputCompleted = false;
824
- try {
825
- while (true) {
826
- const { done, value } = await reader.read();
827
- if (done) {
828
- outputCompleted = true;
829
- break;
830
- }
831
- yield new Uint8Array(value).buffer;
832
- }
833
- await writePromise;
834
- } finally {
835
- if (!outputCompleted) {
836
- await reader.cancel().catch(() => {
837
- });
838
- await writer.abort().catch(() => {
839
- });
840
- await writePromise.catch(() => {
841
- });
842
- }
843
- reader.releaseLock();
844
- }
845
- }
846
- async function writeBatches(inputBatches, writer) {
847
- try {
848
- for await (const inputBatch of inputBatches) {
849
- await writer.write(new Uint8Array(inputBatch));
850
- }
851
- await writer.close();
852
- } catch (error) {
853
- await writer.abort(error).catch(() => {
854
- });
855
- throw error;
856
- }
857
- }
858
- async function concatenateBatches(batches) {
859
- const output = [];
860
- let byteLength = 0;
861
- for await (const batch of batches) {
862
- const bytes = new Uint8Array(batch);
863
- output.push(bytes);
864
- byteLength += bytes.byteLength;
865
- }
866
- const result = new Uint8Array(byteLength);
867
- let offset = 0;
868
- for (const batch of output) {
869
- result.set(batch, offset);
870
- offset += batch.byteLength;
871
- }
872
- return result.buffer;
873
- }
874
- var init_compression_stream = __esm({
875
- "../compression/src/lib/compression-stream.ts"() {
876
- "use strict";
877
708
  }
878
709
  });
879
710
 
@@ -1094,494 +925,138 @@ var init_lazy_compression = __esm({
1094
925
  }
1095
926
  });
1096
927
 
1097
- // ../compression/src/lib/fflate/index.ts
1098
- function inflateSync(data, out) {
1099
- return inflt(data, out);
1100
- }
1101
- function gunzipSync(data, out) {
1102
- return inflt(data.subarray(gzs(data), -8), out || new u8(gzl(data)));
928
+ // ../compression/src/lib/compress-utils-compression.ts
929
+ async function* transformBatches(stream, inputBatches, maximumOutputByteLength = Number.POSITIVE_INFINITY) {
930
+ let outputByteLength = 0;
931
+ try {
932
+ for await (const input of inputBatches) {
933
+ const output2 = stream.write(new Uint8Array(input));
934
+ if (output2.byteLength > maximumOutputByteLength - outputByteLength)
935
+ throw new RangeError("Decompressed output exceeds maxOutputByteLength");
936
+ outputByteLength += output2.byteLength;
937
+ if (output2.byteLength > 0) yield copyArrayBuffer(output2);
938
+ }
939
+ const output = stream.finish();
940
+ if (output.byteLength > maximumOutputByteLength - outputByteLength)
941
+ throw new RangeError("Decompressed output exceeds maxOutputByteLength");
942
+ if (output.byteLength > 0) yield copyArrayBuffer(output);
943
+ } finally {
944
+ stream.destroy();
945
+ }
1103
946
  }
1104
- function unzlibSync(data, out) {
1105
- return inflt((zlv(data), data.subarray(2, -4)), out);
947
+ function copyArrayBuffer(bytes) {
948
+ return bytes.slice().buffer;
1106
949
  }
1107
- var u8, u16, u32, fleb, fdeb, clim, freb, fl, revfl, fd, revfd, rev, hMap, flt, fdt, flrm, fdrm, max, bits, bits16, shft, slc, ec, err, inflt, gzs, gzl, zlv, Inflate, Gunzip, Unzlib;
1108
- var init_fflate = __esm({
1109
- "../compression/src/lib/fflate/index.ts"() {
950
+ function getDecompressOptions(options, size) {
951
+ const decodeOptions = {
952
+ ...options.compressUtils,
953
+ ...size === void 0 ? {} : { expectedSize: size }
954
+ };
955
+ const capacity = decodeOptions.expectedSize;
956
+ const maximum = getMaximumOutputByteLength(options);
957
+ if (capacity !== void 0 && (!Number.isSafeInteger(capacity) || capacity < 0 || capacity > maximum)) {
958
+ throw new RangeError("expectedSize exceeds the configured output capacity limit");
959
+ }
960
+ return decodeOptions;
961
+ }
962
+ function getMaximumOutputByteLength(options) {
963
+ const maximum = options.maxOutputByteLength ?? 512 * 1024 * 1024;
964
+ if (!Number.isSafeInteger(maximum) || maximum < 0 || maximum > 2147483647)
965
+ throw new RangeError("Invalid maxOutputByteLength");
966
+ return maximum;
967
+ }
968
+ function copyDecompressedOutput(bytes, options) {
969
+ if (bytes.byteLength > getMaximumOutputByteLength(options))
970
+ throw new RangeError("Decompressed output exceeds maxOutputByteLength");
971
+ return copyArrayBuffer(bytes);
972
+ }
973
+ var CompressUtilsDecompressor;
974
+ var init_compress_utils_compression = __esm({
975
+ "../compression/src/lib/compress-utils-compression.ts"() {
1110
976
  "use strict";
1111
- u8 = Uint8Array;
1112
- u16 = Uint16Array;
1113
- u32 = Uint32Array;
1114
- fleb = new u8([
1115
- 0,
1116
- 0,
1117
- 0,
1118
- 0,
1119
- 0,
1120
- 0,
1121
- 0,
1122
- 0,
1123
- 1,
1124
- 1,
1125
- 1,
1126
- 1,
1127
- 2,
1128
- 2,
1129
- 2,
1130
- 2,
1131
- 3,
1132
- 3,
1133
- 3,
1134
- 3,
1135
- 4,
1136
- 4,
1137
- 4,
1138
- 4,
1139
- 5,
1140
- 5,
1141
- 5,
1142
- 5,
1143
- 0,
1144
- /* unused */
1145
- 0,
1146
- 0,
1147
- /* impossible */
1148
- 0
1149
- ]);
1150
- fdeb = new u8([
1151
- 0,
1152
- 0,
1153
- 0,
1154
- 0,
1155
- 1,
1156
- 1,
1157
- 2,
1158
- 2,
1159
- 3,
1160
- 3,
1161
- 4,
1162
- 4,
1163
- 5,
1164
- 5,
1165
- 6,
1166
- 6,
1167
- 7,
1168
- 7,
1169
- 8,
1170
- 8,
1171
- 9,
1172
- 9,
1173
- 10,
1174
- 10,
1175
- 11,
1176
- 11,
1177
- 12,
1178
- 12,
1179
- 13,
1180
- 13,
1181
- /* unused */
1182
- 0,
1183
- 0
1184
- ]);
1185
- clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
1186
- freb = (eb, start) => {
1187
- const b = new u16(31);
1188
- for (let i = 0; i < 31; ++i) {
1189
- b[i] = start += 1 << eb[i - 1];
1190
- }
1191
- const r = new u32(b[30]);
1192
- for (let i = 1; i < 30; ++i) {
1193
- for (let j = b[i]; j < b[i + 1]; ++j) {
1194
- r[j] = j - b[i] << 5 | i;
1195
- }
1196
- }
1197
- return [b, r];
1198
- };
1199
- [fl, revfl] = freb(fleb, 2);
1200
- fl[28] = 258, revfl[258] = 28;
1201
- [fd, revfd] = freb(fdeb, 0);
1202
- rev = new u16(32768);
1203
- for (let i = 0; i < 32768; ++i) {
1204
- let x = (i & 43690) >>> 1 | (i & 21845) << 1;
1205
- x = (x & 52428) >>> 2 | (x & 13107) << 2;
1206
- x = (x & 61680) >>> 4 | (x & 3855) << 4;
1207
- rev[i] = ((x & 65280) >>> 8 | (x & 255) << 8) >>> 1;
1208
- }
1209
- hMap = (cd, mb, r) => {
1210
- const s = cd.length;
1211
- let i = 0;
1212
- const l = new u16(mb);
1213
- for (; i < s; ++i) {
1214
- if (cd[i]) ++l[cd[i] - 1];
1215
- }
1216
- const le = new u16(mb);
1217
- for (i = 0; i < mb; ++i) {
1218
- le[i] = le[i - 1] + l[i - 1] << 1;
1219
- }
1220
- let co;
1221
- if (r) {
1222
- co = new u16(1 << mb);
1223
- const rvb = 15 - mb;
1224
- for (i = 0; i < s; ++i) {
1225
- if (cd[i]) {
1226
- const sv = i << 4 | cd[i];
1227
- const r2 = mb - cd[i];
1228
- let v = le[cd[i] - 1]++ << r2;
1229
- for (const m = v | (1 << r2) - 1; v <= m; ++v) {
1230
- co[rev[v] >>> rvb] = sv;
1231
- }
1232
- }
1233
- }
1234
- } else {
1235
- co = new u16(s);
1236
- for (i = 0; i < s; ++i) {
1237
- if (cd[i]) {
1238
- co[i] = rev[le[cd[i] - 1]++] >>> 15 - cd[i];
1239
- }
1240
- }
1241
- }
1242
- return co;
1243
- };
1244
- flt = new u8(288);
1245
- for (let i = 0; i < 144; ++i) flt[i] = 8;
1246
- for (let i = 144; i < 256; ++i) flt[i] = 9;
1247
- for (let i = 256; i < 280; ++i) flt[i] = 7;
1248
- for (let i = 280; i < 288; ++i) flt[i] = 8;
1249
- fdt = new u8(32);
1250
- for (let i = 0; i < 32; ++i) fdt[i] = 5;
1251
- flrm = /* @__PURE__ */ hMap(flt, 9, 1);
1252
- fdrm = /* @__PURE__ */ hMap(fdt, 5, 1);
1253
- max = (a) => {
1254
- let m = a[0];
1255
- for (let i = 1; i < a.length; ++i) {
1256
- if (a[i] > m) m = a[i];
977
+ init_compression();
978
+ CompressUtilsDecompressor = class extends Decompressor {
979
+ name;
980
+ extensions;
981
+ contentEncodings;
982
+ isSupported = true;
983
+ options;
984
+ loadModule;
985
+ /** Module initialized for synchronous operations. */
986
+ module = null;
987
+ /** Shared import and WASM initialization for concurrent callers. */
988
+ modulePromise = null;
989
+ /** Creates a format-specific compress-utils decoder. */
990
+ constructor(metadata, loadModule, options = {}) {
991
+ super(options);
992
+ this.name = metadata.name;
993
+ this.extensions = metadata.extensions || [];
994
+ this.contentEncodings = metadata.contentEncodings || [];
995
+ this.loadModule = loadModule;
996
+ this.options = options;
1257
997
  }
1258
- return m;
1259
- };
1260
- bits = (d, p, m) => {
1261
- const o = p / 8 | 0;
1262
- return (d[o] | d[o + 1] << 8) >> (p & 7) & m;
1263
- };
1264
- bits16 = (d, p) => {
1265
- const o = p / 8 | 0;
1266
- return (d[o] | d[o + 1] << 8 | d[o + 2] << 16) >> (p & 7);
1267
- };
1268
- shft = (p) => (p + 7) / 8 | 0;
1269
- slc = (v, s, e) => {
1270
- if (s == null || s < 0) s = 0;
1271
- if (e == null || e > v.length) e = v.length;
1272
- const n = new (v.BYTES_PER_ELEMENT == 2 ? u16 : v.BYTES_PER_ELEMENT == 4 ? u32 : u8)(e - s);
1273
- n.set(v.subarray(s, e));
1274
- return n;
1275
- };
1276
- ec = [
1277
- "unexpected EOF",
1278
- "invalid block type",
1279
- "invalid length/literal",
1280
- "invalid distance",
1281
- "stream finished",
1282
- "no stream handler",
1283
- ,
1284
- // determined by compression function
1285
- "no callback",
1286
- "invalid UTF-8 data",
1287
- "extra field too long",
1288
- "date not in range 1980-2099",
1289
- "filename too long",
1290
- "stream finishing",
1291
- "invalid zip data"
1292
- // determined by unknown compression method
1293
- ];
1294
- err = (ind, msg, nt) => {
1295
- const e = new Error(msg || ec[ind]);
1296
- e.code = ind;
1297
- if (Error.captureStackTrace) Error.captureStackTrace(e, err);
1298
- if (!nt) throw e;
1299
- return e;
1300
- };
1301
- inflt = (dat, buf, st) => {
1302
- const sl = dat.length;
1303
- if (!sl || st && st.f && !st.l) return buf || new u8(0);
1304
- const noBuf = !buf || st;
1305
- const noSt = !st || st.i;
1306
- if (!st) st = {};
1307
- if (!buf) buf = new u8(sl * 3);
1308
- const cbuf = (l) => {
1309
- let bl = buf.length;
1310
- if (l > bl) {
1311
- const nbuf = new u8(Math.max(bl * 2, l));
1312
- nbuf.set(buf);
1313
- buf = nbuf;
1314
- }
1315
- };
1316
- let final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n;
1317
- const tbts = sl * 8;
1318
- do {
1319
- if (!lm) {
1320
- final = bits(dat, pos, 1);
1321
- const type = bits(dat, pos + 1, 3);
1322
- pos += 3;
1323
- if (!type) {
1324
- const s = shft(pos) + 4, l = dat[s - 4] | dat[s - 3] << 8, t = s + l;
1325
- if (t > sl) {
1326
- if (noSt) err(0);
1327
- break;
1328
- }
1329
- if (noBuf) cbuf(bt + l);
1330
- buf.set(dat.subarray(s, t), bt);
1331
- st.b = bt += l, st.p = pos = t * 8, st.f = final;
1332
- continue;
1333
- } else if (type == 1) lm = flrm, dm = fdrm, lbt = 9, dbt = 5;
1334
- else if (type == 2) {
1335
- const hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;
1336
- const tl = hLit + bits(dat, pos + 5, 31) + 1;
1337
- pos += 14;
1338
- const ldt = new u8(tl);
1339
- const clt = new u8(19);
1340
- for (let i = 0; i < hcLen; ++i) {
1341
- clt[clim[i]] = bits(dat, pos + i * 3, 7);
1342
- }
1343
- pos += hcLen * 3;
1344
- const clb = max(clt), clbmsk = (1 << clb) - 1;
1345
- const clm = hMap(clt, clb, 1);
1346
- for (let i = 0; i < tl; ) {
1347
- const r = clm[bits(dat, pos, clbmsk)];
1348
- pos += r & 15;
1349
- const s = r >>> 4;
1350
- if (s < 16) {
1351
- ldt[i++] = s;
1352
- } else {
1353
- let c = 0, n = 0;
1354
- if (s == 16) n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1];
1355
- else if (s == 17) n = 3 + bits(dat, pos, 7), pos += 3;
1356
- else if (s == 18) n = 11 + bits(dat, pos, 127), pos += 7;
1357
- while (n--) ldt[i++] = c;
1358
- }
1359
- }
1360
- const lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
1361
- lbt = max(lt);
1362
- dbt = max(dt);
1363
- lm = hMap(lt, lbt, 1);
1364
- dm = hMap(dt, dbt, 1);
1365
- } else err(1);
1366
- if (pos > tbts) {
1367
- if (noSt) err(0);
1368
- break;
1369
- }
1370
- }
1371
- if (noBuf) cbuf(bt + 131072);
1372
- const lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;
1373
- let lpos = pos;
1374
- for (; ; lpos = pos) {
1375
- const c = lm[bits16(dat, pos) & lms], sym = c >>> 4;
1376
- pos += c & 15;
1377
- if (pos > tbts) {
1378
- if (noSt) err(0);
1379
- break;
1380
- }
1381
- if (!c) err(2);
1382
- if (sym < 256) buf[bt++] = sym;
1383
- else if (sym == 256) {
1384
- lpos = pos, lm = void 0;
1385
- break;
1386
- } else {
1387
- let add = sym - 254;
1388
- if (sym > 264) {
1389
- const i = sym - 257, b = fleb[i];
1390
- add = bits(dat, pos, (1 << b) - 1) + fl[i];
1391
- pos += b;
1392
- }
1393
- const d = dm[bits16(dat, pos) & dms], dsym = d >>> 4;
1394
- if (!d) err(3);
1395
- pos += d & 15;
1396
- let dt = fd[dsym];
1397
- if (dsym > 3) {
1398
- const b = fdeb[dsym];
1399
- dt += bits16(dat, pos) & (1 << b) - 1, pos += b;
1400
- }
1401
- if (pos > tbts) {
1402
- if (noSt) err(0);
1403
- break;
1404
- }
1405
- if (noBuf) cbuf(bt + 131072);
1406
- const end = bt + add;
1407
- for (; bt < end; bt += 4) {
1408
- buf[bt] = buf[bt - dt];
1409
- buf[bt + 1] = buf[bt + 1 - dt];
1410
- buf[bt + 2] = buf[bt + 2 - dt];
1411
- buf[bt + 3] = buf[bt + 3 - dt];
1412
- }
1413
- bt = end;
1414
- }
998
+ /** Imports and initializes the codec without loading the opposite direction. */
999
+ async preload(modules = {}) {
1000
+ await super.preload(modules);
1001
+ this.modulePromise ||= this.loadModule().then(async (module2) => {
1002
+ var _a;
1003
+ await ((_a = module2.preload) == null ? void 0 : _a.call(module2));
1004
+ this.module = module2;
1005
+ });
1006
+ try {
1007
+ await this.modulePromise;
1008
+ } catch (error) {
1009
+ this.modulePromise = null;
1010
+ throw error;
1415
1011
  }
1416
- st.l = lm, st.p = lpos, st.b = bt, st.f = final;
1417
- if (lm) final = 1, st.m = lbt, st.d = dm, st.n = dbt;
1418
- } while (!final);
1419
- return bt == buf.length ? buf : slc(buf, 0, bt);
1420
- };
1421
- gzs = (d) => {
1422
- if (d[0] != 31 || d[1] != 139 || d[2] != 8) err(6, "invalid gzip data");
1423
- const flg = d[3];
1424
- let st = 10;
1425
- if (flg & 4) st += d[10] | (d[11] << 8) + 2;
1426
- for (let zs = (flg >> 3 & 1) + (flg >> 4 & 1); zs > 0; zs -= !d[st++]) ;
1427
- return st + (flg & 2);
1428
- };
1429
- gzl = (d) => {
1430
- const l = d.length;
1431
- return (d[l - 4] | d[l - 3] << 8 | d[l - 2] << 16 | d[l - 1] << 24) >>> 0;
1432
- };
1433
- zlv = (d) => {
1434
- if ((d[0] & 15) != 8 || d[0] >>> 4 > 7 || (d[0] << 8 | d[1]) % 31) err(6, "invalid zlib data");
1435
- if (d[1] & 32) err(6, "invalid zlib data: preset dictionaries not supported");
1436
- };
1437
- Inflate = class {
1438
- /**
1439
- * Creates an inflation stream
1440
- * @param cb The callback to call whenever data is inflated
1441
- */
1442
- constructor(cb) {
1443
- this.ondata = cb;
1444
- }
1445
- /** Persistent bit-reader and Huffman decoding state. */
1446
- s = {};
1447
- /** Compression options or retained output window for this stream. */
1448
- o;
1449
- /** Compressed bytes pending decoding. */
1450
- p = new u8(0);
1451
- /** Whether the stream has received its final chunk. */
1452
- d;
1453
- /**
1454
- * The handler to call whenever data is available
1455
- */
1456
- ondata;
1457
- /** Appends pending input after checking stream lifecycle. */
1458
- e(c) {
1459
- if (!this.ondata) err(5);
1460
- if (this.d) err(4);
1461
- const l = this.p.length;
1462
- const n = new u8(l + c.length);
1463
- n.set(this.p), n.set(c, l), this.p = n;
1464
- }
1465
- /** Decodes pending input and retains the sliding window. */
1466
- c(final) {
1467
- this.d = this.s.i = final || false;
1468
- const bts = this.s.b;
1469
- const dt = inflt(this.p, this.o, this.s);
1470
- this.ondata(slc(dt, bts, this.s.b), this.d);
1471
- this.o = slc(dt, this.s.b - 32768), this.s.b = this.o.length;
1472
- this.p = slc(this.p, this.s.p / 8 | 0), this.s.p &= 7;
1473
- }
1474
- /**
1475
- * Pushes a chunk to be inflated
1476
- * @param chunk The chunk to push
1477
- * @param final Whether this is the final chunk
1478
- */
1479
- push(chunk, final) {
1480
- this.e(chunk), this.c(final);
1481
- }
1482
- };
1483
- Gunzip = class extends Inflate {
1484
- /** Whether the stream header still needs to be emitted or consumed. */
1485
- v = 1;
1486
- /**
1487
- * Creates a GUNZIP stream
1488
- * @param cb The callback to call whenever data is inflated
1489
- */
1490
- constructor(cb) {
1491
- super(cb);
1492
1012
  }
1493
- /**
1494
- * Pushes a chunk to be GUNZIPped
1495
- * @param chunk The chunk to push
1496
- * @param final Whether this is the last chunk
1497
- */
1498
- push(chunk, final) {
1499
- Inflate.prototype.e.call(this, chunk);
1500
- if (this.v) {
1501
- const s = this.p.length > 3 ? gzs(this.p) : 4;
1502
- if (s >= this.p.length && !final) return;
1503
- this.p = this.p.subarray(s), this.v = 0;
1504
- }
1505
- if (final) {
1506
- if (this.p.length < 8) err(6, "invalid gzip data");
1507
- this.p = this.p.subarray(0, -8);
1508
- }
1509
- Inflate.prototype.c.call(this, final);
1013
+ /** Runs synchronously after preload has initialized the WASM codec. */
1014
+ decompressSync(input, size) {
1015
+ var _a;
1016
+ if (!((_a = this.module) == null ? void 0 : _a.decompressSync))
1017
+ throw new Error(`${this.name}: call preload() before decompressSync()`);
1018
+ return copyDecompressedOutput(
1019
+ this.module.decompressSync(new Uint8Array(input), getDecompressOptions(this.options, size)),
1020
+ this.options
1021
+ );
1510
1022
  }
1511
- };
1512
- Unzlib = class extends Inflate {
1513
- /** Whether the stream header still needs to be emitted or consumed. */
1514
- v = 1;
1515
- /**
1516
- * Creates a Zlib decompression stream
1517
- * @param cb The callback to call whenever data is inflated
1518
- */
1519
- constructor(cb) {
1520
- super(cb);
1023
+ /** Decompresses one buffer with the selected compress-utils decoder. */
1024
+ async decompress(input, size) {
1025
+ const decodeOptions = getDecompressOptions(this.options, size);
1026
+ await this.preload();
1027
+ const module2 = this.module;
1028
+ const output = await module2.decompress(new Uint8Array(input), decodeOptions);
1029
+ return copyDecompressedOutput(output, this.options);
1521
1030
  }
1522
- /**
1523
- * Pushes a chunk to be unzlibbed
1524
- * @param chunk The chunk to push
1525
- * @param final Whether this is the last chunk
1526
- */
1527
- push(chunk, final) {
1528
- Inflate.prototype.e.call(this, chunk);
1529
- if (this.v) {
1530
- if (this.p.length < 2 && !final) return;
1531
- this.p = this.p.subarray(2), this.v = 0;
1532
- }
1533
- if (final) {
1534
- if (this.p.length < 4) err(6, "invalid zlib data");
1535
- this.p = this.p.subarray(0, -4);
1031
+ /** Incrementally decompresses input batches with compress-utils. */
1032
+ async *decompressBatches(inputBatches) {
1033
+ await this.preload();
1034
+ const module2 = this.module;
1035
+ if (!module2.createDecompressStream) {
1036
+ yield await this.decompress(await this.concatenate(inputBatches));
1037
+ return;
1536
1038
  }
1537
- Inflate.prototype.c.call(this, final);
1039
+ const maximum = getMaximumOutputByteLength(this.options);
1040
+ const stream = await module2.createDecompressStream();
1041
+ yield* transformBatches(stream, inputBatches, maximum);
1538
1042
  }
1539
1043
  };
1540
1044
  }
1541
1045
  });
1542
1046
 
1543
- // ../compression/src/lib/fflate-stream.ts
1544
- async function* transformFflateBatches(processor, inputBatches) {
1545
- const chunks = [];
1546
- processor.ondata = (data) => {
1547
- chunks.push(data.slice().buffer);
1548
- };
1549
- for await (const batch of inputBatches) {
1550
- processor.push(new Uint8Array(batch), false);
1551
- yield* chunks.splice(0);
1552
- }
1553
- processor.push(new Uint8Array(0), true);
1554
- yield* chunks;
1555
- }
1556
- var init_fflate_stream = __esm({
1557
- "../compression/src/lib/fflate-stream.ts"() {
1558
- "use strict";
1559
- }
1560
- });
1561
-
1562
- // ../compression/src/gzip-decompressor-fflate.ts
1563
- var GZipFflateDecompressor;
1564
- var init_gzip_decompressor_fflate = __esm({
1565
- "../compression/src/gzip-decompressor-fflate.ts"() {
1047
+ // ../compression/src/gzip-decompressor-compress-utils.ts
1048
+ var GZipCompressUtilsDecompressor;
1049
+ var init_gzip_decompressor_compress_utils = __esm({
1050
+ "../compression/src/gzip-decompressor-compress-utils.ts"() {
1566
1051
  "use strict";
1567
- init_fflate();
1568
- init_compression();
1569
- init_fflate_stream();
1570
- GZipFflateDecompressor = class extends Decompressor {
1571
- name = "gzip";
1572
- extensions = ["gz", "gzip"];
1573
- contentEncodings = ["gzip", "x-gzip"];
1574
- isSupported = true;
1052
+ init_compress_utils_compression();
1053
+ GZipCompressUtilsDecompressor = class extends CompressUtilsDecompressor {
1575
1054
  constructor(options = {}) {
1576
- super(options);
1577
- }
1578
- /** Decompresses one GZIP payload synchronously. */
1579
- decompressSync(input) {
1580
- return gunzipSync(new Uint8Array(input)).slice().buffer;
1581
- }
1582
- /** Decompresses GZIP batches incrementally. */
1583
- async *decompressBatches(inputBatches) {
1584
- yield* transformFflateBatches(new Gunzip(), inputBatches);
1055
+ super(
1056
+ { name: "gzip", extensions: ["gz", "gzip"], contentEncodings: ["gzip", "x-gzip"] },
1057
+ () => import("compress-utils/gzip/decompress"),
1058
+ options
1059
+ );
1585
1060
  }
1586
1061
  };
1587
1062
  }
@@ -1596,23 +1071,18 @@ var GZipDecompressor;
1596
1071
  var init_gzip_decompressor = __esm({
1597
1072
  "../compression/src/gzip-decompressor.ts"() {
1598
1073
  "use strict";
1599
- init_gzip_decompressor_fflate();
1074
+ init_gzip_decompressor_compress_utils();
1600
1075
  init_decompression_stream();
1601
- GZipDecompressor = class extends GZipFflateDecompressor {
1602
- options;
1603
- constructor(options = {}) {
1604
- super(options);
1605
- this.options = options;
1606
- }
1607
- /** Decompresses with the built-in stream when available, then falls back to fflate. */
1608
- async decompress(input) {
1076
+ GZipDecompressor = class extends GZipCompressUtilsDecompressor {
1077
+ /** Decompresses with native streams when available, otherwise lazily initializes WASM. */
1078
+ async decompress(input, size) {
1609
1079
  if (this.options.useNative !== false) {
1610
1080
  const output = await decompressWithNativeDecompressionStream(input, "gzip");
1611
1081
  if (output) return output;
1612
1082
  }
1613
- return this.decompressSync(input);
1083
+ return super.decompress(input, size);
1614
1084
  }
1615
- /** Decompresses batches with a built-in or fflate stream. */
1085
+ /** Streams native batches when available, otherwise uses the WASM stream. */
1616
1086
  async *decompressBatches(inputBatches) {
1617
1087
  if (this.options.useNative !== false) {
1618
1088
  const output = decompressBatchesWithNativeDecompressionStream(inputBatches, "gzip");
@@ -1627,126 +1097,19 @@ var init_gzip_decompressor = __esm({
1627
1097
  }
1628
1098
  });
1629
1099
 
1630
- // ../compression/src/zstd-decompressor-fzstd.ts
1631
- var import_fzstd, ZstdFzstdDecompressor;
1632
- var init_zstd_decompressor_fzstd = __esm({
1633
- "../compression/src/zstd-decompressor-fzstd.ts"() {
1634
- "use strict";
1635
- init_compression();
1636
- import_fzstd = require("fzstd");
1637
- ZstdFzstdDecompressor = class extends Decompressor {
1638
- name = "zstd";
1639
- extensions = ["zst"];
1640
- contentEncodings = ["zstd"];
1641
- isSupported = true;
1642
- constructor(options = {}) {
1643
- super(options);
1644
- }
1645
- /** Decompresses one Zstandard frame synchronously. */
1646
- decompressSync(input) {
1647
- return (0, import_fzstd.decompress)(new Uint8Array(input)).slice().buffer;
1648
- }
1649
- };
1650
- }
1651
- });
1652
-
1653
- // ../compression/src/zstd-fallback.ts
1654
- var zstd_fallback_exports = {};
1655
- __export(zstd_fallback_exports, {
1656
- decompressZstd: () => decompressZstd
1657
- });
1658
- function decompressZstd(input) {
1659
- return (0, import_fzstd2.decompress)(input);
1660
- }
1661
- var import_fzstd2;
1662
- var init_zstd_fallback = __esm({
1663
- "../compression/src/zstd-fallback.ts"() {
1664
- "use strict";
1665
- import_fzstd2 = require("fzstd");
1666
- }
1667
- });
1668
-
1669
- // ../compression/src/lib/zstd-compression.ts
1670
- var zstd_compression_exports = {};
1671
- __export(zstd_compression_exports, {
1672
- ZstdCompression: () => ZstdCompression
1673
- });
1674
- var CHUNK_SIZE, zstdPromise, zstd, ZstdCompression;
1675
- var init_zstd_compression = __esm({
1676
- "../compression/src/lib/zstd-compression.ts"() {
1100
+ // ../compression/src/zstd-decompressor-compress-utils.ts
1101
+ var ZstdCompressUtilsDecompressor;
1102
+ var init_zstd_decompressor_compress_utils = __esm({
1103
+ "../compression/src/zstd-decompressor-compress-utils.ts"() {
1677
1104
  "use strict";
1678
- init_compression();
1679
- init_src();
1680
- init_compression_stream();
1681
- init_decompression_stream();
1682
- CHUNK_SIZE = 1e6;
1683
- ZstdCompression = class extends Compression {
1684
- name = "zstd";
1685
- extensions = [];
1686
- contentEncodings = [];
1687
- isSupported = true;
1688
- options;
1689
- /**
1690
- * zstd-codec is an injectable dependency due to big size
1691
- * @param options
1692
- */
1105
+ init_compress_utils_compression();
1106
+ ZstdCompressUtilsDecompressor = class extends CompressUtilsDecompressor {
1693
1107
  constructor(options = {}) {
1694
- super(options);
1695
- this.options = options;
1696
- registerJSModules(options == null ? void 0 : options.modules);
1697
- }
1698
- async preload(modules = {}) {
1699
- registerJSModules(modules);
1700
- const ZstdCodec = getJSModuleOrNull("zstd-codec");
1701
- if (!zstdPromise && ZstdCodec) {
1702
- zstdPromise = new Promise((resolve) => ZstdCodec.run((zstd2) => resolve(zstd2)));
1703
- }
1704
- if (zstdPromise) {
1705
- zstd = await zstdPromise;
1706
- }
1707
- }
1708
- compressSync(input) {
1709
- getJSModule("zstd-codec", this.name);
1710
- const simpleZstd = new zstd.Simple();
1711
- const inputArray = new Uint8Array(input);
1712
- return simpleZstd.compress(inputArray).buffer;
1713
- }
1714
- async compress(input) {
1715
- var _a;
1716
- if (this.options.useNative !== false && ((_a = this.options.zstd) == null ? void 0 : _a.useNative) !== false) {
1717
- const nativeOutput = await compressWithNativeCompressionStream(input, "zstd");
1718
- if (nativeOutput) return nativeOutput;
1719
- }
1720
- await this.preload();
1721
- return this.compressSync(input);
1722
- }
1723
- decompressSync(input) {
1724
- getJSModule("zstd-codec", this.name);
1725
- const simpleZstd = new zstd.Simple();
1726
- const inputArray = new Uint8Array(input);
1727
- return simpleZstd.decompress(inputArray).buffer;
1728
- }
1729
- async decompress(input, size) {
1730
- var _a;
1731
- if (!getJSModuleOrNull("zstd-codec") && this.options.useNative !== false && ((_a = this.options.zstd) == null ? void 0 : _a.useNative) !== false) {
1732
- const nativeOutput = await decompressWithNativeDecompressionStream(input, "zstd");
1733
- if (nativeOutput) return nativeOutput;
1734
- }
1735
- await this.preload();
1736
- const inputArray = new Uint8Array(input);
1737
- if (!zstd) {
1738
- const { decompressZstd: decompressZstd2 } = await Promise.resolve().then(() => (init_zstd_fallback(), zstd_fallback_exports));
1739
- return ensureArrayBuffer(decompressZstd2(inputArray));
1740
- }
1741
- const simpleZstd = new zstd.Streaming();
1742
- const chunks = [];
1743
- for (let i = 0; i <= inputArray.length; i += CHUNK_SIZE) {
1744
- const chunkView = inputArray.subarray(i, i + CHUNK_SIZE);
1745
- const chunkArrayBuffer = ensureArrayBuffer(chunkView);
1746
- chunks.push(new Uint8Array(chunkArrayBuffer));
1747
- }
1748
- const decompressResult = await simpleZstd.decompressChunks(chunks);
1749
- return decompressResult.buffer;
1108
+ super(
1109
+ { name: "zstd", extensions: ["zst"], contentEncodings: ["zstd"] },
1110
+ () => import("compress-utils/zstd/decompress"),
1111
+ options
1112
+ );
1750
1113
  }
1751
1114
  };
1752
1115
  }
@@ -1761,48 +1124,18 @@ var ZstdDecompressor;
1761
1124
  var init_zstd_decompressor = __esm({
1762
1125
  "../compression/src/zstd-decompressor.ts"() {
1763
1126
  "use strict";
1764
- init_zstd_decompressor_fzstd();
1127
+ init_zstd_decompressor_compress_utils();
1765
1128
  init_decompression_stream();
1766
- init_src();
1767
- ZstdDecompressor = class extends ZstdFzstdDecompressor {
1768
- options;
1769
- compatibility = null;
1770
- constructor(options = {}) {
1771
- super(options);
1772
- this.options = options;
1773
- registerJSModules(options.modules);
1774
- }
1775
- /** Preloads an injected zstd-codec implementation when supplied. */
1776
- async preload(modules = {}) {
1777
- registerJSModules(modules);
1778
- if (getJSModuleOrNull("zstd-codec")) {
1779
- const { ZstdCompression: ZstdCompression2 } = await Promise.resolve().then(() => (init_zstd_compression(), zstd_compression_exports));
1780
- this.compatibility ||= new ZstdCompression2(this.options);
1781
- await this.compatibility.preload(modules);
1782
- }
1783
- }
1784
- /** Decompresses with the built-in stream when available, then falls back to fzstd. */
1785
- async decompress(input) {
1129
+ ZstdDecompressor = class extends ZstdCompressUtilsDecompressor {
1130
+ /** Decompresses with native streams when available, otherwise lazily initializes WASM. */
1131
+ async decompress(input, size) {
1786
1132
  if (this.options.useNative !== false) {
1787
1133
  const output = await decompressWithNativeDecompressionStream(input, "zstd");
1788
1134
  if (output) return output;
1789
1135
  }
1790
- if (getJSModuleOrNull("zstd-codec")) {
1791
- await this.preload(this.options.modules);
1792
- }
1793
- return this.decompressSync(input);
1136
+ return super.decompress(input, size);
1794
1137
  }
1795
- /** Decompresses with a preloaded zstd-codec implementation or compact fzstd. */
1796
- decompressSync(input) {
1797
- if (this.compatibility) {
1798
- return this.compatibility.decompressSync(input);
1799
- }
1800
- if (getJSModuleOrNull("zstd-codec")) {
1801
- throw new Error("zstd: call preload() before synchronous decompression with zstd-codec");
1802
- }
1803
- return super.decompressSync(input);
1804
- }
1805
- /** Decompresses batches with a built-in stream or compact fzstd fallback. */
1138
+ /** Streams native batches when available, otherwise uses the WASM stream. */
1806
1139
  async *decompressBatches(inputBatches) {
1807
1140
  if (this.options.useNative !== false) {
1808
1141
  const output = decompressBatchesWithNativeDecompressionStream(inputBatches, "zstd");
@@ -1811,10 +1144,6 @@ var init_zstd_decompressor = __esm({
1811
1144
  return;
1812
1145
  }
1813
1146
  }
1814
- if (getJSModuleOrNull("zstd-codec")) {
1815
- yield this.decompress(await this.concatenate(inputBatches));
1816
- return;
1817
- }
1818
1147
  yield* super.decompressBatches(inputBatches);
1819
1148
  }
1820
1149
  };
@@ -1827,7 +1156,6 @@ var init_default_codecs = __esm({
1827
1156
  "../compression/src/default-codecs.ts"() {
1828
1157
  "use strict";
1829
1158
  init_lazy_compression();
1830
- init_src();
1831
1159
  GZIP = { name: "gzip", extensions: ["gz"], contentEncodings: ["gzip"] };
1832
1160
  ZSTD = { name: "zstd", extensions: ["zst"], contentEncodings: ["zstd"] };
1833
1161
  GZipDecompressor2 = class extends LazyDecompressor {
@@ -1846,11 +1174,7 @@ var init_default_codecs = __esm({
1846
1174
  ZSTD,
1847
1175
  async () => (await Promise.resolve().then(() => (init_zstd_decompressor(), zstd_decompressor_exports))).ZstdDecompressor,
1848
1176
  options,
1849
- "zstd",
1850
- (preloadOptions) => {
1851
- var _a;
1852
- return !((_a = preloadOptions.modules) == null ? void 0 : _a["zstd-codec"]) && !getJSModuleOrNull("zstd-codec");
1853
- }
1177
+ "zstd"
1854
1178
  );
1855
1179
  }
1856
1180
  };
@@ -1858,7 +1182,7 @@ var init_default_codecs = __esm({
1858
1182
  });
1859
1183
 
1860
1184
  // ../compression/src/index.ts
1861
- var init_src2 = __esm({
1185
+ var init_src = __esm({
1862
1186
  "../compression/src/index.ts"() {
1863
1187
  "use strict";
1864
1188
  init_default_codecs();
@@ -2396,7 +1720,7 @@ var SPZ_HEADER_BYTE_LENGTH, SPZ_MAGIC, SPZ_VERSION, SPZ_EXTENSION_FLAG, SPZ_COLO
2396
1720
  var init_parse_spz = __esm({
2397
1721
  "dist/lib/parse-spz.js"() {
2398
1722
  "use strict";
2399
- init_src2();
1723
+ init_src();
2400
1724
  init_splats_arrow_table();
2401
1725
  init_splat_utils();
2402
1726
  SPZ_HEADER_BYTE_LENGTH = 32;
@@ -2499,7 +1823,7 @@ var init_splat_loader_types = __esm({
2499
1823
  "dist/splat-loader-types.js"() {
2500
1824
  "use strict";
2501
1825
  init_splats_format();
2502
- VERSION2 = true ? "5.0.0-alpha.11" : "latest";
1826
+ VERSION2 = true ? "5.0.0-alpha.13" : "latest";
2503
1827
  SPLATLoader = {
2504
1828
  dataType: null,
2505
1829
  batchType: null,
@@ -2824,7 +2148,7 @@ var init_ksplat_loader_types = __esm({
2824
2148
  "dist/ksplat-loader-types.js"() {
2825
2149
  "use strict";
2826
2150
  init_splats_format();
2827
- VERSION3 = true ? "5.0.0-alpha.11" : "latest";
2151
+ VERSION3 = true ? "5.0.0-alpha.13" : "latest";
2828
2152
  KSPLATLoader = {
2829
2153
  dataType: null,
2830
2154
  batchType: null,
@@ -2869,7 +2193,7 @@ var init_spz_loader_types = __esm({
2869
2193
  "dist/spz-loader-types.js"() {
2870
2194
  "use strict";
2871
2195
  init_splats_format();
2872
- VERSION4 = true ? "5.0.0-alpha.11" : "latest";
2196
+ VERSION4 = true ? "5.0.0-alpha.13" : "latest";
2873
2197
  SPZLoader = {
2874
2198
  dataType: null,
2875
2199
  batchType: null,
@@ -3043,34 +2367,19 @@ var init_parse_rad = __esm({
3043
2367
  }
3044
2368
  });
3045
2369
 
3046
- // ../compression/src/deflate-decompressor-fflate.ts
3047
- var DeflateFflateDecompressor;
3048
- var init_deflate_decompressor_fflate = __esm({
3049
- "../compression/src/deflate-decompressor-fflate.ts"() {
2370
+ // ../compression/src/deflate-decompressor-compress-utils.ts
2371
+ var DeflateCompressUtilsDecompressor;
2372
+ var init_deflate_decompressor_compress_utils = __esm({
2373
+ "../compression/src/deflate-decompressor-compress-utils.ts"() {
3050
2374
  "use strict";
3051
- init_fflate();
3052
- init_compression();
3053
- init_fflate_stream();
3054
- DeflateFflateDecompressor = class extends Decompressor {
3055
- name = "deflate";
3056
- extensions = [];
3057
- contentEncodings = ["deflate"];
3058
- isSupported = true;
3059
- options;
2375
+ init_compress_utils_compression();
2376
+ DeflateCompressUtilsDecompressor = class extends CompressUtilsDecompressor {
3060
2377
  constructor(options = {}) {
3061
- super(options);
3062
- this.options = options;
3063
- }
3064
- /** Decompresses one zlib-wrapped DEFLATE payload synchronously. */
3065
- decompressSync(input) {
3066
- const bytes = new Uint8Array(input);
3067
- const output = this.options.raw ? inflateSync(bytes) : unzlibSync(bytes);
3068
- return output.slice().buffer;
3069
- }
3070
- /** Decompresses DEFLATE batches incrementally. */
3071
- async *decompressBatches(inputBatches) {
3072
- const processor = this.options.raw ? new Inflate() : new Unzlib();
3073
- yield* transformFflateBatches(processor, inputBatches);
2378
+ super(
2379
+ { name: "deflate", contentEncodings: ["deflate"] },
2380
+ () => options.raw ? import("compress-utils/deflate/decompress") : import("compress-utils/zlib/decompress"),
2381
+ options
2382
+ );
3074
2383
  }
3075
2384
  };
3076
2385
  }
@@ -3081,26 +2390,27 @@ var DeflateDecompressor2;
3081
2390
  var init_deflate_decompressor = __esm({
3082
2391
  "../compression/src/deflate-decompressor.ts"() {
3083
2392
  "use strict";
3084
- init_deflate_decompressor_fflate();
2393
+ init_deflate_decompressor_compress_utils();
3085
2394
  init_decompression_stream();
3086
- DeflateDecompressor2 = class extends DeflateFflateDecompressor {
3087
- constructor(options = {}) {
3088
- super(options);
3089
- }
3090
- /** Decompresses with the built-in stream when available, then falls back to fflate. */
3091
- async decompress(input) {
2395
+ DeflateDecompressor2 = class extends DeflateCompressUtilsDecompressor {
2396
+ /** Decompresses with native streams when available, otherwise lazily initializes WASM. */
2397
+ async decompress(input, size) {
3092
2398
  if (this.options.useNative !== false) {
3093
- const format = this.options.raw ? "deflate-raw" : "deflate";
3094
- const output = await decompressWithNativeDecompressionStream(input, format);
2399
+ const output = await decompressWithNativeDecompressionStream(
2400
+ input,
2401
+ this.options.raw ? "deflate-raw" : "deflate"
2402
+ );
3095
2403
  if (output) return output;
3096
2404
  }
3097
- return this.decompressSync(input);
2405
+ return super.decompress(input, size);
3098
2406
  }
3099
- /** Decompresses batches with a built-in or fflate stream. */
2407
+ /** Streams native batches when available, otherwise uses the WASM stream. */
3100
2408
  async *decompressBatches(inputBatches) {
3101
2409
  if (this.options.useNative !== false) {
3102
- const format = this.options.raw ? "deflate-raw" : "deflate";
3103
- const output = decompressBatchesWithNativeDecompressionStream(inputBatches, format);
2410
+ const output = decompressBatchesWithNativeDecompressionStream(
2411
+ inputBatches,
2412
+ this.options.raw ? "deflate-raw" : "deflate"
2413
+ );
3104
2414
  if (output) {
3105
2415
  yield* output;
3106
2416
  return;
@@ -3113,6 +2423,9 @@ var init_deflate_decompressor = __esm({
3113
2423
  });
3114
2424
 
3115
2425
  // dist/lib/parse-rad-chunk.js
2426
+ async function preloadRADCompression() {
2427
+ await Promise.all([RAD_PROPERTY_DEFLATE.preload(), RAD_PROPERTY_RAW_DEFLATE.preload()]);
2428
+ }
3116
2429
  function parseRADChunk(data, options) {
3117
2430
  return makeGaussianSplatsArrowTable(parseRADChunkToGaussianSplats(data, options));
3118
2431
  }
@@ -3320,7 +2633,7 @@ function getRADPropertyBytes(bytes, metadata, property) {
3320
2633
  return decompressRADProperty(propertyBytes, property.property);
3321
2634
  }
3322
2635
  function decompressRADProperty(bytes, propertyName) {
3323
- const arrayBuffer = copyToArrayBuffer3(bytes);
2636
+ const arrayBuffer = copyToArrayBuffer2(bytes);
3324
2637
  try {
3325
2638
  return new Uint8Array(RAD_PROPERTY_DEFLATE.decompressSync(arrayBuffer));
3326
2639
  } catch {
@@ -3378,9 +2691,9 @@ function decodeLeBytesFloat16(bytes, dimensions, count) {
3378
2691
  }
3379
2692
  return values;
3380
2693
  }
3381
- function decodeR8(bytes, dimensions, count, min, max2) {
2694
+ function decodeR8(bytes, dimensions, count, min, max) {
3382
2695
  const values = new Float32Array(count * dimensions);
3383
- const range = max2 - min;
2696
+ const range = max - min;
3384
2697
  for (let rowIndex = 0; rowIndex < count; rowIndex++) {
3385
2698
  for (let dimension = 0; dimension < dimensions; dimension++) {
3386
2699
  values[rowIndex * dimensions + dimension] = bytes[dimension * count + rowIndex] / 255 * range + min;
@@ -3388,9 +2701,9 @@ function decodeR8(bytes, dimensions, count, min, max2) {
3388
2701
  }
3389
2702
  return values;
3390
2703
  }
3391
- function decodeR8Delta(bytes, dimensions, count, min, max2) {
2704
+ function decodeR8Delta(bytes, dimensions, count, min, max) {
3392
2705
  const values = new Float32Array(count * dimensions);
3393
- const range = max2 - min;
2706
+ const range = max - min;
3394
2707
  const last = new Uint8Array(dimensions);
3395
2708
  for (let rowIndex = 0; rowIndex < count; rowIndex++) {
3396
2709
  for (let dimension = 0; dimension < dimensions; dimension++) {
@@ -3402,17 +2715,17 @@ function decodeR8Delta(bytes, dimensions, count, min, max2) {
3402
2715
  }
3403
2716
  return values;
3404
2717
  }
3405
- function decodeS8(bytes, dimensions, count, max2) {
2718
+ function decodeS8(bytes, dimensions, count, max) {
3406
2719
  const values = new Float32Array(count * dimensions);
3407
2720
  for (let rowIndex = 0; rowIndex < count; rowIndex++) {
3408
2721
  for (let dimension = 0; dimension < dimensions; dimension++) {
3409
2722
  const byte = bytes[dimension * count + rowIndex];
3410
- values[rowIndex * dimensions + dimension] = (byte << 24 >> 24) / 127 * max2;
2723
+ values[rowIndex * dimensions + dimension] = (byte << 24 >> 24) / 127 * max;
3411
2724
  }
3412
2725
  }
3413
2726
  return values;
3414
2727
  }
3415
- function decodeS8Delta(bytes, dimensions, count, max2) {
2728
+ function decodeS8Delta(bytes, dimensions, count, max) {
3416
2729
  const values = new Float32Array(count * dimensions);
3417
2730
  const last = new Uint8Array(dimensions);
3418
2731
  for (let rowIndex = 0; rowIndex < count; rowIndex++) {
@@ -3420,16 +2733,16 @@ function decodeS8Delta(bytes, dimensions, count, max2) {
3420
2733
  const byteOffset = dimension * count + rowIndex;
3421
2734
  const value = last[dimension] + bytes[byteOffset] & 255;
3422
2735
  last[dimension] = value;
3423
- values[rowIndex * dimensions + dimension] = (value << 24 >> 24) / 127 * max2;
2736
+ values[rowIndex * dimensions + dimension] = (value << 24 >> 24) / 127 * max;
3424
2737
  }
3425
2738
  }
3426
2739
  return values;
3427
2740
  }
3428
- function decodeScaleR8(bytes, dimensions, count, min, max2) {
2741
+ function decodeScaleR8(bytes, dimensions, count, min, max) {
3429
2742
  const values = new Float32Array(count * dimensions);
3430
2743
  for (let rowIndex = 0; rowIndex < count; rowIndex++) {
3431
2744
  for (let dimension = 0; dimension < dimensions; dimension++) {
3432
- values[rowIndex * dimensions + dimension] = decodeScale8(bytes[dimension * count + rowIndex], min, max2);
2745
+ values[rowIndex * dimensions + dimension] = decodeScale8(bytes[dimension * count + rowIndex], min, max);
3433
2746
  }
3434
2747
  }
3435
2748
  return values;
@@ -3467,11 +2780,11 @@ function makeIdentityRotations(count) {
3467
2780
  }
3468
2781
  return rotations;
3469
2782
  }
3470
- function decodeScale8(scale, min, max2) {
2783
+ function decodeScale8(scale, min, max) {
3471
2784
  if (scale === 0) {
3472
2785
  return 0;
3473
2786
  }
3474
- const logScaleStep = (max2 - min) / 254;
2787
+ const logScaleStep = (max - min) / 254;
3475
2788
  return Math.exp(min + (scale - 1) * logScaleStep);
3476
2789
  }
3477
2790
  function decodeQuatOct888(u, v, r) {
@@ -3562,7 +2875,7 @@ function getSplatEncodingMaximum(splatEncoding, propertyName) {
3562
2875
  function normalizeColorByte2(value) {
3563
2876
  return Math.round(Math.min(Math.max(value, 0), 1) * 255);
3564
2877
  }
3565
- function copyToArrayBuffer3(bytes) {
2878
+ function copyToArrayBuffer2(bytes) {
3566
2879
  const copy = new Uint8Array(bytes.byteLength);
3567
2880
  copy.set(bytes);
3568
2881
  return copy.buffer;
@@ -3591,6 +2904,7 @@ __export(rad_loader_exports, {
3591
2904
  parseRADChunkHeader: () => parseRADChunkHeader,
3592
2905
  parseRADChunkToGaussianSplats: () => parseRADChunkToGaussianSplats,
3593
2906
  parseRADHeader: () => parseRADHeader,
2907
+ preloadRADCompression: () => preloadRADCompression,
3594
2908
  tryParseRADHeader: () => tryParseRADHeader
3595
2909
  });
3596
2910
  var _RADLoaderPreload, RADLoaderMetadataWithoutPreload, RADLoaderWithParser;
@@ -3620,7 +2934,7 @@ var init_rad_loader_types = __esm({
3620
2934
  "dist/rad-loader-types.js"() {
3621
2935
  "use strict";
3622
2936
  init_splats_format();
3623
- VERSION5 = true ? "5.0.0-alpha.11" : "latest";
2937
+ VERSION5 = true ? "5.0.0-alpha.13" : "latest";
3624
2938
  RADLoader = {
3625
2939
  dataType: null,
3626
2940
  batchType: null,
@@ -3658,14 +2972,14 @@ init_spz_loader_types();
3658
2972
  init_rad_loader_types();
3659
2973
 
3660
2974
  // dist/rad-source-loader.js
3661
- init_src();
2975
+ init_loader_utils();
3662
2976
  init_splats_format();
3663
2977
  init_parse_rad();
3664
2978
  init_parse_rad_chunk();
3665
2979
  init_splats_arrow_table();
3666
2980
  var DEFAULT_RAD_HEADER_BYTE_LENGTHS = [64 * 1024, 256 * 1024, 1024 * 1024];
3667
2981
  var DEFAULT_RAD_MAX_CONCURRENT_CHUNK_REQUESTS = 4;
3668
- var VERSION6 = true ? "5.0.0-alpha.11" : "latest";
2982
+ var VERSION6 = true ? "5.0.0-alpha.13" : "latest";
3669
2983
  var RADSourceLoader = {
3670
2984
  dataType: null,
3671
2985
  batchType: null,
@@ -3761,11 +3075,13 @@ var RADSource = class extends DataSource {
3761
3075
  /** Fetches and decodes one RADC chunk into raw Gaussian splat arrays. */
3762
3076
  async getChunkSplats(chunkIndex, options = {}) {
3763
3077
  const metadata = await this.getMetadata();
3078
+ await preloadRADCompression();
3764
3079
  return parseRADChunkToGaussianSplats(await this.getChunk(chunkIndex, options), this._getChunkDecodeOptions(metadata, options));
3765
3080
  }
3766
3081
  /** Fetches and decodes one RADC chunk into a Mesh Arrow table. */
3767
3082
  async getChunkTable(chunkIndex, options = {}) {
3768
3083
  const metadata = await this.getMetadata();
3084
+ await preloadRADCompression();
3769
3085
  return parseRADChunk(await this.getChunk(chunkIndex, options), this._getChunkDecodeOptions(metadata, options));
3770
3086
  }
3771
3087
  /** Iterates decoded RADC chunks as Mesh Arrow tables. */