@glodon-aiot/dataset-annotation 3.13.0-alpha.29 → 3.14.0-alpha.30

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.
Files changed (33) hide show
  1. package/dist/es/components/DetectionAnnotation/components/LabelMaker/RectLabel.mjs +151 -135
  2. package/dist/es/components/DetectionAnnotation/components/LabelMaker/index.mjs +244 -218
  3. package/dist/es/components/VLMAnnotation/RegionItem.mjs +135 -59
  4. package/dist/es/components/VLMAnnotation/TextAnnotationPanel.mjs +73 -62
  5. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteRegion.mjs +55 -40
  6. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.mjs +291 -162
  7. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRControl.mjs +100 -0
  8. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRRecognition.mjs +88 -55
  9. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionBoundaryCheck.mjs +103 -0
  10. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionLoader.mjs +123 -91
  11. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionSelection.mjs +42 -39
  12. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionUpdate.mjs +55 -60
  13. package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/ai.svg.mjs +4 -0
  14. package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/error.svg.mjs +4 -0
  15. package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/loading.svg.mjs +4 -0
  16. package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/star.svg.mjs +4 -0
  17. package/dist/es/components/VLMAnnotation/VLMLabelMaker/index.mjs +512 -387
  18. package/dist/es/components/VLMAnnotation/constants.mjs +39 -32
  19. package/dist/es/components/VLMAnnotation/index.mjs +187 -150
  20. package/dist/es/index.mjs +1 -1
  21. package/dist/lib/index.js +4 -4
  22. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteRegion.d.ts +1 -0
  23. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.d.ts +3 -1
  24. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRControl.d.ts +16 -0
  25. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRRecognition.d.ts +3 -2
  26. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionBoundaryCheck.d.ts +31 -0
  27. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionLoader.d.ts +5 -1
  28. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionSelection.d.ts +2 -1
  29. package/dist/src/components/VLMAnnotation/VLMLabelMaker/index.d.ts +2 -2
  30. package/dist/src/components/VLMAnnotation/constants.d.ts +19 -3
  31. package/dist/src/components/VLMAnnotation/index.d.ts +1 -1
  32. package/dist/src/components/VLMAnnotation/types.d.ts +15 -0
  33. package/package.json +2 -2
