@loaders.gl/core 5.0.0-alpha.1 → 5.0.0-alpha.2
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 +238 -130
- package/dist/dist.min.js +3 -3
- package/dist/index.cjs +1778 -234
- 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.js +17 -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/init.js +1 -1
- package/dist/null-loader.js +1 -1
- package/dist/null-worker-node.js +1 -1
- package/dist/null-worker.js +1 -1
- 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 +23 -3
- package/src/lib/api/parse.ts +5 -0
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,1523 @@ __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
|
+
/** Terminates the worker executing this job and rejects its result with an abort error. */
|
|
274
|
+
abort() {
|
|
275
|
+
if (!this.isRunning) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const error = new Error(`Worker job "${this.name}" was aborted`);
|
|
279
|
+
error.name = "AbortError";
|
|
280
|
+
this.workerThread.destroy();
|
|
281
|
+
this.error(error);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// ../worker-utils/src/lib/node/worker_threads-browser.ts
|
|
286
|
+
var NodeWorker = class {
|
|
287
|
+
/** Restores the native worker constructor when this browser shim is embedded in a Node bundle. */
|
|
288
|
+
constructor(...arguments_) {
|
|
289
|
+
var _a;
|
|
290
|
+
const runtimeProcess = globalThis.process;
|
|
291
|
+
const WorkerConstructor = (_a = runtimeProcess == null ? void 0 : runtimeProcess.getBuiltinModule) == null ? void 0 : _a.call(runtimeProcess, "node:worker_threads").Worker;
|
|
292
|
+
if (WorkerConstructor) {
|
|
293
|
+
return new WorkerConstructor(...arguments_);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/** No-op browser fallback matching the native Worker API. */
|
|
297
|
+
terminate() {
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
// ../worker-utils/src/lib/worker-utils/get-loadable-worker-url.ts
|
|
302
|
+
var workerURLCache = /* @__PURE__ */ new Map();
|
|
303
|
+
function getLoadableWorkerURL(props) {
|
|
304
|
+
assert2(props.source && !props.url || !props.source && props.url);
|
|
305
|
+
let workerURL = workerURLCache.get(props.source || props.url);
|
|
306
|
+
if (!workerURL) {
|
|
307
|
+
if (props.url) {
|
|
308
|
+
workerURL = getLoadableWorkerURLFromURL(props.url);
|
|
309
|
+
workerURLCache.set(props.url, workerURL);
|
|
310
|
+
}
|
|
311
|
+
if (props.source) {
|
|
312
|
+
workerURL = getLoadableWorkerURLFromSource(props.source);
|
|
313
|
+
workerURLCache.set(props.source, workerURL);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
assert2(workerURL);
|
|
317
|
+
return workerURL;
|
|
318
|
+
}
|
|
319
|
+
function getLoadableWorkerURLFromURL(url) {
|
|
320
|
+
if (!url.startsWith("http")) {
|
|
321
|
+
return url;
|
|
322
|
+
}
|
|
323
|
+
const workerSource = buildScriptSource(url);
|
|
324
|
+
return getLoadableWorkerURLFromSource(workerSource);
|
|
325
|
+
}
|
|
326
|
+
function getLoadableWorkerURLFromSource(workerSource) {
|
|
327
|
+
const blob = new Blob([workerSource], { type: "application/javascript" });
|
|
328
|
+
return URL.createObjectURL(blob);
|
|
329
|
+
}
|
|
330
|
+
function buildScriptSource(workerUrl) {
|
|
331
|
+
return `try {
|
|
332
|
+
importScripts('${workerUrl}');
|
|
333
|
+
} catch (error) {
|
|
334
|
+
console.error(error);
|
|
335
|
+
throw error;
|
|
336
|
+
}`;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
|
|
340
|
+
function getTransferList(object, recursive = true, transfers) {
|
|
341
|
+
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
342
|
+
if (!object) {
|
|
343
|
+
} else if (isTransferable(object)) {
|
|
344
|
+
transfersSet.add(object);
|
|
345
|
+
} else if (isTransferable(object.buffer)) {
|
|
346
|
+
transfersSet.add(object.buffer);
|
|
347
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
348
|
+
} else if (recursive && typeof object === "object") {
|
|
349
|
+
for (const key in object) {
|
|
350
|
+
getTransferList(object[key], recursive, transfersSet);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
354
|
+
}
|
|
355
|
+
function isTransferable(object) {
|
|
356
|
+
if (!object) {
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
if (object instanceof ArrayBuffer) {
|
|
360
|
+
return true;
|
|
361
|
+
}
|
|
362
|
+
if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
365
|
+
if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
|
|
369
|
+
return true;
|
|
370
|
+
}
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
function getTransferListForWriter(object) {
|
|
374
|
+
if (object === null) {
|
|
375
|
+
return {};
|
|
376
|
+
}
|
|
377
|
+
const clone = Object.assign({}, object);
|
|
378
|
+
Object.keys(clone).forEach((key) => {
|
|
379
|
+
if (typeof object[key] === "object" && !ArrayBuffer.isView(object[key]) && !(object[key] instanceof Array)) {
|
|
380
|
+
clone[key] = getTransferListForWriter(object[key]);
|
|
381
|
+
} else if (typeof clone[key] === "function" || clone[key] instanceof RegExp) {
|
|
382
|
+
clone[key] = {};
|
|
383
|
+
} else {
|
|
384
|
+
clone[key] = object[key];
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
return clone;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// ../worker-utils/src/lib/worker-farm/worker-thread.ts
|
|
391
|
+
var NOOP = () => {
|
|
392
|
+
};
|
|
393
|
+
var WorkerThread = class {
|
|
394
|
+
name;
|
|
395
|
+
source;
|
|
396
|
+
url;
|
|
397
|
+
terminated = false;
|
|
398
|
+
worker;
|
|
399
|
+
onMessage;
|
|
400
|
+
onError;
|
|
401
|
+
_loadableURL = "";
|
|
402
|
+
/** Checks if workers are supported on this platform */
|
|
403
|
+
static isSupported() {
|
|
404
|
+
return typeof Worker !== "undefined" && isBrowser2 || typeof NodeWorker !== "undefined" && !isBrowser2;
|
|
405
|
+
}
|
|
406
|
+
constructor(props) {
|
|
407
|
+
const { name, source, url } = props;
|
|
408
|
+
assert2(source || url);
|
|
409
|
+
this.name = name;
|
|
410
|
+
this.source = source;
|
|
411
|
+
this.url = url;
|
|
412
|
+
this.onMessage = NOOP;
|
|
413
|
+
this.onError = (error) => console.log(error);
|
|
414
|
+
this.worker = isBrowser2 ? this._createBrowserWorker() : this._createNodeWorker();
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Terminate this worker thread
|
|
418
|
+
* @note Can free up significant memory
|
|
419
|
+
*/
|
|
420
|
+
destroy() {
|
|
421
|
+
this.onMessage = NOOP;
|
|
422
|
+
this.onError = NOOP;
|
|
423
|
+
this.worker.terminate();
|
|
424
|
+
this.terminated = true;
|
|
425
|
+
}
|
|
426
|
+
/** Keeps this worker from preventing Node.js process exit while idle. */
|
|
427
|
+
unref() {
|
|
428
|
+
if (!isBrowser2 && typeof this.worker.unref === "function") {
|
|
429
|
+
this.worker.unref();
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
/** Keeps this worker alive while it is actively processing a job. */
|
|
433
|
+
ref() {
|
|
434
|
+
if (!isBrowser2 && typeof this.worker.ref === "function") {
|
|
435
|
+
this.worker.ref();
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
get isRunning() {
|
|
439
|
+
return Boolean(this.onMessage);
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Send a message to this worker thread
|
|
443
|
+
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
444
|
+
* @param transferList If not supplied, calculated automatically by traversing data
|
|
445
|
+
*/
|
|
446
|
+
postMessage(data, transferList) {
|
|
447
|
+
transferList = transferList || getTransferList(data);
|
|
448
|
+
this.worker.postMessage(data, transferList);
|
|
449
|
+
}
|
|
450
|
+
// PRIVATE
|
|
451
|
+
/**
|
|
452
|
+
* Generate a standard Error from an ErrorEvent
|
|
453
|
+
* @param event
|
|
454
|
+
*/
|
|
455
|
+
_getErrorFromErrorEvent(event) {
|
|
456
|
+
let message = "Failed to load ";
|
|
457
|
+
message += `worker ${this.name} from ${this.url}. `;
|
|
458
|
+
if (event.message) {
|
|
459
|
+
message += `${event.message} in `;
|
|
460
|
+
}
|
|
461
|
+
if (event.lineno) {
|
|
462
|
+
message += `:${event.lineno}:${event.colno}`;
|
|
463
|
+
}
|
|
464
|
+
return new Error(message);
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Creates a worker thread on the browser
|
|
468
|
+
*/
|
|
469
|
+
_createBrowserWorker() {
|
|
470
|
+
this._loadableURL = getLoadableWorkerURL({ source: this.source, url: this.url });
|
|
471
|
+
const worker = new Worker(this._loadableURL, { name: this.name });
|
|
472
|
+
worker.onmessage = (event) => {
|
|
473
|
+
if (!event.data) {
|
|
474
|
+
this.onError(new Error("No data received"));
|
|
475
|
+
} else {
|
|
476
|
+
this.onMessage(event.data);
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
worker.onerror = (error) => {
|
|
480
|
+
this.onError(this._getErrorFromErrorEvent(error));
|
|
481
|
+
this.terminated = true;
|
|
482
|
+
};
|
|
483
|
+
worker.onmessageerror = (event) => console.error(event);
|
|
484
|
+
return worker;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Creates a worker thread in node.js
|
|
488
|
+
* @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool
|
|
489
|
+
*/
|
|
490
|
+
_createNodeWorker() {
|
|
491
|
+
let worker;
|
|
492
|
+
if (this.url) {
|
|
493
|
+
const absolute = this.url.includes(":/") || this.url.startsWith("/");
|
|
494
|
+
const url = absolute ? this.url : `./${this.url}`;
|
|
495
|
+
const workerUrl = url.startsWith("file:") ? new URL(url) : url;
|
|
496
|
+
const type = this.url.endsWith(".ts") || this.url.endsWith(".mjs") ? "module" : "commonjs";
|
|
497
|
+
worker = new NodeWorker(workerUrl, { eval: false, type });
|
|
498
|
+
} else if (this.source) {
|
|
499
|
+
worker = new NodeWorker(this.source, { eval: true });
|
|
500
|
+
} else {
|
|
501
|
+
throw new Error("no worker");
|
|
502
|
+
}
|
|
503
|
+
worker.on("message", (data) => {
|
|
504
|
+
this.onMessage(data);
|
|
505
|
+
});
|
|
506
|
+
worker.on("error", (error) => {
|
|
507
|
+
this.onError(error);
|
|
508
|
+
});
|
|
509
|
+
worker.on("exit", (_code) => {
|
|
510
|
+
});
|
|
511
|
+
return worker;
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
// ../worker-utils/src/lib/worker-farm/worker-pool.ts
|
|
516
|
+
var WorkerPool = class {
|
|
517
|
+
name = "unnamed";
|
|
518
|
+
source;
|
|
519
|
+
// | Function;
|
|
520
|
+
url;
|
|
521
|
+
maxConcurrency = 1;
|
|
522
|
+
maxMobileConcurrency = 1;
|
|
523
|
+
onDebug = () => {
|
|
524
|
+
};
|
|
525
|
+
reuseWorkers = true;
|
|
526
|
+
props = {};
|
|
527
|
+
jobQueue = [];
|
|
528
|
+
idleQueue = [];
|
|
529
|
+
count = 0;
|
|
530
|
+
isDestroyed = false;
|
|
531
|
+
/** Checks if workers are supported on this platform */
|
|
532
|
+
static isSupported() {
|
|
533
|
+
return WorkerThread.isSupported();
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* @param processor - worker function
|
|
537
|
+
* @param maxConcurrency - max count of workers
|
|
538
|
+
*/
|
|
539
|
+
constructor(props) {
|
|
540
|
+
this.source = props.source;
|
|
541
|
+
this.url = props.url;
|
|
542
|
+
this.setProps(props);
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Terminates all workers in the pool
|
|
546
|
+
* @note Can free up significant memory
|
|
547
|
+
*/
|
|
548
|
+
destroy() {
|
|
549
|
+
this.idleQueue.forEach((worker) => worker.destroy());
|
|
550
|
+
this.isDestroyed = true;
|
|
551
|
+
}
|
|
552
|
+
setProps(props) {
|
|
553
|
+
this.props = { ...this.props, ...props };
|
|
554
|
+
if (props.name !== void 0) {
|
|
555
|
+
this.name = props.name;
|
|
556
|
+
}
|
|
557
|
+
if (props.maxConcurrency !== void 0) {
|
|
558
|
+
this.maxConcurrency = props.maxConcurrency;
|
|
559
|
+
}
|
|
560
|
+
if (props.maxMobileConcurrency !== void 0) {
|
|
561
|
+
this.maxMobileConcurrency = props.maxMobileConcurrency;
|
|
562
|
+
}
|
|
563
|
+
if (props.reuseWorkers !== void 0) {
|
|
564
|
+
this.reuseWorkers = props.reuseWorkers;
|
|
565
|
+
}
|
|
566
|
+
if (props.onDebug !== void 0) {
|
|
567
|
+
this.onDebug = props.onDebug;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
async startJob(name, onMessage2 = (job, type, data) => job.done(data), onError = (job, error) => job.error(error)) {
|
|
571
|
+
const startPromise = new Promise((onStart) => {
|
|
572
|
+
this.jobQueue.push({ name, onMessage: onMessage2, onError, onStart });
|
|
573
|
+
return this;
|
|
574
|
+
});
|
|
575
|
+
this._startQueuedJob();
|
|
576
|
+
return await startPromise;
|
|
577
|
+
}
|
|
578
|
+
// PRIVATE
|
|
579
|
+
/**
|
|
580
|
+
* Starts first queued job if worker is available or can be created
|
|
581
|
+
* Called when job is started and whenever a worker returns to the idleQueue
|
|
582
|
+
*/
|
|
583
|
+
async _startQueuedJob() {
|
|
584
|
+
if (!this.jobQueue.length) {
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
const workerThread = this._getAvailableWorker();
|
|
588
|
+
if (!workerThread) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
const queuedJob = this.jobQueue.shift();
|
|
592
|
+
if (queuedJob) {
|
|
593
|
+
this.onDebug({
|
|
594
|
+
message: "Starting job",
|
|
595
|
+
name: queuedJob.name,
|
|
596
|
+
workerThread,
|
|
597
|
+
backlog: this.jobQueue.length
|
|
598
|
+
});
|
|
599
|
+
const job = new WorkerJob(queuedJob.name, workerThread);
|
|
600
|
+
workerThread.ref();
|
|
601
|
+
workerThread.onMessage = (data) => queuedJob.onMessage(job, data.type, data.payload);
|
|
602
|
+
workerThread.onError = (error) => queuedJob.onError(job, error);
|
|
603
|
+
queuedJob.onStart(job);
|
|
604
|
+
try {
|
|
605
|
+
await job.result;
|
|
606
|
+
} catch {
|
|
607
|
+
} finally {
|
|
608
|
+
this.returnWorkerToQueue(workerThread);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Returns a worker to the idle queue
|
|
614
|
+
* Destroys the worker if
|
|
615
|
+
* - pool is destroyed
|
|
616
|
+
* - if this pool doesn't reuse workers
|
|
617
|
+
* - if maxConcurrency has been lowered
|
|
618
|
+
* @param worker
|
|
619
|
+
*/
|
|
620
|
+
returnWorkerToQueue(worker) {
|
|
621
|
+
const shouldDestroyWorker = (
|
|
622
|
+
// Aborted jobs terminate their worker immediately.
|
|
623
|
+
worker.terminated || // If the pool is destroyed, there is no reason to keep the worker around
|
|
624
|
+
this.isDestroyed || // If the app has disabled worker reuse, any completed workers should be destroyed
|
|
625
|
+
!this.reuseWorkers || // If concurrency has been lowered, this worker might be surplus to requirements
|
|
626
|
+
this.count > this._getMaxConcurrency()
|
|
627
|
+
);
|
|
628
|
+
if (shouldDestroyWorker) {
|
|
629
|
+
if (!worker.terminated) {
|
|
630
|
+
worker.destroy();
|
|
631
|
+
}
|
|
632
|
+
this.count--;
|
|
633
|
+
} else {
|
|
634
|
+
worker.unref();
|
|
635
|
+
this.idleQueue.push(worker);
|
|
636
|
+
}
|
|
637
|
+
if (!this.isDestroyed) {
|
|
638
|
+
this._startQueuedJob();
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Returns idle worker or creates new worker if maxConcurrency has not been reached
|
|
643
|
+
*/
|
|
644
|
+
_getAvailableWorker() {
|
|
645
|
+
if (this.idleQueue.length > 0) {
|
|
646
|
+
return this.idleQueue.shift() || null;
|
|
647
|
+
}
|
|
648
|
+
if (this.count < this._getMaxConcurrency()) {
|
|
649
|
+
this.count++;
|
|
650
|
+
const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;
|
|
651
|
+
return new WorkerThread({ name, source: this.source, url: this.url });
|
|
652
|
+
}
|
|
653
|
+
return null;
|
|
654
|
+
}
|
|
655
|
+
_getMaxConcurrency() {
|
|
656
|
+
return isMobile ? this.maxMobileConcurrency : this.maxConcurrency;
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
|
|
660
|
+
// ../worker-utils/src/lib/worker-farm/worker-farm.ts
|
|
661
|
+
var DEFAULT_PROPS = {
|
|
662
|
+
maxConcurrency: 3,
|
|
663
|
+
maxMobileConcurrency: 1,
|
|
664
|
+
reuseWorkers: true,
|
|
665
|
+
onDebug: () => {
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
var WorkerFarm = class _WorkerFarm {
|
|
669
|
+
props;
|
|
670
|
+
workerPools = /* @__PURE__ */ new Map();
|
|
671
|
+
// singleton
|
|
672
|
+
static _workerFarm;
|
|
673
|
+
/** Checks if workers are supported on this platform */
|
|
674
|
+
static isSupported() {
|
|
675
|
+
return WorkerThread.isSupported();
|
|
676
|
+
}
|
|
677
|
+
/** Get the singleton instance of the global worker farm */
|
|
678
|
+
static getWorkerFarm(props = {}) {
|
|
679
|
+
_WorkerFarm._workerFarm = _WorkerFarm._workerFarm || new _WorkerFarm({});
|
|
680
|
+
_WorkerFarm._workerFarm.setProps(props);
|
|
681
|
+
return _WorkerFarm._workerFarm;
|
|
682
|
+
}
|
|
683
|
+
/** get global instance with WorkerFarm.getWorkerFarm() */
|
|
684
|
+
constructor(props) {
|
|
685
|
+
this.props = { ...DEFAULT_PROPS };
|
|
686
|
+
this.setProps(props);
|
|
687
|
+
this.workerPools = /* @__PURE__ */ new Map();
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Terminate all workers in the farm
|
|
691
|
+
* @note Can free up significant memory
|
|
692
|
+
*/
|
|
693
|
+
destroy() {
|
|
694
|
+
for (const workerPool of this.workerPools.values()) {
|
|
695
|
+
workerPool.destroy();
|
|
696
|
+
}
|
|
697
|
+
this.workerPools = /* @__PURE__ */ new Map();
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Set props used when initializing worker pools
|
|
701
|
+
* @param props
|
|
702
|
+
*/
|
|
703
|
+
setProps(props) {
|
|
704
|
+
this.props = { ...this.props, ...props };
|
|
705
|
+
for (const workerPool of this.workerPools.values()) {
|
|
706
|
+
workerPool.setProps(this._getWorkerPoolProps());
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Returns a worker pool for the specified worker
|
|
711
|
+
* @param options - only used first time for a specific worker name
|
|
712
|
+
* @param options.name - the name of the worker - used to identify worker pool
|
|
713
|
+
* @param options.url -
|
|
714
|
+
* @param options.source -
|
|
715
|
+
* @example
|
|
716
|
+
* const job = WorkerFarm.getWorkerFarm().getWorkerPool({name, url}).startJob(...);
|
|
717
|
+
*/
|
|
718
|
+
getWorkerPool(options) {
|
|
719
|
+
const { name, source, url } = options;
|
|
720
|
+
let workerPool = this.workerPools.get(name);
|
|
721
|
+
if (!workerPool) {
|
|
722
|
+
workerPool = new WorkerPool({
|
|
723
|
+
name,
|
|
724
|
+
source,
|
|
725
|
+
url
|
|
726
|
+
});
|
|
727
|
+
workerPool.setProps(this._getWorkerPoolProps());
|
|
728
|
+
this.workerPools.set(name, workerPool);
|
|
729
|
+
}
|
|
730
|
+
return workerPool;
|
|
731
|
+
}
|
|
732
|
+
_getWorkerPoolProps() {
|
|
733
|
+
return {
|
|
734
|
+
maxConcurrency: this.props.maxConcurrency,
|
|
735
|
+
maxMobileConcurrency: this.props.maxMobileConcurrency,
|
|
736
|
+
reuseWorkers: this.props.reuseWorkers,
|
|
737
|
+
onDebug: this.props.onDebug
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
// ../worker-utils/src/lib/worker-api/get-worker-url.ts
|
|
743
|
+
var warnedWorkerVersionFallbacks = /* @__PURE__ */ new Set();
|
|
744
|
+
function getWorkerName(worker) {
|
|
745
|
+
const warning = worker.version !== VERSION2 ? ` (worker-utils@${VERSION2})` : "";
|
|
746
|
+
return `${worker.name}@${worker.version}${warning}`;
|
|
747
|
+
}
|
|
748
|
+
function getWorkerURL(worker, options = {}) {
|
|
749
|
+
var _a;
|
|
750
|
+
const workerOptions = options[worker.id] || {};
|
|
751
|
+
const workerFile = isBrowser2 ? `${worker.id}-worker.js` : `${worker.id}-worker-node.js`;
|
|
752
|
+
let url = workerOptions.workerUrl;
|
|
753
|
+
if (!url && typeof worker.worker === "string") {
|
|
754
|
+
url = worker.worker;
|
|
755
|
+
}
|
|
756
|
+
if (!url && worker.id === "compression") {
|
|
757
|
+
url = options.workerUrl;
|
|
758
|
+
}
|
|
759
|
+
const workerType = options._workerType || ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a._workerType);
|
|
760
|
+
if (workerType === "test") {
|
|
761
|
+
if (isBrowser2) {
|
|
762
|
+
url = `modules/${worker.module}/dist/${workerFile}`;
|
|
763
|
+
} else {
|
|
764
|
+
url = `modules/${worker.module}/src/workers/${worker.id}-worker-node.ts`;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
if (!url) {
|
|
768
|
+
let version2 = worker.version;
|
|
769
|
+
if (version2 === "latest") {
|
|
770
|
+
version2 = NPM_TAG;
|
|
771
|
+
}
|
|
772
|
+
const versionTag = version2 ? `@${version2}` : "";
|
|
773
|
+
url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;
|
|
774
|
+
warnIfUsingNpmTagFallback(worker, url);
|
|
775
|
+
}
|
|
776
|
+
assert2(url);
|
|
777
|
+
return url;
|
|
778
|
+
}
|
|
779
|
+
function warnIfUsingNpmTagFallback(worker, url) {
|
|
780
|
+
if (worker.version !== "latest") {
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
const workerId = `${worker.module}:${worker.id}`;
|
|
784
|
+
if (warnedWorkerVersionFallbacks.has(workerId)) {
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
warnedWorkerVersionFallbacks.add(workerId);
|
|
788
|
+
console.warn(
|
|
789
|
+
`loaders.gl: ${worker.name} loader worker version is "latest" because __VERSION__ was not injected. Fetching ${url} from CDN.`
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
// ../worker-utils/src/lib/worker-api/process-on-worker.ts
|
|
794
|
+
function canProcessOnWorker(worker, options) {
|
|
795
|
+
if (!WorkerFarm.isSupported()) {
|
|
796
|
+
return false;
|
|
797
|
+
}
|
|
798
|
+
const workerOptions = options == null ? void 0 : options[worker.id];
|
|
799
|
+
return Boolean((worker.worker || (workerOptions == null ? void 0 : workerOptions.workerUrl)) && (options == null ? void 0 : options.worker));
|
|
800
|
+
}
|
|
801
|
+
async function processOnWorker(worker, data, options = {}, context = {}, jobContext = {}) {
|
|
802
|
+
var _a, _b, _c;
|
|
803
|
+
throwIfAborted(options.signal);
|
|
804
|
+
const name = getWorkerName(worker);
|
|
805
|
+
const workerFarm = WorkerFarm.getWorkerFarm(options);
|
|
806
|
+
const { source } = options;
|
|
807
|
+
const workerPoolProps = { name, source };
|
|
808
|
+
if (!source) {
|
|
809
|
+
workerPoolProps.url = getWorkerURL(worker, options);
|
|
810
|
+
}
|
|
811
|
+
const workerPool = workerFarm.getWorkerPool(workerPoolProps);
|
|
812
|
+
const jobName = options.jobName || worker.name;
|
|
813
|
+
const job = await workerPool.startJob(
|
|
814
|
+
jobName,
|
|
815
|
+
// eslint-disable-next-line
|
|
816
|
+
onMessage.bind(null, context)
|
|
817
|
+
);
|
|
818
|
+
const abortJob = () => job.abort();
|
|
819
|
+
(_a = options.signal) == null ? void 0 : _a.addEventListener("abort", abortJob, { once: true });
|
|
820
|
+
if ((_b = options.signal) == null ? void 0 : _b.aborted) {
|
|
821
|
+
abortJob();
|
|
822
|
+
}
|
|
823
|
+
try {
|
|
824
|
+
const { signal: _signal, ...workerOptions } = options;
|
|
825
|
+
const transferableOptions = getTransferListForWriter(workerOptions);
|
|
826
|
+
const transferableContext = getTransferListForWriter(jobContext);
|
|
827
|
+
if (job.isRunning) {
|
|
828
|
+
job.postMessage("process", {
|
|
829
|
+
input: data,
|
|
830
|
+
options: transferableOptions,
|
|
831
|
+
context: transferableContext
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
const result = await job.result;
|
|
835
|
+
return result.result;
|
|
836
|
+
} finally {
|
|
837
|
+
(_c = options.signal) == null ? void 0 : _c.removeEventListener("abort", abortJob);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
function throwIfAborted(signal) {
|
|
841
|
+
if (!(signal == null ? void 0 : signal.aborted)) {
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
const error = new Error("Worker job was aborted");
|
|
845
|
+
error.name = "AbortError";
|
|
846
|
+
throw error;
|
|
847
|
+
}
|
|
848
|
+
async function onMessage(context, job, type, payload) {
|
|
849
|
+
switch (type) {
|
|
850
|
+
case "done":
|
|
851
|
+
job.done(payload);
|
|
852
|
+
break;
|
|
853
|
+
case "error":
|
|
854
|
+
job.error(new Error(payload.error));
|
|
855
|
+
break;
|
|
856
|
+
case "process":
|
|
857
|
+
const { id, input, options } = payload;
|
|
858
|
+
try {
|
|
859
|
+
if (!context.process) {
|
|
860
|
+
job.postMessage("error", { id, error: "Worker not set up to process on main thread" });
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
const result = await context.process(input, options, void 0, payload.context || {});
|
|
864
|
+
job.postMessage("done", { id, result });
|
|
865
|
+
} catch (error) {
|
|
866
|
+
const message = error instanceof Error ? error.message : "unknown error";
|
|
867
|
+
job.postMessage("error", { id, error: message });
|
|
868
|
+
}
|
|
869
|
+
break;
|
|
870
|
+
default:
|
|
871
|
+
console.warn(`process-on-worker: unknown message ${type}`);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
// ../worker-utils/src/lib/worker-api/validate-worker-version.ts
|
|
876
|
+
function validateWorkerVersion(worker, coreVersion = VERSION2) {
|
|
877
|
+
assert2(worker, "no worker provided");
|
|
878
|
+
const workerVersion = worker.version;
|
|
879
|
+
if (!coreVersion || !workerVersion) {
|
|
880
|
+
return false;
|
|
881
|
+
}
|
|
882
|
+
return true;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// ../loader-utils/src/lib/worker-loader-utils/parse-with-worker.ts
|
|
886
|
+
function canParseWithWorker(loader, options) {
|
|
887
|
+
var _a, _b;
|
|
888
|
+
const workerOptions = getWorkerOptions(options);
|
|
889
|
+
const nodeWorkers = workerOptions._nodeWorkers;
|
|
890
|
+
if (!isBrowser2 && !nodeWorkers) {
|
|
891
|
+
return false;
|
|
892
|
+
}
|
|
893
|
+
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") {
|
|
894
|
+
return false;
|
|
895
|
+
}
|
|
896
|
+
if (loader.id === "csv" && !shouldParseCSVWithWorker(options)) {
|
|
897
|
+
return false;
|
|
898
|
+
}
|
|
899
|
+
return Boolean(canProcessOnWorker(loader, workerOptions));
|
|
900
|
+
}
|
|
901
|
+
async function parseWithWorker(loader, data, options, context, parseOnMainThread) {
|
|
902
|
+
const signal = getWorkerAbortSignal(options);
|
|
903
|
+
const result = await processOnWorker(
|
|
904
|
+
loader,
|
|
905
|
+
data,
|
|
906
|
+
{ ...getWorkerOptions(options), signal },
|
|
907
|
+
{
|
|
908
|
+
process: async (input, processOptions, _workerContext, parseContext) => {
|
|
909
|
+
if (!parseOnMainThread) {
|
|
910
|
+
throw new Error("Worker not set up to parse on main thread");
|
|
911
|
+
}
|
|
912
|
+
const mainThreadContext = context ? { ...context, ...parseContext || {} } : void 0;
|
|
913
|
+
return await callParseOnMainThread(
|
|
914
|
+
parseOnMainThread,
|
|
915
|
+
input,
|
|
916
|
+
processOptions,
|
|
917
|
+
mainThreadContext
|
|
918
|
+
);
|
|
919
|
+
}
|
|
920
|
+
},
|
|
921
|
+
getSerializableLoaderContext(context)
|
|
922
|
+
);
|
|
923
|
+
return isLoaderWithWorkerResultDeserializer(loader) ? loader.deserializeWorkerResult(result, options, context) : result;
|
|
924
|
+
}
|
|
925
|
+
function getWorkerAbortSignal(options) {
|
|
926
|
+
var _a;
|
|
927
|
+
const parquetSignal = (_a = options == null ? void 0 : options.parquet) == null ? void 0 : _a.signal;
|
|
928
|
+
if (typeof AbortSignal !== "undefined" && parquetSignal instanceof AbortSignal) {
|
|
929
|
+
return parquetSignal;
|
|
930
|
+
}
|
|
931
|
+
return void 0;
|
|
932
|
+
}
|
|
933
|
+
function callParseOnMainThread(parseOnMainThread, input, options, context) {
|
|
934
|
+
if (parseOnMainThread.length <= 2) {
|
|
935
|
+
return parseOnMainThread(input, options);
|
|
936
|
+
}
|
|
937
|
+
return parseOnMainThread(input, void 0, options, context);
|
|
938
|
+
}
|
|
939
|
+
function getWorkerOptions(options = {}) {
|
|
940
|
+
const serializedOptions = JSON.parse(JSON.stringify(options));
|
|
941
|
+
return {
|
|
942
|
+
...serializedOptions.core,
|
|
943
|
+
...serializedOptions
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
function getSerializableLoaderContext(context) {
|
|
947
|
+
if (!context) {
|
|
948
|
+
return {};
|
|
949
|
+
}
|
|
950
|
+
const { fetch: fetch2, loaders, coreApi: coreApi2, _parse, _parseSync, _parseInBatches, ...serializableContext } = context;
|
|
951
|
+
return JSON.parse(JSON.stringify(serializableContext));
|
|
952
|
+
}
|
|
953
|
+
function shouldParseCSVWithWorker(options) {
|
|
954
|
+
var _a, _b;
|
|
955
|
+
const csvOptions = options;
|
|
956
|
+
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";
|
|
957
|
+
}
|
|
958
|
+
function isLoaderWithWorkerResultDeserializer(loader) {
|
|
959
|
+
return typeof loader.deserializeWorkerResult === "function";
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
// ../loader-utils/src/lib/worker-loader-utils/encode-with-worker.ts
|
|
963
|
+
function canEncodeWithWorker(writer, options) {
|
|
964
|
+
var _a, _b;
|
|
965
|
+
if (!WorkerFarm.isSupported()) {
|
|
966
|
+
return false;
|
|
967
|
+
}
|
|
968
|
+
const nodeWorkers = (options == null ? void 0 : options._nodeWorkers) ?? ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a._nodeWorkers);
|
|
969
|
+
const useWorkers = (options == null ? void 0 : options.worker) ?? ((_b = options == null ? void 0 : options.core) == null ? void 0 : _b.worker);
|
|
970
|
+
if (!isBrowser && !nodeWorkers) {
|
|
971
|
+
return false;
|
|
972
|
+
}
|
|
973
|
+
return Boolean(writer.worker && useWorkers);
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
// ../loader-utils/src/lib/binary-utils/array-buffer-utils.ts
|
|
977
|
+
function compareArrayBuffers(arrayBuffer1, arrayBuffer2, byteLength) {
|
|
978
|
+
byteLength = byteLength || arrayBuffer1.byteLength;
|
|
979
|
+
if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) {
|
|
980
|
+
return false;
|
|
981
|
+
}
|
|
982
|
+
const array1 = new Uint8Array(arrayBuffer1);
|
|
983
|
+
const array2 = new Uint8Array(arrayBuffer2);
|
|
984
|
+
for (let i = 0; i < array1.length; ++i) {
|
|
985
|
+
if (array1[i] !== array2[i]) {
|
|
986
|
+
return false;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
return true;
|
|
990
|
+
}
|
|
991
|
+
function concatenateArrayBuffers(...sources) {
|
|
992
|
+
return concatenateArrayBuffersFromArray(sources);
|
|
993
|
+
}
|
|
994
|
+
function concatenateArrayBuffersFromArray(sources) {
|
|
995
|
+
const sourceArrays = sources.map(
|
|
996
|
+
(source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
|
|
997
|
+
);
|
|
998
|
+
const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
|
|
999
|
+
const result = new Uint8Array(byteLength);
|
|
1000
|
+
let offset = 0;
|
|
1001
|
+
for (const sourceArray of sourceArrays) {
|
|
1002
|
+
result.set(sourceArray, offset);
|
|
1003
|
+
offset += sourceArray.byteLength;
|
|
1004
|
+
}
|
|
1005
|
+
return result.buffer;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
// ../loader-utils/src/lib/iterators/text-iterators.ts
|
|
1009
|
+
async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
|
|
1010
|
+
const textDecoder = new TextDecoder(void 0, options);
|
|
1011
|
+
for await (const arrayBuffer of arrayBufferIterator) {
|
|
1012
|
+
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, { stream: true });
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
async function* makeTextEncoderIterator(textIterator) {
|
|
1016
|
+
const textEncoder = new TextEncoder();
|
|
1017
|
+
for await (const text of textIterator) {
|
|
1018
|
+
yield typeof text === "string" ? textEncoder.encode(text).buffer : text;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
async function* makeLineIterator(textIterator) {
|
|
1022
|
+
let previous = "";
|
|
1023
|
+
for await (const textChunk of textIterator) {
|
|
1024
|
+
previous += textChunk;
|
|
1025
|
+
let eolIndex;
|
|
1026
|
+
eolIndex = previous.indexOf("\n");
|
|
1027
|
+
while (eolIndex >= 0) {
|
|
1028
|
+
const line = previous.slice(0, eolIndex + 1);
|
|
1029
|
+
previous = previous.slice(eolIndex + 1);
|
|
1030
|
+
yield line;
|
|
1031
|
+
eolIndex = previous.indexOf("\n");
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
if (previous.length > 0) {
|
|
1035
|
+
yield previous;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
async function* makeNumberedLineIterator(lineIterator) {
|
|
1039
|
+
let counter = 1;
|
|
1040
|
+
for await (const line of lineIterator) {
|
|
1041
|
+
yield { counter, line };
|
|
1042
|
+
counter++;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
// ../loader-utils/src/lib/iterators/async-iteration.ts
|
|
1047
|
+
async function forEach(iterable, visitor) {
|
|
1048
|
+
const iterator = toAsyncIterator(iterable);
|
|
1049
|
+
while (true) {
|
|
1050
|
+
const { done, value } = await iterator.next();
|
|
1051
|
+
if (done) {
|
|
1052
|
+
if (iterator.return) {
|
|
1053
|
+
iterator.return();
|
|
1054
|
+
}
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
const cancel = visitor(value);
|
|
1058
|
+
if (cancel) {
|
|
1059
|
+
return;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
async function concatenateArrayBuffersAsync(asyncIterator) {
|
|
1064
|
+
const arrayBuffers = [];
|
|
1065
|
+
for await (const chunk of asyncIterator) {
|
|
1066
|
+
arrayBuffers.push(copyToArrayBuffer(chunk));
|
|
1067
|
+
}
|
|
1068
|
+
return concatenateArrayBuffers(...arrayBuffers);
|
|
1069
|
+
}
|
|
1070
|
+
function copyToArrayBuffer(chunk) {
|
|
1071
|
+
if (chunk instanceof ArrayBuffer) {
|
|
1072
|
+
return chunk;
|
|
1073
|
+
}
|
|
1074
|
+
if (ArrayBuffer.isView(chunk)) {
|
|
1075
|
+
const { buffer, byteOffset, byteLength } = chunk;
|
|
1076
|
+
return copyFromBuffer(buffer, byteOffset, byteLength);
|
|
1077
|
+
}
|
|
1078
|
+
return copyFromBuffer(chunk);
|
|
1079
|
+
}
|
|
1080
|
+
function copyFromBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
|
|
1081
|
+
const view = new Uint8Array(buffer, byteOffset, byteLength);
|
|
1082
|
+
const copy = new Uint8Array(view.length);
|
|
1083
|
+
copy.set(view);
|
|
1084
|
+
return copy.buffer;
|
|
1085
|
+
}
|
|
1086
|
+
function toAsyncIterator(iterable) {
|
|
1087
|
+
if (typeof iterable[Symbol.asyncIterator] === "function") {
|
|
1088
|
+
return iterable[Symbol.asyncIterator]();
|
|
1089
|
+
}
|
|
1090
|
+
if (typeof iterable[Symbol.iterator] === "function") {
|
|
1091
|
+
const iterator = iterable[Symbol.iterator]();
|
|
1092
|
+
return iteratorToAsyncIterator(iterator);
|
|
1093
|
+
}
|
|
1094
|
+
return iterable;
|
|
1095
|
+
}
|
|
1096
|
+
function iteratorToAsyncIterator(iterator) {
|
|
1097
|
+
return {
|
|
1098
|
+
next(value) {
|
|
1099
|
+
return Promise.resolve(iterator.next(value));
|
|
1100
|
+
},
|
|
1101
|
+
return(value) {
|
|
1102
|
+
if (typeof iterator.return === "function") {
|
|
1103
|
+
return Promise.resolve(iterator.return(value));
|
|
1104
|
+
}
|
|
1105
|
+
return Promise.resolve({ done: true, value });
|
|
1106
|
+
},
|
|
1107
|
+
throw(error) {
|
|
1108
|
+
if (typeof iterator.throw === "function") {
|
|
1109
|
+
return Promise.resolve(iterator.throw(error));
|
|
1110
|
+
}
|
|
1111
|
+
return Promise.reject(error);
|
|
1112
|
+
}
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
// ../loader-utils/src/lib/request-utils/request-scheduler.ts
|
|
1117
|
+
var import_stats = require("@probe.gl/stats");
|
|
1118
|
+
var STAT_QUEUED_REQUESTS = "Queued Requests";
|
|
1119
|
+
var STAT_ACTIVE_REQUESTS = "Active Requests";
|
|
1120
|
+
var STAT_CANCELLED_REQUESTS = "Cancelled Requests";
|
|
1121
|
+
var STAT_QUEUED_REQUESTS_EVER = "Queued Requests Ever";
|
|
1122
|
+
var STAT_ACTIVE_REQUESTS_EVER = "Active Requests Ever";
|
|
1123
|
+
var DEFAULT_PROPS2 = {
|
|
1124
|
+
id: "request-scheduler",
|
|
1125
|
+
/** Specifies if the request scheduler should throttle incoming requests, mainly for comparative testing. */
|
|
1126
|
+
throttleRequests: true,
|
|
1127
|
+
/** The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit. */
|
|
1128
|
+
maxRequests: 6,
|
|
1129
|
+
/**
|
|
1130
|
+
* Specifies a debounce time, in milliseconds. All requests are queued, until no new requests have
|
|
1131
|
+
* been added to the queue for this amount of time.
|
|
1132
|
+
*/
|
|
1133
|
+
debounceTime: 0
|
|
1134
|
+
};
|
|
1135
|
+
var RequestScheduler = class {
|
|
1136
|
+
props;
|
|
1137
|
+
stats;
|
|
1138
|
+
activeRequestCount = 0;
|
|
1139
|
+
/** Tracks the number of active requests and prioritizes/cancels queued requests. */
|
|
1140
|
+
requestQueue = [];
|
|
1141
|
+
requestMap = /* @__PURE__ */ new Map();
|
|
1142
|
+
updateTimer = null;
|
|
1143
|
+
constructor(props = {}) {
|
|
1144
|
+
this.props = { ...DEFAULT_PROPS2, ...props };
|
|
1145
|
+
this.stats = new import_stats.Stats({ id: this.props.id });
|
|
1146
|
+
this.stats.get(STAT_QUEUED_REQUESTS);
|
|
1147
|
+
this.stats.get(STAT_ACTIVE_REQUESTS);
|
|
1148
|
+
this.stats.get(STAT_CANCELLED_REQUESTS);
|
|
1149
|
+
this.stats.get(STAT_QUEUED_REQUESTS_EVER);
|
|
1150
|
+
this.stats.get(STAT_ACTIVE_REQUESTS_EVER);
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* Update scheduler props. Preserves active and queued requests.
|
|
1154
|
+
*/
|
|
1155
|
+
setProps(props) {
|
|
1156
|
+
if (props.throttleRequests !== void 0) {
|
|
1157
|
+
this.props.throttleRequests = props.throttleRequests;
|
|
1158
|
+
}
|
|
1159
|
+
if (props.maxRequests !== void 0) {
|
|
1160
|
+
this.props.maxRequests = props.maxRequests;
|
|
1161
|
+
}
|
|
1162
|
+
if (props.debounceTime !== void 0) {
|
|
1163
|
+
this.props.debounceTime = props.debounceTime;
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Called by an application that wants to issue a request, without having it deeply queued by the browser
|
|
1168
|
+
*
|
|
1169
|
+
* When the returned promise resolved, it is OK for the application to issue a request.
|
|
1170
|
+
* The promise resolves to an object that contains a `done` method.
|
|
1171
|
+
* When the application's request has completed (or failed), the application must call the `done` function
|
|
1172
|
+
*
|
|
1173
|
+
* @param handle
|
|
1174
|
+
* @param getPriority will be called when request "slots" open up,
|
|
1175
|
+
* allowing the caller to update priority or cancel the request
|
|
1176
|
+
* Highest priority executes first, priority < 0 cancels the request
|
|
1177
|
+
* @returns a promise
|
|
1178
|
+
* - resolves to a object (with a `done` field) when the request can be issued without queueing,
|
|
1179
|
+
* - resolves to `null` if the request has been cancelled (by the callback return < 0).
|
|
1180
|
+
* In this case the application should not issue the request
|
|
1181
|
+
*/
|
|
1182
|
+
scheduleRequest(handle, getPriority = () => 0) {
|
|
1183
|
+
if (!this.props.throttleRequests) {
|
|
1184
|
+
return Promise.resolve({ done: () => {
|
|
1185
|
+
} });
|
|
1186
|
+
}
|
|
1187
|
+
if (this.requestMap.has(handle)) {
|
|
1188
|
+
return this.requestMap.get(handle);
|
|
1189
|
+
}
|
|
1190
|
+
const request = { handle, priority: 0, getPriority };
|
|
1191
|
+
const promise = new Promise((resolve2) => {
|
|
1192
|
+
request.resolve = resolve2;
|
|
1193
|
+
return request;
|
|
1194
|
+
});
|
|
1195
|
+
this.requestQueue.push(request);
|
|
1196
|
+
this.requestMap.set(handle, promise);
|
|
1197
|
+
this._issueNewRequests();
|
|
1198
|
+
return promise;
|
|
1199
|
+
}
|
|
1200
|
+
// PRIVATE
|
|
1201
|
+
_issueRequest(request) {
|
|
1202
|
+
const { handle, resolve: resolve2 } = request;
|
|
1203
|
+
let isDone = false;
|
|
1204
|
+
const done = () => {
|
|
1205
|
+
if (!isDone) {
|
|
1206
|
+
isDone = true;
|
|
1207
|
+
this.requestMap.delete(handle);
|
|
1208
|
+
this.activeRequestCount--;
|
|
1209
|
+
this._issueNewRequests();
|
|
1210
|
+
}
|
|
1211
|
+
};
|
|
1212
|
+
this.activeRequestCount++;
|
|
1213
|
+
return resolve2 ? resolve2({ done }) : Promise.resolve({ done });
|
|
1214
|
+
}
|
|
1215
|
+
/** We check requests asynchronously, to prevent multiple updates */
|
|
1216
|
+
_issueNewRequests() {
|
|
1217
|
+
if (this.updateTimer !== null) {
|
|
1218
|
+
clearTimeout(this.updateTimer);
|
|
1219
|
+
}
|
|
1220
|
+
this.updateTimer = setTimeout(() => this._issueNewRequestsAsync(), this.props.debounceTime);
|
|
1221
|
+
}
|
|
1222
|
+
/** Refresh all requests */
|
|
1223
|
+
_issueNewRequestsAsync() {
|
|
1224
|
+
if (this.updateTimer !== null) {
|
|
1225
|
+
clearTimeout(this.updateTimer);
|
|
1226
|
+
}
|
|
1227
|
+
this.updateTimer = null;
|
|
1228
|
+
const freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);
|
|
1229
|
+
if (freeSlots === 0) {
|
|
1230
|
+
return;
|
|
1231
|
+
}
|
|
1232
|
+
this._updateAllRequests();
|
|
1233
|
+
for (let i = 0; i < freeSlots; ++i) {
|
|
1234
|
+
const request = this.requestQueue.shift();
|
|
1235
|
+
if (request) {
|
|
1236
|
+
this._issueRequest(request);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
/** Ensure all requests have updated priorities, and that no longer valid requests are cancelled */
|
|
1241
|
+
_updateAllRequests() {
|
|
1242
|
+
const requestQueue = this.requestQueue;
|
|
1243
|
+
for (let i = 0; i < requestQueue.length; ++i) {
|
|
1244
|
+
const request = requestQueue[i];
|
|
1245
|
+
if (!this._updateRequest(request)) {
|
|
1246
|
+
requestQueue.splice(i, 1);
|
|
1247
|
+
this.requestMap.delete(request.handle);
|
|
1248
|
+
i--;
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
requestQueue.sort((a, b) => a.priority - b.priority);
|
|
1252
|
+
}
|
|
1253
|
+
/** Update a single request by calling the callback */
|
|
1254
|
+
_updateRequest(request) {
|
|
1255
|
+
request.priority = request.getPriority(request.handle);
|
|
1256
|
+
if (request.priority < 0) {
|
|
1257
|
+
request.resolve(null);
|
|
1258
|
+
return false;
|
|
1259
|
+
}
|
|
1260
|
+
return true;
|
|
1261
|
+
}
|
|
1262
|
+
};
|
|
1263
|
+
|
|
1264
|
+
// ../loader-utils/src/lib/path-utils/file-aliases.ts
|
|
1265
|
+
var pathPrefix = "";
|
|
1266
|
+
var fileAliases = {};
|
|
1267
|
+
function setPathPrefix(prefix) {
|
|
1268
|
+
pathPrefix = prefix;
|
|
1269
|
+
}
|
|
1270
|
+
function getPathPrefix() {
|
|
1271
|
+
return pathPrefix;
|
|
1272
|
+
}
|
|
1273
|
+
function resolvePath(filename2) {
|
|
1274
|
+
for (const alias in fileAliases) {
|
|
1275
|
+
if (filename2.startsWith(alias)) {
|
|
1276
|
+
const replacement = fileAliases[alias];
|
|
1277
|
+
filename2 = filename2.replace(alias, replacement);
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
if (!filename2.startsWith("http://") && !filename2.startsWith("https://")) {
|
|
1281
|
+
filename2 = `${pathPrefix}${filename2}`;
|
|
1282
|
+
}
|
|
1283
|
+
return filename2;
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
// ../loader-utils/src/lib/path-utils/path.ts
|
|
1287
|
+
var path_exports = {};
|
|
1288
|
+
__export(path_exports, {
|
|
1289
|
+
dirname: () => dirname,
|
|
1290
|
+
filename: () => filename,
|
|
1291
|
+
join: () => join,
|
|
1292
|
+
resolve: () => resolve
|
|
1293
|
+
});
|
|
1294
|
+
|
|
1295
|
+
// ../loader-utils/src/lib/path-utils/get-cwd.ts
|
|
1296
|
+
function getCWD() {
|
|
1297
|
+
var _a;
|
|
1298
|
+
if (typeof process !== "undefined" && typeof process.cwd !== "undefined") {
|
|
1299
|
+
return process.cwd();
|
|
1300
|
+
}
|
|
1301
|
+
const pathname = (_a = window.location) == null ? void 0 : _a.pathname;
|
|
1302
|
+
return (pathname == null ? void 0 : pathname.slice(0, pathname.lastIndexOf("/") + 1)) || "";
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
// ../loader-utils/src/lib/path-utils/path.ts
|
|
1306
|
+
function filename(url) {
|
|
1307
|
+
const slashIndex = url ? url.lastIndexOf("/") : -1;
|
|
1308
|
+
return slashIndex >= 0 ? url.substr(slashIndex + 1) : url;
|
|
1309
|
+
}
|
|
1310
|
+
function dirname(url) {
|
|
1311
|
+
const slashIndex = url ? url.lastIndexOf("/") : -1;
|
|
1312
|
+
return slashIndex >= 0 ? url.substr(0, slashIndex) : "";
|
|
1313
|
+
}
|
|
1314
|
+
function join(...parts) {
|
|
1315
|
+
const separator = "/";
|
|
1316
|
+
parts = parts.map((part, index) => {
|
|
1317
|
+
if (index) {
|
|
1318
|
+
part = part.replace(new RegExp(`^${separator}`), "");
|
|
1319
|
+
}
|
|
1320
|
+
if (index !== parts.length - 1) {
|
|
1321
|
+
part = part.replace(new RegExp(`${separator}$`), "");
|
|
1322
|
+
}
|
|
1323
|
+
return part;
|
|
1324
|
+
});
|
|
1325
|
+
return parts.join(separator);
|
|
1326
|
+
}
|
|
1327
|
+
function resolve(...components) {
|
|
1328
|
+
const paths = [];
|
|
1329
|
+
for (let _i = 0; _i < components.length; _i++) {
|
|
1330
|
+
paths[_i] = components[_i];
|
|
1331
|
+
}
|
|
1332
|
+
let resolvedPath = "";
|
|
1333
|
+
let resolvedAbsolute = false;
|
|
1334
|
+
let cwd;
|
|
1335
|
+
for (let i = paths.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
1336
|
+
let path;
|
|
1337
|
+
if (i >= 0) {
|
|
1338
|
+
path = paths[i];
|
|
1339
|
+
} else {
|
|
1340
|
+
if (cwd === void 0) {
|
|
1341
|
+
cwd = getCWD();
|
|
1342
|
+
}
|
|
1343
|
+
path = cwd;
|
|
1344
|
+
}
|
|
1345
|
+
if (path.length === 0) {
|
|
1346
|
+
continue;
|
|
1347
|
+
}
|
|
1348
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
1349
|
+
resolvedAbsolute = path.charCodeAt(0) === SLASH;
|
|
1350
|
+
}
|
|
1351
|
+
resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
|
|
1352
|
+
if (resolvedAbsolute) {
|
|
1353
|
+
return `/${resolvedPath}`;
|
|
1354
|
+
} else if (resolvedPath.length > 0) {
|
|
1355
|
+
return resolvedPath;
|
|
1356
|
+
}
|
|
1357
|
+
return ".";
|
|
1358
|
+
}
|
|
1359
|
+
var SLASH = 47;
|
|
1360
|
+
var DOT = 46;
|
|
1361
|
+
function normalizeStringPosix(path, allowAboveRoot) {
|
|
1362
|
+
let res = "";
|
|
1363
|
+
let lastSlash = -1;
|
|
1364
|
+
let dots = 0;
|
|
1365
|
+
let code;
|
|
1366
|
+
let isAboveRoot = false;
|
|
1367
|
+
for (let i = 0; i <= path.length; ++i) {
|
|
1368
|
+
if (i < path.length) {
|
|
1369
|
+
code = path.charCodeAt(i);
|
|
1370
|
+
} else if (code === SLASH) {
|
|
1371
|
+
break;
|
|
1372
|
+
} else {
|
|
1373
|
+
code = SLASH;
|
|
1374
|
+
}
|
|
1375
|
+
if (code === SLASH) {
|
|
1376
|
+
if (lastSlash === i - 1 || dots === 1) {
|
|
1377
|
+
} else if (lastSlash !== i - 1 && dots === 2) {
|
|
1378
|
+
if (res.length < 2 || !isAboveRoot || res.charCodeAt(res.length - 1) !== DOT || res.charCodeAt(res.length - 2) !== DOT) {
|
|
1379
|
+
if (res.length > 2) {
|
|
1380
|
+
const start = res.length - 1;
|
|
1381
|
+
let j = start;
|
|
1382
|
+
for (; j >= 0; --j) {
|
|
1383
|
+
if (res.charCodeAt(j) === SLASH) {
|
|
1384
|
+
break;
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
if (j !== start) {
|
|
1388
|
+
res = j === -1 ? "" : res.slice(0, j);
|
|
1389
|
+
lastSlash = i;
|
|
1390
|
+
dots = 0;
|
|
1391
|
+
isAboveRoot = false;
|
|
1392
|
+
continue;
|
|
1393
|
+
}
|
|
1394
|
+
} else if (res.length === 2 || res.length === 1) {
|
|
1395
|
+
res = "";
|
|
1396
|
+
lastSlash = i;
|
|
1397
|
+
dots = 0;
|
|
1398
|
+
isAboveRoot = false;
|
|
1399
|
+
continue;
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
if (allowAboveRoot) {
|
|
1403
|
+
if (res.length > 0) {
|
|
1404
|
+
res += "/..";
|
|
1405
|
+
} else {
|
|
1406
|
+
res = "..";
|
|
1407
|
+
}
|
|
1408
|
+
isAboveRoot = true;
|
|
1409
|
+
}
|
|
1410
|
+
} else {
|
|
1411
|
+
const slice = path.slice(lastSlash + 1, i);
|
|
1412
|
+
if (res.length > 0) {
|
|
1413
|
+
res += `/${slice}`;
|
|
1414
|
+
} else {
|
|
1415
|
+
res = slice;
|
|
1416
|
+
}
|
|
1417
|
+
isAboveRoot = false;
|
|
1418
|
+
}
|
|
1419
|
+
lastSlash = i;
|
|
1420
|
+
dots = 0;
|
|
1421
|
+
} else if (code === DOT && dots !== -1) {
|
|
1422
|
+
++dots;
|
|
1423
|
+
} else {
|
|
1424
|
+
dots = -1;
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
return res;
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
// ../loader-utils/src/json-loader.ts
|
|
1431
|
+
var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1432
|
+
var JSONLoader = {
|
|
1433
|
+
dataType: null,
|
|
1434
|
+
batchType: null,
|
|
1435
|
+
name: "JSON",
|
|
1436
|
+
id: "json",
|
|
1437
|
+
module: "json",
|
|
1438
|
+
version: VERSION3,
|
|
1439
|
+
encoding: "json",
|
|
1440
|
+
format: "json",
|
|
1441
|
+
extensions: ["json", "geojson"],
|
|
1442
|
+
mimeTypes: ["application/json"],
|
|
1443
|
+
category: "json",
|
|
1444
|
+
text: true,
|
|
1445
|
+
parseTextSync,
|
|
1446
|
+
parse: async (arrayBuffer) => parseTextSync(new TextDecoder().decode(arrayBuffer)),
|
|
1447
|
+
options: {}
|
|
1448
|
+
};
|
|
1449
|
+
function parseTextSync(text) {
|
|
1450
|
+
return JSON.parse(text);
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
// ../loader-utils/src/lib/node/buffer.browser.ts
|
|
1454
|
+
function toArrayBuffer(buffer) {
|
|
1455
|
+
return buffer;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
// ../loader-utils/src/lib/binary-utils/memory-conversion-utils.ts
|
|
1459
|
+
function isBuffer(value) {
|
|
1460
|
+
return value && typeof value === "object" && value.isBuffer;
|
|
1461
|
+
}
|
|
1462
|
+
function toArrayBuffer2(data) {
|
|
1463
|
+
if (isBuffer(data)) {
|
|
1464
|
+
return toArrayBuffer(data);
|
|
1465
|
+
}
|
|
1466
|
+
if (data instanceof ArrayBuffer) {
|
|
1467
|
+
return data;
|
|
1468
|
+
}
|
|
1469
|
+
if (isSharedArrayBuffer(data)) {
|
|
1470
|
+
return copyToArrayBuffer2(data);
|
|
1471
|
+
}
|
|
1472
|
+
if (ArrayBuffer.isView(data)) {
|
|
1473
|
+
const buffer = data.buffer;
|
|
1474
|
+
if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
|
|
1475
|
+
return buffer;
|
|
1476
|
+
}
|
|
1477
|
+
return buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
1478
|
+
}
|
|
1479
|
+
if (typeof data === "string") {
|
|
1480
|
+
const text = data;
|
|
1481
|
+
const uint8Array = new TextEncoder().encode(text);
|
|
1482
|
+
return uint8Array.buffer;
|
|
1483
|
+
}
|
|
1484
|
+
if (data && typeof data === "object" && data._toArrayBuffer) {
|
|
1485
|
+
return data._toArrayBuffer();
|
|
1486
|
+
}
|
|
1487
|
+
throw new Error("toArrayBuffer");
|
|
1488
|
+
}
|
|
1489
|
+
function ensureArrayBuffer(bufferSource) {
|
|
1490
|
+
if (bufferSource instanceof ArrayBuffer) {
|
|
1491
|
+
return bufferSource;
|
|
1492
|
+
}
|
|
1493
|
+
if (isSharedArrayBuffer(bufferSource)) {
|
|
1494
|
+
return copyToArrayBuffer2(bufferSource);
|
|
1495
|
+
}
|
|
1496
|
+
const { buffer, byteOffset, byteLength } = bufferSource;
|
|
1497
|
+
if (buffer instanceof ArrayBuffer && byteOffset === 0 && byteLength === buffer.byteLength) {
|
|
1498
|
+
return buffer;
|
|
1499
|
+
}
|
|
1500
|
+
return copyToArrayBuffer2(buffer, byteOffset, byteLength);
|
|
1501
|
+
}
|
|
1502
|
+
function copyToArrayBuffer2(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
|
|
1503
|
+
const view = new Uint8Array(buffer, byteOffset, byteLength);
|
|
1504
|
+
const copy = new Uint8Array(view.length);
|
|
1505
|
+
copy.set(view);
|
|
1506
|
+
return copy.buffer;
|
|
1507
|
+
}
|
|
1508
|
+
function toArrayBufferView(data) {
|
|
1509
|
+
if (ArrayBuffer.isView(data)) {
|
|
1510
|
+
return data;
|
|
1511
|
+
}
|
|
1512
|
+
return new Uint8Array(data);
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
// ../loader-utils/src/lib/files/blob-file.ts
|
|
1516
|
+
var BlobFile = class {
|
|
1517
|
+
handle;
|
|
1518
|
+
size;
|
|
1519
|
+
bigsize;
|
|
1520
|
+
url;
|
|
1521
|
+
constructor(blob) {
|
|
1522
|
+
this.handle = blob instanceof ArrayBuffer ? new Blob([blob]) : blob;
|
|
1523
|
+
this.size = blob instanceof ArrayBuffer ? blob.byteLength : blob.size;
|
|
1524
|
+
this.bigsize = BigInt(this.size);
|
|
1525
|
+
this.url = blob instanceof File ? blob.name : "";
|
|
1526
|
+
}
|
|
1527
|
+
async close() {
|
|
1528
|
+
}
|
|
1529
|
+
async stat() {
|
|
1530
|
+
return {
|
|
1531
|
+
size: this.handle.size,
|
|
1532
|
+
bigsize: BigInt(this.handle.size),
|
|
1533
|
+
isDirectory: false
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1536
|
+
async read(start, length, signal) {
|
|
1537
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
1538
|
+
throw new Error("Request aborted");
|
|
1539
|
+
}
|
|
1540
|
+
const arrayBuffer = await this.handle.slice(Number(start), Number(start) + Number(length)).arrayBuffer();
|
|
1541
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
1542
|
+
throw new Error("Request aborted");
|
|
1543
|
+
}
|
|
1544
|
+
return arrayBuffer;
|
|
1545
|
+
}
|
|
1546
|
+
};
|
|
1547
|
+
|
|
1548
|
+
// ../loader-utils/src/lib/files/node-file-facade.ts
|
|
1549
|
+
var NOT_IMPLEMENTED = new Error("Not implemented");
|
|
1550
|
+
var NodeFileFacade = class {
|
|
1551
|
+
handle;
|
|
1552
|
+
size = 0;
|
|
1553
|
+
bigsize = 0n;
|
|
1554
|
+
url = "";
|
|
1555
|
+
constructor(url, flags, mode) {
|
|
1556
|
+
var _a;
|
|
1557
|
+
if ((_a = globalThis.loaders) == null ? void 0 : _a.NodeFile) {
|
|
1558
|
+
return new globalThis.loaders.NodeFile(url, flags, mode);
|
|
1559
|
+
}
|
|
1560
|
+
if (isBrowser) {
|
|
1561
|
+
throw new Error("Can't instantiate NodeFile in browser.");
|
|
1562
|
+
}
|
|
1563
|
+
throw new Error("Can't instantiate NodeFile. Make sure to import @loaders.gl/polyfills first.");
|
|
1564
|
+
}
|
|
1565
|
+
/** Read data */
|
|
1566
|
+
async read(start, length) {
|
|
1567
|
+
throw NOT_IMPLEMENTED;
|
|
1568
|
+
}
|
|
1569
|
+
/** Write to file. The number of bytes written will be returned */
|
|
1570
|
+
async write(arrayBuffer, offset, length) {
|
|
1571
|
+
throw NOT_IMPLEMENTED;
|
|
1572
|
+
}
|
|
1573
|
+
/** Get information about file */
|
|
1574
|
+
async stat() {
|
|
1575
|
+
throw NOT_IMPLEMENTED;
|
|
1576
|
+
}
|
|
1577
|
+
/** Truncates the file descriptor. Only available on NodeFile. */
|
|
1578
|
+
async truncate(length) {
|
|
1579
|
+
throw NOT_IMPLEMENTED;
|
|
1580
|
+
}
|
|
1581
|
+
/** Append data to a file. Only available on NodeFile. */
|
|
1582
|
+
async append(data) {
|
|
1583
|
+
throw NOT_IMPLEMENTED;
|
|
1584
|
+
}
|
|
1585
|
+
/** Close the file */
|
|
1586
|
+
async close() {
|
|
1587
|
+
}
|
|
1588
|
+
};
|
|
1589
|
+
|
|
1590
|
+
// ../loader-utils/src/source-types.ts
|
|
1591
|
+
function isSourceLoader(loader) {
|
|
1592
|
+
return Boolean(loader && typeof loader === "object" && "createDataSource" in loader);
|
|
1593
|
+
}
|
|
92
1594
|
|
|
93
1595
|
// dist/lib/fetch/fetch-error.js
|
|
94
1596
|
var FetchError = class extends Error {
|
|
@@ -106,9 +1608,6 @@ var FetchError = class extends Error {
|
|
|
106
1608
|
response;
|
|
107
1609
|
};
|
|
108
1610
|
|
|
109
|
-
// dist/lib/utils/resource-utils.js
|
|
110
|
-
var import_loader_utils = require("@loaders.gl/loader-utils");
|
|
111
|
-
|
|
112
1611
|
// dist/lib/utils/mime-type-utils.js
|
|
113
1612
|
var DATA_URL_PATTERN = /^data:([-\w.]+\/[-\w.+]+)(;|,)/;
|
|
114
1613
|
var MIME_TYPE_PATTERN = /^([-\w.]+\/[-\w.+]+)/;
|
|
@@ -119,16 +1618,16 @@ function compareMIMETypes(mimeType1, mimeType2) {
|
|
|
119
1618
|
return false;
|
|
120
1619
|
}
|
|
121
1620
|
function parseMIMEType(mimeString) {
|
|
122
|
-
const
|
|
123
|
-
if (
|
|
124
|
-
return
|
|
1621
|
+
const matches3 = MIME_TYPE_PATTERN.exec(mimeString);
|
|
1622
|
+
if (matches3) {
|
|
1623
|
+
return matches3[1];
|
|
125
1624
|
}
|
|
126
1625
|
return mimeString;
|
|
127
1626
|
}
|
|
128
1627
|
function parseMIMETypeFromURL(url) {
|
|
129
|
-
const
|
|
130
|
-
if (
|
|
131
|
-
return
|
|
1628
|
+
const matches3 = DATA_URL_PATTERN.exec(url);
|
|
1629
|
+
if (matches3) {
|
|
1630
|
+
return matches3[1];
|
|
132
1631
|
}
|
|
133
1632
|
return "";
|
|
134
1633
|
}
|
|
@@ -136,8 +1635,8 @@ function parseMIMETypeFromURL(url) {
|
|
|
136
1635
|
// dist/lib/utils/url-utils.js
|
|
137
1636
|
var QUERY_STRING_PATTERN = /\?.*/;
|
|
138
1637
|
function extractQueryString(url) {
|
|
139
|
-
const
|
|
140
|
-
return
|
|
1638
|
+
const matches3 = url.match(QUERY_STRING_PATTERN);
|
|
1639
|
+
return matches3 && matches3[0];
|
|
141
1640
|
}
|
|
142
1641
|
function stripQueryString(url) {
|
|
143
1642
|
return url.replace(QUERY_STRING_PATTERN, "");
|
|
@@ -153,10 +1652,10 @@ function shortenUrlForDisplay(url) {
|
|
|
153
1652
|
|
|
154
1653
|
// dist/lib/utils/resource-utils.js
|
|
155
1654
|
function getResourceUrl(resource) {
|
|
156
|
-
if (
|
|
1655
|
+
if (isResponse(resource)) {
|
|
157
1656
|
return resource.url;
|
|
158
1657
|
}
|
|
159
|
-
if (
|
|
1658
|
+
if (isBlob(resource)) {
|
|
160
1659
|
const fileName = "name" in resource ? resource.name : "";
|
|
161
1660
|
return fileName || "";
|
|
162
1661
|
}
|
|
@@ -166,12 +1665,12 @@ function getResourceUrl(resource) {
|
|
|
166
1665
|
return "";
|
|
167
1666
|
}
|
|
168
1667
|
function getResourceMIMEType(resource) {
|
|
169
|
-
if (
|
|
1668
|
+
if (isResponse(resource)) {
|
|
170
1669
|
const contentTypeHeader = resource.headers.get("content-type") || "";
|
|
171
1670
|
const noQueryUrl = stripQueryString(resource.url);
|
|
172
1671
|
return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);
|
|
173
1672
|
}
|
|
174
|
-
if (
|
|
1673
|
+
if (isBlob(resource)) {
|
|
175
1674
|
return resource.type || "";
|
|
176
1675
|
}
|
|
177
1676
|
if (typeof resource === "string") {
|
|
@@ -180,11 +1679,11 @@ function getResourceMIMEType(resource) {
|
|
|
180
1679
|
return "";
|
|
181
1680
|
}
|
|
182
1681
|
function getResourceContentLength(resource) {
|
|
183
|
-
if (
|
|
1682
|
+
if (isResponse(resource)) {
|
|
184
1683
|
const response = resource;
|
|
185
1684
|
return response.headers["content-length"] || -1;
|
|
186
1685
|
}
|
|
187
|
-
if (
|
|
1686
|
+
if (isBlob(resource)) {
|
|
188
1687
|
const blob = resource;
|
|
189
1688
|
return blob.size;
|
|
190
1689
|
}
|
|
@@ -202,7 +1701,7 @@ function getResourceContentLength(resource) {
|
|
|
202
1701
|
|
|
203
1702
|
// dist/lib/utils/response-utils.js
|
|
204
1703
|
async function makeResponse(resource) {
|
|
205
|
-
if (
|
|
1704
|
+
if (isResponse(resource)) {
|
|
206
1705
|
return resource;
|
|
207
1706
|
}
|
|
208
1707
|
const headers = {};
|
|
@@ -255,11 +1754,11 @@ async function getInitialDataUrl(resource) {
|
|
|
255
1754
|
}
|
|
256
1755
|
if (resource instanceof Blob) {
|
|
257
1756
|
const blobSlice = resource.slice(0, 5);
|
|
258
|
-
return await new Promise((
|
|
1757
|
+
return await new Promise((resolve2) => {
|
|
259
1758
|
const reader = new FileReader();
|
|
260
1759
|
reader.onload = (event) => {
|
|
261
1760
|
var _a;
|
|
262
|
-
return
|
|
1761
|
+
return resolve2((_a = event == null ? void 0 : event.target) == null ? void 0 : _a.result);
|
|
263
1762
|
};
|
|
264
1763
|
reader.readAsDataURL(blobSlice);
|
|
265
1764
|
});
|
|
@@ -293,7 +1792,7 @@ function isDataURL(url) {
|
|
|
293
1792
|
async function fetchFile(urlOrData, fetchOptions) {
|
|
294
1793
|
var _a, _b;
|
|
295
1794
|
if (typeof urlOrData === "string") {
|
|
296
|
-
const url =
|
|
1795
|
+
const url = resolvePath(urlOrData);
|
|
297
1796
|
if (isNodePath(url)) {
|
|
298
1797
|
if ((_a = globalThis.loaders) == null ? void 0 : _a.fetchNode) {
|
|
299
1798
|
return (_b = globalThis.loaders) == null ? void 0 : _b.fetchNode(url, fetchOptions);
|
|
@@ -313,23 +1812,20 @@ async function readArrayBuffer(file, start, length) {
|
|
|
313
1812
|
return await readBlob(slice);
|
|
314
1813
|
}
|
|
315
1814
|
async function readBlob(blob) {
|
|
316
|
-
return await new Promise((
|
|
1815
|
+
return await new Promise((resolve2, reject) => {
|
|
317
1816
|
const fileReader = new FileReader();
|
|
318
1817
|
fileReader.onload = (event) => {
|
|
319
1818
|
var _a;
|
|
320
|
-
return
|
|
1819
|
+
return resolve2((_a = event == null ? void 0 : event.target) == null ? void 0 : _a.result);
|
|
321
1820
|
};
|
|
322
1821
|
fileReader.onerror = (error) => reject(error);
|
|
323
1822
|
fileReader.readAsArrayBuffer(blob);
|
|
324
1823
|
});
|
|
325
1824
|
}
|
|
326
1825
|
|
|
327
|
-
// dist/lib/loader-utils/option-utils.js
|
|
328
|
-
var import_loader_utils5 = require("@loaders.gl/loader-utils");
|
|
329
|
-
|
|
330
1826
|
// dist/lib/loader-utils/loggers.js
|
|
331
|
-
var
|
|
332
|
-
var probeLog = new
|
|
1827
|
+
var import_log3 = require("@probe.gl/log");
|
|
1828
|
+
var probeLog = new import_log3.Log({ id: "loaders.gl" });
|
|
333
1829
|
var NullLog = class {
|
|
334
1830
|
/** Drops a log message. */
|
|
335
1831
|
log() {
|
|
@@ -395,7 +1891,6 @@ var ConsoleLog = class {
|
|
|
395
1891
|
};
|
|
396
1892
|
|
|
397
1893
|
// dist/lib/loader-utils/option-defaults.js
|
|
398
|
-
var import_loader_utils4 = require("@loaders.gl/loader-utils");
|
|
399
1894
|
var DEFAULT_LOADER_OPTIONS = {
|
|
400
1895
|
core: {
|
|
401
1896
|
baseUrl: void 0,
|
|
@@ -416,7 +1911,7 @@ var DEFAULT_LOADER_OPTIONS = {
|
|
|
416
1911
|
// How many worker instances should be created for each loader.
|
|
417
1912
|
maxMobileConcurrency: 1,
|
|
418
1913
|
// How many worker instances should be created for each loader on mobile devices.
|
|
419
|
-
reuseWorkers:
|
|
1914
|
+
reuseWorkers: isBrowser,
|
|
420
1915
|
// By default reuse workers in browser (Node.js refuses to terminate if browsers are running)
|
|
421
1916
|
_nodeWorkers: false,
|
|
422
1917
|
// By default do not support node workers
|
|
@@ -521,7 +2016,7 @@ function setGlobalOptions(options) {
|
|
|
521
2016
|
const state = getGlobalLoaderState();
|
|
522
2017
|
const globalOptions = getGlobalLoaderOptions();
|
|
523
2018
|
state.globalOptions = normalizeOptionsInternal(globalOptions, options);
|
|
524
|
-
|
|
2019
|
+
registerJSModules(options.modules);
|
|
525
2020
|
}
|
|
526
2021
|
function normalizeOptions(options, loader, loaders, url) {
|
|
527
2022
|
loaders = loaders || [];
|
|
@@ -555,7 +2050,7 @@ function validateOptionsObject(options, id, defaultOptions, deprecatedOptions, l
|
|
|
555
2050
|
const loaderName = id || "Top level";
|
|
556
2051
|
const prefix = id ? `${id}.` : "";
|
|
557
2052
|
for (const key in options) {
|
|
558
|
-
const isSubOptions = !id &&
|
|
2053
|
+
const isSubOptions = !id && isObject(options[key]);
|
|
559
2054
|
const isBaseUriOption = key === "baseUri" && !id;
|
|
560
2055
|
const isWorkerUrlOption = key === "workerUrl" && id;
|
|
561
2056
|
if (!(key in defaultOptions) && !isBaseUriOption && !isWorkerUrlOption) {
|
|
@@ -615,20 +2110,20 @@ function applyCoreShapeDefault(mergedOptions, userOptions, loader) {
|
|
|
615
2110
|
return;
|
|
616
2111
|
}
|
|
617
2112
|
const loaderScopedDefaults = (_b = loader.options) == null ? void 0 : _b[loader.id];
|
|
618
|
-
if (!
|
|
2113
|
+
if (!isPureObject(loaderScopedDefaults) || !("shape" in loaderScopedDefaults)) {
|
|
619
2114
|
return;
|
|
620
2115
|
}
|
|
621
2116
|
const globalLoaderScopedOptions = getGlobalLoaderOptions()[loader.id];
|
|
622
|
-
if (
|
|
2117
|
+
if (isPureObject(globalLoaderScopedOptions) && "shape" in globalLoaderScopedOptions) {
|
|
623
2118
|
return;
|
|
624
2119
|
}
|
|
625
2120
|
const userLoaderScopedOptions = userOptions[loader.id];
|
|
626
|
-
if (
|
|
2121
|
+
if (isPureObject(userLoaderScopedOptions) && "shape" in userLoaderScopedOptions) {
|
|
627
2122
|
return;
|
|
628
2123
|
}
|
|
629
2124
|
const loaderScopedOptions = mergedOptions[loader.id];
|
|
630
2125
|
mergedOptions[loader.id] = {
|
|
631
|
-
...
|
|
2126
|
+
...isPureObject(loaderScopedOptions) ? loaderScopedOptions : {},
|
|
632
2127
|
shape: coreShape
|
|
633
2128
|
};
|
|
634
2129
|
}
|
|
@@ -636,7 +2131,7 @@ function mergeNestedFields(mergedOptions, options) {
|
|
|
636
2131
|
for (const key in options) {
|
|
637
2132
|
if (key in options) {
|
|
638
2133
|
const value = options[key];
|
|
639
|
-
if (
|
|
2134
|
+
if (isPureObject(value) && isPureObject(mergedOptions[key])) {
|
|
640
2135
|
mergedOptions[key] = {
|
|
641
2136
|
...mergedOptions[key],
|
|
642
2137
|
...options[key]
|
|
@@ -655,7 +2150,7 @@ function addUrlOptions(options, url) {
|
|
|
655
2150
|
const hasCoreBaseUrl = ((_a = options.core) == null ? void 0 : _a.baseUrl) !== void 0;
|
|
656
2151
|
if (!hasCoreBaseUrl) {
|
|
657
2152
|
options.core ||= {};
|
|
658
|
-
options.core.baseUrl =
|
|
2153
|
+
options.core.baseUrl = path_exports.dirname(stripQueryString(url));
|
|
659
2154
|
}
|
|
660
2155
|
}
|
|
661
2156
|
function cloneLoaderOptions(options) {
|
|
@@ -703,7 +2198,6 @@ function addDeprecatedTopLevelOptions(options) {
|
|
|
703
2198
|
}
|
|
704
2199
|
|
|
705
2200
|
// dist/lib/loader-utils/normalize-loader.js
|
|
706
|
-
var import_loader_utils6 = require("@loaders.gl/loader-utils");
|
|
707
2201
|
function isLoaderObject(loader) {
|
|
708
2202
|
if (!loader) {
|
|
709
2203
|
return false;
|
|
@@ -715,8 +2209,8 @@ function isLoaderObject(loader) {
|
|
|
715
2209
|
return hasExtensions;
|
|
716
2210
|
}
|
|
717
2211
|
function normalizeLoader(loader) {
|
|
718
|
-
|
|
719
|
-
|
|
2212
|
+
assert(loader, "null loader");
|
|
2213
|
+
assert(isLoaderObject(loader), "invalid loader");
|
|
720
2214
|
let options;
|
|
721
2215
|
if (Array.isArray(loader)) {
|
|
722
2216
|
options = loader[1];
|
|
@@ -760,7 +2254,6 @@ function _unregisterLoaders() {
|
|
|
760
2254
|
}
|
|
761
2255
|
|
|
762
2256
|
// dist/lib/api/select-loader.js
|
|
763
|
-
var import_loader_utils7 = require("@loaders.gl/loader-utils");
|
|
764
2257
|
var EXT_PATTERN = /\.([^.]+)$/;
|
|
765
2258
|
async function selectLoader(data, loaders = [], options, context) {
|
|
766
2259
|
if (!validHTTPResponse(data)) {
|
|
@@ -779,7 +2272,7 @@ async function selectLoader(data, loaders = [], options, context) {
|
|
|
779
2272
|
if (loader) {
|
|
780
2273
|
return loader;
|
|
781
2274
|
}
|
|
782
|
-
if (
|
|
2275
|
+
if (isBlob(data)) {
|
|
783
2276
|
data = await data.slice(0, 10).arrayBuffer();
|
|
784
2277
|
loader = selectLoaderSync(data, loaders, normalizedOptions, context);
|
|
785
2278
|
}
|
|
@@ -843,7 +2336,7 @@ function selectLoaderInternal(data, loaders, options, context) {
|
|
|
843
2336
|
reason = reason || (loader ? `matched MIME type ${type}` : "");
|
|
844
2337
|
loader = loader || findLoaderByInitialBytes(loaders, data);
|
|
845
2338
|
reason = reason || (loader ? `matched initial data ${getFirstCharacters(data)}` : "");
|
|
846
|
-
if (!loader &&
|
|
2339
|
+
if (!loader && isBlob(data)) {
|
|
847
2340
|
loader = findSourceLoaderByTestData(loaders, data);
|
|
848
2341
|
reason = reason || (loader ? "matched source testData" : "");
|
|
849
2342
|
}
|
|
@@ -852,7 +2345,7 @@ function selectLoaderInternal(data, loaders, options, context) {
|
|
|
852
2345
|
reason = reason || (loader ? `matched fallback MIME type ${type}` : "");
|
|
853
2346
|
}
|
|
854
2347
|
if (reason) {
|
|
855
|
-
|
|
2348
|
+
log.log(1, `selectLoader selected ${loader == null ? void 0 : loader.name}: ${reason}.`);
|
|
856
2349
|
}
|
|
857
2350
|
return loader;
|
|
858
2351
|
}
|
|
@@ -868,7 +2361,7 @@ function getNoValidLoaderMessage(data) {
|
|
|
868
2361
|
const url = getResourceUrl(data);
|
|
869
2362
|
const type = getResourceMIMEType(data);
|
|
870
2363
|
let message = "No valid loader found (";
|
|
871
|
-
message += url ? `${
|
|
2364
|
+
message += url ? `${path_exports.filename(url)}, ` : "no url provided, ";
|
|
872
2365
|
message += `MIME type: ${type ? `"${type}"` : "not provided"}, `;
|
|
873
2366
|
const firstCharacters = data ? getFirstCharacters(data) : "";
|
|
874
2367
|
message += firstCharacters ? ` first bytes: "${firstCharacters}"` : "first bytes: not available";
|
|
@@ -898,7 +2391,7 @@ function findLoaderByExtension(loaders, extension) {
|
|
|
898
2391
|
}
|
|
899
2392
|
function findSourceLoaderByType(loaders, type) {
|
|
900
2393
|
for (const loader of loaders) {
|
|
901
|
-
if (
|
|
2394
|
+
if (isSourceLoader(loader) && loader.type === type) {
|
|
902
2395
|
return loader;
|
|
903
2396
|
}
|
|
904
2397
|
}
|
|
@@ -909,7 +2402,7 @@ function findSourceLoaderByTestURL(loaders, url) {
|
|
|
909
2402
|
return null;
|
|
910
2403
|
}
|
|
911
2404
|
for (const loader of loaders) {
|
|
912
|
-
if (
|
|
2405
|
+
if (isSourceLoader(loader) && loader.testURL(url)) {
|
|
913
2406
|
return loader;
|
|
914
2407
|
}
|
|
915
2408
|
}
|
|
@@ -918,7 +2411,7 @@ function findSourceLoaderByTestURL(loaders, url) {
|
|
|
918
2411
|
function findSourceLoaderByTestData(loaders, data) {
|
|
919
2412
|
var _a;
|
|
920
2413
|
for (const loader of loaders) {
|
|
921
|
-
if (
|
|
2414
|
+
if (isSourceLoader(loader)) {
|
|
922
2415
|
if ((_a = loader.testData) == null ? void 0 : _a.call(loader, data)) {
|
|
923
2416
|
return loader;
|
|
924
2417
|
}
|
|
@@ -972,12 +2465,12 @@ function testDataAgainstBinary(data, byteOffset, loader) {
|
|
|
972
2465
|
return tests.some((test) => testBinary(data, byteOffset, loader, test));
|
|
973
2466
|
}
|
|
974
2467
|
function testBinary(data, byteOffset, loader, test) {
|
|
975
|
-
if (
|
|
976
|
-
return
|
|
2468
|
+
if (isArrayBufferLike(test)) {
|
|
2469
|
+
return compareArrayBuffers(test, data, test.byteLength);
|
|
977
2470
|
}
|
|
978
2471
|
switch (typeof test) {
|
|
979
2472
|
case "function":
|
|
980
|
-
return test(
|
|
2473
|
+
return test(ensureArrayBuffer(data));
|
|
981
2474
|
case "string":
|
|
982
2475
|
const magic = getMagicString(data, byteOffset, test.length);
|
|
983
2476
|
return test === magic;
|
|
@@ -1008,15 +2501,7 @@ function getMagicString(arrayBuffer, byteOffset, length) {
|
|
|
1008
2501
|
return magic;
|
|
1009
2502
|
}
|
|
1010
2503
|
|
|
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
2504
|
// dist/iterators/make-iterator/make-string-iterator.js
|
|
1019
|
-
var import_loader_utils8 = require("@loaders.gl/loader-utils");
|
|
1020
2505
|
var DEFAULT_CHUNK_SIZE = 256 * 1024;
|
|
1021
2506
|
function* makeStringIterator(string, options) {
|
|
1022
2507
|
const chunkSize = (options == null ? void 0 : options.chunkSize) || DEFAULT_CHUNK_SIZE;
|
|
@@ -1026,7 +2511,7 @@ function* makeStringIterator(string, options) {
|
|
|
1026
2511
|
const chunkLength = Math.min(string.length - offset, chunkSize);
|
|
1027
2512
|
const chunk = string.slice(offset, offset + chunkLength);
|
|
1028
2513
|
offset += chunkLength;
|
|
1029
|
-
yield
|
|
2514
|
+
yield ensureArrayBuffer(textEncoder.encode(chunk));
|
|
1030
2515
|
}
|
|
1031
2516
|
}
|
|
1032
2517
|
|
|
@@ -1060,37 +2545,72 @@ async function* makeBlobIterator(blob, options) {
|
|
|
1060
2545
|
}
|
|
1061
2546
|
|
|
1062
2547
|
// dist/iterators/make-iterator/make-stream-iterator.js
|
|
1063
|
-
var import_loader_utils9 = require("@loaders.gl/loader-utils");
|
|
1064
2548
|
function makeStreamIterator(stream, options) {
|
|
1065
|
-
return
|
|
2549
|
+
return isBrowser ? makeBrowserStreamIterator(stream, options) : makeNodeStreamIterator(stream, options);
|
|
1066
2550
|
}
|
|
1067
2551
|
async function* makeBrowserStreamIterator(stream, options) {
|
|
1068
2552
|
const reader = stream.getReader();
|
|
1069
2553
|
let nextBatchPromise;
|
|
2554
|
+
let streamFinished = false;
|
|
2555
|
+
let streamReadFailed = false;
|
|
2556
|
+
let iteratorFailed = false;
|
|
1070
2557
|
try {
|
|
1071
2558
|
while (true) {
|
|
1072
2559
|
const currentBatchPromise = nextBatchPromise || reader.read();
|
|
1073
|
-
|
|
1074
|
-
|
|
2560
|
+
nextBatchPromise = void 0;
|
|
2561
|
+
let batch;
|
|
2562
|
+
try {
|
|
2563
|
+
batch = await currentBatchPromise;
|
|
2564
|
+
} catch (error) {
|
|
2565
|
+
streamReadFailed = true;
|
|
2566
|
+
throw error;
|
|
1075
2567
|
}
|
|
1076
|
-
const { done, value } =
|
|
2568
|
+
const { done, value } = batch;
|
|
1077
2569
|
if (done) {
|
|
2570
|
+
streamFinished = true;
|
|
1078
2571
|
return;
|
|
1079
2572
|
}
|
|
1080
|
-
|
|
2573
|
+
if (options == null ? void 0 : options._streamReadAhead) {
|
|
2574
|
+
nextBatchPromise = reader.read();
|
|
2575
|
+
void nextBatchPromise.catch(() => {
|
|
2576
|
+
});
|
|
2577
|
+
}
|
|
2578
|
+
yield toArrayBuffer2(value);
|
|
2579
|
+
}
|
|
2580
|
+
} catch (error) {
|
|
2581
|
+
iteratorFailed = true;
|
|
2582
|
+
throw error;
|
|
2583
|
+
} finally {
|
|
2584
|
+
let cleanupFailed = false;
|
|
2585
|
+
let cleanupError;
|
|
2586
|
+
if (!streamFinished && !streamReadFailed) {
|
|
2587
|
+
try {
|
|
2588
|
+
await reader.cancel();
|
|
2589
|
+
} catch (error) {
|
|
2590
|
+
cleanupFailed = true;
|
|
2591
|
+
cleanupError = error;
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
try {
|
|
2595
|
+
reader.releaseLock();
|
|
2596
|
+
} catch (error) {
|
|
2597
|
+
if (!cleanupFailed) {
|
|
2598
|
+
cleanupFailed = true;
|
|
2599
|
+
cleanupError = error;
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
if (!iteratorFailed && cleanupFailed) {
|
|
2603
|
+
throw cleanupError;
|
|
1081
2604
|
}
|
|
1082
|
-
} catch (_error) {
|
|
1083
|
-
reader.releaseLock();
|
|
1084
2605
|
}
|
|
1085
2606
|
}
|
|
1086
2607
|
async function* makeNodeStreamIterator(stream, options) {
|
|
1087
2608
|
for await (const chunk of stream) {
|
|
1088
|
-
yield (
|
|
2609
|
+
yield toArrayBuffer2(chunk);
|
|
1089
2610
|
}
|
|
1090
2611
|
}
|
|
1091
2612
|
|
|
1092
2613
|
// dist/iterators/make-iterator/make-iterator.js
|
|
1093
|
-
var import_loader_utils10 = require("@loaders.gl/loader-utils");
|
|
1094
2614
|
function makeIterator(data, options) {
|
|
1095
2615
|
if (typeof data === "string") {
|
|
1096
2616
|
return makeStringIterator(data, options);
|
|
@@ -1098,13 +2618,13 @@ function makeIterator(data, options) {
|
|
|
1098
2618
|
if (data instanceof ArrayBuffer) {
|
|
1099
2619
|
return makeArrayBufferIterator(data, options);
|
|
1100
2620
|
}
|
|
1101
|
-
if (
|
|
2621
|
+
if (isBlob(data)) {
|
|
1102
2622
|
return makeBlobIterator(data, options);
|
|
1103
2623
|
}
|
|
1104
|
-
if (
|
|
2624
|
+
if (isReadableStream(data)) {
|
|
1105
2625
|
return makeStreamIterator(data, options);
|
|
1106
2626
|
}
|
|
1107
|
-
if (
|
|
2627
|
+
if (isResponse(data)) {
|
|
1108
2628
|
const responseBody = data.body;
|
|
1109
2629
|
if (!responseBody) {
|
|
1110
2630
|
throw new Error("Readable stream not available on Response");
|
|
@@ -1120,35 +2640,35 @@ function getArrayBufferOrStringFromDataSync(data, loader, options) {
|
|
|
1120
2640
|
if (loader.text && typeof data === "string") {
|
|
1121
2641
|
return data;
|
|
1122
2642
|
}
|
|
1123
|
-
if (
|
|
2643
|
+
if (isBuffer(data)) {
|
|
1124
2644
|
data = data.buffer;
|
|
1125
2645
|
}
|
|
1126
|
-
if (
|
|
1127
|
-
const bufferSource =
|
|
2646
|
+
if (isArrayBufferLike(data)) {
|
|
2647
|
+
const bufferSource = toArrayBufferView(data);
|
|
1128
2648
|
if (loader.text && !loader.binary) {
|
|
1129
2649
|
const textDecoder = new TextDecoder("utf8");
|
|
1130
2650
|
return textDecoder.decode(bufferSource);
|
|
1131
2651
|
}
|
|
1132
|
-
return (
|
|
2652
|
+
return toArrayBuffer2(bufferSource);
|
|
1133
2653
|
}
|
|
1134
2654
|
throw new Error(ERR_DATA);
|
|
1135
2655
|
}
|
|
1136
2656
|
async function getArrayBufferOrStringFromData(data, loader, options) {
|
|
1137
|
-
if (typeof data === "string" ||
|
|
2657
|
+
if (typeof data === "string" || isArrayBufferLike(data)) {
|
|
1138
2658
|
return getArrayBufferOrStringFromDataSync(data, loader, options);
|
|
1139
2659
|
}
|
|
1140
|
-
if (
|
|
2660
|
+
if (isBlob(data)) {
|
|
1141
2661
|
data = await makeResponse(data);
|
|
1142
2662
|
}
|
|
1143
|
-
if (
|
|
2663
|
+
if (isResponse(data)) {
|
|
1144
2664
|
await checkResponse(data);
|
|
1145
2665
|
return loader.binary ? await data.arrayBuffer() : await data.text();
|
|
1146
2666
|
}
|
|
1147
|
-
if (
|
|
2667
|
+
if (isReadableStream(data)) {
|
|
1148
2668
|
data = makeIterator(data, options);
|
|
1149
2669
|
}
|
|
1150
|
-
if (
|
|
1151
|
-
return
|
|
2670
|
+
if (isIterable(data) || isAsyncIterable(data)) {
|
|
2671
|
+
return concatenateArrayBuffersAsync(data);
|
|
1152
2672
|
}
|
|
1153
2673
|
throw new Error(ERR_DATA);
|
|
1154
2674
|
}
|
|
@@ -1156,32 +2676,32 @@ async function getArrayBufferFromData(data, options) {
|
|
|
1156
2676
|
if (typeof data === "string") {
|
|
1157
2677
|
return new TextEncoder().encode(data).buffer;
|
|
1158
2678
|
}
|
|
1159
|
-
if (
|
|
1160
|
-
return (
|
|
2679
|
+
if (isArrayBufferLike(data)) {
|
|
2680
|
+
return toArrayBuffer2(toArrayBufferView(data));
|
|
1161
2681
|
}
|
|
1162
|
-
if (
|
|
2682
|
+
if (isBlob(data)) {
|
|
1163
2683
|
data = await makeResponse(data);
|
|
1164
2684
|
}
|
|
1165
|
-
if (
|
|
2685
|
+
if (isResponse(data)) {
|
|
1166
2686
|
await checkResponse(data);
|
|
1167
2687
|
return await data.arrayBuffer();
|
|
1168
2688
|
}
|
|
1169
|
-
if (
|
|
2689
|
+
if (isReadableStream(data)) {
|
|
1170
2690
|
data = makeIterator(data, options);
|
|
1171
2691
|
}
|
|
1172
|
-
if (
|
|
1173
|
-
return
|
|
2692
|
+
if (isIterable(data) || isAsyncIterable(data)) {
|
|
2693
|
+
return concatenateArrayBuffersAsync(data);
|
|
1174
2694
|
}
|
|
1175
2695
|
throw new Error(ERR_DATA);
|
|
1176
2696
|
}
|
|
1177
2697
|
async function getAsyncIterableFromData(data, options) {
|
|
1178
|
-
if (
|
|
2698
|
+
if (isPromise(data)) {
|
|
1179
2699
|
data = await data;
|
|
1180
2700
|
}
|
|
1181
|
-
if (
|
|
2701
|
+
if (isIterator(data)) {
|
|
1182
2702
|
return data;
|
|
1183
2703
|
}
|
|
1184
|
-
if (
|
|
2704
|
+
if (isResponse(data)) {
|
|
1185
2705
|
await checkResponse(data);
|
|
1186
2706
|
const body = await data.body;
|
|
1187
2707
|
if (!body) {
|
|
@@ -1189,39 +2709,38 @@ async function getAsyncIterableFromData(data, options) {
|
|
|
1189
2709
|
}
|
|
1190
2710
|
return makeIterator(body, options);
|
|
1191
2711
|
}
|
|
1192
|
-
if (
|
|
2712
|
+
if (isBlob(data) || isReadableStream(data)) {
|
|
1193
2713
|
return makeIterator(data, options);
|
|
1194
2714
|
}
|
|
1195
|
-
if (
|
|
2715
|
+
if (isAsyncIterable(data)) {
|
|
1196
2716
|
return data;
|
|
1197
2717
|
}
|
|
1198
|
-
if (
|
|
2718
|
+
if (isIterable(data)) {
|
|
1199
2719
|
return data;
|
|
1200
2720
|
}
|
|
1201
2721
|
return getIterableFromData(data);
|
|
1202
2722
|
}
|
|
1203
2723
|
function getIterableFromData(data) {
|
|
1204
2724
|
if (ArrayBuffer.isView(data)) {
|
|
1205
|
-
return function* oneChunk() {
|
|
1206
|
-
yield (
|
|
1207
|
-
}();
|
|
2725
|
+
return (function* oneChunk() {
|
|
2726
|
+
yield toArrayBuffer2(data);
|
|
2727
|
+
})();
|
|
1208
2728
|
}
|
|
1209
|
-
if (
|
|
1210
|
-
return function* oneChunk() {
|
|
1211
|
-
yield (
|
|
1212
|
-
}();
|
|
2729
|
+
if (isArrayBufferLike(data)) {
|
|
2730
|
+
return (function* oneChunk() {
|
|
2731
|
+
yield toArrayBuffer2(data);
|
|
2732
|
+
})();
|
|
1213
2733
|
}
|
|
1214
|
-
if (
|
|
2734
|
+
if (isIterator(data)) {
|
|
1215
2735
|
return data;
|
|
1216
2736
|
}
|
|
1217
|
-
if (
|
|
2737
|
+
if (isIterable(data)) {
|
|
1218
2738
|
return data[Symbol.iterator]();
|
|
1219
2739
|
}
|
|
1220
2740
|
throw new Error(ERR_DATA);
|
|
1221
2741
|
}
|
|
1222
2742
|
|
|
1223
2743
|
// dist/lib/loader-utils/get-fetch-function.js
|
|
1224
|
-
var import_loader_utils12 = require("@loaders.gl/loader-utils");
|
|
1225
2744
|
function getFetchFunction(options, context) {
|
|
1226
2745
|
var _a;
|
|
1227
2746
|
const globalOptions = getGlobalLoaderOptions();
|
|
@@ -1230,7 +2749,7 @@ function getFetchFunction(options, context) {
|
|
|
1230
2749
|
if (typeof fetchOption === "function") {
|
|
1231
2750
|
return fetchOption;
|
|
1232
2751
|
}
|
|
1233
|
-
if (
|
|
2752
|
+
if (isObject(fetchOption)) {
|
|
1234
2753
|
return (url) => fetchFile(url, fetchOption);
|
|
1235
2754
|
}
|
|
1236
2755
|
if (context == null ? void 0 : context.fetch) {
|
|
@@ -1239,13 +2758,6 @@ function getFetchFunction(options, context) {
|
|
|
1239
2758
|
return fetchFile;
|
|
1240
2759
|
}
|
|
1241
2760
|
|
|
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
2761
|
// dist/lib/api/load-loader.js
|
|
1250
2762
|
var loaderImplementationPromises = /* @__PURE__ */ new Map();
|
|
1251
2763
|
var loaderImplementations = /* @__PURE__ */ new Map();
|
|
@@ -1327,10 +2839,7 @@ function getLoaderImplementationCacheKey(loader, options) {
|
|
|
1327
2839
|
var _a;
|
|
1328
2840
|
const loaderOptions = options == null ? void 0 : options[loader.id];
|
|
1329
2841
|
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;
|
|
2842
|
+
return String((loaderOptions == null ? void 0 : loaderOptions.backend) || (defaultLoaderOptions == null ? void 0 : defaultLoaderOptions.backend) || "");
|
|
1334
2843
|
}
|
|
1335
2844
|
async function importLoaderImplementation(implementationSpecifier, loaderId) {
|
|
1336
2845
|
const moduleExports = await import(
|
|
@@ -1361,7 +2870,7 @@ async function parseFile(file, loaders, options, context) {
|
|
|
1361
2870
|
if (!loader) {
|
|
1362
2871
|
return null;
|
|
1363
2872
|
}
|
|
1364
|
-
if (
|
|
2873
|
+
if (isSourceLoader(loader)) {
|
|
1365
2874
|
throw new Error(`${loader.id} is a SourceLoader. Use load() to create a runtime source object instead of parseFile().`);
|
|
1366
2875
|
}
|
|
1367
2876
|
const strictOptions = normalizeOptions(options, loader, candidateLoaders, url);
|
|
@@ -1374,8 +2883,8 @@ async function parseFile(file, loaders, options, context) {
|
|
|
1374
2883
|
return await parseFileWithLoader(loader, file, strictOptions, context);
|
|
1375
2884
|
}
|
|
1376
2885
|
async function parseFileWithLoader(loader, file, options, context) {
|
|
1377
|
-
|
|
1378
|
-
options =
|
|
2886
|
+
validateWorkerVersion(loader);
|
|
2887
|
+
options = mergeOptions(loader.options, options);
|
|
1379
2888
|
const loaderWithParser = await getLoaderImplementation(loader, options, context.url);
|
|
1380
2889
|
if (loaderWithParser.parseFile) {
|
|
1381
2890
|
return await loaderWithParser.parseFile(file, options, context);
|
|
@@ -1393,7 +2902,6 @@ async function parseFileWithLoader(loader, file, options, context) {
|
|
|
1393
2902
|
}
|
|
1394
2903
|
|
|
1395
2904
|
// dist/lib/api/parse-sync.js
|
|
1396
|
-
var import_loader_utils14 = require("@loaders.gl/loader-utils");
|
|
1397
2905
|
function parseSync(data, loaders, options, context) {
|
|
1398
2906
|
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
1399
2907
|
context = void 0;
|
|
@@ -1407,7 +2915,7 @@ function parseSync(data, loaders, options, context) {
|
|
|
1407
2915
|
if (!loader) {
|
|
1408
2916
|
return null;
|
|
1409
2917
|
}
|
|
1410
|
-
if (
|
|
2918
|
+
if (isSourceLoader(loader)) {
|
|
1411
2919
|
throw new Error(`${loader.id} is a SourceLoader. Use load() to create a runtime source object instead of parseSync().`);
|
|
1412
2920
|
}
|
|
1413
2921
|
const strictOptions = normalizeOptions(options, loader, candidateLoaders);
|
|
@@ -1433,9 +2941,50 @@ function parseWithLoaderSync(loader, data, options, context) {
|
|
|
1433
2941
|
throw new Error(`${loader.name} loader: 'parseSync' not supported by this loader, use 'parse' instead. ${context.url || ""}`);
|
|
1434
2942
|
}
|
|
1435
2943
|
|
|
2944
|
+
// ../schema-utils/src/lib/table/tables/table-accessors.ts
|
|
2945
|
+
function isTable(table) {
|
|
2946
|
+
var _a;
|
|
2947
|
+
const shape = typeof table === "object" && (table == null ? void 0 : table.shape);
|
|
2948
|
+
switch (shape) {
|
|
2949
|
+
case "array-row-table":
|
|
2950
|
+
case "object-row-table":
|
|
2951
|
+
return Array.isArray(table.data);
|
|
2952
|
+
case "geojson-table":
|
|
2953
|
+
return Array.isArray(table.features);
|
|
2954
|
+
case "columnar-table":
|
|
2955
|
+
return table.data && typeof table.data === "object";
|
|
2956
|
+
case "arrow-table":
|
|
2957
|
+
return Boolean(((_a = table == null ? void 0 : table.data) == null ? void 0 : _a.numRows) !== void 0);
|
|
2958
|
+
default:
|
|
2959
|
+
return false;
|
|
2960
|
+
}
|
|
2961
|
+
}
|
|
2962
|
+
function getTableLength(table) {
|
|
2963
|
+
switch (table.shape) {
|
|
2964
|
+
case "array-row-table":
|
|
2965
|
+
case "object-row-table":
|
|
2966
|
+
return table.data.length;
|
|
2967
|
+
case "geojson-table":
|
|
2968
|
+
return table.features.length;
|
|
2969
|
+
case "arrow-table":
|
|
2970
|
+
const arrowTable = table.data;
|
|
2971
|
+
return arrowTable.numRows;
|
|
2972
|
+
case "columnar-table":
|
|
2973
|
+
for (const column of Object.values(table.data)) {
|
|
2974
|
+
return column.length || 0;
|
|
2975
|
+
}
|
|
2976
|
+
return 0;
|
|
2977
|
+
default:
|
|
2978
|
+
throw new Error("table");
|
|
2979
|
+
}
|
|
2980
|
+
}
|
|
2981
|
+
|
|
2982
|
+
// ../schema-utils/src/lib/table/batches/make-table-batch-iterator.ts
|
|
2983
|
+
function makeBatchFromTable(table) {
|
|
2984
|
+
return { ...table, length: getTableLength(table), batchType: "data" };
|
|
2985
|
+
}
|
|
2986
|
+
|
|
1436
2987
|
// 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
2988
|
async function parseInBatches(data, loaders, options, context) {
|
|
1440
2989
|
const loaderArray = Array.isArray(loaders) ? loaders : void 0;
|
|
1441
2990
|
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
@@ -1488,7 +3037,7 @@ async function parseToOutputIterator(loader, data, options, context) {
|
|
|
1488
3037
|
return parseChunkInBatches(transformedIterator, loader, options, context);
|
|
1489
3038
|
}
|
|
1490
3039
|
async function* parseChunkInBatches(transformedIterator, loader, options, context) {
|
|
1491
|
-
const arrayBuffer = await
|
|
3040
|
+
const arrayBuffer = await concatenateArrayBuffersAsync(transformedIterator);
|
|
1492
3041
|
const parsedData = await parse(
|
|
1493
3042
|
arrayBuffer,
|
|
1494
3043
|
loader,
|
|
@@ -1500,7 +3049,7 @@ async function* parseChunkInBatches(transformedIterator, loader, options, contex
|
|
|
1500
3049
|
yield batch;
|
|
1501
3050
|
}
|
|
1502
3051
|
function convertDataToBatch(parsedData, loader) {
|
|
1503
|
-
const batch =
|
|
3052
|
+
const batch = isTable(parsedData) ? makeBatchFromTable(parsedData) : {
|
|
1504
3053
|
shape: "unknown",
|
|
1505
3054
|
batchType: "data",
|
|
1506
3055
|
data: parsedData,
|
|
@@ -1517,9 +3066,6 @@ async function applyInputTransforms(inputIterator, transforms = []) {
|
|
|
1517
3066
|
return iteratorChain;
|
|
1518
3067
|
}
|
|
1519
3068
|
|
|
1520
|
-
// dist/lib/api/load.js
|
|
1521
|
-
var import_loader_utils16 = require("@loaders.gl/loader-utils");
|
|
1522
|
-
|
|
1523
3069
|
// dist/lib/api/load-in-batches.js
|
|
1524
3070
|
function loadInBatches(files, loaders, options, context) {
|
|
1525
3071
|
let loadersArray;
|
|
@@ -1559,7 +3105,8 @@ async function load(url, loaders, options, context) {
|
|
|
1559
3105
|
resolvedLoaders = loaders;
|
|
1560
3106
|
resolvedOptions = options;
|
|
1561
3107
|
}
|
|
1562
|
-
if (!Array.isArray(resolvedLoaders) &&
|
|
3108
|
+
if (!Array.isArray(resolvedLoaders) && isSourceLoader(resolvedLoaders)) {
|
|
3109
|
+
const sourceLoader = await resolveSourceLoader(resolvedLoaders, url, resolvedOptions);
|
|
1563
3110
|
const runtimeCoreApi = {
|
|
1564
3111
|
fetchFile,
|
|
1565
3112
|
parse,
|
|
@@ -1569,9 +3116,10 @@ async function load(url, loaders, options, context) {
|
|
|
1569
3116
|
load,
|
|
1570
3117
|
loadInBatches
|
|
1571
3118
|
};
|
|
1572
|
-
return
|
|
3119
|
+
return sourceLoader.createDataSource(url, resolvedOptions || {}, runtimeCoreApi);
|
|
1573
3120
|
}
|
|
1574
|
-
if (Array.isArray(resolvedLoaders) && resolvedLoaders.length === 1 &&
|
|
3121
|
+
if (Array.isArray(resolvedLoaders) && resolvedLoaders.length === 1 && isSourceLoader(resolvedLoaders[0])) {
|
|
3122
|
+
const sourceLoader = await resolveSourceLoader(resolvedLoaders[0], url, resolvedOptions);
|
|
1575
3123
|
const runtimeCoreApi = {
|
|
1576
3124
|
fetchFile,
|
|
1577
3125
|
parse,
|
|
@@ -1581,15 +3129,16 @@ async function load(url, loaders, options, context) {
|
|
|
1581
3129
|
load,
|
|
1582
3130
|
loadInBatches
|
|
1583
3131
|
};
|
|
1584
|
-
return
|
|
3132
|
+
return sourceLoader.createDataSource(url, resolvedOptions || {}, runtimeCoreApi);
|
|
1585
3133
|
}
|
|
1586
|
-
if (typeof url === "string" ||
|
|
3134
|
+
if (typeof url === "string" || isBlob(url)) {
|
|
1587
3135
|
const selectedLoader = await selectLoader(url, resolvedLoaders, {
|
|
1588
3136
|
...resolvedOptions,
|
|
1589
3137
|
core: { ...resolvedOptions == null ? void 0 : resolvedOptions.core, nothrow: true }
|
|
1590
3138
|
});
|
|
1591
|
-
if (selectedLoader &&
|
|
1592
|
-
|
|
3139
|
+
if (selectedLoader && isSourceLoader(selectedLoader)) {
|
|
3140
|
+
const sourceLoader = await resolveSourceLoader(selectedLoader, url, resolvedOptions);
|
|
3141
|
+
return sourceLoader.createDataSource(url, resolvedOptions || {}, {
|
|
1593
3142
|
fetchFile,
|
|
1594
3143
|
parse,
|
|
1595
3144
|
parseFile,
|
|
@@ -1605,7 +3154,7 @@ async function load(url, loaders, options, context) {
|
|
|
1605
3154
|
if (typeof url === "string") {
|
|
1606
3155
|
data = await fetch2(url);
|
|
1607
3156
|
}
|
|
1608
|
-
if (
|
|
3157
|
+
if (isBlob(url)) {
|
|
1609
3158
|
data = await fetch2(url);
|
|
1610
3159
|
}
|
|
1611
3160
|
if (typeof url === "string") {
|
|
@@ -1622,6 +3171,16 @@ async function load(url, loaders, options, context) {
|
|
|
1622
3171
|
}
|
|
1623
3172
|
return Array.isArray(resolvedLoaders) ? await parse(data, resolvedLoaders, resolvedOptions, context) : await parse(data, resolvedLoaders, resolvedOptions, context);
|
|
1624
3173
|
}
|
|
3174
|
+
async function resolveSourceLoader(loader, url, options) {
|
|
3175
|
+
if (!loader.preload) {
|
|
3176
|
+
return loader;
|
|
3177
|
+
}
|
|
3178
|
+
const sourceLoader = await loader.preload(typeof url === "string" ? url : "", options);
|
|
3179
|
+
if (!isSourceLoader(sourceLoader)) {
|
|
3180
|
+
throw new Error(`${loader.id} source loader preload() did not return a runtime source loader`);
|
|
3181
|
+
}
|
|
3182
|
+
return sourceLoader;
|
|
3183
|
+
}
|
|
1625
3184
|
|
|
1626
3185
|
// dist/lib/api/core-api.js
|
|
1627
3186
|
var coreApi = Object.freeze({
|
|
@@ -1648,8 +3207,8 @@ function getLoaderContext(context, options, parentContext) {
|
|
|
1648
3207
|
const baseUrl = stripQueryString(newContext.url);
|
|
1649
3208
|
newContext.baseUrl = baseUrl;
|
|
1650
3209
|
newContext.queryString = extractQueryString(newContext.url);
|
|
1651
|
-
newContext.filename =
|
|
1652
|
-
newContext.baseUrl =
|
|
3210
|
+
newContext.filename = path_exports.filename(baseUrl);
|
|
3211
|
+
newContext.baseUrl = path_exports.dirname(baseUrl);
|
|
1653
3212
|
}
|
|
1654
3213
|
if (!Array.isArray(newContext.loaders)) {
|
|
1655
3214
|
newContext.loaders = null;
|
|
@@ -1687,7 +3246,7 @@ async function parse(data, loaders, options, context) {
|
|
|
1687
3246
|
if (!loader) {
|
|
1688
3247
|
return null;
|
|
1689
3248
|
}
|
|
1690
|
-
if (
|
|
3249
|
+
if (isSourceLoader(loader)) {
|
|
1691
3250
|
throw new Error(`${loader.id} is a SourceLoader. Use load() to create a runtime source object instead of parse().`);
|
|
1692
3251
|
}
|
|
1693
3252
|
const strictOptions = normalizeOptions(options, loader, candidateLoaders, url);
|
|
@@ -1700,17 +3259,20 @@ async function parse(data, loaders, options, context) {
|
|
|
1700
3259
|
return await parseWithLoader(loader, data, strictOptions, context);
|
|
1701
3260
|
}
|
|
1702
3261
|
async function parseWithLoader(loader, data, options, context) {
|
|
1703
|
-
|
|
1704
|
-
options =
|
|
1705
|
-
if (
|
|
3262
|
+
validateWorkerVersion(loader);
|
|
3263
|
+
options = mergeOptions(loader.options, options);
|
|
3264
|
+
if (isResponse(data)) {
|
|
1706
3265
|
const { ok, redirected, status, statusText, type, url } = data;
|
|
1707
3266
|
const headers = Object.fromEntries(data.headers.entries());
|
|
1708
3267
|
context.response = { headers, ok, redirected, status, statusText, type, url };
|
|
1709
3268
|
}
|
|
1710
3269
|
const loaderWithParser = await getLoaderImplementation(loader, options, context.url);
|
|
1711
|
-
if (
|
|
3270
|
+
if (canParseWithWorker(loaderWithParser, options)) {
|
|
1712
3271
|
data = await getArrayBufferFromData(data, options);
|
|
1713
|
-
return await
|
|
3272
|
+
return await parseWithWorker(loaderWithParser, data, options, context, parse);
|
|
3273
|
+
}
|
|
3274
|
+
if (isBlob(data) && loaderWithParser.parseBlob) {
|
|
3275
|
+
return await loaderWithParser.parseBlob(data, options, context);
|
|
1714
3276
|
}
|
|
1715
3277
|
data = await getArrayBufferOrStringFromData(data, loader, options);
|
|
1716
3278
|
return await parseWithLoaderImplementation(loaderWithParser, data, options, context);
|
|
@@ -1740,14 +3302,13 @@ function preloadSync(loader) {
|
|
|
1740
3302
|
}
|
|
1741
3303
|
|
|
1742
3304
|
// dist/lib/api/encode-table.js
|
|
1743
|
-
var import_loader_utils19 = require("@loaders.gl/loader-utils");
|
|
1744
3305
|
async function encodeTable(data, writer, options) {
|
|
1745
3306
|
if (writer.encode) {
|
|
1746
3307
|
return await writer.encode(data, options);
|
|
1747
3308
|
}
|
|
1748
3309
|
if (writer.encodeText) {
|
|
1749
3310
|
const text = await writer.encodeText(data, options);
|
|
1750
|
-
return
|
|
3311
|
+
return ensureArrayBuffer(new TextEncoder().encode(text));
|
|
1751
3312
|
}
|
|
1752
3313
|
if (writer.encodeInBatches) {
|
|
1753
3314
|
const batches = encodeTableInBatches(data, writer, options);
|
|
@@ -1755,7 +3316,7 @@ async function encodeTable(data, writer, options) {
|
|
|
1755
3316
|
for await (const batch of batches) {
|
|
1756
3317
|
chunks.push(batch);
|
|
1757
3318
|
}
|
|
1758
|
-
return
|
|
3319
|
+
return concatenateArrayBuffers(...chunks);
|
|
1759
3320
|
}
|
|
1760
3321
|
throw new Error("Writer could not encode data");
|
|
1761
3322
|
}
|
|
@@ -1782,16 +3343,14 @@ function getIterator(data) {
|
|
|
1782
3343
|
}
|
|
1783
3344
|
|
|
1784
3345
|
// 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
3346
|
async function encode(data, writer, options_) {
|
|
1788
3347
|
const globalOptions = getGlobalLoaderOptions();
|
|
1789
3348
|
const options = { ...globalOptions, ...options_ };
|
|
1790
3349
|
if (writer.encodeURLtoURL) {
|
|
1791
3350
|
return encodeWithCommandLineTool(writer, data, options);
|
|
1792
3351
|
}
|
|
1793
|
-
if (
|
|
1794
|
-
return await
|
|
3352
|
+
if (canEncodeWithWorker(writer, options)) {
|
|
3353
|
+
return await processOnWorker(writer, data, options);
|
|
1795
3354
|
}
|
|
1796
3355
|
return await writer.encode(data, options);
|
|
1797
3356
|
}
|
|
@@ -1800,7 +3359,7 @@ function encodeSync(data, writer, options) {
|
|
|
1800
3359
|
return writer.encodeSync(data, options);
|
|
1801
3360
|
}
|
|
1802
3361
|
if (writer.encodeTextSync) {
|
|
1803
|
-
return
|
|
3362
|
+
return ensureArrayBuffer(new TextEncoder().encode(writer.encodeTextSync(data, options)));
|
|
1804
3363
|
}
|
|
1805
3364
|
throw new Error(`Writer ${writer.name} could not synchronously encode data`);
|
|
1806
3365
|
}
|
|
@@ -1835,20 +3394,20 @@ function encodeInBatches(data, writer, options) {
|
|
|
1835
3394
|
throw new Error(`Writer ${writer.name} could not encode in batches`);
|
|
1836
3395
|
}
|
|
1837
3396
|
async function encodeURLtoURL(inputUrl, outputUrl, writer, options) {
|
|
1838
|
-
inputUrl =
|
|
1839
|
-
outputUrl =
|
|
1840
|
-
if (
|
|
3397
|
+
inputUrl = resolvePath(inputUrl);
|
|
3398
|
+
outputUrl = resolvePath(outputUrl);
|
|
3399
|
+
if (isBrowser || !writer.encodeURLtoURL) {
|
|
1841
3400
|
throw new Error();
|
|
1842
3401
|
}
|
|
1843
3402
|
const outputFilename = await writer.encodeURLtoURL(inputUrl, outputUrl, options);
|
|
1844
3403
|
return outputFilename;
|
|
1845
3404
|
}
|
|
1846
3405
|
async function encodeWithCommandLineTool(writer, data, options) {
|
|
1847
|
-
if (
|
|
3406
|
+
if (isBrowser) {
|
|
1848
3407
|
throw new Error(`Writer ${writer.name} not supported in browser`);
|
|
1849
3408
|
}
|
|
1850
3409
|
const tmpInputFilename = getTemporaryFilename("input");
|
|
1851
|
-
const file = new
|
|
3410
|
+
const file = new NodeFileFacade(tmpInputFilename, "w");
|
|
1852
3411
|
await file.write(data);
|
|
1853
3412
|
const tmpOutputFilename = getTemporaryFilename("output");
|
|
1854
3413
|
const outputFilename = await encodeURLtoURL(tmpInputFilename, tmpOutputFilename, writer, options);
|
|
@@ -1859,8 +3418,8 @@ function getIterator2(data) {
|
|
|
1859
3418
|
const dataIterator = [{ ...data, start: 0, end: data.length }];
|
|
1860
3419
|
return dataIterator;
|
|
1861
3420
|
}
|
|
1862
|
-
function getTemporaryFilename(
|
|
1863
|
-
return `/tmp/${
|
|
3421
|
+
function getTemporaryFilename(filename2) {
|
|
3422
|
+
return `/tmp/${filename2}`;
|
|
1864
3423
|
}
|
|
1865
3424
|
|
|
1866
3425
|
// dist/lib/api/create-data-source.js
|
|
@@ -1911,10 +3470,6 @@ function getSourceOfType2(type, sources) {
|
|
|
1911
3470
|
return null;
|
|
1912
3471
|
}
|
|
1913
3472
|
|
|
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
3473
|
// dist/iterators/make-stream/make-stream.js
|
|
1919
3474
|
function makeStream(source, options) {
|
|
1920
3475
|
if (globalThis.loaders.makeNodeStream) {
|
|
@@ -1955,14 +3510,14 @@ function makeStream(source, options) {
|
|
|
1955
3510
|
}
|
|
1956
3511
|
|
|
1957
3512
|
// dist/null-loader.js
|
|
1958
|
-
var
|
|
3513
|
+
var VERSION4 = true ? "5.0.0-alpha.2" : "latest";
|
|
1959
3514
|
var NullWorkerLoader = {
|
|
1960
3515
|
dataType: null,
|
|
1961
3516
|
batchType: null,
|
|
1962
3517
|
name: "Null loader",
|
|
1963
3518
|
id: "null",
|
|
1964
3519
|
module: "core",
|
|
1965
|
-
version:
|
|
3520
|
+
version: VERSION4,
|
|
1966
3521
|
worker: true,
|
|
1967
3522
|
mimeTypes: ["application/x.empty"],
|
|
1968
3523
|
extensions: ["null"],
|
|
@@ -1977,7 +3532,7 @@ var NullLoader = {
|
|
|
1977
3532
|
name: "Null loader",
|
|
1978
3533
|
id: "null",
|
|
1979
3534
|
module: "core",
|
|
1980
|
-
version:
|
|
3535
|
+
version: VERSION4,
|
|
1981
3536
|
mimeTypes: ["application/x.empty"],
|
|
1982
3537
|
extensions: ["null"],
|
|
1983
3538
|
parse: async (arrayBuffer, options, context) => parseSync2(arrayBuffer, options || {}, context),
|
|
@@ -1996,9 +3551,6 @@ function parseSync2(arrayBuffer, options, context) {
|
|
|
1996
3551
|
return null;
|
|
1997
3552
|
}
|
|
1998
3553
|
|
|
1999
|
-
// dist/index.js
|
|
2000
|
-
var import_loader_utils24 = require("@loaders.gl/loader-utils");
|
|
2001
|
-
|
|
2002
3554
|
// dist/lib/progress/fetch-progress.js
|
|
2003
3555
|
async function fetchProgress(response, onProgress, onDone = () => {
|
|
2004
3556
|
}, onError = () => {
|
|
@@ -2047,7 +3599,6 @@ async function read(controller, reader, loadedBytes, totalBytes, onProgress, onD
|
|
|
2047
3599
|
}
|
|
2048
3600
|
|
|
2049
3601
|
// dist/lib/filesystems/browser-filesystem.js
|
|
2050
|
-
var import_loader_utils21 = require("@loaders.gl/loader-utils");
|
|
2051
3602
|
var BrowserFileSystem = class {
|
|
2052
3603
|
_fetch;
|
|
2053
3604
|
files = {};
|
|
@@ -2073,13 +3624,13 @@ var BrowserFileSystem = class {
|
|
|
2073
3624
|
* Implementation of fetch against this file system
|
|
2074
3625
|
* Delegates to global fetch for http{s}:// or data://
|
|
2075
3626
|
*/
|
|
2076
|
-
async fetch(
|
|
2077
|
-
if (
|
|
2078
|
-
return this._fetch(
|
|
3627
|
+
async fetch(path, options) {
|
|
3628
|
+
if (path.includes("://")) {
|
|
3629
|
+
return this._fetch(path, options);
|
|
2079
3630
|
}
|
|
2080
|
-
const file = this.files[
|
|
3631
|
+
const file = this.files[path];
|
|
2081
3632
|
if (!file) {
|
|
2082
|
-
return new Response(
|
|
3633
|
+
return new Response(path, { status: 400, statusText: "NOT FOUND" });
|
|
2083
3634
|
}
|
|
2084
3635
|
const headers = new Headers(options == null ? void 0 : options.headers);
|
|
2085
3636
|
const range = headers.get("Range");
|
|
@@ -2089,11 +3640,11 @@ var BrowserFileSystem = class {
|
|
|
2089
3640
|
const end = parseInt(bytes[2]);
|
|
2090
3641
|
const data = await file.slice(start, end).arrayBuffer();
|
|
2091
3642
|
const response2 = new Response(data);
|
|
2092
|
-
Object.defineProperty(response2, "url", { value:
|
|
3643
|
+
Object.defineProperty(response2, "url", { value: path });
|
|
2093
3644
|
return response2;
|
|
2094
3645
|
}
|
|
2095
3646
|
const response = new Response(file);
|
|
2096
|
-
Object.defineProperty(response, "url", { value:
|
|
3647
|
+
Object.defineProperty(response, "url", { value: path });
|
|
2097
3648
|
return response;
|
|
2098
3649
|
}
|
|
2099
3650
|
/**
|
|
@@ -2101,51 +3652,44 @@ var BrowserFileSystem = class {
|
|
|
2101
3652
|
* @param dirname
|
|
2102
3653
|
* @returns
|
|
2103
3654
|
*/
|
|
2104
|
-
async readdir(
|
|
3655
|
+
async readdir(dirname2) {
|
|
2105
3656
|
const files = [];
|
|
2106
|
-
for (const
|
|
2107
|
-
files.push(
|
|
3657
|
+
for (const path in this.files) {
|
|
3658
|
+
files.push(path);
|
|
2108
3659
|
}
|
|
2109
3660
|
return files;
|
|
2110
3661
|
}
|
|
2111
3662
|
/**
|
|
2112
3663
|
* Return information (size) about files in this file system
|
|
2113
3664
|
*/
|
|
2114
|
-
async stat(
|
|
2115
|
-
const file = this.files[
|
|
3665
|
+
async stat(path, options) {
|
|
3666
|
+
const file = this.files[path];
|
|
2116
3667
|
if (!file) {
|
|
2117
|
-
throw new Error(
|
|
3668
|
+
throw new Error(path);
|
|
2118
3669
|
}
|
|
2119
3670
|
return { size: file.size };
|
|
2120
3671
|
}
|
|
2121
3672
|
/**
|
|
2122
3673
|
* Just removes the file from the list
|
|
2123
3674
|
*/
|
|
2124
|
-
async unlink(
|
|
2125
|
-
delete this.files[
|
|
2126
|
-
delete this.lowerCaseFiles[
|
|
2127
|
-
this.usedFiles[
|
|
3675
|
+
async unlink(path) {
|
|
3676
|
+
delete this.files[path];
|
|
3677
|
+
delete this.lowerCaseFiles[path];
|
|
3678
|
+
this.usedFiles[path] = true;
|
|
2128
3679
|
}
|
|
2129
3680
|
// implements IRandomAccessFileSystem
|
|
2130
3681
|
// RANDOM ACCESS
|
|
2131
3682
|
async openReadableFile(pathname, flags) {
|
|
2132
|
-
return new
|
|
3683
|
+
return new BlobFile(this.files[pathname]);
|
|
2133
3684
|
}
|
|
2134
3685
|
// PRIVATE
|
|
2135
3686
|
// Supports case independent paths, and file usage tracking
|
|
2136
|
-
_getFile(
|
|
2137
|
-
const file = this.files[
|
|
3687
|
+
_getFile(path, used) {
|
|
3688
|
+
const file = this.files[path] || this.lowerCaseFiles[path];
|
|
2138
3689
|
if (file && used) {
|
|
2139
|
-
this.usedFiles[
|
|
3690
|
+
this.usedFiles[path] = true;
|
|
2140
3691
|
}
|
|
2141
3692
|
return file;
|
|
2142
3693
|
}
|
|
2143
3694
|
};
|
|
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
3695
|
//# sourceMappingURL=index.cjs.map
|