@loaders.gl/core 4.2.0-alpha.6 → 4.2.0-beta.1

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 (44) hide show
  1. package/dist/dist.dev.js +1941 -1894
  2. package/dist/dist.min.js +3 -3
  3. package/dist/index.cjs +110 -68
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -0
  8. package/dist/lib/api/select-loader.d.ts.map +1 -1
  9. package/dist/lib/api/select-loader.js +3 -2
  10. package/dist/lib/fetch/fetch-error-message.d.ts.map +1 -1
  11. package/dist/lib/fetch/fetch-error-message.js +2 -0
  12. package/dist/lib/fetch/fetch-error.d.ts +14 -0
  13. package/dist/lib/fetch/fetch-error.d.ts.map +1 -0
  14. package/dist/lib/fetch/fetch-error.js +17 -0
  15. package/dist/lib/fetch/fetch-file.d.ts.map +1 -1
  16. package/dist/lib/fetch/fetch-file.js +1 -0
  17. package/dist/lib/init.js +1 -1
  18. package/dist/lib/loader-utils/option-utils.d.ts +1 -1
  19. package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
  20. package/dist/lib/loader-utils/option-utils.js +3 -0
  21. package/dist/lib/utils/mime-type-utils.d.ts +8 -0
  22. package/dist/lib/utils/mime-type-utils.d.ts.map +1 -1
  23. package/dist/lib/utils/mime-type-utils.js +13 -0
  24. package/dist/lib/utils/response-utils.d.ts.map +1 -1
  25. package/dist/lib/utils/response-utils.js +16 -10
  26. package/dist/lib/utils/url-utils.d.ts +1 -0
  27. package/dist/lib/utils/url-utils.d.ts.map +1 -1
  28. package/dist/lib/utils/url-utils.js +8 -0
  29. package/dist/null-loader.d.ts +40 -3
  30. package/dist/null-loader.d.ts.map +1 -1
  31. package/dist/null-loader.js +5 -1
  32. package/dist/null-worker-node.js +3 -1
  33. package/dist/null-worker.js +3 -1
  34. package/package.json +5 -5
  35. package/src/index.ts +1 -0
  36. package/src/lib/api/select-loader.ts +3 -2
  37. package/src/lib/fetch/fetch-error-message.ts +2 -0
  38. package/src/lib/fetch/fetch-error.ts +18 -0
  39. package/src/lib/fetch/fetch-file.ts +1 -0
  40. package/src/lib/loader-utils/option-utils.ts +3 -1
  41. package/src/lib/utils/mime-type-utils.ts +14 -0
  42. package/src/lib/utils/response-utils.ts +19 -11
  43. package/src/lib/utils/url-utils.ts +9 -0
  44. package/src/null-loader.ts +9 -4
