UNPKG

8.14 kBTypeScriptView Raw
1import { default as default_2 } from 'react';
2import { PureComponent } from 'react';
3
4export declare const areCropsEqual: (cropA: Partial<Crop>, cropB: Partial<Crop>) => boolean;
5
6export declare function centerCrop(crop: Pick<PercentCrop, 'unit'> & Partial<Omit<PercentCrop, 'unit'>>, containerWidth: number, containerHeight: number): PercentCrop;
7
8export declare function centerCrop(crop: Pick<PixelCrop, 'unit'> & Partial<Omit<PixelCrop, 'unit'>>, containerWidth: number, containerHeight: number): PixelCrop;
9
10export declare const clamp: (num: number, min: number, max: number) => number;
11
12export declare const cls: (...args: unknown[]) => string;
13
14export declare function containCrop(pixelCrop: PixelCrop, aspect: number, ord: Ords, containerWidth: number, containerHeight: number, minWidth?: number, minHeight?: number, maxWidth?: number, maxHeight?: number): {
15 unit: "px";
16 x: number;
17 y: number;
18 width: number;
19 height: number;
20};
21
22export declare function convertToPercentCrop(crop: Partial<Crop>, containerWidth: number, containerHeight: number): PercentCrop;
23
24export declare function convertToPixelCrop(crop: Partial<Crop>, containerWidth: number, containerHeight: number): PixelCrop;
25
26export declare interface Crop {
27 x: number;
28 y: number;
29 width: number;
30 height: number;
31 unit: 'px' | '%';
32}
33
34export declare const defaultCrop: PixelCrop;
35
36declare interface EVData {
37 startClientX: number;
38 startClientY: number;
39 startCropX: number;
40 startCropY: number;
41 clientX: number;
42 clientY: number;
43 isResize: boolean;
44 ord?: Ords;
45}
46
47export declare function makeAspectCrop(crop: Pick<PercentCrop, 'unit'> & Partial<Omit<PercentCrop, 'unit'>>, aspect: number, containerWidth: number, containerHeight: number): PercentCrop;
48
49export declare function makeAspectCrop(crop: Pick<PixelCrop, 'unit'> & Partial<Omit<PixelCrop, 'unit'>>, aspect: number, containerWidth: number, containerHeight: number): PixelCrop;
50
51export declare function nudgeCrop(pixelCrop: PixelCrop, key: string, offset: number, ord: Ords): {
52 unit: "px";
53 x: number;
54 y: number;
55 width: number;
56 height: number;
57};
58
59export declare type Ords = XOrds | YOrds | XYOrds;
60
61export declare interface PercentCrop extends Crop {
62 unit: '%';
63}
64
65export declare interface PixelCrop extends Crop {
66 unit: 'px';
67}
68
69declare class ReactCrop extends PureComponent<ReactCropProps, ReactCropState> {
70 static xOrds: string[];
71 static yOrds: string[];
72 static xyOrds: string[];
73 static nudgeStep: number;
74 static nudgeStepMedium: number;
75 static nudgeStepLarge: number;
76 static defaultProps: {
77 ariaLabels: {
78 cropArea: string;
79 nwDragHandle: string;
80 nDragHandle: string;
81 neDragHandle: string;
82 eDragHandle: string;
83 seDragHandle: string;
84 sDragHandle: string;
85 swDragHandle: string;
86 wDragHandle: string;
87 };
88 };
89 get document(): Document;
90 docMoveBound: boolean;
91 mouseDownOnCrop: boolean;
92 dragStarted: boolean;
93 evData: EVData;
94 componentRef: default_2.RefObject<HTMLDivElement>;
95 mediaRef: default_2.RefObject<HTMLDivElement>;
96 resizeObserver?: ResizeObserver;
97 initChangeCalled: boolean;
98 instanceId: string;
99 state: ReactCropState;
100 getBox(): Rectangle;
101 componentDidUpdate(prevProps: ReactCropProps): void;
102 componentWillUnmount(): void;
103 bindDocMove(): void;
104 unbindDocMove(): void;
105 onCropPointerDown: (e: default_2.PointerEvent<HTMLDivElement>) => void;
106 onComponentPointerDown: (e: default_2.PointerEvent<HTMLDivElement>) => void;
107 onDocPointerMove: (e: PointerEvent) => void;
108 onComponentKeyDown: (e: default_2.KeyboardEvent<HTMLDivElement>) => void;
109 onHandlerKeyDown: (e: default_2.KeyboardEvent<HTMLDivElement>, ord: Ords) => void;
110 onDocPointerDone: (e: PointerEvent) => void;
111 onDragFocus: () => void;
112 getCropStyle(): {
113 top: string;
114 left: string;
115 width: string;
116 height: string;
117 } | undefined;
118 dragCrop(): PixelCrop;
119 getPointRegion(box: Rectangle, origOrd: Ords | undefined, minWidth: number, minHeight: number): XYOrds;
120 resolveMinDimensions(box: Rectangle, aspect: number, minWidth?: number, minHeight?: number): number[];
121 resizeCrop(): PixelCrop;
122 renderCropSelection(): default_2.JSX.Element | undefined;
123 makePixelCrop(box: Rectangle): PixelCrop;
124 render(): default_2.JSX.Element;
125}
126export { ReactCrop as Component }
127export { ReactCrop }
128export default ReactCrop;
129
130export declare interface ReactCropProps {
131 /** An object of labels to override the built-in English ones */
132 ariaLabels?: {
133 cropArea: string;
134 nwDragHandle: string;
135 nDragHandle: string;
136 neDragHandle: string;
137 eDragHandle: string;
138 seDragHandle: string;
139 sDragHandle: string;
140 swDragHandle: string;
141 wDragHandle: string;
142 };
143 /** The aspect ratio of the crop, e.g. `1` for a square or `16 / 9` for landscape. */
144 aspect?: number;
145 /** Classes to pass to the `ReactCrop` element. */
146 className?: string;
147 /** The elements that you want to perform a crop on. For example
148 * an image or video. */
149 children?: default_2.ReactNode;
150 /** Show the crop area as a circle. If your aspect is not 1 (a square) then the circle will be warped into an oval shape. Defaults to false. */
151 circularCrop?: boolean;
152 /** Since v10 all crop params are required except for aspect. Omit the entire crop object if you don't want a crop. See README on how to create an aspect crop with a % crop. */
153 crop?: Crop;
154 /** If true then the user cannot resize or draw a new crop. A class of `ReactCrop--disabled` is also added to the container for user styling. */
155 disabled?: boolean;
156 /** If true then the user cannot create or resize a crop, but can still drag the existing crop around. A class of `ReactCrop--locked` is also added to the container for user styling. */
157 locked?: boolean;
158 /** If true is passed then selection can't be disabled if the user clicks outside the selection area. */
159 keepSelection?: boolean;
160 /** A minimum crop width, in pixels. */
161 minWidth?: number;
162 /** A minimum crop height, in pixels. */
163 minHeight?: number;
164 /** A maximum crop width, in pixels. */
165 maxWidth?: number;
166 /** A maximum crop height, in pixels. */
167 maxHeight?: number;
168 /** A callback which happens for every change of the crop. You should set the crop to state and pass it back into the library via the `crop` prop. */
169 onChange: (crop: PixelCrop, percentageCrop: PercentCrop) => void;
170 /** A callback which happens after a resize, drag, or nudge. Passes the current crop state object in pixels and percent. */
171 onComplete?: (crop: PixelCrop, percentageCrop: PercentCrop) => void;
172 /** A callback which happens when a user starts dragging or resizing. It is convenient to manipulate elements outside this component. */
173 onDragStart?: (e: PointerEvent) => void;
174 /** A callback which happens when a user releases the cursor or touch after dragging or resizing. */
175 onDragEnd?: (e: PointerEvent) => void;
176 /** Render a custom element in crop selection. */
177 renderSelectionAddon?: (state: ReactCropState) => default_2.ReactNode;
178 /** Show rule of thirds lines in the cropped area. Defaults to false. */
179 ruleOfThirds?: boolean;
180 /** Inline styles object to be passed to the `ReactCrop` element. */
181 style?: default_2.CSSProperties;
182}
183
184export declare interface ReactCropState {
185 cropIsActive: boolean;
186 newCropIsBeingDrawn: boolean;
187}
188
189declare interface Rectangle {
190 x: number;
191 y: number;
192 width: number;
193 height: number;
194}
195
196export declare type XOrds = 'e' | 'w';
197
198export declare type XYOrds = 'nw' | 'ne' | 'se' | 'sw';
199
200export declare type YOrds = 'n' | 's';
201
202export { }