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

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