@solibo/solibo-ui 2.2.1 → 2.2.4

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