package/dist/dist.dev.js CHANGED
@@ -32,6 +32,7 @@ var __exports__ = (() => {
32
32
  // bundle.ts
33
33
  var bundle_exports = {};
34
34
  __export(bundle_exports, {
35
+ FetchError: () => FetchError,
35
36
  JSONLoader: () => JSONLoader,
36
37
  NullLoader: () => NullLoader,
37
38
  NullWorkerLoader: () => NullWorkerLoader,
@@ -114,2195 +115,2236 @@ var __exports__ = (() => {
114
115
  var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
115
116
  var nodeVersion = matches && parseFloat(matches[1]) || 0;
116
117
 
117
- // ../loader-utils/src/lib/option-utils/merge-loader-options.ts
118
- function mergeLoaderOptions(baseOptions, newOptions) {
119
- return mergeOptionsRecursively(baseOptions || {}, newOptions);
118
+ // ../../node_modules/@babel/runtime/helpers/esm/typeof.js
119
+ function _typeof(obj) {
120
+ "@babel/helpers - typeof";
121
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
122
+ return typeof obj2;
123
+ } : function(obj2) {
124
+ return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
125
+ }, _typeof(obj);
120
126
  }
121
- function mergeOptionsRecursively(baseOptions, newOptions, level = 0) {
122
- if (level > 3) {
123
- return newOptions;
124
- }
125
- const options = { ...baseOptions };
126
- for (const [key, newValue] of Object.entries(newOptions)) {
127
- if (newValue && typeof newValue === "object" && !Array.isArray(newValue)) {
128
- options[key] = mergeOptionsRecursively(
129
- options[key] || {},
130
- newOptions[key],
131
- level + 1
132
- );
133
- } else {
134
- options[key] = newOptions[key];
135
- }
127
+
128
+ // ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
129
+ function _toPrimitive(input, hint) {
130
+ if (_typeof(input) !== "object" || input === null)
131
+ return input;
132
+ var prim = input[Symbol.toPrimitive];
133
+ if (prim !== void 0) {
134
+ var res = prim.call(input, hint || "default");
135
+ if (_typeof(res) !== "object")
136
+ return res;
137
+ throw new TypeError("@@toPrimitive must return a primitive value.");
136
138
  }
137
- return options;
139
+ return (hint === "string" ? String : Number)(input);
138
140
  }
139
141
 
140
- // ../worker-utils/src/lib/env-utils/version.ts
141
- var NPM_TAG = "latest";
142
- function getVersion() {
143
- if (!globalThis._loadersgl_?.version) {
144
- globalThis._loadersgl_ = globalThis._loadersgl_ || {};
145
- if (typeof __VERSION__ === "undefined") {
146
- console.warn(
147
- "loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN."
148
- );
149
- globalThis._loadersgl_.version = NPM_TAG;
150
- } else {
151
- globalThis._loadersgl_.version = __VERSION__;
152
- }
142
+ // ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
143
+ function _toPropertyKey(arg) {
144
+ var key = _toPrimitive(arg, "string");
145
+ return _typeof(key) === "symbol" ? key : String(key);
146
+ }
147
+
148
+ // ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
149
+ function _defineProperty(obj, key, value) {
150
+ key = _toPropertyKey(key);
151
+ if (key in obj) {
152
+ Object.defineProperty(obj, key, {
153
+ value,
154
+ enumerable: true,
155
+ configurable: true,
156
+ writable: true
157
+ });
158
+ } else {
159
+ obj[key] = value;
153
160
  }
154
- return globalThis._loadersgl_.version;
161
+ return obj;
155
162
  }
156
- var VERSION = getVersion();
157
163
 
158
- // ../worker-utils/src/lib/env-utils/assert.ts
159
- function assert2(condition, message) {
160
- if (!condition) {
161
- throw new Error(message || "loaders.gl assertion failed.");
164
+ // ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/lib/is-electron.js
165
+ function isElectron(mockUserAgent) {
166
+ if (typeof window !== "undefined" && typeof window.process === "object" && window.process.type === "renderer") {
167
+ return true;
162
168
  }
169
+ if (typeof process !== "undefined" && typeof process.versions === "object" && Boolean(process.versions["electron"])) {
170
+ return true;
171
+ }
172
+ const realUserAgent = typeof navigator === "object" && typeof navigator.userAgent === "string" && navigator.userAgent;
173
+ const userAgent = mockUserAgent || realUserAgent;
174
+ if (userAgent && userAgent.indexOf("Electron") >= 0) {
175
+ return true;
176
+ }
177
+ return false;
163
178
  }
164
179
 
165
- // ../worker-utils/src/lib/env-utils/globals.ts
166
- var globals2 = {
167
- self: typeof self !== "undefined" && self,
168
- window: typeof window !== "undefined" && window,
169
- global: typeof global !== "undefined" && global,
170
- document: typeof document !== "undefined" && document
171
- };
172
- var self_2 = globals2.self || globals2.window || globals2.global || {};
173
- var window_2 = globals2.window || globals2.self || globals2.global || {};
174
- var global_2 = globals2.global || globals2.self || globals2.window || {};
175
- var document_2 = globals2.document || {};
176
- var isBrowser2 = (
177
- // @ts-ignore process.browser
178
- typeof process !== "object" || String(process) !== "[object process]" || process.browser
179
- );
180
- var isMobile = typeof window !== "undefined" && typeof window.orientation !== "undefined";
181
- var matches2 = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
182
- var nodeVersion2 = matches2 && parseFloat(matches2[1]) || 0;
180
+ // ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/lib/is-browser.js
181
+ function isBrowser2() {
182
+ const isNode = typeof process === "object" && String(process) === "[object process]" && !process.browser;
183
+ return !isNode || isElectron();
184
+ }
183
185
 
184
- // ../worker-utils/src/lib/worker-farm/worker-job.ts
185
- var WorkerJob = class {
186
- name;
187
- workerThread;
188
- isRunning = true;
189
- /** Promise that resolves when Job is done */
190
- result;
191
- _resolve = () => {
192
- };
193
- _reject = () => {
194
- };
195
- constructor(jobName, workerThread) {
196
- this.name = jobName;
197
- this.workerThread = workerThread;
198
- this.result = new Promise((resolve2, reject) => {
199
- this._resolve = resolve2;
200
- this._reject = reject;
201
- });
186
+ // ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/lib/globals.js
187
+ var self_2 = globalThis.self || globalThis.window || globalThis.global;
188
+ var window_2 = globalThis.window || globalThis.self || globalThis.global;
189
+ var document_2 = globalThis.document || {};
190
+ var process_ = globalThis.process || {};
191
+ var console_ = globalThis.console;
192
+ var navigator_ = globalThis.navigator || {};
193
+
194
+ // ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/utils/globals.js
195
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "untranspiled source";
196
+ var isBrowser3 = isBrowser2();
197
+
198
+ // ../../node_modules/@probe.gl/log/dist/utils/local-storage.js
199
+ function getStorage(type) {
200
+ try {
201
+ const storage = window[type];
202
+ const x = "__storage_test__";
203
+ storage.setItem(x, x);
204
+ storage.removeItem(x);
205
+ return storage;
206
+ } catch (e) {
207
+ return null;
202
208
  }
203
- /**
204
- * Send a message to the job's worker thread
205
- * @param data any data structure, ideally consisting mostly of transferrable objects
206
- */
207
- postMessage(type, payload) {
208
- this.workerThread.postMessage({
209
- source: "loaders.gl",
210
- // Lets worker ignore unrelated messages
211
- type,
212
- payload
213
- });
209
+ }
210
+ var LocalStorage = class {
211
+ constructor(id, defaultConfig) {
212
+ let type = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "sessionStorage";
213
+ _defineProperty(this, "storage", void 0);
214
+ _defineProperty(this, "id", void 0);
215
+ _defineProperty(this, "config", void 0);
216
+ this.storage = getStorage(type);
217
+ this.id = id;
218
+ this.config = defaultConfig;
219
+ this._loadConfiguration();
214
220
  }
215
- /**
216
- * Call to resolve the `result` Promise with the supplied value
217
- */
218
- done(value) {
219
- assert2(this.isRunning);
220
- this.isRunning = false;
221
- this._resolve(value);
221
+ getConfiguration() {
222
+ return this.config;
222
223
  }
223
- /**
224
- * Call to reject the `result` Promise with the supplied error
225
- */
226
- error(error) {
227
- assert2(this.isRunning);
228
- this.isRunning = false;
229
- this._reject(error);
224
+ setConfiguration(configuration) {
225
+ Object.assign(this.config, configuration);
226
+ if (this.storage) {
227
+ const serialized = JSON.stringify(this.config);
228
+ this.storage.setItem(this.id, serialized);
229
+ }
230
230
  }
231
- };
232
-
233
- // ../worker-utils/src/lib/node/worker_threads-browser.ts
234
- var NodeWorker = class {
235
- terminate() {
231
+ _loadConfiguration() {
232
+ let configuration = {};
233
+ if (this.storage) {
234
+ const serializedConfiguration = this.storage.getItem(this.id);
235
+ configuration = serializedConfiguration ? JSON.parse(serializedConfiguration) : {};
236
+ }
237
+ Object.assign(this.config, configuration);
238
+ return this;
236
239
  }
237
240
  };
238
241
 
239
- // ../worker-utils/src/lib/worker-utils/get-loadable-worker-url.ts
240
- var workerURLCache = /* @__PURE__ */ new Map();
241
- function getLoadableWorkerURL(props) {
242
- assert2(props.source && !props.url || !props.source && props.url);
243
- let workerURL = workerURLCache.get(props.source || props.url);
244
- if (!workerURL) {
245
- if (props.url) {
246
- workerURL = getLoadableWorkerURLFromURL(props.url);
247
- workerURLCache.set(props.url, workerURL);
248
- }
249
- if (props.source) {
250
- workerURL = getLoadableWorkerURLFromSource(props.source);
251
- workerURLCache.set(props.source, workerURL);
252
- }
253
- }
254
- assert2(workerURL);
255
- return workerURL;
256
- }
257
- function getLoadableWorkerURLFromURL(url) {
258
- if (!url.startsWith("http")) {
259
- return url;
242
+ // ../../node_modules/@probe.gl/log/dist/utils/formatters.js
243
+ function formatTime(ms) {
244
+ let formatted;
245
+ if (ms < 10) {
246
+ formatted = "".concat(ms.toFixed(2), "ms");
247
+ } else if (ms < 100) {
248
+ formatted = "".concat(ms.toFixed(1), "ms");
249
+ } else if (ms < 1e3) {
250
+ formatted = "".concat(ms.toFixed(0), "ms");
251
+ } else {
252
+ formatted = "".concat((ms / 1e3).toFixed(2), "s");
260
253
  }
261
- const workerSource = buildScriptSource(url);
262
- return getLoadableWorkerURLFromSource(workerSource);
254
+ return formatted;
263
255
  }
264
- function getLoadableWorkerURLFromSource(workerSource) {
265
- const blob = new Blob([workerSource], { type: "application/javascript" });
266
- return URL.createObjectURL(blob);
256
+ function leftPad(string) {
257
+ let length = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 8;
258
+ const padLength = Math.max(length - string.length, 0);
259
+ return "".concat(" ".repeat(padLength)).concat(string);
267
260
  }
268
- function buildScriptSource(workerUrl) {
269
- return `try {
270
- importScripts('${workerUrl}');
271
- } catch (error) {
272
- console.error(error);
273
- throw error;
274
- }`;
261
+ function formatImage(image, message, scale) {
262
+ let maxWidth = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 600;
263
+ const imageUrl = image.src.replace(/\(/g, "%28").replace(/\)/g, "%29");
264
+ if (image.width > maxWidth) {
265
+ scale = Math.min(scale, maxWidth / image.width);
266
+ }
267
+ const width = image.width * scale;
268
+ const height = image.height * scale;
269
+ const style = ["font-size:1px;", "padding:".concat(Math.floor(height / 2), "px ").concat(Math.floor(width / 2), "px;"), "line-height:".concat(height, "px;"), "background:url(".concat(imageUrl, ");"), "background-size:".concat(width, "px ").concat(height, "px;"), "color:transparent;"].join("");
270
+ return ["".concat(message, " %c+"), style];
275
271
  }
276
272
 
277
- // ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
278
- function getTransferList(object, recursive = true, transfers) {
279
- const transfersSet = transfers || /* @__PURE__ */ new Set();
280
- if (!object) {
281
- } else if (isTransferable(object)) {
282
- transfersSet.add(object);
283
- } else if (isTransferable(object.buffer)) {
284
- transfersSet.add(object.buffer);
285
- } else if (ArrayBuffer.isView(object)) {
286
- } else if (recursive && typeof object === "object") {
287
- for (const key in object) {
288
- getTransferList(object[key], recursive, transfersSet);
289
- }
273
+ // ../../node_modules/@probe.gl/log/dist/utils/color.js
274
+ var COLOR;
275
+ (function(COLOR2) {
276
+ COLOR2[COLOR2["BLACK"] = 30] = "BLACK";
277
+ COLOR2[COLOR2["RED"] = 31] = "RED";
278
+ COLOR2[COLOR2["GREEN"] = 32] = "GREEN";
279
+ COLOR2[COLOR2["YELLOW"] = 33] = "YELLOW";
280
+ COLOR2[COLOR2["BLUE"] = 34] = "BLUE";
281
+ COLOR2[COLOR2["MAGENTA"] = 35] = "MAGENTA";
282
+ COLOR2[COLOR2["CYAN"] = 36] = "CYAN";
283
+ COLOR2[COLOR2["WHITE"] = 37] = "WHITE";
284
+ COLOR2[COLOR2["BRIGHT_BLACK"] = 90] = "BRIGHT_BLACK";
285
+ COLOR2[COLOR2["BRIGHT_RED"] = 91] = "BRIGHT_RED";
286
+ COLOR2[COLOR2["BRIGHT_GREEN"] = 92] = "BRIGHT_GREEN";
287
+ COLOR2[COLOR2["BRIGHT_YELLOW"] = 93] = "BRIGHT_YELLOW";
288
+ COLOR2[COLOR2["BRIGHT_BLUE"] = 94] = "BRIGHT_BLUE";
289
+ COLOR2[COLOR2["BRIGHT_MAGENTA"] = 95] = "BRIGHT_MAGENTA";
290
+ COLOR2[COLOR2["BRIGHT_CYAN"] = 96] = "BRIGHT_CYAN";
291
+ COLOR2[COLOR2["BRIGHT_WHITE"] = 97] = "BRIGHT_WHITE";
292
+ })(COLOR || (COLOR = {}));
293
+ var BACKGROUND_INCREMENT = 10;
294
+ function getColor(color) {
295
+ if (typeof color !== "string") {
296
+ return color;
290
297
  }
291
- return transfers === void 0 ? Array.from(transfersSet) : [];
298
+ color = color.toUpperCase();
299
+ return COLOR[color] || COLOR.WHITE;
292
300
  }
293
- function isTransferable(object) {
294
- if (!object) {
295
- return false;
296
- }
297
- if (object instanceof ArrayBuffer) {
298
- return true;
299
- }
300
- if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
301
- return true;
301
+ function addColor(string, color, background) {
302
+ if (!isBrowser2 && typeof string === "string") {
303
+ if (color) {
304
+ const colorCode = getColor(color);
305
+ string = "\x1B[".concat(colorCode, "m").concat(string, "\x1B[39m");
306
+ }
307
+ if (background) {
308
+ const colorCode = getColor(background);
309
+ string = "\x1B[".concat(colorCode + BACKGROUND_INCREMENT, "m").concat(string, "\x1B[49m");
310
+ }
302
311
  }
303
- if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
304
- return true;
312
+ return string;
313
+ }
314
+
315
+ // ../../node_modules/@probe.gl/log/dist/utils/autobind.js
316
+ function autobind(obj) {
317
+ let predefined = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ["constructor"];
318
+ const proto = Object.getPrototypeOf(obj);
319
+ const propNames = Object.getOwnPropertyNames(proto);
320
+ const object = obj;
321
+ for (const key of propNames) {
322
+ const value = object[key];
323
+ if (typeof value === "function") {
324
+ if (!predefined.find((name) => key === name)) {
325
+ object[key] = value.bind(obj);
326
+ }
327
+ }
305
328
  }
306
- if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
307
- return true;
329
+ }
330
+
331
+ // ../../node_modules/@probe.gl/log/dist/utils/assert.js
332
+ function assert2(condition, message) {
333
+ if (!condition) {
334
+ throw new Error(message || "Assertion failed");
308
335
  }
309
- return false;
310
336
  }
311
- function getTransferListForWriter(object) {
312
- if (object === null) {
313
- return {};
337
+
338
+ // ../../node_modules/@probe.gl/log/dist/utils/hi-res-timestamp.js
339
+ function getHiResTimestamp() {
340
+ let timestamp;
341
+ if (isBrowser2() && window_2.performance) {
342
+ var _window$performance, _window$performance$n;
343
+ timestamp = window_2 === null || window_2 === void 0 ? void 0 : (_window$performance = window_2.performance) === null || _window$performance === void 0 ? void 0 : (_window$performance$n = _window$performance.now) === null || _window$performance$n === void 0 ? void 0 : _window$performance$n.call(_window$performance);
344
+ } else if ("hrtime" in process_) {
345
+ var _process$hrtime;
346
+ const timeParts = process_ === null || process_ === void 0 ? void 0 : (_process$hrtime = process_.hrtime) === null || _process$hrtime === void 0 ? void 0 : _process$hrtime.call(process_);
347
+ timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
348
+ } else {
349
+ timestamp = Date.now();
314
350
  }
315
- const clone = Object.assign({}, object);
316
- Object.keys(clone).forEach((key) => {
317
- if (typeof object[key] === "object" && !ArrayBuffer.isView(object[key]) && !(object[key] instanceof Array)) {
318
- clone[key] = getTransferListForWriter(object[key]);
319
- } else if (typeof clone[key] === "function" || clone[key] instanceof RegExp) {
320
- clone[key] = {};
321
- } else {
322
- clone[key] = object[key];
323
- }
324
- });
325
- return clone;
351
+ return timestamp;
326
352
  }
327
353
 
328
- // ../worker-utils/src/lib/worker-farm/worker-thread.ts
329
- var NOOP = () => {
354
+ // ../../node_modules/@probe.gl/log/dist/log.js
355
+ var originalConsole = {
356
+ debug: isBrowser2() ? console.debug || console.log : console.log,
357
+ log: console.log,
358
+ info: console.info,
359
+ warn: console.warn,
360
+ error: console.error
330
361
  };
331
- var WorkerThread = class {
332
- name;
333
- source;
334
- url;
335
- terminated = false;
336
- worker;
337
- onMessage;
338
- onError;
339
- _loadableURL = "";
340
- /** Checks if workers are supported on this platform */
341
- static isSupported() {
342
- return typeof Worker !== "undefined" && isBrowser2 || typeof NodeWorker !== "undefined" && !isBrowser2;
362
+ var DEFAULT_LOG_CONFIGURATION = {
363
+ enabled: true,
364
+ level: 0
365
+ };
366
+ function noop() {
367
+ }
368
+ var cache = {};
369
+ var ONCE = {
370
+ once: true
371
+ };
372
+ var Log = class {
373
+ constructor() {
374
+ let {
375
+ id
376
+ } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
377
+ id: ""
378
+ };
379
+ _defineProperty(this, "id", void 0);
380
+ _defineProperty(this, "VERSION", VERSION);
381
+ _defineProperty(this, "_startTs", getHiResTimestamp());
382
+ _defineProperty(this, "_deltaTs", getHiResTimestamp());
383
+ _defineProperty(this, "_storage", void 0);
384
+ _defineProperty(this, "userData", {});
385
+ _defineProperty(this, "LOG_THROTTLE_TIMEOUT", 0);
386
+ this.id = id;
387
+ this.userData = {};
388
+ this._storage = new LocalStorage("__probe-".concat(this.id, "__"), DEFAULT_LOG_CONFIGURATION);
389
+ this.timeStamp("".concat(this.id, " started"));
390
+ autobind(this);
391
+ Object.seal(this);
343
392
  }
344
- constructor(props) {
345
- const { name, source, url } = props;
346
- assert2(source || url);
347
- this.name = name;
348
- this.source = source;
349
- this.url = url;
350
- this.onMessage = NOOP;
351
- this.onError = (error) => console.log(error);
352
- this.worker = isBrowser2 ? this._createBrowserWorker() : this._createNodeWorker();
393
+ set level(newLevel) {
394
+ this.setLevel(newLevel);
353
395
  }
354
- /**
355
- * Terminate this worker thread
356
- * @note Can free up significant memory
357
- */
358
- destroy() {
359
- this.onMessage = NOOP;
360
- this.onError = NOOP;
361
- this.worker.terminate();
362
- this.terminated = true;
396
+ get level() {
397
+ return this.getLevel();
363
398
  }
364
- get isRunning() {
365
- return Boolean(this.onMessage);
399
+ isEnabled() {
400
+ return this._storage.config.enabled;
366
401
  }
367
- /**
368
- * Send a message to this worker thread
369
- * @param data any data structure, ideally consisting mostly of transferrable objects
370
- * @param transferList If not supplied, calculated automatically by traversing data
371
- */
372
- postMessage(data, transferList) {
373
- transferList = transferList || getTransferList(data);
374
- this.worker.postMessage(data, transferList);
402
+ getLevel() {
403
+ return this._storage.config.level;
375
404
  }
376
- // PRIVATE
377
- /**
378
- * Generate a standard Error from an ErrorEvent
379
- * @param event
380
- */
381
- _getErrorFromErrorEvent(event) {
382
- let message = "Failed to load ";
383
- message += `worker ${this.name} from ${this.url}. `;
384
- if (event.message) {
385
- message += `${event.message} in `;
386
- }
387
- if (event.lineno) {
388
- message += `:${event.lineno}:${event.colno}`;
389
- }
390
- return new Error(message);
405
+ getTotal() {
406
+ return Number((getHiResTimestamp() - this._startTs).toPrecision(10));
391
407
  }
392
- /**
393
- * Creates a worker thread on the browser
394
- */
395
- _createBrowserWorker() {
396
- this._loadableURL = getLoadableWorkerURL({ source: this.source, url: this.url });
397
- const worker = new Worker(this._loadableURL, { name: this.name });
398
- worker.onmessage = (event) => {
399
- if (!event.data) {
400
- this.onError(new Error("No data received"));
401
- } else {
402
- this.onMessage(event.data);
403
- }
404
- };
405
- worker.onerror = (error) => {
406
- this.onError(this._getErrorFromErrorEvent(error));
407
- this.terminated = true;
408
- };
409
- worker.onmessageerror = (event) => console.error(event);
410
- return worker;
408
+ getDelta() {
409
+ return Number((getHiResTimestamp() - this._deltaTs).toPrecision(10));
411
410
  }
412
- /**
413
- * Creates a worker thread in node.js
414
- * @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool
415
- */
416
- _createNodeWorker() {
417
- let worker;
418
- if (this.url) {
419
- const absolute = this.url.includes(":/") || this.url.startsWith("/");
420
- const url = absolute ? this.url : `./${this.url}`;
421
- worker = new NodeWorker(url, { eval: false });
422
- } else if (this.source) {
423
- worker = new NodeWorker(this.source, { eval: true });
424
- } else {
425
- throw new Error("no worker");
426
- }
427
- worker.on("message", (data) => {
428
- this.onMessage(data);
429
- });
430
- worker.on("error", (error) => {
431
- this.onError(error);
432
- });
433
- worker.on("exit", (code) => {
434
- });
435
- return worker;
411
+ set priority(newPriority) {
412
+ this.level = newPriority;
436
413
  }
437
- };
438
-
439
- // ../worker-utils/src/lib/worker-farm/worker-pool.ts
440
- var WorkerPool = class {
441
- name = "unnamed";
442
- source;
443
- // | Function;
444
- url;
445
- maxConcurrency = 1;
446
- maxMobileConcurrency = 1;
447
- onDebug = () => {
448
- };
449
- reuseWorkers = true;
450
- props = {};
451
- jobQueue = [];
452
- idleQueue = [];
453
- count = 0;
454
- isDestroyed = false;
455
- /** Checks if workers are supported on this platform */
456
- static isSupported() {
457
- return WorkerThread.isSupported();
458
- }
459
- /**
460
- * @param processor - worker function
461
- * @param maxConcurrency - max count of workers
462
- */
463
- constructor(props) {
464
- this.source = props.source;
465
- this.url = props.url;
466
- this.setProps(props);
414
+ get priority() {
415
+ return this.level;
467
416
  }
468
- /**
469
- * Terminates all workers in the pool
470
- * @note Can free up significant memory
471
- */
472
- destroy() {
473
- this.idleQueue.forEach((worker) => worker.destroy());
474
- this.isDestroyed = true;
417
+ getPriority() {
418
+ return this.level;
475
419
  }
476
- setProps(props) {
477
- this.props = { ...this.props, ...props };
478
- if (props.name !== void 0) {
479
- this.name = props.name;
480
- }
481
- if (props.maxConcurrency !== void 0) {
482
- this.maxConcurrency = props.maxConcurrency;
483
- }
484
- if (props.maxMobileConcurrency !== void 0) {
485
- this.maxMobileConcurrency = props.maxMobileConcurrency;
486
- }
487
- if (props.reuseWorkers !== void 0) {
488
- this.reuseWorkers = props.reuseWorkers;
489
- }
490
- if (props.onDebug !== void 0) {
491
- this.onDebug = props.onDebug;
492
- }
420
+ enable() {
421
+ let enabled = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
422
+ this._storage.setConfiguration({
423
+ enabled
424
+ });
425
+ return this;
493
426
  }
494
- async startJob(name, onMessage3 = (job, type, data) => job.done(data), onError = (job, error) => job.error(error)) {
495
- const startPromise = new Promise((onStart) => {
496
- this.jobQueue.push({ name, onMessage: onMessage3, onError, onStart });
497
- return this;
427
+ setLevel(level) {
428
+ this._storage.setConfiguration({
429
+ level
498
430
  });
499
- this._startQueuedJob();
500
- return await startPromise;
431
+ return this;
501
432
  }
502
- // PRIVATE
503
- /**
504
- * Starts first queued job if worker is available or can be created
505
- * Called when job is started and whenever a worker returns to the idleQueue
506
- */
507
- async _startQueuedJob() {
508
- if (!this.jobQueue.length) {
509
- return;
510
- }
511
- const workerThread = this._getAvailableWorker();
512
- if (!workerThread) {
513
- return;
514
- }
515
- const queuedJob = this.jobQueue.shift();
516
- if (queuedJob) {
517
- this.onDebug({
518
- message: "Starting job",
519
- name: queuedJob.name,
520
- workerThread,
521
- backlog: this.jobQueue.length
522
- });
523
- const job = new WorkerJob(queuedJob.name, workerThread);
524
- workerThread.onMessage = (data) => queuedJob.onMessage(job, data.type, data.payload);
525
- workerThread.onError = (error) => queuedJob.onError(job, error);
526
- queuedJob.onStart(job);
527
- try {
528
- await job.result;
529
- } catch (error) {
530
- console.error(`Worker exception: ${error}`);
531
- } finally {
532
- this.returnWorkerToQueue(workerThread);
533
- }
534
- }
433
+ get(setting) {
434
+ return this._storage.config[setting];
535
435
  }
536
- /**
537
- * Returns a worker to the idle queue
538
- * Destroys the worker if
539
- * - pool is destroyed
540
- * - if this pool doesn't reuse workers
541
- * - if maxConcurrency has been lowered
542
- * @param worker
543
- */
544
- returnWorkerToQueue(worker) {
545
- const shouldDestroyWorker = (
546
- // Workers on Node.js prevent the process from exiting.
547
- // Until we figure out how to close them before exit, we always destroy them
548
- !isBrowser2 || // If the pool is destroyed, there is no reason to keep the worker around
549
- this.isDestroyed || // If the app has disabled worker reuse, any completed workers should be destroyed
550
- !this.reuseWorkers || // If concurrency has been lowered, this worker might be surplus to requirements
551
- this.count > this._getMaxConcurrency()
552
- );
553
- if (shouldDestroyWorker) {
554
- worker.destroy();
555
- this.count--;
436
+ set(setting, value) {
437
+ this._storage.setConfiguration({
438
+ [setting]: value
439
+ });
440
+ }
441
+ settings() {
442
+ if (console.table) {
443
+ console.table(this._storage.config);
556
444
  } else {
557
- this.idleQueue.push(worker);
558
- }
559
- if (!this.isDestroyed) {
560
- this._startQueuedJob();
445
+ console.log(this._storage.config);
561
446
  }
562
447
  }
563
- /**
564
- * Returns idle worker or creates new worker if maxConcurrency has not been reached
565
- */
566
- _getAvailableWorker() {
567
- if (this.idleQueue.length > 0) {
568
- return this.idleQueue.shift() || null;
569
- }
570
- if (this.count < this._getMaxConcurrency()) {
571
- this.count++;
572
- const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;
573
- return new WorkerThread({ name, source: this.source, url: this.url });
574
- }
575
- return null;
448
+ assert(condition, message) {
449
+ assert2(condition, message);
576
450
  }
577
- _getMaxConcurrency() {
578
- return isMobile ? this.maxMobileConcurrency : this.maxConcurrency;
451
+ warn(message) {
452
+ return this._getLogFunction(0, message, originalConsole.warn, arguments, ONCE);
579
453
  }
580
- };
581
-
582
- // ../worker-utils/src/lib/worker-farm/worker-farm.ts
583
- var DEFAULT_PROPS = {
584
- maxConcurrency: 3,
585
- maxMobileConcurrency: 1,
586
- reuseWorkers: true,
587
- onDebug: () => {
454
+ error(message) {
455
+ return this._getLogFunction(0, message, originalConsole.error, arguments);
588
456
  }
589
- };
590
- var _WorkerFarm = class {
591
- props;
592
- workerPools = /* @__PURE__ */ new Map();
593
- /** Checks if workers are supported on this platform */
594
- static isSupported() {
595
- return WorkerThread.isSupported();
457
+ deprecated(oldUsage, newUsage) {
458
+ return this.warn("`".concat(oldUsage, "` is deprecated and will be removed in a later version. Use `").concat(newUsage, "` instead"));
596
459
  }
597
- /** Get the singleton instance of the global worker farm */
598
- static getWorkerFarm(props = {}) {
599
- _WorkerFarm._workerFarm = _WorkerFarm._workerFarm || new _WorkerFarm({});
600
- _WorkerFarm._workerFarm.setProps(props);
601
- return _WorkerFarm._workerFarm;
460
+ removed(oldUsage, newUsage) {
461
+ return this.error("`".concat(oldUsage, "` has been removed. Use `").concat(newUsage, "` instead"));
602
462
  }
603
- /** get global instance with WorkerFarm.getWorkerFarm() */
604
- constructor(props) {
605
- this.props = { ...DEFAULT_PROPS };
606
- this.setProps(props);
607
- this.workerPools = /* @__PURE__ */ new Map();
463
+ probe(logLevel, message) {
464
+ return this._getLogFunction(logLevel, message, originalConsole.log, arguments, {
465
+ time: true,
466
+ once: true
467
+ });
608
468
  }
609
- /**
610
- * Terminate all workers in the farm
611
- * @note Can free up significant memory
612
- */
613
- destroy() {
614
- for (const workerPool of this.workerPools.values()) {
615
- workerPool.destroy();
616
- }
617
- this.workerPools = /* @__PURE__ */ new Map();
469
+ log(logLevel, message) {
470
+ return this._getLogFunction(logLevel, message, originalConsole.debug, arguments);
618
471
  }
619
- /**
620
- * Set props used when initializing worker pools
621
- * @param props
622
- */
623
- setProps(props) {
624
- this.props = { ...this.props, ...props };
625
- for (const workerPool of this.workerPools.values()) {
626
- workerPool.setProps(this._getWorkerPoolProps());
627
- }
472
+ info(logLevel, message) {
473
+ return this._getLogFunction(logLevel, message, console.info, arguments);
628
474
  }
629
- /**
630
- * Returns a worker pool for the specified worker
631
- * @param options - only used first time for a specific worker name
632
- * @param options.name - the name of the worker - used to identify worker pool
633
- * @param options.url -
634
- * @param options.source -
635
- * @example
636
- * const job = WorkerFarm.getWorkerFarm().getWorkerPool({name, url}).startJob(...);
637
- */
638
- getWorkerPool(options) {
639
- const { name, source, url } = options;
640
- let workerPool = this.workerPools.get(name);
641
- if (!workerPool) {
642
- workerPool = new WorkerPool({
643
- name,
644
- source,
645
- url
475
+ once(logLevel, message) {
476
+ return this._getLogFunction(logLevel, message, originalConsole.debug || originalConsole.info, arguments, ONCE);
477
+ }
478
+ table(logLevel, table, columns) {
479
+ if (table) {
480
+ return this._getLogFunction(logLevel, table, console.table || noop, columns && [columns], {
481
+ tag: getTableHeader(table)
646
482
  });
647
- workerPool.setProps(this._getWorkerPoolProps());
648
- this.workerPools.set(name, workerPool);
649
483
  }
650
- return workerPool;
651
- }
652
- _getWorkerPoolProps() {
653
- return {
654
- maxConcurrency: this.props.maxConcurrency,
655
- maxMobileConcurrency: this.props.maxMobileConcurrency,
656
- reuseWorkers: this.props.reuseWorkers,
657
- onDebug: this.props.onDebug
658
- };
484
+ return noop;
659
485
  }
660
- };
661
- var WorkerFarm = _WorkerFarm;
662
- // singleton
663
- __publicField(WorkerFarm, "_workerFarm");
664
-
665
- // ../worker-utils/src/lib/worker-api/get-worker-url.ts
666
- function getWorkerName(worker) {
667
- const warning = worker.version !== VERSION ? ` (worker-utils@${VERSION})` : "";
668
- return `${worker.name}@${worker.version}${warning}`;
669
- }
670
- function getWorkerURL(worker, options = {}) {
671
- const workerOptions = options[worker.id] || {};
672
- const workerFile = isBrowser2 ? `${worker.id}-worker.js` : `${worker.id}-worker-node.js`;
673
- let url = workerOptions.workerUrl;
674
- if (!url && worker.id === "compression") {
675
- url = options.workerUrl;
486
+ image(_ref) {
487
+ let {
488
+ logLevel,
489
+ priority,
490
+ image,
491
+ message = "",
492
+ scale = 1
493
+ } = _ref;
494
+ if (!this._shouldLog(logLevel || priority)) {
495
+ return noop;
496
+ }
497
+ return isBrowser2() ? logImageInBrowser({
498
+ image,
499
+ message,
500
+ scale
501
+ }) : logImageInNode({
502
+ image,
503
+ message,
504
+ scale
505
+ });
676
506
  }
677
- if (options._workerType === "test") {
678
- if (isBrowser2) {
679
- url = `modules/${worker.module}/dist/${workerFile}`;
680
- } else {
681
- url = `modules/${worker.module}/src/workers/${worker.id}-worker-node.ts`;
507
+ time(logLevel, message) {
508
+ return this._getLogFunction(logLevel, message, console.time ? console.time : console.info);
509
+ }
510
+ timeEnd(logLevel, message) {
511
+ return this._getLogFunction(logLevel, message, console.timeEnd ? console.timeEnd : console.info);
512
+ }
513
+ timeStamp(logLevel, message) {
514
+ return this._getLogFunction(logLevel, message, console.timeStamp || noop);
515
+ }
516
+ group(logLevel, message) {
517
+ let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {
518
+ collapsed: false
519
+ };
520
+ const options = normalizeArguments({
521
+ logLevel,
522
+ message,
523
+ opts
524
+ });
525
+ const {
526
+ collapsed
527
+ } = opts;
528
+ options.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
529
+ return this._getLogFunction(options);
530
+ }
531
+ groupCollapsed(logLevel, message) {
532
+ let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
533
+ return this.group(logLevel, message, Object.assign({}, opts, {
534
+ collapsed: true
535
+ }));
536
+ }
537
+ groupEnd(logLevel) {
538
+ return this._getLogFunction(logLevel, "", console.groupEnd || noop);
539
+ }
540
+ withGroup(logLevel, message, func) {
541
+ this.group(logLevel, message)();
542
+ try {
543
+ func();
544
+ } finally {
545
+ this.groupEnd(logLevel)();
682
546
  }
683
547
  }
684
- if (!url) {
685
- let version = worker.version;
686
- if (version === "latest") {
687
- version = NPM_TAG;
548
+ trace() {
549
+ if (console.trace) {
550
+ console.trace();
688
551
  }
689
- const versionTag = version ? `@${version}` : "";
690
- url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;
691
552
  }
692
- assert2(url);
693
- return url;
694
- }
695
-
696
- // ../worker-utils/src/lib/worker-api/process-on-worker.ts
697
- async function processOnWorker(worker, data, options = {}, context = {}) {
698
- const name = getWorkerName(worker);
699
- const workerFarm = WorkerFarm.getWorkerFarm(options);
700
- const { source } = options;
701
- const workerPoolProps = { name, source };
702
- if (!source) {
703
- workerPoolProps.url = getWorkerURL(worker, options);
553
+ _shouldLog(logLevel) {
554
+ return this.isEnabled() && this.getLevel() >= normalizeLogLevel(logLevel);
704
555
  }
705
- const workerPool = workerFarm.getWorkerPool(workerPoolProps);
706
- const jobName = options.jobName || worker.name;
707
- const job = await workerPool.startJob(
708
- jobName,
709
- // eslint-disable-next-line
710
- onMessage.bind(null, context)
711
- );
712
- const transferableOptions = getTransferListForWriter(options);
713
- job.postMessage("process", { input: data, options: transferableOptions });
714
- const result = await job.result;
715
- return result.result;
716
- }
717
- async function onMessage(context, job, type, payload) {
718
- switch (type) {
719
- case "done":
720
- job.done(payload);
721
- break;
722
- case "error":
723
- job.error(new Error(payload.error));
724
- break;
725
- case "process":
726
- const { id, input, options } = payload;
727
- try {
728
- if (!context.process) {
729
- job.postMessage("error", { id, error: "Worker not set up to process on main thread" });
730
- return;
556
+ _getLogFunction(logLevel, message, method, args, opts) {
557
+ if (this._shouldLog(logLevel)) {
558
+ opts = normalizeArguments({
559
+ logLevel,
560
+ message,
561
+ args,
562
+ opts
563
+ });
564
+ method = method || opts.method;
565
+ assert2(method);
566
+ opts.total = this.getTotal();
567
+ opts.delta = this.getDelta();
568
+ this._deltaTs = getHiResTimestamp();
569
+ const tag = opts.tag || opts.message;
570
+ if (opts.once && tag) {
571
+ if (!cache[tag]) {
572
+ cache[tag] = getHiResTimestamp();
573
+ } else {
574
+ return noop;
731
575
  }
732
- const result = await context.process(input, options);
733
- job.postMessage("done", { id, result });
734
- } catch (error) {
735
- const message = error instanceof Error ? error.message : "unknown error";
736
- job.postMessage("error", { id, error: message });
737
576
  }
577
+ message = decorateMessage(this.id, opts.message, opts);
578
+ return method.bind(console, message, ...opts.args);
579
+ }
580
+ return noop;
581
+ }
582
+ };
583
+ _defineProperty(Log, "VERSION", VERSION);
584
+ function normalizeLogLevel(logLevel) {
585
+ if (!logLevel) {
586
+ return 0;
587
+ }
588
+ let resolvedLevel;
589
+ switch (typeof logLevel) {
590
+ case "number":
591
+ resolvedLevel = logLevel;
592
+ break;
593
+ case "object":
594
+ resolvedLevel = logLevel.logLevel || logLevel.priority || 0;
738
595
  break;
739
596
  default:
740
- console.warn(`process-on-worker: unknown message ${type}`);
741
- }
742
- }
743
-
744
- // ../worker-utils/src/lib/worker-api/validate-worker-version.ts
745
- function validateWorkerVersion(worker, coreVersion = VERSION) {
746
- assert2(worker, "no worker provided");
747
- const workerVersion = worker.version;
748
- if (!coreVersion || !workerVersion) {
749
- return false;
597
+ return 0;
750
598
  }
751
- return true;
599
+ assert2(Number.isFinite(resolvedLevel) && resolvedLevel >= 0);
600
+ return resolvedLevel;
752
601
  }
753
-
754
- // ../loader-utils/src/lib/worker-loader-utils/parse-with-worker.ts
755
- function canParseWithWorker(loader, options) {
756
- if (!WorkerFarm.isSupported()) {
757
- return false;
758
- }
759
- if (!isBrowser2 && !options?._nodeWorkers) {
760
- return false;
602
+ function normalizeArguments(opts) {
603
+ const {
604
+ logLevel,
605
+ message
606
+ } = opts;
607
+ opts.logLevel = normalizeLogLevel(logLevel);
608
+ const args = opts.args ? Array.from(opts.args) : [];
609
+ while (args.length && args.shift() !== message) {
761
610
  }
762
- return loader.worker && options?.worker;
763
- }
764
- async function parseWithWorker(loader, data, options, context, parseOnMainThread) {
765
- const name = loader.id;
766
- const url = getWorkerURL(loader, options);
767
- const workerFarm = WorkerFarm.getWorkerFarm(options);
768
- const workerPool = workerFarm.getWorkerPool({ name, url });
769
- options = JSON.parse(JSON.stringify(options));
770
- context = JSON.parse(JSON.stringify(context || {}));
771
- const job = await workerPool.startJob(
772
- "process-on-worker",
773
- // @ts-expect-error
774
- onMessage2.bind(null, parseOnMainThread)
775
- // eslint-disable-line @typescript-eslint/no-misused-promises
776
- );
777
- job.postMessage("process", {
778
- // @ts-ignore
779
- input: data,
780
- options,
781
- context
782
- });
783
- const result = await job.result;
784
- return await result.result;
785
- }
786
- async function onMessage2(parseOnMainThread, job, type, payload) {
787
- switch (type) {
788
- case "done":
789
- job.done(payload);
790
- break;
791
- case "error":
792
- job.error(new Error(payload.error));
793
- break;
794
- case "process":
795
- const { id, input, options } = payload;
796
- try {
797
- const result = await parseOnMainThread(input, options);
798
- job.postMessage("done", { id, result });
799
- } catch (error) {
800
- const message = error instanceof Error ? error.message : "unknown error";
801
- job.postMessage("error", { id, error: message });
611
+ switch (typeof logLevel) {
612
+ case "string":
613
+ case "function":
614
+ if (message !== void 0) {
615
+ args.unshift(message);
802
616
  }
617
+ opts.message = logLevel;
618
+ break;
619
+ case "object":
620
+ Object.assign(opts, logLevel);
803
621
  break;
804
622
  default:
805
- console.warn(`parse-with-worker unknown message ${type}`);
806
- }
807
- }
808
-
809
- // ../loader-utils/src/lib/worker-loader-utils/encode-with-worker.ts
810
- function canEncodeWithWorker(writer, options) {
811
- if (!WorkerFarm.isSupported()) {
812
- return false;
813
623
  }
814
- if (!isBrowser && !options?._nodeWorkers) {
815
- return false;
624
+ if (typeof opts.message === "function") {
625
+ opts.message = opts.message();
816
626
  }
817
- return writer.worker && options?.worker;
627
+ const messageType = typeof opts.message;
628
+ assert2(messageType === "string" || messageType === "object");
629
+ return Object.assign(opts, {
630
+ args
631
+ }, opts.opts);
818
632
  }
819
-
820
- // ../loader-utils/src/lib/binary-utils/array-buffer-utils.ts
821
- function compareArrayBuffers(arrayBuffer1, arrayBuffer2, byteLength) {
822
- byteLength = byteLength || arrayBuffer1.byteLength;
823
- if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) {
824
- return false;
633
+ function decorateMessage(id, message, opts) {
634
+ if (typeof message === "string") {
635
+ const time = opts.time ? leftPad(formatTime(opts.total)) : "";
636
+ message = opts.time ? "".concat(id, ": ").concat(time, " ").concat(message) : "".concat(id, ": ").concat(message);
637
+ message = addColor(message, opts.color, opts.background);
825
638
  }
826
- const array1 = new Uint8Array(arrayBuffer1);
827
- const array2 = new Uint8Array(arrayBuffer2);
828
- for (let i = 0; i < array1.length; ++i) {
829
- if (array1[i] !== array2[i]) {
830
- return false;
831
- }
832
- }
833
- return true;
639
+ return message;
834
640
  }
835
- function concatenateArrayBuffers(...sources) {
836
- return concatenateArrayBuffersFromArray(sources);
641
+ function logImageInNode(_ref2) {
642
+ let {
643
+ image,
644
+ message = "",
645
+ scale = 1
646
+ } = _ref2;
647
+ console.warn("removed");
648
+ return noop;
837
649
  }
838
- function concatenateArrayBuffersFromArray(sources) {
839
- const sourceArrays = sources.map(
840
- (source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
841
- );
842
- const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
843
- const result = new Uint8Array(byteLength);
844
- let offset = 0;
845
- for (const sourceArray of sourceArrays) {
846
- result.set(sourceArray, offset);
847
- offset += sourceArray.byteLength;
650
+ function logImageInBrowser(_ref3) {
651
+ let {
652
+ image,
653
+ message = "",
654
+ scale = 1
655
+ } = _ref3;
656
+ if (typeof image === "string") {
657
+ const img = new Image();
658
+ img.onload = () => {
659
+ const args = formatImage(img, message, scale);
660
+ console.log(...args);
661
+ };
662
+ img.src = image;
663
+ return noop;
848
664
  }
849
- return result.buffer;
850
- }
851
-
852
- // ../loader-utils/src/lib/iterators/text-iterators.ts
853
- async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
854
- const textDecoder = new TextDecoder(void 0, options);
855
- for await (const arrayBuffer of arrayBufferIterator) {
856
- yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, { stream: true });
665
+ const element = image.nodeName || "";
666
+ if (element.toLowerCase() === "img") {
667
+ console.log(...formatImage(image, message, scale));
668
+ return noop;
857
669
  }
858
- }
859
- async function* makeTextEncoderIterator(textIterator) {
860
- const textEncoder = new TextEncoder();
861
- for await (const text of textIterator) {
862
- yield typeof text === "string" ? textEncoder.encode(text) : text;
670
+ if (element.toLowerCase() === "canvas") {
671
+ const img = new Image();
672
+ img.onload = () => console.log(...formatImage(img, message, scale));
673
+ img.src = image.toDataURL();
674
+ return noop;
863
675
  }
676
+ return noop;
864
677
  }
865
- async function* makeLineIterator(textIterator) {
866
- let previous = "";
867
- for await (const textChunk of textIterator) {
868
- previous += textChunk;
869
- let eolIndex;
870
- while ((eolIndex = previous.indexOf("\n")) >= 0) {
871
- const line = previous.slice(0, eolIndex + 1);
872
- previous = previous.slice(eolIndex + 1);
873
- yield line;
678
+ function getTableHeader(table) {
679
+ for (const key in table) {
680
+ for (const title in table[key]) {
681
+ return title || "untitled";
874
682
  }
875
683
  }
876
- if (previous.length > 0) {
877
- yield previous;
878
- }
879
- }
880
- async function* makeNumberedLineIterator(lineIterator) {
881
- let counter = 1;
882
- for await (const line of lineIterator) {
883
- yield { counter, line };
884
- counter++;
885
- }
684
+ return "empty";
886
685
  }
887
686
 
888
- // ../loader-utils/src/lib/iterators/async-iteration.ts
889
- async function forEach(iterator, visitor) {
890
- while (true) {
891
- const { done, value } = await iterator.next();
892
- if (done) {
893
- iterator.return();
894
- return;
895
- }
896
- const cancel = visitor(value);
897
- if (cancel) {
898
- return;
899
- }
900
- }
901
- }
902
- async function concatenateArrayBuffersAsync(asyncIterator) {
903
- const arrayBuffers = [];
904
- for await (const chunk of asyncIterator) {
905
- arrayBuffers.push(chunk);
906
- }
907
- return concatenateArrayBuffers(...arrayBuffers);
908
- }
687
+ // ../../node_modules/@probe.gl/log/dist/index.js
688
+ var dist_default = new Log({
689
+ id: "@probe.gl/log"
690
+ });
909
691
 
910
- // ../../node_modules/@babel/runtime/helpers/esm/typeof.js
911
- function _typeof(obj) {
912
- "@babel/helpers - typeof";
913
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
914
- return typeof obj2;
915
- } : function(obj2) {
916
- return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
917
- }, _typeof(obj);
692
+ // ../loader-utils/src/lib/option-utils/merge-loader-options.ts
693
+ function mergeLoaderOptions(baseOptions, newOptions) {
694
+ return mergeOptionsRecursively(baseOptions || {}, newOptions);
918
695
  }
919
-
920
- // ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
921
- function _toPrimitive(input, hint) {
922
- if (_typeof(input) !== "object" || input === null)
923
- return input;
924
- var prim = input[Symbol.toPrimitive];
925
- if (prim !== void 0) {
926
- var res = prim.call(input, hint || "default");
927
- if (_typeof(res) !== "object")
928
- return res;
929
- throw new TypeError("@@toPrimitive must return a primitive value.");
696
+ function mergeOptionsRecursively(baseOptions, newOptions, level = 0) {
697
+ if (level > 3) {
698
+ return newOptions;
930
699
  }
931
- return (hint === "string" ? String : Number)(input);
700
+ const options = { ...baseOptions };
701
+ for (const [key, newValue] of Object.entries(newOptions)) {
702
+ if (newValue && typeof newValue === "object" && !Array.isArray(newValue)) {
703
+ options[key] = mergeOptionsRecursively(
704
+ options[key] || {},
705
+ newOptions[key],
706
+ level + 1
707
+ );
708
+ } else {
709
+ options[key] = newOptions[key];
710
+ }
711
+ }
712
+ return options;
932
713
  }
933
714
 
934
- // ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
935
- function _toPropertyKey(arg) {
936
- var key = _toPrimitive(arg, "string");
937
- return _typeof(key) === "symbol" ? key : String(key);
715
+ // ../loader-utils/src/lib/module-utils/js-module-utils.ts
716
+ function registerJSModules(modules) {
717
+ globalThis.loaders ||= {};
718
+ globalThis.loaders.modules ||= {};
719
+ Object.assign(globalThis.loaders.modules, modules);
938
720
  }
939
721
 
940
- // ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
941
- function _defineProperty(obj, key, value) {
942
- key = _toPropertyKey(key);
943
- if (key in obj) {
944
- Object.defineProperty(obj, key, {
945
- value,
946
- enumerable: true,
947
- configurable: true,
948
- writable: true
949
- });
950
- } else {
951
- obj[key] = value;
722
+ // ../worker-utils/src/lib/env-utils/version.ts
723
+ var NPM_TAG = "latest";
724
+ function getVersion() {
725
+ if (!globalThis._loadersgl_?.version) {
726
+ globalThis._loadersgl_ = globalThis._loadersgl_ || {};
727
+ if (typeof __VERSION__ === "undefined") {
728
+ console.warn(
729
+ "loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN."
730
+ );
731
+ globalThis._loadersgl_.version = NPM_TAG;
732
+ } else {
733
+ globalThis._loadersgl_.version = __VERSION__;
734
+ }
952
735
  }
953
- return obj;
736
+ return globalThis._loadersgl_.version;
954
737
  }
738
+ var VERSION2 = getVersion();
955
739
 
956
- // ../../node_modules/@probe.gl/stats/dist/utils/hi-res-timestamp.js
957
- function getHiResTimestamp() {
958
- let timestamp;
959
- if (typeof window !== "undefined" && window.performance) {
960
- timestamp = window.performance.now();
961
- } else if (typeof process !== "undefined" && process.hrtime) {
962
- const timeParts = process.hrtime();
963
- timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
964
- } else {
965
- timestamp = Date.now();
740
+ // ../worker-utils/src/lib/env-utils/assert.ts
741
+ function assert3(condition, message) {
742
+ if (!condition) {
743
+ throw new Error(message || "loaders.gl assertion failed.");
966
744
  }
967
- return timestamp;
968
745
  }
969
746
 
970
- // ../../node_modules/@probe.gl/stats/dist/lib/stat.js
971
- var Stat = class {
972
- constructor(name, type) {
973
- _defineProperty(this, "name", void 0);
974
- _defineProperty(this, "type", void 0);
975
- _defineProperty(this, "sampleSize", 1);
976
- _defineProperty(this, "time", 0);
977
- _defineProperty(this, "count", 0);
978
- _defineProperty(this, "samples", 0);
979
- _defineProperty(this, "lastTiming", 0);
980
- _defineProperty(this, "lastSampleTime", 0);
981
- _defineProperty(this, "lastSampleCount", 0);
982
- _defineProperty(this, "_count", 0);
983
- _defineProperty(this, "_time", 0);
984
- _defineProperty(this, "_samples", 0);
985
- _defineProperty(this, "_startTime", 0);
986
- _defineProperty(this, "_timerPending", false);
987
- this.name = name;
988
- this.type = type;
989
- this.reset();
747
+ // ../worker-utils/src/lib/env-utils/globals.ts
748
+ var globals2 = {
749
+ self: typeof self !== "undefined" && self,
750
+ window: typeof window !== "undefined" && window,
751
+ global: typeof global !== "undefined" && global,
752
+ document: typeof document !== "undefined" && document
753
+ };
754
+ var self_3 = globals2.self || globals2.window || globals2.global || {};
755
+ var window_3 = globals2.window || globals2.self || globals2.global || {};
756
+ var global_3 = globals2.global || globals2.self || globals2.window || {};
757
+ var document_3 = globals2.document || {};
758
+ var isBrowser4 = (
759
+ // @ts-ignore process.browser
760
+ typeof process !== "object" || String(process) !== "[object process]" || process.browser
761
+ );
762
+ var isMobile = typeof window !== "undefined" && typeof window.orientation !== "undefined";
763
+ var matches2 = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
764
+ var nodeVersion2 = matches2 && parseFloat(matches2[1]) || 0;
765
+
766
+ // ../worker-utils/src/lib/worker-farm/worker-job.ts
767
+ var WorkerJob = class {
768
+ name;
769
+ workerThread;
770
+ isRunning = true;
771
+ /** Promise that resolves when Job is done */
772
+ result;
773
+ _resolve = () => {
774
+ };
775
+ _reject = () => {
776
+ };
777
+ constructor(jobName, workerThread) {
778
+ this.name = jobName;
779
+ this.workerThread = workerThread;
780
+ this.result = new Promise((resolve2, reject) => {
781
+ this._resolve = resolve2;
782
+ this._reject = reject;
783
+ });
990
784
  }
991
- reset() {
992
- this.time = 0;
993
- this.count = 0;
994
- this.samples = 0;
995
- this.lastTiming = 0;
996
- this.lastSampleTime = 0;
997
- this.lastSampleCount = 0;
998
- this._count = 0;
999
- this._time = 0;
1000
- this._samples = 0;
1001
- this._startTime = 0;
1002
- this._timerPending = false;
1003
- return this;
1004
- }
1005
- setSampleSize(samples) {
1006
- this.sampleSize = samples;
1007
- return this;
1008
- }
1009
- incrementCount() {
1010
- this.addCount(1);
1011
- return this;
785
+ /**
786
+ * Send a message to the job's worker thread
787
+ * @param data any data structure, ideally consisting mostly of transferrable objects
788
+ */
789
+ postMessage(type, payload) {
790
+ this.workerThread.postMessage({
791
+ source: "loaders.gl",
792
+ // Lets worker ignore unrelated messages
793
+ type,
794
+ payload
795
+ });
1012
796
  }
1013
- decrementCount() {
1014
- this.subtractCount(1);
1015
- return this;
797
+ /**
798
+ * Call to resolve the `result` Promise with the supplied value
799
+ */
800
+ done(value) {
801
+ assert3(this.isRunning);
802
+ this.isRunning = false;
803
+ this._resolve(value);
1016
804
  }
1017
- addCount(value) {
1018
- this._count += value;
1019
- this._samples++;
1020
- this._checkSampling();
1021
- return this;
805
+ /**
806
+ * Call to reject the `result` Promise with the supplied error
807
+ */
808
+ error(error) {
809
+ assert3(this.isRunning);
810
+ this.isRunning = false;
811
+ this._reject(error);
1022
812
  }
1023
- subtractCount(value) {
1024
- this._count -= value;
1025
- this._samples++;
1026
- this._checkSampling();
1027
- return this;
813
+ };
814
+
815
+ // ../worker-utils/src/lib/node/worker_threads-browser.ts
816
+ var NodeWorker = class {
817
+ terminate() {
1028
818
  }
1029
- addTime(time) {
1030
- this._time += time;
1031
- this.lastTiming = time;
1032
- this._samples++;
1033
- this._checkSampling();
1034
- return this;
819
+ };
820
+
821
+ // ../worker-utils/src/lib/worker-utils/get-loadable-worker-url.ts
822
+ var workerURLCache = /* @__PURE__ */ new Map();
823
+ function getLoadableWorkerURL(props) {
824
+ assert3(props.source && !props.url || !props.source && props.url);
825
+ let workerURL = workerURLCache.get(props.source || props.url);
826
+ if (!workerURL) {
827
+ if (props.url) {
828
+ workerURL = getLoadableWorkerURLFromURL(props.url);
829
+ workerURLCache.set(props.url, workerURL);
830
+ }
831
+ if (props.source) {
832
+ workerURL = getLoadableWorkerURLFromSource(props.source);
833
+ workerURLCache.set(props.source, workerURL);
834
+ }
1035
835
  }
1036
- timeStart() {
1037
- this._startTime = getHiResTimestamp();
1038
- this._timerPending = true;
1039
- return this;
836
+ assert3(workerURL);
837
+ return workerURL;
838
+ }
839
+ function getLoadableWorkerURLFromURL(url) {
840
+ if (!url.startsWith("http")) {
841
+ return url;
1040
842
  }
1041
- timeEnd() {
1042
- if (!this._timerPending) {
1043
- return this;
843
+ const workerSource = buildScriptSource(url);
844
+ return getLoadableWorkerURLFromSource(workerSource);
845
+ }
846
+ function getLoadableWorkerURLFromSource(workerSource) {
847
+ const blob = new Blob([workerSource], { type: "application/javascript" });
848
+ return URL.createObjectURL(blob);
849
+ }
850
+ function buildScriptSource(workerUrl) {
851
+ return `try {
852
+ importScripts('${workerUrl}');
853
+ } catch (error) {
854
+ console.error(error);
855
+ throw error;
856
+ }`;
857
+ }
858
+
859
+ // ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
860
+ function getTransferList(object, recursive = true, transfers) {
861
+ const transfersSet = transfers || /* @__PURE__ */ new Set();
862
+ if (!object) {
863
+ } else if (isTransferable(object)) {
864
+ transfersSet.add(object);
865
+ } else if (isTransferable(object.buffer)) {
866
+ transfersSet.add(object.buffer);
867
+ } else if (ArrayBuffer.isView(object)) {
868
+ } else if (recursive && typeof object === "object") {
869
+ for (const key in object) {
870
+ getTransferList(object[key], recursive, transfersSet);
1044
871
  }
1045
- this.addTime(getHiResTimestamp() - this._startTime);
1046
- this._timerPending = false;
1047
- this._checkSampling();
1048
- return this;
1049
872
  }
1050
- getSampleAverageCount() {
1051
- return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
873
+ return transfers === void 0 ? Array.from(transfersSet) : [];
874
+ }
875
+ function isTransferable(object) {
876
+ if (!object) {
877
+ return false;
1052
878
  }
1053
- getSampleAverageTime() {
1054
- return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
879
+ if (object instanceof ArrayBuffer) {
880
+ return true;
1055
881
  }
1056
- getSampleHz() {
1057
- return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1e3) : 0;
882
+ if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
883
+ return true;
1058
884
  }
1059
- getAverageCount() {
1060
- return this.samples > 0 ? this.count / this.samples : 0;
885
+ if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
886
+ return true;
1061
887
  }
1062
- getAverageTime() {
1063
- return this.samples > 0 ? this.time / this.samples : 0;
888
+ if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
889
+ return true;
1064
890
  }
1065
- getHz() {
1066
- return this.time > 0 ? this.samples / (this.time / 1e3) : 0;
891
+ return false;
892
+ }
893
+ function getTransferListForWriter(object) {
894
+ if (object === null) {
895
+ return {};
1067
896
  }
1068
- _checkSampling() {
1069
- if (this._samples === this.sampleSize) {
1070
- this.lastSampleTime = this._time;
1071
- this.lastSampleCount = this._count;
1072
- this.count += this._count;
1073
- this.time += this._time;
1074
- this.samples += this._samples;
1075
- this._time = 0;
1076
- this._count = 0;
1077
- this._samples = 0;
897
+ const clone = Object.assign({}, object);
898
+ Object.keys(clone).forEach((key) => {
899
+ if (typeof object[key] === "object" && !ArrayBuffer.isView(object[key]) && !(object[key] instanceof Array)) {
900
+ clone[key] = getTransferListForWriter(object[key]);
901
+ } else if (typeof clone[key] === "function" || clone[key] instanceof RegExp) {
902
+ clone[key] = {};
903
+ } else {
904
+ clone[key] = object[key];
1078
905
  }
1079
- }
1080
- };
906
+ });
907
+ return clone;
908
+ }
1081
909
 
1082
- // ../../node_modules/@probe.gl/stats/dist/lib/stats.js
1083
- var Stats = class {
1084
- constructor(options) {
1085
- _defineProperty(this, "id", void 0);
1086
- _defineProperty(this, "stats", {});
1087
- this.id = options.id;
1088
- this.stats = {};
1089
- this._initializeStats(options.stats);
1090
- Object.seal(this);
910
+ // ../worker-utils/src/lib/worker-farm/worker-thread.ts
911
+ var NOOP = () => {
912
+ };
913
+ var WorkerThread = class {
914
+ name;
915
+ source;
916
+ url;
917
+ terminated = false;
918
+ worker;
919
+ onMessage;
920
+ onError;
921
+ _loadableURL = "";
922
+ /** Checks if workers are supported on this platform */
923
+ static isSupported() {
924
+ return typeof Worker !== "undefined" && isBrowser4 || typeof NodeWorker !== "undefined" && !isBrowser4;
1091
925
  }
1092
- get(name) {
1093
- let type = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "count";
1094
- return this._getOrCreate({
1095
- name,
1096
- type
1097
- });
926
+ constructor(props) {
927
+ const { name, source, url } = props;
928
+ assert3(source || url);
929
+ this.name = name;
930
+ this.source = source;
931
+ this.url = url;
932
+ this.onMessage = NOOP;
933
+ this.onError = (error) => console.log(error);
934
+ this.worker = isBrowser4 ? this._createBrowserWorker() : this._createNodeWorker();
1098
935
  }
1099
- get size() {
1100
- return Object.keys(this.stats).length;
936
+ /**
937
+ * Terminate this worker thread
938
+ * @note Can free up significant memory
939
+ */
940
+ destroy() {
941
+ this.onMessage = NOOP;
942
+ this.onError = NOOP;
943
+ this.worker.terminate();
944
+ this.terminated = true;
1101
945
  }
1102
- reset() {
1103
- for (const stat of Object.values(this.stats)) {
1104
- stat.reset();
1105
- }
1106
- return this;
946
+ get isRunning() {
947
+ return Boolean(this.onMessage);
1107
948
  }
1108
- forEach(fn) {
1109
- for (const stat of Object.values(this.stats)) {
1110
- fn(stat);
949
+ /**
950
+ * Send a message to this worker thread
951
+ * @param data any data structure, ideally consisting mostly of transferrable objects
952
+ * @param transferList If not supplied, calculated automatically by traversing data
953
+ */
954
+ postMessage(data, transferList) {
955
+ transferList = transferList || getTransferList(data);
956
+ this.worker.postMessage(data, transferList);
957
+ }
958
+ // PRIVATE
959
+ /**
960
+ * Generate a standard Error from an ErrorEvent
961
+ * @param event
962
+ */
963
+ _getErrorFromErrorEvent(event) {
964
+ let message = "Failed to load ";
965
+ message += `worker ${this.name} from ${this.url}. `;
966
+ if (event.message) {
967
+ message += `${event.message} in `;
968
+ }
969
+ if (event.lineno) {
970
+ message += `:${event.lineno}:${event.colno}`;
1111
971
  }
972
+ return new Error(message);
1112
973
  }
1113
- getTable() {
1114
- const table = {};
1115
- this.forEach((stat) => {
1116
- table[stat.name] = {
1117
- time: stat.time || 0,
1118
- count: stat.count || 0,
1119
- average: stat.getAverageTime() || 0,
1120
- hz: stat.getHz() || 0
1121
- };
1122
- });
1123
- return table;
1124
- }
1125
- _initializeStats() {
1126
- let stats = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
1127
- stats.forEach((stat) => this._getOrCreate(stat));
1128
- }
1129
- _getOrCreate(stat) {
1130
- const {
1131
- name,
1132
- type
1133
- } = stat;
1134
- let result = this.stats[name];
1135
- if (!result) {
1136
- if (stat instanceof Stat) {
1137
- result = stat;
974
+ /**
975
+ * Creates a worker thread on the browser
976
+ */
977
+ _createBrowserWorker() {
978
+ this._loadableURL = getLoadableWorkerURL({ source: this.source, url: this.url });
979
+ const worker = new Worker(this._loadableURL, { name: this.name });
980
+ worker.onmessage = (event) => {
981
+ if (!event.data) {
982
+ this.onError(new Error("No data received"));
1138
983
  } else {
1139
- result = new Stat(name, type);
984
+ this.onMessage(event.data);
1140
985
  }
1141
- this.stats[name] = result;
986
+ };
987
+ worker.onerror = (error) => {
988
+ this.onError(this._getErrorFromErrorEvent(error));
989
+ this.terminated = true;
990
+ };
991
+ worker.onmessageerror = (event) => console.error(event);
992
+ return worker;
993
+ }
994
+ /**
995
+ * Creates a worker thread in node.js
996
+ * @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool
997
+ */
998
+ _createNodeWorker() {
999
+ let worker;
1000
+ if (this.url) {
1001
+ const absolute = this.url.includes(":/") || this.url.startsWith("/");
1002
+ const url = absolute ? this.url : `./${this.url}`;
1003
+ worker = new NodeWorker(url, { eval: false });
1004
+ } else if (this.source) {
1005
+ worker = new NodeWorker(this.source, { eval: true });
1006
+ } else {
1007
+ throw new Error("no worker");
1142
1008
  }
1143
- return result;
1009
+ worker.on("message", (data) => {
1010
+ this.onMessage(data);
1011
+ });
1012
+ worker.on("error", (error) => {
1013
+ this.onError(error);
1014
+ });
1015
+ worker.on("exit", (code) => {
1016
+ });
1017
+ return worker;
1144
1018
  }
1145
1019
  };
1146
1020
 
1147
- // ../loader-utils/src/lib/request-utils/request-scheduler.ts
1148
- var STAT_QUEUED_REQUESTS = "Queued Requests";
1149
- var STAT_ACTIVE_REQUESTS = "Active Requests";
1150
- var STAT_CANCELLED_REQUESTS = "Cancelled Requests";
1151
- var STAT_QUEUED_REQUESTS_EVER = "Queued Requests Ever";
1152
- var STAT_ACTIVE_REQUESTS_EVER = "Active Requests Ever";
1153
- var DEFAULT_PROPS2 = {
1154
- id: "request-scheduler",
1155
- /** Specifies if the request scheduler should throttle incoming requests, mainly for comparative testing. */
1156
- throttleRequests: true,
1157
- /** The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit. */
1158
- maxRequests: 6,
1021
+ // ../worker-utils/src/lib/worker-farm/worker-pool.ts
1022
+ var WorkerPool = class {
1023
+ name = "unnamed";
1024
+ source;
1025
+ // | Function;
1026
+ url;
1027
+ maxConcurrency = 1;
1028
+ maxMobileConcurrency = 1;
1029
+ onDebug = () => {
1030
+ };
1031
+ reuseWorkers = true;
1032
+ props = {};
1033
+ jobQueue = [];
1034
+ idleQueue = [];
1035
+ count = 0;
1036
+ isDestroyed = false;
1037
+ /** Checks if workers are supported on this platform */
1038
+ static isSupported() {
1039
+ return WorkerThread.isSupported();
1040
+ }
1159
1041
  /**
1160
- * Specifies a debounce time, in milliseconds. All requests are queued, until no new requests have
1161
- * been added to the queue for this amount of time.
1042
+ * @param processor - worker function
1043
+ * @param maxConcurrency - max count of workers
1162
1044
  */
1163
- debounceTime: 0
1164
- };
1165
- var RequestScheduler = class {
1166
- props;
1167
- stats;
1168
- activeRequestCount = 0;
1169
- /** Tracks the number of active requests and prioritizes/cancels queued requests. */
1170
- requestQueue = [];
1171
- requestMap = /* @__PURE__ */ new Map();
1172
- updateTimer = null;
1173
- constructor(props = {}) {
1174
- this.props = { ...DEFAULT_PROPS2, ...props };
1175
- this.stats = new Stats({ id: this.props.id });
1176
- this.stats.get(STAT_QUEUED_REQUESTS);
1177
- this.stats.get(STAT_ACTIVE_REQUESTS);
1178
- this.stats.get(STAT_CANCELLED_REQUESTS);
1179
- this.stats.get(STAT_QUEUED_REQUESTS_EVER);
1180
- this.stats.get(STAT_ACTIVE_REQUESTS_EVER);
1045
+ constructor(props) {
1046
+ this.source = props.source;
1047
+ this.url = props.url;
1048
+ this.setProps(props);
1181
1049
  }
1182
1050
  /**
1183
- * Called by an application that wants to issue a request, without having it deeply queued by the browser
1184
- *
1185
- * When the returned promise resolved, it is OK for the application to issue a request.
1186
- * The promise resolves to an object that contains a `done` method.
1187
- * When the application's request has completed (or failed), the application must call the `done` function
1188
- *
1189
- * @param handle
1190
- * @param getPriority will be called when request "slots" open up,
1191
- * allowing the caller to update priority or cancel the request
1192
- * Highest priority executes first, priority < 0 cancels the request
1193
- * @returns a promise
1194
- * - resolves to a object (with a `done` field) when the request can be issued without queueing,
1195
- * - resolves to `null` if the request has been cancelled (by the callback return < 0).
1196
- * In this case the application should not issue the request
1051
+ * Terminates all workers in the pool
1052
+ * @note Can free up significant memory
1197
1053
  */
1198
- scheduleRequest(handle, getPriority = () => 0) {
1199
- if (!this.props.throttleRequests) {
1200
- return Promise.resolve({ done: () => {
1201
- } });
1054
+ destroy() {
1055
+ this.idleQueue.forEach((worker) => worker.destroy());
1056
+ this.isDestroyed = true;
1057
+ }
1058
+ setProps(props) {
1059
+ this.props = { ...this.props, ...props };
1060
+ if (props.name !== void 0) {
1061
+ this.name = props.name;
1202
1062
  }
1203
- if (this.requestMap.has(handle)) {
1204
- return this.requestMap.get(handle);
1063
+ if (props.maxConcurrency !== void 0) {
1064
+ this.maxConcurrency = props.maxConcurrency;
1205
1065
  }
1206
- const request = { handle, priority: 0, getPriority };
1207
- const promise = new Promise((resolve2) => {
1208
- request.resolve = resolve2;
1209
- return request;
1066
+ if (props.maxMobileConcurrency !== void 0) {
1067
+ this.maxMobileConcurrency = props.maxMobileConcurrency;
1068
+ }
1069
+ if (props.reuseWorkers !== void 0) {
1070
+ this.reuseWorkers = props.reuseWorkers;
1071
+ }
1072
+ if (props.onDebug !== void 0) {
1073
+ this.onDebug = props.onDebug;
1074
+ }
1075
+ }
1076
+ async startJob(name, onMessage3 = (job, type, data) => job.done(data), onError = (job, error) => job.error(error)) {
1077
+ const startPromise = new Promise((onStart) => {
1078
+ this.jobQueue.push({ name, onMessage: onMessage3, onError, onStart });
1079
+ return this;
1210
1080
  });
1211
- this.requestQueue.push(request);
1212
- this.requestMap.set(handle, promise);
1213
- this._issueNewRequests();
1214
- return promise;
1081
+ this._startQueuedJob();
1082
+ return await startPromise;
1215
1083
  }
1216
1084
  // PRIVATE
1217
- _issueRequest(request) {
1218
- const { handle, resolve: resolve2 } = request;
1219
- let isDone = false;
1220
- const done = () => {
1221
- if (!isDone) {
1222
- isDone = true;
1223
- this.requestMap.delete(handle);
1224
- this.activeRequestCount--;
1225
- this._issueNewRequests();
1226
- }
1227
- };
1228
- this.activeRequestCount++;
1229
- return resolve2 ? resolve2({ done }) : Promise.resolve({ done });
1230
- }
1231
- /** We check requests asynchronously, to prevent multiple updates */
1232
- _issueNewRequests() {
1233
- if (this.updateTimer !== null) {
1234
- clearTimeout(this.updateTimer);
1235
- }
1236
- this.updateTimer = setTimeout(() => this._issueNewRequestsAsync(), this.props.debounceTime);
1237
- }
1238
- /** Refresh all requests */
1239
- _issueNewRequestsAsync() {
1240
- if (this.updateTimer !== null) {
1241
- clearTimeout(this.updateTimer);
1242
- }
1243
- this.updateTimer = null;
1244
- const freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);
1245
- if (freeSlots === 0) {
1085
+ /**
1086
+ * Starts first queued job if worker is available or can be created
1087
+ * Called when job is started and whenever a worker returns to the idleQueue
1088
+ */
1089
+ async _startQueuedJob() {
1090
+ if (!this.jobQueue.length) {
1246
1091
  return;
1247
1092
  }
1248
- this._updateAllRequests();
1249
- for (let i = 0; i < freeSlots; ++i) {
1250
- const request = this.requestQueue.shift();
1251
- if (request) {
1252
- this._issueRequest(request);
1253
- }
1093
+ const workerThread = this._getAvailableWorker();
1094
+ if (!workerThread) {
1095
+ return;
1254
1096
  }
1255
- }
1256
- /** Ensure all requests have updated priorities, and that no longer valid requests are cancelled */
1257
- _updateAllRequests() {
1258
- const requestQueue = this.requestQueue;
1259
- for (let i = 0; i < requestQueue.length; ++i) {
1260
- const request = requestQueue[i];
1261
- if (!this._updateRequest(request)) {
1262
- requestQueue.splice(i, 1);
1263
- this.requestMap.delete(request.handle);
1264
- i--;
1097
+ const queuedJob = this.jobQueue.shift();
1098
+ if (queuedJob) {
1099
+ this.onDebug({
1100
+ message: "Starting job",
1101
+ name: queuedJob.name,
1102
+ workerThread,
1103
+ backlog: this.jobQueue.length
1104
+ });
1105
+ const job = new WorkerJob(queuedJob.name, workerThread);
1106
+ workerThread.onMessage = (data) => queuedJob.onMessage(job, data.type, data.payload);
1107
+ workerThread.onError = (error) => queuedJob.onError(job, error);
1108
+ queuedJob.onStart(job);
1109
+ try {
1110
+ await job.result;
1111
+ } catch (error) {
1112
+ console.error(`Worker exception: ${error}`);
1113
+ } finally {
1114
+ this.returnWorkerToQueue(workerThread);
1265
1115
  }
1266
1116
  }
1267
- requestQueue.sort((a, b) => a.priority - b.priority);
1268
1117
  }
1269
- /** Update a single request by calling the callback */
1270
- _updateRequest(request) {
1271
- request.priority = request.getPriority(request.handle);
1272
- if (request.priority < 0) {
1273
- request.resolve(null);
1274
- return false;
1118
+ /**
1119
+ * Returns a worker to the idle queue
1120
+ * Destroys the worker if
1121
+ * - pool is destroyed
1122
+ * - if this pool doesn't reuse workers
1123
+ * - if maxConcurrency has been lowered
1124
+ * @param worker
1125
+ */
1126
+ returnWorkerToQueue(worker) {
1127
+ const shouldDestroyWorker = (
1128
+ // Workers on Node.js prevent the process from exiting.
1129
+ // Until we figure out how to close them before exit, we always destroy them
1130
+ !isBrowser4 || // If the pool is destroyed, there is no reason to keep the worker around
1131
+ this.isDestroyed || // If the app has disabled worker reuse, any completed workers should be destroyed
1132
+ !this.reuseWorkers || // If concurrency has been lowered, this worker might be surplus to requirements
1133
+ this.count > this._getMaxConcurrency()
1134
+ );
1135
+ if (shouldDestroyWorker) {
1136
+ worker.destroy();
1137
+ this.count--;
1138
+ } else {
1139
+ this.idleQueue.push(worker);
1140
+ }
1141
+ if (!this.isDestroyed) {
1142
+ this._startQueuedJob();
1275
1143
  }
1276
- return true;
1277
1144
  }
1278
- };
1279
-
1280
- // ../loader-utils/src/lib/path-utils/file-aliases.ts
1281
- var pathPrefix = "";
1282
- var fileAliases = {};
1283
- function setPathPrefix(prefix) {
1284
- pathPrefix = prefix;
1285
- }
1286
- function getPathPrefix() {
1287
- return pathPrefix;
1288
- }
1289
- function resolvePath(filename2) {
1290
- for (const alias in fileAliases) {
1291
- if (filename2.startsWith(alias)) {
1292
- const replacement = fileAliases[alias];
1293
- filename2 = filename2.replace(alias, replacement);
1145
+ /**
1146
+ * Returns idle worker or creates new worker if maxConcurrency has not been reached
1147
+ */
1148
+ _getAvailableWorker() {
1149
+ if (this.idleQueue.length > 0) {
1150
+ return this.idleQueue.shift() || null;
1151
+ }
1152
+ if (this.count < this._getMaxConcurrency()) {
1153
+ this.count++;
1154
+ const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;
1155
+ return new WorkerThread({ name, source: this.source, url: this.url });
1294
1156
  }
1157
+ return null;
1295
1158
  }
1296
- if (!filename2.startsWith("http://") && !filename2.startsWith("https://")) {
1297
- filename2 = `${pathPrefix}${filename2}`;
1159
+ _getMaxConcurrency() {
1160
+ return isMobile ? this.maxMobileConcurrency : this.maxConcurrency;
1298
1161
  }
1299
- return filename2;
1300
- }
1301
-
1302
- // ../loader-utils/src/json-loader.ts
1303
- var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1304
- var JSONLoader = {
1305
- name: "JSON",
1306
- id: "json",
1307
- module: "json",
1308
- version: VERSION2,
1309
- extensions: ["json", "geojson"],
1310
- mimeTypes: ["application/json"],
1311
- category: "json",
1312
- text: true,
1313
- parseTextSync,
1314
- parse: async (arrayBuffer) => parseTextSync(new TextDecoder().decode(arrayBuffer)),
1315
- options: {}
1316
1162
  };
1317
- function parseTextSync(text) {
1318
- return JSON.parse(text);
1319
- }
1320
-
1321
- // ../loader-utils/src/lib/node/buffer.browser.ts
1322
- function toArrayBuffer(buffer) {
1323
- return buffer;
1324
- }
1325
1163
 
1326
- // ../loader-utils/src/lib/binary-utils/memory-conversion-utils.ts
1327
- function isBuffer(value) {
1328
- return value && typeof value === "object" && value.isBuffer;
1329
- }
1330
- function toArrayBuffer2(data) {
1331
- if (isBuffer(data)) {
1332
- return toArrayBuffer(data);
1164
+ // ../worker-utils/src/lib/worker-farm/worker-farm.ts
1165
+ var DEFAULT_PROPS = {
1166
+ maxConcurrency: 3,
1167
+ maxMobileConcurrency: 1,
1168
+ reuseWorkers: true,
1169
+ onDebug: () => {
1333
1170
  }
1334
- if (data instanceof ArrayBuffer) {
1335
- return data;
1171
+ };
1172
+ var _WorkerFarm = class {
1173
+ props;
1174
+ workerPools = /* @__PURE__ */ new Map();
1175
+ /** Checks if workers are supported on this platform */
1176
+ static isSupported() {
1177
+ return WorkerThread.isSupported();
1336
1178
  }
1337
- if (ArrayBuffer.isView(data)) {
1338
- if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
1339
- return data.buffer;
1179
+ /** Get the singleton instance of the global worker farm */
1180
+ static getWorkerFarm(props = {}) {
1181
+ _WorkerFarm._workerFarm = _WorkerFarm._workerFarm || new _WorkerFarm({});
1182
+ _WorkerFarm._workerFarm.setProps(props);
1183
+ return _WorkerFarm._workerFarm;
1184
+ }
1185
+ /** get global instance with WorkerFarm.getWorkerFarm() */
1186
+ constructor(props) {
1187
+ this.props = { ...DEFAULT_PROPS };
1188
+ this.setProps(props);
1189
+ this.workerPools = /* @__PURE__ */ new Map();
1190
+ }
1191
+ /**
1192
+ * Terminate all workers in the farm
1193
+ * @note Can free up significant memory
1194
+ */
1195
+ destroy() {
1196
+ for (const workerPool of this.workerPools.values()) {
1197
+ workerPool.destroy();
1340
1198
  }
1341
- return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
1199
+ this.workerPools = /* @__PURE__ */ new Map();
1342
1200
  }
1343
- if (typeof data === "string") {
1344
- const text = data;
1345
- const uint8Array = new TextEncoder().encode(text);
1346
- return uint8Array.buffer;
1201
+ /**
1202
+ * Set props used when initializing worker pools
1203
+ * @param props
1204
+ */
1205
+ setProps(props) {
1206
+ this.props = { ...this.props, ...props };
1207
+ for (const workerPool of this.workerPools.values()) {
1208
+ workerPool.setProps(this._getWorkerPoolProps());
1209
+ }
1347
1210
  }
1348
- if (data && typeof data === "object" && data._toArrayBuffer) {
1349
- return data._toArrayBuffer();
1211
+ /**
1212
+ * Returns a worker pool for the specified worker
1213
+ * @param options - only used first time for a specific worker name
1214
+ * @param options.name - the name of the worker - used to identify worker pool
1215
+ * @param options.url -
1216
+ * @param options.source -
1217
+ * @example
1218
+ * const job = WorkerFarm.getWorkerFarm().getWorkerPool({name, url}).startJob(...);
1219
+ */
1220
+ getWorkerPool(options) {
1221
+ const { name, source, url } = options;
1222
+ let workerPool = this.workerPools.get(name);
1223
+ if (!workerPool) {
1224
+ workerPool = new WorkerPool({
1225
+ name,
1226
+ source,
1227
+ url
1228
+ });
1229
+ workerPool.setProps(this._getWorkerPoolProps());
1230
+ this.workerPools.set(name, workerPool);
1231
+ }
1232
+ return workerPool;
1350
1233
  }
1351
- throw new Error("toArrayBuffer");
1352
- }
1353
-
1354
- // ../loader-utils/src/lib/path-utils/path.ts
1355
- var path_exports = {};
1356
- __export(path_exports, {
1357
- dirname: () => dirname,
1358
- filename: () => filename,
1359
- join: () => join,
1360
- resolve: () => resolve
1361
- });
1362
-
1363
- // ../loader-utils/src/lib/path-utils/get-cwd.ts
1364
- function getCWD() {
1365
- if (typeof process !== "undefined" && typeof process.cwd !== "undefined") {
1366
- return process.cwd();
1234
+ _getWorkerPoolProps() {
1235
+ return {
1236
+ maxConcurrency: this.props.maxConcurrency,
1237
+ maxMobileConcurrency: this.props.maxMobileConcurrency,
1238
+ reuseWorkers: this.props.reuseWorkers,
1239
+ onDebug: this.props.onDebug
1240
+ };
1367
1241
  }
1368
- const pathname = window.location?.pathname;
1369
- return pathname?.slice(0, pathname.lastIndexOf("/") + 1) || "";
1370
- }
1242
+ };
1243
+ var WorkerFarm = _WorkerFarm;
1244
+ // singleton
1245
+ __publicField(WorkerFarm, "_workerFarm");
1371
1246
 
1372
- // ../loader-utils/src/lib/path-utils/path.ts
1373
- function filename(url) {
1374
- const slashIndex = url ? url.lastIndexOf("/") : -1;
1375
- return slashIndex >= 0 ? url.substr(slashIndex + 1) : "";
1376
- }
1377
- function dirname(url) {
1378
- const slashIndex = url ? url.lastIndexOf("/") : -1;
1379
- return slashIndex >= 0 ? url.substr(0, slashIndex) : "";
1380
- }
1381
- function join(...parts) {
1382
- const separator = "/";
1383
- parts = parts.map((part, index) => {
1384
- if (index) {
1385
- part = part.replace(new RegExp(`^${separator}`), "");
1386
- }
1387
- if (index !== parts.length - 1) {
1388
- part = part.replace(new RegExp(`${separator}$`), "");
1389
- }
1390
- return part;
1391
- });
1392
- return parts.join(separator);
1247
+ // ../worker-utils/src/lib/worker-api/get-worker-url.ts
1248
+ function getWorkerName(worker) {
1249
+ const warning = worker.version !== VERSION2 ? ` (worker-utils@${VERSION2})` : "";
1250
+ return `${worker.name}@${worker.version}${warning}`;
1393
1251
  }
1394
- function resolve(...components) {
1395
- const paths = [];
1396
- for (let _i = 0; _i < components.length; _i++) {
1397
- paths[_i] = components[_i];
1252
+ function getWorkerURL(worker, options = {}) {
1253
+ const workerOptions = options[worker.id] || {};
1254
+ const workerFile = isBrowser4 ? `${worker.id}-worker.js` : `${worker.id}-worker-node.js`;
1255
+ let url = workerOptions.workerUrl;
1256
+ if (!url && worker.id === "compression") {
1257
+ url = options.workerUrl;
1398
1258
  }
1399
- let resolvedPath = "";
1400
- let resolvedAbsolute = false;
1401
- let cwd;
1402
- for (let i = paths.length - 1; i >= -1 && !resolvedAbsolute; i--) {
1403
- let path;
1404
- if (i >= 0) {
1405
- path = paths[i];
1259
+ if (options._workerType === "test") {
1260
+ if (isBrowser4) {
1261
+ url = `modules/${worker.module}/dist/${workerFile}`;
1406
1262
  } else {
1407
- if (cwd === void 0) {
1408
- cwd = getCWD();
1409
- }
1410
- path = cwd;
1263
+ url = `modules/${worker.module}/src/workers/${worker.id}-worker-node.ts`;
1411
1264
  }
1412
- if (path.length === 0) {
1413
- continue;
1265
+ }
1266
+ if (!url) {
1267
+ let version = worker.version;
1268
+ if (version === "latest") {
1269
+ version = NPM_TAG;
1414
1270
  }
1415
- resolvedPath = `${path}/${resolvedPath}`;
1416
- resolvedAbsolute = path.charCodeAt(0) === SLASH;
1271
+ const versionTag = version ? `@${version}` : "";
1272
+ url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;
1417
1273
  }
1418
- resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
1419
- if (resolvedAbsolute) {
1420
- return `/${resolvedPath}`;
1421
- } else if (resolvedPath.length > 0) {
1422
- return resolvedPath;
1274
+ assert3(url);
1275
+ return url;
1276
+ }
1277
+
1278
+ // ../worker-utils/src/lib/worker-api/process-on-worker.ts
1279
+ async function processOnWorker(worker, data, options = {}, context = {}) {
1280
+ const name = getWorkerName(worker);
1281
+ const workerFarm = WorkerFarm.getWorkerFarm(options);
1282
+ const { source } = options;
1283
+ const workerPoolProps = { name, source };
1284
+ if (!source) {
1285
+ workerPoolProps.url = getWorkerURL(worker, options);
1423
1286
  }
1424
- return ".";
1287
+ const workerPool = workerFarm.getWorkerPool(workerPoolProps);
1288
+ const jobName = options.jobName || worker.name;
1289
+ const job = await workerPool.startJob(
1290
+ jobName,
1291
+ // eslint-disable-next-line
1292
+ onMessage.bind(null, context)
1293
+ );
1294
+ const transferableOptions = getTransferListForWriter(options);
1295
+ job.postMessage("process", { input: data, options: transferableOptions });
1296
+ const result = await job.result;
1297
+ return result.result;
1425
1298
  }
1426
- var SLASH = 47;
1427
- var DOT = 46;
1428
- function normalizeStringPosix(path, allowAboveRoot) {
1429
- let res = "";
1430
- let lastSlash = -1;
1431
- let dots = 0;
1432
- let code;
1433
- let isAboveRoot = false;
1434
- for (let i = 0; i <= path.length; ++i) {
1435
- if (i < path.length) {
1436
- code = path.charCodeAt(i);
1437
- } else if (code === SLASH) {
1299
+ async function onMessage(context, job, type, payload) {
1300
+ switch (type) {
1301
+ case "done":
1302
+ job.done(payload);
1438
1303
  break;
1439
- } else {
1440
- code = SLASH;
1441
- }
1442
- if (code === SLASH) {
1443
- if (lastSlash === i - 1 || dots === 1) {
1444
- } else if (lastSlash !== i - 1 && dots === 2) {
1445
- if (res.length < 2 || !isAboveRoot || res.charCodeAt(res.length - 1) !== DOT || res.charCodeAt(res.length - 2) !== DOT) {
1446
- if (res.length > 2) {
1447
- const start = res.length - 1;
1448
- let j = start;
1449
- for (; j >= 0; --j) {
1450
- if (res.charCodeAt(j) === SLASH) {
1451
- break;
1452
- }
1453
- }
1454
- if (j !== start) {
1455
- res = j === -1 ? "" : res.slice(0, j);
1456
- lastSlash = i;
1457
- dots = 0;
1458
- isAboveRoot = false;
1459
- continue;
1460
- }
1461
- } else if (res.length === 2 || res.length === 1) {
1462
- res = "";
1463
- lastSlash = i;
1464
- dots = 0;
1465
- isAboveRoot = false;
1466
- continue;
1467
- }
1468
- }
1469
- if (allowAboveRoot) {
1470
- if (res.length > 0) {
1471
- res += "/..";
1472
- } else {
1473
- res = "..";
1474
- }
1475
- isAboveRoot = true;
1476
- }
1477
- } else {
1478
- const slice = path.slice(lastSlash + 1, i);
1479
- if (res.length > 0) {
1480
- res += `/${slice}`;
1481
- } else {
1482
- res = slice;
1304
+ case "error":
1305
+ job.error(new Error(payload.error));
1306
+ break;
1307
+ case "process":
1308
+ const { id, input, options } = payload;
1309
+ try {
1310
+ if (!context.process) {
1311
+ job.postMessage("error", { id, error: "Worker not set up to process on main thread" });
1312
+ return;
1483
1313
  }
1484
- isAboveRoot = false;
1314
+ const result = await context.process(input, options);
1315
+ job.postMessage("done", { id, result });
1316
+ } catch (error) {
1317
+ const message = error instanceof Error ? error.message : "unknown error";
1318
+ job.postMessage("error", { id, error: message });
1485
1319
  }
1486
- lastSlash = i;
1487
- dots = 0;
1488
- } else if (code === DOT && dots !== -1) {
1489
- ++dots;
1490
- } else {
1491
- dots = -1;
1492
- }
1320
+ break;
1321
+ default:
1322
+ console.warn(`process-on-worker: unknown message ${type}`);
1493
1323
  }
1494
- return res;
1495
1324
  }
1496
1325
 
1497
- // ../loader-utils/src/lib/files/blob-file.ts
1498
- var BlobFile = class {
1499
- handle;
1500
- size;
1501
- bigsize;
1502
- url;
1503
- constructor(blob) {
1504
- this.handle = blob instanceof ArrayBuffer ? new Blob([blob]) : blob;
1505
- this.size = blob instanceof ArrayBuffer ? blob.byteLength : blob.size;
1506
- this.bigsize = BigInt(this.size);
1507
- this.url = blob instanceof File ? blob.name : "";
1326
+ // ../worker-utils/src/lib/worker-api/validate-worker-version.ts
1327
+ function validateWorkerVersion(worker, coreVersion = VERSION2) {
1328
+ assert3(worker, "no worker provided");
1329
+ const workerVersion = worker.version;
1330
+ if (!coreVersion || !workerVersion) {
1331
+ return false;
1508
1332
  }
1509
- async close() {
1333
+ return true;
1334
+ }
1335
+
1336
+ // ../loader-utils/src/lib/worker-loader-utils/parse-with-worker.ts
1337
+ function canParseWithWorker(loader, options) {
1338
+ if (!WorkerFarm.isSupported()) {
1339
+ return false;
1510
1340
  }
1511
- async stat() {
1512
- return {
1513
- size: this.handle.size,
1514
- bigsize: BigInt(this.handle.size),
1515
- isDirectory: false
1516
- };
1341
+ if (!isBrowser4 && !options?._nodeWorkers) {
1342
+ return false;
1517
1343
  }
1518
- async read(start, length) {
1519
- const arrayBuffer = await this.handle.slice(start, start + length).arrayBuffer();
1520
- return arrayBuffer;
1344
+ return loader.worker && options?.worker;
1345
+ }
1346
+ async function parseWithWorker(loader, data, options, context, parseOnMainThread) {
1347
+ const name = loader.id;
1348
+ const url = getWorkerURL(loader, options);
1349
+ const workerFarm = WorkerFarm.getWorkerFarm(options);
1350
+ const workerPool = workerFarm.getWorkerPool({ name, url });
1351
+ options = JSON.parse(JSON.stringify(options));
1352
+ context = JSON.parse(JSON.stringify(context || {}));
1353
+ const job = await workerPool.startJob(
1354
+ "process-on-worker",
1355
+ // @ts-expect-error
1356
+ onMessage2.bind(null, parseOnMainThread)
1357
+ // eslint-disable-line @typescript-eslint/no-misused-promises
1358
+ );
1359
+ job.postMessage("process", {
1360
+ // @ts-ignore
1361
+ input: data,
1362
+ options,
1363
+ context
1364
+ });
1365
+ const result = await job.result;
1366
+ return await result.result;
1367
+ }
1368
+ async function onMessage2(parseOnMainThread, job, type, payload) {
1369
+ switch (type) {
1370
+ case "done":
1371
+ job.done(payload);
1372
+ break;
1373
+ case "error":
1374
+ job.error(new Error(payload.error));
1375
+ break;
1376
+ case "process":
1377
+ const { id, input, options } = payload;
1378
+ try {
1379
+ const result = await parseOnMainThread(input, options);
1380
+ job.postMessage("done", { id, result });
1381
+ } catch (error) {
1382
+ const message = error instanceof Error ? error.message : "unknown error";
1383
+ job.postMessage("error", { id, error: message });
1384
+ }
1385
+ break;
1386
+ default:
1387
+ console.warn(`parse-with-worker unknown message ${type}`);
1521
1388
  }
1522
- };
1389
+ }
1523
1390
 
1524
- // ../loader-utils/src/lib/files/node-file-facade.ts
1525
- var NOT_IMPLEMENTED = new Error("Not implemented");
1526
- var NodeFileFacade = class {
1527
- handle;
1528
- size = 0;
1529
- bigsize = 0n;
1530
- url = "";
1531
- constructor(url, flags, mode) {
1532
- if (globalThis.loaders?.NodeFile) {
1533
- return new globalThis.loaders.NodeFile(url, flags, mode);
1534
- }
1535
- if (isBrowser) {
1536
- throw new Error("Can't instantiate NodeFile in browser.");
1537
- }
1538
- throw new Error("Can't instantiate NodeFile. Make sure to import @loaders.gl/polyfills first.");
1391
+ // ../loader-utils/src/lib/worker-loader-utils/encode-with-worker.ts
1392
+ function canEncodeWithWorker(writer, options) {
1393
+ if (!WorkerFarm.isSupported()) {
1394
+ return false;
1539
1395
  }
1540
- /** Read data */
1541
- async read(start, end) {
1542
- throw NOT_IMPLEMENTED;
1396
+ if (!isBrowser && !options?._nodeWorkers) {
1397
+ return false;
1543
1398
  }
1544
- /** Write to file. The number of bytes written will be returned */
1545
- async write(arrayBuffer, offset, length) {
1546
- throw NOT_IMPLEMENTED;
1399
+ return writer.worker && options?.worker;
1400
+ }
1401
+
1402
+ // ../loader-utils/src/lib/binary-utils/array-buffer-utils.ts
1403
+ function compareArrayBuffers(arrayBuffer1, arrayBuffer2, byteLength) {
1404
+ byteLength = byteLength || arrayBuffer1.byteLength;
1405
+ if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) {
1406
+ return false;
1547
1407
  }
1548
- /** Get information about file */
1549
- async stat() {
1550
- throw NOT_IMPLEMENTED;
1408
+ const array1 = new Uint8Array(arrayBuffer1);
1409
+ const array2 = new Uint8Array(arrayBuffer2);
1410
+ for (let i = 0; i < array1.length; ++i) {
1411
+ if (array1[i] !== array2[i]) {
1412
+ return false;
1413
+ }
1551
1414
  }
1552
- /** Truncates the file descriptor. Only available on NodeFile. */
1553
- async truncate(length) {
1554
- throw NOT_IMPLEMENTED;
1415
+ return true;
1416
+ }
1417
+ function concatenateArrayBuffers(...sources) {
1418
+ return concatenateArrayBuffersFromArray(sources);
1419
+ }
1420
+ function concatenateArrayBuffersFromArray(sources) {
1421
+ const sourceArrays = sources.map(
1422
+ (source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
1423
+ );
1424
+ const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
1425
+ const result = new Uint8Array(byteLength);
1426
+ let offset = 0;
1427
+ for (const sourceArray of sourceArrays) {
1428
+ result.set(sourceArray, offset);
1429
+ offset += sourceArray.byteLength;
1555
1430
  }
1556
- /** Append data to a file. Only available on NodeFile. */
1557
- async append(data) {
1558
- throw NOT_IMPLEMENTED;
1559
- }
1560
- /** Close the file */
1561
- async close() {
1562
- }
1563
- };
1564
-
1565
- // src/javascript-utils/is-type.ts
1566
- var isBoolean = (x) => typeof x === "boolean";
1567
- var isFunction = (x) => typeof x === "function";
1568
- var isObject = (x) => x !== null && typeof x === "object";
1569
- var isPureObject = (x) => isObject(x) && x.constructor === {}.constructor;
1570
- var isPromise = (x) => isObject(x) && isFunction(x.then);
1571
- var isIterable = (x) => Boolean(x) && typeof x[Symbol.iterator] === "function";
1572
- var isAsyncIterable = (x) => x && typeof x[Symbol.asyncIterator] === "function";
1573
- var isIterator = (x) => x && isFunction(x.next);
1574
- var isResponse = (x) => typeof Response !== "undefined" && x instanceof Response || x && x.arrayBuffer && x.text && x.json;
1575
- var isBlob = (x) => typeof Blob !== "undefined" && x instanceof Blob;
1576
- var isBuffer2 = (x) => x && typeof x === "object" && x.isBuffer;
1577
- var isWritableDOMStream = (x) => isObject(x) && isFunction(x.abort) && isFunction(x.getWriter);
1578
- var isReadableDOMStream = (x) => typeof ReadableStream !== "undefined" && x instanceof ReadableStream || isObject(x) && isFunction(x.tee) && isFunction(x.cancel) && isFunction(x.getReader);
1579
- var isWritableNodeStream = (x) => isObject(x) && isFunction(x.end) && isFunction(x.write) && isBoolean(x.writable);
1580
- var isReadableNodeStream = (x) => isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);
1581
- var isReadableStream = (x) => isReadableDOMStream(x) || isReadableNodeStream(x);
1582
- var isWritableStream = (x) => isWritableDOMStream(x) || isWritableNodeStream(x);
1431
+ return result.buffer;
1432
+ }
1583
1433
 
1584
- // src/lib/utils/mime-type-utils.ts
1585
- var DATA_URL_PATTERN = /^data:([-\w.]+\/[-\w.+]+)(;|,)/;
1586
- var MIME_TYPE_PATTERN = /^([-\w.]+\/[-\w.+]+)/;
1587
- function parseMIMEType(mimeString) {
1588
- const matches3 = MIME_TYPE_PATTERN.exec(mimeString);
1589
- if (matches3) {
1590
- return matches3[1];
1434
+ // ../loader-utils/src/lib/iterators/text-iterators.ts
1435
+ async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
1436
+ const textDecoder = new TextDecoder(void 0, options);
1437
+ for await (const arrayBuffer of arrayBufferIterator) {
1438
+ yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, { stream: true });
1591
1439
  }
1592
- return mimeString;
1593
1440
  }
1594
- function parseMIMETypeFromURL(url) {
1595
- const matches3 = DATA_URL_PATTERN.exec(url);
1596
- if (matches3) {
1597
- return matches3[1];
1441
+ async function* makeTextEncoderIterator(textIterator) {
1442
+ const textEncoder = new TextEncoder();
1443
+ for await (const text of textIterator) {
1444
+ yield typeof text === "string" ? textEncoder.encode(text) : text;
1598
1445
  }
1599
- return "";
1600
1446
  }
1601
-
1602
- // src/lib/utils/url-utils.ts
1603
- var QUERY_STRING_PATTERN = /\?.*/;
1604
- function extractQueryString(url) {
1605
- const matches3 = url.match(QUERY_STRING_PATTERN);
1606
- return matches3 && matches3[0];
1447
+ async function* makeLineIterator(textIterator) {
1448
+ let previous = "";
1449
+ for await (const textChunk of textIterator) {
1450
+ previous += textChunk;
1451
+ let eolIndex;
1452
+ while ((eolIndex = previous.indexOf("\n")) >= 0) {
1453
+ const line = previous.slice(0, eolIndex + 1);
1454
+ previous = previous.slice(eolIndex + 1);
1455
+ yield line;
1456
+ }
1457
+ }
1458
+ if (previous.length > 0) {
1459
+ yield previous;
1460
+ }
1607
1461
  }
1608
- function stripQueryString(url) {
1609
- return url.replace(QUERY_STRING_PATTERN, "");
1462
+ async function* makeNumberedLineIterator(lineIterator) {
1463
+ let counter = 1;
1464
+ for await (const line of lineIterator) {
1465
+ yield { counter, line };
1466
+ counter++;
1467
+ }
1610
1468
  }
1611
1469
 
1612
- // src/lib/utils/resource-utils.ts
1613
- function getResourceUrl(resource) {
1614
- if (isResponse(resource)) {
1615
- const response = resource;
1616
- return response.url;
1470
+ // ../loader-utils/src/lib/iterators/async-iteration.ts
1471
+ async function forEach(iterator, visitor) {
1472
+ while (true) {
1473
+ const { done, value } = await iterator.next();
1474
+ if (done) {
1475
+ iterator.return();
1476
+ return;
1477
+ }
1478
+ const cancel = visitor(value);
1479
+ if (cancel) {
1480
+ return;
1481
+ }
1617
1482
  }
1618
- if (isBlob(resource)) {
1619
- const blob = resource;
1620
- return blob.name || "";
1483
+ }
1484
+ async function concatenateArrayBuffersAsync(asyncIterator) {
1485
+ const arrayBuffers = [];
1486
+ for await (const chunk of asyncIterator) {
1487
+ arrayBuffers.push(chunk);
1621
1488
  }
1622
- if (typeof resource === "string") {
1623
- return resource;
1489
+ return concatenateArrayBuffers(...arrayBuffers);
1490
+ }
1491
+
1492
+ // ../../node_modules/@probe.gl/stats/dist/utils/hi-res-timestamp.js
1493
+ function getHiResTimestamp2() {
1494
+ let timestamp;
1495
+ if (typeof window !== "undefined" && window.performance) {
1496
+ timestamp = window.performance.now();
1497
+ } else if (typeof process !== "undefined" && process.hrtime) {
1498
+ const timeParts = process.hrtime();
1499
+ timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
1500
+ } else {
1501
+ timestamp = Date.now();
1624
1502
  }
1625
- return "";
1503
+ return timestamp;
1626
1504
  }
1627
- function getResourceMIMEType(resource) {
1628
- if (isResponse(resource)) {
1629
- const response = resource;
1630
- const contentTypeHeader = response.headers.get("content-type") || "";
1631
- const noQueryUrl = stripQueryString(response.url);
1632
- return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);
1505
+
1506
+ // ../../node_modules/@probe.gl/stats/dist/lib/stat.js
1507
+ var Stat = class {
1508
+ constructor(name, type) {
1509
+ _defineProperty(this, "name", void 0);
1510
+ _defineProperty(this, "type", void 0);
1511
+ _defineProperty(this, "sampleSize", 1);
1512
+ _defineProperty(this, "time", 0);
1513
+ _defineProperty(this, "count", 0);
1514
+ _defineProperty(this, "samples", 0);
1515
+ _defineProperty(this, "lastTiming", 0);
1516
+ _defineProperty(this, "lastSampleTime", 0);
1517
+ _defineProperty(this, "lastSampleCount", 0);
1518
+ _defineProperty(this, "_count", 0);
1519
+ _defineProperty(this, "_time", 0);
1520
+ _defineProperty(this, "_samples", 0);
1521
+ _defineProperty(this, "_startTime", 0);
1522
+ _defineProperty(this, "_timerPending", false);
1523
+ this.name = name;
1524
+ this.type = type;
1525
+ this.reset();
1633
1526
  }
1634
- if (isBlob(resource)) {
1635
- const blob = resource;
1636
- return blob.type || "";
1527
+ reset() {
1528
+ this.time = 0;
1529
+ this.count = 0;
1530
+ this.samples = 0;
1531
+ this.lastTiming = 0;
1532
+ this.lastSampleTime = 0;
1533
+ this.lastSampleCount = 0;
1534
+ this._count = 0;
1535
+ this._time = 0;
1536
+ this._samples = 0;
1537
+ this._startTime = 0;
1538
+ this._timerPending = false;
1539
+ return this;
1637
1540
  }
1638
- if (typeof resource === "string") {
1639
- return parseMIMETypeFromURL(resource);
1541
+ setSampleSize(samples) {
1542
+ this.sampleSize = samples;
1543
+ return this;
1640
1544
  }
1641
- return "";
1642
- }
1643
- function getResourceContentLength(resource) {
1644
- if (isResponse(resource)) {
1645
- const response = resource;
1646
- return response.headers["content-length"] || -1;
1545
+ incrementCount() {
1546
+ this.addCount(1);
1547
+ return this;
1647
1548
  }
1648
- if (isBlob(resource)) {
1649
- const blob = resource;
1650
- return blob.size;
1549
+ decrementCount() {
1550
+ this.subtractCount(1);
1551
+ return this;
1651
1552
  }
1652
- if (typeof resource === "string") {
1653
- return resource.length;
1553
+ addCount(value) {
1554
+ this._count += value;
1555
+ this._samples++;
1556
+ this._checkSampling();
1557
+ return this;
1654
1558
  }
1655
- if (resource instanceof ArrayBuffer) {
1656
- return resource.byteLength;
1559
+ subtractCount(value) {
1560
+ this._count -= value;
1561
+ this._samples++;
1562
+ this._checkSampling();
1563
+ return this;
1657
1564
  }
1658
- if (ArrayBuffer.isView(resource)) {
1659
- return resource.byteLength;
1565
+ addTime(time) {
1566
+ this._time += time;
1567
+ this.lastTiming = time;
1568
+ this._samples++;
1569
+ this._checkSampling();
1570
+ return this;
1660
1571
  }
1661
- return -1;
1662
- }
1663
-
1664
- // src/lib/utils/response-utils.ts
1665
- async function makeResponse(resource) {
1666
- if (isResponse(resource)) {
1667
- return resource;
1572
+ timeStart() {
1573
+ this._startTime = getHiResTimestamp2();
1574
+ this._timerPending = true;
1575
+ return this;
1668
1576
  }
1669
- const headers = {};
1670
- const contentLength = getResourceContentLength(resource);
1671
- if (contentLength >= 0) {
1672
- headers["content-length"] = String(contentLength);
1577
+ timeEnd() {
1578
+ if (!this._timerPending) {
1579
+ return this;
1580
+ }
1581
+ this.addTime(getHiResTimestamp2() - this._startTime);
1582
+ this._timerPending = false;
1583
+ this._checkSampling();
1584
+ return this;
1673
1585
  }
1674
- const url = getResourceUrl(resource);
1675
- const type = getResourceMIMEType(resource);
1676
- if (type) {
1677
- headers["content-type"] = type;
1586
+ getSampleAverageCount() {
1587
+ return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
1678
1588
  }
1679
- const initialDataUrl = await getInitialDataUrl(resource);
1680
- if (initialDataUrl) {
1681
- headers["x-first-bytes"] = initialDataUrl;
1589
+ getSampleAverageTime() {
1590
+ return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
1682
1591
  }
1683
- if (typeof resource === "string") {
1684
- resource = new TextEncoder().encode(resource);
1592
+ getSampleHz() {
1593
+ return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1e3) : 0;
1685
1594
  }
1686
- const response = new Response(resource, { headers });
1687
- Object.defineProperty(response, "url", { value: url });
1688
- return response;
1689
- }
1690
- async function checkResponse(response) {
1691
- if (!response.ok) {
1692
- const message = await getResponseError(response);
1693
- throw new Error(message);
1595
+ getAverageCount() {
1596
+ return this.samples > 0 ? this.count / this.samples : 0;
1694
1597
  }
1695
- }
1696
- async function getResponseError(response) {
1697
- let message = `Failed to fetch resource ${response.url} (${response.status}): `;
1698
- try {
1699
- const contentType = response.headers.get("Content-Type");
1700
- let text = response.statusText;
1701
- if (contentType?.includes("application/json")) {
1702
- text += ` ${await response.text()}`;
1703
- }
1704
- message += text;
1705
- message = message.length > 60 ? `${message.slice(0, 60)}...` : message;
1706
- } catch (error) {
1598
+ getAverageTime() {
1599
+ return this.samples > 0 ? this.time / this.samples : 0;
1707
1600
  }
1708
- return message;
1709
- }
1710
- async function getInitialDataUrl(resource) {
1711
- const INITIAL_DATA_LENGTH = 5;
1712
- if (typeof resource === "string") {
1713
- return `data:,${resource.slice(0, INITIAL_DATA_LENGTH)}`;
1714
- }
1715
- if (resource instanceof Blob) {
1716
- const blobSlice = resource.slice(0, 5);
1717
- return await new Promise((resolve2) => {
1718
- const reader = new FileReader();
1719
- reader.onload = (event) => resolve2(event?.target?.result);
1720
- reader.readAsDataURL(blobSlice);
1721
- });
1722
- }
1723
- if (resource instanceof ArrayBuffer) {
1724
- const slice = resource.slice(0, INITIAL_DATA_LENGTH);
1725
- const base64 = arrayBufferToBase64(slice);
1726
- return `data:base64,${base64}`;
1727
- }
1728
- return null;
1729
- }
1730
- function arrayBufferToBase64(buffer) {
1731
- let binary = "";
1732
- const bytes = new Uint8Array(buffer);
1733
- for (let i = 0; i < bytes.byteLength; i++) {
1734
- binary += String.fromCharCode(bytes[i]);
1601
+ getHz() {
1602
+ return this.time > 0 ? this.samples / (this.time / 1e3) : 0;
1735
1603
  }
1736
- return btoa(binary);
1737
- }
1738
-
1739
- // src/lib/fetch/fetch-file.ts
1740
- function isNodePath(url) {
1741
- return !isRequestURL(url) && !isDataURL(url);
1742
- }
1743
- function isRequestURL(url) {
1744
- return url.startsWith("http:") || url.startsWith("https:");
1745
- }
1746
- function isDataURL(url) {
1747
- return url.startsWith("data:");
1748
- }
1749
- async function fetchFile(urlOrData, fetchOptions) {
1750
- if (typeof urlOrData === "string") {
1751
- const url = resolvePath(urlOrData);
1752
- if (isNodePath(url)) {
1753
- if (globalThis.loaders?.fetchNode) {
1754
- return globalThis.loaders?.fetchNode(url, fetchOptions);
1755
- }
1604
+ _checkSampling() {
1605
+ if (this._samples === this.sampleSize) {
1606
+ this.lastSampleTime = this._time;
1607
+ this.lastSampleCount = this._count;
1608
+ this.count += this._count;
1609
+ this.time += this._time;
1610
+ this.samples += this._samples;
1611
+ this._time = 0;
1612
+ this._count = 0;
1613
+ this._samples = 0;
1756
1614
  }
1757
- return await fetch(url, fetchOptions);
1758
- }
1759
- return await makeResponse(urlOrData);
1760
- }
1761
-
1762
- // src/lib/fetch/read-array-buffer.ts
1763
- async function readArrayBuffer(file, start, length) {
1764
- if (!(file instanceof Blob)) {
1765
- file = new Blob([file]);
1766
1615
  }
1767
- const slice = file.slice(start, start + length);
1768
- return await readBlob(slice);
1769
- }
1770
- async function readBlob(blob) {
1771
- return await new Promise((resolve2, reject) => {
1772
- const fileReader = new FileReader();
1773
- fileReader.onload = (event) => resolve2(event?.target?.result);
1774
- fileReader.onerror = (error) => reject(error);
1775
- fileReader.readAsArrayBuffer(blob);
1776
- });
1777
- }
1616
+ };
1778
1617
 
1779
- // ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/lib/is-electron.js
1780
- function isElectron(mockUserAgent) {
1781
- if (typeof window !== "undefined" && typeof window.process === "object" && window.process.type === "renderer") {
1782
- return true;
1618
+ // ../../node_modules/@probe.gl/stats/dist/lib/stats.js
1619
+ var Stats = class {
1620
+ constructor(options) {
1621
+ _defineProperty(this, "id", void 0);
1622
+ _defineProperty(this, "stats", {});
1623
+ this.id = options.id;
1624
+ this.stats = {};
1625
+ this._initializeStats(options.stats);
1626
+ Object.seal(this);
1783
1627
  }
1784
- if (typeof process !== "undefined" && typeof process.versions === "object" && Boolean(process.versions["electron"])) {
1785
- return true;
1628
+ get(name) {
1629
+ let type = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "count";
1630
+ return this._getOrCreate({
1631
+ name,
1632
+ type
1633
+ });
1786
1634
  }
1787
- const realUserAgent = typeof navigator === "object" && typeof navigator.userAgent === "string" && navigator.userAgent;
1788
- const userAgent = mockUserAgent || realUserAgent;
1789
- if (userAgent && userAgent.indexOf("Electron") >= 0) {
1790
- return true;
1635
+ get size() {
1636
+ return Object.keys(this.stats).length;
1791
1637
  }
1792
- return false;
1793
- }
1794
-
1795
- // ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/lib/is-browser.js
1796
- function isBrowser3() {
1797
- const isNode = typeof process === "object" && String(process) === "[object process]" && !process.browser;
1798
- return !isNode || isElectron();
1799
- }
1800
-
1801
- // ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/lib/globals.js
1802
- var self_3 = globalThis.self || globalThis.window || globalThis.global;
1803
- var window_3 = globalThis.window || globalThis.self || globalThis.global;
1804
- var document_3 = globalThis.document || {};
1805
- var process_ = globalThis.process || {};
1806
- var console_ = globalThis.console;
1807
- var navigator_ = globalThis.navigator || {};
1808
-
1809
- // ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/utils/globals.js
1810
- var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "untranspiled source";
1811
- var isBrowser4 = isBrowser3();
1812
-
1813
- // ../../node_modules/@probe.gl/log/dist/utils/local-storage.js
1814
- function getStorage(type) {
1815
- try {
1816
- const storage = window[type];
1817
- const x = "__storage_test__";
1818
- storage.setItem(x, x);
1819
- storage.removeItem(x);
1820
- return storage;
1821
- } catch (e) {
1822
- return null;
1638
+ reset() {
1639
+ for (const stat of Object.values(this.stats)) {
1640
+ stat.reset();
1641
+ }
1642
+ return this;
1823
1643
  }
1824
- }
1825
- var LocalStorage = class {
1826
- constructor(id, defaultConfig) {
1827
- let type = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "sessionStorage";
1828
- _defineProperty(this, "storage", void 0);
1829
- _defineProperty(this, "id", void 0);
1830
- _defineProperty(this, "config", void 0);
1831
- this.storage = getStorage(type);
1832
- this.id = id;
1833
- this.config = defaultConfig;
1834
- this._loadConfiguration();
1644
+ forEach(fn) {
1645
+ for (const stat of Object.values(this.stats)) {
1646
+ fn(stat);
1647
+ }
1835
1648
  }
1836
- getConfiguration() {
1837
- return this.config;
1649
+ getTable() {
1650
+ const table = {};
1651
+ this.forEach((stat) => {
1652
+ table[stat.name] = {
1653
+ time: stat.time || 0,
1654
+ count: stat.count || 0,
1655
+ average: stat.getAverageTime() || 0,
1656
+ hz: stat.getHz() || 0
1657
+ };
1658
+ });
1659
+ return table;
1838
1660
  }
1839
- setConfiguration(configuration) {
1840
- Object.assign(this.config, configuration);
1841
- if (this.storage) {
1842
- const serialized = JSON.stringify(this.config);
1843
- this.storage.setItem(this.id, serialized);
1844
- }
1661
+ _initializeStats() {
1662
+ let stats = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
1663
+ stats.forEach((stat) => this._getOrCreate(stat));
1845
1664
  }
1846
- _loadConfiguration() {
1847
- let configuration = {};
1848
- if (this.storage) {
1849
- const serializedConfiguration = this.storage.getItem(this.id);
1850
- configuration = serializedConfiguration ? JSON.parse(serializedConfiguration) : {};
1665
+ _getOrCreate(stat) {
1666
+ const {
1667
+ name,
1668
+ type
1669
+ } = stat;
1670
+ let result = this.stats[name];
1671
+ if (!result) {
1672
+ if (stat instanceof Stat) {
1673
+ result = stat;
1674
+ } else {
1675
+ result = new Stat(name, type);
1676
+ }
1677
+ this.stats[name] = result;
1851
1678
  }
1852
- Object.assign(this.config, configuration);
1853
- return this;
1679
+ return result;
1854
1680
  }
1855
1681
  };
1856
1682
 
1857
- // ../../node_modules/@probe.gl/log/dist/utils/formatters.js
1858
- function formatTime(ms) {
1859
- let formatted;
1860
- if (ms < 10) {
1861
- formatted = "".concat(ms.toFixed(2), "ms");
1862
- } else if (ms < 100) {
1863
- formatted = "".concat(ms.toFixed(1), "ms");
1864
- } else if (ms < 1e3) {
1865
- formatted = "".concat(ms.toFixed(0), "ms");
1866
- } else {
1867
- formatted = "".concat((ms / 1e3).toFixed(2), "s");
1683
+ // ../loader-utils/src/lib/request-utils/request-scheduler.ts
1684
+ var STAT_QUEUED_REQUESTS = "Queued Requests";
1685
+ var STAT_ACTIVE_REQUESTS = "Active Requests";
1686
+ var STAT_CANCELLED_REQUESTS = "Cancelled Requests";
1687
+ var STAT_QUEUED_REQUESTS_EVER = "Queued Requests Ever";
1688
+ var STAT_ACTIVE_REQUESTS_EVER = "Active Requests Ever";
1689
+ var DEFAULT_PROPS2 = {
1690
+ id: "request-scheduler",
1691
+ /** Specifies if the request scheduler should throttle incoming requests, mainly for comparative testing. */
1692
+ throttleRequests: true,
1693
+ /** The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit. */
1694
+ maxRequests: 6,
1695
+ /**
1696
+ * Specifies a debounce time, in milliseconds. All requests are queued, until no new requests have
1697
+ * been added to the queue for this amount of time.
1698
+ */
1699
+ debounceTime: 0
1700
+ };
1701
+ var RequestScheduler = class {
1702
+ props;
1703
+ stats;
1704
+ activeRequestCount = 0;
1705
+ /** Tracks the number of active requests and prioritizes/cancels queued requests. */
1706
+ requestQueue = [];
1707
+ requestMap = /* @__PURE__ */ new Map();
1708
+ updateTimer = null;
1709
+ constructor(props = {}) {
1710
+ this.props = { ...DEFAULT_PROPS2, ...props };
1711
+ this.stats = new Stats({ id: this.props.id });
1712
+ this.stats.get(STAT_QUEUED_REQUESTS);
1713
+ this.stats.get(STAT_ACTIVE_REQUESTS);
1714
+ this.stats.get(STAT_CANCELLED_REQUESTS);
1715
+ this.stats.get(STAT_QUEUED_REQUESTS_EVER);
1716
+ this.stats.get(STAT_ACTIVE_REQUESTS_EVER);
1868
1717
  }
1869
- return formatted;
1870
- }
1871
- function leftPad(string) {
1872
- let length = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 8;
1873
- const padLength = Math.max(length - string.length, 0);
1874
- return "".concat(" ".repeat(padLength)).concat(string);
1875
- }
1876
- function formatImage(image, message, scale) {
1877
- let maxWidth = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 600;
1878
- const imageUrl = image.src.replace(/\(/g, "%28").replace(/\)/g, "%29");
1879
- if (image.width > maxWidth) {
1880
- scale = Math.min(scale, maxWidth / image.width);
1718
+ /**
1719
+ * Called by an application that wants to issue a request, without having it deeply queued by the browser
1720
+ *
1721
+ * When the returned promise resolved, it is OK for the application to issue a request.
1722
+ * The promise resolves to an object that contains a `done` method.
1723
+ * When the application's request has completed (or failed), the application must call the `done` function
1724
+ *
1725
+ * @param handle
1726
+ * @param getPriority will be called when request "slots" open up,
1727
+ * allowing the caller to update priority or cancel the request
1728
+ * Highest priority executes first, priority < 0 cancels the request
1729
+ * @returns a promise
1730
+ * - resolves to a object (with a `done` field) when the request can be issued without queueing,
1731
+ * - resolves to `null` if the request has been cancelled (by the callback return < 0).
1732
+ * In this case the application should not issue the request
1733
+ */
1734
+ scheduleRequest(handle, getPriority = () => 0) {
1735
+ if (!this.props.throttleRequests) {
1736
+ return Promise.resolve({ done: () => {
1737
+ } });
1738
+ }
1739
+ if (this.requestMap.has(handle)) {
1740
+ return this.requestMap.get(handle);
1741
+ }
1742
+ const request = { handle, priority: 0, getPriority };
1743
+ const promise = new Promise((resolve2) => {
1744
+ request.resolve = resolve2;
1745
+ return request;
1746
+ });
1747
+ this.requestQueue.push(request);
1748
+ this.requestMap.set(handle, promise);
1749
+ this._issueNewRequests();
1750
+ return promise;
1881
1751
  }
1882
- const width = image.width * scale;
1883
- const height = image.height * scale;
1884
- const style = ["font-size:1px;", "padding:".concat(Math.floor(height / 2), "px ").concat(Math.floor(width / 2), "px;"), "line-height:".concat(height, "px;"), "background:url(".concat(imageUrl, ");"), "background-size:".concat(width, "px ").concat(height, "px;"), "color:transparent;"].join("");
1885
- return ["".concat(message, " %c+"), style];
1886
- }
1887
-
1888
- // ../../node_modules/@probe.gl/log/dist/utils/color.js
1889
- var COLOR;
1890
- (function(COLOR2) {
1891
- COLOR2[COLOR2["BLACK"] = 30] = "BLACK";
1892
- COLOR2[COLOR2["RED"] = 31] = "RED";
1893
- COLOR2[COLOR2["GREEN"] = 32] = "GREEN";
1894
- COLOR2[COLOR2["YELLOW"] = 33] = "YELLOW";
1895
- COLOR2[COLOR2["BLUE"] = 34] = "BLUE";
1896
- COLOR2[COLOR2["MAGENTA"] = 35] = "MAGENTA";
1897
- COLOR2[COLOR2["CYAN"] = 36] = "CYAN";
1898
- COLOR2[COLOR2["WHITE"] = 37] = "WHITE";
1899
- COLOR2[COLOR2["BRIGHT_BLACK"] = 90] = "BRIGHT_BLACK";
1900
- COLOR2[COLOR2["BRIGHT_RED"] = 91] = "BRIGHT_RED";
1901
- COLOR2[COLOR2["BRIGHT_GREEN"] = 92] = "BRIGHT_GREEN";
1902
- COLOR2[COLOR2["BRIGHT_YELLOW"] = 93] = "BRIGHT_YELLOW";
1903
- COLOR2[COLOR2["BRIGHT_BLUE"] = 94] = "BRIGHT_BLUE";
1904
- COLOR2[COLOR2["BRIGHT_MAGENTA"] = 95] = "BRIGHT_MAGENTA";
1905
- COLOR2[COLOR2["BRIGHT_CYAN"] = 96] = "BRIGHT_CYAN";
1906
- COLOR2[COLOR2["BRIGHT_WHITE"] = 97] = "BRIGHT_WHITE";
1907
- })(COLOR || (COLOR = {}));
1908
- var BACKGROUND_INCREMENT = 10;
1909
- function getColor(color) {
1910
- if (typeof color !== "string") {
1911
- return color;
1752
+ // PRIVATE
1753
+ _issueRequest(request) {
1754
+ const { handle, resolve: resolve2 } = request;
1755
+ let isDone = false;
1756
+ const done = () => {
1757
+ if (!isDone) {
1758
+ isDone = true;
1759
+ this.requestMap.delete(handle);
1760
+ this.activeRequestCount--;
1761
+ this._issueNewRequests();
1762
+ }
1763
+ };
1764
+ this.activeRequestCount++;
1765
+ return resolve2 ? resolve2({ done }) : Promise.resolve({ done });
1766
+ }
1767
+ /** We check requests asynchronously, to prevent multiple updates */
1768
+ _issueNewRequests() {
1769
+ if (this.updateTimer !== null) {
1770
+ clearTimeout(this.updateTimer);
1771
+ }
1772
+ this.updateTimer = setTimeout(() => this._issueNewRequestsAsync(), this.props.debounceTime);
1773
+ }
1774
+ /** Refresh all requests */
1775
+ _issueNewRequestsAsync() {
1776
+ if (this.updateTimer !== null) {
1777
+ clearTimeout(this.updateTimer);
1778
+ }
1779
+ this.updateTimer = null;
1780
+ const freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);
1781
+ if (freeSlots === 0) {
1782
+ return;
1783
+ }
1784
+ this._updateAllRequests();
1785
+ for (let i = 0; i < freeSlots; ++i) {
1786
+ const request = this.requestQueue.shift();
1787
+ if (request) {
1788
+ this._issueRequest(request);
1789
+ }
1790
+ }
1912
1791
  }
1913
- color = color.toUpperCase();
1914
- return COLOR[color] || COLOR.WHITE;
1915
- }
1916
- function addColor(string, color, background) {
1917
- if (!isBrowser3 && typeof string === "string") {
1918
- if (color) {
1919
- const colorCode = getColor(color);
1920
- string = "\x1B[".concat(colorCode, "m").concat(string, "\x1B[39m");
1792
+ /** Ensure all requests have updated priorities, and that no longer valid requests are cancelled */
1793
+ _updateAllRequests() {
1794
+ const requestQueue = this.requestQueue;
1795
+ for (let i = 0; i < requestQueue.length; ++i) {
1796
+ const request = requestQueue[i];
1797
+ if (!this._updateRequest(request)) {
1798
+ requestQueue.splice(i, 1);
1799
+ this.requestMap.delete(request.handle);
1800
+ i--;
1801
+ }
1921
1802
  }
1922
- if (background) {
1923
- const colorCode = getColor(background);
1924
- string = "\x1B[".concat(colorCode + BACKGROUND_INCREMENT, "m").concat(string, "\x1B[49m");
1803
+ requestQueue.sort((a, b) => a.priority - b.priority);
1804
+ }
1805
+ /** Update a single request by calling the callback */
1806
+ _updateRequest(request) {
1807
+ request.priority = request.getPriority(request.handle);
1808
+ if (request.priority < 0) {
1809
+ request.resolve(null);
1810
+ return false;
1925
1811
  }
1812
+ return true;
1926
1813
  }
1927
- return string;
1928
- }
1814
+ };
1929
1815
 
1930
- // ../../node_modules/@probe.gl/log/dist/utils/autobind.js
1931
- function autobind(obj) {
1932
- let predefined = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ["constructor"];
1933
- const proto = Object.getPrototypeOf(obj);
1934
- const propNames = Object.getOwnPropertyNames(proto);
1935
- const object = obj;
1936
- for (const key of propNames) {
1937
- const value = object[key];
1938
- if (typeof value === "function") {
1939
- if (!predefined.find((name) => key === name)) {
1940
- object[key] = value.bind(obj);
1941
- }
1816
+ // ../loader-utils/src/lib/path-utils/file-aliases.ts
1817
+ var pathPrefix = "";
1818
+ var fileAliases = {};
1819
+ function setPathPrefix(prefix) {
1820
+ pathPrefix = prefix;
1821
+ }
1822
+ function getPathPrefix() {
1823
+ return pathPrefix;
1824
+ }
1825
+ function resolvePath(filename2) {
1826
+ for (const alias in fileAliases) {
1827
+ if (filename2.startsWith(alias)) {
1828
+ const replacement = fileAliases[alias];
1829
+ filename2 = filename2.replace(alias, replacement);
1942
1830
  }
1943
1831
  }
1832
+ if (!filename2.startsWith("http://") && !filename2.startsWith("https://")) {
1833
+ filename2 = `${pathPrefix}${filename2}`;
1834
+ }
1835
+ return filename2;
1944
1836
  }
1945
1837
 
1946
- // ../../node_modules/@probe.gl/log/dist/utils/assert.js
1947
- function assert3(condition, message) {
1948
- if (!condition) {
1949
- throw new Error(message || "Assertion failed");
1838
+ // ../loader-utils/src/json-loader.ts
1839
+ var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1840
+ var JSONLoader = {
1841
+ dataType: null,
1842
+ batchType: null,
1843
+ name: "JSON",
1844
+ id: "json",
1845
+ module: "json",
1846
+ version: VERSION3,
1847
+ extensions: ["json", "geojson"],
1848
+ mimeTypes: ["application/json"],
1849
+ category: "json",
1850
+ text: true,
1851
+ parseTextSync,
1852
+ parse: async (arrayBuffer) => parseTextSync(new TextDecoder().decode(arrayBuffer)),
1853
+ options: {}
1854
+ };
1855
+ function parseTextSync(text) {
1856
+ return JSON.parse(text);
1857
+ }
1858
+
1859
+ // ../loader-utils/src/lib/node/buffer.browser.ts
1860
+ function toArrayBuffer(buffer) {
1861
+ return buffer;
1862
+ }
1863
+
1864
+ // ../loader-utils/src/lib/binary-utils/memory-conversion-utils.ts
1865
+ function isBuffer(value) {
1866
+ return value && typeof value === "object" && value.isBuffer;
1867
+ }
1868
+ function toArrayBuffer2(data) {
1869
+ if (isBuffer(data)) {
1870
+ return toArrayBuffer(data);
1950
1871
  }
1872
+ if (data instanceof ArrayBuffer) {
1873
+ return data;
1874
+ }
1875
+ if (ArrayBuffer.isView(data)) {
1876
+ if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
1877
+ return data.buffer;
1878
+ }
1879
+ return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
1880
+ }
1881
+ if (typeof data === "string") {
1882
+ const text = data;
1883
+ const uint8Array = new TextEncoder().encode(text);
1884
+ return uint8Array.buffer;
1885
+ }
1886
+ if (data && typeof data === "object" && data._toArrayBuffer) {
1887
+ return data._toArrayBuffer();
1888
+ }
1889
+ throw new Error("toArrayBuffer");
1951
1890
  }
1952
1891
 
1953
- // ../../node_modules/@probe.gl/log/dist/utils/hi-res-timestamp.js
1954
- function getHiResTimestamp2() {
1955
- let timestamp;
1956
- if (isBrowser3() && window_3.performance) {
1957
- var _window$performance, _window$performance$n;
1958
- timestamp = window_3 === null || window_3 === void 0 ? void 0 : (_window$performance = window_3.performance) === null || _window$performance === void 0 ? void 0 : (_window$performance$n = _window$performance.now) === null || _window$performance$n === void 0 ? void 0 : _window$performance$n.call(_window$performance);
1959
- } else if ("hrtime" in process_) {
1960
- var _process$hrtime;
1961
- const timeParts = process_ === null || process_ === void 0 ? void 0 : (_process$hrtime = process_.hrtime) === null || _process$hrtime === void 0 ? void 0 : _process$hrtime.call(process_);
1962
- timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
1963
- } else {
1964
- timestamp = Date.now();
1892
+ // ../loader-utils/src/lib/path-utils/path.ts
1893
+ var path_exports = {};
1894
+ __export(path_exports, {
1895
+ dirname: () => dirname,
1896
+ filename: () => filename,
1897
+ join: () => join,
1898
+ resolve: () => resolve
1899
+ });
1900
+
1901
+ // ../loader-utils/src/lib/path-utils/get-cwd.ts
1902
+ function getCWD() {
1903
+ if (typeof process !== "undefined" && typeof process.cwd !== "undefined") {
1904
+ return process.cwd();
1965
1905
  }
1966
- return timestamp;
1906
+ const pathname = window.location?.pathname;
1907
+ return pathname?.slice(0, pathname.lastIndexOf("/") + 1) || "";
1967
1908
  }
1968
1909
 
1969
- // ../../node_modules/@probe.gl/log/dist/log.js
1970
- var originalConsole = {
1971
- debug: isBrowser3() ? console.debug || console.log : console.log,
1972
- log: console.log,
1973
- info: console.info,
1974
- warn: console.warn,
1975
- error: console.error
1976
- };
1977
- var DEFAULT_LOG_CONFIGURATION = {
1978
- enabled: true,
1979
- level: 0
1980
- };
1981
- function noop() {
1910
+ // ../loader-utils/src/lib/path-utils/path.ts
1911
+ function filename(url) {
1912
+ const slashIndex = url ? url.lastIndexOf("/") : -1;
1913
+ return slashIndex >= 0 ? url.substr(slashIndex + 1) : "";
1982
1914
  }
1983
- var cache = {};
1984
- var ONCE = {
1985
- once: true
1986
- };
1987
- var Log = class {
1988
- constructor() {
1989
- let {
1990
- id
1991
- } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
1992
- id: ""
1993
- };
1994
- _defineProperty(this, "id", void 0);
1995
- _defineProperty(this, "VERSION", VERSION3);
1996
- _defineProperty(this, "_startTs", getHiResTimestamp2());
1997
- _defineProperty(this, "_deltaTs", getHiResTimestamp2());
1998
- _defineProperty(this, "_storage", void 0);
1999
- _defineProperty(this, "userData", {});
2000
- _defineProperty(this, "LOG_THROTTLE_TIMEOUT", 0);
2001
- this.id = id;
2002
- this.userData = {};
2003
- this._storage = new LocalStorage("__probe-".concat(this.id, "__"), DEFAULT_LOG_CONFIGURATION);
2004
- this.timeStamp("".concat(this.id, " started"));
2005
- autobind(this);
2006
- Object.seal(this);
2007
- }
2008
- set level(newLevel) {
2009
- this.setLevel(newLevel);
1915
+ function dirname(url) {
1916
+ const slashIndex = url ? url.lastIndexOf("/") : -1;
1917
+ return slashIndex >= 0 ? url.substr(0, slashIndex) : "";
1918
+ }
1919
+ function join(...parts) {
1920
+ const separator = "/";
1921
+ parts = parts.map((part, index) => {
1922
+ if (index) {
1923
+ part = part.replace(new RegExp(`^${separator}`), "");
1924
+ }
1925
+ if (index !== parts.length - 1) {
1926
+ part = part.replace(new RegExp(`${separator}$`), "");
1927
+ }
1928
+ return part;
1929
+ });
1930
+ return parts.join(separator);
1931
+ }
1932
+ function resolve(...components) {
1933
+ const paths = [];
1934
+ for (let _i = 0; _i < components.length; _i++) {
1935
+ paths[_i] = components[_i];
2010
1936
  }
2011
- get level() {
2012
- return this.getLevel();
1937
+ let resolvedPath = "";
1938
+ let resolvedAbsolute = false;
1939
+ let cwd;
1940
+ for (let i = paths.length - 1; i >= -1 && !resolvedAbsolute; i--) {
1941
+ let path;
1942
+ if (i >= 0) {
1943
+ path = paths[i];
1944
+ } else {
1945
+ if (cwd === void 0) {
1946
+ cwd = getCWD();
1947
+ }
1948
+ path = cwd;
1949
+ }
1950
+ if (path.length === 0) {
1951
+ continue;
1952
+ }
1953
+ resolvedPath = `${path}/${resolvedPath}`;
1954
+ resolvedAbsolute = path.charCodeAt(0) === SLASH;
2013
1955
  }
2014
- isEnabled() {
2015
- return this._storage.config.enabled;
1956
+ resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
1957
+ if (resolvedAbsolute) {
1958
+ return `/${resolvedPath}`;
1959
+ } else if (resolvedPath.length > 0) {
1960
+ return resolvedPath;
2016
1961
  }
2017
- getLevel() {
2018
- return this._storage.config.level;
1962
+ return ".";
1963
+ }
1964
+ var SLASH = 47;
1965
+ var DOT = 46;
1966
+ function normalizeStringPosix(path, allowAboveRoot) {
1967
+ let res = "";
1968
+ let lastSlash = -1;
1969
+ let dots = 0;
1970
+ let code;
1971
+ let isAboveRoot = false;
1972
+ for (let i = 0; i <= path.length; ++i) {
1973
+ if (i < path.length) {
1974
+ code = path.charCodeAt(i);
1975
+ } else if (code === SLASH) {
1976
+ break;
1977
+ } else {
1978
+ code = SLASH;
1979
+ }
1980
+ if (code === SLASH) {
1981
+ if (lastSlash === i - 1 || dots === 1) {
1982
+ } else if (lastSlash !== i - 1 && dots === 2) {
1983
+ if (res.length < 2 || !isAboveRoot || res.charCodeAt(res.length - 1) !== DOT || res.charCodeAt(res.length - 2) !== DOT) {
1984
+ if (res.length > 2) {
1985
+ const start = res.length - 1;
1986
+ let j = start;
1987
+ for (; j >= 0; --j) {
1988
+ if (res.charCodeAt(j) === SLASH) {
1989
+ break;
1990
+ }
1991
+ }
1992
+ if (j !== start) {
1993
+ res = j === -1 ? "" : res.slice(0, j);
1994
+ lastSlash = i;
1995
+ dots = 0;
1996
+ isAboveRoot = false;
1997
+ continue;
1998
+ }
1999
+ } else if (res.length === 2 || res.length === 1) {
2000
+ res = "";
2001
+ lastSlash = i;
2002
+ dots = 0;
2003
+ isAboveRoot = false;
2004
+ continue;
2005
+ }
2006
+ }
2007
+ if (allowAboveRoot) {
2008
+ if (res.length > 0) {
2009
+ res += "/..";
2010
+ } else {
2011
+ res = "..";
2012
+ }
2013
+ isAboveRoot = true;
2014
+ }
2015
+ } else {
2016
+ const slice = path.slice(lastSlash + 1, i);
2017
+ if (res.length > 0) {
2018
+ res += `/${slice}`;
2019
+ } else {
2020
+ res = slice;
2021
+ }
2022
+ isAboveRoot = false;
2023
+ }
2024
+ lastSlash = i;
2025
+ dots = 0;
2026
+ } else if (code === DOT && dots !== -1) {
2027
+ ++dots;
2028
+ } else {
2029
+ dots = -1;
2030
+ }
2019
2031
  }
2020
- getTotal() {
2021
- return Number((getHiResTimestamp2() - this._startTs).toPrecision(10));
2032
+ return res;
2033
+ }
2034
+
2035
+ // ../loader-utils/src/lib/files/blob-file.ts
2036
+ var BlobFile = class {
2037
+ handle;
2038
+ size;
2039
+ bigsize;
2040
+ url;
2041
+ constructor(blob) {
2042
+ this.handle = blob instanceof ArrayBuffer ? new Blob([blob]) : blob;
2043
+ this.size = blob instanceof ArrayBuffer ? blob.byteLength : blob.size;
2044
+ this.bigsize = BigInt(this.size);
2045
+ this.url = blob instanceof File ? blob.name : "";
2022
2046
  }
2023
- getDelta() {
2024
- return Number((getHiResTimestamp2() - this._deltaTs).toPrecision(10));
2047
+ async close() {
2025
2048
  }
2026
- set priority(newPriority) {
2027
- this.level = newPriority;
2049
+ async stat() {
2050
+ return {
2051
+ size: this.handle.size,
2052
+ bigsize: BigInt(this.handle.size),
2053
+ isDirectory: false
2054
+ };
2028
2055
  }
2029
- get priority() {
2030
- return this.level;
2056
+ async read(start, length) {
2057
+ const arrayBuffer = await this.handle.slice(start, start + length).arrayBuffer();
2058
+ return arrayBuffer;
2031
2059
  }
2032
- getPriority() {
2033
- return this.level;
2060
+ };
2061
+
2062
+ // ../loader-utils/src/lib/files/node-file-facade.ts
2063
+ var NOT_IMPLEMENTED = new Error("Not implemented");
2064
+ var NodeFileFacade = class {
2065
+ handle;
2066
+ size = 0;
2067
+ bigsize = 0n;
2068
+ url = "";
2069
+ constructor(url, flags, mode) {
2070
+ if (globalThis.loaders?.NodeFile) {
2071
+ return new globalThis.loaders.NodeFile(url, flags, mode);
2072
+ }
2073
+ if (isBrowser) {
2074
+ throw new Error("Can't instantiate NodeFile in browser.");
2075
+ }
2076
+ throw new Error("Can't instantiate NodeFile. Make sure to import @loaders.gl/polyfills first.");
2034
2077
  }
2035
- enable() {
2036
- let enabled = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
2037
- this._storage.setConfiguration({
2038
- enabled
2039
- });
2040
- return this;
2078
+ /** Read data */
2079
+ async read(start, end) {
2080
+ throw NOT_IMPLEMENTED;
2041
2081
  }
2042
- setLevel(level) {
2043
- this._storage.setConfiguration({
2044
- level
2045
- });
2046
- return this;
2082
+ /** Write to file. The number of bytes written will be returned */
2083
+ async write(arrayBuffer, offset, length) {
2084
+ throw NOT_IMPLEMENTED;
2047
2085
  }
2048
- get(setting) {
2049
- return this._storage.config[setting];
2086
+ /** Get information about file */
2087
+ async stat() {
2088
+ throw NOT_IMPLEMENTED;
2050
2089
  }
2051
- set(setting, value) {
2052
- this._storage.setConfiguration({
2053
- [setting]: value
2054
- });
2090
+ /** Truncates the file descriptor. Only available on NodeFile. */
2091
+ async truncate(length) {
2092
+ throw NOT_IMPLEMENTED;
2055
2093
  }
2056
- settings() {
2057
- if (console.table) {
2058
- console.table(this._storage.config);
2059
- } else {
2060
- console.log(this._storage.config);
2061
- }
2094
+ /** Append data to a file. Only available on NodeFile. */
2095
+ async append(data) {
2096
+ throw NOT_IMPLEMENTED;
2062
2097
  }
2063
- assert(condition, message) {
2064
- assert3(condition, message);
2098
+ /** Close the file */
2099
+ async close() {
2065
2100
  }
2066
- warn(message) {
2067
- return this._getLogFunction(0, message, originalConsole.warn, arguments, ONCE);
2101
+ };
2102
+
2103
+ // src/javascript-utils/is-type.ts
2104
+ var isBoolean = (x) => typeof x === "boolean";
2105
+ var isFunction = (x) => typeof x === "function";
2106
+ var isObject = (x) => x !== null && typeof x === "object";
2107
+ var isPureObject = (x) => isObject(x) && x.constructor === {}.constructor;
2108
+ var isPromise = (x) => isObject(x) && isFunction(x.then);
2109
+ var isIterable = (x) => Boolean(x) && typeof x[Symbol.iterator] === "function";
2110
+ var isAsyncIterable = (x) => x && typeof x[Symbol.asyncIterator] === "function";
2111
+ var isIterator = (x) => x && isFunction(x.next);
2112
+ var isResponse = (x) => typeof Response !== "undefined" && x instanceof Response || x && x.arrayBuffer && x.text && x.json;
2113
+ var isBlob = (x) => typeof Blob !== "undefined" && x instanceof Blob;
2114
+ var isBuffer2 = (x) => x && typeof x === "object" && x.isBuffer;
2115
+ var isWritableDOMStream = (x) => isObject(x) && isFunction(x.abort) && isFunction(x.getWriter);
2116
+ var isReadableDOMStream = (x) => typeof ReadableStream !== "undefined" && x instanceof ReadableStream || isObject(x) && isFunction(x.tee) && isFunction(x.cancel) && isFunction(x.getReader);
2117
+ var isWritableNodeStream = (x) => isObject(x) && isFunction(x.end) && isFunction(x.write) && isBoolean(x.writable);
2118
+ var isReadableNodeStream = (x) => isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);
2119
+ var isReadableStream = (x) => isReadableDOMStream(x) || isReadableNodeStream(x);
2120
+ var isWritableStream = (x) => isWritableDOMStream(x) || isWritableNodeStream(x);
2121
+
2122
+ // src/lib/fetch/fetch-error.ts
2123
+ var FetchError = class extends Error {
2124
+ constructor(message, info) {
2125
+ super(message);
2126
+ this.reason = info.reason;
2127
+ this.url = info.url;
2128
+ this.response = info.response;
2129
+ }
2130
+ /** A best effort reason for why the fetch failed */
2131
+ reason;
2132
+ /** The URL that failed to load. Empty string if not available. */
2133
+ url;
2134
+ /** The Response object, if any. */
2135
+ response;
2136
+ };
2137
+
2138
+ // src/lib/utils/mime-type-utils.ts
2139
+ var DATA_URL_PATTERN = /^data:([-\w.]+\/[-\w.+]+)(;|,)/;
2140
+ var MIME_TYPE_PATTERN = /^([-\w.]+\/[-\w.+]+)/;
2141
+ function compareMIMETypes(mimeType1, mimeType2) {
2142
+ if (mimeType1.toLowerCase() === mimeType2.toLowerCase()) {
2143
+ return true;
2068
2144
  }
2069
- error(message) {
2070
- return this._getLogFunction(0, message, originalConsole.error, arguments);
2145
+ return false;
2146
+ }
2147
+ function parseMIMEType(mimeString) {
2148
+ const matches3 = MIME_TYPE_PATTERN.exec(mimeString);
2149
+ if (matches3) {
2150
+ return matches3[1];
2071
2151
  }
2072
- deprecated(oldUsage, newUsage) {
2073
- return this.warn("`".concat(oldUsage, "` is deprecated and will be removed in a later version. Use `").concat(newUsage, "` instead"));
2152
+ return mimeString;
2153
+ }
2154
+ function parseMIMETypeFromURL(url) {
2155
+ const matches3 = DATA_URL_PATTERN.exec(url);
2156
+ if (matches3) {
2157
+ return matches3[1];
2074
2158
  }
2075
- removed(oldUsage, newUsage) {
2076
- return this.error("`".concat(oldUsage, "` has been removed. Use `").concat(newUsage, "` instead"));
2159
+ return "";
2160
+ }
2161
+
2162
+ // src/lib/utils/url-utils.ts
2163
+ var QUERY_STRING_PATTERN = /\?.*/;
2164
+ function extractQueryString(url) {
2165
+ const matches3 = url.match(QUERY_STRING_PATTERN);
2166
+ return matches3 && matches3[0];
2167
+ }
2168
+ function stripQueryString(url) {
2169
+ return url.replace(QUERY_STRING_PATTERN, "");
2170
+ }
2171
+ function shortenUrlForDisplay(url) {
2172
+ if (url.length < 50) {
2173
+ return url;
2077
2174
  }
2078
- probe(logLevel, message) {
2079
- return this._getLogFunction(logLevel, message, originalConsole.log, arguments, {
2080
- time: true,
2081
- once: true
2082
- });
2175
+ const urlEnd = url.slice(url.length - 15);
2176
+ const urlStart = url.substr(0, 32);
2177
+ return `${urlStart}...${urlEnd}`;
2178
+ }
2179
+
2180
+ // src/lib/utils/resource-utils.ts
2181
+ function getResourceUrl(resource) {
2182
+ if (isResponse(resource)) {
2183
+ const response = resource;
2184
+ return response.url;
2083
2185
  }
2084
- log(logLevel, message) {
2085
- return this._getLogFunction(logLevel, message, originalConsole.debug, arguments);
2186
+ if (isBlob(resource)) {
2187
+ const blob = resource;
2188
+ return blob.name || "";
2086
2189
  }
2087
- info(logLevel, message) {
2088
- return this._getLogFunction(logLevel, message, console.info, arguments);
2190
+ if (typeof resource === "string") {
2191
+ return resource;
2089
2192
  }
2090
- once(logLevel, message) {
2091
- return this._getLogFunction(logLevel, message, originalConsole.debug || originalConsole.info, arguments, ONCE);
2193
+ return "";
2194
+ }
2195
+ function getResourceMIMEType(resource) {
2196
+ if (isResponse(resource)) {
2197
+ const response = resource;
2198
+ const contentTypeHeader = response.headers.get("content-type") || "";
2199
+ const noQueryUrl = stripQueryString(response.url);
2200
+ return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);
2092
2201
  }
2093
- table(logLevel, table, columns) {
2094
- if (table) {
2095
- return this._getLogFunction(logLevel, table, console.table || noop, columns && [columns], {
2096
- tag: getTableHeader(table)
2097
- });
2098
- }
2099
- return noop;
2202
+ if (isBlob(resource)) {
2203
+ const blob = resource;
2204
+ return blob.type || "";
2100
2205
  }
2101
- image(_ref) {
2102
- let {
2103
- logLevel,
2104
- priority,
2105
- image,
2106
- message = "",
2107
- scale = 1
2108
- } = _ref;
2109
- if (!this._shouldLog(logLevel || priority)) {
2110
- return noop;
2111
- }
2112
- return isBrowser3() ? logImageInBrowser({
2113
- image,
2114
- message,
2115
- scale
2116
- }) : logImageInNode({
2117
- image,
2118
- message,
2119
- scale
2120
- });
2206
+ if (typeof resource === "string") {
2207
+ return parseMIMETypeFromURL(resource);
2121
2208
  }
2122
- time(logLevel, message) {
2123
- return this._getLogFunction(logLevel, message, console.time ? console.time : console.info);
2209
+ return "";
2210
+ }
2211
+ function getResourceContentLength(resource) {
2212
+ if (isResponse(resource)) {
2213
+ const response = resource;
2214
+ return response.headers["content-length"] || -1;
2124
2215
  }
2125
- timeEnd(logLevel, message) {
2126
- return this._getLogFunction(logLevel, message, console.timeEnd ? console.timeEnd : console.info);
2216
+ if (isBlob(resource)) {
2217
+ const blob = resource;
2218
+ return blob.size;
2127
2219
  }
2128
- timeStamp(logLevel, message) {
2129
- return this._getLogFunction(logLevel, message, console.timeStamp || noop);
2220
+ if (typeof resource === "string") {
2221
+ return resource.length;
2130
2222
  }
2131
- group(logLevel, message) {
2132
- let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {
2133
- collapsed: false
2134
- };
2135
- const options = normalizeArguments({
2136
- logLevel,
2137
- message,
2138
- opts
2139
- });
2140
- const {
2141
- collapsed
2142
- } = opts;
2143
- options.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
2144
- return this._getLogFunction(options);
2223
+ if (resource instanceof ArrayBuffer) {
2224
+ return resource.byteLength;
2145
2225
  }
2146
- groupCollapsed(logLevel, message) {
2147
- let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
2148
- return this.group(logLevel, message, Object.assign({}, opts, {
2149
- collapsed: true
2150
- }));
2226
+ if (ArrayBuffer.isView(resource)) {
2227
+ return resource.byteLength;
2151
2228
  }
2152
- groupEnd(logLevel) {
2153
- return this._getLogFunction(logLevel, "", console.groupEnd || noop);
2229
+ return -1;
2230
+ }
2231
+
2232
+ // src/lib/utils/response-utils.ts
2233
+ async function makeResponse(resource) {
2234
+ if (isResponse(resource)) {
2235
+ return resource;
2154
2236
  }
2155
- withGroup(logLevel, message, func) {
2156
- this.group(logLevel, message)();
2157
- try {
2158
- func();
2159
- } finally {
2160
- this.groupEnd(logLevel)();
2161
- }
2237
+ const headers = {};
2238
+ const contentLength = getResourceContentLength(resource);
2239
+ if (contentLength >= 0) {
2240
+ headers["content-length"] = String(contentLength);
2162
2241
  }
2163
- trace() {
2164
- if (console.trace) {
2165
- console.trace();
2166
- }
2242
+ const url = getResourceUrl(resource);
2243
+ const type = getResourceMIMEType(resource);
2244
+ if (type) {
2245
+ headers["content-type"] = type;
2167
2246
  }
2168
- _shouldLog(logLevel) {
2169
- return this.isEnabled() && this.getLevel() >= normalizeLogLevel(logLevel);
2247
+ const initialDataUrl = await getInitialDataUrl(resource);
2248
+ if (initialDataUrl) {
2249
+ headers["x-first-bytes"] = initialDataUrl;
2170
2250
  }
2171
- _getLogFunction(logLevel, message, method, args, opts) {
2172
- if (this._shouldLog(logLevel)) {
2173
- opts = normalizeArguments({
2174
- logLevel,
2175
- message,
2176
- args,
2177
- opts
2178
- });
2179
- method = method || opts.method;
2180
- assert3(method);
2181
- opts.total = this.getTotal();
2182
- opts.delta = this.getDelta();
2183
- this._deltaTs = getHiResTimestamp2();
2184
- const tag = opts.tag || opts.message;
2185
- if (opts.once && tag) {
2186
- if (!cache[tag]) {
2187
- cache[tag] = getHiResTimestamp2();
2188
- } else {
2189
- return noop;
2190
- }
2191
- }
2192
- message = decorateMessage(this.id, opts.message, opts);
2193
- return method.bind(console, message, ...opts.args);
2194
- }
2195
- return noop;
2251
+ if (typeof resource === "string") {
2252
+ resource = new TextEncoder().encode(resource);
2196
2253
  }
2197
- };
2198
- _defineProperty(Log, "VERSION", VERSION3);
2199
- function normalizeLogLevel(logLevel) {
2200
- if (!logLevel) {
2201
- return 0;
2254
+ const response = new Response(resource, { headers });
2255
+ Object.defineProperty(response, "url", { value: url });
2256
+ return response;
2257
+ }
2258
+ async function checkResponse(response) {
2259
+ if (!response.ok) {
2260
+ const error = await getResponseError(response);
2261
+ throw error;
2202
2262
  }
2203
- let resolvedLevel;
2204
- switch (typeof logLevel) {
2205
- case "number":
2206
- resolvedLevel = logLevel;
2207
- break;
2208
- case "object":
2209
- resolvedLevel = logLevel.logLevel || logLevel.priority || 0;
2210
- break;
2211
- default:
2212
- return 0;
2263
+ }
2264
+ async function getResponseError(response) {
2265
+ const shortUrl = shortenUrlForDisplay(response.url);
2266
+ let message = `Failed to fetch resource (${response.status}) ${response.statusText}: ${shortUrl}`;
2267
+ message = message.length > 100 ? `${message.slice(0, 100)}...` : message;
2268
+ const info = {
2269
+ reason: response.statusText,
2270
+ url: response.url,
2271
+ response
2272
+ };
2273
+ try {
2274
+ const contentType = response.headers.get("Content-Type");
2275
+ info.reason = contentType?.includes("application/json") ? await response.json() : response.text();
2276
+ } catch (error) {
2213
2277
  }
2214
- assert3(Number.isFinite(resolvedLevel) && resolvedLevel >= 0);
2215
- return resolvedLevel;
2278
+ return new FetchError(message, info);
2216
2279
  }
2217
- function normalizeArguments(opts) {
2218
- const {
2219
- logLevel,
2220
- message
2221
- } = opts;
2222
- opts.logLevel = normalizeLogLevel(logLevel);
2223
- const args = opts.args ? Array.from(opts.args) : [];
2224
- while (args.length && args.shift() !== message) {
2280
+ async function getInitialDataUrl(resource) {
2281
+ const INITIAL_DATA_LENGTH = 5;
2282
+ if (typeof resource === "string") {
2283
+ return `data:,${resource.slice(0, INITIAL_DATA_LENGTH)}`;
2225
2284
  }
2226
- switch (typeof logLevel) {
2227
- case "string":
2228
- case "function":
2229
- if (message !== void 0) {
2230
- args.unshift(message);
2231
- }
2232
- opts.message = logLevel;
2233
- break;
2234
- case "object":
2235
- Object.assign(opts, logLevel);
2236
- break;
2237
- default:
2285
+ if (resource instanceof Blob) {
2286
+ const blobSlice = resource.slice(0, 5);
2287
+ return await new Promise((resolve2) => {
2288
+ const reader = new FileReader();
2289
+ reader.onload = (event) => resolve2(event?.target?.result);
2290
+ reader.readAsDataURL(blobSlice);
2291
+ });
2238
2292
  }
2239
- if (typeof opts.message === "function") {
2240
- opts.message = opts.message();
2293
+ if (resource instanceof ArrayBuffer) {
2294
+ const slice = resource.slice(0, INITIAL_DATA_LENGTH);
2295
+ const base64 = arrayBufferToBase64(slice);
2296
+ return `data:base64,${base64}`;
2241
2297
  }
2242
- const messageType = typeof opts.message;
2243
- assert3(messageType === "string" || messageType === "object");
2244
- return Object.assign(opts, {
2245
- args
2246
- }, opts.opts);
2298
+ return null;
2247
2299
  }
2248
- function decorateMessage(id, message, opts) {
2249
- if (typeof message === "string") {
2250
- const time = opts.time ? leftPad(formatTime(opts.total)) : "";
2251
- message = opts.time ? "".concat(id, ": ").concat(time, " ").concat(message) : "".concat(id, ": ").concat(message);
2252
- message = addColor(message, opts.color, opts.background);
2300
+ function arrayBufferToBase64(buffer) {
2301
+ let binary = "";
2302
+ const bytes = new Uint8Array(buffer);
2303
+ for (let i = 0; i < bytes.byteLength; i++) {
2304
+ binary += String.fromCharCode(bytes[i]);
2253
2305
  }
2254
- return message;
2306
+ return btoa(binary);
2255
2307
  }
2256
- function logImageInNode(_ref2) {
2257
- let {
2258
- image,
2259
- message = "",
2260
- scale = 1
2261
- } = _ref2;
2262
- console.warn("removed");
2263
- return noop;
2308
+
2309
+ // src/lib/fetch/fetch-file.ts
2310
+ function isNodePath(url) {
2311
+ return !isRequestURL(url) && !isDataURL(url);
2264
2312
  }
2265
- function logImageInBrowser(_ref3) {
2266
- let {
2267
- image,
2268
- message = "",
2269
- scale = 1
2270
- } = _ref3;
2271
- if (typeof image === "string") {
2272
- const img = new Image();
2273
- img.onload = () => {
2274
- const args = formatImage(img, message, scale);
2275
- console.log(...args);
2276
- };
2277
- img.src = image;
2278
- return noop;
2279
- }
2280
- const element = image.nodeName || "";
2281
- if (element.toLowerCase() === "img") {
2282
- console.log(...formatImage(image, message, scale));
2283
- return noop;
2284
- }
2285
- if (element.toLowerCase() === "canvas") {
2286
- const img = new Image();
2287
- img.onload = () => console.log(...formatImage(img, message, scale));
2288
- img.src = image.toDataURL();
2289
- return noop;
2290
- }
2291
- return noop;
2313
+ function isRequestURL(url) {
2314
+ return url.startsWith("http:") || url.startsWith("https:");
2292
2315
  }
2293
- function getTableHeader(table) {
2294
- for (const key in table) {
2295
- for (const title in table[key]) {
2296
- return title || "untitled";
2316
+ function isDataURL(url) {
2317
+ return url.startsWith("data:");
2318
+ }
2319
+ async function fetchFile(urlOrData, fetchOptions) {
2320
+ if (typeof urlOrData === "string") {
2321
+ const url = resolvePath(urlOrData);
2322
+ if (isNodePath(url)) {
2323
+ if (globalThis.loaders?.fetchNode) {
2324
+ return globalThis.loaders?.fetchNode(url, fetchOptions);
2325
+ }
2297
2326
  }
2327
+ return await fetch(url, fetchOptions);
2298
2328
  }
2299
- return "empty";
2329
+ return await makeResponse(urlOrData);
2300
2330
  }
2301
2331
 
2302
- // ../../node_modules/@probe.gl/log/dist/index.js
2303
- var dist_default = new Log({
2304
- id: "@probe.gl/log"
2305
- });
2332
+ // src/lib/fetch/read-array-buffer.ts
2333
+ async function readArrayBuffer(file, start, length) {
2334
+ if (!(file instanceof Blob)) {
2335
+ file = new Blob([file]);
2336
+ }
2337
+ const slice = file.slice(start, start + length);
2338
+ return await readBlob(slice);
2339
+ }
2340
+ async function readBlob(blob) {
2341
+ return await new Promise((resolve2, reject) => {
2342
+ const fileReader = new FileReader();
2343
+ fileReader.onload = (event) => resolve2(event?.target?.result);
2344
+ fileReader.onerror = (error) => reject(error);
2345
+ fileReader.readAsArrayBuffer(blob);
2346
+ });
2347
+ }
2306
2348
 
2307
2349
  // src/lib/loader-utils/loggers.ts
2308
2350
  var probeLog = new Log({ id: "loaders.gl" });
@@ -2410,6 +2452,7 @@ var __exports__ = (() => {
2410
2452
  const state = getGlobalLoaderState();
2411
2453
  const globalOptions = getGlobalLoaderOptions();
2412
2454
  state.globalOptions = normalizeOptionsInternal(globalOptions, options);
2455
+ registerJSModules(options.modules);
2413
2456
  }
2414
2457
  function normalizeOptions(options, loader, loaders, url) {
2415
2458
  loaders = loaders || [];
@@ -2662,10 +2705,10 @@ var __exports__ = (() => {
2662
2705
  }
2663
2706
  function findLoaderByMIMEType(loaders, mimeType) {
2664
2707
  for (const loader of loaders) {
2665
- if (loader.mimeTypes && loader.mimeTypes.includes(mimeType)) {
2708
+ if (loader.mimeTypes?.some((mimeType1) => compareMIMETypes(mimeType, mimeType1))) {
2666
2709
  return loader;
2667
2710
  }
2668
- if (mimeType === `application/x.${loader.id}`) {
2711
+ if (compareMIMETypes(mimeType, `application/x.${loader.id}`)) {
2669
2712
  return loader;
2670
2713
  }
2671
2714
  }
@@ -3024,7 +3067,7 @@ var __exports__ = (() => {
3024
3067
  if (loaderWithParser.parse) {
3025
3068
  return await loaderWithParser.parse(data, options, context);
3026
3069
  }
3027
- assert2(!loaderWithParser.parseSync);
3070
+ assert3(!loaderWithParser.parseSync);
3028
3071
  throw new Error(`${loader.id} loader - no parser found and worker is disabled`);
3029
3072
  }
3030
3073
 
@@ -3405,6 +3448,8 @@ var __exports__ = (() => {
3405
3448
  // src/null-loader.ts
3406
3449
  var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3407
3450
  var NullWorkerLoader = {
3451
+ dataType: null,
3452
+ batchType: null,
3408
3453
  name: "Null loader",
3409
3454
  id: "null",
3410
3455
  module: "core",
@@ -3418,6 +3463,8 @@ var __exports__ = (() => {
3418
3463
  }
3419
3464
  };
3420
3465
  var NullLoader = {
3466
+ dataType: null,
3467
+ batchType: null,
3421
3468
  name: "Null loader",
3422
3469
  id: "null",
3423
3470
  module: "core",