@8btc/whiteboard 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +19 -2
- package/dist/index.js +509 -468
- package/dist/index.umd.js +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var qt = Object.defineProperty;
|
|
2
|
+
var Rt = (o) => {
|
|
3
3
|
throw TypeError(o);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var r = (o, e, t) => (wt(o, e, "read from private field"), t ? t.call(o) : e.get(o)),
|
|
8
|
-
import { jsxs as
|
|
9
|
-
import { useState as
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import { v4 as
|
|
13
|
-
import { Slot as
|
|
14
|
-
import { cva as
|
|
15
|
-
import { clsx as
|
|
16
|
-
import { twMerge as
|
|
17
|
-
import { Minus as
|
|
18
|
-
var
|
|
19
|
-
class
|
|
5
|
+
var Kt = (o, e, t) => e in o ? qt(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
6
|
+
var D = (o, e, t) => Kt(o, typeof e != "symbol" ? e + "" : e, t), wt = (o, e, t) => e.has(o) || Rt("Cannot " + t);
|
|
7
|
+
var r = (o, e, t) => (wt(o, e, "read from private field"), t ? t.call(o) : e.get(o)), l = (o, e, t) => e.has(o) ? Rt("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(o) : e.set(o, t), N = (o, e, t, s) => (wt(o, e, "write to private field"), s ? s.call(o, t) : e.set(o, t), t), _ = (o, e, t) => (wt(o, e, "access private method"), t);
|
|
8
|
+
import { jsxs as W, jsx as v, Fragment as jt } from "react/jsx-runtime";
|
|
9
|
+
import { useState as q, useEffect as It, useRef as Bt } from "react";
|
|
10
|
+
import Y from "konva";
|
|
11
|
+
import Jt from "mitt";
|
|
12
|
+
import { v4 as K } from "uuid";
|
|
13
|
+
import { Slot as Qt } from "@radix-ui/react-slot";
|
|
14
|
+
import { cva as te } from "class-variance-authority";
|
|
15
|
+
import { clsx as ee } from "clsx";
|
|
16
|
+
import { twMerge as se } from "tailwind-merge";
|
|
17
|
+
import { Minus as ie, Plus as ne, Undo2 as re, Redo2 as oe } from "lucide-react";
|
|
18
|
+
var y, m, R, et, st, it, nt, rt, ot, at, ht, Zt;
|
|
19
|
+
class ae {
|
|
20
20
|
constructor(e, t) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
l(this, ht);
|
|
22
|
+
l(this, y);
|
|
23
|
+
l(this, m);
|
|
24
|
+
l(this, R, { x: 0, y: 0, scale: 1 });
|
|
25
25
|
/**
|
|
26
26
|
* 处理滚轮缩放和平移
|
|
27
27
|
*/
|
|
28
|
-
|
|
28
|
+
l(this, et, (e) => {
|
|
29
29
|
e.evt.preventDefault();
|
|
30
|
-
const s = r(this,
|
|
30
|
+
const s = r(this, m).getPointerPosition();
|
|
31
31
|
if (s)
|
|
32
32
|
if (e.evt.ctrlKey) {
|
|
33
|
-
const
|
|
34
|
-
x: (s.x - r(this,
|
|
35
|
-
y: (s.y - r(this,
|
|
33
|
+
const i = r(this, R).scale, n = {
|
|
34
|
+
x: (s.x - r(this, R).x) / i,
|
|
35
|
+
y: (s.y - r(this, R).y) / i
|
|
36
36
|
}, a = 1.01, h = e.evt.deltaY > 0 ? -1 : 1, c = Math.min(Math.abs(e.evt.deltaY), 10);
|
|
37
|
-
let
|
|
37
|
+
let d = i;
|
|
38
38
|
for (let p = 0; p < c; p++)
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
x: s.x -
|
|
42
|
-
y: s.y -
|
|
39
|
+
d = h > 0 ? d * a : d / a;
|
|
40
|
+
const g = Math.max(0.1, Math.min(5, d)), x = {
|
|
41
|
+
x: s.x - n.x * g,
|
|
42
|
+
y: s.y - n.y * g
|
|
43
43
|
};
|
|
44
|
-
r(this,
|
|
44
|
+
r(this, y).updateViewport({ x: x.x, y: x.y, scale: g });
|
|
45
45
|
} else {
|
|
46
|
-
const
|
|
47
|
-
r(this,
|
|
48
|
-
x: r(this,
|
|
49
|
-
y: r(this,
|
|
46
|
+
const i = e.evt.shiftKey ? e.evt.deltaY : e.evt.deltaX, n = e.evt.shiftKey ? 0 : e.evt.deltaY;
|
|
47
|
+
r(this, y).updateViewport({
|
|
48
|
+
x: r(this, R).x - i,
|
|
49
|
+
y: r(this, R).y - n
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
|
-
|
|
54
|
-
const t = r(this,
|
|
53
|
+
l(this, st, (e) => {
|
|
54
|
+
const t = r(this, y).getState().toolType;
|
|
55
55
|
if (e.evt.button !== 0 || t === "hand")
|
|
56
56
|
return;
|
|
57
|
-
const s = e.target === r(this,
|
|
57
|
+
const s = e.target === r(this, m), i = r(this, m).getRelativePointerPosition();
|
|
58
58
|
if (t === "select" && !s) {
|
|
59
|
-
const
|
|
60
|
-
|
|
59
|
+
const n = e.target.id();
|
|
60
|
+
n && r(this, y).selectNode(n, e.evt.shiftKey);
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
|
-
if (t === "rectangle" &&
|
|
64
|
-
const
|
|
65
|
-
if (console.log(
|
|
66
|
-
const a =
|
|
63
|
+
if (t === "rectangle" && i && r(this, y).createDraftNode(t, i), t === "image-marker" && i) {
|
|
64
|
+
const n = r(this, y).findImageAtPosition(i);
|
|
65
|
+
if (console.log(n, "imageShape"), n) {
|
|
66
|
+
const a = n.width(), h = n.height();
|
|
67
67
|
if (a && h) {
|
|
68
68
|
const c = {
|
|
69
|
-
x:
|
|
70
|
-
y:
|
|
69
|
+
x: n.x(),
|
|
70
|
+
y: n.y(),
|
|
71
71
|
width: a,
|
|
72
72
|
height: h
|
|
73
73
|
};
|
|
74
|
-
r(this,
|
|
75
|
-
parent:
|
|
74
|
+
r(this, y).createDraftNode(t, i, {
|
|
75
|
+
parent: n.id(),
|
|
76
76
|
bounds: c,
|
|
77
|
-
startPosition:
|
|
77
|
+
startPosition: i
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
r(this,
|
|
82
|
+
r(this, y).selectNode();
|
|
83
83
|
});
|
|
84
|
-
|
|
85
|
-
const e = r(this,
|
|
84
|
+
l(this, it, () => {
|
|
85
|
+
const e = r(this, y).getState().toolType;
|
|
86
86
|
if (e === "hand")
|
|
87
87
|
return;
|
|
88
|
-
const t = r(this,
|
|
89
|
-
(e === "rectangle" || e === "image-marker") && t && r(this,
|
|
88
|
+
const t = r(this, m).getRelativePointerPosition();
|
|
89
|
+
(e === "rectangle" || e === "image-marker") && t && r(this, y).updateDraftNode(t);
|
|
90
90
|
});
|
|
91
|
-
|
|
92
|
-
const e = r(this,
|
|
93
|
-
e !== "hand" && (e === "rectangle" || e === "image-marker") && r(this,
|
|
91
|
+
l(this, nt, () => {
|
|
92
|
+
const e = r(this, y).getState().toolType;
|
|
93
|
+
e !== "hand" && (e === "rectangle" || e === "image-marker") && r(this, y).finalizeDraftNode();
|
|
94
94
|
});
|
|
95
|
-
|
|
96
|
-
if (e.target !== r(this,
|
|
95
|
+
l(this, rt, (e) => {
|
|
96
|
+
if (e.target !== r(this, m))
|
|
97
97
|
return;
|
|
98
|
-
const t = r(this,
|
|
98
|
+
const t = r(this, y).getState().toolType;
|
|
99
99
|
t === "hand" ? this.setCursor("grabbing") : t === "select" && this.setCursor("all-scroll");
|
|
100
100
|
});
|
|
101
|
-
|
|
102
|
-
e.target === r(this,
|
|
103
|
-
x: r(this,
|
|
104
|
-
y: r(this,
|
|
101
|
+
l(this, ot, (e) => {
|
|
102
|
+
e.target === r(this, m) && r(this, y).updateViewport({
|
|
103
|
+
x: r(this, m).x(),
|
|
104
|
+
y: r(this, m).y()
|
|
105
105
|
});
|
|
106
106
|
});
|
|
107
|
-
|
|
108
|
-
e.target === r(this,
|
|
109
|
-
x: r(this,
|
|
110
|
-
y: r(this,
|
|
107
|
+
l(this, at, (e) => {
|
|
108
|
+
e.target === r(this, m) && (r(this, y).updateViewport({
|
|
109
|
+
x: r(this, m).x(),
|
|
110
|
+
y: r(this, m).y()
|
|
111
111
|
}), this.resetCursor());
|
|
112
112
|
});
|
|
113
|
-
N(this,
|
|
113
|
+
N(this, y, e), N(this, m, new Y.Stage({
|
|
114
114
|
container: t.container,
|
|
115
115
|
width: t.width,
|
|
116
116
|
height: t.height,
|
|
@@ -120,46 +120,46 @@ class ne {
|
|
|
120
120
|
scaleY: 1,
|
|
121
121
|
draggable: t.draggable ?? !1,
|
|
122
122
|
className: t.className
|
|
123
|
-
})),
|
|
123
|
+
})), _(this, ht, Zt).call(this);
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
126
|
* 获取原生 Konva.Stage 实例
|
|
127
127
|
*/
|
|
128
128
|
getStage() {
|
|
129
|
-
return r(this,
|
|
129
|
+
return r(this, m);
|
|
130
130
|
}
|
|
131
131
|
/**
|
|
132
132
|
* 获取当前视口状态
|
|
133
133
|
*/
|
|
134
134
|
getViewport() {
|
|
135
|
-
return { ...r(this,
|
|
135
|
+
return { ...r(this, R) };
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
138
138
|
* 设置视口(包括位置、缩放和尺寸)
|
|
139
139
|
*/
|
|
140
140
|
setViewport(e) {
|
|
141
|
-
const t = { ...r(this,
|
|
142
|
-
N(this,
|
|
141
|
+
const t = { ...r(this, R), ...e };
|
|
142
|
+
N(this, R, t), e.x !== void 0 && r(this, m).x(e.x), e.y !== void 0 && r(this, m).y(e.y), e.scale !== void 0 && (r(this, m).scaleX(e.scale), r(this, m).scaleY(e.scale)), e.width !== void 0 && r(this, m).width(e.width), e.height !== void 0 && r(this, m).height(e.height);
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
145
145
|
* 设置是否可拖拽
|
|
146
146
|
*/
|
|
147
147
|
setDraggable(e) {
|
|
148
|
-
r(this,
|
|
148
|
+
r(this, m).draggable(e);
|
|
149
149
|
}
|
|
150
150
|
/**
|
|
151
151
|
* 设置光标样式
|
|
152
152
|
*/
|
|
153
153
|
setCursor(e) {
|
|
154
|
-
const t = r(this,
|
|
154
|
+
const t = r(this, m).container();
|
|
155
155
|
t.style.cursor = e;
|
|
156
156
|
}
|
|
157
157
|
/**
|
|
158
158
|
* 重置光标样式
|
|
159
159
|
*/
|
|
160
160
|
resetCursor() {
|
|
161
|
-
const e = r(this,
|
|
162
|
-
if (r(this,
|
|
161
|
+
const e = r(this, m).container();
|
|
162
|
+
if (r(this, y).getState().toolType === "hand") {
|
|
163
163
|
e.style.cursor = "grab";
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
@@ -169,85 +169,85 @@ class ne {
|
|
|
169
169
|
* 销毁 Stage
|
|
170
170
|
*/
|
|
171
171
|
destroy() {
|
|
172
|
-
r(this,
|
|
172
|
+
r(this, m).destroy();
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
|
-
|
|
175
|
+
y = new WeakMap(), m = new WeakMap(), R = new WeakMap(), et = new WeakMap(), st = new WeakMap(), it = new WeakMap(), nt = new WeakMap(), rt = new WeakMap(), ot = new WeakMap(), at = new WeakMap(), ht = new WeakSet(), /**
|
|
176
176
|
* 设置事件监听器
|
|
177
177
|
*/
|
|
178
|
-
|
|
179
|
-
r(this,
|
|
178
|
+
Zt = function() {
|
|
179
|
+
r(this, m).on("wheel", r(this, et)), r(this, m).on("pointerdown", r(this, st)), r(this, m).on("pointermove", r(this, it)), r(this, m).on("pointerup", r(this, nt)), r(this, m).on("dragstart", r(this, rt)), r(this, m).on("dragmove", r(this, ot)), r(this, m).on("dragend", r(this, at));
|
|
180
180
|
};
|
|
181
|
-
var
|
|
182
|
-
class
|
|
181
|
+
var B, f, ct, dt, lt, mt, gt, pt, ut, At;
|
|
182
|
+
class he {
|
|
183
183
|
constructor(e, t) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
184
|
+
l(this, ut);
|
|
185
|
+
l(this, B);
|
|
186
|
+
l(this, f);
|
|
187
187
|
/**
|
|
188
188
|
* 处理 transformstart 事件
|
|
189
189
|
*/
|
|
190
|
-
|
|
190
|
+
l(this, ct, () => {
|
|
191
191
|
this.emitPositionChange();
|
|
192
192
|
});
|
|
193
193
|
/**
|
|
194
194
|
* 处理 transform 事件
|
|
195
195
|
*/
|
|
196
|
-
|
|
196
|
+
l(this, dt, () => {
|
|
197
197
|
console.log("transforming..."), this.emitPositionChange();
|
|
198
198
|
});
|
|
199
199
|
/**
|
|
200
200
|
* 处理 transformend 事件
|
|
201
201
|
*/
|
|
202
|
-
|
|
202
|
+
l(this, lt, () => {
|
|
203
203
|
this.emitPositionChange();
|
|
204
204
|
});
|
|
205
205
|
/**
|
|
206
206
|
* 处理 dragstart 事件
|
|
207
207
|
*/
|
|
208
|
-
|
|
208
|
+
l(this, mt, () => {
|
|
209
209
|
this.emitPositionChange();
|
|
210
210
|
});
|
|
211
211
|
/**
|
|
212
212
|
* 处理 dragmove 事件
|
|
213
213
|
*/
|
|
214
|
-
|
|
214
|
+
l(this, gt, () => {
|
|
215
215
|
this.emitPositionChange();
|
|
216
216
|
});
|
|
217
217
|
/**
|
|
218
218
|
* 处理 dragend 事件
|
|
219
219
|
*/
|
|
220
|
-
|
|
220
|
+
l(this, pt, () => {
|
|
221
221
|
this.emitPositionChange();
|
|
222
222
|
});
|
|
223
|
-
N(this,
|
|
223
|
+
N(this, B, e), N(this, f, new Y.Transformer({
|
|
224
224
|
rotateEnabled: t?.rotateEnabled ?? !0,
|
|
225
225
|
ignoreStroke: t?.ignoreStroke ?? !0,
|
|
226
226
|
anchorSize: t?.anchorSize ?? 8,
|
|
227
227
|
borderDash: t?.borderDash ?? [4, 4],
|
|
228
228
|
anchorCornerRadius: t?.anchorCornerRadius ?? 4,
|
|
229
229
|
padding: t?.padding ?? 6
|
|
230
|
-
})),
|
|
230
|
+
})), _(this, ut, At).call(this);
|
|
231
231
|
}
|
|
232
232
|
/**
|
|
233
233
|
* 获取原生 Konva.Transformer 实例
|
|
234
234
|
*/
|
|
235
235
|
getTransformer() {
|
|
236
|
-
return r(this,
|
|
236
|
+
return r(this, f);
|
|
237
237
|
}
|
|
238
238
|
/**
|
|
239
239
|
* 获取 Transformer 的位置信息
|
|
240
240
|
*/
|
|
241
241
|
getPosition() {
|
|
242
|
-
if (r(this,
|
|
242
|
+
if (r(this, f).nodes().length === 0)
|
|
243
243
|
return null;
|
|
244
|
-
const t = r(this,
|
|
244
|
+
const t = r(this, f).getClientRect();
|
|
245
245
|
return {
|
|
246
246
|
x: t.x,
|
|
247
247
|
y: t.y,
|
|
248
248
|
width: t.width,
|
|
249
249
|
height: t.height,
|
|
250
|
-
rotation: r(this,
|
|
250
|
+
rotation: r(this, f).rotation()
|
|
251
251
|
};
|
|
252
252
|
}
|
|
253
253
|
/**
|
|
@@ -258,47 +258,47 @@ class re {
|
|
|
258
258
|
this.clearNodes();
|
|
259
259
|
return;
|
|
260
260
|
}
|
|
261
|
-
r(this,
|
|
261
|
+
r(this, f).nodes(e), r(this, f).moveToTop(), this.emitPositionChange();
|
|
262
262
|
}
|
|
263
263
|
/**
|
|
264
264
|
* 获取当前变换的节点
|
|
265
265
|
*/
|
|
266
266
|
getNodes() {
|
|
267
|
-
return r(this,
|
|
267
|
+
return r(this, f).nodes();
|
|
268
268
|
}
|
|
269
269
|
/**
|
|
270
270
|
* 清除所有节点
|
|
271
271
|
*/
|
|
272
272
|
clearNodes() {
|
|
273
|
-
r(this,
|
|
273
|
+
r(this, f).nodes([]), r(this, f).moveToBottom(), this.emitPositionChange();
|
|
274
274
|
}
|
|
275
275
|
/**
|
|
276
276
|
* emit Transformer 位置
|
|
277
277
|
*/
|
|
278
278
|
emitPositionChange() {
|
|
279
279
|
const e = this.getPosition();
|
|
280
|
-
r(this,
|
|
280
|
+
r(this, B).emitEvent("transformer:positionChange", e);
|
|
281
281
|
}
|
|
282
282
|
/**
|
|
283
283
|
* 销毁 Transformer
|
|
284
284
|
*/
|
|
285
285
|
destroy() {
|
|
286
|
-
r(this,
|
|
286
|
+
r(this, f).destroy();
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
|
-
|
|
289
|
+
B = new WeakMap(), f = new WeakMap(), ct = new WeakMap(), dt = new WeakMap(), lt = new WeakMap(), mt = new WeakMap(), gt = new WeakMap(), pt = new WeakMap(), ut = new WeakSet(), /**
|
|
290
290
|
* 设置事件监听器
|
|
291
291
|
*/
|
|
292
|
-
|
|
293
|
-
r(this,
|
|
292
|
+
At = function() {
|
|
293
|
+
r(this, f).on("transformstart", r(this, ct)), r(this, f).on("transform", r(this, dt)), r(this, f).on("transformend", r(this, lt)), r(this, f).on("dragstart", r(this, mt)), r(this, f).on("dragmove", r(this, gt)), r(this, f).on("dragend", r(this, pt));
|
|
294
294
|
};
|
|
295
|
-
class
|
|
295
|
+
class ce {
|
|
296
296
|
constructor(e) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
this._present = e, this._emitter =
|
|
297
|
+
D(this, "_past", []);
|
|
298
|
+
D(this, "_present");
|
|
299
|
+
D(this, "_future", []);
|
|
300
|
+
D(this, "_emitter");
|
|
301
|
+
this._present = e, this._emitter = Jt();
|
|
302
302
|
}
|
|
303
303
|
/**
|
|
304
304
|
* 获取当前状态
|
|
@@ -391,33 +391,33 @@ class oe {
|
|
|
391
391
|
this._emitter.all.clear();
|
|
392
392
|
}
|
|
393
393
|
}
|
|
394
|
-
const
|
|
394
|
+
const j = "shapeNameForSelect", u = {
|
|
395
395
|
CORNER_RADIUS: 6,
|
|
396
396
|
MIN_SIZE: 10
|
|
397
|
-
},
|
|
397
|
+
}, F = {
|
|
398
398
|
MIN_SIZE: 10
|
|
399
|
-
},
|
|
399
|
+
}, Yt = {
|
|
400
400
|
MIN_SIZE: 10
|
|
401
401
|
};
|
|
402
|
-
function
|
|
402
|
+
function de(o, e, t) {
|
|
403
403
|
return 2 * (e + o - t * (4 - Math.PI));
|
|
404
404
|
}
|
|
405
|
-
function
|
|
406
|
-
let s = 1,
|
|
405
|
+
function le(o, e, t) {
|
|
406
|
+
let s = 1, i = 0, n = 0;
|
|
407
407
|
switch (t) {
|
|
408
408
|
case "dashed":
|
|
409
|
-
|
|
409
|
+
i = Math.min(e * 2, o / 4);
|
|
410
410
|
break;
|
|
411
411
|
case "dotted":
|
|
412
|
-
s = 8,
|
|
412
|
+
s = 8, i = e / s;
|
|
413
413
|
break;
|
|
414
414
|
default:
|
|
415
415
|
return [];
|
|
416
416
|
}
|
|
417
|
-
let a = Math.floor(o /
|
|
418
|
-
return a = Math.max(a, 3),
|
|
417
|
+
let a = Math.floor(o / i / (2 * s));
|
|
418
|
+
return a = Math.max(a, 3), i = o / a / (2 * s), n = (o - a * i) / a, [i, n];
|
|
419
419
|
}
|
|
420
|
-
function
|
|
420
|
+
function me(o) {
|
|
421
421
|
switch (o) {
|
|
422
422
|
case "small":
|
|
423
423
|
return 2;
|
|
@@ -431,24 +431,24 @@ function ce(o) {
|
|
|
431
431
|
return 3;
|
|
432
432
|
}
|
|
433
433
|
}
|
|
434
|
-
function
|
|
434
|
+
function ge(o) {
|
|
435
435
|
return Array.isArray(o) && o.length > 1 ? o[0] + o[1] : 0;
|
|
436
436
|
}
|
|
437
|
-
function
|
|
437
|
+
function Xt(o) {
|
|
438
438
|
return {
|
|
439
|
-
width: Math.max(
|
|
440
|
-
height: Math.max(
|
|
439
|
+
width: Math.max(Yt.MIN_SIZE, o.width() * o.scaleX()),
|
|
440
|
+
height: Math.max(Yt.MIN_SIZE, o.height() * o.scaleY())
|
|
441
441
|
};
|
|
442
442
|
}
|
|
443
443
|
class bt {
|
|
444
444
|
constructor(e, t) {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
445
|
+
D(this, "core");
|
|
446
|
+
D(this, "node");
|
|
447
|
+
D(this, "element");
|
|
448
|
+
D(this, "toolTypeChangeHandler");
|
|
449
449
|
this.core = e, this.node = t, this.element = this.createElement(), this.toolTypeChangeHandler = (s) => {
|
|
450
|
-
const
|
|
451
|
-
this.element.listening(
|
|
450
|
+
const i = s === "select";
|
|
451
|
+
this.element.listening(i);
|
|
452
452
|
}, this.toolTypeChangeHandler(this.core.getToolType()), this.core.on("toolType:change", this.toolTypeChangeHandler);
|
|
453
453
|
}
|
|
454
454
|
/**
|
|
@@ -470,13 +470,13 @@ class bt {
|
|
|
470
470
|
this.core.off("toolType:change", this.toolTypeChangeHandler), this.element.destroy();
|
|
471
471
|
}
|
|
472
472
|
}
|
|
473
|
-
function
|
|
473
|
+
function pe(o, e) {
|
|
474
474
|
if (!e || e === 0)
|
|
475
475
|
return null;
|
|
476
|
-
const t = new
|
|
476
|
+
const t = new Y.Animation((s) => {
|
|
477
477
|
if (!s) return;
|
|
478
|
-
const
|
|
479
|
-
o.dashOffset(
|
|
478
|
+
const i = -s.time / 10 % e;
|
|
479
|
+
o.dashOffset(i);
|
|
480
480
|
}, o.getLayer());
|
|
481
481
|
return {
|
|
482
482
|
start: () => t.start(),
|
|
@@ -484,13 +484,13 @@ function le(o, e) {
|
|
|
484
484
|
isRunning: () => t.isRunning()
|
|
485
485
|
};
|
|
486
486
|
}
|
|
487
|
-
var
|
|
488
|
-
class
|
|
487
|
+
var b, X, vt, Nt, Vt;
|
|
488
|
+
class ue extends bt {
|
|
489
489
|
constructor(t, s) {
|
|
490
490
|
super(t, s);
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
s.style.animated &&
|
|
491
|
+
l(this, X);
|
|
492
|
+
l(this, b, null);
|
|
493
|
+
s.style.animated && _(this, X, vt).call(this), _(this, X, Vt).call(this, this.getElement());
|
|
494
494
|
}
|
|
495
495
|
createElement() {
|
|
496
496
|
const t = Math.max(
|
|
@@ -499,22 +499,22 @@ class me extends bt {
|
|
|
499
499
|
), s = Math.max(
|
|
500
500
|
this.node.props.height ?? u.MIN_SIZE,
|
|
501
501
|
u.MIN_SIZE
|
|
502
|
-
),
|
|
502
|
+
), i = {
|
|
503
503
|
id: this.node.id,
|
|
504
504
|
...this.node.props,
|
|
505
505
|
...this.node.style,
|
|
506
506
|
width: t,
|
|
507
507
|
height: s,
|
|
508
508
|
cornerRadius: u.CORNER_RADIUS,
|
|
509
|
-
name:
|
|
509
|
+
name: j,
|
|
510
510
|
draggable: !0,
|
|
511
511
|
stroke: "black",
|
|
512
512
|
strokeWidth: 2
|
|
513
|
-
},
|
|
514
|
-
return
|
|
513
|
+
}, n = new Y.Rect(i);
|
|
514
|
+
return n.setAttrs({
|
|
515
515
|
width: t,
|
|
516
516
|
height: s
|
|
517
|
-
}),
|
|
517
|
+
}), n;
|
|
518
518
|
}
|
|
519
519
|
/**
|
|
520
520
|
* 获取 Konva.Rect 实例
|
|
@@ -540,86 +540,86 @@ class me extends bt {
|
|
|
540
540
|
};
|
|
541
541
|
const s = this.getElement();
|
|
542
542
|
s.x(this.node.props.x), s.y(this.node.props.y);
|
|
543
|
-
const
|
|
543
|
+
const i = Math.max(
|
|
544
544
|
this.node.props.width ?? u.MIN_SIZE,
|
|
545
545
|
u.MIN_SIZE
|
|
546
|
-
),
|
|
546
|
+
), n = Math.max(
|
|
547
547
|
this.node.props.height ?? u.MIN_SIZE,
|
|
548
548
|
u.MIN_SIZE
|
|
549
549
|
);
|
|
550
|
-
s.width(
|
|
550
|
+
s.width(i), s.height(n), this.node.style.animated && !r(this, b) ? _(this, X, vt).call(this) : !this.node.style.animated && r(this, b) && _(this, X, Nt).call(this);
|
|
551
551
|
}
|
|
552
552
|
/**
|
|
553
553
|
* 销毁
|
|
554
554
|
*/
|
|
555
555
|
destroy() {
|
|
556
|
-
|
|
556
|
+
_(this, X, Nt).call(this), super.destroy();
|
|
557
557
|
}
|
|
558
558
|
}
|
|
559
|
-
|
|
559
|
+
b = new WeakMap(), X = new WeakSet(), /**
|
|
560
560
|
* 初始化动画
|
|
561
561
|
*/
|
|
562
562
|
vt = function() {
|
|
563
563
|
const t = this.getElement(), s = t.dash();
|
|
564
564
|
if (!s || s.length === 0) return;
|
|
565
|
-
const
|
|
566
|
-
N(this,
|
|
565
|
+
const i = ge(s);
|
|
566
|
+
N(this, b, pe(t, i)), r(this, b) && r(this, b).start();
|
|
567
567
|
}, /**
|
|
568
568
|
* 销毁动画
|
|
569
569
|
*/
|
|
570
570
|
Nt = function() {
|
|
571
|
-
r(this,
|
|
571
|
+
r(this, b) && (r(this, b).stop(), N(this, b, null));
|
|
572
572
|
}, /**
|
|
573
573
|
* 设置事件处理器
|
|
574
574
|
*/
|
|
575
|
-
|
|
575
|
+
Vt = function(t = void 0) {
|
|
576
576
|
const s = t ?? this.getElement();
|
|
577
577
|
s.on("transformstart", () => {
|
|
578
|
-
this.node.style.animated && r(this,
|
|
579
|
-
}), s.on("transform", (
|
|
580
|
-
const
|
|
578
|
+
this.node.style.animated && r(this, b) && r(this, b).stop();
|
|
579
|
+
}), s.on("transform", (i) => {
|
|
580
|
+
const n = i.target, { width: a, height: h } = Xt(n), c = de(a, h, u.CORNER_RADIUS), d = le(
|
|
581
581
|
c,
|
|
582
|
-
|
|
582
|
+
me(this.node.style.size),
|
|
583
583
|
this.node.style.line
|
|
584
584
|
);
|
|
585
|
-
|
|
586
|
-
}), s.on("transformend", (
|
|
587
|
-
const
|
|
585
|
+
n.scale({ x: 1, y: 1 }), n.width(a), n.height(h), n.dash(d.map((g) => g * this.core.getStageScale()));
|
|
586
|
+
}), s.on("transformend", (i) => {
|
|
587
|
+
const n = i.target, { width: a, height: h } = Xt(n), c = {
|
|
588
588
|
...this.node.props,
|
|
589
|
-
x:
|
|
590
|
-
y:
|
|
589
|
+
x: n.x(),
|
|
590
|
+
y: n.y(),
|
|
591
591
|
width: a,
|
|
592
592
|
height: h,
|
|
593
|
-
rotation:
|
|
593
|
+
rotation: n.rotation()
|
|
594
594
|
};
|
|
595
595
|
this.node.props = c, this.core._syncNodeFromElement(this.node.id, {
|
|
596
596
|
props: c
|
|
597
|
-
}), this.node.style.animated && r(this,
|
|
598
|
-
}), s.on("dragend", (
|
|
599
|
-
const
|
|
597
|
+
}), this.node.style.animated && r(this, b)?.isRunning() === !1 && r(this, b).start();
|
|
598
|
+
}), s.on("dragend", (i) => {
|
|
599
|
+
const n = i.target, a = {
|
|
600
600
|
...this.node.props,
|
|
601
|
-
x:
|
|
602
|
-
y:
|
|
601
|
+
x: n.x(),
|
|
602
|
+
y: n.y()
|
|
603
603
|
};
|
|
604
604
|
this.node.props = a, this.core._syncNodeFromElement(this.node.id, {
|
|
605
605
|
props: a
|
|
606
606
|
});
|
|
607
607
|
});
|
|
608
608
|
};
|
|
609
|
-
var k, St,
|
|
610
|
-
class
|
|
609
|
+
var k, St, Ut, Mt, _t;
|
|
610
|
+
class ye extends bt {
|
|
611
611
|
constructor(t, s) {
|
|
612
612
|
super(t, s);
|
|
613
|
-
|
|
614
|
-
|
|
613
|
+
l(this, k);
|
|
614
|
+
_(this, k, St).call(this), _(this, k, Ut).call(this, this.getElement());
|
|
615
615
|
}
|
|
616
616
|
createElement() {
|
|
617
617
|
const t = document.createElement("canvas");
|
|
618
|
-
return t.width = 1, t.height = 1, new
|
|
618
|
+
return t.width = 1, t.height = 1, new Y.Image({
|
|
619
619
|
id: this.node.id,
|
|
620
620
|
x: this.node.props.x,
|
|
621
621
|
y: this.node.props.y,
|
|
622
|
-
name:
|
|
622
|
+
name: j,
|
|
623
623
|
draggable: !0,
|
|
624
624
|
image: t
|
|
625
625
|
});
|
|
@@ -652,10 +652,10 @@ class ge extends bt {
|
|
|
652
652
|
};
|
|
653
653
|
const s = this.getElement();
|
|
654
654
|
if (s.x(this.node.props.x), s.y(this.node.props.y), this.node.props.width && this.node.props.height) {
|
|
655
|
-
const
|
|
656
|
-
s.width(
|
|
655
|
+
const i = Math.max(this.node.props.width, F.MIN_SIZE), n = Math.max(this.node.props.height, F.MIN_SIZE);
|
|
656
|
+
s.width(i), s.height(n);
|
|
657
657
|
}
|
|
658
|
-
this.node.props.rotation !== void 0 && s.rotation(this.node.props.rotation), t.meta?.imageUrl && t.meta.imageUrl !== this.node.meta.imageUrl &&
|
|
658
|
+
this.node.props.rotation !== void 0 && s.rotation(this.node.props.rotation), t.meta?.imageUrl && t.meta.imageUrl !== this.node.meta.imageUrl && _(this, k, St).call(this);
|
|
659
659
|
}
|
|
660
660
|
/**
|
|
661
661
|
* 销毁
|
|
@@ -676,41 +676,41 @@ St = function() {
|
|
|
676
676
|
const s = new window.Image();
|
|
677
677
|
s.crossOrigin = "anonymous", s.src = t, s.onload = () => {
|
|
678
678
|
this.getElement().image(s);
|
|
679
|
-
const
|
|
680
|
-
this.getElement().width(Math.max(
|
|
679
|
+
const i = this.node.props.width ?? s.width, n = this.node.props.height ?? s.height;
|
|
680
|
+
this.getElement().width(Math.max(i, F.MIN_SIZE)), this.getElement().height(Math.max(n, F.MIN_SIZE));
|
|
681
681
|
}, s.onerror = () => {
|
|
682
682
|
console.error("Failed to load image:", t);
|
|
683
683
|
};
|
|
684
684
|
}, /**
|
|
685
685
|
* 设置事件处理器
|
|
686
686
|
*/
|
|
687
|
-
|
|
687
|
+
Ut = function(t) {
|
|
688
688
|
t.on("transform", (s) => {
|
|
689
|
-
const
|
|
690
|
-
|
|
689
|
+
const i = s.target, n = Math.max(F.MIN_SIZE, i.width() * i.scaleX()), a = Math.max(F.MIN_SIZE, i.height() * i.scaleY());
|
|
690
|
+
i.scale({ x: 1, y: 1 }), i.width(n), i.height(a), _(this, k, Mt).call(this);
|
|
691
691
|
}), t.on("transformend", (s) => {
|
|
692
|
-
const
|
|
692
|
+
const i = s.target, n = {
|
|
693
693
|
...this.node.props,
|
|
694
|
-
x:
|
|
695
|
-
y:
|
|
696
|
-
width:
|
|
697
|
-
height:
|
|
698
|
-
rotation:
|
|
694
|
+
x: i.x(),
|
|
695
|
+
y: i.y(),
|
|
696
|
+
width: i.width(),
|
|
697
|
+
height: i.height(),
|
|
698
|
+
rotation: i.rotation()
|
|
699
699
|
};
|
|
700
|
-
this.node.props =
|
|
701
|
-
props:
|
|
702
|
-
}),
|
|
700
|
+
this.node.props = n, this.core._syncNodeFromElement(this.node.id, {
|
|
701
|
+
props: n
|
|
702
|
+
}), _(this, k, _t).call(this);
|
|
703
703
|
}), t.on("dragmove", () => {
|
|
704
|
-
|
|
704
|
+
_(this, k, Mt).call(this);
|
|
705
705
|
}), t.on("dragend", (s) => {
|
|
706
|
-
const
|
|
706
|
+
const i = s.target, n = {
|
|
707
707
|
...this.node.props,
|
|
708
|
-
x:
|
|
709
|
-
y:
|
|
708
|
+
x: i.x(),
|
|
709
|
+
y: i.y()
|
|
710
710
|
};
|
|
711
|
-
this.node.props =
|
|
712
|
-
props:
|
|
713
|
-
}),
|
|
711
|
+
this.node.props = n, this.core._syncNodeFromElement(this.node.id, {
|
|
712
|
+
props: n
|
|
713
|
+
}), _(this, k, _t).call(this);
|
|
714
714
|
});
|
|
715
715
|
}, /**
|
|
716
716
|
* 同步 image-marker 节点的位置(实时更新 Konva 元素)
|
|
@@ -718,15 +718,15 @@ zt = function(t) {
|
|
|
718
718
|
Mt = function() {
|
|
719
719
|
const t = this.getElement(), s = t.getLayer();
|
|
720
720
|
if (!s) return;
|
|
721
|
-
const
|
|
722
|
-
(
|
|
723
|
-
),
|
|
724
|
-
c.forEach((
|
|
725
|
-
const
|
|
726
|
-
if (
|
|
727
|
-
const { start: p, end:
|
|
728
|
-
|
|
729
|
-
|
|
721
|
+
const i = t.x(), n = t.y(), a = t.width(), h = t.height(), c = s.find(
|
|
722
|
+
(g) => g.hasName(this.node.id)
|
|
723
|
+
), d = this.core.getState().nodes || [];
|
|
724
|
+
c.forEach((g) => {
|
|
725
|
+
const x = d.find((p) => p.id === g.id());
|
|
726
|
+
if (x?.type === "image-marker" && x.meta.relativePosition) {
|
|
727
|
+
const { start: p, end: M } = x.meta.relativePosition, I = i + p.percentX / 100 * a, E = n + p.percentY / 100 * h, z = i + M.percentX / 100 * a, P = n + M.percentY / 100 * h, ft = Math.min(I, z), L = Math.min(E, P), V = Math.abs(z - I), G = Math.abs(P - E);
|
|
728
|
+
g.position({ x: ft, y: L }), g.setAttrs({ width: V, height: G }), g.getChildren().forEach((C) => {
|
|
729
|
+
C.getClassName() === "Rect" ? C.setAttrs({ width: V, height: G }) : C.getClassName() === "Group" && C.setAttrs({ x: V, y: G });
|
|
730
730
|
});
|
|
731
731
|
}
|
|
732
732
|
});
|
|
@@ -737,29 +737,29 @@ _t = function() {
|
|
|
737
737
|
const s = this.getElement().getLayer();
|
|
738
738
|
if (!s) return;
|
|
739
739
|
s.find(
|
|
740
|
-
(
|
|
741
|
-
).forEach((
|
|
742
|
-
this.core._syncNodeFromElement(
|
|
740
|
+
(n) => n.hasName(this.node.id)
|
|
741
|
+
).forEach((n) => {
|
|
742
|
+
this.core._syncNodeFromElement(n.id(), {
|
|
743
743
|
props: {
|
|
744
|
-
x:
|
|
745
|
-
y:
|
|
746
|
-
width:
|
|
747
|
-
height:
|
|
744
|
+
x: n.x(),
|
|
745
|
+
y: n.y(),
|
|
746
|
+
width: n.width(),
|
|
747
|
+
height: n.height()
|
|
748
748
|
}
|
|
749
749
|
});
|
|
750
750
|
});
|
|
751
751
|
};
|
|
752
|
-
var H, T,
|
|
753
|
-
class
|
|
752
|
+
var H, T, J, Q, yt, Ht;
|
|
753
|
+
class fe extends bt {
|
|
754
754
|
constructor(t, s) {
|
|
755
755
|
super(t, s);
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
const
|
|
762
|
-
N(this, H,
|
|
756
|
+
l(this, yt);
|
|
757
|
+
l(this, H);
|
|
758
|
+
l(this, T);
|
|
759
|
+
l(this, J);
|
|
760
|
+
l(this, Q);
|
|
761
|
+
const i = this.getElement();
|
|
762
|
+
N(this, H, i.findOne(".rect")), N(this, T, i.findOne(".marker-group")), N(this, J, r(this, T).findOne("Circle")), N(this, Q, r(this, T).findOne("Text")), _(this, yt, Ht).call(this);
|
|
763
763
|
}
|
|
764
764
|
createElement() {
|
|
765
765
|
const t = Math.max(
|
|
@@ -768,14 +768,14 @@ class pe extends bt {
|
|
|
768
768
|
), s = Math.max(
|
|
769
769
|
this.node.props.height ?? u.MIN_SIZE,
|
|
770
770
|
u.MIN_SIZE
|
|
771
|
-
),
|
|
771
|
+
), i = new Y.Group({
|
|
772
772
|
id: this.node.id,
|
|
773
773
|
name: `static ${this.node.meta.parent}`,
|
|
774
774
|
x: this.node.props.x,
|
|
775
775
|
y: this.node.props.y,
|
|
776
776
|
width: t,
|
|
777
777
|
height: s
|
|
778
|
-
}),
|
|
778
|
+
}), n = new Y.Rect({
|
|
779
779
|
name: "rect",
|
|
780
780
|
x: 0,
|
|
781
781
|
y: 0,
|
|
@@ -786,16 +786,16 @@ class pe extends bt {
|
|
|
786
786
|
dash: [5, 5],
|
|
787
787
|
fill: "transparent",
|
|
788
788
|
cornerRadius: u.CORNER_RADIUS
|
|
789
|
-
}), a = new
|
|
789
|
+
}), a = new Y.Group({
|
|
790
790
|
name: "marker-group",
|
|
791
791
|
x: t,
|
|
792
792
|
y: s
|
|
793
|
-
}), c = 16 / this.core.getStageScale(),
|
|
793
|
+
}), c = 16 / this.core.getStageScale(), d = new Y.Circle({
|
|
794
794
|
radius: c,
|
|
795
795
|
fill: "red",
|
|
796
796
|
stroke: "black",
|
|
797
797
|
strokeWidth: 2
|
|
798
|
-
}),
|
|
798
|
+
}), g = new Y.Text({
|
|
799
799
|
x: -c,
|
|
800
800
|
y: -c,
|
|
801
801
|
width: c * 2,
|
|
@@ -806,7 +806,7 @@ class pe extends bt {
|
|
|
806
806
|
fontSize: 16,
|
|
807
807
|
fill: "white"
|
|
808
808
|
});
|
|
809
|
-
return a.add(
|
|
809
|
+
return a.add(d), a.add(g), i.add(n), i.add(a), i;
|
|
810
810
|
}
|
|
811
811
|
/**
|
|
812
812
|
* 获取 Konva.Group 实例
|
|
@@ -836,14 +836,14 @@ class pe extends bt {
|
|
|
836
836
|
};
|
|
837
837
|
const s = this.getElement();
|
|
838
838
|
s.x(this.node.props.x), s.y(this.node.props.y);
|
|
839
|
-
const
|
|
839
|
+
const i = Math.max(
|
|
840
840
|
this.node.props.width ?? u.MIN_SIZE,
|
|
841
841
|
u.MIN_SIZE
|
|
842
|
-
),
|
|
842
|
+
), n = Math.max(
|
|
843
843
|
this.node.props.height ?? u.MIN_SIZE,
|
|
844
844
|
u.MIN_SIZE
|
|
845
845
|
);
|
|
846
|
-
s.width(
|
|
846
|
+
s.width(i), s.height(n), r(this, H).width(i), r(this, H).height(n), r(this, T).x(i), r(this, T).y(n), t.style?.color && r(this, H).stroke(t.style.color), t.meta?.markerNumber !== void 0 && r(this, Q).text(String(t.meta.markerNumber));
|
|
847
847
|
}
|
|
848
848
|
/**
|
|
849
849
|
* 销毁
|
|
@@ -855,14 +855,14 @@ class pe extends bt {
|
|
|
855
855
|
* 更新焦点状态(hover 或 selected)
|
|
856
856
|
*/
|
|
857
857
|
setFocusState(t) {
|
|
858
|
-
const s = t ? 3 : 2,
|
|
859
|
-
r(this, H).strokeWidth(s), r(this,
|
|
858
|
+
const s = t ? 3 : 2, i = t ? 1.2 : 1;
|
|
859
|
+
r(this, H).strokeWidth(s), r(this, J).strokeWidth(s), r(this, T).scaleX(i), r(this, T).scaleY(i);
|
|
860
860
|
}
|
|
861
861
|
}
|
|
862
|
-
H = new WeakMap(), T = new WeakMap(),
|
|
862
|
+
H = new WeakMap(), T = new WeakMap(), J = new WeakMap(), Q = new WeakMap(), yt = new WeakSet(), /**
|
|
863
863
|
* 设置事件处理器
|
|
864
864
|
*/
|
|
865
|
-
|
|
865
|
+
Ht = function() {
|
|
866
866
|
r(this, T).on("pointerover", () => {
|
|
867
867
|
this.setFocusState(!0), this.core.setCursor("pointer");
|
|
868
868
|
}), r(this, T).on("pointerout", () => {
|
|
@@ -872,22 +872,22 @@ At = function() {
|
|
|
872
872
|
this.core.selectNode(this.node.id);
|
|
873
873
|
});
|
|
874
874
|
};
|
|
875
|
-
function
|
|
875
|
+
function zt(o, e, t) {
|
|
876
876
|
switch (e) {
|
|
877
877
|
case "rectangle":
|
|
878
|
-
return new
|
|
878
|
+
return new ue(o, t);
|
|
879
879
|
case "image":
|
|
880
|
-
return new
|
|
880
|
+
return new ye(o, t);
|
|
881
881
|
case "image-marker":
|
|
882
|
-
return new
|
|
882
|
+
return new fe(o, t);
|
|
883
883
|
default:
|
|
884
884
|
return null;
|
|
885
885
|
}
|
|
886
886
|
}
|
|
887
|
-
const
|
|
888
|
-
const
|
|
887
|
+
const xe = (o, e, t, s) => {
|
|
888
|
+
const i = {
|
|
889
889
|
type: o,
|
|
890
|
-
id:
|
|
890
|
+
id: K(),
|
|
891
891
|
text: null,
|
|
892
892
|
style: {
|
|
893
893
|
opacity: 1,
|
|
@@ -905,21 +905,21 @@ const ue = (o, e, t, s) => {
|
|
|
905
905
|
meta: s ?? {}
|
|
906
906
|
};
|
|
907
907
|
return o === "image-marker" ? {
|
|
908
|
-
...
|
|
908
|
+
...i,
|
|
909
909
|
style: {
|
|
910
|
-
...
|
|
910
|
+
...i.style,
|
|
911
911
|
color: "#ff0000",
|
|
912
912
|
line: "dashed"
|
|
913
913
|
}
|
|
914
|
-
} :
|
|
914
|
+
} : i;
|
|
915
915
|
};
|
|
916
|
-
function
|
|
916
|
+
function we(o, e, t) {
|
|
917
917
|
let s = e;
|
|
918
918
|
o.type === "image-marker" && t && (s = {
|
|
919
919
|
x: Math.max(t.x, Math.min(t.x + t.width, e.x)),
|
|
920
920
|
y: Math.max(t.y, Math.min(t.y + t.height, e.y))
|
|
921
921
|
});
|
|
922
|
-
const [
|
|
922
|
+
const [i, n] = ve(
|
|
923
923
|
{ x: o.props.x, y: o.props.y },
|
|
924
924
|
s
|
|
925
925
|
);
|
|
@@ -927,22 +927,22 @@ function fe(o, e, t) {
|
|
|
927
927
|
...o,
|
|
928
928
|
props: {
|
|
929
929
|
...o.props,
|
|
930
|
-
x:
|
|
931
|
-
y:
|
|
932
|
-
width: Math.max(
|
|
933
|
-
height: Math.max(
|
|
930
|
+
x: i.x,
|
|
931
|
+
y: i.y,
|
|
932
|
+
width: Math.max(n.x - i.x, u.MIN_SIZE),
|
|
933
|
+
height: Math.max(n.y - i.y, u.MIN_SIZE)
|
|
934
934
|
}
|
|
935
935
|
} : o;
|
|
936
936
|
}
|
|
937
|
-
function
|
|
938
|
-
let t = o.x, s = o.y,
|
|
939
|
-
return t >
|
|
937
|
+
function ve(o, e) {
|
|
938
|
+
let t = o.x, s = o.y, i = e.x, n = e.y, a;
|
|
939
|
+
return t > i && (a = Math.abs(t - i), t = i, i = t + a), s > n && (a = Math.abs(s - n), s = n, n = s + a), [
|
|
940
940
|
{ x: t, y: s },
|
|
941
|
-
{ x:
|
|
941
|
+
{ x: i, y: n }
|
|
942
942
|
];
|
|
943
943
|
}
|
|
944
|
-
var
|
|
945
|
-
class
|
|
944
|
+
var w, Z, A, S;
|
|
945
|
+
class Ne extends ce {
|
|
946
946
|
constructor(t) {
|
|
947
947
|
super({
|
|
948
948
|
viewport: {
|
|
@@ -955,29 +955,29 @@ class xe extends oe {
|
|
|
955
955
|
toolType: "select",
|
|
956
956
|
nodes: []
|
|
957
957
|
});
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
N(this,
|
|
958
|
+
l(this, w);
|
|
959
|
+
l(this, Z);
|
|
960
|
+
l(this, A);
|
|
961
|
+
l(this, S, null);
|
|
962
|
+
N(this, w, new ae(this, {
|
|
963
963
|
container: t,
|
|
964
964
|
width: t.clientWidth,
|
|
965
965
|
height: t.clientHeight,
|
|
966
966
|
draggable: !1,
|
|
967
967
|
className: "touch-none"
|
|
968
|
-
})), N(this,
|
|
968
|
+
})), N(this, Z, new Y.Layer()), N(this, A, new he(this)), r(this, w).getStage().add(r(this, Z)), r(this, Z).add(r(this, A).getTransformer()), this.updateViewport(this.getState().viewport, !1);
|
|
969
969
|
}
|
|
970
970
|
/**
|
|
971
971
|
* 获取 CanvasStage 实例
|
|
972
972
|
*/
|
|
973
973
|
getCanvasStage() {
|
|
974
|
-
return r(this,
|
|
974
|
+
return r(this, w);
|
|
975
975
|
}
|
|
976
976
|
/**
|
|
977
977
|
* 获取 CanvasTransformer 实例
|
|
978
978
|
*/
|
|
979
979
|
getCanvasTransformer() {
|
|
980
|
-
return r(this,
|
|
980
|
+
return r(this, A);
|
|
981
981
|
}
|
|
982
982
|
/**
|
|
983
983
|
* 发射事件(供内部类使用)
|
|
@@ -989,19 +989,19 @@ class xe extends oe {
|
|
|
989
989
|
* 获取 Konva.Stage 实例
|
|
990
990
|
*/
|
|
991
991
|
getStage() {
|
|
992
|
-
return r(this,
|
|
992
|
+
return r(this, w).getStage();
|
|
993
993
|
}
|
|
994
994
|
/**
|
|
995
995
|
* 获取 Stage 容器元素
|
|
996
996
|
*/
|
|
997
997
|
getContainer() {
|
|
998
|
-
return r(this,
|
|
998
|
+
return r(this, w).getStage().container();
|
|
999
999
|
}
|
|
1000
1000
|
/**
|
|
1001
1001
|
* 获取主图层
|
|
1002
1002
|
*/
|
|
1003
1003
|
getMainLayer() {
|
|
1004
|
-
return r(this,
|
|
1004
|
+
return r(this, Z);
|
|
1005
1005
|
}
|
|
1006
1006
|
/**
|
|
1007
1007
|
* 获取当前工具类型
|
|
@@ -1018,59 +1018,59 @@ class xe extends oe {
|
|
|
1018
1018
|
toolType: t
|
|
1019
1019
|
},
|
|
1020
1020
|
!1
|
|
1021
|
-
), this.emit("toolType:change", t), t === "hand" ? (r(this,
|
|
1021
|
+
), this.emit("toolType:change", t), t === "hand" ? (r(this, w).setDraggable(!0), r(this, w).setCursor("grab")) : (r(this, w).setDraggable(!1), r(this, w).resetCursor());
|
|
1022
1022
|
}
|
|
1023
1023
|
/**
|
|
1024
1024
|
* 设置是否可拖拽(内部使用)
|
|
1025
1025
|
*/
|
|
1026
1026
|
setDraggable(t) {
|
|
1027
|
-
r(this,
|
|
1027
|
+
r(this, w).setDraggable(t);
|
|
1028
1028
|
}
|
|
1029
1029
|
/**
|
|
1030
1030
|
* 设置光标
|
|
1031
1031
|
* @internal 仅供内部使用
|
|
1032
1032
|
*/
|
|
1033
1033
|
setCursor(t) {
|
|
1034
|
-
r(this,
|
|
1034
|
+
r(this, w).setCursor(t);
|
|
1035
1035
|
}
|
|
1036
1036
|
/**
|
|
1037
1037
|
* 重置光标
|
|
1038
1038
|
* @internal 仅供内部使用
|
|
1039
1039
|
*/
|
|
1040
1040
|
resetCursor() {
|
|
1041
|
-
r(this,
|
|
1041
|
+
r(this, w).resetCursor();
|
|
1042
1042
|
}
|
|
1043
1043
|
/**
|
|
1044
1044
|
* 获取当前 Stage 缩放比例
|
|
1045
1045
|
*/
|
|
1046
1046
|
getStageScale() {
|
|
1047
|
-
return r(this,
|
|
1047
|
+
return r(this, w).getStage().scaleX();
|
|
1048
1048
|
}
|
|
1049
1049
|
/**
|
|
1050
1050
|
* 更新视口位置
|
|
1051
1051
|
* @internal 仅供内部使用,外部请使用 CanvasApi
|
|
1052
1052
|
*/
|
|
1053
1053
|
updateViewport(t, s = !1) {
|
|
1054
|
-
r(this,
|
|
1055
|
-
const
|
|
1054
|
+
r(this, w).setViewport(t);
|
|
1055
|
+
const i = {
|
|
1056
1056
|
...this.getState().viewport,
|
|
1057
1057
|
...t
|
|
1058
1058
|
};
|
|
1059
1059
|
this._updateState(
|
|
1060
1060
|
{
|
|
1061
|
-
viewport:
|
|
1061
|
+
viewport: i
|
|
1062
1062
|
},
|
|
1063
1063
|
s
|
|
1064
|
-
), this.emit("viewport:change",
|
|
1064
|
+
), this.emit("viewport:change", i), r(this, A).emitPositionChange();
|
|
1065
1065
|
}
|
|
1066
1066
|
createNodes(t) {
|
|
1067
|
-
t.map((
|
|
1068
|
-
r(this,
|
|
1067
|
+
t.map((n) => zt(this, n.type, n)).filter((n) => n !== null).forEach((n) => {
|
|
1068
|
+
r(this, Z).add(n.getElement());
|
|
1069
1069
|
});
|
|
1070
|
-
const
|
|
1070
|
+
const i = [...this.getState().nodes || [], ...t];
|
|
1071
1071
|
this._updateState(
|
|
1072
1072
|
{
|
|
1073
|
-
nodes:
|
|
1073
|
+
nodes: i
|
|
1074
1074
|
},
|
|
1075
1075
|
!0
|
|
1076
1076
|
);
|
|
@@ -1078,20 +1078,20 @@ class xe extends oe {
|
|
|
1078
1078
|
/**
|
|
1079
1079
|
* 创建图片标注节点(内部使用)
|
|
1080
1080
|
*/
|
|
1081
|
-
createImageMarkerNode(t, s,
|
|
1081
|
+
createImageMarkerNode(t, s, i, n) {
|
|
1082
1082
|
const a = this.getState().nodes || [];
|
|
1083
1083
|
let h = 0;
|
|
1084
|
-
a.forEach((
|
|
1085
|
-
|
|
1084
|
+
a.forEach((P) => {
|
|
1085
|
+
P.type === "image-marker" && P.meta.parent === t && typeof P.meta.markerNumber == "number" && (h = Math.max(h, P.meta.markerNumber));
|
|
1086
1086
|
});
|
|
1087
|
-
const c = (s.x -
|
|
1088
|
-
id:
|
|
1087
|
+
const c = (s.x - n.x) / n.width * 100, d = (s.y - n.y) / n.height * 100, g = (i.x - n.x) / n.width * 100, x = (i.y - n.y) / n.height * 100, p = Math.min(s.x, i.x), M = Math.min(s.y, i.y), I = Math.abs(i.x - s.x), E = Math.abs(i.y - s.y), z = {
|
|
1088
|
+
id: K(),
|
|
1089
1089
|
type: "image-marker",
|
|
1090
1090
|
props: {
|
|
1091
1091
|
x: p,
|
|
1092
|
-
y:
|
|
1093
|
-
width:
|
|
1094
|
-
height:
|
|
1092
|
+
y: M,
|
|
1093
|
+
width: I,
|
|
1094
|
+
height: E,
|
|
1095
1095
|
rotation: 0,
|
|
1096
1096
|
visible: !0
|
|
1097
1097
|
},
|
|
@@ -1107,71 +1107,71 @@ class xe extends oe {
|
|
|
1107
1107
|
relativePosition: {
|
|
1108
1108
|
start: {
|
|
1109
1109
|
percentX: Math.max(0, Math.min(100, c)),
|
|
1110
|
-
percentY: Math.max(0, Math.min(100,
|
|
1110
|
+
percentY: Math.max(0, Math.min(100, d))
|
|
1111
1111
|
},
|
|
1112
1112
|
end: {
|
|
1113
|
-
percentX: Math.max(0, Math.min(100,
|
|
1114
|
-
percentY: Math.max(0, Math.min(100,
|
|
1113
|
+
percentX: Math.max(0, Math.min(100, g)),
|
|
1114
|
+
percentY: Math.max(0, Math.min(100, x))
|
|
1115
1115
|
}
|
|
1116
1116
|
}
|
|
1117
1117
|
}
|
|
1118
1118
|
};
|
|
1119
|
-
this.createNodes([
|
|
1119
|
+
this.createNodes([z]);
|
|
1120
1120
|
}
|
|
1121
1121
|
/**
|
|
1122
1122
|
* 在指定位置查找图片节点
|
|
1123
1123
|
* @internal 仅供内部使用
|
|
1124
1124
|
*/
|
|
1125
1125
|
findImageAtPosition(t) {
|
|
1126
|
-
const s = r(this,
|
|
1126
|
+
const s = r(this, w).getStage(), i = s.find(
|
|
1127
1127
|
(a) => a.getClassName() === "Image"
|
|
1128
|
-
),
|
|
1128
|
+
), n = i.map(
|
|
1129
1129
|
(a) => a.listening()
|
|
1130
1130
|
);
|
|
1131
|
-
|
|
1131
|
+
i.forEach((a) => a.listening(!0));
|
|
1132
1132
|
try {
|
|
1133
1133
|
const h = s.getAllIntersections(t).filter(
|
|
1134
1134
|
(c) => c.getClassName() === "Image"
|
|
1135
1135
|
);
|
|
1136
1136
|
return h.length === 0 ? null : h[h.length - 1];
|
|
1137
1137
|
} finally {
|
|
1138
|
-
|
|
1139
|
-
a.listening(
|
|
1138
|
+
i.forEach((a, h) => {
|
|
1139
|
+
a.listening(n[h]);
|
|
1140
1140
|
});
|
|
1141
1141
|
}
|
|
1142
1142
|
}
|
|
1143
1143
|
/**
|
|
1144
1144
|
* @internal 仅供内部使用
|
|
1145
1145
|
*/
|
|
1146
|
-
createDraftNode(t, s,
|
|
1146
|
+
createDraftNode(t, s, i) {
|
|
1147
1147
|
r(this, S) && r(this, S).destroy();
|
|
1148
|
-
const
|
|
1149
|
-
N(this, S,
|
|
1148
|
+
const n = xe(t, s, void 0, i);
|
|
1149
|
+
N(this, S, zt(this, t, n)), console.log(r(this, S)), r(this, S) && r(this, Z).add(r(this, S).getElement());
|
|
1150
1150
|
}
|
|
1151
1151
|
/**
|
|
1152
1152
|
* @internal 仅供内部使用
|
|
1153
1153
|
*/
|
|
1154
1154
|
updateDraftNode(t, s) {
|
|
1155
1155
|
if (!r(this, S)) return;
|
|
1156
|
-
const
|
|
1157
|
-
r(this, S).updateNode(
|
|
1156
|
+
const i = r(this, S).getNode(), n = we(i, t, s);
|
|
1157
|
+
r(this, S).updateNode(n);
|
|
1158
1158
|
}
|
|
1159
1159
|
/**
|
|
1160
1160
|
* @internal 仅供内部使用
|
|
1161
1161
|
*/
|
|
1162
1162
|
finalizeDraftNode() {
|
|
1163
1163
|
if (!r(this, S)) return;
|
|
1164
|
-
const t =
|
|
1164
|
+
const t = K(), s = r(this, S).getNode();
|
|
1165
1165
|
if (s.type === "image-marker" && s.meta.parent) {
|
|
1166
|
-
const
|
|
1166
|
+
const n = s.meta.bounds, a = s.meta.startPosition, h = {
|
|
1167
1167
|
x: s.props.x + (s.props.width || 0),
|
|
1168
1168
|
y: s.props.y + (s.props.height || 0)
|
|
1169
1169
|
}, c = this.getState().nodes || [];
|
|
1170
|
-
let
|
|
1171
|
-
c.forEach((
|
|
1172
|
-
|
|
1170
|
+
let d = 0;
|
|
1171
|
+
c.forEach((E) => {
|
|
1172
|
+
E.type === "image-marker" && E.meta.parent === s.meta.parent && typeof E.meta.markerNumber == "number" && (d = Math.max(d, E.meta.markerNumber));
|
|
1173
1173
|
});
|
|
1174
|
-
const
|
|
1174
|
+
const g = (a.x - n.x) / n.width * 100, x = (a.y - n.y) / n.height * 100, p = (h.x - n.x) / n.width * 100, M = (h.y - n.y) / n.height * 100, I = {
|
|
1175
1175
|
...s,
|
|
1176
1176
|
props: {
|
|
1177
1177
|
...s.props
|
|
@@ -1181,25 +1181,25 @@ class xe extends oe {
|
|
|
1181
1181
|
},
|
|
1182
1182
|
meta: {
|
|
1183
1183
|
parent: s.meta.parent,
|
|
1184
|
-
markerNumber:
|
|
1184
|
+
markerNumber: d + 1,
|
|
1185
1185
|
relativePosition: {
|
|
1186
1186
|
start: {
|
|
1187
|
-
percentX: Math.max(0, Math.min(100,
|
|
1188
|
-
percentY: Math.max(0, Math.min(100,
|
|
1187
|
+
percentX: Math.max(0, Math.min(100, g)),
|
|
1188
|
+
percentY: Math.max(0, Math.min(100, x))
|
|
1189
1189
|
},
|
|
1190
1190
|
end: {
|
|
1191
1191
|
percentX: Math.max(0, Math.min(100, p)),
|
|
1192
|
-
percentY: Math.max(0, Math.min(100,
|
|
1192
|
+
percentY: Math.max(0, Math.min(100, M))
|
|
1193
1193
|
}
|
|
1194
1194
|
}
|
|
1195
1195
|
},
|
|
1196
1196
|
id: t,
|
|
1197
1197
|
type: "image-marker"
|
|
1198
1198
|
};
|
|
1199
|
-
this.createNodes([
|
|
1199
|
+
this.createNodes([I]), r(this, S).destroy(), N(this, S, null), this.setToolType("select");
|
|
1200
1200
|
return;
|
|
1201
1201
|
}
|
|
1202
|
-
const
|
|
1202
|
+
const i = {
|
|
1203
1203
|
...s,
|
|
1204
1204
|
props: {
|
|
1205
1205
|
...s.props
|
|
@@ -1212,18 +1212,18 @@ class xe extends oe {
|
|
|
1212
1212
|
},
|
|
1213
1213
|
id: t
|
|
1214
1214
|
};
|
|
1215
|
-
this.createNodes([
|
|
1215
|
+
this.createNodes([i]), r(this, S).destroy(), N(this, S, null), this.setToolType("select");
|
|
1216
1216
|
}
|
|
1217
1217
|
/**
|
|
1218
1218
|
* 选择节点
|
|
1219
1219
|
* @internal 仅供内部使用,外部请使用 CanvasApi
|
|
1220
1220
|
*/
|
|
1221
1221
|
selectNode(t, s = !1) {
|
|
1222
|
-
const
|
|
1223
|
-
if (
|
|
1222
|
+
const i = this.getState().selectedNodeIds ?? [];
|
|
1223
|
+
if (i.length === 0 && !t)
|
|
1224
1224
|
return;
|
|
1225
1225
|
if (!t) {
|
|
1226
|
-
r(this,
|
|
1226
|
+
r(this, A).clearNodes(), this._updateState(
|
|
1227
1227
|
{
|
|
1228
1228
|
selectedNodeIds: []
|
|
1229
1229
|
},
|
|
@@ -1231,15 +1231,15 @@ class xe extends oe {
|
|
|
1231
1231
|
);
|
|
1232
1232
|
return;
|
|
1233
1233
|
}
|
|
1234
|
-
let
|
|
1235
|
-
s ?
|
|
1236
|
-
const a = this.getStage().find(`.${
|
|
1234
|
+
let n = [];
|
|
1235
|
+
s ? n = i.length ? [...i, t] : [t] : n = [t];
|
|
1236
|
+
const a = this.getStage().find(`.${j}`).filter((h) => {
|
|
1237
1237
|
const c = h.id();
|
|
1238
|
-
return
|
|
1238
|
+
return n.includes(c);
|
|
1239
1239
|
});
|
|
1240
|
-
r(this,
|
|
1240
|
+
r(this, A).setNodes(a), this._updateState(
|
|
1241
1241
|
{
|
|
1242
|
-
selectedNodeIds:
|
|
1242
|
+
selectedNodeIds: n
|
|
1243
1243
|
},
|
|
1244
1244
|
!1
|
|
1245
1245
|
);
|
|
@@ -1254,25 +1254,25 @@ class xe extends oe {
|
|
|
1254
1254
|
* 从元素同步节点数据(供节点类内部使用)
|
|
1255
1255
|
*/
|
|
1256
1256
|
_syncNodeFromElement(t, s) {
|
|
1257
|
-
const
|
|
1258
|
-
if (
|
|
1257
|
+
const i = this.getState().nodes || [], n = i.findIndex((c) => c.id === t);
|
|
1258
|
+
if (n === -1) return;
|
|
1259
1259
|
const a = {
|
|
1260
|
-
...n
|
|
1260
|
+
...i[n],
|
|
1261
1261
|
...s,
|
|
1262
1262
|
props: {
|
|
1263
|
-
...n
|
|
1263
|
+
...i[n].props,
|
|
1264
1264
|
...s.props
|
|
1265
1265
|
},
|
|
1266
1266
|
style: {
|
|
1267
|
-
...n
|
|
1267
|
+
...i[n].style,
|
|
1268
1268
|
...s.style
|
|
1269
1269
|
},
|
|
1270
1270
|
meta: {
|
|
1271
|
-
...n
|
|
1271
|
+
...i[n].meta,
|
|
1272
1272
|
...s.meta
|
|
1273
1273
|
}
|
|
1274
|
-
}, h = [...
|
|
1275
|
-
h[
|
|
1274
|
+
}, h = [...i];
|
|
1275
|
+
h[n] = a, this._updateState(
|
|
1276
1276
|
{
|
|
1277
1277
|
nodes: h
|
|
1278
1278
|
},
|
|
@@ -1284,7 +1284,7 @@ class xe extends oe {
|
|
|
1284
1284
|
* 当 undo/redo 时被调用
|
|
1285
1285
|
*/
|
|
1286
1286
|
_syncState(t) {
|
|
1287
|
-
r(this,
|
|
1287
|
+
r(this, w).setViewport({
|
|
1288
1288
|
x: t.viewport.x,
|
|
1289
1289
|
y: t.viewport.y,
|
|
1290
1290
|
scale: t.viewport.scale,
|
|
@@ -1293,8 +1293,8 @@ class xe extends oe {
|
|
|
1293
1293
|
});
|
|
1294
1294
|
}
|
|
1295
1295
|
}
|
|
1296
|
-
|
|
1297
|
-
class
|
|
1296
|
+
w = new WeakMap(), Z = new WeakMap(), A = new WeakMap(), S = new WeakMap();
|
|
1297
|
+
class Se extends Ne {
|
|
1298
1298
|
/**
|
|
1299
1299
|
* 获取所有可用的工具类型
|
|
1300
1300
|
*/
|
|
@@ -1307,6 +1307,13 @@ class we extends xe {
|
|
|
1307
1307
|
setToolType(e) {
|
|
1308
1308
|
super.setToolType(e);
|
|
1309
1309
|
}
|
|
1310
|
+
/**
|
|
1311
|
+
* 手动创建多个节点
|
|
1312
|
+
* 如果你不知道自己在干什么,请使用更高层的封装方法,如 createImageNode
|
|
1313
|
+
*/
|
|
1314
|
+
createNodes(e) {
|
|
1315
|
+
super.createNodes(e);
|
|
1316
|
+
}
|
|
1310
1317
|
/**
|
|
1311
1318
|
* 更新视口位置
|
|
1312
1319
|
*/
|
|
@@ -1317,8 +1324,8 @@ class we extends xe {
|
|
|
1317
1324
|
* 创建图片节点
|
|
1318
1325
|
*/
|
|
1319
1326
|
createImageNode(e, t) {
|
|
1320
|
-
const s = t ?? { x: 100, y: 100 },
|
|
1321
|
-
id:
|
|
1327
|
+
const s = t ?? { x: 100, y: 100 }, i = {
|
|
1328
|
+
id: K(),
|
|
1322
1329
|
type: "image",
|
|
1323
1330
|
props: {
|
|
1324
1331
|
x: s.x,
|
|
@@ -1338,26 +1345,57 @@ class we extends xe {
|
|
|
1338
1345
|
imageUrl: e
|
|
1339
1346
|
}
|
|
1340
1347
|
};
|
|
1341
|
-
this.createNodes([
|
|
1348
|
+
this.createNodes([i]);
|
|
1342
1349
|
}
|
|
1343
1350
|
/**
|
|
1344
1351
|
* 在当前所有节点的左下角插入图片,并将其居中显示
|
|
1352
|
+
* 如果没有节点,插入到画布中心
|
|
1345
1353
|
* @param imageUrl - 图片 URL
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1354
|
+
* @param options - 配置选项
|
|
1355
|
+
* @param options.width - 图片宽度
|
|
1356
|
+
* @param options.height - 图片高度
|
|
1357
|
+
*/
|
|
1358
|
+
insertImageAtBottomLeft(e, t) {
|
|
1359
|
+
const s = this.getState().nodes || [];
|
|
1360
|
+
let i = { x: 0, y: 0 };
|
|
1361
|
+
if (s.length > 0) {
|
|
1362
|
+
const a = this.getMainLayer();
|
|
1363
|
+
let h = 1 / 0, c = -1 / 0;
|
|
1364
|
+
a.children.forEach((d) => {
|
|
1365
|
+
if (d.visible() && d.getClassName() !== "Transformer" && d.hasName(j)) {
|
|
1366
|
+
const g = d.getAttrs(), x = g.x || 0, p = g.y || 0, M = g.height || 0;
|
|
1367
|
+
h = Math.min(h, x), c = Math.max(c, p + M);
|
|
1357
1368
|
}
|
|
1358
|
-
}),
|
|
1369
|
+
}), h !== 1 / 0 && c !== -1 / 0 && (i = { x: h, y: c + 20 });
|
|
1370
|
+
} else {
|
|
1371
|
+
const a = this.getState().viewport;
|
|
1372
|
+
i = {
|
|
1373
|
+
x: (a.width / 2 - a.x) / a.scale,
|
|
1374
|
+
y: (a.height / 2 - a.y) / a.scale
|
|
1375
|
+
};
|
|
1359
1376
|
}
|
|
1360
|
-
|
|
1377
|
+
const n = {
|
|
1378
|
+
id: K(),
|
|
1379
|
+
type: "image",
|
|
1380
|
+
props: {
|
|
1381
|
+
x: i.x,
|
|
1382
|
+
y: i.y,
|
|
1383
|
+
width: t?.width,
|
|
1384
|
+
height: t?.height,
|
|
1385
|
+
rotation: 0,
|
|
1386
|
+
visible: !0
|
|
1387
|
+
},
|
|
1388
|
+
style: {
|
|
1389
|
+
color: "#000000",
|
|
1390
|
+
line: "solid",
|
|
1391
|
+
size: "medium",
|
|
1392
|
+
opacity: 1
|
|
1393
|
+
},
|
|
1394
|
+
meta: {
|
|
1395
|
+
imageUrl: e
|
|
1396
|
+
}
|
|
1397
|
+
};
|
|
1398
|
+
this.createNodes([n]), requestAnimationFrame(() => {
|
|
1361
1399
|
this.scrollToContent({ scale: !0 });
|
|
1362
1400
|
});
|
|
1363
1401
|
}
|
|
@@ -1367,7 +1405,7 @@ class we extends xe {
|
|
|
1367
1405
|
* @returns DataURL 格式的图片数据
|
|
1368
1406
|
*/
|
|
1369
1407
|
exportAsImage(e) {
|
|
1370
|
-
const t = this.getStage(), s = this.getCanvasTransformer().getTransformer(),
|
|
1408
|
+
const t = this.getStage(), s = this.getCanvasTransformer().getTransformer(), i = s.visible();
|
|
1371
1409
|
s.visible(!1);
|
|
1372
1410
|
try {
|
|
1373
1411
|
return t.toDataURL({
|
|
@@ -1376,7 +1414,7 @@ class we extends xe {
|
|
|
1376
1414
|
quality: e?.quality ?? 1
|
|
1377
1415
|
});
|
|
1378
1416
|
} finally {
|
|
1379
|
-
s.visible(
|
|
1417
|
+
s.visible(i);
|
|
1380
1418
|
}
|
|
1381
1419
|
}
|
|
1382
1420
|
/**
|
|
@@ -1388,20 +1426,20 @@ class we extends xe {
|
|
|
1388
1426
|
const t = this.getCanvasTransformer().getPosition();
|
|
1389
1427
|
if (!t)
|
|
1390
1428
|
return console.warn("No selection to export"), null;
|
|
1391
|
-
const s = this.getStage(),
|
|
1392
|
-
|
|
1429
|
+
const s = this.getStage(), i = e?.padding ?? 10, n = this.getCanvasTransformer().getTransformer(), a = n.visible();
|
|
1430
|
+
n.visible(!1);
|
|
1393
1431
|
try {
|
|
1394
1432
|
return s.toDataURL({
|
|
1395
|
-
x: t.x -
|
|
1396
|
-
y: t.y -
|
|
1397
|
-
width: t.width +
|
|
1398
|
-
height: t.height +
|
|
1433
|
+
x: t.x - i,
|
|
1434
|
+
y: t.y - i,
|
|
1435
|
+
width: t.width + i * 2,
|
|
1436
|
+
height: t.height + i * 2,
|
|
1399
1437
|
pixelRatio: e?.pixelRatio ?? 2,
|
|
1400
1438
|
mimeType: e?.mimeType ?? "image/png",
|
|
1401
1439
|
quality: e?.quality ?? 1
|
|
1402
1440
|
});
|
|
1403
1441
|
} finally {
|
|
1404
|
-
|
|
1442
|
+
n.visible(a);
|
|
1405
1443
|
}
|
|
1406
1444
|
}
|
|
1407
1445
|
/**
|
|
@@ -1420,18 +1458,18 @@ class we extends xe {
|
|
|
1420
1458
|
deleteNodes(e) {
|
|
1421
1459
|
if (e.length === 0) return;
|
|
1422
1460
|
const t = this.getState().nodes || [], s = new Set(e);
|
|
1423
|
-
e.forEach((
|
|
1424
|
-
t.find((h) => h.id ===
|
|
1425
|
-
h.type === "image-marker" && h.meta.parent ===
|
|
1461
|
+
e.forEach((n) => {
|
|
1462
|
+
t.find((h) => h.id === n)?.type === "image" && t.forEach((h) => {
|
|
1463
|
+
h.type === "image-marker" && h.meta.parent === n && s.add(h.id);
|
|
1426
1464
|
});
|
|
1427
|
-
}), s.forEach((
|
|
1428
|
-
const a = this.getStage().findOne(`#${
|
|
1465
|
+
}), s.forEach((n) => {
|
|
1466
|
+
const a = this.getStage().findOne(`#${n}`);
|
|
1429
1467
|
a && a.destroy();
|
|
1430
1468
|
});
|
|
1431
|
-
const
|
|
1469
|
+
const i = t.filter((n) => !s.has(n.id));
|
|
1432
1470
|
this.getCanvasTransformer().clearNodes(), this._updateState(
|
|
1433
1471
|
{
|
|
1434
|
-
nodes:
|
|
1472
|
+
nodes: i,
|
|
1435
1473
|
selectedNodeIds: []
|
|
1436
1474
|
},
|
|
1437
1475
|
!0
|
|
@@ -1439,46 +1477,48 @@ class we extends xe {
|
|
|
1439
1477
|
}
|
|
1440
1478
|
/**
|
|
1441
1479
|
* 滚动到内容区域
|
|
1442
|
-
* -
|
|
1480
|
+
* - 如果提供了 nodeIds,将指定的节点居中显示
|
|
1481
|
+
* - 如果没有提供 nodeIds 但有选中的节点,将选中节点居中显示
|
|
1443
1482
|
* - 如果没有选中节点,将所有内容居中显示
|
|
1444
1483
|
* @param options - 配置选项
|
|
1445
1484
|
* @param options.padding - 内容周围的留白,默认 50px
|
|
1446
1485
|
* @param options.scale - 是否自动调整缩放以适应内容,默认 false
|
|
1486
|
+
* @param options.nodeIds - 要滚动到的节点 ID 数组
|
|
1447
1487
|
*/
|
|
1448
1488
|
scrollToContent(e) {
|
|
1449
1489
|
if ((this.getState().nodes || []).length === 0) return;
|
|
1450
|
-
const s = e?.padding ?? 50,
|
|
1451
|
-
let
|
|
1452
|
-
const g = this.getMainLayer(),
|
|
1453
|
-
if (g.children.forEach((
|
|
1454
|
-
if (
|
|
1455
|
-
if (
|
|
1456
|
-
const U =
|
|
1457
|
-
if (!
|
|
1490
|
+
const s = e?.padding ?? 50, i = e?.scale === !0, n = e?.nodeIds;
|
|
1491
|
+
let a = 1 / 0, h = 1 / 0, c = -1 / 0, d = -1 / 0;
|
|
1492
|
+
const g = this.getMainLayer(), x = this.getState().selectedNodeIds || [], p = n && n.length > 0, M = !p && x.length > 0, I = p ? n : M ? x : null;
|
|
1493
|
+
if (g.children.forEach((C) => {
|
|
1494
|
+
if (C.visible() && C.getClassName() !== "Transformer" && C.hasName(j)) {
|
|
1495
|
+
if (I) {
|
|
1496
|
+
const U = C.id();
|
|
1497
|
+
if (!I.includes(U)) return;
|
|
1458
1498
|
}
|
|
1459
|
-
const
|
|
1460
|
-
if (
|
|
1461
|
-
const U =
|
|
1462
|
-
|
|
1499
|
+
const O = C.getAttrs(), Ct = O.x || 0, Tt = O.y || 0, Lt = O.width || 0, Ot = O.height || 0;
|
|
1500
|
+
if (O.rotation || 0) {
|
|
1501
|
+
const U = C.getClientRect({ skipTransform: !1 }), xt = this.getStage(), tt = xt.scaleX(), kt = xt.x(), Pt = xt.y(), Ft = (U.x - kt) / tt, Wt = (U.y - Pt) / tt, Gt = (U.x + U.width - kt) / tt, $t = (U.y + U.height - Pt) / tt;
|
|
1502
|
+
a = Math.min(a, Ft), h = Math.min(h, Wt), c = Math.max(c, Gt), d = Math.max(d, $t);
|
|
1463
1503
|
} else
|
|
1464
|
-
|
|
1504
|
+
a = Math.min(a, Ct), h = Math.min(h, Tt), c = Math.max(c, Ct + Lt), d = Math.max(d, Tt + Ot);
|
|
1465
1505
|
}
|
|
1466
|
-
}),
|
|
1467
|
-
const
|
|
1468
|
-
let
|
|
1469
|
-
if (
|
|
1470
|
-
const
|
|
1471
|
-
|
|
1506
|
+
}), a === 1 / 0 || h === 1 / 0) return;
|
|
1507
|
+
const E = c - a, z = d - h, P = a + E / 2, ft = h + z / 2, L = this.getState().viewport;
|
|
1508
|
+
let V = L.scale;
|
|
1509
|
+
if (i) {
|
|
1510
|
+
const C = (L.width - s * 2) / E, O = (L.height - s * 2) / z;
|
|
1511
|
+
V = Math.min(C, O, 1);
|
|
1472
1512
|
}
|
|
1473
|
-
const
|
|
1474
|
-
this.updateViewport({ x:
|
|
1513
|
+
const G = L.width / 2 - P * V, Et = L.height / 2 - ft * V;
|
|
1514
|
+
this.updateViewport({ x: G, y: Et, scale: V }, !0);
|
|
1475
1515
|
}
|
|
1476
1516
|
}
|
|
1477
|
-
function
|
|
1478
|
-
const [
|
|
1517
|
+
function Me(o, e, t, s = !1) {
|
|
1518
|
+
const [i, n] = e, [a, h] = t, c = a + (o - i) / (n - i) * (h - a);
|
|
1479
1519
|
return s ? a < h ? Math.max(Math.min(c, h), a) : Math.max(Math.min(c, a), h) : c;
|
|
1480
1520
|
}
|
|
1481
|
-
const
|
|
1521
|
+
const Dt = [
|
|
1482
1522
|
{
|
|
1483
1523
|
min: -1,
|
|
1484
1524
|
mid: 0.15,
|
|
@@ -1500,15 +1540,15 @@ const Yt = [
|
|
|
1500
1540
|
step: 1
|
|
1501
1541
|
}
|
|
1502
1542
|
];
|
|
1503
|
-
function
|
|
1543
|
+
function _e({
|
|
1504
1544
|
viewportX: o,
|
|
1505
1545
|
viewportY: e,
|
|
1506
1546
|
scale: t,
|
|
1507
1547
|
size: s = 20,
|
|
1508
|
-
showGrid:
|
|
1548
|
+
showGrid: i = !0
|
|
1509
1549
|
}) {
|
|
1510
|
-
const
|
|
1511
|
-
return
|
|
1550
|
+
const n = o / t, a = e / t, h = t;
|
|
1551
|
+
return i ? /* @__PURE__ */ W(
|
|
1512
1552
|
"svg",
|
|
1513
1553
|
{
|
|
1514
1554
|
className: "canvas-grid w-full h-full absolute top-0 left-0",
|
|
@@ -1516,38 +1556,38 @@ function Ne({
|
|
|
1516
1556
|
xmlns: "http://www.w3.org/2000/svg",
|
|
1517
1557
|
"aria-hidden": "true",
|
|
1518
1558
|
children: [
|
|
1519
|
-
/* @__PURE__ */
|
|
1520
|
-
const p =
|
|
1521
|
-
return /* @__PURE__ */
|
|
1559
|
+
/* @__PURE__ */ v("defs", { children: Dt.map(({ min: c, mid: d, step: g }, x) => {
|
|
1560
|
+
const p = g * s * h, M = 0.5 + n * h, I = 0.5 + a * h, E = M > 0 ? M % p : p + M % p, z = I > 0 ? I % p : p + I % p, P = h < d ? Me(h, [c, d], [0, 1]) : 1;
|
|
1561
|
+
return /* @__PURE__ */ v(
|
|
1522
1562
|
"pattern",
|
|
1523
1563
|
{
|
|
1524
|
-
id: `grid_${
|
|
1564
|
+
id: `grid_${g}`,
|
|
1525
1565
|
width: p,
|
|
1526
1566
|
height: p,
|
|
1527
1567
|
patternUnits: "userSpaceOnUse",
|
|
1528
|
-
children: /* @__PURE__ */
|
|
1568
|
+
children: /* @__PURE__ */ v(
|
|
1529
1569
|
"circle",
|
|
1530
1570
|
{
|
|
1531
1571
|
className: "tl-grid-dot",
|
|
1532
|
-
cx:
|
|
1533
|
-
cy:
|
|
1572
|
+
cx: E,
|
|
1573
|
+
cy: z,
|
|
1534
1574
|
r: 1,
|
|
1535
|
-
opacity:
|
|
1575
|
+
opacity: P
|
|
1536
1576
|
}
|
|
1537
1577
|
)
|
|
1538
1578
|
},
|
|
1539
|
-
|
|
1579
|
+
x
|
|
1540
1580
|
);
|
|
1541
1581
|
}) }),
|
|
1542
|
-
|
|
1582
|
+
Dt.map(({ step: c }, d) => /* @__PURE__ */ v("rect", { width: "100%", height: "100%", fill: `url(#grid_${c})` }, d))
|
|
1543
1583
|
]
|
|
1544
1584
|
}
|
|
1545
1585
|
) : null;
|
|
1546
1586
|
}
|
|
1547
|
-
function
|
|
1548
|
-
return
|
|
1587
|
+
function Ie(...o) {
|
|
1588
|
+
return se(ee(o));
|
|
1549
1589
|
}
|
|
1550
|
-
const
|
|
1590
|
+
const be = te(
|
|
1551
1591
|
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
1552
1592
|
{
|
|
1553
1593
|
variants: {
|
|
@@ -1574,56 +1614,56 @@ const Me = Bt(
|
|
|
1574
1614
|
}
|
|
1575
1615
|
}
|
|
1576
1616
|
);
|
|
1577
|
-
function
|
|
1617
|
+
function $({
|
|
1578
1618
|
className: o,
|
|
1579
1619
|
variant: e = "default",
|
|
1580
1620
|
size: t = "default",
|
|
1581
1621
|
asChild: s = !1,
|
|
1582
|
-
...
|
|
1622
|
+
...i
|
|
1583
1623
|
}) {
|
|
1584
|
-
return /* @__PURE__ */
|
|
1585
|
-
s ?
|
|
1624
|
+
return /* @__PURE__ */ v(
|
|
1625
|
+
s ? Qt : "button",
|
|
1586
1626
|
{
|
|
1587
1627
|
"data-slot": "button",
|
|
1588
1628
|
"data-variant": e,
|
|
1589
1629
|
"data-size": t,
|
|
1590
|
-
className:
|
|
1591
|
-
...
|
|
1630
|
+
className: Ie(be({ variant: e, size: t, className: o })),
|
|
1631
|
+
...i
|
|
1592
1632
|
}
|
|
1593
1633
|
);
|
|
1594
1634
|
}
|
|
1595
|
-
function
|
|
1596
|
-
const [e, t] =
|
|
1635
|
+
function Ee({ api: o }) {
|
|
1636
|
+
const [e, t] = q(o.getState().viewport);
|
|
1597
1637
|
It(() => {
|
|
1598
1638
|
o.on("viewport:change", (c) => {
|
|
1599
1639
|
t(c);
|
|
1600
1640
|
});
|
|
1601
1641
|
}, [t, o]);
|
|
1602
1642
|
const s = (c) => {
|
|
1603
|
-
const
|
|
1604
|
-
o.updateViewport({ x:
|
|
1605
|
-
},
|
|
1643
|
+
const d = e.width / 2, g = e.height / 2, x = (d - e.x) / e.scale, p = (g - e.y) / e.scale, M = d - x * c, I = g - p * c;
|
|
1644
|
+
o.updateViewport({ x: M, y: I, scale: c });
|
|
1645
|
+
}, i = () => {
|
|
1606
1646
|
const c = Math.min(e.scale * 1.2, 5);
|
|
1607
1647
|
s(c);
|
|
1608
|
-
},
|
|
1648
|
+
}, n = () => {
|
|
1609
1649
|
const c = Math.max(e.scale / 1.2, 0.1);
|
|
1610
1650
|
s(c);
|
|
1611
1651
|
}, a = () => {
|
|
1612
1652
|
s(1);
|
|
1613
1653
|
}, h = Math.round(e.scale * 100);
|
|
1614
|
-
return /* @__PURE__ */
|
|
1615
|
-
/* @__PURE__ */
|
|
1616
|
-
|
|
1654
|
+
return /* @__PURE__ */ W("div", { className: "zoom-panel flex items-center gap-2", children: [
|
|
1655
|
+
/* @__PURE__ */ v(
|
|
1656
|
+
$,
|
|
1617
1657
|
{
|
|
1618
1658
|
size: "sm",
|
|
1619
1659
|
variant: "secondary",
|
|
1620
|
-
onClick:
|
|
1660
|
+
onClick: n,
|
|
1621
1661
|
title: "缩小",
|
|
1622
|
-
children: /* @__PURE__ */
|
|
1662
|
+
children: /* @__PURE__ */ v(ie, {})
|
|
1623
1663
|
}
|
|
1624
1664
|
),
|
|
1625
|
-
/* @__PURE__ */
|
|
1626
|
-
|
|
1665
|
+
/* @__PURE__ */ W(
|
|
1666
|
+
$,
|
|
1627
1667
|
{
|
|
1628
1668
|
size: "sm",
|
|
1629
1669
|
variant: "secondary",
|
|
@@ -1636,81 +1676,82 @@ function _e({ api: o }) {
|
|
|
1636
1676
|
]
|
|
1637
1677
|
}
|
|
1638
1678
|
),
|
|
1639
|
-
/* @__PURE__ */
|
|
1640
|
-
|
|
1679
|
+
/* @__PURE__ */ v(
|
|
1680
|
+
$,
|
|
1641
1681
|
{
|
|
1642
1682
|
size: "sm",
|
|
1643
1683
|
variant: "secondary",
|
|
1644
|
-
onClick:
|
|
1684
|
+
onClick: i,
|
|
1645
1685
|
title: "放大",
|
|
1646
|
-
children: /* @__PURE__ */
|
|
1686
|
+
children: /* @__PURE__ */ v(ne, {})
|
|
1647
1687
|
}
|
|
1648
1688
|
)
|
|
1649
1689
|
] });
|
|
1650
1690
|
}
|
|
1651
|
-
function
|
|
1652
|
-
const [e, t] =
|
|
1691
|
+
function Ce({ api: o }) {
|
|
1692
|
+
const [e, t] = q(o.canUndo()), [s, i] = q(o.canRedo());
|
|
1653
1693
|
return It(() => {
|
|
1654
|
-
const
|
|
1655
|
-
t(o.canUndo()),
|
|
1694
|
+
const n = () => {
|
|
1695
|
+
t(o.canUndo()), i(o.canRedo());
|
|
1656
1696
|
};
|
|
1657
|
-
return o.on("state:change",
|
|
1658
|
-
o.off("state:change",
|
|
1697
|
+
return o.on("state:change", n), () => {
|
|
1698
|
+
o.off("state:change", n);
|
|
1659
1699
|
};
|
|
1660
|
-
}, [o]), /* @__PURE__ */
|
|
1661
|
-
/* @__PURE__ */
|
|
1662
|
-
|
|
1700
|
+
}, [o]), /* @__PURE__ */ W("div", { className: "history-panel flex items-center gap-2", children: [
|
|
1701
|
+
/* @__PURE__ */ v(
|
|
1702
|
+
$,
|
|
1663
1703
|
{
|
|
1664
1704
|
size: "sm",
|
|
1665
1705
|
variant: "secondary",
|
|
1666
1706
|
disabled: !e,
|
|
1667
1707
|
onClick: () => o.undo(),
|
|
1668
1708
|
title: "撤销",
|
|
1669
|
-
children: /* @__PURE__ */
|
|
1709
|
+
children: /* @__PURE__ */ v(re, {})
|
|
1670
1710
|
}
|
|
1671
1711
|
),
|
|
1672
|
-
/* @__PURE__ */
|
|
1673
|
-
|
|
1712
|
+
/* @__PURE__ */ v(
|
|
1713
|
+
$,
|
|
1674
1714
|
{
|
|
1675
1715
|
size: "sm",
|
|
1676
1716
|
variant: "secondary",
|
|
1677
1717
|
disabled: !s,
|
|
1678
1718
|
onClick: () => o.redo(),
|
|
1679
1719
|
title: "重做",
|
|
1680
|
-
children: /* @__PURE__ */
|
|
1720
|
+
children: /* @__PURE__ */ v(oe, {})
|
|
1681
1721
|
}
|
|
1682
1722
|
)
|
|
1683
1723
|
] });
|
|
1684
1724
|
}
|
|
1685
|
-
function
|
|
1686
|
-
const e =
|
|
1725
|
+
function He({ setApi: o }) {
|
|
1726
|
+
const e = Bt(null), [t, s] = q(null), [i, n] = q({ x: 0, y: 0, scale: 1 });
|
|
1687
1727
|
return It(() => {
|
|
1688
1728
|
if (!e.current) return;
|
|
1689
|
-
const a = new
|
|
1729
|
+
const a = new Se(e.current);
|
|
1690
1730
|
return s(a), o?.(a), a.on("viewport:change", (h) => {
|
|
1691
|
-
|
|
1731
|
+
n(h);
|
|
1692
1732
|
}), a.on("transformer:positionChange", (h) => {
|
|
1693
1733
|
console.log("Transformer position changed:", h);
|
|
1694
1734
|
}), () => {
|
|
1695
1735
|
a.dispose();
|
|
1696
1736
|
};
|
|
1697
|
-
}, [o]), /* @__PURE__ */
|
|
1698
|
-
/* @__PURE__ */
|
|
1699
|
-
|
|
1737
|
+
}, [o]), /* @__PURE__ */ W("div", { className: "pure-canvas relative size-full", children: [
|
|
1738
|
+
/* @__PURE__ */ v(
|
|
1739
|
+
_e,
|
|
1700
1740
|
{
|
|
1701
|
-
viewportX:
|
|
1702
|
-
viewportY:
|
|
1703
|
-
scale:
|
|
1741
|
+
viewportX: i.x,
|
|
1742
|
+
viewportY: i.y,
|
|
1743
|
+
scale: i.scale
|
|
1704
1744
|
}
|
|
1705
1745
|
),
|
|
1706
|
-
/* @__PURE__ */
|
|
1707
|
-
t && /* @__PURE__ */
|
|
1708
|
-
/* @__PURE__ */
|
|
1709
|
-
/* @__PURE__ */
|
|
1746
|
+
/* @__PURE__ */ v("div", { ref: e, className: "size-full" }),
|
|
1747
|
+
t && /* @__PURE__ */ W(jt, { children: [
|
|
1748
|
+
/* @__PURE__ */ v("div", { className: "history-panel-wrapper absolute bottom-4 left-4 z-10", children: /* @__PURE__ */ v(Ce, { api: t }) }),
|
|
1749
|
+
/* @__PURE__ */ v("div", { className: "zoom-panel-wrapper absolute bottom-4 right-4 z-10", children: /* @__PURE__ */ v(Ee, { api: t }) })
|
|
1710
1750
|
] })
|
|
1711
1751
|
] });
|
|
1712
1752
|
}
|
|
1713
1753
|
export {
|
|
1714
|
-
|
|
1715
|
-
|
|
1754
|
+
Se as CanvasApi,
|
|
1755
|
+
j as NODE_NAME_FOR_SELECT,
|
|
1756
|
+
He as PureCanvas
|
|
1716
1757
|
};
|