@scaleflex/crop 2.0.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.
- package/LICENSE +21 -0
- package/README.md +452 -0
- package/dist/a11y/aria.d.ts +5 -0
- package/dist/a11y/keyboard.d.ts +13 -0
- package/dist/animation/lerp.d.ts +15 -0
- package/dist/animation/spring.d.ts +15 -0
- package/dist/canvas/bleed-layer.d.ts +6 -0
- package/dist/canvas/crop-frame.d.ts +32 -0
- package/dist/canvas/grid-layer.d.ts +7 -0
- package/dist/canvas/hit-test.d.ts +10 -0
- package/dist/canvas/image-layer.d.ts +28 -0
- package/dist/canvas/overlay-layer.d.ts +6 -0
- package/dist/canvas/renderer.d.ts +34 -0
- package/dist/chunks/sfx-crop-1LGASewd.cjs +353 -0
- package/dist/chunks/sfx-crop-CEe6OfTZ.js +2030 -0
- package/dist/core/config.d.ts +10 -0
- package/dist/core/crop-controller.d.ts +65 -0
- package/dist/core/types.d.ts +270 -0
- package/dist/define.cjs +1194 -0
- package/dist/define.d.ts +1 -0
- package/dist/define.js +1746 -0
- package/dist/elements/base.d.ts +17 -0
- package/dist/elements/icons.d.ts +21 -0
- package/dist/elements/parse-shapes.d.ts +13 -0
- package/dist/elements/popover-anchor.d.ts +20 -0
- package/dist/elements/sfx-crop-canvas.d.ts +24 -0
- package/dist/elements/sfx-crop-canvas.styles.d.ts +1 -0
- package/dist/elements/sfx-crop-rotate.d.ts +42 -0
- package/dist/elements/sfx-crop-rotate.styles.d.ts +5 -0
- package/dist/elements/sfx-crop-shapes.d.ts +67 -0
- package/dist/elements/sfx-crop-shapes.styles.d.ts +6 -0
- package/dist/elements/sfx-crop-toolbar.d.ts +64 -0
- package/dist/elements/sfx-crop-toolbar.styles.d.ts +7 -0
- package/dist/elements/sfx-crop-zoom.d.ts +66 -0
- package/dist/elements/sfx-crop-zoom.styles.d.ts +7 -0
- package/dist/elements/sfx-crop.d.ts +134 -0
- package/dist/elements/sfx-crop.styles.d.ts +9 -0
- package/dist/export/exporter.d.ts +19 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +65 -0
- package/dist/interactions/drag-crop.d.ts +10 -0
- package/dist/interactions/pinch-zoom.d.ts +14 -0
- package/dist/interactions/pointer-tracker.d.ts +29 -0
- package/dist/interactions/resize-handles.d.ts +13 -0
- package/dist/interactions/wheel-zoom.d.ts +12 -0
- package/dist/react/define-CVJd5aYk.cjs +1545 -0
- package/dist/react/define-t4Z6KaLY.js +2590 -0
- package/dist/react/index-B-csHwK2.cjs +2 -0
- package/dist/react/index-CktjrogS.js +1468 -0
- package/dist/react/index.cjs +2 -0
- package/dist/react/index.d.ts +21 -0
- package/dist/react/index.js +10 -0
- package/dist/react/sfx-crop.d.ts +86 -0
- package/dist/react/use-sfx-crop-controller.d.ts +74 -0
- package/dist/react/use-sfx-crop.d.ts +31 -0
- package/dist/styles/shared.css.d.ts +20 -0
- package/dist/transforms/constrain.d.ts +68 -0
- package/dist/transforms/matrix.d.ts +23 -0
- package/dist/transforms/transform-state.d.ts +12 -0
- package/dist/utils/events.d.ts +16 -0
- package/dist/utils/math.d.ts +12 -0
- package/package.json +108 -0
|
@@ -0,0 +1,1468 @@
|
|
|
1
|
+
import { forwardRef as Ot, useRef as tt, useImperativeHandle as At, useEffect as ot, createElement as Wt, useState as J, useCallback as B, useMemo as Rt } from "react";
|
|
2
|
+
typeof customElements < "u" && import("./define-t4Z6KaLY.js");
|
|
3
|
+
function Ct(t, r, i) {
|
|
4
|
+
if (i === void 0) return;
|
|
5
|
+
if (r in t) {
|
|
6
|
+
t[r] = i;
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const o = r.replace(/[A-Z]/g, (a) => "-" + a.toLowerCase());
|
|
10
|
+
i === null || i === !1 ? t.removeAttribute(o) : i === !0 ? t.setAttribute(o, "") : t.setAttribute(o, String(i));
|
|
11
|
+
}
|
|
12
|
+
const Vt = [
|
|
13
|
+
"variant",
|
|
14
|
+
"cropShape",
|
|
15
|
+
"theme",
|
|
16
|
+
"initialRotation",
|
|
17
|
+
"initialScale",
|
|
18
|
+
"initialCrop",
|
|
19
|
+
"minScale",
|
|
20
|
+
"maxScale",
|
|
21
|
+
"minCropSize",
|
|
22
|
+
"availableShapes",
|
|
23
|
+
"handleSize",
|
|
24
|
+
"handleColor",
|
|
25
|
+
"borderRadius",
|
|
26
|
+
"overlayColor",
|
|
27
|
+
"outputType",
|
|
28
|
+
"outputQuality",
|
|
29
|
+
"maxOutputWidth",
|
|
30
|
+
"maxOutputHeight",
|
|
31
|
+
"showGrid",
|
|
32
|
+
"showToolbar",
|
|
33
|
+
"showRotateSlider",
|
|
34
|
+
"showZoomSlider",
|
|
35
|
+
"showShapeSelector",
|
|
36
|
+
"showRotateButton",
|
|
37
|
+
"showFlipButton",
|
|
38
|
+
"toolbarPosition",
|
|
39
|
+
"showBleedMargin",
|
|
40
|
+
"bleedMarginSize",
|
|
41
|
+
"bleedMarginColor",
|
|
42
|
+
"enableAnimations",
|
|
43
|
+
"animationSpeed",
|
|
44
|
+
"keyboard",
|
|
45
|
+
"pinchZoom",
|
|
46
|
+
"wheelZoom",
|
|
47
|
+
"icons"
|
|
48
|
+
], xe = Ot(function(r, i) {
|
|
49
|
+
const o = tt(null), a = tt(r);
|
|
50
|
+
return a.current = r, At(i, () => o.current, []), ot(() => {
|
|
51
|
+
const e = o.current;
|
|
52
|
+
if (!e) return;
|
|
53
|
+
const h = [
|
|
54
|
+
["sfx-crop-ready", (s) => {
|
|
55
|
+
var n, l;
|
|
56
|
+
return (l = (n = a.current).onReady) == null ? void 0 : l.call(n, s.detail);
|
|
57
|
+
}],
|
|
58
|
+
["sfx-crop-image-load", (s) => {
|
|
59
|
+
var n, l;
|
|
60
|
+
return (l = (n = a.current).onImageLoad) == null ? void 0 : l.call(n, s.detail);
|
|
61
|
+
}],
|
|
62
|
+
["sfx-crop-change", (s) => {
|
|
63
|
+
var n, l;
|
|
64
|
+
return (l = (n = a.current).onChange) == null ? void 0 : l.call(n, s.detail);
|
|
65
|
+
}],
|
|
66
|
+
["sfx-crop-crop-change", (s) => {
|
|
67
|
+
var n, l;
|
|
68
|
+
return (l = (n = a.current).onCropChange) == null ? void 0 : l.call(n, s.detail);
|
|
69
|
+
}],
|
|
70
|
+
["sfx-crop-save", (s) => {
|
|
71
|
+
var n, l;
|
|
72
|
+
return (l = (n = a.current).onSave) == null ? void 0 : l.call(n, s.detail);
|
|
73
|
+
}],
|
|
74
|
+
["sfx-crop-cancel", () => {
|
|
75
|
+
var s, n;
|
|
76
|
+
return (n = (s = a.current).onCancel) == null ? void 0 : n.call(s);
|
|
77
|
+
}],
|
|
78
|
+
["sfx-crop-error", (s) => {
|
|
79
|
+
var n, l;
|
|
80
|
+
return (l = (n = a.current).onError) == null ? void 0 : l.call(n, s.detail);
|
|
81
|
+
}]
|
|
82
|
+
];
|
|
83
|
+
for (const [s, n] of h) e.addEventListener(s, n);
|
|
84
|
+
return () => {
|
|
85
|
+
for (const [s, n] of h) e.removeEventListener(s, n);
|
|
86
|
+
};
|
|
87
|
+
}, []), ot(() => {
|
|
88
|
+
const e = o.current;
|
|
89
|
+
if (e) {
|
|
90
|
+
for (const h of Vt) Ct(e, h, r[h]);
|
|
91
|
+
Ct(e, "src", r.src);
|
|
92
|
+
}
|
|
93
|
+
}), Wt("sfx-crop", {
|
|
94
|
+
ref: o,
|
|
95
|
+
className: r.className,
|
|
96
|
+
style: r.style,
|
|
97
|
+
id: r.id
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
typeof customElements < "u" && import("./define-t4Z6KaLY.js");
|
|
101
|
+
function Me() {
|
|
102
|
+
const t = tt(null), [r, i] = J(!1);
|
|
103
|
+
ot(() => {
|
|
104
|
+
const u = t.current;
|
|
105
|
+
if (!u) return;
|
|
106
|
+
const m = () => i(!0);
|
|
107
|
+
return u.addEventListener("sfx-crop-ready", m), () => {
|
|
108
|
+
u.removeEventListener("sfx-crop-ready", m), i(!1);
|
|
109
|
+
};
|
|
110
|
+
}, []);
|
|
111
|
+
const o = B((u) => t.current ? t.current.loadImage(u) : Promise.resolve(), []), a = B(() => {
|
|
112
|
+
var u;
|
|
113
|
+
return (u = t.current) == null ? void 0 : u.rotateLeft();
|
|
114
|
+
}, []), e = B(() => {
|
|
115
|
+
var u;
|
|
116
|
+
return (u = t.current) == null ? void 0 : u.flipHorizontal();
|
|
117
|
+
}, []), h = B((u) => {
|
|
118
|
+
var m;
|
|
119
|
+
return (m = t.current) == null ? void 0 : m.setRotation(u);
|
|
120
|
+
}, []), s = B((u) => {
|
|
121
|
+
var m;
|
|
122
|
+
return (m = t.current) == null ? void 0 : m.setScale(u);
|
|
123
|
+
}, []), n = B((u) => {
|
|
124
|
+
var m;
|
|
125
|
+
return (m = t.current) == null ? void 0 : m.setCropShape(u);
|
|
126
|
+
}, []), l = B((u) => {
|
|
127
|
+
var m;
|
|
128
|
+
return (m = t.current) == null ? void 0 : m.setCropRect(u);
|
|
129
|
+
}, []), d = B(() => {
|
|
130
|
+
var u;
|
|
131
|
+
return ((u = t.current) == null ? void 0 : u.getCropRect()) ?? null;
|
|
132
|
+
}, []), g = B(() => {
|
|
133
|
+
var u;
|
|
134
|
+
return ((u = t.current) == null ? void 0 : u.getTransformState()) ?? null;
|
|
135
|
+
}, []), w = B(() => {
|
|
136
|
+
var u;
|
|
137
|
+
return (u = t.current) == null ? void 0 : u.reset();
|
|
138
|
+
}, []), y = B(() => {
|
|
139
|
+
var u;
|
|
140
|
+
return ((u = t.current) == null ? void 0 : u.toCanvas()) ?? null;
|
|
141
|
+
}, []), c = B(async (u, m) => t.current ? t.current.toBlob(u, m) : null, []), p = B((u, m) => {
|
|
142
|
+
var H;
|
|
143
|
+
return ((H = t.current) == null ? void 0 : H.toDataURL(u, m)) ?? null;
|
|
144
|
+
}, []), S = B(() => {
|
|
145
|
+
var u;
|
|
146
|
+
return ((u = t.current) == null ? void 0 : u.toTransformParams()) ?? null;
|
|
147
|
+
}, []), x = B((u, m) => t.current ? t.current.save(u, m) : Promise.resolve(), []), C = B(() => {
|
|
148
|
+
var u;
|
|
149
|
+
return (u = t.current) == null ? void 0 : u.cancel();
|
|
150
|
+
}, []);
|
|
151
|
+
return {
|
|
152
|
+
ref: t,
|
|
153
|
+
ready: r,
|
|
154
|
+
loadImage: o,
|
|
155
|
+
rotateLeft: a,
|
|
156
|
+
flipHorizontal: e,
|
|
157
|
+
setRotation: h,
|
|
158
|
+
setScale: s,
|
|
159
|
+
setCropShape: n,
|
|
160
|
+
setCropRect: l,
|
|
161
|
+
getCropRect: d,
|
|
162
|
+
getTransformState: g,
|
|
163
|
+
reset: w,
|
|
164
|
+
toCanvas: y,
|
|
165
|
+
toBlob: c,
|
|
166
|
+
toDataURL: p,
|
|
167
|
+
toTransformParams: S,
|
|
168
|
+
save: x,
|
|
169
|
+
cancel: C
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const zt = {
|
|
173
|
+
src: "",
|
|
174
|
+
variant: "classic",
|
|
175
|
+
cropShape: "16:9",
|
|
176
|
+
initialCrop: null,
|
|
177
|
+
initialRotation: 0,
|
|
178
|
+
initialScale: 1,
|
|
179
|
+
customAspectRatios: [],
|
|
180
|
+
minCropSize: 20,
|
|
181
|
+
availableShapes: [
|
|
182
|
+
"free",
|
|
183
|
+
"square",
|
|
184
|
+
"16:9",
|
|
185
|
+
"4:3",
|
|
186
|
+
"3:2",
|
|
187
|
+
"5:4",
|
|
188
|
+
"2:1",
|
|
189
|
+
"9:16",
|
|
190
|
+
"3:4",
|
|
191
|
+
"2:3",
|
|
192
|
+
"4:5",
|
|
193
|
+
"1:2"
|
|
194
|
+
],
|
|
195
|
+
minScale: 0.5,
|
|
196
|
+
maxScale: 5,
|
|
197
|
+
theme: "light",
|
|
198
|
+
showGrid: "interaction",
|
|
199
|
+
showRotateSlider: !0,
|
|
200
|
+
showZoomSlider: !0,
|
|
201
|
+
showShapeSelector: !0,
|
|
202
|
+
showRotateButton: !0,
|
|
203
|
+
showFlipButton: !0,
|
|
204
|
+
toolbarPosition: "top",
|
|
205
|
+
showToolbar: !0,
|
|
206
|
+
overlayColor: "rgba(0, 0, 0, 0.55)",
|
|
207
|
+
handleSize: 12,
|
|
208
|
+
handleColor: "#ffffff",
|
|
209
|
+
borderRadius: 20,
|
|
210
|
+
outputType: "image/png",
|
|
211
|
+
outputQuality: 0.92,
|
|
212
|
+
maxOutputWidth: 0,
|
|
213
|
+
maxOutputHeight: 0,
|
|
214
|
+
showBleedMargin: !1,
|
|
215
|
+
bleedMarginSize: 10,
|
|
216
|
+
bleedMarginColor: "rgba(255, 0, 0, 0.5)",
|
|
217
|
+
enableAnimations: !0,
|
|
218
|
+
animationSpeed: 1,
|
|
219
|
+
keyboard: !0,
|
|
220
|
+
pinchZoom: !0,
|
|
221
|
+
wheelZoom: !0
|
|
222
|
+
};
|
|
223
|
+
function Ht(t) {
|
|
224
|
+
return { ...zt, ...t };
|
|
225
|
+
}
|
|
226
|
+
function I(t, r, i) {
|
|
227
|
+
return Math.min(Math.max(t, r), i);
|
|
228
|
+
}
|
|
229
|
+
function U(t, r, i) {
|
|
230
|
+
return t + (r - t) * i;
|
|
231
|
+
}
|
|
232
|
+
function st(t) {
|
|
233
|
+
return t * Math.PI / 180;
|
|
234
|
+
}
|
|
235
|
+
function Bt(t, r, i, o) {
|
|
236
|
+
const a = i - t, e = o - r;
|
|
237
|
+
return Math.sqrt(a * a + e * e);
|
|
238
|
+
}
|
|
239
|
+
function Kt(t) {
|
|
240
|
+
const r = /^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?)$/.exec(t.trim());
|
|
241
|
+
if (!r) return null;
|
|
242
|
+
const i = Number(r[1]), o = Number(r[2]);
|
|
243
|
+
return !Number.isFinite(i) || !Number.isFinite(o) || i <= 0 || o <= 0 ? null : i / o;
|
|
244
|
+
}
|
|
245
|
+
function gt(t) {
|
|
246
|
+
switch (t) {
|
|
247
|
+
case "free":
|
|
248
|
+
return null;
|
|
249
|
+
case "rounded-rect":
|
|
250
|
+
return null;
|
|
251
|
+
case "square":
|
|
252
|
+
case "circle":
|
|
253
|
+
return 1;
|
|
254
|
+
// Everything else — `"16:9"`, `"4:3"`, `"7:2"`, `"2.35:1"` — goes
|
|
255
|
+
// through `parseRatio`. The switch intentionally doesn't enumerate
|
|
256
|
+
// the named ratios so the library stays a parser, not a catalog.
|
|
257
|
+
default:
|
|
258
|
+
return Kt(t);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function Nt(t, r, i, o, a, e) {
|
|
262
|
+
if (r === null)
|
|
263
|
+
return Zt(t, e, o, a);
|
|
264
|
+
const h = o / a, s = r / h;
|
|
265
|
+
let { x: n, y: l, width: d, height: g } = t;
|
|
266
|
+
const w = i.includes("e") || i.includes("w"), y = i.includes("n") || i.includes("s");
|
|
267
|
+
w && !y ? g = d / s : y && !w ? d = g * s : g = d / s;
|
|
268
|
+
const c = t.x + t.width, p = t.y + t.height, S = t.x + t.width / 2, x = t.y + t.height / 2;
|
|
269
|
+
let C;
|
|
270
|
+
i.includes("w") ? C = c : i.includes("e") ? C = 1 - t.x : C = 2 * Math.min(S, 1 - S);
|
|
271
|
+
let u;
|
|
272
|
+
i.includes("n") ? u = p : i.includes("s") ? u = 1 - t.y : u = 2 * Math.min(x, 1 - x);
|
|
273
|
+
const m = Math.min(1, C / d, u / g);
|
|
274
|
+
m < 1 && (d *= m, g *= m);
|
|
275
|
+
const H = e / o, V = e / a;
|
|
276
|
+
return d < H && (d = H, g = d / s), g < V && (g = V, d = g * s), i.includes("w") ? n = c - d : i.includes("e") ? n = t.x : n = S - d / 2, i.includes("n") ? l = p - g : i.includes("s") ? l = t.y : l = x - g / 2, n = I(n, 0, 1 - d), l = I(l, 0, 1 - g), { x: n, y: l, width: d, height: g };
|
|
277
|
+
}
|
|
278
|
+
function Zt(t, r, i, o) {
|
|
279
|
+
const a = r / i, e = r / o;
|
|
280
|
+
return {
|
|
281
|
+
...t,
|
|
282
|
+
width: Math.max(t.width, a),
|
|
283
|
+
height: Math.max(t.height, e)
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function _t(t, r, i, o, a, e, h) {
|
|
287
|
+
const s = t.rotation * Math.PI / 180, n = Math.abs(Math.cos(s)), l = Math.abs(Math.sin(s)), d = o.width * n + o.height * l, g = o.width * l + o.height * n, w = Math.max(d / a, g / e), y = Math.min(w, h), c = I(t.scale, y, h), p = r / 2 - (o.x + o.width / 2), S = i / 2 - (o.y + o.height / 2), x = Math.max(0, (a * c - d) / 2), C = Math.max(0, (e * c - g) / 2);
|
|
288
|
+
return {
|
|
289
|
+
scale: c,
|
|
290
|
+
panX: I(t.panX, (-x - p) / c, (x - p) / c),
|
|
291
|
+
panY: I(t.panY, (-C - S) / c, (C - S) / c),
|
|
292
|
+
minScale: y
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
const N = 0.8;
|
|
296
|
+
function bt(t, r, i) {
|
|
297
|
+
return !r || !i ? t : t / (r / i);
|
|
298
|
+
}
|
|
299
|
+
function xt(t = "free", r = 1, i = 1) {
|
|
300
|
+
const o = gt(t);
|
|
301
|
+
let a;
|
|
302
|
+
if (o !== null) {
|
|
303
|
+
const e = bt(o, r, i);
|
|
304
|
+
let h, s;
|
|
305
|
+
e >= 1 ? (h = N, s = h / e, s > N && (s = N, h = s * e)) : (s = N, h = s * e, h > N && (h = N, s = h / e)), a = {
|
|
306
|
+
x: (1 - h) / 2,
|
|
307
|
+
y: (1 - s) / 2,
|
|
308
|
+
width: h,
|
|
309
|
+
height: s
|
|
310
|
+
};
|
|
311
|
+
} else {
|
|
312
|
+
const e = N;
|
|
313
|
+
a = { x: (1 - e) / 2, y: (1 - e) / 2, width: e, height: e };
|
|
314
|
+
}
|
|
315
|
+
return {
|
|
316
|
+
quarterTurns: 0,
|
|
317
|
+
rotation: 0,
|
|
318
|
+
flipH: !1,
|
|
319
|
+
flipV: !1,
|
|
320
|
+
scale: 1,
|
|
321
|
+
panX: 0,
|
|
322
|
+
panY: 0,
|
|
323
|
+
cropRect: a
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
function Ut(t) {
|
|
327
|
+
const r = t.quarterTurns - 90;
|
|
328
|
+
return {
|
|
329
|
+
...t,
|
|
330
|
+
quarterTurns: r,
|
|
331
|
+
panX: 0,
|
|
332
|
+
panY: 0
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function $t(t) {
|
|
336
|
+
return { ...t, flipH: !t.flipH };
|
|
337
|
+
}
|
|
338
|
+
function ht(t, r) {
|
|
339
|
+
const i = I(r, -45, 45);
|
|
340
|
+
let o = t.rotationPivot;
|
|
341
|
+
if (i === 0)
|
|
342
|
+
o = void 0;
|
|
343
|
+
else if (!o) {
|
|
344
|
+
const a = t.cropRect;
|
|
345
|
+
o = { x: a.x + a.width / 2, y: a.y + a.height / 2 };
|
|
346
|
+
}
|
|
347
|
+
return { ...t, rotation: i, rotationPivot: o };
|
|
348
|
+
}
|
|
349
|
+
function nt(t, r, i, o) {
|
|
350
|
+
return {
|
|
351
|
+
...t,
|
|
352
|
+
scale: I(r, i, o)
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function k(t, r) {
|
|
356
|
+
return {
|
|
357
|
+
...t,
|
|
358
|
+
cropRect: {
|
|
359
|
+
x: I(r.x, 0, 1 - r.width),
|
|
360
|
+
y: I(r.y, 0, 1 - r.height),
|
|
361
|
+
width: I(r.width, 0, 1),
|
|
362
|
+
height: I(r.height, 0, 1)
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function dt(t, r, i = 1, o = 1) {
|
|
367
|
+
const a = gt(r);
|
|
368
|
+
let e;
|
|
369
|
+
if (a === null)
|
|
370
|
+
e = { ...t.cropRect };
|
|
371
|
+
else {
|
|
372
|
+
const h = bt(a, i, o), { cropRect: s } = t, n = s.x + s.width / 2, l = s.y + s.height / 2;
|
|
373
|
+
let d, g;
|
|
374
|
+
h >= 1 ? (d = N, g = d / h, g > N && (g = N, d = g * h)) : (g = N, d = g * h, d > N && (d = N, g = d / h)), e = {
|
|
375
|
+
x: I(n - d / 2, 0, 1 - d),
|
|
376
|
+
y: I(l - g / 2, 0, 1 - g),
|
|
377
|
+
width: d,
|
|
378
|
+
height: g
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
return {
|
|
382
|
+
...t,
|
|
383
|
+
cropRect: e
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function Mt(t, r, i) {
|
|
387
|
+
return {
|
|
388
|
+
...t,
|
|
389
|
+
panX: t.panX + r,
|
|
390
|
+
panY: t.panY + i
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
function ct(t, r, i, o, a) {
|
|
394
|
+
const e = Math.round(a / 90) % 2 !== 0, h = e ? r : t, s = e ? t : r, n = Math.max(h / i, s / o);
|
|
395
|
+
return { drawW: i * n, drawH: o * n };
|
|
396
|
+
}
|
|
397
|
+
function Gt(t, r, i, o, a = !1) {
|
|
398
|
+
const { x: e, y: h, w: s, h: n } = i, l = e + s / 2, d = h + n / 2;
|
|
399
|
+
t.save();
|
|
400
|
+
const g = e + (o.cropRect.x + o.cropRect.width / 2) * s, w = h + (o.cropRect.y + o.cropRect.height / 2) * n, y = o.rotationPivot ?? {
|
|
401
|
+
x: o.cropRect.x + o.cropRect.width / 2,
|
|
402
|
+
y: o.cropRect.y + o.cropRect.height / 2
|
|
403
|
+
}, c = e + y.x * s, p = h + y.y * n;
|
|
404
|
+
o.rotation !== 0 && (t.translate(c, p), t.rotate(st(o.rotation)), t.translate(-c, -p)), (o.flipH !== 1 || o.flipV !== 1) && (t.translate(g, w), t.scale(o.flipH, o.flipV), t.translate(-g, -w)), t.translate(l, d), t.scale(o.scale, o.scale), t.translate(o.panX, o.panY), o.quarterTurns !== 0 && t.rotate(st(o.quarterTurns));
|
|
405
|
+
let S, x;
|
|
406
|
+
if (a) {
|
|
407
|
+
const C = ct(s, n, r.naturalWidth, r.naturalHeight, o.quarterTurns);
|
|
408
|
+
S = C.drawW, x = C.drawH;
|
|
409
|
+
} else {
|
|
410
|
+
const u = Math.round(o.quarterTurns / 90) % 2 !== 0 ? Math.min(s, n) / Math.max(s, n) : 1;
|
|
411
|
+
S = s * u, x = n * u;
|
|
412
|
+
}
|
|
413
|
+
t.drawImage(r, -S / 2, -x / 2, S, x), t.restore();
|
|
414
|
+
}
|
|
415
|
+
let G = null;
|
|
416
|
+
function Qt(t, r) {
|
|
417
|
+
G || (G = document.createElement("canvas")), (G.width !== t || G.height !== r) && (G.width = t, G.height = r);
|
|
418
|
+
const i = G.getContext("2d");
|
|
419
|
+
return i.clearRect(0, 0, t, r), i;
|
|
420
|
+
}
|
|
421
|
+
function jt(t, r, i, o, a = "rect", e = 20, h = "rgba(0, 0, 0, 0.55)") {
|
|
422
|
+
const s = Qt(r, i);
|
|
423
|
+
if (s.fillStyle = h, s.fillRect(0, 0, r, i), s.globalCompositeOperation = "destination-out", s.fillStyle = "rgba(0, 0, 0, 1)", a === "circle") {
|
|
424
|
+
const n = o.x + o.width / 2, l = o.y + o.height / 2, d = o.width / 2, g = o.height / 2;
|
|
425
|
+
s.beginPath(), s.ellipse(n, l, d, g, 0, 0, Math.PI * 2), s.fill();
|
|
426
|
+
} else if (a === "rounded-rect") {
|
|
427
|
+
const { x: n, y: l, width: d, height: g } = o, w = Math.min(e, d / 2, g / 2);
|
|
428
|
+
s.beginPath(), s.moveTo(n + w, l), s.lineTo(n + d - w, l), s.arcTo(n + d, l, n + d, l + w, w), s.lineTo(n + d, l + g - w), s.arcTo(n + d, l + g, n + d - w, l + g, w), s.lineTo(n + w, l + g), s.arcTo(n, l + g, n, l + g - w, w), s.lineTo(n, l + w), s.arcTo(n, l, n + w, l, w), s.closePath(), s.fill();
|
|
429
|
+
} else
|
|
430
|
+
s.fillRect(o.x, o.y, o.width, o.height);
|
|
431
|
+
s.globalCompositeOperation = "source-over", t.drawImage(G, 0, 0);
|
|
432
|
+
}
|
|
433
|
+
const kt = 12, Jt = 22, lt = 11, at = 9, te = {
|
|
434
|
+
frame: "#ffffff",
|
|
435
|
+
frameShadow: "rgba(0, 0, 0, 0.3)",
|
|
436
|
+
handleFill: "#ffffff",
|
|
437
|
+
handleStroke: "rgba(0, 0, 0, 0.25)"
|
|
438
|
+
};
|
|
439
|
+
function ee(t, r, i = "rect", o = 20, a = te, e = !0) {
|
|
440
|
+
const h = i === "circle", s = i === "rounded-rect", { x: n, y: l, width: d, height: g } = r;
|
|
441
|
+
if (t.save(), t.strokeStyle = a.frameShadow, t.lineWidth = 1, h) {
|
|
442
|
+
const S = n + d / 2, x = l + g / 2, C = d / 2 - 1, u = g / 2 - 1;
|
|
443
|
+
t.beginPath(), t.ellipse(S, x, C, u, 0, 0, Math.PI * 2), t.stroke();
|
|
444
|
+
} else s ? (Tt(t, n + 1, l + 1, d - 2, g - 2, Math.min(o, d / 2, g / 2)), t.stroke()) : t.strokeRect(n + 1, l + 1, d - 2, g - 2);
|
|
445
|
+
if (t.strokeStyle = a.frame, t.lineWidth = 2, h) {
|
|
446
|
+
const S = n + d / 2, x = l + g / 2, C = d / 2, u = g / 2;
|
|
447
|
+
t.beginPath(), t.ellipse(S, x, C, u, 0, 0, Math.PI * 2), t.stroke(), t.setLineDash([4, 4]), t.strokeStyle = a.frameShadow, t.lineWidth = 1, t.beginPath(), t.ellipse(S, x, C - 1, u - 1, 0, 0, Math.PI * 2), t.stroke(), t.setLineDash([]);
|
|
448
|
+
} else if (s) {
|
|
449
|
+
const S = Math.min(o, d / 2, g / 2);
|
|
450
|
+
Tt(t, n, l, d, g, S), t.stroke();
|
|
451
|
+
} else
|
|
452
|
+
t.strokeRect(n, l, d, g);
|
|
453
|
+
if (!e) {
|
|
454
|
+
t.restore();
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
t.fillStyle = a.handleFill, t.strokeStyle = a.handleStroke, t.lineWidth = 1;
|
|
458
|
+
const w = Math.min(kt / 2, d / 6, g / 6), y = [
|
|
459
|
+
{ cx: n, cy: l },
|
|
460
|
+
{ cx: n + d, cy: l },
|
|
461
|
+
{ cx: n + d, cy: l + g },
|
|
462
|
+
{ cx: n, cy: l + g }
|
|
463
|
+
];
|
|
464
|
+
for (const S of y)
|
|
465
|
+
t.beginPath(), t.arc(S.cx, S.cy, w, 0, Math.PI * 2), t.fill(), t.stroke();
|
|
466
|
+
const c = n - lt, p = l - lt;
|
|
467
|
+
t.beginPath(), t.arc(c, p, w, 0, Math.PI * 2), t.fill(), t.stroke(), t.fillStyle = a.handleStroke, t.beginPath(), t.arc(c, p, Math.max(2, w * 0.35), 0, Math.PI * 2), t.fill(), t.restore();
|
|
468
|
+
}
|
|
469
|
+
function Tt(t, r, i, o, a, e) {
|
|
470
|
+
e = Math.min(e, o / 2, a / 2), t.beginPath(), t.moveTo(r + e, i), t.lineTo(r + o - e, i), t.arcTo(r + o, i, r + o, i + e, e), t.lineTo(r + o, i + a - e), t.arcTo(r + o, i + a, r + o - e, i + a, e), t.lineTo(r + e, i + a), t.arcTo(r, i + a, r, i + a - e, e), t.lineTo(r, i + e), t.arcTo(r, i, r + e, i, e), t.closePath();
|
|
471
|
+
}
|
|
472
|
+
function ne(t) {
|
|
473
|
+
const { x: r, y: i, width: o, height: a } = t, e = Jt;
|
|
474
|
+
return [
|
|
475
|
+
// Move-handle (NW diagonal) — checked first so it wins over the NW
|
|
476
|
+
// corner's hit area where they overlap.
|
|
477
|
+
{
|
|
478
|
+
target: "move-handle",
|
|
479
|
+
rect: {
|
|
480
|
+
x: r - lt - at,
|
|
481
|
+
y: i - lt - at,
|
|
482
|
+
w: at * 2,
|
|
483
|
+
h: at * 2
|
|
484
|
+
}
|
|
485
|
+
},
|
|
486
|
+
// Corner handles (highest priority — checked first)
|
|
487
|
+
{ target: "handle-nw", rect: { x: r - e, y: i - e, w: e * 2, h: e * 2 } },
|
|
488
|
+
{ target: "handle-ne", rect: { x: r + o - e, y: i - e, w: e * 2, h: e * 2 } },
|
|
489
|
+
{ target: "handle-se", rect: { x: r + o - e, y: i + a - e, w: e * 2, h: e * 2 } },
|
|
490
|
+
{ target: "handle-sw", rect: { x: r - e, y: i + a - e, w: e * 2, h: e * 2 } },
|
|
491
|
+
// Edge hit zones (no visual handle, but cursor + resize still work)
|
|
492
|
+
{ target: "handle-n", rect: { x: r + e, y: i - e, w: o - e * 2, h: e * 2 } },
|
|
493
|
+
{ target: "handle-s", rect: { x: r + e, y: i + a - e, w: o - e * 2, h: e * 2 } },
|
|
494
|
+
{ target: "handle-e", rect: { x: r + o - e, y: i + e, w: e * 2, h: a - e * 2 } },
|
|
495
|
+
{ target: "handle-w", rect: { x: r - e, y: i + e, w: e * 2, h: a - e * 2 } }
|
|
496
|
+
];
|
|
497
|
+
}
|
|
498
|
+
function re(t, r, i) {
|
|
499
|
+
const { x: o, y: a, width: e, height: h } = r;
|
|
500
|
+
t.save(), t.strokeStyle = `rgba(255, 255, 255, ${0.35 * i})`, t.lineWidth = 0.5;
|
|
501
|
+
for (let s = 1; s <= 2; s++) {
|
|
502
|
+
const n = o + e * s / 3;
|
|
503
|
+
t.beginPath(), t.moveTo(n, a), t.lineTo(n, a + h), t.stroke();
|
|
504
|
+
}
|
|
505
|
+
for (let s = 1; s <= 2; s++) {
|
|
506
|
+
const n = a + h * s / 3;
|
|
507
|
+
t.beginPath(), t.moveTo(o, n), t.lineTo(o + e, n), t.stroke();
|
|
508
|
+
}
|
|
509
|
+
t.restore();
|
|
510
|
+
}
|
|
511
|
+
function oe(t, r, i, o) {
|
|
512
|
+
i * 2 >= r.width || i * 2 >= r.height || (t.save(), t.strokeStyle = o, t.lineWidth = 1, t.setLineDash([6, 4]), t.strokeRect(
|
|
513
|
+
r.x + i,
|
|
514
|
+
r.y + i,
|
|
515
|
+
r.width - i * 2,
|
|
516
|
+
r.height - i * 2
|
|
517
|
+
), t.setLineDash([]), t.restore());
|
|
518
|
+
}
|
|
519
|
+
function ie(t, r, i, o = 20, a = !1, e) {
|
|
520
|
+
const h = t.getContext("2d");
|
|
521
|
+
if (!h) throw new Error("2D canvas context unavailable");
|
|
522
|
+
const s = h;
|
|
523
|
+
function n() {
|
|
524
|
+
if (e) return e;
|
|
525
|
+
if (t.parentElement) return t.parentElement;
|
|
526
|
+
let R = t.getRootNode();
|
|
527
|
+
for (; R && R !== document && R instanceof ShadowRoot; ) {
|
|
528
|
+
const P = R.host;
|
|
529
|
+
if (P instanceof HTMLElement) return P;
|
|
530
|
+
R = P.getRootNode();
|
|
531
|
+
}
|
|
532
|
+
return null;
|
|
533
|
+
}
|
|
534
|
+
let l = !0, d = null, g = !1, w = !1, y = 0;
|
|
535
|
+
const c = {
|
|
536
|
+
quarterTurns: 0,
|
|
537
|
+
rotation: 0,
|
|
538
|
+
flipH: 1,
|
|
539
|
+
flipV: 1,
|
|
540
|
+
scale: 1,
|
|
541
|
+
panX: 0,
|
|
542
|
+
panY: 0,
|
|
543
|
+
cropRect: { x: 0, y: 0, width: 1, height: 1 },
|
|
544
|
+
gridOpacity: 0,
|
|
545
|
+
interactive: !1
|
|
546
|
+
}, p = { ...c }, S = {
|
|
547
|
+
quarterTurns: 0,
|
|
548
|
+
flipH: 0,
|
|
549
|
+
flipV: 0
|
|
550
|
+
};
|
|
551
|
+
let x = { show: !1, size: 10, color: "rgba(255, 0, 0, 0.5)" }, C = 0, u = 0.5, m = 5, H = !1;
|
|
552
|
+
function V() {
|
|
553
|
+
if (g) return;
|
|
554
|
+
const R = n();
|
|
555
|
+
if (!R) return;
|
|
556
|
+
const P = window.devicePixelRatio, A = Math.min(Number.isFinite(P) && P > 0 ? P : 1, 2), F = R.getBoundingClientRect();
|
|
557
|
+
F.width <= 0 || F.height <= 0 || (t.width = Math.max(0, Math.floor(F.width * A)), t.height = Math.max(0, Math.floor(F.height * A)), t.style.width = `${F.width}px`, t.style.height = `${F.height}px`, s.setTransform(A, 0, 0, A, 0, 0), l = !0);
|
|
558
|
+
}
|
|
559
|
+
function z() {
|
|
560
|
+
const R = n();
|
|
561
|
+
return R ? { x: 0, y: 0, w: R.clientWidth, h: R.clientHeight } : { x: 0, y: 0, w: 0, h: 0 };
|
|
562
|
+
}
|
|
563
|
+
function E() {
|
|
564
|
+
const R = z(), P = c.cropRect;
|
|
565
|
+
return {
|
|
566
|
+
x: R.x + P.x * R.w,
|
|
567
|
+
y: R.y + P.y * R.h,
|
|
568
|
+
width: P.width * R.w,
|
|
569
|
+
height: P.height * R.h
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
function O(R, P) {
|
|
573
|
+
return 1 - Math.pow(1 - R, P * 60);
|
|
574
|
+
}
|
|
575
|
+
function _(R) {
|
|
576
|
+
if (a) {
|
|
577
|
+
c.quarterTurns = p.quarterTurns, c.rotation = p.rotation, c.flipH = p.flipH, c.flipV = p.flipV, c.scale = p.scale, c.panX = p.panX, c.panY = p.panY, c.cropRect = { ...p.cropRect }, c.gridOpacity = p.gridOpacity, c.interactive = p.interactive, l = !0;
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
let P = !1;
|
|
581
|
+
if (Math.abs(c.quarterTurns - p.quarterTurns) > 0.01) {
|
|
582
|
+
const T = -180 * (c.quarterTurns - p.quarterTurns), W = -22 * S.quarterTurns;
|
|
583
|
+
S.quarterTurns += (T + W) * R, c.quarterTurns += S.quarterTurns * R, Math.abs(c.quarterTurns - p.quarterTurns) < 0.01 && Math.abs(S.quarterTurns) < 0.01 && (c.quarterTurns = p.quarterTurns, S.quarterTurns = 0), P = !0, l = !0;
|
|
584
|
+
}
|
|
585
|
+
if (Math.abs(c.flipH - p.flipH) > 0.01) {
|
|
586
|
+
const T = -400 * (c.flipH - p.flipH), W = -28 * S.flipH;
|
|
587
|
+
S.flipH += (T + W) * R, c.flipH += S.flipH * R, Math.abs(c.flipH - p.flipH) < 0.01 && Math.abs(S.flipH) < 0.01 && (c.flipH = p.flipH, S.flipH = 0), P = !0, l = !0;
|
|
588
|
+
}
|
|
589
|
+
if (Math.abs(c.flipV - p.flipV) > 0.01) {
|
|
590
|
+
const T = -400 * (c.flipV - p.flipV), W = -28 * S.flipV;
|
|
591
|
+
S.flipV += (T + W) * R, c.flipV += S.flipV * R, Math.abs(c.flipV - p.flipV) < 0.01 && Math.abs(S.flipV) < 0.01 && (c.flipV = p.flipV, S.flipV = 0), P = !0, l = !0;
|
|
592
|
+
}
|
|
593
|
+
const A = O(0.15, R), F = O(0.12, R), K = O(0.12, R);
|
|
594
|
+
if (Math.abs(c.rotation - p.rotation) > 0.01 && (c.rotation = U(c.rotation, p.rotation, A), P = !0, l = !0), Math.abs(c.scale - p.scale) > 1e-3 && (c.scale = U(c.scale, p.scale, A), P = !0, l = !0), !!p.interactive) {
|
|
595
|
+
(c.panX !== p.panX || c.panY !== p.panY) && (c.panX = p.panX, c.panY = p.panY, l = !0);
|
|
596
|
+
const b = p.cropRect, T = c.cropRect;
|
|
597
|
+
(T.x !== b.x || T.y !== b.y || T.width !== b.width || T.height !== b.height) && (c.cropRect = { ...b }, l = !0);
|
|
598
|
+
} else {
|
|
599
|
+
Math.abs(c.panX - p.panX) > 0.1 && (c.panX = U(c.panX, p.panX, A), P = !0, l = !0), Math.abs(c.panY - p.panY) > 0.1 && (c.panY = U(c.panY, p.panY, A), P = !0, l = !0);
|
|
600
|
+
const b = c.cropRect, T = p.cropRect;
|
|
601
|
+
(Math.abs(b.x - T.x) > 1e-4 || Math.abs(b.y - T.y) > 1e-4 || Math.abs(b.width - T.width) > 1e-4 || Math.abs(b.height - T.height) > 1e-4) && (c.cropRect = {
|
|
602
|
+
x: U(b.x, T.x, F),
|
|
603
|
+
y: U(b.y, T.y, F),
|
|
604
|
+
width: U(b.width, T.width, F),
|
|
605
|
+
height: U(b.height, T.height, F)
|
|
606
|
+
}, P = !0, l = !0);
|
|
607
|
+
}
|
|
608
|
+
if (Math.abs(c.gridOpacity - p.gridOpacity) > 0.01 && (c.gridOpacity = U(c.gridOpacity, p.gridOpacity, K), P = !0, l = !0), c.scale < u) {
|
|
609
|
+
const T = -400 * (c.scale - u), W = -28 * C;
|
|
610
|
+
C += (T + W) * R, c.scale += C * R, Math.abs(c.scale - u) < 1e-3 && Math.abs(C) < 1e-3 && (c.scale = u, C = 0), P = !0, l = !0;
|
|
611
|
+
} else if (c.scale > m) {
|
|
612
|
+
const T = -400 * (c.scale - m), W = -28 * C;
|
|
613
|
+
C += (T + W) * R, c.scale += C * R, Math.abs(c.scale - m) < 1e-3 && Math.abs(C) < 1e-3 && (c.scale = m, C = 0), P = !0, l = !0;
|
|
614
|
+
}
|
|
615
|
+
P || (c.rotation = p.rotation, c.scale = p.scale, c.panX = p.panX, c.panY = p.panY, c.cropRect = { ...p.cropRect }, c.gridOpacity = p.gridOpacity, c.interactive = p.interactive);
|
|
616
|
+
}
|
|
617
|
+
function $(R) {
|
|
618
|
+
if (g || !w) {
|
|
619
|
+
d = null;
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
const P = typeof R == "number" ? R : performance.now(), A = y === 0 ? 1 / 60 : Math.min(0.25, Math.max(0, (P - y) / 1e3));
|
|
623
|
+
if (y = P, d = requestAnimationFrame($), _(A), !l) return;
|
|
624
|
+
const F = n();
|
|
625
|
+
if (!F) return;
|
|
626
|
+
const K = F.clientWidth, D = F.clientHeight;
|
|
627
|
+
if (K === 0 || D === 0) return;
|
|
628
|
+
l = !1, s.clearRect(0, 0, K, D);
|
|
629
|
+
const b = z();
|
|
630
|
+
Gt(s, r, b, c, H);
|
|
631
|
+
const T = E(), W = i(), ut = n() ?? t, Q = (j, it) => getComputedStyle(ut).getPropertyValue(j).trim() || it;
|
|
632
|
+
if (!(H && W === "rect")) {
|
|
633
|
+
const j = Q("--sfx-cr-overlay-color", "rgba(0, 0, 0, 0.55)");
|
|
634
|
+
jt(s, K, D, T, W, o, j);
|
|
635
|
+
}
|
|
636
|
+
H && W === "rect" || ee(s, T, W, o, {
|
|
637
|
+
frame: Q("--sfx-cr-frame-color", "#ffffff"),
|
|
638
|
+
frameShadow: Q("--sfx-cr-frame-shadow", "rgba(0, 0, 0, 0.3)"),
|
|
639
|
+
handleFill: Q("--sfx-cr-handle-fill", "#ffffff"),
|
|
640
|
+
handleStroke: Q("--sfx-cr-handle-stroke", "rgba(0, 0, 0, 0.25)")
|
|
641
|
+
}, !H), x.show && oe(s, T, x.size, x.color), c.gridOpacity > 0.01 && re(s, T, c.gridOpacity);
|
|
642
|
+
}
|
|
643
|
+
return V(), {
|
|
644
|
+
markDirty() {
|
|
645
|
+
l = !0;
|
|
646
|
+
},
|
|
647
|
+
startLoop() {
|
|
648
|
+
w || g || (w = !0, y = 0, $());
|
|
649
|
+
},
|
|
650
|
+
stopLoop() {
|
|
651
|
+
w = !1, d !== null && (cancelAnimationFrame(d), d = null);
|
|
652
|
+
},
|
|
653
|
+
setDisplayState(R) {
|
|
654
|
+
Object.assign(p, R), c.rotationPivot = R.rotationPivot, l = !0;
|
|
655
|
+
},
|
|
656
|
+
getDisplayState() {
|
|
657
|
+
return { ...c };
|
|
658
|
+
},
|
|
659
|
+
getCanvasCropRect: E,
|
|
660
|
+
setScaleBounds(R, P) {
|
|
661
|
+
u = R, m = P;
|
|
662
|
+
},
|
|
663
|
+
setBleedConfig(R) {
|
|
664
|
+
x = R, l = !0;
|
|
665
|
+
},
|
|
666
|
+
setFixedFrame(R) {
|
|
667
|
+
H = R, l = !0;
|
|
668
|
+
},
|
|
669
|
+
resize: V,
|
|
670
|
+
destroy() {
|
|
671
|
+
g = !0, w = !1, d !== null && (cancelAnimationFrame(d), d = null);
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
const ae = [
|
|
676
|
+
"nw",
|
|
677
|
+
"ne",
|
|
678
|
+
"sw",
|
|
679
|
+
"se",
|
|
680
|
+
"n",
|
|
681
|
+
"s",
|
|
682
|
+
"e",
|
|
683
|
+
"w"
|
|
684
|
+
];
|
|
685
|
+
function se(t) {
|
|
686
|
+
return ae.includes(t) ? t : null;
|
|
687
|
+
}
|
|
688
|
+
function ce(t, r, i) {
|
|
689
|
+
return t >= i.x && t <= i.x + i.w && r >= i.y && r <= i.y + i.h;
|
|
690
|
+
}
|
|
691
|
+
function pt(t, r, i) {
|
|
692
|
+
const o = ne(i);
|
|
693
|
+
for (const { target: a, rect: e } of o)
|
|
694
|
+
if (ce(t, r, e)) {
|
|
695
|
+
if (a === "move-handle") return { type: "move-handle" };
|
|
696
|
+
const h = se(a.replace("handle-", ""));
|
|
697
|
+
if (h) return { type: "handle", position: h };
|
|
698
|
+
}
|
|
699
|
+
return t >= i.x && t <= i.x + i.width && r >= i.y && r <= i.y + i.height ? { type: "crop-area" } : { type: "outside" };
|
|
700
|
+
}
|
|
701
|
+
function Pt(t, r) {
|
|
702
|
+
if (t.type === "move-handle") return "move";
|
|
703
|
+
switch (t.type) {
|
|
704
|
+
case "crop-area":
|
|
705
|
+
return "move";
|
|
706
|
+
case "outside":
|
|
707
|
+
return "crosshair";
|
|
708
|
+
case "handle":
|
|
709
|
+
switch (t.position) {
|
|
710
|
+
case "nw":
|
|
711
|
+
case "se":
|
|
712
|
+
return "nwse-resize";
|
|
713
|
+
case "ne":
|
|
714
|
+
case "sw":
|
|
715
|
+
return "nesw-resize";
|
|
716
|
+
case "n":
|
|
717
|
+
case "s":
|
|
718
|
+
return "ns-resize";
|
|
719
|
+
case "e":
|
|
720
|
+
case "w":
|
|
721
|
+
return "ew-resize";
|
|
722
|
+
default:
|
|
723
|
+
return "default";
|
|
724
|
+
}
|
|
725
|
+
default:
|
|
726
|
+
return "default";
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
function le(t, r) {
|
|
730
|
+
const i = /* @__PURE__ */ new Map();
|
|
731
|
+
let o = 0, a = !1;
|
|
732
|
+
function e(y) {
|
|
733
|
+
return y === "touch" || y === "pen" ? y : "mouse";
|
|
734
|
+
}
|
|
735
|
+
function h(y) {
|
|
736
|
+
const c = t.getBoundingClientRect();
|
|
737
|
+
return {
|
|
738
|
+
x: y.clientX - c.left,
|
|
739
|
+
y: y.clientY - c.top
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
function s() {
|
|
743
|
+
return [...i.values()];
|
|
744
|
+
}
|
|
745
|
+
function n(y) {
|
|
746
|
+
if (y.pointerType === "mouse" && y.button !== 0) return;
|
|
747
|
+
try {
|
|
748
|
+
t.setPointerCapture(y.pointerId);
|
|
749
|
+
} catch {
|
|
750
|
+
}
|
|
751
|
+
const c = h(y), p = {
|
|
752
|
+
id: y.pointerId,
|
|
753
|
+
x: c.x,
|
|
754
|
+
y: c.y,
|
|
755
|
+
startX: c.x,
|
|
756
|
+
startY: c.y,
|
|
757
|
+
pressure: y.pressure,
|
|
758
|
+
pointerType: e(y.pointerType),
|
|
759
|
+
shiftKey: y.shiftKey,
|
|
760
|
+
altKey: y.altKey
|
|
761
|
+
};
|
|
762
|
+
i.set(y.pointerId, p), r.onPointerDown(p, s());
|
|
763
|
+
}
|
|
764
|
+
function l(y) {
|
|
765
|
+
const c = i.get(y.pointerId);
|
|
766
|
+
if (!c) {
|
|
767
|
+
if (r.onHover) {
|
|
768
|
+
const x = h(y);
|
|
769
|
+
r.onHover({
|
|
770
|
+
id: y.pointerId,
|
|
771
|
+
x: x.x,
|
|
772
|
+
y: x.y,
|
|
773
|
+
startX: x.x,
|
|
774
|
+
startY: x.y,
|
|
775
|
+
pressure: 0,
|
|
776
|
+
pointerType: e(y.pointerType),
|
|
777
|
+
shiftKey: y.shiftKey,
|
|
778
|
+
altKey: y.altKey
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
const p = h(y);
|
|
784
|
+
c.x = p.x, c.y = p.y, c.pressure = y.pressure, c.shiftKey = y.shiftKey, c.altKey = y.altKey;
|
|
785
|
+
const S = s();
|
|
786
|
+
if (r.onPointerMove(c, S), S.length === 2 && r.onPinch) {
|
|
787
|
+
const [x, C] = S, u = Math.sqrt((C.x - x.x) ** 2 + (C.y - x.y) ** 2);
|
|
788
|
+
!a && u > 10 && (o = u, a = !0), a && r.onPinch({
|
|
789
|
+
centerX: (x.x + C.x) / 2,
|
|
790
|
+
centerY: (x.y + C.y) / 2,
|
|
791
|
+
scale: u / o,
|
|
792
|
+
distance: u
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
function d(y) {
|
|
797
|
+
const c = i.get(y.pointerId);
|
|
798
|
+
if (c) {
|
|
799
|
+
i.delete(y.pointerId);
|
|
800
|
+
try {
|
|
801
|
+
t.releasePointerCapture(y.pointerId);
|
|
802
|
+
} catch {
|
|
803
|
+
}
|
|
804
|
+
s().length < 2 && (a = !1, o = 0), r.onPointerUp(c, s());
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
function g(y) {
|
|
808
|
+
r.onWheel && r.onWheel(y);
|
|
809
|
+
}
|
|
810
|
+
t.addEventListener("pointerdown", n), t.addEventListener("pointermove", l), t.addEventListener("pointerup", d), t.addEventListener("pointercancel", d), t.addEventListener("wheel", g, { passive: !1 });
|
|
811
|
+
const w = (y) => y.preventDefault();
|
|
812
|
+
return t.addEventListener("contextmenu", w), t.style.touchAction = "none", {
|
|
813
|
+
destroy() {
|
|
814
|
+
t.removeEventListener("pointerdown", n), t.removeEventListener("pointermove", l), t.removeEventListener("pointerup", d), t.removeEventListener("pointercancel", d), t.removeEventListener("wheel", g), t.removeEventListener("contextmenu", w), t.style.touchAction = "", i.clear();
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
function ue(t, r, i, o, a) {
|
|
819
|
+
const e = (r - t.startX) / o, h = (i - t.startY) / a, { startCrop: s } = t;
|
|
820
|
+
return {
|
|
821
|
+
x: I(s.x - e, 0, 1 - s.width),
|
|
822
|
+
y: I(s.y - h, 0, 1 - s.height),
|
|
823
|
+
width: s.width,
|
|
824
|
+
height: s.height
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
function fe(t, r, i, o) {
|
|
828
|
+
return {
|
|
829
|
+
handle: t.startsWith("handle-") ? t.slice(7) : t,
|
|
830
|
+
startCrop: { ...r },
|
|
831
|
+
startX: i,
|
|
832
|
+
startY: o
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
function he(t, r, i, o, a, e, h, s = { shiftKey: !1, altKey: !1 }) {
|
|
836
|
+
const n = (r - t.startX) / o, l = (i - t.startY) / a, { startCrop: d, handle: g } = t;
|
|
837
|
+
let w = d.x, y = d.y, c = d.width, p = d.height;
|
|
838
|
+
const S = h / o, x = h / a;
|
|
839
|
+
if (g.includes("w")) {
|
|
840
|
+
const m = I(w + n, 0, w + c - S);
|
|
841
|
+
c = c - (m - w), w = m;
|
|
842
|
+
}
|
|
843
|
+
if (g.includes("e") && (c = I(c + n, S, 1 - w)), g.includes("n")) {
|
|
844
|
+
const m = I(y + l, 0, y + p - x);
|
|
845
|
+
p = p - (m - y), y = m;
|
|
846
|
+
}
|
|
847
|
+
if (g.includes("s") && (p = I(p + l, x, 1 - y)), c = Math.max(c, S), p = Math.max(p, x), s.altKey) {
|
|
848
|
+
const m = d.x + d.width / 2, H = d.y + d.height / 2, V = c / 2, z = p / 2;
|
|
849
|
+
w = I(m - V, 0, 1 - c), y = I(H - z, 0, 1 - p);
|
|
850
|
+
}
|
|
851
|
+
let C = { x: w, y, width: c, height: p }, u = gt(e);
|
|
852
|
+
return s.shiftKey && e === "free" && (u = d.width / d.height), u !== null && (C = Nt(C, u, g, o, a, h)), C;
|
|
853
|
+
}
|
|
854
|
+
function de(t, r) {
|
|
855
|
+
if (t.length < 2) return null;
|
|
856
|
+
const [i, o] = t, a = Bt(i.x, i.y, o.x, o.y);
|
|
857
|
+
return a < 10 ? null : {
|
|
858
|
+
initialDistance: a,
|
|
859
|
+
initialScale: r,
|
|
860
|
+
initialCenterX: (i.x + o.x) / 2,
|
|
861
|
+
initialCenterY: (i.y + o.y) / 2
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
function pe(t, r, i, o, a, e, h) {
|
|
865
|
+
const s = 1 - t * i.sensitivity * 1e-3, n = I(r * s, i.minScale, i.maxScale);
|
|
866
|
+
let l = 0, d = 0;
|
|
867
|
+
if (o !== void 0 && e !== void 0) {
|
|
868
|
+
const g = 1 - n / r;
|
|
869
|
+
l = (o - e) * g, d = (a - h) * g;
|
|
870
|
+
}
|
|
871
|
+
return { scale: n, panDeltaX: l, panDeltaY: d };
|
|
872
|
+
}
|
|
873
|
+
function ye(t, r) {
|
|
874
|
+
function i(o) {
|
|
875
|
+
if (!((typeof o.composedPath == "function" ? o.composedPath() : []).includes(t) || t.contains(document.activeElement) || document.activeElement === t) || o.ctrlKey || o.metaKey || o.altKey) return;
|
|
876
|
+
const h = o.shiftKey ? 0.01 : 5e-3;
|
|
877
|
+
switch (o.key) {
|
|
878
|
+
case "ArrowLeft":
|
|
879
|
+
o.preventDefault(), r.onMoveCrop(-h, 0);
|
|
880
|
+
break;
|
|
881
|
+
case "ArrowRight":
|
|
882
|
+
o.preventDefault(), r.onMoveCrop(h, 0);
|
|
883
|
+
break;
|
|
884
|
+
case "ArrowUp":
|
|
885
|
+
o.preventDefault(), r.onMoveCrop(0, -h);
|
|
886
|
+
break;
|
|
887
|
+
case "ArrowDown":
|
|
888
|
+
o.preventDefault(), r.onMoveCrop(0, h);
|
|
889
|
+
break;
|
|
890
|
+
case "r":
|
|
891
|
+
case "R":
|
|
892
|
+
o.preventDefault(), r.onRotateLeft();
|
|
893
|
+
break;
|
|
894
|
+
case "f":
|
|
895
|
+
case "F":
|
|
896
|
+
o.preventDefault(), r.onFlipH();
|
|
897
|
+
break;
|
|
898
|
+
case "+":
|
|
899
|
+
case "=":
|
|
900
|
+
o.preventDefault(), r.onZoomIn();
|
|
901
|
+
break;
|
|
902
|
+
case "-":
|
|
903
|
+
case "_":
|
|
904
|
+
o.preventDefault(), r.onZoomOut();
|
|
905
|
+
break;
|
|
906
|
+
case "0":
|
|
907
|
+
o.preventDefault(), r.onResetZoom();
|
|
908
|
+
break;
|
|
909
|
+
case "[":
|
|
910
|
+
o.preventDefault(), r.onRotateFine(-1);
|
|
911
|
+
break;
|
|
912
|
+
case "]":
|
|
913
|
+
o.preventDefault(), r.onRotateFine(1);
|
|
914
|
+
break;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
return t.addEventListener("keydown", i), {
|
|
918
|
+
destroy() {
|
|
919
|
+
t.removeEventListener("keydown", i);
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
function Te(t) {
|
|
924
|
+
t.setAttribute("role", "application"), t.setAttribute("aria-roledescription", "image crop tool"), t.setAttribute("aria-label", "Image crop tool — use arrow keys to move crop, R to rotate, F to flip horizontal, +/- to zoom"), t.setAttribute("tabindex", "0");
|
|
925
|
+
}
|
|
926
|
+
function yt(t, r, i = "free") {
|
|
927
|
+
let o = t.querySelector(".sfx-cr-sr-only[aria-live]");
|
|
928
|
+
o || (o = document.createElement("div"), o.className = "sfx-cr-sr-only", o.setAttribute("aria-live", "polite"), t.appendChild(o));
|
|
929
|
+
const a = r.quarterTurns + r.rotation, e = Math.round(r.scale * 100), h = i, s = r.flipH ? ", flipped horizontal" : "";
|
|
930
|
+
o.textContent = `Crop: ${h}, rotation ${a.toFixed(1)}°${s}, zoom ${e}%`;
|
|
931
|
+
}
|
|
932
|
+
function mt(t) {
|
|
933
|
+
const r = t.getContext("2d");
|
|
934
|
+
if (!r) throw new Error("2D canvas context unavailable");
|
|
935
|
+
return r;
|
|
936
|
+
}
|
|
937
|
+
function ge(t, r, i) {
|
|
938
|
+
const o = t.quarterTurns + t.rotation, a = Math.round(t.cropRect.width * r), e = Math.round(t.cropRect.height * i), h = Math.round(t.quarterTurns / 90) % 2 !== 0;
|
|
939
|
+
return {
|
|
940
|
+
rotation: o,
|
|
941
|
+
flipH: t.flipH,
|
|
942
|
+
flipV: t.flipV,
|
|
943
|
+
scale: t.scale,
|
|
944
|
+
crop: {
|
|
945
|
+
x: Math.round(t.cropRect.x * r),
|
|
946
|
+
y: Math.round(t.cropRect.y * i),
|
|
947
|
+
width: a,
|
|
948
|
+
height: e
|
|
949
|
+
},
|
|
950
|
+
outputWidth: h ? e : a,
|
|
951
|
+
outputHeight: h ? a : e
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
function me(t, r, i, o, a = "free", e = 20, h = 0, s = 0, n = "classic") {
|
|
955
|
+
const l = t.naturalWidth, d = t.naturalHeight, g = n === "fixed" && h > 0 && s > 0;
|
|
956
|
+
let w, y, c, p;
|
|
957
|
+
if (g) {
|
|
958
|
+
const F = ct(h, s, l, d, r.quarterTurns), K = Math.max(l / F.drawW, d / F.drawH);
|
|
959
|
+
w = Math.max(1, Math.round(h * K)), y = Math.max(1, Math.round(s * K));
|
|
960
|
+
const D = ct(w, y, l, d, r.quarterTurns);
|
|
961
|
+
c = D.drawW, p = D.drawH;
|
|
962
|
+
} else {
|
|
963
|
+
w = l, y = d;
|
|
964
|
+
const K = Math.round(r.quarterTurns / 90) % 2 !== 0 ? Math.min(w, y) / Math.max(w, y) : 1;
|
|
965
|
+
c = w * K, p = y * K;
|
|
966
|
+
}
|
|
967
|
+
const S = r.cropRect.x * w, x = r.cropRect.y * y, C = r.cropRect.width * w, u = r.cropRect.height * y;
|
|
968
|
+
let m = Math.max(1, Math.round(C)), H = Math.max(1, Math.round(u));
|
|
969
|
+
i > 0 && m > i && (H = Math.max(1, Math.round(H * (i / m))), m = i), o > 0 && H > o && (m = Math.max(1, Math.round(m * (o / H))), H = o);
|
|
970
|
+
const V = C > 1e-6 ? m / C : 1, z = document.createElement("canvas");
|
|
971
|
+
z.width = m, z.height = H;
|
|
972
|
+
const E = mt(z);
|
|
973
|
+
E.save(), E.scale(V, V), E.translate(-S, -x);
|
|
974
|
+
const O = (r.cropRect.x + r.cropRect.width / 2) * w, _ = (r.cropRect.y + r.cropRect.height / 2) * y, $ = r.rotationPivot ?? {
|
|
975
|
+
x: r.cropRect.x + r.cropRect.width / 2,
|
|
976
|
+
y: r.cropRect.y + r.cropRect.height / 2
|
|
977
|
+
}, R = $.x * w, P = $.y * y;
|
|
978
|
+
r.rotation !== 0 && (E.translate(R, P), E.rotate(st(r.rotation)), E.translate(-R, -P)), (r.flipH || r.flipV) && (E.translate(O, _), E.scale(r.flipH ? -1 : 1, r.flipV ? -1 : 1), E.translate(-O, -_)), E.translate(w / 2, y / 2), E.scale(r.scale, r.scale);
|
|
979
|
+
const A = h > 0 ? w / h : 1;
|
|
980
|
+
return E.translate(r.panX * A, r.panY * A), r.quarterTurns !== 0 && E.rotate(st(r.quarterTurns)), E.drawImage(t, -c / 2, -p / 2, c, p), E.restore(), a === "circle" ? ve(z) : a === "rounded-rect" && we(z, e), z;
|
|
981
|
+
}
|
|
982
|
+
function we(t, r) {
|
|
983
|
+
const i = mt(t), o = t.width, a = t.height, e = Math.min(r, o / 2, a / 2);
|
|
984
|
+
i.globalCompositeOperation = "destination-in", i.beginPath(), i.moveTo(e, 0), i.lineTo(o - e, 0), i.arcTo(o, 0, o, e, e), i.lineTo(o, a - e), i.arcTo(o, a, o - e, a, e), i.lineTo(e, a), i.arcTo(0, a, 0, a - e, e), i.lineTo(0, e), i.arcTo(0, 0, e, 0, e), i.closePath(), i.fill(), i.globalCompositeOperation = "source-over";
|
|
985
|
+
}
|
|
986
|
+
function ve(t) {
|
|
987
|
+
const r = mt(t), i = t.width, o = t.height;
|
|
988
|
+
r.globalCompositeOperation = "destination-in", r.beginPath(), r.ellipse(i / 2, o / 2, i / 2, o / 2, 0, 0, Math.PI * 2), r.fill(), r.globalCompositeOperation = "source-over";
|
|
989
|
+
}
|
|
990
|
+
async function Se(t, r, i) {
|
|
991
|
+
return new Promise((o, a) => {
|
|
992
|
+
let e = !1;
|
|
993
|
+
try {
|
|
994
|
+
t.toBlob(
|
|
995
|
+
(h) => {
|
|
996
|
+
e || (e = !0, h ? o(h) : a(new Error("Failed to create blob (canvas may be empty or tainted)")));
|
|
997
|
+
},
|
|
998
|
+
r,
|
|
999
|
+
i
|
|
1000
|
+
);
|
|
1001
|
+
} catch (h) {
|
|
1002
|
+
e || (e = !0, a(h instanceof Error ? h : new Error(String(h))));
|
|
1003
|
+
}
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
function Re(t) {
|
|
1007
|
+
const { canvas: r, host: i, layoutContainer: o, callbacks: a = {} } = t;
|
|
1008
|
+
let e = { ...t.config }, h = e.cropShape, s = null, n = xt(e.cropShape), l = null, d = null, g = null, w = null, y = null, c = !1, p = !1, S = 0, x = null, C = null, u = null, m = null, H = null, V = 0, z = 0, E = 0;
|
|
1009
|
+
e.initialCrop && (n = k(n, e.initialCrop)), e.initialRotation && (n = ht(n, e.initialRotation)), e.initialScale && e.initialScale !== 1 && (n = nt(n, e.initialScale, e.minScale, e.maxScale));
|
|
1010
|
+
function O() {
|
|
1011
|
+
return h === "circle" ? "circle" : h === "rounded-rect" ? "rounded-rect" : "rect";
|
|
1012
|
+
}
|
|
1013
|
+
function _() {
|
|
1014
|
+
return { ...n, cropRect: { ...n.cropRect } };
|
|
1015
|
+
}
|
|
1016
|
+
function $() {
|
|
1017
|
+
if (!s) return { ...n.cropRect };
|
|
1018
|
+
const f = s.naturalWidth, v = s.naturalHeight;
|
|
1019
|
+
return {
|
|
1020
|
+
x: Math.round(n.cropRect.x * f),
|
|
1021
|
+
y: Math.round(n.cropRect.y * v),
|
|
1022
|
+
width: Math.round(n.cropRect.width * f),
|
|
1023
|
+
height: Math.round(n.cropRect.height * v)
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
const R = { x: 0, y: 0, width: 1, height: 1 };
|
|
1027
|
+
let P = 0, A = 0;
|
|
1028
|
+
function F() {
|
|
1029
|
+
const f = o.clientWidth, v = o.clientHeight;
|
|
1030
|
+
return f > 0 && v > 0 && (P = f, A = v), { w: f > 0 ? f : P, h: v > 0 ? v : A };
|
|
1031
|
+
}
|
|
1032
|
+
function K() {
|
|
1033
|
+
if (!s || !l) return;
|
|
1034
|
+
const { w: f, h: v } = F();
|
|
1035
|
+
if (f <= 0 || v <= 0) return;
|
|
1036
|
+
let M, L, Y;
|
|
1037
|
+
if (e.variant === "fixed") {
|
|
1038
|
+
M = { x: 0, y: 0, width: f, height: v };
|
|
1039
|
+
const X = ct(f, v, s.naturalWidth, s.naturalHeight, n.quarterTurns);
|
|
1040
|
+
L = X.drawW, Y = X.drawH;
|
|
1041
|
+
} else {
|
|
1042
|
+
if (Math.round(n.quarterTurns / 90) % 2 !== 0) {
|
|
1043
|
+
l.setScaleBounds(e.minScale, e.maxScale);
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
const X = n.cropRect;
|
|
1047
|
+
M = { x: X.x * f, y: X.y * v, width: X.width * f, height: X.height * v }, L = f, Y = v;
|
|
1048
|
+
}
|
|
1049
|
+
const q = _t(n, f, v, M, L, Y, e.maxScale);
|
|
1050
|
+
n = { ...n, scale: q.scale, panX: q.panX, panY: q.panY }, l.setScaleBounds(q.minScale, e.maxScale);
|
|
1051
|
+
}
|
|
1052
|
+
function D() {
|
|
1053
|
+
if (!l) return;
|
|
1054
|
+
K();
|
|
1055
|
+
const f = {
|
|
1056
|
+
quarterTurns: n.quarterTurns,
|
|
1057
|
+
rotation: n.rotation,
|
|
1058
|
+
flipH: n.flipH ? -1 : 1,
|
|
1059
|
+
flipV: n.flipV ? -1 : 1,
|
|
1060
|
+
scale: n.scale,
|
|
1061
|
+
panX: n.panX,
|
|
1062
|
+
panY: n.panY,
|
|
1063
|
+
cropRect: { ...n.cropRect },
|
|
1064
|
+
rotationPivot: n.rotationPivot,
|
|
1065
|
+
gridOpacity: p || e.showGrid === !0 ? 1 : 0,
|
|
1066
|
+
interactive: p
|
|
1067
|
+
};
|
|
1068
|
+
l.setDisplayState(f);
|
|
1069
|
+
}
|
|
1070
|
+
function b() {
|
|
1071
|
+
var f;
|
|
1072
|
+
(f = a.onChange) == null || f.call(a, _());
|
|
1073
|
+
}
|
|
1074
|
+
function T() {
|
|
1075
|
+
var f;
|
|
1076
|
+
(f = a.onCropChange) == null || f.call(a, $());
|
|
1077
|
+
}
|
|
1078
|
+
w = new ResizeObserver(() => {
|
|
1079
|
+
c || (y && clearTimeout(y), y = setTimeout(() => {
|
|
1080
|
+
y = null, !c && (l == null || l.resize(), D(), l == null || l.markDirty());
|
|
1081
|
+
}, 16));
|
|
1082
|
+
}), w.observe(o);
|
|
1083
|
+
async function W(f) {
|
|
1084
|
+
var M, L, Y, q, X;
|
|
1085
|
+
if (c) return;
|
|
1086
|
+
const v = ++S;
|
|
1087
|
+
(M = a.onLoadingChange) == null || M.call(a, !0, null);
|
|
1088
|
+
try {
|
|
1089
|
+
const Z = new Image();
|
|
1090
|
+
if (Z.crossOrigin = "anonymous", await new Promise((et, qt) => {
|
|
1091
|
+
Z.onload = () => et(), Z.onerror = () => qt(new Error(`Failed to load image: ${f}`)), Z.src = f;
|
|
1092
|
+
}), c || v !== S) return;
|
|
1093
|
+
s = Z, (L = a.onLoadingChange) == null || L.call(a, !1, null), (Y = a.onImageLoad) == null || Y.call(a, Z), ut();
|
|
1094
|
+
} catch (Z) {
|
|
1095
|
+
if (c || v !== S) return;
|
|
1096
|
+
const et = Z.message;
|
|
1097
|
+
(q = a.onLoadingChange) == null || q.call(a, !1, et), (X = a.onError) == null || X.call(a, Z);
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
function ut() {
|
|
1101
|
+
var v, M;
|
|
1102
|
+
if (!s) return;
|
|
1103
|
+
e.variant === "fixed" ? n = { ...n, cropRect: { ...R } } : e.initialCrop || (n = dt(n, h, s.naturalWidth, s.naturalHeight));
|
|
1104
|
+
const f = !e.enableAnimations || typeof window < "u" && ((v = window.matchMedia) == null ? void 0 : v.call(window, "(prefers-reduced-motion: reduce)").matches);
|
|
1105
|
+
l = ie(
|
|
1106
|
+
r,
|
|
1107
|
+
s,
|
|
1108
|
+
O,
|
|
1109
|
+
e.borderRadius,
|
|
1110
|
+
f,
|
|
1111
|
+
// Pass the layout container explicitly: the canvas lives in its own
|
|
1112
|
+
// shadow root and `canvas.parentElement` returns null there.
|
|
1113
|
+
o
|
|
1114
|
+
), l.setScaleBounds(e.minScale, e.maxScale), l.setFixedFrame(e.variant === "fixed"), l.setBleedConfig({
|
|
1115
|
+
show: e.showBleedMargin,
|
|
1116
|
+
size: e.bleedMarginSize,
|
|
1117
|
+
color: e.bleedMarginColor
|
|
1118
|
+
}), D(), l.startLoop(), Q(), e.keyboard && (g = ye(i, {
|
|
1119
|
+
onRotateLeft: () => wt(),
|
|
1120
|
+
onFlipH: () => vt(),
|
|
1121
|
+
onZoomIn: () => rt(n.scale + 0.1),
|
|
1122
|
+
onZoomOut: () => rt(n.scale - 0.1),
|
|
1123
|
+
onResetZoom: () => rt(1),
|
|
1124
|
+
onMoveCrop: (L, Y) => {
|
|
1125
|
+
if (e.variant === "fixed") return;
|
|
1126
|
+
const q = n.cropRect;
|
|
1127
|
+
n = k(n, { x: q.x + L, y: q.y + Y, width: q.width, height: q.height }), D(), b(), T();
|
|
1128
|
+
},
|
|
1129
|
+
onRotateFine: (L) => St(n.rotation + L)
|
|
1130
|
+
})), (M = a.onReady) == null || M.call(a);
|
|
1131
|
+
}
|
|
1132
|
+
function Q() {
|
|
1133
|
+
d = le(r, {
|
|
1134
|
+
onPointerDown: (f, v) => {
|
|
1135
|
+
const M = Date.now(), L = M - V, Y = Math.sqrt((f.x - z) ** 2 + (f.y - E) ** 2);
|
|
1136
|
+
if (L < 300 && Y < 20 && v.length === 1) {
|
|
1137
|
+
rt(1), V = 0;
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
if (V = M, z = f.x, E = f.y, v.length === 2) {
|
|
1141
|
+
H = de(v, n.scale), x = null, m = null;
|
|
1142
|
+
return;
|
|
1143
|
+
}
|
|
1144
|
+
const q = l.getCanvasCropRect();
|
|
1145
|
+
let X = pt(f.x, f.y, q);
|
|
1146
|
+
e.variant === "fixed" && (X.type === "handle" || X.type === "move-handle") && (X = { type: "crop-area" }), p = !0, X.type === "move-handle" ? u = {
|
|
1147
|
+
startX: f.x,
|
|
1148
|
+
startY: f.y,
|
|
1149
|
+
startRect: { ...n.cropRect }
|
|
1150
|
+
} : X.type === "crop-area" ? C = { startX: f.x, startY: f.y, startPanX: n.panX, startPanY: n.panY } : X.type === "handle" && X.position && (m = fe("handle-" + X.position, n.cropRect, f.x, f.y)), D();
|
|
1151
|
+
},
|
|
1152
|
+
onPointerMove: (f) => {
|
|
1153
|
+
if (!s) return;
|
|
1154
|
+
const v = l.getCanvasCropRect();
|
|
1155
|
+
if (u) {
|
|
1156
|
+
const { displayW: M, displayH: L } = j();
|
|
1157
|
+
if (M > 0 && L > 0) {
|
|
1158
|
+
const Y = (f.x - u.startX) / M, q = (f.y - u.startY) / L;
|
|
1159
|
+
n = k(n, {
|
|
1160
|
+
x: u.startRect.x + Y,
|
|
1161
|
+
y: u.startRect.y + q,
|
|
1162
|
+
width: u.startRect.width,
|
|
1163
|
+
height: u.startRect.height
|
|
1164
|
+
}), D(), b(), T();
|
|
1165
|
+
}
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
if (C) {
|
|
1169
|
+
const M = f.x - C.startX, L = f.y - C.startY, Y = n.flipH ? -1 : 1, q = n.flipV ? -1 : 1;
|
|
1170
|
+
n = {
|
|
1171
|
+
...n,
|
|
1172
|
+
panX: C.startPanX + Y * M / n.scale,
|
|
1173
|
+
panY: C.startPanY + q * L / n.scale
|
|
1174
|
+
}, D(), b();
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
if (x) {
|
|
1178
|
+
const { displayW: M, displayH: L } = j(), Y = ue(x, f.x, f.y, M, L);
|
|
1179
|
+
n = k(n, Y), D(), b(), T();
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
if (m) {
|
|
1183
|
+
const { displayW: M, displayH: L } = j(), Y = he(
|
|
1184
|
+
m,
|
|
1185
|
+
f.x,
|
|
1186
|
+
f.y,
|
|
1187
|
+
M,
|
|
1188
|
+
L,
|
|
1189
|
+
h,
|
|
1190
|
+
e.minCropSize,
|
|
1191
|
+
{ shiftKey: f.shiftKey, altKey: f.altKey }
|
|
1192
|
+
);
|
|
1193
|
+
n = k(n, Y), D(), b(), T();
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
if (e.variant === "fixed")
|
|
1197
|
+
r.style.cursor = "grab";
|
|
1198
|
+
else {
|
|
1199
|
+
const M = pt(f.x, f.y, v);
|
|
1200
|
+
r.style.cursor = Pt(M);
|
|
1201
|
+
}
|
|
1202
|
+
},
|
|
1203
|
+
onHover: (f) => {
|
|
1204
|
+
if (!l) return;
|
|
1205
|
+
if (e.variant === "fixed") {
|
|
1206
|
+
r.style.cursor = "grab";
|
|
1207
|
+
return;
|
|
1208
|
+
}
|
|
1209
|
+
const v = l.getCanvasCropRect(), M = pt(f.x, f.y, v);
|
|
1210
|
+
r.style.cursor = Pt(M);
|
|
1211
|
+
},
|
|
1212
|
+
onPointerUp: (f, v) => {
|
|
1213
|
+
v.length < 2 && (H = null), v.length === 0 && (x = null, C = null, u = null, m = null, p = !1, z = 0, E = 0, D());
|
|
1214
|
+
},
|
|
1215
|
+
onPinch: (f) => {
|
|
1216
|
+
var Y;
|
|
1217
|
+
H || (H = { initialDistance: f.distance, initialScale: n.scale, initialCenterX: f.centerX, initialCenterY: f.centerY });
|
|
1218
|
+
const v = n.scale * (f.distance / H.initialDistance), M = f.centerX - H.initialCenterX, L = f.centerY - H.initialCenterY;
|
|
1219
|
+
n = nt(n, v, e.minScale, e.maxScale), n = Mt(n, M, L), (Y = a.onScaleSync) == null || Y.call(a, n.scale), D(), b();
|
|
1220
|
+
},
|
|
1221
|
+
onWheel: (f) => {
|
|
1222
|
+
var Z, et;
|
|
1223
|
+
if (!e.wheelZoom) return;
|
|
1224
|
+
f.preventDefault();
|
|
1225
|
+
const v = r.getBoundingClientRect(), M = f.clientX - v.left, L = f.clientY - v.top, Y = v.width / 2, q = v.height / 2, X = pe(f.deltaY, n.scale, {
|
|
1226
|
+
minScale: e.minScale,
|
|
1227
|
+
maxScale: e.maxScale,
|
|
1228
|
+
sensitivity: 1
|
|
1229
|
+
}, M, L, Y, q);
|
|
1230
|
+
n = nt(n, X.scale, e.minScale, e.maxScale), n = Mt(n, X.panDeltaX, X.panDeltaY), (Z = a.onScaleSync) == null || Z.call(a, n.scale), (et = a.onWheelZoomActivity) == null || et.call(a), D(), b();
|
|
1231
|
+
}
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
function j() {
|
|
1235
|
+
return { displayW: o.clientWidth, displayH: o.clientHeight };
|
|
1236
|
+
}
|
|
1237
|
+
function it(f) {
|
|
1238
|
+
var v;
|
|
1239
|
+
c || h !== f && (h = f, e.variant === "fixed" ? n = { ...n, cropRect: { ...R } } : n = dt(
|
|
1240
|
+
n,
|
|
1241
|
+
f,
|
|
1242
|
+
(s == null ? void 0 : s.naturalWidth) ?? 1,
|
|
1243
|
+
(s == null ? void 0 : s.naturalHeight) ?? 1
|
|
1244
|
+
), (v = a.onShapeSync) == null || v.call(a, f), D(), b(), T());
|
|
1245
|
+
}
|
|
1246
|
+
function Dt(f) {
|
|
1247
|
+
c || (n = k(n, f), D(), b(), T());
|
|
1248
|
+
}
|
|
1249
|
+
function wt() {
|
|
1250
|
+
c || (n = Ut(n), D(), yt(i, n, h), b(), T());
|
|
1251
|
+
}
|
|
1252
|
+
function vt() {
|
|
1253
|
+
c || (n = $t(n), D(), yt(i, n, h), b(), T());
|
|
1254
|
+
}
|
|
1255
|
+
function St(f) {
|
|
1256
|
+
var v;
|
|
1257
|
+
c || (n = ht(n, f), (v = a.onRotationSync) == null || v.call(a, f), D(), b());
|
|
1258
|
+
}
|
|
1259
|
+
function rt(f) {
|
|
1260
|
+
var v;
|
|
1261
|
+
c || (n = nt(n, f, e.minScale, e.maxScale), (v = a.onScaleSync) == null || v.call(a, n.scale), D(), b());
|
|
1262
|
+
}
|
|
1263
|
+
function Lt() {
|
|
1264
|
+
var f, v, M;
|
|
1265
|
+
c || (h = e.cropShape, n = xt(
|
|
1266
|
+
e.cropShape,
|
|
1267
|
+
(s == null ? void 0 : s.naturalWidth) ?? 1,
|
|
1268
|
+
(s == null ? void 0 : s.naturalHeight) ?? 1
|
|
1269
|
+
), e.variant === "fixed" ? n = { ...n, cropRect: { ...R } } : e.initialCrop && (n = k(n, e.initialCrop)), e.initialRotation && (n = ht(n, e.initialRotation)), e.initialScale !== void 0 && e.initialScale !== 1 && (n = nt(n, e.initialScale, e.minScale, e.maxScale)), (f = a.onRotationSync) == null || f.call(a, n.rotation), (v = a.onShapeSync) == null || v.call(a, e.cropShape), (M = a.onScaleSync) == null || M.call(a, n.scale), D(), yt(i, n, h), b(), T());
|
|
1270
|
+
}
|
|
1271
|
+
function ft() {
|
|
1272
|
+
if (!s) throw new Error("No image loaded");
|
|
1273
|
+
const { w: f, h: v } = F();
|
|
1274
|
+
return me(
|
|
1275
|
+
s,
|
|
1276
|
+
n,
|
|
1277
|
+
e.maxOutputWidth,
|
|
1278
|
+
e.maxOutputHeight,
|
|
1279
|
+
h,
|
|
1280
|
+
e.borderRadius,
|
|
1281
|
+
// Pan is stored in the renderer's CSS-px container space; pass the
|
|
1282
|
+
// container dims so the exporter can rescale pan into display space.
|
|
1283
|
+
// The height + variant drive the fixed variant's cover-fit export.
|
|
1284
|
+
f,
|
|
1285
|
+
v,
|
|
1286
|
+
e.variant
|
|
1287
|
+
);
|
|
1288
|
+
}
|
|
1289
|
+
async function Et(f, v) {
|
|
1290
|
+
const M = ft();
|
|
1291
|
+
return Se(M, f || e.outputType, v ?? e.outputQuality);
|
|
1292
|
+
}
|
|
1293
|
+
function Yt(f, v) {
|
|
1294
|
+
try {
|
|
1295
|
+
return ft().toDataURL(f || e.outputType, v ?? e.outputQuality);
|
|
1296
|
+
} catch (M) {
|
|
1297
|
+
const L = M instanceof Error ? M : new Error(String(M));
|
|
1298
|
+
throw new Error(`Failed to export data URL: ${L.message}`);
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
function Xt() {
|
|
1302
|
+
if (!s) throw new Error("No image loaded");
|
|
1303
|
+
return ge(n, s.naturalWidth, s.naturalHeight);
|
|
1304
|
+
}
|
|
1305
|
+
function Ft(f) {
|
|
1306
|
+
if (c) return;
|
|
1307
|
+
const v = e.src, M = e.variant;
|
|
1308
|
+
e = Ht({ ...e, ...f }), f.cropShape !== void 0 && it(f.cropShape), f.variant !== void 0 && f.variant !== M && (l == null || l.setFixedFrame(e.variant === "fixed"), e.variant === "fixed" ? n = { ...n, cropRect: { ...R } } : (l == null || l.setScaleBounds(e.minScale, e.maxScale), n = dt(n, h, (s == null ? void 0 : s.naturalWidth) ?? 1, (s == null ? void 0 : s.naturalHeight) ?? 1), n = nt({ ...n, panX: 0, panY: 0 }, e.initialScale ?? 1, e.minScale, e.maxScale)), D(), b(), T()), f.src !== void 0 && f.src !== v && W(f.src).catch(() => {
|
|
1309
|
+
}), (f.showBleedMargin !== void 0 || f.bleedMarginSize !== void 0 || f.bleedMarginColor !== void 0) && (l == null || l.setBleedConfig({
|
|
1310
|
+
show: e.showBleedMargin,
|
|
1311
|
+
size: e.bleedMarginSize,
|
|
1312
|
+
color: e.bleedMarginColor
|
|
1313
|
+
})), f.showGrid !== void 0 && D(), l == null || l.markDirty();
|
|
1314
|
+
}
|
|
1315
|
+
function It() {
|
|
1316
|
+
c || (c = !0, S++, l == null || l.destroy(), d == null || d.destroy(), g == null || g.destroy(), w == null || w.disconnect(), y && (clearTimeout(y), y = null));
|
|
1317
|
+
}
|
|
1318
|
+
return {
|
|
1319
|
+
loadImage: W,
|
|
1320
|
+
getTransformState: _,
|
|
1321
|
+
getCropRect: $,
|
|
1322
|
+
setCropShape: it,
|
|
1323
|
+
setCropRect: Dt,
|
|
1324
|
+
rotateLeft: wt,
|
|
1325
|
+
flipHorizontal: vt,
|
|
1326
|
+
setRotation: St,
|
|
1327
|
+
setScale: rt,
|
|
1328
|
+
reset: Lt,
|
|
1329
|
+
toCanvas: ft,
|
|
1330
|
+
toBlob: Et,
|
|
1331
|
+
toDataURL: Yt,
|
|
1332
|
+
toTransformParams: Xt,
|
|
1333
|
+
update: Ft,
|
|
1334
|
+
destroy: It
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1337
|
+
function Pe(t = {}) {
|
|
1338
|
+
const r = tt(null), i = tt(null), o = tt(null), a = tt(t);
|
|
1339
|
+
a.current = t;
|
|
1340
|
+
const [e, h] = J(() => ({
|
|
1341
|
+
quarterTurns: 0,
|
|
1342
|
+
rotation: 0,
|
|
1343
|
+
flipH: !1,
|
|
1344
|
+
flipV: !1,
|
|
1345
|
+
scale: 1,
|
|
1346
|
+
panX: 0,
|
|
1347
|
+
panY: 0,
|
|
1348
|
+
cropRect: { x: 0, y: 0, width: 1, height: 1 }
|
|
1349
|
+
})), [s, n] = J({ x: 0, y: 0, width: 1, height: 1 }), [l, d] = J(t.cropShape ?? "free"), [g, w] = J(!1), [y, c] = J(null), [p, S] = J(!1);
|
|
1350
|
+
ot(() => {
|
|
1351
|
+
const u = r.current, m = i.current;
|
|
1352
|
+
if (!u || !m) return;
|
|
1353
|
+
const H = a.current, V = Ht(H), E = Re({
|
|
1354
|
+
canvas: u,
|
|
1355
|
+
host: m,
|
|
1356
|
+
layoutContainer: m,
|
|
1357
|
+
config: V,
|
|
1358
|
+
callbacks: {
|
|
1359
|
+
onReady: () => S(!0),
|
|
1360
|
+
onImageLoad: () => {
|
|
1361
|
+
},
|
|
1362
|
+
onError: (O) => c(O.message),
|
|
1363
|
+
onChange: (O) => h(O),
|
|
1364
|
+
onCropChange: (O) => n(O),
|
|
1365
|
+
onShapeSync: (O) => d(O),
|
|
1366
|
+
onLoadingChange: (O, _) => {
|
|
1367
|
+
w(O), c(_);
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
});
|
|
1371
|
+
return o.current = E, H.src && E.loadImage(H.src).catch(() => {
|
|
1372
|
+
}), () => {
|
|
1373
|
+
S(!1), E.destroy(), o.current = null;
|
|
1374
|
+
};
|
|
1375
|
+
}, [t.src]), ot(() => {
|
|
1376
|
+
const u = o.current;
|
|
1377
|
+
if (!u) return;
|
|
1378
|
+
const { src: m, ...H } = t;
|
|
1379
|
+
u.update(H);
|
|
1380
|
+
}, [
|
|
1381
|
+
t.cropShape,
|
|
1382
|
+
t.minScale,
|
|
1383
|
+
t.maxScale,
|
|
1384
|
+
t.minCropSize,
|
|
1385
|
+
t.theme,
|
|
1386
|
+
t.showGrid,
|
|
1387
|
+
t.showBleedMargin,
|
|
1388
|
+
t.bleedMarginSize,
|
|
1389
|
+
t.bleedMarginColor,
|
|
1390
|
+
t.enableAnimations,
|
|
1391
|
+
t.keyboard,
|
|
1392
|
+
t.pinchZoom,
|
|
1393
|
+
t.wheelZoom
|
|
1394
|
+
]);
|
|
1395
|
+
const x = Rt(() => ({
|
|
1396
|
+
loadImage: (u) => o.current ? o.current.loadImage(u) : Promise.resolve(),
|
|
1397
|
+
rotateLeft: () => {
|
|
1398
|
+
var u;
|
|
1399
|
+
return (u = o.current) == null ? void 0 : u.rotateLeft();
|
|
1400
|
+
},
|
|
1401
|
+
flipHorizontal: () => {
|
|
1402
|
+
var u;
|
|
1403
|
+
return (u = o.current) == null ? void 0 : u.flipHorizontal();
|
|
1404
|
+
},
|
|
1405
|
+
setRotation: (u) => {
|
|
1406
|
+
var m;
|
|
1407
|
+
return (m = o.current) == null ? void 0 : m.setRotation(u);
|
|
1408
|
+
},
|
|
1409
|
+
setScale: (u) => {
|
|
1410
|
+
var m;
|
|
1411
|
+
return (m = o.current) == null ? void 0 : m.setScale(u);
|
|
1412
|
+
},
|
|
1413
|
+
setCropShape: (u) => {
|
|
1414
|
+
var m;
|
|
1415
|
+
return (m = o.current) == null ? void 0 : m.setCropShape(u);
|
|
1416
|
+
},
|
|
1417
|
+
setCropRect: (u) => {
|
|
1418
|
+
var m;
|
|
1419
|
+
return (m = o.current) == null ? void 0 : m.setCropRect(u);
|
|
1420
|
+
},
|
|
1421
|
+
reset: () => {
|
|
1422
|
+
var u;
|
|
1423
|
+
return (u = o.current) == null ? void 0 : u.reset();
|
|
1424
|
+
}
|
|
1425
|
+
}), []), C = Rt(() => ({
|
|
1426
|
+
toCanvas: () => {
|
|
1427
|
+
var u;
|
|
1428
|
+
return ((u = o.current) == null ? void 0 : u.toCanvas()) ?? null;
|
|
1429
|
+
},
|
|
1430
|
+
toBlob: (u, m) => o.current ? o.current.toBlob(u, m) : Promise.resolve(null),
|
|
1431
|
+
toDataURL: (u, m) => {
|
|
1432
|
+
var H;
|
|
1433
|
+
return ((H = o.current) == null ? void 0 : H.toDataURL(u, m)) ?? null;
|
|
1434
|
+
},
|
|
1435
|
+
toTransformParams: () => {
|
|
1436
|
+
var u;
|
|
1437
|
+
return ((u = o.current) == null ? void 0 : u.toTransformParams()) ?? null;
|
|
1438
|
+
},
|
|
1439
|
+
getController: () => o.current
|
|
1440
|
+
}), []);
|
|
1441
|
+
return {
|
|
1442
|
+
canvasRef: r,
|
|
1443
|
+
containerRef: i,
|
|
1444
|
+
state: e,
|
|
1445
|
+
cropRect: s,
|
|
1446
|
+
cropShape: l,
|
|
1447
|
+
scale: e.scale,
|
|
1448
|
+
rotation: e.rotation,
|
|
1449
|
+
loading: g,
|
|
1450
|
+
error: y,
|
|
1451
|
+
ready: p,
|
|
1452
|
+
actions: x,
|
|
1453
|
+
api: C
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1456
|
+
export {
|
|
1457
|
+
zt as D,
|
|
1458
|
+
xe as S,
|
|
1459
|
+
I as a,
|
|
1460
|
+
Pe as b,
|
|
1461
|
+
Re as c,
|
|
1462
|
+
gt as g,
|
|
1463
|
+
Ht as m,
|
|
1464
|
+
Kt as p,
|
|
1465
|
+
Te as s,
|
|
1466
|
+
Me as u
|
|
1467
|
+
};
|
|
1468
|
+
//# sourceMappingURL=index-CktjrogS.js.map
|