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

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
@@ -5,8 +5,13 @@ 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) => function __init() {
9
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
8
+ var __esm = (fn, res, err) => function __init() {
9
+ if (err) throw err[0];
10
+ try {
11
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
12
+ } catch (e) {
13
+ throw err = [e], e;
14
+ }
10
15
  };
11
16
  var __export = (target, all) => {
12
17
  for (var name in all)
@@ -83,12 +88,12 @@ function convertColorByteToSphericalHarmonicDc(colorByte) {
83
88
  function convertAlphaByteToLinearOpacity(alphaByte) {
84
89
  return Math.min(Math.max(alphaByte / 255, 0), 1);
85
90
  }
86
- function normalizeQuaternion(w, x, y, z) {
87
- const length = Math.hypot(w, x, y, z);
91
+ function normalizeQuaternion(w, x, y, z2) {
92
+ const length = Math.hypot(w, x, y, z2);
88
93
  if (!Number.isFinite(length) || length <= Number.EPSILON) {
89
94
  return [1, 0, 0, 0];
90
95
  }
91
- return [w / length, x / length, y / length, z / length];
96
+ return [w / length, x / length, y / length, z2 / length];
92
97
  }
93
98
  function decodeQuaternionByte(byte) {
94
99
  return (byte - 128) / 128;
@@ -270,11 +275,11 @@ function parseSPLATToGaussianSplats(data) {
270
275
  colors[positionOffset + 1] = dataView.getUint8(byteOffset + 25);
271
276
  colors[positionOffset + 2] = dataView.getUint8(byteOffset + 26);
272
277
  opacities[splatIndex] = convertAlphaByteToLinearOpacity(dataView.getUint8(byteOffset + 27));
273
- const [w, x, y, z] = normalizeQuaternion(decodeQuaternionByte(dataView.getUint8(byteOffset + 28)), decodeQuaternionByte(dataView.getUint8(byteOffset + 29)), decodeQuaternionByte(dataView.getUint8(byteOffset + 30)), decodeQuaternionByte(dataView.getUint8(byteOffset + 31)));
278
+ const [w, x, y, z2] = normalizeQuaternion(decodeQuaternionByte(dataView.getUint8(byteOffset + 28)), decodeQuaternionByte(dataView.getUint8(byteOffset + 29)), decodeQuaternionByte(dataView.getUint8(byteOffset + 30)), decodeQuaternionByte(dataView.getUint8(byteOffset + 31)));
274
279
  rotations[rotationOffset + 0] = w;
275
280
  rotations[rotationOffset + 1] = x;
276
281
  rotations[rotationOffset + 2] = y;
277
- rotations[rotationOffset + 3] = z;
282
+ rotations[rotationOffset + 3] = z2;
278
283
  }
279
284
  return {
280
285
  format: "splat",
@@ -331,7 +336,7 @@ var init_splat_loader_types = __esm({
331
336
  "dist/splat-loader-types.js"() {
332
337
  "use strict";
333
338
  init_splats_format();
334
- VERSION = true ? "5.0.0-alpha.1" : "latest";
339
+ VERSION = true ? "5.0.0-alpha.2" : "latest";
335
340
  SPLATLoader = {
336
341
  dataType: null,
337
342
  batchType: null,
@@ -407,11 +412,11 @@ function decodeKSPLATSplat(data, header, section, localSplatIndex, outputSplatIn
407
412
  scales[positionOffset + 0] = readCompressedFloat(data, splatBase + layout.scaleOffsetBytes, 0, header.compressionLevel);
408
413
  scales[positionOffset + 1] = readCompressedFloat(data, splatBase + layout.scaleOffsetBytes, 1, header.compressionLevel);
409
414
  scales[positionOffset + 2] = readCompressedFloat(data, splatBase + layout.scaleOffsetBytes, 2, header.compressionLevel);
410
- const [w, x, y, z] = normalizeQuaternion(readCompressedFloat(data, splatBase + layout.scaleOffsetBytes, 3, header.compressionLevel), readCompressedFloat(data, splatBase + layout.scaleOffsetBytes, 4, header.compressionLevel), readCompressedFloat(data, splatBase + layout.scaleOffsetBytes, 5, header.compressionLevel), readCompressedFloat(data, splatBase + layout.scaleOffsetBytes, 6, header.compressionLevel));
415
+ const [w, x, y, z2] = normalizeQuaternion(readCompressedFloat(data, splatBase + layout.scaleOffsetBytes, 3, header.compressionLevel), readCompressedFloat(data, splatBase + layout.scaleOffsetBytes, 4, header.compressionLevel), readCompressedFloat(data, splatBase + layout.scaleOffsetBytes, 5, header.compressionLevel), readCompressedFloat(data, splatBase + layout.scaleOffsetBytes, 6, header.compressionLevel));
411
416
  rotations[rotationOffset + 0] = w;
412
417
  rotations[rotationOffset + 1] = x;
413
418
  rotations[rotationOffset + 2] = y;
414
- rotations[rotationOffset + 3] = z;
419
+ rotations[rotationOffset + 3] = z2;
415
420
  const colorBase = splatBase + layout.colorOffsetBytes;
416
421
  const colorView = new Uint8Array(data, colorBase, 4);
417
422
  colors[positionOffset + 0] = colorView[0];
@@ -656,7 +661,7 @@ var init_ksplat_loader_types = __esm({
656
661
  "dist/ksplat-loader-types.js"() {
657
662
  "use strict";
658
663
  init_splats_format();
659
- VERSION2 = true ? "5.0.0-alpha.1" : "latest";
664
+ VERSION2 = true ? "5.0.0-alpha.2" : "latest";
660
665
  KSPLATLoader = {
661
666
  dataType: null,
662
667
  batchType: null,
@@ -672,6 +677,671 @@ var init_ksplat_loader_types = __esm({
672
677
  }
673
678
  });
674
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
+ // ../loader-utils/src/lib/log-utils/log.ts
804
+ function createLog() {
805
+ const log2 = new import_log.Log({ id: "loaders.gl" });
806
+ globalThis.loaders ||= {};
807
+ globalThis.loaders.log = log2;
808
+ globalThis.loaders.version = version;
809
+ globalThis.probe ||= {};
810
+ globalThis.probe.loaders = log2;
811
+ return log2;
812
+ }
813
+ var import_log, VERSION3, version, log;
814
+ var init_log = __esm({
815
+ "../loader-utils/src/lib/log-utils/log.ts"() {
816
+ "use strict";
817
+ import_log = require("@probe.gl/log");
818
+ VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
819
+ version = VERSION3[0] >= "0" && VERSION3[0] <= "9" ? `v${VERSION3}` : "";
820
+ log = createLog();
821
+ }
822
+ });
823
+
824
+ // ../loader-utils/src/lib/javascript-utils/is-type.ts
825
+ var isObject, isPureObject, isSharedArrayBuffer;
826
+ var init_is_type = __esm({
827
+ "../loader-utils/src/lib/javascript-utils/is-type.ts"() {
828
+ "use strict";
829
+ isObject = (value) => value !== null && typeof value === "object";
830
+ isPureObject = (value) => isObject(value) && value.constructor === {}.constructor;
831
+ isSharedArrayBuffer = (value) => typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer;
832
+ }
833
+ });
834
+
835
+ // ../loader-utils/src/lib/option-utils/merge-options.ts
836
+ function mergeOptions(baseOptions, newOptions) {
837
+ return mergeOptionsRecursively(baseOptions || {}, newOptions);
838
+ }
839
+ function mergeOptionsRecursively(baseOptions, newOptions, level = 0) {
840
+ if (level > 3) {
841
+ return newOptions;
842
+ }
843
+ const options = { ...baseOptions };
844
+ for (const [key, newValue] of Object.entries(newOptions)) {
845
+ if (isPureObject(newValue)) {
846
+ options[key] = mergeOptionsRecursively(
847
+ options[key] || {},
848
+ newOptions[key],
849
+ level + 1
850
+ );
851
+ } else {
852
+ options[key] = newOptions[key];
853
+ }
854
+ }
855
+ return options;
856
+ }
857
+ var init_merge_options = __esm({
858
+ "../loader-utils/src/lib/option-utils/merge-options.ts"() {
859
+ "use strict";
860
+ init_is_type();
861
+ }
862
+ });
863
+
864
+ // ../loader-utils/src/lib/module-utils/js-module-utils.ts
865
+ function registerJSModules(modules) {
866
+ globalThis.loaders ||= {};
867
+ globalThis.loaders.modules ||= {};
868
+ Object.assign(globalThis.loaders.modules, modules);
869
+ }
870
+ function getJSModule(name, caller) {
871
+ var _a, _b;
872
+ const module2 = (_b = (_a = globalThis.loaders) == null ? void 0 : _a.modules) == null ? void 0 : _b[name];
873
+ if (!module2) {
874
+ throw new Error(`${caller}: ${name} library not installed`);
875
+ }
876
+ return module2;
877
+ }
878
+ function getJSModuleOrNull(name) {
879
+ var _a, _b;
880
+ const module2 = (_b = (_a = globalThis.loaders) == null ? void 0 : _a.modules) == null ? void 0 : _b[name];
881
+ return module2 || null;
882
+ }
883
+ var init_js_module_utils = __esm({
884
+ "../loader-utils/src/lib/module-utils/js-module-utils.ts"() {
885
+ "use strict";
886
+ }
887
+ });
888
+
889
+ // ../loader-utils/src/lib/binary-utils/array-buffer-utils.ts
890
+ function concatenateArrayBuffers(...sources) {
891
+ return concatenateArrayBuffersFromArray(sources);
892
+ }
893
+ function concatenateArrayBuffersFromArray(sources) {
894
+ const sourceArrays = sources.map(
895
+ (source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
896
+ );
897
+ const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
898
+ const result = new Uint8Array(byteLength);
899
+ let offset = 0;
900
+ for (const sourceArray of sourceArrays) {
901
+ result.set(sourceArray, offset);
902
+ offset += sourceArray.byteLength;
903
+ }
904
+ return result.buffer;
905
+ }
906
+ var init_array_buffer_utils = __esm({
907
+ "../loader-utils/src/lib/binary-utils/array-buffer-utils.ts"() {
908
+ "use strict";
909
+ }
910
+ });
911
+
912
+ // ../loader-utils/src/lib/iterators/async-iteration.ts
913
+ async function concatenateArrayBuffersAsync(asyncIterator) {
914
+ const arrayBuffers = [];
915
+ for await (const chunk of asyncIterator) {
916
+ arrayBuffers.push(copyToArrayBuffer(chunk));
917
+ }
918
+ return concatenateArrayBuffers(...arrayBuffers);
919
+ }
920
+ function copyToArrayBuffer(chunk) {
921
+ if (chunk instanceof ArrayBuffer) {
922
+ return chunk;
923
+ }
924
+ if (ArrayBuffer.isView(chunk)) {
925
+ const { buffer, byteOffset, byteLength } = chunk;
926
+ return copyFromBuffer(buffer, byteOffset, byteLength);
927
+ }
928
+ return copyFromBuffer(chunk);
929
+ }
930
+ function copyFromBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
931
+ const view = new Uint8Array(buffer, byteOffset, byteLength);
932
+ const copy = new Uint8Array(view.length);
933
+ copy.set(view);
934
+ return copy.buffer;
935
+ }
936
+ var init_async_iteration = __esm({
937
+ "../loader-utils/src/lib/iterators/async-iteration.ts"() {
938
+ "use strict";
939
+ init_array_buffer_utils();
940
+ }
941
+ });
942
+
943
+ // ../loader-utils/src/lib/path-utils/file-aliases.ts
944
+ function resolvePath(filename) {
945
+ for (const alias in fileAliases) {
946
+ if (filename.startsWith(alias)) {
947
+ const replacement = fileAliases[alias];
948
+ filename = filename.replace(alias, replacement);
949
+ }
950
+ }
951
+ if (!filename.startsWith("http://") && !filename.startsWith("https://")) {
952
+ filename = `${pathPrefix}${filename}`;
953
+ }
954
+ return filename;
955
+ }
956
+ var pathPrefix, fileAliases;
957
+ var init_file_aliases = __esm({
958
+ "../loader-utils/src/lib/path-utils/file-aliases.ts"() {
959
+ "use strict";
960
+ pathPrefix = "";
961
+ fileAliases = {};
962
+ }
963
+ });
964
+
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
+ // ../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
+ function ensureArrayBuffer(bufferSource) {
1007
+ if (bufferSource instanceof ArrayBuffer) {
1008
+ return bufferSource;
1009
+ }
1010
+ if (isSharedArrayBuffer(bufferSource)) {
1011
+ return copyToArrayBuffer2(bufferSource);
1012
+ }
1013
+ const { buffer, byteOffset, byteLength } = bufferSource;
1014
+ if (buffer instanceof ArrayBuffer && byteOffset === 0 && byteLength === buffer.byteLength) {
1015
+ return buffer;
1016
+ }
1017
+ return copyToArrayBuffer2(buffer, byteOffset, byteLength);
1018
+ }
1019
+ function copyToArrayBuffer2(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
1020
+ const view = new Uint8Array(buffer, byteOffset, byteLength);
1021
+ const copy = new Uint8Array(view.length);
1022
+ copy.set(view);
1023
+ return copy.buffer;
1024
+ }
1025
+ var init_memory_conversion_utils = __esm({
1026
+ "../loader-utils/src/lib/binary-utils/memory-conversion-utils.ts"() {
1027
+ "use strict";
1028
+ 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
+ }
1043
+ });
1044
+
1045
+ // ../loader-utils/src/lib/sources/data-source.ts
1046
+ 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);
1057
+ }
1058
+ function mergeFetchOptions(fetchOptions, requestOptions) {
1059
+ const mergedOptions = { ...fetchOptions, ...requestOptions };
1060
+ if (fetchOptions.headers || (requestOptions == null ? void 0 : requestOptions.headers)) {
1061
+ mergedOptions.headers = mergeHeaders(fetchOptions.headers, requestOptions == null ? void 0 : requestOptions.headers);
1062
+ }
1063
+ return mergedOptions;
1064
+ }
1065
+ function mergeHeaders(defaultHeaders, requestHeaders) {
1066
+ const headers = new Headers(defaultHeaders);
1067
+ if (requestHeaders) {
1068
+ new Headers(requestHeaders).forEach((value, key) => headers.set(key, value));
1069
+ }
1070
+ return headers;
1071
+ }
1072
+ function normalizeDirectLoaderOptions(options) {
1073
+ const loadOptions = { ...options };
1074
+ if (options == null ? void 0 : options.core) {
1075
+ loadOptions.core = { ...options.core };
1076
+ }
1077
+ const topLevelBaseUri = typeof loadOptions.baseUri === "string" ? loadOptions.baseUri : void 0;
1078
+ const topLevelBaseUrl = typeof loadOptions.baseUrl === "string" ? loadOptions.baseUrl : void 0;
1079
+ if (topLevelBaseUri !== void 0 || topLevelBaseUrl !== void 0) {
1080
+ loadOptions.core ||= {};
1081
+ if (loadOptions.core.baseUrl === void 0) {
1082
+ loadOptions.core.baseUrl = topLevelBaseUrl ?? topLevelBaseUri;
1083
+ }
1084
+ delete loadOptions.baseUri;
1085
+ delete loadOptions.baseUrl;
1086
+ }
1087
+ return loadOptions;
1088
+ }
1089
+ function normalizeError(error, message) {
1090
+ if (error instanceof Error) {
1091
+ return error;
1092
+ }
1093
+ if (typeof error === "string") {
1094
+ return new Error(error);
1095
+ }
1096
+ return new Error(message);
1097
+ }
1098
+ function unavailableCoreApiMethod(methodName) {
1099
+ return () => {
1100
+ throw new Error(
1101
+ `CoreAPI.${methodName} is unavailable. Use @loaders.gl/core.createDataSource().`
1102
+ );
1103
+ };
1104
+ }
1105
+ var UNAVAILABLE_CORE_API, DataSource;
1106
+ var init_data_source = __esm({
1107
+ "../loader-utils/src/lib/sources/data-source.ts"() {
1108
+ "use strict";
1109
+ init_merge_options();
1110
+ init_file_aliases();
1111
+ init_log();
1112
+ UNAVAILABLE_CORE_API = {
1113
+ fetchFile: unavailableCoreApiMethod("fetchFile"),
1114
+ parse: unavailableCoreApiMethod("parse"),
1115
+ parseFile: unavailableCoreApiMethod("parseFile"),
1116
+ parseSync: unavailableCoreApiMethod("parseSync"),
1117
+ parseInBatches: unavailableCoreApiMethod("parseInBatches"),
1118
+ load: unavailableCoreApiMethod("load"),
1119
+ loadInBatches: unavailableCoreApiMethod("loadInBatches")
1120
+ };
1121
+ DataSource = class _DataSource {
1122
+ static defaultOptions = {
1123
+ core: {
1124
+ type: "auto",
1125
+ attributions: [],
1126
+ loadOptions: {},
1127
+ loaders: [],
1128
+ onError: void 0
1129
+ }
1130
+ };
1131
+ optionsType;
1132
+ options;
1133
+ data;
1134
+ url;
1135
+ /** The actual load options, if calling a loaders.gl loader */
1136
+ loadOptions;
1137
+ /** A resolved fetch function extracted from loadOptions prop */
1138
+ fetch;
1139
+ /** Shared source-level runtime hooks, when supplied by the source factory. */
1140
+ coreApi;
1141
+ /** Whether a real CoreAPI instance was injected by the integration layer. */
1142
+ hasCoreApi;
1143
+ _needsRefresh = true;
1144
+ constructor(data, options, defaultOptions, coreApi) {
1145
+ var _a;
1146
+ if (defaultOptions) {
1147
+ this.options = mergeOptions({ ...defaultOptions, core: _DataSource.defaultOptions }, options);
1148
+ } else {
1149
+ this.options = { ...options };
1150
+ }
1151
+ this.data = data;
1152
+ this.url = typeof data === "string" ? resolvePath(data) : "";
1153
+ const loadOptions = normalizeDirectLoaderOptions((_a = this.options.core) == null ? void 0 : _a.loadOptions);
1154
+ this.loadOptions = loadOptions;
1155
+ const fetch2 = getFetchFunction(loadOptions);
1156
+ this.coreApi = coreApi || UNAVAILABLE_CORE_API;
1157
+ this.hasCoreApi = Boolean(coreApi);
1158
+ this.fetch = fetch2;
1159
+ }
1160
+ setProps(options) {
1161
+ this.options = Object.assign(this.options, options);
1162
+ this.setNeedsRefresh();
1163
+ }
1164
+ /** Mark this data source as needing a refresh (redraw) */
1165
+ setNeedsRefresh() {
1166
+ this._needsRefresh = true;
1167
+ }
1168
+ /**
1169
+ * Does this data source need refreshing?
1170
+ * @note The specifics of the refresh mechanism depends on type of data source
1171
+ */
1172
+ getNeedsRefresh(clear = true) {
1173
+ const needsRefresh = this._needsRefresh;
1174
+ if (clear) {
1175
+ this._needsRefresh = false;
1176
+ }
1177
+ return needsRefresh;
1178
+ }
1179
+ /** Reports a source-level failure through the configured callback or the shared logger. */
1180
+ reportError(error, message) {
1181
+ var _a;
1182
+ const normalizedError = normalizeError(error, message);
1183
+ const callback = (_a = this.options.core) == null ? void 0 : _a.onError;
1184
+ if (callback) {
1185
+ callback(normalizedError, this);
1186
+ } else {
1187
+ log.warn(`${this.constructor.name}: ${normalizedError.message}`)();
1188
+ }
1189
+ return normalizedError;
1190
+ }
1191
+ };
1192
+ }
1193
+ });
1194
+
1195
+ // ../loader-utils/src/index.ts
1196
+ var init_src = __esm({
1197
+ "../loader-utils/src/index.ts"() {
1198
+ "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();
1206
+ }
1207
+ });
1208
+
1209
+ // ../compression/src/lib/compression.ts
1210
+ var Compression;
1211
+ var init_compression = __esm({
1212
+ "../compression/src/lib/compression.ts"() {
1213
+ "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);
1219
+ }
1220
+ /** Preloads any dynamic libraries. May enable sync functions */
1221
+ async preload(modules = {}) {
1222
+ registerJSModules(modules);
1223
+ return;
1224
+ }
1225
+ /** Asynchronously compress data */
1226
+ async compress(input) {
1227
+ await this.preload();
1228
+ return this.compressSync(input);
1229
+ }
1230
+ /** Asynchronously decompress data */
1231
+ 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`);
1238
+ }
1239
+ /** Synchronously compress data */
1240
+ 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);
1247
+ }
1248
+ /** Decompress batches */
1249
+ async *decompressBatches(asyncIterator) {
1250
+ const input = await this.concatenate(asyncIterator);
1251
+ yield this.decompress(input);
1252
+ }
1253
+ // HELPERS
1254
+ concatenate(asyncIterator) {
1255
+ return concatenateArrayBuffersAsync(asyncIterator);
1256
+ }
1257
+ improveError(error) {
1258
+ if (!error.message.includes(this.name)) {
1259
+ error.message = `${this.name} ${error.message}`;
1260
+ }
1261
+ return error;
1262
+ }
1263
+ };
1264
+ }
1265
+ });
1266
+
1267
+ // ../compression/src/lib/zstd-compression.ts
1268
+ var CHUNK_SIZE, zstdPromise, zstd, ZstdCompression;
1269
+ var init_zstd_compression = __esm({
1270
+ "../compression/src/lib/zstd-compression.ts"() {
1271
+ "use strict";
1272
+ init_compression();
1273
+ init_src();
1274
+ CHUNK_SIZE = 1e6;
1275
+ ZstdCompression = class extends Compression {
1276
+ name = "zstd";
1277
+ extensions = [];
1278
+ contentEncodings = [];
1279
+ isSupported = true;
1280
+ options;
1281
+ /**
1282
+ * zstd-codec is an injectable dependency due to big size
1283
+ * @param options
1284
+ */
1285
+ constructor(options = {}) {
1286
+ super(options);
1287
+ this.options = options;
1288
+ registerJSModules(options == null ? void 0 : options.modules);
1289
+ }
1290
+ async preload(modules = {}) {
1291
+ registerJSModules(modules);
1292
+ const ZstdCodec = getJSModuleOrNull("zstd-codec");
1293
+ if (!zstdPromise && ZstdCodec) {
1294
+ zstdPromise = new Promise((resolve) => ZstdCodec.run((zstd2) => resolve(zstd2)));
1295
+ }
1296
+ if (zstdPromise) {
1297
+ zstd = await zstdPromise;
1298
+ }
1299
+ }
1300
+ compressSync(input) {
1301
+ getJSModule("zstd-codec", this.name);
1302
+ const simpleZstd = new zstd.Simple();
1303
+ const inputArray = new Uint8Array(input);
1304
+ return simpleZstd.compress(inputArray).buffer;
1305
+ }
1306
+ decompressSync(input) {
1307
+ getJSModule("zstd-codec", this.name);
1308
+ const simpleZstd = new zstd.Simple();
1309
+ const inputArray = new Uint8Array(input);
1310
+ return simpleZstd.decompress(inputArray).buffer;
1311
+ }
1312
+ async decompress(input, size) {
1313
+ await this.preload();
1314
+ const inputArray = new Uint8Array(input);
1315
+ if (!zstd) {
1316
+ const { decompress } = await import("fzstd");
1317
+ return ensureArrayBuffer(decompress(inputArray));
1318
+ }
1319
+ const simpleZstd = new zstd.Streaming();
1320
+ const chunks = [];
1321
+ for (let i = 0; i <= inputArray.length; i += CHUNK_SIZE) {
1322
+ const chunkView = inputArray.subarray(i, i + CHUNK_SIZE);
1323
+ const chunkArrayBuffer = ensureArrayBuffer(chunkView);
1324
+ chunks.push(new Uint8Array(chunkArrayBuffer));
1325
+ }
1326
+ const decompressResult = await simpleZstd.decompressChunks(chunks);
1327
+ return decompressResult.buffer;
1328
+ }
1329
+ };
1330
+ }
1331
+ });
1332
+
1333
+ // ../compression/src/zstd-compression.ts
1334
+ var zstd_compression_exports = {};
1335
+ __export(zstd_compression_exports, {
1336
+ ZstdCompression: () => ZstdCompression
1337
+ });
1338
+ var init_zstd_compression2 = __esm({
1339
+ "../compression/src/zstd-compression.ts"() {
1340
+ "use strict";
1341
+ init_zstd_compression();
1342
+ }
1343
+ });
1344
+
675
1345
  // dist/lib/parse-spz.js
676
1346
  async function parseSPZ(data, options) {
677
1347
  return makeGaussianSplatsArrowTable(await parseSPZToGaussianSplats(data, options));
@@ -680,11 +1350,30 @@ async function parseSPZToGaussianSplats(data, options) {
680
1350
  const header = parseSPZHeader(data);
681
1351
  const streamInfos = parseSPZStreamInfos(data, header, getSPZStreamByteLengths(header));
682
1352
  const compressedStreams = streamInfos.map((streamInfo) => data.slice(streamInfo.compressedOffset, streamInfo.compressedOffset + streamInfo.compressedSize));
683
- const compression = new import_compression.ZstdCompression({ modules: options == null ? void 0 : options.modules });
684
- const streams = await Promise.all(compressedStreams.map((compressedStream, streamIndex) => compression.decompress(compressedStream, streamInfos[streamIndex].uncompressedSize)));
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
+ })));
685
1360
  validateSPZStreamLengths(streams, streamInfos);
686
1361
  return decodeSPZStreams(header, streams, data);
687
1362
  }
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
+ }
688
1377
  function parseSPZHeader(data) {
689
1378
  if (data.byteLength < SPZ_HEADER_BYTE_LENGTH) {
690
1379
  throw new Error(`SPZLoader: file must contain a ${SPZ_HEADER_BYTE_LENGTH}-byte header.`);
@@ -827,12 +1516,12 @@ function decodeSPZRotations(rotationStream, rotations) {
827
1516
  const byteOffset = splatIndex * 4;
828
1517
  const component = rotationStream[byteOffset] | rotationStream[byteOffset + 1] << 8 | rotationStream[byteOffset + 2] << 16 | rotationStream[byteOffset + 3] << 24;
829
1518
  const xyzw = decodeSPZQuaternion(component >>> 0);
830
- const [w, x, y, z] = normalizeQuaternion(xyzw[3], xyzw[0], xyzw[1], xyzw[2]);
1519
+ const [w, x, y, z2] = normalizeQuaternion(xyzw[3], xyzw[0], xyzw[1], xyzw[2]);
831
1520
  const rotationOffset = splatIndex * 4;
832
1521
  rotations[rotationOffset + 0] = w;
833
1522
  rotations[rotationOffset + 1] = x;
834
1523
  rotations[rotationOffset + 2] = y;
835
- rotations[rotationOffset + 3] = z;
1524
+ rotations[rotationOffset + 3] = z2;
836
1525
  }
837
1526
  }
838
1527
  function decodeSPZQuaternion(component) {
@@ -898,11 +1587,12 @@ function getSPZExtensionBytes(data, header) {
898
1587
  const extensionByteLength = getSPZExtensionByteLength(header);
899
1588
  return extensionByteLength ? new Uint8Array(data.slice(SPZ_HEADER_BYTE_LENGTH, header.tocByteOffset)) : void 0;
900
1589
  }
901
- var import_compression, SPZ_HEADER_BYTE_LENGTH, SPZ_MAGIC, SPZ_VERSION, SPZ_EXTENSION_FLAG, SPZ_COLOR_SCALE, SPZ_ROTATION_COMPONENT_SCALE, SPZ_ROTATION_COMPONENT_MASK;
1590
+ var SPZ_HEADER_BYTE_LENGTH, SPZ_MAGIC, SPZ_VERSION, SPZ_EXTENSION_FLAG, SPZ_COLOR_SCALE, SPZ_ROTATION_COMPONENT_SCALE, SPZ_ROTATION_COMPONENT_MASK;
902
1591
  var init_parse_spz = __esm({
903
1592
  "dist/lib/parse-spz.js"() {
904
1593
  "use strict";
905
- import_compression = require("@loaders.gl/compression");
1594
+ init_native_decompression();
1595
+ init_src();
906
1596
  init_splats_arrow_table();
907
1597
  init_splat_utils();
908
1598
  SPZ_HEADER_BYTE_LENGTH = 32;
@@ -939,17 +1629,17 @@ async function preload3() {
939
1629
  const { SPZLoaderWithParser: SPZLoaderWithParser2 } = await Promise.resolve().then(() => (init_spz_loader(), spz_loader_exports));
940
1630
  return SPZLoaderWithParser2;
941
1631
  }
942
- var VERSION3, SPZLoader;
1632
+ var VERSION4, SPZLoader;
943
1633
  var init_spz_loader_types = __esm({
944
1634
  "dist/spz-loader-types.js"() {
945
1635
  "use strict";
946
1636
  init_splats_format();
947
- VERSION3 = true ? "5.0.0-alpha.1" : "latest";
1637
+ VERSION4 = true ? "5.0.0-alpha.2" : "latest";
948
1638
  SPZLoader = {
949
1639
  dataType: null,
950
1640
  batchType: null,
951
1641
  ...SPZFormat,
952
- version: VERSION3,
1642
+ version: VERSION4,
953
1643
  options: {
954
1644
  splats: {
955
1645
  shape: "arrow-table"
@@ -960,6 +1650,65 @@ var init_spz_loader_types = __esm({
960
1650
  }
961
1651
  });
962
1652
 
1653
+ // dist/rad-zod-schema.js
1654
+ var import_zod, nonNegativeSafeIntegerSchema, RADSplatEncodingSchema, RADChunkRangeSchema, RADMetadataJSONSchema, RADChunkPropertySchema, RADChunkMetadataJSONSchema;
1655
+ var init_rad_zod_schema = __esm({
1656
+ "dist/rad-zod-schema.js"() {
1657
+ "use strict";
1658
+ import_zod = require("zod");
1659
+ nonNegativeSafeIntegerSchema = import_zod.z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
1660
+ RADSplatEncodingSchema = import_zod.z.object({
1661
+ rgbMin: import_zod.z.number().finite().optional(),
1662
+ rgbMax: import_zod.z.number().finite().optional(),
1663
+ lnScaleMin: import_zod.z.number().finite().optional(),
1664
+ lnScaleMax: import_zod.z.number().finite().optional(),
1665
+ sh1Max: import_zod.z.number().finite().optional(),
1666
+ sh2Max: import_zod.z.number().finite().optional(),
1667
+ sh3Max: import_zod.z.number().finite().optional(),
1668
+ lodOpacity: import_zod.z.boolean().optional()
1669
+ }).passthrough();
1670
+ RADChunkRangeSchema = import_zod.z.object({
1671
+ offset: nonNegativeSafeIntegerSchema,
1672
+ bytes: nonNegativeSafeIntegerSchema,
1673
+ base: nonNegativeSafeIntegerSchema.optional(),
1674
+ count: nonNegativeSafeIntegerSchema.optional(),
1675
+ filename: import_zod.z.string().optional()
1676
+ }).passthrough();
1677
+ RADMetadataJSONSchema = import_zod.z.object({
1678
+ version: import_zod.z.literal(1),
1679
+ type: import_zod.z.literal("gsplat"),
1680
+ count: nonNegativeSafeIntegerSchema,
1681
+ maxSh: nonNegativeSafeIntegerSchema.optional(),
1682
+ lodTree: import_zod.z.boolean().optional(),
1683
+ chunkSize: nonNegativeSafeIntegerSchema.optional(),
1684
+ allChunkBytes: nonNegativeSafeIntegerSchema.optional(),
1685
+ chunks: import_zod.z.array(RADChunkRangeSchema),
1686
+ splatEncoding: RADSplatEncodingSchema.optional(),
1687
+ shCodeCount: nonNegativeSafeIntegerSchema.optional(),
1688
+ comment: import_zod.z.string().optional()
1689
+ }).passthrough();
1690
+ RADChunkPropertySchema = import_zod.z.object({
1691
+ offset: nonNegativeSafeIntegerSchema,
1692
+ bytes: nonNegativeSafeIntegerSchema,
1693
+ property: import_zod.z.string(),
1694
+ encoding: import_zod.z.string(),
1695
+ compression: import_zod.z.string().optional(),
1696
+ min: import_zod.z.number().finite().optional(),
1697
+ max: import_zod.z.number().finite().optional()
1698
+ }).passthrough();
1699
+ RADChunkMetadataJSONSchema = import_zod.z.object({
1700
+ version: import_zod.z.literal(1),
1701
+ base: nonNegativeSafeIntegerSchema,
1702
+ count: nonNegativeSafeIntegerSchema,
1703
+ payloadBytes: nonNegativeSafeIntegerSchema,
1704
+ maxSh: nonNegativeSafeIntegerSchema.optional(),
1705
+ lodTree: import_zod.z.boolean().optional(),
1706
+ splatEncoding: RADSplatEncodingSchema.optional(),
1707
+ properties: import_zod.z.array(RADChunkPropertySchema)
1708
+ }).passthrough();
1709
+ }
1710
+ });
1711
+
963
1712
  // dist/lib/parse-rad.js
964
1713
  function parseRADHeader(data) {
965
1714
  const metadata = tryParseRADHeader(data);
@@ -983,7 +1732,7 @@ function tryParseRADHeader(data) {
983
1732
  if (bytes.byteLength < headerJsonEnd) {
984
1733
  return null;
985
1734
  }
986
- const rawMetadata = parseJSONRecord(bytes.subarray(RAD_HEADER_BYTE_LENGTH, headerJsonEnd), "RADLoader: failed to parse RAD metadata JSON.");
1735
+ const rawMetadata = RADMetadataJSONSchema.parse(parseJSON(bytes.subarray(RAD_HEADER_BYTE_LENGTH, headerJsonEnd), "RADLoader: failed to parse RAD metadata JSON."));
987
1736
  return normalizeRADMetadata(rawMetadata, headerJsonByteLength);
988
1737
  }
989
1738
  function parseRADChunkHeader(data) {
@@ -1003,7 +1752,7 @@ function parseRADChunkHeader(data) {
1003
1752
  if (bytes.byteLength < payloadByteOffset) {
1004
1753
  throw new Error("RADLoader: RADC chunk must contain a complete metadata header.");
1005
1754
  }
1006
- const rawMetadata = parseJSONRecord(bytes.subarray(RAD_HEADER_BYTE_LENGTH, headerJsonEnd), "RADLoader: failed to parse RADC metadata JSON.");
1755
+ const rawMetadata = RADChunkMetadataJSONSchema.parse(parseJSON(bytes.subarray(RAD_HEADER_BYTE_LENGTH, headerJsonEnd), "RADLoader: failed to parse RADC metadata JSON."));
1007
1756
  const payloadBytes = readSafeUint642(dataView, payloadByteLengthOffset, "RADC payload byte length");
1008
1757
  return normalizeRADChunkMetadata(rawMetadata, headerJsonByteLength, payloadByteOffset, payloadBytes);
1009
1758
  }
@@ -1011,157 +1760,31 @@ function roundUpToEight(byteLength) {
1011
1760
  return byteLength + 7 & ~7;
1012
1761
  }
1013
1762
  function normalizeRADMetadata(rawMetadata, headerJsonByteLength) {
1014
- const version = requireSafeInteger(rawMetadata.version, "RAD version");
1015
- if (version !== 1) {
1016
- throw new Error(`RADLoader: version ${version} is not supported.`);
1017
- }
1018
- const type = requireString(rawMetadata.type, "RAD type");
1019
- if (type !== "gsplat") {
1020
- throw new Error(`RADLoader: RAD type ${type} is not supported.`);
1021
- }
1022
- const chunks = requireArray(rawMetadata.chunks, "RAD chunks").map((chunk, chunkIndex) => normalizeRADChunkRange(chunk, chunkIndex));
1023
- const metadata = {
1024
- version,
1025
- type,
1026
- count: requireSafeInteger(rawMetadata.count, "RAD count"),
1027
- maxSh: optionalSafeInteger(rawMetadata.maxSh, "RAD maxSh"),
1028
- lodTree: optionalBoolean(rawMetadata.lodTree, "RAD lodTree"),
1029
- chunkSize: optionalSafeInteger(rawMetadata.chunkSize, "RAD chunkSize"),
1030
- allChunkBytes: optionalSafeInteger(rawMetadata.allChunkBytes, "RAD allChunkBytes"),
1031
- chunks,
1032
- splatEncoding: optionalSplatEncoding(rawMetadata.splatEncoding, "RAD splatEncoding"),
1033
- shCodeCount: optionalSafeInteger(rawMetadata.shCodeCount, "RAD shCodeCount"),
1034
- comment: optionalString(rawMetadata.comment, "RAD comment"),
1763
+ return {
1764
+ ...rawMetadata,
1035
1765
  headerJsonByteLength,
1036
1766
  chunksByteOffset: RAD_HEADER_BYTE_LENGTH + roundUpToEight(headerJsonByteLength)
1037
1767
  };
1038
- return metadata;
1039
- }
1040
- function normalizeRADChunkRange(rawChunk, chunkIndex) {
1041
- const chunk = requireRecord(rawChunk, `RAD chunk ${chunkIndex}`);
1042
- return {
1043
- offset: requireSafeInteger(chunk.offset, `RAD chunk ${chunkIndex} offset`),
1044
- bytes: requireSafeInteger(chunk.bytes, `RAD chunk ${chunkIndex} bytes`),
1045
- base: optionalSafeInteger(chunk.base, `RAD chunk ${chunkIndex} base`),
1046
- count: optionalSafeInteger(chunk.count, `RAD chunk ${chunkIndex} count`),
1047
- filename: optionalString(chunk.filename, `RAD chunk ${chunkIndex} filename`)
1048
- };
1049
1768
  }
1050
1769
  function normalizeRADChunkMetadata(rawMetadata, headerJsonByteLength, payloadByteOffset, payloadBytes) {
1051
- const version = requireSafeInteger(rawMetadata.version, "RADC version");
1052
- if (version !== 1) {
1053
- throw new Error(`RADLoader: RADC version ${version} is not supported.`);
1054
- }
1055
- const metadataPayloadBytes = requireSafeInteger(rawMetadata.payloadBytes, "RADC payloadBytes");
1056
- if (metadataPayloadBytes !== payloadBytes) {
1770
+ if (rawMetadata.payloadBytes !== payloadBytes) {
1057
1771
  throw new Error("RADLoader: RADC metadata payload byte length does not match binary header.");
1058
1772
  }
1059
1773
  return {
1060
- version,
1061
- base: requireSafeInteger(rawMetadata.base, "RADC base"),
1062
- count: requireSafeInteger(rawMetadata.count, "RADC count"),
1774
+ ...rawMetadata,
1063
1775
  payloadBytes,
1064
- maxSh: optionalSafeInteger(rawMetadata.maxSh, "RADC maxSh"),
1065
- lodTree: optionalBoolean(rawMetadata.lodTree, "RADC lodTree"),
1066
- splatEncoding: optionalSplatEncoding(rawMetadata.splatEncoding, "RADC splatEncoding"),
1067
- properties: requireArray(rawMetadata.properties, "RADC properties").map((property, index) => normalizeRADChunkProperty(property, index)),
1068
1776
  headerJsonByteLength,
1069
1777
  payloadByteOffset,
1070
1778
  chunkByteLength: payloadByteOffset + payloadBytes
1071
1779
  };
1072
1780
  }
1073
- function normalizeRADChunkProperty(rawProperty, propertyIndex) {
1074
- const property = requireRecord(rawProperty, `RADC property ${propertyIndex}`);
1075
- return {
1076
- offset: requireSafeInteger(property.offset, `RADC property ${propertyIndex} offset`),
1077
- bytes: requireSafeInteger(property.bytes, `RADC property ${propertyIndex} bytes`),
1078
- property: requireString(property.property, `RADC property ${propertyIndex} name`),
1079
- encoding: requireString(property.encoding, `RADC property ${propertyIndex} encoding`),
1080
- compression: optionalString(property.compression, `RADC property ${propertyIndex} compression`),
1081
- min: optionalFiniteNumber(property.min, `RADC property ${propertyIndex} min`),
1082
- max: optionalFiniteNumber(property.max, `RADC property ${propertyIndex} max`)
1083
- };
1084
- }
1085
- function optionalSplatEncoding(value, fieldName) {
1086
- if (value === void 0) {
1087
- return void 0;
1088
- }
1089
- const encoding = requireRecord(value, fieldName);
1090
- return {
1091
- rgbMin: optionalFiniteNumber(encoding.rgbMin, `${fieldName}.rgbMin`),
1092
- rgbMax: optionalFiniteNumber(encoding.rgbMax, `${fieldName}.rgbMax`),
1093
- lnScaleMin: optionalFiniteNumber(encoding.lnScaleMin, `${fieldName}.lnScaleMin`),
1094
- lnScaleMax: optionalFiniteNumber(encoding.lnScaleMax, `${fieldName}.lnScaleMax`),
1095
- sh1Max: optionalFiniteNumber(encoding.sh1Max, `${fieldName}.sh1Max`),
1096
- sh2Max: optionalFiniteNumber(encoding.sh2Max, `${fieldName}.sh2Max`),
1097
- sh3Max: optionalFiniteNumber(encoding.sh3Max, `${fieldName}.sh3Max`),
1098
- lodOpacity: optionalBoolean(encoding.lodOpacity, `${fieldName}.lodOpacity`)
1099
- };
1100
- }
1101
- function parseJSONRecord(bytes, message) {
1781
+ function parseJSON(bytes, message) {
1102
1782
  try {
1103
- return requireRecord(JSON.parse(TEXT_DECODER.decode(bytes)), message);
1104
- } catch (error) {
1105
- if (error instanceof Error && error.message.startsWith("RADLoader:")) {
1106
- throw error;
1107
- }
1783
+ return JSON.parse(TEXT_DECODER.decode(bytes));
1784
+ } catch {
1108
1785
  throw new Error(message);
1109
1786
  }
1110
1787
  }
1111
- function requireRecord(value, fieldName) {
1112
- if (!value || typeof value !== "object" || Array.isArray(value)) {
1113
- throw new Error(`RADLoader: ${fieldName} must be an object.`);
1114
- }
1115
- return value;
1116
- }
1117
- function requireArray(value, fieldName) {
1118
- if (!Array.isArray(value)) {
1119
- throw new Error(`RADLoader: ${fieldName} must be an array.`);
1120
- }
1121
- return value;
1122
- }
1123
- function requireString(value, fieldName) {
1124
- if (typeof value !== "string") {
1125
- throw new Error(`RADLoader: ${fieldName} must be a string.`);
1126
- }
1127
- return value;
1128
- }
1129
- function optionalString(value, fieldName) {
1130
- if (value === void 0) {
1131
- return void 0;
1132
- }
1133
- return requireString(value, fieldName);
1134
- }
1135
- function optionalBoolean(value, fieldName) {
1136
- if (value === void 0) {
1137
- return void 0;
1138
- }
1139
- if (typeof value !== "boolean") {
1140
- throw new Error(`RADLoader: ${fieldName} must be a boolean.`);
1141
- }
1142
- return value;
1143
- }
1144
- function requireSafeInteger(value, fieldName) {
1145
- if (!Number.isSafeInteger(value) || Number(value) < 0) {
1146
- throw new Error(`RADLoader: ${fieldName} must be a non-negative safe integer.`);
1147
- }
1148
- return Number(value);
1149
- }
1150
- function optionalSafeInteger(value, fieldName) {
1151
- if (value === void 0) {
1152
- return void 0;
1153
- }
1154
- return requireSafeInteger(value, fieldName);
1155
- }
1156
- function optionalFiniteNumber(value, fieldName) {
1157
- if (value === void 0) {
1158
- return void 0;
1159
- }
1160
- if (typeof value !== "number" || !Number.isFinite(value)) {
1161
- throw new Error(`RADLoader: ${fieldName} must be a finite number.`);
1162
- }
1163
- return value;
1164
- }
1165
1788
  function readSafeUint642(dataView, byteOffset, fieldName) {
1166
1789
  const value = dataView.getBigUint64(byteOffset, true);
1167
1790
  if (value > BigInt(Number.MAX_SAFE_INTEGER)) {
@@ -1176,6 +1799,7 @@ var RAD_MAGIC, RAD_CHUNK_MAGIC, RAD_HEADER_BYTE_LENGTH, RAD_CHUNK_PAYLOAD_LENGTH
1176
1799
  var init_parse_rad = __esm({
1177
1800
  "dist/lib/parse-rad.js"() {
1178
1801
  "use strict";
1802
+ init_rad_zod_schema();
1179
1803
  RAD_MAGIC = 809779538;
1180
1804
  RAD_CHUNK_MAGIC = 1128546642;
1181
1805
  RAD_HEADER_BYTE_LENGTH = 8;
@@ -1184,6 +1808,144 @@ var init_parse_rad = __esm({
1184
1808
  }
1185
1809
  });
1186
1810
 
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"() {
1815
+ "use strict";
1816
+ init_compression();
1817
+ init_src();
1818
+ import_pako = __toESM(require("pako"), 1);
1819
+ import_zlib = __toESM(require("zlib"), 1);
1820
+ DeflateCompression = class extends Compression {
1821
+ name = "deflate";
1822
+ extensions = [];
1823
+ contentEncodings = ["deflate"];
1824
+ isSupported = true;
1825
+ options;
1826
+ _chunks = [];
1827
+ constructor(options = {}) {
1828
+ super(options);
1829
+ this.options = options;
1830
+ }
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
+ }
1858
+ 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);
1868
+ }
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);
1874
+ }
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);
1880
+ }
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) {
1896
+ }
1897
+ const chunks = this._getChunks();
1898
+ yield* chunks;
1899
+ }
1900
+ _onData(chunk) {
1901
+ this._chunks.push(chunk);
1902
+ }
1903
+ _onEnd(status) {
1904
+ if (status !== 0) {
1905
+ throw new Error(this._getError(status) + this._chunks.length);
1906
+ }
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]}`;
1936
+ }
1937
+ };
1938
+ }
1939
+ });
1940
+
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
+
1187
1949
  // dist/lib/parse-rad-chunk.js
1188
1950
  function parseRADChunk(data, options) {
1189
1951
  return makeGaussianSplatsArrowTable(parseRADChunkToGaussianSplats(data, options));
@@ -1281,9 +2043,9 @@ function decodeRADRotations(bytes, metadata, splatCount) {
1281
2043
  const rotationOffset = splatIndex * 4;
1282
2044
  const x = xyz[xyzOffset + 0];
1283
2045
  const y = xyz[xyzOffset + 1];
1284
- const z = xyz[xyzOffset + 2];
1285
- const w = Math.sqrt(Math.max(0, 1 - x * x - y * y - z * z));
1286
- const normalized = normalizeQuaternion(w, x, y, z);
2046
+ const z2 = xyz[xyzOffset + 2];
2047
+ const w = Math.sqrt(Math.max(0, 1 - x * x - y * y - z2 * z2));
2048
+ const normalized = normalizeQuaternion(w, x, y, z2);
1287
2049
  rotations.set(normalized, rotationOffset);
1288
2050
  }
1289
2051
  return rotations;
@@ -1392,7 +2154,7 @@ function getRADPropertyBytes(bytes, metadata, property) {
1392
2154
  return decompressRADProperty(propertyBytes, property.property);
1393
2155
  }
1394
2156
  function decompressRADProperty(bytes, propertyName) {
1395
- const arrayBuffer = copyToArrayBuffer(bytes);
2157
+ const arrayBuffer = copyToArrayBuffer3(bytes);
1396
2158
  try {
1397
2159
  return new Uint8Array(RAD_PROPERTY_DEFLATE.decompressSync(arrayBuffer));
1398
2160
  } catch {
@@ -1517,8 +2279,8 @@ function decodeRADOct88R8Rotations(bytes, count) {
1517
2279
  const rotations = new Float32Array(count * 4);
1518
2280
  for (let splatIndex = 0; splatIndex < count; splatIndex++) {
1519
2281
  const byteOffset = splatIndex * 3;
1520
- const [x, y, z, w] = decodeQuatOct888(bytes[byteOffset], bytes[byteOffset + 1], bytes[byteOffset + 2]);
1521
- rotations.set(normalizeQuaternion(w, x, y, z), splatIndex * 4);
2282
+ const [x, y, z2, w] = decodeQuatOct888(bytes[byteOffset], bytes[byteOffset + 1], bytes[byteOffset + 2]);
2283
+ rotations.set(normalizeQuaternion(w, x, y, z2), splatIndex * 4);
1522
2284
  }
1523
2285
  return rotations;
1524
2286
  }
@@ -1549,14 +2311,14 @@ function decodeScale8(scale, min, max) {
1549
2311
  function decodeQuatOct888(u, v, r) {
1550
2312
  let x = u / 255 * 2 - 1;
1551
2313
  let y = v / 255 * 2 - 1;
1552
- const z = 1 - Math.abs(x) - Math.abs(y);
1553
- const t = Math.max(-z, 0);
2314
+ const z2 = 1 - Math.abs(x) - Math.abs(y);
2315
+ const t = Math.max(-z2, 0);
1554
2316
  x = x >= 0 ? x - t : x + t;
1555
2317
  y = y >= 0 ? y - t : y + t;
1556
- const length = Math.hypot(x, y, z);
2318
+ const length = Math.hypot(x, y, z2);
1557
2319
  const axisX = length > Number.EPSILON ? x / length : 1;
1558
2320
  const axisY = length > Number.EPSILON ? y / length : 0;
1559
- const axisZ = length > Number.EPSILON ? z / length : 0;
2321
+ const axisZ = length > Number.EPSILON ? z2 / length : 0;
1560
2322
  const halfTheta = r / 255 * 0.5 * Math.PI;
1561
2323
  const sinHalfTheta = Math.sin(halfTheta);
1562
2324
  return [axisX * sinHalfTheta, axisY * sinHalfTheta, axisZ * sinHalfTheta, Math.cos(halfTheta)];
@@ -1634,7 +2396,7 @@ function getSplatEncodingMaximum(splatEncoding, propertyName) {
1634
2396
  function normalizeColorByte2(value) {
1635
2397
  return Math.round(Math.min(Math.max(value, 0), 1) * 255);
1636
2398
  }
1637
- function copyToArrayBuffer(bytes) {
2399
+ function copyToArrayBuffer3(bytes) {
1638
2400
  const copy = new Uint8Array(bytes.byteLength);
1639
2401
  copy.set(bytes);
1640
2402
  return copy.buffer;
@@ -1642,16 +2404,16 @@ function copyToArrayBuffer(bytes) {
1642
2404
  function getUint8Array2(data) {
1643
2405
  return data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
1644
2406
  }
1645
- var import_compression2, RAD_PROPERTY_DEFLATE, RAD_PROPERTY_RAW_DEFLATE;
2407
+ var RAD_PROPERTY_DEFLATE, RAD_PROPERTY_RAW_DEFLATE;
1646
2408
  var init_parse_rad_chunk = __esm({
1647
2409
  "dist/lib/parse-rad-chunk.js"() {
1648
2410
  "use strict";
1649
- import_compression2 = require("@loaders.gl/compression");
2411
+ init_src2();
1650
2412
  init_parse_rad();
1651
2413
  init_splats_arrow_table();
1652
2414
  init_splat_utils();
1653
- RAD_PROPERTY_DEFLATE = new import_compression2.DeflateCompression();
1654
- RAD_PROPERTY_RAW_DEFLATE = new import_compression2.DeflateCompression({ raw: true });
2415
+ RAD_PROPERTY_DEFLATE = new DeflateCompression();
2416
+ RAD_PROPERTY_RAW_DEFLATE = new DeflateCompression({ raw: true });
1655
2417
  }
1656
2418
  });
1657
2419
 
@@ -1687,17 +2449,17 @@ async function preload4() {
1687
2449
  const { RADLoaderWithParser: RADLoaderWithParser2 } = await Promise.resolve().then(() => (init_rad_loader(), rad_loader_exports));
1688
2450
  return RADLoaderWithParser2;
1689
2451
  }
1690
- var VERSION4, RADLoader;
2452
+ var VERSION5, RADLoader;
1691
2453
  var init_rad_loader_types = __esm({
1692
2454
  "dist/rad-loader-types.js"() {
1693
2455
  "use strict";
1694
2456
  init_splats_format();
1695
- VERSION4 = true ? "5.0.0-alpha.1" : "latest";
2457
+ VERSION5 = true ? "5.0.0-alpha.2" : "latest";
1696
2458
  RADLoader = {
1697
2459
  dataType: null,
1698
2460
  batchType: null,
1699
2461
  ...RADFormat,
1700
- version: VERSION4,
2462
+ version: VERSION5,
1701
2463
  options: {},
1702
2464
  preload: preload4
1703
2465
  };
@@ -1705,8 +2467,8 @@ var init_rad_loader_types = __esm({
1705
2467
  });
1706
2468
 
1707
2469
  // dist/index.js
1708
- var dist_exports = {};
1709
- __export(dist_exports, {
2470
+ var index_exports = {};
2471
+ __export(index_exports, {
1710
2472
  KSPLATFormat: () => KSPLATFormat,
1711
2473
  KSPLATLoader: () => KSPLATLoader,
1712
2474
  RADFormat: () => RADFormat,
@@ -1719,7 +2481,7 @@ __export(dist_exports, {
1719
2481
  SPZLoader: () => SPZLoader,
1720
2482
  resolveRADChunkUrl: () => resolveRADChunkUrl
1721
2483
  });
1722
- module.exports = __toCommonJS(dist_exports);
2484
+ module.exports = __toCommonJS(index_exports);
1723
2485
  init_splats_format();
1724
2486
  init_splat_loader_types();
1725
2487
  init_ksplat_loader_types();
@@ -1727,20 +2489,20 @@ init_spz_loader_types();
1727
2489
  init_rad_loader_types();
1728
2490
 
1729
2491
  // dist/rad-source-loader.js
1730
- var import_loader_utils = require("@loaders.gl/loader-utils");
2492
+ init_src();
1731
2493
  init_splats_format();
1732
2494
  init_parse_rad();
1733
2495
  init_parse_rad_chunk();
1734
2496
  init_splats_arrow_table();
1735
2497
  var DEFAULT_RAD_HEADER_BYTE_LENGTHS = [64 * 1024, 256 * 1024, 1024 * 1024];
1736
2498
  var DEFAULT_RAD_MAX_CONCURRENT_CHUNK_REQUESTS = 4;
1737
- var VERSION5 = true ? "5.0.0-alpha.1" : "latest";
2499
+ var VERSION6 = true ? "5.0.0-alpha.2" : "latest";
1738
2500
  var RADSourceLoader = {
1739
2501
  dataType: null,
1740
2502
  batchType: null,
1741
2503
  ...RADFormat,
1742
2504
  name: "RADSourceLoader",
1743
- version: VERSION5,
2505
+ version: VERSION6,
1744
2506
  type: "rad",
1745
2507
  fromUrl: true,
1746
2508
  fromBlob: true,
@@ -1761,7 +2523,7 @@ var RADSourceLoader = {
1761
2523
  testURL: (url) => /\.rad(?:$|[?#])/i.test(url),
1762
2524
  createDataSource: (data, options, coreApi) => new RADSource(data, options, coreApi)
1763
2525
  };
1764
- var RADSource = class extends import_loader_utils.DataSource {
2526
+ var RADSource = class extends DataSource {
1765
2527
  /** Shared metadata promise exposed for source-style integrations. */
1766
2528
  metadata;
1767
2529
  /** Lazily initialized RAD header promise. */