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

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 +28 -1
  3. package/dist/appliance-plugin.js +1 -1
  4. package/dist/appliance-plugin.mjs +33 -30
  5. package/dist/{bridge-C8yT2GqS.js → bridge-CDqtVTPN.js} +1 -1
  6. package/dist/{bridge-DLGOhX8U.mjs → bridge-nmqVpnZ5.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 +7 -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 +236 -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 +15 -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 +66 -14
  53. package/dist/core/tools/text.d.ts +2 -1
  54. package/dist/core/types.d.ts +66 -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 +10 -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-B44o9ggV.mjs +56070 -0
  67. package/dist/{index-D8p2ph99.mjs → index-BF310Wzc.mjs} +401 -263
  68. package/dist/index-BJOPyRJn.js +1 -0
  69. package/dist/index-BiqhUSZ0.js +570 -0
  70. package/dist/index-Cjaia8CY.mjs +4107 -0
  71. package/dist/index-Cu0f4kha.js +570 -0
  72. package/dist/index-DDd-30M7.js +1 -0
  73. package/dist/index-DdbAM7Xi.mjs +4106 -0
  74. package/dist/index-DhCFlEfW.mjs +56062 -0
  75. package/dist/index-mcBiJOLo.mjs +931 -0
  76. package/dist/index-o1TaWHww.js +1 -0
  77. package/dist/index-puxStU6w.js +1 -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 +7 -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 +9 -16
  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,3267 +0,0 @@
1
- var pe = Object.defineProperty;
2
- var de = (C, t, e) => t in C ? pe(C, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : C[t] = e;
3
- var m = (C, t, e) => de(C, typeof t != "symbol" ? t + "" : t, e);
4
- import { D as K, e as W, c as y, r as q, b as g, g as X, t as V, a as h, f as ie, M as ue, h as D, i as Y, j as fe, C as H, k as P, l as me, m as ye, n as ke, o as Se, p as J, q as _, E as N, s as j, u as $, v as we, w as ae, x as ne, T as ee, y as te, z as ve, A as ce, G as le, B as se, F as Te, H as z, V as oe, S as Ie } from "./index-B-tFucpi.mjs";
5
- import { cloneDeep as Z, xor as ge, isNumber as G, isEqual as re } from "lodash";
6
- import "clipper-lib";
7
- import "lineclip";
8
- import "rbush";
9
- import "xss";
10
- import "white-web-sdk";
11
- import "react-dom";
12
- import "react";
13
- class We {
14
- constructor(t) {
15
- m(this, "vNodes");
16
- m(this, "thread");
17
- m(this, "serviceWorkShapes", /* @__PURE__ */ new Map());
18
- m(this, "localWorkShapes", /* @__PURE__ */ new Map());
19
- m(this, "tmpOpt");
20
- m(this, "animationId");
21
- m(this, "syncUnitTime", K.syncOpt.interval);
22
- this.vNodes = t.vNodes, this.thread = t.thread;
23
- }
24
- createLocalWork(t) {
25
- const { workId: e, opt: s, toolsType: o } = t;
26
- if (e && s) {
27
- const r = e.toString();
28
- !this.getToolsOpt() && o && this.setToolsOpt({
29
- toolsType: o,
30
- toolsOpt: s
31
- }), this.setWorkOptions(r, s);
32
- }
33
- }
34
- getLocalWorkShape(t) {
35
- return this.localWorkShapes.get(t);
36
- }
37
- createLocalWorkShape(t, e) {
38
- if (t && this.tmpOpt) {
39
- const s = {
40
- toolsType: this.tmpOpt.toolsType,
41
- toolsOpt: e || this.tmpOpt.toolsOpt
42
- }, o = this.createWorkShapeNode({ ...s, workId: t });
43
- return o && this.localWorkShapes.set(t, {
44
- node: o,
45
- toolsType: o.toolsType,
46
- workState: W.Start
47
- }), o;
48
- }
49
- }
50
- canUseTopLayer(t) {
51
- return t === y.LaserPen;
52
- }
53
- destroy() {
54
- this.clearAll();
55
- }
56
- clearAll() {
57
- this.thread.topLayer.children.length && (this.thread.topLayer.parent.children.forEach((t) => {
58
- t.name !== "viewport" && t.remove();
59
- }), q(
60
- this.thread.serviceLayer,
61
- this.thread.serviceLayer.parent
62
- )), this.serviceWorkShapes.clear(), this.localWorkShapes.clear();
63
- }
64
- consumeDraw(t) {
65
- const { workId: e, dataType: s } = t;
66
- if (s === g.Service)
67
- this.activeServiceWorkShape(t);
68
- else {
69
- const o = e == null ? void 0 : e.toString(), r = o && this.localWorkShapes.get(o);
70
- if (!r)
71
- return;
72
- const i = r.node.consume({
73
- data: t,
74
- isFullWork: !1,
75
- isSubWorker: !0
76
- });
77
- i.rect && (r.result = i, r.workState = W.Doing, o && this.localWorkShapes.set(o, r));
78
- }
79
- this.runAnimation();
80
- }
81
- setToolsOpt(t) {
82
- var e;
83
- this.tmpOpt = t, (e = t.toolsOpt) != null && e.syncUnitTime && (this.syncUnitTime = t.toolsOpt.syncUnitTime);
84
- }
85
- getToolsOpt() {
86
- return this.tmpOpt;
87
- }
88
- createWorkShapeNode(t) {
89
- const { toolsType: e } = t;
90
- if (e === y.LaserPen)
91
- return X({
92
- ...t,
93
- vNodes: this.vNodes,
94
- fullLayer: this.thread.topLayer,
95
- drawLayer: this.thread.topLayer
96
- });
97
- }
98
- setNodeKey(t, e, s, o) {
99
- return e.toolsType = s, e.node = this.createWorkShapeNode({
100
- workId: t,
101
- toolsType: s,
102
- toolsOpt: o
103
- }), e;
104
- }
105
- activeServiceWorkShape(t) {
106
- var k, S;
107
- const { workId: e, opt: s, toolsType: o, type: r, updateNodeOpt: i, ops: c, op: a } = t;
108
- if (!e)
109
- return;
110
- const n = e.toString(), d = (k = this.vNodes.get(n)) == null ? void 0 : k.rect;
111
- if (!((S = this.serviceWorkShapes) != null && S.has(n))) {
112
- let p = {
113
- toolsType: o,
114
- animationWorkData: a || [],
115
- animationIndex: 0,
116
- type: r,
117
- updateNodeOpt: i,
118
- ops: c,
119
- oldRect: d
120
- };
121
- o && s && (p = this.setNodeKey(n, p, o, s)), this.serviceWorkShapes.set(n, p);
122
- }
123
- const l = this.serviceWorkShapes.get(n);
124
- r && (l.type = r), c && (l.animationWorkData = V(c), l.ops = c), i && (l.updateNodeOpt = i), a && (l.animationWorkData = a), l.node && l.node.getWorkId() !== n && l.node.setWorkId(n), d && (l.oldRect = d), o && s && (l.toolsType !== o && o && s && this.setNodeKey(n, l, o, s), l.node && l.node.setWorkOptions(s));
125
- }
126
- computNextAnimationIndex(t, e) {
127
- var r;
128
- const s = ((r = t.node) == null ? void 0 : r.syncUnitTime) || this.syncUnitTime, o = Math.floor(
129
- (t.animationWorkData || []).slice(t.animationIndex).length * 32 / e / s
130
- ) * e;
131
- return Math.min(
132
- (t.animationIndex || 0) + (o || e),
133
- (t.animationWorkData || []).length
134
- );
135
- }
136
- animationDraw() {
137
- var o, r, i, c;
138
- this.animationId = void 0;
139
- let t = !1;
140
- const e = /* @__PURE__ */ new Map(), s = [];
141
- for (const [a, n] of this.serviceWorkShapes.entries())
142
- switch (n.toolsType) {
143
- case y.LaserPen: {
144
- const l = this.computNextAnimationIndex(
145
- n,
146
- 8
147
- ), k = Math.max(0, n.animationIndex || 0), S = (n.animationWorkData || []).slice(
148
- k,
149
- l
150
- );
151
- if ((n.animationIndex || 0) < l && ((o = n.node) == null || o.consumeService({
152
- op: S,
153
- isFullWork: !1
154
- }), n.animationIndex = l, S.length && e.set(a, {
155
- workState: k === 0 ? W.Start : l === ((r = n.animationWorkData) == null ? void 0 : r.length) ? W.Done : W.Doing,
156
- op: S.slice(-2)
157
- })), n.isDel) {
158
- (i = n.node) == null || i.clearTmpPoints(), this.serviceWorkShapes.delete(a);
159
- break;
160
- }
161
- n.ops && n.animationIndex === ((c = n.animationWorkData) == null ? void 0 : c.length) && !n.isDel && (this.thread.topLayer.getElementsByName(
162
- a.toString()
163
- )[0] || (n.isDel = !0, this.serviceWorkShapes.set(a, n))), t = !0;
164
- break;
165
- }
166
- }
167
- for (const [a, n] of this.localWorkShapes.entries()) {
168
- const { result: d, toolsType: l, isDel: k, workState: S } = n;
169
- switch (l) {
170
- case y.LaserPen: {
171
- if (k) {
172
- n.node.clearTmpPoints(), this.localWorkShapes.delete(a), s.push({
173
- removeIds: [a.toString()],
174
- type: h.RemoveNode
175
- });
176
- break;
177
- }
178
- d && ((d.op || d.ops) && s.push(d), n.result = void 0), !this.thread.topLayer.getElementsByName(
179
- a.toString()
180
- )[0] && S === W.Done && (n.isDel = !0, this.localWorkShapes.set(a, n)), t = !0;
181
- break;
182
- }
183
- }
184
- }
185
- t && this.runAnimation(), e.size && e.forEach((a, n) => {
186
- s.push({
187
- type: h.Cursor,
188
- uid: n.split(ie)[0],
189
- op: a.op,
190
- workState: a.workState,
191
- viewId: this.thread.viewId
192
- });
193
- }), s.length && this.thread.post({ sp: s });
194
- }
195
- runAnimation() {
196
- this.animationId || (this.animationId = requestAnimationFrame(this.animationDraw.bind(this)));
197
- }
198
- setWorkOptions(t, e) {
199
- var o;
200
- let s = (o = this.localWorkShapes.get(t)) == null ? void 0 : o.node;
201
- if (!s && this.tmpOpt) {
202
- const { toolsType: r } = this.tmpOpt;
203
- this.tmpOpt.toolsOpt = e, s = this.createWorkShapeNode({ workId: t, toolsType: r, toolsOpt: e }), s && this.localWorkShapes.set(t, {
204
- node: s,
205
- toolsType: r,
206
- workState: W.Start
207
- }), this.setToolsOpt(this.tmpOpt);
208
- }
209
- e != null && e.syncUnitTime || (e.syncUnitTime = this.syncUnitTime), s && s.setWorkOptions(e);
210
- }
211
- consumeDrawAll(t) {
212
- const { workId: e, dataType: s } = t;
213
- if (s === g.Service)
214
- this.activeServiceWorkShape(t);
215
- else {
216
- const o = e == null ? void 0 : e.toString(), r = o && this.localWorkShapes.get(o);
217
- if (!r)
218
- return;
219
- const i = r.node.consumeAll({ data: t });
220
- r.result = i, r.workState = W.Done, o && this.localWorkShapes.set(o, r);
221
- }
222
- this.runAnimation();
223
- }
224
- }
225
- class Le {
226
- constructor(t) {
227
- m(this, "vNodes");
228
- m(this, "thread");
229
- m(this, "workShapes", /* @__PURE__ */ new Map());
230
- m(this, "effectSelectNodeData", /* @__PURE__ */ new Set());
231
- m(this, "batchEraserRemoveNodes", /* @__PURE__ */ new Set());
232
- m(this, "batchEraserWorks", /* @__PURE__ */ new Set());
233
- m(this, "tmpOpt");
234
- m(this, "syncUnitTime", K.syncOpt.interval);
235
- m(this, "fullWorkerDrawCount", 0);
236
- m(this, "drawWorkActiveId");
237
- m(this, "consumeCount", 0);
238
- m(this, "combineDrawActiveId");
239
- m(this, "eraserBatchScheduler", new ue());
240
- this.vNodes = t.vNodes, this.thread = t.thread;
241
- }
242
- async loadImageBitMap(t) {
243
- return await this.thread.loadImageBitMap(t);
244
- }
245
- createLocalWork(t) {
246
- const { workId: e, opt: s, toolsType: o } = t;
247
- if (e && s) {
248
- const r = e.toString();
249
- !this.getToolsOpt() && o && this.setToolsOpt({
250
- toolsType: o,
251
- toolsOpt: s
252
- }), this.setWorkOptions(r, s);
253
- }
254
- }
255
- // async workShapesDone(scenePath: string, serviceWork: SubServiceThread) {
256
- // for (const key of this.workShapes.keys()) {
257
- // await this.consumeDrawAll({
258
- // workId: key,
259
- // scenePath,
260
- // viewId: this.thread.viewId,
261
- // msgType: EPostMessageType.DrawWork,
262
- // dataType: EDataType.Local
263
- // }, serviceWork)
264
- // }
265
- // }
266
- async updateSelector(t) {
267
- var S;
268
- const e = this.workShapes.get(
269
- D
270
- );
271
- if (!((S = e == null ? void 0 : e.selectIds) != null && S.length)) return;
272
- const { callback: s, ...o } = t, { updateSelectorOpt: r, willSerializeData: i, smoothSync: c } = o, a = await (e == null ? void 0 : e.updateSelector({
273
- updateSelectorOpt: r,
274
- selectIds: Z(e.selectIds),
275
- vNodes: this.vNodes,
276
- willSerializeData: i,
277
- worker: this
278
- })), n = /* @__PURE__ */ new Map();
279
- let d;
280
- a != null && a.selectIds && (d = ge(e.selectIds, a.selectIds), a.selectIds.forEach((p) => {
281
- const f = this.vNodes.get(p);
282
- if (f) {
283
- const { toolsType: u, op: v, opt: I } = f;
284
- n.set(p, {
285
- opt: I,
286
- toolsType: u,
287
- ops: (v == null ? void 0 : v.length) && Y(v) || void 0
288
- });
289
- }
290
- }), e.selectIds = a.selectIds);
291
- const l = [], k = s && s({
292
- res: a,
293
- workShapeNode: e,
294
- param: o,
295
- postData: { sp: l },
296
- newServiceStore: n,
297
- smoothSync: c
298
- }) || { sp: l };
299
- d && k.sp.push({
300
- type: h.RemoveNode,
301
- removeIds: d,
302
- viewId: this.thread.viewId
303
- }), k.sp.length && this.thread.post(k);
304
- }
305
- destroy() {
306
- this.eraserBatchScheduler.cancel(), this.clearAll();
307
- }
308
- clearAll() {
309
- if (this.eraserBatchScheduler.cancel(), this.thread.localLayer.children.length && (this.thread.topLayer.parent.children.forEach((e) => {
310
- e.name !== "viewport" && e.remove();
311
- }), q(
312
- this.thread.localLayer,
313
- this.thread.localLayer.parent
314
- )), this.workShapes.get(
315
- D
316
- )) {
317
- const e = [];
318
- e.push({
319
- type: h.Select,
320
- dataType: g.Local,
321
- selectIds: [],
322
- willSyncService: !1
323
- }), this.thread.post({ sp: e });
324
- }
325
- this.workShapes.clear(), this.effectSelectNodeData.clear(), this.batchEraserWorks.clear(), this.batchEraserRemoveNodes.clear();
326
- }
327
- async checkTextActive(t) {
328
- const { op: e, viewId: s, dataType: o } = t;
329
- if (e != null && e.length) {
330
- let r;
331
- for (const i of this.vNodes.curNodeMap.values()) {
332
- const { rect: c, name: a, toolsType: n, opt: d } = i, l = e[0] * this.thread.fullLayer.worldScaling[0] + this.thread.fullLayer.worldPosition[0], k = e[1] * this.thread.fullLayer.worldScaling[1] + this.thread.fullLayer.worldPosition[1];
333
- if (n === y.Text && fe([l, k], c) && d.workState === W.Done) {
334
- r = a;
335
- break;
336
- }
337
- }
338
- r && (await this.blurSelector({
339
- viewId: s,
340
- msgType: h.Select,
341
- dataType: o,
342
- isSync: !0
343
- }), this.thread.post({
344
- sp: [
345
- {
346
- type: h.GetTextActive,
347
- toolsType: y.Text,
348
- workId: r
349
- }
350
- ]
351
- }));
352
- }
353
- }
354
- cursorHover(t) {
355
- const { opt: e, toolsType: s, point: o } = t, r = this.setFullWork({
356
- workId: H,
357
- toolsType: s,
358
- opt: e
359
- });
360
- r && o && r.cursorHover(o);
361
- }
362
- cursorBlur() {
363
- var e;
364
- const t = this.getWorkShape(H);
365
- t && ((e = t.selectIds) != null && e.length) && (t.cursorBlur(), this.clearWorkShapeNodeCache(H)), this.thread.fullLayer.parent.children.forEach((s) => {
366
- s.name === "Cursor_Hover_Id" && s.remove();
367
- });
368
- }
369
- updateFullSelectWork(t) {
370
- var o, r, i, c, a;
371
- const e = this.workShapes.get(
372
- D
373
- ), { selectIds: s } = t;
374
- if (!(s != null && s.length)) {
375
- this.blurSelector(t);
376
- return;
377
- }
378
- if (!e) {
379
- const n = this.setFullWork(t);
380
- !n && t.workId && this.tmpOpt && ((o = this.tmpOpt) == null ? void 0 : o.toolsType) === y.Selector && this.setWorkOptions(
381
- t.workId.toString(),
382
- t.opt || this.tmpOpt.toolsOpt
383
- ), n && this.updateFullSelectWork(t);
384
- return;
385
- }
386
- if (e && (s != null && s.length)) {
387
- const { selectRect: n } = e.updateSelectIds(s), d = [
388
- {
389
- selectorColor: ((r = t.opt) == null ? void 0 : r.strokeColor) || e.selectorColor,
390
- strokeColor: ((i = t.opt) == null ? void 0 : i.strokeColor) || e.strokeColor,
391
- fillColor: ((c = t.opt) == null ? void 0 : c.fillColor) || e.fillColor,
392
- textOpt: ((a = t.opt) == null ? void 0 : a.textOpt) || e.textOpt,
393
- canTextEdit: e.canTextEdit,
394
- canRotate: e.canRotate,
395
- scaleType: e.scaleType,
396
- type: h.Select,
397
- viewId: this.thread.viewId,
398
- dataType: g.Local,
399
- selectIds: s,
400
- selectRect: n,
401
- points: e.getChildrenPoints(),
402
- willSyncService: (t == null ? void 0 : t.willSyncService) || !1,
403
- opt: (t == null ? void 0 : t.willSyncService) && e.getWorkOptions() || void 0,
404
- canLock: e.canLock,
405
- isLocked: e.isLocked,
406
- toolsTypes: e.toolsTypes,
407
- shapeOpt: e.shapeOpt,
408
- thickness: e.thickness,
409
- useStroke: e.useStroke,
410
- strokeType: e.strokeType
411
- }
412
- ];
413
- this.thread.post({ sp: d });
414
- }
415
- }
416
- async removeSelector(t) {
417
- const { willSyncService: e, needUndoTicker: s } = t, o = [], r = [], i = this.workShapes.get(
418
- D
419
- );
420
- if (!i)
421
- return;
422
- const c = i.selectIds && [...i.selectIds] || [];
423
- for (const a of c) {
424
- const n = this.vNodes.get(a);
425
- if (n)
426
- switch (n.toolsType) {
427
- case y.Text: {
428
- o.push({
429
- type: h.TextUpdate,
430
- toolsType: y.Text,
431
- workId: a,
432
- dataType: g.Local
433
- });
434
- break;
435
- }
436
- case y.BackgroundSVG:
437
- o.push({
438
- type: h.BackgroundSVGDelete,
439
- toolsType: y.BackgroundSVG,
440
- workId: a,
441
- dataType: g.Local,
442
- viewId: this.thread.viewId
443
- });
444
- break;
445
- }
446
- this.removeNode(a), r.push(a);
447
- }
448
- r.length && o.push({
449
- type: h.RemoveNode,
450
- removeIds: r,
451
- needUndoTicker: s,
452
- emitEventType: t.emitEventType,
453
- requestId: t.requestId
454
- }), o.push({
455
- type: h.Select,
456
- selectIds: [],
457
- willSyncService: e
458
- }), await this.blurSelector(), s && o.push({
459
- type: h.None,
460
- needUndoTicker: s
461
- }), o.length && this.thread.post({ sp: o });
462
- }
463
- removeWork(t) {
464
- const { workId: e } = t, s = e == null ? void 0 : e.toString();
465
- s && this.removeNode(s);
466
- }
467
- removeNode(t) {
468
- var o;
469
- const e = this.vNodes.get(t);
470
- e && (e.toolsType === y.BackgroundSVG && this.thread.post({
471
- sp: [
472
- {
473
- type: h.BackgroundSVGDelete,
474
- toolsType: y.BackgroundSVG,
475
- workId: t,
476
- dataType: g.Local,
477
- viewId: this.thread.viewId
478
- }
479
- ]
480
- }), (o = this.thread.fullLayer) == null || o.getElementsByName(t).forEach((r) => {
481
- r.remove(), P(r, this.thread.fullLayer.parent);
482
- }), this.vNodes.delete(t)), this.workShapes.has(t) && (this.thread.localLayer.getElementsByName(t).forEach((r) => {
483
- r.remove(), P(r, this.thread.localLayer.parent);
484
- }), this.clearWorkShapeNodeCache(t));
485
- }
486
- setFullWork(t) {
487
- const { workId: e, opt: s, toolsType: o } = t;
488
- if (e && s && o) {
489
- const r = e.toString();
490
- let i;
491
- return e && this.workShapes.has(r) ? (i = this.workShapes.get(r), (i == null ? void 0 : i.toolsType) !== o ? (i == null || i.clearTmpPoints(), this.workShapes.delete(r), i = void 0) : i == null || i.setWorkOptions(s)) : i = this.createWorkShapeNode({
492
- toolsOpt: s,
493
- toolsType: o,
494
- workId: r
495
- }), i || (i = this.createWorkShapeNode({
496
- toolsOpt: s,
497
- toolsType: o,
498
- workId: r
499
- })), i ? (this.workShapes.set(r, i), i) : void 0;
500
- }
501
- }
502
- async consumeFull(t) {
503
- var i, c;
504
- const e = (i = t.workId) == null ? void 0 : i.toString(), s = (c = t.updateNodeOpt) == null ? void 0 : c.eraserGeometryDelta;
505
- if (e && s) {
506
- const a = this.vNodes.get(e), n = t.ops && V(t.ops) || t.op || [];
507
- if (!a || !t.centerPos || !me(
508
- this.vNodes,
509
- e,
510
- s,
511
- a,
512
- { op: n, centerPos: t.centerPos }
513
- )) {
514
- ye(this.vNodes, e);
515
- return;
516
- }
517
- }
518
- const o = this.setFullWork(t), r = t.ops && V(t.ops);
519
- if (o) {
520
- e && t.clearPreviewLocalWork && this.thread.localLayer.getElementsByName(e).forEach((n) => {
521
- n.remove(), P(n, this.thread.localLayer.parent);
522
- }), o.toolsType === y.BackgroundSVG ? o.consumeService({
523
- isFullWork: !0,
524
- replaceId: e
525
- }) : o.toolsType === y.Image ? await o.consumeServiceAsync({
526
- isFullWork: !0,
527
- replaceId: e,
528
- worker: this
529
- }) : o.toolsType === y.Text ? await o.consumeServiceAsync({
530
- isFullWork: !0,
531
- replaceId: e,
532
- boxRect: this.thread.getSceneRect()
533
- }) : o.consumeService({
534
- op: r,
535
- isFullWork: !0,
536
- replaceId: e
537
- }), t != null && t.updateNodeOpt && o.updataOptService(t.updateNodeOpt);
538
- const a = [];
539
- t.workId && this.workShapes.delete(t.workId.toString()), t.willSyncService && a.push({
540
- opt: t.opt,
541
- toolsType: t.toolsType,
542
- type: h.FullWork,
543
- workId: t.workId,
544
- ops: t.ops,
545
- updateNodeOpt: t.updateNodeOpt,
546
- viewId: this.thread.viewId,
547
- needUndoTicker: t.needUndoTicker,
548
- requestId: t.requestId,
549
- emitEventType: t.emitEventType,
550
- scenePath: t.scenePath
551
- }), t.isLockSentEventCursor && a.push({
552
- type: h.None,
553
- isLockSentEventCursor: !0,
554
- scenePath: t.scenePath
555
- }), t.needUndoTicker && a.push({
556
- type: h.None,
557
- needUndoTicker: t.needUndoTicker,
558
- emitEventType: t.emitEventType,
559
- requestId: t.requestId,
560
- scenePath: t.scenePath
561
- }), a.length && this.thread.post({ sp: a });
562
- }
563
- }
564
- async colloctEffectSelectWork(t) {
565
- const e = this.workShapes.get(
566
- D
567
- ), { workId: s, msgType: o } = t;
568
- if (e && s && e.selectIds && e.selectIds.includes(s.toString())) {
569
- o === h.RemoveNode ? e.selectIds = e.selectIds.filter(
570
- (r) => r !== s.toString()
571
- ) : this.effectSelectNodeData.add(t), await this.runEffectSelectWork(!0);
572
- return;
573
- }
574
- return t;
575
- }
576
- async runEffectSelectWork(t) {
577
- var e;
578
- for await (const s of this.effectSelectNodeData.values()) {
579
- const o = this.setFullWork(s);
580
- if (o) {
581
- const r = (e = s.workId) == null ? void 0 : e.toString();
582
- if (o.toolsType === y.BackgroundSVG)
583
- o.consumeService({
584
- isFullWork: !0,
585
- replaceId: r
586
- });
587
- else if (o.toolsType === y.Image)
588
- await o.consumeServiceAsync({
589
- isFullWork: !0,
590
- replaceId: r,
591
- worker: this
592
- });
593
- else if (o.toolsType === y.Text)
594
- await o.consumeServiceAsync({
595
- isFullWork: !0,
596
- replaceId: r,
597
- boxRect: this.thread.getSceneRect()
598
- });
599
- else {
600
- const i = s.ops && V(s.ops);
601
- o.consumeService({
602
- op: i,
603
- isFullWork: !0,
604
- replaceId: r
605
- }), s != null && s.updateNodeOpt && o.updataOptService(s.updateNodeOpt);
606
- }
607
- s.workId && this.workShapes.delete(s.workId.toString());
608
- }
609
- this.effectSelectNodeData.delete(s);
610
- }
611
- this.reRenderSelector(t);
612
- }
613
- hasSelector() {
614
- return this.workShapes.has(D);
615
- }
616
- getSelector() {
617
- return this.workShapes.get(D);
618
- }
619
- reRenderSelector(t = !1) {
620
- var o;
621
- const e = this.workShapes.get(
622
- D
623
- );
624
- if (!e) return;
625
- if (e && !((o = e.selectIds) != null && o.length))
626
- return this.blurSelector();
627
- const s = e.reRenderSelector();
628
- s && this.thread.post({
629
- sp: [
630
- {
631
- type: h.Select,
632
- selectIds: e.selectIds,
633
- selectRect: s,
634
- willSyncService: t,
635
- viewId: this.thread.viewId,
636
- points: e.getChildrenPoints(),
637
- textOpt: e.textOpt,
638
- selectorColor: e.selectorColor,
639
- strokeColor: e.strokeColor,
640
- fillColor: e.fillColor,
641
- canTextEdit: e.canTextEdit,
642
- canRotate: e.canRotate,
643
- scaleType: e.scaleType,
644
- opt: e.getWorkOptions() || void 0,
645
- canLock: e.canLock,
646
- isLocked: e.isLocked,
647
- toolsTypes: e.toolsTypes,
648
- shapeOpt: e.shapeOpt,
649
- thickness: e.thickness,
650
- useStroke: e.useStroke,
651
- strokeType: e.strokeType
652
- }
653
- ]
654
- });
655
- }
656
- async blurSelector(t) {
657
- var o;
658
- const e = this.workShapes.get(
659
- D
660
- ), s = e == null ? void 0 : e.blurSelector();
661
- if (this.clearWorkShapeNodeCache(D), ((o = this.thread.fullLayer) == null ? void 0 : o.parent).children.forEach((r) => {
662
- r.name === D && r.remove();
663
- }), s) {
664
- const r = [];
665
- r.push({
666
- ...s,
667
- isSync: t == null ? void 0 : t.isSync,
668
- scenePath: t == null ? void 0 : t.scenePath
669
- }), this.thread.post({ sp: r });
670
- }
671
- }
672
- clearWorkShapeNodeCache(t) {
673
- var e;
674
- (e = this.getWorkShape(t)) == null || e.clearTmpPoints(), this.workShapes.delete(t);
675
- }
676
- async drawBitMapEraserFull(t, e, s, o) {
677
- const { willUpdateNodes: r, willDeleteNodes: i } = e, c = t.getWorkId(), a = [
678
- ...r ? Array.from(r.keys()).map((d) => String(d)) : [],
679
- ...i ? Array.from(i) : []
680
- ], n = [];
681
- if (o && n.push({
682
- type: h.None,
683
- needUndoTicker: o,
684
- undoScopeIds: a,
685
- undoScopePhase: "finalize"
686
- }), n.push({
687
- type: h.RemoveNode,
688
- removeIds: [c],
689
- eraseTxnId: c,
690
- viewId: this.thread.viewId,
691
- needUndoTicker: o
692
- }), s && n.push({
693
- type: h.None,
694
- isLockSentEventCursor: s
695
- }), r != null && r.size || i != null && i.size) {
696
- if (r != null && r.size)
697
- for (const [d, l] of r)
698
- n.push({
699
- type: h.UpdateNode,
700
- dataType: g.Local,
701
- opt: l.opt,
702
- workId: d,
703
- updateNodeOpt: {
704
- useAnimation: !1
705
- },
706
- eraseTxnId: c,
707
- needUndoTicker: o
708
- });
709
- i != null && i.size && n.push({
710
- type: h.RemoveNode,
711
- removeIds: [...i],
712
- eraseTxnId: c,
713
- viewId: this.thread.viewId,
714
- needUndoTicker: o
715
- });
716
- }
717
- n.length && this.thread.post({ sp: n });
718
- }
719
- drawPencilEraserFull(t, e, s, o) {
720
- const { willNewNodes: r, willDeleteNodes: i } = e, c = t.getWorkId(), a = [
721
- ...r ? Array.from(r.keys()).map((d) => String(d)) : [],
722
- ...i ? Array.from(i) : []
723
- ], n = [];
724
- if (o && a.length && n.push({
725
- type: h.None,
726
- needUndoTicker: o,
727
- undoScopeIds: a
728
- }), n.push({
729
- type: h.RemoveNode,
730
- removeIds: [c],
731
- viewId: this.thread.viewId,
732
- needUndoTicker: o
733
- }), s && n.push({
734
- type: h.None,
735
- isLockSentEventCursor: s
736
- }), r != null && r.size || i != null && i.size) {
737
- if (r != null && r.size)
738
- for (const [d, l] of r)
739
- n.push({
740
- type: h.FullWork,
741
- dataType: g.Local,
742
- toolsType: l.toolsType,
743
- ops: Y(l.op),
744
- opt: l.opt,
745
- workId: d,
746
- updateNodeOpt: {
747
- useAnimation: !1
748
- },
749
- needUndoTicker: o
750
- });
751
- i != null && i.size && n.push({
752
- type: h.RemoveNode,
753
- removeIds: [...i],
754
- viewId: this.thread.viewId,
755
- needUndoTicker: o
756
- });
757
- }
758
- n.length && this.thread.post({ sp: n });
759
- }
760
- drawEraser(t, e, s, o) {
761
- const r = [], i = t.removeIds || [];
762
- o && i.length && r.push({
763
- type: h.None,
764
- collectUndoTicker: o,
765
- undoScopeIds: i,
766
- undoScopePhase: "collect"
767
- }), t.removeIds && r.push({ ...t, needUndoTicker: s, collectUndoTicker: o }), e && r.push({
768
- type: h.None,
769
- isLockSentEventCursor: e
770
- }), s && r.push({
771
- type: h.None,
772
- needUndoTicker: s,
773
- undoScopePhase: "finalize"
774
- }), this.thread.post({ sp: r, consumeCount: this.consumeCount });
775
- }
776
- getWorkShape(t) {
777
- return this.workShapes.get(t);
778
- }
779
- getWorkShapes() {
780
- return this.workShapes;
781
- }
782
- async consumeDraw(t, e) {
783
- const { op: s, workId: o, scenePath: r, postCount: i, smoothSync: c } = t;
784
- if (s != null && s.length && o) {
785
- const a = o.toString(), n = this.workShapes.get(a);
786
- if (!n)
787
- return;
788
- const d = n.toolsType;
789
- if (d === y.LaserPen)
790
- return;
791
- if (this.combineDrawActiveId && this.combineDrawActiveId !== a) {
792
- const l = this.combineDrawActiveId;
793
- this.eraserBatchScheduler.cancel(), this.combineDrawActiveId = void 0, this.consumeDrawAll(
794
- {
795
- workId: l,
796
- scenePath: r,
797
- viewId: this.thread.viewId,
798
- msgType: h.DrawWork,
799
- dataType: g.Local
800
- },
801
- e
802
- );
803
- }
804
- switch (this.drawWorkActiveId && this.drawWorkActiveId !== a && (this.consumeDrawAll(
805
- {
806
- workId: this.drawWorkActiveId,
807
- scenePath: r,
808
- viewId: this.thread.viewId,
809
- msgType: h.DrawWork,
810
- dataType: g.Local
811
- },
812
- e
813
- ), this.drawWorkActiveId = void 0), !this.drawWorkActiveId && a !== D && (this.drawWorkActiveId = a), G(i) && (this.consumeCount = i), d) {
814
- case y.Selector: {
815
- const l = n.consume({
816
- data: t,
817
- isFullWork: !0,
818
- isMainThread: !0
819
- });
820
- this.fullWorkerDrawCount++;
821
- const k = [];
822
- l.type === h.Select && (l.selectIds && e.runReverseSelectWork(l.selectIds), k.push({ ...l, scenePath: r })), await this.thread.fullLayer.parent.prepareRender, this.thread.post({
823
- consumeCount: this.consumeCount,
824
- fullWorkerDrawCount: this.fullWorkerDrawCount,
825
- sp: k
826
- });
827
- break;
828
- }
829
- case y.PencilEraser:
830
- case y.BitMapEraser: {
831
- n.consume({
832
- data: t,
833
- isFullWork: !1,
834
- isMainThread: !0
835
- }), this.fullWorkerDrawCount++, await this.thread.localLayer.parent.prepareRender, this.thread.post({
836
- sp: void 0,
837
- consumeCount: this.consumeCount,
838
- fullWorkerDrawCount: this.fullWorkerDrawCount
839
- }), this.combineDrawActiveId = a, this.eraserBatchScheduler.schedule(() => {
840
- this.drawEraserCombine(
841
- a,
842
- t.needUndoTicker,
843
- t.collectUndoTicker
844
- );
845
- }, ke(this.thread.master.maxCombineEraserTime));
846
- break;
847
- }
848
- case y.Eraser:
849
- {
850
- const l = n.consume({
851
- data: t,
852
- isFullWork: !0
853
- });
854
- await this.thread.fullLayer.parent.prepareRender, this.drawEraser(
855
- l,
856
- void 0,
857
- t.needUndoTicker,
858
- t.collectUndoTicker
859
- );
860
- }
861
- break;
862
- case y.Arrow:
863
- case y.Straight:
864
- case y.Ellipse:
865
- case y.Rectangle:
866
- case y.Star:
867
- case y.Polygon:
868
- case y.SpeechBalloon:
869
- case y.Pencil:
870
- {
871
- const l = n.consume({
872
- data: t,
873
- isFullWork: !1,
874
- isMainThread: !0,
875
- smoothSync: c
876
- });
877
- l && (this.fullWorkerDrawCount++, await this.thread.localLayer.parent.prepareRender, this.thread.post({
878
- consumeCount: this.consumeCount,
879
- fullWorkerDrawCount: this.fullWorkerDrawCount,
880
- sp: l.op && [{ ...l, scenePath: r }] || void 0
881
- }));
882
- }
883
- break;
884
- }
885
- }
886
- }
887
- drawEraserCombine(t, e, s) {
888
- var r, i, c, a, n, d;
889
- const o = (r = this.workShapes.get(t)) == null ? void 0 : r.combineConsume({ workerEngine: this });
890
- if (o) {
891
- const { willDeleteNodes: l, willNewNodes: k } = o, S = [
892
- ...l ? Array.from(l) : []
893
- ], p = {
894
- render: [],
895
- sp: []
896
- };
897
- if (o != null && o.rect) {
898
- const f = Se(o.rect);
899
- (i = p.render) == null || i.push(
900
- {
901
- rect: f,
902
- isClear: !0,
903
- clearCanvas: J.Bg,
904
- viewId: this.thread.viewId
905
- },
906
- {
907
- rect: f,
908
- drawCanvas: J.Bg,
909
- viewId: this.thread.viewId
910
- }
911
- );
912
- }
913
- if (s && S.length && ((c = this.getWorkShape(t)) == null ? void 0 : c.toolsType) === y.BitMapEraser && ((a = p.sp) == null || a.push({
914
- type: h.None,
915
- collectUndoTicker: s,
916
- undoScopeIds: S,
917
- undoScopePhase: "collect"
918
- })), l != null && l.size && ((n = p.sp) == null || n.push({
919
- type: h.RemoveNode,
920
- removeIds: [...l],
921
- viewId: this.thread.viewId,
922
- needUndoTicker: e,
923
- collectUndoTicker: s
924
- })), k != null && k.size)
925
- for (const [f, u] of k)
926
- (d = p.sp) == null || d.push({
927
- type: h.FullWork,
928
- dataType: g.Local,
929
- toolsType: u.toolsType,
930
- ops: Y(u.op),
931
- opt: u.opt,
932
- workId: f,
933
- updateNodeOpt: {
934
- useAnimation: !1
935
- },
936
- needUndoTicker: e,
937
- collectUndoTicker: s
938
- });
939
- this.thread.post(p);
940
- }
941
- }
942
- consumeDrawAll(t, e) {
943
- var c, a, n, d, l, k;
944
- this.eraserBatchScheduler.cancel();
945
- const { workId: s, scenePath: o, isLockSentEventCursor: r } = t, i = t.needUndoTicker;
946
- if (s) {
947
- this.combineDrawActiveId === s.toString() && (this.combineDrawActiveId = void 0);
948
- const S = s.toString();
949
- this.drawWorkActiveId === S && (this.drawWorkActiveId = void 0);
950
- const p = this.workShapes.get(S);
951
- if (!p)
952
- return;
953
- const f = p.toolsType;
954
- if (f === y.LaserPen)
955
- return;
956
- const u = this.workShapes.get(H), v = (c = u == null ? void 0 : u.selectIds) == null ? void 0 : c[0], I = p.consumeAll({ data: t, workerEngine: this });
957
- switch (f) {
958
- case y.Selector:
959
- {
960
- I.selectIds && v && ((a = I.selectIds) != null && a.includes(v)) && u.cursorBlur();
961
- const L = [];
962
- r && L.push({
963
- type: h.None,
964
- isLockSentEventCursor: r,
965
- scenePath: o
966
- }), I.type === h.Select && (I.selectIds && e.runReverseSelectWork(I.selectIds), L.push({ ...I, scenePath: o })), L.length && this.thread.post({ sp: L }), (n = p.selectIds) != null && n.length ? p.clearTmpPoints() : this.clearWorkShapeNodeCache(S);
967
- }
968
- break;
969
- case y.PencilEraser:
970
- this.drawPencilEraserFull(
971
- p,
972
- I,
973
- r,
974
- i
975
- ), this.fullWorkerDrawCount = 0, this.clearWorkShapeNodeCache(S);
976
- break;
977
- case y.BitMapEraser:
978
- this.drawBitMapEraserFull(
979
- p,
980
- I,
981
- r,
982
- i
983
- ), this.fullWorkerDrawCount = 0, this.clearWorkShapeNodeCache(S);
984
- break;
985
- case y.Eraser:
986
- this.drawEraser(
987
- { ...I, scenePath: o },
988
- r,
989
- i,
990
- t.collectUndoTicker
991
- ), p.clearTmpPoints();
992
- break;
993
- case y.Arrow:
994
- case y.Straight:
995
- case y.Ellipse:
996
- case y.Rectangle:
997
- case y.Star:
998
- case y.Polygon:
999
- case y.SpeechBalloon:
1000
- case y.Pencil: {
1001
- const L = [];
1002
- if (r && L.push({
1003
- type: h.None,
1004
- isLockSentEventCursor: r,
1005
- scenePath: o
1006
- }), I) {
1007
- const T = f === y.Pencil, E = T && I.type === h.RemoveNode, R = ((d = I.workId) == null ? void 0 : d.toString()) || ((k = (l = I.removeIds) == null ? void 0 : l[0]) == null ? void 0 : k.toString());
1008
- E ? q(
1009
- this.thread.localLayer,
1010
- this.thread.localLayer.parent
1011
- ) : L.push({
1012
- ...I,
1013
- scenePath: o,
1014
- needUndoTicker: t.needUndoTicker,
1015
- undoScopeIds: T && R ? [R] : I.undoScopeIds,
1016
- undoScopePhase: T ? "finalize" : I.undoScopePhase
1017
- }), this.fullWorkerDrawCount = 0, t.needUndoTicker && L.push({
1018
- type: h.None,
1019
- needUndoTicker: t.needUndoTicker,
1020
- scenePath: o,
1021
- undoScopeIds: E ? [] : void 0,
1022
- undoScopePhase: E ? "finalize" : void 0
1023
- }), (E ? this.thread.localLayer : this.thread.fullLayer).parent.prepareRender.then(() => {
1024
- this.thread.post({
1025
- fullWorkerDrawCount: this.fullWorkerDrawCount,
1026
- sp: L
1027
- });
1028
- });
1029
- }
1030
- this.clearWorkShapeNodeCache(S);
1031
- break;
1032
- }
1033
- }
1034
- }
1035
- }
1036
- getToolsOpt() {
1037
- return this.tmpOpt;
1038
- }
1039
- setToolsOpt(t) {
1040
- var e;
1041
- this.tmpOpt = t, (e = t.toolsOpt) != null && e.syncUnitTime && (this.syncUnitTime = t.toolsOpt.syncUnitTime);
1042
- }
1043
- setWorkOptions(t, e) {
1044
- let s = this.workShapes.get(t);
1045
- if (!s && this.tmpOpt) {
1046
- const { toolsType: o } = this.tmpOpt;
1047
- this.tmpOpt.toolsOpt = e, s = this.createWorkShapeNode({ workId: t, toolsType: o, toolsOpt: e }), s && this.workShapes.set(t, s), this.setToolsOpt(this.tmpOpt);
1048
- }
1049
- e.syncUnitTime || (e.syncUnitTime = this.syncUnitTime), s == null || s.setWorkOptions(e);
1050
- }
1051
- createWorkShapeNode(t) {
1052
- return X(
1053
- {
1054
- ...t,
1055
- vNodes: this.vNodes,
1056
- fullLayer: this.thread.fullLayer,
1057
- drawLayer: this.thread.localLayer
1058
- },
1059
- this.thread.serviceWork
1060
- );
1061
- }
1062
- }
1063
- class Ne {
1064
- constructor(t) {
1065
- m(this, "vNodes");
1066
- m(this, "thread");
1067
- m(this, "workShapes", /* @__PURE__ */ new Map());
1068
- m(this, "selectorWorkShapes", /* @__PURE__ */ new Map());
1069
- m(this, "willRunEffectSelectorIds", /* @__PURE__ */ new Set());
1070
- m(this, "runEffectId");
1071
- m(this, "animationId");
1072
- m(this, "syncUnitTime", K.syncOpt.interval);
1073
- this.vNodes = t.vNodes, this.thread = t.thread;
1074
- }
1075
- async loadImageBitMap(t) {
1076
- return await this.thread.loadImageBitMap(t);
1077
- }
1078
- destroy() {
1079
- this.clearAll();
1080
- }
1081
- clearAll() {
1082
- this.thread.serviceLayer.children.length && (this.thread.serviceLayer.parent.children.forEach((t) => {
1083
- t.name !== "viewport" && t.remove();
1084
- }), q(
1085
- this.thread.serviceLayer,
1086
- this.thread.serviceLayer.parent
1087
- )), this.workShapes.clear(), this.selectorWorkShapes.clear(), this.willRunEffectSelectorIds.clear();
1088
- }
1089
- runEffect() {
1090
- this.runEffectId || (this.runEffectId = setTimeout(
1091
- this.effectRunSelector.bind(this),
1092
- 0
1093
- ));
1094
- }
1095
- effectRunSelector() {
1096
- this.runEffectId = void 0, this.willRunEffectSelectorIds.forEach((t) => {
1097
- var s, o;
1098
- const e = this.selectorWorkShapes.get(t);
1099
- e && e.selectIds && ((s = e.node) == null || s.selectServiceNode(
1100
- t,
1101
- e,
1102
- !0
1103
- )), (o = e == null ? void 0 : e.selectIds) != null && o.length || this.selectorWorkShapes.delete(t);
1104
- }), this.willRunEffectSelectorIds.clear();
1105
- }
1106
- runSelectWork(t) {
1107
- this.activeSelectorShape(t);
1108
- const { workId: e } = t, s = e == null ? void 0 : e.toString();
1109
- s && this.willRunEffectSelectorIds.add(s), this.runEffect();
1110
- }
1111
- removeWork(t) {
1112
- const { workId: e } = t, s = e == null ? void 0 : e.toString();
1113
- if (s) {
1114
- if (this.workShapes.get(s)) {
1115
- this.workShapes.delete(s), this.removeNode(s, t);
1116
- return;
1117
- }
1118
- this.removeNode(s, t);
1119
- }
1120
- }
1121
- consumeFull(t) {
1122
- if (this.activeWorkShape(t), t.refreshTextRender) {
1123
- this.animationId && (cancelAnimationFrame(this.animationId), this.animationId = void 0), this.animationDraw();
1124
- return;
1125
- }
1126
- this.runAnimation();
1127
- }
1128
- runReverseSelectWork(t) {
1129
- t.forEach((e) => {
1130
- this.selectorWorkShapes.forEach((s, o) => {
1131
- var r;
1132
- if ((r = s.selectIds) != null && r.length) {
1133
- const i = s.selectIds.indexOf(e);
1134
- i > -1 && (s.selectIds.splice(i, 1), this.willRunEffectSelectorIds.add(o));
1135
- }
1136
- });
1137
- }), this.willRunEffectSelectorIds.size && this.runEffect();
1138
- }
1139
- consumeDraw(t) {
1140
- this.activeWorkShape(t), this.runAnimation();
1141
- }
1142
- computNextAnimationIndex(t, e) {
1143
- const s = Math.floor(
1144
- (t.animationWorkData || []).slice(t.animationIndex).length * 32 / e / this.syncUnitTime
1145
- ) * e;
1146
- return Math.min(
1147
- (t.animationIndex || 0) + (s || e),
1148
- (t.animationWorkData || []).length
1149
- );
1150
- }
1151
- async animationDraw() {
1152
- var o, r, i, c, a, n, d, l, k, S, p, f, u, v, I, L, T, E, R, B, F;
1153
- this.animationId = void 0;
1154
- let t = !1;
1155
- const e = /* @__PURE__ */ new Map(), s = [];
1156
- for (const [b, w] of this.workShapes.entries())
1157
- switch (w.toolsType) {
1158
- case y.BackgroundSVG: {
1159
- (o = w.node) == null || o.consumeService({
1160
- isFullWork: !0,
1161
- replaceId: b
1162
- }), this.selectorWorkShapes.forEach((M, O) => {
1163
- var A;
1164
- (A = M.selectIds) != null && A.includes(b) && (this.willRunEffectSelectorIds.add(O), this.runEffect());
1165
- }), this.workShapes.delete(b);
1166
- break;
1167
- }
1168
- case y.Image: {
1169
- await ((r = w.node) == null ? void 0 : r.consumeServiceAsync({
1170
- isFullWork: !0,
1171
- worker: this
1172
- })), this.selectorWorkShapes.forEach((M, O) => {
1173
- var A;
1174
- (A = M.selectIds) != null && A.includes(b) && (this.willRunEffectSelectorIds.add(O), this.runEffect());
1175
- }), this.workShapes.delete(b);
1176
- break;
1177
- }
1178
- case y.Text: {
1179
- w.node && (await ((i = w.node) == null ? void 0 : i.consumeServiceAsync({
1180
- isFullWork: !0,
1181
- replaceId: b,
1182
- boxRect: this.thread.getSceneRect()
1183
- })), this.selectorWorkShapes.forEach((M, O) => {
1184
- var A;
1185
- (A = M.selectIds) != null && A.includes(b) && (this.willRunEffectSelectorIds.add(O), this.runEffect());
1186
- }), w.refreshTextRender && w.requestId && s.push({
1187
- type: h.RefreshTextRender,
1188
- requestId: w.requestId,
1189
- workId: b,
1190
- viewId: this.thread.viewId
1191
- }), (c = w.node) == null || c.clearTmpPoints(), this.workShapes.delete(b));
1192
- break;
1193
- }
1194
- case y.Arrow:
1195
- case y.Straight:
1196
- case y.Rectangle:
1197
- case y.Ellipse:
1198
- case y.Star:
1199
- case y.Polygon:
1200
- case y.SpeechBalloon: {
1201
- const M = !!w.ops;
1202
- if ((a = w.animationWorkData) != null && a.length) {
1203
- const O = w.oldRect;
1204
- (n = w.node) == null || n.consumeService({
1205
- op: w.animationWorkData,
1206
- isFullWork: M
1207
- }), M && (this.selectorWorkShapes.forEach((A, U) => {
1208
- var Q;
1209
- (Q = A.selectIds) != null && Q.includes(b) && (this.willRunEffectSelectorIds.add(U), this.runEffect());
1210
- }), (d = w.node) == null || d.clearTmpPoints(), this.workShapes.delete(b)), w.isEnableCursor ? e.set(b, {
1211
- cursorTool: _(w.toolsType),
1212
- workState: O ? w.ops ? W.Done : W.Doing : W.Start,
1213
- op: w.animationWorkData.slice(-3, -1)
1214
- }) : M && !w.useAnimation && ((l = w.updateNodeOpt) != null && l.useAnimation) && e.set(b, {
1215
- cursorTool: _(w.toolsType),
1216
- workState: W.Done,
1217
- op: w.animationWorkData.slice(-3, -1),
1218
- uid: (k = w.updateNodeOpt) == null ? void 0 : k.uid
1219
- }), w.animationWorkData.length = 0;
1220
- }
1221
- break;
1222
- }
1223
- case y.Pencil: {
1224
- if (w.useAnimation) {
1225
- if (w.useAnimation) {
1226
- if (w.isDel) {
1227
- (L = w.node) == null || L.clearTmpPoints(), this.workShapes.delete(b);
1228
- break;
1229
- }
1230
- const M = 3, O = this.computNextAnimationIndex(
1231
- w,
1232
- M
1233
- ), A = w.isDiff ? 0 : Math.max(0, (w.animationIndex || 0) - M), U = (w.animationWorkData || []).slice(
1234
- A,
1235
- O
1236
- ), Q = (E = (T = w.node) == null ? void 0 : T.getWorkId()) == null ? void 0 : E.toString();
1237
- if ((w.animationIndex || 0) < O || w.isDiff) {
1238
- if ((R = w.node) == null || R.consumeService({
1239
- op: U,
1240
- isFullWork: !1
1241
- }), w.animationIndex = O, w.isDiff && (w.isDiff = !1), U.length && w.isEnableCursor) {
1242
- const he = U.slice(-3, -1);
1243
- e.set(b, {
1244
- cursorTool: _(w.toolsType),
1245
- workState: A === 0 ? W.Start : O === ((B = w.animationWorkData) == null ? void 0 : B.length) ? W.Done : W.Doing,
1246
- op: he
1247
- });
1248
- }
1249
- } else w.ops && ((F = w.node) == null || F.consumeService({
1250
- op: w.animationWorkData || [],
1251
- isFullWork: !0,
1252
- replaceId: Q
1253
- }), w.isDel = !0, w.isEnableCursor && e.set(b, {
1254
- cursorTool: _(w.toolsType),
1255
- workState: W.Done,
1256
- op: U.slice(-3, -1)
1257
- }));
1258
- t = !0;
1259
- break;
1260
- }
1261
- } else {
1262
- const M = !!w.ops;
1263
- if ((S = w.node) == null || S.consumeService({
1264
- op: w.animationWorkData || [],
1265
- isFullWork: M,
1266
- replaceId: b
1267
- }), (p = w.node) == null || p.updataOptService(w.updateNodeOpt), M) {
1268
- if (!w.isEnableCursor && ((f = w.updateNodeOpt) != null && f.useAnimation) && ((u = w.animationWorkData) != null && u.length)) {
1269
- const O = w.animationWorkData.slice(-3, -1);
1270
- e.set(b, {
1271
- cursorTool: _(w.toolsType),
1272
- workState: W.Done,
1273
- op: O,
1274
- uid: (v = w.updateNodeOpt) == null ? void 0 : v.uid
1275
- });
1276
- }
1277
- this.selectorWorkShapes.forEach((O, A) => {
1278
- var U;
1279
- (U = O.selectIds) != null && U.includes(b) && (this.willRunEffectSelectorIds.add(A), this.runEffect());
1280
- }), (I = w.node) == null || I.clearTmpPoints(), this.workShapes.delete(b);
1281
- }
1282
- }
1283
- break;
1284
- }
1285
- }
1286
- t && this.runAnimation(), e.size && e.forEach((b, w) => {
1287
- s.push({
1288
- type: h.Cursor,
1289
- uid: b.uid || w.split(ie)[0],
1290
- op: b.op,
1291
- workState: b.workState,
1292
- cursorTool: b.cursorTool,
1293
- viewId: this.thread.viewId
1294
- });
1295
- }), s.length && this.thread.post({ sp: s });
1296
- }
1297
- runAnimation() {
1298
- this.animationId || (this.animationId = requestAnimationFrame(this.animationDraw.bind(this)));
1299
- }
1300
- hasDiffData(t, e, s) {
1301
- const o = t.length;
1302
- if (e.length < o)
1303
- return !0;
1304
- switch (s) {
1305
- case y.Pencil: {
1306
- for (let r = 0; r < o; r += 3)
1307
- if (e[r] !== t[r] || e[r + 1] !== t[r + 1])
1308
- return !0;
1309
- break;
1310
- }
1311
- case y.LaserPen: {
1312
- for (let r = 0; r < o; r += 2)
1313
- if (e[r] !== t[r] || e[r + 1] !== t[r + 1])
1314
- return !0;
1315
- break;
1316
- }
1317
- }
1318
- return !1;
1319
- }
1320
- activeWorkShape(t) {
1321
- var v, I, L, T;
1322
- const {
1323
- workId: e,
1324
- opt: s,
1325
- toolsType: o,
1326
- type: r,
1327
- updateNodeOpt: i,
1328
- ops: c,
1329
- op: a,
1330
- useAnimation: n,
1331
- imageBitmap: d,
1332
- isEnableCursor: l,
1333
- requestId: k,
1334
- refreshTextRender: S
1335
- } = t;
1336
- if (!e)
1337
- return;
1338
- const p = e.toString(), f = (v = this.vNodes.get(p)) == null ? void 0 : v.rect;
1339
- if (!((I = this.workShapes) != null && I.has(p))) {
1340
- let E = {
1341
- toolsType: o,
1342
- animationWorkData: a || [],
1343
- animationIndex: 0,
1344
- type: r,
1345
- updateNodeOpt: i,
1346
- ops: c,
1347
- useAnimation: typeof n < "u" ? n : typeof (i == null ? void 0 : i.useAnimation) < "u" ? i == null ? void 0 : i.useAnimation : !0,
1348
- oldRect: f,
1349
- isDiff: !1,
1350
- imageBitmap: d,
1351
- isEnableCursor: l
1352
- };
1353
- o && s && (E = this.setNodeKey(p, E, o, s)), (L = this.workShapes) == null || L.set(p, E);
1354
- }
1355
- const u = (T = this.workShapes) == null ? void 0 : T.get(p);
1356
- u.isEnableCursor = l, u.requestId = k, u.refreshTextRender = !!S, r && (u.type = r), c && (u.animationWorkData = V(c), u.ops = c), i && (u.updateNodeOpt = i), a && (u.isDiff = this.hasDiffData(
1357
- u.animationWorkData || [],
1358
- a,
1359
- u.toolsType
1360
- ), u.toolsType, y.Pencil, u.animationWorkData = a), u.node && u.node.getWorkId() !== p && u.node.setWorkId(p), f && (u.oldRect = f), o && s && (s.syncUnitTime && (this.syncUnitTime = s.syncUnitTime), u.toolsType !== o && o && s && this.setNodeKey(p, u, o, s), u.node && u.node.setWorkOptions(s)), d && (u.imageBitmap = d);
1361
- }
1362
- removeNode(t, e) {
1363
- t.indexOf(D) > -1 && this.removeSelectWork(e), this.thread.fullLayer.getElementsByName(t).forEach((o) => {
1364
- o.remove(), P(o, this.thread.fullLayer.parent);
1365
- }), this.thread.serviceLayer.getElementsByName(t).forEach((o) => {
1366
- o.remove(), P(o, this.thread.serviceLayer.parent);
1367
- });
1368
- const s = this.vNodes.get(t);
1369
- s && s.toolsType === y.BackgroundSVG && this.thread.post({
1370
- sp: [
1371
- {
1372
- type: h.BackgroundSVGDelete,
1373
- toolsType: y.BackgroundSVG,
1374
- workId: t,
1375
- dataType: g.Service,
1376
- viewId: this.thread.viewId
1377
- }
1378
- ]
1379
- }), this.vNodes.delete(t);
1380
- }
1381
- removeSelectWork(t) {
1382
- const { workId: e } = t, s = e == null ? void 0 : e.toString();
1383
- s && (this.activeSelectorShape(t), this.willRunEffectSelectorIds.add(s)), this.runEffect();
1384
- }
1385
- activeSelectorShape(t) {
1386
- var n, d, l;
1387
- const { workId: e, opt: s, toolsType: o, type: r, selectIds: i } = t;
1388
- if (!e)
1389
- return;
1390
- const c = e.toString();
1391
- if (!((n = this.selectorWorkShapes) != null && n.has(c))) {
1392
- let k = {
1393
- toolsType: o,
1394
- selectIds: i,
1395
- type: r,
1396
- opt: s
1397
- };
1398
- o && s && (k = this.setNodeKey(c, k, o, s)), (d = this.selectorWorkShapes) == null || d.set(c, k);
1399
- }
1400
- const a = (l = this.selectorWorkShapes) == null ? void 0 : l.get(c);
1401
- r && (a.type = r), a.node && a.node.getWorkId() !== c && a.node.setWorkId(c), a.selectIds = i || [];
1402
- }
1403
- setNodeKey(t, e, s, o) {
1404
- return e.toolsType = s, e.node = X(
1405
- {
1406
- toolsType: s,
1407
- toolsOpt: o,
1408
- vNodes: this.vNodes,
1409
- fullLayer: this.thread.fullLayer,
1410
- drawLayer: this.thread.serviceLayer,
1411
- workId: t
1412
- },
1413
- this
1414
- ), e;
1415
- }
1416
- }
1417
- class x {
1418
- constructor() {
1419
- m(this, "localWork");
1420
- m(this, "serviceWork");
1421
- m(this, "threadEngine");
1422
- }
1423
- registerMainThread(t) {
1424
- return this.threadEngine = t, this.localWork = t.localWork, this.serviceWork = t.serviceWork, this;
1425
- }
1426
- }
1427
- class Ee extends x {
1428
- constructor() {
1429
- super(...arguments);
1430
- m(this, "emitEventType", N.CopyNode);
1431
- }
1432
- async consume(e) {
1433
- const { msgType: s, dataType: o, emitEventType: r } = e;
1434
- if (s === h.FullWork && o === g.Local && r === this.emitEventType)
1435
- return this.consumeForLocalWorker(e), !0;
1436
- }
1437
- async consumeForLocalWorker(e) {
1438
- var o;
1439
- const { workId: s } = e;
1440
- s && await ((o = this.localWork) == null ? void 0 : o.consumeFull(e));
1441
- }
1442
- }
1443
- class be extends x {
1444
- constructor() {
1445
- super(...arguments);
1446
- m(this, "emitEventType", N.SetColorNode);
1447
- }
1448
- async consume(e) {
1449
- const { msgType: s, dataType: o, emitEventType: r } = e;
1450
- if (s === h.UpdateNode && o === g.Local && r === this.emitEventType)
1451
- return this.consumeForLocalWorker(e), !0;
1452
- }
1453
- async consumeForLocalWorker(e) {
1454
- var l;
1455
- const {
1456
- workId: s,
1457
- updateNodeOpt: o,
1458
- willRefreshSelector: r,
1459
- willSyncService: i,
1460
- willSerializeData: c,
1461
- textUpdateForWoker: a,
1462
- needUndoTicker: n,
1463
- requestId: d
1464
- } = e;
1465
- s === D && o && await ((l = this.localWork) == null ? void 0 : l.updateSelector({
1466
- updateSelectorOpt: o,
1467
- willRefreshSelector: r,
1468
- willSyncService: i,
1469
- willSerializeData: c,
1470
- emitEventType: this.emitEventType,
1471
- requestId: d,
1472
- textUpdateForWoker: a,
1473
- callback: this.updateSelectorCallback,
1474
- needUndoTicker: n
1475
- }));
1476
- }
1477
- updateSelectorCallback(e) {
1478
- const { param: s, postData: o, newServiceStore: r } = e, {
1479
- willSyncService: i,
1480
- isSync: c,
1481
- textUpdateForWoker: a,
1482
- needUndoTicker: n,
1483
- requestId: d,
1484
- emitEventType: l
1485
- } = s, k = o.sp || [];
1486
- if (i)
1487
- for (const [S, p] of r.entries())
1488
- a && p.toolsType === y.Text ? k.push({
1489
- ...p,
1490
- workId: S,
1491
- type: h.TextUpdate,
1492
- dataType: g.Local,
1493
- willSyncService: !0,
1494
- emitEventType: l,
1495
- requestId: d,
1496
- needUndoTicker: n
1497
- }) : k.push({
1498
- ...p,
1499
- workId: S,
1500
- type: h.UpdateNode,
1501
- updateNodeOpt: {
1502
- useAnimation: !1
1503
- },
1504
- isSync: c,
1505
- emitEventType: l,
1506
- requestId: d,
1507
- needUndoTicker: n
1508
- });
1509
- return n && k.push({
1510
- type: h.None,
1511
- needUndoTicker: n
1512
- }), {
1513
- sp: k
1514
- };
1515
- }
1516
- }
1517
- class Ce extends x {
1518
- constructor() {
1519
- super(...arguments);
1520
- m(this, "emitEventType", N.ZIndexNode);
1521
- }
1522
- async consume(e) {
1523
- const { msgType: s, dataType: o, emitEventType: r } = e;
1524
- if (s === h.UpdateNode && o === g.Local && r === this.emitEventType)
1525
- return this.consumeForLocalWorker(e), !0;
1526
- }
1527
- async consumeForLocalWorker(e) {
1528
- var d;
1529
- const {
1530
- workId: s,
1531
- updateNodeOpt: o,
1532
- willRefreshSelector: r,
1533
- willSyncService: i,
1534
- willSerializeData: c,
1535
- needUndoTicker: a,
1536
- requestId: n
1537
- } = e;
1538
- s === D && o && await ((d = this.localWork) == null ? void 0 : d.updateSelector({
1539
- updateSelectorOpt: o,
1540
- willRefreshSelector: r,
1541
- willSyncService: i,
1542
- willSerializeData: c,
1543
- emitEventType: this.emitEventType,
1544
- requestId: n,
1545
- callback: this.updateSelectorCallback,
1546
- needUndoTicker: a
1547
- }));
1548
- }
1549
- updateSelectorCallback(e) {
1550
- const { param: s, postData: o, newServiceStore: r } = e, {
1551
- willSyncService: i,
1552
- isSync: c,
1553
- needUndoTicker: a,
1554
- requestId: n,
1555
- emitEventType: d
1556
- } = s, l = o.sp || [];
1557
- if (i && l)
1558
- for (const [k, S] of r.entries())
1559
- S.toolsType === y.BackgroundSVG && l.push({
1560
- ...S,
1561
- workId: k,
1562
- type: h.BackgroundSVGUpdate,
1563
- dataType: g.Local,
1564
- updateNodeOpt: {
1565
- useAnimation: !1
1566
- },
1567
- needUndoTicker: a,
1568
- emitEventType: d,
1569
- requestId: n
1570
- }), l.push({
1571
- ...S,
1572
- workId: k,
1573
- type: h.UpdateNode,
1574
- updateNodeOpt: {
1575
- useAnimation: !1
1576
- },
1577
- isSync: c,
1578
- emitEventType: d,
1579
- requestId: n,
1580
- needUndoTicker: a
1581
- });
1582
- return a && l.push({
1583
- type: h.None,
1584
- needUndoTicker: a
1585
- }), {
1586
- sp: l
1587
- };
1588
- }
1589
- }
1590
- class De extends x {
1591
- constructor() {
1592
- super(...arguments);
1593
- m(this, "emitEventType", N.TranslateNode);
1594
- m(this, "updateSelectorCallback", (e) => {
1595
- const { param: s, postData: o, newServiceStore: r, workShapeNode: i, res: c, smoothSync: a } = e, {
1596
- willSyncService: n,
1597
- isSync: d,
1598
- updateSelectorOpt: l,
1599
- textUpdateForWoker: k,
1600
- needUndoTicker: S
1601
- } = s, p = l.workState, f = o.sp || [];
1602
- if (p === W.Start)
1603
- return {
1604
- sp: [
1605
- {
1606
- type: h.SelectorTransform,
1607
- emitEventType: this.emitEventType,
1608
- workState: p
1609
- }
1610
- ],
1611
- render: []
1612
- };
1613
- const u = c == null ? void 0 : c.selectRect;
1614
- if (n) {
1615
- const v = p === W.Done ? S : void 0;
1616
- f.push({
1617
- type: h.Select,
1618
- selectIds: i.selectIds,
1619
- selectRect: u,
1620
- willSyncService: p === W.Done ? !0 : a,
1621
- isSync: !0,
1622
- points: p === W.Done && i.getChildrenPoints() || void 0,
1623
- textOpt: i.textOpt,
1624
- needUndoTicker: v,
1625
- emitEventType: this.emitEventType
1626
- });
1627
- const I = {
1628
- workState: p,
1629
- useAnimation: l.useAnimation || !1
1630
- };
1631
- l.uid && (I.uid = l.uid);
1632
- for (const [L, T] of r.entries())
1633
- T.toolsType === y.BackgroundSVG && f.push({
1634
- ...T,
1635
- workId: L,
1636
- type: h.BackgroundSVGUpdate,
1637
- dataType: g.Local,
1638
- willSyncService: p === W.Done ? !0 : a,
1639
- updateNodeOpt: I,
1640
- needUndoTicker: v,
1641
- emitEventType: this.emitEventType
1642
- }), k && T.toolsType === y.Text ? f.push({
1643
- ...T,
1644
- workId: L,
1645
- type: h.TextUpdate,
1646
- dataType: g.Local,
1647
- willSyncService: p === W.Done ? !0 : a,
1648
- updateNodeOpt: I,
1649
- needUndoTicker: v,
1650
- emitEventType: this.emitEventType
1651
- }) : (a || p === W.Done) && f.push({
1652
- ...T,
1653
- workId: L,
1654
- type: h.UpdateNode,
1655
- updateNodeOpt: {
1656
- ...I,
1657
- eraserGeometryDelta: j(T.opt)
1658
- },
1659
- isSync: d,
1660
- needUndoTicker: v,
1661
- emitEventType: this.emitEventType
1662
- });
1663
- }
1664
- return S && f.push({
1665
- type: h.None,
1666
- needUndoTicker: S
1667
- }), f.push({
1668
- type: h.SelectorTransform,
1669
- emitEventType: this.emitEventType,
1670
- workState: p
1671
- }), {
1672
- sp: f
1673
- };
1674
- });
1675
- }
1676
- async consume(e) {
1677
- const { msgType: s, dataType: o, emitEventType: r } = e;
1678
- if (s === h.UpdateNode && o === g.Local && r === this.emitEventType)
1679
- return await this.consumeForLocalWorker(e), !0;
1680
- }
1681
- async consumeForLocalWorker(e) {
1682
- var k, S;
1683
- const {
1684
- workId: s,
1685
- updateNodeOpt: o,
1686
- willRefreshSelector: r,
1687
- willSyncService: i,
1688
- willSerializeData: c,
1689
- textUpdateForWoker: a,
1690
- emitEventType: n,
1691
- smoothSync: d,
1692
- needUndoTicker: l
1693
- } = e;
1694
- s === D && o && (o.workState === W.Done && (o != null && o.translate) && (o.translate[0] || o.translate[1]) || o.workState !== W.Done ? await ((k = this.localWork) == null ? void 0 : k.updateSelector({
1695
- updateSelectorOpt: o,
1696
- willRefreshSelector: r,
1697
- willSyncService: i,
1698
- willSerializeData: c,
1699
- isSync: !0,
1700
- textUpdateForWoker: a,
1701
- emitEventType: n,
1702
- callback: this.updateSelectorCallback,
1703
- smoothSync: d,
1704
- needUndoTicker: l
1705
- })) : o.workState === W.Done && ((S = this.localWork) == null || S.vNodes.deleteLastTarget()));
1706
- }
1707
- }
1708
- class Re extends x {
1709
- constructor() {
1710
- super(...arguments);
1711
- m(this, "emitEventType", N.ScaleNode);
1712
- m(this, "updateSelectorCallback", (e) => {
1713
- const { param: s, postData: o, workShapeNode: r, res: i, newServiceStore: c, smoothSync: a } = e, { updateSelectorOpt: n, willSyncService: d, needUndoTicker: l } = s, k = n.workState, S = o.sp || [], p = i == null ? void 0 : i.selectRect, f = k === W.Done ? l : void 0;
1714
- if (k === W.Start)
1715
- return {
1716
- sp: [
1717
- {
1718
- type: h.SelectorTransform,
1719
- emitEventType: this.emitEventType,
1720
- workState: k
1721
- }
1722
- ],
1723
- render: []
1724
- };
1725
- if (d) {
1726
- S.push({
1727
- type: h.Select,
1728
- selectIds: r.selectIds,
1729
- selectRect: p,
1730
- willSyncService: k === W.Done ? !0 : a,
1731
- isSync: !0,
1732
- points: k === W.Done && r.getChildrenPoints() || void 0,
1733
- textOpt: r.textOpt
1734
- });
1735
- const u = {
1736
- useAnimation: n.useAnimation || !1
1737
- };
1738
- n.uid && (u.uid = n.uid);
1739
- for (const [v, I] of c.entries())
1740
- I.toolsType === y.BackgroundSVG && S.push({
1741
- ...I,
1742
- workId: v,
1743
- type: h.BackgroundSVGUpdate,
1744
- dataType: g.Local,
1745
- willSyncService: k === W.Done ? !0 : a,
1746
- updateNodeOpt: u,
1747
- needUndoTicker: f,
1748
- emitEventType: this.emitEventType
1749
- }), I.toolsType === y.Text ? S.push({
1750
- ...I,
1751
- workId: v,
1752
- type: h.TextUpdate,
1753
- dataType: g.Local,
1754
- willSyncService: k === W.Done ? !0 : a,
1755
- updateNodeOpt: u,
1756
- needUndoTicker: f,
1757
- emitEventType: this.emitEventType
1758
- }) : (a || k === W.Done) && S.push({
1759
- ...I,
1760
- workId: v,
1761
- type: h.UpdateNode,
1762
- updateNodeOpt: {
1763
- ...u,
1764
- eraserGeometryDelta: j(I.opt)
1765
- },
1766
- isSync: !0,
1767
- needUndoTicker: f,
1768
- emitEventType: this.emitEventType
1769
- });
1770
- }
1771
- return l && S.push({
1772
- type: h.None,
1773
- needUndoTicker: l
1774
- }), S.push({
1775
- type: h.SelectorTransform,
1776
- emitEventType: this.emitEventType,
1777
- workState: k
1778
- }), {
1779
- sp: S
1780
- };
1781
- });
1782
- }
1783
- async consume(e) {
1784
- const { msgType: s, dataType: o, emitEventType: r } = e;
1785
- if (s === h.UpdateNode && o === g.Local && r === this.emitEventType)
1786
- return await this.consumeForLocalWorker(e), !0;
1787
- }
1788
- async consumeForLocalWorker(e) {
1789
- var n;
1790
- const {
1791
- workId: s,
1792
- updateNodeOpt: o,
1793
- willSyncService: r,
1794
- willSerializeData: i,
1795
- smoothSync: c,
1796
- needUndoTicker: a
1797
- } = e;
1798
- s === D && o && await ((n = this.localWork) == null ? void 0 : n.updateSelector({
1799
- updateSelectorOpt: o,
1800
- willSyncService: r,
1801
- willSerializeData: i,
1802
- isSync: !0,
1803
- callback: this.updateSelectorCallback.bind(this),
1804
- smoothSync: c,
1805
- needUndoTicker: a
1806
- }));
1807
- }
1808
- }
1809
- class Oe extends x {
1810
- constructor() {
1811
- super(...arguments);
1812
- m(this, "emitEventType", N.RotateNode);
1813
- m(this, "updateSelectorCallback", (e) => {
1814
- const { param: s, postData: o, workShapeNode: r, res: i, newServiceStore: c, smoothSync: a } = e, {
1815
- updateSelectorOpt: n,
1816
- willSyncService: d,
1817
- willSerializeData: l,
1818
- isSync: k,
1819
- needUndoTicker: S
1820
- } = s, p = n.workState, f = o.sp || [], u = i == null ? void 0 : i.selectRect, v = p === W.Done ? S : void 0;
1821
- if (d) {
1822
- l && p === W.Done && f.push({
1823
- type: h.Select,
1824
- selectIds: r.selectIds,
1825
- selectRect: u,
1826
- willSyncService: p === W.Done ? !0 : a,
1827
- isSync: k,
1828
- points: r.getChildrenPoints()
1829
- });
1830
- const I = {
1831
- useAnimation: n.useAnimation || !1
1832
- };
1833
- if (n.uid && (I.uid = n.uid), a || p === W.Done)
1834
- for (const [L, T] of c.entries())
1835
- f.push({
1836
- ...T,
1837
- workId: L,
1838
- type: h.UpdateNode,
1839
- updateNodeOpt: {
1840
- ...I,
1841
- eraserGeometryDelta: j(T.opt)
1842
- },
1843
- isSync: k,
1844
- needUndoTicker: v,
1845
- emitEventType: this.emitEventType
1846
- });
1847
- }
1848
- return S && f.push({
1849
- type: h.None,
1850
- needUndoTicker: S
1851
- }), f.push({
1852
- type: h.SelectorTransform,
1853
- emitEventType: this.emitEventType,
1854
- workState: p
1855
- }), {
1856
- sp: f
1857
- };
1858
- });
1859
- }
1860
- async consume(e) {
1861
- const { msgType: s, dataType: o, emitEventType: r } = e;
1862
- if (s === h.UpdateNode && o === g.Local && r === this.emitEventType)
1863
- return await this.consumeForLocalWorker(e), !0;
1864
- }
1865
- async consumeForLocalWorker(e) {
1866
- var l;
1867
- const {
1868
- workId: s,
1869
- updateNodeOpt: o,
1870
- willRefreshSelector: r,
1871
- willSyncService: i,
1872
- willSerializeData: c,
1873
- emitEventType: a,
1874
- smoothSync: n,
1875
- needUndoTicker: d
1876
- } = e;
1877
- s === D && o && await ((l = this.localWork) == null ? void 0 : l.updateSelector({
1878
- updateSelectorOpt: o,
1879
- willRefreshSelector: r,
1880
- willSyncService: i,
1881
- willSerializeData: c,
1882
- emitEventType: a,
1883
- isSync: !0,
1884
- callback: this.updateSelectorCallback,
1885
- smoothSync: n,
1886
- needUndoTicker: d
1887
- }));
1888
- }
1889
- }
1890
- class Me extends x {
1891
- constructor() {
1892
- super(...arguments);
1893
- m(this, "emitEventType", N.SetFontStyle);
1894
- }
1895
- async consume(e) {
1896
- const { msgType: s, dataType: o, emitEventType: r } = e;
1897
- if (s === h.UpdateNode && o === g.Local && r === this.emitEventType)
1898
- return await this.consumeForLocalWorker(e), !0;
1899
- }
1900
- async consumeForLocalWorker(e) {
1901
- var d;
1902
- const {
1903
- workId: s,
1904
- updateNodeOpt: o,
1905
- willRefreshSelector: r,
1906
- willSyncService: i,
1907
- willSerializeData: c,
1908
- textUpdateForWoker: a,
1909
- requestId: n
1910
- } = e;
1911
- s === D && o && await ((d = this.localWork) == null ? void 0 : d.updateSelector({
1912
- updateSelectorOpt: o,
1913
- willRefreshSelector: r,
1914
- willSyncService: i,
1915
- willSerializeData: c,
1916
- emitEventType: this.emitEventType,
1917
- requestId: n,
1918
- textUpdateForWoker: a,
1919
- callback: this.updateSelectorCallback
1920
- }));
1921
- }
1922
- updateSelectorCallback(e) {
1923
- const { param: s, postData: o, newServiceStore: r, workShapeNode: i, res: c } = e, {
1924
- willSyncService: a,
1925
- isSync: n,
1926
- updateSelectorOpt: d,
1927
- textUpdateForWoker: l,
1928
- requestId: k,
1929
- emitEventType: S
1930
- } = s, p = o.sp || [], f = c == null ? void 0 : c.selectRect;
1931
- if (a && p) {
1932
- d.fontSize && p.push({
1933
- type: h.Select,
1934
- selectIds: i.selectIds,
1935
- selectRect: f,
1936
- willSyncService: a,
1937
- isSync: n,
1938
- points: i.getChildrenPoints()
1939
- });
1940
- for (const [u, v] of r.entries())
1941
- l && v.toolsType === y.Text ? p.push({
1942
- ...v,
1943
- workId: u,
1944
- type: h.TextUpdate,
1945
- dataType: g.Local,
1946
- willSyncService: !0,
1947
- emitEventType: S,
1948
- requestId: k
1949
- }) : p.push({
1950
- ...v,
1951
- workId: u,
1952
- type: h.UpdateNode,
1953
- updateNodeOpt: {
1954
- useAnimation: !1
1955
- },
1956
- isSync: n,
1957
- emitEventType: S,
1958
- requestId: k
1959
- });
1960
- }
1961
- return {
1962
- sp: p
1963
- };
1964
- }
1965
- }
1966
- class Ae extends x {
1967
- constructor() {
1968
- super(...arguments);
1969
- m(this, "emitEventType", N.SetPoint);
1970
- m(this, "updateSelectorCallback", (e) => {
1971
- const { param: s, postData: o, newServiceStore: r, workShapeNode: i, res: c } = e, { willSyncService: a, isSync: n, needUndoTicker: d } = s, l = o.sp || [], k = c == null ? void 0 : c.selectRect;
1972
- if (a && l) {
1973
- for (const [S, p] of r.entries())
1974
- l.push({
1975
- ...p,
1976
- workId: S,
1977
- type: h.UpdateNode,
1978
- updateNodeOpt: {
1979
- useAnimation: !1
1980
- },
1981
- isSync: n,
1982
- needUndoTicker: d,
1983
- emitEventType: this.emitEventType
1984
- });
1985
- l.push({
1986
- type: h.Select,
1987
- selectIds: i.selectIds,
1988
- selectRect: k,
1989
- willSyncService: a,
1990
- isSync: n,
1991
- points: i.getChildrenPoints()
1992
- });
1993
- }
1994
- return d && l.push({
1995
- type: h.None,
1996
- needUndoTicker: d
1997
- }), l.push({
1998
- type: h.SelectorTransform,
1999
- emitEventType: this.emitEventType,
2000
- workState: s.updateSelectorOpt.workState
2001
- }), {
2002
- sp: l
2003
- };
2004
- });
2005
- }
2006
- async consume(e) {
2007
- const { msgType: s, dataType: o, emitEventType: r } = e;
2008
- if (s === h.UpdateNode && o === g.Local && r === this.emitEventType)
2009
- return this.consumeForLocalWorker(e), !0;
2010
- }
2011
- async consumeForLocalWorker(e) {
2012
- var d;
2013
- const {
2014
- workId: s,
2015
- updateNodeOpt: o,
2016
- willRefreshSelector: r,
2017
- willSyncService: i,
2018
- willSerializeData: c,
2019
- textUpdateForWoker: a,
2020
- needUndoTicker: n
2021
- } = e;
2022
- s === D && o && await ((d = this.localWork) == null ? void 0 : d.updateSelector({
2023
- updateSelectorOpt: o,
2024
- willRefreshSelector: r,
2025
- willSyncService: i,
2026
- emitEventType: this.emitEventType,
2027
- willSerializeData: c,
2028
- isSync: !0,
2029
- textUpdateForWoker: a,
2030
- callback: this.updateSelectorCallback,
2031
- needUndoTicker: n
2032
- }));
2033
- }
2034
- }
2035
- class xe extends x {
2036
- constructor() {
2037
- super(...arguments);
2038
- m(this, "emitEventType", N.SetLock);
2039
- }
2040
- async consume(e) {
2041
- const { msgType: s, dataType: o, emitEventType: r } = e;
2042
- if (s === h.UpdateNode && o === g.Local && r === this.emitEventType)
2043
- return this.consumeForLocalWorker(e), !0;
2044
- }
2045
- async consumeForLocalWorker(e) {
2046
- var d;
2047
- const {
2048
- workId: s,
2049
- updateNodeOpt: o,
2050
- willRefreshSelector: r,
2051
- willSyncService: i,
2052
- willSerializeData: c,
2053
- needUndoTicker: a,
2054
- requestId: n
2055
- } = e;
2056
- s === D && o && await ((d = this.localWork) == null ? void 0 : d.updateSelector({
2057
- updateSelectorOpt: o,
2058
- willRefreshSelector: r,
2059
- willSyncService: i,
2060
- willSerializeData: c,
2061
- emitEventType: this.emitEventType,
2062
- requestId: n,
2063
- callback: this.updateSelectorCallback,
2064
- needUndoTicker: a
2065
- }));
2066
- }
2067
- updateSelectorCallback(e) {
2068
- const { param: s, postData: o, newServiceStore: r, workShapeNode: i, res: c } = e, {
2069
- willSyncService: a,
2070
- isSync: n,
2071
- updateSelectorOpt: d,
2072
- needUndoTicker: l,
2073
- requestId: k,
2074
- emitEventType: S
2075
- } = s, p = o.sp || [], f = c == null ? void 0 : c.selectRect;
2076
- if (a && p) {
2077
- for (const [u, v] of r.entries())
2078
- p.push({
2079
- ...v,
2080
- workId: u,
2081
- type: h.UpdateNode,
2082
- updateNodeOpt: {
2083
- useAnimation: !1
2084
- },
2085
- isSync: n,
2086
- emitEventType: S,
2087
- requestId: k
2088
- });
2089
- p.push({
2090
- isLocked: d.isLocked,
2091
- selectorColor: i.selectorColor,
2092
- scaleType: i.scaleType,
2093
- canRotate: i.canRotate,
2094
- type: h.Select,
2095
- selectIds: i.selectIds,
2096
- selectRect: f,
2097
- willSyncService: a,
2098
- isSync: n
2099
- });
2100
- }
2101
- return l && p.push({
2102
- type: h.None,
2103
- needUndoTicker: l
2104
- }), {
2105
- sp: p
2106
- };
2107
- }
2108
- }
2109
- class Be extends x {
2110
- constructor() {
2111
- super(...arguments);
2112
- m(this, "emitEventType", N.SetShapeOpt);
2113
- }
2114
- async consume(e) {
2115
- const { msgType: s, dataType: o, emitEventType: r } = e;
2116
- if (s === h.UpdateNode && o === g.Local && r === this.emitEventType)
2117
- return this.consumeForLocalWorker(e), !0;
2118
- }
2119
- async consumeForLocalWorker(e) {
2120
- var d;
2121
- const {
2122
- workId: s,
2123
- updateNodeOpt: o,
2124
- willRefreshSelector: r,
2125
- willSyncService: i,
2126
- willSerializeData: c,
2127
- needUndoTicker: a,
2128
- requestId: n
2129
- } = e;
2130
- s === D && o && await ((d = this.localWork) == null ? void 0 : d.updateSelector({
2131
- updateSelectorOpt: o,
2132
- willRefreshSelector: r,
2133
- willSyncService: i,
2134
- willSerializeData: c,
2135
- emitEventType: this.emitEventType,
2136
- requestId: n,
2137
- callback: this.updateSelectorCallback,
2138
- needUndoTicker: a
2139
- }));
2140
- }
2141
- updateSelectorCallback(e) {
2142
- const { param: s, postData: o, newServiceStore: r } = e, {
2143
- willSyncService: i,
2144
- isSync: c,
2145
- needUndoTicker: a,
2146
- requestId: n,
2147
- emitEventType: d
2148
- } = s, l = o.sp || [];
2149
- if (i && l)
2150
- for (const [k, S] of r.entries())
2151
- l.push({
2152
- ...S,
2153
- workId: k,
2154
- type: h.UpdateNode,
2155
- updateNodeOpt: {
2156
- useAnimation: !1
2157
- },
2158
- isSync: c,
2159
- emitEventType: d,
2160
- requestId: n
2161
- });
2162
- return a && l.push({
2163
- type: h.None,
2164
- needUndoTicker: a
2165
- }), {
2166
- sp: l
2167
- };
2168
- }
2169
- }
2170
- class Fe {
2171
- constructor(t) {
2172
- m(this, "builders", /* @__PURE__ */ new Map());
2173
- this.builders = new Map(t.map((e) => [e, this.build(e)]));
2174
- }
2175
- build(t) {
2176
- switch (t) {
2177
- case N.TranslateNode:
2178
- return new De();
2179
- case N.ZIndexNode:
2180
- return new Ce();
2181
- case N.CopyNode:
2182
- return new Ee();
2183
- case N.SetColorNode:
2184
- return new be();
2185
- case N.ScaleNode:
2186
- return new Re();
2187
- case N.RotateNode:
2188
- return new Oe();
2189
- case N.SetFontStyle:
2190
- return new Me();
2191
- case N.SetPoint:
2192
- return new Ae();
2193
- case N.SetLock:
2194
- return new xe();
2195
- case N.SetShapeOpt:
2196
- return new Be();
2197
- }
2198
- }
2199
- registerForMainThread(t) {
2200
- return this.builders.forEach((e) => {
2201
- e && e.registerMainThread(t);
2202
- }), this;
2203
- }
2204
- async consumeForMainThread(t) {
2205
- for (const e of this.builders.values())
2206
- if (await (e == null ? void 0 : e.consume(t)))
2207
- return !0;
2208
- return !1;
2209
- }
2210
- }
2211
- function Ue({
2212
- subThreads: C,
2213
- layers: t,
2214
- scene: e,
2215
- removeLayerTexture: s
2216
- }) {
2217
- for (const o of C)
2218
- o.destroy();
2219
- for (const o of t) {
2220
- const r = o.parent;
2221
- r && s(o, r), o.remove();
2222
- }
2223
- e.remove();
2224
- }
2225
- class Pe {
2226
- constructor(t, e) {
2227
- m(this, "viewId");
2228
- m(this, "fullLayer");
2229
- m(this, "topLayer");
2230
- m(this, "localLayer");
2231
- m(this, "serviceLayer");
2232
- m(this, "snapshotFullLayer");
2233
- m(this, "vNodes");
2234
- m(this, "master");
2235
- m(this, "opt");
2236
- m(this, "cameraOpt");
2237
- m(this, "scene");
2238
- m(this, "localWork");
2239
- m(this, "serviceWork");
2240
- m(this, "topWork");
2241
- m(this, "taskUpdateCameraId");
2242
- m(this, "taskUpdateCameraResolve");
2243
- m(this, "debounceUpdateCameraId");
2244
- m(this, "debounceUpdateCache", /* @__PURE__ */ new Set());
2245
- m(this, "mainThreadPostId");
2246
- m(this, "destroyed", !1);
2247
- m(this, "combinePostMsg", /* @__PURE__ */ new Set());
2248
- m(this, "methodBuilder");
2249
- m(this, "cacheImages", /* @__PURE__ */ new Map());
2250
- m(this, "imageResolveMap", /* @__PURE__ */ new Map());
2251
- this.viewId = t, this.opt = e, this.scene = this.createScene({
2252
- ...e.canvasOpt,
2253
- container: e.container
2254
- }), this.master = e.master;
2255
- const s = K.bufferSize.full, o = K.bufferSize.sub;
2256
- this.fullLayer = this.createLayer("fullLayer", this.scene, {
2257
- ...e.layerOpt,
2258
- bufferSize: this.viewId === $ ? s : o * 2
2259
- }), this.topLayer = this.createLayer("topLayer", this.scene, {
2260
- ...e.layerOpt,
2261
- bufferSize: (this.viewId === $, o),
2262
- contextType: "2d"
2263
- }), this.localLayer = this.createLayer("localLayer", this.scene, {
2264
- ...e.layerOpt,
2265
- bufferSize: (this.viewId === $, o),
2266
- contextType: "2d"
2267
- }), this.serviceLayer = this.createLayer("serviceLayer", this.scene, {
2268
- ...e.layerOpt,
2269
- bufferSize: (this.viewId === $, o),
2270
- contextType: "2d"
2271
- }), this.vNodes = new we(t, this.scene);
2272
- const r = {
2273
- thread: this,
2274
- vNodes: this.vNodes
2275
- };
2276
- this.localWork = new Le(r), this.serviceWork = new Ne(r), this.topWork = new We(r), this.vNodes.init(this.fullLayer), this.methodBuilder = new Fe([
2277
- N.CopyNode,
2278
- N.SetColorNode,
2279
- N.DeleteNode,
2280
- N.RotateNode,
2281
- N.ScaleNode,
2282
- N.TranslateNode,
2283
- N.ZIndexNode,
2284
- N.SetFontStyle,
2285
- N.SetPoint,
2286
- N.SetLock,
2287
- N.SetShapeOpt
2288
- ]).registerForMainThread(this);
2289
- }
2290
- getCachedImages(t) {
2291
- var e;
2292
- return (e = this.cacheImages.get(t)) == null ? void 0 : e.imageSource;
2293
- }
2294
- getCachedImagesByWorkId(t) {
2295
- for (const [e, s] of this.cacheImages.entries())
2296
- if (e === t && s.imageSource)
2297
- return s.imageSource;
2298
- }
2299
- deleteCachedImagesByWorkId(t) {
2300
- for (const [e, s] of this.cacheImages.entries())
2301
- s.workId === t && ("close" in s.imageSource && s.imageSource.close(), this.cacheImages.delete(e));
2302
- }
2303
- clearCacheImages() {
2304
- this.cacheImages.forEach((t) => {
2305
- "close" in t.imageSource && t.imageSource.close();
2306
- }), this.cacheImages.clear();
2307
- }
2308
- clearImageResolveMap() {
2309
- this.imageResolveMap.forEach(({ timer: t }) => {
2310
- t && clearTimeout(t);
2311
- }), this.imageResolveMap.clear();
2312
- }
2313
- post(t) {
2314
- this.combinePostMsg.add(t), this.runBatchPostData();
2315
- }
2316
- updateDpr(t) {
2317
- this.scene.displayRatio = t;
2318
- }
2319
- async on(t) {
2320
- if (!await this.methodBuilder.consumeForMainThread(t)) {
2321
- const {
2322
- msgType: e,
2323
- toolsType: s,
2324
- opt: o,
2325
- dataType: r,
2326
- workId: i,
2327
- workState: c,
2328
- imageSrc: a,
2329
- imageBitmap: n,
2330
- imageElement: d,
2331
- workIds: l,
2332
- isLockSentEventCursor: k
2333
- } = t, S = i == null ? void 0 : i.toString();
2334
- switch (e) {
2335
- case h.UpdateDpr:
2336
- G(t.dpr) && this.updateDpr(t.dpr);
2337
- break;
2338
- case h.AuthClear: {
2339
- const { clearUids: p, localUid: f } = t;
2340
- this.vNodes.setCanClearUids(p), this.vNodes.setLocalUid(f);
2341
- break;
2342
- }
2343
- case h.Destroy:
2344
- this.destroy();
2345
- break;
2346
- case h.Clear:
2347
- this.clearAll();
2348
- break;
2349
- case h.UpdateCamera:
2350
- await this.updateCamera(t);
2351
- break;
2352
- case h.UpdateTools:
2353
- if (s && o) {
2354
- const p = {
2355
- toolsType: s,
2356
- toolsOpt: o
2357
- };
2358
- this.topWork.canUseTopLayer(s) ? this.topWork.setToolsOpt(p) : this.localWork.setToolsOpt(p);
2359
- }
2360
- break;
2361
- case h.CreateWork:
2362
- if (S && o && s) {
2363
- if (this.topWork.canUseTopLayer(s)) {
2364
- this.topWork.getToolsOpt() || this.topWork.setToolsOpt({
2365
- toolsType: s,
2366
- toolsOpt: o
2367
- }), this.topWork.setWorkOptions(S, o);
2368
- break;
2369
- }
2370
- this.localWork.getToolsOpt() || this.localWork.setToolsOpt({
2371
- toolsType: s,
2372
- toolsOpt: o
2373
- }), this.localWork.setWorkOptions(S, o);
2374
- }
2375
- break;
2376
- case h.DrawWork:
2377
- c === W.Done && r === g.Local ? (this.consumeDrawAll(r, t), s === y.LaserPen && k && this.post({
2378
- sp: [
2379
- {
2380
- type: h.None,
2381
- isLockSentEventCursor: k
2382
- }
2383
- ]
2384
- })) : await this.consumeDraw(r, t);
2385
- break;
2386
- case h.UpdateNode:
2387
- case h.FullWork:
2388
- if (s && this.topWork.canUseTopLayer(s)) {
2389
- this.consumeDrawAll(r, t);
2390
- break;
2391
- }
2392
- this.consumeFull(r, t);
2393
- break;
2394
- case h.RemoveNode:
2395
- await this.removeNode(t);
2396
- return;
2397
- case h.Select:
2398
- r === g.Service && (i === D ? this.localWork.updateFullSelectWork(t) : this.serviceWork.runSelectWork(t));
2399
- break;
2400
- case h.CursorBlur:
2401
- this.localWork.cursorBlur();
2402
- return;
2403
- case h.CursorHover:
2404
- this.localWork.cursorHover(t);
2405
- break;
2406
- case h.GetTextActive:
2407
- r === g.Local && this.localWork.checkTextActive(t);
2408
- break;
2409
- case h.GetImageBitMap:
2410
- if (a && (n || d) && i) {
2411
- const p = i.toString();
2412
- this.deleteCachedImagesByWorkId(p), this.cacheImages.set(a, {
2413
- imageSource: n || d,
2414
- workId: p
2415
- });
2416
- const f = this.imageResolveMap.get(a);
2417
- if (f) {
2418
- const { resolve: u, timer: v } = f;
2419
- v && clearTimeout(v), u && u(a);
2420
- }
2421
- }
2422
- break;
2423
- case h.GetVNodeInfo:
2424
- if (i && l) {
2425
- const p = l.map((f) => this.vNodes.get(f));
2426
- this.post({
2427
- sp: [
2428
- {
2429
- type: h.GetVNodeInfo,
2430
- dataType: g.Local,
2431
- workId: i,
2432
- vInfo: p
2433
- }
2434
- ]
2435
- });
2436
- }
2437
- break;
2438
- }
2439
- }
2440
- }
2441
- getIconSize(t, e, s) {
2442
- const o = t * s, r = e * s;
2443
- return o <= 50 || r <= 50 ? [50, 50] : o <= 100 || r <= 100 ? [100, 100] : o <= 200 || r <= 200 ? [200, 200] : o <= 400 || r <= 400 ? [400, 400] : o <= 800 || r <= 800 ? [800, 800] : [1600, 1600];
2444
- }
2445
- async loadImageBitMap(t) {
2446
- const { toolsType: e, opt: s, workId: o } = t;
2447
- if (e === y.Image && s && o) {
2448
- const r = o.toString(), { src: i, type: c, width: a, height: n, strokeColor: d } = s;
2449
- if (!i || !c || !a || !n)
2450
- return;
2451
- let l = i;
2452
- if (c === ae.Iconify) {
2453
- const [f, u] = this.getIconSize(a, n, this.opt.displayer.dpr);
2454
- l = ne(i, f, u, d);
2455
- }
2456
- if (this.cacheImages.has(l)) {
2457
- const f = this.getCachedImages(l);
2458
- if (f)
2459
- return f;
2460
- }
2461
- if (this.imageResolveMap.has(l)) {
2462
- const f = this.getCachedImagesByWorkId(r);
2463
- if (f)
2464
- return f;
2465
- }
2466
- const p = await new Promise((f) => {
2467
- const u = this.imageResolveMap.get(l) || {
2468
- resolve: void 0,
2469
- timer: void 0
2470
- };
2471
- u.timer && clearTimeout(u.timer), u.resolve = f, u.timer = setTimeout(() => {
2472
- const v = this.imageResolveMap.get(l);
2473
- v != null && v.resolve && v.resolve(l);
2474
- }, 5e3), this.imageResolveMap.set(l, u), this.opt.post({
2475
- sp: [
2476
- {
2477
- imageSrc: l,
2478
- workId: r,
2479
- viewId: this.viewId,
2480
- isgl: !!this.fullLayer.parent.gl,
2481
- isSubWorker: !1,
2482
- type: h.GetImageBitMap
2483
- }
2484
- ]
2485
- });
2486
- });
2487
- return this.imageResolveMap.delete(p), this.getCachedImages(l);
2488
- }
2489
- }
2490
- async removeNode(t) {
2491
- const { dataType: e, workId: s, removeIds: o } = t, r = o || [];
2492
- if (s && r.push(s.toString()), r.length)
2493
- for (const i of r) {
2494
- if (i === D) {
2495
- await this.localWork.removeSelector(t);
2496
- continue;
2497
- }
2498
- e === g.Local ? this.localWork.removeWork(t) : e === g.Service && this.serviceWork.removeWork(t), await this.localWork.colloctEffectSelectWork(t);
2499
- }
2500
- }
2501
- async consumeFull(t, e) {
2502
- const s = await this.localWork.colloctEffectSelectWork(e);
2503
- s && t === g.Local && await this.localWork.consumeFull(s), s && t === g.Service && this.serviceWork.consumeFull(s);
2504
- }
2505
- setCameraOpt(t) {
2506
- this.cameraOpt = t;
2507
- const { scale: e, centerX: s, centerY: o, width: r, height: i } = t;
2508
- (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]);
2509
- }
2510
- runBatchPostData() {
2511
- this.mainThreadPostId || (this.mainThreadPostId = requestAnimationFrame(
2512
- this.combinePost.bind(this)
2513
- ));
2514
- }
2515
- combinePostData() {
2516
- var o;
2517
- this.mainThreadPostId = void 0;
2518
- const t = [];
2519
- let e, s;
2520
- for (const r of this.combinePostMsg.values()) {
2521
- if ((o = r.sp) != null && o.length)
2522
- for (const i of r.sp) {
2523
- let c = !1;
2524
- for (const a of t)
2525
- if (re(i, a)) {
2526
- c = !0;
2527
- break;
2528
- }
2529
- c || t.push(i);
2530
- }
2531
- G(r.fullWorkerDrawCount) && (e = r.fullWorkerDrawCount), G(r.consumeCount) && (s = r.consumeCount);
2532
- }
2533
- return this.combinePostMsg.clear(), {
2534
- sp: t,
2535
- fullWorkerDrawCount: e,
2536
- consumeCount: s
2537
- };
2538
- }
2539
- combinePost() {
2540
- var s, o;
2541
- const t = this.combinePostData(), e = (s = t.sp) == null ? void 0 : s.filter(
2542
- (r) => r.type !== h.None || r.isLockSentEventCursor || r.needUndoTicker || r.collectUndoTicker
2543
- );
2544
- e != null && e.length ? t.sp = e.map((r) => r.viewId ? r : { ...r, viewId: this.viewId }) : delete t.sp, t.consumeCount === void 0 && delete t.consumeCount, t.fullWorkerDrawCount === void 0 && delete t.fullWorkerDrawCount, (t != null && t.consumeCount || t != null && t.fullWorkerDrawCount || (o = t.sp) != null && o.length) && this.opt.post(t);
2545
- }
2546
- clearAll() {
2547
- this.fullLayer.children.length && (this.fullLayer.parent.children.forEach((t) => {
2548
- t.name !== "viewport" && t.remove();
2549
- }), q(this.fullLayer, this.fullLayer.parent)), this.clearCacheImages(), this.clearImageResolveMap(), this.localWork.clearAll(), this.topWork.clearAll(), this.serviceWork.clearAll(), this.vNodes.clear(), this.post({
2550
- sp: [
2551
- {
2552
- type: h.Clear
2553
- }
2554
- ]
2555
- });
2556
- }
2557
- consumeDrawAll(t, e) {
2558
- const { toolsType: s, workId: o } = e;
2559
- if (o) {
2560
- const r = o.toString();
2561
- if (s && this.topWork.canUseTopLayer(s)) {
2562
- t === g.Local && (this.topWork.getLocalWorkShape(
2563
- o.toString()
2564
- ) || this.topWork.createLocalWork(e)), this.topWork.consumeDrawAll(e);
2565
- return;
2566
- }
2567
- t === g.Local && (this.localWork.getWorkShape(r) || this.localWork.createLocalWork(e), this.localWork.consumeDrawAll(e, this.serviceWork));
2568
- }
2569
- }
2570
- async consumeDraw(t, e) {
2571
- const { opt: s, workId: o, toolsType: r } = e;
2572
- if (o && r && s) {
2573
- const i = o.toString();
2574
- if (this.topWork.canUseTopLayer(r)) {
2575
- t === g.Local && (this.topWork.getLocalWorkShape(i) || this.topWork.createLocalWork(e)), this.topWork.consumeDraw(e);
2576
- return;
2577
- }
2578
- t === g.Local ? (this.localWork.getWorkShape(i) || this.localWork.createLocalWork(e), await this.localWork.consumeDraw(e, this.serviceWork)) : t === g.Service && this.serviceWork.consumeDraw(e);
2579
- return;
2580
- }
2581
- }
2582
- async updateCamera(t) {
2583
- var c, a;
2584
- const { cameraOpt: e, scenePath: s, cameraTaskId: o } = t;
2585
- let r = !1;
2586
- const i = this.cameraOpt;
2587
- if (e && !re(i, e)) {
2588
- const n = !i || i.scale !== e.scale || i.centerX !== e.centerX || i.centerY !== e.centerY || i.width !== e.width || i.height !== e.height;
2589
- if (this.taskUpdateCameraId && (clearTimeout(this.taskUpdateCameraId), this.taskUpdateCameraId = void 0, (c = this.taskUpdateCameraResolve) == null || c.call(this, !1), this.taskUpdateCameraResolve = void 0), s) {
2590
- const p = [];
2591
- for (const [f, u] of this.localWork.getWorkShapes().entries())
2592
- switch (u.toolsType) {
2593
- case y.Text:
2594
- case y.BitMapEraser:
2595
- case y.PencilEraser:
2596
- case y.Eraser:
2597
- case y.Selector:
2598
- case y.LaserPen:
2599
- break;
2600
- default:
2601
- f !== H && f !== D && p.push(`${f}:${u.toolsType}`);
2602
- break;
2603
- }
2604
- if (p.length) {
2605
- await new Promise((u) => {
2606
- this.taskUpdateCameraResolve = u, this.taskUpdateCameraId = setTimeout(() => {
2607
- this.taskUpdateCameraId = void 0, this.taskUpdateCameraResolve = void 0, u(!0);
2608
- }, ee);
2609
- }) && await this.updateCamera(t);
2610
- return;
2611
- }
2612
- }
2613
- const d = /* @__PURE__ */ new Map();
2614
- for (const [p, f] of this.vNodes.getNodesByType(y.Text).entries()) {
2615
- const u = f.rect;
2616
- d.set(p, Z(u));
2617
- }
2618
- for (const [p, f] of this.vNodes.gethasEraserNodes().entries())
2619
- d.set(p, Z(f.rect));
2620
- const l = new Set(d.keys());
2621
- let k = !1;
2622
- if (this.localWork.hasSelector()) {
2623
- const p = (a = this.localWork.getSelector()) == null ? void 0 : a.selectIds;
2624
- if (p) {
2625
- k = !0;
2626
- for (const f of p)
2627
- l.add(f);
2628
- }
2629
- }
2630
- let S = !1;
2631
- if (this.serviceWork.selectorWorkShapes.size)
2632
- for (const p of this.serviceWork.selectorWorkShapes.values()) {
2633
- const f = p.selectIds;
2634
- if (f) {
2635
- S = !0;
2636
- for (const u of f)
2637
- l.add(u);
2638
- }
2639
- }
2640
- if (this.setCameraOpt(e), this.vNodes.curNodeMap.size) {
2641
- this.vNodes.clearTarget(), this.vNodes.updateHighLevelNodesRect(l), this.debounceUpdateCameraId && clearTimeout(this.debounceUpdateCameraId);
2642
- for (const [p, f] of d.entries()) {
2643
- const u = this.vNodes.get(p);
2644
- if (u) {
2645
- const v = f, I = u.rect, L = this.getSceneRect(), T = te(v, L), E = te(I, L);
2646
- let R = !1;
2647
- (T !== E || v.w !== I.w || v.h !== I.h || E === ve.intersect) && (R = !0);
2648
- const { toolsType: B, opt: F } = u, b = F.eraserlines && F.eraserlines.length > 0 || !!F.eraserFaces;
2649
- (R || n && b) && (B === y.Text || b) && this.debounceUpdateCache.add(p);
2650
- }
2651
- }
2652
- if (k && this.localWork.reRenderSelector(), S)
2653
- for (const [
2654
- p,
2655
- f
2656
- ] of this.serviceWork.selectorWorkShapes.entries())
2657
- this.serviceWork.runSelectWork({
2658
- workId: p,
2659
- selectIds: f.selectIds,
2660
- msgType: h.Select,
2661
- dataType: g.Service,
2662
- viewId: this.viewId
2663
- });
2664
- r = !0, this.debounceUpdateCameraId = setTimeout(async () => {
2665
- var f;
2666
- this.debounceUpdateCameraId = void 0;
2667
- const p = [];
2668
- for (const u of this.debounceUpdateCache.values()) {
2669
- const v = (f = this.fullLayer) == null ? void 0 : f.getElementsByName(u)[0], I = this.vNodes.get(u);
2670
- if (I) {
2671
- const { toolsType: L, opt: T } = I;
2672
- if (v || L !== y.Text) {
2673
- const E = this.localWork.setFullWork({
2674
- toolsType: L,
2675
- opt: T,
2676
- workId: u
2677
- });
2678
- if (E) {
2679
- if (L === y.Text)
2680
- p.push(
2681
- E.consumeServiceAsync({
2682
- isFullWork: !0,
2683
- replaceId: u,
2684
- boxRect: this.getSceneRect()
2685
- })
2686
- );
2687
- else if (T.eraserlines && T.eraserlines.length > 0 || T.eraserFaces) {
2688
- const R = E.consumeService({
2689
- op: I.op,
2690
- isFullWork: !0,
2691
- replaceId: u,
2692
- workState: W.Done
2693
- });
2694
- this.localWork.clearWorkShapeNodeCache(u), p.push(Promise.resolve(R));
2695
- }
2696
- }
2697
- }
2698
- }
2699
- this.debounceUpdateCache.delete(u);
2700
- }
2701
- this.vNodes.updateLowLevelNodesRect(), this.vNodes.clearHighLevelIds(), await Promise.all(p), await Promise.all([
2702
- this.fullLayer.parent.prepareRender,
2703
- this.topLayer.parent.prepareRender,
2704
- this.localLayer.parent.prepareRender,
2705
- this.serviceLayer.parent.prepareRender
2706
- ]), G(o) && this.opt.post({
2707
- viewId: this.viewId,
2708
- cameraSettledTaskId: o
2709
- });
2710
- }, ee);
2711
- }
2712
- await Promise.all([
2713
- this.fullLayer.parent.prepareRender,
2714
- this.topLayer.parent.prepareRender,
2715
- this.localLayer.parent.prepareRender,
2716
- this.serviceLayer.parent.prepareRender
2717
- ]), !r && G(o) && this.opt.post({
2718
- viewId: this.viewId,
2719
- cameraSettledTaskId: o
2720
- });
2721
- }
2722
- }
2723
- getSceneRect() {
2724
- const { width: t, height: e } = this.scene;
2725
- return {
2726
- x: 0,
2727
- y: 0,
2728
- w: Math.floor(t),
2729
- h: Math.floor(e)
2730
- };
2731
- }
2732
- createScene(t) {
2733
- return new ce({
2734
- displayRatio: this.opt.displayer.dpr,
2735
- depth: !1,
2736
- desynchronized: !0,
2737
- ...t,
2738
- autoRender: !0,
2739
- id: this.viewId,
2740
- contextType: "2d"
2741
- });
2742
- }
2743
- createLayer(t, e, s) {
2744
- const { width: o, height: r } = s, i = `canvas-${t}`, c = e.layer(i, { ...s, offscreen: !1 }), a = new le({
2745
- anchor: [0.5, 0.5],
2746
- pos: [o * 0.5, r * 0.5],
2747
- size: [o, r],
2748
- name: "viewport",
2749
- id: t
2750
- });
2751
- return c.append(a), a;
2752
- }
2753
- updateScene(t) {
2754
- this.scene.attr({ ...t });
2755
- const { width: e, height: s } = t;
2756
- this.scene.width = e, this.scene.height = s, this.updateLayer({ width: e, height: s });
2757
- }
2758
- updateLayer(t) {
2759
- const { width: e, height: s } = t;
2760
- 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]);
2761
- }
2762
- destroy() {
2763
- this.destroyed || (this.destroyed = !0, this.clearCacheImages(), this.clearImageResolveMap(), this.vNodes.clear(), Ue({
2764
- subThreads: [this.localWork, this.serviceWork, this.topWork],
2765
- layers: [
2766
- this.fullLayer,
2767
- this.topLayer,
2768
- this.localLayer,
2769
- this.serviceLayer
2770
- ],
2771
- scene: this.scene,
2772
- removeLayerTexture: (t, e) => P(t, e)
2773
- }));
2774
- }
2775
- }
2776
- class ze {
2777
- constructor(t, e) {
2778
- m(this, "viewId");
2779
- m(this, "fullLayer");
2780
- m(this, "master");
2781
- m(this, "opt");
2782
- m(this, "scene");
2783
- m(this, "mainThreadPostId");
2784
- m(this, "combinePostMsg", /* @__PURE__ */ new Set());
2785
- m(this, "workShapes", /* @__PURE__ */ new Map());
2786
- m(this, "cacheImages", /* @__PURE__ */ new Map());
2787
- m(this, "imageResolveMap", /* @__PURE__ */ new Map());
2788
- this.viewId = t, this.opt = e, this.scene = this.createScene({
2789
- ...e.canvasOpt,
2790
- container: e.container
2791
- }), this.master = e.master, this.fullLayer = this.createLayer("fullLayer", this.scene, {
2792
- ...e.layerOpt,
2793
- bufferSize: this.viewId === $ ? 6e3 : 3e3,
2794
- contextType: "2d"
2795
- });
2796
- }
2797
- getCachedImages(t) {
2798
- var e;
2799
- return (e = this.cacheImages.get(t)) == null ? void 0 : e.imageSource;
2800
- }
2801
- getCachedImagesByWorkId(t) {
2802
- for (const [e, s] of this.cacheImages.entries())
2803
- if (e === t && s.imageSource)
2804
- return s.imageSource;
2805
- }
2806
- deleteCachedImagesByWorkId(t) {
2807
- for (const [e, s] of this.cacheImages.entries())
2808
- s.workId === t && ("close" in s.imageSource && s.imageSource.close(), this.cacheImages.delete(e));
2809
- }
2810
- clearCacheImages() {
2811
- this.cacheImages.forEach((t) => {
2812
- "close" in t.imageSource && t.imageSource.close();
2813
- }), this.cacheImages.clear();
2814
- }
2815
- clearImageResolveMap() {
2816
- this.imageResolveMap.forEach(({ timer: t }) => {
2817
- t && clearTimeout(t);
2818
- }), this.imageResolveMap.clear();
2819
- }
2820
- post(t) {
2821
- this.combinePostMsg.add(t), this.runBatchPostData();
2822
- }
2823
- async on(t) {
2824
- const { msgType: e, imageSrc: s, imageBitmap: o, imageElement: r, workId: i } = t;
2825
- switch (e) {
2826
- case h.Snapshot: {
2827
- await this.getSnapshot(t), this.destroy();
2828
- return;
2829
- }
2830
- case h.BoundingBox: {
2831
- await this.getBoundingRect(t), this.destroy();
2832
- return;
2833
- }
2834
- case h.GetImageBitMap: {
2835
- if (s && (o || r) && i) {
2836
- const c = i.toString();
2837
- this.deleteCachedImagesByWorkId(c), this.cacheImages.set(s, {
2838
- imageSource: o || r,
2839
- workId: c
2840
- });
2841
- const a = this.imageResolveMap.get(s);
2842
- if (a) {
2843
- const { resolve: n, timer: d } = a;
2844
- d && clearTimeout(d), n && n(s);
2845
- }
2846
- }
2847
- break;
2848
- }
2849
- }
2850
- }
2851
- getIconSize(t, e, s) {
2852
- const o = t * s, r = e * s;
2853
- return o <= 50 || r <= 50 ? [50, 50] : o <= 100 || r <= 100 ? [100, 100] : o <= 200 || r <= 200 ? [200, 200] : o <= 400 || r <= 400 ? [400, 400] : o <= 800 || r <= 800 ? [800, 800] : [1600, 1600];
2854
- }
2855
- async loadImageBitMap(t) {
2856
- const { toolsType: e, opt: s, workId: o } = t;
2857
- if (e === y.Image && s && o) {
2858
- const r = o.toString(), { src: i, type: c, width: a, height: n, strokeColor: d } = s;
2859
- if (!i || !c || !a || !n)
2860
- return;
2861
- let l = i;
2862
- if (c === ae.Iconify) {
2863
- const [f, u] = this.getIconSize(a, n, this.opt.displayer.dpr);
2864
- l = ne(i, f, u, d);
2865
- }
2866
- if (this.cacheImages.has(l)) {
2867
- const f = this.getCachedImages(l);
2868
- if (f)
2869
- return f;
2870
- }
2871
- if (this.imageResolveMap.has(l)) {
2872
- const f = this.getCachedImagesByWorkId(r);
2873
- if (f)
2874
- return f;
2875
- }
2876
- const p = await new Promise((f) => {
2877
- const u = this.imageResolveMap.get(l) || {
2878
- resolve: void 0,
2879
- timer: void 0
2880
- };
2881
- u.timer && clearTimeout(u.timer), u.resolve = f, u.timer = setTimeout(() => {
2882
- const v = this.imageResolveMap.get(l);
2883
- v != null && v.resolve && v.resolve(l);
2884
- }, 5e3), this.imageResolveMap.set(l, u), this.opt.post({
2885
- sp: [
2886
- {
2887
- imageSrc: l,
2888
- workId: r,
2889
- viewId: this.viewId,
2890
- isgl: !!this.fullLayer.parent.gl,
2891
- isSubWorker: !0,
2892
- type: h.GetImageBitMap
2893
- }
2894
- ]
2895
- });
2896
- });
2897
- return this.imageResolveMap.delete(p), this.getCachedImages(l);
2898
- }
2899
- }
2900
- createWorkShapeNode(t) {
2901
- return X({
2902
- ...t,
2903
- fullLayer: this.fullLayer,
2904
- drawLayer: void 0
2905
- });
2906
- }
2907
- setFullWork(t) {
2908
- const { workId: e, opt: s, toolsType: o } = t;
2909
- if (e && s && o) {
2910
- const r = e.toString();
2911
- let i;
2912
- return e && this.workShapes.has(r) ? (i = this.workShapes.get(r), i == null || i.setWorkOptions(s)) : i = this.createWorkShapeNode({
2913
- toolsOpt: s,
2914
- toolsType: o,
2915
- workId: r
2916
- }), i ? (this.workShapes.set(r, i), i) : void 0;
2917
- }
2918
- }
2919
- async runFullWork(t) {
2920
- var o;
2921
- const e = this.setFullWork(t), s = t.ops && V(t.ops);
2922
- if (e) {
2923
- let r, i;
2924
- const c = (o = e.getWorkId()) == null ? void 0 : o.toString();
2925
- return e.toolsType === y.BackgroundSVG ? r = e.consumeService({
2926
- isFullWork: !0,
2927
- replaceId: c
2928
- }) : e.toolsType === y.Image ? r = await e.consumeServiceAsync({
2929
- isFullWork: !0,
2930
- worker: this
2931
- }) : e.toolsType === y.Text ? r = await e.consumeServiceAsync({
2932
- isFullWork: !0,
2933
- replaceId: c,
2934
- isDrawLabel: !0
2935
- }) : (r = e.consumeService({
2936
- op: s,
2937
- isFullWork: !0,
2938
- replaceId: c
2939
- }), i = (t == null ? void 0 : t.updateNodeOpt) && e.updataOptService(t.updateNodeOpt)), se(r, i);
2940
- }
2941
- }
2942
- async getSnapshot(t) {
2943
- const { scenePath: e, scenes: s, cameraOpt: o, w: r, h: i } = t;
2944
- if (e && s && o) {
2945
- this.setCameraOpt(o);
2946
- for (const [a, n] of Object.entries(s))
2947
- if (n != null && n.type)
2948
- switch (n == null ? void 0 : n.type) {
2949
- case h.UpdateNode:
2950
- case h.FullWork: {
2951
- const { opt: d } = n, l = {
2952
- ...n,
2953
- opt: d,
2954
- workId: a,
2955
- msgType: h.FullWork,
2956
- dataType: g.Service,
2957
- viewId: this.viewId
2958
- };
2959
- await this.runFullWork(l);
2960
- break;
2961
- }
2962
- }
2963
- let c;
2964
- r && i && (c = {
2965
- resizeWidth: r,
2966
- resizeHeight: i
2967
- });
2968
- try {
2969
- await this.getSnapshotRender({ scenePath: e, options: c });
2970
- } catch (a) {
2971
- const n = a && a instanceof Error ? a.message : a == null ? void 0 : a.toString();
2972
- console.error(
2973
- "[SnapshotThreadImpl] getSnapshotRender error",
2974
- n
2975
- ), this.post({
2976
- sp: [
2977
- {
2978
- type: h.ReportError,
2979
- reportString: `[SnapshotThreadImpl] getSnapshotRender error: ${n}`
2980
- }
2981
- ]
2982
- });
2983
- }
2984
- }
2985
- }
2986
- getSceneRect() {
2987
- const { width: t, height: e } = this.scene;
2988
- return {
2989
- x: 0,
2990
- y: 0,
2991
- w: Math.floor(t),
2992
- h: Math.floor(e)
2993
- };
2994
- }
2995
- getRectImageBitmap(t, e) {
2996
- 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;
2997
- return createImageBitmap(
2998
- this.fullLayer.parent.canvas,
2999
- s,
3000
- o,
3001
- r,
3002
- i,
3003
- e
3004
- );
3005
- }
3006
- async getSnapshotRender(t) {
3007
- var r;
3008
- const { scenePath: e, options: s } = t;
3009
- ((r = this.fullLayer) == null ? void 0 : r.parent).render();
3010
- const o = await this.getRectImageBitmap(
3011
- this.getSceneRect(),
3012
- s
3013
- );
3014
- o && (this.post({
3015
- sp: [
3016
- {
3017
- type: h.Snapshot,
3018
- scenePath: e,
3019
- imageBitmap: o,
3020
- viewId: this.viewId,
3021
- index: 0
3022
- }
3023
- ]
3024
- }), this.fullLayer && q(this.fullLayer, this.fullLayer.parent));
3025
- }
3026
- async getBoundingRect(t) {
3027
- const { scenePath: e, scenes: s, cameraOpt: o } = t;
3028
- if (e && s && o) {
3029
- this.setCameraOpt(o);
3030
- let r;
3031
- for (const [i, c] of Object.entries(s))
3032
- if (c != null && c.type)
3033
- switch (c == null ? void 0 : c.type) {
3034
- case h.UpdateNode:
3035
- case h.FullWork: {
3036
- const a = await this.runFullWork({
3037
- ...c,
3038
- workId: i,
3039
- msgType: h.FullWork,
3040
- dataType: g.Service,
3041
- viewId: this.viewId
3042
- });
3043
- r = se(r, a);
3044
- break;
3045
- }
3046
- }
3047
- r && this.post({
3048
- sp: [
3049
- {
3050
- type: h.BoundingBox,
3051
- scenePath: e,
3052
- rect: r
3053
- }
3054
- ]
3055
- });
3056
- }
3057
- }
3058
- setCameraOpt(t) {
3059
- const { scale: e, centerX: s, centerY: o, width: r, height: i } = t;
3060
- this.updateScene({ width: r, height: i }), this.fullLayer.setAttribute("scale", [e, e]), this.fullLayer.setAttribute("translate", [-s, -o]);
3061
- }
3062
- runBatchPostData() {
3063
- this.mainThreadPostId || (this.mainThreadPostId = requestAnimationFrame(
3064
- this.combinePost.bind(this)
3065
- ));
3066
- }
3067
- combinePostData() {
3068
- var e;
3069
- this.mainThreadPostId = void 0;
3070
- const t = [];
3071
- for (const s of this.combinePostMsg.values())
3072
- if ((e = s.sp) != null && e.length)
3073
- for (const o of s.sp) {
3074
- let r = !1;
3075
- for (const i of t)
3076
- if (Te(o, i)) {
3077
- r = !0;
3078
- break;
3079
- }
3080
- r || t.push(o);
3081
- }
3082
- return this.combinePostMsg.clear(), {
3083
- sp: t
3084
- };
3085
- }
3086
- combinePost() {
3087
- var s, o;
3088
- const t = this.combinePostData(), e = (s = t.sp) == null ? void 0 : s.filter(
3089
- (r) => r.type !== h.None || r.isLockSentEventCursor || r.needUndoTicker
3090
- );
3091
- e != null && e.length ? t.sp = e.map((r) => r.viewId ? r : { ...r, viewId: this.viewId }) : delete t.sp, (o = t.sp) != null && o.length && this.opt.post(t);
3092
- }
3093
- createScene(t) {
3094
- return new ce({
3095
- displayRatio: this.opt.displayer.dpr,
3096
- depth: !1,
3097
- desynchronized: !0,
3098
- ...t,
3099
- autoRender: !1,
3100
- contextType: "2d"
3101
- });
3102
- }
3103
- createLayer(t, e, s) {
3104
- const { width: o, height: r } = s, i = `canvas-${t}`, c = e.layer(i, s), a = new le({
3105
- anchor: [0.5, 0.5],
3106
- pos: [o * 0.5, r * 0.5],
3107
- size: [o, r],
3108
- name: "viewport",
3109
- id: t
3110
- });
3111
- return c.append(a), a;
3112
- }
3113
- updateScene(t) {
3114
- this.scene.attr({ ...t });
3115
- const { width: e, height: s } = t;
3116
- this.scene.width = e, this.scene.height = s, this.updateLayer({ width: e, height: s });
3117
- }
3118
- updateLayer(t) {
3119
- const { width: e, height: s } = t;
3120
- 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]);
3121
- }
3122
- destroy() {
3123
- this.clearCacheImages(), this.clearImageResolveMap(), this.fullLayer.remove(), P(this.fullLayer, this.fullLayer.parent), this.scene.remove();
3124
- }
3125
- }
3126
- class Ze {
3127
- constructor(t) {
3128
- m(this, "mainThreadMap", /* @__PURE__ */ new Map());
3129
- m(this, "cameraRenderQueueByView", /* @__PURE__ */ new Map());
3130
- m(this, "viewGenerationById", /* @__PURE__ */ new Map());
3131
- m(this, "snapshotThread");
3132
- m(this, "master");
3133
- m(this, "post", (t) => {
3134
- const {
3135
- fullWorkerDrawCount: e,
3136
- sp: s,
3137
- workerTasksqueueCount: o,
3138
- cameraTaskId: r,
3139
- cameraSettledTaskId: i,
3140
- viewId: c,
3141
- consumeCount: a
3142
- } = t;
3143
- c && z(r) && this.master.ackCameraTask(c, r), c && z(i) && this.master.ackCameraSettledTask(c, i), this.master.isBusy && z(o) && this.master.setWorkerTasksqueueCount(o), z(e) && this.master.setMaxDrawCount(e), z(a) && this.master.setConsumeCount(a), s && this.master.collectorSyncData(s);
3144
- });
3145
- this.master = t;
3146
- }
3147
- enqueueViewTask(t, e) {
3148
- const o = (this.cameraRenderQueueByView.get(t) || Promise.resolve()).catch(() => {
3149
- }).then(e);
3150
- return this.cameraRenderQueueByView.set(t, o), o;
3151
- }
3152
- destroy() {
3153
- var t;
3154
- (t = this.snapshotThread) == null || t.destroy(), this.snapshotThread = void 0;
3155
- for (const e of this.mainThreadMap.values())
3156
- e.destroy();
3157
- this.mainThreadMap.clear();
3158
- }
3159
- createMainThread(t, e) {
3160
- return new Pe(t, e);
3161
- }
3162
- createSnapshotThread(t, e) {
3163
- return new ze(t, e);
3164
- }
3165
- async consume(t) {
3166
- var e, s, o, r;
3167
- for (const i of t.values()) {
3168
- const {
3169
- msgType: c,
3170
- viewId: a,
3171
- tasksqueue: n,
3172
- mainTasksqueueCount: d,
3173
- cameraTaskId: l,
3174
- layerOpt: k,
3175
- offscreenCanvasOpt: S,
3176
- cameraOpt: p,
3177
- isSubWorker: f
3178
- } = i;
3179
- if (c === h.Console) {
3180
- console.log(this);
3181
- continue;
3182
- }
3183
- if (c === h.Init) {
3184
- const L = i.viewGeneration ?? (this.viewGenerationById.get(a) || 0) + 1;
3185
- await this.enqueueViewTask(a, async () => {
3186
- var F;
3187
- this.viewGenerationById.set(a, L);
3188
- const T = (F = this.master.control.viewContainerManager.getView(a)) == null ? void 0 : F.displayer, E = T == null ? void 0 : T.canvasContainerRef.current;
3189
- if (!T || !E || !k || !S) return;
3190
- const R = this.mainThreadMap.get(a);
3191
- R == null || R.destroy();
3192
- const B = this.createMainThread(a, { displayer: T, container: E, layerOpt: k, master: this.master, canvasOpt: S, post: this.post });
3193
- this.mainThreadMap.set(a, B), B && p && B.setCameraOpt(p), this.post({ sp: [{ type: h.Init, viewId: a, viewGeneration: L }] });
3194
- });
3195
- continue;
3196
- }
3197
- if ((c === h.Snapshot || c === h.BoundingBox) && a === ((e = this.master.control.viewContainerManager.mainView) == null ? void 0 : e.id)) {
3198
- const L = (s = this.master.control.viewContainerManager.getView(a)) == null ? void 0 : s.displayer, T = (o = L.snapshotContainerRef) == null ? void 0 : o.current;
3199
- if (L && T && p) {
3200
- (r = this.snapshotThread) == null || r.destroy(), T.style.width = `${p.width}px`, T.style.height = `${p.height}px`;
3201
- const E = {
3202
- ...oe.defaultLayerOpt,
3203
- offscreen: !1,
3204
- width: p.width,
3205
- height: p.height
3206
- }, R = {
3207
- ...oe.defaultScreenCanvasOpt,
3208
- width: p.width,
3209
- height: p.height
3210
- };
3211
- this.snapshotThread = this.createSnapshotThread(a, {
3212
- displayer: L,
3213
- container: T,
3214
- layerOpt: E,
3215
- master: this.master,
3216
- canvasOpt: R,
3217
- post: this.post
3218
- }), this.snapshotThread.on(i).then(() => {
3219
- this.snapshotThread = void 0, T.innerHTML = "", T.style.width = "", T.style.height = "";
3220
- });
3221
- continue;
3222
- }
3223
- }
3224
- if (c === h.GetImageBitMap && f && this.snapshotThread) {
3225
- this.snapshotThread.on(i);
3226
- continue;
3227
- }
3228
- if (c === h.TasksQueue && (n != null && n.size)) {
3229
- const L = n.get(a), T = this.mainThreadMap.get(a), E = this.viewGenerationById.get(a);
3230
- L && T && await this.enqueueViewTask(a, async () => {
3231
- this.viewGenerationById.get(a) !== E || this.mainThreadMap.get(a) !== T || await T.on(L);
3232
- }), d && z(l) && this.post({
3233
- workerTasksqueueCount: d,
3234
- cameraTaskId: l,
3235
- viewId: a
3236
- });
3237
- continue;
3238
- }
3239
- if (a === Ie) {
3240
- const L = [...this.mainThreadMap.entries()];
3241
- for (const [T, E] of L) {
3242
- const R = this.enqueueViewTask(T, async () => {
3243
- this.mainThreadMap.get(T) === E && (c === h.Destroy ? (E.destroy(), this.mainThreadMap.delete(T), this.viewGenerationById.set(T, (this.viewGenerationById.get(T) || 0) + 1)) : await E.on(i));
3244
- });
3245
- await R, this.cameraRenderQueueByView.get(T) === R && this.cameraRenderQueueByView.delete(T);
3246
- }
3247
- continue;
3248
- }
3249
- const u = this.mainThreadMap.get(a);
3250
- if (c === h.Destroy && !u) {
3251
- await this.enqueueViewTask(a, async () => {
3252
- this.viewGenerationById.set(a, i.viewGeneration ?? (this.viewGenerationById.get(a) || 0) + 1);
3253
- });
3254
- continue;
3255
- }
3256
- if (!u)
3257
- continue;
3258
- const v = this.viewGenerationById.get(a), I = this.enqueueViewTask(a, async () => {
3259
- this.viewGenerationById.get(a) !== v || this.mainThreadMap.get(a) !== u || await u.on(i);
3260
- });
3261
- c === h.Destroy && (await I, this.mainThreadMap.get(a) === u && this.mainThreadMap.delete(a), this.cameraRenderQueueByView.get(a) === I && this.cameraRenderQueueByView.delete(a), this.viewGenerationById.set(a, i.viewGeneration ?? (v || 0) + 1));
3262
- }
3263
- }
3264
- }
3265
- export {
3266
- Ze as MainThreadManagerImpl
3267
- };