@8btc/whiteboard 0.0.2 → 0.0.3

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.js CHANGED
@@ -1,116 +1,116 @@
1
- var Wt = Object.defineProperty;
2
- var Tt = (o) => {
1
+ var qt = Object.defineProperty;
2
+ var Rt = (o) => {
3
3
  throw TypeError(o);
4
4
  };
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 {
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
- d(this, ot);
22
- d(this, f);
23
- d(this, l);
24
- d(this, X, { x: 0, y: 0, scale: 1 });
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
- d(this, Q, (e) => {
28
+ l(this, et, (e) => {
29
29
  e.evt.preventDefault();
30
- const s = r(this, l).getPointerPosition();
30
+ const s = r(this, m).getPointerPosition();
31
31
  if (s)
32
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
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 g = n;
37
+ let d = i;
38
38
  for (let p = 0; p < c; p++)
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
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, f).updateViewport({ x: v.x, y: v.y, scale: m });
44
+ r(this, y).updateViewport({ x: x.x, y: x.y, scale: g });
45
45
  } else {
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
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
- d(this, tt, (e) => {
54
- const t = r(this, f).getState().toolType;
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, l), n = r(this, l).getRelativePointerPosition();
57
+ const s = e.target === r(this, m), i = r(this, m).getRelativePointerPosition();
58
58
  if (t === "select" && !s) {
59
- const i = e.target.id();
60
- i && r(this, f).selectNode(i, e.evt.shiftKey);
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" && 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();
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: i.x(),
70
- y: i.y(),
69
+ x: n.x(),
70
+ y: n.y(),
71
71
  width: a,
72
72
  height: h
73
73
  };
74
- r(this, f).createDraftNode(t, n, {
75
- parent: i.id(),
74
+ r(this, y).createDraftNode(t, i, {
75
+ parent: n.id(),
76
76
  bounds: c,
77
- startPosition: n
77
+ startPosition: i
78
78
  });
79
79
  }
80
80
  }
81
81
  }
82
- r(this, f).selectNode();
82
+ r(this, y).selectNode();
83
83
  });
84
- d(this, et, () => {
85
- const e = r(this, f).getState().toolType;
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, l).getRelativePointerPosition();
89
- (e === "rectangle" || e === "image-marker") && t && r(this, f).updateDraftNode(t);
88
+ const t = r(this, m).getRelativePointerPosition();
89
+ (e === "rectangle" || e === "image-marker") && t && r(this, y).updateDraftNode(t);
90
90
  });
91
- d(this, st, () => {
92
- const e = r(this, f).getState().toolType;
93
- e !== "hand" && (e === "rectangle" || e === "image-marker") && r(this, f).finalizeDraftNode();
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
- d(this, it, (e) => {
96
- if (e.target !== r(this, l))
95
+ l(this, rt, (e) => {
96
+ if (e.target !== r(this, m))
97
97
  return;
98
- const t = r(this, f).getState().toolType;
98
+ const t = r(this, y).getState().toolType;
99
99
  t === "hand" ? this.setCursor("grabbing") : t === "select" && this.setCursor("all-scroll");
100
100
  });
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()
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
- 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()
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, f, e), N(this, l, new D.Stage({
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
- })), M(this, ot, Xt).call(this);
123
+ })), _(this, ht, Zt).call(this);
124
124
  }
125
125
  /**
126
126
  * 获取原生 Konva.Stage 实例
127
127
  */
128
128
  getStage() {
129
- return r(this, l);
129
+ return r(this, m);
130
130
  }
131
131
  /**
132
132
  * 获取当前视口状态
133
133
  */
134
134
  getViewport() {
135
- return { ...r(this, X) };
135
+ return { ...r(this, R) };
136
136
  }
137
137
  /**
138
138
  * 设置视口(包括位置、缩放和尺寸)
139
139
  */
140
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);
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, l).draggable(e);
148
+ r(this, m).draggable(e);
149
149
  }
150
150
  /**
151
151
  * 设置光标样式
152
152
  */
153
153
  setCursor(e) {
154
- const t = r(this, l).container();
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, l).container();
162
- if (r(this, f).getState().toolType === "hand") {
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, l).destroy();
172
+ r(this, m).destroy();
173
173
  }
174
174
  }
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(), /**
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
- 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));
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 q, y, at, ht, ct, dt, lt, mt, gt, Dt;
182
- class re {
181
+ var B, f, ct, dt, lt, mt, gt, pt, ut, At;
182
+ class he {
183
183
  constructor(e, t) {
184
- d(this, gt);
185
- d(this, q);
186
- d(this, y);
184
+ l(this, ut);
185
+ l(this, B);
186
+ l(this, f);
187
187
  /**
188
188
  * 处理 transformstart 事件
189
189
  */
