@netless/appliance-plugin 1.1.43-beta.1 → 1.1.43-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/appliance-plugin.js +1 -1
- package/dist/appliance-plugin.mjs +1 -1
- package/dist/{bridge-CDqtVTPN.js → bridge-CjP_hVOP.js} +1 -1
- package/dist/{bridge-nmqVpnZ5.mjs → bridge-DDjnM21Q.mjs} +1 -1
- package/dist/bridge.js +1 -1
- package/dist/bridge.mjs +1 -1
- package/dist/core/mainEngine.d.ts +1 -0
- package/dist/core/mainThread/subLocalThread.d.ts +3 -1
- package/dist/core/worker/fullWorkerLocal.d.ts +2 -1
- package/dist/fullWorker.js +25 -25
- package/dist/{index-BJOPyRJn.js → index-0kVavCij.js} +1 -1
- package/dist/{index-DhCFlEfW.mjs → index-9PPheeLn.mjs} +9048 -9033
- package/dist/{index-B44o9ggV.mjs → index-BJ0z6a4a.mjs} +30 -15
- package/dist/{index-Cjaia8CY.mjs → index-CWYxJZvD.mjs} +58 -46
- package/dist/{index-DDd-30M7.js → index-CfY3_e4d.js} +1 -1
- package/dist/index-CnrGW2oH.js +1 -0
- package/dist/{index-BF310Wzc.mjs → index-D0sxmVc0.mjs} +1 -1
- package/dist/index-DvSdT6k5.js +1 -0
- package/dist/{index-DdbAM7Xi.mjs → index-DvrjPbBe.mjs} +58 -46
- package/dist/{index-mcBiJOLo.mjs → index-NA6eaAqy.mjs} +1 -1
- package/dist/index-S6ml0iJb.js +570 -0
- package/dist/{index-Cu0f4kha.js → index-bu6U96S2.js} +1 -1
- package/dist/subWorker.js +2 -2
- package/package.json +1 -1
- package/dist/index-BiqhUSZ0.js +0 -570
- package/dist/index-o1TaWHww.js +0 -1
- package/dist/index-puxStU6w.js +0 -1
|
@@ -19854,7 +19854,7 @@ const o0 = 500;
|
|
|
19854
19854
|
function zc(s) {
|
|
19855
19855
|
return typeof s != "number" || !Number.isFinite(s) || s <= 0 ? o0 : Math.max(1, Math.floor(s));
|
|
19856
19856
|
}
|
|
19857
|
-
const Bc = "1.1.43-beta.
|
|
19857
|
+
const Bc = "1.1.43-beta.3", Ipe = "@netless/appliance-plugin", Cpe = "6c6e2b9027f933e8", ju = 5e3, bpe = 1e4, Epe = 1e4;
|
|
19858
19858
|
if (typeof window < "u") {
|
|
19859
19859
|
let s = window.__netlessUA || "";
|
|
19860
19860
|
s += ` ${Ipe}@${Bc}`, window.__netlessUA = s;
|
|
@@ -27010,7 +27010,10 @@ const _a = class _a extends Ee {
|
|
|
27010
27010
|
this.recordFinalPointBatch(), this.getCandidateWorkIds().clear(), this.collectVectorCandidateWorkIds(this.tmpPoints, n), this.collectDeleteCandidatesForDone(this.tmpPoints, n);
|
|
27011
27011
|
for (const [u, h] of this.snapshotDoneCandidates())
|
|
27012
27012
|
i.set(u, h);
|
|
27013
|
-
|
|
27013
|
+
r && typeof r.publishBitmapEraserBeforeImages == "function" && r.publishBitmapEraserBeforeImages(
|
|
27014
|
+
this.workId,
|
|
27015
|
+
i
|
|
27016
|
+
), this.collectDoneVectorChanges(n), this.commitDoingFaces(), this.renderChangedNodes(
|
|
27014
27017
|
r,
|
|
27015
27018
|
this.workOptions.removeOnDone !== !1
|
|
27016
27019
|
), this.commitPendingDeletions(r);
|
|
@@ -35941,6 +35944,15 @@ class jwe extends Bwe {
|
|
|
35941
35944
|
const n = this.Logger, i = `[Appliance]: [main-view-camera] stage=${e} ${JSON.stringify(r)}`;
|
|
35942
35945
|
n.infoDebounced ? n.infoDebounced(`main-view-camera:${e}`, i) : n.info(i);
|
|
35943
35946
|
}
|
|
35947
|
+
logAppViewCameraTrace(e, r, n) {
|
|
35948
|
+
const i = this.Logger, o = `[Appliance]: [app-view-camera] stage=${r} ${JSON.stringify(
|
|
35949
|
+
{
|
|
35950
|
+
viewId: e,
|
|
35951
|
+
...n
|
|
35952
|
+
}
|
|
35953
|
+
)}`;
|
|
35954
|
+
i != null && i.infoDebounced ? i.infoDebounced(`app-view-camera:${e}:${r}`, o) : i && i.info(o);
|
|
35955
|
+
}
|
|
35944
35956
|
closeImageBitmap(e) {
|
|
35945
35957
|
var r;
|
|
35946
35958
|
if (e)
|
|
@@ -37339,12 +37351,12 @@ class jwe extends Bwe {
|
|
|
37339
37351
|
}
|
|
37340
37352
|
async useBackgroundThread() {
|
|
37341
37353
|
this.Logger.info("[Appliance]: use background thread");
|
|
37342
|
-
const { BackgroundThreadManagerImpl: e } = await import("./index-
|
|
37354
|
+
const { BackgroundThreadManagerImpl: e } = await import("./index-NA6eaAqy.mjs");
|
|
37343
37355
|
this.backgroundThreadManager = new e(this);
|
|
37344
37356
|
}
|
|
37345
37357
|
async useMainThread() {
|
|
37346
37358
|
this.Logger.info("[Appliance]: no OffscreenCanvas");
|
|
37347
|
-
const { MainThreadManagerImpl: e } = await import("./index-
|
|
37359
|
+
const { MainThreadManagerImpl: e } = await import("./index-CWYxJZvD.mjs");
|
|
37348
37360
|
this.mainThread = new e(this), this.isRenderTransportReady = !0, this.flushPendingTransportInitMessages();
|
|
37349
37361
|
}
|
|
37350
37362
|
getRenderProbeCandidates() {
|
|
@@ -39118,7 +39130,7 @@ class jwe extends Bwe {
|
|
|
39118
39130
|
}
|
|
39119
39131
|
onLocalEventDoing(e, r) {
|
|
39120
39132
|
var i;
|
|
39121
|
-
if (((i = this.currentToolsData) == null ? void 0 : i.toolsType) === Q.Text
|
|
39133
|
+
if (((i = this.currentToolsData) == null ? void 0 : i.toolsType) === Q.Text)
|
|
39122
39134
|
return;
|
|
39123
39135
|
this.currentLocalWorkData.workState === de.Start && this.setCurrentLocalWorkData({
|
|
39124
39136
|
...this.currentLocalWorkData,
|
|
@@ -39142,7 +39154,7 @@ class jwe extends Bwe {
|
|
|
39142
39154
|
), n = !0;
|
|
39143
39155
|
}
|
|
39144
39156
|
}
|
|
39145
|
-
if (n) {
|
|
39157
|
+
if (!this.forceDoneFullLayerBitmapEraseAtPointLimit(r) && n) {
|
|
39146
39158
|
this.runAnimation();
|
|
39147
39159
|
return;
|
|
39148
39160
|
}
|
|
@@ -39232,7 +39244,7 @@ class jwe extends Bwe {
|
|
|
39232
39244
|
maxInputPoints: c
|
|
39233
39245
|
}), this.markFullLayerBitmapEraseDoneStaging(a), this.localPointsBatchData.set(i, o), r = !0);
|
|
39234
39246
|
}
|
|
39235
|
-
return r && this.
|
|
39247
|
+
return r && this.checkDrawingWork(e), r;
|
|
39236
39248
|
}
|
|
39237
39249
|
pushLocalPoint(e, r, n, i, o) {
|
|
39238
39250
|
var c;
|
|
@@ -40784,7 +40796,12 @@ class jwe extends Bwe {
|
|
|
40784
40796
|
r,
|
|
40785
40797
|
n.taskId,
|
|
40786
40798
|
n.viewGeneration
|
|
40787
|
-
) || r.currentTaskId !== void 0 || r.pendingCamera || !n.coreAckReceived || !n.settledAckReceived || (e === Ue
|
|
40799
|
+
) || r.currentTaskId !== void 0 || r.pendingCamera || !n.coreAckReceived || !n.settledAckReceived || (e === Ue ? this.logMainViewCameraTrace("completed", {
|
|
40800
|
+
taskId: n.taskId,
|
|
40801
|
+
scenePath: n.scenePath,
|
|
40802
|
+
camera: n.camera,
|
|
40803
|
+
renderFinished: !0
|
|
40804
|
+
}) : this.logAppViewCameraTrace(e, "completed", {
|
|
40788
40805
|
taskId: n.taskId,
|
|
40789
40806
|
scenePath: n.scenePath,
|
|
40790
40807
|
camera: n.camera,
|
|
@@ -40973,15 +40990,13 @@ class jwe extends Bwe {
|
|
|
40973
40990
|
const r = /* @__PURE__ */ new Set();
|
|
40974
40991
|
let n = !1;
|
|
40975
40992
|
for (const [i, o] of this.localPointsBatchData.entries()) {
|
|
40976
|
-
const { state: a, viewId: c, toolsType: l, undoTickerId: u } = o
|
|
40977
|
-
|
|
40993
|
+
const { state: a, viewId: c, toolsType: l, undoTickerId: u } = o, h = this.getFullLayerBitmapEraseTxns().get(
|
|
40994
|
+
i.toString()
|
|
40995
|
+
), d = a === de.Done && o.isFullWork === !0 && l === Q.BitMapEraser && (h == null ? void 0 : h.phase) === "done-staging";
|
|
40996
|
+
if (e === c && (a === de.Start || a === de.Doing || d)) {
|
|
40978
40997
|
if (l === Q.Text)
|
|
40979
40998
|
continue;
|
|
40980
|
-
o.state = de.Done, o.isFullWork = !0, this.localPointsBatchData.set(i, o)
|
|
40981
|
-
const h = this.getFullLayerBitmapEraseTxns().get(
|
|
40982
|
-
i.toString()
|
|
40983
|
-
);
|
|
40984
|
-
(h == null ? void 0 : h.phase) === "doing" && this.markFullLayerBitmapEraseDoneStaging(h), u && (r.add(u), o.scenePath && l && Jl.has(l) ? this.internalMsgEmitter.emit(
|
|
40999
|
+
o.state = de.Done, o.isFullWork = !0, this.localPointsBatchData.set(i, o), (h == null ? void 0 : h.phase) === "doing" && this.markFullLayerBitmapEraseDoneStaging(h), u && (r.add(u), o.scenePath && l && Jl.has(l) ? this.internalMsgEmitter.emit(
|
|
40985
41000
|
"finalizeRequested",
|
|
40986
41001
|
u,
|
|
40987
41002
|
c,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var ye = Object.defineProperty;
|
|
2
2
|
var we = (M, e, t) => e in M ? ye(M, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : M[e] = t;
|
|
3
3
|
var u = (M, e, t) => we(M, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
-
import { D as K, e as b, c as m, r as $, b as R, g as Z, t as V, a as h, f as de, M as ve, h as D, i as j, j as ke, C as H, k as z, l as Se, m as te, n as Ie, o as se, p as ge, q as Te, s as re, u as ie, v as Y, w as _, E as N, x as ee, y as Q, z as We, A as Re, B as Ee, F as be, G as Le, H as pe, I as ue, T as oe, J as ae, K as Ce, L as Ne, N as fe, P as me, Q as ne, R as
|
|
4
|
+
import { D as K, e as b, c as m, r as $, b as R, g as Z, t as V, a as h, f as de, M as ve, h as D, i as j, j as ke, C as H, k as z, l as Se, m as te, n as Ie, o as se, p as ge, q as Te, s as re, u as ie, v as Y, w as _, E as N, x as ee, y as Q, z as We, A as Re, B as Ee, F as be, G as Le, H as pe, I as ue, T as oe, J as ae, K as Ce, L as Ne, N as fe, P as me, Q as ne, R as Be, S as ce, U as q, W as Oe, V as he, X as De } from "./index-BJ0z6a4a.mjs";
|
|
5
5
|
import { cloneDeep as J, xor as Me, isNumber as G, isEqual as le } from "lodash";
|
|
6
6
|
import "clipper-lib";
|
|
7
7
|
import "lineclip";
|
|
@@ -700,6 +700,18 @@ class Ae {
|
|
|
700
700
|
const t = this.workShapes.get(e);
|
|
701
701
|
(t == null ? void 0 : t.toolsType) === m.BitMapEraser && (t.clearTmpPoints(), this.workShapes.delete(e), this.combineDrawActiveId === e && (this.combineDrawActiveId = void 0), this.drawWorkActiveId === e && (this.drawWorkActiveId = void 0), this.bitmapEraserRenderQueue = Promise.resolve());
|
|
702
702
|
}
|
|
703
|
+
publishBitmapEraserBeforeImages(e, t) {
|
|
704
|
+
t.size && this.thread.post({
|
|
705
|
+
sp: [
|
|
706
|
+
{
|
|
707
|
+
type: h.None,
|
|
708
|
+
viewId: this.thread.viewId,
|
|
709
|
+
eraseTxnId: e,
|
|
710
|
+
eraseTxnBeforeImages: new Map(t)
|
|
711
|
+
}
|
|
712
|
+
]
|
|
713
|
+
});
|
|
714
|
+
}
|
|
703
715
|
async drawBitMapEraserFull(e, t, s, r) {
|
|
704
716
|
const {
|
|
705
717
|
willUpdateNodes: i,
|
|
@@ -1272,9 +1284,9 @@ class Fe {
|
|
|
1272
1284
|
(r = k.node) == null || r.consumeService({
|
|
1273
1285
|
isFullWork: !0,
|
|
1274
1286
|
replaceId: E
|
|
1275
|
-
}), this.selectorWorkShapes.forEach((
|
|
1287
|
+
}), this.selectorWorkShapes.forEach((B, O) => {
|
|
1276
1288
|
var P;
|
|
1277
|
-
(P =
|
|
1289
|
+
(P = B.selectIds) != null && P.includes(E) && (this.willRunEffectSelectorIds.add(O), this.runEffect());
|
|
1278
1290
|
}), this.workShapes.delete(E);
|
|
1279
1291
|
break;
|
|
1280
1292
|
}
|
|
@@ -1282,9 +1294,9 @@ class Fe {
|
|
|
1282
1294
|
await ((i = k.node) == null ? void 0 : i.consumeServiceAsync({
|
|
1283
1295
|
isFullWork: !0,
|
|
1284
1296
|
worker: this
|
|
1285
|
-
})), this.selectorWorkShapes.forEach((
|
|
1297
|
+
})), this.selectorWorkShapes.forEach((B, O) => {
|
|
1286
1298
|
var P;
|
|
1287
|
-
(P =
|
|
1299
|
+
(P = B.selectIds) != null && P.includes(E) && (this.willRunEffectSelectorIds.add(O), this.runEffect());
|
|
1288
1300
|
}), this.workShapes.delete(E);
|
|
1289
1301
|
break;
|
|
1290
1302
|
}
|
|
@@ -1293,9 +1305,9 @@ class Fe {
|
|
|
1293
1305
|
isFullWork: !0,
|
|
1294
1306
|
replaceId: E,
|
|
1295
1307
|
boxRect: this.thread.getSceneRect()
|
|
1296
|
-
})), this.selectorWorkShapes.forEach((
|
|
1308
|
+
})), this.selectorWorkShapes.forEach((B, O) => {
|
|
1297
1309
|
var P;
|
|
1298
|
-
(P =
|
|
1310
|
+
(P = B.selectIds) != null && P.includes(E) && (this.willRunEffectSelectorIds.add(O), this.runEffect());
|
|
1299
1311
|
}), k.refreshTextRender && k.requestId && s.push({
|
|
1300
1312
|
type: h.RefreshTextRender,
|
|
1301
1313
|
requestId: k.requestId,
|
|
@@ -1311,20 +1323,20 @@ class Fe {
|
|
|
1311
1323
|
case m.Star:
|
|
1312
1324
|
case m.Polygon:
|
|
1313
1325
|
case m.SpeechBalloon: {
|
|
1314
|
-
const
|
|
1326
|
+
const B = !!k.ops;
|
|
1315
1327
|
if ((n = k.animationWorkData) != null && n.length) {
|
|
1316
|
-
const
|
|
1328
|
+
const O = k.oldRect;
|
|
1317
1329
|
(c = k.node) == null || c.consumeService({
|
|
1318
1330
|
op: k.animationWorkData,
|
|
1319
|
-
isFullWork:
|
|
1320
|
-
}),
|
|
1331
|
+
isFullWork: B
|
|
1332
|
+
}), B && (this.selectorWorkShapes.forEach((P, F) => {
|
|
1321
1333
|
var U;
|
|
1322
1334
|
(U = P.selectIds) != null && U.includes(E) && (this.willRunEffectSelectorIds.add(F), this.runEffect());
|
|
1323
1335
|
}), (d = k.node) == null || d.clearTmpPoints(), this.workShapes.delete(E)), k.isEnableCursor ? t.set(E, {
|
|
1324
1336
|
cursorTool: _(k.toolsType),
|
|
1325
|
-
workState:
|
|
1337
|
+
workState: O ? k.ops ? b.Done : b.Doing : b.Start,
|
|
1326
1338
|
op: k.animationWorkData.slice(-3, -1)
|
|
1327
|
-
}) :
|
|
1339
|
+
}) : B && !k.useAnimation && ((l = k.updateNodeOpt) != null && l.useAnimation) && t.set(E, {
|
|
1328
1340
|
cursorTool: _(k.toolsType),
|
|
1329
1341
|
workState: b.Done,
|
|
1330
1342
|
op: k.animationWorkData.slice(-3, -1),
|
|
@@ -1340,22 +1352,22 @@ class Fe {
|
|
|
1340
1352
|
(y = k.node) == null || y.clearTmpPoints(), this.workShapes.delete(E);
|
|
1341
1353
|
break;
|
|
1342
1354
|
}
|
|
1343
|
-
const
|
|
1355
|
+
const B = 3, O = this.computNextAnimationIndex(
|
|
1344
1356
|
k,
|
|
1345
|
-
O
|
|
1346
|
-
), P = k.isDiff ? 0 : Math.max(0, (k.animationIndex || 0) - O), F = (k.animationWorkData || []).slice(
|
|
1347
|
-
P,
|
|
1348
1357
|
B
|
|
1358
|
+
), P = k.isDiff ? 0 : Math.max(0, (k.animationIndex || 0) - B), F = (k.animationWorkData || []).slice(
|
|
1359
|
+
P,
|
|
1360
|
+
O
|
|
1349
1361
|
), U = (T = (v = k.node) == null ? void 0 : v.getWorkId()) == null ? void 0 : T.toString();
|
|
1350
|
-
if ((k.animationIndex || 0) <
|
|
1362
|
+
if ((k.animationIndex || 0) < O || k.isDiff) {
|
|
1351
1363
|
if ((C = k.node) == null || C.consumeService({
|
|
1352
1364
|
op: F,
|
|
1353
1365
|
isFullWork: !1
|
|
1354
|
-
}), k.animationIndex =
|
|
1366
|
+
}), k.animationIndex = O, k.isDiff && (k.isDiff = !1), F.length && k.isEnableCursor) {
|
|
1355
1367
|
const X = F.slice(-3, -1);
|
|
1356
1368
|
t.set(E, {
|
|
1357
1369
|
cursorTool: _(k.toolsType),
|
|
1358
|
-
workState: P === 0 ? b.Start :
|
|
1370
|
+
workState: P === 0 ? b.Start : O === ((L = k.animationWorkData) == null ? void 0 : L.length) ? b.Done : b.Doing,
|
|
1359
1371
|
op: X
|
|
1360
1372
|
});
|
|
1361
1373
|
}
|
|
@@ -1372,24 +1384,24 @@ class Fe {
|
|
|
1372
1384
|
break;
|
|
1373
1385
|
}
|
|
1374
1386
|
} else {
|
|
1375
|
-
const
|
|
1387
|
+
const B = !!k.ops;
|
|
1376
1388
|
if ((f = k.node) == null || f.consumeService({
|
|
1377
1389
|
op: k.animationWorkData || [],
|
|
1378
|
-
isFullWork:
|
|
1390
|
+
isFullWork: B,
|
|
1379
1391
|
replaceId: E
|
|
1380
|
-
}), (w = k.node) == null || w.updataOptService(k.updateNodeOpt),
|
|
1392
|
+
}), (w = k.node) == null || w.updataOptService(k.updateNodeOpt), B) {
|
|
1381
1393
|
if (!k.isEnableCursor && ((S = k.updateNodeOpt) != null && S.useAnimation) && ((I = k.animationWorkData) != null && I.length)) {
|
|
1382
|
-
const
|
|
1394
|
+
const O = k.animationWorkData.slice(-3, -1);
|
|
1383
1395
|
t.set(E, {
|
|
1384
1396
|
cursorTool: _(k.toolsType),
|
|
1385
1397
|
workState: b.Done,
|
|
1386
|
-
op:
|
|
1398
|
+
op: O,
|
|
1387
1399
|
uid: (W = k.updateNodeOpt) == null ? void 0 : W.uid
|
|
1388
1400
|
});
|
|
1389
1401
|
}
|
|
1390
|
-
this.selectorWorkShapes.forEach((
|
|
1402
|
+
this.selectorWorkShapes.forEach((O, P) => {
|
|
1391
1403
|
var F;
|
|
1392
|
-
(F =
|
|
1404
|
+
(F = O.selectIds) != null && F.includes(E) && (this.willRunEffectSelectorIds.add(P), this.runEffect());
|
|
1393
1405
|
}), (g = k.node) == null || g.clearTmpPoints(), this.workShapes.delete(E);
|
|
1394
1406
|
}
|
|
1395
1407
|
}
|
|
@@ -2979,9 +2991,9 @@ class je {
|
|
|
2979
2991
|
for (const [T, C] of f.entries()) {
|
|
2980
2992
|
const L = this.vNodes.get(T);
|
|
2981
2993
|
if (L) {
|
|
2982
|
-
const A = C, E = L.rect, k = this.getSceneRect(),
|
|
2994
|
+
const A = C, E = L.rect, k = this.getSceneRect(), B = ae(A, k), O = ae(E, k);
|
|
2983
2995
|
let P = c;
|
|
2984
|
-
(
|
|
2996
|
+
(B !== O || A.w !== E.w || A.h !== E.h || O === Ce.intersect) && (P = !0);
|
|
2985
2997
|
const { toolsType: F, opt: U } = L, X = U.eraserlines && U.eraserlines.length > 0 || !!U.eraserFaces;
|
|
2986
2998
|
(P || p && X) && (F === m.Text || X) && this.debounceUpdateCache.add(T);
|
|
2987
2999
|
}
|
|
@@ -3009,17 +3021,17 @@ class je {
|
|
|
3009
3021
|
if (!v()) return;
|
|
3010
3022
|
const C = [];
|
|
3011
3023
|
for (const E of this.debounceUpdateCache.values()) {
|
|
3012
|
-
const k = (T = this.fullLayer) == null ? void 0 : T.getElementsByName(E)[0],
|
|
3013
|
-
if (
|
|
3014
|
-
const { toolsType:
|
|
3015
|
-
if (k ||
|
|
3024
|
+
const k = (T = this.fullLayer) == null ? void 0 : T.getElementsByName(E)[0], B = this.vNodes.get(E);
|
|
3025
|
+
if (B) {
|
|
3026
|
+
const { toolsType: O, opt: P } = B;
|
|
3027
|
+
if (k || O !== m.Text) {
|
|
3016
3028
|
const F = this.localWork.setFullWork({
|
|
3017
|
-
toolsType:
|
|
3029
|
+
toolsType: O,
|
|
3018
3030
|
opt: P,
|
|
3019
3031
|
workId: E
|
|
3020
3032
|
});
|
|
3021
3033
|
if (F) {
|
|
3022
|
-
if (
|
|
3034
|
+
if (O === m.Text)
|
|
3023
3035
|
C.push(
|
|
3024
3036
|
F.consumeServiceAsync({
|
|
3025
3037
|
isFullWork: !0,
|
|
@@ -3030,7 +3042,7 @@ class je {
|
|
|
3030
3042
|
);
|
|
3031
3043
|
else if (P.eraserlines && P.eraserlines.length > 0 || P.eraserFaces) {
|
|
3032
3044
|
const U = F.consumeService({
|
|
3033
|
-
op:
|
|
3045
|
+
op: B.op,
|
|
3034
3046
|
isFullWork: !0,
|
|
3035
3047
|
replaceId: E,
|
|
3036
3048
|
workState: b.Done
|
|
@@ -3604,7 +3616,7 @@ class Je {
|
|
|
3604
3616
|
for (const r of s.sp) {
|
|
3605
3617
|
let i = !1;
|
|
3606
3618
|
for (const o of e)
|
|
3607
|
-
if (
|
|
3619
|
+
if (Be(r, o)) {
|
|
3608
3620
|
i = !0;
|
|
3609
3621
|
break;
|
|
3610
3622
|
}
|
|
@@ -3757,7 +3769,7 @@ class lt {
|
|
|
3757
3769
|
consumeWorkId: p
|
|
3758
3770
|
} = e;
|
|
3759
3771
|
if (c && q(i)) {
|
|
3760
|
-
const f =
|
|
3772
|
+
const f = Oe(
|
|
3761
3773
|
o,
|
|
3762
3774
|
a,
|
|
3763
3775
|
"mainThread"
|
|
@@ -3912,7 +3924,7 @@ class lt {
|
|
|
3912
3924
|
if (o === h.Init) {
|
|
3913
3925
|
const g = i.viewGeneration ?? (this.viewGenerationById.get(a) || 0) + 1;
|
|
3914
3926
|
await this.enqueueViewTask(a, async () => {
|
|
3915
|
-
var E, k,
|
|
3927
|
+
var E, k, B;
|
|
3916
3928
|
const y = this.viewGenerationById.get(a);
|
|
3917
3929
|
if (y !== void 0 && g < y)
|
|
3918
3930
|
return;
|
|
@@ -3933,11 +3945,11 @@ class lt {
|
|
|
3933
3945
|
canvasOpt: p,
|
|
3934
3946
|
viewOwner: v,
|
|
3935
3947
|
viewGeneration: g,
|
|
3936
|
-
mainThreadRenderMode: ((
|
|
3937
|
-
post: (
|
|
3938
|
-
...
|
|
3939
|
-
viewId:
|
|
3940
|
-
viewGeneration:
|
|
3948
|
+
mainThreadRenderMode: ((B = (k = this.master.control) == null ? void 0 : k.renderingCompatibilityDecision) == null ? void 0 : B.mainThreadRenderMode) ?? "normal",
|
|
3949
|
+
post: (O) => this.post({
|
|
3950
|
+
...O,
|
|
3951
|
+
viewId: O.viewId || a,
|
|
3952
|
+
viewGeneration: O.viewGeneration ?? g,
|
|
3941
3953
|
viewOwner: v
|
|
3942
3954
|
})
|
|
3943
3955
|
});
|
|
@@ -3984,9 +3996,9 @@ class lt {
|
|
|
3984
3996
|
surface: L
|
|
3985
3997
|
}), k.on(i).then(() => {
|
|
3986
3998
|
this.disposeSnapshotThread(T, k);
|
|
3987
|
-
}).catch((
|
|
3999
|
+
}).catch((B) => {
|
|
3988
4000
|
this.master.Logger.error(
|
|
3989
|
-
`[Appliance]: snapshot render failed; viewId=${a}; error=${
|
|
4001
|
+
`[Appliance]: snapshot render failed; viewId=${a}; error=${B instanceof Error ? B.message : String(B)}`
|
|
3990
4002
|
), this.disposeSnapshotThread(T, k);
|
|
3991
4003
|
});
|
|
3992
4004
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var B=Object.defineProperty;var L=(n,e,t)=>e in n?B(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var d=(n,e,t)=>L(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./index-BiqhUSZ0.js"),v=require("lodash");require("clipper-lib");require("lz-string");require("lineclip");require("xss");require("rbush");require("react-dom");require("react");class C{constructor(){d(this,"threadEngine")}registerBackgroundThread(e){return this.threadEngine=e,this}}class W extends C{constructor(){super(...arguments);d(this,"emitEventType",c.EmitEventType.CopyNode)}async consume(t){const{msgType:s,dataType:r,emitEventType:a}=t;if(s===c.EPostMessageType.FullWork&&r===c.EDataType.Local&&a===this.emitEventType)return this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var r;const{workId:s}=t;s&&await((r=this.threadEngine)==null?void 0:r.consumeFull(t))}}class F{constructor(e){d(this,"builders",new Map);this.builders=new Map(e.map(t=>[t,this.build(t)]))}build(e){switch(e){case c.EmitEventType.CopyNode:return new W}}registerForBackgroundThread(e){return this.builders.forEach(t=>{t&&t.registerBackgroundThread(e)}),this}async consumeForBackgroundThread(e){for(const t of this.builders.values())if(await(t==null?void 0:t.consume(e)))return!0;return!1}}async function R(n){const e=n.querySelectorAll("img"),t=Array.from(e).map(a=>{if(!a.crossOrigin&&a.src&&!a.src.startsWith("data:")&&(a.crossOrigin="anonymous",a.complete)){const i=a.src;a.src="",a.src=i}return a.complete&&a.crossOrigin?Promise.resolve():new Promise(i=>{a.onload=()=>{i(void 0)},a.onerror=()=>{i(void 0)}})});return n.querySelectorAll("svg").forEach(a=>{a.querySelectorAll("image").forEach(o=>{o.href&&!o.href.baseVal.startsWith("data:")&&(o.getAttribute("crossorigin")||o.setAttribute("crossorigin","anonymous"),t.push(new Promise(l=>{const h=new Image;h.crossOrigin="anonymous",h.onload=()=>{l(void 0)},h.onerror=()=>{l(void 0)},h.src=o.href.baseVal})))})}),await Promise.all(t)}async function A(n){const s=Date.now();let r=!1;for(;Date.now()-s<5e3;){const a=n.querySelectorAll("path");if(a.length>0&&(r=Array.from(a).some(i=>{const o=i.getAttribute("d")||"";return o!=="M0,0C0,0,0,0,0,0"&&o.length>10}),r))break;await new Promise(i=>setTimeout(i,50))}}async function x(n){const e=n.querySelectorAll("svg");if(!e.length)return;const t=[];for(let s=0;s<e.length;s++){const r=e[s];t.push(A(r))}await Promise.all(t)}async function O(n){if(n.querySelectorAll("svg[data-type='mermaid']").length>0){const s=Date.now();let r=!1;for(;Date.now()-s<5e3&&!r;){const a=n.querySelectorAll("foreignObject");if(a.length>0){let i=!0;for(const o of Array.from(a)){const l=parseFloat(o.getAttribute("width")||"0"),h=parseFloat(o.getAttribute("height")||"0");if(o.querySelector(".mermaid-container")&&(l<50||h<50)){i=!1;break}}if(i){r=!0;break}}else r=!0;await new Promise(i=>setTimeout(i,50))}}}async function $(n,e={}){const{width:t=n.offsetWidth,height:s=n.offsetHeight}=e,r=n.offsetWidth||t,a=n.offsetHeight||s;try{const{loadSvgToImageLib:i,getSvgToImageLib:o}=await Promise.resolve().then(()=>require("./svgToImageLoader-B3gIDAQo.js"));let l=o();if(!l)try{l=await i()}catch(u){return console.error("[loadSvgToImageLib] error: ",u),null}const h=n.style.width,y=n.style.height,w=n.style.display;n.style.width||(n.style.width=`${r}px`),n.style.height||(n.style.height=`${a}px`),(!n.style.display||n.style.display==="none")&&(n.style.display="block");try{await new Promise(p=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{p()})})});const u=await l.toPng(n,{width:r,height:a,quality:1});return n.style.width=h,n.style.height=y,n.style.display=w,new Promise(p=>{const g=new Image;g.crossOrigin="anonymous",g.onload=()=>{p(g)},g.onerror=()=>{p(null)},g.src=u})}catch(u){return n.style.width=h,n.style.height=y,n.style.display=w,console.error("[divToImageElement] error: ",u),null}}catch(i){return console.error("[divToImageElement] error: ",i),null}}class V{constructor(e){d(this,"toolsType",c.EToolsKey.BackgroundSVG);d(this,"vNodes");d(this,"workOptions");d(this,"workId");d(this,"markmapInstance",null);d(this,"isDestroyed",!1);d(this,"element");d(this,"manager");d(this,"scenePath");d(this,"trackBackgroundImageLoad");d(this,"reloadSourceUrl");const{vNodes:t,workId:s,toolsOpt:r,manager:a,scenePath:i,trackBackgroundImageLoad:o=!0}=e;this.workId=s,this.vNodes=t,this.workOptions=r,this.manager=a,this.scenePath=i,this.trackBackgroundImageLoad=o,this.element=this.createElement(),this.manager.fullLayer.appendChild(this.element),this.vNodes.setInfo(this.workId,{workShape:this})}get fullLayer(){return this.manager.fullLayer}get collector(){return this.manager.master.control.collector}async init(){await this.render()}createElement(){const{type:e}=this.workOptions;let t;return e===c.ESVGType.markmap?(t=document.createElementNS("http://www.w3.org/2000/svg","svg"),t.classList.add("svg")):(t=document.createElement("img"),t.classList.add("img")),t.id=this.workId,t.setAttribute("data-id",this.workId),t}async render(e){this.isDestroyed||!this.element||!this.element.parentNode||(this.updateElementPosition(e),await this.updateSvg(e))}isSameSize(e){const{width:t,height:s}=e,{width:r,height:a}=this.workOptions,i=t*this.manager.camera.scale,o=s*this.manager.camera.scale,l=r*this.manager.camera.scale,h=a*this.manager.camera.scale;return i===l&&o===h}isSamePosition(e){const{centerX:t,centerY:s}=e,{centerX:r,centerY:a}=this.workOptions,i=this.manager.getPagePoint(r,a),o=this.manager.getPagePoint(t,s);return v.isEqual(o,i)}isSameZIndex(e){const{zIndex:t}=e,{zIndex:s}=this.workOptions;return t===s}isSameState(e){const{state:t}=e,{state:s}=this.workOptions;return v.isEqual(t,s)}isSameData(e){const{data:t}=e,{data:s}=this.workOptions;return v.isEqual(t,s)}updateElementPosition(e){if(this.isDestroyed||!this.element||!this.fullLayer)return;const{centerX:t,centerY:s,width:r,height:a,zIndex:i}=this.workOptions,o=this.manager.getPagePoint(t,s),l=r*this.manager.camera.scale,h=a*this.manager.camera.scale;(!e||e&&!this.isSameSize(e))&&(this.element.setAttribute("width",`${l}`),this.element.setAttribute("height",`${h}`),this.element.style.width=`${l}px`,this.element.style.height=`${h}px`),(!e||e&&!this.isSamePosition(e))&&(this.element.style.left=`${o.x}px`,this.element.style.top=`${o.y}px`),(!e||e&&!this.isSameZIndex(e))&&(this.element.style.zIndex=(i||0).toString())}async updateSvg(e){const{type:t,state:s}=this.workOptions;if(t===c.ESVGType.markmap){const r=c.getMarkmapRuntimeOrThrow(),{data:a}=this.workOptions;if(this.markmapInstance||(this.markmapInstance=r.createMarkmap(this.element,this.manager.markmapOptions),this.markmapInstance.handleClick=async(l,h)=>{var u,p,g;(u=this.markmapInstance)==null||u.toggleNode(h);const y=this.serializeData((p=this.markmapInstance)==null?void 0:p.state.data);this.setWorkOptions({...this.workOptions,state:y},!1),r.checkNodeHasMermaid(h)&&await r.renderMermaidAfterDOMUpdate(this.element,this.workId),this.scenePath&&this.collector&&((g=this.collector)==null||g.dispatch({type:c.EPostMessageType.UpdateNode,workId:this.workId,opt:this.workOptions,isSync:!0,viewId:this.manager.viewId,scenePath:this.scenePath}))}),e&&this.isSameState(e)&&this.isSameSize(e)&&this.isSameData(e))return;const i=r.transform(this.workId,a);let{root:o}=i;a&&r.hasMermaidCodeBlock(a)&&(o=r.injectMermaidHtml(o,a,this.workId));try{s&&Array.isArray(s)&&this.transformState(s,o),await this.markmapInstance.setData(o),!this.isDestroyed&&this.element&&this.fullLayer&&this.markmapInstance&&(window.markmapInstance=this.markmapInstance,a&&r.hasMermaidCodeBlock(a)&&await r.renderMermaidAfterDOMUpdate(this.element,this.workId),await this.fit(!e||e&&!this.isSameData(e)))}catch(l){console.error("[updateSvg] error: ",l)}}else{const{src:r,crossOrigin:a}=this.workOptions,i=this.reloadSourceUrl??r;if(this.element.crossOrigin=v.isString(a)?a:"anonymous",!this.trackBackgroundImageLoad){this.element.src=i,await new Promise((o,l)=>{this.element.onload=()=>o(),this.element.onerror=()=>l()});return}await this.manager.master.control.backgroundImageLoadCoordinator.load({viewId:this.manager.viewId,scenePath:this.scenePath,resourceId:this.workId,src:i,image:this.element,isActive:()=>!this.isDestroyed&&this.manager.master.control.viewContainerManager.getCurScenePath(this.manager.viewId)===this.scenePath,onReloadUrl:o=>{this.reloadSourceUrl=o}})}}async fit(e=!0){var t;if(!this.isDestroyed&&this.element&&this.fullLayer&&this.markmapInstance){const s=c.getMarkmapRuntimeOrThrow();e&&this.element&&await s.waitForImagesInForeignObjects(this.element),await((t=this.markmapInstance)==null?void 0:t.fit()),this.element&&s.isSafari()&&s.hasMermaidSvg(this.element)&&(await O(this.element),await s.transformMermaidSvgToMarkmapSvg(this.element))}}serializeData(e){var r;const t=[e],s=[];for(;t.length>0;){const a=t.pop();a&&(a!=null&&a.children&&t.push(...a.children),s.push(((r=a==null?void 0:a.payload)==null?void 0:r.fold)||0))}return s}transformState(e,t){const s=[t];for(;s.length>0;){const r=s.pop();r&&(r!=null&&r.children&&s.push(...r.children),r.payload?r.payload.fold=e.shift():e.shift())}}async updateCamera(){this.updateElementPosition(),await this.fit(!1)}async setWorkOptions(e,t=!0){if(!v.isEqual(this.workOptions,e)){const s=v.clone(this.workOptions),r="src"in this.workOptions?this.workOptions.src:void 0,a="src"in e?e.src:void 0;r!==a&&(this.reloadSourceUrl=void 0),this.workOptions=e,t&&await this.render(s)}}destroy(){this.isDestroyed=!0,this.reloadSourceUrl=void 0,this.trackBackgroundImageLoad&&this.manager.master.control.backgroundImageLoadCoordinator.cancelResource(this.manager.viewId,this.scenePath,this.workId),this.element.remove()}getRectFromLayer(){const e=this.element.getBoundingClientRect();return{x:e.x,y:e.y,w:e.width,h:e.height}}}function P(n){const{toolsType:e,...t}=n;switch(e){case c.EToolsKey.BackgroundSVG:return new V(t);default:return}}class b{constructor(e){d(this,"viewId");d(this,"fullLayer");d(this,"curNodeMap");this.viewId=e,this.curNodeMap=new c.ObserverMap}init(e){this.fullLayer=e}get(e){return this.curNodeMap.get(e)}setInfo(e,t){const s=this.curNodeMap.get(e)||{name:e,workShape:t.workShape};t.workShape&&(s.workShape=t.workShape),this.curNodeMap.set(e,s)}getNodeRectFormShape(e){const t=this.curNodeMap.get(e);if(t&&t.workShape)return t.workShape.getRectFromLayer()}delete(e){const t=this.curNodeMap.get(e);t&&t.workShape.destroy(),this.curNodeMap.delete(e)}clear(){for(const e of this.curNodeMap.values())e.workShape.destroy();this.curNodeMap.clear()}}class U{constructor(e,t){d(this,"opt");d(this,"viewId");d(this,"fullLayer");d(this,"vNodes");d(this,"master");d(this,"cameraOpt");d(this,"methodBuilder");d(this,"destroyed",!1);d(this,"updateCamera",v.throttle(async e=>{if(this.destroyed)return;const{cameraOpt:t}=e;t&&!v.isEqual(this.cameraOpt,t)&&await this.setCameraOpt(t)},100));this.viewId=e,this.opt=t,this.master=t.master,this.fullLayer=t.container,this.methodBuilder=new F([c.EmitEventType.CopyNode]).registerForBackgroundThread(this),this.vNodes=new b(e),this.vNodes.init(this.fullLayer)}get camera(){return this.cameraOpt||{scale:1,centerX:0,centerY:0,width:0,height:0}}get view(){var e;return(e=this.master.control.viewContainerManager.getView(this.viewId))==null?void 0:e.viewData}get markmapOptions(){return this.master.control.pluginOptions.extras.markmap.options}getPagePoint(e,t){const{scale:s,centerX:r,centerY:a,width:i,height:o}=this.camera;return{x:(e-r)*s+i/2,y:(t-a)*s+o/2}}async setCameraOpt(e){if(!this.destroyed){this.cameraOpt=e;for(const t of this.vNodes.curNodeMap.values()){if(this.destroyed)return;const{workShape:s}=t;s&&await s.updateCamera()}}}clearAll(){this.vNodes.clear()}canUseFullLayer(e){return e===c.EToolsKey.BackgroundSVG}async consumeFull(e){if(this.destroyed)return;const{toolsType:t,opt:s,workId:r,scenePath:a}=e;if(r!=null&&r.toString()&&t&&this.canUseFullLayer(t))switch(t){case c.EToolsKey.BackgroundSVG:await this.setFullWork({toolsType:t,opt:s,workId:r,scenePath:a});break}}async setFullWork(e){const{workId:t,opt:s,toolsType:r,scenePath:a}=e;if(t&&s&&r&&a){const i=t.toString();let o;const l=this.vNodes.get(i);return!l||!l.workShape?(o=this.createWorkShapeNode({toolsOpt:s,toolsType:c.EToolsKey.BackgroundSVG,workId:i,scenePath:a}),o&&await o.init()):(o=l.workShape,await o.setWorkOptions(s)),o}}createWorkShapeNode(e){return P({...e,vNodes:this.vNodes,manager:this})}removeWork(e){const{workId:t}=e,s=t==null?void 0:t.toString();s&&this.removeNode(s)}removeNode(e){this.vNodes.delete(e)}async on(e){if(!this.destroyed&&!await this.methodBuilder.consumeForBackgroundThread(e)){if(this.destroyed)return;const{msgType:t,toolsType:s}=e;switch(t){case c.EPostMessageType.Destroy:{this.destroy();break}case c.EPostMessageType.Clear:{this.clearAll();break}case c.EPostMessageType.UpdateCamera:{this.updateCamera(e);break}case c.EPostMessageType.UpdateTools:{this.toggleFullLayer(s===c.EToolsKey.Clicker);break}case c.EPostMessageType.BackgroundSVGUpdate:case c.EPostMessageType.UpdateNode:case c.EPostMessageType.FullWork:{s&&this.canUseFullLayer(s)&&await this.consumeFull(e);break}case c.EPostMessageType.BackgroundSVGDelete:{this.removeWork(e);break}}}}toggleFullLayer(e){this.destroyed||this.fullLayer.classList.toggle("appliance-plugin-background-svg-active",e)}destroy(){this.destroyed||(this.destroyed=!0,this.updateCamera.cancel(),this.vNodes.clear())}}class D{constructor(e,t){d(this,"viewId");d(this,"fullLayer");d(this,"master");d(this,"vNodes");d(this,"cameraOpt");d(this,"opt");d(this,"workShapes",new Map);d(this,"destroyed",!1);d(this,"activeRequest");this.viewId=e,this.opt=t,this.master=t.master,this.fullLayer=t.container,this.vNodes=new b(e),this.vNodes.init(this.fullLayer)}get camera(){return this.cameraOpt||{scale:1,centerX:0,centerY:0,width:0,height:0}}get view(){var e;return(e=this.master.control.viewContainerManager.getView(this.viewId))==null?void 0:e.viewData}get markmapOptions(){return this.master.control.pluginOptions.extras.markmap.options}reportRequestFailure(e,t,s,r,a){const i=r instanceof Error?r.message:String(r);try{this.opt.post({sp:[{type:c.EPostMessageType.ReportError,viewId:this.viewId,scenePath:s,requestId:t,reportBusiness:e,reportStage:a,reportError:i,reportString:`[BackgroundSnapshotThread] ${e} failed; stage=${a}; requestId=${t||"unknown"}; error=${i}`}]})}catch(o){console.error(`[BackgroundSnapshotThread] ${e} failure report failed`,o)}}createOffscreenCanvas(e){const{width:t,height:s}=e.canvasOpt,r=new OffscreenCanvas(e.canvasOpt.width,e.canvasOpt.height);r.width=t,r.height=s}async setCameraOpt(e){if(!this.destroyed){this.cameraOpt=e;for(const t of this.vNodes.curNodeMap.values()){if(this.destroyed)return;const{workShape:s}=t;s&&await s.updateCamera()}}}getPagePoint(e,t){const{scale:s,centerX:r,centerY:a,width:i,height:o}=this.camera;return{x:(e-r)*s+i/2,y:(t-a)*s+o/2}}async getSnapshot(e){var i;if(this.destroyed)return;const{scenePath:t,scenes:s,cameraOpt:r,requestId:a}=e;this.activeRequest={business:"snapshot",scenePath:t,requestId:a};try{if(!(t&&s&&r))throw new Error("snapshot input is incomplete");await this.setCameraOpt(r);for(const[l,h]of Object.entries(s)){if(this.destroyed)return;if(h!=null&&h.type&&(h==null?void 0:h.toolsType)===c.EToolsKey.BackgroundSVG)switch(h==null?void 0:h.type){case c.EPostMessageType.UpdateNode:case c.EPostMessageType.FullWork:{const{opt:y}=h,w={...h,opt:y,workId:l,msgType:c.EPostMessageType.FullWork,dataType:c.EDataType.Service,viewId:this.viewId,scenePath:t,requestId:a};await this.runFullWork(w);break}default:break}}if(await O(this.fullLayer),this.destroyed||(await R(this.fullLayer),this.destroyed)||(await x(this.fullLayer),this.destroyed))return;const o=await $(this.fullLayer);if(!this.destroyed&&o)this.opt.post({sp:[{type:c.EPostMessageType.Snapshot,scenePath:t,imageElement:o,viewId:this.viewId,index:1,requestId:a}]});else if(!this.destroyed)throw new Error("snapshot image element is empty")}catch(o){this.destroyed||this.reportRequestFailure("snapshot",a,t,o,"render")}finally{((i=this.activeRequest)==null?void 0:i.requestId)===a&&(this.activeRequest=void 0)}}createWorkShapeNode(e){return P({...e,vNodes:this.vNodes,manager:this,trackBackgroundImageLoad:!1})}async setFullWork(e){const{workId:t,opt:s,toolsType:r,scenePath:a}=e;if(t&&s&&r&&a){const i=t.toString();let o;const l=this.vNodes.get(i);return!l||!l.workShape?(o=this.createWorkShapeNode({toolsOpt:s,toolsType:c.EToolsKey.BackgroundSVG,workId:i,scenePath:a}),o&&await o.init()):(o=l.workShape,await o.setWorkOptions(s)),o}}async runFullWork(e){if(this.destroyed)return;const{toolsType:t,opt:s,workId:r,scenePath:a}=e;await this.setFullWork({toolsType:t,opt:s,workId:r,scenePath:a})}destroy(e){this.destroyed||(e&&this.activeRequest&&this.reportRequestFailure("snapshot",this.activeRequest.requestId,this.activeRequest.scenePath,new Error(`snapshot request ${e}`),e),this.activeRequest=void 0,this.destroyed=!0,this.fullLayer.innerHTML="",this.fullLayer.style.width="",this.fullLayer.style.height="")}}class H{constructor(e){d(this,"backgroundThreadMap",new Map);d(this,"snapshotThreadsByRequest",new Map);d(this,"destroyed",!1);d(this,"master");d(this,"post",e=>{if(this.destroyed)return;const{sp:t}=e;t&&this.master.collectorSyncData(t)});this.master=e,this.backgroundThreadMap=new Map}createBackgroundThread(e,t){return new U(e,t)}createSnapshotThread(e,t){return new D(e,t)}getSnapshotRequestKey(e){return e.requestId||`${e.viewId}\0${e.scenePath||""}\0${e.msgType}`}disposeSnapshotThread(e,t,s){const r=this.snapshotThreadsByRequest.get(e);if(!(!r||r.thread!==t)){this.snapshotThreadsByRequest.delete(e);try{t.destroy(s)}finally{r.surface.remove()}}}async consume(e){var t,s,r,a,i;if(!this.destroyed)for(const o of e.values()){if(this.destroyed)return;const{msgType:l,viewId:h,layerOpt:y,offscreenCanvasOpt:w,cameraOpt:u,tasksqueue:p}=o;if(l===c.EPostMessageType.Console){console.log(this);continue}if(l===c.EPostMessageType.Init){const m=(t=this.master.control.viewContainerManager.getView(h))==null?void 0:t.displayer,T=(s=m==null?void 0:m.backgroundContainerRef)==null?void 0:s.current;if(m&&T&&y&&w){const f=this.backgroundThreadMap.get(h);f==null||f.destroy();const k=this.createBackgroundThread(h,{displayer:m,container:T,layerOpt:y,master:this.master,canvasOpt:w,post:this.post});this.backgroundThreadMap.set(h,k),k&&u&&await k.setCameraOpt(u)}continue}if(l===c.EPostMessageType.Snapshot){const m=(r=this.master.control.viewContainerManager.getView(h))==null?void 0:r.displayer,f=(i=((a=this.master.control.viewContainerManager.mainView)==null?void 0:a.displayer).backgroundSnapshotContainerRef)==null?void 0:i.current;if(m&&f&&u){const k=this.getSnapshotRequestKey(o),E=this.snapshotThreadsByRequest.get(k);E&&this.disposeSnapshotThread(k,E.thread,"replaced");const S=document.createElement("div");S.style.width=`${u.width}px`,S.style.height=`${u.height}px`,f.append(S);const q={...c.ViewContainerManager.defaultLayerOpt,offscreen:!1,width:u.width,height:u.height},N={...c.ViewContainerManager.defaultScreenCanvasOpt,width:u.width,height:u.height},I=this.createSnapshotThread(h,{displayer:m,container:S,layerOpt:q,master:this.master,canvasOpt:N,post:this.post});this.snapshotThreadsByRequest.set(k,{thread:I,surface:S}),I.getSnapshot(o).catch(M=>{this.master.Logger.error(`[Appliance]: background snapshot render failed; viewId=${h}; error=${M instanceof Error?M.message:String(M)}`)}).finally(()=>{this.disposeSnapshotThread(k,I)});continue}this.post({sp:[{type:c.EPostMessageType.ReportError,viewId:h,scenePath:o.scenePath,requestId:o.requestId,reportBusiness:"snapshot",reportStage:"surface-unavailable",reportError:"background snapshot surface is unavailable",reportString:`[BackgroundThreadManager] snapshot surface is unavailable; viewId=${h}; requestId=${o.requestId||"unknown"}`}]})}if(l===c.EPostMessageType.TasksQueue&&(p!=null&&p.size)){for(const[m,T]of this.backgroundThreadMap.entries()){const f=p.get(m);f&&await T.on(f)}continue}if(h===c.Storage_ViewId_ALL){for(const m of this.backgroundThreadMap.values())await m.on(o);l===c.EPostMessageType.Destroy&&this.backgroundThreadMap.clear();continue}const g=this.backgroundThreadMap.get(h);g&&(await g.on(o),l===c.EPostMessageType.Destroy&&this.backgroundThreadMap.get(h)===g&&this.backgroundThreadMap.delete(h))}}async consumeTargetOne(e,t){if(this.destroyed)return;const s=this.backgroundThreadMap.get(e);s&&await s.on(t)}discardView(e){for(const[s,r]of[...this.snapshotThreadsByRequest.entries()])r.thread.viewId===e&&this.disposeSnapshotThread(s,r.thread,"view-destroyed");const t=this.backgroundThreadMap.get(e);try{t==null||t.destroy()}catch(s){this.master.Logger.error(`[Appliance]: BackgroundThread View discard failed; viewId=${e}; error=${s instanceof Error?s.message:String(s)}`)}this.backgroundThreadMap.delete(e)}destroy(){if(this.destroyed)return;const e=[];for(const[t,s]of[...this.snapshotThreadsByRequest.entries()])try{this.disposeSnapshotThread(t,s.thread,"manager-destroyed")}catch(r){e.push(`snapshot-thread: ${r instanceof Error?r.message:String(r)}`)}this.snapshotThreadsByRequest.clear(),this.destroyed=!0;for(const t of this.backgroundThreadMap.values())try{t.destroy()}catch(s){e.push(`background-thread: ${s instanceof Error?s.message:String(s)}`)}this.backgroundThreadMap.clear(),e.length&&this.master.Logger.error(`[Appliance]: BackgroundThread destroy completed with cleanup errors: ${e.join("; ")}`)}}exports.BackgroundThreadManagerImpl=H;
|
|
1
|
+
"use strict";var B=Object.defineProperty;var L=(n,e,t)=>e in n?B(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var d=(n,e,t)=>L(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./index-S6ml0iJb.js"),v=require("lodash");require("clipper-lib");require("lz-string");require("lineclip");require("xss");require("rbush");require("react-dom");require("react");class C{constructor(){d(this,"threadEngine")}registerBackgroundThread(e){return this.threadEngine=e,this}}class W extends C{constructor(){super(...arguments);d(this,"emitEventType",c.EmitEventType.CopyNode)}async consume(t){const{msgType:s,dataType:r,emitEventType:a}=t;if(s===c.EPostMessageType.FullWork&&r===c.EDataType.Local&&a===this.emitEventType)return this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var r;const{workId:s}=t;s&&await((r=this.threadEngine)==null?void 0:r.consumeFull(t))}}class F{constructor(e){d(this,"builders",new Map);this.builders=new Map(e.map(t=>[t,this.build(t)]))}build(e){switch(e){case c.EmitEventType.CopyNode:return new W}}registerForBackgroundThread(e){return this.builders.forEach(t=>{t&&t.registerBackgroundThread(e)}),this}async consumeForBackgroundThread(e){for(const t of this.builders.values())if(await(t==null?void 0:t.consume(e)))return!0;return!1}}async function R(n){const e=n.querySelectorAll("img"),t=Array.from(e).map(a=>{if(!a.crossOrigin&&a.src&&!a.src.startsWith("data:")&&(a.crossOrigin="anonymous",a.complete)){const i=a.src;a.src="",a.src=i}return a.complete&&a.crossOrigin?Promise.resolve():new Promise(i=>{a.onload=()=>{i(void 0)},a.onerror=()=>{i(void 0)}})});return n.querySelectorAll("svg").forEach(a=>{a.querySelectorAll("image").forEach(o=>{o.href&&!o.href.baseVal.startsWith("data:")&&(o.getAttribute("crossorigin")||o.setAttribute("crossorigin","anonymous"),t.push(new Promise(l=>{const h=new Image;h.crossOrigin="anonymous",h.onload=()=>{l(void 0)},h.onerror=()=>{l(void 0)},h.src=o.href.baseVal})))})}),await Promise.all(t)}async function A(n){const s=Date.now();let r=!1;for(;Date.now()-s<5e3;){const a=n.querySelectorAll("path");if(a.length>0&&(r=Array.from(a).some(i=>{const o=i.getAttribute("d")||"";return o!=="M0,0C0,0,0,0,0,0"&&o.length>10}),r))break;await new Promise(i=>setTimeout(i,50))}}async function x(n){const e=n.querySelectorAll("svg");if(!e.length)return;const t=[];for(let s=0;s<e.length;s++){const r=e[s];t.push(A(r))}await Promise.all(t)}async function O(n){if(n.querySelectorAll("svg[data-type='mermaid']").length>0){const s=Date.now();let r=!1;for(;Date.now()-s<5e3&&!r;){const a=n.querySelectorAll("foreignObject");if(a.length>0){let i=!0;for(const o of Array.from(a)){const l=parseFloat(o.getAttribute("width")||"0"),h=parseFloat(o.getAttribute("height")||"0");if(o.querySelector(".mermaid-container")&&(l<50||h<50)){i=!1;break}}if(i){r=!0;break}}else r=!0;await new Promise(i=>setTimeout(i,50))}}}async function $(n,e={}){const{width:t=n.offsetWidth,height:s=n.offsetHeight}=e,r=n.offsetWidth||t,a=n.offsetHeight||s;try{const{loadSvgToImageLib:i,getSvgToImageLib:o}=await Promise.resolve().then(()=>require("./svgToImageLoader-B3gIDAQo.js"));let l=o();if(!l)try{l=await i()}catch(u){return console.error("[loadSvgToImageLib] error: ",u),null}const h=n.style.width,y=n.style.height,w=n.style.display;n.style.width||(n.style.width=`${r}px`),n.style.height||(n.style.height=`${a}px`),(!n.style.display||n.style.display==="none")&&(n.style.display="block");try{await new Promise(p=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{p()})})});const u=await l.toPng(n,{width:r,height:a,quality:1});return n.style.width=h,n.style.height=y,n.style.display=w,new Promise(p=>{const g=new Image;g.crossOrigin="anonymous",g.onload=()=>{p(g)},g.onerror=()=>{p(null)},g.src=u})}catch(u){return n.style.width=h,n.style.height=y,n.style.display=w,console.error("[divToImageElement] error: ",u),null}}catch(i){return console.error("[divToImageElement] error: ",i),null}}class V{constructor(e){d(this,"toolsType",c.EToolsKey.BackgroundSVG);d(this,"vNodes");d(this,"workOptions");d(this,"workId");d(this,"markmapInstance",null);d(this,"isDestroyed",!1);d(this,"element");d(this,"manager");d(this,"scenePath");d(this,"trackBackgroundImageLoad");d(this,"reloadSourceUrl");const{vNodes:t,workId:s,toolsOpt:r,manager:a,scenePath:i,trackBackgroundImageLoad:o=!0}=e;this.workId=s,this.vNodes=t,this.workOptions=r,this.manager=a,this.scenePath=i,this.trackBackgroundImageLoad=o,this.element=this.createElement(),this.manager.fullLayer.appendChild(this.element),this.vNodes.setInfo(this.workId,{workShape:this})}get fullLayer(){return this.manager.fullLayer}get collector(){return this.manager.master.control.collector}async init(){await this.render()}createElement(){const{type:e}=this.workOptions;let t;return e===c.ESVGType.markmap?(t=document.createElementNS("http://www.w3.org/2000/svg","svg"),t.classList.add("svg")):(t=document.createElement("img"),t.classList.add("img")),t.id=this.workId,t.setAttribute("data-id",this.workId),t}async render(e){this.isDestroyed||!this.element||!this.element.parentNode||(this.updateElementPosition(e),await this.updateSvg(e))}isSameSize(e){const{width:t,height:s}=e,{width:r,height:a}=this.workOptions,i=t*this.manager.camera.scale,o=s*this.manager.camera.scale,l=r*this.manager.camera.scale,h=a*this.manager.camera.scale;return i===l&&o===h}isSamePosition(e){const{centerX:t,centerY:s}=e,{centerX:r,centerY:a}=this.workOptions,i=this.manager.getPagePoint(r,a),o=this.manager.getPagePoint(t,s);return v.isEqual(o,i)}isSameZIndex(e){const{zIndex:t}=e,{zIndex:s}=this.workOptions;return t===s}isSameState(e){const{state:t}=e,{state:s}=this.workOptions;return v.isEqual(t,s)}isSameData(e){const{data:t}=e,{data:s}=this.workOptions;return v.isEqual(t,s)}updateElementPosition(e){if(this.isDestroyed||!this.element||!this.fullLayer)return;const{centerX:t,centerY:s,width:r,height:a,zIndex:i}=this.workOptions,o=this.manager.getPagePoint(t,s),l=r*this.manager.camera.scale,h=a*this.manager.camera.scale;(!e||e&&!this.isSameSize(e))&&(this.element.setAttribute("width",`${l}`),this.element.setAttribute("height",`${h}`),this.element.style.width=`${l}px`,this.element.style.height=`${h}px`),(!e||e&&!this.isSamePosition(e))&&(this.element.style.left=`${o.x}px`,this.element.style.top=`${o.y}px`),(!e||e&&!this.isSameZIndex(e))&&(this.element.style.zIndex=(i||0).toString())}async updateSvg(e){const{type:t,state:s}=this.workOptions;if(t===c.ESVGType.markmap){const r=c.getMarkmapRuntimeOrThrow(),{data:a}=this.workOptions;if(this.markmapInstance||(this.markmapInstance=r.createMarkmap(this.element,this.manager.markmapOptions),this.markmapInstance.handleClick=async(l,h)=>{var u,p,g;(u=this.markmapInstance)==null||u.toggleNode(h);const y=this.serializeData((p=this.markmapInstance)==null?void 0:p.state.data);this.setWorkOptions({...this.workOptions,state:y},!1),r.checkNodeHasMermaid(h)&&await r.renderMermaidAfterDOMUpdate(this.element,this.workId),this.scenePath&&this.collector&&((g=this.collector)==null||g.dispatch({type:c.EPostMessageType.UpdateNode,workId:this.workId,opt:this.workOptions,isSync:!0,viewId:this.manager.viewId,scenePath:this.scenePath}))}),e&&this.isSameState(e)&&this.isSameSize(e)&&this.isSameData(e))return;const i=r.transform(this.workId,a);let{root:o}=i;a&&r.hasMermaidCodeBlock(a)&&(o=r.injectMermaidHtml(o,a,this.workId));try{s&&Array.isArray(s)&&this.transformState(s,o),await this.markmapInstance.setData(o),!this.isDestroyed&&this.element&&this.fullLayer&&this.markmapInstance&&(window.markmapInstance=this.markmapInstance,a&&r.hasMermaidCodeBlock(a)&&await r.renderMermaidAfterDOMUpdate(this.element,this.workId),await this.fit(!e||e&&!this.isSameData(e)))}catch(l){console.error("[updateSvg] error: ",l)}}else{const{src:r,crossOrigin:a}=this.workOptions,i=this.reloadSourceUrl??r;if(this.element.crossOrigin=v.isString(a)?a:"anonymous",!this.trackBackgroundImageLoad){this.element.src=i,await new Promise((o,l)=>{this.element.onload=()=>o(),this.element.onerror=()=>l()});return}await this.manager.master.control.backgroundImageLoadCoordinator.load({viewId:this.manager.viewId,scenePath:this.scenePath,resourceId:this.workId,src:i,image:this.element,isActive:()=>!this.isDestroyed&&this.manager.master.control.viewContainerManager.getCurScenePath(this.manager.viewId)===this.scenePath,onReloadUrl:o=>{this.reloadSourceUrl=o}})}}async fit(e=!0){var t;if(!this.isDestroyed&&this.element&&this.fullLayer&&this.markmapInstance){const s=c.getMarkmapRuntimeOrThrow();e&&this.element&&await s.waitForImagesInForeignObjects(this.element),await((t=this.markmapInstance)==null?void 0:t.fit()),this.element&&s.isSafari()&&s.hasMermaidSvg(this.element)&&(await O(this.element),await s.transformMermaidSvgToMarkmapSvg(this.element))}}serializeData(e){var r;const t=[e],s=[];for(;t.length>0;){const a=t.pop();a&&(a!=null&&a.children&&t.push(...a.children),s.push(((r=a==null?void 0:a.payload)==null?void 0:r.fold)||0))}return s}transformState(e,t){const s=[t];for(;s.length>0;){const r=s.pop();r&&(r!=null&&r.children&&s.push(...r.children),r.payload?r.payload.fold=e.shift():e.shift())}}async updateCamera(){this.updateElementPosition(),await this.fit(!1)}async setWorkOptions(e,t=!0){if(!v.isEqual(this.workOptions,e)){const s=v.clone(this.workOptions),r="src"in this.workOptions?this.workOptions.src:void 0,a="src"in e?e.src:void 0;r!==a&&(this.reloadSourceUrl=void 0),this.workOptions=e,t&&await this.render(s)}}destroy(){this.isDestroyed=!0,this.reloadSourceUrl=void 0,this.trackBackgroundImageLoad&&this.manager.master.control.backgroundImageLoadCoordinator.cancelResource(this.manager.viewId,this.scenePath,this.workId),this.element.remove()}getRectFromLayer(){const e=this.element.getBoundingClientRect();return{x:e.x,y:e.y,w:e.width,h:e.height}}}function P(n){const{toolsType:e,...t}=n;switch(e){case c.EToolsKey.BackgroundSVG:return new V(t);default:return}}class b{constructor(e){d(this,"viewId");d(this,"fullLayer");d(this,"curNodeMap");this.viewId=e,this.curNodeMap=new c.ObserverMap}init(e){this.fullLayer=e}get(e){return this.curNodeMap.get(e)}setInfo(e,t){const s=this.curNodeMap.get(e)||{name:e,workShape:t.workShape};t.workShape&&(s.workShape=t.workShape),this.curNodeMap.set(e,s)}getNodeRectFormShape(e){const t=this.curNodeMap.get(e);if(t&&t.workShape)return t.workShape.getRectFromLayer()}delete(e){const t=this.curNodeMap.get(e);t&&t.workShape.destroy(),this.curNodeMap.delete(e)}clear(){for(const e of this.curNodeMap.values())e.workShape.destroy();this.curNodeMap.clear()}}class U{constructor(e,t){d(this,"opt");d(this,"viewId");d(this,"fullLayer");d(this,"vNodes");d(this,"master");d(this,"cameraOpt");d(this,"methodBuilder");d(this,"destroyed",!1);d(this,"updateCamera",v.throttle(async e=>{if(this.destroyed)return;const{cameraOpt:t}=e;t&&!v.isEqual(this.cameraOpt,t)&&await this.setCameraOpt(t)},100));this.viewId=e,this.opt=t,this.master=t.master,this.fullLayer=t.container,this.methodBuilder=new F([c.EmitEventType.CopyNode]).registerForBackgroundThread(this),this.vNodes=new b(e),this.vNodes.init(this.fullLayer)}get camera(){return this.cameraOpt||{scale:1,centerX:0,centerY:0,width:0,height:0}}get view(){var e;return(e=this.master.control.viewContainerManager.getView(this.viewId))==null?void 0:e.viewData}get markmapOptions(){return this.master.control.pluginOptions.extras.markmap.options}getPagePoint(e,t){const{scale:s,centerX:r,centerY:a,width:i,height:o}=this.camera;return{x:(e-r)*s+i/2,y:(t-a)*s+o/2}}async setCameraOpt(e){if(!this.destroyed){this.cameraOpt=e;for(const t of this.vNodes.curNodeMap.values()){if(this.destroyed)return;const{workShape:s}=t;s&&await s.updateCamera()}}}clearAll(){this.vNodes.clear()}canUseFullLayer(e){return e===c.EToolsKey.BackgroundSVG}async consumeFull(e){if(this.destroyed)return;const{toolsType:t,opt:s,workId:r,scenePath:a}=e;if(r!=null&&r.toString()&&t&&this.canUseFullLayer(t))switch(t){case c.EToolsKey.BackgroundSVG:await this.setFullWork({toolsType:t,opt:s,workId:r,scenePath:a});break}}async setFullWork(e){const{workId:t,opt:s,toolsType:r,scenePath:a}=e;if(t&&s&&r&&a){const i=t.toString();let o;const l=this.vNodes.get(i);return!l||!l.workShape?(o=this.createWorkShapeNode({toolsOpt:s,toolsType:c.EToolsKey.BackgroundSVG,workId:i,scenePath:a}),o&&await o.init()):(o=l.workShape,await o.setWorkOptions(s)),o}}createWorkShapeNode(e){return P({...e,vNodes:this.vNodes,manager:this})}removeWork(e){const{workId:t}=e,s=t==null?void 0:t.toString();s&&this.removeNode(s)}removeNode(e){this.vNodes.delete(e)}async on(e){if(!this.destroyed&&!await this.methodBuilder.consumeForBackgroundThread(e)){if(this.destroyed)return;const{msgType:t,toolsType:s}=e;switch(t){case c.EPostMessageType.Destroy:{this.destroy();break}case c.EPostMessageType.Clear:{this.clearAll();break}case c.EPostMessageType.UpdateCamera:{this.updateCamera(e);break}case c.EPostMessageType.UpdateTools:{this.toggleFullLayer(s===c.EToolsKey.Clicker);break}case c.EPostMessageType.BackgroundSVGUpdate:case c.EPostMessageType.UpdateNode:case c.EPostMessageType.FullWork:{s&&this.canUseFullLayer(s)&&await this.consumeFull(e);break}case c.EPostMessageType.BackgroundSVGDelete:{this.removeWork(e);break}}}}toggleFullLayer(e){this.destroyed||this.fullLayer.classList.toggle("appliance-plugin-background-svg-active",e)}destroy(){this.destroyed||(this.destroyed=!0,this.updateCamera.cancel(),this.vNodes.clear())}}class D{constructor(e,t){d(this,"viewId");d(this,"fullLayer");d(this,"master");d(this,"vNodes");d(this,"cameraOpt");d(this,"opt");d(this,"workShapes",new Map);d(this,"destroyed",!1);d(this,"activeRequest");this.viewId=e,this.opt=t,this.master=t.master,this.fullLayer=t.container,this.vNodes=new b(e),this.vNodes.init(this.fullLayer)}get camera(){return this.cameraOpt||{scale:1,centerX:0,centerY:0,width:0,height:0}}get view(){var e;return(e=this.master.control.viewContainerManager.getView(this.viewId))==null?void 0:e.viewData}get markmapOptions(){return this.master.control.pluginOptions.extras.markmap.options}reportRequestFailure(e,t,s,r,a){const i=r instanceof Error?r.message:String(r);try{this.opt.post({sp:[{type:c.EPostMessageType.ReportError,viewId:this.viewId,scenePath:s,requestId:t,reportBusiness:e,reportStage:a,reportError:i,reportString:`[BackgroundSnapshotThread] ${e} failed; stage=${a}; requestId=${t||"unknown"}; error=${i}`}]})}catch(o){console.error(`[BackgroundSnapshotThread] ${e} failure report failed`,o)}}createOffscreenCanvas(e){const{width:t,height:s}=e.canvasOpt,r=new OffscreenCanvas(e.canvasOpt.width,e.canvasOpt.height);r.width=t,r.height=s}async setCameraOpt(e){if(!this.destroyed){this.cameraOpt=e;for(const t of this.vNodes.curNodeMap.values()){if(this.destroyed)return;const{workShape:s}=t;s&&await s.updateCamera()}}}getPagePoint(e,t){const{scale:s,centerX:r,centerY:a,width:i,height:o}=this.camera;return{x:(e-r)*s+i/2,y:(t-a)*s+o/2}}async getSnapshot(e){var i;if(this.destroyed)return;const{scenePath:t,scenes:s,cameraOpt:r,requestId:a}=e;this.activeRequest={business:"snapshot",scenePath:t,requestId:a};try{if(!(t&&s&&r))throw new Error("snapshot input is incomplete");await this.setCameraOpt(r);for(const[l,h]of Object.entries(s)){if(this.destroyed)return;if(h!=null&&h.type&&(h==null?void 0:h.toolsType)===c.EToolsKey.BackgroundSVG)switch(h==null?void 0:h.type){case c.EPostMessageType.UpdateNode:case c.EPostMessageType.FullWork:{const{opt:y}=h,w={...h,opt:y,workId:l,msgType:c.EPostMessageType.FullWork,dataType:c.EDataType.Service,viewId:this.viewId,scenePath:t,requestId:a};await this.runFullWork(w);break}default:break}}if(await O(this.fullLayer),this.destroyed||(await R(this.fullLayer),this.destroyed)||(await x(this.fullLayer),this.destroyed))return;const o=await $(this.fullLayer);if(!this.destroyed&&o)this.opt.post({sp:[{type:c.EPostMessageType.Snapshot,scenePath:t,imageElement:o,viewId:this.viewId,index:1,requestId:a}]});else if(!this.destroyed)throw new Error("snapshot image element is empty")}catch(o){this.destroyed||this.reportRequestFailure("snapshot",a,t,o,"render")}finally{((i=this.activeRequest)==null?void 0:i.requestId)===a&&(this.activeRequest=void 0)}}createWorkShapeNode(e){return P({...e,vNodes:this.vNodes,manager:this,trackBackgroundImageLoad:!1})}async setFullWork(e){const{workId:t,opt:s,toolsType:r,scenePath:a}=e;if(t&&s&&r&&a){const i=t.toString();let o;const l=this.vNodes.get(i);return!l||!l.workShape?(o=this.createWorkShapeNode({toolsOpt:s,toolsType:c.EToolsKey.BackgroundSVG,workId:i,scenePath:a}),o&&await o.init()):(o=l.workShape,await o.setWorkOptions(s)),o}}async runFullWork(e){if(this.destroyed)return;const{toolsType:t,opt:s,workId:r,scenePath:a}=e;await this.setFullWork({toolsType:t,opt:s,workId:r,scenePath:a})}destroy(e){this.destroyed||(e&&this.activeRequest&&this.reportRequestFailure("snapshot",this.activeRequest.requestId,this.activeRequest.scenePath,new Error(`snapshot request ${e}`),e),this.activeRequest=void 0,this.destroyed=!0,this.fullLayer.innerHTML="",this.fullLayer.style.width="",this.fullLayer.style.height="")}}class H{constructor(e){d(this,"backgroundThreadMap",new Map);d(this,"snapshotThreadsByRequest",new Map);d(this,"destroyed",!1);d(this,"master");d(this,"post",e=>{if(this.destroyed)return;const{sp:t}=e;t&&this.master.collectorSyncData(t)});this.master=e,this.backgroundThreadMap=new Map}createBackgroundThread(e,t){return new U(e,t)}createSnapshotThread(e,t){return new D(e,t)}getSnapshotRequestKey(e){return e.requestId||`${e.viewId}\0${e.scenePath||""}\0${e.msgType}`}disposeSnapshotThread(e,t,s){const r=this.snapshotThreadsByRequest.get(e);if(!(!r||r.thread!==t)){this.snapshotThreadsByRequest.delete(e);try{t.destroy(s)}finally{r.surface.remove()}}}async consume(e){var t,s,r,a,i;if(!this.destroyed)for(const o of e.values()){if(this.destroyed)return;const{msgType:l,viewId:h,layerOpt:y,offscreenCanvasOpt:w,cameraOpt:u,tasksqueue:p}=o;if(l===c.EPostMessageType.Console){console.log(this);continue}if(l===c.EPostMessageType.Init){const m=(t=this.master.control.viewContainerManager.getView(h))==null?void 0:t.displayer,T=(s=m==null?void 0:m.backgroundContainerRef)==null?void 0:s.current;if(m&&T&&y&&w){const f=this.backgroundThreadMap.get(h);f==null||f.destroy();const k=this.createBackgroundThread(h,{displayer:m,container:T,layerOpt:y,master:this.master,canvasOpt:w,post:this.post});this.backgroundThreadMap.set(h,k),k&&u&&await k.setCameraOpt(u)}continue}if(l===c.EPostMessageType.Snapshot){const m=(r=this.master.control.viewContainerManager.getView(h))==null?void 0:r.displayer,f=(i=((a=this.master.control.viewContainerManager.mainView)==null?void 0:a.displayer).backgroundSnapshotContainerRef)==null?void 0:i.current;if(m&&f&&u){const k=this.getSnapshotRequestKey(o),E=this.snapshotThreadsByRequest.get(k);E&&this.disposeSnapshotThread(k,E.thread,"replaced");const S=document.createElement("div");S.style.width=`${u.width}px`,S.style.height=`${u.height}px`,f.append(S);const q={...c.ViewContainerManager.defaultLayerOpt,offscreen:!1,width:u.width,height:u.height},N={...c.ViewContainerManager.defaultScreenCanvasOpt,width:u.width,height:u.height},I=this.createSnapshotThread(h,{displayer:m,container:S,layerOpt:q,master:this.master,canvasOpt:N,post:this.post});this.snapshotThreadsByRequest.set(k,{thread:I,surface:S}),I.getSnapshot(o).catch(M=>{this.master.Logger.error(`[Appliance]: background snapshot render failed; viewId=${h}; error=${M instanceof Error?M.message:String(M)}`)}).finally(()=>{this.disposeSnapshotThread(k,I)});continue}this.post({sp:[{type:c.EPostMessageType.ReportError,viewId:h,scenePath:o.scenePath,requestId:o.requestId,reportBusiness:"snapshot",reportStage:"surface-unavailable",reportError:"background snapshot surface is unavailable",reportString:`[BackgroundThreadManager] snapshot surface is unavailable; viewId=${h}; requestId=${o.requestId||"unknown"}`}]})}if(l===c.EPostMessageType.TasksQueue&&(p!=null&&p.size)){for(const[m,T]of this.backgroundThreadMap.entries()){const f=p.get(m);f&&await T.on(f)}continue}if(h===c.Storage_ViewId_ALL){for(const m of this.backgroundThreadMap.values())await m.on(o);l===c.EPostMessageType.Destroy&&this.backgroundThreadMap.clear();continue}const g=this.backgroundThreadMap.get(h);g&&(await g.on(o),l===c.EPostMessageType.Destroy&&this.backgroundThreadMap.get(h)===g&&this.backgroundThreadMap.delete(h))}}async consumeTargetOne(e,t){if(this.destroyed)return;const s=this.backgroundThreadMap.get(e);s&&await s.on(t)}discardView(e){for(const[s,r]of[...this.snapshotThreadsByRequest.entries()])r.thread.viewId===e&&this.disposeSnapshotThread(s,r.thread,"view-destroyed");const t=this.backgroundThreadMap.get(e);try{t==null||t.destroy()}catch(s){this.master.Logger.error(`[Appliance]: BackgroundThread View discard failed; viewId=${e}; error=${s instanceof Error?s.message:String(s)}`)}this.backgroundThreadMap.delete(e)}destroy(){if(this.destroyed)return;const e=[];for(const[t,s]of[...this.snapshotThreadsByRequest.entries()])try{this.disposeSnapshotThread(t,s.thread,"manager-destroyed")}catch(r){e.push(`snapshot-thread: ${r instanceof Error?r.message:String(r)}`)}this.snapshotThreadsByRequest.clear(),this.destroyed=!0;for(const t of this.backgroundThreadMap.values())try{t.destroy()}catch(s){e.push(`background-thread: ${s instanceof Error?s.message:String(s)}`)}this.backgroundThreadMap.clear(),e.length&&this.master.Logger.error(`[Appliance]: BackgroundThread destroy completed with cleanup errors: ${e.join("; ")}`)}}exports.BackgroundThreadManagerImpl=H;
|