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