190
- d(this, at, () => {
190
+ l(this, ct, () => {
191
191
  this.emitPositionChange();
192
192
  });
193
193
  /**
194
194
  * 处理 transform 事件
195
195
  */
196
- d(this, ht, () => {
196
+ l(this, dt, () => {
197
197
  console.log("transforming..."), this.emitPositionChange();
198
198
  });
199
199
  /**
200
200
  * 处理 transformend 事件
201
201
  */
202
- d(this, ct, () => {
202
+ l(this, lt, () => {
203
203
  this.emitPositionChange();
204
204
  });
205
205
  /**
206
206
  * 处理 dragstart 事件
207
207
  */
208
- d(this, dt, () => {
208
+ l(this, mt, () => {
209
209
  this.emitPositionChange();
210
210
  });
211
211
  /**
212
212
  * 处理 dragmove 事件
213
213
  */
214
- d(this, lt, () => {
214
+ l(this, gt, () => {
215
215
  this.emitPositionChange();
216
216
  });
217
217
  /**
218
218
  * 处理 dragend 事件
219
219
  */
220
- d(this, mt, () => {
220
+ l(this, pt, () => {
221
221
  this.emitPositionChange();
222
222
  });
223
- N(this, q, e), N(this, y, new D.Transformer({
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
- })), M(this, gt, Dt).call(this);
230
+ })), _(this, ut, At).call(this);
231
231
  }
232
232
  /**
233
233
  * 获取原生 Konva.Transformer 实例
234
234
  */
235
235
  getTransformer() {
236
- return r(this, y);
236
+ return r(this, f);
237
237
  }
238
238
  /**
239
239
  * 获取 Transformer 的位置信息
240
240
  */
241
241
  getPosition() {
242
- if (r(this, y).nodes().length === 0)
242
+ if (r(this, f).nodes().length === 0)
243
243
  return null;
244
- const t = r(this, y).getClientRect();
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, y).rotation()
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, y).nodes(e), r(this, y).moveToTop(), this.emitPositionChange();
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, y).nodes();
267
+ return r(this, f).nodes();
268
268
  }
269
269
  /**
270
270
  * 清除所有节点
271
271
  */
272
272
  clearNodes() {
273
- r(this, y).nodes([]), r(this, y).moveToBottom(), this.emitPositionChange();
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, q).emitEvent("transformer:positionChange", e);
280
+ r(this, B).emitEvent("transformer:positionChange", e);
281
281
  }
282
282
  /**
283
283
  * 销毁 Transformer
284
284
  */
285
285
  destroy() {
286
- r(this, y).destroy();
286
+ r(this, f).destroy();
287
287
  }
288
288
  }
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(), /**
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
- 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));
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 oe {
295
+ class ce {
296
296
  constructor(e) {
297
- z(this, "_past", []);
298
- z(this, "_present");
299
- z(this, "_future", []);
300
- z(this, "_emitter");
301
- this._present = e, this._emitter = Kt();
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 $ = "shapeNameForSelect", u = {
394
+ const j = "shapeNameForSelect", u = {
395
395
  CORNER_RADIUS: 6,
396
396
  MIN_SIZE: 10
397
- }, O = {
397
+ }, F = {
398
398
  MIN_SIZE: 10
399
- }, kt = {
399
+ }, Yt = {
400
400
  MIN_SIZE: 10
401
401
  };
402
- function ae(o, e, t) {
402
+ function de(o, e, t) {
403
403
  return 2 * (e + o - t * (4 - Math.PI));
404
404
  }
405
- function he(o, e, t) {
406
- let s = 1, n = 0, i = 0;
405
+ function le(o, e, t) {
406
+ let s = 1, i = 0, n = 0;
407
407
  switch (t) {
408
408
  case "dashed":
409
- n = Math.min(e * 2, o / 4);
409
+ i = Math.min(e * 2, o / 4);
410
410
  break;
411
411
  case "dotted":
412
- s = 8, n = e / s;
412
+ s = 8, i = e / s;
413
413
  break;
414
414
  default:
415
415
  return [];
416
416
  }
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];
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 ce(o) {
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 de(o) {
434
+ function ge(o) {
435
435
  return Array.isArray(o) && o.length > 1 ? o[0] + o[1] : 0;
436
436
  }
437
- function Pt(o) {
437
+ function Xt(o) {
438
438
  return {
439
- width: Math.max(kt.MIN_SIZE, o.width() * o.scaleX()),
440
- height: Math.max(kt.MIN_SIZE, o.height() * o.scaleY())
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
- z(this, "core");
446
- z(this, "node");
447
- z(this, "element");
448
- z(this, "toolTypeChangeHandler");
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 n = s === "select";
451
- this.element.listening(n);
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 le(o, e) {
473
+ function pe(o, e) {
474
474
  if (!e || e === 0)
475
475
  return null;
476
- const t = new D.Animation((s) => {
476
+ const t = new Y.Animation((s) => {
477
477
  if (!s) return;
478
- const n = -s.time / 10 % e;
479
- o.dashOffset(n);
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 I, Z, vt, Nt, Zt;
488
- class me extends bt {
487
+ var b, X, vt, Nt, Vt;
488
+ class ue extends bt {
489
489
  constructor(t, s) {
490
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());
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
- ), n = {
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
- }, i = new D.Rect(n);
514
- return i.setAttrs({
513
+ }, n = new Y.Rect(i);
514
+ return n.setAttrs({
515
515
  width: t,
516
516
  height: s
517
- }), i;
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 n = Math.max(
543
+ const i = Math.max(
544
544
  this.node.props.width ?? u.MIN_SIZE,
545
545
  u.MIN_SIZE
546
- ), i = Math.max(
546
+ ), n = Math.max(
547
547
  this.node.props.height ?? u.MIN_SIZE,
548
548
  u.MIN_SIZE
549
549
  );
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);
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
- M(this, Z, Nt).call(this), super.destroy();
556
+ _(this, X, Nt).call(this), super.destroy();
557
557
  }
558
558
  }
559
- I = new WeakMap(), Z = new WeakSet(), /**
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 n = de(s);
566
- N(this, I, le(t, n)), r(this, I) && r(this, I).start();
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, I) && (r(this, I).stop(), N(this, I, null));
571
+ r(this, b) && (r(this, b).stop(), N(this, b, null));
572
572
  }, /**
573
573
  * 设置事件处理器
574
574
  */
575
- Zt = function(t = void 0) {
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, 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(
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
- ce(this.node.style.size),
582
+ me(this.node.style.size),
583
583
  this.node.style.line
584
584
  );
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 = {
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: i.x(),
590
- y: i.y(),
589
+ x: n.x(),
590
+ y: n.y(),
591
591
  width: a,
592
592
  height: h,
593
- rotation: i.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, I)?.isRunning() === !1 && r(this, I).start();
598
- }), s.on("dragend", (n) => {
599
- const i = n.target, a = {
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: i.x(),
602
- y: i.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, zt, Mt, _t;
610
- class ge extends bt {
609
+ var k, St, Ut, Mt, _t;
610
+ class ye extends bt {
611
611
  constructor(t, s) {
612
612
  super(t, s);
613
- d(this, k);
614
- M(this, k, St).call(this), M(this, k, zt).call(this, this.getElement());
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 D.Image({
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 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);
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 && M(this, k, St).call(this);
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 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));
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
- zt = function(t) {
687
+ Ut = function(t) {
688
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);
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 n = s.target, i = {
692
+ const i = s.target, n = {
693
693
  ...this.node.props,
694
- x: n.x(),
695
- y: n.y(),
696
- width: n.width(),
697
- height: n.height(),
698
- rotation: n.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 = i, this.core._syncNodeFromElement(this.node.id, {
701
- props: i
702
- }), M(this, k, _t).call(this);
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
- M(this, k, Mt).call(this);
704
+ _(this, k, Mt).call(this);
705
705
  }), t.on("dragend", (s) => {
706
- const n = s.target, i = {
706
+ const i = s.target, n = {
707
707
  ...this.node.props,
708
- x: n.x(),
709
- y: n.y()
708
+ x: i.x(),
709
+ y: i.y()
710
710
  };
711
- this.node.props = i, this.core._syncNodeFromElement(this.node.id, {
712
- props: i
713
- }), M(this, k, _t).call(this);
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 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 });
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
- (i) => i.hasName(this.node.id)
741
- ).forEach((i) => {
742
- this.core._syncNodeFromElement(i.id(), {
740
+ (n) => n.hasName(this.node.id)
741
+ ).forEach((n) => {
742
+ this.core._syncNodeFromElement(n.id(), {
743
743
  props: {
744
- x: i.x(),
745
- y: i.y(),
746
- width: i.width(),
747
- height: i.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, K, j, pt, At;
753
- class pe extends bt {
752
+ var H, T, J, Q, yt, Ht;
753
+ class fe extends bt {
754
754
  constructor(t, s) {
755
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);
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
- ), n = new D.Group({
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
- }), i = new D.Rect({
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 D.Group({
789
+ }), a = new Y.Group({
790
790
  name: "marker-group",
791
791
  x: t,
792
792
  y: s
793
- }), c = 16 / this.core.getStageScale(), g = new D.Circle({
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
- }), m = new D.Text({
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(g), a.add(m), n.add(i), n.add(a), n;
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 n = Math.max(
839
+ const i = Math.max(
840
840
  this.node.props.width ?? u.MIN_SIZE,
841
841
  u.MIN_SIZE
842
- ), i = Math.max(
842
+ ), n = Math.max(
843
843
  this.node.props.height ?? u.MIN_SIZE,
844
844
  u.MIN_SIZE
845
845
  );
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));
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, 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);
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(), K = new WeakMap(), j = new WeakMap(), pt = new WeakSet(), /**
862
+ H = new WeakMap(), T = new WeakMap(), J = new WeakMap(), Q = new WeakMap(), yt = new WeakSet(), /**
863
863
  * 设置事件处理器
864
864
  */
865
- At = function() {
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 Rt(o, e, t) {
875
+ function zt(o, e, t) {
876
876
  switch (e) {
877
877
  case "rectangle":
878
- return new me(o, t);
878
+ return new ue(o, t);
879
879
  case "image":
880
- return new ge(o, t);
880
+ return new ye(o, t);
881
881
  case "image-marker":
882
- return new pe(o, t);
882
+ return new fe(o, t);
883
883
  default:
884
884
  return null;
885
885
  }
886
886
  }
887
- const ue = (o, e, t, s) => {
888
- const n = {
887
+ const xe = (o, e, t, s) => {
888
+ const i = {
889
889
  type: o,
890
- id: J(),
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
- ...n,
908
+ ...i,
909
909
  style: {
910
- ...n.style,
910
+ ...i.style,
911
911
  color: "#ff0000",
912
912
  line: "dashed"
913
913
  }
914
- } : n;
914
+ } : i;
915
915
  };
916
- function fe(o, e, t) {
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 [n, i] = ye(
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: 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)
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 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), [
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: n, y: i }
941
+ { x: i, y: n }
942
942
  ];
943
943
  }
944
- var x, A, V, S;
945
- class xe extends oe {
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
- d(this, x);
959
- d(this, A);
960
- d(this, V);
961
- d(this, S, null);
962
- N(this, x, new ne(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, 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);
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, x);
974
+ return r(this, w);
975
975
  }
976
976
  /**
977
977
  * 获取 CanvasTransformer 实例
978
978
  */
979
979
  getCanvasTransformer() {
980
- return r(this, V);
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, x).getStage();
992
+ return r(this, w).getStage();
993
993
  }
994
994
  /**
995
995
  * 获取 Stage 容器元素
996
996
  */
997
997
  getContainer() {
998
- return r(this, x).getStage().container();
998
+ return r(this, w).getStage().container();
999
999
  }
1000
1000
  /**
1001
1001
  * 获取主图层
1002
1002
  */
1003
1003
  getMainLayer() {
1004
- return r(this, A);
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, x).setDraggable(!0), r(this, x).setCursor("grab")) : (r(this, x).setDraggable(!1), r(this, x).resetCursor());
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, x).setDraggable(t);
1027
+ r(this, w).setDraggable(t);
1028
1028
  }
1029
1029
  /**
1030
1030
  * 设置光标
1031
1031
  * @internal 仅供内部使用
1032
1032
  */
1033
1033
  setCursor(t) {
1034
- r(this, x).setCursor(t);
1034
+ r(this, w).setCursor(t);
1035
1035
  }
1036
1036
  /**
1037
1037
  * 重置光标
1038
1038
  * @internal 仅供内部使用
1039
1039
  */
1040
1040
  resetCursor() {
1041
- r(this, x).resetCursor();
1041
+ r(this, w).resetCursor();
1042
1042
  }
1043
1043
  /**
1044
1044
  * 获取当前 Stage 缩放比例
1045
1045
  */
1046
1046
  getStageScale() {
1047
- return r(this, x).getStage().scaleX();
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, x).setViewport(t);
1055
- const n = {
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: n
1061
+ viewport: i
1062
1062
  },
1063
1063
  s
1064
- ), this.emit("viewport:change", n), r(this, V).emitPositionChange();
1064
+ ), this.emit("viewport:change", i), r(this, A).emitPositionChange();
1065
1065
  }
1066
1066
  createNodes(t) {
1067
- t.map((i) => Rt(this, i.type, i)).filter((i) => i !== null).forEach((i) => {
1068
- r(this, A).add(i.getElement());
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 n = [...this.getState().nodes || [], ...t];
1070
+ const i = [...this.getState().nodes || [], ...t];
1071
1071
  this._updateState(
1072
1072
  {
1073
- nodes: n
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, n, i) {
1081
+ createImageMarkerNode(t, s, i, n) {
1082
1082
  const a = this.getState().nodes || [];
1083
1083
  let h = 0;
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));
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 - 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(),
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: b,
1094
- height: C,
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, g))
1110
+ percentY: Math.max(0, Math.min(100, d))
1111
1111
  },
1112
1112
  end: {
1113
- percentX: Math.max(0, Math.min(100, m)),
1114
- percentY: Math.max(0, Math.min(100, v))
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([P]);
1119
+ this.createNodes([z]);
1120
1120
  }
1121
1121
  /**
1122
1122
  * 在指定位置查找图片节点
1123
1123
  * @internal 仅供内部使用
1124
1124
  */
1125
1125
  findImageAtPosition(t) {
1126
- const s = r(this, x).getStage(), n = s.find(
1126
+ const s = r(this, w).getStage(), i = s.find(
1127
1127
  (a) => a.getClassName() === "Image"
1128
- ), i = n.map(
1128
+ ), n = i.map(
1129
1129
  (a) => a.listening()
1130
1130
  );
1131
- n.forEach((a) => a.listening(!0));
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
- n.forEach((a, h) => {
1139
- a.listening(i[h]);
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, n) {
1146
+ createDraftNode(t, s, i) {
1147
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());
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 n = r(this, S).getNode(), i = fe(n, t, s);
1157
- r(this, S).updateNode(i);
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 = J(), s = r(this, S).getNode();
1164
+ const t = K(), s = r(this, S).getNode();
1165
1165
  if (s.type === "image-marker" && s.meta.parent) {
1166
- const i = s.meta.bounds, a = s.meta.startPosition, h = {
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 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));
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 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 = {
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: g + 1,
1184
+ markerNumber: d + 1,
1185
1185
  relativePosition: {
1186
1186
  start: {
1187
- percentX: Math.max(0, Math.min(100, m)),
1188
- percentY: Math.max(0, Math.min(100, v))
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([b]), r(this, S).destroy(), N(this, S, null), this.setToolType("select");
1199
+ this.createNodes([I]), r(this, S).destroy(), N(this, S, null), this.setToolType("select");
1200
1200
  return;
1201
1201
  }
1202
- const n = {
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([n]), r(this, S).destroy(), N(this, S, null), this.setToolType("select");
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 n = this.getState().selectedNodeIds ?? [];
1223
- if (n.length === 0 && !t)
1222
+ const i = this.getState().selectedNodeIds ?? [];
1223
+ if (i.length === 0 && !t)
1224
1224
  return;
1225
1225
  if (!t) {
1226
- r(this, V).clearNodes(), this._updateState(
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 i = [];
1235
- s ? i = n.length ? [...n, t] : [t] : i = [t];
1236
- const a = this.getStage().find(`.${$}`).filter((h) => {
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 i.includes(c);
1238
+ return n.includes(c);
1239
1239
  });
1240
- r(this, V).setNodes(a), this._updateState(
1240
+ r(this, A).setNodes(a), this._updateState(
1241
1241
  {
1242
- selectedNodeIds: i
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 n = this.getState().nodes || [], i = n.findIndex((c) => c.id === t);
1258
- if (i === -1) return;
1257
+ const i = this.getState().nodes || [], n = i.findIndex((c) => c.id === t);
1258
+ if (n === -1) return;
1259
1259
  const a = {
1260
- ...n[i],
1260
+ ...i[n],
1261
1261
  ...s,
1262
1262
  props: {
1263
- ...n[i].props,
1263
+ ...i[n].props,
1264
1264
  ...s.props
1265
1265
  },
1266
1266
  style: {
1267
- ...n[i].style,
1267
+ ...i[n].style,
1268
1268
  ...s.style
1269
1269
  },
1270
1270
  meta: {
1271
- ...n[i].meta,
1271
+ ...i[n].meta,
1272
1272
  ...s.meta
1273
1273
  }
1274
- }, h = [...n];
1275
- h[i] = a, this._updateState(
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, x).setViewport({
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
- x = new WeakMap(), A = new WeakMap(), V = new WeakMap(), S = new WeakMap();
1297
- class we extends xe {
1296
+ w = new WeakMap(), Z = new WeakMap(), A = new WeakMap(), S = new WeakMap();
1297
+ class Se extends Ne {
1298
1298
  /**
1299
1299
  * 获取所有可用的工具类型
1300
1300
  */
@@ -1317,8 +1317,8 @@ class we extends xe {
1317
1317
  * 创建图片节点
1318
1318
  */
1319
1319
  createImageNode(e, t) {
1320
- const s = t ?? { x: 100, y: 100 }, n = {
1321
- id: J(),
1320
+ const s = t ?? { x: 100, y: 100 }, i = {
1321
+ id: K(),
1322
1322
  type: "image",
1323
1323
  props: {
1324
1324
  x: s.x,
@@ -1338,26 +1338,57 @@ class we extends xe {
1338
1338
  imageUrl: e
1339
1339
  }
1340
1340
  };
1341
- this.createNodes([n]);
1341
+ this.createNodes([i]);
1342
1342
  }
1343
1343
  /**
1344
1344
  * 在当前所有节点的左下角插入图片,并将其居中显示
1345
+ * 如果没有节点,插入到画布中心
1345
1346
  * @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);
1347
+ * @param options - 配置选项
1348
+ * @param options.width - 图片宽度
1349
+ * @param options.height - 图片高度
1350
+ */
1351
+ insertImageAtBottomLeft(e, t) {
1352
+ const s = this.getState().nodes || [];
1353
+ let i = { x: 0, y: 0 };
1354
+ if (s.length > 0) {
1355
+ const a = this.getMainLayer();
1356
+ let h = 1 / 0, c = -1 / 0;
1357
+ a.children.forEach((d) => {
1358
+ if (d.visible() && d.getClassName() !== "Transformer" && d.hasName(j)) {
1359
+ const g = d.getAttrs(), x = g.x || 0, p = g.y || 0, M = g.height || 0;
1360
+ h = Math.min(h, x), c = Math.max(c, p + M);
1357
1361
  }
1358
- }), i !== 1 / 0 && a !== -1 / 0 && (s = { x: i, y: a + 20 });
1362
+ }), h !== 1 / 0 && c !== -1 / 0 && (i = { x: h, y: c + 20 });
1363
+ } else {
1364
+ const a = this.getState().viewport;
1365
+ i = {
1366
+ x: (a.width / 2 - a.x) / a.scale,
1367
+ y: (a.height / 2 - a.y) / a.scale
1368
+ };
1359
1369
  }
1360
- this.createImageNode(e, s), requestAnimationFrame(() => {
1370
+ const n = {
1371
+ id: K(),
1372
+ type: "image",
1373
+ props: {
1374
+ x: i.x,
1375
+ y: i.y,
1376
+ width: t?.width,
1377
+ height: t?.height,
1378
+ rotation: 0,
1379
+ visible: !0
1380
+ },
1381
+ style: {
1382
+ color: "#000000",
1383
+ line: "solid",
1384
+ size: "medium",
1385
+ opacity: 1
1386
+ },
1387
+ meta: {
1388
+ imageUrl: e
1389
+ }
1390
+ };
1391
+ this.createNodes([n]), requestAnimationFrame(() => {
1361
1392
  this.scrollToContent({ scale: !0 });
1362
1393
  });
1363
1394
  }
@@ -1367,7 +1398,7 @@ class we extends xe {
1367
1398
  * @returns DataURL 格式的图片数据
1368
1399
  */
1369
1400
  exportAsImage(e) {
1370
- const t = this.getStage(), s = this.getCanvasTransformer().getTransformer(), n = s.visible();
1401
+ const t = this.getStage(), s = this.getCanvasTransformer().getTransformer(), i = s.visible();
1371
1402
  s.visible(!1);
1372
1403
  try {
1373
1404
  return t.toDataURL({
@@ -1376,7 +1407,7 @@ class we extends xe {
1376
1407
  quality: e?.quality ?? 1
1377
1408
  });
1378
1409
  } finally {
1379
- s.visible(n);
1410
+ s.visible(i);
1380
1411
  }
1381
1412
  }
1382
1413
  /**
@@ -1388,20 +1419,20 @@ class we extends xe {
1388
1419
  const t = this.getCanvasTransformer().getPosition();
1389
1420
  if (!t)
1390
1421
  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);
1422
+ const s = this.getStage(), i = e?.padding ?? 10, n = this.getCanvasTransformer().getTransformer(), a = n.visible();
1423
+ n.visible(!1);
1393
1424
  try {
1394
1425
  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,
1426
+ x: t.x - i,
1427
+ y: t.y - i,
1428
+ width: t.width + i * 2,
1429
+ height: t.height + i * 2,
1399
1430
  pixelRatio: e?.pixelRatio ?? 2,
1400
1431
  mimeType: e?.mimeType ?? "image/png",
1401
1432
  quality: e?.quality ?? 1
1402
1433
  });
1403
1434
  } finally {
1404
- i.visible(a);
1435
+ n.visible(a);
1405
1436
  }
1406
1437
  }
1407
1438
  /**
@@ -1420,18 +1451,18 @@ class we extends xe {
1420
1451
  deleteNodes(e) {
1421
1452
  if (e.length === 0) return;
1422
1453
  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);
1454
+ e.forEach((n) => {
1455
+ t.find((h) => h.id === n)?.type === "image" && t.forEach((h) => {
1456
+ h.type === "image-marker" && h.meta.parent === n && s.add(h.id);
1426
1457
  });
1427
- }), s.forEach((i) => {
1428
- const a = this.getStage().findOne(`#${i}`);
1458
+ }), s.forEach((n) => {
1459
+ const a = this.getStage().findOne(`#${n}`);
1429
1460
  a && a.destroy();
1430
1461
  });
1431
- const n = t.filter((i) => !s.has(i.id));
1462
+ const i = t.filter((n) => !s.has(n.id));
1432
1463
  this.getCanvasTransformer().clearNodes(), this._updateState(
1433
1464
  {
1434
- nodes: n,
1465
+ nodes: i,
1435
1466
  selectedNodeIds: []
1436
1467
  },
1437
1468
  !0
@@ -1439,46 +1470,48 @@ class we extends xe {
1439
1470
  }
1440
1471
  /**
1441
1472
  * 滚动到内容区域
1442
- * - 如果有选中的节点,将选中节点居中显示
1473
+ * - 如果提供了 nodeIds,将指定的节点居中显示
1474
+ * - 如果没有提供 nodeIds 但有选中的节点,将选中节点居中显示
1443
1475
  * - 如果没有选中节点,将所有内容居中显示
1444
1476
  * @param options - 配置选项
1445
1477
  * @param options.padding - 内容周围的留白,默认 50px
1446
1478
  * @param options.scale - 是否自动调整缩放以适应内容,默认 false
1479
+ * @param options.nodeIds - 要滚动到的节点 ID 数组
1447
1480
  */
1448
1481
  scrollToContent(e) {
1449
1482
  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;
1483
+ const s = e?.padding ?? 50, i = e?.scale === !0, n = e?.nodeIds;
1484
+ let a = 1 / 0, h = 1 / 0, c = -1 / 0, d = -1 / 0;
1485
+ const g = this.getMainLayer(), x = this.getState().selectedNodeIds || [], p = n && n.length > 0, M = !p && x.length > 0, I = p ? n : M ? x : null;
1486
+ if (g.children.forEach((C) => {
1487
+ if (C.visible() && C.getClassName() !== "Transformer" && C.hasName(j)) {
1488
+ if (I) {
1489
+ const U = C.id();
1490
+ if (!I.includes(U)) return;
1458
1491
  }
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);
1492
+ const O = C.getAttrs(), Ct = O.x || 0, Tt = O.y || 0, Lt = O.width || 0, Ot = O.height || 0;
1493
+ if (O.rotation || 0) {
1494
+ 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;
1495
+ a = Math.min(a, Ft), h = Math.min(h, Wt), c = Math.max(c, Gt), d = Math.max(d, $t);
1463
1496
  } else
1464
- i = Math.min(i, yt), a = Math.min(a, L), h = Math.max(h, yt + Vt), c = Math.max(c, L + Ut);
1497
+ a = Math.min(a, Ct), h = Math.min(h, Tt), c = Math.max(c, Ct + Lt), d = Math.max(d, Tt + Ot);
1465
1498
  }
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);
1499
+ }), a === 1 / 0 || h === 1 / 0) return;
1500
+ const E = c - a, z = d - h, P = a + E / 2, ft = h + z / 2, L = this.getState().viewport;
1501
+ let V = L.scale;
1502
+ if (i) {
1503
+ const C = (L.width - s * 2) / E, O = (L.height - s * 2) / z;
1504
+ V = Math.min(C, O, 1);
1472
1505
  }
1473
- const ut = P.width / 2 - b * E, ft = P.height / 2 - C * E;
1474
- this.updateViewport({ x: ut, y: ft, scale: E }, !0);
1506
+ const G = L.width / 2 - P * V, Et = L.height / 2 - ft * V;
1507
+ this.updateViewport({ x: G, y: Et, scale: V }, !0);
1475
1508
  }
1476
1509
  }
1477
- function ve(o, e, t, s = !1) {
1478
- const [n, i] = e, [a, h] = t, c = a + (o - n) / (i - n) * (h - a);
1510
+ function Me(o, e, t, s = !1) {
1511
+ const [i, n] = e, [a, h] = t, c = a + (o - i) / (n - i) * (h - a);
1479
1512
  return s ? a < h ? Math.max(Math.min(c, h), a) : Math.max(Math.min(c, a), h) : c;
1480
1513
  }
1481
- const Yt = [
1514
+ const Dt = [
1482
1515
  {
1483
1516
  min: -1,
1484
1517
  mid: 0.15,
@@ -1500,15 +1533,15 @@ const Yt = [
1500
1533
  step: 1
1501
1534
  }
1502
1535
  ];
1503
- function Ne({
1536
+ function _e({
1504
1537
  viewportX: o,
1505
1538
  viewportY: e,
1506
1539
  scale: t,
1507
1540
  size: s = 20,
1508
- showGrid: n = !0
1541
+ showGrid: i = !0
1509
1542
  }) {
1510
- const i = o / t, a = e / t, h = t;
1511
- return n ? /* @__PURE__ */ F(
1543
+ const n = o / t, a = e / t, h = t;
1544
+ return i ? /* @__PURE__ */ W(
1512
1545
  "svg",
1513
1546
  {
1514
1547
  className: "canvas-grid w-full h-full absolute top-0 left-0",
@@ -1516,38 +1549,38 @@ function Ne({
1516
1549
  xmlns: "http://www.w3.org/2000/svg",
1517
1550
  "aria-hidden": "true",
1518
1551
  children: [
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;
1521
- return /* @__PURE__ */ w(
1552
+ /* @__PURE__ */ v("defs", { children: Dt.map(({ min: c, mid: d, step: g }, x) => {
1553
+ 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;
1554
+ return /* @__PURE__ */ v(
1522
1555
  "pattern",
1523
1556
  {
1524
- id: `grid_${m}`,
1557
+ id: `grid_${g}`,
1525
1558
  width: p,
1526
1559
  height: p,
1527
1560
  patternUnits: "userSpaceOnUse",
1528
- children: /* @__PURE__ */ w(
1561
+ children: /* @__PURE__ */ v(
1529
1562
  "circle",
1530
1563
  {
1531
1564
  className: "tl-grid-dot",
1532
- cx: C,
1533
- cy: P,
1565
+ cx: E,
1566
+ cy: z,
1534
1567
  r: 1,
1535
- opacity: E
1568
+ opacity: P
1536
1569
  }
1537
1570
  )
1538
1571
  },
1539
- v
1572
+ x
1540
1573
  );
1541
1574
  }) }),
1542
- Yt.map(({ step: c }, g) => /* @__PURE__ */ w("rect", { width: "100%", height: "100%", fill: `url(#grid_${c})` }, g))
1575
+ Dt.map(({ step: c }, d) => /* @__PURE__ */ v("rect", { width: "100%", height: "100%", fill: `url(#grid_${c})` }, d))
1543
1576
  ]
1544
1577
  }
1545
1578
  ) : null;
1546
1579
  }
1547
- function Se(...o) {
1548
- return Qt(Jt(o));
1580
+ function Ie(...o) {
1581
+ return se(ee(o));
1549
1582
  }
1550
- const Me = Bt(
1583
+ const be = te(
1551
1584
  "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
1585
  {
1553
1586
  variants: {
@@ -1574,56 +1607,56 @@ const Me = Bt(
1574
1607
  }
1575
1608
  }
1576
1609
  );
1577
- function W({
1610
+ function $({
1578
1611
  className: o,
1579
1612
  variant: e = "default",
1580
1613
  size: t = "default",
1581
1614
  asChild: s = !1,
1582
- ...n
1615
+ ...i
1583
1616
  }) {
1584
- return /* @__PURE__ */ w(
1585
- s ? jt : "button",
1617
+ return /* @__PURE__ */ v(
1618
+ s ? Qt : "button",
1586
1619
  {
1587
1620
  "data-slot": "button",
1588
1621
  "data-variant": e,
1589
1622
  "data-size": t,
1590
- className: Se(Me({ variant: e, size: t, className: o })),
1591
- ...n
1623
+ className: Ie(be({ variant: e, size: t, className: o })),
1624
+ ...i
1592
1625
  }
1593
1626
  );
1594
1627
  }
1595
- function _e({ api: o }) {
1596
- const [e, t] = G(o.getState().viewport);
1628
+ function Ee({ api: o }) {
1629
+ const [e, t] = q(o.getState().viewport);
1597
1630
  It(() => {
1598
1631
  o.on("viewport:change", (c) => {
1599
1632
  t(c);
1600
1633
  });
1601
1634
  }, [t, o]);
1602
1635
  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 });
1605
- }, n = () => {
1636
+ 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;
1637
+ o.updateViewport({ x: M, y: I, scale: c });
1638
+ }, i = () => {
1606
1639
  const c = Math.min(e.scale * 1.2, 5);
1607
1640
  s(c);
1608
- }, i = () => {
1641
+ }, n = () => {
1609
1642
  const c = Math.max(e.scale / 1.2, 0.1);
1610
1643
  s(c);
1611
1644
  }, a = () => {
1612
1645
  s(1);
1613
1646
  }, h = Math.round(e.scale * 100);
1614
- return /* @__PURE__ */ F("div", { className: "zoom-panel flex items-center gap-2", children: [
1615
- /* @__PURE__ */ w(
1616
- W,
1647
+ return /* @__PURE__ */ W("div", { className: "zoom-panel flex items-center gap-2", children: [
1648
+ /* @__PURE__ */ v(
1649
+ $,
1617
1650
  {
1618
1651
  size: "sm",
1619
1652
  variant: "secondary",
1620
- onClick: i,
1653
+ onClick: n,
1621
1654
  title: "缩小",
1622
- children: /* @__PURE__ */ w(te, {})
1655
+ children: /* @__PURE__ */ v(ie, {})
1623
1656
  }
1624
1657
  ),
1625
- /* @__PURE__ */ F(
1626
- W,
1658
+ /* @__PURE__ */ W(
1659
+ $,
1627
1660
  {
1628
1661
  size: "sm",
1629
1662
  variant: "secondary",
@@ -1636,81 +1669,81 @@ function _e({ api: o }) {
1636
1669
  ]
1637
1670
  }
1638
1671
  ),
1639
- /* @__PURE__ */ w(
1640
- W,
1672
+ /* @__PURE__ */ v(
1673
+ $,
1641
1674
  {
1642
1675
  size: "sm",
1643
1676
  variant: "secondary",
1644
- onClick: n,
1677
+ onClick: i,
1645
1678
  title: "放大",
1646
- children: /* @__PURE__ */ w(ee, {})
1679
+ children: /* @__PURE__ */ v(ne, {})
1647
1680
  }
1648
1681
  )
1649
1682
  ] });
1650
1683
  }
1651
- function Ie({ api: o }) {
1652
- const [e, t] = G(o.canUndo()), [s, n] = G(o.canRedo());
1684
+ function Ce({ api: o }) {
1685
+ const [e, t] = q(o.canUndo()), [s, i] = q(o.canRedo());
1653
1686
  return It(() => {
1654
- const i = () => {
1655
- t(o.canUndo()), n(o.canRedo());
1687
+ const n = () => {
1688
+ t(o.canUndo()), i(o.canRedo());
1656
1689
  };
1657
- return o.on("state:change", i), () => {
1658
- o.off("state:change", i);
1690
+ return o.on("state:change", n), () => {
1691
+ o.off("state:change", n);
1659
1692
  };
1660
- }, [o]), /* @__PURE__ */ F("div", { className: "history-panel flex items-center gap-2", children: [
1661
- /* @__PURE__ */ w(
1662
- W,
1693
+ }, [o]), /* @__PURE__ */ W("div", { className: "history-panel flex items-center gap-2", children: [
1694
+ /* @__PURE__ */ v(
1695
+ $,
1663
1696
  {
1664
1697
  size: "sm",
1665
1698
  variant: "secondary",
1666
1699
  disabled: !e,
1667
1700
  onClick: () => o.undo(),
1668
1701
  title: "撤销",
1669
- children: /* @__PURE__ */ w(se, {})
1702
+ children: /* @__PURE__ */ v(re, {})
1670
1703
  }
1671
1704
  ),
1672
- /* @__PURE__ */ w(
1673
- W,
1705
+ /* @__PURE__ */ v(
1706
+ $,
1674
1707
  {
1675
1708
  size: "sm",
1676
1709
  variant: "secondary",
1677
1710
  disabled: !s,
1678
1711
  onClick: () => o.redo(),
1679
1712
  title: "重做",
1680
- children: /* @__PURE__ */ w(ie, {})
1713
+ children: /* @__PURE__ */ v(oe, {})
1681
1714
  }
1682
1715
  )
1683
1716
  ] });
1684
1717
  }
1685
- function Ae({ setApi: o }) {
1686
- const e = qt(null), [t, s] = G(null), [n, i] = G({ x: 0, y: 0, scale: 1 });
1718
+ function He({ setApi: o }) {
1719
+ const e = Bt(null), [t, s] = q(null), [i, n] = q({ x: 0, y: 0, scale: 1 });
1687
1720
  return It(() => {
1688
1721
  if (!e.current) return;
1689
- const a = new we(e.current);
1722
+ const a = new Se(e.current);
1690
1723
  return s(a), o?.(a), a.on("viewport:change", (h) => {
1691
- i(h);
1724
+ n(h);
1692
1725
  }), a.on("transformer:positionChange", (h) => {
1693
1726
  console.log("Transformer position changed:", h);
1694
1727
  }), () => {
1695
1728
  a.dispose();
1696
1729
  };
1697
- }, [o]), /* @__PURE__ */ F("div", { className: "pure-canvas relative size-full", children: [
1698
- /* @__PURE__ */ w(
1699
- Ne,
1730
+ }, [o]), /* @__PURE__ */ W("div", { className: "pure-canvas relative size-full", children: [
1731
+ /* @__PURE__ */ v(
1732
+ _e,
1700
1733
  {
1701
- viewportX: n.x,
1702
- viewportY: n.y,
1703
- scale: n.scale
1734
+ viewportX: i.x,
1735
+ viewportY: i.y,
1736
+ scale: i.scale
1704
1737
  }
1705
1738
  ),
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 }) })
1739
+ /* @__PURE__ */ v("div", { ref: e, className: "size-full" }),
1740
+ t && /* @__PURE__ */ W(jt, { children: [
1741
+ /* @__PURE__ */ v("div", { className: "history-panel-wrapper absolute bottom-4 left-4 z-10", children: /* @__PURE__ */ v(Ce, { api: t }) }),
1742
+ /* @__PURE__ */ v("div", { className: "zoom-panel-wrapper absolute bottom-4 right-4 z-10", children: /* @__PURE__ */ v(Ee, { api: t }) })
1710
1743
  ] })
1711
1744
  ] });
1712
1745
  }
1713
1746
  export {
1714
- we as CanvasApi,
1715
- Ae as PureCanvas
1747
+ Se as CanvasApi,
1748
+ He as PureCanvas
1716
1749
  };