@loaders.gl/splats 5.0.0-alpha.6 → 5.0.0-alpha.7

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
@@ -81,1894 +81,2045 @@ var init_splats_format = __esm({
81
81
  }
82
82
  });
83
83
 
84
- // dist/lib/splat-utils.js
85
- function convertColorByteToSphericalHarmonicDc(colorByte) {
86
- return (colorByte / 255 - 0.5) / SH_C0;
87
- }
88
- function convertAlphaByteToLinearOpacity(alphaByte) {
89
- return Math.min(Math.max(alphaByte / 255, 0), 1);
90
- }
91
- function normalizeQuaternion(w, x, y, z2) {
92
- const length = Math.hypot(w, x, y, z2);
93
- if (!Number.isFinite(length) || length <= Number.EPSILON) {
94
- return [1, 0, 0, 0];
95
- }
96
- return [w / length, x / length, y / length, z2 / length];
97
- }
98
- function decodeQuaternionByte(byte) {
99
- return (byte - 128) / 128;
100
- }
101
- function decodeFloat16(value) {
102
- const sign = value & 32768 ? -1 : 1;
103
- const exponent = value >> 10 & 31;
104
- const fraction = value & 1023;
105
- if (exponent === 0) {
106
- return sign * Math.pow(2, -14) * (fraction / 1024);
107
- }
108
- if (exponent === 31) {
109
- return fraction ? Number.NaN : sign * Number.POSITIVE_INFINITY;
110
- }
111
- return sign * Math.pow(2, exponent - 15) * (1 + fraction / 1024);
84
+ // ../loader-utils/src/lib/log-utils/log.ts
85
+ function createLog() {
86
+ const log2 = new import_log.Log({ id: "loaders.gl" });
87
+ globalThis.loaders ||= {};
88
+ globalThis.loaders.log = log2;
89
+ globalThis.loaders.version = version;
90
+ globalThis.probe ||= {};
91
+ globalThis.probe.loaders = log2;
92
+ return log2;
112
93
  }
113
- var SH_C0;
114
- var init_splat_utils = __esm({
115
- "dist/lib/splat-utils.js"() {
94
+ var import_log, VERSION, version, log;
95
+ var init_log = __esm({
96
+ "../loader-utils/src/lib/log-utils/log.ts"() {
116
97
  "use strict";
117
- SH_C0 = 0.28209479177387814;
98
+ import_log = require("@probe.gl/log");
99
+ VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
100
+ version = VERSION[0] >= "0" && VERSION[0] <= "9" ? `v${VERSION}` : "";
101
+ log = createLog();
118
102
  }
119
103
  });
120
104
 
121
- // dist/lib/splats-arrow-table.js
122
- function makeGaussianSplatsArrowTable(splats) {
123
- const columns = {};
124
- const fields = [];
125
- const schemaFields = [];
126
- addColumn(columns, fields, schemaFields, "POSITION", makeFixedSizeListVector(splats.positions, 3), {
127
- type: "fixed-size-list",
128
- listSize: 3,
129
- children: [{ name: "value", type: "float32" }]
130
- });
131
- const colorCoefficients = getColorCoefficients(splats);
132
- addScalarColumn(columns, fields, schemaFields, "f_dc_0", colorCoefficients[0], {
133
- "loaders_gl.gaussian_splats.semantic": "spherical_harmonic_dc",
134
- "loaders_gl.gaussian_splats.component": "0",
135
- "loaders_gl.gaussian_splats.encoding": "coefficient"
136
- });
137
- addScalarColumn(columns, fields, schemaFields, "f_dc_1", colorCoefficients[1], {
138
- "loaders_gl.gaussian_splats.semantic": "spherical_harmonic_dc",
139
- "loaders_gl.gaussian_splats.component": "1",
140
- "loaders_gl.gaussian_splats.encoding": "coefficient"
141
- });
142
- addScalarColumn(columns, fields, schemaFields, "f_dc_2", colorCoefficients[2], {
143
- "loaders_gl.gaussian_splats.semantic": "spherical_harmonic_dc",
144
- "loaders_gl.gaussian_splats.component": "2",
145
- "loaders_gl.gaussian_splats.encoding": "coefficient"
146
- });
147
- addScalarColumn(columns, fields, schemaFields, "opacity", splats.opacities, {
148
- "loaders_gl.gaussian_splats.semantic": "opacity",
149
- "loaders_gl.gaussian_splats.encoding": "linear"
150
- });
151
- addVectorComponents(columns, fields, schemaFields, "scale", splats.scales, 3, {
152
- "loaders_gl.gaussian_splats.semantic": "scale",
153
- "loaders_gl.gaussian_splats.encoding": "linear"
154
- });
155
- addVectorComponents(columns, fields, schemaFields, "rot", splats.rotations, 4, {
156
- "loaders_gl.gaussian_splats.semantic": "rotation",
157
- "loaders_gl.gaussian_splats.encoding": "quaternion"
158
- });
159
- if (splats.sphericalHarmonics && splats.sphericalHarmonicsComponentCount) {
160
- addSphericalHarmonicRestColumns(columns, fields, schemaFields, splats.sphericalHarmonics, splats.sphericalHarmonicsComponentCount);
105
+ // ../loader-utils/src/lib/javascript-utils/is-type.ts
106
+ var isObject, isPureObject, isSharedArrayBuffer;
107
+ var init_is_type = __esm({
108
+ "../loader-utils/src/lib/javascript-utils/is-type.ts"() {
109
+ "use strict";
110
+ isObject = (value) => value !== null && typeof value === "object";
111
+ isPureObject = (value) => isObject(value) && value.constructor === {}.constructor;
112
+ isSharedArrayBuffer = (value) => typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer;
161
113
  }
162
- const metadata = /* @__PURE__ */ new Map([
163
- ["loaders_gl.semantic_type", "gaussian-splats"],
164
- ["loaders_gl.gaussian_splats.version", "1"],
165
- ["loaders_gl.gaussian_splats.source_format", splats.format],
166
- ["topology", "point-list"],
167
- ["mode", "0"]
168
- ]);
169
- const arrowSchema = new arrow.Schema(fields, metadata);
170
- const schema = {
171
- fields: schemaFields,
172
- metadata: Object.fromEntries(metadata)
173
- };
174
- return {
175
- shape: "arrow-table",
176
- schema,
177
- data: new arrow.Table(arrowSchema, columns),
178
- topology: "point-list",
179
- loaderData: splats.loaderData
180
- };
114
+ });
115
+
116
+ // ../loader-utils/src/lib/option-utils/merge-options.ts
117
+ function mergeOptions(baseOptions, newOptions) {
118
+ return mergeOptionsRecursively(baseOptions || {}, newOptions);
181
119
  }
182
- function addVectorComponents(columns, fields, schemaFields, prefix, values, size, metadata) {
183
- for (let component = 0; component < size; component++) {
184
- const componentValues = new Float32Array(values.length / size);
185
- for (let rowIndex = 0; rowIndex < componentValues.length; rowIndex++) {
186
- componentValues[rowIndex] = values[rowIndex * size + component];
120
+ function mergeOptionsRecursively(baseOptions, newOptions, level = 0) {
121
+ if (level > 3) {
122
+ return newOptions;
123
+ }
124
+ const options = { ...baseOptions };
125
+ for (const [key, newValue] of Object.entries(newOptions)) {
126
+ if (isPureObject(newValue)) {
127
+ options[key] = mergeOptionsRecursively(
128
+ options[key] || {},
129
+ newOptions[key],
130
+ level + 1
131
+ );
132
+ } else {
133
+ options[key] = newOptions[key];
187
134
  }
188
- addScalarColumn(columns, fields, schemaFields, `${prefix}_${component}`, componentValues, {
189
- ...metadata,
190
- "loaders_gl.gaussian_splats.component": String(component)
191
- });
192
135
  }
136
+ return options;
193
137
  }
194
- function addSphericalHarmonicRestColumns(columns, fields, schemaFields, sphericalHarmonics, componentCount) {
195
- for (let component = 0; component < componentCount; component++) {
196
- const componentValues = new Float32Array(sphericalHarmonics.length / componentCount);
197
- for (let rowIndex = 0; rowIndex < componentValues.length; rowIndex++) {
198
- componentValues[rowIndex] = sphericalHarmonics[rowIndex * componentCount + component];
199
- }
200
- addScalarColumn(columns, fields, schemaFields, `f_rest_${component}`, componentValues, {
201
- "loaders_gl.gaussian_splats.semantic": "spherical_harmonic_rest",
202
- "loaders_gl.gaussian_splats.component": String(component),
203
- "loaders_gl.gaussian_splats.encoding": "coefficient"
204
- });
138
+ var init_merge_options = __esm({
139
+ "../loader-utils/src/lib/option-utils/merge-options.ts"() {
140
+ "use strict";
141
+ init_is_type();
205
142
  }
143
+ });
144
+
145
+ // ../loader-utils/src/lib/module-utils/js-module-utils.ts
146
+ function registerJSModules(modules) {
147
+ globalThis.loaders ||= {};
148
+ globalThis.loaders.modules ||= {};
149
+ Object.assign(globalThis.loaders.modules, modules);
206
150
  }
207
- function addScalarColumn(columns, fields, schemaFields, name, values, metadata) {
208
- addColumn(columns, fields, schemaFields, name, arrow.makeVector(values), "float32", metadata);
151
+ function getJSModule(name, caller) {
152
+ var _a, _b;
153
+ const module2 = (_b = (_a = globalThis.loaders) == null ? void 0 : _a.modules) == null ? void 0 : _b[name];
154
+ if (!module2) {
155
+ throw new Error(`${caller}: ${name} library not installed`);
156
+ }
157
+ return module2;
209
158
  }
210
- function addColumn(columns, fields, schemaFields, name, column, schemaType, metadata = {}) {
211
- columns[name] = column;
212
- fields.push(new arrow.Field(name, column.type, false, new Map(Object.entries(metadata))));
213
- schemaFields.push({ name, type: schemaType, nullable: false, metadata });
159
+ function getJSModuleOrNull(name) {
160
+ var _a, _b;
161
+ const module2 = (_b = (_a = globalThis.loaders) == null ? void 0 : _a.modules) == null ? void 0 : _b[name];
162
+ return module2 || null;
214
163
  }
215
- function makeFixedSizeListVector(value, size) {
216
- const values = arrow.makeVector(value);
217
- const child = values.data[0];
218
- const type = new arrow.FixedSizeList(size, new arrow.Field("value", child.type, false));
219
- const data = new arrow.Data(type, 0, value.length / size, 0, {}, [child]);
220
- return new arrow.Vector([data]);
164
+ var init_js_module_utils = __esm({
165
+ "../loader-utils/src/lib/module-utils/js-module-utils.ts"() {
166
+ "use strict";
167
+ }
168
+ });
169
+
170
+ // ../loader-utils/src/lib/binary-utils/array-buffer-utils.ts
171
+ function concatenateArrayBuffers(...sources) {
172
+ return concatenateArrayBuffersFromArray(sources);
221
173
  }
222
- function getColorCoefficients(splats) {
223
- const rowCount = splats.splatCount;
224
- const fdc0 = new Float32Array(rowCount);
225
- const fdc1 = new Float32Array(rowCount);
226
- const fdc2 = new Float32Array(rowCount);
227
- for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {
228
- if (splats.sphericalHarmonicDcs) {
229
- fdc0[rowIndex] = splats.sphericalHarmonicDcs[rowIndex * 3 + 0];
230
- fdc1[rowIndex] = splats.sphericalHarmonicDcs[rowIndex * 3 + 1];
231
- fdc2[rowIndex] = splats.sphericalHarmonicDcs[rowIndex * 3 + 2];
232
- } else {
233
- fdc0[rowIndex] = convertColorByteToSphericalHarmonicDc(splats.colors[rowIndex * 3 + 0]);
234
- fdc1[rowIndex] = convertColorByteToSphericalHarmonicDc(splats.colors[rowIndex * 3 + 1]);
235
- fdc2[rowIndex] = convertColorByteToSphericalHarmonicDc(splats.colors[rowIndex * 3 + 2]);
236
- }
174
+ function concatenateArrayBuffersFromArray(sources) {
175
+ const sourceArrays = sources.map(
176
+ (source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
177
+ );
178
+ const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
179
+ const result = new Uint8Array(byteLength);
180
+ let offset = 0;
181
+ for (const sourceArray of sourceArrays) {
182
+ result.set(sourceArray, offset);
183
+ offset += sourceArray.byteLength;
237
184
  }
238
- return [fdc0, fdc1, fdc2];
185
+ return result.buffer;
239
186
  }
240
- var arrow;
241
- var init_splats_arrow_table = __esm({
242
- "dist/lib/splats-arrow-table.js"() {
187
+ var init_array_buffer_utils = __esm({
188
+ "../loader-utils/src/lib/binary-utils/array-buffer-utils.ts"() {
243
189
  "use strict";
244
- arrow = __toESM(require("apache-arrow"), 1);
245
- init_splat_utils();
246
190
  }
247
191
  });
248
192
 
249
- // dist/lib/parse-splat.js
250
- function parseSPLAT(data) {
251
- return makeGaussianSplatsArrowTable(parseSPLATToGaussianSplats(data));
193
+ // ../loader-utils/src/lib/iterators/async-iteration.ts
194
+ async function concatenateArrayBuffersAsync(asyncIterator) {
195
+ const arrayBuffers = [];
196
+ for await (const chunk of asyncIterator) {
197
+ arrayBuffers.push(copyToArrayBuffer(chunk));
198
+ }
199
+ return concatenateArrayBuffers(...arrayBuffers);
252
200
  }
253
- function parseSPLATToGaussianSplats(data) {
254
- if (data.byteLength % SPLAT_ROW_BYTE_LENGTH !== 0) {
255
- throw new Error(`SPLATLoader: byte length must be a multiple of ${SPLAT_ROW_BYTE_LENGTH}.`);
201
+ function copyToArrayBuffer(chunk) {
202
+ if (chunk instanceof ArrayBuffer) {
203
+ return chunk;
256
204
  }
257
- const splatCount = data.byteLength / SPLAT_ROW_BYTE_LENGTH;
258
- const dataView = new DataView(data);
259
- const positions = new Float32Array(splatCount * 3);
260
- const scales = new Float32Array(splatCount * 3);
261
- const rotations = new Float32Array(splatCount * 4);
262
- const colors = new Uint8Array(splatCount * 3);
263
- const opacities = new Float32Array(splatCount);
264
- for (let splatIndex = 0; splatIndex < splatCount; splatIndex++) {
265
- const byteOffset = splatIndex * SPLAT_ROW_BYTE_LENGTH;
266
- const positionOffset = splatIndex * 3;
267
- const rotationOffset = splatIndex * 4;
268
- positions[positionOffset + 0] = dataView.getFloat32(byteOffset + 0, true);
269
- positions[positionOffset + 1] = dataView.getFloat32(byteOffset + 4, true);
270
- positions[positionOffset + 2] = dataView.getFloat32(byteOffset + 8, true);
271
- scales[positionOffset + 0] = dataView.getFloat32(byteOffset + 12, true);
272
- scales[positionOffset + 1] = dataView.getFloat32(byteOffset + 16, true);
273
- scales[positionOffset + 2] = dataView.getFloat32(byteOffset + 20, true);
274
- colors[positionOffset + 0] = dataView.getUint8(byteOffset + 24);
275
- colors[positionOffset + 1] = dataView.getUint8(byteOffset + 25);
276
- colors[positionOffset + 2] = dataView.getUint8(byteOffset + 26);
277
- opacities[splatIndex] = convertAlphaByteToLinearOpacity(dataView.getUint8(byteOffset + 27));
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)));
279
- rotations[rotationOffset + 0] = w;
280
- rotations[rotationOffset + 1] = x;
281
- rotations[rotationOffset + 2] = y;
282
- rotations[rotationOffset + 3] = z2;
205
+ if (ArrayBuffer.isView(chunk)) {
206
+ const { buffer, byteOffset, byteLength } = chunk;
207
+ return copyFromBuffer(buffer, byteOffset, byteLength);
283
208
  }
284
- return {
285
- format: "splat",
286
- splatCount,
287
- positions,
288
- scales,
289
- rotations,
290
- colors,
291
- opacities,
292
- loaderData: {
293
- format: "splat",
294
- splatCount,
295
- rowByteLength: SPLAT_ROW_BYTE_LENGTH
209
+ return copyFromBuffer(chunk);
210
+ }
211
+ function copyFromBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
212
+ const view = new Uint8Array(buffer, byteOffset, byteLength);
213
+ const copy = new Uint8Array(view.length);
214
+ copy.set(view);
215
+ return copy.buffer;
216
+ }
217
+ var init_async_iteration = __esm({
218
+ "../loader-utils/src/lib/iterators/async-iteration.ts"() {
219
+ "use strict";
220
+ init_array_buffer_utils();
221
+ }
222
+ });
223
+
224
+ // ../loader-utils/src/lib/request-utils/request-credentials.ts
225
+ function createAuthenticatedFetch(options) {
226
+ const baseFetch = options.fetch || ((url, requestOptions) => fetch(url, requestOptions));
227
+ if (!options.credentials.length) return baseFetch;
228
+ const existingMetadata = baseFetch[AUTHENTICATED_FETCH];
229
+ if (existingMetadata === options.credentials) return baseFetch;
230
+ const authenticatedFetch = async (url, requestOptions = {}) => {
231
+ var _a, _b, _c;
232
+ const resolvedURL = parseHTTPURL(url);
233
+ if (!resolvedURL) return baseFetch(url, requestOptions);
234
+ const authorization = await authorizeRequest(resolvedURL, requestOptions, options.credentials);
235
+ const response = await baseFetch(authorization.url, authorization.options);
236
+ const refreshableCredentials = authorization.credentials.filter(
237
+ ({ credential }) => typeof credential.token === "function" && credential.refreshStatusCodes.includes(response.status)
238
+ );
239
+ if (!refreshableCredentials.length || !isReplayableRequest(requestOptions)) return response;
240
+ if ((_a = requestOptions.signal) == null ? void 0 : _a.aborted) throw createAbortError();
241
+ const refreshedTokens = /* @__PURE__ */ new Map();
242
+ await Promise.all(
243
+ refreshableCredentials.map(async ({ credential }) => {
244
+ const token = await refreshCredential(credential, url, response);
245
+ if (token) refreshedTokens.set(credential, token);
246
+ })
247
+ );
248
+ if (!refreshedTokens.size) return response;
249
+ await ((_b = response.body) == null ? void 0 : _b.cancel().catch(() => {
250
+ }));
251
+ if ((_c = requestOptions.signal) == null ? void 0 : _c.aborted) throw createAbortError();
252
+ const replayAuthorization = await authorizeRequest(
253
+ resolvedURL,
254
+ requestOptions,
255
+ options.credentials,
256
+ refreshedTokens,
257
+ authorization.credentials
258
+ );
259
+ return baseFetch(replayAuthorization.url, replayAuthorization.options);
260
+ };
261
+ Object.defineProperty(authenticatedFetch, AUTHENTICATED_FETCH, {
262
+ value: options.credentials
263
+ });
264
+ return authenticatedFetch;
265
+ }
266
+ async function authorizeRequest(sourceURL, requestOptions, credentials, tokenOverrides = /* @__PURE__ */ new Map(), previousCredentials = []) {
267
+ const url = new URL(sourceURL);
268
+ const headers = new Headers(requestOptions.headers);
269
+ const resolvedCredentials = [];
270
+ const previousTokens = new Map(
271
+ previousCredentials.map(({ credential, token }) => [credential, token])
272
+ );
273
+ for (const credential of credentials) {
274
+ if (!credential.origins.includes(url.origin)) continue;
275
+ const overrideToken = tokenOverrides.get(credential);
276
+ const previousToken = previousTokens.get(credential);
277
+ const ownsQueryParameter = credential.type === "query-parameter" && previousToken !== void 0;
278
+ const ownsHeader = credential.type === "header" && previousToken !== void 0;
279
+ if (credential.type === "query-parameter" && url.searchParams.has(credential.name) && !ownsQueryParameter || credential.type === "header" && headers.has(credential.name) && !ownsHeader) {
280
+ continue;
281
+ }
282
+ const token = overrideToken ?? previousToken ?? await resolveToken(credential.token, { url: sourceURL.toString(), reason: "request" });
283
+ if (!token) continue;
284
+ if (credential.type === "query-parameter") {
285
+ url.searchParams.set(credential.name, token);
286
+ } else {
287
+ headers.set(credential.name, `${credential.prefix || ""}${token}`);
296
288
  }
289
+ resolvedCredentials.push({ credential, token });
290
+ }
291
+ return {
292
+ url: url.toString(),
293
+ options: { ...requestOptions, headers },
294
+ credentials: resolvedCredentials
297
295
  };
298
296
  }
299
- var SPLAT_ROW_BYTE_LENGTH;
300
- var init_parse_splat = __esm({
301
- "dist/lib/parse-splat.js"() {
297
+ async function refreshCredential(credential, url, response) {
298
+ const existingPromise = refreshPromises.get(credential);
299
+ if (existingPromise) return existingPromise;
300
+ const tokenProvider = credential.token;
301
+ const promise = Promise.resolve(
302
+ tokenProvider({
303
+ url,
304
+ reason: "refresh",
305
+ response: { status: response.status, headers: response.headers }
306
+ })
307
+ ).finally(() => refreshPromises.delete(credential));
308
+ refreshPromises.set(credential, promise);
309
+ return promise;
310
+ }
311
+ async function resolveToken(token, context) {
312
+ return typeof token === "function" ? token(context) : token;
313
+ }
314
+ function parseHTTPURL(url) {
315
+ try {
316
+ const parsedURL = new URL(url);
317
+ return ["http:", "https:"].includes(parsedURL.protocol) ? parsedURL : null;
318
+ } catch {
319
+ return null;
320
+ }
321
+ }
322
+ function isReplayableRequest(options) {
323
+ const method = (options.method || "GET").toUpperCase();
324
+ if (!["GET", "HEAD", "OPTIONS", "PUT", "DELETE"].includes(method)) return false;
325
+ return !(options.body && typeof ReadableStream !== "undefined" && options.body instanceof ReadableStream);
326
+ }
327
+ function createAbortError() {
328
+ return new DOMException("The operation was aborted.", "AbortError");
329
+ }
330
+ var AUTHENTICATED_FETCH, refreshPromises;
331
+ var init_request_credentials = __esm({
332
+ "../loader-utils/src/lib/request-utils/request-credentials.ts"() {
302
333
  "use strict";
303
- init_splats_arrow_table();
304
- init_splat_utils();
305
- SPLAT_ROW_BYTE_LENGTH = 32;
334
+ AUTHENTICATED_FETCH = /* @__PURE__ */ Symbol("loaders.gl.authenticated-fetch");
335
+ refreshPromises = /* @__PURE__ */ new WeakMap();
306
336
  }
307
337
  });
308
338
 
309
- // dist/splat-loader.js
310
- var splat_loader_exports = {};
311
- __export(splat_loader_exports, {
312
- SPLATLoaderWithParser: () => SPLATLoaderWithParser
313
- });
314
- var _SPLATLoaderPreload, SPLATLoaderMetadataWithoutPreload, SPLATLoaderWithParser;
315
- var init_splat_loader = __esm({
316
- "dist/splat-loader.js"() {
339
+ // ../loader-utils/src/lib/path-utils/file-aliases.ts
340
+ function resolvePath(filename) {
341
+ for (const alias in fileAliases) {
342
+ if (filename.startsWith(alias)) {
343
+ const replacement = fileAliases[alias];
344
+ filename = filename.replace(alias, replacement);
345
+ }
346
+ }
347
+ if (!filename.startsWith("http://") && !filename.startsWith("https://")) {
348
+ filename = `${pathPrefix}${filename}`;
349
+ }
350
+ return filename;
351
+ }
352
+ var pathPrefix, fileAliases;
353
+ var init_file_aliases = __esm({
354
+ "../loader-utils/src/lib/path-utils/file-aliases.ts"() {
317
355
  "use strict";
318
- init_parse_splat();
319
- init_splat_loader_types();
320
- ({ preload: _SPLATLoaderPreload, ...SPLATLoaderMetadataWithoutPreload } = SPLATLoader);
321
- SPLATLoaderWithParser = {
322
- ...SPLATLoaderMetadataWithoutPreload,
323
- parse: async (arrayBuffer) => parseSPLAT(arrayBuffer),
324
- parseSync: (arrayBuffer) => parseSPLAT(arrayBuffer)
325
- };
356
+ pathPrefix = "";
357
+ fileAliases = {};
326
358
  }
327
359
  });
328
360
 
329
- // dist/splat-loader-types.js
330
- async function preload() {
331
- const { SPLATLoaderWithParser: SPLATLoaderWithParser2 } = await Promise.resolve().then(() => (init_splat_loader(), splat_loader_exports));
332
- return SPLATLoaderWithParser2;
361
+ // ../loader-utils/src/lib/binary-utils/memory-conversion-utils.ts
362
+ function ensureArrayBuffer(bufferSource) {
363
+ if (bufferSource instanceof ArrayBuffer) {
364
+ return bufferSource;
365
+ }
366
+ if (isSharedArrayBuffer(bufferSource)) {
367
+ return copyToArrayBuffer2(bufferSource);
368
+ }
369
+ const { buffer, byteOffset, byteLength } = bufferSource;
370
+ if (buffer instanceof ArrayBuffer && byteOffset === 0 && byteLength === buffer.byteLength) {
371
+ return buffer;
372
+ }
373
+ return copyToArrayBuffer2(buffer, byteOffset, byteLength);
333
374
  }
334
- var VERSION, SPLATLoader;
335
- var init_splat_loader_types = __esm({
336
- "dist/splat-loader-types.js"() {
375
+ function copyToArrayBuffer2(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
376
+ const view = new Uint8Array(buffer, byteOffset, byteLength);
377
+ const copy = new Uint8Array(view.length);
378
+ copy.set(view);
379
+ return copy.buffer;
380
+ }
381
+ var init_memory_conversion_utils = __esm({
382
+ "../loader-utils/src/lib/binary-utils/memory-conversion-utils.ts"() {
337
383
  "use strict";
338
- init_splats_format();
339
- VERSION = true ? "5.0.0-alpha.6" : "latest";
340
- SPLATLoader = {
341
- dataType: null,
342
- batchType: null,
343
- ...SPLATFormat,
344
- version: VERSION,
345
- options: {
346
- splats: {
347
- shape: "arrow-table"
348
- }
349
- },
350
- preload
351
- };
384
+ init_is_type();
352
385
  }
353
386
  });
354
387
 
355
- // dist/lib/parse-ksplat.js
356
- function parseKSPLAT(data) {
357
- return makeGaussianSplatsArrowTable(parseKSPLATToGaussianSplats(data));
358
- }
359
- function parseKSPLATToGaussianSplats(data) {
360
- if (data.byteLength < HEADER_BYTE_LENGTH) {
361
- throw new Error(`KSPLATLoader: file must contain a ${HEADER_BYTE_LENGTH}-byte header.`);
388
+ // ../loader-utils/src/lib/sources/data-source.ts
389
+ function getFetchFunction(options) {
390
+ var _a, _b;
391
+ const fetchOption = (options == null ? void 0 : options.fetch) ?? ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a.fetch);
392
+ let fetchFunction;
393
+ if (typeof fetchOption === "function") {
394
+ fetchFunction = (url, fetchOptions) => fetchOption(url, fetchOptions);
395
+ } else if (fetchOption) {
396
+ fetchFunction = (url, requestOptions) => fetch(url, mergeFetchOptions(fetchOption, requestOptions));
397
+ } else {
398
+ fetchFunction = (url, requestOptions) => fetch(url, requestOptions);
362
399
  }
363
- const header = parseKSPLATHeader(data);
364
- checkKSPLATVersion(header);
365
- const sections = parseKSPLATSections(data, header);
366
- const splatCount = getTotalSplatCount(header, sections);
367
- const sphericalHarmonicsComponentCount = Math.max(0, ...sections.slice(0, getActiveSectionCount(header)).map((section) => getSphericalHarmonicsComponentCount(section.sphericalHarmonicsDegree)));
368
- const positions = new Float32Array(splatCount * 3);
369
- const scales = new Float32Array(splatCount * 3);
370
- const rotations = new Float32Array(splatCount * 4);
371
- const colors = new Uint8Array(splatCount * 3);
372
- const opacities = new Float32Array(splatCount);
373
- const sphericalHarmonics = sphericalHarmonicsComponentCount ? new Float32Array(splatCount * sphericalHarmonicsComponentCount) : void 0;
374
- let outputSplatIndex = 0;
375
- for (const section of sections.slice(0, getActiveSectionCount(header))) {
376
- validateSectionBounds(data, section);
377
- for (let localSplatIndex = 0; localSplatIndex < section.splatCount && outputSplatIndex < splatCount; localSplatIndex++) {
378
- decodeKSPLATSplat(data, header, section, localSplatIndex, outputSplatIndex, positions, scales, rotations, colors, opacities, sphericalHarmonics, sphericalHarmonicsComponentCount);
379
- outputSplatIndex++;
380
- }
381
- }
382
- return {
383
- format: "ksplat",
384
- splatCount,
385
- positions,
386
- scales,
387
- rotations,
388
- colors,
389
- opacities,
390
- sphericalHarmonics,
391
- sphericalHarmonicsComponentCount,
392
- loaderData: {
393
- format: "ksplat",
394
- ...header,
395
- sections: sections.slice(0, getActiveSectionCount(header)).map((section) => ({
396
- splatCount: section.splatCount,
397
- maxSplatCount: section.maxSplatCount,
398
- sphericalHarmonicsDegree: section.sphericalHarmonicsDegree
399
- }))
400
- }
401
- };
402
- }
403
- function decodeKSPLATSplat(data, header, section, localSplatIndex, outputSplatIndex, positions, scales, rotations, colors, opacities, sphericalHarmonics, sphericalHarmonicsComponentCount) {
404
- const layout = COMPRESSION_LAYOUTS[header.compressionLevel];
405
- const splatBase = section.dataBase + section.bytesPerSplat * localSplatIndex;
406
- const positionOffset = outputSplatIndex * 3;
407
- const rotationOffset = outputSplatIndex * 4;
408
- const bucketCenter = getBucketCenter(data, section, localSplatIndex);
409
- positions[positionOffset + 0] = decodeKSPLATCenterComponent(data, splatBase, 0, header, section, bucketCenter[0]);
410
- positions[positionOffset + 1] = decodeKSPLATCenterComponent(data, splatBase, 1, header, section, bucketCenter[1]);
411
- positions[positionOffset + 2] = decodeKSPLATCenterComponent(data, splatBase, 2, header, section, bucketCenter[2]);
412
- scales[positionOffset + 0] = readCompressedFloat(data, splatBase + layout.scaleOffsetBytes, 0, header.compressionLevel);
413
- scales[positionOffset + 1] = readCompressedFloat(data, splatBase + layout.scaleOffsetBytes, 1, header.compressionLevel);
414
- scales[positionOffset + 2] = readCompressedFloat(data, splatBase + layout.scaleOffsetBytes, 2, 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));
416
- rotations[rotationOffset + 0] = w;
417
- rotations[rotationOffset + 1] = x;
418
- rotations[rotationOffset + 2] = y;
419
- rotations[rotationOffset + 3] = z2;
420
- const colorBase = splatBase + layout.colorOffsetBytes;
421
- const colorView = new Uint8Array(data, colorBase, 4);
422
- colors[positionOffset + 0] = colorView[0];
423
- colors[positionOffset + 1] = colorView[1];
424
- colors[positionOffset + 2] = colorView[2];
425
- opacities[outputSplatIndex] = convertAlphaByteToLinearOpacity(colorView[3]);
426
- if (sphericalHarmonics && sphericalHarmonicsComponentCount) {
427
- decodeSphericalHarmonics(data, splatBase + layout.sphericalHarmonicsOffsetBytes, header, section, outputSplatIndex, sphericalHarmonics, sphericalHarmonicsComponentCount);
428
- }
429
- }
430
- function parseKSPLATHeader(data) {
431
- const dataView = new DataView(data, 0, HEADER_BYTE_LENGTH);
432
- const compressionLevel = dataView.getUint16(20, true);
433
- if (compressionLevel !== 0 && compressionLevel !== 1 && compressionLevel !== 2) {
434
- throw new Error(`KSPLATLoader: unsupported compression level ${compressionLevel}.`);
435
- }
436
- return {
437
- versionMajor: dataView.getUint8(0),
438
- versionMinor: dataView.getUint8(1),
439
- maxSectionCount: dataView.getUint32(4, true),
440
- sectionCount: dataView.getUint32(8, true),
441
- maxSplatCount: dataView.getUint32(12, true),
442
- splatCount: dataView.getUint32(16, true),
443
- compressionLevel,
444
- minSphericalHarmonicsCoeff: dataView.getFloat32(36, true) || -DEFAULT_SH_8BIT_COMPRESSION_HALF_RANGE,
445
- maxSphericalHarmonicsCoeff: dataView.getFloat32(40, true) || DEFAULT_SH_8BIT_COMPRESSION_HALF_RANGE
446
- };
447
- }
448
- function checkKSPLATVersion(header) {
449
- if (header.versionMajor === CURRENT_MAJOR_VERSION ? header.versionMinor >= CURRENT_MINOR_VERSION : header.versionMajor > CURRENT_MAJOR_VERSION) {
450
- return;
451
- }
452
- throw new Error(`KSPLATLoader: version ${header.versionMajor}.${header.versionMinor} is not supported.`);
400
+ return createAuthenticatedFetch({
401
+ fetch: fetchFunction,
402
+ credentials: ((_b = options == null ? void 0 : options.core) == null ? void 0 : _b.credentials) || []
403
+ });
453
404
  }
454
- function parseKSPLATSections(data, header) {
455
- if (data.byteLength < HEADER_BYTE_LENGTH + header.maxSectionCount * SECTION_HEADER_BYTE_LENGTH) {
456
- throw new Error("KSPLATLoader: file does not contain all section headers.");
457
- }
458
- const sections = [];
459
- let sectionBase = HEADER_BYTE_LENGTH + header.maxSectionCount * SECTION_HEADER_BYTE_LENGTH;
460
- let splatCountOffset = 0;
461
- for (let sectionIndex = 0; sectionIndex < header.maxSectionCount; sectionIndex++) {
462
- const sectionHeaderBase = HEADER_BYTE_LENGTH + sectionIndex * SECTION_HEADER_BYTE_LENGTH;
463
- const dataView = new DataView(data, sectionHeaderBase, SECTION_HEADER_BYTE_LENGTH);
464
- const splatCount = dataView.getUint32(0, true);
465
- const maxSplatCount = dataView.getUint32(4, true);
466
- const bucketSize = dataView.getUint32(8, true);
467
- const bucketCount = dataView.getUint32(12, true);
468
- const bucketBlockSize = dataView.getFloat32(16, true);
469
- const bucketStorageSizeBytes = dataView.getUint16(20, true);
470
- const compressionScaleRange = dataView.getUint32(24, true) || COMPRESSION_LAYOUTS[header.compressionLevel].scaleRange;
471
- const fullBucketCount = dataView.getUint32(32, true);
472
- const partiallyFilledBucketCount = dataView.getUint32(36, true);
473
- const sphericalHarmonicsDegree = dataView.getUint16(40, true);
474
- const bytesPerSplat = getBytesPerSplat(header.compressionLevel, sphericalHarmonicsDegree);
475
- const bucketsMetaDataSizeBytes = partiallyFilledBucketCount * 4;
476
- const bucketsStorageSizeBytes = bucketStorageSizeBytes * bucketCount + bucketsMetaDataSizeBytes;
477
- const storageSizeBytes = bytesPerSplat * maxSplatCount + bucketsStorageSizeBytes;
478
- sections.push({
479
- bytesPerSplat,
480
- splatCountOffset,
481
- splatCount: splatCount || maxSplatCount,
482
- maxSplatCount,
483
- bucketSize,
484
- bucketCount,
485
- bucketStorageSizeBytes,
486
- bucketsStorageSizeBytes,
487
- compressionScaleRange,
488
- compressionScaleFactor: bucketBlockSize / 2 / compressionScaleRange,
489
- base: sectionBase,
490
- bucketsBase: sectionBase + bucketsMetaDataSizeBytes,
491
- dataBase: sectionBase + bucketsStorageSizeBytes,
492
- fullBucketCount,
493
- partiallyFilledBucketCount,
494
- sphericalHarmonicsDegree
495
- });
496
- sectionBase += storageSizeBytes;
497
- splatCountOffset += maxSplatCount;
405
+ function mergeFetchOptions(fetchOptions, requestOptions) {
406
+ const mergedOptions = { ...fetchOptions, ...requestOptions };
407
+ if (fetchOptions.headers || (requestOptions == null ? void 0 : requestOptions.headers)) {
408
+ mergedOptions.headers = mergeHeaders(fetchOptions.headers, requestOptions == null ? void 0 : requestOptions.headers);
498
409
  }
499
- return sections;
500
- }
501
- function decodeKSPLATCenterComponent(data, splatBase, component, header, section, bucketCenter) {
502
- const value = readCompressedCenterValue(data, splatBase, component, header.compressionLevel);
503
- return header.compressionLevel >= 1 ? (value - section.compressionScaleRange) * section.compressionScaleFactor + bucketCenter : value;
504
- }
505
- function readCompressedCenterValue(data, byteOffset, component, compressionLevel) {
506
- const dataView = new DataView(data);
507
- return compressionLevel === 0 ? dataView.getFloat32(byteOffset + component * 4, true) : dataView.getUint16(byteOffset + component * 2, true);
410
+ return mergedOptions;
508
411
  }
509
- function getBucketCenter(data, section, localSplatIndex) {
510
- if (!section.bucketCount) {
511
- return [0, 0, 0];
412
+ function mergeHeaders(defaultHeaders, requestHeaders) {
413
+ const headers = new Headers(defaultHeaders);
414
+ if (requestHeaders) {
415
+ new Headers(requestHeaders).forEach((value, key) => headers.set(key, value));
512
416
  }
513
- const bucketIndex = getBucketIndex(data, section, localSplatIndex);
514
- const bucketBase = section.bucketsBase + bucketIndex * section.bucketStorageSizeBytes;
515
- const dataView = new DataView(data, bucketBase, 12);
516
- return [dataView.getFloat32(0, true), dataView.getFloat32(4, true), dataView.getFloat32(8, true)];
417
+ return headers;
517
418
  }
518
- function getBucketIndex(data, section, localSplatIndex) {
519
- const maxSplatIndexInFullBuckets = section.fullBucketCount * section.bucketSize;
520
- if (localSplatIndex < maxSplatIndexInFullBuckets) {
521
- return Math.floor(localSplatIndex / section.bucketSize);
419
+ function normalizeDirectLoaderOptions(options) {
420
+ const loadOptions = { ...options };
421
+ if (options == null ? void 0 : options.core) {
422
+ loadOptions.core = { ...options.core };
522
423
  }
523
- let bucketSplatIndex = maxSplatIndexInFullBuckets;
524
- let bucketIndex = section.fullBucketCount;
525
- for (let partiallyFilledBucketIndex = 0; partiallyFilledBucketIndex < section.partiallyFilledBucketCount; partiallyFilledBucketIndex++) {
526
- const bucketLength = new DataView(data, section.base + partiallyFilledBucketIndex * 4, 4).getUint32(0, true);
527
- if (localSplatIndex < bucketSplatIndex + bucketLength) {
528
- return bucketIndex;
424
+ const topLevelBaseUri = typeof loadOptions.baseUri === "string" ? loadOptions.baseUri : void 0;
425
+ const topLevelBaseUrl = typeof loadOptions.baseUrl === "string" ? loadOptions.baseUrl : void 0;
426
+ if (topLevelBaseUri !== void 0 || topLevelBaseUrl !== void 0) {
427
+ loadOptions.core ||= {};
428
+ if (loadOptions.core.baseUrl === void 0) {
429
+ loadOptions.core.baseUrl = topLevelBaseUrl ?? topLevelBaseUri;
529
430
  }
530
- bucketSplatIndex += bucketLength;
531
- bucketIndex++;
532
- }
533
- return Math.max(bucketIndex - 1, 0);
534
- }
535
- function decodeSphericalHarmonics(data, byteOffset, header, section, outputSplatIndex, output, outputComponentCount) {
536
- const componentCount = getSphericalHarmonicsComponentCount(section.sphericalHarmonicsDegree);
537
- const componentBase = outputSplatIndex * outputComponentCount;
538
- for (let component = 0; component < componentCount; component++) {
539
- output[componentBase + component] = readCompressedFloat(data, byteOffset, component, header.compressionLevel, true, header.minSphericalHarmonicsCoeff, header.maxSphericalHarmonicsCoeff);
431
+ delete loadOptions.baseUri;
432
+ delete loadOptions.baseUrl;
540
433
  }
434
+ return loadOptions;
541
435
  }
542
- function readCompressedFloat(data, byteOffset, component, compressionLevel, sphericalHarmonic = false, sphericalHarmonicRangeMin = 0, sphericalHarmonicRangeMax = 0) {
543
- const dataView = new DataView(data);
544
- if (compressionLevel === 0) {
545
- return dataView.getFloat32(byteOffset + component * 4, true);
546
- }
547
- if (compressionLevel === 1 || !sphericalHarmonic) {
548
- return decodeFloat16(dataView.getUint16(byteOffset + component * 2, true));
436
+ function normalizeError(error, message) {
437
+ if (error instanceof Error) {
438
+ return error;
549
439
  }
550
- const value = dataView.getUint8(byteOffset + component);
551
- return value / 255 * (sphericalHarmonicRangeMax - sphericalHarmonicRangeMin) + sphericalHarmonicRangeMin;
552
- }
553
- function getBytesPerSplat(compressionLevel, sphericalHarmonicsDegree) {
554
- const layout = COMPRESSION_LAYOUTS[compressionLevel];
555
- return layout.bytesPerCenter + layout.bytesPerScale + layout.bytesPerRotation + layout.bytesPerColor + layout.bytesPerSphericalHarmonicsComponent * getSphericalHarmonicsComponentCount(sphericalHarmonicsDegree);
556
- }
557
- function getSphericalHarmonicsComponentCount(sphericalHarmonicsDegree) {
558
- switch (sphericalHarmonicsDegree) {
559
- case 0:
560
- return 0;
561
- case 1:
562
- return 9;
563
- case 2:
564
- return 24;
565
- case 3:
566
- return 45;
567
- default:
568
- throw new Error(`KSPLATLoader: unsupported spherical harmonics degree ${sphericalHarmonicsDegree}.`);
440
+ if (typeof error === "string") {
441
+ return new Error(error);
569
442
  }
443
+ return new Error(message);
570
444
  }
571
- function getActiveSectionCount(header) {
572
- return header.sectionCount || header.maxSectionCount;
573
- }
574
- function getTotalSplatCount(header, sections) {
575
- const sectionSplatCount = sections.slice(0, getActiveSectionCount(header)).reduce((splatCount, section) => splatCount + section.splatCount, 0);
576
- return header.splatCount ? Math.min(header.splatCount, sectionSplatCount || header.splatCount) : sectionSplatCount;
577
- }
578
- function validateSectionBounds(data, section) {
579
- const requiredByteLength = section.dataBase + section.bytesPerSplat * section.splatCount;
580
- if (requiredByteLength > data.byteLength) {
581
- throw new Error("KSPLATLoader: section data extends beyond the file length.");
582
- }
445
+ function unavailableCoreApiMethod(methodName) {
446
+ return () => {
447
+ throw new Error(
448
+ `CoreAPI.${methodName} is unavailable. Use @loaders.gl/core.createDataSource().`
449
+ );
450
+ };
583
451
  }
584
- var CURRENT_MAJOR_VERSION, CURRENT_MINOR_VERSION, HEADER_BYTE_LENGTH, SECTION_HEADER_BYTE_LENGTH, DEFAULT_SH_8BIT_COMPRESSION_RANGE, DEFAULT_SH_8BIT_COMPRESSION_HALF_RANGE, COMPRESSION_LAYOUTS;
585
- var init_parse_ksplat = __esm({
586
- "dist/lib/parse-ksplat.js"() {
452
+ var UNAVAILABLE_CORE_API, DataSource;
453
+ var init_data_source = __esm({
454
+ "../loader-utils/src/lib/sources/data-source.ts"() {
587
455
  "use strict";
588
- init_splats_arrow_table();
589
- init_splat_utils();
590
- CURRENT_MAJOR_VERSION = 0;
591
- CURRENT_MINOR_VERSION = 1;
592
- HEADER_BYTE_LENGTH = 4096;
593
- SECTION_HEADER_BYTE_LENGTH = 1024;
594
- DEFAULT_SH_8BIT_COMPRESSION_RANGE = 3;
595
- DEFAULT_SH_8BIT_COMPRESSION_HALF_RANGE = DEFAULT_SH_8BIT_COMPRESSION_RANGE / 2;
596
- COMPRESSION_LAYOUTS = {
597
- 0: {
598
- bytesPerCenter: 12,
599
- bytesPerScale: 12,
600
- bytesPerRotation: 16,
601
- bytesPerColor: 4,
602
- scaleOffsetBytes: 12,
603
- colorOffsetBytes: 40,
604
- sphericalHarmonicsOffsetBytes: 44,
605
- scaleRange: 1,
606
- bytesPerSphericalHarmonicsComponent: 4
607
- },
608
- 1: {
609
- bytesPerCenter: 6,
610
- bytesPerScale: 6,
611
- bytesPerRotation: 8,
612
- bytesPerColor: 4,
613
- scaleOffsetBytes: 6,
614
- colorOffsetBytes: 20,
615
- sphericalHarmonicsOffsetBytes: 24,
616
- scaleRange: 32767,
617
- bytesPerSphericalHarmonicsComponent: 2
618
- },
619
- 2: {
620
- bytesPerCenter: 6,
621
- bytesPerScale: 6,
622
- bytesPerRotation: 8,
623
- bytesPerColor: 4,
624
- scaleOffsetBytes: 6,
625
- colorOffsetBytes: 20,
626
- sphericalHarmonicsOffsetBytes: 24,
627
- scaleRange: 32767,
628
- bytesPerSphericalHarmonicsComponent: 1
456
+ init_merge_options();
457
+ init_file_aliases();
458
+ init_log();
459
+ init_request_credentials();
460
+ UNAVAILABLE_CORE_API = {
461
+ fetchFile: unavailableCoreApiMethod("fetchFile"),
462
+ parse: unavailableCoreApiMethod("parse"),
463
+ parseFile: unavailableCoreApiMethod("parseFile"),
464
+ parseSync: unavailableCoreApiMethod("parseSync"),
465
+ parseInBatches: unavailableCoreApiMethod("parseInBatches"),
466
+ load: unavailableCoreApiMethod("load"),
467
+ loadInBatches: unavailableCoreApiMethod("loadInBatches")
468
+ };
469
+ DataSource = class _DataSource {
470
+ static defaultOptions = {
471
+ core: {
472
+ type: "auto",
473
+ attributions: [],
474
+ loadOptions: {},
475
+ loaders: [],
476
+ onError: void 0
477
+ }
478
+ };
479
+ optionsType;
480
+ options;
481
+ data;
482
+ url;
483
+ /** The actual load options, if calling a loaders.gl loader */
484
+ loadOptions;
485
+ /** A resolved fetch function extracted from loadOptions prop */
486
+ fetch;
487
+ /** Shared source-level runtime hooks, when supplied by the source factory. */
488
+ coreApi;
489
+ /** Whether a real CoreAPI instance was injected by the integration layer. */
490
+ hasCoreApi;
491
+ _needsRefresh = true;
492
+ constructor(data, options, defaultOptions, coreApi) {
493
+ var _a;
494
+ if (defaultOptions) {
495
+ this.options = mergeOptions({ ...defaultOptions, core: _DataSource.defaultOptions }, options);
496
+ } else {
497
+ this.options = { ...options };
498
+ }
499
+ this.data = data;
500
+ this.url = typeof data === "string" ? resolvePath(data) : "";
501
+ const loadOptions = normalizeDirectLoaderOptions((_a = this.options.core) == null ? void 0 : _a.loadOptions);
502
+ this.loadOptions = loadOptions;
503
+ const fetch2 = getFetchFunction(loadOptions);
504
+ this.coreApi = coreApi || UNAVAILABLE_CORE_API;
505
+ this.hasCoreApi = Boolean(coreApi);
506
+ this.fetch = fetch2;
507
+ }
508
+ setProps(options) {
509
+ this.options = Object.assign(this.options, options);
510
+ this.setNeedsRefresh();
511
+ }
512
+ /** Mark this data source as needing a refresh (redraw) */
513
+ setNeedsRefresh() {
514
+ this._needsRefresh = true;
515
+ }
516
+ /**
517
+ * Does this data source need refreshing?
518
+ * @note The specifics of the refresh mechanism depends on type of data source
519
+ */
520
+ getNeedsRefresh(clear = true) {
521
+ const needsRefresh = this._needsRefresh;
522
+ if (clear) {
523
+ this._needsRefresh = false;
524
+ }
525
+ return needsRefresh;
526
+ }
527
+ /** Reports a source-level failure through the configured callback or the shared logger. */
528
+ reportError(error, message) {
529
+ var _a;
530
+ const normalizedError = normalizeError(error, message);
531
+ const callback = (_a = this.options.core) == null ? void 0 : _a.onError;
532
+ if (callback) {
533
+ callback(normalizedError, this);
534
+ } else {
535
+ log.warn(`${this.constructor.name}: ${normalizedError.message}`)();
536
+ }
537
+ return normalizedError;
629
538
  }
630
539
  };
631
540
  }
632
541
  });
633
542
 
634
- // dist/ksplat-loader.js
635
- var ksplat_loader_exports = {};
636
- __export(ksplat_loader_exports, {
637
- KSPLATLoaderWithParser: () => KSPLATLoaderWithParser
638
- });
639
- var _KSPLATLoaderPreload, KSPLATLoaderMetadataWithoutPreload, KSPLATLoaderWithParser;
640
- var init_ksplat_loader = __esm({
641
- "dist/ksplat-loader.js"() {
543
+ // ../loader-utils/src/index.ts
544
+ var init_src = __esm({
545
+ "../loader-utils/src/index.ts"() {
642
546
  "use strict";
643
- init_parse_ksplat();
644
- init_ksplat_loader_types();
645
- ({ preload: _KSPLATLoaderPreload, ...KSPLATLoaderMetadataWithoutPreload } = KSPLATLoader);
646
- KSPLATLoaderWithParser = {
647
- ...KSPLATLoaderMetadataWithoutPreload,
648
- parse: async (arrayBuffer) => parseKSPLAT(arrayBuffer),
649
- parseSync: (arrayBuffer) => parseKSPLAT(arrayBuffer)
650
- };
547
+ init_js_module_utils();
548
+ init_js_module_utils();
549
+ init_async_iteration();
550
+ init_memory_conversion_utils();
551
+ init_data_source();
651
552
  }
652
553
  });
653
554
 
654
- // dist/ksplat-loader-types.js
655
- async function preload2() {
656
- const { KSPLATLoaderWithParser: KSPLATLoaderWithParser2 } = await Promise.resolve().then(() => (init_ksplat_loader(), ksplat_loader_exports));
657
- return KSPLATLoaderWithParser2;
658
- }
659
- var VERSION2, KSPLATLoader;
660
- var init_ksplat_loader_types = __esm({
661
- "dist/ksplat-loader-types.js"() {
555
+ // ../compression/src/lib/compression.ts
556
+ var CompressionTransform, Compressor, Decompressor, Compression;
557
+ var init_compression = __esm({
558
+ "../compression/src/lib/compression.ts"() {
662
559
  "use strict";
663
- init_splats_format();
664
- VERSION2 = true ? "5.0.0-alpha.6" : "latest";
665
- KSPLATLoader = {
666
- dataType: null,
667
- batchType: null,
668
- ...KSPLATFormat,
669
- version: VERSION2,
670
- options: {
671
- splats: {
672
- shape: "arrow-table"
560
+ init_src();
561
+ CompressionTransform = class {
562
+ /** Preloads any dynamic libraries. May enable sync functions */
563
+ async preload(modules = {}) {
564
+ registerJSModules(modules);
565
+ return void 0;
566
+ }
567
+ // HELPERS
568
+ concatenate(asyncIterator) {
569
+ return concatenateArrayBuffersAsync(asyncIterator);
570
+ }
571
+ improveError(error) {
572
+ if (!error.message.includes(this.name)) {
573
+ error.message = `${this.name} ${error.message}`;
673
574
  }
674
- },
675
- preload: preload2
575
+ return error;
576
+ }
577
+ };
578
+ Compressor = class extends CompressionTransform {
579
+ constructor(options) {
580
+ super();
581
+ this.compressBatches = this.compressBatches.bind(this);
582
+ }
583
+ /** Asynchronously compresses data. */
584
+ async compress(input) {
585
+ await this.preload();
586
+ return this.compressSync(input);
587
+ }
588
+ /** Synchronously compresses data. */
589
+ compressSync(input) {
590
+ throw new Error(`${this.name}: sync compression not supported`);
591
+ }
592
+ /** Compresses batches. */
593
+ async *compressBatches(asyncIterator) {
594
+ const input = await this.concatenate(asyncIterator);
595
+ yield this.compress(input);
596
+ }
597
+ };
598
+ Decompressor = class extends CompressionTransform {
599
+ constructor(options) {
600
+ super();
601
+ this.decompressBatches = this.decompressBatches.bind(this);
602
+ }
603
+ /** Asynchronously decompresses data. */
604
+ async decompress(input, size) {
605
+ await this.preload();
606
+ return this.decompressSync(input, size);
607
+ }
608
+ /** Synchronously decompresses data. */
609
+ decompressSync(input, size) {
610
+ throw new Error(`${this.name}: sync decompression not supported`);
611
+ }
612
+ /** Decompresses batches. */
613
+ async *decompressBatches(asyncIterator) {
614
+ const input = await this.concatenate(asyncIterator);
615
+ yield this.decompress(input);
616
+ }
617
+ };
618
+ Compression = class extends Compressor {
619
+ constructor(options) {
620
+ super(options);
621
+ this.decompressBatches = this.decompressBatches.bind(this);
622
+ }
623
+ /** Asynchronously decompresses data. */
624
+ async decompress(input, size) {
625
+ await this.preload();
626
+ return this.decompressSync(input, size);
627
+ }
628
+ /** Synchronously decompresses data. */
629
+ decompressSync(input, size) {
630
+ throw new Error(`${this.name}: sync decompression not supported`);
631
+ }
632
+ /** Decompresses batches. */
633
+ async *decompressBatches(asyncIterator) {
634
+ const input = await this.concatenate(asyncIterator);
635
+ yield this.decompress(input);
636
+ }
676
637
  };
677
638
  }
678
639
  });
679
640
 
680
- // ../loader-utils/src/lib/log-utils/log.ts
681
- function createLog() {
682
- const log2 = new import_log.Log({ id: "loaders.gl" });
683
- globalThis.loaders ||= {};
684
- globalThis.loaders.log = log2;
685
- globalThis.loaders.version = version;
686
- globalThis.probe ||= {};
687
- globalThis.probe.loaders = log2;
688
- return log2;
641
+ // ../compression/src/lib/compression-stream.ts
642
+ async function compressWithNativeCompressionStream(input, format) {
643
+ const outputBatches = compressBatchesWithNativeCompressionStream([input], format);
644
+ return outputBatches ? await concatenateBatches(outputBatches) : null;
689
645
  }
690
- var import_log, VERSION3, version, log;
691
- var init_log = __esm({
692
- "../loader-utils/src/lib/log-utils/log.ts"() {
693
- "use strict";
694
- import_log = require("@probe.gl/log");
695
- VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
696
- version = VERSION3[0] >= "0" && VERSION3[0] <= "9" ? `v${VERSION3}` : "";
697
- log = createLog();
698
- }
699
- });
700
-
701
- // ../loader-utils/src/lib/javascript-utils/is-type.ts
702
- var isObject, isPureObject, isSharedArrayBuffer;
703
- var init_is_type = __esm({
704
- "../loader-utils/src/lib/javascript-utils/is-type.ts"() {
705
- "use strict";
706
- isObject = (value) => value !== null && typeof value === "object";
707
- isPureObject = (value) => isObject(value) && value.constructor === {}.constructor;
708
- isSharedArrayBuffer = (value) => typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer;
709
- }
710
- });
711
-
712
- // ../loader-utils/src/lib/option-utils/merge-options.ts
713
- function mergeOptions(baseOptions, newOptions) {
714
- return mergeOptionsRecursively(baseOptions || {}, newOptions);
646
+ function compressBatchesWithNativeCompressionStream(inputBatches, format) {
647
+ const compressionStream = createNativeCompressionStream(format);
648
+ return compressionStream ? transformBatches(inputBatches, compressionStream) : null;
715
649
  }
716
- function mergeOptionsRecursively(baseOptions, newOptions, level = 0) {
717
- if (level > 3) {
718
- return newOptions;
650
+ function createNativeCompressionStream(format) {
651
+ if (typeof globalThis.CompressionStream === "undefined") {
652
+ return null;
719
653
  }
720
- const options = { ...baseOptions };
721
- for (const [key, newValue] of Object.entries(newOptions)) {
722
- if (isPureObject(newValue)) {
723
- options[key] = mergeOptionsRecursively(
724
- options[key] || {},
725
- newOptions[key],
726
- level + 1
727
- );
728
- } else {
729
- options[key] = newOptions[key];
654
+ try {
655
+ const CompressionStreamConstructor = globalThis.CompressionStream;
656
+ return new CompressionStreamConstructor(format);
657
+ } catch (error) {
658
+ if (error instanceof TypeError || (error == null ? void 0 : error.name) === "TypeError") {
659
+ return null;
730
660
  }
661
+ throw error;
731
662
  }
732
- return options;
733
663
  }
734
- var init_merge_options = __esm({
735
- "../loader-utils/src/lib/option-utils/merge-options.ts"() {
736
- "use strict";
737
- init_is_type();
664
+ async function* transformBatches(inputBatches, compressionStream) {
665
+ const writer = compressionStream.writable.getWriter();
666
+ const reader = compressionStream.readable.getReader();
667
+ const writePromise = writeBatches(inputBatches, writer);
668
+ writePromise.catch(() => {
669
+ });
670
+ let outputCompleted = false;
671
+ try {
672
+ while (true) {
673
+ const { done, value } = await reader.read();
674
+ if (done) {
675
+ outputCompleted = true;
676
+ break;
677
+ }
678
+ yield new Uint8Array(value).buffer;
679
+ }
680
+ await writePromise;
681
+ } finally {
682
+ if (!outputCompleted) {
683
+ await reader.cancel().catch(() => {
684
+ });
685
+ await writer.abort().catch(() => {
686
+ });
687
+ await writePromise.catch(() => {
688
+ });
689
+ }
690
+ reader.releaseLock();
738
691
  }
739
- });
740
-
741
- // ../loader-utils/src/lib/module-utils/js-module-utils.ts
742
- function registerJSModules(modules) {
743
- globalThis.loaders ||= {};
744
- globalThis.loaders.modules ||= {};
745
- Object.assign(globalThis.loaders.modules, modules);
746
692
  }
747
- function getJSModule(name, caller) {
748
- var _a, _b;
749
- const module2 = (_b = (_a = globalThis.loaders) == null ? void 0 : _a.modules) == null ? void 0 : _b[name];
750
- if (!module2) {
751
- throw new Error(`${caller}: ${name} library not installed`);
693
+ async function writeBatches(inputBatches, writer) {
694
+ try {
695
+ for await (const inputBatch of inputBatches) {
696
+ await writer.write(new Uint8Array(inputBatch));
697
+ }
698
+ await writer.close();
699
+ } catch (error) {
700
+ await writer.abort(error).catch(() => {
701
+ });
702
+ throw error;
752
703
  }
753
- return module2;
754
- }
755
- function getJSModuleOrNull(name) {
756
- var _a, _b;
757
- const module2 = (_b = (_a = globalThis.loaders) == null ? void 0 : _a.modules) == null ? void 0 : _b[name];
758
- return module2 || null;
759
704
  }
760
- var init_js_module_utils = __esm({
761
- "../loader-utils/src/lib/module-utils/js-module-utils.ts"() {
762
- "use strict";
705
+ async function concatenateBatches(batches) {
706
+ const output = [];
707
+ let byteLength = 0;
708
+ for await (const batch of batches) {
709
+ const bytes = new Uint8Array(batch);
710
+ output.push(bytes);
711
+ byteLength += bytes.byteLength;
763
712
  }
764
- });
765
-
766
- // ../loader-utils/src/lib/binary-utils/array-buffer-utils.ts
767
- function concatenateArrayBuffers(...sources) {
768
- return concatenateArrayBuffersFromArray(sources);
769
- }
770
- function concatenateArrayBuffersFromArray(sources) {
771
- const sourceArrays = sources.map(
772
- (source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
773
- );
774
- const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
775
713
  const result = new Uint8Array(byteLength);
776
714
  let offset = 0;
777
- for (const sourceArray of sourceArrays) {
778
- result.set(sourceArray, offset);
779
- offset += sourceArray.byteLength;
715
+ for (const batch of output) {
716
+ result.set(batch, offset);
717
+ offset += batch.byteLength;
780
718
  }
781
719
  return result.buffer;
782
720
  }
783
- var init_array_buffer_utils = __esm({
784
- "../loader-utils/src/lib/binary-utils/array-buffer-utils.ts"() {
721
+ var init_compression_stream = __esm({
722
+ "../compression/src/lib/compression-stream.ts"() {
785
723
  "use strict";
786
724
  }
787
725
  });
788
726
 
789
- // ../loader-utils/src/lib/iterators/async-iteration.ts
790
- async function concatenateArrayBuffersAsync(asyncIterator) {
791
- const arrayBuffers = [];
792
- for await (const chunk of asyncIterator) {
793
- arrayBuffers.push(copyToArrayBuffer(chunk));
727
+ // ../compression/src/lib/decompression-stream.ts
728
+ async function decompressWithNativeDecompressionStream(input, format) {
729
+ const outputBatches = decompressBatchesWithNativeDecompressionStream([input], format);
730
+ return outputBatches ? await concatenateNativeDecompressionBatches(outputBatches) : null;
731
+ }
732
+ function decompressBatchesWithNativeDecompressionStream(inputBatches, format) {
733
+ const decompressionStream = createNativeDecompressionStream(format);
734
+ return decompressionStream ? transformBatchesWithNativeDecompressionStream(inputBatches, decompressionStream) : null;
735
+ }
736
+ function isNativeDecompressionSupported(format) {
737
+ return Boolean(createNativeDecompressionStream(format));
738
+ }
739
+ function createNativeDecompressionStream(format) {
740
+ var _a, _b;
741
+ if (typeof globalThis.DecompressionStream === "undefined") {
742
+ return null;
743
+ }
744
+ if (((_b = (_a = globalThis.process) == null ? void 0 : _a.release) == null ? void 0 : _b.name) === "node" && typeof globalThis.Buffer === "undefined") {
745
+ return null;
746
+ }
747
+ try {
748
+ const DecompressionStreamConstructor = globalThis.DecompressionStream;
749
+ return new DecompressionStreamConstructor(format);
750
+ } catch (error) {
751
+ if (error instanceof TypeError || (error == null ? void 0 : error.name) === "TypeError") {
752
+ return null;
753
+ }
754
+ throw error;
794
755
  }
795
- return concatenateArrayBuffers(...arrayBuffers);
796
756
  }
797
- function copyToArrayBuffer(chunk) {
798
- if (chunk instanceof ArrayBuffer) {
799
- return chunk;
757
+ async function* transformBatchesWithNativeDecompressionStream(inputBatches, decompressionStream) {
758
+ const writer = decompressionStream.writable.getWriter();
759
+ const reader = decompressionStream.readable.getReader();
760
+ const writePromise = writeBatchesToNativeDecompressionStream(inputBatches, writer);
761
+ writePromise.catch(() => {
762
+ });
763
+ let outputCompleted = false;
764
+ try {
765
+ while (true) {
766
+ const { done, value } = await reader.read();
767
+ if (done) {
768
+ outputCompleted = true;
769
+ break;
770
+ }
771
+ yield copyExactArrayBuffer(value);
772
+ }
773
+ await writePromise;
774
+ } finally {
775
+ if (!outputCompleted) {
776
+ await reader.cancel().catch(() => {
777
+ });
778
+ await writer.abort().catch(() => {
779
+ });
780
+ await writePromise.catch(() => {
781
+ });
782
+ }
783
+ reader.releaseLock();
800
784
  }
801
- if (ArrayBuffer.isView(chunk)) {
802
- const { buffer, byteOffset, byteLength } = chunk;
803
- return copyFromBuffer(buffer, byteOffset, byteLength);
785
+ }
786
+ async function concatenateNativeDecompressionBatches(outputBatches) {
787
+ const batches = [];
788
+ let byteLength = 0;
789
+ for await (const outputBatch of outputBatches) {
790
+ const bytes = new Uint8Array(outputBatch);
791
+ batches.push(bytes);
792
+ byteLength += bytes.byteLength;
804
793
  }
805
- return copyFromBuffer(chunk);
794
+ const output = new Uint8Array(byteLength);
795
+ let byteOffset = 0;
796
+ for (const batch of batches) {
797
+ output.set(batch, byteOffset);
798
+ byteOffset += batch.byteLength;
799
+ }
800
+ return output.buffer;
806
801
  }
807
- function copyFromBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
808
- const view = new Uint8Array(buffer, byteOffset, byteLength);
809
- const copy = new Uint8Array(view.length);
810
- copy.set(view);
811
- return copy.buffer;
802
+ function copyExactArrayBuffer(value) {
803
+ return new Uint8Array(value).buffer;
812
804
  }
813
- var init_async_iteration = __esm({
814
- "../loader-utils/src/lib/iterators/async-iteration.ts"() {
805
+ async function writeBatchesToNativeDecompressionStream(inputBatches, writer) {
806
+ try {
807
+ for await (const inputBatch of inputBatches) {
808
+ await writer.write(new Uint8Array(inputBatch));
809
+ }
810
+ await writer.close();
811
+ } catch (error) {
812
+ await writer.abort(error).catch(() => {
813
+ });
814
+ throw error;
815
+ }
816
+ }
817
+ var init_decompression_stream = __esm({
818
+ "../compression/src/lib/decompression-stream.ts"() {
815
819
  "use strict";
816
- init_array_buffer_utils();
817
820
  }
818
821
  });
819
822
 
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"() {
823
+ // ../compression/src/lib/native-decompressor.ts
824
+ var native_decompressor_exports = {};
825
+ __export(native_decompressor_exports, {
826
+ NativeDecompressor: () => NativeDecompressor
827
+ });
828
+ var NativeDecompressor;
829
+ var init_native_decompressor = __esm({
830
+ "../compression/src/lib/native-decompressor.ts"() {
929
831
  "use strict";
930
- AUTHENTICATED_FETCH = /* @__PURE__ */ Symbol("loaders.gl.authenticated-fetch");
931
- refreshPromises = /* @__PURE__ */ new WeakMap();
832
+ init_compression();
833
+ init_decompression_stream();
834
+ NativeDecompressor = class extends Decompressor {
835
+ name;
836
+ extensions;
837
+ contentEncodings;
838
+ isSupported = true;
839
+ /** Runtime stream format used for every operation. */
840
+ format;
841
+ constructor(metadata, format, options = {}) {
842
+ super(options);
843
+ this.name = metadata.name;
844
+ this.extensions = [...metadata.extensions];
845
+ this.contentEncodings = [...metadata.contentEncodings];
846
+ this.format = format;
847
+ }
848
+ /** Decompresses one buffer with the runtime-provided stream. */
849
+ async decompress(input) {
850
+ const output = await decompressWithNativeDecompressionStream(input, this.format);
851
+ if (!output) throw new Error(`${this.name}: built-in decompression is no longer available`);
852
+ return output;
853
+ }
854
+ /** Decompresses batches incrementally with the runtime-provided stream. */
855
+ async *decompressBatches(inputBatches) {
856
+ const output = decompressBatchesWithNativeDecompressionStream(inputBatches, this.format);
857
+ if (!output) throw new Error(`${this.name}: built-in decompression is no longer available`);
858
+ yield* output;
859
+ }
860
+ };
932
861
  }
933
862
  });
934
863
 
935
- // ../loader-utils/src/lib/path-utils/file-aliases.ts
936
- function resolvePath(filename) {
937
- for (const alias in fileAliases) {
938
- if (filename.startsWith(alias)) {
939
- const replacement = fileAliases[alias];
940
- filename = filename.replace(alias, replacement);
941
- }
942
- }
943
- if (!filename.startsWith("http://") && !filename.startsWith("https://")) {
944
- filename = `${pathPrefix}${filename}`;
945
- }
946
- return filename;
864
+ // ../compression/src/lib/lazy-compression.ts
865
+ function mergeModules(options, modules) {
866
+ return { ...options, modules: { ...options.modules, ...modules } };
947
867
  }
948
- var pathPrefix, fileAliases;
949
- var init_file_aliases = __esm({
950
- "../loader-utils/src/lib/path-utils/file-aliases.ts"() {
868
+ var LazyDecompressor;
869
+ var init_lazy_compression = __esm({
870
+ "../compression/src/lib/lazy-compression.ts"() {
951
871
  "use strict";
952
- pathPrefix = "";
953
- fileAliases = {};
872
+ init_compression();
873
+ init_decompression_stream();
874
+ LazyDecompressor = class extends Decompressor {
875
+ name;
876
+ extensions;
877
+ contentEncodings;
878
+ isSupported = true;
879
+ /** Constructor options retained until a concrete implementation is selected. */
880
+ options;
881
+ /** Built-in stream format to probe, or null when the format has no built-in path. */
882
+ nativeFormat;
883
+ /** Returns whether built-in selection remains eligible for the merged preload options. */
884
+ shouldUseNative;
885
+ /** Dynamically imports the balanced fallback constructor. */
886
+ loadFallback;
887
+ /** Selected concrete implementation after preload completes. */
888
+ implementation = null;
889
+ /** Shared in-flight selection used by concurrent asynchronous calls. */
890
+ implementationPromise = null;
891
+ constructor(metadata, loadFallback, options = {}, nativeFormat = null, shouldUseNative = () => true) {
892
+ super(options);
893
+ this.name = metadata.name;
894
+ this.extensions = [...metadata.extensions];
895
+ this.contentEncodings = [...metadata.contentEncodings];
896
+ this.options = options;
897
+ this.nativeFormat = nativeFormat;
898
+ this.shouldUseNative = shouldUseNative;
899
+ this.loadFallback = loadFallback;
900
+ }
901
+ /** Selects and returns the built-in or dynamically imported fallback decompressor. */
902
+ async preload(modules = {}) {
903
+ if (this.implementation) return this.implementation;
904
+ const options = mergeModules(this.options, modules);
905
+ this.implementationPromise ||= this.loadImplementation(options);
906
+ try {
907
+ this.implementation = await this.implementationPromise;
908
+ return this.implementation;
909
+ } catch (error) {
910
+ this.implementationPromise = null;
911
+ throw error;
912
+ }
913
+ }
914
+ /** Loads the selected concrete decompressor. */
915
+ async loadImplementation(options) {
916
+ if (options.useNative !== false && this.nativeFormat && this.shouldUseNative(options) && isNativeDecompressionSupported(this.nativeFormat)) {
917
+ const { NativeDecompressor: NativeDecompressor2 } = await Promise.resolve().then(() => (init_native_decompressor(), native_decompressor_exports));
918
+ return new NativeDecompressor2(this, this.nativeFormat, options);
919
+ }
920
+ const Decompressor2 = await this.loadFallback();
921
+ const implementation = new Decompressor2({ ...options, useNative: false });
922
+ await implementation.preload(options.modules);
923
+ return implementation;
924
+ }
925
+ /** Decompresses after lazily selecting the default implementation. */
926
+ async decompress(input, size) {
927
+ return (await this.preload()).decompress(input, size);
928
+ }
929
+ /** Decompresses synchronously after an implementation has been preloaded. */
930
+ decompressSync(input, size) {
931
+ if (!this.implementation) {
932
+ throw new Error(`${this.name}: call preload() before decompressSync()`);
933
+ }
934
+ return this.implementation.decompressSync(input, size);
935
+ }
936
+ /** Decompresses batches after lazily selecting the default implementation. */
937
+ async *decompressBatches(inputBatches) {
938
+ yield* (await this.preload()).decompressBatches(inputBatches);
939
+ }
940
+ };
954
941
  }
955
942
  });
956
943
 
957
- // ../loader-utils/src/lib/binary-utils/memory-conversion-utils.ts
958
- function ensureArrayBuffer(bufferSource) {
959
- if (bufferSource instanceof ArrayBuffer) {
960
- return bufferSource;
961
- }
962
- if (isSharedArrayBuffer(bufferSource)) {
963
- return copyToArrayBuffer2(bufferSource);
964
- }
965
- const { buffer, byteOffset, byteLength } = bufferSource;
966
- if (buffer instanceof ArrayBuffer && byteOffset === 0 && byteLength === buffer.byteLength) {
967
- return buffer;
944
+ // ../compression/src/lib/fflate-stream.ts
945
+ async function* transformFflateBatches(processor, inputBatches) {
946
+ const chunks = [];
947
+ processor.ondata = (data) => {
948
+ chunks.push(data.slice().buffer);
949
+ };
950
+ for await (const batch of inputBatches) {
951
+ processor.push(new Uint8Array(batch), false);
952
+ yield* chunks.splice(0);
968
953
  }
969
- return copyToArrayBuffer2(buffer, byteOffset, byteLength);
970
- }
971
- function copyToArrayBuffer2(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
972
- const view = new Uint8Array(buffer, byteOffset, byteLength);
973
- const copy = new Uint8Array(view.length);
974
- copy.set(view);
975
- return copy.buffer;
954
+ processor.push(new Uint8Array(0), true);
955
+ yield* chunks;
976
956
  }
977
- var init_memory_conversion_utils = __esm({
978
- "../loader-utils/src/lib/binary-utils/memory-conversion-utils.ts"() {
957
+ var init_fflate_stream = __esm({
958
+ "../compression/src/lib/fflate-stream.ts"() {
979
959
  "use strict";
980
- init_is_type();
981
960
  }
982
961
  });
983
962
 
984
- // ../loader-utils/src/lib/sources/data-source.ts
985
- function getFetchFunction(options) {
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
- });
1000
- }
1001
- function mergeFetchOptions(fetchOptions, requestOptions) {
1002
- const mergedOptions = { ...fetchOptions, ...requestOptions };
1003
- if (fetchOptions.headers || (requestOptions == null ? void 0 : requestOptions.headers)) {
1004
- mergedOptions.headers = mergeHeaders(fetchOptions.headers, requestOptions == null ? void 0 : requestOptions.headers);
1005
- }
1006
- return mergedOptions;
1007
- }
1008
- function mergeHeaders(defaultHeaders, requestHeaders) {
1009
- const headers = new Headers(defaultHeaders);
1010
- if (requestHeaders) {
1011
- new Headers(requestHeaders).forEach((value, key) => headers.set(key, value));
1012
- }
1013
- return headers;
1014
- }
1015
- function normalizeDirectLoaderOptions(options) {
1016
- const loadOptions = { ...options };
1017
- if (options == null ? void 0 : options.core) {
1018
- loadOptions.core = { ...options.core };
1019
- }
1020
- const topLevelBaseUri = typeof loadOptions.baseUri === "string" ? loadOptions.baseUri : void 0;
1021
- const topLevelBaseUrl = typeof loadOptions.baseUrl === "string" ? loadOptions.baseUrl : void 0;
1022
- if (topLevelBaseUri !== void 0 || topLevelBaseUrl !== void 0) {
1023
- loadOptions.core ||= {};
1024
- if (loadOptions.core.baseUrl === void 0) {
1025
- loadOptions.core.baseUrl = topLevelBaseUrl ?? topLevelBaseUri;
1026
- }
1027
- delete loadOptions.baseUri;
1028
- delete loadOptions.baseUrl;
1029
- }
1030
- return loadOptions;
1031
- }
1032
- function normalizeError(error, message) {
1033
- if (error instanceof Error) {
1034
- return error;
1035
- }
1036
- if (typeof error === "string") {
1037
- return new Error(error);
1038
- }
1039
- return new Error(message);
1040
- }
1041
- function unavailableCoreApiMethod(methodName) {
1042
- return () => {
1043
- throw new Error(
1044
- `CoreAPI.${methodName} is unavailable. Use @loaders.gl/core.createDataSource().`
1045
- );
1046
- };
1047
- }
1048
- var UNAVAILABLE_CORE_API, DataSource;
1049
- var init_data_source = __esm({
1050
- "../loader-utils/src/lib/sources/data-source.ts"() {
963
+ // ../compression/src/gzip-decompressor-fflate.ts
964
+ var import_fflate, GZipFflateDecompressor;
965
+ var init_gzip_decompressor_fflate = __esm({
966
+ "../compression/src/gzip-decompressor-fflate.ts"() {
1051
967
  "use strict";
1052
- init_merge_options();
1053
- init_file_aliases();
1054
- init_log();
1055
- init_request_credentials();
1056
- UNAVAILABLE_CORE_API = {
1057
- fetchFile: unavailableCoreApiMethod("fetchFile"),
1058
- parse: unavailableCoreApiMethod("parse"),
1059
- parseFile: unavailableCoreApiMethod("parseFile"),
1060
- parseSync: unavailableCoreApiMethod("parseSync"),
1061
- parseInBatches: unavailableCoreApiMethod("parseInBatches"),
1062
- load: unavailableCoreApiMethod("load"),
1063
- loadInBatches: unavailableCoreApiMethod("loadInBatches")
1064
- };
1065
- DataSource = class _DataSource {
1066
- static defaultOptions = {
1067
- core: {
1068
- type: "auto",
1069
- attributions: [],
1070
- loadOptions: {},
1071
- loaders: [],
1072
- onError: void 0
1073
- }
1074
- };
1075
- optionsType;
1076
- options;
1077
- data;
1078
- url;
1079
- /** The actual load options, if calling a loaders.gl loader */
1080
- loadOptions;
1081
- /** A resolved fetch function extracted from loadOptions prop */
1082
- fetch;
1083
- /** Shared source-level runtime hooks, when supplied by the source factory. */
1084
- coreApi;
1085
- /** Whether a real CoreAPI instance was injected by the integration layer. */
1086
- hasCoreApi;
1087
- _needsRefresh = true;
1088
- constructor(data, options, defaultOptions, coreApi) {
1089
- var _a;
1090
- if (defaultOptions) {
1091
- this.options = mergeOptions({ ...defaultOptions, core: _DataSource.defaultOptions }, options);
1092
- } else {
1093
- this.options = { ...options };
1094
- }
1095
- this.data = data;
1096
- this.url = typeof data === "string" ? resolvePath(data) : "";
1097
- const loadOptions = normalizeDirectLoaderOptions((_a = this.options.core) == null ? void 0 : _a.loadOptions);
1098
- this.loadOptions = loadOptions;
1099
- const fetch2 = getFetchFunction(loadOptions);
1100
- this.coreApi = coreApi || UNAVAILABLE_CORE_API;
1101
- this.hasCoreApi = Boolean(coreApi);
1102
- this.fetch = fetch2;
968
+ import_fflate = require("fflate");
969
+ init_compression();
970
+ init_fflate_stream();
971
+ GZipFflateDecompressor = class extends Decompressor {
972
+ name = "gzip";
973
+ extensions = ["gz", "gzip"];
974
+ contentEncodings = ["gzip", "x-gzip"];
975
+ isSupported = true;
976
+ constructor(options = {}) {
977
+ super(options);
1103
978
  }
1104
- setProps(options) {
1105
- this.options = Object.assign(this.options, options);
1106
- this.setNeedsRefresh();
979
+ /** Decompresses one GZIP payload synchronously. */
980
+ decompressSync(input) {
981
+ return (0, import_fflate.gunzipSync)(new Uint8Array(input)).slice().buffer;
1107
982
  }
1108
- /** Mark this data source as needing a refresh (redraw) */
1109
- setNeedsRefresh() {
1110
- this._needsRefresh = true;
983
+ /** Decompresses GZIP batches incrementally. */
984
+ async *decompressBatches(inputBatches) {
985
+ yield* transformFflateBatches(new import_fflate.Gunzip(), inputBatches);
1111
986
  }
1112
- /**
1113
- * Does this data source need refreshing?
1114
- * @note The specifics of the refresh mechanism depends on type of data source
1115
- */
1116
- getNeedsRefresh(clear = true) {
1117
- const needsRefresh = this._needsRefresh;
1118
- if (clear) {
1119
- this._needsRefresh = false;
987
+ };
988
+ }
989
+ });
990
+
991
+ // ../compression/src/gzip-decompressor.ts
992
+ var gzip_decompressor_exports = {};
993
+ __export(gzip_decompressor_exports, {
994
+ GZipDecompressor: () => GZipDecompressor
995
+ });
996
+ var GZipDecompressor;
997
+ var init_gzip_decompressor = __esm({
998
+ "../compression/src/gzip-decompressor.ts"() {
999
+ "use strict";
1000
+ init_gzip_decompressor_fflate();
1001
+ init_decompression_stream();
1002
+ GZipDecompressor = class extends GZipFflateDecompressor {
1003
+ options;
1004
+ constructor(options = {}) {
1005
+ super(options);
1006
+ this.options = options;
1007
+ }
1008
+ /** Decompresses with the built-in stream when available, then falls back to fflate. */
1009
+ async decompress(input) {
1010
+ if (this.options.useNative !== false) {
1011
+ const output = await decompressWithNativeDecompressionStream(input, "gzip");
1012
+ if (output) return output;
1120
1013
  }
1121
- return needsRefresh;
1014
+ return this.decompressSync(input);
1122
1015
  }
1123
- /** Reports a source-level failure through the configured callback or the shared logger. */
1124
- reportError(error, message) {
1125
- var _a;
1126
- const normalizedError = normalizeError(error, message);
1127
- const callback = (_a = this.options.core) == null ? void 0 : _a.onError;
1128
- if (callback) {
1129
- callback(normalizedError, this);
1130
- } else {
1131
- log.warn(`${this.constructor.name}: ${normalizedError.message}`)();
1016
+ /** Decompresses batches with a built-in or fflate stream. */
1017
+ async *decompressBatches(inputBatches) {
1018
+ if (this.options.useNative !== false) {
1019
+ const output = decompressBatchesWithNativeDecompressionStream(inputBatches, "gzip");
1020
+ if (output) {
1021
+ yield* output;
1022
+ return;
1023
+ }
1132
1024
  }
1133
- return normalizedError;
1025
+ yield* super.decompressBatches(inputBatches);
1134
1026
  }
1135
1027
  };
1136
1028
  }
1137
1029
  });
1138
1030
 
1139
- // ../loader-utils/src/index.ts
1140
- var init_src = __esm({
1141
- "../loader-utils/src/index.ts"() {
1031
+ // ../compression/src/zstd-decompressor-fzstd.ts
1032
+ var import_fzstd, ZstdFzstdDecompressor;
1033
+ var init_zstd_decompressor_fzstd = __esm({
1034
+ "../compression/src/zstd-decompressor-fzstd.ts"() {
1142
1035
  "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();
1036
+ init_compression();
1037
+ import_fzstd = require("fzstd");
1038
+ ZstdFzstdDecompressor = class extends Decompressor {
1039
+ name = "zstd";
1040
+ extensions = ["zst"];
1041
+ contentEncodings = ["zstd"];
1042
+ isSupported = true;
1043
+ constructor(options = {}) {
1044
+ super(options);
1045
+ }
1046
+ /** Decompresses one Zstandard frame synchronously. */
1047
+ decompressSync(input) {
1048
+ return (0, import_fzstd.decompress)(new Uint8Array(input)).slice().buffer;
1049
+ }
1050
+ };
1148
1051
  }
1149
1052
  });
1150
1053
 
1151
- // ../compression/src/lib/compression.ts
1152
- var CompressionTransform, Compressor, Decompressor, Compression;
1153
- var init_compression = __esm({
1154
- "../compression/src/lib/compression.ts"() {
1054
+ // ../compression/src/zstd-fallback.ts
1055
+ var zstd_fallback_exports = {};
1056
+ __export(zstd_fallback_exports, {
1057
+ decompressZstd: () => decompressZstd
1058
+ });
1059
+ function decompressZstd(input) {
1060
+ return (0, import_fzstd2.decompress)(input);
1061
+ }
1062
+ var import_fzstd2;
1063
+ var init_zstd_fallback = __esm({
1064
+ "../compression/src/zstd-fallback.ts"() {
1065
+ "use strict";
1066
+ import_fzstd2 = require("fzstd");
1067
+ }
1068
+ });
1069
+
1070
+ // ../compression/src/lib/zstd-compression.ts
1071
+ var zstd_compression_exports = {};
1072
+ __export(zstd_compression_exports, {
1073
+ ZstdCompression: () => ZstdCompression
1074
+ });
1075
+ var CHUNK_SIZE, zstdPromise, zstd, ZstdCompression;
1076
+ var init_zstd_compression = __esm({
1077
+ "../compression/src/lib/zstd-compression.ts"() {
1155
1078
  "use strict";
1079
+ init_compression();
1156
1080
  init_src();
1157
- CompressionTransform = class {
1158
- /** Preloads any dynamic libraries. May enable sync functions */
1081
+ init_compression_stream();
1082
+ init_decompression_stream();
1083
+ CHUNK_SIZE = 1e6;
1084
+ ZstdCompression = class extends Compression {
1085
+ name = "zstd";
1086
+ extensions = [];
1087
+ contentEncodings = [];
1088
+ isSupported = true;
1089
+ options;
1090
+ /**
1091
+ * zstd-codec is an injectable dependency due to big size
1092
+ * @param options
1093
+ */
1094
+ constructor(options = {}) {
1095
+ super(options);
1096
+ this.options = options;
1097
+ registerJSModules(options == null ? void 0 : options.modules);
1098
+ }
1159
1099
  async preload(modules = {}) {
1160
1100
  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}`;
1101
+ const ZstdCodec = getJSModuleOrNull("zstd-codec");
1102
+ if (!zstdPromise && ZstdCodec) {
1103
+ zstdPromise = new Promise((resolve) => ZstdCodec.run((zstd2) => resolve(zstd2)));
1104
+ }
1105
+ if (zstdPromise) {
1106
+ zstd = await zstdPromise;
1170
1107
  }
1171
- return error;
1172
1108
  }
1173
- };
1174
- Compressor = class extends CompressionTransform {
1175
- constructor(options) {
1176
- super();
1177
- this.compressBatches = this.compressBatches.bind(this);
1109
+ compressSync(input) {
1110
+ getJSModule("zstd-codec", this.name);
1111
+ const simpleZstd = new zstd.Simple();
1112
+ const inputArray = new Uint8Array(input);
1113
+ return simpleZstd.compress(inputArray).buffer;
1178
1114
  }
1179
- /** Asynchronously compresses data. */
1180
1115
  async compress(input) {
1116
+ var _a;
1117
+ if (this.options.useNative !== false && ((_a = this.options.zstd) == null ? void 0 : _a.useNative) !== false) {
1118
+ const nativeOutput = await compressWithNativeCompressionStream(input, "zstd");
1119
+ if (nativeOutput) return nativeOutput;
1120
+ }
1181
1121
  await this.preload();
1182
1122
  return this.compressSync(input);
1183
1123
  }
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);
1124
+ decompressSync(input) {
1125
+ getJSModule("zstd-codec", this.name);
1126
+ const simpleZstd = new zstd.Simple();
1127
+ const inputArray = new Uint8Array(input);
1128
+ return simpleZstd.decompress(inputArray).buffer;
1198
1129
  }
1199
- /** Asynchronously decompresses data. */
1200
1130
  async decompress(input, size) {
1131
+ var _a;
1132
+ if (!getJSModuleOrNull("zstd-codec") && this.options.useNative !== false && ((_a = this.options.zstd) == null ? void 0 : _a.useNative) !== false) {
1133
+ const nativeOutput = await decompressWithNativeDecompressionStream(input, "zstd");
1134
+ if (nativeOutput) return nativeOutput;
1135
+ }
1201
1136
  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);
1137
+ const inputArray = new Uint8Array(input);
1138
+ if (!zstd) {
1139
+ const { decompressZstd: decompressZstd2 } = await Promise.resolve().then(() => (init_zstd_fallback(), zstd_fallback_exports));
1140
+ return ensureArrayBuffer(decompressZstd2(inputArray));
1141
+ }
1142
+ const simpleZstd = new zstd.Streaming();
1143
+ const chunks = [];
1144
+ for (let i = 0; i <= inputArray.length; i += CHUNK_SIZE) {
1145
+ const chunkView = inputArray.subarray(i, i + CHUNK_SIZE);
1146
+ const chunkArrayBuffer = ensureArrayBuffer(chunkView);
1147
+ chunks.push(new Uint8Array(chunkArrayBuffer));
1148
+ }
1149
+ const decompressResult = await simpleZstd.decompressChunks(chunks);
1150
+ return decompressResult.buffer;
1212
1151
  }
1213
1152
  };
1214
- Compression = class extends Compressor {
1215
- constructor(options) {
1153
+ }
1154
+ });
1155
+
1156
+ // ../compression/src/zstd-decompressor.ts
1157
+ var zstd_decompressor_exports = {};
1158
+ __export(zstd_decompressor_exports, {
1159
+ ZstdDecompressor: () => ZstdDecompressor
1160
+ });
1161
+ var ZstdDecompressor;
1162
+ var init_zstd_decompressor = __esm({
1163
+ "../compression/src/zstd-decompressor.ts"() {
1164
+ "use strict";
1165
+ init_zstd_decompressor_fzstd();
1166
+ init_decompression_stream();
1167
+ init_src();
1168
+ ZstdDecompressor = class extends ZstdFzstdDecompressor {
1169
+ options;
1170
+ compatibility = null;
1171
+ constructor(options = {}) {
1216
1172
  super(options);
1217
- this.decompressBatches = this.decompressBatches.bind(this);
1173
+ this.options = options;
1174
+ registerJSModules(options.modules);
1218
1175
  }
1219
- /** Asynchronously decompresses data. */
1220
- async decompress(input, size) {
1221
- await this.preload();
1222
- return this.decompressSync(input, size);
1176
+ /** Preloads an injected zstd-codec implementation when supplied. */
1177
+ async preload(modules = {}) {
1178
+ registerJSModules(modules);
1179
+ if (getJSModuleOrNull("zstd-codec")) {
1180
+ const { ZstdCompression: ZstdCompression2 } = await Promise.resolve().then(() => (init_zstd_compression(), zstd_compression_exports));
1181
+ this.compatibility ||= new ZstdCompression2(this.options);
1182
+ await this.compatibility.preload(modules);
1183
+ }
1223
1184
  }
1224
- /** Synchronously decompresses data. */
1225
- decompressSync(input, size) {
1226
- throw new Error(`${this.name}: sync decompression not supported`);
1185
+ /** Decompresses with the built-in stream when available, then falls back to fzstd. */
1186
+ async decompress(input) {
1187
+ if (this.options.useNative !== false) {
1188
+ const output = await decompressWithNativeDecompressionStream(input, "zstd");
1189
+ if (output) return output;
1190
+ }
1191
+ if (getJSModuleOrNull("zstd-codec")) {
1192
+ await this.preload(this.options.modules);
1193
+ }
1194
+ return this.decompressSync(input);
1227
1195
  }
1228
- /** Decompresses batches. */
1229
- async *decompressBatches(asyncIterator) {
1230
- const input = await this.concatenate(asyncIterator);
1231
- yield this.decompress(input);
1196
+ /** Decompresses with a preloaded zstd-codec implementation or compact fzstd. */
1197
+ decompressSync(input) {
1198
+ if (this.compatibility) {
1199
+ return this.compatibility.decompressSync(input);
1200
+ }
1201
+ if (getJSModuleOrNull("zstd-codec")) {
1202
+ throw new Error("zstd: call preload() before synchronous decompression with zstd-codec");
1203
+ }
1204
+ return super.decompressSync(input);
1205
+ }
1206
+ /** Decompresses batches with a built-in stream or compact fzstd fallback. */
1207
+ async *decompressBatches(inputBatches) {
1208
+ if (this.options.useNative !== false) {
1209
+ const output = decompressBatchesWithNativeDecompressionStream(inputBatches, "zstd");
1210
+ if (output) {
1211
+ yield* output;
1212
+ return;
1213
+ }
1214
+ }
1215
+ if (getJSModuleOrNull("zstd-codec")) {
1216
+ yield this.decompress(await this.concatenate(inputBatches));
1217
+ return;
1218
+ }
1219
+ yield* super.decompressBatches(inputBatches);
1232
1220
  }
1233
1221
  };
1234
1222
  }
1235
1223
  });
1236
1224
 
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;
1225
+ // ../compression/src/default-codecs.ts
1226
+ var GZIP, ZSTD, GZipDecompressor2, ZstdDecompressor2;
1227
+ var init_default_codecs = __esm({
1228
+ "../compression/src/default-codecs.ts"() {
1229
+ "use strict";
1230
+ init_lazy_compression();
1231
+ init_src();
1232
+ GZIP = { name: "gzip", extensions: ["gz"], contentEncodings: ["gzip"] };
1233
+ ZSTD = { name: "zstd", extensions: ["zst"], contentEncodings: ["zstd"] };
1234
+ GZipDecompressor2 = class extends LazyDecompressor {
1235
+ constructor(options = {}) {
1236
+ super(
1237
+ GZIP,
1238
+ async () => (await Promise.resolve().then(() => (init_gzip_decompressor(), gzip_decompressor_exports))).GZipDecompressor,
1239
+ options,
1240
+ "gzip"
1241
+ );
1242
+ }
1243
+ };
1244
+ ZstdDecompressor2 = class extends LazyDecompressor {
1245
+ constructor(options = {}) {
1246
+ super(
1247
+ ZSTD,
1248
+ async () => (await Promise.resolve().then(() => (init_zstd_decompressor(), zstd_decompressor_exports))).ZstdDecompressor,
1249
+ options,
1250
+ "zstd",
1251
+ (preloadOptions) => {
1252
+ var _a;
1253
+ return !((_a = preloadOptions.modules) == null ? void 0 : _a["zstd-codec"]) && !getJSModuleOrNull("zstd-codec");
1254
+ }
1255
+ );
1256
+ }
1257
+ };
1249
1258
  }
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;
1259
+ });
1260
+
1261
+ // ../compression/src/index.ts
1262
+ var init_src2 = __esm({
1263
+ "../compression/src/index.ts"() {
1264
+ "use strict";
1265
+ init_default_codecs();
1258
1266
  }
1267
+ });
1268
+
1269
+ // dist/lib/splat-utils.js
1270
+ function convertColorByteToSphericalHarmonicDc(colorByte) {
1271
+ return (colorByte / 255 - 0.5) / SH_C0;
1259
1272
  }
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
- }
1273
+ function convertAlphaByteToLinearOpacity(alphaByte) {
1274
+ return Math.min(Math.max(alphaByte / 255, 0), 1);
1288
1275
  }
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;
1276
+ function normalizeQuaternion(w, x, y, z2) {
1277
+ const length = Math.hypot(w, x, y, z2);
1278
+ if (!Number.isFinite(length) || length <= Number.EPSILON) {
1279
+ return [1, 0, 0, 0];
1299
1280
  }
1281
+ return [w / length, x / length, y / length, z2 / length];
1300
1282
  }
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;
1283
+ function decodeQuaternionByte(byte) {
1284
+ return (byte - 128) / 128;
1285
+ }
1286
+ function decodeFloat16(value) {
1287
+ const sign = value & 32768 ? -1 : 1;
1288
+ const exponent = value >> 10 & 31;
1289
+ const fraction = value & 1023;
1290
+ if (exponent === 0) {
1291
+ return sign * Math.pow(2, -14) * (fraction / 1024);
1308
1292
  }
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;
1293
+ if (exponent === 31) {
1294
+ return fraction ? Number.NaN : sign * Number.POSITIVE_INFINITY;
1314
1295
  }
1315
- return result.buffer;
1296
+ return sign * Math.pow(2, exponent - 15) * (1 + fraction / 1024);
1316
1297
  }
1317
- var init_compression_stream = __esm({
1318
- "../compression/src/lib/compression-stream.ts"() {
1298
+ var SH_C0;
1299
+ var init_splat_utils = __esm({
1300
+ "dist/lib/splat-utils.js"() {
1319
1301
  "use strict";
1302
+ SH_C0 = 0.28209479177387814;
1320
1303
  }
1321
1304
  });
1322
1305
 
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;
1306
+ // dist/lib/splats-arrow-table.js
1307
+ function makeGaussianSplatsArrowTable(splats) {
1308
+ const columns = {};
1309
+ const fields = [];
1310
+ const schemaFields = [];
1311
+ addColumn(columns, fields, schemaFields, "POSITION", makeFixedSizeListVector(splats.positions, 3), {
1312
+ type: "fixed-size-list",
1313
+ listSize: 3,
1314
+ children: [{ name: "value", type: "float32" }]
1315
+ });
1316
+ const colorCoefficients = getColorCoefficients(splats);
1317
+ addScalarColumn(columns, fields, schemaFields, "f_dc_0", colorCoefficients[0], {
1318
+ "loaders_gl.gaussian_splats.semantic": "spherical_harmonic_dc",
1319
+ "loaders_gl.gaussian_splats.component": "0",
1320
+ "loaders_gl.gaussian_splats.encoding": "coefficient"
1321
+ });
1322
+ addScalarColumn(columns, fields, schemaFields, "f_dc_1", colorCoefficients[1], {
1323
+ "loaders_gl.gaussian_splats.semantic": "spherical_harmonic_dc",
1324
+ "loaders_gl.gaussian_splats.component": "1",
1325
+ "loaders_gl.gaussian_splats.encoding": "coefficient"
1326
+ });
1327
+ addScalarColumn(columns, fields, schemaFields, "f_dc_2", colorCoefficients[2], {
1328
+ "loaders_gl.gaussian_splats.semantic": "spherical_harmonic_dc",
1329
+ "loaders_gl.gaussian_splats.component": "2",
1330
+ "loaders_gl.gaussian_splats.encoding": "coefficient"
1331
+ });
1332
+ addScalarColumn(columns, fields, schemaFields, "opacity", splats.opacities, {
1333
+ "loaders_gl.gaussian_splats.semantic": "opacity",
1334
+ "loaders_gl.gaussian_splats.encoding": "linear"
1335
+ });
1336
+ addVectorComponents(columns, fields, schemaFields, "scale", splats.scales, 3, {
1337
+ "loaders_gl.gaussian_splats.semantic": "scale",
1338
+ "loaders_gl.gaussian_splats.encoding": "linear"
1339
+ });
1340
+ addVectorComponents(columns, fields, schemaFields, "rot", splats.rotations, 4, {
1341
+ "loaders_gl.gaussian_splats.semantic": "rotation",
1342
+ "loaders_gl.gaussian_splats.encoding": "quaternion"
1343
+ });
1344
+ if (splats.sphericalHarmonics && splats.sphericalHarmonicsComponentCount) {
1345
+ addSphericalHarmonicRestColumns(columns, fields, schemaFields, splats.sphericalHarmonics, splats.sphericalHarmonicsComponentCount);
1342
1346
  }
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;
1347
+ const metadata = /* @__PURE__ */ new Map([
1348
+ ["loaders_gl.semantic_type", "gaussian-splats"],
1349
+ ["loaders_gl.gaussian_splats.version", "1"],
1350
+ ["loaders_gl.gaussian_splats.source_format", splats.format],
1351
+ ["topology", "point-list"],
1352
+ ["mode", "0"]
1353
+ ]);
1354
+ const arrowSchema = new arrow.Schema(fields, metadata);
1355
+ const schema = {
1356
+ fields: schemaFields,
1357
+ metadata: Object.fromEntries(metadata)
1358
+ };
1359
+ return {
1360
+ shape: "arrow-table",
1361
+ schema,
1362
+ data: new arrow.Table(arrowSchema, columns),
1363
+ topology: "point-list",
1364
+ loaderData: splats.loaderData
1365
+ };
1366
+ }
1367
+ function addVectorComponents(columns, fields, schemaFields, prefix, values, size, metadata) {
1368
+ for (let component = 0; component < size; component++) {
1369
+ const componentValues = new Float32Array(values.length / size);
1370
+ for (let rowIndex = 0; rowIndex < componentValues.length; rowIndex++) {
1371
+ componentValues[rowIndex] = values[rowIndex * size + component];
1349
1372
  }
1350
- throw error;
1373
+ addScalarColumn(columns, fields, schemaFields, `${prefix}_${component}`, componentValues, {
1374
+ ...metadata,
1375
+ "loaders_gl.gaussian_splats.component": String(component)
1376
+ });
1351
1377
  }
1352
1378
  }
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
- });
1379
+ function addSphericalHarmonicRestColumns(columns, fields, schemaFields, sphericalHarmonics, componentCount) {
1380
+ for (let component = 0; component < componentCount; component++) {
1381
+ const componentValues = new Float32Array(sphericalHarmonics.length / componentCount);
1382
+ for (let rowIndex = 0; rowIndex < componentValues.length; rowIndex++) {
1383
+ componentValues[rowIndex] = sphericalHarmonics[rowIndex * componentCount + component];
1378
1384
  }
1379
- reader.releaseLock();
1385
+ addScalarColumn(columns, fields, schemaFields, `f_rest_${component}`, componentValues, {
1386
+ "loaders_gl.gaussian_splats.semantic": "spherical_harmonic_rest",
1387
+ "loaders_gl.gaussian_splats.component": String(component),
1388
+ "loaders_gl.gaussian_splats.encoding": "coefficient"
1389
+ });
1380
1390
  }
1381
1391
  }
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;
1392
+ function addScalarColumn(columns, fields, schemaFields, name, values, metadata) {
1393
+ addColumn(columns, fields, schemaFields, name, arrow.makeVector(values), "float32", metadata);
1397
1394
  }
1398
- function copyExactArrayBuffer(value) {
1399
- return new Uint8Array(value).buffer;
1395
+ function addColumn(columns, fields, schemaFields, name, column, schemaType, metadata = {}) {
1396
+ columns[name] = column;
1397
+ fields.push(new arrow.Field(name, column.type, false, new Map(Object.entries(metadata))));
1398
+ schemaFields.push({ name, type: schemaType, nullable: false, metadata });
1400
1399
  }
1401
- async function writeBatchesToNativeDecompressionStream(inputBatches, writer) {
1402
- try {
1403
- for await (const inputBatch of inputBatches) {
1404
- await writer.write(new Uint8Array(inputBatch));
1400
+ function makeFixedSizeListVector(value, size) {
1401
+ const values = arrow.makeVector(value);
1402
+ const child = values.data[0];
1403
+ const type = new arrow.FixedSizeList(size, new arrow.Field("value", child.type, false));
1404
+ const data = new arrow.Data(type, 0, value.length / size, 0, {}, [child]);
1405
+ return new arrow.Vector([data]);
1406
+ }
1407
+ function getColorCoefficients(splats) {
1408
+ const rowCount = splats.splatCount;
1409
+ const fdc0 = new Float32Array(rowCount);
1410
+ const fdc1 = new Float32Array(rowCount);
1411
+ const fdc2 = new Float32Array(rowCount);
1412
+ for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {
1413
+ if (splats.sphericalHarmonicDcs) {
1414
+ fdc0[rowIndex] = splats.sphericalHarmonicDcs[rowIndex * 3 + 0];
1415
+ fdc1[rowIndex] = splats.sphericalHarmonicDcs[rowIndex * 3 + 1];
1416
+ fdc2[rowIndex] = splats.sphericalHarmonicDcs[rowIndex * 3 + 2];
1417
+ } else {
1418
+ fdc0[rowIndex] = convertColorByteToSphericalHarmonicDc(splats.colors[rowIndex * 3 + 0]);
1419
+ fdc1[rowIndex] = convertColorByteToSphericalHarmonicDc(splats.colors[rowIndex * 3 + 1]);
1420
+ fdc2[rowIndex] = convertColorByteToSphericalHarmonicDc(splats.colors[rowIndex * 3 + 2]);
1405
1421
  }
1406
- await writer.close();
1407
- } catch (error) {
1408
- await writer.abort(error).catch(() => {
1409
- });
1410
- throw error;
1411
1422
  }
1423
+ return [fdc0, fdc1, fdc2];
1412
1424
  }
1413
- var init_decompression_stream = __esm({
1414
- "../compression/src/lib/decompression-stream.ts"() {
1425
+ var arrow;
1426
+ var init_splats_arrow_table = __esm({
1427
+ "dist/lib/splats-arrow-table.js"() {
1415
1428
  "use strict";
1429
+ arrow = __toESM(require("apache-arrow"), 1);
1430
+ init_splat_utils();
1416
1431
  }
1417
1432
  });
1418
1433
 
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"() {
1427
- "use strict";
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
- };
1434
+ // dist/lib/parse-spz.js
1435
+ async function parseSPZ(data, options) {
1436
+ return makeGaussianSplatsArrowTable(await parseSPZToGaussianSplats(data, options));
1437
+ }
1438
+ async function parseSPZToGaussianSplats(data, options) {
1439
+ var _a, _b, _c;
1440
+ const version2 = detectSPZVersion(data);
1441
+ if (version2 === 0) {
1442
+ return await parseLegacySPZ(data, options);
1457
1443
  }
1458
- });
1459
-
1460
- // ../compression/src/lib/lazy-compression.ts
1461
- function mergeModules(options, modules) {
1462
- return { ...options, modules: { ...options.modules, ...modules } };
1444
+ if (version2 !== SPZ_VERSION) {
1445
+ throw new Error(`SPZLoader: version ${version2} is not supported.`);
1446
+ }
1447
+ const header = parseSPZHeader(data);
1448
+ const streamInfos = parseSPZStreamInfos(data, header, getSPZStreamByteLengths(header));
1449
+ const compressedStreams = streamInfos.map((streamInfo) => data.slice(streamInfo.compressedOffset, streamInfo.compressedOffset + streamInfo.compressedSize));
1450
+ const decompressor = new ZstdDecompressor2({ modules: options == null ? void 0 : options.modules });
1451
+ const streams = await Promise.all(compressedStreams.map((compressedStream, streamIndex) => decompressor.decompress(compressedStream, streamInfos[streamIndex].uncompressedSize)));
1452
+ validateSPZStreamLengths(streams, streamInfos);
1453
+ return applySPZCoordinateSystem(decodeSPZStreams(header, streams, data), ((_a = options == null ? void 0 : options.splats) == null ? void 0 : _a.sourceCoordinateSystem) ?? "RUB", ((_b = options == null ? void 0 : options.splats) == null ? void 0 : _b.targetCoordinateSystem) ?? ((_c = options == null ? void 0 : options.splats) == null ? void 0 : _c.sourceCoordinateSystem) ?? "RUB");
1463
1454
  }
1464
- var LazyDecompressor;
1465
- var init_lazy_compression = __esm({
1466
- "../compression/src/lib/lazy-compression.ts"() {
1467
- "use strict";
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;
1496
- }
1497
- /** Selects and returns the built-in or dynamically imported fallback decompressor. */
1498
- async preload(modules = {}) {
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
- }
1509
- }
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;
1520
- }
1521
- /** Decompresses after lazily selecting the default implementation. */
1522
- async decompress(input, size) {
1523
- return (await this.preload()).decompress(input, size);
1524
- }
1525
- /** Decompresses synchronously after an implementation has been preloaded. */
1526
- decompressSync(input, size) {
1527
- if (!this.implementation) {
1528
- throw new Error(`${this.name}: call preload() before decompressSync()`);
1529
- }
1530
- return this.implementation.decompressSync(input, size);
1531
- }
1532
- /** Decompresses batches after lazily selecting the default implementation. */
1533
- async *decompressBatches(inputBatches) {
1534
- yield* (await this.preload()).decompressBatches(inputBatches);
1455
+ function detectSPZVersion(data) {
1456
+ if (data.byteLength < 8) {
1457
+ throw new Error("SPZLoader: file must contain at least an 8-byte header.");
1458
+ }
1459
+ const bytes = new Uint8Array(data);
1460
+ if (bytes[0] === 31 && bytes[1] === 139) {
1461
+ return 0;
1462
+ }
1463
+ if (data.byteLength < SPZ_HEADER_BYTE_LENGTH) {
1464
+ throw new Error("SPZLoader: file must contain a 32-byte header.");
1465
+ }
1466
+ return new DataView(data).getUint32(4, true);
1467
+ }
1468
+ async function parseLegacySPZ(data, options) {
1469
+ var _a, _b, _c;
1470
+ const decompressed = await new GZipDecompressor2({
1471
+ modules: options == null ? void 0 : options.modules,
1472
+ useNative: true
1473
+ }).decompress(data);
1474
+ if (decompressed.byteLength < 16) {
1475
+ throw new Error("SPZLoader: legacy payload must contain a 16-byte header.");
1476
+ }
1477
+ const dataView = new DataView(decompressed);
1478
+ const header = {
1479
+ magic: dataView.getUint32(0, true),
1480
+ version: dataView.getUint32(4, true),
1481
+ numPoints: dataView.getUint32(8, true),
1482
+ shDegree: dataView.getUint8(12),
1483
+ fractionalBits: dataView.getUint8(13),
1484
+ flags: dataView.getUint8(14)
1485
+ };
1486
+ if (header.magic !== SPZ_MAGIC) {
1487
+ throw new Error("SPZLoader: NGSP magic header not found.");
1488
+ }
1489
+ if (header.version !== 2 && header.version !== 3) {
1490
+ throw new Error(`SPZLoader: version ${header.version} is not supported.`);
1491
+ }
1492
+ if (dataView.getUint8(15) !== 0) {
1493
+ throw new Error("SPZLoader: legacy header reserved byte must be zero.");
1494
+ }
1495
+ if (header.shDegree > 3) {
1496
+ throw new Error(`SPZLoader: spherical harmonics degree ${header.shDegree} is not supported.`);
1497
+ }
1498
+ const count = header.numPoints;
1499
+ const shComponentCount = getSphericalHarmonicsComponentCount(header.shDegree);
1500
+ const positionByteLength = count * 9;
1501
+ const alphaByteLength = count;
1502
+ const colorByteLength = count * 3;
1503
+ const scaleByteLength = count * 3;
1504
+ const rotationByteLength = count * (header.version === 2 ? 3 : 4);
1505
+ const shByteLength = count * shComponentCount;
1506
+ const payloadByteLength = positionByteLength + alphaByteLength + colorByteLength + scaleByteLength + rotationByteLength + shByteLength;
1507
+ if (decompressed.byteLength - 16 !== payloadByteLength) {
1508
+ throw new Error(`SPZLoader: legacy payload has ${decompressed.byteLength - 16} bytes, expected ${payloadByteLength}.`);
1509
+ }
1510
+ let offset = 16;
1511
+ const positions = new Float32Array(count * 3);
1512
+ const opacities = new Float32Array(count);
1513
+ const colors = new Uint8Array(count * 3);
1514
+ const scales = new Float32Array(count * 3);
1515
+ const rotations = new Float32Array(count * 4);
1516
+ const sphericalHarmonicDcs = new Float32Array(count * 3);
1517
+ const sphericalHarmonics = shComponentCount ? new Float32Array(count * shComponentCount) : void 0;
1518
+ decodeSPZPositions(new Uint8Array(decompressed, offset, positionByteLength), positions, header.fractionalBits);
1519
+ offset += positionByteLength;
1520
+ decodeSPZOpacities(new Uint8Array(decompressed, offset, alphaByteLength), opacities);
1521
+ offset += alphaByteLength;
1522
+ decodeSPZColors(new Uint8Array(decompressed, offset, colorByteLength), colors, sphericalHarmonicDcs);
1523
+ offset += colorByteLength;
1524
+ decodeSPZScales(new Uint8Array(decompressed, offset, scaleByteLength), scales);
1525
+ offset += scaleByteLength;
1526
+ if (header.version === 2) {
1527
+ decodeLegacySPZRotations(new Uint8Array(decompressed, offset, rotationByteLength), rotations);
1528
+ } else {
1529
+ decodeSPZRotations(new Uint8Array(decompressed, offset, rotationByteLength), rotations);
1530
+ }
1531
+ offset += rotationByteLength;
1532
+ if (sphericalHarmonics) {
1533
+ decodeSPZSphericalHarmonics(new Uint8Array(decompressed, offset, shByteLength), sphericalHarmonics);
1534
+ }
1535
+ return applySPZCoordinateSystem({
1536
+ format: "spz",
1537
+ splatCount: count,
1538
+ positions,
1539
+ scales,
1540
+ rotations,
1541
+ colors,
1542
+ sphericalHarmonicDcs,
1543
+ opacities,
1544
+ sphericalHarmonics,
1545
+ sphericalHarmonicsComponentCount: shComponentCount || void 0,
1546
+ loaderData: { ...header, legacy: true }
1547
+ }, ((_a = options == null ? void 0 : options.splats) == null ? void 0 : _a.sourceCoordinateSystem) ?? "RUB", ((_b = options == null ? void 0 : options.splats) == null ? void 0 : _b.targetCoordinateSystem) ?? ((_c = options == null ? void 0 : options.splats) == null ? void 0 : _c.sourceCoordinateSystem) ?? "RUB");
1548
+ }
1549
+ function decodeLegacySPZRotations(rotationStream, rotations) {
1550
+ for (let splatIndex = 0; splatIndex < rotations.length / 4; splatIndex++) {
1551
+ const byteOffset = splatIndex * 3;
1552
+ const x = signedByte(rotationStream[byteOffset]) / 127;
1553
+ const y = signedByte(rotationStream[byteOffset + 1]) / 127;
1554
+ const z2 = signedByte(rotationStream[byteOffset + 2]) / 127;
1555
+ const w = Math.sqrt(Math.max(0, 1 - x * x - y * y - z2 * z2));
1556
+ const normalized = normalizeQuaternion(w, x, y, z2);
1557
+ rotations.set(normalized, splatIndex * 4);
1558
+ }
1559
+ }
1560
+ function signedByte(value) {
1561
+ return value > 127 ? value - 256 : value;
1562
+ }
1563
+ function applySPZCoordinateSystem(splats, source, target) {
1564
+ if (source === target || source === "UNSPECIFIED" || target === "UNSPECIFIED") {
1565
+ return splats;
1566
+ }
1567
+ if (source === "RUB" && target === "LUF") {
1568
+ for (let index = 0; index < splats.positions.length; index += 3) {
1569
+ splats.positions[index] = -splats.positions[index];
1570
+ splats.positions[index + 2] = -splats.positions[index + 2];
1571
+ }
1572
+ for (let index = 0; index < splats.rotations.length; index += 4) {
1573
+ splats.rotations[index + 1] = -splats.rotations[index + 1];
1574
+ splats.rotations[index + 3] = -splats.rotations[index + 3];
1575
+ }
1576
+ return splats;
1577
+ }
1578
+ if (source === "LUF" && target === "RUB") {
1579
+ return applySPZCoordinateSystem(splats, "RUB", "LUF");
1580
+ }
1581
+ throw new Error(`SPZLoader: coordinate conversion ${source} -> ${target} is not supported.`);
1582
+ }
1583
+ function parseSPZHeader(data) {
1584
+ if (data.byteLength < SPZ_HEADER_BYTE_LENGTH) {
1585
+ throw new Error(`SPZLoader: file must contain a ${SPZ_HEADER_BYTE_LENGTH}-byte header.`);
1586
+ }
1587
+ const dataView = new DataView(data);
1588
+ const header = {
1589
+ magic: dataView.getUint32(0, true),
1590
+ version: dataView.getUint32(4, true),
1591
+ numPoints: dataView.getUint32(8, true),
1592
+ shDegree: dataView.getUint8(12),
1593
+ fractionalBits: dataView.getUint8(13),
1594
+ flags: dataView.getUint8(14),
1595
+ numStreams: dataView.getUint8(15),
1596
+ tocByteOffset: dataView.getUint32(16, true)
1597
+ };
1598
+ if (header.magic !== SPZ_MAGIC) {
1599
+ throw new Error("SPZLoader: NGSP magic header not found.");
1600
+ }
1601
+ if (header.version !== SPZ_VERSION) {
1602
+ throw new Error(`SPZLoader: version ${header.version} is not supported.`);
1603
+ }
1604
+ if (header.shDegree > 4) {
1605
+ throw new Error(`SPZLoader: spherical harmonics degree ${header.shDegree} is not supported.`);
1606
+ }
1607
+ if (header.tocByteOffset < SPZ_HEADER_BYTE_LENGTH || header.tocByteOffset > data.byteLength) {
1608
+ throw new Error("SPZLoader: invalid table of contents byte offset.");
1609
+ }
1610
+ return header;
1611
+ }
1612
+ function parseSPZStreamInfos(data, header, expectedUncompressedSizes) {
1613
+ if (header.numStreams !== expectedUncompressedSizes.length) {
1614
+ throw new Error(`SPZLoader: expected ${expectedUncompressedSizes.length} streams, found ${header.numStreams}.`);
1615
+ }
1616
+ const tocByteLength = header.numStreams * 16;
1617
+ const tocEnd = header.tocByteOffset + tocByteLength;
1618
+ if (tocEnd > data.byteLength) {
1619
+ throw new Error("SPZLoader: table of contents exceeds file byte length.");
1620
+ }
1621
+ const dataView = new DataView(data);
1622
+ let compressedOffset = tocEnd;
1623
+ const streamInfos = [];
1624
+ for (let streamIndex = 0; streamIndex < header.numStreams; streamIndex++) {
1625
+ const tocOffset = header.tocByteOffset + streamIndex * 16;
1626
+ const compressedSize = readSafeUint64(dataView, tocOffset);
1627
+ const uncompressedSize = readSafeUint64(dataView, tocOffset + 8);
1628
+ const expectedUncompressedSize = expectedUncompressedSizes[streamIndex];
1629
+ if (uncompressedSize !== expectedUncompressedSize) {
1630
+ throw new Error(`SPZLoader: stream ${streamIndex} has ${uncompressedSize} uncompressed bytes, expected ${expectedUncompressedSize}.`);
1631
+ }
1632
+ if (compressedOffset + compressedSize > data.byteLength) {
1633
+ throw new Error(`SPZLoader: stream ${streamIndex} exceeds file byte length.`);
1634
+ }
1635
+ streamInfos.push({ compressedSize, uncompressedSize, compressedOffset });
1636
+ compressedOffset += compressedSize;
1637
+ }
1638
+ if (compressedOffset !== data.byteLength) {
1639
+ throw new Error("SPZLoader: compressed stream byte lengths do not match file byte length.");
1640
+ }
1641
+ return streamInfos;
1642
+ }
1643
+ function readSafeUint64(dataView, byteOffset) {
1644
+ const value = dataView.getBigUint64(byteOffset, true);
1645
+ if (value > BigInt(Number.MAX_SAFE_INTEGER)) {
1646
+ throw new Error("SPZLoader: stream byte length exceeds Number.MAX_SAFE_INTEGER.");
1647
+ }
1648
+ return Number(value);
1649
+ }
1650
+ function getSPZStreamByteLengths(header) {
1651
+ return [
1652
+ header.numPoints * 9,
1653
+ header.numPoints,
1654
+ header.numPoints * 3,
1655
+ header.numPoints * 3,
1656
+ header.numPoints * 4,
1657
+ header.numPoints * getSphericalHarmonicsComponentCount(header.shDegree)
1658
+ ].filter((byteLength) => byteLength > 0);
1659
+ }
1660
+ function validateSPZStreamLengths(streams, streamInfos) {
1661
+ for (let streamIndex = 0; streamIndex < streams.length; streamIndex++) {
1662
+ if (streams[streamIndex].byteLength !== streamInfos[streamIndex].uncompressedSize) {
1663
+ throw new Error(`SPZLoader: decompressed stream ${streamIndex} has unexpected byte length.`);
1664
+ }
1665
+ }
1666
+ }
1667
+ function decodeSPZStreams(header, streams, sourceData) {
1668
+ const splatCount = header.numPoints;
1669
+ const positions = new Float32Array(splatCount * 3);
1670
+ const scales = new Float32Array(splatCount * 3);
1671
+ const rotations = new Float32Array(splatCount * 4);
1672
+ const colors = new Uint8Array(splatCount * 3);
1673
+ const sphericalHarmonicDcs = new Float32Array(splatCount * 3);
1674
+ const opacities = new Float32Array(splatCount);
1675
+ const sphericalHarmonicsComponentCount = getSphericalHarmonicsComponentCount(header.shDegree);
1676
+ const sphericalHarmonics = sphericalHarmonicsComponentCount ? new Float32Array(splatCount * sphericalHarmonicsComponentCount) : void 0;
1677
+ const [positionStream, alphaStream, colorStream, scaleStream, rotationStream, sphericalHarmonicsStream] = streams.map((stream) => new Uint8Array(stream));
1678
+ decodeSPZPositions(positionStream, positions, header.fractionalBits);
1679
+ decodeSPZScales(scaleStream, scales);
1680
+ decodeSPZRotations(rotationStream, rotations);
1681
+ decodeSPZColors(colorStream, colors, sphericalHarmonicDcs);
1682
+ decodeSPZOpacities(alphaStream, opacities);
1683
+ if (sphericalHarmonics && sphericalHarmonicsStream) {
1684
+ decodeSPZSphericalHarmonics(sphericalHarmonicsStream, sphericalHarmonics);
1685
+ }
1686
+ return {
1687
+ format: "spz",
1688
+ splatCount,
1689
+ positions,
1690
+ scales,
1691
+ rotations,
1692
+ colors,
1693
+ sphericalHarmonicDcs,
1694
+ opacities,
1695
+ sphericalHarmonics,
1696
+ sphericalHarmonicsComponentCount,
1697
+ loaderData: {
1698
+ format: "spz",
1699
+ ...header,
1700
+ antialiased: Boolean(header.flags & 1),
1701
+ extensionByteLength: getSPZExtensionByteLength(header),
1702
+ extensionBytes: getSPZExtensionBytes(sourceData, header)
1703
+ }
1704
+ };
1705
+ }
1706
+ function decodeSPZPositions(positionStream, positions, fractionalBits) {
1707
+ const scale = 1 / 2 ** fractionalBits;
1708
+ for (let componentIndex = 0; componentIndex < positions.length; componentIndex++) {
1709
+ const byteOffset = componentIndex * 3;
1710
+ let fixed32 = positionStream[byteOffset] | positionStream[byteOffset + 1] << 8 | positionStream[byteOffset + 2] << 16;
1711
+ fixed32 |= fixed32 & 8388608 ? 4278190080 : 0;
1712
+ positions[componentIndex] = fixed32 * scale;
1713
+ }
1714
+ }
1715
+ function decodeSPZScales(scaleStream, scales) {
1716
+ for (let componentIndex = 0; componentIndex < scales.length; componentIndex++) {
1717
+ scales[componentIndex] = Math.exp(scaleStream[componentIndex] / 16 - 10);
1718
+ }
1719
+ }
1720
+ function decodeSPZRotations(rotationStream, rotations) {
1721
+ for (let splatIndex = 0; splatIndex < rotations.length / 4; splatIndex++) {
1722
+ const byteOffset = splatIndex * 4;
1723
+ const component = rotationStream[byteOffset] | rotationStream[byteOffset + 1] << 8 | rotationStream[byteOffset + 2] << 16 | rotationStream[byteOffset + 3] << 24;
1724
+ const xyzw = decodeSPZQuaternion(component >>> 0);
1725
+ const [w, x, y, z2] = normalizeQuaternion(xyzw[3], xyzw[0], xyzw[1], xyzw[2]);
1726
+ const rotationOffset = splatIndex * 4;
1727
+ rotations[rotationOffset + 0] = w;
1728
+ rotations[rotationOffset + 1] = x;
1729
+ rotations[rotationOffset + 2] = y;
1730
+ rotations[rotationOffset + 3] = z2;
1731
+ }
1732
+ }
1733
+ function decodeSPZQuaternion(component) {
1734
+ const rotation = [0, 0, 0, 0];
1735
+ const largestComponent = component >>> 30;
1736
+ let remainingBits = component;
1737
+ let sumSquares = 0;
1738
+ for (let componentIndex = 3; componentIndex >= 0; componentIndex--) {
1739
+ if (componentIndex !== largestComponent) {
1740
+ const magnitude = remainingBits & SPZ_ROTATION_COMPONENT_MASK;
1741
+ const isNegative = remainingBits >>> 9 & 1;
1742
+ remainingBits >>>= 10;
1743
+ let value = SPZ_ROTATION_COMPONENT_SCALE * magnitude / SPZ_ROTATION_COMPONENT_MASK;
1744
+ if (isNegative) {
1745
+ value = -value;
1535
1746
  }
1536
- };
1747
+ rotation[componentIndex] = value;
1748
+ sumSquares += value * value;
1749
+ }
1537
1750
  }
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"() {
1751
+ rotation[largestComponent] = Math.sqrt(Math.max(0, 1 - sumSquares));
1752
+ return rotation;
1753
+ }
1754
+ function decodeSPZColors(colorStream, colors, sphericalHarmonicDcs) {
1755
+ for (let componentIndex = 0; componentIndex < colors.length; componentIndex++) {
1756
+ sphericalHarmonicDcs[componentIndex] = (colorStream[componentIndex] / 255 - 0.5) / SPZ_COLOR_SCALE;
1757
+ colors[componentIndex] = normalizeColorByte(sphericalHarmonicDcs[componentIndex]);
1758
+ }
1759
+ }
1760
+ function decodeSPZOpacities(alphaStream, opacities) {
1761
+ for (let splatIndex = 0; splatIndex < opacities.length; splatIndex++) {
1762
+ opacities[splatIndex] = alphaStream[splatIndex] / 255;
1763
+ }
1764
+ }
1765
+ function decodeSPZSphericalHarmonics(sphericalHarmonicsStream, sphericalHarmonics) {
1766
+ for (let componentIndex = 0; componentIndex < sphericalHarmonics.length; componentIndex++) {
1767
+ sphericalHarmonics[componentIndex] = (sphericalHarmonicsStream[componentIndex] - 128) / 128;
1768
+ }
1769
+ }
1770
+ function normalizeColorByte(sphericalHarmonicDc) {
1771
+ return Math.min(Math.max(Math.round((sphericalHarmonicDc * SPZ_COLOR_SCALE + 0.5) * 255), 0), 255);
1772
+ }
1773
+ function getSphericalHarmonicsComponentCount(shDegree) {
1774
+ switch (shDegree) {
1775
+ case 0:
1776
+ return 0;
1777
+ case 1:
1778
+ return 9;
1779
+ case 2:
1780
+ return 24;
1781
+ case 3:
1782
+ return 45;
1783
+ case 4:
1784
+ return 72;
1785
+ default:
1786
+ throw new Error(`SPZLoader: spherical harmonics degree ${shDegree} is not supported.`);
1787
+ }
1788
+ }
1789
+ function getSPZExtensionByteLength(header) {
1790
+ return header.flags & SPZ_EXTENSION_FLAG ? header.tocByteOffset - SPZ_HEADER_BYTE_LENGTH : 0;
1791
+ }
1792
+ function getSPZExtensionBytes(data, header) {
1793
+ const extensionByteLength = getSPZExtensionByteLength(header);
1794
+ return extensionByteLength ? new Uint8Array(data.slice(SPZ_HEADER_BYTE_LENGTH, header.tocByteOffset)) : void 0;
1795
+ }
1796
+ var SPZ_HEADER_BYTE_LENGTH, SPZ_MAGIC, SPZ_VERSION, SPZ_EXTENSION_FLAG, SPZ_COLOR_SCALE, SPZ_ROTATION_COMPONENT_SCALE, SPZ_ROTATION_COMPONENT_MASK;
1797
+ var init_parse_spz = __esm({
1798
+ "dist/lib/parse-spz.js"() {
1544
1799
  "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);
1554
- }
1555
- /** Decompresses one Zstandard frame synchronously. */
1556
- decompressSync(input) {
1557
- return (0, import_fzstd.decompress)(new Uint8Array(input)).slice().buffer;
1558
- }
1559
- };
1800
+ init_src2();
1801
+ init_splats_arrow_table();
1802
+ init_splat_utils();
1803
+ SPZ_HEADER_BYTE_LENGTH = 32;
1804
+ SPZ_MAGIC = 1347635022;
1805
+ SPZ_VERSION = 4;
1806
+ SPZ_EXTENSION_FLAG = 2;
1807
+ SPZ_COLOR_SCALE = 0.15;
1808
+ SPZ_ROTATION_COMPONENT_SCALE = Math.SQRT1_2;
1809
+ SPZ_ROTATION_COMPONENT_MASK = (1 << 9) - 1;
1560
1810
  }
1561
1811
  });
1562
1812
 
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);
1813
+ // dist/lib/parse-splat.js
1814
+ function parseSPLAT(data) {
1815
+ return makeGaussianSplatsArrowTable(parseSPLATToGaussianSplats(data));
1570
1816
  }
1571
- var import_fzstd2;
1572
- var init_zstd_fallback = __esm({
1573
- "../compression/src/zstd-fallback.ts"() {
1574
- "use strict";
1575
- import_fzstd2 = require("fzstd");
1817
+ function parseSPLATToGaussianSplats(data) {
1818
+ if (data.byteLength % SPLAT_ROW_BYTE_LENGTH !== 0) {
1819
+ throw new Error(`SPLATLoader: byte length must be a multiple of ${SPLAT_ROW_BYTE_LENGTH}.`);
1576
1820
  }
1577
- });
1578
-
1579
- // ../compression/src/lib/zstd-compression.ts
1580
- var zstd_compression_exports = {};
1581
- __export(zstd_compression_exports, {
1582
- ZstdCompression: () => ZstdCompression
1583
- });
1584
- var CHUNK_SIZE, zstdPromise, zstd, ZstdCompression;
1585
- var init_zstd_compression = __esm({
1586
- "../compression/src/lib/zstd-compression.ts"() {
1587
- "use strict";
1588
- init_compression();
1589
- init_src();
1590
- init_compression_stream();
1591
- init_decompression_stream();
1592
- CHUNK_SIZE = 1e6;
1593
- ZstdCompression = class extends Compression {
1594
- name = "zstd";
1595
- extensions = [];
1596
- contentEncodings = [];
1597
- isSupported = true;
1598
- options;
1599
- /**
1600
- * zstd-codec is an injectable dependency due to big size
1601
- * @param options
1602
- */
1603
- constructor(options = {}) {
1604
- super(options);
1605
- this.options = options;
1606
- registerJSModules(options == null ? void 0 : options.modules);
1607
- }
1608
- async preload(modules = {}) {
1609
- registerJSModules(modules);
1610
- const ZstdCodec = getJSModuleOrNull("zstd-codec");
1611
- if (!zstdPromise && ZstdCodec) {
1612
- zstdPromise = new Promise((resolve) => ZstdCodec.run((zstd2) => resolve(zstd2)));
1613
- }
1614
- if (zstdPromise) {
1615
- zstd = await zstdPromise;
1616
- }
1617
- }
1618
- compressSync(input) {
1619
- getJSModule("zstd-codec", this.name);
1620
- const simpleZstd = new zstd.Simple();
1621
- const inputArray = new Uint8Array(input);
1622
- return simpleZstd.compress(inputArray).buffer;
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
- }
1633
- decompressSync(input) {
1634
- getJSModule("zstd-codec", this.name);
1635
- const simpleZstd = new zstd.Simple();
1636
- const inputArray = new Uint8Array(input);
1637
- return simpleZstd.decompress(inputArray).buffer;
1638
- }
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
- }
1645
- await this.preload();
1646
- const inputArray = new Uint8Array(input);
1647
- if (!zstd) {
1648
- const { decompressZstd: decompressZstd2 } = await Promise.resolve().then(() => (init_zstd_fallback(), zstd_fallback_exports));
1649
- return ensureArrayBuffer(decompressZstd2(inputArray));
1650
- }
1651
- const simpleZstd = new zstd.Streaming();
1652
- const chunks = [];
1653
- for (let i = 0; i <= inputArray.length; i += CHUNK_SIZE) {
1654
- const chunkView = inputArray.subarray(i, i + CHUNK_SIZE);
1655
- const chunkArrayBuffer = ensureArrayBuffer(chunkView);
1656
- chunks.push(new Uint8Array(chunkArrayBuffer));
1657
- }
1658
- const decompressResult = await simpleZstd.decompressChunks(chunks);
1659
- return decompressResult.buffer;
1660
- }
1661
- };
1821
+ const splatCount = data.byteLength / SPLAT_ROW_BYTE_LENGTH;
1822
+ const dataView = new DataView(data);
1823
+ const positions = new Float32Array(splatCount * 3);
1824
+ const scales = new Float32Array(splatCount * 3);
1825
+ const rotations = new Float32Array(splatCount * 4);
1826
+ const colors = new Uint8Array(splatCount * 3);
1827
+ const opacities = new Float32Array(splatCount);
1828
+ for (let splatIndex = 0; splatIndex < splatCount; splatIndex++) {
1829
+ const byteOffset = splatIndex * SPLAT_ROW_BYTE_LENGTH;
1830
+ const positionOffset = splatIndex * 3;
1831
+ const rotationOffset = splatIndex * 4;
1832
+ positions[positionOffset + 0] = dataView.getFloat32(byteOffset + 0, true);
1833
+ positions[positionOffset + 1] = dataView.getFloat32(byteOffset + 4, true);
1834
+ positions[positionOffset + 2] = dataView.getFloat32(byteOffset + 8, true);
1835
+ scales[positionOffset + 0] = dataView.getFloat32(byteOffset + 12, true);
1836
+ scales[positionOffset + 1] = dataView.getFloat32(byteOffset + 16, true);
1837
+ scales[positionOffset + 2] = dataView.getFloat32(byteOffset + 20, true);
1838
+ colors[positionOffset + 0] = dataView.getUint8(byteOffset + 24);
1839
+ colors[positionOffset + 1] = dataView.getUint8(byteOffset + 25);
1840
+ colors[positionOffset + 2] = dataView.getUint8(byteOffset + 26);
1841
+ opacities[splatIndex] = convertAlphaByteToLinearOpacity(dataView.getUint8(byteOffset + 27));
1842
+ 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)));
1843
+ rotations[rotationOffset + 0] = w;
1844
+ rotations[rotationOffset + 1] = x;
1845
+ rotations[rotationOffset + 2] = y;
1846
+ rotations[rotationOffset + 3] = z2;
1662
1847
  }
1663
- });
1664
-
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"() {
1848
+ return {
1849
+ format: "splat",
1850
+ splatCount,
1851
+ positions,
1852
+ scales,
1853
+ rotations,
1854
+ colors,
1855
+ opacities,
1856
+ loaderData: {
1857
+ format: "splat",
1858
+ splatCount,
1859
+ rowByteLength: SPLAT_ROW_BYTE_LENGTH
1860
+ }
1861
+ };
1862
+ }
1863
+ var SPLAT_ROW_BYTE_LENGTH;
1864
+ var init_parse_splat = __esm({
1865
+ "dist/lib/parse-splat.js"() {
1673
1866
  "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
- };
1867
+ init_splats_arrow_table();
1868
+ init_splat_utils();
1869
+ SPLAT_ROW_BYTE_LENGTH = 32;
1731
1870
  }
1732
1871
  });
1733
1872
 
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
- }
1873
+ // dist/splat-loader.js
1874
+ var splat_loader_exports = {};
1875
+ __export(splat_loader_exports, {
1876
+ SPLATLoaderWithParser: () => SPLATLoaderWithParser
1757
1877
  });
1758
-
1759
- // ../compression/src/index.ts
1760
- var init_src2 = __esm({
1761
- "../compression/src/index.ts"() {
1878
+ var _SPLATLoaderPreload, SPLATLoaderMetadataWithoutPreload, SPLATLoaderWithParser;
1879
+ var init_splat_loader = __esm({
1880
+ "dist/splat-loader.js"() {
1762
1881
  "use strict";
1763
- init_default_codecs();
1882
+ init_parse_splat();
1883
+ init_splat_loader_types();
1884
+ ({ preload: _SPLATLoaderPreload, ...SPLATLoaderMetadataWithoutPreload } = SPLATLoader);
1885
+ SPLATLoaderWithParser = {
1886
+ ...SPLATLoaderMetadataWithoutPreload,
1887
+ parse: async (arrayBuffer) => parseSPLAT(arrayBuffer),
1888
+ parseSync: (arrayBuffer) => parseSPLAT(arrayBuffer)
1889
+ };
1764
1890
  }
1765
1891
  });
1766
1892
 
1767
- // dist/lib/parse-spz.js
1768
- async function parseSPZ(data, options) {
1769
- return makeGaussianSplatsArrowTable(await parseSPZToGaussianSplats(data, options));
1770
- }
1771
- async function parseSPZToGaussianSplats(data, options) {
1772
- const header = parseSPZHeader(data);
1773
- const streamInfos = parseSPZStreamInfos(data, header, getSPZStreamByteLengths(header));
1774
- const compressedStreams = streamInfos.map((streamInfo) => data.slice(streamInfo.compressedOffset, streamInfo.compressedOffset + streamInfo.compressedSize));
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)));
1777
- validateSPZStreamLengths(streams, streamInfos);
1778
- return decodeSPZStreams(header, streams, data);
1893
+ // dist/splat-loader-types.js
1894
+ async function preload() {
1895
+ const { SPLATLoaderWithParser: SPLATLoaderWithParser2 } = await Promise.resolve().then(() => (init_splat_loader(), splat_loader_exports));
1896
+ return SPLATLoaderWithParser2;
1779
1897
  }
1780
- function parseSPZHeader(data) {
1781
- if (data.byteLength < SPZ_HEADER_BYTE_LENGTH) {
1782
- throw new Error(`SPZLoader: file must contain a ${SPZ_HEADER_BYTE_LENGTH}-byte header.`);
1783
- }
1784
- const dataView = new DataView(data);
1785
- const header = {
1786
- magic: dataView.getUint32(0, true),
1787
- version: dataView.getUint32(4, true),
1788
- numPoints: dataView.getUint32(8, true),
1789
- shDegree: dataView.getUint8(12),
1790
- fractionalBits: dataView.getUint8(13),
1791
- flags: dataView.getUint8(14),
1792
- numStreams: dataView.getUint8(15),
1793
- tocByteOffset: dataView.getUint32(16, true)
1794
- };
1795
- if (header.magic !== SPZ_MAGIC) {
1796
- throw new Error("SPZLoader: NGSP magic header not found.");
1797
- }
1798
- if (header.version !== SPZ_VERSION) {
1799
- throw new Error(`SPZLoader: version ${header.version} is not supported.`);
1800
- }
1801
- if (header.shDegree > 4) {
1802
- throw new Error(`SPZLoader: spherical harmonics degree ${header.shDegree} is not supported.`);
1803
- }
1804
- if (header.tocByteOffset < SPZ_HEADER_BYTE_LENGTH || header.tocByteOffset > data.byteLength) {
1805
- throw new Error("SPZLoader: invalid table of contents byte offset.");
1898
+ var VERSION2, SPLATLoader;
1899
+ var init_splat_loader_types = __esm({
1900
+ "dist/splat-loader-types.js"() {
1901
+ "use strict";
1902
+ init_splats_format();
1903
+ VERSION2 = true ? "5.0.0-alpha.7" : "latest";
1904
+ SPLATLoader = {
1905
+ dataType: null,
1906
+ batchType: null,
1907
+ ...SPLATFormat,
1908
+ version: VERSION2,
1909
+ options: {
1910
+ splats: {
1911
+ shape: "arrow-table"
1912
+ }
1913
+ },
1914
+ preload
1915
+ };
1806
1916
  }
1807
- return header;
1917
+ });
1918
+
1919
+ // dist/lib/parse-ksplat.js
1920
+ function parseKSPLAT(data) {
1921
+ return makeGaussianSplatsArrowTable(parseKSPLATToGaussianSplats(data));
1808
1922
  }
1809
- function parseSPZStreamInfos(data, header, expectedUncompressedSizes) {
1810
- if (header.numStreams !== expectedUncompressedSizes.length) {
1811
- throw new Error(`SPZLoader: expected ${expectedUncompressedSizes.length} streams, found ${header.numStreams}.`);
1812
- }
1813
- const tocByteLength = header.numStreams * 16;
1814
- const tocEnd = header.tocByteOffset + tocByteLength;
1815
- if (tocEnd > data.byteLength) {
1816
- throw new Error("SPZLoader: table of contents exceeds file byte length.");
1923
+ function parseKSPLATToGaussianSplats(data) {
1924
+ if (data.byteLength < HEADER_BYTE_LENGTH) {
1925
+ throw new Error(`KSPLATLoader: file must contain a ${HEADER_BYTE_LENGTH}-byte header.`);
1817
1926
  }
1818
- const dataView = new DataView(data);
1819
- let compressedOffset = tocEnd;
1820
- const streamInfos = [];
1821
- for (let streamIndex = 0; streamIndex < header.numStreams; streamIndex++) {
1822
- const tocOffset = header.tocByteOffset + streamIndex * 16;
1823
- const compressedSize = readSafeUint64(dataView, tocOffset);
1824
- const uncompressedSize = readSafeUint64(dataView, tocOffset + 8);
1825
- const expectedUncompressedSize = expectedUncompressedSizes[streamIndex];
1826
- if (uncompressedSize !== expectedUncompressedSize) {
1827
- throw new Error(`SPZLoader: stream ${streamIndex} has ${uncompressedSize} uncompressed bytes, expected ${expectedUncompressedSize}.`);
1828
- }
1829
- if (compressedOffset + compressedSize > data.byteLength) {
1830
- throw new Error(`SPZLoader: stream ${streamIndex} exceeds file byte length.`);
1927
+ const header = parseKSPLATHeader(data);
1928
+ checkKSPLATVersion(header);
1929
+ const sections = parseKSPLATSections(data, header);
1930
+ const splatCount = getTotalSplatCount(header, sections);
1931
+ const sphericalHarmonicsComponentCount = Math.max(0, ...sections.slice(0, getActiveSectionCount(header)).map((section) => getSphericalHarmonicsComponentCount2(section.sphericalHarmonicsDegree)));
1932
+ const positions = new Float32Array(splatCount * 3);
1933
+ const scales = new Float32Array(splatCount * 3);
1934
+ const rotations = new Float32Array(splatCount * 4);
1935
+ const colors = new Uint8Array(splatCount * 3);
1936
+ const opacities = new Float32Array(splatCount);
1937
+ const sphericalHarmonics = sphericalHarmonicsComponentCount ? new Float32Array(splatCount * sphericalHarmonicsComponentCount) : void 0;
1938
+ let outputSplatIndex = 0;
1939
+ for (const section of sections.slice(0, getActiveSectionCount(header))) {
1940
+ validateSectionBounds(data, section);
1941
+ for (let localSplatIndex = 0; localSplatIndex < section.splatCount && outputSplatIndex < splatCount; localSplatIndex++) {
1942
+ decodeKSPLATSplat(data, header, section, localSplatIndex, outputSplatIndex, positions, scales, rotations, colors, opacities, sphericalHarmonics, sphericalHarmonicsComponentCount);
1943
+ outputSplatIndex++;
1831
1944
  }
1832
- streamInfos.push({ compressedSize, uncompressedSize, compressedOffset });
1833
- compressedOffset += compressedSize;
1834
1945
  }
1835
- if (compressedOffset !== data.byteLength) {
1836
- throw new Error("SPZLoader: compressed stream byte lengths do not match file byte length.");
1837
- }
1838
- return streamInfos;
1946
+ return {
1947
+ format: "ksplat",
1948
+ splatCount,
1949
+ positions,
1950
+ scales,
1951
+ rotations,
1952
+ colors,
1953
+ opacities,
1954
+ sphericalHarmonics,
1955
+ sphericalHarmonicsComponentCount,
1956
+ loaderData: {
1957
+ format: "ksplat",
1958
+ ...header,
1959
+ sections: sections.slice(0, getActiveSectionCount(header)).map((section) => ({
1960
+ splatCount: section.splatCount,
1961
+ maxSplatCount: section.maxSplatCount,
1962
+ sphericalHarmonicsDegree: section.sphericalHarmonicsDegree
1963
+ }))
1964
+ }
1965
+ };
1839
1966
  }
1840
- function readSafeUint64(dataView, byteOffset) {
1841
- const value = dataView.getBigUint64(byteOffset, true);
1842
- if (value > BigInt(Number.MAX_SAFE_INTEGER)) {
1843
- throw new Error("SPZLoader: stream byte length exceeds Number.MAX_SAFE_INTEGER.");
1967
+ function decodeKSPLATSplat(data, header, section, localSplatIndex, outputSplatIndex, positions, scales, rotations, colors, opacities, sphericalHarmonics, sphericalHarmonicsComponentCount) {
1968
+ const layout = COMPRESSION_LAYOUTS[header.compressionLevel];
1969
+ const splatBase = section.dataBase + section.bytesPerSplat * localSplatIndex;
1970
+ const positionOffset = outputSplatIndex * 3;
1971
+ const rotationOffset = outputSplatIndex * 4;
1972
+ const bucketCenter = getBucketCenter(data, section, localSplatIndex);
1973
+ positions[positionOffset + 0] = decodeKSPLATCenterComponent(data, splatBase, 0, header, section, bucketCenter[0]);
1974
+ positions[positionOffset + 1] = decodeKSPLATCenterComponent(data, splatBase, 1, header, section, bucketCenter[1]);
1975
+ positions[positionOffset + 2] = decodeKSPLATCenterComponent(data, splatBase, 2, header, section, bucketCenter[2]);
1976
+ scales[positionOffset + 0] = readCompressedFloat(data, splatBase + layout.scaleOffsetBytes, 0, header.compressionLevel);
1977
+ scales[positionOffset + 1] = readCompressedFloat(data, splatBase + layout.scaleOffsetBytes, 1, header.compressionLevel);
1978
+ scales[positionOffset + 2] = readCompressedFloat(data, splatBase + layout.scaleOffsetBytes, 2, header.compressionLevel);
1979
+ 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));
1980
+ rotations[rotationOffset + 0] = w;
1981
+ rotations[rotationOffset + 1] = x;
1982
+ rotations[rotationOffset + 2] = y;
1983
+ rotations[rotationOffset + 3] = z2;
1984
+ const colorBase = splatBase + layout.colorOffsetBytes;
1985
+ const colorView = new Uint8Array(data, colorBase, 4);
1986
+ colors[positionOffset + 0] = colorView[0];
1987
+ colors[positionOffset + 1] = colorView[1];
1988
+ colors[positionOffset + 2] = colorView[2];
1989
+ opacities[outputSplatIndex] = convertAlphaByteToLinearOpacity(colorView[3]);
1990
+ if (sphericalHarmonics && sphericalHarmonicsComponentCount) {
1991
+ decodeSphericalHarmonics(data, splatBase + layout.sphericalHarmonicsOffsetBytes, header, section, outputSplatIndex, sphericalHarmonics, sphericalHarmonicsComponentCount);
1844
1992
  }
1845
- return Number(value);
1846
1993
  }
1847
- function getSPZStreamByteLengths(header) {
1848
- return [
1849
- header.numPoints * 9,
1850
- header.numPoints,
1851
- header.numPoints * 3,
1852
- header.numPoints * 3,
1853
- header.numPoints * 4,
1854
- header.numPoints * getSphericalHarmonicsComponentCount2(header.shDegree)
1855
- ].filter((byteLength) => byteLength > 0);
1994
+ function parseKSPLATHeader(data) {
1995
+ const dataView = new DataView(data, 0, HEADER_BYTE_LENGTH);
1996
+ const compressionLevel = dataView.getUint16(20, true);
1997
+ if (compressionLevel !== 0 && compressionLevel !== 1 && compressionLevel !== 2) {
1998
+ throw new Error(`KSPLATLoader: unsupported compression level ${compressionLevel}.`);
1999
+ }
2000
+ return {
2001
+ versionMajor: dataView.getUint8(0),
2002
+ versionMinor: dataView.getUint8(1),
2003
+ maxSectionCount: dataView.getUint32(4, true),
2004
+ sectionCount: dataView.getUint32(8, true),
2005
+ maxSplatCount: dataView.getUint32(12, true),
2006
+ splatCount: dataView.getUint32(16, true),
2007
+ compressionLevel,
2008
+ minSphericalHarmonicsCoeff: dataView.getFloat32(36, true) || -DEFAULT_SH_8BIT_COMPRESSION_HALF_RANGE,
2009
+ maxSphericalHarmonicsCoeff: dataView.getFloat32(40, true) || DEFAULT_SH_8BIT_COMPRESSION_HALF_RANGE
2010
+ };
1856
2011
  }
1857
- function validateSPZStreamLengths(streams, streamInfos) {
1858
- for (let streamIndex = 0; streamIndex < streams.length; streamIndex++) {
1859
- if (streams[streamIndex].byteLength !== streamInfos[streamIndex].uncompressedSize) {
1860
- throw new Error(`SPZLoader: decompressed stream ${streamIndex} has unexpected byte length.`);
1861
- }
2012
+ function checkKSPLATVersion(header) {
2013
+ if (header.versionMajor === CURRENT_MAJOR_VERSION ? header.versionMinor >= CURRENT_MINOR_VERSION : header.versionMajor > CURRENT_MAJOR_VERSION) {
2014
+ return;
1862
2015
  }
2016
+ throw new Error(`KSPLATLoader: version ${header.versionMajor}.${header.versionMinor} is not supported.`);
1863
2017
  }
1864
- function decodeSPZStreams(header, streams, sourceData) {
1865
- const splatCount = header.numPoints;
1866
- const positions = new Float32Array(splatCount * 3);
1867
- const scales = new Float32Array(splatCount * 3);
1868
- const rotations = new Float32Array(splatCount * 4);
1869
- const colors = new Uint8Array(splatCount * 3);
1870
- const sphericalHarmonicDcs = new Float32Array(splatCount * 3);
1871
- const opacities = new Float32Array(splatCount);
1872
- const sphericalHarmonicsComponentCount = getSphericalHarmonicsComponentCount2(header.shDegree);
1873
- const sphericalHarmonics = sphericalHarmonicsComponentCount ? new Float32Array(splatCount * sphericalHarmonicsComponentCount) : void 0;
1874
- const [positionStream, alphaStream, colorStream, scaleStream, rotationStream, sphericalHarmonicsStream] = streams.map((stream) => new Uint8Array(stream));
1875
- decodeSPZPositions(positionStream, positions, header.fractionalBits);
1876
- decodeSPZScales(scaleStream, scales);
1877
- decodeSPZRotations(rotationStream, rotations);
1878
- decodeSPZColors(colorStream, colors, sphericalHarmonicDcs);
1879
- decodeSPZOpacities(alphaStream, opacities);
1880
- if (sphericalHarmonics && sphericalHarmonicsStream) {
1881
- decodeSPZSphericalHarmonics(sphericalHarmonicsStream, sphericalHarmonics);
2018
+ function parseKSPLATSections(data, header) {
2019
+ if (data.byteLength < HEADER_BYTE_LENGTH + header.maxSectionCount * SECTION_HEADER_BYTE_LENGTH) {
2020
+ throw new Error("KSPLATLoader: file does not contain all section headers.");
2021
+ }
2022
+ const sections = [];
2023
+ let sectionBase = HEADER_BYTE_LENGTH + header.maxSectionCount * SECTION_HEADER_BYTE_LENGTH;
2024
+ let splatCountOffset = 0;
2025
+ for (let sectionIndex = 0; sectionIndex < header.maxSectionCount; sectionIndex++) {
2026
+ const sectionHeaderBase = HEADER_BYTE_LENGTH + sectionIndex * SECTION_HEADER_BYTE_LENGTH;
2027
+ const dataView = new DataView(data, sectionHeaderBase, SECTION_HEADER_BYTE_LENGTH);
2028
+ const splatCount = dataView.getUint32(0, true);
2029
+ const maxSplatCount = dataView.getUint32(4, true);
2030
+ const bucketSize = dataView.getUint32(8, true);
2031
+ const bucketCount = dataView.getUint32(12, true);
2032
+ const bucketBlockSize = dataView.getFloat32(16, true);
2033
+ const bucketStorageSizeBytes = dataView.getUint16(20, true);
2034
+ const compressionScaleRange = dataView.getUint32(24, true) || COMPRESSION_LAYOUTS[header.compressionLevel].scaleRange;
2035
+ const fullBucketCount = dataView.getUint32(32, true);
2036
+ const partiallyFilledBucketCount = dataView.getUint32(36, true);
2037
+ const sphericalHarmonicsDegree = dataView.getUint16(40, true);
2038
+ const bytesPerSplat = getBytesPerSplat(header.compressionLevel, sphericalHarmonicsDegree);
2039
+ const bucketsMetaDataSizeBytes = partiallyFilledBucketCount * 4;
2040
+ const bucketsStorageSizeBytes = bucketStorageSizeBytes * bucketCount + bucketsMetaDataSizeBytes;
2041
+ const storageSizeBytes = bytesPerSplat * maxSplatCount + bucketsStorageSizeBytes;
2042
+ sections.push({
2043
+ bytesPerSplat,
2044
+ splatCountOffset,
2045
+ splatCount: splatCount || maxSplatCount,
2046
+ maxSplatCount,
2047
+ bucketSize,
2048
+ bucketCount,
2049
+ bucketStorageSizeBytes,
2050
+ bucketsStorageSizeBytes,
2051
+ compressionScaleRange,
2052
+ compressionScaleFactor: bucketBlockSize / 2 / compressionScaleRange,
2053
+ base: sectionBase,
2054
+ bucketsBase: sectionBase + bucketsMetaDataSizeBytes,
2055
+ dataBase: sectionBase + bucketsStorageSizeBytes,
2056
+ fullBucketCount,
2057
+ partiallyFilledBucketCount,
2058
+ sphericalHarmonicsDegree
2059
+ });
2060
+ sectionBase += storageSizeBytes;
2061
+ splatCountOffset += maxSplatCount;
1882
2062
  }
1883
- return {
1884
- format: "spz",
1885
- splatCount,
1886
- positions,
1887
- scales,
1888
- rotations,
1889
- colors,
1890
- sphericalHarmonicDcs,
1891
- opacities,
1892
- sphericalHarmonics,
1893
- sphericalHarmonicsComponentCount,
1894
- loaderData: {
1895
- format: "spz",
1896
- ...header,
1897
- antialiased: Boolean(header.flags & 1),
1898
- extensionByteLength: getSPZExtensionByteLength(header),
1899
- extensionBytes: getSPZExtensionBytes(sourceData, header)
1900
- }
1901
- };
2063
+ return sections;
1902
2064
  }
1903
- function decodeSPZPositions(positionStream, positions, fractionalBits) {
1904
- const scale = 1 / 2 ** fractionalBits;
1905
- for (let componentIndex = 0; componentIndex < positions.length; componentIndex++) {
1906
- const byteOffset = componentIndex * 3;
1907
- let fixed32 = positionStream[byteOffset] | positionStream[byteOffset + 1] << 8 | positionStream[byteOffset + 2] << 16;
1908
- fixed32 |= fixed32 & 8388608 ? 4278190080 : 0;
1909
- positions[componentIndex] = fixed32 * scale;
1910
- }
2065
+ function decodeKSPLATCenterComponent(data, splatBase, component, header, section, bucketCenter) {
2066
+ const value = readCompressedCenterValue(data, splatBase, component, header.compressionLevel);
2067
+ return header.compressionLevel >= 1 ? (value - section.compressionScaleRange) * section.compressionScaleFactor + bucketCenter : value;
1911
2068
  }
1912
- function decodeSPZScales(scaleStream, scales) {
1913
- for (let componentIndex = 0; componentIndex < scales.length; componentIndex++) {
1914
- scales[componentIndex] = Math.exp(scaleStream[componentIndex] / 16 - 10);
1915
- }
2069
+ function readCompressedCenterValue(data, byteOffset, component, compressionLevel) {
2070
+ const dataView = new DataView(data);
2071
+ return compressionLevel === 0 ? dataView.getFloat32(byteOffset + component * 4, true) : dataView.getUint16(byteOffset + component * 2, true);
1916
2072
  }
1917
- function decodeSPZRotations(rotationStream, rotations) {
1918
- for (let splatIndex = 0; splatIndex < rotations.length / 4; splatIndex++) {
1919
- const byteOffset = splatIndex * 4;
1920
- const component = rotationStream[byteOffset] | rotationStream[byteOffset + 1] << 8 | rotationStream[byteOffset + 2] << 16 | rotationStream[byteOffset + 3] << 24;
1921
- const xyzw = decodeSPZQuaternion(component >>> 0);
1922
- const [w, x, y, z2] = normalizeQuaternion(xyzw[3], xyzw[0], xyzw[1], xyzw[2]);
1923
- const rotationOffset = splatIndex * 4;
1924
- rotations[rotationOffset + 0] = w;
1925
- rotations[rotationOffset + 1] = x;
1926
- rotations[rotationOffset + 2] = y;
1927
- rotations[rotationOffset + 3] = z2;
2073
+ function getBucketCenter(data, section, localSplatIndex) {
2074
+ if (!section.bucketCount) {
2075
+ return [0, 0, 0];
1928
2076
  }
2077
+ const bucketIndex = getBucketIndex(data, section, localSplatIndex);
2078
+ const bucketBase = section.bucketsBase + bucketIndex * section.bucketStorageSizeBytes;
2079
+ const dataView = new DataView(data, bucketBase, 12);
2080
+ return [dataView.getFloat32(0, true), dataView.getFloat32(4, true), dataView.getFloat32(8, true)];
1929
2081
  }
1930
- function decodeSPZQuaternion(component) {
1931
- const rotation = [0, 0, 0, 0];
1932
- const largestComponent = component >>> 30;
1933
- let remainingBits = component;
1934
- let sumSquares = 0;
1935
- for (let componentIndex = 3; componentIndex >= 0; componentIndex--) {
1936
- if (componentIndex !== largestComponent) {
1937
- const magnitude = remainingBits & SPZ_ROTATION_COMPONENT_MASK;
1938
- const isNegative = remainingBits >>> 9 & 1;
1939
- remainingBits >>>= 10;
1940
- let value = SPZ_ROTATION_COMPONENT_SCALE * magnitude / SPZ_ROTATION_COMPONENT_MASK;
1941
- if (isNegative) {
1942
- value = -value;
1943
- }
1944
- rotation[componentIndex] = value;
1945
- sumSquares += value * value;
2082
+ function getBucketIndex(data, section, localSplatIndex) {
2083
+ const maxSplatIndexInFullBuckets = section.fullBucketCount * section.bucketSize;
2084
+ if (localSplatIndex < maxSplatIndexInFullBuckets) {
2085
+ return Math.floor(localSplatIndex / section.bucketSize);
2086
+ }
2087
+ let bucketSplatIndex = maxSplatIndexInFullBuckets;
2088
+ let bucketIndex = section.fullBucketCount;
2089
+ for (let partiallyFilledBucketIndex = 0; partiallyFilledBucketIndex < section.partiallyFilledBucketCount; partiallyFilledBucketIndex++) {
2090
+ const bucketLength = new DataView(data, section.base + partiallyFilledBucketIndex * 4, 4).getUint32(0, true);
2091
+ if (localSplatIndex < bucketSplatIndex + bucketLength) {
2092
+ return bucketIndex;
1946
2093
  }
2094
+ bucketSplatIndex += bucketLength;
2095
+ bucketIndex++;
1947
2096
  }
1948
- rotation[largestComponent] = Math.sqrt(Math.max(0, 1 - sumSquares));
1949
- return rotation;
2097
+ return Math.max(bucketIndex - 1, 0);
1950
2098
  }
1951
- function decodeSPZColors(colorStream, colors, sphericalHarmonicDcs) {
1952
- for (let componentIndex = 0; componentIndex < colors.length; componentIndex++) {
1953
- sphericalHarmonicDcs[componentIndex] = (colorStream[componentIndex] / 255 - 0.5) / SPZ_COLOR_SCALE;
1954
- colors[componentIndex] = normalizeColorByte(sphericalHarmonicDcs[componentIndex]);
2099
+ function decodeSphericalHarmonics(data, byteOffset, header, section, outputSplatIndex, output, outputComponentCount) {
2100
+ const componentCount = getSphericalHarmonicsComponentCount2(section.sphericalHarmonicsDegree);
2101
+ const componentBase = outputSplatIndex * outputComponentCount;
2102
+ for (let component = 0; component < componentCount; component++) {
2103
+ output[componentBase + component] = readCompressedFloat(data, byteOffset, component, header.compressionLevel, true, header.minSphericalHarmonicsCoeff, header.maxSphericalHarmonicsCoeff);
1955
2104
  }
1956
2105
  }
1957
- function decodeSPZOpacities(alphaStream, opacities) {
1958
- for (let splatIndex = 0; splatIndex < opacities.length; splatIndex++) {
1959
- opacities[splatIndex] = alphaStream[splatIndex] / 255;
2106
+ function readCompressedFloat(data, byteOffset, component, compressionLevel, sphericalHarmonic = false, sphericalHarmonicRangeMin = 0, sphericalHarmonicRangeMax = 0) {
2107
+ const dataView = new DataView(data);
2108
+ if (compressionLevel === 0) {
2109
+ return dataView.getFloat32(byteOffset + component * 4, true);
1960
2110
  }
1961
- }
1962
- function decodeSPZSphericalHarmonics(sphericalHarmonicsStream, sphericalHarmonics) {
1963
- for (let componentIndex = 0; componentIndex < sphericalHarmonics.length; componentIndex++) {
1964
- sphericalHarmonics[componentIndex] = (sphericalHarmonicsStream[componentIndex] - 128) / 128;
2111
+ if (compressionLevel === 1 || !sphericalHarmonic) {
2112
+ return decodeFloat16(dataView.getUint16(byteOffset + component * 2, true));
1965
2113
  }
2114
+ const value = dataView.getUint8(byteOffset + component);
2115
+ return value / 255 * (sphericalHarmonicRangeMax - sphericalHarmonicRangeMin) + sphericalHarmonicRangeMin;
1966
2116
  }
1967
- function normalizeColorByte(sphericalHarmonicDc) {
1968
- return Math.min(Math.max(Math.round((sphericalHarmonicDc * SPZ_COLOR_SCALE + 0.5) * 255), 0), 255);
2117
+ function getBytesPerSplat(compressionLevel, sphericalHarmonicsDegree) {
2118
+ const layout = COMPRESSION_LAYOUTS[compressionLevel];
2119
+ return layout.bytesPerCenter + layout.bytesPerScale + layout.bytesPerRotation + layout.bytesPerColor + layout.bytesPerSphericalHarmonicsComponent * getSphericalHarmonicsComponentCount2(sphericalHarmonicsDegree);
1969
2120
  }
1970
- function getSphericalHarmonicsComponentCount2(shDegree) {
1971
- switch (shDegree) {
2121
+ function getSphericalHarmonicsComponentCount2(sphericalHarmonicsDegree) {
2122
+ switch (sphericalHarmonicsDegree) {
1972
2123
  case 0:
1973
2124
  return 0;
1974
2125
  case 1:
@@ -1977,33 +2128,116 @@ function getSphericalHarmonicsComponentCount2(shDegree) {
1977
2128
  return 24;
1978
2129
  case 3:
1979
2130
  return 45;
1980
- case 4:
1981
- return 72;
1982
2131
  default:
1983
- throw new Error(`SPZLoader: spherical harmonics degree ${shDegree} is not supported.`);
2132
+ throw new Error(`KSPLATLoader: unsupported spherical harmonics degree ${sphericalHarmonicsDegree}.`);
1984
2133
  }
1985
2134
  }
1986
- function getSPZExtensionByteLength(header) {
1987
- return header.flags & SPZ_EXTENSION_FLAG ? header.tocByteOffset - SPZ_HEADER_BYTE_LENGTH : 0;
2135
+ function getActiveSectionCount(header) {
2136
+ return header.sectionCount || header.maxSectionCount;
1988
2137
  }
1989
- function getSPZExtensionBytes(data, header) {
1990
- const extensionByteLength = getSPZExtensionByteLength(header);
1991
- return extensionByteLength ? new Uint8Array(data.slice(SPZ_HEADER_BYTE_LENGTH, header.tocByteOffset)) : void 0;
2138
+ function getTotalSplatCount(header, sections) {
2139
+ const sectionSplatCount = sections.slice(0, getActiveSectionCount(header)).reduce((splatCount, section) => splatCount + section.splatCount, 0);
2140
+ return header.splatCount ? Math.min(header.splatCount, sectionSplatCount || header.splatCount) : sectionSplatCount;
1992
2141
  }
1993
- var SPZ_HEADER_BYTE_LENGTH, SPZ_MAGIC, SPZ_VERSION, SPZ_EXTENSION_FLAG, SPZ_COLOR_SCALE, SPZ_ROTATION_COMPONENT_SCALE, SPZ_ROTATION_COMPONENT_MASK;
1994
- var init_parse_spz = __esm({
1995
- "dist/lib/parse-spz.js"() {
2142
+ function validateSectionBounds(data, section) {
2143
+ const requiredByteLength = section.dataBase + section.bytesPerSplat * section.splatCount;
2144
+ if (requiredByteLength > data.byteLength) {
2145
+ throw new Error("KSPLATLoader: section data extends beyond the file length.");
2146
+ }
2147
+ }
2148
+ var CURRENT_MAJOR_VERSION, CURRENT_MINOR_VERSION, HEADER_BYTE_LENGTH, SECTION_HEADER_BYTE_LENGTH, DEFAULT_SH_8BIT_COMPRESSION_RANGE, DEFAULT_SH_8BIT_COMPRESSION_HALF_RANGE, COMPRESSION_LAYOUTS;
2149
+ var init_parse_ksplat = __esm({
2150
+ "dist/lib/parse-ksplat.js"() {
1996
2151
  "use strict";
1997
- init_src2();
1998
2152
  init_splats_arrow_table();
1999
2153
  init_splat_utils();
2000
- SPZ_HEADER_BYTE_LENGTH = 32;
2001
- SPZ_MAGIC = 1347635022;
2002
- SPZ_VERSION = 4;
2003
- SPZ_EXTENSION_FLAG = 2;
2004
- SPZ_COLOR_SCALE = 0.15;
2005
- SPZ_ROTATION_COMPONENT_SCALE = Math.SQRT1_2;
2006
- SPZ_ROTATION_COMPONENT_MASK = (1 << 9) - 1;
2154
+ CURRENT_MAJOR_VERSION = 0;
2155
+ CURRENT_MINOR_VERSION = 1;
2156
+ HEADER_BYTE_LENGTH = 4096;
2157
+ SECTION_HEADER_BYTE_LENGTH = 1024;
2158
+ DEFAULT_SH_8BIT_COMPRESSION_RANGE = 3;
2159
+ DEFAULT_SH_8BIT_COMPRESSION_HALF_RANGE = DEFAULT_SH_8BIT_COMPRESSION_RANGE / 2;
2160
+ COMPRESSION_LAYOUTS = {
2161
+ 0: {
2162
+ bytesPerCenter: 12,
2163
+ bytesPerScale: 12,
2164
+ bytesPerRotation: 16,
2165
+ bytesPerColor: 4,
2166
+ scaleOffsetBytes: 12,
2167
+ colorOffsetBytes: 40,
2168
+ sphericalHarmonicsOffsetBytes: 44,
2169
+ scaleRange: 1,
2170
+ bytesPerSphericalHarmonicsComponent: 4
2171
+ },
2172
+ 1: {
2173
+ bytesPerCenter: 6,
2174
+ bytesPerScale: 6,
2175
+ bytesPerRotation: 8,
2176
+ bytesPerColor: 4,
2177
+ scaleOffsetBytes: 6,
2178
+ colorOffsetBytes: 20,
2179
+ sphericalHarmonicsOffsetBytes: 24,
2180
+ scaleRange: 32767,
2181
+ bytesPerSphericalHarmonicsComponent: 2
2182
+ },
2183
+ 2: {
2184
+ bytesPerCenter: 6,
2185
+ bytesPerScale: 6,
2186
+ bytesPerRotation: 8,
2187
+ bytesPerColor: 4,
2188
+ scaleOffsetBytes: 6,
2189
+ colorOffsetBytes: 20,
2190
+ sphericalHarmonicsOffsetBytes: 24,
2191
+ scaleRange: 32767,
2192
+ bytesPerSphericalHarmonicsComponent: 1
2193
+ }
2194
+ };
2195
+ }
2196
+ });
2197
+
2198
+ // dist/ksplat-loader.js
2199
+ var ksplat_loader_exports = {};
2200
+ __export(ksplat_loader_exports, {
2201
+ KSPLATLoaderWithParser: () => KSPLATLoaderWithParser
2202
+ });
2203
+ var _KSPLATLoaderPreload, KSPLATLoaderMetadataWithoutPreload, KSPLATLoaderWithParser;
2204
+ var init_ksplat_loader = __esm({
2205
+ "dist/ksplat-loader.js"() {
2206
+ "use strict";
2207
+ init_parse_ksplat();
2208
+ init_ksplat_loader_types();
2209
+ ({ preload: _KSPLATLoaderPreload, ...KSPLATLoaderMetadataWithoutPreload } = KSPLATLoader);
2210
+ KSPLATLoaderWithParser = {
2211
+ ...KSPLATLoaderMetadataWithoutPreload,
2212
+ parse: async (arrayBuffer) => parseKSPLAT(arrayBuffer),
2213
+ parseSync: (arrayBuffer) => parseKSPLAT(arrayBuffer)
2214
+ };
2215
+ }
2216
+ });
2217
+
2218
+ // dist/ksplat-loader-types.js
2219
+ async function preload2() {
2220
+ const { KSPLATLoaderWithParser: KSPLATLoaderWithParser2 } = await Promise.resolve().then(() => (init_ksplat_loader(), ksplat_loader_exports));
2221
+ return KSPLATLoaderWithParser2;
2222
+ }
2223
+ var VERSION3, KSPLATLoader;
2224
+ var init_ksplat_loader_types = __esm({
2225
+ "dist/ksplat-loader-types.js"() {
2226
+ "use strict";
2227
+ init_splats_format();
2228
+ VERSION3 = true ? "5.0.0-alpha.7" : "latest";
2229
+ KSPLATLoader = {
2230
+ dataType: null,
2231
+ batchType: null,
2232
+ ...KSPLATFormat,
2233
+ version: VERSION3,
2234
+ options: {
2235
+ splats: {
2236
+ shape: "arrow-table"
2237
+ }
2238
+ },
2239
+ preload: preload2
2240
+ };
2007
2241
  }
2008
2242
  });
2009
2243
 
@@ -2036,7 +2270,7 @@ var init_spz_loader_types = __esm({
2036
2270
  "dist/spz-loader-types.js"() {
2037
2271
  "use strict";
2038
2272
  init_splats_format();
2039
- VERSION4 = true ? "5.0.0-alpha.6" : "latest";
2273
+ VERSION4 = true ? "5.0.0-alpha.7" : "latest";
2040
2274
  SPZLoader = {
2041
2275
  dataType: null,
2042
2276
  batchType: null,
@@ -2210,31 +2444,12 @@ var init_parse_rad = __esm({
2210
2444
  }
2211
2445
  });
2212
2446
 
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
2447
  // ../compression/src/deflate-decompressor-fflate.ts
2233
- var import_fflate, DeflateFflateDecompressor;
2448
+ var import_fflate2, DeflateFflateDecompressor;
2234
2449
  var init_deflate_decompressor_fflate = __esm({
2235
2450
  "../compression/src/deflate-decompressor-fflate.ts"() {
2236
2451
  "use strict";
2237
- import_fflate = require("fflate");
2452
+ import_fflate2 = require("fflate");
2238
2453
  init_compression();
2239
2454
  init_fflate_stream();
2240
2455
  DeflateFflateDecompressor = class extends Decompressor {
@@ -2250,12 +2465,12 @@ var init_deflate_decompressor_fflate = __esm({
2250
2465
  /** Decompresses one zlib-wrapped DEFLATE payload synchronously. */
2251
2466
  decompressSync(input) {
2252
2467
  const bytes = new Uint8Array(input);
2253
- const output = this.options.raw ? (0, import_fflate.inflateSync)(bytes) : (0, import_fflate.unzlibSync)(bytes);
2468
+ const output = this.options.raw ? (0, import_fflate2.inflateSync)(bytes) : (0, import_fflate2.unzlibSync)(bytes);
2254
2469
  return output.slice().buffer;
2255
2470
  }
2256
2471
  /** Decompresses DEFLATE batches incrementally. */
2257
2472
  async *decompressBatches(inputBatches) {
2258
- const processor = this.options.raw ? new import_fflate.Inflate() : new import_fflate.Unzlib();
2473
+ const processor = this.options.raw ? new import_fflate2.Inflate() : new import_fflate2.Unzlib();
2259
2474
  yield* transformFflateBatches(processor, inputBatches);
2260
2475
  }
2261
2476
  };
@@ -2806,7 +3021,7 @@ var init_rad_loader_types = __esm({
2806
3021
  "dist/rad-loader-types.js"() {
2807
3022
  "use strict";
2808
3023
  init_splats_format();
2809
- VERSION5 = true ? "5.0.0-alpha.6" : "latest";
3024
+ VERSION5 = true ? "5.0.0-alpha.7" : "latest";
2810
3025
  RADLoader = {
2811
3026
  dataType: null,
2812
3027
  batchType: null,
@@ -2831,10 +3046,13 @@ __export(index_exports, {
2831
3046
  SPLATLoader: () => SPLATLoader,
2832
3047
  SPZFormat: () => SPZFormat,
2833
3048
  SPZLoader: () => SPZLoader,
3049
+ parseSPZ: () => parseSPZ,
3050
+ parseSPZToGaussianSplats: () => parseSPZToGaussianSplats,
2834
3051
  resolveRADChunkUrl: () => resolveRADChunkUrl
2835
3052
  });
2836
3053
  module.exports = __toCommonJS(index_exports);
2837
3054
  init_splats_format();
3055
+ init_parse_spz();
2838
3056
  init_splat_loader_types();
2839
3057
  init_ksplat_loader_types();
2840
3058
  init_spz_loader_types();
@@ -2848,7 +3066,7 @@ init_parse_rad_chunk();
2848
3066
  init_splats_arrow_table();
2849
3067
  var DEFAULT_RAD_HEADER_BYTE_LENGTHS = [64 * 1024, 256 * 1024, 1024 * 1024];
2850
3068
  var DEFAULT_RAD_MAX_CONCURRENT_CHUNK_REQUESTS = 4;
2851
- var VERSION6 = true ? "5.0.0-alpha.6" : "latest";
3069
+ var VERSION6 = true ? "5.0.0-alpha.7" : "latest";
2852
3070
  var RADSourceLoader = {
2853
3071
  dataType: null,
2854
3072
  batchType: null,