UNPKG

3.84 kBTypeScriptView Raw
1export type Task<T> = () => Promise<T>;
2export type WorkerResult = import("./index").WorkerResult;
3export type SquooshOptions = import("./index").SquooshOptions;
4export type ImageminOptions = import("imagemin").Options;
5export type WebpackError = import("webpack").WebpackError;
6export type Uint8ArrayUtf8ByteString = (
7 array: number[] | Uint8Array,
8 start: number,
9 end: number
10) => string;
11export type StringToBytes = (string: string) => number[];
12export type MetaData = {
13 warnings: Array<Error>;
14 errors: Array<Error>;
15};
16export type SharpLib = typeof import("sharp");
17export type Sharp = import("sharp").Sharp;
18export type ResizeOptions = import("sharp").ResizeOptions & {
19 enabled?: boolean;
20};
21export type SharpEncodeOptions = {
22 avif?: import("sharp").AvifOptions | undefined;
23 gif?: import("sharp").GifOptions | undefined;
24 heif?: import("sharp").HeifOptions | undefined;
25 jpeg?: import("sharp").JpegOptions | undefined;
26 jpg?: import("sharp").JpegOptions | undefined;
27 png?: import("sharp").PngOptions | undefined;
28 webp?: import("sharp").WebpOptions | undefined;
29};
30export type SharpFormat = keyof SharpEncodeOptions;
31export type SharpOptions = {
32 resize?: ResizeOptions | undefined;
33 rotate?: number | "auto" | undefined;
34 sizeSuffix?: SizeSuffix | undefined;
35 encodeOptions?: SharpEncodeOptions | undefined;
36};
37export type SizeSuffix = (width: number, height: number) => string;
38/**
39 * @template T
40 * @typedef {() => Promise<T>} Task
41 */
42/**
43 * Run tasks with limited concurency.
44 * @template T
45 * @param {number} limit - Limit of tasks that run at once.
46 * @param {Task<T>[]} tasks - List of tasks to run.
47 * @returns {Promise<T[]>} A promise that fulfills to an array of the results
48 */
49export function throttleAll<T>(limit: number, tasks: Task<T>[]): Promise<T[]>;
50/**
51 * @param {string} url
52 * @returns {boolean}
53 */
54export function isAbsoluteURL(url: string): boolean;
55/**
56 * @template T
57 * @param {ImageminOptions} imageminConfig
58 * @returns {Promise<ImageminOptions>}
59 */
60export function imageminNormalizeConfig<T>(
61 imageminConfig: ImageminOptions
62): Promise<ImageminOptions>;
63/**
64 * @template T
65 * @param {WorkerResult} original
66 * @param {T} options
67 * @returns {Promise<WorkerResult>}
68 */
69export function imageminMinify<T>(
70 original: WorkerResult,
71 options: T
72): Promise<WorkerResult>;
73/**
74 * @template T
75 * @param {WorkerResult} original
76 * @param {T} minimizerOptions
77 * @returns {Promise<WorkerResult>}
78 */
79export function imageminGenerate<T>(
80 original: WorkerResult,
81 minimizerOptions: T
82): Promise<WorkerResult>;
83/**
84 * @template T
85 * @param {WorkerResult} original
86 * @param {T} options
87 * @returns {Promise<WorkerResult>}
88 */
89export function squooshMinify<T>(
90 original: WorkerResult,
91 options: T
92): Promise<WorkerResult>;
93export namespace squooshMinify {
94 export { squooshImagePoolSetup as setup };
95 export { squooshImagePoolTeardown as teardown };
96}
97/**
98 * @template T
99 * @param {WorkerResult} original
100 * @param {T} minifyOptions
101 * @returns {Promise<WorkerResult>}
102 */
103export function squooshGenerate<T>(
104 original: WorkerResult,
105 minifyOptions: T
106): Promise<WorkerResult>;
107export namespace squooshGenerate {
108 export { squooshImagePoolSetup as setup };
109 export { squooshImagePoolTeardown as teardown };
110}
111/**
112 * @template T
113 * @param {WorkerResult} original
114 * @param {T} options
115 * @returns {Promise<WorkerResult>}
116 */
117export function sharpMinify<T>(
118 original: WorkerResult,
119 options: T
120): Promise<WorkerResult>;
121/**
122 * @template T
123 * @param {WorkerResult} original
124 * @param {T} minimizerOptions
125 * @returns {Promise<WorkerResult>}
126 */
127export function sharpGenerate<T>(
128 original: WorkerResult,
129 minimizerOptions: T
130): Promise<WorkerResult>;
131declare function squooshImagePoolSetup(): void;
132declare function squooshImagePoolTeardown(): Promise<void>;
133export {};