react-img-cutout 1.1.0 → 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 F, useRef as V, useCallback as P, useMemo as B, useEffect as O, useContext as H, createContext as it } from "react";
2
- var rt = { exports: {} }, G = {};
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
3
  var ut;
4
4
  function Et() {
5
5
  if (ut) return G;
6
6
  ut = 1;
7
- var t = /* @__PURE__ */ Symbol.for("react.transitional.element"), r = /* @__PURE__ */ Symbol.for("react.fragment");
8
- function o(n, i, c) {
7
+ var t = /* @__PURE__ */ Symbol.for("react.transitional.element"), e = /* @__PURE__ */ Symbol.for("react.fragment");
8
+ function n(r, i, l) {
9
9
  var a = null;
10
- if (c !== void 0 && (a = "" + c), i.key !== void 0 && (a = "" + i.key), "key" in i) {
11
- c = {};
10
+ if (l !== void 0 && (a = "" + l), i.key !== void 0 && (a = "" + i.key), "key" in i) {
11
+ l = {};
12
12
  for (var s in i)
13
- s !== "key" && (c[s] = i[s]);
14
- } else c = i;
15
- return i = c.ref, {
13
+ s !== "key" && (l[s] = i[s]);
14
+ } else l = i;
15
+ return i = l.ref, {
16
16
  $$typeof: t,
17
- type: n,
17
+ type: r,
18
18
  key: a,
19
19
  ref: i !== void 0 ? i : null,
20
- props: c
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 q = {};
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 === R ? null : e.displayName || e.name || null;
33
- if (typeof e == "string") return e;
34
- switch (e) {
35
- case x:
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 u:
37
+ case h:
38
38
  return "Profiler";
39
- case w:
39
+ case b:
40
40
  return "StrictMode";
41
- case M:
41
+ case $:
42
42
  return "Suspense";
43
- case D:
43
+ case N:
44
44
  return "SuspenseList";
45
- case _:
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 E:
53
- return "Portal";
51
+ ), o.$$typeof) {
54
52
  case v:
55
- return e.displayName || "Context";
56
- case b:
57
- return (e._context.displayName || "Context") + ".Consumer";
58
- case m:
59
- var p = e.render;
60
- return e = e.displayName, e || (e = p.displayName || p.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
61
- case z:
62
- return p = e.displayName || null, p !== null ? p : t(e.type) || "Memo";
63
- case j:
64
- p = e._payload, e = e._init;
53
+ return "Portal";
54
+ case w:
55
+ return o.displayName || "Context";
56
+ case E:
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(p));
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 p = !1;
77
+ e(o);
78
+ var y = !1;
79
79
  } catch {
80
- p = !0;
80
+ y = !0;
81
81
  }
82
- if (p) {
83
- p = console;
84
- var C = p.error, T = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
85
- return C.call(
86
- p,
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
- T
89
- ), r(e);
88
+ S
89
+ ), e(o);
90
90
  }
91
91
  }
92
- function n(e) {
93
- if (e === x) return "<>";
94
- if (typeof e == "object" && e !== null && e.$$typeof === j)
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 p = t(e);
98
- return p ? "<" + p + ">" : "<...>";
97
+ var y = t(o);
98
+ return y ? "<" + y + ">" : "<...>";
99
99
  } catch {
100
100
  return "<...>";
101
101
  }
102
102
  }
103
103
  function i() {
104
- var e = A.A;
105
- return e === null ? null : e.getOwner();
104
+ var o = j.A;
105
+ return o === null ? null : o.getOwner();
106
106
  }
107
- function c() {
107
+ function l() {
108
108
  return Error("react-stack-top-frame");
109
109
  }
110
- function a(e) {
111
- if (W.call(e, "key")) {
112
- var p = Object.getOwnPropertyDescriptor(e, "key").get;
113
- if (p && p.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, p) {
118
- function C() {
119
- N || (N = !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
- p
121
+ y
122
122
  ));
123
123
  }
124
- C.isReactWarning = !0, Object.defineProperty(e, "key", {
125
- get: C,
124
+ A.isReactWarning = !0, Object.defineProperty(o, "key", {
125
+ get: A,
126
126
  configurable: !0
127
127
  });
128
128
  }
129
- function f() {
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 l(e, p, C, T, et, ot) {
136
- var S = C.ref;
137
- return e = {
138
- $$typeof: y,
139
- type: e,
140
- key: p,
141
- props: C,
142
- _owner: T
143
- }, (S !== void 0 ? S : 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: f
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: et
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: ot
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 d(e, p, C, T, et, ot) {
169
- var S = p.children;
170
- if (S !== void 0)
171
- if (T)
172
- if (U(S)) {
173
- for (T = 0; T < S.length; T++)
174
- k(S[T]);
175
- Object.freeze && Object.freeze(S);
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 k(S);
181
- if (W.call(p, "key")) {
182
- S = t(e);
183
- var L = Object.keys(p).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
- T = 0 < L.length ? "{key: someKey, " + L.join(": ..., ") + ": ...}" : "{key: someKey}", ct[S + T] || (L = 0 < L.length ? "{" + L.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
- T,
194
193
  S,
195
- L,
196
- S
197
- ), ct[S + T] = !0);
194
+ T,
195
+ U,
196
+ T
197
+ ), ct[T + S] = !0);
198
198
  }
199
- if (S = null, C !== void 0 && (o(C), S = "" + C), a(p) && (o(p.key), S = "" + p.key), "key" in p) {
200
- C = {};
201
- for (var st in p)
202
- st !== "key" && (C[st] = p[st]);
203
- } else C = p;
204
- return S && s(
205
- C,
206
- typeof e == "function" ? e.displayName || e.name || "Unknown" : e
207
- ), l(
208
- e,
209
- S,
210
- C,
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,
210
+ A,
211
211
  i(),
212
- et,
213
- ot
212
+ rt,
213
+ st
214
214
  );
215
215
  }
216
- function k(e) {
217
- g(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === j && (e._payload.status === "fulfilled" ? g(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 g(e) {
220
- return typeof e == "object" && e !== null && e.$$typeof === y;
219
+ function p(o) {
220
+ return typeof o == "object" && o !== null && o.$$typeof === m;
221
221
  }
222
- var h = kt, y = /* @__PURE__ */ Symbol.for("react.transitional.element"), E = /* @__PURE__ */ Symbol.for("react.portal"), x = /* @__PURE__ */ Symbol.for("react.fragment"), w = /* @__PURE__ */ Symbol.for("react.strict_mode"), u = /* @__PURE__ */ Symbol.for("react.profiler"), b = /* @__PURE__ */ Symbol.for("react.consumer"), v = /* @__PURE__ */ Symbol.for("react.context"), m = /* @__PURE__ */ Symbol.for("react.forward_ref"), M = /* @__PURE__ */ Symbol.for("react.suspense"), D = /* @__PURE__ */ Symbol.for("react.suspense_list"), z = /* @__PURE__ */ Symbol.for("react.memo"), j = /* @__PURE__ */ Symbol.for("react.lazy"), _ = /* @__PURE__ */ Symbol.for("react.activity"), R = /* @__PURE__ */ Symbol.for("react.client.reference"), A = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, W = Object.prototype.hasOwnProperty, U = 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
- h = {
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 N, Y = {}, X = h.react_stack_bottom_frame.bind(
231
- h,
232
- c
233
- )(), lt = $(n(c)), ct = {};
234
- q.Fragment = x, q.jsx = function(e, p, C) {
235
- var T = 1e4 > A.recentlyCreatedOwnerStacks++;
230
+ var M, W = {}, Y = g.react_stack_bottom_frame.bind(
231
+ g,
232
+ l
233
+ )(), D = _(r(l)), ct = {};
234
+ J.Fragment = f, J.jsx = function(o, y, A) {
235
+ var S = 1e4 > j.recentlyCreatedOwnerStacks++;
236
236
  return d(
237
- e,
238
- p,
239
- C,
237
+ o,
238
+ y,
239
+ A,
240
240
  !1,
241
- T ? Error("react-stack-top-frame") : X,
242
- T ? $(n(e)) : lt
241
+ S ? Error("react-stack-top-frame") : Y,
242
+ S ? _(r(o)) : D
243
243
  );
244
- }, q.jsxs = function(e, p, C) {
245
- var T = 1e4 > A.recentlyCreatedOwnerStacks++;
244
+ }, J.jsxs = function(o, y, A) {
245
+ var S = 1e4 > j.recentlyCreatedOwnerStacks++;
246
246
  return d(
247
- e,
248
- p,
249
- C,
247
+ o,
248
+ y,
249
+ A,
250
250
  !0,
251
- T ? Error("react-stack-top-frame") : X,
252
- T ? $(n(e)) : lt
251
+ S ? Error("react-stack-top-frame") : Y,
252
+ S ? _(r(o)) : D
253
253
  );
254
254
  };
255
- })()), q;
255
+ })()), J;
256
256
  }
257
257
  var dt;
258
- function Rt() {
259
- return dt || (dt = 1, process.env.NODE_ENV === "production" ? rt.exports = Et() : rt.exports = It()), rt.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);
270
+ }
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];
284
+ }
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;
260
311
  }
261
- var I = Rt();
262
- function At(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;
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;
267
329
  }
268
- function Ct(t, r, o, n) {
269
- if (r <= 0 || o <= 0) return { x: 0, y: 0, w: 1, h: 1 };
270
- let i = r, c = o, a = 0, s = 0, f = !1;
271
- for (let l = 0; l < o; l++)
272
- for (let d = 0; d < r; d++)
273
- t[l * r + d] > n && (d < i && (i = d), d > a && (a = d), l < c && (c = l), l > s && (s = l), f = !0);
274
- return f ? {
275
- x: i / r,
276
- y: c / o,
277
- w: (a - i + 1) / r,
278
- h: (s - c + 1) / o
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 _t {
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 _t {
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 _t {
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((a) => {
313
- r.onload = () => a(), r.onerror = () => a();
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;
384
+ const n = e.naturalWidth, r = e.naturalHeight;
385
+ if (n <= 0 || r <= 0) return;
317
386
  const i = document.createElement("canvas");
318
- i.width = o, i.height = n;
319
- const c = i.getContext("2d", { willReadFrequently: !0 });
320
- if (c)
387
+ i.width = n, i.height = r;
388
+ const l = i.getContext("2d", { willReadFrequently: !0 });
389
+ if (l)
321
390
  try {
322
- c.drawImage(r, 0, 0);
323
- const a = c.getImageData(0, 0, o, n);
324
- this.alpha = At(a.data, o * n), this.width = o, this.height = n, this.bounds = Ct(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 _t {
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 i = Math.min(this.width - 1, Math.max(0, Math.floor(r * this.width))), c = 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[c * this.width + i] > this.threshold;
421
+ return this.alpha[l * this.width + i] > this.threshold;
353
422
  }
354
423
  }
355
- class jt {
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 Tt(t, r, o) {
367
- let n = !1;
368
- for (let i = 0, c = o.length - 1; i < o.length; c = i++) {
369
- const a = o[i][0], s = o[i][1], f = o[c][0], l = o[c][1];
370
- s > r != l > r && t < (f - a) * (r - s) / (l - s) + a && (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 St {
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, i = -1 / 0, c = -1 / 0;
381
- for (const [a, s] of r.points)
382
- a < o && (o = a), a > i && (i = a), s < n && (n = s), s > c && (c = 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: i - o,
387
- h: c - 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 St {
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 : Tt(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 Pt(t, r) {
476
+ function Wt(t, e) {
408
477
  switch (t.type) {
409
478
  case "image":
410
- return new _t(t, r);
479
+ return new Pt(t, e);
411
480
  case "bbox":
412
- return new jt(t);
481
+ return new Mt(t);
413
482
  case "polygon":
414
- return new St(t);
483
+ return new Dt(t);
415
484
  }
416
485
  }
417
- function $t(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 $t(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 [i, c] = F(null), [a, s] = F(null), f = V(null), l = V([]), [d, k] = F({}), g = Math.min(255, Math.max(0, o)), h = V(null), y = P(() => {
429
- h.current === null && (h.current = setTimeout(() => {
430
- h.current = null, c(null);
431
- }, n));
432
- }, [n]), E = P(() => {
433
- h.current !== null && (clearTimeout(h.current), h.current = null);
434
- }, []), x = t.map($t).join("|"), w = B(() => t, [x]);
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]);
435
504
  O(() => {
436
- if (!r) {
437
- l.current = [];
505
+ if (!e) {
506
+ c.current = [];
438
507
  return;
439
508
  }
440
- let j = !1, _ = [];
441
- async function R() {
442
- const A = [], W = {};
443
- for (const U of w) {
444
- const $ = Pt(U, g);
445
- if ($.prepare && await $.prepare(), j) return;
446
- A.push($), W[$.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
- j || (_ = A, l.current = A, k(W));
517
+ j || (R = _, c.current = _, k(M), g(W));
449
518
  }
450
- return R(), () => {
519
+ return C(), () => {
451
520
  j = !0;
452
- for (const A of _)
453
- A.dispose?.();
521
+ for (const _ of R)
522
+ _.dispose?.();
454
523
  };
455
- }, [w, r, g]);
456
- const u = P(
457
- (j, _) => {
458
- const R = l.current;
459
- for (let A = R.length - 1; A >= 0; A--)
460
- if (R[A].hitTest(j, _))
461
- return R[A].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
- ), b = P(
534
+ ), x = P(
466
535
  (j) => {
467
- const _ = f.current;
468
- if (!_) return null;
469
- const R = _.getBoundingClientRect(), A = (j.clientX - R.left) / R.width, W = (j.clientY - R.top) / R.height;
470
- return A < 0 || A > 1 || W < 0 || W > 1 ? null : { nx: A, ny: W };
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
- ), v = P(
542
+ ), $ = P(
474
543
  (j) => {
475
- if (!r) return;
476
- const _ = b(j);
477
- if (!_) {
478
- y();
544
+ if (!e) return;
545
+ const R = x(j);
546
+ if (!R) {
547
+ f();
479
548
  return;
480
549
  }
481
- const R = u(_.nx, _.ny);
482
- if (R === null) {
550
+ const C = w(R.nx, R.ny);
551
+ if (C === null) {
483
552
  if (j.target?.closest('[data-cutout-overlay="true"]')) {
484
- E();
553
+ b();
485
554
  return;
486
555
  }
487
- y();
556
+ f();
488
557
  return;
489
558
  }
490
- E(), c(R);
559
+ b(), l(C);
491
560
  },
492
- [r, b, u, y, E]
493
- ), m = P(() => {
494
- y();
495
- }, [y]), M = P(
561
+ [e, x, w, f, b]
562
+ ), N = P(() => {
563
+ f();
564
+ }, [f]), H = P(
496
565
  (j) => {
497
- if (!r) return;
498
- const _ = b(j);
499
- if (!_) {
566
+ if (!e) return;
567
+ const R = x(j);
568
+ if (!R) {
500
569
  s(null);
501
570
  return;
502
571
  }
503
- const R = u(_.nx, _.ny);
504
- s(R === a || R === null ? null : R);
572
+ const C = w(R.nx, R.ny);
573
+ s(C === a || C === null ? null : C);
505
574
  },
506
- [r, b, u, a]
507
- ), D = a ?? i, z = r ? d : {};
575
+ [e, x, w, a]
576
+ ), V = a ?? i, q = e ? d : {}, X = e ? p : {};
508
577
  return O(() => () => {
509
- E();
510
- }, [E]), {
578
+ b();
579
+ }, [b]), {
511
580
  hoveredId: i,
512
581
  selectedId: a,
513
- activeId: D,
514
- boundsMap: z,
515
- containerRef: f,
582
+ activeId: V,
583
+ boundsMap: q,
584
+ contourMap: X,
585
+ containerRef: u,
516
586
  containerProps: {
517
- onPointerMove: v,
518
- onPointerLeave: m,
519
- onClick: M
587
+ onPointerMove: $,
588
+ onPointerLeave: N,
589
+ onClick: H
520
590
  }
521
591
  };
522
592
  }
523
- function at(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 K = "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: K,
610
+ transition: Z,
541
611
  mainImageHovered: {
542
612
  filter: "brightness(0.45) saturate(0.7)"
543
613
  },
@@ -575,9 +645,9 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
575
645
  stroke: "transparent",
576
646
  strokeWidth: 1
577
647
  }
578
- }, Dt = {
648
+ }, Lt = {
579
649
  name: "glow",
580
- transition: K,
650
+ transition: Z,
581
651
  mainImageHovered: {
582
652
  filter: "brightness(0.55) saturate(0.8)"
583
653
  },
@@ -615,9 +685,9 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
615
685
  stroke: "transparent",
616
686
  strokeWidth: 1
617
687
  }
618
- }, Nt = {
688
+ }, Bt = {
619
689
  name: "lift",
620
- transition: K,
690
+ transition: Z,
621
691
  mainImageHovered: {
622
692
  filter: "brightness(0.4)"
623
693
  },
@@ -655,7 +725,7 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
655
725
  stroke: "transparent",
656
726
  strokeWidth: 1
657
727
  }
658
- }, Yt = {
728
+ }, Ft = {
659
729
  name: "subtle",
660
730
  transition: "all 0.3s ease",
661
731
  mainImageHovered: {
@@ -694,21 +764,14 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
694
764
  stroke: "transparent",
695
765
  strokeWidth: 1
696
766
  }
697
- }, ht = at(
767
+ }, gt = vt(
698
768
  "_ricut-trace-stroke",
699
769
  `from { stroke-dashoffset: 0; }
700
770
  to { stroke-dashoffset: -1; }`
701
- ), gt = at(
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: K,
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 K = "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 K = "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 K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
749
811
  stroke: "transparent",
750
812
  strokeWidth: 1
751
813
  }
752
- }, mt = at(
814
+ }, pt = vt(
753
815
  "_ricut-shimmer",
754
816
  `0%, 100% {
755
817
  filter: brightness(1.05) contrast(1.02)
@@ -766,10 +828,10 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
766
828
  drop-shadow(0 0 6px rgba(255, 255, 255, 0.12))
767
829
  drop-shadow(0 12px 32px rgba(0, 0, 0, 0.4));
768
830
  }`
769
- ), Bt = {
831
+ ), Ht = {
770
832
  name: "shimmer",
771
- transition: K,
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 K = "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 K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
810
872
  stroke: "transparent",
811
873
  strokeWidth: 1
812
874
  }
813
- }, J = {
814
- elevate: Ot,
815
- glow: Dt,
816
- lift: Nt,
817
- subtle: Yt,
818
- trace: Vt,
819
- shimmer: Bt
820
- }, Z = it(null), xt = it(null);
821
- function nt() {
822
- const t = H(xt);
875
+ }, K = {
876
+ elevate: Vt,
877
+ glow: Lt,
878
+ lift: Bt,
879
+ subtle: Ft,
880
+ trace: zt,
881
+ shimmer: Ht
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 Q = it(null);
827
- function Kt() {
828
- const t = H(Q);
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 Ht({ id: t, src: r, label: o, effect: n, children: i, renderLayer: c }) {
834
- const a = H(Z), s = nt();
895
+ function Xt({ id: t, src: e, label: n, effect: r, children: i, renderLayer: l }) {
896
+ const a = z(Q), s = ot();
835
897
  if (!a)
836
898
  throw new Error("<CutoutViewer.Cutout> must be used inside <CutoutViewer>");
837
- O(() => (a.registerCutout({ type: "image", id: t, src: r, label: o }), () => a.unregisterCutout(t)), [t, r, o, a]);
838
- const f = n ? typeof n == "string" ? J[n] ?? s.effect : n : s.effect, l = s.activeId === t, d = s.hoveredId === t, k = s.selectedId === t, g = { x: 0, y: 0, w: 1, h: 1 }, h = s.boundsMap[t] ?? g;
839
- let y;
840
- !s.enabled || !s.isAnyActive && !s.showAll ? y = f.cutoutIdle : s.showAll || l ? y = f.cutoutActive : y = f.cutoutInactive;
841
- const E = B(
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: h,
846
- isActive: l,
847
- isHovered: d,
848
- isSelected: k,
849
- effect: f
906
+ label: n,
907
+ bounds: m,
908
+ isActive: d,
909
+ isHovered: k,
910
+ isSelected: p,
911
+ effect: u
850
912
  }),
851
- [t, o, h, l, d, k, f]
913
+ [t, n, m, d, k, p, u]
852
914
  );
853
- return /* @__PURE__ */ I.jsxs(Q.Provider, { value: E, children: [
854
- /* @__PURE__ */ I.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,68 +921,102 @@ function Ht({ id: t, src: r, label: o, effect: n, children: i, renderLayer: c })
859
921
  pointerEvents: "none",
860
922
  position: "absolute",
861
923
  inset: 0,
862
- zIndex: l ? 20 : 10,
863
- transition: f.transition,
864
- ...y
924
+ zIndex: d ? 20 : 10,
925
+ transition: u.transition,
926
+ ...v
865
927
  },
866
- children: c ? c({ isActive: l, isHovered: d, isSelected: k, bounds: h, effect: f }) : /* @__PURE__ */ I.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
978
  i
883
979
  ] });
884
980
  }
885
- function yt(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 Lt({
985
+ function Ut({
890
986
  id: t,
891
- bounds: r,
892
- label: o,
893
- effect: n,
987
+ bounds: e,
988
+ label: n,
989
+ effect: r,
894
990
  children: i,
895
- renderLayer: c
991
+ renderLayer: l
896
992
  }) {
897
- const a = H(Z), s = nt();
993
+ const a = z(Q), s = ot();
898
994
  if (!a)
899
995
  throw new Error(
900
996
  "<CutoutViewer.BBoxCutout> must be used inside <CutoutViewer>"
901
997
  );
902
- const { x: f, y: l, w: d, h: k } = r;
903
- O(() => (a.registerCutout({ type: "bbox", id: t, bounds: { x: f, y: l, w: d, h: k }, label: o }), () => a.unregisterCutout(t)), [t, f, l, d, k, o, a]);
904
- const g = n ? typeof n == "string" ? J[n] ?? s.effect : n : s.effect, h = s.activeId === t, y = s.hoveredId === t, E = s.selectedId === t, x = { x: 0, y: 0, w: 1, h: 1 }, w = s.boundsMap[t] ?? x;
905
- let u, b;
906
- !s.enabled || !s.isAnyActive && !s.showAll ? (b = { ...g.cutoutIdle, filter: "none", opacity: 0 }, u = g.geometryIdle) : s.showAll || h ? (b = yt(g.cutoutActive), u = g.geometryActive) : (b = yt(g.cutoutInactive), u = g.geometryInactive);
907
- const m = u ?? {
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 = B(
1007
+ }, $ = F(
912
1008
  () => ({
913
1009
  id: t,
914
- label: o,
915
- bounds: w,
916
- isActive: h,
917
- isHovered: y,
918
- isSelected: E,
919
- effect: g
1010
+ label: n,
1011
+ bounds: b,
1012
+ isActive: g,
1013
+ isHovered: m,
1014
+ isSelected: v,
1015
+ effect: p
920
1016
  }),
921
- [t, o, w, h, y, E, g]
1017
+ [t, n, b, g, m, v, p]
922
1018
  );
923
- return /* @__PURE__ */ I.jsxs(Q.Provider, { value: M, children: [
1019
+ return /* @__PURE__ */ I.jsxs(tt.Provider, { value: $, children: [
924
1020
  /* @__PURE__ */ I.jsx(
925
1021
  "div",
926
1022
  {
@@ -929,11 +1025,11 @@ function Lt({
929
1025
  pointerEvents: "none",
930
1026
  position: "absolute",
931
1027
  inset: 0,
932
- zIndex: h ? 20 : 10,
933
- transition: g.transition,
934
- ...b
1028
+ zIndex: g ? 20 : 10,
1029
+ transition: p.transition,
1030
+ ...E
935
1031
  },
936
- children: c ? c({ isActive: h, isHovered: y, isSelected: E, bounds: w, effect: g }) : /* @__PURE__ */ I.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 Lt({
944
1040
  width: "100%",
945
1041
  height: "100%",
946
1042
  overflow: "visible",
947
- filter: m.glow ? `drop-shadow(${m.glow.split(",")[0]?.trim() ?? ""})` : "none"
1043
+ filter: x.glow ? `drop-shadow(${x.glow.split(",")[0]?.trim() ?? ""})` : "none"
948
1044
  },
949
1045
  children: /* @__PURE__ */ I.jsx(
950
1046
  "rect",
951
1047
  {
952
- x: w.x,
953
- y: w.y,
954
- width: w.w,
955
- height: w.h,
1048
+ x: b.x,
1049
+ y: b.y,
1050
+ width: b.w,
1051
+ height: b.h,
956
1052
  rx: 4e-3,
957
- fill: m.fill,
958
- stroke: m.stroke,
959
- strokeWidth: (m.strokeWidth ?? 2) * 15e-4,
960
- strokeLinecap: m.strokeDasharray ? "round" : void 0,
961
- strokeDasharray: m.strokeDasharray,
962
- pathLength: m.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: g.transition,
965
- animation: m.animation
1060
+ transition: p.transition,
1061
+ animation: x.animation
966
1062
  }
967
1063
  }
968
1064
  )
@@ -973,45 +1069,45 @@ function Lt({
973
1069
  i
974
1070
  ] });
975
1071
  }
976
- function bt(t) {
977
- const { filter: r, ...o } = t;
978
- return o;
1072
+ function yt(t) {
1073
+ const { filter: e, ...n } = t;
1074
+ return n;
979
1075
  }
980
- function Ft({
1076
+ function qt({
981
1077
  id: t,
982
- points: r,
983
- label: o,
984
- effect: n,
1078
+ points: e,
1079
+ label: n,
1080
+ effect: r,
985
1081
  children: i,
986
- renderLayer: c
1082
+ renderLayer: l
987
1083
  }) {
988
- const a = H(Z), s = nt();
1084
+ const a = z(Q), s = ot();
989
1085
  if (!a)
990
1086
  throw new Error(
991
1087
  "<CutoutViewer.PolygonCutout> must be used inside <CutoutViewer>"
992
1088
  );
993
- const f = r.flat().join(",");
994
- O(() => (a.registerCutout({ type: "polygon", id: t, points: r, label: o }), () => a.unregisterCutout(t)), [t, f, o, a]);
995
- const l = n ? typeof n == "string" ? J[n] ?? s.effect : n : s.effect, d = s.activeId === t, k = s.hoveredId === t, g = s.selectedId === t, h = { x: 0, y: 0, w: 1, h: 1 }, y = s.boundsMap[t] ?? h;
996
- let E, x;
997
- !s.enabled || !s.isAnyActive && !s.showAll ? (x = { ...l.cutoutIdle, filter: "none", opacity: 0 }, E = l.geometryIdle) : s.showAll || d ? (x = bt(l.cutoutActive), E = l.geometryActive) : (x = bt(l.cutoutInactive), E = l.geometryInactive);
998
- const u = E ?? {
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
- }, b = B(
1098
+ }, E = F(
1003
1099
  () => ({
1004
1100
  id: t,
1005
- label: o,
1006
- bounds: y,
1101
+ label: n,
1102
+ bounds: m,
1007
1103
  isActive: d,
1008
1104
  isHovered: k,
1009
- isSelected: g,
1010
- effect: l
1105
+ isSelected: p,
1106
+ effect: c
1011
1107
  }),
1012
- [t, o, y, d, k, g, l]
1108
+ [t, n, m, d, k, p, c]
1013
1109
  );
1014
- return /* @__PURE__ */ I.jsxs(Q.Provider, { value: b, children: [
1110
+ return /* @__PURE__ */ I.jsxs(tt.Provider, { value: E, children: [
1015
1111
  /* @__PURE__ */ I.jsx(
1016
1112
  "div",
1017
1113
  {
@@ -1021,10 +1117,10 @@ function Ft({
1021
1117
  position: "absolute",
1022
1118
  inset: 0,
1023
1119
  zIndex: d ? 20 : 10,
1024
- transition: l.transition,
1025
- ...x
1120
+ transition: c.transition,
1121
+ ...f
1026
1122
  },
1027
- children: c ? c({ isActive: d, isHovered: k, isSelected: g, bounds: y, effect: l }) : /* @__PURE__ */ I.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 Ft({
1035
1131
  width: "100%",
1036
1132
  height: "100%",
1037
1133
  overflow: "visible",
1038
- filter: u.glow ? `drop-shadow(${u.glow.split(",")[0]?.trim() ?? ""})` : "none"
1134
+ filter: h.glow ? `drop-shadow(${h.glow.split(",")[0]?.trim() ?? ""})` : "none"
1039
1135
  },
1040
1136
  children: /* @__PURE__ */ I.jsx(
1041
1137
  "polygon",
1042
1138
  {
1043
- points: r.map(([v, m]) => `${v},${m}`).join(" "),
1044
- fill: u.fill,
1045
- stroke: u.stroke,
1046
- strokeWidth: (u.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: u.strokeDasharray ? "round" : void 0,
1049
- strokeDasharray: u.strokeDasharray,
1050
- pathLength: u.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: l.transition,
1053
- animation: u.animation
1148
+ transition: c.transition,
1149
+ animation: h.animation
1054
1150
  }
1055
1151
  }
1056
1152
  )
@@ -1061,151 +1157,151 @@ function Ft({
1061
1157
  i
1062
1158
  ] });
1063
1159
  }
1064
- function zt(t, r) {
1065
- const { x: o, y: n, w: i, h: c } = r;
1160
+ function Gt(t, e) {
1161
+ const { x: n, y: r, w: i, h: l } = e;
1066
1162
  let a, s;
1067
- t.includes("left") ? (a = `${o * 100}%`, s = "0") : t.includes("right") ? (a = `${(o + i) * 100}%`, s = "-100%") : (a = `${(o + i / 2) * 100}%`, s = "-50%");
1068
- let f, l;
1069
- return t.startsWith("top") ? (f = `${n * 100}%`, l = "-100%") : t.startsWith("bottom") ? (f = `${(n + c) * 100}%`, l = "0") : (f = `${(n + c / 2) * 100}%`, l = "-50%"), {
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
1167
  left: a,
1072
- top: f,
1073
- transform: `translate(${s}, ${l})`
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 i = H(Q), c = nt();
1178
+ const i = z(tt), l = ot();
1083
1179
  if (!i)
1084
1180
  throw new Error(
1085
1181
  "<CutoutViewer.Overlay> must be used inside <CutoutViewer.Cutout>"
1086
1182
  );
1087
- const a = c.enabled && (c.showAll || i.isActive), s = zt(t, i.bounds);
1183
+ const a = l.enabled && (l.showAll || i.isActive), s = Gt(t, i.bounds);
1088
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
1191
  transition: i.effect.transition,
1096
1192
  opacity: a ? 1 : 0,
1097
1193
  pointerEvents: a ? "auto" : "none",
1098
1194
  ...s,
1099
- ...n
1195
+ ...r
1100
1196
  },
1101
- children: r
1197
+ children: e
1102
1198
  }
1103
1199
  );
1104
1200
  }
1105
- function Xt({
1201
+ function Kt({
1106
1202
  onComplete: t,
1107
- minPoints: r = 3,
1108
- closeThreshold: o = 0.03
1203
+ minPoints: e = 3,
1204
+ closeThreshold: n = 0.03
1109
1205
  }) {
1110
- const [n, i] = F([]), [c, a] = F(null), s = V(null), f = P(
1111
- (u, b) => {
1112
- const v = s.current;
1113
- if (!v) return null;
1114
- const m = v.getBoundingClientRect(), M = (u - m.left) / m.width, D = (b - m.top) / m.height;
1115
- return M < 0 || M > 1 || D < 0 || D > 1 ? null : [M, D];
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];
1116
1212
  },
1117
1213
  []
1118
- ), l = P(
1119
- (u, b) => {
1120
- if (b.length < r) return !1;
1121
- const v = u[0] - b[0][0], m = u[1] - b[0][1];
1122
- return Math.sqrt(v * v + m * m) < o;
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;
1123
1219
  },
1124
- [r, o]
1220
+ [e, n]
1125
1221
  ), d = P(
1126
- (u) => {
1127
- u.length < r || (t(u), i([]), a(null));
1222
+ (h) => {
1223
+ h.length < e || (t(h), i([]), a(null));
1128
1224
  },
1129
- [t, r]
1225
+ [t, e]
1130
1226
  ), k = P(() => {
1131
1227
  i([]), a(null);
1132
- }, []), g = P(
1133
- (u) => {
1134
- a(f(u.clientX, u.clientY));
1228
+ }, []), p = P(
1229
+ (h) => {
1230
+ a(u(h.clientX, h.clientY));
1135
1231
  },
1136
- [f]
1137
- ), h = P(() => {
1232
+ [u]
1233
+ ), g = P(() => {
1138
1234
  a(null);
1139
- }, []), y = P(
1140
- (u) => {
1141
- u.stopPropagation();
1142
- const b = f(u.clientX, u.clientY);
1143
- b && i((v) => l(b, v) ? (d(v), []) : [...v, b]);
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]);
1144
1240
  },
1145
- [f, l, d]
1146
- ), E = P(
1147
- (u) => {
1148
- u.stopPropagation(), i((b) => {
1149
- const v = b.slice(0, -1);
1150
- return v.length >= r ? (d(v), []) : v;
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;
1151
1247
  });
1152
1248
  },
1153
- [r, d]
1154
- ), x = P(
1155
- (u) => {
1156
- u.preventDefault(), i((b) => b.slice(0, -1));
1249
+ [e, d]
1250
+ ), f = P(
1251
+ (h) => {
1252
+ h.preventDefault(), i((E) => E.slice(0, -1));
1157
1253
  },
1158
1254
  []
1159
- ), w = c !== null && l(c, n);
1255
+ ), b = l !== null && c(l, r);
1160
1256
  return {
1161
- points: n,
1162
- previewPoint: c,
1163
- willClose: w,
1257
+ points: r,
1258
+ previewPoint: l,
1259
+ willClose: b,
1164
1260
  reset: k,
1165
1261
  containerRef: s,
1166
1262
  containerProps: {
1167
- onPointerMove: g,
1168
- onPointerLeave: h,
1169
- onClick: y,
1170
- onDoubleClick: E,
1171
- onContextMenu: x
1263
+ onPointerMove: p,
1264
+ onPointerLeave: g,
1265
+ onClick: m,
1266
+ onDoubleClick: v,
1267
+ onContextMenu: f
1172
1268
  }
1173
1269
  };
1174
1270
  }
1175
- function Gt({
1271
+ function Zt({
1176
1272
  onComplete: t,
1177
- minPoints: r = 3,
1178
- closeThreshold: o = 0.03,
1179
- strokeColor: n = "#3b82f6",
1273
+ minPoints: e = 3,
1274
+ closeThreshold: n = 0.03,
1275
+ strokeColor: r = "#3b82f6",
1180
1276
  enabled: i = !0,
1181
- style: c,
1277
+ style: l,
1182
1278
  className: a = ""
1183
1279
  }) {
1184
- if (!H(Z))
1280
+ if (!z(Q))
1185
1281
  throw new Error(
1186
1282
  "<CutoutViewer.DrawPolygon> must be used inside <CutoutViewer>"
1187
1283
  );
1188
1284
  const {
1189
- points: f,
1190
- previewPoint: l,
1285
+ points: u,
1286
+ previewPoint: c,
1191
1287
  willClose: d,
1192
1288
  reset: k,
1193
- containerRef: g,
1194
- containerProps: h
1195
- } = Xt({ onComplete: t, minPoints: r, closeThreshold: o });
1289
+ containerRef: p,
1290
+ containerProps: g
1291
+ } = Kt({ onComplete: t, minPoints: e, closeThreshold: n });
1196
1292
  O(() => {
1197
- function x(w) {
1198
- w.key === "Escape" && k();
1293
+ function f(b) {
1294
+ b.key === "Escape" && k();
1199
1295
  }
1200
- return document.addEventListener("keydown", x), () => document.removeEventListener("keydown", x);
1296
+ return document.addEventListener("keydown", f), () => document.removeEventListener("keydown", f);
1201
1297
  }, [k]), O(() => {
1202
1298
  i || k();
1203
1299
  }, [i, k]);
1204
- const y = l ? [...f, l] : f, E = y.map(([x, w]) => `${x},${w}`).join(" ");
1300
+ const m = c ? [...u, c] : u, v = m.map(([f, b]) => `${f},${b}`).join(" ");
1205
1301
  return /* @__PURE__ */ I.jsx(
1206
1302
  "div",
1207
1303
  {
1208
- ref: g,
1304
+ ref: p,
1209
1305
  "data-draw-polygon": "true",
1210
1306
  className: a,
1211
1307
  style: {
@@ -1214,10 +1310,10 @@ function Gt({
1214
1310
  cursor: i ? d ? "cell" : "crosshair" : "default",
1215
1311
  zIndex: 30,
1216
1312
  pointerEvents: i ? "auto" : "none",
1217
- ...c
1313
+ ...l
1218
1314
  },
1219
- ...i ? h : {},
1220
- children: f.length > 0 && /* @__PURE__ */ I.jsxs(
1315
+ ...i ? g : {},
1316
+ children: u.length > 0 && /* @__PURE__ */ I.jsxs(
1221
1317
  "svg",
1222
1318
  {
1223
1319
  viewBox: "0 0 1 1",
@@ -1231,61 +1327,61 @@ function Gt({
1231
1327
  pointerEvents: "none"
1232
1328
  },
1233
1329
  children: [
1234
- f.length >= 3 && /* @__PURE__ */ I.jsx(
1330
+ u.length >= 3 && /* @__PURE__ */ I.jsx(
1235
1331
  "polygon",
1236
1332
  {
1237
- points: f.map(([x, w]) => `${x},${w}`).join(" "),
1238
- fill: n,
1333
+ points: u.map(([f, b]) => `${f},${b}`).join(" "),
1334
+ fill: r,
1239
1335
  fillOpacity: 0.15,
1240
1336
  stroke: "none"
1241
1337
  }
1242
1338
  ),
1243
- y.length >= 2 && /* @__PURE__ */ I.jsx(
1339
+ m.length >= 2 && /* @__PURE__ */ I.jsx(
1244
1340
  "polyline",
1245
1341
  {
1246
- points: E,
1342
+ points: v,
1247
1343
  fill: "none",
1248
- stroke: n,
1344
+ stroke: r,
1249
1345
  strokeWidth: 3e-3,
1250
1346
  strokeLinecap: "round",
1251
1347
  strokeLinejoin: "round",
1252
- strokeDasharray: l ? "0.015 0.008" : void 0
1348
+ strokeDasharray: c ? "0.015 0.008" : void 0
1253
1349
  }
1254
1350
  ),
1255
- l && f.length >= 1 && /* @__PURE__ */ I.jsx(
1351
+ c && u.length >= 1 && /* @__PURE__ */ I.jsx(
1256
1352
  "line",
1257
1353
  {
1258
- x1: l[0],
1259
- y1: l[1],
1260
- x2: f[0][0],
1261
- y2: f[0][1],
1262
- stroke: n,
1354
+ x1: c[0],
1355
+ y1: c[1],
1356
+ x2: u[0][0],
1357
+ y2: u[0][1],
1358
+ stroke: r,
1263
1359
  strokeWidth: 2e-3,
1264
1360
  strokeDasharray: "0.015 0.008",
1265
1361
  strokeLinecap: "round",
1266
1362
  opacity: d ? 0.9 : 0.35
1267
1363
  }
1268
1364
  ),
1269
- f.map(([x, w], u) => /* @__PURE__ */ I.jsx(
1365
+ u.map(([f, b], h) => /* @__PURE__ */ I.jsx(
1270
1366
  "circle",
1271
1367
  {
1272
- cx: x,
1273
- cy: w,
1274
- r: u === 0 ? 0.012 : 7e-3,
1275
- fill: u === 0 && d ? n : "white",
1276
- stroke: n,
1368
+ cx: f,
1369
+ cy: b,
1370
+ r: h === 0 ? 0.012 : 7e-3,
1371
+ fill: h === 0 && d ? r : "white",
1372
+ stroke: r,
1277
1373
  strokeWidth: 2e-3
1278
1374
  },
1279
- u
1375
+ h
1280
1376
  )),
1281
- l && /* @__PURE__ */ I.jsx(
1377
+ c && /* @__PURE__ */ I.jsx(
1282
1378
  "circle",
1283
1379
  {
1284
- cx: l[0],
1285
- cy: l[1],
1380
+ cx: c[0],
1381
+ cy: c[1],
1286
1382
  r: 5e-3,
1287
- fill: d ? n : "white",
1288
- stroke: n,
1383
+ fill: d ? r : "white",
1384
+ stroke: r,
1289
1385
  strokeWidth: 2e-3,
1290
1386
  opacity: 0.8
1291
1387
  }
@@ -1296,7 +1392,7 @@ function Gt({
1296
1392
  }
1297
1393
  );
1298
1394
  }
1299
- function vt(t) {
1395
+ function bt(t) {
1300
1396
  switch (t.type) {
1301
1397
  case "image":
1302
1398
  return `image:${t.src}:${t.label ?? ""}`;
@@ -1306,93 +1402,94 @@ function vt(t) {
1306
1402
  return `polygon:${t.points.flat().join(",")}:${t.label ?? ""}`;
1307
1403
  }
1308
1404
  }
1309
- function qt({
1405
+ function Qt({
1310
1406
  mainImage: t,
1311
- mainImageAlt: r = "Main image",
1312
- effect: o = "elevate",
1313
- enabled: n = !0,
1407
+ mainImageAlt: e = "Main image",
1408
+ effect: n = "elevate",
1409
+ enabled: r = !0,
1314
1410
  showAll: i = !1,
1315
- alphaThreshold: c = 30,
1411
+ alphaThreshold: l = 30,
1316
1412
  hoverLeaveDelay: a = 150,
1317
1413
  children: s,
1318
- className: f = "",
1319
- style: l,
1414
+ className: u = "",
1415
+ style: c,
1320
1416
  onHover: d,
1321
1417
  onActiveChange: k,
1322
- onSelect: g
1418
+ onSelect: p
1323
1419
  }) {
1324
- const h = typeof o == "string" ? J[o] ?? J.elevate : o;
1420
+ const g = typeof n == "string" ? K[n] ?? K.elevate : n;
1325
1421
  O(() => {
1326
- Wt(h);
1327
- }, [h]);
1328
- const [y, E] = F(() => /* @__PURE__ */ new Map()), x = P(
1329
- ($) => {
1330
- E((N) => {
1331
- const Y = N.get($.id);
1332
- if (Y && vt(Y) === vt($))
1333
- return N;
1334
- const X = new Map(N);
1335
- return X.set($.id, $), X;
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))
1429
+ return W;
1430
+ const D = new Map(W);
1431
+ return D.set(M.id, M), D;
1336
1432
  });
1337
1433
  },
1338
1434
  []
1339
- ), w = P(($) => {
1340
- E((N) => {
1341
- if (!N.has($)) return N;
1342
- const Y = new Map(N);
1343
- return Y.delete($), Y;
1435
+ ), b = P((M) => {
1436
+ v((W) => {
1437
+ if (!W.has(M)) return W;
1438
+ const Y = new Map(W);
1439
+ return Y.delete(M), Y;
1344
1440
  });
1345
- }, []), u = B(
1346
- () => ({ registerCutout: x, unregisterCutout: w }),
1347
- [x, w]
1348
- ), b = B(() => Array.from(y.values()), [y]), { activeId: v, selectedId: m, hoveredId: M, boundsMap: D, containerRef: z, containerProps: j } = Mt(b, n, c, a), _ = V(null), R = V(null), A = V(null);
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);
1349
1445
  O(() => {
1350
- M !== _.current && (_.current = M, d?.(M));
1351
- }, [M, d]), O(() => {
1352
- v !== R.current && (R.current = v, k?.(v));
1353
- }, [v, k]), O(() => {
1354
- m !== A.current && (A.current = m, g?.(m));
1355
- }, [m, g]);
1356
- const W = i || v !== null, U = B(
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(
1357
1453
  () => ({
1358
- activeId: v,
1359
- selectedId: m,
1360
- hoveredId: M,
1361
- effect: h,
1362
- enabled: n,
1454
+ activeId: w,
1455
+ selectedId: x,
1456
+ hoveredId: $,
1457
+ effect: g,
1458
+ enabled: r,
1363
1459
  showAll: i,
1364
- boundsMap: D,
1365
- isAnyActive: W
1460
+ boundsMap: N,
1461
+ contourMap: H,
1462
+ isAnyActive: C
1366
1463
  }),
1367
- [v, m, M, h, n, i, D, W]
1464
+ [w, x, $, g, r, i, N, H, C]
1368
1465
  );
1369
- return /* @__PURE__ */ I.jsx(Z.Provider, { value: u, children: /* @__PURE__ */ I.jsx(xt.Provider, { value: U, children: /* @__PURE__ */ I.jsxs(
1466
+ return /* @__PURE__ */ I.jsx(Q.Provider, { value: h, children: /* @__PURE__ */ I.jsx(xt.Provider, { value: _, children: /* @__PURE__ */ I.jsxs(
1370
1467
  "div",
1371
1468
  {
1372
- ref: z,
1373
- className: f,
1469
+ ref: V,
1470
+ className: u,
1374
1471
  style: {
1375
1472
  position: "relative",
1376
1473
  width: "100%",
1377
1474
  overflow: "hidden",
1378
- cursor: W && n ? "pointer" : "default",
1379
- ...l
1475
+ cursor: C && r ? "pointer" : "default",
1476
+ ...c
1380
1477
  },
1381
- ...j,
1478
+ ...q,
1382
1479
  children: [
1383
1480
  /* @__PURE__ */ I.jsx(
1384
1481
  "img",
1385
1482
  {
1386
1483
  src: t,
1387
- alt: r,
1484
+ alt: e,
1388
1485
  draggable: !1,
1389
1486
  style: {
1390
1487
  display: "block",
1391
1488
  width: "100%",
1392
1489
  height: "auto",
1393
1490
  userSelect: "none",
1394
- transition: h.transition,
1395
- ...W && n ? h.mainImageHovered : {}
1491
+ transition: g.transition,
1492
+ ...C && r ? g.mainImageHovered : {}
1396
1493
  }
1397
1494
  }
1398
1495
  ),
@@ -1403,9 +1500,9 @@ function qt({
1403
1500
  pointerEvents: "none",
1404
1501
  position: "absolute",
1405
1502
  inset: 0,
1406
- transition: h.transition,
1407
- opacity: W && n ? 1 : 0,
1408
- ...h.vignetteStyle
1503
+ transition: g.transition,
1504
+ opacity: C && r ? 1 : 0,
1505
+ ...g.vignetteStyle
1409
1506
  }
1410
1507
  }
1411
1508
  ),
@@ -1414,29 +1511,29 @@ function qt({
1414
1511
  }
1415
1512
  ) }) });
1416
1513
  }
1417
- const tt = qt;
1418
- tt.Cutout = Ht;
1419
- tt.BBoxCutout = Lt;
1420
- tt.PolygonCutout = Ft;
1421
- tt.Overlay = Ut;
1422
- tt.DrawPolygon = Gt;
1514
+ const et = Qt;
1515
+ et.Cutout = Xt;
1516
+ et.BBoxCutout = Ut;
1517
+ et.PolygonCutout = qt;
1518
+ et.Overlay = Jt;
1519
+ et.DrawPolygon = Zt;
1423
1520
  export {
1424
- Ut as CutoutOverlay,
1425
- tt as CutoutViewer,
1426
- Gt as DrawPolygon,
1427
- _t as ImageHitTestStrategy,
1428
- St as PolygonHitTestStrategy,
1429
- jt as RectHitTestStrategy,
1430
- Pt as createHitTestStrategy,
1431
- at as defineKeyframes,
1432
- Ot as elevateEffect,
1433
- Dt as glowEffect,
1434
- J as hoverEffects,
1435
- Nt as liftEffect,
1436
- Bt as shimmerEffect,
1437
- Yt as subtleEffect,
1438
- Vt as traceEffect,
1439
- Kt as useCutout,
1440
- Mt as useCutoutHitTest,
1441
- Xt as useDrawPolygon
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,
1533
+ Ht as shimmerEffect,
1534
+ Ft as subtleEffect,
1535
+ zt as traceEffect,
1536
+ ee as useCutout,
1537
+ Nt as useCutoutHitTest,
1538
+ Kt as useDrawPolygon
1442
1539
  };