@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
@@ -1,789 +0,0 @@
1
- var F = Object.defineProperty;
2
- var E = (n, e, t) => e in n ? F(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var h = (n, e, t) => E(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { E as T, a as d, b as L, c as k, d as M, g as b, O as A, V as N, S as x } from "./index-HAZlgByL.mjs";
5
- import { isEqual as I, isString as V, clone as U, throttle as D } from "lodash";
6
- import "clipper-lib";
7
- import "lz-string";
8
- import "lineclip";
9
- import "xss";
10
- import "rbush";
11
- import "react-dom";
12
- import "react";
13
- class R {
14
- constructor() {
15
- h(this, "threadEngine");
16
- }
17
- registerBackgroundThread(e) {
18
- return this.threadEngine = e, this;
19
- }
20
- }
21
- class H extends R {
22
- constructor() {
23
- super(...arguments);
24
- h(this, "emitEventType", T.CopyNode);
25
- }
26
- async consume(t) {
27
- const { msgType: s, dataType: r, emitEventType: a } = t;
28
- if (s === d.FullWork && r === L.Local && a === this.emitEventType)
29
- return this.consumeForLocalWorker(t), !0;
30
- }
31
- async consumeForLocalWorker(t) {
32
- var r;
33
- const { workId: s } = t;
34
- s && await ((r = this.threadEngine) == null ? void 0 : r.consumeFull(t));
35
- }
36
- }
37
- class q {
38
- constructor(e) {
39
- h(this, "builders", /* @__PURE__ */ new Map());
40
- this.builders = new Map(e.map((t) => [t, this.build(t)]));
41
- }
42
- build(e) {
43
- switch (e) {
44
- case T.CopyNode:
45
- return new H();
46
- }
47
- }
48
- registerForBackgroundThread(e) {
49
- return this.builders.forEach((t) => {
50
- t && t.registerBackgroundThread(e);
51
- }), this;
52
- }
53
- async consumeForBackgroundThread(e) {
54
- for (const t of this.builders.values())
55
- if (await (t == null ? void 0 : t.consume(e)))
56
- return !0;
57
- return !1;
58
- }
59
- }
60
- async function _(n) {
61
- const e = n.querySelectorAll("img"), t = Array.from(e).map((a) => {
62
- if (!a.crossOrigin && a.src && !a.src.startsWith("data:") && (a.crossOrigin = "anonymous", a.complete)) {
63
- const i = a.src;
64
- a.src = "", a.src = i;
65
- }
66
- return a.complete && a.crossOrigin ? Promise.resolve() : new Promise((i) => {
67
- a.onload = () => {
68
- i(void 0);
69
- }, a.onerror = () => {
70
- i(void 0);
71
- };
72
- });
73
- });
74
- return n.querySelectorAll("svg").forEach((a) => {
75
- a.querySelectorAll("image").forEach((o) => {
76
- o.href && !o.href.baseVal.startsWith("data:") && (o.getAttribute("crossorigin") || o.setAttribute("crossorigin", "anonymous"), t.push(
77
- new Promise((c) => {
78
- const l = new Image();
79
- l.crossOrigin = "anonymous", l.onload = () => {
80
- c(void 0);
81
- }, l.onerror = () => {
82
- c(void 0);
83
- }, l.src = o.href.baseVal;
84
- })
85
- ));
86
- });
87
- }), await Promise.all(t);
88
- }
89
- async function $(n) {
90
- const s = Date.now();
91
- let r = !1;
92
- for (; Date.now() - s < 5e3; ) {
93
- const a = n.querySelectorAll("path");
94
- if (a.length > 0 && (r = Array.from(a).some((i) => {
95
- const o = i.getAttribute("d") || "";
96
- return o !== "M0,0C0,0,0,0,0,0" && o.length > 10;
97
- }), r))
98
- break;
99
- await new Promise((i) => setTimeout(i, 50));
100
- }
101
- }
102
- async function z(n) {
103
- const e = n.querySelectorAll("svg");
104
- if (!e.length)
105
- return;
106
- const t = [];
107
- for (let s = 0; s < e.length; s++) {
108
- const r = e[s];
109
- t.push($(r));
110
- }
111
- await Promise.all(t);
112
- }
113
- async function P(n) {
114
- if (n.querySelectorAll("svg[data-type='mermaid']").length > 0) {
115
- const s = Date.now();
116
- let r = !1;
117
- for (; Date.now() - s < 5e3 && !r; ) {
118
- const a = n.querySelectorAll("foreignObject");
119
- if (a.length > 0) {
120
- let i = !0;
121
- for (const o of Array.from(a)) {
122
- const c = parseFloat(o.getAttribute("width") || "0"), l = parseFloat(o.getAttribute("height") || "0");
123
- if (o.querySelector(".mermaid-container") && (c < 50 || l < 50)) {
124
- i = !1;
125
- break;
126
- }
127
- }
128
- if (i) {
129
- r = !0;
130
- break;
131
- }
132
- } else
133
- r = !0;
134
- await new Promise((i) => setTimeout(i, 50));
135
- }
136
- }
137
- }
138
- async function G(n, e = {}) {
139
- const { width: t = n.offsetWidth, height: s = n.offsetHeight } = e, r = n.offsetWidth || t, a = n.offsetHeight || s;
140
- try {
141
- const { loadSvgToImageLib: i, getSvgToImageLib: o } = await import("./svgToImageLoader-DZz5bAo4.mjs");
142
- let c = o();
143
- if (!c)
144
- try {
145
- c = await i();
146
- } catch (w) {
147
- return console.error("[loadSvgToImageLib] error: ", w), null;
148
- }
149
- const l = n.style.width, p = n.style.height, y = n.style.display;
150
- 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");
151
- try {
152
- await new Promise((m) => {
153
- requestAnimationFrame(() => {
154
- requestAnimationFrame(() => {
155
- m();
156
- });
157
- });
158
- });
159
- const w = await c.toPng(n, {
160
- width: r,
161
- height: a,
162
- quality: 1
163
- });
164
- return n.style.width = l, n.style.height = p, n.style.display = y, new Promise((m) => {
165
- const u = new Image();
166
- u.crossOrigin = "anonymous", u.onload = () => {
167
- m(u);
168
- }, u.onerror = () => {
169
- m(null);
170
- }, u.src = w;
171
- });
172
- } catch (w) {
173
- return n.style.width = l, n.style.height = p, n.style.display = y, console.error("[divToImageElement] error: ", w), null;
174
- }
175
- } catch (i) {
176
- return console.error("[divToImageElement] error: ", i), null;
177
- }
178
- }
179
- class X {
180
- constructor(e) {
181
- h(this, "toolsType", k.BackgroundSVG);
182
- h(this, "vNodes");
183
- h(this, "workOptions");
184
- h(this, "workId");
185
- h(this, "markmapInstance", null);
186
- h(this, "isDestroyed", !1);
187
- h(this, "element");
188
- h(this, "manager");
189
- h(this, "scenePath");
190
- h(this, "trackBackgroundImageLoad");
191
- h(this, "reloadSourceUrl");
192
- const {
193
- vNodes: t,
194
- workId: s,
195
- toolsOpt: r,
196
- manager: a,
197
- scenePath: i,
198
- trackBackgroundImageLoad: o = !0
199
- } = e;
200
- 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, {
201
- workShape: this
202
- });
203
- }
204
- get fullLayer() {
205
- return this.manager.fullLayer;
206
- }
207
- get collector() {
208
- return this.manager.master.control.collector;
209
- }
210
- async init() {
211
- await this.render();
212
- }
213
- createElement() {
214
- const { type: e } = this.workOptions;
215
- let t;
216
- return e === M.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;
217
- }
218
- async render(e) {
219
- this.isDestroyed || !this.element || !this.element.parentNode || (this.updateElementPosition(e), await this.updateSvg(e));
220
- }
221
- isSameSize(e) {
222
- const { width: t, height: s } = e, { width: r, height: a } = this.workOptions, i = t * this.manager.camera.scale, o = s * this.manager.camera.scale, c = r * this.manager.camera.scale, l = a * this.manager.camera.scale;
223
- return i === c && o === l;
224
- }
225
- isSamePosition(e) {
226
- const { centerX: t, centerY: s } = e, { centerX: r, centerY: a } = this.workOptions, i = this.manager.getPagePoint(r, a), o = this.manager.getPagePoint(t, s);
227
- return I(o, i);
228
- }
229
- isSameZIndex(e) {
230
- const { zIndex: t } = e, { zIndex: s } = this.workOptions;
231
- return t === s;
232
- }
233
- isSameState(e) {
234
- const { state: t } = e, { state: s } = this.workOptions;
235
- return I(t, s);
236
- }
237
- isSameData(e) {
238
- const { data: t } = e, { data: s } = this.workOptions;
239
- return I(t, s);
240
- }
241
- updateElementPosition(e) {
242
- if (this.isDestroyed || !this.element || !this.fullLayer)
243
- return;
244
- const { centerX: t, centerY: s, width: r, height: a, zIndex: i } = this.workOptions, o = this.manager.getPagePoint(t, s), c = r * this.manager.camera.scale, l = a * this.manager.camera.scale;
245
- (!e || e && !this.isSameSize(e)) && (this.element.setAttribute("width", `${c}`), this.element.setAttribute("height", `${l}`), this.element.style.width = `${c}px`, this.element.style.height = `${l}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());
246
- }
247
- async updateSvg(e) {
248
- const { type: t, state: s } = this.workOptions;
249
- if (t === M.markmap) {
250
- const r = b(), { data: a } = this.workOptions;
251
- if (this.markmapInstance || (this.markmapInstance = r.createMarkmap(
252
- this.element,
253
- this.manager.markmapOptions
254
- ), this.markmapInstance.handleClick = async (c, l) => {
255
- var w, m, u;
256
- (w = this.markmapInstance) == null || w.toggleNode(l);
257
- const p = this.serializeData((m = this.markmapInstance) == null ? void 0 : m.state.data);
258
- this.setWorkOptions(
259
- {
260
- ...this.workOptions,
261
- state: p
262
- },
263
- !1
264
- ), r.checkNodeHasMermaid(l) && await r.renderMermaidAfterDOMUpdate(
265
- this.element,
266
- this.workId
267
- ), this.scenePath && this.collector && ((u = this.collector) == null || u.dispatch({
268
- type: d.UpdateNode,
269
- workId: this.workId,
270
- opt: this.workOptions,
271
- isSync: !0,
272
- viewId: this.manager.viewId,
273
- scenePath: this.scenePath
274
- }));
275
- }), e && this.isSameState(e) && this.isSameSize(e) && this.isSameData(e))
276
- return;
277
- const i = r.transform(this.workId, a);
278
- let { root: o } = i;
279
- a && r.hasMermaidCodeBlock(a) && (o = r.injectMermaidHtml(o, a, this.workId));
280
- try {
281
- 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(
282
- this.element,
283
- this.workId
284
- ), await this.fit(
285
- !e || e && !this.isSameData(e)
286
- ));
287
- } catch (c) {
288
- console.error("[updateSvg] error: ", c);
289
- }
290
- } else {
291
- const { src: r, crossOrigin: a } = this.workOptions, i = this.reloadSourceUrl ?? r;
292
- if (this.element.crossOrigin = V(a) ? a : "anonymous", !this.trackBackgroundImageLoad) {
293
- this.element.src = i, await new Promise((o, c) => {
294
- this.element.onload = () => o(), this.element.onerror = () => c();
295
- });
296
- return;
297
- }
298
- await this.manager.master.control.backgroundImageLoadCoordinator.load({
299
- viewId: this.manager.viewId,
300
- scenePath: this.scenePath,
301
- resourceId: this.workId,
302
- src: i,
303
- image: this.element,
304
- isActive: () => !this.isDestroyed && this.manager.master.control.viewContainerManager.getCurScenePath(
305
- this.manager.viewId
306
- ) === this.scenePath,
307
- onReloadUrl: (o) => {
308
- this.reloadSourceUrl = o;
309
- }
310
- });
311
- }
312
- }
313
- async fit(e = !0) {
314
- var t;
315
- if (!this.isDestroyed && this.element && this.fullLayer && this.markmapInstance) {
316
- const s = b();
317
- e && this.element && await s.waitForImagesInForeignObjects(
318
- this.element
319
- ), await ((t = this.markmapInstance) == null ? void 0 : t.fit()), this.element && s.isSafari() && s.hasMermaidSvg(this.element) && (await P(this.element), await s.transformMermaidSvgToMarkmapSvg(
320
- this.element
321
- ));
322
- }
323
- }
324
- serializeData(e) {
325
- var r;
326
- const t = [e], s = [];
327
- for (; t.length > 0; ) {
328
- const a = t.pop();
329
- a && (a != null && a.children && t.push(...a.children), s.push(((r = a == null ? void 0 : a.payload) == null ? void 0 : r.fold) || 0));
330
- }
331
- return s;
332
- }
333
- transformState(e, t) {
334
- const s = [t];
335
- for (; s.length > 0; ) {
336
- const r = s.pop();
337
- r && (r != null && r.children && s.push(...r.children), r.payload ? r.payload.fold = e.shift() : e.shift());
338
- }
339
- }
340
- async updateCamera() {
341
- this.updateElementPosition(), await this.fit(!1);
342
- }
343
- async setWorkOptions(e, t = !0) {
344
- if (!I(this.workOptions, e)) {
345
- const s = U(this.workOptions), r = "src" in this.workOptions ? this.workOptions.src : void 0, a = "src" in e ? e.src : void 0;
346
- r !== a && (this.reloadSourceUrl = void 0), this.workOptions = e, t && await this.render(s);
347
- }
348
- }
349
- destroy() {
350
- this.isDestroyed = !0, this.reloadSourceUrl = void 0, this.trackBackgroundImageLoad && this.manager.master.control.backgroundImageLoadCoordinator.cancelResource(
351
- this.manager.viewId,
352
- this.scenePath,
353
- this.workId
354
- ), this.element.remove();
355
- }
356
- getRectFromLayer() {
357
- const e = this.element.getBoundingClientRect();
358
- return {
359
- x: e.x,
360
- y: e.y,
361
- w: e.width,
362
- h: e.height
363
- };
364
- }
365
- }
366
- function C(n) {
367
- const { toolsType: e, ...t } = n;
368
- switch (e) {
369
- case k.BackgroundSVG:
370
- return new X(t);
371
- default:
372
- return;
373
- }
374
- }
375
- class W {
376
- constructor(e) {
377
- h(this, "viewId");
378
- h(this, "fullLayer");
379
- h(this, "curNodeMap");
380
- this.viewId = e, this.curNodeMap = new A();
381
- }
382
- init(e) {
383
- this.fullLayer = e;
384
- }
385
- get(e) {
386
- return this.curNodeMap.get(e);
387
- }
388
- setInfo(e, t) {
389
- const s = this.curNodeMap.get(
390
- e
391
- ) || {
392
- name: e,
393
- workShape: t.workShape
394
- };
395
- t.workShape && (s.workShape = t.workShape), this.curNodeMap.set(e, s);
396
- }
397
- getNodeRectFormShape(e) {
398
- const t = this.curNodeMap.get(e);
399
- if (t && t.workShape)
400
- return t.workShape.getRectFromLayer();
401
- }
402
- delete(e) {
403
- const t = this.curNodeMap.get(e);
404
- t && t.workShape.destroy(), this.curNodeMap.delete(e);
405
- }
406
- clear() {
407
- for (const e of this.curNodeMap.values())
408
- e.workShape.destroy();
409
- this.curNodeMap.clear();
410
- }
411
- }
412
- class Y {
413
- constructor(e, t) {
414
- h(this, "opt");
415
- h(this, "viewId");
416
- h(this, "fullLayer");
417
- h(this, "vNodes");
418
- h(this, "master");
419
- h(this, "cameraOpt");
420
- h(this, "methodBuilder");
421
- h(this, "updateCamera", D(async (e) => {
422
- const { cameraOpt: t } = e;
423
- t && !I(this.cameraOpt, t) && await this.setCameraOpt(t);
424
- }, 100));
425
- this.viewId = e, this.opt = t, this.master = t.master, this.fullLayer = t.container, this.methodBuilder = new q([
426
- T.CopyNode
427
- ]).registerForBackgroundThread(this), this.vNodes = new W(e), this.vNodes.init(this.fullLayer);
428
- }
429
- get camera() {
430
- return this.cameraOpt || {
431
- scale: 1,
432
- centerX: 0,
433
- centerY: 0,
434
- width: 0,
435
- height: 0
436
- };
437
- }
438
- get view() {
439
- var e;
440
- return (e = this.master.control.viewContainerManager.getView(this.viewId)) == null ? void 0 : e.viewData;
441
- }
442
- get markmapOptions() {
443
- return this.master.control.pluginOptions.extras.markmap.options;
444
- }
445
- getPagePoint(e, t) {
446
- const { scale: s, centerX: r, centerY: a, width: i, height: o } = this.camera;
447
- return {
448
- x: (e - r) * s + i / 2,
449
- y: (t - a) * s + o / 2
450
- };
451
- }
452
- async setCameraOpt(e) {
453
- this.cameraOpt = e;
454
- for (const t of this.vNodes.curNodeMap.values()) {
455
- const { workShape: s } = t;
456
- s && await s.updateCamera();
457
- }
458
- }
459
- clearAll() {
460
- this.vNodes.clear();
461
- }
462
- canUseFullLayer(e) {
463
- return e === k.BackgroundSVG;
464
- }
465
- async consumeFull(e) {
466
- const { toolsType: t, opt: s, workId: r, scenePath: a } = e;
467
- if (r != null && r.toString() && t && this.canUseFullLayer(t))
468
- switch (t) {
469
- case k.BackgroundSVG:
470
- await this.setFullWork({
471
- toolsType: t,
472
- opt: s,
473
- workId: r,
474
- scenePath: a
475
- });
476
- break;
477
- }
478
- }
479
- async setFullWork(e) {
480
- const { workId: t, opt: s, toolsType: r, scenePath: a } = e;
481
- if (t && s && r && a) {
482
- const i = t.toString();
483
- let o;
484
- const c = this.vNodes.get(i);
485
- return !c || !c.workShape ? (o = this.createWorkShapeNode({
486
- toolsOpt: s,
487
- toolsType: k.BackgroundSVG,
488
- workId: i,
489
- scenePath: a
490
- }), o && await o.init()) : (o = c.workShape, await o.setWorkOptions(s)), o;
491
- }
492
- }
493
- createWorkShapeNode(e) {
494
- return C({
495
- ...e,
496
- vNodes: this.vNodes,
497
- manager: this
498
- });
499
- }
500
- removeWork(e) {
501
- const { workId: t } = e, s = t == null ? void 0 : t.toString();
502
- s && this.removeNode(s);
503
- }
504
- removeNode(e) {
505
- this.vNodes.delete(e);
506
- }
507
- async on(e) {
508
- if (!await this.methodBuilder.consumeForBackgroundThread(e)) {
509
- const { msgType: t, toolsType: s } = e;
510
- switch (t) {
511
- case d.Destroy: {
512
- this.destroy();
513
- break;
514
- }
515
- case d.Clear: {
516
- this.clearAll();
517
- break;
518
- }
519
- case d.UpdateCamera: {
520
- this.updateCamera(e);
521
- break;
522
- }
523
- case d.UpdateTools: {
524
- this.toggleFullLayer(s === k.Clicker);
525
- break;
526
- }
527
- case d.BackgroundSVGUpdate:
528
- case d.UpdateNode:
529
- case d.FullWork: {
530
- s && this.canUseFullLayer(s) && await this.consumeFull(e);
531
- break;
532
- }
533
- case d.BackgroundSVGDelete: {
534
- this.removeWork(e);
535
- break;
536
- }
537
- }
538
- }
539
- }
540
- toggleFullLayer(e) {
541
- this.fullLayer.classList.toggle(
542
- "appliance-plugin-background-svg-active",
543
- e
544
- );
545
- }
546
- destroy() {
547
- this.vNodes.clear();
548
- }
549
- }
550
- class j {
551
- constructor(e, t) {
552
- h(this, "viewId");
553
- h(this, "fullLayer");
554
- h(this, "master");
555
- h(this, "vNodes");
556
- h(this, "cameraOpt");
557
- h(this, "opt");
558
- h(this, "workShapes", /* @__PURE__ */ new Map());
559
- this.viewId = e, this.opt = t, this.master = t.master, this.fullLayer = t.container, this.vNodes = new W(e), this.vNodes.init(this.fullLayer);
560
- }
561
- get camera() {
562
- return this.cameraOpt || {
563
- scale: 1,
564
- centerX: 0,
565
- centerY: 0,
566
- width: 0,
567
- height: 0
568
- };
569
- }
570
- get view() {
571
- var e;
572
- return (e = this.master.control.viewContainerManager.getView(this.viewId)) == null ? void 0 : e.viewData;
573
- }
574
- get markmapOptions() {
575
- return this.master.control.pluginOptions.extras.markmap.options;
576
- }
577
- createOffscreenCanvas(e) {
578
- const { width: t, height: s } = e.canvasOpt, r = new OffscreenCanvas(
579
- e.canvasOpt.width,
580
- e.canvasOpt.height
581
- );
582
- r.width = t, r.height = s;
583
- }
584
- async setCameraOpt(e) {
585
- this.cameraOpt = e;
586
- for (const t of this.vNodes.curNodeMap.values()) {
587
- const { workShape: s } = t;
588
- s && await s.updateCamera();
589
- }
590
- }
591
- getPagePoint(e, t) {
592
- const { scale: s, centerX: r, centerY: a, width: i, height: o } = this.camera;
593
- return {
594
- x: (e - r) * s + i / 2,
595
- y: (t - a) * s + o / 2
596
- };
597
- }
598
- async getSnapshot(e) {
599
- const { scenePath: t, scenes: s, cameraOpt: r } = e;
600
- if (t && s && r) {
601
- await this.setCameraOpt(r);
602
- for (const [a, i] of Object.entries(s))
603
- if (i != null && i.type && (i == null ? void 0 : i.toolsType) === k.BackgroundSVG)
604
- switch (i == null ? void 0 : i.type) {
605
- case d.UpdateNode:
606
- case d.FullWork: {
607
- const { opt: o } = i, c = {
608
- ...i,
609
- opt: o,
610
- workId: a,
611
- msgType: d.FullWork,
612
- dataType: L.Service,
613
- viewId: this.viewId,
614
- scenePath: t
615
- };
616
- await this.runFullWork(c);
617
- break;
618
- }
619
- }
620
- try {
621
- if (t) {
622
- await P(this.fullLayer), await _(this.fullLayer), await z(this.fullLayer);
623
- const a = await G(this.fullLayer);
624
- a && this.opt.post({
625
- sp: [
626
- {
627
- type: d.Snapshot,
628
- scenePath: t,
629
- imageElement: a,
630
- viewId: this.viewId,
631
- index: 1
632
- }
633
- ]
634
- });
635
- }
636
- } catch (a) {
637
- const i = a && a instanceof Error ? a.message : a == null ? void 0 : a.toString();
638
- this.opt.post({
639
- sp: [
640
- {
641
- type: d.ReportError,
642
- reportString: `[SnapshotThreadImpl] getSnapshotRender error: ${i}`
643
- }
644
- ]
645
- });
646
- }
647
- }
648
- }
649
- createWorkShapeNode(e) {
650
- return C({
651
- ...e,
652
- vNodes: this.vNodes,
653
- manager: this,
654
- trackBackgroundImageLoad: !1
655
- });
656
- }
657
- async setFullWork(e) {
658
- const { workId: t, opt: s, toolsType: r, scenePath: a } = e;
659
- if (t && s && r && a) {
660
- const i = t.toString();
661
- let o;
662
- const c = this.vNodes.get(i);
663
- return !c || !c.workShape ? (o = this.createWorkShapeNode({
664
- toolsOpt: s,
665
- toolsType: k.BackgroundSVG,
666
- workId: i,
667
- scenePath: a
668
- }), o && await o.init()) : (o = c.workShape, await o.setWorkOptions(s)), o;
669
- }
670
- }
671
- async runFullWork(e) {
672
- const { toolsType: t, opt: s, workId: r, scenePath: a } = e;
673
- await this.setFullWork({
674
- toolsType: t,
675
- opt: s,
676
- workId: r,
677
- scenePath: a
678
- });
679
- }
680
- destroy() {
681
- this.fullLayer.innerHTML = "", this.fullLayer.style.width = "", this.fullLayer.style.height = "";
682
- }
683
- }
684
- class oe {
685
- constructor(e) {
686
- h(this, "backgroundThreadMap", /* @__PURE__ */ new Map());
687
- h(this, "snapshotThread");
688
- h(this, "master");
689
- h(this, "post", (e) => {
690
- const { sp: t } = e;
691
- t && this.master.collectorSyncData(t);
692
- });
693
- this.master = e, this.backgroundThreadMap = /* @__PURE__ */ new Map();
694
- }
695
- createBackgroundThread(e, t) {
696
- return new Y(e, t);
697
- }
698
- createSnapshotThread(e, t) {
699
- return new j(e, t);
700
- }
701
- async consume(e) {
702
- var t, s, r, a, i, o;
703
- for (const c of e.values()) {
704
- const {
705
- msgType: l,
706
- viewId: p,
707
- layerOpt: y,
708
- offscreenCanvasOpt: w,
709
- cameraOpt: m,
710
- tasksqueue: u
711
- } = c;
712
- if (l === d.Console) {
713
- console.log(this);
714
- continue;
715
- }
716
- if (l === d.Init) {
717
- const g = (t = this.master.control.viewContainerManager.getView(p)) == null ? void 0 : t.displayer, v = (s = g == null ? void 0 : g.backgroundContainerRef) == null ? void 0 : s.current;
718
- if (g && v && y && w) {
719
- const f = this.backgroundThreadMap.get(p);
720
- f == null || f.destroy();
721
- const S = this.createBackgroundThread(p, {
722
- displayer: g,
723
- container: v,
724
- layerOpt: y,
725
- master: this.master,
726
- canvasOpt: w,
727
- post: this.post
728
- });
729
- this.backgroundThreadMap.set(p, S), S && m && await S.setCameraOpt(m);
730
- }
731
- continue;
732
- }
733
- if (l === d.Snapshot) {
734
- const g = (r = this.master.control.viewContainerManager.getView(p)) == null ? void 0 : r.displayer, f = (i = ((a = this.master.control.viewContainerManager.mainView) == null ? void 0 : a.displayer).backgroundSnapshotContainerRef) == null ? void 0 : i.current;
735
- if (g && f && m) {
736
- (o = this.snapshotThread) == null || o.destroy(), f.style.width = `${m.width}px`, f.style.height = `${m.height}px`;
737
- const S = {
738
- ...N.defaultLayerOpt,
739
- offscreen: !1,
740
- width: m.width,
741
- height: m.height
742
- }, B = {
743
- ...N.defaultScreenCanvasOpt,
744
- width: m.width,
745
- height: m.height
746
- };
747
- this.snapshotThread = this.createSnapshotThread(p, {
748
- displayer: g,
749
- container: f,
750
- layerOpt: S,
751
- master: this.master,
752
- canvasOpt: B,
753
- post: this.post
754
- }), await this.snapshotThread.getSnapshot(c), this.snapshotThread.destroy(), this.snapshotThread = void 0;
755
- continue;
756
- }
757
- }
758
- if (l === d.TasksQueue && (u != null && u.size)) {
759
- for (const [g, v] of this.backgroundThreadMap.entries()) {
760
- const f = u.get(g);
761
- f && await v.on(f);
762
- }
763
- continue;
764
- }
765
- if (p === x) {
766
- for (const g of this.backgroundThreadMap.values())
767
- await g.on(c);
768
- l === d.Destroy && this.backgroundThreadMap.clear();
769
- continue;
770
- }
771
- const O = this.backgroundThreadMap.get(p);
772
- O && (await O.on(c), l === d.Destroy && this.backgroundThreadMap.delete(p));
773
- }
774
- }
775
- async consumeTargetOne(e, t) {
776
- const s = this.backgroundThreadMap.get(e);
777
- s && await s.on(t);
778
- }
779
- destroy() {
780
- var e;
781
- (e = this.snapshotThread) == null || e.destroy(), this.snapshotThread = void 0;
782
- for (const t of this.backgroundThreadMap.values())
783
- t.destroy();
784
- this.backgroundThreadMap.clear();
785
- }
786
- }
787
- export {
788
- oe as BackgroundThreadManagerImpl
789
- };