@netless/appliance-plugin 1.1.22-beta.3 → 1.1.22-beta.4

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