mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
fix(pica): correct module definition (#44858)
- support for global usage - support for module usage ref: 41210 https://github.com/DefinitelyTyped/DefinitelyTyped/pull/41210#issuecomment-630108296 Thanks!
This commit is contained in:
parent
1ed325dc65
commit
163dc8d7e5
176
types/pica/index.d.ts
vendored
176
types/pica/index.d.ts
vendored
@ -1,95 +1,101 @@
|
||||
// Type definitions for pica 5.1
|
||||
// Project: https://github.com/nodeca/pica
|
||||
// Definitions by: Hamit YILMAZ <https://github.com/hmtylmz>
|
||||
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare class Pica {
|
||||
constructor(config?: PicaOptions);
|
||||
/**
|
||||
* Resize image from one canvas (or image) to another.
|
||||
* Sizes are taken from source and destination objects.
|
||||
* Result is Promise, resolved with to on success.
|
||||
* (!) If you need to process multiple images, do it sequentially to optimize CPU & memory use.
|
||||
* Pica already knows how to use multiple cores (if browser allows).
|
||||
*/
|
||||
resize(
|
||||
from: HTMLCanvasElement | HTMLImageElement | File | Blob,
|
||||
to: HTMLCanvasElement,
|
||||
options?: PicaResizeOptions
|
||||
): Promise<HTMLCanvasElement>;
|
||||
declare namespace pica {
|
||||
interface PicaOptions {
|
||||
// tile width/height.
|
||||
// Images are processed by regions, to restrict peak memory use. Default 1024.
|
||||
tile?: number;
|
||||
// list of features to use.
|
||||
// Default is [ 'js', 'wasm', 'ww' ]. Can be [ 'js', 'wasm', 'cib', 'ww' ] or [ 'all' ].
|
||||
// Note, resize via createImageBitmap() ('cib') disabled by default due problems with quality.
|
||||
features?: string[];
|
||||
// cache timeout, ms. Webworkers create is not fast.
|
||||
// This option allow reuse webworkers effectively. Default 2000.
|
||||
idle?: number;
|
||||
// max webworkers pool size. Default is autodetected CPU count, but not more than 4.
|
||||
concurrency?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method, similar to canvas.toBlob(), but with promise interface & polyfill for old browsers.
|
||||
*/
|
||||
toBlob(
|
||||
canvas: HTMLCanvasElement,
|
||||
mimeType: string,
|
||||
quality?: number
|
||||
): Promise<Blob>;
|
||||
interface PicaResizeOptions {
|
||||
// 0..3. Default = 3 (lanczos, win=3).
|
||||
quality?: number;
|
||||
// use alpha channel. Default = false.
|
||||
alpha?: boolean;
|
||||
// >=0, in percents. Default = 0 (off). Usually between 50 to 100 is good.
|
||||
unsharpAmount?: number;
|
||||
// 0.5..2.0. By default it's not set. Radius of Gaussian blur.
|
||||
// If it is less than 0.5, Unsharp Mask is off. Big values are clamped to 2.0.
|
||||
unsharpRadius?: number;
|
||||
// 0..255. Default = 0. Threshold for applying unsharp mask.
|
||||
unsharpThreshold?: number;
|
||||
// Promise instance. If defined, current operation will be terminated on rejection.
|
||||
cancelToken?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Supplementary method, not recommended for direct use.
|
||||
* Resize Uint8Array with raw RGBA bitmap (don't confuse with jpeg / png / ... binaries).
|
||||
* It does not use tiles & webworkers. Left for special cases when you really need to process raw binary data (for example, if you decode jpeg files "manually").
|
||||
*/
|
||||
resizeBuffer(
|
||||
options: PicaResizeBufferOptions
|
||||
): Promise<number[]>;
|
||||
interface PicaResizeBufferOptions {
|
||||
// Uint8Array with source data.
|
||||
src: number[];
|
||||
// src image width.
|
||||
width: number;
|
||||
// src image height.
|
||||
height: number;
|
||||
// output width, >=0, in pixels.
|
||||
toWidth: number;
|
||||
// output height, >=0, in pixels.
|
||||
toHeigh: number;
|
||||
// 0..3. Default = 3 (lanczos, win=3).
|
||||
quality?: number;
|
||||
// use alpha channel. Default = false.
|
||||
alpha?: boolean;
|
||||
// >=0, in percents. Default = 0 (off). Usually between 50 to 100 is good.
|
||||
unsharpAmount?: number;
|
||||
// 0.5..2.0. Radius of Gaussian blur.
|
||||
// If it is less than 0.5, Unsharp Mask is off. Big values are clamped to 2.0.
|
||||
unsharpRadius?: number;
|
||||
// 0..255. Default = 0. Threshold for applying unsharp mask.
|
||||
unsharpThreshold?: number;
|
||||
// Optional. Output buffer to write data, if you don't wish pica to create new one.
|
||||
dest?: string;
|
||||
}
|
||||
|
||||
interface Pica {
|
||||
/**
|
||||
* Resize image from one canvas (or image) to another.
|
||||
* Sizes are taken from source and destination objects.
|
||||
* Result is Promise, resolved with to on success.
|
||||
* (!) If you need to process multiple images, do it sequentially to optimize CPU & memory use.
|
||||
* Pica already knows how to use multiple cores (if browser allows).
|
||||
*/
|
||||
resize(
|
||||
from: HTMLCanvasElement | HTMLImageElement | File | Blob,
|
||||
to: HTMLCanvasElement,
|
||||
options?: PicaResizeOptions,
|
||||
): Promise<HTMLCanvasElement>;
|
||||
|
||||
/**
|
||||
* Convenience method, similar to canvas.toBlob(), but with promise interface & polyfill for old browsers.
|
||||
*/
|
||||
toBlob(canvas: HTMLCanvasElement, mimeType: string, quality?: number): Promise<Blob>;
|
||||
|
||||
/**
|
||||
* Supplementary method, not recommended for direct use.
|
||||
* Resize Uint8Array with raw RGBA bitmap (don't confuse with jpeg / png / ... binaries).
|
||||
* It does not use tiles & webworkers. Left for special cases when you really need to process raw binary data (for example, if you decode jpeg files "manually").
|
||||
*/
|
||||
resizeBuffer(options: PicaResizeBufferOptions): Promise<number[]>;
|
||||
}
|
||||
|
||||
interface PicaStatic {
|
||||
new (config?: PicaOptions): Pica;
|
||||
(config?: PicaOptions): Pica;
|
||||
}
|
||||
}
|
||||
|
||||
interface PicaOptions {
|
||||
// tile width/height.
|
||||
// Images are processed by regions, to restrict peak memory use. Default 1024.
|
||||
tile?: number;
|
||||
// list of features to use.
|
||||
// Default is [ 'js', 'wasm', 'ww' ]. Can be [ 'js', 'wasm', 'cib', 'ww' ] or [ 'all' ].
|
||||
// Note, resize via createImageBitmap() ('cib') disabled by default due problems with quality.
|
||||
features?: string[];
|
||||
// cache timeout, ms. Webworkers create is not fast.
|
||||
// This option allow reuse webworkers effectively. Default 2000.
|
||||
idle?: number;
|
||||
// max webworkers pool size. Default is autodetected CPU count, but not more than 4.
|
||||
concurrency?: number;
|
||||
}
|
||||
declare const pica: pica.PicaStatic;
|
||||
export as namespace pica;
|
||||
|
||||
interface PicaResizeOptions {
|
||||
// 0..3. Default = 3 (lanczos, win=3).
|
||||
quality?: number;
|
||||
// use alpha channel. Default = false.
|
||||
alpha?: boolean;
|
||||
// >=0, in percents. Default = 0 (off). Usually between 50 to 100 is good.
|
||||
unsharpAmount?: number;
|
||||
// 0.5..2.0. By default it's not set. Radius of Gaussian blur.
|
||||
// If it is less than 0.5, Unsharp Mask is off. Big values are clamped to 2.0.
|
||||
unsharpRadius?: number;
|
||||
// 0..255. Default = 0. Threshold for applying unsharp mask.
|
||||
unsharpThreshold?: number;
|
||||
// Promise instance. If defined, current operation will be terminated on rejection.
|
||||
cancelToken?: string;
|
||||
}
|
||||
|
||||
interface PicaResizeBufferOptions {
|
||||
// Uint8Array with source data.
|
||||
src: number[];
|
||||
// src image width.
|
||||
width: number;
|
||||
// src image height.
|
||||
height: number;
|
||||
// output width, >=0, in pixels.
|
||||
toWidth: number;
|
||||
// output height, >=0, in pixels.
|
||||
toHeigh: number;
|
||||
// 0..3. Default = 3 (lanczos, win=3).
|
||||
quality?: number;
|
||||
// use alpha channel. Default = false.
|
||||
alpha?: boolean;
|
||||
// >=0, in percents. Default = 0 (off). Usually between 50 to 100 is good.
|
||||
unsharpAmount?: number;
|
||||
// 0.5..2.0. Radius of Gaussian blur.
|
||||
// If it is less than 0.5, Unsharp Mask is off. Big values are clamped to 2.0.
|
||||
unsharpRadius?: number;
|
||||
// 0..255. Default = 0. Threshold for applying unsharp mask.
|
||||
unsharpThreshold?: number;
|
||||
// Optional. Output buffer to write data, if you don't wish pica to create new one.
|
||||
dest?: string;
|
||||
}
|
||||
export = pica;
|
||||
|
||||
45
types/pica/test/pica-tests.cjs.ts
Normal file
45
types/pica/test/pica-tests.cjs.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import pica = require('pica');
|
||||
|
||||
const resizer = pica();
|
||||
|
||||
const picaOptions = { features: ['js', 'wasm', 'ww', 'cib'] };
|
||||
const resizerWithOptions: pica.Pica = pica(picaOptions);
|
||||
|
||||
const image: HTMLImageElement = document.createElement('img');
|
||||
image.width = 100;
|
||||
image.height = 100;
|
||||
|
||||
const canvas: HTMLCanvasElement = document.createElement('canvas');
|
||||
canvas.width = 100;
|
||||
canvas.height = 100;
|
||||
|
||||
// Resize image
|
||||
resizer.resize(image, canvas);
|
||||
resizerWithOptions.resize(image, canvas);
|
||||
|
||||
// Resize image with options
|
||||
const resizeOptions: pica.PicaResizeOptions = {
|
||||
quality: 9,
|
||||
};
|
||||
resizer.resize(image, canvas, resizeOptions);
|
||||
resizerWithOptions.resize(image, canvas, resizeOptions);
|
||||
|
||||
// Blob canvas
|
||||
resizer.toBlob(canvas, 'image/png');
|
||||
resizerWithOptions.toBlob(canvas, 'image/png');
|
||||
|
||||
// Blob canvas with quality
|
||||
resizer.toBlob(canvas, 'image/png', 9);
|
||||
resizerWithOptions.toBlob(canvas, 'image/png', 9);
|
||||
|
||||
// Resize buffer
|
||||
const resizeBufferSrc: number[] = [21, 31];
|
||||
const resizeBufferOptions: pica.PicaResizeBufferOptions = {
|
||||
src: resizeBufferSrc,
|
||||
width: 100,
|
||||
height: 100,
|
||||
toWidth: 50,
|
||||
toHeigh: 50,
|
||||
};
|
||||
resizer.resizeBuffer(resizeBufferOptions);
|
||||
resizerWithOptions.resizeBuffer(resizeBufferOptions);
|
||||
@ -1,13 +1,12 @@
|
||||
let resizer: Pica = new Pica();
|
||||
const resizer = pica();
|
||||
const picaOptions: pica.PicaOptions = { features: ['js', 'wasm', 'ww', 'cib'] };
|
||||
const resizerWithOptions: pica.Pica = pica(picaOptions);
|
||||
|
||||
let picaOptions: PicaOptions = { features: ['js', 'wasm', 'ww', 'cib'] };
|
||||
let resizerWithOptions: Pica = new Pica(picaOptions);
|
||||
|
||||
let image: HTMLImageElement = document.createElement('img');
|
||||
const image: HTMLImageElement = document.createElement('img');
|
||||
image.width = 100;
|
||||
image.height = 100;
|
||||
|
||||
let canvas: HTMLCanvasElement = document.createElement('canvas');
|
||||
const canvas: HTMLCanvasElement = document.createElement('canvas');
|
||||
canvas.width = 100;
|
||||
canvas.height = 100;
|
||||
|
||||
@ -16,8 +15,8 @@ resizer.resize(image, canvas);
|
||||
resizerWithOptions.resize(image, canvas);
|
||||
|
||||
// Resize image with options
|
||||
let resizeOptions: PicaResizeOptions = {
|
||||
quality: 9
|
||||
const resizeOptions: pica.PicaResizeOptions = {
|
||||
quality: 9,
|
||||
};
|
||||
resizer.resize(image, canvas, resizeOptions);
|
||||
resizerWithOptions.resize(image, canvas, resizeOptions);
|
||||
@ -31,8 +30,8 @@ resizer.toBlob(canvas, 'image/png', 9);
|
||||
resizerWithOptions.toBlob(canvas, 'image/png', 9);
|
||||
|
||||
// Resize buffer
|
||||
let resizeBufferSrc: number[] = [21, 31];
|
||||
let resizeBufferOptions: PicaResizeBufferOptions = {
|
||||
const resizeBufferSrc: number[] = [21, 31];
|
||||
const resizeBufferOptions: pica.PicaResizeBufferOptions = {
|
||||
src: resizeBufferSrc,
|
||||
width: 100,
|
||||
height: 100,
|
||||
@ -19,6 +19,7 @@
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"pica-tests.ts"
|
||||
"test/pica-tests.cjs.ts",
|
||||
"test/pica-tests.global.ts"
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user