@netless/appliance-plugin 1.0.4 → 1.0.7

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 (53) hide show
  1. package/cdn/cdn.js +1 -1
  2. package/cdn/fullWorker-CF7R0e.js +438 -0
  3. package/cdn/subWorker-BbF9q2.js +438 -0
  4. package/dist/appliance-plugin.js +1 -1
  5. package/dist/appliance-plugin.mjs +7 -7
  6. package/dist/collector/utils/color.d.ts +1 -1
  7. package/dist/core/enum.d.ts +22 -16
  8. package/dist/core/mainEngine.d.ts +10 -3
  9. package/dist/core/mainThread/snapshotThread.d.ts +1 -1
  10. package/dist/core/mainThread/subLocalThread.d.ts +2 -1
  11. package/dist/core/mainThread/subTopThread.d.ts +3 -3
  12. package/dist/core/mainThread/workerMainThread.d.ts +99 -0
  13. package/dist/core/tools/eraser.d.ts +1 -20
  14. package/dist/core/tools/pencilEraser.d.ts +76 -0
  15. package/dist/core/tools/utils.d.ts +6 -5
  16. package/dist/core/types.d.ts +1 -0
  17. package/dist/core/utils/math.d.ts +3 -0
  18. package/dist/core/utils/spriteNode.d.ts +1 -1
  19. package/dist/core/vNodeManager.d.ts +1 -0
  20. package/dist/core/worker/base.d.ts +5 -2
  21. package/dist/core/worker/fullWorkerLocal.d.ts +2 -0
  22. package/dist/core/worker/subWorkerLocal.d.ts +3 -2
  23. package/dist/core/worker/subWorkerTopLayer.d.ts +3 -3
  24. package/dist/core/worker/workerManager.d.ts +1 -0
  25. package/dist/displayer/floatBar/index.d.ts +2 -2
  26. package/dist/displayer/floatBar/resizable/index.d.ts +1 -1
  27. package/dist/displayer/types.d.ts +0 -1
  28. package/dist/fullWorker.js +126 -125
  29. package/dist/index-2kLI3OsH.js +1 -0
  30. package/dist/index-C7xQ-iwn.mjs +2304 -0
  31. package/dist/index-DWP99OFK.mjs +13721 -0
  32. package/dist/index-OwNIkbKl.js +1 -0
  33. package/dist/plugin/baseApplianceManager.d.ts +5 -4
  34. package/dist/plugin/baseViewContainerManager.d.ts +4 -3
  35. package/dist/plugin/const.d.ts +3 -0
  36. package/dist/plugin/displayerView.d.ts +2 -1
  37. package/dist/plugin/multi/containerManager.d.ts +2 -0
  38. package/dist/plugin/multi/displayer/appViewDisplayerManager.d.ts +1 -0
  39. package/dist/plugin/multi/displayer/mainViewDisplayerManager.d.ts +1 -0
  40. package/dist/plugin/single/applianceSingleManager.d.ts +0 -1
  41. package/dist/plugin/single/containerManager.d.ts +2 -0
  42. package/dist/plugin/single/displayer/mainViewDisplayerManager.d.ts +1 -0
  43. package/dist/plugin/types.d.ts +11 -0
  44. package/dist/style.css +1 -1
  45. package/dist/subWorker.js +126 -125
  46. package/dist/undo/index.d.ts +0 -1
  47. package/package.json +6 -7
  48. package/cdn/fullWorker-DRJe2Z.js +0 -437
  49. package/cdn/subWorker-BCicGG.js +0 -437
  50. package/dist/index-BJWcnp2n.mjs +0 -5683
  51. package/dist/index-Bj242vt1.mjs +0 -9769
  52. package/dist/index-C_jpLx3X.js +0 -1
  53. package/dist/index-D6FsYoIf.js +0 -1
