iiif-processor
Version:
IIIF 2.1 & 3.0 Image API modules for NodeJS
93 lines (90 loc) • 2.19 kB
TypeScript
type BoundingBox = {
left: number;
top: number;
width: number;
height: number;
};
type Dimensions = {
width: number;
height: number;
};
type Format = 'jpg' | 'jpeg' | 'tif' | 'tiff' | 'png' | 'webp';
type IIIFSpec = {
id: string;
info?: boolean;
region?: string;
size?: string;
rotation?: string;
quality?: string;
format?: string;
density?: number;
};
type MaxDimensions = {
width?: number;
height?: number;
area?: number;
};
type Quality = 'color' | 'gray' | 'bitonal' | 'default';
type ContentResult = {
type: 'content';
canonicalLink?: string;
profileLink?: string;
contentType: string;
body: Buffer | string;
};
type RedirectResult = {
type: 'redirect';
location: string;
};
type ErrorResult = {
type: 'error';
message: string;
statusCode: number;
};
type ProcessorResult = ContentResult | RedirectResult | ErrorResult;
interface Calculated {
region: BoundingBox;
size: Dimensions & {
fit?: 'fill' | 'inside';
};
rotation: {
flop: boolean;
degree: number;
};
quality: Quality;
format: {
type: Format;
density?: number;
};
fullSize: Dimensions;
}
interface CalculatorLike {
region(s: string): this;
size(s: string): this;
rotation(s: string): this;
quality(q: string): this;
format(f: string, density?: number): this;
info(): Calculated;
canonicalPath(): string;
}
type CalculatorOptions = {
max?: MaxDimensions;
};
type CalculatorCtor = {
new (dims: Dimensions, opts?: CalculatorOptions): CalculatorLike;
parsePath(path: string): IIIFSpec | null;
};
interface InfoDocInput {
id: string;
width: number;
height: number;
sizes: Dimensions[];
max?: MaxDimensions;
}
type InfoDoc = Record<string, unknown>;
interface VersionModule {
profileLink: string;
infoDoc(input: InfoDocInput): InfoDoc;
Calculator: CalculatorCtor;
}
export type { BoundingBox as B, CalculatorOptions as C, Dimensions as D, ErrorResult as E, MaxDimensions as M, ProcessorResult as P, RedirectResult as R, VersionModule as V, Calculated as a, ContentResult as b };