react-img-cutout 1.0.1 → 1.2.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 CHANGED
@@ -1,286 +1,355 @@
1
- import kt, { useState as tt, useRef as B, useCallback as O, useMemo as D, useEffect as N, useContext as F, createContext as at } from "react";
2
- var Q = { exports: {} }, G = {};
3
- var ct;
1
+ import kt, { useState as L, useRef as B, useCallback as P, useMemo as F, useEffect as O, useContext as z, createContext as lt } from "react";
2
+ var nt = { exports: {} }, G = {};
3
+ var ut;
4
4
  function Et() {
5
- if (ct) return G;
6
- ct = 1;
7
- var t = /* @__PURE__ */ Symbol.for("react.transitional.element"), r = /* @__PURE__ */ Symbol.for("react.fragment");
8
- function o(n, a, l) {
9
- var i = null;
10
- if (l !== void 0 && (i = "" + l), a.key !== void 0 && (i = "" + a.key), "key" in a) {
5
+ if (ut) return G;
6
+ ut = 1;
7
+ var t = /* @__PURE__ */ Symbol.for("react.transitional.element"), e = /* @__PURE__ */ Symbol.for("react.fragment");
8
+ function n(r, i, l) {
9
+ var a = null;
10
+ if (l !== void 0 && (a = "" + l), i.key !== void 0 && (a = "" + i.key), "key" in i) {
11
11
  l = {};
12
- for (var s in a)
13
- s !== "key" && (l[s] = a[s]);
14
- } else l = a;
15
- return a = l.ref, {
12
+ for (var s in i)
13
+ s !== "key" && (l[s] = i[s]);
14
+ } else l = i;
15
+ return i = l.ref, {
16
16
  $$typeof: t,
17
- type: n,
18
- key: i,
19
- ref: a !== void 0 ? a : null,
17
+ type: r,
18
+ key: a,
19
+ ref: i !== void 0 ? i : null,
20
20
  props: l
21
21
  };
22
22
  }
23
- return G.Fragment = r, G.jsx = o, G.jsxs = o, G;
23
+ return G.Fragment = e, G.jsx = n, G.jsxs = n, G;
24
24
  }
25
- var X = {};
25
+ var J = {};
26
26
  var ft;
27
27
  function It() {
28
28
  return ft || (ft = 1, process.env.NODE_ENV !== "production" && (function() {
29
- function t(e) {
30
- if (e == null) return null;
31
- if (typeof e == "function")
32
- return e.$$typeof === y ? null : e.displayName || e.name || null;
33
- if (typeof e == "string") return e;
34
- switch (e) {
35
- case S:
29
+ function t(o) {
30
+ if (o == null) return null;
31
+ if (typeof o == "function")
32
+ return o.$$typeof === X ? null : o.displayName || o.name || null;
33
+ if (typeof o == "string") return o;
34
+ switch (o) {
35
+ case f:
36
36
  return "Fragment";
37
- case m:
37
+ case h:
38
38
  return "Profiler";
39
- case T:
39
+ case b:
40
40
  return "StrictMode";
41
- case M:
41
+ case $:
42
42
  return "Suspense";
43
- case V:
43
+ case N:
44
44
  return "SuspenseList";
45
- case k:
45
+ case q:
46
46
  return "Activity";
47
47
  }
48
- if (typeof e == "object")
49
- switch (typeof e.tag == "number" && console.error(
48
+ if (typeof o == "object")
49
+ switch (typeof o.tag == "number" && console.error(
50
50
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
51
- ), e.$$typeof) {
52
- case w:
51
+ ), o.$$typeof) {
52
+ case v:
53
53
  return "Portal";
54
- case P:
55
- return e.displayName || "Context";
56
- case j:
57
- return (e._context.displayName || "Context") + ".Consumer";
58
- case b:
59
- var c = e.render;
60
- return e = e.displayName, e || (e = c.displayName || c.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
61
- case z:
62
- return c = e.displayName || null, c !== null ? c : t(e.type) || "Memo";
54
+ case w:
55
+ return o.displayName || "Context";
63
56
  case E:
64
- c = e._payload, e = e._init;
57
+ return (o._context.displayName || "Context") + ".Consumer";
58
+ case x:
59
+ var y = o.render;
60
+ return o = o.displayName, o || (o = y.displayName || y.name || "", o = o !== "" ? "ForwardRef(" + o + ")" : "ForwardRef"), o;
61
+ case H:
62
+ return y = o.displayName || null, y !== null ? y : t(o.type) || "Memo";
63
+ case V:
64
+ y = o._payload, o = o._init;
65
65
  try {
66
- return t(e(c));
66
+ return t(o(y));
67
67
  } catch {
68
68
  }
69
69
  }
70
70
  return null;
71
71
  }
72
- function r(e) {
73
- return "" + e;
72
+ function e(o) {
73
+ return "" + o;
74
74
  }
75
- function o(e) {
75
+ function n(o) {
76
76
  try {
77
- r(e);
78
- var c = !1;
77
+ e(o);
78
+ var y = !1;
79
79
  } catch {
80
- c = !0;
80
+ y = !0;
81
81
  }
82
- if (c) {
83
- c = console;
84
- var x = c.error, I = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
85
- return x.call(
86
- c,
82
+ if (y) {
83
+ y = console;
84
+ var A = y.error, S = typeof Symbol == "function" && Symbol.toStringTag && o[Symbol.toStringTag] || o.constructor.name || "Object";
85
+ return A.call(
86
+ y,
87
87
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
88
- I
89
- ), r(e);
88
+ S
89
+ ), e(o);
90
90
  }
91
91
  }
92
- function n(e) {
93
- if (e === S) return "<>";
94
- if (typeof e == "object" && e !== null && e.$$typeof === E)
92
+ function r(o) {
93
+ if (o === f) return "<>";
94
+ if (typeof o == "object" && o !== null && o.$$typeof === V)
95
95
  return "<...>";
96
96
  try {
97
- var c = t(e);
98
- return c ? "<" + c + ">" : "<...>";
97
+ var y = t(o);
98
+ return y ? "<" + y + ">" : "<...>";
99
99
  } catch {
100
100
  return "<...>";
101
101
  }
102
102
  }
103
- function a() {
104
- var e = v.A;
105
- return e === null ? null : e.getOwner();
103
+ function i() {
104
+ var o = j.A;
105
+ return o === null ? null : o.getOwner();
106
106
  }
107
107
  function l() {
108
108
  return Error("react-stack-top-frame");
109
109
  }
110
- function i(e) {
111
- if ($.call(e, "key")) {
112
- var c = Object.getOwnPropertyDescriptor(e, "key").get;
113
- if (c && c.isReactWarning) return !1;
110
+ function a(o) {
111
+ if (R.call(o, "key")) {
112
+ var y = Object.getOwnPropertyDescriptor(o, "key").get;
113
+ if (y && y.isReactWarning) return !1;
114
114
  }
115
- return e.key !== void 0;
115
+ return o.key !== void 0;
116
116
  }
117
- function s(e, c) {
118
- function x() {
119
- W || (W = !0, console.error(
117
+ function s(o, y) {
118
+ function A() {
119
+ M || (M = !0, console.error(
120
120
  "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
121
- c
121
+ y
122
122
  ));
123
123
  }
124
- x.isReactWarning = !0, Object.defineProperty(e, "key", {
125
- get: x,
124
+ A.isReactWarning = !0, Object.defineProperty(o, "key", {
125
+ get: A,
126
126
  configurable: !0
127
127
  });
128
128
  }
129
- function d() {
130
- var e = t(this.type);
131
- return Y[e] || (Y[e] = !0, console.error(
129
+ function u() {
130
+ var o = t(this.type);
131
+ return W[o] || (W[o] = !0, console.error(
132
132
  "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
133
- )), e = this.props.ref, e !== void 0 ? e : null;
133
+ )), o = this.props.ref, o !== void 0 ? o : null;
134
134
  }
135
- function u(e, c, x, I, Z, nt) {
136
- var A = x.ref;
137
- return e = {
138
- $$typeof: g,
139
- type: e,
140
- key: c,
141
- props: x,
142
- _owner: I
143
- }, (A !== void 0 ? A : null) !== null ? Object.defineProperty(e, "ref", {
135
+ function c(o, y, A, S, rt, st) {
136
+ var T = A.ref;
137
+ return o = {
138
+ $$typeof: m,
139
+ type: o,
140
+ key: y,
141
+ props: A,
142
+ _owner: S
143
+ }, (T !== void 0 ? T : null) !== null ? Object.defineProperty(o, "ref", {
144
144
  enumerable: !1,
145
- get: d
146
- }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
145
+ get: u
146
+ }) : Object.defineProperty(o, "ref", { enumerable: !1, value: null }), o._store = {}, Object.defineProperty(o._store, "validated", {
147
147
  configurable: !1,
148
148
  enumerable: !1,
149
149
  writable: !0,
150
150
  value: 0
151
- }), Object.defineProperty(e, "_debugInfo", {
151
+ }), Object.defineProperty(o, "_debugInfo", {
152
152
  configurable: !1,
153
153
  enumerable: !1,
154
154
  writable: !0,
155
155
  value: null
156
- }), Object.defineProperty(e, "_debugStack", {
156
+ }), Object.defineProperty(o, "_debugStack", {
157
157
  configurable: !1,
158
158
  enumerable: !1,
159
159
  writable: !0,
160
- value: Z
161
- }), Object.defineProperty(e, "_debugTask", {
160
+ value: rt
161
+ }), Object.defineProperty(o, "_debugTask", {
162
162
  configurable: !1,
163
163
  enumerable: !1,
164
164
  writable: !0,
165
- value: nt
166
- }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
165
+ value: st
166
+ }), Object.freeze && (Object.freeze(o.props), Object.freeze(o)), o;
167
167
  }
168
- function p(e, c, x, I, Z, nt) {
169
- var A = c.children;
170
- if (A !== void 0)
171
- if (I)
172
- if (L(A)) {
173
- for (I = 0; I < A.length; I++)
174
- R(A[I]);
175
- Object.freeze && Object.freeze(A);
168
+ function d(o, y, A, S, rt, st) {
169
+ var T = y.children;
170
+ if (T !== void 0)
171
+ if (S)
172
+ if (C(T)) {
173
+ for (S = 0; S < T.length; S++)
174
+ k(T[S]);
175
+ Object.freeze && Object.freeze(T);
176
176
  } else
177
177
  console.error(
178
178
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
179
179
  );
180
- else R(A);
181
- if ($.call(c, "key")) {
182
- A = t(e);
183
- var H = Object.keys(c).filter(function(wt) {
180
+ else k(T);
181
+ if (R.call(y, "key")) {
182
+ T = t(o);
183
+ var U = Object.keys(y).filter(function(wt) {
184
184
  return wt !== "key";
185
185
  });
186
- I = 0 < H.length ? "{key: someKey, " + H.join(": ..., ") + ": ...}" : "{key: someKey}", ut[A + I] || (H = 0 < H.length ? "{" + H.join(": ..., ") + ": ...}" : "{}", console.error(
186
+ S = 0 < U.length ? "{key: someKey, " + U.join(": ..., ") + ": ...}" : "{key: someKey}", ct[T + S] || (U = 0 < U.length ? "{" + U.join(": ..., ") + ": ...}" : "{}", console.error(
187
187
  `A props object containing a "key" prop is being spread into JSX:
188
188
  let props = %s;
189
189
  <%s {...props} />
190
190
  React keys must be passed directly to JSX without using spread:
191
191
  let props = %s;
192
192
  <%s key={someKey} {...props} />`,
193
- I,
194
- A,
195
- H,
196
- A
197
- ), ut[A + I] = !0);
193
+ S,
194
+ T,
195
+ U,
196
+ T
197
+ ), ct[T + S] = !0);
198
198
  }
199
- if (A = null, x !== void 0 && (o(x), A = "" + x), i(c) && (o(c.key), A = "" + c.key), "key" in c) {
200
- x = {};
201
- for (var st in c)
202
- st !== "key" && (x[st] = c[st]);
203
- } else x = c;
204
- return A && s(
205
- x,
206
- typeof e == "function" ? e.displayName || e.name || "Unknown" : e
207
- ), u(
208
- e,
199
+ if (T = null, A !== void 0 && (n(A), T = "" + A), a(y) && (n(y.key), T = "" + y.key), "key" in y) {
200
+ A = {};
201
+ for (var it in y)
202
+ it !== "key" && (A[it] = y[it]);
203
+ } else A = y;
204
+ return T && s(
205
+ A,
206
+ typeof o == "function" ? o.displayName || o.name || "Unknown" : o
207
+ ), c(
208
+ o,
209
+ T,
209
210
  A,
210
- x,
211
- a(),
212
- Z,
213
- nt
211
+ i(),
212
+ rt,
213
+ st
214
214
  );
215
215
  }
216
- function R(e) {
217
- h(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === E && (e._payload.status === "fulfilled" ? h(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
216
+ function k(o) {
217
+ p(o) ? o._store && (o._store.validated = 1) : typeof o == "object" && o !== null && o.$$typeof === V && (o._payload.status === "fulfilled" ? p(o._payload.value) && o._payload.value._store && (o._payload.value._store.validated = 1) : o._store && (o._store.validated = 1));
218
218
  }
219
- function h(e) {
220
- return typeof e == "object" && e !== null && e.$$typeof === g;
219
+ function p(o) {
220
+ return typeof o == "object" && o !== null && o.$$typeof === m;
221
221
  }
222
- var f = kt, g = /* @__PURE__ */ Symbol.for("react.transitional.element"), w = /* @__PURE__ */ Symbol.for("react.portal"), S = /* @__PURE__ */ Symbol.for("react.fragment"), T = /* @__PURE__ */ Symbol.for("react.strict_mode"), m = /* @__PURE__ */ Symbol.for("react.profiler"), j = /* @__PURE__ */ Symbol.for("react.consumer"), P = /* @__PURE__ */ Symbol.for("react.context"), b = /* @__PURE__ */ Symbol.for("react.forward_ref"), M = /* @__PURE__ */ Symbol.for("react.suspense"), V = /* @__PURE__ */ Symbol.for("react.suspense_list"), z = /* @__PURE__ */ Symbol.for("react.memo"), E = /* @__PURE__ */ Symbol.for("react.lazy"), k = /* @__PURE__ */ Symbol.for("react.activity"), y = /* @__PURE__ */ Symbol.for("react.client.reference"), v = f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, $ = Object.prototype.hasOwnProperty, L = Array.isArray, _ = console.createTask ? console.createTask : function() {
222
+ var g = kt, m = /* @__PURE__ */ Symbol.for("react.transitional.element"), v = /* @__PURE__ */ Symbol.for("react.portal"), f = /* @__PURE__ */ Symbol.for("react.fragment"), b = /* @__PURE__ */ Symbol.for("react.strict_mode"), h = /* @__PURE__ */ Symbol.for("react.profiler"), E = /* @__PURE__ */ Symbol.for("react.consumer"), w = /* @__PURE__ */ Symbol.for("react.context"), x = /* @__PURE__ */ Symbol.for("react.forward_ref"), $ = /* @__PURE__ */ Symbol.for("react.suspense"), N = /* @__PURE__ */ Symbol.for("react.suspense_list"), H = /* @__PURE__ */ Symbol.for("react.memo"), V = /* @__PURE__ */ Symbol.for("react.lazy"), q = /* @__PURE__ */ Symbol.for("react.activity"), X = /* @__PURE__ */ Symbol.for("react.client.reference"), j = g.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, R = Object.prototype.hasOwnProperty, C = Array.isArray, _ = console.createTask ? console.createTask : function() {
223
223
  return null;
224
224
  };
225
- f = {
226
- react_stack_bottom_frame: function(e) {
227
- return e();
225
+ g = {
226
+ react_stack_bottom_frame: function(o) {
227
+ return o();
228
228
  }
229
229
  };
230
- var W, Y = {}, U = f.react_stack_bottom_frame.bind(
231
- f,
230
+ var M, W = {}, Y = g.react_stack_bottom_frame.bind(
231
+ g,
232
232
  l
233
- )(), lt = _(n(l)), ut = {};
234
- X.Fragment = S, X.jsx = function(e, c, x) {
235
- var I = 1e4 > v.recentlyCreatedOwnerStacks++;
236
- return p(
237
- e,
238
- c,
239
- x,
233
+ )(), D = _(r(l)), ct = {};
234
+ J.Fragment = f, J.jsx = function(o, y, A) {
235
+ var S = 1e4 > j.recentlyCreatedOwnerStacks++;
236
+ return d(
237
+ o,
238
+ y,
239
+ A,
240
240
  !1,
241
- I ? Error("react-stack-top-frame") : U,
242
- I ? _(n(e)) : lt
241
+ S ? Error("react-stack-top-frame") : Y,
242
+ S ? _(r(o)) : D
243
243
  );
244
- }, X.jsxs = function(e, c, x) {
245
- var I = 1e4 > v.recentlyCreatedOwnerStacks++;
246
- return p(
247
- e,
248
- c,
249
- x,
244
+ }, J.jsxs = function(o, y, A) {
245
+ var S = 1e4 > j.recentlyCreatedOwnerStacks++;
246
+ return d(
247
+ o,
248
+ y,
249
+ A,
250
250
  !0,
251
- I ? Error("react-stack-top-frame") : U,
252
- I ? _(n(e)) : lt
251
+ S ? Error("react-stack-top-frame") : Y,
252
+ S ? _(r(o)) : D
253
253
  );
254
254
  };
255
- })()), X;
255
+ })()), J;
256
256
  }
257
257
  var dt;
258
- function At() {
259
- return dt || (dt = 1, process.env.NODE_ENV === "production" ? Q.exports = Et() : Q.exports = It()), Q.exports;
258
+ function Ct() {
259
+ return dt || (dt = 1, process.env.NODE_ENV === "production" ? nt.exports = Et() : nt.exports = It()), nt.exports;
260
+ }
261
+ var I = Ct();
262
+ const At = 200;
263
+ function Rt(t, e, n) {
264
+ const r = n[0] - e[0], i = n[1] - e[1], l = r * r + i * i;
265
+ if (l === 0) {
266
+ const s = t[0] - e[0], u = t[1] - e[1];
267
+ return Math.sqrt(s * s + u * u);
268
+ }
269
+ return Math.abs(r * (e[1] - t[1]) - i * (e[0] - t[0])) / Math.sqrt(l);
260
270
  }
261
- var C = At();
262
- function Rt(t, r) {
263
- const o = new Uint8Array(r);
264
- for (let n = 0; n < r; n++)
265
- o[n] = t[n * 4 + 3];
266
- return o;
271
+ function at(t, e) {
272
+ if (t.length <= 2) return t;
273
+ let n = 0, r = 0;
274
+ const i = t[0], l = t[t.length - 1];
275
+ for (let a = 1; a < t.length - 1; a++) {
276
+ const s = Rt(t[a], i, l);
277
+ s > n && (n = s, r = a);
278
+ }
279
+ if (n > e) {
280
+ const a = at(t.slice(0, r + 1), e), s = at(t.slice(r), e);
281
+ return a.slice(0, -1).concat(s);
282
+ }
283
+ return [i, l];
267
284
  }
268
- function _t(t, r, o, n) {
269
- if (r <= 0 || o <= 0) return { x: 0, y: 0, w: 1, h: 1 };
270
- let a = r, l = o, i = 0, s = 0, d = !1;
271
- for (let u = 0; u < o; u++)
272
- for (let p = 0; p < r; p++)
273
- t[u * r + p] > n && (p < a && (a = p), p > i && (i = p), u < l && (l = u), u > s && (s = u), d = !0);
274
- return d ? {
275
- x: a / r,
276
- y: l / o,
277
- w: (i - a + 1) / r,
278
- h: (s - l + 1) / o
285
+ function _t(t, e, n) {
286
+ let r = -1, i = -1;
287
+ t: for (let g = 0; g < n; g++)
288
+ for (let m = 0; m < e; m++)
289
+ if (t[g * e + m]) {
290
+ r = m, i = g;
291
+ break t;
292
+ }
293
+ if (r < 0) return [];
294
+ const l = [1, 1, 0, -1, -1, -1, 0, 1], a = [0, 1, 1, 1, 0, -1, -1, -1], s = [];
295
+ let u = r, c = i, d = 5;
296
+ const k = e * n * 4;
297
+ let p = 0;
298
+ do {
299
+ s.push([u, c]);
300
+ let g = !1;
301
+ for (let m = 0; m < 8; m++) {
302
+ const v = (d + m) % 8, f = u + l[v], b = c + a[v];
303
+ if (f >= 0 && f < e && b >= 0 && b < n && t[b * e + f]) {
304
+ u = f, c = b, d = ((v + 4) % 8 + 1) % 8, g = !0;
305
+ break;
306
+ }
307
+ }
308
+ if (!g || ++p > k) break;
309
+ } while (u !== r || c !== i);
310
+ return s;
311
+ }
312
+ function jt(t, e, n, r = 30, i = 3e-3) {
313
+ if (e <= 0 || n <= 0 || t.length === 0) return [];
314
+ const l = Math.min(1, At / Math.max(e, n)), a = Math.max(1, Math.round(e * l)), s = Math.max(1, Math.round(n * l)), u = new Uint8Array(a * s);
315
+ for (let p = 0; p < s; p++) {
316
+ const g = Math.min(n - 1, Math.floor(p / l));
317
+ for (let m = 0; m < a; m++) {
318
+ const v = Math.min(e - 1, Math.floor(m / l));
319
+ u[p * a + m] = t[g * e + v] > r ? 1 : 0;
320
+ }
321
+ }
322
+ const c = _t(u, a, s);
323
+ if (c.length < 3) return [];
324
+ const d = c.map(([p, g]) => [
325
+ (p + 0.5) / a,
326
+ (g + 0.5) / s
327
+ ]), k = at(d, i);
328
+ return k.length >= 3 ? k : d;
329
+ }
330
+ function St(t, e) {
331
+ const n = new Uint8Array(e);
332
+ for (let r = 0; r < e; r++)
333
+ n[r] = t[r * 4 + 3];
334
+ return n;
335
+ }
336
+ function Tt(t, e, n, r) {
337
+ if (e <= 0 || n <= 0) return { x: 0, y: 0, w: 1, h: 1 };
338
+ let i = e, l = n, a = 0, s = 0, u = !1;
339
+ for (let c = 0; c < n; c++)
340
+ for (let d = 0; d < e; d++)
341
+ t[c * e + d] > r && (d < i && (i = d), d > a && (a = d), c < l && (l = c), c > s && (s = c), u = !0);
342
+ return u ? {
343
+ x: i / e,
344
+ y: l / n,
345
+ w: (a - i + 1) / e,
346
+ h: (s - l + 1) / n
279
347
  } : { x: 0, y: 0, w: 1, h: 1 };
280
348
  }
281
- class Ct {
349
+ class Pt {
282
350
  id;
283
351
  bounds = { x: 0, y: 0, w: 1, h: 1 };
352
+ contour = [];
284
353
  /** URL of the cutout mask image */
285
354
  src;
286
355
  /** Alpha value (0-255) a pixel must exceed to be considered "visible" */
@@ -290,8 +359,8 @@ class Ct {
290
359
  /** Source image dimensions (pixels) — needed to map normalized coords to pixel indices */
291
360
  width = 0;
292
361
  height = 0;
293
- constructor(r, o) {
294
- this.id = r.id, this.src = r.src, this.threshold = o;
362
+ constructor(e, n) {
363
+ this.id = e.id, this.src = e.src, this.threshold = n;
295
364
  }
296
365
  /**
297
366
  * Loads the cutout image and pre-computes the alpha buffer + bounding box.
@@ -308,20 +377,20 @@ class Ct {
308
377
  * empty alpha buffer, which means hitTest will always return false.
309
378
  */
310
379
  async prepare() {
311
- const r = new Image();
312
- r.crossOrigin = "anonymous", r.src = this.src, await new Promise((i) => {
313
- r.onload = () => i(), r.onerror = () => i();
380
+ const e = new Image();
381
+ e.crossOrigin = "anonymous", e.src = this.src, await new Promise((a) => {
382
+ e.onload = () => a(), e.onerror = () => a();
314
383
  });
315
- const o = r.naturalWidth, n = r.naturalHeight;
316
- if (o <= 0 || n <= 0) return;
317
- const a = document.createElement("canvas");
318
- a.width = o, a.height = n;
319
- const l = a.getContext("2d", { willReadFrequently: !0 });
384
+ const n = e.naturalWidth, r = e.naturalHeight;
385
+ if (n <= 0 || r <= 0) return;
386
+ const i = document.createElement("canvas");
387
+ i.width = n, i.height = r;
388
+ const l = i.getContext("2d", { willReadFrequently: !0 });
320
389
  if (l)
321
390
  try {
322
- l.drawImage(r, 0, 0);
323
- const i = l.getImageData(0, 0, o, n);
324
- this.alpha = Rt(i.data, o * n), this.width = o, this.height = n, this.bounds = _t(this.alpha, o, n, this.threshold);
391
+ l.drawImage(e, 0, 0);
392
+ const a = l.getImageData(0, 0, n, r);
393
+ this.alpha = St(a.data, n * r), this.width = n, this.height = r, this.bounds = Tt(this.alpha, n, r, this.threshold), this.contour = jt(this.alpha, n, r, this.threshold);
325
394
  } catch {
326
395
  this.alpha = new Uint8Array(0);
327
396
  }
@@ -341,50 +410,50 @@ class Ct {
341
410
  * @param nx - normalized x-coordinate (0-1, relative to the image width)
342
411
  * @param ny - normalized y-coordinate (0-1, relative to the image height)
343
412
  */
344
- hitTest(r, o) {
413
+ hitTest(e, n) {
345
414
  if (this.alpha.length === 0) return !1;
346
- const n = this.bounds;
347
- if (r < n.x || r > n.x + n.w || o < n.y || o > n.y + n.h) return !1;
348
- const a = Math.min(this.width - 1, Math.max(0, Math.floor(r * this.width))), l = Math.min(
415
+ const r = this.bounds;
416
+ if (e < r.x || e > r.x + r.w || n < r.y || n > r.y + r.h) return !1;
417
+ const i = Math.min(this.width - 1, Math.max(0, Math.floor(e * this.width))), l = Math.min(
349
418
  this.height - 1,
350
- Math.max(0, Math.floor(o * this.height))
419
+ Math.max(0, Math.floor(n * this.height))
351
420
  );
352
- return this.alpha[l * this.width + a] > this.threshold;
421
+ return this.alpha[l * this.width + i] > this.threshold;
353
422
  }
354
423
  }
355
- class Tt {
424
+ class Mt {
356
425
  id;
357
426
  bounds;
358
- constructor(r) {
359
- this.id = r.id, this.bounds = { ...r.bounds };
427
+ constructor(e) {
428
+ this.id = e.id, this.bounds = { ...e.bounds };
360
429
  }
361
- hitTest(r, o) {
362
- const n = this.bounds;
363
- return r >= n.x && r <= n.x + n.w && o >= n.y && o <= n.y + n.h;
430
+ hitTest(e, n) {
431
+ const r = this.bounds;
432
+ return e >= r.x && e <= r.x + r.w && n >= r.y && n <= r.y + r.h;
364
433
  }
365
434
  }
366
- function St(t, r, o) {
367
- let n = !1;
368
- for (let a = 0, l = o.length - 1; a < o.length; l = a++) {
369
- const i = o[a][0], s = o[a][1], d = o[l][0], u = o[l][1];
370
- s > r != u > r && t < (d - i) * (r - s) / (u - s) + i && (n = !n);
435
+ function $t(t, e, n) {
436
+ let r = !1;
437
+ for (let i = 0, l = n.length - 1; i < n.length; l = i++) {
438
+ const a = n[i][0], s = n[i][1], u = n[l][0], c = n[l][1];
439
+ s > e != c > e && t < (u - a) * (e - s) / (c - s) + a && (r = !r);
371
440
  }
372
- return n;
441
+ return r;
373
442
  }
374
- class jt {
443
+ class Dt {
375
444
  id;
376
445
  bounds;
377
446
  points;
378
- constructor(r) {
379
- this.id = r.id, this.points = r.points;
380
- let o = 1 / 0, n = 1 / 0, a = -1 / 0, l = -1 / 0;
381
- for (const [i, s] of r.points)
382
- i < o && (o = i), i > a && (a = i), s < n && (n = s), s > l && (l = s);
447
+ constructor(e) {
448
+ this.id = e.id, this.points = e.points;
449
+ let n = 1 / 0, r = 1 / 0, i = -1 / 0, l = -1 / 0;
450
+ for (const [a, s] of e.points)
451
+ a < n && (n = a), a > i && (i = a), s < r && (r = s), s > l && (l = s);
383
452
  this.bounds = {
384
- x: o,
385
- y: n,
386
- w: a - o,
387
- h: l - n
453
+ x: n,
454
+ y: r,
455
+ w: i - n,
456
+ h: l - r
388
457
  };
389
458
  }
390
459
  /**
@@ -399,22 +468,22 @@ class jt {
399
468
  * @param nx - normalized x-coordinate (0-1, relative to the image width)
400
469
  * @param ny - normalized y-coordinate (0-1, relative to the image height)
401
470
  */
402
- hitTest(r, o) {
403
- const n = this.bounds;
404
- return r < n.x || r > n.x + n.w || o < n.y || o > n.y + n.h ? !1 : St(r, o, this.points);
471
+ hitTest(e, n) {
472
+ const r = this.bounds;
473
+ return e < r.x || e > r.x + r.w || n < r.y || n > r.y + r.h ? !1 : $t(e, n, this.points);
405
474
  }
406
475
  }
407
- function $t(t, r) {
476
+ function Wt(t, e) {
408
477
  switch (t.type) {
409
478
  case "image":
410
- return new Ct(t, r);
479
+ return new Pt(t, e);
411
480
  case "bbox":
412
- return new Tt(t);
481
+ return new Mt(t);
413
482
  case "polygon":
414
- return new jt(t);
483
+ return new Dt(t);
415
484
  }
416
485
  }
417
- function Pt(t) {
486
+ function Ot(t) {
418
487
  switch (t.type) {
419
488
  case "image":
420
489
  return `${t.id}:image:${t.src}:${t.label ?? ""}`;
@@ -424,120 +493,121 @@ function Pt(t) {
424
493
  return `${t.id}:polygon:${t.points.flat().join(",")}:${t.label ?? ""}`;
425
494
  }
426
495
  }
427
- function Mt(t, r = !0, o = 30, n = 150) {
428
- const [a, l] = tt(null), [i, s] = tt(null), d = B(null), u = B([]), [p, R] = tt({}), h = Math.min(255, Math.max(0, o)), f = B(null), g = O(() => {
429
- f.current === null && (f.current = setTimeout(() => {
430
- f.current = null, l(null);
431
- }, n));
432
- }, [n]), w = O(() => {
433
- f.current !== null && (clearTimeout(f.current), f.current = null);
434
- }, []), S = t.map(Pt).join("|"), T = D(() => t, [S]);
435
- N(() => {
436
- if (!r) {
437
- u.current = [];
496
+ function Nt(t, e = !0, n = 30, r = 150) {
497
+ const [i, l] = L(null), [a, s] = L(null), u = B(null), c = B([]), [d, k] = L({}), [p, g] = L({}), m = Math.min(255, Math.max(0, n)), v = B(null), f = P(() => {
498
+ v.current === null && (v.current = setTimeout(() => {
499
+ v.current = null, l(null);
500
+ }, r));
501
+ }, [r]), b = P(() => {
502
+ v.current !== null && (clearTimeout(v.current), v.current = null);
503
+ }, []), h = t.map(Ot).join("|"), E = F(() => t, [h]);
504
+ O(() => {
505
+ if (!e) {
506
+ c.current = [];
438
507
  return;
439
508
  }
440
- let E = !1, k = [];
441
- async function y() {
442
- const v = [], $ = {};
443
- for (const L of T) {
444
- const _ = $t(L, h);
445
- if (_.prepare && await _.prepare(), E) return;
446
- v.push(_), $[_.id] = _.bounds;
509
+ let j = !1, R = [];
510
+ async function C() {
511
+ const _ = [], M = {}, W = {};
512
+ for (const Y of E) {
513
+ const D = Wt(Y, m);
514
+ if (D.prepare && await D.prepare(), j) return;
515
+ _.push(D), M[D.id] = D.bounds, D.contour && D.contour.length >= 3 && (W[D.id] = D.contour);
447
516
  }
448
- E || (k = v, u.current = v, R($));
517
+ j || (R = _, c.current = _, k(M), g(W));
449
518
  }
450
- return y(), () => {
451
- E = !0;
452
- for (const v of k)
453
- v.dispose?.();
519
+ return C(), () => {
520
+ j = !0;
521
+ for (const _ of R)
522
+ _.dispose?.();
454
523
  };
455
- }, [T, r, h]);
456
- const m = O(
457
- (E, k) => {
458
- const y = u.current;
459
- for (let v = y.length - 1; v >= 0; v--)
460
- if (y[v].hitTest(E, k))
461
- return y[v].id;
524
+ }, [E, e, m]);
525
+ const w = P(
526
+ (j, R) => {
527
+ const C = c.current;
528
+ for (let _ = C.length - 1; _ >= 0; _--)
529
+ if (C[_].hitTest(j, R))
530
+ return C[_].id;
462
531
  return null;
463
532
  },
464
533
  []
465
- ), j = O(
466
- (E) => {
467
- const k = d.current;
468
- if (!k) return null;
469
- const y = k.getBoundingClientRect(), v = (E.clientX - y.left) / y.width, $ = (E.clientY - y.top) / y.height;
470
- return v < 0 || v > 1 || $ < 0 || $ > 1 ? null : { nx: v, ny: $ };
534
+ ), x = P(
535
+ (j) => {
536
+ const R = u.current;
537
+ if (!R) return null;
538
+ const C = R.getBoundingClientRect(), _ = (j.clientX - C.left) / C.width, M = (j.clientY - C.top) / C.height;
539
+ return _ < 0 || _ > 1 || M < 0 || M > 1 ? null : { nx: _, ny: M };
471
540
  },
472
541
  []
473
- ), P = O(
474
- (E) => {
475
- if (!r) return;
476
- const k = j(E);
477
- if (!k) {
478
- g();
542
+ ), $ = P(
543
+ (j) => {
544
+ if (!e) return;
545
+ const R = x(j);
546
+ if (!R) {
547
+ f();
479
548
  return;
480
549
  }
481
- const y = m(k.nx, k.ny);
482
- if (y === null) {
483
- if (E.target?.closest('[data-cutout-overlay="true"]')) {
484
- w();
550
+ const C = w(R.nx, R.ny);
551
+ if (C === null) {
552
+ if (j.target?.closest('[data-cutout-overlay="true"]')) {
553
+ b();
485
554
  return;
486
555
  }
487
- g();
556
+ f();
488
557
  return;
489
558
  }
490
- w(), l(y);
559
+ b(), l(C);
491
560
  },
492
- [r, j, m, g, w]
493
- ), b = O(() => {
494
- g();
495
- }, [g]), M = O(
496
- (E) => {
497
- if (!r) return;
498
- const k = j(E);
499
- if (!k) {
561
+ [e, x, w, f, b]
562
+ ), N = P(() => {
563
+ f();
564
+ }, [f]), H = P(
565
+ (j) => {
566
+ if (!e) return;
567
+ const R = x(j);
568
+ if (!R) {
500
569
  s(null);
501
570
  return;
502
571
  }
503
- const y = m(k.nx, k.ny);
504
- s(y === i || y === null ? null : y);
572
+ const C = w(R.nx, R.ny);
573
+ s(C === a || C === null ? null : C);
505
574
  },
506
- [r, j, m, i]
507
- ), V = i ?? a, z = r ? p : {};
508
- return N(() => () => {
509
- w();
510
- }, [w]), {
511
- hoveredId: a,
512
- selectedId: i,
575
+ [e, x, w, a]
576
+ ), V = a ?? i, q = e ? d : {}, X = e ? p : {};
577
+ return O(() => () => {
578
+ b();
579
+ }, [b]), {
580
+ hoveredId: i,
581
+ selectedId: a,
513
582
  activeId: V,
514
- boundsMap: z,
515
- containerRef: d,
583
+ boundsMap: q,
584
+ contourMap: X,
585
+ containerRef: u,
516
586
  containerProps: {
517
- onPointerMove: P,
518
- onPointerLeave: b,
519
- onClick: M
587
+ onPointerMove: $,
588
+ onPointerLeave: N,
589
+ onClick: H
520
590
  }
521
591
  };
522
592
  }
523
- function it(t, r) {
524
- return { name: t, css: r };
593
+ function vt(t, e) {
594
+ return { name: t, css: e };
525
595
  }
526
- const pt = /* @__PURE__ */ new Set();
527
- function Wt(t) {
596
+ const ht = /* @__PURE__ */ new Set();
597
+ function Yt(t) {
528
598
  if (!(!t.keyframes?.length || typeof document > "u"))
529
- for (const r of t.keyframes) {
530
- if (pt.has(r.name)) continue;
531
- pt.add(r.name);
532
- const o = document.createElement("style");
533
- o.setAttribute("data-ricut-kf", r.name), o.textContent = `@keyframes ${r.name} {
534
- ${r.css}
535
- }`, document.head.appendChild(o);
599
+ for (const e of t.keyframes) {
600
+ if (ht.has(e.name)) continue;
601
+ ht.add(e.name);
602
+ const n = document.createElement("style");
603
+ n.setAttribute("data-ricut-kf", e.name), n.textContent = `@keyframes ${e.name} {
604
+ ${e.css}
605
+ }`, document.head.appendChild(n);
536
606
  }
537
607
  }
538
- const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
608
+ const Z = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Vt = {
539
609
  name: "elevate",
540
- transition: J,
610
+ transition: Z,
541
611
  mainImageHovered: {
542
612
  filter: "brightness(0.45) saturate(0.7)"
543
613
  },
@@ -575,9 +645,9 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
575
645
  stroke: "transparent",
576
646
  strokeWidth: 1
577
647
  }
578
- }, Nt = {
648
+ }, Lt = {
579
649
  name: "glow",
580
- transition: J,
650
+ transition: Z,
581
651
  mainImageHovered: {
582
652
  filter: "brightness(0.55) saturate(0.8)"
583
653
  },
@@ -615,9 +685,9 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
615
685
  stroke: "transparent",
616
686
  strokeWidth: 1
617
687
  }
618
- }, Yt = {
688
+ }, Bt = {
619
689
  name: "lift",
620
- transition: J,
690
+ transition: Z,
621
691
  mainImageHovered: {
622
692
  filter: "brightness(0.4)"
623
693
  },
@@ -655,7 +725,7 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
655
725
  stroke: "transparent",
656
726
  strokeWidth: 1
657
727
  }
658
- }, Dt = {
728
+ }, Ft = {
659
729
  name: "subtle",
660
730
  transition: "all 0.3s ease",
661
731
  mainImageHovered: {
@@ -694,21 +764,14 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
694
764
  stroke: "transparent",
695
765
  strokeWidth: 1
696
766
  }
697
- }, ht = it(
767
+ }, gt = vt(
698
768
  "_ricut-trace-stroke",
699
769
  `from { stroke-dashoffset: 0; }
700
770
  to { stroke-dashoffset: -1; }`
701
- ), gt = it(
702
- "_ricut-trace-glow",
703
- `0% { filter: drop-shadow(-3px -3px 6px rgba(255,255,255,0.6)) drop-shadow(0 0 2px rgba(255,255,255,0.15)); }
704
- 25% { filter: drop-shadow(3px -3px 6px rgba(255,255,255,0.6)) drop-shadow(0 0 2px rgba(255,255,255,0.15)); }
705
- 50% { filter: drop-shadow(3px 3px 6px rgba(255,255,255,0.6)) drop-shadow(0 0 2px rgba(255,255,255,0.15)); }
706
- 75% { filter: drop-shadow(-3px 3px 6px rgba(255,255,255,0.6)) drop-shadow(0 0 2px rgba(255,255,255,0.15)); }
707
- 100% { filter: drop-shadow(-3px -3px 6px rgba(255,255,255,0.6)) drop-shadow(0 0 2px rgba(255,255,255,0.15)); }`
708
- ), Vt = {
771
+ ), zt = {
709
772
  name: "trace",
710
- transition: J,
711
- keyframes: [ht, gt],
773
+ transition: Z,
774
+ keyframes: [gt],
712
775
  mainImageHovered: {
713
776
  filter: "brightness(0.35) saturate(0.5)"
714
777
  },
@@ -717,9 +780,8 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
717
780
  },
718
781
  cutoutActive: {
719
782
  transform: "scale(1)",
720
- filter: "drop-shadow(-3px -3px 6px rgba(255,255,255,0.6)) drop-shadow(0 0 2px rgba(255,255,255,0.15))",
721
- opacity: 1,
722
- animation: `${gt.name} 3s linear infinite`
783
+ filter: "drop-shadow(0 0 8px rgba(255,255,255,0.15))",
784
+ opacity: 1
723
785
  },
724
786
  cutoutInactive: {
725
787
  transform: "scale(1)",
@@ -736,7 +798,7 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
736
798
  stroke: "rgba(255, 255, 255, 0.9)",
737
799
  strokeWidth: 2.5,
738
800
  strokeDasharray: "0.15 0.85",
739
- animation: `${ht.name} 3s linear infinite`,
801
+ animation: `${gt.name} 3s linear infinite`,
740
802
  glow: "0 0 10px rgba(255, 255, 255, 0.25)"
741
803
  },
742
804
  geometryInactive: {
@@ -749,7 +811,7 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
749
811
  stroke: "transparent",
750
812
  strokeWidth: 1
751
813
  }
752
- }, mt = it(
814
+ }, pt = vt(
753
815
  "_ricut-shimmer",
754
816
  `0%, 100% {
755
817
  filter: brightness(1.05) contrast(1.02)
@@ -768,8 +830,8 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
768
830
  }`
769
831
  ), Ht = {
770
832
  name: "shimmer",
771
- transition: J,
772
- keyframes: [mt],
833
+ transition: Z,
834
+ keyframes: [pt],
773
835
  mainImageHovered: {
774
836
  filter: "brightness(0.35) saturate(0.6)"
775
837
  },
@@ -782,7 +844,7 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
782
844
  we set it here so there's a graceful look before the first frame. */
783
845
  filter: "brightness(1.05) contrast(1.02) drop-shadow(0 0 6px rgba(255,255,255,0.12)) drop-shadow(0 12px 32px rgba(0,0,0,0.4))",
784
846
  opacity: 1,
785
- animation: `${mt.name} 2.4s ease-in-out infinite`
847
+ animation: `${pt.name} 2.4s ease-in-out infinite`
786
848
  },
787
849
  cutoutInactive: {
788
850
  transform: "scale(1)",
@@ -810,48 +872,48 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
810
872
  stroke: "transparent",
811
873
  strokeWidth: 1
812
874
  }
813
- }, q = {
814
- elevate: Ot,
815
- glow: Nt,
816
- lift: Yt,
817
- subtle: Dt,
818
- trace: Vt,
875
+ }, K = {
876
+ elevate: Vt,
877
+ glow: Lt,
878
+ lift: Bt,
879
+ subtle: Ft,
880
+ trace: zt,
819
881
  shimmer: Ht
820
- }, et = at(null), xt = at(null);
821
- function rt() {
822
- const t = F(xt);
882
+ }, Q = lt(null), xt = lt(null);
883
+ function ot() {
884
+ const t = z(xt);
823
885
  if (!t) throw new Error("Must be used inside <CutoutViewer>");
824
886
  return t;
825
887
  }
826
- const K = at(null);
827
- function qt() {
828
- const t = F(K);
888
+ const tt = lt(null);
889
+ function ee() {
890
+ const t = z(tt);
829
891
  if (!t)
830
892
  throw new Error("useCutout must be used inside <CutoutViewer.Cutout>");
831
893
  return t;
832
894
  }
833
- function Bt({ id: t, src: r, label: o, effect: n, children: a, renderLayer: l }) {
834
- const i = F(et), s = rt();
835
- if (!i)
895
+ function Xt({ id: t, src: e, label: n, effect: r, children: i, renderLayer: l }) {
896
+ const a = z(Q), s = ot();
897
+ if (!a)
836
898
  throw new Error("<CutoutViewer.Cutout> must be used inside <CutoutViewer>");
837
- N(() => (i.registerCutout({ type: "image", id: t, src: r, label: o }), () => i.unregisterCutout(t)), [t, r, o, i]);
838
- const d = n ? typeof n == "string" ? q[n] ?? s.effect : n : s.effect, u = s.activeId === t, p = s.hoveredId === t, R = s.selectedId === t, h = { x: 0, y: 0, w: 1, h: 1 }, f = s.boundsMap[t] ?? h;
839
- let g;
840
- !s.enabled || !s.isAnyActive && !s.showAll ? g = d.cutoutIdle : s.showAll || u ? g = d.cutoutActive : g = d.cutoutInactive;
841
- const w = D(
899
+ O(() => (a.registerCutout({ type: "image", id: t, src: e, label: n }), () => a.unregisterCutout(t)), [t, e, n, a]);
900
+ const u = r ? typeof r == "string" ? K[r] ?? s.effect : r : s.effect, c = s.contourMap[t] ?? null, d = s.activeId === t, k = s.hoveredId === t, p = s.selectedId === t, g = { x: 0, y: 0, w: 1, h: 1 }, m = s.boundsMap[t] ?? g;
901
+ let v, f;
902
+ !s.enabled || !s.isAnyActive && !s.showAll ? (v = u.cutoutIdle, f = u.geometryIdle) : s.showAll || d ? (v = u.cutoutActive, f = u.geometryActive) : (v = u.cutoutInactive, f = u.geometryInactive);
903
+ const b = F(
842
904
  () => ({
843
905
  id: t,
844
- label: o,
845
- bounds: f,
846
- isActive: u,
847
- isHovered: p,
848
- isSelected: R,
849
- effect: d
906
+ label: n,
907
+ bounds: m,
908
+ isActive: d,
909
+ isHovered: k,
910
+ isSelected: p,
911
+ effect: u
850
912
  }),
851
- [t, o, f, u, p, R, d]
913
+ [t, n, m, d, k, p, u]
852
914
  );
853
- return /* @__PURE__ */ C.jsxs(K.Provider, { value: w, children: [
854
- /* @__PURE__ */ C.jsx(
915
+ return /* @__PURE__ */ I.jsxs(tt.Provider, { value: b, children: [
916
+ /* @__PURE__ */ I.jsxs(
855
917
  "div",
856
918
  {
857
919
  "data-cutout-id": t,
@@ -859,69 +921,103 @@ function Bt({ id: t, src: r, label: o, effect: n, children: a, renderLayer: l })
859
921
  pointerEvents: "none",
860
922
  position: "absolute",
861
923
  inset: 0,
862
- zIndex: u ? 20 : 10,
863
- transition: d.transition,
864
- ...g
924
+ zIndex: d ? 20 : 10,
925
+ transition: u.transition,
926
+ ...v
865
927
  },
866
- children: l ? l({ isActive: u, isHovered: p, isSelected: R, bounds: f, effect: d }) : /* @__PURE__ */ C.jsx(
867
- "img",
868
- {
869
- src: r,
870
- alt: o || t,
871
- draggable: !1,
872
- style: {
873
- width: "100%",
874
- height: "100%",
875
- objectFit: "fill",
876
- userSelect: "none"
928
+ children: [
929
+ l ? l({ isActive: d, isHovered: k, isSelected: p, bounds: m, effect: u }) : /* @__PURE__ */ I.jsx(
930
+ "img",
931
+ {
932
+ src: e,
933
+ alt: n || t,
934
+ draggable: !1,
935
+ style: {
936
+ width: "100%",
937
+ height: "100%",
938
+ objectFit: "fill",
939
+ userSelect: "none"
940
+ }
877
941
  }
878
- }
879
- )
942
+ ),
943
+ c && f && /* @__PURE__ */ I.jsx(
944
+ "svg",
945
+ {
946
+ viewBox: "0 0 1 1",
947
+ preserveAspectRatio: "none",
948
+ style: {
949
+ position: "absolute",
950
+ inset: 0,
951
+ width: "100%",
952
+ height: "100%",
953
+ overflow: "visible",
954
+ filter: f.glow ? `drop-shadow(${f.glow.split(",")[0]?.trim() ?? ""})` : "none"
955
+ },
956
+ children: /* @__PURE__ */ I.jsx(
957
+ "polygon",
958
+ {
959
+ points: c.map(([h, E]) => `${h},${E}`).join(" "),
960
+ fill: f.fill,
961
+ stroke: f.stroke,
962
+ strokeWidth: (f.strokeWidth ?? 2) * 15e-4,
963
+ strokeLinejoin: "round",
964
+ strokeLinecap: f.strokeDasharray ? "round" : void 0,
965
+ strokeDasharray: f.strokeDasharray,
966
+ pathLength: f.strokeDasharray ? 1 : void 0,
967
+ style: {
968
+ transition: u.transition,
969
+ animation: f.animation
970
+ }
971
+ }
972
+ )
973
+ }
974
+ )
975
+ ]
880
976
  }
881
977
  ),
882
- a
978
+ i
883
979
  ] });
884
980
  }
885
- function bt(t) {
886
- const { filter: r, ...o } = t;
887
- return o;
981
+ function mt(t) {
982
+ const { filter: e, ...n } = t;
983
+ return n;
888
984
  }
889
- function Ft({
985
+ function Ut({
890
986
  id: t,
891
- bounds: r,
892
- label: o,
893
- effect: n,
894
- children: a,
987
+ bounds: e,
988
+ label: n,
989
+ effect: r,
990
+ children: i,
895
991
  renderLayer: l
896
992
  }) {
897
- const i = F(et), s = rt();
898
- if (!i)
993
+ const a = z(Q), s = ot();
994
+ if (!a)
899
995
  throw new Error(
900
996
  "<CutoutViewer.BBoxCutout> must be used inside <CutoutViewer>"
901
997
  );
902
- const { x: d, y: u, w: p, h: R } = r;
903
- N(() => (i.registerCutout({ type: "bbox", id: t, bounds: { x: d, y: u, w: p, h: R }, label: o }), () => i.unregisterCutout(t)), [t, d, u, p, R, o, i]);
904
- const h = n ? typeof n == "string" ? q[n] ?? s.effect : n : s.effect, f = s.activeId === t, g = s.hoveredId === t, w = s.selectedId === t, S = { x: 0, y: 0, w: 1, h: 1 }, T = s.boundsMap[t] ?? S;
905
- let m, j;
906
- !s.enabled || !s.isAnyActive && !s.showAll ? (j = { ...h.cutoutIdle, filter: "none", opacity: 0 }, m = h.geometryIdle) : s.showAll || f ? (j = bt(h.cutoutActive), m = h.geometryActive) : (j = bt(h.cutoutInactive), m = h.geometryInactive);
907
- const b = m ?? {
998
+ const { x: u, y: c, w: d, h: k } = e;
999
+ O(() => (a.registerCutout({ type: "bbox", id: t, bounds: { x: u, y: c, w: d, h: k }, label: n }), () => a.unregisterCutout(t)), [t, u, c, d, k, n, a]);
1000
+ const p = r ? typeof r == "string" ? K[r] ?? s.effect : r : s.effect, g = s.activeId === t, m = s.hoveredId === t, v = s.selectedId === t, f = { x: 0, y: 0, w: 1, h: 1 }, b = s.boundsMap[t] ?? f;
1001
+ let h, E;
1002
+ !s.enabled || !s.isAnyActive && !s.showAll ? (E = { ...p.cutoutIdle, filter: "none", opacity: 0 }, h = p.geometryIdle) : s.showAll || g ? (E = mt(p.cutoutActive), h = p.geometryActive) : (E = mt(p.cutoutInactive), h = p.geometryInactive);
1003
+ const x = h ?? {
908
1004
  fill: "rgba(37, 99, 235, 0.15)",
909
1005
  stroke: "rgba(37, 99, 235, 0.6)",
910
1006
  strokeWidth: 2
911
- }, M = D(
1007
+ }, $ = F(
912
1008
  () => ({
913
1009
  id: t,
914
- label: o,
915
- bounds: T,
916
- isActive: f,
917
- isHovered: g,
918
- isSelected: w,
919
- effect: h
1010
+ label: n,
1011
+ bounds: b,
1012
+ isActive: g,
1013
+ isHovered: m,
1014
+ isSelected: v,
1015
+ effect: p
920
1016
  }),
921
- [t, o, T, f, g, w, h]
1017
+ [t, n, b, g, m, v, p]
922
1018
  );
923
- return /* @__PURE__ */ C.jsxs(K.Provider, { value: M, children: [
924
- /* @__PURE__ */ C.jsx(
1019
+ return /* @__PURE__ */ I.jsxs(tt.Provider, { value: $, children: [
1020
+ /* @__PURE__ */ I.jsx(
925
1021
  "div",
926
1022
  {
927
1023
  "data-cutout-id": t,
@@ -929,11 +1025,11 @@ function Ft({
929
1025
  pointerEvents: "none",
930
1026
  position: "absolute",
931
1027
  inset: 0,
932
- zIndex: f ? 20 : 10,
933
- transition: h.transition,
934
- ...j
1028
+ zIndex: g ? 20 : 10,
1029
+ transition: p.transition,
1030
+ ...E
935
1031
  },
936
- children: l ? l({ isActive: f, isHovered: g, isSelected: w, bounds: T, effect: h }) : /* @__PURE__ */ C.jsx(
1032
+ children: l ? l({ isActive: g, isHovered: m, isSelected: v, bounds: b, effect: p }) : /* @__PURE__ */ I.jsx(
937
1033
  "svg",
938
1034
  {
939
1035
  viewBox: "0 0 1 1",
@@ -944,25 +1040,25 @@ function Ft({
944
1040
  width: "100%",
945
1041
  height: "100%",
946
1042
  overflow: "visible",
947
- filter: b.glow ? `drop-shadow(${b.glow.split(",")[0]?.trim() ?? ""})` : "none"
1043
+ filter: x.glow ? `drop-shadow(${x.glow.split(",")[0]?.trim() ?? ""})` : "none"
948
1044
  },
949
- children: /* @__PURE__ */ C.jsx(
1045
+ children: /* @__PURE__ */ I.jsx(
950
1046
  "rect",
951
1047
  {
952
- x: T.x,
953
- y: T.y,
954
- width: T.w,
955
- height: T.h,
1048
+ x: b.x,
1049
+ y: b.y,
1050
+ width: b.w,
1051
+ height: b.h,
956
1052
  rx: 4e-3,
957
- fill: b.fill,
958
- stroke: b.stroke,
959
- strokeWidth: (b.strokeWidth ?? 2) * 15e-4,
960
- strokeLinecap: b.strokeDasharray ? "round" : void 0,
961
- strokeDasharray: b.strokeDasharray,
962
- pathLength: b.strokeDasharray ? 1 : void 0,
1053
+ fill: x.fill,
1054
+ stroke: x.stroke,
1055
+ strokeWidth: (x.strokeWidth ?? 2) * 15e-4,
1056
+ strokeLinecap: x.strokeDasharray ? "round" : void 0,
1057
+ strokeDasharray: x.strokeDasharray,
1058
+ pathLength: x.strokeDasharray ? 1 : void 0,
963
1059
  style: {
964
- transition: h.transition,
965
- animation: b.animation
1060
+ transition: p.transition,
1061
+ animation: x.animation
966
1062
  }
967
1063
  }
968
1064
  )
@@ -970,49 +1066,49 @@ function Ft({
970
1066
  )
971
1067
  }
972
1068
  ),
973
- a
1069
+ i
974
1070
  ] });
975
1071
  }
976
1072
  function yt(t) {
977
- const { filter: r, ...o } = t;
978
- return o;
1073
+ const { filter: e, ...n } = t;
1074
+ return n;
979
1075
  }
980
- function zt({
1076
+ function qt({
981
1077
  id: t,
982
- points: r,
983
- label: o,
984
- effect: n,
985
- children: a,
1078
+ points: e,
1079
+ label: n,
1080
+ effect: r,
1081
+ children: i,
986
1082
  renderLayer: l
987
1083
  }) {
988
- const i = F(et), s = rt();
989
- if (!i)
1084
+ const a = z(Q), s = ot();
1085
+ if (!a)
990
1086
  throw new Error(
991
1087
  "<CutoutViewer.PolygonCutout> must be used inside <CutoutViewer>"
992
1088
  );
993
- const d = r.flat().join(",");
994
- N(() => (i.registerCutout({ type: "polygon", id: t, points: r, label: o }), () => i.unregisterCutout(t)), [t, d, o, i]);
995
- const u = n ? typeof n == "string" ? q[n] ?? s.effect : n : s.effect, p = s.activeId === t, R = s.hoveredId === t, h = s.selectedId === t, f = { x: 0, y: 0, w: 1, h: 1 }, g = s.boundsMap[t] ?? f;
996
- let w, S;
997
- !s.enabled || !s.isAnyActive && !s.showAll ? (S = { ...u.cutoutIdle, filter: "none", opacity: 0 }, w = u.geometryIdle) : s.showAll || p ? (S = yt(u.cutoutActive), w = u.geometryActive) : (S = yt(u.cutoutInactive), w = u.geometryInactive);
998
- const m = w ?? {
1089
+ const u = e.flat().join(",");
1090
+ O(() => (a.registerCutout({ type: "polygon", id: t, points: e, label: n }), () => a.unregisterCutout(t)), [t, u, n, a]);
1091
+ const c = r ? typeof r == "string" ? K[r] ?? s.effect : r : s.effect, d = s.activeId === t, k = s.hoveredId === t, p = s.selectedId === t, g = { x: 0, y: 0, w: 1, h: 1 }, m = s.boundsMap[t] ?? g;
1092
+ let v, f;
1093
+ !s.enabled || !s.isAnyActive && !s.showAll ? (f = { ...c.cutoutIdle, filter: "none", opacity: 0 }, v = c.geometryIdle) : s.showAll || d ? (f = yt(c.cutoutActive), v = c.geometryActive) : (f = yt(c.cutoutInactive), v = c.geometryInactive);
1094
+ const h = v ?? {
999
1095
  fill: "rgba(37, 99, 235, 0.15)",
1000
1096
  stroke: "rgba(37, 99, 235, 0.6)",
1001
1097
  strokeWidth: 2
1002
- }, j = D(
1098
+ }, E = F(
1003
1099
  () => ({
1004
1100
  id: t,
1005
- label: o,
1006
- bounds: g,
1007
- isActive: p,
1008
- isHovered: R,
1009
- isSelected: h,
1010
- effect: u
1101
+ label: n,
1102
+ bounds: m,
1103
+ isActive: d,
1104
+ isHovered: k,
1105
+ isSelected: p,
1106
+ effect: c
1011
1107
  }),
1012
- [t, o, g, p, R, h, u]
1108
+ [t, n, m, d, k, p, c]
1013
1109
  );
1014
- return /* @__PURE__ */ C.jsxs(K.Provider, { value: j, children: [
1015
- /* @__PURE__ */ C.jsx(
1110
+ return /* @__PURE__ */ I.jsxs(tt.Provider, { value: E, children: [
1111
+ /* @__PURE__ */ I.jsx(
1016
1112
  "div",
1017
1113
  {
1018
1114
  "data-cutout-id": t,
@@ -1020,11 +1116,11 @@ function zt({
1020
1116
  pointerEvents: "none",
1021
1117
  position: "absolute",
1022
1118
  inset: 0,
1023
- zIndex: p ? 20 : 10,
1024
- transition: u.transition,
1025
- ...S
1119
+ zIndex: d ? 20 : 10,
1120
+ transition: c.transition,
1121
+ ...f
1026
1122
  },
1027
- children: l ? l({ isActive: p, isHovered: R, isSelected: h, bounds: g, effect: u }) : /* @__PURE__ */ C.jsx(
1123
+ children: l ? l({ isActive: d, isHovered: k, isSelected: p, bounds: m, effect: c }) : /* @__PURE__ */ I.jsx(
1028
1124
  "svg",
1029
1125
  {
1030
1126
  viewBox: "0 0 1 1",
@@ -1035,22 +1131,22 @@ function zt({
1035
1131
  width: "100%",
1036
1132
  height: "100%",
1037
1133
  overflow: "visible",
1038
- filter: m.glow ? `drop-shadow(${m.glow.split(",")[0]?.trim() ?? ""})` : "none"
1134
+ filter: h.glow ? `drop-shadow(${h.glow.split(",")[0]?.trim() ?? ""})` : "none"
1039
1135
  },
1040
- children: /* @__PURE__ */ C.jsx(
1136
+ children: /* @__PURE__ */ I.jsx(
1041
1137
  "polygon",
1042
1138
  {
1043
- points: r.map(([P, b]) => `${P},${b}`).join(" "),
1044
- fill: m.fill,
1045
- stroke: m.stroke,
1046
- strokeWidth: (m.strokeWidth ?? 2) * 15e-4,
1139
+ points: e.map(([w, x]) => `${w},${x}`).join(" "),
1140
+ fill: h.fill,
1141
+ stroke: h.stroke,
1142
+ strokeWidth: (h.strokeWidth ?? 2) * 15e-4,
1047
1143
  strokeLinejoin: "round",
1048
- strokeLinecap: m.strokeDasharray ? "round" : void 0,
1049
- strokeDasharray: m.strokeDasharray,
1050
- pathLength: m.strokeDasharray ? 1 : void 0,
1144
+ strokeLinecap: h.strokeDasharray ? "round" : void 0,
1145
+ strokeDasharray: h.strokeDasharray,
1146
+ pathLength: h.strokeDasharray ? 1 : void 0,
1051
1147
  style: {
1052
- transition: u.transition,
1053
- animation: m.animation
1148
+ transition: c.transition,
1149
+ animation: h.animation
1054
1150
  }
1055
1151
  }
1056
1152
  )
@@ -1058,51 +1154,245 @@ function zt({
1058
1154
  )
1059
1155
  }
1060
1156
  ),
1061
- a
1157
+ i
1062
1158
  ] });
1063
1159
  }
1064
- function Lt(t, r) {
1065
- const { x: o, y: n, w: a, h: l } = r;
1066
- let i, s;
1067
- t.includes("left") ? (i = `${o * 100}%`, s = "0") : t.includes("right") ? (i = `${(o + a) * 100}%`, s = "-100%") : (i = `${(o + a / 2) * 100}%`, s = "-50%");
1068
- let d, u;
1069
- return t.startsWith("top") ? (d = `${n * 100}%`, u = "-100%") : t.startsWith("bottom") ? (d = `${(n + l) * 100}%`, u = "0") : (d = `${(n + l / 2) * 100}%`, u = "-50%"), {
1160
+ function Gt(t, e) {
1161
+ const { x: n, y: r, w: i, h: l } = e;
1162
+ let a, s;
1163
+ t.includes("left") ? (a = `${n * 100}%`, s = "0") : t.includes("right") ? (a = `${(n + i) * 100}%`, s = "-100%") : (a = `${(n + i / 2) * 100}%`, s = "-50%");
1164
+ let u, c;
1165
+ return t.startsWith("top") ? (u = `${r * 100}%`, c = "-100%") : t.startsWith("bottom") ? (u = `${(r + l) * 100}%`, c = "0") : (u = `${(r + l / 2) * 100}%`, c = "-50%"), {
1070
1166
  position: "absolute",
1071
- left: i,
1072
- top: d,
1073
- transform: `translate(${s}, ${u})`
1167
+ left: a,
1168
+ top: u,
1169
+ transform: `translate(${s}, ${c})`
1074
1170
  };
1075
1171
  }
1076
- function Ut({
1172
+ function Jt({
1077
1173
  placement: t = "top-center",
1078
- children: r,
1079
- className: o = "",
1080
- style: n
1174
+ children: e,
1175
+ className: n = "",
1176
+ style: r
1081
1177
  }) {
1082
- const a = F(K), l = rt();
1083
- if (!a)
1178
+ const i = z(tt), l = ot();
1179
+ if (!i)
1084
1180
  throw new Error(
1085
1181
  "<CutoutViewer.Overlay> must be used inside <CutoutViewer.Cutout>"
1086
1182
  );
1087
- const i = l.enabled && (l.showAll || a.isActive), s = Lt(t, a.bounds);
1088
- return /* @__PURE__ */ C.jsx(
1183
+ const a = l.enabled && (l.showAll || i.isActive), s = Gt(t, i.bounds);
1184
+ return /* @__PURE__ */ I.jsx(
1089
1185
  "div",
1090
1186
  {
1091
1187
  "data-cutout-overlay": "true",
1092
- className: o,
1188
+ className: n,
1093
1189
  style: {
1094
1190
  zIndex: 30,
1095
- transition: a.effect.transition,
1096
- opacity: i ? 1 : 0,
1097
- pointerEvents: i ? "auto" : "none",
1191
+ transition: i.effect.transition,
1192
+ opacity: a ? 1 : 0,
1193
+ pointerEvents: a ? "auto" : "none",
1098
1194
  ...s,
1099
- ...n
1195
+ ...r
1196
+ },
1197
+ children: e
1198
+ }
1199
+ );
1200
+ }
1201
+ function Kt({
1202
+ onComplete: t,
1203
+ minPoints: e = 3,
1204
+ closeThreshold: n = 0.03
1205
+ }) {
1206
+ const [r, i] = L([]), [l, a] = L(null), s = B(null), u = P(
1207
+ (h, E) => {
1208
+ const w = s.current;
1209
+ if (!w) return null;
1210
+ const x = w.getBoundingClientRect(), $ = (h - x.left) / x.width, N = (E - x.top) / x.height;
1211
+ return $ < 0 || $ > 1 || N < 0 || N > 1 ? null : [$, N];
1212
+ },
1213
+ []
1214
+ ), c = P(
1215
+ (h, E) => {
1216
+ if (E.length < e) return !1;
1217
+ const w = h[0] - E[0][0], x = h[1] - E[0][1];
1218
+ return Math.sqrt(w * w + x * x) < n;
1219
+ },
1220
+ [e, n]
1221
+ ), d = P(
1222
+ (h) => {
1223
+ h.length < e || (t(h), i([]), a(null));
1224
+ },
1225
+ [t, e]
1226
+ ), k = P(() => {
1227
+ i([]), a(null);
1228
+ }, []), p = P(
1229
+ (h) => {
1230
+ a(u(h.clientX, h.clientY));
1231
+ },
1232
+ [u]
1233
+ ), g = P(() => {
1234
+ a(null);
1235
+ }, []), m = P(
1236
+ (h) => {
1237
+ h.stopPropagation();
1238
+ const E = u(h.clientX, h.clientY);
1239
+ E && i((w) => c(E, w) ? (d(w), []) : [...w, E]);
1240
+ },
1241
+ [u, c, d]
1242
+ ), v = P(
1243
+ (h) => {
1244
+ h.stopPropagation(), i((E) => {
1245
+ const w = E.slice(0, -1);
1246
+ return w.length >= e ? (d(w), []) : w;
1247
+ });
1248
+ },
1249
+ [e, d]
1250
+ ), f = P(
1251
+ (h) => {
1252
+ h.preventDefault(), i((E) => E.slice(0, -1));
1253
+ },
1254
+ []
1255
+ ), b = l !== null && c(l, r);
1256
+ return {
1257
+ points: r,
1258
+ previewPoint: l,
1259
+ willClose: b,
1260
+ reset: k,
1261
+ containerRef: s,
1262
+ containerProps: {
1263
+ onPointerMove: p,
1264
+ onPointerLeave: g,
1265
+ onClick: m,
1266
+ onDoubleClick: v,
1267
+ onContextMenu: f
1268
+ }
1269
+ };
1270
+ }
1271
+ function Zt({
1272
+ onComplete: t,
1273
+ minPoints: e = 3,
1274
+ closeThreshold: n = 0.03,
1275
+ strokeColor: r = "#3b82f6",
1276
+ enabled: i = !0,
1277
+ style: l,
1278
+ className: a = ""
1279
+ }) {
1280
+ if (!z(Q))
1281
+ throw new Error(
1282
+ "<CutoutViewer.DrawPolygon> must be used inside <CutoutViewer>"
1283
+ );
1284
+ const {
1285
+ points: u,
1286
+ previewPoint: c,
1287
+ willClose: d,
1288
+ reset: k,
1289
+ containerRef: p,
1290
+ containerProps: g
1291
+ } = Kt({ onComplete: t, minPoints: e, closeThreshold: n });
1292
+ O(() => {
1293
+ function f(b) {
1294
+ b.key === "Escape" && k();
1295
+ }
1296
+ return document.addEventListener("keydown", f), () => document.removeEventListener("keydown", f);
1297
+ }, [k]), O(() => {
1298
+ i || k();
1299
+ }, [i, k]);
1300
+ const m = c ? [...u, c] : u, v = m.map(([f, b]) => `${f},${b}`).join(" ");
1301
+ return /* @__PURE__ */ I.jsx(
1302
+ "div",
1303
+ {
1304
+ ref: p,
1305
+ "data-draw-polygon": "true",
1306
+ className: a,
1307
+ style: {
1308
+ position: "absolute",
1309
+ inset: 0,
1310
+ cursor: i ? d ? "cell" : "crosshair" : "default",
1311
+ zIndex: 30,
1312
+ pointerEvents: i ? "auto" : "none",
1313
+ ...l
1100
1314
  },
1101
- children: r
1315
+ ...i ? g : {},
1316
+ children: u.length > 0 && /* @__PURE__ */ I.jsxs(
1317
+ "svg",
1318
+ {
1319
+ viewBox: "0 0 1 1",
1320
+ preserveAspectRatio: "none",
1321
+ style: {
1322
+ position: "absolute",
1323
+ inset: 0,
1324
+ width: "100%",
1325
+ height: "100%",
1326
+ overflow: "visible",
1327
+ pointerEvents: "none"
1328
+ },
1329
+ children: [
1330
+ u.length >= 3 && /* @__PURE__ */ I.jsx(
1331
+ "polygon",
1332
+ {
1333
+ points: u.map(([f, b]) => `${f},${b}`).join(" "),
1334
+ fill: r,
1335
+ fillOpacity: 0.15,
1336
+ stroke: "none"
1337
+ }
1338
+ ),
1339
+ m.length >= 2 && /* @__PURE__ */ I.jsx(
1340
+ "polyline",
1341
+ {
1342
+ points: v,
1343
+ fill: "none",
1344
+ stroke: r,
1345
+ strokeWidth: 3e-3,
1346
+ strokeLinecap: "round",
1347
+ strokeLinejoin: "round",
1348
+ strokeDasharray: c ? "0.015 0.008" : void 0
1349
+ }
1350
+ ),
1351
+ c && u.length >= 1 && /* @__PURE__ */ I.jsx(
1352
+ "line",
1353
+ {
1354
+ x1: c[0],
1355
+ y1: c[1],
1356
+ x2: u[0][0],
1357
+ y2: u[0][1],
1358
+ stroke: r,
1359
+ strokeWidth: 2e-3,
1360
+ strokeDasharray: "0.015 0.008",
1361
+ strokeLinecap: "round",
1362
+ opacity: d ? 0.9 : 0.35
1363
+ }
1364
+ ),
1365
+ u.map(([f, b], h) => /* @__PURE__ */ I.jsx(
1366
+ "circle",
1367
+ {
1368
+ cx: f,
1369
+ cy: b,
1370
+ r: h === 0 ? 0.012 : 7e-3,
1371
+ fill: h === 0 && d ? r : "white",
1372
+ stroke: r,
1373
+ strokeWidth: 2e-3
1374
+ },
1375
+ h
1376
+ )),
1377
+ c && /* @__PURE__ */ I.jsx(
1378
+ "circle",
1379
+ {
1380
+ cx: c[0],
1381
+ cy: c[1],
1382
+ r: 5e-3,
1383
+ fill: d ? r : "white",
1384
+ stroke: r,
1385
+ strokeWidth: 2e-3,
1386
+ opacity: 0.8
1387
+ }
1388
+ )
1389
+ ]
1390
+ }
1391
+ )
1102
1392
  }
1103
1393
  );
1104
1394
  }
1105
- function vt(t) {
1395
+ function bt(t) {
1106
1396
  switch (t.type) {
1107
1397
  case "image":
1108
1398
  return `image:${t.src}:${t.label ?? ""}`;
@@ -1112,106 +1402,107 @@ function vt(t) {
1112
1402
  return `polygon:${t.points.flat().join(",")}:${t.label ?? ""}`;
1113
1403
  }
1114
1404
  }
1115
- function Gt({
1405
+ function Qt({
1116
1406
  mainImage: t,
1117
- mainImageAlt: r = "Main image",
1118
- effect: o = "elevate",
1119
- enabled: n = !0,
1120
- showAll: a = !1,
1407
+ mainImageAlt: e = "Main image",
1408
+ effect: n = "elevate",
1409
+ enabled: r = !0,
1410
+ showAll: i = !1,
1121
1411
  alphaThreshold: l = 30,
1122
- hoverLeaveDelay: i = 150,
1412
+ hoverLeaveDelay: a = 150,
1123
1413
  children: s,
1124
- className: d = "",
1125
- style: u,
1126
- onHover: p,
1127
- onActiveChange: R,
1128
- onSelect: h
1414
+ className: u = "",
1415
+ style: c,
1416
+ onHover: d,
1417
+ onActiveChange: k,
1418
+ onSelect: p
1129
1419
  }) {
1130
- const f = typeof o == "string" ? q[o] ?? q.elevate : o;
1131
- N(() => {
1132
- Wt(f);
1133
- }, [f]);
1134
- const [g, w] = tt(() => /* @__PURE__ */ new Map()), S = O(
1135
- (_) => {
1136
- w((W) => {
1137
- const Y = W.get(_.id);
1138
- if (Y && vt(Y) === vt(_))
1420
+ const g = typeof n == "string" ? K[n] ?? K.elevate : n;
1421
+ O(() => {
1422
+ Yt(g);
1423
+ }, [g]);
1424
+ const [m, v] = L(() => /* @__PURE__ */ new Map()), f = P(
1425
+ (M) => {
1426
+ v((W) => {
1427
+ const Y = W.get(M.id);
1428
+ if (Y && bt(Y) === bt(M))
1139
1429
  return W;
1140
- const U = new Map(W);
1141
- return U.set(_.id, _), U;
1430
+ const D = new Map(W);
1431
+ return D.set(M.id, M), D;
1142
1432
  });
1143
1433
  },
1144
1434
  []
1145
- ), T = O((_) => {
1146
- w((W) => {
1147
- if (!W.has(_)) return W;
1435
+ ), b = P((M) => {
1436
+ v((W) => {
1437
+ if (!W.has(M)) return W;
1148
1438
  const Y = new Map(W);
1149
- return Y.delete(_), Y;
1439
+ return Y.delete(M), Y;
1150
1440
  });
1151
- }, []), m = D(
1152
- () => ({ registerCutout: S, unregisterCutout: T }),
1153
- [S, T]
1154
- ), j = D(() => Array.from(g.values()), [g]), { activeId: P, selectedId: b, hoveredId: M, boundsMap: V, containerRef: z, containerProps: E } = Mt(j, n, l, i), k = B(null), y = B(null), v = B(null);
1155
- N(() => {
1156
- M !== k.current && (k.current = M, p?.(M));
1157
- }, [M, p]), N(() => {
1158
- P !== y.current && (y.current = P, R?.(P));
1159
- }, [P, R]), N(() => {
1160
- b !== v.current && (v.current = b, h?.(b));
1161
- }, [b, h]);
1162
- const $ = a || P !== null, L = D(
1441
+ }, []), h = F(
1442
+ () => ({ registerCutout: f, unregisterCutout: b }),
1443
+ [f, b]
1444
+ ), E = F(() => Array.from(m.values()), [m]), { activeId: w, selectedId: x, hoveredId: $, boundsMap: N, contourMap: H, containerRef: V, containerProps: q } = Nt(E, r, l, a), X = B(null), j = B(null), R = B(null);
1445
+ O(() => {
1446
+ $ !== X.current && (X.current = $, d?.($));
1447
+ }, [$, d]), O(() => {
1448
+ w !== j.current && (j.current = w, k?.(w));
1449
+ }, [w, k]), O(() => {
1450
+ x !== R.current && (R.current = x, p?.(x));
1451
+ }, [x, p]);
1452
+ const C = i || w !== null, _ = F(
1163
1453
  () => ({
1164
- activeId: P,
1165
- selectedId: b,
1166
- hoveredId: M,
1167
- effect: f,
1168
- enabled: n,
1169
- showAll: a,
1170
- boundsMap: V,
1171
- isAnyActive: $
1454
+ activeId: w,
1455
+ selectedId: x,
1456
+ hoveredId: $,
1457
+ effect: g,
1458
+ enabled: r,
1459
+ showAll: i,
1460
+ boundsMap: N,
1461
+ contourMap: H,
1462
+ isAnyActive: C
1172
1463
  }),
1173
- [P, b, M, f, n, a, V, $]
1464
+ [w, x, $, g, r, i, N, H, C]
1174
1465
  );
1175
- return /* @__PURE__ */ C.jsx(et.Provider, { value: m, children: /* @__PURE__ */ C.jsx(xt.Provider, { value: L, children: /* @__PURE__ */ C.jsxs(
1466
+ return /* @__PURE__ */ I.jsx(Q.Provider, { value: h, children: /* @__PURE__ */ I.jsx(xt.Provider, { value: _, children: /* @__PURE__ */ I.jsxs(
1176
1467
  "div",
1177
1468
  {
1178
- ref: z,
1179
- className: d,
1469
+ ref: V,
1470
+ className: u,
1180
1471
  style: {
1181
1472
  position: "relative",
1182
1473
  width: "100%",
1183
1474
  overflow: "hidden",
1184
- cursor: $ && n ? "pointer" : "default",
1185
- ...u
1475
+ cursor: C && r ? "pointer" : "default",
1476
+ ...c
1186
1477
  },
1187
- ...E,
1478
+ ...q,
1188
1479
  children: [
1189
- /* @__PURE__ */ C.jsx(
1480
+ /* @__PURE__ */ I.jsx(
1190
1481
  "img",
1191
1482
  {
1192
1483
  src: t,
1193
- alt: r,
1484
+ alt: e,
1194
1485
  draggable: !1,
1195
1486
  style: {
1196
1487
  display: "block",
1197
1488
  width: "100%",
1198
1489
  height: "auto",
1199
1490
  userSelect: "none",
1200
- transition: f.transition,
1201
- ...$ && n ? f.mainImageHovered : {}
1491
+ transition: g.transition,
1492
+ ...C && r ? g.mainImageHovered : {}
1202
1493
  }
1203
1494
  }
1204
1495
  ),
1205
- /* @__PURE__ */ C.jsx(
1496
+ /* @__PURE__ */ I.jsx(
1206
1497
  "div",
1207
1498
  {
1208
1499
  style: {
1209
1500
  pointerEvents: "none",
1210
1501
  position: "absolute",
1211
1502
  inset: 0,
1212
- transition: f.transition,
1213
- opacity: $ && n ? 1 : 0,
1214
- ...f.vignetteStyle
1503
+ transition: g.transition,
1504
+ opacity: C && r ? 1 : 0,
1505
+ ...g.vignetteStyle
1215
1506
  }
1216
1507
  }
1217
1508
  ),
@@ -1220,26 +1511,29 @@ function Gt({
1220
1511
  }
1221
1512
  ) }) });
1222
1513
  }
1223
- const ot = Gt;
1224
- ot.Cutout = Bt;
1225
- ot.BBoxCutout = Ft;
1226
- ot.PolygonCutout = zt;
1227
- ot.Overlay = Ut;
1514
+ const et = Qt;
1515
+ et.Cutout = Xt;
1516
+ et.BBoxCutout = Ut;
1517
+ et.PolygonCutout = qt;
1518
+ et.Overlay = Jt;
1519
+ et.DrawPolygon = Zt;
1228
1520
  export {
1229
- Ut as CutoutOverlay,
1230
- ot as CutoutViewer,
1231
- Ct as ImageHitTestStrategy,
1232
- jt as PolygonHitTestStrategy,
1233
- Tt as RectHitTestStrategy,
1234
- $t as createHitTestStrategy,
1235
- it as defineKeyframes,
1236
- Ot as elevateEffect,
1237
- Nt as glowEffect,
1238
- q as hoverEffects,
1239
- Yt as liftEffect,
1521
+ Jt as CutoutOverlay,
1522
+ et as CutoutViewer,
1523
+ Zt as DrawPolygon,
1524
+ Pt as ImageHitTestStrategy,
1525
+ Dt as PolygonHitTestStrategy,
1526
+ Mt as RectHitTestStrategy,
1527
+ Wt as createHitTestStrategy,
1528
+ vt as defineKeyframes,
1529
+ Vt as elevateEffect,
1530
+ Lt as glowEffect,
1531
+ K as hoverEffects,
1532
+ Bt as liftEffect,
1240
1533
  Ht as shimmerEffect,
1241
- Dt as subtleEffect,
1242
- Vt as traceEffect,
1243
- qt as useCutout,
1244
- Mt as useCutoutHitTest
1534
+ Ft as subtleEffect,
1535
+ zt as traceEffect,
1536
+ ee as useCutout,
1537
+ Nt as useCutoutHitTest,
1538
+ Kt as useDrawPolygon
1245
1539
  };