@loaders.gl/core 4.0.0-alpha.4 → 4.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/core-addons/write-file-browser.d.ts +1 -0
- package/dist/core-addons/write-file-browser.d.ts.map +1 -0
- package/dist/dist.min.js +3423 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/iterators/batch-iterators/timed-batch-iterator.d.ts +5 -0
- package/dist/iterators/batch-iterators/timed-batch-iterator.d.ts.map +1 -0
- package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts +9 -0
- package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts.map +1 -0
- package/dist/iterators/make-iterator/make-blob-iterator.d.ts +9 -0
- package/dist/iterators/make-iterator/make-blob-iterator.d.ts.map +1 -0
- package/dist/iterators/make-iterator/make-iterator.d.ts +19 -0
- package/dist/iterators/make-iterator/make-iterator.d.ts.map +1 -0
- package/dist/iterators/make-iterator/make-stream-iterator.d.ts +11 -0
- package/dist/iterators/make-iterator/make-stream-iterator.d.ts.map +1 -0
- package/dist/iterators/make-iterator/make-string-iterator.d.ts +9 -0
- package/dist/iterators/make-iterator/make-string-iterator.d.ts.map +1 -0
- package/dist/iterators/make-stream/make-dom-stream.d.ts +14 -0
- package/dist/iterators/make-stream/make-dom-stream.d.ts.map +1 -0
- package/dist/iterators/make-stream/make-dom-stream.js +1 -1
- package/dist/iterators/make-stream/make-dom-stream.js.map +1 -1
- package/dist/iterators/make-stream/make-node-stream.d.ts +6 -0
- package/dist/iterators/make-stream/make-node-stream.d.ts.map +1 -0
- package/dist/iterators/make-stream/make-node-stream.js +1 -4
- package/dist/iterators/make-stream/make-node-stream.js.map +1 -1
- package/dist/javascript-utils/is-type.d.ts +22 -0
- package/dist/javascript-utils/is-type.d.ts.map +1 -0
- package/dist/lib/api/encode.d.ts +26 -0
- package/dist/lib/api/encode.d.ts.map +1 -0
- package/dist/lib/api/load-in-batches.d.ts +13 -0
- package/dist/lib/api/load-in-batches.d.ts.map +1 -0
- package/dist/lib/api/load.d.ts +12 -0
- package/dist/lib/api/load.d.ts.map +1 -0
- package/dist/lib/api/parse-in-batches.d.ts +10 -0
- package/dist/lib/api/parse-in-batches.d.ts.map +1 -0
- package/dist/lib/api/parse-sync.d.ts +10 -0
- package/dist/lib/api/parse-sync.d.ts.map +1 -0
- package/dist/lib/api/parse.d.ts +10 -0
- package/dist/lib/api/parse.d.ts.map +1 -0
- package/dist/lib/api/register-loaders.d.ts +7 -0
- package/dist/lib/api/register-loaders.d.ts.map +1 -0
- package/dist/lib/api/save.d.ts +4 -0
- package/dist/lib/api/save.d.ts.map +1 -0
- package/dist/lib/api/select-loader.d.ts +22 -0
- package/dist/lib/api/select-loader.d.ts.map +1 -0
- package/dist/lib/api/set-loader-options.d.ts +6 -0
- package/dist/lib/api/set-loader-options.d.ts.map +1 -0
- package/dist/lib/common.d.ts +2 -0
- package/dist/lib/common.d.ts.map +1 -0
- package/dist/lib/fetch/fetch-error-message.d.ts +3 -0
- package/dist/lib/fetch/fetch-error-message.d.ts.map +1 -0
- package/dist/lib/fetch/fetch-file.d.ts +13 -0
- package/dist/lib/fetch/fetch-file.d.ts.map +1 -0
- package/dist/lib/fetch/read-array-buffer.d.ts +17 -0
- package/dist/lib/fetch/read-array-buffer.d.ts.map +1 -0
- package/dist/lib/fetch/read-file.d.ts +5 -0
- package/dist/lib/fetch/read-file.d.ts.map +1 -0
- package/dist/lib/fetch/write-file.d.ts +3 -0
- package/dist/lib/fetch/write-file.d.ts.map +1 -0
- package/dist/lib/filesystems/browser-filesystem.d.ts +58 -0
- package/dist/lib/filesystems/browser-filesystem.d.ts.map +1 -0
- package/dist/lib/filesystems/filesystem.d.ts +46 -0
- package/dist/lib/filesystems/filesystem.d.ts.map +1 -0
- package/dist/lib/filesystems/read-array-buffer.d.ts +19 -0
- package/dist/lib/filesystems/read-array-buffer.d.ts.map +1 -0
- package/dist/lib/init.d.ts +3 -0
- package/dist/lib/init.d.ts.map +1 -0
- package/dist/lib/init.js +1 -1
- package/dist/lib/init.js.map +1 -1
- package/dist/lib/loader-utils/check-errors.d.ts +3 -0
- package/dist/lib/loader-utils/check-errors.d.ts.map +1 -0
- package/dist/lib/loader-utils/get-data.d.ts +6 -0
- package/dist/lib/loader-utils/get-data.d.ts.map +1 -0
- package/dist/lib/loader-utils/loader-context.d.ts +13 -0
- package/dist/lib/loader-utils/loader-context.d.ts.map +1 -0
- package/dist/lib/loader-utils/loggers.d.ts +16 -0
- package/dist/lib/loader-utils/loggers.d.ts.map +1 -0
- package/dist/lib/loader-utils/normalize-loader.d.ts +4 -0
- package/dist/lib/loader-utils/normalize-loader.d.ts.map +1 -0
- package/dist/lib/loader-utils/option-defaults.d.ts +20 -0
- package/dist/lib/loader-utils/option-defaults.d.ts.map +1 -0
- package/dist/lib/loader-utils/option-utils.d.ts +36 -0
- package/dist/lib/loader-utils/option-utils.d.ts.map +1 -0
- package/dist/lib/progress/fetch-progress.d.ts +6 -0
- package/dist/lib/progress/fetch-progress.d.ts.map +1 -0
- package/dist/lib/utils/mime-type-utils.d.ts +20 -0
- package/dist/lib/utils/mime-type-utils.d.ts.map +1 -0
- package/dist/lib/utils/resource-utils.d.ts +21 -0
- package/dist/lib/utils/resource-utils.d.ts.map +1 -0
- package/dist/lib/utils/response-utils.d.ts +18 -0
- package/dist/lib/utils/response-utils.d.ts.map +1 -0
- package/dist/null-loader.d.ts +10 -0
- package/dist/null-loader.d.ts.map +1 -0
- package/dist/null-loader.js +1 -1
- package/dist/null-worker.js +1 -1
- package/dist/workers/null-worker.d.ts +2 -0
- package/dist/workers/null-worker.d.ts.map +1 -0
- package/package.json +12 -11
- package/src/index.ts +1 -3
- package/src/iterators/make-stream/make-dom-stream.ts +9 -4
- package/src/iterators/make-stream/make-node-stream.ts +2 -7
- package/src/lib/{init.js → init.ts} +0 -0
- package/dist/iterators/make-stream/make-stream.js +0 -7
- package/dist/iterators/make-stream/make-stream.js.map +0 -1
- package/src/iterators/make-stream/make-stream.ts +0 -19
package/dist/dist.min.js
ADDED
|
@@ -0,0 +1,3423 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
9
|
+
var __esm = (fn, res) => function __init() {
|
|
10
|
+
return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
|
|
11
|
+
};
|
|
12
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
13
|
+
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
14
|
+
};
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
__markAsModule(target);
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, module2, desc) => {
|
|
21
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(module2))
|
|
23
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
24
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return target;
|
|
27
|
+
};
|
|
28
|
+
var __toModule = (module2) => {
|
|
29
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// ../loader-utils/src/lib/env-utils/assert.ts
|
|
33
|
+
function assert(condition, message) {
|
|
34
|
+
if (!condition) {
|
|
35
|
+
throw new Error(message || "loader assertion failed.");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
var init_assert = __esm({
|
|
39
|
+
"../loader-utils/src/lib/env-utils/assert.ts"() {
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// ../loader-utils/src/lib/env-utils/globals.ts
|
|
44
|
+
var globals, self_, window_, global_, document_, isBrowser, isWorker, matches, nodeVersion;
|
|
45
|
+
var init_globals = __esm({
|
|
46
|
+
"../loader-utils/src/lib/env-utils/globals.ts"() {
|
|
47
|
+
globals = {
|
|
48
|
+
self: typeof self !== "undefined" && self,
|
|
49
|
+
window: typeof window !== "undefined" && window,
|
|
50
|
+
global: typeof global !== "undefined" && global,
|
|
51
|
+
document: typeof document !== "undefined" && document
|
|
52
|
+
};
|
|
53
|
+
self_ = globals.self || globals.window || globals.global || {};
|
|
54
|
+
window_ = globals.window || globals.self || globals.global || {};
|
|
55
|
+
global_ = globals.global || globals.self || globals.window || {};
|
|
56
|
+
document_ = globals.document || {};
|
|
57
|
+
isBrowser = Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser);
|
|
58
|
+
isWorker = typeof importScripts === "function";
|
|
59
|
+
matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
60
|
+
nodeVersion = matches && parseFloat(matches[1]) || 0;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// ../worker-utils/src/lib/env-utils/version.ts
|
|
65
|
+
var DEFAULT_VERSION, VERSION;
|
|
66
|
+
var init_version = __esm({
|
|
67
|
+
"../worker-utils/src/lib/env-utils/version.ts"() {
|
|
68
|
+
DEFAULT_VERSION = "beta";
|
|
69
|
+
VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : DEFAULT_VERSION;
|
|
70
|
+
if (typeof __VERSION__ === "undefined") {
|
|
71
|
+
console.error("loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// ../worker-utils/src/lib/env-utils/assert.ts
|
|
77
|
+
function assert2(condition, message) {
|
|
78
|
+
if (!condition) {
|
|
79
|
+
throw new Error(message || "loaders.gl assertion failed.");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
var init_assert2 = __esm({
|
|
83
|
+
"../worker-utils/src/lib/env-utils/assert.ts"() {
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// ../worker-utils/src/lib/env-utils/globals.ts
|
|
88
|
+
var globals2, self_2, window_2, global_2, document_2, isBrowser2, isMobile, matches2, nodeVersion2;
|
|
89
|
+
var init_globals2 = __esm({
|
|
90
|
+
"../worker-utils/src/lib/env-utils/globals.ts"() {
|
|
91
|
+
globals2 = {
|
|
92
|
+
self: typeof self !== "undefined" && self,
|
|
93
|
+
window: typeof window !== "undefined" && window,
|
|
94
|
+
global: typeof global !== "undefined" && global,
|
|
95
|
+
document: typeof document !== "undefined" && document
|
|
96
|
+
};
|
|
97
|
+
self_2 = globals2.self || globals2.window || globals2.global || {};
|
|
98
|
+
window_2 = globals2.window || globals2.self || globals2.global || {};
|
|
99
|
+
global_2 = globals2.global || globals2.self || globals2.window || {};
|
|
100
|
+
document_2 = globals2.document || {};
|
|
101
|
+
isBrowser2 = typeof process !== "object" || String(process) !== "[object process]" || process.browser;
|
|
102
|
+
isMobile = typeof window !== "undefined" && typeof window.orientation !== "undefined";
|
|
103
|
+
matches2 = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
104
|
+
nodeVersion2 = matches2 && parseFloat(matches2[1]) || 0;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// ../worker-utils/src/lib/worker-farm/worker-job.ts
|
|
109
|
+
var WorkerJob;
|
|
110
|
+
var init_worker_job = __esm({
|
|
111
|
+
"../worker-utils/src/lib/worker-farm/worker-job.ts"() {
|
|
112
|
+
init_assert2();
|
|
113
|
+
WorkerJob = class {
|
|
114
|
+
constructor(jobName, workerThread) {
|
|
115
|
+
this.name = jobName;
|
|
116
|
+
this.workerThread = workerThread;
|
|
117
|
+
this.isRunning = true;
|
|
118
|
+
this._resolve = () => {
|
|
119
|
+
};
|
|
120
|
+
this._reject = () => {
|
|
121
|
+
};
|
|
122
|
+
this.result = new Promise((resolve, reject) => {
|
|
123
|
+
this._resolve = resolve;
|
|
124
|
+
this._reject = reject;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
postMessage(type, payload) {
|
|
128
|
+
this.workerThread.postMessage({
|
|
129
|
+
source: "loaders.gl",
|
|
130
|
+
type,
|
|
131
|
+
payload
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
done(value) {
|
|
135
|
+
assert2(this.isRunning);
|
|
136
|
+
this.isRunning = false;
|
|
137
|
+
this._resolve(value);
|
|
138
|
+
}
|
|
139
|
+
error(error) {
|
|
140
|
+
assert2(this.isRunning);
|
|
141
|
+
this.isRunning = false;
|
|
142
|
+
this._reject(error);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// ../worker-utils/src/lib/worker-utils/get-loadable-worker-url.ts
|
|
149
|
+
function getLoadableWorkerURL(props) {
|
|
150
|
+
assert2(props.source && !props.url || !props.source && props.url);
|
|
151
|
+
let workerURL = workerURLCache.get(props.source || props.url);
|
|
152
|
+
if (!workerURL) {
|
|
153
|
+
if (props.url) {
|
|
154
|
+
workerURL = getLoadableWorkerURLFromURL(props.url);
|
|
155
|
+
workerURLCache.set(props.url, workerURL);
|
|
156
|
+
}
|
|
157
|
+
if (props.source) {
|
|
158
|
+
workerURL = getLoadableWorkerURLFromSource(props.source);
|
|
159
|
+
workerURLCache.set(props.source, workerURL);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
assert2(workerURL);
|
|
163
|
+
return workerURL;
|
|
164
|
+
}
|
|
165
|
+
function getLoadableWorkerURLFromURL(url) {
|
|
166
|
+
if (!url.startsWith("http")) {
|
|
167
|
+
return url;
|
|
168
|
+
}
|
|
169
|
+
const workerSource = buildScriptSource(url);
|
|
170
|
+
return getLoadableWorkerURLFromSource(workerSource);
|
|
171
|
+
}
|
|
172
|
+
function getLoadableWorkerURLFromSource(workerSource) {
|
|
173
|
+
const blob = new Blob([workerSource], { type: "application/javascript" });
|
|
174
|
+
return URL.createObjectURL(blob);
|
|
175
|
+
}
|
|
176
|
+
function buildScriptSource(workerUrl) {
|
|
177
|
+
return `try {
|
|
178
|
+
importScripts('${workerUrl}');
|
|
179
|
+
} catch (error) {
|
|
180
|
+
console.error(error);
|
|
181
|
+
throw error;
|
|
182
|
+
}`;
|
|
183
|
+
}
|
|
184
|
+
var workerURLCache;
|
|
185
|
+
var init_get_loadable_worker_url = __esm({
|
|
186
|
+
"../worker-utils/src/lib/worker-utils/get-loadable-worker-url.ts"() {
|
|
187
|
+
init_assert2();
|
|
188
|
+
workerURLCache = new Map();
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
|
|
193
|
+
function getTransferList(object, recursive = true, transfers) {
|
|
194
|
+
const transfersSet = transfers || new Set();
|
|
195
|
+
if (!object) {
|
|
196
|
+
} else if (isTransferable(object)) {
|
|
197
|
+
transfersSet.add(object);
|
|
198
|
+
} else if (isTransferable(object.buffer)) {
|
|
199
|
+
transfersSet.add(object.buffer);
|
|
200
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
201
|
+
} else if (recursive && typeof object === "object") {
|
|
202
|
+
for (const key in object) {
|
|
203
|
+
getTransferList(object[key], recursive, transfersSet);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
207
|
+
}
|
|
208
|
+
function isTransferable(object) {
|
|
209
|
+
if (!object) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
if (object instanceof ArrayBuffer) {
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
var init_get_transfer_list = __esm({
|
|
227
|
+
"../worker-utils/src/lib/worker-utils/get-transfer-list.ts"() {
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// ../worker-utils/src/lib/worker-farm/worker-thread.ts
|
|
232
|
+
var NOOP, WorkerThread;
|
|
233
|
+
var init_worker_thread = __esm({
|
|
234
|
+
"../worker-utils/src/lib/worker-farm/worker-thread.ts"() {
|
|
235
|
+
init_assert2();
|
|
236
|
+
init_get_loadable_worker_url();
|
|
237
|
+
init_get_transfer_list();
|
|
238
|
+
NOOP = () => {
|
|
239
|
+
};
|
|
240
|
+
WorkerThread = class {
|
|
241
|
+
constructor(props) {
|
|
242
|
+
this.terminated = false;
|
|
243
|
+
this._loadableURL = "";
|
|
244
|
+
const { name, source, url } = props;
|
|
245
|
+
assert2(source || url);
|
|
246
|
+
this.name = name;
|
|
247
|
+
this.source = source;
|
|
248
|
+
this.url = url;
|
|
249
|
+
this.onMessage = NOOP;
|
|
250
|
+
this.onError = (error) => console.log(error);
|
|
251
|
+
this.worker = this._createBrowserWorker();
|
|
252
|
+
}
|
|
253
|
+
static isSupported() {
|
|
254
|
+
return typeof Worker !== "undefined";
|
|
255
|
+
}
|
|
256
|
+
destroy() {
|
|
257
|
+
this.onMessage = NOOP;
|
|
258
|
+
this.onError = NOOP;
|
|
259
|
+
this.worker.terminate();
|
|
260
|
+
this.terminated = true;
|
|
261
|
+
}
|
|
262
|
+
get isRunning() {
|
|
263
|
+
return Boolean(this.onMessage);
|
|
264
|
+
}
|
|
265
|
+
postMessage(data, transferList) {
|
|
266
|
+
transferList = transferList || getTransferList(data);
|
|
267
|
+
this.worker.postMessage(data, transferList);
|
|
268
|
+
}
|
|
269
|
+
_getErrorFromErrorEvent(event) {
|
|
270
|
+
let message = "Failed to load ";
|
|
271
|
+
message += `worker ${this.name} from ${this.url}. `;
|
|
272
|
+
if (event.message) {
|
|
273
|
+
message += `${event.message} in `;
|
|
274
|
+
}
|
|
275
|
+
if (event.lineno) {
|
|
276
|
+
message += `:${event.lineno}:${event.colno}`;
|
|
277
|
+
}
|
|
278
|
+
return new Error(message);
|
|
279
|
+
}
|
|
280
|
+
_createBrowserWorker() {
|
|
281
|
+
this._loadableURL = getLoadableWorkerURL({ source: this.source, url: this.url });
|
|
282
|
+
const worker = new Worker(this._loadableURL, { name: this.name });
|
|
283
|
+
worker.onmessage = (event) => {
|
|
284
|
+
if (!event.data) {
|
|
285
|
+
this.onError(new Error("No data received"));
|
|
286
|
+
} else {
|
|
287
|
+
this.onMessage(event.data);
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
worker.onerror = (error) => {
|
|
291
|
+
this.onError(this._getErrorFromErrorEvent(error));
|
|
292
|
+
this.terminated = true;
|
|
293
|
+
};
|
|
294
|
+
worker.onmessageerror = (event) => console.error(event);
|
|
295
|
+
return worker;
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
// ../worker-utils/src/lib/worker-farm/worker-pool.ts
|
|
302
|
+
var WorkerPool;
|
|
303
|
+
var init_worker_pool = __esm({
|
|
304
|
+
"../worker-utils/src/lib/worker-farm/worker-pool.ts"() {
|
|
305
|
+
init_globals2();
|
|
306
|
+
init_worker_thread();
|
|
307
|
+
init_worker_job();
|
|
308
|
+
WorkerPool = class {
|
|
309
|
+
constructor(props) {
|
|
310
|
+
this.name = "unnamed";
|
|
311
|
+
this.maxConcurrency = 1;
|
|
312
|
+
this.maxMobileConcurrency = 1;
|
|
313
|
+
this.onDebug = () => {
|
|
314
|
+
};
|
|
315
|
+
this.reuseWorkers = true;
|
|
316
|
+
this.props = {};
|
|
317
|
+
this.jobQueue = [];
|
|
318
|
+
this.idleQueue = [];
|
|
319
|
+
this.count = 0;
|
|
320
|
+
this.isDestroyed = false;
|
|
321
|
+
this.source = props.source;
|
|
322
|
+
this.url = props.url;
|
|
323
|
+
this.setProps(props);
|
|
324
|
+
}
|
|
325
|
+
destroy() {
|
|
326
|
+
this.idleQueue.forEach((worker) => worker.destroy());
|
|
327
|
+
this.isDestroyed = true;
|
|
328
|
+
}
|
|
329
|
+
setProps(props) {
|
|
330
|
+
this.props = { ...this.props, ...props };
|
|
331
|
+
if (props.name !== void 0) {
|
|
332
|
+
this.name = props.name;
|
|
333
|
+
}
|
|
334
|
+
if (props.maxConcurrency !== void 0) {
|
|
335
|
+
this.maxConcurrency = props.maxConcurrency;
|
|
336
|
+
}
|
|
337
|
+
if (props.maxMobileConcurrency !== void 0) {
|
|
338
|
+
this.maxMobileConcurrency = props.maxMobileConcurrency;
|
|
339
|
+
}
|
|
340
|
+
if (props.reuseWorkers !== void 0) {
|
|
341
|
+
this.reuseWorkers = props.reuseWorkers;
|
|
342
|
+
}
|
|
343
|
+
if (props.onDebug !== void 0) {
|
|
344
|
+
this.onDebug = props.onDebug;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
async startJob(name, onMessage2 = (job, type, data) => job.done(data), onError = (job, error) => job.error(error)) {
|
|
348
|
+
const startPromise = new Promise((onStart) => {
|
|
349
|
+
this.jobQueue.push({ name, onMessage: onMessage2, onError, onStart });
|
|
350
|
+
return this;
|
|
351
|
+
});
|
|
352
|
+
this._startQueuedJob();
|
|
353
|
+
return await startPromise;
|
|
354
|
+
}
|
|
355
|
+
async _startQueuedJob() {
|
|
356
|
+
if (!this.jobQueue.length) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
const workerThread = this._getAvailableWorker();
|
|
360
|
+
if (!workerThread) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
const queuedJob = this.jobQueue.shift();
|
|
364
|
+
if (queuedJob) {
|
|
365
|
+
this.onDebug({
|
|
366
|
+
message: "Starting job",
|
|
367
|
+
name: queuedJob.name,
|
|
368
|
+
workerThread,
|
|
369
|
+
backlog: this.jobQueue.length
|
|
370
|
+
});
|
|
371
|
+
const job = new WorkerJob(queuedJob.name, workerThread);
|
|
372
|
+
workerThread.onMessage = (data) => queuedJob.onMessage(job, data.type, data.payload);
|
|
373
|
+
workerThread.onError = (error) => queuedJob.onError(job, error);
|
|
374
|
+
queuedJob.onStart(job);
|
|
375
|
+
try {
|
|
376
|
+
await job.result;
|
|
377
|
+
} finally {
|
|
378
|
+
this.returnWorkerToQueue(workerThread);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
returnWorkerToQueue(worker) {
|
|
383
|
+
const shouldDestroyWorker = this.isDestroyed || !this.reuseWorkers || this.count > this._getMaxConcurrency();
|
|
384
|
+
if (shouldDestroyWorker) {
|
|
385
|
+
worker.destroy();
|
|
386
|
+
this.count--;
|
|
387
|
+
} else {
|
|
388
|
+
this.idleQueue.push(worker);
|
|
389
|
+
}
|
|
390
|
+
if (!this.isDestroyed) {
|
|
391
|
+
this._startQueuedJob();
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
_getAvailableWorker() {
|
|
395
|
+
if (this.idleQueue.length > 0) {
|
|
396
|
+
return this.idleQueue.shift() || null;
|
|
397
|
+
}
|
|
398
|
+
if (this.count < this._getMaxConcurrency()) {
|
|
399
|
+
this.count++;
|
|
400
|
+
const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;
|
|
401
|
+
return new WorkerThread({ name, source: this.source, url: this.url });
|
|
402
|
+
}
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
_getMaxConcurrency() {
|
|
406
|
+
return isMobile ? this.maxMobileConcurrency : this.maxConcurrency;
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
// ../worker-utils/src/lib/worker-farm/worker-farm.ts
|
|
413
|
+
var DEFAULT_PROPS, WorkerFarm;
|
|
414
|
+
var init_worker_farm = __esm({
|
|
415
|
+
"../worker-utils/src/lib/worker-farm/worker-farm.ts"() {
|
|
416
|
+
init_worker_pool();
|
|
417
|
+
init_worker_thread();
|
|
418
|
+
DEFAULT_PROPS = {
|
|
419
|
+
maxConcurrency: 3,
|
|
420
|
+
maxMobileConcurrency: 1,
|
|
421
|
+
onDebug: () => {
|
|
422
|
+
},
|
|
423
|
+
reuseWorkers: true
|
|
424
|
+
};
|
|
425
|
+
WorkerFarm = class {
|
|
426
|
+
constructor(props) {
|
|
427
|
+
this.workerPools = new Map();
|
|
428
|
+
this.props = { ...DEFAULT_PROPS };
|
|
429
|
+
this.setProps(props);
|
|
430
|
+
this.workerPools = new Map();
|
|
431
|
+
}
|
|
432
|
+
static isSupported() {
|
|
433
|
+
return WorkerThread.isSupported();
|
|
434
|
+
}
|
|
435
|
+
static getWorkerFarm(props = {}) {
|
|
436
|
+
WorkerFarm._workerFarm = WorkerFarm._workerFarm || new WorkerFarm({});
|
|
437
|
+
WorkerFarm._workerFarm.setProps(props);
|
|
438
|
+
return WorkerFarm._workerFarm;
|
|
439
|
+
}
|
|
440
|
+
destroy() {
|
|
441
|
+
for (const workerPool of this.workerPools.values()) {
|
|
442
|
+
workerPool.destroy();
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
setProps(props) {
|
|
446
|
+
this.props = { ...this.props, ...props };
|
|
447
|
+
for (const workerPool of this.workerPools.values()) {
|
|
448
|
+
workerPool.setProps(this._getWorkerPoolProps());
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
getWorkerPool(options) {
|
|
452
|
+
const { name, source, url } = options;
|
|
453
|
+
let workerPool = this.workerPools.get(name);
|
|
454
|
+
if (!workerPool) {
|
|
455
|
+
workerPool = new WorkerPool({
|
|
456
|
+
name,
|
|
457
|
+
source,
|
|
458
|
+
url
|
|
459
|
+
});
|
|
460
|
+
workerPool.setProps(this._getWorkerPoolProps());
|
|
461
|
+
this.workerPools.set(name, workerPool);
|
|
462
|
+
}
|
|
463
|
+
return workerPool;
|
|
464
|
+
}
|
|
465
|
+
_getWorkerPoolProps() {
|
|
466
|
+
return {
|
|
467
|
+
maxConcurrency: this.props.maxConcurrency,
|
|
468
|
+
maxMobileConcurrency: this.props.maxMobileConcurrency,
|
|
469
|
+
reuseWorkers: this.props.reuseWorkers,
|
|
470
|
+
onDebug: this.props.onDebug
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
// ../worker-utils/src/lib/worker-api/get-worker-url.ts
|
|
478
|
+
function getWorkerURL(worker, options = {}) {
|
|
479
|
+
const workerOptions = options[worker.id] || {};
|
|
480
|
+
const workerFile = `${worker.id}-worker.js`;
|
|
481
|
+
let url = workerOptions.workerUrl;
|
|
482
|
+
if (!url && worker.id === "compression") {
|
|
483
|
+
url = options.workerUrl;
|
|
484
|
+
}
|
|
485
|
+
if (options._workerType === "test") {
|
|
486
|
+
url = `modules/${worker.module}/dist/${workerFile}`;
|
|
487
|
+
}
|
|
488
|
+
if (!url) {
|
|
489
|
+
let version = worker.version;
|
|
490
|
+
if (version === "latest") {
|
|
491
|
+
version = NPM_TAG;
|
|
492
|
+
}
|
|
493
|
+
const versionTag = version ? `@${version}` : "";
|
|
494
|
+
url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;
|
|
495
|
+
}
|
|
496
|
+
assert2(url);
|
|
497
|
+
return url;
|
|
498
|
+
}
|
|
499
|
+
var NPM_TAG;
|
|
500
|
+
var init_get_worker_url = __esm({
|
|
501
|
+
"../worker-utils/src/lib/worker-api/get-worker-url.ts"() {
|
|
502
|
+
init_assert2();
|
|
503
|
+
NPM_TAG = "beta";
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
// ../worker-utils/src/lib/worker-api/validate-worker-version.ts
|
|
508
|
+
function validateWorkerVersion(worker, coreVersion = VERSION) {
|
|
509
|
+
assert2(worker, "no worker provided");
|
|
510
|
+
const workerVersion = worker.version;
|
|
511
|
+
if (!coreVersion || !workerVersion) {
|
|
512
|
+
return false;
|
|
513
|
+
}
|
|
514
|
+
return true;
|
|
515
|
+
}
|
|
516
|
+
var init_validate_worker_version = __esm({
|
|
517
|
+
"../worker-utils/src/lib/worker-api/validate-worker-version.ts"() {
|
|
518
|
+
init_assert2();
|
|
519
|
+
init_version();
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
// ../worker-utils/src/index.ts
|
|
524
|
+
var init_src = __esm({
|
|
525
|
+
"../worker-utils/src/index.ts"() {
|
|
526
|
+
init_assert2();
|
|
527
|
+
init_worker_farm();
|
|
528
|
+
init_get_worker_url();
|
|
529
|
+
init_validate_worker_version();
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
// ../loader-utils/src/lib/worker-loader-utils/parse-with-worker.ts
|
|
534
|
+
function canParseWithWorker(loader, options) {
|
|
535
|
+
if (!WorkerFarm.isSupported()) {
|
|
536
|
+
return false;
|
|
537
|
+
}
|
|
538
|
+
return loader.worker && options?.worker;
|
|
539
|
+
}
|
|
540
|
+
async function parseWithWorker(loader, data, options, context, parseOnMainThread) {
|
|
541
|
+
const name = loader.id;
|
|
542
|
+
const url = getWorkerURL(loader, options);
|
|
543
|
+
const workerFarm = WorkerFarm.getWorkerFarm(options);
|
|
544
|
+
const workerPool = workerFarm.getWorkerPool({ name, url });
|
|
545
|
+
options = JSON.parse(JSON.stringify(options));
|
|
546
|
+
const job = await workerPool.startJob("process-on-worker", onMessage.bind(null, parseOnMainThread));
|
|
547
|
+
job.postMessage("process", {
|
|
548
|
+
input: data,
|
|
549
|
+
options
|
|
550
|
+
});
|
|
551
|
+
const result = await job.result;
|
|
552
|
+
return await result.result;
|
|
553
|
+
}
|
|
554
|
+
async function onMessage(parseOnMainThread, job, type, payload) {
|
|
555
|
+
switch (type) {
|
|
556
|
+
case "done":
|
|
557
|
+
job.done(payload);
|
|
558
|
+
break;
|
|
559
|
+
case "error":
|
|
560
|
+
job.error(new Error(payload.error));
|
|
561
|
+
break;
|
|
562
|
+
case "process":
|
|
563
|
+
const { id, input, options } = payload;
|
|
564
|
+
try {
|
|
565
|
+
const result = await parseOnMainThread(input, options);
|
|
566
|
+
job.postMessage("done", { id, result });
|
|
567
|
+
} catch (error) {
|
|
568
|
+
const message = error instanceof Error ? error.message : "unknown error";
|
|
569
|
+
job.postMessage("error", { id, error: message });
|
|
570
|
+
}
|
|
571
|
+
break;
|
|
572
|
+
default:
|
|
573
|
+
console.warn(`parse-with-worker unknown message ${type}`);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
var init_parse_with_worker = __esm({
|
|
577
|
+
"../loader-utils/src/lib/worker-loader-utils/parse-with-worker.ts"() {
|
|
578
|
+
init_src();
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
// (disabled):../loader-utils/src/lib/node/buffer
|
|
583
|
+
var init_buffer = __esm({
|
|
584
|
+
"(disabled):../loader-utils/src/lib/node/buffer"() {
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
// ../loader-utils/src/lib/binary-utils/buffer-utils.ts
|
|
589
|
+
function isBuffer(value) {
|
|
590
|
+
return value && typeof value === "object" && value.isBuffer;
|
|
591
|
+
}
|
|
592
|
+
function toBuffer2(data) {
|
|
593
|
+
return node.toBuffer ? node.toBuffer(data) : data;
|
|
594
|
+
}
|
|
595
|
+
function bufferToArrayBuffer(buffer) {
|
|
596
|
+
if (isBuffer(buffer)) {
|
|
597
|
+
const typedArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);
|
|
598
|
+
return typedArray.slice().buffer;
|
|
599
|
+
}
|
|
600
|
+
return buffer;
|
|
601
|
+
}
|
|
602
|
+
var init_buffer_utils = __esm({
|
|
603
|
+
"../loader-utils/src/lib/binary-utils/buffer-utils.ts"() {
|
|
604
|
+
init_buffer();
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
// ../loader-utils/src/lib/binary-utils/array-buffer-utils.ts
|
|
609
|
+
function toArrayBuffer(data) {
|
|
610
|
+
if (isBuffer(data)) {
|
|
611
|
+
return bufferToArrayBuffer(data);
|
|
612
|
+
}
|
|
613
|
+
if (data instanceof ArrayBuffer) {
|
|
614
|
+
return data;
|
|
615
|
+
}
|
|
616
|
+
if (ArrayBuffer.isView(data)) {
|
|
617
|
+
if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
|
|
618
|
+
return data.buffer;
|
|
619
|
+
}
|
|
620
|
+
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
621
|
+
}
|
|
622
|
+
if (typeof data === "string") {
|
|
623
|
+
const text = data;
|
|
624
|
+
const uint8Array = new TextEncoder().encode(text);
|
|
625
|
+
return uint8Array.buffer;
|
|
626
|
+
}
|
|
627
|
+
if (data && typeof data === "object" && data._toArrayBuffer) {
|
|
628
|
+
return data._toArrayBuffer();
|
|
629
|
+
}
|
|
630
|
+
throw new Error("toArrayBuffer");
|
|
631
|
+
}
|
|
632
|
+
function compareArrayBuffers(arrayBuffer1, arrayBuffer2, byteLength) {
|
|
633
|
+
byteLength = byteLength || arrayBuffer1.byteLength;
|
|
634
|
+
if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) {
|
|
635
|
+
return false;
|
|
636
|
+
}
|
|
637
|
+
const array1 = new Uint8Array(arrayBuffer1);
|
|
638
|
+
const array2 = new Uint8Array(arrayBuffer2);
|
|
639
|
+
for (let i = 0; i < array1.length; ++i) {
|
|
640
|
+
if (array1[i] !== array2[i]) {
|
|
641
|
+
return false;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
return true;
|
|
645
|
+
}
|
|
646
|
+
function concatenateArrayBuffers(...sources) {
|
|
647
|
+
const sourceArrays = sources.map((source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2);
|
|
648
|
+
const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
|
|
649
|
+
const result = new Uint8Array(byteLength);
|
|
650
|
+
let offset = 0;
|
|
651
|
+
for (const sourceArray of sourceArrays) {
|
|
652
|
+
result.set(sourceArray, offset);
|
|
653
|
+
offset += sourceArray.byteLength;
|
|
654
|
+
}
|
|
655
|
+
return result.buffer;
|
|
656
|
+
}
|
|
657
|
+
var init_array_buffer_utils = __esm({
|
|
658
|
+
"../loader-utils/src/lib/binary-utils/array-buffer-utils.ts"() {
|
|
659
|
+
init_buffer_utils();
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
// ../loader-utils/src/lib/iterators/text-iterators.ts
|
|
664
|
+
async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
|
|
665
|
+
const textDecoder = new TextDecoder(void 0, options);
|
|
666
|
+
for await (const arrayBuffer of arrayBufferIterator) {
|
|
667
|
+
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, { stream: true });
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
async function* makeTextEncoderIterator(textIterator) {
|
|
671
|
+
const textEncoder = new TextEncoder();
|
|
672
|
+
for await (const text of textIterator) {
|
|
673
|
+
yield typeof text === "string" ? textEncoder.encode(text) : text;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
async function* makeLineIterator(textIterator) {
|
|
677
|
+
let previous = "";
|
|
678
|
+
for await (const textChunk of textIterator) {
|
|
679
|
+
previous += textChunk;
|
|
680
|
+
let eolIndex;
|
|
681
|
+
while ((eolIndex = previous.indexOf("\n")) >= 0) {
|
|
682
|
+
const line = previous.slice(0, eolIndex + 1);
|
|
683
|
+
previous = previous.slice(eolIndex + 1);
|
|
684
|
+
yield line;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
if (previous.length > 0) {
|
|
688
|
+
yield previous;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
async function* makeNumberedLineIterator(lineIterator) {
|
|
692
|
+
let counter = 1;
|
|
693
|
+
for await (const line of lineIterator) {
|
|
694
|
+
yield { counter, line };
|
|
695
|
+
counter++;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
var init_text_iterators = __esm({
|
|
699
|
+
"../loader-utils/src/lib/iterators/text-iterators.ts"() {
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
// ../loader-utils/src/lib/iterators/async-iteration.ts
|
|
704
|
+
async function forEach(iterator, visitor) {
|
|
705
|
+
while (true) {
|
|
706
|
+
const { done, value } = await iterator.next();
|
|
707
|
+
if (done) {
|
|
708
|
+
iterator.return();
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
const cancel = visitor(value);
|
|
712
|
+
if (cancel) {
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
async function concatenateArrayBuffersAsync(asyncIterator) {
|
|
718
|
+
const arrayBuffers = [];
|
|
719
|
+
for await (const chunk of asyncIterator) {
|
|
720
|
+
arrayBuffers.push(chunk);
|
|
721
|
+
}
|
|
722
|
+
return concatenateArrayBuffers(...arrayBuffers);
|
|
723
|
+
}
|
|
724
|
+
var init_async_iteration = __esm({
|
|
725
|
+
"../loader-utils/src/lib/iterators/async-iteration.ts"() {
|
|
726
|
+
init_array_buffer_utils();
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
// ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
|
|
731
|
+
function _defineProperty(obj, key, value) {
|
|
732
|
+
if (key in obj) {
|
|
733
|
+
Object.defineProperty(obj, key, {
|
|
734
|
+
value,
|
|
735
|
+
enumerable: true,
|
|
736
|
+
configurable: true,
|
|
737
|
+
writable: true
|
|
738
|
+
});
|
|
739
|
+
} else {
|
|
740
|
+
obj[key] = value;
|
|
741
|
+
}
|
|
742
|
+
return obj;
|
|
743
|
+
}
|
|
744
|
+
var init_defineProperty = __esm({
|
|
745
|
+
"../../node_modules/@babel/runtime/helpers/esm/defineProperty.js"() {
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
// ../../node_modules/@probe.gl/stats/dist/esm/utils/hi-res-timestamp.js
|
|
750
|
+
function getHiResTimestamp() {
|
|
751
|
+
let timestamp;
|
|
752
|
+
if (typeof window !== "undefined" && window.performance) {
|
|
753
|
+
timestamp = window.performance.now();
|
|
754
|
+
} else if (typeof process !== "undefined" && process.hrtime) {
|
|
755
|
+
const timeParts = process.hrtime();
|
|
756
|
+
timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
|
|
757
|
+
} else {
|
|
758
|
+
timestamp = Date.now();
|
|
759
|
+
}
|
|
760
|
+
return timestamp;
|
|
761
|
+
}
|
|
762
|
+
var init_hi_res_timestamp = __esm({
|
|
763
|
+
"../../node_modules/@probe.gl/stats/dist/esm/utils/hi-res-timestamp.js"() {
|
|
764
|
+
}
|
|
765
|
+
});
|
|
766
|
+
|
|
767
|
+
// ../../node_modules/@probe.gl/stats/dist/esm/lib/stat.js
|
|
768
|
+
var Stat;
|
|
769
|
+
var init_stat = __esm({
|
|
770
|
+
"../../node_modules/@probe.gl/stats/dist/esm/lib/stat.js"() {
|
|
771
|
+
init_defineProperty();
|
|
772
|
+
init_hi_res_timestamp();
|
|
773
|
+
Stat = class {
|
|
774
|
+
constructor(name, type) {
|
|
775
|
+
_defineProperty(this, "name", void 0);
|
|
776
|
+
_defineProperty(this, "type", void 0);
|
|
777
|
+
_defineProperty(this, "sampleSize", 1);
|
|
778
|
+
_defineProperty(this, "time", void 0);
|
|
779
|
+
_defineProperty(this, "count", void 0);
|
|
780
|
+
_defineProperty(this, "samples", void 0);
|
|
781
|
+
_defineProperty(this, "lastTiming", void 0);
|
|
782
|
+
_defineProperty(this, "lastSampleTime", void 0);
|
|
783
|
+
_defineProperty(this, "lastSampleCount", void 0);
|
|
784
|
+
_defineProperty(this, "_count", 0);
|
|
785
|
+
_defineProperty(this, "_time", 0);
|
|
786
|
+
_defineProperty(this, "_samples", 0);
|
|
787
|
+
_defineProperty(this, "_startTime", 0);
|
|
788
|
+
_defineProperty(this, "_timerPending", false);
|
|
789
|
+
this.name = name;
|
|
790
|
+
this.type = type;
|
|
791
|
+
this.reset();
|
|
792
|
+
}
|
|
793
|
+
setSampleSize(samples) {
|
|
794
|
+
this.sampleSize = samples;
|
|
795
|
+
return this;
|
|
796
|
+
}
|
|
797
|
+
incrementCount() {
|
|
798
|
+
this.addCount(1);
|
|
799
|
+
return this;
|
|
800
|
+
}
|
|
801
|
+
decrementCount() {
|
|
802
|
+
this.subtractCount(1);
|
|
803
|
+
return this;
|
|
804
|
+
}
|
|
805
|
+
addCount(value) {
|
|
806
|
+
this._count += value;
|
|
807
|
+
this._samples++;
|
|
808
|
+
this._checkSampling();
|
|
809
|
+
return this;
|
|
810
|
+
}
|
|
811
|
+
subtractCount(value) {
|
|
812
|
+
this._count -= value;
|
|
813
|
+
this._samples++;
|
|
814
|
+
this._checkSampling();
|
|
815
|
+
return this;
|
|
816
|
+
}
|
|
817
|
+
addTime(time) {
|
|
818
|
+
this._time += time;
|
|
819
|
+
this.lastTiming = time;
|
|
820
|
+
this._samples++;
|
|
821
|
+
this._checkSampling();
|
|
822
|
+
return this;
|
|
823
|
+
}
|
|
824
|
+
timeStart() {
|
|
825
|
+
this._startTime = getHiResTimestamp();
|
|
826
|
+
this._timerPending = true;
|
|
827
|
+
return this;
|
|
828
|
+
}
|
|
829
|
+
timeEnd() {
|
|
830
|
+
if (!this._timerPending) {
|
|
831
|
+
return this;
|
|
832
|
+
}
|
|
833
|
+
this.addTime(getHiResTimestamp() - this._startTime);
|
|
834
|
+
this._timerPending = false;
|
|
835
|
+
this._checkSampling();
|
|
836
|
+
return this;
|
|
837
|
+
}
|
|
838
|
+
getSampleAverageCount() {
|
|
839
|
+
return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
|
|
840
|
+
}
|
|
841
|
+
getSampleAverageTime() {
|
|
842
|
+
return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
|
|
843
|
+
}
|
|
844
|
+
getSampleHz() {
|
|
845
|
+
return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1e3) : 0;
|
|
846
|
+
}
|
|
847
|
+
getAverageCount() {
|
|
848
|
+
return this.samples > 0 ? this.count / this.samples : 0;
|
|
849
|
+
}
|
|
850
|
+
getAverageTime() {
|
|
851
|
+
return this.samples > 0 ? this.time / this.samples : 0;
|
|
852
|
+
}
|
|
853
|
+
getHz() {
|
|
854
|
+
return this.time > 0 ? this.samples / (this.time / 1e3) : 0;
|
|
855
|
+
}
|
|
856
|
+
reset() {
|
|
857
|
+
this.time = 0;
|
|
858
|
+
this.count = 0;
|
|
859
|
+
this.samples = 0;
|
|
860
|
+
this.lastTiming = 0;
|
|
861
|
+
this.lastSampleTime = 0;
|
|
862
|
+
this.lastSampleCount = 0;
|
|
863
|
+
this._count = 0;
|
|
864
|
+
this._time = 0;
|
|
865
|
+
this._samples = 0;
|
|
866
|
+
this._startTime = 0;
|
|
867
|
+
this._timerPending = false;
|
|
868
|
+
return this;
|
|
869
|
+
}
|
|
870
|
+
_checkSampling() {
|
|
871
|
+
if (this._samples === this.sampleSize) {
|
|
872
|
+
this.lastSampleTime = this._time;
|
|
873
|
+
this.lastSampleCount = this._count;
|
|
874
|
+
this.count += this._count;
|
|
875
|
+
this.time += this._time;
|
|
876
|
+
this.samples += this._samples;
|
|
877
|
+
this._time = 0;
|
|
878
|
+
this._count = 0;
|
|
879
|
+
this._samples = 0;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
});
|
|
885
|
+
|
|
886
|
+
// ../../node_modules/@probe.gl/stats/dist/esm/lib/stats.js
|
|
887
|
+
var Stats;
|
|
888
|
+
var init_stats = __esm({
|
|
889
|
+
"../../node_modules/@probe.gl/stats/dist/esm/lib/stats.js"() {
|
|
890
|
+
init_defineProperty();
|
|
891
|
+
init_stat();
|
|
892
|
+
Stats = class {
|
|
893
|
+
constructor(options) {
|
|
894
|
+
_defineProperty(this, "id", void 0);
|
|
895
|
+
_defineProperty(this, "stats", {});
|
|
896
|
+
this.id = options.id;
|
|
897
|
+
this.stats = {};
|
|
898
|
+
this._initializeStats(options.stats);
|
|
899
|
+
Object.seal(this);
|
|
900
|
+
}
|
|
901
|
+
get(name) {
|
|
902
|
+
let type = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "count";
|
|
903
|
+
return this._getOrCreate({
|
|
904
|
+
name,
|
|
905
|
+
type
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
get size() {
|
|
909
|
+
return Object.keys(this.stats).length;
|
|
910
|
+
}
|
|
911
|
+
reset() {
|
|
912
|
+
for (const key in this.stats) {
|
|
913
|
+
this.stats[key].reset();
|
|
914
|
+
}
|
|
915
|
+
return this;
|
|
916
|
+
}
|
|
917
|
+
forEach(fn) {
|
|
918
|
+
for (const key in this.stats) {
|
|
919
|
+
fn(this.stats[key]);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
getTable() {
|
|
923
|
+
const table = {};
|
|
924
|
+
this.forEach((stat) => {
|
|
925
|
+
table[stat.name] = {
|
|
926
|
+
time: stat.time || 0,
|
|
927
|
+
count: stat.count || 0,
|
|
928
|
+
average: stat.getAverageTime() || 0,
|
|
929
|
+
hz: stat.getHz() || 0
|
|
930
|
+
};
|
|
931
|
+
});
|
|
932
|
+
return table;
|
|
933
|
+
}
|
|
934
|
+
_initializeStats() {
|
|
935
|
+
let stats = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
|
936
|
+
stats.forEach((stat) => this._getOrCreate(stat));
|
|
937
|
+
}
|
|
938
|
+
_getOrCreate(stat) {
|
|
939
|
+
if (!stat || !stat.name) {
|
|
940
|
+
return null;
|
|
941
|
+
}
|
|
942
|
+
const {
|
|
943
|
+
name,
|
|
944
|
+
type
|
|
945
|
+
} = stat;
|
|
946
|
+
if (!this.stats[name]) {
|
|
947
|
+
if (stat instanceof Stat) {
|
|
948
|
+
this.stats[name] = stat;
|
|
949
|
+
} else {
|
|
950
|
+
this.stats[name] = new Stat(name, type);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
return this.stats[name];
|
|
954
|
+
}
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
// ../../node_modules/@probe.gl/stats/dist/esm/index.js
|
|
960
|
+
var init_esm = __esm({
|
|
961
|
+
"../../node_modules/@probe.gl/stats/dist/esm/index.js"() {
|
|
962
|
+
init_stats();
|
|
963
|
+
init_stat();
|
|
964
|
+
init_hi_res_timestamp();
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
|
|
968
|
+
// ../loader-utils/src/lib/request-utils/request-scheduler.ts
|
|
969
|
+
var STAT_QUEUED_REQUESTS, STAT_ACTIVE_REQUESTS, STAT_CANCELLED_REQUESTS, STAT_QUEUED_REQUESTS_EVER, STAT_ACTIVE_REQUESTS_EVER, DEFAULT_PROPS2, RequestScheduler;
|
|
970
|
+
var init_request_scheduler = __esm({
|
|
971
|
+
"../loader-utils/src/lib/request-utils/request-scheduler.ts"() {
|
|
972
|
+
init_esm();
|
|
973
|
+
STAT_QUEUED_REQUESTS = "Queued Requests";
|
|
974
|
+
STAT_ACTIVE_REQUESTS = "Active Requests";
|
|
975
|
+
STAT_CANCELLED_REQUESTS = "Cancelled Requests";
|
|
976
|
+
STAT_QUEUED_REQUESTS_EVER = "Queued Requests Ever";
|
|
977
|
+
STAT_ACTIVE_REQUESTS_EVER = "Active Requests Ever";
|
|
978
|
+
DEFAULT_PROPS2 = {
|
|
979
|
+
id: "request-scheduler",
|
|
980
|
+
throttleRequests: true,
|
|
981
|
+
maxRequests: 6
|
|
982
|
+
};
|
|
983
|
+
RequestScheduler = class {
|
|
984
|
+
constructor(props = {}) {
|
|
985
|
+
this.activeRequestCount = 0;
|
|
986
|
+
this.requestQueue = [];
|
|
987
|
+
this.requestMap = new Map();
|
|
988
|
+
this.deferredUpdate = null;
|
|
989
|
+
this.props = { ...DEFAULT_PROPS2, ...props };
|
|
990
|
+
this.stats = new Stats({ id: this.props.id });
|
|
991
|
+
this.stats.get(STAT_QUEUED_REQUESTS);
|
|
992
|
+
this.stats.get(STAT_ACTIVE_REQUESTS);
|
|
993
|
+
this.stats.get(STAT_CANCELLED_REQUESTS);
|
|
994
|
+
this.stats.get(STAT_QUEUED_REQUESTS_EVER);
|
|
995
|
+
this.stats.get(STAT_ACTIVE_REQUESTS_EVER);
|
|
996
|
+
}
|
|
997
|
+
scheduleRequest(handle, getPriority = () => 0) {
|
|
998
|
+
if (!this.props.throttleRequests) {
|
|
999
|
+
return Promise.resolve({ done: () => {
|
|
1000
|
+
} });
|
|
1001
|
+
}
|
|
1002
|
+
if (this.requestMap.has(handle)) {
|
|
1003
|
+
return this.requestMap.get(handle);
|
|
1004
|
+
}
|
|
1005
|
+
const request = { handle, priority: 0, getPriority };
|
|
1006
|
+
const promise = new Promise((resolve) => {
|
|
1007
|
+
request.resolve = resolve;
|
|
1008
|
+
return request;
|
|
1009
|
+
});
|
|
1010
|
+
this.requestQueue.push(request);
|
|
1011
|
+
this.requestMap.set(handle, promise);
|
|
1012
|
+
this._issueNewRequests();
|
|
1013
|
+
return promise;
|
|
1014
|
+
}
|
|
1015
|
+
_issueRequest(request) {
|
|
1016
|
+
const { handle, resolve } = request;
|
|
1017
|
+
let isDone = false;
|
|
1018
|
+
const done = () => {
|
|
1019
|
+
if (!isDone) {
|
|
1020
|
+
isDone = true;
|
|
1021
|
+
this.requestMap.delete(handle);
|
|
1022
|
+
this.activeRequestCount--;
|
|
1023
|
+
this._issueNewRequests();
|
|
1024
|
+
}
|
|
1025
|
+
};
|
|
1026
|
+
this.activeRequestCount++;
|
|
1027
|
+
return resolve ? resolve({ done }) : Promise.resolve({ done });
|
|
1028
|
+
}
|
|
1029
|
+
_issueNewRequests() {
|
|
1030
|
+
if (!this.deferredUpdate) {
|
|
1031
|
+
this.deferredUpdate = setTimeout(() => this._issueNewRequestsAsync(), 0);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
_issueNewRequestsAsync() {
|
|
1035
|
+
this.deferredUpdate = null;
|
|
1036
|
+
const freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);
|
|
1037
|
+
if (freeSlots === 0) {
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
this._updateAllRequests();
|
|
1041
|
+
for (let i = 0; i < freeSlots; ++i) {
|
|
1042
|
+
const request = this.requestQueue.shift();
|
|
1043
|
+
if (request) {
|
|
1044
|
+
this._issueRequest(request);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
_updateAllRequests() {
|
|
1049
|
+
const requestQueue = this.requestQueue;
|
|
1050
|
+
for (let i = 0; i < requestQueue.length; ++i) {
|
|
1051
|
+
const request = requestQueue[i];
|
|
1052
|
+
if (!this._updateRequest(request)) {
|
|
1053
|
+
requestQueue.splice(i, 1);
|
|
1054
|
+
this.requestMap.delete(request.handle);
|
|
1055
|
+
i--;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
requestQueue.sort((a, b) => a.priority - b.priority);
|
|
1059
|
+
}
|
|
1060
|
+
_updateRequest(request) {
|
|
1061
|
+
request.priority = request.getPriority(request.handle);
|
|
1062
|
+
if (request.priority < 0) {
|
|
1063
|
+
request.resolve(null);
|
|
1064
|
+
return false;
|
|
1065
|
+
}
|
|
1066
|
+
return true;
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
});
|
|
1071
|
+
|
|
1072
|
+
// ../loader-utils/src/lib/path-utils/file-aliases.ts
|
|
1073
|
+
function setPathPrefix(prefix) {
|
|
1074
|
+
pathPrefix = prefix;
|
|
1075
|
+
}
|
|
1076
|
+
function getPathPrefix() {
|
|
1077
|
+
return pathPrefix;
|
|
1078
|
+
}
|
|
1079
|
+
function resolvePath(filename2) {
|
|
1080
|
+
for (const alias in fileAliases) {
|
|
1081
|
+
if (filename2.startsWith(alias)) {
|
|
1082
|
+
const replacement = fileAliases[alias];
|
|
1083
|
+
filename2 = filename2.replace(alias, replacement);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
if (!filename2.startsWith("http://") && !filename2.startsWith("https://")) {
|
|
1087
|
+
filename2 = `${pathPrefix}${filename2}`;
|
|
1088
|
+
}
|
|
1089
|
+
return filename2;
|
|
1090
|
+
}
|
|
1091
|
+
var pathPrefix, fileAliases;
|
|
1092
|
+
var init_file_aliases = __esm({
|
|
1093
|
+
"../loader-utils/src/lib/path-utils/file-aliases.ts"() {
|
|
1094
|
+
pathPrefix = "";
|
|
1095
|
+
fileAliases = {};
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1098
|
+
|
|
1099
|
+
// ../loader-utils/src/json-loader.ts
|
|
1100
|
+
function parseTextSync(text) {
|
|
1101
|
+
return JSON.parse(text);
|
|
1102
|
+
}
|
|
1103
|
+
var VERSION2, JSONLoader;
|
|
1104
|
+
var init_json_loader = __esm({
|
|
1105
|
+
"../loader-utils/src/json-loader.ts"() {
|
|
1106
|
+
VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1107
|
+
JSONLoader = {
|
|
1108
|
+
name: "JSON",
|
|
1109
|
+
id: "json",
|
|
1110
|
+
module: "json",
|
|
1111
|
+
version: VERSION2,
|
|
1112
|
+
extensions: ["json", "geojson"],
|
|
1113
|
+
mimeTypes: ["application/json"],
|
|
1114
|
+
category: "json",
|
|
1115
|
+
text: true,
|
|
1116
|
+
parseTextSync,
|
|
1117
|
+
parse: async (arrayBuffer) => parseTextSync(new TextDecoder().decode(arrayBuffer)),
|
|
1118
|
+
options: {}
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
1122
|
+
|
|
1123
|
+
// ../loader-utils/src/lib/path-utils/path.ts
|
|
1124
|
+
var path_exports = {};
|
|
1125
|
+
__export(path_exports, {
|
|
1126
|
+
dirname: () => dirname,
|
|
1127
|
+
filename: () => filename,
|
|
1128
|
+
join: () => join
|
|
1129
|
+
});
|
|
1130
|
+
function filename(url) {
|
|
1131
|
+
const slashIndex = url && url.lastIndexOf("/");
|
|
1132
|
+
return slashIndex >= 0 ? url.substr(slashIndex + 1) : "";
|
|
1133
|
+
}
|
|
1134
|
+
function dirname(url) {
|
|
1135
|
+
const slashIndex = url && url.lastIndexOf("/");
|
|
1136
|
+
return slashIndex >= 0 ? url.substr(0, slashIndex) : "";
|
|
1137
|
+
}
|
|
1138
|
+
function join(...parts) {
|
|
1139
|
+
const separator = "/";
|
|
1140
|
+
parts = parts.map((part, index) => {
|
|
1141
|
+
if (index) {
|
|
1142
|
+
part = part.replace(new RegExp(`^${separator}`), "");
|
|
1143
|
+
}
|
|
1144
|
+
if (index !== parts.length - 1) {
|
|
1145
|
+
part = part.replace(new RegExp(`${separator}$`), "");
|
|
1146
|
+
}
|
|
1147
|
+
return part;
|
|
1148
|
+
});
|
|
1149
|
+
return parts.join(separator);
|
|
1150
|
+
}
|
|
1151
|
+
var init_path = __esm({
|
|
1152
|
+
"../loader-utils/src/lib/path-utils/path.ts"() {
|
|
1153
|
+
}
|
|
1154
|
+
});
|
|
1155
|
+
|
|
1156
|
+
// (disabled):../loader-utils/src/lib/node/fs
|
|
1157
|
+
var require_fs = __commonJS({
|
|
1158
|
+
"(disabled):../loader-utils/src/lib/node/fs"() {
|
|
1159
|
+
}
|
|
1160
|
+
});
|
|
1161
|
+
|
|
1162
|
+
// ../loader-utils/src/index.ts
|
|
1163
|
+
var fs;
|
|
1164
|
+
var init_src2 = __esm({
|
|
1165
|
+
"../loader-utils/src/index.ts"() {
|
|
1166
|
+
init_assert();
|
|
1167
|
+
init_globals();
|
|
1168
|
+
init_parse_with_worker();
|
|
1169
|
+
init_array_buffer_utils();
|
|
1170
|
+
init_text_iterators();
|
|
1171
|
+
init_async_iteration();
|
|
1172
|
+
init_request_scheduler();
|
|
1173
|
+
init_file_aliases();
|
|
1174
|
+
init_json_loader();
|
|
1175
|
+
init_path();
|
|
1176
|
+
init_buffer_utils();
|
|
1177
|
+
fs = __toModule(require_fs());
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
1180
|
+
|
|
1181
|
+
// src/javascript-utils/is-type.ts
|
|
1182
|
+
var isBoolean, isFunction, isObject, isPureObject, isPromise, isIterable, isAsyncIterable, isIterator, isResponse, isBlob, isBuffer2, isWritableDOMStream, isReadableDOMStream, isWritableNodeStream, isReadableNodeStream, isReadableStream, isWritableStream;
|
|
1183
|
+
var init_is_type = __esm({
|
|
1184
|
+
"src/javascript-utils/is-type.ts"() {
|
|
1185
|
+
isBoolean = (x) => typeof x === "boolean";
|
|
1186
|
+
isFunction = (x) => typeof x === "function";
|
|
1187
|
+
isObject = (x) => x !== null && typeof x === "object";
|
|
1188
|
+
isPureObject = (x) => isObject(x) && x.constructor === {}.constructor;
|
|
1189
|
+
isPromise = (x) => isObject(x) && isFunction(x.then);
|
|
1190
|
+
isIterable = (x) => x && typeof x[Symbol.iterator] === "function";
|
|
1191
|
+
isAsyncIterable = (x) => x && typeof x[Symbol.asyncIterator] === "function";
|
|
1192
|
+
isIterator = (x) => x && isFunction(x.next);
|
|
1193
|
+
isResponse = (x) => typeof Response !== "undefined" && x instanceof Response || x && x.arrayBuffer && x.text && x.json;
|
|
1194
|
+
isBlob = (x) => typeof Blob !== "undefined" && x instanceof Blob;
|
|
1195
|
+
isBuffer2 = (x) => x && typeof x === "object" && x.isBuffer;
|
|
1196
|
+
isWritableDOMStream = (x) => isObject(x) && isFunction(x.abort) && isFunction(x.getWriter);
|
|
1197
|
+
isReadableDOMStream = (x) => typeof ReadableStream !== "undefined" && x instanceof ReadableStream || isObject(x) && isFunction(x.tee) && isFunction(x.cancel) && isFunction(x.getReader);
|
|
1198
|
+
isWritableNodeStream = (x) => isObject(x) && isFunction(x.end) && isFunction(x.write) && isBoolean(x.writable);
|
|
1199
|
+
isReadableNodeStream = (x) => isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);
|
|
1200
|
+
isReadableStream = (x) => isReadableDOMStream(x) || isReadableNodeStream(x);
|
|
1201
|
+
isWritableStream = (x) => isWritableDOMStream(x) || isWritableNodeStream(x);
|
|
1202
|
+
}
|
|
1203
|
+
});
|
|
1204
|
+
|
|
1205
|
+
// src/lib/utils/mime-type-utils.ts
|
|
1206
|
+
function parseMIMEType(mimeString) {
|
|
1207
|
+
const matches3 = MIME_TYPE_PATTERN.exec(mimeString);
|
|
1208
|
+
if (matches3) {
|
|
1209
|
+
return matches3[1];
|
|
1210
|
+
}
|
|
1211
|
+
return mimeString;
|
|
1212
|
+
}
|
|
1213
|
+
function parseMIMETypeFromURL(url) {
|
|
1214
|
+
const matches3 = DATA_URL_PATTERN.exec(url);
|
|
1215
|
+
if (matches3) {
|
|
1216
|
+
return matches3[1];
|
|
1217
|
+
}
|
|
1218
|
+
return "";
|
|
1219
|
+
}
|
|
1220
|
+
var DATA_URL_PATTERN, MIME_TYPE_PATTERN;
|
|
1221
|
+
var init_mime_type_utils = __esm({
|
|
1222
|
+
"src/lib/utils/mime-type-utils.ts"() {
|
|
1223
|
+
DATA_URL_PATTERN = /^data:([-\w.]+\/[-\w.+]+)(;|,)/;
|
|
1224
|
+
MIME_TYPE_PATTERN = /^([-\w.]+\/[-\w.+]+)/;
|
|
1225
|
+
}
|
|
1226
|
+
});
|
|
1227
|
+
|
|
1228
|
+
// src/lib/utils/resource-utils.ts
|
|
1229
|
+
function getResourceUrlAndType(resource) {
|
|
1230
|
+
if (isResponse(resource)) {
|
|
1231
|
+
const url = stripQueryString(resource.url || "");
|
|
1232
|
+
const contentTypeHeader = resource.headers.get("content-type") || "";
|
|
1233
|
+
return {
|
|
1234
|
+
url,
|
|
1235
|
+
type: parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(url)
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
if (isBlob(resource)) {
|
|
1239
|
+
return {
|
|
1240
|
+
url: stripQueryString(resource.name || ""),
|
|
1241
|
+
type: resource.type || ""
|
|
1242
|
+
};
|
|
1243
|
+
}
|
|
1244
|
+
if (typeof resource === "string") {
|
|
1245
|
+
return {
|
|
1246
|
+
url: stripQueryString(resource),
|
|
1247
|
+
type: parseMIMETypeFromURL(resource)
|
|
1248
|
+
};
|
|
1249
|
+
}
|
|
1250
|
+
return {
|
|
1251
|
+
url: "",
|
|
1252
|
+
type: ""
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
function getResourceContentLength(resource) {
|
|
1256
|
+
if (isResponse(resource)) {
|
|
1257
|
+
return resource.headers["content-length"] || -1;
|
|
1258
|
+
}
|
|
1259
|
+
if (isBlob(resource)) {
|
|
1260
|
+
return resource.size;
|
|
1261
|
+
}
|
|
1262
|
+
if (typeof resource === "string") {
|
|
1263
|
+
return resource.length;
|
|
1264
|
+
}
|
|
1265
|
+
if (resource instanceof ArrayBuffer) {
|
|
1266
|
+
return resource.byteLength;
|
|
1267
|
+
}
|
|
1268
|
+
if (ArrayBuffer.isView(resource)) {
|
|
1269
|
+
return resource.byteLength;
|
|
1270
|
+
}
|
|
1271
|
+
return -1;
|
|
1272
|
+
}
|
|
1273
|
+
function stripQueryString(url) {
|
|
1274
|
+
return url.replace(QUERY_STRING_PATTERN, "");
|
|
1275
|
+
}
|
|
1276
|
+
var QUERY_STRING_PATTERN;
|
|
1277
|
+
var init_resource_utils = __esm({
|
|
1278
|
+
"src/lib/utils/resource-utils.ts"() {
|
|
1279
|
+
init_is_type();
|
|
1280
|
+
init_mime_type_utils();
|
|
1281
|
+
QUERY_STRING_PATTERN = /\?.*/;
|
|
1282
|
+
}
|
|
1283
|
+
});
|
|
1284
|
+
|
|
1285
|
+
// src/lib/utils/response-utils.ts
|
|
1286
|
+
async function makeResponse(resource) {
|
|
1287
|
+
if (isResponse(resource)) {
|
|
1288
|
+
return resource;
|
|
1289
|
+
}
|
|
1290
|
+
const headers = {};
|
|
1291
|
+
const contentLength = getResourceContentLength(resource);
|
|
1292
|
+
if (contentLength >= 0) {
|
|
1293
|
+
headers["content-length"] = String(contentLength);
|
|
1294
|
+
}
|
|
1295
|
+
const { url, type } = getResourceUrlAndType(resource);
|
|
1296
|
+
if (type) {
|
|
1297
|
+
headers["content-type"] = type;
|
|
1298
|
+
}
|
|
1299
|
+
const initialDataUrl = await getInitialDataUrl(resource);
|
|
1300
|
+
if (initialDataUrl) {
|
|
1301
|
+
headers["x-first-bytes"] = initialDataUrl;
|
|
1302
|
+
}
|
|
1303
|
+
if (typeof resource === "string") {
|
|
1304
|
+
resource = new TextEncoder().encode(resource);
|
|
1305
|
+
}
|
|
1306
|
+
const response = new Response(resource, { headers });
|
|
1307
|
+
Object.defineProperty(response, "url", { value: url });
|
|
1308
|
+
return response;
|
|
1309
|
+
}
|
|
1310
|
+
async function checkResponse(response) {
|
|
1311
|
+
if (!response.ok) {
|
|
1312
|
+
const message = await getResponseError(response);
|
|
1313
|
+
throw new Error(message);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
async function getResponseError(response) {
|
|
1317
|
+
let message = `Failed to fetch resource ${response.url} (${response.status}): `;
|
|
1318
|
+
try {
|
|
1319
|
+
const contentType = response.headers.get("Content-Type");
|
|
1320
|
+
let text = response.statusText;
|
|
1321
|
+
if (contentType.includes("application/json")) {
|
|
1322
|
+
text += ` ${await response.text()}`;
|
|
1323
|
+
}
|
|
1324
|
+
message += text;
|
|
1325
|
+
message = message.length > 60 ? `${message.slice(60)}...` : message;
|
|
1326
|
+
} catch (error) {
|
|
1327
|
+
}
|
|
1328
|
+
return message;
|
|
1329
|
+
}
|
|
1330
|
+
async function getInitialDataUrl(resource) {
|
|
1331
|
+
const INITIAL_DATA_LENGTH = 5;
|
|
1332
|
+
if (typeof resource === "string") {
|
|
1333
|
+
return `data:,${resource.slice(0, INITIAL_DATA_LENGTH)}`;
|
|
1334
|
+
}
|
|
1335
|
+
if (resource instanceof Blob) {
|
|
1336
|
+
const blobSlice = resource.slice(0, 5);
|
|
1337
|
+
return await new Promise((resolve) => {
|
|
1338
|
+
const reader = new FileReader();
|
|
1339
|
+
reader.onload = (event) => resolve(event?.target?.result);
|
|
1340
|
+
reader.readAsDataURL(blobSlice);
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
if (resource instanceof ArrayBuffer) {
|
|
1344
|
+
const slice = resource.slice(0, INITIAL_DATA_LENGTH);
|
|
1345
|
+
const base64 = arrayBufferToBase64(slice);
|
|
1346
|
+
return `data:base64,${base64}`;
|
|
1347
|
+
}
|
|
1348
|
+
return null;
|
|
1349
|
+
}
|
|
1350
|
+
function arrayBufferToBase64(buffer) {
|
|
1351
|
+
let binary = "";
|
|
1352
|
+
const bytes = new Uint8Array(buffer);
|
|
1353
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
1354
|
+
binary += String.fromCharCode(bytes[i]);
|
|
1355
|
+
}
|
|
1356
|
+
return btoa(binary);
|
|
1357
|
+
}
|
|
1358
|
+
var init_response_utils = __esm({
|
|
1359
|
+
"src/lib/utils/response-utils.ts"() {
|
|
1360
|
+
init_is_type();
|
|
1361
|
+
init_resource_utils();
|
|
1362
|
+
}
|
|
1363
|
+
});
|
|
1364
|
+
|
|
1365
|
+
// src/lib/fetch/fetch-file.ts
|
|
1366
|
+
async function fetchFile(url, options) {
|
|
1367
|
+
if (typeof url === "string") {
|
|
1368
|
+
url = resolvePath(url);
|
|
1369
|
+
let fetchOptions = options;
|
|
1370
|
+
if (options?.fetch && typeof options?.fetch !== "function") {
|
|
1371
|
+
fetchOptions = options.fetch;
|
|
1372
|
+
}
|
|
1373
|
+
return await fetch(url, fetchOptions);
|
|
1374
|
+
}
|
|
1375
|
+
return await makeResponse(url);
|
|
1376
|
+
}
|
|
1377
|
+
var init_fetch_file = __esm({
|
|
1378
|
+
"src/lib/fetch/fetch-file.ts"() {
|
|
1379
|
+
init_src2();
|
|
1380
|
+
init_response_utils();
|
|
1381
|
+
}
|
|
1382
|
+
});
|
|
1383
|
+
|
|
1384
|
+
// src/lib/fetch/read-array-buffer.ts
|
|
1385
|
+
async function readArrayBuffer(file, start, length) {
|
|
1386
|
+
if (typeof file === "number") {
|
|
1387
|
+
return await fs._readToArrayBuffer(file, start, length);
|
|
1388
|
+
}
|
|
1389
|
+
if (!(file instanceof Blob)) {
|
|
1390
|
+
file = new Blob([file]);
|
|
1391
|
+
}
|
|
1392
|
+
const slice = file.slice(start, start + length);
|
|
1393
|
+
return await readBlob(slice);
|
|
1394
|
+
}
|
|
1395
|
+
async function readBlob(blob) {
|
|
1396
|
+
return await new Promise((resolve, reject) => {
|
|
1397
|
+
const fileReader = new FileReader();
|
|
1398
|
+
fileReader.onload = (event) => resolve(event?.target?.result);
|
|
1399
|
+
fileReader.onerror = (error) => reject(error);
|
|
1400
|
+
fileReader.readAsArrayBuffer(blob);
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
var init_read_array_buffer = __esm({
|
|
1404
|
+
"src/lib/fetch/read-array-buffer.ts"() {
|
|
1405
|
+
init_src2();
|
|
1406
|
+
}
|
|
1407
|
+
});
|
|
1408
|
+
|
|
1409
|
+
// src/lib/fetch/read-file.ts
|
|
1410
|
+
function readFileSync(url, options = {}) {
|
|
1411
|
+
url = resolvePath(url);
|
|
1412
|
+
if (!isBrowser) {
|
|
1413
|
+
const buffer = fs.readFileSync(url, options);
|
|
1414
|
+
return typeof buffer !== "string" ? toArrayBuffer(buffer) : buffer;
|
|
1415
|
+
}
|
|
1416
|
+
if (!options.nothrow) {
|
|
1417
|
+
assert(false);
|
|
1418
|
+
}
|
|
1419
|
+
return null;
|
|
1420
|
+
}
|
|
1421
|
+
var init_read_file = __esm({
|
|
1422
|
+
"src/lib/fetch/read-file.ts"() {
|
|
1423
|
+
init_src2();
|
|
1424
|
+
init_src2();
|
|
1425
|
+
}
|
|
1426
|
+
});
|
|
1427
|
+
|
|
1428
|
+
// src/lib/fetch/write-file.ts
|
|
1429
|
+
async function writeFile(filePath, arrayBufferOrString, options) {
|
|
1430
|
+
filePath = resolvePath(filePath);
|
|
1431
|
+
if (!isBrowser) {
|
|
1432
|
+
await fs.writeFile(filePath, toBuffer2(arrayBufferOrString), { flag: "w" });
|
|
1433
|
+
}
|
|
1434
|
+
assert(false);
|
|
1435
|
+
}
|
|
1436
|
+
function writeFileSync(filePath, arrayBufferOrString, options) {
|
|
1437
|
+
filePath = resolvePath(filePath);
|
|
1438
|
+
if (!isBrowser) {
|
|
1439
|
+
fs.writeFileSync(filePath, toBuffer2(arrayBufferOrString), { flag: "w" });
|
|
1440
|
+
}
|
|
1441
|
+
assert(false);
|
|
1442
|
+
}
|
|
1443
|
+
var init_write_file = __esm({
|
|
1444
|
+
"src/lib/fetch/write-file.ts"() {
|
|
1445
|
+
init_src2();
|
|
1446
|
+
init_src2();
|
|
1447
|
+
}
|
|
1448
|
+
});
|
|
1449
|
+
|
|
1450
|
+
// ../../node_modules/probe.gl/dist/esm/env/is-electron.js
|
|
1451
|
+
function isElectron(mockUserAgent) {
|
|
1452
|
+
if (typeof window !== "undefined" && typeof window.process === "object" && window.process.type === "renderer") {
|
|
1453
|
+
return true;
|
|
1454
|
+
}
|
|
1455
|
+
if (typeof process !== "undefined" && typeof process.versions === "object" && Boolean(process.versions.electron)) {
|
|
1456
|
+
return true;
|
|
1457
|
+
}
|
|
1458
|
+
const realUserAgent = typeof navigator === "object" && typeof navigator.userAgent === "string" && navigator.userAgent;
|
|
1459
|
+
const userAgent = mockUserAgent || realUserAgent;
|
|
1460
|
+
if (userAgent && userAgent.indexOf("Electron") >= 0) {
|
|
1461
|
+
return true;
|
|
1462
|
+
}
|
|
1463
|
+
return false;
|
|
1464
|
+
}
|
|
1465
|
+
var init_is_electron = __esm({
|
|
1466
|
+
"../../node_modules/probe.gl/dist/esm/env/is-electron.js"() {
|
|
1467
|
+
}
|
|
1468
|
+
});
|
|
1469
|
+
|
|
1470
|
+
// ../../node_modules/probe.gl/dist/esm/env/is-browser.js
|
|
1471
|
+
function isBrowser3() {
|
|
1472
|
+
const isNode = typeof process === "object" && String(process) === "[object process]" && !process.browser;
|
|
1473
|
+
return !isNode || isElectron();
|
|
1474
|
+
}
|
|
1475
|
+
var init_is_browser = __esm({
|
|
1476
|
+
"../../node_modules/probe.gl/dist/esm/env/is-browser.js"() {
|
|
1477
|
+
init_is_electron();
|
|
1478
|
+
}
|
|
1479
|
+
});
|
|
1480
|
+
|
|
1481
|
+
// ../../node_modules/probe.gl/dist/esm/env/globals.js
|
|
1482
|
+
var globals3, self_3, window_3, global_3, document_3, process_;
|
|
1483
|
+
var init_globals3 = __esm({
|
|
1484
|
+
"../../node_modules/probe.gl/dist/esm/env/globals.js"() {
|
|
1485
|
+
globals3 = {
|
|
1486
|
+
self: typeof self !== "undefined" && self,
|
|
1487
|
+
window: typeof window !== "undefined" && window,
|
|
1488
|
+
global: typeof global !== "undefined" && global,
|
|
1489
|
+
document: typeof document !== "undefined" && document,
|
|
1490
|
+
process: typeof process === "object" && process
|
|
1491
|
+
};
|
|
1492
|
+
self_3 = globals3.self || globals3.window || globals3.global;
|
|
1493
|
+
window_3 = globals3.window || globals3.self || globals3.global;
|
|
1494
|
+
global_3 = globals3.global || globals3.self || globals3.window;
|
|
1495
|
+
document_3 = globals3.document || {};
|
|
1496
|
+
process_ = globals3.process || {};
|
|
1497
|
+
}
|
|
1498
|
+
});
|
|
1499
|
+
|
|
1500
|
+
// ../../node_modules/probe.gl/dist/esm/utils/globals.js
|
|
1501
|
+
var VERSION3, isBrowser4;
|
|
1502
|
+
var init_globals4 = __esm({
|
|
1503
|
+
"../../node_modules/probe.gl/dist/esm/utils/globals.js"() {
|
|
1504
|
+
init_is_browser();
|
|
1505
|
+
init_globals3();
|
|
1506
|
+
VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "untranspiled source";
|
|
1507
|
+
isBrowser4 = isBrowser3();
|
|
1508
|
+
}
|
|
1509
|
+
});
|
|
1510
|
+
|
|
1511
|
+
// ../../node_modules/probe.gl/dist/esm/utils/local-storage.js
|
|
1512
|
+
function getStorage(type) {
|
|
1513
|
+
try {
|
|
1514
|
+
const storage = window[type];
|
|
1515
|
+
const x = "__storage_test__";
|
|
1516
|
+
storage.setItem(x, x);
|
|
1517
|
+
storage.removeItem(x);
|
|
1518
|
+
return storage;
|
|
1519
|
+
} catch (e) {
|
|
1520
|
+
return null;
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
var LocalStorage;
|
|
1524
|
+
var init_local_storage = __esm({
|
|
1525
|
+
"../../node_modules/probe.gl/dist/esm/utils/local-storage.js"() {
|
|
1526
|
+
LocalStorage = class {
|
|
1527
|
+
constructor(id, defaultSettings, type = "sessionStorage") {
|
|
1528
|
+
this.storage = getStorage(type);
|
|
1529
|
+
this.id = id;
|
|
1530
|
+
this.config = {};
|
|
1531
|
+
Object.assign(this.config, defaultSettings);
|
|
1532
|
+
this._loadConfiguration();
|
|
1533
|
+
}
|
|
1534
|
+
getConfiguration() {
|
|
1535
|
+
return this.config;
|
|
1536
|
+
}
|
|
1537
|
+
setConfiguration(configuration) {
|
|
1538
|
+
this.config = {};
|
|
1539
|
+
return this.updateConfiguration(configuration);
|
|
1540
|
+
}
|
|
1541
|
+
updateConfiguration(configuration) {
|
|
1542
|
+
Object.assign(this.config, configuration);
|
|
1543
|
+
if (this.storage) {
|
|
1544
|
+
const serialized = JSON.stringify(this.config);
|
|
1545
|
+
this.storage.setItem(this.id, serialized);
|
|
1546
|
+
}
|
|
1547
|
+
return this;
|
|
1548
|
+
}
|
|
1549
|
+
_loadConfiguration() {
|
|
1550
|
+
let configuration = {};
|
|
1551
|
+
if (this.storage) {
|
|
1552
|
+
const serializedConfiguration = this.storage.getItem(this.id);
|
|
1553
|
+
configuration = serializedConfiguration ? JSON.parse(serializedConfiguration) : {};
|
|
1554
|
+
}
|
|
1555
|
+
Object.assign(this.config, configuration);
|
|
1556
|
+
return this;
|
|
1557
|
+
}
|
|
1558
|
+
};
|
|
1559
|
+
}
|
|
1560
|
+
});
|
|
1561
|
+
|
|
1562
|
+
// ../../node_modules/probe.gl/dist/esm/utils/formatters.js
|
|
1563
|
+
function formatTime(ms) {
|
|
1564
|
+
let formatted;
|
|
1565
|
+
if (ms < 10) {
|
|
1566
|
+
formatted = "".concat(ms.toFixed(2), "ms");
|
|
1567
|
+
} else if (ms < 100) {
|
|
1568
|
+
formatted = "".concat(ms.toFixed(1), "ms");
|
|
1569
|
+
} else if (ms < 1e3) {
|
|
1570
|
+
formatted = "".concat(ms.toFixed(0), "ms");
|
|
1571
|
+
} else {
|
|
1572
|
+
formatted = "".concat((ms / 1e3).toFixed(2), "s");
|
|
1573
|
+
}
|
|
1574
|
+
return formatted;
|
|
1575
|
+
}
|
|
1576
|
+
function leftPad(string, length = 8) {
|
|
1577
|
+
const padLength = Math.max(length - string.length, 0);
|
|
1578
|
+
return "".concat(" ".repeat(padLength)).concat(string);
|
|
1579
|
+
}
|
|
1580
|
+
function formatImage(image, message, scale, maxWidth = 600) {
|
|
1581
|
+
const imageUrl = image.src.replace(/\(/g, "%28").replace(/\)/g, "%29");
|
|
1582
|
+
if (image.width > maxWidth) {
|
|
1583
|
+
scale = Math.min(scale, maxWidth / image.width);
|
|
1584
|
+
}
|
|
1585
|
+
const width = image.width * scale;
|
|
1586
|
+
const height = image.height * scale;
|
|
1587
|
+
const style = ["font-size:1px;", "padding:".concat(Math.floor(height / 2), "px ").concat(Math.floor(width / 2), "px;"), "line-height:".concat(height, "px;"), "background:url(".concat(imageUrl, ");"), "background-size:".concat(width, "px ").concat(height, "px;"), "color:transparent;"].join("");
|
|
1588
|
+
return ["".concat(message, " %c+"), style];
|
|
1589
|
+
}
|
|
1590
|
+
var init_formatters = __esm({
|
|
1591
|
+
"../../node_modules/probe.gl/dist/esm/utils/formatters.js"() {
|
|
1592
|
+
}
|
|
1593
|
+
});
|
|
1594
|
+
|
|
1595
|
+
// ../../node_modules/probe.gl/dist/esm/utils/color.js
|
|
1596
|
+
function getColor(color) {
|
|
1597
|
+
return typeof color === "string" ? COLOR[color.toUpperCase()] || COLOR.WHITE : color;
|
|
1598
|
+
}
|
|
1599
|
+
function addColor(string, color, background) {
|
|
1600
|
+
if (!isBrowser4 && typeof string === "string") {
|
|
1601
|
+
if (color) {
|
|
1602
|
+
color = getColor(color);
|
|
1603
|
+
string = "[".concat(color, "m").concat(string, "[39m");
|
|
1604
|
+
}
|
|
1605
|
+
if (background) {
|
|
1606
|
+
color = getColor(background);
|
|
1607
|
+
string = "[".concat(background + 10, "m").concat(string, "[49m");
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
return string;
|
|
1611
|
+
}
|
|
1612
|
+
var COLOR;
|
|
1613
|
+
var init_color = __esm({
|
|
1614
|
+
"../../node_modules/probe.gl/dist/esm/utils/color.js"() {
|
|
1615
|
+
init_globals4();
|
|
1616
|
+
COLOR = {
|
|
1617
|
+
BLACK: 30,
|
|
1618
|
+
RED: 31,
|
|
1619
|
+
GREEN: 32,
|
|
1620
|
+
YELLOW: 33,
|
|
1621
|
+
BLUE: 34,
|
|
1622
|
+
MAGENTA: 35,
|
|
1623
|
+
CYAN: 36,
|
|
1624
|
+
WHITE: 37,
|
|
1625
|
+
BRIGHT_BLACK: 90,
|
|
1626
|
+
BRIGHT_RED: 91,
|
|
1627
|
+
BRIGHT_GREEN: 92,
|
|
1628
|
+
BRIGHT_YELLOW: 93,
|
|
1629
|
+
BRIGHT_BLUE: 94,
|
|
1630
|
+
BRIGHT_MAGENTA: 95,
|
|
1631
|
+
BRIGHT_CYAN: 96,
|
|
1632
|
+
BRIGHT_WHITE: 97
|
|
1633
|
+
};
|
|
1634
|
+
}
|
|
1635
|
+
});
|
|
1636
|
+
|
|
1637
|
+
// ../../node_modules/probe.gl/dist/esm/utils/autobind.js
|
|
1638
|
+
function autobind(obj, predefined = ["constructor"]) {
|
|
1639
|
+
const proto = Object.getPrototypeOf(obj);
|
|
1640
|
+
const propNames = Object.getOwnPropertyNames(proto);
|
|
1641
|
+
for (const key of propNames) {
|
|
1642
|
+
if (typeof obj[key] === "function") {
|
|
1643
|
+
if (!predefined.find((name) => key === name)) {
|
|
1644
|
+
obj[key] = obj[key].bind(obj);
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
var init_autobind = __esm({
|
|
1650
|
+
"../../node_modules/probe.gl/dist/esm/utils/autobind.js"() {
|
|
1651
|
+
}
|
|
1652
|
+
});
|
|
1653
|
+
|
|
1654
|
+
// ../../node_modules/probe.gl/dist/esm/utils/assert.js
|
|
1655
|
+
function assert3(condition, message) {
|
|
1656
|
+
if (!condition) {
|
|
1657
|
+
throw new Error(message || "Assertion failed");
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
var init_assert3 = __esm({
|
|
1661
|
+
"../../node_modules/probe.gl/dist/esm/utils/assert.js"() {
|
|
1662
|
+
}
|
|
1663
|
+
});
|
|
1664
|
+
|
|
1665
|
+
// ../../node_modules/probe.gl/dist/esm/utils/hi-res-timestamp.js
|
|
1666
|
+
function getHiResTimestamp2() {
|
|
1667
|
+
let timestamp;
|
|
1668
|
+
if (isBrowser4 && window_3.performance) {
|
|
1669
|
+
timestamp = window_3.performance.now();
|
|
1670
|
+
} else if (process_.hrtime) {
|
|
1671
|
+
const timeParts = process_.hrtime();
|
|
1672
|
+
timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
|
|
1673
|
+
} else {
|
|
1674
|
+
timestamp = Date.now();
|
|
1675
|
+
}
|
|
1676
|
+
return timestamp;
|
|
1677
|
+
}
|
|
1678
|
+
var init_hi_res_timestamp2 = __esm({
|
|
1679
|
+
"../../node_modules/probe.gl/dist/esm/utils/hi-res-timestamp.js"() {
|
|
1680
|
+
init_globals4();
|
|
1681
|
+
}
|
|
1682
|
+
});
|
|
1683
|
+
|
|
1684
|
+
// ../../node_modules/probe.gl/dist/esm/lib/log.js
|
|
1685
|
+
function noop() {
|
|
1686
|
+
}
|
|
1687
|
+
function getTableHeader(table) {
|
|
1688
|
+
for (const key in table) {
|
|
1689
|
+
for (const title in table[key]) {
|
|
1690
|
+
return title || "untitled";
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
return "empty";
|
|
1694
|
+
}
|
|
1695
|
+
function normalizeLogLevel(logLevel) {
|
|
1696
|
+
if (!logLevel) {
|
|
1697
|
+
return 0;
|
|
1698
|
+
}
|
|
1699
|
+
let resolvedLevel;
|
|
1700
|
+
switch (typeof logLevel) {
|
|
1701
|
+
case "number":
|
|
1702
|
+
resolvedLevel = logLevel;
|
|
1703
|
+
break;
|
|
1704
|
+
case "object":
|
|
1705
|
+
resolvedLevel = logLevel.logLevel || logLevel.priority || 0;
|
|
1706
|
+
break;
|
|
1707
|
+
default:
|
|
1708
|
+
return 0;
|
|
1709
|
+
}
|
|
1710
|
+
assert3(Number.isFinite(resolvedLevel) && resolvedLevel >= 0);
|
|
1711
|
+
return resolvedLevel;
|
|
1712
|
+
}
|
|
1713
|
+
function normalizeArguments(opts) {
|
|
1714
|
+
const {
|
|
1715
|
+
logLevel,
|
|
1716
|
+
message
|
|
1717
|
+
} = opts;
|
|
1718
|
+
opts.logLevel = normalizeLogLevel(logLevel);
|
|
1719
|
+
const args = opts.args ? Array.from(opts.args) : [];
|
|
1720
|
+
while (args.length && args.shift() !== message) {
|
|
1721
|
+
}
|
|
1722
|
+
opts.args = args;
|
|
1723
|
+
switch (typeof logLevel) {
|
|
1724
|
+
case "string":
|
|
1725
|
+
case "function":
|
|
1726
|
+
if (message !== void 0) {
|
|
1727
|
+
args.unshift(message);
|
|
1728
|
+
}
|
|
1729
|
+
opts.message = logLevel;
|
|
1730
|
+
break;
|
|
1731
|
+
case "object":
|
|
1732
|
+
Object.assign(opts, logLevel);
|
|
1733
|
+
break;
|
|
1734
|
+
default:
|
|
1735
|
+
}
|
|
1736
|
+
if (typeof opts.message === "function") {
|
|
1737
|
+
opts.message = opts.message();
|
|
1738
|
+
}
|
|
1739
|
+
const messageType = typeof opts.message;
|
|
1740
|
+
assert3(messageType === "string" || messageType === "object");
|
|
1741
|
+
return Object.assign(opts, opts.opts);
|
|
1742
|
+
}
|
|
1743
|
+
function decorateMessage(id, message, opts) {
|
|
1744
|
+
if (typeof message === "string") {
|
|
1745
|
+
const time = opts.time ? leftPad(formatTime(opts.total)) : "";
|
|
1746
|
+
message = opts.time ? "".concat(id, ": ").concat(time, " ").concat(message) : "".concat(id, ": ").concat(message);
|
|
1747
|
+
message = addColor(message, opts.color, opts.background);
|
|
1748
|
+
}
|
|
1749
|
+
return message;
|
|
1750
|
+
}
|
|
1751
|
+
function logImageInNode({
|
|
1752
|
+
image,
|
|
1753
|
+
message = "",
|
|
1754
|
+
scale = 1
|
|
1755
|
+
}) {
|
|
1756
|
+
let asciify = null;
|
|
1757
|
+
try {
|
|
1758
|
+
asciify = module.require("asciify-image");
|
|
1759
|
+
} catch (error) {
|
|
1760
|
+
}
|
|
1761
|
+
if (asciify) {
|
|
1762
|
+
return () => asciify(image, {
|
|
1763
|
+
fit: "box",
|
|
1764
|
+
width: "".concat(Math.round(80 * scale), "%")
|
|
1765
|
+
}).then((data) => console.log(data));
|
|
1766
|
+
}
|
|
1767
|
+
return noop;
|
|
1768
|
+
}
|
|
1769
|
+
function logImageInBrowser({
|
|
1770
|
+
image,
|
|
1771
|
+
message = "",
|
|
1772
|
+
scale = 1
|
|
1773
|
+
}) {
|
|
1774
|
+
if (typeof image === "string") {
|
|
1775
|
+
const img = new Image();
|
|
1776
|
+
img.onload = () => {
|
|
1777
|
+
const args = formatImage(img, message, scale);
|
|
1778
|
+
console.log(...args);
|
|
1779
|
+
};
|
|
1780
|
+
img.src = image;
|
|
1781
|
+
return noop;
|
|
1782
|
+
}
|
|
1783
|
+
const element = image.nodeName || "";
|
|
1784
|
+
if (element.toLowerCase() === "img") {
|
|
1785
|
+
console.log(...formatImage(image, message, scale));
|
|
1786
|
+
return noop;
|
|
1787
|
+
}
|
|
1788
|
+
if (element.toLowerCase() === "canvas") {
|
|
1789
|
+
const img = new Image();
|
|
1790
|
+
img.onload = () => console.log(...formatImage(img, message, scale));
|
|
1791
|
+
img.src = image.toDataURL();
|
|
1792
|
+
return noop;
|
|
1793
|
+
}
|
|
1794
|
+
return noop;
|
|
1795
|
+
}
|
|
1796
|
+
var originalConsole, DEFAULT_SETTINGS, cache, ONCE, Log;
|
|
1797
|
+
var init_log = __esm({
|
|
1798
|
+
"../../node_modules/probe.gl/dist/esm/lib/log.js"() {
|
|
1799
|
+
init_globals4();
|
|
1800
|
+
init_local_storage();
|
|
1801
|
+
init_formatters();
|
|
1802
|
+
init_color();
|
|
1803
|
+
init_autobind();
|
|
1804
|
+
init_assert3();
|
|
1805
|
+
init_hi_res_timestamp2();
|
|
1806
|
+
originalConsole = {
|
|
1807
|
+
debug: isBrowser4 ? console.debug || console.log : console.log,
|
|
1808
|
+
log: console.log,
|
|
1809
|
+
info: console.info,
|
|
1810
|
+
warn: console.warn,
|
|
1811
|
+
error: console.error
|
|
1812
|
+
};
|
|
1813
|
+
DEFAULT_SETTINGS = {
|
|
1814
|
+
enabled: true,
|
|
1815
|
+
level: 0
|
|
1816
|
+
};
|
|
1817
|
+
cache = {};
|
|
1818
|
+
ONCE = {
|
|
1819
|
+
once: true
|
|
1820
|
+
};
|
|
1821
|
+
Log = class {
|
|
1822
|
+
constructor({
|
|
1823
|
+
id
|
|
1824
|
+
} = {
|
|
1825
|
+
id: ""
|
|
1826
|
+
}) {
|
|
1827
|
+
this.id = id;
|
|
1828
|
+
this.VERSION = VERSION3;
|
|
1829
|
+
this._startTs = getHiResTimestamp2();
|
|
1830
|
+
this._deltaTs = getHiResTimestamp2();
|
|
1831
|
+
this.LOG_THROTTLE_TIMEOUT = 0;
|
|
1832
|
+
this._storage = new LocalStorage("__probe-".concat(this.id, "__"), DEFAULT_SETTINGS);
|
|
1833
|
+
this.userData = {};
|
|
1834
|
+
this.timeStamp("".concat(this.id, " started"));
|
|
1835
|
+
autobind(this);
|
|
1836
|
+
Object.seal(this);
|
|
1837
|
+
}
|
|
1838
|
+
set level(newLevel) {
|
|
1839
|
+
this.setLevel(newLevel);
|
|
1840
|
+
}
|
|
1841
|
+
get level() {
|
|
1842
|
+
return this.getLevel();
|
|
1843
|
+
}
|
|
1844
|
+
isEnabled() {
|
|
1845
|
+
return this._storage.config.enabled;
|
|
1846
|
+
}
|
|
1847
|
+
getLevel() {
|
|
1848
|
+
return this._storage.config.level;
|
|
1849
|
+
}
|
|
1850
|
+
getTotal() {
|
|
1851
|
+
return Number((getHiResTimestamp2() - this._startTs).toPrecision(10));
|
|
1852
|
+
}
|
|
1853
|
+
getDelta() {
|
|
1854
|
+
return Number((getHiResTimestamp2() - this._deltaTs).toPrecision(10));
|
|
1855
|
+
}
|
|
1856
|
+
set priority(newPriority) {
|
|
1857
|
+
this.level = newPriority;
|
|
1858
|
+
}
|
|
1859
|
+
get priority() {
|
|
1860
|
+
return this.level;
|
|
1861
|
+
}
|
|
1862
|
+
getPriority() {
|
|
1863
|
+
return this.level;
|
|
1864
|
+
}
|
|
1865
|
+
enable(enabled = true) {
|
|
1866
|
+
this._storage.updateConfiguration({
|
|
1867
|
+
enabled
|
|
1868
|
+
});
|
|
1869
|
+
return this;
|
|
1870
|
+
}
|
|
1871
|
+
setLevel(level) {
|
|
1872
|
+
this._storage.updateConfiguration({
|
|
1873
|
+
level
|
|
1874
|
+
});
|
|
1875
|
+
return this;
|
|
1876
|
+
}
|
|
1877
|
+
assert(condition, message) {
|
|
1878
|
+
assert3(condition, message);
|
|
1879
|
+
}
|
|
1880
|
+
warn(message) {
|
|
1881
|
+
return this._getLogFunction(0, message, originalConsole.warn, arguments, ONCE);
|
|
1882
|
+
}
|
|
1883
|
+
error(message) {
|
|
1884
|
+
return this._getLogFunction(0, message, originalConsole.error, arguments);
|
|
1885
|
+
}
|
|
1886
|
+
deprecated(oldUsage, newUsage) {
|
|
1887
|
+
return this.warn("`".concat(oldUsage, "` is deprecated and will be removed in a later version. Use `").concat(newUsage, "` instead"));
|
|
1888
|
+
}
|
|
1889
|
+
removed(oldUsage, newUsage) {
|
|
1890
|
+
return this.error("`".concat(oldUsage, "` has been removed. Use `").concat(newUsage, "` instead"));
|
|
1891
|
+
}
|
|
1892
|
+
probe(logLevel, message) {
|
|
1893
|
+
return this._getLogFunction(logLevel, message, originalConsole.log, arguments, {
|
|
1894
|
+
time: true,
|
|
1895
|
+
once: true
|
|
1896
|
+
});
|
|
1897
|
+
}
|
|
1898
|
+
log(logLevel, message) {
|
|
1899
|
+
return this._getLogFunction(logLevel, message, originalConsole.debug, arguments);
|
|
1900
|
+
}
|
|
1901
|
+
info(logLevel, message) {
|
|
1902
|
+
return this._getLogFunction(logLevel, message, console.info, arguments);
|
|
1903
|
+
}
|
|
1904
|
+
once(logLevel, message) {
|
|
1905
|
+
return this._getLogFunction(logLevel, message, originalConsole.debug || originalConsole.info, arguments, ONCE);
|
|
1906
|
+
}
|
|
1907
|
+
table(logLevel, table, columns) {
|
|
1908
|
+
if (table) {
|
|
1909
|
+
return this._getLogFunction(logLevel, table, console.table || noop, columns && [columns], {
|
|
1910
|
+
tag: getTableHeader(table)
|
|
1911
|
+
});
|
|
1912
|
+
}
|
|
1913
|
+
return noop;
|
|
1914
|
+
}
|
|
1915
|
+
image({
|
|
1916
|
+
logLevel,
|
|
1917
|
+
priority,
|
|
1918
|
+
image,
|
|
1919
|
+
message = "",
|
|
1920
|
+
scale = 1
|
|
1921
|
+
}) {
|
|
1922
|
+
if (!this._shouldLog(logLevel || priority)) {
|
|
1923
|
+
return noop;
|
|
1924
|
+
}
|
|
1925
|
+
return isBrowser4 ? logImageInBrowser({
|
|
1926
|
+
image,
|
|
1927
|
+
message,
|
|
1928
|
+
scale
|
|
1929
|
+
}) : logImageInNode({
|
|
1930
|
+
image,
|
|
1931
|
+
message,
|
|
1932
|
+
scale
|
|
1933
|
+
});
|
|
1934
|
+
}
|
|
1935
|
+
settings() {
|
|
1936
|
+
if (console.table) {
|
|
1937
|
+
console.table(this._storage.config);
|
|
1938
|
+
} else {
|
|
1939
|
+
console.log(this._storage.config);
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
get(setting) {
|
|
1943
|
+
return this._storage.config[setting];
|
|
1944
|
+
}
|
|
1945
|
+
set(setting, value) {
|
|
1946
|
+
this._storage.updateConfiguration({
|
|
1947
|
+
[setting]: value
|
|
1948
|
+
});
|
|
1949
|
+
}
|
|
1950
|
+
time(logLevel, message) {
|
|
1951
|
+
return this._getLogFunction(logLevel, message, console.time ? console.time : console.info);
|
|
1952
|
+
}
|
|
1953
|
+
timeEnd(logLevel, message) {
|
|
1954
|
+
return this._getLogFunction(logLevel, message, console.timeEnd ? console.timeEnd : console.info);
|
|
1955
|
+
}
|
|
1956
|
+
timeStamp(logLevel, message) {
|
|
1957
|
+
return this._getLogFunction(logLevel, message, console.timeStamp || noop);
|
|
1958
|
+
}
|
|
1959
|
+
group(logLevel, message, opts = {
|
|
1960
|
+
collapsed: false
|
|
1961
|
+
}) {
|
|
1962
|
+
opts = normalizeArguments({
|
|
1963
|
+
logLevel,
|
|
1964
|
+
message,
|
|
1965
|
+
opts
|
|
1966
|
+
});
|
|
1967
|
+
const {
|
|
1968
|
+
collapsed
|
|
1969
|
+
} = opts;
|
|
1970
|
+
opts.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
|
|
1971
|
+
return this._getLogFunction(opts);
|
|
1972
|
+
}
|
|
1973
|
+
groupCollapsed(logLevel, message, opts = {}) {
|
|
1974
|
+
return this.group(logLevel, message, Object.assign({}, opts, {
|
|
1975
|
+
collapsed: true
|
|
1976
|
+
}));
|
|
1977
|
+
}
|
|
1978
|
+
groupEnd(logLevel) {
|
|
1979
|
+
return this._getLogFunction(logLevel, "", console.groupEnd || noop);
|
|
1980
|
+
}
|
|
1981
|
+
withGroup(logLevel, message, func) {
|
|
1982
|
+
this.group(logLevel, message)();
|
|
1983
|
+
try {
|
|
1984
|
+
func();
|
|
1985
|
+
} finally {
|
|
1986
|
+
this.groupEnd(logLevel)();
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
trace() {
|
|
1990
|
+
if (console.trace) {
|
|
1991
|
+
console.trace();
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
_shouldLog(logLevel) {
|
|
1995
|
+
return this.isEnabled() && this.getLevel() >= normalizeLogLevel(logLevel);
|
|
1996
|
+
}
|
|
1997
|
+
_getLogFunction(logLevel, message, method, args = [], opts) {
|
|
1998
|
+
if (this._shouldLog(logLevel)) {
|
|
1999
|
+
opts = normalizeArguments({
|
|
2000
|
+
logLevel,
|
|
2001
|
+
message,
|
|
2002
|
+
args,
|
|
2003
|
+
opts
|
|
2004
|
+
});
|
|
2005
|
+
method = method || opts.method;
|
|
2006
|
+
assert3(method);
|
|
2007
|
+
opts.total = this.getTotal();
|
|
2008
|
+
opts.delta = this.getDelta();
|
|
2009
|
+
this._deltaTs = getHiResTimestamp2();
|
|
2010
|
+
const tag = opts.tag || opts.message;
|
|
2011
|
+
if (opts.once) {
|
|
2012
|
+
if (!cache[tag]) {
|
|
2013
|
+
cache[tag] = getHiResTimestamp2();
|
|
2014
|
+
} else {
|
|
2015
|
+
return noop;
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
message = decorateMessage(this.id, opts.message, opts);
|
|
2019
|
+
return method.bind(console, message, ...opts.args);
|
|
2020
|
+
}
|
|
2021
|
+
return noop;
|
|
2022
|
+
}
|
|
2023
|
+
};
|
|
2024
|
+
Log.VERSION = VERSION3;
|
|
2025
|
+
}
|
|
2026
|
+
});
|
|
2027
|
+
|
|
2028
|
+
// ../../node_modules/probe.gl/node_modules/@probe.gl/stats/dist/esm/utils/hi-res-timestamp.js
|
|
2029
|
+
var init_hi_res_timestamp3 = __esm({
|
|
2030
|
+
"../../node_modules/probe.gl/node_modules/@probe.gl/stats/dist/esm/utils/hi-res-timestamp.js"() {
|
|
2031
|
+
}
|
|
2032
|
+
});
|
|
2033
|
+
|
|
2034
|
+
// ../../node_modules/probe.gl/node_modules/@probe.gl/stats/dist/esm/lib/stat.js
|
|
2035
|
+
var init_stat2 = __esm({
|
|
2036
|
+
"../../node_modules/probe.gl/node_modules/@probe.gl/stats/dist/esm/lib/stat.js"() {
|
|
2037
|
+
init_hi_res_timestamp3();
|
|
2038
|
+
}
|
|
2039
|
+
});
|
|
2040
|
+
|
|
2041
|
+
// ../../node_modules/probe.gl/node_modules/@probe.gl/stats/dist/esm/lib/stats.js
|
|
2042
|
+
var init_stats2 = __esm({
|
|
2043
|
+
"../../node_modules/probe.gl/node_modules/@probe.gl/stats/dist/esm/lib/stats.js"() {
|
|
2044
|
+
init_stat2();
|
|
2045
|
+
}
|
|
2046
|
+
});
|
|
2047
|
+
|
|
2048
|
+
// ../../node_modules/probe.gl/node_modules/@probe.gl/stats/dist/esm/index.js
|
|
2049
|
+
var init_esm2 = __esm({
|
|
2050
|
+
"../../node_modules/probe.gl/node_modules/@probe.gl/stats/dist/esm/index.js"() {
|
|
2051
|
+
init_stats2();
|
|
2052
|
+
init_stat2();
|
|
2053
|
+
init_hi_res_timestamp3();
|
|
2054
|
+
}
|
|
2055
|
+
});
|
|
2056
|
+
|
|
2057
|
+
// ../../node_modules/probe.gl/dist/esm/index.js
|
|
2058
|
+
var esm_default;
|
|
2059
|
+
var init_esm3 = __esm({
|
|
2060
|
+
"../../node_modules/probe.gl/dist/esm/index.js"() {
|
|
2061
|
+
init_log();
|
|
2062
|
+
init_log();
|
|
2063
|
+
init_esm2();
|
|
2064
|
+
esm_default = new Log({
|
|
2065
|
+
id: "probe.gl"
|
|
2066
|
+
});
|
|
2067
|
+
}
|
|
2068
|
+
});
|
|
2069
|
+
|
|
2070
|
+
// src/lib/loader-utils/loggers.ts
|
|
2071
|
+
var probeLog, NullLog, ConsoleLog;
|
|
2072
|
+
var init_loggers = __esm({
|
|
2073
|
+
"src/lib/loader-utils/loggers.ts"() {
|
|
2074
|
+
init_esm3();
|
|
2075
|
+
probeLog = new Log({ id: "loaders.gl" });
|
|
2076
|
+
NullLog = class {
|
|
2077
|
+
log() {
|
|
2078
|
+
return () => {
|
|
2079
|
+
};
|
|
2080
|
+
}
|
|
2081
|
+
info() {
|
|
2082
|
+
return () => {
|
|
2083
|
+
};
|
|
2084
|
+
}
|
|
2085
|
+
warn() {
|
|
2086
|
+
return () => {
|
|
2087
|
+
};
|
|
2088
|
+
}
|
|
2089
|
+
error() {
|
|
2090
|
+
return () => {
|
|
2091
|
+
};
|
|
2092
|
+
}
|
|
2093
|
+
};
|
|
2094
|
+
ConsoleLog = class {
|
|
2095
|
+
constructor() {
|
|
2096
|
+
this.console = console;
|
|
2097
|
+
}
|
|
2098
|
+
log(...args) {
|
|
2099
|
+
return this.console.log.bind(this.console, ...args);
|
|
2100
|
+
}
|
|
2101
|
+
info(...args) {
|
|
2102
|
+
return this.console.info.bind(this.console, ...args);
|
|
2103
|
+
}
|
|
2104
|
+
warn(...args) {
|
|
2105
|
+
return this.console.warn.bind(this.console, ...args);
|
|
2106
|
+
}
|
|
2107
|
+
error(...args) {
|
|
2108
|
+
return this.console.error.bind(this.console, ...args);
|
|
2109
|
+
}
|
|
2110
|
+
};
|
|
2111
|
+
}
|
|
2112
|
+
});
|
|
2113
|
+
|
|
2114
|
+
// src/lib/loader-utils/option-defaults.ts
|
|
2115
|
+
var DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS;
|
|
2116
|
+
var init_option_defaults = __esm({
|
|
2117
|
+
"src/lib/loader-utils/option-defaults.ts"() {
|
|
2118
|
+
init_loggers();
|
|
2119
|
+
DEFAULT_LOADER_OPTIONS = {
|
|
2120
|
+
fetch: null,
|
|
2121
|
+
mimeType: void 0,
|
|
2122
|
+
nothrow: false,
|
|
2123
|
+
log: new ConsoleLog(),
|
|
2124
|
+
CDN: "https://unpkg.com/@loaders.gl",
|
|
2125
|
+
worker: true,
|
|
2126
|
+
maxConcurrency: 3,
|
|
2127
|
+
maxMobileConcurrency: 1,
|
|
2128
|
+
reuseWorkers: true,
|
|
2129
|
+
_workerType: "",
|
|
2130
|
+
limit: 0,
|
|
2131
|
+
_limitMB: 0,
|
|
2132
|
+
batchSize: "auto",
|
|
2133
|
+
batchDebounceMs: 0,
|
|
2134
|
+
metadata: false,
|
|
2135
|
+
transforms: []
|
|
2136
|
+
};
|
|
2137
|
+
REMOVED_LOADER_OPTIONS = {
|
|
2138
|
+
throws: "nothrow",
|
|
2139
|
+
dataType: "(no longer used)",
|
|
2140
|
+
uri: "baseUri",
|
|
2141
|
+
method: "fetch.method",
|
|
2142
|
+
headers: "fetch.headers",
|
|
2143
|
+
body: "fetch.body",
|
|
2144
|
+
mode: "fetch.mode",
|
|
2145
|
+
credentials: "fetch.credentials",
|
|
2146
|
+
cache: "fetch.cache",
|
|
2147
|
+
redirect: "fetch.redirect",
|
|
2148
|
+
referrer: "fetch.referrer",
|
|
2149
|
+
referrerPolicy: "fetch.referrerPolicy",
|
|
2150
|
+
integrity: "fetch.integrity",
|
|
2151
|
+
keepalive: "fetch.keepalive",
|
|
2152
|
+
signal: "fetch.signal"
|
|
2153
|
+
};
|
|
2154
|
+
}
|
|
2155
|
+
});
|
|
2156
|
+
|
|
2157
|
+
// src/lib/loader-utils/option-utils.ts
|
|
2158
|
+
function getGlobalLoaderState() {
|
|
2159
|
+
globalThis.loaders = globalThis.loaders || {};
|
|
2160
|
+
const { loaders } = globalThis;
|
|
2161
|
+
loaders._state = loaders._state || {};
|
|
2162
|
+
return loaders._state;
|
|
2163
|
+
}
|
|
2164
|
+
function setGlobalOptions(options) {
|
|
2165
|
+
const state = getGlobalLoaderState();
|
|
2166
|
+
const globalOptions = getGlobalLoaderOptions();
|
|
2167
|
+
state.globalOptions = normalizeOptionsInternal(globalOptions, options);
|
|
2168
|
+
}
|
|
2169
|
+
function normalizeOptions(options, loader, loaders, url) {
|
|
2170
|
+
loaders = loaders || [];
|
|
2171
|
+
loaders = Array.isArray(loaders) ? loaders : [loaders];
|
|
2172
|
+
validateOptions(options, loaders);
|
|
2173
|
+
return normalizeOptionsInternal(loader, options, url);
|
|
2174
|
+
}
|
|
2175
|
+
function getFetchFunction(options, context) {
|
|
2176
|
+
const globalOptions = getGlobalLoaderOptions();
|
|
2177
|
+
const fetchOptions = options || globalOptions;
|
|
2178
|
+
if (typeof fetchOptions.fetch === "function") {
|
|
2179
|
+
return fetchOptions.fetch;
|
|
2180
|
+
}
|
|
2181
|
+
if (isObject(fetchOptions.fetch)) {
|
|
2182
|
+
return (url) => fetchFile(url, fetchOptions);
|
|
2183
|
+
}
|
|
2184
|
+
if (context?.fetch) {
|
|
2185
|
+
return context?.fetch;
|
|
2186
|
+
}
|
|
2187
|
+
return fetchFile;
|
|
2188
|
+
}
|
|
2189
|
+
function validateOptions(options, loaders) {
|
|
2190
|
+
validateOptionsObject(options, null, DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS, loaders);
|
|
2191
|
+
for (const loader of loaders) {
|
|
2192
|
+
const idOptions = options && options[loader.id] || {};
|
|
2193
|
+
const loaderOptions = loader.options && loader.options[loader.id] || {};
|
|
2194
|
+
const deprecatedOptions = loader.deprecatedOptions && loader.deprecatedOptions[loader.id] || {};
|
|
2195
|
+
validateOptionsObject(idOptions, loader.id, loaderOptions, deprecatedOptions, loaders);
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
function validateOptionsObject(options, id, defaultOptions, deprecatedOptions, loaders) {
|
|
2199
|
+
const loaderName = id || "Top level";
|
|
2200
|
+
const prefix = id ? `${id}.` : "";
|
|
2201
|
+
for (const key in options) {
|
|
2202
|
+
const isSubOptions = !id && isObject(options[key]);
|
|
2203
|
+
const isBaseUriOption = key === "baseUri" && !id;
|
|
2204
|
+
const isWorkerUrlOption = key === "workerUrl" && id;
|
|
2205
|
+
if (!(key in defaultOptions) && !isBaseUriOption && !isWorkerUrlOption) {
|
|
2206
|
+
if (key in deprecatedOptions) {
|
|
2207
|
+
probeLog.warn(`${loaderName} loader option '${prefix}${key}' no longer supported, use '${deprecatedOptions[key]}'`)();
|
|
2208
|
+
} else if (!isSubOptions) {
|
|
2209
|
+
const suggestion = findSimilarOption(key, loaders);
|
|
2210
|
+
probeLog.warn(`${loaderName} loader option '${prefix}${key}' not recognized. ${suggestion}`)();
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
function findSimilarOption(optionKey, loaders) {
|
|
2216
|
+
const lowerCaseOptionKey = optionKey.toLowerCase();
|
|
2217
|
+
let bestSuggestion = "";
|
|
2218
|
+
for (const loader of loaders) {
|
|
2219
|
+
for (const key in loader.options) {
|
|
2220
|
+
if (optionKey === key) {
|
|
2221
|
+
return `Did you mean '${loader.id}.${key}'?`;
|
|
2222
|
+
}
|
|
2223
|
+
const lowerCaseKey = key.toLowerCase();
|
|
2224
|
+
const isPartialMatch = lowerCaseOptionKey.startsWith(lowerCaseKey) || lowerCaseKey.startsWith(lowerCaseOptionKey);
|
|
2225
|
+
if (isPartialMatch) {
|
|
2226
|
+
bestSuggestion = bestSuggestion || `Did you mean '${loader.id}.${key}'?`;
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
return bestSuggestion;
|
|
2231
|
+
}
|
|
2232
|
+
function normalizeOptionsInternal(loader, options, url) {
|
|
2233
|
+
const loaderDefaultOptions = loader.options || {};
|
|
2234
|
+
const mergedOptions = { ...loaderDefaultOptions };
|
|
2235
|
+
addUrlOptions(mergedOptions, url);
|
|
2236
|
+
if (mergedOptions.log === null) {
|
|
2237
|
+
mergedOptions.log = new NullLog();
|
|
2238
|
+
}
|
|
2239
|
+
mergeNestedFields(mergedOptions, getGlobalLoaderOptions());
|
|
2240
|
+
mergeNestedFields(mergedOptions, options);
|
|
2241
|
+
return mergedOptions;
|
|
2242
|
+
}
|
|
2243
|
+
function mergeNestedFields(mergedOptions, options) {
|
|
2244
|
+
for (const key in options) {
|
|
2245
|
+
if (key in options) {
|
|
2246
|
+
const value = options[key];
|
|
2247
|
+
if (isPureObject(value) && isPureObject(mergedOptions[key])) {
|
|
2248
|
+
mergedOptions[key] = {
|
|
2249
|
+
...mergedOptions[key],
|
|
2250
|
+
...options[key]
|
|
2251
|
+
};
|
|
2252
|
+
} else {
|
|
2253
|
+
mergedOptions[key] = options[key];
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
function addUrlOptions(options, url) {
|
|
2259
|
+
if (url && !("baseUri" in options)) {
|
|
2260
|
+
options.baseUri = url;
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
var getGlobalLoaderOptions;
|
|
2264
|
+
var init_option_utils = __esm({
|
|
2265
|
+
"src/lib/loader-utils/option-utils.ts"() {
|
|
2266
|
+
init_is_type();
|
|
2267
|
+
init_fetch_file();
|
|
2268
|
+
init_loggers();
|
|
2269
|
+
init_option_defaults();
|
|
2270
|
+
getGlobalLoaderOptions = () => {
|
|
2271
|
+
const state = getGlobalLoaderState();
|
|
2272
|
+
state.globalOptions = state.globalOptions || { ...DEFAULT_LOADER_OPTIONS };
|
|
2273
|
+
return state.globalOptions;
|
|
2274
|
+
};
|
|
2275
|
+
}
|
|
2276
|
+
});
|
|
2277
|
+
|
|
2278
|
+
// src/lib/api/set-loader-options.ts
|
|
2279
|
+
function setLoaderOptions(options) {
|
|
2280
|
+
setGlobalOptions(options);
|
|
2281
|
+
}
|
|
2282
|
+
var init_set_loader_options = __esm({
|
|
2283
|
+
"src/lib/api/set-loader-options.ts"() {
|
|
2284
|
+
init_option_utils();
|
|
2285
|
+
}
|
|
2286
|
+
});
|
|
2287
|
+
|
|
2288
|
+
// src/lib/loader-utils/normalize-loader.ts
|
|
2289
|
+
function isLoaderObject(loader) {
|
|
2290
|
+
if (!loader) {
|
|
2291
|
+
return false;
|
|
2292
|
+
}
|
|
2293
|
+
if (Array.isArray(loader)) {
|
|
2294
|
+
loader = loader[0];
|
|
2295
|
+
}
|
|
2296
|
+
const hasExtensions = Array.isArray(loader?.extensions);
|
|
2297
|
+
return hasExtensions;
|
|
2298
|
+
}
|
|
2299
|
+
function normalizeLoader(loader) {
|
|
2300
|
+
assert(loader, "null loader");
|
|
2301
|
+
assert(isLoaderObject(loader), "invalid loader");
|
|
2302
|
+
let options;
|
|
2303
|
+
if (Array.isArray(loader)) {
|
|
2304
|
+
options = loader[1];
|
|
2305
|
+
loader = loader[0];
|
|
2306
|
+
loader = {
|
|
2307
|
+
...loader,
|
|
2308
|
+
options: { ...loader.options, ...options }
|
|
2309
|
+
};
|
|
2310
|
+
}
|
|
2311
|
+
if (loader?.parseTextSync || loader?.parseText) {
|
|
2312
|
+
loader.text = true;
|
|
2313
|
+
}
|
|
2314
|
+
if (!loader.text) {
|
|
2315
|
+
loader.binary = true;
|
|
2316
|
+
}
|
|
2317
|
+
return loader;
|
|
2318
|
+
}
|
|
2319
|
+
var init_normalize_loader = __esm({
|
|
2320
|
+
"src/lib/loader-utils/normalize-loader.ts"() {
|
|
2321
|
+
init_src2();
|
|
2322
|
+
}
|
|
2323
|
+
});
|
|
2324
|
+
|
|
2325
|
+
// src/lib/api/register-loaders.ts
|
|
2326
|
+
function registerLoaders(loaders) {
|
|
2327
|
+
const loaderRegistry = getGlobalLoaderRegistry();
|
|
2328
|
+
loaders = Array.isArray(loaders) ? loaders : [loaders];
|
|
2329
|
+
for (const loader of loaders) {
|
|
2330
|
+
const normalizedLoader = normalizeLoader(loader);
|
|
2331
|
+
if (!loaderRegistry.find((registeredLoader) => normalizedLoader === registeredLoader)) {
|
|
2332
|
+
loaderRegistry.unshift(normalizedLoader);
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2336
|
+
function getRegisteredLoaders() {
|
|
2337
|
+
return getGlobalLoaderRegistry();
|
|
2338
|
+
}
|
|
2339
|
+
function _unregisterLoaders() {
|
|
2340
|
+
const state = getGlobalLoaderState();
|
|
2341
|
+
state.loaderRegistry = [];
|
|
2342
|
+
}
|
|
2343
|
+
var getGlobalLoaderRegistry;
|
|
2344
|
+
var init_register_loaders = __esm({
|
|
2345
|
+
"src/lib/api/register-loaders.ts"() {
|
|
2346
|
+
init_normalize_loader();
|
|
2347
|
+
init_option_utils();
|
|
2348
|
+
getGlobalLoaderRegistry = () => {
|
|
2349
|
+
const state = getGlobalLoaderState();
|
|
2350
|
+
state.loaderRegistry = state.loaderRegistry || [];
|
|
2351
|
+
return state.loaderRegistry;
|
|
2352
|
+
};
|
|
2353
|
+
}
|
|
2354
|
+
});
|
|
2355
|
+
|
|
2356
|
+
// src/lib/api/select-loader.ts
|
|
2357
|
+
async function selectLoader(data, loaders = [], options, context) {
|
|
2358
|
+
if (!validHTTPResponse(data)) {
|
|
2359
|
+
return null;
|
|
2360
|
+
}
|
|
2361
|
+
let loader = selectLoaderSync(data, loaders, { ...options, nothrow: true }, context);
|
|
2362
|
+
if (loader) {
|
|
2363
|
+
return loader;
|
|
2364
|
+
}
|
|
2365
|
+
if (isBlob(data)) {
|
|
2366
|
+
data = await data.slice(0, 10).arrayBuffer();
|
|
2367
|
+
loader = selectLoaderSync(data, loaders, options, context);
|
|
2368
|
+
}
|
|
2369
|
+
if (!loader && !options?.nothrow) {
|
|
2370
|
+
throw new Error(getNoValidLoaderMessage(data));
|
|
2371
|
+
}
|
|
2372
|
+
return loader;
|
|
2373
|
+
}
|
|
2374
|
+
function selectLoaderSync(data, loaders = [], options, context) {
|
|
2375
|
+
if (!validHTTPResponse(data)) {
|
|
2376
|
+
return null;
|
|
2377
|
+
}
|
|
2378
|
+
if (loaders && !Array.isArray(loaders)) {
|
|
2379
|
+
return normalizeLoader(loaders);
|
|
2380
|
+
}
|
|
2381
|
+
let candidateLoaders = [];
|
|
2382
|
+
if (loaders) {
|
|
2383
|
+
candidateLoaders = candidateLoaders.concat(loaders);
|
|
2384
|
+
}
|
|
2385
|
+
if (!options?.ignoreRegisteredLoaders) {
|
|
2386
|
+
candidateLoaders.push(...getRegisteredLoaders());
|
|
2387
|
+
}
|
|
2388
|
+
normalizeLoaders(candidateLoaders);
|
|
2389
|
+
const loader = selectLoaderInternal(data, candidateLoaders, options, context);
|
|
2390
|
+
if (!loader && !options?.nothrow) {
|
|
2391
|
+
throw new Error(getNoValidLoaderMessage(data));
|
|
2392
|
+
}
|
|
2393
|
+
return loader;
|
|
2394
|
+
}
|
|
2395
|
+
function selectLoaderInternal(data, loaders, options, context) {
|
|
2396
|
+
const { url, type } = getResourceUrlAndType(data);
|
|
2397
|
+
const testUrl = url || context?.url;
|
|
2398
|
+
let loader = null;
|
|
2399
|
+
if (options?.mimeType) {
|
|
2400
|
+
loader = findLoaderByMIMEType(loaders, options?.mimeType);
|
|
2401
|
+
}
|
|
2402
|
+
loader = loader || findLoaderByUrl(loaders, testUrl);
|
|
2403
|
+
loader = loader || findLoaderByMIMEType(loaders, type);
|
|
2404
|
+
loader = loader || findLoaderByInitialBytes(loaders, data);
|
|
2405
|
+
loader = loader || findLoaderByMIMEType(loaders, options?.fallbackMimeType);
|
|
2406
|
+
return loader;
|
|
2407
|
+
}
|
|
2408
|
+
function validHTTPResponse(data) {
|
|
2409
|
+
if (data instanceof Response) {
|
|
2410
|
+
if (data.status === 204) {
|
|
2411
|
+
return false;
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
return true;
|
|
2415
|
+
}
|
|
2416
|
+
function getNoValidLoaderMessage(data) {
|
|
2417
|
+
const { url, type } = getResourceUrlAndType(data);
|
|
2418
|
+
let message = "No valid loader found (";
|
|
2419
|
+
message += url ? `${path_exports.filename(url)}, ` : "no url provided, ";
|
|
2420
|
+
message += `MIME type: ${type ? `"${type}"` : "not provided"}, `;
|
|
2421
|
+
const firstCharacters = data ? getFirstCharacters(data) : "";
|
|
2422
|
+
message += firstCharacters ? ` first bytes: "${firstCharacters}"` : "first bytes: not available";
|
|
2423
|
+
message += ")";
|
|
2424
|
+
return message;
|
|
2425
|
+
}
|
|
2426
|
+
function normalizeLoaders(loaders) {
|
|
2427
|
+
for (const loader of loaders) {
|
|
2428
|
+
normalizeLoader(loader);
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
function findLoaderByUrl(loaders, url) {
|
|
2432
|
+
const match = url && EXT_PATTERN.exec(url);
|
|
2433
|
+
const extension = match && match[1];
|
|
2434
|
+
return extension ? findLoaderByExtension(loaders, extension) : null;
|
|
2435
|
+
}
|
|
2436
|
+
function findLoaderByExtension(loaders, extension) {
|
|
2437
|
+
extension = extension.toLowerCase();
|
|
2438
|
+
for (const loader of loaders) {
|
|
2439
|
+
for (const loaderExtension of loader.extensions) {
|
|
2440
|
+
if (loaderExtension.toLowerCase() === extension) {
|
|
2441
|
+
return loader;
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
return null;
|
|
2446
|
+
}
|
|
2447
|
+
function findLoaderByMIMEType(loaders, mimeType) {
|
|
2448
|
+
for (const loader of loaders) {
|
|
2449
|
+
if (loader.mimeTypes && loader.mimeTypes.includes(mimeType)) {
|
|
2450
|
+
return loader;
|
|
2451
|
+
}
|
|
2452
|
+
if (mimeType === `application/x.${loader.id}`) {
|
|
2453
|
+
return loader;
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
return null;
|
|
2457
|
+
}
|
|
2458
|
+
function findLoaderByInitialBytes(loaders, data) {
|
|
2459
|
+
if (!data) {
|
|
2460
|
+
return null;
|
|
2461
|
+
}
|
|
2462
|
+
for (const loader of loaders) {
|
|
2463
|
+
if (typeof data === "string") {
|
|
2464
|
+
if (testDataAgainstText(data, loader)) {
|
|
2465
|
+
return loader;
|
|
2466
|
+
}
|
|
2467
|
+
} else if (ArrayBuffer.isView(data)) {
|
|
2468
|
+
if (testDataAgainstBinary(data.buffer, data.byteOffset, loader)) {
|
|
2469
|
+
return loader;
|
|
2470
|
+
}
|
|
2471
|
+
} else if (data instanceof ArrayBuffer) {
|
|
2472
|
+
const byteOffset = 0;
|
|
2473
|
+
if (testDataAgainstBinary(data, byteOffset, loader)) {
|
|
2474
|
+
return loader;
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
return null;
|
|
2479
|
+
}
|
|
2480
|
+
function testDataAgainstText(data, loader) {
|
|
2481
|
+
if (loader.testText) {
|
|
2482
|
+
return loader.testText(data);
|
|
2483
|
+
}
|
|
2484
|
+
const tests = Array.isArray(loader.tests) ? loader.tests : [loader.tests];
|
|
2485
|
+
return tests.some((test) => data.startsWith(test));
|
|
2486
|
+
}
|
|
2487
|
+
function testDataAgainstBinary(data, byteOffset, loader) {
|
|
2488
|
+
const tests = Array.isArray(loader.tests) ? loader.tests : [loader.tests];
|
|
2489
|
+
return tests.some((test) => testBinary(data, byteOffset, loader, test));
|
|
2490
|
+
}
|
|
2491
|
+
function testBinary(data, byteOffset, loader, test) {
|
|
2492
|
+
if (test instanceof ArrayBuffer) {
|
|
2493
|
+
return compareArrayBuffers(test, data, test.byteLength);
|
|
2494
|
+
}
|
|
2495
|
+
switch (typeof test) {
|
|
2496
|
+
case "function":
|
|
2497
|
+
return test(data, loader);
|
|
2498
|
+
case "string":
|
|
2499
|
+
const magic = getMagicString(data, byteOffset, test.length);
|
|
2500
|
+
return test === magic;
|
|
2501
|
+
default:
|
|
2502
|
+
return false;
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
function getFirstCharacters(data, length = 5) {
|
|
2506
|
+
if (typeof data === "string") {
|
|
2507
|
+
return data.slice(0, length);
|
|
2508
|
+
} else if (ArrayBuffer.isView(data)) {
|
|
2509
|
+
return getMagicString(data.buffer, data.byteOffset, length);
|
|
2510
|
+
} else if (data instanceof ArrayBuffer) {
|
|
2511
|
+
const byteOffset = 0;
|
|
2512
|
+
return getMagicString(data, byteOffset, length);
|
|
2513
|
+
}
|
|
2514
|
+
return "";
|
|
2515
|
+
}
|
|
2516
|
+
function getMagicString(arrayBuffer, byteOffset, length) {
|
|
2517
|
+
if (arrayBuffer.byteLength < byteOffset + length) {
|
|
2518
|
+
return "";
|
|
2519
|
+
}
|
|
2520
|
+
const dataView = new DataView(arrayBuffer);
|
|
2521
|
+
let magic = "";
|
|
2522
|
+
for (let i = 0; i < length; i++) {
|
|
2523
|
+
magic += String.fromCharCode(dataView.getUint8(byteOffset + i));
|
|
2524
|
+
}
|
|
2525
|
+
return magic;
|
|
2526
|
+
}
|
|
2527
|
+
var EXT_PATTERN;
|
|
2528
|
+
var init_select_loader = __esm({
|
|
2529
|
+
"src/lib/api/select-loader.ts"() {
|
|
2530
|
+
init_src2();
|
|
2531
|
+
init_normalize_loader();
|
|
2532
|
+
init_resource_utils();
|
|
2533
|
+
init_register_loaders();
|
|
2534
|
+
init_is_type();
|
|
2535
|
+
EXT_PATTERN = /\.([^.]+)$/;
|
|
2536
|
+
}
|
|
2537
|
+
});
|
|
2538
|
+
|
|
2539
|
+
// src/iterators/make-iterator/make-string-iterator.ts
|
|
2540
|
+
function* makeStringIterator(string, options) {
|
|
2541
|
+
const chunkSize = options?.chunkSize || DEFAULT_CHUNK_SIZE;
|
|
2542
|
+
let offset = 0;
|
|
2543
|
+
const textEncoder = new TextEncoder();
|
|
2544
|
+
while (offset < string.length) {
|
|
2545
|
+
const chunkLength = Math.min(string.length - offset, chunkSize);
|
|
2546
|
+
const chunk = string.slice(offset, offset + chunkLength);
|
|
2547
|
+
offset += chunkLength;
|
|
2548
|
+
yield textEncoder.encode(chunk);
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
var DEFAULT_CHUNK_SIZE;
|
|
2552
|
+
var init_make_string_iterator = __esm({
|
|
2553
|
+
"src/iterators/make-iterator/make-string-iterator.ts"() {
|
|
2554
|
+
DEFAULT_CHUNK_SIZE = 256 * 1024;
|
|
2555
|
+
}
|
|
2556
|
+
});
|
|
2557
|
+
|
|
2558
|
+
// src/iterators/make-iterator/make-array-buffer-iterator.ts
|
|
2559
|
+
function* makeArrayBufferIterator(arrayBuffer, options = {}) {
|
|
2560
|
+
const { chunkSize = DEFAULT_CHUNK_SIZE2 } = options;
|
|
2561
|
+
let byteOffset = 0;
|
|
2562
|
+
while (byteOffset < arrayBuffer.byteLength) {
|
|
2563
|
+
const chunkByteLength = Math.min(arrayBuffer.byteLength - byteOffset, chunkSize);
|
|
2564
|
+
const chunk = new ArrayBuffer(chunkByteLength);
|
|
2565
|
+
const sourceArray = new Uint8Array(arrayBuffer, byteOffset, chunkByteLength);
|
|
2566
|
+
const chunkArray = new Uint8Array(chunk);
|
|
2567
|
+
chunkArray.set(sourceArray);
|
|
2568
|
+
byteOffset += chunkByteLength;
|
|
2569
|
+
yield chunk;
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
var DEFAULT_CHUNK_SIZE2;
|
|
2573
|
+
var init_make_array_buffer_iterator = __esm({
|
|
2574
|
+
"src/iterators/make-iterator/make-array-buffer-iterator.ts"() {
|
|
2575
|
+
DEFAULT_CHUNK_SIZE2 = 256 * 1024;
|
|
2576
|
+
}
|
|
2577
|
+
});
|
|
2578
|
+
|
|
2579
|
+
// src/iterators/make-iterator/make-blob-iterator.ts
|
|
2580
|
+
async function* makeBlobIterator(blob, options) {
|
|
2581
|
+
const chunkSize = options?.chunkSize || DEFAULT_CHUNK_SIZE3;
|
|
2582
|
+
let offset = 0;
|
|
2583
|
+
while (offset < blob.size) {
|
|
2584
|
+
const end = offset + chunkSize;
|
|
2585
|
+
const chunk = await blob.slice(offset, end).arrayBuffer();
|
|
2586
|
+
offset = end;
|
|
2587
|
+
yield chunk;
|
|
2588
|
+
}
|
|
2589
|
+
}
|
|
2590
|
+
var DEFAULT_CHUNK_SIZE3;
|
|
2591
|
+
var init_make_blob_iterator = __esm({
|
|
2592
|
+
"src/iterators/make-iterator/make-blob-iterator.ts"() {
|
|
2593
|
+
DEFAULT_CHUNK_SIZE3 = 1024 * 1024;
|
|
2594
|
+
}
|
|
2595
|
+
});
|
|
2596
|
+
|
|
2597
|
+
// src/iterators/make-iterator/make-stream-iterator.ts
|
|
2598
|
+
function makeStreamIterator(stream, options) {
|
|
2599
|
+
return isBrowser ? makeBrowserStreamIterator(stream, options) : makeNodeStreamIterator(stream, options);
|
|
2600
|
+
}
|
|
2601
|
+
async function* makeBrowserStreamIterator(stream, options) {
|
|
2602
|
+
const reader = stream.getReader();
|
|
2603
|
+
let nextBatchPromise;
|
|
2604
|
+
try {
|
|
2605
|
+
while (true) {
|
|
2606
|
+
const currentBatchPromise = nextBatchPromise || reader.read();
|
|
2607
|
+
if (options?._streamReadAhead) {
|
|
2608
|
+
nextBatchPromise = reader.read();
|
|
2609
|
+
}
|
|
2610
|
+
const { done, value } = await currentBatchPromise;
|
|
2611
|
+
if (done) {
|
|
2612
|
+
return;
|
|
2613
|
+
}
|
|
2614
|
+
yield toArrayBuffer(value);
|
|
2615
|
+
}
|
|
2616
|
+
} catch (error) {
|
|
2617
|
+
reader.releaseLock();
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
async function* makeNodeStreamIterator(stream, options) {
|
|
2621
|
+
for await (const chunk of stream) {
|
|
2622
|
+
yield toArrayBuffer(chunk);
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
var init_make_stream_iterator = __esm({
|
|
2626
|
+
"src/iterators/make-iterator/make-stream-iterator.ts"() {
|
|
2627
|
+
init_src2();
|
|
2628
|
+
}
|
|
2629
|
+
});
|
|
2630
|
+
|
|
2631
|
+
// src/iterators/make-iterator/make-iterator.ts
|
|
2632
|
+
function makeIterator(data, options) {
|
|
2633
|
+
if (typeof data === "string") {
|
|
2634
|
+
return makeStringIterator(data, options);
|
|
2635
|
+
}
|
|
2636
|
+
if (data instanceof ArrayBuffer) {
|
|
2637
|
+
return makeArrayBufferIterator(data, options);
|
|
2638
|
+
}
|
|
2639
|
+
if (isBlob(data)) {
|
|
2640
|
+
return makeBlobIterator(data, options);
|
|
2641
|
+
}
|
|
2642
|
+
if (isReadableStream(data)) {
|
|
2643
|
+
return makeStreamIterator(data, options);
|
|
2644
|
+
}
|
|
2645
|
+
if (isResponse(data)) {
|
|
2646
|
+
const response = data;
|
|
2647
|
+
return makeStreamIterator(response.body, options);
|
|
2648
|
+
}
|
|
2649
|
+
throw new Error("makeIterator");
|
|
2650
|
+
}
|
|
2651
|
+
var init_make_iterator = __esm({
|
|
2652
|
+
"src/iterators/make-iterator/make-iterator.ts"() {
|
|
2653
|
+
init_make_string_iterator();
|
|
2654
|
+
init_make_array_buffer_iterator();
|
|
2655
|
+
init_make_blob_iterator();
|
|
2656
|
+
init_make_stream_iterator();
|
|
2657
|
+
init_is_type();
|
|
2658
|
+
}
|
|
2659
|
+
});
|
|
2660
|
+
|
|
2661
|
+
// src/lib/loader-utils/get-data.ts
|
|
2662
|
+
function getArrayBufferOrStringFromDataSync(data, loader, options) {
|
|
2663
|
+
if (loader.text && typeof data === "string") {
|
|
2664
|
+
return data;
|
|
2665
|
+
}
|
|
2666
|
+
if (isBuffer2(data)) {
|
|
2667
|
+
data = data.buffer;
|
|
2668
|
+
}
|
|
2669
|
+
if (data instanceof ArrayBuffer) {
|
|
2670
|
+
const arrayBuffer = data;
|
|
2671
|
+
if (loader.text && !loader.binary) {
|
|
2672
|
+
const textDecoder = new TextDecoder("utf8");
|
|
2673
|
+
return textDecoder.decode(arrayBuffer);
|
|
2674
|
+
}
|
|
2675
|
+
return arrayBuffer;
|
|
2676
|
+
}
|
|
2677
|
+
if (ArrayBuffer.isView(data)) {
|
|
2678
|
+
if (loader.text && !loader.binary) {
|
|
2679
|
+
const textDecoder = new TextDecoder("utf8");
|
|
2680
|
+
return textDecoder.decode(data);
|
|
2681
|
+
}
|
|
2682
|
+
let arrayBuffer = data.buffer;
|
|
2683
|
+
const byteLength = data.byteLength || data.length;
|
|
2684
|
+
if (data.byteOffset !== 0 || byteLength !== arrayBuffer.byteLength) {
|
|
2685
|
+
arrayBuffer = arrayBuffer.slice(data.byteOffset, data.byteOffset + byteLength);
|
|
2686
|
+
}
|
|
2687
|
+
return arrayBuffer;
|
|
2688
|
+
}
|
|
2689
|
+
throw new Error(ERR_DATA);
|
|
2690
|
+
}
|
|
2691
|
+
async function getArrayBufferOrStringFromData(data, loader, options) {
|
|
2692
|
+
const isArrayBuffer = data instanceof ArrayBuffer || ArrayBuffer.isView(data);
|
|
2693
|
+
if (typeof data === "string" || isArrayBuffer) {
|
|
2694
|
+
return getArrayBufferOrStringFromDataSync(data, loader, options);
|
|
2695
|
+
}
|
|
2696
|
+
if (isBlob(data)) {
|
|
2697
|
+
data = await makeResponse(data);
|
|
2698
|
+
}
|
|
2699
|
+
if (isResponse(data)) {
|
|
2700
|
+
const response = data;
|
|
2701
|
+
await checkResponse(response);
|
|
2702
|
+
return loader.binary ? await response.arrayBuffer() : await response.text();
|
|
2703
|
+
}
|
|
2704
|
+
if (isReadableStream(data)) {
|
|
2705
|
+
data = makeIterator(data, options);
|
|
2706
|
+
}
|
|
2707
|
+
if (isIterable(data) || isAsyncIterable(data)) {
|
|
2708
|
+
return concatenateArrayBuffersAsync(data);
|
|
2709
|
+
}
|
|
2710
|
+
throw new Error(ERR_DATA);
|
|
2711
|
+
}
|
|
2712
|
+
async function getAsyncIterableFromData(data, options) {
|
|
2713
|
+
if (isIterator(data)) {
|
|
2714
|
+
return data;
|
|
2715
|
+
}
|
|
2716
|
+
if (isResponse(data)) {
|
|
2717
|
+
const response = data;
|
|
2718
|
+
await checkResponse(response);
|
|
2719
|
+
const body = await response.body;
|
|
2720
|
+
return makeIterator(body, options);
|
|
2721
|
+
}
|
|
2722
|
+
if (isBlob(data) || isReadableStream(data)) {
|
|
2723
|
+
return makeIterator(data, options);
|
|
2724
|
+
}
|
|
2725
|
+
if (isAsyncIterable(data)) {
|
|
2726
|
+
return data[Symbol.asyncIterator]();
|
|
2727
|
+
}
|
|
2728
|
+
return getIterableFromData(data);
|
|
2729
|
+
}
|
|
2730
|
+
function getIterableFromData(data) {
|
|
2731
|
+
if (ArrayBuffer.isView(data)) {
|
|
2732
|
+
return function* oneChunk() {
|
|
2733
|
+
yield data.buffer;
|
|
2734
|
+
}();
|
|
2735
|
+
}
|
|
2736
|
+
if (data instanceof ArrayBuffer) {
|
|
2737
|
+
return function* oneChunk() {
|
|
2738
|
+
yield data;
|
|
2739
|
+
}();
|
|
2740
|
+
}
|
|
2741
|
+
if (isIterator(data)) {
|
|
2742
|
+
return data;
|
|
2743
|
+
}
|
|
2744
|
+
if (isIterable(data)) {
|
|
2745
|
+
return data[Symbol.iterator]();
|
|
2746
|
+
}
|
|
2747
|
+
throw new Error(ERR_DATA);
|
|
2748
|
+
}
|
|
2749
|
+
var ERR_DATA;
|
|
2750
|
+
var init_get_data = __esm({
|
|
2751
|
+
"src/lib/loader-utils/get-data.ts"() {
|
|
2752
|
+
init_src2();
|
|
2753
|
+
init_is_type();
|
|
2754
|
+
init_make_iterator();
|
|
2755
|
+
init_response_utils();
|
|
2756
|
+
ERR_DATA = "Cannot convert supplied data type";
|
|
2757
|
+
}
|
|
2758
|
+
});
|
|
2759
|
+
|
|
2760
|
+
// src/lib/loader-utils/loader-context.ts
|
|
2761
|
+
function getLoaderContext(context, options, previousContext = null) {
|
|
2762
|
+
if (previousContext) {
|
|
2763
|
+
return previousContext;
|
|
2764
|
+
}
|
|
2765
|
+
const resolvedContext = {
|
|
2766
|
+
fetch: getFetchFunction(options, context),
|
|
2767
|
+
...context
|
|
2768
|
+
};
|
|
2769
|
+
if (!Array.isArray(resolvedContext.loaders)) {
|
|
2770
|
+
resolvedContext.loaders = null;
|
|
2771
|
+
}
|
|
2772
|
+
return resolvedContext;
|
|
2773
|
+
}
|
|
2774
|
+
function getLoadersFromContext(loaders, context) {
|
|
2775
|
+
if (!context && loaders && !Array.isArray(loaders)) {
|
|
2776
|
+
return loaders;
|
|
2777
|
+
}
|
|
2778
|
+
let candidateLoaders;
|
|
2779
|
+
if (loaders) {
|
|
2780
|
+
candidateLoaders = Array.isArray(loaders) ? loaders : [loaders];
|
|
2781
|
+
}
|
|
2782
|
+
if (context && context.loaders) {
|
|
2783
|
+
const contextLoaders = Array.isArray(context.loaders) ? context.loaders : [context.loaders];
|
|
2784
|
+
candidateLoaders = candidateLoaders ? [...candidateLoaders, ...contextLoaders] : contextLoaders;
|
|
2785
|
+
}
|
|
2786
|
+
return candidateLoaders && candidateLoaders.length ? candidateLoaders : null;
|
|
2787
|
+
}
|
|
2788
|
+
var init_loader_context = __esm({
|
|
2789
|
+
"src/lib/loader-utils/loader-context.ts"() {
|
|
2790
|
+
init_option_utils();
|
|
2791
|
+
}
|
|
2792
|
+
});
|
|
2793
|
+
|
|
2794
|
+
// src/lib/api/parse.ts
|
|
2795
|
+
async function parse(data, loaders, options, context) {
|
|
2796
|
+
assert2(!context || typeof context === "object");
|
|
2797
|
+
if (loaders && !Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
2798
|
+
context = void 0;
|
|
2799
|
+
options = loaders;
|
|
2800
|
+
loaders = void 0;
|
|
2801
|
+
}
|
|
2802
|
+
data = await data;
|
|
2803
|
+
options = options || {};
|
|
2804
|
+
const { url } = getResourceUrlAndType(data);
|
|
2805
|
+
const typedLoaders = loaders;
|
|
2806
|
+
const candidateLoaders = getLoadersFromContext(typedLoaders, context);
|
|
2807
|
+
const loader = await selectLoader(data, candidateLoaders, options);
|
|
2808
|
+
if (!loader) {
|
|
2809
|
+
return null;
|
|
2810
|
+
}
|
|
2811
|
+
options = normalizeOptions(options, loader, candidateLoaders, url);
|
|
2812
|
+
context = getLoaderContext({ url, parse, loaders: candidateLoaders }, options, context);
|
|
2813
|
+
return await parseWithLoader(loader, data, options, context);
|
|
2814
|
+
}
|
|
2815
|
+
async function parseWithLoader(loader, data, options, context) {
|
|
2816
|
+
validateWorkerVersion(loader);
|
|
2817
|
+
data = await getArrayBufferOrStringFromData(data, loader, options);
|
|
2818
|
+
if (loader.parseTextSync && typeof data === "string") {
|
|
2819
|
+
options.dataType = "text";
|
|
2820
|
+
return loader.parseTextSync(data, options, context, loader);
|
|
2821
|
+
}
|
|
2822
|
+
if (canParseWithWorker(loader, options)) {
|
|
2823
|
+
return await parseWithWorker(loader, data, options, context, parse);
|
|
2824
|
+
}
|
|
2825
|
+
if (loader.parseText && typeof data === "string") {
|
|
2826
|
+
return await loader.parseText(data, options, context, loader);
|
|
2827
|
+
}
|
|
2828
|
+
if (loader.parse) {
|
|
2829
|
+
return await loader.parse(data, options, context, loader);
|
|
2830
|
+
}
|
|
2831
|
+
assert2(!loader.parseSync);
|
|
2832
|
+
throw new Error(`${loader.id} loader - no parser found and worker is disabled`);
|
|
2833
|
+
}
|
|
2834
|
+
var init_parse = __esm({
|
|
2835
|
+
"src/lib/api/parse.ts"() {
|
|
2836
|
+
init_src();
|
|
2837
|
+
init_src2();
|
|
2838
|
+
init_normalize_loader();
|
|
2839
|
+
init_option_utils();
|
|
2840
|
+
init_get_data();
|
|
2841
|
+
init_loader_context();
|
|
2842
|
+
init_resource_utils();
|
|
2843
|
+
init_select_loader();
|
|
2844
|
+
}
|
|
2845
|
+
});
|
|
2846
|
+
|
|
2847
|
+
// src/lib/api/parse-sync.ts
|
|
2848
|
+
function parseSync(data, loaders, options, context) {
|
|
2849
|
+
assert(!context || typeof context === "object");
|
|
2850
|
+
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
2851
|
+
context = void 0;
|
|
2852
|
+
options = loaders;
|
|
2853
|
+
loaders = void 0;
|
|
2854
|
+
}
|
|
2855
|
+
options = options || {};
|
|
2856
|
+
const typedLoaders = loaders;
|
|
2857
|
+
const candidateLoaders = getLoadersFromContext(typedLoaders, context);
|
|
2858
|
+
const loader = selectLoaderSync(data, candidateLoaders, options);
|
|
2859
|
+
if (!loader) {
|
|
2860
|
+
return null;
|
|
2861
|
+
}
|
|
2862
|
+
options = normalizeOptions(options, loader, candidateLoaders);
|
|
2863
|
+
const { url } = getResourceUrlAndType(data);
|
|
2864
|
+
const parse2 = () => {
|
|
2865
|
+
throw new Error("parseSync called parse");
|
|
2866
|
+
};
|
|
2867
|
+
context = getLoaderContext({ url, parseSync, parse: parse2, loaders }, options);
|
|
2868
|
+
return parseWithLoaderSync(loader, data, options, context);
|
|
2869
|
+
}
|
|
2870
|
+
function parseWithLoaderSync(loader, data, options, context) {
|
|
2871
|
+
data = getArrayBufferOrStringFromDataSync(data, loader, options);
|
|
2872
|
+
if (loader.parseTextSync && typeof data === "string") {
|
|
2873
|
+
return loader.parseTextSync(data, options);
|
|
2874
|
+
}
|
|
2875
|
+
if (loader.parseSync && data instanceof ArrayBuffer) {
|
|
2876
|
+
return loader.parseSync(data, options, context);
|
|
2877
|
+
}
|
|
2878
|
+
throw new Error(`${loader.name} loader: 'parseSync' not supported by this loader, use 'parse' instead. ${context.url || ""}`);
|
|
2879
|
+
}
|
|
2880
|
+
var init_parse_sync = __esm({
|
|
2881
|
+
"src/lib/api/parse-sync.ts"() {
|
|
2882
|
+
init_src2();
|
|
2883
|
+
init_select_loader();
|
|
2884
|
+
init_normalize_loader();
|
|
2885
|
+
init_option_utils();
|
|
2886
|
+
init_get_data();
|
|
2887
|
+
init_loader_context();
|
|
2888
|
+
init_resource_utils();
|
|
2889
|
+
}
|
|
2890
|
+
});
|
|
2891
|
+
|
|
2892
|
+
// src/lib/api/parse-in-batches.ts
|
|
2893
|
+
async function parseInBatches(data, loaders, options, context) {
|
|
2894
|
+
assert(!context || typeof context === "object");
|
|
2895
|
+
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
2896
|
+
context = void 0;
|
|
2897
|
+
options = loaders;
|
|
2898
|
+
loaders = void 0;
|
|
2899
|
+
}
|
|
2900
|
+
data = await data;
|
|
2901
|
+
options = options || {};
|
|
2902
|
+
const { url } = getResourceUrlAndType(data);
|
|
2903
|
+
const loader = await selectLoader(data, loaders, options);
|
|
2904
|
+
if (!loader) {
|
|
2905
|
+
return null;
|
|
2906
|
+
}
|
|
2907
|
+
options = normalizeOptions(options, loader, loaders, url);
|
|
2908
|
+
context = getLoaderContext({ url, parseInBatches, parse, loaders }, options, context);
|
|
2909
|
+
return await parseWithLoaderInBatches(loader, data, options, context);
|
|
2910
|
+
}
|
|
2911
|
+
async function parseWithLoaderInBatches(loader, data, options, context) {
|
|
2912
|
+
const outputIterator = await parseToOutputIterator(loader, data, options, context);
|
|
2913
|
+
if (!options.metadata) {
|
|
2914
|
+
return outputIterator;
|
|
2915
|
+
}
|
|
2916
|
+
const metadataBatch = {
|
|
2917
|
+
batchType: "metadata",
|
|
2918
|
+
metadata: {
|
|
2919
|
+
_loader: loader,
|
|
2920
|
+
_context: context
|
|
2921
|
+
},
|
|
2922
|
+
data: [],
|
|
2923
|
+
bytesUsed: 0
|
|
2924
|
+
};
|
|
2925
|
+
async function* makeMetadataBatchIterator(iterator) {
|
|
2926
|
+
yield metadataBatch;
|
|
2927
|
+
yield* iterator;
|
|
2928
|
+
}
|
|
2929
|
+
return makeMetadataBatchIterator(outputIterator);
|
|
2930
|
+
}
|
|
2931
|
+
async function parseToOutputIterator(loader, data, options, context) {
|
|
2932
|
+
const inputIterator = await getAsyncIterableFromData(data, options);
|
|
2933
|
+
const transformedIterator = await applyInputTransforms(inputIterator, options?.transforms || []);
|
|
2934
|
+
if (loader.parseInBatches) {
|
|
2935
|
+
return loader.parseInBatches(transformedIterator, options, context);
|
|
2936
|
+
}
|
|
2937
|
+
async function* parseChunkInBatches() {
|
|
2938
|
+
const arrayBuffer = await concatenateArrayBuffersAsync(transformedIterator);
|
|
2939
|
+
const parsedData = await parse(arrayBuffer, loader, { ...options, mimeType: loader.mimeTypes[0] }, context);
|
|
2940
|
+
const batch = {
|
|
2941
|
+
mimeType: loader.mimeTypes[0],
|
|
2942
|
+
shape: Array.isArray(parsedData) ? "row-table" : "unknown",
|
|
2943
|
+
batchType: "data",
|
|
2944
|
+
data: parsedData,
|
|
2945
|
+
length: Array.isArray(parsedData) ? parsedData.length : 1
|
|
2946
|
+
};
|
|
2947
|
+
yield batch;
|
|
2948
|
+
}
|
|
2949
|
+
return parseChunkInBatches();
|
|
2950
|
+
}
|
|
2951
|
+
async function applyInputTransforms(inputIterator, transforms = []) {
|
|
2952
|
+
let iteratorChain = inputIterator;
|
|
2953
|
+
for await (const transformBatches of transforms) {
|
|
2954
|
+
iteratorChain = transformBatches(iteratorChain);
|
|
2955
|
+
}
|
|
2956
|
+
return iteratorChain;
|
|
2957
|
+
}
|
|
2958
|
+
var init_parse_in_batches = __esm({
|
|
2959
|
+
"src/lib/api/parse-in-batches.ts"() {
|
|
2960
|
+
init_src2();
|
|
2961
|
+
init_normalize_loader();
|
|
2962
|
+
init_option_utils();
|
|
2963
|
+
init_loader_context();
|
|
2964
|
+
init_get_data();
|
|
2965
|
+
init_resource_utils();
|
|
2966
|
+
init_select_loader();
|
|
2967
|
+
init_parse();
|
|
2968
|
+
}
|
|
2969
|
+
});
|
|
2970
|
+
|
|
2971
|
+
// src/lib/api/load.ts
|
|
2972
|
+
async function load(url, loaders, options, context) {
|
|
2973
|
+
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
2974
|
+
context = void 0;
|
|
2975
|
+
options = loaders;
|
|
2976
|
+
loaders = void 0;
|
|
2977
|
+
}
|
|
2978
|
+
const fetch2 = getFetchFunction(options);
|
|
2979
|
+
let data = url;
|
|
2980
|
+
if (typeof url === "string") {
|
|
2981
|
+
data = await fetch2(url);
|
|
2982
|
+
}
|
|
2983
|
+
if (isBlob(url)) {
|
|
2984
|
+
data = await fetch2(url);
|
|
2985
|
+
}
|
|
2986
|
+
return await parse(data, loaders, options);
|
|
2987
|
+
}
|
|
2988
|
+
var init_load = __esm({
|
|
2989
|
+
"src/lib/api/load.ts"() {
|
|
2990
|
+
init_is_type();
|
|
2991
|
+
init_normalize_loader();
|
|
2992
|
+
init_option_utils();
|
|
2993
|
+
init_parse();
|
|
2994
|
+
}
|
|
2995
|
+
});
|
|
2996
|
+
|
|
2997
|
+
// src/lib/api/load-in-batches.ts
|
|
2998
|
+
function loadInBatches(files, loaders, options, context) {
|
|
2999
|
+
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
3000
|
+
context = void 0;
|
|
3001
|
+
options = loaders;
|
|
3002
|
+
loaders = null;
|
|
3003
|
+
}
|
|
3004
|
+
const fetch2 = getFetchFunction(options || {});
|
|
3005
|
+
if (!Array.isArray(files)) {
|
|
3006
|
+
return loadOneFileInBatches(files, loaders, options, fetch2);
|
|
3007
|
+
}
|
|
3008
|
+
const promises = files.map((file) => loadOneFileInBatches(file, loaders, options, fetch2));
|
|
3009
|
+
return promises;
|
|
3010
|
+
}
|
|
3011
|
+
async function loadOneFileInBatches(file, loaders, options, fetch2) {
|
|
3012
|
+
if (typeof file === "string") {
|
|
3013
|
+
const url = file;
|
|
3014
|
+
const response = await fetch2(url);
|
|
3015
|
+
return await parseInBatches(response, loaders, options);
|
|
3016
|
+
}
|
|
3017
|
+
return await parseInBatches(file, loaders, options);
|
|
3018
|
+
}
|
|
3019
|
+
var init_load_in_batches = __esm({
|
|
3020
|
+
"src/lib/api/load-in-batches.ts"() {
|
|
3021
|
+
init_normalize_loader();
|
|
3022
|
+
init_option_utils();
|
|
3023
|
+
init_parse_in_batches();
|
|
3024
|
+
}
|
|
3025
|
+
});
|
|
3026
|
+
|
|
3027
|
+
// src/lib/api/encode.ts
|
|
3028
|
+
async function encode(data, writer, options) {
|
|
3029
|
+
if (writer.encode) {
|
|
3030
|
+
return await writer.encode(data, options);
|
|
3031
|
+
}
|
|
3032
|
+
if (writer.encodeSync) {
|
|
3033
|
+
return writer.encodeSync(data, options);
|
|
3034
|
+
}
|
|
3035
|
+
if (writer.encodeText) {
|
|
3036
|
+
return new TextEncoder().encode(await writer.encodeText(data, options));
|
|
3037
|
+
}
|
|
3038
|
+
if (writer.encodeInBatches) {
|
|
3039
|
+
const batches = encodeInBatches(data, writer, options);
|
|
3040
|
+
const chunks = [];
|
|
3041
|
+
for await (const batch of batches) {
|
|
3042
|
+
chunks.push(batch);
|
|
3043
|
+
}
|
|
3044
|
+
return concatenateArrayBuffers(...chunks);
|
|
3045
|
+
}
|
|
3046
|
+
if (!isBrowser && writer.encodeURLtoURL) {
|
|
3047
|
+
const tmpInputFilename = getTemporaryFilename("input");
|
|
3048
|
+
await writeFile(tmpInputFilename, data);
|
|
3049
|
+
const tmpOutputFilename = getTemporaryFilename("output");
|
|
3050
|
+
const outputFilename = await encodeURLtoURL(tmpInputFilename, tmpOutputFilename, writer, options);
|
|
3051
|
+
const response = await fetchFile(outputFilename);
|
|
3052
|
+
return response.arrayBuffer();
|
|
3053
|
+
}
|
|
3054
|
+
throw new Error("Writer could not encode data");
|
|
3055
|
+
}
|
|
3056
|
+
function encodeSync(data, writer, options) {
|
|
3057
|
+
if (writer.encodeSync) {
|
|
3058
|
+
return writer.encodeSync(data, options);
|
|
3059
|
+
}
|
|
3060
|
+
throw new Error("Writer could not synchronously encode data");
|
|
3061
|
+
}
|
|
3062
|
+
async function encodeText(data, writer, options) {
|
|
3063
|
+
if (writer.text && writer.encodeText) {
|
|
3064
|
+
return await writer.encodeText(data, options);
|
|
3065
|
+
}
|
|
3066
|
+
if (writer.text && (writer.encode || writer.encodeInBatches)) {
|
|
3067
|
+
const arrayBuffer = await encode(data, writer, options);
|
|
3068
|
+
return new TextDecoder().decode(arrayBuffer);
|
|
3069
|
+
}
|
|
3070
|
+
throw new Error("Writer could not encode data as text");
|
|
3071
|
+
}
|
|
3072
|
+
function encodeInBatches(data, writer, options) {
|
|
3073
|
+
if (writer.encodeInBatches) {
|
|
3074
|
+
const dataIterator = getIterator(data);
|
|
3075
|
+
return writer.encodeInBatches(dataIterator, options);
|
|
3076
|
+
}
|
|
3077
|
+
throw new Error("Writer could not encode data in batches");
|
|
3078
|
+
}
|
|
3079
|
+
async function encodeURLtoURL(inputUrl, outputUrl, writer, options) {
|
|
3080
|
+
inputUrl = resolvePath(inputUrl);
|
|
3081
|
+
outputUrl = resolvePath(outputUrl);
|
|
3082
|
+
if (isBrowser || !writer.encodeURLtoURL) {
|
|
3083
|
+
throw new Error();
|
|
3084
|
+
}
|
|
3085
|
+
const outputFilename = await writer.encodeURLtoURL(inputUrl, outputUrl, options);
|
|
3086
|
+
return outputFilename;
|
|
3087
|
+
}
|
|
3088
|
+
function getIterator(data) {
|
|
3089
|
+
const dataIterator = [{ table: data, start: 0, end: data.length }];
|
|
3090
|
+
return dataIterator;
|
|
3091
|
+
}
|
|
3092
|
+
function getTemporaryFilename(filename2) {
|
|
3093
|
+
return `/tmp/${filename2}`;
|
|
3094
|
+
}
|
|
3095
|
+
var init_encode = __esm({
|
|
3096
|
+
"src/lib/api/encode.ts"() {
|
|
3097
|
+
init_src2();
|
|
3098
|
+
init_src2();
|
|
3099
|
+
init_write_file();
|
|
3100
|
+
init_fetch_file();
|
|
3101
|
+
}
|
|
3102
|
+
});
|
|
3103
|
+
|
|
3104
|
+
// src/lib/api/save.ts
|
|
3105
|
+
async function save(data, url, writer, options) {
|
|
3106
|
+
const encodedData = await encode(data, writer, options);
|
|
3107
|
+
return await writeFile(url, encodedData);
|
|
3108
|
+
}
|
|
3109
|
+
function saveSync(data, url, writer, options) {
|
|
3110
|
+
const encodedData = encodeSync(data, writer, options);
|
|
3111
|
+
return writeFileSync(url, encodedData);
|
|
3112
|
+
}
|
|
3113
|
+
var init_save = __esm({
|
|
3114
|
+
"src/lib/api/save.ts"() {
|
|
3115
|
+
init_encode();
|
|
3116
|
+
init_write_file();
|
|
3117
|
+
}
|
|
3118
|
+
});
|
|
3119
|
+
|
|
3120
|
+
// src/iterators/make-stream/make-dom-stream.ts
|
|
3121
|
+
function makeStream(source, options) {
|
|
3122
|
+
const iterator = source[Symbol.asyncIterator] ? source[Symbol.asyncIterator]() : source[Symbol.iterator]();
|
|
3123
|
+
return new ReadableStream({
|
|
3124
|
+
type: "bytes",
|
|
3125
|
+
async pull(controller) {
|
|
3126
|
+
try {
|
|
3127
|
+
const { done, value } = await iterator.next();
|
|
3128
|
+
if (done) {
|
|
3129
|
+
controller.close();
|
|
3130
|
+
} else {
|
|
3131
|
+
controller.enqueue(new Uint8Array(value));
|
|
3132
|
+
}
|
|
3133
|
+
} catch (error) {
|
|
3134
|
+
controller.error(error);
|
|
3135
|
+
}
|
|
3136
|
+
},
|
|
3137
|
+
async cancel() {
|
|
3138
|
+
await iterator?.return?.();
|
|
3139
|
+
}
|
|
3140
|
+
}, {
|
|
3141
|
+
highWaterMark: 2 ** 24,
|
|
3142
|
+
...options
|
|
3143
|
+
});
|
|
3144
|
+
}
|
|
3145
|
+
var init_make_dom_stream = __esm({
|
|
3146
|
+
"src/iterators/make-stream/make-dom-stream.ts"() {
|
|
3147
|
+
}
|
|
3148
|
+
});
|
|
3149
|
+
|
|
3150
|
+
// src/null-loader.ts
|
|
3151
|
+
var VERSION4, NullWorkerLoader, NullLoader;
|
|
3152
|
+
var init_null_loader = __esm({
|
|
3153
|
+
"src/null-loader.ts"() {
|
|
3154
|
+
VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
3155
|
+
NullWorkerLoader = {
|
|
3156
|
+
name: "Null loader",
|
|
3157
|
+
id: "null",
|
|
3158
|
+
module: "core",
|
|
3159
|
+
version: VERSION4,
|
|
3160
|
+
worker: true,
|
|
3161
|
+
mimeTypes: ["application/x.empty"],
|
|
3162
|
+
extensions: ["null"],
|
|
3163
|
+
tests: [() => false],
|
|
3164
|
+
options: {
|
|
3165
|
+
null: {}
|
|
3166
|
+
}
|
|
3167
|
+
};
|
|
3168
|
+
NullLoader = {
|
|
3169
|
+
name: "Null loader",
|
|
3170
|
+
id: "null",
|
|
3171
|
+
module: "core",
|
|
3172
|
+
version: VERSION4,
|
|
3173
|
+
mimeTypes: ["application/x.empty"],
|
|
3174
|
+
extensions: ["null"],
|
|
3175
|
+
parse: async (arrayBuffer) => arrayBuffer,
|
|
3176
|
+
parseSync: (arrayBuffer) => arrayBuffer,
|
|
3177
|
+
parseInBatches: async function* generator(asyncIterator) {
|
|
3178
|
+
for await (const batch of asyncIterator) {
|
|
3179
|
+
yield batch;
|
|
3180
|
+
}
|
|
3181
|
+
},
|
|
3182
|
+
tests: [() => false],
|
|
3183
|
+
options: {
|
|
3184
|
+
null: {}
|
|
3185
|
+
}
|
|
3186
|
+
};
|
|
3187
|
+
}
|
|
3188
|
+
});
|
|
3189
|
+
|
|
3190
|
+
// src/lib/progress/fetch-progress.ts
|
|
3191
|
+
async function fetchProgress(response, onProgress, onDone = () => {
|
|
3192
|
+
}, onError = () => {
|
|
3193
|
+
}) {
|
|
3194
|
+
response = await response;
|
|
3195
|
+
if (!response.ok) {
|
|
3196
|
+
return response;
|
|
3197
|
+
}
|
|
3198
|
+
const body = response.body;
|
|
3199
|
+
if (!body) {
|
|
3200
|
+
return response;
|
|
3201
|
+
}
|
|
3202
|
+
const contentLength = response.headers.get("content-length") || 0;
|
|
3203
|
+
const totalBytes = contentLength && parseInt(contentLength);
|
|
3204
|
+
if (!(contentLength > 0)) {
|
|
3205
|
+
return response;
|
|
3206
|
+
}
|
|
3207
|
+
if (typeof ReadableStream === "undefined" || !body.getReader) {
|
|
3208
|
+
return response;
|
|
3209
|
+
}
|
|
3210
|
+
const progressStream = new ReadableStream({
|
|
3211
|
+
async start(controller) {
|
|
3212
|
+
const reader = body.getReader();
|
|
3213
|
+
await read(controller, reader, 0, totalBytes, onProgress, onDone, onError);
|
|
3214
|
+
}
|
|
3215
|
+
});
|
|
3216
|
+
return new Response(progressStream);
|
|
3217
|
+
}
|
|
3218
|
+
async function read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError) {
|
|
3219
|
+
try {
|
|
3220
|
+
const { done, value } = await reader.read();
|
|
3221
|
+
if (done) {
|
|
3222
|
+
onDone();
|
|
3223
|
+
controller.close();
|
|
3224
|
+
return;
|
|
3225
|
+
}
|
|
3226
|
+
loadedBytes += value.byteLength;
|
|
3227
|
+
const percent = Math.round(loadedBytes / totalBytes * 100);
|
|
3228
|
+
onProgress(percent, { loadedBytes, totalBytes });
|
|
3229
|
+
controller.enqueue(value);
|
|
3230
|
+
await read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError);
|
|
3231
|
+
} catch (error) {
|
|
3232
|
+
controller.error(error);
|
|
3233
|
+
onError(error);
|
|
3234
|
+
}
|
|
3235
|
+
}
|
|
3236
|
+
var init_fetch_progress = __esm({
|
|
3237
|
+
"src/lib/progress/fetch-progress.ts"() {
|
|
3238
|
+
}
|
|
3239
|
+
});
|
|
3240
|
+
|
|
3241
|
+
// src/lib/filesystems/browser-filesystem.ts
|
|
3242
|
+
var BrowserFileSystem;
|
|
3243
|
+
var init_browser_filesystem = __esm({
|
|
3244
|
+
"src/lib/filesystems/browser-filesystem.ts"() {
|
|
3245
|
+
BrowserFileSystem = class {
|
|
3246
|
+
constructor(files, options) {
|
|
3247
|
+
this.files = {};
|
|
3248
|
+
this.lowerCaseFiles = {};
|
|
3249
|
+
this.usedFiles = {};
|
|
3250
|
+
this._fetch = options?.fetch || fetch;
|
|
3251
|
+
for (let i = 0; i < files.length; ++i) {
|
|
3252
|
+
const file = files[i];
|
|
3253
|
+
this.files[file.name] = file;
|
|
3254
|
+
this.lowerCaseFiles[file.name.toLowerCase()] = file;
|
|
3255
|
+
this.usedFiles[file.name] = false;
|
|
3256
|
+
}
|
|
3257
|
+
this.fetch = this.fetch.bind(this);
|
|
3258
|
+
}
|
|
3259
|
+
async fetch(path, options) {
|
|
3260
|
+
if (path.includes("://")) {
|
|
3261
|
+
return this._fetch(path, options);
|
|
3262
|
+
}
|
|
3263
|
+
const file = this.files[path];
|
|
3264
|
+
if (!file) {
|
|
3265
|
+
return new Response(path, { status: 400, statusText: "NOT FOUND" });
|
|
3266
|
+
}
|
|
3267
|
+
const headers = new Headers(options?.headers);
|
|
3268
|
+
const range = headers.get("Range");
|
|
3269
|
+
const bytes = range && /bytes=($1)-($2)/.exec(range);
|
|
3270
|
+
if (bytes) {
|
|
3271
|
+
const start = parseInt(bytes[1]);
|
|
3272
|
+
const end = parseInt(bytes[2]);
|
|
3273
|
+
const data = await file.slice(start, end).arrayBuffer();
|
|
3274
|
+
const response2 = new Response(data);
|
|
3275
|
+
Object.defineProperty(response2, "url", { value: path });
|
|
3276
|
+
return response2;
|
|
3277
|
+
}
|
|
3278
|
+
const response = new Response(file);
|
|
3279
|
+
Object.defineProperty(response, "url", { value: path });
|
|
3280
|
+
return response;
|
|
3281
|
+
}
|
|
3282
|
+
async readdir(dirname2) {
|
|
3283
|
+
const files = [];
|
|
3284
|
+
for (const path in this.files) {
|
|
3285
|
+
files.push(path);
|
|
3286
|
+
}
|
|
3287
|
+
return files;
|
|
3288
|
+
}
|
|
3289
|
+
async stat(path, options) {
|
|
3290
|
+
const file = this.files[path];
|
|
3291
|
+
if (!file) {
|
|
3292
|
+
throw new Error(path);
|
|
3293
|
+
}
|
|
3294
|
+
return { size: file.size };
|
|
3295
|
+
}
|
|
3296
|
+
async unlink(path) {
|
|
3297
|
+
delete this.files[path];
|
|
3298
|
+
delete this.lowerCaseFiles[path];
|
|
3299
|
+
this.usedFiles[path] = true;
|
|
3300
|
+
}
|
|
3301
|
+
async open(pathname, flags, mode) {
|
|
3302
|
+
return this.files[pathname];
|
|
3303
|
+
}
|
|
3304
|
+
async read(fd, buffer, offset = 0, length = buffer.byteLength, position = null) {
|
|
3305
|
+
const file = fd;
|
|
3306
|
+
const startPosition = 0;
|
|
3307
|
+
const arrayBuffer = await file.slice(startPosition, startPosition + length).arrayBuffer();
|
|
3308
|
+
return { bytesRead: length, buffer: arrayBuffer };
|
|
3309
|
+
}
|
|
3310
|
+
async close(fd) {
|
|
3311
|
+
}
|
|
3312
|
+
_getFile(path, used) {
|
|
3313
|
+
const file = this.files[path] || this.lowerCaseFiles[path];
|
|
3314
|
+
if (file && used) {
|
|
3315
|
+
this.usedFiles[path] = true;
|
|
3316
|
+
}
|
|
3317
|
+
return file;
|
|
3318
|
+
}
|
|
3319
|
+
};
|
|
3320
|
+
}
|
|
3321
|
+
});
|
|
3322
|
+
|
|
3323
|
+
// src/index.ts
|
|
3324
|
+
var src_exports = {};
|
|
3325
|
+
__export(src_exports, {
|
|
3326
|
+
JSONLoader: () => JSONLoader,
|
|
3327
|
+
NullLoader: () => NullLoader,
|
|
3328
|
+
NullWorkerLoader: () => NullWorkerLoader,
|
|
3329
|
+
RequestScheduler: () => RequestScheduler,
|
|
3330
|
+
_BrowserFileSystem: () => BrowserFileSystem,
|
|
3331
|
+
_fetchProgress: () => fetchProgress,
|
|
3332
|
+
_unregisterLoaders: () => _unregisterLoaders,
|
|
3333
|
+
assert: () => assert,
|
|
3334
|
+
concatenateArrayBuffersAsync: () => concatenateArrayBuffersAsync,
|
|
3335
|
+
document: () => document_,
|
|
3336
|
+
encode: () => encode,
|
|
3337
|
+
encodeInBatches: () => encodeInBatches,
|
|
3338
|
+
encodeSync: () => encodeSync,
|
|
3339
|
+
encodeText: () => encodeText,
|
|
3340
|
+
encodeURLtoURL: () => encodeURLtoURL,
|
|
3341
|
+
fetchFile: () => fetchFile,
|
|
3342
|
+
forEach: () => forEach,
|
|
3343
|
+
getPathPrefix: () => getPathPrefix,
|
|
3344
|
+
global: () => global_,
|
|
3345
|
+
isAsyncIterable: () => isAsyncIterable,
|
|
3346
|
+
isBrowser: () => isBrowser,
|
|
3347
|
+
isIterable: () => isIterable,
|
|
3348
|
+
isIterator: () => isIterator,
|
|
3349
|
+
isPromise: () => isPromise,
|
|
3350
|
+
isPureObject: () => isPureObject,
|
|
3351
|
+
isReadableStream: () => isReadableStream,
|
|
3352
|
+
isResponse: () => isResponse,
|
|
3353
|
+
isWorker: () => isWorker,
|
|
3354
|
+
isWritableStream: () => isWritableStream,
|
|
3355
|
+
load: () => load,
|
|
3356
|
+
loadInBatches: () => loadInBatches,
|
|
3357
|
+
makeIterator: () => makeIterator,
|
|
3358
|
+
makeLineIterator: () => makeLineIterator,
|
|
3359
|
+
makeNumberedLineIterator: () => makeNumberedLineIterator,
|
|
3360
|
+
makeStream: () => makeStream,
|
|
3361
|
+
makeTextDecoderIterator: () => makeTextDecoderIterator,
|
|
3362
|
+
makeTextEncoderIterator: () => makeTextEncoderIterator,
|
|
3363
|
+
parse: () => parse,
|
|
3364
|
+
parseInBatches: () => parseInBatches,
|
|
3365
|
+
parseSync: () => parseSync,
|
|
3366
|
+
readArrayBuffer: () => readArrayBuffer,
|
|
3367
|
+
readFileSync: () => readFileSync,
|
|
3368
|
+
registerLoaders: () => registerLoaders,
|
|
3369
|
+
resolvePath: () => resolvePath,
|
|
3370
|
+
save: () => save,
|
|
3371
|
+
saveSync: () => saveSync,
|
|
3372
|
+
selectLoader: () => selectLoader,
|
|
3373
|
+
selectLoaderSync: () => selectLoaderSync,
|
|
3374
|
+
self: () => self_,
|
|
3375
|
+
setLoaderOptions: () => setLoaderOptions,
|
|
3376
|
+
setPathPrefix: () => setPathPrefix,
|
|
3377
|
+
window: () => window_,
|
|
3378
|
+
writeFile: () => writeFile,
|
|
3379
|
+
writeFileSync: () => writeFileSync
|
|
3380
|
+
});
|
|
3381
|
+
var init_src3 = __esm({
|
|
3382
|
+
"src/index.ts"() {
|
|
3383
|
+
init_fetch_file();
|
|
3384
|
+
init_read_array_buffer();
|
|
3385
|
+
init_read_file();
|
|
3386
|
+
init_write_file();
|
|
3387
|
+
init_set_loader_options();
|
|
3388
|
+
init_register_loaders();
|
|
3389
|
+
init_select_loader();
|
|
3390
|
+
init_parse();
|
|
3391
|
+
init_parse_sync();
|
|
3392
|
+
init_parse_in_batches();
|
|
3393
|
+
init_load();
|
|
3394
|
+
init_load_in_batches();
|
|
3395
|
+
init_encode();
|
|
3396
|
+
init_save();
|
|
3397
|
+
init_src2();
|
|
3398
|
+
init_src2();
|
|
3399
|
+
init_make_iterator();
|
|
3400
|
+
init_make_dom_stream();
|
|
3401
|
+
init_null_loader();
|
|
3402
|
+
init_src2();
|
|
3403
|
+
init_fetch_progress();
|
|
3404
|
+
init_browser_filesystem();
|
|
3405
|
+
init_register_loaders();
|
|
3406
|
+
init_src2();
|
|
3407
|
+
init_src2();
|
|
3408
|
+
init_src2();
|
|
3409
|
+
init_src2();
|
|
3410
|
+
init_is_type();
|
|
3411
|
+
}
|
|
3412
|
+
});
|
|
3413
|
+
|
|
3414
|
+
// src/bundle.ts
|
|
3415
|
+
var require_bundle = __commonJS({
|
|
3416
|
+
"src/bundle.ts"(exports, module2) {
|
|
3417
|
+
var moduleExports = (init_src3(), src_exports);
|
|
3418
|
+
globalThis.loaders = globalThis.loaders || {};
|
|
3419
|
+
module2.exports = Object.assign(globalThis.loaders, moduleExports);
|
|
3420
|
+
}
|
|
3421
|
+
});
|
|
3422
|
+
require_bundle();
|
|
3423
|
+
})();
|