@loaders.gl/core 4.4.5 → 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 +800 -271
- package/dist/dist.min.js +4 -3
- package/dist/index.cjs +2191 -296
- package/dist/index.cjs.map +3 -4
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/iterators/make-iterator/make-stream-iterator.js +48 -9
- package/dist/iterators/make-iterator/make-stream-iterator.js.map +1 -1
- package/dist/lib/api/core-api.d.ts +6 -0
- package/dist/lib/api/core-api.d.ts.map +1 -0
- package/dist/lib/api/core-api.js +23 -0
- package/dist/lib/api/core-api.js.map +1 -0
- package/dist/lib/api/create-data-source.d.ts +2 -2
- package/dist/lib/api/create-data-source.d.ts.map +1 -1
- package/dist/lib/api/create-data-source.js +15 -14
- package/dist/lib/api/create-data-source.js.map +1 -1
- package/dist/lib/api/load-in-batches.d.ts +4 -4
- package/dist/lib/api/load-in-batches.d.ts.map +1 -1
- package/dist/lib/api/load-in-batches.js +1 -1
- package/dist/lib/api/load-in-batches.js.map +1 -1
- package/dist/lib/api/load-loader.d.ts +8 -0
- package/dist/lib/api/load-loader.d.ts.map +1 -0
- package/dist/lib/api/load-loader.js +110 -0
- package/dist/lib/api/load-loader.js.map +1 -0
- package/dist/lib/api/load.d.ts +2 -2
- package/dist/lib/api/load.d.ts.map +1 -1
- package/dist/lib/api/load.js +66 -3
- package/dist/lib/api/load.js.map +1 -1
- package/dist/lib/api/parse-file.d.ts +15 -0
- package/dist/lib/api/parse-file.d.ts.map +1 -0
- package/dist/lib/api/parse-file.js +70 -0
- package/dist/lib/api/parse-file.js.map +1 -0
- package/dist/lib/api/parse-in-batches.d.ts +2 -2
- package/dist/lib/api/parse-in-batches.d.ts.map +1 -1
- package/dist/lib/api/parse-in-batches.js +6 -4
- package/dist/lib/api/parse-in-batches.js.map +1 -1
- package/dist/lib/api/parse-sync.d.ts +2 -2
- package/dist/lib/api/parse-sync.d.ts.map +1 -1
- package/dist/lib/api/parse-sync.js +10 -1
- package/dist/lib/api/parse-sync.js.map +1 -1
- package/dist/lib/api/parse.d.ts +2 -2
- package/dist/lib/api/parse.d.ts.map +1 -1
- package/dist/lib/api/parse.js +28 -16
- package/dist/lib/api/parse.js.map +1 -1
- package/dist/lib/api/preload.d.ts +11 -0
- package/dist/lib/api/preload.d.ts.map +1 -0
- package/dist/lib/api/preload.js +14 -0
- package/dist/lib/api/preload.js.map +1 -0
- package/dist/lib/api/register-loaders.js +1 -1
- package/dist/lib/api/register-loaders.js.map +1 -1
- package/dist/lib/api/select-loader.d.ts.map +1 -1
- package/dist/lib/api/select-loader.js +48 -5
- package/dist/lib/api/select-loader.js.map +1 -1
- package/dist/lib/api/select-source.d.ts +3 -3
- package/dist/lib/api/select-source.d.ts.map +1 -1
- package/dist/lib/api/select-source.js +2 -5
- package/dist/lib/api/select-source.js.map +1 -1
- package/dist/lib/fetch/fetch-error-message.js +1 -1
- package/dist/lib/fetch/fetch-error-message.js.map +1 -1
- package/dist/lib/init.js +1 -1
- package/dist/lib/init.js.map +1 -1
- package/dist/lib/loader-utils/check-errors.js +1 -1
- package/dist/lib/loader-utils/check-errors.js.map +1 -1
- package/dist/lib/loader-utils/get-data.d.ts +4 -0
- package/dist/lib/loader-utils/get-data.d.ts.map +1 -1
- package/dist/lib/loader-utils/get-data.js +26 -0
- package/dist/lib/loader-utils/get-data.js.map +1 -1
- package/dist/lib/loader-utils/get-fetch-function.d.ts +1 -1
- package/dist/lib/loader-utils/get-fetch-function.d.ts.map +1 -1
- package/dist/lib/loader-utils/get-fetch-function.js +1 -1
- package/dist/lib/loader-utils/get-fetch-function.js.map +1 -1
- package/dist/lib/loader-utils/loader-context.d.ts +1 -1
- package/dist/lib/loader-utils/loader-context.d.ts.map +1 -1
- package/dist/lib/loader-utils/loader-context.js +3 -1
- package/dist/lib/loader-utils/loader-context.js.map +1 -1
- package/dist/lib/loader-utils/loggers.d.ts +19 -0
- package/dist/lib/loader-utils/loggers.d.ts.map +1 -1
- package/dist/lib/loader-utils/loggers.js +28 -2
- package/dist/lib/loader-utils/loggers.js.map +1 -1
- package/dist/lib/loader-utils/option-defaults.d.ts +1 -0
- package/dist/lib/loader-utils/option-defaults.d.ts.map +1 -1
- package/dist/lib/loader-utils/option-defaults.js +2 -0
- package/dist/lib/loader-utils/option-defaults.js.map +1 -1
- package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
- package/dist/lib/loader-utils/option-utils.js +50 -2
- package/dist/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/lib/utils/response-utils.js +3 -3
- package/dist/lib/utils/response-utils.js.map +1 -1
- package/dist/null-loader.d.ts.map +1 -1
- package/dist/null-loader.js +1 -1
- package/dist/null-loader.js.map +1 -1
- package/dist/null-worker-node.js +199 -36
- package/dist/null-worker.js +199 -36
- package/package.json +6 -6
- package/src/index.ts +10 -1
- package/src/iterators/make-iterator/make-stream-iterator.ts +47 -9
- package/src/lib/api/core-api.ts +25 -0
- package/src/lib/api/create-data-source.ts +24 -24
- package/src/lib/api/load-in-batches.ts +16 -11
- package/src/lib/api/load-loader.ts +152 -0
- package/src/lib/api/load.ts +98 -5
- package/src/lib/api/parse-file.ts +143 -0
- package/src/lib/api/parse-in-batches.ts +13 -5
- package/src/lib/api/parse-sync.ts +27 -2
- package/src/lib/api/parse.ts +49 -18
- package/src/lib/api/preload.ts +31 -0
- package/src/lib/api/register-loaders.ts +1 -1
- package/src/lib/api/select-loader.ts +57 -5
- package/src/lib/api/select-source.ts +7 -10
- package/src/lib/fetch/fetch-error-message.ts +1 -1
- package/src/lib/loader-utils/check-errors.ts +1 -1
- package/src/lib/loader-utils/get-data.ts +36 -0
- package/src/lib/loader-utils/get-fetch-function.ts +3 -2
- package/src/lib/loader-utils/loader-context.ts +5 -2
- package/src/lib/loader-utils/loggers.ts +28 -2
- package/src/lib/loader-utils/option-defaults.ts +2 -0
- package/src/lib/loader-utils/option-utils.ts +59 -2
- package/src/lib/utils/response-utils.ts +3 -3
- package/src/null-loader.ts +3 -3
package/dist/index.cjs
CHANGED
|
@@ -18,21 +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
|
-
_selectSource: () =>
|
|
30
|
+
_selectSource: () => selectSource,
|
|
31
31
|
_unregisterLoaders: () => _unregisterLoaders,
|
|
32
|
-
assert: () =>
|
|
33
|
-
concatenateArrayBuffersAsync: () =>
|
|
32
|
+
assert: () => assert,
|
|
33
|
+
concatenateArrayBuffersAsync: () => concatenateArrayBuffersAsync,
|
|
34
|
+
coreApi: () => coreApi,
|
|
34
35
|
createDataSource: () => createDataSource,
|
|
35
|
-
document: () =>
|
|
36
|
+
document: () => document_,
|
|
36
37
|
encode: () => encode,
|
|
37
38
|
encodeInBatches: () => encodeInBatches,
|
|
38
39
|
encodeSync: () => encodeSync,
|
|
@@ -43,48 +44,1553 @@ __export(dist_exports, {
|
|
|
43
44
|
encodeTextSync: () => encodeTextSync,
|
|
44
45
|
encodeURLtoURL: () => encodeURLtoURL,
|
|
45
46
|
fetchFile: () => fetchFile,
|
|
46
|
-
forEach: () =>
|
|
47
|
+
forEach: () => forEach,
|
|
47
48
|
getLoaderOptions: () => getGlobalLoaderOptions,
|
|
48
|
-
getPathPrefix: () =>
|
|
49
|
-
global: () =>
|
|
50
|
-
isAsyncIterable: () =>
|
|
51
|
-
isBrowser: () =>
|
|
52
|
-
isIterable: () =>
|
|
53
|
-
isIterator: () =>
|
|
54
|
-
isPromise: () =>
|
|
55
|
-
isPureObject: () =>
|
|
56
|
-
isReadableStream: () =>
|
|
57
|
-
isResponse: () =>
|
|
58
|
-
isWorker: () =>
|
|
59
|
-
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,
|
|
60
61
|
load: () => load,
|
|
61
62
|
loadInBatches: () => loadInBatches,
|
|
62
63
|
makeIterator: () => makeIterator,
|
|
63
|
-
makeLineIterator: () =>
|
|
64
|
-
makeNumberedLineIterator: () =>
|
|
64
|
+
makeLineIterator: () => makeLineIterator,
|
|
65
|
+
makeNumberedLineIterator: () => makeNumberedLineIterator,
|
|
65
66
|
makeStream: () => makeStream,
|
|
66
|
-
makeTextDecoderIterator: () =>
|
|
67
|
-
makeTextEncoderIterator: () =>
|
|
67
|
+
makeTextDecoderIterator: () => makeTextDecoderIterator,
|
|
68
|
+
makeTextEncoderIterator: () => makeTextEncoderIterator,
|
|
68
69
|
parse: () => parse,
|
|
70
|
+
parseFile: () => parseFile,
|
|
69
71
|
parseInBatches: () => parseInBatches,
|
|
70
72
|
parseSync: () => parseSync,
|
|
73
|
+
preload: () => preload,
|
|
74
|
+
preloadSync: () => preloadSync,
|
|
71
75
|
readArrayBuffer: () => readArrayBuffer,
|
|
72
76
|
registerLoaders: () => registerLoaders,
|
|
73
|
-
resolvePath: () =>
|
|
77
|
+
resolvePath: () => resolvePath,
|
|
74
78
|
selectLoader: () => selectLoader,
|
|
75
79
|
selectLoaderSync: () => selectLoaderSync,
|
|
76
|
-
self: () =>
|
|
80
|
+
self: () => self_,
|
|
77
81
|
setLoaderOptions: () => setGlobalOptions,
|
|
78
|
-
setPathPrefix: () =>
|
|
79
|
-
window: () =>
|
|
82
|
+
setPathPrefix: () => setPathPrefix,
|
|
83
|
+
window: () => window_
|
|
80
84
|
});
|
|
81
|
-
module.exports = __toCommonJS(
|
|
85
|
+
module.exports = __toCommonJS(index_exports);
|
|
82
86
|
|
|
83
|
-
//
|
|
84
|
-
|
|
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
|
+
}
|
|
85
93
|
|
|
86
|
-
//
|
|
87
|
-
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
|
+
}
|
|
88
1594
|
|
|
89
1595
|
// dist/lib/fetch/fetch-error.js
|
|
90
1596
|
var FetchError = class extends Error {
|
|
@@ -102,9 +1608,6 @@ var FetchError = class extends Error {
|
|
|
102
1608
|
response;
|
|
103
1609
|
};
|
|
104
1610
|
|
|
105
|
-
// dist/lib/utils/resource-utils.js
|
|
106
|
-
var import_loader_utils = require("@loaders.gl/loader-utils");
|
|
107
|
-
|
|
108
1611
|
// dist/lib/utils/mime-type-utils.js
|
|
109
1612
|
var DATA_URL_PATTERN = /^data:([-\w.]+\/[-\w.+]+)(;|,)/;
|
|
110
1613
|
var MIME_TYPE_PATTERN = /^([-\w.]+\/[-\w.+]+)/;
|
|
@@ -115,16 +1618,16 @@ function compareMIMETypes(mimeType1, mimeType2) {
|
|
|
115
1618
|
return false;
|
|
116
1619
|
}
|
|
117
1620
|
function parseMIMEType(mimeString) {
|
|
118
|
-
const
|
|
119
|
-
if (
|
|
120
|
-
return
|
|
1621
|
+
const matches3 = MIME_TYPE_PATTERN.exec(mimeString);
|
|
1622
|
+
if (matches3) {
|
|
1623
|
+
return matches3[1];
|
|
121
1624
|
}
|
|
122
1625
|
return mimeString;
|
|
123
1626
|
}
|
|
124
1627
|
function parseMIMETypeFromURL(url) {
|
|
125
|
-
const
|
|
126
|
-
if (
|
|
127
|
-
return
|
|
1628
|
+
const matches3 = DATA_URL_PATTERN.exec(url);
|
|
1629
|
+
if (matches3) {
|
|
1630
|
+
return matches3[1];
|
|
128
1631
|
}
|
|
129
1632
|
return "";
|
|
130
1633
|
}
|
|
@@ -132,8 +1635,8 @@ function parseMIMETypeFromURL(url) {
|
|
|
132
1635
|
// dist/lib/utils/url-utils.js
|
|
133
1636
|
var QUERY_STRING_PATTERN = /\?.*/;
|
|
134
1637
|
function extractQueryString(url) {
|
|
135
|
-
const
|
|
136
|
-
return
|
|
1638
|
+
const matches3 = url.match(QUERY_STRING_PATTERN);
|
|
1639
|
+
return matches3 && matches3[0];
|
|
137
1640
|
}
|
|
138
1641
|
function stripQueryString(url) {
|
|
139
1642
|
return url.replace(QUERY_STRING_PATTERN, "");
|
|
@@ -149,10 +1652,10 @@ function shortenUrlForDisplay(url) {
|
|
|
149
1652
|
|
|
150
1653
|
// dist/lib/utils/resource-utils.js
|
|
151
1654
|
function getResourceUrl(resource) {
|
|
152
|
-
if (
|
|
1655
|
+
if (isResponse(resource)) {
|
|
153
1656
|
return resource.url;
|
|
154
1657
|
}
|
|
155
|
-
if (
|
|
1658
|
+
if (isBlob(resource)) {
|
|
156
1659
|
const fileName = "name" in resource ? resource.name : "";
|
|
157
1660
|
return fileName || "";
|
|
158
1661
|
}
|
|
@@ -162,12 +1665,12 @@ function getResourceUrl(resource) {
|
|
|
162
1665
|
return "";
|
|
163
1666
|
}
|
|
164
1667
|
function getResourceMIMEType(resource) {
|
|
165
|
-
if (
|
|
1668
|
+
if (isResponse(resource)) {
|
|
166
1669
|
const contentTypeHeader = resource.headers.get("content-type") || "";
|
|
167
1670
|
const noQueryUrl = stripQueryString(resource.url);
|
|
168
1671
|
return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);
|
|
169
1672
|
}
|
|
170
|
-
if (
|
|
1673
|
+
if (isBlob(resource)) {
|
|
171
1674
|
return resource.type || "";
|
|
172
1675
|
}
|
|
173
1676
|
if (typeof resource === "string") {
|
|
@@ -176,11 +1679,11 @@ function getResourceMIMEType(resource) {
|
|
|
176
1679
|
return "";
|
|
177
1680
|
}
|
|
178
1681
|
function getResourceContentLength(resource) {
|
|
179
|
-
if (
|
|
1682
|
+
if (isResponse(resource)) {
|
|
180
1683
|
const response = resource;
|
|
181
1684
|
return response.headers["content-length"] || -1;
|
|
182
1685
|
}
|
|
183
|
-
if (
|
|
1686
|
+
if (isBlob(resource)) {
|
|
184
1687
|
const blob = resource;
|
|
185
1688
|
return blob.size;
|
|
186
1689
|
}
|
|
@@ -198,7 +1701,7 @@ function getResourceContentLength(resource) {
|
|
|
198
1701
|
|
|
199
1702
|
// dist/lib/utils/response-utils.js
|
|
200
1703
|
async function makeResponse(resource) {
|
|
201
|
-
if (
|
|
1704
|
+
if (isResponse(resource)) {
|
|
202
1705
|
return resource;
|
|
203
1706
|
}
|
|
204
1707
|
const headers = {};
|
|
@@ -240,7 +1743,7 @@ async function getResponseError(response) {
|
|
|
240
1743
|
try {
|
|
241
1744
|
const contentType = response.headers.get("Content-Type");
|
|
242
1745
|
info.reason = !response.bodyUsed && (contentType == null ? void 0 : contentType.includes("application/json")) ? await response.json() : await response.text();
|
|
243
|
-
} catch (
|
|
1746
|
+
} catch (_error) {
|
|
244
1747
|
}
|
|
245
1748
|
return new FetchError(message, info);
|
|
246
1749
|
}
|
|
@@ -251,11 +1754,11 @@ async function getInitialDataUrl(resource) {
|
|
|
251
1754
|
}
|
|
252
1755
|
if (resource instanceof Blob) {
|
|
253
1756
|
const blobSlice = resource.slice(0, 5);
|
|
254
|
-
return await new Promise((
|
|
1757
|
+
return await new Promise((resolve2) => {
|
|
255
1758
|
const reader = new FileReader();
|
|
256
1759
|
reader.onload = (event) => {
|
|
257
1760
|
var _a;
|
|
258
|
-
return
|
|
1761
|
+
return resolve2((_a = event == null ? void 0 : event.target) == null ? void 0 : _a.result);
|
|
259
1762
|
};
|
|
260
1763
|
reader.readAsDataURL(blobSlice);
|
|
261
1764
|
});
|
|
@@ -289,7 +1792,7 @@ function isDataURL(url) {
|
|
|
289
1792
|
async function fetchFile(urlOrData, fetchOptions) {
|
|
290
1793
|
var _a, _b;
|
|
291
1794
|
if (typeof urlOrData === "string") {
|
|
292
|
-
const url =
|
|
1795
|
+
const url = resolvePath(urlOrData);
|
|
293
1796
|
if (isNodePath(url)) {
|
|
294
1797
|
if ((_a = globalThis.loaders) == null ? void 0 : _a.fetchNode) {
|
|
295
1798
|
return (_b = globalThis.loaders) == null ? void 0 : _b.fetchNode(url, fetchOptions);
|
|
@@ -309,62 +1812,85 @@ async function readArrayBuffer(file, start, length) {
|
|
|
309
1812
|
return await readBlob(slice);
|
|
310
1813
|
}
|
|
311
1814
|
async function readBlob(blob) {
|
|
312
|
-
return await new Promise((
|
|
1815
|
+
return await new Promise((resolve2, reject) => {
|
|
313
1816
|
const fileReader = new FileReader();
|
|
314
1817
|
fileReader.onload = (event) => {
|
|
315
1818
|
var _a;
|
|
316
|
-
return
|
|
1819
|
+
return resolve2((_a = event == null ? void 0 : event.target) == null ? void 0 : _a.result);
|
|
317
1820
|
};
|
|
318
1821
|
fileReader.onerror = (error) => reject(error);
|
|
319
1822
|
fileReader.readAsArrayBuffer(blob);
|
|
320
1823
|
});
|
|
321
1824
|
}
|
|
322
1825
|
|
|
323
|
-
// dist/lib/loader-utils/option-utils.js
|
|
324
|
-
var import_loader_utils5 = require("@loaders.gl/loader-utils");
|
|
325
|
-
|
|
326
1826
|
// dist/lib/loader-utils/loggers.js
|
|
327
|
-
var
|
|
328
|
-
var probeLog = new
|
|
1827
|
+
var import_log3 = require("@probe.gl/log");
|
|
1828
|
+
var probeLog = new import_log3.Log({ id: "loaders.gl" });
|
|
329
1829
|
var NullLog = class {
|
|
1830
|
+
/** Drops a log message. */
|
|
330
1831
|
log() {
|
|
331
1832
|
return () => {
|
|
332
1833
|
};
|
|
333
1834
|
}
|
|
1835
|
+
/** Drops an info message. */
|
|
334
1836
|
info() {
|
|
335
1837
|
return () => {
|
|
336
1838
|
};
|
|
337
1839
|
}
|
|
1840
|
+
/** Logs one message once; no-op for the null logger. */
|
|
1841
|
+
once() {
|
|
1842
|
+
return () => {
|
|
1843
|
+
};
|
|
1844
|
+
}
|
|
1845
|
+
/** Drops a warning message. */
|
|
338
1846
|
warn() {
|
|
339
1847
|
return () => {
|
|
340
1848
|
};
|
|
341
1849
|
}
|
|
1850
|
+
/** Drops an error message. */
|
|
342
1851
|
error() {
|
|
343
1852
|
return () => {
|
|
344
1853
|
};
|
|
345
1854
|
}
|
|
346
1855
|
};
|
|
347
1856
|
var ConsoleLog = class {
|
|
1857
|
+
/** Console-like object used for message output. */
|
|
348
1858
|
console;
|
|
1859
|
+
/** Messages already emitted through `once`. */
|
|
1860
|
+
onceMessages = /* @__PURE__ */ new Set();
|
|
1861
|
+
/** Creates a console-backed logger. */
|
|
349
1862
|
constructor() {
|
|
350
1863
|
this.console = console;
|
|
351
1864
|
}
|
|
1865
|
+
/** Logs a message to the console. */
|
|
352
1866
|
log(...args) {
|
|
353
1867
|
return this.console.log.bind(this.console, ...args);
|
|
354
1868
|
}
|
|
1869
|
+
/** Logs an informational message to the console. */
|
|
355
1870
|
info(...args) {
|
|
356
1871
|
return this.console.info.bind(this.console, ...args);
|
|
357
1872
|
}
|
|
1873
|
+
/** Logs one message once to the console. */
|
|
1874
|
+
once(...args) {
|
|
1875
|
+
const message = String(args[0]);
|
|
1876
|
+
if (this.onceMessages.has(message)) {
|
|
1877
|
+
return () => {
|
|
1878
|
+
};
|
|
1879
|
+
}
|
|
1880
|
+
this.onceMessages.add(message);
|
|
1881
|
+
return this.console.info.bind(this.console, ...args);
|
|
1882
|
+
}
|
|
1883
|
+
/** Logs a warning message to the console. */
|
|
358
1884
|
warn(...args) {
|
|
359
1885
|
return this.console.warn.bind(this.console, ...args);
|
|
360
1886
|
}
|
|
1887
|
+
/** Logs an error message to the console. */
|
|
361
1888
|
error(...args) {
|
|
362
1889
|
return this.console.error.bind(this.console, ...args);
|
|
363
1890
|
}
|
|
364
1891
|
};
|
|
365
1892
|
|
|
366
1893
|
// dist/lib/loader-utils/option-defaults.js
|
|
367
|
-
var import_loader_utils4 = require("@loaders.gl/loader-utils");
|
|
368
1894
|
var DEFAULT_LOADER_OPTIONS = {
|
|
369
1895
|
core: {
|
|
370
1896
|
baseUrl: void 0,
|
|
@@ -374,6 +1900,7 @@ var DEFAULT_LOADER_OPTIONS = {
|
|
|
374
1900
|
fallbackMimeType: void 0,
|
|
375
1901
|
ignoreRegisteredLoaders: void 0,
|
|
376
1902
|
nothrow: false,
|
|
1903
|
+
shape: void 0,
|
|
377
1904
|
log: new ConsoleLog(),
|
|
378
1905
|
// A probe.gl compatible (`log.log()()` syntax) that just logs to console
|
|
379
1906
|
useLocalLibraries: false,
|
|
@@ -384,7 +1911,7 @@ var DEFAULT_LOADER_OPTIONS = {
|
|
|
384
1911
|
// How many worker instances should be created for each loader.
|
|
385
1912
|
maxMobileConcurrency: 1,
|
|
386
1913
|
// How many worker instances should be created for each loader on mobile devices.
|
|
387
|
-
reuseWorkers:
|
|
1914
|
+
reuseWorkers: isBrowser,
|
|
388
1915
|
// By default reuse workers in browser (Node.js refuses to terminate if browsers are running)
|
|
389
1916
|
_nodeWorkers: false,
|
|
390
1917
|
// By default do not support node workers
|
|
@@ -419,6 +1946,7 @@ var REMOVED_LOADER_OPTIONS = {
|
|
|
419
1946
|
_worker: "core._workerType",
|
|
420
1947
|
limit: "core.limit",
|
|
421
1948
|
_limitMB: "core._limitMB",
|
|
1949
|
+
shape: "core.shape",
|
|
422
1950
|
batchSize: "core.batchSize",
|
|
423
1951
|
batchDebounceMs: "core.batchDebounceMs",
|
|
424
1952
|
metadata: "core.metadata",
|
|
@@ -457,10 +1985,12 @@ var CORE_LOADER_OPTION_KEYS = [
|
|
|
457
1985
|
"maxConcurrency",
|
|
458
1986
|
"maxMobileConcurrency",
|
|
459
1987
|
"reuseWorkers",
|
|
1988
|
+
"workerTransferBufferCopy",
|
|
460
1989
|
"_nodeWorkers",
|
|
461
1990
|
"_workerType",
|
|
462
1991
|
"limit",
|
|
463
1992
|
"_limitMB",
|
|
1993
|
+
"shape",
|
|
464
1994
|
"batchSize",
|
|
465
1995
|
"batchDebounceMs",
|
|
466
1996
|
"metadata",
|
|
@@ -486,7 +2016,7 @@ function setGlobalOptions(options) {
|
|
|
486
2016
|
const state = getGlobalLoaderState();
|
|
487
2017
|
const globalOptions = getGlobalLoaderOptions();
|
|
488
2018
|
state.globalOptions = normalizeOptionsInternal(globalOptions, options);
|
|
489
|
-
|
|
2019
|
+
registerJSModules(options.modules);
|
|
490
2020
|
}
|
|
491
2021
|
function normalizeOptions(options, loader, loaders, url) {
|
|
492
2022
|
loaders = loaders || [];
|
|
@@ -520,7 +2050,7 @@ function validateOptionsObject(options, id, defaultOptions, deprecatedOptions, l
|
|
|
520
2050
|
const loaderName = id || "Top level";
|
|
521
2051
|
const prefix = id ? `${id}.` : "";
|
|
522
2052
|
for (const key in options) {
|
|
523
|
-
const isSubOptions = !id &&
|
|
2053
|
+
const isSubOptions = !id && isObject(options[key]);
|
|
524
2054
|
const isBaseUriOption = key === "baseUri" && !id;
|
|
525
2055
|
const isWorkerUrlOption = key === "workerUrl" && id;
|
|
526
2056
|
if (!(key in defaultOptions) && !isBaseUriOption && !isWorkerUrlOption) {
|
|
@@ -568,15 +2098,40 @@ function normalizeOptionsInternal(loader, options, url) {
|
|
|
568
2098
|
mergeNestedFields(mergedOptions, normalizeLoaderOptions(getGlobalLoaderOptions()));
|
|
569
2099
|
const userOptions = normalizeLoaderOptions(options);
|
|
570
2100
|
mergeNestedFields(mergedOptions, userOptions);
|
|
2101
|
+
applyCoreShapeDefault(mergedOptions, userOptions, loader);
|
|
571
2102
|
addUrlOptions(mergedOptions, url);
|
|
572
2103
|
addDeprecatedTopLevelOptions(mergedOptions);
|
|
573
2104
|
return mergedOptions;
|
|
574
2105
|
}
|
|
2106
|
+
function applyCoreShapeDefault(mergedOptions, userOptions, loader) {
|
|
2107
|
+
var _a, _b;
|
|
2108
|
+
const coreShape = (_a = mergedOptions.core) == null ? void 0 : _a.shape;
|
|
2109
|
+
if (coreShape === void 0) {
|
|
2110
|
+
return;
|
|
2111
|
+
}
|
|
2112
|
+
const loaderScopedDefaults = (_b = loader.options) == null ? void 0 : _b[loader.id];
|
|
2113
|
+
if (!isPureObject(loaderScopedDefaults) || !("shape" in loaderScopedDefaults)) {
|
|
2114
|
+
return;
|
|
2115
|
+
}
|
|
2116
|
+
const globalLoaderScopedOptions = getGlobalLoaderOptions()[loader.id];
|
|
2117
|
+
if (isPureObject(globalLoaderScopedOptions) && "shape" in globalLoaderScopedOptions) {
|
|
2118
|
+
return;
|
|
2119
|
+
}
|
|
2120
|
+
const userLoaderScopedOptions = userOptions[loader.id];
|
|
2121
|
+
if (isPureObject(userLoaderScopedOptions) && "shape" in userLoaderScopedOptions) {
|
|
2122
|
+
return;
|
|
2123
|
+
}
|
|
2124
|
+
const loaderScopedOptions = mergedOptions[loader.id];
|
|
2125
|
+
mergedOptions[loader.id] = {
|
|
2126
|
+
...isPureObject(loaderScopedOptions) ? loaderScopedOptions : {},
|
|
2127
|
+
shape: coreShape
|
|
2128
|
+
};
|
|
2129
|
+
}
|
|
575
2130
|
function mergeNestedFields(mergedOptions, options) {
|
|
576
2131
|
for (const key in options) {
|
|
577
2132
|
if (key in options) {
|
|
578
2133
|
const value = options[key];
|
|
579
|
-
if (
|
|
2134
|
+
if (isPureObject(value) && isPureObject(mergedOptions[key])) {
|
|
580
2135
|
mergedOptions[key] = {
|
|
581
2136
|
...mergedOptions[key],
|
|
582
2137
|
...options[key]
|
|
@@ -595,7 +2150,7 @@ function addUrlOptions(options, url) {
|
|
|
595
2150
|
const hasCoreBaseUrl = ((_a = options.core) == null ? void 0 : _a.baseUrl) !== void 0;
|
|
596
2151
|
if (!hasCoreBaseUrl) {
|
|
597
2152
|
options.core ||= {};
|
|
598
|
-
options.core.baseUrl =
|
|
2153
|
+
options.core.baseUrl = path_exports.dirname(stripQueryString(url));
|
|
599
2154
|
}
|
|
600
2155
|
}
|
|
601
2156
|
function cloneLoaderOptions(options) {
|
|
@@ -614,7 +2169,8 @@ function moveDeprecatedTopLevelOptionsToCore(options) {
|
|
|
614
2169
|
}
|
|
615
2170
|
for (const key of CORE_LOADER_OPTION_KEYS) {
|
|
616
2171
|
if (options[key] !== void 0) {
|
|
617
|
-
|
|
2172
|
+
options.core ||= {};
|
|
2173
|
+
const coreOptions = options.core;
|
|
618
2174
|
const coreRecord = coreOptions;
|
|
619
2175
|
if (coreRecord[key] === void 0) {
|
|
620
2176
|
coreRecord[key] = options[key];
|
|
@@ -642,7 +2198,6 @@ function addDeprecatedTopLevelOptions(options) {
|
|
|
642
2198
|
}
|
|
643
2199
|
|
|
644
2200
|
// dist/lib/loader-utils/normalize-loader.js
|
|
645
|
-
var import_loader_utils6 = require("@loaders.gl/loader-utils");
|
|
646
2201
|
function isLoaderObject(loader) {
|
|
647
2202
|
if (!loader) {
|
|
648
2203
|
return false;
|
|
@@ -654,8 +2209,8 @@ function isLoaderObject(loader) {
|
|
|
654
2209
|
return hasExtensions;
|
|
655
2210
|
}
|
|
656
2211
|
function normalizeLoader(loader) {
|
|
657
|
-
|
|
658
|
-
|
|
2212
|
+
assert(loader, "null loader");
|
|
2213
|
+
assert(isLoaderObject(loader), "invalid loader");
|
|
659
2214
|
let options;
|
|
660
2215
|
if (Array.isArray(loader)) {
|
|
661
2216
|
options = loader[1];
|
|
@@ -699,7 +2254,6 @@ function _unregisterLoaders() {
|
|
|
699
2254
|
}
|
|
700
2255
|
|
|
701
2256
|
// dist/lib/api/select-loader.js
|
|
702
|
-
var import_loader_utils7 = require("@loaders.gl/loader-utils");
|
|
703
2257
|
var EXT_PATTERN = /\.([^.]+)$/;
|
|
704
2258
|
async function selectLoader(data, loaders = [], options, context) {
|
|
705
2259
|
if (!validHTTPResponse(data)) {
|
|
@@ -718,7 +2272,7 @@ async function selectLoader(data, loaders = [], options, context) {
|
|
|
718
2272
|
if (loader) {
|
|
719
2273
|
return loader;
|
|
720
2274
|
}
|
|
721
|
-
if (
|
|
2275
|
+
if (isBlob(data)) {
|
|
722
2276
|
data = await data.slice(0, 10).arrayBuffer();
|
|
723
2277
|
loader = selectLoaderSync(data, loaders, normalizedOptions, context);
|
|
724
2278
|
}
|
|
@@ -765,22 +2319,33 @@ function selectLoaderInternal(data, loaders, options, context) {
|
|
|
765
2319
|
const testUrl = stripQueryString(url) || (context == null ? void 0 : context.url);
|
|
766
2320
|
let loader = null;
|
|
767
2321
|
let reason = "";
|
|
2322
|
+
const sourceType = (options == null ? void 0 : options.core) && "type" in options.core ? options.core.type : void 0;
|
|
2323
|
+
if (sourceType && sourceType !== "auto") {
|
|
2324
|
+
loader = findSourceLoaderByType(loaders, sourceType);
|
|
2325
|
+
reason = loader ? `match forced by supplied source type ${sourceType}` : "";
|
|
2326
|
+
}
|
|
768
2327
|
if ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a.mimeType) {
|
|
769
2328
|
loader = findLoaderByMIMEType(loaders, (_b = options == null ? void 0 : options.core) == null ? void 0 : _b.mimeType);
|
|
770
2329
|
reason = `match forced by supplied MIME type ${(_c = options == null ? void 0 : options.core) == null ? void 0 : _c.mimeType}`;
|
|
771
2330
|
}
|
|
2331
|
+
loader = loader || findSourceLoaderByTestURL(loaders, testUrl);
|
|
2332
|
+
reason = reason || (loader ? `matched source url ${testUrl}` : "");
|
|
772
2333
|
loader = loader || findLoaderByUrl(loaders, testUrl);
|
|
773
2334
|
reason = reason || (loader ? `matched url ${testUrl}` : "");
|
|
774
2335
|
loader = loader || findLoaderByMIMEType(loaders, type);
|
|
775
2336
|
reason = reason || (loader ? `matched MIME type ${type}` : "");
|
|
776
2337
|
loader = loader || findLoaderByInitialBytes(loaders, data);
|
|
777
2338
|
reason = reason || (loader ? `matched initial data ${getFirstCharacters(data)}` : "");
|
|
2339
|
+
if (!loader && isBlob(data)) {
|
|
2340
|
+
loader = findSourceLoaderByTestData(loaders, data);
|
|
2341
|
+
reason = reason || (loader ? "matched source testData" : "");
|
|
2342
|
+
}
|
|
778
2343
|
if ((_d = options == null ? void 0 : options.core) == null ? void 0 : _d.fallbackMimeType) {
|
|
779
2344
|
loader = loader || findLoaderByMIMEType(loaders, (_e = options == null ? void 0 : options.core) == null ? void 0 : _e.fallbackMimeType);
|
|
780
2345
|
reason = reason || (loader ? `matched fallback MIME type ${type}` : "");
|
|
781
2346
|
}
|
|
782
2347
|
if (reason) {
|
|
783
|
-
|
|
2348
|
+
log.log(1, `selectLoader selected ${loader == null ? void 0 : loader.name}: ${reason}.`);
|
|
784
2349
|
}
|
|
785
2350
|
return loader;
|
|
786
2351
|
}
|
|
@@ -796,7 +2361,7 @@ function getNoValidLoaderMessage(data) {
|
|
|
796
2361
|
const url = getResourceUrl(data);
|
|
797
2362
|
const type = getResourceMIMEType(data);
|
|
798
2363
|
let message = "No valid loader found (";
|
|
799
|
-
message += url ? `${
|
|
2364
|
+
message += url ? `${path_exports.filename(url)}, ` : "no url provided, ";
|
|
800
2365
|
message += `MIME type: ${type ? `"${type}"` : "not provided"}, `;
|
|
801
2366
|
const firstCharacters = data ? getFirstCharacters(data) : "";
|
|
802
2367
|
message += firstCharacters ? ` first bytes: "${firstCharacters}"` : "first bytes: not available";
|
|
@@ -808,16 +2373,46 @@ function normalizeLoaders(loaders) {
|
|
|
808
2373
|
normalizeLoader(loader);
|
|
809
2374
|
}
|
|
810
2375
|
}
|
|
811
|
-
function findLoaderByUrl(loaders, url) {
|
|
812
|
-
const match = url && EXT_PATTERN.exec(url);
|
|
813
|
-
const extension = match && match[1];
|
|
814
|
-
return extension ? findLoaderByExtension(loaders, extension) : null;
|
|
815
|
-
}
|
|
816
|
-
function findLoaderByExtension(loaders, extension) {
|
|
817
|
-
extension = extension.toLowerCase();
|
|
2376
|
+
function findLoaderByUrl(loaders, url) {
|
|
2377
|
+
const match = url && EXT_PATTERN.exec(url);
|
|
2378
|
+
const extension = match && match[1];
|
|
2379
|
+
return extension ? findLoaderByExtension(loaders, extension) : null;
|
|
2380
|
+
}
|
|
2381
|
+
function findLoaderByExtension(loaders, extension) {
|
|
2382
|
+
extension = extension.toLowerCase();
|
|
2383
|
+
for (const loader of loaders) {
|
|
2384
|
+
for (const loaderExtension of loader.extensions) {
|
|
2385
|
+
if (loaderExtension.toLowerCase() === extension) {
|
|
2386
|
+
return loader;
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
return null;
|
|
2391
|
+
}
|
|
2392
|
+
function findSourceLoaderByType(loaders, type) {
|
|
2393
|
+
for (const loader of loaders) {
|
|
2394
|
+
if (isSourceLoader(loader) && loader.type === type) {
|
|
2395
|
+
return loader;
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
return null;
|
|
2399
|
+
}
|
|
2400
|
+
function findSourceLoaderByTestURL(loaders, url) {
|
|
2401
|
+
if (!url) {
|
|
2402
|
+
return null;
|
|
2403
|
+
}
|
|
2404
|
+
for (const loader of loaders) {
|
|
2405
|
+
if (isSourceLoader(loader) && loader.testURL(url)) {
|
|
2406
|
+
return loader;
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
return null;
|
|
2410
|
+
}
|
|
2411
|
+
function findSourceLoaderByTestData(loaders, data) {
|
|
2412
|
+
var _a;
|
|
818
2413
|
for (const loader of loaders) {
|
|
819
|
-
|
|
820
|
-
if (
|
|
2414
|
+
if (isSourceLoader(loader)) {
|
|
2415
|
+
if ((_a = loader.testData) == null ? void 0 : _a.call(loader, data)) {
|
|
821
2416
|
return loader;
|
|
822
2417
|
}
|
|
823
2418
|
}
|
|
@@ -870,12 +2465,12 @@ function testDataAgainstBinary(data, byteOffset, loader) {
|
|
|
870
2465
|
return tests.some((test) => testBinary(data, byteOffset, loader, test));
|
|
871
2466
|
}
|
|
872
2467
|
function testBinary(data, byteOffset, loader, test) {
|
|
873
|
-
if (
|
|
874
|
-
return
|
|
2468
|
+
if (isArrayBufferLike(test)) {
|
|
2469
|
+
return compareArrayBuffers(test, data, test.byteLength);
|
|
875
2470
|
}
|
|
876
2471
|
switch (typeof test) {
|
|
877
2472
|
case "function":
|
|
878
|
-
return test(
|
|
2473
|
+
return test(ensureArrayBuffer(data));
|
|
879
2474
|
case "string":
|
|
880
2475
|
const magic = getMagicString(data, byteOffset, test.length);
|
|
881
2476
|
return test === magic;
|
|
@@ -906,15 +2501,7 @@ function getMagicString(arrayBuffer, byteOffset, length) {
|
|
|
906
2501
|
return magic;
|
|
907
2502
|
}
|
|
908
2503
|
|
|
909
|
-
// dist/lib/api/parse.js
|
|
910
|
-
var import_loader_utils14 = require("@loaders.gl/loader-utils");
|
|
911
|
-
var import_worker_utils = require("@loaders.gl/worker-utils");
|
|
912
|
-
|
|
913
|
-
// dist/lib/loader-utils/get-data.js
|
|
914
|
-
var import_loader_utils11 = require("@loaders.gl/loader-utils");
|
|
915
|
-
|
|
916
2504
|
// dist/iterators/make-iterator/make-string-iterator.js
|
|
917
|
-
var import_loader_utils8 = require("@loaders.gl/loader-utils");
|
|
918
2505
|
var DEFAULT_CHUNK_SIZE = 256 * 1024;
|
|
919
2506
|
function* makeStringIterator(string, options) {
|
|
920
2507
|
const chunkSize = (options == null ? void 0 : options.chunkSize) || DEFAULT_CHUNK_SIZE;
|
|
@@ -924,7 +2511,7 @@ function* makeStringIterator(string, options) {
|
|
|
924
2511
|
const chunkLength = Math.min(string.length - offset, chunkSize);
|
|
925
2512
|
const chunk = string.slice(offset, offset + chunkLength);
|
|
926
2513
|
offset += chunkLength;
|
|
927
|
-
yield
|
|
2514
|
+
yield ensureArrayBuffer(textEncoder.encode(chunk));
|
|
928
2515
|
}
|
|
929
2516
|
}
|
|
930
2517
|
|
|
@@ -958,37 +2545,72 @@ async function* makeBlobIterator(blob, options) {
|
|
|
958
2545
|
}
|
|
959
2546
|
|
|
960
2547
|
// dist/iterators/make-iterator/make-stream-iterator.js
|
|
961
|
-
var import_loader_utils9 = require("@loaders.gl/loader-utils");
|
|
962
2548
|
function makeStreamIterator(stream, options) {
|
|
963
|
-
return
|
|
2549
|
+
return isBrowser ? makeBrowserStreamIterator(stream, options) : makeNodeStreamIterator(stream, options);
|
|
964
2550
|
}
|
|
965
2551
|
async function* makeBrowserStreamIterator(stream, options) {
|
|
966
2552
|
const reader = stream.getReader();
|
|
967
2553
|
let nextBatchPromise;
|
|
2554
|
+
let streamFinished = false;
|
|
2555
|
+
let streamReadFailed = false;
|
|
2556
|
+
let iteratorFailed = false;
|
|
968
2557
|
try {
|
|
969
2558
|
while (true) {
|
|
970
2559
|
const currentBatchPromise = nextBatchPromise || reader.read();
|
|
971
|
-
|
|
972
|
-
|
|
2560
|
+
nextBatchPromise = void 0;
|
|
2561
|
+
let batch;
|
|
2562
|
+
try {
|
|
2563
|
+
batch = await currentBatchPromise;
|
|
2564
|
+
} catch (error) {
|
|
2565
|
+
streamReadFailed = true;
|
|
2566
|
+
throw error;
|
|
973
2567
|
}
|
|
974
|
-
const { done, value } =
|
|
2568
|
+
const { done, value } = batch;
|
|
975
2569
|
if (done) {
|
|
2570
|
+
streamFinished = true;
|
|
976
2571
|
return;
|
|
977
2572
|
}
|
|
978
|
-
|
|
2573
|
+
if (options == null ? void 0 : options._streamReadAhead) {
|
|
2574
|
+
nextBatchPromise = reader.read();
|
|
2575
|
+
void nextBatchPromise.catch(() => {
|
|
2576
|
+
});
|
|
2577
|
+
}
|
|
2578
|
+
yield toArrayBuffer2(value);
|
|
979
2579
|
}
|
|
980
2580
|
} catch (error) {
|
|
981
|
-
|
|
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;
|
|
2604
|
+
}
|
|
982
2605
|
}
|
|
983
2606
|
}
|
|
984
2607
|
async function* makeNodeStreamIterator(stream, options) {
|
|
985
2608
|
for await (const chunk of stream) {
|
|
986
|
-
yield (
|
|
2609
|
+
yield toArrayBuffer2(chunk);
|
|
987
2610
|
}
|
|
988
2611
|
}
|
|
989
2612
|
|
|
990
2613
|
// dist/iterators/make-iterator/make-iterator.js
|
|
991
|
-
var import_loader_utils10 = require("@loaders.gl/loader-utils");
|
|
992
2614
|
function makeIterator(data, options) {
|
|
993
2615
|
if (typeof data === "string") {
|
|
994
2616
|
return makeStringIterator(data, options);
|
|
@@ -996,13 +2618,13 @@ function makeIterator(data, options) {
|
|
|
996
2618
|
if (data instanceof ArrayBuffer) {
|
|
997
2619
|
return makeArrayBufferIterator(data, options);
|
|
998
2620
|
}
|
|
999
|
-
if (
|
|
2621
|
+
if (isBlob(data)) {
|
|
1000
2622
|
return makeBlobIterator(data, options);
|
|
1001
2623
|
}
|
|
1002
|
-
if (
|
|
2624
|
+
if (isReadableStream(data)) {
|
|
1003
2625
|
return makeStreamIterator(data, options);
|
|
1004
2626
|
}
|
|
1005
|
-
if (
|
|
2627
|
+
if (isResponse(data)) {
|
|
1006
2628
|
const responseBody = data.body;
|
|
1007
2629
|
if (!responseBody) {
|
|
1008
2630
|
throw new Error("Readable stream not available on Response");
|
|
@@ -1018,46 +2640,68 @@ function getArrayBufferOrStringFromDataSync(data, loader, options) {
|
|
|
1018
2640
|
if (loader.text && typeof data === "string") {
|
|
1019
2641
|
return data;
|
|
1020
2642
|
}
|
|
1021
|
-
if (
|
|
2643
|
+
if (isBuffer(data)) {
|
|
1022
2644
|
data = data.buffer;
|
|
1023
2645
|
}
|
|
1024
|
-
if (
|
|
1025
|
-
const bufferSource =
|
|
2646
|
+
if (isArrayBufferLike(data)) {
|
|
2647
|
+
const bufferSource = toArrayBufferView(data);
|
|
1026
2648
|
if (loader.text && !loader.binary) {
|
|
1027
2649
|
const textDecoder = new TextDecoder("utf8");
|
|
1028
2650
|
return textDecoder.decode(bufferSource);
|
|
1029
2651
|
}
|
|
1030
|
-
return (
|
|
2652
|
+
return toArrayBuffer2(bufferSource);
|
|
1031
2653
|
}
|
|
1032
2654
|
throw new Error(ERR_DATA);
|
|
1033
2655
|
}
|
|
1034
2656
|
async function getArrayBufferOrStringFromData(data, loader, options) {
|
|
1035
|
-
if (typeof data === "string" ||
|
|
2657
|
+
if (typeof data === "string" || isArrayBufferLike(data)) {
|
|
1036
2658
|
return getArrayBufferOrStringFromDataSync(data, loader, options);
|
|
1037
2659
|
}
|
|
1038
|
-
if (
|
|
2660
|
+
if (isBlob(data)) {
|
|
1039
2661
|
data = await makeResponse(data);
|
|
1040
2662
|
}
|
|
1041
|
-
if (
|
|
2663
|
+
if (isResponse(data)) {
|
|
1042
2664
|
await checkResponse(data);
|
|
1043
2665
|
return loader.binary ? await data.arrayBuffer() : await data.text();
|
|
1044
2666
|
}
|
|
1045
|
-
if (
|
|
2667
|
+
if (isReadableStream(data)) {
|
|
2668
|
+
data = makeIterator(data, options);
|
|
2669
|
+
}
|
|
2670
|
+
if (isIterable(data) || isAsyncIterable(data)) {
|
|
2671
|
+
return concatenateArrayBuffersAsync(data);
|
|
2672
|
+
}
|
|
2673
|
+
throw new Error(ERR_DATA);
|
|
2674
|
+
}
|
|
2675
|
+
async function getArrayBufferFromData(data, options) {
|
|
2676
|
+
if (typeof data === "string") {
|
|
2677
|
+
return new TextEncoder().encode(data).buffer;
|
|
2678
|
+
}
|
|
2679
|
+
if (isArrayBufferLike(data)) {
|
|
2680
|
+
return toArrayBuffer2(toArrayBufferView(data));
|
|
2681
|
+
}
|
|
2682
|
+
if (isBlob(data)) {
|
|
2683
|
+
data = await makeResponse(data);
|
|
2684
|
+
}
|
|
2685
|
+
if (isResponse(data)) {
|
|
2686
|
+
await checkResponse(data);
|
|
2687
|
+
return await data.arrayBuffer();
|
|
2688
|
+
}
|
|
2689
|
+
if (isReadableStream(data)) {
|
|
1046
2690
|
data = makeIterator(data, options);
|
|
1047
2691
|
}
|
|
1048
|
-
if (
|
|
1049
|
-
return
|
|
2692
|
+
if (isIterable(data) || isAsyncIterable(data)) {
|
|
2693
|
+
return concatenateArrayBuffersAsync(data);
|
|
1050
2694
|
}
|
|
1051
2695
|
throw new Error(ERR_DATA);
|
|
1052
2696
|
}
|
|
1053
2697
|
async function getAsyncIterableFromData(data, options) {
|
|
1054
|
-
if (
|
|
2698
|
+
if (isPromise(data)) {
|
|
1055
2699
|
data = await data;
|
|
1056
2700
|
}
|
|
1057
|
-
if (
|
|
2701
|
+
if (isIterator(data)) {
|
|
1058
2702
|
return data;
|
|
1059
2703
|
}
|
|
1060
|
-
if (
|
|
2704
|
+
if (isResponse(data)) {
|
|
1061
2705
|
await checkResponse(data);
|
|
1062
2706
|
const body = await data.body;
|
|
1063
2707
|
if (!body) {
|
|
@@ -1065,39 +2709,38 @@ async function getAsyncIterableFromData(data, options) {
|
|
|
1065
2709
|
}
|
|
1066
2710
|
return makeIterator(body, options);
|
|
1067
2711
|
}
|
|
1068
|
-
if (
|
|
2712
|
+
if (isBlob(data) || isReadableStream(data)) {
|
|
1069
2713
|
return makeIterator(data, options);
|
|
1070
2714
|
}
|
|
1071
|
-
if (
|
|
2715
|
+
if (isAsyncIterable(data)) {
|
|
1072
2716
|
return data;
|
|
1073
2717
|
}
|
|
1074
|
-
if (
|
|
2718
|
+
if (isIterable(data)) {
|
|
1075
2719
|
return data;
|
|
1076
2720
|
}
|
|
1077
2721
|
return getIterableFromData(data);
|
|
1078
2722
|
}
|
|
1079
2723
|
function getIterableFromData(data) {
|
|
1080
2724
|
if (ArrayBuffer.isView(data)) {
|
|
1081
|
-
return function* oneChunk() {
|
|
1082
|
-
yield (
|
|
1083
|
-
}();
|
|
2725
|
+
return (function* oneChunk() {
|
|
2726
|
+
yield toArrayBuffer2(data);
|
|
2727
|
+
})();
|
|
1084
2728
|
}
|
|
1085
|
-
if (
|
|
1086
|
-
return function* oneChunk() {
|
|
1087
|
-
yield (
|
|
1088
|
-
}();
|
|
2729
|
+
if (isArrayBufferLike(data)) {
|
|
2730
|
+
return (function* oneChunk() {
|
|
2731
|
+
yield toArrayBuffer2(data);
|
|
2732
|
+
})();
|
|
1089
2733
|
}
|
|
1090
|
-
if (
|
|
2734
|
+
if (isIterator(data)) {
|
|
1091
2735
|
return data;
|
|
1092
2736
|
}
|
|
1093
|
-
if (
|
|
2737
|
+
if (isIterable(data)) {
|
|
1094
2738
|
return data[Symbol.iterator]();
|
|
1095
2739
|
}
|
|
1096
2740
|
throw new Error(ERR_DATA);
|
|
1097
2741
|
}
|
|
1098
2742
|
|
|
1099
2743
|
// dist/lib/loader-utils/get-fetch-function.js
|
|
1100
|
-
var import_loader_utils12 = require("@loaders.gl/loader-utils");
|
|
1101
2744
|
function getFetchFunction(options, context) {
|
|
1102
2745
|
var _a;
|
|
1103
2746
|
const globalOptions = getGlobalLoaderOptions();
|
|
@@ -1106,7 +2749,7 @@ function getFetchFunction(options, context) {
|
|
|
1106
2749
|
if (typeof fetchOption === "function") {
|
|
1107
2750
|
return fetchOption;
|
|
1108
2751
|
}
|
|
1109
|
-
if (
|
|
2752
|
+
if (isObject(fetchOption)) {
|
|
1110
2753
|
return (url) => fetchFile(url, fetchOption);
|
|
1111
2754
|
}
|
|
1112
2755
|
if (context == null ? void 0 : context.fetch) {
|
|
@@ -1115,92 +2758,147 @@ function getFetchFunction(options, context) {
|
|
|
1115
2758
|
return fetchFile;
|
|
1116
2759
|
}
|
|
1117
2760
|
|
|
1118
|
-
// dist/lib/
|
|
1119
|
-
var
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
2761
|
+
// dist/lib/api/load-loader.js
|
|
2762
|
+
var loaderImplementationPromises = /* @__PURE__ */ new Map();
|
|
2763
|
+
var loaderImplementations = /* @__PURE__ */ new Map();
|
|
2764
|
+
async function getLoaderImplementation(loader, options, url) {
|
|
2765
|
+
var _a;
|
|
2766
|
+
if (isLoaderWithParser(loader)) {
|
|
2767
|
+
return loader;
|
|
1123
2768
|
}
|
|
1124
|
-
const
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
2769
|
+
const implementationCacheKey = getLoaderImplementationCacheKey(loader, options);
|
|
2770
|
+
const loaderImplementation = (_a = loaderImplementations.get(loader)) == null ? void 0 : _a.get(implementationCacheKey);
|
|
2771
|
+
if (loaderImplementation) {
|
|
2772
|
+
return loaderImplementation;
|
|
2773
|
+
}
|
|
2774
|
+
let loaderImplementationPromisesForLoader = loaderImplementationPromises.get(loader);
|
|
2775
|
+
if (!loaderImplementationPromisesForLoader) {
|
|
2776
|
+
loaderImplementationPromisesForLoader = /* @__PURE__ */ new Map();
|
|
2777
|
+
loaderImplementationPromises.set(loader, loaderImplementationPromisesForLoader);
|
|
2778
|
+
}
|
|
2779
|
+
let loaderImplementationPromise = loaderImplementationPromisesForLoader.get(implementationCacheKey);
|
|
2780
|
+
if (!loaderImplementationPromise) {
|
|
2781
|
+
loaderImplementationPromise = resolveLoaderImplementation(loader, options, url).then((implementation) => {
|
|
2782
|
+
let loaderImplementationsForLoader = loaderImplementations.get(loader);
|
|
2783
|
+
if (!loaderImplementationsForLoader) {
|
|
2784
|
+
loaderImplementationsForLoader = /* @__PURE__ */ new Map();
|
|
2785
|
+
loaderImplementations.set(loader, loaderImplementationsForLoader);
|
|
2786
|
+
}
|
|
2787
|
+
loaderImplementationsForLoader.set(implementationCacheKey, implementation);
|
|
2788
|
+
return implementation;
|
|
2789
|
+
}).catch((error) => {
|
|
2790
|
+
loaderImplementationPromisesForLoader.delete(implementationCacheKey);
|
|
2791
|
+
if (loaderImplementationPromisesForLoader.size === 0) {
|
|
2792
|
+
loaderImplementationPromises.delete(loader);
|
|
2793
|
+
}
|
|
2794
|
+
throw error;
|
|
2795
|
+
});
|
|
2796
|
+
loaderImplementationPromisesForLoader.set(implementationCacheKey, loaderImplementationPromise);
|
|
1134
2797
|
}
|
|
1135
|
-
|
|
1136
|
-
|
|
2798
|
+
return await loaderImplementationPromise;
|
|
2799
|
+
}
|
|
2800
|
+
function getLoaderImplementationSync(loader) {
|
|
2801
|
+
var _a;
|
|
2802
|
+
if (isLoaderWithParser(loader)) {
|
|
2803
|
+
return loader;
|
|
1137
2804
|
}
|
|
1138
|
-
|
|
2805
|
+
const implementationCacheKey = getLoaderImplementationCacheKey(loader);
|
|
2806
|
+
return ((_a = loaderImplementations.get(loader)) == null ? void 0 : _a.get(implementationCacheKey)) || null;
|
|
1139
2807
|
}
|
|
1140
|
-
function
|
|
1141
|
-
|
|
1142
|
-
|
|
2808
|
+
function isLoaderWithParser(loader) {
|
|
2809
|
+
const candidate = loader;
|
|
2810
|
+
return Boolean(candidate.parse || candidate.parseSync || candidate.parseInBatches || candidate.parseText || candidate.parseTextSync || candidate.parseFile || candidate.parseFileInBatches);
|
|
2811
|
+
}
|
|
2812
|
+
async function resolveLoaderImplementation(loader, options, url) {
|
|
2813
|
+
if (loader.preload) {
|
|
2814
|
+
const preloadedLoader = await loader.preload(url || "", options);
|
|
2815
|
+
if (isLoaderWithParser(preloadedLoader)) {
|
|
2816
|
+
return preloadedLoader;
|
|
2817
|
+
}
|
|
2818
|
+
throw new Error(`${loader.id} loader preload() did not return a parser-bearing loader`);
|
|
1143
2819
|
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
2820
|
+
const implementationSpecifier = getLoaderImplementationSpecifier(loader, options);
|
|
2821
|
+
return await importLoaderImplementation(implementationSpecifier, loader.id);
|
|
2822
|
+
}
|
|
2823
|
+
function getLoaderImplementationSpecifier(loader, options) {
|
|
2824
|
+
var _a;
|
|
2825
|
+
const workerType = (options == null ? void 0 : options._workerType) || ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a._workerType);
|
|
2826
|
+
if (workerType === "test") {
|
|
2827
|
+
const sourcePath = `modules/${loader.module}/src/${loader.id}-loader.ts`;
|
|
2828
|
+
if (typeof window !== "undefined") {
|
|
2829
|
+
return `/${sourcePath}`;
|
|
2830
|
+
}
|
|
2831
|
+
if (typeof process !== "undefined" && process.cwd) {
|
|
2832
|
+
return new URL(sourcePath, `file://${process.cwd()}/`).toString();
|
|
2833
|
+
}
|
|
2834
|
+
return sourcePath;
|
|
1147
2835
|
}
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
2836
|
+
throw new Error(`${loader.id} loader does not provide a parser implementation. Import a parser-bearing loader directly, or use preload() before parse/load.`);
|
|
2837
|
+
}
|
|
2838
|
+
function getLoaderImplementationCacheKey(loader, options) {
|
|
2839
|
+
var _a;
|
|
2840
|
+
const loaderOptions = options == null ? void 0 : options[loader.id];
|
|
2841
|
+
const defaultLoaderOptions = (_a = loader.options) == null ? void 0 : _a[loader.id];
|
|
2842
|
+
return String((loaderOptions == null ? void 0 : loaderOptions.backend) || (defaultLoaderOptions == null ? void 0 : defaultLoaderOptions.backend) || "");
|
|
2843
|
+
}
|
|
2844
|
+
async function importLoaderImplementation(implementationSpecifier, loaderId) {
|
|
2845
|
+
const moduleExports = await import(
|
|
2846
|
+
/* webpackIgnore: true */
|
|
2847
|
+
/* @vite-ignore */
|
|
2848
|
+
implementationSpecifier
|
|
2849
|
+
);
|
|
2850
|
+
for (const exportValue of Object.values(moduleExports)) {
|
|
2851
|
+
if (exportValue && typeof exportValue === "object" && exportValue.id === loaderId && isLoaderWithParser(exportValue)) {
|
|
2852
|
+
return exportValue;
|
|
2853
|
+
}
|
|
1151
2854
|
}
|
|
1152
|
-
|
|
2855
|
+
throw new Error(`Could not find parser implementation for ${loaderId} in ${implementationSpecifier}`);
|
|
1153
2856
|
}
|
|
1154
2857
|
|
|
1155
|
-
// dist/lib/api/parse.js
|
|
1156
|
-
async function
|
|
2858
|
+
// dist/lib/api/parse-file.js
|
|
2859
|
+
async function parseFile(file, loaders, options, context) {
|
|
1157
2860
|
if (loaders && !Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
1158
2861
|
context = void 0;
|
|
1159
2862
|
options = loaders;
|
|
1160
2863
|
loaders = void 0;
|
|
1161
2864
|
}
|
|
1162
|
-
data = await data;
|
|
1163
2865
|
options = options || {};
|
|
1164
|
-
const url =
|
|
2866
|
+
const url = file.url || "";
|
|
1165
2867
|
const typedLoaders = loaders;
|
|
1166
2868
|
const candidateLoaders = getLoadersFromContext(typedLoaders, context);
|
|
1167
|
-
const loader = await selectLoader(
|
|
2869
|
+
const loader = await selectLoader(url, candidateLoaders, options);
|
|
1168
2870
|
if (!loader) {
|
|
1169
2871
|
return null;
|
|
1170
2872
|
}
|
|
2873
|
+
if (isSourceLoader(loader)) {
|
|
2874
|
+
throw new Error(`${loader.id} is a SourceLoader. Use load() to create a runtime source object instead of parseFile().`);
|
|
2875
|
+
}
|
|
1171
2876
|
const strictOptions = normalizeOptions(options, loader, candidateLoaders, url);
|
|
1172
2877
|
context = getLoaderContext(
|
|
1173
|
-
// @ts-expect-error
|
|
2878
|
+
// @ts-expect-error candidateLoaders may be a single forced loader
|
|
1174
2879
|
{ url, _parse: parse, loaders: candidateLoaders },
|
|
1175
2880
|
strictOptions,
|
|
1176
2881
|
context || null
|
|
1177
2882
|
);
|
|
1178
|
-
return await
|
|
1179
|
-
}
|
|
1180
|
-
async function
|
|
1181
|
-
|
|
1182
|
-
options =
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
return await (
|
|
1195
|
-
}
|
|
1196
|
-
if (loaderWithParser.parseText && typeof data === "string") {
|
|
1197
|
-
return await loaderWithParser.parseText(data, options, context);
|
|
1198
|
-
}
|
|
1199
|
-
if (loaderWithParser.parse) {
|
|
1200
|
-
return await loaderWithParser.parse(data, options, context);
|
|
2883
|
+
return await parseFileWithLoader(loader, file, strictOptions, context);
|
|
2884
|
+
}
|
|
2885
|
+
async function parseFileWithLoader(loader, file, options, context) {
|
|
2886
|
+
validateWorkerVersion(loader);
|
|
2887
|
+
options = mergeOptions(loader.options, options);
|
|
2888
|
+
const loaderWithParser = await getLoaderImplementation(loader, options, context.url);
|
|
2889
|
+
if (loaderWithParser.parseFile) {
|
|
2890
|
+
return await loaderWithParser.parseFile(file, options, context);
|
|
2891
|
+
}
|
|
2892
|
+
const parseFunction = loaderWithParser.parse;
|
|
2893
|
+
if (parseFunction) {
|
|
2894
|
+
const length = file.bigsize > 0n ? Number(file.bigsize) : file.size;
|
|
2895
|
+
if (!length) {
|
|
2896
|
+
throw new Error(`${loader.id} loader - cannot fall back to parse without a file size`);
|
|
2897
|
+
}
|
|
2898
|
+
const data = await file.read(0n, length);
|
|
2899
|
+
return await parse(data, loaderWithParser, options, context);
|
|
1201
2900
|
}
|
|
1202
|
-
|
|
1203
|
-
throw new Error(`${loader.id} loader - no parser found and worker is disabled`);
|
|
2901
|
+
throw new Error(`${loader.id} loader - no file parser found`);
|
|
1204
2902
|
}
|
|
1205
2903
|
|
|
1206
2904
|
// dist/lib/api/parse-sync.js
|
|
@@ -1217,13 +2915,17 @@ function parseSync(data, loaders, options, context) {
|
|
|
1217
2915
|
if (!loader) {
|
|
1218
2916
|
return null;
|
|
1219
2917
|
}
|
|
2918
|
+
if (isSourceLoader(loader)) {
|
|
2919
|
+
throw new Error(`${loader.id} is a SourceLoader. Use load() to create a runtime source object instead of parseSync().`);
|
|
2920
|
+
}
|
|
1220
2921
|
const strictOptions = normalizeOptions(options, loader, candidateLoaders);
|
|
1221
2922
|
const url = getResourceUrl(data);
|
|
1222
2923
|
const parse2 = () => {
|
|
1223
2924
|
throw new Error("parseSync called parse (which is async");
|
|
1224
2925
|
};
|
|
1225
2926
|
context = getLoaderContext({ url, _parseSync: parse2, _parse: parse2, loaders }, strictOptions, context || null);
|
|
1226
|
-
|
|
2927
|
+
const loaderWithParser = getLoaderImplementationSync(loader);
|
|
2928
|
+
return parseWithLoaderSync(loaderWithParser || loader, data, strictOptions, context);
|
|
1227
2929
|
}
|
|
1228
2930
|
function parseWithLoaderSync(loader, data, options, context) {
|
|
1229
2931
|
data = getArrayBufferOrStringFromDataSync(data, loader, options);
|
|
@@ -1233,12 +2935,56 @@ function parseWithLoaderSync(loader, data, options, context) {
|
|
|
1233
2935
|
if (loader.parseSync && data instanceof ArrayBuffer) {
|
|
1234
2936
|
return loader.parseSync(data, options, context);
|
|
1235
2937
|
}
|
|
2938
|
+
if (loader.preload) {
|
|
2939
|
+
throw new Error(`${loader.name} loader: 'parseSync' requires a parser-bearing loader. Import the loader implementation directly, or call preload(loader) before parseSync(). ${context.url || ""}`);
|
|
2940
|
+
}
|
|
1236
2941
|
throw new Error(`${loader.name} loader: 'parseSync' not supported by this loader, use 'parse' instead. ${context.url || ""}`);
|
|
1237
2942
|
}
|
|
1238
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
|
+
|
|
1239
2987
|
// dist/lib/api/parse-in-batches.js
|
|
1240
|
-
var import_schema_utils = require("@loaders.gl/schema-utils");
|
|
1241
|
-
var import_loader_utils15 = require("@loaders.gl/loader-utils");
|
|
1242
2988
|
async function parseInBatches(data, loaders, options, context) {
|
|
1243
2989
|
const loaderArray = Array.isArray(loaders) ? loaders : void 0;
|
|
1244
2990
|
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
@@ -1255,9 +3001,10 @@ async function parseInBatches(data, loaders, options, context) {
|
|
|
1255
3001
|
}
|
|
1256
3002
|
const strictOptions = normalizeOptions(options, loader, loaderArray, url);
|
|
1257
3003
|
context = getLoaderContext({ url, _parseInBatches: parseInBatches, _parse: parse, loaders: loaderArray }, strictOptions, context || null);
|
|
1258
|
-
|
|
3004
|
+
const loaderWithParser = await getLoaderImplementation(loader, strictOptions, context.url);
|
|
3005
|
+
return await parseWithLoaderInBatches(loader, loaderWithParser, data, strictOptions, context);
|
|
1259
3006
|
}
|
|
1260
|
-
async function parseWithLoaderInBatches(loader, data, options, context) {
|
|
3007
|
+
async function parseWithLoaderInBatches(originalLoader, loader, data, options, context) {
|
|
1261
3008
|
var _a;
|
|
1262
3009
|
const outputIterator = await parseToOutputIterator(loader, data, options, context);
|
|
1263
3010
|
if (!((_a = options == null ? void 0 : options.core) == null ? void 0 : _a.metadata)) {
|
|
@@ -1267,7 +3014,7 @@ async function parseWithLoaderInBatches(loader, data, options, context) {
|
|
|
1267
3014
|
shape: "metadata",
|
|
1268
3015
|
batchType: "metadata",
|
|
1269
3016
|
metadata: {
|
|
1270
|
-
_loader:
|
|
3017
|
+
_loader: originalLoader,
|
|
1271
3018
|
_context: context
|
|
1272
3019
|
},
|
|
1273
3020
|
// Populate with some default fields to avoid crashing
|
|
@@ -1290,7 +3037,7 @@ async function parseToOutputIterator(loader, data, options, context) {
|
|
|
1290
3037
|
return parseChunkInBatches(transformedIterator, loader, options, context);
|
|
1291
3038
|
}
|
|
1292
3039
|
async function* parseChunkInBatches(transformedIterator, loader, options, context) {
|
|
1293
|
-
const arrayBuffer = await
|
|
3040
|
+
const arrayBuffer = await concatenateArrayBuffersAsync(transformedIterator);
|
|
1294
3041
|
const parsedData = await parse(
|
|
1295
3042
|
arrayBuffer,
|
|
1296
3043
|
loader,
|
|
@@ -1302,7 +3049,7 @@ async function* parseChunkInBatches(transformedIterator, loader, options, contex
|
|
|
1302
3049
|
yield batch;
|
|
1303
3050
|
}
|
|
1304
3051
|
function convertDataToBatch(parsedData, loader) {
|
|
1305
|
-
const batch =
|
|
3052
|
+
const batch = isTable(parsedData) ? makeBatchFromTable(parsedData) : {
|
|
1306
3053
|
shape: "unknown",
|
|
1307
3054
|
batchType: "data",
|
|
1308
3055
|
data: parsedData,
|
|
@@ -1319,8 +3066,33 @@ async function applyInputTransforms(inputIterator, transforms = []) {
|
|
|
1319
3066
|
return iteratorChain;
|
|
1320
3067
|
}
|
|
1321
3068
|
|
|
3069
|
+
// dist/lib/api/load-in-batches.js
|
|
3070
|
+
function loadInBatches(files, loaders, options, context) {
|
|
3071
|
+
let loadersArray;
|
|
3072
|
+
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
3073
|
+
context = void 0;
|
|
3074
|
+
options = loaders;
|
|
3075
|
+
loadersArray = void 0;
|
|
3076
|
+
} else {
|
|
3077
|
+
loadersArray = loaders;
|
|
3078
|
+
}
|
|
3079
|
+
const fetch2 = getFetchFunction(options || {});
|
|
3080
|
+
if (!Array.isArray(files)) {
|
|
3081
|
+
return loadOneFileInBatches(files, loadersArray, options || {}, fetch2);
|
|
3082
|
+
}
|
|
3083
|
+
const promises = files.map((file) => loadOneFileInBatches(file, loadersArray, options || {}, fetch2));
|
|
3084
|
+
return promises;
|
|
3085
|
+
}
|
|
3086
|
+
async function loadOneFileInBatches(file, loaders, options, fetch2) {
|
|
3087
|
+
if (typeof file === "string") {
|
|
3088
|
+
const url = file;
|
|
3089
|
+
const response = await fetch2(url);
|
|
3090
|
+
return Array.isArray(loaders) ? await parseInBatches(response, loaders, options) : await parseInBatches(response, loaders, options);
|
|
3091
|
+
}
|
|
3092
|
+
return Array.isArray(loaders) ? await parseInBatches(file, loaders, options) : await parseInBatches(file, loaders, options);
|
|
3093
|
+
}
|
|
3094
|
+
|
|
1322
3095
|
// dist/lib/api/load.js
|
|
1323
|
-
var import_loader_utils16 = require("@loaders.gl/loader-utils");
|
|
1324
3096
|
async function load(url, loaders, options, context) {
|
|
1325
3097
|
var _a;
|
|
1326
3098
|
let resolvedLoaders;
|
|
@@ -1333,12 +3105,56 @@ async function load(url, loaders, options, context) {
|
|
|
1333
3105
|
resolvedLoaders = loaders;
|
|
1334
3106
|
resolvedOptions = options;
|
|
1335
3107
|
}
|
|
3108
|
+
if (!Array.isArray(resolvedLoaders) && isSourceLoader(resolvedLoaders)) {
|
|
3109
|
+
const sourceLoader = await resolveSourceLoader(resolvedLoaders, url, resolvedOptions);
|
|
3110
|
+
const runtimeCoreApi = {
|
|
3111
|
+
fetchFile,
|
|
3112
|
+
parse,
|
|
3113
|
+
parseFile,
|
|
3114
|
+
parseSync,
|
|
3115
|
+
parseInBatches,
|
|
3116
|
+
load,
|
|
3117
|
+
loadInBatches
|
|
3118
|
+
};
|
|
3119
|
+
return sourceLoader.createDataSource(url, resolvedOptions || {}, runtimeCoreApi);
|
|
3120
|
+
}
|
|
3121
|
+
if (Array.isArray(resolvedLoaders) && resolvedLoaders.length === 1 && isSourceLoader(resolvedLoaders[0])) {
|
|
3122
|
+
const sourceLoader = await resolveSourceLoader(resolvedLoaders[0], url, resolvedOptions);
|
|
3123
|
+
const runtimeCoreApi = {
|
|
3124
|
+
fetchFile,
|
|
3125
|
+
parse,
|
|
3126
|
+
parseFile,
|
|
3127
|
+
parseSync,
|
|
3128
|
+
parseInBatches,
|
|
3129
|
+
load,
|
|
3130
|
+
loadInBatches
|
|
3131
|
+
};
|
|
3132
|
+
return sourceLoader.createDataSource(url, resolvedOptions || {}, runtimeCoreApi);
|
|
3133
|
+
}
|
|
3134
|
+
if (typeof url === "string" || isBlob(url)) {
|
|
3135
|
+
const selectedLoader = await selectLoader(url, resolvedLoaders, {
|
|
3136
|
+
...resolvedOptions,
|
|
3137
|
+
core: { ...resolvedOptions == null ? void 0 : resolvedOptions.core, nothrow: true }
|
|
3138
|
+
});
|
|
3139
|
+
if (selectedLoader && isSourceLoader(selectedLoader)) {
|
|
3140
|
+
const sourceLoader = await resolveSourceLoader(selectedLoader, url, resolvedOptions);
|
|
3141
|
+
return sourceLoader.createDataSource(url, resolvedOptions || {}, {
|
|
3142
|
+
fetchFile,
|
|
3143
|
+
parse,
|
|
3144
|
+
parseFile,
|
|
3145
|
+
parseSync,
|
|
3146
|
+
parseInBatches,
|
|
3147
|
+
load,
|
|
3148
|
+
loadInBatches
|
|
3149
|
+
});
|
|
3150
|
+
}
|
|
3151
|
+
}
|
|
1336
3152
|
const fetch2 = getFetchFunction(resolvedOptions);
|
|
1337
3153
|
let data = url;
|
|
1338
3154
|
if (typeof url === "string") {
|
|
1339
3155
|
data = await fetch2(url);
|
|
1340
3156
|
}
|
|
1341
|
-
if (
|
|
3157
|
+
if (isBlob(url)) {
|
|
1342
3158
|
data = await fetch2(url);
|
|
1343
3159
|
}
|
|
1344
3160
|
if (typeof url === "string") {
|
|
@@ -1353,44 +3169,146 @@ async function load(url, loaders, options, context) {
|
|
|
1353
3169
|
};
|
|
1354
3170
|
}
|
|
1355
3171
|
}
|
|
1356
|
-
return Array.isArray(resolvedLoaders) ? await parse(data, resolvedLoaders, resolvedOptions) : await parse(data, resolvedLoaders, resolvedOptions);
|
|
3172
|
+
return Array.isArray(resolvedLoaders) ? await parse(data, resolvedLoaders, resolvedOptions, context) : await parse(data, resolvedLoaders, resolvedOptions, context);
|
|
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;
|
|
1357
3183
|
}
|
|
1358
3184
|
|
|
1359
|
-
// dist/lib/api/
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
3185
|
+
// dist/lib/api/core-api.js
|
|
3186
|
+
var coreApi = Object.freeze({
|
|
3187
|
+
fetchFile,
|
|
3188
|
+
parse,
|
|
3189
|
+
parseFile,
|
|
3190
|
+
parseSync,
|
|
3191
|
+
parseInBatches,
|
|
3192
|
+
load,
|
|
3193
|
+
loadInBatches
|
|
3194
|
+
});
|
|
3195
|
+
|
|
3196
|
+
// dist/lib/loader-utils/loader-context.js
|
|
3197
|
+
function getLoaderContext(context, options, parentContext) {
|
|
3198
|
+
if (parentContext) {
|
|
3199
|
+
return parentContext;
|
|
3200
|
+
}
|
|
3201
|
+
const newContext = {
|
|
3202
|
+
...context,
|
|
3203
|
+
fetch: getFetchFunction(options, context),
|
|
3204
|
+
coreApi: context.coreApi || coreApi
|
|
3205
|
+
};
|
|
3206
|
+
if (newContext.url) {
|
|
3207
|
+
const baseUrl = stripQueryString(newContext.url);
|
|
3208
|
+
newContext.baseUrl = baseUrl;
|
|
3209
|
+
newContext.queryString = extractQueryString(newContext.url);
|
|
3210
|
+
newContext.filename = path_exports.filename(baseUrl);
|
|
3211
|
+
newContext.baseUrl = path_exports.dirname(baseUrl);
|
|
3212
|
+
}
|
|
3213
|
+
if (!Array.isArray(newContext.loaders)) {
|
|
3214
|
+
newContext.loaders = null;
|
|
3215
|
+
}
|
|
3216
|
+
return newContext;
|
|
3217
|
+
}
|
|
3218
|
+
function getLoadersFromContext(loaders, context) {
|
|
3219
|
+
if (loaders && !Array.isArray(loaders)) {
|
|
3220
|
+
return loaders;
|
|
3221
|
+
}
|
|
3222
|
+
let candidateLoaders;
|
|
3223
|
+
if (loaders) {
|
|
3224
|
+
candidateLoaders = Array.isArray(loaders) ? loaders : [loaders];
|
|
3225
|
+
}
|
|
3226
|
+
if (context && context.loaders) {
|
|
3227
|
+
const contextLoaders = Array.isArray(context.loaders) ? context.loaders : [context.loaders];
|
|
3228
|
+
candidateLoaders = candidateLoaders ? [...candidateLoaders, ...contextLoaders] : contextLoaders;
|
|
3229
|
+
}
|
|
3230
|
+
return candidateLoaders && candidateLoaders.length ? candidateLoaders : void 0;
|
|
3231
|
+
}
|
|
3232
|
+
|
|
3233
|
+
// dist/lib/api/parse.js
|
|
3234
|
+
async function parse(data, loaders, options, context) {
|
|
3235
|
+
if (loaders && !Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
1363
3236
|
context = void 0;
|
|
1364
3237
|
options = loaders;
|
|
1365
|
-
|
|
1366
|
-
} else {
|
|
1367
|
-
loadersArray = loaders;
|
|
3238
|
+
loaders = void 0;
|
|
1368
3239
|
}
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
3240
|
+
data = await data;
|
|
3241
|
+
options = options || {};
|
|
3242
|
+
const url = getResourceUrl(data);
|
|
3243
|
+
const typedLoaders = loaders;
|
|
3244
|
+
const candidateLoaders = getLoadersFromContext(typedLoaders, context);
|
|
3245
|
+
const loader = await selectLoader(data, candidateLoaders, options);
|
|
3246
|
+
if (!loader) {
|
|
3247
|
+
return null;
|
|
1372
3248
|
}
|
|
1373
|
-
|
|
1374
|
-
|
|
3249
|
+
if (isSourceLoader(loader)) {
|
|
3250
|
+
throw new Error(`${loader.id} is a SourceLoader. Use load() to create a runtime source object instead of parse().`);
|
|
3251
|
+
}
|
|
3252
|
+
const strictOptions = normalizeOptions(options, loader, candidateLoaders, url);
|
|
3253
|
+
context = getLoaderContext(
|
|
3254
|
+
// @ts-expect-error
|
|
3255
|
+
{ url, _parse: parse, loaders: candidateLoaders },
|
|
3256
|
+
strictOptions,
|
|
3257
|
+
context || null
|
|
3258
|
+
);
|
|
3259
|
+
return await parseWithLoader(loader, data, strictOptions, context);
|
|
1375
3260
|
}
|
|
1376
|
-
async function
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
3261
|
+
async function parseWithLoader(loader, data, options, context) {
|
|
3262
|
+
validateWorkerVersion(loader);
|
|
3263
|
+
options = mergeOptions(loader.options, options);
|
|
3264
|
+
if (isResponse(data)) {
|
|
3265
|
+
const { ok, redirected, status, statusText, type, url } = data;
|
|
3266
|
+
const headers = Object.fromEntries(data.headers.entries());
|
|
3267
|
+
context.response = { headers, ok, redirected, status, statusText, type, url };
|
|
1381
3268
|
}
|
|
1382
|
-
|
|
3269
|
+
const loaderWithParser = await getLoaderImplementation(loader, options, context.url);
|
|
3270
|
+
if (canParseWithWorker(loaderWithParser, options)) {
|
|
3271
|
+
data = await getArrayBufferFromData(data, options);
|
|
3272
|
+
return await parseWithWorker(loaderWithParser, data, options, context, parse);
|
|
3273
|
+
}
|
|
3274
|
+
if (isBlob(data) && loaderWithParser.parseBlob) {
|
|
3275
|
+
return await loaderWithParser.parseBlob(data, options, context);
|
|
3276
|
+
}
|
|
3277
|
+
data = await getArrayBufferOrStringFromData(data, loader, options);
|
|
3278
|
+
return await parseWithLoaderImplementation(loaderWithParser, data, options, context);
|
|
3279
|
+
}
|
|
3280
|
+
async function parseWithLoaderImplementation(loader, data, options, context) {
|
|
3281
|
+
if (loader.parseText && typeof data === "string") {
|
|
3282
|
+
return await loader.parseText(data, options, context);
|
|
3283
|
+
}
|
|
3284
|
+
if (loader.parseTextSync && typeof data === "string") {
|
|
3285
|
+
return loader.parseTextSync(data, options, context);
|
|
3286
|
+
}
|
|
3287
|
+
if (loader.parse) {
|
|
3288
|
+
return await loader.parse(data, options, context);
|
|
3289
|
+
}
|
|
3290
|
+
if (loader.parseSync) {
|
|
3291
|
+
throw new Error(`${loader.name} loader: 'parse' not available on parser-bearing sync loader. Add an async 'parse' function to this loader, or call preload(loader) before parseSync(). ${context.url || ""}`);
|
|
3292
|
+
}
|
|
3293
|
+
throw new Error(`${loader.id} loader - no parser found and worker is disabled`);
|
|
3294
|
+
}
|
|
3295
|
+
|
|
3296
|
+
// dist/lib/api/preload.js
|
|
3297
|
+
async function preload(loader, options, url) {
|
|
3298
|
+
return await getLoaderImplementation(loader, options, url);
|
|
3299
|
+
}
|
|
3300
|
+
function preloadSync(loader) {
|
|
3301
|
+
return getLoaderImplementationSync(loader);
|
|
1383
3302
|
}
|
|
1384
3303
|
|
|
1385
3304
|
// dist/lib/api/encode-table.js
|
|
1386
|
-
var import_loader_utils17 = require("@loaders.gl/loader-utils");
|
|
1387
3305
|
async function encodeTable(data, writer, options) {
|
|
1388
3306
|
if (writer.encode) {
|
|
1389
3307
|
return await writer.encode(data, options);
|
|
1390
3308
|
}
|
|
1391
3309
|
if (writer.encodeText) {
|
|
1392
3310
|
const text = await writer.encodeText(data, options);
|
|
1393
|
-
return
|
|
3311
|
+
return ensureArrayBuffer(new TextEncoder().encode(text));
|
|
1394
3312
|
}
|
|
1395
3313
|
if (writer.encodeInBatches) {
|
|
1396
3314
|
const batches = encodeTableInBatches(data, writer, options);
|
|
@@ -1398,7 +3316,7 @@ async function encodeTable(data, writer, options) {
|
|
|
1398
3316
|
for await (const batch of batches) {
|
|
1399
3317
|
chunks.push(batch);
|
|
1400
3318
|
}
|
|
1401
|
-
return
|
|
3319
|
+
return concatenateArrayBuffers(...chunks);
|
|
1402
3320
|
}
|
|
1403
3321
|
throw new Error("Writer could not encode data");
|
|
1404
3322
|
}
|
|
@@ -1425,16 +3343,14 @@ function getIterator(data) {
|
|
|
1425
3343
|
}
|
|
1426
3344
|
|
|
1427
3345
|
// dist/lib/api/encode.js
|
|
1428
|
-
var import_loader_utils18 = require("@loaders.gl/loader-utils");
|
|
1429
|
-
var import_worker_utils2 = require("@loaders.gl/worker-utils");
|
|
1430
3346
|
async function encode(data, writer, options_) {
|
|
1431
3347
|
const globalOptions = getGlobalLoaderOptions();
|
|
1432
3348
|
const options = { ...globalOptions, ...options_ };
|
|
1433
3349
|
if (writer.encodeURLtoURL) {
|
|
1434
3350
|
return encodeWithCommandLineTool(writer, data, options);
|
|
1435
3351
|
}
|
|
1436
|
-
if (
|
|
1437
|
-
return await
|
|
3352
|
+
if (canEncodeWithWorker(writer, options)) {
|
|
3353
|
+
return await processOnWorker(writer, data, options);
|
|
1438
3354
|
}
|
|
1439
3355
|
return await writer.encode(data, options);
|
|
1440
3356
|
}
|
|
@@ -1443,7 +3359,7 @@ function encodeSync(data, writer, options) {
|
|
|
1443
3359
|
return writer.encodeSync(data, options);
|
|
1444
3360
|
}
|
|
1445
3361
|
if (writer.encodeTextSync) {
|
|
1446
|
-
return
|
|
3362
|
+
return ensureArrayBuffer(new TextEncoder().encode(writer.encodeTextSync(data, options)));
|
|
1447
3363
|
}
|
|
1448
3364
|
throw new Error(`Writer ${writer.name} could not synchronously encode data`);
|
|
1449
3365
|
}
|
|
@@ -1478,20 +3394,20 @@ function encodeInBatches(data, writer, options) {
|
|
|
1478
3394
|
throw new Error(`Writer ${writer.name} could not encode in batches`);
|
|
1479
3395
|
}
|
|
1480
3396
|
async function encodeURLtoURL(inputUrl, outputUrl, writer, options) {
|
|
1481
|
-
inputUrl =
|
|
1482
|
-
outputUrl =
|
|
1483
|
-
if (
|
|
3397
|
+
inputUrl = resolvePath(inputUrl);
|
|
3398
|
+
outputUrl = resolvePath(outputUrl);
|
|
3399
|
+
if (isBrowser || !writer.encodeURLtoURL) {
|
|
1484
3400
|
throw new Error();
|
|
1485
3401
|
}
|
|
1486
3402
|
const outputFilename = await writer.encodeURLtoURL(inputUrl, outputUrl, options);
|
|
1487
3403
|
return outputFilename;
|
|
1488
3404
|
}
|
|
1489
3405
|
async function encodeWithCommandLineTool(writer, data, options) {
|
|
1490
|
-
if (
|
|
3406
|
+
if (isBrowser) {
|
|
1491
3407
|
throw new Error(`Writer ${writer.name} not supported in browser`);
|
|
1492
3408
|
}
|
|
1493
3409
|
const tmpInputFilename = getTemporaryFilename("input");
|
|
1494
|
-
const file = new
|
|
3410
|
+
const file = new NodeFileFacade(tmpInputFilename, "w");
|
|
1495
3411
|
await file.write(data);
|
|
1496
3412
|
const tmpOutputFilename = getTemporaryFilename("output");
|
|
1497
3413
|
const outputFilename = await encodeURLtoURL(tmpInputFilename, tmpOutputFilename, writer, options);
|
|
@@ -1502,27 +3418,25 @@ function getIterator2(data) {
|
|
|
1502
3418
|
const dataIterator = [{ ...data, start: 0, end: data.length }];
|
|
1503
3419
|
return dataIterator;
|
|
1504
3420
|
}
|
|
1505
|
-
function getTemporaryFilename(
|
|
1506
|
-
return `/tmp/${
|
|
3421
|
+
function getTemporaryFilename(filename2) {
|
|
3422
|
+
return `/tmp/${filename2}`;
|
|
1507
3423
|
}
|
|
1508
3424
|
|
|
1509
3425
|
// dist/lib/api/create-data-source.js
|
|
1510
3426
|
function createDataSource(data, sources, options) {
|
|
1511
3427
|
var _a;
|
|
1512
|
-
const
|
|
1513
|
-
const
|
|
3428
|
+
const resolvedOptions = options || {};
|
|
3429
|
+
const type = ((_a = resolvedOptions == null ? void 0 : resolvedOptions.core) == null ? void 0 : _a.type) || resolvedOptions.type || "auto";
|
|
3430
|
+
const source = sources.length === 1 ? sources[0] : type === "auto" ? selectLoaderSync(data, sources, {
|
|
3431
|
+
// `createDataSource` supports non-fetch inputs such as in-memory tables.
|
|
3432
|
+
// Selection remains best-effort for those cases.
|
|
3433
|
+
...resolvedOptions,
|
|
3434
|
+
core: { ...resolvedOptions == null ? void 0 : resolvedOptions.core, type: "auto" }
|
|
3435
|
+
}) : getSourceOfType(type, sources);
|
|
1514
3436
|
if (!source) {
|
|
1515
3437
|
throw new Error("Not a valid source type");
|
|
1516
3438
|
}
|
|
1517
|
-
return source.createDataSource(data,
|
|
1518
|
-
}
|
|
1519
|
-
function selectSource(url, sources) {
|
|
1520
|
-
for (const service of sources) {
|
|
1521
|
-
if (service.testURL && service.testURL(url)) {
|
|
1522
|
-
return service;
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
return null;
|
|
3439
|
+
return source.createDataSource(data, resolvedOptions, coreApi);
|
|
1526
3440
|
}
|
|
1527
3441
|
function getSourceOfType(type, sources) {
|
|
1528
3442
|
for (const service of sources) {
|
|
@@ -1534,15 +3448,11 @@ function getSourceOfType(type, sources) {
|
|
|
1534
3448
|
}
|
|
1535
3449
|
|
|
1536
3450
|
// dist/lib/api/select-source.js
|
|
1537
|
-
function
|
|
3451
|
+
function selectSource(url, sources, options) {
|
|
1538
3452
|
const type = (options == null ? void 0 : options.type) || "auto";
|
|
1539
3453
|
let selectedSource = null;
|
|
1540
3454
|
if (type === "auto") {
|
|
1541
|
-
|
|
1542
|
-
if (typeof url === "string" && source.testURL && source.testURL(url)) {
|
|
1543
|
-
return source;
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
3455
|
+
selectedSource = selectLoaderSync(url, sources, { core: { nothrow: true } });
|
|
1546
3456
|
} else {
|
|
1547
3457
|
selectedSource = getSourceOfType2(type, sources);
|
|
1548
3458
|
}
|
|
@@ -1560,10 +3470,6 @@ function getSourceOfType2(type, sources) {
|
|
|
1560
3470
|
return null;
|
|
1561
3471
|
}
|
|
1562
3472
|
|
|
1563
|
-
// dist/index.js
|
|
1564
|
-
var import_loader_utils20 = require("@loaders.gl/loader-utils");
|
|
1565
|
-
var import_loader_utils21 = require("@loaders.gl/loader-utils");
|
|
1566
|
-
|
|
1567
3473
|
// dist/iterators/make-stream/make-stream.js
|
|
1568
3474
|
function makeStream(source, options) {
|
|
1569
3475
|
if (globalThis.loaders.makeNodeStream) {
|
|
@@ -1604,14 +3510,14 @@ function makeStream(source, options) {
|
|
|
1604
3510
|
}
|
|
1605
3511
|
|
|
1606
3512
|
// dist/null-loader.js
|
|
1607
|
-
var
|
|
3513
|
+
var VERSION4 = true ? "5.0.0-alpha.2" : "latest";
|
|
1608
3514
|
var NullWorkerLoader = {
|
|
1609
3515
|
dataType: null,
|
|
1610
3516
|
batchType: null,
|
|
1611
3517
|
name: "Null loader",
|
|
1612
3518
|
id: "null",
|
|
1613
3519
|
module: "core",
|
|
1614
|
-
version:
|
|
3520
|
+
version: VERSION4,
|
|
1615
3521
|
worker: true,
|
|
1616
3522
|
mimeTypes: ["application/x.empty"],
|
|
1617
3523
|
extensions: ["null"],
|
|
@@ -1626,7 +3532,7 @@ var NullLoader = {
|
|
|
1626
3532
|
name: "Null loader",
|
|
1627
3533
|
id: "null",
|
|
1628
3534
|
module: "core",
|
|
1629
|
-
version:
|
|
3535
|
+
version: VERSION4,
|
|
1630
3536
|
mimeTypes: ["application/x.empty"],
|
|
1631
3537
|
extensions: ["null"],
|
|
1632
3538
|
parse: async (arrayBuffer, options, context) => parseSync2(arrayBuffer, options || {}, context),
|
|
@@ -1645,9 +3551,6 @@ function parseSync2(arrayBuffer, options, context) {
|
|
|
1645
3551
|
return null;
|
|
1646
3552
|
}
|
|
1647
3553
|
|
|
1648
|
-
// dist/index.js
|
|
1649
|
-
var import_loader_utils22 = require("@loaders.gl/loader-utils");
|
|
1650
|
-
|
|
1651
3554
|
// dist/lib/progress/fetch-progress.js
|
|
1652
3555
|
async function fetchProgress(response, onProgress, onDone = () => {
|
|
1653
3556
|
}, onError = () => {
|
|
@@ -1696,7 +3599,6 @@ async function read(controller, reader, loadedBytes, totalBytes, onProgress, onD
|
|
|
1696
3599
|
}
|
|
1697
3600
|
|
|
1698
3601
|
// dist/lib/filesystems/browser-filesystem.js
|
|
1699
|
-
var import_loader_utils19 = require("@loaders.gl/loader-utils");
|
|
1700
3602
|
var BrowserFileSystem = class {
|
|
1701
3603
|
_fetch;
|
|
1702
3604
|
files = {};
|
|
@@ -1722,13 +3624,13 @@ var BrowserFileSystem = class {
|
|
|
1722
3624
|
* Implementation of fetch against this file system
|
|
1723
3625
|
* Delegates to global fetch for http{s}:// or data://
|
|
1724
3626
|
*/
|
|
1725
|
-
async fetch(
|
|
1726
|
-
if (
|
|
1727
|
-
return this._fetch(
|
|
3627
|
+
async fetch(path, options) {
|
|
3628
|
+
if (path.includes("://")) {
|
|
3629
|
+
return this._fetch(path, options);
|
|
1728
3630
|
}
|
|
1729
|
-
const file = this.files[
|
|
3631
|
+
const file = this.files[path];
|
|
1730
3632
|
if (!file) {
|
|
1731
|
-
return new Response(
|
|
3633
|
+
return new Response(path, { status: 400, statusText: "NOT FOUND" });
|
|
1732
3634
|
}
|
|
1733
3635
|
const headers = new Headers(options == null ? void 0 : options.headers);
|
|
1734
3636
|
const range = headers.get("Range");
|
|
@@ -1738,11 +3640,11 @@ var BrowserFileSystem = class {
|
|
|
1738
3640
|
const end = parseInt(bytes[2]);
|
|
1739
3641
|
const data = await file.slice(start, end).arrayBuffer();
|
|
1740
3642
|
const response2 = new Response(data);
|
|
1741
|
-
Object.defineProperty(response2, "url", { value:
|
|
3643
|
+
Object.defineProperty(response2, "url", { value: path });
|
|
1742
3644
|
return response2;
|
|
1743
3645
|
}
|
|
1744
3646
|
const response = new Response(file);
|
|
1745
|
-
Object.defineProperty(response, "url", { value:
|
|
3647
|
+
Object.defineProperty(response, "url", { value: path });
|
|
1746
3648
|
return response;
|
|
1747
3649
|
}
|
|
1748
3650
|
/**
|
|
@@ -1750,51 +3652,44 @@ var BrowserFileSystem = class {
|
|
|
1750
3652
|
* @param dirname
|
|
1751
3653
|
* @returns
|
|
1752
3654
|
*/
|
|
1753
|
-
async readdir(
|
|
3655
|
+
async readdir(dirname2) {
|
|
1754
3656
|
const files = [];
|
|
1755
|
-
for (const
|
|
1756
|
-
files.push(
|
|
3657
|
+
for (const path in this.files) {
|
|
3658
|
+
files.push(path);
|
|
1757
3659
|
}
|
|
1758
3660
|
return files;
|
|
1759
3661
|
}
|
|
1760
3662
|
/**
|
|
1761
3663
|
* Return information (size) about files in this file system
|
|
1762
3664
|
*/
|
|
1763
|
-
async stat(
|
|
1764
|
-
const file = this.files[
|
|
3665
|
+
async stat(path, options) {
|
|
3666
|
+
const file = this.files[path];
|
|
1765
3667
|
if (!file) {
|
|
1766
|
-
throw new Error(
|
|
3668
|
+
throw new Error(path);
|
|
1767
3669
|
}
|
|
1768
3670
|
return { size: file.size };
|
|
1769
3671
|
}
|
|
1770
3672
|
/**
|
|
1771
3673
|
* Just removes the file from the list
|
|
1772
3674
|
*/
|
|
1773
|
-
async unlink(
|
|
1774
|
-
delete this.files[
|
|
1775
|
-
delete this.lowerCaseFiles[
|
|
1776
|
-
this.usedFiles[
|
|
3675
|
+
async unlink(path) {
|
|
3676
|
+
delete this.files[path];
|
|
3677
|
+
delete this.lowerCaseFiles[path];
|
|
3678
|
+
this.usedFiles[path] = true;
|
|
1777
3679
|
}
|
|
1778
3680
|
// implements IRandomAccessFileSystem
|
|
1779
3681
|
// RANDOM ACCESS
|
|
1780
3682
|
async openReadableFile(pathname, flags) {
|
|
1781
|
-
return new
|
|
3683
|
+
return new BlobFile(this.files[pathname]);
|
|
1782
3684
|
}
|
|
1783
3685
|
// PRIVATE
|
|
1784
3686
|
// Supports case independent paths, and file usage tracking
|
|
1785
|
-
_getFile(
|
|
1786
|
-
const file = this.files[
|
|
3687
|
+
_getFile(path, used) {
|
|
3688
|
+
const file = this.files[path] || this.lowerCaseFiles[path];
|
|
1787
3689
|
if (file && used) {
|
|
1788
|
-
this.usedFiles[
|
|
3690
|
+
this.usedFiles[path] = true;
|
|
1789
3691
|
}
|
|
1790
3692
|
return file;
|
|
1791
3693
|
}
|
|
1792
3694
|
};
|
|
1793
|
-
|
|
1794
|
-
// dist/index.js
|
|
1795
|
-
var import_loader_utils23 = require("@loaders.gl/loader-utils");
|
|
1796
|
-
var import_loader_utils24 = require("@loaders.gl/loader-utils");
|
|
1797
|
-
var import_loader_utils25 = require("@loaders.gl/loader-utils");
|
|
1798
|
-
var import_loader_utils26 = require("@loaders.gl/loader-utils");
|
|
1799
|
-
var import_loader_utils27 = require("@loaders.gl/loader-utils");
|
|
1800
3695
|
//# sourceMappingURL=index.cjs.map
|