@netless/appliance-plugin 1.1.2 → 1.1.3-4.beta.0

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