(null);
+
const points = useMemo(() => {
const result: PointNode[] = [];
HORIZONTAL_DIRECTIONS.forEach((hDirection) => {
@@ -198,23 +203,10 @@ export const BoundingBox = ({
) =>
({ left, top }: MoveDirections, nativeEvent: MouseEvent | TouchEvent) => {
const directions = {
- left: 0,
- right: 0,
- top: 0,
- bottom: 0,
+ left,
+ top,
};
- if (horizontalDirection === 'west') {
- directions.left -= left;
- } else if (horizontalDirection === 'east') {
- directions.right += left;
- }
- if (verticalDirection === 'north') {
- directions.top -= top;
- } else if (verticalDirection === 'south') {
- directions.bottom += top;
- }
-
let respectDirection: 'width' | 'height' | undefined;
if (!verticalDirection && horizontalDirection) {
respectDirection = 'width';
@@ -224,20 +216,27 @@ export const BoundingBox = ({
if (!disabled) {
if (onResize) {
- onResize(directions, {
- allowedDirections: {
- left: horizontalDirection === 'west' || !horizontalDirection,
- right: horizontalDirection === 'east' || !horizontalDirection,
- bottom: verticalDirection === 'south' || !verticalDirection,
- top: verticalDirection === 'north' || !verticalDirection,
- },
- preserveAspectRatio: nativeEvent && nativeEvent.shiftKey,
- respectDirection,
- });
+ const anchor = getDirectionNames(horizontalDirection, verticalDirection).camelCase;
+ if (anchor) {
+ onResize(anchor, directions, {
+ reference: lastReference || reference,
+ preserveAspectRatio: nativeEvent && nativeEvent.shiftKey,
+ respectDirection,
+ compensate: true,
+ });
+ }
+ }
+ if (!lastReference) {
+ setLastReference(reference);
}
}
};
+ const onHandlerDragEnd = () => {
+ onResizeEnd?.();
+ setLastReference(null);
+ };
+
return (
{children}
@@ -251,7 +250,7 @@ export const BoundingBox = ({
position={line.name}
disabled={line.disabled}
onDrag={onHandlerDrag(line.horizontalPosition, line.verticalPosition)}
- onDragEnd={onResizeEnd}
+ onDragEnd={onHandlerDragEnd}
/>
))}
@@ -266,7 +265,7 @@ export const BoundingBox = ({
verticalPosition={handler.verticalPosition}
disabled={handler.disabled}
onDrag={onHandlerDrag(handler.horizontalPosition, handler.verticalPosition)}
- onDragEnd={onResizeEnd}
+ onDragEnd={onHandlerDragEnd}
/>
);
diff --git a/src/components/stencils/CircleStencil.tsx b/src/components/stencils/CircleStencil.tsx
index b4a6ee45..e5d00bff 100644
--- a/src/components/stencils/CircleStencil.tsx
+++ b/src/components/stencils/CircleStencil.tsx
@@ -5,12 +5,12 @@ import {
OrdinalDirection,
CropperTransitions,
CropperState,
- ResizeDirections,
MoveDirections,
CropperImage,
ResizeOptions,
getStencilCoordinates,
CropperInteractions,
+ ResizeAnchor,
} from 'advanced-cropper';
import { SimpleLine } from '../lines/SimpleLine';
import { SimpleHandler } from '../handlers/SimpleHandler';
@@ -18,7 +18,6 @@ import { BoundingBox } from '../service/BoundingBox';
import { StencilOverlay } from '../service/StencilOverlay';
import { DraggableArea } from '../service/DraggableArea';
import { StencilWrapper } from '../service/StencilWrapper';
-import { StencilOptions } from '../../types';
import { StencilGrid } from '../service/StencilGrid';
type HandlerComponent = ComponentType;
@@ -42,7 +41,7 @@ interface DesiredCropperRef {
getTransitions: () => CropperTransitions;
getInteractions: () => CropperInteractions;
hasInteractions: () => boolean;
- resizeCoordinates: (directions: Partial, parameters: unknown) => void;
+ resizeCoordinates: (anchor: ResizeAnchor, directions: Partial, parameters: unknown) => void;
resizeCoordinatesEnd: () => void;
moveCoordinates: (directions: Partial) => void;
moveCoordinatesEnd: () => void;
@@ -134,9 +133,9 @@ export const CircleStencil = forwardRef(
}
};
- const onResize = (directions: ResizeDirections, options: ResizeOptions) => {
+ const onResize = (anchor: ResizeAnchor, directions: MoveDirections, options: ResizeOptions) => {
if (cropper && resizable) {
- cropper.resizeCoordinates(directions, options);
+ cropper.resizeCoordinates(anchor, directions, options);
}
};
@@ -167,6 +166,7 @@ export const CircleStencil = forwardRef(
transitions={transitions}
>
CropperTransitions;
getInteractions: () => CropperInteractions;
hasInteractions: () => boolean;
- resizeCoordinates: (directions: Partial, parameters: unknown) => void;
+ resizeCoordinates: (anchor: ResizeAnchor, directions: Partial, parameters: unknown) => void;
resizeCoordinatesEnd: () => void;
moveCoordinates: (directions: Partial) => void;
moveCoordinatesEnd: () => void;
@@ -151,9 +151,9 @@ export const RectangleStencil = forwardRef(
}
};
- const onResize = (directions: ResizeDirections, options: ResizeOptions) => {
+ const onResize = (anchor: ResizeAnchor, directions: MoveDirections, options: ResizeOptions) => {
if (cropper && resizable) {
- cropper.resizeCoordinates(directions, options);
+ cropper.resizeCoordinates(anchor, directions, options);
}
};
@@ -189,6 +189,7 @@ export const RectangleStencil = forwardRef(
transitions={transitions}
>