@loaders.gl/arcgis 5.0.0-alpha.10 → 5.0.0-alpha.11

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
@@ -9665,6 +9665,7 @@ var init_i3s_loader_options = __esm({
9665
9665
  decodeTextures: true,
9666
9666
  attributeValues: "legacy",
9667
9667
  colorFormat: "uint8norm",
9668
+ geometryMode: "render",
9668
9669
  coordinateSystem: COORDINATE_SYSTEM.METER_OFFSETS
9669
9670
  };
9670
9671
  }
@@ -13685,9 +13686,6 @@ var init_tileset_traverser = __esm({
13685
13686
  childRefines = child.contentAvailable;
13686
13687
  }
13687
13688
  refines = refines && childRefines;
13688
- if (!refines) {
13689
- return false;
13690
- }
13691
13689
  }
13692
13690
  }
13693
13691
  if (!hasVisibleChild) {
@@ -15028,16 +15026,20 @@ var init_format_spatial_reference = __esm({
15028
15026
  });
15029
15027
 
15030
15028
  // ../tiles/src/spatial/spatial-resource-registry.ts
15029
+ function getSpatialProjectionEngine() {
15030
+ return spatialProjectionEngine;
15031
+ }
15031
15032
  function getGeoidModel(name) {
15032
15033
  return geoidModels.get(name);
15033
15034
  }
15034
- var import_geoid, import_projection, geoidModels;
15035
+ var import_geoid, import_projection, geoidModels, spatialProjectionEngine;
15035
15036
  var init_spatial_resource_registry = __esm({
15036
15037
  "../tiles/src/spatial/spatial-resource-registry.ts"() {
15037
15038
  "use strict";
15038
15039
  import_geoid = require("@math.gl/geoid");
15039
15040
  import_projection = require("@math.gl/projection");
15040
15041
  geoidModels = /* @__PURE__ */ new Map();
15042
+ spatialProjectionEngine = new import_projection.FullProjectionEngine();
15041
15043
  }
15042
15044
  });
15043
15045
 
@@ -15142,13 +15144,12 @@ function transformHeight(height, geoidUndulation, source, target) {
15142
15144
  }
15143
15145
  throw new Error(`Unsupported height conversion from ${source} to ${target}`);
15144
15146
  }
