@loaders.gl/core 4.2.0-alpha.4 → 4.2.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core-addons/write-file-browser.js +62 -1
- package/dist/dist.dev.js +366 -301
- package/dist/dist.min.js +15 -0
- package/dist/index.cjs +60 -71
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +20 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -1
- package/dist/iterators/batch-iterators/timed-batch-iterator.js +18 -13
- package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts +1 -1
- package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts.map +1 -1
- package/dist/iterators/make-iterator/make-array-buffer-iterator.js +21 -15
- package/dist/iterators/make-iterator/make-blob-iterator.d.ts +1 -1
- package/dist/iterators/make-iterator/make-blob-iterator.d.ts.map +1 -1
- package/dist/iterators/make-iterator/make-blob-iterator.js +18 -10
- package/dist/iterators/make-iterator/make-iterator.d.ts +1 -1
- package/dist/iterators/make-iterator/make-iterator.d.ts.map +1 -1
- package/dist/iterators/make-iterator/make-iterator.js +29 -18
- package/dist/iterators/make-iterator/make-stream-iterator.js +86 -23
- package/dist/iterators/make-iterator/make-string-iterator.d.ts +1 -1
- package/dist/iterators/make-iterator/make-string-iterator.d.ts.map +1 -1
- package/dist/iterators/make-iterator/make-string-iterator.js +20 -10
- package/dist/iterators/make-stream/make-stream.js +47 -29
- package/dist/javascript-utils/is-type.js +25 -19
- package/dist/lib/api/encode-table.js +40 -35
- package/dist/lib/api/encode.js +112 -73
- package/dist/lib/api/load-in-batches.js +35 -21
- package/dist/lib/api/load.js +35 -20
- package/dist/lib/api/loader-options.d.ts +2 -2
- package/dist/lib/api/loader-options.d.ts.map +1 -1
- package/dist/lib/api/loader-options.js +3 -1
- package/dist/lib/api/parse-in-batches.js +106 -69
- package/dist/lib/api/parse-sync.js +42 -33
- package/dist/lib/api/parse.js +73 -61
- package/dist/lib/api/register-loaders.js +23 -14
- package/dist/lib/api/select-loader.js +216 -163
- package/dist/lib/common.js +3 -1
- package/dist/lib/fetch/fetch-error-message.js +17 -12
- package/dist/lib/fetch/fetch-file.js +26 -15
- package/dist/lib/fetch/read-array-buffer.js +30 -15
- package/dist/lib/filesystems/browser-filesystem.js +127 -69
- package/dist/lib/filesystems/read-array-buffer.js +14 -6
- package/dist/lib/init.js +13 -7
- package/dist/lib/loader-utils/check-errors.js +37 -16
- package/dist/lib/loader-utils/get-data.js +110 -88
- package/dist/lib/loader-utils/get-fetch-function.js +24 -13
- package/dist/lib/loader-utils/loader-context.js +50 -31
- package/dist/lib/loader-utils/loggers.js +35 -44
- package/dist/lib/loader-utils/normalize-loader.js +45 -32
- package/dist/lib/loader-utils/option-defaults.js +38 -34
- package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
- package/dist/lib/loader-utils/option-utils.js +133 -80
- package/dist/lib/progress/fetch-progress.js +54 -47
- package/dist/lib/utils/log.js +4 -4
- package/dist/lib/utils/mime-type-utils.js +34 -11
- package/dist/lib/utils/resource-utils.js +77 -45
- package/dist/lib/utils/response-utils.js +97 -74
- package/dist/lib/utils/url-utils.js +6 -4
- package/dist/null-loader.js +44 -30
- package/dist/null-worker-node.js +4 -2
- package/dist/null-worker.js +4 -2
- package/dist/workers/null-worker-node.js +3 -1
- package/dist/workers/null-worker.js +3 -1
- package/package.json +12 -11
- package/src/lib/api/parse-in-batches.ts +6 -5
- package/src/lib/loader-utils/option-utils.ts +3 -1
- package/src/lib/utils/resource-utils.ts +1 -1
- package/dist/core-addons/README.md +0 -1
- package/dist/core-addons/write-file-browser.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/iterators/batch-iterators/timed-batch-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-array-buffer-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-blob-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-stream-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-string-iterator.js.map +0 -1
- package/dist/iterators/make-stream/make-stream.js.map +0 -1
- package/dist/javascript-utils/is-type.js.map +0 -1
- package/dist/lib/api/encode-table.js.map +0 -1
- package/dist/lib/api/encode.js.map +0 -1
- package/dist/lib/api/load-in-batches.js.map +0 -1
- package/dist/lib/api/load.js.map +0 -1
- package/dist/lib/api/loader-options.js.map +0 -1
- package/dist/lib/api/parse-in-batches.js.map +0 -1
- package/dist/lib/api/parse-sync.js.map +0 -1
- package/dist/lib/api/parse.js.map +0 -1
- package/dist/lib/api/register-loaders.js.map +0 -1
- package/dist/lib/api/select-loader.js.map +0 -1
- package/dist/lib/common.js.map +0 -1
- package/dist/lib/fetch/fetch-error-message.js.map +0 -1
- package/dist/lib/fetch/fetch-file.js.map +0 -1
- package/dist/lib/fetch/read-array-buffer.js.map +0 -1
- package/dist/lib/filesystems/browser-filesystem.js.map +0 -1
- package/dist/lib/filesystems/read-array-buffer.js.map +0 -1
- package/dist/lib/init.js.map +0 -1
- package/dist/lib/loader-utils/check-errors.js.map +0 -1
- package/dist/lib/loader-utils/get-data.js.map +0 -1
- package/dist/lib/loader-utils/get-fetch-function.js.map +0 -1
- package/dist/lib/loader-utils/loader-context.js.map +0 -1
- package/dist/lib/loader-utils/loggers.js.map +0 -1
- package/dist/lib/loader-utils/normalize-loader.js.map +0 -1
- package/dist/lib/loader-utils/option-defaults.js.map +0 -1
- package/dist/lib/loader-utils/option-utils.js.map +0 -1
- package/dist/lib/progress/fetch-progress.js.map +0 -1
- package/dist/lib/utils/log.js.map +0 -1
- package/dist/lib/utils/mime-type-utils.js.map +0 -1
- package/dist/lib/utils/resource-utils.js.map +0 -1
- package/dist/lib/utils/response-utils.js.map +0 -1
- package/dist/lib/utils/url-utils.js.map +0 -1
- package/dist/null-loader.js.map +0 -1
- package/dist/workers/null-worker-node.js.map +0 -1
- package/dist/workers/null-worker.js.map +0 -1
package/dist/dist.dev.js
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
if (typeof exports === 'object' && typeof module === 'object')
|
|
3
3
|
module.exports = factory();
|
|
4
4
|
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
|
-
else if (typeof exports === 'object') exports['
|
|
6
|
-
else root['
|
|
5
|
+
else if (typeof exports === 'object') exports['loaders'] = factory();
|
|
6
|
+
else root['loaders'] = factory();})(globalThis, function () {
|
|
7
7
|
"use strict";
|
|
8
8
|
var __exports__ = (() => {
|
|
9
9
|
var __defProp = Object.defineProperty;
|
|
10
10
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
11
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
12
12
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
14
|
var __export = (target, all) => {
|
|
14
15
|
for (var name in all)
|
|
15
16
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -23,10 +24,14 @@ var __exports__ = (() => {
|
|
|
23
24
|
return to;
|
|
24
25
|
};
|
|
25
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var __publicField = (obj, key, value) => {
|
|
28
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
29
|
+
return value;
|
|
30
|
+
};
|
|
26
31
|
|
|
27
|
-
//
|
|
28
|
-
var
|
|
29
|
-
__export(
|
|
32
|
+
// bundle.ts
|
|
33
|
+
var bundle_exports = {};
|
|
34
|
+
__export(bundle_exports, {
|
|
30
35
|
JSONLoader: () => JSONLoader,
|
|
31
36
|
NullLoader: () => NullLoader,
|
|
32
37
|
NullWorkerLoader: () => NullWorkerLoader,
|
|
@@ -101,7 +106,10 @@ var __exports__ = (() => {
|
|
|
101
106
|
var window_ = globals.window || globals.self || globals.global || {};
|
|
102
107
|
var global_ = globals.global || globals.self || globals.window || {};
|
|
103
108
|
var document_ = globals.document || {};
|
|
104
|
-
var isBrowser =
|
|
109
|
+
var isBrowser = (
|
|
110
|
+
// @ts-ignore process does not exist on browser
|
|
111
|
+
Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser)
|
|
112
|
+
);
|
|
105
113
|
var isWorker = typeof importScripts === "function";
|
|
106
114
|
var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
107
115
|
var nodeVersion = matches && parseFloat(matches[1]) || 0;
|
|
@@ -114,12 +122,14 @@ var __exports__ = (() => {
|
|
|
114
122
|
if (level > 3) {
|
|
115
123
|
return newOptions;
|
|
116
124
|
}
|
|
117
|
-
const options = {
|
|
118
|
-
...baseOptions
|
|
119
|
-
};
|
|
125
|
+
const options = { ...baseOptions };
|
|
120
126
|
for (const [key, newValue] of Object.entries(newOptions)) {
|
|
121
127
|
if (newValue && typeof newValue === "object" && !Array.isArray(newValue)) {
|
|
122
|
-
options[key] = mergeOptionsRecursively(
|
|
128
|
+
options[key] = mergeOptionsRecursively(
|
|
129
|
+
options[key] || {},
|
|
130
|
+
newOptions[key],
|
|
131
|
+
level + 1
|
|
132
|
+
);
|
|
123
133
|
} else {
|
|
124
134
|
options[key] = newOptions[key];
|
|
125
135
|
}
|
|
@@ -132,11 +142,13 @@ var __exports__ = (() => {
|
|
|
132
142
|
function getVersion() {
|
|
133
143
|
if (!globalThis._loadersgl_?.version) {
|
|
134
144
|
globalThis._loadersgl_ = globalThis._loadersgl_ || {};
|
|
135
|
-
if (
|
|
136
|
-
console.warn(
|
|
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
|
+
);
|
|
137
149
|
globalThis._loadersgl_.version = NPM_TAG;
|
|
138
150
|
} else {
|
|
139
|
-
globalThis._loadersgl_.version =
|
|
151
|
+
globalThis._loadersgl_.version = __VERSION__;
|
|
140
152
|
}
|
|
141
153
|
}
|
|
142
154
|
return globalThis._loadersgl_.version;
|
|
@@ -161,14 +173,21 @@ var __exports__ = (() => {
|
|
|
161
173
|
var window_2 = globals2.window || globals2.self || globals2.global || {};
|
|
162
174
|
var global_2 = globals2.global || globals2.self || globals2.window || {};
|
|
163
175
|
var document_2 = globals2.document || {};
|
|
164
|
-
var isBrowser2 =
|
|
176
|
+
var isBrowser2 = (
|
|
177
|
+
// @ts-ignore process.browser
|
|
178
|
+
typeof process !== "object" || String(process) !== "[object process]" || process.browser
|
|
179
|
+
);
|
|
165
180
|
var isMobile = typeof window !== "undefined" && typeof window.orientation !== "undefined";
|
|
166
181
|
var matches2 = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
167
182
|
var nodeVersion2 = matches2 && parseFloat(matches2[1]) || 0;
|
|
168
183
|
|
|
169
184
|
// ../worker-utils/src/lib/worker-farm/worker-job.ts
|
|
170
185
|
var WorkerJob = class {
|
|
186
|
+
name;
|
|
187
|
+
workerThread;
|
|
171
188
|
isRunning = true;
|
|
189
|
+
/** Promise that resolves when Job is done */
|
|
190
|
+
result;
|
|
172
191
|
_resolve = () => {
|
|
173
192
|
};
|
|
174
193
|
_reject = () => {
|
|
@@ -181,18 +200,29 @@ var __exports__ = (() => {
|
|
|
181
200
|
this._reject = reject;
|
|
182
201
|
});
|
|
183
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Send a message to the job's worker thread
|
|
205
|
+
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
206
|
+
*/
|
|
184
207
|
postMessage(type, payload) {
|
|
185
208
|
this.workerThread.postMessage({
|
|
186
209
|
source: "loaders.gl",
|
|
210
|
+
// Lets worker ignore unrelated messages
|
|
187
211
|
type,
|
|
188
212
|
payload
|
|
189
213
|
});
|
|
190
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Call to resolve the `result` Promise with the supplied value
|
|
217
|
+
*/
|
|
191
218
|
done(value) {
|
|
192
219
|
assert2(this.isRunning);
|
|
193
220
|
this.isRunning = false;
|
|
194
221
|
this._resolve(value);
|
|
195
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Call to reject the `result` Promise with the supplied error
|
|
225
|
+
*/
|
|
196
226
|
error(error) {
|
|
197
227
|
assert2(this.isRunning);
|
|
198
228
|
this.isRunning = false;
|
|
@@ -232,9 +262,7 @@ var __exports__ = (() => {
|
|
|
232
262
|
return getLoadableWorkerURLFromSource(workerSource);
|
|
233
263
|
}
|
|
234
264
|
function getLoadableWorkerURLFromSource(workerSource) {
|
|
235
|
-
const blob = new Blob([workerSource], {
|
|
236
|
-
type: "application/javascript"
|
|
237
|
-
});
|
|
265
|
+
const blob = new Blob([workerSource], { type: "application/javascript" });
|
|
238
266
|
return URL.createObjectURL(blob);
|
|
239
267
|
}
|
|
240
268
|
function buildScriptSource(workerUrl) {
|
|
@@ -301,17 +329,20 @@ var __exports__ = (() => {
|
|
|
301
329
|
var NOOP = () => {
|
|
302
330
|
};
|
|
303
331
|
var WorkerThread = class {
|
|
332
|
+
name;
|
|
333
|
+
source;
|
|
334
|
+
url;
|
|
304
335
|
terminated = false;
|
|
336
|
+
worker;
|
|
337
|
+
onMessage;
|
|
338
|
+
onError;
|
|
305
339
|
_loadableURL = "";
|
|
340
|
+
/** Checks if workers are supported on this platform */
|
|
306
341
|
static isSupported() {
|
|
307
342
|
return typeof Worker !== "undefined" && isBrowser2 || typeof NodeWorker !== "undefined" && !isBrowser2;
|
|
308
343
|
}
|
|
309
344
|
constructor(props) {
|
|
310
|
-
const {
|
|
311
|
-
name,
|
|
312
|
-
source,
|
|
313
|
-
url
|
|
314
|
-
} = props;
|
|
345
|
+
const { name, source, url } = props;
|
|
315
346
|
assert2(source || url);
|
|
316
347
|
this.name = name;
|
|
317
348
|
this.source = source;
|
|
@@ -320,6 +351,10 @@ var __exports__ = (() => {
|
|
|
320
351
|
this.onError = (error) => console.log(error);
|
|
321
352
|
this.worker = isBrowser2 ? this._createBrowserWorker() : this._createNodeWorker();
|
|
322
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* Terminate this worker thread
|
|
356
|
+
* @note Can free up significant memory
|
|
357
|
+
*/
|
|
323
358
|
destroy() {
|
|
324
359
|
this.onMessage = NOOP;
|
|
325
360
|
this.onError = NOOP;
|
|
@@ -329,10 +364,20 @@ var __exports__ = (() => {
|
|
|
329
364
|
get isRunning() {
|
|
330
365
|
return Boolean(this.onMessage);
|
|
331
366
|
}
|
|
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
|
+
*/
|
|
332
372
|
postMessage(data, transferList) {
|
|
333
373
|
transferList = transferList || getTransferList(data);
|
|
334
374
|
this.worker.postMessage(data, transferList);
|
|
335
375
|
}
|
|
376
|
+
// PRIVATE
|
|
377
|
+
/**
|
|
378
|
+
* Generate a standard Error from an ErrorEvent
|
|
379
|
+
* @param event
|
|
380
|
+
*/
|
|
336
381
|
_getErrorFromErrorEvent(event) {
|
|
337
382
|
let message = "Failed to load ";
|
|
338
383
|
message += `worker ${this.name} from ${this.url}. `;
|
|
@@ -344,14 +389,12 @@ var __exports__ = (() => {
|
|
|
344
389
|
}
|
|
345
390
|
return new Error(message);
|
|
346
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* Creates a worker thread on the browser
|
|
394
|
+
*/
|
|
347
395
|
_createBrowserWorker() {
|
|
348
|
-
this._loadableURL = getLoadableWorkerURL({
|
|
349
|
-
|
|
350
|
-
url: this.url
|
|
351
|
-
});
|
|
352
|
-
const worker = new Worker(this._loadableURL, {
|
|
353
|
-
name: this.name
|
|
354
|
-
});
|
|
396
|
+
this._loadableURL = getLoadableWorkerURL({ source: this.source, url: this.url });
|
|
397
|
+
const worker = new Worker(this._loadableURL, { name: this.name });
|
|
355
398
|
worker.onmessage = (event) => {
|
|
356
399
|
if (!event.data) {
|
|
357
400
|
this.onError(new Error("No data received"));
|
|
@@ -366,18 +409,18 @@ var __exports__ = (() => {
|
|
|
366
409
|
worker.onmessageerror = (event) => console.error(event);
|
|
367
410
|
return worker;
|
|
368
411
|
}
|
|
412
|
+
/**
|
|
413
|
+
* Creates a worker thread in node.js
|
|
414
|
+
* @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool
|
|
415
|
+
*/
|
|
369
416
|
_createNodeWorker() {
|
|
370
417
|
let worker;
|
|
371
418
|
if (this.url) {
|
|
372
419
|
const absolute = this.url.includes(":/") || this.url.startsWith("/");
|
|
373
420
|
const url = absolute ? this.url : `./${this.url}`;
|
|
374
|
-
worker = new NodeWorker(url, {
|
|
375
|
-
eval: false
|
|
376
|
-
});
|
|
421
|
+
worker = new NodeWorker(url, { eval: false });
|
|
377
422
|
} else if (this.source) {
|
|
378
|
-
worker = new NodeWorker(this.source, {
|
|
379
|
-
eval: true
|
|
380
|
-
});
|
|
423
|
+
worker = new NodeWorker(this.source, { eval: true });
|
|
381
424
|
} else {
|
|
382
425
|
throw new Error("no worker");
|
|
383
426
|
}
|
|
@@ -396,6 +439,9 @@ var __exports__ = (() => {
|
|
|
396
439
|
// ../worker-utils/src/lib/worker-farm/worker-pool.ts
|
|
397
440
|
var WorkerPool = class {
|
|
398
441
|
name = "unnamed";
|
|
442
|
+
source;
|
|
443
|
+
// | Function;
|
|
444
|
+
url;
|
|
399
445
|
maxConcurrency = 1;
|
|
400
446
|
maxMobileConcurrency = 1;
|
|
401
447
|
onDebug = () => {
|
|
@@ -406,23 +452,29 @@ var __exports__ = (() => {
|
|
|
406
452
|
idleQueue = [];
|
|
407
453
|
count = 0;
|
|
408
454
|
isDestroyed = false;
|
|
455
|
+
/** Checks if workers are supported on this platform */
|
|
409
456
|
static isSupported() {
|
|
410
457
|
return WorkerThread.isSupported();
|
|
411
458
|
}
|
|
459
|
+
/**
|
|
460
|
+
* @param processor - worker function
|
|
461
|
+
* @param maxConcurrency - max count of workers
|
|
462
|
+
*/
|
|
412
463
|
constructor(props) {
|
|
413
464
|
this.source = props.source;
|
|
414
465
|
this.url = props.url;
|
|
415
466
|
this.setProps(props);
|
|
416
467
|
}
|
|
468
|
+
/**
|
|
469
|
+
* Terminates all workers in the pool
|
|
470
|
+
* @note Can free up significant memory
|
|
471
|
+
*/
|
|
417
472
|
destroy() {
|
|
418
473
|
this.idleQueue.forEach((worker) => worker.destroy());
|
|
419
474
|
this.isDestroyed = true;
|
|
420
475
|
}
|
|
421
476
|
setProps(props) {
|
|
422
|
-
this.props = {
|
|
423
|
-
...this.props,
|
|
424
|
-
...props
|
|
425
|
-
};
|
|
477
|
+
this.props = { ...this.props, ...props };
|
|
426
478
|
if (props.name !== void 0) {
|
|
427
479
|
this.name = props.name;
|
|
428
480
|
}
|
|
@@ -441,17 +493,17 @@ var __exports__ = (() => {
|
|
|
441
493
|
}
|
|
442
494
|
async startJob(name, onMessage3 = (job, type, data) => job.done(data), onError = (job, error) => job.error(error)) {
|
|
443
495
|
const startPromise = new Promise((onStart) => {
|
|
444
|
-
this.jobQueue.push({
|
|
445
|
-
name,
|
|
446
|
-
onMessage: onMessage3,
|
|
447
|
-
onError,
|
|
448
|
-
onStart
|
|
449
|
-
});
|
|
496
|
+
this.jobQueue.push({ name, onMessage: onMessage3, onError, onStart });
|
|
450
497
|
return this;
|
|
451
498
|
});
|
|
452
499
|
this._startQueuedJob();
|
|
453
500
|
return await startPromise;
|
|
454
501
|
}
|
|
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
|
+
*/
|
|
455
507
|
async _startQueuedJob() {
|
|
456
508
|
if (!this.jobQueue.length) {
|
|
457
509
|
return;
|
|
@@ -481,8 +533,23 @@ var __exports__ = (() => {
|
|
|
481
533
|
}
|
|
482
534
|
}
|
|
483
535
|
}
|
|
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
|
+
*/
|
|
484
544
|
returnWorkerToQueue(worker) {
|
|
485
|
-
const shouldDestroyWorker =
|
|
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
|
+
);
|
|
486
553
|
if (shouldDestroyWorker) {
|
|
487
554
|
worker.destroy();
|
|
488
555
|
this.count--;
|
|
@@ -493,6 +560,9 @@ var __exports__ = (() => {
|
|
|
493
560
|
this._startQueuedJob();
|
|
494
561
|
}
|
|
495
562
|
}
|
|
563
|
+
/**
|
|
564
|
+
* Returns idle worker or creates new worker if maxConcurrency has not been reached
|
|
565
|
+
*/
|
|
496
566
|
_getAvailableWorker() {
|
|
497
567
|
if (this.idleQueue.length > 0) {
|
|
498
568
|
return this.idleQueue.shift() || null;
|
|
@@ -500,11 +570,7 @@ var __exports__ = (() => {
|
|
|
500
570
|
if (this.count < this._getMaxConcurrency()) {
|
|
501
571
|
this.count++;
|
|
502
572
|
const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;
|
|
503
|
-
return new WorkerThread({
|
|
504
|
-
name,
|
|
505
|
-
source: this.source,
|
|
506
|
-
url: this.url
|
|
507
|
-
});
|
|
573
|
+
return new WorkerThread({ name, source: this.source, url: this.url });
|
|
508
574
|
}
|
|
509
575
|
return null;
|
|
510
576
|
}
|
|
@@ -521,44 +587,56 @@ var __exports__ = (() => {
|
|
|
521
587
|
onDebug: () => {
|
|
522
588
|
}
|
|
523
589
|
};
|
|
524
|
-
var
|
|
590
|
+
var _WorkerFarm = class {
|
|
591
|
+
props;
|
|
525
592
|
workerPools = /* @__PURE__ */ new Map();
|
|
593
|
+
/** Checks if workers are supported on this platform */
|
|
526
594
|
static isSupported() {
|
|
527
595
|
return WorkerThread.isSupported();
|
|
528
596
|
}
|
|
597
|
+
/** Get the singleton instance of the global worker farm */
|
|
529
598
|
static getWorkerFarm(props = {}) {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
return
|
|
599
|
+
_WorkerFarm._workerFarm = _WorkerFarm._workerFarm || new _WorkerFarm({});
|
|
600
|
+
_WorkerFarm._workerFarm.setProps(props);
|
|
601
|
+
return _WorkerFarm._workerFarm;
|
|
533
602
|
}
|
|
603
|
+
/** get global instance with WorkerFarm.getWorkerFarm() */
|
|
534
604
|
constructor(props) {
|
|
535
|
-
this.props = {
|
|
536
|
-
...DEFAULT_PROPS
|
|
537
|
-
};
|
|
605
|
+
this.props = { ...DEFAULT_PROPS };
|
|
538
606
|
this.setProps(props);
|
|
539
607
|
this.workerPools = /* @__PURE__ */ new Map();
|
|
540
608
|
}
|
|
609
|
+
/**
|
|
610
|
+
* Terminate all workers in the farm
|
|
611
|
+
* @note Can free up significant memory
|
|
612
|
+
*/
|
|
541
613
|
destroy() {
|
|
542
614
|
for (const workerPool of this.workerPools.values()) {
|
|
543
615
|
workerPool.destroy();
|
|
544
616
|
}
|
|
545
617
|
this.workerPools = /* @__PURE__ */ new Map();
|
|
546
618
|
}
|
|
619
|
+
/**
|
|
620
|
+
* Set props used when initializing worker pools
|
|
621
|
+
* @param props
|
|
622
|
+
*/
|
|
547
623
|
setProps(props) {
|
|
548
|
-
this.props = {
|
|
549
|
-
...this.props,
|
|
550
|
-
...props
|
|
551
|
-
};
|
|
624
|
+
this.props = { ...this.props, ...props };
|
|
552
625
|
for (const workerPool of this.workerPools.values()) {
|
|
553
626
|
workerPool.setProps(this._getWorkerPoolProps());
|
|
554
627
|
}
|
|
555
628
|
}
|
|
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
|
+
*/
|
|
556
638
|
getWorkerPool(options) {
|
|
557
|
-
const {
|
|
558
|
-
name,
|
|
559
|
-
source,
|
|
560
|
-
url
|
|
561
|
-
} = options;
|
|
639
|
+
const { name, source, url } = options;
|
|
562
640
|
let workerPool = this.workerPools.get(name);
|
|
563
641
|
if (!workerPool) {
|
|
564
642
|
workerPool = new WorkerPool({
|
|
@@ -580,6 +658,9 @@ var __exports__ = (() => {
|
|
|
580
658
|
};
|
|
581
659
|
}
|
|
582
660
|
};
|
|
661
|
+
var WorkerFarm = _WorkerFarm;
|
|
662
|
+
// singleton
|
|
663
|
+
__publicField(WorkerFarm, "_workerFarm");
|
|
583
664
|
|
|
584
665
|
// ../worker-utils/src/lib/worker-api/get-worker-url.ts
|
|
585
666
|
function getWorkerName(worker) {
|
|
@@ -616,24 +697,20 @@ var __exports__ = (() => {
|
|
|
616
697
|
async function processOnWorker(worker, data, options = {}, context = {}) {
|
|
617
698
|
const name = getWorkerName(worker);
|
|
618
699
|
const workerFarm = WorkerFarm.getWorkerFarm(options);
|
|
619
|
-
const {
|
|
620
|
-
|
|
621
|
-
} = options;
|
|
622
|
-
const workerPoolProps = {
|
|
623
|
-
name,
|
|
624
|
-
source
|
|
625
|
-
};
|
|
700
|
+
const { source } = options;
|
|
701
|
+
const workerPoolProps = { name, source };
|
|
626
702
|
if (!source) {
|
|
627
703
|
workerPoolProps.url = getWorkerURL(worker, options);
|
|
628
704
|
}
|
|
629
705
|
const workerPool = workerFarm.getWorkerPool(workerPoolProps);
|
|
630
706
|
const jobName = options.jobName || worker.name;
|
|
631
|
-
const job = await workerPool.startJob(
|
|
707
|
+
const job = await workerPool.startJob(
|
|
708
|
+
jobName,
|
|
709
|
+
// eslint-disable-next-line
|
|
710
|
+
onMessage.bind(null, context)
|
|
711
|
+
);
|
|
632
712
|
const transferableOptions = getTransferListForWriter(options);
|
|
633
|
-
job.postMessage("process", {
|
|
634
|
-
input: data,
|
|
635
|
-
options: transferableOptions
|
|
636
|
-
});
|
|
713
|
+
job.postMessage("process", { input: data, options: transferableOptions });
|
|
637
714
|
const result = await job.result;
|
|
638
715
|
return result.result;
|
|
639
716
|
}
|
|
@@ -646,30 +723,17 @@ var __exports__ = (() => {
|
|
|
646
723
|
job.error(new Error(payload.error));
|
|
647
724
|
break;
|
|
648
725
|
case "process":
|
|
649
|
-
const {
|
|
650
|
-
id,
|
|
651
|
-
input,
|
|
652
|
-
options
|
|
653
|
-
} = payload;
|
|
726
|
+
const { id, input, options } = payload;
|
|
654
727
|
try {
|
|
655
728
|
if (!context.process) {
|
|
656
|
-
job.postMessage("error", {
|
|
657
|
-
id,
|
|
658
|
-
error: "Worker not set up to process on main thread"
|
|
659
|
-
});
|
|
729
|
+
job.postMessage("error", { id, error: "Worker not set up to process on main thread" });
|
|
660
730
|
return;
|
|
661
731
|
}
|
|
662
732
|
const result = await context.process(input, options);
|
|
663
|
-
job.postMessage("done", {
|
|
664
|
-
id,
|
|
665
|
-
result
|
|
666
|
-
});
|
|
733
|
+
job.postMessage("done", { id, result });
|
|
667
734
|
} catch (error) {
|
|
668
735
|
const message = error instanceof Error ? error.message : "unknown error";
|
|
669
|
-
job.postMessage("error", {
|
|
670
|
-
id,
|
|
671
|
-
error: message
|
|
672
|
-
});
|
|
736
|
+
job.postMessage("error", { id, error: message });
|
|
673
737
|
}
|
|
674
738
|
break;
|
|
675
739
|
default:
|
|
@@ -701,14 +765,17 @@ var __exports__ = (() => {
|
|
|
701
765
|
const name = loader.id;
|
|
702
766
|
const url = getWorkerURL(loader, options);
|
|
703
767
|
const workerFarm = WorkerFarm.getWorkerFarm(options);
|
|
704
|
-
const workerPool = workerFarm.getWorkerPool({
|
|
705
|
-
name,
|
|
706
|
-
url
|
|
707
|
-
});
|
|
768
|
+
const workerPool = workerFarm.getWorkerPool({ name, url });
|
|
708
769
|
options = JSON.parse(JSON.stringify(options));
|
|
709
770
|
context = JSON.parse(JSON.stringify(context || {}));
|
|
710
|
-
const job = await workerPool.startJob(
|
|
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
|
+
);
|
|
711
777
|
job.postMessage("process", {
|
|
778
|
+
// @ts-ignore
|
|
712
779
|
input: data,
|
|
713
780
|
options,
|
|
714
781
|
context
|
|
@@ -725,23 +792,13 @@ var __exports__ = (() => {
|
|
|
725
792
|
job.error(new Error(payload.error));
|
|
726
793
|
break;
|
|
727
794
|
case "process":
|
|
728
|
-
const {
|
|
729
|
-
id,
|
|
730
|
-
input,
|
|
731
|
-
options
|
|
732
|
-
} = payload;
|
|
795
|
+
const { id, input, options } = payload;
|
|
733
796
|
try {
|
|
734
797
|
const result = await parseOnMainThread(input, options);
|
|
735
|
-
job.postMessage("done", {
|
|
736
|
-
id,
|
|
737
|
-
result
|
|
738
|
-
});
|
|
798
|
+
job.postMessage("done", { id, result });
|
|
739
799
|
} catch (error) {
|
|
740
800
|
const message = error instanceof Error ? error.message : "unknown error";
|
|
741
|
-
job.postMessage("error", {
|
|
742
|
-
id,
|
|
743
|
-
error: message
|
|
744
|
-
});
|
|
801
|
+
job.postMessage("error", { id, error: message });
|
|
745
802
|
}
|
|
746
803
|
break;
|
|
747
804
|
default:
|
|
@@ -779,7 +836,9 @@ var __exports__ = (() => {
|
|
|
779
836
|
return concatenateArrayBuffersFromArray(sources);
|
|
780
837
|
}
|
|
781
838
|
function concatenateArrayBuffersFromArray(sources) {
|
|
782
|
-
const sourceArrays = sources.map(
|
|
839
|
+
const sourceArrays = sources.map(
|
|
840
|
+
(source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
|
|
841
|
+
);
|
|
783
842
|
const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
|
|
784
843
|
const result = new Uint8Array(byteLength);
|
|
785
844
|
let offset = 0;
|
|
@@ -794,9 +853,7 @@ var __exports__ = (() => {
|
|
|
794
853
|
async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
|
|
795
854
|
const textDecoder = new TextDecoder(void 0, options);
|
|
796
855
|
for await (const arrayBuffer of arrayBufferIterator) {
|
|
797
|
-
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, {
|
|
798
|
-
stream: true
|
|
799
|
-
});
|
|
856
|
+
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, { stream: true });
|
|
800
857
|
}
|
|
801
858
|
}
|
|
802
859
|
async function* makeTextEncoderIterator(textIterator) {
|
|
@@ -823,10 +880,7 @@ var __exports__ = (() => {
|
|
|
823
880
|
async function* makeNumberedLineIterator(lineIterator) {
|
|
824
881
|
let counter = 1;
|
|
825
882
|
for await (const line of lineIterator) {
|
|
826
|
-
yield {
|
|
827
|
-
counter,
|
|
828
|
-
line
|
|
829
|
-
};
|
|
883
|
+
yield { counter, line };
|
|
830
884
|
counter++;
|
|
831
885
|
}
|
|
832
886
|
}
|
|
@@ -834,10 +888,7 @@ var __exports__ = (() => {
|
|
|
834
888
|
// ../loader-utils/src/lib/iterators/async-iteration.ts
|
|
835
889
|
async function forEach(iterator, visitor) {
|
|
836
890
|
while (true) {
|
|
837
|
-
const {
|
|
838
|
-
done,
|
|
839
|
-
value
|
|
840
|
-
} = await iterator.next();
|
|
891
|
+
const { done, value } = await iterator.next();
|
|
841
892
|
if (done) {
|
|
842
893
|
iterator.return();
|
|
843
894
|
return;
|
|
@@ -902,7 +953,7 @@ var __exports__ = (() => {
|
|
|
902
953
|
return obj;
|
|
903
954
|
}
|
|
904
955
|
|
|
905
|
-
//
|
|
956
|
+
// ../../node_modules/@probe.gl/stats/dist/utils/hi-res-timestamp.js
|
|
906
957
|
function getHiResTimestamp() {
|
|
907
958
|
let timestamp;
|
|
908
959
|
if (typeof window !== "undefined" && window.performance) {
|
|
@@ -916,7 +967,7 @@ var __exports__ = (() => {
|
|
|
916
967
|
return timestamp;
|
|
917
968
|
}
|
|
918
969
|
|
|
919
|
-
//
|
|
970
|
+
// ../../node_modules/@probe.gl/stats/dist/lib/stat.js
|
|
920
971
|
var Stat = class {
|
|
921
972
|
constructor(name, type) {
|
|
922
973
|
_defineProperty(this, "name", void 0);
|
|
@@ -1028,7 +1079,7 @@ var __exports__ = (() => {
|
|
|
1028
1079
|
}
|
|
1029
1080
|
};
|
|
1030
1081
|
|
|
1031
|
-
//
|
|
1082
|
+
// ../../node_modules/@probe.gl/stats/dist/lib/stats.js
|
|
1032
1083
|
var Stats = class {
|
|
1033
1084
|
constructor(options) {
|
|
1034
1085
|
_defineProperty(this, "id", void 0);
|
|
@@ -1101,43 +1152,58 @@ var __exports__ = (() => {
|
|
|
1101
1152
|
var STAT_ACTIVE_REQUESTS_EVER = "Active Requests Ever";
|
|
1102
1153
|
var DEFAULT_PROPS2 = {
|
|
1103
1154
|
id: "request-scheduler",
|
|
1155
|
+
/** Specifies if the request scheduler should throttle incoming requests, mainly for comparative testing. */
|
|
1104
1156
|
throttleRequests: true,
|
|
1105
|
-
|
|
1157
|
+
/** The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit. */
|
|
1158
|
+
maxRequests: 6,
|
|
1159
|
+
/**
|
|
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.
|
|
1162
|
+
*/
|
|
1163
|
+
debounceTime: 0
|
|
1106
1164
|
};
|
|
1107
1165
|
var RequestScheduler = class {
|
|
1166
|
+
props;
|
|
1167
|
+
stats;
|
|
1108
1168
|
activeRequestCount = 0;
|
|
1169
|
+
/** Tracks the number of active requests and prioritizes/cancels queued requests. */
|
|
1109
1170
|
requestQueue = [];
|
|
1110
1171
|
requestMap = /* @__PURE__ */ new Map();
|
|
1111
|
-
|
|
1172
|
+
updateTimer = null;
|
|
1112
1173
|
constructor(props = {}) {
|
|
1113
|
-
this.props = {
|
|
1114
|
-
|
|
1115
|
-
...props
|
|
1116
|
-
};
|
|
1117
|
-
this.stats = new Stats({
|
|
1118
|
-
id: this.props.id
|
|
1119
|
-
});
|
|
1174
|
+
this.props = { ...DEFAULT_PROPS2, ...props };
|
|
1175
|
+
this.stats = new Stats({ id: this.props.id });
|
|
1120
1176
|
this.stats.get(STAT_QUEUED_REQUESTS);
|
|
1121
1177
|
this.stats.get(STAT_ACTIVE_REQUESTS);
|
|
1122
1178
|
this.stats.get(STAT_CANCELLED_REQUESTS);
|
|
1123
1179
|
this.stats.get(STAT_QUEUED_REQUESTS_EVER);
|
|
1124
1180
|
this.stats.get(STAT_ACTIVE_REQUESTS_EVER);
|
|
1125
1181
|
}
|
|
1182
|
+
/**
|
|
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
|
|
1197
|
+
*/
|
|
1126
1198
|
scheduleRequest(handle, getPriority = () => 0) {
|
|
1127
1199
|
if (!this.props.throttleRequests) {
|
|
1128
|
-
return Promise.resolve({
|
|
1129
|
-
|
|
1130
|
-
}
|
|
1131
|
-
});
|
|
1200
|
+
return Promise.resolve({ done: () => {
|
|
1201
|
+
} });
|
|
1132
1202
|
}
|
|
1133
1203
|
if (this.requestMap.has(handle)) {
|
|
1134
1204
|
return this.requestMap.get(handle);
|
|
1135
1205
|
}
|
|
1136
|
-
const request = {
|
|
1137
|
-
handle,
|
|
1138
|
-
priority: 0,
|
|
1139
|
-
getPriority
|
|
1140
|
-
};
|
|
1206
|
+
const request = { handle, priority: 0, getPriority };
|
|
1141
1207
|
const promise = new Promise((resolve2) => {
|
|
1142
1208
|
request.resolve = resolve2;
|
|
1143
1209
|
return request;
|
|
@@ -1147,11 +1213,9 @@ var __exports__ = (() => {
|
|
|
1147
1213
|
this._issueNewRequests();
|
|
1148
1214
|
return promise;
|
|
1149
1215
|
}
|
|
1216
|
+
// PRIVATE
|
|
1150
1217
|
_issueRequest(request) {
|
|
1151
|
-
const {
|
|
1152
|
-
handle,
|
|
1153
|
-
resolve: resolve2
|
|
1154
|
-
} = request;
|
|
1218
|
+
const { handle, resolve: resolve2 } = request;
|
|
1155
1219
|
let isDone = false;
|
|
1156
1220
|
const done = () => {
|
|
1157
1221
|
if (!isDone) {
|
|
@@ -1162,19 +1226,21 @@ var __exports__ = (() => {
|
|
|
1162
1226
|
}
|
|
1163
1227
|
};
|
|
1164
1228
|
this.activeRequestCount++;
|
|
1165
|
-
return resolve2 ? resolve2({
|
|
1166
|
-
done
|
|
1167
|
-
}) : Promise.resolve({
|
|
1168
|
-
done
|
|
1169
|
-
});
|
|
1229
|
+
return resolve2 ? resolve2({ done }) : Promise.resolve({ done });
|
|
1170
1230
|
}
|
|
1231
|
+
/** We check requests asynchronously, to prevent multiple updates */
|
|
1171
1232
|
_issueNewRequests() {
|
|
1172
|
-
if (
|
|
1173
|
-
|
|
1233
|
+
if (this.updateTimer !== null) {
|
|
1234
|
+
clearTimeout(this.updateTimer);
|
|
1174
1235
|
}
|
|
1236
|
+
this.updateTimer = setTimeout(() => this._issueNewRequestsAsync(), this.props.debounceTime);
|
|
1175
1237
|
}
|
|
1238
|
+
/** Refresh all requests */
|
|
1176
1239
|
_issueNewRequestsAsync() {
|
|
1177
|
-
this.
|
|
1240
|
+
if (this.updateTimer !== null) {
|
|
1241
|
+
clearTimeout(this.updateTimer);
|
|
1242
|
+
}
|
|
1243
|
+
this.updateTimer = null;
|
|
1178
1244
|
const freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);
|
|
1179
1245
|
if (freeSlots === 0) {
|
|
1180
1246
|
return;
|
|
@@ -1187,6 +1253,7 @@ var __exports__ = (() => {
|
|
|
1187
1253
|
}
|
|
1188
1254
|
}
|
|
1189
1255
|
}
|
|
1256
|
+
/** Ensure all requests have updated priorities, and that no longer valid requests are cancelled */
|
|
1190
1257
|
_updateAllRequests() {
|
|
1191
1258
|
const requestQueue = this.requestQueue;
|
|
1192
1259
|
for (let i = 0; i < requestQueue.length; ++i) {
|
|
@@ -1199,6 +1266,7 @@ var __exports__ = (() => {
|
|
|
1199
1266
|
}
|
|
1200
1267
|
requestQueue.sort((a, b) => a.priority - b.priority);
|
|
1201
1268
|
}
|
|
1269
|
+
/** Update a single request by calling the callback */
|
|
1202
1270
|
_updateRequest(request) {
|
|
1203
1271
|
request.priority = request.getPriority(request.handle);
|
|
1204
1272
|
if (request.priority < 0) {
|
|
@@ -1232,7 +1300,7 @@ var __exports__ = (() => {
|
|
|
1232
1300
|
}
|
|
1233
1301
|
|
|
1234
1302
|
// ../loader-utils/src/json-loader.ts
|
|
1235
|
-
var VERSION2 =
|
|
1303
|
+
var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1236
1304
|
var JSONLoader = {
|
|
1237
1305
|
name: "JSON",
|
|
1238
1306
|
id: "json",
|
|
@@ -1428,6 +1496,10 @@ var __exports__ = (() => {
|
|
|
1428
1496
|
|
|
1429
1497
|
// ../loader-utils/src/lib/files/blob-file.ts
|
|
1430
1498
|
var BlobFile = class {
|
|
1499
|
+
handle;
|
|
1500
|
+
size;
|
|
1501
|
+
bigsize;
|
|
1502
|
+
url;
|
|
1431
1503
|
constructor(blob) {
|
|
1432
1504
|
this.handle = blob instanceof ArrayBuffer ? new Blob([blob]) : blob;
|
|
1433
1505
|
this.size = blob instanceof ArrayBuffer ? blob.byteLength : blob.size;
|
|
@@ -1452,6 +1524,7 @@ var __exports__ = (() => {
|
|
|
1452
1524
|
// ../loader-utils/src/lib/files/node-file-facade.ts
|
|
1453
1525
|
var NOT_IMPLEMENTED = new Error("Not implemented");
|
|
1454
1526
|
var NodeFileFacade = class {
|
|
1527
|
+
handle;
|
|
1455
1528
|
size = 0;
|
|
1456
1529
|
bigsize = 0n;
|
|
1457
1530
|
url = "";
|
|
@@ -1464,21 +1537,27 @@ var __exports__ = (() => {
|
|
|
1464
1537
|
}
|
|
1465
1538
|
throw new Error("Can't instantiate NodeFile. Make sure to import @loaders.gl/polyfills first.");
|
|
1466
1539
|
}
|
|
1540
|
+
/** Read data */
|
|
1467
1541
|
async read(start, end) {
|
|
1468
1542
|
throw NOT_IMPLEMENTED;
|
|
1469
1543
|
}
|
|
1544
|
+
/** Write to file. The number of bytes written will be returned */
|
|
1470
1545
|
async write(arrayBuffer, offset, length) {
|
|
1471
1546
|
throw NOT_IMPLEMENTED;
|
|
1472
1547
|
}
|
|
1548
|
+
/** Get information about file */
|
|
1473
1549
|
async stat() {
|
|
1474
1550
|
throw NOT_IMPLEMENTED;
|
|
1475
1551
|
}
|
|
1552
|
+
/** Truncates the file descriptor. Only available on NodeFile. */
|
|
1476
1553
|
async truncate(length) {
|
|
1477
1554
|
throw NOT_IMPLEMENTED;
|
|
1478
1555
|
}
|
|
1556
|
+
/** Append data to a file. Only available on NodeFile. */
|
|
1479
1557
|
async append(data) {
|
|
1480
1558
|
throw NOT_IMPLEMENTED;
|
|
1481
1559
|
}
|
|
1560
|
+
/** Close the file */
|
|
1482
1561
|
async close() {
|
|
1483
1562
|
}
|
|
1484
1563
|
};
|
|
@@ -1604,12 +1683,8 @@ var __exports__ = (() => {
|
|
|
1604
1683
|
if (typeof resource === "string") {
|
|
1605
1684
|
resource = new TextEncoder().encode(resource);
|
|
1606
1685
|
}
|
|
1607
|
-
const response = new Response(resource, {
|
|
1608
|
-
|
|
1609
|
-
});
|
|
1610
|
-
Object.defineProperty(response, "url", {
|
|
1611
|
-
value: url
|
|
1612
|
-
});
|
|
1686
|
+
const response = new Response(resource, { headers });
|
|
1687
|
+
Object.defineProperty(response, "url", { value: url });
|
|
1613
1688
|
return response;
|
|
1614
1689
|
}
|
|
1615
1690
|
async function checkResponse(response) {
|
|
@@ -2230,9 +2305,7 @@ var __exports__ = (() => {
|
|
|
2230
2305
|
});
|
|
2231
2306
|
|
|
2232
2307
|
// src/lib/loader-utils/loggers.ts
|
|
2233
|
-
var probeLog = new Log({
|
|
2234
|
-
id: "loaders.gl"
|
|
2235
|
-
});
|
|
2308
|
+
var probeLog = new Log({ id: "loaders.gl" });
|
|
2236
2309
|
var NullLog = class {
|
|
2237
2310
|
log() {
|
|
2238
2311
|
return () => {
|
|
@@ -2252,6 +2325,7 @@ var __exports__ = (() => {
|
|
|
2252
2325
|
}
|
|
2253
2326
|
};
|
|
2254
2327
|
var ConsoleLog = class {
|
|
2328
|
+
console;
|
|
2255
2329
|
constructor() {
|
|
2256
2330
|
this.console = console;
|
|
2257
2331
|
}
|
|
@@ -2271,29 +2345,39 @@ var __exports__ = (() => {
|
|
|
2271
2345
|
|
|
2272
2346
|
// src/lib/loader-utils/option-defaults.ts
|
|
2273
2347
|
var DEFAULT_LOADER_OPTIONS = {
|
|
2348
|
+
// baseUri
|
|
2274
2349
|
fetch: null,
|
|
2275
2350
|
mimeType: void 0,
|
|
2276
2351
|
nothrow: false,
|
|
2277
2352
|
log: new ConsoleLog(),
|
|
2353
|
+
// A probe.gl compatible (`log.log()()` syntax) that just logs to console
|
|
2278
2354
|
useLocalLibraries: false,
|
|
2279
2355
|
CDN: "https://unpkg.com/@loaders.gl",
|
|
2280
2356
|
worker: true,
|
|
2357
|
+
// By default, use worker if provided by loader.
|
|
2281
2358
|
maxConcurrency: 3,
|
|
2359
|
+
// How many worker instances should be created for each loader.
|
|
2282
2360
|
maxMobileConcurrency: 1,
|
|
2361
|
+
// How many worker instances should be created for each loader on mobile devices.
|
|
2283
2362
|
reuseWorkers: isBrowser,
|
|
2363
|
+
// By default reuse workers in browser (Node.js refuses to terminate if browsers are running)
|
|
2284
2364
|
_nodeWorkers: false,
|
|
2365
|
+
// By default do not support node workers
|
|
2285
2366
|
_workerType: "",
|
|
2367
|
+
// 'test' to use locally generated workers
|
|
2286
2368
|
limit: 0,
|
|
2287
2369
|
_limitMB: 0,
|
|
2288
2370
|
batchSize: "auto",
|
|
2289
2371
|
batchDebounceMs: 0,
|
|
2290
2372
|
metadata: false,
|
|
2373
|
+
// TODO - currently only implemented for parseInBatches, adds initial metadata batch,
|
|
2291
2374
|
transforms: []
|
|
2292
2375
|
};
|
|
2293
2376
|
var REMOVED_LOADER_OPTIONS = {
|
|
2294
2377
|
throws: "nothrow",
|
|
2295
2378
|
dataType: "(no longer used)",
|
|
2296
2379
|
uri: "baseUri",
|
|
2380
|
+
// Warn if fetch options are used on top-level
|
|
2297
2381
|
method: "fetch.method",
|
|
2298
2382
|
headers: "fetch.headers",
|
|
2299
2383
|
body: "fetch.body",
|
|
@@ -2311,17 +2395,15 @@ var __exports__ = (() => {
|
|
|
2311
2395
|
// src/lib/loader-utils/option-utils.ts
|
|
2312
2396
|
function getGlobalLoaderState() {
|
|
2313
2397
|
globalThis.loaders = globalThis.loaders || {};
|
|
2314
|
-
const {
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2398
|
+
const { loaders } = globalThis;
|
|
2399
|
+
if (!loaders._state) {
|
|
2400
|
+
loaders._state = {};
|
|
2401
|
+
}
|
|
2318
2402
|
return loaders._state;
|
|
2319
2403
|
}
|
|
2320
2404
|
function getGlobalLoaderOptions() {
|
|
2321
2405
|
const state = getGlobalLoaderState();
|
|
2322
|
-
state.globalOptions = state.globalOptions || {
|
|
2323
|
-
...DEFAULT_LOADER_OPTIONS
|
|
2324
|
-
};
|
|
2406
|
+
state.globalOptions = state.globalOptions || { ...DEFAULT_LOADER_OPTIONS };
|
|
2325
2407
|
return state.globalOptions;
|
|
2326
2408
|
}
|
|
2327
2409
|
function setGlobalOptions(options) {
|
|
@@ -2353,10 +2435,14 @@ var __exports__ = (() => {
|
|
|
2353
2435
|
const isWorkerUrlOption = key === "workerUrl" && id;
|
|
2354
2436
|
if (!(key in defaultOptions) && !isBaseUriOption && !isWorkerUrlOption) {
|
|
2355
2437
|
if (key in deprecatedOptions) {
|
|
2356
|
-
probeLog.warn(
|
|
2438
|
+
probeLog.warn(
|
|
2439
|
+
`${loaderName} loader option '${prefix}${key}' no longer supported, use '${deprecatedOptions[key]}'`
|
|
2440
|
+
)();
|
|
2357
2441
|
} else if (!isSubOptions) {
|
|
2358
2442
|
const suggestion = findSimilarOption(key, loaders);
|
|
2359
|
-
probeLog.warn(
|
|
2443
|
+
probeLog.warn(
|
|
2444
|
+
`${loaderName} loader option '${prefix}${key}' not recognized. ${suggestion}`
|
|
2445
|
+
)();
|
|
2360
2446
|
}
|
|
2361
2447
|
}
|
|
2362
2448
|
}
|
|
@@ -2380,9 +2466,7 @@ var __exports__ = (() => {
|
|
|
2380
2466
|
}
|
|
2381
2467
|
function normalizeOptionsInternal(loader, options, url) {
|
|
2382
2468
|
const loaderDefaultOptions = loader.options || {};
|
|
2383
|
-
const mergedOptions = {
|
|
2384
|
-
...loaderDefaultOptions
|
|
2385
|
-
};
|
|
2469
|
+
const mergedOptions = { ...loaderDefaultOptions };
|
|
2386
2470
|
addUrlOptions(mergedOptions, url);
|
|
2387
2471
|
if (mergedOptions.log === null) {
|
|
2388
2472
|
mergedOptions.log = new NullLog();
|
|
@@ -2432,10 +2516,7 @@ var __exports__ = (() => {
|
|
|
2432
2516
|
loader = loader[0];
|
|
2433
2517
|
loader = {
|
|
2434
2518
|
...loader,
|
|
2435
|
-
options: {
|
|
2436
|
-
...loader.options,
|
|
2437
|
-
...options
|
|
2438
|
-
}
|
|
2519
|
+
options: { ...loader.options, ...options }
|
|
2439
2520
|
};
|
|
2440
2521
|
}
|
|
2441
2522
|
if (loader?.parseTextSync || loader?.parseText) {
|
|
@@ -2472,9 +2553,7 @@ var __exports__ = (() => {
|
|
|
2472
2553
|
}
|
|
2473
2554
|
|
|
2474
2555
|
// src/lib/utils/log.ts
|
|
2475
|
-
var log = new Log({
|
|
2476
|
-
id: "loaders.gl"
|
|
2477
|
-
});
|
|
2556
|
+
var log = new Log({ id: "loaders.gl" });
|
|
2478
2557
|
|
|
2479
2558
|
// src/lib/api/select-loader.ts
|
|
2480
2559
|
var EXT_PATTERN = /\.([^.]+)$/;
|
|
@@ -2482,10 +2561,7 @@ var __exports__ = (() => {
|
|
|
2482
2561
|
if (!validHTTPResponse(data)) {
|
|
2483
2562
|
return null;
|
|
2484
2563
|
}
|
|
2485
|
-
let loader = selectLoaderSync(data, loaders, {
|
|
2486
|
-
...options,
|
|
2487
|
-
nothrow: true
|
|
2488
|
-
}, context);
|
|
2564
|
+
let loader = selectLoaderSync(data, loaders, { ...options, nothrow: true }, context);
|
|
2489
2565
|
if (loader) {
|
|
2490
2566
|
return loader;
|
|
2491
2567
|
}
|
|
@@ -2682,9 +2758,7 @@ var __exports__ = (() => {
|
|
|
2682
2758
|
// src/iterators/make-iterator/make-array-buffer-iterator.ts
|
|
2683
2759
|
var DEFAULT_CHUNK_SIZE2 = 256 * 1024;
|
|
2684
2760
|
function* makeArrayBufferIterator(arrayBuffer, options = {}) {
|
|
2685
|
-
const {
|
|
2686
|
-
chunkSize = DEFAULT_CHUNK_SIZE2
|
|
2687
|
-
} = options;
|
|
2761
|
+
const { chunkSize = DEFAULT_CHUNK_SIZE2 } = options;
|
|
2688
2762
|
let byteOffset = 0;
|
|
2689
2763
|
while (byteOffset < arrayBuffer.byteLength) {
|
|
2690
2764
|
const chunkByteLength = Math.min(arrayBuffer.byteLength - byteOffset, chunkSize);
|
|
@@ -2723,10 +2797,7 @@ var __exports__ = (() => {
|
|
|
2723
2797
|
if (options?._streamReadAhead) {
|
|
2724
2798
|
nextBatchPromise = reader.read();
|
|
2725
2799
|
}
|
|
2726
|
-
const {
|
|
2727
|
-
done,
|
|
2728
|
-
value
|
|
2729
|
-
} = await currentBatchPromise;
|
|
2800
|
+
const { done, value } = await currentBatchPromise;
|
|
2730
2801
|
if (done) {
|
|
2731
2802
|
return;
|
|
2732
2803
|
}
|
|
@@ -2922,11 +2993,12 @@ var __exports__ = (() => {
|
|
|
2922
2993
|
return null;
|
|
2923
2994
|
}
|
|
2924
2995
|
options = normalizeOptions(options, loader, candidateLoaders, url);
|
|
2925
|
-
context = getLoaderContext(
|
|
2926
|
-
|
|
2927
|
-
_parse: parse,
|
|
2928
|
-
|
|
2929
|
-
|
|
2996
|
+
context = getLoaderContext(
|
|
2997
|
+
// @ts-expect-error
|
|
2998
|
+
{ url, _parse: parse, loaders: candidateLoaders },
|
|
2999
|
+
options,
|
|
3000
|
+
context || null
|
|
3001
|
+
);
|
|
2930
3002
|
return await parseWithLoader(loader, data, options, context);
|
|
2931
3003
|
}
|
|
2932
3004
|
async function parseWithLoader(loader, data, options, context) {
|
|
@@ -2934,24 +3006,9 @@ var __exports__ = (() => {
|
|
|
2934
3006
|
options = mergeLoaderOptions(loader.options, options);
|
|
2935
3007
|
if (isResponse(data)) {
|
|
2936
3008
|
const response = data;
|
|
2937
|
-
const {
|
|
2938
|
-
ok,
|
|
2939
|
-
redirected,
|
|
2940
|
-
status,
|
|
2941
|
-
statusText,
|
|
2942
|
-
type,
|
|
2943
|
-
url
|
|
2944
|
-
} = response;
|
|
3009
|
+
const { ok, redirected, status, statusText, type, url } = response;
|
|
2945
3010
|
const headers = Object.fromEntries(response.headers.entries());
|
|
2946
|
-
context.response = {
|
|
2947
|
-
headers,
|
|
2948
|
-
ok,
|
|
2949
|
-
redirected,
|
|
2950
|
-
status,
|
|
2951
|
-
statusText,
|
|
2952
|
-
type,
|
|
2953
|
-
url
|
|
2954
|
-
};
|
|
3011
|
+
context.response = { headers, ok, redirected, status, statusText, type, url };
|
|
2955
3012
|
}
|
|
2956
3013
|
data = await getArrayBufferOrStringFromData(data, loader, options);
|
|
2957
3014
|
const loaderWithParser = loader;
|
|
@@ -2990,12 +3047,11 @@ var __exports__ = (() => {
|
|
|
2990
3047
|
const parse2 = () => {
|
|
2991
3048
|
throw new Error("parseSync called parse (which is async");
|
|
2992
3049
|
};
|
|
2993
|
-
context = getLoaderContext(
|
|
2994
|
-
url,
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
}, options, context || null);
|
|
3050
|
+
context = getLoaderContext(
|
|
3051
|
+
{ url, _parseSync: parse2, _parse: parse2, loaders },
|
|
3052
|
+
options,
|
|
3053
|
+
context || null
|
|
3054
|
+
);
|
|
2999
3055
|
return parseWithLoaderSync(loader, data, options, context);
|
|
3000
3056
|
}
|
|
3001
3057
|
function parseWithLoaderSync(loader, data, options, context) {
|
|
@@ -3006,7 +3062,9 @@ var __exports__ = (() => {
|
|
|
3006
3062
|
if (loader.parseSync && data instanceof ArrayBuffer) {
|
|
3007
3063
|
return loader.parseSync(data, options, context);
|
|
3008
3064
|
}
|
|
3009
|
-
throw new Error(
|
|
3065
|
+
throw new Error(
|
|
3066
|
+
`${loader.name} loader: 'parseSync' not supported by this loader, use 'parse' instead. ${context.url || ""}`
|
|
3067
|
+
);
|
|
3010
3068
|
}
|
|
3011
3069
|
|
|
3012
3070
|
// ../schema/src/lib/table/simple-table/table-accessors.ts
|
|
@@ -3048,11 +3106,7 @@ var __exports__ = (() => {
|
|
|
3048
3106
|
|
|
3049
3107
|
// ../schema/src/lib/table/simple-table/make-table-from-batches.ts
|
|
3050
3108
|
function makeBatchFromTable(table) {
|
|
3051
|
-
return {
|
|
3052
|
-
...table,
|
|
3053
|
-
length: getTableLength(table),
|
|
3054
|
-
batchType: "data"
|
|
3055
|
-
};
|
|
3109
|
+
return { ...table, length: getTableLength(table), batchType: "data" };
|
|
3056
3110
|
}
|
|
3057
3111
|
|
|
3058
3112
|
// src/lib/api/parse-in-batches.ts
|
|
@@ -3071,12 +3125,11 @@ var __exports__ = (() => {
|
|
|
3071
3125
|
return [];
|
|
3072
3126
|
}
|
|
3073
3127
|
options = normalizeOptions(options, loader, loaderArray, url);
|
|
3074
|
-
context = getLoaderContext(
|
|
3075
|
-
url,
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
}, options, context || null);
|
|
3128
|
+
context = getLoaderContext(
|
|
3129
|
+
{ url, _parseInBatches: parseInBatches, _parse: parse, loaders: loaderArray },
|
|
3130
|
+
options,
|
|
3131
|
+
context || null
|
|
3132
|
+
);
|
|
3080
3133
|
return await parseWithLoaderInBatches(loader, data, options, context);
|
|
3081
3134
|
}
|
|
3082
3135
|
async function parseWithLoaderInBatches(loader, data, options, context) {
|
|
@@ -3091,6 +3144,7 @@ var __exports__ = (() => {
|
|
|
3091
3144
|
_loader: loader,
|
|
3092
3145
|
_context: context
|
|
3093
3146
|
},
|
|
3147
|
+
// Populate with some default fields to avoid crashing
|
|
3094
3148
|
data: [],
|
|
3095
3149
|
bytesUsed: 0
|
|
3096
3150
|
};
|
|
@@ -3110,10 +3164,13 @@ var __exports__ = (() => {
|
|
|
3110
3164
|
}
|
|
3111
3165
|
async function* parseChunkInBatches(transformedIterator, loader, options, context) {
|
|
3112
3166
|
const arrayBuffer = await concatenateArrayBuffersAsync(transformedIterator);
|
|
3113
|
-
const parsedData = await parse(
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3167
|
+
const parsedData = await parse(
|
|
3168
|
+
arrayBuffer,
|
|
3169
|
+
loader,
|
|
3170
|
+
// TODO - Hack: supply loaders MIME type to ensure we match it
|
|
3171
|
+
{ ...options, mimeType: loader.mimeTypes[0] },
|
|
3172
|
+
context
|
|
3173
|
+
);
|
|
3117
3174
|
const batch = convertDataToBatch(parsedData, loader);
|
|
3118
3175
|
yield batch;
|
|
3119
3176
|
}
|
|
@@ -3172,7 +3229,9 @@ var __exports__ = (() => {
|
|
|
3172
3229
|
if (!Array.isArray(files)) {
|
|
3173
3230
|
return loadOneFileInBatches(files, loadersArray, options || {}, fetch2);
|
|
3174
3231
|
}
|
|
3175
|
-
const promises = files.map(
|
|
3232
|
+
const promises = files.map(
|
|
3233
|
+
(file) => loadOneFileInBatches(file, loadersArray, options || {}, fetch2)
|
|
3234
|
+
);
|
|
3176
3235
|
return promises;
|
|
3177
3236
|
}
|
|
3178
3237
|
async function loadOneFileInBatches(file, loaders, options, fetch2) {
|
|
@@ -3221,21 +3280,14 @@ var __exports__ = (() => {
|
|
|
3221
3280
|
throw new Error("Writer could not encode data in batches");
|
|
3222
3281
|
}
|
|
3223
3282
|
function getIterator(data) {
|
|
3224
|
-
const dataIterator = [{
|
|
3225
|
-
...data,
|
|
3226
|
-
start: 0,
|
|
3227
|
-
end: data.length
|
|
3228
|
-
}];
|
|
3283
|
+
const dataIterator = [{ ...data, start: 0, end: data.length }];
|
|
3229
3284
|
return dataIterator;
|
|
3230
3285
|
}
|
|
3231
3286
|
|
|
3232
3287
|
// src/lib/api/encode.ts
|
|
3233
3288
|
async function encode(data, writer, options) {
|
|
3234
3289
|
const globalOptions = getGlobalLoaderOptions();
|
|
3235
|
-
options = {
|
|
3236
|
-
...globalOptions,
|
|
3237
|
-
...options
|
|
3238
|
-
};
|
|
3290
|
+
options = { ...globalOptions, ...options };
|
|
3239
3291
|
if (writer.encodeURLtoURL) {
|
|
3240
3292
|
return encodeWithCommandLineTool(writer, data, options);
|
|
3241
3293
|
}
|
|
@@ -3305,11 +3357,7 @@ var __exports__ = (() => {
|
|
|
3305
3357
|
return response.arrayBuffer();
|
|
3306
3358
|
}
|
|
3307
3359
|
function getIterator2(data) {
|
|
3308
|
-
const dataIterator = [{
|
|
3309
|
-
...data,
|
|
3310
|
-
start: 0,
|
|
3311
|
-
end: data.length
|
|
3312
|
-
}];
|
|
3360
|
+
const dataIterator = [{ ...data, start: 0, end: data.length }];
|
|
3313
3361
|
return dataIterator;
|
|
3314
3362
|
}
|
|
3315
3363
|
function getTemporaryFilename(filename2) {
|
|
@@ -3322,34 +3370,40 @@ var __exports__ = (() => {
|
|
|
3322
3370
|
return globalThis.loaders.makeNodeStream(source, options);
|
|
3323
3371
|
}
|
|
3324
3372
|
const iterator = source[Symbol.asyncIterator] ? source[Symbol.asyncIterator]() : source[Symbol.iterator]();
|
|
3325
|
-
return new ReadableStream(
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3373
|
+
return new ReadableStream(
|
|
3374
|
+
{
|
|
3375
|
+
// Create a byte stream (enables `Response(stream).arrayBuffer()`)
|
|
3376
|
+
// Only supported on Chrome
|
|
3377
|
+
// See: https://developer.mozilla.org/en-US/docs/Web/API/ReadableByteStreamController
|
|
3378
|
+
// @ts-ignore
|
|
3379
|
+
type: "bytes",
|
|
3380
|
+
async pull(controller) {
|
|
3381
|
+
try {
|
|
3382
|
+
const { done, value } = await iterator.next();
|
|
3383
|
+
if (done) {
|
|
3384
|
+
controller.close();
|
|
3385
|
+
} else {
|
|
3386
|
+
controller.enqueue(new Uint8Array(value));
|
|
3387
|
+
}
|
|
3388
|
+
} catch (error) {
|
|
3389
|
+
controller.error(error);
|
|
3337
3390
|
}
|
|
3338
|
-
}
|
|
3339
|
-
|
|
3391
|
+
},
|
|
3392
|
+
async cancel() {
|
|
3393
|
+
await iterator?.return?.();
|
|
3340
3394
|
}
|
|
3341
3395
|
},
|
|
3342
|
-
|
|
3343
|
-
|
|
3396
|
+
// options: QueingStrategy<Uint8Array>
|
|
3397
|
+
{
|
|
3398
|
+
// This is bytes, not chunks
|
|
3399
|
+
highWaterMark: 2 ** 24,
|
|
3400
|
+
...options
|
|
3344
3401
|
}
|
|
3345
|
-
|
|
3346
|
-
highWaterMark: 2 ** 24,
|
|
3347
|
-
...options
|
|
3348
|
-
});
|
|
3402
|
+
);
|
|
3349
3403
|
}
|
|
3350
3404
|
|
|
3351
3405
|
// src/null-loader.ts
|
|
3352
|
-
var VERSION4 =
|
|
3406
|
+
var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
3353
3407
|
var NullWorkerLoader = {
|
|
3354
3408
|
name: "Null loader",
|
|
3355
3409
|
id: "null",
|
|
@@ -3416,10 +3470,7 @@ var __exports__ = (() => {
|
|
|
3416
3470
|
}
|
|
3417
3471
|
async function read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError) {
|
|
3418
3472
|
try {
|
|
3419
|
-
const {
|
|
3420
|
-
done,
|
|
3421
|
-
value
|
|
3422
|
-
} = await reader.read();
|
|
3473
|
+
const { done, value } = await reader.read();
|
|
3423
3474
|
if (done) {
|
|
3424
3475
|
onDone();
|
|
3425
3476
|
controller.close();
|
|
@@ -3427,10 +3478,7 @@ var __exports__ = (() => {
|
|
|
3427
3478
|
}
|
|
3428
3479
|
loadedBytes += value.byteLength;
|
|
3429
3480
|
const percent = Math.round(loadedBytes / totalBytes * 100);
|
|
3430
|
-
onProgress(percent, {
|
|
3431
|
-
loadedBytes,
|
|
3432
|
-
totalBytes
|
|
3433
|
-
});
|
|
3481
|
+
onProgress(percent, { loadedBytes, totalBytes });
|
|
3434
3482
|
controller.enqueue(value);
|
|
3435
3483
|
await read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError);
|
|
3436
3484
|
} catch (error) {
|
|
@@ -3441,9 +3489,15 @@ var __exports__ = (() => {
|
|
|
3441
3489
|
|
|
3442
3490
|
// src/lib/filesystems/browser-filesystem.ts
|
|
3443
3491
|
var BrowserFileSystem = class {
|
|
3492
|
+
_fetch;
|
|
3444
3493
|
files = {};
|
|
3445
3494
|
lowerCaseFiles = {};
|
|
3446
3495
|
usedFiles = {};
|
|
3496
|
+
/**
|
|
3497
|
+
* A FileSystem API wrapper around a list of browser 'File' objects
|
|
3498
|
+
* @param files
|
|
3499
|
+
* @param options
|
|
3500
|
+
*/
|
|
3447
3501
|
constructor(files, options) {
|
|
3448
3502
|
this._fetch = options?.fetch || fetch;
|
|
3449
3503
|
for (let i = 0; i < files.length; ++i) {
|
|
@@ -3454,16 +3508,18 @@ var __exports__ = (() => {
|
|
|
3454
3508
|
}
|
|
3455
3509
|
this.fetch = this.fetch.bind(this);
|
|
3456
3510
|
}
|
|
3511
|
+
// implements IFileSystem
|
|
3512
|
+
/**
|
|
3513
|
+
* Implementation of fetch against this file system
|
|
3514
|
+
* Delegates to global fetch for http{s}:// or data://
|
|
3515
|
+
*/
|
|
3457
3516
|
async fetch(path, options) {
|
|
3458
3517
|
if (path.includes("://")) {
|
|
3459
3518
|
return this._fetch(path, options);
|
|
3460
3519
|
}
|
|
3461
3520
|
const file = this.files[path];
|
|
3462
3521
|
if (!file) {
|
|
3463
|
-
return new Response(path, {
|
|
3464
|
-
status: 400,
|
|
3465
|
-
statusText: "NOT FOUND"
|
|
3466
|
-
});
|
|
3522
|
+
return new Response(path, { status: 400, statusText: "NOT FOUND" });
|
|
3467
3523
|
}
|
|
3468
3524
|
const headers = new Headers(options?.headers);
|
|
3469
3525
|
const range = headers.get("Range");
|
|
@@ -3473,17 +3529,18 @@ var __exports__ = (() => {
|
|
|
3473
3529
|
const end = parseInt(bytes[2]);
|
|
3474
3530
|
const data = await file.slice(start, end).arrayBuffer();
|
|
3475
3531
|
const response2 = new Response(data);
|
|
3476
|
-
Object.defineProperty(response2, "url", {
|
|
3477
|
-
value: path
|
|
3478
|
-
});
|
|
3532
|
+
Object.defineProperty(response2, "url", { value: path });
|
|
3479
3533
|
return response2;
|
|
3480
3534
|
}
|
|
3481
3535
|
const response = new Response(file);
|
|
3482
|
-
Object.defineProperty(response, "url", {
|
|
3483
|
-
value: path
|
|
3484
|
-
});
|
|
3536
|
+
Object.defineProperty(response, "url", { value: path });
|
|
3485
3537
|
return response;
|
|
3486
3538
|
}
|
|
3539
|
+
/**
|
|
3540
|
+
* List filenames in this filesystem
|
|
3541
|
+
* @param dirname
|
|
3542
|
+
* @returns
|
|
3543
|
+
*/
|
|
3487
3544
|
async readdir(dirname2) {
|
|
3488
3545
|
const files = [];
|
|
3489
3546
|
for (const path in this.files) {
|
|
@@ -3491,23 +3548,31 @@ var __exports__ = (() => {
|
|
|
3491
3548
|
}
|
|
3492
3549
|
return files;
|
|
3493
3550
|
}
|
|
3551
|
+
/**
|
|
3552
|
+
* Return information (size) about files in this file system
|
|
3553
|
+
*/
|
|
3494
3554
|
async stat(path, options) {
|
|
3495
3555
|
const file = this.files[path];
|
|
3496
3556
|
if (!file) {
|
|
3497
3557
|
throw new Error(path);
|
|
3498
3558
|
}
|
|
3499
|
-
return {
|
|
3500
|
-
size: file.size
|
|
3501
|
-
};
|
|
3559
|
+
return { size: file.size };
|
|
3502
3560
|
}
|
|
3561
|
+
/**
|
|
3562
|
+
* Just removes the file from the list
|
|
3563
|
+
*/
|
|
3503
3564
|
async unlink(path) {
|
|
3504
3565
|
delete this.files[path];
|
|
3505
3566
|
delete this.lowerCaseFiles[path];
|
|
3506
3567
|
this.usedFiles[path] = true;
|
|
3507
3568
|
}
|
|
3569
|
+
// implements IRandomAccessFileSystem
|
|
3570
|
+
// RANDOM ACCESS
|
|
3508
3571
|
async openReadableFile(pathname, flags) {
|
|
3509
3572
|
return new BlobFile(this.files[pathname]);
|
|
3510
3573
|
}
|
|
3574
|
+
// PRIVATE
|
|
3575
|
+
// Supports case independent paths, and file usage tracking
|
|
3511
3576
|
_getFile(path, used) {
|
|
3512
3577
|
const file = this.files[path] || this.lowerCaseFiles[path];
|
|
3513
3578
|
if (file && used) {
|
|
@@ -3516,7 +3581,7 @@ var __exports__ = (() => {
|
|
|
3516
3581
|
return file;
|
|
3517
3582
|
}
|
|
3518
3583
|
};
|
|
3519
|
-
return __toCommonJS(
|
|
3584
|
+
return __toCommonJS(bundle_exports);
|
|
3520
3585
|
})();
|
|
3521
3586
|
return __exports__;
|
|
3522
3587
|
});
|