[blueimp-load-image] extended type definitions for parseMetaData and blobSlice. (#37868)

* extended loadimagecallback with metadata argument.

* lint.

* extended unit test.

* cleanup test.

* polishing.

* added further type definitions for the blueimp-image-loader.

* merge.

* formatting.

* use interface instead of type definition.

* enhance export definition.
This commit is contained in:
Saeid Rezaei
2019-08-23 08:28:57 -07:00
committed by Sheetal Nandi
parent b3a8f6fd08
commit b9f18e033c
+73 -17
View File
@@ -2,12 +2,16 @@
// Project: https://github.com/blueimp/JavaScript-Load-Image
// Definitions by: Evan Kesten <https://github.com/ebk46>
// Konstantin Lukaschenko <https://github.com/KonstantinLukaschenko>
// Saeid Rezaei <https://github.com/moeinio>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
/// <reference types="node" />
export type LoadImageCallback = (image: HTMLCanvasElement | HTMLImageElement, data?: MetaData) => void;
export type ParseMetaDataCallback = (data: ImageHead) => void;
export interface Exif {
[tag: number]: number | string | string[];
}
@@ -16,18 +20,24 @@ export interface Iptc {
[tag: number]: number | string | string[];
}
export interface MetaData {
export interface ImageHead {
imageHead?: ArrayBuffer | Uint8Array;
}
export interface MetaData extends ImageHead {
originalWidth?: number;
originalHeight?: number;
imageHead?: ArrayBuffer | Uint8Array;
exif?: Exif;
iptc?: Iptc;
}
export interface BasicOptions {
maxWidth?: number; maxHeight?: number;
minWidth?: number; minHeight?: number;
contain?: boolean; cover?: boolean;
maxWidth?: number;
maxHeight?: number;
minWidth?: number;
minHeight?: number;
contain?: boolean;
cover?: boolean;
crossOrigin?: string;
noRevoke?: boolean;
}
@@ -40,27 +50,73 @@ export type AspectRatio = number;
// it automatically enables 'canvas' so in those cases,
// 'canvas' cannot be false
export interface CanvasTrueOptions {
canvas: true; sourceWidth?: number; sourceHeight?: number;
top?: number; right?: number; bottom?: number; left?: number;
pixelRatio?: number; downsamplingRatio?: number;
orientation?: Orientation; crop?: boolean;
canvas: true;
sourceWidth?: number;
sourceHeight?: number;
top?: number;
right?: number;
bottom?: number;
left?: number;
pixelRatio?: number;
downsamplingRatio?: number;
orientation?: Orientation;
crop?: boolean;
}
export interface CanvasFalseOptions {
canvas?: false;
}
export interface CanvasFalseOptions { canvas?: false; }
export type CanvasOptions = CanvasTrueOptions | CanvasFalseOptions;
// Setting 'aspectRatio' automatically enables 'crop', so setting 'crop' to
// 'false' in that case is not valid
export interface CropTrueOptions { crop?: true; aspectRatio?: AspectRatio; }
export interface CropFalseOptions { crop?: false; }
export interface CropTrueOptions {
crop?: true;
aspectRatio?: AspectRatio;
}
export interface CropFalseOptions {
crop?: false;
}
export type CropOptions = CanvasTrueOptions | CropFalseOptions;
// Setting 'orientation' automatically sets 'meta' to true
// so setting it to false is not valid in that case
export interface MetaTrueOptions { meta?: true; orientation: Orientation; }
export interface MetaFalseOptions { meta?: false; }
export interface MetaTrueOptions {
meta?: true;
orientation: Orientation;
}
export interface MetaFalseOptions {
meta?: false;
}
export type MetaOptions = MetaTrueOptions | MetaFalseOptions;
export interface ParseOptions {
// Defines the maximum number of bytes to parse.
maxMetaDataSize?: number;
// Disables creating the imageHead property.
disableImageHead?: boolean;
}
export type LoadImageOptions = BasicOptions & CanvasOptions & CropOptions & MetaOptions;
export default function loadImage(
file: File | Blob | string, callback: LoadImageCallback, options: LoadImageOptions
): HTMLImageElement | FileReader | false;
// loadImage is implemented as a callable object.
interface LoadImage {
(file: File | Blob | string, callback: LoadImageCallback, options: LoadImageOptions):
| HTMLImageElement
| FileReader
| false;
// Parses image meta data and calls the callback with the image head
parseMetaData: (
file: File | Blob | string,
callback: ParseMetaDataCallback,
options?: ParseOptions,
data?: ImageHead,
) => void;
blobSlice: (file: Blob, start?: number, end?: number) => Blob;
}
declare const loadImage: LoadImage;
export default loadImage;