@netless/appliance-plugin 1.1.34-beta.0 → 1.1.34-beta.2

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.
@@ -0,0 +1,1255 @@
1
+ var K = Object.defineProperty;
2
+ var j = (o, e, t) => e in o ? K(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
+ var p = (o, e, t) => j(o, typeof e != "symbol" ? e + "" : e, t);
4
+ import { E as B, a as k, b as D, c as x, d as E, V as P, S as Z } from "./index-CslUUlge.mjs";
5
+ import { isEqual as W, isString as _, clone as J, throttle as Q } 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 * as z from "markmap-view";
14
+ import { Transformer as ee } from "markmap-lib";
15
+ import { O as te } from "./ObserverMap-BudneEfB.mjs";
16
+ class re {
17
+ constructor() {
18
+ p(this, "threadEngine");
19
+ }
20
+ registerBackgroundThread(e) {
21
+ return this.threadEngine = e, this;
22
+ }
23
+ }
24
+ class ae extends re {
25
+ constructor() {
26
+ super(...arguments);
27
+ p(this, "emitEventType", B.CopyNode);
28
+ }
29
+ async consume(t) {
30
+ const { msgType: r, dataType: s, emitEventType: i } = t;
31
+ if (r === k.FullWork && s === D.Local && i === this.emitEventType)
32
+ return this.consumeForLocalWorker(t), !0;
33
+ }
34
+ async consumeForLocalWorker(t) {
35
+ var s;
36
+ const { workId: r } = t;
37
+ r && await ((s = this.threadEngine) == null ? void 0 : s.consumeFull(t));
38
+ }
39
+ }
40
+ class se {
41
+ constructor(e) {
42
+ p(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 B.CopyNode:
48
+ return new ae();
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
+ let N = null, C = null, $ = !1;
64
+ function q(o) {
65
+ return !o || typeof o != "string" ? !1 : /```\s*mermaid[\s\S]*?```/i.test(o);
66
+ }
67
+ async function ie() {
68
+ return N || C || (C = import("mermaid").then((o) => (N = o, C = null, o)).catch((o) => {
69
+ throw C = null, o;
70
+ }), C);
71
+ }
72
+ async function ne() {
73
+ const o = await ie();
74
+ return $ || (o.default.initialize({
75
+ startOnLoad: !1,
76
+ theme: "default"
77
+ }), $ = !0), o;
78
+ }
79
+ function oe() {
80
+ return (N == null ? void 0 : N.default) || null;
81
+ }
82
+ const I = class I {
83
+ constructor() {
84
+ // 使用 workId 作为 key,存储每个实例的 mermaid 代码块
85
+ p(this, "mermaidCodeBlocksByWorkId", /* @__PURE__ */ new Map());
86
+ }
87
+ /**
88
+ * 获取 MermaidManager 单例实例
89
+ */
90
+ static getInstance() {
91
+ return I.instance || (I.instance = new I()), I.instance;
92
+ }
93
+ /**
94
+ * 生成唯一的 mermaid ID
95
+ */
96
+ generateId() {
97
+ return `mermaid-${Math.random().toString(36).substr(2, 9)}`;
98
+ }
99
+ /**
100
+ * 生成 mermaid HTML 容器
101
+ * @param id mermaid ID
102
+ * @param mermaidCode mermaid 代码(可选,如果提供则存储)
103
+ * @param workId 工作 ID(用于命名空间隔离)
104
+ * @returns HTML 字符串
105
+ */
106
+ createContainer(e, t, r) {
107
+ if (t && r) {
108
+ let s = this.mermaidCodeBlocksByWorkId.get(r);
109
+ s || (s = /* @__PURE__ */ new Map(), this.mermaidCodeBlocksByWorkId.set(r, s)), s.set(e, t);
110
+ }
111
+ return `<div class="mermaid-container" data-mermaid-id="${e}"><div class="mermaid-placeholder" id="${e}">正在渲染图表...</div></div>`;
112
+ }
113
+ /**
114
+ * 获取 mermaid 代码块
115
+ * @param id mermaid ID
116
+ * @param workId 工作 ID(用于命名空间隔离)
117
+ * @returns mermaid 代码或 undefined
118
+ */
119
+ getCode(e, t) {
120
+ const r = this.mermaidCodeBlocksByWorkId.get(t);
121
+ return r == null ? void 0 : r.get(e);
122
+ }
123
+ /**
124
+ * 清空指定 workId 的 mermaid 代码块
125
+ * @param workId 工作 ID(如果未提供,清空所有)
126
+ */
127
+ clear(e) {
128
+ e ? this.mermaidCodeBlocksByWorkId.delete(e) : this.mermaidCodeBlocksByWorkId.clear();
129
+ }
130
+ /**
131
+ * 扩展 markdown-it 的渲染规则,处理 mermaid 代码块
132
+ * @param transformer Transformer 实例
133
+ * @param workId 工作 ID(用于命名空间隔离)
134
+ */
135
+ extendMarkdown(e, t) {
136
+ const r = e.md.renderer, s = r.rules.fence, i = this;
137
+ r.rules.fence = (a, n, c, d, w) => {
138
+ const u = a[n];
139
+ if (u.info.trim() === "mermaid") {
140
+ const g = i.generateId();
141
+ return i.createContainer(g, u.content, t);
142
+ }
143
+ return s ? s(a, n, c, d, w) : "";
144
+ };
145
+ }
146
+ // 为了向后兼容,保留静态方法(内部使用单例)
147
+ static generateId() {
148
+ return I.getInstance().generateId();
149
+ }
150
+ static createContainer(e, t, r) {
151
+ return I.getInstance().createContainer(
152
+ e,
153
+ t,
154
+ r
155
+ );
156
+ }
157
+ static getCode(e, t) {
158
+ return I.getInstance().getCode(e, t);
159
+ }
160
+ static clear(e) {
161
+ I.getInstance().clear(e);
162
+ }
163
+ static extendMarkdown(e, t) {
164
+ I.getInstance().extendMarkdown(e, t);
165
+ }
166
+ };
167
+ p(I, "instance", null);
168
+ let b = I;
169
+ class T {
170
+ /**
171
+ * 检查 markmap 节点及其子节点是否包含 mermaid 代码块
172
+ * @param node markmap 节点数据
173
+ * @returns 如果节点或其子节点包含 mermaid 代码块,返回 true
174
+ */
175
+ static checkNodeHasMermaid(e) {
176
+ if (!e)
177
+ return !1;
178
+ if (e.content && typeof e.content == "string" && (e.content.includes('class="mermaid-container"') || e.content.includes("class='mermaid-container'") || e.content.includes("data-mermaid-id=") || e.content.includes("mermaid-placeholder")))
179
+ return !0;
180
+ if (e.children && Array.isArray(e.children)) {
181
+ for (const t of e.children)
182
+ if (T.checkNodeHasMermaid(t))
183
+ return !0;
184
+ }
185
+ return !1;
186
+ }
187
+ /**
188
+ * 等待 DOM 更新后渲染 Mermaid 图表
189
+ * @param svgElement SVG 元素
190
+ * @param workId 工作 ID
191
+ * @returns Promise<void>
192
+ */
193
+ static async renderMermaidAfterDOMUpdate(e, t) {
194
+ await T.renderMermaidBlocks(e, t);
195
+ }
196
+ /**
197
+ * 渲染所有 mermaid 容器中的图表
198
+ * @param svgElement SVG 元素
199
+ * @param workId 工作 ID
200
+ * @returns Promise<void>
201
+ */
202
+ static async renderMermaidBlocks(e, t) {
203
+ if (!e)
204
+ return;
205
+ try {
206
+ await ne();
207
+ } catch (n) {
208
+ console.error("[renderMermaidBlocks] error: ", n);
209
+ return;
210
+ }
211
+ const r = oe();
212
+ if (!r)
213
+ return;
214
+ let s = null, i = !1;
215
+ for (let n = 0; n < 30; n++) {
216
+ const c = e.querySelectorAll("foreignObject");
217
+ if (s = e.querySelectorAll(".mermaid-container"), s.length > 0 || (c.length > 0 && (i = !0), await new Promise((d) => setTimeout(d, 50)), i && n >= 20))
218
+ break;
219
+ }
220
+ if (!s || s.length === 0)
221
+ return;
222
+ const a = Array.from(s).map(
223
+ async (n, c) => {
224
+ const d = n, w = d.getAttribute("data-mermaid-id"), u = w ? b.getCode(w, t) : void 0, l = d.querySelector(
225
+ ".mermaid-placeholder"
226
+ );
227
+ if (!(!l || !u))
228
+ try {
229
+ const f = `mermaid-${t.replace(/[^a-zA-Z0-9_-]/g, "-")}-${Date.now()}-${c}`, { svg: v } = await r.render(f, u);
230
+ if (l && l.parentNode) {
231
+ const y = document.createElement("div");
232
+ y.innerHTML = v;
233
+ const m = y.querySelector("svg");
234
+ if (m) {
235
+ if (!m.getAttribute("viewBox") && m.getAttribute("width") && m.getAttribute("height")) {
236
+ const A = m.getAttribute("width"), S = m.getAttribute("height"), M = parseFloat((A == null ? void 0 : A.replace(/px|%/, "")) || "0"), O = parseFloat(
237
+ (S == null ? void 0 : S.replace(/px|%/, "")) || "0"
238
+ );
239
+ M > 0 && O > 0 && m.setAttribute(
240
+ "viewBox",
241
+ `0 0 ${M} ${O}`
242
+ );
243
+ }
244
+ m.style.display = "block", m.style.maxWidth = "100%", m.style.width = "auto", m.style.height = "auto", m.style.overflow = "visible", m.style.verticalAlign = "top", m.style.objectFit = "contain";
245
+ const h = document.createElement("div");
246
+ h.className = "mermaid-wrapper", h.style.width = "100%", h.style.height = "auto", h.style.overflow = "hidden", h.style.display = "inline-block", h.style.verticalAlign = "top", h.style.margin = "0", h.style.padding = "0", h.style.boxSizing = "border-box", h.style.position = "relative", this.isSafari() && (h.style.clipPath = "inset(100% 0 0 0)", h.style.pointerEvents = "none"), h.appendChild(m), m.style.width = "100%", m.style.height = "100%", m.style.maxWidth = "100%", m.style.maxHeight = "100%", m.style.objectFit = "contain", m.setAttribute("data-type", "mermaid"), this.isSafari() && (m.style.opacity = "0"), l.parentNode.replaceChild(h, l);
247
+ } else
248
+ l.outerHTML = v;
249
+ }
250
+ } catch (g) {
251
+ const f = g instanceof Error ? g.message : String(g);
252
+ l && (l.textContent = `Mermaid 渲染失败: ${f}`, l.style.color = "red", l.style.fontSize = "12px");
253
+ }
254
+ }
255
+ );
256
+ await Promise.all(a);
257
+ }
258
+ /**
259
+ * 检测是否是 Safari 浏览器
260
+ * @returns 如果是 Safari 返回 true,否则返回 false
261
+ */
262
+ static isSafari() {
263
+ const e = navigator.userAgent.toLowerCase(), t = e.indexOf("safari") !== -1 && e.indexOf("chrome") === -1 && e.indexOf("chromium") === -1, r = !!(navigator.vendor && navigator.vendor.indexOf("Apple") !== -1);
264
+ return t || r;
265
+ }
266
+ /**
267
+ * 将 mermaid SVG 从 foreignObject 移出,直接添加到 markmap SVG 中(Safari 兼容性处理)
268
+ * 克隆 mermaid SVG 元素,设置正确的尺寸和位置,然后将 foreignObject 中的 mermaid-container 透明度设为 0
269
+ * @param svgElement markmap SVG 元素
270
+ * @returns Promise<void>
271
+ */
272
+ static async transformMermaidSvgToMarkmapSvg(e) {
273
+ if (!e)
274
+ return;
275
+ await new Promise((a) => setTimeout(a, 200));
276
+ const t = e.querySelectorAll(
277
+ 'g[data-mermaid-wrapper][data-mermaid-clone="true"]'
278
+ ), r = e.querySelectorAll("foreignObject"), s = /* @__PURE__ */ new Set();
279
+ if (r.forEach((a) => {
280
+ const n = a.querySelector(
281
+ ".mermaid-container"
282
+ ), c = n == null ? void 0 : n.getAttribute("data-mermaid-id");
283
+ c && s.add(c);
284
+ }), t.forEach((a) => {
285
+ const n = a.getAttribute("data-mermaid-id");
286
+ n && !s.has(n) && a.remove();
287
+ }), r.length === 0)
288
+ return;
289
+ const i = Array.from(r).map(
290
+ async (a) => {
291
+ let n = a.querySelector(
292
+ 'svg[data-type="mermaid"]'
293
+ );
294
+ if (!n) {
295
+ const w = a.querySelector(".mermaid-wrapper");
296
+ w && (n = w.querySelector(
297
+ 'svg[data-type="mermaid"]'
298
+ ));
299
+ }
300
+ if (!n)
301
+ return;
302
+ const c = a.querySelector(
303
+ ".mermaid-container"
304
+ ), d = c == null ? void 0 : c.getAttribute("data-mermaid-id");
305
+ if (d)
306
+ try {
307
+ const w = parseFloat(a.getAttribute("x") || "0"), u = parseFloat(a.getAttribute("y") || "0"), l = parseFloat(
308
+ a.getAttribute("width") || "0"
309
+ ), g = parseFloat(
310
+ a.getAttribute("height") || "0"
311
+ );
312
+ if (l <= 0 || g <= 0)
313
+ return;
314
+ const f = a.parentElement;
315
+ if (!f || f.tagName !== "g")
316
+ return;
317
+ let v = f.getAttribute("transform");
318
+ if (!v)
319
+ v = `translate(${w}, ${u})`;
320
+ else {
321
+ const S = v.match(
322
+ /translate\(([^,]+),([^)]+)\)/
323
+ );
324
+ if (S) {
325
+ const M = parseFloat(S[1]), O = parseFloat(S[2]), F = M + w, R = O + u;
326
+ v = v.replace(
327
+ /translate\([^)]+\)/,
328
+ `translate(${F}, ${R})`
329
+ );
330
+ } else
331
+ v = `translate(${w}, ${u}) ${v}`;
332
+ }
333
+ const y = e.querySelector(
334
+ `g[data-mermaid-wrapper][data-mermaid-id="${d}"][data-mermaid-clone="true"]`
335
+ );
336
+ let m;
337
+ if (y) {
338
+ m = y;
339
+ const S = m.querySelector('svg[data-type="mermaid"]');
340
+ S && m.removeChild(S);
341
+ } else
342
+ m = document.createElementNS(
343
+ "http://www.w3.org/2000/svg",
344
+ "g"
345
+ ), m.setAttribute("data-mermaid-wrapper", "true"), m.setAttribute("data-mermaid-clone", "true"), m.setAttribute("data-mermaid-id", d);
346
+ m.setAttribute("transform", v);
347
+ const h = n.cloneNode(!0);
348
+ if (h.setAttribute("width", l.toString()), h.setAttribute("height", g.toString()), h.setAttribute("data-mermaid-transformed", "true"), h.style.width = "", h.style.height = "", h.style.maxWidth = "", h.style.maxHeight = "", h.style.transform = "", h.style.transformOrigin = "", h.style.display = "block", h.style.overflow = "visible", h.style.opacity = "1", !h.getAttribute("viewBox")) {
349
+ const S = h.getAttribute("width"), M = h.getAttribute("height");
350
+ if (S && M) {
351
+ const O = parseFloat(
352
+ S.replace(/px|%/, "") || "0"
353
+ ), F = parseFloat(
354
+ M.replace(/px|%/, "") || "0"
355
+ );
356
+ O > 0 && F > 0 && h.setAttribute(
357
+ "viewBox",
358
+ `0 0 ${O} ${F}`
359
+ );
360
+ }
361
+ }
362
+ m.appendChild(h), y || (f && f.parentNode ? f.parentNode.insertBefore(m, f.nextSibling) : e.appendChild(m)), c && (c.style.opacity = "0", c.style.pointerEvents = "none");
363
+ } catch (w) {
364
+ console.error("[transformMermaidSvgToMarkmapSvg] error: ", w);
365
+ }
366
+ }
367
+ );
368
+ await Promise.all(i);
369
+ }
370
+ /**
371
+ * 在 root 数据中注入 mermaid HTML
372
+ * 找到包含 mermaid 代码块的节点,将 HTML 添加到其 content 中
373
+ * @param root markmap root 数据
374
+ * @param markdown markdown 文本
375
+ * @param workId 工作 ID(用于命名空间隔离)
376
+ * @returns 修改后的 root 数据
377
+ */
378
+ static injectMermaidHtml(e, t, r) {
379
+ const s = [], i = t.split(`
380
+ `);
381
+ let a = "", n = !1, c = [], d = -1;
382
+ for (let u = 0; u < i.length; u++) {
383
+ const l = i[u], g = l.match(/^(#{1,6})\s+(.+)$/);
384
+ if (g && (a = g[2].trim()), l.trim().startsWith("```mermaid"))
385
+ n = !0, c = [], d = u;
386
+ else if (n && l.trim() === "```") {
387
+ n = !1;
388
+ const f = c.join(`
389
+ `);
390
+ f && a && s.push({
391
+ title: a,
392
+ content: f,
393
+ index: d
394
+ }), c = [];
395
+ } else n && c.push(l);
396
+ }
397
+ const w = (u) => {
398
+ if (!u) return;
399
+ const l = u.content || "", g = T.decodeHtmlEntities(l);
400
+ for (const f of s)
401
+ if (g.includes(f.title) || l.includes(f.title)) {
402
+ const v = b.generateId(), y = b.createContainer(
403
+ v,
404
+ f.content,
405
+ r
406
+ );
407
+ u.content ? u.content = u.content + y : u.content = y;
408
+ break;
409
+ }
410
+ u.children && u.children.length > 0 && u.children.forEach((f) => {
411
+ w(f);
412
+ });
413
+ };
414
+ return w(e), e;
415
+ }
416
+ /**
417
+ * 解码 HTML 实体
418
+ * @param str HTML 字符串
419
+ * @returns 解码后的字符串
420
+ */
421
+ static decodeHtmlEntities(e) {
422
+ const t = document.createElement("textarea");
423
+ return t.innerHTML = e, t.value;
424
+ }
425
+ /**
426
+ * 检查 divElement 中是否包含 mermaid SVG 元素
427
+ * @param divElement HTMLDivElement 或 SVGSVGElement 元素
428
+ * @returns 如果包含 mermaid SVG 元素,返回 true,否则返回 false
429
+ */
430
+ static hasMermaidSvg(e) {
431
+ return e.querySelectorAll("svg[data-type='mermaid']").length > 0;
432
+ }
433
+ }
434
+ class U extends ee {
435
+ constructor(t) {
436
+ super(t);
437
+ p(this, "currentWorkId", null);
438
+ }
439
+ /**
440
+ * 设置当前工作 ID(用于命名空间隔离)
441
+ * @param workId 工作 ID
442
+ */
443
+ setWorkId(t) {
444
+ this.currentWorkId = t, t && b.extendMarkdown(this, t);
445
+ }
446
+ transform(t, r) {
447
+ this.currentWorkId ? b.clear(this.currentWorkId) : b.clear();
448
+ const s = this.convertKatexToText(t), i = super.transform(s, r);
449
+ return i.root && this.processKatexInRoot(i.root), i;
450
+ }
451
+ /**
452
+ * 将 markdown 内容中的 katex 公式转换为普通文本
453
+ * 处理 $...$ 和 $$...$$ 格式的公式
454
+ * 由于 Safari 对 katex 的兼容性问题,将公式转换为普通文本显示
455
+ * @param content markdown 内容
456
+ * @returns 处理后的内容
457
+ */
458
+ convertKatexToText(t) {
459
+ if (!t)
460
+ return t;
461
+ let r = t.replace(
462
+ /\$\$([\s\S]*?)\$\$/g,
463
+ (s, i) => i.replace(/\\/g, "").replace(/\{/g, "").replace(/\}/g, "").replace(/\\over/g, "/").replace(/\\pm/g, "±").replace(/\\sqrt/g, "√").replace(/\\frac/g, "/").trim()
464
+ );
465
+ return r = r.replace(
466
+ /\$([^$\n]+?)\$/g,
467
+ (s, i) => i.replace(/\\/g, "").replace(/\{/g, "").replace(/\}/g, "").replace(/\\over/g, "/").replace(/\\pm/g, "±").replace(/\\sqrt/g, "√").replace(/\\frac/g, "/").trim()
468
+ ), r;
469
+ }
470
+ /**
471
+ * 处理转换结果中的 katex HTML,将其转换为普通文本
472
+ * 递归处理节点树,查找包含 katex 的内容并转换
473
+ * 由于 Safari 对 katex 的兼容性问题,将 katex HTML 转换为普通文本显示
474
+ * @param node markmap 节点
475
+ */
476
+ processKatexInRoot(t) {
477
+ if (t) {
478
+ if (t.content && typeof t.content == "string" && (t.content.includes("katex") || t.content.includes("katex-mathml"))) {
479
+ const r = t.content.match(
480
+ /<annotation[^>]*encoding="application\/x-tex">([^<]+)<\/annotation>/
481
+ );
482
+ if (r) {
483
+ const s = r[1].replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/\\/g, "").replace(/\{/g, "").replace(/\}/g, "").replace(/\\over/g, "/").replace(/\\pm/g, "±").replace(/\\sqrt/g, "√").replace(/\\frac/g, "/").trim();
484
+ t.content = t.content.replace(
485
+ /<div[^>]*xmlns="http:\/\/www\.w3\.org\/1999\/xhtml"[^>]*>Katex:\s*<span[^>]*class="katex"[^>]*>[\s\S]*?<\/span><\/div>/g,
486
+ s
487
+ );
488
+ } else {
489
+ const s = document.createElement("div");
490
+ s.innerHTML = t.content;
491
+ const i = s.querySelector(".katex");
492
+ if (i) {
493
+ let a = i.textContent || "";
494
+ a = a.replace(/^Katex:\s*/i, "").trim(), t.content = t.content.replace(
495
+ /<div[^>]*xmlns="http:\/\/www\.w3\.org\/1999\/xhtml"[^>]*>Katex:\s*<span[^>]*class="katex"[^>]*>[\s\S]*?<\/span><\/div>/g,
496
+ a || "公式"
497
+ );
498
+ } else {
499
+ const a = t.content.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").replace(/^Katex:\s*/i, "").trim();
500
+ t.content = a || "公式";
501
+ }
502
+ }
503
+ }
504
+ t.children && Array.isArray(t.children) && t.children.forEach((r) => {
505
+ this.processKatexInRoot(r);
506
+ });
507
+ }
508
+ }
509
+ /**
510
+ * 等待 markmap foreignObject 内所有图片加载完成
511
+ * 用于在调用 fit() 之前确保所有图片都已加载,以便正确计算尺寸
512
+ * @param svgElement SVG 元素
513
+ * @param timeout 超时时间(毫秒),默认 10 秒
514
+ * @returns Promise<void> 当所有图片加载完成时 resolve
515
+ */
516
+ static async waitForImagesInForeignObjects(t, r = 1e4) {
517
+ if (!t)
518
+ return;
519
+ const s = t.querySelectorAll(
520
+ "foreignObject.markmap-foreign img"
521
+ );
522
+ if (s.length === 0)
523
+ return;
524
+ const i = [], a = /* @__PURE__ */ new Set();
525
+ s.forEach((n) => {
526
+ const c = n.src || n.getAttribute("src");
527
+ if (!c || a.has(c) || (a.add(c), n.complete && n.naturalWidth > 0))
528
+ return;
529
+ const d = new Promise((w) => {
530
+ const u = setTimeout(() => {
531
+ w();
532
+ }, r);
533
+ if (n.complete && n.naturalWidth > 0) {
534
+ clearTimeout(u), w();
535
+ return;
536
+ }
537
+ const l = () => {
538
+ clearTimeout(u), n.removeEventListener("load", l), n.removeEventListener("error", g), w();
539
+ }, g = () => {
540
+ clearTimeout(u), n.removeEventListener("load", l), n.removeEventListener("error", g), w();
541
+ };
542
+ n.addEventListener("load", l), n.addEventListener("error", g), !n.src && c && (n.src = c);
543
+ });
544
+ i.push(d);
545
+ }), i.length > 0 && await Promise.all(i);
546
+ }
547
+ }
548
+ const L = new U(), { loadCSS: ce, loadJS: le, Markmap: he } = z, { scripts: H, styles: V } = L.getAssets();
549
+ V && ce(V);
550
+ H && le(H, {
551
+ getMarkmap: () => z
552
+ });
553
+ async function de(o) {
554
+ const e = o.querySelectorAll("img"), t = Array.from(e).map((i) => {
555
+ if (!i.crossOrigin && i.src && !i.src.startsWith("data:") && (i.crossOrigin = "anonymous", i.complete)) {
556
+ const a = i.src;
557
+ i.src = "", i.src = a;
558
+ }
559
+ return i.complete && i.crossOrigin ? Promise.resolve() : new Promise((a) => {
560
+ i.onload = () => {
561
+ a(void 0);
562
+ }, i.onerror = () => {
563
+ a(void 0);
564
+ };
565
+ });
566
+ });
567
+ return o.querySelectorAll("svg").forEach((i) => {
568
+ i.querySelectorAll("image").forEach((n) => {
569
+ n.href && !n.href.baseVal.startsWith("data:") && (n.getAttribute("crossorigin") || n.setAttribute("crossorigin", "anonymous"), t.push(
570
+ new Promise((c) => {
571
+ const d = new Image();
572
+ d.crossOrigin = "anonymous", d.onload = () => {
573
+ c(void 0);
574
+ }, d.onerror = () => {
575
+ c(void 0);
576
+ }, d.src = n.href.baseVal;
577
+ })
578
+ ));
579
+ });
580
+ }), await Promise.all(t);
581
+ }
582
+ async function me(o) {
583
+ const r = Date.now();
584
+ let s = !1;
585
+ for (; Date.now() - r < 5e3; ) {
586
+ const i = o.querySelectorAll("path");
587
+ if (i.length > 0 && (s = Array.from(i).some((a) => {
588
+ const n = a.getAttribute("d") || "";
589
+ return n !== "M0,0C0,0,0,0,0,0" && n.length > 10;
590
+ }), s))
591
+ break;
592
+ await new Promise((a) => setTimeout(a, 50));
593
+ }
594
+ }
595
+ async function ue(o) {
596
+ const e = o.querySelectorAll("svg");
597
+ if (!e.length)
598
+ return;
599
+ const t = [];
600
+ for (let r = 0; r < e.length; r++) {
601
+ const s = e[r];
602
+ t.push(me(s));
603
+ }
604
+ await Promise.all(t);
605
+ }
606
+ async function G(o) {
607
+ if (T.hasMermaidSvg(o)) {
608
+ const r = Date.now();
609
+ let s = !1;
610
+ for (; Date.now() - r < 5e3 && !s; ) {
611
+ const i = o.querySelectorAll("foreignObject");
612
+ if (i.length > 0) {
613
+ let a = !0;
614
+ for (const n of Array.from(i)) {
615
+ const c = parseFloat(n.getAttribute("width") || "0"), d = parseFloat(n.getAttribute("height") || "0");
616
+ if (n.querySelector(".mermaid-container") && (c < 50 || d < 50)) {
617
+ a = !1;
618
+ break;
619
+ }
620
+ }
621
+ if (a) {
622
+ s = !0;
623
+ break;
624
+ }
625
+ } else
626
+ s = !0;
627
+ await new Promise((a) => setTimeout(a, 50));
628
+ }
629
+ }
630
+ }
631
+ async function pe(o, e = {}) {
632
+ const { width: t = o.offsetWidth, height: r = o.offsetHeight } = e, s = o.offsetWidth || t, i = o.offsetHeight || r;
633
+ try {
634
+ const { loadSvgToImageLib: a, getSvgToImageLib: n } = await import("./svgToImageLoader-mXH53h-l.mjs");
635
+ let c = n();
636
+ if (!c)
637
+ try {
638
+ c = await a();
639
+ } catch (l) {
640
+ return console.error("[loadSvgToImageLib] error: ", l), null;
641
+ }
642
+ const d = o.style.width, w = o.style.height, u = o.style.display;
643
+ o.style.width || (o.style.width = `${s}px`), o.style.height || (o.style.height = `${i}px`), (!o.style.display || o.style.display === "none") && (o.style.display = "block");
644
+ try {
645
+ await new Promise((g) => {
646
+ requestAnimationFrame(() => {
647
+ requestAnimationFrame(() => {
648
+ g();
649
+ });
650
+ });
651
+ });
652
+ const l = await c.toPng(o, {
653
+ width: s,
654
+ height: i,
655
+ quality: 1
656
+ });
657
+ return o.style.width = d, o.style.height = w, o.style.display = u, new Promise((g) => {
658
+ const f = new Image();
659
+ f.crossOrigin = "anonymous", f.onload = () => {
660
+ g(f);
661
+ }, f.onerror = () => {
662
+ g(null);
663
+ }, f.src = l;
664
+ });
665
+ } catch (l) {
666
+ return o.style.width = d, o.style.height = w, o.style.display = u, console.error("[divToImageElement] error: ", l), null;
667
+ }
668
+ } catch (a) {
669
+ return console.error("[divToImageElement] error: ", a), null;
670
+ }
671
+ }
672
+ class ge {
673
+ constructor(e) {
674
+ p(this, "toolsType", x.BackgroundSVG);
675
+ p(this, "vNodes");
676
+ p(this, "workOptions");
677
+ p(this, "workId");
678
+ p(this, "markmapInstance", null);
679
+ p(this, "isDestroyed", !1);
680
+ p(this, "element");
681
+ p(this, "manager");
682
+ const { vNodes: t, workId: r, toolsOpt: s, manager: i } = e;
683
+ this.workId = r, this.vNodes = t, this.workOptions = s, this.manager = i, this.element = this.createElement(), this.manager.fullLayer.appendChild(this.element), this.vNodes.setInfo(this.workId, {
684
+ workShape: this
685
+ });
686
+ }
687
+ get fullLayer() {
688
+ return this.manager.fullLayer;
689
+ }
690
+ get collector() {
691
+ return this.manager.master.control.collector;
692
+ }
693
+ get scenePath() {
694
+ return this.manager.master.control.viewContainerManager.getCurScenePath(
695
+ this.manager.viewId
696
+ );
697
+ }
698
+ async init() {
699
+ await this.render();
700
+ }
701
+ createElement() {
702
+ const { type: e } = this.workOptions;
703
+ let t;
704
+ return e === E.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;
705
+ }
706
+ async render(e) {
707
+ this.isDestroyed || !this.element || !this.element.parentNode || (this.updateElementPosition(e), await this.updateSvg(e));
708
+ }
709
+ isSameSize(e) {
710
+ const { width: t, height: r } = e, { width: s, height: i } = this.workOptions, a = t * this.manager.camera.scale, n = r * this.manager.camera.scale, c = s * this.manager.camera.scale, d = i * this.manager.camera.scale;
711
+ return a === c && n === d;
712
+ }
713
+ isSamePosition(e) {
714
+ const { centerX: t, centerY: r } = e, { centerX: s, centerY: i } = this.workOptions, a = this.manager.getPagePoint(s, i), n = this.manager.getPagePoint(t, r);
715
+ return W(n, a);
716
+ }
717
+ isSameZIndex(e) {
718
+ const { zIndex: t } = e, { zIndex: r } = this.workOptions;
719
+ return t === r;
720
+ }
721
+ isSameState(e) {
722
+ const { state: t } = e, { state: r } = this.workOptions;
723
+ return W(t, r);
724
+ }
725
+ isSameData(e) {
726
+ const { data: t } = e, { data: r } = this.workOptions;
727
+ return W(t, r);
728
+ }
729
+ updateElementPosition(e) {
730
+ if (this.isDestroyed || !this.element || !this.fullLayer)
731
+ return;
732
+ const { centerX: t, centerY: r, width: s, height: i, zIndex: a } = this.workOptions, n = this.manager.getPagePoint(t, r), c = s * this.manager.camera.scale, d = i * this.manager.camera.scale;
733
+ (!e || e && !this.isSameSize(e)) && (this.element.setAttribute("width", `${c}`), this.element.setAttribute("height", `${d}`), this.element.style.width = `${c}px`, this.element.style.height = `${d}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 = (a || 0).toString());
734
+ }
735
+ async updateSvg(e) {
736
+ const { type: t, state: r } = this.workOptions;
737
+ if (t === E.markmap) {
738
+ const { data: s } = this.workOptions;
739
+ if (this.markmapInstance || (this.markmapInstance = he.create(
740
+ this.element,
741
+ this.manager.markmapOptions
742
+ ), this.markmapInstance.handleClick = async (n, c) => {
743
+ var u, l, g;
744
+ (u = this.markmapInstance) == null || u.toggleNode(c);
745
+ const d = this.serializeData((l = this.markmapInstance) == null ? void 0 : l.state.data);
746
+ this.setWorkOptions(
747
+ {
748
+ ...this.workOptions,
749
+ state: d
750
+ },
751
+ !1
752
+ ), T.checkNodeHasMermaid(c) && await T.renderMermaidAfterDOMUpdate(
753
+ this.element,
754
+ this.workId
755
+ ), this.scenePath && this.collector && ((g = this.collector) == null || g.dispatch({
756
+ type: k.UpdateNode,
757
+ workId: this.workId,
758
+ opt: this.workOptions,
759
+ isSync: !0,
760
+ viewId: this.manager.viewId,
761
+ scenePath: this.scenePath
762
+ }));
763
+ }), e && this.isSameState(e) && this.isSameSize(e) && this.isSameData(e))
764
+ return;
765
+ L.setWorkId(this.workId);
766
+ const i = L.transform(s);
767
+ let { root: a } = i;
768
+ s && q(s) && (a = T.injectMermaidHtml(a, s, this.workId));
769
+ try {
770
+ r && Array.isArray(r) && this.transformState(
771
+ r,
772
+ a
773
+ ), await this.markmapInstance.setData(a), !this.isDestroyed && this.element && this.fullLayer && this.markmapInstance && (window.markmapInstance = this.markmapInstance, s && q(s) && await T.renderMermaidAfterDOMUpdate(
774
+ this.element,
775
+ this.workId
776
+ ), await this.fit(
777
+ !e || e && !this.isSameData(e)
778
+ ));
779
+ } catch (n) {
780
+ console.error("[updateSvg] error: ", n);
781
+ }
782
+ } else {
783
+ const { src: s, crossOrigin: i } = this.workOptions;
784
+ this.element.src = s, this.element.crossOrigin = _(i) ? i : "anonymous";
785
+ try {
786
+ await new Promise((a, n) => {
787
+ this.element.onload = () => {
788
+ a();
789
+ }, this.element.onerror = function() {
790
+ n();
791
+ };
792
+ });
793
+ } catch (a) {
794
+ console.error("[updateSvg] error: ", a);
795
+ }
796
+ }
797
+ }
798
+ async fit(e = !0) {
799
+ var t;
800
+ !this.isDestroyed && this.element && this.fullLayer && this.markmapInstance && (e && this.element && await U.waitForImagesInForeignObjects(
801
+ this.element
802
+ ), await ((t = this.markmapInstance) == null ? void 0 : t.fit()), this.element && T.isSafari() && T.hasMermaidSvg(this.element) && (await G(this.element), await T.transformMermaidSvgToMarkmapSvg(
803
+ this.element
804
+ )));
805
+ }
806
+ serializeData(e) {
807
+ var s;
808
+ const t = [e], r = [];
809
+ for (; t.length > 0; ) {
810
+ const i = t.pop();
811
+ i && (i != null && i.children && t.push(...i.children), r.push(((s = i == null ? void 0 : i.payload) == null ? void 0 : s.fold) || 0));
812
+ }
813
+ return r;
814
+ }
815
+ transformState(e, t) {
816
+ const r = [t];
817
+ for (; r.length > 0; ) {
818
+ const s = r.pop();
819
+ s && (s != null && s.children && r.push(...s.children), s.payload ? s.payload.fold = e.shift() : e.shift());
820
+ }
821
+ }
822
+ async updateCamera() {
823
+ this.updateElementPosition(), await this.fit(!1);
824
+ }
825
+ async setWorkOptions(e, t = !0) {
826
+ if (!W(this.workOptions, e)) {
827
+ const r = J(this.workOptions);
828
+ this.workOptions = e, t && await this.render(r);
829
+ }
830
+ }
831
+ destroy() {
832
+ this.isDestroyed = !0, this.element.remove();
833
+ }
834
+ getRectFromLayer() {
835
+ const e = this.element.getBoundingClientRect();
836
+ return {
837
+ x: e.x,
838
+ y: e.y,
839
+ w: e.width,
840
+ h: e.height
841
+ };
842
+ }
843
+ }
844
+ function X(o) {
845
+ const { toolsType: e, ...t } = o;
846
+ switch (e) {
847
+ case x.BackgroundSVG:
848
+ return new ge(t);
849
+ default:
850
+ return;
851
+ }
852
+ }
853
+ class Y {
854
+ constructor(e) {
855
+ p(this, "viewId");
856
+ p(this, "fullLayer");
857
+ p(this, "curNodeMap");
858
+ this.viewId = e, this.curNodeMap = new te();
859
+ }
860
+ init(e) {
861
+ this.fullLayer = e;
862
+ }
863
+ get(e) {
864
+ return this.curNodeMap.get(e);
865
+ }
866
+ setInfo(e, t) {
867
+ const r = this.curNodeMap.get(
868
+ e
869
+ ) || {
870
+ name: e,
871
+ workShape: t.workShape
872
+ };
873
+ t.workShape && (r.workShape = t.workShape), this.curNodeMap.set(e, r);
874
+ }
875
+ getNodeRectFormShape(e) {
876
+ const t = this.curNodeMap.get(e);
877
+ if (t && t.workShape)
878
+ return t.workShape.getRectFromLayer();
879
+ }
880
+ delete(e) {
881
+ const t = this.curNodeMap.get(e);
882
+ t && t.workShape.destroy(), this.curNodeMap.delete(e);
883
+ }
884
+ clear() {
885
+ for (const e of this.curNodeMap.values())
886
+ e.workShape.destroy();
887
+ this.curNodeMap.clear();
888
+ }
889
+ }
890
+ class fe {
891
+ constructor(e, t) {
892
+ p(this, "opt");
893
+ p(this, "viewId");
894
+ p(this, "fullLayer");
895
+ p(this, "vNodes");
896
+ p(this, "master");
897
+ p(this, "cameraOpt");
898
+ p(this, "methodBuilder");
899
+ p(this, "updateCamera", Q(async (e) => {
900
+ const { cameraOpt: t } = e;
901
+ t && !W(this.cameraOpt, t) && await this.setCameraOpt(t);
902
+ }, 100));
903
+ this.viewId = e, this.opt = t, this.master = t.master, this.fullLayer = t.container, this.methodBuilder = new se([
904
+ B.CopyNode
905
+ ]).registerForBackgroundThread(this), this.vNodes = new Y(e), this.vNodes.init(this.fullLayer);
906
+ }
907
+ get camera() {
908
+ return this.cameraOpt || {
909
+ scale: 1,
910
+ centerX: 0,
911
+ centerY: 0,
912
+ width: 0,
913
+ height: 0
914
+ };
915
+ }
916
+ get view() {
917
+ var e;
918
+ return (e = this.master.control.viewContainerManager.getView(this.viewId)) == null ? void 0 : e.viewData;
919
+ }
920
+ get markmapOptions() {
921
+ return this.master.control.pluginOptions.extras.markmap.options;
922
+ }
923
+ getPagePoint(e, t) {
924
+ const { scale: r, centerX: s, centerY: i, width: a, height: n } = this.camera;
925
+ return {
926
+ x: (e - s) * r + a / 2,
927
+ y: (t - i) * r + n / 2
928
+ };
929
+ }
930
+ async setCameraOpt(e) {
931
+ this.cameraOpt = e;
932
+ for (const t of this.vNodes.curNodeMap.values()) {
933
+ const { workShape: r } = t;
934
+ r && await r.updateCamera();
935
+ }
936
+ }
937
+ clearAll() {
938
+ this.vNodes.clear();
939
+ }
940
+ canUseFullLayer(e) {
941
+ return e === x.BackgroundSVG;
942
+ }
943
+ async consumeFull(e) {
944
+ const { toolsType: t, opt: r, workId: s } = e;
945
+ if (s != null && s.toString() && t && this.canUseFullLayer(t))
946
+ switch (t) {
947
+ case x.BackgroundSVG:
948
+ await this.setFullWork({
949
+ toolsType: t,
950
+ opt: r,
951
+ workId: s
952
+ });
953
+ break;
954
+ }
955
+ }
956
+ async setFullWork(e) {
957
+ const { workId: t, opt: r, toolsType: s } = e;
958
+ if (t && r && s) {
959
+ const i = t.toString();
960
+ let a;
961
+ const n = this.vNodes.get(i);
962
+ return !n || !n.workShape ? (a = this.createWorkShapeNode({
963
+ toolsOpt: r,
964
+ toolsType: x.BackgroundSVG,
965
+ workId: i
966
+ }), a && await a.init()) : (a = n.workShape, await a.setWorkOptions(r)), a;
967
+ }
968
+ }
969
+ createWorkShapeNode(e) {
970
+ return X({
971
+ ...e,
972
+ vNodes: this.vNodes,
973
+ manager: this
974
+ });
975
+ }
976
+ removeWork(e) {
977
+ const { workId: t } = e, r = t == null ? void 0 : t.toString();
978
+ r && this.removeNode(r);
979
+ }
980
+ removeNode(e) {
981
+ this.vNodes.delete(e);
982
+ }
983
+ async on(e) {
984
+ if (!await this.methodBuilder.consumeForBackgroundThread(e)) {
985
+ const { msgType: t, toolsType: r } = e;
986
+ switch (t) {
987
+ case k.Destroy: {
988
+ this.destroy();
989
+ break;
990
+ }
991
+ case k.Clear: {
992
+ this.clearAll();
993
+ break;
994
+ }
995
+ case k.UpdateCamera: {
996
+ this.updateCamera(e);
997
+ break;
998
+ }
999
+ case k.UpdateTools: {
1000
+ this.toggleFullLayer(r === x.Clicker);
1001
+ break;
1002
+ }
1003
+ case k.BackgroundSVGUpdate:
1004
+ case k.UpdateNode:
1005
+ case k.FullWork: {
1006
+ r && this.canUseFullLayer(r) && await this.consumeFull(e);
1007
+ break;
1008
+ }
1009
+ case k.BackgroundSVGDelete: {
1010
+ this.removeWork(e);
1011
+ break;
1012
+ }
1013
+ }
1014
+ }
1015
+ }
1016
+ toggleFullLayer(e) {
1017
+ this.fullLayer.classList.toggle(
1018
+ "appliance-plugin-background-svg-active",
1019
+ e
1020
+ );
1021
+ }
1022
+ destroy() {
1023
+ this.vNodes.clear();
1024
+ }
1025
+ }
1026
+ class we {
1027
+ constructor(e, t) {
1028
+ p(this, "viewId");
1029
+ p(this, "fullLayer");
1030
+ p(this, "master");
1031
+ p(this, "vNodes");
1032
+ p(this, "cameraOpt");
1033
+ p(this, "opt");
1034
+ p(this, "workShapes", /* @__PURE__ */ new Map());
1035
+ this.viewId = e, this.opt = t, this.master = t.master, this.fullLayer = t.container, this.vNodes = new Y(e), this.vNodes.init(this.fullLayer);
1036
+ }
1037
+ get camera() {
1038
+ return this.cameraOpt || {
1039
+ scale: 1,
1040
+ centerX: 0,
1041
+ centerY: 0,
1042
+ width: 0,
1043
+ height: 0
1044
+ };
1045
+ }
1046
+ get view() {
1047
+ var e;
1048
+ return (e = this.master.control.viewContainerManager.getView(this.viewId)) == null ? void 0 : e.viewData;
1049
+ }
1050
+ get markmapOptions() {
1051
+ return this.master.control.pluginOptions.extras.markmap.options;
1052
+ }
1053
+ createOffscreenCanvas(e) {
1054
+ const { width: t, height: r } = e.canvasOpt, s = new OffscreenCanvas(
1055
+ e.canvasOpt.width,
1056
+ e.canvasOpt.height
1057
+ );
1058
+ s.width = t, s.height = r;
1059
+ }
1060
+ async setCameraOpt(e) {
1061
+ this.cameraOpt = e;
1062
+ for (const t of this.vNodes.curNodeMap.values()) {
1063
+ const { workShape: r } = t;
1064
+ r && await r.updateCamera();
1065
+ }
1066
+ }
1067
+ getPagePoint(e, t) {
1068
+ const { scale: r, centerX: s, centerY: i, width: a, height: n } = this.camera;
1069
+ return {
1070
+ x: (e - s) * r + a / 2,
1071
+ y: (t - i) * r + n / 2
1072
+ };
1073
+ }
1074
+ async getSnapshot(e) {
1075
+ const { scenePath: t, scenes: r, cameraOpt: s } = e;
1076
+ if (t && r && s) {
1077
+ await this.setCameraOpt(s);
1078
+ for (const [i, a] of Object.entries(r))
1079
+ if (a != null && a.type && (a == null ? void 0 : a.toolsType) === x.BackgroundSVG)
1080
+ switch (a == null ? void 0 : a.type) {
1081
+ case k.UpdateNode:
1082
+ case k.FullWork: {
1083
+ const { opt: n } = a, c = {
1084
+ ...a,
1085
+ opt: n,
1086
+ workId: i,
1087
+ msgType: k.FullWork,
1088
+ dataType: D.Service,
1089
+ viewId: this.viewId
1090
+ };
1091
+ await this.runFullWork(c);
1092
+ break;
1093
+ }
1094
+ }
1095
+ try {
1096
+ if (t) {
1097
+ await G(this.fullLayer), await de(this.fullLayer), await ue(this.fullLayer);
1098
+ const i = await pe(this.fullLayer);
1099
+ i && this.opt.post({
1100
+ sp: [
1101
+ {
1102
+ type: k.Snapshot,
1103
+ scenePath: t,
1104
+ imageElement: i,
1105
+ viewId: this.viewId,
1106
+ index: 1
1107
+ }
1108
+ ]
1109
+ });
1110
+ }
1111
+ } catch (i) {
1112
+ const a = i && i instanceof Error ? i.message : i == null ? void 0 : i.toString();
1113
+ this.opt.post({
1114
+ sp: [
1115
+ {
1116
+ type: k.ReportError,
1117
+ reportString: `[SnapshotThreadImpl] getSnapshotRender error: ${a}`
1118
+ }
1119
+ ]
1120
+ });
1121
+ }
1122
+ }
1123
+ }
1124
+ createWorkShapeNode(e) {
1125
+ return X({
1126
+ ...e,
1127
+ vNodes: this.vNodes,
1128
+ manager: this
1129
+ });
1130
+ }
1131
+ async setFullWork(e) {
1132
+ const { workId: t, opt: r, toolsType: s } = e;
1133
+ if (t && r && s) {
1134
+ const i = t.toString();
1135
+ let a;
1136
+ const n = this.vNodes.get(i);
1137
+ return !n || !n.workShape ? (a = this.createWorkShapeNode({
1138
+ toolsOpt: r,
1139
+ toolsType: x.BackgroundSVG,
1140
+ workId: i
1141
+ }), a && await a.init()) : (a = n.workShape, await a.setWorkOptions(r)), a;
1142
+ }
1143
+ }
1144
+ async runFullWork(e) {
1145
+ const { toolsType: t, opt: r, workId: s } = e;
1146
+ await this.setFullWork({
1147
+ toolsType: t,
1148
+ opt: r,
1149
+ workId: s
1150
+ });
1151
+ }
1152
+ destroy() {
1153
+ this.fullLayer.innerHTML = "", this.fullLayer.style.width = "", this.fullLayer.style.height = "";
1154
+ }
1155
+ }
1156
+ class Ne {
1157
+ constructor(e) {
1158
+ p(this, "backgroundThreadMap", /* @__PURE__ */ new Map());
1159
+ p(this, "snapshotThread");
1160
+ p(this, "master");
1161
+ p(this, "post", (e) => {
1162
+ const { sp: t } = e;
1163
+ t && this.master.collectorSyncData(t);
1164
+ });
1165
+ this.master = e, this.backgroundThreadMap = /* @__PURE__ */ new Map();
1166
+ }
1167
+ createBackgroundThread(e, t) {
1168
+ return new fe(e, t);
1169
+ }
1170
+ createSnapshotThread(e, t) {
1171
+ return new we(e, t);
1172
+ }
1173
+ async consume(e) {
1174
+ var t, r, s, i, a;
1175
+ for (const n of e.values()) {
1176
+ const {
1177
+ msgType: c,
1178
+ viewId: d,
1179
+ layerOpt: w,
1180
+ offscreenCanvasOpt: u,
1181
+ cameraOpt: l,
1182
+ tasksqueue: g,
1183
+ mainTasksqueueCount: f
1184
+ } = n;
1185
+ if (c === k.Console) {
1186
+ console.log(this);
1187
+ continue;
1188
+ }
1189
+ if (c === k.Init) {
1190
+ const y = (t = this.master.control.viewContainerManager.getView(d)) == null ? void 0 : t.displayer, m = (r = y == null ? void 0 : y.backgroundContainerRef) == null ? void 0 : r.current;
1191
+ if (y && m && w && u) {
1192
+ const h = this.createBackgroundThread(d, {
1193
+ displayer: y,
1194
+ container: m,
1195
+ layerOpt: w,
1196
+ master: this.master,
1197
+ canvasOpt: u,
1198
+ post: this.post
1199
+ });
1200
+ this.backgroundThreadMap.set(d, h), h && l && await h.setCameraOpt(l);
1201
+ }
1202
+ continue;
1203
+ }
1204
+ if (c === k.Snapshot) {
1205
+ const y = (s = this.master.control.viewContainerManager.getView(d)) == null ? void 0 : s.displayer, h = (a = ((i = this.master.control.viewContainerManager.mainView) == null ? void 0 : i.displayer).backgroundSnapshotContainerRef) == null ? void 0 : a.current;
1206
+ if (y && h && l) {
1207
+ h.style.width = `${l.width}px`, h.style.height = `${l.height}px`;
1208
+ const A = {
1209
+ ...P.defaultLayerOpt,
1210
+ offscreen: !1,
1211
+ width: l.width,
1212
+ height: l.height
1213
+ }, S = {
1214
+ ...P.defaultScreenCanvasOpt,
1215
+ width: l.width,
1216
+ height: l.height
1217
+ };
1218
+ this.snapshotThread = this.createSnapshotThread(d, {
1219
+ displayer: y,
1220
+ container: h,
1221
+ layerOpt: A,
1222
+ master: this.master,
1223
+ canvasOpt: S,
1224
+ post: this.post
1225
+ }), await this.snapshotThread.getSnapshot(n), this.snapshotThread.destroy(), this.snapshotThread = void 0;
1226
+ continue;
1227
+ }
1228
+ }
1229
+ if (c === k.TasksQueue && (g != null && g.size)) {
1230
+ for (const [y, m] of this.backgroundThreadMap.entries()) {
1231
+ const h = g.get(y);
1232
+ h && (await m.on(h), f && this.post({ workerTasksqueueCount: f }));
1233
+ }
1234
+ continue;
1235
+ }
1236
+ if (d === Z) {
1237
+ for (const y of this.backgroundThreadMap.values())
1238
+ y.on(n), c === k.Destroy && this.backgroundThreadMap.delete(d);
1239
+ continue;
1240
+ }
1241
+ const v = this.backgroundThreadMap.get(d);
1242
+ v && (v.on(n), c === k.Destroy && this.backgroundThreadMap.delete(d));
1243
+ }
1244
+ }
1245
+ async consumeTargetOne(e, t) {
1246
+ const r = this.backgroundThreadMap.get(e);
1247
+ r && await r.on(t);
1248
+ }
1249
+ destroy() {
1250
+ this.backgroundThreadMap.clear();
1251
+ }
1252
+ }
1253
+ export {
1254
+ Ne as BackgroundThreadManagerImpl
1255
+ };