From 596e530ad678957f65c1fa5ba210b93e4d54cd80 Mon Sep 17 00:00:00 2001 From: Guillaume VARA Date: Mon, 23 Dec 2024 09:35:43 +0100 Subject: [PATCH 1/7] Standardize TypeScript exports --- index.d.ts | 103 ++++++++++++++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/index.d.ts b/index.d.ts index 570ae17..4f25ba3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,58 +1,57 @@ -export interface Options { // eslint-disable-line @typescript-eslint/consistent-type-definitions - /** - Speed `10` has 5% lower quality, but is about 8 times faster than the default. Speed `11` disables dithering and lowers compression level. - - Values: `1` (brute-force) to `11` (fastest) - - @default 3 - */ - speed?: number; +declare namespace pngquant { + type Options = { + /** + * Speed `10` has 5% lower quality, but is about 8 times faster than the default. Speed `11` disables dithering and lowers compression level. + * Values: `1` (brute-force) to `11` (fastest) + * @default 3 + */ + speed?: number; + + /** + * Remove optional metadata. + * @default false + */ + strip?: boolean; + + /** + * Instructs pngquant to use the least amount of colors required to meet or exceed the max quality. If conversion results in quality below the min quality the image won't be saved. + * Min and max are numbers in range 0 (worst) to 1 (perfect), similar to JPEG. + * Values: `[0...1, 0...1]` + * @example [0.3, 0.5] + */ + quality?: [number, number]; + + /** + * Set the dithering level using a fractional number between 0 (none) and 1 (full). + * Pass in `false` to disable dithering. + * Values: 0...1 + * @default 1 + */ + dithering?: number | boolean; + + /** + * Truncate number of least significant bits of color (per channel). + * Use this when image will be output on low-depth displays (e.g. 16-bit RGB). pngquant will make almost-opaque pixels fully opaque and will reduce amount of semi-transparent colors. + */ + posterize?: number; + + /** + * Print verbose status messages. + * @default false + */ + verbose?: boolean; + }; /** - Remove optional metadata. - - @default false - */ - strip?: boolean; - - /** - Instructs pngquant to use the least amount of colors required to meet or exceed the max quality. If conversion results in quality below the min quality the image won't be saved. - - Min and max are numbers in range 0 (worst) to 1 (perfect), similar to JPEG. - - Values: `[0...1, 0...1]` - - @example [0.3, 0.5] - */ - quality?: [number, number]; + * Buffer or stream to optimize. + */ + type Plugin = (input: Uint8Array | NodeJS.ReadableStream) => Promise; /** - Set the dithering level using a fractional number between 0 (none) and 1 (full). - - Pass in `false` to disable dithering. - - Values: 0...1 - - @default 1 - */ - dithering?: number | boolean; - - /** - Truncate number of least significant bits of color (per channel). - - Use this when image will be output on low-depth displays (e.g. 16-bit RGB). pngquant will make almost-opaque pixels fully opaque and will reduce amount of semi-transparent colors. - */ - posterize?: number; + * Imagemin plugin for pngquant. + * @returns An Imagemin plugin. + */ + function imageminPngquant(options?: Options): Plugin; } -/** -Image data to optimize. -*/ -export type Plugin = (input: Uint8Array) => Promise; - -/** -Imagemin plugin for pngquant. - -@returns An Imagemin plugin. -*/ -export default function imageminPngquant(options?: Options): Plugin; +export = pngquant; From ca179267d4fe4927c44ae36645ac65a9e74785f7 Mon Sep 17 00:00:00 2001 From: Guillaume VARA Date: Mon, 23 Dec 2024 09:36:23 +0100 Subject: [PATCH 2/7] 11.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a57c3b3..838b145 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "imagemin-pngquant", - "version": "10.0.0", + "version": "11.0.0", "description": "Imagemin plugin for `pngquant`", "license": "MIT", "repository": "imagemin/imagemin-pngquant", From 7d9182699953200a909a8f7353f24113d5b811f5 Mon Sep 17 00:00:00 2001 From: Guillaume VARA Date: Mon, 23 Dec 2024 09:49:27 +0100 Subject: [PATCH 3/7] Fix example --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 879f2df..e1a434f 100644 --- a/readme.md +++ b/readme.md @@ -10,7 +10,7 @@ npm install imagemin-pngquant ### Prerequisites -> **Linux** machines must have the following packages prior to install: `libpng-dev libimagequant-dev` +> **Linux** machines must have the following packages prior to install: `libpng-dev libimagequant-dev` ```sh sudo apt-get -y install libpng-dev libimagequant-dev @@ -20,7 +20,7 @@ sudo apt-get -y install libpng-dev libimagequant-dev ```js import imagemin from 'imagemin'; -import imageminPngquant from 'imagemin-pngquant'; +import { imageminPngquant } from 'imagemin-pngquant'; await imagemin(['images/*.png'], { destination: 'build/images', From 572e72d701d7826917d5896b86680b106ee194d4 Mon Sep 17 00:00:00 2001 From: Guillaume VARA Date: Mon, 23 Dec 2024 10:04:20 +0100 Subject: [PATCH 4/7] cleaner --- index.d.ts | 99 +++++++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/index.d.ts b/index.d.ts index 4f25ba3..535eab4 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,57 +1,56 @@ -declare namespace pngquant { - type Options = { - /** - * Speed `10` has 5% lower quality, but is about 8 times faster than the default. Speed `11` disables dithering and lowers compression level. - * Values: `1` (brute-force) to `11` (fastest) - * @default 3 - */ - speed?: number; - - /** - * Remove optional metadata. - * @default false - */ - strip?: boolean; - - /** - * Instructs pngquant to use the least amount of colors required to meet or exceed the max quality. If conversion results in quality below the min quality the image won't be saved. - * Min and max are numbers in range 0 (worst) to 1 (perfect), similar to JPEG. - * Values: `[0...1, 0...1]` - * @example [0.3, 0.5] - */ - quality?: [number, number]; - - /** - * Set the dithering level using a fractional number between 0 (none) and 1 (full). - * Pass in `false` to disable dithering. - * Values: 0...1 - * @default 1 - */ - dithering?: number | boolean; - - /** - * Truncate number of least significant bits of color (per channel). - * Use this when image will be output on low-depth displays (e.g. 16-bit RGB). pngquant will make almost-opaque pixels fully opaque and will reduce amount of semi-transparent colors. - */ - posterize?: number; - - /** - * Print verbose status messages. - * @default false - */ - verbose?: boolean; - }; +type Options = { + /** + * Speed `10` has 5% lower quality, but is about 8 times faster than the default. Speed `11` disables dithering and lowers compression level. + * Values: `1` (brute-force) to `11` (fastest) + * @default 3 + */ + speed?: number; + + /** + * Remove optional metadata. + * @default false + */ + strip?: boolean; /** - * Buffer or stream to optimize. + * Instructs pngquant to use the least amount of colors required to meet or exceed the max quality. If conversion results in quality below the min quality the image won't be saved. + * Min and max are numbers in range 0 (worst) to 1 (perfect), similar to JPEG. + * Values: `[0...1, 0...1]` + * @example [0.3, 0.5] */ - type Plugin = (input: Uint8Array | NodeJS.ReadableStream) => Promise; + quality?: [number, number]; /** - * Imagemin plugin for pngquant. - * @returns An Imagemin plugin. + * Set the dithering level using a fractional number between 0 (none) and 1 (full). + * Pass in `false` to disable dithering. + * Values: 0...1 + * @default 1 */ - function imageminPngquant(options?: Options): Plugin; -} + dithering?: number | boolean; -export = pngquant; + /** + * Truncate number of least significant bits of color (per channel). + * Use this when image will be output on low-depth displays (e.g. 16-bit RGB). pngquant will make almost-opaque pixels fully opaque and will reduce amount of semi-transparent colors. + */ + posterize?: number; + + /** + * Print verbose status messages. + * @default false + */ + verbose?: boolean; +}; + +/** + * Buffer or stream to optimize. + * @todo Replace banned type Buffer with Uint8Array (@typescript-eslint/ban-types - https://sindresorhus.com/blog/goodbye-nodejs-buffer) + */ +type Plugin = (input: Buffer | NodeJS.ReadableStream) => Promise; + +/** + * Imagemin plugin for pngquant. + * @returns An Imagemin plugin. + */ +declare function imageminPngquant(options?: Options): Plugin; + +export { type Options, type Plugin, imageminPngquant }; From 45b786cc7ed3858d726ee1616bc263c4586d0763 Mon Sep 17 00:00:00 2001 From: Guillaume VARA Date: Mon, 23 Dec 2024 10:05:25 +0100 Subject: [PATCH 5/7] comply to lint rules --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 535eab4..680137a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -53,4 +53,4 @@ type Plugin = (input: Buffer | NodeJS.ReadableStream) => Promise; */ declare function imageminPngquant(options?: Options): Plugin; -export { type Options, type Plugin, imageminPngquant }; +export {type Options, type Plugin, imageminPngquant}; From 3fc0329cc6be54e255963f59e4b3f8bc90c2a68e Mon Sep 17 00:00:00 2001 From: Guillaume VARA Date: Mon, 23 Dec 2024 10:46:29 +0100 Subject: [PATCH 6/7] add peer Dependency to imagemin --- index.d.ts | 4 +++- package.json | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 680137a..1ee3e41 100644 --- a/index.d.ts +++ b/index.d.ts @@ -43,7 +43,9 @@ type Options = { /** * Buffer or stream to optimize. - * @todo Replace banned type Buffer with Uint8Array (@typescript-eslint/ban-types - https://sindresorhus.com/blog/goodbye-nodejs-buffer) + * @info Banned type Buffer has been replaced in Imagemin >=8.0.1 with Uint8Array, must stick to it. + * @see https://sindresorhus.com/blog/goodbye-nodejs-buffer [@typescript-eslint/ban-types] + * @see https://github.com/imagemin/imagemin/compare/v8.0.1...main */ type Plugin = (input: Buffer | NodeJS.ReadableStream) => Promise; diff --git a/package.json b/package.json index 838b145..a6e9356 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,9 @@ "pngquant-bin": "^9.0.0", "uint8array-extras": "^1.1.0" }, + "peerDependencies": { + "imagemin": "^8.0.1" + }, "devDependencies": { "@types/node": "^20.12.10", "ava": "^6.1.3", From 839df453f0da5e163496d728be77b62189a15777 Mon Sep 17 00:00:00 2001 From: Guillaume VARA Date: Mon, 23 Dec 2024 10:47:16 +0100 Subject: [PATCH 7/7] turn Buffer into Uint8Array to align with Imagemin >= 8.0.1 --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 1ee3e41..5d02775 100644 --- a/index.d.ts +++ b/index.d.ts @@ -47,7 +47,7 @@ type Options = { * @see https://sindresorhus.com/blog/goodbye-nodejs-buffer [@typescript-eslint/ban-types] * @see https://github.com/imagemin/imagemin/compare/v8.0.1...main */ -type Plugin = (input: Buffer | NodeJS.ReadableStream) => Promise; +type Plugin = (input: Uint8Array | NodeJS.ReadableStream) => Promise; /** * Imagemin plugin for pngquant.