Utils
warning
It's the part of the unstable API. Use it carefully. Everything can be changed in the future.
#
Modifiers of state components#
Fit Coordinatesfunction fitCoordinates(state: CropperState, settings: CoreSettings): Coordinates;
#
Fit Visible Areafunction fitVisibleArea(state: CropperState, settings: CoreSettings): VisibleArea;
#
Resize Coordinates Algorithmfunction resizeCoordinatesAlgorithm( coordinates: Coordinates, directions: ResizeDirections, options: ResizeOptions, limitations: ResizeLimitations,): Coordinates;
interface ResizeOptions { compensate?: boolean; preserveRatio?: boolean; allowedDirections?: ResizeDirections; respectDirection?: 'width' | 'height';}
interface ResizeLimitations { aspectRatio: AspectRatio; sizeRestrictions: SizeRestrictions; positionRestrictions: PositionRestrictions;}
#
Move Coordinates Algorithmfunction moveCoordinatesAlgorithm( coordinates: Coordinates, directions: MoveDirections, positionRestrictions: PositionRestrictions,): Coordinates;
#
Round Coordinatesfunction roundCoordinates(state: CropperState, settings: CoreSettings): Coordinates;
#
Touch#
Get a mean touchfunction getMeanTouch(touches: SimpleTouch[]): SimpleTouch;
#
Calculate geometric propertiesfunction calculateGeometricProperties(touches: SimpleTouch[], container: HTMLElement): GeometricProperties;
#
Create touch resize eventfunction createTouchResizeEvent(oldProperties: GeometricProperties, newProperties: GeometricProperties): TransformImageEvent
#
Create touch resize eventfunction createTouchMoveEvent(oldTouches: SimpleTouch[], newTouches: SimpleTouch[]): TransformImageEvent
#
Create wheel resize eventfunction createWheelResizeEvent( event: WheelEvent & { wheelDelta?: number }, container: HTMLElement, ratio = 0.1,): ResizeEvent;
#
Canvas#
Draw the cropped areafunction drawCroppedArea( state: CropperState, image: HTMLImageElement, resultCanvas: HTMLCanvasElement, spareCanvas: HTMLCanvasElement, options: DrawOptions,)
interface DrawOptions { width?: number; height?: number; minWidth?: number; maxWidth?: number; minHeight?: number; maxHeight?: number; maxArea?: number; imageSmoothingQuality?: 'low' | 'medium' | 'high'; imageSmoothingEnabled?: boolean; fillColor?: string;}
#
Events#
Normalize transform image eventfunction normalizeTransformImageEvent(state: CropperState, event: TransformImageEvent): TransformImageEvent;
#
Normalize move eventfunction normalizeMoveEvent(state: CropperState, event: MoveEvent): MoveEvent;
#
Normalize resize eventfunction normalizeResizeEvent(state: CropperState, event: ResizeEvent): ResizeEvent;
#
Getters#
Get area size restrictionsfunction getAreaSizeRestrictions(state: CropperState, settings: CoreSettings)
#
Get area position restrictionsfunction getAreaPositionRestrictions(state: CropperState, settings: CoreSettings)
#
Get size restrictionsfunction getSizeRestrictions(state: CropperState, settings: CoreSettings)
#
Get positions restrictionsfunction getPositionRestrictions(state: CropperState, settings: CoreSettings)
#
Get coefficientfunction getCoefficient(state: CropperState)
#
Get stencil coordinatesfunction getStencilCoordinates(state: CropperState | null)
#
Get aspect ratiofunction getAspectRatio(state: CropperState, settings: CoreSettings)
#
Get default coordinatesfunction getDefaultCoordinates(state: CropperState, settings: CoreSettings)
#
Get default visible areafunction getDefaultVisibleArea(state: CropperState, settings: CoreSettings)
#
Get area size restrictionsfunction getTransformedImageSize(state: CropperState)
#
Get area size restrictionsfunction getComputedTransforms(state: CropperState)
function getMinimumSize(state: CropperState)
#
Image#
Load Imagefunction loadImage(src: string, settings: LoadImageSettings = {}): Promise<CropperImage>
#
Get Preview Stylefunction getImageStyle(image: CropperImage, state: CropperState, transitions: CropperTransitions)
#
Get Image Stylefunction getPreviewStyle( image: CropperImage, state: CropperState, transitions: CropperTransitions | null, size: Size,)
#
Get Mime Typefunction getMimeType(arrayBuffer, fallback = null): string
#
Size#
Approximate Sizefunction approximateSize(params: { width: number; height: number; sizeRestrictions: SizeRestrictions; aspectRatio?: AspectRatio;}): Size
#
State#
Compare statesfunction isEqualState(a: CropperState | null, b: CropperState | null): boolean
#
Restrictions#
Get broken ratiofunction getBrokenRatio(currentAspectRatio: number, aspectRatio: AspectRatio): number | undefined
#
Fit to the size restrictionsfunction fitToSizeRestrictions(coordinates: Size, sizeRestrictions: SizeRestrictions)
#
Resize to the size restrictionsfunction resizeToSizeRestrictions(coordinates: Coordinates, sizeRestrictions: SizeRestrictions)
#
Convert position restrictions to size restrictionsfunction positionToSizeRestrictions(positionRestrictions: PositionRestrictions): SizeRestrictions
#
Merge position restrictionsfunction mergePositionRestrictions(a: PositionRestrictions, b: PositionRestrictions): SizeRestrictions;
#
Fit to position restrictionsfunction fitToPositionRestrictions(coordinates: Coordinates, positionRestrictions: PositionRestrictions): MoveDirections;
#
Move to position restrictionsfunction moveToPositionRestrictions(coordinates: Coordinates, positionRestrictions: PositionRestrictions): Coordinates;
#
Convert coordinates to positions restrictionsfunction coordinatesToPositionRestrictions(coordinates: Coordinates): PositionRestrictions
#
Geometry#
Rotate sizefunction rotateSize(size: Size, angle: number)
#
Rotate pointfunction rotatePoint(point: Point, angle: number, anchor?: Point)
#
To limitsfunction toLimits(object: Coordinates): Limits
#
Difffunction diff(firstObject: Point, secondObject: Point): Diff
#
Distance between sizesfunction sizeDistance(a: Size, b: Size): number
#
Get centerfunction getCenter(object: Coordinates): Point
#
Get intersectionsfunction getIntersections(object: Coordinates, limits: Limits): Intersections
#
Apply directionsfunction applyDirections(coordinates: Coordinates, directions: ResizeDirections): Coordinates
#
Inverse movefunction inverseMove(directions: MoveDirections): MoveDirections
#
Apply movefunction applyMove(object: Coordinates, move: MoveDirections): Coordinates
#
Apply scalefunction applyScale(object: Coordinates, scaleFactor: number, center?: Point, progress?: number): Coordinates
#
Get ratiofunction ratio(object: Size): number
#
Get maximum scalefunction maxScale(size: Size, restrictions: SizeRestrictions): number
#
Get minimum scalefunction minScale(size: Size, restrictions: SizeRestrictions): number
#
Math#
Is roughly equalfunction isRoughlyEqual(a: number, b: number, tolerance = 1e-3): boolean;
#
Is greaterfunction isGreater(a: number, b: number, tolerance?: number): boolean;
#
Is lowerfunction isLower(a: number, b: number, tolerance?: number): boolean;