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