@loaders.gl/geospatial 5.0.0-beta.2 → 5.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/WKT-README.md +1 -1
- package/dist/dbf-loader-types.cjs +1 -1
- package/dist/dbf-worker.js +776 -153
- package/dist/flatgeobuf/flatgeobuf-loader-types.cjs +1 -1
- package/dist/flatgeobuf/flatgeobuf-loader-types.js +1 -1
- package/dist/flatgeobuf/flatgeobuf-source-loader.cjs +1 -1
- package/dist/flatgeobuf/flatgeobuf-source-loader.js +1 -1
- package/dist/flatgeobuf-loader-types.cjs +1 -1
- package/dist/flatgeobuf-source-loader.cjs +1 -1
- package/dist/flatgeobuf-worker.js +1238 -584
- package/dist/geopackage/geopackage-source-loader.cjs +1 -1
- package/dist/geopackage/geopackage-source-loader.js +1 -1
- package/dist/geopackage-source-loader.cjs +1 -1
- package/dist/gpx-loader-types.cjs +1 -1
- package/dist/kml/gpx-loader-types.cjs +1 -1
- package/dist/kml/gpx-loader-types.js +1 -1
- package/dist/kml/kml-loader-types.cjs +1 -1
- package/dist/kml/kml-loader-types.js +1 -1
- package/dist/kml/kml-writer.cjs +1 -1
- package/dist/kml/kml-writer.js +1 -1
- package/dist/kml/kmz-loader-types.cjs +1 -1
- package/dist/kml/kmz-loader-types.js +1 -1
- package/dist/kml/kmz-source.cjs +1 -1
- package/dist/kml/kmz-source.js +1 -1
- package/dist/kml/tcx-loader-types.cjs +1 -1
- package/dist/kml/tcx-loader-types.js +1 -1
- package/dist/kml-loader-types.cjs +1 -1
- package/dist/kml-writer.cjs +1 -1
- package/dist/kmz-loader-types.cjs +1 -1
- package/dist/kmz-source.cjs +1 -1
- package/dist/shapefile/dbf-loader-types.cjs +1 -1
- package/dist/shapefile/dbf-loader-types.js +1 -1
- package/dist/shapefile/dbf-loader.d.ts +1 -1
- package/dist/shapefile/lib/shapefile-worker-transport.cjs +3 -3
- package/dist/shapefile/lib/shapefile-worker-transport.cjs.map +2 -2
- package/dist/shapefile/lib/shapefile-worker-transport.js +1 -1
- package/dist/shapefile/lib/shapefile-worker-transport.js.map +1 -1
- package/dist/shapefile/shapefile-loader-types.cjs +1 -1
- package/dist/shapefile/shapefile-loader-types.js +1 -1
- package/dist/shapefile/shp-loader-types.cjs +1 -1
- package/dist/shapefile/shp-loader-types.js +1 -1
- package/dist/shapefile/shp-loader.d.ts +1 -1
- package/dist/shapefile-loader-types.cjs +1 -1
- package/dist/shapefile-worker.js +3099 -2400
- package/dist/shp-loader-types.cjs +1 -1
- package/dist/shp-worker.js +2811 -2216
- package/dist/tcx-loader-types.cjs +1 -1
- package/dist/wkt/lib/version.cjs +1 -1
- package/dist/wkt/lib/version.js +1 -1
- package/dist/wkt/wkt-format.cjs +2 -2
- package/dist/wkt/wkt-format.cjs.map +2 -2
- package/dist/wkt/wkt-format.js +1 -1
- package/dist/wkt/wkt-format.js.map +1 -1
- package/dist/wkt-worker.js +582 -75
- package/package.json +6 -5
- package/src/shapefile/lib/shapefile-worker-transport.ts +1 -1
- package/src/wkt/wkt-format.ts +1 -1
package/dist/wkt-worker.js
CHANGED
|
@@ -15,25 +15,34 @@
|
|
|
15
15
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
//
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
// ../core/src/worker-utils/lib/node/worker_threads-browser.ts
|
|
19
|
+
var worker_threads_browser_exports = {};
|
|
20
|
+
__export(worker_threads_browser_exports, {
|
|
21
|
+
NodeWorker: () => NodeWorker,
|
|
22
|
+
parentPort: () => parentPort2
|
|
22
23
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
var NodeWorker, parentPort2;
|
|
25
|
+
var init_worker_threads_browser = __esm({
|
|
26
|
+
"../core/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;
|
|
33
42
|
}
|
|
34
43
|
});
|
|
35
44
|
|
|
36
|
-
// ../../node_modules/@math.gl/
|
|
45
|
+
// ../../node_modules/@math.gl/arrow/dist/wkb/types.js
|
|
37
46
|
function getWellKnownDimensionSize(dimension) {
|
|
38
47
|
switch (dimension) {
|
|
39
48
|
case "xy":
|
|
@@ -46,11 +55,11 @@
|
|
|
46
55
|
}
|
|
47
56
|
}
|
|
48
57
|
var init_types = __esm({
|
|
49
|
-
"../../node_modules/@math.gl/
|
|
58
|
+
"../../node_modules/@math.gl/arrow/dist/wkb/types.js"() {
|
|
50
59
|
}
|
|
51
60
|
});
|
|
52
61
|
|
|
53
|
-
// ../../node_modules/@math.gl/
|
|
62
|
+
// ../../node_modules/@math.gl/arrow/dist/wkb/wkb-reader.js
|
|
54
63
|
function inspectWKBHeader(input, byteOffset = 0) {
|
|
55
64
|
return inspectWKBHeaderView(getDataView(input), byteOffset);
|
|
56
65
|
}
|
|
@@ -111,7 +120,7 @@
|
|
|
111
120
|
}
|
|
112
121
|
var GEOMETRY_TYPES;
|
|
113
122
|
var init_wkb_reader = __esm({
|
|
114
|
-
"../../node_modules/@math.gl/
|
|
123
|
+
"../../node_modules/@math.gl/arrow/dist/wkb/wkb-reader.js"() {
|
|
115
124
|
GEOMETRY_TYPES = [
|
|
116
125
|
"Point",
|
|
117
126
|
"LineString",
|
|
@@ -124,7 +133,7 @@
|
|
|
124
133
|
}
|
|
125
134
|
});
|
|
126
135
|
|
|
127
|
-
// ../../node_modules/@math.gl/
|
|
136
|
+
// ../../node_modules/@math.gl/arrow/dist/wkb/wkb.js
|
|
128
137
|
function parseWKB(bytes, options = {}) {
|
|
129
138
|
const state = {
|
|
130
139
|
maximumDepth: validateLimit(options.maximumDepth, 64, "maximumDepth"),
|
|
@@ -244,13 +253,13 @@
|
|
|
244
253
|
return limit;
|
|
245
254
|
}
|
|
246
255
|
var init_wkb = __esm({
|
|
247
|
-
"../../node_modules/@math.gl/
|
|
256
|
+
"../../node_modules/@math.gl/arrow/dist/wkb/wkb.js"() {
|
|
248
257
|
init_types();
|
|
249
258
|
init_wkb_reader();
|
|
250
259
|
}
|
|
251
260
|
});
|
|
252
261
|
|
|
253
|
-
// ../../node_modules/@math.gl/
|
|
262
|
+
// ../../node_modules/@math.gl/arrow/dist/wkb/wkt.js
|
|
254
263
|
function parseWKTWithMetadata(text, options = {}) {
|
|
255
264
|
const parser = new WKTParser(text);
|
|
256
265
|
const result = parser.parseGeometry("xy", options, true);
|
|
@@ -369,7 +378,7 @@
|
|
|
369
378
|
}
|
|
370
379
|
var WKTParser;
|
|
371
380
|
var init_wkt = __esm({
|
|
372
|
-
"../../node_modules/@math.gl/
|
|
381
|
+
"../../node_modules/@math.gl/arrow/dist/wkb/wkt.js"() {
|
|
373
382
|
init_types();
|
|
374
383
|
WKTParser = class {
|
|
375
384
|
constructor(text) {
|
|
@@ -484,25 +493,15 @@
|
|
|
484
493
|
}
|
|
485
494
|
});
|
|
486
495
|
|
|
487
|
-
// ../../node_modules/@math.gl/
|
|
496
|
+
// ../../node_modules/@math.gl/arrow/dist/wkb/index.js
|
|
488
497
|
var init_wkb2 = __esm({
|
|
489
|
-
"../../node_modules/@math.gl/
|
|
498
|
+
"../../node_modules/@math.gl/arrow/dist/wkb/index.js"() {
|
|
490
499
|
init_wkb();
|
|
491
500
|
init_wkb_reader();
|
|
492
501
|
init_wkt();
|
|
493
502
|
}
|
|
494
503
|
});
|
|
495
504
|
|
|
496
|
-
// ../../node_modules/@math.gl/geospatial/dist/index.js
|
|
497
|
-
var init_dist = __esm({
|
|
498
|
-
"../../node_modules/@math.gl/geospatial/dist/index.js"() {
|
|
499
|
-
init_ellipsoid();
|
|
500
|
-
init_globe();
|
|
501
|
-
init_tiles();
|
|
502
|
-
init_wkb2();
|
|
503
|
-
}
|
|
504
|
-
});
|
|
505
|
-
|
|
506
505
|
// ../core/src/arrow-geometry/geometry-utils.ts
|
|
507
506
|
function normalizeEmptyPoints(geometry) {
|
|
508
507
|
if (geometry.type === "Point") {
|
|
@@ -589,7 +588,7 @@
|
|
|
589
588
|
var init_geometry_codecs = __esm({
|
|
590
589
|
"../core/src/arrow-geometry/geometry-codecs.ts"() {
|
|
591
590
|
"use strict";
|
|
592
|
-
|
|
591
|
+
init_wkb2();
|
|
593
592
|
init_geometry_utils();
|
|
594
593
|
}
|
|
595
594
|
});
|
|
@@ -599,7 +598,7 @@
|
|
|
599
598
|
var init_version = __esm({
|
|
600
599
|
"src/wkt/lib/version.ts"() {
|
|
601
600
|
"use strict";
|
|
602
|
-
VERSION = true ? "5.0.0-beta.
|
|
601
|
+
VERSION = true ? "5.0.0-beta.5" : "latest";
|
|
603
602
|
}
|
|
604
603
|
});
|
|
605
604
|
|
|
@@ -621,7 +620,7 @@
|
|
|
621
620
|
var init_wkt_format = __esm({
|
|
622
621
|
"src/wkt/wkt-format.ts"() {
|
|
623
622
|
"use strict";
|
|
624
|
-
|
|
623
|
+
init_wkb2();
|
|
625
624
|
WKT_MAGIC_STRINGS = [
|
|
626
625
|
"POINT(",
|
|
627
626
|
"LINESTRING(",
|
|
@@ -777,10 +776,10 @@
|
|
|
777
776
|
}
|
|
778
777
|
});
|
|
779
778
|
|
|
780
|
-
// ../../node_modules/@math.gl/
|
|
781
|
-
var parentPort = null;
|
|
779
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/node/worker_threads-browser.js
|
|
780
|
+
var parentPort = globalThis.process?.getBuiltinModule?.("node:worker_threads")?.parentPort ?? null;
|
|
782
781
|
|
|
783
|
-
// ../../node_modules/@math.gl/
|
|
782
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-utils/get-transfer-list.js
|
|
784
783
|
function getTransferList(object, recursive = true, transfers) {
|
|
785
784
|
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
786
785
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -793,6 +792,9 @@
|
|
|
793
792
|
else if (ArrayBuffer.isView(value)) {
|
|
794
793
|
if (isTransferable(value.buffer))
|
|
795
794
|
transfersSet.add(value.buffer);
|
|
795
|
+
} else if (recursive && typeof MessageChannel !== "undefined" && value instanceof MessageChannel) {
|
|
796
|
+
visit(value.port1);
|
|
797
|
+
visit(value.port2);
|
|
796
798
|
} else if (recursive && value instanceof Map) {
|
|
797
799
|
for (const [key, item] of value) {
|
|
798
800
|
visit(key);
|
|
@@ -828,7 +830,7 @@
|
|
|
828
830
|
return false;
|
|
829
831
|
}
|
|
830
832
|
|
|
831
|
-
// ../../node_modules/@math.gl/
|
|
833
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-body.js
|
|
832
834
|
async function getParentPort() {
|
|
833
835
|
return parentPort;
|
|
834
836
|
}
|
|
@@ -844,16 +846,16 @@
|
|
|
844
846
|
*/
|
|
845
847
|
static set onmessage(onMessage) {
|
|
846
848
|
async function handleMessage(message) {
|
|
847
|
-
const
|
|
848
|
-
const { type, payload } =
|
|
849
|
+
const parentPort3 = await getParentPort();
|
|
850
|
+
const { type, payload } = parentPort3 ? message : message.data;
|
|
849
851
|
onMessage(type, payload);
|
|
850
852
|
}
|
|
851
|
-
getParentPort().then((
|
|
852
|
-
if (
|
|
853
|
-
|
|
853
|
+
getParentPort().then((parentPort3) => {
|
|
854
|
+
if (parentPort3) {
|
|
855
|
+
parentPort3.on("message", (message) => {
|
|
854
856
|
handleMessage(message);
|
|
855
857
|
});
|
|
856
|
-
|
|
858
|
+
parentPort3.on("exit", () => console.debug("Node worker closing"));
|
|
857
859
|
} else {
|
|
858
860
|
globalThis.onmessage = handleMessage;
|
|
859
861
|
}
|
|
@@ -871,9 +873,9 @@
|
|
|
871
873
|
};
|
|
872
874
|
onMessageWrapperMap.set(onMessage, onMessageWrapper);
|
|
873
875
|
}
|
|
874
|
-
const
|
|
875
|
-
if (
|
|
876
|
-
|
|
876
|
+
const parentPort3 = await getParentPort();
|
|
877
|
+
if (parentPort3) {
|
|
878
|
+
parentPort3.on("message", onMessageWrapper);
|
|
877
879
|
} else {
|
|
878
880
|
globalThis.addEventListener("message", onMessageWrapper);
|
|
879
881
|
}
|
|
@@ -884,9 +886,9 @@
|
|
|
884
886
|
if (!onMessageWrapper) {
|
|
885
887
|
return;
|
|
886
888
|
}
|
|
887
|
-
const
|
|
888
|
-
if (
|
|
889
|
-
|
|
889
|
+
const parentPort3 = await getParentPort();
|
|
890
|
+
if (parentPort3) {
|
|
891
|
+
parentPort3.off("message", onMessageWrapper);
|
|
890
892
|
} else {
|
|
891
893
|
globalThis.removeEventListener("message", onMessageWrapper);
|
|
892
894
|
}
|
|
@@ -896,12 +898,12 @@
|
|
|
896
898
|
* @param type
|
|
897
899
|
* @param payload
|
|
898
900
|
*/
|
|
899
|
-
static async postMessage(type, payload) {
|
|
901
|
+
static async postMessage(type, payload, copy = false) {
|
|
900
902
|
const data = { source: "loaders.gl", type, payload };
|
|
901
|
-
const transferList = getTransferList(payload);
|
|
902
|
-
const
|
|
903
|
-
if (
|
|
904
|
-
|
|
903
|
+
const transferList = copy ? [] : getTransferList(payload);
|
|
904
|
+
const parentPort3 = await getParentPort();
|
|
905
|
+
if (parentPort3) {
|
|
906
|
+
parentPort3.postMessage(data, transferList);
|
|
905
907
|
} else {
|
|
906
908
|
globalThis.postMessage(data, transferList);
|
|
907
909
|
}
|
|
@@ -915,7 +917,7 @@
|
|
|
915
917
|
return messageData && typeof messageData.source === "string" && messageData.source.startsWith("loaders.gl") ? messageData : null;
|
|
916
918
|
}
|
|
917
919
|
|
|
918
|
-
// ../../node_modules/@math.gl/
|
|
920
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/async-queue/async-queue.js
|
|
919
921
|
var AsyncQueue = class {
|
|
920
922
|
constructor() {
|
|
921
923
|
this._values = [];
|
|
@@ -982,7 +984,7 @@
|
|
|
982
984
|
}
|
|
983
985
|
};
|
|
984
986
|
|
|
985
|
-
// ../../node_modules/@math.gl/
|
|
987
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/shared-state.js
|
|
986
988
|
var SharedWorkerState = class {
|
|
987
989
|
constructor(buffer) {
|
|
988
990
|
if (typeof SharedArrayBuffer === "undefined" || !(buffer instanceof SharedArrayBuffer) || buffer.byteLength !== 16)
|
|
@@ -1021,12 +1023,19 @@
|
|
|
1021
1023
|
}
|
|
1022
1024
|
};
|
|
1023
1025
|
|
|
1024
|
-
// ../../node_modules/@math.gl/
|
|
1026
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/validate-output-ownership.js
|
|
1027
|
+
function validateOutputOwnership(ownership) {
|
|
1028
|
+
if (ownership !== void 0 && ownership !== "copy" && ownership !== "transfer") {
|
|
1029
|
+
throw new Error("Invalid worker output ownership");
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/create-worker.js
|
|
1025
1034
|
var requestId = 0;
|
|
1026
1035
|
var activeController = null;
|
|
1027
1036
|
var activeInputBatches = null;
|
|
1028
1037
|
var activeOutputAcknowledgements = null;
|
|
1029
|
-
async function createWorker(
|
|
1038
|
+
async function createWorker(process2, processInBatches, preload3) {
|
|
1030
1039
|
if (!await WorkerBody.inWorkerThread()) {
|
|
1031
1040
|
return;
|
|
1032
1041
|
}
|
|
@@ -1067,23 +1076,26 @@
|
|
|
1067
1076
|
}
|
|
1068
1077
|
switch (type) {
|
|
1069
1078
|
case "preload":
|
|
1079
|
+
await preload3?.();
|
|
1070
1080
|
WorkerBody.postMessage("done", {});
|
|
1071
1081
|
break;
|
|
1072
1082
|
case "process":
|
|
1073
1083
|
throwIfAborted();
|
|
1074
|
-
|
|
1084
|
+
validateOutputOwnership(payload.options?.["outputOwnership"]);
|
|
1085
|
+
if (!process2) {
|
|
1075
1086
|
throw new Error("Worker does not support atomic processing");
|
|
1076
1087
|
}
|
|
1077
|
-
const result = await
|
|
1088
|
+
const result = await process2(payload.input, payload.options || {}, jobContext, payload.context || {});
|
|
1078
1089
|
throwIfAborted();
|
|
1079
1090
|
reporter?.finish();
|
|
1080
1091
|
await WorkerBody.postMessage("done", {
|
|
1081
1092
|
result,
|
|
1082
1093
|
executionMs: performance.now() - startedAt
|
|
1083
|
-
});
|
|
1094
|
+
}, payload.options?.["outputOwnership"] === "copy");
|
|
1084
1095
|
break;
|
|
1085
1096
|
case "process-in-batches":
|
|
1086
1097
|
throwIfAborted();
|
|
1098
|
+
validateOutputOwnership(payload.options?.["outputOwnership"]);
|
|
1087
1099
|
if (!processInBatches) {
|
|
1088
1100
|
throw new Error("Worker does not support batched processing");
|
|
1089
1101
|
}
|
|
@@ -1095,7 +1107,7 @@
|
|
|
1095
1107
|
const resultIterator = processInBatches(createDemandDrivenIterator(inputBatches), payload.options || {}, jobContext, payload.context || {});
|
|
1096
1108
|
for await (const batch of resultIterator) {
|
|
1097
1109
|
throwIfAborted();
|
|
1098
|
-
await WorkerBody.postMessage("output-batch", { result: batch });
|
|
1110
|
+
await WorkerBody.postMessage("output-batch", { result: batch }, payload.options?.["outputOwnership"] === "copy");
|
|
1099
1111
|
await outputAcknowledgements.next();
|
|
1100
1112
|
}
|
|
1101
1113
|
throwIfAborted();
|
|
@@ -1193,14 +1205,14 @@
|
|
|
1193
1205
|
});
|
|
1194
1206
|
}
|
|
1195
1207
|
function createProgressReporter() {
|
|
1196
|
-
let
|
|
1208
|
+
let pending2;
|
|
1197
1209
|
let finished = false;
|
|
1198
1210
|
let scheduled = false;
|
|
1199
1211
|
const flush = () => {
|
|
1200
1212
|
scheduled = false;
|
|
1201
|
-
if (
|
|
1202
|
-
WorkerBody.postMessage("progress", { progress:
|
|
1203
|
-
|
|
1213
|
+
if (pending2) {
|
|
1214
|
+
WorkerBody.postMessage("progress", { progress: pending2 });
|
|
1215
|
+
pending2 = void 0;
|
|
1204
1216
|
}
|
|
1205
1217
|
};
|
|
1206
1218
|
return {
|
|
@@ -1208,9 +1220,9 @@
|
|
|
1208
1220
|
report(progress) {
|
|
1209
1221
|
if (finished)
|
|
1210
1222
|
return;
|
|
1211
|
-
if (
|
|
1223
|
+
if (pending2 && pending2.phase !== progress.phase)
|
|
1212
1224
|
flush();
|
|
1213
|
-
|
|
1225
|
+
pending2 = { ...progress };
|
|
1214
1226
|
if (!scheduled) {
|
|
1215
1227
|
scheduled = true;
|
|
1216
1228
|
setTimeout(flush, 0);
|
|
@@ -1219,21 +1231,516 @@
|
|
|
1219
1231
|
/** Flushes final progress and suppresses reports from stale callbacks. */
|
|
1220
1232
|
finish(discard = false) {
|
|
1221
1233
|
if (discard)
|
|
1222
|
-
|
|
1234
|
+
pending2 = void 0;
|
|
1223
1235
|
flush();
|
|
1224
1236
|
finished = true;
|
|
1225
1237
|
}
|
|
1226
1238
|
};
|
|
1227
1239
|
}
|
|
1228
1240
|
|
|
1229
|
-
// ../../node_modules/@math.gl/
|
|
1241
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/index.js
|
|
1230
1242
|
var import_meta = {};
|
|
1231
1243
|
var path = typeof __filename === "string" ? __filename.replace(/\\/g, "/") : "";
|
|
1232
1244
|
var moduleUrl = path ? `file://${path.startsWith("/") ? "" : "/"}${encodeURI(path).replace(/#/g, "%23").replace(/\?/g, "%3F")}` : import_meta.url;
|
|
1233
1245
|
|
|
1246
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-preload.js
|
|
1247
|
+
var pending = /* @__PURE__ */ new WeakMap();
|
|
1248
|
+
var loaded = /* @__PURE__ */ new WeakSet();
|
|
1249
|
+
function preloadTaskCode(task, signal) {
|
|
1250
|
+
if (!task.preload)
|
|
1251
|
+
return Promise.resolve();
|
|
1252
|
+
let promise = pending.get(task);
|
|
1253
|
+
if (!promise) {
|
|
1254
|
+
promise = Promise.resolve().then(() => task.preload()).then(() => {
|
|
1255
|
+
loaded.add(task);
|
|
1256
|
+
});
|
|
1257
|
+
pending.set(task, promise);
|
|
1258
|
+
void promise.catch(() => pending.delete(task));
|
|
1259
|
+
}
|
|
1260
|
+
return withSignal(promise, signal);
|
|
1261
|
+
}
|
|
1262
|
+
function withSignal(operation, signal) {
|
|
1263
|
+
if (!signal)
|
|
1264
|
+
return operation;
|
|
1265
|
+
return new Promise((resolve, reject) => {
|
|
1266
|
+
const abort = () => {
|
|
1267
|
+
signal.removeEventListener("abort", abort);
|
|
1268
|
+
reject(signal.reason);
|
|
1269
|
+
};
|
|
1270
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
1271
|
+
if (signal.aborted)
|
|
1272
|
+
abort();
|
|
1273
|
+
operation.then((value) => {
|
|
1274
|
+
signal.removeEventListener("abort", abort);
|
|
1275
|
+
resolve(value);
|
|
1276
|
+
}, (error) => {
|
|
1277
|
+
signal.removeEventListener("abort", abort);
|
|
1278
|
+
reject(error);
|
|
1279
|
+
});
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-channel.js
|
|
1284
|
+
var TaskRequestError = class extends Error {
|
|
1285
|
+
};
|
|
1286
|
+
var TaskChannel = class {
|
|
1287
|
+
constructor(options) {
|
|
1288
|
+
this.options = options;
|
|
1289
|
+
this.nextId = 1;
|
|
1290
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
1291
|
+
this.incoming = /* @__PURE__ */ new Map();
|
|
1292
|
+
}
|
|
1293
|
+
/** Send a request without serializing other in-flight requests. */
|
|
1294
|
+
request(operation, value, signal, transfer = []) {
|
|
1295
|
+
if (this.failure)
|
|
1296
|
+
return Promise.reject(this.failure.reason);
|
|
1297
|
+
if (signal?.aborted)
|
|
1298
|
+
return Promise.reject(signal.reason);
|
|
1299
|
+
const id = this.nextId++;
|
|
1300
|
+
return new Promise((resolve, reject) => {
|
|
1301
|
+
const abort = () => {
|
|
1302
|
+
const pending2 = this.pending.get(id);
|
|
1303
|
+
if (!pending2)
|
|
1304
|
+
return;
|
|
1305
|
+
this.pending.delete(id);
|
|
1306
|
+
pending2.cleanup();
|
|
1307
|
+
reject(signal?.reason);
|
|
1308
|
+
this.send({ source: "math.gl/tasks", kind: "cancel", id });
|
|
1309
|
+
};
|
|
1310
|
+
this.pending.set(id, {
|
|
1311
|
+
resolve,
|
|
1312
|
+
reject,
|
|
1313
|
+
cleanup: () => signal?.removeEventListener("abort", abort)
|
|
1314
|
+
});
|
|
1315
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
1316
|
+
this.send({ source: "math.gl/tasks", kind: "request", id, operation, value }, transfer);
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
/** Send a one-way notification. */
|
|
1320
|
+
emit(operation, value, transfer = []) {
|
|
1321
|
+
if (this.failure)
|
|
1322
|
+
throw this.failure.reason;
|
|
1323
|
+
this.send({ source: "math.gl/tasks", kind: "event", id: 0, operation, value }, transfer);
|
|
1324
|
+
}
|
|
1325
|
+
/** Dispatch a transport message; unrelated protocols are ignored. */
|
|
1326
|
+
receive(message) {
|
|
1327
|
+
if (this.failure || message?.source !== "math.gl/tasks")
|
|
1328
|
+
return;
|
|
1329
|
+
if (message.kind === "failure") {
|
|
1330
|
+
const reason = new Error(message.error?.message ?? "Task channel failed");
|
|
1331
|
+
this.close(reason);
|
|
1332
|
+
this.options.onFailure?.(reason);
|
|
1333
|
+
} else if (message.kind === "result" || message.kind === "error") {
|
|
1334
|
+
const pending2 = this.pending.get(message.id);
|
|
1335
|
+
if (!pending2)
|
|
1336
|
+
return;
|
|
1337
|
+
this.pending.delete(message.id);
|
|
1338
|
+
pending2.cleanup();
|
|
1339
|
+
if (message.kind === "result")
|
|
1340
|
+
pending2.resolve(message.value);
|
|
1341
|
+
else {
|
|
1342
|
+
const error = new TaskRequestError(message.error?.message ?? "Task request failed");
|
|
1343
|
+
error.name = message.error?.name ?? "Error";
|
|
1344
|
+
pending2.reject(error);
|
|
1345
|
+
}
|
|
1346
|
+
} else if (message.kind === "cancel") {
|
|
1347
|
+
this.incoming.get(message.id)?.abort(new DOMException("Task request cancelled", "AbortError"));
|
|
1348
|
+
} else if (message.kind === "event") {
|
|
1349
|
+
try {
|
|
1350
|
+
this.options.handleEvent?.(message.operation, message.value);
|
|
1351
|
+
} catch (error) {
|
|
1352
|
+
this.fail(error);
|
|
1353
|
+
}
|
|
1354
|
+
} else if (message.kind === "request") {
|
|
1355
|
+
if (this.incoming.has(message.id)) {
|
|
1356
|
+
this.fail(new Error("Duplicate task request identifier"));
|
|
1357
|
+
return;
|
|
1358
|
+
}
|
|
1359
|
+
const controller = new AbortController();
|
|
1360
|
+
this.incoming.set(message.id, controller);
|
|
1361
|
+
void Promise.resolve().then(() => {
|
|
1362
|
+
controller.signal.throwIfAborted();
|
|
1363
|
+
return this.options.handleRequest(message.operation, message.value, controller.signal);
|
|
1364
|
+
}).then((value) => {
|
|
1365
|
+
if (!controller.signal.aborted && !this.failure) {
|
|
1366
|
+
this.send({ source: "math.gl/tasks", kind: "result", id: message.id, value }, this.options.getResultTransferList?.(value, message.value));
|
|
1367
|
+
}
|
|
1368
|
+
}).catch((reason) => {
|
|
1369
|
+
if (!controller.signal.aborted && !this.failure) {
|
|
1370
|
+
this.send({
|
|
1371
|
+
source: "math.gl/tasks",
|
|
1372
|
+
kind: "error",
|
|
1373
|
+
id: message.id,
|
|
1374
|
+
error: {
|
|
1375
|
+
name: reason instanceof Error ? reason.name : "Error",
|
|
1376
|
+
message: reason instanceof Error ? reason.message : String(reason)
|
|
1377
|
+
}
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
}).finally(() => this.incoming.delete(message.id));
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
/** Reject all outstanding calls with a common cause and abort incoming callbacks. */
|
|
1384
|
+
close(reason = new Error("Task channel closed")) {
|
|
1385
|
+
if (this.failure)
|
|
1386
|
+
return;
|
|
1387
|
+
this.failure = { reason };
|
|
1388
|
+
for (const pending2 of this.pending.values()) {
|
|
1389
|
+
pending2.cleanup();
|
|
1390
|
+
pending2.reject(reason);
|
|
1391
|
+
}
|
|
1392
|
+
this.pending.clear();
|
|
1393
|
+
for (const controller of this.incoming.values())
|
|
1394
|
+
controller.abort(reason);
|
|
1395
|
+
this.incoming.clear();
|
|
1396
|
+
}
|
|
1397
|
+
send(message, transfer = []) {
|
|
1398
|
+
if (this.failure)
|
|
1399
|
+
return;
|
|
1400
|
+
try {
|
|
1401
|
+
this.options.send(message, transfer);
|
|
1402
|
+
} catch (error) {
|
|
1403
|
+
this.fail(error);
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
/** Invalidate the channel and notify the peer when the transport still works. */
|
|
1407
|
+
fail(reason) {
|
|
1408
|
+
if (this.failure)
|
|
1409
|
+
return;
|
|
1410
|
+
this.close(reason);
|
|
1411
|
+
try {
|
|
1412
|
+
this.options.send({
|
|
1413
|
+
source: "math.gl/tasks",
|
|
1414
|
+
kind: "failure",
|
|
1415
|
+
id: 0,
|
|
1416
|
+
error: {
|
|
1417
|
+
name: reason instanceof Error ? reason.name : "Error",
|
|
1418
|
+
message: reason instanceof Error ? reason.message : String(reason)
|
|
1419
|
+
}
|
|
1420
|
+
}, []);
|
|
1421
|
+
} catch {
|
|
1422
|
+
}
|
|
1423
|
+
this.options.onFailure?.(reason);
|
|
1424
|
+
}
|
|
1425
|
+
};
|
|
1426
|
+
|
|
1427
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-runtime.js
|
|
1428
|
+
function assertPayload(value) {
|
|
1429
|
+
if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) {
|
|
1430
|
+
throw new TypeError("Task payloads must be plain objects with named fields");
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
function clonePayload(value, ownership = "copy") {
|
|
1434
|
+
assertPayload(value);
|
|
1435
|
+
if (!["copy", "transfer", "share"].includes(ownership))
|
|
1436
|
+
throw new TypeError("Invalid input ownership");
|
|
1437
|
+
const transfer = getTransferList(value);
|
|
1438
|
+
if (ownership === "share" && transfer.length)
|
|
1439
|
+
throw new TypeError("Share requires shared storage");
|
|
1440
|
+
return structuredClone(value, {
|
|
1441
|
+
transfer: ownership === "transfer" ? transfer : []
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
function taskContext(state, context = {}) {
|
|
1445
|
+
const signal = context.signal ?? new AbortController().signal;
|
|
1446
|
+
return {
|
|
1447
|
+
state,
|
|
1448
|
+
signal,
|
|
1449
|
+
requestHost: async (operation, payload, controls) => {
|
|
1450
|
+
signal.throwIfAborted();
|
|
1451
|
+
if (!context.requestHost)
|
|
1452
|
+
throw new Error("No host request handler configured");
|
|
1453
|
+
return context.requestHost(operation, payload, controls);
|
|
1454
|
+
},
|
|
1455
|
+
emitHost: (operation, payload) => {
|
|
1456
|
+
signal.throwIfAborted();
|
|
1457
|
+
context.emitHost?.(operation, payload);
|
|
1458
|
+
},
|
|
1459
|
+
throwIfAborted: () => {
|
|
1460
|
+
signal.throwIfAborted();
|
|
1461
|
+
context.throwIfAborted?.();
|
|
1462
|
+
},
|
|
1463
|
+
reportProgress: (progress) => context.reportProgress?.({
|
|
1464
|
+
...progress,
|
|
1465
|
+
phase: progress.phase ?? "process",
|
|
1466
|
+
unit: progress.unit ?? "items"
|
|
1467
|
+
})
|
|
1468
|
+
};
|
|
1469
|
+
}
|
|
1470
|
+
var TaskRuntime = class {
|
|
1471
|
+
constructor(task) {
|
|
1472
|
+
this.task = task;
|
|
1473
|
+
this.initialized = false;
|
|
1474
|
+
}
|
|
1475
|
+
async initialize(input, context = {}) {
|
|
1476
|
+
if (this.initialized)
|
|
1477
|
+
throw new Error("Task is already initialized");
|
|
1478
|
+
assertPayload(input);
|
|
1479
|
+
await preloadTaskCode(this.task, context.signal);
|
|
1480
|
+
context.signal?.throwIfAborted();
|
|
1481
|
+
this.state = await this.task.initialize?.(input, taskContext(void 0, context));
|
|
1482
|
+
this.initialized = true;
|
|
1483
|
+
return {};
|
|
1484
|
+
}
|
|
1485
|
+
async destroy() {
|
|
1486
|
+
if (this.initialized) {
|
|
1487
|
+
this.initialized = false;
|
|
1488
|
+
const state = this.state;
|
|
1489
|
+
this.state = void 0;
|
|
1490
|
+
if (this.task.initialize)
|
|
1491
|
+
await this.task.destroy?.(state);
|
|
1492
|
+
}
|
|
1493
|
+
return {};
|
|
1494
|
+
}
|
|
1495
|
+
async process(input, options, context = {}) {
|
|
1496
|
+
if (!this.initialized)
|
|
1497
|
+
throw new Error("Task is not initialized");
|
|
1498
|
+
if (!this.task.process)
|
|
1499
|
+
throw new Error("Task has no atomic processor");
|
|
1500
|
+
assertPayload(input);
|
|
1501
|
+
const result = await this.task.process(input, options, taskContext(this.state, context));
|
|
1502
|
+
assertPayload(result);
|
|
1503
|
+
return result;
|
|
1504
|
+
}
|
|
1505
|
+
async *stream(inputs, options, context = {}) {
|
|
1506
|
+
if (!this.initialized)
|
|
1507
|
+
throw new Error("Task is not initialized");
|
|
1508
|
+
if (!this.task.processInBatches)
|
|
1509
|
+
throw new Error("Task has no streaming processor");
|
|
1510
|
+
for await (const output of this.task.processInBatches(inputs, options, taskContext(this.state, context))) {
|
|
1511
|
+
assertPayload(output);
|
|
1512
|
+
yield output;
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1516
|
+
async function initializeTaskWorker(task) {
|
|
1517
|
+
if (!await WorkerBody.inWorkerThread())
|
|
1518
|
+
throw new Error("initializeTaskWorker must run inside a worker");
|
|
1519
|
+
if (installed)
|
|
1520
|
+
throw new Error("A task is already installed in this worker");
|
|
1521
|
+
installed = true;
|
|
1522
|
+
const runtime = new TaskRuntime(task);
|
|
1523
|
+
let channelStream;
|
|
1524
|
+
const channel = new TaskChannel({
|
|
1525
|
+
getResultTransferList: (value, request) => request.outputOwnership === "transfer" ? getTransferList(value) : [],
|
|
1526
|
+
send: (message, transfer) => {
|
|
1527
|
+
const snapshot = structuredClone(message, { transfer });
|
|
1528
|
+
void WorkerBody.postMessage("task-channel", snapshot).catch((reason) => channel.fail(reason));
|
|
1529
|
+
},
|
|
1530
|
+
handleRequest: async (operation, value, signal) => {
|
|
1531
|
+
const request = value;
|
|
1532
|
+
const context = {
|
|
1533
|
+
signal,
|
|
1534
|
+
reportProgress: (progress) => channel.emit("task:progress", { id: request.progressId, progress }),
|
|
1535
|
+
requestHost: (operation2, payload, controls = {}) => {
|
|
1536
|
+
const request2 = {
|
|
1537
|
+
operation: operation2,
|
|
1538
|
+
payload: clonePayload(payload, controls.inputOwnership),
|
|
1539
|
+
outputOwnership: controls.outputOwnership ?? "copy"
|
|
1540
|
+
};
|
|
1541
|
+
return channel.request("task:host-request", request2, signal, getTransferList(request2));
|
|
1542
|
+
},
|
|
1543
|
+
emitHost: (operation2, payload) => channel.emit("task:host-event", { operation: operation2, payload, id: request.progressId })
|
|
1544
|
+
};
|
|
1545
|
+
switch (operation) {
|
|
1546
|
+
case "initialize":
|
|
1547
|
+
return runtime.initialize(request.input, context);
|
|
1548
|
+
case "process":
|
|
1549
|
+
return runtime.process(request.input, request.options, context);
|
|
1550
|
+
case "stream-open": {
|
|
1551
|
+
if (channelStream)
|
|
1552
|
+
throw new Error("A task stream is already open");
|
|
1553
|
+
async function* inputs() {
|
|
1554
|
+
while (true) {
|
|
1555
|
+
const result = await channel.request("task:next-input", { outputOwnership: "transfer" }, signal);
|
|
1556
|
+
if (result.done)
|
|
1557
|
+
return;
|
|
1558
|
+
yield result.value;
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
channelStream = runtime.stream(inputs(), request.options, context)[Symbol.asyncIterator]();
|
|
1562
|
+
return {};
|
|
1563
|
+
}
|
|
1564
|
+
case "stream-next":
|
|
1565
|
+
if (!channelStream)
|
|
1566
|
+
throw new Error("No active task stream");
|
|
1567
|
+
return channelStream.next();
|
|
1568
|
+
case "stream-close":
|
|
1569
|
+
try {
|
|
1570
|
+
await channelStream?.return?.();
|
|
1571
|
+
} finally {
|
|
1572
|
+
channelStream = void 0;
|
|
1573
|
+
}
|
|
1574
|
+
return {};
|
|
1575
|
+
case "destroy":
|
|
1576
|
+
return runtime.destroy();
|
|
1577
|
+
default:
|
|
1578
|
+
throw new Error("Unknown task channel operation");
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
});
|
|
1582
|
+
await WorkerBody.addEventListener((type, payload) => {
|
|
1583
|
+
if (type === "task-channel")
|
|
1584
|
+
channel.receive(payload);
|
|
1585
|
+
});
|
|
1586
|
+
let streamOptions = {};
|
|
1587
|
+
return createWorker(async (request, _options, context) => {
|
|
1588
|
+
switch (request.operation) {
|
|
1589
|
+
case "initialize":
|
|
1590
|
+
return runtime.initialize(request.input, context);
|
|
1591
|
+
case "destroy":
|
|
1592
|
+
return runtime.destroy();
|
|
1593
|
+
case "stream-options":
|
|
1594
|
+
streamOptions = request.options;
|
|
1595
|
+
return {};
|
|
1596
|
+
case "process":
|
|
1597
|
+
return runtime.process(request.input, request.options, context);
|
|
1598
|
+
default:
|
|
1599
|
+
throw new Error("Unknown task operation");
|
|
1600
|
+
}
|
|
1601
|
+
}, async function* (inputs, _options, context) {
|
|
1602
|
+
async function* batches() {
|
|
1603
|
+
for await (const input of inputs) {
|
|
1604
|
+
assertPayload(input);
|
|
1605
|
+
yield input;
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
try {
|
|
1609
|
+
yield* runtime.stream(batches(), streamOptions, context);
|
|
1610
|
+
} finally {
|
|
1611
|
+
streamOptions = {};
|
|
1612
|
+
}
|
|
1613
|
+
}, () => preloadTaskCode(task));
|
|
1614
|
+
}
|
|
1615
|
+
var installed = false;
|
|
1616
|
+
|
|
1617
|
+
// ../core/src/worker-utils/lib/worker-api/task-runtime.ts
|
|
1618
|
+
function normalizeTaskProgress(progress) {
|
|
1619
|
+
return { ...progress, phase: progress.phase ?? "process", unit: progress.unit ?? "items" };
|
|
1620
|
+
}
|
|
1621
|
+
async function isWorkerThread() {
|
|
1622
|
+
if (typeof self !== "undefined" && typeof document === "undefined" && typeof self.postMessage === "function")
|
|
1623
|
+
return true;
|
|
1624
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
1625
|
+
const { isMainThread } = await Promise.resolve().then(() => (init_worker_threads_browser(), worker_threads_browser_exports));
|
|
1626
|
+
return !isMainThread;
|
|
1627
|
+
}
|
|
1628
|
+
return false;
|
|
1629
|
+
}
|
|
1630
|
+
var initializeTaskWorker2 = initializeTaskWorker;
|
|
1631
|
+
|
|
1632
|
+
// ../core/src/worker-utils/lib/worker-utils/get-transfer-list.ts
|
|
1633
|
+
function getTransferList2(object, recursive = true, transfers) {
|
|
1634
|
+
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
1635
|
+
if (!object) {
|
|
1636
|
+
} else if (isTransferable2(object)) {
|
|
1637
|
+
transfersSet.add(object);
|
|
1638
|
+
} else if (isTransferable2(object.buffer)) {
|
|
1639
|
+
transfersSet.add(object.buffer);
|
|
1640
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
1641
|
+
} else if (recursive && typeof object === "object") {
|
|
1642
|
+
for (const key in object) {
|
|
1643
|
+
getTransferList2(object[key], recursive, transfersSet);
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
1647
|
+
}
|
|
1648
|
+
function isTransferable2(object) {
|
|
1649
|
+
if (!object) {
|
|
1650
|
+
return false;
|
|
1651
|
+
}
|
|
1652
|
+
if (object instanceof ArrayBuffer) {
|
|
1653
|
+
return true;
|
|
1654
|
+
}
|
|
1655
|
+
if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
|
|
1656
|
+
return true;
|
|
1657
|
+
}
|
|
1658
|
+
if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
|
|
1659
|
+
return true;
|
|
1660
|
+
}
|
|
1661
|
+
if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
|
|
1662
|
+
return true;
|
|
1663
|
+
}
|
|
1664
|
+
return false;
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
// ../core/src/worker-utils/lib/worker-api/create-worker.ts
|
|
1668
|
+
async function createWorker2(process2, processInBatches) {
|
|
1669
|
+
if (!await isWorkerThread()) return;
|
|
1670
|
+
await initializeTaskWorker2(createWorkerTask(process2, processInBatches));
|
|
1671
|
+
}
|
|
1672
|
+
function createWorkerTask(process2, processInBatches) {
|
|
1673
|
+
return {
|
|
1674
|
+
id: "loaders.gl",
|
|
1675
|
+
initialize: (state) => state,
|
|
1676
|
+
destroy: (state) => state.port?.close(),
|
|
1677
|
+
process: async ({ value }, options, context) => {
|
|
1678
|
+
if (!process2) throw new Error("Worker does not support atomic processing");
|
|
1679
|
+
return { value: await process2(value, options, createContext(context), context.state.context) };
|
|
1680
|
+
},
|
|
1681
|
+
...processInBatches ? {
|
|
1682
|
+
processInBatches: async function* (inputs, options, context) {
|
|
1683
|
+
async function* values() {
|
|
1684
|
+
for await (const input of inputs) yield input.value;
|
|
1685
|
+
}
|
|
1686
|
+
for await (const value of processInBatches(
|
|
1687
|
+
values(),
|
|
1688
|
+
options,
|
|
1689
|
+
createContext(context),
|
|
1690
|
+
context.state.context
|
|
1691
|
+
)) {
|
|
1692
|
+
yield { value };
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
} : {}
|
|
1696
|
+
};
|
|
1697
|
+
}
|
|
1698
|
+
function createContext(context) {
|
|
1699
|
+
let requestIdentifier = 0;
|
|
1700
|
+
const port = context.state.port;
|
|
1701
|
+
return {
|
|
1702
|
+
signal: context.signal,
|
|
1703
|
+
throwIfAborted: () => context.throwIfAborted(),
|
|
1704
|
+
reportProgress: (progress) => context.reportProgress(normalizeTaskProgress(progress)),
|
|
1705
|
+
process: port ? (input, options = {}, jobContext = {}) => {
|
|
1706
|
+
context.throwIfAborted();
|
|
1707
|
+
const identifier = ++requestIdentifier;
|
|
1708
|
+
return new Promise((resolve, reject) => {
|
|
1709
|
+
const onMessage = (event) => {
|
|
1710
|
+
if (event.data.identifier !== identifier) return;
|
|
1711
|
+
cleanup();
|
|
1712
|
+
if (event.data.error) {
|
|
1713
|
+
const error = new Error(event.data.error.message);
|
|
1714
|
+
error.name = event.data.error.name;
|
|
1715
|
+
reject(error);
|
|
1716
|
+
} else resolve(event.data.value);
|
|
1717
|
+
};
|
|
1718
|
+
const onAbort = () => {
|
|
1719
|
+
cleanup();
|
|
1720
|
+
reject(context.signal.reason);
|
|
1721
|
+
};
|
|
1722
|
+
const cleanup = () => {
|
|
1723
|
+
port.removeEventListener("message", onMessage);
|
|
1724
|
+
context.signal.removeEventListener("abort", onAbort);
|
|
1725
|
+
};
|
|
1726
|
+
port.addEventListener("message", onMessage);
|
|
1727
|
+
context.signal.addEventListener("abort", onAbort, { once: true });
|
|
1728
|
+
port.start();
|
|
1729
|
+
try {
|
|
1730
|
+
const request = { identifier, input, options, context: jobContext };
|
|
1731
|
+
port.postMessage(request, getTransferList2(request));
|
|
1732
|
+
} catch (error) {
|
|
1733
|
+
cleanup();
|
|
1734
|
+
reject(error);
|
|
1735
|
+
}
|
|
1736
|
+
});
|
|
1737
|
+
} : void 0
|
|
1738
|
+
};
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1234
1741
|
// ../core/src/loader-utils/lib/worker-loader-utils/create-loader-worker.ts
|
|
1235
1742
|
async function createLoaderWorker(loader, selectLoader = () => loader) {
|
|
1236
|
-
await
|
|
1743
|
+
await createWorker2(
|
|
1237
1744
|
(input, options, workerContext, loaderContext) => processLoaderWorkerData(
|
|
1238
1745
|
selectLoader(options || {}),
|
|
1239
1746
|
input,
|