diff --git a/types/colorthief/colorthief-tests.ts b/types/colorthief/colorthief-tests.ts index eaff24798b465d..96a5641e4e712e 100644 --- a/types/colorthief/colorthief-tests.ts +++ b/types/colorthief/colorthief-tests.ts @@ -4,6 +4,17 @@ // Import the ColorThief class for testing import ColorThief from "colorthief"; +// Node.js version tests +const imgPath = "rainbow.png"; + +// Test getColor method +const dominantColorNode: Promise = ColorThief.getColor(imgPath); +const dominantColorWithQualityNode: Promise = ColorThief.getColor(imgPath, 5); + +// Test getPalette method +const paletteNode: Promise = ColorThief.getPalette(imgPath); +const paletteWithOptionsNode: Promise = ColorThief.getPalette(imgPath, 8, 5); + // Browser version tests const colorThief = new ColorThief(); const img = document.createElement("img"); diff --git a/types/colorthief/index.d.ts b/types/colorthief/index.d.ts index 48bc62cad1dc04..b581ae20ec01ec 100644 --- a/types/colorthief/index.d.ts +++ b/types/colorthief/index.d.ts @@ -1,4 +1,5 @@ /// +/// export = ColorThief; export as namespace ColorThief; @@ -41,6 +42,38 @@ declare namespace ColorThief { * Color Thief - Extract dominant colors from images */ declare class ColorThief { + // -------------------------------------------------------- + // Node.js usage (Static methods returning Promises) + // -------------------------------------------------------- + + /** + * Extract the dominant color from an image (Node.js) + * @param sourceImage - Path to the image file, or Buffer containing image + * @param quality - Quality/speed trade-off (1 = highest quality, 10 = default) + * @returns Promise resolving to RGB color array [r, g, b] where values are 0-255 + */ + static getColor( + sourceImage: Buffer | Uint8Array | ArrayBuffer | string, + quality?: number, + ): Promise; + + /** + * Extract a palette of colors from an image (Node.js) + * @param sourceImage - Path to the image file, or Buffer containing image + * @param colorCount - Number of colors to extract (2-20, default: 10) + * @param quality - Quality/speed trade-off (1 = highest quality, 10 = default) + * @returns Promise resolving to Array of RGB color arrays [[r, g, b], ...] where values are 0-255 + */ + static getPalette( + sourceImage: Buffer | Uint8Array | ArrayBuffer | string, + colorCount?: number, + quality?: number, + ): Promise; + + // -------------------------------------------------------- + // Browser usage (Instance methods) + // -------------------------------------------------------- + /** * Extract the dominant color from an image * @param sourceImage - HTML image element diff --git a/types/colorthief/package.json b/types/colorthief/package.json index f5dc66b2027c43..5174f8a740e00f 100644 --- a/types/colorthief/package.json +++ b/types/colorthief/package.json @@ -5,6 +5,9 @@ "projects": [ "https://github.com/lokesh/color-thief" ], + "dependencies": { + "@types/node": "*" + }, "devDependencies": { "@types/colorthief": "workspace:." },