@loaders.gl/core 5.0.0-alpha.1 → 5.0.0-alpha.3
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/LICENSE +14 -3
- package/dist/dist.dev.js +416 -151
- package/dist/dist.min.js +3 -3
- package/dist/index.cjs +1944 -245
- package/dist/index.cjs.map +3 -4
- package/dist/iterators/make-iterator/make-stream-iterator.js +49 -10
- package/dist/iterators/make-iterator/make-stream-iterator.js.map +1 -1
- package/dist/lib/api/load-loader.js +1 -7
- package/dist/lib/api/load-loader.js.map +1 -1
- package/dist/lib/api/load.d.ts.map +1 -1
- package/dist/lib/api/load.js +24 -3
- package/dist/lib/api/load.js.map +1 -1
- package/dist/lib/api/parse.d.ts.map +1 -1
- package/dist/lib/api/parse.js +4 -1
- package/dist/lib/api/parse.js.map +1 -1
- package/dist/lib/filesystems/browser-filesystem.d.ts.map +1 -1
- package/dist/lib/filesystems/browser-filesystem.js +25 -11
- package/dist/lib/filesystems/browser-filesystem.js.map +1 -1
- package/dist/lib/init.js +1 -1
- package/dist/lib/loader-utils/get-fetch-function.js +24 -10
- package/dist/lib/loader-utils/get-fetch-function.js.map +1 -1
- package/dist/null-loader.js +1 -1
- package/dist/null-worker-node.js +96 -56
- package/dist/null-worker.js +96 -56
- package/package.json +6 -6
- package/src/iterators/make-iterator/make-stream-iterator.ts +48 -10
- package/src/lib/api/load-loader.ts +2 -13
- package/src/lib/api/load.ts +44 -4
- package/src/lib/api/parse.ts +5 -0
- package/src/lib/filesystems/browser-filesystem.ts +25 -11
- package/src/lib/loader-utils/get-fetch-function.ts +23 -12
package/dist/index.cjs
CHANGED
|
@@ -18,22 +18,22 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// dist/index.js
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
FetchError: () => FetchError,
|
|
24
|
-
JSONLoader: () =>
|
|
24
|
+
JSONLoader: () => JSONLoader,
|
|
25
25
|
NullLoader: () => NullLoader,
|
|
26
26
|
NullWorkerLoader: () => NullWorkerLoader,
|
|
27
|
-
RequestScheduler: () =>
|
|
27
|
+
RequestScheduler: () => RequestScheduler,
|
|
28
28
|
_BrowserFileSystem: () => BrowserFileSystem,
|
|
29
29
|
_fetchProgress: () => fetchProgress,
|
|
30
30
|
_selectSource: () => selectSource,
|
|
31
31
|
_unregisterLoaders: () => _unregisterLoaders,
|
|
32
|
-
assert: () =>
|
|
33
|
-
concatenateArrayBuffersAsync: () =>
|
|
32
|
+
assert: () => assert,
|
|
33
|
+
concatenateArrayBuffersAsync: () => concatenateArrayBuffersAsync,
|
|
34
34
|
coreApi: () => coreApi,
|
|
35
35
|
createDataSource: () => createDataSource,
|
|
36
|
-
document: () =>
|
|
36
|
+
document: () => document_,
|
|
37
37
|
encode: () => encode,
|
|
38
38
|
encodeInBatches: () => encodeInBatches,
|
|
39
39
|
encodeSync: () => encodeSync,
|
|
@@ -44,28 +44,28 @@ __export(dist_exports, {
|
|
|
44
44
|
encodeTextSync: () => encodeTextSync,
|
|
45
45
|
encodeURLtoURL: () => encodeURLtoURL,
|
|
46
46
|
fetchFile: () => fetchFile,
|
|
47
|
-
forEach: () =>
|
|
47
|
+
forEach: () => forEach,
|
|
48
48
|
getLoaderOptions: () => getGlobalLoaderOptions,
|
|
49
|
-
getPathPrefix: () =>
|
|
50
|
-
global: () =>
|
|
51
|
-
isAsyncIterable: () =>
|
|
52
|
-
isBrowser: () =>
|
|
53
|
-
isIterable: () =>
|
|
54
|
-
isIterator: () =>
|
|
55
|
-
isPromise: () =>
|
|
56
|
-
isPureObject: () =>
|
|
57
|
-
isReadableStream: () =>
|
|
58
|
-
isResponse: () =>
|
|
59
|
-
isWorker: () =>
|
|
60
|
-
isWritableStream: () =>
|
|
49
|
+
getPathPrefix: () => getPathPrefix,
|
|
50
|
+
global: () => global_,
|
|
51
|
+
isAsyncIterable: () => isAsyncIterable,
|
|
52
|
+
isBrowser: () => isBrowser,
|
|
53
|
+
isIterable: () => isIterable,
|
|
54
|
+
isIterator: () => isIterator,
|
|
55
|
+
isPromise: () => isPromise,
|
|
56
|
+
isPureObject: () => isPureObject,
|
|
57
|
+
isReadableStream: () => isReadableStream,
|
|
58
|
+
isResponse: () => isResponse,
|
|
59
|
+
isWorker: () => isWorker,
|
|
60
|
+
isWritableStream: () => isWritableStream,
|
|
61
61
|
load: () => load,
|
|
62
62
|
loadInBatches: () => loadInBatches,
|
|
63
63
|
makeIterator: () => makeIterator,
|
|
64
|
-
makeLineIterator: () =>
|
|
65
|
-
makeNumberedLineIterator: () =>
|
|
64
|
+
makeLineIterator: () => makeLineIterator,
|
|
65
|
+
makeNumberedLineIterator: () => makeNumberedLineIterator,
|
|
66
66
|
makeStream: () => makeStream,
|
|
67
|
-
makeTextDecoderIterator: () =>
|
|
68
|
-
makeTextEncoderIterator: () =>
|
|
67
|
+
makeTextDecoderIterator: () => makeTextDecoderIterator,
|
|
68
|
+
makeTextEncoderIterator: () => makeTextEncoderIterator,
|
|
69
69
|
parse: () => parse,
|
|
70
70
|
parseFile: () => parseFile,
|
|
71
71
|
parseInBatches: () => parseInBatches,
|
|
@@ -74,21 +74,1645 @@ __export(dist_exports, {
|
|
|
74
74
|
preloadSync: () => preloadSync,
|
|
75
75
|
readArrayBuffer: () => readArrayBuffer,
|
|
76
76
|
registerLoaders: () => registerLoaders,
|
|
77
|
-
resolvePath: () =>
|
|
77
|
+
resolvePath: () => resolvePath,
|
|
78
78
|
selectLoader: () => selectLoader,
|
|
79
79
|
selectLoaderSync: () => selectLoaderSync,
|
|
80
|
-
self: () =>
|
|
80
|
+
self: () => self_,
|
|
81
81
|
setLoaderOptions: () => setGlobalOptions,
|
|
82
|
-
setPathPrefix: () =>
|
|
83
|
-
window: () =>
|
|
82
|
+
setPathPrefix: () => setPathPrefix,
|
|
83
|
+
window: () => window_
|
|
84
84
|
});
|
|
85
|
-
module.exports = __toCommonJS(
|
|
85
|
+
module.exports = __toCommonJS(index_exports);
|
|
86
86
|
|
|
87
|
-
//
|
|
88
|
-
|
|
87
|
+
// ../loader-utils/src/lib/env-utils/assert.ts
|
|
88
|
+
function assert(condition, message) {
|
|
89
|
+
if (!condition) {
|
|
90
|
+
throw new Error(message || "loader assertion failed.");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
89
93
|
|
|
90
|
-
//
|
|
91
|
-
var
|
|
94
|
+
// ../loader-utils/src/lib/env-utils/globals.ts
|
|
95
|
+
var globals = {
|
|
96
|
+
self: typeof self !== "undefined" && self,
|
|
97
|
+
window: typeof window !== "undefined" && window,
|
|
98
|
+
global: typeof global !== "undefined" && global,
|
|
99
|
+
document: typeof document !== "undefined" && document
|
|
100
|
+
};
|
|
101
|
+
var self_ = globals.self || globals.window || globals.global || {};
|
|
102
|
+
var window_ = globals.window || globals.self || globals.global || {};
|
|
103
|
+
var global_ = globals.global || globals.self || globals.window || {};
|
|
104
|
+
var document_ = globals.document || {};
|
|
105
|
+
var isBrowser = (
|
|
106
|
+
// @ts-ignore process does not exist on browser
|
|
107
|
+
Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser)
|
|
108
|
+
);
|
|
109
|
+
var isWorker = typeof importScripts === "function";
|
|
110
|
+
var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
111
|
+
var nodeVersion = matches && parseFloat(matches[1]) || 0;
|
|
112
|
+
|
|
113
|
+
// ../loader-utils/src/lib/log-utils/log.ts
|
|
114
|
+
var import_log = require("@probe.gl/log");
|
|
115
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
116
|
+
var version = VERSION[0] >= "0" && VERSION[0] <= "9" ? `v${VERSION}` : "";
|
|
117
|
+
function createLog() {
|
|
118
|
+
const log2 = new import_log.Log({ id: "loaders.gl" });
|
|
119
|
+
globalThis.loaders ||= {};
|
|
120
|
+
globalThis.loaders.log = log2;
|
|
121
|
+
globalThis.loaders.version = version;
|
|
122
|
+
globalThis.probe ||= {};
|
|
123
|
+
globalThis.probe.loaders = log2;
|
|
124
|
+
return log2;
|
|
125
|
+
}
|
|
126
|
+
var log = createLog();
|
|
127
|
+
|
|
128
|
+
// ../loader-utils/src/lib/javascript-utils/is-type.ts
|
|
129
|
+
var isBoolean = (value) => typeof value === "boolean";
|
|
130
|
+
var isFunction = (value) => typeof value === "function";
|
|
131
|
+
var isObject = (value) => value !== null && typeof value === "object";
|
|
132
|
+
var isPureObject = (value) => isObject(value) && value.constructor === {}.constructor;
|
|
133
|
+
var isSharedArrayBuffer = (value) => typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer;
|
|
134
|
+
var isArrayBufferLike = (value) => isObject(value) && typeof value.byteLength === "number" && typeof value.slice === "function";
|
|
135
|
+
var isPromise = (value) => isObject(value) && "then" in value && isFunction(value.then);
|
|
136
|
+
var isIterable = (value) => Boolean(value) && isFunction(value[Symbol.iterator]);
|
|
137
|
+
var isAsyncIterable = (value) => Boolean(value) && isFunction(value[Symbol.asyncIterator]);
|
|
138
|
+
var isIterator = (value) => Boolean(value) && isFunction(value.next);
|
|
139
|
+
var isResponse = (value) => typeof Response !== "undefined" && value instanceof Response || isObject(value) && isFunction(value.arrayBuffer) && isFunction(value.text) && isFunction(value.json);
|
|
140
|
+
var isBlob = (value) => typeof Blob !== "undefined" && value instanceof Blob;
|
|
141
|
+
var isWritableDOMStream = (value) => isObject(value) && isFunction(value.abort) && isFunction(value.getWriter);
|
|
142
|
+
var isReadableDOMStream = (value) => typeof ReadableStream !== "undefined" && value instanceof ReadableStream || isObject(value) && isFunction(value.tee) && isFunction(value.cancel) && isFunction(value.getReader);
|
|
143
|
+
var isWritableNodeStream = (value) => isObject(value) && isFunction(value.end) && isFunction(value.write) && isBoolean(value.writable);
|
|
144
|
+
var isReadableNodeStream = (value) => isObject(value) && isFunction(value.read) && isFunction(value.pipe) && isBoolean(value.readable);
|
|
145
|
+
var isReadableStream = (value) => isReadableDOMStream(value) || isReadableNodeStream(value);
|
|
146
|
+
var isWritableStream = (value) => isWritableDOMStream(value) || isWritableNodeStream(value);
|
|
147
|
+
|
|
148
|
+
// ../loader-utils/src/lib/option-utils/merge-options.ts
|
|
149
|
+
function mergeOptions(baseOptions, newOptions) {
|
|
150
|
+
return mergeOptionsRecursively(baseOptions || {}, newOptions);
|
|
151
|
+
}
|
|
152
|
+
function mergeOptionsRecursively(baseOptions, newOptions, level = 0) {
|
|
153
|
+
if (level > 3) {
|
|
154
|
+
return newOptions;
|
|
155
|
+
}
|
|
156
|
+
const options = { ...baseOptions };
|
|
157
|
+
for (const [key, newValue] of Object.entries(newOptions)) {
|
|
158
|
+
if (isPureObject(newValue)) {
|
|
159
|
+
options[key] = mergeOptionsRecursively(
|
|
160
|
+
options[key] || {},
|
|
161
|
+
newOptions[key],
|
|
162
|
+
level + 1
|
|
163
|
+
);
|
|
164
|
+
} else {
|
|
165
|
+
options[key] = newOptions[key];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return options;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ../loader-utils/src/lib/module-utils/js-module-utils.ts
|
|
172
|
+
function registerJSModules(modules) {
|
|
173
|
+
globalThis.loaders ||= {};
|
|
174
|
+
globalThis.loaders.modules ||= {};
|
|
175
|
+
Object.assign(globalThis.loaders.modules, modules);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ../worker-utils/src/lib/npm-tag.ts
|
|
179
|
+
var NPM_TAG = "latest";
|
|
180
|
+
|
|
181
|
+
// ../worker-utils/src/lib/env-utils/version.ts
|
|
182
|
+
function getVersion() {
|
|
183
|
+
var _a;
|
|
184
|
+
if (!((_a = globalThis._loadersgl_) == null ? void 0 : _a.version)) {
|
|
185
|
+
globalThis._loadersgl_ = globalThis._loadersgl_ || {};
|
|
186
|
+
if (typeof __VERSION__ === "undefined") {
|
|
187
|
+
globalThis._loadersgl_.version = NPM_TAG;
|
|
188
|
+
} else {
|
|
189
|
+
globalThis._loadersgl_.version = __VERSION__;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return globalThis._loadersgl_.version;
|
|
193
|
+
}
|
|
194
|
+
var VERSION2 = getVersion();
|
|
195
|
+
|
|
196
|
+
// ../worker-utils/src/lib/env-utils/assert.ts
|
|
197
|
+
function assert2(condition, message) {
|
|
198
|
+
if (!condition) {
|
|
199
|
+
throw new Error(message || "loaders.gl assertion failed.");
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ../worker-utils/src/lib/env-utils/globals.ts
|
|
204
|
+
var globals2 = {
|
|
205
|
+
self: typeof self !== "undefined" && self,
|
|
206
|
+
window: typeof window !== "undefined" && window,
|
|
207
|
+
global: typeof global !== "undefined" && global,
|
|
208
|
+
document: typeof document !== "undefined" && document
|
|
209
|
+
};
|
|
210
|
+
var self_2 = globals2.self || globals2.window || globals2.global || {};
|
|
211
|
+
var window_2 = globals2.window || globals2.self || globals2.global || {};
|
|
212
|
+
var global_2 = globals2.global || globals2.self || globals2.window || {};
|
|
213
|
+
var document_2 = globals2.document || {};
|
|
214
|
+
var isBrowser2 = (
|
|
215
|
+
// @ts-ignore process.browser
|
|
216
|
+
typeof process !== "object" || String(process) !== "[object process]" || process.browser
|
|
217
|
+
);
|
|
218
|
+
var isMobile = typeof window !== "undefined" && typeof window.orientation !== "undefined";
|
|
219
|
+
var matches2 = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
220
|
+
var nodeVersion2 = matches2 && parseFloat(matches2[1]) || 0;
|
|
221
|
+
|
|
222
|
+
// ../worker-utils/src/lib/worker-farm/worker-job.ts
|
|
223
|
+
var WorkerJob = class {
|
|
224
|
+
name;
|
|
225
|
+
workerThread;
|
|
226
|
+
isRunning = true;
|
|
227
|
+
/** Promise that resolves when Job is done */
|
|
228
|
+
result;
|
|
229
|
+
_resolve = () => {
|
|
230
|
+
};
|
|
231
|
+
_reject = () => {
|
|
232
|
+
};
|
|
233
|
+
constructor(jobName, workerThread) {
|
|
234
|
+
this.name = jobName;
|
|
235
|
+
this.workerThread = workerThread;
|
|
236
|
+
this.result = new Promise((resolve2, reject) => {
|
|
237
|
+
this._resolve = resolve2;
|
|
238
|
+
this._reject = reject;
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Send a message to the job's worker thread
|
|
243
|
+
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
244
|
+
*/
|
|
245
|
+
postMessage(type, payload) {
|
|
246
|
+
this.workerThread.postMessage({
|
|
247
|
+
source: "loaders.gl",
|
|
248
|
+
// Lets worker ignore unrelated messages
|
|
249
|
+
type,
|
|
250
|
+
payload
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Call to resolve the `result` Promise with the supplied value
|
|
255
|
+
*/
|
|
256
|
+
done(value) {
|
|
257
|
+
if (!this.isRunning) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
this.isRunning = false;
|
|
261
|
+
this._resolve(value);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Call to reject the `result` Promise with the supplied error
|
|
265
|
+
*/
|
|
266
|
+
error(error) {
|
|
267
|
+
if (!this.isRunning) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
this.isRunning = false;
|
|
271
|
+
this._reject(error);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Terminates the worker executing this job and rejects its result.
|
|
275
|
+
* @param reason Abort reason supplied by the caller, or a cross-runtime `AbortError`.
|
|
276
|
+
*/
|
|
277
|
+
abort(reason) {
|
|
278
|
+
if (!this.isRunning) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const error = reason ?? createAbortError(`Worker job "${this.name}" was aborted`);
|
|
282
|
+
this.workerThread.destroy();
|
|
283
|
+
this.error(error);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
function createAbortError(message) {
|
|
287
|
+
const error = new Error(message);
|
|
288
|
+
error.name = "AbortError";
|
|
289
|
+
return error;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// ../worker-utils/src/lib/node/worker_threads-browser.ts
|
|
293
|
+
var NodeWorker = class {
|
|
294
|
+
/** Restores the native worker constructor when this browser shim is embedded in a Node bundle. */
|
|
295
|
+
constructor(...arguments_) {
|
|
296
|
+
var _a;
|
|
297
|
+
const runtimeProcess = globalThis.process;
|
|
298
|
+
const WorkerConstructor = (_a = runtimeProcess == null ? void 0 : runtimeProcess.getBuiltinModule) == null ? void 0 : _a.call(runtimeProcess, "node:worker_threads").Worker;
|
|
299
|
+
if (WorkerConstructor) {
|
|
300
|
+
return new WorkerConstructor(...arguments_);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/** No-op browser fallback matching the native Worker API. */
|
|
304
|
+
terminate() {
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
// ../worker-utils/src/lib/worker-utils/get-loadable-worker-url.ts
|
|
309
|
+
var workerURLCache = /* @__PURE__ */ new Map();
|
|
310
|
+
function getLoadableWorkerURL(props) {
|
|
311
|
+
assert2(props.source && !props.url || !props.source && props.url);
|
|
312
|
+
let workerURL = workerURLCache.get(props.source || props.url);
|
|
313
|
+
if (!workerURL) {
|
|
314
|
+
if (props.url) {
|
|
315
|
+
workerURL = getLoadableWorkerURLFromURL(props.url);
|
|
316
|
+
workerURLCache.set(props.url, workerURL);
|
|
317
|
+
}
|
|
318
|
+
if (props.source) {
|
|
319
|
+
workerURL = getLoadableWorkerURLFromSource(props.source);
|
|
320
|
+
workerURLCache.set(props.source, workerURL);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
assert2(workerURL);
|
|
324
|
+
return workerURL;
|
|
325
|
+
}
|
|
326
|
+
function getLoadableWorkerURLFromURL(url) {
|
|
327
|
+
if (!url.startsWith("http")) {
|
|
328
|
+
return url;
|
|
329
|
+
}
|
|
330
|
+
const workerSource = buildScriptSource(url);
|
|
331
|
+
return getLoadableWorkerURLFromSource(workerSource);
|
|
332
|
+
}
|
|
333
|
+
function getLoadableWorkerURLFromSource(workerSource) {
|
|
334
|
+
const blob = new Blob([workerSource], { type: "application/javascript" });
|
|
335
|
+
return URL.createObjectURL(blob);
|
|
336
|
+
}
|
|
337
|
+
function buildScriptSource(workerUrl) {
|
|
338
|
+
return `try {
|
|
339
|
+
importScripts('${workerUrl}');
|
|
340
|
+
} catch (error) {
|
|
341
|
+
console.error(error);
|
|
342
|
+
throw error;
|
|
343
|
+
}`;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
|
|
347
|
+
function getTransferList(object, recursive = true, transfers) {
|
|
348
|
+
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
349
|
+
if (!object) {
|
|
350
|
+
} else if (isTransferable(object)) {
|
|
351
|
+
transfersSet.add(object);
|
|
352
|
+
} else if (isTransferable(object.buffer)) {
|
|
353
|
+
transfersSet.add(object.buffer);
|
|
354
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
355
|
+
} else if (recursive && typeof object === "object") {
|
|
356
|
+
for (const key in object) {
|
|
357
|
+
getTransferList(object[key], recursive, transfersSet);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
361
|
+
}
|
|
362
|
+
function isTransferable(object) {
|
|
363
|
+
if (!object) {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
if (object instanceof ArrayBuffer) {
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
function getTransferListForWriter(object) {
|
|
381
|
+
if (object === null) {
|
|
382
|
+
return {};
|
|
383
|
+
}
|
|
384
|
+
const clone = Object.assign({}, object);
|
|
385
|
+
Object.keys(clone).forEach((key) => {
|
|
386
|
+
if (typeof object[key] === "object" && !ArrayBuffer.isView(object[key]) && !(object[key] instanceof Array)) {
|
|
387
|
+
clone[key] = getTransferListForWriter(object[key]);
|
|
388
|
+
} else if (typeof clone[key] === "function" || clone[key] instanceof RegExp) {
|
|
389
|
+
clone[key] = {};
|
|
390
|
+
} else {
|
|
391
|
+
clone[key] = object[key];
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
return clone;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// ../worker-utils/src/lib/worker-farm/worker-thread.ts
|
|
398
|
+
var NOOP = () => {
|
|
399
|
+
};
|
|
400
|
+
var WorkerThread = class {
|
|
401
|
+
name;
|
|
402
|
+
source;
|
|
403
|
+
url;
|
|
404
|
+
terminated = false;
|
|
405
|
+
worker;
|
|
406
|
+
onMessage;
|
|
407
|
+
onError;
|
|
408
|
+
_loadableURL = "";
|
|
409
|
+
/** Checks if workers are supported on this platform */
|
|
410
|
+
static isSupported() {
|
|
411
|
+
return typeof Worker !== "undefined" && isBrowser2 || typeof NodeWorker !== "undefined" && !isBrowser2;
|
|
412
|
+
}
|
|
413
|
+
constructor(props) {
|
|
414
|
+
const { name, source, url } = props;
|
|
415
|
+
assert2(source || url);
|
|
416
|
+
this.name = name;
|
|
417
|
+
this.source = source;
|
|
418
|
+
this.url = url;
|
|
419
|
+
this.onMessage = NOOP;
|
|
420
|
+
this.onError = (error) => console.log(error);
|
|
421
|
+
this.worker = isBrowser2 ? this._createBrowserWorker() : this._createNodeWorker();
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Terminate this worker thread
|
|
425
|
+
* @note Can free up significant memory
|
|
426
|
+
*/
|
|
427
|
+
destroy() {
|
|
428
|
+
this.onMessage = NOOP;
|
|
429
|
+
this.onError = NOOP;
|
|
430
|
+
this.worker.terminate();
|
|
431
|
+
this.terminated = true;
|
|
432
|
+
}
|
|
433
|
+
/** Keeps this worker from preventing Node.js process exit while idle. */
|
|
434
|
+
unref() {
|
|
435
|
+
if (!isBrowser2 && typeof this.worker.unref === "function") {
|
|
436
|
+
this.worker.unref();
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
/** Keeps this worker alive while it is actively processing a job. */
|
|
440
|
+
ref() {
|
|
441
|
+
if (!isBrowser2 && typeof this.worker.ref === "function") {
|
|
442
|
+
this.worker.ref();
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
get isRunning() {
|
|
446
|
+
return Boolean(this.onMessage);
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Send a message to this worker thread
|
|
450
|
+
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
451
|
+
* @param transferList If not supplied, calculated automatically by traversing data
|
|
452
|
+
*/
|
|
453
|
+
postMessage(data, transferList) {
|
|
454
|
+
transferList = transferList || getTransferList(data);
|
|
455
|
+
this.worker.postMessage(data, transferList);
|
|
456
|
+
}
|
|
457
|
+
// PRIVATE
|
|
458
|
+
/**
|
|
459
|
+
* Generate a standard Error from an ErrorEvent
|
|
460
|
+
* @param event
|
|
461
|
+
*/
|
|
462
|
+
_getErrorFromErrorEvent(event) {
|
|
463
|
+
let message = "Failed to load ";
|
|
464
|
+
message += `worker ${this.name} from ${this.url}. `;
|
|
465
|
+
if (event.message) {
|
|
466
|
+
message += `${event.message} in `;
|
|
467
|
+
}
|
|
468
|
+
if (event.lineno) {
|
|
469
|
+
message += `:${event.lineno}:${event.colno}`;
|
|
470
|
+
}
|
|
471
|
+
return new Error(message);
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Creates a worker thread on the browser
|
|
475
|
+
*/
|
|
476
|
+
_createBrowserWorker() {
|
|
477
|
+
this._loadableURL = getLoadableWorkerURL({ source: this.source, url: this.url });
|
|
478
|
+
const worker = new Worker(this._loadableURL, { name: this.name });
|
|
479
|
+
worker.onmessage = (event) => {
|
|
480
|
+
if (!event.data) {
|
|
481
|
+
this.onError(new Error("No data received"));
|
|
482
|
+
} else {
|
|
483
|
+
this.onMessage(event.data);
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
worker.onerror = (error) => {
|
|
487
|
+
this.onError(this._getErrorFromErrorEvent(error));
|
|
488
|
+
this.terminated = true;
|
|
489
|
+
};
|
|
490
|
+
worker.onmessageerror = (event) => console.error(event);
|
|
491
|
+
return worker;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Creates a worker thread in node.js
|
|
495
|
+
* @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool
|
|
496
|
+
*/
|
|
497
|
+
_createNodeWorker() {
|
|
498
|
+
let worker;
|
|
499
|
+
if (this.url) {
|
|
500
|
+
const absolute = this.url.includes(":/") || this.url.startsWith("/");
|
|
501
|
+
const url = absolute ? this.url : `./${this.url}`;
|
|
502
|
+
const workerUrl = url.startsWith("file:") ? new URL(url) : url;
|
|
503
|
+
const type = this.url.endsWith(".ts") || this.url.endsWith(".mjs") ? "module" : "commonjs";
|
|
504
|
+
worker = new NodeWorker(workerUrl, { eval: false, type });
|
|
505
|
+
} else if (this.source) {
|
|
506
|
+
worker = new NodeWorker(this.source, { eval: true });
|
|
507
|
+
} else {
|
|
508
|
+
throw new Error("no worker");
|
|
509
|
+
}
|
|
510
|
+
worker.on("message", (data) => {
|
|
511
|
+
this.onMessage(data);
|
|
512
|
+
});
|
|
513
|
+
worker.on("error", (error) => {
|
|
514
|
+
this.onError(error);
|
|
515
|
+
});
|
|
516
|
+
worker.on("exit", (_code) => {
|
|
517
|
+
});
|
|
518
|
+
return worker;
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
// ../worker-utils/src/lib/worker-farm/worker-pool.ts
|
|
523
|
+
var WorkerPool = class {
|
|
524
|
+
name = "unnamed";
|
|
525
|
+
source;
|
|
526
|
+
// | Function;
|
|
527
|
+
url;
|
|
528
|
+
maxConcurrency = 1;
|
|
529
|
+
maxMobileConcurrency = 1;
|
|
530
|
+
onDebug = () => {
|
|
531
|
+
};
|
|
532
|
+
reuseWorkers = true;
|
|
533
|
+
props = {};
|
|
534
|
+
jobQueue = [];
|
|
535
|
+
idleQueue = [];
|
|
536
|
+
count = 0;
|
|
537
|
+
isDestroyed = false;
|
|
538
|
+
/** Checks if workers are supported on this platform */
|
|
539
|
+
static isSupported() {
|
|
540
|
+
return WorkerThread.isSupported();
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* @param processor - worker function
|
|
544
|
+
* @param maxConcurrency - max count of workers
|
|
545
|
+
*/
|
|
546
|
+
constructor(props) {
|
|
547
|
+
this.source = props.source;
|
|
548
|
+
this.url = props.url;
|
|
549
|
+
this.setProps(props);
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Terminates all workers in the pool
|
|
553
|
+
* @note Can free up significant memory
|
|
554
|
+
*/
|
|
555
|
+
destroy() {
|
|
556
|
+
this.idleQueue.forEach((worker) => worker.destroy());
|
|
557
|
+
this.isDestroyed = true;
|
|
558
|
+
}
|
|
559
|
+
setProps(props) {
|
|
560
|
+
this.props = { ...this.props, ...props };
|
|
561
|
+
if (props.name !== void 0) {
|
|
562
|
+
this.name = props.name;
|
|
563
|
+
}
|
|
564
|
+
if (props.maxConcurrency !== void 0) {
|
|
565
|
+
this.maxConcurrency = props.maxConcurrency;
|
|
566
|
+
}
|
|
567
|
+
if (props.maxMobileConcurrency !== void 0) {
|
|
568
|
+
this.maxMobileConcurrency = props.maxMobileConcurrency;
|
|
569
|
+
}
|
|
570
|
+
if (props.reuseWorkers !== void 0) {
|
|
571
|
+
this.reuseWorkers = props.reuseWorkers;
|
|
572
|
+
}
|
|
573
|
+
if (props.onDebug !== void 0) {
|
|
574
|
+
this.onDebug = props.onDebug;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
async startJob(name, onMessage2 = (job, type, data) => job.done(data), onError = (job, error) => job.error(error)) {
|
|
578
|
+
const startPromise = new Promise((onStart) => {
|
|
579
|
+
this.jobQueue.push({ name, onMessage: onMessage2, onError, onStart });
|
|
580
|
+
return this;
|
|
581
|
+
});
|
|
582
|
+
this._startQueuedJob();
|
|
583
|
+
return await startPromise;
|
|
584
|
+
}
|
|
585
|
+
// PRIVATE
|
|
586
|
+
/**
|
|
587
|
+
* Starts first queued job if worker is available or can be created
|
|
588
|
+
* Called when job is started and whenever a worker returns to the idleQueue
|
|
589
|
+
*/
|
|
590
|
+
async _startQueuedJob() {
|
|
591
|
+
if (!this.jobQueue.length) {
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
const workerThread = this._getAvailableWorker();
|
|
595
|
+
if (!workerThread) {
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
const queuedJob = this.jobQueue.shift();
|
|
599
|
+
if (queuedJob) {
|
|
600
|
+
this.onDebug({
|
|
601
|
+
message: "Starting job",
|
|
602
|
+
name: queuedJob.name,
|
|
603
|
+
workerThread,
|
|
604
|
+
backlog: this.jobQueue.length
|
|
605
|
+
});
|
|
606
|
+
const job = new WorkerJob(queuedJob.name, workerThread);
|
|
607
|
+
workerThread.ref();
|
|
608
|
+
workerThread.onMessage = (data) => queuedJob.onMessage(job, data.type, data.payload);
|
|
609
|
+
workerThread.onError = (error) => queuedJob.onError(job, error);
|
|
610
|
+
queuedJob.onStart(job);
|
|
611
|
+
try {
|
|
612
|
+
await job.result;
|
|
613
|
+
} catch {
|
|
614
|
+
} finally {
|
|
615
|
+
this.returnWorkerToQueue(workerThread);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Returns a worker to the idle queue
|
|
621
|
+
* Destroys the worker if
|
|
622
|
+
* - pool is destroyed
|
|
623
|
+
* - if this pool doesn't reuse workers
|
|
624
|
+
* - if maxConcurrency has been lowered
|
|
625
|
+
* @param worker
|
|
626
|
+
*/
|
|
627
|
+
returnWorkerToQueue(worker) {
|
|
628
|
+
const shouldDestroyWorker = (
|
|
629
|
+
// Aborted jobs terminate their worker immediately.
|
|
630
|
+
worker.terminated || // If the pool is destroyed, there is no reason to keep the worker around
|
|
631
|
+
this.isDestroyed || // If the app has disabled worker reuse, any completed workers should be destroyed
|
|
632
|
+
!this.reuseWorkers || // If concurrency has been lowered, this worker might be surplus to requirements
|
|
633
|
+
this.count > this._getMaxConcurrency()
|
|
634
|
+
);
|
|
635
|
+
if (shouldDestroyWorker) {
|
|
636
|
+
if (!worker.terminated) {
|
|
637
|
+
worker.destroy();
|
|
638
|
+
}
|
|
639
|
+
this.count--;
|
|
640
|
+
} else {
|
|
641
|
+
worker.unref();
|
|
642
|
+
this.idleQueue.push(worker);
|
|
643
|
+
}
|
|
644
|
+
if (!this.isDestroyed) {
|
|
645
|
+
this._startQueuedJob();
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Returns idle worker or creates new worker if maxConcurrency has not been reached
|
|
650
|
+
*/
|
|
651
|
+
_getAvailableWorker() {
|
|
652
|
+
if (this.idleQueue.length > 0) {
|
|
653
|
+
return this.idleQueue.shift() || null;
|
|
654
|
+
}
|
|
655
|
+
if (this.count < this._getMaxConcurrency()) {
|
|
656
|
+
this.count++;
|
|
657
|
+
const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;
|
|
658
|
+
return new WorkerThread({ name, source: this.source, url: this.url });
|
|
659
|
+
}
|
|
660
|
+
return null;
|
|
661
|
+
}
|
|
662
|
+
_getMaxConcurrency() {
|
|
663
|
+
return isMobile ? this.maxMobileConcurrency : this.maxConcurrency;
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
|
|
667
|
+
// ../worker-utils/src/lib/worker-farm/worker-farm.ts
|
|
668
|
+
var DEFAULT_PROPS = {
|
|
669
|
+
maxConcurrency: 3,
|
|
670
|
+
maxMobileConcurrency: 1,
|
|
671
|
+
reuseWorkers: true,
|
|
672
|
+
onDebug: () => {
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
var WorkerFarm = class _WorkerFarm {
|
|
676
|
+
props;
|
|
677
|
+
workerPools = /* @__PURE__ */ new Map();
|
|
678
|
+
// singleton
|
|
679
|
+
static _workerFarm;
|
|
680
|
+
/** Checks if workers are supported on this platform */
|
|
681
|
+
static isSupported() {
|
|
682
|
+
return WorkerThread.isSupported();
|
|
683
|
+
}
|
|
684
|
+
/** Get the singleton instance of the global worker farm */
|
|
685
|
+
static getWorkerFarm(props = {}) {
|
|
686
|
+
_WorkerFarm._workerFarm = _WorkerFarm._workerFarm || new _WorkerFarm({});
|
|
687
|
+
_WorkerFarm._workerFarm.setProps(props);
|
|
688
|
+
return _WorkerFarm._workerFarm;
|
|
689
|
+
}
|
|
690
|
+
/** get global instance with WorkerFarm.getWorkerFarm() */
|
|
691
|
+
constructor(props) {
|
|
692
|
+
this.props = { ...DEFAULT_PROPS };
|
|
693
|
+
this.setProps(props);
|
|
694
|
+
this.workerPools = /* @__PURE__ */ new Map();
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Terminate all workers in the farm
|
|
698
|
+
* @note Can free up significant memory
|
|
699
|
+
*/
|
|
700
|
+
destroy() {
|
|
701
|
+
for (const workerPool of this.workerPools.values()) {
|
|
702
|
+
workerPool.destroy();
|
|
703
|
+
}
|
|
704
|
+
this.workerPools = /* @__PURE__ */ new Map();
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Set props used when initializing worker pools
|
|
708
|
+
* @param props
|
|
709
|
+
*/
|
|
710
|
+
setProps(props) {
|
|
711
|
+
this.props = { ...this.props, ...props };
|
|
712
|
+
for (const workerPool of this.workerPools.values()) {
|
|
713
|
+
workerPool.setProps(this._getWorkerPoolProps());
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Returns a worker pool for the specified worker
|
|
718
|
+
* @param options - only used first time for a specific worker name
|
|
719
|
+
* @param options.name - the name of the worker - used to identify worker pool
|
|
720
|
+
* @param options.url -
|
|
721
|
+
* @param options.source -
|
|
722
|
+
* @example
|
|
723
|
+
* const job = WorkerFarm.getWorkerFarm().getWorkerPool({name, url}).startJob(...);
|
|
724
|
+
*/
|
|
725
|
+
getWorkerPool(options) {
|
|
726
|
+
const { name, source, url } = options;
|
|
727
|
+
let workerPool = this.workerPools.get(name);
|
|
728
|
+
if (!workerPool) {
|
|
729
|
+
workerPool = new WorkerPool({
|
|
730
|
+
name,
|
|
731
|
+
source,
|
|
732
|
+
url
|
|
733
|
+
});
|
|
734
|
+
workerPool.setProps(this._getWorkerPoolProps());
|
|
735
|
+
this.workerPools.set(name, workerPool);
|
|
736
|
+
}
|
|
737
|
+
return workerPool;
|
|
738
|
+
}
|
|
739
|
+
_getWorkerPoolProps() {
|
|
740
|
+
return {
|
|
741
|
+
maxConcurrency: this.props.maxConcurrency,
|
|
742
|
+
maxMobileConcurrency: this.props.maxMobileConcurrency,
|
|
743
|
+
reuseWorkers: this.props.reuseWorkers,
|
|
744
|
+
onDebug: this.props.onDebug
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
|
|
749
|
+
// ../worker-utils/src/lib/worker-api/get-worker-url.ts
|
|
750
|
+
var warnedWorkerVersionFallbacks = /* @__PURE__ */ new Set();
|
|
751
|
+
function getWorkerName(worker) {
|
|
752
|
+
const warning = worker.version !== VERSION2 ? ` (worker-utils@${VERSION2})` : "";
|
|
753
|
+
return `${worker.name}@${worker.version}${warning}`;
|
|
754
|
+
}
|
|
755
|
+
function getWorkerURL(worker, options = {}) {
|
|
756
|
+
var _a;
|
|
757
|
+
const workerOptions = options[worker.id] || {};
|
|
758
|
+
const workerFile = isBrowser2 ? `${worker.id}-worker.js` : worker.workerNode || `${worker.id}-worker-node.js`;
|
|
759
|
+
let url = workerOptions.workerUrl;
|
|
760
|
+
if (!url && typeof worker.worker === "string") {
|
|
761
|
+
url = worker.worker;
|
|
762
|
+
}
|
|
763
|
+
if (!url && worker.id === "compression") {
|
|
764
|
+
url = options.workerUrl;
|
|
765
|
+
}
|
|
766
|
+
const workerType = options._workerType || ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a._workerType);
|
|
767
|
+
if (workerType === "test") {
|
|
768
|
+
if (isBrowser2) {
|
|
769
|
+
url = `modules/${worker.module}/dist/${workerFile}`;
|
|
770
|
+
} else {
|
|
771
|
+
url = `modules/${worker.module}/src/workers/${worker.id}-worker-node.ts`;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
if (!url) {
|
|
775
|
+
let version2 = worker.version;
|
|
776
|
+
if (version2 === "latest") {
|
|
777
|
+
version2 = NPM_TAG;
|
|
778
|
+
}
|
|
779
|
+
const versionTag = version2 ? `@${version2}` : "";
|
|
780
|
+
url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;
|
|
781
|
+
warnIfUsingNpmTagFallback(worker, url);
|
|
782
|
+
}
|
|
783
|
+
assert2(url);
|
|
784
|
+
return url;
|
|
785
|
+
}
|
|
786
|
+
function warnIfUsingNpmTagFallback(worker, url) {
|
|
787
|
+
if (worker.version !== "latest") {
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
const workerId = `${worker.module}:${worker.id}`;
|
|
791
|
+
if (warnedWorkerVersionFallbacks.has(workerId)) {
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
warnedWorkerVersionFallbacks.add(workerId);
|
|
795
|
+
console.warn(
|
|
796
|
+
`loaders.gl: ${worker.name} loader worker version is "latest" because __VERSION__ was not injected. Fetching ${url} from CDN.`
|
|
797
|
+
);
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// ../worker-utils/src/lib/worker-api/process-on-worker.ts
|
|
801
|
+
function canProcessOnWorker(worker, options) {
|
|
802
|
+
if (!WorkerFarm.isSupported()) {
|
|
803
|
+
return false;
|
|
804
|
+
}
|
|
805
|
+
const workerOptions = options == null ? void 0 : options[worker.id];
|
|
806
|
+
return Boolean((worker.worker || (workerOptions == null ? void 0 : workerOptions.workerUrl)) && (options == null ? void 0 : options.worker));
|
|
807
|
+
}
|
|
808
|
+
async function processOnWorker(worker, data, options = {}, context = {}, jobContext = {}) {
|
|
809
|
+
var _a, _b, _c;
|
|
810
|
+
throwIfAborted(options.signal);
|
|
811
|
+
const name = getWorkerName(worker);
|
|
812
|
+
const workerFarm = WorkerFarm.getWorkerFarm(options);
|
|
813
|
+
const { source } = options;
|
|
814
|
+
const workerPoolProps = { name, source };
|
|
815
|
+
if (!source) {
|
|
816
|
+
workerPoolProps.url = getWorkerURL(worker, options);
|
|
817
|
+
}
|
|
818
|
+
const workerPool = workerFarm.getWorkerPool(workerPoolProps);
|
|
819
|
+
const jobName = options.jobName || worker.name;
|
|
820
|
+
const job = await workerPool.startJob(
|
|
821
|
+
jobName,
|
|
822
|
+
// eslint-disable-next-line
|
|
823
|
+
onMessage.bind(null, context)
|
|
824
|
+
);
|
|
825
|
+
const abortJob = () => job.abort(getAbortReason(options.signal));
|
|
826
|
+
(_a = options.signal) == null ? void 0 : _a.addEventListener("abort", abortJob, { once: true });
|
|
827
|
+
if ((_b = options.signal) == null ? void 0 : _b.aborted) {
|
|
828
|
+
abortJob();
|
|
829
|
+
}
|
|
830
|
+
try {
|
|
831
|
+
const { signal: _signal, ...workerOptions } = options;
|
|
832
|
+
const transferableOptions = getTransferListForWriter(workerOptions);
|
|
833
|
+
const transferableContext = getTransferListForWriter(jobContext);
|
|
834
|
+
if (job.isRunning) {
|
|
835
|
+
job.postMessage("process", {
|
|
836
|
+
input: data,
|
|
837
|
+
options: transferableOptions,
|
|
838
|
+
context: transferableContext
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
const result = await job.result;
|
|
842
|
+
return result.result;
|
|
843
|
+
} finally {
|
|
844
|
+
(_c = options.signal) == null ? void 0 : _c.removeEventListener("abort", abortJob);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
function throwIfAborted(signal) {
|
|
848
|
+
if (!(signal == null ? void 0 : signal.aborted)) {
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
throw getAbortReason(signal);
|
|
852
|
+
}
|
|
853
|
+
function getAbortReason(signal) {
|
|
854
|
+
return (signal == null ? void 0 : signal.reason) ?? createAbortError2("Worker job was aborted");
|
|
855
|
+
}
|
|
856
|
+
function createAbortError2(message) {
|
|
857
|
+
const error = new Error(message);
|
|
858
|
+
error.name = "AbortError";
|
|
859
|
+
return error;
|
|
860
|
+
}
|
|
861
|
+
async function onMessage(context, job, type, payload) {
|
|
862
|
+
switch (type) {
|
|
863
|
+
case "done":
|
|
864
|
+
job.done(payload);
|
|
865
|
+
break;
|
|
866
|
+
case "error":
|
|
867
|
+
job.error(new Error(payload.error));
|
|
868
|
+
break;
|
|
869
|
+
case "process":
|
|
870
|
+
const { id, input, options } = payload;
|
|
871
|
+
try {
|
|
872
|
+
if (!context.process) {
|
|
873
|
+
job.postMessage("error", { id, error: "Worker not set up to process on main thread" });
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
const result = await context.process(input, options, void 0, payload.context || {});
|
|
877
|
+
job.postMessage("done", { id, result });
|
|
878
|
+
} catch (error) {
|
|
879
|
+
const message = error instanceof Error ? error.message : "unknown error";
|
|
880
|
+
job.postMessage("error", { id, error: message });
|
|
881
|
+
}
|
|
882
|
+
break;
|
|
883
|
+
default:
|
|
884
|
+
console.warn(`process-on-worker: unknown message ${type}`);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
// ../worker-utils/src/lib/worker-api/validate-worker-version.ts
|
|
889
|
+
function validateWorkerVersion(worker, coreVersion = VERSION2) {
|
|
890
|
+
assert2(worker, "no worker provided");
|
|
891
|
+
const workerVersion = worker.version;
|
|
892
|
+
if (!coreVersion || !workerVersion) {
|
|
893
|
+
return false;
|
|
894
|
+
}
|
|
895
|
+
return true;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
// ../loader-utils/src/lib/worker-loader-utils/parse-with-worker.ts
|
|
899
|
+
function canParseWithWorker(loader, options) {
|
|
900
|
+
var _a, _b;
|
|
901
|
+
const workerOptions = getWorkerOptions(options);
|
|
902
|
+
const nodeWorkers = workerOptions._nodeWorkers;
|
|
903
|
+
if (!isBrowser2 && !nodeWorkers) {
|
|
904
|
+
return false;
|
|
905
|
+
}
|
|
906
|
+
if (loader.id === "excel" && ((_a = options == null ? void 0 : options.excel) == null ? void 0 : _a.shape) === "arrow-table" || loader.id === "ply" && ((_b = options == null ? void 0 : options.ply) == null ? void 0 : _b.shape) === "arrow-table") {
|
|
907
|
+
return false;
|
|
908
|
+
}
|
|
909
|
+
if (loader.id === "csv" && !shouldParseCSVWithWorker(options)) {
|
|
910
|
+
return false;
|
|
911
|
+
}
|
|
912
|
+
return Boolean(canProcessOnWorker(loader, workerOptions));
|
|
913
|
+
}
|
|
914
|
+
async function parseWithWorker(loader, data, options, context, parseOnMainThread, signal) {
|
|
915
|
+
const workerSignal = signal || getWorkerAbortSignal(options);
|
|
916
|
+
const result = await processOnWorker(
|
|
917
|
+
loader,
|
|
918
|
+
data,
|
|
919
|
+
{ ...getWorkerOptions(options), signal: workerSignal },
|
|
920
|
+
{
|
|
921
|
+
process: async (input, processOptions, _workerContext, parseContext) => {
|
|
922
|
+
if (!parseOnMainThread) {
|
|
923
|
+
throw new Error("Worker not set up to parse on main thread");
|
|
924
|
+
}
|
|
925
|
+
const mainThreadContext = context ? { ...context, ...parseContext || {} } : void 0;
|
|
926
|
+
return await callParseOnMainThread(
|
|
927
|
+
parseOnMainThread,
|
|
928
|
+
input,
|
|
929
|
+
processOptions,
|
|
930
|
+
mainThreadContext
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
},
|
|
934
|
+
getSerializableLoaderContext(context)
|
|
935
|
+
);
|
|
936
|
+
return isLoaderWithWorkerResultDeserializer(loader) ? loader.deserializeWorkerResult(result, options, context) : result;
|
|
937
|
+
}
|
|
938
|
+
function getWorkerAbortSignal(options) {
|
|
939
|
+
var _a;
|
|
940
|
+
const parquetSignal = (_a = options == null ? void 0 : options.parquet) == null ? void 0 : _a.signal;
|
|
941
|
+
if (typeof AbortSignal !== "undefined" && parquetSignal instanceof AbortSignal) {
|
|
942
|
+
return parquetSignal;
|
|
943
|
+
}
|
|
944
|
+
return void 0;
|
|
945
|
+
}
|
|
946
|
+
function callParseOnMainThread(parseOnMainThread, input, options, context) {
|
|
947
|
+
if (parseOnMainThread.length <= 2) {
|
|
948
|
+
return parseOnMainThread(input, options);
|
|
949
|
+
}
|
|
950
|
+
return parseOnMainThread(input, void 0, options, context);
|
|
951
|
+
}
|
|
952
|
+
function getWorkerOptions(options = {}) {
|
|
953
|
+
const serializedOptions = JSON.parse(JSON.stringify(options));
|
|
954
|
+
return {
|
|
955
|
+
...serializedOptions.core,
|
|
956
|
+
...serializedOptions
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
function getSerializableLoaderContext(context) {
|
|
960
|
+
if (!context) {
|
|
961
|
+
return {};
|
|
962
|
+
}
|
|
963
|
+
const { fetch: fetch2, loaders, coreApi: coreApi2, _parse, _parseSync, _parseInBatches, ...serializableContext } = context;
|
|
964
|
+
return JSON.parse(JSON.stringify(serializableContext));
|
|
965
|
+
}
|
|
966
|
+
function shouldParseCSVWithWorker(options) {
|
|
967
|
+
var _a, _b;
|
|
968
|
+
const csvOptions = options;
|
|
969
|
+
return (((_a = csvOptions == null ? void 0 : csvOptions.csv) == null ? void 0 : _a.shape) ?? ((_b = csvOptions == null ? void 0 : csvOptions.core) == null ? void 0 : _b.shape)) === "arrow-table";
|
|
970
|
+
}
|
|
971
|
+
function isLoaderWithWorkerResultDeserializer(loader) {
|
|
972
|
+
return typeof loader.deserializeWorkerResult === "function";
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
// ../loader-utils/src/lib/worker-loader-utils/encode-with-worker.ts
|
|
976
|
+
function canEncodeWithWorker(writer, options) {
|
|
977
|
+
var _a, _b;
|
|
978
|
+
if (!WorkerFarm.isSupported()) {
|
|
979
|
+
return false;
|
|
980
|
+
}
|
|
981
|
+
const nodeWorkers = (options == null ? void 0 : options._nodeWorkers) ?? ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a._nodeWorkers);
|
|
982
|
+
const useWorkers = (options == null ? void 0 : options.worker) ?? ((_b = options == null ? void 0 : options.core) == null ? void 0 : _b.worker);
|
|
983
|
+
if (!isBrowser && !nodeWorkers) {
|
|
984
|
+
return false;
|
|
985
|
+
}
|
|
986
|
+
return Boolean(writer.worker && useWorkers);
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
// ../loader-utils/src/lib/binary-utils/array-buffer-utils.ts
|
|
990
|
+
function compareArrayBuffers(arrayBuffer1, arrayBuffer2, byteLength) {
|
|
991
|
+
byteLength = byteLength || arrayBuffer1.byteLength;
|
|
992
|
+
if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) {
|
|
993
|
+
return false;
|
|
994
|
+
}
|
|
995
|
+
const array1 = new Uint8Array(arrayBuffer1);
|
|
996
|
+
const array2 = new Uint8Array(arrayBuffer2);
|
|
997
|
+
for (let i = 0; i < array1.length; ++i) {
|
|
998
|
+
if (array1[i] !== array2[i]) {
|
|
999
|
+
return false;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
return true;
|
|
1003
|
+
}
|
|
1004
|
+
function concatenateArrayBuffers(...sources) {
|
|
1005
|
+
return concatenateArrayBuffersFromArray(sources);
|
|
1006
|
+
}
|
|
1007
|
+
function concatenateArrayBuffersFromArray(sources) {
|
|
1008
|
+
const sourceArrays = sources.map(
|
|
1009
|
+
(source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
|
|
1010
|
+
);
|
|
1011
|
+
const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
|
|
1012
|
+
const result = new Uint8Array(byteLength);
|
|
1013
|
+
let offset = 0;
|
|
1014
|
+
for (const sourceArray of sourceArrays) {
|
|
1015
|
+
result.set(sourceArray, offset);
|
|
1016
|
+
offset += sourceArray.byteLength;
|
|
1017
|
+
}
|
|
1018
|
+
return result.buffer;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
// ../loader-utils/src/lib/iterators/text-iterators.ts
|
|
1022
|
+
async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
|
|
1023
|
+
const textDecoder = new TextDecoder(void 0, options);
|
|
1024
|
+
for await (const arrayBuffer of arrayBufferIterator) {
|
|
1025
|
+
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, { stream: true });
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
async function* makeTextEncoderIterator(textIterator) {
|
|
1029
|
+
const textEncoder = new TextEncoder();
|
|
1030
|
+
for await (const text of textIterator) {
|
|
1031
|
+
yield typeof text === "string" ? textEncoder.encode(text).buffer : text;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
async function* makeLineIterator(textIterator) {
|
|
1035
|
+
let previous = "";
|
|
1036
|
+
for await (const textChunk of textIterator) {
|
|
1037
|
+
previous += textChunk;
|
|
1038
|
+
let eolIndex;
|
|
1039
|
+
eolIndex = previous.indexOf("\n");
|
|
1040
|
+
while (eolIndex >= 0) {
|
|
1041
|
+
const line = previous.slice(0, eolIndex + 1);
|
|
1042
|
+
previous = previous.slice(eolIndex + 1);
|
|
1043
|
+
yield line;
|
|
1044
|
+
eolIndex = previous.indexOf("\n");
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
if (previous.length > 0) {
|
|
1048
|
+
yield previous;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
async function* makeNumberedLineIterator(lineIterator) {
|
|
1052
|
+
let counter = 1;
|
|
1053
|
+
for await (const line of lineIterator) {
|
|
1054
|
+
yield { counter, line };
|
|
1055
|
+
counter++;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
// ../loader-utils/src/lib/iterators/async-iteration.ts
|
|
1060
|
+
async function forEach(iterable, visitor) {
|
|
1061
|
+
const iterator = toAsyncIterator(iterable);
|
|
1062
|
+
while (true) {
|
|
1063
|
+
const { done, value } = await iterator.next();
|
|
1064
|
+
if (done) {
|
|
1065
|
+
if (iterator.return) {
|
|
1066
|
+
iterator.return();
|
|
1067
|
+
}
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
const cancel = visitor(value);
|
|
1071
|
+
if (cancel) {
|
|
1072
|
+
return;
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
async function concatenateArrayBuffersAsync(asyncIterator) {
|
|
1077
|
+
const arrayBuffers = [];
|
|
1078
|
+
for await (const chunk of asyncIterator) {
|
|
1079
|
+
arrayBuffers.push(copyToArrayBuffer(chunk));
|
|
1080
|
+
}
|
|
1081
|
+
return concatenateArrayBuffers(...arrayBuffers);
|
|
1082
|
+
}
|
|
1083
|
+
function copyToArrayBuffer(chunk) {
|
|
1084
|
+
if (chunk instanceof ArrayBuffer) {
|
|
1085
|
+
return chunk;
|
|
1086
|
+
}
|
|
1087
|
+
if (ArrayBuffer.isView(chunk)) {
|
|
1088
|
+
const { buffer, byteOffset, byteLength } = chunk;
|
|
1089
|
+
return copyFromBuffer(buffer, byteOffset, byteLength);
|
|
1090
|
+
}
|
|
1091
|
+
return copyFromBuffer(chunk);
|
|
1092
|
+
}
|
|
1093
|
+
function copyFromBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
|
|
1094
|
+
const view = new Uint8Array(buffer, byteOffset, byteLength);
|
|
1095
|
+
const copy = new Uint8Array(view.length);
|
|
1096
|
+
copy.set(view);
|
|
1097
|
+
return copy.buffer;
|
|
1098
|
+
}
|
|
1099
|
+
function toAsyncIterator(iterable) {
|
|
1100
|
+
if (typeof iterable[Symbol.asyncIterator] === "function") {
|
|
1101
|
+
return iterable[Symbol.asyncIterator]();
|
|
1102
|
+
}
|
|
1103
|
+
if (typeof iterable[Symbol.iterator] === "function") {
|
|
1104
|
+
const iterator = iterable[Symbol.iterator]();
|
|
1105
|
+
return iteratorToAsyncIterator(iterator);
|
|
1106
|
+
}
|
|
1107
|
+
return iterable;
|
|
1108
|
+
}
|
|
1109
|
+
function iteratorToAsyncIterator(iterator) {
|
|
1110
|
+
return {
|
|
1111
|
+
next(value) {
|
|
1112
|
+
return Promise.resolve(iterator.next(value));
|
|
1113
|
+
},
|
|
1114
|
+
return(value) {
|
|
1115
|
+
if (typeof iterator.return === "function") {
|
|
1116
|
+
return Promise.resolve(iterator.return(value));
|
|
1117
|
+
}
|
|
1118
|
+
return Promise.resolve({ done: true, value });
|
|
1119
|
+
},
|
|
1120
|
+
throw(error) {
|
|
1121
|
+
if (typeof iterator.throw === "function") {
|
|
1122
|
+
return Promise.resolve(iterator.throw(error));
|
|
1123
|
+
}
|
|
1124
|
+
return Promise.reject(error);
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
// ../loader-utils/src/lib/request-utils/request-scheduler.ts
|
|
1130
|
+
var import_stats = require("@probe.gl/stats");
|
|
1131
|
+
var STAT_QUEUED_REQUESTS = "Queued Requests";
|
|
1132
|
+
var STAT_ACTIVE_REQUESTS = "Active Requests";
|
|
1133
|
+
var STAT_CANCELLED_REQUESTS = "Cancelled Requests";
|
|
1134
|
+
var STAT_QUEUED_REQUESTS_EVER = "Queued Requests Ever";
|
|
1135
|
+
var STAT_ACTIVE_REQUESTS_EVER = "Active Requests Ever";
|
|
1136
|
+
var DEFAULT_PROPS2 = {
|
|
1137
|
+
id: "request-scheduler",
|
|
1138
|
+
/** Specifies if the request scheduler should throttle incoming requests, mainly for comparative testing. */
|
|
1139
|
+
throttleRequests: true,
|
|
1140
|
+
/** The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit. */
|
|
1141
|
+
maxRequests: 6,
|
|
1142
|
+
/**
|
|
1143
|
+
* Specifies a debounce time, in milliseconds. All requests are queued, until no new requests have
|
|
1144
|
+
* been added to the queue for this amount of time.
|
|
1145
|
+
*/
|
|
1146
|
+
debounceTime: 0
|
|
1147
|
+
};
|
|
1148
|
+
var RequestScheduler = class {
|
|
1149
|
+
props;
|
|
1150
|
+
stats;
|
|
1151
|
+
activeRequestCount = 0;
|
|
1152
|
+
/** Tracks the number of active requests and prioritizes/cancels queued requests. */
|
|
1153
|
+
requestQueue = [];
|
|
1154
|
+
requestMap = /* @__PURE__ */ new Map();
|
|
1155
|
+
updateTimer = null;
|
|
1156
|
+
constructor(props = {}) {
|
|
1157
|
+
this.props = { ...DEFAULT_PROPS2, ...props };
|
|
1158
|
+
this.stats = new import_stats.Stats({ id: this.props.id });
|
|
1159
|
+
this.stats.get(STAT_QUEUED_REQUESTS);
|
|
1160
|
+
this.stats.get(STAT_ACTIVE_REQUESTS);
|
|
1161
|
+
this.stats.get(STAT_CANCELLED_REQUESTS);
|
|
1162
|
+
this.stats.get(STAT_QUEUED_REQUESTS_EVER);
|
|
1163
|
+
this.stats.get(STAT_ACTIVE_REQUESTS_EVER);
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* Update scheduler props. Preserves active and queued requests.
|
|
1167
|
+
*/
|
|
1168
|
+
setProps(props) {
|
|
1169
|
+
if (props.throttleRequests !== void 0) {
|
|
1170
|
+
this.props.throttleRequests = props.throttleRequests;
|
|
1171
|
+
}
|
|
1172
|
+
if (props.maxRequests !== void 0) {
|
|
1173
|
+
this.props.maxRequests = props.maxRequests;
|
|
1174
|
+
}
|
|
1175
|
+
if (props.debounceTime !== void 0) {
|
|
1176
|
+
this.props.debounceTime = props.debounceTime;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
/**
|
|
1180
|
+
* Called by an application that wants to issue a request, without having it deeply queued by the browser
|
|
1181
|
+
*
|
|
1182
|
+
* When the returned promise resolved, it is OK for the application to issue a request.
|
|
1183
|
+
* The promise resolves to an object that contains a `done` method.
|
|
1184
|
+
* When the application's request has completed (or failed), the application must call the `done` function
|
|
1185
|
+
*
|
|
1186
|
+
* @param handle
|
|
1187
|
+
* @param getPriority will be called when request "slots" open up,
|
|
1188
|
+
* allowing the caller to update priority or cancel the request
|
|
1189
|
+
* Highest priority executes first, priority < 0 cancels the request
|
|
1190
|
+
* @returns a promise
|
|
1191
|
+
* - resolves to a object (with a `done` field) when the request can be issued without queueing,
|
|
1192
|
+
* - resolves to `null` if the request has been cancelled (by the callback return < 0).
|
|
1193
|
+
* In this case the application should not issue the request
|
|
1194
|
+
*/
|
|
1195
|
+
scheduleRequest(handle, getPriority = () => 0) {
|
|
1196
|
+
if (!this.props.throttleRequests) {
|
|
1197
|
+
return Promise.resolve({ done: () => {
|
|
1198
|
+
} });
|
|
1199
|
+
}
|
|
1200
|
+
if (this.requestMap.has(handle)) {
|
|
1201
|
+
return this.requestMap.get(handle);
|
|
1202
|
+
}
|
|
1203
|
+
const request = { handle, priority: 0, getPriority };
|
|
1204
|
+
const promise = new Promise((resolve2) => {
|
|
1205
|
+
request.resolve = resolve2;
|
|
1206
|
+
return request;
|
|
1207
|
+
});
|
|
1208
|
+
this.requestQueue.push(request);
|
|
1209
|
+
this.requestMap.set(handle, promise);
|
|
1210
|
+
this._issueNewRequests();
|
|
1211
|
+
return promise;
|
|
1212
|
+
}
|
|
1213
|
+
// PRIVATE
|
|
1214
|
+
_issueRequest(request) {
|
|
1215
|
+
const { handle, resolve: resolve2 } = request;
|
|
1216
|
+
let isDone = false;
|
|
1217
|
+
const done = () => {
|
|
1218
|
+
if (!isDone) {
|
|
1219
|
+
isDone = true;
|
|
1220
|
+
this.requestMap.delete(handle);
|
|
1221
|
+
this.activeRequestCount--;
|
|
1222
|
+
this._issueNewRequests();
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
this.activeRequestCount++;
|
|
1226
|
+
return resolve2 ? resolve2({ done }) : Promise.resolve({ done });
|
|
1227
|
+
}
|
|
1228
|
+
/** We check requests asynchronously, to prevent multiple updates */
|
|
1229
|
+
_issueNewRequests() {
|
|
1230
|
+
if (this.updateTimer !== null) {
|
|
1231
|
+
clearTimeout(this.updateTimer);
|
|
1232
|
+
}
|
|
1233
|
+
this.updateTimer = setTimeout(() => this._issueNewRequestsAsync(), this.props.debounceTime);
|
|
1234
|
+
}
|
|
1235
|
+
/** Refresh all requests */
|
|
1236
|
+
_issueNewRequestsAsync() {
|
|
1237
|
+
if (this.updateTimer !== null) {
|
|
1238
|
+
clearTimeout(this.updateTimer);
|
|
1239
|
+
}
|
|
1240
|
+
this.updateTimer = null;
|
|
1241
|
+
const freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);
|
|
1242
|
+
if (freeSlots === 0) {
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
this._updateAllRequests();
|
|
1246
|
+
for (let i = 0; i < freeSlots; ++i) {
|
|
1247
|
+
const request = this.requestQueue.shift();
|
|
1248
|
+
if (request) {
|
|
1249
|
+
this._issueRequest(request);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
/** Ensure all requests have updated priorities, and that no longer valid requests are cancelled */
|
|
1254
|
+
_updateAllRequests() {
|
|
1255
|
+
const requestQueue = this.requestQueue;
|
|
1256
|
+
for (let i = 0; i < requestQueue.length; ++i) {
|
|
1257
|
+
const request = requestQueue[i];
|
|
1258
|
+
if (!this._updateRequest(request)) {
|
|
1259
|
+
requestQueue.splice(i, 1);
|
|
1260
|
+
this.requestMap.delete(request.handle);
|
|
1261
|
+
i--;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
requestQueue.sort((a, b) => a.priority - b.priority);
|
|
1265
|
+
}
|
|
1266
|
+
/** Update a single request by calling the callback */
|
|
1267
|
+
_updateRequest(request) {
|
|
1268
|
+
request.priority = request.getPriority(request.handle);
|
|
1269
|
+
if (request.priority < 0) {
|
|
1270
|
+
request.resolve(null);
|
|
1271
|
+
return false;
|
|
1272
|
+
}
|
|
1273
|
+
return true;
|
|
1274
|
+
}
|
|
1275
|
+
};
|
|
1276
|
+
|
|
1277
|
+
// ../loader-utils/src/lib/request-utils/request-credentials.ts
|
|
1278
|
+
var AUTHENTICATED_FETCH = /* @__PURE__ */ Symbol("loaders.gl.authenticated-fetch");
|
|
1279
|
+
var refreshPromises = /* @__PURE__ */ new WeakMap();
|
|
1280
|
+
function createAuthenticatedFetch(options) {
|
|
1281
|
+
const baseFetch = options.fetch || ((url, requestOptions) => fetch(url, requestOptions));
|
|
1282
|
+
if (!options.credentials.length) return baseFetch;
|
|
1283
|
+
const existingMetadata = baseFetch[AUTHENTICATED_FETCH];
|
|
1284
|
+
if (existingMetadata === options.credentials) return baseFetch;
|
|
1285
|
+
const authenticatedFetch = async (url, requestOptions = {}) => {
|
|
1286
|
+
var _a, _b, _c;
|
|
1287
|
+
const resolvedURL = parseHTTPURL(url);
|
|
1288
|
+
if (!resolvedURL) return baseFetch(url, requestOptions);
|
|
1289
|
+
const authorization = await authorizeRequest(resolvedURL, requestOptions, options.credentials);
|
|
1290
|
+
const response = await baseFetch(authorization.url, authorization.options);
|
|
1291
|
+
const refreshableCredentials = authorization.credentials.filter(
|
|
1292
|
+
({ credential }) => typeof credential.token === "function" && credential.refreshStatusCodes.includes(response.status)
|
|
1293
|
+
);
|
|
1294
|
+
if (!refreshableCredentials.length || !isReplayableRequest(requestOptions)) return response;
|
|
1295
|
+
if ((_a = requestOptions.signal) == null ? void 0 : _a.aborted) throw createAbortError3();
|
|
1296
|
+
const refreshedTokens = /* @__PURE__ */ new Map();
|
|
1297
|
+
await Promise.all(
|
|
1298
|
+
refreshableCredentials.map(async ({ credential }) => {
|
|
1299
|
+
const token = await refreshCredential(credential, url, response);
|
|
1300
|
+
if (token) refreshedTokens.set(credential, token);
|
|
1301
|
+
})
|
|
1302
|
+
);
|
|
1303
|
+
if (!refreshedTokens.size) return response;
|
|
1304
|
+
await ((_b = response.body) == null ? void 0 : _b.cancel().catch(() => {
|
|
1305
|
+
}));
|
|
1306
|
+
if ((_c = requestOptions.signal) == null ? void 0 : _c.aborted) throw createAbortError3();
|
|
1307
|
+
const replayAuthorization = await authorizeRequest(
|
|
1308
|
+
resolvedURL,
|
|
1309
|
+
requestOptions,
|
|
1310
|
+
options.credentials,
|
|
1311
|
+
refreshedTokens,
|
|
1312
|
+
authorization.credentials
|
|
1313
|
+
);
|
|
1314
|
+
return baseFetch(replayAuthorization.url, replayAuthorization.options);
|
|
1315
|
+
};
|
|
1316
|
+
Object.defineProperty(authenticatedFetch, AUTHENTICATED_FETCH, {
|
|
1317
|
+
value: options.credentials
|
|
1318
|
+
});
|
|
1319
|
+
return authenticatedFetch;
|
|
1320
|
+
}
|
|
1321
|
+
async function authorizeRequest(sourceURL, requestOptions, credentials, tokenOverrides = /* @__PURE__ */ new Map(), previousCredentials = []) {
|
|
1322
|
+
const url = new URL(sourceURL);
|
|
1323
|
+
const headers = new Headers(requestOptions.headers);
|
|
1324
|
+
const resolvedCredentials = [];
|
|
1325
|
+
const previousTokens = new Map(
|
|
1326
|
+
previousCredentials.map(({ credential, token }) => [credential, token])
|
|
1327
|
+
);
|
|
1328
|
+
for (const credential of credentials) {
|
|
1329
|
+
if (!credential.origins.includes(url.origin)) continue;
|
|
1330
|
+
const overrideToken = tokenOverrides.get(credential);
|
|
1331
|
+
const previousToken = previousTokens.get(credential);
|
|
1332
|
+
const ownsQueryParameter = credential.type === "query-parameter" && previousToken !== void 0;
|
|
1333
|
+
const ownsHeader = credential.type === "header" && previousToken !== void 0;
|
|
1334
|
+
if (credential.type === "query-parameter" && url.searchParams.has(credential.name) && !ownsQueryParameter || credential.type === "header" && headers.has(credential.name) && !ownsHeader) {
|
|
1335
|
+
continue;
|
|
1336
|
+
}
|
|
1337
|
+
const token = overrideToken ?? previousToken ?? await resolveToken(credential.token, { url: sourceURL.toString(), reason: "request" });
|
|
1338
|
+
if (!token) continue;
|
|
1339
|
+
if (credential.type === "query-parameter") {
|
|
1340
|
+
url.searchParams.set(credential.name, token);
|
|
1341
|
+
} else {
|
|
1342
|
+
headers.set(credential.name, `${credential.prefix || ""}${token}`);
|
|
1343
|
+
}
|
|
1344
|
+
resolvedCredentials.push({ credential, token });
|
|
1345
|
+
}
|
|
1346
|
+
return {
|
|
1347
|
+
url: url.toString(),
|
|
1348
|
+
options: { ...requestOptions, headers },
|
|
1349
|
+
credentials: resolvedCredentials
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
async function refreshCredential(credential, url, response) {
|
|
1353
|
+
const existingPromise = refreshPromises.get(credential);
|
|
1354
|
+
if (existingPromise) return existingPromise;
|
|
1355
|
+
const tokenProvider = credential.token;
|
|
1356
|
+
const promise = Promise.resolve(
|
|
1357
|
+
tokenProvider({
|
|
1358
|
+
url,
|
|
1359
|
+
reason: "refresh",
|
|
1360
|
+
response: { status: response.status, headers: response.headers }
|
|
1361
|
+
})
|
|
1362
|
+
).finally(() => refreshPromises.delete(credential));
|
|
1363
|
+
refreshPromises.set(credential, promise);
|
|
1364
|
+
return promise;
|
|
1365
|
+
}
|
|
1366
|
+
async function resolveToken(token, context) {
|
|
1367
|
+
return typeof token === "function" ? token(context) : token;
|
|
1368
|
+
}
|
|
1369
|
+
function parseHTTPURL(url) {
|
|
1370
|
+
try {
|
|
1371
|
+
const parsedURL = new URL(url);
|
|
1372
|
+
return ["http:", "https:"].includes(parsedURL.protocol) ? parsedURL : null;
|
|
1373
|
+
} catch {
|
|
1374
|
+
return null;
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
function isReplayableRequest(options) {
|
|
1378
|
+
const method = (options.method || "GET").toUpperCase();
|
|
1379
|
+
if (!["GET", "HEAD", "OPTIONS", "PUT", "DELETE"].includes(method)) return false;
|
|
1380
|
+
return !(options.body && typeof ReadableStream !== "undefined" && options.body instanceof ReadableStream);
|
|
1381
|
+
}
|
|
1382
|
+
function createAbortError3() {
|
|
1383
|
+
return new DOMException("The operation was aborted.", "AbortError");
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
// ../loader-utils/src/lib/path-utils/file-aliases.ts
|
|
1387
|
+
var pathPrefix = "";
|
|
1388
|
+
var fileAliases = {};
|
|
1389
|
+
function setPathPrefix(prefix) {
|
|
1390
|
+
pathPrefix = prefix;
|
|
1391
|
+
}
|
|
1392
|
+
function getPathPrefix() {
|
|
1393
|
+
return pathPrefix;
|
|
1394
|
+
}
|
|
1395
|
+
function resolvePath(filename2) {
|
|
1396
|
+
for (const alias in fileAliases) {
|
|
1397
|
+
if (filename2.startsWith(alias)) {
|
|
1398
|
+
const replacement = fileAliases[alias];
|
|
1399
|
+
filename2 = filename2.replace(alias, replacement);
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
if (!filename2.startsWith("http://") && !filename2.startsWith("https://")) {
|
|
1403
|
+
filename2 = `${pathPrefix}${filename2}`;
|
|
1404
|
+
}
|
|
1405
|
+
return filename2;
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
// ../loader-utils/src/lib/path-utils/path.ts
|
|
1409
|
+
var path_exports = {};
|
|
1410
|
+
__export(path_exports, {
|
|
1411
|
+
dirname: () => dirname,
|
|
1412
|
+
filename: () => filename,
|
|
1413
|
+
join: () => join,
|
|
1414
|
+
resolve: () => resolve
|
|
1415
|
+
});
|
|
1416
|
+
|
|
1417
|
+
// ../loader-utils/src/lib/path-utils/get-cwd.ts
|
|
1418
|
+
function getCWD() {
|
|
1419
|
+
var _a;
|
|
1420
|
+
if (typeof process !== "undefined" && typeof process.cwd !== "undefined") {
|
|
1421
|
+
return process.cwd();
|
|
1422
|
+
}
|
|
1423
|
+
const pathname = (_a = window.location) == null ? void 0 : _a.pathname;
|
|
1424
|
+
return (pathname == null ? void 0 : pathname.slice(0, pathname.lastIndexOf("/") + 1)) || "";
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
// ../loader-utils/src/lib/path-utils/path.ts
|
|
1428
|
+
function filename(url) {
|
|
1429
|
+
const slashIndex = url ? url.lastIndexOf("/") : -1;
|
|
1430
|
+
return slashIndex >= 0 ? url.substr(slashIndex + 1) : url;
|
|
1431
|
+
}
|
|
1432
|
+
function dirname(url) {
|
|
1433
|
+
const slashIndex = url ? url.lastIndexOf("/") : -1;
|
|
1434
|
+
return slashIndex >= 0 ? url.substr(0, slashIndex) : "";
|
|
1435
|
+
}
|
|
1436
|
+
function join(...parts) {
|
|
1437
|
+
const separator = "/";
|
|
1438
|
+
parts = parts.map((part, index) => {
|
|
1439
|
+
if (index) {
|
|
1440
|
+
part = part.replace(new RegExp(`^${separator}`), "");
|
|
1441
|
+
}
|
|
1442
|
+
if (index !== parts.length - 1) {
|
|
1443
|
+
part = part.replace(new RegExp(`${separator}$`), "");
|
|
1444
|
+
}
|
|
1445
|
+
return part;
|
|
1446
|
+
});
|
|
1447
|
+
return parts.join(separator);
|
|
1448
|
+
}
|
|
1449
|
+
function resolve(...components) {
|
|
1450
|
+
const paths = [];
|
|
1451
|
+
for (let _i = 0; _i < components.length; _i++) {
|
|
1452
|
+
paths[_i] = components[_i];
|
|
1453
|
+
}
|
|
1454
|
+
let resolvedPath = "";
|
|
1455
|
+
let resolvedAbsolute = false;
|
|
1456
|
+
let cwd;
|
|
1457
|
+
for (let i = paths.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
1458
|
+
let path;
|
|
1459
|
+
if (i >= 0) {
|
|
1460
|
+
path = paths[i];
|
|
1461
|
+
} else {
|
|
1462
|
+
if (cwd === void 0) {
|
|
1463
|
+
cwd = getCWD();
|
|
1464
|
+
}
|
|
1465
|
+
path = cwd;
|
|
1466
|
+
}
|
|
1467
|
+
if (path.length === 0) {
|
|
1468
|
+
continue;
|
|
1469
|
+
}
|
|
1470
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
1471
|
+
resolvedAbsolute = path.charCodeAt(0) === SLASH;
|
|
1472
|
+
}
|
|
1473
|
+
resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
|
|
1474
|
+
if (resolvedAbsolute) {
|
|
1475
|
+
return `/${resolvedPath}`;
|
|
1476
|
+
} else if (resolvedPath.length > 0) {
|
|
1477
|
+
return resolvedPath;
|
|
1478
|
+
}
|
|
1479
|
+
return ".";
|
|
1480
|
+
}
|
|
1481
|
+
var SLASH = 47;
|
|
1482
|
+
var DOT = 46;
|
|
1483
|
+
function normalizeStringPosix(path, allowAboveRoot) {
|
|
1484
|
+
let res = "";
|
|
1485
|
+
let lastSlash = -1;
|
|
1486
|
+
let dots = 0;
|
|
1487
|
+
let code;
|
|
1488
|
+
let isAboveRoot = false;
|
|
1489
|
+
for (let i = 0; i <= path.length; ++i) {
|
|
1490
|
+
if (i < path.length) {
|
|
1491
|
+
code = path.charCodeAt(i);
|
|
1492
|
+
} else if (code === SLASH) {
|
|
1493
|
+
break;
|
|
1494
|
+
} else {
|
|
1495
|
+
code = SLASH;
|
|
1496
|
+
}
|
|
1497
|
+
if (code === SLASH) {
|
|
1498
|
+
if (lastSlash === i - 1 || dots === 1) {
|
|
1499
|
+
} else if (lastSlash !== i - 1 && dots === 2) {
|
|
1500
|
+
if (res.length < 2 || !isAboveRoot || res.charCodeAt(res.length - 1) !== DOT || res.charCodeAt(res.length - 2) !== DOT) {
|
|
1501
|
+
if (res.length > 2) {
|
|
1502
|
+
const start = res.length - 1;
|
|
1503
|
+
let j = start;
|
|
1504
|
+
for (; j >= 0; --j) {
|
|
1505
|
+
if (res.charCodeAt(j) === SLASH) {
|
|
1506
|
+
break;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
if (j !== start) {
|
|
1510
|
+
res = j === -1 ? "" : res.slice(0, j);
|
|
1511
|
+
lastSlash = i;
|
|
1512
|
+
dots = 0;
|
|
1513
|
+
isAboveRoot = false;
|
|
1514
|
+
continue;
|
|
1515
|
+
}
|
|
1516
|
+
} else if (res.length === 2 || res.length === 1) {
|
|
1517
|
+
res = "";
|
|
1518
|
+
lastSlash = i;
|
|
1519
|
+
dots = 0;
|
|
1520
|
+
isAboveRoot = false;
|
|
1521
|
+
continue;
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
if (allowAboveRoot) {
|
|
1525
|
+
if (res.length > 0) {
|
|
1526
|
+
res += "/..";
|
|
1527
|
+
} else {
|
|
1528
|
+
res = "..";
|
|
1529
|
+
}
|
|
1530
|
+
isAboveRoot = true;
|
|
1531
|
+
}
|
|
1532
|
+
} else {
|
|
1533
|
+
const slice = path.slice(lastSlash + 1, i);
|
|
1534
|
+
if (res.length > 0) {
|
|
1535
|
+
res += `/${slice}`;
|
|
1536
|
+
} else {
|
|
1537
|
+
res = slice;
|
|
1538
|
+
}
|
|
1539
|
+
isAboveRoot = false;
|
|
1540
|
+
}
|
|
1541
|
+
lastSlash = i;
|
|
1542
|
+
dots = 0;
|
|
1543
|
+
} else if (code === DOT && dots !== -1) {
|
|
1544
|
+
++dots;
|
|
1545
|
+
} else {
|
|
1546
|
+
dots = -1;
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
return res;
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
// ../loader-utils/src/json-loader.ts
|
|
1553
|
+
var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1554
|
+
var JSONLoader = {
|
|
1555
|
+
dataType: null,
|
|
1556
|
+
batchType: null,
|
|
1557
|
+
name: "JSON",
|
|
1558
|
+
id: "json",
|
|
1559
|
+
module: "json",
|
|
1560
|
+
version: VERSION3,
|
|
1561
|
+
encoding: "json",
|
|
1562
|
+
format: "json",
|
|
1563
|
+
extensions: ["json", "geojson"],
|
|
1564
|
+
mimeTypes: ["application/json"],
|
|
1565
|
+
category: "json",
|
|
1566
|
+
text: true,
|
|
1567
|
+
parseTextSync,
|
|
1568
|
+
parse: async (arrayBuffer) => parseTextSync(new TextDecoder().decode(arrayBuffer)),
|
|
1569
|
+
options: {}
|
|
1570
|
+
};
|
|
1571
|
+
function parseTextSync(text) {
|
|
1572
|
+
return JSON.parse(text);
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
// ../loader-utils/src/lib/node/buffer.browser.ts
|
|
1576
|
+
function toArrayBuffer(buffer) {
|
|
1577
|
+
return buffer;
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
// ../loader-utils/src/lib/binary-utils/memory-conversion-utils.ts
|
|
1581
|
+
function isBuffer(value) {
|
|
1582
|
+
return value && typeof value === "object" && value.isBuffer;
|
|
1583
|
+
}
|
|
1584
|
+
function toArrayBuffer2(data) {
|
|
1585
|
+
if (isBuffer(data)) {
|
|
1586
|
+
return toArrayBuffer(data);
|
|
1587
|
+
}
|
|
1588
|
+
if (data instanceof ArrayBuffer) {
|
|
1589
|
+
return data;
|
|
1590
|
+
}
|
|
1591
|
+
if (isSharedArrayBuffer(data)) {
|
|
1592
|
+
return copyToArrayBuffer2(data);
|
|
1593
|
+
}
|
|
1594
|
+
if (ArrayBuffer.isView(data)) {
|
|
1595
|
+
const buffer = data.buffer;
|
|
1596
|
+
if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
|
|
1597
|
+
return buffer;
|
|
1598
|
+
}
|
|
1599
|
+
return buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
1600
|
+
}
|
|
1601
|
+
if (typeof data === "string") {
|
|
1602
|
+
const text = data;
|
|
1603
|
+
const uint8Array = new TextEncoder().encode(text);
|
|
1604
|
+
return uint8Array.buffer;
|
|
1605
|
+
}
|
|
1606
|
+
if (data && typeof data === "object" && data._toArrayBuffer) {
|
|
1607
|
+
return data._toArrayBuffer();
|
|
1608
|
+
}
|
|
1609
|
+
throw new Error("toArrayBuffer");
|
|
1610
|
+
}
|
|
1611
|
+
function ensureArrayBuffer(bufferSource) {
|
|
1612
|
+
if (bufferSource instanceof ArrayBuffer) {
|
|
1613
|
+
return bufferSource;
|
|
1614
|
+
}
|
|
1615
|
+
if (isSharedArrayBuffer(bufferSource)) {
|
|
1616
|
+
return copyToArrayBuffer2(bufferSource);
|
|
1617
|
+
}
|
|
1618
|
+
const { buffer, byteOffset, byteLength } = bufferSource;
|
|
1619
|
+
if (buffer instanceof ArrayBuffer && byteOffset === 0 && byteLength === buffer.byteLength) {
|
|
1620
|
+
return buffer;
|
|
1621
|
+
}
|
|
1622
|
+
return copyToArrayBuffer2(buffer, byteOffset, byteLength);
|
|
1623
|
+
}
|
|
1624
|
+
function copyToArrayBuffer2(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
|
|
1625
|
+
const view = new Uint8Array(buffer, byteOffset, byteLength);
|
|
1626
|
+
const copy = new Uint8Array(view.length);
|
|
1627
|
+
copy.set(view);
|
|
1628
|
+
return copy.buffer;
|
|
1629
|
+
}
|
|
1630
|
+
function toArrayBufferView(data) {
|
|
1631
|
+
if (ArrayBuffer.isView(data)) {
|
|
1632
|
+
return data;
|
|
1633
|
+
}
|
|
1634
|
+
return new Uint8Array(data);
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
// ../loader-utils/src/lib/files/blob-file.ts
|
|
1638
|
+
var BlobFile = class {
|
|
1639
|
+
handle;
|
|
1640
|
+
size;
|
|
1641
|
+
bigsize;
|
|
1642
|
+
url;
|
|
1643
|
+
constructor(blob) {
|
|
1644
|
+
this.handle = blob instanceof ArrayBuffer ? new Blob([blob]) : blob;
|
|
1645
|
+
this.size = blob instanceof ArrayBuffer ? blob.byteLength : blob.size;
|
|
1646
|
+
this.bigsize = BigInt(this.size);
|
|
1647
|
+
this.url = blob instanceof File ? blob.name : "";
|
|
1648
|
+
}
|
|
1649
|
+
async close() {
|
|
1650
|
+
}
|
|
1651
|
+
async stat() {
|
|
1652
|
+
return {
|
|
1653
|
+
size: this.handle.size,
|
|
1654
|
+
bigsize: BigInt(this.handle.size),
|
|
1655
|
+
isDirectory: false
|
|
1656
|
+
};
|
|
1657
|
+
}
|
|
1658
|
+
async read(start, length, signal) {
|
|
1659
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
1660
|
+
throw new Error("Request aborted");
|
|
1661
|
+
}
|
|
1662
|
+
const arrayBuffer = await this.handle.slice(Number(start), Number(start) + Number(length)).arrayBuffer();
|
|
1663
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
1664
|
+
throw new Error("Request aborted");
|
|
1665
|
+
}
|
|
1666
|
+
return arrayBuffer;
|
|
1667
|
+
}
|
|
1668
|
+
};
|
|
1669
|
+
|
|
1670
|
+
// ../loader-utils/src/lib/files/node-file-facade.ts
|
|
1671
|
+
var NOT_IMPLEMENTED = new Error("Not implemented");
|
|
1672
|
+
var NodeFileFacade = class {
|
|
1673
|
+
handle;
|
|
1674
|
+
size = 0;
|
|
1675
|
+
bigsize = 0n;
|
|
1676
|
+
url = "";
|
|
1677
|
+
constructor(url, flags, mode) {
|
|
1678
|
+
var _a;
|
|
1679
|
+
if ((_a = globalThis.loaders) == null ? void 0 : _a.NodeFile) {
|
|
1680
|
+
return new globalThis.loaders.NodeFile(url, flags, mode);
|
|
1681
|
+
}
|
|
1682
|
+
if (isBrowser) {
|
|
1683
|
+
throw new Error("Can't instantiate NodeFile in browser.");
|
|
1684
|
+
}
|
|
1685
|
+
throw new Error("Can't instantiate NodeFile. Make sure to import @loaders.gl/polyfills first.");
|
|
1686
|
+
}
|
|
1687
|
+
/** Read data */
|
|
1688
|
+
async read(start, length) {
|
|
1689
|
+
throw NOT_IMPLEMENTED;
|
|
1690
|
+
}
|
|
1691
|
+
/** Write to file. The number of bytes written will be returned */
|
|
1692
|
+
async write(arrayBuffer, offset, length) {
|
|
1693
|
+
throw NOT_IMPLEMENTED;
|
|
1694
|
+
}
|
|
1695
|
+
/** Get information about file */
|
|
1696
|
+
async stat() {
|
|
1697
|
+
throw NOT_IMPLEMENTED;
|
|
1698
|
+
}
|
|
1699
|
+
/** Truncates the file descriptor. Only available on NodeFile. */
|
|
1700
|
+
async truncate(length) {
|
|
1701
|
+
throw NOT_IMPLEMENTED;
|
|
1702
|
+
}
|
|
1703
|
+
/** Append data to a file. Only available on NodeFile. */
|
|
1704
|
+
async append(data) {
|
|
1705
|
+
throw NOT_IMPLEMENTED;
|
|
1706
|
+
}
|
|
1707
|
+
/** Close the file */
|
|
1708
|
+
async close() {
|
|
1709
|
+
}
|
|
1710
|
+
};
|
|
1711
|
+
|
|
1712
|
+
// ../loader-utils/src/source-types.ts
|
|
1713
|
+
function isSourceLoader(loader) {
|
|
1714
|
+
return Boolean(loader && typeof loader === "object" && "createDataSource" in loader);
|
|
1715
|
+
}
|
|
92
1716
|
|
|
93
1717
|
// dist/lib/fetch/fetch-error.js
|
|
94
1718
|
var FetchError = class extends Error {
|
|
@@ -106,9 +1730,6 @@ var FetchError = class extends Error {
|
|
|
106
1730
|
response;
|
|
107
1731
|
};
|
|
108
1732
|
|
|
109
|
-
// dist/lib/utils/resource-utils.js
|
|
110
|
-
var import_loader_utils = require("@loaders.gl/loader-utils");
|
|
111
|
-
|
|
112
1733
|
// dist/lib/utils/mime-type-utils.js
|
|
113
1734
|
var DATA_URL_PATTERN = /^data:([-\w.]+\/[-\w.+]+)(;|,)/;
|
|
114
1735
|
var MIME_TYPE_PATTERN = /^([-\w.]+\/[-\w.+]+)/;
|
|
@@ -119,16 +1740,16 @@ function compareMIMETypes(mimeType1, mimeType2) {
|
|
|
119
1740
|
return false;
|
|
120
1741
|
}
|
|
121
1742
|
function parseMIMEType(mimeString) {
|
|
122
|
-
const
|
|
123
|
-
if (
|
|
124
|
-
return
|
|
1743
|
+
const matches3 = MIME_TYPE_PATTERN.exec(mimeString);
|
|
1744
|
+
if (matches3) {
|
|
1745
|
+
return matches3[1];
|
|
125
1746
|
}
|
|
126
1747
|
return mimeString;
|
|
127
1748
|
}
|
|
128
1749
|
function parseMIMETypeFromURL(url) {
|
|
129
|
-
const
|
|
130
|
-
if (
|
|
131
|
-
return
|
|
1750
|
+
const matches3 = DATA_URL_PATTERN.exec(url);
|
|
1751
|
+
if (matches3) {
|
|
1752
|
+
return matches3[1];
|
|
132
1753
|
}
|
|
133
1754
|
return "";
|
|
134
1755
|
}
|
|
@@ -136,8 +1757,8 @@ function parseMIMETypeFromURL(url) {
|
|
|
136
1757
|
// dist/lib/utils/url-utils.js
|
|
137
1758
|
var QUERY_STRING_PATTERN = /\?.*/;
|
|
138
1759
|
function extractQueryString(url) {
|
|
139
|
-
const
|
|
140
|
-
return
|
|
1760
|
+
const matches3 = url.match(QUERY_STRING_PATTERN);
|
|
1761
|
+
return matches3 && matches3[0];
|
|
141
1762
|
}
|
|
142
1763
|
function stripQueryString(url) {
|
|
143
1764
|
return url.replace(QUERY_STRING_PATTERN, "");
|
|
@@ -153,10 +1774,10 @@ function shortenUrlForDisplay(url) {
|
|
|
153
1774
|
|
|
154
1775
|
// dist/lib/utils/resource-utils.js
|
|
155
1776
|
function getResourceUrl(resource) {
|
|
156
|
-
if (
|
|
1777
|
+
if (isResponse(resource)) {
|
|
157
1778
|
return resource.url;
|
|
158
1779
|
}
|
|
159
|
-
if (
|
|
1780
|
+
if (isBlob(resource)) {
|
|
160
1781
|
const fileName = "name" in resource ? resource.name : "";
|
|
161
1782
|
return fileName || "";
|
|
162
1783
|
}
|
|
@@ -166,12 +1787,12 @@ function getResourceUrl(resource) {
|
|
|
166
1787
|
return "";
|
|
167
1788
|
}
|
|
168
1789
|
function getResourceMIMEType(resource) {
|
|
169
|
-
if (
|
|
1790
|
+
if (isResponse(resource)) {
|
|
170
1791
|
const contentTypeHeader = resource.headers.get("content-type") || "";
|
|
171
1792
|
const noQueryUrl = stripQueryString(resource.url);
|
|
172
1793
|
return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);
|
|
173
1794
|
}
|
|
174
|
-
if (
|
|
1795
|
+
if (isBlob(resource)) {
|
|
175
1796
|
return resource.type || "";
|
|
176
1797
|
}
|
|
177
1798
|
if (typeof resource === "string") {
|
|
@@ -180,11 +1801,11 @@ function getResourceMIMEType(resource) {
|
|
|
180
1801
|
return "";
|
|
181
1802
|
}
|
|
182
1803
|
function getResourceContentLength(resource) {
|
|
183
|
-
if (
|
|
1804
|
+
if (isResponse(resource)) {
|
|
184
1805
|
const response = resource;
|
|
185
1806
|
return response.headers["content-length"] || -1;
|
|
186
1807
|
}
|
|
187
|
-
if (
|
|
1808
|
+
if (isBlob(resource)) {
|
|
188
1809
|
const blob = resource;
|
|
189
1810
|
return blob.size;
|
|
190
1811
|
}
|
|
@@ -202,7 +1823,7 @@ function getResourceContentLength(resource) {
|
|
|
202
1823
|
|
|
203
1824
|
// dist/lib/utils/response-utils.js
|
|
204
1825
|
async function makeResponse(resource) {
|
|
205
|
-
if (
|
|
1826
|
+
if (isResponse(resource)) {
|
|
206
1827
|
return resource;
|
|
207
1828
|
}
|
|
208
1829
|
const headers = {};
|
|
@@ -255,11 +1876,11 @@ async function getInitialDataUrl(resource) {
|
|
|
255
1876
|
}
|
|
256
1877
|
if (resource instanceof Blob) {
|
|
257
1878
|
const blobSlice = resource.slice(0, 5);
|
|
258
|
-
return await new Promise((
|
|
1879
|
+
return await new Promise((resolve2) => {
|
|
259
1880
|
const reader = new FileReader();
|
|
260
1881
|
reader.onload = (event) => {
|
|
261
1882
|
var _a;
|
|
262
|
-
return
|
|
1883
|
+
return resolve2((_a = event == null ? void 0 : event.target) == null ? void 0 : _a.result);
|
|
263
1884
|
};
|
|
264
1885
|
reader.readAsDataURL(blobSlice);
|
|
265
1886
|
});
|
|
@@ -293,7 +1914,7 @@ function isDataURL(url) {
|
|
|
293
1914
|
async function fetchFile(urlOrData, fetchOptions) {
|
|
294
1915
|
var _a, _b;
|
|
295
1916
|
if (typeof urlOrData === "string") {
|
|
296
|
-
const url =
|
|
1917
|
+
const url = resolvePath(urlOrData);
|
|
297
1918
|
if (isNodePath(url)) {
|
|
298
1919
|
if ((_a = globalThis.loaders) == null ? void 0 : _a.fetchNode) {
|
|
299
1920
|
return (_b = globalThis.loaders) == null ? void 0 : _b.fetchNode(url, fetchOptions);
|
|
@@ -313,23 +1934,20 @@ async function readArrayBuffer(file, start, length) {
|
|
|
313
1934
|
return await readBlob(slice);
|
|
314
1935
|
}
|
|
315
1936
|
async function readBlob(blob) {
|
|
316
|
-
return await new Promise((
|
|
1937
|
+
return await new Promise((resolve2, reject) => {
|
|
317
1938
|
const fileReader = new FileReader();
|
|
318
1939
|
fileReader.onload = (event) => {
|
|
319
1940
|
var _a;
|
|
320
|
-
return
|
|
1941
|
+
return resolve2((_a = event == null ? void 0 : event.target) == null ? void 0 : _a.result);
|
|
321
1942
|
};
|
|
322
1943
|
fileReader.onerror = (error) => reject(error);
|
|
323
1944
|
fileReader.readAsArrayBuffer(blob);
|
|
324
1945
|
});
|
|
325
1946
|
}
|
|
326
1947
|
|
|
327
|
-
// dist/lib/loader-utils/option-utils.js
|
|
328
|
-
var import_loader_utils5 = require("@loaders.gl/loader-utils");
|
|
329
|
-
|
|
330
1948
|
// dist/lib/loader-utils/loggers.js
|
|
331
|
-
var
|
|
332
|
-
var probeLog = new
|
|
1949
|
+
var import_log3 = require("@probe.gl/log");
|
|
1950
|
+
var probeLog = new import_log3.Log({ id: "loaders.gl" });
|
|
333
1951
|
var NullLog = class {
|
|
334
1952
|
/** Drops a log message. */
|
|
335
1953
|
log() {
|
|
@@ -395,7 +2013,6 @@ var ConsoleLog = class {
|
|
|
395
2013
|
};
|
|
396
2014
|
|
|
397
2015
|
// dist/lib/loader-utils/option-defaults.js
|
|
398
|
-
var import_loader_utils4 = require("@loaders.gl/loader-utils");
|
|
399
2016
|
var DEFAULT_LOADER_OPTIONS = {
|
|
400
2017
|
core: {
|
|
401
2018
|
baseUrl: void 0,
|
|
@@ -416,7 +2033,7 @@ var DEFAULT_LOADER_OPTIONS = {
|
|
|
416
2033
|
// How many worker instances should be created for each loader.
|
|
417
2034
|
maxMobileConcurrency: 1,
|
|
418
2035
|
// How many worker instances should be created for each loader on mobile devices.
|
|
419
|
-
reuseWorkers:
|
|
2036
|
+
reuseWorkers: isBrowser,
|
|
420
2037
|
// By default reuse workers in browser (Node.js refuses to terminate if browsers are running)
|
|
421
2038
|
_nodeWorkers: false,
|
|
422
2039
|
// By default do not support node workers
|
|
@@ -521,7 +2138,7 @@ function setGlobalOptions(options) {
|
|
|
521
2138
|
const state = getGlobalLoaderState();
|
|
522
2139
|
const globalOptions = getGlobalLoaderOptions();
|
|
523
2140
|
state.globalOptions = normalizeOptionsInternal(globalOptions, options);
|
|
524
|
-
|
|
2141
|
+
registerJSModules(options.modules);
|
|
525
2142
|
}
|
|
526
2143
|
function normalizeOptions(options, loader, loaders, url) {
|
|
527
2144
|
loaders = loaders || [];
|
|
@@ -555,7 +2172,7 @@ function validateOptionsObject(options, id, defaultOptions, deprecatedOptions, l
|
|
|
555
2172
|
const loaderName = id || "Top level";
|
|
556
2173
|
const prefix = id ? `${id}.` : "";
|
|
557
2174
|
for (const key in options) {
|
|
558
|
-
const isSubOptions = !id &&
|
|
2175
|
+
const isSubOptions = !id && isObject(options[key]);
|
|
559
2176
|
const isBaseUriOption = key === "baseUri" && !id;
|
|
560
2177
|
const isWorkerUrlOption = key === "workerUrl" && id;
|
|
561
2178
|
if (!(key in defaultOptions) && !isBaseUriOption && !isWorkerUrlOption) {
|
|
@@ -615,20 +2232,20 @@ function applyCoreShapeDefault(mergedOptions, userOptions, loader) {
|
|
|
615
2232
|
return;
|
|
616
2233
|
}
|
|
617
2234
|
const loaderScopedDefaults = (_b = loader.options) == null ? void 0 : _b[loader.id];
|
|
618
|
-
if (!
|
|
2235
|
+
if (!isPureObject(loaderScopedDefaults) || !("shape" in loaderScopedDefaults)) {
|
|
619
2236
|
return;
|
|
620
2237
|
}
|
|
621
2238
|
const globalLoaderScopedOptions = getGlobalLoaderOptions()[loader.id];
|
|
622
|
-
if (
|
|
2239
|
+
if (isPureObject(globalLoaderScopedOptions) && "shape" in globalLoaderScopedOptions) {
|
|
623
2240
|
return;
|
|
624
2241
|
}
|
|
625
2242
|
const userLoaderScopedOptions = userOptions[loader.id];
|
|
626
|
-
if (
|
|
2243
|
+
if (isPureObject(userLoaderScopedOptions) && "shape" in userLoaderScopedOptions) {
|
|
627
2244
|
return;
|
|
628
2245
|
}
|
|
629
2246
|
const loaderScopedOptions = mergedOptions[loader.id];
|
|
630
2247
|
mergedOptions[loader.id] = {
|
|
631
|
-
...
|
|
2248
|
+
...isPureObject(loaderScopedOptions) ? loaderScopedOptions : {},
|
|
632
2249
|
shape: coreShape
|
|
633
2250
|
};
|
|
634
2251
|
}
|
|
@@ -636,7 +2253,7 @@ function mergeNestedFields(mergedOptions, options) {
|
|
|
636
2253
|
for (const key in options) {
|
|
637
2254
|
if (key in options) {
|
|
638
2255
|
const value = options[key];
|
|
639
|
-
if (
|
|
2256
|
+
if (isPureObject(value) && isPureObject(mergedOptions[key])) {
|
|
640
2257
|
mergedOptions[key] = {
|
|
641
2258
|
...mergedOptions[key],
|
|
642
2259
|
...options[key]
|
|
@@ -655,7 +2272,7 @@ function addUrlOptions(options, url) {
|
|
|
655
2272
|
const hasCoreBaseUrl = ((_a = options.core) == null ? void 0 : _a.baseUrl) !== void 0;
|
|
656
2273
|
if (!hasCoreBaseUrl) {
|
|
657
2274
|
options.core ||= {};
|
|
658
|
-
options.core.baseUrl =
|
|
2275
|
+
options.core.baseUrl = path_exports.dirname(stripQueryString(url));
|
|
659
2276
|
}
|
|
660
2277
|
}
|
|
661
2278
|
function cloneLoaderOptions(options) {
|
|
@@ -703,7 +2320,6 @@ function addDeprecatedTopLevelOptions(options) {
|
|
|
703
2320
|
}
|
|
704
2321
|
|
|
705
2322
|
// dist/lib/loader-utils/normalize-loader.js
|
|
706
|
-
var import_loader_utils6 = require("@loaders.gl/loader-utils");
|
|
707
2323
|
function isLoaderObject(loader) {
|
|
708
2324
|
if (!loader) {
|
|
709
2325
|
return false;
|
|
@@ -715,8 +2331,8 @@ function isLoaderObject(loader) {
|
|
|
715
2331
|
return hasExtensions;
|
|
716
2332
|
}
|
|
717
2333
|
function normalizeLoader(loader) {
|
|
718
|
-
|
|
719
|
-
|
|
2334
|
+
assert(loader, "null loader");
|
|
2335
|
+
assert(isLoaderObject(loader), "invalid loader");
|
|
720
2336
|
let options;
|
|
721
2337
|
if (Array.isArray(loader)) {
|
|
722
2338
|
options = loader[1];
|
|
@@ -760,7 +2376,6 @@ function _unregisterLoaders() {
|
|
|
760
2376
|
}
|
|
761
2377
|
|
|
762
2378
|
// dist/lib/api/select-loader.js
|
|
763
|
-
var import_loader_utils7 = require("@loaders.gl/loader-utils");
|
|
764
2379
|
var EXT_PATTERN = /\.([^.]+)$/;
|
|
765
2380
|
async function selectLoader(data, loaders = [], options, context) {
|
|
766
2381
|
if (!validHTTPResponse(data)) {
|
|
@@ -779,7 +2394,7 @@ async function selectLoader(data, loaders = [], options, context) {
|
|
|
779
2394
|
if (loader) {
|
|
780
2395
|
return loader;
|
|
781
2396
|
}
|
|
782
|
-
if (
|
|
2397
|
+
if (isBlob(data)) {
|
|
783
2398
|
data = await data.slice(0, 10).arrayBuffer();
|
|
784
2399
|
loader = selectLoaderSync(data, loaders, normalizedOptions, context);
|
|
785
2400
|
}
|
|
@@ -843,7 +2458,7 @@ function selectLoaderInternal(data, loaders, options, context) {
|
|
|
843
2458
|
reason = reason || (loader ? `matched MIME type ${type}` : "");
|
|
844
2459
|
loader = loader || findLoaderByInitialBytes(loaders, data);
|
|
845
2460
|
reason = reason || (loader ? `matched initial data ${getFirstCharacters(data)}` : "");
|
|
846
|
-
if (!loader &&
|
|
2461
|
+
if (!loader && isBlob(data)) {
|
|
847
2462
|
loader = findSourceLoaderByTestData(loaders, data);
|
|
848
2463
|
reason = reason || (loader ? "matched source testData" : "");
|
|
849
2464
|
}
|
|
@@ -852,7 +2467,7 @@ function selectLoaderInternal(data, loaders, options, context) {
|
|
|
852
2467
|
reason = reason || (loader ? `matched fallback MIME type ${type}` : "");
|
|
853
2468
|
}
|
|
854
2469
|
if (reason) {
|
|
855
|
-
|
|
2470
|
+
log.log(1, `selectLoader selected ${loader == null ? void 0 : loader.name}: ${reason}.`);
|
|
856
2471
|
}
|
|
857
2472
|
return loader;
|
|
858
2473
|
}
|
|
@@ -868,7 +2483,7 @@ function getNoValidLoaderMessage(data) {
|
|
|
868
2483
|
const url = getResourceUrl(data);
|
|
869
2484
|
const type = getResourceMIMEType(data);
|
|
870
2485
|
let message = "No valid loader found (";
|
|
871
|
-
message += url ? `${
|
|
2486
|
+
message += url ? `${path_exports.filename(url)}, ` : "no url provided, ";
|
|
872
2487
|
message += `MIME type: ${type ? `"${type}"` : "not provided"}, `;
|
|
873
2488
|
const firstCharacters = data ? getFirstCharacters(data) : "";
|
|
874
2489
|
message += firstCharacters ? ` first bytes: "${firstCharacters}"` : "first bytes: not available";
|
|
@@ -898,7 +2513,7 @@ function findLoaderByExtension(loaders, extension) {
|
|
|
898
2513
|
}
|
|
899
2514
|
function findSourceLoaderByType(loaders, type) {
|
|
900
2515
|
for (const loader of loaders) {
|
|
901
|
-
if (
|
|
2516
|
+
if (isSourceLoader(loader) && loader.type === type) {
|
|
902
2517
|
return loader;
|
|
903
2518
|
}
|
|
904
2519
|
}
|
|
@@ -909,7 +2524,7 @@ function findSourceLoaderByTestURL(loaders, url) {
|
|
|
909
2524
|
return null;
|
|
910
2525
|
}
|
|
911
2526
|
for (const loader of loaders) {
|
|
912
|
-
if (
|
|
2527
|
+
if (isSourceLoader(loader) && loader.testURL(url)) {
|
|
913
2528
|
return loader;
|
|
914
2529
|
}
|
|
915
2530
|
}
|
|
@@ -918,7 +2533,7 @@ function findSourceLoaderByTestURL(loaders, url) {
|
|
|
918
2533
|
function findSourceLoaderByTestData(loaders, data) {
|
|
919
2534
|
var _a;
|
|
920
2535
|
for (const loader of loaders) {
|
|
921
|
-
if (
|
|
2536
|
+
if (isSourceLoader(loader)) {
|
|
922
2537
|
if ((_a = loader.testData) == null ? void 0 : _a.call(loader, data)) {
|
|
923
2538
|
return loader;
|
|
924
2539
|
}
|
|
@@ -972,12 +2587,12 @@ function testDataAgainstBinary(data, byteOffset, loader) {
|
|
|
972
2587
|
return tests.some((test) => testBinary(data, byteOffset, loader, test));
|
|
973
2588
|
}
|
|
974
2589
|
function testBinary(data, byteOffset, loader, test) {
|
|
975
|
-
if (
|
|
976
|
-
return
|
|
2590
|
+
if (isArrayBufferLike(test)) {
|
|
2591
|
+
return compareArrayBuffers(test, data, test.byteLength);
|
|
977
2592
|
}
|
|
978
2593
|
switch (typeof test) {
|
|
979
2594
|
case "function":
|
|
980
|
-
return test(
|
|
2595
|
+
return test(ensureArrayBuffer(data));
|
|
981
2596
|
case "string":
|
|
982
2597
|
const magic = getMagicString(data, byteOffset, test.length);
|
|
983
2598
|
return test === magic;
|
|
@@ -1008,15 +2623,7 @@ function getMagicString(arrayBuffer, byteOffset, length) {
|
|
|
1008
2623
|
return magic;
|
|
1009
2624
|
}
|
|
1010
2625
|
|
|
1011
|
-
// dist/lib/api/parse.js
|
|
1012
|
-
var import_loader_utils18 = require("@loaders.gl/loader-utils");
|
|
1013
|
-
var import_worker_utils2 = require("@loaders.gl/worker-utils");
|
|
1014
|
-
|
|
1015
|
-
// dist/lib/loader-utils/get-data.js
|
|
1016
|
-
var import_loader_utils11 = require("@loaders.gl/loader-utils");
|
|
1017
|
-
|
|
1018
2626
|
// dist/iterators/make-iterator/make-string-iterator.js
|
|
1019
|
-
var import_loader_utils8 = require("@loaders.gl/loader-utils");
|
|
1020
2627
|
var DEFAULT_CHUNK_SIZE = 256 * 1024;
|
|
1021
2628
|
function* makeStringIterator(string, options) {
|
|
1022
2629
|
const chunkSize = (options == null ? void 0 : options.chunkSize) || DEFAULT_CHUNK_SIZE;
|
|
@@ -1026,7 +2633,7 @@ function* makeStringIterator(string, options) {
|
|
|
1026
2633
|
const chunkLength = Math.min(string.length - offset, chunkSize);
|
|
1027
2634
|
const chunk = string.slice(offset, offset + chunkLength);
|
|
1028
2635
|
offset += chunkLength;
|
|
1029
|
-
yield
|
|
2636
|
+
yield ensureArrayBuffer(textEncoder.encode(chunk));
|
|
1030
2637
|
}
|
|
1031
2638
|
}
|
|
1032
2639
|
|
|
@@ -1060,37 +2667,72 @@ async function* makeBlobIterator(blob, options) {
|
|
|
1060
2667
|
}
|
|
1061
2668
|
|
|
1062
2669
|
// dist/iterators/make-iterator/make-stream-iterator.js
|
|
1063
|
-
var import_loader_utils9 = require("@loaders.gl/loader-utils");
|
|
1064
2670
|
function makeStreamIterator(stream, options) {
|
|
1065
|
-
return
|
|
2671
|
+
return isBrowser ? makeBrowserStreamIterator(stream, options) : makeNodeStreamIterator(stream, options);
|
|
1066
2672
|
}
|
|
1067
2673
|
async function* makeBrowserStreamIterator(stream, options) {
|
|
1068
2674
|
const reader = stream.getReader();
|
|
1069
2675
|
let nextBatchPromise;
|
|
2676
|
+
let streamFinished = false;
|
|
2677
|
+
let streamReadFailed = false;
|
|
2678
|
+
let iteratorFailed = false;
|
|
1070
2679
|
try {
|
|
1071
2680
|
while (true) {
|
|
1072
2681
|
const currentBatchPromise = nextBatchPromise || reader.read();
|
|
1073
|
-
|
|
1074
|
-
|
|
2682
|
+
nextBatchPromise = void 0;
|
|
2683
|
+
let batch;
|
|
2684
|
+
try {
|
|
2685
|
+
batch = await currentBatchPromise;
|
|
2686
|
+
} catch (error) {
|
|
2687
|
+
streamReadFailed = true;
|
|
2688
|
+
throw error;
|
|
1075
2689
|
}
|
|
1076
|
-
const { done, value } =
|
|
2690
|
+
const { done, value } = batch;
|
|
1077
2691
|
if (done) {
|
|
2692
|
+
streamFinished = true;
|
|
1078
2693
|
return;
|
|
1079
2694
|
}
|
|
1080
|
-
|
|
2695
|
+
if (options == null ? void 0 : options._streamReadAhead) {
|
|
2696
|
+
nextBatchPromise = reader.read();
|
|
2697
|
+
void nextBatchPromise.catch(() => {
|
|
2698
|
+
});
|
|
2699
|
+
}
|
|
2700
|
+
yield toArrayBuffer2(value);
|
|
2701
|
+
}
|
|
2702
|
+
} catch (error) {
|
|
2703
|
+
iteratorFailed = true;
|
|
2704
|
+
throw error;
|
|
2705
|
+
} finally {
|
|
2706
|
+
let cleanupFailed = false;
|
|
2707
|
+
let cleanupError;
|
|
2708
|
+
if (!streamFinished && !streamReadFailed) {
|
|
2709
|
+
try {
|
|
2710
|
+
await reader.cancel();
|
|
2711
|
+
} catch (error) {
|
|
2712
|
+
cleanupFailed = true;
|
|
2713
|
+
cleanupError = error;
|
|
2714
|
+
}
|
|
2715
|
+
}
|
|
2716
|
+
try {
|
|
2717
|
+
reader.releaseLock();
|
|
2718
|
+
} catch (error) {
|
|
2719
|
+
if (!cleanupFailed) {
|
|
2720
|
+
cleanupFailed = true;
|
|
2721
|
+
cleanupError = error;
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
if (!iteratorFailed && cleanupFailed) {
|
|
2725
|
+
throw cleanupError;
|
|
1081
2726
|
}
|
|
1082
|
-
} catch (_error) {
|
|
1083
|
-
reader.releaseLock();
|
|
1084
2727
|
}
|
|
1085
2728
|
}
|
|
1086
2729
|
async function* makeNodeStreamIterator(stream, options) {
|
|
1087
2730
|
for await (const chunk of stream) {
|
|
1088
|
-
yield (
|
|
2731
|
+
yield toArrayBuffer2(chunk);
|
|
1089
2732
|
}
|
|
1090
2733
|
}
|
|
1091
2734
|
|
|
1092
2735
|
// dist/iterators/make-iterator/make-iterator.js
|
|
1093
|
-
var import_loader_utils10 = require("@loaders.gl/loader-utils");
|
|
1094
2736
|
function makeIterator(data, options) {
|
|
1095
2737
|
if (typeof data === "string") {
|
|
1096
2738
|
return makeStringIterator(data, options);
|
|
@@ -1098,13 +2740,13 @@ function makeIterator(data, options) {
|
|
|
1098
2740
|
if (data instanceof ArrayBuffer) {
|
|
1099
2741
|
return makeArrayBufferIterator(data, options);
|
|
1100
2742
|
}
|
|
1101
|
-
if (
|
|
2743
|
+
if (isBlob(data)) {
|
|
1102
2744
|
return makeBlobIterator(data, options);
|
|
1103
2745
|
}
|
|
1104
|
-
if (
|
|
2746
|
+
if (isReadableStream(data)) {
|
|
1105
2747
|
return makeStreamIterator(data, options);
|
|
1106
2748
|
}
|
|
1107
|
-
if (
|
|
2749
|
+
if (isResponse(data)) {
|
|
1108
2750
|
const responseBody = data.body;
|
|
1109
2751
|
if (!responseBody) {
|
|
1110
2752
|
throw new Error("Readable stream not available on Response");
|
|
@@ -1120,35 +2762,35 @@ function getArrayBufferOrStringFromDataSync(data, loader, options) {
|
|
|
1120
2762
|
if (loader.text && typeof data === "string") {
|
|
1121
2763
|
return data;
|
|
1122
2764
|
}
|
|
1123
|
-
if (
|
|
2765
|
+
if (isBuffer(data)) {
|
|
1124
2766
|
data = data.buffer;
|
|
1125
2767
|
}
|
|
1126
|
-
if (
|
|
1127
|
-
const bufferSource =
|
|
2768
|
+
if (isArrayBufferLike(data)) {
|
|
2769
|
+
const bufferSource = toArrayBufferView(data);
|
|
1128
2770
|
if (loader.text && !loader.binary) {
|
|
1129
2771
|
const textDecoder = new TextDecoder("utf8");
|
|
1130
2772
|
return textDecoder.decode(bufferSource);
|
|
1131
2773
|
}
|
|
1132
|
-
return (
|
|
2774
|
+
return toArrayBuffer2(bufferSource);
|
|
1133
2775
|
}
|
|
1134
2776
|
throw new Error(ERR_DATA);
|
|
1135
2777
|
}
|
|
1136
2778
|
async function getArrayBufferOrStringFromData(data, loader, options) {
|
|
1137
|
-
if (typeof data === "string" ||
|
|
2779
|
+
if (typeof data === "string" || isArrayBufferLike(data)) {
|
|
1138
2780
|
return getArrayBufferOrStringFromDataSync(data, loader, options);
|
|
1139
2781
|
}
|
|
1140
|
-
if (
|
|
2782
|
+
if (isBlob(data)) {
|
|
1141
2783
|
data = await makeResponse(data);
|
|
1142
2784
|
}
|
|
1143
|
-
if (
|
|
2785
|
+
if (isResponse(data)) {
|
|
1144
2786
|
await checkResponse(data);
|
|
1145
2787
|
return loader.binary ? await data.arrayBuffer() : await data.text();
|
|
1146
2788
|
}
|
|
1147
|
-
if (
|
|
2789
|
+
if (isReadableStream(data)) {
|
|
1148
2790
|
data = makeIterator(data, options);
|
|
1149
2791
|
}
|
|
1150
|
-
if (
|
|
1151
|
-
return
|
|
2792
|
+
if (isIterable(data) || isAsyncIterable(data)) {
|
|
2793
|
+
return concatenateArrayBuffersAsync(data);
|
|
1152
2794
|
}
|
|
1153
2795
|
throw new Error(ERR_DATA);
|
|
1154
2796
|
}
|
|
@@ -1156,32 +2798,32 @@ async function getArrayBufferFromData(data, options) {
|
|
|
1156
2798
|
if (typeof data === "string") {
|
|
1157
2799
|
return new TextEncoder().encode(data).buffer;
|
|
1158
2800
|
}
|
|
1159
|
-
if (
|
|
1160
|
-
return (
|
|
2801
|
+
if (isArrayBufferLike(data)) {
|
|
2802
|
+
return toArrayBuffer2(toArrayBufferView(data));
|
|
1161
2803
|
}
|
|
1162
|
-
if (
|
|
2804
|
+
if (isBlob(data)) {
|
|
1163
2805
|
data = await makeResponse(data);
|
|
1164
2806
|
}
|
|
1165
|
-
if (
|
|
2807
|
+
if (isResponse(data)) {
|
|
1166
2808
|
await checkResponse(data);
|
|
1167
2809
|
return await data.arrayBuffer();
|
|
1168
2810
|
}
|
|
1169
|
-
if (
|
|
2811
|
+
if (isReadableStream(data)) {
|
|
1170
2812
|
data = makeIterator(data, options);
|
|
1171
2813
|
}
|
|
1172
|
-
if (
|
|
1173
|
-
return
|
|
2814
|
+
if (isIterable(data) || isAsyncIterable(data)) {
|
|
2815
|
+
return concatenateArrayBuffersAsync(data);
|
|
1174
2816
|
}
|
|
1175
2817
|
throw new Error(ERR_DATA);
|
|
1176
2818
|
}
|
|
1177
2819
|
async function getAsyncIterableFromData(data, options) {
|
|
1178
|
-
if (
|
|
2820
|
+
if (isPromise(data)) {
|
|
1179
2821
|
data = await data;
|
|
1180
2822
|
}
|
|
1181
|
-
if (
|
|
2823
|
+
if (isIterator(data)) {
|
|
1182
2824
|
return data;
|
|
1183
2825
|
}
|
|
1184
|
-
if (
|
|
2826
|
+
if (isResponse(data)) {
|
|
1185
2827
|
await checkResponse(data);
|
|
1186
2828
|
const body = await data.body;
|
|
1187
2829
|
if (!body) {
|
|
@@ -1189,63 +2831,68 @@ async function getAsyncIterableFromData(data, options) {
|
|
|
1189
2831
|
}
|
|
1190
2832
|
return makeIterator(body, options);
|
|
1191
2833
|
}
|
|
1192
|
-
if (
|
|
2834
|
+
if (isBlob(data) || isReadableStream(data)) {
|
|
1193
2835
|
return makeIterator(data, options);
|
|
1194
2836
|
}
|
|
1195
|
-
if (
|
|
2837
|
+
if (isAsyncIterable(data)) {
|
|
1196
2838
|
return data;
|
|
1197
2839
|
}
|
|
1198
|
-
if (
|
|
2840
|
+
if (isIterable(data)) {
|
|
1199
2841
|
return data;
|
|
1200
2842
|
}
|
|
1201
2843
|
return getIterableFromData(data);
|
|
1202
2844
|
}
|
|
1203
2845
|
function getIterableFromData(data) {
|
|
1204
2846
|
if (ArrayBuffer.isView(data)) {
|
|
1205
|
-
return function* oneChunk() {
|
|
1206
|
-
yield (
|
|
1207
|
-
}();
|
|
2847
|
+
return (function* oneChunk() {
|
|
2848
|
+
yield toArrayBuffer2(data);
|
|
2849
|
+
})();
|
|
1208
2850
|
}
|
|
1209
|
-
if (
|
|
1210
|
-
return function* oneChunk() {
|
|
1211
|
-
yield (
|
|
1212
|
-
}();
|
|
2851
|
+
if (isArrayBufferLike(data)) {
|
|
2852
|
+
return (function* oneChunk() {
|
|
2853
|
+
yield toArrayBuffer2(data);
|
|
2854
|
+
})();
|
|
1213
2855
|
}
|
|
1214
|
-
if (
|
|
2856
|
+
if (isIterator(data)) {
|
|
1215
2857
|
return data;
|
|
1216
2858
|
}
|
|
1217
|
-
if (
|
|
2859
|
+
if (isIterable(data)) {
|
|
1218
2860
|
return data[Symbol.iterator]();
|
|
1219
2861
|
}
|
|
1220
2862
|
throw new Error(ERR_DATA);
|
|
1221
2863
|
}
|
|
1222
2864
|
|
|
1223
2865
|
// dist/lib/loader-utils/get-fetch-function.js
|
|
1224
|
-
var import_loader_utils12 = require("@loaders.gl/loader-utils");
|
|
1225
2866
|
function getFetchFunction(options, context) {
|
|
1226
|
-
var _a;
|
|
2867
|
+
var _a, _b;
|
|
1227
2868
|
const globalOptions = getGlobalLoaderOptions();
|
|
1228
2869
|
const loaderOptions = options || globalOptions;
|
|
1229
2870
|
const fetchOption = loaderOptions.fetch ?? ((_a = loaderOptions.core) == null ? void 0 : _a.fetch);
|
|
2871
|
+
let fetchFunction;
|
|
1230
2872
|
if (typeof fetchOption === "function") {
|
|
1231
|
-
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
|
|
2873
|
+
fetchFunction = fetchOption;
|
|
2874
|
+
} else if (isObject(fetchOption)) {
|
|
2875
|
+
fetchFunction = (url, requestOptions) => fetchFile(url, mergeFetchOptions(fetchOption, requestOptions));
|
|
2876
|
+
} else if (context == null ? void 0 : context.fetch) {
|
|
2877
|
+
fetchFunction = context.fetch;
|
|
2878
|
+
} else {
|
|
2879
|
+
fetchFunction = fetchFile;
|
|
1235
2880
|
}
|
|
1236
|
-
|
|
1237
|
-
|
|
2881
|
+
return createAuthenticatedFetch({
|
|
2882
|
+
fetch: fetchFunction,
|
|
2883
|
+
credentials: ((_b = loaderOptions.core) == null ? void 0 : _b.credentials) || []
|
|
2884
|
+
});
|
|
2885
|
+
}
|
|
2886
|
+
function mergeFetchOptions(defaultOptions, requestOptions) {
|
|
2887
|
+
const options = { ...defaultOptions, ...requestOptions };
|
|
2888
|
+
if (defaultOptions.headers || (requestOptions == null ? void 0 : requestOptions.headers)) {
|
|
2889
|
+
const headers = new Headers(defaultOptions.headers);
|
|
2890
|
+
new Headers(requestOptions == null ? void 0 : requestOptions.headers).forEach((value, key) => headers.set(key, value));
|
|
2891
|
+
options.headers = headers;
|
|
1238
2892
|
}
|
|
1239
|
-
return
|
|
2893
|
+
return options;
|
|
1240
2894
|
}
|
|
1241
2895
|
|
|
1242
|
-
// dist/lib/loader-utils/loader-context.js
|
|
1243
|
-
var import_loader_utils17 = require("@loaders.gl/loader-utils");
|
|
1244
|
-
|
|
1245
|
-
// dist/lib/api/parse-file.js
|
|
1246
|
-
var import_loader_utils13 = require("@loaders.gl/loader-utils");
|
|
1247
|
-
var import_worker_utils = require("@loaders.gl/worker-utils");
|
|
1248
|
-
|
|
1249
2896
|
// dist/lib/api/load-loader.js
|
|
1250
2897
|
var loaderImplementationPromises = /* @__PURE__ */ new Map();
|
|
1251
2898
|
var loaderImplementations = /* @__PURE__ */ new Map();
|
|
@@ -1327,10 +2974,7 @@ function getLoaderImplementationCacheKey(loader, options) {
|
|
|
1327
2974
|
var _a;
|
|
1328
2975
|
const loaderOptions = options == null ? void 0 : options[loader.id];
|
|
1329
2976
|
const defaultLoaderOptions = (_a = loader.options) == null ? void 0 : _a[loader.id];
|
|
1330
|
-
return String((loaderOptions == null ? void 0 : loaderOptions.backend) ||
|
|
1331
|
-
}
|
|
1332
|
-
function getDeprecatedImplementationBackend(implementation) {
|
|
1333
|
-
return implementation === "js" ? "typescript" : implementation;
|
|
2977
|
+
return String((loaderOptions == null ? void 0 : loaderOptions.backend) || (defaultLoaderOptions == null ? void 0 : defaultLoaderOptions.backend) || "");
|
|
1334
2978
|
}
|
|
1335
2979
|
async function importLoaderImplementation(implementationSpecifier, loaderId) {
|
|
1336
2980
|
const moduleExports = await import(
|
|
@@ -1361,7 +3005,7 @@ async function parseFile(file, loaders, options, context) {
|
|
|
1361
3005
|
if (!loader) {
|
|
1362
3006
|
return null;
|
|
1363
3007
|
}
|
|
1364
|
-
if (
|
|
3008
|
+
if (isSourceLoader(loader)) {
|
|
1365
3009
|
throw new Error(`${loader.id} is a SourceLoader. Use load() to create a runtime source object instead of parseFile().`);
|
|
1366
3010
|
}
|
|
1367
3011
|
const strictOptions = normalizeOptions(options, loader, candidateLoaders, url);
|
|
@@ -1374,8 +3018,8 @@ async function parseFile(file, loaders, options, context) {
|
|
|
1374
3018
|
return await parseFileWithLoader(loader, file, strictOptions, context);
|
|
1375
3019
|
}
|
|
1376
3020
|
async function parseFileWithLoader(loader, file, options, context) {
|
|
1377
|
-
|
|
1378
|
-
options =
|
|
3021
|
+
validateWorkerVersion(loader);
|
|
3022
|
+
options = mergeOptions(loader.options, options);
|
|
1379
3023
|
const loaderWithParser = await getLoaderImplementation(loader, options, context.url);
|
|
1380
3024
|
if (loaderWithParser.parseFile) {
|
|
1381
3025
|
return await loaderWithParser.parseFile(file, options, context);
|
|
@@ -1393,7 +3037,6 @@ async function parseFileWithLoader(loader, file, options, context) {
|
|
|
1393
3037
|
}
|
|
1394
3038
|
|
|
1395
3039
|
// dist/lib/api/parse-sync.js
|
|
1396
|
-
var import_loader_utils14 = require("@loaders.gl/loader-utils");
|
|
1397
3040
|
function parseSync(data, loaders, options, context) {
|
|
1398
3041
|
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
1399
3042
|
context = void 0;
|
|
@@ -1407,7 +3050,7 @@ function parseSync(data, loaders, options, context) {
|
|
|
1407
3050
|
if (!loader) {
|
|
1408
3051
|
return null;
|
|
1409
3052
|
}
|
|
1410
|
-
if (
|
|
3053
|
+
if (isSourceLoader(loader)) {
|
|
1411
3054
|
throw new Error(`${loader.id} is a SourceLoader. Use load() to create a runtime source object instead of parseSync().`);
|
|
1412
3055
|
}
|
|
1413
3056
|
const strictOptions = normalizeOptions(options, loader, candidateLoaders);
|
|
@@ -1433,9 +3076,50 @@ function parseWithLoaderSync(loader, data, options, context) {
|
|
|
1433
3076
|
throw new Error(`${loader.name} loader: 'parseSync' not supported by this loader, use 'parse' instead. ${context.url || ""}`);
|
|
1434
3077
|
}
|
|
1435
3078
|
|
|
3079
|
+
// ../schema-utils/src/lib/table/tables/table-accessors.ts
|
|
3080
|
+
function isTable(table) {
|
|
3081
|
+
var _a;
|
|
3082
|
+
const shape = typeof table === "object" && (table == null ? void 0 : table.shape);
|
|
3083
|
+
switch (shape) {
|
|
3084
|
+
case "array-row-table":
|
|
3085
|
+
case "object-row-table":
|
|
3086
|
+
return Array.isArray(table.data);
|
|
3087
|
+
case "geojson-table":
|
|
3088
|
+
return Array.isArray(table.features);
|
|
3089
|
+
case "columnar-table":
|
|
3090
|
+
return Boolean(table.data && typeof table.data === "object");
|
|
3091
|
+
case "arrow-table":
|
|
3092
|
+
return Boolean(((_a = table == null ? void 0 : table.data) == null ? void 0 : _a.numRows) !== void 0);
|
|
3093
|
+
default:
|
|
3094
|
+
return false;
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
function getTableLength(table) {
|
|
3098
|
+
switch (table.shape) {
|
|
3099
|
+
case "array-row-table":
|
|
3100
|
+
case "object-row-table":
|
|
3101
|
+
return table.data.length;
|
|
3102
|
+
case "geojson-table":
|
|
3103
|
+
return table.features.length;
|
|
3104
|
+
case "arrow-table":
|
|
3105
|
+
const arrowTable = table.data;
|
|
3106
|
+
return arrowTable.numRows;
|
|
3107
|
+
case "columnar-table":
|
|
3108
|
+
for (const column of Object.values(table.data)) {
|
|
3109
|
+
return column.length || 0;
|
|
3110
|
+
}
|
|
3111
|
+
return 0;
|
|
3112
|
+
default:
|
|
3113
|
+
throw new Error("table");
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
|
|
3117
|
+
// ../schema-utils/src/lib/table/batches/make-table-batch-iterator.ts
|
|
3118
|
+
function makeBatchFromTable(table) {
|
|
3119
|
+
return { ...table, length: getTableLength(table), batchType: "data" };
|
|
3120
|
+
}
|
|
3121
|
+
|
|
1436
3122
|
// dist/lib/api/parse-in-batches.js
|
|
1437
|
-
var import_schema_utils = require("@loaders.gl/schema-utils");
|
|
1438
|
-
var import_loader_utils15 = require("@loaders.gl/loader-utils");
|
|
1439
3123
|
async function parseInBatches(data, loaders, options, context) {
|
|
1440
3124
|
const loaderArray = Array.isArray(loaders) ? loaders : void 0;
|
|
1441
3125
|
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
@@ -1488,7 +3172,7 @@ async function parseToOutputIterator(loader, data, options, context) {
|
|
|
1488
3172
|
return parseChunkInBatches(transformedIterator, loader, options, context);
|
|
1489
3173
|
}
|
|
1490
3174
|
async function* parseChunkInBatches(transformedIterator, loader, options, context) {
|
|
1491
|
-
const arrayBuffer = await
|
|
3175
|
+
const arrayBuffer = await concatenateArrayBuffersAsync(transformedIterator);
|
|
1492
3176
|
const parsedData = await parse(
|
|
1493
3177
|
arrayBuffer,
|
|
1494
3178
|
loader,
|
|
@@ -1500,7 +3184,7 @@ async function* parseChunkInBatches(transformedIterator, loader, options, contex
|
|
|
1500
3184
|
yield batch;
|
|
1501
3185
|
}
|
|
1502
3186
|
function convertDataToBatch(parsedData, loader) {
|
|
1503
|
-
const batch =
|
|
3187
|
+
const batch = isTable(parsedData) ? makeBatchFromTable(parsedData) : {
|
|
1504
3188
|
shape: "unknown",
|
|
1505
3189
|
batchType: "data",
|
|
1506
3190
|
data: parsedData,
|
|
@@ -1517,9 +3201,6 @@ async function applyInputTransforms(inputIterator, transforms = []) {
|
|
|
1517
3201
|
return iteratorChain;
|
|
1518
3202
|
}
|
|
1519
3203
|
|
|
1520
|
-
// dist/lib/api/load.js
|
|
1521
|
-
var import_loader_utils16 = require("@loaders.gl/loader-utils");
|
|
1522
|
-
|
|
1523
3204
|
// dist/lib/api/load-in-batches.js
|
|
1524
3205
|
function loadInBatches(files, loaders, options, context) {
|
|
1525
3206
|
let loadersArray;
|
|
@@ -1559,7 +3240,8 @@ async function load(url, loaders, options, context) {
|
|
|
1559
3240
|
resolvedLoaders = loaders;
|
|
1560
3241
|
resolvedOptions = options;
|
|
1561
3242
|
}
|
|
1562
|
-
if (!Array.isArray(resolvedLoaders) &&
|
|
3243
|
+
if (!Array.isArray(resolvedLoaders) && isSourceLoader(resolvedLoaders)) {
|
|
3244
|
+
const sourceLoader = await resolveSourceLoader(resolvedLoaders, url, resolvedOptions);
|
|
1563
3245
|
const runtimeCoreApi = {
|
|
1564
3246
|
fetchFile,
|
|
1565
3247
|
parse,
|
|
@@ -1569,9 +3251,10 @@ async function load(url, loaders, options, context) {
|
|
|
1569
3251
|
load,
|
|
1570
3252
|
loadInBatches
|
|
1571
3253
|
};
|
|
1572
|
-
return
|
|
3254
|
+
return sourceLoader.createDataSource(url, resolvedOptions || {}, runtimeCoreApi);
|
|
1573
3255
|
}
|
|
1574
|
-
if (Array.isArray(resolvedLoaders) && resolvedLoaders.length === 1 &&
|
|
3256
|
+
if (Array.isArray(resolvedLoaders) && resolvedLoaders.length === 1 && isSourceLoader(resolvedLoaders[0])) {
|
|
3257
|
+
const sourceLoader = await resolveSourceLoader(resolvedLoaders[0], url, resolvedOptions);
|
|
1575
3258
|
const runtimeCoreApi = {
|
|
1576
3259
|
fetchFile,
|
|
1577
3260
|
parse,
|
|
@@ -1581,15 +3264,16 @@ async function load(url, loaders, options, context) {
|
|
|
1581
3264
|
load,
|
|
1582
3265
|
loadInBatches
|
|
1583
3266
|
};
|
|
1584
|
-
return
|
|
3267
|
+
return sourceLoader.createDataSource(url, resolvedOptions || {}, runtimeCoreApi);
|
|
1585
3268
|
}
|
|
1586
|
-
if (typeof url === "string" ||
|
|
3269
|
+
if (typeof url === "string" || isBlob(url)) {
|
|
1587
3270
|
const selectedLoader = await selectLoader(url, resolvedLoaders, {
|
|
1588
3271
|
...resolvedOptions,
|
|
1589
3272
|
core: { ...resolvedOptions == null ? void 0 : resolvedOptions.core, nothrow: true }
|
|
1590
3273
|
});
|
|
1591
|
-
if (selectedLoader &&
|
|
1592
|
-
|
|
3274
|
+
if (selectedLoader && isSourceLoader(selectedLoader)) {
|
|
3275
|
+
const sourceLoader = await resolveSourceLoader(selectedLoader, url, resolvedOptions);
|
|
3276
|
+
return sourceLoader.createDataSource(url, resolvedOptions || {}, {
|
|
1593
3277
|
fetchFile,
|
|
1594
3278
|
parse,
|
|
1595
3279
|
parseFile,
|
|
@@ -1599,13 +3283,19 @@ async function load(url, loaders, options, context) {
|
|
|
1599
3283
|
loadInBatches
|
|
1600
3284
|
});
|
|
1601
3285
|
}
|
|
3286
|
+
if (selectedLoader && typeof url === "string") {
|
|
3287
|
+
const loaderImplementation = await getLoaderImplementation(selectedLoader, resolvedOptions, url);
|
|
3288
|
+
const parseUrl = loaderImplementation.parseUrl;
|
|
3289
|
+
if (parseUrl)
|
|
3290
|
+
return await parseUrl(url, resolvedOptions, context);
|
|
3291
|
+
}
|
|
1602
3292
|
}
|
|
1603
3293
|
const fetch2 = getFetchFunction(resolvedOptions);
|
|
1604
3294
|
let data = url;
|
|
1605
3295
|
if (typeof url === "string") {
|
|
1606
3296
|
data = await fetch2(url);
|
|
1607
3297
|
}
|
|
1608
|
-
if (
|
|
3298
|
+
if (isBlob(url)) {
|
|
1609
3299
|
data = await fetch2(url);
|
|
1610
3300
|
}
|
|
1611
3301
|
if (typeof url === "string") {
|
|
@@ -1622,6 +3312,16 @@ async function load(url, loaders, options, context) {
|
|
|
1622
3312
|
}
|
|
1623
3313
|
return Array.isArray(resolvedLoaders) ? await parse(data, resolvedLoaders, resolvedOptions, context) : await parse(data, resolvedLoaders, resolvedOptions, context);
|
|
1624
3314
|
}
|
|
3315
|
+
async function resolveSourceLoader(loader, url, options) {
|
|
3316
|
+
if (!loader.preload) {
|
|
3317
|
+
return loader;
|
|
3318
|
+
}
|
|
3319
|
+
const sourceLoader = await loader.preload(typeof url === "string" ? url : "", options);
|
|
3320
|
+
if (!isSourceLoader(sourceLoader)) {
|
|
3321
|
+
throw new Error(`${loader.id} source loader preload() did not return a runtime source loader`);
|
|
3322
|
+
}
|
|
3323
|
+
return sourceLoader;
|
|
3324
|
+
}
|
|
1625
3325
|
|
|
1626
3326
|
// dist/lib/api/core-api.js
|
|
1627
3327
|
var coreApi = Object.freeze({
|
|
@@ -1648,8 +3348,8 @@ function getLoaderContext(context, options, parentContext) {
|
|
|
1648
3348
|
const baseUrl = stripQueryString(newContext.url);
|
|
1649
3349
|
newContext.baseUrl = baseUrl;
|
|
1650
3350
|
newContext.queryString = extractQueryString(newContext.url);
|
|
1651
|
-
newContext.filename =
|
|
1652
|
-
newContext.baseUrl =
|
|
3351
|
+
newContext.filename = path_exports.filename(baseUrl);
|
|
3352
|
+
newContext.baseUrl = path_exports.dirname(baseUrl);
|
|
1653
3353
|
}
|
|
1654
3354
|
if (!Array.isArray(newContext.loaders)) {
|
|
1655
3355
|
newContext.loaders = null;
|
|
@@ -1687,7 +3387,7 @@ async function parse(data, loaders, options, context) {
|
|
|
1687
3387
|
if (!loader) {
|
|
1688
3388
|
return null;
|
|
1689
3389
|
}
|
|
1690
|
-
if (
|
|
3390
|
+
if (isSourceLoader(loader)) {
|
|
1691
3391
|
throw new Error(`${loader.id} is a SourceLoader. Use load() to create a runtime source object instead of parse().`);
|
|
1692
3392
|
}
|
|
1693
3393
|
const strictOptions = normalizeOptions(options, loader, candidateLoaders, url);
|
|
@@ -1700,17 +3400,20 @@ async function parse(data, loaders, options, context) {
|
|
|
1700
3400
|
return await parseWithLoader(loader, data, strictOptions, context);
|
|
1701
3401
|
}
|
|
1702
3402
|
async function parseWithLoader(loader, data, options, context) {
|
|
1703
|
-
|
|
1704
|
-
options =
|
|
1705
|
-
if (
|
|
3403
|
+
validateWorkerVersion(loader);
|
|
3404
|
+
options = mergeOptions(loader.options, options);
|
|
3405
|
+
if (isResponse(data)) {
|
|
1706
3406
|
const { ok, redirected, status, statusText, type, url } = data;
|
|
1707
3407
|
const headers = Object.fromEntries(data.headers.entries());
|
|
1708
3408
|
context.response = { headers, ok, redirected, status, statusText, type, url };
|
|
1709
3409
|
}
|
|
1710
3410
|
const loaderWithParser = await getLoaderImplementation(loader, options, context.url);
|
|
1711
|
-
if (
|
|
3411
|
+
if (canParseWithWorker(loaderWithParser, options)) {
|
|
1712
3412
|
data = await getArrayBufferFromData(data, options);
|
|
1713
|
-
return await
|
|
3413
|
+
return await parseWithWorker(loaderWithParser, data, options, context, parse);
|
|
3414
|
+
}
|
|
3415
|
+
if (isBlob(data) && loaderWithParser.parseBlob) {
|
|
3416
|
+
return await loaderWithParser.parseBlob(data, options, context);
|
|
1714
3417
|
}
|
|
1715
3418
|
data = await getArrayBufferOrStringFromData(data, loader, options);
|
|
1716
3419
|
return await parseWithLoaderImplementation(loaderWithParser, data, options, context);
|
|
@@ -1740,14 +3443,13 @@ function preloadSync(loader) {
|
|
|
1740
3443
|
}
|
|
1741
3444
|
|
|
1742
3445
|
// dist/lib/api/encode-table.js
|
|
1743
|
-
var import_loader_utils19 = require("@loaders.gl/loader-utils");
|
|
1744
3446
|
async function encodeTable(data, writer, options) {
|
|
1745
3447
|
if (writer.encode) {
|
|
1746
3448
|
return await writer.encode(data, options);
|
|
1747
3449
|
}
|
|
1748
3450
|
if (writer.encodeText) {
|
|
1749
3451
|
const text = await writer.encodeText(data, options);
|
|
1750
|
-
return
|
|
3452
|
+
return ensureArrayBuffer(new TextEncoder().encode(text));
|
|
1751
3453
|
}
|
|
1752
3454
|
if (writer.encodeInBatches) {
|
|
1753
3455
|
const batches = encodeTableInBatches(data, writer, options);
|
|
@@ -1755,7 +3457,7 @@ async function encodeTable(data, writer, options) {
|
|
|
1755
3457
|
for await (const batch of batches) {
|
|
1756
3458
|
chunks.push(batch);
|
|
1757
3459
|
}
|
|
1758
|
-
return
|
|
3460
|
+
return concatenateArrayBuffers(...chunks);
|
|
1759
3461
|
}
|
|
1760
3462
|
throw new Error("Writer could not encode data");
|
|
1761
3463
|
}
|
|
@@ -1782,16 +3484,14 @@ function getIterator(data) {
|
|
|
1782
3484
|
}
|
|
1783
3485
|
|
|
1784
3486
|
// dist/lib/api/encode.js
|
|
1785
|
-
var import_loader_utils20 = require("@loaders.gl/loader-utils");
|
|
1786
|
-
var import_worker_utils3 = require("@loaders.gl/worker-utils");
|
|
1787
3487
|
async function encode(data, writer, options_) {
|
|
1788
3488
|
const globalOptions = getGlobalLoaderOptions();
|
|
1789
3489
|
const options = { ...globalOptions, ...options_ };
|
|
1790
3490
|
if (writer.encodeURLtoURL) {
|
|
1791
3491
|
return encodeWithCommandLineTool(writer, data, options);
|
|
1792
3492
|
}
|
|
1793
|
-
if (
|
|
1794
|
-
return await
|
|
3493
|
+
if (canEncodeWithWorker(writer, options)) {
|
|
3494
|
+
return await processOnWorker(writer, data, options);
|
|
1795
3495
|
}
|
|
1796
3496
|
return await writer.encode(data, options);
|
|
1797
3497
|
}
|
|
@@ -1800,7 +3500,7 @@ function encodeSync(data, writer, options) {
|
|
|
1800
3500
|
return writer.encodeSync(data, options);
|
|
1801
3501
|
}
|
|
1802
3502
|
if (writer.encodeTextSync) {
|
|
1803
|
-
return
|
|
3503
|
+
return ensureArrayBuffer(new TextEncoder().encode(writer.encodeTextSync(data, options)));
|
|
1804
3504
|
}
|
|
1805
3505
|
throw new Error(`Writer ${writer.name} could not synchronously encode data`);
|
|
1806
3506
|
}
|
|
@@ -1835,20 +3535,20 @@ function encodeInBatches(data, writer, options) {
|
|
|
1835
3535
|
throw new Error(`Writer ${writer.name} could not encode in batches`);
|
|
1836
3536
|
}
|
|
1837
3537
|
async function encodeURLtoURL(inputUrl, outputUrl, writer, options) {
|
|
1838
|
-
inputUrl =
|
|
1839
|
-
outputUrl =
|
|
1840
|
-
if (
|
|
3538
|
+
inputUrl = resolvePath(inputUrl);
|
|
3539
|
+
outputUrl = resolvePath(outputUrl);
|
|
3540
|
+
if (isBrowser || !writer.encodeURLtoURL) {
|
|
1841
3541
|
throw new Error();
|
|
1842
3542
|
}
|
|
1843
3543
|
const outputFilename = await writer.encodeURLtoURL(inputUrl, outputUrl, options);
|
|
1844
3544
|
return outputFilename;
|
|
1845
3545
|
}
|
|
1846
3546
|
async function encodeWithCommandLineTool(writer, data, options) {
|
|
1847
|
-
if (
|
|
3547
|
+
if (isBrowser) {
|
|
1848
3548
|
throw new Error(`Writer ${writer.name} not supported in browser`);
|
|
1849
3549
|
}
|
|
1850
3550
|
const tmpInputFilename = getTemporaryFilename("input");
|
|
1851
|
-
const file = new
|
|
3551
|
+
const file = new NodeFileFacade(tmpInputFilename, "w");
|
|
1852
3552
|
await file.write(data);
|
|
1853
3553
|
const tmpOutputFilename = getTemporaryFilename("output");
|
|
1854
3554
|
const outputFilename = await encodeURLtoURL(tmpInputFilename, tmpOutputFilename, writer, options);
|
|
@@ -1859,8 +3559,8 @@ function getIterator2(data) {
|
|
|
1859
3559
|
const dataIterator = [{ ...data, start: 0, end: data.length }];
|
|
1860
3560
|
return dataIterator;
|
|
1861
3561
|
}
|
|
1862
|
-
function getTemporaryFilename(
|
|
1863
|
-
return `/tmp/${
|
|
3562
|
+
function getTemporaryFilename(filename2) {
|
|
3563
|
+
return `/tmp/${filename2}`;
|
|
1864
3564
|
}
|
|
1865
3565
|
|
|
1866
3566
|
// dist/lib/api/create-data-source.js
|
|
@@ -1911,10 +3611,6 @@ function getSourceOfType2(type, sources) {
|
|
|
1911
3611
|
return null;
|
|
1912
3612
|
}
|
|
1913
3613
|
|
|
1914
|
-
// dist/index.js
|
|
1915
|
-
var import_loader_utils22 = require("@loaders.gl/loader-utils");
|
|
1916
|
-
var import_loader_utils23 = require("@loaders.gl/loader-utils");
|
|
1917
|
-
|
|
1918
3614
|
// dist/iterators/make-stream/make-stream.js
|
|
1919
3615
|
function makeStream(source, options) {
|
|
1920
3616
|
if (globalThis.loaders.makeNodeStream) {
|
|
@@ -1955,14 +3651,14 @@ function makeStream(source, options) {
|
|
|
1955
3651
|
}
|
|
1956
3652
|
|
|
1957
3653
|
// dist/null-loader.js
|
|
1958
|
-
var
|
|
3654
|
+
var VERSION4 = true ? "5.0.0-alpha.3" : "latest";
|
|
1959
3655
|
var NullWorkerLoader = {
|
|
1960
3656
|
dataType: null,
|
|
1961
3657
|
batchType: null,
|
|
1962
3658
|
name: "Null loader",
|
|
1963
3659
|
id: "null",
|
|
1964
3660
|
module: "core",
|
|
1965
|
-
version:
|
|
3661
|
+
version: VERSION4,
|
|
1966
3662
|
worker: true,
|
|
1967
3663
|
mimeTypes: ["application/x.empty"],
|
|
1968
3664
|
extensions: ["null"],
|
|
@@ -1977,7 +3673,7 @@ var NullLoader = {
|
|
|
1977
3673
|
name: "Null loader",
|
|
1978
3674
|
id: "null",
|
|
1979
3675
|
module: "core",
|
|
1980
|
-
version:
|
|
3676
|
+
version: VERSION4,
|
|
1981
3677
|
mimeTypes: ["application/x.empty"],
|
|
1982
3678
|
extensions: ["null"],
|
|
1983
3679
|
parse: async (arrayBuffer, options, context) => parseSync2(arrayBuffer, options || {}, context),
|
|
@@ -1996,9 +3692,6 @@ function parseSync2(arrayBuffer, options, context) {
|
|
|
1996
3692
|
return null;
|
|
1997
3693
|
}
|
|
1998
3694
|
|
|
1999
|
-
// dist/index.js
|
|
2000
|
-
var import_loader_utils24 = require("@loaders.gl/loader-utils");
|
|
2001
|
-
|
|
2002
3695
|
// dist/lib/progress/fetch-progress.js
|
|
2003
3696
|
async function fetchProgress(response, onProgress, onDone = () => {
|
|
2004
3697
|
}, onError = () => {
|
|
@@ -2047,7 +3740,6 @@ async function read(controller, reader, loadedBytes, totalBytes, onProgress, onD
|
|
|
2047
3740
|
}
|
|
2048
3741
|
|
|
2049
3742
|
// dist/lib/filesystems/browser-filesystem.js
|
|
2050
|
-
var import_loader_utils21 = require("@loaders.gl/loader-utils");
|
|
2051
3743
|
var BrowserFileSystem = class {
|
|
2052
3744
|
_fetch;
|
|
2053
3745
|
files = {};
|
|
@@ -2073,27 +3765,38 @@ var BrowserFileSystem = class {
|
|
|
2073
3765
|
* Implementation of fetch against this file system
|
|
2074
3766
|
* Delegates to global fetch for http{s}:// or data://
|
|
2075
3767
|
*/
|
|
2076
|
-
async fetch(
|
|
2077
|
-
if (
|
|
2078
|
-
return this._fetch(
|
|
3768
|
+
async fetch(path, options) {
|
|
3769
|
+
if (path.includes("://")) {
|
|
3770
|
+
return this._fetch(path, options);
|
|
2079
3771
|
}
|
|
2080
|
-
const file = this.
|
|
3772
|
+
const file = this._getFile(path, true);
|
|
2081
3773
|
if (!file) {
|
|
2082
|
-
return new Response(
|
|
3774
|
+
return new Response(path, { status: 400, statusText: "NOT FOUND" });
|
|
2083
3775
|
}
|
|
2084
3776
|
const headers = new Headers(options == null ? void 0 : options.headers);
|
|
2085
3777
|
const range = headers.get("Range");
|
|
2086
|
-
const bytes = range && /bytes=(
|
|
3778
|
+
const bytes = range && /bytes=(\d+)-(\d+)/.exec(range);
|
|
2087
3779
|
if (bytes) {
|
|
2088
3780
|
const start = parseInt(bytes[1]);
|
|
2089
|
-
const end = parseInt(bytes[2]);
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
3781
|
+
const end = Math.min(parseInt(bytes[2]), file.size - 1);
|
|
3782
|
+
if (start > end) {
|
|
3783
|
+
const response3 = new Response(null, {
|
|
3784
|
+
status: 416,
|
|
3785
|
+
headers: { "Content-Range": `bytes */${file.size}` }
|
|
3786
|
+
});
|
|
3787
|
+
Object.defineProperty(response3, "url", { value: path });
|
|
3788
|
+
return response3;
|
|
3789
|
+
}
|
|
3790
|
+
const data = await file.slice(start, end + 1).arrayBuffer();
|
|
3791
|
+
const response2 = new Response(data, {
|
|
3792
|
+
status: 206,
|
|
3793
|
+
headers: { "Content-Range": `bytes ${start}-${end}/${file.size}` }
|
|
3794
|
+
});
|
|
3795
|
+
Object.defineProperty(response2, "url", { value: path });
|
|
2093
3796
|
return response2;
|
|
2094
3797
|
}
|
|
2095
3798
|
const response = new Response(file);
|
|
2096
|
-
Object.defineProperty(response, "url", { value:
|
|
3799
|
+
Object.defineProperty(response, "url", { value: path });
|
|
2097
3800
|
return response;
|
|
2098
3801
|
}
|
|
2099
3802
|
/**
|
|
@@ -2101,51 +3804,47 @@ var BrowserFileSystem = class {
|
|
|
2101
3804
|
* @param dirname
|
|
2102
3805
|
* @returns
|
|
2103
3806
|
*/
|
|
2104
|
-
async readdir(
|
|
3807
|
+
async readdir(dirname2) {
|
|
2105
3808
|
const files = [];
|
|
2106
|
-
for (const
|
|
2107
|
-
files.push(
|
|
3809
|
+
for (const path in this.files) {
|
|
3810
|
+
files.push(path);
|
|
2108
3811
|
}
|
|
2109
3812
|
return files;
|
|
2110
3813
|
}
|
|
2111
3814
|
/**
|
|
2112
3815
|
* Return information (size) about files in this file system
|
|
2113
3816
|
*/
|
|
2114
|
-
async stat(
|
|
2115
|
-
const file = this.
|
|
3817
|
+
async stat(path, options) {
|
|
3818
|
+
const file = this._getFile(path, false);
|
|
2116
3819
|
if (!file) {
|
|
2117
|
-
throw new Error(
|
|
3820
|
+
throw new Error(path);
|
|
2118
3821
|
}
|
|
2119
3822
|
return { size: file.size };
|
|
2120
3823
|
}
|
|
2121
3824
|
/**
|
|
2122
3825
|
* Just removes the file from the list
|
|
2123
3826
|
*/
|
|
2124
|
-
async unlink(
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
3827
|
+
async unlink(path) {
|
|
3828
|
+
const file = this._getFile(path, false);
|
|
3829
|
+
if (file) {
|
|
3830
|
+
delete this.files[file.name];
|
|
3831
|
+
delete this.lowerCaseFiles[file.name.toLowerCase()];
|
|
3832
|
+
this.usedFiles[file.name] = true;
|
|
3833
|
+
}
|
|
2128
3834
|
}
|
|
2129
3835
|
// implements IRandomAccessFileSystem
|
|
2130
3836
|
// RANDOM ACCESS
|
|
2131
3837
|
async openReadableFile(pathname, flags) {
|
|
2132
|
-
return new
|
|
3838
|
+
return new BlobFile(this._getFile(pathname, true));
|
|
2133
3839
|
}
|
|
2134
3840
|
// PRIVATE
|
|
2135
3841
|
// Supports case independent paths, and file usage tracking
|
|
2136
|
-
_getFile(
|
|
2137
|
-
const file = this.files[
|
|
3842
|
+
_getFile(path, used) {
|
|
3843
|
+
const file = this.files[path] || this.lowerCaseFiles[path.toLowerCase()];
|
|
2138
3844
|
if (file && used) {
|
|
2139
|
-
this.usedFiles[
|
|
3845
|
+
this.usedFiles[path] = true;
|
|
2140
3846
|
}
|
|
2141
3847
|
return file;
|
|
2142
3848
|
}
|
|
2143
3849
|
};
|
|
2144
|
-
|
|
2145
|
-
// dist/index.js
|
|
2146
|
-
var import_loader_utils25 = require("@loaders.gl/loader-utils");
|
|
2147
|
-
var import_loader_utils26 = require("@loaders.gl/loader-utils");
|
|
2148
|
-
var import_loader_utils27 = require("@loaders.gl/loader-utils");
|
|
2149
|
-
var import_loader_utils28 = require("@loaders.gl/loader-utils");
|
|
2150
|
-
var import_loader_utils29 = require("@loaders.gl/loader-utils");
|
|
2151
3850
|
//# sourceMappingURL=index.cjs.map
|