@@ -0,0 +1,2304 @@
1
+ var se = Object.defineProperty;
2
+ var oe = (I, t, e) => t in I ? se(I, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : I[t] = e;
3
+ var d = (I, t, e) => oe(I, typeof t != "symbol" ? t + "" : t, e);
4
+ import { E as f, a as T, i as re, c as C, b as ie, d as ae, e as z, f as x, g as ne, D as F, h as w, j as B, t as P, k as p, S as Y, l as N, m as V, n as ce, C as H, o as le, p as v, M as A, T as $, q as _, r as Z, s as he, u as j, V as G, v as pe } from "./index-DWP99OFK.mjs";
5
+ import { Scene as Q, Group as J } from "spritejs";
6
+ import { cloneDeep as ee, xor as de, isEqual as X, isNumber as ue } from "lodash";
7
+ import "lineclip";
8
+ import "white-web-sdk";
9
+ import "react-dom";
10
+ import "react";
11
+ class fe {
12
+ constructor(t, e) {
13
+ d(this, "viewId");
14
+ d(this, "scene");
15
+ d(this, "fullLayer");
16
+ d(this, "curNodeMap", /* @__PURE__ */ new Map());
17
+ d(this, "targetNodeMap", []);
18
+ d(this, "highLevelIds");
19
+ this.viewId = t, this.scene = e;
20
+ }
21
+ init(t) {
22
+ this.fullLayer = t;
23
+ }
24
+ get(t) {
25
+ return this.curNodeMap.get(t);
26
+ }
27
+ getUnLockNodes() {
28
+ const t = /* @__PURE__ */ new Map();
29
+ for (const [e, s] of this.curNodeMap.entries())
30
+ s.toolsType === f.Image && s.opt.locked || s.toolsType === f.Text && (s.opt.workState === T.Doing || s.opt.workState === T.Start) || t.set(e, s);
31
+ return t;
32
+ }
33
+ getNodesByType(t) {
34
+ const e = /* @__PURE__ */ new Map();
35
+ return this.curNodeMap.forEach((s, o) => {
36
+ s.toolsType === t && e.set(o, s);
37
+ }), e;
38
+ }
39
+ hasRenderNodes() {
40
+ let t = !1;
41
+ for (const e of this.curNodeMap.values())
42
+ re(e) && (t = !0);
43
+ return t;
44
+ }
45
+ has(t) {
46
+ return this.curNodeMap.has(t);
47
+ }
48
+ setInfo(t, e) {
49
+ const s = this.curNodeMap.get(t) || {
50
+ name: t,
51
+ rect: e.rect
52
+ };
53
+ e.rect && (s.rect = C(e.rect)), e.op && ie(e.op) && (s.op = C(e.op)), e.canRotate && (s.canRotate = e.canRotate), e.scaleType && (s.scaleType = e.scaleType), e.opt && (s.opt = C(e.opt)), e.toolsType && (s.toolsType = e.toolsType), e.centerPos && (s.centerPos = C(e.centerPos)), ae(e.isSelected) && (s.isSelected = e.isSelected), s.rect ? this.curNodeMap.set(t, s) : this.curNodeMap.delete(t);
54
+ }
55
+ selected(t) {
56
+ this.setInfo(t, { isSelected: !0 });
57
+ }
58
+ unSelected(t) {
59
+ this.setInfo(t, { isSelected: !1 });
60
+ }
61
+ delete(t) {
62
+ this.curNodeMap.delete(t);
63
+ }
64
+ clear() {
65
+ this.curNodeMap.clear(), this.targetNodeMap.length = 0;
66
+ }
67
+ hasRectIntersectRange(t, e = !0) {
68
+ for (const s of this.curNodeMap.values())
69
+ if (z(t, s.rect)) {
70
+ if (e && s.toolsType === f.Image && s.opt.locked || e && s.toolsType === f.Text && (s.opt.workState === T.Doing || s.opt.workState === T.Start))
71
+ continue;
72
+ return !0;
73
+ }
74
+ return !1;
75
+ }
76
+ getRectIntersectRange(t, e = !0, s = !0) {
77
+ let o;
78
+ const r = /* @__PURE__ */ new Map();
79
+ for (const [i, n] of this.curNodeMap.entries())
80
+ if (z(t, n.rect)) {
81
+ if (e && n.toolsType === f.Image && n.opt.locked || s && n.toolsType === f.Text && (n.opt.workState === T.Doing || n.opt.workState === T.Start))
82
+ continue;
83
+ o = x(o, n.rect), r.set(i, n);
84
+ }
85
+ return {
86
+ rectRange: o,
87
+ nodeRange: r
88
+ };
89
+ }
90
+ getNodeRectFormShape(t, e) {
91
+ const s = ne(e.toolsType);
92
+ return this.fullLayer && (s == null ? void 0 : s.getRectFromLayer(this.fullLayer, t));
93
+ }
94
+ updateNodeRect(t) {
95
+ const e = this.curNodeMap.get(t);
96
+ if (e) {
97
+ const s = this.getNodeRectFormShape(t, e);
98
+ if (!s) {
99
+ this.curNodeMap.delete(t);
100
+ return;
101
+ }
102
+ e.rect = s, this.curNodeMap.set(t, e);
103
+ }
104
+ }
105
+ updateHighLevelNodesRect(t) {
106
+ this.highLevelIds = t;
107
+ for (const e of this.highLevelIds.keys())
108
+ this.updateNodeRect(e);
109
+ }
110
+ updateLowLevelNodesRect() {
111
+ var t;
112
+ for (const e of this.curNodeMap.keys())
113
+ (t = this.highLevelIds) != null && t.has(e) || this.updateNodeRect(e);
114
+ }
115
+ clearHighLevelIds() {
116
+ this.highLevelIds = void 0;
117
+ }
118
+ combineIntersectRect(t) {
119
+ let e = t;
120
+ return this.curNodeMap.forEach((s) => {
121
+ z(e, s.rect) && (e = x(e, s.rect));
122
+ }), e;
123
+ }
124
+ setTargetAssignKeys(t) {
125
+ const e = /* @__PURE__ */ new Map();
126
+ for (const s of t) {
127
+ const o = this.curNodeMap.get(s);
128
+ o && e.set(s, C(o));
129
+ }
130
+ return this.targetNodeMap.push(C(e)), this.targetNodeMap.length - 1;
131
+ }
132
+ setTarget() {
133
+ return this.targetNodeMap.push(C(this.curNodeMap)), this.targetNodeMap.length - 1;
134
+ }
135
+ getLastTarget() {
136
+ return this.targetNodeMap[this.targetNodeMap.length - 1];
137
+ }
138
+ deleteLastTarget() {
139
+ this.targetNodeMap.length && (this.targetNodeMap.length = this.targetNodeMap.length - 1);
140
+ }
141
+ getTarget(t) {
142
+ return this.targetNodeMap[t];
143
+ }
144
+ deleteTarget(t) {
145
+ this.targetNodeMap.length = t;
146
+ }
147
+ clearTarget() {
148
+ this.targetNodeMap.length = 0;
149
+ }
150
+ }
151
+ class Se {
152
+ constructor(t) {
153
+ d(this, "vNodes");
154
+ d(this, "thread");
155
+ d(this, "serviceWorkShapes", /* @__PURE__ */ new Map());
156
+ d(this, "localWorkShapes", /* @__PURE__ */ new Map());
157
+ d(this, "tmpOpt");
158
+ d(this, "animationId");
159
+ d(this, "syncUnitTime", F.syncOpt.interval);
160
+ this.vNodes = t.vNodes, this.thread = t.thread;
161
+ }
162
+ createLocalWork(t) {
163
+ const { workId: e, opt: s, toolsType: o } = t;
164
+ if (e && s) {
165
+ const r = e.toString();
166
+ !this.getToolsOpt() && o && this.setToolsOpt({
167
+ toolsType: o,
168
+ toolsOpt: s
169
+ }), this.setWorkOptions(r, s);
170
+ }
171
+ }
172
+ getLocalWorkShape(t) {
173
+ return this.localWorkShapes.get(t);
174
+ }
175
+ createLocalWorkShape(t, e) {
176
+ if (t && this.tmpOpt) {
177
+ const s = {
178
+ toolsType: this.tmpOpt.toolsType,
179
+ toolsOpt: e || this.tmpOpt.toolsOpt
180
+ }, o = this.createWorkShapeNode({ ...s, workId: t });
181
+ return o && this.localWorkShapes.set(t, {
182
+ node: o,
183
+ toolsType: o.toolsType,
184
+ workState: T.Start
185
+ }), o;
186
+ }
187
+ }
188
+ canUseTopLayer(t) {
189
+ return t === f.LaserPen;
190
+ }
191
+ destroy() {
192
+ this.clearAll();
193
+ }
194
+ clearAll() {
195
+ this.thread.topLayer.children.length && (this.thread.topLayer.parent.children.forEach((t) => {
196
+ t.name !== "viewport" && t.remove();
197
+ }), this.thread.serviceLayer.removeAllChildren()), this.serviceWorkShapes.clear(), this.localWorkShapes.clear();
198
+ }
199
+ consumeDraw(t) {
200
+ const { workId: e, dataType: s } = t;
201
+ if (s === w.Service)
202
+ this.activeServiceWorkShape(t);
203
+ else {
204
+ const o = e == null ? void 0 : e.toString(), r = o && this.localWorkShapes.get(o);
205
+ if (!r)
206
+ return;
207
+ const i = r.node.consume({ data: t, isFullWork: !1, isSubWorker: !0 });
208
+ i.rect && (r.result = i, r.workState = T.Doing, o && this.localWorkShapes.set(o, r));
209
+ }
210
+ this.runAnimation();
211
+ }
212
+ setToolsOpt(t) {
213
+ var e;
214
+ this.tmpOpt = t, (e = t.toolsOpt) != null && e.syncUnitTime && (this.syncUnitTime = t.toolsOpt.syncUnitTime);
215
+ }
216
+ getToolsOpt() {
217
+ return this.tmpOpt;
218
+ }
219
+ createWorkShapeNode(t) {
220
+ const { toolsType: e } = t;
221
+ if (e === f.LaserPen)
222
+ return B({ ...t, vNodes: this.vNodes, fullLayer: this.thread.topLayer, drawLayer: this.thread.topLayer });
223
+ }
224
+ setNodeKey(t, e, s, o) {
225
+ return e.toolsType = s, e.node = this.createWorkShapeNode({ workId: t, toolsType: s, toolsOpt: o }), e;
226
+ }
227
+ activeServiceWorkShape(t) {
228
+ var S, u;
229
+ const { workId: e, opt: s, toolsType: o, type: r, updateNodeOpt: i, ops: n, op: c } = t;
230
+ if (!e)
231
+ return;
232
+ const a = e.toString(), h = (S = this.vNodes.get(a)) == null ? void 0 : S.rect;
233
+ if (!((u = this.serviceWorkShapes) != null && u.has(a))) {
234
+ let y = {
235
+ toolsType: o,
236
+ animationWorkData: c || [],
237
+ animationIndex: 0,
238
+ type: r,
239
+ updateNodeOpt: i,
240
+ ops: n,
241
+ oldRect: h
242
+ };
243
+ o && s && (y = this.setNodeKey(a, y, o, s)), this.serviceWorkShapes.set(a, y);
244
+ }
245
+ const l = this.serviceWorkShapes.get(a);
246
+ r && (l.type = r), n && (l.animationWorkData = P(n), l.ops = n), i && (l.updateNodeOpt = i), c && (l.animationWorkData = c), l.node && l.node.getWorkId() !== a && l.node.setWorkId(a), h && (l.oldRect = h), o && s && (l.toolsType !== o && o && s && this.setNodeKey(a, l, o, s), l.node && l.node.setWorkOptions(s));
247
+ }
248
+ computNextAnimationIndex(t, e) {
249
+ var r;
250
+ const s = ((r = t.node) == null ? void 0 : r.syncUnitTime) || this.syncUnitTime, o = Math.floor((t.animationWorkData || []).slice(t.animationIndex).length * 32 / e / s) * e;
251
+ return Math.min((t.animationIndex || 0) + (o || e), (t.animationWorkData || []).length);
252
+ }
253
+ animationDraw() {
254
+ var o, r, i, n;
255
+ this.animationId = void 0;
256
+ let t = !1;
257
+ const e = /* @__PURE__ */ new Map(), s = [];
258
+ for (const [c, a] of this.serviceWorkShapes.entries())
259
+ switch (a.toolsType) {
260
+ case f.LaserPen: {
261
+ const l = this.computNextAnimationIndex(a, 8), S = Math.max(0, a.animationIndex || 0), u = (a.animationWorkData || []).slice(S, l);
262
+ if ((a.animationIndex || 0) < l && ((o = a.node) == null || o.consumeService({
263
+ op: u,
264
+ isFullWork: !1
265
+ }), a.animationIndex = l, u.length && e.set(c, {
266
+ workState: S === 0 ? T.Start : l === ((r = a.animationWorkData) == null ? void 0 : r.length) ? T.Done : T.Doing,
267
+ op: u.slice(-2)
268
+ })), a.isDel) {
269
+ (i = a.node) == null || i.clearTmpPoints(), this.serviceWorkShapes.delete(c);
270
+ break;
271
+ }
272
+ a.ops && a.animationIndex === ((n = a.animationWorkData) == null ? void 0 : n.length) && !a.isDel && (this.thread.topLayer.getElementsByName(c.toString())[0] || (a.isDel = !0, this.serviceWorkShapes.set(c, a))), t = !0;
273
+ break;
274
+ }
275
+ }
276
+ for (const [c, a] of this.localWorkShapes.entries()) {
277
+ const { result: h, toolsType: l, isDel: S, workState: u } = a;
278
+ switch (l) {
279
+ case f.LaserPen: {
280
+ if (S) {
281
+ a.node.clearTmpPoints(), this.localWorkShapes.delete(c), s.push({
282
+ removeIds: [c.toString()],
283
+ type: p.RemoveNode
284
+ });
285
+ break;
286
+ }
287
+ h && ((h.op || h.ops) && s.push(h), a.result = void 0), !this.thread.topLayer.getElementsByName(c.toString())[0] && u === T.Done && (a.isDel = !0, this.localWorkShapes.set(c, a)), t = !0;
288
+ break;
289
+ }
290
+ }
291
+ }
292
+ t && this.runAnimation(), e.size && e.forEach((c, a) => {
293
+ s.push({
294
+ type: p.Cursor,
295
+ uid: a.split(Y)[0],
296
+ op: c.op,
297
+ workState: c.workState,
298
+ viewId: this.thread.viewId
299
+ });
300
+ }), s.length && this.thread.post({ sp: s });
301
+ }
302
+ runAnimation() {
303
+ this.animationId || (this.animationId = requestAnimationFrame(this.animationDraw.bind(this)));
304
+ }
305
+ setWorkOptions(t, e) {
306
+ var o;
307
+ let s = (o = this.localWorkShapes.get(t)) == null ? void 0 : o.node;
308
+ if (!s && this.tmpOpt) {
309
+ const { toolsType: r } = this.tmpOpt;
310
+ this.tmpOpt.toolsOpt = e, s = this.createWorkShapeNode({ workId: t, toolsType: r, toolsOpt: e }), s && this.localWorkShapes.set(t, {
311
+ node: s,
312
+ toolsType: r,
313
+ workState: T.Start
314
+ }), this.setToolsOpt(this.tmpOpt);
315
+ }
316
+ e != null && e.syncUnitTime || (e.syncUnitTime = this.syncUnitTime), s && s.setWorkOptions(e);
317
+ }
318
+ consumeDrawAll(t) {
319
+ const { workId: e, dataType: s } = t;
320
+ if (s === w.Service)
321
+ this.activeServiceWorkShape(t);
322
+ else {
323
+ const o = e == null ? void 0 : e.toString(), r = o && this.localWorkShapes.get(o);
324
+ if (!r)
325
+ return;
326
+ const i = r.node.consumeAll({ data: t });
327
+ r.result = i, r.workState = T.Done, o && this.localWorkShapes.set(o, r);
328
+ }
329
+ this.runAnimation();
330
+ }
331
+ }
332
+ class ke {
333
+ constructor(t) {
334
+ d(this, "vNodes");
335
+ d(this, "thread");
336
+ d(this, "workShapes", /* @__PURE__ */ new Map());
337
+ d(this, "effectSelectNodeData", /* @__PURE__ */ new Set());
338
+ d(this, "batchEraserRemoveNodes", /* @__PURE__ */ new Set());
339
+ d(this, "batchEraserWorks", /* @__PURE__ */ new Set());
340
+ d(this, "tmpOpt");
341
+ d(this, "syncUnitTime", F.syncOpt.interval);
342
+ d(this, "drawCount", 0);
343
+ d(this, "drawWorkActiveId");
344
+ d(this, "batchEraserCombine", le(() => {
345
+ this.updateBatchEraserCombineNode(this.batchEraserWorks, this.batchEraserRemoveNodes), this.batchEraserWorks.clear(), this.batchEraserRemoveNodes.clear();
346
+ }, 100, { leading: !1 }));
347
+ this.vNodes = t.vNodes, this.thread = t.thread;
348
+ }
349
+ createLocalWork(t) {
350
+ const { workId: e, opt: s, toolsType: o } = t;
351
+ if (e && s) {
352
+ const r = e.toString();
353
+ !this.getToolsOpt() && o && this.setToolsOpt({
354
+ toolsType: o,
355
+ toolsOpt: s
356
+ }), this.setWorkOptions(r, s);
357
+ }
358
+ }
359
+ workShapesDone(t, e) {
360
+ for (const s of this.workShapes.keys())
361
+ this.consumeDrawAll({
362
+ workId: s,
363
+ scenePath: t,
364
+ viewId: this.thread.viewId,
365
+ msgType: p.DrawWork,
366
+ dataType: w.Local
367
+ }, e);
368
+ }
369
+ async updateSelector(t) {
370
+ var u;
371
+ const e = this.workShapes.get(N);
372
+ if (!((u = e == null ? void 0 : e.selectIds) != null && u.length)) return;
373
+ const { callback: s, ...o } = t, { updateSelectorOpt: r, willSerializeData: i, scene: n } = o, c = await (e == null ? void 0 : e.updateSelector({
374
+ updateSelectorOpt: r,
375
+ selectIds: ee(e.selectIds),
376
+ vNodes: this.vNodes,
377
+ willSerializeData: i,
378
+ worker: this,
379
+ scene: n,
380
+ isMainThread: !0
381
+ })), a = /* @__PURE__ */ new Map();
382
+ let h;
383
+ c != null && c.selectIds && (h = de(e.selectIds, c.selectIds), c.selectIds.forEach((y) => {
384
+ const m = this.vNodes.get(y);
385
+ if (m) {
386
+ const { toolsType: g, op: W, opt: M } = m;
387
+ a.set(y, {
388
+ opt: M,
389
+ toolsType: g,
390
+ ops: (W == null ? void 0 : W.length) && V(W) || void 0
391
+ });
392
+ }
393
+ }), e.selectIds = c.selectIds);
394
+ const l = [], S = s && s({
395
+ res: c,
396
+ workShapeNode: e,
397
+ param: o,
398
+ postData: { sp: l },
399
+ newServiceStore: a
400
+ }) || { sp: l };
401
+ h && S.sp.push({
402
+ type: p.RemoveNode,
403
+ removeIds: h,
404
+ viewId: this.thread.viewId
405
+ }), S.sp.length && this.thread.post(S);
406
+ }
407
+ destroy() {
408
+ this.clearAll();
409
+ }
410
+ clearAll() {
411
+ if (this.thread.localLayer.children.length && (this.thread.topLayer.parent.children.forEach((e) => {
412
+ e.name !== "viewport" && e.remove();
413
+ }), this.thread.localLayer.removeAllChildren()), this.workShapes.get(N)) {
414
+ const e = [];
415
+ e.push({
416
+ type: p.Select,
417
+ dataType: w.Local,
418
+ selectIds: [],
419
+ willSyncService: !1
420
+ }), this.thread.post({ sp: e });
421
+ }
422
+ this.workShapes.clear(), this.effectSelectNodeData.clear(), this.batchEraserWorks.clear(), this.batchEraserRemoveNodes.clear();
423
+ }
424
+ async checkTextActive(t) {
425
+ const { op: e, viewId: s, dataType: o } = t;
426
+ if (e != null && e.length) {
427
+ let r;
428
+ for (const i of this.vNodes.curNodeMap.values()) {
429
+ const { rect: n, name: c, toolsType: a, opt: h } = i, l = e[0] * this.thread.fullLayer.worldScaling[0] + this.thread.fullLayer.worldPosition[0], S = e[1] * this.thread.fullLayer.worldScaling[1] + this.thread.fullLayer.worldPosition[1];
430
+ if (a === f.Text && ce([l, S], n) && h.workState === T.Done) {
431
+ r = c;
432
+ break;
433
+ }
434
+ }
435
+ r && (await this.blurSelector({
436
+ viewId: s,
437
+ msgType: p.Select,
438
+ dataType: o,
439
+ isSync: !0
440
+ }), this.thread.post({
441
+ sp: [{
442
+ type: p.GetTextActive,
443
+ toolsType: f.Text,
444
+ workId: r
445
+ }]
446
+ }));
447
+ }
448
+ }
449
+ cursorHover(t) {
450
+ const { opt: e, toolsType: s, point: o } = t, r = this.setFullWork({
451
+ workId: H,
452
+ toolsType: s,
453
+ opt: e
454
+ });
455
+ r && o && r.cursorHover(o);
456
+ }
457
+ updateFullSelectWork(t) {
458
+ var o, r, i, n, c;
459
+ const e = this.workShapes.get(N), { selectIds: s } = t;
460
+ if (!(s != null && s.length)) {
461
+ this.blurSelector(t);
462
+ return;
463
+ }
464
+ if (!e) {
465
+ const a = this.setFullWork(t);
466
+ !a && t.workId && this.tmpOpt && ((o = this.tmpOpt) == null ? void 0 : o.toolsType) === f.Selector && this.setWorkOptions(t.workId.toString(), t.opt || this.tmpOpt.toolsOpt), a && this.updateFullSelectWork(t);
467
+ return;
468
+ }
469
+ if (e && (s != null && s.length)) {
470
+ const { selectRect: a } = e.updateSelectIds(s), h = [{
471
+ ...t,
472
+ selectorColor: ((r = t.opt) == null ? void 0 : r.strokeColor) || e.selectorColor,
473
+ strokeColor: ((i = t.opt) == null ? void 0 : i.strokeColor) || e.strokeColor,
474
+ fillColor: ((n = t.opt) == null ? void 0 : n.fillColor) || e.fillColor,
475
+ textOpt: ((c = t.opt) == null ? void 0 : c.textOpt) || e.textOpt,
476
+ canTextEdit: e.canTextEdit,
477
+ canRotate: e.canRotate,
478
+ scaleType: e.scaleType,
479
+ type: p.Select,
480
+ selectRect: a,
481
+ points: e.getChildrenPoints(),
482
+ willSyncService: (t == null ? void 0 : t.willSyncService) || !1,
483
+ opt: (t == null ? void 0 : t.willSyncService) && e.getWorkOptions() || void 0,
484
+ canLock: e.canLock,
485
+ isLocked: e.isLocked,
486
+ toolsTypes: e.toolsTypes,
487
+ shapeOpt: e.shapeOpt,
488
+ thickness: e.thickness,
489
+ useStroke: e.useStroke,
490
+ strokeType: e.strokeType
491
+ }];
492
+ this.thread.post({ sp: h });
493
+ }
494
+ }
495
+ commandDeleteText(t) {
496
+ const e = this.vNodes.get(t);
497
+ if (e && e.toolsType === f.Text)
498
+ return {
499
+ type: p.TextUpdate,
500
+ toolsType: f.Text,
501
+ workId: t,
502
+ dataType: w.Local
503
+ };
504
+ }
505
+ async removeSelector(t) {
506
+ const { willSyncService: e } = t, s = [], o = [], r = this.workShapes.get(N);
507
+ if (!r)
508
+ return;
509
+ const i = r.selectIds && [...r.selectIds] || [];
510
+ for (const n of i) {
511
+ if (this.vNodes.get(n)) {
512
+ const a = this.commandDeleteText(n);
513
+ a && s.push(a);
514
+ }
515
+ this.removeNode(n), o.push(n);
516
+ }
517
+ o.length && s.push({
518
+ type: p.RemoveNode,
519
+ removeIds: o
520
+ }), s.push({
521
+ type: p.Select,
522
+ selectIds: [],
523
+ willSyncService: e
524
+ }), await this.blurSelector(), s.length && this.thread.post({ sp: s });
525
+ }
526
+ removeWork(t) {
527
+ const { workId: e } = t, s = e == null ? void 0 : e.toString();
528
+ s && this.removeNode(s);
529
+ }
530
+ removeNode(t) {
531
+ var o;
532
+ this.vNodes.get(t) && ((o = this.thread.fullLayer) == null || o.getElementsByName(t).forEach((r) => {
533
+ r.remove();
534
+ }), this.vNodes.delete(t)), this.workShapes.has(t) && (this.thread.localLayer.getElementsByName(t).forEach((r) => {
535
+ r.remove();
536
+ }), this.clearWorkShapeNodeCache(t));
537
+ }
538
+ setFullWork(t) {
539
+ const { workId: e, opt: s, toolsType: o } = t;
540
+ if (e && s && o) {
541
+ const r = e.toString();
542
+ let i;
543
+ return e && this.workShapes.has(r) ? (i = this.workShapes.get(r), i == null || i.setWorkOptions(s)) : i = this.createWorkShapeNode({
544
+ toolsOpt: s,
545
+ toolsType: o,
546
+ workId: r
547
+ }), i ? (this.workShapes.set(r, i), i) : void 0;
548
+ }
549
+ }
550
+ async consumeFull(t, e) {
551
+ var r;
552
+ const s = this.setFullWork(t), o = t.ops && P(t.ops);
553
+ if (s) {
554
+ const i = (r = t.workId) == null ? void 0 : r.toString();
555
+ s.toolsType === f.Image && e ? await s.consumeServiceAsync({
556
+ scene: e,
557
+ isFullWork: !0,
558
+ replaceId: i,
559
+ isMainThread: !0
560
+ }) : s.toolsType === f.Text ? await s.consumeServiceAsync({
561
+ isFullWork: !0,
562
+ replaceId: i
563
+ }) : s.consumeService({
564
+ op: o,
565
+ isFullWork: !0,
566
+ replaceId: i
567
+ }), t != null && t.updateNodeOpt && s.updataOptService(t.updateNodeOpt);
568
+ const n = [];
569
+ t.workId && this.workShapes.delete(t.workId.toString()), t.willSyncService && n.push({
570
+ opt: t.opt,
571
+ toolsType: t.toolsType,
572
+ type: p.FullWork,
573
+ workId: t.workId,
574
+ ops: t.ops,
575
+ updateNodeOpt: t.updateNodeOpt,
576
+ viewId: this.thread.viewId
577
+ }), n.length && this.thread.post({ sp: n });
578
+ }
579
+ }
580
+ async colloctEffectSelectWork(t) {
581
+ const e = this.workShapes.get(N), { workId: s, msgType: o } = t;
582
+ if (e && s && e.selectIds && e.selectIds.includes(s.toString())) {
583
+ o === p.RemoveNode ? e.selectIds = e.selectIds.filter((r) => r !== s.toString()) : this.effectSelectNodeData.add(t), await new Promise((r) => {
584
+ setTimeout(() => {
585
+ r(!0);
586
+ }, 0);
587
+ }), await this.runEffectSelectWork(!0).then(() => {
588
+ var r;
589
+ (r = this.effectSelectNodeData) == null || r.clear();
590
+ });
591
+ return;
592
+ }
593
+ return t;
594
+ }
595
+ async runEffectSelectWork(t) {
596
+ var e, s, o;
597
+ for (const r of this.effectSelectNodeData.values()) {
598
+ const i = this.setFullWork(r);
599
+ if (i) {
600
+ const n = (e = r.workId) == null ? void 0 : e.toString();
601
+ if (i.toolsType === f.Image)
602
+ await i.consumeServiceAsync({
603
+ scene: (o = (s = this.thread.localLayer) == null ? void 0 : s.parent) == null ? void 0 : o.parent,
604
+ isFullWork: !0,
605
+ replaceId: n,
606
+ isMainThread: !0
607
+ });
608
+ else if (i.toolsType === f.Text)
609
+ await i.consumeServiceAsync({
610
+ isFullWork: !0,
611
+ replaceId: n
612
+ });
613
+ else {
614
+ const c = r.ops && P(r.ops);
615
+ i.consumeService({
616
+ op: c,
617
+ isFullWork: !0,
618
+ replaceId: n
619
+ }), r != null && r.updateNodeOpt && i.updataOptService(r.updateNodeOpt);
620
+ }
621
+ r.workId && this.workShapes.delete(r.workId.toString());
622
+ }
623
+ }
624
+ this.reRenderSelector(t);
625
+ }
626
+ hasSelector() {
627
+ return this.workShapes.has(N);
628
+ }
629
+ getSelector() {
630
+ return this.workShapes.get(N);
631
+ }
632
+ reRenderSelector(t = !1) {
633
+ var o;
634
+ const e = this.workShapes.get(N);
635
+ if (!e) return;
636
+ if (e && !((o = e.selectIds) != null && o.length))
637
+ return this.blurSelector();
638
+ const s = e.reRenderSelector();
639
+ s && this.thread.post({
640
+ sp: [{
641
+ type: p.Select,
642
+ selectIds: e.selectIds,
643
+ selectRect: s,
644
+ willSyncService: t,
645
+ viewId: this.thread.viewId,
646
+ points: e.getChildrenPoints(),
647
+ textOpt: e.textOpt,
648
+ selectorColor: e.selectorColor,
649
+ strokeColor: e.strokeColor,
650
+ fillColor: e.fillColor,
651
+ canTextEdit: e.canTextEdit,
652
+ canRotate: e.canRotate,
653
+ scaleType: e.scaleType,
654
+ opt: e.getWorkOptions() || void 0,
655
+ canLock: e.canLock,
656
+ isLocked: e.isLocked,
657
+ toolsTypes: e.toolsTypes,
658
+ shapeOpt: e.shapeOpt,
659
+ thickness: e.thickness,
660
+ useStroke: e.useStroke,
661
+ strokeType: e.strokeType
662
+ }]
663
+ });
664
+ }
665
+ async blurSelector(t) {
666
+ var o;
667
+ const e = this.workShapes.get(N), s = e == null ? void 0 : e.blurSelector();
668
+ if (this.clearWorkShapeNodeCache(N), ((o = this.thread.fullLayer) == null ? void 0 : o.parent).children.forEach((r) => {
669
+ r.name === N && r.remove();
670
+ }), s) {
671
+ const r = [];
672
+ r.push({
673
+ ...s,
674
+ isSync: t == null ? void 0 : t.isSync
675
+ }), this.thread.post({ sp: r });
676
+ }
677
+ }
678
+ clearWorkShapeNodeCache(t) {
679
+ var e;
680
+ (e = this.getWorkShape(t)) == null || e.clearTmpPoints(), this.workShapes.delete(t);
681
+ }
682
+ drawPencilEraser(t) {
683
+ var s, o;
684
+ const e = [];
685
+ if ((s = t.newWorkDatas) != null && s.size) {
686
+ for (const r of t.newWorkDatas.values()) {
687
+ const i = r.workId.toString();
688
+ this.batchEraserWorks.add(i), e.push({
689
+ type: p.FullWork,
690
+ workId: i,
691
+ ops: V(r.op),
692
+ opt: r.opt,
693
+ toolsType: r.toolsType,
694
+ updateNodeOpt: {
695
+ useAnimation: !1
696
+ }
697
+ });
698
+ }
699
+ delete t.newWorkDatas;
700
+ }
701
+ (o = t.removeIds) == null || o.forEach((r) => {
702
+ this.batchEraserRemoveNodes.add(r);
703
+ }), e.push(t), this.thread.post({ sp: e }), this.batchEraserCombine();
704
+ }
705
+ drawEraser(t) {
706
+ const e = [];
707
+ t.removeIds && e.push(t), this.thread.post({ sp: e });
708
+ }
709
+ updateBatchEraserCombineNode(t, e) {
710
+ for (const s of e.keys())
711
+ this.thread.fullLayer.getElementsByName(s).forEach((o) => {
712
+ o.remove();
713
+ });
714
+ t.forEach((s) => {
715
+ const o = this.vNodes.get(s);
716
+ if (o && o.toolsType === f.Pencil && !this.thread.fullLayer.getElementsByName(s)[0]) {
717
+ const i = this.setFullWork({ ...o, workId: s });
718
+ i && i.consumeService({
719
+ op: o.op,
720
+ isFullWork: !0
721
+ });
722
+ }
723
+ });
724
+ }
725
+ getWorkShape(t) {
726
+ return this.workShapes.get(t);
727
+ }
728
+ getWorkShapes() {
729
+ return this.workShapes;
730
+ }
731
+ consumeDraw(t, e) {
732
+ const { op: s, workId: o, scenePath: r } = t;
733
+ if (s != null && s.length && o) {
734
+ const i = o.toString(), n = this.workShapes.get(i);
735
+ if (!n)
736
+ return;
737
+ const c = n.toolsType;
738
+ if (c === f.LaserPen)
739
+ return;
740
+ switch (this.drawWorkActiveId && this.drawWorkActiveId !== i && (this.consumeDrawAll({
741
+ workId: this.drawWorkActiveId,
742
+ scenePath: r,
743
+ viewId: this.thread.viewId,
744
+ msgType: p.DrawWork,
745
+ dataType: w.Local
746
+ }, e), this.drawWorkActiveId = void 0), !this.drawWorkActiveId && i !== N && (this.drawWorkActiveId = i), c) {
747
+ case f.Selector:
748
+ {
749
+ const a = n.consume({
750
+ data: t,
751
+ isFullWork: !0
752
+ });
753
+ a.type === p.Select && (a.selectIds && e.runReverseSelectWork(a.selectIds), this.thread.post({ sp: [a] }));
754
+ }
755
+ break;
756
+ case f.PencilEraser:
757
+ {
758
+ const a = n.consume({
759
+ data: t,
760
+ isFullWork: !0
761
+ });
762
+ a != null && a.rect && this.drawPencilEraser(a);
763
+ }
764
+ break;
765
+ case f.Eraser:
766
+ {
767
+ const a = n.consume({
768
+ data: t,
769
+ isFullWork: !0
770
+ });
771
+ a != null && a.rect && this.drawEraser(a);
772
+ }
773
+ break;
774
+ case f.Arrow:
775
+ case f.Straight:
776
+ case f.Ellipse:
777
+ case f.Rectangle:
778
+ case f.Star:
779
+ case f.Polygon:
780
+ case f.SpeechBalloon:
781
+ case f.Pencil:
782
+ {
783
+ const a = n.consume({
784
+ data: t,
785
+ isFullWork: !1,
786
+ isMainThread: !0
787
+ });
788
+ a && (this.drawCount++, this.thread.post({
789
+ drawCount: this.drawCount,
790
+ sp: a.op && [{ ...a, scenePath: r }] || void 0
791
+ }));
792
+ }
793
+ break;
794
+ }
795
+ }
796
+ }
797
+ consumeDrawAll(t, e) {
798
+ var r, i, n;
799
+ const { workId: s, scenePath: o } = t;
800
+ if (s) {
801
+ const c = s.toString();
802
+ this.drawWorkActiveId === c && (this.drawWorkActiveId = void 0);
803
+ const a = this.workShapes.get(c);
804
+ if (!a)
805
+ return;
806
+ const h = a.toolsType;
807
+ if (h === f.LaserPen)
808
+ return;
809
+ const l = this.workShapes.get(H), S = (r = l == null ? void 0 : l.selectIds) == null ? void 0 : r[0], u = a.consumeAll({ data: t });
810
+ switch (h) {
811
+ case f.Selector:
812
+ u.selectIds && S && ((i = u.selectIds) != null && i.includes(S)) && l.cursorBlur(), u.type === p.Select && (u.selectIds && e.runReverseSelectWork(u.selectIds), this.thread.post({ sp: [{ ...u, scenePath: o }] })), (n = a.selectIds) != null && n.length ? a.clearTmpPoints() : this.clearWorkShapeNodeCache(c);
813
+ break;
814
+ case f.PencilEraser:
815
+ u != null && u.rect && this.drawPencilEraser({ ...u, scenePath: o }), a.clearTmpPoints();
816
+ break;
817
+ case f.Eraser:
818
+ u != null && u.rect && this.drawEraser({ ...u, scenePath: o }), a.clearTmpPoints();
819
+ break;
820
+ case f.Arrow:
821
+ case f.Straight:
822
+ case f.Ellipse:
823
+ case f.Rectangle:
824
+ case f.Star:
825
+ case f.Polygon:
826
+ case f.SpeechBalloon:
827
+ case f.Pencil:
828
+ u && (this.drawCount = 0, this.thread.post({
829
+ drawCount: this.drawCount,
830
+ sp: [u]
831
+ })), this.clearWorkShapeNodeCache(c);
832
+ break;
833
+ }
834
+ }
835
+ }
836
+ getToolsOpt() {
837
+ return this.tmpOpt;
838
+ }
839
+ setToolsOpt(t) {
840
+ var e;
841
+ this.tmpOpt = t, (e = t.toolsOpt) != null && e.syncUnitTime && (this.syncUnitTime = t.toolsOpt.syncUnitTime);
842
+ }
843
+ setWorkOptions(t, e) {
844
+ let s = this.workShapes.get(t);
845
+ if (!s && this.tmpOpt) {
846
+ const { toolsType: o } = this.tmpOpt;
847
+ this.tmpOpt.toolsOpt = e, s = this.createWorkShapeNode({ workId: t, toolsType: o, toolsOpt: e }), s && this.workShapes.set(t, s), this.setToolsOpt(this.tmpOpt);
848
+ }
849
+ e.syncUnitTime || (e.syncUnitTime = this.syncUnitTime), s == null || s.setWorkOptions(e);
850
+ }
851
+ createWorkShapeNode(t) {
852
+ return B({ ...t, vNodes: this.vNodes, fullLayer: this.thread.fullLayer, drawLayer: this.thread.localLayer }, this.thread.serviceWork);
853
+ }
854
+ }
855
+ class ye {
856
+ constructor(t) {
857
+ d(this, "vNodes");
858
+ d(this, "thread");
859
+ d(this, "workShapes", /* @__PURE__ */ new Map());
860
+ d(this, "selectorWorkShapes", /* @__PURE__ */ new Map());
861
+ d(this, "willRunEffectSelectorIds", /* @__PURE__ */ new Set());
862
+ d(this, "runEffectId");
863
+ d(this, "animationId");
864
+ d(this, "syncUnitTime", F.syncOpt.interval);
865
+ this.vNodes = t.vNodes, this.thread = t.thread;
866
+ }
867
+ destroy() {
868
+ this.clearAll();
869
+ }
870
+ clearAll() {
871
+ this.thread.serviceLayer.children.length && (this.thread.serviceLayer.parent.children.forEach((t) => {
872
+ t.name !== "viewport" && t.remove();
873
+ }), this.thread.serviceLayer.removeAllChildren()), this.workShapes.clear(), this.selectorWorkShapes.clear(), this.willRunEffectSelectorIds.clear();
874
+ }
875
+ runEffect() {
876
+ this.runEffectId || (this.runEffectId = setTimeout(this.effectRunSelector.bind(this), 0));
877
+ }
878
+ effectRunSelector() {
879
+ this.runEffectId = void 0, this.willRunEffectSelectorIds.forEach((t) => {
880
+ var s, o;
881
+ const e = this.selectorWorkShapes.get(t);
882
+ e && e.selectIds && ((s = e.node) == null || s.selectServiceNode(t, e, !0)), (o = e == null ? void 0 : e.selectIds) != null && o.length || this.selectorWorkShapes.delete(t);
883
+ }), this.willRunEffectSelectorIds.clear();
884
+ }
885
+ runSelectWork(t) {
886
+ this.activeSelectorShape(t);
887
+ const { workId: e } = t, s = e == null ? void 0 : e.toString();
888
+ s && this.willRunEffectSelectorIds.add(s), this.runEffect();
889
+ }
890
+ removeWork(t) {
891
+ const { workId: e } = t, s = e == null ? void 0 : e.toString();
892
+ if (s) {
893
+ if (this.workShapes.get(s)) {
894
+ this.workShapes.delete(s), this.removeNode(s, t);
895
+ return;
896
+ }
897
+ this.removeNode(s, t);
898
+ }
899
+ }
900
+ consumeFull(t) {
901
+ this.activeWorkShape(t), this.runAnimation();
902
+ }
903
+ runReverseSelectWork(t) {
904
+ t.forEach((e) => {
905
+ this.selectorWorkShapes.forEach((s, o) => {
906
+ var r;
907
+ if ((r = s.selectIds) != null && r.length) {
908
+ const i = s.selectIds.indexOf(e);
909
+ i > -1 && (s.selectIds.splice(i, 1), this.willRunEffectSelectorIds.add(o));
910
+ }
911
+ });
912
+ }), this.willRunEffectSelectorIds.size && this.runEffect();
913
+ }
914
+ consumeDraw(t) {
915
+ this.activeWorkShape(t), this.runAnimation();
916
+ }
917
+ computNextAnimationIndex(t, e) {
918
+ const s = Math.floor((t.animationWorkData || []).slice(t.animationIndex).length * 32 / e / this.syncUnitTime) * e;
919
+ return Math.min((t.animationIndex || 0) + (s || e), (t.animationWorkData || []).length);
920
+ }
921
+ async animationDraw() {
922
+ var s, o, r, i, n, c, a, h, l, S, u, y, m, g, W, M;
923
+ this.animationId = void 0;
924
+ let t = !1;
925
+ const e = /* @__PURE__ */ new Map();
926
+ for (const [L, k] of this.workShapes.entries())
927
+ switch (k.toolsType) {
928
+ case f.Image: {
929
+ await ((o = k.node) == null ? void 0 : o.consumeServiceAsync({
930
+ isFullWork: !0,
931
+ scene: (s = this.thread.fullLayer.parent) == null ? void 0 : s.parent,
932
+ isMainThread: !0
933
+ })), this.selectorWorkShapes.forEach((b, D) => {
934
+ var O;
935
+ (O = b.selectIds) != null && O.includes(L) && (this.willRunEffectSelectorIds.add(D), this.runEffect());
936
+ }), this.workShapes.delete(L);
937
+ break;
938
+ }
939
+ case f.Text: {
940
+ k.node && (await ((r = k.node) == null ? void 0 : r.consumeServiceAsync({
941
+ isFullWork: !0,
942
+ replaceId: L
943
+ })), this.selectorWorkShapes.forEach((b, D) => {
944
+ var O;
945
+ (O = b.selectIds) != null && O.includes(L) && (this.willRunEffectSelectorIds.add(D), this.runEffect());
946
+ }), (i = k.node) == null || i.clearTmpPoints(), this.workShapes.delete(L));
947
+ break;
948
+ }
949
+ case f.Arrow:
950
+ case f.Straight:
951
+ case f.Rectangle:
952
+ case f.Ellipse:
953
+ case f.Star:
954
+ case f.Polygon:
955
+ case f.SpeechBalloon: {
956
+ const b = !!k.ops;
957
+ if ((n = k.animationWorkData) != null && n.length) {
958
+ const D = k.oldRect;
959
+ (c = k.node) == null || c.consumeService({
960
+ op: k.animationWorkData,
961
+ isFullWork: b
962
+ }), b && (this.selectorWorkShapes.forEach((O, R) => {
963
+ var U;
964
+ (U = O.selectIds) != null && U.includes(L) && (this.willRunEffectSelectorIds.add(R), this.runEffect());
965
+ }), (a = k.node) == null || a.clearTmpPoints(), this.workShapes.delete(L)), e.set(L, {
966
+ workState: D ? k.ops ? T.Done : T.Doing : T.Start,
967
+ op: k.animationWorkData.filter((O, R) => {
968
+ if (R % 3 !== 2)
969
+ return !0;
970
+ }).slice(-2)
971
+ }), k.animationWorkData.length = 0;
972
+ }
973
+ break;
974
+ }
975
+ case f.Pencil: {
976
+ if (!k.useAnimation && k.ops)
977
+ (h = k.node) == null || h.consumeService({
978
+ op: k.animationWorkData || [],
979
+ isFullWork: !0,
980
+ replaceId: L
981
+ }), (l = k.node) == null || l.updataOptService(k.updateNodeOpt), this.selectorWorkShapes.forEach((b, D) => {
982
+ var O;
983
+ (O = b.selectIds) != null && O.includes(L) && (this.willRunEffectSelectorIds.add(D), this.runEffect());
984
+ }), (S = k.node) == null || S.clearTmpPoints(), this.workShapes.delete(L);
985
+ else if (k.useAnimation) {
986
+ if (k.isDel) {
987
+ (u = k.node) == null || u.clearTmpPoints(), this.workShapes.delete(L);
988
+ break;
989
+ }
990
+ const b = 3, D = this.computNextAnimationIndex(k, b), O = k.isDiff ? 0 : Math.max(0, (k.animationIndex || 0) - b), R = (k.animationWorkData || []).slice(O, D), U = (m = (y = k.node) == null ? void 0 : y.getWorkId()) == null ? void 0 : m.toString();
991
+ if ((k.animationIndex || 0) < D || k.isDiff) {
992
+ if ((g = k.node) == null || g.consumeService({
993
+ op: R,
994
+ isFullWork: !1
995
+ }), k.animationIndex = D, k.isDiff && (k.isDiff = !1), R.length) {
996
+ const q = R.filter((K, te) => {
997
+ if (te % b !== b - 1)
998
+ return !0;
999
+ }).slice(-2);
1000
+ e.set(L, {
1001
+ workState: O === 0 ? T.Start : D === ((W = k.animationWorkData) == null ? void 0 : W.length) ? T.Done : T.Doing,
1002
+ op: q
1003
+ });
1004
+ }
1005
+ } else k.ops && ((M = k.node) == null || M.consumeService({
1006
+ op: k.animationWorkData || [],
1007
+ isFullWork: !0,
1008
+ replaceId: U
1009
+ }), k.isDel = !0, e.set(L, {
1010
+ workState: T.Done,
1011
+ op: R.filter((q, K) => {
1012
+ if (K % b !== b - 1)
1013
+ return !0;
1014
+ }).slice(-2)
1015
+ }));
1016
+ t = !0;
1017
+ break;
1018
+ }
1019
+ break;
1020
+ }
1021
+ }
1022
+ if (t && this.runAnimation(), e.size) {
1023
+ const L = [];
1024
+ e.forEach((k, b) => {
1025
+ L.push({
1026
+ type: p.Cursor,
1027
+ uid: b.split(Y)[0],
1028
+ op: k.op,
1029
+ workState: k.workState,
1030
+ viewId: this.thread.viewId
1031
+ });
1032
+ }), this.thread.post({ sp: L });
1033
+ }
1034
+ }
1035
+ runAnimation() {
1036
+ this.animationId || (this.animationId = requestAnimationFrame(this.animationDraw.bind(this)));
1037
+ }
1038
+ hasDiffData(t, e, s) {
1039
+ const o = t.length;
1040
+ if (e.length < o)
1041
+ return !0;
1042
+ switch (s) {
1043
+ case f.Pencil: {
1044
+ for (let r = 0; r < o; r += 3)
1045
+ if (e[r] !== t[r] || e[r + 1] !== t[r + 1])
1046
+ return !0;
1047
+ break;
1048
+ }
1049
+ case f.LaserPen: {
1050
+ for (let r = 0; r < o; r += 2)
1051
+ if (e[r] !== t[r] || e[r + 1] !== t[r + 1])
1052
+ return !0;
1053
+ break;
1054
+ }
1055
+ }
1056
+ return !1;
1057
+ }
1058
+ activeWorkShape(t) {
1059
+ var u, y, m, g;
1060
+ const { workId: e, opt: s, toolsType: o, type: r, updateNodeOpt: i, ops: n, op: c, useAnimation: a } = t;
1061
+ if (!e)
1062
+ return;
1063
+ const h = e.toString(), l = (u = this.vNodes.get(h)) == null ? void 0 : u.rect;
1064
+ if (!((y = this.workShapes) != null && y.has(h))) {
1065
+ let W = {
1066
+ toolsType: o,
1067
+ animationWorkData: c || [],
1068
+ animationIndex: 0,
1069
+ type: r,
1070
+ updateNodeOpt: i,
1071
+ ops: n,
1072
+ useAnimation: typeof a < "u" ? a : typeof (i == null ? void 0 : i.useAnimation) < "u" ? i == null ? void 0 : i.useAnimation : !0,
1073
+ oldRect: l,
1074
+ isDiff: !1
1075
+ };
1076
+ o && s && (W = this.setNodeKey(h, W, o, s)), (m = this.workShapes) == null || m.set(h, W);
1077
+ }
1078
+ const S = (g = this.workShapes) == null ? void 0 : g.get(h);
1079
+ r && (S.type = r), n && (S.animationWorkData = P(n), S.ops = n), i && (S.updateNodeOpt = i), c && (S.isDiff = this.hasDiffData(S.animationWorkData || [], c, S.toolsType), S.animationWorkData = c), S.node && S.node.getWorkId() !== h && S.node.setWorkId(h), l && (S.oldRect = l), o && s && (s.syncUnitTime && (this.syncUnitTime = s.syncUnitTime), S.toolsType !== o && o && s && this.setNodeKey(h, S, o, s), S.node && S.node.setWorkOptions(s));
1080
+ }
1081
+ removeNode(t, e) {
1082
+ t.indexOf(N) > -1 && this.removeSelectWork(e), this.thread.fullLayer.getElementsByName(t).forEach((s) => {
1083
+ s.remove();
1084
+ }), this.thread.serviceLayer.getElementsByName(t).forEach((s) => {
1085
+ s.remove();
1086
+ }), this.vNodes.delete(t);
1087
+ }
1088
+ removeSelectWork(t) {
1089
+ const { workId: e } = t, s = e == null ? void 0 : e.toString();
1090
+ s && (this.activeSelectorShape(t), this.willRunEffectSelectorIds.add(s)), this.runEffect();
1091
+ }
1092
+ activeSelectorShape(t) {
1093
+ var a, h, l;
1094
+ const { workId: e, opt: s, toolsType: o, type: r, selectIds: i } = t;
1095
+ if (!e)
1096
+ return;
1097
+ const n = e.toString();
1098
+ if (!((a = this.selectorWorkShapes) != null && a.has(n))) {
1099
+ let S = {
1100
+ toolsType: o,
1101
+ selectIds: i,
1102
+ type: r,
1103
+ opt: s
1104
+ };
1105
+ o && s && (S = this.setNodeKey(n, S, o, s)), (h = this.selectorWorkShapes) == null || h.set(n, S);
1106
+ }
1107
+ const c = (l = this.selectorWorkShapes) == null ? void 0 : l.get(n);
1108
+ r && (c.type = r), c.node && c.node.getWorkId() !== n && c.node.setWorkId(n), c.selectIds = i || [];
1109
+ }
1110
+ setNodeKey(t, e, s, o) {
1111
+ return e.toolsType = s, e.node = B({
1112
+ toolsType: s,
1113
+ toolsOpt: o,
1114
+ vNodes: this.vNodes,
1115
+ fullLayer: this.thread.fullLayer,
1116
+ drawLayer: this.thread.serviceLayer,
1117
+ workId: t
1118
+ }, this), e;
1119
+ }
1120
+ }
1121
+ class E {
1122
+ constructor() {
1123
+ d(this, "localWork");
1124
+ d(this, "serviceWork");
1125
+ d(this, "scene");
1126
+ }
1127
+ registerMainThread(t, e, s) {
1128
+ return this.localWork = t, this.serviceWork = e, this.scene = s, this;
1129
+ }
1130
+ }
1131
+ class me extends E {
1132
+ constructor() {
1133
+ super(...arguments);
1134
+ d(this, "emitEventType", v.CopyNode);
1135
+ }
1136
+ async consume(e) {
1137
+ const { msgType: s, dataType: o, emitEventType: r } = e;
1138
+ if (s === p.FullWork && o === w.Local && r === this.emitEventType)
1139
+ return this.consumeForLocalWorker(e), !0;
1140
+ }
1141
+ async consumeForLocalWorker(e) {
1142
+ var o;
1143
+ const { workId: s } = e;
1144
+ s && await ((o = this.localWork) == null ? void 0 : o.consumeFull(e, this.scene));
1145
+ }
1146
+ }
1147
+ class we extends E {
1148
+ constructor() {
1149
+ super(...arguments);
1150
+ d(this, "emitEventType", v.SetColorNode);
1151
+ }
1152
+ async consume(e) {
1153
+ const { msgType: s, dataType: o, emitEventType: r } = e;
1154
+ if (s === p.UpdateNode && o === w.Local && r === this.emitEventType)
1155
+ return this.consumeForLocalWorker(e), !0;
1156
+ }
1157
+ async consumeForLocalWorker(e) {
1158
+ var a;
1159
+ const { workId: s, updateNodeOpt: o, willRefreshSelector: r, willSyncService: i, willSerializeData: n, textUpdateForWoker: c } = e;
1160
+ s === N && o && await ((a = this.localWork) == null ? void 0 : a.updateSelector({
1161
+ updateSelectorOpt: o,
1162
+ willRefreshSelector: r,
1163
+ willSyncService: i,
1164
+ willSerializeData: n,
1165
+ textUpdateForWoker: c,
1166
+ callback: this.updateSelectorCallback
1167
+ }));
1168
+ }
1169
+ updateSelectorCallback(e) {
1170
+ const { param: s, postData: o, newServiceStore: r } = e, { willSyncService: i, isSync: n, textUpdateForWoker: c } = s, a = o.sp || [];
1171
+ if (i)
1172
+ for (const [h, l] of r.entries())
1173
+ c && l.toolsType === f.Text ? a.push({
1174
+ ...l,
1175
+ workId: h,
1176
+ type: p.TextUpdate,
1177
+ dataType: w.Local,
1178
+ willSyncService: !0
1179
+ }) : a.push(
1180
+ {
1181
+ ...l,
1182
+ workId: h,
1183
+ type: p.UpdateNode,
1184
+ updateNodeOpt: {
1185
+ useAnimation: !1
1186
+ },
1187
+ isSync: n
1188
+ }
1189
+ );
1190
+ return {
1191
+ sp: a
1192
+ };
1193
+ }
1194
+ }
1195
+ class ve extends E {
1196
+ constructor() {
1197
+ super(...arguments);
1198
+ d(this, "emitEventType", v.ZIndexNode);
1199
+ }
1200
+ async consume(e) {
1201
+ const { msgType: s, dataType: o, emitEventType: r } = e;
1202
+ if (s === p.UpdateNode && o === w.Local && r === this.emitEventType)
1203
+ return this.consumeForLocalWorker(e), !0;
1204
+ }
1205
+ async consumeForLocalWorker(e) {
1206
+ var c;
1207
+ const { workId: s, updateNodeOpt: o, willRefreshSelector: r, willSyncService: i, willSerializeData: n } = e;
1208
+ s === N && o && await ((c = this.localWork) == null ? void 0 : c.updateSelector({
1209
+ updateSelectorOpt: o,
1210
+ willRefreshSelector: r,
1211
+ willSyncService: i,
1212
+ willSerializeData: n,
1213
+ callback: this.updateSelectorCallback
1214
+ }));
1215
+ }
1216
+ updateSelectorCallback(e) {
1217
+ const { param: s, postData: o, newServiceStore: r } = e, { willSyncService: i, isSync: n } = s, c = o.sp || [];
1218
+ if (i && c)
1219
+ for (const [a, h] of r.entries())
1220
+ c.push(
1221
+ {
1222
+ ...h,
1223
+ workId: a,
1224
+ type: p.UpdateNode,
1225
+ updateNodeOpt: {
1226
+ useAnimation: !1
1227
+ },
1228
+ isSync: n
1229
+ }
1230
+ );
1231
+ return {
1232
+ sp: c
1233
+ };
1234
+ }
1235
+ }
1236
+ class Te extends E {
1237
+ constructor() {
1238
+ super(...arguments);
1239
+ d(this, "emitEventType", v.TranslateNode);
1240
+ }
1241
+ async consume(e) {
1242
+ const { msgType: s, dataType: o, emitEventType: r } = e;
1243
+ if (s === p.UpdateNode && o === w.Local && r === this.emitEventType)
1244
+ return await this.consumeForLocalWorker(e), !0;
1245
+ }
1246
+ async consumeForLocalWorker(e) {
1247
+ var h, l;
1248
+ const { workId: s, updateNodeOpt: o, willRefreshSelector: r, willSyncService: i, willSerializeData: n, textUpdateForWoker: c, emitEventType: a } = e;
1249
+ s === N && o && (o.workState === T.Done && (o != null && o.translate) && (o.translate[0] || o.translate[1]) || o.workState !== T.Done ? await ((h = this.localWork) == null ? void 0 : h.updateSelector({
1250
+ updateSelectorOpt: o,
1251
+ willRefreshSelector: r,
1252
+ willSyncService: i,
1253
+ willSerializeData: n,
1254
+ isSync: !0,
1255
+ textUpdateForWoker: c,
1256
+ emitEventType: a,
1257
+ scene: this.scene,
1258
+ callback: this.updateSelectorCallback
1259
+ })) : o.workState === T.Done && ((l = this.localWork) == null || l.vNodes.deleteLastTarget()));
1260
+ }
1261
+ updateSelectorCallback(e) {
1262
+ const { param: s, postData: o, newServiceStore: r, workShapeNode: i, res: n } = e, { willSyncService: c, isSync: a, updateSelectorOpt: h, textUpdateForWoker: l } = s, S = h.workState, u = o.sp || [];
1263
+ if (S === T.Start)
1264
+ return {
1265
+ sp: [],
1266
+ render: []
1267
+ };
1268
+ const y = n == null ? void 0 : n.selectRect;
1269
+ if (c) {
1270
+ S === T.Doing && u.push({
1271
+ type: p.Select,
1272
+ selectIds: i.selectIds,
1273
+ selectRect: y,
1274
+ willSyncService: !0,
1275
+ isSync: !0,
1276
+ points: i.getChildrenPoints(),
1277
+ textOpt: i.textOpt
1278
+ });
1279
+ for (const [m, g] of r.entries())
1280
+ l && g.toolsType === f.Text ? u.push({
1281
+ ...g,
1282
+ workId: m,
1283
+ type: p.TextUpdate,
1284
+ dataType: w.Local,
1285
+ willSyncService: !0
1286
+ }) : u.push(
1287
+ {
1288
+ ...g,
1289
+ workId: m,
1290
+ type: p.UpdateNode,
1291
+ updateNodeOpt: {
1292
+ useAnimation: !1
1293
+ },
1294
+ isSync: a
1295
+ }
1296
+ );
1297
+ }
1298
+ return {
1299
+ sp: u
1300
+ };
1301
+ }
1302
+ }
1303
+ class ge extends E {
1304
+ constructor() {
1305
+ super(...arguments);
1306
+ d(this, "emitEventType", v.DeleteNode);
1307
+ }
1308
+ async consume() {
1309
+ return !1;
1310
+ }
1311
+ }
1312
+ class We extends E {
1313
+ constructor() {
1314
+ super(...arguments);
1315
+ d(this, "emitEventType", v.ScaleNode);
1316
+ }
1317
+ async consume(e) {
1318
+ const { msgType: s, dataType: o, emitEventType: r } = e;
1319
+ if (s === p.UpdateNode && o === w.Local && r === this.emitEventType)
1320
+ return await this.consumeForLocalWorker(e), !0;
1321
+ }
1322
+ async consumeForLocalWorker(e) {
1323
+ var n;
1324
+ const { workId: s, updateNodeOpt: o, willSyncService: r, willSerializeData: i } = e;
1325
+ s === N && o && await ((n = this.localWork) == null ? void 0 : n.updateSelector({
1326
+ updateSelectorOpt: o,
1327
+ willSyncService: r,
1328
+ willSerializeData: i,
1329
+ isSync: !0,
1330
+ scene: this.scene,
1331
+ callback: this.updateSelectorCallback.bind(this)
1332
+ }));
1333
+ }
1334
+ updateSelectorCallback(e) {
1335
+ const { param: s, postData: o, workShapeNode: r, res: i, newServiceStore: n } = e, { updateSelectorOpt: c, willSyncService: a } = s, h = c.workState, l = o.sp || [], S = i == null ? void 0 : i.selectRect;
1336
+ if (h === T.Start)
1337
+ return {
1338
+ sp: [],
1339
+ render: []
1340
+ };
1341
+ if (a) {
1342
+ l.push({
1343
+ type: p.Select,
1344
+ selectIds: r.selectIds,
1345
+ selectRect: S,
1346
+ willSyncService: !0,
1347
+ isSync: !0,
1348
+ points: h === T.Done && r.getChildrenPoints() || void 0,
1349
+ textOpt: r.textOpt
1350
+ });
1351
+ for (const [u, y] of n.entries())
1352
+ y.toolsType === f.Text ? l.push({
1353
+ ...y,
1354
+ workId: u,
1355
+ type: p.TextUpdate,
1356
+ dataType: w.Local,
1357
+ willSyncService: !0
1358
+ }) : l.push(
1359
+ {
1360
+ ...y,
1361
+ workId: u,
1362
+ type: p.UpdateNode,
1363
+ updateNodeOpt: {
1364
+ useAnimation: !1
1365
+ },
1366
+ isSync: !0
1367
+ }
1368
+ );
1369
+ }
1370
+ return {
1371
+ sp: l
1372
+ };
1373
+ }
1374
+ }
1375
+ class Ie extends E {
1376
+ constructor() {
1377
+ super(...arguments);
1378
+ d(this, "emitEventType", v.RotateNode);
1379
+ }
1380
+ async consume(e) {
1381
+ const { msgType: s, dataType: o, emitEventType: r } = e;
1382
+ if (s === p.UpdateNode && o === w.Local && r === this.emitEventType)
1383
+ return await this.consumeForLocalWorker(e), !0;
1384
+ }
1385
+ async consumeForLocalWorker(e) {
1386
+ var a;
1387
+ const { workId: s, updateNodeOpt: o, willRefreshSelector: r, willSyncService: i, willSerializeData: n, emitEventType: c } = e;
1388
+ s === N && o && await ((a = this.localWork) == null ? void 0 : a.updateSelector({
1389
+ updateSelectorOpt: o,
1390
+ willRefreshSelector: r,
1391
+ willSyncService: i,
1392
+ willSerializeData: n,
1393
+ emitEventType: c,
1394
+ isSync: !0,
1395
+ scene: this.scene,
1396
+ callback: this.updateSelectorCallback
1397
+ }));
1398
+ }
1399
+ updateSelectorCallback(e) {
1400
+ const { param: s, postData: o, workShapeNode: r, res: i, newServiceStore: n } = e, { updateSelectorOpt: c, willSyncService: a, willSerializeData: h, isSync: l } = s, S = c.workState, u = o.sp || [], y = i == null ? void 0 : i.selectRect;
1401
+ if (a) {
1402
+ h && S === T.Done && u.push({
1403
+ type: p.Select,
1404
+ selectIds: r.selectIds,
1405
+ selectRect: y,
1406
+ willSyncService: !0,
1407
+ isSync: l,
1408
+ points: r.getChildrenPoints()
1409
+ });
1410
+ for (const [m, g] of n.entries())
1411
+ u.push(
1412
+ {
1413
+ ...g,
1414
+ workId: m,
1415
+ type: p.UpdateNode,
1416
+ updateNodeOpt: {
1417
+ useAnimation: !1
1418
+ },
1419
+ isSync: l
1420
+ }
1421
+ );
1422
+ }
1423
+ return {
1424
+ sp: u
1425
+ };
1426
+ }
1427
+ }
1428
+ class Ne extends E {
1429
+ constructor() {
1430
+ super(...arguments);
1431
+ d(this, "emitEventType", v.SetFontStyle);
1432
+ }
1433
+ async consume(e) {
1434
+ const { msgType: s, dataType: o, emitEventType: r } = e;
1435
+ if (s === p.UpdateNode && o === w.Local && r === this.emitEventType)
1436
+ return await this.consumeForLocalWorker(e), !0;
1437
+ }
1438
+ async consumeForLocalWorker(e) {
1439
+ var a;
1440
+ const { workId: s, updateNodeOpt: o, willRefreshSelector: r, willSyncService: i, willSerializeData: n, textUpdateForWoker: c } = e;
1441
+ s === N && o && await ((a = this.localWork) == null ? void 0 : a.updateSelector({
1442
+ updateSelectorOpt: o,
1443
+ willRefreshSelector: r,
1444
+ willSyncService: i,
1445
+ willSerializeData: n,
1446
+ textUpdateForWoker: c,
1447
+ callback: this.updateSelectorCallback
1448
+ }));
1449
+ }
1450
+ updateSelectorCallback(e) {
1451
+ const { param: s, postData: o, newServiceStore: r, workShapeNode: i, res: n } = e, { willSyncService: c, isSync: a, updateSelectorOpt: h, textUpdateForWoker: l } = s, S = o.sp || [], u = n == null ? void 0 : n.selectRect;
1452
+ if (c && S) {
1453
+ h.fontSize && S.push({
1454
+ type: p.Select,
1455
+ selectIds: i.selectIds,
1456
+ selectRect: u,
1457
+ willSyncService: c,
1458
+ isSync: a,
1459
+ points: i.getChildrenPoints()
1460
+ });
1461
+ for (const [y, m] of r.entries())
1462
+ l && m.toolsType === f.Text ? S.push({
1463
+ ...m,
1464
+ workId: y,
1465
+ type: p.TextUpdate,
1466
+ dataType: w.Local,
1467
+ willSyncService: !0
1468
+ }) : S.push(
1469
+ {
1470
+ ...m,
1471
+ workId: y,
1472
+ type: p.UpdateNode,
1473
+ updateNodeOpt: {
1474
+ useAnimation: !1
1475
+ },
1476
+ isSync: a
1477
+ }
1478
+ );
1479
+ }
1480
+ return {
1481
+ sp: S
1482
+ };
1483
+ }
1484
+ }
1485
+ class Le extends E {
1486
+ constructor() {
1487
+ super(...arguments);
1488
+ d(this, "emitEventType", v.SetPoint);
1489
+ }
1490
+ async consume(e) {
1491
+ const { msgType: s, dataType: o, emitEventType: r } = e;
1492
+ if (s === p.UpdateNode && o === w.Local && r === this.emitEventType)
1493
+ return this.consumeForLocalWorker(e), !0;
1494
+ }
1495
+ async consumeForLocalWorker(e) {
1496
+ var a;
1497
+ const { workId: s, updateNodeOpt: o, willRefreshSelector: r, willSyncService: i, willSerializeData: n, textUpdateForWoker: c } = e;
1498
+ s === N && o && await ((a = this.localWork) == null ? void 0 : a.updateSelector({
1499
+ updateSelectorOpt: o,
1500
+ willRefreshSelector: r,
1501
+ willSyncService: i,
1502
+ emitEventType: this.emitEventType,
1503
+ willSerializeData: n,
1504
+ isSync: !0,
1505
+ textUpdateForWoker: c,
1506
+ callback: this.updateSelectorCallback
1507
+ }));
1508
+ }
1509
+ updateSelectorCallback(e) {
1510
+ const { param: s, postData: o, newServiceStore: r, workShapeNode: i, res: n } = e, { willSyncService: c, isSync: a } = s, h = o.sp || [], l = n == null ? void 0 : n.selectRect;
1511
+ if (c && h) {
1512
+ for (const [S, u] of r.entries())
1513
+ h.push(
1514
+ {
1515
+ ...u,
1516
+ workId: S,
1517
+ type: p.UpdateNode,
1518
+ updateNodeOpt: {
1519
+ useAnimation: !1
1520
+ },
1521
+ isSync: a
1522
+ }
1523
+ );
1524
+ h.push({
1525
+ type: p.Select,
1526
+ selectIds: i.selectIds,
1527
+ selectRect: l,
1528
+ willSyncService: c,
1529
+ isSync: a,
1530
+ points: i.getChildrenPoints()
1531
+ });
1532
+ }
1533
+ return {
1534
+ sp: h
1535
+ };
1536
+ }
1537
+ }
1538
+ class be extends E {
1539
+ constructor() {
1540
+ super(...arguments);
1541
+ d(this, "emitEventType", v.SetLock);
1542
+ }
1543
+ async consume(e) {
1544
+ const { msgType: s, dataType: o, emitEventType: r } = e;
1545
+ if (s === p.UpdateNode && o === w.Local && r === this.emitEventType)
1546
+ return this.consumeForLocalWorker(e), !0;
1547
+ }
1548
+ async consumeForLocalWorker(e) {
1549
+ var c;
1550
+ const { workId: s, updateNodeOpt: o, willRefreshSelector: r, willSyncService: i, willSerializeData: n } = e;
1551
+ s === N && o && await ((c = this.localWork) == null ? void 0 : c.updateSelector({
1552
+ updateSelectorOpt: o,
1553
+ willRefreshSelector: r,
1554
+ willSyncService: i,
1555
+ willSerializeData: n,
1556
+ callback: this.updateSelectorCallback
1557
+ }));
1558
+ }
1559
+ updateSelectorCallback(e) {
1560
+ const { param: s, postData: o, newServiceStore: r, workShapeNode: i, res: n } = e, { willSyncService: c, isSync: a, updateSelectorOpt: h } = s, l = o.sp || [], S = n == null ? void 0 : n.selectRect;
1561
+ if (c && l) {
1562
+ for (const [u, y] of r.entries())
1563
+ l.push(
1564
+ {
1565
+ ...y,
1566
+ workId: u,
1567
+ type: p.UpdateNode,
1568
+ updateNodeOpt: {
1569
+ useAnimation: !1
1570
+ },
1571
+ isSync: a
1572
+ }
1573
+ );
1574
+ l.push({
1575
+ isLocked: h.isLocked,
1576
+ selectorColor: i.selectorColor,
1577
+ scaleType: i.scaleType,
1578
+ canRotate: i.canRotate,
1579
+ type: p.Select,
1580
+ selectIds: i.selectIds,
1581
+ selectRect: S,
1582
+ willSyncService: c,
1583
+ isSync: a
1584
+ });
1585
+ }
1586
+ return {
1587
+ sp: l
1588
+ };
1589
+ }
1590
+ }
1591
+ class Oe extends E {
1592
+ constructor() {
1593
+ super(...arguments);
1594
+ d(this, "emitEventType", v.SetShapeOpt);
1595
+ }
1596
+ async consume(e) {
1597
+ const { msgType: s, dataType: o, emitEventType: r } = e;
1598
+ if (s === p.UpdateNode && o === w.Local && r === this.emitEventType)
1599
+ return this.consumeForLocalWorker(e), !0;
1600
+ }
1601
+ async consumeForLocalWorker(e) {
1602
+ var c;
1603
+ const { workId: s, updateNodeOpt: o, willRefreshSelector: r, willSyncService: i, willSerializeData: n } = e;
1604
+ s === N && o && await ((c = this.localWork) == null ? void 0 : c.updateSelector({
1605
+ updateSelectorOpt: o,
1606
+ willRefreshSelector: r,
1607
+ willSyncService: i,
1608
+ willSerializeData: n,
1609
+ callback: this.updateSelectorCallback
1610
+ }));
1611
+ }
1612
+ updateSelectorCallback(e) {
1613
+ const { param: s, postData: o, newServiceStore: r } = e, { willSyncService: i, isSync: n } = s, c = o.sp || [];
1614
+ if (i && c)
1615
+ for (const [a, h] of r.entries())
1616
+ c.push(
1617
+ {
1618
+ ...h,
1619
+ workId: a,
1620
+ type: p.UpdateNode,
1621
+ updateNodeOpt: {
1622
+ useAnimation: !1
1623
+ },
1624
+ isSync: n
1625
+ }
1626
+ );
1627
+ return {
1628
+ sp: c
1629
+ };
1630
+ }
1631
+ }
1632
+ class De {
1633
+ constructor(t) {
1634
+ d(this, "builders", /* @__PURE__ */ new Map());
1635
+ this.builders = new Map(t.map((e) => [e, this.build(e)]));
1636
+ }
1637
+ build(t) {
1638
+ switch (t) {
1639
+ case v.TranslateNode:
1640
+ return new Te();
1641
+ case v.ZIndexNode:
1642
+ return new ve();
1643
+ case v.CopyNode:
1644
+ return new me();
1645
+ case v.SetColorNode:
1646
+ return new we();
1647
+ case v.DeleteNode:
1648
+ return new ge();
1649
+ case v.ScaleNode:
1650
+ return new We();
1651
+ case v.RotateNode:
1652
+ return new Ie();
1653
+ case v.SetFontStyle:
1654
+ return new Ne();
1655
+ case v.SetPoint:
1656
+ return new Le();
1657
+ case v.SetLock:
1658
+ return new be();
1659
+ case v.SetShapeOpt:
1660
+ return new Oe();
1661
+ }
1662
+ }
1663
+ registerForMainThread(t, e, s) {
1664
+ return this.builders.forEach((o) => {
1665
+ o && o.registerMainThread(t, e, s);
1666
+ }), this;
1667
+ }
1668
+ async consumeForMainThread(t) {
1669
+ for (const e of this.builders.values())
1670
+ if (await (e == null ? void 0 : e.consume(t)))
1671
+ return !0;
1672
+ return !1;
1673
+ }
1674
+ }
1675
+ class Ee {
1676
+ constructor(t, e) {
1677
+ d(this, "viewId");
1678
+ d(this, "fullLayer");
1679
+ d(this, "topLayer");
1680
+ d(this, "localLayer");
1681
+ d(this, "serviceLayer");
1682
+ d(this, "snapshotFullLayer");
1683
+ d(this, "vNodes");
1684
+ d(this, "master");
1685
+ d(this, "opt");
1686
+ d(this, "cameraOpt");
1687
+ d(this, "scene");
1688
+ d(this, "localWork");
1689
+ d(this, "serviceWork");
1690
+ d(this, "topWork");
1691
+ d(this, "taskUpdateCameraId");
1692
+ d(this, "debounceUpdateCameraId");
1693
+ d(this, "debounceUpdateCache", /* @__PURE__ */ new Set());
1694
+ d(this, "mainThreadPostId");
1695
+ d(this, "combinePostMsg", /* @__PURE__ */ new Set());
1696
+ d(this, "methodBuilder");
1697
+ this.viewId = t, this.opt = e, this.scene = this.createScene({ ...e.canvasOpt, container: e.container }), this.master = e.master;
1698
+ const s = F.bufferSize.full, o = F.bufferSize.sub;
1699
+ this.fullLayer = this.createLayer("fullLayer", this.scene, { ...e.layerOpt, bufferSize: this.viewId === A ? s : o }), this.topLayer = this.createLayer("topLayer", this.scene, { ...e.layerOpt, bufferSize: (this.viewId === A, o) }), this.localLayer = this.createLayer("localLayer", this.scene, { ...e.layerOpt, bufferSize: (this.viewId === A, o) }), this.serviceLayer = this.createLayer("serviceLayer", this.scene, { ...e.layerOpt, bufferSize: (this.viewId === A, o) }), this.vNodes = new fe(t, this.scene);
1700
+ const r = {
1701
+ thread: this,
1702
+ vNodes: this.vNodes
1703
+ };
1704
+ this.localWork = new ke(r), this.serviceWork = new ye(r), this.topWork = new Se(r), this.vNodes.init(this.fullLayer), this.methodBuilder = new De([
1705
+ v.CopyNode,
1706
+ v.SetColorNode,
1707
+ v.DeleteNode,
1708
+ v.RotateNode,
1709
+ v.ScaleNode,
1710
+ v.TranslateNode,
1711
+ v.ZIndexNode,
1712
+ v.SetFontStyle,
1713
+ v.SetPoint,
1714
+ v.SetLock,
1715
+ v.SetShapeOpt
1716
+ ]).registerForMainThread(this.localWork, this.serviceWork, this.scene);
1717
+ }
1718
+ post(t) {
1719
+ this.combinePostMsg.add(t), this.runBatchPostData();
1720
+ }
1721
+ async on(t) {
1722
+ if (!await this.methodBuilder.consumeForMainThread(t)) {
1723
+ const { msgType: e, toolsType: s, opt: o, dataType: r, workId: i, workState: n } = t, c = i == null ? void 0 : i.toString();
1724
+ switch (e) {
1725
+ case p.Destroy:
1726
+ this.destroy();
1727
+ break;
1728
+ case p.Clear:
1729
+ this.clearAll();
1730
+ break;
1731
+ case p.UpdateCamera:
1732
+ await this.updateCamera(t);
1733
+ break;
1734
+ case p.UpdateTools:
1735
+ if (s && o) {
1736
+ const a = {
1737
+ toolsType: s,
1738
+ toolsOpt: o
1739
+ };
1740
+ this.topWork.canUseTopLayer(s) ? this.topWork.setToolsOpt(a) : this.localWork.setToolsOpt(a);
1741
+ }
1742
+ break;
1743
+ case p.CreateWork:
1744
+ if (c && o && s) {
1745
+ if (this.topWork.canUseTopLayer(s)) {
1746
+ this.topWork.getToolsOpt() || this.topWork.setToolsOpt({
1747
+ toolsType: s,
1748
+ toolsOpt: o
1749
+ }), this.topWork.setWorkOptions(c, o);
1750
+ break;
1751
+ }
1752
+ this.localWork.getToolsOpt() || this.localWork.setToolsOpt({
1753
+ toolsType: s,
1754
+ toolsOpt: o
1755
+ }), this.localWork.setWorkOptions(c, o);
1756
+ }
1757
+ break;
1758
+ case p.DrawWork:
1759
+ n === T.Done && r === w.Local ? this.consumeDrawAll(r, t) : this.consumeDraw(r, t);
1760
+ break;
1761
+ case p.UpdateNode:
1762
+ case p.FullWork:
1763
+ if (s && this.topWork.canUseTopLayer(s)) {
1764
+ this.consumeDrawAll(r, t);
1765
+ break;
1766
+ }
1767
+ this.consumeFull(r, t);
1768
+ break;
1769
+ case p.RemoveNode:
1770
+ await this.removeNode(t);
1771
+ return;
1772
+ case p.Select:
1773
+ r === w.Service && (i === N ? this.localWork.updateFullSelectWork(t) : this.serviceWork.runSelectWork(t));
1774
+ break;
1775
+ case p.CursorHover:
1776
+ this.localWork.cursorHover(t);
1777
+ break;
1778
+ case p.GetTextActive:
1779
+ r === w.Local && this.localWork.checkTextActive(t);
1780
+ break;
1781
+ }
1782
+ }
1783
+ }
1784
+ async removeNode(t) {
1785
+ const { dataType: e, workId: s, removeIds: o } = t, r = o || [];
1786
+ if (s && r.push(s.toString()), r.length)
1787
+ for (const i of r) {
1788
+ if (i === N) {
1789
+ await this.localWork.removeSelector(t);
1790
+ continue;
1791
+ }
1792
+ e === w.Local ? this.localWork.removeWork(t) : e === w.Service && this.serviceWork.removeWork(t), await this.localWork.colloctEffectSelectWork(t);
1793
+ }
1794
+ }
1795
+ async consumeFull(t, e) {
1796
+ const s = await this.localWork.colloctEffectSelectWork(e);
1797
+ s && t === w.Local && await this.localWork.consumeFull(s, this.scene), s && t === w.Service && this.serviceWork.consumeFull(s);
1798
+ }
1799
+ setCameraOpt(t) {
1800
+ this.cameraOpt = t;
1801
+ const { scale: e, centerX: s, centerY: o, width: r, height: i } = t;
1802
+ (r !== this.scene.width || i !== this.scene.height) && this.updateScene({ width: r, height: i }), this.fullLayer.setAttribute("scale", [e, e]), this.fullLayer.setAttribute("translate", [-s, -o]), this.topLayer.setAttribute("scale", [e, e]), this.topLayer.setAttribute("translate", [-s, -o]), this.localLayer.setAttribute("scale", [e, e]), this.localLayer.setAttribute("translate", [-s, -o]), this.serviceLayer.setAttribute("scale", [e, e]), this.serviceLayer.setAttribute("translate", [-s, -o]);
1803
+ }
1804
+ runBatchPostData() {
1805
+ this.mainThreadPostId || (this.mainThreadPostId = requestAnimationFrame(this.combinePost.bind(this)));
1806
+ }
1807
+ combinePostData() {
1808
+ var s;
1809
+ this.mainThreadPostId = void 0;
1810
+ const t = [];
1811
+ let e;
1812
+ for (const o of this.combinePostMsg.values()) {
1813
+ if ((s = o.sp) != null && s.length)
1814
+ for (const r of o.sp) {
1815
+ let i = !1;
1816
+ for (const n of t)
1817
+ if (X(r, n)) {
1818
+ i = !0;
1819
+ break;
1820
+ }
1821
+ i || t.push(r);
1822
+ }
1823
+ ue(o.drawCount) && (e = o.drawCount);
1824
+ }
1825
+ return this.combinePostMsg.clear(), {
1826
+ sp: t,
1827
+ drawCount: e
1828
+ };
1829
+ }
1830
+ combinePost() {
1831
+ var s, o;
1832
+ const t = this.combinePostData(), e = (s = t.sp) == null ? void 0 : s.filter((r) => r.type !== p.None);
1833
+ e != null && e.length ? t.sp = e.map((r) => r.viewId ? r : { ...r, viewId: this.viewId }) : delete t.sp, t.drawCount === void 0 && delete t.drawCount, (t != null && t.drawCount || (o = t.sp) != null && o.length) && this.opt.post(t);
1834
+ }
1835
+ clearAll() {
1836
+ this.fullLayer.children.length && (this.fullLayer.parent.children.forEach((t) => {
1837
+ t.name !== "viewport" && t.remove();
1838
+ }), this.fullLayer.removeAllChildren()), this.localWork.clearAll(), this.topWork.clearAll(), this.serviceWork.clearAll(), this.vNodes.clear(), this.post({
1839
+ sp: [{
1840
+ type: p.Clear
1841
+ }]
1842
+ });
1843
+ }
1844
+ consumeDrawAll(t, e) {
1845
+ const { toolsType: s, workId: o } = e;
1846
+ if (o) {
1847
+ const r = o.toString();
1848
+ if (s && this.topWork.canUseTopLayer(s)) {
1849
+ t === w.Local && (this.topWork.getLocalWorkShape(o.toString()) || this.topWork.createLocalWork(e)), this.topWork.consumeDrawAll(e);
1850
+ return;
1851
+ }
1852
+ t === w.Local && (this.localWork.getWorkShape(r) || this.localWork.createLocalWork(e), this.localWork.consumeDrawAll(e, this.serviceWork));
1853
+ }
1854
+ }
1855
+ consumeDraw(t, e) {
1856
+ const { opt: s, workId: o, toolsType: r } = e;
1857
+ if (o && r && s) {
1858
+ const i = o.toString();
1859
+ if (this.topWork.canUseTopLayer(r)) {
1860
+ t === w.Local && (this.topWork.getLocalWorkShape(i) || this.topWork.createLocalWork(e)), this.topWork.consumeDraw(e);
1861
+ return;
1862
+ }
1863
+ t === w.Local ? (this.localWork.getWorkShape(i) || this.localWork.createLocalWork(e), this.localWork.consumeDraw(e, this.serviceWork)) : t === w.Service && this.serviceWork.consumeDraw(e);
1864
+ return;
1865
+ }
1866
+ }
1867
+ async updateCamera(t) {
1868
+ var o;
1869
+ const { cameraOpt: e, scenePath: s } = t;
1870
+ if (e && !X(this.cameraOpt, e)) {
1871
+ if (this.taskUpdateCameraId && (clearTimeout(this.taskUpdateCameraId), this.taskUpdateCameraId = void 0), s) {
1872
+ let a = !1;
1873
+ for (const [h, l] of this.localWork.getWorkShapes().entries())
1874
+ if (l.toolsType !== f.Text && l.toolsType !== f.PencilEraser && l.toolsType !== f.Eraser && l.toolsType !== f.Selector && l.toolsType !== f.LaserPen && h !== H && h !== N) {
1875
+ a = !0;
1876
+ break;
1877
+ }
1878
+ if (a) {
1879
+ this.taskUpdateCameraId = setTimeout(() => {
1880
+ this.taskUpdateCameraId = void 0, this.updateCamera(t);
1881
+ }, $);
1882
+ return;
1883
+ }
1884
+ }
1885
+ const r = /* @__PURE__ */ new Map();
1886
+ for (const [a, h] of this.vNodes.getNodesByType(f.Text).entries()) {
1887
+ const l = h.rect;
1888
+ r.set(a, ee(l));
1889
+ }
1890
+ const i = new Set(r.keys());
1891
+ let n = !1;
1892
+ if (this.localWork.hasSelector()) {
1893
+ const a = (o = this.localWork.getSelector()) == null ? void 0 : o.selectIds;
1894
+ if (a) {
1895
+ n = !0;
1896
+ for (const h of a)
1897
+ i.add(h);
1898
+ }
1899
+ }
1900
+ let c = !1;
1901
+ if (this.serviceWork.selectorWorkShapes.size)
1902
+ for (const a of this.serviceWork.selectorWorkShapes.values()) {
1903
+ const h = a.selectIds;
1904
+ if (h) {
1905
+ c = !0;
1906
+ for (const l of h)
1907
+ i.add(l);
1908
+ }
1909
+ }
1910
+ if (this.setCameraOpt(e), this.vNodes.curNodeMap.size) {
1911
+ this.vNodes.clearTarget(), this.vNodes.updateHighLevelNodesRect(i), this.debounceUpdateCameraId && clearTimeout(this.debounceUpdateCameraId);
1912
+ for (const [a, h] of r.entries()) {
1913
+ const l = this.vNodes.get(a);
1914
+ if (l) {
1915
+ const S = h, u = l.rect, y = this.getSceneRect(), m = _(S, y), g = _(u, y);
1916
+ let W = !1;
1917
+ if ((m !== g || S.w !== u.w || S.h !== u.h || g === Z.intersect) && (W = !0), W) {
1918
+ const { toolsType: M, opt: L } = l;
1919
+ M === f.Text && L.workState === T.Done && this.debounceUpdateCache.add(a);
1920
+ }
1921
+ }
1922
+ }
1923
+ if (n && this.localWork.reRenderSelector(), c)
1924
+ for (const [a, h] of this.serviceWork.selectorWorkShapes.entries())
1925
+ this.serviceWork.runSelectWork({
1926
+ workId: a,
1927
+ selectIds: h.selectIds,
1928
+ msgType: p.Select,
1929
+ dataType: w.Service,
1930
+ viewId: this.viewId
1931
+ });
1932
+ this.debounceUpdateCameraId = setTimeout(() => {
1933
+ var h;
1934
+ this.debounceUpdateCameraId = void 0;
1935
+ const a = [];
1936
+ for (const l of this.debounceUpdateCache.values()) {
1937
+ if ((h = this.fullLayer) == null ? void 0 : h.getElementsByName(l)[0]) {
1938
+ const u = this.vNodes.get(l);
1939
+ if (u) {
1940
+ const { toolsType: y, opt: m, rect: g } = u, W = this.localWork.setFullWork({
1941
+ toolsType: y,
1942
+ opt: m,
1943
+ workId: l
1944
+ });
1945
+ if (W) {
1946
+ const M = this.getSceneRect(), L = _(g, M);
1947
+ a.push(W.consumeServiceAsync({
1948
+ isFullWork: !0,
1949
+ replaceId: l,
1950
+ isDrawLabel: L !== Z.outside
1951
+ }));
1952
+ }
1953
+ }
1954
+ }
1955
+ this.debounceUpdateCache.delete(l);
1956
+ }
1957
+ this.vNodes.updateLowLevelNodesRect(), this.vNodes.clearHighLevelIds();
1958
+ }, $);
1959
+ }
1960
+ }
1961
+ }
1962
+ getSceneRect() {
1963
+ const { width: t, height: e } = this.scene;
1964
+ return {
1965
+ x: 0,
1966
+ y: 0,
1967
+ w: Math.floor(t),
1968
+ h: Math.floor(e)
1969
+ };
1970
+ }
1971
+ createScene(t) {
1972
+ return new Q({
1973
+ displayRatio: this.opt.displayer.dpr,
1974
+ depth: !1,
1975
+ desynchronized: !0,
1976
+ ...t,
1977
+ autoRender: !0,
1978
+ id: this.viewId
1979
+ });
1980
+ }
1981
+ createLayer(t, e, s) {
1982
+ const { width: o, height: r } = s, i = `canvas-${t}`, n = e.layer(i, { ...s, offscreen: !1 }), c = new J({
1983
+ anchor: [0.5, 0.5],
1984
+ pos: [o * 0.5, r * 0.5],
1985
+ size: [o, r],
1986
+ name: "viewport",
1987
+ id: t
1988
+ });
1989
+ return n.append(c), c;
1990
+ }
1991
+ updateScene(t) {
1992
+ this.scene.attr({ ...t });
1993
+ const { width: e, height: s } = t;
1994
+ this.scene.width = e, this.scene.height = s, this.updateLayer({ width: e, height: s });
1995
+ }
1996
+ updateLayer(t) {
1997
+ const { width: e, height: s } = t;
1998
+ this.fullLayer.parent.setAttribute("width", e), this.fullLayer.parent.setAttribute("height", s), this.fullLayer.setAttribute("size", [e, s]), this.fullLayer.setAttribute("pos", [e * 0.5, s * 0.5]), this.topLayer.parent.setAttribute("width", e), this.topLayer.parent.setAttribute("height", s), this.topLayer.setAttribute("size", [e, s]), this.topLayer.setAttribute("pos", [e * 0.5, s * 0.5]), this.localLayer.parent.setAttribute("width", e), this.localLayer.parent.setAttribute("height", s), this.localLayer.setAttribute("size", [e, s]), this.localLayer.setAttribute("pos", [e * 0.5, s * 0.5]), this.serviceLayer.parent.setAttribute("width", e), this.serviceLayer.parent.setAttribute("height", s), this.serviceLayer.setAttribute("size", [e, s]), this.serviceLayer.setAttribute("pos", [e * 0.5, s * 0.5]);
1999
+ }
2000
+ destroy() {
2001
+ this.vNodes.clear(), this.fullLayer.remove(), this.topLayer.remove(), this.localLayer.remove(), this.serviceLayer.remove(), this.scene.remove(), this.localWork.destroy(), this.serviceWork.destroy(), this.topWork.destroy();
2002
+ }
2003
+ }
2004
+ class Me {
2005
+ constructor(t, e) {
2006
+ d(this, "viewId");
2007
+ d(this, "fullLayer");
2008
+ d(this, "master");
2009
+ d(this, "opt");
2010
+ d(this, "scene");
2011
+ d(this, "mainThreadPostId");
2012
+ d(this, "combinePostMsg", /* @__PURE__ */ new Set());
2013
+ d(this, "workShapes", /* @__PURE__ */ new Map());
2014
+ this.viewId = t, this.opt = e, this.scene = this.createScene({ ...e.canvasOpt, container: e.container }), this.master = e.master, this.fullLayer = this.createLayer("fullLayer", this.scene, { ...e.layerOpt, bufferSize: this.viewId === A ? 6e3 : 3e3 });
2015
+ }
2016
+ post(t) {
2017
+ this.combinePostMsg.add(t), this.runBatchPostData();
2018
+ }
2019
+ async on(t) {
2020
+ const { msgType: e } = t;
2021
+ switch (e) {
2022
+ case p.Snapshot:
2023
+ await this.getSnapshot(t), this.destroy();
2024
+ return;
2025
+ case p.BoundingBox:
2026
+ await this.getBoundingRect(t), this.destroy();
2027
+ return;
2028
+ }
2029
+ }
2030
+ createWorkShapeNode(t) {
2031
+ return B({ ...t, fullLayer: this.fullLayer, drawLayer: void 0 });
2032
+ }
2033
+ setFullWork(t) {
2034
+ const { workId: e, opt: s, toolsType: o } = t;
2035
+ if (e && s && o) {
2036
+ const r = e.toString();
2037
+ let i;
2038
+ return e && this.workShapes.has(r) ? (i = this.workShapes.get(r), i == null || i.setWorkOptions(s)) : i = this.createWorkShapeNode({
2039
+ toolsOpt: s,
2040
+ toolsType: o,
2041
+ workId: r
2042
+ }), i ? (this.workShapes.set(r, i), i) : void 0;
2043
+ }
2044
+ }
2045
+ async runFullWork(t) {
2046
+ var o, r;
2047
+ const e = this.setFullWork(t), s = t.ops && P(t.ops);
2048
+ if (e) {
2049
+ let i, n;
2050
+ const c = (o = e.getWorkId()) == null ? void 0 : o.toString();
2051
+ return e.toolsType === f.Image ? i = await e.consumeServiceAsync({
2052
+ isFullWork: !0,
2053
+ scene: (r = this.fullLayer.parent) == null ? void 0 : r.parent,
2054
+ isMainThread: !0
2055
+ }) : e.toolsType === f.Text ? i = await e.consumeServiceAsync({
2056
+ isFullWork: !0,
2057
+ replaceId: c,
2058
+ isDrawLabel: !0
2059
+ }) : (i = e.consumeService({
2060
+ op: s,
2061
+ isFullWork: !0,
2062
+ replaceId: c
2063
+ }), n = (t == null ? void 0 : t.updateNodeOpt) && e.updataOptService(t.updateNodeOpt)), x(i, n);
2064
+ }
2065
+ }
2066
+ async getSnapshot(t) {
2067
+ const { scenePath: e, scenes: s, cameraOpt: o, w: r, h: i } = t;
2068
+ if (e && s && o) {
2069
+ this.setCameraOpt(o);
2070
+ let n;
2071
+ for (const [a, h] of Object.entries(s))
2072
+ if (h != null && h.type)
2073
+ switch (h == null ? void 0 : h.type) {
2074
+ case p.UpdateNode:
2075
+ case p.FullWork: {
2076
+ const { opt: l } = h, S = await this.runFullWork({
2077
+ ...h,
2078
+ opt: l,
2079
+ workId: a,
2080
+ msgType: p.FullWork,
2081
+ dataType: w.Service,
2082
+ viewId: this.viewId
2083
+ });
2084
+ n = x(n, S);
2085
+ break;
2086
+ }
2087
+ }
2088
+ let c;
2089
+ r && i && (c = {
2090
+ resizeWidth: r,
2091
+ resizeHeight: i
2092
+ }), await this.getSnapshotRender({ scenePath: e, options: c });
2093
+ }
2094
+ }
2095
+ getSceneRect() {
2096
+ const { width: t, height: e } = this.scene;
2097
+ return {
2098
+ x: 0,
2099
+ y: 0,
2100
+ w: Math.floor(t),
2101
+ h: Math.floor(e)
2102
+ };
2103
+ }
2104
+ getRectImageBitmap(t, e) {
2105
+ const s = Math.floor(t.x * this.opt.displayer.dpr), o = Math.floor(t.y * this.opt.displayer.dpr), r = t.w > 0 && Math.floor(t.w * this.opt.displayer.dpr || 1) || 1, i = t.h > 0 && Math.floor(t.h * this.opt.displayer.dpr || 1) || 1;
2106
+ return createImageBitmap(this.fullLayer.parent.canvas, s, o, r, i, e);
2107
+ }
2108
+ async getSnapshotRender(t) {
2109
+ var r, i;
2110
+ const { scenePath: e, options: s } = t;
2111
+ ((r = this.fullLayer) == null ? void 0 : r.parent).render();
2112
+ const o = await this.getRectImageBitmap(this.getSceneRect(), s);
2113
+ o && (this.post({
2114
+ sp: [{
2115
+ type: p.Snapshot,
2116
+ scenePath: e,
2117
+ imageBitmap: o,
2118
+ viewId: this.viewId
2119
+ }]
2120
+ }), (i = this.fullLayer) == null || i.removeAllChildren());
2121
+ }
2122
+ async getBoundingRect(t) {
2123
+ const { scenePath: e, scenes: s, cameraOpt: o } = t;
2124
+ if (e && s && o) {
2125
+ this.setCameraOpt(o);
2126
+ let r;
2127
+ for (const [i, n] of Object.entries(s))
2128
+ if (n != null && n.type)
2129
+ switch (n == null ? void 0 : n.type) {
2130
+ case p.UpdateNode:
2131
+ case p.FullWork: {
2132
+ const c = await this.runFullWork({
2133
+ ...n,
2134
+ workId: i,
2135
+ msgType: p.FullWork,
2136
+ dataType: w.Service,
2137
+ viewId: this.viewId
2138
+ });
2139
+ r = x(r, c);
2140
+ break;
2141
+ }
2142
+ }
2143
+ r && this.post({
2144
+ sp: [{
2145
+ type: p.BoundingBox,
2146
+ scenePath: e,
2147
+ rect: r
2148
+ }]
2149
+ });
2150
+ }
2151
+ }
2152
+ setCameraOpt(t) {
2153
+ const { scale: e, centerX: s, centerY: o, width: r, height: i } = t;
2154
+ this.updateScene({ width: r, height: i }), this.fullLayer.setAttribute("scale", [e, e]), this.fullLayer.setAttribute("translate", [-s, -o]);
2155
+ }
2156
+ runBatchPostData() {
2157
+ this.mainThreadPostId || (this.mainThreadPostId = requestAnimationFrame(this.combinePost.bind(this)));
2158
+ }
2159
+ combinePostData() {
2160
+ var e;
2161
+ this.mainThreadPostId = void 0;
2162
+ const t = [];
2163
+ for (const s of this.combinePostMsg.values())
2164
+ if ((e = s.sp) != null && e.length)
2165
+ for (const o of s.sp) {
2166
+ let r = !1;
2167
+ for (const i of t)
2168
+ if (he(o, i)) {
2169
+ r = !0;
2170
+ break;
2171
+ }
2172
+ r || t.push(o);
2173
+ }
2174
+ return this.combinePostMsg.clear(), {
2175
+ sp: t
2176
+ };
2177
+ }
2178
+ combinePost() {
2179
+ var s, o;
2180
+ const t = this.combinePostData(), e = (s = t.sp) == null ? void 0 : s.filter((r) => r.type !== p.None);
2181
+ e != null && e.length ? t.sp = e.map((r) => r.viewId ? r : { ...r, viewId: this.viewId }) : delete t.sp, (t != null && t.drawCount || (o = t.sp) != null && o.length) && this.opt.post(t);
2182
+ }
2183
+ createScene(t) {
2184
+ return new Q({
2185
+ displayRatio: this.opt.displayer.dpr,
2186
+ depth: !1,
2187
+ desynchronized: !0,
2188
+ ...t,
2189
+ autoRender: !1
2190
+ });
2191
+ }
2192
+ createLayer(t, e, s) {
2193
+ const { width: o, height: r } = s, i = `canvas-${t}`, n = e.layer(i, s), c = new J({
2194
+ anchor: [0.5, 0.5],
2195
+ pos: [o * 0.5, r * 0.5],
2196
+ size: [o, r],
2197
+ name: "viewport",
2198
+ id: t
2199
+ });
2200
+ return n.append(c), c;
2201
+ }
2202
+ updateScene(t) {
2203
+ this.scene.attr({ ...t });
2204
+ const { width: e, height: s } = t;
2205
+ this.scene.width = e, this.scene.height = s, this.updateLayer({ width: e, height: s });
2206
+ }
2207
+ updateLayer(t) {
2208
+ const { width: e, height: s } = t;
2209
+ this.fullLayer.parent.setAttribute("width", e), this.fullLayer.parent.setAttribute("height", s), this.fullLayer.setAttribute("size", [e, s]), this.fullLayer.setAttribute("pos", [e * 0.5, s * 0.5]);
2210
+ }
2211
+ destroy() {
2212
+ this.fullLayer.remove(), this.scene.remove();
2213
+ }
2214
+ }
2215
+ class ze {
2216
+ constructor(t) {
2217
+ d(this, "mainThreadMap", /* @__PURE__ */ new Map());
2218
+ d(this, "snapshotThread");
2219
+ d(this, "master");
2220
+ this.master = t;
2221
+ }
2222
+ post(t) {
2223
+ const { drawCount: e, sp: s, workerTasksqueueCount: o } = t;
2224
+ this.master.isBusy && j(o) && this.master.setWorkerTasksqueueCount(o), j(e) && this.master.setMaxDrawCount(e), s && this.master.collectorSyncData(s);
2225
+ }
2226
+ destroy() {
2227
+ this.mainThreadMap.clear();
2228
+ }
2229
+ createMainThread(t, e) {
2230
+ return new Ee(t, e);
2231
+ }
2232
+ createSnapshotThread(t, e) {
2233
+ return new Me(t, e);
2234
+ }
2235
+ async consume(t) {
2236
+ var e, s, o, r;
2237
+ for (const i of t.values()) {
2238
+ const { msgType: n, viewId: c, tasksqueue: a, mainTasksqueueCount: h, layerOpt: l, offscreenCanvasOpt: S, cameraOpt: u } = i;
2239
+ if (n === p.Console) {
2240
+ console.log(this);
2241
+ continue;
2242
+ }
2243
+ if (n === p.Init) {
2244
+ const m = (e = this.master.control.viewContainerManager.getView(c)) == null ? void 0 : e.displayer, g = m == null ? void 0 : m.canvasContainerRef.current;
2245
+ if (m && g && l && S) {
2246
+ const W = this.createMainThread(c, {
2247
+ displayer: m,
2248
+ container: g,
2249
+ layerOpt: l,
2250
+ master: this.master,
2251
+ canvasOpt: S,
2252
+ post: this.post.bind(this)
2253
+ });
2254
+ this.mainThreadMap.set(c, W), W && u && W.setCameraOpt(u);
2255
+ }
2256
+ continue;
2257
+ }
2258
+ if ((n === p.Snapshot || n === p.BoundingBox) && c === ((s = this.master.control.viewContainerManager.mainView) == null ? void 0 : s.id)) {
2259
+ const m = (o = this.master.control.viewContainerManager.getView(c)) == null ? void 0 : o.displayer, g = (r = m.snapshotContainerRef) == null ? void 0 : r.current;
2260
+ if (m && g && u) {
2261
+ g.style.width = `${u.width}px`, g.style.height = `${u.height}px`;
2262
+ const W = {
2263
+ ...G.defaultLayerOpt,
2264
+ offscreen: !1,
2265
+ width: u.width,
2266
+ height: u.height
2267
+ }, M = {
2268
+ ...G.defaultScreenCanvasOpt,
2269
+ width: u.width,
2270
+ height: u.height
2271
+ };
2272
+ this.snapshotThread = this.createSnapshotThread(c, {
2273
+ displayer: m,
2274
+ container: g,
2275
+ layerOpt: W,
2276
+ master: this.master,
2277
+ canvasOpt: M,
2278
+ post: this.post.bind(this)
2279
+ }), this.snapshotThread.on(i).then(() => {
2280
+ this.snapshotThread = void 0, g.innerHTML = "", g.style.width = "", g.style.height = "";
2281
+ });
2282
+ continue;
2283
+ }
2284
+ }
2285
+ if (n === p.TasksQueue && (a != null && a.size)) {
2286
+ for (const [m, g] of this.mainThreadMap.entries()) {
2287
+ const W = a.get(m);
2288
+ W && (await g.on(W), h && this.post({ workerTasksqueueCount: h }));
2289
+ }
2290
+ continue;
2291
+ }
2292
+ if (c === pe) {
2293
+ for (const m of this.mainThreadMap.values())
2294
+ m.on(i), n === p.Destroy && this.mainThreadMap.delete(c);
2295
+ continue;
2296
+ }
2297
+ const y = this.mainThreadMap.get(c);
2298
+ y && (y.on(i), n === p.Destroy && this.mainThreadMap.delete(c));
2299
+ }
2300
+ }
2301
+ }
2302
+ export {
2303
+ ze as MainThreadManagerImpl
2304
+ };