react-img-cutout 1.1.0 → 1.3.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,454 @@
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 Ct, { useState as O, useRef as N, useCallback as M, useMemo as V, useEffect as W, useContext as Y, createContext as lt } from "react";
2
+ var st = { exports: {} }, tt = {};
3
3
  var ut;
4
- function Et() {
5
- if (ut) return G;
4
+ function Mt() {
5
+ if (ut) return tt;
6
6
  ut = 1;
7
7
  var t = /* @__PURE__ */ Symbol.for("react.transitional.element"), r = /* @__PURE__ */ Symbol.for("react.fragment");
8
- function o(n, i, c) {
9
- var a = null;
10
- if (c !== void 0 && (a = "" + c), i.key !== void 0 && (a = "" + i.key), "key" in i) {
11
- c = {};
12
- for (var s in i)
13
- s !== "key" && (c[s] = i[s]);
14
- } else c = i;
15
- return i = c.ref, {
8
+ function n(e, c, i) {
9
+ var s = null;
10
+ if (i !== void 0 && (s = "" + i), c.key !== void 0 && (s = "" + c.key), "key" in c) {
11
+ i = {};
12
+ for (var o in c)
13
+ o !== "key" && (i[o] = c[o]);
14
+ } else i = c;
15
+ return c = i.ref, {
16
16
  $$typeof: t,
17
- type: n,
18
- key: a,
19
- ref: i !== void 0 ? i : null,
20
- props: c
17
+ type: e,
18
+ key: s,
19
+ ref: c !== void 0 ? c : null,
20
+ props: i
21
21
  };
22
22
  }
23
- return G.Fragment = r, G.jsx = o, G.jsxs = o, G;
23
+ return tt.Fragment = r, tt.jsx = n, tt.jsxs = n, tt;
24
24
  }
25
- var q = {};
26
- var ft;
25
+ var et = {};
26
+ var ht;
27
27
  function It() {
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:
28
+ return ht || (ht = 1, process.env.NODE_ENV !== "production" && (function() {
29
+ function t(a) {
30
+ if (a == null) return null;
31
+ if (typeof a == "function")
32
+ return a.$$typeof === Q ? null : a.displayName || a.name || null;
33
+ if (typeof a == "string") return a;
34
+ switch (a) {
35
+ case d:
36
36
  return "Fragment";
37
- case u:
37
+ case f:
38
38
  return "Profiler";
39
- case w:
39
+ case h:
40
40
  return "StrictMode";
41
- case M:
41
+ case A:
42
42
  return "Suspense";
43
- case D:
44
- return "SuspenseList";
45
43
  case _:
44
+ return "SuspenseList";
45
+ case U:
46
46
  return "Activity";
47
47
  }
48
- if (typeof e == "object")
49
- switch (typeof e.tag == "number" && console.error(
48
+ if (typeof a == "object")
49
+ switch (typeof a.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:
51
+ ), a.$$typeof) {
52
+ case y:
53
53
  return "Portal";
54
- case v:
55
- return e.displayName || "Context";
54
+ case k:
55
+ return a.displayName || "Context";
56
+ case w:
57
+ return (a._context.displayName || "Context") + ".Consumer";
56
58
  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;
59
+ var E = a.render;
60
+ return a = a.displayName, a || (a = E.displayName || E.name || "", a = a !== "" ? "ForwardRef(" + a + ")" : "ForwardRef"), a;
61
+ case X:
62
+ return E = a.displayName || null, E !== null ? E : t(a.type) || "Memo";
63
+ case D:
64
+ E = a._payload, a = a._init;
65
65
  try {
66
- return t(e(p));
66
+ return t(a(E));
67
67
  } catch {
68
68
  }
69
69
  }
70
70
  return null;
71
71
  }
72
- function r(e) {
73
- return "" + e;
72
+ function r(a) {
73
+ return "" + a;
74
74
  }
75
- function o(e) {
75
+ function n(a) {
76
76
  try {
77
- r(e);
78
- var p = !1;
77
+ r(a);
78
+ var E = !1;
79
79
  } catch {
80
- p = !0;
80
+ E = !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 (E) {
83
+ E = console;
84
+ var j = E.error, $ = typeof Symbol == "function" && Symbol.toStringTag && a[Symbol.toStringTag] || a.constructor.name || "Object";
85
+ return j.call(
86
+ E,
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
+ $
89
+ ), r(a);
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 e(a) {
93
+ if (a === d) return "<>";
94
+ if (typeof a == "object" && a !== null && a.$$typeof === D)
95
95
  return "<...>";
96
96
  try {
97
- var p = t(e);
98
- return p ? "<" + p + ">" : "<...>";
97
+ var E = t(a);
98
+ return E ? "<" + E + ">" : "<...>";
99
99
  } catch {
100
100
  return "<...>";
101
101
  }
102
102
  }
103
- function i() {
104
- var e = A.A;
105
- return e === null ? null : e.getOwner();
106
- }
107
103
  function c() {
104
+ var a = B.A;
105
+ return a === null ? null : a.getOwner();
106
+ }
107
+ function i() {
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 s(a) {
111
+ if (q.call(a, "key")) {
112
+ var E = Object.getOwnPropertyDescriptor(a, "key").get;
113
+ if (E && E.isReactWarning) return !1;
114
114
  }
115
- return e.key !== void 0;
115
+ return a.key !== void 0;
116
116
  }
117
- function s(e, p) {
118
- function C() {
119
- N || (N = !0, console.error(
117
+ function o(a, E) {
118
+ function j() {
119
+ P || (P = !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
+ E
122
122
  ));
123
123
  }
124
- C.isReactWarning = !0, Object.defineProperty(e, "key", {
125
- get: C,
124
+ j.isReactWarning = !0, Object.defineProperty(a, "key", {
125
+ get: j,
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 l() {
130
+ var a = t(this.type);
131
+ return I[a] || (I[a] = !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
+ )), a = this.props.ref, a !== void 0 ? a : 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 u(a, E, j, $, ot, it) {
136
+ var T = j.ref;
137
+ return a = {
138
+ $$typeof: g,
139
+ type: a,
140
+ key: E,
141
+ props: j,
142
+ _owner: $
143
+ }, (T !== void 0 ? T : null) !== null ? Object.defineProperty(a, "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: l
146
+ }) : Object.defineProperty(a, "ref", { enumerable: !1, value: null }), a._store = {}, Object.defineProperty(a._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(a, "_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(a, "_debugStack", {
157
157
  configurable: !1,
158
158
  enumerable: !1,
159
159
  writable: !0,
160
- value: et
161
- }), Object.defineProperty(e, "_debugTask", {
160
+ value: ot
161
+ }), Object.defineProperty(a, "_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: it
166
+ }), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a;
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 p(a, E, j, $, ot, it) {
169
+ var T = E.children;
170
+ if (T !== void 0)
171
+ if ($)
172
+ if (S(T)) {
173
+ for ($ = 0; $ < T.length; $++)
174
+ m(T[$]);
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) {
184
- return wt !== "key";
180
+ else m(T);
181
+ if (q.call(E, "key")) {
182
+ T = t(a);
183
+ var K = Object.keys(E).filter(function(Et) {
184
+ return Et !== "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
+ $ = 0 < K.length ? "{key: someKey, " + K.join(": ..., ") + ": ...}" : "{key: someKey}", G[T + $] || (K = 0 < K.length ? "{" + K.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
+ $,
193
194
  T,
194
- S,
195
- L,
196
- S
197
- ), ct[S + T] = !0);
195
+ K,
196
+ T
197
+ ), G[T + $] = !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,
211
- i(),
212
- et,
213
- ot
199
+ if (T = null, j !== void 0 && (n(j), T = "" + j), s(E) && (n(E.key), T = "" + E.key), "key" in E) {
200
+ j = {};
201
+ for (var at in E)
202
+ at !== "key" && (j[at] = E[at]);
203
+ } else j = E;
204
+ return T && o(
205
+ j,
206
+ typeof a == "function" ? a.displayName || a.name || "Unknown" : a
207
+ ), u(
208
+ a,
209
+ T,
210
+ j,
211
+ c(),
212
+ ot,
213
+ it
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 m(a) {
217
+ v(a) ? a._store && (a._store.validated = 1) : typeof a == "object" && a !== null && a.$$typeof === D && (a._payload.status === "fulfilled" ? v(a._payload.value) && a._payload.value._store && (a._payload.value._store.validated = 1) : a._store && (a._store.validated = 1));
218
218
  }
219
- function g(e) {
220
- return typeof e == "object" && e !== null && e.$$typeof === y;
219
+ function v(a) {
220
+ return typeof a == "object" && a !== null && a.$$typeof === g;
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 x = Ct, g = /* @__PURE__ */ Symbol.for("react.transitional.element"), y = /* @__PURE__ */ Symbol.for("react.portal"), d = /* @__PURE__ */ Symbol.for("react.fragment"), h = /* @__PURE__ */ Symbol.for("react.strict_mode"), f = /* @__PURE__ */ Symbol.for("react.profiler"), w = /* @__PURE__ */ Symbol.for("react.consumer"), k = /* @__PURE__ */ Symbol.for("react.context"), b = /* @__PURE__ */ Symbol.for("react.forward_ref"), A = /* @__PURE__ */ Symbol.for("react.suspense"), _ = /* @__PURE__ */ Symbol.for("react.suspense_list"), X = /* @__PURE__ */ Symbol.for("react.memo"), D = /* @__PURE__ */ Symbol.for("react.lazy"), U = /* @__PURE__ */ Symbol.for("react.activity"), Q = /* @__PURE__ */ Symbol.for("react.client.reference"), B = x.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, q = Object.prototype.hasOwnProperty, S = Array.isArray, R = console.createTask ? console.createTask : function() {
223
223
  return null;
224
224
  };
225
- h = {
226
- react_stack_bottom_frame: function(e) {
227
- return e();
225
+ x = {
226
+ react_stack_bottom_frame: function(a) {
227
+ return a();
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++;
236
- return d(
237
- e,
238
- p,
239
- C,
230
+ var P, I = {}, z = x.react_stack_bottom_frame.bind(
231
+ x,
232
+ i
233
+ )(), L = R(e(i)), G = {};
234
+ et.Fragment = d, et.jsx = function(a, E, j) {
235
+ var $ = 1e4 > B.recentlyCreatedOwnerStacks++;
236
+ return p(
237
+ a,
238
+ E,
239
+ j,
240
240
  !1,
241
- T ? Error("react-stack-top-frame") : X,
242
- T ? $(n(e)) : lt
241
+ $ ? Error("react-stack-top-frame") : z,
242
+ $ ? R(e(a)) : L
243
243
  );
244
- }, q.jsxs = function(e, p, C) {
245
- var T = 1e4 > A.recentlyCreatedOwnerStacks++;
246
- return d(
247
- e,
248
- p,
249
- C,
244
+ }, et.jsxs = function(a, E, j) {
245
+ var $ = 1e4 > B.recentlyCreatedOwnerStacks++;
246
+ return p(
247
+ a,
248
+ E,
249
+ j,
250
250
  !0,
251
- T ? Error("react-stack-top-frame") : X,
252
- T ? $(n(e)) : lt
251
+ $ ? Error("react-stack-top-frame") : z,
252
+ $ ? R(e(a)) : L
253
253
  );
254
254
  };
255
- })()), q;
255
+ })()), et;
256
256
  }
257
- var dt;
257
+ var ft;
258
258
  function Rt() {
259
- return dt || (dt = 1, process.env.NODE_ENV === "production" ? rt.exports = Et() : rt.exports = It()), rt.exports;
259
+ return ft || (ft = 1, process.env.NODE_ENV === "production" ? st.exports = Mt() : st.exports = It()), st.exports;
260
+ }
261
+ var C = Rt();
262
+ const At = 400;
263
+ function Pt(t, r, n) {
264
+ const e = n[0] - r[0], c = n[1] - r[1], i = e * e + c * c;
265
+ if (i === 0) {
266
+ const o = t[0] - r[0], l = t[1] - r[1];
267
+ return Math.sqrt(o * o + l * l);
268
+ }
269
+ return Math.abs(e * (r[1] - t[1]) - c * (r[0] - t[0])) / Math.sqrt(i);
270
+ }
271
+ function ct(t, r) {
272
+ if (t.length <= 2) return t;
273
+ let n = 0, e = 0;
274
+ const c = t[0], i = t[t.length - 1];
275
+ for (let s = 1; s < t.length - 1; s++) {
276
+ const o = Pt(t[s], c, i);
277
+ o > n && (n = o, e = s);
278
+ }
279
+ if (n > r) {
280
+ const s = ct(t.slice(0, e + 1), r), o = ct(t.slice(e), r);
281
+ return s.slice(0, -1).concat(o);
282
+ }
283
+ return [c, i];
284
+ }
285
+ function dt(t) {
286
+ let r = 0;
287
+ const n = t.length;
288
+ for (let e = 0; e < n; e++) {
289
+ const [c, i] = t[e], [s, o] = t[(e + 1) % n];
290
+ r += c * o - s * i;
291
+ }
292
+ return r * 0.5;
293
+ }
294
+ function St(t, r) {
295
+ if (t.length <= 3 || r <= 0) return t;
296
+ const n = t.concat([t[0]]), e = ct(n, r);
297
+ return e.length < 4 ? t : (e.pop(), e.length >= 3 ? e : t);
298
+ }
299
+ const jt = [
300
+ [],
301
+ // 0 (0000)
302
+ [[3, 0]],
303
+ // 1 (0001) TL
304
+ [[0, 1]],
305
+ // 2 (0010) TR
306
+ [[3, 1]],
307
+ // 3 (0011) TL TR
308
+ [[1, 2]],
309
+ // 4 (0100) BR
310
+ [[3, 0], [1, 2]],
311
+ // 5 (0101) TL BR (saddle)
312
+ [[0, 2]],
313
+ // 6 (0110) TR BR
314
+ [[3, 2]],
315
+ // 7 (0111) TL TR BR
316
+ [[2, 3]],
317
+ // 8 (1000) BL
318
+ [[2, 0]],
319
+ // 9 (1001) TL BL
320
+ [[0, 1], [2, 3]],
321
+ // 10 (1010) TR BL (saddle)
322
+ [[2, 1]],
323
+ // 11 (1011) TL TR BL
324
+ [[1, 3]],
325
+ // 12 (1100) BR BL
326
+ [[1, 0]],
327
+ // 13 (1101) TL BR BL
328
+ [[0, 3]],
329
+ // 14 (1110) TR BR BL
330
+ []
331
+ // 15 (1111)
332
+ ];
333
+ function _t(t, r, n, e) {
334
+ const c = [];
335
+ for (let i = 0; i < n - 1; i++)
336
+ for (let s = 0; s < r - 1; s++) {
337
+ const o = t[i * r + s], l = t[i * r + s + 1], u = t[(i + 1) * r + s + 1], p = t[(i + 1) * r + s];
338
+ let m = 0;
339
+ if (o >= e && (m |= 1), l >= e && (m |= 2), u >= e && (m |= 4), p >= e && (m |= 8), m === 0 || m === 15) continue;
340
+ const v = (x) => {
341
+ switch (x) {
342
+ case 0: {
343
+ const g = l - o, y = Math.abs(g) < 1e-10 ? 0.5 : Math.max(0, Math.min(1, (e - o) / g));
344
+ return [s + y, i];
345
+ }
346
+ case 1: {
347
+ const g = u - l, y = Math.abs(g) < 1e-10 ? 0.5 : Math.max(0, Math.min(1, (e - l) / g));
348
+ return [s + 1, i + y];
349
+ }
350
+ case 2: {
351
+ const g = u - p, y = Math.abs(g) < 1e-10 ? 0.5 : Math.max(0, Math.min(1, (e - p) / g));
352
+ return [s + y, i + 1];
353
+ }
354
+ case 3: {
355
+ const g = p - o, y = Math.abs(g) < 1e-10 ? 0.5 : Math.max(0, Math.min(1, (e - o) / g));
356
+ return [s, i + y];
357
+ }
358
+ default:
359
+ return [s + 0.5, i + 0.5];
360
+ }
361
+ };
362
+ for (const [x, g] of jt[m])
363
+ c.push([v(x), v(g)]);
364
+ }
365
+ return c;
366
+ }
367
+ function $t(t) {
368
+ if (t.length === 0) return [];
369
+ const r = (i) => `${Math.round(i[0] * 1e4)},${Math.round(i[1] * 1e4)}`, n = /* @__PURE__ */ new Map();
370
+ for (let i = 0; i < t.length; i++)
371
+ for (const s of [0, 1]) {
372
+ const o = r(t[i][s]);
373
+ let l = n.get(o);
374
+ l || (l = [], n.set(o, l)), l.push({ idx: i, end: s });
375
+ }
376
+ const e = new Uint8Array(t.length), c = [];
377
+ for (let i = 0; i < t.length; i++) {
378
+ if (e[i]) continue;
379
+ const s = [];
380
+ let o = i, l = 1, u = 0;
381
+ const p = t.length + 1;
382
+ for (; u++ < p && !e[o]; ) {
383
+ e[o] = 1;
384
+ const m = l === 1 ? 0 : 1;
385
+ s.push(t[o][m]);
386
+ const v = t[o][l], x = r(v), g = n.get(x);
387
+ if (!g) break;
388
+ const y = g.find((d) => !e[d.idx]);
389
+ if (!y) break;
390
+ o = y.idx, l = y.end === 0 ? 1 : 0;
391
+ }
392
+ s.length >= 3 && c.push(s);
393
+ }
394
+ return c;
395
+ }
396
+ function Tt(t, r, n, e = 30, c = 2e-3) {
397
+ if (r <= 0 || n <= 0 || t.length === 0) return [];
398
+ const i = Math.min(1, At / Math.max(r, n)), s = Math.max(1, Math.round(r * i)), o = Math.max(1, Math.round(n * i)), l = s + 2, u = o + 2, p = new Float32Array(l * u);
399
+ for (let h = 0; h < o; h++) {
400
+ const f = Math.min(n - 1, Math.floor(h / i));
401
+ for (let w = 0; w < s; w++) {
402
+ const k = Math.min(r - 1, Math.floor(w / i));
403
+ p[(h + 1) * l + (w + 1)] = t[f * r + k];
404
+ }
405
+ }
406
+ const m = _t(p, l, u, e), v = $t(m);
407
+ if (v.length === 0) return [];
408
+ let x = v[0], g = Math.abs(dt(x));
409
+ for (let h = 1; h < v.length; h++) {
410
+ const f = Math.abs(dt(v[h]));
411
+ f > g && (x = v[h], g = f);
412
+ }
413
+ const y = x.map(([h, f]) => [
414
+ (h - 1) / s,
415
+ (f - 1) / o
416
+ ]), d = St(y, c);
417
+ return d.length >= 3 ? d : y;
260
418
  }
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;
419
+ function Dt(t) {
420
+ const r = t.length;
421
+ if (r < 3) return "";
422
+ const n = [`M${t[0][0]},${t[0][1]}`];
423
+ for (let e = 0; e < r; e++) {
424
+ const c = t[(e - 1 + r) % r], i = t[e], s = t[(e + 1) % r], o = t[(e + 2) % r], l = i[0] + (s[0] - c[0]) / 6, u = i[1] + (s[1] - c[1]) / 6, p = s[0] - (o[0] - i[0]) / 6, m = s[1] - (o[1] - i[1]) / 6;
425
+ n.push(`C${l},${u} ${p},${m} ${s[0]},${s[1]}`);
426
+ }
427
+ return n.push("Z"), n.join("");
267
428
  }
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
429
+ function Wt(t, r) {
430
+ const n = new Uint8Array(r);
431
+ for (let e = 0; e < r; e++)
432
+ n[e] = t[e * 4 + 3];
433
+ return n;
434
+ }
435
+ function zt(t, r, n, e) {
436
+ if (r <= 0 || n <= 0) return { x: 0, y: 0, w: 1, h: 1 };
437
+ let c = r, i = n, s = 0, o = 0, l = !1;
438
+ for (let u = 0; u < n; u++)
439
+ for (let p = 0; p < r; p++)
440
+ t[u * r + p] > e && (p < c && (c = p), p > s && (s = p), u < i && (i = u), u > o && (o = u), l = !0);
441
+ return l ? {
442
+ x: c / r,
443
+ y: i / n,
444
+ w: (s - c + 1) / r,
445
+ h: (o - i + 1) / n
279
446
  } : { x: 0, y: 0, w: 1, h: 1 };
280
447
  }
281
- class _t {
448
+ class Ot {
282
449
  id;
283
450
  bounds = { x: 0, y: 0, w: 1, h: 1 };
451
+ contour = [];
284
452
  /** URL of the cutout mask image */
285
453
  src;
286
454
  /** Alpha value (0-255) a pixel must exceed to be considered "visible" */
@@ -290,8 +458,8 @@ class _t {
290
458
  /** Source image dimensions (pixels) — needed to map normalized coords to pixel indices */
291
459
  width = 0;
292
460
  height = 0;
293
- constructor(r, o) {
294
- this.id = r.id, this.src = r.src, this.threshold = o;
461
+ constructor(r, n) {
462
+ this.id = r.id, this.src = r.src, this.threshold = n;
295
463
  }
296
464
  /**
297
465
  * Loads the cutout image and pre-computes the alpha buffer + bounding box.
@@ -309,19 +477,19 @@ class _t {
309
477
  */
310
478
  async prepare() {
311
479
  const r = new Image();
312
- r.crossOrigin = "anonymous", r.src = this.src, await new Promise((a) => {
313
- r.onload = () => a(), r.onerror = () => a();
480
+ r.crossOrigin = "anonymous", r.src = this.src, await new Promise((s) => {
481
+ r.onload = () => s(), r.onerror = () => s();
314
482
  });
315
- const o = r.naturalWidth, n = r.naturalHeight;
316
- if (o <= 0 || n <= 0) return;
317
- const i = document.createElement("canvas");
318
- i.width = o, i.height = n;
319
- const c = i.getContext("2d", { willReadFrequently: !0 });
320
- if (c)
483
+ const n = r.naturalWidth, e = r.naturalHeight;
484
+ if (n <= 0 || e <= 0) return;
485
+ const c = document.createElement("canvas");
486
+ c.width = n, c.height = e;
487
+ const i = c.getContext("2d", { willReadFrequently: !0 });
488
+ if (i)
321
489
  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);
490
+ i.drawImage(r, 0, 0);
491
+ const s = i.getImageData(0, 0, n, e);
492
+ this.alpha = Wt(s.data, n * e), this.width = n, this.height = e, this.bounds = zt(this.alpha, n, e, this.threshold), this.contour = Tt(this.alpha, n, e, this.threshold);
325
493
  } catch {
326
494
  this.alpha = new Uint8Array(0);
327
495
  }
@@ -341,50 +509,50 @@ class _t {
341
509
  * @param nx - normalized x-coordinate (0-1, relative to the image width)
342
510
  * @param ny - normalized y-coordinate (0-1, relative to the image height)
343
511
  */
344
- hitTest(r, o) {
512
+ hitTest(r, n) {
345
513
  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(
514
+ const e = this.bounds;
515
+ if (r < e.x || r > e.x + e.w || n < e.y || n > e.y + e.h) return !1;
516
+ const c = Math.min(this.width - 1, Math.max(0, Math.floor(r * this.width))), i = Math.min(
349
517
  this.height - 1,
350
- Math.max(0, Math.floor(o * this.height))
518
+ Math.max(0, Math.floor(n * this.height))
351
519
  );
352
- return this.alpha[c * this.width + i] > this.threshold;
520
+ return this.alpha[i * this.width + c] > this.threshold;
353
521
  }
354
522
  }
355
- class jt {
523
+ class Lt {
356
524
  id;
357
525
  bounds;
358
526
  constructor(r) {
359
527
  this.id = r.id, this.bounds = { ...r.bounds };
360
528
  }
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;
529
+ hitTest(r, n) {
530
+ const e = this.bounds;
531
+ return r >= e.x && r <= e.x + e.w && n >= e.y && n <= e.y + e.h;
364
532
  }
365
533
  }
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);
534
+ function Yt(t, r, n) {
535
+ let e = !1;
536
+ for (let c = 0, i = n.length - 1; c < n.length; i = c++) {
537
+ const s = n[c][0], o = n[c][1], l = n[i][0], u = n[i][1];
538
+ o > r != u > r && t < (l - s) * (r - o) / (u - o) + s && (e = !e);
371
539
  }
372
- return n;
540
+ return e;
373
541
  }
374
- class St {
542
+ class Nt {
375
543
  id;
376
544
  bounds;
377
545
  points;
378
546
  constructor(r) {
379
547
  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);
548
+ let n = 1 / 0, e = 1 / 0, c = -1 / 0, i = -1 / 0;
549
+ for (const [s, o] of r.points)
550
+ s < n && (n = s), s > c && (c = s), o < e && (e = o), o > i && (i = o);
383
551
  this.bounds = {
384
- x: o,
385
- y: n,
386
- w: i - o,
387
- h: c - n
552
+ x: n,
553
+ y: e,
554
+ w: c - n,
555
+ h: i - e
388
556
  };
389
557
  }
390
558
  /**
@@ -399,22 +567,47 @@ class St {
399
567
  * @param nx - normalized x-coordinate (0-1, relative to the image width)
400
568
  * @param ny - normalized y-coordinate (0-1, relative to the image height)
401
569
  */
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);
570
+ hitTest(r, n) {
571
+ const e = this.bounds;
572
+ return r < e.x || r > e.x + e.w || n < e.y || n > e.y + e.h ? !1 : Yt(r, n, this.points);
573
+ }
574
+ }
575
+ class Vt {
576
+ id;
577
+ bounds;
578
+ cx;
579
+ cy;
580
+ rx;
581
+ ry;
582
+ constructor(r, n = 1, e = 1) {
583
+ this.id = r.id, this.cx = r.center.x, this.cy = r.center.y;
584
+ const c = Math.max(1, n), i = Math.max(1, e), s = Math.min(c, i);
585
+ this.rx = r.radius * s / c, this.ry = r.radius * s / i, this.bounds = {
586
+ x: r.center.x - this.rx,
587
+ y: r.center.y - this.ry,
588
+ w: this.rx * 2,
589
+ h: this.ry * 2
590
+ };
591
+ }
592
+ hitTest(r, n) {
593
+ if (this.rx <= 0 || this.ry <= 0) return !1;
594
+ const e = (r - this.cx) / this.rx, c = (n - this.cy) / this.ry;
595
+ return e * e + c * c <= 1;
405
596
  }
406
597
  }
407
- function Pt(t, r) {
598
+ function Bt(t, r, n) {
408
599
  switch (t.type) {
409
600
  case "image":
410
- return new _t(t, r);
601
+ return new Ot(t, r);
411
602
  case "bbox":
412
- return new jt(t);
603
+ return new Lt(t);
413
604
  case "polygon":
414
- return new St(t);
605
+ return new Nt(t);
606
+ case "circle":
607
+ return new Vt(t, n?.viewportWidth, n?.viewportHeight);
415
608
  }
416
609
  }
417
- function $t(t) {
610
+ function Ht(t) {
418
611
  switch (t.type) {
419
612
  case "image":
420
613
  return `${t.id}:image:${t.src}:${t.label ?? ""}`;
@@ -422,122 +615,142 @@ function $t(t) {
422
615
  return `${t.id}:bbox:${t.bounds.x},${t.bounds.y},${t.bounds.w},${t.bounds.h}:${t.label ?? ""}`;
423
616
  case "polygon":
424
617
  return `${t.id}:polygon:${t.points.flat().join(",")}:${t.label ?? ""}`;
618
+ case "circle":
619
+ return `${t.id}:circle:${t.center.x},${t.center.y},${t.radius}:${t.label ?? ""}`;
425
620
  }
426
621
  }
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(() => {
622
+ function Ft(t, r = !0, n = 30, e = 150) {
623
+ const [c, i] = O(null), [s, o] = O(null), l = N(null), u = N([]), [p, m] = O({}), [v, x] = O({ width: 1, height: 1 }), [g, y] = O({}), d = Math.min(255, Math.max(0, n)), h = N(null), f = M(() => {
429
624
  h.current === null && (h.current = setTimeout(() => {
430
- h.current = null, c(null);
431
- }, n));
432
- }, [n]), E = P(() => {
625
+ h.current = null, i(null);
626
+ }, e));
627
+ }, [e]), w = M(() => {
433
628
  h.current !== null && (clearTimeout(h.current), h.current = null);
434
- }, []), x = t.map($t).join("|"), w = B(() => t, [x]);
435
- O(() => {
629
+ }, []), k = t.map(Ht).join("|"), b = V(() => t, [k]);
630
+ W(() => {
631
+ const S = l.current;
632
+ if (!S) return;
633
+ const R = () => {
634
+ const I = S.getBoundingClientRect();
635
+ x({
636
+ width: Math.max(1, I.width),
637
+ height: Math.max(1, I.height)
638
+ });
639
+ };
640
+ R();
641
+ const P = new ResizeObserver(R);
642
+ return P.observe(S), () => P.disconnect();
643
+ }, []), W(() => {
436
644
  if (!r) {
437
- l.current = [];
645
+ u.current = [];
438
646
  return;
439
647
  }
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;
648
+ let S = !1, R = [];
649
+ async function P() {
650
+ const I = [], z = {}, L = {};
651
+ for (const G of b) {
652
+ const a = Bt(G, d, {
653
+ viewportWidth: v.width,
654
+ viewportHeight: v.height
655
+ });
656
+ if (a.prepare && await a.prepare(), S) return;
657
+ I.push(a), z[a.id] = a.bounds, a.contour && a.contour.length >= 3 && (L[a.id] = a.contour);
447
658
  }
448
- j || (_ = A, l.current = A, k(W));
659
+ S || (R = I, u.current = I, m(z), y(L));
449
660
  }
450
- return R(), () => {
451
- j = !0;
452
- for (const A of _)
453
- A.dispose?.();
661
+ return P(), () => {
662
+ S = !0;
663
+ for (const I of R)
664
+ I.dispose?.();
454
665
  };
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;
666
+ }, [b, r, d, v.width, v.height]);
667
+ const A = M(
668
+ (S, R) => {
669
+ const P = u.current;
670
+ for (let I = P.length - 1; I >= 0; I--)
671
+ if (P[I].hitTest(S, R))
672
+ return P[I].id;
462
673
  return null;
463
674
  },
464
675
  []
465
- ), b = P(
466
- (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 };
676
+ ), _ = M(
677
+ (S) => {
678
+ const R = l.current;
679
+ if (!R) return null;
680
+ const P = R.getBoundingClientRect(), I = (S.clientX - P.left) / P.width, z = (S.clientY - P.top) / P.height;
681
+ return I < 0 || I > 1 || z < 0 || z > 1 ? null : { nx: I, ny: z };
471
682
  },
472
683
  []
473
- ), v = P(
474
- (j) => {
684
+ ), X = M(
685
+ (S) => {
475
686
  if (!r) return;
476
- const _ = b(j);
477
- if (!_) {
478
- y();
687
+ const R = _(S);
688
+ if (!R) {
689
+ f();
479
690
  return;
480
691
  }
481
- const R = u(_.nx, _.ny);
482
- if (R === null) {
483
- if (j.target?.closest('[data-cutout-overlay="true"]')) {
484
- E();
692
+ const P = A(R.nx, R.ny);
693
+ if (P === null) {
694
+ if (S.target?.closest('[data-cutout-overlay="true"]')) {
695
+ w();
485
696
  return;
486
697
  }
487
- y();
698
+ f();
488
699
  return;
489
700
  }
490
- E(), c(R);
701
+ w(), i(P);
491
702
  },
492
- [r, b, u, y, E]
493
- ), m = P(() => {
494
- y();
495
- }, [y]), M = P(
496
- (j) => {
703
+ [r, _, A, f, w]
704
+ ), D = M(() => {
705
+ f();
706
+ }, [f]), U = M(
707
+ (S) => {
497
708
  if (!r) return;
498
- const _ = b(j);
499
- if (!_) {
500
- s(null);
709
+ const R = _(S);
710
+ if (!R) {
711
+ o(null);
501
712
  return;
502
713
  }
503
- const R = u(_.nx, _.ny);
504
- s(R === a || R === null ? null : R);
714
+ const P = A(R.nx, R.ny);
715
+ o(P === s || P === null ? null : P);
505
716
  },
506
- [r, b, u, a]
507
- ), D = a ?? i, z = r ? d : {};
508
- return O(() => () => {
509
- E();
510
- }, [E]), {
511
- hoveredId: i,
512
- selectedId: a,
513
- activeId: D,
514
- boundsMap: z,
515
- containerRef: f,
717
+ [r, _, A, s]
718
+ ), Q = s ?? c, B = r ? p : {}, q = r ? g : {};
719
+ return W(() => () => {
720
+ w();
721
+ }, [w]), {
722
+ hoveredId: c,
723
+ selectedId: s,
724
+ activeId: Q,
725
+ viewportSize: v,
726
+ boundsMap: B,
727
+ contourMap: q,
728
+ containerRef: l,
516
729
  containerProps: {
517
- onPointerMove: v,
518
- onPointerLeave: m,
519
- onClick: M
730
+ onPointerMove: X,
731
+ onPointerLeave: D,
732
+ onClick: U
520
733
  }
521
734
  };
522
735
  }
523
- function at(t, r) {
736
+ function bt(t, r) {
524
737
  return { name: t, css: r };
525
738
  }
526
- const pt = /* @__PURE__ */ new Set();
527
- function Wt(t) {
739
+ const gt = /* @__PURE__ */ new Set();
740
+ function Xt(t) {
528
741
  if (!(!t.keyframes?.length || typeof document > "u"))
529
742
  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} {
743
+ if (gt.has(r.name)) continue;
744
+ gt.add(r.name);
745
+ const n = document.createElement("style");
746
+ n.setAttribute("data-ricut-kf", r.name), n.textContent = `@keyframes ${r.name} {
534
747
  ${r.css}
535
- }`, document.head.appendChild(o);
748
+ }`, document.head.appendChild(n);
536
749
  }
537
750
  }
538
- const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
751
+ const rt = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ut = {
539
752
  name: "elevate",
540
- transition: K,
753
+ transition: rt,
541
754
  mainImageHovered: {
542
755
  filter: "brightness(0.45) saturate(0.7)"
543
756
  },
@@ -562,7 +775,7 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
562
775
  geometryActive: {
563
776
  fill: "rgba(130, 190, 255, 0.2)",
564
777
  stroke: "rgba(130, 190, 255, 0.9)",
565
- strokeWidth: 2,
778
+ strokeWidth: 0,
566
779
  glow: "0 0 24px rgba(130, 190, 255, 0.5), 0 0 56px rgba(130, 190, 255, 0.2), 0 12px 40px rgba(0, 0, 0, 0.4)"
567
780
  },
568
781
  geometryInactive: {
@@ -575,9 +788,9 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
575
788
  stroke: "transparent",
576
789
  strokeWidth: 1
577
790
  }
578
- }, Dt = {
791
+ }, qt = {
579
792
  name: "glow",
580
- transition: K,
793
+ transition: rt,
581
794
  mainImageHovered: {
582
795
  filter: "brightness(0.55) saturate(0.8)"
583
796
  },
@@ -602,7 +815,7 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
602
815
  geometryActive: {
603
816
  fill: "rgba(255, 200, 100, 0.15)",
604
817
  stroke: "rgba(255, 200, 100, 0.85)",
605
- strokeWidth: 2,
818
+ strokeWidth: 0,
606
819
  glow: "0 0 20px rgba(255, 200, 100, 0.5), 0 0 56px rgba(255, 200, 100, 0.2)"
607
820
  },
608
821
  geometryInactive: {
@@ -615,9 +828,9 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
615
828
  stroke: "transparent",
616
829
  strokeWidth: 1
617
830
  }
618
- }, Nt = {
831
+ }, Gt = {
619
832
  name: "lift",
620
- transition: K,
833
+ transition: rt,
621
834
  mainImageHovered: {
622
835
  filter: "brightness(0.4)"
623
836
  },
@@ -642,7 +855,7 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
642
855
  geometryActive: {
643
856
  fill: "rgba(255, 255, 255, 0.1)",
644
857
  stroke: "rgba(255, 255, 255, 0.7)",
645
- strokeWidth: 2,
858
+ strokeWidth: 0,
646
859
  glow: "0 20px 56px rgba(0, 0, 0, 0.6), 0 0 16px rgba(255, 255, 255, 0.1)"
647
860
  },
648
861
  geometryInactive: {
@@ -655,7 +868,7 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
655
868
  stroke: "transparent",
656
869
  strokeWidth: 1
657
870
  }
658
- }, Yt = {
871
+ }, Kt = {
659
872
  name: "subtle",
660
873
  transition: "all 0.3s ease",
661
874
  mainImageHovered: {
@@ -682,7 +895,7 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
682
895
  geometryActive: {
683
896
  fill: "rgba(255, 255, 255, 0.08)",
684
897
  stroke: "rgba(255, 255, 255, 0.5)",
685
- strokeWidth: 1
898
+ strokeWidth: 0
686
899
  },
687
900
  geometryInactive: {
688
901
  fill: "transparent",
@@ -694,21 +907,14 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
694
907
  stroke: "transparent",
695
908
  strokeWidth: 1
696
909
  }
697
- }, ht = at(
910
+ }, pt = bt(
698
911
  "_ricut-trace-stroke",
699
912
  `from { stroke-dashoffset: 0; }
700
913
  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 = {
914
+ ), Jt = {
709
915
  name: "trace",
710
- transition: K,
711
- keyframes: [ht, gt],
916
+ transition: rt,
917
+ keyframes: [pt],
712
918
  mainImageHovered: {
713
919
  filter: "brightness(0.35) saturate(0.5)"
714
920
  },
@@ -717,9 +923,8 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
717
923
  },
718
924
  cutoutActive: {
719
925
  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`
926
+ filter: "drop-shadow(0 0 8px rgba(255,255,255,0.15))",
927
+ opacity: 1
723
928
  },
724
929
  cutoutInactive: {
725
930
  transform: "scale(1)",
@@ -734,9 +939,9 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
734
939
  geometryActive: {
735
940
  fill: "rgba(255, 255, 255, 0.03)",
736
941
  stroke: "rgba(255, 255, 255, 0.9)",
737
- strokeWidth: 2.5,
942
+ strokeWidth: 2,
738
943
  strokeDasharray: "0.15 0.85",
739
- animation: `${ht.name} 3s linear infinite`,
944
+ animation: `${pt.name} 3s linear infinite`,
740
945
  glow: "0 0 10px rgba(255, 255, 255, 0.25)"
741
946
  },
742
947
  geometryInactive: {
@@ -749,7 +954,7 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
749
954
  stroke: "transparent",
750
955
  strokeWidth: 1
751
956
  }
752
- }, mt = at(
957
+ }, yt = bt(
753
958
  "_ricut-shimmer",
754
959
  `0%, 100% {
755
960
  filter: brightness(1.05) contrast(1.02)
@@ -766,10 +971,10 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
766
971
  drop-shadow(0 0 6px rgba(255, 255, 255, 0.12))
767
972
  drop-shadow(0 12px 32px rgba(0, 0, 0, 0.4));
768
973
  }`
769
- ), Bt = {
974
+ ), Zt = {
770
975
  name: "shimmer",
771
- transition: K,
772
- keyframes: [mt],
976
+ transition: rt,
977
+ keyframes: [yt],
773
978
  mainImageHovered: {
774
979
  filter: "brightness(0.35) saturate(0.6)"
775
980
  },
@@ -782,7 +987,7 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
782
987
  we set it here so there's a graceful look before the first frame. */
783
988
  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
989
  opacity: 1,
785
- animation: `${mt.name} 2.4s ease-in-out infinite`
990
+ animation: `${yt.name} 2.4s ease-in-out infinite`
786
991
  },
787
992
  cutoutInactive: {
788
993
  transform: "scale(1)",
@@ -797,7 +1002,7 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
797
1002
  geometryActive: {
798
1003
  fill: "rgba(255, 255, 255, 0.1)",
799
1004
  stroke: "rgba(255, 255, 255, 0.7)",
800
- strokeWidth: 2,
1005
+ strokeWidth: 0,
801
1006
  glow: "0 0 14px rgba(255, 255, 255, 0.35), 0 12px 32px rgba(0, 0, 0, 0.4)"
802
1007
  },
803
1008
  geometryInactive: {
@@ -811,47 +1016,51 @@ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
811
1016
  strokeWidth: 1
812
1017
  }
813
1018
  }, 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);
1019
+ elevate: Ut,
1020
+ glow: qt,
1021
+ lift: Gt,
1022
+ subtle: Kt,
1023
+ trace: Jt,
1024
+ shimmer: Zt
1025
+ }, H = lt(null), kt = lt(null);
821
1026
  function nt() {
822
- const t = H(xt);
1027
+ const t = Y(kt);
823
1028
  if (!t) throw new Error("Must be used inside <CutoutViewer>");
824
1029
  return t;
825
1030
  }
826
- const Q = it(null);
827
- function Kt() {
828
- const t = H(Q);
1031
+ const Z = lt(null);
1032
+ function de() {
1033
+ const t = Y(Z);
829
1034
  if (!t)
830
1035
  throw new Error("useCutout must be used inside <CutoutViewer.Cutout>");
831
1036
  return t;
832
1037
  }
833
- function Ht({ id: t, src: r, label: o, effect: n, children: i, renderLayer: c }) {
834
- const a = H(Z), s = nt();
835
- if (!a)
1038
+ function Qt({ id: t, src: r, label: n, effect: e, children: c, renderLayer: i }) {
1039
+ const s = Y(H), o = nt();
1040
+ if (!s)
836
1041
  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(
1042
+ W(() => (s.registerCutout({ type: "image", id: t, src: r, label: n }), () => s.unregisterCutout(t)), [t, r, n, s]);
1043
+ const l = e ? typeof e == "string" ? J[e] ?? o.effect : e : o.effect, u = o.contourMap[t] ?? null, p = V(() => {
1044
+ if (!u) return null;
1045
+ const w = o.viewportSize.width || 1, k = o.viewportSize.height || 1, b = u.map(([A, _]) => [A * w, _ * k]);
1046
+ return Dt(b);
1047
+ }, [u, o.viewportSize.width, o.viewportSize.height]), m = o.activeId === t, v = o.hoveredId === t, x = o.selectedId === t, g = { x: 0, y: 0, w: 1, h: 1 }, y = o.boundsMap[t] ?? g;
1048
+ let d, h;
1049
+ !o.enabled || !o.isAnyActive && !o.showAll ? (d = l.cutoutIdle, h = l.geometryIdle) : o.showAll || m ? (d = l.cutoutActive, h = l.geometryActive) : (d = l.cutoutInactive, h = l.geometryInactive);
1050
+ const f = V(
842
1051
  () => ({
843
1052
  id: t,
844
- label: o,
845
- bounds: h,
846
- isActive: l,
847
- isHovered: d,
848
- isSelected: k,
849
- effect: f
1053
+ label: n,
1054
+ bounds: y,
1055
+ isActive: m,
1056
+ isHovered: v,
1057
+ isSelected: x,
1058
+ effect: l
850
1059
  }),
851
- [t, o, h, l, d, k, f]
1060
+ [t, n, y, m, v, x, l]
852
1061
  );
853
- return /* @__PURE__ */ I.jsxs(Q.Provider, { value: E, children: [
854
- /* @__PURE__ */ I.jsx(
1062
+ return /* @__PURE__ */ C.jsxs(Z.Provider, { value: f, children: [
1063
+ /* @__PURE__ */ C.jsxs(
855
1064
  "div",
856
1065
  {
857
1066
  "data-cutout-id": t,
@@ -859,69 +1068,103 @@ function Ht({ id: t, src: r, label: o, effect: n, children: i, renderLayer: c })
859
1068
  pointerEvents: "none",
860
1069
  position: "absolute",
861
1070
  inset: 0,
862
- zIndex: l ? 20 : 10,
863
- transition: f.transition,
864
- ...y
1071
+ zIndex: m ? 20 : 10,
1072
+ transition: l.transition,
1073
+ ...d
865
1074
  },
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"
1075
+ children: [
1076
+ i ? i({ isActive: m, isHovered: v, isSelected: x, bounds: y, effect: l }) : /* @__PURE__ */ C.jsx(
1077
+ "img",
1078
+ {
1079
+ src: r,
1080
+ alt: n || t,
1081
+ draggable: !1,
1082
+ style: {
1083
+ width: "100%",
1084
+ height: "100%",
1085
+ objectFit: "fill",
1086
+ userSelect: "none"
1087
+ }
877
1088
  }
878
- }
879
- )
1089
+ ),
1090
+ p && h && /* @__PURE__ */ C.jsx(
1091
+ "svg",
1092
+ {
1093
+ viewBox: `0 0 ${o.viewportSize.width || 1} ${o.viewportSize.height || 1}`,
1094
+ preserveAspectRatio: "none",
1095
+ style: {
1096
+ position: "absolute",
1097
+ inset: 0,
1098
+ width: "100%",
1099
+ height: "100%",
1100
+ overflow: "visible",
1101
+ filter: h.glow ? `drop-shadow(${h.glow.split(",")[0]?.trim() ?? ""})` : "none"
1102
+ },
1103
+ children: /* @__PURE__ */ C.jsx(
1104
+ "path",
1105
+ {
1106
+ d: p,
1107
+ fill: h.fill,
1108
+ stroke: h.stroke,
1109
+ strokeWidth: h.strokeWidth ?? 2,
1110
+ strokeLinejoin: "round",
1111
+ strokeLinecap: h.strokeDasharray ? "round" : void 0,
1112
+ strokeDasharray: h.strokeDasharray,
1113
+ pathLength: h.strokeDasharray ? 1 : void 0,
1114
+ style: {
1115
+ transition: l.transition,
1116
+ animation: h.animation
1117
+ }
1118
+ }
1119
+ )
1120
+ }
1121
+ )
1122
+ ]
880
1123
  }
881
1124
  ),
882
- i
1125
+ c
883
1126
  ] });
884
1127
  }
885
- function yt(t) {
886
- const { filter: r, ...o } = t;
887
- return o;
1128
+ function mt(t) {
1129
+ const { filter: r, ...n } = t;
1130
+ return n;
888
1131
  }
889
- function Lt({
1132
+ function te({
890
1133
  id: t,
891
1134
  bounds: r,
892
- label: o,
893
- effect: n,
894
- children: i,
895
- renderLayer: c
1135
+ label: n,
1136
+ effect: e,
1137
+ children: c,
1138
+ renderLayer: i
896
1139
  }) {
897
- const a = H(Z), s = nt();
898
- if (!a)
1140
+ const s = Y(H), o = nt();
1141
+ if (!s)
899
1142
  throw new Error(
900
1143
  "<CutoutViewer.BBoxCutout> must be used inside <CutoutViewer>"
901
1144
  );
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 ?? {
1145
+ const { x: l, y: u, w: p, h: m } = r;
1146
+ W(() => (s.registerCutout({ type: "bbox", id: t, bounds: { x: l, y: u, w: p, h: m }, label: n }), () => s.unregisterCutout(t)), [t, l, u, p, m, n, s]);
1147
+ const v = e ? typeof e == "string" ? J[e] ?? o.effect : e : o.effect, x = o.activeId === t, g = o.hoveredId === t, y = o.selectedId === t, d = { x: 0, y: 0, w: 1, h: 1 }, h = o.boundsMap[t] ?? d;
1148
+ let f, w;
1149
+ !o.enabled || !o.isAnyActive && !o.showAll ? (w = { ...v.cutoutIdle, filter: "none", opacity: 0 }, f = v.geometryIdle) : o.showAll || x ? (w = mt(v.cutoutActive), f = v.geometryActive) : (w = mt(v.cutoutInactive), f = v.geometryInactive);
1150
+ const b = f ?? {
908
1151
  fill: "rgba(37, 99, 235, 0.15)",
909
1152
  stroke: "rgba(37, 99, 235, 0.6)",
910
1153
  strokeWidth: 2
911
- }, M = B(
1154
+ }, A = V(
912
1155
  () => ({
913
1156
  id: t,
914
- label: o,
915
- bounds: w,
916
- isActive: h,
917
- isHovered: y,
918
- isSelected: E,
919
- effect: g
1157
+ label: n,
1158
+ bounds: h,
1159
+ isActive: x,
1160
+ isHovered: g,
1161
+ isSelected: y,
1162
+ effect: v
920
1163
  }),
921
- [t, o, w, h, y, E, g]
1164
+ [t, n, h, x, g, y, v]
922
1165
  );
923
- return /* @__PURE__ */ I.jsxs(Q.Provider, { value: M, children: [
924
- /* @__PURE__ */ I.jsx(
1166
+ return /* @__PURE__ */ C.jsxs(Z.Provider, { value: A, children: [
1167
+ /* @__PURE__ */ C.jsx(
925
1168
  "div",
926
1169
  {
927
1170
  "data-cutout-id": t,
@@ -929,11 +1172,11 @@ function Lt({
929
1172
  pointerEvents: "none",
930
1173
  position: "absolute",
931
1174
  inset: 0,
932
- zIndex: h ? 20 : 10,
933
- transition: g.transition,
934
- ...b
1175
+ zIndex: x ? 20 : 10,
1176
+ transition: v.transition,
1177
+ ...w
935
1178
  },
936
- children: c ? c({ isActive: h, isHovered: y, isSelected: E, bounds: w, effect: g }) : /* @__PURE__ */ I.jsx(
1179
+ children: i ? i({ isActive: x, isHovered: g, isSelected: y, bounds: h, effect: v }) : /* @__PURE__ */ C.jsx(
937
1180
  "svg",
938
1181
  {
939
1182
  viewBox: "0 0 1 1",
@@ -944,25 +1187,25 @@ function Lt({
944
1187
  width: "100%",
945
1188
  height: "100%",
946
1189
  overflow: "visible",
947
- filter: m.glow ? `drop-shadow(${m.glow.split(",")[0]?.trim() ?? ""})` : "none"
1190
+ filter: b.glow ? `drop-shadow(${b.glow.split(",")[0]?.trim() ?? ""})` : "none"
948
1191
  },
949
- children: /* @__PURE__ */ I.jsx(
1192
+ children: /* @__PURE__ */ C.jsx(
950
1193
  "rect",
951
1194
  {
952
- x: w.x,
953
- y: w.y,
954
- width: w.w,
955
- height: w.h,
1195
+ x: h.x,
1196
+ y: h.y,
1197
+ width: h.w,
1198
+ height: h.h,
956
1199
  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,
1200
+ fill: b.fill,
1201
+ stroke: b.stroke,
1202
+ strokeWidth: (b.strokeWidth ?? 2) * 15e-4,
1203
+ strokeLinecap: b.strokeDasharray ? "round" : void 0,
1204
+ strokeDasharray: b.strokeDasharray,
1205
+ pathLength: b.strokeDasharray ? 1 : void 0,
963
1206
  style: {
964
- transition: g.transition,
965
- animation: m.animation
1207
+ transition: v.transition,
1208
+ animation: b.animation
966
1209
  }
967
1210
  }
968
1211
  )
@@ -970,49 +1213,49 @@ function Lt({
970
1213
  )
971
1214
  }
972
1215
  ),
973
- i
1216
+ c
974
1217
  ] });
975
1218
  }
976
- function bt(t) {
977
- const { filter: r, ...o } = t;
978
- return o;
1219
+ function vt(t) {
1220
+ const { filter: r, ...n } = t;
1221
+ return n;
979
1222
  }
980
- function Ft({
1223
+ function ee({
981
1224
  id: t,
982
1225
  points: r,
983
- label: o,
984
- effect: n,
985
- children: i,
986
- renderLayer: c
1226
+ label: n,
1227
+ effect: e,
1228
+ children: c,
1229
+ renderLayer: i
987
1230
  }) {
988
- const a = H(Z), s = nt();
989
- if (!a)
1231
+ const s = Y(H), o = nt();
1232
+ if (!s)
990
1233
  throw new Error(
991
1234
  "<CutoutViewer.PolygonCutout> must be used inside <CutoutViewer>"
992
1235
  );
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 ?? {
1236
+ const l = r.flat().join(",");
1237
+ W(() => (s.registerCutout({ type: "polygon", id: t, points: r, label: n }), () => s.unregisterCutout(t)), [t, l, n, s]);
1238
+ const u = e ? typeof e == "string" ? J[e] ?? o.effect : e : o.effect, p = o.activeId === t, m = o.hoveredId === t, v = o.selectedId === t, x = { x: 0, y: 0, w: 1, h: 1 }, g = o.boundsMap[t] ?? x;
1239
+ let y, d;
1240
+ !o.enabled || !o.isAnyActive && !o.showAll ? (d = { ...u.cutoutIdle, filter: "none", opacity: 0 }, y = u.geometryIdle) : o.showAll || p ? (d = vt(u.cutoutActive), y = u.geometryActive) : (d = vt(u.cutoutInactive), y = u.geometryInactive);
1241
+ const f = y ?? {
999
1242
  fill: "rgba(37, 99, 235, 0.15)",
1000
1243
  stroke: "rgba(37, 99, 235, 0.6)",
1001
1244
  strokeWidth: 2
1002
- }, b = B(
1245
+ }, w = V(
1003
1246
  () => ({
1004
1247
  id: t,
1005
- label: o,
1006
- bounds: y,
1007
- isActive: d,
1008
- isHovered: k,
1009
- isSelected: g,
1010
- effect: l
1248
+ label: n,
1249
+ bounds: g,
1250
+ isActive: p,
1251
+ isHovered: m,
1252
+ isSelected: v,
1253
+ effect: u
1011
1254
  }),
1012
- [t, o, y, d, k, g, l]
1255
+ [t, n, g, p, m, v, u]
1013
1256
  );
1014
- return /* @__PURE__ */ I.jsxs(Q.Provider, { value: b, children: [
1015
- /* @__PURE__ */ I.jsx(
1257
+ return /* @__PURE__ */ C.jsxs(Z.Provider, { value: w, children: [
1258
+ /* @__PURE__ */ C.jsx(
1016
1259
  "div",
1017
1260
  {
1018
1261
  "data-cutout-id": t,
@@ -1020,11 +1263,11 @@ function Ft({
1020
1263
  pointerEvents: "none",
1021
1264
  position: "absolute",
1022
1265
  inset: 0,
1023
- zIndex: d ? 20 : 10,
1024
- transition: l.transition,
1025
- ...x
1266
+ zIndex: p ? 20 : 10,
1267
+ transition: u.transition,
1268
+ ...d
1026
1269
  },
1027
- children: c ? c({ isActive: d, isHovered: k, isSelected: g, bounds: y, effect: l }) : /* @__PURE__ */ I.jsx(
1270
+ children: i ? i({ isActive: p, isHovered: m, isSelected: v, bounds: g, effect: u }) : /* @__PURE__ */ C.jsx(
1028
1271
  "svg",
1029
1272
  {
1030
1273
  viewBox: "0 0 1 1",
@@ -1035,22 +1278,113 @@ function Ft({
1035
1278
  width: "100%",
1036
1279
  height: "100%",
1037
1280
  overflow: "visible",
1038
- filter: u.glow ? `drop-shadow(${u.glow.split(",")[0]?.trim() ?? ""})` : "none"
1281
+ filter: f.glow ? `drop-shadow(${f.glow.split(",")[0]?.trim() ?? ""})` : "none"
1039
1282
  },
1040
- children: /* @__PURE__ */ I.jsx(
1283
+ children: /* @__PURE__ */ C.jsx(
1041
1284
  "polygon",
1042
1285
  {
1043
- points: r.map(([v, m]) => `${v},${m}`).join(" "),
1044
- fill: u.fill,
1045
- stroke: u.stroke,
1046
- strokeWidth: (u.strokeWidth ?? 2) * 15e-4,
1286
+ points: r.map(([k, b]) => `${k},${b}`).join(" "),
1287
+ fill: f.fill,
1288
+ stroke: f.stroke,
1289
+ strokeWidth: (f.strokeWidth ?? 2) * 15e-4,
1047
1290
  strokeLinejoin: "round",
1048
- strokeLinecap: u.strokeDasharray ? "round" : void 0,
1049
- strokeDasharray: u.strokeDasharray,
1050
- pathLength: u.strokeDasharray ? 1 : void 0,
1291
+ strokeLinecap: f.strokeDasharray ? "round" : void 0,
1292
+ strokeDasharray: f.strokeDasharray,
1293
+ pathLength: f.strokeDasharray ? 1 : void 0,
1294
+ style: {
1295
+ transition: u.transition,
1296
+ animation: f.animation
1297
+ }
1298
+ }
1299
+ )
1300
+ }
1301
+ )
1302
+ }
1303
+ ),
1304
+ c
1305
+ ] });
1306
+ }
1307
+ function wt(t) {
1308
+ const { filter: r, ...n } = t;
1309
+ return n;
1310
+ }
1311
+ function re({
1312
+ id: t,
1313
+ center: r,
1314
+ radius: n,
1315
+ label: e,
1316
+ effect: c,
1317
+ children: i,
1318
+ renderLayer: s
1319
+ }) {
1320
+ const o = Y(H), l = nt();
1321
+ if (!o)
1322
+ throw new Error(
1323
+ "<CutoutViewer.CircleCutout> must be used inside <CutoutViewer>"
1324
+ );
1325
+ const { x: u, y: p } = r;
1326
+ W(() => (o.registerCutout({ type: "circle", id: t, center: { x: u, y: p }, radius: n, label: e }), () => o.unregisterCutout(t)), [t, u, p, n, e, o]);
1327
+ const m = c ? typeof c == "string" ? J[c] ?? l.effect : c : l.effect, v = l.activeId === t, x = l.hoveredId === t, g = l.selectedId === t, y = { x: 0, y: 0, w: 1, h: 1 }, d = l.boundsMap[t] ?? y, h = Math.max(1, l.viewportSize.width), f = Math.max(1, l.viewportSize.height), w = Math.min(h, f), k = n * w / h, b = n * w / f;
1328
+ let A, _;
1329
+ !l.enabled || !l.isAnyActive && !l.showAll ? (_ = { ...m.cutoutIdle, filter: "none", opacity: 0 }, A = m.geometryIdle) : l.showAll || v ? (_ = wt(m.cutoutActive), A = m.geometryActive) : (_ = wt(m.cutoutInactive), A = m.geometryInactive);
1330
+ const D = A ?? {
1331
+ fill: "rgba(37, 99, 235, 0.15)",
1332
+ stroke: "rgba(37, 99, 235, 0.6)",
1333
+ strokeWidth: 2
1334
+ }, U = V(
1335
+ () => ({
1336
+ id: t,
1337
+ label: e,
1338
+ bounds: d,
1339
+ isActive: v,
1340
+ isHovered: x,
1341
+ isSelected: g,
1342
+ effect: m
1343
+ }),
1344
+ [t, e, d, v, x, g, m]
1345
+ );
1346
+ return /* @__PURE__ */ C.jsxs(Z.Provider, { value: U, children: [
1347
+ /* @__PURE__ */ C.jsx(
1348
+ "div",
1349
+ {
1350
+ "data-cutout-id": t,
1351
+ style: {
1352
+ pointerEvents: "none",
1353
+ position: "absolute",
1354
+ inset: 0,
1355
+ zIndex: v ? 20 : 10,
1356
+ transition: m.transition,
1357
+ ..._
1358
+ },
1359
+ children: s ? s({ isActive: v, isHovered: x, isSelected: g, bounds: d, effect: m }) : /* @__PURE__ */ C.jsx(
1360
+ "svg",
1361
+ {
1362
+ viewBox: "0 0 1 1",
1363
+ preserveAspectRatio: "none",
1364
+ style: {
1365
+ position: "absolute",
1366
+ inset: 0,
1367
+ width: "100%",
1368
+ height: "100%",
1369
+ overflow: "visible",
1370
+ filter: D.glow ? `drop-shadow(${D.glow.split(",")[0]?.trim() ?? ""})` : "none"
1371
+ },
1372
+ children: /* @__PURE__ */ C.jsx(
1373
+ "ellipse",
1374
+ {
1375
+ cx: r.x,
1376
+ cy: r.y,
1377
+ rx: k,
1378
+ ry: b,
1379
+ fill: D.fill,
1380
+ stroke: D.stroke,
1381
+ strokeWidth: (D.strokeWidth ?? 2) * 15e-4,
1382
+ strokeLinecap: D.strokeDasharray ? "round" : void 0,
1383
+ strokeDasharray: D.strokeDasharray,
1384
+ pathLength: D.strokeDasharray ? 1 : void 0,
1051
1385
  style: {
1052
- transition: l.transition,
1053
- animation: u.animation
1386
+ transition: m.transition,
1387
+ animation: D.animation
1054
1388
  }
1055
1389
  }
1056
1390
  )
@@ -1061,163 +1395,163 @@ function Ft({
1061
1395
  i
1062
1396
  ] });
1063
1397
  }
1064
- function zt(t, r) {
1065
- const { x: o, y: n, w: i, h: c } = r;
1066
- 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%"), {
1398
+ function ne(t, r) {
1399
+ const { x: n, y: e, w: c, h: i } = r;
1400
+ let s, o;
1401
+ t.includes("left") ? (s = `${n * 100}%`, o = "0") : t.includes("right") ? (s = `${(n + c) * 100}%`, o = "-100%") : (s = `${(n + c / 2) * 100}%`, o = "-50%");
1402
+ let l, u;
1403
+ return t.startsWith("top") ? (l = `${e * 100}%`, u = "-100%") : t.startsWith("bottom") ? (l = `${(e + i) * 100}%`, u = "0") : (l = `${(e + i / 2) * 100}%`, u = "-50%"), {
1070
1404
  position: "absolute",
1071
- left: a,
1072
- top: f,
1073
- transform: `translate(${s}, ${l})`
1405
+ left: s,
1406
+ top: l,
1407
+ transform: `translate(${o}, ${u})`
1074
1408
  };
1075
1409
  }
1076
- function Ut({
1410
+ function oe({
1077
1411
  placement: t = "top-center",
1078
1412
  children: r,
1079
- className: o = "",
1080
- style: n
1413
+ className: n = "",
1414
+ style: e
1081
1415
  }) {
1082
- const i = H(Q), c = nt();
1083
- if (!i)
1416
+ const c = Y(Z), i = nt();
1417
+ if (!c)
1084
1418
  throw new Error(
1085
1419
  "<CutoutViewer.Overlay> must be used inside <CutoutViewer.Cutout>"
1086
1420
  );
1087
- const a = c.enabled && (c.showAll || i.isActive), s = zt(t, i.bounds);
1088
- return /* @__PURE__ */ I.jsx(
1421
+ const s = i.enabled && (i.showAll || c.isActive), o = ne(t, c.bounds);
1422
+ return /* @__PURE__ */ C.jsx(
1089
1423
  "div",
1090
1424
  {
1091
1425
  "data-cutout-overlay": "true",
1092
- className: o,
1426
+ className: n,
1093
1427
  style: {
1094
1428
  zIndex: 30,
1095
- transition: i.effect.transition,
1096
- opacity: a ? 1 : 0,
1097
- pointerEvents: a ? "auto" : "none",
1098
- ...s,
1099
- ...n
1429
+ transition: c.effect.transition,
1430
+ opacity: s ? 1 : 0,
1431
+ pointerEvents: s ? "auto" : "none",
1432
+ ...o,
1433
+ ...e
1100
1434
  },
1101
1435
  children: r
1102
1436
  }
1103
1437
  );
1104
1438
  }
1105
- function Xt({
1439
+ function se({
1106
1440
  onComplete: t,
1107
1441
  minPoints: r = 3,
1108
- closeThreshold: o = 0.03
1442
+ closeThreshold: n = 0.03
1109
1443
  }) {
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];
1444
+ const [e, c] = O([]), [i, s] = O(null), o = N(null), l = M(
1445
+ (f, w) => {
1446
+ const k = o.current;
1447
+ if (!k) return null;
1448
+ const b = k.getBoundingClientRect(), A = (f - b.left) / b.width, _ = (w - b.top) / b.height;
1449
+ return A < 0 || A > 1 || _ < 0 || _ > 1 ? null : [A, _];
1116
1450
  },
1117
1451
  []
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;
1452
+ ), u = M(
1453
+ (f, w) => {
1454
+ if (w.length < r) return !1;
1455
+ const k = f[0] - w[0][0], b = f[1] - w[0][1];
1456
+ return Math.sqrt(k * k + b * b) < n;
1123
1457
  },
1124
- [r, o]
1125
- ), d = P(
1126
- (u) => {
1127
- u.length < r || (t(u), i([]), a(null));
1458
+ [r, n]
1459
+ ), p = M(
1460
+ (f) => {
1461
+ f.length < r || (t(f), c([]), s(null));
1128
1462
  },
1129
1463
  [t, r]
1130
- ), k = P(() => {
1131
- i([]), a(null);
1132
- }, []), g = P(
1133
- (u) => {
1134
- a(f(u.clientX, u.clientY));
1464
+ ), m = M(() => {
1465
+ c([]), s(null);
1466
+ }, []), v = M(
1467
+ (f) => {
1468
+ s(l(f.clientX, f.clientY));
1135
1469
  },
1136
- [f]
1137
- ), h = P(() => {
1138
- 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]);
1470
+ [l]
1471
+ ), x = M(() => {
1472
+ s(null);
1473
+ }, []), g = M(
1474
+ (f) => {
1475
+ f.stopPropagation();
1476
+ const w = l(f.clientX, f.clientY);
1477
+ w && c((k) => u(w, k) ? (p(k), []) : [...k, w]);
1144
1478
  },
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;
1479
+ [l, u, p]
1480
+ ), y = M(
1481
+ (f) => {
1482
+ f.stopPropagation(), c((w) => {
1483
+ const k = w.slice(0, -1);
1484
+ return k.length >= r ? (p(k), []) : k;
1151
1485
  });
1152
1486
  },
1153
- [r, d]
1154
- ), x = P(
1155
- (u) => {
1156
- u.preventDefault(), i((b) => b.slice(0, -1));
1487
+ [r, p]
1488
+ ), d = M(
1489
+ (f) => {
1490
+ f.preventDefault(), c((w) => w.slice(0, -1));
1157
1491
  },
1158
1492
  []
1159
- ), w = c !== null && l(c, n);
1493
+ ), h = i !== null && u(i, e);
1160
1494
  return {
1161
- points: n,
1162
- previewPoint: c,
1163
- willClose: w,
1164
- reset: k,
1165
- containerRef: s,
1495
+ points: e,
1496
+ previewPoint: i,
1497
+ willClose: h,
1498
+ reset: m,
1499
+ containerRef: o,
1166
1500
  containerProps: {
1167
- onPointerMove: g,
1168
- onPointerLeave: h,
1169
- onClick: y,
1170
- onDoubleClick: E,
1171
- onContextMenu: x
1501
+ onPointerMove: v,
1502
+ onPointerLeave: x,
1503
+ onClick: g,
1504
+ onDoubleClick: y,
1505
+ onContextMenu: d
1172
1506
  }
1173
1507
  };
1174
1508
  }
1175
- function Gt({
1509
+ function ie({
1176
1510
  onComplete: t,
1177
1511
  minPoints: r = 3,
1178
- closeThreshold: o = 0.03,
1179
- strokeColor: n = "#3b82f6",
1180
- enabled: i = !0,
1181
- style: c,
1182
- className: a = ""
1512
+ closeThreshold: n = 0.03,
1513
+ strokeColor: e = "#3b82f6",
1514
+ enabled: c = !0,
1515
+ style: i,
1516
+ className: s = ""
1183
1517
  }) {
1184
- if (!H(Z))
1518
+ if (!Y(H))
1185
1519
  throw new Error(
1186
1520
  "<CutoutViewer.DrawPolygon> must be used inside <CutoutViewer>"
1187
1521
  );
1188
1522
  const {
1189
- points: f,
1190
- previewPoint: l,
1191
- willClose: d,
1192
- reset: k,
1193
- containerRef: g,
1194
- containerProps: h
1195
- } = Xt({ onComplete: t, minPoints: r, closeThreshold: o });
1196
- O(() => {
1197
- function x(w) {
1198
- w.key === "Escape" && k();
1523
+ points: l,
1524
+ previewPoint: u,
1525
+ willClose: p,
1526
+ reset: m,
1527
+ containerRef: v,
1528
+ containerProps: x
1529
+ } = se({ onComplete: t, minPoints: r, closeThreshold: n });
1530
+ W(() => {
1531
+ function d(h) {
1532
+ h.key === "Escape" && m();
1199
1533
  }
1200
- return document.addEventListener("keydown", x), () => document.removeEventListener("keydown", x);
1201
- }, [k]), O(() => {
1202
- i || k();
1203
- }, [i, k]);
1204
- const y = l ? [...f, l] : f, E = y.map(([x, w]) => `${x},${w}`).join(" ");
1205
- return /* @__PURE__ */ I.jsx(
1534
+ return document.addEventListener("keydown", d), () => document.removeEventListener("keydown", d);
1535
+ }, [m]), W(() => {
1536
+ c || m();
1537
+ }, [c, m]);
1538
+ const g = u ? [...l, u] : l, y = g.map(([d, h]) => `${d},${h}`).join(" ");
1539
+ return /* @__PURE__ */ C.jsx(
1206
1540
  "div",
1207
1541
  {
1208
- ref: g,
1542
+ ref: v,
1209
1543
  "data-draw-polygon": "true",
1210
- className: a,
1544
+ className: s,
1211
1545
  style: {
1212
1546
  position: "absolute",
1213
1547
  inset: 0,
1214
- cursor: i ? d ? "cell" : "crosshair" : "default",
1548
+ cursor: c ? p ? "cell" : "crosshair" : "default",
1215
1549
  zIndex: 30,
1216
- pointerEvents: i ? "auto" : "none",
1217
- ...c
1550
+ pointerEvents: c ? "auto" : "none",
1551
+ ...i
1218
1552
  },
1219
- ...i ? h : {},
1220
- children: f.length > 0 && /* @__PURE__ */ I.jsxs(
1553
+ ...c ? x : {},
1554
+ children: l.length > 0 && /* @__PURE__ */ C.jsxs(
1221
1555
  "svg",
1222
1556
  {
1223
1557
  viewBox: "0 0 1 1",
@@ -1231,61 +1565,61 @@ function Gt({
1231
1565
  pointerEvents: "none"
1232
1566
  },
1233
1567
  children: [
1234
- f.length >= 3 && /* @__PURE__ */ I.jsx(
1568
+ l.length >= 3 && /* @__PURE__ */ C.jsx(
1235
1569
  "polygon",
1236
1570
  {
1237
- points: f.map(([x, w]) => `${x},${w}`).join(" "),
1238
- fill: n,
1571
+ points: l.map(([d, h]) => `${d},${h}`).join(" "),
1572
+ fill: e,
1239
1573
  fillOpacity: 0.15,
1240
1574
  stroke: "none"
1241
1575
  }
1242
1576
  ),
1243
- y.length >= 2 && /* @__PURE__ */ I.jsx(
1577
+ g.length >= 2 && /* @__PURE__ */ C.jsx(
1244
1578
  "polyline",
1245
1579
  {
1246
- points: E,
1580
+ points: y,
1247
1581
  fill: "none",
1248
- stroke: n,
1582
+ stroke: e,
1249
1583
  strokeWidth: 3e-3,
1250
1584
  strokeLinecap: "round",
1251
1585
  strokeLinejoin: "round",
1252
- strokeDasharray: l ? "0.015 0.008" : void 0
1586
+ strokeDasharray: u ? "0.015 0.008" : void 0
1253
1587
  }
1254
1588
  ),
1255
- l && f.length >= 1 && /* @__PURE__ */ I.jsx(
1589
+ u && l.length >= 1 && /* @__PURE__ */ C.jsx(
1256
1590
  "line",
1257
1591
  {
1258
- x1: l[0],
1259
- y1: l[1],
1260
- x2: f[0][0],
1261
- y2: f[0][1],
1262
- stroke: n,
1592
+ x1: u[0],
1593
+ y1: u[1],
1594
+ x2: l[0][0],
1595
+ y2: l[0][1],
1596
+ stroke: e,
1263
1597
  strokeWidth: 2e-3,
1264
1598
  strokeDasharray: "0.015 0.008",
1265
1599
  strokeLinecap: "round",
1266
- opacity: d ? 0.9 : 0.35
1600
+ opacity: p ? 0.9 : 0.35
1267
1601
  }
1268
1602
  ),
1269
- f.map(([x, w], u) => /* @__PURE__ */ I.jsx(
1603
+ l.map(([d, h], f) => /* @__PURE__ */ C.jsx(
1270
1604
  "circle",
1271
1605
  {
1272
- cx: x,
1273
- cy: w,
1274
- r: u === 0 ? 0.012 : 7e-3,
1275
- fill: u === 0 && d ? n : "white",
1276
- stroke: n,
1606
+ cx: d,
1607
+ cy: h,
1608
+ r: f === 0 ? 0.012 : 7e-3,
1609
+ fill: f === 0 && p ? e : "white",
1610
+ stroke: e,
1277
1611
  strokeWidth: 2e-3
1278
1612
  },
1279
- u
1613
+ f
1280
1614
  )),
1281
- l && /* @__PURE__ */ I.jsx(
1615
+ u && /* @__PURE__ */ C.jsx(
1282
1616
  "circle",
1283
1617
  {
1284
- cx: l[0],
1285
- cy: l[1],
1618
+ cx: u[0],
1619
+ cy: u[1],
1286
1620
  r: 5e-3,
1287
- fill: d ? n : "white",
1288
- stroke: n,
1621
+ fill: p ? e : "white",
1622
+ stroke: e,
1289
1623
  strokeWidth: 2e-3,
1290
1624
  opacity: 0.8
1291
1625
  }
@@ -1296,7 +1630,298 @@ function Gt({
1296
1630
  }
1297
1631
  );
1298
1632
  }
1299
- function vt(t) {
1633
+ function ae({
1634
+ onComplete: t,
1635
+ minSize: r = 0.01
1636
+ }) {
1637
+ const [n, e] = O(null), [c, i] = O(null), s = N(null), o = M(
1638
+ (g, y) => {
1639
+ const d = s.current;
1640
+ if (!d) return null;
1641
+ const h = d.getBoundingClientRect(), f = (g - h.left) / h.width, w = (y - h.top) / h.height;
1642
+ return {
1643
+ x: Math.max(0, Math.min(1, f)),
1644
+ y: Math.max(0, Math.min(1, w))
1645
+ };
1646
+ },
1647
+ []
1648
+ ), l = M(
1649
+ (g, y) => {
1650
+ const d = Math.min(g.x, y.x), h = Math.min(g.y, y.y), f = Math.abs(y.x - g.x), w = Math.abs(y.y - g.y);
1651
+ return { x: d, y: h, w: f, h: w };
1652
+ },
1653
+ []
1654
+ ), u = M(() => {
1655
+ e(null), i(null);
1656
+ }, []);
1657
+ W(() => {
1658
+ function g(y) {
1659
+ y.key === "Escape" && u();
1660
+ }
1661
+ return document.addEventListener("keydown", g), () => document.removeEventListener("keydown", g);
1662
+ }, [u]);
1663
+ const p = M(
1664
+ (g) => {
1665
+ g.currentTarget.setPointerCapture(g.pointerId);
1666
+ const y = o(g.clientX, g.clientY);
1667
+ y && (e(y), i({ x: y.x, y: y.y, w: 0, h: 0 }));
1668
+ },
1669
+ [o]
1670
+ ), m = M(
1671
+ (g) => {
1672
+ if (!n) return;
1673
+ const y = o(g.clientX, g.clientY);
1674
+ y && i(l(n, y));
1675
+ },
1676
+ [n, o, l]
1677
+ ), v = M(
1678
+ (g) => {
1679
+ if (!n) return;
1680
+ const y = o(g.clientX, g.clientY);
1681
+ if (y) {
1682
+ const d = l(n, y);
1683
+ d.w >= r && d.h >= r && t(d);
1684
+ }
1685
+ e(null), i(null);
1686
+ },
1687
+ [n, o, l, r, t]
1688
+ ), x = M(() => {
1689
+ }, []);
1690
+ return {
1691
+ rect: c,
1692
+ isDragging: n !== null,
1693
+ reset: u,
1694
+ containerRef: s,
1695
+ containerProps: {
1696
+ onPointerDown: p,
1697
+ onPointerMove: m,
1698
+ onPointerUp: v,
1699
+ onPointerLeave: x
1700
+ }
1701
+ };
1702
+ }
1703
+ function ce({
1704
+ onComplete: t,
1705
+ minSize: r,
1706
+ strokeColor: n = "#3b82f6",
1707
+ enabled: e = !0,
1708
+ style: c,
1709
+ className: i = ""
1710
+ }) {
1711
+ if (!Y(H))
1712
+ throw new Error(
1713
+ "<CutoutViewer.DrawRectangle> must be used inside <CutoutViewer>"
1714
+ );
1715
+ const { rect: o, reset: l, containerRef: u, containerProps: p } = ae({
1716
+ onComplete: t,
1717
+ minSize: r
1718
+ });
1719
+ return W(() => {
1720
+ e || l();
1721
+ }, [e, l]), /* @__PURE__ */ C.jsx(
1722
+ "div",
1723
+ {
1724
+ ref: u,
1725
+ "data-draw-rectangle": "true",
1726
+ className: i,
1727
+ style: {
1728
+ position: "absolute",
1729
+ inset: 0,
1730
+ cursor: e ? "crosshair" : "default",
1731
+ zIndex: 30,
1732
+ pointerEvents: e ? "auto" : "none",
1733
+ ...c
1734
+ },
1735
+ ...e ? p : {},
1736
+ children: o && o.w > 0 && o.h > 0 && /* @__PURE__ */ C.jsx(
1737
+ "svg",
1738
+ {
1739
+ viewBox: "0 0 1 1",
1740
+ preserveAspectRatio: "none",
1741
+ style: {
1742
+ position: "absolute",
1743
+ inset: 0,
1744
+ width: "100%",
1745
+ height: "100%",
1746
+ overflow: "visible",
1747
+ pointerEvents: "none"
1748
+ },
1749
+ children: /* @__PURE__ */ C.jsx(
1750
+ "rect",
1751
+ {
1752
+ x: o.x,
1753
+ y: o.y,
1754
+ width: o.w,
1755
+ height: o.h,
1756
+ fill: n,
1757
+ fillOpacity: 0.15,
1758
+ stroke: n,
1759
+ strokeWidth: 3e-3,
1760
+ strokeLinecap: "round",
1761
+ strokeLinejoin: "round",
1762
+ strokeDasharray: "0.015 0.008"
1763
+ }
1764
+ )
1765
+ }
1766
+ )
1767
+ }
1768
+ );
1769
+ }
1770
+ function le({
1771
+ onComplete: t,
1772
+ minRadius: r = 0.01
1773
+ }) {
1774
+ const [n, e] = O(null), [c, i] = O(null), [s, o] = O({ width: 1, height: 1 }), l = N(null);
1775
+ W(() => {
1776
+ const d = l.current;
1777
+ if (!d) return;
1778
+ const h = () => {
1779
+ const w = d.getBoundingClientRect();
1780
+ o({
1781
+ width: Math.max(1, w.width),
1782
+ height: Math.max(1, w.height)
1783
+ });
1784
+ };
1785
+ h();
1786
+ const f = new ResizeObserver(h);
1787
+ return f.observe(d), () => f.disconnect();
1788
+ }, []);
1789
+ const u = M(
1790
+ (d, h) => {
1791
+ const f = l.current;
1792
+ if (!f) return null;
1793
+ const w = f.getBoundingClientRect(), k = (d - w.left) / w.width, b = (h - w.top) / w.height;
1794
+ return {
1795
+ x: Math.max(0, Math.min(1, k)),
1796
+ y: Math.max(0, Math.min(1, b))
1797
+ };
1798
+ },
1799
+ []
1800
+ ), p = M(
1801
+ (d, h) => {
1802
+ const f = (d.x - h.x) * s.width, w = (d.y - h.y) * s.height, k = Math.sqrt(f * f + w * w), b = Math.min(s.width, s.height);
1803
+ return k / b;
1804
+ },
1805
+ [s.height, s.width]
1806
+ ), m = M(() => {
1807
+ e(null), i(null);
1808
+ }, []);
1809
+ W(() => {
1810
+ function d(h) {
1811
+ h.key === "Escape" && m();
1812
+ }
1813
+ return document.addEventListener("keydown", d), () => document.removeEventListener("keydown", d);
1814
+ }, [m]);
1815
+ const v = M(
1816
+ (d) => {
1817
+ d.currentTarget.setPointerCapture(d.pointerId);
1818
+ const h = u(d.clientX, d.clientY);
1819
+ h && (e(h), i({ center: h, radius: 0 }));
1820
+ },
1821
+ [u]
1822
+ ), x = M(
1823
+ (d) => {
1824
+ if (!n) return;
1825
+ const h = u(d.clientX, d.clientY);
1826
+ if (!h) return;
1827
+ const f = p(h, n);
1828
+ i({ center: n, radius: f });
1829
+ },
1830
+ [n, u, p]
1831
+ ), g = M(
1832
+ (d) => {
1833
+ if (!n) return;
1834
+ const h = u(d.clientX, d.clientY);
1835
+ if (h) {
1836
+ const f = p(h, n);
1837
+ f >= r && t({ center: n, radius: f });
1838
+ }
1839
+ e(null), i(null);
1840
+ },
1841
+ [n, u, p, r, t]
1842
+ ), y = M(() => {
1843
+ }, []);
1844
+ return {
1845
+ circle: c,
1846
+ viewportSize: s,
1847
+ isDragging: n !== null,
1848
+ reset: m,
1849
+ containerRef: l,
1850
+ containerProps: {
1851
+ onPointerDown: v,
1852
+ onPointerMove: x,
1853
+ onPointerUp: g,
1854
+ onPointerLeave: y
1855
+ }
1856
+ };
1857
+ }
1858
+ function ue({
1859
+ onComplete: t,
1860
+ minRadius: r,
1861
+ strokeColor: n = "#3b82f6",
1862
+ enabled: e = !0,
1863
+ style: c,
1864
+ className: i = ""
1865
+ }) {
1866
+ if (!Y(H))
1867
+ throw new Error(
1868
+ "<CutoutViewer.DrawCircle> must be used inside <CutoutViewer>"
1869
+ );
1870
+ const { circle: o, viewportSize: l, reset: u, containerRef: p, containerProps: m } = le({
1871
+ onComplete: t,
1872
+ minRadius: r
1873
+ }), v = Math.max(1, l.width), x = Math.max(1, l.height), g = Math.min(v, x);
1874
+ return W(() => {
1875
+ e || u();
1876
+ }, [e, u]), /* @__PURE__ */ C.jsx(
1877
+ "div",
1878
+ {
1879
+ ref: p,
1880
+ "data-draw-circle": "true",
1881
+ className: i,
1882
+ style: {
1883
+ position: "absolute",
1884
+ inset: 0,
1885
+ cursor: e ? "crosshair" : "default",
1886
+ zIndex: 30,
1887
+ pointerEvents: e ? "auto" : "none",
1888
+ ...c
1889
+ },
1890
+ ...e ? m : {},
1891
+ children: o && o.radius > 0 && /* @__PURE__ */ C.jsx(
1892
+ "svg",
1893
+ {
1894
+ viewBox: "0 0 1 1",
1895
+ preserveAspectRatio: "none",
1896
+ style: {
1897
+ position: "absolute",
1898
+ inset: 0,
1899
+ width: "100%",
1900
+ height: "100%",
1901
+ overflow: "visible",
1902
+ pointerEvents: "none"
1903
+ },
1904
+ children: /* @__PURE__ */ C.jsx(
1905
+ "ellipse",
1906
+ {
1907
+ cx: o.center.x,
1908
+ cy: o.center.y,
1909
+ rx: o.radius * g / v,
1910
+ ry: o.radius * g / x,
1911
+ fill: n,
1912
+ fillOpacity: 0.15,
1913
+ stroke: n,
1914
+ strokeWidth: 3e-3,
1915
+ strokeLinecap: "round",
1916
+ strokeDasharray: "0.015 0.008"
1917
+ }
1918
+ )
1919
+ }
1920
+ )
1921
+ }
1922
+ );
1923
+ }
1924
+ function xt(t) {
1300
1925
  switch (t.type) {
1301
1926
  case "image":
1302
1927
  return `image:${t.src}:${t.label ?? ""}`;
@@ -1304,83 +1929,87 @@ function vt(t) {
1304
1929
  return `bbox:${t.bounds.x},${t.bounds.y},${t.bounds.w},${t.bounds.h}:${t.label ?? ""}`;
1305
1930
  case "polygon":
1306
1931
  return `polygon:${t.points.flat().join(",")}:${t.label ?? ""}`;
1932
+ case "circle":
1933
+ return `circle:${t.center.x},${t.center.y},${t.radius}:${t.label ?? ""}`;
1307
1934
  }
1308
1935
  }
1309
- function qt({
1936
+ function he({
1310
1937
  mainImage: t,
1311
1938
  mainImageAlt: r = "Main image",
1312
- effect: o = "elevate",
1313
- enabled: n = !0,
1314
- showAll: i = !1,
1315
- alphaThreshold: c = 30,
1316
- hoverLeaveDelay: a = 150,
1317
- children: s,
1318
- className: f = "",
1319
- style: l,
1320
- onHover: d,
1321
- onActiveChange: k,
1322
- onSelect: g
1939
+ effect: n = "elevate",
1940
+ enabled: e = !0,
1941
+ showAll: c = !1,
1942
+ alphaThreshold: i = 30,
1943
+ hoverLeaveDelay: s = 150,
1944
+ children: o,
1945
+ className: l = "",
1946
+ style: u,
1947
+ onHover: p,
1948
+ onActiveChange: m,
1949
+ onSelect: v
1323
1950
  }) {
1324
- const h = typeof o == "string" ? J[o] ?? J.elevate : o;
1325
- 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;
1951
+ const x = typeof n == "string" ? J[n] ?? J.elevate : n;
1952
+ W(() => {
1953
+ Xt(x);
1954
+ }, [x]);
1955
+ const [g, y] = O(() => /* @__PURE__ */ new Map()), d = M(
1956
+ (I) => {
1957
+ y((z) => {
1958
+ const L = z.get(I.id);
1959
+ if (L && xt(L) === xt(I))
1960
+ return z;
1961
+ const G = new Map(z);
1962
+ return G.set(I.id, I), G;
1336
1963
  });
1337
1964
  },
1338
1965
  []
1339
- ), w = P(($) => {
1340
- E((N) => {
1341
- if (!N.has($)) return N;
1342
- const Y = new Map(N);
1343
- return Y.delete($), Y;
1966
+ ), h = M((I) => {
1967
+ y((z) => {
1968
+ if (!z.has(I)) return z;
1969
+ const L = new Map(z);
1970
+ return L.delete(I), L;
1344
1971
  });
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);
1349
- 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(
1972
+ }, []), f = V(
1973
+ () => ({ registerCutout: d, unregisterCutout: h }),
1974
+ [d, h]
1975
+ ), w = V(() => Array.from(g.values()), [g]), { activeId: k, selectedId: b, hoveredId: A, viewportSize: _, boundsMap: X, contourMap: D, containerRef: U, containerProps: Q } = Ft(w, e, i, s), B = N(null), q = N(null), S = N(null);
1976
+ W(() => {
1977
+ A !== B.current && (B.current = A, p?.(A));
1978
+ }, [A, p]), W(() => {
1979
+ k !== q.current && (q.current = k, m?.(k));
1980
+ }, [k, m]), W(() => {
1981
+ b !== S.current && (S.current = b, v?.(b));
1982
+ }, [b, v]);
1983
+ const R = c || k !== null, P = V(
1357
1984
  () => ({
1358
- activeId: v,
1359
- selectedId: m,
1360
- hoveredId: M,
1361
- effect: h,
1362
- enabled: n,
1363
- showAll: i,
1364
- boundsMap: D,
1365
- isAnyActive: W
1985
+ activeId: k,
1986
+ selectedId: b,
1987
+ hoveredId: A,
1988
+ viewportSize: _,
1989
+ effect: x,
1990
+ enabled: e,
1991
+ showAll: c,
1992
+ boundsMap: X,
1993
+ contourMap: D,
1994
+ isAnyActive: R
1366
1995
  }),
1367
- [v, m, M, h, n, i, D, W]
1996
+ [k, b, A, _, x, e, c, X, D, R]
1368
1997
  );
1369
- return /* @__PURE__ */ I.jsx(Z.Provider, { value: u, children: /* @__PURE__ */ I.jsx(xt.Provider, { value: U, children: /* @__PURE__ */ I.jsxs(
1998
+ return /* @__PURE__ */ C.jsx(H.Provider, { value: f, children: /* @__PURE__ */ C.jsx(kt.Provider, { value: P, children: /* @__PURE__ */ C.jsxs(
1370
1999
  "div",
1371
2000
  {
1372
- ref: z,
1373
- className: f,
2001
+ ref: U,
2002
+ className: l,
1374
2003
  style: {
1375
2004
  position: "relative",
1376
2005
  width: "100%",
1377
2006
  overflow: "hidden",
1378
- cursor: W && n ? "pointer" : "default",
1379
- ...l
2007
+ cursor: R && e ? "pointer" : "default",
2008
+ ...u
1380
2009
  },
1381
- ...j,
2010
+ ...Q,
1382
2011
  children: [
1383
- /* @__PURE__ */ I.jsx(
2012
+ /* @__PURE__ */ C.jsx(
1384
2013
  "img",
1385
2014
  {
1386
2015
  src: t,
@@ -1391,52 +2020,60 @@ function qt({
1391
2020
  width: "100%",
1392
2021
  height: "auto",
1393
2022
  userSelect: "none",
1394
- transition: h.transition,
1395
- ...W && n ? h.mainImageHovered : {}
2023
+ transition: x.transition,
2024
+ ...R && e ? x.mainImageHovered : {}
1396
2025
  }
1397
2026
  }
1398
2027
  ),
1399
- /* @__PURE__ */ I.jsx(
2028
+ /* @__PURE__ */ C.jsx(
1400
2029
  "div",
1401
2030
  {
1402
2031
  style: {
1403
2032
  pointerEvents: "none",
1404
2033
  position: "absolute",
1405
2034
  inset: 0,
1406
- transition: h.transition,
1407
- opacity: W && n ? 1 : 0,
1408
- ...h.vignetteStyle
2035
+ transition: x.transition,
2036
+ opacity: R && e ? 1 : 0,
2037
+ ...x.vignetteStyle
1409
2038
  }
1410
2039
  }
1411
2040
  ),
1412
- s
2041
+ o
1413
2042
  ]
1414
2043
  }
1415
2044
  ) }) });
1416
2045
  }
1417
- const tt = qt;
1418
- tt.Cutout = Ht;
1419
- tt.BBoxCutout = Lt;
1420
- tt.PolygonCutout = Ft;
1421
- tt.Overlay = Ut;
1422
- tt.DrawPolygon = Gt;
2046
+ const F = he;
2047
+ F.Cutout = Qt;
2048
+ F.BBoxCutout = te;
2049
+ F.PolygonCutout = ee;
2050
+ F.CircleCutout = re;
2051
+ F.Overlay = oe;
2052
+ F.DrawPolygon = ie;
2053
+ F.DrawRectangle = ce;
2054
+ F.DrawCircle = ue;
1423
2055
  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,
2056
+ Vt as CircleHitTestStrategy,
2057
+ oe as CutoutOverlay,
2058
+ F as CutoutViewer,
2059
+ ue as DrawCircle,
2060
+ ie as DrawPolygon,
2061
+ ce as DrawRectangle,
2062
+ Ot as ImageHitTestStrategy,
2063
+ Nt as PolygonHitTestStrategy,
2064
+ Lt as RectHitTestStrategy,
2065
+ Bt as createHitTestStrategy,
2066
+ bt as defineKeyframes,
2067
+ Ut as elevateEffect,
2068
+ qt as glowEffect,
1434
2069
  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
2070
+ Gt as liftEffect,
2071
+ Zt as shimmerEffect,
2072
+ Kt as subtleEffect,
2073
+ Jt as traceEffect,
2074
+ de as useCutout,
2075
+ Ft as useCutoutHitTest,
2076
+ le as useDrawCircle,
2077
+ se as useDrawPolygon,
2078
+ ae as useDrawRectangle
1442
2079
  };