Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,44 @@
// Definitions by: James Ooi https://github.com/jamesssooi
// Based on the template: https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-class-d-ts.html


/*~ Expose this module as a UMD */
export as namespace Croppr;

/*~ Specify the class constructor function */
export = Croppr;


declare class Croppr {

/** @constructor */
constructor(element: string | HTMLElement, options?: Croppr.CropprOptions, deferred?: boolean)
constructor(
element: string | HTMLElement,
options?: Croppr.CropprOptions,
deferred?: boolean
);

/** Gets the value of the crop region */
getValue(mode?: 'real' | 'ratio' | 'raw'): Croppr.CropValue
getValue(mode?: "real" | "ratio" | "raw"): Croppr.CropValue;

/** Changes the image src. */
setImage(src: string): Croppr
setImage(src: string): Croppr;

/** Destroys the Croppr instance */
destroy(): void
destroy(): void;

/** Moves the crop region to a specified coordinate */
moveTo(x: number, y: number): Croppr
moveTo(x: number, y: number): Croppr;

/** Resizes the crop region to a specified width and height */
resizeTo(width: number, height: number, origin?: Array<number>): Croppr
resizeTo(width: number, height: number, origin?: Array<number>): Croppr;

/** Scale the crop region by a factor */
scaleBy(factor: number, origin?: Array<number>): Croppr
scaleBy(factor: number, origin?: Array<number>): Croppr;

/** Resets the crop region to the initial settings */
reset(): Croppr

reset(): Croppr;
}

/*~ Declare type modules */
declare namespace Croppr {

export interface CropprOptions {
aspectRatio?: number;
maxSize?: SizeValue;
Expand All @@ -50,20 +49,19 @@ declare namespace Croppr {
onCropMove?(data: CropValue): void;
onCropEnd?(data: CropValue): void;
onInitialize?(instance: Croppr): void;
returnMode?: 'real' | 'ratio' | 'raw';
returnMode?: "real" | "ratio" | "raw";
}

export interface CropValue {
x: number;
y: number;
width: number;
height: number
height: number;
}

export interface SizeValue extends Array<string | number> {
0: number,
1: number,
2?: 'px' | '%'
export interface SizeValue extends Array<string | number | undefined> {
0: number;
1: number;
2?: "px" | "%" | undefined;
}

}