@servantcdh/ez-planet-labeling 0.1.0

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 ADDED
@@ -0,0 +1,2436 @@
1
+ import Ft, { createContext as Ze, useState as st, useMemo as it, useContext as Qe, useRef as Et, useEffect as St, useCallback as F } from "react";
2
+ import { jsx as p, jsxs as T, Fragment as je } from "react/jsx-runtime";
3
+ const lo = "Brush", At = "Bounded Box", re = "Filled Box", Ve = "Filled Polygon", Vt = "Magic Brush", kt = "Superpixel", zt = "BrushCursor", te = "SuperpixelBoundary", uo = "Combined Label", ee = "Segment Anything Box", fo = "Eraser", tn = 1, en = 0, nn = [
4
+ zt,
5
+ te,
6
+ ee
7
+ ], ie = [
8
+ "id",
9
+ "unique",
10
+ "hex",
11
+ "alpha",
12
+ "info",
13
+ "selected",
14
+ "class",
15
+ "added",
16
+ "index",
17
+ "seq",
18
+ "copied",
19
+ "combinded",
20
+ "labeler",
21
+ "labelInsertData",
22
+ "labelPayload",
23
+ "pathContours",
24
+ "pathEditableContourIndex",
25
+ "pathBaseOffset",
26
+ "points"
27
+ ], sn = 5, on = 3;
28
+ let Rt = null;
29
+ const an = async () => (Rt || (Rt = await import("fabric")), Rt), H = () => {
30
+ if (!Rt)
31
+ throw new Error(
32
+ "Fabric has not been loaded. Call loadFabric() first (async)."
33
+ );
34
+ return Rt;
35
+ }, vt = () => H().Point, rn = () => H().Line, Ne = () => H().Rect, Pe = () => H().Polygon, cn = () => H().PencilBrush, ln = () => H().Circle, ke = () => H().FabricImage, un = () => H().Control, dn = () => H().StaticCanvas;
36
+ let _t = null, fn = { x: 0, y: 0 }, hn = { x: 0, y: 0 };
37
+ const ot = () => _t, fe = (t) => {
38
+ _t = t;
39
+ }, mn = () => fn, gn = () => hn, ct = () => {
40
+ if (!_t)
41
+ throw new Error("Canvas has not been initialized.");
42
+ return _t;
43
+ }, vn = [
44
+ "load",
45
+ "selected",
46
+ "deleted",
47
+ "zoom",
48
+ "copy",
49
+ "paste",
50
+ "deleteSelected",
51
+ "selectAll",
52
+ "reset",
53
+ "combine",
54
+ "seq",
55
+ "addClass",
56
+ "deleteObjectsOfTool",
57
+ "addObjects",
58
+ "deselectAll",
59
+ "undo",
60
+ "redo",
61
+ "changed",
62
+ "blur",
63
+ "focus",
64
+ "init"
65
+ ], pn = (t) => {
66
+ const e = ot();
67
+ if (!e)
68
+ return () => {
69
+ };
70
+ const n = vn.map((o) => {
71
+ const s = `label:${o}`, a = (i) => {
72
+ t(o, i.data);
73
+ };
74
+ return e.on(s, a), { eventName: s, handler: a };
75
+ });
76
+ return () => {
77
+ n.forEach(({ eventName: o, handler: s }) => {
78
+ e.off(o, s);
79
+ });
80
+ };
81
+ }, bn = (t, e) => {
82
+ const n = ot();
83
+ n && n.fire(`label:${t}`, { data: e });
84
+ }, Le = (t) => t, ft = (t = ct()) => Le(t.getObjects()), ho = (t = ct()) => t.getActiveObjects(), yn = (t) => ({
85
+ ...t,
86
+ objects: Le(t.objects)
87
+ }), Tt = (t = ct()) => yn(t.toJSON(ie)), Pt = (t) => (e) => t(e), S = (t) => t, he = (t, e) => e === 0 ? 0 : t / e, Ht = ({ x: t, y: e }) => {
88
+ const o = ct().getZoom();
89
+ return { x: he(t, o), y: he(e, o) };
90
+ }, Ee = (t) => Ht({
91
+ x: t.offsetX,
92
+ y: t.offsetY
93
+ }), mt = (t) => {
94
+ const e = t ?? _t;
95
+ e && e.contextContainer && e.renderAll();
96
+ }, ce = (t, e) => {
97
+ const n = ct(), o = ln(), s = Ne(), a = mn();
98
+ n.remove(
99
+ ...ft(n).filter(
100
+ ({ info: r }) => r === zt
101
+ )
102
+ );
103
+ const i = {
104
+ info: zt,
105
+ left: -100,
106
+ top: -100,
107
+ width: t.lineWidth,
108
+ height: t.lineWidth,
109
+ radius: t.lineWidth / 2,
110
+ ...e ? { fill: e } : {
111
+ fill: "rgba(0, 0, 0, 0)",
112
+ stroke: "white",
113
+ strokeWidth: 1.5,
114
+ strokeDashArray: [3, 3]
115
+ },
116
+ originX: "center",
117
+ originY: "center",
118
+ selectable: !1
119
+ }, c = t.lineCap === "round" ? new o(i) : new s(i), u = (r) => {
120
+ if (!r && !a.x)
121
+ return;
122
+ const f = r == null ? void 0 : r.e, { x: v, y: h } = f ? n.getScenePoint(f) : a;
123
+ a.x = v, a.y = h, c.set({ top: h, left: v }), c.setCoords(), n.renderAll();
124
+ }, m = (r) => {
125
+ u(r);
126
+ }, d = () => {
127
+ bn("init");
128
+ };
129
+ return u(), { brushCursor: c, handleOnMouseMove: m, handleOnMouseUp: d };
130
+ }, le = ({ colorCode: t, callback: e }, n, o = !1) => {
131
+ const s = ct(), a = Ne();
132
+ o && (n = o, s.getObjects().forEach((r) => r.set({ visible: !1 })), s.renderAll());
133
+ let i = 0, c = 0;
134
+ const u = function(r) {
135
+ const f = r.scenePoint ?? r.pointer;
136
+ if (!f)
137
+ return;
138
+ const { x: v, y: h } = Ht(f);
139
+ i = v, c = h;
140
+ }, m = function(r) {
141
+ const f = r.scenePoint ?? r.pointer;
142
+ if (!f)
143
+ return;
144
+ const { x: v, y: h } = Ht(f), x = v - i, l = h - c;
145
+ let g = Math.abs(x), b = Math.abs(l), N = x > 0 ? i : v, w = l > 0 ? c : h;
146
+ const I = N < 0, C = w < 0;
147
+ g = I ? g + N : g, b = C ? b + w : b, N = I ? 0 : N, w = C ? 0 : w;
148
+ const P = s.getZoom(), y = Number(s.width ?? 0) / P, L = Number(s.height ?? 0) / P, _ = N + g > y, W = w + b > L;
149
+ g = _ ? g - (N + g - y) : g, b = W ? b - (w + b - L) : b;
150
+ const V = g && b ? new a({
151
+ left: N,
152
+ top: w,
153
+ width: g,
154
+ height: b,
155
+ ...n ? {
156
+ fill: "",
157
+ stroke: t,
158
+ strokeWidth: o ? on : sn,
159
+ erasable: !1,
160
+ info: o ? ee : At,
161
+ ...o ? {
162
+ strokeDashArray: [7, 5],
163
+ lockMovementX: !0,
164
+ lockMovementY: !0
165
+ } : {}
166
+ } : {
167
+ fill: t,
168
+ info: re
169
+ },
170
+ objectCaching: !1,
171
+ selectable: !1
172
+ }) : null;
173
+ if (o && !V && e && e({
174
+ point: { x: v, y: h, maskInput: tn }
175
+ }), o && V && e) {
176
+ const nt = Number(N ?? 0), M = Number(w ?? 0), D = nt + g, J = M + b;
177
+ e({ box: { x1: nt, y1: M, x2: D, y2: J } });
178
+ }
179
+ V && s.add(V);
180
+ }, d = function(r) {
181
+ r.preventDefault();
182
+ const { x: f, y: v } = Ht({ x: r.offsetX, y: r.offsetY });
183
+ r.target && r.target.localName === "canvas" && e && e({
184
+ point: { x: f, y: v, maskInput: en }
185
+ });
186
+ };
187
+ return s.defaultCursor = "crosshair", s.hoverCursor = o ? "crosshair" : "default", s.selection = !0, s.on("mouse:down", S(u)), s.on("mouse:up", S(m)), o && document.addEventListener("contextmenu", d), () => {
188
+ s.defaultCursor = "default", s.selection = !1, s.off("mouse:down", S(u)), s.off("mouse:up", S(m)), o && (document.removeEventListener("contextmenu", d), s.remove(
189
+ ...ft(s).filter(
190
+ ({ info: r }) => r === ee
191
+ )
192
+ ), ft(s).forEach(
193
+ (r) => r.set({ visible: !0 })
194
+ )), mt(s);
195
+ };
196
+ }, Te = () => ({ id: "brush", init: ({ brush: e, colorCode: n }) => {
197
+ const o = ct(), s = cn();
198
+ o.isDrawingMode = !0, o.freeDrawingBrush = new s(o), o.freeDrawingBrush.color = n, o.freeDrawingBrush.strokeLineCap = e.lineCap, o.freeDrawingBrush.width = e.lineWidth;
199
+ const { brushCursor: a, handleOnMouseMove: i, handleOnMouseUp: c } = ce(e, n), u = function() {
200
+ o.add(a);
201
+ }, m = function() {
202
+ o.remove(a);
203
+ };
204
+ return o.add(a), o.on("mouse:over", S(u)), o.on("mouse:out", S(m)), o.on("mouse:move", S(i)), o.on("mouse:up", S(c)), () => {
205
+ o.remove(a), o.off("mouse:over", S(u)), o.off("mouse:out", S(m)), o.off("mouse:move", S(i)), o.off("mouse:up", S(c)), o.isDrawingMode = !1;
206
+ };
207
+ } }), Re = () => ({ id: "eraser", init: async ({ brush: e }) => {
208
+ const n = ct(), { EraserBrush: o } = await import("./index-DDn_Fjhx.js");
209
+ n.freeDrawingBrush = new o(n), n.isDrawingMode = !0, n.freeDrawingBrush.strokeLineCap = e.lineCap, n.freeDrawingBrush.width = e.lineWidth;
210
+ const { brushCursor: s, handleOnMouseMove: a, handleOnMouseUp: i } = ce(e), c = function() {
211
+ n.add(s);
212
+ }, u = function() {
213
+ n.remove(s);
214
+ };
215
+ return n.add(s), n.on("mouse:over", S(c)), n.on("mouse:out", S(u)), n.on("mouse:move", S(a)), n.on("mouse:up", S(i)), () => {
216
+ n.remove(s), n.off("mouse:over", S(c)), n.off("mouse:out", S(u)), n.off("mouse:move", S(a)), n.off("mouse:up", S(i)), n.isDrawingMode = !1;
217
+ };
218
+ } }), me = (t, e, n = 0) => {
219
+ const o = 10 ** n;
220
+ return Math.round(t * e * o) / o;
221
+ }, Be = (t, e) => {
222
+ t = t.includes("#") ? t.substring(1) : t;
223
+ const n = parseInt(t, 16), o = n >> 16 & 255, s = n >> 8 & 255, a = n & 255;
224
+ return `rgba(${o},${s},${a},${e})`;
225
+ }, ue = (t) => {
226
+ const e = t.substring(5);
227
+ return e.substring(0, e.length - 1).split(",").map((o) => +o);
228
+ }, yt = (t) => Math.round(t).toString(16).padStart(2, "0"), xn = (t) => {
229
+ let e = t.startsWith("#") ? t.substring(1) : t;
230
+ (e.length === 3 || e.length === 4) && (e = e.split("").map((u) => u + u).join(""));
231
+ const n = e.length === 8;
232
+ if (e.length !== 6 && !n)
233
+ return null;
234
+ const o = parseInt(e.substring(0, 6), 16), s = o >> 16 & 255, a = o >> 8 & 255, i = o & 255, c = n ? parseInt(e.substring(6), 16) / 255 : 1;
235
+ return { r: s, g: a, b: i, a: c };
236
+ }, qt = (t) => {
237
+ const e = { hex: "000000", alpha: "100%" };
238
+ if (!t)
239
+ return e;
240
+ const n = t.trim();
241
+ if (n.startsWith("rgba(")) {
242
+ const [s, a, i, c] = ue(n);
243
+ return {
244
+ hex: `${yt(s)}${yt(a)}${yt(i)}`,
245
+ alpha: `${me(c, 100, 0)}%`
246
+ };
247
+ }
248
+ if (n.startsWith("rgb(")) {
249
+ const s = n.substring(4, n.length - 1).split(",").map((u) => +u), [a = 0, i = 0, c = 0] = s;
250
+ return {
251
+ hex: `${yt(a)}${yt(i)}${yt(c)}`,
252
+ alpha: "100%"
253
+ };
254
+ }
255
+ const o = xn(n);
256
+ if (o) {
257
+ const { r: s, g: a, b: i, a: c } = o;
258
+ return {
259
+ hex: `${yt(s)}${yt(a)}${yt(i)}`,
260
+ alpha: `${me(c, 100, 0)}%`
261
+ };
262
+ }
263
+ return e;
264
+ }, mo = (t) => {
265
+ const [e, n, o, s] = ue(t), a = Math.round(e).toString(16).padStart(2, "0"), i = Math.round(n).toString(16).padStart(2, "0"), c = Math.round(o).toString(16).padStart(2, "0"), u = Math.round(s * 255).toString(16).padStart(2, "0");
266
+ return `#${a}${i}${c}${u}`;
267
+ }, Ae = (t) => new Promise((e) => {
268
+ const n = new Image();
269
+ n.src = t, n.setAttribute("crossOrigin", ""), n.onload = () => e(n);
270
+ }), go = (t, e) => {
271
+ for (let n = 0; n < t.data.length; n += 4) {
272
+ const o = t.data[n], s = t.data[n + 1], a = t.data[n + 2];
273
+ o === 0 && s === 0 && a === 0 ? t.data[n + 3] = 0 : e && (t.data[n + 3] = Math.round(255 * e * 100) / 100);
274
+ }
275
+ return t;
276
+ }, _e = (t) => {
277
+ const e = (r) => {
278
+ const f = r.data;
279
+ let v = r.width, h = r.height, x = 0, l = 0;
280
+ for (let g = 0; g < r.height; g += 1)
281
+ for (let b = 0; b < r.width; b += 1) {
282
+ const N = (g * r.width + b) * 4;
283
+ f[N + 3] > 0 && (v = Math.min(v, b), h = Math.min(h, g), x = Math.max(x, b), l = Math.max(l, g));
284
+ }
285
+ return { minX: v, minY: h, maxX: x, maxY: l };
286
+ }, n = document.createElement("canvas"), o = n.getContext("2d");
287
+ if (!o)
288
+ return { canvas: n, minX: 0, minY: 0 };
289
+ const { minX: s, minY: a, maxX: i, maxY: c } = e(t), u = i - s + 1, m = c - a + 1, d = o.createImageData(u, m);
290
+ for (let r = 0; r < m; r += 1)
291
+ for (let f = 0; f < u; f += 1) {
292
+ const v = ((a + r) * t.width + s + f) * 4, h = (r * u + f) * 4;
293
+ d.data[h] = t.data[v], d.data[h + 1] = t.data[v + 1], d.data[h + 2] = t.data[v + 2], d.data[h + 3] = t.data[v + 3];
294
+ }
295
+ return n.width = u, n.height = m, o.putImageData(d, 0, 0), { canvas: n, minX: s, minY: a };
296
+ };
297
+ let Lt = null;
298
+ const vo = (t) => {
299
+ Lt = t;
300
+ }, De = () => ({ id: "magic-wand", init: async ({
301
+ src: e,
302
+ colorCode: n,
303
+ brush: o,
304
+ magicbrushConfig: s
305
+ }) => {
306
+ if (!Lt) {
307
+ console.warn(
308
+ "[@ez-planet/labeling-canvas] MagicBrush module not provided. Call setMagicBrushModule() first."
309
+ );
310
+ return;
311
+ }
312
+ const a = ct(), i = ke(), c = vt(), u = H(), m = () => {
313
+ a.contextContainer && a.renderAll();
314
+ };
315
+ a.defaultCursor = "crosshair", a.hoverCursor = "crosshair";
316
+ const { threshold: d, radius: r } = s;
317
+ let f = null, v = null;
318
+ const h = await Ae(e), { width: x, height: l } = h, g = document.createElement("canvas").getContext("2d");
319
+ if (!g)
320
+ return;
321
+ g.canvas.width = x, g.canvas.height = l, g.drawImage(h, 0, 0), f = g.getImageData(0, 0, x, l);
322
+ const b = ({ x: M, y: D }) => ({
323
+ x: Math.min(Math.max(Math.round(M), 0), x - 1),
324
+ y: Math.min(Math.max(Math.round(D), 0), l - 1)
325
+ }), N = async (M) => {
326
+ const D = M.getElement(), J = document.createElement("canvas").getContext("2d");
327
+ if (!D || !J)
328
+ return null;
329
+ const O = D.naturalWidth || D.width, k = D.naturalHeight || D.height;
330
+ J.canvas.width = O, J.canvas.height = k, J.drawImage(D, 0, 0, O, k);
331
+ const R = J.getImageData(0, 0, O, k).data, E = new Uint8Array(O * k);
332
+ let Y = O, Q = k, G = -1, $ = -1;
333
+ for (let B = 0; B < k; B += 1)
334
+ for (let X = 0; X < O; X += 1)
335
+ R[(B * O + X) * 4 + 3] && (E[B * O + X] = 1, Y = Math.min(Y, X), Q = Math.min(Q, B), G = Math.max(G, X), $ = Math.max($, B));
336
+ if (J.canvas.remove(), G < Y || $ < Q) return null;
337
+ const z = Lt.traceContours({
338
+ data: E,
339
+ width: O,
340
+ height: k,
341
+ bounds: { minX: Y, minY: Q, maxX: G, maxY: $ }
342
+ }), j = Lt.simplifyContours(z, 1, 6).filter(
343
+ ({ points: B }) => B.length
344
+ );
345
+ if (!j.length) return null;
346
+ const lt = M.scaleX ?? 1, Mt = M.scaleY ?? 1, It = M.left ?? 0, at = M.top ?? 0;
347
+ let K = 1 / 0, tt = 1 / 0;
348
+ const ut = j.map((B) => {
349
+ const X = B.points.map(({ x: dt, y: A }) => {
350
+ const U = dt * lt, bt = A * Mt;
351
+ return K = Math.min(K, U), tt = Math.min(tt, bt), new c(U, bt);
352
+ });
353
+ return { inner: B.inner, points: X };
354
+ });
355
+ if (!Number.isFinite(K) || !Number.isFinite(tt)) return null;
356
+ const rt = { x: K, y: tt }, ht = ut.map((B) => ({
357
+ inner: B.inner,
358
+ points: B.points.map(
359
+ ({ x: X, y: dt }) => new c(X - rt.x, dt - rt.y)
360
+ )
361
+ })).sort((B, X) => Number(B.inner) - Number(X.inner)), Ut = ht.findIndex(
362
+ ({ inner: B }) => !B
363
+ ), Ot = Ut >= 0 ? Ut : 0, pt = ht[Ot] ?? ht[0], Wt = (pt == null ? void 0 : pt.points.map(({ x: B, y: X }) => new c(B, X))) ?? [], Nt = [];
364
+ return ht.forEach(({ points: B }) => {
365
+ if (!B.length) return;
366
+ const [X, ...dt] = B;
367
+ Nt.push(`M ${X.x} ${X.y}`), dt.forEach(({ x: A, y: U }) => {
368
+ Nt.push(`L ${A} ${U}`);
369
+ }), Nt.push("Z");
370
+ }), new u.Path(Nt.join(" "), {
371
+ left: It + rt.x,
372
+ top: at + rt.y,
373
+ originX: "left",
374
+ originY: "top",
375
+ objectCaching: !1,
376
+ selectable: !1,
377
+ evented: !0,
378
+ fillRule: "evenodd",
379
+ pathOffset: new c(0, 0),
380
+ points: Wt,
381
+ pathContours: ht,
382
+ pathBaseOffset: rt,
383
+ pathEditableContourIndex: Ot,
384
+ info: M.info ?? Vt,
385
+ fill: M.fill,
386
+ hex: M.hex,
387
+ alpha: M.alpha,
388
+ index: M.index,
389
+ class: M.class,
390
+ unique: M.unique,
391
+ labeler: M.labeler,
392
+ combinded: M.combinded,
393
+ lockMovementX: M.lockMovementX,
394
+ lockMovementY: M.lockMovementY,
395
+ passStack: !0,
396
+ replaced: !0
397
+ });
398
+ }, w = () => {
399
+ if (!f || !v) return;
400
+ const M = {
401
+ data: f.data,
402
+ width: f.width,
403
+ height: f.height,
404
+ bytes: 4
405
+ }, { x: D, y: J } = v;
406
+ let O = Lt.floodFill(M, D, J, d);
407
+ O = Lt.gaussBlurOnlyBorder(O, r), I(O, n);
408
+ }, I = (M, D) => {
409
+ if (!f) return;
410
+ const O = ((at) => {
411
+ const K = at.substring(5), ut = K.substring(0, K.length - 1).split(",").map((rt) => +rt);
412
+ return ut[3] = Math.round(ut[3] * 255), ut;
413
+ })(D), k = document.createElement("canvas"), R = k.getContext("2d");
414
+ if (!R) return;
415
+ R.canvas.width = f.width, R.canvas.height = f.height;
416
+ const E = M.data, Y = M.bounds, Q = M.width, G = f.width, $ = f.height, z = R.createImageData(G, $), j = z.data;
417
+ for (let at = Y.minY; at <= Y.maxY; at++)
418
+ for (let K = Y.minX; K <= Y.maxX; K++) {
419
+ if (E[at * Q + K] === 0) continue;
420
+ const tt = (at * G + K) * 4;
421
+ j[tt] = O[0], j[tt + 1] = O[1], j[tt + 2] = O[2], j[tt + 3] = O[3];
422
+ }
423
+ k.remove();
424
+ const { canvas: lt, minX: Mt, minY: It } = _e(z);
425
+ C(lt, Mt, It);
426
+ }, C = async (M, D, J) => {
427
+ if (!v) return;
428
+ const O = D, k = J, R = M.toDataURL();
429
+ M.remove();
430
+ const E = await i.fromURL(R, {}, {
431
+ left: O,
432
+ top: k,
433
+ objectCaching: !1,
434
+ selectable: !1,
435
+ info: Vt,
436
+ fill: n,
437
+ lockMovementX: !0,
438
+ lockMovementY: !0
439
+ }), { hex: Y, alpha: Q } = qt(n);
440
+ E.set({
441
+ hex: Y,
442
+ alpha: Q,
443
+ evented: !1,
444
+ passStack: !0,
445
+ replaced: !0
446
+ }), a.add(E);
447
+ const G = await N(E);
448
+ if (G) {
449
+ a.remove(E), a.add(G);
450
+ const $ = Tt(a);
451
+ $.objects = $.objects.filter(
452
+ ({ info: z }) => !nn.includes(z ?? "")
453
+ ), $.objects.forEach((z) => z.evented = !1);
454
+ }
455
+ }, P = function(M) {
456
+ const D = M.e;
457
+ (D == null ? void 0 : D.button) === 0 && (v = b(Ee(D)), w());
458
+ }, {
459
+ brushCursor: y,
460
+ handleOnMouseMove: L,
461
+ handleOnMouseUp: _
462
+ } = ce({ ...o, lineCap: "square" }), W = () => {
463
+ _();
464
+ }, V = function() {
465
+ a.add(y);
466
+ }, nt = function() {
467
+ a.remove(y);
468
+ };
469
+ return a.add(y), a.on("mouse:over", S(V)), a.on("mouse:out", S(nt)), a.on("mouse:down", S(P)), a.on("mouse:move", S(L)), a.on("mouse:up", S(W)), () => {
470
+ a.remove(y), m(), a.off("mouse:over", S(V)), a.off("mouse:out", S(nt)), a.off("mouse:down", S(P)), a.off("mouse:move", S(L)), a.off("mouse:up", S(W));
471
+ };
472
+ } }), Ue = () => ({ id: "pen", init: ({ colorCode: e }) => {
473
+ const n = ct(), o = vt(), s = Pe(), a = rn();
474
+ let i = [], c = [], u = !1;
475
+ const m = function(h, x) {
476
+ if (!c.length)
477
+ return !1;
478
+ const l = c[0];
479
+ if (l.x1 === void 0 || l.y1 === void 0)
480
+ return !1;
481
+ const g = n.getScenePoint(h), b = l.x1 ?? 0, N = l.y1 ?? 0, { x: w, y: I } = g;
482
+ return Math.abs(b - w) <= x && Math.abs(N - I) <= x;
483
+ }, d = function(h) {
484
+ h.preventDefault(), n.remove(...c), c = [];
485
+ }, r = function(h) {
486
+ const x = h.e;
487
+ if (x && m(x, 10)) {
488
+ u = !0;
489
+ return;
490
+ }
491
+ const l = n.getScenePoint(x), g = c.length ? c[c.length - 1] : null;
492
+ if (!g || g.x2) {
493
+ const b = new a(
494
+ [l.x, l.y, l.x, l.y],
495
+ {
496
+ stroke: "red",
497
+ strokeWidth: 2,
498
+ strokeDashArray: [5, 5],
499
+ selectable: !1,
500
+ evented: !1
501
+ }
502
+ );
503
+ b.replaced = !0, n.add(b), c.push(b);
504
+ } else
505
+ g.set({ x2: l.x, y2: l.y });
506
+ i.push(new o(l.x, l.y));
507
+ }, f = function(h) {
508
+ if (u)
509
+ return;
510
+ const x = c.length ? c[c.length - 1] : null;
511
+ if (x) {
512
+ const l = h.e;
513
+ if (!l)
514
+ return;
515
+ const g = n.getScenePoint(l);
516
+ x.set({ x2: g.x, y2: g.y }), n.renderAll();
517
+ }
518
+ }, v = function() {
519
+ if (u) {
520
+ n.remove(...c);
521
+ const h = new s(i, {
522
+ fill: e,
523
+ objectCaching: !1,
524
+ selectable: !1,
525
+ evented: !0,
526
+ info: Ve
527
+ });
528
+ n.add(h), n.renderAll(), i = [], c = [], u = !1;
529
+ }
530
+ };
531
+ return n.defaultCursor = "crosshair", document.addEventListener("contextmenu", d), n.on("mouse:down", S(r)), n.on("mouse:move", S(f)), n.on("mouse:up", S(v)), () => {
532
+ document.removeEventListener("contextmenu", d), n.defaultCursor = "default", n.off("mouse:down", S(r)), n.off("mouse:move", S(f)), n.off("mouse:up", S(v)), n.remove(...c), c = [];
533
+ };
534
+ } }), Cn = (t) => {
535
+ if (!t)
536
+ return !1;
537
+ const e = Pe(), n = H();
538
+ return !!(t instanceof e || t instanceof n.Path && [kt, Vt].includes(
539
+ t.info ?? ""
540
+ ) && Array.isArray(t.points) && Array.isArray(t.pathContours));
541
+ }, On = (t) => {
542
+ const e = H();
543
+ if (!(t instanceof e.Path) || !Array.isArray(t.pathContours) || !Array.isArray(t.points))
544
+ return;
545
+ const n = t, o = n.pathContours, s = n.pathEditableContourIndex ?? 0;
546
+ if (!o[s])
547
+ return;
548
+ const a = vt();
549
+ o[s].points = n.points.map(
550
+ ({ x: u, y: m }) => new a(u, m)
551
+ );
552
+ const i = [];
553
+ o.forEach(({ points: u }) => {
554
+ if (!u.length)
555
+ return;
556
+ const [m, ...d] = u;
557
+ i.push(`M ${m.x} ${m.y}`), d.forEach(({ x: r, y: f }) => {
558
+ i.push(`L ${r} ${f}`);
559
+ }), i.push("Z");
560
+ });
561
+ const c = new e.Path(i.join(" "));
562
+ n.set({ path: c.path }), n.pathContours = o, n.dirty = !0, n.setCoords();
563
+ }, We = (t) => {
564
+ const e = vt(), n = t.strokeWidth ?? 0, o = (t.strokeUniform ? 1 / (t.scaleX ?? 1) : 1) * n, s = (t.strokeUniform ? 1 / (t.scaleY ?? 1) : 1) * n;
565
+ return new e(
566
+ Math.max((t.width ?? 0) + o, 1),
567
+ Math.max((t.height ?? 0) + s, 1)
568
+ );
569
+ }, Sn = (t) => {
570
+ const e = t._setPositionDimensions;
571
+ typeof e == "function" ? e.call(t, {}) : t.setCoords();
572
+ }, wn = (t, e) => {
573
+ let n = !1;
574
+ for (let o = 0, s = e.length - 1; o < e.length; s = o++) {
575
+ const a = e[o].x, i = e[o].y, c = e[s].x, u = e[s].y;
576
+ i > t.y != u > t.y && t.x < (c - a) * (t.y - i) / (u - i + Number.EPSILON) + a && (n = !n);
577
+ }
578
+ return n;
579
+ }, Mn = (t) => {
580
+ if (t.length < 3)
581
+ return 0;
582
+ let e = 0;
583
+ for (let n = 0; n < t.length; n += 1) {
584
+ const { x: o, y: s } = t[n], { x: a, y: i } = t[(n + 1) % t.length];
585
+ e += o * i - a * s;
586
+ }
587
+ return Math.abs(e / 2);
588
+ }, In = function(t, e, n) {
589
+ var u;
590
+ const o = vt(), s = H().util, a = n.points[this.pointIndex ?? 0], i = a.x - n.pathOffset.x, c = a.y - n.pathOffset.y;
591
+ return s.transformPoint(
592
+ new o(i, c),
593
+ s.multiplyTransformMatrices(
594
+ ((u = n.canvas) == null ? void 0 : u.viewportTransform) ?? [1, 0, 0, 1, 0, 0],
595
+ n.calcTransformMatrix()
596
+ )
597
+ );
598
+ }, Ye = (t) => {
599
+ var a;
600
+ const e = vt(), n = H().util;
601
+ if (!t.points || !t.pathOffset)
602
+ return [];
603
+ const o = t.calcTransformMatrix(), s = (a = t.canvas) != null && a.viewportTransform ? n.multiplyTransformMatrices(t.canvas.viewportTransform, o) : o;
604
+ return t.points.map(
605
+ (i) => n.transformPoint(
606
+ new e(i.x - t.pathOffset.x, i.y - t.pathOffset.y),
607
+ s
608
+ )
609
+ );
610
+ }, Nn = function(t, e, n, o) {
611
+ var v;
612
+ const s = vt(), a = H(), i = e.target;
613
+ if (!i || !i.points || !i.pathOffset)
614
+ return !1;
615
+ const c = (v = i.controls) == null ? void 0 : v[i.__corner ?? ""];
616
+ if (!c)
617
+ return !1;
618
+ const u = c.pointIndex ?? 0, m = i.toLocalPoint(
619
+ new s(n, o),
620
+ "center",
621
+ "center"
622
+ ), d = We(i), r = i._getTransformedDimensions(0, 0), f = {
623
+ x: m.x * d.x / r.x + i.pathOffset.x,
624
+ y: m.y * d.y / r.y + i.pathOffset.y
625
+ };
626
+ return i.points[u] = f, i instanceof a.Path && On(i), !0;
627
+ }, Pn = function(t, e) {
628
+ return function(n, o, s, a) {
629
+ var N;
630
+ const i = vt(), c = o.target;
631
+ if (!c.points || !c.pathOffset)
632
+ return !1;
633
+ const u = c.controls, m = typeof c.__corner == "string" ? c.__corner : "", d = u == null ? void 0 : u[m], r = (d == null ? void 0 : d.pointIndex) ?? t, v = H().util.transformPoint(
634
+ new i(
635
+ c.points[t].x - c.pathOffset.x,
636
+ c.points[t].y - c.pathOffset.y
637
+ ),
638
+ c.calcTransformMatrix()
639
+ ), h = e(n, o, s, a), x = We(c), l = (c.points[t].x - c.pathOffset.x) / x.x, g = (c.points[t].y - c.pathOffset.y) / x.y;
640
+ Sn(c), c.setPositionByOrigin(
641
+ v,
642
+ l + 0.5,
643
+ g + 0.5
644
+ );
645
+ const b = c.editSnapshot;
646
+ if ((N = b == null ? void 0 : b.absolutePoints) != null && N.length) {
647
+ const I = Ye(c).map((C, P) => {
648
+ if (P === r)
649
+ return null;
650
+ const y = b.absolutePoints[P];
651
+ return y ? {
652
+ dx: y.x - C.x,
653
+ dy: y.y - C.y
654
+ } : null;
655
+ }).filter(
656
+ (C) => C !== null
657
+ );
658
+ if (I.length) {
659
+ const C = I.reduce((y, { dx: L }) => y + L, 0) / I.length, P = I.reduce((y, { dy: L }) => y + L, 0) / I.length;
660
+ (C !== 0 || P !== 0) && (c.set({
661
+ left: (c.left ?? 0) + C,
662
+ top: (c.top ?? 0) + P
663
+ }), c.setCoords());
664
+ }
665
+ }
666
+ return h;
667
+ };
668
+ }, kn = (t, e) => {
669
+ var m, d;
670
+ const n = H(), o = vt();
671
+ if (!(t instanceof n.Path) || !Array.isArray(t.pathContours) || !e)
672
+ return;
673
+ const s = t.toLocalPoint(
674
+ new o(e.x, e.y),
675
+ "left",
676
+ "top"
677
+ ), a = t.pathContours.map(
678
+ ({ points: r }, f) => ({
679
+ index: f,
680
+ inside: wn(s, r),
681
+ distance: Math.min(
682
+ ...r.map(
683
+ (v) => Math.hypot(v.x - s.x, v.y - s.y)
684
+ )
685
+ ),
686
+ area: Mn(r)
687
+ })
688
+ ), c = ((m = a.filter(({ inside: r }) => r).sort((r, f) => r.area - f.area)[0]) == null ? void 0 : m.index) ?? ((d = a.sort((r, f) => r.distance - f.distance)[0]) == null ? void 0 : d.index) ?? 0;
689
+ t.pathEditableContourIndex = c;
690
+ const u = t.pathContours[c];
691
+ u && (t.points = u.points.map(
692
+ ({ x: r, y: f }) => new o(r, f)
693
+ ));
694
+ }, Ln = (t) => {
695
+ var o;
696
+ const e = un(), n = (((o = t.points) == null ? void 0 : o.length) ?? 1) - 1;
697
+ t.controls = (t.points ?? []).reduce(
698
+ function(s, a, i) {
699
+ const c = () => (t.editSnapshot = {
700
+ dragIndex: i,
701
+ absolutePoints: Ye(t)
702
+ }, !1), u = () => (delete t.editSnapshot, !1);
703
+ return s["p" + i] = new e({
704
+ positionHandler: In,
705
+ actionHandler: Pn(
706
+ i > 0 ? i - 1 : n,
707
+ Nn
708
+ ),
709
+ actionName: "editPolygon",
710
+ pointIndex: i,
711
+ mouseDownHandler: c,
712
+ mouseUpHandler: u
713
+ }), s;
714
+ },
715
+ {}
716
+ );
717
+ }, Fe = (t, e) => {
718
+ const n = e.passStack;
719
+ e.passStack = !0, t.fire("object:modified", { target: e }), e.passStack = n;
720
+ }, En = (t, e, n) => {
721
+ if (!e || !Cn(e))
722
+ return ne(t), null;
723
+ const o = e;
724
+ return o.edit || (kn(o, n), o.edit = !0, o.cornerStyle = "circle", Ln(o), o.transparentCorners = !1, o.hasBorders = !1), ne(t, o), t.requestRenderAll(), Fe(t, o), o;
725
+ }, ne = (t, e) => {
726
+ const n = H().FabricObject;
727
+ ft(t).forEach((o) => {
728
+ if (!e || o !== e && e.edit) {
729
+ const s = o, a = s.edit;
730
+ s.edit = !1, s.cornerStyle = "rect", s.controls = n.prototype.controls, s.hasBorders = !0, s.transparentCorners = !0, delete s.editSnapshot, a && Fe(t, s);
731
+ }
732
+ }), t.requestRenderAll();
733
+ }, se = () => ({ id: "bounded-box", init: (e) => le(e, !0) }), Tn = () => ({ id: "filled-box", init: (e) => le(e, !1) }), po = () => ({ id: "seg-anything", init: ({ callback: e }) => le({ colorCode: "#13C0A4", callback: e }, !0, !0) }), Xe = () => ({ id: "selection", init: () => {
734
+ let e = !1, n = !1;
735
+ const o = gn(), s = ct();
736
+ s.defaultCursor = "default", s.hoverCursor = "default", s.moveCursor = "default", s.selection = !0;
737
+ const a = ft();
738
+ a.forEach((y) => {
739
+ y.selectable = !0, y.evented = !0;
740
+ });
741
+ let i = null;
742
+ const c = (y = !1) => {
743
+ i && (ne(s), i = null, y && s.discardActiveObject(), mt(s));
744
+ }, u = function(y) {
745
+ const L = y.scenePoint ?? y.absolutePointer, _ = y.target;
746
+ i && _ !== i && c(!_), L && (e = !0, o.x = L.x, o.y = L.y);
747
+ }, m = function(y) {
748
+ e && a.forEach((L) => {
749
+ L.info === At && (L.selectable = !1);
750
+ });
751
+ }, d = function(y) {
752
+ const L = y.scenePoint ?? y.absolutePointer;
753
+ L && (o.x = L.x - o.x, o.y = L.y - o.y), e = !1, a.forEach((_) => {
754
+ _.info === At && (_.selectable = !n);
755
+ });
756
+ }, r = function({ target: y }) {
757
+ }, f = function() {
758
+ }, v = function(y) {
759
+ if (y.key === "Escape" || y.code === "Escape") {
760
+ c(!0);
761
+ return;
762
+ }
763
+ n = y.shiftKey;
764
+ }, h = function() {
765
+ n = !1;
766
+ }, x = function(y) {
767
+ const L = y.scenePoint ?? y.absolutePointer, _ = En(
768
+ s,
769
+ y.target ?? null,
770
+ L
771
+ );
772
+ _ && (i = _, s.setActiveObject(_));
773
+ }, l = Pt(u), g = Pt(m), b = Pt(d), N = Pt(r), w = Pt(f), I = Pt(x), C = () => {
774
+ c();
775
+ };
776
+ s.on("mouse:down", S(l)), s.on("mouse:move", S(g)), s.on("mouse:up", S(b)), s.on("mouse:over", S(N)), s.on("mouse:out", S(w)), s.on("mouse:dblclick", S(I)), s.on("selection:cleared", C), document.addEventListener("keydown", v), document.addEventListener("keyup", h);
777
+ const P = ft(s).find(
778
+ ({ info: y }) => y === zt
779
+ );
780
+ return P && (s.remove(P), mt(s)), () => {
781
+ c(), s.defaultCursor = "default", s.hoverCursor = "default", s.moveCursor = "default", s.selection = !1, s.discardActiveObject(), mt(s), s.off("mouse:down", S(l)), s.off("mouse:move", S(g)), s.off("mouse:up", S(b)), s.off("mouse:over", S(N)), s.off("mouse:out", S(w)), s.off("mouse:dblclick", S(I)), s.off("selection:cleared", C), document.removeEventListener("keydown", v), document.removeEventListener("keyup", h), a.forEach((y) => {
782
+ y.selectable = !1, y.evented = !1;
783
+ });
784
+ };
785
+ } });
786
+ let oe = null, $t = null;
787
+ const bo = (t) => {
788
+ oe = t.SLIC, $t = t.MagicBrush;
789
+ }, He = () => ({ id: "superpixel", init: async ({
790
+ src: e,
791
+ colorCode: n,
792
+ superpixelConfig: o,
793
+ previousTool: s
794
+ }) => {
795
+ if (!oe || !$t) {
796
+ console.warn(
797
+ "[@ez-planet/labeling-canvas] SLIC/MagicBrush modules not provided. Call setSuperpixelModules() first."
798
+ );
799
+ return;
800
+ }
801
+ const a = ct(), i = ke(), c = vt(), u = H();
802
+ a.defaultCursor = "crosshair", a.hoverCursor = "crosshair";
803
+ const m = !s || s.id !== "superpixel", d = await Ae(e), { width: r, height: f } = d, v = ft(a).filter(({ info: O }) => O === kt).pop(), h = (v == null ? void 0 : v.index) ?? 0, x = m ? h + 1 : h, l = document.createElement("canvas").getContext("2d");
804
+ if (!l) return;
805
+ l.canvas.width = r, l.canvas.height = f;
806
+ const g = document.createElement("canvas").getContext("2d");
807
+ if (!g) return;
808
+ g.canvas.width = r, g.canvas.height = f;
809
+ const b = document.createElement("canvas").getContext("2d");
810
+ if (!b) return;
811
+ b.canvas.width = r, b.canvas.height = f, l.drawImage(d, 0, 0);
812
+ const N = l.getImageData(0, 0, r, f), w = new oe(N, o), I = w.result;
813
+ w.createPixelIndex(I), g.putImageData(I, 0, 0);
814
+ const C = g.getImageData(0, 0, r, f);
815
+ w.computeEdgemap(C), l.clearRect(0, 0, r, f), l.putImageData(C, 0, 0);
816
+ const P = l.canvas.toDataURL();
817
+ l.canvas.remove();
818
+ let y = setTimeout(async () => {
819
+ y && clearTimeout(y), y = null;
820
+ const O = await i.fromURL(P, {}, {
821
+ left: 0,
822
+ top: 0,
823
+ objectCaching: !1,
824
+ selectable: !1,
825
+ info: te
826
+ });
827
+ a.add(O);
828
+ }, 1), L = !1, _ = null, W = null;
829
+ const V = ({ x: O, y: k }) => ({
830
+ x: Math.min(Math.max(Math.round(O), 0), r - 1),
831
+ y: Math.min(Math.max(Math.round(k), 0), f - 1)
832
+ }), nt = (O) => {
833
+ const k = O.getElement(), R = document.createElement("canvas").getContext("2d");
834
+ if (!k || !R) return null;
835
+ const E = k.naturalWidth || k.width, Y = k.naturalHeight || k.height;
836
+ R.canvas.width = E, R.canvas.height = Y, R.drawImage(k, 0, 0, E, Y);
837
+ const Q = R.getImageData(0, 0, E, Y).data, G = new Uint8Array(E * Y);
838
+ let $ = E, z = Y, j = -1, lt = -1;
839
+ for (let A = 0; A < Y; A += 1)
840
+ for (let U = 0; U < E; U += 1)
841
+ Q[(A * E + U) * 4 + 3] && (G[A * E + U] = 1, $ = Math.min($, U), z = Math.min(z, A), j = Math.max(j, U), lt = Math.max(lt, A));
842
+ if (R.canvas.remove(), j < $ || lt < z) return null;
843
+ const Mt = $t.traceContours({
844
+ data: G,
845
+ width: E,
846
+ height: Y,
847
+ bounds: { minX: $, minY: z, maxX: j, maxY: lt }
848
+ }), It = O.scaleX ?? 1, at = O.scaleY ?? 1, K = O.left ?? 0, tt = O.top ?? 0, ut = $t.simplifyContours(Mt, 1, 6).filter(
849
+ ({ points: A }) => A.length
850
+ );
851
+ if (!ut.length) return null;
852
+ let rt = 1 / 0, ht = 1 / 0;
853
+ const Ut = ut.map((A) => {
854
+ const U = A.points.map(({ x: bt, y: Kt }) => {
855
+ const Yt = bt * It, de = Kt * at;
856
+ return rt = Math.min(rt, Yt), ht = Math.min(ht, de), { x: Yt, y: de };
857
+ });
858
+ return { inner: A.inner, points: U };
859
+ });
860
+ if (!Number.isFinite(rt) || !Number.isFinite(ht)) return null;
861
+ const Ot = { x: rt, y: ht }, pt = Ut.map((A) => ({
862
+ inner: A.inner,
863
+ points: A.points.map(
864
+ ({ x: U, y: bt }) => new c(U - Ot.x, bt - Ot.y)
865
+ )
866
+ })).sort((A, U) => Number(A.inner) - Number(U.inner)), Wt = pt.findIndex(({ inner: A }) => !A), Nt = Wt >= 0 ? Wt : 0, B = pt[Nt] ?? pt[0], X = (B == null ? void 0 : B.points.map(({ x: A, y: U }) => new c(A, U))) ?? [], dt = [];
867
+ return pt.forEach(({ points: A }) => {
868
+ if (!A.length) return;
869
+ const [U, ...bt] = A;
870
+ dt.push(`M ${U.x} ${U.y}`), bt.forEach(({ x: Kt, y: Yt }) => dt.push(`L ${Kt} ${Yt}`)), dt.push("Z");
871
+ }), new u.Path(dt.join(" "), {
872
+ left: K + Ot.x,
873
+ top: tt + Ot.y,
874
+ originX: "left",
875
+ originY: "top",
876
+ objectCaching: !1,
877
+ selectable: !1,
878
+ evented: !0,
879
+ fillRule: "evenodd",
880
+ pathOffset: new c(0, 0),
881
+ points: X,
882
+ pathContours: pt,
883
+ pathBaseOffset: Ot,
884
+ pathEditableContourIndex: Nt,
885
+ info: O.info ?? kt,
886
+ fill: O.fill,
887
+ hex: O.hex,
888
+ alpha: O.alpha,
889
+ opacity: O.opacity ?? 1,
890
+ index: O.index,
891
+ class: O.class,
892
+ unique: O.unique,
893
+ labeler: O.labeler,
894
+ combinded: O.combinded,
895
+ lockMovementX: O.lockMovementX,
896
+ lockMovementY: O.lockMovementY
897
+ });
898
+ }, M = (O) => {
899
+ const k = O.e;
900
+ if (L && (k == null ? void 0 : k.button) === 0) {
901
+ const R = V(Ee(k));
902
+ if (!R.x && !R.y) return;
903
+ const E = w.getClickOffset(R, r), Y = I.data, Q = b.getImageData(0, 0, r, f), G = w.getEncodedLabel(Y, E);
904
+ if (_ === G) return;
905
+ _ = G;
906
+ const $ = w.getPixelIndex()[G], z = ue(n), j = Math.max(0, Math.min(1, z[3] ?? 1)), lt = [
907
+ z[0],
908
+ z[1],
909
+ z[2],
910
+ Math.round(j * 255)
911
+ ];
912
+ w.highlightPixels($, lt, Q, C), w.fillPixels($, lt, Q), b.clearRect(0, 0, r, f), b.putImageData(Q, 0, 0);
913
+ const { canvas: Mt, minX: It, minY: at } = _e(Q), { hex: K, alpha: tt } = qt(n), ut = new u.FabricImage(Mt, {
914
+ left: It,
915
+ top: at,
916
+ objectCaching: !1,
917
+ selectable: !1,
918
+ info: kt,
919
+ evented: !1,
920
+ replaced: !0,
921
+ fill: n,
922
+ hex: K,
923
+ alpha: tt,
924
+ opacity: j,
925
+ index: x,
926
+ lockMovementX: !0,
927
+ lockMovementY: !0
928
+ });
929
+ W && a.remove(W), W = ut, a.add(ut);
930
+ }
931
+ }, D = (O) => {
932
+ L = !0, M(O);
933
+ }, J = () => {
934
+ L = !1, _ = null;
935
+ const O = ft(a).filter(
936
+ (R) => R.info === kt && R.index === x && R.type === "image"
937
+ ), k = O[O.length - 1];
938
+ k && (k.combinded = !0, k.evented = !0, a.remove(...O), a.add(k), W = k);
939
+ };
940
+ return a.on("mouse:down", S(D)), a.on("mouse:move", S(M)), a.on("mouse:up", S(J)), () => {
941
+ y && (clearTimeout(y), y = null);
942
+ try {
943
+ const O = ft(a), k = O.find(
944
+ ({ info: E }) => E === te
945
+ );
946
+ k && a.remove(k);
947
+ const R = W || (O.filter(
948
+ (E) => E.info === kt && E instanceof u.FabricImage
949
+ ).pop() ?? null);
950
+ if (R) {
951
+ const E = nt(R);
952
+ E && (a.remove(R), a.add(E), a.renderAll());
953
+ }
954
+ } finally {
955
+ a.off("mouse:down", S(D)), a.off("mouse:move", S(M)), a.off("mouse:up", S(J)), W = null;
956
+ }
957
+ };
958
+ } }), Rn = /* @__PURE__ */ new Set([At, re]), Dt = (t) => typeof t == "number" && Number.isFinite(t), Gt = (t) => Dt(t) && t !== 0 ? Math.abs(t) : 1, Xt = (t, e = 0) => Dt(t) ? t : e, Zt = (t) => {
959
+ if (!t) return;
960
+ const e = t.trim();
961
+ if (!e) return;
962
+ if (e.startsWith("#")) {
963
+ if (e.length === 7 || e.length === 9)
964
+ return e;
965
+ const { hex: o } = qt(e);
966
+ return `#${o}`;
967
+ }
968
+ const { hex: n } = qt(e);
969
+ return `#${n}`;
970
+ }, Qt = (t, e) => {
971
+ if (e === "fill" && typeof t.fill == "string")
972
+ return Zt(t.fill);
973
+ if (e === "stroke" && typeof t.stroke == "string")
974
+ return Zt(t.stroke);
975
+ if (e === "hex" && typeof t.hex == "string" && t.hex.length)
976
+ return Zt(`#${t.hex}`);
977
+ }, Bn = (t) => {
978
+ const e = t.info ?? "";
979
+ return Rn.has(e) ? "box" : "segmentation";
980
+ }, An = (t, e, n) => {
981
+ const o = Xt(t.left), s = Xt(t.top), a = Xt(t.width), i = Xt(t.height), c = Gt(t.scaleX), u = Gt(t.scaleY), m = a * c, d = i * u;
982
+ return {
983
+ type: "box",
984
+ x: e > 0 ? o / e : o,
985
+ y: n > 0 ? s / n : s,
986
+ width: e > 0 ? Math.max(m, 0) / e : m,
987
+ height: n > 0 ? Math.max(d, 0) / n : d
988
+ };
989
+ }, _n = (t) => t.clone(ie).then((e) => e ?? t), Dn = async (t) => {
990
+ if (typeof document > "u") return null;
991
+ const e = t.getBoundingRect(), n = Math.max(
992
+ 1,
993
+ Math.round((e == null ? void 0 : e.width) ?? (t.width ?? 0) * Gt(t.scaleX))
994
+ ), o = Math.max(
995
+ 1,
996
+ Math.round((e == null ? void 0 : e.height) ?? (t.height ?? 0) * Gt(t.scaleY))
997
+ ), s = dn(), a = document.createElement("canvas");
998
+ a.width = n, a.height = o;
999
+ const i = new s(a, {
1000
+ width: n,
1001
+ height: o,
1002
+ renderOnAddRemove: !1
1003
+ }), c = await _n(t), u = (e == null ? void 0 : e.left) ?? 0, m = (e == null ? void 0 : e.top) ?? 0;
1004
+ c.set({
1005
+ left: (c.left ?? 0) - u,
1006
+ top: (c.top ?? 0) - m
1007
+ }), i.add(c), i.renderAll();
1008
+ const d = i.toDataURL({ format: "png", multiplier: 1 });
1009
+ return i.dispose(), a.remove(), d;
1010
+ }, Un = async (t) => {
1011
+ const e = await Dn(t);
1012
+ if (!e) return null;
1013
+ const [, n] = e.split(",");
1014
+ if (!n) return null;
1015
+ const o = JSON.stringify(t.toObject(ie));
1016
+ return {
1017
+ type: "segmentation",
1018
+ mask: n,
1019
+ vector: o
1020
+ };
1021
+ }, Wn = (t) => {
1022
+ const e = Qt(t, "fill") ?? Qt(t, "hex") ?? "#000000", n = Dt(t.opacity) ? t.opacity : 1, o = Qt(t, "stroke"), s = Dt(t.seq) ? t.seq : void 0;
1023
+ return { color: e, opacity: n, lineColor: o, zIndex: s };
1024
+ }, Yn = async (t, e, n) => {
1025
+ const o = t.unique ?? "";
1026
+ if (!o) return null;
1027
+ const s = Bn(t);
1028
+ let a = null;
1029
+ s === "box" ? a = An(t, e, n) : a = await Un(t);
1030
+ const i = Wn(t), c = {
1031
+ name: t.class ?? "",
1032
+ index: Dt(t.seq) ? t.seq : 0
1033
+ };
1034
+ return { id: o, type: s, label: c, style: i, geometry: a };
1035
+ }, $e = async (t, e, n) => {
1036
+ const o = [];
1037
+ for (const s of t) {
1038
+ const a = await Yn(s, e, n);
1039
+ a && o.push(a);
1040
+ }
1041
+ return o;
1042
+ }, ze = (t, e, n) => {
1043
+ const { id: o, type: s, label: a, style: i, geometry: c } = t, u = {
1044
+ unique: o,
1045
+ class: a.name,
1046
+ seq: a.index,
1047
+ hex: i.color.replace("#", ""),
1048
+ alpha: `${Math.round(i.opacity * 100)}%`,
1049
+ opacity: i.opacity,
1050
+ objectCaching: !1,
1051
+ selectable: !1,
1052
+ evented: !0
1053
+ };
1054
+ if (i.lineColor && (u.stroke = i.lineColor), s === "box" && (c == null ? void 0 : c.type) === "box") {
1055
+ const m = c;
1056
+ return {
1057
+ ...u,
1058
+ type: "rect",
1059
+ left: m.x * e,
1060
+ top: m.y * n,
1061
+ width: m.width * e,
1062
+ height: m.height * n,
1063
+ fill: i.lineColor ? "" : Be(i.color.replace("#", ""), i.opacity),
1064
+ stroke: i.lineColor ?? void 0,
1065
+ info: i.lineColor ? At : re
1066
+ };
1067
+ }
1068
+ if (s === "segmentation" && (c == null ? void 0 : c.type) === "segmentation") {
1069
+ const m = c;
1070
+ if (m.vector)
1071
+ try {
1072
+ return {
1073
+ ...u,
1074
+ ...JSON.parse(m.vector),
1075
+ unique: o
1076
+ };
1077
+ } catch {
1078
+ }
1079
+ return {
1080
+ ...u,
1081
+ type: "image",
1082
+ src: `data:image/png;base64,${m.mask}`
1083
+ };
1084
+ }
1085
+ return u;
1086
+ }, ge = (t) => {
1087
+ let e;
1088
+ const n = /* @__PURE__ */ new Set(), o = (m, d) => {
1089
+ const r = typeof m == "function" ? m(e) : m;
1090
+ if (!Object.is(r, e)) {
1091
+ const f = e;
1092
+ e = d ?? (typeof r != "object" || r === null) ? r : Object.assign({}, e, r), n.forEach((v) => v(e, f));
1093
+ }
1094
+ }, s = () => e, c = { setState: o, getState: s, getInitialState: () => u, subscribe: (m) => (n.add(m), () => n.delete(m)) }, u = e = t(o, s, c);
1095
+ return c;
1096
+ }, qe = (t) => t ? ge(t) : ge, Fn = (t) => t;
1097
+ function Xn(t, e = Fn) {
1098
+ const n = Ft.useSyncExternalStore(
1099
+ t.subscribe,
1100
+ Ft.useCallback(() => e(t.getState()), [t, e]),
1101
+ Ft.useCallback(() => e(t.getInitialState()), [t, e])
1102
+ );
1103
+ return Ft.useDebugValue(n), n;
1104
+ }
1105
+ const ve = (t) => {
1106
+ const e = qe(t), n = (o) => Xn(e, o);
1107
+ return Object.assign(n, e), n;
1108
+ }, wt = (t) => t ? ve(t) : ve, Ct = wt((t) => ({
1109
+ tool: null,
1110
+ setTool(e) {
1111
+ t({ tool: e });
1112
+ },
1113
+ overedUniques: [],
1114
+ setOveredUniques(e) {
1115
+ t({ overedUniques: e });
1116
+ },
1117
+ undoStack: [],
1118
+ redoStack: [],
1119
+ setUndoStack(e) {
1120
+ if (e.length === 1 && !JSON.parse(e[0]).objects.length)
1121
+ return t({ undoStack: [] });
1122
+ t({ undoStack: e });
1123
+ },
1124
+ setRedoStack(e) {
1125
+ if (e.length === 1 && !JSON.parse(e[0]).objects.length)
1126
+ return t({ redoStack: [] });
1127
+ t({ redoStack: e });
1128
+ }
1129
+ })), yo = () => Ct.getState(), pe = [
1130
+ "#C21460",
1131
+ "#8601AF",
1132
+ "#4424D6",
1133
+ "#0247FE",
1134
+ "#347C98",
1135
+ "#66B032",
1136
+ "#B2D732",
1137
+ "#FEFE33",
1138
+ "#FCCC1A",
1139
+ "#FB9902",
1140
+ "#FC600A",
1141
+ "#FE2712"
1142
+ ], be = wt((t) => ({
1143
+ colorCode: Be(pe[pe.length - 1], 1),
1144
+ setColorCode(e) {
1145
+ t({ colorCode: e });
1146
+ }
1147
+ })), ye = wt((t) => ({
1148
+ opacity: 1,
1149
+ setOpacity(e) {
1150
+ t({ opacity: e });
1151
+ }
1152
+ })), Hn = [
1153
+ { id: 1, lineCap: "square", lineWidth: 5 },
1154
+ { id: 3, lineCap: "square", lineWidth: 10 },
1155
+ { id: 5, lineCap: "square", lineWidth: 20 },
1156
+ { id: 2, lineCap: "round", lineWidth: 5 },
1157
+ { id: 4, lineCap: "round", lineWidth: 10 },
1158
+ { id: 6, lineCap: "round", lineWidth: 20 }
1159
+ ], xe = wt((t) => ({
1160
+ brush: Hn[0],
1161
+ setBrush(e) {
1162
+ t({ brush: e });
1163
+ }
1164
+ }));
1165
+ var Ce = (t, e, n) => (s, a) => ({
1166
+ pastStates: (n == null ? void 0 : n.pastStates) || [],
1167
+ futureStates: (n == null ? void 0 : n.futureStates) || [],
1168
+ undo: (i = 1) => {
1169
+ var c, u;
1170
+ if (a().pastStates.length) {
1171
+ const m = ((c = n == null ? void 0 : n.partialize) == null ? void 0 : c.call(n, e())) || e(), d = a().pastStates.splice(-i, i), r = d.shift();
1172
+ t(r), s({
1173
+ pastStates: a().pastStates,
1174
+ futureStates: a().futureStates.concat(
1175
+ ((u = n == null ? void 0 : n.diff) == null ? void 0 : u.call(n, m, r)) || m,
1176
+ d.reverse()
1177
+ )
1178
+ });
1179
+ }
1180
+ },
1181
+ redo: (i = 1) => {
1182
+ var c, u;
1183
+ if (a().futureStates.length) {
1184
+ const m = ((c = n == null ? void 0 : n.partialize) == null ? void 0 : c.call(n, e())) || e(), d = a().futureStates.splice(-i, i), r = d.shift();
1185
+ t(r), s({
1186
+ pastStates: a().pastStates.concat(
1187
+ ((u = n == null ? void 0 : n.diff) == null ? void 0 : u.call(n, m, r)) || m,
1188
+ d.reverse()
1189
+ ),
1190
+ futureStates: a().futureStates
1191
+ });
1192
+ }
1193
+ },
1194
+ clear: () => s({ pastStates: [], futureStates: [] }),
1195
+ isTracking: !0,
1196
+ pause: () => s({ isTracking: !1 }),
1197
+ resume: () => s({ isTracking: !0 }),
1198
+ setOnSave: (i) => s({ _onSave: i }),
1199
+ // Internal properties
1200
+ _onSave: n == null ? void 0 : n.onSave,
1201
+ _handleSet: (i, c, u, m) => {
1202
+ var d, r;
1203
+ n != null && n.limit && a().pastStates.length >= (n == null ? void 0 : n.limit) && a().pastStates.shift(), (r = (d = a())._onSave) == null || r.call(d, i, u), s({
1204
+ pastStates: a().pastStates.concat(m || i),
1205
+ futureStates: []
1206
+ });
1207
+ }
1208
+ }), $n = (t, e) => (o, s, a) => {
1209
+ var m, d;
1210
+ a.temporal = qe(
1211
+ ((m = e == null ? void 0 : e.wrapTemporal) == null ? void 0 : m.call(e, Ce(o, s, e))) || Ce(o, s, e)
1212
+ );
1213
+ const i = ((d = e == null ? void 0 : e.handleSet) == null ? void 0 : d.call(
1214
+ e,
1215
+ a.temporal.getState()._handleSet
1216
+ )) || a.temporal.getState()._handleSet, c = (r) => {
1217
+ var h, x, l;
1218
+ if (!a.temporal.getState().isTracking) return;
1219
+ const f = ((h = e == null ? void 0 : e.partialize) == null ? void 0 : h.call(e, s())) || s(), v = (x = e == null ? void 0 : e.diff) == null ? void 0 : x.call(e, r, f);
1220
+ // If the user has provided a diff function but nothing has been changed, deltaState will be null
1221
+ v === null || // If the user has provided an equality function, use it
1222
+ (l = e == null ? void 0 : e.equality) != null && l.call(e, r, f) || i(
1223
+ r,
1224
+ void 0,
1225
+ f,
1226
+ v
1227
+ );
1228
+ }, u = a.setState;
1229
+ return a.setState = (...r) => {
1230
+ var v;
1231
+ const f = ((v = e == null ? void 0 : e.partialize) == null ? void 0 : v.call(e, s())) || s();
1232
+ u(...r), c(f);
1233
+ }, t(
1234
+ // Modify the set function to call the userlandSet function
1235
+ (...r) => {
1236
+ var v;
1237
+ const f = ((v = e == null ? void 0 : e.partialize) == null ? void 0 : v.call(e, s())) || s();
1238
+ o(...r), c(f);
1239
+ },
1240
+ s,
1241
+ a
1242
+ );
1243
+ };
1244
+ const xo = () => wt()(
1245
+ $n(
1246
+ (t) => ({
1247
+ snapshot: null,
1248
+ setSnapshot: (e) => t({ snapshot: e }),
1249
+ reset: () => t({ snapshot: null })
1250
+ }),
1251
+ {
1252
+ limit: 100,
1253
+ partialize: (t) => ({ snapshot: t.snapshot })
1254
+ }
1255
+ )
1256
+ ), Oe = 0, Se = 1, Bt = {
1257
+ NORMAL: [Oe, Se],
1258
+ ONLY_ORIGIN: [Oe],
1259
+ ONLY_OVERLAY: [Se]
1260
+ }, jt = [
1261
+ Bt.NORMAL,
1262
+ Bt.ONLY_ORIGIN,
1263
+ Bt.ONLY_OVERLAY
1264
+ ], Co = wt((t, e) => ({
1265
+ mode: Bt.NORMAL,
1266
+ setMode: (n) => t({ mode: n }),
1267
+ cycleMode: () => {
1268
+ const n = e().mode, o = jt.findIndex(
1269
+ (a) => a.length === n.length && a.every((i, c) => i === n[c])
1270
+ ), s = o >= 0 ? jt[(o + 1) % jt.length] : Bt.NORMAL;
1271
+ t({ mode: s });
1272
+ }
1273
+ })), Jt = wt((t) => ({
1274
+ objects: [],
1275
+ setObjects: (e) => t({ objects: e })
1276
+ })), ae = wt((t) => ({
1277
+ level: 1,
1278
+ width: 0,
1279
+ height: 0,
1280
+ setZoom: ({ level: e, width: n, height: o }) => t({ level: e, width: n, height: o }),
1281
+ reset: () => t({ level: 1, width: 0, height: 0 })
1282
+ })), Ge = Ze(null);
1283
+ function zn() {
1284
+ const t = Qe(Ge);
1285
+ if (!t)
1286
+ throw new Error("useLabelingContext must be used within a LabelingProvider");
1287
+ return t;
1288
+ }
1289
+ function qn({
1290
+ image: t,
1291
+ annotations: e,
1292
+ onChange: n,
1293
+ records: o,
1294
+ activeRecordId: s,
1295
+ onRecordSelect: a,
1296
+ classes: i,
1297
+ onClassSelect: c,
1298
+ onSave: u,
1299
+ isSaving: m = !1,
1300
+ mode: d = "labeling",
1301
+ onModeChange: r,
1302
+ validationResults: f = [],
1303
+ indicator: v,
1304
+ extensions: h = [],
1305
+ tools: x = ["selection", "blankRect", "polygon", "brush", "eraser"],
1306
+ theme: l,
1307
+ layout: g = {},
1308
+ children: b
1309
+ }) {
1310
+ var nt;
1311
+ const [N, w] = st(((nt = i[0]) == null ? void 0 : nt.id) ?? null), [I, C] = st(null), [P, y] = st(
1312
+ g.navigation === "bottom" ? "vertical" : "horizontal"
1313
+ ), [L, _] = st(g.navigation !== "hidden"), W = it(
1314
+ () => ({
1315
+ image: t,
1316
+ annotations: e,
1317
+ onChange: n,
1318
+ records: o,
1319
+ activeRecordId: s,
1320
+ onRecordSelect: a,
1321
+ classes: i,
1322
+ onClassSelect: c,
1323
+ selectedClassId: N,
1324
+ setSelectedClassId: w,
1325
+ selectedAnnotationId: I,
1326
+ setSelectedAnnotationId: C,
1327
+ onSave: u,
1328
+ isSaving: m,
1329
+ mode: d,
1330
+ onModeChange: r,
1331
+ validationResults: f,
1332
+ indicator: v,
1333
+ extensions: h,
1334
+ tools: x,
1335
+ theme: l,
1336
+ layout: g,
1337
+ navDirection: P,
1338
+ setNavDirection: y,
1339
+ navVisible: L,
1340
+ setNavVisible: _
1341
+ }),
1342
+ [
1343
+ t,
1344
+ e,
1345
+ n,
1346
+ o,
1347
+ s,
1348
+ a,
1349
+ i,
1350
+ c,
1351
+ N,
1352
+ I,
1353
+ u,
1354
+ m,
1355
+ d,
1356
+ r,
1357
+ f,
1358
+ v,
1359
+ h,
1360
+ x,
1361
+ l,
1362
+ g,
1363
+ P,
1364
+ L
1365
+ ]
1366
+ ), V = it(() => {
1367
+ if (!l) return;
1368
+ const M = {};
1369
+ return l.primary && (M["--lc-primary"] = l.primary), l.background && (M["--lc-background"] = l.background), l.surface && (M["--lc-surface"] = l.surface), l.border && (M["--lc-border"] = l.border), l.text && (M["--lc-text"] = l.text), l.textSecondary && (M["--lc-text-secondary"] = l.textSecondary), l.hover && (M["--lc-hover"] = l.hover), l.fontFamily && (M["--lc-font-family"] = l.fontFamily), Object.keys(M).length > 0 ? M : void 0;
1370
+ }, [l]);
1371
+ return /* @__PURE__ */ p(Ge.Provider, { value: W, children: /* @__PURE__ */ p("div", { style: V, children: b }) });
1372
+ }
1373
+ const Gn = "lc-workspace-8csim", Jn = "lc-mainSection-uZv5Q", Kn = "lc-controls-VGubk", Zn = "lc-controlsLeft-2Cdhh", Qn = "lc-controlsRight-sbdSx", jn = "lc-canvasArea-zoUW1", Vn = "lc-canvasSection-aUKNP", ts = "lc-imagePanel-ghGQ6", es = "lc-sidePanel-3s3Nv", xt = {
1374
+ workspace: Gn,
1375
+ mainSection: Jn,
1376
+ controls: Kn,
1377
+ controlsLeft: Zn,
1378
+ controlsRight: Qn,
1379
+ canvasArea: jn,
1380
+ canvasSection: Vn,
1381
+ imagePanel: ts,
1382
+ sidePanel: es
1383
+ };
1384
+ function ns({
1385
+ image: t,
1386
+ annotations: e,
1387
+ onChange: n,
1388
+ readOnly: o = !1,
1389
+ width: s,
1390
+ height: a
1391
+ }) {
1392
+ const i = Et(null), c = Et(null), [u, m] = st(!1), [d, r] = st({ width: 0, height: 0 }), f = Et(e);
1393
+ f.current = e;
1394
+ const v = Et(n);
1395
+ v.current = n;
1396
+ const h = ae((g) => g.setZoom), x = Jt((g) => g.setObjects), l = typeof t == "string" ? t : t.url;
1397
+ return St(() => {
1398
+ if (typeof document > "u") return;
1399
+ let g = !1;
1400
+ return (async () => {
1401
+ if (await an(), g || !i.current) return;
1402
+ const N = await import("fabric"), w = new N.Canvas(i.current, {
1403
+ selection: !o,
1404
+ preserveObjectStacking: !0
1405
+ });
1406
+ fe(w), m(!0);
1407
+ const I = await N.FabricImage.fromURL(l, { crossOrigin: "anonymous" });
1408
+ if (g) return;
1409
+ const C = typeof t == "object" ? t.width : I.width ?? 0, P = typeof t == "object" ? t.height : I.height ?? 0;
1410
+ r({ width: C, height: P });
1411
+ const y = c.current, L = s ?? (y == null ? void 0 : y.clientWidth) ?? C, _ = a ?? (y == null ? void 0 : y.clientHeight) ?? P, W = Math.min(L / (C || 1), _ / (P || 1), 1), V = Math.round(C * W), nt = Math.round(P * W);
1412
+ w.setDimensions({ width: V, height: nt }), w.setZoom(W), I.set({ selectable: !1, evented: !1 }), w.backgroundImage = I, w.renderAll(), h({ level: W, width: V, height: nt });
1413
+ })(), () => {
1414
+ g = !0;
1415
+ const N = ot();
1416
+ N && (N.dispose(), fe(null));
1417
+ };
1418
+ }, [l]), St(() => {
1419
+ if (!u) return;
1420
+ const g = ot();
1421
+ if (!g) return;
1422
+ (async () => {
1423
+ const N = g.getObjects();
1424
+ for (const I of N)
1425
+ g.remove(I);
1426
+ const w = await import("fabric");
1427
+ for (const I of e) {
1428
+ const C = ze(I, d.width, d.height), P = C.type;
1429
+ let y = null;
1430
+ P === "rect" ? y = new w.Rect(C) : P === "image" && typeof C.src == "string" ? (y = await w.FabricImage.fromURL(C.src, { crossOrigin: "anonymous" }), y.set(C)) : P === "path" && C.path ? y = new w.Path(C.path, C) : P === "polygon" && C.points && (y = new w.Polygon(C.points, C)), y && (o && y.set({ selectable: !1, evented: !1 }), g.add(y));
1431
+ }
1432
+ g.renderAll(), x(g.getObjects());
1433
+ })();
1434
+ }, [e, u, d.width, d.height, o, x]), St(() => {
1435
+ if (!u) return;
1436
+ const g = ot();
1437
+ if (!g) return;
1438
+ const b = async () => {
1439
+ var C;
1440
+ const w = ft(), I = await $e(
1441
+ w,
1442
+ d.width,
1443
+ d.height
1444
+ );
1445
+ x(w), (C = v.current) == null || C.call(v, {
1446
+ annotations: I,
1447
+ action: {
1448
+ type: "batch",
1449
+ added: [],
1450
+ updated: I,
1451
+ deleted: []
1452
+ }
1453
+ });
1454
+ }, N = ["object:added", "object:removed", "object:modified"];
1455
+ for (const w of N)
1456
+ g.on(w, b);
1457
+ return () => {
1458
+ for (const w of N)
1459
+ g.off(w, b);
1460
+ };
1461
+ }, [u, d.width, d.height, x]), St(() => {
1462
+ if (u)
1463
+ return pn(() => {
1464
+ });
1465
+ }, [u]), /* @__PURE__ */ p("div", { ref: c, className: xt.canvasSection, children: /* @__PURE__ */ p("div", { className: xt.imagePanel, children: /* @__PURE__ */ p("canvas", { ref: i }) }) });
1466
+ }
1467
+ const ss = "lc-navigationWrapper-3oNp8", os = "lc-title-ozM0E", as = "lc-titleUtil-V4RV4", rs = "lc-directionButton-GOUn-", is = "lc-content-fBa8N", cs = "lc-recordList-kWbe2", ls = "lc-recordItem-qutOX", us = "lc-recordThumbnail-s2bPH", ds = "lc-recordTitle-BtPW7", fs = "lc-recordStatus--HJxg", hs = "lc-childrenList-i9Ow3", ms = "lc-searchInput-RI4GW", gs = "lc-empty-olthD", et = {
1468
+ navigationWrapper: ss,
1469
+ title: os,
1470
+ titleUtil: as,
1471
+ directionButton: rs,
1472
+ content: is,
1473
+ recordList: cs,
1474
+ recordItem: ls,
1475
+ recordThumbnail: us,
1476
+ recordTitle: ds,
1477
+ recordStatus: fs,
1478
+ childrenList: hs,
1479
+ searchInput: ms,
1480
+ empty: gs
1481
+ };
1482
+ function we({
1483
+ records: t,
1484
+ activeRecordId: e,
1485
+ onRecordSelect: n,
1486
+ direction: o = "horizontal",
1487
+ onDirectionChange: s,
1488
+ hidden: a = !1
1489
+ }) {
1490
+ const [i, c] = st(""), u = it(() => {
1491
+ if (!i.trim()) return t;
1492
+ const r = i.trim().toLowerCase();
1493
+ return t.filter(
1494
+ (f) => {
1495
+ var v;
1496
+ return f.title.toLowerCase().includes(r) || ((v = f.children) == null ? void 0 : v.some((h) => h.title.toLowerCase().includes(r)));
1497
+ }
1498
+ );
1499
+ }, [t, i]), m = F((r) => {
1500
+ c(r.target.value);
1501
+ }, []), d = o === "vertical" ? "bottom" : "left";
1502
+ return /* @__PURE__ */ T(
1503
+ "div",
1504
+ {
1505
+ className: et.navigationWrapper,
1506
+ "data-position": d,
1507
+ "data-hidden": a || void 0,
1508
+ children: [
1509
+ /* @__PURE__ */ T("div", { className: et.title, children: [
1510
+ /* @__PURE__ */ p("p", { children: "Navigation" }),
1511
+ s && /* @__PURE__ */ T("div", { className: et.titleUtil, children: [
1512
+ /* @__PURE__ */ p(
1513
+ "button",
1514
+ {
1515
+ className: et.directionButton,
1516
+ "data-active": o === "horizontal" || void 0,
1517
+ onClick: () => s("horizontal"),
1518
+ title: "Side panel",
1519
+ children: /* @__PURE__ */ p(vs, {})
1520
+ }
1521
+ ),
1522
+ /* @__PURE__ */ p(
1523
+ "button",
1524
+ {
1525
+ className: et.directionButton,
1526
+ "data-active": o === "vertical" || void 0,
1527
+ onClick: () => s("vertical"),
1528
+ title: "Bottom panel",
1529
+ children: /* @__PURE__ */ p(ps, {})
1530
+ }
1531
+ )
1532
+ ] })
1533
+ ] }),
1534
+ /* @__PURE__ */ T("div", { className: et.content, children: [
1535
+ /* @__PURE__ */ p(
1536
+ "input",
1537
+ {
1538
+ className: et.searchInput,
1539
+ type: "text",
1540
+ placeholder: "Search records...",
1541
+ value: i,
1542
+ onChange: m
1543
+ }
1544
+ ),
1545
+ u.length === 0 ? /* @__PURE__ */ p("div", { className: et.empty, children: "No records found" }) : /* @__PURE__ */ p("div", { className: et.recordList, children: u.map((r) => /* @__PURE__ */ p(
1546
+ Je,
1547
+ {
1548
+ record: r,
1549
+ activeRecordId: e,
1550
+ onRecordSelect: n
1551
+ },
1552
+ r.id
1553
+ )) })
1554
+ ] })
1555
+ ]
1556
+ }
1557
+ );
1558
+ }
1559
+ function Je({
1560
+ record: t,
1561
+ activeRecordId: e,
1562
+ onRecordSelect: n
1563
+ }) {
1564
+ const o = t.id === e, s = t.children && t.children.length > 0, [a, i] = st(o || !1), c = F(() => {
1565
+ s && i((u) => !u), n(t);
1566
+ }, [s, n, t]);
1567
+ return /* @__PURE__ */ T(je, { children: [
1568
+ /* @__PURE__ */ T(
1569
+ "div",
1570
+ {
1571
+ className: et.recordItem,
1572
+ "data-active": o || void 0,
1573
+ onClick: c,
1574
+ children: [
1575
+ t.thumbnail && /* @__PURE__ */ p(
1576
+ "img",
1577
+ {
1578
+ className: et.recordThumbnail,
1579
+ src: t.thumbnail,
1580
+ alt: t.title
1581
+ }
1582
+ ),
1583
+ /* @__PURE__ */ p("span", { className: et.recordTitle, children: t.title }),
1584
+ t.status && /* @__PURE__ */ p("span", { className: et.recordStatus, "data-status": t.status })
1585
+ ]
1586
+ }
1587
+ ),
1588
+ s && a && /* @__PURE__ */ p("div", { className: et.childrenList, children: t.children.map((u) => /* @__PURE__ */ p(
1589
+ Je,
1590
+ {
1591
+ record: u,
1592
+ activeRecordId: e,
1593
+ onRecordSelect: n
1594
+ },
1595
+ u.id
1596
+ )) })
1597
+ ] });
1598
+ }
1599
+ function vs() {
1600
+ return /* @__PURE__ */ T("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", children: [
1601
+ /* @__PURE__ */ p("rect", { x: "1", y: "1", width: "12", height: "12", rx: "1.5", stroke: "currentColor", strokeWidth: "1.2" }),
1602
+ /* @__PURE__ */ p("line", { x1: "5", y1: "1", x2: "5", y2: "13", stroke: "currentColor", strokeWidth: "1.2" })
1603
+ ] });
1604
+ }
1605
+ function ps() {
1606
+ return /* @__PURE__ */ T("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", children: [
1607
+ /* @__PURE__ */ p("rect", { x: "1", y: "1", width: "12", height: "12", rx: "1.5", stroke: "currentColor", strokeWidth: "1.2" }),
1608
+ /* @__PURE__ */ p("line", { x1: "1", y1: "9", x2: "13", y2: "9", stroke: "currentColor", strokeWidth: "1.2" })
1609
+ ] });
1610
+ }
1611
+ const bs = "lc-infoPanel-mqfKy", ys = "lc-section-sMcXk", xs = "lc-sectionTitle-XfGbz", Cs = "lc-sectionContent-xsoVh", Os = "lc-tabs-huI9o", Ss = "lc-tab-jbpRb", ws = "lc-classList-mtPXc", Ms = "lc-classButton-Cdd6v", Is = "lc-classColorDot-Ravod", Ns = "lc-className-yQWn-", Ps = "lc-classHotkey-deQqu", ks = "lc-labelList-iJvDs", Ls = "lc-labelItem-ws-sn", Es = "lc-indicator-6JWmk", Ts = "lc-indicatorProgress-5iZVD", q = {
1612
+ infoPanel: bs,
1613
+ section: ys,
1614
+ sectionTitle: xs,
1615
+ sectionContent: Cs,
1616
+ tabs: Os,
1617
+ tab: Ss,
1618
+ classList: ws,
1619
+ classButton: Ms,
1620
+ classColorDot: Is,
1621
+ className: Ns,
1622
+ classHotkey: Ps,
1623
+ labelList: ks,
1624
+ labelItem: Ls,
1625
+ indicator: Es,
1626
+ indicatorProgress: Ts
1627
+ };
1628
+ function Rs({
1629
+ classes: t,
1630
+ annotations: e,
1631
+ selectedAnnotationId: n,
1632
+ onClassSelect: o,
1633
+ onAnnotationSelect: s,
1634
+ onAnnotationDelete: a,
1635
+ disabled: i = !1
1636
+ }) {
1637
+ var v;
1638
+ const [c, u] = st("class"), [m, d] = st(((v = t[0]) == null ? void 0 : v.id) ?? "");
1639
+ St(() => {
1640
+ t.length > 0 && !t.find((h) => h.id === m) && d(t[0].id);
1641
+ }, [t, m]);
1642
+ const r = it(() => {
1643
+ const h = /* @__PURE__ */ new Map();
1644
+ for (const x of t) {
1645
+ const l = x.group ?? "", g = h.get(l) ?? [];
1646
+ g.push(x), h.set(l, g);
1647
+ }
1648
+ return h;
1649
+ }, [t]), f = F(
1650
+ (h) => {
1651
+ i || (d(h.id), o == null || o(h));
1652
+ },
1653
+ [i, o]
1654
+ );
1655
+ return St(() => {
1656
+ const h = (x) => {
1657
+ if (i) return;
1658
+ const l = x.target;
1659
+ if (l instanceof HTMLElement && (l.tagName === "INPUT" || l.tagName === "TEXTAREA" || l.tagName === "SELECT" || l.isContentEditable))
1660
+ return;
1661
+ const g = x.key, b = t.find((N) => N.hotkey === g);
1662
+ b && (x.preventDefault(), f(b));
1663
+ };
1664
+ return window.addEventListener("keydown", h), () => window.removeEventListener("keydown", h);
1665
+ }, [t, i, f]), /* @__PURE__ */ p("div", { className: q.infoPanel, children: /* @__PURE__ */ T("div", { className: q.section, children: [
1666
+ /* @__PURE__ */ p("div", { className: q.sectionTitle, children: /* @__PURE__ */ T("div", { className: q.tabs, children: [
1667
+ /* @__PURE__ */ p(
1668
+ "button",
1669
+ {
1670
+ className: q.tab,
1671
+ "data-active": c === "class" || void 0,
1672
+ onClick: () => u("class"),
1673
+ children: "Class"
1674
+ }
1675
+ ),
1676
+ /* @__PURE__ */ p(
1677
+ "button",
1678
+ {
1679
+ className: q.tab,
1680
+ "data-active": c === "label" || void 0,
1681
+ onClick: () => u("label"),
1682
+ children: "Label"
1683
+ }
1684
+ )
1685
+ ] }) }),
1686
+ c === "class" && /* @__PURE__ */ p("div", { className: q.sectionContent, children: /* @__PURE__ */ p("div", { className: q.classList, children: Array.from(r.entries()).map(([h, x]) => /* @__PURE__ */ T("div", { children: [
1687
+ h && /* @__PURE__ */ p("div", { style: { fontSize: "0.75rem", fontWeight: 600, color: "#64748b", padding: "0.25rem 0", marginTop: "0.25rem" }, children: h }),
1688
+ x.map((l) => /* @__PURE__ */ T(
1689
+ "button",
1690
+ {
1691
+ className: q.classButton,
1692
+ "data-active": m === l.id || void 0,
1693
+ disabled: i,
1694
+ onClick: () => f(l),
1695
+ children: [
1696
+ /* @__PURE__ */ p(
1697
+ "div",
1698
+ {
1699
+ className: q.classColorDot,
1700
+ style: { backgroundColor: l.color }
1701
+ }
1702
+ ),
1703
+ /* @__PURE__ */ p("span", { className: q.className, children: l.name }),
1704
+ l.hotkey && /* @__PURE__ */ p("span", { className: q.classHotkey, children: l.hotkey })
1705
+ ]
1706
+ },
1707
+ l.id
1708
+ ))
1709
+ ] }, h || "__default")) }) }),
1710
+ c === "label" && /* @__PURE__ */ p("div", { className: q.sectionContent, children: e.length === 0 ? /* @__PURE__ */ p("div", { style: { fontSize: "0.8125rem", color: "#64748b", padding: "1rem 0", textAlign: "center" }, children: "No labels yet" }) : /* @__PURE__ */ p("div", { className: q.labelList, children: e.map((h) => /* @__PURE__ */ T(
1711
+ "div",
1712
+ {
1713
+ className: q.labelItem,
1714
+ "data-selected": n === h.id || void 0,
1715
+ onClick: () => s == null ? void 0 : s(h),
1716
+ children: [
1717
+ /* @__PURE__ */ p(
1718
+ "div",
1719
+ {
1720
+ className: q.classColorDot,
1721
+ style: { backgroundColor: h.style.color, opacity: h.style.opacity }
1722
+ }
1723
+ ),
1724
+ /* @__PURE__ */ p("p", { children: h.label.name || h.type }),
1725
+ a && /* @__PURE__ */ p(
1726
+ "button",
1727
+ {
1728
+ style: {
1729
+ marginLeft: "auto",
1730
+ padding: "0.125rem 0.25rem",
1731
+ border: "none",
1732
+ background: "transparent",
1733
+ cursor: "pointer",
1734
+ fontSize: "0.75rem",
1735
+ color: "#94a3b8"
1736
+ },
1737
+ onClick: (x) => {
1738
+ x.stopPropagation(), a(h.id);
1739
+ },
1740
+ children: "×"
1741
+ }
1742
+ )
1743
+ ]
1744
+ },
1745
+ h.id
1746
+ )) }) })
1747
+ ] }) });
1748
+ }
1749
+ const Bs = "lc-stickyWrapper-vurRe", As = "lc-toolbarWrapper-YBEn0", _s = "lc-divider-lifqe", Ds = "lc-toolButton-G2Yss", Us = "lc-toolButtonSlim-AHST8", Ws = "lc-buttonWithSub-ZjS34", Ys = "lc-subToolbar-c1-nf", gt = {
1750
+ stickyWrapper: Bs,
1751
+ toolbarWrapper: As,
1752
+ divider: _s,
1753
+ toolButton: Ds,
1754
+ toolButtonSlim: Us,
1755
+ buttonWithSub: Ws,
1756
+ subToolbar: Ys
1757
+ };
1758
+ function Fs({
1759
+ items: t,
1760
+ show: e = !0,
1761
+ verticalNav: n = !1,
1762
+ children: o
1763
+ }) {
1764
+ return e ? /* @__PURE__ */ p(
1765
+ "div",
1766
+ {
1767
+ className: gt.stickyWrapper,
1768
+ "data-vertical-nav": n || void 0,
1769
+ children: /* @__PURE__ */ T("div", { className: gt.toolbarWrapper, children: [
1770
+ t.map((s, a) => /* @__PURE__ */ p(Ke, { item: s }, a)),
1771
+ o
1772
+ ] })
1773
+ }
1774
+ ) : null;
1775
+ }
1776
+ function Ke({ item: t }) {
1777
+ var e;
1778
+ return t.variant === "divider" ? /* @__PURE__ */ p("div", { className: gt.divider }) : t.variant === "radio" ? /* @__PURE__ */ p(
1779
+ "button",
1780
+ {
1781
+ className: gt.toolButton,
1782
+ "data-active": t.checked || void 0,
1783
+ title: t.title,
1784
+ disabled: t.disabled,
1785
+ onClick: t.onClick,
1786
+ children: t.icon
1787
+ }
1788
+ ) : (e = t.subItems) != null && e.length ? /* @__PURE__ */ p(Xs, { item: t }) : /* @__PURE__ */ p(
1789
+ "button",
1790
+ {
1791
+ className: `${gt.toolButton} ${t.slim ? gt.toolButtonSlim : ""}`,
1792
+ "data-active": t.active || void 0,
1793
+ title: t.tooltip ?? t.title,
1794
+ disabled: t.disabled,
1795
+ onClick: t.onClick,
1796
+ children: t.icon
1797
+ }
1798
+ );
1799
+ }
1800
+ function Xs({ item: t }) {
1801
+ const [e, n] = st(!1), o = Et(null), s = F((a) => {
1802
+ o.current && !o.current.contains(a.target) && n(!1);
1803
+ }, []);
1804
+ return St(() => {
1805
+ if (e)
1806
+ return window.addEventListener("mousedown", s), () => window.removeEventListener("mousedown", s);
1807
+ }, [e, s]), /* @__PURE__ */ T("div", { className: gt.buttonWithSub, ref: o, children: [
1808
+ /* @__PURE__ */ p(
1809
+ "button",
1810
+ {
1811
+ className: `${gt.toolButton} ${t.slim ? gt.toolButtonSlim : ""}`,
1812
+ "data-active": t.active || void 0,
1813
+ title: t.tooltip ?? t.title,
1814
+ disabled: t.disabled,
1815
+ onClick: () => {
1816
+ var a;
1817
+ (a = t.onClick) == null || a.call(t), n((i) => !i);
1818
+ },
1819
+ children: t.icon
1820
+ }
1821
+ ),
1822
+ e && t.subItems && /* @__PURE__ */ p("div", { className: gt.subToolbar, children: t.subItems.map((a, i) => /* @__PURE__ */ p(Ke, { item: a }, i)) })
1823
+ ] });
1824
+ }
1825
+ const Hs = {
1826
+ selection: Xe,
1827
+ brush: Te,
1828
+ blankRect: se,
1829
+ filledRect: se,
1830
+ polygon: Ue,
1831
+ eraser: Re,
1832
+ magicbrush: De,
1833
+ superpixel: He
1834
+ }, Me = {
1835
+ selection: "Selection",
1836
+ brush: "Brush",
1837
+ blankRect: "Bounding Box",
1838
+ filledRect: "Filled Box",
1839
+ polygon: "Pen",
1840
+ eraser: "Eraser",
1841
+ magicbrush: "Magic Brush",
1842
+ superpixel: "Superpixel"
1843
+ }, Ie = [
1844
+ "selection",
1845
+ "blankRect",
1846
+ "polygon",
1847
+ "brush",
1848
+ "eraser"
1849
+ ];
1850
+ function $s({
1851
+ tools: t = Ie,
1852
+ sections: e,
1853
+ onSave: n,
1854
+ isSaving: o,
1855
+ onPrev: s,
1856
+ onNext: a,
1857
+ hasPrev: i,
1858
+ hasNext: c,
1859
+ children: u
1860
+ }) {
1861
+ const m = Ct((b) => b.tool), d = Ct((b) => b.setTool), r = F(
1862
+ (b) => {
1863
+ const N = Hs[b];
1864
+ N && d(N());
1865
+ },
1866
+ [d]
1867
+ ), f = [], v = t.length > 0 ? t : Ie;
1868
+ for (const b of v) {
1869
+ if (b === "selection") {
1870
+ f.push({
1871
+ variant: "radio",
1872
+ id: "selection",
1873
+ name: "tool",
1874
+ title: Me.selection,
1875
+ checked: (m == null ? void 0 : m.id) === "selection",
1876
+ onClick: () => r("selection")
1877
+ }), f.push({ variant: "divider" });
1878
+ continue;
1879
+ }
1880
+ f.push({
1881
+ variant: "radio",
1882
+ id: b,
1883
+ name: "tool",
1884
+ title: Me[b],
1885
+ checked: (m == null ? void 0 : m.id) === b || b === "blankRect" && (m == null ? void 0 : m.id) === "bounded-box" || b === "filledRect" && (m == null ? void 0 : m.id) === "filled-box",
1886
+ onClick: () => r(b)
1887
+ });
1888
+ }
1889
+ const h = f.findIndex(
1890
+ (b) => b.variant === "radio" && b.id === "eraser"
1891
+ );
1892
+ h > 0 && f.splice(h, 0, { variant: "divider" });
1893
+ const x = [];
1894
+ (s || a) && (x.push({ variant: "divider" }), s && x.push({
1895
+ variant: "button",
1896
+ title: "Previous",
1897
+ disabled: !i,
1898
+ onClick: s
1899
+ }), a && x.push({
1900
+ variant: "button",
1901
+ title: "Next",
1902
+ disabled: !c,
1903
+ onClick: a
1904
+ }));
1905
+ const l = [];
1906
+ n && (l.push({ variant: "divider" }), l.push({
1907
+ variant: "button",
1908
+ title: "Save",
1909
+ disabled: o,
1910
+ onClick: n
1911
+ }));
1912
+ const g = [
1913
+ ...f,
1914
+ ...x,
1915
+ ...l
1916
+ ];
1917
+ return /* @__PURE__ */ p(Fs, { items: g, children: u });
1918
+ }
1919
+ function zs({ indicator: t }) {
1920
+ return t ? /* @__PURE__ */ T("div", { className: q.indicator, children: [
1921
+ /* @__PURE__ */ p("span", { children: t.title }),
1922
+ t.subtitle && /* @__PURE__ */ T("span", { children: [
1923
+ ": ",
1924
+ t.subtitle
1925
+ ] }),
1926
+ t.detail && /* @__PURE__ */ T("span", { children: [
1927
+ " ",
1928
+ t.detail
1929
+ ] }),
1930
+ t.progress && /* @__PURE__ */ T("span", { className: q.indicatorProgress, children: [
1931
+ "(",
1932
+ t.progress.current,
1933
+ "/",
1934
+ t.progress.total,
1935
+ ")"
1936
+ ] })
1937
+ ] }) : null;
1938
+ }
1939
+ function Oo(t) {
1940
+ return /* @__PURE__ */ p(
1941
+ qn,
1942
+ {
1943
+ image: t.image,
1944
+ annotations: t.annotations,
1945
+ onChange: t.onChange,
1946
+ records: t.records,
1947
+ activeRecordId: t.activeRecordId,
1948
+ onRecordSelect: t.onRecordSelect,
1949
+ classes: t.classes,
1950
+ onClassSelect: t.onClassSelect,
1951
+ onSave: t.onSave,
1952
+ isSaving: t.isSaving,
1953
+ mode: t.mode,
1954
+ onModeChange: t.onModeChange,
1955
+ validationResults: t.validationResults,
1956
+ indicator: t.indicator,
1957
+ extensions: t.extensions,
1958
+ tools: t.tools,
1959
+ theme: t.theme,
1960
+ layout: t.layout,
1961
+ children: /* @__PURE__ */ p(qs, {})
1962
+ }
1963
+ );
1964
+ }
1965
+ function qs() {
1966
+ const t = zn(), e = t.mode === "readonly", n = t.navVisible && t.layout.navigation !== "hidden", o = t.navDirection, s = n && o === "horizontal" ? "with-nav-left" : n && o === "vertical" ? "with-nav-bottom" : void 0;
1967
+ return /* @__PURE__ */ T("div", { className: xt.workspace, "data-layout": s, children: [
1968
+ n && o === "horizontal" && /* @__PURE__ */ p(
1969
+ we,
1970
+ {
1971
+ records: t.records,
1972
+ activeRecordId: t.activeRecordId,
1973
+ onRecordSelect: t.onRecordSelect,
1974
+ direction: t.navDirection,
1975
+ onDirectionChange: t.setNavDirection
1976
+ }
1977
+ ),
1978
+ /* @__PURE__ */ T("div", { className: xt.mainSection, children: [
1979
+ /* @__PURE__ */ T("div", { className: xt.controls, children: [
1980
+ /* @__PURE__ */ p("div", { className: xt.controlsLeft, children: /* @__PURE__ */ p(zs, { indicator: t.indicator }) }),
1981
+ /* @__PURE__ */ p("div", { className: xt.controlsRight })
1982
+ ] }),
1983
+ /* @__PURE__ */ T("div", { className: xt.canvasArea, children: [
1984
+ /* @__PURE__ */ p(
1985
+ ns,
1986
+ {
1987
+ image: t.image,
1988
+ annotations: t.annotations,
1989
+ onChange: t.onChange,
1990
+ readOnly: e
1991
+ }
1992
+ ),
1993
+ !e && /* @__PURE__ */ p(
1994
+ $s,
1995
+ {
1996
+ tools: t.tools,
1997
+ onSave: () => t.onSave({
1998
+ annotations: t.annotations,
1999
+ canvasJSON: {},
2000
+ image: typeof t.image == "string" ? { width: 0, height: 0 } : { width: t.image.width, height: t.image.height }
2001
+ }),
2002
+ isSaving: t.isSaving
2003
+ }
2004
+ )
2005
+ ] }),
2006
+ /* @__PURE__ */ p("div", { className: xt.sidePanel, children: /* @__PURE__ */ p(
2007
+ Rs,
2008
+ {
2009
+ classes: t.classes,
2010
+ annotations: t.annotations,
2011
+ selectedAnnotationId: t.selectedAnnotationId,
2012
+ onClassSelect: t.onClassSelect,
2013
+ onAnnotationSelect: (a) => t.setSelectedAnnotationId(a.id),
2014
+ disabled: e
2015
+ }
2016
+ ) })
2017
+ ] }),
2018
+ n && o === "vertical" && /* @__PURE__ */ p(
2019
+ we,
2020
+ {
2021
+ records: t.records,
2022
+ activeRecordId: t.activeRecordId,
2023
+ onRecordSelect: t.onRecordSelect,
2024
+ direction: t.navDirection,
2025
+ onDirectionChange: t.setNavDirection
2026
+ }
2027
+ )
2028
+ ] });
2029
+ }
2030
+ const Gs = "lc-issuePanel-Ji1Oq", Js = "lc-issuePanelTitle-MnKUa", Ks = "lc-issueCount-xtlWy", Zs = "lc-issueItem-CL2Qq", Qs = "lc-issueHeader-YSNcb", js = "lc-issueLabel-K-Klr", Vs = "lc-issueBadge-oMlCN", to = "lc-issueReason-Pof-O", eo = "lc-issueDate-PZH2G", no = "lc-validationActions-qtvXO", so = "lc-validateButton-mhzNq", oo = "lc-reasonInput-WGZ6m", ao = "lc-emptyState-4wJWu", Z = {
2031
+ issuePanel: Gs,
2032
+ issuePanelTitle: Js,
2033
+ issueCount: Ks,
2034
+ issueItem: Zs,
2035
+ issueHeader: Qs,
2036
+ issueLabel: js,
2037
+ issueBadge: Vs,
2038
+ issueReason: to,
2039
+ issueDate: eo,
2040
+ validationActions: no,
2041
+ validateButton: so,
2042
+ reasonInput: oo,
2043
+ emptyState: ao
2044
+ };
2045
+ function So({
2046
+ annotations: t,
2047
+ validationResults: e,
2048
+ selectedAnnotationId: n,
2049
+ onAnnotationSelect: o,
2050
+ onValidate: s,
2051
+ onValidationUpdate: a,
2052
+ onValidationDelete: i
2053
+ }) {
2054
+ const [c, u] = st(""), [m, d] = st(null), r = e.filter((l) => !l.result).length, f = F(async () => {
2055
+ n && await (s == null ? void 0 : s({
2056
+ annotationIds: [n],
2057
+ result: !0
2058
+ }));
2059
+ }, [n, s]), v = F(async () => {
2060
+ n && (await (s == null ? void 0 : s({
2061
+ annotationIds: [n],
2062
+ result: !1,
2063
+ reason: c || void 0
2064
+ })), u(""));
2065
+ }, [n, c, s]), h = F(
2066
+ async (l) => {
2067
+ await (i == null ? void 0 : i({ ids: [l] }));
2068
+ },
2069
+ [i]
2070
+ ), x = F(
2071
+ (l) => l.annotationId ? t.find((g) => g.id === l.annotationId) ?? null : null,
2072
+ [t]
2073
+ );
2074
+ return /* @__PURE__ */ T("div", { className: Z.issuePanel, children: [
2075
+ /* @__PURE__ */ T("div", { className: Z.issuePanelTitle, children: [
2076
+ /* @__PURE__ */ p("span", { children: "Validation" }),
2077
+ r > 0 && /* @__PURE__ */ T("span", { className: Z.issueCount, children: [
2078
+ r,
2079
+ " issues"
2080
+ ] })
2081
+ ] }),
2082
+ e.length === 0 ? /* @__PURE__ */ p("div", { className: Z.emptyState, children: /* @__PURE__ */ p("p", { children: "No validation results yet" }) }) : e.map((l) => {
2083
+ const g = x(l);
2084
+ return /* @__PURE__ */ T(
2085
+ "div",
2086
+ {
2087
+ className: Z.issueItem,
2088
+ "data-selected": m === l.id || void 0,
2089
+ "data-result": l.result ? "pass" : "fail",
2090
+ onClick: () => {
2091
+ d(l.id), g && (o == null || o(g));
2092
+ },
2093
+ children: [
2094
+ /* @__PURE__ */ T("div", { className: Z.issueHeader, children: [
2095
+ /* @__PURE__ */ p("span", { className: Z.issueLabel, children: (g == null ? void 0 : g.label.name) ?? `Annotation ${l.annotationId ?? l.id}` }),
2096
+ /* @__PURE__ */ p(
2097
+ "span",
2098
+ {
2099
+ className: Z.issueBadge,
2100
+ "data-result": l.result ? "pass" : "fail",
2101
+ children: l.result ? "Pass" : "Fail"
2102
+ }
2103
+ )
2104
+ ] }),
2105
+ l.reason && /* @__PURE__ */ p("p", { className: Z.issueReason, children: l.reason }),
2106
+ l.validatedAt && /* @__PURE__ */ p("span", { className: Z.issueDate, children: l.validatedAt }),
2107
+ i && /* @__PURE__ */ p(
2108
+ "button",
2109
+ {
2110
+ className: Z.validateButton,
2111
+ "data-variant": "secondary",
2112
+ style: { marginTop: "0.25rem", padding: "0.25rem 0.5rem", fontSize: "0.75rem" },
2113
+ onClick: (b) => {
2114
+ b.stopPropagation(), h(l.id);
2115
+ },
2116
+ children: "Delete"
2117
+ }
2118
+ )
2119
+ ]
2120
+ },
2121
+ l.id
2122
+ );
2123
+ }),
2124
+ s && /* @__PURE__ */ p("div", { className: Z.validationActions, children: /* @__PURE__ */ p(
2125
+ "textarea",
2126
+ {
2127
+ className: Z.reasonInput,
2128
+ placeholder: "Reason (optional)...",
2129
+ value: c,
2130
+ onChange: (l) => u(l.target.value)
2131
+ }
2132
+ ) }),
2133
+ s && /* @__PURE__ */ T("div", { className: Z.validationActions, children: [
2134
+ /* @__PURE__ */ p(
2135
+ "button",
2136
+ {
2137
+ className: Z.validateButton,
2138
+ "data-variant": "approve",
2139
+ disabled: !n,
2140
+ onClick: f,
2141
+ children: "Approve"
2142
+ }
2143
+ ),
2144
+ /* @__PURE__ */ p(
2145
+ "button",
2146
+ {
2147
+ className: Z.validateButton,
2148
+ "data-variant": "reject",
2149
+ disabled: !n,
2150
+ onClick: v,
2151
+ children: "Reject"
2152
+ }
2153
+ )
2154
+ ] })
2155
+ ] });
2156
+ }
2157
+ const ro = {
2158
+ selection: Xe,
2159
+ brush: Te,
2160
+ blankRect: se,
2161
+ filledRect: Tn,
2162
+ polygon: Ue,
2163
+ eraser: Re,
2164
+ magicbrush: De,
2165
+ superpixel: He
2166
+ };
2167
+ function wo() {
2168
+ const t = Ct((r) => r.tool), e = Ct((r) => r.setTool), n = be((r) => r.colorCode), o = be((r) => r.setColorCode), s = ye((r) => r.opacity), a = ye((r) => r.setOpacity), i = xe((r) => r.brush), c = xe((r) => r.setBrush), u = F(
2169
+ (r) => {
2170
+ const f = ro[r];
2171
+ f && e(f());
2172
+ },
2173
+ [e]
2174
+ ), m = F(() => {
2175
+ e(null);
2176
+ }, [e]), d = (t == null ? void 0 : t.id) ?? null;
2177
+ return it(
2178
+ () => ({
2179
+ activeToolId: d,
2180
+ currentTool: t,
2181
+ setTool: u,
2182
+ clearTool: m,
2183
+ colorCode: n,
2184
+ setColorCode: o,
2185
+ opacity: s,
2186
+ setOpacity: a,
2187
+ brush: i,
2188
+ setBrush: c
2189
+ }),
2190
+ [d, t, u, m, n, o, s, a, i, c]
2191
+ );
2192
+ }
2193
+ function Mo() {
2194
+ const t = Jt((d) => d.objects), e = Jt((d) => d.setObjects), n = ae((d) => d.level), o = ae((d) => d.setZoom), s = F(
2195
+ async (d, r) => {
2196
+ const f = ft();
2197
+ return $e(f, d, r);
2198
+ },
2199
+ []
2200
+ ), a = F(
2201
+ async (d, r, f) => {
2202
+ const v = ot();
2203
+ if (!v) return;
2204
+ const h = ze(d, r, f), x = await import("fabric");
2205
+ let l = null;
2206
+ const g = h.type;
2207
+ g === "rect" ? l = new x.Rect(h) : g === "polygon" && h.points ? l = new x.Polygon(h.points, h) : g === "path" && h.path ? l = new x.Path(h.path, h) : g === "image" && typeof h.src == "string" && (l = await x.FabricImage.fromURL(h.src, { crossOrigin: "anonymous" }), l.set(h)), l && (v.add(l), mt(v), e(v.getObjects()));
2208
+ },
2209
+ [e]
2210
+ ), i = F(
2211
+ (d) => {
2212
+ const r = ot();
2213
+ if (!r) return;
2214
+ const v = r.getObjects().find((h) => h.unique === d);
2215
+ v && (r.remove(v), mt(r), e(r.getObjects()));
2216
+ },
2217
+ [e]
2218
+ ), c = F(() => {
2219
+ const d = ot();
2220
+ if (!d) return;
2221
+ const r = d.getObjects();
2222
+ for (const f of r)
2223
+ d.remove(f);
2224
+ mt(d), e([]);
2225
+ }, [e]), u = F(
2226
+ async (d, r) => {
2227
+ const f = await s(d, r), v = Tt();
2228
+ return {
2229
+ annotations: f,
2230
+ canvasJSON: v,
2231
+ image: { width: d, height: r }
2232
+ };
2233
+ },
2234
+ [s]
2235
+ ), m = F(
2236
+ (d) => {
2237
+ const r = ot();
2238
+ r && (r.setZoom(d), mt(r), o({ level: d, width: r.getWidth(), height: r.getHeight() }));
2239
+ },
2240
+ [o]
2241
+ );
2242
+ return it(
2243
+ () => ({
2244
+ objects: t,
2245
+ zoom: n,
2246
+ getAnnotations: s,
2247
+ addAnnotation: a,
2248
+ removeAnnotation: i,
2249
+ clearCanvas: c,
2250
+ exportState: u,
2251
+ setZoomLevel: m
2252
+ }),
2253
+ [t, n, s, a, i, c, u, m]
2254
+ );
2255
+ }
2256
+ function Io() {
2257
+ const t = Ct((r) => r.undoStack), e = Ct((r) => r.redoStack), n = Ct((r) => r.setUndoStack), o = Ct((r) => r.setRedoStack), s = Jt((r) => r.setObjects), a = t.length > 0, i = e.length > 0, c = F(() => {
2258
+ const r = Tt(), f = JSON.stringify(r);
2259
+ n([...t, f]), o([]);
2260
+ }, [t, n, o]), u = F(async () => {
2261
+ if (!a) return;
2262
+ const r = ot();
2263
+ if (!r) return;
2264
+ const f = JSON.stringify(Tt());
2265
+ o([...e, f]);
2266
+ const v = [...t], h = v.pop();
2267
+ n(v), await r.loadFromJSON(h), mt(r), s(r.getObjects());
2268
+ }, [a, t, e, n, o, s]), m = F(async () => {
2269
+ if (!i) return;
2270
+ const r = ot();
2271
+ if (!r) return;
2272
+ const f = JSON.stringify(Tt());
2273
+ n([...t, f]);
2274
+ const v = [...e], h = v.pop();
2275
+ o(v), await r.loadFromJSON(h), mt(r), s(r.getObjects());
2276
+ }, [i, t, e, n, o, s]), d = F(() => {
2277
+ n([]), o([]);
2278
+ }, [n, o]);
2279
+ return it(
2280
+ () => ({
2281
+ canUndo: a,
2282
+ canRedo: i,
2283
+ undo: u,
2284
+ redo: m,
2285
+ pushSnapshot: c,
2286
+ clear: d
2287
+ }),
2288
+ [a, i, u, m, c, d]
2289
+ );
2290
+ }
2291
+ function No(t) {
2292
+ const {
2293
+ extensions: e,
2294
+ image: n,
2295
+ annotations: o,
2296
+ selectedIds: s,
2297
+ activeTool: a,
2298
+ addAnnotations: i,
2299
+ updateAnnotation: c,
2300
+ removeAnnotations: u,
2301
+ setTool: m
2302
+ } = t, d = it(
2303
+ () => e.filter((l) => l.slot === "tool"),
2304
+ [e]
2305
+ ), r = it(
2306
+ () => e.filter((l) => l.slot === "sidePanel"),
2307
+ [e]
2308
+ ), f = it(
2309
+ () => e.filter((l) => l.slot === "toolbar"),
2310
+ [e]
2311
+ ), v = it(
2312
+ () => ({
2313
+ image: n,
2314
+ annotations: o,
2315
+ selectedIds: s,
2316
+ activeTool: a,
2317
+ addAnnotations: i,
2318
+ updateAnnotation: c,
2319
+ removeAnnotations: u,
2320
+ setTool: m,
2321
+ canvas: {
2322
+ toJSON: () => Tt(),
2323
+ getImageDataURL: () => {
2324
+ const l = ot();
2325
+ return l ? l.toDataURL({ format: "png", multiplier: 1 }) : "";
2326
+ }
2327
+ }
2328
+ }),
2329
+ [n, o, s, a, i, c, u, m]
2330
+ ), h = it(
2331
+ () => d.find((l) => l.id === a),
2332
+ [d, a]
2333
+ ), x = Et(h == null ? void 0 : h.canvasHandlers);
2334
+ return x.current = h == null ? void 0 : h.canvasHandlers, St(() => {
2335
+ const l = ot();
2336
+ if (!l || !x.current) return;
2337
+ const g = (I) => {
2338
+ var P, y, L, _, W;
2339
+ const C = ((P = l.getScenePoint) == null ? void 0 : P.call(l, I)) ?? ((y = l.getPointer) == null ? void 0 : y.call(l, I)) ?? { x: 0, y: 0 };
2340
+ return {
2341
+ x: C.x,
2342
+ y: C.y,
2343
+ shiftKey: ((L = I.e) == null ? void 0 : L.shiftKey) ?? !1,
2344
+ ctrlKey: ((_ = I.e) == null ? void 0 : _.ctrlKey) ?? !1,
2345
+ altKey: ((W = I.e) == null ? void 0 : W.altKey) ?? !1
2346
+ };
2347
+ }, b = (I) => {
2348
+ var C, P;
2349
+ return (P = (C = x.current) == null ? void 0 : C.onMouseDown) == null ? void 0 : P.call(C, g(I));
2350
+ }, N = (I) => {
2351
+ var C, P;
2352
+ return (P = (C = x.current) == null ? void 0 : C.onMouseMove) == null ? void 0 : P.call(C, g(I));
2353
+ }, w = (I) => {
2354
+ var C, P;
2355
+ return (P = (C = x.current) == null ? void 0 : C.onMouseUp) == null ? void 0 : P.call(C, g(I));
2356
+ };
2357
+ return l.on("mouse:down", b), l.on("mouse:move", N), l.on("mouse:up", w), () => {
2358
+ l.off("mouse:down", b), l.off("mouse:move", N), l.off("mouse:up", w);
2359
+ };
2360
+ }, [h == null ? void 0 : h.id]), {
2361
+ context: v,
2362
+ toolExtensions: d,
2363
+ sidePanelExtensions: r,
2364
+ toolbarExtensions: f,
2365
+ activeToolExtension: h
2366
+ };
2367
+ }
2368
+ export {
2369
+ nn as EXCEPTION_TOOLS,
2370
+ ie as EXPORT_PROPS,
2371
+ Bt as LAYER_MODE,
2372
+ ns as LabelingCanvas,
2373
+ Fs as LabelingFloatingToolbar,
2374
+ zs as LabelingIndicator,
2375
+ Rs as LabelingInfoPanel,
2376
+ So as LabelingIssuePanel,
2377
+ we as LabelingNavigation,
2378
+ qn as LabelingProvider,
2379
+ $s as LabelingToolbar,
2380
+ Oo as LabelingWorkspace,
2381
+ At as TOOL_INFO_BOUNDED_BOX,
2382
+ lo as TOOL_INFO_BRUSH,
2383
+ uo as TOOL_INFO_COMBINED_LABELS,
2384
+ fo as TOOL_INFO_ERASER,
2385
+ re as TOOL_INFO_FILLED_BOX,
2386
+ Ve as TOOL_INFO_FILLED_POLYGON,
2387
+ Vt as TOOL_INFO_MAGIC_BRUSH,
2388
+ kt as TOOL_INFO_SUPERPIXEL,
2389
+ ze as annotationToFabricProps,
2390
+ Hn as basicBrushes,
2391
+ pe as basicColors,
2392
+ se as blankRectTool,
2393
+ Te as brushTool,
2394
+ $e as canvasToAnnotations,
2395
+ Ae as createImage,
2396
+ xo as createTemporalHistoryStore,
2397
+ _e as cropAlphaArea,
2398
+ bn as emitLabelEvent,
2399
+ ct as ensureCanvas,
2400
+ Re as eraserTool,
2401
+ Yn as fabricObjectToAnnotation,
2402
+ Tn as filledRectTool,
2403
+ ho as getActiveLabeledObjects,
2404
+ ot as getCanvasInstance,
2405
+ Tt as getCanvasJSON,
2406
+ ft as getLabeledObjects,
2407
+ yo as getToolSelectionStore,
2408
+ an as loadFabric,
2409
+ De as magicbrushTool,
2410
+ Ue as polygonTool,
2411
+ mt as renderAllSafe,
2412
+ po as segmentAnythingTool,
2413
+ Xe as selectionTool,
2414
+ fe as setCanvasInstance,
2415
+ vo as setMagicBrushModule,
2416
+ bo as setSuperpixelModules,
2417
+ pn as subscribeLabelEvents,
2418
+ He as superpixelTool,
2419
+ qt as toHex,
2420
+ mo as toRGBAHex,
2421
+ Be as toRgba,
2422
+ ue as toRgbaArray,
2423
+ go as transparentBlackPixel,
2424
+ xe as useBrushStore,
2425
+ Jt as useCanvasObjectsStore,
2426
+ No as useExtensions,
2427
+ Mo as useLabelingCanvas,
2428
+ zn as useLabelingContext,
2429
+ Io as useLabelingHistory,
2430
+ wo as useLabelingTools,
2431
+ Co as useLayerModeStore,
2432
+ ye as useOpacityStore,
2433
+ be as usePaletteStore,
2434
+ Ct as useToolSelectionStore,
2435
+ ae as useZoomStore
2436
+ };