@solibo/solibo-ui 2.2.0 → 2.2.1

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.
Files changed (43) hide show
  1. package/dist/assets/index28.css +1 -1
  2. package/dist/assets/index32.css +1 -1
  3. package/dist/assets/index38.css +1 -1
  4. package/dist/assets/index52.css +1 -1
  5. package/dist/assets/index56.css +1 -1
  6. package/dist/components/badge/index.cjs +1 -1
  7. package/dist/components/badge/index.js +40 -38
  8. package/dist/components/card/index.cjs +1 -1
  9. package/dist/components/card/index.js +41 -41
  10. package/dist/components/checkbox/index.cjs +1 -1
  11. package/dist/components/checkbox/index.js +1 -1
  12. package/dist/components/croppable/index.cjs +1 -1
  13. package/dist/components/croppable/index.js +269 -233
  14. package/dist/components/dropdown/index.cjs +1 -1
  15. package/dist/components/dropdown/index.js +3 -3
  16. package/dist/components/editor/index.cjs +1 -1
  17. package/dist/components/editor/index.js +1 -1
  18. package/dist/components/icon/index.cjs +1 -1
  19. package/dist/components/icon/index.js +1 -1
  20. package/dist/components/input/index.cjs +1 -1
  21. package/dist/components/input/index.js +2 -2
  22. package/dist/components/list/index.cjs +1 -1
  23. package/dist/components/list/index.js +11 -11
  24. package/dist/components/nav/index.cjs +1 -1
  25. package/dist/components/nav/index.js +1 -1
  26. package/dist/components/search/index.cjs +1 -1
  27. package/dist/components/search/index.js +1 -1
  28. package/dist/components/select/index.cjs +1 -1
  29. package/dist/components/select/index.js +2 -2
  30. package/dist/components/toolbar/index.cjs +1 -1
  31. package/dist/components/toolbar/index.js +4 -4
  32. package/dist/icons-BIdcCH-v.cjs +2 -0
  33. package/dist/{icons-CTtWkF6z.js → icons-DVeBguFb.js} +6 -3
  34. package/dist/{index-O1kh8Vnq.cjs → index-7blZaPiA.cjs} +2 -2
  35. package/dist/{index-BlirPoN9.js → index-Dd20d_9U.js} +2 -2
  36. package/dist/{index-C3NJXvlq.js → index-Dx-KtGBg.js} +2 -2
  37. package/dist/{index-CireNaZt.cjs → index-VLDsM9it.cjs} +2 -2
  38. package/dist/index.cjs +1 -1
  39. package/dist/index.d.ts +12 -3
  40. package/dist/index.js +2 -2
  41. package/dist/tokens.json +1 -1
  42. package/package.json +1 -1
  43. package/dist/icons-B3hIY9Bm.cjs +0 -2
