@loaders.gl/core 4.2.0-alpha.6 → 4.2.0-beta.1
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/dist.dev.js +1941 -1894
- package/dist/dist.min.js +3 -3
- package/dist/index.cjs +110 -68
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/lib/api/select-loader.d.ts.map +1 -1
- package/dist/lib/api/select-loader.js +3 -2
- package/dist/lib/fetch/fetch-error-message.d.ts.map +1 -1
- package/dist/lib/fetch/fetch-error-message.js +2 -0
- package/dist/lib/fetch/fetch-error.d.ts +14 -0
- package/dist/lib/fetch/fetch-error.d.ts.map +1 -0
- package/dist/lib/fetch/fetch-error.js +17 -0
- package/dist/lib/fetch/fetch-file.d.ts.map +1 -1
- package/dist/lib/fetch/fetch-file.js +1 -0
- package/dist/lib/init.js +1 -1
- package/dist/lib/loader-utils/option-utils.d.ts +1 -1
- package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
- package/dist/lib/loader-utils/option-utils.js +3 -0
- package/dist/lib/utils/mime-type-utils.d.ts +8 -0
- package/dist/lib/utils/mime-type-utils.d.ts.map +1 -1
- package/dist/lib/utils/mime-type-utils.js +13 -0
- package/dist/lib/utils/response-utils.d.ts.map +1 -1
- package/dist/lib/utils/response-utils.js +16 -10
- package/dist/lib/utils/url-utils.d.ts +1 -0
- package/dist/lib/utils/url-utils.d.ts.map +1 -1
- package/dist/lib/utils/url-utils.js +8 -0
- package/dist/null-loader.d.ts +40 -3
- package/dist/null-loader.d.ts.map +1 -1
- package/dist/null-loader.js +5 -1
- package/dist/null-worker-node.js +3 -1
- package/dist/null-worker.js +3 -1
- package/package.json +5 -5
- package/src/index.ts +1 -0
- package/src/lib/api/select-loader.ts +3 -2
- package/src/lib/fetch/fetch-error-message.ts +2 -0
- package/src/lib/fetch/fetch-error.ts +18 -0
- package/src/lib/fetch/fetch-file.ts +1 -0
- package/src/lib/loader-utils/option-utils.ts +3 -1
- package/src/lib/utils/mime-type-utils.ts +14 -0
- package/src/lib/utils/response-utils.ts +19 -11
- package/src/lib/utils/url-utils.ts +9 -0
- package/src/null-loader.ts +9 -4
package/dist/dist.dev.js
CHANGED
|
@@ -32,6 +32,7 @@ var __exports__ = (() => {
|
|
|
32
32
|
// bundle.ts
|
|
33
33
|
var bundle_exports = {};
|
|
34
34
|
__export(bundle_exports, {
|
|
35
|
+
FetchError: () => FetchError,
|
|
35
36
|
JSONLoader: () => JSONLoader,
|
|
36
37
|
NullLoader: () => NullLoader,
|
|
37
38
|
NullWorkerLoader: () => NullWorkerLoader,
|
|
@@ -114,2195 +115,2236 @@ var __exports__ = (() => {
|
|
|
114
115
|
var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
115
116
|
var nodeVersion = matches && parseFloat(matches[1]) || 0;
|
|
116
117
|
|
|
117
|
-
//
|
|
118
|
-
function
|
|
119
|
-
|
|
118
|
+
// ../../node_modules/@babel/runtime/helpers/esm/typeof.js
|
|
119
|
+
function _typeof(obj) {
|
|
120
|
+
"@babel/helpers - typeof";
|
|
121
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
|
|
122
|
+
return typeof obj2;
|
|
123
|
+
} : function(obj2) {
|
|
124
|
+
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
125
|
+
}, _typeof(obj);
|
|
120
126
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
);
|
|
133
|
-
} else {
|
|
134
|
-
options[key] = newOptions[key];
|
|
135
|
-
}
|
|
127
|
+
|
|
128
|
+
// ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
|
|
129
|
+
function _toPrimitive(input, hint) {
|
|
130
|
+
if (_typeof(input) !== "object" || input === null)
|
|
131
|
+
return input;
|
|
132
|
+
var prim = input[Symbol.toPrimitive];
|
|
133
|
+
if (prim !== void 0) {
|
|
134
|
+
var res = prim.call(input, hint || "default");
|
|
135
|
+
if (_typeof(res) !== "object")
|
|
136
|
+
return res;
|
|
137
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
136
138
|
}
|
|
137
|
-
return
|
|
139
|
+
return (hint === "string" ? String : Number)(input);
|
|
138
140
|
}
|
|
139
141
|
|
|
140
|
-
//
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
142
|
+
// ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
|
|
143
|
+
function _toPropertyKey(arg) {
|
|
144
|
+
var key = _toPrimitive(arg, "string");
|
|
145
|
+
return _typeof(key) === "symbol" ? key : String(key);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
|
|
149
|
+
function _defineProperty(obj, key, value) {
|
|
150
|
+
key = _toPropertyKey(key);
|
|
151
|
+
if (key in obj) {
|
|
152
|
+
Object.defineProperty(obj, key, {
|
|
153
|
+
value,
|
|
154
|
+
enumerable: true,
|
|
155
|
+
configurable: true,
|
|
156
|
+
writable: true
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
obj[key] = value;
|
|
153
160
|
}
|
|
154
|
-
return
|
|
161
|
+
return obj;
|
|
155
162
|
}
|
|
156
|
-
var VERSION = getVersion();
|
|
157
163
|
|
|
158
|
-
//
|
|
159
|
-
function
|
|
160
|
-
if (
|
|
161
|
-
|
|
164
|
+
// ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/lib/is-electron.js
|
|
165
|
+
function isElectron(mockUserAgent) {
|
|
166
|
+
if (typeof window !== "undefined" && typeof window.process === "object" && window.process.type === "renderer") {
|
|
167
|
+
return true;
|
|
162
168
|
}
|
|
169
|
+
if (typeof process !== "undefined" && typeof process.versions === "object" && Boolean(process.versions["electron"])) {
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
const realUserAgent = typeof navigator === "object" && typeof navigator.userAgent === "string" && navigator.userAgent;
|
|
173
|
+
const userAgent = mockUserAgent || realUserAgent;
|
|
174
|
+
if (userAgent && userAgent.indexOf("Electron") >= 0) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
return false;
|
|
163
178
|
}
|
|
164
179
|
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
document: typeof document !== "undefined" && document
|
|
171
|
-
};
|
|
172
|
-
var self_2 = globals2.self || globals2.window || globals2.global || {};
|
|
173
|
-
var window_2 = globals2.window || globals2.self || globals2.global || {};
|
|
174
|
-
var global_2 = globals2.global || globals2.self || globals2.window || {};
|
|
175
|
-
var document_2 = globals2.document || {};
|
|
176
|
-
var isBrowser2 = (
|
|
177
|
-
// @ts-ignore process.browser
|
|
178
|
-
typeof process !== "object" || String(process) !== "[object process]" || process.browser
|
|
179
|
-
);
|
|
180
|
-
var isMobile = typeof window !== "undefined" && typeof window.orientation !== "undefined";
|
|
181
|
-
var matches2 = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
182
|
-
var nodeVersion2 = matches2 && parseFloat(matches2[1]) || 0;
|
|
180
|
+
// ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/lib/is-browser.js
|
|
181
|
+
function isBrowser2() {
|
|
182
|
+
const isNode = typeof process === "object" && String(process) === "[object process]" && !process.browser;
|
|
183
|
+
return !isNode || isElectron();
|
|
184
|
+
}
|
|
183
185
|
|
|
184
|
-
//
|
|
185
|
-
var
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
186
|
+
// ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/lib/globals.js
|
|
187
|
+
var self_2 = globalThis.self || globalThis.window || globalThis.global;
|
|
188
|
+
var window_2 = globalThis.window || globalThis.self || globalThis.global;
|
|
189
|
+
var document_2 = globalThis.document || {};
|
|
190
|
+
var process_ = globalThis.process || {};
|
|
191
|
+
var console_ = globalThis.console;
|
|
192
|
+
var navigator_ = globalThis.navigator || {};
|
|
193
|
+
|
|
194
|
+
// ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/utils/globals.js
|
|
195
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "untranspiled source";
|
|
196
|
+
var isBrowser3 = isBrowser2();
|
|
197
|
+
|
|
198
|
+
// ../../node_modules/@probe.gl/log/dist/utils/local-storage.js
|
|
199
|
+
function getStorage(type) {
|
|
200
|
+
try {
|
|
201
|
+
const storage = window[type];
|
|
202
|
+
const x = "__storage_test__";
|
|
203
|
+
storage.setItem(x, x);
|
|
204
|
+
storage.removeItem(x);
|
|
205
|
+
return storage;
|
|
206
|
+
} catch (e) {
|
|
207
|
+
return null;
|
|
202
208
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
this
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
209
|
+
}
|
|
210
|
+
var LocalStorage = class {
|
|
211
|
+
constructor(id, defaultConfig) {
|
|
212
|
+
let type = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "sessionStorage";
|
|
213
|
+
_defineProperty(this, "storage", void 0);
|
|
214
|
+
_defineProperty(this, "id", void 0);
|
|
215
|
+
_defineProperty(this, "config", void 0);
|
|
216
|
+
this.storage = getStorage(type);
|
|
217
|
+
this.id = id;
|
|
218
|
+
this.config = defaultConfig;
|
|
219
|
+
this._loadConfiguration();
|
|
214
220
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
*/
|
|
218
|
-
done(value) {
|
|
219
|
-
assert2(this.isRunning);
|
|
220
|
-
this.isRunning = false;
|
|
221
|
-
this._resolve(value);
|
|
221
|
+
getConfiguration() {
|
|
222
|
+
return this.config;
|
|
222
223
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
this._reject(error);
|
|
224
|
+
setConfiguration(configuration) {
|
|
225
|
+
Object.assign(this.config, configuration);
|
|
226
|
+
if (this.storage) {
|
|
227
|
+
const serialized = JSON.stringify(this.config);
|
|
228
|
+
this.storage.setItem(this.id, serialized);
|
|
229
|
+
}
|
|
230
230
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
231
|
+
_loadConfiguration() {
|
|
232
|
+
let configuration = {};
|
|
233
|
+
if (this.storage) {
|
|
234
|
+
const serializedConfiguration = this.storage.getItem(this.id);
|
|
235
|
+
configuration = serializedConfiguration ? JSON.parse(serializedConfiguration) : {};
|
|
236
|
+
}
|
|
237
|
+
Object.assign(this.config, configuration);
|
|
238
|
+
return this;
|
|
236
239
|
}
|
|
237
240
|
};
|
|
238
241
|
|
|
239
|
-
//
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
if (
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
workerURL = getLoadableWorkerURLFromSource(props.source);
|
|
251
|
-
workerURLCache.set(props.source, workerURL);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
assert2(workerURL);
|
|
255
|
-
return workerURL;
|
|
256
|
-
}
|
|
257
|
-
function getLoadableWorkerURLFromURL(url) {
|
|
258
|
-
if (!url.startsWith("http")) {
|
|
259
|
-
return url;
|
|
242
|
+
// ../../node_modules/@probe.gl/log/dist/utils/formatters.js
|
|
243
|
+
function formatTime(ms) {
|
|
244
|
+
let formatted;
|
|
245
|
+
if (ms < 10) {
|
|
246
|
+
formatted = "".concat(ms.toFixed(2), "ms");
|
|
247
|
+
} else if (ms < 100) {
|
|
248
|
+
formatted = "".concat(ms.toFixed(1), "ms");
|
|
249
|
+
} else if (ms < 1e3) {
|
|
250
|
+
formatted = "".concat(ms.toFixed(0), "ms");
|
|
251
|
+
} else {
|
|
252
|
+
formatted = "".concat((ms / 1e3).toFixed(2), "s");
|
|
260
253
|
}
|
|
261
|
-
|
|
262
|
-
return getLoadableWorkerURLFromSource(workerSource);
|
|
254
|
+
return formatted;
|
|
263
255
|
}
|
|
264
|
-
function
|
|
265
|
-
|
|
266
|
-
|
|
256
|
+
function leftPad(string) {
|
|
257
|
+
let length = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 8;
|
|
258
|
+
const padLength = Math.max(length - string.length, 0);
|
|
259
|
+
return "".concat(" ".repeat(padLength)).concat(string);
|
|
267
260
|
}
|
|
268
|
-
function
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
261
|
+
function formatImage(image, message, scale) {
|
|
262
|
+
let maxWidth = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 600;
|
|
263
|
+
const imageUrl = image.src.replace(/\(/g, "%28").replace(/\)/g, "%29");
|
|
264
|
+
if (image.width > maxWidth) {
|
|
265
|
+
scale = Math.min(scale, maxWidth / image.width);
|
|
266
|
+
}
|
|
267
|
+
const width = image.width * scale;
|
|
268
|
+
const height = image.height * scale;
|
|
269
|
+
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("");
|
|
270
|
+
return ["".concat(message, " %c+"), style];
|
|
275
271
|
}
|
|
276
272
|
|
|
277
|
-
//
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
273
|
+
// ../../node_modules/@probe.gl/log/dist/utils/color.js
|
|
274
|
+
var COLOR;
|
|
275
|
+
(function(COLOR2) {
|
|
276
|
+
COLOR2[COLOR2["BLACK"] = 30] = "BLACK";
|
|
277
|
+
COLOR2[COLOR2["RED"] = 31] = "RED";
|
|
278
|
+
COLOR2[COLOR2["GREEN"] = 32] = "GREEN";
|
|
279
|
+
COLOR2[COLOR2["YELLOW"] = 33] = "YELLOW";
|
|
280
|
+
COLOR2[COLOR2["BLUE"] = 34] = "BLUE";
|
|
281
|
+
COLOR2[COLOR2["MAGENTA"] = 35] = "MAGENTA";
|
|
282
|
+
COLOR2[COLOR2["CYAN"] = 36] = "CYAN";
|
|
283
|
+
COLOR2[COLOR2["WHITE"] = 37] = "WHITE";
|
|
284
|
+
COLOR2[COLOR2["BRIGHT_BLACK"] = 90] = "BRIGHT_BLACK";
|
|
285
|
+
COLOR2[COLOR2["BRIGHT_RED"] = 91] = "BRIGHT_RED";
|
|
286
|
+
COLOR2[COLOR2["BRIGHT_GREEN"] = 92] = "BRIGHT_GREEN";
|
|
287
|
+
COLOR2[COLOR2["BRIGHT_YELLOW"] = 93] = "BRIGHT_YELLOW";
|
|
288
|
+
COLOR2[COLOR2["BRIGHT_BLUE"] = 94] = "BRIGHT_BLUE";
|
|
289
|
+
COLOR2[COLOR2["BRIGHT_MAGENTA"] = 95] = "BRIGHT_MAGENTA";
|
|
290
|
+
COLOR2[COLOR2["BRIGHT_CYAN"] = 96] = "BRIGHT_CYAN";
|
|
291
|
+
COLOR2[COLOR2["BRIGHT_WHITE"] = 97] = "BRIGHT_WHITE";
|
|
292
|
+
})(COLOR || (COLOR = {}));
|
|
293
|
+
var BACKGROUND_INCREMENT = 10;
|
|
294
|
+
function getColor(color) {
|
|
295
|
+
if (typeof color !== "string") {
|
|
296
|
+
return color;
|
|
290
297
|
}
|
|
291
|
-
|
|
298
|
+
color = color.toUpperCase();
|
|
299
|
+
return COLOR[color] || COLOR.WHITE;
|
|
292
300
|
}
|
|
293
|
-
function
|
|
294
|
-
if (!
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
301
|
+
function addColor(string, color, background) {
|
|
302
|
+
if (!isBrowser2 && typeof string === "string") {
|
|
303
|
+
if (color) {
|
|
304
|
+
const colorCode = getColor(color);
|
|
305
|
+
string = "\x1B[".concat(colorCode, "m").concat(string, "\x1B[39m");
|
|
306
|
+
}
|
|
307
|
+
if (background) {
|
|
308
|
+
const colorCode = getColor(background);
|
|
309
|
+
string = "\x1B[".concat(colorCode + BACKGROUND_INCREMENT, "m").concat(string, "\x1B[49m");
|
|
310
|
+
}
|
|
302
311
|
}
|
|
303
|
-
|
|
304
|
-
|
|
312
|
+
return string;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// ../../node_modules/@probe.gl/log/dist/utils/autobind.js
|
|
316
|
+
function autobind(obj) {
|
|
317
|
+
let predefined = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ["constructor"];
|
|
318
|
+
const proto = Object.getPrototypeOf(obj);
|
|
319
|
+
const propNames = Object.getOwnPropertyNames(proto);
|
|
320
|
+
const object = obj;
|
|
321
|
+
for (const key of propNames) {
|
|
322
|
+
const value = object[key];
|
|
323
|
+
if (typeof value === "function") {
|
|
324
|
+
if (!predefined.find((name) => key === name)) {
|
|
325
|
+
object[key] = value.bind(obj);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
305
328
|
}
|
|
306
|
-
|
|
307
|
-
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// ../../node_modules/@probe.gl/log/dist/utils/assert.js
|
|
332
|
+
function assert2(condition, message) {
|
|
333
|
+
if (!condition) {
|
|
334
|
+
throw new Error(message || "Assertion failed");
|
|
308
335
|
}
|
|
309
|
-
return false;
|
|
310
336
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
337
|
+
|
|
338
|
+
// ../../node_modules/@probe.gl/log/dist/utils/hi-res-timestamp.js
|
|
339
|
+
function getHiResTimestamp() {
|
|
340
|
+
let timestamp;
|
|
341
|
+
if (isBrowser2() && window_2.performance) {
|
|
342
|
+
var _window$performance, _window$performance$n;
|
|
343
|
+
timestamp = window_2 === null || window_2 === void 0 ? void 0 : (_window$performance = window_2.performance) === null || _window$performance === void 0 ? void 0 : (_window$performance$n = _window$performance.now) === null || _window$performance$n === void 0 ? void 0 : _window$performance$n.call(_window$performance);
|
|
344
|
+
} else if ("hrtime" in process_) {
|
|
345
|
+
var _process$hrtime;
|
|
346
|
+
const timeParts = process_ === null || process_ === void 0 ? void 0 : (_process$hrtime = process_.hrtime) === null || _process$hrtime === void 0 ? void 0 : _process$hrtime.call(process_);
|
|
347
|
+
timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
|
|
348
|
+
} else {
|
|
349
|
+
timestamp = Date.now();
|
|
314
350
|
}
|
|
315
|
-
|
|
316
|
-
Object.keys(clone).forEach((key) => {
|
|
317
|
-
if (typeof object[key] === "object" && !ArrayBuffer.isView(object[key]) && !(object[key] instanceof Array)) {
|
|
318
|
-
clone[key] = getTransferListForWriter(object[key]);
|
|
319
|
-
} else if (typeof clone[key] === "function" || clone[key] instanceof RegExp) {
|
|
320
|
-
clone[key] = {};
|
|
321
|
-
} else {
|
|
322
|
-
clone[key] = object[key];
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
return clone;
|
|
351
|
+
return timestamp;
|
|
326
352
|
}
|
|
327
353
|
|
|
328
|
-
//
|
|
329
|
-
var
|
|
354
|
+
// ../../node_modules/@probe.gl/log/dist/log.js
|
|
355
|
+
var originalConsole = {
|
|
356
|
+
debug: isBrowser2() ? console.debug || console.log : console.log,
|
|
357
|
+
log: console.log,
|
|
358
|
+
info: console.info,
|
|
359
|
+
warn: console.warn,
|
|
360
|
+
error: console.error
|
|
330
361
|
};
|
|
331
|
-
var
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
362
|
+
var DEFAULT_LOG_CONFIGURATION = {
|
|
363
|
+
enabled: true,
|
|
364
|
+
level: 0
|
|
365
|
+
};
|
|
366
|
+
function noop() {
|
|
367
|
+
}
|
|
368
|
+
var cache = {};
|
|
369
|
+
var ONCE = {
|
|
370
|
+
once: true
|
|
371
|
+
};
|
|
372
|
+
var Log = class {
|
|
373
|
+
constructor() {
|
|
374
|
+
let {
|
|
375
|
+
id
|
|
376
|
+
} = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
|
|
377
|
+
id: ""
|
|
378
|
+
};
|
|
379
|
+
_defineProperty(this, "id", void 0);
|
|
380
|
+
_defineProperty(this, "VERSION", VERSION);
|
|
381
|
+
_defineProperty(this, "_startTs", getHiResTimestamp());
|
|
382
|
+
_defineProperty(this, "_deltaTs", getHiResTimestamp());
|
|
383
|
+
_defineProperty(this, "_storage", void 0);
|
|
384
|
+
_defineProperty(this, "userData", {});
|
|
385
|
+
_defineProperty(this, "LOG_THROTTLE_TIMEOUT", 0);
|
|
386
|
+
this.id = id;
|
|
387
|
+
this.userData = {};
|
|
388
|
+
this._storage = new LocalStorage("__probe-".concat(this.id, "__"), DEFAULT_LOG_CONFIGURATION);
|
|
389
|
+
this.timeStamp("".concat(this.id, " started"));
|
|
390
|
+
autobind(this);
|
|
391
|
+
Object.seal(this);
|
|
343
392
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
assert2(source || url);
|
|
347
|
-
this.name = name;
|
|
348
|
-
this.source = source;
|
|
349
|
-
this.url = url;
|
|
350
|
-
this.onMessage = NOOP;
|
|
351
|
-
this.onError = (error) => console.log(error);
|
|
352
|
-
this.worker = isBrowser2 ? this._createBrowserWorker() : this._createNodeWorker();
|
|
393
|
+
set level(newLevel) {
|
|
394
|
+
this.setLevel(newLevel);
|
|
353
395
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
* @note Can free up significant memory
|
|
357
|
-
*/
|
|
358
|
-
destroy() {
|
|
359
|
-
this.onMessage = NOOP;
|
|
360
|
-
this.onError = NOOP;
|
|
361
|
-
this.worker.terminate();
|
|
362
|
-
this.terminated = true;
|
|
396
|
+
get level() {
|
|
397
|
+
return this.getLevel();
|
|
363
398
|
}
|
|
364
|
-
|
|
365
|
-
return
|
|
399
|
+
isEnabled() {
|
|
400
|
+
return this._storage.config.enabled;
|
|
366
401
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
370
|
-
* @param transferList If not supplied, calculated automatically by traversing data
|
|
371
|
-
*/
|
|
372
|
-
postMessage(data, transferList) {
|
|
373
|
-
transferList = transferList || getTransferList(data);
|
|
374
|
-
this.worker.postMessage(data, transferList);
|
|
402
|
+
getLevel() {
|
|
403
|
+
return this._storage.config.level;
|
|
375
404
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
* Generate a standard Error from an ErrorEvent
|
|
379
|
-
* @param event
|
|
380
|
-
*/
|
|
381
|
-
_getErrorFromErrorEvent(event) {
|
|
382
|
-
let message = "Failed to load ";
|
|
383
|
-
message += `worker ${this.name} from ${this.url}. `;
|
|
384
|
-
if (event.message) {
|
|
385
|
-
message += `${event.message} in `;
|
|
386
|
-
}
|
|
387
|
-
if (event.lineno) {
|
|
388
|
-
message += `:${event.lineno}:${event.colno}`;
|
|
389
|
-
}
|
|
390
|
-
return new Error(message);
|
|
405
|
+
getTotal() {
|
|
406
|
+
return Number((getHiResTimestamp() - this._startTs).toPrecision(10));
|
|
391
407
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
*/
|
|
395
|
-
_createBrowserWorker() {
|
|
396
|
-
this._loadableURL = getLoadableWorkerURL({ source: this.source, url: this.url });
|
|
397
|
-
const worker = new Worker(this._loadableURL, { name: this.name });
|
|
398
|
-
worker.onmessage = (event) => {
|
|
399
|
-
if (!event.data) {
|
|
400
|
-
this.onError(new Error("No data received"));
|
|
401
|
-
} else {
|
|
402
|
-
this.onMessage(event.data);
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
worker.onerror = (error) => {
|
|
406
|
-
this.onError(this._getErrorFromErrorEvent(error));
|
|
407
|
-
this.terminated = true;
|
|
408
|
-
};
|
|
409
|
-
worker.onmessageerror = (event) => console.error(event);
|
|
410
|
-
return worker;
|
|
408
|
+
getDelta() {
|
|
409
|
+
return Number((getHiResTimestamp() - this._deltaTs).toPrecision(10));
|
|
411
410
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
* @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool
|
|
415
|
-
*/
|
|
416
|
-
_createNodeWorker() {
|
|
417
|
-
let worker;
|
|
418
|
-
if (this.url) {
|
|
419
|
-
const absolute = this.url.includes(":/") || this.url.startsWith("/");
|
|
420
|
-
const url = absolute ? this.url : `./${this.url}`;
|
|
421
|
-
worker = new NodeWorker(url, { eval: false });
|
|
422
|
-
} else if (this.source) {
|
|
423
|
-
worker = new NodeWorker(this.source, { eval: true });
|
|
424
|
-
} else {
|
|
425
|
-
throw new Error("no worker");
|
|
426
|
-
}
|
|
427
|
-
worker.on("message", (data) => {
|
|
428
|
-
this.onMessage(data);
|
|
429
|
-
});
|
|
430
|
-
worker.on("error", (error) => {
|
|
431
|
-
this.onError(error);
|
|
432
|
-
});
|
|
433
|
-
worker.on("exit", (code) => {
|
|
434
|
-
});
|
|
435
|
-
return worker;
|
|
411
|
+
set priority(newPriority) {
|
|
412
|
+
this.level = newPriority;
|
|
436
413
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
// ../worker-utils/src/lib/worker-farm/worker-pool.ts
|
|
440
|
-
var WorkerPool = class {
|
|
441
|
-
name = "unnamed";
|
|
442
|
-
source;
|
|
443
|
-
// | Function;
|
|
444
|
-
url;
|
|
445
|
-
maxConcurrency = 1;
|
|
446
|
-
maxMobileConcurrency = 1;
|
|
447
|
-
onDebug = () => {
|
|
448
|
-
};
|
|
449
|
-
reuseWorkers = true;
|
|
450
|
-
props = {};
|
|
451
|
-
jobQueue = [];
|
|
452
|
-
idleQueue = [];
|
|
453
|
-
count = 0;
|
|
454
|
-
isDestroyed = false;
|
|
455
|
-
/** Checks if workers are supported on this platform */
|
|
456
|
-
static isSupported() {
|
|
457
|
-
return WorkerThread.isSupported();
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* @param processor - worker function
|
|
461
|
-
* @param maxConcurrency - max count of workers
|
|
462
|
-
*/
|
|
463
|
-
constructor(props) {
|
|
464
|
-
this.source = props.source;
|
|
465
|
-
this.url = props.url;
|
|
466
|
-
this.setProps(props);
|
|
414
|
+
get priority() {
|
|
415
|
+
return this.level;
|
|
467
416
|
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
* @note Can free up significant memory
|
|
471
|
-
*/
|
|
472
|
-
destroy() {
|
|
473
|
-
this.idleQueue.forEach((worker) => worker.destroy());
|
|
474
|
-
this.isDestroyed = true;
|
|
417
|
+
getPriority() {
|
|
418
|
+
return this.level;
|
|
475
419
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
this.maxConcurrency = props.maxConcurrency;
|
|
483
|
-
}
|
|
484
|
-
if (props.maxMobileConcurrency !== void 0) {
|
|
485
|
-
this.maxMobileConcurrency = props.maxMobileConcurrency;
|
|
486
|
-
}
|
|
487
|
-
if (props.reuseWorkers !== void 0) {
|
|
488
|
-
this.reuseWorkers = props.reuseWorkers;
|
|
489
|
-
}
|
|
490
|
-
if (props.onDebug !== void 0) {
|
|
491
|
-
this.onDebug = props.onDebug;
|
|
492
|
-
}
|
|
420
|
+
enable() {
|
|
421
|
+
let enabled = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
|
|
422
|
+
this._storage.setConfiguration({
|
|
423
|
+
enabled
|
|
424
|
+
});
|
|
425
|
+
return this;
|
|
493
426
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
return this;
|
|
427
|
+
setLevel(level) {
|
|
428
|
+
this._storage.setConfiguration({
|
|
429
|
+
level
|
|
498
430
|
});
|
|
499
|
-
this
|
|
500
|
-
return await startPromise;
|
|
431
|
+
return this;
|
|
501
432
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
* Starts first queued job if worker is available or can be created
|
|
505
|
-
* Called when job is started and whenever a worker returns to the idleQueue
|
|
506
|
-
*/
|
|
507
|
-
async _startQueuedJob() {
|
|
508
|
-
if (!this.jobQueue.length) {
|
|
509
|
-
return;
|
|
510
|
-
}
|
|
511
|
-
const workerThread = this._getAvailableWorker();
|
|
512
|
-
if (!workerThread) {
|
|
513
|
-
return;
|
|
514
|
-
}
|
|
515
|
-
const queuedJob = this.jobQueue.shift();
|
|
516
|
-
if (queuedJob) {
|
|
517
|
-
this.onDebug({
|
|
518
|
-
message: "Starting job",
|
|
519
|
-
name: queuedJob.name,
|
|
520
|
-
workerThread,
|
|
521
|
-
backlog: this.jobQueue.length
|
|
522
|
-
});
|
|
523
|
-
const job = new WorkerJob(queuedJob.name, workerThread);
|
|
524
|
-
workerThread.onMessage = (data) => queuedJob.onMessage(job, data.type, data.payload);
|
|
525
|
-
workerThread.onError = (error) => queuedJob.onError(job, error);
|
|
526
|
-
queuedJob.onStart(job);
|
|
527
|
-
try {
|
|
528
|
-
await job.result;
|
|
529
|
-
} catch (error) {
|
|
530
|
-
console.error(`Worker exception: ${error}`);
|
|
531
|
-
} finally {
|
|
532
|
-
this.returnWorkerToQueue(workerThread);
|
|
533
|
-
}
|
|
534
|
-
}
|
|
433
|
+
get(setting) {
|
|
434
|
+
return this._storage.config[setting];
|
|
535
435
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
returnWorkerToQueue(worker) {
|
|
545
|
-
const shouldDestroyWorker = (
|
|
546
|
-
// Workers on Node.js prevent the process from exiting.
|
|
547
|
-
// Until we figure out how to close them before exit, we always destroy them
|
|
548
|
-
!isBrowser2 || // If the pool is destroyed, there is no reason to keep the worker around
|
|
549
|
-
this.isDestroyed || // If the app has disabled worker reuse, any completed workers should be destroyed
|
|
550
|
-
!this.reuseWorkers || // If concurrency has been lowered, this worker might be surplus to requirements
|
|
551
|
-
this.count > this._getMaxConcurrency()
|
|
552
|
-
);
|
|
553
|
-
if (shouldDestroyWorker) {
|
|
554
|
-
worker.destroy();
|
|
555
|
-
this.count--;
|
|
436
|
+
set(setting, value) {
|
|
437
|
+
this._storage.setConfiguration({
|
|
438
|
+
[setting]: value
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
settings() {
|
|
442
|
+
if (console.table) {
|
|
443
|
+
console.table(this._storage.config);
|
|
556
444
|
} else {
|
|
557
|
-
this.
|
|
558
|
-
}
|
|
559
|
-
if (!this.isDestroyed) {
|
|
560
|
-
this._startQueuedJob();
|
|
445
|
+
console.log(this._storage.config);
|
|
561
446
|
}
|
|
562
447
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
*/
|
|
566
|
-
_getAvailableWorker() {
|
|
567
|
-
if (this.idleQueue.length > 0) {
|
|
568
|
-
return this.idleQueue.shift() || null;
|
|
569
|
-
}
|
|
570
|
-
if (this.count < this._getMaxConcurrency()) {
|
|
571
|
-
this.count++;
|
|
572
|
-
const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;
|
|
573
|
-
return new WorkerThread({ name, source: this.source, url: this.url });
|
|
574
|
-
}
|
|
575
|
-
return null;
|
|
448
|
+
assert(condition, message) {
|
|
449
|
+
assert2(condition, message);
|
|
576
450
|
}
|
|
577
|
-
|
|
578
|
-
return
|
|
451
|
+
warn(message) {
|
|
452
|
+
return this._getLogFunction(0, message, originalConsole.warn, arguments, ONCE);
|
|
579
453
|
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
// ../worker-utils/src/lib/worker-farm/worker-farm.ts
|
|
583
|
-
var DEFAULT_PROPS = {
|
|
584
|
-
maxConcurrency: 3,
|
|
585
|
-
maxMobileConcurrency: 1,
|
|
586
|
-
reuseWorkers: true,
|
|
587
|
-
onDebug: () => {
|
|
454
|
+
error(message) {
|
|
455
|
+
return this._getLogFunction(0, message, originalConsole.error, arguments);
|
|
588
456
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
props;
|
|
592
|
-
workerPools = /* @__PURE__ */ new Map();
|
|
593
|
-
/** Checks if workers are supported on this platform */
|
|
594
|
-
static isSupported() {
|
|
595
|
-
return WorkerThread.isSupported();
|
|
457
|
+
deprecated(oldUsage, newUsage) {
|
|
458
|
+
return this.warn("`".concat(oldUsage, "` is deprecated and will be removed in a later version. Use `").concat(newUsage, "` instead"));
|
|
596
459
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
_WorkerFarm._workerFarm = _WorkerFarm._workerFarm || new _WorkerFarm({});
|
|
600
|
-
_WorkerFarm._workerFarm.setProps(props);
|
|
601
|
-
return _WorkerFarm._workerFarm;
|
|
460
|
+
removed(oldUsage, newUsage) {
|
|
461
|
+
return this.error("`".concat(oldUsage, "` has been removed. Use `").concat(newUsage, "` instead"));
|
|
602
462
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
463
|
+
probe(logLevel, message) {
|
|
464
|
+
return this._getLogFunction(logLevel, message, originalConsole.log, arguments, {
|
|
465
|
+
time: true,
|
|
466
|
+
once: true
|
|
467
|
+
});
|
|
608
468
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
* @note Can free up significant memory
|
|
612
|
-
*/
|
|
613
|
-
destroy() {
|
|
614
|
-
for (const workerPool of this.workerPools.values()) {
|
|
615
|
-
workerPool.destroy();
|
|
616
|
-
}
|
|
617
|
-
this.workerPools = /* @__PURE__ */ new Map();
|
|
469
|
+
log(logLevel, message) {
|
|
470
|
+
return this._getLogFunction(logLevel, message, originalConsole.debug, arguments);
|
|
618
471
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
* @param props
|
|
622
|
-
*/
|
|
623
|
-
setProps(props) {
|
|
624
|
-
this.props = { ...this.props, ...props };
|
|
625
|
-
for (const workerPool of this.workerPools.values()) {
|
|
626
|
-
workerPool.setProps(this._getWorkerPoolProps());
|
|
627
|
-
}
|
|
472
|
+
info(logLevel, message) {
|
|
473
|
+
return this._getLogFunction(logLevel, message, console.info, arguments);
|
|
628
474
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
* const job = WorkerFarm.getWorkerFarm().getWorkerPool({name, url}).startJob(...);
|
|
637
|
-
*/
|
|
638
|
-
getWorkerPool(options) {
|
|
639
|
-
const { name, source, url } = options;
|
|
640
|
-
let workerPool = this.workerPools.get(name);
|
|
641
|
-
if (!workerPool) {
|
|
642
|
-
workerPool = new WorkerPool({
|
|
643
|
-
name,
|
|
644
|
-
source,
|
|
645
|
-
url
|
|
475
|
+
once(logLevel, message) {
|
|
476
|
+
return this._getLogFunction(logLevel, message, originalConsole.debug || originalConsole.info, arguments, ONCE);
|
|
477
|
+
}
|
|
478
|
+
table(logLevel, table, columns) {
|
|
479
|
+
if (table) {
|
|
480
|
+
return this._getLogFunction(logLevel, table, console.table || noop, columns && [columns], {
|
|
481
|
+
tag: getTableHeader(table)
|
|
646
482
|
});
|
|
647
|
-
workerPool.setProps(this._getWorkerPoolProps());
|
|
648
|
-
this.workerPools.set(name, workerPool);
|
|
649
483
|
}
|
|
650
|
-
return
|
|
651
|
-
}
|
|
652
|
-
_getWorkerPoolProps() {
|
|
653
|
-
return {
|
|
654
|
-
maxConcurrency: this.props.maxConcurrency,
|
|
655
|
-
maxMobileConcurrency: this.props.maxMobileConcurrency,
|
|
656
|
-
reuseWorkers: this.props.reuseWorkers,
|
|
657
|
-
onDebug: this.props.onDebug
|
|
658
|
-
};
|
|
484
|
+
return noop;
|
|
659
485
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
486
|
+
image(_ref) {
|
|
487
|
+
let {
|
|
488
|
+
logLevel,
|
|
489
|
+
priority,
|
|
490
|
+
image,
|
|
491
|
+
message = "",
|
|
492
|
+
scale = 1
|
|
493
|
+
} = _ref;
|
|
494
|
+
if (!this._shouldLog(logLevel || priority)) {
|
|
495
|
+
return noop;
|
|
496
|
+
}
|
|
497
|
+
return isBrowser2() ? logImageInBrowser({
|
|
498
|
+
image,
|
|
499
|
+
message,
|
|
500
|
+
scale
|
|
501
|
+
}) : logImageInNode({
|
|
502
|
+
image,
|
|
503
|
+
message,
|
|
504
|
+
scale
|
|
505
|
+
});
|
|
676
506
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
507
|
+
time(logLevel, message) {
|
|
508
|
+
return this._getLogFunction(logLevel, message, console.time ? console.time : console.info);
|
|
509
|
+
}
|
|
510
|
+
timeEnd(logLevel, message) {
|
|
511
|
+
return this._getLogFunction(logLevel, message, console.timeEnd ? console.timeEnd : console.info);
|
|
512
|
+
}
|
|
513
|
+
timeStamp(logLevel, message) {
|
|
514
|
+
return this._getLogFunction(logLevel, message, console.timeStamp || noop);
|
|
515
|
+
}
|
|
516
|
+
group(logLevel, message) {
|
|
517
|
+
let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {
|
|
518
|
+
collapsed: false
|
|
519
|
+
};
|
|
520
|
+
const options = normalizeArguments({
|
|
521
|
+
logLevel,
|
|
522
|
+
message,
|
|
523
|
+
opts
|
|
524
|
+
});
|
|
525
|
+
const {
|
|
526
|
+
collapsed
|
|
527
|
+
} = opts;
|
|
528
|
+
options.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
|
|
529
|
+
return this._getLogFunction(options);
|
|
530
|
+
}
|
|
531
|
+
groupCollapsed(logLevel, message) {
|
|
532
|
+
let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
533
|
+
return this.group(logLevel, message, Object.assign({}, opts, {
|
|
534
|
+
collapsed: true
|
|
535
|
+
}));
|
|
536
|
+
}
|
|
537
|
+
groupEnd(logLevel) {
|
|
538
|
+
return this._getLogFunction(logLevel, "", console.groupEnd || noop);
|
|
539
|
+
}
|
|
540
|
+
withGroup(logLevel, message, func) {
|
|
541
|
+
this.group(logLevel, message)();
|
|
542
|
+
try {
|
|
543
|
+
func();
|
|
544
|
+
} finally {
|
|
545
|
+
this.groupEnd(logLevel)();
|
|
682
546
|
}
|
|
683
547
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
version = NPM_TAG;
|
|
548
|
+
trace() {
|
|
549
|
+
if (console.trace) {
|
|
550
|
+
console.trace();
|
|
688
551
|
}
|
|
689
|
-
const versionTag = version ? `@${version}` : "";
|
|
690
|
-
url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;
|
|
691
552
|
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
// ../worker-utils/src/lib/worker-api/process-on-worker.ts
|
|
697
|
-
async function processOnWorker(worker, data, options = {}, context = {}) {
|
|
698
|
-
const name = getWorkerName(worker);
|
|
699
|
-
const workerFarm = WorkerFarm.getWorkerFarm(options);
|
|
700
|
-
const { source } = options;
|
|
701
|
-
const workerPoolProps = { name, source };
|
|
702
|
-
if (!source) {
|
|
703
|
-
workerPoolProps.url = getWorkerURL(worker, options);
|
|
553
|
+
_shouldLog(logLevel) {
|
|
554
|
+
return this.isEnabled() && this.getLevel() >= normalizeLogLevel(logLevel);
|
|
704
555
|
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
break;
|
|
725
|
-
case "process":
|
|
726
|
-
const { id, input, options } = payload;
|
|
727
|
-
try {
|
|
728
|
-
if (!context.process) {
|
|
729
|
-
job.postMessage("error", { id, error: "Worker not set up to process on main thread" });
|
|
730
|
-
return;
|
|
556
|
+
_getLogFunction(logLevel, message, method, args, opts) {
|
|
557
|
+
if (this._shouldLog(logLevel)) {
|
|
558
|
+
opts = normalizeArguments({
|
|
559
|
+
logLevel,
|
|
560
|
+
message,
|
|
561
|
+
args,
|
|
562
|
+
opts
|
|
563
|
+
});
|
|
564
|
+
method = method || opts.method;
|
|
565
|
+
assert2(method);
|
|
566
|
+
opts.total = this.getTotal();
|
|
567
|
+
opts.delta = this.getDelta();
|
|
568
|
+
this._deltaTs = getHiResTimestamp();
|
|
569
|
+
const tag = opts.tag || opts.message;
|
|
570
|
+
if (opts.once && tag) {
|
|
571
|
+
if (!cache[tag]) {
|
|
572
|
+
cache[tag] = getHiResTimestamp();
|
|
573
|
+
} else {
|
|
574
|
+
return noop;
|
|
731
575
|
}
|
|
732
|
-
const result = await context.process(input, options);
|
|
733
|
-
job.postMessage("done", { id, result });
|
|
734
|
-
} catch (error) {
|
|
735
|
-
const message = error instanceof Error ? error.message : "unknown error";
|
|
736
|
-
job.postMessage("error", { id, error: message });
|
|
737
576
|
}
|
|
577
|
+
message = decorateMessage(this.id, opts.message, opts);
|
|
578
|
+
return method.bind(console, message, ...opts.args);
|
|
579
|
+
}
|
|
580
|
+
return noop;
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
_defineProperty(Log, "VERSION", VERSION);
|
|
584
|
+
function normalizeLogLevel(logLevel) {
|
|
585
|
+
if (!logLevel) {
|
|
586
|
+
return 0;
|
|
587
|
+
}
|
|
588
|
+
let resolvedLevel;
|
|
589
|
+
switch (typeof logLevel) {
|
|
590
|
+
case "number":
|
|
591
|
+
resolvedLevel = logLevel;
|
|
592
|
+
break;
|
|
593
|
+
case "object":
|
|
594
|
+
resolvedLevel = logLevel.logLevel || logLevel.priority || 0;
|
|
738
595
|
break;
|
|
739
596
|
default:
|
|
740
|
-
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
// ../worker-utils/src/lib/worker-api/validate-worker-version.ts
|
|
745
|
-
function validateWorkerVersion(worker, coreVersion = VERSION) {
|
|
746
|
-
assert2(worker, "no worker provided");
|
|
747
|
-
const workerVersion = worker.version;
|
|
748
|
-
if (!coreVersion || !workerVersion) {
|
|
749
|
-
return false;
|
|
597
|
+
return 0;
|
|
750
598
|
}
|
|
751
|
-
|
|
599
|
+
assert2(Number.isFinite(resolvedLevel) && resolvedLevel >= 0);
|
|
600
|
+
return resolvedLevel;
|
|
752
601
|
}
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
602
|
+
function normalizeArguments(opts) {
|
|
603
|
+
const {
|
|
604
|
+
logLevel,
|
|
605
|
+
message
|
|
606
|
+
} = opts;
|
|
607
|
+
opts.logLevel = normalizeLogLevel(logLevel);
|
|
608
|
+
const args = opts.args ? Array.from(opts.args) : [];
|
|
609
|
+
while (args.length && args.shift() !== message) {
|
|
761
610
|
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
const workerFarm = WorkerFarm.getWorkerFarm(options);
|
|
768
|
-
const workerPool = workerFarm.getWorkerPool({ name, url });
|
|
769
|
-
options = JSON.parse(JSON.stringify(options));
|
|
770
|
-
context = JSON.parse(JSON.stringify(context || {}));
|
|
771
|
-
const job = await workerPool.startJob(
|
|
772
|
-
"process-on-worker",
|
|
773
|
-
// @ts-expect-error
|
|
774
|
-
onMessage2.bind(null, parseOnMainThread)
|
|
775
|
-
// eslint-disable-line @typescript-eslint/no-misused-promises
|
|
776
|
-
);
|
|
777
|
-
job.postMessage("process", {
|
|
778
|
-
// @ts-ignore
|
|
779
|
-
input: data,
|
|
780
|
-
options,
|
|
781
|
-
context
|
|
782
|
-
});
|
|
783
|
-
const result = await job.result;
|
|
784
|
-
return await result.result;
|
|
785
|
-
}
|
|
786
|
-
async function onMessage2(parseOnMainThread, job, type, payload) {
|
|
787
|
-
switch (type) {
|
|
788
|
-
case "done":
|
|
789
|
-
job.done(payload);
|
|
790
|
-
break;
|
|
791
|
-
case "error":
|
|
792
|
-
job.error(new Error(payload.error));
|
|
793
|
-
break;
|
|
794
|
-
case "process":
|
|
795
|
-
const { id, input, options } = payload;
|
|
796
|
-
try {
|
|
797
|
-
const result = await parseOnMainThread(input, options);
|
|
798
|
-
job.postMessage("done", { id, result });
|
|
799
|
-
} catch (error) {
|
|
800
|
-
const message = error instanceof Error ? error.message : "unknown error";
|
|
801
|
-
job.postMessage("error", { id, error: message });
|
|
611
|
+
switch (typeof logLevel) {
|
|
612
|
+
case "string":
|
|
613
|
+
case "function":
|
|
614
|
+
if (message !== void 0) {
|
|
615
|
+
args.unshift(message);
|
|
802
616
|
}
|
|
617
|
+
opts.message = logLevel;
|
|
618
|
+
break;
|
|
619
|
+
case "object":
|
|
620
|
+
Object.assign(opts, logLevel);
|
|
803
621
|
break;
|
|
804
622
|
default:
|
|
805
|
-
console.warn(`parse-with-worker unknown message ${type}`);
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
// ../loader-utils/src/lib/worker-loader-utils/encode-with-worker.ts
|
|
810
|
-
function canEncodeWithWorker(writer, options) {
|
|
811
|
-
if (!WorkerFarm.isSupported()) {
|
|
812
|
-
return false;
|
|
813
623
|
}
|
|
814
|
-
if (
|
|
815
|
-
|
|
624
|
+
if (typeof opts.message === "function") {
|
|
625
|
+
opts.message = opts.message();
|
|
816
626
|
}
|
|
817
|
-
|
|
627
|
+
const messageType = typeof opts.message;
|
|
628
|
+
assert2(messageType === "string" || messageType === "object");
|
|
629
|
+
return Object.assign(opts, {
|
|
630
|
+
args
|
|
631
|
+
}, opts.opts);
|
|
818
632
|
}
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
return false;
|
|
633
|
+
function decorateMessage(id, message, opts) {
|
|
634
|
+
if (typeof message === "string") {
|
|
635
|
+
const time = opts.time ? leftPad(formatTime(opts.total)) : "";
|
|
636
|
+
message = opts.time ? "".concat(id, ": ").concat(time, " ").concat(message) : "".concat(id, ": ").concat(message);
|
|
637
|
+
message = addColor(message, opts.color, opts.background);
|
|
825
638
|
}
|
|
826
|
-
|
|
827
|
-
const array2 = new Uint8Array(arrayBuffer2);
|
|
828
|
-
for (let i = 0; i < array1.length; ++i) {
|
|
829
|
-
if (array1[i] !== array2[i]) {
|
|
830
|
-
return false;
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
return true;
|
|
639
|
+
return message;
|
|
834
640
|
}
|
|
835
|
-
function
|
|
836
|
-
|
|
641
|
+
function logImageInNode(_ref2) {
|
|
642
|
+
let {
|
|
643
|
+
image,
|
|
644
|
+
message = "",
|
|
645
|
+
scale = 1
|
|
646
|
+
} = _ref2;
|
|
647
|
+
console.warn("removed");
|
|
648
|
+
return noop;
|
|
837
649
|
}
|
|
838
|
-
function
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
650
|
+
function logImageInBrowser(_ref3) {
|
|
651
|
+
let {
|
|
652
|
+
image,
|
|
653
|
+
message = "",
|
|
654
|
+
scale = 1
|
|
655
|
+
} = _ref3;
|
|
656
|
+
if (typeof image === "string") {
|
|
657
|
+
const img = new Image();
|
|
658
|
+
img.onload = () => {
|
|
659
|
+
const args = formatImage(img, message, scale);
|
|
660
|
+
console.log(...args);
|
|
661
|
+
};
|
|
662
|
+
img.src = image;
|
|
663
|
+
return noop;
|
|
848
664
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
|
|
854
|
-
const textDecoder = new TextDecoder(void 0, options);
|
|
855
|
-
for await (const arrayBuffer of arrayBufferIterator) {
|
|
856
|
-
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, { stream: true });
|
|
665
|
+
const element = image.nodeName || "";
|
|
666
|
+
if (element.toLowerCase() === "img") {
|
|
667
|
+
console.log(...formatImage(image, message, scale));
|
|
668
|
+
return noop;
|
|
857
669
|
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
670
|
+
if (element.toLowerCase() === "canvas") {
|
|
671
|
+
const img = new Image();
|
|
672
|
+
img.onload = () => console.log(...formatImage(img, message, scale));
|
|
673
|
+
img.src = image.toDataURL();
|
|
674
|
+
return noop;
|
|
863
675
|
}
|
|
676
|
+
return noop;
|
|
864
677
|
}
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
let eolIndex;
|
|
870
|
-
while ((eolIndex = previous.indexOf("\n")) >= 0) {
|
|
871
|
-
const line = previous.slice(0, eolIndex + 1);
|
|
872
|
-
previous = previous.slice(eolIndex + 1);
|
|
873
|
-
yield line;
|
|
678
|
+
function getTableHeader(table) {
|
|
679
|
+
for (const key in table) {
|
|
680
|
+
for (const title in table[key]) {
|
|
681
|
+
return title || "untitled";
|
|
874
682
|
}
|
|
875
683
|
}
|
|
876
|
-
|
|
877
|
-
yield previous;
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
async function* makeNumberedLineIterator(lineIterator) {
|
|
881
|
-
let counter = 1;
|
|
882
|
-
for await (const line of lineIterator) {
|
|
883
|
-
yield { counter, line };
|
|
884
|
-
counter++;
|
|
885
|
-
}
|
|
684
|
+
return "empty";
|
|
886
685
|
}
|
|
887
686
|
|
|
888
|
-
//
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
if (done) {
|
|
893
|
-
iterator.return();
|
|
894
|
-
return;
|
|
895
|
-
}
|
|
896
|
-
const cancel = visitor(value);
|
|
897
|
-
if (cancel) {
|
|
898
|
-
return;
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
async function concatenateArrayBuffersAsync(asyncIterator) {
|
|
903
|
-
const arrayBuffers = [];
|
|
904
|
-
for await (const chunk of asyncIterator) {
|
|
905
|
-
arrayBuffers.push(chunk);
|
|
906
|
-
}
|
|
907
|
-
return concatenateArrayBuffers(...arrayBuffers);
|
|
908
|
-
}
|
|
687
|
+
// ../../node_modules/@probe.gl/log/dist/index.js
|
|
688
|
+
var dist_default = new Log({
|
|
689
|
+
id: "@probe.gl/log"
|
|
690
|
+
});
|
|
909
691
|
|
|
910
|
-
//
|
|
911
|
-
function
|
|
912
|
-
|
|
913
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
|
|
914
|
-
return typeof obj2;
|
|
915
|
-
} : function(obj2) {
|
|
916
|
-
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
917
|
-
}, _typeof(obj);
|
|
692
|
+
// ../loader-utils/src/lib/option-utils/merge-loader-options.ts
|
|
693
|
+
function mergeLoaderOptions(baseOptions, newOptions) {
|
|
694
|
+
return mergeOptionsRecursively(baseOptions || {}, newOptions);
|
|
918
695
|
}
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
if (_typeof(input) !== "object" || input === null)
|
|
923
|
-
return input;
|
|
924
|
-
var prim = input[Symbol.toPrimitive];
|
|
925
|
-
if (prim !== void 0) {
|
|
926
|
-
var res = prim.call(input, hint || "default");
|
|
927
|
-
if (_typeof(res) !== "object")
|
|
928
|
-
return res;
|
|
929
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
696
|
+
function mergeOptionsRecursively(baseOptions, newOptions, level = 0) {
|
|
697
|
+
if (level > 3) {
|
|
698
|
+
return newOptions;
|
|
930
699
|
}
|
|
931
|
-
|
|
700
|
+
const options = { ...baseOptions };
|
|
701
|
+
for (const [key, newValue] of Object.entries(newOptions)) {
|
|
702
|
+
if (newValue && typeof newValue === "object" && !Array.isArray(newValue)) {
|
|
703
|
+
options[key] = mergeOptionsRecursively(
|
|
704
|
+
options[key] || {},
|
|
705
|
+
newOptions[key],
|
|
706
|
+
level + 1
|
|
707
|
+
);
|
|
708
|
+
} else {
|
|
709
|
+
options[key] = newOptions[key];
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
return options;
|
|
932
713
|
}
|
|
933
714
|
|
|
934
|
-
//
|
|
935
|
-
function
|
|
936
|
-
|
|
937
|
-
|
|
715
|
+
// ../loader-utils/src/lib/module-utils/js-module-utils.ts
|
|
716
|
+
function registerJSModules(modules) {
|
|
717
|
+
globalThis.loaders ||= {};
|
|
718
|
+
globalThis.loaders.modules ||= {};
|
|
719
|
+
Object.assign(globalThis.loaders.modules, modules);
|
|
938
720
|
}
|
|
939
721
|
|
|
940
|
-
//
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
if (
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
722
|
+
// ../worker-utils/src/lib/env-utils/version.ts
|
|
723
|
+
var NPM_TAG = "latest";
|
|
724
|
+
function getVersion() {
|
|
725
|
+
if (!globalThis._loadersgl_?.version) {
|
|
726
|
+
globalThis._loadersgl_ = globalThis._loadersgl_ || {};
|
|
727
|
+
if (typeof __VERSION__ === "undefined") {
|
|
728
|
+
console.warn(
|
|
729
|
+
"loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN."
|
|
730
|
+
);
|
|
731
|
+
globalThis._loadersgl_.version = NPM_TAG;
|
|
732
|
+
} else {
|
|
733
|
+
globalThis._loadersgl_.version = __VERSION__;
|
|
734
|
+
}
|
|
952
735
|
}
|
|
953
|
-
return
|
|
736
|
+
return globalThis._loadersgl_.version;
|
|
954
737
|
}
|
|
738
|
+
var VERSION2 = getVersion();
|
|
955
739
|
|
|
956
|
-
//
|
|
957
|
-
function
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
timestamp = window.performance.now();
|
|
961
|
-
} else if (typeof process !== "undefined" && process.hrtime) {
|
|
962
|
-
const timeParts = process.hrtime();
|
|
963
|
-
timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
|
|
964
|
-
} else {
|
|
965
|
-
timestamp = Date.now();
|
|
740
|
+
// ../worker-utils/src/lib/env-utils/assert.ts
|
|
741
|
+
function assert3(condition, message) {
|
|
742
|
+
if (!condition) {
|
|
743
|
+
throw new Error(message || "loaders.gl assertion failed.");
|
|
966
744
|
}
|
|
967
|
-
return timestamp;
|
|
968
745
|
}
|
|
969
746
|
|
|
970
|
-
//
|
|
971
|
-
var
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
747
|
+
// ../worker-utils/src/lib/env-utils/globals.ts
|
|
748
|
+
var globals2 = {
|
|
749
|
+
self: typeof self !== "undefined" && self,
|
|
750
|
+
window: typeof window !== "undefined" && window,
|
|
751
|
+
global: typeof global !== "undefined" && global,
|
|
752
|
+
document: typeof document !== "undefined" && document
|
|
753
|
+
};
|
|
754
|
+
var self_3 = globals2.self || globals2.window || globals2.global || {};
|
|
755
|
+
var window_3 = globals2.window || globals2.self || globals2.global || {};
|
|
756
|
+
var global_3 = globals2.global || globals2.self || globals2.window || {};
|
|
757
|
+
var document_3 = globals2.document || {};
|
|
758
|
+
var isBrowser4 = (
|
|
759
|
+
// @ts-ignore process.browser
|
|
760
|
+
typeof process !== "object" || String(process) !== "[object process]" || process.browser
|
|
761
|
+
);
|
|
762
|
+
var isMobile = typeof window !== "undefined" && typeof window.orientation !== "undefined";
|
|
763
|
+
var matches2 = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
764
|
+
var nodeVersion2 = matches2 && parseFloat(matches2[1]) || 0;
|
|
765
|
+
|
|
766
|
+
// ../worker-utils/src/lib/worker-farm/worker-job.ts
|
|
767
|
+
var WorkerJob = class {
|
|
768
|
+
name;
|
|
769
|
+
workerThread;
|
|
770
|
+
isRunning = true;
|
|
771
|
+
/** Promise that resolves when Job is done */
|
|
772
|
+
result;
|
|
773
|
+
_resolve = () => {
|
|
774
|
+
};
|
|
775
|
+
_reject = () => {
|
|
776
|
+
};
|
|
777
|
+
constructor(jobName, workerThread) {
|
|
778
|
+
this.name = jobName;
|
|
779
|
+
this.workerThread = workerThread;
|
|
780
|
+
this.result = new Promise((resolve2, reject) => {
|
|
781
|
+
this._resolve = resolve2;
|
|
782
|
+
this._reject = reject;
|
|
783
|
+
});
|
|
990
784
|
}
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
this.
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
this._timerPending = false;
|
|
1003
|
-
return this;
|
|
1004
|
-
}
|
|
1005
|
-
setSampleSize(samples) {
|
|
1006
|
-
this.sampleSize = samples;
|
|
1007
|
-
return this;
|
|
1008
|
-
}
|
|
1009
|
-
incrementCount() {
|
|
1010
|
-
this.addCount(1);
|
|
1011
|
-
return this;
|
|
785
|
+
/**
|
|
786
|
+
* Send a message to the job's worker thread
|
|
787
|
+
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
788
|
+
*/
|
|
789
|
+
postMessage(type, payload) {
|
|
790
|
+
this.workerThread.postMessage({
|
|
791
|
+
source: "loaders.gl",
|
|
792
|
+
// Lets worker ignore unrelated messages
|
|
793
|
+
type,
|
|
794
|
+
payload
|
|
795
|
+
});
|
|
1012
796
|
}
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
797
|
+
/**
|
|
798
|
+
* Call to resolve the `result` Promise with the supplied value
|
|
799
|
+
*/
|
|
800
|
+
done(value) {
|
|
801
|
+
assert3(this.isRunning);
|
|
802
|
+
this.isRunning = false;
|
|
803
|
+
this._resolve(value);
|
|
1016
804
|
}
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
805
|
+
/**
|
|
806
|
+
* Call to reject the `result` Promise with the supplied error
|
|
807
|
+
*/
|
|
808
|
+
error(error) {
|
|
809
|
+
assert3(this.isRunning);
|
|
810
|
+
this.isRunning = false;
|
|
811
|
+
this._reject(error);
|
|
1022
812
|
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
813
|
+
};
|
|
814
|
+
|
|
815
|
+
// ../worker-utils/src/lib/node/worker_threads-browser.ts
|
|
816
|
+
var NodeWorker = class {
|
|
817
|
+
terminate() {
|
|
1028
818
|
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
// ../worker-utils/src/lib/worker-utils/get-loadable-worker-url.ts
|
|
822
|
+
var workerURLCache = /* @__PURE__ */ new Map();
|
|
823
|
+
function getLoadableWorkerURL(props) {
|
|
824
|
+
assert3(props.source && !props.url || !props.source && props.url);
|
|
825
|
+
let workerURL = workerURLCache.get(props.source || props.url);
|
|
826
|
+
if (!workerURL) {
|
|
827
|
+
if (props.url) {
|
|
828
|
+
workerURL = getLoadableWorkerURLFromURL(props.url);
|
|
829
|
+
workerURLCache.set(props.url, workerURL);
|
|
830
|
+
}
|
|
831
|
+
if (props.source) {
|
|
832
|
+
workerURL = getLoadableWorkerURLFromSource(props.source);
|
|
833
|
+
workerURLCache.set(props.source, workerURL);
|
|
834
|
+
}
|
|
1035
835
|
}
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
836
|
+
assert3(workerURL);
|
|
837
|
+
return workerURL;
|
|
838
|
+
}
|
|
839
|
+
function getLoadableWorkerURLFromURL(url) {
|
|
840
|
+
if (!url.startsWith("http")) {
|
|
841
|
+
return url;
|
|
1040
842
|
}
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
843
|
+
const workerSource = buildScriptSource(url);
|
|
844
|
+
return getLoadableWorkerURLFromSource(workerSource);
|
|
845
|
+
}
|
|
846
|
+
function getLoadableWorkerURLFromSource(workerSource) {
|
|
847
|
+
const blob = new Blob([workerSource], { type: "application/javascript" });
|
|
848
|
+
return URL.createObjectURL(blob);
|
|
849
|
+
}
|
|
850
|
+
function buildScriptSource(workerUrl) {
|
|
851
|
+
return `try {
|
|
852
|
+
importScripts('${workerUrl}');
|
|
853
|
+
} catch (error) {
|
|
854
|
+
console.error(error);
|
|
855
|
+
throw error;
|
|
856
|
+
}`;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
|
|
860
|
+
function getTransferList(object, recursive = true, transfers) {
|
|
861
|
+
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
862
|
+
if (!object) {
|
|
863
|
+
} else if (isTransferable(object)) {
|
|
864
|
+
transfersSet.add(object);
|
|
865
|
+
} else if (isTransferable(object.buffer)) {
|
|
866
|
+
transfersSet.add(object.buffer);
|
|
867
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
868
|
+
} else if (recursive && typeof object === "object") {
|
|
869
|
+
for (const key in object) {
|
|
870
|
+
getTransferList(object[key], recursive, transfersSet);
|
|
1044
871
|
}
|
|
1045
|
-
this.addTime(getHiResTimestamp() - this._startTime);
|
|
1046
|
-
this._timerPending = false;
|
|
1047
|
-
this._checkSampling();
|
|
1048
|
-
return this;
|
|
1049
872
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
873
|
+
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
874
|
+
}
|
|
875
|
+
function isTransferable(object) {
|
|
876
|
+
if (!object) {
|
|
877
|
+
return false;
|
|
1052
878
|
}
|
|
1053
|
-
|
|
1054
|
-
return
|
|
879
|
+
if (object instanceof ArrayBuffer) {
|
|
880
|
+
return true;
|
|
1055
881
|
}
|
|
1056
|
-
|
|
1057
|
-
return
|
|
882
|
+
if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
|
|
883
|
+
return true;
|
|
1058
884
|
}
|
|
1059
|
-
|
|
1060
|
-
return
|
|
885
|
+
if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
|
|
886
|
+
return true;
|
|
1061
887
|
}
|
|
1062
|
-
|
|
1063
|
-
return
|
|
888
|
+
if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
|
|
889
|
+
return true;
|
|
1064
890
|
}
|
|
1065
|
-
|
|
1066
|
-
|
|
891
|
+
return false;
|
|
892
|
+
}
|
|
893
|
+
function getTransferListForWriter(object) {
|
|
894
|
+
if (object === null) {
|
|
895
|
+
return {};
|
|
1067
896
|
}
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
this._count = 0;
|
|
1077
|
-
this._samples = 0;
|
|
897
|
+
const clone = Object.assign({}, object);
|
|
898
|
+
Object.keys(clone).forEach((key) => {
|
|
899
|
+
if (typeof object[key] === "object" && !ArrayBuffer.isView(object[key]) && !(object[key] instanceof Array)) {
|
|
900
|
+
clone[key] = getTransferListForWriter(object[key]);
|
|
901
|
+
} else if (typeof clone[key] === "function" || clone[key] instanceof RegExp) {
|
|
902
|
+
clone[key] = {};
|
|
903
|
+
} else {
|
|
904
|
+
clone[key] = object[key];
|
|
1078
905
|
}
|
|
1079
|
-
}
|
|
1080
|
-
|
|
906
|
+
});
|
|
907
|
+
return clone;
|
|
908
|
+
}
|
|
1081
909
|
|
|
1082
|
-
//
|
|
1083
|
-
var
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
910
|
+
// ../worker-utils/src/lib/worker-farm/worker-thread.ts
|
|
911
|
+
var NOOP = () => {
|
|
912
|
+
};
|
|
913
|
+
var WorkerThread = class {
|
|
914
|
+
name;
|
|
915
|
+
source;
|
|
916
|
+
url;
|
|
917
|
+
terminated = false;
|
|
918
|
+
worker;
|
|
919
|
+
onMessage;
|
|
920
|
+
onError;
|
|
921
|
+
_loadableURL = "";
|
|
922
|
+
/** Checks if workers are supported on this platform */
|
|
923
|
+
static isSupported() {
|
|
924
|
+
return typeof Worker !== "undefined" && isBrowser4 || typeof NodeWorker !== "undefined" && !isBrowser4;
|
|
1091
925
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
926
|
+
constructor(props) {
|
|
927
|
+
const { name, source, url } = props;
|
|
928
|
+
assert3(source || url);
|
|
929
|
+
this.name = name;
|
|
930
|
+
this.source = source;
|
|
931
|
+
this.url = url;
|
|
932
|
+
this.onMessage = NOOP;
|
|
933
|
+
this.onError = (error) => console.log(error);
|
|
934
|
+
this.worker = isBrowser4 ? this._createBrowserWorker() : this._createNodeWorker();
|
|
1098
935
|
}
|
|
1099
|
-
|
|
1100
|
-
|
|
936
|
+
/**
|
|
937
|
+
* Terminate this worker thread
|
|
938
|
+
* @note Can free up significant memory
|
|
939
|
+
*/
|
|
940
|
+
destroy() {
|
|
941
|
+
this.onMessage = NOOP;
|
|
942
|
+
this.onError = NOOP;
|
|
943
|
+
this.worker.terminate();
|
|
944
|
+
this.terminated = true;
|
|
1101
945
|
}
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
stat.reset();
|
|
1105
|
-
}
|
|
1106
|
-
return this;
|
|
946
|
+
get isRunning() {
|
|
947
|
+
return Boolean(this.onMessage);
|
|
1107
948
|
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
949
|
+
/**
|
|
950
|
+
* Send a message to this worker thread
|
|
951
|
+
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
952
|
+
* @param transferList If not supplied, calculated automatically by traversing data
|
|
953
|
+
*/
|
|
954
|
+
postMessage(data, transferList) {
|
|
955
|
+
transferList = transferList || getTransferList(data);
|
|
956
|
+
this.worker.postMessage(data, transferList);
|
|
957
|
+
}
|
|
958
|
+
// PRIVATE
|
|
959
|
+
/**
|
|
960
|
+
* Generate a standard Error from an ErrorEvent
|
|
961
|
+
* @param event
|
|
962
|
+
*/
|
|
963
|
+
_getErrorFromErrorEvent(event) {
|
|
964
|
+
let message = "Failed to load ";
|
|
965
|
+
message += `worker ${this.name} from ${this.url}. `;
|
|
966
|
+
if (event.message) {
|
|
967
|
+
message += `${event.message} in `;
|
|
968
|
+
}
|
|
969
|
+
if (event.lineno) {
|
|
970
|
+
message += `:${event.lineno}:${event.colno}`;
|
|
1111
971
|
}
|
|
972
|
+
return new Error(message);
|
|
1112
973
|
}
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
});
|
|
1123
|
-
return table;
|
|
1124
|
-
}
|
|
1125
|
-
_initializeStats() {
|
|
1126
|
-
let stats = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
|
1127
|
-
stats.forEach((stat) => this._getOrCreate(stat));
|
|
1128
|
-
}
|
|
1129
|
-
_getOrCreate(stat) {
|
|
1130
|
-
const {
|
|
1131
|
-
name,
|
|
1132
|
-
type
|
|
1133
|
-
} = stat;
|
|
1134
|
-
let result = this.stats[name];
|
|
1135
|
-
if (!result) {
|
|
1136
|
-
if (stat instanceof Stat) {
|
|
1137
|
-
result = stat;
|
|
974
|
+
/**
|
|
975
|
+
* Creates a worker thread on the browser
|
|
976
|
+
*/
|
|
977
|
+
_createBrowserWorker() {
|
|
978
|
+
this._loadableURL = getLoadableWorkerURL({ source: this.source, url: this.url });
|
|
979
|
+
const worker = new Worker(this._loadableURL, { name: this.name });
|
|
980
|
+
worker.onmessage = (event) => {
|
|
981
|
+
if (!event.data) {
|
|
982
|
+
this.onError(new Error("No data received"));
|
|
1138
983
|
} else {
|
|
1139
|
-
|
|
984
|
+
this.onMessage(event.data);
|
|
1140
985
|
}
|
|
1141
|
-
|
|
986
|
+
};
|
|
987
|
+
worker.onerror = (error) => {
|
|
988
|
+
this.onError(this._getErrorFromErrorEvent(error));
|
|
989
|
+
this.terminated = true;
|
|
990
|
+
};
|
|
991
|
+
worker.onmessageerror = (event) => console.error(event);
|
|
992
|
+
return worker;
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* Creates a worker thread in node.js
|
|
996
|
+
* @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool
|
|
997
|
+
*/
|
|
998
|
+
_createNodeWorker() {
|
|
999
|
+
let worker;
|
|
1000
|
+
if (this.url) {
|
|
1001
|
+
const absolute = this.url.includes(":/") || this.url.startsWith("/");
|
|
1002
|
+
const url = absolute ? this.url : `./${this.url}`;
|
|
1003
|
+
worker = new NodeWorker(url, { eval: false });
|
|
1004
|
+
} else if (this.source) {
|
|
1005
|
+
worker = new NodeWorker(this.source, { eval: true });
|
|
1006
|
+
} else {
|
|
1007
|
+
throw new Error("no worker");
|
|
1142
1008
|
}
|
|
1143
|
-
|
|
1009
|
+
worker.on("message", (data) => {
|
|
1010
|
+
this.onMessage(data);
|
|
1011
|
+
});
|
|
1012
|
+
worker.on("error", (error) => {
|
|
1013
|
+
this.onError(error);
|
|
1014
|
+
});
|
|
1015
|
+
worker.on("exit", (code) => {
|
|
1016
|
+
});
|
|
1017
|
+
return worker;
|
|
1144
1018
|
}
|
|
1145
1019
|
};
|
|
1146
1020
|
|
|
1147
|
-
// ../
|
|
1148
|
-
var
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1021
|
+
// ../worker-utils/src/lib/worker-farm/worker-pool.ts
|
|
1022
|
+
var WorkerPool = class {
|
|
1023
|
+
name = "unnamed";
|
|
1024
|
+
source;
|
|
1025
|
+
// | Function;
|
|
1026
|
+
url;
|
|
1027
|
+
maxConcurrency = 1;
|
|
1028
|
+
maxMobileConcurrency = 1;
|
|
1029
|
+
onDebug = () => {
|
|
1030
|
+
};
|
|
1031
|
+
reuseWorkers = true;
|
|
1032
|
+
props = {};
|
|
1033
|
+
jobQueue = [];
|
|
1034
|
+
idleQueue = [];
|
|
1035
|
+
count = 0;
|
|
1036
|
+
isDestroyed = false;
|
|
1037
|
+
/** Checks if workers are supported on this platform */
|
|
1038
|
+
static isSupported() {
|
|
1039
|
+
return WorkerThread.isSupported();
|
|
1040
|
+
}
|
|
1159
1041
|
/**
|
|
1160
|
-
*
|
|
1161
|
-
*
|
|
1042
|
+
* @param processor - worker function
|
|
1043
|
+
* @param maxConcurrency - max count of workers
|
|
1162
1044
|
*/
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
stats;
|
|
1168
|
-
activeRequestCount = 0;
|
|
1169
|
-
/** Tracks the number of active requests and prioritizes/cancels queued requests. */
|
|
1170
|
-
requestQueue = [];
|
|
1171
|
-
requestMap = /* @__PURE__ */ new Map();
|
|
1172
|
-
updateTimer = null;
|
|
1173
|
-
constructor(props = {}) {
|
|
1174
|
-
this.props = { ...DEFAULT_PROPS2, ...props };
|
|
1175
|
-
this.stats = new Stats({ id: this.props.id });
|
|
1176
|
-
this.stats.get(STAT_QUEUED_REQUESTS);
|
|
1177
|
-
this.stats.get(STAT_ACTIVE_REQUESTS);
|
|
1178
|
-
this.stats.get(STAT_CANCELLED_REQUESTS);
|
|
1179
|
-
this.stats.get(STAT_QUEUED_REQUESTS_EVER);
|
|
1180
|
-
this.stats.get(STAT_ACTIVE_REQUESTS_EVER);
|
|
1045
|
+
constructor(props) {
|
|
1046
|
+
this.source = props.source;
|
|
1047
|
+
this.url = props.url;
|
|
1048
|
+
this.setProps(props);
|
|
1181
1049
|
}
|
|
1182
1050
|
/**
|
|
1183
|
-
*
|
|
1184
|
-
*
|
|
1185
|
-
* When the returned promise resolved, it is OK for the application to issue a request.
|
|
1186
|
-
* The promise resolves to an object that contains a `done` method.
|
|
1187
|
-
* When the application's request has completed (or failed), the application must call the `done` function
|
|
1188
|
-
*
|
|
1189
|
-
* @param handle
|
|
1190
|
-
* @param getPriority will be called when request "slots" open up,
|
|
1191
|
-
* allowing the caller to update priority or cancel the request
|
|
1192
|
-
* Highest priority executes first, priority < 0 cancels the request
|
|
1193
|
-
* @returns a promise
|
|
1194
|
-
* - resolves to a object (with a `done` field) when the request can be issued without queueing,
|
|
1195
|
-
* - resolves to `null` if the request has been cancelled (by the callback return < 0).
|
|
1196
|
-
* In this case the application should not issue the request
|
|
1051
|
+
* Terminates all workers in the pool
|
|
1052
|
+
* @note Can free up significant memory
|
|
1197
1053
|
*/
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1054
|
+
destroy() {
|
|
1055
|
+
this.idleQueue.forEach((worker) => worker.destroy());
|
|
1056
|
+
this.isDestroyed = true;
|
|
1057
|
+
}
|
|
1058
|
+
setProps(props) {
|
|
1059
|
+
this.props = { ...this.props, ...props };
|
|
1060
|
+
if (props.name !== void 0) {
|
|
1061
|
+
this.name = props.name;
|
|
1202
1062
|
}
|
|
1203
|
-
if (
|
|
1204
|
-
|
|
1063
|
+
if (props.maxConcurrency !== void 0) {
|
|
1064
|
+
this.maxConcurrency = props.maxConcurrency;
|
|
1205
1065
|
}
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1066
|
+
if (props.maxMobileConcurrency !== void 0) {
|
|
1067
|
+
this.maxMobileConcurrency = props.maxMobileConcurrency;
|
|
1068
|
+
}
|
|
1069
|
+
if (props.reuseWorkers !== void 0) {
|
|
1070
|
+
this.reuseWorkers = props.reuseWorkers;
|
|
1071
|
+
}
|
|
1072
|
+
if (props.onDebug !== void 0) {
|
|
1073
|
+
this.onDebug = props.onDebug;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
async startJob(name, onMessage3 = (job, type, data) => job.done(data), onError = (job, error) => job.error(error)) {
|
|
1077
|
+
const startPromise = new Promise((onStart) => {
|
|
1078
|
+
this.jobQueue.push({ name, onMessage: onMessage3, onError, onStart });
|
|
1079
|
+
return this;
|
|
1210
1080
|
});
|
|
1211
|
-
this.
|
|
1212
|
-
|
|
1213
|
-
this._issueNewRequests();
|
|
1214
|
-
return promise;
|
|
1081
|
+
this._startQueuedJob();
|
|
1082
|
+
return await startPromise;
|
|
1215
1083
|
}
|
|
1216
1084
|
// PRIVATE
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
this.requestMap.delete(handle);
|
|
1224
|
-
this.activeRequestCount--;
|
|
1225
|
-
this._issueNewRequests();
|
|
1226
|
-
}
|
|
1227
|
-
};
|
|
1228
|
-
this.activeRequestCount++;
|
|
1229
|
-
return resolve2 ? resolve2({ done }) : Promise.resolve({ done });
|
|
1230
|
-
}
|
|
1231
|
-
/** We check requests asynchronously, to prevent multiple updates */
|
|
1232
|
-
_issueNewRequests() {
|
|
1233
|
-
if (this.updateTimer !== null) {
|
|
1234
|
-
clearTimeout(this.updateTimer);
|
|
1235
|
-
}
|
|
1236
|
-
this.updateTimer = setTimeout(() => this._issueNewRequestsAsync(), this.props.debounceTime);
|
|
1237
|
-
}
|
|
1238
|
-
/** Refresh all requests */
|
|
1239
|
-
_issueNewRequestsAsync() {
|
|
1240
|
-
if (this.updateTimer !== null) {
|
|
1241
|
-
clearTimeout(this.updateTimer);
|
|
1242
|
-
}
|
|
1243
|
-
this.updateTimer = null;
|
|
1244
|
-
const freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);
|
|
1245
|
-
if (freeSlots === 0) {
|
|
1085
|
+
/**
|
|
1086
|
+
* Starts first queued job if worker is available or can be created
|
|
1087
|
+
* Called when job is started and whenever a worker returns to the idleQueue
|
|
1088
|
+
*/
|
|
1089
|
+
async _startQueuedJob() {
|
|
1090
|
+
if (!this.jobQueue.length) {
|
|
1246
1091
|
return;
|
|
1247
1092
|
}
|
|
1248
|
-
this.
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
if (request) {
|
|
1252
|
-
this._issueRequest(request);
|
|
1253
|
-
}
|
|
1093
|
+
const workerThread = this._getAvailableWorker();
|
|
1094
|
+
if (!workerThread) {
|
|
1095
|
+
return;
|
|
1254
1096
|
}
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1097
|
+
const queuedJob = this.jobQueue.shift();
|
|
1098
|
+
if (queuedJob) {
|
|
1099
|
+
this.onDebug({
|
|
1100
|
+
message: "Starting job",
|
|
1101
|
+
name: queuedJob.name,
|
|
1102
|
+
workerThread,
|
|
1103
|
+
backlog: this.jobQueue.length
|
|
1104
|
+
});
|
|
1105
|
+
const job = new WorkerJob(queuedJob.name, workerThread);
|
|
1106
|
+
workerThread.onMessage = (data) => queuedJob.onMessage(job, data.type, data.payload);
|
|
1107
|
+
workerThread.onError = (error) => queuedJob.onError(job, error);
|
|
1108
|
+
queuedJob.onStart(job);
|
|
1109
|
+
try {
|
|
1110
|
+
await job.result;
|
|
1111
|
+
} catch (error) {
|
|
1112
|
+
console.error(`Worker exception: ${error}`);
|
|
1113
|
+
} finally {
|
|
1114
|
+
this.returnWorkerToQueue(workerThread);
|
|
1265
1115
|
}
|
|
1266
1116
|
}
|
|
1267
|
-
requestQueue.sort((a, b) => a.priority - b.priority);
|
|
1268
1117
|
}
|
|
1269
|
-
/**
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1118
|
+
/**
|
|
1119
|
+
* Returns a worker to the idle queue
|
|
1120
|
+
* Destroys the worker if
|
|
1121
|
+
* - pool is destroyed
|
|
1122
|
+
* - if this pool doesn't reuse workers
|
|
1123
|
+
* - if maxConcurrency has been lowered
|
|
1124
|
+
* @param worker
|
|
1125
|
+
*/
|
|
1126
|
+
returnWorkerToQueue(worker) {
|
|
1127
|
+
const shouldDestroyWorker = (
|
|
1128
|
+
// Workers on Node.js prevent the process from exiting.
|
|
1129
|
+
// Until we figure out how to close them before exit, we always destroy them
|
|
1130
|
+
!isBrowser4 || // If the pool is destroyed, there is no reason to keep the worker around
|
|
1131
|
+
this.isDestroyed || // If the app has disabled worker reuse, any completed workers should be destroyed
|
|
1132
|
+
!this.reuseWorkers || // If concurrency has been lowered, this worker might be surplus to requirements
|
|
1133
|
+
this.count > this._getMaxConcurrency()
|
|
1134
|
+
);
|
|
1135
|
+
if (shouldDestroyWorker) {
|
|
1136
|
+
worker.destroy();
|
|
1137
|
+
this.count--;
|
|
1138
|
+
} else {
|
|
1139
|
+
this.idleQueue.push(worker);
|
|
1140
|
+
}
|
|
1141
|
+
if (!this.isDestroyed) {
|
|
1142
|
+
this._startQueuedJob();
|
|
1275
1143
|
}
|
|
1276
|
-
return true;
|
|
1277
1144
|
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
function resolvePath(filename2) {
|
|
1290
|
-
for (const alias in fileAliases) {
|
|
1291
|
-
if (filename2.startsWith(alias)) {
|
|
1292
|
-
const replacement = fileAliases[alias];
|
|
1293
|
-
filename2 = filename2.replace(alias, replacement);
|
|
1145
|
+
/**
|
|
1146
|
+
* Returns idle worker or creates new worker if maxConcurrency has not been reached
|
|
1147
|
+
*/
|
|
1148
|
+
_getAvailableWorker() {
|
|
1149
|
+
if (this.idleQueue.length > 0) {
|
|
1150
|
+
return this.idleQueue.shift() || null;
|
|
1151
|
+
}
|
|
1152
|
+
if (this.count < this._getMaxConcurrency()) {
|
|
1153
|
+
this.count++;
|
|
1154
|
+
const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;
|
|
1155
|
+
return new WorkerThread({ name, source: this.source, url: this.url });
|
|
1294
1156
|
}
|
|
1157
|
+
return null;
|
|
1295
1158
|
}
|
|
1296
|
-
|
|
1297
|
-
|
|
1159
|
+
_getMaxConcurrency() {
|
|
1160
|
+
return isMobile ? this.maxMobileConcurrency : this.maxConcurrency;
|
|
1298
1161
|
}
|
|
1299
|
-
return filename2;
|
|
1300
|
-
}
|
|
1301
|
-
|
|
1302
|
-
// ../loader-utils/src/json-loader.ts
|
|
1303
|
-
var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1304
|
-
var JSONLoader = {
|
|
1305
|
-
name: "JSON",
|
|
1306
|
-
id: "json",
|
|
1307
|
-
module: "json",
|
|
1308
|
-
version: VERSION2,
|
|
1309
|
-
extensions: ["json", "geojson"],
|
|
1310
|
-
mimeTypes: ["application/json"],
|
|
1311
|
-
category: "json",
|
|
1312
|
-
text: true,
|
|
1313
|
-
parseTextSync,
|
|
1314
|
-
parse: async (arrayBuffer) => parseTextSync(new TextDecoder().decode(arrayBuffer)),
|
|
1315
|
-
options: {}
|
|
1316
1162
|
};
|
|
1317
|
-
function parseTextSync(text) {
|
|
1318
|
-
return JSON.parse(text);
|
|
1319
|
-
}
|
|
1320
|
-
|
|
1321
|
-
// ../loader-utils/src/lib/node/buffer.browser.ts
|
|
1322
|
-
function toArrayBuffer(buffer) {
|
|
1323
|
-
return buffer;
|
|
1324
|
-
}
|
|
1325
1163
|
|
|
1326
|
-
// ../
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
return toArrayBuffer(data);
|
|
1164
|
+
// ../worker-utils/src/lib/worker-farm/worker-farm.ts
|
|
1165
|
+
var DEFAULT_PROPS = {
|
|
1166
|
+
maxConcurrency: 3,
|
|
1167
|
+
maxMobileConcurrency: 1,
|
|
1168
|
+
reuseWorkers: true,
|
|
1169
|
+
onDebug: () => {
|
|
1333
1170
|
}
|
|
1334
|
-
|
|
1335
|
-
|
|
1171
|
+
};
|
|
1172
|
+
var _WorkerFarm = class {
|
|
1173
|
+
props;
|
|
1174
|
+
workerPools = /* @__PURE__ */ new Map();
|
|
1175
|
+
/** Checks if workers are supported on this platform */
|
|
1176
|
+
static isSupported() {
|
|
1177
|
+
return WorkerThread.isSupported();
|
|
1336
1178
|
}
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1179
|
+
/** Get the singleton instance of the global worker farm */
|
|
1180
|
+
static getWorkerFarm(props = {}) {
|
|
1181
|
+
_WorkerFarm._workerFarm = _WorkerFarm._workerFarm || new _WorkerFarm({});
|
|
1182
|
+
_WorkerFarm._workerFarm.setProps(props);
|
|
1183
|
+
return _WorkerFarm._workerFarm;
|
|
1184
|
+
}
|
|
1185
|
+
/** get global instance with WorkerFarm.getWorkerFarm() */
|
|
1186
|
+
constructor(props) {
|
|
1187
|
+
this.props = { ...DEFAULT_PROPS };
|
|
1188
|
+
this.setProps(props);
|
|
1189
|
+
this.workerPools = /* @__PURE__ */ new Map();
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* Terminate all workers in the farm
|
|
1193
|
+
* @note Can free up significant memory
|
|
1194
|
+
*/
|
|
1195
|
+
destroy() {
|
|
1196
|
+
for (const workerPool of this.workerPools.values()) {
|
|
1197
|
+
workerPool.destroy();
|
|
1340
1198
|
}
|
|
1341
|
-
|
|
1199
|
+
this.workerPools = /* @__PURE__ */ new Map();
|
|
1342
1200
|
}
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1201
|
+
/**
|
|
1202
|
+
* Set props used when initializing worker pools
|
|
1203
|
+
* @param props
|
|
1204
|
+
*/
|
|
1205
|
+
setProps(props) {
|
|
1206
|
+
this.props = { ...this.props, ...props };
|
|
1207
|
+
for (const workerPool of this.workerPools.values()) {
|
|
1208
|
+
workerPool.setProps(this._getWorkerPoolProps());
|
|
1209
|
+
}
|
|
1347
1210
|
}
|
|
1348
|
-
|
|
1349
|
-
|
|
1211
|
+
/**
|
|
1212
|
+
* Returns a worker pool for the specified worker
|
|
1213
|
+
* @param options - only used first time for a specific worker name
|
|
1214
|
+
* @param options.name - the name of the worker - used to identify worker pool
|
|
1215
|
+
* @param options.url -
|
|
1216
|
+
* @param options.source -
|
|
1217
|
+
* @example
|
|
1218
|
+
* const job = WorkerFarm.getWorkerFarm().getWorkerPool({name, url}).startJob(...);
|
|
1219
|
+
*/
|
|
1220
|
+
getWorkerPool(options) {
|
|
1221
|
+
const { name, source, url } = options;
|
|
1222
|
+
let workerPool = this.workerPools.get(name);
|
|
1223
|
+
if (!workerPool) {
|
|
1224
|
+
workerPool = new WorkerPool({
|
|
1225
|
+
name,
|
|
1226
|
+
source,
|
|
1227
|
+
url
|
|
1228
|
+
});
|
|
1229
|
+
workerPool.setProps(this._getWorkerPoolProps());
|
|
1230
|
+
this.workerPools.set(name, workerPool);
|
|
1231
|
+
}
|
|
1232
|
+
return workerPool;
|
|
1350
1233
|
}
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
filename: () => filename,
|
|
1359
|
-
join: () => join,
|
|
1360
|
-
resolve: () => resolve
|
|
1361
|
-
});
|
|
1362
|
-
|
|
1363
|
-
// ../loader-utils/src/lib/path-utils/get-cwd.ts
|
|
1364
|
-
function getCWD() {
|
|
1365
|
-
if (typeof process !== "undefined" && typeof process.cwd !== "undefined") {
|
|
1366
|
-
return process.cwd();
|
|
1234
|
+
_getWorkerPoolProps() {
|
|
1235
|
+
return {
|
|
1236
|
+
maxConcurrency: this.props.maxConcurrency,
|
|
1237
|
+
maxMobileConcurrency: this.props.maxMobileConcurrency,
|
|
1238
|
+
reuseWorkers: this.props.reuseWorkers,
|
|
1239
|
+
onDebug: this.props.onDebug
|
|
1240
|
+
};
|
|
1367
1241
|
}
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1242
|
+
};
|
|
1243
|
+
var WorkerFarm = _WorkerFarm;
|
|
1244
|
+
// singleton
|
|
1245
|
+
__publicField(WorkerFarm, "_workerFarm");
|
|
1371
1246
|
|
|
1372
|
-
// ../
|
|
1373
|
-
function
|
|
1374
|
-
const
|
|
1375
|
-
return
|
|
1376
|
-
}
|
|
1377
|
-
function dirname(url) {
|
|
1378
|
-
const slashIndex = url ? url.lastIndexOf("/") : -1;
|
|
1379
|
-
return slashIndex >= 0 ? url.substr(0, slashIndex) : "";
|
|
1380
|
-
}
|
|
1381
|
-
function join(...parts) {
|
|
1382
|
-
const separator = "/";
|
|
1383
|
-
parts = parts.map((part, index) => {
|
|
1384
|
-
if (index) {
|
|
1385
|
-
part = part.replace(new RegExp(`^${separator}`), "");
|
|
1386
|
-
}
|
|
1387
|
-
if (index !== parts.length - 1) {
|
|
1388
|
-
part = part.replace(new RegExp(`${separator}$`), "");
|
|
1389
|
-
}
|
|
1390
|
-
return part;
|
|
1391
|
-
});
|
|
1392
|
-
return parts.join(separator);
|
|
1247
|
+
// ../worker-utils/src/lib/worker-api/get-worker-url.ts
|
|
1248
|
+
function getWorkerName(worker) {
|
|
1249
|
+
const warning = worker.version !== VERSION2 ? ` (worker-utils@${VERSION2})` : "";
|
|
1250
|
+
return `${worker.name}@${worker.version}${warning}`;
|
|
1393
1251
|
}
|
|
1394
|
-
function
|
|
1395
|
-
const
|
|
1396
|
-
|
|
1397
|
-
|
|
1252
|
+
function getWorkerURL(worker, options = {}) {
|
|
1253
|
+
const workerOptions = options[worker.id] || {};
|
|
1254
|
+
const workerFile = isBrowser4 ? `${worker.id}-worker.js` : `${worker.id}-worker-node.js`;
|
|
1255
|
+
let url = workerOptions.workerUrl;
|
|
1256
|
+
if (!url && worker.id === "compression") {
|
|
1257
|
+
url = options.workerUrl;
|
|
1398
1258
|
}
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
for (let i = paths.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
1403
|
-
let path;
|
|
1404
|
-
if (i >= 0) {
|
|
1405
|
-
path = paths[i];
|
|
1259
|
+
if (options._workerType === "test") {
|
|
1260
|
+
if (isBrowser4) {
|
|
1261
|
+
url = `modules/${worker.module}/dist/${workerFile}`;
|
|
1406
1262
|
} else {
|
|
1407
|
-
|
|
1408
|
-
cwd = getCWD();
|
|
1409
|
-
}
|
|
1410
|
-
path = cwd;
|
|
1263
|
+
url = `modules/${worker.module}/src/workers/${worker.id}-worker-node.ts`;
|
|
1411
1264
|
}
|
|
1412
|
-
|
|
1413
|
-
|
|
1265
|
+
}
|
|
1266
|
+
if (!url) {
|
|
1267
|
+
let version = worker.version;
|
|
1268
|
+
if (version === "latest") {
|
|
1269
|
+
version = NPM_TAG;
|
|
1414
1270
|
}
|
|
1415
|
-
|
|
1416
|
-
|
|
1271
|
+
const versionTag = version ? `@${version}` : "";
|
|
1272
|
+
url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;
|
|
1417
1273
|
}
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1274
|
+
assert3(url);
|
|
1275
|
+
return url;
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
// ../worker-utils/src/lib/worker-api/process-on-worker.ts
|
|
1279
|
+
async function processOnWorker(worker, data, options = {}, context = {}) {
|
|
1280
|
+
const name = getWorkerName(worker);
|
|
1281
|
+
const workerFarm = WorkerFarm.getWorkerFarm(options);
|
|
1282
|
+
const { source } = options;
|
|
1283
|
+
const workerPoolProps = { name, source };
|
|
1284
|
+
if (!source) {
|
|
1285
|
+
workerPoolProps.url = getWorkerURL(worker, options);
|
|
1423
1286
|
}
|
|
1424
|
-
|
|
1287
|
+
const workerPool = workerFarm.getWorkerPool(workerPoolProps);
|
|
1288
|
+
const jobName = options.jobName || worker.name;
|
|
1289
|
+
const job = await workerPool.startJob(
|
|
1290
|
+
jobName,
|
|
1291
|
+
// eslint-disable-next-line
|
|
1292
|
+
onMessage.bind(null, context)
|
|
1293
|
+
);
|
|
1294
|
+
const transferableOptions = getTransferListForWriter(options);
|
|
1295
|
+
job.postMessage("process", { input: data, options: transferableOptions });
|
|
1296
|
+
const result = await job.result;
|
|
1297
|
+
return result.result;
|
|
1425
1298
|
}
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
let lastSlash = -1;
|
|
1431
|
-
let dots = 0;
|
|
1432
|
-
let code;
|
|
1433
|
-
let isAboveRoot = false;
|
|
1434
|
-
for (let i = 0; i <= path.length; ++i) {
|
|
1435
|
-
if (i < path.length) {
|
|
1436
|
-
code = path.charCodeAt(i);
|
|
1437
|
-
} else if (code === SLASH) {
|
|
1299
|
+
async function onMessage(context, job, type, payload) {
|
|
1300
|
+
switch (type) {
|
|
1301
|
+
case "done":
|
|
1302
|
+
job.done(payload);
|
|
1438
1303
|
break;
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
if (
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
let j = start;
|
|
1449
|
-
for (; j >= 0; --j) {
|
|
1450
|
-
if (res.charCodeAt(j) === SLASH) {
|
|
1451
|
-
break;
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
if (j !== start) {
|
|
1455
|
-
res = j === -1 ? "" : res.slice(0, j);
|
|
1456
|
-
lastSlash = i;
|
|
1457
|
-
dots = 0;
|
|
1458
|
-
isAboveRoot = false;
|
|
1459
|
-
continue;
|
|
1460
|
-
}
|
|
1461
|
-
} else if (res.length === 2 || res.length === 1) {
|
|
1462
|
-
res = "";
|
|
1463
|
-
lastSlash = i;
|
|
1464
|
-
dots = 0;
|
|
1465
|
-
isAboveRoot = false;
|
|
1466
|
-
continue;
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
if (allowAboveRoot) {
|
|
1470
|
-
if (res.length > 0) {
|
|
1471
|
-
res += "/..";
|
|
1472
|
-
} else {
|
|
1473
|
-
res = "..";
|
|
1474
|
-
}
|
|
1475
|
-
isAboveRoot = true;
|
|
1476
|
-
}
|
|
1477
|
-
} else {
|
|
1478
|
-
const slice = path.slice(lastSlash + 1, i);
|
|
1479
|
-
if (res.length > 0) {
|
|
1480
|
-
res += `/${slice}`;
|
|
1481
|
-
} else {
|
|
1482
|
-
res = slice;
|
|
1304
|
+
case "error":
|
|
1305
|
+
job.error(new Error(payload.error));
|
|
1306
|
+
break;
|
|
1307
|
+
case "process":
|
|
1308
|
+
const { id, input, options } = payload;
|
|
1309
|
+
try {
|
|
1310
|
+
if (!context.process) {
|
|
1311
|
+
job.postMessage("error", { id, error: "Worker not set up to process on main thread" });
|
|
1312
|
+
return;
|
|
1483
1313
|
}
|
|
1484
|
-
|
|
1314
|
+
const result = await context.process(input, options);
|
|
1315
|
+
job.postMessage("done", { id, result });
|
|
1316
|
+
} catch (error) {
|
|
1317
|
+
const message = error instanceof Error ? error.message : "unknown error";
|
|
1318
|
+
job.postMessage("error", { id, error: message });
|
|
1485
1319
|
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
++dots;
|
|
1490
|
-
} else {
|
|
1491
|
-
dots = -1;
|
|
1492
|
-
}
|
|
1320
|
+
break;
|
|
1321
|
+
default:
|
|
1322
|
+
console.warn(`process-on-worker: unknown message ${type}`);
|
|
1493
1323
|
}
|
|
1494
|
-
return res;
|
|
1495
1324
|
}
|
|
1496
1325
|
|
|
1497
|
-
// ../
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
constructor(blob) {
|
|
1504
|
-
this.handle = blob instanceof ArrayBuffer ? new Blob([blob]) : blob;
|
|
1505
|
-
this.size = blob instanceof ArrayBuffer ? blob.byteLength : blob.size;
|
|
1506
|
-
this.bigsize = BigInt(this.size);
|
|
1507
|
-
this.url = blob instanceof File ? blob.name : "";
|
|
1326
|
+
// ../worker-utils/src/lib/worker-api/validate-worker-version.ts
|
|
1327
|
+
function validateWorkerVersion(worker, coreVersion = VERSION2) {
|
|
1328
|
+
assert3(worker, "no worker provided");
|
|
1329
|
+
const workerVersion = worker.version;
|
|
1330
|
+
if (!coreVersion || !workerVersion) {
|
|
1331
|
+
return false;
|
|
1508
1332
|
}
|
|
1509
|
-
|
|
1333
|
+
return true;
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
// ../loader-utils/src/lib/worker-loader-utils/parse-with-worker.ts
|
|
1337
|
+
function canParseWithWorker(loader, options) {
|
|
1338
|
+
if (!WorkerFarm.isSupported()) {
|
|
1339
|
+
return false;
|
|
1510
1340
|
}
|
|
1511
|
-
|
|
1512
|
-
return
|
|
1513
|
-
size: this.handle.size,
|
|
1514
|
-
bigsize: BigInt(this.handle.size),
|
|
1515
|
-
isDirectory: false
|
|
1516
|
-
};
|
|
1341
|
+
if (!isBrowser4 && !options?._nodeWorkers) {
|
|
1342
|
+
return false;
|
|
1517
1343
|
}
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1344
|
+
return loader.worker && options?.worker;
|
|
1345
|
+
}
|
|
1346
|
+
async function parseWithWorker(loader, data, options, context, parseOnMainThread) {
|
|
1347
|
+
const name = loader.id;
|
|
1348
|
+
const url = getWorkerURL(loader, options);
|
|
1349
|
+
const workerFarm = WorkerFarm.getWorkerFarm(options);
|
|
1350
|
+
const workerPool = workerFarm.getWorkerPool({ name, url });
|
|
1351
|
+
options = JSON.parse(JSON.stringify(options));
|
|
1352
|
+
context = JSON.parse(JSON.stringify(context || {}));
|
|
1353
|
+
const job = await workerPool.startJob(
|
|
1354
|
+
"process-on-worker",
|
|
1355
|
+
// @ts-expect-error
|
|
1356
|
+
onMessage2.bind(null, parseOnMainThread)
|
|
1357
|
+
// eslint-disable-line @typescript-eslint/no-misused-promises
|
|
1358
|
+
);
|
|
1359
|
+
job.postMessage("process", {
|
|
1360
|
+
// @ts-ignore
|
|
1361
|
+
input: data,
|
|
1362
|
+
options,
|
|
1363
|
+
context
|
|
1364
|
+
});
|
|
1365
|
+
const result = await job.result;
|
|
1366
|
+
return await result.result;
|
|
1367
|
+
}
|
|
1368
|
+
async function onMessage2(parseOnMainThread, job, type, payload) {
|
|
1369
|
+
switch (type) {
|
|
1370
|
+
case "done":
|
|
1371
|
+
job.done(payload);
|
|
1372
|
+
break;
|
|
1373
|
+
case "error":
|
|
1374
|
+
job.error(new Error(payload.error));
|
|
1375
|
+
break;
|
|
1376
|
+
case "process":
|
|
1377
|
+
const { id, input, options } = payload;
|
|
1378
|
+
try {
|
|
1379
|
+
const result = await parseOnMainThread(input, options);
|
|
1380
|
+
job.postMessage("done", { id, result });
|
|
1381
|
+
} catch (error) {
|
|
1382
|
+
const message = error instanceof Error ? error.message : "unknown error";
|
|
1383
|
+
job.postMessage("error", { id, error: message });
|
|
1384
|
+
}
|
|
1385
|
+
break;
|
|
1386
|
+
default:
|
|
1387
|
+
console.warn(`parse-with-worker unknown message ${type}`);
|
|
1521
1388
|
}
|
|
1522
|
-
}
|
|
1389
|
+
}
|
|
1523
1390
|
|
|
1524
|
-
// ../loader-utils/src/lib/
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
size = 0;
|
|
1529
|
-
bigsize = 0n;
|
|
1530
|
-
url = "";
|
|
1531
|
-
constructor(url, flags, mode) {
|
|
1532
|
-
if (globalThis.loaders?.NodeFile) {
|
|
1533
|
-
return new globalThis.loaders.NodeFile(url, flags, mode);
|
|
1534
|
-
}
|
|
1535
|
-
if (isBrowser) {
|
|
1536
|
-
throw new Error("Can't instantiate NodeFile in browser.");
|
|
1537
|
-
}
|
|
1538
|
-
throw new Error("Can't instantiate NodeFile. Make sure to import @loaders.gl/polyfills first.");
|
|
1391
|
+
// ../loader-utils/src/lib/worker-loader-utils/encode-with-worker.ts
|
|
1392
|
+
function canEncodeWithWorker(writer, options) {
|
|
1393
|
+
if (!WorkerFarm.isSupported()) {
|
|
1394
|
+
return false;
|
|
1539
1395
|
}
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
throw NOT_IMPLEMENTED;
|
|
1396
|
+
if (!isBrowser && !options?._nodeWorkers) {
|
|
1397
|
+
return false;
|
|
1543
1398
|
}
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1399
|
+
return writer.worker && options?.worker;
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
// ../loader-utils/src/lib/binary-utils/array-buffer-utils.ts
|
|
1403
|
+
function compareArrayBuffers(arrayBuffer1, arrayBuffer2, byteLength) {
|
|
1404
|
+
byteLength = byteLength || arrayBuffer1.byteLength;
|
|
1405
|
+
if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) {
|
|
1406
|
+
return false;
|
|
1547
1407
|
}
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1408
|
+
const array1 = new Uint8Array(arrayBuffer1);
|
|
1409
|
+
const array2 = new Uint8Array(arrayBuffer2);
|
|
1410
|
+
for (let i = 0; i < array1.length; ++i) {
|
|
1411
|
+
if (array1[i] !== array2[i]) {
|
|
1412
|
+
return false;
|
|
1413
|
+
}
|
|
1551
1414
|
}
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1415
|
+
return true;
|
|
1416
|
+
}
|
|
1417
|
+
function concatenateArrayBuffers(...sources) {
|
|
1418
|
+
return concatenateArrayBuffersFromArray(sources);
|
|
1419
|
+
}
|
|
1420
|
+
function concatenateArrayBuffersFromArray(sources) {
|
|
1421
|
+
const sourceArrays = sources.map(
|
|
1422
|
+
(source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
|
|
1423
|
+
);
|
|
1424
|
+
const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
|
|
1425
|
+
const result = new Uint8Array(byteLength);
|
|
1426
|
+
let offset = 0;
|
|
1427
|
+
for (const sourceArray of sourceArrays) {
|
|
1428
|
+
result.set(sourceArray, offset);
|
|
1429
|
+
offset += sourceArray.byteLength;
|
|
1555
1430
|
}
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
throw NOT_IMPLEMENTED;
|
|
1559
|
-
}
|
|
1560
|
-
/** Close the file */
|
|
1561
|
-
async close() {
|
|
1562
|
-
}
|
|
1563
|
-
};
|
|
1564
|
-
|
|
1565
|
-
// src/javascript-utils/is-type.ts
|
|
1566
|
-
var isBoolean = (x) => typeof x === "boolean";
|
|
1567
|
-
var isFunction = (x) => typeof x === "function";
|
|
1568
|
-
var isObject = (x) => x !== null && typeof x === "object";
|
|
1569
|
-
var isPureObject = (x) => isObject(x) && x.constructor === {}.constructor;
|
|
1570
|
-
var isPromise = (x) => isObject(x) && isFunction(x.then);
|
|
1571
|
-
var isIterable = (x) => Boolean(x) && typeof x[Symbol.iterator] === "function";
|
|
1572
|
-
var isAsyncIterable = (x) => x && typeof x[Symbol.asyncIterator] === "function";
|
|
1573
|
-
var isIterator = (x) => x && isFunction(x.next);
|
|
1574
|
-
var isResponse = (x) => typeof Response !== "undefined" && x instanceof Response || x && x.arrayBuffer && x.text && x.json;
|
|
1575
|
-
var isBlob = (x) => typeof Blob !== "undefined" && x instanceof Blob;
|
|
1576
|
-
var isBuffer2 = (x) => x && typeof x === "object" && x.isBuffer;
|
|
1577
|
-
var isWritableDOMStream = (x) => isObject(x) && isFunction(x.abort) && isFunction(x.getWriter);
|
|
1578
|
-
var isReadableDOMStream = (x) => typeof ReadableStream !== "undefined" && x instanceof ReadableStream || isObject(x) && isFunction(x.tee) && isFunction(x.cancel) && isFunction(x.getReader);
|
|
1579
|
-
var isWritableNodeStream = (x) => isObject(x) && isFunction(x.end) && isFunction(x.write) && isBoolean(x.writable);
|
|
1580
|
-
var isReadableNodeStream = (x) => isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);
|
|
1581
|
-
var isReadableStream = (x) => isReadableDOMStream(x) || isReadableNodeStream(x);
|
|
1582
|
-
var isWritableStream = (x) => isWritableDOMStream(x) || isWritableNodeStream(x);
|
|
1431
|
+
return result.buffer;
|
|
1432
|
+
}
|
|
1583
1433
|
|
|
1584
|
-
// src/lib/
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
if (matches3) {
|
|
1590
|
-
return matches3[1];
|
|
1434
|
+
// ../loader-utils/src/lib/iterators/text-iterators.ts
|
|
1435
|
+
async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
|
|
1436
|
+
const textDecoder = new TextDecoder(void 0, options);
|
|
1437
|
+
for await (const arrayBuffer of arrayBufferIterator) {
|
|
1438
|
+
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, { stream: true });
|
|
1591
1439
|
}
|
|
1592
|
-
return mimeString;
|
|
1593
1440
|
}
|
|
1594
|
-
function
|
|
1595
|
-
const
|
|
1596
|
-
|
|
1597
|
-
|
|
1441
|
+
async function* makeTextEncoderIterator(textIterator) {
|
|
1442
|
+
const textEncoder = new TextEncoder();
|
|
1443
|
+
for await (const text of textIterator) {
|
|
1444
|
+
yield typeof text === "string" ? textEncoder.encode(text) : text;
|
|
1598
1445
|
}
|
|
1599
|
-
return "";
|
|
1600
1446
|
}
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1447
|
+
async function* makeLineIterator(textIterator) {
|
|
1448
|
+
let previous = "";
|
|
1449
|
+
for await (const textChunk of textIterator) {
|
|
1450
|
+
previous += textChunk;
|
|
1451
|
+
let eolIndex;
|
|
1452
|
+
while ((eolIndex = previous.indexOf("\n")) >= 0) {
|
|
1453
|
+
const line = previous.slice(0, eolIndex + 1);
|
|
1454
|
+
previous = previous.slice(eolIndex + 1);
|
|
1455
|
+
yield line;
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
if (previous.length > 0) {
|
|
1459
|
+
yield previous;
|
|
1460
|
+
}
|
|
1607
1461
|
}
|
|
1608
|
-
function
|
|
1609
|
-
|
|
1462
|
+
async function* makeNumberedLineIterator(lineIterator) {
|
|
1463
|
+
let counter = 1;
|
|
1464
|
+
for await (const line of lineIterator) {
|
|
1465
|
+
yield { counter, line };
|
|
1466
|
+
counter++;
|
|
1467
|
+
}
|
|
1610
1468
|
}
|
|
1611
1469
|
|
|
1612
|
-
// src/lib/
|
|
1613
|
-
function
|
|
1614
|
-
|
|
1615
|
-
const
|
|
1616
|
-
|
|
1470
|
+
// ../loader-utils/src/lib/iterators/async-iteration.ts
|
|
1471
|
+
async function forEach(iterator, visitor) {
|
|
1472
|
+
while (true) {
|
|
1473
|
+
const { done, value } = await iterator.next();
|
|
1474
|
+
if (done) {
|
|
1475
|
+
iterator.return();
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1478
|
+
const cancel = visitor(value);
|
|
1479
|
+
if (cancel) {
|
|
1480
|
+
return;
|
|
1481
|
+
}
|
|
1617
1482
|
}
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1483
|
+
}
|
|
1484
|
+
async function concatenateArrayBuffersAsync(asyncIterator) {
|
|
1485
|
+
const arrayBuffers = [];
|
|
1486
|
+
for await (const chunk of asyncIterator) {
|
|
1487
|
+
arrayBuffers.push(chunk);
|
|
1621
1488
|
}
|
|
1622
|
-
|
|
1623
|
-
|
|
1489
|
+
return concatenateArrayBuffers(...arrayBuffers);
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
// ../../node_modules/@probe.gl/stats/dist/utils/hi-res-timestamp.js
|
|
1493
|
+
function getHiResTimestamp2() {
|
|
1494
|
+
let timestamp;
|
|
1495
|
+
if (typeof window !== "undefined" && window.performance) {
|
|
1496
|
+
timestamp = window.performance.now();
|
|
1497
|
+
} else if (typeof process !== "undefined" && process.hrtime) {
|
|
1498
|
+
const timeParts = process.hrtime();
|
|
1499
|
+
timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
|
|
1500
|
+
} else {
|
|
1501
|
+
timestamp = Date.now();
|
|
1624
1502
|
}
|
|
1625
|
-
return
|
|
1503
|
+
return timestamp;
|
|
1626
1504
|
}
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1505
|
+
|
|
1506
|
+
// ../../node_modules/@probe.gl/stats/dist/lib/stat.js
|
|
1507
|
+
var Stat = class {
|
|
1508
|
+
constructor(name, type) {
|
|
1509
|
+
_defineProperty(this, "name", void 0);
|
|
1510
|
+
_defineProperty(this, "type", void 0);
|
|
1511
|
+
_defineProperty(this, "sampleSize", 1);
|
|
1512
|
+
_defineProperty(this, "time", 0);
|
|
1513
|
+
_defineProperty(this, "count", 0);
|
|
1514
|
+
_defineProperty(this, "samples", 0);
|
|
1515
|
+
_defineProperty(this, "lastTiming", 0);
|
|
1516
|
+
_defineProperty(this, "lastSampleTime", 0);
|
|
1517
|
+
_defineProperty(this, "lastSampleCount", 0);
|
|
1518
|
+
_defineProperty(this, "_count", 0);
|
|
1519
|
+
_defineProperty(this, "_time", 0);
|
|
1520
|
+
_defineProperty(this, "_samples", 0);
|
|
1521
|
+
_defineProperty(this, "_startTime", 0);
|
|
1522
|
+
_defineProperty(this, "_timerPending", false);
|
|
1523
|
+
this.name = name;
|
|
1524
|
+
this.type = type;
|
|
1525
|
+
this.reset();
|
|
1633
1526
|
}
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1527
|
+
reset() {
|
|
1528
|
+
this.time = 0;
|
|
1529
|
+
this.count = 0;
|
|
1530
|
+
this.samples = 0;
|
|
1531
|
+
this.lastTiming = 0;
|
|
1532
|
+
this.lastSampleTime = 0;
|
|
1533
|
+
this.lastSampleCount = 0;
|
|
1534
|
+
this._count = 0;
|
|
1535
|
+
this._time = 0;
|
|
1536
|
+
this._samples = 0;
|
|
1537
|
+
this._startTime = 0;
|
|
1538
|
+
this._timerPending = false;
|
|
1539
|
+
return this;
|
|
1637
1540
|
}
|
|
1638
|
-
|
|
1639
|
-
|
|
1541
|
+
setSampleSize(samples) {
|
|
1542
|
+
this.sampleSize = samples;
|
|
1543
|
+
return this;
|
|
1640
1544
|
}
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
if (isResponse(resource)) {
|
|
1645
|
-
const response = resource;
|
|
1646
|
-
return response.headers["content-length"] || -1;
|
|
1545
|
+
incrementCount() {
|
|
1546
|
+
this.addCount(1);
|
|
1547
|
+
return this;
|
|
1647
1548
|
}
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
return
|
|
1549
|
+
decrementCount() {
|
|
1550
|
+
this.subtractCount(1);
|
|
1551
|
+
return this;
|
|
1651
1552
|
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1553
|
+
addCount(value) {
|
|
1554
|
+
this._count += value;
|
|
1555
|
+
this._samples++;
|
|
1556
|
+
this._checkSampling();
|
|
1557
|
+
return this;
|
|
1654
1558
|
}
|
|
1655
|
-
|
|
1656
|
-
|
|
1559
|
+
subtractCount(value) {
|
|
1560
|
+
this._count -= value;
|
|
1561
|
+
this._samples++;
|
|
1562
|
+
this._checkSampling();
|
|
1563
|
+
return this;
|
|
1657
1564
|
}
|
|
1658
|
-
|
|
1659
|
-
|
|
1565
|
+
addTime(time) {
|
|
1566
|
+
this._time += time;
|
|
1567
|
+
this.lastTiming = time;
|
|
1568
|
+
this._samples++;
|
|
1569
|
+
this._checkSampling();
|
|
1570
|
+
return this;
|
|
1660
1571
|
}
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
async function makeResponse(resource) {
|
|
1666
|
-
if (isResponse(resource)) {
|
|
1667
|
-
return resource;
|
|
1572
|
+
timeStart() {
|
|
1573
|
+
this._startTime = getHiResTimestamp2();
|
|
1574
|
+
this._timerPending = true;
|
|
1575
|
+
return this;
|
|
1668
1576
|
}
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1577
|
+
timeEnd() {
|
|
1578
|
+
if (!this._timerPending) {
|
|
1579
|
+
return this;
|
|
1580
|
+
}
|
|
1581
|
+
this.addTime(getHiResTimestamp2() - this._startTime);
|
|
1582
|
+
this._timerPending = false;
|
|
1583
|
+
this._checkSampling();
|
|
1584
|
+
return this;
|
|
1673
1585
|
}
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
if (type) {
|
|
1677
|
-
headers["content-type"] = type;
|
|
1586
|
+
getSampleAverageCount() {
|
|
1587
|
+
return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
|
|
1678
1588
|
}
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
headers["x-first-bytes"] = initialDataUrl;
|
|
1589
|
+
getSampleAverageTime() {
|
|
1590
|
+
return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
|
|
1682
1591
|
}
|
|
1683
|
-
|
|
1684
|
-
|
|
1592
|
+
getSampleHz() {
|
|
1593
|
+
return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1e3) : 0;
|
|
1685
1594
|
}
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
return response;
|
|
1689
|
-
}
|
|
1690
|
-
async function checkResponse(response) {
|
|
1691
|
-
if (!response.ok) {
|
|
1692
|
-
const message = await getResponseError(response);
|
|
1693
|
-
throw new Error(message);
|
|
1595
|
+
getAverageCount() {
|
|
1596
|
+
return this.samples > 0 ? this.count / this.samples : 0;
|
|
1694
1597
|
}
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
let message = `Failed to fetch resource ${response.url} (${response.status}): `;
|
|
1698
|
-
try {
|
|
1699
|
-
const contentType = response.headers.get("Content-Type");
|
|
1700
|
-
let text = response.statusText;
|
|
1701
|
-
if (contentType?.includes("application/json")) {
|
|
1702
|
-
text += ` ${await response.text()}`;
|
|
1703
|
-
}
|
|
1704
|
-
message += text;
|
|
1705
|
-
message = message.length > 60 ? `${message.slice(0, 60)}...` : message;
|
|
1706
|
-
} catch (error) {
|
|
1598
|
+
getAverageTime() {
|
|
1599
|
+
return this.samples > 0 ? this.time / this.samples : 0;
|
|
1707
1600
|
}
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
async function getInitialDataUrl(resource) {
|
|
1711
|
-
const INITIAL_DATA_LENGTH = 5;
|
|
1712
|
-
if (typeof resource === "string") {
|
|
1713
|
-
return `data:,${resource.slice(0, INITIAL_DATA_LENGTH)}`;
|
|
1714
|
-
}
|
|
1715
|
-
if (resource instanceof Blob) {
|
|
1716
|
-
const blobSlice = resource.slice(0, 5);
|
|
1717
|
-
return await new Promise((resolve2) => {
|
|
1718
|
-
const reader = new FileReader();
|
|
1719
|
-
reader.onload = (event) => resolve2(event?.target?.result);
|
|
1720
|
-
reader.readAsDataURL(blobSlice);
|
|
1721
|
-
});
|
|
1722
|
-
}
|
|
1723
|
-
if (resource instanceof ArrayBuffer) {
|
|
1724
|
-
const slice = resource.slice(0, INITIAL_DATA_LENGTH);
|
|
1725
|
-
const base64 = arrayBufferToBase64(slice);
|
|
1726
|
-
return `data:base64,${base64}`;
|
|
1727
|
-
}
|
|
1728
|
-
return null;
|
|
1729
|
-
}
|
|
1730
|
-
function arrayBufferToBase64(buffer) {
|
|
1731
|
-
let binary = "";
|
|
1732
|
-
const bytes = new Uint8Array(buffer);
|
|
1733
|
-
for (let i = 0; i < bytes.byteLength; i++) {
|
|
1734
|
-
binary += String.fromCharCode(bytes[i]);
|
|
1601
|
+
getHz() {
|
|
1602
|
+
return this.time > 0 ? this.samples / (this.time / 1e3) : 0;
|
|
1735
1603
|
}
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
function isDataURL(url) {
|
|
1747
|
-
return url.startsWith("data:");
|
|
1748
|
-
}
|
|
1749
|
-
async function fetchFile(urlOrData, fetchOptions) {
|
|
1750
|
-
if (typeof urlOrData === "string") {
|
|
1751
|
-
const url = resolvePath(urlOrData);
|
|
1752
|
-
if (isNodePath(url)) {
|
|
1753
|
-
if (globalThis.loaders?.fetchNode) {
|
|
1754
|
-
return globalThis.loaders?.fetchNode(url, fetchOptions);
|
|
1755
|
-
}
|
|
1604
|
+
_checkSampling() {
|
|
1605
|
+
if (this._samples === this.sampleSize) {
|
|
1606
|
+
this.lastSampleTime = this._time;
|
|
1607
|
+
this.lastSampleCount = this._count;
|
|
1608
|
+
this.count += this._count;
|
|
1609
|
+
this.time += this._time;
|
|
1610
|
+
this.samples += this._samples;
|
|
1611
|
+
this._time = 0;
|
|
1612
|
+
this._count = 0;
|
|
1613
|
+
this._samples = 0;
|
|
1756
1614
|
}
|
|
1757
|
-
return await fetch(url, fetchOptions);
|
|
1758
|
-
}
|
|
1759
|
-
return await makeResponse(urlOrData);
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1762
|
-
// src/lib/fetch/read-array-buffer.ts
|
|
1763
|
-
async function readArrayBuffer(file, start, length) {
|
|
1764
|
-
if (!(file instanceof Blob)) {
|
|
1765
|
-
file = new Blob([file]);
|
|
1766
1615
|
}
|
|
1767
|
-
|
|
1768
|
-
return await readBlob(slice);
|
|
1769
|
-
}
|
|
1770
|
-
async function readBlob(blob) {
|
|
1771
|
-
return await new Promise((resolve2, reject) => {
|
|
1772
|
-
const fileReader = new FileReader();
|
|
1773
|
-
fileReader.onload = (event) => resolve2(event?.target?.result);
|
|
1774
|
-
fileReader.onerror = (error) => reject(error);
|
|
1775
|
-
fileReader.readAsArrayBuffer(blob);
|
|
1776
|
-
});
|
|
1777
|
-
}
|
|
1616
|
+
};
|
|
1778
1617
|
|
|
1779
|
-
// ../../node_modules/@probe.gl/
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1618
|
+
// ../../node_modules/@probe.gl/stats/dist/lib/stats.js
|
|
1619
|
+
var Stats = class {
|
|
1620
|
+
constructor(options) {
|
|
1621
|
+
_defineProperty(this, "id", void 0);
|
|
1622
|
+
_defineProperty(this, "stats", {});
|
|
1623
|
+
this.id = options.id;
|
|
1624
|
+
this.stats = {};
|
|
1625
|
+
this._initializeStats(options.stats);
|
|
1626
|
+
Object.seal(this);
|
|
1783
1627
|
}
|
|
1784
|
-
|
|
1785
|
-
|
|
1628
|
+
get(name) {
|
|
1629
|
+
let type = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "count";
|
|
1630
|
+
return this._getOrCreate({
|
|
1631
|
+
name,
|
|
1632
|
+
type
|
|
1633
|
+
});
|
|
1786
1634
|
}
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
if (userAgent && userAgent.indexOf("Electron") >= 0) {
|
|
1790
|
-
return true;
|
|
1635
|
+
get size() {
|
|
1636
|
+
return Object.keys(this.stats).length;
|
|
1791
1637
|
}
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
const isNode = typeof process === "object" && String(process) === "[object process]" && !process.browser;
|
|
1798
|
-
return !isNode || isElectron();
|
|
1799
|
-
}
|
|
1800
|
-
|
|
1801
|
-
// ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/lib/globals.js
|
|
1802
|
-
var self_3 = globalThis.self || globalThis.window || globalThis.global;
|
|
1803
|
-
var window_3 = globalThis.window || globalThis.self || globalThis.global;
|
|
1804
|
-
var document_3 = globalThis.document || {};
|
|
1805
|
-
var process_ = globalThis.process || {};
|
|
1806
|
-
var console_ = globalThis.console;
|
|
1807
|
-
var navigator_ = globalThis.navigator || {};
|
|
1808
|
-
|
|
1809
|
-
// ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/utils/globals.js
|
|
1810
|
-
var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "untranspiled source";
|
|
1811
|
-
var isBrowser4 = isBrowser3();
|
|
1812
|
-
|
|
1813
|
-
// ../../node_modules/@probe.gl/log/dist/utils/local-storage.js
|
|
1814
|
-
function getStorage(type) {
|
|
1815
|
-
try {
|
|
1816
|
-
const storage = window[type];
|
|
1817
|
-
const x = "__storage_test__";
|
|
1818
|
-
storage.setItem(x, x);
|
|
1819
|
-
storage.removeItem(x);
|
|
1820
|
-
return storage;
|
|
1821
|
-
} catch (e) {
|
|
1822
|
-
return null;
|
|
1638
|
+
reset() {
|
|
1639
|
+
for (const stat of Object.values(this.stats)) {
|
|
1640
|
+
stat.reset();
|
|
1641
|
+
}
|
|
1642
|
+
return this;
|
|
1823
1643
|
}
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
_defineProperty(this, "storage", void 0);
|
|
1829
|
-
_defineProperty(this, "id", void 0);
|
|
1830
|
-
_defineProperty(this, "config", void 0);
|
|
1831
|
-
this.storage = getStorage(type);
|
|
1832
|
-
this.id = id;
|
|
1833
|
-
this.config = defaultConfig;
|
|
1834
|
-
this._loadConfiguration();
|
|
1644
|
+
forEach(fn) {
|
|
1645
|
+
for (const stat of Object.values(this.stats)) {
|
|
1646
|
+
fn(stat);
|
|
1647
|
+
}
|
|
1835
1648
|
}
|
|
1836
|
-
|
|
1837
|
-
|
|
1649
|
+
getTable() {
|
|
1650
|
+
const table = {};
|
|
1651
|
+
this.forEach((stat) => {
|
|
1652
|
+
table[stat.name] = {
|
|
1653
|
+
time: stat.time || 0,
|
|
1654
|
+
count: stat.count || 0,
|
|
1655
|
+
average: stat.getAverageTime() || 0,
|
|
1656
|
+
hz: stat.getHz() || 0
|
|
1657
|
+
};
|
|
1658
|
+
});
|
|
1659
|
+
return table;
|
|
1838
1660
|
}
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
const serialized = JSON.stringify(this.config);
|
|
1843
|
-
this.storage.setItem(this.id, serialized);
|
|
1844
|
-
}
|
|
1661
|
+
_initializeStats() {
|
|
1662
|
+
let stats = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
|
1663
|
+
stats.forEach((stat) => this._getOrCreate(stat));
|
|
1845
1664
|
}
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1665
|
+
_getOrCreate(stat) {
|
|
1666
|
+
const {
|
|
1667
|
+
name,
|
|
1668
|
+
type
|
|
1669
|
+
} = stat;
|
|
1670
|
+
let result = this.stats[name];
|
|
1671
|
+
if (!result) {
|
|
1672
|
+
if (stat instanceof Stat) {
|
|
1673
|
+
result = stat;
|
|
1674
|
+
} else {
|
|
1675
|
+
result = new Stat(name, type);
|
|
1676
|
+
}
|
|
1677
|
+
this.stats[name] = result;
|
|
1851
1678
|
}
|
|
1852
|
-
|
|
1853
|
-
return this;
|
|
1679
|
+
return result;
|
|
1854
1680
|
}
|
|
1855
1681
|
};
|
|
1856
1682
|
|
|
1857
|
-
//
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1683
|
+
// ../loader-utils/src/lib/request-utils/request-scheduler.ts
|
|
1684
|
+
var STAT_QUEUED_REQUESTS = "Queued Requests";
|
|
1685
|
+
var STAT_ACTIVE_REQUESTS = "Active Requests";
|
|
1686
|
+
var STAT_CANCELLED_REQUESTS = "Cancelled Requests";
|
|
1687
|
+
var STAT_QUEUED_REQUESTS_EVER = "Queued Requests Ever";
|
|
1688
|
+
var STAT_ACTIVE_REQUESTS_EVER = "Active Requests Ever";
|
|
1689
|
+
var DEFAULT_PROPS2 = {
|
|
1690
|
+
id: "request-scheduler",
|
|
1691
|
+
/** Specifies if the request scheduler should throttle incoming requests, mainly for comparative testing. */
|
|
1692
|
+
throttleRequests: true,
|
|
1693
|
+
/** The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit. */
|
|
1694
|
+
maxRequests: 6,
|
|
1695
|
+
/**
|
|
1696
|
+
* Specifies a debounce time, in milliseconds. All requests are queued, until no new requests have
|
|
1697
|
+
* been added to the queue for this amount of time.
|
|
1698
|
+
*/
|
|
1699
|
+
debounceTime: 0
|
|
1700
|
+
};
|
|
1701
|
+
var RequestScheduler = class {
|
|
1702
|
+
props;
|
|
1703
|
+
stats;
|
|
1704
|
+
activeRequestCount = 0;
|
|
1705
|
+
/** Tracks the number of active requests and prioritizes/cancels queued requests. */
|
|
1706
|
+
requestQueue = [];
|
|
1707
|
+
requestMap = /* @__PURE__ */ new Map();
|
|
1708
|
+
updateTimer = null;
|
|
1709
|
+
constructor(props = {}) {
|
|
1710
|
+
this.props = { ...DEFAULT_PROPS2, ...props };
|
|
1711
|
+
this.stats = new Stats({ id: this.props.id });
|
|
1712
|
+
this.stats.get(STAT_QUEUED_REQUESTS);
|
|
1713
|
+
this.stats.get(STAT_ACTIVE_REQUESTS);
|
|
1714
|
+
this.stats.get(STAT_CANCELLED_REQUESTS);
|
|
1715
|
+
this.stats.get(STAT_QUEUED_REQUESTS_EVER);
|
|
1716
|
+
this.stats.get(STAT_ACTIVE_REQUESTS_EVER);
|
|
1868
1717
|
}
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1718
|
+
/**
|
|
1719
|
+
* Called by an application that wants to issue a request, without having it deeply queued by the browser
|
|
1720
|
+
*
|
|
1721
|
+
* When the returned promise resolved, it is OK for the application to issue a request.
|
|
1722
|
+
* The promise resolves to an object that contains a `done` method.
|
|
1723
|
+
* When the application's request has completed (or failed), the application must call the `done` function
|
|
1724
|
+
*
|
|
1725
|
+
* @param handle
|
|
1726
|
+
* @param getPriority will be called when request "slots" open up,
|
|
1727
|
+
* allowing the caller to update priority or cancel the request
|
|
1728
|
+
* Highest priority executes first, priority < 0 cancels the request
|
|
1729
|
+
* @returns a promise
|
|
1730
|
+
* - resolves to a object (with a `done` field) when the request can be issued without queueing,
|
|
1731
|
+
* - resolves to `null` if the request has been cancelled (by the callback return < 0).
|
|
1732
|
+
* In this case the application should not issue the request
|
|
1733
|
+
*/
|
|
1734
|
+
scheduleRequest(handle, getPriority = () => 0) {
|
|
1735
|
+
if (!this.props.throttleRequests) {
|
|
1736
|
+
return Promise.resolve({ done: () => {
|
|
1737
|
+
} });
|
|
1738
|
+
}
|
|
1739
|
+
if (this.requestMap.has(handle)) {
|
|
1740
|
+
return this.requestMap.get(handle);
|
|
1741
|
+
}
|
|
1742
|
+
const request = { handle, priority: 0, getPriority };
|
|
1743
|
+
const promise = new Promise((resolve2) => {
|
|
1744
|
+
request.resolve = resolve2;
|
|
1745
|
+
return request;
|
|
1746
|
+
});
|
|
1747
|
+
this.requestQueue.push(request);
|
|
1748
|
+
this.requestMap.set(handle, promise);
|
|
1749
|
+
this._issueNewRequests();
|
|
1750
|
+
return promise;
|
|
1881
1751
|
}
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1752
|
+
// PRIVATE
|
|
1753
|
+
_issueRequest(request) {
|
|
1754
|
+
const { handle, resolve: resolve2 } = request;
|
|
1755
|
+
let isDone = false;
|
|
1756
|
+
const done = () => {
|
|
1757
|
+
if (!isDone) {
|
|
1758
|
+
isDone = true;
|
|
1759
|
+
this.requestMap.delete(handle);
|
|
1760
|
+
this.activeRequestCount--;
|
|
1761
|
+
this._issueNewRequests();
|
|
1762
|
+
}
|
|
1763
|
+
};
|
|
1764
|
+
this.activeRequestCount++;
|
|
1765
|
+
return resolve2 ? resolve2({ done }) : Promise.resolve({ done });
|
|
1766
|
+
}
|
|
1767
|
+
/** We check requests asynchronously, to prevent multiple updates */
|
|
1768
|
+
_issueNewRequests() {
|
|
1769
|
+
if (this.updateTimer !== null) {
|
|
1770
|
+
clearTimeout(this.updateTimer);
|
|
1771
|
+
}
|
|
1772
|
+
this.updateTimer = setTimeout(() => this._issueNewRequestsAsync(), this.props.debounceTime);
|
|
1773
|
+
}
|
|
1774
|
+
/** Refresh all requests */
|
|
1775
|
+
_issueNewRequestsAsync() {
|
|
1776
|
+
if (this.updateTimer !== null) {
|
|
1777
|
+
clearTimeout(this.updateTimer);
|
|
1778
|
+
}
|
|
1779
|
+
this.updateTimer = null;
|
|
1780
|
+
const freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);
|
|
1781
|
+
if (freeSlots === 0) {
|
|
1782
|
+
return;
|
|
1783
|
+
}
|
|
1784
|
+
this._updateAllRequests();
|
|
1785
|
+
for (let i = 0; i < freeSlots; ++i) {
|
|
1786
|
+
const request = this.requestQueue.shift();
|
|
1787
|
+
if (request) {
|
|
1788
|
+
this._issueRequest(request);
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1912
1791
|
}
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1792
|
+
/** Ensure all requests have updated priorities, and that no longer valid requests are cancelled */
|
|
1793
|
+
_updateAllRequests() {
|
|
1794
|
+
const requestQueue = this.requestQueue;
|
|
1795
|
+
for (let i = 0; i < requestQueue.length; ++i) {
|
|
1796
|
+
const request = requestQueue[i];
|
|
1797
|
+
if (!this._updateRequest(request)) {
|
|
1798
|
+
requestQueue.splice(i, 1);
|
|
1799
|
+
this.requestMap.delete(request.handle);
|
|
1800
|
+
i--;
|
|
1801
|
+
}
|
|
1921
1802
|
}
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1803
|
+
requestQueue.sort((a, b) => a.priority - b.priority);
|
|
1804
|
+
}
|
|
1805
|
+
/** Update a single request by calling the callback */
|
|
1806
|
+
_updateRequest(request) {
|
|
1807
|
+
request.priority = request.getPriority(request.handle);
|
|
1808
|
+
if (request.priority < 0) {
|
|
1809
|
+
request.resolve(null);
|
|
1810
|
+
return false;
|
|
1925
1811
|
}
|
|
1812
|
+
return true;
|
|
1926
1813
|
}
|
|
1927
|
-
|
|
1928
|
-
}
|
|
1814
|
+
};
|
|
1929
1815
|
|
|
1930
|
-
//
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1816
|
+
// ../loader-utils/src/lib/path-utils/file-aliases.ts
|
|
1817
|
+
var pathPrefix = "";
|
|
1818
|
+
var fileAliases = {};
|
|
1819
|
+
function setPathPrefix(prefix) {
|
|
1820
|
+
pathPrefix = prefix;
|
|
1821
|
+
}
|
|
1822
|
+
function getPathPrefix() {
|
|
1823
|
+
return pathPrefix;
|
|
1824
|
+
}
|
|
1825
|
+
function resolvePath(filename2) {
|
|
1826
|
+
for (const alias in fileAliases) {
|
|
1827
|
+
if (filename2.startsWith(alias)) {
|
|
1828
|
+
const replacement = fileAliases[alias];
|
|
1829
|
+
filename2 = filename2.replace(alias, replacement);
|
|
1942
1830
|
}
|
|
1943
1831
|
}
|
|
1832
|
+
if (!filename2.startsWith("http://") && !filename2.startsWith("https://")) {
|
|
1833
|
+
filename2 = `${pathPrefix}${filename2}`;
|
|
1834
|
+
}
|
|
1835
|
+
return filename2;
|
|
1944
1836
|
}
|
|
1945
1837
|
|
|
1946
|
-
//
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1838
|
+
// ../loader-utils/src/json-loader.ts
|
|
1839
|
+
var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1840
|
+
var JSONLoader = {
|
|
1841
|
+
dataType: null,
|
|
1842
|
+
batchType: null,
|
|
1843
|
+
name: "JSON",
|
|
1844
|
+
id: "json",
|
|
1845
|
+
module: "json",
|
|
1846
|
+
version: VERSION3,
|
|
1847
|
+
extensions: ["json", "geojson"],
|
|
1848
|
+
mimeTypes: ["application/json"],
|
|
1849
|
+
category: "json",
|
|
1850
|
+
text: true,
|
|
1851
|
+
parseTextSync,
|
|
1852
|
+
parse: async (arrayBuffer) => parseTextSync(new TextDecoder().decode(arrayBuffer)),
|
|
1853
|
+
options: {}
|
|
1854
|
+
};
|
|
1855
|
+
function parseTextSync(text) {
|
|
1856
|
+
return JSON.parse(text);
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
// ../loader-utils/src/lib/node/buffer.browser.ts
|
|
1860
|
+
function toArrayBuffer(buffer) {
|
|
1861
|
+
return buffer;
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
// ../loader-utils/src/lib/binary-utils/memory-conversion-utils.ts
|
|
1865
|
+
function isBuffer(value) {
|
|
1866
|
+
return value && typeof value === "object" && value.isBuffer;
|
|
1867
|
+
}
|
|
1868
|
+
function toArrayBuffer2(data) {
|
|
1869
|
+
if (isBuffer(data)) {
|
|
1870
|
+
return toArrayBuffer(data);
|
|
1950
1871
|
}
|
|
1872
|
+
if (data instanceof ArrayBuffer) {
|
|
1873
|
+
return data;
|
|
1874
|
+
}
|
|
1875
|
+
if (ArrayBuffer.isView(data)) {
|
|
1876
|
+
if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
|
|
1877
|
+
return data.buffer;
|
|
1878
|
+
}
|
|
1879
|
+
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
1880
|
+
}
|
|
1881
|
+
if (typeof data === "string") {
|
|
1882
|
+
const text = data;
|
|
1883
|
+
const uint8Array = new TextEncoder().encode(text);
|
|
1884
|
+
return uint8Array.buffer;
|
|
1885
|
+
}
|
|
1886
|
+
if (data && typeof data === "object" && data._toArrayBuffer) {
|
|
1887
|
+
return data._toArrayBuffer();
|
|
1888
|
+
}
|
|
1889
|
+
throw new Error("toArrayBuffer");
|
|
1951
1890
|
}
|
|
1952
1891
|
|
|
1953
|
-
//
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1892
|
+
// ../loader-utils/src/lib/path-utils/path.ts
|
|
1893
|
+
var path_exports = {};
|
|
1894
|
+
__export(path_exports, {
|
|
1895
|
+
dirname: () => dirname,
|
|
1896
|
+
filename: () => filename,
|
|
1897
|
+
join: () => join,
|
|
1898
|
+
resolve: () => resolve
|
|
1899
|
+
});
|
|
1900
|
+
|
|
1901
|
+
// ../loader-utils/src/lib/path-utils/get-cwd.ts
|
|
1902
|
+
function getCWD() {
|
|
1903
|
+
if (typeof process !== "undefined" && typeof process.cwd !== "undefined") {
|
|
1904
|
+
return process.cwd();
|
|
1965
1905
|
}
|
|
1966
|
-
|
|
1906
|
+
const pathname = window.location?.pathname;
|
|
1907
|
+
return pathname?.slice(0, pathname.lastIndexOf("/") + 1) || "";
|
|
1967
1908
|
}
|
|
1968
1909
|
|
|
1969
|
-
//
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
info: console.info,
|
|
1974
|
-
warn: console.warn,
|
|
1975
|
-
error: console.error
|
|
1976
|
-
};
|
|
1977
|
-
var DEFAULT_LOG_CONFIGURATION = {
|
|
1978
|
-
enabled: true,
|
|
1979
|
-
level: 0
|
|
1980
|
-
};
|
|
1981
|
-
function noop() {
|
|
1910
|
+
// ../loader-utils/src/lib/path-utils/path.ts
|
|
1911
|
+
function filename(url) {
|
|
1912
|
+
const slashIndex = url ? url.lastIndexOf("/") : -1;
|
|
1913
|
+
return slashIndex >= 0 ? url.substr(slashIndex + 1) : "";
|
|
1982
1914
|
}
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
}
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
this.timeStamp("".concat(this.id, " started"));
|
|
2005
|
-
autobind(this);
|
|
2006
|
-
Object.seal(this);
|
|
2007
|
-
}
|
|
2008
|
-
set level(newLevel) {
|
|
2009
|
-
this.setLevel(newLevel);
|
|
1915
|
+
function dirname(url) {
|
|
1916
|
+
const slashIndex = url ? url.lastIndexOf("/") : -1;
|
|
1917
|
+
return slashIndex >= 0 ? url.substr(0, slashIndex) : "";
|
|
1918
|
+
}
|
|
1919
|
+
function join(...parts) {
|
|
1920
|
+
const separator = "/";
|
|
1921
|
+
parts = parts.map((part, index) => {
|
|
1922
|
+
if (index) {
|
|
1923
|
+
part = part.replace(new RegExp(`^${separator}`), "");
|
|
1924
|
+
}
|
|
1925
|
+
if (index !== parts.length - 1) {
|
|
1926
|
+
part = part.replace(new RegExp(`${separator}$`), "");
|
|
1927
|
+
}
|
|
1928
|
+
return part;
|
|
1929
|
+
});
|
|
1930
|
+
return parts.join(separator);
|
|
1931
|
+
}
|
|
1932
|
+
function resolve(...components) {
|
|
1933
|
+
const paths = [];
|
|
1934
|
+
for (let _i = 0; _i < components.length; _i++) {
|
|
1935
|
+
paths[_i] = components[_i];
|
|
2010
1936
|
}
|
|
2011
|
-
|
|
2012
|
-
|
|
1937
|
+
let resolvedPath = "";
|
|
1938
|
+
let resolvedAbsolute = false;
|
|
1939
|
+
let cwd;
|
|
1940
|
+
for (let i = paths.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
1941
|
+
let path;
|
|
1942
|
+
if (i >= 0) {
|
|
1943
|
+
path = paths[i];
|
|
1944
|
+
} else {
|
|
1945
|
+
if (cwd === void 0) {
|
|
1946
|
+
cwd = getCWD();
|
|
1947
|
+
}
|
|
1948
|
+
path = cwd;
|
|
1949
|
+
}
|
|
1950
|
+
if (path.length === 0) {
|
|
1951
|
+
continue;
|
|
1952
|
+
}
|
|
1953
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
1954
|
+
resolvedAbsolute = path.charCodeAt(0) === SLASH;
|
|
2013
1955
|
}
|
|
2014
|
-
|
|
2015
|
-
|
|
1956
|
+
resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
|
|
1957
|
+
if (resolvedAbsolute) {
|
|
1958
|
+
return `/${resolvedPath}`;
|
|
1959
|
+
} else if (resolvedPath.length > 0) {
|
|
1960
|
+
return resolvedPath;
|
|
2016
1961
|
}
|
|
2017
|
-
|
|
2018
|
-
|
|
1962
|
+
return ".";
|
|
1963
|
+
}
|
|
1964
|
+
var SLASH = 47;
|
|
1965
|
+
var DOT = 46;
|
|
1966
|
+
function normalizeStringPosix(path, allowAboveRoot) {
|
|
1967
|
+
let res = "";
|
|
1968
|
+
let lastSlash = -1;
|
|
1969
|
+
let dots = 0;
|
|
1970
|
+
let code;
|
|
1971
|
+
let isAboveRoot = false;
|
|
1972
|
+
for (let i = 0; i <= path.length; ++i) {
|
|
1973
|
+
if (i < path.length) {
|
|
1974
|
+
code = path.charCodeAt(i);
|
|
1975
|
+
} else if (code === SLASH) {
|
|
1976
|
+
break;
|
|
1977
|
+
} else {
|
|
1978
|
+
code = SLASH;
|
|
1979
|
+
}
|
|
1980
|
+
if (code === SLASH) {
|
|
1981
|
+
if (lastSlash === i - 1 || dots === 1) {
|
|
1982
|
+
} else if (lastSlash !== i - 1 && dots === 2) {
|
|
1983
|
+
if (res.length < 2 || !isAboveRoot || res.charCodeAt(res.length - 1) !== DOT || res.charCodeAt(res.length - 2) !== DOT) {
|
|
1984
|
+
if (res.length > 2) {
|
|
1985
|
+
const start = res.length - 1;
|
|
1986
|
+
let j = start;
|
|
1987
|
+
for (; j >= 0; --j) {
|
|
1988
|
+
if (res.charCodeAt(j) === SLASH) {
|
|
1989
|
+
break;
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
if (j !== start) {
|
|
1993
|
+
res = j === -1 ? "" : res.slice(0, j);
|
|
1994
|
+
lastSlash = i;
|
|
1995
|
+
dots = 0;
|
|
1996
|
+
isAboveRoot = false;
|
|
1997
|
+
continue;
|
|
1998
|
+
}
|
|
1999
|
+
} else if (res.length === 2 || res.length === 1) {
|
|
2000
|
+
res = "";
|
|
2001
|
+
lastSlash = i;
|
|
2002
|
+
dots = 0;
|
|
2003
|
+
isAboveRoot = false;
|
|
2004
|
+
continue;
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
if (allowAboveRoot) {
|
|
2008
|
+
if (res.length > 0) {
|
|
2009
|
+
res += "/..";
|
|
2010
|
+
} else {
|
|
2011
|
+
res = "..";
|
|
2012
|
+
}
|
|
2013
|
+
isAboveRoot = true;
|
|
2014
|
+
}
|
|
2015
|
+
} else {
|
|
2016
|
+
const slice = path.slice(lastSlash + 1, i);
|
|
2017
|
+
if (res.length > 0) {
|
|
2018
|
+
res += `/${slice}`;
|
|
2019
|
+
} else {
|
|
2020
|
+
res = slice;
|
|
2021
|
+
}
|
|
2022
|
+
isAboveRoot = false;
|
|
2023
|
+
}
|
|
2024
|
+
lastSlash = i;
|
|
2025
|
+
dots = 0;
|
|
2026
|
+
} else if (code === DOT && dots !== -1) {
|
|
2027
|
+
++dots;
|
|
2028
|
+
} else {
|
|
2029
|
+
dots = -1;
|
|
2030
|
+
}
|
|
2019
2031
|
}
|
|
2020
|
-
|
|
2021
|
-
|
|
2032
|
+
return res;
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
// ../loader-utils/src/lib/files/blob-file.ts
|
|
2036
|
+
var BlobFile = class {
|
|
2037
|
+
handle;
|
|
2038
|
+
size;
|
|
2039
|
+
bigsize;
|
|
2040
|
+
url;
|
|
2041
|
+
constructor(blob) {
|
|
2042
|
+
this.handle = blob instanceof ArrayBuffer ? new Blob([blob]) : blob;
|
|
2043
|
+
this.size = blob instanceof ArrayBuffer ? blob.byteLength : blob.size;
|
|
2044
|
+
this.bigsize = BigInt(this.size);
|
|
2045
|
+
this.url = blob instanceof File ? blob.name : "";
|
|
2022
2046
|
}
|
|
2023
|
-
|
|
2024
|
-
return Number((getHiResTimestamp2() - this._deltaTs).toPrecision(10));
|
|
2047
|
+
async close() {
|
|
2025
2048
|
}
|
|
2026
|
-
|
|
2027
|
-
|
|
2049
|
+
async stat() {
|
|
2050
|
+
return {
|
|
2051
|
+
size: this.handle.size,
|
|
2052
|
+
bigsize: BigInt(this.handle.size),
|
|
2053
|
+
isDirectory: false
|
|
2054
|
+
};
|
|
2028
2055
|
}
|
|
2029
|
-
|
|
2030
|
-
|
|
2056
|
+
async read(start, length) {
|
|
2057
|
+
const arrayBuffer = await this.handle.slice(start, start + length).arrayBuffer();
|
|
2058
|
+
return arrayBuffer;
|
|
2031
2059
|
}
|
|
2032
|
-
|
|
2033
|
-
|
|
2060
|
+
};
|
|
2061
|
+
|
|
2062
|
+
// ../loader-utils/src/lib/files/node-file-facade.ts
|
|
2063
|
+
var NOT_IMPLEMENTED = new Error("Not implemented");
|
|
2064
|
+
var NodeFileFacade = class {
|
|
2065
|
+
handle;
|
|
2066
|
+
size = 0;
|
|
2067
|
+
bigsize = 0n;
|
|
2068
|
+
url = "";
|
|
2069
|
+
constructor(url, flags, mode) {
|
|
2070
|
+
if (globalThis.loaders?.NodeFile) {
|
|
2071
|
+
return new globalThis.loaders.NodeFile(url, flags, mode);
|
|
2072
|
+
}
|
|
2073
|
+
if (isBrowser) {
|
|
2074
|
+
throw new Error("Can't instantiate NodeFile in browser.");
|
|
2075
|
+
}
|
|
2076
|
+
throw new Error("Can't instantiate NodeFile. Make sure to import @loaders.gl/polyfills first.");
|
|
2034
2077
|
}
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
enabled
|
|
2039
|
-
});
|
|
2040
|
-
return this;
|
|
2078
|
+
/** Read data */
|
|
2079
|
+
async read(start, end) {
|
|
2080
|
+
throw NOT_IMPLEMENTED;
|
|
2041
2081
|
}
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
});
|
|
2046
|
-
return this;
|
|
2082
|
+
/** Write to file. The number of bytes written will be returned */
|
|
2083
|
+
async write(arrayBuffer, offset, length) {
|
|
2084
|
+
throw NOT_IMPLEMENTED;
|
|
2047
2085
|
}
|
|
2048
|
-
|
|
2049
|
-
|
|
2086
|
+
/** Get information about file */
|
|
2087
|
+
async stat() {
|
|
2088
|
+
throw NOT_IMPLEMENTED;
|
|
2050
2089
|
}
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
});
|
|
2090
|
+
/** Truncates the file descriptor. Only available on NodeFile. */
|
|
2091
|
+
async truncate(length) {
|
|
2092
|
+
throw NOT_IMPLEMENTED;
|
|
2055
2093
|
}
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
} else {
|
|
2060
|
-
console.log(this._storage.config);
|
|
2061
|
-
}
|
|
2094
|
+
/** Append data to a file. Only available on NodeFile. */
|
|
2095
|
+
async append(data) {
|
|
2096
|
+
throw NOT_IMPLEMENTED;
|
|
2062
2097
|
}
|
|
2063
|
-
|
|
2064
|
-
|
|
2098
|
+
/** Close the file */
|
|
2099
|
+
async close() {
|
|
2065
2100
|
}
|
|
2066
|
-
|
|
2067
|
-
|
|
2101
|
+
};
|
|
2102
|
+
|
|
2103
|
+
// src/javascript-utils/is-type.ts
|
|
2104
|
+
var isBoolean = (x) => typeof x === "boolean";
|
|
2105
|
+
var isFunction = (x) => typeof x === "function";
|
|
2106
|
+
var isObject = (x) => x !== null && typeof x === "object";
|
|
2107
|
+
var isPureObject = (x) => isObject(x) && x.constructor === {}.constructor;
|
|
2108
|
+
var isPromise = (x) => isObject(x) && isFunction(x.then);
|
|
2109
|
+
var isIterable = (x) => Boolean(x) && typeof x[Symbol.iterator] === "function";
|
|
2110
|
+
var isAsyncIterable = (x) => x && typeof x[Symbol.asyncIterator] === "function";
|
|
2111
|
+
var isIterator = (x) => x && isFunction(x.next);
|
|
2112
|
+
var isResponse = (x) => typeof Response !== "undefined" && x instanceof Response || x && x.arrayBuffer && x.text && x.json;
|
|
2113
|
+
var isBlob = (x) => typeof Blob !== "undefined" && x instanceof Blob;
|
|
2114
|
+
var isBuffer2 = (x) => x && typeof x === "object" && x.isBuffer;
|
|
2115
|
+
var isWritableDOMStream = (x) => isObject(x) && isFunction(x.abort) && isFunction(x.getWriter);
|
|
2116
|
+
var isReadableDOMStream = (x) => typeof ReadableStream !== "undefined" && x instanceof ReadableStream || isObject(x) && isFunction(x.tee) && isFunction(x.cancel) && isFunction(x.getReader);
|
|
2117
|
+
var isWritableNodeStream = (x) => isObject(x) && isFunction(x.end) && isFunction(x.write) && isBoolean(x.writable);
|
|
2118
|
+
var isReadableNodeStream = (x) => isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);
|
|
2119
|
+
var isReadableStream = (x) => isReadableDOMStream(x) || isReadableNodeStream(x);
|
|
2120
|
+
var isWritableStream = (x) => isWritableDOMStream(x) || isWritableNodeStream(x);
|
|
2121
|
+
|
|
2122
|
+
// src/lib/fetch/fetch-error.ts
|
|
2123
|
+
var FetchError = class extends Error {
|
|
2124
|
+
constructor(message, info) {
|
|
2125
|
+
super(message);
|
|
2126
|
+
this.reason = info.reason;
|
|
2127
|
+
this.url = info.url;
|
|
2128
|
+
this.response = info.response;
|
|
2129
|
+
}
|
|
2130
|
+
/** A best effort reason for why the fetch failed */
|
|
2131
|
+
reason;
|
|
2132
|
+
/** The URL that failed to load. Empty string if not available. */
|
|
2133
|
+
url;
|
|
2134
|
+
/** The Response object, if any. */
|
|
2135
|
+
response;
|
|
2136
|
+
};
|
|
2137
|
+
|
|
2138
|
+
// src/lib/utils/mime-type-utils.ts
|
|
2139
|
+
var DATA_URL_PATTERN = /^data:([-\w.]+\/[-\w.+]+)(;|,)/;
|
|
2140
|
+
var MIME_TYPE_PATTERN = /^([-\w.]+\/[-\w.+]+)/;
|
|
2141
|
+
function compareMIMETypes(mimeType1, mimeType2) {
|
|
2142
|
+
if (mimeType1.toLowerCase() === mimeType2.toLowerCase()) {
|
|
2143
|
+
return true;
|
|
2068
2144
|
}
|
|
2069
|
-
|
|
2070
|
-
|
|
2145
|
+
return false;
|
|
2146
|
+
}
|
|
2147
|
+
function parseMIMEType(mimeString) {
|
|
2148
|
+
const matches3 = MIME_TYPE_PATTERN.exec(mimeString);
|
|
2149
|
+
if (matches3) {
|
|
2150
|
+
return matches3[1];
|
|
2071
2151
|
}
|
|
2072
|
-
|
|
2073
|
-
|
|
2152
|
+
return mimeString;
|
|
2153
|
+
}
|
|
2154
|
+
function parseMIMETypeFromURL(url) {
|
|
2155
|
+
const matches3 = DATA_URL_PATTERN.exec(url);
|
|
2156
|
+
if (matches3) {
|
|
2157
|
+
return matches3[1];
|
|
2074
2158
|
}
|
|
2075
|
-
|
|
2076
|
-
|
|
2159
|
+
return "";
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
// src/lib/utils/url-utils.ts
|
|
2163
|
+
var QUERY_STRING_PATTERN = /\?.*/;
|
|
2164
|
+
function extractQueryString(url) {
|
|
2165
|
+
const matches3 = url.match(QUERY_STRING_PATTERN);
|
|
2166
|
+
return matches3 && matches3[0];
|
|
2167
|
+
}
|
|
2168
|
+
function stripQueryString(url) {
|
|
2169
|
+
return url.replace(QUERY_STRING_PATTERN, "");
|
|
2170
|
+
}
|
|
2171
|
+
function shortenUrlForDisplay(url) {
|
|
2172
|
+
if (url.length < 50) {
|
|
2173
|
+
return url;
|
|
2077
2174
|
}
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2175
|
+
const urlEnd = url.slice(url.length - 15);
|
|
2176
|
+
const urlStart = url.substr(0, 32);
|
|
2177
|
+
return `${urlStart}...${urlEnd}`;
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2180
|
+
// src/lib/utils/resource-utils.ts
|
|
2181
|
+
function getResourceUrl(resource) {
|
|
2182
|
+
if (isResponse(resource)) {
|
|
2183
|
+
const response = resource;
|
|
2184
|
+
return response.url;
|
|
2083
2185
|
}
|
|
2084
|
-
|
|
2085
|
-
|
|
2186
|
+
if (isBlob(resource)) {
|
|
2187
|
+
const blob = resource;
|
|
2188
|
+
return blob.name || "";
|
|
2086
2189
|
}
|
|
2087
|
-
|
|
2088
|
-
return
|
|
2190
|
+
if (typeof resource === "string") {
|
|
2191
|
+
return resource;
|
|
2089
2192
|
}
|
|
2090
|
-
|
|
2091
|
-
|
|
2193
|
+
return "";
|
|
2194
|
+
}
|
|
2195
|
+
function getResourceMIMEType(resource) {
|
|
2196
|
+
if (isResponse(resource)) {
|
|
2197
|
+
const response = resource;
|
|
2198
|
+
const contentTypeHeader = response.headers.get("content-type") || "";
|
|
2199
|
+
const noQueryUrl = stripQueryString(response.url);
|
|
2200
|
+
return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);
|
|
2092
2201
|
}
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
tag: getTableHeader(table)
|
|
2097
|
-
});
|
|
2098
|
-
}
|
|
2099
|
-
return noop;
|
|
2202
|
+
if (isBlob(resource)) {
|
|
2203
|
+
const blob = resource;
|
|
2204
|
+
return blob.type || "";
|
|
2100
2205
|
}
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
logLevel,
|
|
2104
|
-
priority,
|
|
2105
|
-
image,
|
|
2106
|
-
message = "",
|
|
2107
|
-
scale = 1
|
|
2108
|
-
} = _ref;
|
|
2109
|
-
if (!this._shouldLog(logLevel || priority)) {
|
|
2110
|
-
return noop;
|
|
2111
|
-
}
|
|
2112
|
-
return isBrowser3() ? logImageInBrowser({
|
|
2113
|
-
image,
|
|
2114
|
-
message,
|
|
2115
|
-
scale
|
|
2116
|
-
}) : logImageInNode({
|
|
2117
|
-
image,
|
|
2118
|
-
message,
|
|
2119
|
-
scale
|
|
2120
|
-
});
|
|
2206
|
+
if (typeof resource === "string") {
|
|
2207
|
+
return parseMIMETypeFromURL(resource);
|
|
2121
2208
|
}
|
|
2122
|
-
|
|
2123
|
-
|
|
2209
|
+
return "";
|
|
2210
|
+
}
|
|
2211
|
+
function getResourceContentLength(resource) {
|
|
2212
|
+
if (isResponse(resource)) {
|
|
2213
|
+
const response = resource;
|
|
2214
|
+
return response.headers["content-length"] || -1;
|
|
2124
2215
|
}
|
|
2125
|
-
|
|
2126
|
-
|
|
2216
|
+
if (isBlob(resource)) {
|
|
2217
|
+
const blob = resource;
|
|
2218
|
+
return blob.size;
|
|
2127
2219
|
}
|
|
2128
|
-
|
|
2129
|
-
return
|
|
2220
|
+
if (typeof resource === "string") {
|
|
2221
|
+
return resource.length;
|
|
2130
2222
|
}
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
collapsed: false
|
|
2134
|
-
};
|
|
2135
|
-
const options = normalizeArguments({
|
|
2136
|
-
logLevel,
|
|
2137
|
-
message,
|
|
2138
|
-
opts
|
|
2139
|
-
});
|
|
2140
|
-
const {
|
|
2141
|
-
collapsed
|
|
2142
|
-
} = opts;
|
|
2143
|
-
options.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
|
|
2144
|
-
return this._getLogFunction(options);
|
|
2223
|
+
if (resource instanceof ArrayBuffer) {
|
|
2224
|
+
return resource.byteLength;
|
|
2145
2225
|
}
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
return this.group(logLevel, message, Object.assign({}, opts, {
|
|
2149
|
-
collapsed: true
|
|
2150
|
-
}));
|
|
2226
|
+
if (ArrayBuffer.isView(resource)) {
|
|
2227
|
+
return resource.byteLength;
|
|
2151
2228
|
}
|
|
2152
|
-
|
|
2153
|
-
|
|
2229
|
+
return -1;
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
// src/lib/utils/response-utils.ts
|
|
2233
|
+
async function makeResponse(resource) {
|
|
2234
|
+
if (isResponse(resource)) {
|
|
2235
|
+
return resource;
|
|
2154
2236
|
}
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
} finally {
|
|
2160
|
-
this.groupEnd(logLevel)();
|
|
2161
|
-
}
|
|
2237
|
+
const headers = {};
|
|
2238
|
+
const contentLength = getResourceContentLength(resource);
|
|
2239
|
+
if (contentLength >= 0) {
|
|
2240
|
+
headers["content-length"] = String(contentLength);
|
|
2162
2241
|
}
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2242
|
+
const url = getResourceUrl(resource);
|
|
2243
|
+
const type = getResourceMIMEType(resource);
|
|
2244
|
+
if (type) {
|
|
2245
|
+
headers["content-type"] = type;
|
|
2167
2246
|
}
|
|
2168
|
-
|
|
2169
|
-
|
|
2247
|
+
const initialDataUrl = await getInitialDataUrl(resource);
|
|
2248
|
+
if (initialDataUrl) {
|
|
2249
|
+
headers["x-first-bytes"] = initialDataUrl;
|
|
2170
2250
|
}
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
opts = normalizeArguments({
|
|
2174
|
-
logLevel,
|
|
2175
|
-
message,
|
|
2176
|
-
args,
|
|
2177
|
-
opts
|
|
2178
|
-
});
|
|
2179
|
-
method = method || opts.method;
|
|
2180
|
-
assert3(method);
|
|
2181
|
-
opts.total = this.getTotal();
|
|
2182
|
-
opts.delta = this.getDelta();
|
|
2183
|
-
this._deltaTs = getHiResTimestamp2();
|
|
2184
|
-
const tag = opts.tag || opts.message;
|
|
2185
|
-
if (opts.once && tag) {
|
|
2186
|
-
if (!cache[tag]) {
|
|
2187
|
-
cache[tag] = getHiResTimestamp2();
|
|
2188
|
-
} else {
|
|
2189
|
-
return noop;
|
|
2190
|
-
}
|
|
2191
|
-
}
|
|
2192
|
-
message = decorateMessage(this.id, opts.message, opts);
|
|
2193
|
-
return method.bind(console, message, ...opts.args);
|
|
2194
|
-
}
|
|
2195
|
-
return noop;
|
|
2251
|
+
if (typeof resource === "string") {
|
|
2252
|
+
resource = new TextEncoder().encode(resource);
|
|
2196
2253
|
}
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2254
|
+
const response = new Response(resource, { headers });
|
|
2255
|
+
Object.defineProperty(response, "url", { value: url });
|
|
2256
|
+
return response;
|
|
2257
|
+
}
|
|
2258
|
+
async function checkResponse(response) {
|
|
2259
|
+
if (!response.ok) {
|
|
2260
|
+
const error = await getResponseError(response);
|
|
2261
|
+
throw error;
|
|
2202
2262
|
}
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2263
|
+
}
|
|
2264
|
+
async function getResponseError(response) {
|
|
2265
|
+
const shortUrl = shortenUrlForDisplay(response.url);
|
|
2266
|
+
let message = `Failed to fetch resource (${response.status}) ${response.statusText}: ${shortUrl}`;
|
|
2267
|
+
message = message.length > 100 ? `${message.slice(0, 100)}...` : message;
|
|
2268
|
+
const info = {
|
|
2269
|
+
reason: response.statusText,
|
|
2270
|
+
url: response.url,
|
|
2271
|
+
response
|
|
2272
|
+
};
|
|
2273
|
+
try {
|
|
2274
|
+
const contentType = response.headers.get("Content-Type");
|
|
2275
|
+
info.reason = contentType?.includes("application/json") ? await response.json() : response.text();
|
|
2276
|
+
} catch (error) {
|
|
2213
2277
|
}
|
|
2214
|
-
|
|
2215
|
-
return resolvedLevel;
|
|
2278
|
+
return new FetchError(message, info);
|
|
2216
2279
|
}
|
|
2217
|
-
function
|
|
2218
|
-
const
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
} = opts;
|
|
2222
|
-
opts.logLevel = normalizeLogLevel(logLevel);
|
|
2223
|
-
const args = opts.args ? Array.from(opts.args) : [];
|
|
2224
|
-
while (args.length && args.shift() !== message) {
|
|
2280
|
+
async function getInitialDataUrl(resource) {
|
|
2281
|
+
const INITIAL_DATA_LENGTH = 5;
|
|
2282
|
+
if (typeof resource === "string") {
|
|
2283
|
+
return `data:,${resource.slice(0, INITIAL_DATA_LENGTH)}`;
|
|
2225
2284
|
}
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
break;
|
|
2234
|
-
case "object":
|
|
2235
|
-
Object.assign(opts, logLevel);
|
|
2236
|
-
break;
|
|
2237
|
-
default:
|
|
2285
|
+
if (resource instanceof Blob) {
|
|
2286
|
+
const blobSlice = resource.slice(0, 5);
|
|
2287
|
+
return await new Promise((resolve2) => {
|
|
2288
|
+
const reader = new FileReader();
|
|
2289
|
+
reader.onload = (event) => resolve2(event?.target?.result);
|
|
2290
|
+
reader.readAsDataURL(blobSlice);
|
|
2291
|
+
});
|
|
2238
2292
|
}
|
|
2239
|
-
if (
|
|
2240
|
-
|
|
2293
|
+
if (resource instanceof ArrayBuffer) {
|
|
2294
|
+
const slice = resource.slice(0, INITIAL_DATA_LENGTH);
|
|
2295
|
+
const base64 = arrayBufferToBase64(slice);
|
|
2296
|
+
return `data:base64,${base64}`;
|
|
2241
2297
|
}
|
|
2242
|
-
|
|
2243
|
-
assert3(messageType === "string" || messageType === "object");
|
|
2244
|
-
return Object.assign(opts, {
|
|
2245
|
-
args
|
|
2246
|
-
}, opts.opts);
|
|
2298
|
+
return null;
|
|
2247
2299
|
}
|
|
2248
|
-
function
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2300
|
+
function arrayBufferToBase64(buffer) {
|
|
2301
|
+
let binary = "";
|
|
2302
|
+
const bytes = new Uint8Array(buffer);
|
|
2303
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
2304
|
+
binary += String.fromCharCode(bytes[i]);
|
|
2253
2305
|
}
|
|
2254
|
-
return
|
|
2306
|
+
return btoa(binary);
|
|
2255
2307
|
}
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
scale = 1
|
|
2261
|
-
} = _ref2;
|
|
2262
|
-
console.warn("removed");
|
|
2263
|
-
return noop;
|
|
2308
|
+
|
|
2309
|
+
// src/lib/fetch/fetch-file.ts
|
|
2310
|
+
function isNodePath(url) {
|
|
2311
|
+
return !isRequestURL(url) && !isDataURL(url);
|
|
2264
2312
|
}
|
|
2265
|
-
function
|
|
2266
|
-
|
|
2267
|
-
image,
|
|
2268
|
-
message = "",
|
|
2269
|
-
scale = 1
|
|
2270
|
-
} = _ref3;
|
|
2271
|
-
if (typeof image === "string") {
|
|
2272
|
-
const img = new Image();
|
|
2273
|
-
img.onload = () => {
|
|
2274
|
-
const args = formatImage(img, message, scale);
|
|
2275
|
-
console.log(...args);
|
|
2276
|
-
};
|
|
2277
|
-
img.src = image;
|
|
2278
|
-
return noop;
|
|
2279
|
-
}
|
|
2280
|
-
const element = image.nodeName || "";
|
|
2281
|
-
if (element.toLowerCase() === "img") {
|
|
2282
|
-
console.log(...formatImage(image, message, scale));
|
|
2283
|
-
return noop;
|
|
2284
|
-
}
|
|
2285
|
-
if (element.toLowerCase() === "canvas") {
|
|
2286
|
-
const img = new Image();
|
|
2287
|
-
img.onload = () => console.log(...formatImage(img, message, scale));
|
|
2288
|
-
img.src = image.toDataURL();
|
|
2289
|
-
return noop;
|
|
2290
|
-
}
|
|
2291
|
-
return noop;
|
|
2313
|
+
function isRequestURL(url) {
|
|
2314
|
+
return url.startsWith("http:") || url.startsWith("https:");
|
|
2292
2315
|
}
|
|
2293
|
-
function
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2316
|
+
function isDataURL(url) {
|
|
2317
|
+
return url.startsWith("data:");
|
|
2318
|
+
}
|
|
2319
|
+
async function fetchFile(urlOrData, fetchOptions) {
|
|
2320
|
+
if (typeof urlOrData === "string") {
|
|
2321
|
+
const url = resolvePath(urlOrData);
|
|
2322
|
+
if (isNodePath(url)) {
|
|
2323
|
+
if (globalThis.loaders?.fetchNode) {
|
|
2324
|
+
return globalThis.loaders?.fetchNode(url, fetchOptions);
|
|
2325
|
+
}
|
|
2297
2326
|
}
|
|
2327
|
+
return await fetch(url, fetchOptions);
|
|
2298
2328
|
}
|
|
2299
|
-
return
|
|
2329
|
+
return await makeResponse(urlOrData);
|
|
2300
2330
|
}
|
|
2301
2331
|
|
|
2302
|
-
//
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2332
|
+
// src/lib/fetch/read-array-buffer.ts
|
|
2333
|
+
async function readArrayBuffer(file, start, length) {
|
|
2334
|
+
if (!(file instanceof Blob)) {
|
|
2335
|
+
file = new Blob([file]);
|
|
2336
|
+
}
|
|
2337
|
+
const slice = file.slice(start, start + length);
|
|
2338
|
+
return await readBlob(slice);
|
|
2339
|
+
}
|
|
2340
|
+
async function readBlob(blob) {
|
|
2341
|
+
return await new Promise((resolve2, reject) => {
|
|
2342
|
+
const fileReader = new FileReader();
|
|
2343
|
+
fileReader.onload = (event) => resolve2(event?.target?.result);
|
|
2344
|
+
fileReader.onerror = (error) => reject(error);
|
|
2345
|
+
fileReader.readAsArrayBuffer(blob);
|
|
2346
|
+
});
|
|
2347
|
+
}
|
|
2306
2348
|
|
|
2307
2349
|
// src/lib/loader-utils/loggers.ts
|
|
2308
2350
|
var probeLog = new Log({ id: "loaders.gl" });
|
|
@@ -2410,6 +2452,7 @@ var __exports__ = (() => {
|
|
|
2410
2452
|
const state = getGlobalLoaderState();
|
|
2411
2453
|
const globalOptions = getGlobalLoaderOptions();
|
|
2412
2454
|
state.globalOptions = normalizeOptionsInternal(globalOptions, options);
|
|
2455
|
+
registerJSModules(options.modules);
|
|
2413
2456
|
}
|
|
2414
2457
|
function normalizeOptions(options, loader, loaders, url) {
|
|
2415
2458
|
loaders = loaders || [];
|
|
@@ -2662,10 +2705,10 @@ var __exports__ = (() => {
|
|
|
2662
2705
|
}
|
|
2663
2706
|
function findLoaderByMIMEType(loaders, mimeType) {
|
|
2664
2707
|
for (const loader of loaders) {
|
|
2665
|
-
if (loader.mimeTypes
|
|
2708
|
+
if (loader.mimeTypes?.some((mimeType1) => compareMIMETypes(mimeType, mimeType1))) {
|
|
2666
2709
|
return loader;
|
|
2667
2710
|
}
|
|
2668
|
-
if (mimeType
|
|
2711
|
+
if (compareMIMETypes(mimeType, `application/x.${loader.id}`)) {
|
|
2669
2712
|
return loader;
|
|
2670
2713
|
}
|
|
2671
2714
|
}
|
|
@@ -3024,7 +3067,7 @@ var __exports__ = (() => {
|
|
|
3024
3067
|
if (loaderWithParser.parse) {
|
|
3025
3068
|
return await loaderWithParser.parse(data, options, context);
|
|
3026
3069
|
}
|
|
3027
|
-
|
|
3070
|
+
assert3(!loaderWithParser.parseSync);
|
|
3028
3071
|
throw new Error(`${loader.id} loader - no parser found and worker is disabled`);
|
|
3029
3072
|
}
|
|
3030
3073
|
|
|
@@ -3405,6 +3448,8 @@ var __exports__ = (() => {
|
|
|
3405
3448
|
// src/null-loader.ts
|
|
3406
3449
|
var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
3407
3450
|
var NullWorkerLoader = {
|
|
3451
|
+
dataType: null,
|
|
3452
|
+
batchType: null,
|
|
3408
3453
|
name: "Null loader",
|
|
3409
3454
|
id: "null",
|
|
3410
3455
|
module: "core",
|
|
@@ -3418,6 +3463,8 @@ var __exports__ = (() => {
|
|
|
3418
3463
|
}
|
|
3419
3464
|
};
|
|
3420
3465
|
var NullLoader = {
|
|
3466
|
+
dataType: null,
|
|
3467
|
+
batchType: null,
|
|
3421
3468
|
name: "Null loader",
|
|
3422
3469
|
id: "null",
|
|
3423
3470
|
module: "core",
|