antd-img-crop 4.25.0 → 4.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/antd-img-crop.cjs.js +21 -41
- package/dist/antd-img-crop.d.ts +5 -5
- package/dist/antd-img-crop.esm.js +21 -41
- package/package.json +27 -27
|
@@ -20,9 +20,14 @@ const ASPECT_STEP = 0.01;
|
|
|
20
20
|
|
|
21
21
|
const EasyCrop = react.forwardRef((props, ref) => {
|
|
22
22
|
const { cropperRef, zoomSlider, rotationSlider, aspectSlider, showReset, resetBtnText, modalImage, aspect: propAspect, minZoom, maxZoom, minAspect, maxAspect, cropShape, showGrid, cropperProps, } = props;
|
|
23
|
+
const [crop, setCrop] = react.useState({ x: 0, y: 0 });
|
|
23
24
|
const [zoom, setZoom] = react.useState(ZOOM_INITIAL);
|
|
24
25
|
const [rotation, setRotation] = react.useState(ROTATION_INITIAL);
|
|
25
26
|
const [aspect, setAspect] = react.useState(propAspect);
|
|
27
|
+
const cropPixelsRef = react.useRef({ width: 0, height: 0, x: 0, y: 0 });
|
|
28
|
+
const onCropComplete = react.useCallback((_, croppedAreaPixels) => {
|
|
29
|
+
cropPixelsRef.current = croppedAreaPixels;
|
|
30
|
+
}, []);
|
|
26
31
|
const prevPropAspect = react.useRef(propAspect);
|
|
27
32
|
if (prevPropAspect.current !== propAspect) {
|
|
28
33
|
prevPropAspect.current = propAspect;
|
|
@@ -36,11 +41,6 @@ const EasyCrop = react.forwardRef((props, ref) => {
|
|
|
36
41
|
setRotation(ROTATION_INITIAL);
|
|
37
42
|
setAspect(propAspect);
|
|
38
43
|
};
|
|
39
|
-
const [crop, onCropChange] = react.useState({ x: 0, y: 0 });
|
|
40
|
-
const cropPixelsRef = react.useRef({ width: 0, height: 0, x: 0, y: 0 });
|
|
41
|
-
const onCropComplete = react.useCallback((_, croppedAreaPixels) => {
|
|
42
|
-
cropPixelsRef.current = croppedAreaPixels;
|
|
43
|
-
}, []);
|
|
44
44
|
react.useImperativeHandle(ref, () => ({
|
|
45
45
|
rotation,
|
|
46
46
|
cropPixelsRef,
|
|
@@ -49,46 +49,20 @@ const EasyCrop = react.forwardRef((props, ref) => {
|
|
|
49
49
|
const wrapperClass = '[display:flex] [align-items:center] [width:60%] [margin-inline:auto]';
|
|
50
50
|
const buttonClass = '[display:flex] [align-items:center] [justify-content:center] [height:32px] [width:32px] [background:transparent] [border:0] [font-family:inherit] [font-size:18px] [cursor:pointer] disabled:[opacity:20%] disabled:[cursor:default]';
|
|
51
51
|
const sliderClass = '[flex:1]';
|
|
52
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Cropper, Object.assign({}, cropperProps, { ref: cropperRef, image: modalImage, crop: crop,
|
|
53
|
-
//
|
|
54
|
-
zoom: zoom, rotation: rotation, aspect: aspect, minZoom: minZoom, maxZoom: maxZoom, zoomWithScroll: zoomSlider,
|
|
55
|
-
//
|
|
56
|
-
cropShape: cropShape, showGrid: showGrid, onCropChange: onCropChange, onZoomChange: setZoom, onRotationChange: setRotation, onCropComplete: onCropComplete, classes: {
|
|
52
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Cropper, Object.assign({}, cropperProps, { ref: cropperRef, image: modalImage, crop: crop, zoom: zoom, rotation: rotation, aspect: aspect, minZoom: minZoom, maxZoom: maxZoom, zoomWithScroll: zoomSlider, cropShape: cropShape, showGrid: showGrid, onCropChange: setCrop, onZoomChange: setZoom, onRotationChange: setRotation, onCropComplete: onCropComplete, classes: {
|
|
57
53
|
containerClassName: `${PREFIX}-container ![position:relative] [width:100%] [height:40vh] [&~section:first-of-type]:[margin-top:16px] [&~section:last-of-type]:[margin-bottom:16px]`,
|
|
58
54
|
mediaClassName: `${PREFIX}-media`,
|
|
59
55
|
} })), zoomSlider && (jsxRuntime.jsxs("section", { className: `${PREFIX}-control ${PREFIX}-control-zoom ${wrapperClass}`, children: [jsxRuntime.jsx("button", { className: buttonClass, onClick: () => setZoom(+(zoom - ZOOM_STEP).toFixed(1)), disabled: zoom - ZOOM_STEP < minZoom, children: "\uFF0D" }), jsxRuntime.jsx(AntSlider, { className: sliderClass, min: minZoom, max: maxZoom, step: ZOOM_STEP, value: zoom, onChange: setZoom }), jsxRuntime.jsx("button", { className: buttonClass, onClick: () => setZoom(+(zoom + ZOOM_STEP).toFixed(1)), disabled: zoom + ZOOM_STEP > maxZoom, children: "\uFF0B" })] })), rotationSlider && (jsxRuntime.jsxs("section", { className: `${PREFIX}-control ${PREFIX}-control-rotation ${wrapperClass}`, children: [jsxRuntime.jsx("button", { className: `${buttonClass} [font-size:16px]`, onClick: () => setRotation(rotation - ROTATION_STEP), disabled: rotation === ROTATION_MIN, children: "\u21BA" }), jsxRuntime.jsx(AntSlider, { className: sliderClass, min: ROTATION_MIN, max: ROTATION_MAX, step: ROTATION_STEP, value: rotation, onChange: setRotation }), jsxRuntime.jsx("button", { className: `${buttonClass} [font-size:16px]`, onClick: () => setRotation(rotation + ROTATION_STEP), disabled: rotation === ROTATION_MAX, children: "\u21BB" })] })), aspectSlider && (jsxRuntime.jsxs("section", { className: `${PREFIX}-control ${PREFIX}-control-aspect ${wrapperClass}`, children: [jsxRuntime.jsx("button", { className: buttonClass, onClick: () => setAspect(+(aspect - ASPECT_STEP).toFixed(2)), disabled: aspect - ASPECT_STEP < minAspect, children: "\u2195" }), jsxRuntime.jsx(AntSlider, { className: sliderClass, min: minAspect, max: maxAspect, step: ASPECT_STEP, value: aspect, onChange: setAspect }), jsxRuntime.jsx("button", { className: buttonClass, onClick: () => setAspect(+(aspect + ASPECT_STEP).toFixed(2)), disabled: aspect + ASPECT_STEP > maxAspect, children: "\u2194" })] })), showReset && (zoomSlider || rotationSlider || aspectSlider) && (jsxRuntime.jsx(AntButton, { className: "[position:absolute] [bottom:20px]", style: isResetActive ? {} : { opacity: 0.3, pointerEvents: 'none' }, onClick: onReset, children: resetBtnText }))] }));
|
|
60
56
|
});
|
|
61
57
|
var EasyCrop$1 = react.memo(EasyCrop);
|
|
62
58
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
var style = document.createElement('style');
|
|
71
|
-
style.type = 'text/css';
|
|
72
|
-
|
|
73
|
-
if (insertAt === 'top') {
|
|
74
|
-
if (head.firstChild) {
|
|
75
|
-
head.insertBefore(style, head.firstChild);
|
|
76
|
-
} else {
|
|
77
|
-
head.appendChild(style);
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
head.appendChild(style);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (style.styleSheet) {
|
|
84
|
-
style.styleSheet.cssText = css;
|
|
85
|
-
} else {
|
|
86
|
-
style.appendChild(document.createTextNode(css));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
var css_248z = "/*! tailwindcss v4.1.4 | MIT License | https://tailwindcss.com */.visible{visibility:visible}.\\!\\[position\\:relative\\]{position:relative!important}.\\[position\\:absolute\\]{position:absolute}.\\[bottom\\:20px\\]{bottom:20px}.container{width:100%}.\\[margin-inline\\:auto\\]{margin-inline:auto}.\\[display\\:flex\\]{display:flex}.grid{display:grid}.\\[height\\:32px\\]{height:32px}.\\[height\\:40vh\\]{height:40vh}.\\[width\\:32px\\]{width:32px}.\\[width\\:60\\%\\]{width:60%}.\\[width\\:100\\%\\]{width:100%}.\\[flex\\:1\\]{flex:1}.\\[cursor\\:pointer\\]{cursor:pointer}.\\[align-items\\:center\\]{align-items:center}.\\[justify-content\\:center\\]{justify-content:center}.\\[font-family\\:inherit\\]{font-family:inherit}.\\[font-size\\:16px\\]{font-size:16px}.\\[font-size\\:18px\\]{font-size:18px}.\\[background\\:transparent\\]{background:transparent}.\\[border\\:0\\]{border:0}.disabled\\:\\[cursor\\:default\\]{&:disabled{cursor:default}}.disabled\\:\\[opacity\\:20\\%\\]{&:disabled{opacity:20%}}.\\[\\&\\~section\\:first-of-type\\]\\:\\[margin-top\\:16px\\]{&~section:first-of-type{margin-top:16px}}.\\[\\&\\~section\\:last-of-type\\]\\:\\[margin-bottom\\:16px\\]{&~section:last-of-type{margin-bottom:16px}}";
|
|
91
|
-
styleInject(css_248z,{"insertAt":"top"});
|
|
59
|
+
var css_248z = "/*! tailwindcss v4.1.14 | MIT License | https://tailwindcss.com */.visible{visibility:visible}.\\!\\[position\\:relative\\]{position:relative!important}.\\[position\\:absolute\\]{position:absolute}.\\[bottom\\:20px\\]{bottom:20px}.container{width:100%}.\\[margin-inline\\:auto\\]{margin-inline:auto}.\\[display\\:flex\\]{display:flex}.grid{display:grid}.\\[height\\:32px\\]{height:32px}.\\[height\\:40vh\\]{height:40vh}.\\[width\\:32px\\]{width:32px}.\\[width\\:60\\%\\]{width:60%}.\\[width\\:100\\%\\]{width:100%}.\\[flex\\:1\\]{flex:1}.\\[cursor\\:pointer\\]{cursor:pointer}.\\[align-items\\:center\\]{align-items:center}.\\[justify-content\\:center\\]{justify-content:center}.\\[font-family\\:inherit\\]{font-family:inherit}.\\[font-size\\:16px\\]{font-size:16px}.\\[font-size\\:18px\\]{font-size:18px}.\\[background\\:transparent\\]{background:transparent}.\\[border\\:0\\]{border:0}.disabled\\:\\[cursor\\:default\\]{&:disabled{cursor:default}}.disabled\\:\\[opacity\\:20\\%\\]{&:disabled{opacity:20%}}.\\[\\&\\~section\\:first-of-type\\]\\:\\[margin-top\\:16px\\]{&~section:first-of-type{margin-top:16px}}.\\[\\&\\~section\\:last-of-type\\]\\:\\[margin-bottom\\:16px\\]{&~section:last-of-type{margin-bottom:16px}}";
|
|
60
|
+
const style = document.createElement('style');
|
|
61
|
+
const meta = document.querySelector('meta[name="csp-nonce"]');
|
|
62
|
+
const nonce = meta && meta.content;
|
|
63
|
+
nonce && style.setAttribute('nonce', nonce);
|
|
64
|
+
style.textContent = css_248z;
|
|
65
|
+
document.head.appendChild(style);
|
|
92
66
|
|
|
93
67
|
const ImgCrop = react.forwardRef((props, cropperRef) => {
|
|
94
68
|
const { quality = 0.4, fillColor = 'white', zoomSlider = true, rotationSlider = false, aspectSlider = false, showReset = false, resetText, aspect = 1, minZoom = 1, maxZoom = 3, minAspect = 0.5, maxAspect = 2, cropShape = 'rect', showGrid = false, cropperProps, modalClassName, modalTitle, modalWidth, modalOk, modalCancel, onModalOk, onModalCancel, modalProps, beforeCrop, children, } = props;
|
|
@@ -148,6 +122,7 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
|
|
|
148
122
|
/**
|
|
149
123
|
* upload
|
|
150
124
|
*/
|
|
125
|
+
const [modalOpen, setModalOpen] = react.useState(false);
|
|
151
126
|
const [modalImage, setModalImage] = react.useState('');
|
|
152
127
|
const onCancel = react.useRef(undefined);
|
|
153
128
|
const onOk = react.useRef(undefined);
|
|
@@ -194,13 +169,17 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
|
|
|
194
169
|
const reader = new FileReader();
|
|
195
170
|
reader.addEventListener('load', () => {
|
|
196
171
|
if (typeof reader.result === 'string') {
|
|
197
|
-
|
|
172
|
+
setModalOpen(true);
|
|
173
|
+
setTimeout(() => {
|
|
174
|
+
setModalImage(reader.result);
|
|
175
|
+
}, 10);
|
|
198
176
|
}
|
|
199
177
|
});
|
|
200
178
|
reader.readAsDataURL(processedFile);
|
|
201
179
|
// on modal cancel
|
|
202
180
|
onCancel.current = () => {
|
|
203
181
|
var _a, _b;
|
|
182
|
+
setModalOpen(false);
|
|
204
183
|
setModalImage('');
|
|
205
184
|
easyCropRef.current.onReset();
|
|
206
185
|
let hasResolveCalled = false;
|
|
@@ -214,6 +193,7 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
|
|
|
214
193
|
};
|
|
215
194
|
// on modal confirm
|
|
216
195
|
onOk.current = (event) => tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
196
|
+
setModalOpen(false);
|
|
217
197
|
setModalImage('');
|
|
218
198
|
easyCropRef.current.onReset();
|
|
219
199
|
const canvas = getCropCanvas(event.target);
|
|
@@ -263,7 +243,7 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
|
|
|
263
243
|
const isCN = lang === 'zh-CN';
|
|
264
244
|
const title = modalTitle || (isCN ? '编辑图片' : 'Edit image');
|
|
265
245
|
const resetBtnText = resetText || (isCN ? '重置' : 'Reset');
|
|
266
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [getNewUpload(children),
|
|
246
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [getNewUpload(children), jsxRuntime.jsx(AntModal, Object.assign({}, modalProps, modalBaseProps, { open: modalOpen, title: title, onCancel: onCancel.current, onOk: onOk.current, wrapClassName: wrapClassName, maskClosable: false, destroyOnHidden: true, children: jsxRuntime.jsx(EasyCrop$1, { ref: easyCropRef, cropperRef: cropperRef, zoomSlider: zoomSlider, rotationSlider: rotationSlider, aspectSlider: aspectSlider, showReset: showReset, resetBtnText: resetBtnText, modalImage: modalImage, aspect: aspect, minZoom: minZoom, maxZoom: maxZoom, minAspect: minAspect, maxAspect: maxAspect, cropShape: cropShape, showGrid: showGrid, cropperProps: cropperProps }) }))] }));
|
|
267
247
|
});
|
|
268
248
|
|
|
269
249
|
module.exports = ImgCrop;
|
package/dist/antd-img-crop.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { JSX } from 'react';
|
|
3
|
-
import Cropper, { CropperProps } from 'react-easy-crop';
|
|
4
3
|
import { UploadProps, ModalProps } from 'antd';
|
|
4
|
+
import { CropperProps } from 'react-easy-crop';
|
|
5
5
|
|
|
6
6
|
type BeforeUpload = Exclude<UploadProps['beforeUpload'], undefined>;
|
|
7
7
|
type BeforeUploadReturnType = ReturnType<BeforeUpload>;
|
|
8
|
-
type ImgCropProps = {
|
|
8
|
+
type ImgCropProps$1 = {
|
|
9
9
|
quality?: number;
|
|
10
10
|
fillColor?: string;
|
|
11
11
|
zoomSlider?: boolean;
|
|
@@ -28,12 +28,12 @@ type ImgCropProps = {
|
|
|
28
28
|
modalCancel?: string;
|
|
29
29
|
onModalOk?: (value: BeforeUploadReturnType) => void;
|
|
30
30
|
onModalCancel?: (resolve: (value: BeforeUploadReturnType) => void) => void;
|
|
31
|
-
modalProps?: Omit<ModalProps, 'className' | 'title' | 'width' | 'okText' | 'cancelText' | 'onOk' | 'onCancel' | 'open' | 'visible' | 'wrapClassName' | 'maskClosable' | '
|
|
31
|
+
modalProps?: Omit<ModalProps, 'className' | 'title' | 'width' | 'okText' | 'cancelText' | 'onOk' | 'onCancel' | 'open' | 'visible' | 'wrapClassName' | 'maskClosable' | 'destroyOnHidden'>;
|
|
32
32
|
beforeCrop?: BeforeUpload;
|
|
33
33
|
children: JSX.Element;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
declare const ImgCrop: react.ForwardRefExoticComponent<ImgCropProps & react.RefAttributes<
|
|
36
|
+
declare const ImgCrop: react.ForwardRefExoticComponent<Omit<ImgCropProps, "ref"> & react.RefAttributes<CropperRef>>;
|
|
37
37
|
|
|
38
38
|
export { ImgCrop as default };
|
|
39
|
-
export type { ImgCropProps };
|
|
39
|
+
export type { ImgCropProps$1 as ImgCropProps };
|
|
@@ -18,9 +18,14 @@ const ASPECT_STEP = 0.01;
|
|
|
18
18
|
|
|
19
19
|
const EasyCrop = forwardRef((props, ref) => {
|
|
20
20
|
const { cropperRef, zoomSlider, rotationSlider, aspectSlider, showReset, resetBtnText, modalImage, aspect: propAspect, minZoom, maxZoom, minAspect, maxAspect, cropShape, showGrid, cropperProps, } = props;
|
|
21
|
+
const [crop, setCrop] = useState({ x: 0, y: 0 });
|
|
21
22
|
const [zoom, setZoom] = useState(ZOOM_INITIAL);
|
|
22
23
|
const [rotation, setRotation] = useState(ROTATION_INITIAL);
|
|
23
24
|
const [aspect, setAspect] = useState(propAspect);
|
|
25
|
+
const cropPixelsRef = useRef({ width: 0, height: 0, x: 0, y: 0 });
|
|
26
|
+
const onCropComplete = useCallback((_, croppedAreaPixels) => {
|
|
27
|
+
cropPixelsRef.current = croppedAreaPixels;
|
|
28
|
+
}, []);
|
|
24
29
|
const prevPropAspect = useRef(propAspect);
|
|
25
30
|
if (prevPropAspect.current !== propAspect) {
|
|
26
31
|
prevPropAspect.current = propAspect;
|
|
@@ -34,11 +39,6 @@ const EasyCrop = forwardRef((props, ref) => {
|
|
|
34
39
|
setRotation(ROTATION_INITIAL);
|
|
35
40
|
setAspect(propAspect);
|
|
36
41
|
};
|
|
37
|
-
const [crop, onCropChange] = useState({ x: 0, y: 0 });
|
|
38
|
-
const cropPixelsRef = useRef({ width: 0, height: 0, x: 0, y: 0 });
|
|
39
|
-
const onCropComplete = useCallback((_, croppedAreaPixels) => {
|
|
40
|
-
cropPixelsRef.current = croppedAreaPixels;
|
|
41
|
-
}, []);
|
|
42
42
|
useImperativeHandle(ref, () => ({
|
|
43
43
|
rotation,
|
|
44
44
|
cropPixelsRef,
|
|
@@ -47,46 +47,20 @@ const EasyCrop = forwardRef((props, ref) => {
|
|
|
47
47
|
const wrapperClass = '[display:flex] [align-items:center] [width:60%] [margin-inline:auto]';
|
|
48
48
|
const buttonClass = '[display:flex] [align-items:center] [justify-content:center] [height:32px] [width:32px] [background:transparent] [border:0] [font-family:inherit] [font-size:18px] [cursor:pointer] disabled:[opacity:20%] disabled:[cursor:default]';
|
|
49
49
|
const sliderClass = '[flex:1]';
|
|
50
|
-
return (jsxs(Fragment, { children: [jsx(Cropper, Object.assign({}, cropperProps, { ref: cropperRef, image: modalImage, crop: crop,
|
|
51
|
-
//
|
|
52
|
-
zoom: zoom, rotation: rotation, aspect: aspect, minZoom: minZoom, maxZoom: maxZoom, zoomWithScroll: zoomSlider,
|
|
53
|
-
//
|
|
54
|
-
cropShape: cropShape, showGrid: showGrid, onCropChange: onCropChange, onZoomChange: setZoom, onRotationChange: setRotation, onCropComplete: onCropComplete, classes: {
|
|
50
|
+
return (jsxs(Fragment, { children: [jsx(Cropper, Object.assign({}, cropperProps, { ref: cropperRef, image: modalImage, crop: crop, zoom: zoom, rotation: rotation, aspect: aspect, minZoom: minZoom, maxZoom: maxZoom, zoomWithScroll: zoomSlider, cropShape: cropShape, showGrid: showGrid, onCropChange: setCrop, onZoomChange: setZoom, onRotationChange: setRotation, onCropComplete: onCropComplete, classes: {
|
|
55
51
|
containerClassName: `${PREFIX}-container ![position:relative] [width:100%] [height:40vh] [&~section:first-of-type]:[margin-top:16px] [&~section:last-of-type]:[margin-bottom:16px]`,
|
|
56
52
|
mediaClassName: `${PREFIX}-media`,
|
|
57
53
|
} })), zoomSlider && (jsxs("section", { className: `${PREFIX}-control ${PREFIX}-control-zoom ${wrapperClass}`, children: [jsx("button", { className: buttonClass, onClick: () => setZoom(+(zoom - ZOOM_STEP).toFixed(1)), disabled: zoom - ZOOM_STEP < minZoom, children: "\uFF0D" }), jsx(AntSlider, { className: sliderClass, min: minZoom, max: maxZoom, step: ZOOM_STEP, value: zoom, onChange: setZoom }), jsx("button", { className: buttonClass, onClick: () => setZoom(+(zoom + ZOOM_STEP).toFixed(1)), disabled: zoom + ZOOM_STEP > maxZoom, children: "\uFF0B" })] })), rotationSlider && (jsxs("section", { className: `${PREFIX}-control ${PREFIX}-control-rotation ${wrapperClass}`, children: [jsx("button", { className: `${buttonClass} [font-size:16px]`, onClick: () => setRotation(rotation - ROTATION_STEP), disabled: rotation === ROTATION_MIN, children: "\u21BA" }), jsx(AntSlider, { className: sliderClass, min: ROTATION_MIN, max: ROTATION_MAX, step: ROTATION_STEP, value: rotation, onChange: setRotation }), jsx("button", { className: `${buttonClass} [font-size:16px]`, onClick: () => setRotation(rotation + ROTATION_STEP), disabled: rotation === ROTATION_MAX, children: "\u21BB" })] })), aspectSlider && (jsxs("section", { className: `${PREFIX}-control ${PREFIX}-control-aspect ${wrapperClass}`, children: [jsx("button", { className: buttonClass, onClick: () => setAspect(+(aspect - ASPECT_STEP).toFixed(2)), disabled: aspect - ASPECT_STEP < minAspect, children: "\u2195" }), jsx(AntSlider, { className: sliderClass, min: minAspect, max: maxAspect, step: ASPECT_STEP, value: aspect, onChange: setAspect }), jsx("button", { className: buttonClass, onClick: () => setAspect(+(aspect + ASPECT_STEP).toFixed(2)), disabled: aspect + ASPECT_STEP > maxAspect, children: "\u2194" })] })), showReset && (zoomSlider || rotationSlider || aspectSlider) && (jsx(AntButton, { className: "[position:absolute] [bottom:20px]", style: isResetActive ? {} : { opacity: 0.3, pointerEvents: 'none' }, onClick: onReset, children: resetBtnText }))] }));
|
|
58
54
|
});
|
|
59
55
|
var EasyCrop$1 = memo(EasyCrop);
|
|
60
56
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
var style = document.createElement('style');
|
|
69
|
-
style.type = 'text/css';
|
|
70
|
-
|
|
71
|
-
if (insertAt === 'top') {
|
|
72
|
-
if (head.firstChild) {
|
|
73
|
-
head.insertBefore(style, head.firstChild);
|
|
74
|
-
} else {
|
|
75
|
-
head.appendChild(style);
|
|
76
|
-
}
|
|
77
|
-
} else {
|
|
78
|
-
head.appendChild(style);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (style.styleSheet) {
|
|
82
|
-
style.styleSheet.cssText = css;
|
|
83
|
-
} else {
|
|
84
|
-
style.appendChild(document.createTextNode(css));
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
var css_248z = "/*! tailwindcss v4.1.4 | MIT License | https://tailwindcss.com */.visible{visibility:visible}.\\!\\[position\\:relative\\]{position:relative!important}.\\[position\\:absolute\\]{position:absolute}.\\[bottom\\:20px\\]{bottom:20px}.container{width:100%}.\\[margin-inline\\:auto\\]{margin-inline:auto}.\\[display\\:flex\\]{display:flex}.grid{display:grid}.\\[height\\:32px\\]{height:32px}.\\[height\\:40vh\\]{height:40vh}.\\[width\\:32px\\]{width:32px}.\\[width\\:60\\%\\]{width:60%}.\\[width\\:100\\%\\]{width:100%}.\\[flex\\:1\\]{flex:1}.\\[cursor\\:pointer\\]{cursor:pointer}.\\[align-items\\:center\\]{align-items:center}.\\[justify-content\\:center\\]{justify-content:center}.\\[font-family\\:inherit\\]{font-family:inherit}.\\[font-size\\:16px\\]{font-size:16px}.\\[font-size\\:18px\\]{font-size:18px}.\\[background\\:transparent\\]{background:transparent}.\\[border\\:0\\]{border:0}.disabled\\:\\[cursor\\:default\\]{&:disabled{cursor:default}}.disabled\\:\\[opacity\\:20\\%\\]{&:disabled{opacity:20%}}.\\[\\&\\~section\\:first-of-type\\]\\:\\[margin-top\\:16px\\]{&~section:first-of-type{margin-top:16px}}.\\[\\&\\~section\\:last-of-type\\]\\:\\[margin-bottom\\:16px\\]{&~section:last-of-type{margin-bottom:16px}}";
|
|
89
|
-
styleInject(css_248z,{"insertAt":"top"});
|
|
57
|
+
var css_248z = "/*! tailwindcss v4.1.14 | MIT License | https://tailwindcss.com */.visible{visibility:visible}.\\!\\[position\\:relative\\]{position:relative!important}.\\[position\\:absolute\\]{position:absolute}.\\[bottom\\:20px\\]{bottom:20px}.container{width:100%}.\\[margin-inline\\:auto\\]{margin-inline:auto}.\\[display\\:flex\\]{display:flex}.grid{display:grid}.\\[height\\:32px\\]{height:32px}.\\[height\\:40vh\\]{height:40vh}.\\[width\\:32px\\]{width:32px}.\\[width\\:60\\%\\]{width:60%}.\\[width\\:100\\%\\]{width:100%}.\\[flex\\:1\\]{flex:1}.\\[cursor\\:pointer\\]{cursor:pointer}.\\[align-items\\:center\\]{align-items:center}.\\[justify-content\\:center\\]{justify-content:center}.\\[font-family\\:inherit\\]{font-family:inherit}.\\[font-size\\:16px\\]{font-size:16px}.\\[font-size\\:18px\\]{font-size:18px}.\\[background\\:transparent\\]{background:transparent}.\\[border\\:0\\]{border:0}.disabled\\:\\[cursor\\:default\\]{&:disabled{cursor:default}}.disabled\\:\\[opacity\\:20\\%\\]{&:disabled{opacity:20%}}.\\[\\&\\~section\\:first-of-type\\]\\:\\[margin-top\\:16px\\]{&~section:first-of-type{margin-top:16px}}.\\[\\&\\~section\\:last-of-type\\]\\:\\[margin-bottom\\:16px\\]{&~section:last-of-type{margin-bottom:16px}}";
|
|
58
|
+
const style = document.createElement('style');
|
|
59
|
+
const meta = document.querySelector('meta[name="csp-nonce"]');
|
|
60
|
+
const nonce = meta && meta.content;
|
|
61
|
+
nonce && style.setAttribute('nonce', nonce);
|
|
62
|
+
style.textContent = css_248z;
|
|
63
|
+
document.head.appendChild(style);
|
|
90
64
|
|
|
91
65
|
const ImgCrop = forwardRef((props, cropperRef) => {
|
|
92
66
|
const { quality = 0.4, fillColor = 'white', zoomSlider = true, rotationSlider = false, aspectSlider = false, showReset = false, resetText, aspect = 1, minZoom = 1, maxZoom = 3, minAspect = 0.5, maxAspect = 2, cropShape = 'rect', showGrid = false, cropperProps, modalClassName, modalTitle, modalWidth, modalOk, modalCancel, onModalOk, onModalCancel, modalProps, beforeCrop, children, } = props;
|
|
@@ -146,6 +120,7 @@ const ImgCrop = forwardRef((props, cropperRef) => {
|
|
|
146
120
|
/**
|
|
147
121
|
* upload
|
|
148
122
|
*/
|
|
123
|
+
const [modalOpen, setModalOpen] = useState(false);
|
|
149
124
|
const [modalImage, setModalImage] = useState('');
|
|
150
125
|
const onCancel = useRef(undefined);
|
|
151
126
|
const onOk = useRef(undefined);
|
|
@@ -192,13 +167,17 @@ const ImgCrop = forwardRef((props, cropperRef) => {
|
|
|
192
167
|
const reader = new FileReader();
|
|
193
168
|
reader.addEventListener('load', () => {
|
|
194
169
|
if (typeof reader.result === 'string') {
|
|
195
|
-
|
|
170
|
+
setModalOpen(true);
|
|
171
|
+
setTimeout(() => {
|
|
172
|
+
setModalImage(reader.result);
|
|
173
|
+
}, 10);
|
|
196
174
|
}
|
|
197
175
|
});
|
|
198
176
|
reader.readAsDataURL(processedFile);
|
|
199
177
|
// on modal cancel
|
|
200
178
|
onCancel.current = () => {
|
|
201
179
|
var _a, _b;
|
|
180
|
+
setModalOpen(false);
|
|
202
181
|
setModalImage('');
|
|
203
182
|
easyCropRef.current.onReset();
|
|
204
183
|
let hasResolveCalled = false;
|
|
@@ -212,6 +191,7 @@ const ImgCrop = forwardRef((props, cropperRef) => {
|
|
|
212
191
|
};
|
|
213
192
|
// on modal confirm
|
|
214
193
|
onOk.current = (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
194
|
+
setModalOpen(false);
|
|
215
195
|
setModalImage('');
|
|
216
196
|
easyCropRef.current.onReset();
|
|
217
197
|
const canvas = getCropCanvas(event.target);
|
|
@@ -261,7 +241,7 @@ const ImgCrop = forwardRef((props, cropperRef) => {
|
|
|
261
241
|
const isCN = lang === 'zh-CN';
|
|
262
242
|
const title = modalTitle || (isCN ? '编辑图片' : 'Edit image');
|
|
263
243
|
const resetBtnText = resetText || (isCN ? '重置' : 'Reset');
|
|
264
|
-
return (jsxs(Fragment, { children: [getNewUpload(children),
|
|
244
|
+
return (jsxs(Fragment, { children: [getNewUpload(children), jsx(AntModal, Object.assign({}, modalProps, modalBaseProps, { open: modalOpen, title: title, onCancel: onCancel.current, onOk: onOk.current, wrapClassName: wrapClassName, maskClosable: false, destroyOnHidden: true, children: jsx(EasyCrop$1, { ref: easyCropRef, cropperRef: cropperRef, zoomSlider: zoomSlider, rotationSlider: rotationSlider, aspectSlider: aspectSlider, showReset: showReset, resetBtnText: resetBtnText, modalImage: modalImage, aspect: aspect, minZoom: minZoom, maxZoom: maxZoom, minAspect: minAspect, maxAspect: maxAspect, cropShape: cropShape, showGrid: showGrid, cropperProps: cropperProps }) }))] }));
|
|
265
245
|
});
|
|
266
246
|
|
|
267
247
|
export { ImgCrop as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "antd-img-crop",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.26.0",
|
|
4
4
|
"description": "An image cropper for Ant Design Upload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -31,42 +31,42 @@
|
|
|
31
31
|
"react-dom": ">=16.8.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"react-easy-crop": "^5.
|
|
34
|
+
"react-easy-crop": "^5.5.3",
|
|
35
35
|
"tslib": "^2.8.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@eslint/compat": "^1.
|
|
38
|
+
"@eslint/compat": "^1.4.0",
|
|
39
39
|
"@eslint/eslintrc": "^3.3.1",
|
|
40
|
-
"@eslint/js": "^9.
|
|
40
|
+
"@eslint/js": "^9.37.0",
|
|
41
41
|
"@rollup/plugin-replace": "^6.0.2",
|
|
42
|
-
"@rollup/plugin-typescript": "^12.1.
|
|
43
|
-
"@tailwindcss/postcss": "^4.1.
|
|
44
|
-
"@types/node": "^
|
|
45
|
-
"@types/react": "19.
|
|
46
|
-
"@types/react-dom": "19.1
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
48
|
-
"@vitejs/plugin-react": "^
|
|
49
|
-
"antd": "^5.
|
|
42
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
43
|
+
"@tailwindcss/postcss": "^4.1.14",
|
|
44
|
+
"@types/node": "^24.7.1",
|
|
45
|
+
"@types/react": "19.2.2",
|
|
46
|
+
"@types/react-dom": "19.2.1",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^8.46.0",
|
|
48
|
+
"@vitejs/plugin-react": "^5.0.4",
|
|
49
|
+
"antd": "^5.27.4",
|
|
50
50
|
"autoprefixer": "^10.4.21",
|
|
51
|
-
"eslint": "^9.
|
|
52
|
-
"eslint-config-prettier": "^10.1.
|
|
51
|
+
"eslint": "^9.37.0",
|
|
52
|
+
"eslint-config-prettier": "^10.1.8",
|
|
53
53
|
"eslint-config-react-app": "^7.0.1",
|
|
54
54
|
"eslint-plugin-flowtype": "^8.0.3",
|
|
55
|
-
"eslint-plugin-import": "^2.
|
|
55
|
+
"eslint-plugin-import": "^2.32.0",
|
|
56
56
|
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
57
57
|
"eslint-plugin-react": "^7.37.5",
|
|
58
|
-
"eslint-plugin-react-hooks": "^
|
|
59
|
-
"postcss": "^8.5.
|
|
60
|
-
"prettier": "^3.
|
|
61
|
-
"prettier-plugin-organize-imports": "^4.
|
|
62
|
-
"prettier-plugin-tailwindcss": "^0.6.
|
|
63
|
-
"react": "19.
|
|
64
|
-
"react-dom": "19.
|
|
65
|
-
"rollup": "4.
|
|
66
|
-
"rollup-plugin-dts": "^6.2.
|
|
58
|
+
"eslint-plugin-react-hooks": "^7.0.0",
|
|
59
|
+
"postcss": "^8.5.6",
|
|
60
|
+
"prettier": "^3.6.2",
|
|
61
|
+
"prettier-plugin-organize-imports": "^4.3.0",
|
|
62
|
+
"prettier-plugin-tailwindcss": "^0.6.14",
|
|
63
|
+
"react": "19.2.0",
|
|
64
|
+
"react-dom": "19.2.0",
|
|
65
|
+
"rollup": "4.52.4",
|
|
66
|
+
"rollup-plugin-dts": "^6.2.3",
|
|
67
67
|
"rollup-plugin-postcss": "^4.0.2",
|
|
68
|
-
"tailwindcss": "^4.1.
|
|
69
|
-
"typescript": "^5.
|
|
70
|
-
"vite": "^
|
|
68
|
+
"tailwindcss": "^4.1.14",
|
|
69
|
+
"typescript": "^5.9.3",
|
|
70
|
+
"vite": "^7.1.9"
|
|
71
71
|
}
|
|
72
72
|
}
|