@@ -1,323 +1,359 @@
1
- import { jsxs as J, jsx as w } from "react/jsx-runtime";
2
- import ot from "classix";
3
- import { useRef as x, useState as S, useEffect as E } from "react";
4
- import { Button as wt } from "../button/index.js";
5
- import { Figure as xt } from "../figure/index.js";
6
- import { Icon as yt } from "../icon/index.js";
7
- import '../../assets/index38.css';const O = 10, Z = 0.1, Pt = 0.92, d = (u, p, _) => Math.min(_, Math.max(p, u)), Yt = (u) => new Promise((p, _) => {
8
- const h = URL.createObjectURL(u), s = new globalThis.Image();
9
- s.onload = () => {
10
- URL.revokeObjectURL(h), p(s);
11
- }, s.onerror = () => {
12
- URL.revokeObjectURL(h), _(new Error("croppable-image-load-failed"));
13
- }, s.src = h;
14
- }), Xt = async ({
15
- file: u,
16
- fill: p,
17
- transform: _,
18
- viewport: h
1
+ import { jsxs as q, jsx as d } from "react/jsx-runtime";
2
+ import ft from "classix";
3
+ import { useRef as M, useState as T, useEffect as v } from "react";
4
+ import { Toolbar as Gt } from "../toolbar/index.js";
5
+ import { Button as ot } from "../button/index.js";
6
+ import { Figure as Ft } from "../figure/index.js";
7
+ import { Icon as Jt } from "../icon/index.js";
8
+ import '../../assets/index38.css';const H = 10, G = 0.1, Kt = 0.92, x = (s, l, f) => Math.min(f, Math.max(l, s)), Qt = (s) => new Promise((l, f) => {
9
+ const y = URL.createObjectURL(s), c = new globalThis.Image();
10
+ c.onload = () => {
11
+ URL.revokeObjectURL(y), l(c);
12
+ }, c.onerror = () => {
13
+ URL.revokeObjectURL(y), f(new Error("croppable-image-load-failed"));
14
+ }, c.src = y;
15
+ }), Vt = async ({
16
+ file: s,
17
+ fill: l,
18
+ transform: f,
19
+ viewport: y
19
20
  }) => {
20
- const s = await Yt(u), P = h.width / s.naturalWidth, R = h.height / s.naturalHeight, y = Math.max(P, R), j = s.naturalWidth * y, L = s.naturalHeight * y, C = p === "width" ? Math.max(Z, P / y) : p === "height" ? Math.max(Z, R / y) : Z, T = d(_.zoom, C, O), g = y * T, b = j * T, $ = L * T, m = (h.width - b) / 2 + _.offset.x, k = (h.height - $) / 2 + _.offset.y, Y = d(-m / g, 0, s.naturalWidth), v = d(-k / g, 0, s.naturalHeight), I = d(h.width / g, 1, Math.max(1, s.naturalWidth - Y)), c = d(h.height / g, 1, Math.max(1, s.naturalHeight - v)), z = document.createElement("canvas"), a = z.getContext("2d");
21
- if (!a)
21
+ const c = await Qt(s), S = y.width / c.naturalWidth, Z = y.height / c.naturalHeight, I = Math.max(S, Z), F = c.naturalWidth * I, B = c.naturalHeight * I, _ = l === "width" ? Math.max(G, S / I) : l === "height" ? Math.max(G, Z / I) : G, P = x(f.zoom, _, H), R = I * P, E = F * P, j = B * P, ct = (y.width - E) / 2 + f.offset.x, L = (y.height - j) / 2 + f.offset.y, z = x(-ct / R, 0, c.naturalWidth), b = x(-L / R, 0, c.naturalHeight), J = x(y.width / R, 1, Math.max(1, c.naturalWidth - z)), w = x(y.height / R, 1, Math.max(1, c.naturalHeight - b)), u = document.createElement("canvas"), Y = u.getContext("2d");
22
+ if (!Y)
22
23
  throw new Error("croppable-image-context-missing");
23
- z.width = Math.max(1, Math.round(I)), z.height = Math.max(1, Math.round(c)), a.drawImage(s, Y, v, I, c, 0, 0, z.width, z.height);
24
- const X = u.type.startsWith("image/") ? u.type : "image/jpeg", A = await new Promise((F) => {
25
- z.toBlob(F, X, Pt);
24
+ u.width = Math.max(1, Math.round(J)), u.height = Math.max(1, Math.round(w)), Y.drawImage(c, z, b, J, w, 0, 0, u.width, u.height);
25
+ const U = s.type.startsWith("image/") ? s.type : "image/jpeg", O = await new Promise((i) => {
26
+ u.toBlob(i, U, Kt);
26
27
  });
27
- if (!A)
28
+ if (!O)
28
29
  throw new Error("croppable-image-export-failed");
29
- return new globalThis.File([A], u.name, {
30
+ return new globalThis.File([O], s.name, {
30
31
  lastModified: Date.now(),
31
- type: A.type || X
32
+ type: O.type || U
32
33
  });
33
- }, At = "_croppable_1kqo4_1", Dt = "_empty_1kqo4_14", Wt = "_media_1kqo4_22", Ht = "_overlay_1kqo4_33", St = "_viewport_1kqo4_41", Zt = "_draggable_1kqo4_53", jt = "_dragging_1kqo4_57", qt = "_inner_1kqo4_61", Bt = "_standalone_1kqo4_77", M = {
34
- croppable: At,
35
- empty: Dt,
36
- media: Wt,
37
- overlay: Ht,
38
- viewport: St,
39
- draggable: Zt,
40
- dragging: jt,
41
- inner: qt,
42
- standalone: Bt
43
- }, Nt = 192, N = {
34
+ }, Ct = "_croppable_sjc2z_1", tn = "_empty_sjc2z_15", nn = "_action_sjc2z_23", en = "_caption_sjc2z_31", rn = "_media_sjc2z_38", on = "_viewport_sjc2z_49", cn = "_draggable_sjc2z_61", sn = "_dragging_sjc2z_65", an = "_inner_sjc2z_69", ln = "_standalone_sjc2z_85", h = {
35
+ croppable: Ct,
36
+ empty: tn,
37
+ action: nn,
38
+ caption: en,
39
+ media: rn,
40
+ viewport: on,
41
+ draggable: cn,
42
+ dragging: sn,
43
+ inner: an,
44
+ standalone: ln
45
+ }, un = 192, X = {
44
46
  offset: {
45
47
  x: 0,
46
48
  y: 0
47
49
  },
48
50
  zoom: 1
49
- }, bt = "Select image", Ct = ({
50
- children: u,
51
- fill: p = "none",
52
- height: _,
53
- image: h,
54
- label: s,
55
- onCroppableChange: P,
56
- onFileChange: R,
57
- onImageChange: y,
58
- onTransformChange: j,
59
- transform: L,
60
- standalone: C
51
+ }, Pt = (s, l) => (s == null ? void 0 : s.file) === l.file && (s == null ? void 0 : s.source) === l.source && (s == null ? void 0 : s.settings) === l.settings, yn = ({
52
+ cancelLabel: s,
53
+ children: l,
54
+ fill: f = "none",
55
+ height: y,
56
+ image: c,
57
+ deleteLabel: S,
58
+ saveLabel: Z,
59
+ uploadLabel: I,
60
+ onCroppableChange: F,
61
+ onDelete: B,
62
+ onFileChange: _,
63
+ onImageChange: P,
64
+ onSave: R,
65
+ onTransformChange: E,
66
+ transform: j,
67
+ standalone: ct
61
68
  }) => {
62
- const T = x(null), g = x(null), b = x(null), $ = x(null), m = x(y), k = x(null), Y = x(null), v = x(null), I = x(/* @__PURE__ */ new Map()), c = x(N), z = x(null), [a, X] = S(null), [A, F] = S(null), [rt, tt] = S(!1), [zt, ct] = S(N), [G, it] = S(null), [f, Mt] = S({
69
+ const L = M(null), z = M(null), b = M(null), J = M(null), w = M(P), u = M(null), Y = M(null), U = M(null), O = M(/* @__PURE__ */ new Map()), i = M(X), st = M(null), [g, V] = T(null), [it, at] = T(null), [wt, C] = T(!1), [Et, lt] = T(X), [k, ut] = T(null), [m, Lt] = T({
63
70
  width: 0,
64
71
  height: 0
65
- }), q = (() => {
66
- const t = f.width, n = f.height;
67
- if (!t || !n) return {
72
+ }), [gt, dt] = T(null), [K, tt] = T(null), Q = (() => {
73
+ const t = m.width, e = m.height;
74
+ if (!t || !e) return {
68
75
  width: 0,
69
76
  height: 0,
70
- minZoom: Z
77
+ minZoom: G
71
78
  };
72
- if (!a) return {
79
+ if (!g) return {
73
80
  width: t,
74
- height: n,
75
- minZoom: Z
81
+ height: e,
82
+ minZoom: G
76
83
  };
77
- const o = t / a.width, e = n / a.height, r = Math.max(o, e), i = p === "width" ? o / r : p === "height" ? e / r : 0;
84
+ const r = t / g.width, n = e / g.height, o = Math.max(r, n), a = f === "width" ? r / o : f === "height" ? n / o : 0;
78
85
  return {
79
- width: a.width * r,
80
- height: a.height * r,
81
- minZoom: Math.max(Z, i)
86
+ width: g.width * o,
87
+ height: g.height * o,
88
+ minZoom: Math.max(G, a)
82
89
  };
83
- })(), D = q.minZoom, B = L ?? zt, W = d(B.zoom, D, O), K = A ?? h ?? null, st = !u && !!h && !A && !G, Q = !st, at = u ?? (K ? /* @__PURE__ */ w("img", { alt: "", draggable: !1, onLoad: (t) => {
84
- const n = t.currentTarget;
85
- n.naturalWidth && n.naturalHeight && X({
86
- width: n.naturalWidth,
87
- height: n.naturalHeight
90
+ })(), $ = Q.minZoom, A = j ?? Et, D = x(A.zoom, $, H), nt = it ?? c ?? null, xt = !l && !!c && !it && !k, et = !xt, yt = l ?? (nt ? /* @__PURE__ */ d("img", { alt: "", draggable: !1, onLoad: (t) => {
91
+ const e = t.currentTarget;
92
+ e.naturalWidth && e.naturalHeight && V({
93
+ width: e.naturalWidth,
94
+ height: e.naturalHeight
88
95
  });
89
- }, src: K }) : null), H = at == null, et = (t, n) => {
96
+ }, src: nt }) : null), N = yt == null, ht = {
97
+ file: k,
98
+ source: it,
99
+ settings: JSON.stringify([f, D, A.offset.x, A.offset.y, m.width, m.height])
100
+ };
101
+ v(() => {
102
+ !K || !c || c === K.image && c !== K.crop.source || (dt(K.crop), tt(null));
103
+ }, [c, K]);
104
+ const pt = (t, e) => {
90
105
  const {
91
- maxX: o,
92
- maxY: e
93
- } = ut(n);
106
+ maxX: r,
107
+ maxY: n
108
+ } = bt(e);
94
109
  return {
95
- x: d(t.x, -o, o),
96
- y: d(t.y, -e, e)
110
+ x: x(t.x, -r, r),
111
+ y: x(t.y, -n, n)
97
112
  };
98
- }, lt = (t, n) => {
99
- const o = z.current;
100
- if (!o) return null;
101
- const e = o.getBoundingClientRect(), r = t - e.left - e.width / 2, i = n - e.top - e.height / 2;
113
+ }, zt = (t, e) => {
114
+ const r = st.current;
115
+ if (!r) return null;
116
+ const n = r.getBoundingClientRect(), o = t - n.left - n.width / 2, a = e - n.top - n.height / 2;
102
117
  return {
103
- x: r,
104
- y: i
118
+ x: o,
119
+ y: a
105
120
  };
106
- }, _t = (t, n, o, e) => {
107
- const r = d(n, D, O), i = d(o, D, O);
108
- if (r === 0) return t;
109
- const l = i / r;
121
+ }, Nt = (t, e, r, n) => {
122
+ const o = x(e, $, H), a = x(r, $, H);
123
+ if (o === 0) return t;
124
+ const p = a / o;
110
125
  return {
111
- x: (1 - l) * e.x + l * t.x,
112
- y: (1 - l) * e.y + l * t.y
126
+ x: (1 - p) * n.x + p * t.x,
127
+ y: (1 - p) * n.y + p * t.y
113
128
  };
114
- }, Rt = (t, n, o) => {
115
- const e = c.current.zoom, r = d(t, D, O), i = c.current.offset, l = o ? _t(i, e, r, o) : n, U = et(l, r);
116
- c.current = {
117
- zoom: r,
118
- offset: U
119
- }, L || ct({
120
- zoom: r,
121
- offset: U
122
- }), j == null || j({
123
- zoom: r,
124
- offset: U
129
+ }, Tt = (t, e, r) => {
130
+ const n = i.current.zoom, o = x(t, $, H), a = i.current.offset, p = r ? Nt(a, n, o, r) : e, W = pt(p, o);
131
+ i.current = {
132
+ zoom: o,
133
+ offset: W
134
+ }, j || lt({
135
+ zoom: o,
136
+ offset: W
137
+ }), E == null || E({
138
+ zoom: o,
139
+ offset: W
125
140
  });
126
- }, V = (t, n, o) => {
141
+ }, rt = (t, e, r) => {
127
142
  Y.current = {
128
143
  zoom: t,
129
- offset: n,
130
- anchor: o ?? null
131
- }, g.current == null && (g.current = window.requestAnimationFrame(() => {
132
- g.current = null;
133
- const e = Y.current;
144
+ offset: e,
145
+ anchor: r ?? null
146
+ }, z.current == null && (z.current = window.requestAnimationFrame(() => {
147
+ z.current = null;
148
+ const n = Y.current;
134
149
  Y.current = null;
135
- const r = (e == null ? void 0 : e.zoom) ?? c.current.zoom, i = (e == null ? void 0 : e.offset) ?? c.current.offset, l = (e == null ? void 0 : e.anchor) ?? null;
136
- Rt(r, i, l);
150
+ const o = (n == null ? void 0 : n.zoom) ?? i.current.zoom, a = (n == null ? void 0 : n.offset) ?? i.current.offset, p = (n == null ? void 0 : n.anchor) ?? null;
151
+ Tt(o, a, p);
137
152
  }));
138
- }, Lt = (t) => {
139
- if (H || !Q) return;
140
- const n = t.ctrlKey ? 1e-3 : 25e-5, o = c.current.zoom * Math.exp(-t.deltaY * n), e = lt(t.clientX, t.clientY);
141
- V(o, c.current.offset, e);
142
- }, ut = (t) => {
143
- const n = f.width, o = f.height;
144
- if (!n || !o) return {
153
+ }, Xt = (t) => {
154
+ if (N || !et) return;
155
+ const e = t.ctrlKey ? 1e-3 : 25e-5, r = i.current.zoom * Math.exp(-t.deltaY * e), n = zt(t.clientX, t.clientY);
156
+ rt(r, i.current.offset, n);
157
+ }, bt = (t) => {
158
+ const e = m.width, r = m.height;
159
+ if (!e || !r) return {
145
160
  maxX: 0,
146
161
  maxY: 0
147
162
  };
148
- const e = d(t, D, O), r = q.width * e, i = q.height * e, l = Math.max(0, (r - n) / 2), U = Math.max(0, (i - o) / 2);
163
+ const n = x(t, $, H), o = Q.width * n, a = Q.height * n, p = Math.max(0, (o - e) / 2), W = Math.max(0, (a - r) / 2);
149
164
  return {
150
- maxX: l,
151
- maxY: U
165
+ maxX: p,
166
+ maxY: W
152
167
  };
153
- }, Tt = (t) => {
154
- var r;
155
- const n = t.target, o = ((r = n.files) == null ? void 0 : r[0]) ?? null;
156
- if (k.current && (URL.revokeObjectURL(k.current), k.current = null), !o) {
157
- F(null), it(null), R == null || R(null), n.value = "";
168
+ }, Yt = (t) => {
169
+ var o;
170
+ tt(null), dt(null);
171
+ const e = t.target, r = ((o = e.files) == null ? void 0 : o[0]) ?? null;
172
+ if (u.current && (URL.revokeObjectURL(u.current), u.current = null), !r) {
173
+ at(null), ut(null), _ == null || _(null), e.value = "";
158
174
  return;
159
175
  }
160
- const e = URL.createObjectURL(o);
161
- k.current = e, F(e), X(null), it(o), V(N.zoom, N.offset), c.current = N, R == null || R(o), n.value = "";
176
+ const n = URL.createObjectURL(r);
177
+ u.current = n, at(n), V(null), ut(r), rt(X.zoom, X.offset), i.current = X, _ == null || _(r), e.value = "";
178
+ }, _t = () => {
179
+ tt(null), dt(null), z.current != null && (window.cancelAnimationFrame(z.current), z.current = null), Y.current = null, L.current = null, b.current = null, U.current = null, O.current.clear(), C(!1), u.current && (URL.revokeObjectURL(u.current), u.current = null), at(null), V(null), ut(null), i.current = X, lt(X), E == null || E(X), _ == null || _(null);
162
180
  }, kt = (t) => {
163
- if (!(H || !Q || t.pointerType === "mouse" && t.button !== 0)) {
181
+ t.stopPropagation(), _t();
182
+ }, At = (t) => {
183
+ t.stopPropagation(), _t(), B == null || B();
184
+ }, Dt = (t) => {
185
+ if (!(N || !et || t.pointerType === "mouse" && t.button !== 0)) {
164
186
  if (t.currentTarget.setPointerCapture(t.pointerId), t.pointerType === "touch") {
165
- const n = I.current;
166
- if (n.set(t.pointerId, {
187
+ const e = O.current;
188
+ if (e.set(t.pointerId, {
167
189
  x: t.clientX,
168
190
  y: t.clientY
169
- }), n.size === 2) {
170
- b.current = null, T.current = null, tt(!1);
171
- const [o, e] = Array.from(n.values());
172
- v.current = Math.hypot(o.x - e.x, o.y - e.y);
191
+ }), e.size === 2) {
192
+ b.current = null, L.current = null, C(!1);
193
+ const [r, n] = Array.from(e.values());
194
+ U.current = Math.hypot(r.x - n.x, r.y - n.y);
173
195
  return;
174
196
  }
175
197
  }
176
- T.current = t.pointerId, b.current = {
198
+ L.current = t.pointerId, b.current = {
177
199
  x: t.clientX,
178
200
  y: t.clientY,
179
- originX: c.current.offset.x,
180
- originY: c.current.offset.y
201
+ originX: i.current.offset.x,
202
+ originY: i.current.offset.y
181
203
  };
182
204
  }
183
- }, vt = (t) => {
184
- if (H || !Q) return;
205
+ }, Wt = (t) => {
206
+ if (N || !et) return;
185
207
  if (t.pointerType === "touch") {
186
- const r = I.current;
187
- if (!r.has(t.pointerId)) return;
188
- if (r.set(t.pointerId, {
208
+ const o = O.current;
209
+ if (!o.has(t.pointerId)) return;
210
+ if (o.set(t.pointerId, {
189
211
  x: t.clientX,
190
212
  y: t.clientY
191
- }), r.size === 2) {
192
- const [i, l] = Array.from(r.values()), U = i.x - l.x, Et = i.y - l.y, pt = Math.hypot(U, Et), gt = {
193
- x: (i.x + l.x) / 2,
194
- y: (i.y + l.y) / 2
213
+ }), o.size === 2) {
214
+ const [a, p] = Array.from(o.values()), W = a.x - p.x, Zt = a.y - p.y, vt = Math.hypot(W, Zt), It = {
215
+ x: (a.x + p.x) / 2,
216
+ y: (a.y + p.y) / 2
195
217
  };
196
- if (v.current) {
197
- const It = pt / v.current, Ut = c.current.zoom * It, Ot = lt(gt.x, gt.y);
198
- V(Ut, c.current.offset, Ot);
218
+ if (U.current) {
219
+ const Bt = vt / U.current, $t = i.current.zoom * Bt, qt = zt(It.x, It.y);
220
+ rt($t, i.current.offset, qt);
199
221
  }
200
- v.current = pt;
222
+ U.current = vt;
201
223
  return;
202
224
  }
203
225
  }
204
- if (T.current !== t.pointerId || !b.current || !nt) return;
205
- const n = t.clientX - b.current.x, o = t.clientY - b.current.y, e = Math.abs(n) + Math.abs(o);
206
- !rt && e > 2 && tt(!0), !(e <= 1) && V(c.current.zoom, {
207
- x: b.current.originX + n,
208
- y: b.current.originY + o
226
+ if (L.current !== t.pointerId || !b.current || !mt) return;
227
+ const e = t.clientX - b.current.x, r = t.clientY - b.current.y, n = Math.abs(e) + Math.abs(r);
228
+ !wt && n > 2 && C(!0), !(n <= 1) && rt(i.current.zoom, {
229
+ x: b.current.originX + e,
230
+ y: b.current.originY + r
209
231
  });
210
- }, ht = (t) => {
211
- t.pointerType === "touch" && (I.current.delete(t.pointerId), I.current.size < 2 && (v.current = null)), T.current === t.pointerId && (T.current = null, b.current = null, tt(!1));
232
+ }, Mt = (t) => {
233
+ t.pointerType === "touch" && (O.current.delete(t.pointerId), O.current.size < 2 && (U.current = null)), L.current === t.pointerId && (L.current = null, b.current = null, C(!1));
212
234
  };
213
- E(() => {
214
- if (!L) return;
215
- const t = d(L.zoom, D, O);
216
- c.current = {
235
+ v(() => {
236
+ if (!j) return;
237
+ const t = x(j.zoom, $, H);
238
+ i.current = {
217
239
  zoom: t,
218
- offset: et(L.offset, t)
240
+ offset: pt(j.offset, t)
219
241
  };
220
- }, [L, f.width, f.height, a == null ? void 0 : a.width, a == null ? void 0 : a.height]), E(() => () => {
221
- k.current && URL.revokeObjectURL(k.current);
222
- }, []), E(() => {
223
- const t = z.current;
242
+ }, [j, m.width, m.height, g == null ? void 0 : g.width, g == null ? void 0 : g.height]), v(() => () => {
243
+ u.current && URL.revokeObjectURL(u.current);
244
+ }, []), v(() => {
245
+ const t = st.current;
224
246
  if (!t) return;
225
- const n = () => {
226
- const r = t.getBoundingClientRect();
227
- Mt((i) => i.width === r.width && i.height === r.height ? i : {
228
- width: r.width,
229
- height: r.height
230
- }), P && P(r);
247
+ const e = () => {
248
+ const o = t.getBoundingClientRect();
249
+ Lt((a) => a.width === o.width && a.height === o.height ? a : {
250
+ width: o.width,
251
+ height: o.height
252
+ }), F && F(o);
231
253
  };
232
- n();
233
- const o = () => n();
234
- if (window.addEventListener("scroll", o, !0), typeof ResizeObserver > "u") {
235
- const r = () => n();
236
- return window.addEventListener("resize", r), () => {
237
- window.removeEventListener("resize", r), window.removeEventListener("scroll", o, !0);
254
+ e();
255
+ const r = () => e();
256
+ if (window.addEventListener("scroll", r, !0), typeof ResizeObserver > "u") {
257
+ const o = () => e();
258
+ return window.addEventListener("resize", o), () => {
259
+ window.removeEventListener("resize", o), window.removeEventListener("scroll", r, !0);
238
260
  };
239
261
  }
240
- const e = new ResizeObserver(() => n());
241
- return e.observe(t), () => {
242
- e.disconnect(), window.removeEventListener("scroll", o, !0);
262
+ const n = new ResizeObserver(() => e());
263
+ return n.observe(t), () => {
264
+ n.disconnect(), window.removeEventListener("scroll", r, !0);
243
265
  };
244
- }, [P]), E(() => {
245
- if (L) return;
246
- const t = c.current.offset, n = et(t, W);
247
- t.x === n.x && t.y === n.y || (c.current = {
248
- zoom: c.current.zoom,
249
- offset: n
250
- }, ct((o) => ({
251
- ...o,
252
- offset: n
266
+ }, [F]), v(() => {
267
+ if (j) return;
268
+ const t = i.current.offset, e = pt(t, D);
269
+ t.x === e.x && t.y === e.y || (i.current = {
270
+ zoom: i.current.zoom,
271
+ offset: e
272
+ }, lt((r) => ({
273
+ ...r,
274
+ offset: e
253
275
  })));
254
- }, [W, a, f.width, f.height]), E(() => {
255
- K || X(null);
256
- }, [K]), E(() => {
257
- m.current = y;
258
- }, [y]), E(() => {
259
- var o;
260
- if (!y) return;
261
- if (!G || !f.width || !f.height || u) {
262
- (o = m.current) == null || o.call(m, null);
276
+ }, [D, g, m.width, m.height]), v(() => {
277
+ nt || V(null);
278
+ }, [nt]), v(() => {
279
+ w.current = P;
280
+ }, [P]), v(() => {
281
+ var r;
282
+ if (!P) return;
283
+ if (!k || !m.width || !m.height || l) {
284
+ (r = w.current) == null || r.call(w, null);
263
285
  return;
264
286
  }
265
287
  let t = !0;
266
- const n = window.setTimeout(() => {
267
- Xt({
268
- file: G,
269
- fill: p,
288
+ const e = window.setTimeout(() => {
289
+ Vt({
290
+ file: k,
291
+ fill: f,
270
292
  transform: {
271
- zoom: W,
272
- offset: B.offset
293
+ zoom: D,
294
+ offset: A.offset
273
295
  },
274
- viewport: f
275
- }).then((e) => {
276
- var r;
277
- t && ((r = m.current) == null || r.call(m, e));
296
+ viewport: m
297
+ }).then((n) => {
298
+ var o;
299
+ t && ((o = w.current) == null || o.call(w, n));
278
300
  }).catch(() => {
279
- var e;
280
- t && ((e = m.current) == null || e.call(m, null));
301
+ var n;
302
+ t && ((n = w.current) == null || n.call(w, null));
281
303
  });
282
304
  }, 75);
283
305
  return () => {
284
- t = !1, window.clearTimeout(n);
306
+ t = !1, window.clearTimeout(e);
285
307
  };
286
- }, [u, W, B.offset, p, G, f]), E(() => () => {
287
- g.current != null && (window.cancelAnimationFrame(g.current), g.current = null);
308
+ }, [l, D, A.offset, f, k, m]), v(() => () => {
309
+ z.current != null && (window.cancelAnimationFrame(z.current), z.current = null);
288
310
  }, []);
289
- const dt = ut(W), nt = !H && Q && (dt.maxX > 0 || dt.maxY > 0), mt = () => {
311
+ const Rt = bt(D), mt = !N && et && (Rt.maxX > 0 || Rt.maxY > 0), jt = !N && !xt && !!R && !Pt(gt, ht), Ut = !!c && !l && !!k && !Pt(gt, ht), Ht = !Ut && !N && !!(k || B), Ot = () => {
290
312
  var t;
291
- return (t = $.current) == null ? void 0 : t.click();
292
- }, ft = (t) => {
293
- t.preventDefault(), t.stopPropagation(), mt();
313
+ return (t = J.current) == null ? void 0 : t.click();
314
+ }, St = (t) => {
315
+ t.preventDefault(), t.stopPropagation(), Ot();
294
316
  };
295
- return /* @__PURE__ */ J("div", { className: ot(M.croppable, C && M.standalone), onClick: () => {
296
- H && mt();
317
+ return /* @__PURE__ */ q("div", { className: ft(h.croppable, ct && h.standalone), onClick: () => {
318
+ N && Ot();
297
319
  }, "data-component": "croppable", children: [
298
- /* @__PURE__ */ w("input", { accept: "image/*", onChange: Tt, ref: $, type: "file" }),
299
- /* @__PURE__ */ w("div", { className: M.viewport, ref: z, onDragStart: (t) => t.preventDefault(), onPointerDown: kt, onPointerMove: vt, onPointerUp: ht, onPointerCancel: ht, onWheel: Lt, style: {
300
- "--croppable-height": `${_ ?? Nt}px`,
301
- "--croppable-zoom": W,
302
- "--croppable-x": `${B.offset.x}px`,
303
- "--croppable-y": `${B.offset.y}px`,
304
- ...a ? {
305
- "--croppable-image-width": `${q.width}px`,
306
- "--croppable-image-height": `${q.height}px`
320
+ /* @__PURE__ */ d("input", { accept: "image/*", onChange: Yt, ref: J, type: "file" }),
321
+ /* @__PURE__ */ d("div", { className: h.viewport, ref: st, onDragStart: (t) => t.preventDefault(), onPointerDown: Dt, onPointerMove: Wt, onPointerUp: Mt, onPointerCancel: Mt, onWheel: Xt, style: {
322
+ "--croppable-height": `${y ?? un}px`,
323
+ "--croppable-zoom": D,
324
+ "--croppable-x": `${A.offset.x}px`,
325
+ "--croppable-y": `${A.offset.y}px`,
326
+ ...g ? {
327
+ "--croppable-image-width": `${Q.width}px`,
328
+ "--croppable-image-height": `${Q.height}px`
307
329
  } : null
308
- }, children: H ? /* @__PURE__ */ J("div", { className: M.empty, children: [
309
- /* @__PURE__ */ w(xt, { children: /* @__PURE__ */ w(yt, { name: "Image", size: "large" }) }),
310
- /* @__PURE__ */ w(wt, { onClick: ft, children: s ?? bt })
311
- ] }) : /* @__PURE__ */ J("div", { className: ot(M.media, nt && M.draggable, nt && rt && M.dragging), children: [
312
- /* @__PURE__ */ w("div", { className: ot(M.inner), children: at }),
313
- st && /* @__PURE__ */ w("div", { className: M.overlay, children: /* @__PURE__ */ J("div", { className: M.empty, children: [
314
- /* @__PURE__ */ w(xt, { children: /* @__PURE__ */ w(yt, { name: "Image", size: "large" }) }),
315
- /* @__PURE__ */ w(wt, { onClick: ft, children: s ?? bt })
316
- ] }) })
317
- ] }) })
330
+ }, children: N ? /* @__PURE__ */ d("div", { className: h.empty, children: /* @__PURE__ */ d(Ft, { children: /* @__PURE__ */ d(Jt, { name: "Image", size: "large" }) }) }) : /* @__PURE__ */ d("div", { className: ft(h.media, mt && h.draggable, mt && wt && h.dragging), children: /* @__PURE__ */ d("div", { className: ft(h.inner), children: yt }) }) }),
331
+ /* @__PURE__ */ q(Gt, { children: [
332
+ jt && /* @__PURE__ */ q("span", { className: h.action, children: [
333
+ /* @__PURE__ */ d(ot, { "aria-label": Z ?? "Save image", icon: "FloppyDisk", onClick: () => {
334
+ tt({
335
+ image: c,
336
+ crop: ht
337
+ }), R == null || R();
338
+ }, variant: "primary" }),
339
+ Z && /* @__PURE__ */ d("span", { className: h.caption, children: Z })
340
+ ] }),
341
+ !jt && /* @__PURE__ */ q("span", { className: h.action, children: [
342
+ /* @__PURE__ */ d(ot, { "aria-label": I, icon: "UploadSimple", onClick: St, variant: "secondary" }),
343
+ /* @__PURE__ */ d("span", { className: h.caption, children: I })
344
+ ] }),
345
+ Ut && /* @__PURE__ */ q("span", { className: h.action, children: [
346
+ /* @__PURE__ */ d(ot, { "aria-label": s ?? "Cancel changes", icon: "X", onClick: kt, variant: "secondary" }),
347
+ s && /* @__PURE__ */ d("span", { className: h.caption, children: s })
348
+ ] }),
349
+ Ht && /* @__PURE__ */ q("span", { className: h.action, children: [
350
+ /* @__PURE__ */ d(ot, { "aria-label": S ?? "Delete image", icon: "Trash", intent: "danger", onClick: At, variant: "secondary" }),
351
+ S && /* @__PURE__ */ d("span", { className: h.caption, children: S })
352
+ ] })
353
+ ] })
318
354
  ] });
319
355
  };
320
356
  export {
321
- Ct as Croppable
357
+ yn as Croppable
322
358
  };
323
359
  //# sourceMappingURL=index.js.map