react-img-cutout 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,69 +1,69 @@
1
- import kt, { useState as tt, useRef as B, useCallback as O, useMemo as D, useEffect as N, useContext as F, createContext as at } from "react";
2
- var Q = { exports: {} }, G = {};
3
- var ct;
1
+ import kt, { useState as 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 = {};
3
+ var ut;
4
4
  function Et() {
5
- if (ct) return G;
6
- ct = 1;
5
+ if (ut) return G;
6
+ ut = 1;
7
7
  var t = /* @__PURE__ */ Symbol.for("react.transitional.element"), r = /* @__PURE__ */ Symbol.for("react.fragment");
8
- function o(n, a, l) {
9
- var i = null;
10
- if (l !== void 0 && (i = "" + l), a.key !== void 0 && (i = "" + a.key), "key" in a) {
11
- l = {};
12
- for (var s in a)
13
- s !== "key" && (l[s] = a[s]);
14
- } else l = a;
15
- return a = l.ref, {
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, {
16
16
  $$typeof: t,
17
17
  type: n,
18
- key: i,
19
- ref: a !== void 0 ? a : null,
20
- props: l
18
+ key: a,
19
+ ref: i !== void 0 ? i : null,
20
+ props: c
21
21
  };
22
22
  }
23
23
  return G.Fragment = r, G.jsx = o, G.jsxs = o, G;
24
24
  }
25
- var X = {};
25
+ var q = {};
26
26
  var ft;
27
27
  function It() {
28
28
  return ft || (ft = 1, process.env.NODE_ENV !== "production" && (function() {
29
29
  function t(e) {
30
30
  if (e == null) return null;
31
31
  if (typeof e == "function")
32
- return e.$$typeof === y ? null : e.displayName || e.name || null;
32
+ return e.$$typeof === R ? null : e.displayName || e.name || null;
33
33
  if (typeof e == "string") return e;
34
34
  switch (e) {
35
- case S:
35
+ case x:
36
36
  return "Fragment";
37
- case m:
37
+ case u:
38
38
  return "Profiler";
39
- case T:
39
+ case w:
40
40
  return "StrictMode";
41
41
  case M:
42
42
  return "Suspense";
43
- case V:
43
+ case D:
44
44
  return "SuspenseList";
45
- case k:
45
+ case _:
46
46
  return "Activity";
47
47
  }
48
48
  if (typeof e == "object")
49
49
  switch (typeof e.tag == "number" && console.error(
50
50
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
51
51
  ), e.$$typeof) {
52
- case w:
52
+ case E:
53
53
  return "Portal";
54
- case P:
54
+ case v:
55
55
  return e.displayName || "Context";
56
- case j:
57
- return (e._context.displayName || "Context") + ".Consumer";
58
56
  case b:
59
- var c = e.render;
60
- return e = e.displayName, e || (e = c.displayName || c.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
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
61
  case z:
62
- return c = e.displayName || null, c !== null ? c : t(e.type) || "Memo";
63
- case E:
64
- c = e._payload, e = e._init;
62
+ return p = e.displayName || null, p !== null ? p : t(e.type) || "Memo";
63
+ case j:
64
+ p = e._payload, e = e._init;
65
65
  try {
66
- return t(e(c));
66
+ return t(e(p));
67
67
  } catch {
68
68
  }
69
69
  }
@@ -75,74 +75,74 @@ function It() {
75
75
  function o(e) {
76
76
  try {
77
77
  r(e);
78
- var c = !1;
78
+ var p = !1;
79
79
  } catch {
80
- c = !0;
80
+ p = !0;
81
81
  }
82
- if (c) {
83
- c = console;
84
- var x = c.error, I = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
85
- return x.call(
86
- c,
82
+ if (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,
87
87
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
88
- I
88
+ T
89
89
  ), r(e);
90
90
  }
91
91
  }
92
92
  function n(e) {
93
- if (e === S) return "<>";
94
- if (typeof e == "object" && e !== null && e.$$typeof === E)
93
+ if (e === x) return "<>";
94
+ if (typeof e == "object" && e !== null && e.$$typeof === j)
95
95
  return "<...>";
96
96
  try {
97
- var c = t(e);
98
- return c ? "<" + c + ">" : "<...>";
97
+ var p = t(e);
98
+ return p ? "<" + p + ">" : "<...>";
99
99
  } catch {
100
100
  return "<...>";
101
101
  }
102
102
  }
103
- function a() {
104
- var e = v.A;
103
+ function i() {
104
+ var e = A.A;
105
105
  return e === null ? null : e.getOwner();
106
106
  }
107
- function l() {
107
+ function c() {
108
108
  return Error("react-stack-top-frame");
109
109
  }
110
- function i(e) {
111
- if ($.call(e, "key")) {
112
- var c = Object.getOwnPropertyDescriptor(e, "key").get;
113
- if (c && c.isReactWarning) return !1;
110
+ function a(e) {
111
+ if (W.call(e, "key")) {
112
+ var p = Object.getOwnPropertyDescriptor(e, "key").get;
113
+ if (p && p.isReactWarning) return !1;
114
114
  }
115
115
  return e.key !== void 0;
116
116
  }
117
- function s(e, c) {
118
- function x() {
119
- W || (W = !0, console.error(
117
+ function s(e, p) {
118
+ function C() {
119
+ N || (N = !0, console.error(
120
120
  "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
121
- c
121
+ p
122
122
  ));
123
123
  }
124
- x.isReactWarning = !0, Object.defineProperty(e, "key", {
125
- get: x,
124
+ C.isReactWarning = !0, Object.defineProperty(e, "key", {
125
+ get: C,
126
126
  configurable: !0
127
127
  });
128
128
  }
129
- function d() {
129
+ function f() {
130
130
  var e = t(this.type);
131
131
  return Y[e] || (Y[e] = !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
133
  )), e = this.props.ref, e !== void 0 ? e : null;
134
134
  }
135
- function u(e, c, x, I, Z, nt) {
136
- var A = x.ref;
135
+ function l(e, p, C, T, et, ot) {
136
+ var S = C.ref;
137
137
  return e = {
138
- $$typeof: g,
138
+ $$typeof: y,
139
139
  type: e,
140
- key: c,
141
- props: x,
142
- _owner: I
143
- }, (A !== void 0 ? A : null) !== null ? Object.defineProperty(e, "ref", {
140
+ key: p,
141
+ props: C,
142
+ _owner: T
143
+ }, (S !== void 0 ? S : null) !== null ? Object.defineProperty(e, "ref", {
144
144
  enumerable: !1,
145
- get: d
145
+ get: f
146
146
  }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
147
147
  configurable: !1,
148
148
  enumerable: !1,
@@ -157,128 +157,128 @@ function It() {
157
157
  configurable: !1,
158
158
  enumerable: !1,
159
159
  writable: !0,
160
- value: Z
160
+ value: et
161
161
  }), Object.defineProperty(e, "_debugTask", {
162
162
  configurable: !1,
163
163
  enumerable: !1,
164
164
  writable: !0,
165
- value: nt
165
+ value: ot
166
166
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
167
167
  }
168
- function p(e, c, x, I, Z, nt) {
169
- var A = c.children;
170
- if (A !== void 0)
171
- if (I)
172
- if (L(A)) {
173
- for (I = 0; I < A.length; I++)
174
- R(A[I]);
175
- Object.freeze && Object.freeze(A);
168
+ function d(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);
176
176
  } else
177
177
  console.error(
178
178
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
179
179
  );
180
- else R(A);
181
- if ($.call(c, "key")) {
182
- A = t(e);
183
- var H = Object.keys(c).filter(function(wt) {
180
+ else k(S);
181
+ if (W.call(p, "key")) {
182
+ S = t(e);
183
+ var L = Object.keys(p).filter(function(wt) {
184
184
  return wt !== "key";
185
185
  });
186
- I = 0 < H.length ? "{key: someKey, " + H.join(": ..., ") + ": ...}" : "{key: someKey}", ut[A + I] || (H = 0 < H.length ? "{" + H.join(": ..., ") + ": ...}" : "{}", console.error(
186
+ T = 0 < L.length ? "{key: someKey, " + L.join(": ..., ") + ": ...}" : "{key: someKey}", ct[S + T] || (L = 0 < L.length ? "{" + L.join(": ..., ") + ": ...}" : "{}", console.error(
187
187
  `A props object containing a "key" prop is being spread into JSX:
188
188
  let props = %s;
189
189
  <%s {...props} />
190
190
  React keys must be passed directly to JSX without using spread:
191
191
  let props = %s;
192
192
  <%s key={someKey} {...props} />`,
193
- I,
194
- A,
195
- H,
196
- A
197
- ), ut[A + I] = !0);
193
+ T,
194
+ S,
195
+ L,
196
+ S
197
+ ), ct[S + T] = !0);
198
198
  }
199
- if (A = null, x !== void 0 && (o(x), A = "" + x), i(c) && (o(c.key), A = "" + c.key), "key" in c) {
200
- x = {};
201
- for (var st in c)
202
- st !== "key" && (x[st] = c[st]);
203
- } else x = c;
204
- return A && s(
205
- x,
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
206
  typeof e == "function" ? e.displayName || e.name || "Unknown" : e
207
- ), u(
207
+ ), l(
208
208
  e,
209
- A,
210
- x,
211
- a(),
212
- Z,
213
- nt
209
+ S,
210
+ C,
211
+ i(),
212
+ et,
213
+ ot
214
214
  );
215
215
  }
216
- function R(e) {
217
- h(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === E && (e._payload.status === "fulfilled" ? h(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
216
+ function k(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));
218
218
  }
219
- function h(e) {
220
- return typeof e == "object" && e !== null && e.$$typeof === g;
219
+ function g(e) {
220
+ return typeof e == "object" && e !== null && e.$$typeof === y;
221
221
  }
222
- var f = kt, g = /* @__PURE__ */ Symbol.for("react.transitional.element"), w = /* @__PURE__ */ Symbol.for("react.portal"), S = /* @__PURE__ */ Symbol.for("react.fragment"), T = /* @__PURE__ */ Symbol.for("react.strict_mode"), m = /* @__PURE__ */ Symbol.for("react.profiler"), j = /* @__PURE__ */ Symbol.for("react.consumer"), P = /* @__PURE__ */ Symbol.for("react.context"), b = /* @__PURE__ */ Symbol.for("react.forward_ref"), M = /* @__PURE__ */ Symbol.for("react.suspense"), V = /* @__PURE__ */ Symbol.for("react.suspense_list"), z = /* @__PURE__ */ Symbol.for("react.memo"), E = /* @__PURE__ */ Symbol.for("react.lazy"), k = /* @__PURE__ */ Symbol.for("react.activity"), y = /* @__PURE__ */ Symbol.for("react.client.reference"), v = f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, $ = Object.prototype.hasOwnProperty, L = Array.isArray, _ = console.createTask ? console.createTask : function() {
222
+ var 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() {
223
223
  return null;
224
224
  };
225
- f = {
225
+ h = {
226
226
  react_stack_bottom_frame: function(e) {
227
227
  return e();
228
228
  }
229
229
  };
230
- var W, Y = {}, U = f.react_stack_bottom_frame.bind(
231
- f,
232
- l
233
- )(), lt = _(n(l)), ut = {};
234
- X.Fragment = S, X.jsx = function(e, c, x) {
235
- var I = 1e4 > v.recentlyCreatedOwnerStacks++;
236
- return p(
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
237
  e,
238
- c,
239
- x,
238
+ p,
239
+ C,
240
240
  !1,
241
- I ? Error("react-stack-top-frame") : U,
242
- I ? _(n(e)) : lt
241
+ T ? Error("react-stack-top-frame") : X,
242
+ T ? $(n(e)) : lt
243
243
  );
244
- }, X.jsxs = function(e, c, x) {
245
- var I = 1e4 > v.recentlyCreatedOwnerStacks++;
246
- return p(
244
+ }, q.jsxs = function(e, p, C) {
245
+ var T = 1e4 > A.recentlyCreatedOwnerStacks++;
246
+ return d(
247
247
  e,
248
- c,
249
- x,
248
+ p,
249
+ C,
250
250
  !0,
251
- I ? Error("react-stack-top-frame") : U,
252
- I ? _(n(e)) : lt
251
+ T ? Error("react-stack-top-frame") : X,
252
+ T ? $(n(e)) : lt
253
253
  );
254
254
  };
255
- })()), X;
255
+ })()), q;
256
256
  }
257
257
  var dt;
258
- function At() {
259
- return dt || (dt = 1, process.env.NODE_ENV === "production" ? Q.exports = Et() : Q.exports = It()), Q.exports;
258
+ function Rt() {
259
+ return dt || (dt = 1, process.env.NODE_ENV === "production" ? rt.exports = Et() : rt.exports = It()), rt.exports;
260
260
  }
261
- var C = At();
262
- function Rt(t, r) {
261
+ var I = Rt();
262
+ function At(t, r) {
263
263
  const o = new Uint8Array(r);
264
264
  for (let n = 0; n < r; n++)
265
265
  o[n] = t[n * 4 + 3];
266
266
  return o;
267
267
  }
268
- function _t(t, r, o, n) {
268
+ function Ct(t, r, o, n) {
269
269
  if (r <= 0 || o <= 0) return { x: 0, y: 0, w: 1, h: 1 };
270
- let a = r, l = o, i = 0, s = 0, d = !1;
271
- for (let u = 0; u < o; u++)
272
- for (let p = 0; p < r; p++)
273
- t[u * r + p] > n && (p < a && (a = p), p > i && (i = p), u < l && (l = u), u > s && (s = u), d = !0);
274
- return d ? {
275
- x: a / r,
276
- y: l / o,
277
- w: (i - a + 1) / r,
278
- h: (s - l + 1) / o
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
279
279
  } : { x: 0, y: 0, w: 1, h: 1 };
280
280
  }
281
- class Ct {
281
+ class _t {
282
282
  id;
283
283
  bounds = { x: 0, y: 0, w: 1, h: 1 };
284
284
  /** URL of the cutout mask image */
@@ -309,19 +309,19 @@ class Ct {
309
309
  */
310
310
  async prepare() {
311
311
  const r = new Image();
312
- r.crossOrigin = "anonymous", r.src = this.src, await new Promise((i) => {
313
- r.onload = () => i(), r.onerror = () => i();
312
+ r.crossOrigin = "anonymous", r.src = this.src, await new Promise((a) => {
313
+ r.onload = () => a(), r.onerror = () => a();
314
314
  });
315
315
  const o = r.naturalWidth, n = r.naturalHeight;
316
316
  if (o <= 0 || n <= 0) return;
317
- const a = document.createElement("canvas");
318
- a.width = o, a.height = n;
319
- const l = a.getContext("2d", { willReadFrequently: !0 });
320
- if (l)
317
+ const i = document.createElement("canvas");
318
+ i.width = o, i.height = n;
319
+ const c = i.getContext("2d", { willReadFrequently: !0 });
320
+ if (c)
321
321
  try {
322
- l.drawImage(r, 0, 0);
323
- const i = l.getImageData(0, 0, o, n);
324
- this.alpha = Rt(i.data, o * n), this.width = o, this.height = n, this.bounds = _t(this.alpha, o, n, this.threshold);
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);
325
325
  } catch {
326
326
  this.alpha = new Uint8Array(0);
327
327
  }
@@ -345,14 +345,14 @@ class Ct {
345
345
  if (this.alpha.length === 0) return !1;
346
346
  const n = this.bounds;
347
347
  if (r < n.x || r > n.x + n.w || o < n.y || o > n.y + n.h) return !1;
348
- const a = Math.min(this.width - 1, Math.max(0, Math.floor(r * this.width))), l = Math.min(
348
+ const i = Math.min(this.width - 1, Math.max(0, Math.floor(r * this.width))), c = Math.min(
349
349
  this.height - 1,
350
350
  Math.max(0, Math.floor(o * this.height))
351
351
  );
352
- return this.alpha[l * this.width + a] > this.threshold;
352
+ return this.alpha[c * this.width + i] > this.threshold;
353
353
  }
354
354
  }
355
- class Tt {
355
+ class jt {
356
356
  id;
357
357
  bounds;
358
358
  constructor(r) {
@@ -363,28 +363,28 @@ class Tt {
363
363
  return r >= n.x && r <= n.x + n.w && o >= n.y && o <= n.y + n.h;
364
364
  }
365
365
  }
366
- function St(t, r, o) {
366
+ function Tt(t, r, o) {
367
367
  let n = !1;
368
- for (let a = 0, l = o.length - 1; a < o.length; l = a++) {
369
- const i = o[a][0], s = o[a][1], d = o[l][0], u = o[l][1];
370
- s > r != u > r && t < (d - i) * (r - s) / (u - s) + i && (n = !n);
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);
371
371
  }
372
372
  return n;
373
373
  }
374
- class jt {
374
+ class St {
375
375
  id;
376
376
  bounds;
377
377
  points;
378
378
  constructor(r) {
379
379
  this.id = r.id, this.points = r.points;
380
- let o = 1 / 0, n = 1 / 0, a = -1 / 0, l = -1 / 0;
381
- for (const [i, s] of r.points)
382
- i < o && (o = i), i > a && (a = i), s < n && (n = s), s > l && (l = s);
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);
383
383
  this.bounds = {
384
384
  x: o,
385
385
  y: n,
386
- w: a - o,
387
- h: l - n
386
+ w: i - o,
387
+ h: c - n
388
388
  };
389
389
  }
390
390
  /**
@@ -401,20 +401,20 @@ class jt {
401
401
  */
402
402
  hitTest(r, o) {
403
403
  const n = this.bounds;
404
- return r < n.x || r > n.x + n.w || o < n.y || o > n.y + n.h ? !1 : St(r, o, this.points);
404
+ return r < n.x || r > n.x + n.w || o < n.y || o > n.y + n.h ? !1 : Tt(r, o, this.points);
405
405
  }
406
406
  }
407
- function $t(t, r) {
407
+ function Pt(t, r) {
408
408
  switch (t.type) {
409
409
  case "image":
410
- return new Ct(t, r);
410
+ return new _t(t, r);
411
411
  case "bbox":
412
- return new Tt(t);
413
- case "polygon":
414
412
  return new jt(t);
413
+ case "polygon":
414
+ return new St(t);
415
415
  }
416
416
  }
417
- function Pt(t) {
417
+ function $t(t) {
418
418
  switch (t.type) {
419
419
  case "image":
420
420
  return `${t.id}:image:${t.src}:${t.label ?? ""}`;
@@ -425,102 +425,102 @@ function Pt(t) {
425
425
  }
426
426
  }
427
427
  function Mt(t, r = !0, o = 30, n = 150) {
428
- const [a, l] = tt(null), [i, s] = tt(null), d = B(null), u = B([]), [p, R] = tt({}), h = Math.min(255, Math.max(0, o)), f = B(null), g = O(() => {
429
- f.current === null && (f.current = setTimeout(() => {
430
- f.current = null, l(null);
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
431
  }, n));
432
- }, [n]), w = O(() => {
433
- f.current !== null && (clearTimeout(f.current), f.current = null);
434
- }, []), S = t.map(Pt).join("|"), T = D(() => t, [S]);
435
- N(() => {
432
+ }, [n]), E = P(() => {
433
+ h.current !== null && (clearTimeout(h.current), h.current = null);
434
+ }, []), x = t.map($t).join("|"), w = B(() => t, [x]);
435
+ O(() => {
436
436
  if (!r) {
437
- u.current = [];
437
+ l.current = [];
438
438
  return;
439
439
  }
440
- let E = !1, k = [];
441
- async function y() {
442
- const v = [], $ = {};
443
- for (const L of T) {
444
- const _ = $t(L, h);
445
- if (_.prepare && await _.prepare(), E) return;
446
- v.push(_), $[_.id] = _.bounds;
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;
447
447
  }
448
- E || (k = v, u.current = v, R($));
448
+ j || (_ = A, l.current = A, k(W));
449
449
  }
450
- return y(), () => {
451
- E = !0;
452
- for (const v of k)
453
- v.dispose?.();
450
+ return R(), () => {
451
+ j = !0;
452
+ for (const A of _)
453
+ A.dispose?.();
454
454
  };
455
- }, [T, r, h]);
456
- const m = O(
457
- (E, k) => {
458
- const y = u.current;
459
- for (let v = y.length - 1; v >= 0; v--)
460
- if (y[v].hitTest(E, k))
461
- return y[v].id;
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;
462
462
  return null;
463
463
  },
464
464
  []
465
- ), j = O(
466
- (E) => {
467
- const k = d.current;
468
- if (!k) return null;
469
- const y = k.getBoundingClientRect(), v = (E.clientX - y.left) / y.width, $ = (E.clientY - y.top) / y.height;
470
- return v < 0 || v > 1 || $ < 0 || $ > 1 ? null : { nx: v, ny: $ };
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 };
471
471
  },
472
472
  []
473
- ), P = O(
474
- (E) => {
473
+ ), v = P(
474
+ (j) => {
475
475
  if (!r) return;
476
- const k = j(E);
477
- if (!k) {
478
- g();
476
+ const _ = b(j);
477
+ if (!_) {
478
+ y();
479
479
  return;
480
480
  }
481
- const y = m(k.nx, k.ny);
482
- if (y === null) {
483
- if (E.target?.closest('[data-cutout-overlay="true"]')) {
484
- w();
481
+ const R = u(_.nx, _.ny);
482
+ if (R === null) {
483
+ if (j.target?.closest('[data-cutout-overlay="true"]')) {
484
+ E();
485
485
  return;
486
486
  }
487
- g();
487
+ y();
488
488
  return;
489
489
  }
490
- w(), l(y);
490
+ E(), c(R);
491
491
  },
492
- [r, j, m, g, w]
493
- ), b = O(() => {
494
- g();
495
- }, [g]), M = O(
496
- (E) => {
492
+ [r, b, u, y, E]
493
+ ), m = P(() => {
494
+ y();
495
+ }, [y]), M = P(
496
+ (j) => {
497
497
  if (!r) return;
498
- const k = j(E);
499
- if (!k) {
498
+ const _ = b(j);
499
+ if (!_) {
500
500
  s(null);
501
501
  return;
502
502
  }
503
- const y = m(k.nx, k.ny);
504
- s(y === i || y === null ? null : y);
503
+ const R = u(_.nx, _.ny);
504
+ s(R === a || R === null ? null : R);
505
505
  },
506
- [r, j, m, i]
507
- ), V = i ?? a, z = r ? p : {};
508
- return N(() => () => {
509
- w();
510
- }, [w]), {
511
- hoveredId: a,
512
- selectedId: i,
513
- activeId: V,
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
514
  boundsMap: z,
515
- containerRef: d,
515
+ containerRef: f,
516
516
  containerProps: {
517
- onPointerMove: P,
518
- onPointerLeave: b,
517
+ onPointerMove: v,
518
+ onPointerLeave: m,
519
519
  onClick: M
520
520
  }
521
521
  };
522
522
  }
523
- function it(t, r) {
523
+ function at(t, r) {
524
524
  return { name: t, css: r };
525
525
  }
526
526
  const pt = /* @__PURE__ */ new Set();
@@ -535,9 +535,9 @@ ${r.css}
535
535
  }`, document.head.appendChild(o);
536
536
  }
537
537
  }
538
- const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
538
+ const K = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
539
539
  name: "elevate",
540
- transition: J,
540
+ transition: K,
541
541
  mainImageHovered: {
542
542
  filter: "brightness(0.45) saturate(0.7)"
543
543
  },
@@ -575,9 +575,9 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
575
575
  stroke: "transparent",
576
576
  strokeWidth: 1
577
577
  }
578
- }, Nt = {
578
+ }, Dt = {
579
579
  name: "glow",
580
- transition: J,
580
+ transition: K,
581
581
  mainImageHovered: {
582
582
  filter: "brightness(0.55) saturate(0.8)"
583
583
  },
@@ -615,9 +615,9 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
615
615
  stroke: "transparent",
616
616
  strokeWidth: 1
617
617
  }
618
- }, Yt = {
618
+ }, Nt = {
619
619
  name: "lift",
620
- transition: J,
620
+ transition: K,
621
621
  mainImageHovered: {
622
622
  filter: "brightness(0.4)"
623
623
  },
@@ -655,7 +655,7 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
655
655
  stroke: "transparent",
656
656
  strokeWidth: 1
657
657
  }
658
- }, Dt = {
658
+ }, Yt = {
659
659
  name: "subtle",
660
660
  transition: "all 0.3s ease",
661
661
  mainImageHovered: {
@@ -694,11 +694,11 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
694
694
  stroke: "transparent",
695
695
  strokeWidth: 1
696
696
  }
697
- }, ht = it(
697
+ }, ht = at(
698
698
  "_ricut-trace-stroke",
699
699
  `from { stroke-dashoffset: 0; }
700
700
  to { stroke-dashoffset: -1; }`
701
- ), gt = it(
701
+ ), gt = at(
702
702
  "_ricut-trace-glow",
703
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
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)); }
@@ -707,7 +707,7 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
707
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
708
  ), Vt = {
709
709
  name: "trace",
710
- transition: J,
710
+ transition: K,
711
711
  keyframes: [ht, gt],
712
712
  mainImageHovered: {
713
713
  filter: "brightness(0.35) saturate(0.5)"
@@ -749,7 +749,7 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
749
749
  stroke: "transparent",
750
750
  strokeWidth: 1
751
751
  }
752
- }, mt = it(
752
+ }, mt = at(
753
753
  "_ricut-shimmer",
754
754
  `0%, 100% {
755
755
  filter: brightness(1.05) contrast(1.02)
@@ -766,9 +766,9 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
766
766
  drop-shadow(0 0 6px rgba(255, 255, 255, 0.12))
767
767
  drop-shadow(0 12px 32px rgba(0, 0, 0, 0.4));
768
768
  }`
769
- ), Ht = {
769
+ ), Bt = {
770
770
  name: "shimmer",
771
- transition: J,
771
+ transition: K,
772
772
  keyframes: [mt],
773
773
  mainImageHovered: {
774
774
  filter: "brightness(0.35) saturate(0.6)"
@@ -810,48 +810,48 @@ const J = "all 0.5s cubic-bezier(0.22, 1, 0.36, 1)", Ot = {
810
810
  stroke: "transparent",
811
811
  strokeWidth: 1
812
812
  }
813
- }, q = {
813
+ }, J = {
814
814
  elevate: Ot,
815
- glow: Nt,
816
- lift: Yt,
817
- subtle: Dt,
815
+ glow: Dt,
816
+ lift: Nt,
817
+ subtle: Yt,
818
818
  trace: Vt,
819
- shimmer: Ht
820
- }, et = at(null), xt = at(null);
821
- function rt() {
822
- const t = F(xt);
819
+ shimmer: Bt
820
+ }, Z = it(null), xt = it(null);
821
+ function nt() {
822
+ const t = H(xt);
823
823
  if (!t) throw new Error("Must be used inside <CutoutViewer>");
824
824
  return t;
825
825
  }
826
- const K = at(null);
827
- function qt() {
828
- const t = F(K);
826
+ const Q = it(null);
827
+ function Kt() {
828
+ const t = H(Q);
829
829
  if (!t)
830
830
  throw new Error("useCutout must be used inside <CutoutViewer.Cutout>");
831
831
  return t;
832
832
  }
833
- function Bt({ id: t, src: r, label: o, effect: n, children: a, renderLayer: l }) {
834
- const i = F(et), s = rt();
835
- if (!i)
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)
836
836
  throw new Error("<CutoutViewer.Cutout> must be used inside <CutoutViewer>");
837
- N(() => (i.registerCutout({ type: "image", id: t, src: r, label: o }), () => i.unregisterCutout(t)), [t, r, o, i]);
838
- const d = n ? typeof n == "string" ? q[n] ?? s.effect : n : s.effect, u = s.activeId === t, p = s.hoveredId === t, R = s.selectedId === t, h = { x: 0, y: 0, w: 1, h: 1 }, f = s.boundsMap[t] ?? h;
839
- let g;
840
- !s.enabled || !s.isAnyActive && !s.showAll ? g = d.cutoutIdle : s.showAll || u ? g = d.cutoutActive : g = d.cutoutInactive;
841
- const w = D(
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(
842
842
  () => ({
843
843
  id: t,
844
844
  label: o,
845
- bounds: f,
846
- isActive: u,
847
- isHovered: p,
848
- isSelected: R,
849
- effect: d
845
+ bounds: h,
846
+ isActive: l,
847
+ isHovered: d,
848
+ isSelected: k,
849
+ effect: f
850
850
  }),
851
- [t, o, f, u, p, R, d]
851
+ [t, o, h, l, d, k, f]
852
852
  );
853
- return /* @__PURE__ */ C.jsxs(K.Provider, { value: w, children: [
854
- /* @__PURE__ */ C.jsx(
853
+ return /* @__PURE__ */ I.jsxs(Q.Provider, { value: E, children: [
854
+ /* @__PURE__ */ I.jsx(
855
855
  "div",
856
856
  {
857
857
  "data-cutout-id": t,
@@ -859,11 +859,11 @@ function Bt({ id: t, src: r, label: o, effect: n, children: a, renderLayer: l })
859
859
  pointerEvents: "none",
860
860
  position: "absolute",
861
861
  inset: 0,
862
- zIndex: u ? 20 : 10,
863
- transition: d.transition,
864
- ...g
862
+ zIndex: l ? 20 : 10,
863
+ transition: f.transition,
864
+ ...y
865
865
  },
866
- children: l ? l({ isActive: u, isHovered: p, isSelected: R, bounds: f, effect: d }) : /* @__PURE__ */ C.jsx(
866
+ children: c ? c({ isActive: l, isHovered: d, isSelected: k, bounds: h, effect: f }) : /* @__PURE__ */ I.jsx(
867
867
  "img",
868
868
  {
869
869
  src: r,
@@ -879,49 +879,49 @@ function Bt({ id: t, src: r, label: o, effect: n, children: a, renderLayer: l })
879
879
  )
880
880
  }
881
881
  ),
882
- a
882
+ i
883
883
  ] });
884
884
  }
885
- function bt(t) {
885
+ function yt(t) {
886
886
  const { filter: r, ...o } = t;
887
887
  return o;
888
888
  }
889
- function Ft({
889
+ function Lt({
890
890
  id: t,
891
891
  bounds: r,
892
892
  label: o,
893
893
  effect: n,
894
- children: a,
895
- renderLayer: l
894
+ children: i,
895
+ renderLayer: c
896
896
  }) {
897
- const i = F(et), s = rt();
898
- if (!i)
897
+ const a = H(Z), s = nt();
898
+ if (!a)
899
899
  throw new Error(
900
900
  "<CutoutViewer.BBoxCutout> must be used inside <CutoutViewer>"
901
901
  );
902
- const { x: d, y: u, w: p, h: R } = r;
903
- N(() => (i.registerCutout({ type: "bbox", id: t, bounds: { x: d, y: u, w: p, h: R }, label: o }), () => i.unregisterCutout(t)), [t, d, u, p, R, o, i]);
904
- const h = n ? typeof n == "string" ? q[n] ?? s.effect : n : s.effect, f = s.activeId === t, g = s.hoveredId === t, w = s.selectedId === t, S = { x: 0, y: 0, w: 1, h: 1 }, T = s.boundsMap[t] ?? S;
905
- let m, j;
906
- !s.enabled || !s.isAnyActive && !s.showAll ? (j = { ...h.cutoutIdle, filter: "none", opacity: 0 }, m = h.geometryIdle) : s.showAll || f ? (j = bt(h.cutoutActive), m = h.geometryActive) : (j = bt(h.cutoutInactive), m = h.geometryInactive);
907
- const b = m ?? {
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 ?? {
908
908
  fill: "rgba(37, 99, 235, 0.15)",
909
909
  stroke: "rgba(37, 99, 235, 0.6)",
910
910
  strokeWidth: 2
911
- }, M = D(
911
+ }, M = B(
912
912
  () => ({
913
913
  id: t,
914
914
  label: o,
915
- bounds: T,
916
- isActive: f,
917
- isHovered: g,
918
- isSelected: w,
919
- effect: h
915
+ bounds: w,
916
+ isActive: h,
917
+ isHovered: y,
918
+ isSelected: E,
919
+ effect: g
920
920
  }),
921
- [t, o, T, f, g, w, h]
921
+ [t, o, w, h, y, E, g]
922
922
  );
923
- return /* @__PURE__ */ C.jsxs(K.Provider, { value: M, children: [
924
- /* @__PURE__ */ C.jsx(
923
+ return /* @__PURE__ */ I.jsxs(Q.Provider, { value: M, children: [
924
+ /* @__PURE__ */ I.jsx(
925
925
  "div",
926
926
  {
927
927
  "data-cutout-id": t,
@@ -929,11 +929,11 @@ function Ft({
929
929
  pointerEvents: "none",
930
930
  position: "absolute",
931
931
  inset: 0,
932
- zIndex: f ? 20 : 10,
933
- transition: h.transition,
934
- ...j
932
+ zIndex: h ? 20 : 10,
933
+ transition: g.transition,
934
+ ...b
935
935
  },
936
- children: l ? l({ isActive: f, isHovered: g, isSelected: w, bounds: T, effect: h }) : /* @__PURE__ */ C.jsx(
936
+ children: c ? c({ isActive: h, isHovered: y, isSelected: E, bounds: w, effect: g }) : /* @__PURE__ */ I.jsx(
937
937
  "svg",
938
938
  {
939
939
  viewBox: "0 0 1 1",
@@ -944,25 +944,25 @@ function Ft({
944
944
  width: "100%",
945
945
  height: "100%",
946
946
  overflow: "visible",
947
- filter: b.glow ? `drop-shadow(${b.glow.split(",")[0]?.trim() ?? ""})` : "none"
947
+ filter: m.glow ? `drop-shadow(${m.glow.split(",")[0]?.trim() ?? ""})` : "none"
948
948
  },
949
- children: /* @__PURE__ */ C.jsx(
949
+ children: /* @__PURE__ */ I.jsx(
950
950
  "rect",
951
951
  {
952
- x: T.x,
953
- y: T.y,
954
- width: T.w,
955
- height: T.h,
952
+ x: w.x,
953
+ y: w.y,
954
+ width: w.w,
955
+ height: w.h,
956
956
  rx: 4e-3,
957
- fill: b.fill,
958
- stroke: b.stroke,
959
- strokeWidth: (b.strokeWidth ?? 2) * 15e-4,
960
- strokeLinecap: b.strokeDasharray ? "round" : void 0,
961
- strokeDasharray: b.strokeDasharray,
962
- pathLength: b.strokeDasharray ? 1 : void 0,
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,
963
963
  style: {
964
- transition: h.transition,
965
- animation: b.animation
964
+ transition: g.transition,
965
+ animation: m.animation
966
966
  }
967
967
  }
968
968
  )
@@ -970,49 +970,49 @@ function Ft({
970
970
  )
971
971
  }
972
972
  ),
973
- a
973
+ i
974
974
  ] });
975
975
  }
976
- function yt(t) {
976
+ function bt(t) {
977
977
  const { filter: r, ...o } = t;
978
978
  return o;
979
979
  }
980
- function zt({
980
+ function Ft({
981
981
  id: t,
982
982
  points: r,
983
983
  label: o,
984
984
  effect: n,
985
- children: a,
986
- renderLayer: l
985
+ children: i,
986
+ renderLayer: c
987
987
  }) {
988
- const i = F(et), s = rt();
989
- if (!i)
988
+ const a = H(Z), s = nt();
989
+ if (!a)
990
990
  throw new Error(
991
991
  "<CutoutViewer.PolygonCutout> must be used inside <CutoutViewer>"
992
992
  );
993
- const d = r.flat().join(",");
994
- N(() => (i.registerCutout({ type: "polygon", id: t, points: r, label: o }), () => i.unregisterCutout(t)), [t, d, o, i]);
995
- const u = n ? typeof n == "string" ? q[n] ?? s.effect : n : s.effect, p = s.activeId === t, R = s.hoveredId === t, h = s.selectedId === t, f = { x: 0, y: 0, w: 1, h: 1 }, g = s.boundsMap[t] ?? f;
996
- let w, S;
997
- !s.enabled || !s.isAnyActive && !s.showAll ? (S = { ...u.cutoutIdle, filter: "none", opacity: 0 }, w = u.geometryIdle) : s.showAll || p ? (S = yt(u.cutoutActive), w = u.geometryActive) : (S = yt(u.cutoutInactive), w = u.geometryInactive);
998
- const m = w ?? {
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 ?? {
999
999
  fill: "rgba(37, 99, 235, 0.15)",
1000
1000
  stroke: "rgba(37, 99, 235, 0.6)",
1001
1001
  strokeWidth: 2
1002
- }, j = D(
1002
+ }, b = B(
1003
1003
  () => ({
1004
1004
  id: t,
1005
1005
  label: o,
1006
- bounds: g,
1007
- isActive: p,
1008
- isHovered: R,
1009
- isSelected: h,
1010
- effect: u
1006
+ bounds: y,
1007
+ isActive: d,
1008
+ isHovered: k,
1009
+ isSelected: g,
1010
+ effect: l
1011
1011
  }),
1012
- [t, o, g, p, R, h, u]
1012
+ [t, o, y, d, k, g, l]
1013
1013
  );
1014
- return /* @__PURE__ */ C.jsxs(K.Provider, { value: j, children: [
1015
- /* @__PURE__ */ C.jsx(
1014
+ return /* @__PURE__ */ I.jsxs(Q.Provider, { value: b, children: [
1015
+ /* @__PURE__ */ I.jsx(
1016
1016
  "div",
1017
1017
  {
1018
1018
  "data-cutout-id": t,
@@ -1020,11 +1020,11 @@ function zt({
1020
1020
  pointerEvents: "none",
1021
1021
  position: "absolute",
1022
1022
  inset: 0,
1023
- zIndex: p ? 20 : 10,
1024
- transition: u.transition,
1025
- ...S
1023
+ zIndex: d ? 20 : 10,
1024
+ transition: l.transition,
1025
+ ...x
1026
1026
  },
1027
- children: l ? l({ isActive: p, isHovered: R, isSelected: h, bounds: g, effect: u }) : /* @__PURE__ */ C.jsx(
1027
+ children: c ? c({ isActive: d, isHovered: k, isSelected: g, bounds: y, effect: l }) : /* @__PURE__ */ I.jsx(
1028
1028
  "svg",
1029
1029
  {
1030
1030
  viewBox: "0 0 1 1",
@@ -1035,22 +1035,22 @@ function zt({
1035
1035
  width: "100%",
1036
1036
  height: "100%",
1037
1037
  overflow: "visible",
1038
- filter: m.glow ? `drop-shadow(${m.glow.split(",")[0]?.trim() ?? ""})` : "none"
1038
+ filter: u.glow ? `drop-shadow(${u.glow.split(",")[0]?.trim() ?? ""})` : "none"
1039
1039
  },
1040
- children: /* @__PURE__ */ C.jsx(
1040
+ children: /* @__PURE__ */ I.jsx(
1041
1041
  "polygon",
1042
1042
  {
1043
- points: r.map(([P, b]) => `${P},${b}`).join(" "),
1044
- fill: m.fill,
1045
- stroke: m.stroke,
1046
- strokeWidth: (m.strokeWidth ?? 2) * 15e-4,
1043
+ points: r.map(([v, m]) => `${v},${m}`).join(" "),
1044
+ fill: u.fill,
1045
+ stroke: u.stroke,
1046
+ strokeWidth: (u.strokeWidth ?? 2) * 15e-4,
1047
1047
  strokeLinejoin: "round",
1048
- strokeLinecap: m.strokeDasharray ? "round" : void 0,
1049
- strokeDasharray: m.strokeDasharray,
1050
- pathLength: m.strokeDasharray ? 1 : void 0,
1048
+ strokeLinecap: u.strokeDasharray ? "round" : void 0,
1049
+ strokeDasharray: u.strokeDasharray,
1050
+ pathLength: u.strokeDasharray ? 1 : void 0,
1051
1051
  style: {
1052
- transition: u.transition,
1053
- animation: m.animation
1052
+ transition: l.transition,
1053
+ animation: u.animation
1054
1054
  }
1055
1055
  }
1056
1056
  )
@@ -1058,19 +1058,19 @@ function zt({
1058
1058
  )
1059
1059
  }
1060
1060
  ),
1061
- a
1061
+ i
1062
1062
  ] });
1063
1063
  }
1064
- function Lt(t, r) {
1065
- const { x: o, y: n, w: a, h: l } = r;
1066
- let i, s;
1067
- t.includes("left") ? (i = `${o * 100}%`, s = "0") : t.includes("right") ? (i = `${(o + a) * 100}%`, s = "-100%") : (i = `${(o + a / 2) * 100}%`, s = "-50%");
1068
- let d, u;
1069
- return t.startsWith("top") ? (d = `${n * 100}%`, u = "-100%") : t.startsWith("bottom") ? (d = `${(n + l) * 100}%`, u = "0") : (d = `${(n + l / 2) * 100}%`, u = "-50%"), {
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%"), {
1070
1070
  position: "absolute",
1071
- left: i,
1072
- top: d,
1073
- transform: `translate(${s}, ${u})`
1071
+ left: a,
1072
+ top: f,
1073
+ transform: `translate(${s}, ${l})`
1074
1074
  };
1075
1075
  }
1076
1076
  function Ut({
@@ -1079,22 +1079,22 @@ function Ut({
1079
1079
  className: o = "",
1080
1080
  style: n
1081
1081
  }) {
1082
- const a = F(K), l = rt();
1083
- if (!a)
1082
+ const i = H(Q), c = nt();
1083
+ if (!i)
1084
1084
  throw new Error(
1085
1085
  "<CutoutViewer.Overlay> must be used inside <CutoutViewer.Cutout>"
1086
1086
  );
1087
- const i = l.enabled && (l.showAll || a.isActive), s = Lt(t, a.bounds);
1088
- return /* @__PURE__ */ C.jsx(
1087
+ const a = c.enabled && (c.showAll || i.isActive), s = zt(t, i.bounds);
1088
+ return /* @__PURE__ */ I.jsx(
1089
1089
  "div",
1090
1090
  {
1091
1091
  "data-cutout-overlay": "true",
1092
1092
  className: o,
1093
1093
  style: {
1094
1094
  zIndex: 30,
1095
- transition: a.effect.transition,
1096
- opacity: i ? 1 : 0,
1097
- pointerEvents: i ? "auto" : "none",
1095
+ transition: i.effect.transition,
1096
+ opacity: a ? 1 : 0,
1097
+ pointerEvents: a ? "auto" : "none",
1098
1098
  ...s,
1099
1099
  ...n
1100
1100
  },
@@ -1102,6 +1102,200 @@ function Ut({
1102
1102
  }
1103
1103
  );
1104
1104
  }
1105
+ function Xt({
1106
+ onComplete: t,
1107
+ minPoints: r = 3,
1108
+ closeThreshold: o = 0.03
1109
+ }) {
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];
1116
+ },
1117
+ []
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;
1123
+ },
1124
+ [r, o]
1125
+ ), d = P(
1126
+ (u) => {
1127
+ u.length < r || (t(u), i([]), a(null));
1128
+ },
1129
+ [t, r]
1130
+ ), k = P(() => {
1131
+ i([]), a(null);
1132
+ }, []), g = P(
1133
+ (u) => {
1134
+ a(f(u.clientX, u.clientY));
1135
+ },
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]);
1144
+ },
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;
1151
+ });
1152
+ },
1153
+ [r, d]
1154
+ ), x = P(
1155
+ (u) => {
1156
+ u.preventDefault(), i((b) => b.slice(0, -1));
1157
+ },
1158
+ []
1159
+ ), w = c !== null && l(c, n);
1160
+ return {
1161
+ points: n,
1162
+ previewPoint: c,
1163
+ willClose: w,
1164
+ reset: k,
1165
+ containerRef: s,
1166
+ containerProps: {
1167
+ onPointerMove: g,
1168
+ onPointerLeave: h,
1169
+ onClick: y,
1170
+ onDoubleClick: E,
1171
+ onContextMenu: x
1172
+ }
1173
+ };
1174
+ }
1175
+ function Gt({
1176
+ onComplete: t,
1177
+ minPoints: r = 3,
1178
+ closeThreshold: o = 0.03,
1179
+ strokeColor: n = "#3b82f6",
1180
+ enabled: i = !0,
1181
+ style: c,
1182
+ className: a = ""
1183
+ }) {
1184
+ if (!H(Z))
1185
+ throw new Error(
1186
+ "<CutoutViewer.DrawPolygon> must be used inside <CutoutViewer>"
1187
+ );
1188
+ 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();
1199
+ }
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(
1206
+ "div",
1207
+ {
1208
+ ref: g,
1209
+ "data-draw-polygon": "true",
1210
+ className: a,
1211
+ style: {
1212
+ position: "absolute",
1213
+ inset: 0,
1214
+ cursor: i ? d ? "cell" : "crosshair" : "default",
1215
+ zIndex: 30,
1216
+ pointerEvents: i ? "auto" : "none",
1217
+ ...c
1218
+ },
1219
+ ...i ? h : {},
1220
+ children: f.length > 0 && /* @__PURE__ */ I.jsxs(
1221
+ "svg",
1222
+ {
1223
+ viewBox: "0 0 1 1",
1224
+ preserveAspectRatio: "none",
1225
+ style: {
1226
+ position: "absolute",
1227
+ inset: 0,
1228
+ width: "100%",
1229
+ height: "100%",
1230
+ overflow: "visible",
1231
+ pointerEvents: "none"
1232
+ },
1233
+ children: [
1234
+ f.length >= 3 && /* @__PURE__ */ I.jsx(
1235
+ "polygon",
1236
+ {
1237
+ points: f.map(([x, w]) => `${x},${w}`).join(" "),
1238
+ fill: n,
1239
+ fillOpacity: 0.15,
1240
+ stroke: "none"
1241
+ }
1242
+ ),
1243
+ y.length >= 2 && /* @__PURE__ */ I.jsx(
1244
+ "polyline",
1245
+ {
1246
+ points: E,
1247
+ fill: "none",
1248
+ stroke: n,
1249
+ strokeWidth: 3e-3,
1250
+ strokeLinecap: "round",
1251
+ strokeLinejoin: "round",
1252
+ strokeDasharray: l ? "0.015 0.008" : void 0
1253
+ }
1254
+ ),
1255
+ l && f.length >= 1 && /* @__PURE__ */ I.jsx(
1256
+ "line",
1257
+ {
1258
+ x1: l[0],
1259
+ y1: l[1],
1260
+ x2: f[0][0],
1261
+ y2: f[0][1],
1262
+ stroke: n,
1263
+ strokeWidth: 2e-3,
1264
+ strokeDasharray: "0.015 0.008",
1265
+ strokeLinecap: "round",
1266
+ opacity: d ? 0.9 : 0.35
1267
+ }
1268
+ ),
1269
+ f.map(([x, w], u) => /* @__PURE__ */ I.jsx(
1270
+ "circle",
1271
+ {
1272
+ cx: x,
1273
+ cy: w,
1274
+ r: u === 0 ? 0.012 : 7e-3,
1275
+ fill: u === 0 && d ? n : "white",
1276
+ stroke: n,
1277
+ strokeWidth: 2e-3
1278
+ },
1279
+ u
1280
+ )),
1281
+ l && /* @__PURE__ */ I.jsx(
1282
+ "circle",
1283
+ {
1284
+ cx: l[0],
1285
+ cy: l[1],
1286
+ r: 5e-3,
1287
+ fill: d ? n : "white",
1288
+ stroke: n,
1289
+ strokeWidth: 2e-3,
1290
+ opacity: 0.8
1291
+ }
1292
+ )
1293
+ ]
1294
+ }
1295
+ )
1296
+ }
1297
+ );
1298
+ }
1105
1299
  function vt(t) {
1106
1300
  switch (t.type) {
1107
1301
  case "image":
@@ -1112,81 +1306,81 @@ function vt(t) {
1112
1306
  return `polygon:${t.points.flat().join(",")}:${t.label ?? ""}`;
1113
1307
  }
1114
1308
  }
1115
- function Gt({
1309
+ function qt({
1116
1310
  mainImage: t,
1117
1311
  mainImageAlt: r = "Main image",
1118
1312
  effect: o = "elevate",
1119
1313
  enabled: n = !0,
1120
- showAll: a = !1,
1121
- alphaThreshold: l = 30,
1122
- hoverLeaveDelay: i = 150,
1314
+ showAll: i = !1,
1315
+ alphaThreshold: c = 30,
1316
+ hoverLeaveDelay: a = 150,
1123
1317
  children: s,
1124
- className: d = "",
1125
- style: u,
1126
- onHover: p,
1127
- onActiveChange: R,
1128
- onSelect: h
1318
+ className: f = "",
1319
+ style: l,
1320
+ onHover: d,
1321
+ onActiveChange: k,
1322
+ onSelect: g
1129
1323
  }) {
1130
- const f = typeof o == "string" ? q[o] ?? q.elevate : o;
1131
- N(() => {
1132
- Wt(f);
1133
- }, [f]);
1134
- const [g, w] = tt(() => /* @__PURE__ */ new Map()), S = O(
1135
- (_) => {
1136
- w((W) => {
1137
- const Y = W.get(_.id);
1138
- if (Y && vt(Y) === vt(_))
1139
- return W;
1140
- const U = new Map(W);
1141
- return U.set(_.id, _), U;
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;
1142
1336
  });
1143
1337
  },
1144
1338
  []
1145
- ), T = O((_) => {
1146
- w((W) => {
1147
- if (!W.has(_)) return W;
1148
- const Y = new Map(W);
1149
- return Y.delete(_), Y;
1339
+ ), w = P(($) => {
1340
+ E((N) => {
1341
+ if (!N.has($)) return N;
1342
+ const Y = new Map(N);
1343
+ return Y.delete($), Y;
1150
1344
  });
1151
- }, []), m = D(
1152
- () => ({ registerCutout: S, unregisterCutout: T }),
1153
- [S, T]
1154
- ), j = D(() => Array.from(g.values()), [g]), { activeId: P, selectedId: b, hoveredId: M, boundsMap: V, containerRef: z, containerProps: E } = Mt(j, n, l, i), k = B(null), y = B(null), v = B(null);
1155
- N(() => {
1156
- M !== k.current && (k.current = M, p?.(M));
1157
- }, [M, p]), N(() => {
1158
- P !== y.current && (y.current = P, R?.(P));
1159
- }, [P, R]), N(() => {
1160
- b !== v.current && (v.current = b, h?.(b));
1161
- }, [b, h]);
1162
- const $ = a || P !== null, L = D(
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(
1163
1357
  () => ({
1164
- activeId: P,
1165
- selectedId: b,
1358
+ activeId: v,
1359
+ selectedId: m,
1166
1360
  hoveredId: M,
1167
- effect: f,
1361
+ effect: h,
1168
1362
  enabled: n,
1169
- showAll: a,
1170
- boundsMap: V,
1171
- isAnyActive: $
1363
+ showAll: i,
1364
+ boundsMap: D,
1365
+ isAnyActive: W
1172
1366
  }),
1173
- [P, b, M, f, n, a, V, $]
1367
+ [v, m, M, h, n, i, D, W]
1174
1368
  );
1175
- return /* @__PURE__ */ C.jsx(et.Provider, { value: m, children: /* @__PURE__ */ C.jsx(xt.Provider, { value: L, children: /* @__PURE__ */ C.jsxs(
1369
+ return /* @__PURE__ */ I.jsx(Z.Provider, { value: u, children: /* @__PURE__ */ I.jsx(xt.Provider, { value: U, children: /* @__PURE__ */ I.jsxs(
1176
1370
  "div",
1177
1371
  {
1178
1372
  ref: z,
1179
- className: d,
1373
+ className: f,
1180
1374
  style: {
1181
1375
  position: "relative",
1182
1376
  width: "100%",
1183
1377
  overflow: "hidden",
1184
- cursor: $ && n ? "pointer" : "default",
1185
- ...u
1378
+ cursor: W && n ? "pointer" : "default",
1379
+ ...l
1186
1380
  },
1187
- ...E,
1381
+ ...j,
1188
1382
  children: [
1189
- /* @__PURE__ */ C.jsx(
1383
+ /* @__PURE__ */ I.jsx(
1190
1384
  "img",
1191
1385
  {
1192
1386
  src: t,
@@ -1197,21 +1391,21 @@ function Gt({
1197
1391
  width: "100%",
1198
1392
  height: "auto",
1199
1393
  userSelect: "none",
1200
- transition: f.transition,
1201
- ...$ && n ? f.mainImageHovered : {}
1394
+ transition: h.transition,
1395
+ ...W && n ? h.mainImageHovered : {}
1202
1396
  }
1203
1397
  }
1204
1398
  ),
1205
- /* @__PURE__ */ C.jsx(
1399
+ /* @__PURE__ */ I.jsx(
1206
1400
  "div",
1207
1401
  {
1208
1402
  style: {
1209
1403
  pointerEvents: "none",
1210
1404
  position: "absolute",
1211
1405
  inset: 0,
1212
- transition: f.transition,
1213
- opacity: $ && n ? 1 : 0,
1214
- ...f.vignetteStyle
1406
+ transition: h.transition,
1407
+ opacity: W && n ? 1 : 0,
1408
+ ...h.vignetteStyle
1215
1409
  }
1216
1410
  }
1217
1411
  ),
@@ -1220,26 +1414,29 @@ function Gt({
1220
1414
  }
1221
1415
  ) }) });
1222
1416
  }
1223
- const ot = Gt;
1224
- ot.Cutout = Bt;
1225
- ot.BBoxCutout = Ft;
1226
- ot.PolygonCutout = zt;
1227
- ot.Overlay = Ut;
1417
+ const tt = qt;
1418
+ tt.Cutout = Ht;
1419
+ tt.BBoxCutout = Lt;
1420
+ tt.PolygonCutout = Ft;
1421
+ tt.Overlay = Ut;
1422
+ tt.DrawPolygon = Gt;
1228
1423
  export {
1229
1424
  Ut as CutoutOverlay,
1230
- ot as CutoutViewer,
1231
- Ct as ImageHitTestStrategy,
1232
- jt as PolygonHitTestStrategy,
1233
- Tt as RectHitTestStrategy,
1234
- $t as createHitTestStrategy,
1235
- it as defineKeyframes,
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,
1236
1432
  Ot as elevateEffect,
1237
- Nt as glowEffect,
1238
- q as hoverEffects,
1239
- Yt as liftEffect,
1240
- Ht as shimmerEffect,
1241
- Dt as subtleEffect,
1433
+ Dt as glowEffect,
1434
+ J as hoverEffects,
1435
+ Nt as liftEffect,
1436
+ Bt as shimmerEffect,
1437
+ Yt as subtleEffect,
1242
1438
  Vt as traceEffect,
1243
- qt as useCutout,
1244
- Mt as useCutoutHitTest
1439
+ Kt as useCutout,
1440
+ Mt as useCutoutHitTest,
1441
+ Xt as useDrawPolygon
1245
1442
  };