@@ -1,20 +1,20 @@
1
- var j = Object.defineProperty, A = Object.defineProperties;
2
- var B = Object.getOwnPropertyDescriptors;
3
- var F = Object.getOwnPropertySymbols;
4
- var T = Object.prototype.hasOwnProperty, I = Object.prototype.propertyIsEnumerable;
5
- var w = (l, i, s) => i in l ? j(l, i, { enumerable: !0, configurable: !0, writable: !0, value: s }) : l[i] = s, f = (l, i) => {
6
- for (var s in i || (i = {}))
7
- T.call(i, s) && w(l, s, i[s]);
8
- if (F)
9
- for (var s of F(i))
10
- I.call(i, s) && w(l, s, i[s]);
11
- return l;
12
- }, C = (l, i) => A(l, B(i));
13
- var d = (l, i, s) => (w(l, typeof i != "symbol" ? i + "" : i, s), s);
14
- import { fabric as g } from "fabric";
15
- import O from "./FabricCustomize.mjs";
1
+ var A = Object.defineProperty, B = Object.defineProperties;
2
+ var T = Object.getOwnPropertyDescriptors;
3
+ var U = Object.getOwnPropertySymbols;
4
+ var H = Object.prototype.hasOwnProperty, D = Object.prototype.propertyIsEnumerable;
5
+ var C = (r, e, s) => e in r ? A(r, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : r[e] = s, d = (r, e) => {
6
+ for (var s in e || (e = {}))
7
+ H.call(e, s) && C(r, s, e[s]);
8
+ if (U)
9
+ for (var s of U(e))
10
+ D.call(e, s) && C(r, s, e[s]);
11
+ return r;
12
+ }, m = (r, e) => B(r, T(e));
13
+ var b = (r, e, s) => (C(r, typeof e != "symbol" ? e + "" : e, s), s);
14
+ import { fabric as v } from "fabric";
15
+ import I from "./FabricCustomize.mjs";
16
16
  import { formatColorToArray as X } from "../../../../utils/color.mjs";
17
- const z = {
17
+ const O = {
18
18
  borderWidth: 2,
19
19
  controls: ["TL", "BL", "TR", "BR"],
20
20
  cornerStrokeColor: "#84868C",
@@ -23,15 +23,15 @@ const z = {
23
23
  active: !1
24
24
  };
25
25
  class M {
26
- constructor(i, s, a) {
27
- d(this, "config");
28
- d(this, "color");
29
- d(this, "_active", !1);
30
- d(this, "_fabricRect", null);
31
- d(this, "_label", null);
32
- d(this, "_hover", !1);
33
- d(this, "_strokeRect");
34
- this._canvas = s, this.handlers = a, g.Rect.prototype.cornerColor = "blue", this.config = f(f({}, z), i), this.color = X(i.color), this._active = this.config.active || !1, s && this.render(s);
26
+ constructor(e, s, c) {
27
+ b(this, "config");
28
+ b(this, "color");
29
+ b(this, "_active", !1);
30
+ b(this, "_fabricRect", null);
31
+ b(this, "_label", null);
32
+ b(this, "_hover", !1);
33
+ b(this, "_strokeRect");
34
+ this._canvas = s, this.handlers = c, v.Rect.prototype.cornerColor = "blue", this.config = d(d({}, O), e), this.color = X(e.color), this._active = this.config.active || !1, s && this.render(s);
35
35
  }
36
36
  get object() {
37
37
  return this._fabricRect;
@@ -39,22 +39,24 @@ class M {
39
39
  get active() {
40
40
  return this._active;
41
41
  }
42
- set active(i) {
42
+ set active(e) {
43
43
  var s;
44
- this._active = i, (s = this._fabricRect) != null && s.canvas && (i && !this.config.hideDelete ? (this._fabricRect.set(this.activeStyle), this.canvas.setActiveObject(this._fabricRect)) : (this.canvas.discardActiveObject(), this.hover || this._fabricRect.set(this.normalStyle)), this.canvas.requestRenderAll());
44
+ this._active = e, (s = this._fabricRect) != null && s.canvas && (e && !this.config.hideDelete ? (this._fabricRect.set(m(d({}, this.activeStyle), {
45
+ lockUniScaling: !1
46
+ })), this._fabricRect.uniformScaling = !1, this.canvas.setActiveObject(this._fabricRect)) : (this.canvas.discardActiveObject(), this.hover || this._fabricRect.set(this.normalStyle)), this.canvas.requestRenderAll());
45
47
  }
46
48
  get hover() {
47
49
  return this._hover;
48
50
  }
49
- set hover(i) {
50
- var s, a;
51
- this._hover = i, i ? (s = this._fabricRect) == null || s.set(this.hoverStyle) : this.active || (a = this._fabricRect) == null || a.set(this.normalStyle), this.canvas.requestRenderAll();
51
+ set hover(e) {
52
+ var s, c;
53
+ this._hover = e, e ? (s = this._fabricRect) == null || s.set(this.hoverStyle) : this.active || (c = this._fabricRect) == null || c.set(this.normalStyle), this.canvas.requestRenderAll();
52
54
  }
53
55
  get canvas() {
54
56
  return this._canvas;
55
57
  }
56
- set canvas(i) {
57
- this._canvas !== i && (this._canvas = i, this.render(i));
58
+ set canvas(e) {
59
+ this._canvas !== e && (this._canvas = e, this.render(e));
58
60
  }
59
61
  get normalStyle() {
60
62
  return {
@@ -68,7 +70,7 @@ class M {
68
70
  };
69
71
  }
70
72
  get activeStyle() {
71
- return C(f({}, this.normalStyle), {
73
+ return m(d({}, this.normalStyle), {
72
74
  content: `<svg height="500" width="500"><text fill="#ffffff" font-size="45" x="50" y="86">${this.config.name}</text></svg>`,
73
75
  fill: `rgba(${this.color[0]},${this.color[1]}, ${this.color[2]}, 0.1)`
74
76
  });
@@ -77,40 +79,42 @@ class M {
77
79
  return this.activeStyle;
78
80
  }
79
81
  createRect() {
80
- const i = {
82
+ const e = {
81
83
  hasBorders: !1,
82
84
  cornerSize: 6,
83
85
  cornerStrokeColor: "#84868C",
84
86
  cornerColor: "#FFFFFF",
85
87
  transparentCorners: !1
86
- }, s = 0, a = new g.Rect(
88
+ }, s = 0, c = new v.Rect(
87
89
  // this.config.points?.map((p) => ({ x: p[0], y: p[1] })),
88
- C(f(f({
90
+ m(d(d({
89
91
  left: this.config.points[0][0],
90
92
  top: this.config.points[0][1],
91
93
  width: this.config.points[2][0] - this.config.points[0][0] - s,
92
94
  height: this.config.points[2][1] - this.config.points[0][1] - s
93
- }, i), this.normalStyle), {
95
+ }, e), this.normalStyle), {
94
96
  // 禁止缩放时翻转
95
- lockScalingFlip: !0
97
+ lockScalingFlip: !0,
98
+ // 允许不保持比例调整(可以自由调整宽高)
99
+ lockUniScaling: !1
96
100
  })
97
101
  );
98
- a.setControlsVisibility({
102
+ c.setControlsVisibility({
99
103
  mtr: !1
100
104
  });
101
- const c = () => {
102
- if (a.canvas !== this.canvas) {
103
- this.canvas.off("after:render", c);
105
+ const l = () => {
106
+ if (c.canvas !== this.canvas) {
107
+ this.canvas.off("after:render", l);
104
108
  return;
105
109
  }
106
110
  this.canvas.contextContainer.strokeStyle = `rgb(${this.color[0]},${this.color[1]}, ${this.color[2]})`;
107
- const o = a.getBoundingRect();
111
+ const o = c.getBoundingRect();
108
112
  this._strokeRect = this.canvas.contextContainer.strokeRect(o.left + 0.5, o.top + 0.5, o.width, o.height);
109
113
  };
110
- return this.canvas.on("after:render", c), a;
114
+ return this.canvas.on("after:render", l), c;
111
115
  }
112
- scaledNumber(i) {
113
- return i / this.canvas.getZoom();
116
+ scaledNumber(e) {
117
+ return e / this.canvas.getZoom();
114
118
  }
115
119
  // getPolyVertices(poly: fabric.Rect) {
116
120
  // const points = poly.points,
@@ -133,26 +137,26 @@ class M {
133
137
  // });
134
138
  // }
135
139
  createLabelName() {
136
- const [i, s, a] = this.color, c = new g.Text(this.handlers.renderLabelItem ? this.handlers.renderLabelItem(this.config) : this.config.name, {
140
+ const [e, s, c] = this.color, l = new v.Text(this.handlers.renderLabelItem ? this.handlers.renderLabelItem(this.config) : this.config.name, {
137
141
  fill: "#FFFFFF",
138
142
  fontSize: 12,
139
143
  selectable: !1,
140
144
  evented: !1,
141
145
  top: 4,
142
146
  left: 8
143
- }), o = new g.Rect({
147
+ }), o = new v.Rect({
144
148
  selectable: !1,
145
149
  evented: !1,
146
150
  strokeWidth: 0,
147
- fill: `rgb(${i},${s},${a})`,
151
+ fill: `rgb(${e},${s},${c})`,
148
152
  rx: 2,
149
153
  ry: 2,
150
- width: (c.width || 0) + 16,
151
- height: (c.height || 0) + 8,
154
+ width: (l.width || 0) + 16,
155
+ height: (l.height || 0) + 8,
152
156
  left: 0,
153
157
  top: 0
154
158
  });
155
- return new g.Group([o, c], {
159
+ return new v.Group([o, l], {
156
160
  selectable: !1,
157
161
  evented: !1,
158
162
  // lockScalingX: false,
@@ -162,27 +166,27 @@ class M {
162
166
  });
163
167
  }
164
168
  renderLabel() {
165
- var i, s;
169
+ var e, s;
166
170
  if (this._fabricRect) {
167
171
  if (this._label || (this._label = this.createLabelName(), this.setLabelPosition()), this._label.canvas === this.canvas) {
168
- const a = this._label.getObjects().find((o) => o.type === "rect"), c = this._label.getObjects().find((o) => o.type === "text");
169
- if (c) {
170
- c.set({
172
+ const c = this._label.getObjects().find((o) => o.type === "rect"), l = this._label.getObjects().find((o) => o.type === "text");
173
+ if (l) {
174
+ l.set({
171
175
  text: this.handlers.renderLabelItem ? this.handlers.renderLabelItem(this.config) : this.config.name,
172
176
  left: 8
173
177
  // fontSize: this.scaledNumber(12),
174
178
  });
175
- const o = (c.getBoundingRect().width || 0) + 16;
176
- a == null || a.set({
179
+ const o = (l.getBoundingRect().width || 0) + 16;
180
+ c == null || c.set({
177
181
  fill: `rgba(${this.color[0]},${this.color[1]}, ${this.color[2]}, 1)`,
178
182
  width: o,
179
183
  left: -o / 2
180
- }), c.set({
184
+ }), l.set({
181
185
  left: -o / 2 + 8
182
186
  });
183
- const r = ((i = this._fabricRect.aCoords) == null ? void 0 : i.tl.x) !== void 0 ? (s = this._fabricRect.aCoords) == null ? void 0 : s.tl.x : void 0;
187
+ const g = ((e = this._fabricRect.aCoords) == null ? void 0 : e.tl.x) !== void 0 ? (s = this._fabricRect.aCoords) == null ? void 0 : s.tl.x : void 0;
184
188
  this._label.set({
185
- left: r,
189
+ left: g,
186
190
  width: o
187
191
  });
188
192
  }
@@ -192,118 +196,130 @@ class M {
192
196
  }
193
197
  }
194
198
  setLabelPosition() {
195
- var r, t, e, h;
199
+ var g, h, n, t;
196
200
  if (!this._fabricRect || !this._label)
197
201
  return;
198
- const i = this._label.getObjects().find((b) => b.type === "rect");
199
- if (!i)
202
+ const e = this._label.getObjects().find((i) => i.type === "rect");
203
+ if (!e)
200
204
  return;
201
- const s = i.height ? i.height : void 0, a = i.width ? i.width : void 0, c = ((r = this._fabricRect.aCoords) == null ? void 0 : r.tl.y) !== void 0 && s !== void 0 && i.scaleY ? ((t = this._fabricRect.aCoords) == null ? void 0 : t.tl.y) - s / this.canvas.getZoom() : void 0, o = ((e = this._fabricRect.aCoords) == null ? void 0 : e.tl.x) !== void 0 ? (h = this._fabricRect.aCoords) == null ? void 0 : h.tl.x : void 0;
205
+ const s = e.height ? e.height : void 0, c = e.width ? e.width : void 0, l = ((g = this._fabricRect.aCoords) == null ? void 0 : g.tl.y) !== void 0 && s !== void 0 && e.scaleY ? ((h = this._fabricRect.aCoords) == null ? void 0 : h.tl.y) - s / this.canvas.getZoom() : void 0, o = ((n = this._fabricRect.aCoords) == null ? void 0 : n.tl.x) !== void 0 ? (t = this._fabricRect.aCoords) == null ? void 0 : t.tl.x : void 0;
202
206
  this._label.set({
203
- top: c,
207
+ top: l,
204
208
  left: o,
205
209
  height: s,
206
- width: a,
210
+ width: c,
207
211
  scaleX: 1 / this.canvas.getZoom(),
208
212
  scaleY: 1 / this.canvas.getZoom()
209
- }), this.config = f({}, this.config);
213
+ }), this.config = d({}, this.config);
210
214
  }
211
- addToCanvas(i) {
215
+ addToCanvas(e) {
212
216
  if (!this._fabricRect)
213
217
  return;
214
- this.canvas = i, this.canvas.add(this._fabricRect), this._fabricRect.on("mouseover", (o) => {
218
+ this.canvas = e, this.canvas.add(this._fabricRect), this._fabricRect.on("mouseover", (h) => {
215
219
  this.hover = !0;
216
- }), this._fabricRect.on("mouseout", (o) => {
220
+ }), this._fabricRect.on("mouseout", (h) => {
217
221
  this.hover = !1;
218
222
  }), this._fabricRect.on("mousedown", () => {
219
223
  this._fabricRect && this.canvas.setActiveObject(this._fabricRect);
220
- });
221
- const s = (o) => {
222
- var r;
223
- (r = o.selected) != null && r.some((t) => t === this._fabricRect) ? this.active = !0 : this.active && (this.active = !1);
224
- };
225
- this.canvas.on("selection:created", s), this.canvas.on("selection:updated", s), this.canvas.on("selection:cleared", (o) => {
224
+ }), this._handleSelectionUpdate && (this.canvas.off("selection:created", this._handleSelectionUpdate), this.canvas.off("selection:updated", this._handleSelectionUpdate)), this._handleSelectionCleared && this.canvas.off("selection:cleared", this._handleSelectionCleared);
225
+ const s = (h) => {
226
+ var n;
227
+ (n = h.selected) != null && n.some((t) => t === this._fabricRect) ? (this.active = !0, this._fabricRect && (this._fabricRect.set({
228
+ lockUniScaling: !1
229
+ }), this._fabricRect.uniformScaling = !1)) : this.active && (this.active = !1);
230
+ }, c = (h) => {
226
231
  this.active && (this.active = !1);
227
- });
228
- const a = (o) => {
229
- var b, y, x, S, $, L;
230
- const r = o.transform.action;
231
- o.transform.corner;
232
- const t = o.transform.target, e = o.transform.target.canvas.backgroundImage, h = 0;
233
- if (e && (r === "drag" && (t.top < e.top && t.set({
234
- top: e.top
235
- }), t.top + (t.height + h) * t.scaleY > e.top + e.height && t.set({
236
- top: e.height + e.top - (t.height + h) * t.scaleY
237
- }), t.left < e.left && t.set({
238
- left: e.left
239
- }), t.left + (t.width + h) * t.scaleX > e.left + e.width && t.set({
240
- left: e.width + e.left - (t.width + h) * t.scaleX
241
- })), r === "scale" && (t.top + (t.height + h) * t.scaleY > e.top + e.height && t.set({
242
- top: (t.height + h) * t.scaleY > e.height ? e.top : e.top + e.height - (t.height + h) * t.scaleY,
243
- height: (t.height + h) * t.scaleY > e.height ? e.height - h : t.height + h
244
- }), t.left + (t.width + h) * t.scaleX > e.left + e.width && t.set({
245
- left: e.width + e.left - (t.width + h) * t.scaleX
246
- })), r === "scaleX" && (t.left + (t.width + h) * t.scaleX > e.left + e.width && t.set({
247
- left: t.left - (t.left + (t.width + h) * t.scaleX - (e.left + e.width))
248
- }), t.left < e.left && t.set({
249
- left: e.left
250
- })), r === "scaleY" && (t.top + (t.height + h) * t.scaleY > e.top + e.height && t.set({
251
- top: t.top - (t.top + (t.height + h) * t.scaleY - (e.top + e.height))
252
- }), t.top < e.top && t.set({
253
- top: e.top
254
- })), (t.width + h) * t.scaleX > e.width && t.set({
255
- left: e.left,
256
- width: (e.width - h) / t.scaleX
257
- }), (t.height + h) * t.scaleY > e.height && t.set({
258
- top: e.top,
259
- height: (e.height - h) / t.scaleY
260
- })), e) {
261
- const v = t.getBoundingRect(!0), R = (b = e.left) != null ? b : 0, m = (y = e.top) != null ? y : 0, k = R + ((x = e.width) != null ? x : 0), Y = m + ((S = e.height) != null ? S : 0);
262
- if (v.width > (($ = e.width) != null ? $ : v.width)) {
263
- const u = (e.width - h) / Math.max(t.width, 1);
232
+ };
233
+ this.canvas.on("selection:created", s), this.canvas.on("selection:updated", s), this.canvas.on("selection:cleared", c), this._handleSelectionUpdate = s, this._handleSelectionCleared = c;
234
+ const l = (h) => {
235
+ var y, x, $, j, k, L;
236
+ const n = h.transform.action;
237
+ h.transform.corner;
238
+ const t = h.transform.target, i = h.transform.target.canvas.backgroundImage, a = 0;
239
+ if (i && (n === "drag" && (t.top < i.top && t.set({
240
+ top: i.top
241
+ }), t.top + (t.height + a) * t.scaleY > i.top + i.height && t.set({
242
+ top: i.height + i.top - (t.height + a) * t.scaleY
243
+ }), t.left < i.left && t.set({
244
+ left: i.left
245
+ }), t.left + (t.width + a) * t.scaleX > i.left + i.width && t.set({
246
+ left: i.width + i.left - (t.width + a) * t.scaleX
247
+ })), n === "scale" && (t.top + (t.height + a) * t.scaleY > i.top + i.height && t.set({
248
+ top: (t.height + a) * t.scaleY > i.height ? i.top : i.top + i.height - (t.height + a) * t.scaleY,
249
+ height: (t.height + a) * t.scaleY > i.height ? i.height - a : t.height + a
250
+ }), t.left + (t.width + a) * t.scaleX > i.left + i.width && t.set({
251
+ left: i.width + i.left - (t.width + a) * t.scaleX
252
+ })), n === "scaleX" && (t.left + (t.width + a) * t.scaleX > i.left + i.width && t.set({
253
+ left: t.left - (t.left + (t.width + a) * t.scaleX - (i.left + i.width))
254
+ }), t.left < i.left && t.set({
255
+ left: i.left
256
+ })), n === "scaleY" && (t.top + (t.height + a) * t.scaleY > i.top + i.height && t.set({
257
+ top: t.top - (t.top + (t.height + a) * t.scaleY - (i.top + i.height))
258
+ }), t.top < i.top && t.set({
259
+ top: i.top
260
+ })), (t.width + a) * t.scaleX > i.width && t.set({
261
+ left: i.left,
262
+ width: (i.width - a) / t.scaleX
263
+ }), (t.height + a) * t.scaleY > i.height && t.set({
264
+ top: i.top,
265
+ height: (i.height - a) / t.scaleY
266
+ })), i) {
267
+ const _ = t.getBoundingRect(!0), u = (y = i.left) != null ? y : 0, S = (x = i.top) != null ? x : 0, Y = u + (($ = i.width) != null ? $ : 0), F = S + ((j = i.height) != null ? j : 0);
268
+ if (_.width > ((k = i.width) != null ? k : _.width)) {
269
+ const w = (i.width - a) / Math.max(t.width, 1);
264
270
  t.set({
265
- scaleX: Math.min(t.scaleX, u)
271
+ scaleX: Math.min(t.scaleX, w)
266
272
  });
267
273
  }
268
- if (v.height > ((L = e.height) != null ? L : v.height)) {
269
- const u = (e.height - h) / Math.max(t.height, 1);
274
+ if (_.height > ((L = i.height) != null ? L : _.height)) {
275
+ const w = (i.height - a) / Math.max(t.height, 1);
270
276
  t.set({
271
- scaleY: Math.min(t.scaleY, u)
277
+ scaleY: Math.min(t.scaleY, w)
272
278
  });
273
279
  }
274
- const n = t.getBoundingRect(!0);
275
- let _ = 0, p = 0;
276
- n.left < R ? _ = R - n.left : n.left + n.width > k && (_ = k - (n.left + n.width)), n.top < m ? p = m - n.top : n.top + n.height > Y && (p = Y - (n.top + n.height)), (_ !== 0 || p !== 0) && t.set({
277
- left: t.left + _,
278
- top: t.top + p
280
+ const f = t.getBoundingRect(!0);
281
+ let p = 0, R = 0;
282
+ f.left < u ? p = u - f.left : f.left + f.width > Y && (p = Y - (f.left + f.width)), f.top < S ? R = S - f.top : f.top + f.height > F && (R = F - (f.top + f.height)), (p !== 0 || R !== 0) && t.set({
283
+ left: t.left + p,
284
+ top: t.top + R
279
285
  });
280
286
  }
281
287
  this.canvas.renderAll();
282
- }, c = (o) => {
283
- a(o), this.setLabelPosition();
288
+ }, o = (h) => {
289
+ l(h), this.setLabelPosition();
284
290
  };
285
- this._fabricRect.on("moving", c), this._fabricRect.on("scaling", c), this._fabricRect.on("rotating", c), this._fabricRect.on("skewing", c), this._fabricRect.on("resizing", c), this.canvas.on("object:removed", (o) => {
286
- o.target === this._fabricRect && this.destroy();
287
- }), this.canvas.on("object:modified", (o) => {
288
- o.target === this._fabricRect && (this.setLabelPosition(), this.handlers.onChange && this.handlers.onChange(this));
291
+ this._fabricRect.on("moving", o), this._fabricRect.on("scaling", o), this._fabricRect.on("rotating", o), this._fabricRect.on("skewing", o), this._fabricRect.on("resizing", o), this._objectRemovedHandler && this.canvas.off("object:removed", this._objectRemovedHandler);
292
+ const g = (h) => {
293
+ var n;
294
+ ((n = h.target) == null ? void 0 : n.type) === "rect" && h.target === this._fabricRect && !this._isDestroying && this._fabricRect && this.destroy();
295
+ };
296
+ this.canvas.on("object:removed", g), this._objectRemovedHandler = g, this.canvas.on("object:modified", (h) => {
297
+ h.target === this._fabricRect && (this.setLabelPosition(), this.handlers.onChange && this.handlers.onChange(this));
289
298
  });
290
299
  }
291
- render(i) {
292
- O(g), this._fabricRect || (this._fabricRect = this.createRect()), this._fabricRect.canvas === this.canvas ? this._fabricRect.set({
300
+ render(e) {
301
+ I(v), this._fabricRect || (this._fabricRect = this.createRect()), this._fabricRect.canvas === this.canvas ? this._fabricRect.set({
293
302
  fill: `rgba(${this.color[0]},${this.color[1]}, ${this.color[2]}, 0)`,
294
303
  stroke: `rgba(${this.color[0]},${this.color[1]}, ${this.color[2]}, 1)`
295
- }) : this.addToCanvas(i), this.renderLabel();
304
+ }) : this.addToCanvas(e), this.renderLabel();
296
305
  try {
297
306
  this.canvas.renderAll();
298
307
  } catch (s) {
299
308
  console.log("render failed");
300
309
  }
301
310
  }
302
- set labelConfig(i) {
303
- this.config = f(f({}, this.config), i), this.color = X(i.color), this.render(this.canvas), this.handlers.onChange && this.handlers.onChange(this);
311
+ set labelConfig(e) {
312
+ this.config = d(d({}, this.config), e), this.color = X(e.color), this.render(this.canvas), this.handlers.onChange && this.handlers.onChange(this);
304
313
  }
305
314
  destroy() {
306
- this._fabricRect && this.canvas.remove(this._fabricRect), this._label && this.canvas.remove(this._label), this._label = null, this._fabricRect = null, this.canvas.requestRenderAll(), this.handlers.onDelete && this.handlers.onDelete(this);
315
+ if (!this._isDestroying) {
316
+ if (this._isDestroying = !0, this._objectRemovedHandler) {
317
+ this.canvas.off("object:removed", this._objectRemovedHandler);
318
+ const e = this._objectRemovedHandler;
319
+ this.canvas.off("object:removed", e), this._objectRemovedHandler = null;
320
+ }
321
+ this._handleSelectionUpdate && (this.canvas.off("selection:created", this._handleSelectionUpdate), this.canvas.off("selection:updated", this._handleSelectionUpdate), this._handleSelectionUpdate = null), this._handleSelectionCleared && (this.canvas.off("selection:cleared", this._handleSelectionCleared), this._handleSelectionCleared = null), this._fabricRect && this.canvas.remove(this._fabricRect), this._label && this.canvas.remove(this._label), this._label = null, this._fabricRect = null, this.canvas.requestRenderAll(), this.handlers.onDelete && this.handlers.onDelete(this);
322
+ }
307
323
  }
308
324
  }
309
325
  export {