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

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