@loaders.gl/splats 5.0.0-alpha.2 → 5.0.0-alpha.4

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.
package/dist/index.cjs CHANGED
@@ -336,7 +336,7 @@ var init_splat_loader_types = __esm({
336
336
  "dist/splat-loader-types.js"() {
337
337
  "use strict";
338
338
  init_splats_format();
339
- VERSION = true ? "5.0.0-alpha.2" : "latest";
339
+ VERSION = true ? "5.0.0-alpha.4" : "latest";
340
340
  SPLATLoader = {
341
341
  dataType: null,
342
342
  batchType: null,
@@ -661,7 +661,7 @@ var init_ksplat_loader_types = __esm({
661
661
  "dist/ksplat-loader-types.js"() {
662
662
  "use strict";
663
663
  init_splats_format();
664
- VERSION2 = true ? "5.0.0-alpha.2" : "latest";
664
+ VERSION2 = true ? "5.0.0-alpha.4" : "latest";
665
665
  KSPLATLoader = {
666
666
  dataType: null,
667
667
  batchType: null,
@@ -677,129 +677,6 @@ var init_ksplat_loader_types = __esm({
677
677
  }
678
678
  });
679
679
 
680
- // ../compression/src/lib/decompression-stream.ts
681
- async function decompressWithNativeDecompressionStream(input, format) {
682
- const outputBatches = decompressBatchesWithNativeDecompressionStream([input], format);
683
- return outputBatches ? await concatenateNativeDecompressionBatches(outputBatches) : null;
684
- }
685
- function decompressBatchesWithNativeDecompressionStream(inputBatches, format) {
686
- const decompressionStream = createNativeDecompressionStream(format);
687
- return decompressionStream ? transformBatchesWithNativeDecompressionStream(inputBatches, decompressionStream) : null;
688
- }
689
- function createNativeDecompressionStream(format) {
690
- var _a, _b;
691
- if (typeof globalThis.DecompressionStream === "undefined") {
692
- return null;
693
- }
694
- if (((_b = (_a = globalThis.process) == null ? void 0 : _a.versions) == null ? void 0 : _b.node) && typeof globalThis.Buffer === "undefined") {
695
- return null;
696
- }
697
- try {
698
- const DecompressionStreamConstructor = globalThis.DecompressionStream;
699
- return new DecompressionStreamConstructor(format);
700
- } catch (error) {
701
- if (error instanceof TypeError || (error == null ? void 0 : error.name) === "TypeError") {
702
- return null;
703
- }
704
- throw error;
705
- }
706
- }
707
- async function* transformBatchesWithNativeDecompressionStream(inputBatches, decompressionStream) {
708
- const writer = decompressionStream.writable.getWriter();
709
- const reader = decompressionStream.readable.getReader();
710
- const writePromise = writeBatchesToNativeDecompressionStream(inputBatches, writer);
711
- writePromise.catch(() => {
712
- });
713
- let outputCompleted = false;
714
- try {
715
- while (true) {
716
- const { done, value } = await reader.read();
717
- if (done) {
718
- outputCompleted = true;
719
- break;
720
- }
721
- yield copyExactArrayBuffer(value);
722
- }
723
- await writePromise;
724
- } finally {
725
- if (!outputCompleted) {
726
- await reader.cancel().catch(() => {
727
- });
728
- await writer.abort().catch(() => {
729
- });
730
- await writePromise.catch(() => {
731
- });
732
- }
733
- reader.releaseLock();
734
- }
735
- }
736
- async function concatenateNativeDecompressionBatches(outputBatches) {
737
- const batches = [];
738
- let byteLength = 0;
739
- for await (const outputBatch of outputBatches) {
740
- const bytes = new Uint8Array(outputBatch);
741
- batches.push(bytes);
742
- byteLength += bytes.byteLength;
743
- }
744
- const output = new Uint8Array(byteLength);
745
- let byteOffset = 0;
746
- for (const batch of batches) {
747
- output.set(batch, byteOffset);
748
- byteOffset += batch.byteLength;
749
- }
750
- return output.buffer;
751
- }
752
- function copyExactArrayBuffer(value) {
753
- return new Uint8Array(value).buffer;
754
- }
755
- async function writeBatchesToNativeDecompressionStream(inputBatches, writer) {
756
- try {
757
- for await (const inputBatch of inputBatches) {
758
- await writer.write(new Uint8Array(inputBatch));
759
- }
760
- await writer.close();
761
- } catch (error) {
762
- await writer.abort(error).catch(() => {
763
- });
764
- throw error;
765
- }
766
- }
767
- var init_decompression_stream = __esm({
768
- "../compression/src/lib/decompression-stream.ts"() {
769
- "use strict";
770
- }
771
- });
772
-
773
- // ../compression/src/native-decompression.ts
774
- var init_native_decompression = __esm({
775
- "../compression/src/native-decompression.ts"() {
776
- "use strict";
777
- init_decompression_stream();
778
- }
779
- });
780
-
781
- // ../loader-utils/src/lib/env-utils/globals.ts
782
- var globals, self_, window_, global_, document_, isBrowser, matches, nodeVersion;
783
- var init_globals = __esm({
784
- "../loader-utils/src/lib/env-utils/globals.ts"() {
785
- "use strict";
786
- globals = {
787
- self: typeof self !== "undefined" && self,
788
- window: typeof window !== "undefined" && window,
789
- global: typeof global !== "undefined" && global,
790
- document: typeof document !== "undefined" && document
791
- };
792
- self_ = globals.self || globals.window || globals.global || {};
793
- window_ = globals.window || globals.self || globals.global || {};
794
- global_ = globals.global || globals.self || globals.window || {};
795
- document_ = globals.document || {};
796
- isBrowser = // @ts-ignore process does not exist on browser
797
- Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser);
798
- matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
799
- nodeVersion = matches && parseFloat(matches[1]) || 0;
800
- }
801
- });
802
-
803
680
  // ../loader-utils/src/lib/log-utils/log.ts
804
681
  function createLog() {
805
682
  const log2 = new import_log.Log({ id: "loaders.gl" });
@@ -940,6 +817,121 @@ var init_async_iteration = __esm({
940
817
  }
941
818
  });
942
819
 
820
+ // ../loader-utils/src/lib/request-utils/request-credentials.ts
821
+ function createAuthenticatedFetch(options) {
822
+ const baseFetch = options.fetch || ((url, requestOptions) => fetch(url, requestOptions));
823
+ if (!options.credentials.length) return baseFetch;
824
+ const existingMetadata = baseFetch[AUTHENTICATED_FETCH];
825
+ if (existingMetadata === options.credentials) return baseFetch;
826
+ const authenticatedFetch = async (url, requestOptions = {}) => {
827
+ var _a, _b, _c;
828
+ const resolvedURL = parseHTTPURL(url);
829
+ if (!resolvedURL) return baseFetch(url, requestOptions);
830
+ const authorization = await authorizeRequest(resolvedURL, requestOptions, options.credentials);
831
+ const response = await baseFetch(authorization.url, authorization.options);
832
+ const refreshableCredentials = authorization.credentials.filter(
833
+ ({ credential }) => typeof credential.token === "function" && credential.refreshStatusCodes.includes(response.status)
834
+ );
835
+ if (!refreshableCredentials.length || !isReplayableRequest(requestOptions)) return response;
836
+ if ((_a = requestOptions.signal) == null ? void 0 : _a.aborted) throw createAbortError();
837
+ const refreshedTokens = /* @__PURE__ */ new Map();
838
+ await Promise.all(
839
+ refreshableCredentials.map(async ({ credential }) => {
840
+ const token = await refreshCredential(credential, url, response);
841
+ if (token) refreshedTokens.set(credential, token);
842
+ })
843
+ );
844
+ if (!refreshedTokens.size) return response;
845
+ await ((_b = response.body) == null ? void 0 : _b.cancel().catch(() => {
846
+ }));
847
+ if ((_c = requestOptions.signal) == null ? void 0 : _c.aborted) throw createAbortError();
848
+ const replayAuthorization = await authorizeRequest(
849
+ resolvedURL,
850
+ requestOptions,
851
+ options.credentials,
852
+ refreshedTokens,
853
+ authorization.credentials
854
+ );
855
+ return baseFetch(replayAuthorization.url, replayAuthorization.options);
856
+ };
857
+ Object.defineProperty(authenticatedFetch, AUTHENTICATED_FETCH, {
858
+ value: options.credentials
859
+ });
860
+ return authenticatedFetch;
861
+ }
862
+ async function authorizeRequest(sourceURL, requestOptions, credentials, tokenOverrides = /* @__PURE__ */ new Map(), previousCredentials = []) {
863
+ const url = new URL(sourceURL);
864
+ const headers = new Headers(requestOptions.headers);
865
+ const resolvedCredentials = [];
866
+ const previousTokens = new Map(
867
+ previousCredentials.map(({ credential, token }) => [credential, token])
868
+ );
869
+ for (const credential of credentials) {
870
+ if (!credential.origins.includes(url.origin)) continue;
871
+ const overrideToken = tokenOverrides.get(credential);
872
+ const previousToken = previousTokens.get(credential);
873
+ const ownsQueryParameter = credential.type === "query-parameter" && previousToken !== void 0;
874
+ const ownsHeader = credential.type === "header" && previousToken !== void 0;
875
+ if (credential.type === "query-parameter" && url.searchParams.has(credential.name) && !ownsQueryParameter || credential.type === "header" && headers.has(credential.name) && !ownsHeader) {
876
+ continue;
877
+ }
878
+ const token = overrideToken ?? previousToken ?? await resolveToken(credential.token, { url: sourceURL.toString(), reason: "request" });
879
+ if (!token) continue;
880
+ if (credential.type === "query-parameter") {
881
+ url.searchParams.set(credential.name, token);
882
+ } else {
883
+ headers.set(credential.name, `${credential.prefix || ""}${token}`);
884
+ }
885
+ resolvedCredentials.push({ credential, token });
886
+ }
887
+ return {
888
+ url: url.toString(),
889
+ options: { ...requestOptions, headers },
890
+ credentials: resolvedCredentials
891
+ };
892
+ }
893
+ async function refreshCredential(credential, url, response) {
894
+ const existingPromise = refreshPromises.get(credential);
895
+ if (existingPromise) return existingPromise;
896
+ const tokenProvider = credential.token;
897
+ const promise = Promise.resolve(
898
+ tokenProvider({
899
+ url,
900
+ reason: "refresh",
901
+ response: { status: response.status, headers: response.headers }
902
+ })
903
+ ).finally(() => refreshPromises.delete(credential));
904
+ refreshPromises.set(credential, promise);
905
+ return promise;
906
+ }
907
+ async function resolveToken(token, context) {
908
+ return typeof token === "function" ? token(context) : token;
909
+ }
910
+ function parseHTTPURL(url) {
911
+ try {
912
+ const parsedURL = new URL(url);
913
+ return ["http:", "https:"].includes(parsedURL.protocol) ? parsedURL : null;
914
+ } catch {
915
+ return null;
916
+ }
917
+ }
918
+ function isReplayableRequest(options) {
919
+ const method = (options.method || "GET").toUpperCase();
920
+ if (!["GET", "HEAD", "OPTIONS", "PUT", "DELETE"].includes(method)) return false;
921
+ return !(options.body && typeof ReadableStream !== "undefined" && options.body instanceof ReadableStream);
922
+ }
923
+ function createAbortError() {
924
+ return new DOMException("The operation was aborted.", "AbortError");
925
+ }
926
+ var AUTHENTICATED_FETCH, refreshPromises;
927
+ var init_request_credentials = __esm({
928
+ "../loader-utils/src/lib/request-utils/request-credentials.ts"() {
929
+ "use strict";
930
+ AUTHENTICATED_FETCH = /* @__PURE__ */ Symbol("loaders.gl.authenticated-fetch");
931
+ refreshPromises = /* @__PURE__ */ new WeakMap();
932
+ }
933
+ });
934
+
943
935
  // ../loader-utils/src/lib/path-utils/file-aliases.ts
944
936
  function resolvePath(filename) {
945
937
  for (const alias in fileAliases) {
@@ -962,47 +954,7 @@ var init_file_aliases = __esm({
962
954
  }
963
955
  });
964
956
 
965
- // ../loader-utils/src/lib/node/buffer.browser.ts
966
- function toArrayBuffer(buffer) {
967
- return buffer;
968
- }
969
- var init_buffer_browser = __esm({
970
- "../loader-utils/src/lib/node/buffer.browser.ts"() {
971
- "use strict";
972
- }
973
- });
974
-
975
957
  // ../loader-utils/src/lib/binary-utils/memory-conversion-utils.ts
976
- function isBuffer(value) {
977
- return value && typeof value === "object" && value.isBuffer;
978
- }
979
- function toArrayBuffer2(data) {
980
- if (isBuffer(data)) {
981
- return toArrayBuffer(data);
982
- }
983
- if (data instanceof ArrayBuffer) {
984
- return data;
985
- }
986
- if (isSharedArrayBuffer(data)) {
987
- return copyToArrayBuffer2(data);
988
- }
989
- if (ArrayBuffer.isView(data)) {
990
- const buffer = data.buffer;
991
- if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
992
- return buffer;
993
- }
994
- return buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
995
- }
996
- if (typeof data === "string") {
997
- const text = data;
998
- const uint8Array = new TextEncoder().encode(text);
999
- return uint8Array.buffer;
1000
- }
1001
- if (data && typeof data === "object" && data._toArrayBuffer) {
1002
- return data._toArrayBuffer();
1003
- }
1004
- throw new Error("toArrayBuffer");
1005
- }
1006
958
  function ensureArrayBuffer(bufferSource) {
1007
959
  if (bufferSource instanceof ArrayBuffer) {
1008
960
  return bufferSource;
@@ -1026,34 +978,25 @@ var init_memory_conversion_utils = __esm({
1026
978
  "../loader-utils/src/lib/binary-utils/memory-conversion-utils.ts"() {
1027
979
  "use strict";
1028
980
  init_is_type();
1029
- init_buffer_browser();
1030
- }
1031
- });
1032
-
1033
- // ../loader-utils/src/lib/node/promisify.ts
1034
- function promisify1(fn) {
1035
- return (args) => new Promise(
1036
- (resolve, reject) => fn(args, (error, callbackArgs) => error ? reject(error) : resolve(callbackArgs))
1037
- );
1038
- }
1039
- var init_promisify = __esm({
1040
- "../loader-utils/src/lib/node/promisify.ts"() {
1041
- "use strict";
1042
981
  }
1043
982
  });
1044
983
 
1045
984
  // ../loader-utils/src/lib/sources/data-source.ts
1046
985
  function getFetchFunction(options) {
1047
- var _a;
1048
- const fetchFunction = (_a = options == null ? void 0 : options.core) == null ? void 0 : _a.fetch;
1049
- if (fetchFunction && typeof fetchFunction === "function") {
1050
- return (url, fetchOptions2) => fetchFunction(url, fetchOptions2);
1051
- }
1052
- const fetchOptions = options == null ? void 0 : options.fetch;
1053
- if (fetchOptions && typeof fetchOptions !== "function") {
1054
- return (url, requestOptions) => fetch(url, mergeFetchOptions(fetchOptions, requestOptions));
1055
- }
1056
- return (url, requestOptions) => fetch(url, requestOptions);
986
+ var _a, _b;
987
+ const fetchOption = (options == null ? void 0 : options.fetch) ?? ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a.fetch);
988
+ let fetchFunction;
989
+ if (typeof fetchOption === "function") {
990
+ fetchFunction = (url, fetchOptions) => fetchOption(url, fetchOptions);
991
+ } else if (fetchOption) {
992
+ fetchFunction = (url, requestOptions) => fetch(url, mergeFetchOptions(fetchOption, requestOptions));
993
+ } else {
994
+ fetchFunction = (url, requestOptions) => fetch(url, requestOptions);
995
+ }
996
+ return createAuthenticatedFetch({
997
+ fetch: fetchFunction,
998
+ credentials: ((_b = options == null ? void 0 : options.core) == null ? void 0 : _b.credentials) || []
999
+ });
1057
1000
  }
1058
1001
  function mergeFetchOptions(fetchOptions, requestOptions) {
1059
1002
  const mergedOptions = { ...fetchOptions, ...requestOptions };
@@ -1109,6 +1052,7 @@ var init_data_source = __esm({
1109
1052
  init_merge_options();
1110
1053
  init_file_aliases();
1111
1054
  init_log();
1055
+ init_request_credentials();
1112
1056
  UNAVAILABLE_CORE_API = {
1113
1057
  fetchFile: unavailableCoreApiMethod("fetchFile"),
1114
1058
  parse: unavailableCoreApiMethod("parse"),
@@ -1188,89 +1132,463 @@ var init_data_source = __esm({
1188
1132
  }
1189
1133
  return normalizedError;
1190
1134
  }
1191
- };
1135
+ };
1136
+ }
1137
+ });
1138
+
1139
+ // ../loader-utils/src/index.ts
1140
+ var init_src = __esm({
1141
+ "../loader-utils/src/index.ts"() {
1142
+ "use strict";
1143
+ init_js_module_utils();
1144
+ init_js_module_utils();
1145
+ init_async_iteration();
1146
+ init_memory_conversion_utils();
1147
+ init_data_source();
1148
+ }
1149
+ });
1150
+
1151
+ // ../compression/src/lib/compression.ts
1152
+ var CompressionTransform, Compressor, Decompressor, Compression;
1153
+ var init_compression = __esm({
1154
+ "../compression/src/lib/compression.ts"() {
1155
+ "use strict";
1156
+ init_src();
1157
+ CompressionTransform = class {
1158
+ /** Preloads any dynamic libraries. May enable sync functions */
1159
+ async preload(modules = {}) {
1160
+ registerJSModules(modules);
1161
+ return void 0;
1162
+ }
1163
+ // HELPERS
1164
+ concatenate(asyncIterator) {
1165
+ return concatenateArrayBuffersAsync(asyncIterator);
1166
+ }
1167
+ improveError(error) {
1168
+ if (!error.message.includes(this.name)) {
1169
+ error.message = `${this.name} ${error.message}`;
1170
+ }
1171
+ return error;
1172
+ }
1173
+ };
1174
+ Compressor = class extends CompressionTransform {
1175
+ constructor(options) {
1176
+ super();
1177
+ this.compressBatches = this.compressBatches.bind(this);
1178
+ }
1179
+ /** Asynchronously compresses data. */
1180
+ async compress(input) {
1181
+ await this.preload();
1182
+ return this.compressSync(input);
1183
+ }
1184
+ /** Synchronously compresses data. */
1185
+ compressSync(input) {
1186
+ throw new Error(`${this.name}: sync compression not supported`);
1187
+ }
1188
+ /** Compresses batches. */
1189
+ async *compressBatches(asyncIterator) {
1190
+ const input = await this.concatenate(asyncIterator);
1191
+ yield this.compress(input);
1192
+ }
1193
+ };
1194
+ Decompressor = class extends CompressionTransform {
1195
+ constructor(options) {
1196
+ super();
1197
+ this.decompressBatches = this.decompressBatches.bind(this);
1198
+ }
1199
+ /** Asynchronously decompresses data. */
1200
+ async decompress(input, size) {
1201
+ await this.preload();
1202
+ return this.decompressSync(input, size);
1203
+ }
1204
+ /** Synchronously decompresses data. */
1205
+ decompressSync(input, size) {
1206
+ throw new Error(`${this.name}: sync decompression not supported`);
1207
+ }
1208
+ /** Decompresses batches. */
1209
+ async *decompressBatches(asyncIterator) {
1210
+ const input = await this.concatenate(asyncIterator);
1211
+ yield this.decompress(input);
1212
+ }
1213
+ };
1214
+ Compression = class extends Compressor {
1215
+ constructor(options) {
1216
+ super(options);
1217
+ this.decompressBatches = this.decompressBatches.bind(this);
1218
+ }
1219
+ /** Asynchronously decompresses data. */
1220
+ async decompress(input, size) {
1221
+ await this.preload();
1222
+ return this.decompressSync(input, size);
1223
+ }
1224
+ /** Synchronously decompresses data. */
1225
+ decompressSync(input, size) {
1226
+ throw new Error(`${this.name}: sync decompression not supported`);
1227
+ }
1228
+ /** Decompresses batches. */
1229
+ async *decompressBatches(asyncIterator) {
1230
+ const input = await this.concatenate(asyncIterator);
1231
+ yield this.decompress(input);
1232
+ }
1233
+ };
1234
+ }
1235
+ });
1236
+
1237
+ // ../compression/src/lib/compression-stream.ts
1238
+ async function compressWithNativeCompressionStream(input, format) {
1239
+ const outputBatches = compressBatchesWithNativeCompressionStream([input], format);
1240
+ return outputBatches ? await concatenateBatches(outputBatches) : null;
1241
+ }
1242
+ function compressBatchesWithNativeCompressionStream(inputBatches, format) {
1243
+ const compressionStream = createNativeCompressionStream(format);
1244
+ return compressionStream ? transformBatches(inputBatches, compressionStream) : null;
1245
+ }
1246
+ function createNativeCompressionStream(format) {
1247
+ if (typeof globalThis.CompressionStream === "undefined") {
1248
+ return null;
1249
+ }
1250
+ try {
1251
+ const CompressionStreamConstructor = globalThis.CompressionStream;
1252
+ return new CompressionStreamConstructor(format);
1253
+ } catch (error) {
1254
+ if (error instanceof TypeError || (error == null ? void 0 : error.name) === "TypeError") {
1255
+ return null;
1256
+ }
1257
+ throw error;
1258
+ }
1259
+ }
1260
+ async function* transformBatches(inputBatches, compressionStream) {
1261
+ const writer = compressionStream.writable.getWriter();
1262
+ const reader = compressionStream.readable.getReader();
1263
+ const writePromise = writeBatches(inputBatches, writer);
1264
+ writePromise.catch(() => {
1265
+ });
1266
+ let outputCompleted = false;
1267
+ try {
1268
+ while (true) {
1269
+ const { done, value } = await reader.read();
1270
+ if (done) {
1271
+ outputCompleted = true;
1272
+ break;
1273
+ }
1274
+ yield new Uint8Array(value).buffer;
1275
+ }
1276
+ await writePromise;
1277
+ } finally {
1278
+ if (!outputCompleted) {
1279
+ await reader.cancel().catch(() => {
1280
+ });
1281
+ await writer.abort().catch(() => {
1282
+ });
1283
+ await writePromise.catch(() => {
1284
+ });
1285
+ }
1286
+ reader.releaseLock();
1287
+ }
1288
+ }
1289
+ async function writeBatches(inputBatches, writer) {
1290
+ try {
1291
+ for await (const inputBatch of inputBatches) {
1292
+ await writer.write(new Uint8Array(inputBatch));
1293
+ }
1294
+ await writer.close();
1295
+ } catch (error) {
1296
+ await writer.abort(error).catch(() => {
1297
+ });
1298
+ throw error;
1299
+ }
1300
+ }
1301
+ async function concatenateBatches(batches) {
1302
+ const output = [];
1303
+ let byteLength = 0;
1304
+ for await (const batch of batches) {
1305
+ const bytes = new Uint8Array(batch);
1306
+ output.push(bytes);
1307
+ byteLength += bytes.byteLength;
1308
+ }
1309
+ const result = new Uint8Array(byteLength);
1310
+ let offset = 0;
1311
+ for (const batch of output) {
1312
+ result.set(batch, offset);
1313
+ offset += batch.byteLength;
1314
+ }
1315
+ return result.buffer;
1316
+ }
1317
+ var init_compression_stream = __esm({
1318
+ "../compression/src/lib/compression-stream.ts"() {
1319
+ "use strict";
1320
+ }
1321
+ });
1322
+
1323
+ // ../compression/src/lib/decompression-stream.ts
1324
+ async function decompressWithNativeDecompressionStream(input, format) {
1325
+ const outputBatches = decompressBatchesWithNativeDecompressionStream([input], format);
1326
+ return outputBatches ? await concatenateNativeDecompressionBatches(outputBatches) : null;
1327
+ }
1328
+ function decompressBatchesWithNativeDecompressionStream(inputBatches, format) {
1329
+ const decompressionStream = createNativeDecompressionStream(format);
1330
+ return decompressionStream ? transformBatchesWithNativeDecompressionStream(inputBatches, decompressionStream) : null;
1331
+ }
1332
+ function isNativeDecompressionSupported(format) {
1333
+ return Boolean(createNativeDecompressionStream(format));
1334
+ }
1335
+ function createNativeDecompressionStream(format) {
1336
+ var _a, _b;
1337
+ if (typeof globalThis.DecompressionStream === "undefined") {
1338
+ return null;
1339
+ }
1340
+ if (((_b = (_a = globalThis.process) == null ? void 0 : _a.release) == null ? void 0 : _b.name) === "node" && typeof globalThis.Buffer === "undefined") {
1341
+ return null;
1342
+ }
1343
+ try {
1344
+ const DecompressionStreamConstructor = globalThis.DecompressionStream;
1345
+ return new DecompressionStreamConstructor(format);
1346
+ } catch (error) {
1347
+ if (error instanceof TypeError || (error == null ? void 0 : error.name) === "TypeError") {
1348
+ return null;
1349
+ }
1350
+ throw error;
1351
+ }
1352
+ }
1353
+ async function* transformBatchesWithNativeDecompressionStream(inputBatches, decompressionStream) {
1354
+ const writer = decompressionStream.writable.getWriter();
1355
+ const reader = decompressionStream.readable.getReader();
1356
+ const writePromise = writeBatchesToNativeDecompressionStream(inputBatches, writer);
1357
+ writePromise.catch(() => {
1358
+ });
1359
+ let outputCompleted = false;
1360
+ try {
1361
+ while (true) {
1362
+ const { done, value } = await reader.read();
1363
+ if (done) {
1364
+ outputCompleted = true;
1365
+ break;
1366
+ }
1367
+ yield copyExactArrayBuffer(value);
1368
+ }
1369
+ await writePromise;
1370
+ } finally {
1371
+ if (!outputCompleted) {
1372
+ await reader.cancel().catch(() => {
1373
+ });
1374
+ await writer.abort().catch(() => {
1375
+ });
1376
+ await writePromise.catch(() => {
1377
+ });
1378
+ }
1379
+ reader.releaseLock();
1380
+ }
1381
+ }
1382
+ async function concatenateNativeDecompressionBatches(outputBatches) {
1383
+ const batches = [];
1384
+ let byteLength = 0;
1385
+ for await (const outputBatch of outputBatches) {
1386
+ const bytes = new Uint8Array(outputBatch);
1387
+ batches.push(bytes);
1388
+ byteLength += bytes.byteLength;
1389
+ }
1390
+ const output = new Uint8Array(byteLength);
1391
+ let byteOffset = 0;
1392
+ for (const batch of batches) {
1393
+ output.set(batch, byteOffset);
1394
+ byteOffset += batch.byteLength;
1395
+ }
1396
+ return output.buffer;
1397
+ }
1398
+ function copyExactArrayBuffer(value) {
1399
+ return new Uint8Array(value).buffer;
1400
+ }
1401
+ async function writeBatchesToNativeDecompressionStream(inputBatches, writer) {
1402
+ try {
1403
+ for await (const inputBatch of inputBatches) {
1404
+ await writer.write(new Uint8Array(inputBatch));
1405
+ }
1406
+ await writer.close();
1407
+ } catch (error) {
1408
+ await writer.abort(error).catch(() => {
1409
+ });
1410
+ throw error;
1411
+ }
1412
+ }
1413
+ var init_decompression_stream = __esm({
1414
+ "../compression/src/lib/decompression-stream.ts"() {
1415
+ "use strict";
1192
1416
  }
1193
1417
  });
1194
1418
 
1195
- // ../loader-utils/src/index.ts
1196
- var init_src = __esm({
1197
- "../loader-utils/src/index.ts"() {
1419
+ // ../compression/src/lib/native-decompressor.ts
1420
+ var native_decompressor_exports = {};
1421
+ __export(native_decompressor_exports, {
1422
+ NativeDecompressor: () => NativeDecompressor
1423
+ });
1424
+ var NativeDecompressor;
1425
+ var init_native_decompressor = __esm({
1426
+ "../compression/src/lib/native-decompressor.ts"() {
1198
1427
  "use strict";
1199
- init_globals();
1200
- init_js_module_utils();
1201
- init_js_module_utils();
1202
- init_async_iteration();
1203
- init_memory_conversion_utils();
1204
- init_promisify();
1205
- init_data_source();
1428
+ init_compression();
1429
+ init_decompression_stream();
1430
+ NativeDecompressor = class extends Decompressor {
1431
+ name;
1432
+ extensions;
1433
+ contentEncodings;
1434
+ isSupported = true;
1435
+ /** Runtime stream format used for every operation. */
1436
+ format;
1437
+ constructor(metadata, format, options = {}) {
1438
+ super(options);
1439
+ this.name = metadata.name;
1440
+ this.extensions = [...metadata.extensions];
1441
+ this.contentEncodings = [...metadata.contentEncodings];
1442
+ this.format = format;
1443
+ }
1444
+ /** Decompresses one buffer with the runtime-provided stream. */
1445
+ async decompress(input) {
1446
+ const output = await decompressWithNativeDecompressionStream(input, this.format);
1447
+ if (!output) throw new Error(`${this.name}: built-in decompression is no longer available`);
1448
+ return output;
1449
+ }
1450
+ /** Decompresses batches incrementally with the runtime-provided stream. */
1451
+ async *decompressBatches(inputBatches) {
1452
+ const output = decompressBatchesWithNativeDecompressionStream(inputBatches, this.format);
1453
+ if (!output) throw new Error(`${this.name}: built-in decompression is no longer available`);
1454
+ yield* output;
1455
+ }
1456
+ };
1206
1457
  }
1207
1458
  });
1208
1459
 
1209
- // ../compression/src/lib/compression.ts
1210
- var Compression;
1211
- var init_compression = __esm({
1212
- "../compression/src/lib/compression.ts"() {
1460
+ // ../compression/src/lib/lazy-compression.ts
1461
+ function mergeModules(options, modules) {
1462
+ return { ...options, modules: { ...options.modules, ...modules } };
1463
+ }
1464
+ var LazyDecompressor;
1465
+ var init_lazy_compression = __esm({
1466
+ "../compression/src/lib/lazy-compression.ts"() {
1213
1467
  "use strict";
1214
- init_src();
1215
- Compression = class {
1216
- constructor(options) {
1217
- this.compressBatches = this.compressBatches.bind(this);
1218
- this.decompressBatches = this.decompressBatches.bind(this);
1468
+ init_compression();
1469
+ init_decompression_stream();
1470
+ LazyDecompressor = class extends Decompressor {
1471
+ name;
1472
+ extensions;
1473
+ contentEncodings;
1474
+ isSupported = true;
1475
+ /** Constructor options retained until a concrete implementation is selected. */
1476
+ options;
1477
+ /** Built-in stream format to probe, or null when the format has no built-in path. */
1478
+ nativeFormat;
1479
+ /** Returns whether built-in selection remains eligible for the merged preload options. */
1480
+ shouldUseNative;
1481
+ /** Dynamically imports the balanced fallback constructor. */
1482
+ loadFallback;
1483
+ /** Selected concrete implementation after preload completes. */
1484
+ implementation = null;
1485
+ /** Shared in-flight selection used by concurrent asynchronous calls. */
1486
+ implementationPromise = null;
1487
+ constructor(metadata, loadFallback, options = {}, nativeFormat = null, shouldUseNative = () => true) {
1488
+ super(options);
1489
+ this.name = metadata.name;
1490
+ this.extensions = [...metadata.extensions];
1491
+ this.contentEncodings = [...metadata.contentEncodings];
1492
+ this.options = options;
1493
+ this.nativeFormat = nativeFormat;
1494
+ this.shouldUseNative = shouldUseNative;
1495
+ this.loadFallback = loadFallback;
1219
1496
  }
1220
- /** Preloads any dynamic libraries. May enable sync functions */
1497
+ /** Selects and returns the built-in or dynamically imported fallback decompressor. */
1221
1498
  async preload(modules = {}) {
1222
- registerJSModules(modules);
1223
- return;
1499
+ if (this.implementation) return this.implementation;
1500
+ const options = mergeModules(this.options, modules);
1501
+ this.implementationPromise ||= this.loadImplementation(options);
1502
+ try {
1503
+ this.implementation = await this.implementationPromise;
1504
+ return this.implementation;
1505
+ } catch (error) {
1506
+ this.implementationPromise = null;
1507
+ throw error;
1508
+ }
1224
1509
  }
1225
- /** Asynchronously compress data */
1226
- async compress(input) {
1227
- await this.preload();
1228
- return this.compressSync(input);
1510
+ /** Loads the selected concrete decompressor. */
1511
+ async loadImplementation(options) {
1512
+ if (options.useNative !== false && this.nativeFormat && this.shouldUseNative(options) && isNativeDecompressionSupported(this.nativeFormat)) {
1513
+ const { NativeDecompressor: NativeDecompressor2 } = await Promise.resolve().then(() => (init_native_decompressor(), native_decompressor_exports));
1514
+ return new NativeDecompressor2(this, this.nativeFormat, options);
1515
+ }
1516
+ const Decompressor2 = await this.loadFallback();
1517
+ const implementation = new Decompressor2({ ...options, useNative: false });
1518
+ await implementation.preload(options.modules);
1519
+ return implementation;
1229
1520
  }
1230
- /** Asynchronously decompress data */
1521
+ /** Decompresses after lazily selecting the default implementation. */
1231
1522
  async decompress(input, size) {
1232
- await this.preload();
1233
- return this.decompressSync(input, size);
1234
- }
1235
- /** Synchronously compress data */
1236
- compressSync(input) {
1237
- throw new Error(`${this.name}: sync compression not supported`);
1523
+ return (await this.preload()).decompress(input, size);
1238
1524
  }
1239
- /** Synchronously compress data */
1525
+ /** Decompresses synchronously after an implementation has been preloaded. */
1240
1526
  decompressSync(input, size) {
1241
- throw new Error(`${this.name}: sync decompression not supported`);
1242
- }
1243
- /** Compress batches */
1244
- async *compressBatches(asyncIterator) {
1245
- const input = await this.concatenate(asyncIterator);
1246
- yield this.compress(input);
1527
+ if (!this.implementation) {
1528
+ throw new Error(`${this.name}: call preload() before decompressSync()`);
1529
+ }
1530
+ return this.implementation.decompressSync(input, size);
1247
1531
  }
1248
- /** Decompress batches */
1249
- async *decompressBatches(asyncIterator) {
1250
- const input = await this.concatenate(asyncIterator);
1251
- yield this.decompress(input);
1532
+ /** Decompresses batches after lazily selecting the default implementation. */
1533
+ async *decompressBatches(inputBatches) {
1534
+ yield* (await this.preload()).decompressBatches(inputBatches);
1252
1535
  }
1253
- // HELPERS
1254
- concatenate(asyncIterator) {
1255
- return concatenateArrayBuffersAsync(asyncIterator);
1536
+ };
1537
+ }
1538
+ });
1539
+
1540
+ // ../compression/src/zstd-decompressor-fzstd.ts
1541
+ var import_fzstd, ZstdFzstdDecompressor;
1542
+ var init_zstd_decompressor_fzstd = __esm({
1543
+ "../compression/src/zstd-decompressor-fzstd.ts"() {
1544
+ "use strict";
1545
+ init_compression();
1546
+ import_fzstd = require("fzstd");
1547
+ ZstdFzstdDecompressor = class extends Decompressor {
1548
+ name = "zstd";
1549
+ extensions = ["zst"];
1550
+ contentEncodings = ["zstd"];
1551
+ isSupported = true;
1552
+ constructor(options = {}) {
1553
+ super(options);
1256
1554
  }
1257
- improveError(error) {
1258
- if (!error.message.includes(this.name)) {
1259
- error.message = `${this.name} ${error.message}`;
1260
- }
1261
- return error;
1555
+ /** Decompresses one Zstandard frame synchronously. */
1556
+ decompressSync(input) {
1557
+ return (0, import_fzstd.decompress)(new Uint8Array(input)).slice().buffer;
1262
1558
  }
1263
1559
  };
1264
1560
  }
1265
1561
  });
1266
1562
 
1563
+ // ../compression/src/zstd-fallback.ts
1564
+ var zstd_fallback_exports = {};
1565
+ __export(zstd_fallback_exports, {
1566
+ decompressZstd: () => decompressZstd
1567
+ });
1568
+ function decompressZstd(input) {
1569
+ return (0, import_fzstd2.decompress)(input);
1570
+ }
1571
+ var import_fzstd2;
1572
+ var init_zstd_fallback = __esm({
1573
+ "../compression/src/zstd-fallback.ts"() {
1574
+ "use strict";
1575
+ import_fzstd2 = require("fzstd");
1576
+ }
1577
+ });
1578
+
1267
1579
  // ../compression/src/lib/zstd-compression.ts
1580
+ var zstd_compression_exports = {};
1581
+ __export(zstd_compression_exports, {
1582
+ ZstdCompression: () => ZstdCompression
1583
+ });
1268
1584
  var CHUNK_SIZE, zstdPromise, zstd, ZstdCompression;
1269
1585
  var init_zstd_compression = __esm({
1270
1586
  "../compression/src/lib/zstd-compression.ts"() {
1271
1587
  "use strict";
1272
1588
  init_compression();
1273
1589
  init_src();
1590
+ init_compression_stream();
1591
+ init_decompression_stream();
1274
1592
  CHUNK_SIZE = 1e6;
1275
1593
  ZstdCompression = class extends Compression {
1276
1594
  name = "zstd";
@@ -1303,6 +1621,15 @@ var init_zstd_compression = __esm({
1303
1621
  const inputArray = new Uint8Array(input);
1304
1622
  return simpleZstd.compress(inputArray).buffer;
1305
1623
  }
1624
+ async compress(input) {
1625
+ var _a;
1626
+ if (this.options.useNative !== false && ((_a = this.options.zstd) == null ? void 0 : _a.useNative) !== false) {
1627
+ const nativeOutput = await compressWithNativeCompressionStream(input, "zstd");
1628
+ if (nativeOutput) return nativeOutput;
1629
+ }
1630
+ await this.preload();
1631
+ return this.compressSync(input);
1632
+ }
1306
1633
  decompressSync(input) {
1307
1634
  getJSModule("zstd-codec", this.name);
1308
1635
  const simpleZstd = new zstd.Simple();
@@ -1310,11 +1637,16 @@ var init_zstd_compression = __esm({
1310
1637
  return simpleZstd.decompress(inputArray).buffer;
1311
1638
  }
1312
1639
  async decompress(input, size) {
1640
+ var _a;
1641
+ if (!getJSModuleOrNull("zstd-codec") && this.options.useNative !== false && ((_a = this.options.zstd) == null ? void 0 : _a.useNative) !== false) {
1642
+ const nativeOutput = await decompressWithNativeDecompressionStream(input, "zstd");
1643
+ if (nativeOutput) return nativeOutput;
1644
+ }
1313
1645
  await this.preload();
1314
1646
  const inputArray = new Uint8Array(input);
1315
1647
  if (!zstd) {
1316
- const { decompress } = await import("fzstd");
1317
- return ensureArrayBuffer(decompress(inputArray));
1648
+ const { decompressZstd: decompressZstd2 } = await Promise.resolve().then(() => (init_zstd_fallback(), zstd_fallback_exports));
1649
+ return ensureArrayBuffer(decompressZstd2(inputArray));
1318
1650
  }
1319
1651
  const simpleZstd = new zstd.Streaming();
1320
1652
  const chunks = [];
@@ -1330,15 +1662,105 @@ var init_zstd_compression = __esm({
1330
1662
  }
1331
1663
  });
1332
1664
 
1333
- // ../compression/src/zstd-compression.ts
1334
- var zstd_compression_exports = {};
1335
- __export(zstd_compression_exports, {
1336
- ZstdCompression: () => ZstdCompression
1665
+ // ../compression/src/zstd-decompressor.ts
1666
+ var zstd_decompressor_exports = {};
1667
+ __export(zstd_decompressor_exports, {
1668
+ ZstdDecompressor: () => ZstdDecompressor
1669
+ });
1670
+ var ZstdDecompressor;
1671
+ var init_zstd_decompressor = __esm({
1672
+ "../compression/src/zstd-decompressor.ts"() {
1673
+ "use strict";
1674
+ init_zstd_decompressor_fzstd();
1675
+ init_decompression_stream();
1676
+ init_src();
1677
+ ZstdDecompressor = class extends ZstdFzstdDecompressor {
1678
+ options;
1679
+ compatibility = null;
1680
+ constructor(options = {}) {
1681
+ super(options);
1682
+ this.options = options;
1683
+ registerJSModules(options.modules);
1684
+ }
1685
+ /** Preloads an injected zstd-codec implementation when supplied. */
1686
+ async preload(modules = {}) {
1687
+ registerJSModules(modules);
1688
+ if (getJSModuleOrNull("zstd-codec")) {
1689
+ const { ZstdCompression: ZstdCompression2 } = await Promise.resolve().then(() => (init_zstd_compression(), zstd_compression_exports));
1690
+ this.compatibility ||= new ZstdCompression2(this.options);
1691
+ await this.compatibility.preload(modules);
1692
+ }
1693
+ }
1694
+ /** Decompresses with the built-in stream when available, then falls back to fzstd. */
1695
+ async decompress(input) {
1696
+ if (this.options.useNative !== false) {
1697
+ const output = await decompressWithNativeDecompressionStream(input, "zstd");
1698
+ if (output) return output;
1699
+ }
1700
+ if (getJSModuleOrNull("zstd-codec")) {
1701
+ await this.preload(this.options.modules);
1702
+ }
1703
+ return this.decompressSync(input);
1704
+ }
1705
+ /** Decompresses with a preloaded zstd-codec implementation or compact fzstd. */
1706
+ decompressSync(input) {
1707
+ if (this.compatibility) {
1708
+ return this.compatibility.decompressSync(input);
1709
+ }
1710
+ if (getJSModuleOrNull("zstd-codec")) {
1711
+ throw new Error("zstd: call preload() before synchronous decompression with zstd-codec");
1712
+ }
1713
+ return super.decompressSync(input);
1714
+ }
1715
+ /** Decompresses batches with a built-in stream or compact fzstd fallback. */
1716
+ async *decompressBatches(inputBatches) {
1717
+ if (this.options.useNative !== false) {
1718
+ const output = decompressBatchesWithNativeDecompressionStream(inputBatches, "zstd");
1719
+ if (output) {
1720
+ yield* output;
1721
+ return;
1722
+ }
1723
+ }
1724
+ if (getJSModuleOrNull("zstd-codec")) {
1725
+ yield this.decompress(await this.concatenate(inputBatches));
1726
+ return;
1727
+ }
1728
+ yield* super.decompressBatches(inputBatches);
1729
+ }
1730
+ };
1731
+ }
1732
+ });
1733
+
1734
+ // ../compression/src/default-codecs.ts
1735
+ var ZSTD, ZstdDecompressor2;
1736
+ var init_default_codecs = __esm({
1737
+ "../compression/src/default-codecs.ts"() {
1738
+ "use strict";
1739
+ init_lazy_compression();
1740
+ init_src();
1741
+ ZSTD = { name: "zstd", extensions: ["zst"], contentEncodings: ["zstd"] };
1742
+ ZstdDecompressor2 = class extends LazyDecompressor {
1743
+ constructor(options = {}) {
1744
+ super(
1745
+ ZSTD,
1746
+ async () => (await Promise.resolve().then(() => (init_zstd_decompressor(), zstd_decompressor_exports))).ZstdDecompressor,
1747
+ options,
1748
+ "zstd",
1749
+ (preloadOptions) => {
1750
+ var _a;
1751
+ return !((_a = preloadOptions.modules) == null ? void 0 : _a["zstd-codec"]) && !getJSModuleOrNull("zstd-codec");
1752
+ }
1753
+ );
1754
+ }
1755
+ };
1756
+ }
1337
1757
  });
1338
- var init_zstd_compression2 = __esm({
1339
- "../compression/src/zstd-compression.ts"() {
1758
+
1759
+ // ../compression/src/index.ts
1760
+ var init_src2 = __esm({
1761
+ "../compression/src/index.ts"() {
1340
1762
  "use strict";
1341
- init_zstd_compression();
1763
+ init_default_codecs();
1342
1764
  }
1343
1765
  });
1344
1766
 
@@ -1350,30 +1772,11 @@ async function parseSPZToGaussianSplats(data, options) {
1350
1772
  const header = parseSPZHeader(data);
1351
1773
  const streamInfos = parseSPZStreamInfos(data, header, getSPZStreamByteLengths(header));
1352
1774
  const compressedStreams = streamInfos.map((streamInfo) => data.slice(streamInfo.compressedOffset, streamInfo.compressedOffset + streamInfo.compressedSize));
1353
- registerJSModules(options == null ? void 0 : options.modules);
1354
- const useNativeDecompressionStream = !getJSModuleOrNull("zstd-codec");
1355
- let compressionPromise;
1356
- const streams = await Promise.all(compressedStreams.map((compressedStream, streamIndex) => decompressSPZStream(compressedStream, streamInfos[streamIndex].uncompressedSize, useNativeDecompressionStream, () => {
1357
- compressionPromise ||= createZstdCompression(options == null ? void 0 : options.modules);
1358
- return compressionPromise;
1359
- })));
1775
+ const decompressor = new ZstdDecompressor2({ modules: options == null ? void 0 : options.modules });
1776
+ const streams = await Promise.all(compressedStreams.map((compressedStream, streamIndex) => decompressor.decompress(compressedStream, streamInfos[streamIndex].uncompressedSize)));
1360
1777
  validateSPZStreamLengths(streams, streamInfos);
1361
1778
  return decodeSPZStreams(header, streams, data);
1362
1779
  }
1363
- async function decompressSPZStream(compressedStream, uncompressedSize, useNativeDecompressionStream, getCompression) {
1364
- if (useNativeDecompressionStream) {
1365
- const nativeOutput = await decompressWithNativeDecompressionStream(compressedStream, "zstd");
1366
- if (nativeOutput) {
1367
- return nativeOutput;
1368
- }
1369
- }
1370
- const compression = await getCompression();
1371
- return await compression.decompress(compressedStream, uncompressedSize);
1372
- }
1373
- async function createZstdCompression(modules) {
1374
- const { ZstdCompression: ZstdCompression2 } = await Promise.resolve().then(() => (init_zstd_compression2(), zstd_compression_exports));
1375
- return new ZstdCompression2({ modules });
1376
- }
1377
1780
  function parseSPZHeader(data) {
1378
1781
  if (data.byteLength < SPZ_HEADER_BYTE_LENGTH) {
1379
1782
  throw new Error(`SPZLoader: file must contain a ${SPZ_HEADER_BYTE_LENGTH}-byte header.`);
@@ -1591,8 +1994,7 @@ var SPZ_HEADER_BYTE_LENGTH, SPZ_MAGIC, SPZ_VERSION, SPZ_EXTENSION_FLAG, SPZ_COLO
1591
1994
  var init_parse_spz = __esm({
1592
1995
  "dist/lib/parse-spz.js"() {
1593
1996
  "use strict";
1594
- init_native_decompression();
1595
- init_src();
1997
+ init_src2();
1596
1998
  init_splats_arrow_table();
1597
1999
  init_splat_utils();
1598
2000
  SPZ_HEADER_BYTE_LENGTH = 32;
@@ -1634,7 +2036,7 @@ var init_spz_loader_types = __esm({
1634
2036
  "dist/spz-loader-types.js"() {
1635
2037
  "use strict";
1636
2038
  init_splats_format();
1637
- VERSION4 = true ? "5.0.0-alpha.2" : "latest";
2039
+ VERSION4 = true ? "5.0.0-alpha.4" : "latest";
1638
2040
  SPZLoader = {
1639
2041
  dataType: null,
1640
2042
  batchType: null,
@@ -1808,144 +2210,94 @@ var init_parse_rad = __esm({
1808
2210
  }
1809
2211
  });
1810
2212
 
1811
- // ../compression/src/lib/deflate-compression.ts
1812
- var import_pako, import_zlib, DeflateCompression;
1813
- var init_deflate_compression = __esm({
1814
- "../compression/src/lib/deflate-compression.ts"() {
2213
+ // ../compression/src/lib/fflate-stream.ts
2214
+ async function* transformFflateBatches(processor, inputBatches) {
2215
+ const chunks = [];
2216
+ processor.ondata = (data) => {
2217
+ chunks.push(data.slice().buffer);
2218
+ };
2219
+ for await (const batch of inputBatches) {
2220
+ processor.push(new Uint8Array(batch), false);
2221
+ yield* chunks.splice(0);
2222
+ }
2223
+ processor.push(new Uint8Array(0), true);
2224
+ yield* chunks;
2225
+ }
2226
+ var init_fflate_stream = __esm({
2227
+ "../compression/src/lib/fflate-stream.ts"() {
2228
+ "use strict";
2229
+ }
2230
+ });
2231
+
2232
+ // ../compression/src/deflate-decompressor-fflate.ts
2233
+ var import_fflate, DeflateFflateDecompressor;
2234
+ var init_deflate_decompressor_fflate = __esm({
2235
+ "../compression/src/deflate-decompressor-fflate.ts"() {
1815
2236
  "use strict";
2237
+ import_fflate = require("fflate");
1816
2238
  init_compression();
1817
- init_src();
1818
- import_pako = __toESM(require("pako"), 1);
1819
- import_zlib = __toESM(require("zlib"), 1);
1820
- DeflateCompression = class extends Compression {
2239
+ init_fflate_stream();
2240
+ DeflateFflateDecompressor = class extends Decompressor {
1821
2241
  name = "deflate";
1822
2242
  extensions = [];
1823
2243
  contentEncodings = ["deflate"];
1824
2244
  isSupported = true;
1825
2245
  options;
1826
- _chunks = [];
1827
2246
  constructor(options = {}) {
1828
2247
  super(options);
1829
2248
  this.options = options;
1830
2249
  }
1831
- async compress(input) {
1832
- var _a, _b;
1833
- if (!isBrowser && ((_a = this.options.deflate) == null ? void 0 : _a.useZlib)) {
1834
- const buffer = ((_b = this.options.deflate) == null ? void 0 : _b.gzip) ? await promisify1(import_zlib.default.gzip)(input) : await promisify1(import_zlib.default.deflate)(input);
1835
- return toArrayBuffer2(buffer);
1836
- }
1837
- return this.compressSync(input);
1838
- }
1839
- async decompress(input) {
1840
- var _a, _b;
1841
- if (!isBrowser && ((_a = this.options.deflate) == null ? void 0 : _a.useZlib)) {
1842
- const buffer = ((_b = this.options.deflate) == null ? void 0 : _b.gzip) ? await promisify1(import_zlib.default.gunzip)(input) : await promisify1(import_zlib.default.inflate)(input);
1843
- return toArrayBuffer2(buffer);
1844
- }
1845
- return this.decompressSync(input);
1846
- }
1847
- compressSync(input) {
1848
- var _a, _b, _c, _d;
1849
- if (!isBrowser && ((_a = this.options.deflate) == null ? void 0 : _a.useZlib)) {
1850
- const buffer = ((_b = this.options.deflate) == null ? void 0 : _b.gzip) ? import_zlib.default.gzipSync(input) : import_zlib.default.deflateSync(input);
1851
- return toArrayBuffer2(buffer);
1852
- }
1853
- const pakoOptions = ((_c = this.options) == null ? void 0 : _c.deflate) || {};
1854
- const inputArray = new Uint8Array(input);
1855
- const deflate = ((_d = this.options) == null ? void 0 : _d.raw) ? import_pako.default.deflateRaw : import_pako.default.deflate;
1856
- return toArrayBuffer2(deflate(inputArray, pakoOptions).buffer);
1857
- }
2250
+ /** Decompresses one zlib-wrapped DEFLATE payload synchronously. */
1858
2251
  decompressSync(input) {
1859
- var _a, _b, _c, _d;
1860
- if (!isBrowser && ((_a = this.options.deflate) == null ? void 0 : _a.useZlib)) {
1861
- const buffer = ((_b = this.options.deflate) == null ? void 0 : _b.gzip) ? import_zlib.default.gunzipSync(input) : import_zlib.default.inflateSync(input);
1862
- return toArrayBuffer2(buffer);
1863
- }
1864
- const pakoOptions = ((_c = this.options) == null ? void 0 : _c.deflate) || {};
1865
- const inputArray = new Uint8Array(input);
1866
- const inflate = ((_d = this.options) == null ? void 0 : _d.raw) ? import_pako.default.inflateRaw : import_pako.default.inflate;
1867
- return toArrayBuffer2(inflate(inputArray, pakoOptions).buffer);
2252
+ const bytes = new Uint8Array(input);
2253
+ const output = this.options.raw ? (0, import_fflate.inflateSync)(bytes) : (0, import_fflate.unzlibSync)(bytes);
2254
+ return output.slice().buffer;
1868
2255
  }
1869
- async *compressBatches(asyncIterator) {
1870
- var _a;
1871
- const pakoOptions = ((_a = this.options) == null ? void 0 : _a.deflate) || {};
1872
- const pakoProcessor = new import_pako.default.Deflate(pakoOptions);
1873
- yield* this.transformBatches(pakoProcessor, asyncIterator);
2256
+ /** Decompresses DEFLATE batches incrementally. */
2257
+ async *decompressBatches(inputBatches) {
2258
+ const processor = this.options.raw ? new import_fflate.Inflate() : new import_fflate.Unzlib();
2259
+ yield* transformFflateBatches(processor, inputBatches);
1874
2260
  }
1875
- async *decompressBatches(asyncIterator) {
1876
- var _a;
1877
- const pakoOptions = ((_a = this.options) == null ? void 0 : _a.deflate) || {};
1878
- const pakoProcessor = new import_pako.default.Inflate(pakoOptions);
1879
- yield* this.transformBatches(pakoProcessor, asyncIterator);
2261
+ };
2262
+ }
2263
+ });
2264
+
2265
+ // ../compression/src/deflate-decompressor.ts
2266
+ var DeflateDecompressor2;
2267
+ var init_deflate_decompressor = __esm({
2268
+ "../compression/src/deflate-decompressor.ts"() {
2269
+ "use strict";
2270
+ init_deflate_decompressor_fflate();
2271
+ init_decompression_stream();
2272
+ DeflateDecompressor2 = class extends DeflateFflateDecompressor {
2273
+ constructor(options = {}) {
2274
+ super(options);
1880
2275
  }
1881
- async *transformBatches(pakoProcessor, asyncIterator) {
1882
- pakoProcessor.onData = this._onData.bind(this);
1883
- pakoProcessor.onEnd = this._onEnd.bind(this);
1884
- for await (const chunk of asyncIterator) {
1885
- const uint8Array = new Uint8Array(chunk);
1886
- const ok2 = pakoProcessor.push(uint8Array, false);
1887
- if (!ok2) {
1888
- throw new Error(`${this._getError()}write`);
1889
- }
1890
- const chunks2 = this._getChunks();
1891
- yield* chunks2;
1892
- }
1893
- const emptyChunk = new Uint8Array(0);
1894
- const ok = pakoProcessor.push(emptyChunk, true);
1895
- if (!ok) {
2276
+ /** Decompresses with the built-in stream when available, then falls back to fflate. */
2277
+ async decompress(input) {
2278
+ if (this.options.useNative !== false) {
2279
+ const format = this.options.raw ? "deflate-raw" : "deflate";
2280
+ const output = await decompressWithNativeDecompressionStream(input, format);
2281
+ if (output) return output;
1896
2282
  }
1897
- const chunks = this._getChunks();
1898
- yield* chunks;
1899
- }
1900
- _onData(chunk) {
1901
- this._chunks.push(chunk);
2283
+ return this.decompressSync(input);
1902
2284
  }
1903
- _onEnd(status) {
1904
- if (status !== 0) {
1905
- throw new Error(this._getError(status) + this._chunks.length);
2285
+ /** Decompresses batches with a built-in or fflate stream. */
2286
+ async *decompressBatches(inputBatches) {
2287
+ if (this.options.useNative !== false) {
2288
+ const format = this.options.raw ? "deflate-raw" : "deflate";
2289
+ const output = decompressBatchesWithNativeDecompressionStream(inputBatches, format);
2290
+ if (output) {
2291
+ yield* output;
2292
+ return;
2293
+ }
1906
2294
  }
1907
- }
1908
- _getChunks() {
1909
- const chunks = this._chunks;
1910
- this._chunks = [];
1911
- return chunks;
1912
- }
1913
- // TODO - For some reason we don't get the error message from pako in _onEnd?
1914
- _getError(code = 0) {
1915
- const MESSAGES = {
1916
- /* Z_NEED_DICT 2 */
1917
- 2: "need dictionary",
1918
- /* Z_STREAM_END 1 */
1919
- 1: "stream end",
1920
- /* Z_OK 0 */
1921
- 0: "",
1922
- /* Z_ERRNO (-1) */
1923
- "-1": "file error",
1924
- /* Z_STREAM_ERROR (-2) */
1925
- "-2": "stream error",
1926
- /* Z_DATA_ERROR (-3) */
1927
- "-3": "data error",
1928
- /* Z_MEM_ERROR (-4) */
1929
- "-4": "insufficient memory",
1930
- /* Z_BUF_ERROR (-5) */
1931
- "-5": "buffer error",
1932
- /* Z_VERSION_ERROR (-6) */
1933
- "-6": "incompatible version"
1934
- };
1935
- return `${this.name}: ${MESSAGES[code]}`;
2295
+ yield* super.decompressBatches(inputBatches);
1936
2296
  }
1937
2297
  };
1938
2298
  }
1939
2299
  });
1940
2300
 
1941
- // ../compression/src/index.ts
1942
- var init_src2 = __esm({
1943
- "../compression/src/index.ts"() {
1944
- "use strict";
1945
- init_deflate_compression();
1946
- }
1947
- });
1948
-
1949
2301
  // dist/lib/parse-rad-chunk.js
1950
2302
  function parseRADChunk(data, options) {
1951
2303
  return makeGaussianSplatsArrowTable(parseRADChunkToGaussianSplats(data, options));
@@ -2408,12 +2760,12 @@ var RAD_PROPERTY_DEFLATE, RAD_PROPERTY_RAW_DEFLATE;
2408
2760
  var init_parse_rad_chunk = __esm({
2409
2761
  "dist/lib/parse-rad-chunk.js"() {
2410
2762
  "use strict";
2411
- init_src2();
2763
+ init_deflate_decompressor();
2412
2764
  init_parse_rad();
2413
2765
  init_splats_arrow_table();
2414
2766
  init_splat_utils();
2415
- RAD_PROPERTY_DEFLATE = new DeflateCompression();
2416
- RAD_PROPERTY_RAW_DEFLATE = new DeflateCompression({ raw: true });
2767
+ RAD_PROPERTY_DEFLATE = new DeflateDecompressor2({ useNative: false });
2768
+ RAD_PROPERTY_RAW_DEFLATE = new DeflateDecompressor2({ raw: true, useNative: false });
2417
2769
  }
2418
2770
  });
2419
2771
 
@@ -2454,7 +2806,7 @@ var init_rad_loader_types = __esm({
2454
2806
  "dist/rad-loader-types.js"() {
2455
2807
  "use strict";
2456
2808
  init_splats_format();
2457
- VERSION5 = true ? "5.0.0-alpha.2" : "latest";
2809
+ VERSION5 = true ? "5.0.0-alpha.4" : "latest";
2458
2810
  RADLoader = {
2459
2811
  dataType: null,
2460
2812
  batchType: null,
@@ -2496,7 +2848,7 @@ init_parse_rad_chunk();
2496
2848
  init_splats_arrow_table();
2497
2849
  var DEFAULT_RAD_HEADER_BYTE_LENGTHS = [64 * 1024, 256 * 1024, 1024 * 1024];
2498
2850
  var DEFAULT_RAD_MAX_CONCURRENT_CHUNK_REQUESTS = 4;
2499
- var VERSION6 = true ? "5.0.0-alpha.2" : "latest";
2851
+ var VERSION6 = true ? "5.0.0-alpha.4" : "latest";
2500
2852
  var RADSourceLoader = {
2501
2853
  dataType: null,
2502
2854
  batchType: null,