@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
|
@@ -5,6 +5,18 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res, err) => function __init() {
|
|
9
|
+
if (err) throw err[0];
|
|
10
|
+
try {
|
|
11
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
throw err = [e], e;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
8
20
|
var __copyProps = (to, from, except, desc) => {
|
|
9
21
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
22
|
for (let key of __getOwnPropNames(from))
|
|
@@ -22,90 +34,82 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
34
|
mod
|
|
23
35
|
));
|
|
24
36
|
|
|
25
|
-
// src/worker-utils/lib/
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
/** Indicate that we not waiting for more values - The async iterator will be done */
|
|
66
|
-
close() {
|
|
67
|
-
while (this._settlers.length > 0) {
|
|
68
|
-
const settler = this._settlers.shift();
|
|
69
|
-
settler.resolve({ done: true });
|
|
70
|
-
}
|
|
71
|
-
this._closed = true;
|
|
72
|
-
}
|
|
73
|
-
// ITERATOR IMPLEMENTATION
|
|
74
|
-
/** @returns a Promise for an IteratorResult */
|
|
75
|
-
next() {
|
|
76
|
-
if (this._values.length > 0) {
|
|
77
|
-
const value = this._values.shift();
|
|
78
|
-
if (value instanceof Error) {
|
|
79
|
-
return Promise.reject(value);
|
|
80
|
-
}
|
|
81
|
-
return Promise.resolve({ done: false, value });
|
|
82
|
-
}
|
|
83
|
-
if (this._closed) {
|
|
84
|
-
if (this._settlers.length > 0) {
|
|
85
|
-
throw new Error("Illegal internal state");
|
|
86
|
-
}
|
|
87
|
-
return Promise.resolve({ done: true, value: void 0 });
|
|
88
|
-
}
|
|
89
|
-
return new Promise((resolve, reject) => {
|
|
90
|
-
this._settlers.push({ resolve, reject });
|
|
91
|
-
});
|
|
37
|
+
// src/worker-utils/lib/node/worker_threads.ts
|
|
38
|
+
var worker_threads_exports = {};
|
|
39
|
+
__export(worker_threads_exports, {
|
|
40
|
+
BroadcastChannel: () => import_worker_threads3.BroadcastChannel,
|
|
41
|
+
MessageChannel: () => import_worker_threads3.MessageChannel,
|
|
42
|
+
MessagePort: () => import_worker_threads3.MessagePort,
|
|
43
|
+
NodeWorker: () => NodeWorker,
|
|
44
|
+
SHARE_ENV: () => import_worker_threads3.SHARE_ENV,
|
|
45
|
+
Worker: () => import_worker_threads3.Worker,
|
|
46
|
+
getEnvironmentData: () => import_worker_threads3.getEnvironmentData,
|
|
47
|
+
isInternalThread: () => isInternalThread2,
|
|
48
|
+
isMainThread: () => import_worker_threads3.isMainThread,
|
|
49
|
+
isMarkedAsUntransferable: () => import_worker_threads3.isMarkedAsUntransferable,
|
|
50
|
+
locks: () => locks2,
|
|
51
|
+
markAsUncloneable: () => import_worker_threads3.markAsUncloneable,
|
|
52
|
+
markAsUntransferable: () => import_worker_threads3.markAsUntransferable,
|
|
53
|
+
moveMessagePortToContext: () => import_worker_threads3.moveMessagePortToContext,
|
|
54
|
+
parentPort: () => parentPort2,
|
|
55
|
+
postMessageToThread: () => import_worker_threads3.postMessageToThread,
|
|
56
|
+
receiveMessageOnPort: () => import_worker_threads3.receiveMessageOnPort,
|
|
57
|
+
resourceLimits: () => import_worker_threads3.resourceLimits,
|
|
58
|
+
setEnvironmentData: () => import_worker_threads3.setEnvironmentData,
|
|
59
|
+
structuredClone: () => structuredClone3,
|
|
60
|
+
threadId: () => import_worker_threads3.threadId,
|
|
61
|
+
threadName: () => threadName2,
|
|
62
|
+
workerData: () => import_worker_threads3.workerData
|
|
63
|
+
});
|
|
64
|
+
var WorkerThreads, import_worker_threads3, parentPort2, NodeWorker, isInternalThread2, threadName2, locks2, structuredClone3;
|
|
65
|
+
var init_worker_threads = __esm({
|
|
66
|
+
"src/worker-utils/lib/node/worker_threads.ts"() {
|
|
67
|
+
"use strict";
|
|
68
|
+
WorkerThreads = __toESM(require("worker_threads"), 1);
|
|
69
|
+
import_worker_threads3 = require("worker_threads");
|
|
70
|
+
parentPort2 = WorkerThreads == null ? void 0 : WorkerThreads.parentPort;
|
|
71
|
+
NodeWorker = WorkerThreads.Worker;
|
|
72
|
+
isInternalThread2 = WorkerThreads.isInternalThread;
|
|
73
|
+
threadName2 = WorkerThreads.threadName;
|
|
74
|
+
locks2 = WorkerThreads.locks;
|
|
75
|
+
structuredClone3 = WorkerThreads.structuredClone;
|
|
92
76
|
}
|
|
93
|
-
};
|
|
77
|
+
});
|
|
94
78
|
|
|
95
|
-
//
|
|
79
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/node/worker_threads.js
|
|
80
|
+
var import_worker_threads = require("worker_threads");
|
|
81
|
+
var parentPort = import_worker_threads.parentPort;
|
|
82
|
+
|
|
83
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-utils/get-transfer-list.js
|
|
96
84
|
function getTransferList(object, recursive = true, transfers) {
|
|
97
85
|
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
86
|
+
const seen = /* @__PURE__ */ new Set();
|
|
87
|
+
function visit(value) {
|
|
88
|
+
if (!value || typeof value !== "object" || seen.has(value))
|
|
89
|
+
return;
|
|
90
|
+
seen.add(value);
|
|
91
|
+
if (isTransferable(value))
|
|
92
|
+
transfersSet.add(value);
|
|
93
|
+
else if (ArrayBuffer.isView(value)) {
|
|
94
|
+
if (isTransferable(value.buffer))
|
|
95
|
+
transfersSet.add(value.buffer);
|
|
96
|
+
} else if (recursive && typeof MessageChannel !== "undefined" && value instanceof MessageChannel) {
|
|
97
|
+
visit(value.port1);
|
|
98
|
+
visit(value.port2);
|
|
99
|
+
} else if (recursive && value instanceof Map) {
|
|
100
|
+
for (const [key, item] of value) {
|
|
101
|
+
visit(key);
|
|
102
|
+
visit(item);
|
|
103
|
+
}
|
|
104
|
+
} else if (recursive && value instanceof Set) {
|
|
105
|
+
for (const item of value)
|
|
106
|
+
visit(item);
|
|
107
|
+
} else if (recursive) {
|
|
108
|
+
for (const key of Object.keys(value))
|
|
109
|
+
visit(value[key]);
|
|
107
110
|
}
|
|
108
111
|
}
|
|
112
|
+
visit(object);
|
|
109
113
|
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
110
114
|
}
|
|
111
115
|
function isTransferable(object) {
|
|
@@ -127,11 +131,7 @@ function isTransferable(object) {
|
|
|
127
131
|
return false;
|
|
128
132
|
}
|
|
129
133
|
|
|
130
|
-
//
|
|
131
|
-
var WorkerThreads = __toESM(require("worker_threads"), 1);
|
|
132
|
-
var parentPort = WorkerThreads == null ? void 0 : WorkerThreads.parentPort;
|
|
133
|
-
|
|
134
|
-
// src/worker-utils/lib/worker-farm/worker-body.ts
|
|
134
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-farm/worker-body.js
|
|
135
135
|
async function getParentPort() {
|
|
136
136
|
return parentPort;
|
|
137
137
|
}
|
|
@@ -139,23 +139,24 @@ var onMessageWrapperMap = /* @__PURE__ */ new Map();
|
|
|
139
139
|
var WorkerBody = class {
|
|
140
140
|
/** Check that we are actually in a worker thread */
|
|
141
141
|
static async inWorkerThread() {
|
|
142
|
-
|
|
142
|
+
const workerGlobalScope = globalThis.WorkerGlobalScope;
|
|
143
|
+
return typeof workerGlobalScope === "function" && globalThis instanceof workerGlobalScope || Boolean(await getParentPort());
|
|
143
144
|
}
|
|
144
145
|
/*
|
|
145
146
|
* (type: WorkerMessageType, payload: WorkerMessagePayload) => any
|
|
146
147
|
*/
|
|
147
148
|
static set onmessage(onMessage) {
|
|
148
149
|
async function handleMessage(message) {
|
|
149
|
-
const
|
|
150
|
-
const { type, payload } =
|
|
150
|
+
const parentPort3 = await getParentPort();
|
|
151
|
+
const { type, payload } = parentPort3 ? message : message.data;
|
|
151
152
|
onMessage(type, payload);
|
|
152
153
|
}
|
|
153
|
-
getParentPort().then((
|
|
154
|
-
if (
|
|
155
|
-
|
|
154
|
+
getParentPort().then((parentPort3) => {
|
|
155
|
+
if (parentPort3) {
|
|
156
|
+
parentPort3.on("message", (message) => {
|
|
156
157
|
handleMessage(message);
|
|
157
158
|
});
|
|
158
|
-
|
|
159
|
+
parentPort3.on("exit", () => console.debug("Node worker closing"));
|
|
159
160
|
} else {
|
|
160
161
|
globalThis.onmessage = handleMessage;
|
|
161
162
|
}
|
|
@@ -173,9 +174,9 @@ var WorkerBody = class {
|
|
|
173
174
|
};
|
|
174
175
|
onMessageWrapperMap.set(onMessage, onMessageWrapper);
|
|
175
176
|
}
|
|
176
|
-
const
|
|
177
|
-
if (
|
|
178
|
-
|
|
177
|
+
const parentPort3 = await getParentPort();
|
|
178
|
+
if (parentPort3) {
|
|
179
|
+
parentPort3.on("message", onMessageWrapper);
|
|
179
180
|
} else {
|
|
180
181
|
globalThis.addEventListener("message", onMessageWrapper);
|
|
181
182
|
}
|
|
@@ -186,9 +187,9 @@ var WorkerBody = class {
|
|
|
186
187
|
if (!onMessageWrapper) {
|
|
187
188
|
return;
|
|
188
189
|
}
|
|
189
|
-
const
|
|
190
|
-
if (
|
|
191
|
-
|
|
190
|
+
const parentPort3 = await getParentPort();
|
|
191
|
+
if (parentPort3) {
|
|
192
|
+
parentPort3.off("message", onMessageWrapper);
|
|
192
193
|
} else {
|
|
193
194
|
globalThis.removeEventListener("message", onMessageWrapper);
|
|
194
195
|
}
|
|
@@ -198,12 +199,12 @@ var WorkerBody = class {
|
|
|
198
199
|
* @param type
|
|
199
200
|
* @param payload
|
|
200
201
|
*/
|
|
201
|
-
static async postMessage(type, payload) {
|
|
202
|
+
static async postMessage(type, payload, copy = false) {
|
|
202
203
|
const data = { source: "loaders.gl", type, payload };
|
|
203
|
-
const transferList = getTransferList(payload);
|
|
204
|
-
const
|
|
205
|
-
if (
|
|
206
|
-
|
|
204
|
+
const transferList = copy ? [] : getTransferList(payload);
|
|
205
|
+
const parentPort3 = await getParentPort();
|
|
206
|
+
if (parentPort3) {
|
|
207
|
+
parentPort3.postMessage(data, transferList);
|
|
207
208
|
} else {
|
|
208
209
|
globalThis.postMessage(data, transferList);
|
|
209
210
|
}
|
|
@@ -217,11 +218,125 @@ function getWorkerMessageData(message) {
|
|
|
217
218
|
return messageData && typeof messageData.source === "string" && messageData.source.startsWith("loaders.gl") ? messageData : null;
|
|
218
219
|
}
|
|
219
220
|
|
|
220
|
-
//
|
|
221
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/async-queue/async-queue.js
|
|
222
|
+
var AsyncQueue = class {
|
|
223
|
+
constructor() {
|
|
224
|
+
this._values = [];
|
|
225
|
+
this._settlers = [];
|
|
226
|
+
this._closed = false;
|
|
227
|
+
}
|
|
228
|
+
/** Return an async iterator for this queue */
|
|
229
|
+
[Symbol.asyncIterator]() {
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
/** Push a new value - the async iterator will yield a promise resolved to this value */
|
|
233
|
+
push(value) {
|
|
234
|
+
return this.enqueue(value);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Push a new value - the async iterator will yield a promise resolved to this value
|
|
238
|
+
* Add an error - the async iterator will yield a promise rejected with this value
|
|
239
|
+
*/
|
|
240
|
+
enqueue(value) {
|
|
241
|
+
if (this._closed) {
|
|
242
|
+
throw new Error("Closed");
|
|
243
|
+
}
|
|
244
|
+
if (this._settlers.length > 0) {
|
|
245
|
+
if (this._values.length > 0) {
|
|
246
|
+
throw new Error("Illegal internal state");
|
|
247
|
+
}
|
|
248
|
+
const settler = this._settlers.shift();
|
|
249
|
+
if (value instanceof Error) {
|
|
250
|
+
settler.reject(value);
|
|
251
|
+
} else {
|
|
252
|
+
settler.resolve({ value });
|
|
253
|
+
}
|
|
254
|
+
} else {
|
|
255
|
+
this._values.push(value);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/** Indicate that we not waiting for more values - The async iterator will be done */
|
|
259
|
+
close() {
|
|
260
|
+
while (this._settlers.length > 0) {
|
|
261
|
+
const settler = this._settlers.shift();
|
|
262
|
+
settler.resolve({ done: true });
|
|
263
|
+
}
|
|
264
|
+
this._closed = true;
|
|
265
|
+
}
|
|
266
|
+
// ITERATOR IMPLEMENTATION
|
|
267
|
+
/** @returns a Promise for an IteratorResult */
|
|
268
|
+
next() {
|
|
269
|
+
if (this._values.length > 0) {
|
|
270
|
+
const value = this._values.shift();
|
|
271
|
+
if (value instanceof Error) {
|
|
272
|
+
return Promise.reject(value);
|
|
273
|
+
}
|
|
274
|
+
return Promise.resolve({ done: false, value });
|
|
275
|
+
}
|
|
276
|
+
if (this._closed) {
|
|
277
|
+
if (this._settlers.length > 0) {
|
|
278
|
+
throw new Error("Illegal internal state");
|
|
279
|
+
}
|
|
280
|
+
return Promise.resolve({ done: true, value: void 0 });
|
|
281
|
+
}
|
|
282
|
+
return new Promise((resolve, reject) => {
|
|
283
|
+
this._settlers.push({ resolve, reject });
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/shared-state.js
|
|
289
|
+
var SharedWorkerState = class {
|
|
290
|
+
constructor(buffer) {
|
|
291
|
+
if (typeof SharedArrayBuffer === "undefined" || !(buffer instanceof SharedArrayBuffer) || buffer.byteLength !== 16)
|
|
292
|
+
throw new Error("Expected a 16-byte shared worker control buffer");
|
|
293
|
+
this.buffer = buffer;
|
|
294
|
+
this.values = new Int32Array(buffer);
|
|
295
|
+
}
|
|
296
|
+
get snapshot() {
|
|
297
|
+
return {
|
|
298
|
+
cancelled: Atomics.load(this.values, 0) !== 0,
|
|
299
|
+
completed: Atomics.load(this.values, 1),
|
|
300
|
+
total: Atomics.load(this.values, 2),
|
|
301
|
+
revision: Atomics.load(this.values, 3)
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
cancel() {
|
|
305
|
+
Atomics.store(this.values, 0, 1);
|
|
306
|
+
Atomics.add(this.values, 3, 1);
|
|
307
|
+
Atomics.notify(this.values, 0);
|
|
308
|
+
}
|
|
309
|
+
throwIfCancelled() {
|
|
310
|
+
if (Atomics.load(this.values, 0) !== 0) {
|
|
311
|
+
const error = new Error("Shared worker task was cancelled");
|
|
312
|
+
error.name = "AbortError";
|
|
313
|
+
throw error;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/** Integer counters for application-defined work; messages still carry phase names and units. */
|
|
317
|
+
setProgress(completed, total = -1) {
|
|
318
|
+
if (!Number.isInteger(completed) || completed < 0 || completed > 2147483647 || !Number.isInteger(total) || total < -1 || total > 2147483647) {
|
|
319
|
+
throw new RangeError("Shared progress requires nonnegative int32 counts (or total -1)");
|
|
320
|
+
}
|
|
321
|
+
Atomics.store(this.values, 1, completed);
|
|
322
|
+
Atomics.store(this.values, 2, total);
|
|
323
|
+
Atomics.add(this.values, 3, 1);
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/validate-output-ownership.js
|
|
328
|
+
function validateOutputOwnership(ownership) {
|
|
329
|
+
if (ownership !== void 0 && ownership !== "copy" && ownership !== "transfer") {
|
|
330
|
+
throw new Error("Invalid worker output ownership");
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/create-worker.js
|
|
221
335
|
var requestId = 0;
|
|
336
|
+
var activeController = null;
|
|
222
337
|
var activeInputBatches = null;
|
|
223
338
|
var activeOutputAcknowledgements = null;
|
|
224
|
-
async function createWorker(
|
|
339
|
+
async function createWorker(process2, processInBatches2, preload) {
|
|
225
340
|
if (!await WorkerBody.inWorkerThread()) {
|
|
226
341
|
return;
|
|
227
342
|
}
|
|
@@ -229,27 +344,60 @@ async function createWorker(process, processInBatches2) {
|
|
|
229
344
|
process: processOnMainThread
|
|
230
345
|
};
|
|
231
346
|
WorkerBody.onmessage = async (type, payload) => {
|
|
347
|
+
var _a, _b, _c, _d, _e;
|
|
348
|
+
if (type === "cancel") {
|
|
349
|
+
activeController == null ? void 0 : activeController.abort();
|
|
350
|
+
activeInputBatches == null ? void 0 : activeInputBatches.close();
|
|
351
|
+
activeOutputAcknowledgements == null ? void 0 : activeOutputAcknowledgements.close();
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
const controller = type === "process" || type === "process-in-batches" ? new AbortController() : void 0;
|
|
355
|
+
if (controller)
|
|
356
|
+
activeController = controller;
|
|
357
|
+
const startedAt = performance.now();
|
|
232
358
|
const reporter = type === "process" || type === "process-in-batches" ? createProgressReporter() : void 0;
|
|
233
|
-
|
|
359
|
+
let sharedState;
|
|
360
|
+
const throwIfAborted = () => {
|
|
361
|
+
controller == null ? void 0 : controller.signal.throwIfAborted();
|
|
362
|
+
sharedState == null ? void 0 : sharedState.throwIfCancelled();
|
|
363
|
+
};
|
|
364
|
+
const jobContext = {
|
|
365
|
+
...context,
|
|
366
|
+
signal: controller == null ? void 0 : controller.signal,
|
|
367
|
+
sharedState,
|
|
368
|
+
throwIfAborted,
|
|
369
|
+
reportProgress: (progress) => {
|
|
370
|
+
if (!(controller == null ? void 0 : controller.signal.aborted) && !(sharedState == null ? void 0 : sharedState.snapshot.cancelled))
|
|
371
|
+
reporter == null ? void 0 : reporter.report(progress);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
234
374
|
try {
|
|
375
|
+
if (controller && ((_a = payload.options) == null ? void 0 : _a["sharedState"])) {
|
|
376
|
+
sharedState = new SharedWorkerState(payload.options["sharedState"]);
|
|
377
|
+
jobContext.sharedState = sharedState;
|
|
378
|
+
}
|
|
235
379
|
switch (type) {
|
|
236
380
|
case "preload":
|
|
381
|
+
await (preload == null ? void 0 : preload());
|
|
237
382
|
WorkerBody.postMessage("done", {});
|
|
238
383
|
break;
|
|
239
384
|
case "process":
|
|
240
|
-
|
|
385
|
+
throwIfAborted();
|
|
386
|
+
validateOutputOwnership((_b = payload.options) == null ? void 0 : _b["outputOwnership"]);
|
|
387
|
+
if (!process2) {
|
|
241
388
|
throw new Error("Worker does not support atomic processing");
|
|
242
389
|
}
|
|
243
|
-
const result = await
|
|
244
|
-
|
|
245
|
-
payload.options || {},
|
|
246
|
-
jobContext,
|
|
247
|
-
payload.context || {}
|
|
248
|
-
);
|
|
390
|
+
const result = await process2(payload.input, payload.options || {}, jobContext, payload.context || {});
|
|
391
|
+
throwIfAborted();
|
|
249
392
|
reporter == null ? void 0 : reporter.finish();
|
|
250
|
-
WorkerBody.postMessage("done", {
|
|
393
|
+
await WorkerBody.postMessage("done", {
|
|
394
|
+
result,
|
|
395
|
+
executionMs: performance.now() - startedAt
|
|
396
|
+
}, ((_c = payload.options) == null ? void 0 : _c["outputOwnership"]) === "copy");
|
|
251
397
|
break;
|
|
252
398
|
case "process-in-batches":
|
|
399
|
+
throwIfAborted();
|
|
400
|
+
validateOutputOwnership((_d = payload.options) == null ? void 0 : _d["outputOwnership"]);
|
|
253
401
|
if (!processInBatches2) {
|
|
254
402
|
throw new Error("Worker does not support batched processing");
|
|
255
403
|
}
|
|
@@ -258,18 +406,15 @@ async function createWorker(process, processInBatches2) {
|
|
|
258
406
|
activeInputBatches = inputBatches;
|
|
259
407
|
activeOutputAcknowledgements = outputAcknowledgements;
|
|
260
408
|
try {
|
|
261
|
-
const resultIterator = processInBatches2(
|
|
262
|
-
createDemandDrivenIterator(inputBatches),
|
|
263
|
-
payload.options || {},
|
|
264
|
-
jobContext,
|
|
265
|
-
payload.context || {}
|
|
266
|
-
);
|
|
409
|
+
const resultIterator = processInBatches2(createDemandDrivenIterator(inputBatches), payload.options || {}, jobContext, payload.context || {});
|
|
267
410
|
for await (const batch of resultIterator) {
|
|
268
|
-
|
|
411
|
+
throwIfAborted();
|
|
412
|
+
await WorkerBody.postMessage("output-batch", { result: batch }, ((_e = payload.options) == null ? void 0 : _e["outputOwnership"]) === "copy");
|
|
269
413
|
await outputAcknowledgements.next();
|
|
270
414
|
}
|
|
415
|
+
throwIfAborted();
|
|
271
416
|
reporter == null ? void 0 : reporter.finish();
|
|
272
|
-
await WorkerBody.postMessage("done", {});
|
|
417
|
+
await WorkerBody.postMessage("done", { executionMs: performance.now() - startedAt });
|
|
273
418
|
} finally {
|
|
274
419
|
activeInputBatches = null;
|
|
275
420
|
activeOutputAcknowledgements = null;
|
|
@@ -296,11 +441,18 @@ async function createWorker(process, processInBatches2) {
|
|
|
296
441
|
default:
|
|
297
442
|
}
|
|
298
443
|
} catch (error) {
|
|
299
|
-
reporter == null ? void 0 : reporter.finish();
|
|
444
|
+
reporter == null ? void 0 : reporter.finish((controller == null ? void 0 : controller.signal.aborted) || (sharedState == null ? void 0 : sharedState.snapshot.cancelled));
|
|
300
445
|
const message = error instanceof Error ? error.message : "";
|
|
301
|
-
WorkerBody.postMessage("error", {
|
|
446
|
+
await WorkerBody.postMessage("error", {
|
|
447
|
+
error: message,
|
|
448
|
+
errorName: error instanceof Error ? error.name : "Error"
|
|
449
|
+
});
|
|
450
|
+
} finally {
|
|
451
|
+
if (controller && activeController === controller)
|
|
452
|
+
activeController = null;
|
|
302
453
|
}
|
|
303
454
|
};
|
|
455
|
+
await WorkerBody.postMessage("ready", {});
|
|
304
456
|
}
|
|
305
457
|
async function* createDemandDrivenIterator(inputBatches) {
|
|
306
458
|
while (true) {
|
|
@@ -313,61 +465,365 @@ async function* createDemandDrivenIterator(inputBatches) {
|
|
|
313
465
|
}
|
|
314
466
|
}
|
|
315
467
|
function processOnMainThread(arrayBuffer, options = {}, jobContext = {}) {
|
|
468
|
+
const signal = activeController == null ? void 0 : activeController.signal;
|
|
469
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
316
470
|
return new Promise((resolve, reject) => {
|
|
317
471
|
const id = requestId++;
|
|
318
|
-
const
|
|
319
|
-
|
|
472
|
+
const cleanup = () => {
|
|
473
|
+
signal == null ? void 0 : signal.removeEventListener("abort", abort);
|
|
474
|
+
void WorkerBody.removeEventListener(onMessage);
|
|
475
|
+
};
|
|
476
|
+
const abort = () => {
|
|
477
|
+
cleanup();
|
|
478
|
+
reject(signal == null ? void 0 : signal.reason);
|
|
479
|
+
};
|
|
480
|
+
const onMessage = (type, payload) => {
|
|
481
|
+
if (payload.id !== id)
|
|
320
482
|
return;
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
case "error":
|
|
328
|
-
WorkerBody.removeEventListener(onMessage);
|
|
329
|
-
reject(payload2.error);
|
|
330
|
-
break;
|
|
331
|
-
default:
|
|
483
|
+
if (type === "done") {
|
|
484
|
+
cleanup();
|
|
485
|
+
resolve(payload.result);
|
|
486
|
+
} else if (type === "error") {
|
|
487
|
+
cleanup();
|
|
488
|
+
reject(payload.error);
|
|
332
489
|
}
|
|
333
490
|
};
|
|
334
|
-
WorkerBody.addEventListener(onMessage)
|
|
335
|
-
|
|
336
|
-
|
|
491
|
+
void WorkerBody.addEventListener(onMessage).then(async () => {
|
|
492
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
493
|
+
abort();
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
signal == null ? void 0 : signal.addEventListener("abort", abort, { once: true });
|
|
497
|
+
await WorkerBody.postMessage("process", {
|
|
498
|
+
id,
|
|
499
|
+
input: arrayBuffer,
|
|
500
|
+
options,
|
|
501
|
+
context: jobContext
|
|
502
|
+
});
|
|
503
|
+
}).catch((error) => {
|
|
504
|
+
cleanup();
|
|
505
|
+
reject(error);
|
|
506
|
+
});
|
|
337
507
|
});
|
|
338
508
|
}
|
|
339
509
|
function createProgressReporter() {
|
|
340
|
-
let
|
|
510
|
+
let pending2;
|
|
341
511
|
let finished = false;
|
|
342
512
|
let scheduled = false;
|
|
343
513
|
const flush = () => {
|
|
344
514
|
scheduled = false;
|
|
345
|
-
if (
|
|
346
|
-
WorkerBody.postMessage("progress", { progress:
|
|
347
|
-
|
|
515
|
+
if (pending2) {
|
|
516
|
+
WorkerBody.postMessage("progress", { progress: pending2 });
|
|
517
|
+
pending2 = void 0;
|
|
348
518
|
}
|
|
349
519
|
};
|
|
350
520
|
return {
|
|
351
521
|
/** Records progress while retaining phase transitions. */
|
|
352
522
|
report(progress) {
|
|
353
|
-
if (finished)
|
|
354
|
-
|
|
355
|
-
|
|
523
|
+
if (finished)
|
|
524
|
+
return;
|
|
525
|
+
if (pending2 && pending2.phase !== progress.phase)
|
|
526
|
+
flush();
|
|
527
|
+
pending2 = { ...progress };
|
|
356
528
|
if (!scheduled) {
|
|
357
529
|
scheduled = true;
|
|
358
530
|
setTimeout(flush, 0);
|
|
359
531
|
}
|
|
360
532
|
},
|
|
361
533
|
/** Flushes final progress and suppresses reports from stale callbacks. */
|
|
362
|
-
finish() {
|
|
534
|
+
finish(discard = false) {
|
|
535
|
+
if (discard)
|
|
536
|
+
pending2 = void 0;
|
|
363
537
|
flush();
|
|
364
538
|
finished = true;
|
|
365
539
|
}
|
|
366
540
|
};
|
|
367
541
|
}
|
|
368
542
|
|
|
543
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/index.js
|
|
544
|
+
var import_meta = {};
|
|
545
|
+
var path = typeof __filename === "string" ? __filename.replace(/\\/g, "/") : "";
|
|
546
|
+
var moduleUrl = path ? `file://${path.startsWith("/") ? "" : "/"}${encodeURI(path).replace(/#/g, "%23").replace(/\?/g, "%3F")}` : import_meta.url;
|
|
547
|
+
|
|
548
|
+
// ../../node_modules/@math.gl/core/dist/tasks/task-preload.js
|
|
549
|
+
var pending = /* @__PURE__ */ new WeakMap();
|
|
550
|
+
var loaded = /* @__PURE__ */ new WeakSet();
|
|
551
|
+
function preloadTaskCode(task, signal) {
|
|
552
|
+
if (!task.preload)
|
|
553
|
+
return Promise.resolve();
|
|
554
|
+
let promise = pending.get(task);
|
|
555
|
+
if (!promise) {
|
|
556
|
+
promise = Promise.resolve().then(() => task.preload()).then(() => {
|
|
557
|
+
loaded.add(task);
|
|
558
|
+
});
|
|
559
|
+
pending.set(task, promise);
|
|
560
|
+
void promise.catch(() => pending.delete(task));
|
|
561
|
+
}
|
|
562
|
+
return withSignal(promise, signal);
|
|
563
|
+
}
|
|
564
|
+
function withSignal(operation, signal) {
|
|
565
|
+
if (!signal)
|
|
566
|
+
return operation;
|
|
567
|
+
return new Promise((resolve, reject) => {
|
|
568
|
+
const abort = () => {
|
|
569
|
+
signal.removeEventListener("abort", abort);
|
|
570
|
+
reject(signal.reason);
|
|
571
|
+
};
|
|
572
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
573
|
+
if (signal.aborted)
|
|
574
|
+
abort();
|
|
575
|
+
operation.then((value) => {
|
|
576
|
+
signal.removeEventListener("abort", abort);
|
|
577
|
+
resolve(value);
|
|
578
|
+
}, (error) => {
|
|
579
|
+
signal.removeEventListener("abort", abort);
|
|
580
|
+
reject(error);
|
|
581
|
+
});
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// ../../node_modules/@math.gl/core/dist/tasks/task-runtime.js
|
|
586
|
+
function assertPayload(value) {
|
|
587
|
+
if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) {
|
|
588
|
+
throw new TypeError("Task payloads must be plain objects with named fields");
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
function taskContext(state, context = {}) {
|
|
592
|
+
const signal = context.signal ?? new AbortController().signal;
|
|
593
|
+
return {
|
|
594
|
+
state,
|
|
595
|
+
signal,
|
|
596
|
+
throwIfAborted: () => {
|
|
597
|
+
var _a;
|
|
598
|
+
signal.throwIfAborted();
|
|
599
|
+
(_a = context.throwIfAborted) == null ? void 0 : _a.call(context);
|
|
600
|
+
},
|
|
601
|
+
reportProgress: (progress) => {
|
|
602
|
+
var _a;
|
|
603
|
+
return (_a = context.reportProgress) == null ? void 0 : _a.call(context, {
|
|
604
|
+
...progress,
|
|
605
|
+
phase: progress.phase ?? "process",
|
|
606
|
+
unit: progress.unit ?? "items"
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
var TaskRuntime = class {
|
|
612
|
+
constructor(task) {
|
|
613
|
+
this.task = task;
|
|
614
|
+
this.initialized = false;
|
|
615
|
+
}
|
|
616
|
+
async initialize(input, context = {}) {
|
|
617
|
+
var _a, _b, _c;
|
|
618
|
+
if (this.initialized)
|
|
619
|
+
throw new Error("Task is already initialized");
|
|
620
|
+
assertPayload(input);
|
|
621
|
+
await preloadTaskCode(this.task, context.signal);
|
|
622
|
+
(_a = context.signal) == null ? void 0 : _a.throwIfAborted();
|
|
623
|
+
this.state = await ((_c = (_b = this.task).initialize) == null ? void 0 : _c.call(_b, input, taskContext(void 0, context)));
|
|
624
|
+
this.initialized = true;
|
|
625
|
+
return {};
|
|
626
|
+
}
|
|
627
|
+
async destroy() {
|
|
628
|
+
var _a, _b;
|
|
629
|
+
if (this.initialized) {
|
|
630
|
+
this.initialized = false;
|
|
631
|
+
const state = this.state;
|
|
632
|
+
this.state = void 0;
|
|
633
|
+
if (this.task.initialize)
|
|
634
|
+
await ((_b = (_a = this.task).destroy) == null ? void 0 : _b.call(_a, state));
|
|
635
|
+
}
|
|
636
|
+
return {};
|
|
637
|
+
}
|
|
638
|
+
async process(input, options, context = {}) {
|
|
639
|
+
if (!this.initialized)
|
|
640
|
+
throw new Error("Task is not initialized");
|
|
641
|
+
if (!this.task.process)
|
|
642
|
+
throw new Error("Task has no atomic processor");
|
|
643
|
+
assertPayload(input);
|
|
644
|
+
const result = await this.task.process(input, options, taskContext(this.state, context));
|
|
645
|
+
assertPayload(result);
|
|
646
|
+
return result;
|
|
647
|
+
}
|
|
648
|
+
async *stream(inputs, options, context = {}) {
|
|
649
|
+
if (!this.initialized)
|
|
650
|
+
throw new Error("Task is not initialized");
|
|
651
|
+
if (!this.task.processInBatches)
|
|
652
|
+
throw new Error("Task has no streaming processor");
|
|
653
|
+
for await (const output of this.task.processInBatches(inputs, options, taskContext(this.state, context))) {
|
|
654
|
+
assertPayload(output);
|
|
655
|
+
yield output;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
async function initializeTaskWorker(task) {
|
|
660
|
+
if (!await WorkerBody.inWorkerThread())
|
|
661
|
+
throw new Error("initializeTaskWorker must run inside a worker");
|
|
662
|
+
if (installed)
|
|
663
|
+
throw new Error("A task is already installed in this worker");
|
|
664
|
+
installed = true;
|
|
665
|
+
const runtime = new TaskRuntime(task);
|
|
666
|
+
let streamOptions = {};
|
|
667
|
+
return createWorker(async (request, _options, context) => {
|
|
668
|
+
switch (request.operation) {
|
|
669
|
+
case "initialize":
|
|
670
|
+
return runtime.initialize(request.input, context);
|
|
671
|
+
case "destroy":
|
|
672
|
+
return runtime.destroy();
|
|
673
|
+
case "stream-options":
|
|
674
|
+
streamOptions = request.options;
|
|
675
|
+
return {};
|
|
676
|
+
case "process":
|
|
677
|
+
return runtime.process(request.input, request.options, context);
|
|
678
|
+
default:
|
|
679
|
+
throw new Error("Unknown task operation");
|
|
680
|
+
}
|
|
681
|
+
}, async function* (inputs, _options, context) {
|
|
682
|
+
async function* batches() {
|
|
683
|
+
for await (const input of inputs) {
|
|
684
|
+
assertPayload(input);
|
|
685
|
+
yield input;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
try {
|
|
689
|
+
yield* runtime.stream(batches(), streamOptions, context);
|
|
690
|
+
} finally {
|
|
691
|
+
streamOptions = {};
|
|
692
|
+
}
|
|
693
|
+
}, () => preloadTaskCode(task));
|
|
694
|
+
}
|
|
695
|
+
var installed = false;
|
|
696
|
+
|
|
697
|
+
// src/worker-utils/lib/worker-api/task-runtime.ts
|
|
698
|
+
function normalizeTaskProgress(progress) {
|
|
699
|
+
return { ...progress, phase: progress.phase ?? "process", unit: progress.unit ?? "items" };
|
|
700
|
+
}
|
|
701
|
+
async function isWorkerThread() {
|
|
702
|
+
var _a;
|
|
703
|
+
if (typeof self !== "undefined" && typeof document === "undefined" && typeof self.postMessage === "function")
|
|
704
|
+
return true;
|
|
705
|
+
if (typeof process !== "undefined" && ((_a = process.versions) == null ? void 0 : _a.node)) {
|
|
706
|
+
const { isMainThread: isMainThread2 } = await Promise.resolve().then(() => (init_worker_threads(), worker_threads_exports));
|
|
707
|
+
return !isMainThread2;
|
|
708
|
+
}
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
711
|
+
var initializeTaskWorker2 = initializeTaskWorker;
|
|
712
|
+
|
|
713
|
+
// src/worker-utils/lib/worker-utils/get-transfer-list.ts
|
|
714
|
+
function getTransferList2(object, recursive = true, transfers) {
|
|
715
|
+
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
716
|
+
if (!object) {
|
|
717
|
+
} else if (isTransferable2(object)) {
|
|
718
|
+
transfersSet.add(object);
|
|
719
|
+
} else if (isTransferable2(object.buffer)) {
|
|
720
|
+
transfersSet.add(object.buffer);
|
|
721
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
722
|
+
} else if (recursive && typeof object === "object") {
|
|
723
|
+
for (const key in object) {
|
|
724
|
+
getTransferList2(object[key], recursive, transfersSet);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
728
|
+
}
|
|
729
|
+
function isTransferable2(object) {
|
|
730
|
+
if (!object) {
|
|
731
|
+
return false;
|
|
732
|
+
}
|
|
733
|
+
if (object instanceof ArrayBuffer) {
|
|
734
|
+
return true;
|
|
735
|
+
}
|
|
736
|
+
if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
|
|
737
|
+
return true;
|
|
738
|
+
}
|
|
739
|
+
if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
|
|
740
|
+
return true;
|
|
741
|
+
}
|
|
742
|
+
if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
|
|
743
|
+
return true;
|
|
744
|
+
}
|
|
745
|
+
return false;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// src/worker-utils/lib/worker-api/create-worker.ts
|
|
749
|
+
async function createWorker2(process2, processInBatches2) {
|
|
750
|
+
if (!await isWorkerThread()) return;
|
|
751
|
+
await initializeTaskWorker2(createWorkerTask(process2, processInBatches2));
|
|
752
|
+
}
|
|
753
|
+
function createWorkerTask(process2, processInBatches2) {
|
|
754
|
+
return {
|
|
755
|
+
id: "loaders.gl",
|
|
756
|
+
initialize: (state) => state,
|
|
757
|
+
destroy: (state) => {
|
|
758
|
+
var _a;
|
|
759
|
+
return (_a = state.port) == null ? void 0 : _a.close();
|
|
760
|
+
},
|
|
761
|
+
process: async ({ value }, options, context) => {
|
|
762
|
+
if (!process2) throw new Error("Worker does not support atomic processing");
|
|
763
|
+
return { value: await process2(value, options, createContext(context), context.state.context) };
|
|
764
|
+
},
|
|
765
|
+
...processInBatches2 ? {
|
|
766
|
+
processInBatches: async function* (inputs, options, context) {
|
|
767
|
+
async function* values() {
|
|
768
|
+
for await (const input of inputs) yield input.value;
|
|
769
|
+
}
|
|
770
|
+
for await (const value of processInBatches2(
|
|
771
|
+
values(),
|
|
772
|
+
options,
|
|
773
|
+
createContext(context),
|
|
774
|
+
context.state.context
|
|
775
|
+
)) {
|
|
776
|
+
yield { value };
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
} : {}
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
function createContext(context) {
|
|
783
|
+
let requestIdentifier = 0;
|
|
784
|
+
const port = context.state.port;
|
|
785
|
+
return {
|
|
786
|
+
signal: context.signal,
|
|
787
|
+
throwIfAborted: () => context.throwIfAborted(),
|
|
788
|
+
reportProgress: (progress) => context.reportProgress(normalizeTaskProgress(progress)),
|
|
789
|
+
process: port ? (input, options = {}, jobContext = {}) => {
|
|
790
|
+
context.throwIfAborted();
|
|
791
|
+
const identifier = ++requestIdentifier;
|
|
792
|
+
return new Promise((resolve, reject) => {
|
|
793
|
+
const onMessage = (event) => {
|
|
794
|
+
if (event.data.identifier !== identifier) return;
|
|
795
|
+
cleanup();
|
|
796
|
+
if (event.data.error) {
|
|
797
|
+
const error = new Error(event.data.error.message);
|
|
798
|
+
error.name = event.data.error.name;
|
|
799
|
+
reject(error);
|
|
800
|
+
} else resolve(event.data.value);
|
|
801
|
+
};
|
|
802
|
+
const onAbort = () => {
|
|
803
|
+
cleanup();
|
|
804
|
+
reject(context.signal.reason);
|
|
805
|
+
};
|
|
806
|
+
const cleanup = () => {
|
|
807
|
+
port.removeEventListener("message", onMessage);
|
|
808
|
+
context.signal.removeEventListener("abort", onAbort);
|
|
809
|
+
};
|
|
810
|
+
port.addEventListener("message", onMessage);
|
|
811
|
+
context.signal.addEventListener("abort", onAbort, { once: true });
|
|
812
|
+
port.start();
|
|
813
|
+
try {
|
|
814
|
+
const request = { identifier, input, options, context: jobContext };
|
|
815
|
+
port.postMessage(request, getTransferList2(request));
|
|
816
|
+
} catch (error) {
|
|
817
|
+
cleanup();
|
|
818
|
+
reject(error);
|
|
819
|
+
}
|
|
820
|
+
});
|
|
821
|
+
} : void 0
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
|
|
369
825
|
// src/worker-utils/workers/null-worker.ts
|
|
370
|
-
|
|
826
|
+
createWorker2(
|
|
371
827
|
async (data) => {
|
|
372
828
|
return data;
|
|
373
829
|
},
|