UNPKG

advanced-cropper

Version:

The core of the advanced cropper libraries family

204 lines (203 loc) 7.14 kB
type TimingFunction = string; interface Coordinates { width: number; height: number; top: number; left: number; } type VisibleArea = Coordinates; interface Limits { top?: number; left?: number; right?: number; bottom?: number; } interface SizeRestrictions { minWidth: number; maxWidth: number; minHeight: number; maxHeight: number; } type AreaSizeRestrictions = SizeRestrictions; type PositionRestrictions = Limits; type AreaPositionRestrictions = Limits; interface ResizeDirections { top: number; left: number; right: number; bottom: number; } interface MoveDirections { top: number; left: number; } interface Point { top: number; left: number; } interface Size { width: number; height: number; } type ImageSize = Size; type Boundary = Size; interface Intersections { left: number; top: number; bottom: number; right: number; } interface AspectRatio { minimum: number; maximum: number; } type ResizeAnchor = OrdinalDirection | 'center'; type RawAspectRatio = Partial<AspectRatio> | number; interface Diff { left: number; top: number; } interface Position { left: number; top: number; } declare enum ImageRestriction { fillArea = "fillArea", fitArea = "fitArea", stencil = "stencil", none = "none" } declare enum Priority { coordinates = "coordinates", visibleArea = "visibleArea" } type PositionDirection = 'left' | 'top' | 'right' | 'bottom'; type HorizontalDirection = 'left' | 'right'; type VerticalDirection = 'top' | 'bottom'; type MainDirections = 'left' | 'top'; type HorizontalCardinalDirection = 'west' | 'east'; type VerticalCardinalDirection = 'north' | 'south'; type CardinalDirection = HorizontalCardinalDirection | VerticalCardinalDirection; type OrdinalDirection = HorizontalCardinalDirection | VerticalCardinalDirection | 'westNorth' | 'westSouth' | 'eastNorth' | 'eastSouth'; interface Scale { factor: number; center?: Point; } interface Rotate { angle: number; center?: Point; } interface Flip { horizontal?: boolean; vertical?: boolean; } interface Transforms { rotate: number; flip: { horizontal: boolean; vertical: boolean; }; } interface PartialTransforms { rotate?: number; flip?: { horizontal?: boolean; vertical?: boolean; }; } interface ImageTransform { scale?: number | Scale; move?: { left?: number; top?: number; }; rotate?: number | Rotate; flip?: Flip; } type CoordinatesTransform = ((state: CropperState, settings: CoreSettings) => Partial<Coordinates> | null) | Partial<Coordinates> | null; interface CropperState { boundary: Boundary; imageSize: ImageSize; transforms: Transforms; visibleArea: VisibleArea | null; coordinates: Coordinates | null; } interface InitializedCropperState { boundary: Boundary; imageSize: ImageSize; transforms: Transforms; visibleArea: VisibleArea; coordinates: Coordinates; } type BoundarySizeAlgorithm = (boundary: HTMLElement, size: Size) => Boundary; type DefaultSize<Settings = CoreSettings> = Size | BivarianceConstraint<(state: CropperState, props: Settings) => Size>; type DefaultPosition<Settings = CoreSettings> = Position | BivarianceConstraint<(state: CropperState, props: Settings) => Position>; type DefaultVisibleArea<Settings = CoreSettings> = VisibleArea | BivarianceConstraint<(state: CropperState, props: Settings) => VisibleArea>; type DefaultCoordinates<Settings = CoreSettings> = (CoordinatesTransform | CoordinatesTransform[]) | BivarianceConstraint<(state: CropperState, settings: Settings) => CoordinatesTransform | CoordinatesTransform[]>; type DefaultTransforms<Settings = CoreSettings> = PartialTransforms | BivarianceConstraint<(state: CropperState, settings: Settings) => PartialTransforms>; interface CoreSettings { areaPositionRestrictions: AreaPositionRestrictions | BivarianceConstraint<(state: CropperState, settings: this) => AreaPositionRestrictions>; areaSizeRestrictions: AreaSizeRestrictions | BivarianceConstraint<(state: CropperState, settings: this) => AreaSizeRestrictions>; sizeRestrictions: SizeRestrictions | BivarianceConstraint<(state: CropperState, settings: this) => SizeRestrictions>; positionRestrictions: PositionRestrictions | BivarianceConstraint<(state: CropperState, settings: this) => PositionRestrictions>; aspectRatio: AspectRatio | BivarianceConstraint<(state: CropperState, settings: this) => RawAspectRatio>; } interface InitializeSettings { defaultCoordinates: DefaultCoordinates<this>; defaultVisibleArea: DefaultVisibleArea<this>; defaultTransforms?: DefaultTransforms<this>; priority?: Priority; } type BivarianceConstraint<T extends (...args: any) => any> = { method(...args: Parameters<T>): ReturnType<T>; }['method']; interface ModifierSettings { transformImage?: { adjustStencil?: boolean; }; moveCoordinates?: {}; resizeCoordinates?: {}; } interface CropperImage { src: string; revoke: boolean; transforms: Transforms; arrayBuffer: ArrayBuffer | null; width: number; height: number; } interface CropperTransitions { timingFunction: TimingFunction; duration: number; active: boolean; } type CropperInteractions = { moveCoordinates: boolean; resizeCoordinates: boolean; transformImage: { rotate: boolean; move: boolean; scale: boolean; flip: boolean; }; }; interface CropperTransitionsSettings { timingFunction?: string; duration?: number; } interface SimpleTouch { clientX: number; clientY: number; } interface PostprocessAction<Name extends string = string> { name?: Name; immediately?: boolean; transitions?: boolean; interaction?: boolean; } type PostprocessFunction<Settings = CoreSettings, State = CropperState> = BivarianceConstraint<(state: State, settings: Settings, action: PostprocessAction) => State>; type Nullable<T> = T | null | undefined; type DebouncedFunction<T extends (...args: any[]) => any> = T & { clear: () => void; }; export { TimingFunction, Coordinates, VisibleArea, Limits, SizeRestrictions, AreaSizeRestrictions, PositionRestrictions, AreaPositionRestrictions, ResizeDirections, MoveDirections, Point, Size, ImageSize, Boundary, Intersections, AspectRatio, ResizeAnchor, RawAspectRatio, Diff, Position, ImageRestriction, Priority, PositionDirection, HorizontalDirection, VerticalDirection, MainDirections, HorizontalCardinalDirection, VerticalCardinalDirection, CardinalDirection, OrdinalDirection, Scale, Rotate, Flip, Transforms, PartialTransforms, ImageTransform, CoordinatesTransform, CropperState, InitializedCropperState, BoundarySizeAlgorithm, DefaultSize, DefaultPosition, DefaultVisibleArea, DefaultCoordinates, DefaultTransforms, CoreSettings, InitializeSettings, BivarianceConstraint, ModifierSettings, CropperImage, CropperTransitions, CropperInteractions, CropperTransitionsSettings, SimpleTouch, PostprocessAction, PostprocessFunction, Nullable, DebouncedFunction };