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