@netless/appliance-plugin 1.1.42 → 1.1.43-beta.0

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.
Files changed (112) hide show
  1. package/READMA.zh-CN.md +23 -1
  2. package/README.md +24 -1
  3. package/dist/appliance-plugin.js +1 -1
  4. package/dist/appliance-plugin.mjs +33 -30
  5. package/dist/{bridge-C8yT2GqS.js → bridge-D68E09T9.js} +1 -1
  6. package/dist/{bridge-DLGOhX8U.mjs → bridge-DcVN05tP.mjs} +1 -1
  7. package/dist/bridge.js +1 -1
  8. package/dist/bridge.mjs +1 -1
  9. package/dist/collector/collector.d.ts +50 -2
  10. package/dist/collector/types.d.ts +6 -0
  11. package/dist/component/svg/manager.d.ts +1 -0
  12. package/dist/component/svg/snapshot.d.ts +4 -1
  13. package/dist/component/textEditor/manager.d.ts +3 -0
  14. package/dist/core/backGroundThread/index.d.ts +6 -1
  15. package/dist/core/cameraTask.d.ts +45 -0
  16. package/dist/core/const.d.ts +4 -0
  17. package/dist/core/enum.d.ts +5 -1
  18. package/dist/core/error.d.ts +1 -0
  19. package/dist/core/fontFace.d.ts +5 -3
  20. package/dist/core/mainEngine.d.ts +230 -31
  21. package/dist/core/mainThread/base.d.ts +23 -2
  22. package/dist/core/mainThread/canvas2DReadback.d.ts +27 -0
  23. package/dist/core/mainThread/index.d.ts +12 -1
  24. package/dist/core/mainThread/snapshotThread.d.ts +11 -2
  25. package/dist/core/mainThread/subLocalThread.d.ts +12 -6
  26. package/dist/core/mainThread/subServiceThread.d.ts +5 -3
  27. package/dist/core/msgEvent/base.d.ts +4 -1
  28. package/dist/core/msgEvent/baseForWorker.d.ts +1 -1
  29. package/dist/core/msgEvent/copyNode/forWorker.d.ts +1 -1
  30. package/dist/core/msgEvent/forWorker.d.ts +1 -1
  31. package/dist/core/msgEvent/index.d.ts +5 -3
  32. package/dist/core/msgEvent/rotateNode/forMain.d.ts +1 -0
  33. package/dist/core/msgEvent/rotateNode/forWorker.d.ts +1 -1
  34. package/dist/core/msgEvent/scaleNode/forMain.d.ts +1 -0
  35. package/dist/core/msgEvent/scaleNode/forWorker.d.ts +1 -1
  36. package/dist/core/msgEvent/setColor/forMain.d.ts +1 -0
  37. package/dist/core/msgEvent/setColor/forWorker.d.ts +1 -1
  38. package/dist/core/msgEvent/setFont/forWorker.d.ts +1 -1
  39. package/dist/core/msgEvent/setLock/forWorker.d.ts +1 -1
  40. package/dist/core/msgEvent/setPoint/forWorker.d.ts +1 -1
  41. package/dist/core/msgEvent/setShape/forWorker.d.ts +1 -1
  42. package/dist/core/msgEvent/setZIndex/forWorker.d.ts +1 -1
  43. package/dist/core/msgEvent/translateNode/forMain.d.ts +1 -0
  44. package/dist/core/msgEvent/translateNode/forWorker.d.ts +1 -1
  45. package/dist/core/renderRuntimeFallback.d.ts +2 -0
  46. package/dist/core/rendererBusinessTask.d.ts +30 -0
  47. package/dist/core/serviceRenderScheduler.d.ts +33 -0
  48. package/dist/core/tools/base.d.ts +1 -1
  49. package/dist/core/tools/bitmapEraserFastPath.d.ts +8 -0
  50. package/dist/core/tools/eraserFaces.d.ts +24 -9
  51. package/dist/core/tools/image.d.ts +1 -0
  52. package/dist/core/tools/pencilEraserBitMap.d.ts +62 -14
  53. package/dist/core/tools/text.d.ts +2 -1
  54. package/dist/core/types.d.ts +64 -1
  55. package/dist/core/utils/indexDB.d.ts +3 -3
  56. package/dist/core/vNodeManager.d.ts +7 -0
  57. package/dist/core/worker/base.d.ts +52 -7
  58. package/dist/core/worker/fullWorkerLocal.d.ts +8 -2
  59. package/dist/core/worker/fullWorkerService.d.ts +7 -3
  60. package/dist/core/worker/renderCapabilityProbe.d.ts +54 -0
  61. package/dist/core/worker/simpleWorker.d.ts +2 -2
  62. package/dist/core/worker/snapshotWork.d.ts +1 -0
  63. package/dist/core/worker/workerManager.d.ts +17 -4
  64. package/dist/displayer/floatBar/selectorGesture.d.ts +2 -0
  65. package/dist/fullWorker.js +138 -139
  66. package/dist/index-BNHPCii1.mjs +4089 -0
  67. package/dist/index-B_vZ9d3x.mjs +55912 -0
  68. package/dist/index-C2AHqjj8.js +570 -0
  69. package/dist/index-CV8YaU3F.mjs +931 -0
  70. package/dist/index-CWDWQZBs.mjs +4088 -0
  71. package/dist/index-DChI1--R.js +1 -0
  72. package/dist/index-DFo0Gmfx.js +570 -0
  73. package/dist/index-DiLPVPwQ.js +1 -0
  74. package/dist/index-GBYM7kT5.js +1 -0
  75. package/dist/index-GZUDLXJC.js +1 -0
  76. package/dist/{index-D8p2ph99.mjs → index-K_0NX6pD.mjs} +401 -263
  77. package/dist/index-NG5kKK1W.mjs +55920 -0
  78. package/dist/plugin/applianceMultiPlugin.d.ts +18 -3
  79. package/dist/plugin/applianceSinglePlugin.d.ts +18 -4
  80. package/dist/plugin/baseApplianceManager.d.ts +138 -12
  81. package/dist/plugin/baseViewContainerManager.d.ts +40 -3
  82. package/dist/plugin/bitmapEraserOptions.d.ts +9 -0
  83. package/dist/plugin/const.d.ts +4 -0
  84. package/dist/plugin/displayerView.d.ts +7 -7
  85. package/dist/plugin/initLogAggregator.d.ts +45 -0
  86. package/dist/plugin/multi/applianceMultiManager.d.ts +1 -0
  87. package/dist/plugin/multi/containerManager.d.ts +19 -1
  88. package/dist/plugin/pluginInstanceOwner.d.ts +1 -0
  89. package/dist/plugin/renderImageBitmapRetirement.d.ts +100 -0
  90. package/dist/plugin/renderRuntimeCache.d.ts +18 -0
  91. package/dist/plugin/renderSurface.d.ts +15 -0
  92. package/dist/plugin/renderingCompatibility.d.ts +21 -5
  93. package/dist/plugin/roomLifecycle.d.ts +12 -0
  94. package/dist/plugin/selectorApi.d.ts +8 -0
  95. package/dist/plugin/single/applianceSingleManager.d.ts +4 -0
  96. package/dist/plugin/types.d.ts +11 -14
  97. package/dist/plugin/utils.d.ts +8 -0
  98. package/dist/subWorker.js +136 -137
  99. package/dist/undo/index.d.ts +12 -3
  100. package/dist/undo/timing.d.ts +9 -4
  101. package/package.json +23 -8
  102. package/dist/index--wqREfHK.js +0 -570
  103. package/dist/index-B-tFucpi.mjs +0 -48995
  104. package/dist/index-BOx854fU.mjs +0 -3266
  105. package/dist/index-BpiBM5wZ.js +0 -1
  106. package/dist/index-ByjVgxJm.js +0 -1
  107. package/dist/index-CSVCH-SQ.mjs +0 -789
  108. package/dist/index-CfIWmlMn.js +0 -570
  109. package/dist/index-D6gXcNbF.js +0 -1
  110. package/dist/index-HAZlgByL.mjs +0 -48987
  111. package/dist/index-OZXjSPr1.js +0 -1
  112. package/dist/index-z7deO9Md.mjs +0 -3267
