@loaders.gl/textures 4.0.0-alpha.17 → 4.0.0-alpha.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/basis-worker-node.js +70 -71
  2. package/dist/basis-worker.js +46 -30
  3. package/dist/compressed-texture-worker.js +46 -30
  4. package/dist/crunch-worker.js +33 -17
  5. package/dist/dist.min.js +74 -37
  6. package/dist/es5/index.js +14 -0
  7. package/dist/es5/index.js.map +1 -1
  8. package/dist/es5/ktx2-basis-writer.js +4 -2
  9. package/dist/es5/ktx2-basis-writer.js.map +1 -1
  10. package/dist/es5/lib/encoders/encode-ktx2-basis-texture.js +6 -5
  11. package/dist/es5/lib/encoders/encode-ktx2-basis-texture.js.map +1 -1
  12. package/dist/es5/lib/parsers/basis-module-loader.js +26 -21
  13. package/dist/es5/lib/parsers/basis-module-loader.js.map +1 -1
  14. package/dist/es5/lib/parsers/crunch-module-loader.js +6 -1
  15. package/dist/es5/lib/parsers/crunch-module-loader.js.map +1 -1
  16. package/dist/es5/lib/parsers/parse-basis.js +7 -7
  17. package/dist/es5/lib/parsers/parse-basis.js.map +1 -1
  18. package/dist/es5/lib/texture-api/deep-load.js.map +1 -1
  19. package/dist/es5/lib/utils/version.js +1 -1
  20. package/dist/es5/workers/ktx2-basis-writer-worker-node.js.map +1 -1
  21. package/dist/es5/workers/ktx2-basis-writer-worker.js.map +1 -1
  22. package/dist/esm/index.js +2 -0
  23. package/dist/esm/index.js.map +1 -1
  24. package/dist/esm/ktx2-basis-writer.js +6 -4
  25. package/dist/esm/ktx2-basis-writer.js.map +1 -1
  26. package/dist/esm/lib/encoders/encode-ktx2-basis-texture.js +1 -1
  27. package/dist/esm/lib/encoders/encode-ktx2-basis-texture.js.map +1 -1
  28. package/dist/esm/lib/parsers/basis-module-loader.js +13 -10
  29. package/dist/esm/lib/parsers/basis-module-loader.js.map +1 -1
  30. package/dist/esm/lib/parsers/crunch-module-loader.js +4 -1
  31. package/dist/esm/lib/parsers/crunch-module-loader.js.map +1 -1
  32. package/dist/esm/lib/parsers/parse-basis.js +3 -3
  33. package/dist/esm/lib/parsers/parse-basis.js.map +1 -1
  34. package/dist/esm/lib/texture-api/deep-load.js.map +1 -1
  35. package/dist/esm/lib/utils/version.js +1 -1
  36. package/dist/esm/workers/ktx2-basis-writer-worker-node.js.map +1 -1
  37. package/dist/esm/workers/ktx2-basis-writer-worker.js.map +1 -1
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +6 -1
  41. package/dist/ktx2-basis-writer-worker-node.js +73 -67
  42. package/dist/ktx2-basis-writer-worker.js +49 -26
  43. package/dist/ktx2-basis-writer.d.ts +8 -6
  44. package/dist/ktx2-basis-writer.d.ts.map +1 -1
  45. package/dist/ktx2-basis-writer.js +6 -4
  46. package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts.map +1 -1
  47. package/dist/lib/encoders/encode-ktx2-basis-texture.js +1 -1
  48. package/dist/lib/parsers/basis-module-loader.d.ts +11 -1
  49. package/dist/lib/parsers/basis-module-loader.d.ts.map +1 -1
  50. package/dist/lib/parsers/basis-module-loader.js +21 -17
  51. package/dist/lib/parsers/crunch-module-loader.d.ts +4 -0
  52. package/dist/lib/parsers/crunch-module-loader.d.ts.map +1 -1
  53. package/dist/lib/parsers/crunch-module-loader.js +6 -2
  54. package/dist/lib/parsers/parse-basis.js +2 -2
  55. package/dist/lib/texture-api/deep-load.d.ts.map +1 -1
  56. package/dist/lib/texture-api/deep-load.js +0 -1
  57. package/dist/npy-worker.js +1 -1
  58. package/package.json +7 -7
  59. package/src/index.ts +4 -0
  60. package/src/ktx2-basis-writer.ts +14 -10
  61. package/src/lib/encoders/encode-ktx2-basis-texture.ts +6 -1
  62. package/src/lib/parsers/basis-module-loader.ts +19 -16
  63. package/src/lib/parsers/crunch-module-loader.ts +6 -1
  64. package/src/lib/parsers/parse-basis.ts +3 -3
  65. package/src/lib/texture-api/deep-load.ts +0 -1
  66. package/src/workers/ktx2-basis-writer-worker-node.ts +2 -2
  67. package/src/workers/ktx2-basis-writer-worker.ts +2 -2
