@loaders.gl/core 5.0.0-beta.1 → 5.0.0-beta.4
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/README.md +3 -1
- package/dist/cluster-source.cjs +7228 -0
- package/dist/cluster-source.cjs.map +6 -0
- package/dist/cluster-source.d.ts +2 -0
- package/dist/cluster-source.d.ts.map +1 -0
- package/dist/cluster-source.js +2 -0
- package/dist/cluster-source.js.map +1 -0
- package/dist/dist.dev.js +2141 -438
- package/dist/dist.min.js +3 -3
- package/dist/federated-table-scan-source.cjs +2677 -0
- package/dist/federated-table-scan-source.cjs.map +6 -0
- package/dist/federated-table-scan-source.d.ts +2 -0
- package/dist/federated-table-scan-source.d.ts.map +1 -0
- package/dist/federated-table-scan-source.js +2 -0
- package/dist/federated-table-scan-source.js.map +1 -0
- package/dist/index.cjs +268 -960
- package/dist/index.cjs.map +3 -3
- package/dist/lib/init.js +1 -1
- package/dist/loader-utils/index.cjs +418 -1234
- package/dist/loader-utils/index.cjs.map +3 -3
- package/dist/loader-utils/json-loader.js +1 -1
- package/dist/loader-utils/lib/log-utils/log.js +1 -1
- package/dist/loader-utils/lib/worker-loader-utils/encode-with-worker.d.ts.map +1 -1
- package/dist/loader-utils/lib/worker-loader-utils/encode-with-worker.js +2 -5
- package/dist/loader-utils/lib/worker-loader-utils/encode-with-worker.js.map +1 -1
- package/dist/loader-utils/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -1
- package/dist/loader-utils/lib/worker-loader-utils/parse-with-worker.js +14 -6
- package/dist/loader-utils/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
- package/dist/loader-utils/loader-types.d.ts +2 -2
- package/dist/loader-utils/loader-types.d.ts.map +1 -1
- package/dist/null-loader.js +1 -1
- package/dist/null-worker-node.js +538 -82
- package/dist/null-worker.js +514 -81
- package/dist/polyfills/images/encode-image-node.d.ts +18 -15
- package/dist/polyfills/images/encode-image-node.d.ts.map +1 -1
- package/dist/polyfills/images/encode-image-node.js +19 -33
- package/dist/polyfills/images/encode-image-node.js.map +1 -1
- package/dist/polyfills/images/image-codecs-node.d.ts +2 -6
- package/dist/polyfills/images/image-codecs-node.d.ts.map +1 -1
- package/dist/polyfills/images/image-codecs-node.js +2 -24
- package/dist/polyfills/images/image-codecs-node.js.map +1 -1
- package/dist/polyfills/images/load-sharp.d.ts +3 -0
- package/dist/polyfills/images/load-sharp.d.ts.map +1 -0
- package/dist/polyfills/images/load-sharp.js +11 -0
- package/dist/polyfills/images/load-sharp.js.map +1 -0
- package/dist/polyfills/images/node-image-bitmap.d.ts +1 -1
- package/dist/polyfills/images/node-image-bitmap.js +1 -1
- package/dist/polyfills/images/node-image-formats.d.ts +1 -1
- package/dist/polyfills/images/node-image-formats.d.ts.map +1 -1
- package/dist/polyfills/images/node-image-formats.js +10 -4
- package/dist/polyfills/images/node-image-formats.js.map +1 -1
- package/dist/polyfills/images/parse-image-node.d.ts +10 -2
- package/dist/polyfills/images/parse-image-node.d.ts.map +1 -1
- package/dist/polyfills/images/parse-image-node.js +20 -32
- package/dist/polyfills/images/parse-image-node.js.map +1 -1
- package/dist/polyfills/index.cjs +73 -149
- package/dist/vector-table-scan-source.cjs +1703 -0
- package/dist/vector-table-scan-source.cjs.map +6 -0
- package/dist/vector-table-scan-source.d.ts +2 -0
- package/dist/vector-table-scan-source.d.ts.map +1 -0
- package/dist/vector-table-scan-source.js +2 -0
- package/dist/vector-table-scan-source.js.map +1 -0
- package/dist/worker-utils/index.cjs +371 -1182
- package/dist/worker-utils/index.cjs.map +3 -3
- package/dist/worker-utils/index.d.ts +5 -8
- package/dist/worker-utils/index.d.ts.map +1 -1
- package/dist/worker-utils/index.js +4 -10
- package/dist/worker-utils/index.js.map +1 -1
- package/dist/worker-utils/lib/env-utils/version.js +1 -1
- package/dist/worker-utils/lib/worker-api/create-worker.d.ts +5 -7
- package/dist/worker-utils/lib/worker-api/create-worker.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-api/create-worker.js +76 -146
- package/dist/worker-utils/lib/worker-api/create-worker.js.map +1 -1
- package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts +16 -47
- package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-api/process-on-worker.js +214 -312
- package/dist/worker-utils/lib/worker-api/process-on-worker.js.map +1 -1
- package/dist/worker-utils/lib/worker-api/task-runtime.d.ts +36 -0
- package/dist/worker-utils/lib/worker-api/task-runtime.d.ts.map +1 -0
- package/dist/worker-utils/lib/worker-api/task-runtime.js +23 -0
- package/dist/worker-utils/lib/worker-api/task-runtime.js.map +1 -0
- package/dist/worker-utils/lib/worker-utils/get-transfer-list.d.ts +1 -0
- package/dist/worker-utils/lib/worker-utils/get-transfer-list.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-utils/get-transfer-list.js +3 -1
- package/dist/worker-utils/lib/worker-utils/get-transfer-list.js.map +1 -1
- package/dist/worker-utils/null-worker-node.js +603 -147
- package/dist/worker-utils/null-worker-node.js.map +4 -4
- package/dist/worker-utils/null-worker.js +576 -143
- package/dist/worker-utils/null-worker.js.map +4 -4
- package/dist/worker-utils/types.d.ts +55 -72
- package/dist/worker-utils/types.d.ts.map +1 -1
- package/package.json +27 -29
- package/src/cluster-source.ts +1 -0
- package/src/federated-table-scan-source.ts +1 -0
- package/src/loader-utils/lib/worker-loader-utils/encode-with-worker.ts +5 -6
- package/src/loader-utils/lib/worker-loader-utils/parse-with-worker.ts +14 -6
- package/src/loader-utils/loader-types.ts +2 -2
- package/src/polyfills/README.md +2 -2
- package/src/polyfills/images/encode-image-node.ts +44 -37
- package/src/polyfills/images/image-codecs-node.ts +2 -37
- package/src/polyfills/images/load-sharp.ts +13 -0
- package/src/polyfills/images/node-image-bitmap.ts +1 -1
- package/src/polyfills/images/node-image-formats.ts +10 -4
- package/src/polyfills/images/parse-image-node.ts +31 -40
- package/src/vector-table-scan-source.ts +1 -0
- package/src/worker-utils/index.ts +17 -17
- package/src/worker-utils/lib/worker-api/create-worker.ts +89 -188
- package/src/worker-utils/lib/worker-api/process-on-worker.ts +249 -403
- package/src/worker-utils/lib/worker-api/task-runtime.ts +66 -0
- package/src/worker-utils/lib/worker-utils/get-transfer-list.ts +2 -0
- package/src/worker-utils/types.ts +74 -109
- package/dist/worker-utils/lib/async-queue/async-queue.d.ts +0 -32
- package/dist/worker-utils/lib/async-queue/async-queue.d.ts.map +0 -1
- package/dist/worker-utils/lib/async-queue/async-queue.js +0 -91
- package/dist/worker-utils/lib/async-queue/async-queue.js.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-body.d.ts +0 -20
- package/dist/worker-utils/lib/worker-farm/worker-body.d.ts.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-body.js +0 -131
- package/dist/worker-utils/lib/worker-farm/worker-body.js.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-farm.d.ts +0 -58
- package/dist/worker-utils/lib/worker-farm/worker-farm.d.ts.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-farm.js +0 -116
- package/dist/worker-utils/lib/worker-farm/worker-farm.js.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-job.d.ts +0 -34
- package/dist/worker-utils/lib/worker-farm/worker-job.d.ts.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-job.js +0 -74
- package/dist/worker-utils/lib/worker-farm/worker-job.js.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-pool.d.ts +0 -94
- package/dist/worker-utils/lib/worker-farm/worker-pool.d.ts.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-pool.js +0 -246
- package/dist/worker-utils/lib/worker-farm/worker-pool.js.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-thread.d.ts +0 -67
- package/dist/worker-utils/lib/worker-farm/worker-thread.d.ts.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-thread.js +0 -175
- package/dist/worker-utils/lib/worker-farm/worker-thread.js.map +0 -1
- package/src/polyfills/images/encode-image.node.ts.disabled +0 -41
- package/src/polyfills/images/parse-image.node.ts.disabled +0 -55
- package/src/worker-utils/lib/async-queue/async-queue.ts +0 -100
- package/src/worker-utils/lib/worker-farm/worker-body.ts +0 -145
- package/src/worker-utils/lib/worker-farm/worker-farm.ts +0 -144
- package/src/worker-utils/lib/worker-farm/worker-job.ts +0 -85
- package/src/worker-utils/lib/worker-farm/worker-pool.ts +0 -316
- package/src/worker-utils/lib/worker-farm/worker-thread.ts +0 -206
package/dist/null-worker.js
CHANGED
|
@@ -1,22 +1,80 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
(() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __esm = (fn, res, err) => function __init() {
|
|
6
|
+
if (err) throw err[0];
|
|
7
|
+
try {
|
|
8
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
+
} catch (e) {
|
|
10
|
+
throw err = [e], e;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
|
|
3
18
|
// src/worker-utils/lib/node/worker_threads-browser.ts
|
|
4
|
-
var
|
|
19
|
+
var worker_threads_browser_exports = {};
|
|
20
|
+
__export(worker_threads_browser_exports, {
|
|
21
|
+
NodeWorker: () => NodeWorker,
|
|
22
|
+
parentPort: () => parentPort2
|
|
23
|
+
});
|
|
24
|
+
var NodeWorker, parentPort2;
|
|
25
|
+
var init_worker_threads_browser = __esm({
|
|
26
|
+
"src/worker-utils/lib/node/worker_threads-browser.ts"() {
|
|
27
|
+
"use strict";
|
|
28
|
+
NodeWorker = class {
|
|
29
|
+
/** Restores the native worker constructor when this browser shim is embedded in a Node bundle. */
|
|
30
|
+
constructor(...arguments_) {
|
|
31
|
+
const runtimeProcess = globalThis.process;
|
|
32
|
+
const WorkerConstructor = runtimeProcess?.getBuiltinModule?.("node:worker_threads").Worker;
|
|
33
|
+
if (WorkerConstructor) {
|
|
34
|
+
return new WorkerConstructor(...arguments_);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** No-op browser fallback matching the native Worker API. */
|
|
38
|
+
terminate() {
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
parentPort2 = null;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
5
44
|
|
|
6
|
-
//
|
|
45
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/node/worker_threads-browser.js
|
|
46
|
+
var parentPort = globalThis.process?.getBuiltinModule?.("node:worker_threads")?.parentPort ?? null;
|
|
47
|
+
|
|
48
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-utils/get-transfer-list.js
|
|
7
49
|
function getTransferList(object, recursive = true, transfers) {
|
|
8
50
|
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
51
|
+
const seen = /* @__PURE__ */ new Set();
|
|
52
|
+
function visit(value) {
|
|
53
|
+
if (!value || typeof value !== "object" || seen.has(value))
|
|
54
|
+
return;
|
|
55
|
+
seen.add(value);
|
|
56
|
+
if (isTransferable(value))
|
|
57
|
+
transfersSet.add(value);
|
|
58
|
+
else if (ArrayBuffer.isView(value)) {
|
|
59
|
+
if (isTransferable(value.buffer))
|
|
60
|
+
transfersSet.add(value.buffer);
|
|
61
|
+
} else if (recursive && typeof MessageChannel !== "undefined" && value instanceof MessageChannel) {
|
|
62
|
+
visit(value.port1);
|
|
63
|
+
visit(value.port2);
|
|
64
|
+
} else if (recursive && value instanceof Map) {
|
|
65
|
+
for (const [key, item] of value) {
|
|
66
|
+
visit(key);
|
|
67
|
+
visit(item);
|
|
68
|
+
}
|
|
69
|
+
} else if (recursive && value instanceof Set) {
|
|
70
|
+
for (const item of value)
|
|
71
|
+
visit(item);
|
|
72
|
+
} else if (recursive) {
|
|
73
|
+
for (const key of Object.keys(value))
|
|
74
|
+
visit(value[key]);
|
|
18
75
|
}
|
|
19
76
|
}
|
|
77
|
+
visit(object);
|
|
20
78
|
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
21
79
|
}
|
|
22
80
|
function isTransferable(object) {
|
|
@@ -38,7 +96,7 @@
|
|
|
38
96
|
return false;
|
|
39
97
|
}
|
|
40
98
|
|
|
41
|
-
//
|
|
99
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-farm/worker-body.js
|
|
42
100
|
async function getParentPort() {
|
|
43
101
|
return parentPort;
|
|
44
102
|
}
|
|
@@ -46,23 +104,24 @@
|
|
|
46
104
|
var WorkerBody = class {
|
|
47
105
|
/** Check that we are actually in a worker thread */
|
|
48
106
|
static async inWorkerThread() {
|
|
49
|
-
|
|
107
|
+
const workerGlobalScope = globalThis.WorkerGlobalScope;
|
|
108
|
+
return typeof workerGlobalScope === "function" && globalThis instanceof workerGlobalScope || Boolean(await getParentPort());
|
|
50
109
|
}
|
|
51
110
|
/*
|
|
52
111
|
* (type: WorkerMessageType, payload: WorkerMessagePayload) => any
|
|
53
112
|
*/
|
|
54
113
|
static set onmessage(onMessage) {
|
|
55
114
|
async function handleMessage(message) {
|
|
56
|
-
const
|
|
57
|
-
const { type, payload } =
|
|
115
|
+
const parentPort3 = await getParentPort();
|
|
116
|
+
const { type, payload } = parentPort3 ? message : message.data;
|
|
58
117
|
onMessage(type, payload);
|
|
59
118
|
}
|
|
60
|
-
getParentPort().then((
|
|
61
|
-
if (
|
|
62
|
-
|
|
119
|
+
getParentPort().then((parentPort3) => {
|
|
120
|
+
if (parentPort3) {
|
|
121
|
+
parentPort3.on("message", (message) => {
|
|
63
122
|
handleMessage(message);
|
|
64
123
|
});
|
|
65
|
-
|
|
124
|
+
parentPort3.on("exit", () => console.debug("Node worker closing"));
|
|
66
125
|
} else {
|
|
67
126
|
globalThis.onmessage = handleMessage;
|
|
68
127
|
}
|
|
@@ -80,9 +139,9 @@
|
|
|
80
139
|
};
|
|
81
140
|
onMessageWrapperMap.set(onMessage, onMessageWrapper);
|
|
82
141
|
}
|
|
83
|
-
const
|
|
84
|
-
if (
|
|
85
|
-
|
|
142
|
+
const parentPort3 = await getParentPort();
|
|
143
|
+
if (parentPort3) {
|
|
144
|
+
parentPort3.on("message", onMessageWrapper);
|
|
86
145
|
} else {
|
|
87
146
|
globalThis.addEventListener("message", onMessageWrapper);
|
|
88
147
|
}
|
|
@@ -93,9 +152,9 @@
|
|
|
93
152
|
if (!onMessageWrapper) {
|
|
94
153
|
return;
|
|
95
154
|
}
|
|
96
|
-
const
|
|
97
|
-
if (
|
|
98
|
-
|
|
155
|
+
const parentPort3 = await getParentPort();
|
|
156
|
+
if (parentPort3) {
|
|
157
|
+
parentPort3.off("message", onMessageWrapper);
|
|
99
158
|
} else {
|
|
100
159
|
globalThis.removeEventListener("message", onMessageWrapper);
|
|
101
160
|
}
|
|
@@ -105,12 +164,12 @@
|
|
|
105
164
|
* @param type
|
|
106
165
|
* @param payload
|
|
107
166
|
*/
|
|
108
|
-
static async postMessage(type, payload) {
|
|
167
|
+
static async postMessage(type, payload, copy = false) {
|
|
109
168
|
const data = { source: "loaders.gl", type, payload };
|
|
110
|
-
const transferList = getTransferList(payload);
|
|
111
|
-
const
|
|
112
|
-
if (
|
|
113
|
-
|
|
169
|
+
const transferList = copy ? [] : getTransferList(payload);
|
|
170
|
+
const parentPort3 = await getParentPort();
|
|
171
|
+
if (parentPort3) {
|
|
172
|
+
parentPort3.postMessage(data, transferList);
|
|
114
173
|
} else {
|
|
115
174
|
globalThis.postMessage(data, transferList);
|
|
116
175
|
}
|
|
@@ -124,11 +183,8 @@
|
|
|
124
183
|
return messageData && typeof messageData.source === "string" && messageData.source.startsWith("loaders.gl") ? messageData : null;
|
|
125
184
|
}
|
|
126
185
|
|
|
127
|
-
//
|
|
186
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/async-queue/async-queue.js
|
|
128
187
|
var AsyncQueue = class {
|
|
129
|
-
_values;
|
|
130
|
-
_settlers;
|
|
131
|
-
_closed;
|
|
132
188
|
constructor() {
|
|
133
189
|
this._values = [];
|
|
134
190
|
this._settlers = [];
|
|
@@ -194,11 +250,58 @@
|
|
|
194
250
|
}
|
|
195
251
|
};
|
|
196
252
|
|
|
197
|
-
//
|
|
253
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/shared-state.js
|
|
254
|
+
var SharedWorkerState = class {
|
|
255
|
+
constructor(buffer) {
|
|
256
|
+
if (typeof SharedArrayBuffer === "undefined" || !(buffer instanceof SharedArrayBuffer) || buffer.byteLength !== 16)
|
|
257
|
+
throw new Error("Expected a 16-byte shared worker control buffer");
|
|
258
|
+
this.buffer = buffer;
|
|
259
|
+
this.values = new Int32Array(buffer);
|
|
260
|
+
}
|
|
261
|
+
get snapshot() {
|
|
262
|
+
return {
|
|
263
|
+
cancelled: Atomics.load(this.values, 0) !== 0,
|
|
264
|
+
completed: Atomics.load(this.values, 1),
|
|
265
|
+
total: Atomics.load(this.values, 2),
|
|
266
|
+
revision: Atomics.load(this.values, 3)
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
cancel() {
|
|
270
|
+
Atomics.store(this.values, 0, 1);
|
|
271
|
+
Atomics.add(this.values, 3, 1);
|
|
272
|
+
Atomics.notify(this.values, 0);
|
|
273
|
+
}
|
|
274
|
+
throwIfCancelled() {
|
|
275
|
+
if (Atomics.load(this.values, 0) !== 0) {
|
|
276
|
+
const error = new Error("Shared worker task was cancelled");
|
|
277
|
+
error.name = "AbortError";
|
|
278
|
+
throw error;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/** Integer counters for application-defined work; messages still carry phase names and units. */
|
|
282
|
+
setProgress(completed, total = -1) {
|
|
283
|
+
if (!Number.isInteger(completed) || completed < 0 || completed > 2147483647 || !Number.isInteger(total) || total < -1 || total > 2147483647) {
|
|
284
|
+
throw new RangeError("Shared progress requires nonnegative int32 counts (or total -1)");
|
|
285
|
+
}
|
|
286
|
+
Atomics.store(this.values, 1, completed);
|
|
287
|
+
Atomics.store(this.values, 2, total);
|
|
288
|
+
Atomics.add(this.values, 3, 1);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/validate-output-ownership.js
|
|
293
|
+
function validateOutputOwnership(ownership) {
|
|
294
|
+
if (ownership !== void 0 && ownership !== "copy" && ownership !== "transfer") {
|
|
295
|
+
throw new Error("Invalid worker output ownership");
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/create-worker.js
|
|
198
300
|
var requestId = 0;
|
|
301
|
+
var activeController = null;
|
|
199
302
|
var activeInputBatches = null;
|
|
200
303
|
var activeOutputAcknowledgements = null;
|
|
201
|
-
async function createWorker(
|
|
304
|
+
async function createWorker(process2, processInBatches, preload) {
|
|
202
305
|
if (!await WorkerBody.inWorkerThread()) {
|
|
203
306
|
return;
|
|
204
307
|
}
|
|
@@ -206,27 +309,59 @@
|
|
|
206
309
|
process: processOnMainThread
|
|
207
310
|
};
|
|
208
311
|
WorkerBody.onmessage = async (type, payload) => {
|
|
312
|
+
if (type === "cancel") {
|
|
313
|
+
activeController?.abort();
|
|
314
|
+
activeInputBatches?.close();
|
|
315
|
+
activeOutputAcknowledgements?.close();
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const controller = type === "process" || type === "process-in-batches" ? new AbortController() : void 0;
|
|
319
|
+
if (controller)
|
|
320
|
+
activeController = controller;
|
|
321
|
+
const startedAt = performance.now();
|
|
209
322
|
const reporter = type === "process" || type === "process-in-batches" ? createProgressReporter() : void 0;
|
|
210
|
-
|
|
323
|
+
let sharedState;
|
|
324
|
+
const throwIfAborted = () => {
|
|
325
|
+
controller?.signal.throwIfAborted();
|
|
326
|
+
sharedState?.throwIfCancelled();
|
|
327
|
+
};
|
|
328
|
+
const jobContext = {
|
|
329
|
+
...context,
|
|
330
|
+
signal: controller?.signal,
|
|
331
|
+
sharedState,
|
|
332
|
+
throwIfAborted,
|
|
333
|
+
reportProgress: (progress) => {
|
|
334
|
+
if (!controller?.signal.aborted && !sharedState?.snapshot.cancelled)
|
|
335
|
+
reporter?.report(progress);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
211
338
|
try {
|
|
339
|
+
if (controller && payload.options?.["sharedState"]) {
|
|
340
|
+
sharedState = new SharedWorkerState(payload.options["sharedState"]);
|
|
341
|
+
jobContext.sharedState = sharedState;
|
|
342
|
+
}
|
|
212
343
|
switch (type) {
|
|
213
344
|
case "preload":
|
|
345
|
+
await preload?.();
|
|
214
346
|
WorkerBody.postMessage("done", {});
|
|
215
347
|
break;
|
|
216
348
|
case "process":
|
|
217
|
-
|
|
349
|
+
throwIfAborted();
|
|
350
|
+
validateOutputOwnership(payload.options?.["outputOwnership"]);
|
|
351
|
+
if (!process2) {
|
|
218
352
|
throw new Error("Worker does not support atomic processing");
|
|
219
353
|
}
|
|
220
|
-
const result = await
|
|
221
|
-
|
|
222
|
-
payload.options || {},
|
|
223
|
-
jobContext,
|
|
224
|
-
payload.context || {}
|
|
225
|
-
);
|
|
354
|
+
const result = await process2(payload.input, payload.options || {}, jobContext, payload.context || {});
|
|
355
|
+
throwIfAborted();
|
|
226
356
|
reporter?.finish();
|
|
227
|
-
WorkerBody.postMessage("done", {
|
|
357
|
+
await WorkerBody.postMessage("done", {
|
|
358
|
+
result,
|
|
359
|
+
executionMs: performance.now() - startedAt
|
|
360
|
+
}, payload.options?.["outputOwnership"] === "copy");
|
|
228
361
|
break;
|
|
229
362
|
case "process-in-batches":
|
|
363
|
+
throwIfAborted();
|
|
364
|
+
validateOutputOwnership(payload.options?.["outputOwnership"]);
|
|
230
365
|
if (!processInBatches) {
|
|
231
366
|
throw new Error("Worker does not support batched processing");
|
|
232
367
|
}
|
|
@@ -235,18 +370,15 @@
|
|
|
235
370
|
activeInputBatches = inputBatches;
|
|
236
371
|
activeOutputAcknowledgements = outputAcknowledgements;
|
|
237
372
|
try {
|
|
238
|
-
const resultIterator = processInBatches(
|
|
239
|
-
createDemandDrivenIterator(inputBatches),
|
|
240
|
-
payload.options || {},
|
|
241
|
-
jobContext,
|
|
242
|
-
payload.context || {}
|
|
243
|
-
);
|
|
373
|
+
const resultIterator = processInBatches(createDemandDrivenIterator(inputBatches), payload.options || {}, jobContext, payload.context || {});
|
|
244
374
|
for await (const batch of resultIterator) {
|
|
245
|
-
|
|
375
|
+
throwIfAborted();
|
|
376
|
+
await WorkerBody.postMessage("output-batch", { result: batch }, payload.options?.["outputOwnership"] === "copy");
|
|
246
377
|
await outputAcknowledgements.next();
|
|
247
378
|
}
|
|
379
|
+
throwIfAborted();
|
|
248
380
|
reporter?.finish();
|
|
249
|
-
await WorkerBody.postMessage("done", {});
|
|
381
|
+
await WorkerBody.postMessage("done", { executionMs: performance.now() - startedAt });
|
|
250
382
|
} finally {
|
|
251
383
|
activeInputBatches = null;
|
|
252
384
|
activeOutputAcknowledgements = null;
|
|
@@ -273,11 +405,18 @@
|
|
|
273
405
|
default:
|
|
274
406
|
}
|
|
275
407
|
} catch (error) {
|
|
276
|
-
reporter?.finish();
|
|
408
|
+
reporter?.finish(controller?.signal.aborted || sharedState?.snapshot.cancelled);
|
|
277
409
|
const message = error instanceof Error ? error.message : "";
|
|
278
|
-
WorkerBody.postMessage("error", {
|
|
410
|
+
await WorkerBody.postMessage("error", {
|
|
411
|
+
error: message,
|
|
412
|
+
errorName: error instanceof Error ? error.name : "Error"
|
|
413
|
+
});
|
|
414
|
+
} finally {
|
|
415
|
+
if (controller && activeController === controller)
|
|
416
|
+
activeController = null;
|
|
279
417
|
}
|
|
280
418
|
};
|
|
419
|
+
await WorkerBody.postMessage("ready", {});
|
|
281
420
|
}
|
|
282
421
|
async function* createDemandDrivenIterator(inputBatches) {
|
|
283
422
|
while (true) {
|
|
@@ -290,62 +429,356 @@
|
|
|
290
429
|
}
|
|
291
430
|
}
|
|
292
431
|
function processOnMainThread(arrayBuffer, options = {}, jobContext = {}) {
|
|
432
|
+
const signal = activeController?.signal;
|
|
433
|
+
signal?.throwIfAborted();
|
|
293
434
|
return new Promise((resolve, reject) => {
|
|
294
435
|
const id = requestId++;
|
|
295
|
-
const
|
|
296
|
-
|
|
436
|
+
const cleanup = () => {
|
|
437
|
+
signal?.removeEventListener("abort", abort);
|
|
438
|
+
void WorkerBody.removeEventListener(onMessage);
|
|
439
|
+
};
|
|
440
|
+
const abort = () => {
|
|
441
|
+
cleanup();
|
|
442
|
+
reject(signal?.reason);
|
|
443
|
+
};
|
|
444
|
+
const onMessage = (type, payload) => {
|
|
445
|
+
if (payload.id !== id)
|
|
297
446
|
return;
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
case "error":
|
|
305
|
-
WorkerBody.removeEventListener(onMessage);
|
|
306
|
-
reject(payload2.error);
|
|
307
|
-
break;
|
|
308
|
-
default:
|
|
447
|
+
if (type === "done") {
|
|
448
|
+
cleanup();
|
|
449
|
+
resolve(payload.result);
|
|
450
|
+
} else if (type === "error") {
|
|
451
|
+
cleanup();
|
|
452
|
+
reject(payload.error);
|
|
309
453
|
}
|
|
310
454
|
};
|
|
311
|
-
WorkerBody.addEventListener(onMessage)
|
|
312
|
-
|
|
313
|
-
|
|
455
|
+
void WorkerBody.addEventListener(onMessage).then(async () => {
|
|
456
|
+
if (signal?.aborted) {
|
|
457
|
+
abort();
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
461
|
+
await WorkerBody.postMessage("process", {
|
|
462
|
+
id,
|
|
463
|
+
input: arrayBuffer,
|
|
464
|
+
options,
|
|
465
|
+
context: jobContext
|
|
466
|
+
});
|
|
467
|
+
}).catch((error) => {
|
|
468
|
+
cleanup();
|
|
469
|
+
reject(error);
|
|
470
|
+
});
|
|
314
471
|
});
|
|
315
472
|
}
|
|
316
473
|
function createProgressReporter() {
|
|
317
|
-
let
|
|
474
|
+
let pending2;
|
|
318
475
|
let finished = false;
|
|
319
476
|
let scheduled = false;
|
|
320
477
|
const flush = () => {
|
|
321
478
|
scheduled = false;
|
|
322
|
-
if (
|
|
323
|
-
WorkerBody.postMessage("progress", { progress:
|
|
324
|
-
|
|
479
|
+
if (pending2) {
|
|
480
|
+
WorkerBody.postMessage("progress", { progress: pending2 });
|
|
481
|
+
pending2 = void 0;
|
|
325
482
|
}
|
|
326
483
|
};
|
|
327
484
|
return {
|
|
328
485
|
/** Records progress while retaining phase transitions. */
|
|
329
486
|
report(progress) {
|
|
330
|
-
if (finished)
|
|
331
|
-
|
|
332
|
-
|
|
487
|
+
if (finished)
|
|
488
|
+
return;
|
|
489
|
+
if (pending2 && pending2.phase !== progress.phase)
|
|
490
|
+
flush();
|
|
491
|
+
pending2 = { ...progress };
|
|
333
492
|
if (!scheduled) {
|
|
334
493
|
scheduled = true;
|
|
335
494
|
setTimeout(flush, 0);
|
|
336
495
|
}
|
|
337
496
|
},
|
|
338
497
|
/** Flushes final progress and suppresses reports from stale callbacks. */
|
|
339
|
-
finish() {
|
|
498
|
+
finish(discard = false) {
|
|
499
|
+
if (discard)
|
|
500
|
+
pending2 = void 0;
|
|
340
501
|
flush();
|
|
341
502
|
finished = true;
|
|
342
503
|
}
|
|
343
504
|
};
|
|
344
505
|
}
|
|
345
506
|
|
|
507
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/index.js
|
|
508
|
+
var import_meta = {};
|
|
509
|
+
var path = typeof __filename === "string" ? __filename.replace(/\\/g, "/") : "";
|
|
510
|
+
var moduleUrl = path ? `file://${path.startsWith("/") ? "" : "/"}${encodeURI(path).replace(/#/g, "%23").replace(/\?/g, "%3F")}` : import_meta.url;
|
|
511
|
+
|
|
512
|
+
// ../../node_modules/@math.gl/core/dist/tasks/task-preload.js
|
|
513
|
+
var pending = /* @__PURE__ */ new WeakMap();
|
|
514
|
+
var loaded = /* @__PURE__ */ new WeakSet();
|
|
515
|
+
function preloadTaskCode(task, signal) {
|
|
516
|
+
if (!task.preload)
|
|
517
|
+
return Promise.resolve();
|
|
518
|
+
let promise = pending.get(task);
|
|
519
|
+
if (!promise) {
|
|
520
|
+
promise = Promise.resolve().then(() => task.preload()).then(() => {
|
|
521
|
+
loaded.add(task);
|
|
522
|
+
});
|
|
523
|
+
pending.set(task, promise);
|
|
524
|
+
void promise.catch(() => pending.delete(task));
|
|
525
|
+
}
|
|
526
|
+
return withSignal(promise, signal);
|
|
527
|
+
}
|
|
528
|
+
function withSignal(operation, signal) {
|
|
529
|
+
if (!signal)
|
|
530
|
+
return operation;
|
|
531
|
+
return new Promise((resolve, reject) => {
|
|
532
|
+
const abort = () => {
|
|
533
|
+
signal.removeEventListener("abort", abort);
|
|
534
|
+
reject(signal.reason);
|
|
535
|
+
};
|
|
536
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
537
|
+
if (signal.aborted)
|
|
538
|
+
abort();
|
|
539
|
+
operation.then((value) => {
|
|
540
|
+
signal.removeEventListener("abort", abort);
|
|
541
|
+
resolve(value);
|
|
542
|
+
}, (error) => {
|
|
543
|
+
signal.removeEventListener("abort", abort);
|
|
544
|
+
reject(error);
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// ../../node_modules/@math.gl/core/dist/tasks/task-runtime.js
|
|
550
|
+
function assertPayload(value) {
|
|
551
|
+
if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) {
|
|
552
|
+
throw new TypeError("Task payloads must be plain objects with named fields");
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
function taskContext(state, context = {}) {
|
|
556
|
+
const signal = context.signal ?? new AbortController().signal;
|
|
557
|
+
return {
|
|
558
|
+
state,
|
|
559
|
+
signal,
|
|
560
|
+
throwIfAborted: () => {
|
|
561
|
+
signal.throwIfAborted();
|
|
562
|
+
context.throwIfAborted?.();
|
|
563
|
+
},
|
|
564
|
+
reportProgress: (progress) => context.reportProgress?.({
|
|
565
|
+
...progress,
|
|
566
|
+
phase: progress.phase ?? "process",
|
|
567
|
+
unit: progress.unit ?? "items"
|
|
568
|
+
})
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
var TaskRuntime = class {
|
|
572
|
+
constructor(task) {
|
|
573
|
+
this.task = task;
|
|
574
|
+
this.initialized = false;
|
|
575
|
+
}
|
|
576
|
+
async initialize(input, context = {}) {
|
|
577
|
+
if (this.initialized)
|
|
578
|
+
throw new Error("Task is already initialized");
|
|
579
|
+
assertPayload(input);
|
|
580
|
+
await preloadTaskCode(this.task, context.signal);
|
|
581
|
+
context.signal?.throwIfAborted();
|
|
582
|
+
this.state = await this.task.initialize?.(input, taskContext(void 0, context));
|
|
583
|
+
this.initialized = true;
|
|
584
|
+
return {};
|
|
585
|
+
}
|
|
586
|
+
async destroy() {
|
|
587
|
+
if (this.initialized) {
|
|
588
|
+
this.initialized = false;
|
|
589
|
+
const state = this.state;
|
|
590
|
+
this.state = void 0;
|
|
591
|
+
if (this.task.initialize)
|
|
592
|
+
await this.task.destroy?.(state);
|
|
593
|
+
}
|
|
594
|
+
return {};
|
|
595
|
+
}
|
|
596
|
+
async process(input, options, context = {}) {
|
|
597
|
+
if (!this.initialized)
|
|
598
|
+
throw new Error("Task is not initialized");
|
|
599
|
+
if (!this.task.process)
|
|
600
|
+
throw new Error("Task has no atomic processor");
|
|
601
|
+
assertPayload(input);
|
|
602
|
+
const result = await this.task.process(input, options, taskContext(this.state, context));
|
|
603
|
+
assertPayload(result);
|
|
604
|
+
return result;
|
|
605
|
+
}
|
|
606
|
+
async *stream(inputs, options, context = {}) {
|
|
607
|
+
if (!this.initialized)
|
|
608
|
+
throw new Error("Task is not initialized");
|
|
609
|
+
if (!this.task.processInBatches)
|
|
610
|
+
throw new Error("Task has no streaming processor");
|
|
611
|
+
for await (const output of this.task.processInBatches(inputs, options, taskContext(this.state, context))) {
|
|
612
|
+
assertPayload(output);
|
|
613
|
+
yield output;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
async function initializeTaskWorker(task) {
|
|
618
|
+
if (!await WorkerBody.inWorkerThread())
|
|
619
|
+
throw new Error("initializeTaskWorker must run inside a worker");
|
|
620
|
+
if (installed)
|
|
621
|
+
throw new Error("A task is already installed in this worker");
|
|
622
|
+
installed = true;
|
|
623
|
+
const runtime = new TaskRuntime(task);
|
|
624
|
+
let streamOptions = {};
|
|
625
|
+
return createWorker(async (request, _options, context) => {
|
|
626
|
+
switch (request.operation) {
|
|
627
|
+
case "initialize":
|
|
628
|
+
return runtime.initialize(request.input, context);
|
|
629
|
+
case "destroy":
|
|
630
|
+
return runtime.destroy();
|
|
631
|
+
case "stream-options":
|
|
632
|
+
streamOptions = request.options;
|
|
633
|
+
return {};
|
|
634
|
+
case "process":
|
|
635
|
+
return runtime.process(request.input, request.options, context);
|
|
636
|
+
default:
|
|
637
|
+
throw new Error("Unknown task operation");
|
|
638
|
+
}
|
|
639
|
+
}, async function* (inputs, _options, context) {
|
|
640
|
+
async function* batches() {
|
|
641
|
+
for await (const input of inputs) {
|
|
642
|
+
assertPayload(input);
|
|
643
|
+
yield input;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
try {
|
|
647
|
+
yield* runtime.stream(batches(), streamOptions, context);
|
|
648
|
+
} finally {
|
|
649
|
+
streamOptions = {};
|
|
650
|
+
}
|
|
651
|
+
}, () => preloadTaskCode(task));
|
|
652
|
+
}
|
|
653
|
+
var installed = false;
|
|
654
|
+
|
|
655
|
+
// src/worker-utils/lib/worker-api/task-runtime.ts
|
|
656
|
+
function normalizeTaskProgress(progress) {
|
|
657
|
+
return { ...progress, phase: progress.phase ?? "process", unit: progress.unit ?? "items" };
|
|
658
|
+
}
|
|
659
|
+
async function isWorkerThread() {
|
|
660
|
+
if (typeof self !== "undefined" && typeof document === "undefined" && typeof self.postMessage === "function")
|
|
661
|
+
return true;
|
|
662
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
663
|
+
const { isMainThread } = await Promise.resolve().then(() => (init_worker_threads_browser(), worker_threads_browser_exports));
|
|
664
|
+
return !isMainThread;
|
|
665
|
+
}
|
|
666
|
+
return false;
|
|
667
|
+
}
|
|
668
|
+
var initializeTaskWorker2 = initializeTaskWorker;
|
|
669
|
+
|
|
670
|
+
// src/worker-utils/lib/worker-utils/get-transfer-list.ts
|
|
671
|
+
function getTransferList2(object, recursive = true, transfers) {
|
|
672
|
+
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
673
|
+
if (!object) {
|
|
674
|
+
} else if (isTransferable2(object)) {
|
|
675
|
+
transfersSet.add(object);
|
|
676
|
+
} else if (isTransferable2(object.buffer)) {
|
|
677
|
+
transfersSet.add(object.buffer);
|
|
678
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
679
|
+
} else if (recursive && typeof object === "object") {
|
|
680
|
+
for (const key in object) {
|
|
681
|
+
getTransferList2(object[key], recursive, transfersSet);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
685
|
+
}
|
|
686
|
+
function isTransferable2(object) {
|
|
687
|
+
if (!object) {
|
|
688
|
+
return false;
|
|
689
|
+
}
|
|
690
|
+
if (object instanceof ArrayBuffer) {
|
|
691
|
+
return true;
|
|
692
|
+
}
|
|
693
|
+
if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
|
|
694
|
+
return true;
|
|
695
|
+
}
|
|
696
|
+
if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
|
|
697
|
+
return true;
|
|
698
|
+
}
|
|
699
|
+
if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
|
|
700
|
+
return true;
|
|
701
|
+
}
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// src/worker-utils/lib/worker-api/create-worker.ts
|
|
706
|
+
async function createWorker2(process2, processInBatches) {
|
|
707
|
+
if (!await isWorkerThread()) return;
|
|
708
|
+
await initializeTaskWorker2(createWorkerTask(process2, processInBatches));
|
|
709
|
+
}
|
|
710
|
+
function createWorkerTask(process2, processInBatches) {
|
|
711
|
+
return {
|
|
712
|
+
id: "loaders.gl",
|
|
713
|
+
initialize: (state) => state,
|
|
714
|
+
destroy: (state) => state.port?.close(),
|
|
715
|
+
process: async ({ value }, options, context) => {
|
|
716
|
+
if (!process2) throw new Error("Worker does not support atomic processing");
|
|
717
|
+
return { value: await process2(value, options, createContext(context), context.state.context) };
|
|
718
|
+
},
|
|
719
|
+
...processInBatches ? {
|
|
720
|
+
processInBatches: async function* (inputs, options, context) {
|
|
721
|
+
async function* values() {
|
|
722
|
+
for await (const input of inputs) yield input.value;
|
|
723
|
+
}
|
|
724
|
+
for await (const value of processInBatches(
|
|
725
|
+
values(),
|
|
726
|
+
options,
|
|
727
|
+
createContext(context),
|
|
728
|
+
context.state.context
|
|
729
|
+
)) {
|
|
730
|
+
yield { value };
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
} : {}
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
function createContext(context) {
|
|
737
|
+
let requestIdentifier = 0;
|
|
738
|
+
const port = context.state.port;
|
|
739
|
+
return {
|
|
740
|
+
signal: context.signal,
|
|
741
|
+
throwIfAborted: () => context.throwIfAborted(),
|
|
742
|
+
reportProgress: (progress) => context.reportProgress(normalizeTaskProgress(progress)),
|
|
743
|
+
process: port ? (input, options = {}, jobContext = {}) => {
|
|
744
|
+
context.throwIfAborted();
|
|
745
|
+
const identifier = ++requestIdentifier;
|
|
746
|
+
return new Promise((resolve, reject) => {
|
|
747
|
+
const onMessage = (event) => {
|
|
748
|
+
if (event.data.identifier !== identifier) return;
|
|
749
|
+
cleanup();
|
|
750
|
+
if (event.data.error) {
|
|
751
|
+
const error = new Error(event.data.error.message);
|
|
752
|
+
error.name = event.data.error.name;
|
|
753
|
+
reject(error);
|
|
754
|
+
} else resolve(event.data.value);
|
|
755
|
+
};
|
|
756
|
+
const onAbort = () => {
|
|
757
|
+
cleanup();
|
|
758
|
+
reject(context.signal.reason);
|
|
759
|
+
};
|
|
760
|
+
const cleanup = () => {
|
|
761
|
+
port.removeEventListener("message", onMessage);
|
|
762
|
+
context.signal.removeEventListener("abort", onAbort);
|
|
763
|
+
};
|
|
764
|
+
port.addEventListener("message", onMessage);
|
|
765
|
+
context.signal.addEventListener("abort", onAbort, { once: true });
|
|
766
|
+
port.start();
|
|
767
|
+
try {
|
|
768
|
+
const request = { identifier, input, options, context: jobContext };
|
|
769
|
+
port.postMessage(request, getTransferList2(request));
|
|
770
|
+
} catch (error) {
|
|
771
|
+
cleanup();
|
|
772
|
+
reject(error);
|
|
773
|
+
}
|
|
774
|
+
});
|
|
775
|
+
} : void 0
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
|
|
346
779
|
// src/loader-utils/lib/worker-loader-utils/create-loader-worker.ts
|
|
347
780
|
async function createLoaderWorker(loader, selectLoader = () => loader) {
|
|
348
|
-
await
|
|
781
|
+
await createWorker2(
|
|
349
782
|
(input, options, workerContext, loaderContext) => processLoaderWorkerData(
|
|
350
783
|
selectLoader(options || {}),
|
|
351
784
|
input,
|
|
@@ -482,7 +915,7 @@
|
|
|
482
915
|
}
|
|
483
916
|
|
|
484
917
|
// src/null-loader.ts
|
|
485
|
-
var VERSION = true ? "5.0.0-beta.
|
|
918
|
+
var VERSION = true ? "5.0.0-beta.4" : "latest";
|
|
486
919
|
var NullLoader = {
|
|
487
920
|
dataType: null,
|
|
488
921
|
batchType: null,
|