antd-img-crop 4.25.0 → 4.27.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.
@@ -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,22 @@ 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
- function styleInject(css, ref) {
64
- if ( ref === void 0 ) ref = {};
65
- var insertAt = ref.insertAt;
66
-
67
- if (typeof document === 'undefined') { return; }
68
-
69
- var head = document.head || document.getElementsByTagName('head')[0];
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
+ (function() {
61
+ if (typeof document === 'undefined') return;
62
+ const style = document.createElement('style');
63
+ const meta = document.querySelector('meta[name="csp-nonce"]');
64
+ if (meta && meta.content) style.setAttribute('nonce', meta.content);
65
+ style.textContent = css_248z;
66
+ document.head.appendChild(style);
67
+ })();
92
68
 
93
69
  const ImgCrop = react.forwardRef((props, cropperRef) => {
94
70
  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 +124,7 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
148
124
  /**
149
125
  * upload
150
126
  */
127
+ const [modalOpen, setModalOpen] = react.useState(false);
151
128
  const [modalImage, setModalImage] = react.useState('');
152
129
  const onCancel = react.useRef(undefined);
153
130
  const onOk = react.useRef(undefined);
@@ -194,13 +171,17 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
194
171
  const reader = new FileReader();
195
172
  reader.addEventListener('load', () => {
196
173
  if (typeof reader.result === 'string') {
197
- setModalImage(reader.result); // open modal
174
+ setModalOpen(true);
175
+ setTimeout(() => {
176
+ setModalImage(reader.result);
177
+ }, 10);
198
178
  }
199
179
  });
200
180
  reader.readAsDataURL(processedFile);
201
181
  // on modal cancel
202
182
  onCancel.current = () => {
203
183
  var _a, _b;
184
+ setModalOpen(false);
204
185
  setModalImage('');
205
186
  easyCropRef.current.onReset();
206
187
  let hasResolveCalled = false;
@@ -214,6 +195,7 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
214
195
  };
215
196
  // on modal confirm
216
197
  onOk.current = (event) => tslib.__awaiter(void 0, void 0, void 0, function* () {
198
+ setModalOpen(false);
217
199
  setModalImage('');
218
200
  easyCropRef.current.onReset();
219
201
  const canvas = getCropCanvas(event.target);
@@ -263,7 +245,7 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
263
245
  const isCN = lang === 'zh-CN';
264
246
  const title = modalTitle || (isCN ? '编辑图片' : 'Edit image');
265
247
  const resetBtnText = resetText || (isCN ? '重置' : 'Reset');
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 }) })))] }));
248
+ 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
249
  });
268
250
 
269
251
  module.exports = ImgCrop;
@@ -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' | 'destroyOnClose'>;
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<Cropper>>;
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,22 @@ 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
- function styleInject(css, ref) {
62
- if ( ref === void 0 ) ref = {};
63
- var insertAt = ref.insertAt;
64
-
65
- if (typeof document === 'undefined') { return; }
66
-
67
- var head = document.head || document.getElementsByTagName('head')[0];
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
+ (function() {
59
+ if (typeof document === 'undefined') return;
60
+ const style = document.createElement('style');
61
+ const meta = document.querySelector('meta[name="csp-nonce"]');
62
+ if (meta && meta.content) style.setAttribute('nonce', meta.content);
63
+ style.textContent = css_248z;
64
+ document.head.appendChild(style);
65
+ })();
90
66
 
91
67
  const ImgCrop = forwardRef((props, cropperRef) => {
92
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;
@@ -146,6 +122,7 @@ const ImgCrop = forwardRef((props, cropperRef) => {
146
122
  /**
147
123
  * upload
148
124
  */
125
+ const [modalOpen, setModalOpen] = useState(false);
149
126
  const [modalImage, setModalImage] = useState('');
150
127
  const onCancel = useRef(undefined);
151
128
  const onOk = useRef(undefined);
@@ -192,13 +169,17 @@ const ImgCrop = forwardRef((props, cropperRef) => {
192
169
  const reader = new FileReader();
193
170
  reader.addEventListener('load', () => {
194
171
  if (typeof reader.result === 'string') {
195
- setModalImage(reader.result); // open modal
172
+ setModalOpen(true);
173
+ setTimeout(() => {
174
+ setModalImage(reader.result);
175
+ }, 10);
196
176
  }
197
177
  });
198
178
  reader.readAsDataURL(processedFile);
199
179
  // on modal cancel
200
180
  onCancel.current = () => {
201
181
  var _a, _b;
182
+ setModalOpen(false);
202
183
  setModalImage('');
203
184
  easyCropRef.current.onReset();
204
185
  let hasResolveCalled = false;
@@ -212,6 +193,7 @@ const ImgCrop = forwardRef((props, cropperRef) => {
212
193
  };
213
194
  // on modal confirm
214
195
  onOk.current = (event) => __awaiter(void 0, void 0, void 0, function* () {
196
+ setModalOpen(false);
215
197
  setModalImage('');
216
198
  easyCropRef.current.onReset();
217
199
  const canvas = getCropCanvas(event.target);
@@ -261,7 +243,7 @@ const ImgCrop = forwardRef((props, cropperRef) => {
261
243
  const isCN = lang === 'zh-CN';
262
244
  const title = modalTitle || (isCN ? '编辑图片' : 'Edit image');
263
245
  const resetBtnText = resetText || (isCN ? '重置' : 'Reset');
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 }) })))] }));
246
+ 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
247
  });
266
248
 
267
249
  export { ImgCrop as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antd-img-crop",
3
- "version": "4.25.0",
3
+ "version": "4.27.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.4.1",
34
+ "react-easy-crop": "^5.5.3",
35
35
  "tslib": "^2.8.1"
36
36
  },
37
37
  "devDependencies": {
38
- "@eslint/compat": "^1.2.8",
38
+ "@eslint/compat": "^1.4.0",
39
39
  "@eslint/eslintrc": "^3.3.1",
40
- "@eslint/js": "^9.25.1",
40
+ "@eslint/js": "^9.37.0",
41
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",
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.25.1",
52
- "eslint-config-prettier": "^10.1.2",
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.31.0",
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": "^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
+ "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.4",
69
- "typescript": "^5.8.3",
70
- "vite": "^6.3.3"
68
+ "tailwindcss": "^4.1.14",
69
+ "typescript": "^5.9.3",
70
+ "vite": "^7.1.9"
71
71
  }
72
72
  }