@@ -0,0 +1,931 @@
1
+ var A = Object.defineProperty;
2
+ var x = (n, e, t) => e in n ? A(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var c = (n, e, t) => x(n, typeof e != "symbol" ? e + "" : e, t);
4
+ import { E as b, a as l, b as C, c as v, d as L, O as $, V as B, S as V } from "./index-NG5kKK1W.mjs";
5
+ import { isEqual as T, isString as U, clone as D, throttle as H } from "lodash";
6
+ import "white-web-sdk";
7
+ import "clipper-lib";
8
+ import "lz-string";
9
+ import "lineclip";
10
+ import "xss";
11
+ import "rbush";
12
+ import "react-dom";
13
+ import "react";
14
+ import { g as P } from "./markmap-runtime-Cg3OxuZ2.mjs";
15
+ class _ {
16
+ constructor() {
17
+ c(this, "threadEngine");
18
+ }
19
+ registerBackgroundThread(e) {
20
+ return this.threadEngine = e, this;
21
+ }
22
+ }
23
+ class z extends _ {
24
+ constructor() {
25
+ super(...arguments);
26
+ c(this, "emitEventType", b.CopyNode);
27
+ }
28
+ async consume(t) {
29
+ const { msgType: s, dataType: r, emitEventType: a } = t;
30
+ if (s === l.FullWork && r === C.Local && a === this.emitEventType)
31
+ return this.consumeForLocalWorker(t), !0;
32
+ }
33
+ async consumeForLocalWorker(t) {
34
+ var r;
35
+ const { workId: s } = t;
36
+ s && await ((r = this.threadEngine) == null ? void 0 : r.consumeFull(t));
37
+ }
38
+ }
39
+ class G {
40
+ constructor(e) {
41
+ c(this, "builders", /* @__PURE__ */ new Map());
42
+ this.builders = new Map(e.map((t) => [t, this.build(t)]));
43
+ }
44
+ build(e) {
45
+ switch (e) {
46
+ case b.CopyNode:
47
+ return new z();
48
+ }
49
+ }
50
+ registerForBackgroundThread(e) {
51
+ return this.builders.forEach((t) => {
52
+ t && t.registerBackgroundThread(e);
53
+ }), this;
54
+ }
55
+ async consumeForBackgroundThread(e) {
56
+ for (const t of this.builders.values())
57
+ if (await (t == null ? void 0 : t.consume(e)))
58
+ return !0;
59
+ return !1;
60
+ }
61
+ }
62
+ async function X(n) {
63
+ const e = n.querySelectorAll("img"), t = Array.from(e).map((a) => {
64
+ if (!a.crossOrigin && a.src && !a.src.startsWith("data:") && (a.crossOrigin = "anonymous", a.complete)) {
65
+ const o = a.src;
66
+ a.src = "", a.src = o;
67
+ }
68
+ return a.complete && a.crossOrigin ? Promise.resolve() : new Promise((o) => {
69
+ a.onload = () => {
70
+ o(void 0);
71
+ }, a.onerror = () => {
72
+ o(void 0);
73
+ };
74
+ });
75
+ });
76
+ return n.querySelectorAll("svg").forEach((a) => {
77
+ a.querySelectorAll("image").forEach((i) => {
78
+ i.href && !i.href.baseVal.startsWith("data:") && (i.getAttribute("crossorigin") || i.setAttribute("crossorigin", "anonymous"), t.push(
79
+ new Promise((d) => {
80
+ const h = new Image();
81
+ h.crossOrigin = "anonymous", h.onload = () => {
82
+ d(void 0);
83
+ }, h.onerror = () => {
84
+ d(void 0);
85
+ }, h.src = i.href.baseVal;
86
+ })
87
+ ));
88
+ });
89
+ }), await Promise.all(t);
90
+ }
91
+ async function Y(n) {
92
+ const s = Date.now();
93
+ let r = !1;
94
+ for (; Date.now() - s < 5e3; ) {
95
+ const a = n.querySelectorAll("path");
96
+ if (a.length > 0 && (r = Array.from(a).some((o) => {
97
+ const i = o.getAttribute("d") || "";
98
+ return i !== "M0,0C0,0,0,0,0,0" && i.length > 10;
99
+ }), r))
100
+ break;
101
+ await new Promise((o) => setTimeout(o, 50));
102
+ }
103
+ }
104
+ async function j(n) {
105
+ const e = n.querySelectorAll("svg");
106
+ if (!e.length)
107
+ return;
108
+ const t = [];
109
+ for (let s = 0; s < e.length; s++) {
110
+ const r = e[s];
111
+ t.push(Y(r));
112
+ }
113
+ await Promise.all(t);
114
+ }
115
+ async function E(n) {
116
+ if (n.querySelectorAll("svg[data-type='mermaid']").length > 0) {
117
+ const s = Date.now();
118
+ let r = !1;
119
+ for (; Date.now() - s < 5e3 && !r; ) {
120
+ const a = n.querySelectorAll("foreignObject");
121
+ if (a.length > 0) {
122
+ let o = !0;
123
+ for (const i of Array.from(a)) {
124
+ const d = parseFloat(i.getAttribute("width") || "0"), h = parseFloat(i.getAttribute("height") || "0");
125
+ if (i.querySelector(".mermaid-container") && (d < 50 || h < 50)) {
126
+ o = !1;
127
+ break;
128
+ }
129
+ }
130
+ if (o) {
131
+ r = !0;
132
+ break;
133
+ }
134
+ } else
135
+ r = !0;
136
+ await new Promise((o) => setTimeout(o, 50));
137
+ }
138
+ }
139
+ }
140
+ async function K(n, e = {}) {
141
+ const { width: t = n.offsetWidth, height: s = n.offsetHeight } = e, r = n.offsetWidth || t, a = n.offsetHeight || s;
142
+ try {
143
+ const { loadSvgToImageLib: o, getSvgToImageLib: i } = await import("./svgToImageLoader-DZz5bAo4.mjs");
144
+ let d = i();
145
+ if (!d)
146
+ try {
147
+ d = await o();
148
+ } catch (u) {
149
+ return console.error("[loadSvgToImageLib] error: ", u), null;
150
+ }
151
+ const h = n.style.width, f = n.style.height, y = n.style.display;
152
+ 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");
153
+ try {
154
+ await new Promise((p) => {
155
+ requestAnimationFrame(() => {
156
+ requestAnimationFrame(() => {
157
+ p();
158
+ });
159
+ });
160
+ });
161
+ const u = await d.toPng(n, {
162
+ width: r,
163
+ height: a,
164
+ quality: 1
165
+ });
166
+ return n.style.width = h, n.style.height = f, n.style.display = y, new Promise((p) => {
167
+ const m = new Image();
168
+ m.crossOrigin = "anonymous", m.onload = () => {
169
+ p(m);
170
+ }, m.onerror = () => {
171
+ p(null);
172
+ }, m.src = u;
173
+ });
174
+ } catch (u) {
175
+ return n.style.width = h, n.style.height = f, n.style.display = y, console.error("[divToImageElement] error: ", u), null;
176
+ }
177
+ } catch (o) {
178
+ return console.error("[divToImageElement] error: ", o), null;
179
+ }
180
+ }
181
+ class Z {
182
+ constructor(e) {
183
+ c(this, "toolsType", v.BackgroundSVG);
184
+ c(this, "vNodes");
185
+ c(this, "workOptions");
186
+ c(this, "workId");
187
+ c(this, "markmapInstance", null);
188
+ c(this, "isDestroyed", !1);
189
+ c(this, "element");
190
+ c(this, "manager");
191
+ c(this, "scenePath");
192
+ c(this, "trackBackgroundImageLoad");
193
+ c(this, "reloadSourceUrl");
194
+ const {
195
+ vNodes: t,
196
+ workId: s,
197
+ toolsOpt: r,
198
+ manager: a,
199
+ scenePath: o,
200
+ trackBackgroundImageLoad: i = !0
201
+ } = e;
202
+ this.workId = s, this.vNodes = t, this.workOptions = r, this.manager = a, this.scenePath = o, this.trackBackgroundImageLoad = i, this.element = this.createElement(), this.manager.fullLayer.appendChild(this.element), this.vNodes.setInfo(this.workId, {
203
+ workShape: this
204
+ });
205
+ }
206
+ get fullLayer() {
207
+ return this.manager.fullLayer;
208
+ }
209
+ get collector() {
210
+ return this.manager.master.control.collector;
211
+ }
212
+ async init() {
213
+ await this.render();
214
+ }
215
+ createElement() {
216
+ const { type: e } = this.workOptions;
217
+ let t;
218
+ return e === L.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;
219
+ }
220
+ async render(e) {
221
+ this.isDestroyed || !this.element || !this.element.parentNode || (this.updateElementPosition(e), await this.updateSvg(e));
222
+ }
223
+ isSameSize(e) {
224
+ const { width: t, height: s } = e, { width: r, height: a } = this.workOptions, o = t * this.manager.camera.scale, i = s * this.manager.camera.scale, d = r * this.manager.camera.scale, h = a * this.manager.camera.scale;
225
+ return o === d && i === h;
226
+ }
227
+ isSamePosition(e) {
228
+ const { centerX: t, centerY: s } = e, { centerX: r, centerY: a } = this.workOptions, o = this.manager.getPagePoint(r, a), i = this.manager.getPagePoint(t, s);
229
+ return T(i, o);
230
+ }
231
+ isSameZIndex(e) {
232
+ const { zIndex: t } = e, { zIndex: s } = this.workOptions;
233
+ return t === s;
234
+ }
235
+ isSameState(e) {
236
+ const { state: t } = e, { state: s } = this.workOptions;
237
+ return T(t, s);
238
+ }
239
+ isSameData(e) {
240
+ const { data: t } = e, { data: s } = this.workOptions;
241
+ return T(t, s);
242
+ }
243
+ updateElementPosition(e) {
244
+ if (this.isDestroyed || !this.element || !this.fullLayer)
245
+ return;
246
+ const { centerX: t, centerY: s, width: r, height: a, zIndex: o } = this.workOptions, i = this.manager.getPagePoint(t, s), d = r * this.manager.camera.scale, h = a * this.manager.camera.scale;
247
+ (!e || e && !this.isSameSize(e)) && (this.element.setAttribute("width", `${d}`), this.element.setAttribute("height", `${h}`), this.element.style.width = `${d}px`, this.element.style.height = `${h}px`), (!e || e && !this.isSamePosition(e)) && (this.element.style.left = `${i.x}px`, this.element.style.top = `${i.y}px`), (!e || e && !this.isSameZIndex(e)) && (this.element.style.zIndex = (o || 0).toString());
248
+ }
249
+ async updateSvg(e) {
250
+ const { type: t, state: s } = this.workOptions;
251
+ if (t === L.markmap) {
252
+ const r = P(), { data: a } = this.workOptions;
253
+ if (this.markmapInstance || (this.markmapInstance = r.createMarkmap(
254
+ this.element,
255
+ this.manager.markmapOptions
256
+ ), this.markmapInstance.handleClick = async (d, h) => {
257
+ var u, p, m;
258
+ (u = this.markmapInstance) == null || u.toggleNode(h);
259
+ const f = this.serializeData((p = this.markmapInstance) == null ? void 0 : p.state.data);
260
+ this.setWorkOptions(
261
+ {
262
+ ...this.workOptions,
263
+ state: f
264
+ },
265
+ !1
266
+ ), r.checkNodeHasMermaid(h) && await r.renderMermaidAfterDOMUpdate(
267
+ this.element,
268
+ this.workId
269
+ ), this.scenePath && this.collector && ((m = this.collector) == null || m.dispatch({
270
+ type: l.UpdateNode,
271
+ workId: this.workId,
272
+ opt: this.workOptions,
273
+ isSync: !0,
274
+ viewId: this.manager.viewId,
275
+ scenePath: this.scenePath
276
+ }));
277
+ }), e && this.isSameState(e) && this.isSameSize(e) && this.isSameData(e))
278
+ return;
279
+ const o = r.transform(this.workId, a);
280
+ let { root: i } = o;
281
+ a && r.hasMermaidCodeBlock(a) && (i = r.injectMermaidHtml(i, a, this.workId));
282
+ try {
283
+ s && Array.isArray(s) && this.transformState(s, i), await this.markmapInstance.setData(i), !this.isDestroyed && this.element && this.fullLayer && this.markmapInstance && (window.markmapInstance = this.markmapInstance, a && r.hasMermaidCodeBlock(a) && await r.renderMermaidAfterDOMUpdate(
284
+ this.element,
285
+ this.workId
286
+ ), await this.fit(
287
+ !e || e && !this.isSameData(e)
288
+ ));
289
+ } catch (d) {
290
+ console.error("[updateSvg] error: ", d);
291
+ }
292
+ } else {
293
+ const { src: r, crossOrigin: a } = this.workOptions, o = this.reloadSourceUrl ?? r;
294
+ if (this.element.crossOrigin = U(a) ? a : "anonymous", !this.trackBackgroundImageLoad) {
295
+ this.element.src = o, await new Promise((i, d) => {
296
+ this.element.onload = () => i(), this.element.onerror = () => d();
297
+ });
298
+ return;
299
+ }
300
+ await this.manager.master.control.backgroundImageLoadCoordinator.load({
301
+ viewId: this.manager.viewId,
302
+ scenePath: this.scenePath,
303
+ resourceId: this.workId,
304
+ src: o,
305
+ image: this.element,
306
+ isActive: () => !this.isDestroyed && this.manager.master.control.viewContainerManager.getCurScenePath(
307
+ this.manager.viewId
308
+ ) === this.scenePath,
309
+ onReloadUrl: (i) => {
310
+ this.reloadSourceUrl = i;
311
+ }
312
+ });
313
+ }
314
+ }
315
+ async fit(e = !0) {
316
+ var t;
317
+ if (!this.isDestroyed && this.element && this.fullLayer && this.markmapInstance) {
318
+ const s = P();
319
+ e && this.element && await s.waitForImagesInForeignObjects(
320
+ this.element
321
+ ), await ((t = this.markmapInstance) == null ? void 0 : t.fit()), this.element && s.isSafari() && s.hasMermaidSvg(this.element) && (await E(this.element), await s.transformMermaidSvgToMarkmapSvg(
322
+ this.element
323
+ ));
324
+ }
325
+ }
326
+ serializeData(e) {
327
+ var r;
328
+ const t = [e], s = [];
329
+ for (; t.length > 0; ) {
330
+ const a = t.pop();
331
+ a && (a != null && a.children && t.push(...a.children), s.push(((r = a == null ? void 0 : a.payload) == null ? void 0 : r.fold) || 0));
332
+ }
333
+ return s;
334
+ }
335
+ transformState(e, t) {
336
+ const s = [t];
337
+ for (; s.length > 0; ) {
338
+ const r = s.pop();
339
+ r && (r != null && r.children && s.push(...r.children), r.payload ? r.payload.fold = e.shift() : e.shift());
340
+ }
341
+ }
342
+ async updateCamera() {
343
+ this.updateElementPosition(), await this.fit(!1);
344
+ }
345
+ async setWorkOptions(e, t = !0) {
346
+ if (!T(this.workOptions, e)) {
347
+ const s = D(this.workOptions), r = "src" in this.workOptions ? this.workOptions.src : void 0, a = "src" in e ? e.src : void 0;
348
+ r !== a && (this.reloadSourceUrl = void 0), this.workOptions = e, t && await this.render(s);
349
+ }
350
+ }
351
+ destroy() {
352
+ this.isDestroyed = !0, this.reloadSourceUrl = void 0, this.trackBackgroundImageLoad && this.manager.master.control.backgroundImageLoadCoordinator.cancelResource(
353
+ this.manager.viewId,
354
+ this.scenePath,
355
+ this.workId
356
+ ), this.element.remove();
357
+ }
358
+ getRectFromLayer() {
359
+ const e = this.element.getBoundingClientRect();
360
+ return {
361
+ x: e.x,
362
+ y: e.y,
363
+ w: e.width,
364
+ h: e.height
365
+ };
366
+ }
367
+ }
368
+ function q(n) {
369
+ const { toolsType: e, ...t } = n;
370
+ switch (e) {
371
+ case v.BackgroundSVG:
372
+ return new Z(t);
373
+ default:
374
+ return;
375
+ }
376
+ }
377
+ class W {
378
+ constructor(e) {
379
+ c(this, "viewId");
380
+ c(this, "fullLayer");
381
+ c(this, "curNodeMap");
382
+ this.viewId = e, this.curNodeMap = new $();
383
+ }
384
+ init(e) {
385
+ this.fullLayer = e;
386
+ }
387
+ get(e) {
388
+ return this.curNodeMap.get(e);
389
+ }
390
+ setInfo(e, t) {
391
+ const s = this.curNodeMap.get(
392
+ e
393
+ ) || {
394
+ name: e,
395
+ workShape: t.workShape
396
+ };
397
+ t.workShape && (s.workShape = t.workShape), this.curNodeMap.set(e, s);
398
+ }
399
+ getNodeRectFormShape(e) {
400
+ const t = this.curNodeMap.get(e);
401
+ if (t && t.workShape)
402
+ return t.workShape.getRectFromLayer();
403
+ }
404
+ delete(e) {
405
+ const t = this.curNodeMap.get(e);
406
+ t && t.workShape.destroy(), this.curNodeMap.delete(e);
407
+ }
408
+ clear() {
409
+ for (const e of this.curNodeMap.values())
410
+ e.workShape.destroy();
411
+ this.curNodeMap.clear();
412
+ }
413
+ }
414
+ class Q {
415
+ constructor(e, t) {
416
+ c(this, "opt");
417
+ c(this, "viewId");
418
+ c(this, "fullLayer");
419
+ c(this, "vNodes");
420
+ c(this, "master");
421
+ c(this, "cameraOpt");
422
+ c(this, "methodBuilder");
423
+ c(this, "destroyed", !1);
424
+ c(this, "updateCamera", H(async (e) => {
425
+ if (this.destroyed) return;
426
+ const { cameraOpt: t } = e;
427
+ t && !T(this.cameraOpt, t) && await this.setCameraOpt(t);
428
+ }, 100));
429
+ this.viewId = e, this.opt = t, this.master = t.master, this.fullLayer = t.container, this.methodBuilder = new G([
430
+ b.CopyNode
431
+ ]).registerForBackgroundThread(this), this.vNodes = new W(e), this.vNodes.init(this.fullLayer);
432
+ }
433
+ get camera() {
434
+ return this.cameraOpt || {
435
+ scale: 1,
436
+ centerX: 0,
437
+ centerY: 0,
438
+ width: 0,
439
+ height: 0
440
+ };
441
+ }
442
+ get view() {
443
+ var e;
444
+ return (e = this.master.control.viewContainerManager.getView(this.viewId)) == null ? void 0 : e.viewData;
445
+ }
446
+ get markmapOptions() {
447
+ return this.master.control.pluginOptions.extras.markmap.options;
448
+ }
449
+ getPagePoint(e, t) {
450
+ const { scale: s, centerX: r, centerY: a, width: o, height: i } = this.camera;
451
+ return {
452
+ x: (e - r) * s + o / 2,
453
+ y: (t - a) * s + i / 2
454
+ };
455
+ }
456
+ async setCameraOpt(e) {
457
+ if (!this.destroyed) {
458
+ this.cameraOpt = e;
459
+ for (const t of this.vNodes.curNodeMap.values()) {
460
+ if (this.destroyed) return;
461
+ const { workShape: s } = t;
462
+ s && await s.updateCamera();
463
+ }
464
+ }
465
+ }
466
+ clearAll() {
467
+ this.vNodes.clear();
468
+ }
469
+ canUseFullLayer(e) {
470
+ return e === v.BackgroundSVG;
471
+ }
472
+ async consumeFull(e) {
473
+ if (this.destroyed) return;
474
+ const { toolsType: t, opt: s, workId: r, scenePath: a } = e;
475
+ if (r != null && r.toString() && t && this.canUseFullLayer(t))
476
+ switch (t) {
477
+ case v.BackgroundSVG:
478
+ await this.setFullWork({
479
+ toolsType: t,
480
+ opt: s,
481
+ workId: r,
482
+ scenePath: a
483
+ });
484
+ break;
485
+ }
486
+ }
487
+ async setFullWork(e) {
488
+ const { workId: t, opt: s, toolsType: r, scenePath: a } = e;
489
+ if (t && s && r && a) {
490
+ const o = t.toString();
491
+ let i;
492
+ const d = this.vNodes.get(o);
493
+ return !d || !d.workShape ? (i = this.createWorkShapeNode({
494
+ toolsOpt: s,
495
+ toolsType: v.BackgroundSVG,
496
+ workId: o,
497
+ scenePath: a
498
+ }), i && await i.init()) : (i = d.workShape, await i.setWorkOptions(s)), i;
499
+ }
500
+ }
501
+ createWorkShapeNode(e) {
502
+ return q({
503
+ ...e,
504
+ vNodes: this.vNodes,
505
+ manager: this
506
+ });
507
+ }
508
+ removeWork(e) {
509
+ const { workId: t } = e, s = t == null ? void 0 : t.toString();
510
+ s && this.removeNode(s);
511
+ }
512
+ removeNode(e) {
513
+ this.vNodes.delete(e);
514
+ }
515
+ async on(e) {
516
+ if (!this.destroyed && !await this.methodBuilder.consumeForBackgroundThread(e)) {
517
+ if (this.destroyed) return;
518
+ const { msgType: t, toolsType: s } = e;
519
+ switch (t) {
520
+ case l.Destroy: {
521
+ this.destroy();
522
+ break;
523
+ }
524
+ case l.Clear: {
525
+ this.clearAll();
526
+ break;
527
+ }
528
+ case l.UpdateCamera: {
529
+ this.updateCamera(e);
530
+ break;
531
+ }
532
+ case l.UpdateTools: {
533
+ this.toggleFullLayer(s === v.Clicker);
534
+ break;
535
+ }
536
+ case l.BackgroundSVGUpdate:
537
+ case l.UpdateNode:
538
+ case l.FullWork: {
539
+ s && this.canUseFullLayer(s) && await this.consumeFull(e);
540
+ break;
541
+ }
542
+ case l.BackgroundSVGDelete: {
543
+ this.removeWork(e);
544
+ break;
545
+ }
546
+ }
547
+ }
548
+ }
549
+ toggleFullLayer(e) {
550
+ this.destroyed || this.fullLayer.classList.toggle(
551
+ "appliance-plugin-background-svg-active",
552
+ e
553
+ );
554
+ }
555
+ destroy() {
556
+ this.destroyed || (this.destroyed = !0, this.updateCamera.cancel(), this.vNodes.clear());
557
+ }
558
+ }
559
+ class J {
560
+ constructor(e, t) {
561
+ c(this, "viewId");
562
+ c(this, "fullLayer");
563
+ c(this, "master");
564
+ c(this, "vNodes");
565
+ c(this, "cameraOpt");
566
+ c(this, "opt");
567
+ c(this, "workShapes", /* @__PURE__ */ new Map());
568
+ c(this, "destroyed", !1);
569
+ c(this, "activeRequest");
570
+ this.viewId = e, this.opt = t, this.master = t.master, this.fullLayer = t.container, this.vNodes = new W(e), this.vNodes.init(this.fullLayer);
571
+ }
572
+ get camera() {
573
+ return this.cameraOpt || {
574
+ scale: 1,
575
+ centerX: 0,
576
+ centerY: 0,
577
+ width: 0,
578
+ height: 0
579
+ };
580
+ }
581
+ get view() {
582
+ var e;
583
+ return (e = this.master.control.viewContainerManager.getView(this.viewId)) == null ? void 0 : e.viewData;
584
+ }
585
+ get markmapOptions() {
586
+ return this.master.control.pluginOptions.extras.markmap.options;
587
+ }
588
+ reportRequestFailure(e, t, s, r, a) {
589
+ const o = r instanceof Error ? r.message : String(r);
590
+ try {
591
+ this.opt.post({
592
+ sp: [
593
+ {
594
+ type: l.ReportError,
595
+ viewId: this.viewId,
596
+ scenePath: s,
597
+ requestId: t,
598
+ reportBusiness: e,
599
+ reportStage: a,
600
+ reportError: o,
601
+ reportString: `[BackgroundSnapshotThread] ${e} failed; stage=${a}; requestId=${t || "unknown"}; error=${o}`
602
+ }
603
+ ]
604
+ });
605
+ } catch (i) {
606
+ console.error(
607
+ `[BackgroundSnapshotThread] ${e} failure report failed`,
608
+ i
609
+ );
610
+ }
611
+ }
612
+ createOffscreenCanvas(e) {
613
+ const { width: t, height: s } = e.canvasOpt, r = new OffscreenCanvas(
614
+ e.canvasOpt.width,
615
+ e.canvasOpt.height
616
+ );
617
+ r.width = t, r.height = s;
618
+ }
619
+ async setCameraOpt(e) {
620
+ if (!this.destroyed) {
621
+ this.cameraOpt = e;
622
+ for (const t of this.vNodes.curNodeMap.values()) {
623
+ if (this.destroyed) return;
624
+ const { workShape: s } = t;
625
+ s && await s.updateCamera();
626
+ }
627
+ }
628
+ }
629
+ getPagePoint(e, t) {
630
+ const { scale: s, centerX: r, centerY: a, width: o, height: i } = this.camera;
631
+ return {
632
+ x: (e - r) * s + o / 2,
633
+ y: (t - a) * s + i / 2
634
+ };
635
+ }
636
+ async getSnapshot(e) {
637
+ var o;
638
+ if (this.destroyed) return;
639
+ const { scenePath: t, scenes: s, cameraOpt: r, requestId: a } = e;
640
+ this.activeRequest = { business: "snapshot", scenePath: t, requestId: a };
641
+ try {
642
+ if (!(t && s && r))
643
+ throw new Error("snapshot input is incomplete");
644
+ await this.setCameraOpt(r);
645
+ for (const [d, h] of Object.entries(s)) {
646
+ if (this.destroyed) return;
647
+ if (h != null && h.type && (h == null ? void 0 : h.toolsType) === v.BackgroundSVG)
648
+ switch (h == null ? void 0 : h.type) {
649
+ case l.UpdateNode:
650
+ case l.FullWork: {
651
+ const { opt: f } = h, y = {
652
+ ...h,
653
+ opt: f,
654
+ workId: d,
655
+ msgType: l.FullWork,
656
+ dataType: C.Service,
657
+ viewId: this.viewId,
658
+ scenePath: t,
659
+ requestId: a
660
+ };
661
+ await this.runFullWork(y);
662
+ break;
663
+ }
664
+ default:
665
+ break;
666
+ }
667
+ }
668
+ if (await E(this.fullLayer), this.destroyed || (await X(this.fullLayer), this.destroyed) || (await j(this.fullLayer), this.destroyed)) return;
669
+ const i = await K(this.fullLayer);
670
+ if (!this.destroyed && i)
671
+ this.opt.post({
672
+ sp: [
673
+ {
674
+ type: l.Snapshot,
675
+ scenePath: t,
676
+ imageElement: i,
677
+ viewId: this.viewId,
678
+ index: 1,
679
+ requestId: a
680
+ }
681
+ ]
682
+ });
683
+ else if (!this.destroyed)
684
+ throw new Error("snapshot image element is empty");
685
+ } catch (i) {
686
+ this.destroyed || this.reportRequestFailure(
687
+ "snapshot",
688
+ a,
689
+ t,
690
+ i,
691
+ "render"
692
+ );
693
+ } finally {
694
+ ((o = this.activeRequest) == null ? void 0 : o.requestId) === a && (this.activeRequest = void 0);
695
+ }
696
+ }
697
+ createWorkShapeNode(e) {
698
+ return q({
699
+ ...e,
700
+ vNodes: this.vNodes,
701
+ manager: this,
702
+ trackBackgroundImageLoad: !1
703
+ });
704
+ }
705
+ async setFullWork(e) {
706
+ const { workId: t, opt: s, toolsType: r, scenePath: a } = e;
707
+ if (t && s && r && a) {
708
+ const o = t.toString();
709
+ let i;
710
+ const d = this.vNodes.get(o);
711
+ return !d || !d.workShape ? (i = this.createWorkShapeNode({
712
+ toolsOpt: s,
713
+ toolsType: v.BackgroundSVG,
714
+ workId: o,
715
+ scenePath: a
716
+ }), i && await i.init()) : (i = d.workShape, await i.setWorkOptions(s)), i;
717
+ }
718
+ }
719
+ async runFullWork(e) {
720
+ if (this.destroyed) return;
721
+ const { toolsType: t, opt: s, workId: r, scenePath: a } = e;
722
+ await this.setFullWork({
723
+ toolsType: t,
724
+ opt: s,
725
+ workId: r,
726
+ scenePath: a
727
+ });
728
+ }
729
+ destroy(e) {
730
+ this.destroyed || (e && this.activeRequest && this.reportRequestFailure(
731
+ "snapshot",
732
+ this.activeRequest.requestId,
733
+ this.activeRequest.scenePath,
734
+ new Error(`snapshot request ${e}`),
735
+ e
736
+ ), this.activeRequest = void 0, this.destroyed = !0, this.fullLayer.innerHTML = "", this.fullLayer.style.width = "", this.fullLayer.style.height = "");
737
+ }
738
+ }
739
+ class ue {
740
+ constructor(e) {
741
+ c(this, "backgroundThreadMap", /* @__PURE__ */ new Map());
742
+ c(this, "snapshotThreadsByRequest", /* @__PURE__ */ new Map());
743
+ c(this, "destroyed", !1);
744
+ c(this, "master");
745
+ c(this, "post", (e) => {
746
+ if (this.destroyed) return;
747
+ const { sp: t } = e;
748
+ t && this.master.collectorSyncData(t);
749
+ });
750
+ this.master = e, this.backgroundThreadMap = /* @__PURE__ */ new Map();
751
+ }
752
+ createBackgroundThread(e, t) {
753
+ return new Q(e, t);
754
+ }
755
+ createSnapshotThread(e, t) {
756
+ return new J(e, t);
757
+ }
758
+ getSnapshotRequestKey(e) {
759
+ return e.requestId || `${e.viewId}\0${e.scenePath || ""}\0${e.msgType}`;
760
+ }
761
+ disposeSnapshotThread(e, t, s) {
762
+ const r = this.snapshotThreadsByRequest.get(e);
763
+ if (!(!r || r.thread !== t)) {
764
+ this.snapshotThreadsByRequest.delete(e);
765
+ try {
766
+ t.destroy(s);
767
+ } finally {
768
+ r.surface.remove();
769
+ }
770
+ }
771
+ }
772
+ async consume(e) {
773
+ var t, s, r, a, o;
774
+ if (!this.destroyed)
775
+ for (const i of e.values()) {
776
+ if (this.destroyed) return;
777
+ const {
778
+ msgType: d,
779
+ viewId: h,
780
+ layerOpt: f,
781
+ offscreenCanvasOpt: y,
782
+ cameraOpt: u,
783
+ tasksqueue: p
784
+ } = i;
785
+ if (d === l.Console) {
786
+ console.log(this);
787
+ continue;
788
+ }
789
+ if (d === l.Init) {
790
+ const g = (t = this.master.control.viewContainerManager.getView(h)) == null ? void 0 : t.displayer, S = (s = g == null ? void 0 : g.backgroundContainerRef) == null ? void 0 : s.current;
791
+ if (g && S && f && y) {
792
+ const w = this.backgroundThreadMap.get(h);
793
+ w == null || w.destroy();
794
+ const k = this.createBackgroundThread(h, {
795
+ displayer: g,
796
+ container: S,
797
+ layerOpt: f,
798
+ master: this.master,
799
+ canvasOpt: y,
800
+ post: this.post
801
+ });
802
+ this.backgroundThreadMap.set(h, k), k && u && await k.setCameraOpt(u);
803
+ }
804
+ continue;
805
+ }
806
+ if (d === l.Snapshot) {
807
+ const g = (r = this.master.control.viewContainerManager.getView(h)) == null ? void 0 : r.displayer, w = (o = ((a = this.master.control.viewContainerManager.mainView) == null ? void 0 : a.displayer).backgroundSnapshotContainerRef) == null ? void 0 : o.current;
808
+ if (g && w && u) {
809
+ const k = this.getSnapshotRequestKey(i), N = this.snapshotThreadsByRequest.get(k);
810
+ N && this.disposeSnapshotThread(k, N.thread, "replaced");
811
+ const I = document.createElement("div");
812
+ I.style.width = `${u.width}px`, I.style.height = `${u.height}px`, w.append(I);
813
+ const F = {
814
+ ...B.defaultLayerOpt,
815
+ offscreen: !1,
816
+ width: u.width,
817
+ height: u.height
818
+ }, R = {
819
+ ...B.defaultScreenCanvasOpt,
820
+ width: u.width,
821
+ height: u.height
822
+ }, O = this.createSnapshotThread(h, {
823
+ displayer: g,
824
+ container: I,
825
+ layerOpt: F,
826
+ master: this.master,
827
+ canvasOpt: R,
828
+ post: this.post
829
+ });
830
+ this.snapshotThreadsByRequest.set(k, {
831
+ thread: O,
832
+ surface: I
833
+ }), O.getSnapshot(i).catch((M) => {
834
+ this.master.Logger.error(
835
+ `[Appliance]: background snapshot render failed; viewId=${h}; error=${M instanceof Error ? M.message : String(M)}`
836
+ );
837
+ }).finally(() => {
838
+ this.disposeSnapshotThread(k, O);
839
+ });
840
+ continue;
841
+ }
842
+ this.post({
843
+ sp: [
844
+ {
845
+ type: l.ReportError,
846
+ viewId: h,
847
+ scenePath: i.scenePath,
848
+ requestId: i.requestId,
849
+ reportBusiness: "snapshot",
850
+ reportStage: "surface-unavailable",
851
+ reportError: "background snapshot surface is unavailable",
852
+ reportString: `[BackgroundThreadManager] snapshot surface is unavailable; viewId=${h}; requestId=${i.requestId || "unknown"}`
853
+ }
854
+ ]
855
+ });
856
+ }
857
+ if (d === l.TasksQueue && (p != null && p.size)) {
858
+ for (const [g, S] of this.backgroundThreadMap.entries()) {
859
+ const w = p.get(g);
860
+ w && await S.on(w);
861
+ }
862
+ continue;
863
+ }
864
+ if (h === V) {
865
+ for (const g of this.backgroundThreadMap.values())
866
+ await g.on(i);
867
+ d === l.Destroy && this.backgroundThreadMap.clear();
868
+ continue;
869
+ }
870
+ const m = this.backgroundThreadMap.get(h);
871
+ m && (await m.on(i), d === l.Destroy && this.backgroundThreadMap.get(h) === m && this.backgroundThreadMap.delete(h));
872
+ }
873
+ }
874
+ async consumeTargetOne(e, t) {
875
+ if (this.destroyed) return;
876
+ const s = this.backgroundThreadMap.get(e);
877
+ s && await s.on(t);
878
+ }
879
+ discardView(e) {
880
+ for (const [s, r] of [
881
+ ...this.snapshotThreadsByRequest.entries()
882
+ ])
883
+ r.thread.viewId === e && this.disposeSnapshotThread(
884
+ s,
885
+ r.thread,
886
+ "view-destroyed"
887
+ );
888
+ const t = this.backgroundThreadMap.get(e);
889
+ try {
890
+ t == null || t.destroy();
891
+ } catch (s) {
892
+ this.master.Logger.error(
893
+ `[Appliance]: BackgroundThread View discard failed; viewId=${e}; error=${s instanceof Error ? s.message : String(s)}`
894
+ );
895
+ }
896
+ this.backgroundThreadMap.delete(e);
897
+ }
898
+ destroy() {
899
+ if (this.destroyed) return;
900
+ const e = [];
901
+ for (const [t, s] of [
902
+ ...this.snapshotThreadsByRequest.entries()
903
+ ])
904
+ try {
905
+ this.disposeSnapshotThread(
906
+ t,
907
+ s.thread,
908
+ "manager-destroyed"
909
+ );
910
+ } catch (r) {
911
+ e.push(
912
+ `snapshot-thread: ${r instanceof Error ? r.message : String(r)}`
913
+ );
914
+ }
915
+ this.snapshotThreadsByRequest.clear(), this.destroyed = !0;
916
+ for (const t of this.backgroundThreadMap.values())
917
+ try {
918
+ t.destroy();
919
+ } catch (s) {
920
+ e.push(
921
+ `background-thread: ${s instanceof Error ? s.message : String(s)}`
922
+ );
923
+ }
924
+ this.backgroundThreadMap.clear(), e.length && this.master.Logger.error(
925
+ `[Appliance]: BackgroundThread destroy completed with cleanup errors: ${e.join("; ")}`
926
+ );
927
+ }
928
+ }
929
+ export {
930
+ ue as BackgroundThreadManagerImpl
931
+ };