@8btc/whiteboard 0.0.3 → 0.0.5

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,47 +1,47 @@
1
- var qt = Object.defineProperty;
1
+ var Kt = Object.defineProperty;
2
2
  var Rt = (o) => {
3
3
  throw TypeError(o);
4
4
  };
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";
5
+ var qt = (o, e, t) => e in o ? Kt(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
6
+ var Z = (o, e, t) => qt(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)), d = (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), v = (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 W, jsx as w, Fragment as jt } from "react/jsx-runtime";
9
+ import { useState as K, useEffect as It, useRef as Bt } from "react";
10
10
  import Y from "konva";
11
11
  import Jt from "mitt";
12
- import { v4 as K } from "uuid";
12
+ import { v4 as Q } from "uuid";
13
13
  import { Slot as Qt } from "@radix-ui/react-slot";
14
14
  import { cva as te } from "class-variance-authority";
15
15
  import { clsx as ee } from "clsx";
16
16
  import { twMerge as se } from "tailwind-merge";
17
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;
18
+ var y, l, R, tt, et, st, it, nt, rt, ot, at, zt;
19
19
  class ae {
20
20
  constructor(e, t) {
21
- l(this, ht);
22
- l(this, y);
23
- l(this, m);
24
- l(this, R, { x: 0, y: 0, scale: 1 });
21
+ d(this, at);
22
+ d(this, y);
23
+ d(this, l);
24
+ d(this, R, { x: 0, y: 0, scale: 1 });
25
25
  /**
26
26
  * 处理滚轮缩放和平移
27
27
  */
28
- l(this, et, (e) => {
28
+ d(this, tt, (e) => {
29
29
  e.evt.preventDefault();
30
- const s = r(this, m).getPointerPosition();
30
+ const s = r(this, l).getPointerPosition();
31
31
  if (s)
32
32
  if (e.evt.ctrlKey) {
33
33
  const i = r(this, R).scale, n = {
34
34
  x: (s.x - r(this, R).x) / i,
35
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 d = i;
37
+ let m = i;
38
38
  for (let p = 0; p < c; p++)
39
- d = h > 0 ? d * a : d / a;
40
- const g = Math.max(0.1, Math.min(5, d)), x = {
39
+ m = h > 0 ? m * a : m / a;
40
+ const g = Math.max(0.1, Math.min(5, m)), S = {
41
41
  x: s.x - n.x * g,
42
42
  y: s.y - n.y * g
43
43
  };
44
- r(this, y).updateViewport({ x: x.x, y: x.y, scale: g });
44
+ r(this, y).updateViewport({ x: S.x, y: S.y, scale: g });
45
45
  } else {
46
46
  const i = e.evt.shiftKey ? e.evt.deltaY : e.evt.deltaX, n = e.evt.shiftKey ? 0 : e.evt.deltaY;
47
47
  r(this, y).updateViewport({
@@ -50,11 +50,11 @@ class ae {
50
50
  });
51
51
  }
52
52
  });
53
- l(this, st, (e) => {
53
+ d(this, et, (e) => {
54
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, m), i = r(this, m).getRelativePointerPosition();
57
+ const s = e.target === r(this, l), i = r(this, l).getRelativePointerPosition();
58
58
  if (t === "select" && !s) {
59
59
  const n = e.target.id();
60
60
  n && r(this, y).selectNode(n, e.evt.shiftKey);
@@ -81,36 +81,36 @@ class ae {
81
81
  }
82
82
  r(this, y).selectNode();
83
83
  });
84
- l(this, it, () => {
84
+ d(this, st, () => {
85
85
  const e = r(this, y).getState().toolType;
86
86
  if (e === "hand")
87
87
  return;
88
- const t = r(this, m).getRelativePointerPosition();
88
+ const t = r(this, l).getRelativePointerPosition();
89
89
  (e === "rectangle" || e === "image-marker") && t && r(this, y).updateDraftNode(t);
90
90
  });
91
- l(this, nt, () => {
91
+ d(this, it, () => {
92
92
  const e = r(this, y).getState().toolType;
93
93
  e !== "hand" && (e === "rectangle" || e === "image-marker") && r(this, y).finalizeDraftNode();
94
94
  });
95
- l(this, rt, (e) => {
96
- if (e.target !== r(this, m))
95
+ d(this, nt, (e) => {
96
+ if (e.target !== r(this, l))
97
97
  return;
98
98
  const t = r(this, y).getState().toolType;
99
99
  t === "hand" ? this.setCursor("grabbing") : t === "select" && this.setCursor("all-scroll");
100
100
  });
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()
101
+ d(this, rt, (e) => {
102
+ e.target === r(this, l) && r(this, y).updateViewport({
103
+ x: r(this, l).x(),
104
+ y: r(this, l).y()
105
105
  });
106
106
  });
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()
107
+ d(this, ot, (e) => {
108
+ e.target === r(this, l) && (r(this, y).updateViewport({
109
+ x: r(this, l).x(),
110
+ y: r(this, l).y()
111
111
  }), this.resetCursor());
112
112
  });
113
- N(this, y, e), N(this, m, new Y.Stage({
113
+ v(this, y, e), v(this, l, new Y.Stage({
114
114
  container: t.container,
115
115
  width: t.width,
116
116
  height: t.height,
@@ -120,13 +120,13 @@ class ae {
120
120
  scaleY: 1,
121
121
  draggable: t.draggable ?? !1,
122
122
  className: t.className
123
- })), _(this, ht, Zt).call(this);
123
+ })), M(this, at, zt).call(this);
124
124
  }
125
125
  /**
126
126
  * 获取原生 Konva.Stage 实例
127
127
  */
128
128
  getStage() {
129
- return r(this, m);
129
+ return r(this, l);
130
130
  }
131
131
  /**
132
132
  * 获取当前视口状态
@@ -139,26 +139,26 @@ class ae {
139
139
  */
140
140
  setViewport(e) {
141
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);
142
+ v(this, R, 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
147
  setDraggable(e) {
148
- r(this, m).draggable(e);
148
+ r(this, l).draggable(e);
149
149
  }
150
150
  /**
151
151
  * 设置光标样式
152
152
  */
153
153
  setCursor(e) {
154
- const t = r(this, m).container();
154
+ const t = r(this, l).container();
155
155
  t.style.cursor = e;
156
156
  }
157
157
  /**
158
158
  * 重置光标样式
159
159
  */
160
160
  resetCursor() {
161
- const e = r(this, m).container();
161
+ const e = r(this, l).container();
162
162
  if (r(this, y).getState().toolType === "hand") {
163
163
  e.style.cursor = "grab";
164
164
  return;
@@ -169,65 +169,65 @@ class ae {
169
169
  * 销毁 Stage
170
170
  */
171
171
  destroy() {
172
- r(this, m).destroy();
172
+ r(this, l).destroy();
173
173
  }
174
174
  }
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(), /**
175
+ y = new WeakMap(), l = new WeakMap(), R = new WeakMap(), tt = new WeakMap(), et = new WeakMap(), st = new WeakMap(), it = new WeakMap(), nt = new WeakMap(), rt = new WeakMap(), ot = new WeakMap(), at = new WeakSet(), /**
176
176
  * 设置事件监听器
177
177
  */
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));
178
+ zt = function() {
179
+ r(this, l).on("wheel", r(this, tt)), r(this, l).on("pointerdown", r(this, et)), r(this, l).on("pointermove", r(this, st)), r(this, l).on("pointerup", r(this, it)), r(this, l).on("dragstart", r(this, nt)), r(this, l).on("dragmove", r(this, rt)), r(this, l).on("dragend", r(this, ot));
180
180
  };
181
- var B, f, ct, dt, lt, mt, gt, pt, ut, At;
181
+ var q, f, ht, ct, dt, lt, mt, gt, pt, At;
182
182
  class he {
183
183
  constructor(e, t) {
184
- l(this, ut);
185
- l(this, B);
186
- l(this, f);
184
+ d(this, pt);
185
+ d(this, q);
186
+ d(this, f);
187
187
  /**
188
188
  * 处理 transformstart 事件
189
189
  */
190
- l(this, ct, () => {
190
+ d(this, ht, () => {
191
191
  this.emitPositionChange();
192
192
  });
193
193
  /**
194
194
  * 处理 transform 事件
195
195
  */
196
- l(this, dt, () => {
196
+ d(this, ct, () => {
197
197
  console.log("transforming..."), this.emitPositionChange();
198
198
  });
199
199
  /**
200
200
  * 处理 transformend 事件
201
201
  */
202
- l(this, lt, () => {
202
+ d(this, dt, () => {
203
203
  this.emitPositionChange();
204
204
  });
205
205
  /**
206
206
  * 处理 dragstart 事件
207
207
  */
208
- l(this, mt, () => {
208
+ d(this, lt, () => {
209
209
  this.emitPositionChange();
210
210
  });
211
211
  /**
212
212
  * 处理 dragmove 事件
213
213
  */
214
- l(this, gt, () => {
214
+ d(this, mt, () => {
215
215
  this.emitPositionChange();
216
216
  });
217
217
  /**
218
218
  * 处理 dragend 事件
219
219
  */
220
- l(this, pt, () => {
220
+ d(this, gt, () => {
221
221
  this.emitPositionChange();
222
222
  });
223
- N(this, B, e), N(this, f, new Y.Transformer({
223
+ v(this, q, e), v(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
- })), _(this, ut, At).call(this);
230
+ })), M(this, pt, At).call(this);
231
231
  }
232
232
  /**
233
233
  * 获取原生 Konva.Transformer 实例
@@ -277,7 +277,7 @@ class he {
277
277
  */
278
278
  emitPositionChange() {
279
279
  const e = this.getPosition();
280
- r(this, B).emitEvent("transformer:positionChange", e);
280
+ r(this, q).emitEvent("transformer:positionChange", e);
281
281
  }
282
282
  /**
283
283
  * 销毁 Transformer
@@ -286,18 +286,18 @@ class he {
286
286
  r(this, f).destroy();
287
287
  }
288
288
  }
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(), /**
289
+ q = new WeakMap(), f = new WeakMap(), ht = new WeakMap(), ct = new WeakMap(), dt = new WeakMap(), lt = new WeakMap(), mt = new WeakMap(), gt = new WeakMap(), pt = new WeakSet(), /**
290
290
  * 设置事件监听器
291
291
  */
292
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));
293
+ r(this, f).on("transformstart", r(this, ht)), r(this, f).on("transform", r(this, ct)), r(this, f).on("transformend", r(this, dt)), r(this, f).on("dragstart", r(this, lt)), r(this, f).on("dragmove", r(this, mt)), r(this, f).on("dragend", r(this, gt));
294
294
  };
295
295
  class ce {
296
296
  constructor(e) {
297
- D(this, "_past", []);
298
- D(this, "_present");
299
- D(this, "_future", []);
300
- D(this, "_emitter");
297
+ Z(this, "_past", []);
298
+ Z(this, "_present");
299
+ Z(this, "_future", []);
300
+ Z(this, "_emitter");
301
301
  this._present = e, this._emitter = Jt();
302
302
  }
303
303
  /**
@@ -391,7 +391,7 @@ class ce {
391
391
  this._emitter.all.clear();
392
392
  }
393
393
  }
394
- const j = "shapeNameForSelect", u = {
394
+ const yt = "shapeNameForSelect", u = {
395
395
  CORNER_RADIUS: 6,
396
396
  MIN_SIZE: 10
397
397
  }, F = {
@@ -434,7 +434,7 @@ function me(o) {
434
434
  function ge(o) {
435
435
  return Array.isArray(o) && o.length > 1 ? o[0] + o[1] : 0;
436
436
  }
437
- function Xt(o) {
437
+ function Dt(o) {
438
438
  return {
439
439
  width: Math.max(Yt.MIN_SIZE, o.width() * o.scaleX()),
440
440
  height: Math.max(Yt.MIN_SIZE, o.height() * o.scaleY())
@@ -442,10 +442,10 @@ function Xt(o) {
442
442
  }
443
443
  class bt {
444
444
  constructor(e, t) {
445
- D(this, "core");
446
- D(this, "node");
447
- D(this, "element");
448
- D(this, "toolTypeChangeHandler");
445
+ Z(this, "core");
446
+ Z(this, "node");
447
+ Z(this, "element");
448
+ Z(this, "toolTypeChangeHandler");
449
449
  this.core = e, this.node = t, this.element = this.createElement(), this.toolTypeChangeHandler = (s) => {
450
450
  const i = s === "select";
451
451
  this.element.listening(i);
@@ -484,13 +484,13 @@ function pe(o, e) {
484
484
  isRunning: () => t.isRunning()
485
485
  };
486
486
  }
487
- var b, X, vt, Nt, Vt;
487
+ var I, D, vt, Nt, Vt;
488
488
  class ue extends bt {
489
489
  constructor(t, s) {
490
490
  super(t, s);
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());
491
+ d(this, D);
492
+ d(this, I, null);
493
+ s.style.animated && M(this, D, vt).call(this), M(this, D, Vt).call(this, this.getElement());
494
494
  }
495
495
  createElement() {
496
496
  const t = Math.max(
@@ -506,7 +506,7 @@ class ue extends bt {
506
506
  width: t,
507
507
  height: s,
508
508
  cornerRadius: u.CORNER_RADIUS,
509
- name: j,
509
+ name: yt,
510
510
  draggable: !0,
511
511
  stroke: "black",
512
512
  strokeWidth: 2
@@ -547,44 +547,44 @@ class ue extends bt {
547
547
  this.node.props.height ?? u.MIN_SIZE,
548
548
  u.MIN_SIZE
549
549
  );
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);
550
+ s.width(i), s.height(n), this.node.style.animated && !r(this, I) ? M(this, D, vt).call(this) : !this.node.style.animated && r(this, I) && M(this, D, Nt).call(this);
551
551
  }
552
552
  /**
553
553
  * 销毁
554
554
  */
555
555
  destroy() {
556
- _(this, X, Nt).call(this), super.destroy();
556
+ M(this, D, Nt).call(this), super.destroy();
557
557
  }
558
558
  }
559
- b = new WeakMap(), X = new WeakSet(), /**
559
+ I = new WeakMap(), D = 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
565
  const i = ge(s);
566
- N(this, b, pe(t, i)), r(this, b) && r(this, b).start();
566
+ v(this, I, pe(t, i)), r(this, I) && r(this, I).start();
567
567
  }, /**
568
568
  * 销毁动画
569
569
  */
570
570
  Nt = function() {
571
- r(this, b) && (r(this, b).stop(), N(this, b, null));
571
+ r(this, I) && (r(this, I).stop(), v(this, I, null));
572
572
  }, /**
573
573
  * 设置事件处理器
574
574
  */
575
575
  Vt = function(t = void 0) {
576
576
  const s = t ?? this.getElement();
577
577
  s.on("transformstart", () => {
578
- this.node.style.animated && r(this, b) && r(this, b).stop();
578
+ this.node.style.animated && r(this, I) && r(this, I).stop();
579
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(
580
+ const n = i.target, { width: a, height: h } = Dt(n), c = de(a, h, u.CORNER_RADIUS), m = le(
581
581
  c,
582
582
  me(this.node.style.size),
583
583
  this.node.style.line
584
584
  );
585
- n.scale({ x: 1, y: 1 }), n.width(a), n.height(h), n.dash(d.map((g) => g * this.core.getStageScale()));
585
+ n.scale({ x: 1, y: 1 }), n.width(a), n.height(h), n.dash(m.map((g) => g * this.core.getStageScale()));
586
586
  }), s.on("transformend", (i) => {
587
- const n = i.target, { width: a, height: h } = Xt(n), c = {
587
+ const n = i.target, { width: a, height: h } = Dt(n), c = {
588
588
  ...this.node.props,
589
589
  x: n.x(),
590
590
  y: n.y(),
@@ -594,7 +594,7 @@ Vt = function(t = void 0) {
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, b)?.isRunning() === !1 && r(this, b).start();
597
+ }), this.node.style.animated && r(this, I)?.isRunning() === !1 && r(this, I).start();
598
598
  }), s.on("dragend", (i) => {
599
599
  const n = i.target, a = {
600
600
  ...this.node.props,
@@ -610,8 +610,8 @@ var k, St, Ut, Mt, _t;
610
610
  class ye extends bt {
611
611
  constructor(t, s) {
612
612
  super(t, s);
613
- l(this, k);
614
- _(this, k, St).call(this), _(this, k, Ut).call(this, this.getElement());
613
+ d(this, k);
614
+ M(this, k, St).call(this), M(this, k, Ut).call(this, this.getElement());
615
615
  }
616
616
  createElement() {
617
617
  const t = document.createElement("canvas");
@@ -619,7 +619,7 @@ class ye extends bt {
619
619
  id: this.node.id,
620
620
  x: this.node.props.x,
621
621
  y: this.node.props.y,
622
- name: j,
622
+ name: yt,
623
623
  draggable: !0,
624
624
  image: t
625
625
  });
@@ -655,7 +655,7 @@ class ye extends bt {
655
655
  const i = Math.max(this.node.props.width, F.MIN_SIZE), n = Math.max(this.node.props.height, F.MIN_SIZE);
656
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 && _(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 && M(this, k, St).call(this);
659
659
  }
660
660
  /**
661
661
  * 销毁
@@ -687,7 +687,7 @@ St = function() {
687
687
  Ut = function(t) {
688
688
  t.on("transform", (s) => {
689
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);
690
+ i.scale({ x: 1, y: 1 }), i.width(n), i.height(a), M(this, k, Mt).call(this);
691
691
  }), t.on("transformend", (s) => {
692
692
  const i = s.target, n = {
693
693
  ...this.node.props,
@@ -699,9 +699,9 @@ Ut = function(t) {
699
699
  };
700
700
  this.node.props = n, this.core._syncNodeFromElement(this.node.id, {
701
701
  props: n
702
- }), _(this, k, _t).call(this);
702
+ }), M(this, k, _t).call(this);
703
703
  }), t.on("dragmove", () => {
704
- _(this, k, Mt).call(this);
704
+ M(this, k, Mt).call(this);
705
705
  }), t.on("dragend", (s) => {
706
706
  const i = s.target, n = {
707
707
  ...this.node.props,
@@ -710,7 +710,7 @@ Ut = function(t) {
710
710
  };
711
711
  this.node.props = n, this.core._syncNodeFromElement(this.node.id, {
712
712
  props: n
713
- }), _(this, k, _t).call(this);
713
+ }), M(this, k, _t).call(this);
714
714
  });
715
715
  }, /**
716
716
  * 同步 image-marker 节点的位置(实时更新 Konva 元素)
@@ -720,12 +720,12 @@ Mt = function() {
720
720
  if (!s) return;
721
721
  const i = t.x(), n = t.y(), a = t.width(), h = t.height(), c = s.find(
722
722
  (g) => g.hasName(this.node.id)
723
- ), d = this.core.getState().nodes || [];
723
+ ), m = this.core.getState().nodes || [];
724
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) => {
725
+ const S = m.find((p) => p.id === g.id());
726
+ if (S?.type === "image-marker" && S.meta.relativePosition) {
727
+ const { start: p, end: b } = S.meta.relativePosition, _ = i + p.percentX / 100 * a, E = n + p.percentY / 100 * h, X = i + b.percentX / 100 * a, P = n + b.percentY / 100 * h, ft = Math.min(_, X), O = Math.min(E, P), V = Math.abs(X - _), G = Math.abs(P - E);
728
+ g.position({ x: ft, y: O }), g.setAttrs({ width: V, height: G }), g.getChildren().forEach((C) => {
729
729
  C.getClassName() === "Rect" ? C.setAttrs({ width: V, height: G }) : C.getClassName() === "Group" && C.setAttrs({ x: V, y: G });
730
730
  });
731
731
  }
@@ -749,17 +749,17 @@ _t = function() {
749
749
  });
750
750
  });
751
751
  };
752
- var H, T, J, Q, yt, Ht;
752
+ var H, T, j, B, ut, Ht;
753
753
  class fe extends bt {
754
754
  constructor(t, s) {
755
755
  super(t, s);
756
- l(this, yt);
757
- l(this, H);
758
- l(this, T);
759
- l(this, J);
760
- l(this, Q);
756
+ d(this, ut);
757
+ d(this, H);
758
+ d(this, T);
759
+ d(this, j);
760
+ d(this, B);
761
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);
762
+ v(this, H, i.findOne(".rect")), v(this, T, i.findOne(".marker-group")), v(this, j, r(this, T).findOne("Circle")), v(this, B, r(this, T).findOne("Text")), M(this, ut, Ht).call(this);
763
763
  }
764
764
  createElement() {
765
765
  const t = Math.max(
@@ -790,7 +790,7 @@ class fe extends bt {
790
790
  name: "marker-group",
791
791
  x: t,
792
792
  y: s
793
- }), c = 16 / this.core.getStageScale(), d = new Y.Circle({
793
+ }), c = 16 / this.core.getStageScale(), m = new Y.Circle({
794
794
  radius: c,
795
795
  fill: "red",
796
796
  stroke: "black",
@@ -806,7 +806,7 @@ class fe extends bt {
806
806
  fontSize: 16,
807
807
  fill: "white"
808
808
  });
809
- return a.add(d), a.add(g), i.add(n), i.add(a), i;
809
+ return a.add(m), a.add(g), i.add(n), i.add(a), i;
810
810
  }
811
811
  /**
812
812
  * 获取 Konva.Group 实例
@@ -843,7 +843,7 @@ class fe extends bt {
843
843
  this.node.props.height ?? u.MIN_SIZE,
844
844
  u.MIN_SIZE
845
845
  );
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));
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, B).text(String(t.meta.markerNumber));
847
847
  }
848
848
  /**
849
849
  * 销毁
@@ -856,10 +856,10 @@ class fe extends bt {
856
856
  */
857
857
  setFocusState(t) {
858
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);
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(), J = new WeakMap(), Q = new WeakMap(), yt = new WeakSet(), /**
862
+ H = new WeakMap(), T = new WeakMap(), j = new WeakMap(), B = new WeakMap(), ut = new WeakSet(), /**
863
863
  * 设置事件处理器
864
864
  */
865
865
  Ht = function() {
@@ -872,7 +872,7 @@ Ht = function() {
872
872
  this.core.selectNode(this.node.id);
873
873
  });
874
874
  };
875
- function zt(o, e, t) {
875
+ function Xt(o, e, t) {
876
876
  switch (e) {
877
877
  case "rectangle":
878
878
  return new ue(o, t);
@@ -887,7 +887,7 @@ function zt(o, e, t) {
887
887
  const xe = (o, e, t, s) => {
888
888
  const i = {
889
889
  type: o,
890
- id: K(),
890
+ id: Q(),
891
891
  text: null,
892
892
  style: {
893
893
  opacity: 1,
@@ -941,7 +941,7 @@ function ve(o, e) {
941
941
  { x: i, y: n }
942
942
  ];
943
943
  }
944
- var w, Z, A, S;
944
+ var x, z, A, N;
945
945
  class Ne extends ce {
946
946
  constructor(t) {
947
947
  super({
@@ -955,23 +955,23 @@ class Ne extends ce {
955
955
  toolType: "select",
956
956
  nodes: []
957
957
  });
958
- l(this, w);
959
- l(this, Z);
960
- l(this, A);
961
- l(this, S, null);
962
- N(this, w, new ae(this, {
958
+ d(this, x);
959
+ d(this, z);
960
+ d(this, A);
961
+ d(this, N, null);
962
+ v(this, x, 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, 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);
968
+ })), v(this, z, new Y.Layer()), v(this, A, new he(this)), r(this, x).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, w);
974
+ return r(this, x);
975
975
  }
976
976
  /**
977
977
  * 获取 CanvasTransformer 实例
@@ -989,19 +989,19 @@ class Ne extends ce {
989
989
  * 获取 Konva.Stage 实例
990
990
  */
991
991
  getStage() {
992
- return r(this, w).getStage();
992
+ return r(this, x).getStage();
993
993
  }
994
994
  /**
995
995
  * 获取 Stage 容器元素
996
996
  */
997
997
  getContainer() {
998
- return r(this, w).getStage().container();
998
+ return r(this, x).getStage().container();
999
999
  }
1000
1000
  /**
1001
1001
  * 获取主图层
1002
1002
  */
1003
1003
  getMainLayer() {
1004
- return r(this, Z);
1004
+ return r(this, z);
1005
1005
  }
1006
1006
  /**
1007
1007
  * 获取当前工具类型
@@ -1018,40 +1018,40 @@ class Ne extends ce {
1018
1018
  toolType: t
1019
1019
  },
1020
1020
  !1
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());
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
- r(this, w).setDraggable(t);
1027
+ r(this, x).setDraggable(t);
1028
1028
  }
1029
1029
  /**
1030
1030
  * 设置光标
1031
1031
  * @internal 仅供内部使用
1032
1032
  */
1033
1033
  setCursor(t) {
1034
- r(this, w).setCursor(t);
1034
+ r(this, x).setCursor(t);
1035
1035
  }
1036
1036
  /**
1037
1037
  * 重置光标
1038
1038
  * @internal 仅供内部使用
1039
1039
  */
1040
1040
  resetCursor() {
1041
- r(this, w).resetCursor();
1041
+ r(this, x).resetCursor();
1042
1042
  }
1043
1043
  /**
1044
1044
  * 获取当前 Stage 缩放比例
1045
1045
  */
1046
1046
  getStageScale() {
1047
- return r(this, w).getStage().scaleX();
1047
+ return r(this, x).getStage().scaleX();
1048
1048
  }
1049
1049
  /**
1050
1050
  * 更新视口位置
1051
1051
  * @internal 仅供内部使用,外部请使用 CanvasApi
1052
1052
  */
1053
1053
  updateViewport(t, s = !1) {
1054
- r(this, w).setViewport(t);
1054
+ r(this, x).setViewport(t);
1055
1055
  const i = {
1056
1056
  ...this.getState().viewport,
1057
1057
  ...t
@@ -1064,8 +1064,8 @@ class Ne extends ce {
1064
1064
  ), this.emit("viewport:change", i), r(this, A).emitPositionChange();
1065
1065
  }
1066
1066
  createNodes(t) {
1067
- t.map((n) => zt(this, n.type, n)).filter((n) => n !== null).forEach((n) => {
1068
- r(this, Z).add(n.getElement());
1067
+ t.map((n) => Xt(this, n.type, n)).filter((n) => n !== null).forEach((n) => {
1068
+ r(this, z).add(n.getElement());
1069
1069
  });
1070
1070
  const i = [...this.getState().nodes || [], ...t];
1071
1071
  this._updateState(
@@ -1084,13 +1084,13 @@ class Ne extends ce {
1084
1084
  a.forEach((P) => {
1085
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 - 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(),
1087
+ const c = (s.x - n.x) / n.width * 100, m = (s.y - n.y) / n.height * 100, g = (i.x - n.x) / n.width * 100, S = (i.y - n.y) / n.height * 100, p = Math.min(s.x, i.x), b = Math.min(s.y, i.y), _ = Math.abs(i.x - s.x), E = Math.abs(i.y - s.y), X = {
1088
+ id: Q(),
1089
1089
  type: "image-marker",
1090
1090
  props: {
1091
1091
  x: p,
1092
- y: M,
1093
- width: I,
1092
+ y: b,
1093
+ width: _,
1094
1094
  height: E,
1095
1095
  rotation: 0,
1096
1096
  visible: !0
@@ -1107,23 +1107,23 @@ class Ne extends ce {
1107
1107
  relativePosition: {
1108
1108
  start: {
1109
1109
  percentX: Math.max(0, Math.min(100, c)),
1110
- percentY: Math.max(0, Math.min(100, d))
1110
+ percentY: Math.max(0, Math.min(100, m))
1111
1111
  },
1112
1112
  end: {
1113
1113
  percentX: Math.max(0, Math.min(100, g)),
1114
- percentY: Math.max(0, Math.min(100, x))
1114
+ percentY: Math.max(0, Math.min(100, S))
1115
1115
  }
1116
1116
  }
1117
1117
  }
1118
1118
  };
1119
- this.createNodes([z]);
1119
+ this.createNodes([X]);
1120
1120
  }
1121
1121
  /**
1122
1122
  * 在指定位置查找图片节点
1123
1123
  * @internal 仅供内部使用
1124
1124
  */
1125
1125
  findImageAtPosition(t) {
1126
- const s = r(this, w).getStage(), i = s.find(
1126
+ const s = r(this, x).getStage(), i = s.find(
1127
1127
  (a) => a.getClassName() === "Image"
1128
1128
  ), n = i.map(
1129
1129
  (a) => a.listening()
@@ -1144,34 +1144,34 @@ class Ne extends ce {
1144
1144
  * @internal 仅供内部使用
1145
1145
  */
1146
1146
  createDraftNode(t, s, i) {
1147
- r(this, S) && r(this, S).destroy();
1147
+ r(this, N) && r(this, N).destroy();
1148
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());
1149
+ v(this, N, Xt(this, t, n)), console.log(r(this, N)), r(this, N) && r(this, z).add(r(this, N).getElement());
1150
1150
  }
1151
1151
  /**
1152
1152
  * @internal 仅供内部使用
1153
1153
  */
1154
1154
  updateDraftNode(t, s) {
1155
- if (!r(this, S)) return;
1156
- const i = r(this, S).getNode(), n = we(i, t, s);
1157
- r(this, S).updateNode(n);
1155
+ if (!r(this, N)) return;
1156
+ const i = r(this, N).getNode(), n = we(i, t, s);
1157
+ r(this, N).updateNode(n);
1158
1158
  }
1159
1159
  /**
1160
1160
  * @internal 仅供内部使用
1161
1161
  */
1162
1162
  finalizeDraftNode() {
1163
- if (!r(this, S)) return;
1164
- const t = K(), s = r(this, S).getNode();
1163
+ if (!r(this, N)) return;
1164
+ const t = Q(), s = r(this, N).getNode();
1165
1165
  if (s.type === "image-marker" && s.meta.parent) {
1166
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 d = 0;
1170
+ let m = 0;
1171
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));
1172
+ E.type === "image-marker" && E.meta.parent === s.meta.parent && typeof E.meta.markerNumber == "number" && (m = Math.max(m, E.meta.markerNumber));
1173
1173
  });
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 = {
1174
+ const g = (a.x - n.x) / n.width * 100, S = (a.y - n.y) / n.height * 100, p = (h.x - n.x) / n.width * 100, b = (h.y - n.y) / n.height * 100, _ = {
1175
1175
  ...s,
1176
1176
  props: {
1177
1177
  ...s.props
@@ -1181,22 +1181,22 @@ class Ne extends ce {
1181
1181
  },
1182
1182
  meta: {
1183
1183
  parent: s.meta.parent,
1184
- markerNumber: d + 1,
1184
+ markerNumber: m + 1,
1185
1185
  relativePosition: {
1186
1186
  start: {
1187
1187
  percentX: Math.max(0, Math.min(100, g)),
1188
- percentY: Math.max(0, Math.min(100, x))
1188
+ percentY: Math.max(0, Math.min(100, S))
1189
1189
  },
1190
1190
  end: {
1191
1191
  percentX: Math.max(0, Math.min(100, p)),
1192
- percentY: Math.max(0, Math.min(100, M))
1192
+ percentY: Math.max(0, Math.min(100, b))
1193
1193
  }
1194
1194
  }
1195
1195
  },
1196
1196
  id: t,
1197
1197
  type: "image-marker"
1198
1198
  };
1199
- this.createNodes([I]), r(this, S).destroy(), N(this, S, null), this.setToolType("select");
1199
+ this.createNodes([_]), r(this, N).destroy(), v(this, N, null), this.setToolType("select");
1200
1200
  return;
1201
1201
  }
1202
1202
  const i = {
@@ -1212,7 +1212,7 @@ class Ne extends ce {
1212
1212
  },
1213
1213
  id: t
1214
1214
  };
1215
- this.createNodes([i]), r(this, S).destroy(), N(this, S, null), this.setToolType("select");
1215
+ this.createNodes([i]), r(this, N).destroy(), v(this, N, null), this.setToolType("select");
1216
1216
  }
1217
1217
  /**
1218
1218
  * 选择节点
@@ -1233,7 +1233,7 @@ class Ne extends ce {
1233
1233
  }
1234
1234
  let n = [];
1235
1235
  s ? n = i.length ? [...i, t] : [t] : n = [t];
1236
- const a = this.getStage().find(`.${j}`).filter((h) => {
1236
+ const a = this.getStage().find(`.${yt}`).filter((h) => {
1237
1237
  const c = h.id();
1238
1238
  return n.includes(c);
1239
1239
  });
@@ -1248,7 +1248,7 @@ class Ne extends ce {
1248
1248
  * 销毁 canvas
1249
1249
  */
1250
1250
  dispose() {
1251
- this.getCanvasTransformer().destroy(), this.getCanvasStage().destroy(), this._dispose();
1251
+ this.getCanvasTransformer().destroy(), this.getMainLayer().destroy(), this.getCanvasStage().destroy(), this._dispose();
1252
1252
  }
1253
1253
  /**
1254
1254
  * 从元素同步节点数据(供节点类内部使用)
@@ -1284,7 +1284,7 @@ class Ne extends ce {
1284
1284
  * 当 undo/redo 时被调用
1285
1285
  */
1286
1286
  _syncState(t) {
1287
- r(this, w).setViewport({
1287
+ r(this, x).setViewport({
1288
1288
  x: t.viewport.x,
1289
1289
  y: t.viewport.y,
1290
1290
  scale: t.viewport.scale,
@@ -1293,7 +1293,7 @@ class Ne extends ce {
1293
1293
  });
1294
1294
  }
1295
1295
  }
1296
- w = new WeakMap(), Z = new WeakMap(), A = new WeakMap(), S = new WeakMap();
1296
+ x = new WeakMap(), z = new WeakMap(), A = new WeakMap(), N = new WeakMap();
1297
1297
  class Se extends Ne {
1298
1298
  /**
1299
1299
  * 获取所有可用的工具类型
@@ -1307,6 +1307,13 @@ class Se extends Ne {
1307
1307
  setToolType(e) {
1308
1308
  super.setToolType(e);
1309
1309
  }
1310
+ /**
1311
+ * 手动创建多个节点
1312
+ * 如果你不知道自己在干什么,请使用更高层的封装方法,如 createImageNode
1313
+ */
1314
+ createNodes(e) {
1315
+ super.createNodes(e);
1316
+ }
1310
1317
  /**
1311
1318
  * 更新视口位置
1312
1319
  */
@@ -1318,7 +1325,7 @@ class Se extends Ne {
1318
1325
  */
1319
1326
  createImageNode(e, t) {
1320
1327
  const s = t ?? { x: 100, y: 100 }, i = {
1321
- id: K(),
1328
+ id: Q(),
1322
1329
  type: "image",
1323
1330
  props: {
1324
1331
  x: s.x,
@@ -1340,58 +1347,6 @@ class Se extends Ne {
1340
1347
  };
1341
1348
  this.createNodes([i]);
1342
1349
  }
1343
- /**
1344
- * 在当前所有节点的左下角插入图片,并将其居中显示
1345
- * 如果没有节点,插入到画布中心
1346
- * @param imageUrl - 图片 URL
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);
1361
- }
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
- };
1369
- }
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(() => {
1392
- this.scrollToContent({ scale: !0 });
1393
- });
1394
- }
1395
1350
  /**
1396
1351
  * 导出全部图形为图片
1397
1352
  * @param options - 导出配置
@@ -1419,7 +1374,7 @@ class Se extends Ne {
1419
1374
  const t = this.getCanvasTransformer().getPosition();
1420
1375
  if (!t)
1421
1376
  return console.warn("No selection to export"), null;
1422
- const s = this.getStage(), i = e?.padding ?? 10, n = this.getCanvasTransformer().getTransformer(), a = n.visible();
1377
+ const s = this.getStage(), i = e?.padding ?? 0, n = this.getCanvasTransformer().getTransformer(), a = n.visible();
1423
1378
  n.visible(!1);
1424
1379
  try {
1425
1380
  return s.toDataURL({
@@ -1427,7 +1382,7 @@ class Se extends Ne {
1427
1382
  y: t.y - i,
1428
1383
  width: t.width + i * 2,
1429
1384
  height: t.height + i * 2,
1430
- pixelRatio: e?.pixelRatio ?? 2,
1385
+ pixelRatio: e?.pixelRatio ?? 1,
1431
1386
  mimeType: e?.mimeType ?? "image/png",
1432
1387
  quality: e?.quality ?? 1
1433
1388
  });
@@ -1481,29 +1436,29 @@ class Se extends Ne {
1481
1436
  scrollToContent(e) {
1482
1437
  if ((this.getState().nodes || []).length === 0) return;
1483
1438
  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;
1439
+ let a = 1 / 0, h = 1 / 0, c = -1 / 0, m = -1 / 0;
1440
+ const g = this.getMainLayer(), S = this.getState().selectedNodeIds || [], p = n && n.length > 0, b = !p && S.length > 0, _ = p ? n : b ? S : null;
1486
1441
  if (g.children.forEach((C) => {
1487
- if (C.visible() && C.getClassName() !== "Transformer" && C.hasName(j)) {
1488
- if (I) {
1442
+ if (C.visible() && C.getClassName() !== "Transformer" && C.hasName(yt)) {
1443
+ if (_) {
1489
1444
  const U = C.id();
1490
- if (!I.includes(U)) return;
1445
+ if (!_.includes(U)) return;
1491
1446
  }
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);
1447
+ const L = C.getAttrs(), Ct = L.x || 0, Tt = L.y || 0, Ot = L.width || 0, Lt = L.height || 0;
1448
+ if (L.rotation || 0) {
1449
+ const U = C.getClientRect({ skipTransform: !1 }), xt = this.getStage(), J = xt.scaleX(), kt = xt.x(), Pt = xt.y(), Ft = (U.x - kt) / J, Wt = (U.y - Pt) / J, Gt = (U.x + U.width - kt) / J, $t = (U.y + U.height - Pt) / J;
1450
+ a = Math.min(a, Ft), h = Math.min(h, Wt), c = Math.max(c, Gt), m = Math.max(m, $t);
1496
1451
  } else
1497
- a = Math.min(a, Ct), h = Math.min(h, Tt), c = Math.max(c, Ct + Lt), d = Math.max(d, Tt + Ot);
1452
+ a = Math.min(a, Ct), h = Math.min(h, Tt), c = Math.max(c, Ct + Ot), m = Math.max(m, Tt + Lt);
1498
1453
  }
1499
1454
  }), 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;
1455
+ const E = c - a, X = m - h, P = a + E / 2, ft = h + X / 2, O = this.getState().viewport;
1456
+ let V = O.scale;
1502
1457
  if (i) {
1503
- const C = (L.width - s * 2) / E, O = (L.height - s * 2) / z;
1504
- V = Math.min(C, O, 1);
1458
+ const C = (O.width - s * 2) / E, L = (O.height - s * 2) / X;
1459
+ V = Math.min(C, L, 1);
1505
1460
  }
1506
- const G = L.width / 2 - P * V, Et = L.height / 2 - ft * V;
1461
+ const G = O.width / 2 - P * V, Et = O.height / 2 - ft * V;
1507
1462
  this.updateViewport({ x: G, y: Et, scale: V }, !0);
1508
1463
  }
1509
1464
  }
@@ -1511,7 +1466,7 @@ function Me(o, e, t, s = !1) {
1511
1466
  const [i, n] = e, [a, h] = t, c = a + (o - i) / (n - i) * (h - a);
1512
1467
  return s ? a < h ? Math.max(Math.min(c, h), a) : Math.max(Math.min(c, a), h) : c;
1513
1468
  }
1514
- const Dt = [
1469
+ const Zt = [
1515
1470
  {
1516
1471
  min: -1,
1517
1472
  mid: 0.15,
@@ -1549,30 +1504,30 @@ function _e({
1549
1504
  xmlns: "http://www.w3.org/2000/svg",
1550
1505
  "aria-hidden": "true",
1551
1506
  children: [
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(
1507
+ /* @__PURE__ */ w("defs", { children: Zt.map(({ min: c, mid: m, step: g }, S) => {
1508
+ const p = g * s * h, b = 0.5 + n * h, _ = 0.5 + a * h, E = b > 0 ? b % p : p + b % p, X = _ > 0 ? _ % p : p + _ % p, P = h < m ? Me(h, [c, m], [0, 1]) : 1;
1509
+ return /* @__PURE__ */ w(
1555
1510
  "pattern",
1556
1511
  {
1557
1512
  id: `grid_${g}`,
1558
1513
  width: p,
1559
1514
  height: p,
1560
1515
  patternUnits: "userSpaceOnUse",
1561
- children: /* @__PURE__ */ v(
1516
+ children: /* @__PURE__ */ w(
1562
1517
  "circle",
1563
1518
  {
1564
1519
  className: "tl-grid-dot",
1565
1520
  cx: E,
1566
- cy: z,
1521
+ cy: X,
1567
1522
  r: 1,
1568
1523
  opacity: P
1569
1524
  }
1570
1525
  )
1571
1526
  },
1572
- x
1527
+ S
1573
1528
  );
1574
1529
  }) }),
1575
- Dt.map(({ step: c }, d) => /* @__PURE__ */ v("rect", { width: "100%", height: "100%", fill: `url(#grid_${c})` }, d))
1530
+ Zt.map(({ step: c }, m) => /* @__PURE__ */ w("rect", { width: "100%", height: "100%", fill: `url(#grid_${c})` }, m))
1576
1531
  ]
1577
1532
  }
1578
1533
  ) : null;
@@ -1614,7 +1569,7 @@ function $({
1614
1569
  asChild: s = !1,
1615
1570
  ...i
1616
1571
  }) {
1617
- return /* @__PURE__ */ v(
1572
+ return /* @__PURE__ */ w(
1618
1573
  s ? Qt : "button",
1619
1574
  {
1620
1575
  "data-slot": "button",
@@ -1626,15 +1581,15 @@ function $({
1626
1581
  );
1627
1582
  }
1628
1583
  function Ee({ api: o }) {
1629
- const [e, t] = q(o.getState().viewport);
1584
+ const [e, t] = K(o.getState().viewport);
1630
1585
  It(() => {
1631
1586
  o.on("viewport:change", (c) => {
1632
1587
  t(c);
1633
1588
  });
1634
1589
  }, [t, o]);
1635
1590
  const s = (c) => {
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 });
1591
+ const m = e.width / 2, g = e.height / 2, S = (m - e.x) / e.scale, p = (g - e.y) / e.scale, b = m - S * c, _ = g - p * c;
1592
+ o.updateViewport({ x: b, y: _, scale: c });
1638
1593
  }, i = () => {
1639
1594
  const c = Math.min(e.scale * 1.2, 5);
1640
1595
  s(c);
@@ -1645,14 +1600,14 @@ function Ee({ api: o }) {
1645
1600
  s(1);
1646
1601
  }, h = Math.round(e.scale * 100);
1647
1602
  return /* @__PURE__ */ W("div", { className: "zoom-panel flex items-center gap-2", children: [
1648
- /* @__PURE__ */ v(
1603
+ /* @__PURE__ */ w(
1649
1604
  $,
1650
1605
  {
1651
1606
  size: "sm",
1652
1607
  variant: "secondary",
1653
1608
  onClick: n,
1654
1609
  title: "缩小",
1655
- children: /* @__PURE__ */ v(ie, {})
1610
+ children: /* @__PURE__ */ w(ie, {})
1656
1611
  }
1657
1612
  ),
1658
1613
  /* @__PURE__ */ W(
@@ -1669,20 +1624,20 @@ function Ee({ api: o }) {
1669
1624
  ]
1670
1625
  }
1671
1626
  ),
1672
- /* @__PURE__ */ v(
1627
+ /* @__PURE__ */ w(
1673
1628
  $,
1674
1629
  {
1675
1630
  size: "sm",
1676
1631
  variant: "secondary",
1677
1632
  onClick: i,
1678
1633
  title: "放大",
1679
- children: /* @__PURE__ */ v(ne, {})
1634
+ children: /* @__PURE__ */ w(ne, {})
1680
1635
  }
1681
1636
  )
1682
1637
  ] });
1683
1638
  }
1684
1639
  function Ce({ api: o }) {
1685
- const [e, t] = q(o.canUndo()), [s, i] = q(o.canRedo());
1640
+ const [e, t] = K(o.canUndo()), [s, i] = K(o.canRedo());
1686
1641
  return It(() => {
1687
1642
  const n = () => {
1688
1643
  t(o.canUndo()), i(o.canRedo());
@@ -1691,7 +1646,7 @@ function Ce({ api: o }) {
1691
1646
  o.off("state:change", n);
1692
1647
  };
1693
1648
  }, [o]), /* @__PURE__ */ W("div", { className: "history-panel flex items-center gap-2", children: [
1694
- /* @__PURE__ */ v(
1649
+ /* @__PURE__ */ w(
1695
1650
  $,
1696
1651
  {
1697
1652
  size: "sm",
@@ -1699,10 +1654,10 @@ function Ce({ api: o }) {
1699
1654
  disabled: !e,
1700
1655
  onClick: () => o.undo(),
1701
1656
  title: "撤销",
1702
- children: /* @__PURE__ */ v(re, {})
1657
+ children: /* @__PURE__ */ w(re, {})
1703
1658
  }
1704
1659
  ),
1705
- /* @__PURE__ */ v(
1660
+ /* @__PURE__ */ w(
1706
1661
  $,
1707
1662
  {
1708
1663
  size: "sm",
@@ -1710,13 +1665,13 @@ function Ce({ api: o }) {
1710
1665
  disabled: !s,
1711
1666
  onClick: () => o.redo(),
1712
1667
  title: "重做",
1713
- children: /* @__PURE__ */ v(oe, {})
1668
+ children: /* @__PURE__ */ w(oe, {})
1714
1669
  }
1715
1670
  )
1716
1671
  ] });
1717
1672
  }
1718
1673
  function He({ setApi: o }) {
1719
- const e = Bt(null), [t, s] = q(null), [i, n] = q({ x: 0, y: 0, scale: 1 });
1674
+ const e = Bt(null), [t, s] = K(null), [i, n] = K({ x: 0, y: 0, scale: 1 });
1720
1675
  return It(() => {
1721
1676
  if (!e.current) return;
1722
1677
  const a = new Se(e.current);
@@ -1728,7 +1683,7 @@ function He({ setApi: o }) {
1728
1683
  a.dispose();
1729
1684
  };
1730
1685
  }, [o]), /* @__PURE__ */ W("div", { className: "pure-canvas relative size-full", children: [
1731
- /* @__PURE__ */ v(
1686
+ /* @__PURE__ */ w(
1732
1687
  _e,
1733
1688
  {
1734
1689
  viewportX: i.x,
@@ -1736,14 +1691,16 @@ function He({ setApi: o }) {
1736
1691
  scale: i.scale
1737
1692
  }
1738
1693
  ),
1739
- /* @__PURE__ */ v("div", { ref: e, className: "size-full" }),
1694
+ /* @__PURE__ */ w("div", { ref: e, className: "size-full" }),
1740
1695
  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 }) })
1696
+ /* @__PURE__ */ w("div", { className: "history-panel-wrapper absolute bottom-4 left-4 z-10", children: /* @__PURE__ */ w(Ce, { api: t }) }),
1697
+ /* @__PURE__ */ w("div", { className: "zoom-panel-wrapper absolute bottom-4 right-4 z-10", children: /* @__PURE__ */ w(Ee, { api: t }) })
1743
1698
  ] })
1744
1699
  ] });
1745
1700
  }
1746
1701
  export {
1747
1702
  Se as CanvasApi,
1703
+ yt as NODE_NAME_FOR_SELECT,
1748
1704
  He as PureCanvas
1749
1705
  };
1706
+ //# sourceMappingURL=index.js.map