Skip to content

Instantly share code, notes, and snippets.

@bengry
Created December 26, 2024 16:08
Show Gist options
  • Save bengry/caa2d602db5c011d12d4b54ad81f8b52 to your computer and use it in GitHub Desktop.
Save bengry/caa2d602db5c011d12d4b54ad81f8b52 to your computer and use it in GitHub Desktop.
Partial types for https://www.npmjs.com/package/@texel/color (v1.1.4)
declare module '@texel/color' {
type Coords = [number, number, number];
interface BaseColorSpace {
id: string;
base?: BaseColorSpace;
}
interface ColorSpace extends BaseColorSpace {
toBase?: (input: Coords, out?: Coords) => Coords;
fromBase?: (input: Coords, out?: Coords) => Coords;
}
type XYZColorMatrix = [
[number, number, number],
[number, number, number],
[number, number, number],
];
interface XYZColorSpace extends BaseColorSpace {
toXYZ_M: XYZColorMatrix;
fromXYZ_M: XYZColorMatrix;
toLMS_M: XYZColorMatrix;
fromLMS_M: XYZColorMatrix;
}
// srgb
declare const sRGB: ColorSpace;
export const sRGBLinear: XYZColorSpace;
// oklab
declare const OKLab: ColorSpace;
declare const OKLCH: ColorSpace;
declare const OKHSL: ColorSpace;
declare const OKHSV: ColorSpace;
function convert(
input: Coords,
fromSpace: ColorSpace,
toSpace: ColorSpace
): Coords;
function serialize(
coords: Coords,
inputSpace: ColorSpace,
outputSpace?: ColorSpace
): string;
function deserialize(colorString: string): ColorInfo;
interface ColorInfo {
id: ColorSpace['id'];
coords: Coords;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment