antd-img-crop 4.23.0 → 4.25.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/README.md +8 -6
- package/README.zh-CN.md +8 -6
- package/dist/antd-img-crop.cjs.js +15 -12
- package/dist/antd-img-crop.d.ts +7 -3
- package/dist/antd-img-crop.esm.js +15 -12
- package/package.json +35 -26
package/README.md
CHANGED
|
@@ -50,14 +50,16 @@ const Demo = () => (
|
|
|
50
50
|
| -------------- | ---------- | -------------- | -------------------------------------------------------------------------------- |
|
|
51
51
|
| quality | `number` | `0.4` | Cropped image quality, `0` to `1` |
|
|
52
52
|
| fillColor | `string` | `'white'` | Fill color for cropped image |
|
|
53
|
-
| zoomSlider | `boolean` | `true` | Enable zoom
|
|
54
|
-
| rotationSlider | `boolean` | `false` | Enable rotation
|
|
55
|
-
| aspectSlider | `boolean` | `false` | Enable aspect
|
|
56
|
-
| showReset | `boolean` | `false` | Show reset button to reset zoom rotation aspect
|
|
53
|
+
| zoomSlider | `boolean` | `true` | Enable zoom |
|
|
54
|
+
| rotationSlider | `boolean` | `false` | Enable rotation |
|
|
55
|
+
| aspectSlider | `boolean` | `false` | Enable aspect |
|
|
56
|
+
| showReset | `boolean` | `false` | Show reset button to reset zoom & rotation & aspect |
|
|
57
57
|
| resetText | `string` | `Reset` | Reset button text |
|
|
58
58
|
| aspect | `number` | `1 / 1` | Aspect of crop area , `width / height` |
|
|
59
|
-
| minZoom | `number` | `1` | Minimum zoom
|
|
60
|
-
| maxZoom | `number` | `3` | Maximum zoom
|
|
59
|
+
| minZoom | `number` | `1` | Minimum zoom |
|
|
60
|
+
| maxZoom | `number` | `3` | Maximum zoom |
|
|
61
|
+
| minAspect | `number` | `0.5` | Minimum aspect |
|
|
62
|
+
| maxAspect | `number` | `2` | Maximum aspect |
|
|
61
63
|
| cropShape | `string` | `'rect'` | Shape of crop area, `'rect'` or `'round'` |
|
|
62
64
|
| showGrid | `boolean` | `false` | Show grid of crop area (third-lines) |
|
|
63
65
|
| cropperProps | `object` | - | [react-easy-crop] props (\* existing props cannot be overridden) |
|
package/README.zh-CN.md
CHANGED
|
@@ -50,14 +50,16 @@ const Demo = () => (
|
|
|
50
50
|
| -------------- | -------------------- | ------------ | ---------------------------------------------------------------- |
|
|
51
51
|
| quality | `number` | `0.4` | 裁切图片质量,`0` 到 `1` 之间 |
|
|
52
52
|
| fillColor | `string` | `'white'` | 裁切图像填充色 |
|
|
53
|
-
| zoomSlider | `boolean` | `true` |
|
|
54
|
-
| rotationSlider | `boolean` | `false` |
|
|
55
|
-
| aspectSlider | `boolean` | `false` |
|
|
56
|
-
| showReset | `boolean` | `false` |
|
|
53
|
+
| zoomSlider | `boolean` | `true` | 允许缩放 |
|
|
54
|
+
| rotationSlider | `boolean` | `false` | 允许旋转 |
|
|
55
|
+
| aspectSlider | `boolean` | `false` | 允许调整裁切比 |
|
|
56
|
+
| showReset | `boolean` | `false` | 显示重置按钮,重置缩放 & 旋转 & 裁切比 |
|
|
57
57
|
| resetText | `string` | `重置` | 重置按钮文字 |
|
|
58
58
|
| aspect | `number` | `1 / 1` | 裁切区域宽高比,`width / height` |
|
|
59
|
-
| minZoom | `number` | `1` |
|
|
60
|
-
| maxZoom | `number` | `3` |
|
|
59
|
+
| minZoom | `number` | `1` | 最小缩放 |
|
|
60
|
+
| maxZoom | `number` | `3` | 最大缩放 |
|
|
61
|
+
| minAspect | `number` | `0.5` | 最小裁切比 |
|
|
62
|
+
| maxAspect | `number` | `2` | 最大裁切比 |
|
|
61
63
|
| cropShape | `string` | `'rect'` | 裁切区域形状,`'rect'` 或 `'round'` |
|
|
62
64
|
| showGrid | `boolean` | `false` | 显示裁切区域网格(九宫格) |
|
|
63
65
|
| cropperProps | `object` | - | [react-easy-crop] 的 props(\* 已有 props 无法重写) |
|
|
@@ -16,22 +16,25 @@ const ROTATION_INITIAL = 0;
|
|
|
16
16
|
const ROTATION_MIN = -180;
|
|
17
17
|
const ROTATION_MAX = 180;
|
|
18
18
|
const ROTATION_STEP = 1;
|
|
19
|
-
const ASPECT_MIN = 0.5;
|
|
20
|
-
const ASPECT_MAX = 2;
|
|
21
19
|
const ASPECT_STEP = 0.01;
|
|
22
20
|
|
|
23
21
|
const EasyCrop = react.forwardRef((props, ref) => {
|
|
24
|
-
const { cropperRef, zoomSlider, rotationSlider, aspectSlider, showReset, resetBtnText, modalImage, aspect:
|
|
22
|
+
const { cropperRef, zoomSlider, rotationSlider, aspectSlider, showReset, resetBtnText, modalImage, aspect: propAspect, minZoom, maxZoom, minAspect, maxAspect, cropShape, showGrid, cropperProps, } = props;
|
|
25
23
|
const [zoom, setZoom] = react.useState(ZOOM_INITIAL);
|
|
26
24
|
const [rotation, setRotation] = react.useState(ROTATION_INITIAL);
|
|
27
|
-
const [aspect, setAspect] = react.useState(
|
|
25
|
+
const [aspect, setAspect] = react.useState(propAspect);
|
|
26
|
+
const prevPropAspect = react.useRef(propAspect);
|
|
27
|
+
if (prevPropAspect.current !== propAspect) {
|
|
28
|
+
prevPropAspect.current = propAspect;
|
|
29
|
+
setAspect(propAspect);
|
|
30
|
+
}
|
|
28
31
|
const isResetActive = zoom !== ZOOM_INITIAL ||
|
|
29
32
|
rotation !== ROTATION_INITIAL ||
|
|
30
|
-
aspect !==
|
|
33
|
+
aspect !== propAspect;
|
|
31
34
|
const onReset = () => {
|
|
32
35
|
setZoom(ZOOM_INITIAL);
|
|
33
36
|
setRotation(ROTATION_INITIAL);
|
|
34
|
-
setAspect(
|
|
37
|
+
setAspect(propAspect);
|
|
35
38
|
};
|
|
36
39
|
const [crop, onCropChange] = react.useState({ x: 0, y: 0 });
|
|
37
40
|
const cropPixelsRef = react.useRef({ width: 0, height: 0, x: 0, y: 0 });
|
|
@@ -53,7 +56,7 @@ const EasyCrop = react.forwardRef((props, ref) => {
|
|
|
53
56
|
cropShape: cropShape, showGrid: showGrid, onCropChange: onCropChange, onZoomChange: setZoom, onRotationChange: setRotation, onCropComplete: onCropComplete, classes: {
|
|
54
57
|
containerClassName: `${PREFIX}-container ![position:relative] [width:100%] [height:40vh] [&~section:first-of-type]:[margin-top:16px] [&~section:last-of-type]:[margin-bottom:16px]`,
|
|
55
58
|
mediaClassName: `${PREFIX}-media`,
|
|
56
|
-
} })), 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 <
|
|
59
|
+
} })), 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 }))] }));
|
|
57
60
|
});
|
|
58
61
|
var EasyCrop$1 = react.memo(EasyCrop);
|
|
59
62
|
|
|
@@ -84,11 +87,11 @@ function styleInject(css, ref) {
|
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
|
|
87
|
-
var css_248z = "
|
|
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}}";
|
|
88
91
|
styleInject(css_248z,{"insertAt":"top"});
|
|
89
92
|
|
|
90
93
|
const ImgCrop = react.forwardRef((props, cropperRef) => {
|
|
91
|
-
const { quality = 0.4, fillColor = 'white', zoomSlider = true, rotationSlider = false, aspectSlider = false, showReset = false, resetText, aspect = 1, minZoom = 1, maxZoom = 3, cropShape = 'rect', showGrid = false, cropperProps, modalClassName, modalTitle, modalWidth, modalOk, modalCancel, onModalOk, onModalCancel, modalProps, beforeCrop, children, } = props;
|
|
94
|
+
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;
|
|
92
95
|
const cb = react.useRef({});
|
|
93
96
|
cb.current.onModalOk = onModalOk;
|
|
94
97
|
cb.current.onModalCancel = onModalCancel;
|
|
@@ -146,8 +149,8 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
|
|
|
146
149
|
* upload
|
|
147
150
|
*/
|
|
148
151
|
const [modalImage, setModalImage] = react.useState('');
|
|
149
|
-
const onCancel = react.useRef();
|
|
150
|
-
const onOk = react.useRef();
|
|
152
|
+
const onCancel = react.useRef(undefined);
|
|
153
|
+
const onOk = react.useRef(undefined);
|
|
151
154
|
const runBeforeUpload = react.useCallback((_a) => tslib.__awaiter(void 0, [_a], void 0, function* ({ beforeUpload, file, resolve, reject, }) {
|
|
152
155
|
const rawFile = file;
|
|
153
156
|
if (typeof beforeUpload !== 'function') {
|
|
@@ -260,7 +263,7 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
|
|
|
260
263
|
const isCN = lang === 'zh-CN';
|
|
261
264
|
const title = modalTitle || (isCN ? '编辑图片' : 'Edit image');
|
|
262
265
|
const resetBtnText = resetText || (isCN ? '重置' : 'Reset');
|
|
263
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [getNewUpload(children), modalImage && (jsxRuntime.jsx(AntModal, Object.assign({}, modalProps, modalBaseProps, { open: true, title: title, onCancel: onCancel.current, onOk: onOk.current, wrapClassName: wrapClassName, maskClosable: false, destroyOnClose: 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, cropShape: cropShape, showGrid: showGrid, cropperProps: cropperProps }) })))] }));
|
|
266
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [getNewUpload(children), modalImage && (jsxRuntime.jsx(AntModal, Object.assign({}, modalProps, modalBaseProps, { open: true, title: title, onCancel: onCancel.current, onOk: onOk.current, wrapClassName: wrapClassName, maskClosable: false, destroyOnClose: 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 }) })))] }));
|
|
264
267
|
});
|
|
265
268
|
|
|
266
269
|
module.exports = ImgCrop;
|
package/dist/antd-img-crop.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
+
import { JSX } from 'react';
|
|
2
3
|
import Cropper, { CropperProps } from 'react-easy-crop';
|
|
3
|
-
import {
|
|
4
|
+
import { UploadProps, ModalProps } from 'antd';
|
|
4
5
|
|
|
5
6
|
type BeforeUpload = Exclude<UploadProps['beforeUpload'], undefined>;
|
|
6
7
|
type BeforeUploadReturnType = ReturnType<BeforeUpload>;
|
|
@@ -15,9 +16,11 @@ type ImgCropProps = {
|
|
|
15
16
|
aspect?: number;
|
|
16
17
|
minZoom?: number;
|
|
17
18
|
maxZoom?: number;
|
|
19
|
+
minAspect?: number;
|
|
20
|
+
maxAspect?: number;
|
|
18
21
|
cropShape?: 'rect' | 'round';
|
|
19
22
|
showGrid?: boolean;
|
|
20
|
-
cropperProps?: Omit<CropperProps, 'image' | 'crop' | 'zoom' | 'rotation' | 'aspect' | 'minZoom' | 'maxZoom' | 'zoomWithScroll' | 'cropShape' | 'showGrid' | 'onCropChange' | 'onZoomChange' | 'onRotationChange' | 'onCropComplete' | 'classes'
|
|
23
|
+
cropperProps?: Omit<CropperProps, 'image' | 'crop' | 'zoom' | 'rotation' | 'aspect' | 'minZoom' | 'maxZoom' | 'minAspect' | 'maxAspect' | 'zoomWithScroll' | 'cropShape' | 'showGrid' | 'onCropChange' | 'onZoomChange' | 'onRotationChange' | 'onCropComplete' | 'classes' | 'keyboardStep'> & Partial<Pick<CropperProps, 'keyboardStep'>>;
|
|
21
24
|
modalClassName?: string;
|
|
22
25
|
modalTitle?: string;
|
|
23
26
|
modalWidth?: number | string;
|
|
@@ -32,4 +35,5 @@ type ImgCropProps = {
|
|
|
32
35
|
|
|
33
36
|
declare const ImgCrop: react.ForwardRefExoticComponent<ImgCropProps & react.RefAttributes<Cropper>>;
|
|
34
37
|
|
|
35
|
-
export {
|
|
38
|
+
export { ImgCrop as default };
|
|
39
|
+
export type { ImgCropProps };
|
|
@@ -14,22 +14,25 @@ const ROTATION_INITIAL = 0;
|
|
|
14
14
|
const ROTATION_MIN = -180;
|
|
15
15
|
const ROTATION_MAX = 180;
|
|
16
16
|
const ROTATION_STEP = 1;
|
|
17
|
-
const ASPECT_MIN = 0.5;
|
|
18
|
-
const ASPECT_MAX = 2;
|
|
19
17
|
const ASPECT_STEP = 0.01;
|
|
20
18
|
|
|
21
19
|
const EasyCrop = forwardRef((props, ref) => {
|
|
22
|
-
const { cropperRef, zoomSlider, rotationSlider, aspectSlider, showReset, resetBtnText, modalImage, aspect:
|
|
20
|
+
const { cropperRef, zoomSlider, rotationSlider, aspectSlider, showReset, resetBtnText, modalImage, aspect: propAspect, minZoom, maxZoom, minAspect, maxAspect, cropShape, showGrid, cropperProps, } = props;
|
|
23
21
|
const [zoom, setZoom] = useState(ZOOM_INITIAL);
|
|
24
22
|
const [rotation, setRotation] = useState(ROTATION_INITIAL);
|
|
25
|
-
const [aspect, setAspect] = useState(
|
|
23
|
+
const [aspect, setAspect] = useState(propAspect);
|
|
24
|
+
const prevPropAspect = useRef(propAspect);
|
|
25
|
+
if (prevPropAspect.current !== propAspect) {
|
|
26
|
+
prevPropAspect.current = propAspect;
|
|
27
|
+
setAspect(propAspect);
|
|
28
|
+
}
|
|
26
29
|
const isResetActive = zoom !== ZOOM_INITIAL ||
|
|
27
30
|
rotation !== ROTATION_INITIAL ||
|
|
28
|
-
aspect !==
|
|
31
|
+
aspect !== propAspect;
|
|
29
32
|
const onReset = () => {
|
|
30
33
|
setZoom(ZOOM_INITIAL);
|
|
31
34
|
setRotation(ROTATION_INITIAL);
|
|
32
|
-
setAspect(
|
|
35
|
+
setAspect(propAspect);
|
|
33
36
|
};
|
|
34
37
|
const [crop, onCropChange] = useState({ x: 0, y: 0 });
|
|
35
38
|
const cropPixelsRef = useRef({ width: 0, height: 0, x: 0, y: 0 });
|
|
@@ -51,7 +54,7 @@ const EasyCrop = forwardRef((props, ref) => {
|
|
|
51
54
|
cropShape: cropShape, showGrid: showGrid, onCropChange: onCropChange, onZoomChange: setZoom, onRotationChange: setRotation, onCropComplete: onCropComplete, classes: {
|
|
52
55
|
containerClassName: `${PREFIX}-container ![position:relative] [width:100%] [height:40vh] [&~section:first-of-type]:[margin-top:16px] [&~section:last-of-type]:[margin-bottom:16px]`,
|
|
53
56
|
mediaClassName: `${PREFIX}-media`,
|
|
54
|
-
} })), 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 <
|
|
57
|
+
} })), 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 }))] }));
|
|
55
58
|
});
|
|
56
59
|
var EasyCrop$1 = memo(EasyCrop);
|
|
57
60
|
|
|
@@ -82,11 +85,11 @@ function styleInject(css, ref) {
|
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
87
|
|
|
85
|
-
var css_248z = "
|
|
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}}";
|
|
86
89
|
styleInject(css_248z,{"insertAt":"top"});
|
|
87
90
|
|
|
88
91
|
const ImgCrop = forwardRef((props, cropperRef) => {
|
|
89
|
-
const { quality = 0.4, fillColor = 'white', zoomSlider = true, rotationSlider = false, aspectSlider = false, showReset = false, resetText, aspect = 1, minZoom = 1, maxZoom = 3, cropShape = 'rect', showGrid = false, cropperProps, modalClassName, modalTitle, modalWidth, modalOk, modalCancel, onModalOk, onModalCancel, modalProps, beforeCrop, children, } = props;
|
|
92
|
+
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;
|
|
90
93
|
const cb = useRef({});
|
|
91
94
|
cb.current.onModalOk = onModalOk;
|
|
92
95
|
cb.current.onModalCancel = onModalCancel;
|
|
@@ -144,8 +147,8 @@ const ImgCrop = forwardRef((props, cropperRef) => {
|
|
|
144
147
|
* upload
|
|
145
148
|
*/
|
|
146
149
|
const [modalImage, setModalImage] = useState('');
|
|
147
|
-
const onCancel = useRef();
|
|
148
|
-
const onOk = useRef();
|
|
150
|
+
const onCancel = useRef(undefined);
|
|
151
|
+
const onOk = useRef(undefined);
|
|
149
152
|
const runBeforeUpload = useCallback((_a) => __awaiter(void 0, [_a], void 0, function* ({ beforeUpload, file, resolve, reject, }) {
|
|
150
153
|
const rawFile = file;
|
|
151
154
|
if (typeof beforeUpload !== 'function') {
|
|
@@ -258,7 +261,7 @@ const ImgCrop = forwardRef((props, cropperRef) => {
|
|
|
258
261
|
const isCN = lang === 'zh-CN';
|
|
259
262
|
const title = modalTitle || (isCN ? '编辑图片' : 'Edit image');
|
|
260
263
|
const resetBtnText = resetText || (isCN ? '重置' : 'Reset');
|
|
261
|
-
return (jsxs(Fragment, { children: [getNewUpload(children), modalImage && (jsx(AntModal, Object.assign({}, modalProps, modalBaseProps, { open: true, title: title, onCancel: onCancel.current, onOk: onOk.current, wrapClassName: wrapClassName, maskClosable: false, destroyOnClose: 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, cropShape: cropShape, showGrid: showGrid, cropperProps: cropperProps }) })))] }));
|
|
264
|
+
return (jsxs(Fragment, { children: [getNewUpload(children), modalImage && (jsx(AntModal, Object.assign({}, modalProps, modalBaseProps, { open: true, title: title, onCancel: onCancel.current, onOk: onOk.current, wrapClassName: wrapClassName, maskClosable: false, destroyOnClose: 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 }) })))] }));
|
|
262
265
|
});
|
|
263
266
|
|
|
264
267
|
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.25.0",
|
|
4
4
|
"description": "An image cropper for Ant Design Upload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -23,8 +23,7 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"scripts": {
|
|
26
|
-
"build": "rm -rf dist && rollup -c --configPlugin @rollup/plugin-typescript"
|
|
27
|
-
"u": "pnpm update --latest && pnpm add eslint@8.57.0"
|
|
26
|
+
"build": "rm -rf dist && rollup -c --configPlugin @rollup/plugin-typescript"
|
|
28
27
|
},
|
|
29
28
|
"peerDependencies": {
|
|
30
29
|
"antd": ">=4.0.0",
|
|
@@ -32,32 +31,42 @@
|
|
|
32
31
|
"react-dom": ">=16.8.0"
|
|
33
32
|
},
|
|
34
33
|
"dependencies": {
|
|
35
|
-
"react-easy-crop": "^5.
|
|
36
|
-
"tslib": "^2.
|
|
34
|
+
"react-easy-crop": "^5.4.1",
|
|
35
|
+
"tslib": "^2.8.1"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
44
|
-
"@
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"eslint-
|
|
38
|
+
"@eslint/compat": "^1.2.8",
|
|
39
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
40
|
+
"@eslint/js": "^9.25.1",
|
|
41
|
+
"@rollup/plugin-replace": "^6.0.2",
|
|
42
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
43
|
+
"@tailwindcss/postcss": "^4.1.4",
|
|
44
|
+
"@types/node": "^22.15.3",
|
|
45
|
+
"@types/react": "19.1.2",
|
|
46
|
+
"@types/react-dom": "19.1.2",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^8.31.1",
|
|
48
|
+
"@vitejs/plugin-react": "^4.4.1",
|
|
49
|
+
"antd": "^5.24.9",
|
|
50
|
+
"autoprefixer": "^10.4.21",
|
|
51
|
+
"eslint": "^9.25.1",
|
|
52
|
+
"eslint-config-prettier": "^10.1.2",
|
|
49
53
|
"eslint-config-react-app": "^7.0.1",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"react": "^
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
54
|
+
"eslint-plugin-flowtype": "^8.0.3",
|
|
55
|
+
"eslint-plugin-import": "^2.31.0",
|
|
56
|
+
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
57
|
+
"eslint-plugin-react": "^7.37.5",
|
|
58
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
59
|
+
"postcss": "^8.5.3",
|
|
60
|
+
"prettier": "^3.5.3",
|
|
61
|
+
"prettier-plugin-organize-imports": "^4.1.0",
|
|
62
|
+
"prettier-plugin-tailwindcss": "^0.6.11",
|
|
63
|
+
"react": "19.1.0",
|
|
64
|
+
"react-dom": "19.1.0",
|
|
65
|
+
"rollup": "4.40.1",
|
|
66
|
+
"rollup-plugin-dts": "^6.2.1",
|
|
58
67
|
"rollup-plugin-postcss": "^4.0.2",
|
|
59
|
-
"tailwindcss": "^
|
|
60
|
-
"typescript": "^5.
|
|
61
|
-
"vite": "^
|
|
68
|
+
"tailwindcss": "^4.1.4",
|
|
69
|
+
"typescript": "^5.8.3",
|
|
70
|
+
"vite": "^6.3.3"
|
|
62
71
|
}
|
|
63
72
|
}
|