diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..a46d1ff --- /dev/null +++ b/index.d.ts @@ -0,0 +1,59 @@ +// Type definitions for Croppr.js +// 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) + + /** Gets the value of the crop region */ + getValue(mode?: 'real' | 'ratio' | 'raw'): Croppr.CropprValue + + /** Destroys the Croppr instance */ + destroy(): void + + /** Moves the crop region to a specified coordinate */ + moveTo(x: number, y: number): Croppr + + /** Resizes the crop region to a specified width and height */ + resizeTo(width: number, height: number, origin?: Array): Croppr + + /** Scale the crop region by a factor */ + scaleBy(factor: number, origin?: Array): Croppr + + /** Resets the crop region to the initial settings */ + reset(): Croppr +} + +/*~ Declare type modules */ +declare namespace Croppr { + + export interface CropprOptions { + aspectRatio?: number; + maxSize?: [number, number, '%' | 'px']; + minSize?: [number, number, '%' | 'px']; + startSize?: [number, number, '%' | 'px']; + onCropStart?(data: Croppr.CropprValue): void; + onCropMove?(data: Croppr.CropprValue): void; + onCropEnd?(data: Croppr.CropprValue): void; + onInitialize?(instance: Croppr): void; + returnMode?: 'real' | 'ratio' | 'raw'; + } + + export interface CropprValue { + x: number; + y: number; + width: number; + height: number + } + +} diff --git a/package.json b/package.json index 250358c..4d9a924 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "2.1.0", "description": "A vanilla JavaScript image cropper that's lightweight, awesome, and has absolutely zero dependencies.", "main": "dist/croppr.js", + "typings": "./index.d.ts", "scripts": { "test": "mocha", "build": "rollup --config rollup.config.dev.js & cp src/css/croppr.css dist/croppr.css",