@@ -21408,7 +21408,7 @@ var require_cookie = __commonJS({
21408
21408
  var Store = require_store().Store;
21409
21409
  var MemoryCookieStore = require_memstore().MemoryCookieStore;
21410
21410
  var pathMatch = require_pathMatch().pathMatch;
21411
- var VERSION5 = require_version();
21411
+ var VERSION4 = require_version();
21412
21412
  var punycode;
21413
21413
  try {
21414
21414
  punycode = require("punycode");
@@ -22225,7 +22225,7 @@ var require_cookie = __commonJS({
22225
22225
  type = null;
22226
22226
  }
22227
22227
  var serialized = {
22228
- version: "tough-cookie@" + VERSION5,
22228
+ version: "tough-cookie@" + VERSION4,
22229
22229
  storeType: type,
22230
22230
  rejectPublicSuffixes: !!this.rejectPublicSuffixes,
22231
22231
  cookies: []
@@ -22377,7 +22377,7 @@ var require_cookie = __commonJS({
22377
22377
  CAN_BE_SYNC.forEach(function(method) {
22378
22378
  CookieJar.prototype[method + "Sync"] = syncWrap(method);
22379
22379
  });
22380
- exports2.version = VERSION5;
22380
+ exports2.version = VERSION4;
22381
22381
  exports2.CookieJar = CookieJar;
22382
22382
  exports2.Cookie = Cookie;
22383
22383
  exports2.Store = Store;
@@ -62939,48 +62939,12 @@ var Response = class {
62939
62939
  // ../polyfills/src/node/fetch/fetch.node.ts
62940
62940
  var import_http = __toModule(require("http"));
62941
62941
  var import_https = __toModule(require("https"));
62942
-
62943
- // ../polyfills/src/node/fetch/fetch-file.node.ts
62944
- var import_fs = __toModule(require("fs"));
62945
- async function fetchFileNode(url, options) {
62946
- const noqueryUrl = url.split("?")[0];
62947
- try {
62948
- const body = await new Promise((resolve, reject) => {
62949
- const stream = import_fs.default.createReadStream(noqueryUrl, { encoding: null });
62950
- stream.once("readable", () => resolve(stream));
62951
- stream.on("error", (error) => reject(error));
62952
- });
62953
- const status = 200;
62954
- const statusText = "OK";
62955
- const headers = getHeadersForFile(noqueryUrl);
62956
- return new Response(body, { headers, status, statusText, url });
62957
- } catch (error) {
62958
- const status = 400;
62959
- const statusText = error.message;
62960
- const headers = {};
62961
- return new Response(error.message, { headers, status, statusText, url });
62962
- }
62963
- }
62964
- function getHeadersForFile(noqueryUrl) {
62965
- const headers = {};
62966
- if (!headers["content-length"]) {
62967
- const stats = import_fs.default.statSync(noqueryUrl);
62968
- headers["content-length"] = stats.size;
62969
- }
62970
- if (noqueryUrl.endsWith(".gz")) {
62971
- noqueryUrl = noqueryUrl.slice(0, -3);
62972
- headers["content-encoding"] = "gzip";
62973
- }
62974
- return new Headers(headers);
62975
- }
62976
-
62977
- // ../polyfills/src/node/fetch/fetch.node.ts
62978
62942
  var isDataURL = (url) => url.startsWith("data:");
62979
62943
  var isRequestURL = (url) => url.startsWith("http:") || url.startsWith("https:");
62980
62944
  async function fetchNode(url, options) {
62981
62945
  try {
62982
- if (!isRequestURL(url) && !isDataURL(url)) {
62983
- return await fetchFileNode(url, options);
62946
+ if (globalThis.fetch !== fetchNode && (isRequestURL(url) || isDataURL(url))) {
62947
+ return await fetch(url, options);
62984
62948
  }
62985
62949
  if (isDataURL(url)) {
62986
62950
  const { arrayBuffer, mimeType } = decodeDataUri(url);
@@ -63338,7 +63302,7 @@ if (!("allSettled" in Promise)) {
63338
63302
  }
63339
63303
 
63340
63304
  // ../worker-utils/src/lib/env-utils/version.ts
63341
- var VERSION = true ? "4.0.0-alpha.17" : DEFAULT_VERSION;
63305
+ var VERSION = true ? "4.0.0-alpha.19" : DEFAULT_VERSION;
63342
63306
  if (false) {
63343
63307
  console.error("loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.");
63344
63308
  }
@@ -63479,11 +63443,30 @@ function isKnownMessage(message) {
63479
63443
  // ../worker-utils/src/lib/node/require-utils.node.ts
63480
63444
  var require_utils_node_exports = {};
63481
63445
  __export(require_utils_node_exports, {
63446
+ readFileAsArrayBuffer: () => readFileAsArrayBuffer,
63447
+ readFileAsText: () => readFileAsText,
63482
63448
  requireFromFile: () => requireFromFile,
63483
63449
  requireFromString: () => requireFromString
63484
63450
  });
63485
63451
  var import_module = __toModule(require("module"));
63486
63452
  var import_path = __toModule(require("path"));
63453
+ var import_fs = __toModule(require("fs"));
63454
+ async function readFileAsArrayBuffer(filename) {
63455
+ if (filename.startsWith("http")) {
63456
+ const response = await fetch(filename);
63457
+ return await response.arrayBuffer();
63458
+ }
63459
+ const buffer = import_fs.default.readFileSync(filename);
63460
+ return buffer.buffer;
63461
+ }
63462
+ async function readFileAsText(filename) {
63463
+ if (filename.startsWith("http")) {
63464
+ const response = await fetch(filename);
63465
+ return await response.text();
63466
+ }
63467
+ const text = import_fs.default.readFileSync(filename, "utf8");
63468
+ return text;
63469
+ }
63487
63470
  async function requireFromFile(filename) {
63488
63471
  if (filename.startsWith("http")) {
63489
63472
  const response = await fetch(filename);
@@ -63519,37 +63502,37 @@ function requireFromString(code, filename = "", options) {
63519
63502
  var LATEST = "beta";
63520
63503
  var VERSION2 = typeof VERSION !== "undefined" ? VERSION : LATEST;
63521
63504
  var loadLibraryPromises = {};
63522
- async function loadLibrary(libraryUrl, moduleName = null, options = {}) {
63505
+ async function loadLibrary(libraryUrl, moduleName = null, options = {}, libraryName = null) {
63523
63506
  if (moduleName) {
63524
- libraryUrl = getLibraryUrl(libraryUrl, moduleName, options);
63507
+ libraryUrl = getLibraryUrl(libraryUrl, moduleName, options, libraryName);
63525
63508
  }
63526
63509
  loadLibraryPromises[libraryUrl] = loadLibraryPromises[libraryUrl] || loadLibraryFromFile(libraryUrl);
63527
63510
  return await loadLibraryPromises[libraryUrl];
63528
63511
  }
63529
- function getLibraryUrl(library, moduleName, options) {
63530
- if (library.startsWith("http")) {
63512
+ function getLibraryUrl(library, moduleName, options = {}, libraryName = null) {
63513
+ if (!options.useLocalLibraries && library.startsWith("http")) {
63531
63514
  return library;
63532
63515
  }
63516
+ libraryName = libraryName || library;
63533
63517
  const modules = options.modules || {};
63534
- if (modules[library]) {
63535
- return modules[library];
63518
+ if (modules[libraryName]) {
63519
+ return modules[libraryName];
63536
63520
  }
63537
63521
  if (!isBrowser2) {
63538
- return `modules/${moduleName}/dist/libs/${library}`;
63522
+ return `modules/${moduleName}/dist/libs/${libraryName}`;
63539
63523
  }
63540
63524
  if (options.CDN) {
63541
63525
  assert2(options.CDN.startsWith("http"));
63542
- return `${options.CDN}/${moduleName}@${VERSION2}/dist/libs/${library}`;
63526
+ return `${options.CDN}/${moduleName}@${VERSION2}/dist/libs/${libraryName}`;
63543
63527
  }
63544
63528
  if (isWorker) {
63545
- return `../src/libs/${library}`;
63529
+ return `../src/libs/${libraryName}`;
63546
63530
  }
63547
- return `modules/${moduleName}/src/libs/${library}`;
63531
+ return `modules/${moduleName}/src/libs/${libraryName}`;
63548
63532
  }
63549
63533
  async function loadLibraryFromFile(libraryUrl) {
63550
63534
  if (libraryUrl.endsWith("wasm")) {
63551
- const response2 = await fetch(libraryUrl);
63552
- return await response2.arrayBuffer();
63535
+ return await loadAsArrayBuffer(libraryUrl);
63553
63536
  }
63554
63537
  if (!isBrowser2) {
63555
63538
  try {
@@ -63561,8 +63544,7 @@ async function loadLibraryFromFile(libraryUrl) {
63561
63544
  if (isWorker) {
63562
63545
  return importScripts(libraryUrl);
63563
63546
  }
63564
- const response = await fetch(libraryUrl);
63565
- const scriptSource = await response.text();
63547
+ const scriptSource = await loadAsText(libraryUrl);
63566
63548
  return loadLibraryFromString(scriptSource, libraryUrl);
63567
63549
  }
63568
63550
  function loadLibraryFromString(scriptSource, id) {
@@ -63583,6 +63565,20 @@ function loadLibraryFromString(scriptSource, id) {
63583
63565
  document.body.appendChild(script);
63584
63566
  return null;
63585
63567
  }
63568
+ async function loadAsArrayBuffer(url) {
63569
+ if (!readFileAsArrayBuffer || url.startsWith("http")) {
63570
+ const response = await fetch(url);
63571
+ return await response.arrayBuffer();
63572
+ }
63573
+ return await readFileAsArrayBuffer(url);
63574
+ }
63575
+ async function loadAsText(url) {
63576
+ if (!readFileAsText || url.startsWith("http")) {
63577
+ const response = await fetch(url);
63578
+ return await response.text();
63579
+ }
63580
+ return await readFileAsText(url);
63581
+ }
63586
63582
 
63587
63583
  // ../loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
63588
63584
  var requestId = 0;
@@ -63658,32 +63654,35 @@ async function parseData({ loader, arrayBuffer, options, context }) {
63658
63654
  }
63659
63655
 
63660
63656
  // src/lib/utils/version.ts
63661
- var VERSION3 = true ? "4.0.0-alpha.17" : "beta";
63657
+ var VERSION3 = true ? "4.0.0-alpha.19" : "beta";
63662
63658
 
63663
63659
  // src/lib/parsers/basis-module-loader.ts
63664
- var VERSION4 = true ? "4.0.0-alpha.17" : "beta";
63665
- var BASIS_CDN_ENCODER_WASM = `https://unpkg.com/@loaders.gl/textures@${VERSION4}/dist/libs/basis_encoder.wasm`;
63666
- var BASIS_CDN_ENCODER_JS = `https://unpkg.com/@loaders.gl/textures@${VERSION4}/dist/libs/basis_encoder.js`;
63660
+ var BASIS_EXTERNAL_LIBRARIES = {
63661
+ TRANSCODER: "basis_transcoder.js",
63662
+ TRANSCODER_WASM: "basis_transcoder.wasm",
63663
+ ENCODER: "basis_encoder.js",
63664
+ ENCODER_WASM: "basis_encoder.wasm"
63665
+ };
63667
63666
  var loadBasisTranscoderPromise;
63668
- async function loadBasisTrascoderModule(options) {
63667
+ async function loadBasisTranscoderModule(options) {
63669
63668
  const modules = options.modules || {};
63670
63669
  if (modules.basis) {
63671
63670
  return modules.basis;
63672
63671
  }
63673
- loadBasisTranscoderPromise = loadBasisTranscoderPromise || loadBasisTrascoder(options);
63672
+ loadBasisTranscoderPromise = loadBasisTranscoderPromise || loadBasisTranscoder(options);
63674
63673
  return await loadBasisTranscoderPromise;
63675
63674
  }
63676
- async function loadBasisTrascoder(options) {
63675
+ async function loadBasisTranscoder(options) {
63677
63676
  let BASIS = null;
63678
63677
  let wasmBinary = null;
63679
63678
  [BASIS, wasmBinary] = await Promise.all([
63680
- await loadLibrary("basis_transcoder.js", "textures", options),
63681
- await loadLibrary("basis_transcoder.wasm", "textures", options)
63679
+ await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER, "textures", options),
63680
+ await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER_WASM, "textures", options)
63682
63681
  ]);
63683
63682
  BASIS = BASIS || globalThis.BASIS;
63684
- return await initializeBasisTrascoderModule(BASIS, wasmBinary);
63683
+ return await initializeBasisTranscoderModule(BASIS, wasmBinary);
63685
63684
  }
63686
- function initializeBasisTrascoderModule(BasisModule, wasmBinary) {
63685
+ function initializeBasisTranscoderModule(BasisModule, wasmBinary) {
63687
63686
  const options = {};
63688
63687
  if (wasmBinary) {
63689
63688
  options.wasmBinary = wasmBinary;
@@ -63709,8 +63708,8 @@ async function loadBasisEncoder(options) {
63709
63708
  let BASIS_ENCODER = null;
63710
63709
  let wasmBinary = null;
63711
63710
  [BASIS_ENCODER, wasmBinary] = await Promise.all([
63712
- await loadLibrary(BASIS_CDN_ENCODER_JS, "textures", options),
63713
- await loadLibrary(BASIS_CDN_ENCODER_WASM, "textures", options)
63711
+ await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER, "textures", options),
63712
+ await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER_WASM, "textures", options)
63714
63713
  ]);
63715
63714
  BASIS_ENCODER = BASIS_ENCODER || globalThis.BASIS;
63716
63715
  return await initializeBasisEncoderModule(BASIS_ENCODER, wasmBinary);
@@ -63900,7 +63899,7 @@ async function parseBasis(data, options) {
63900
63899
  const fileConstructors = await loadBasisEncoderModule(options);
63901
63900
  return parseKTX2File(fileConstructors.KTX2File, data, options);
63902
63901
  }
63903
- const { BasisFile } = await loadBasisTrascoderModule(options);
63902
+ const { BasisFile } = await loadBasisTranscoderModule(options);
63904
63903
  return parseBasisFile(BasisFile, data, options);
63905
63904
  }
63906
63905
  switch (options.basis.module) {
@@ -63915,7 +63914,7 @@ async function parseBasis(data, options) {
63915
63914
  }
63916
63915
  case "transcoder":
63917
63916
  default:
63918
- const { BasisFile } = await loadBasisTrascoderModule(options);
63917
+ const { BasisFile } = await loadBasisTranscoderModule(options);
63919
63918
  return parseBasisFile(BasisFile, data, options);
63920
63919
  }
63921
63920
  }
@@ -28,7 +28,7 @@
28
28
  });
29
29
 
30
30
  // ../worker-utils/src/lib/env-utils/version.ts
31
- var VERSION = true ? "4.0.0-alpha.17" : DEFAULT_VERSION;
31
+ var VERSION = true ? "4.0.0-alpha.19" : DEFAULT_VERSION;
32
32
  if (false) {
33
33
  console.error("loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.");
34
34
  }
@@ -171,37 +171,37 @@
171
171
  var LATEST = "beta";
172
172
  var VERSION2 = typeof VERSION !== "undefined" ? VERSION : LATEST;
173
173
  var loadLibraryPromises = {};
174
- async function loadLibrary(libraryUrl, moduleName = null, options = {}) {
174
+ async function loadLibrary(libraryUrl, moduleName = null, options = {}, libraryName = null) {
175
175
  if (moduleName) {
176
- libraryUrl = getLibraryUrl(libraryUrl, moduleName, options);
176
+ libraryUrl = getLibraryUrl(libraryUrl, moduleName, options, libraryName);
177
177
  }
178
178
  loadLibraryPromises[libraryUrl] = loadLibraryPromises[libraryUrl] || loadLibraryFromFile(libraryUrl);
179
179
  return await loadLibraryPromises[libraryUrl];
180
180
  }
181
- function getLibraryUrl(library, moduleName, options) {
182
- if (library.startsWith("http")) {
181
+ function getLibraryUrl(library, moduleName, options = {}, libraryName = null) {
182
+ if (!options.useLocalLibraries && library.startsWith("http")) {
183
183
  return library;
184
184
  }
185
+ libraryName = libraryName || library;
185
186
  const modules = options.modules || {};
186
- if (modules[library]) {
187
- return modules[library];
187
+ if (modules[libraryName]) {
188
+ return modules[libraryName];
188
189
  }
189
190
  if (!isBrowser) {
190
- return `modules/${moduleName}/dist/libs/${library}`;
191
+ return `modules/${moduleName}/dist/libs/${libraryName}`;
191
192
  }
192
193
  if (options.CDN) {
193
194
  assert(options.CDN.startsWith("http"));
194
- return `${options.CDN}/${moduleName}@${VERSION2}/dist/libs/${library}`;
195
+ return `${options.CDN}/${moduleName}@${VERSION2}/dist/libs/${libraryName}`;
195
196
  }
196
197
  if (isWorker) {
197
- return `../src/libs/${library}`;
198
+ return `../src/libs/${libraryName}`;
198
199
  }
199
- return `modules/${moduleName}/src/libs/${library}`;
200
+ return `modules/${moduleName}/src/libs/${libraryName}`;
200
201
  }
201
202
  async function loadLibraryFromFile(libraryUrl) {
202
203
  if (libraryUrl.endsWith("wasm")) {
203
- const response2 = await fetch(libraryUrl);
204
- return await response2.arrayBuffer();
204
+ return await loadAsArrayBuffer(libraryUrl);
205
205
  }
206
206
  if (!isBrowser) {
207
207
  try {
@@ -213,8 +213,7 @@
213
213
  if (isWorker) {
214
214
  return importScripts(libraryUrl);
215
215
  }
216
- const response = await fetch(libraryUrl);
217
- const scriptSource = await response.text();
216
+ const scriptSource = await loadAsText(libraryUrl);
218
217
  return loadLibraryFromString(scriptSource, libraryUrl);
219
218
  }
220
219
  function loadLibraryFromString(scriptSource, id) {
@@ -235,6 +234,20 @@
235
234
  document.body.appendChild(script);
236
235
  return null;
237
236
  }
237
+ async function loadAsArrayBuffer(url) {
238
+ if (!node.readFileAsArrayBuffer || url.startsWith("http")) {
239
+ const response = await fetch(url);
240
+ return await response.arrayBuffer();
241
+ }
242
+ return await node.readFileAsArrayBuffer(url);
243
+ }
244
+ async function loadAsText(url) {
245
+ if (!node.readFileAsText || url.startsWith("http")) {
246
+ const response = await fetch(url);
247
+ return await response.text();
248
+ }
249
+ return await node.readFileAsText(url);
250
+ }
238
251
 
239
252
  // ../loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
240
253
  var requestId = 0;
@@ -312,32 +325,35 @@
312
325
  }
313
326
 
314
327
  // src/lib/utils/version.ts
315
- var VERSION3 = true ? "4.0.0-alpha.17" : "beta";
328
+ var VERSION3 = true ? "4.0.0-alpha.19" : "beta";
316
329
 
317
330
  // src/lib/parsers/basis-module-loader.ts
318
- var VERSION4 = true ? "4.0.0-alpha.17" : "beta";
319
- var BASIS_CDN_ENCODER_WASM = `https://unpkg.com/@loaders.gl/textures@${VERSION4}/dist/libs/basis_encoder.wasm`;
320
- var BASIS_CDN_ENCODER_JS = `https://unpkg.com/@loaders.gl/textures@${VERSION4}/dist/libs/basis_encoder.js`;
331
+ var BASIS_EXTERNAL_LIBRARIES = {
332
+ TRANSCODER: "basis_transcoder.js",
333
+ TRANSCODER_WASM: "basis_transcoder.wasm",
334
+ ENCODER: "basis_encoder.js",
335
+ ENCODER_WASM: "basis_encoder.wasm"
336
+ };
321
337
  var loadBasisTranscoderPromise;
322
- async function loadBasisTrascoderModule(options) {
338
+ async function loadBasisTranscoderModule(options) {
323
339
  const modules = options.modules || {};
324
340
  if (modules.basis) {
325
341
  return modules.basis;
326
342
  }
327
- loadBasisTranscoderPromise = loadBasisTranscoderPromise || loadBasisTrascoder(options);
343
+ loadBasisTranscoderPromise = loadBasisTranscoderPromise || loadBasisTranscoder(options);
328
344
  return await loadBasisTranscoderPromise;
329
345
  }
330
- async function loadBasisTrascoder(options) {
346
+ async function loadBasisTranscoder(options) {
331
347
  let BASIS = null;
332
348
  let wasmBinary = null;
333
349
  [BASIS, wasmBinary] = await Promise.all([
334
- await loadLibrary("basis_transcoder.js", "textures", options),
335
- await loadLibrary("basis_transcoder.wasm", "textures", options)
350
+ await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER, "textures", options),
351
+ await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER_WASM, "textures", options)
336
352
  ]);
337
353
  BASIS = BASIS || globalThis.BASIS;
338
- return await initializeBasisTrascoderModule(BASIS, wasmBinary);
354
+ return await initializeBasisTranscoderModule(BASIS, wasmBinary);
339
355
  }
340
- function initializeBasisTrascoderModule(BasisModule, wasmBinary) {
356
+ function initializeBasisTranscoderModule(BasisModule, wasmBinary) {
341
357
  const options = {};
342
358
  if (wasmBinary) {
343
359
  options.wasmBinary = wasmBinary;
@@ -363,8 +379,8 @@
363
379
  let BASIS_ENCODER = null;
364
380
  let wasmBinary = null;
365
381
  [BASIS_ENCODER, wasmBinary] = await Promise.all([
366
- await loadLibrary(BASIS_CDN_ENCODER_JS, "textures", options),
367
- await loadLibrary(BASIS_CDN_ENCODER_WASM, "textures", options)
382
+ await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER, "textures", options),
383
+ await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER_WASM, "textures", options)
368
384
  ]);
369
385
  BASIS_ENCODER = BASIS_ENCODER || globalThis.BASIS;
370
386
  return await initializeBasisEncoderModule(BASIS_ENCODER, wasmBinary);
@@ -581,7 +597,7 @@
581
597
  const fileConstructors = await loadBasisEncoderModule(options);
582
598
  return parseKTX2File(fileConstructors.KTX2File, data, options);
583
599
  }
584
- const { BasisFile } = await loadBasisTrascoderModule(options);
600
+ const { BasisFile } = await loadBasisTranscoderModule(options);
585
601
  return parseBasisFile(BasisFile, data, options);
586
602
  }
587
603
  switch (options.basis.module) {
@@ -596,7 +612,7 @@
596
612
  }
597
613
  case "transcoder":
598
614
  default:
599
- const { BasisFile } = await loadBasisTrascoderModule(options);
615
+ const { BasisFile } = await loadBasisTranscoderModule(options);
600
616
  return parseBasisFile(BasisFile, data, options);
601
617
  }
602
618
  }
@@ -35,7 +35,7 @@
35
35
  }
36
36
 
37
37
  // ../worker-utils/src/lib/env-utils/version.ts
38
- var VERSION = true ? "4.0.0-alpha.17" : DEFAULT_VERSION;
38
+ var VERSION = true ? "4.0.0-alpha.19" : DEFAULT_VERSION;
39
39
  if (false) {
40
40
  console.error("loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.");
41
41
  }
@@ -178,37 +178,37 @@
178
178
  var LATEST = "beta";
179
179
  var VERSION2 = typeof VERSION !== "undefined" ? VERSION : LATEST;
180
180
  var loadLibraryPromises = {};
181
- async function loadLibrary(libraryUrl, moduleName = null, options = {}) {
181
+ async function loadLibrary(libraryUrl, moduleName = null, options = {}, libraryName = null) {
182
182
  if (moduleName) {
183
- libraryUrl = getLibraryUrl(libraryUrl, moduleName, options);
183
+ libraryUrl = getLibraryUrl(libraryUrl, moduleName, options, libraryName);
184
184
  }
185
185
  loadLibraryPromises[libraryUrl] = loadLibraryPromises[libraryUrl] || loadLibraryFromFile(libraryUrl);
186
186
  return await loadLibraryPromises[libraryUrl];
187
187
  }
188
- function getLibraryUrl(library, moduleName, options) {
189
- if (library.startsWith("http")) {
188
+ function getLibraryUrl(library, moduleName, options = {}, libraryName = null) {
189
+ if (!options.useLocalLibraries && library.startsWith("http")) {
190
190
  return library;
191
191
  }
192
+ libraryName = libraryName || library;
192
193
  const modules = options.modules || {};
193
- if (modules[library]) {
194
- return modules[library];
194
+ if (modules[libraryName]) {
195
+ return modules[libraryName];
195
196
  }
196
197
  if (!isBrowser) {
197
- return `modules/${moduleName}/dist/libs/${library}`;
198
+ return `modules/${moduleName}/dist/libs/${libraryName}`;
198
199
  }
199
200
  if (options.CDN) {
200
201
  assert2(options.CDN.startsWith("http"));
201
- return `${options.CDN}/${moduleName}@${VERSION2}/dist/libs/${library}`;
202
+ return `${options.CDN}/${moduleName}@${VERSION2}/dist/libs/${libraryName}`;
202
203
  }
203
204
  if (isWorker) {
204
- return `../src/libs/${library}`;
205
+ return `../src/libs/${libraryName}`;
205
206
  }
206
- return `modules/${moduleName}/src/libs/${library}`;
207
+ return `modules/${moduleName}/src/libs/${libraryName}`;
207
208
  }
208
209
  async function loadLibraryFromFile(libraryUrl) {
209
210
  if (libraryUrl.endsWith("wasm")) {
210
- const response2 = await fetch(libraryUrl);
211
- return await response2.arrayBuffer();
211
+ return await loadAsArrayBuffer(libraryUrl);
212
212
  }
213
213
  if (!isBrowser) {
214
214
  try {
@@ -220,8 +220,7 @@
220
220
  if (isWorker) {
221
221
  return importScripts(libraryUrl);
222
222
  }
223
- const response = await fetch(libraryUrl);
224
- const scriptSource = await response.text();
223
+ const scriptSource = await loadAsText(libraryUrl);
225
224
  return loadLibraryFromString(scriptSource, libraryUrl);
226
225
  }
227
226
  function loadLibraryFromString(scriptSource, id) {
@@ -242,6 +241,20 @@
242
241
  document.body.appendChild(script);
243
242
  return null;
244
243
  }
244
+ async function loadAsArrayBuffer(url) {
245
+ if (!node.readFileAsArrayBuffer || url.startsWith("http")) {
246
+ const response = await fetch(url);
247
+ return await response.arrayBuffer();
248
+ }
249
+ return await node.readFileAsArrayBuffer(url);
250
+ }
251
+ async function loadAsText(url) {
252
+ if (!node.readFileAsText || url.startsWith("http")) {
253
+ const response = await fetch(url);
254
+ return await response.text();
255
+ }
256
+ return await node.readFileAsText(url);
257
+ }
245
258
 
246
259
  // ../loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
247
260
  var requestId = 0;
@@ -319,7 +332,7 @@
319
332
  }
320
333
 
321
334
  // src/lib/utils/version.ts
322
- var VERSION3 = true ? "4.0.0-alpha.17" : "beta";
335
+ var VERSION3 = true ? "4.0.0-alpha.19" : "beta";
323
336
 
324
337
  // ../../node_modules/ktx-parse/dist/ktx-parse.modern.js
325
338
  var t = new Uint8Array([0]);
@@ -907,29 +920,32 @@
907
920
  }
908
921
 
909
922
  // src/lib/parsers/basis-module-loader.ts
910
- var VERSION4 = true ? "4.0.0-alpha.17" : "beta";
911
- var BASIS_CDN_ENCODER_WASM = `https://unpkg.com/@loaders.gl/textures@${VERSION4}/dist/libs/basis_encoder.wasm`;
912
- var BASIS_CDN_ENCODER_JS = `https://unpkg.com/@loaders.gl/textures@${VERSION4}/dist/libs/basis_encoder.js`;
923
+ var BASIS_EXTERNAL_LIBRARIES = {
924
+ TRANSCODER: "basis_transcoder.js",
925
+ TRANSCODER_WASM: "basis_transcoder.wasm",
926
+ ENCODER: "basis_encoder.js",
927
+ ENCODER_WASM: "basis_encoder.wasm"
928
+ };
913
929
  var loadBasisTranscoderPromise;
914
- async function loadBasisTrascoderModule(options) {
930
+ async function loadBasisTranscoderModule(options) {
915
931
  const modules = options.modules || {};
916
932
  if (modules.basis) {
917
933
  return modules.basis;
918
934
  }
919
- loadBasisTranscoderPromise = loadBasisTranscoderPromise || loadBasisTrascoder(options);
935
+ loadBasisTranscoderPromise = loadBasisTranscoderPromise || loadBasisTranscoder(options);
920
936
  return await loadBasisTranscoderPromise;
921
937
  }
922
- async function loadBasisTrascoder(options) {
938
+ async function loadBasisTranscoder(options) {
923
939
  let BASIS = null;
924
940
  let wasmBinary = null;
925
941
  [BASIS, wasmBinary] = await Promise.all([
926
- await loadLibrary("basis_transcoder.js", "textures", options),
927
- await loadLibrary("basis_transcoder.wasm", "textures", options)
942
+ await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER, "textures", options),
943
+ await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER_WASM, "textures", options)
928
944
  ]);
929
945
  BASIS = BASIS || globalThis.BASIS;
930
- return await initializeBasisTrascoderModule(BASIS, wasmBinary);
946
+ return await initializeBasisTranscoderModule(BASIS, wasmBinary);
931
947
  }
932
- function initializeBasisTrascoderModule(BasisModule, wasmBinary) {
948
+ function initializeBasisTranscoderModule(BasisModule, wasmBinary) {
933
949
  const options = {};
934
950
  if (wasmBinary) {
935
951
  options.wasmBinary = wasmBinary;
@@ -955,8 +971,8 @@
955
971
  let BASIS_ENCODER = null;
956
972
  let wasmBinary = null;
957
973
  [BASIS_ENCODER, wasmBinary] = await Promise.all([
958
- await loadLibrary(BASIS_CDN_ENCODER_JS, "textures", options),
959
- await loadLibrary(BASIS_CDN_ENCODER_WASM, "textures", options)
974
+ await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER, "textures", options),
975
+ await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER_WASM, "textures", options)
960
976
  ]);
961
977
  BASIS_ENCODER = BASIS_ENCODER || globalThis.BASIS;
962
978
  return await initializeBasisEncoderModule(BASIS_ENCODER, wasmBinary);
@@ -1062,7 +1078,7 @@
1062
1078
  const fileConstructors = await loadBasisEncoderModule(options);
1063
1079
  return parseKTX2File(fileConstructors.KTX2File, data, options);
1064
1080
  }
1065
- const { BasisFile } = await loadBasisTrascoderModule(options);
1081
+ const { BasisFile } = await loadBasisTranscoderModule(options);
1066
1082
  return parseBasisFile(BasisFile, data, options);
1067
1083
  }
1068
1084
  switch (options.basis.module) {
@@ -1077,7 +1093,7 @@
1077
1093
  }
1078
1094
  case "transcoder":
1079
1095
  default:
1080
- const { BasisFile } = await loadBasisTrascoderModule(options);
1096
+ const { BasisFile } = await loadBasisTranscoderModule(options);
1081
1097
  return parseBasisFile(BasisFile, data, options);
1082
1098
  }
1083
1099
  }