@netless/appliance-plugin 1.1.36-beta.4 → 1.1.37

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