15145
- var import_core7, import_geospatial4, import_projection2, SpatialCoordinateTransformer;
15147
+ var import_core7, import_geospatial4, SpatialCoordinateTransformer;
15146
15148
  var init_spatial_coordinate_transformer = __esm({
15147
15149
  "../tiles/src/spatial/spatial-coordinate-transformer.ts"() {
15148
15150
  "use strict";
15149
15151
  import_core7 = require("@math.gl/core");
15150
15152
  import_geospatial4 = require("@math.gl/geospatial");
15151
- import_projection2 = require("@math.gl/projection");
15152
15153
  init_spatial_resource_registry();
15153
15154
  init_normalize_crs_identifier();
15154
15155
  init_get_spatial_coordinate_frame();
@@ -15179,6 +15180,7 @@ var init_spatial_coordinate_transformer = __esm({
15179
15180
  */
15180
15181
  constructor(spatialReference, options = {}) {
15181
15182
  this.spatialReference = spatialReference;
15183
+ const projectionEngine = getSpatialProjectionEngine();
15182
15184
  validateTransformRequest(spatialReference);
15183
15185
  const outputCrs = spatialReference.targetCrs || spatialReference.sourceCrs;
15184
15186
  this.sourceIsGeocentric = isWgs84Geocentric(spatialReference.sourceCrs);
@@ -15186,7 +15188,7 @@ var init_spatial_coordinate_transformer = __esm({
15186
15188
  this.sourceIsGeographic = isWgs84Geographic(spatialReference.sourceCrs);
15187
15189
  this.outputIsGeographic = isWgs84Geographic(outputCrs);
15188
15190
  if (spatialReference.sourceCrs && spatialReference.targetCrs && !this.sourceIsGeocentric && !this.outputIsGeocentric) {
15189
- this.horizontalProjection = new import_projection2.Projection({
15191
+ this.horizontalProjection = projectionEngine.createProjection({
15190
15192
  from: getHorizontalProjectionDefinition(spatialReference.sourceCrs),
15191
15193
  to: getHorizontalProjectionDefinition(spatialReference.targetCrs),
15192
15194
  enforceAxis: false
@@ -15194,14 +15196,14 @@ var init_spatial_coordinate_transformer = __esm({
15194
15196
  }
15195
15197
  if (requiresHeightTransformation(spatialReference) || this.sourceIsGeocentric || this.outputIsGeocentric) {
15196
15198
  if (!this.sourceIsGeographic && !this.sourceIsGeocentric) {
15197
- this.geographicProjection = new import_projection2.Projection({
15199
+ this.geographicProjection = projectionEngine.createProjection({
15198
15200
  from: getHorizontalProjectionDefinition(spatialReference.sourceCrs),
15199
15201
  to: WGS84_GEOGRAPHIC_CRS,
15200
15202
  enforceAxis: false
15201
15203
  });
15202
15204
  }
15203
15205
  if (!this.outputIsGeographic && !this.outputIsGeocentric) {
15204
- this.heightOutputProjection = new import_projection2.Projection({
15206
+ this.heightOutputProjection = projectionEngine.createProjection({
15205
15207
  from: WGS84_GEOGRAPHIC_CRS,
15206
15208
  to: getHorizontalProjectionDefinition(outputCrs),
15207
15209
  enforceAxis: false
@@ -15248,7 +15250,7 @@ var init_spatial_coordinate_transformer = __esm({
15248
15250
  return result;
15249
15251
  }
15250
15252
  if (this.horizontalProjection) {
15251
- const projected = this.horizontalProjection.project(result.slice(0, 3));
15253
+ const projected = this.horizontalProjection.projectSync(result.slice(0, 3));
15252
15254
  result.splice(0, projected.length, ...projected);
15253
15255
  }
15254
15256
  return result;
@@ -15312,7 +15314,7 @@ var init_spatial_coordinate_transformer = __esm({
15312
15314
  if (this.sourceIsGeographic) {
15313
15315
  return coordinate.slice(0, 3);
15314
15316
  }
15315
- return this.geographicProjection.project(coordinate.slice(0, 3));
15317
+ return this.geographicProjection.projectSync(coordinate.slice(0, 3));
15316
15318
  }
15317
15319
  /** Convert one conventional WGS84 geographic coordinate to the selected output CRS. */
15318
15320
  fromGeographic(coordinate) {
@@ -15322,7 +15324,7 @@ var init_spatial_coordinate_transformer = __esm({
15322
15324
  if (this.outputIsGeographic) {
15323
15325
  return coordinate.slice(0, 3);
15324
15326
  }
15325
- return this.heightOutputProjection.project(coordinate.slice(0, 3));
15327
+ return this.heightOutputProjection.projectSync(coordinate.slice(0, 3));
15326
15328
  }
15327
15329
  };
15328
15330
  }
@@ -15958,6 +15960,34 @@ var init_i3s_spatial_transformer = __esm({
15958
15960
  placedPositions.subarray(sourcePositions.length)
15959
15961
  );
15960
15962
  }
15963
+ /**
15964
+ * Transforms conversion geometry without passing through renderer float32 offsets.
15965
+ * Positions and normals share one batch of elevation samples. Source arrays remain unchanged.
15966
+ * @param sourcePositions - Packed absolute xyz positions in source units.
15967
+ * @param normals - Optional packed normals paired with the positions.
15968
+ * @param normalReferenceFrame - I3S earth-centered or vertex-reference-frame declaration.
15969
+ * @returns Absolute target positions and optional transformed normals.
15970
+ */
15971
+ async transformGeometryAsync(sourcePositions, normals, normalReferenceFrame = "earth-centered") {
15972
+ if (sourcePositions.length % 3 || normals && normals.length !== sourcePositions.length) {
15973
+ throw new Error("Conversion positions and normals must contain matching finite xyz triples");
15974
+ }
15975
+ for (let index = 0; index < sourcePositions.length; index++) {
15976
+ if (!Number.isFinite(sourcePositions[index]) || normals && !Number.isFinite(normals[index])) {
15977
+ throw new Error(
15978
+ "Conversion positions and normals must contain matching finite xyz triples"
15979
+ );
15980
+ }
15981
+ }
15982
+ if (!["earth-centered", "vertex-reference-frame"].includes(normalReferenceFrame)) {
15983
+ throw new Error("Unsupported I3S normal reference frame");
15984
+ }
15985
+ const placedPositions = await this.placeSourcePositions(sourcePositions);
15986
+ return {
15987
+ positions: this.positionTransformer.transformPositions(placedPositions),
15988
+ normals: normals ? this.transformNormals(normals, placedPositions, normalReferenceFrame) : void 0
15989
+ };
15990
+ }
15961
15991
  /** Transform already placed positions into renderer-relative target coordinates. */
15962
15992
  transformPlacedPositions(sourcePositions, sourceOrigin) {
15963
15993
  const origin = this.transformPlacedPosition(sourceOrigin);
@@ -15995,7 +16025,19 @@ var init_i3s_spatial_transformer = __esm({
15995
16025
  * @param normalReferenceFrame - I3S normal frame declaration.
15996
16026
  */
15997
16027
  transformNormals(normals, sourcePositions, normalReferenceFrame = "earth-centered") {
16028
+ if (normals.length !== sourcePositions.length || normals.length % 3) {
16029
+ throw new Error("I3S normals and positions must have matching xyz component counts");
16030
+ }
15998
16031
  const transformedNormals = new Float32Array(normals.length);
16032
+ if (normalReferenceFrame === "earth-centered" && (this.spatialReference.targetCrs || this.spatialReference.sourceCrs) === "EPSG:4978") {
16033
+ for (let index = 0; index < normals.length; index += 3) {
16034
+ const length = Math.hypot(normals[index], normals[index + 1], normals[index + 2]);
16035
+ for (let axis = 0; axis < 3; axis++) {
16036
+ transformedNormals[index + axis] = length ? normals[index + axis] / length : normals[index + axis];
16037
+ }
16038
+ }
16039
+ return transformedNormals;
16040
+ }
15999
16041
  for (let index = 0; index < normals.length; index += 3) {
16000
16042
  const geographic = this.sourceToGeographicTransformer.transformPosition([
16001
16043
  sourcePositions[index],
@@ -16740,6 +16782,7 @@ var init_src11 = __esm({
16740
16782
  init_i3s_source();
16741
16783
  init_spatial_types();
16742
16784
  init_format_spatial_reference();
16785
+ init_spatial_coordinate_transformer();
16743
16786
  init_i3s_spatial_transformer();
16744
16787
  }
16745
16788
  });
@@ -16828,8 +16871,13 @@ function getLoaderForTextureFormat(textureFormat) {
16828
16871
  }
16829
16872
  }
16830
16873
  async function parseI3STileContent(arrayBuffer, tileOptions, tilesetOptions, options, context) {
16831
- var _a2;
16874
+ var _a2, _b;
16875
+ const geometryMode = ((_a2 = options == null ? void 0 : options.i3s) == null ? void 0 : _a2.geometryMode) ?? "render";
16876
+ if (geometryMode !== "render" && geometryMode !== "source") {
16877
+ throw new Error("Unsupported I3S geometry mode");
16878
+ }
16832
16879
  const content = {
16880
+ geometryMode,
16833
16881
  attributes: {},
16834
16882
  indices: null,
16835
16883
  featureIds: [],
@@ -16843,7 +16891,7 @@ async function parseI3STileContent(arrayBuffer, tileOptions, tilesetOptions, opt
16843
16891
  pointSymbol: tileOptions.pointSymbol
16844
16892
  };
16845
16893
  const requiredContext = context ? getRequiredContext(context, "parse nested resources") : null;
16846
- const textureResources = ((_a2 = tileOptions.textureUrls) == null ? void 0 : _a2.length) ? tileOptions.textureUrls : tileOptions.textureUrl ? [
16894
+ const textureResources = ((_b = tileOptions.textureUrls) == null ? void 0 : _b.length) ? tileOptions.textureUrls : tileOptions.textureUrl ? [
16847
16895
  {
16848
16896
  textureSetDefinitionId: getMaterialTextureSetDefinitionId(
16849
16897
  tileOptions.materialDefinition
@@ -16981,6 +17029,13 @@ async function parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOp
16981
17029
  id: featureIndex
16982
17030
  };
16983
17031
  copyDracoTextureCoordinates(attributes, decompressedGeometry.attributes);
17032
+ if (content.geometryMode === "source") {
17033
+ for (const [name, attribute] of Object.entries(decompressedGeometry.attributes)) {
17034
+ if (!["POSITION", "NORMAL", "COLOR_0", "feature-index", "uv-region"].includes(name) && !/^TEXCOORD_\d+$/.test(name)) {
17035
+ attributes[name] = attribute;
17036
+ }
17037
+ }
17038
+ }
16984
17039
  updateAttributesMetadata(attributes, decompressedGeometry);
16985
17040
  const featureIds = getFeatureIdsFromFeatureIndexMetadata(featureIndex);
16986
17041
  if (featureIds) {
@@ -17029,7 +17084,32 @@ async function parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOp
17029
17084
  attributes = concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes);
17030
17085
  }
17031
17086
  const spatialReference = tilesetOptions.spatialReference;
17032
- if ((spatialReference == null ? void 0 : spatialReference.status) === "transformable" || (spatialReference == null ? void 0 : spatialReference.status) === "transformed") {
17087
+ if (content.geometryMode === "source") {
17088
+ if (attributes.position.size !== 3 || attributes.position.transform || attributes.position.normalized || (attributes.position.byteStride ?? 0) !== 0 || (attributes.position.byteOffset ?? 0) !== 0 || attributes.position.value.length !== vertexCount * 3 || tileOptions.mbs.length < 3 || tileOptions.mbs.slice(0, 3).some((value) => !Number.isFinite(value))) {
17089
+ throw new Error("Source I3S geometry requires packed xyz values and a finite source origin");
17090
+ }
17091
+ const positions = offsetsToSourcePositions(
17092
+ attributes.position.value,
17093
+ attributes.position.metadata,
17094
+ tileOptions.mbs
17095
+ );
17096
+ if (positions.some((value) => !Number.isFinite(value))) {
17097
+ throw new Error("Source I3S positions must be finite");
17098
+ }
17099
+ attributes.position = { value: positions, size: 3 };
17100
+ content.origin = [0, 0, 0];
17101
+ content.cartographicOrigin = [0, 0, 0];
17102
+ content.coordinateSystem = (spatialReference == null ? void 0 : spatialReference.sourceCrs) && getSpatialCoordinateFrame(spatialReference.sourceCrs) === "geographic" ? "lnglat" : "cartesian";
17103
+ content.spatialReference = spatialReference ? Object.freeze({
17104
+ ...spatialReference,
17105
+ status: "native",
17106
+ targetCrs: void 0,
17107
+ targetHeightReference: "native",
17108
+ outputCoordinates: "auto"
17109
+ }) : void 0;
17110
+ content.normalReferenceFrame = tilesetOptions.store.normalReferenceFrame || "earth-centered";
17111
+ content.sourceAttributes = attributes;
17112
+ } else if ((spatialReference == null ? void 0 : spatialReference.status) === "transformable" || (spatialReference == null ? void 0 : spatialReference.status) === "transformed") {
17033
17113
  const spatialTransformer = new I3SSpatialTransformer(
17034
17114
  spatialReference,
17035
17115
  tilesetOptions.spatialOptions || ((_c = options == null ? void 0 : options.i3s) == null ? void 0 : _c.spatial)
@@ -17287,9 +17367,10 @@ function parsePositions(attribute, options) {
17287
17367
  return enuMatrix;
17288
17368
  }
17289
17369
  function offsetsToSourcePositions(vertices, metadata = {}, sourceOrigin) {
17370
+ var _a2, _b;
17290
17371
  const positions = new Float64Array(vertices.length);
17291
- const scaleX = metadata["i3s-scale_x"] && metadata["i3s-scale_x"].double || 1;
17292
- const scaleY = metadata["i3s-scale_y"] && metadata["i3s-scale_y"].double || 1;
17372
+ const scaleX = ((_a2 = metadata["i3s-scale_x"]) == null ? void 0 : _a2.double) ?? 1;
17373
+ const scaleY = ((_b = metadata["i3s-scale_y"]) == null ? void 0 : _b.double) ?? 1;
17293
17374
  for (let index = 0; index < positions.length; index += 3) {
17294
17375
  positions[index] = vertices[index] * scaleX + sourceOrigin[0];
17295
17376
  positions[index + 1] = vertices[index + 1] * scaleY + sourceOrigin[1];
@@ -21732,6 +21813,223 @@ var init_compression = __esm({
21732
21813
  }
21733
21814
  });
21734
21815
 
21816
+ // ../compression/src/lib/decompression-stream.ts
21817
+ async function decompressWithNativeDecompressionStream(input, format) {
21818
+ const outputBatches = decompressBatchesWithNativeDecompressionStream([input], format);
21819
+ return outputBatches ? await concatenateNativeDecompressionBatches(outputBatches) : null;
21820
+ }
21821
+ function decompressBatchesWithNativeDecompressionStream(inputBatches, format) {
21822
+ const decompressionStream = createNativeDecompressionStream(format);
21823
+ return decompressionStream ? transformBatchesWithNativeDecompressionStream(inputBatches, decompressionStream) : null;
21824
+ }
21825
+ function isNativeDecompressionSupported(format) {
21826
+ return Boolean(createNativeDecompressionStream(format));
21827
+ }
21828
+ function createNativeDecompressionStream(format) {
21829
+ var _a2, _b;
21830
+ if (typeof globalThis.DecompressionStream === "undefined") {
21831
+ return null;
21832
+ }
21833
+ if (((_b = (_a2 = globalThis.process) == null ? void 0 : _a2.release) == null ? void 0 : _b.name) === "node" && typeof globalThis.Buffer === "undefined") {
21834
+ return null;
21835
+ }
21836
+ try {
21837
+ const DecompressionStreamConstructor = globalThis.DecompressionStream;
21838
+ return new DecompressionStreamConstructor(format);
21839
+ } catch (error) {
21840
+ if (error instanceof TypeError || (error == null ? void 0 : error.name) === "TypeError") {
21841
+ return null;
21842
+ }
21843
+ throw error;
21844
+ }
21845
+ }
21846
+ async function* transformBatchesWithNativeDecompressionStream(inputBatches, decompressionStream) {
21847
+ const writer = decompressionStream.writable.getWriter();
21848
+ const reader = decompressionStream.readable.getReader();
21849
+ const writePromise = writeBatchesToNativeDecompressionStream(inputBatches, writer);
21850
+ writePromise.catch(() => {
21851
+ });
21852
+ let outputCompleted = false;
21853
+ try {
21854
+ while (true) {
21855
+ const { done, value } = await reader.read();
21856
+ if (done) {
21857
+ outputCompleted = true;
21858
+ break;
21859
+ }
21860
+ yield copyExactArrayBuffer(value);
21861
+ }
21862
+ await writePromise;
21863
+ } finally {
21864
+ if (!outputCompleted) {
21865
+ await reader.cancel().catch(() => {
21866
+ });
21867
+ await writer.abort().catch(() => {
21868
+ });
21869
+ await writePromise.catch(() => {
21870
+ });
21871
+ }
21872
+ reader.releaseLock();
21873
+ }
21874
+ }
21875
+ async function concatenateNativeDecompressionBatches(outputBatches) {
21876
+ const batches = [];
21877
+ let byteLength = 0;
21878
+ for await (const outputBatch of outputBatches) {
21879
+ const bytes = new Uint8Array(outputBatch);
21880
+ batches.push(bytes);
21881
+ byteLength += bytes.byteLength;
21882
+ }
21883
+ const output = new Uint8Array(byteLength);
21884
+ let byteOffset = 0;
21885
+ for (const batch of batches) {
21886
+ output.set(batch, byteOffset);
21887
+ byteOffset += batch.byteLength;
21888
+ }
21889
+ return output.buffer;
21890
+ }
21891
+ function copyExactArrayBuffer(value) {
21892
+ return new Uint8Array(value).buffer;
21893
+ }
21894
+ async function writeBatchesToNativeDecompressionStream(inputBatches, writer) {
21895
+ try {
21896
+ for await (const inputBatch of inputBatches) {
21897
+ await writer.write(new Uint8Array(inputBatch));
21898
+ }
21899
+ await writer.close();
21900
+ } catch (error) {
21901
+ await writer.abort(error).catch(() => {
21902
+ });
21903
+ throw error;
21904
+ }
21905
+ }
21906
+ var init_decompression_stream = __esm({
21907
+ "../compression/src/lib/decompression-stream.ts"() {
21908
+ "use strict";
21909
+ }
21910
+ });
21911
+
21912
+ // ../compression/src/lib/native-decompressor.ts
21913
+ var native_decompressor_exports = {};
21914
+ __export(native_decompressor_exports, {
21915
+ NativeDecompressor: () => NativeDecompressor
21916
+ });
21917
+ var NativeDecompressor;
21918
+ var init_native_decompressor = __esm({
21919
+ "../compression/src/lib/native-decompressor.ts"() {
21920
+ "use strict";
21921
+ init_compression();
21922
+ init_decompression_stream();
21923
+ NativeDecompressor = class extends Decompressor {
21924
+ name;
21925
+ extensions;
21926
+ contentEncodings;
21927
+ isSupported = true;
21928
+ /** Runtime stream format used for every operation. */
21929
+ format;
21930
+ constructor(metadata, format, options = {}) {
21931
+ super(options);
21932
+ this.name = metadata.name;
21933
+ this.extensions = [...metadata.extensions];
21934
+ this.contentEncodings = [...metadata.contentEncodings];
21935
+ this.format = format;
21936
+ }
21937
+ /** Decompresses one buffer with the runtime-provided stream. */
21938
+ async decompress(input) {
21939
+ const output = await decompressWithNativeDecompressionStream(input, this.format);
21940
+ if (!output) throw new Error(`${this.name}: built-in decompression is no longer available`);
21941
+ return output;
21942
+ }
21943
+ /** Decompresses batches incrementally with the runtime-provided stream. */
21944
+ async *decompressBatches(inputBatches) {
21945
+ const output = decompressBatchesWithNativeDecompressionStream(inputBatches, this.format);
21946
+ if (!output) throw new Error(`${this.name}: built-in decompression is no longer available`);
21947
+ yield* output;
21948
+ }
21949
+ };
21950
+ }
21951
+ });
21952
+
21953
+ // ../compression/src/lib/lazy-compression.ts
21954
+ function mergeModules(options, modules) {
21955
+ return { ...options, modules: { ...options.modules, ...modules } };
21956
+ }
21957
+ var LazyDecompressor;
21958
+ var init_lazy_compression = __esm({
21959
+ "../compression/src/lib/lazy-compression.ts"() {
21960
+ "use strict";
21961
+ init_compression();
21962
+ init_decompression_stream();
21963
+ LazyDecompressor = class extends Decompressor {
21964
+ name;
21965
+ extensions;
21966
+ contentEncodings;
21967
+ isSupported = true;
21968
+ /** Constructor options retained until a concrete implementation is selected. */
21969
+ options;
21970
+ /** Built-in stream format to probe, or null when the format has no built-in path. */
21971
+ nativeFormat;
21972
+ /** Returns whether built-in selection remains eligible for the merged preload options. */
21973
+ shouldUseNative;
21974
+ /** Dynamically imports the balanced fallback constructor. */
21975
+ loadFallback;
21976
+ /** Selected concrete implementation after preload completes. */
21977
+ implementation = null;
21978
+ /** Shared in-flight selection used by concurrent asynchronous calls. */
21979
+ implementationPromise = null;
21980
+ constructor(metadata, loadFallback, options = {}, nativeFormat = null, shouldUseNative = () => true) {
21981
+ super(options);
21982
+ this.name = metadata.name;
21983
+ this.extensions = [...metadata.extensions];
21984
+ this.contentEncodings = [...metadata.contentEncodings];
21985
+ this.options = options;
21986
+ this.nativeFormat = nativeFormat;
21987
+ this.shouldUseNative = shouldUseNative;
21988
+ this.loadFallback = loadFallback;
21989
+ }
21990
+ /** Selects and returns the built-in or dynamically imported fallback decompressor. */
21991
+ async preload(modules = {}) {
21992
+ if (this.implementation) return this.implementation;
21993
+ const options = mergeModules(this.options, modules);
21994
+ this.implementationPromise ||= this.loadImplementation(options);
21995
+ try {
21996
+ this.implementation = await this.implementationPromise;
21997
+ return this.implementation;
21998
+ } catch (error) {
21999
+ this.implementationPromise = null;
22000
+ throw error;
22001
+ }
22002
+ }
22003
+ /** Loads the selected concrete decompressor. */
22004
+ async loadImplementation(options) {
22005
+ if (options.useNative !== false && this.nativeFormat && this.shouldUseNative(options) && isNativeDecompressionSupported(this.nativeFormat)) {
22006
+ const { NativeDecompressor: NativeDecompressor2 } = await Promise.resolve().then(() => (init_native_decompressor(), native_decompressor_exports));
22007
+ return new NativeDecompressor2(this, this.nativeFormat, options);
22008
+ }
22009
+ const Decompressor2 = await this.loadFallback();
22010
+ const implementation = new Decompressor2({ ...options, useNative: false });
22011
+ await implementation.preload(options.modules);
22012
+ return implementation;
22013
+ }
22014
+ /** Decompresses after lazily selecting the default implementation. */
22015
+ async decompress(input, size) {
22016
+ return (await this.preload()).decompress(input, size);
22017
+ }
22018
+ /** Decompresses synchronously after an implementation has been preloaded. */
22019
+ decompressSync(input, size) {
22020
+ if (!this.implementation) {
22021
+ throw new Error(`${this.name}: call preload() before decompressSync()`);
22022
+ }
22023
+ return this.implementation.decompressSync(input, size);
22024
+ }
22025
+ /** Decompresses batches after lazily selecting the default implementation. */
22026
+ async *decompressBatches(inputBatches) {
22027
+ yield* (await this.preload()).decompressBatches(inputBatches);
22028
+ }
22029
+ };
22030
+ }
22031
+ });
22032
+
21735
22033
  // ../compression/src/lib/fflate/index.ts
21736
22034
  function inflateSync(data, out) {
21737
22035
  return inflt(data, out);
@@ -22178,223 +22476,6 @@ var init_fflate = __esm({
22178
22476
  }
22179
22477
  });
22180
22478
 
22181
- // ../compression/src/lib/decompression-stream.ts
22182
- async function decompressWithNativeDecompressionStream(input, format) {
22183
- const outputBatches = decompressBatchesWithNativeDecompressionStream([input], format);
22184
- return outputBatches ? await concatenateNativeDecompressionBatches(outputBatches) : null;
22185
- }
22186
- function decompressBatchesWithNativeDecompressionStream(inputBatches, format) {
22187
- const decompressionStream = createNativeDecompressionStream(format);
22188
- return decompressionStream ? transformBatchesWithNativeDecompressionStream(inputBatches, decompressionStream) : null;
22189
- }
22190
- function isNativeDecompressionSupported(format) {
22191
- return Boolean(createNativeDecompressionStream(format));
22192
- }
22193
- function createNativeDecompressionStream(format) {
22194
- var _a2, _b;
22195
- if (typeof globalThis.DecompressionStream === "undefined") {
22196
- return null;
22197
- }
22198
- if (((_b = (_a2 = globalThis.process) == null ? void 0 : _a2.release) == null ? void 0 : _b.name) === "node" && typeof globalThis.Buffer === "undefined") {
22199
- return null;
22200
- }
22201
- try {
22202
- const DecompressionStreamConstructor = globalThis.DecompressionStream;
22203
- return new DecompressionStreamConstructor(format);
22204
- } catch (error) {
22205
- if (error instanceof TypeError || (error == null ? void 0 : error.name) === "TypeError") {
22206
- return null;
22207
- }
22208
- throw error;
22209
- }
22210
- }
22211
- async function* transformBatchesWithNativeDecompressionStream(inputBatches, decompressionStream) {
22212
- const writer = decompressionStream.writable.getWriter();
22213
- const reader = decompressionStream.readable.getReader();
22214
- const writePromise = writeBatchesToNativeDecompressionStream(inputBatches, writer);
22215
- writePromise.catch(() => {
22216
- });
22217
- let outputCompleted = false;
22218
- try {
22219
- while (true) {
22220
- const { done, value } = await reader.read();
22221
- if (done) {
22222
- outputCompleted = true;
22223
- break;
22224
- }
22225
- yield copyExactArrayBuffer(value);
22226
- }
22227
- await writePromise;
22228
- } finally {
22229
- if (!outputCompleted) {
22230
- await reader.cancel().catch(() => {
22231
- });
22232
- await writer.abort().catch(() => {
22233
- });
22234
- await writePromise.catch(() => {
22235
- });
22236
- }
22237
- reader.releaseLock();
22238
- }
22239
- }
22240
- async function concatenateNativeDecompressionBatches(outputBatches) {
22241
- const batches = [];
22242
- let byteLength = 0;
22243
- for await (const outputBatch of outputBatches) {
22244
- const bytes = new Uint8Array(outputBatch);
22245
- batches.push(bytes);
22246
- byteLength += bytes.byteLength;
22247
- }
22248
- const output = new Uint8Array(byteLength);
22249
- let byteOffset = 0;
22250
- for (const batch of batches) {
22251
- output.set(batch, byteOffset);
22252
- byteOffset += batch.byteLength;
22253
- }
22254
- return output.buffer;
22255
- }
22256
- function copyExactArrayBuffer(value) {
22257
- return new Uint8Array(value).buffer;
22258
- }
22259
- async function writeBatchesToNativeDecompressionStream(inputBatches, writer) {
22260
- try {
22261
- for await (const inputBatch of inputBatches) {
22262
- await writer.write(new Uint8Array(inputBatch));
22263
- }
22264
- await writer.close();
22265
- } catch (error) {
22266
- await writer.abort(error).catch(() => {
22267
- });
22268
- throw error;
22269
- }
22270
- }
22271
- var init_decompression_stream = __esm({
22272
- "../compression/src/lib/decompression-stream.ts"() {
22273
- "use strict";
22274
- }
22275
- });
22276
-
22277
- // ../compression/src/lib/native-decompressor.ts
22278
- var native_decompressor_exports = {};
22279
- __export(native_decompressor_exports, {
22280
- NativeDecompressor: () => NativeDecompressor
22281
- });
22282
- var NativeDecompressor;
22283
- var init_native_decompressor = __esm({
22284
- "../compression/src/lib/native-decompressor.ts"() {
22285
- "use strict";
22286
- init_compression();
22287
- init_decompression_stream();
22288
- NativeDecompressor = class extends Decompressor {
22289
- name;
22290
- extensions;
22291
- contentEncodings;
22292
- isSupported = true;
22293
- /** Runtime stream format used for every operation. */
22294
- format;
22295
- constructor(metadata, format, options = {}) {
22296
- super(options);
22297
- this.name = metadata.name;
22298
- this.extensions = [...metadata.extensions];
22299
- this.contentEncodings = [...metadata.contentEncodings];
22300
- this.format = format;
22301
- }
22302
- /** Decompresses one buffer with the runtime-provided stream. */
22303
- async decompress(input) {
22304
- const output = await decompressWithNativeDecompressionStream(input, this.format);
22305
- if (!output) throw new Error(`${this.name}: built-in decompression is no longer available`);
22306
- return output;
22307
- }
22308
- /** Decompresses batches incrementally with the runtime-provided stream. */
22309
- async *decompressBatches(inputBatches) {
22310
- const output = decompressBatchesWithNativeDecompressionStream(inputBatches, this.format);
22311
- if (!output) throw new Error(`${this.name}: built-in decompression is no longer available`);
22312
- yield* output;
22313
- }
22314
- };
22315
- }
22316
- });
22317
-
22318
- // ../compression/src/lib/lazy-compression.ts
22319
- function mergeModules(options, modules) {
22320
- return { ...options, modules: { ...options.modules, ...modules } };
22321
- }
22322
- var LazyDecompressor;
22323
- var init_lazy_compression = __esm({
22324
- "../compression/src/lib/lazy-compression.ts"() {
22325
- "use strict";
22326
- init_compression();
22327
- init_decompression_stream();
22328
- LazyDecompressor = class extends Decompressor {
22329
- name;
22330
- extensions;
22331
- contentEncodings;
22332
- isSupported = true;
22333
- /** Constructor options retained until a concrete implementation is selected. */
22334
- options;
22335
- /** Built-in stream format to probe, or null when the format has no built-in path. */
22336
- nativeFormat;
22337
- /** Returns whether built-in selection remains eligible for the merged preload options. */
22338
- shouldUseNative;
22339
- /** Dynamically imports the balanced fallback constructor. */
22340
- loadFallback;
22341
- /** Selected concrete implementation after preload completes. */
22342
- implementation = null;
22343
- /** Shared in-flight selection used by concurrent asynchronous calls. */
22344
- implementationPromise = null;
22345
- constructor(metadata, loadFallback, options = {}, nativeFormat = null, shouldUseNative = () => true) {
22346
- super(options);
22347
- this.name = metadata.name;
22348
- this.extensions = [...metadata.extensions];
22349
- this.contentEncodings = [...metadata.contentEncodings];
22350
- this.options = options;
22351
- this.nativeFormat = nativeFormat;
22352
- this.shouldUseNative = shouldUseNative;
22353
- this.loadFallback = loadFallback;
22354
- }
22355
- /** Selects and returns the built-in or dynamically imported fallback decompressor. */
22356
- async preload(modules = {}) {
22357
- if (this.implementation) return this.implementation;
22358
- const options = mergeModules(this.options, modules);
22359
- this.implementationPromise ||= this.loadImplementation(options);
22360
- try {
22361
- this.implementation = await this.implementationPromise;
22362
- return this.implementation;
22363
- } catch (error) {
22364
- this.implementationPromise = null;
22365
- throw error;
22366
- }
22367
- }
22368
- /** Loads the selected concrete decompressor. */
22369
- async loadImplementation(options) {
22370
- if (options.useNative !== false && this.nativeFormat && this.shouldUseNative(options) && isNativeDecompressionSupported(this.nativeFormat)) {
22371
- const { NativeDecompressor: NativeDecompressor2 } = await Promise.resolve().then(() => (init_native_decompressor(), native_decompressor_exports));
22372
- return new NativeDecompressor2(this, this.nativeFormat, options);
22373
- }
22374
- const Decompressor2 = await this.loadFallback();
22375
- const implementation = new Decompressor2({ ...options, useNative: false });
22376
- await implementation.preload(options.modules);
22377
- return implementation;
22378
- }
22379
- /** Decompresses after lazily selecting the default implementation. */
22380
- async decompress(input, size) {
22381
- return (await this.preload()).decompress(input, size);
22382
- }
22383
- /** Decompresses synchronously after an implementation has been preloaded. */
22384
- decompressSync(input, size) {
22385
- if (!this.implementation) {
22386
- throw new Error(`${this.name}: call preload() before decompressSync()`);
22387
- }
22388
- return this.implementation.decompressSync(input, size);
22389
- }
22390
- /** Decompresses batches after lazily selecting the default implementation. */
22391
- async *decompressBatches(inputBatches) {
22392
- yield* (await this.preload()).decompressBatches(inputBatches);
22393
- }
22394
- };
22395
- }
22396
- });
22397
-
22398
22479
  // ../compression/src/lib/fflate-stream.ts
22399
22480
  async function* transformFflateBatches(processor, inputBatches) {
22400
22481
  const chunks = [];