diff --git a/types/src/index.d.ts b/types/src/index.d.ts index bc083599f..25325c0fb 100644 --- a/types/src/index.d.ts +++ b/types/src/index.d.ts @@ -1,6 +1,6 @@ -import { uv, xy } from "../src/chromaticity"; -import ColorImport, { ToColorPrototype } from "../src/color"; -import contrast from "../src/contrast"; +import { uv, xy } from "./chromaticity"; +import Color from "./color"; +import contrast from "./contrast"; import { contrastWCAG21, contrastAPCA, @@ -8,8 +8,8 @@ import { contrastWeber, contrastLstar, contrastDeltaPhi, -} from "../src/contrast/index"; -import deltaE from "../src/deltaE"; +} from "./contrast/index"; +import deltaE from "./deltaE"; import { deltaE76, deltaECMC, @@ -17,77 +17,73 @@ import { deltaEJz, deltaEITP, deltaEOK, -} from "../src/deltaE/index"; -import { mix, range, steps } from "../src/interpolation"; -import { getLuminance } from "../src/luminance"; -import { lighten, darken } from "../src/variations"; +} from "./deltaE/index"; +import { mix, range, steps } from "./interpolation"; +import { getLuminance } from "./luminance"; +import { lighten, darken } from "./variations"; -declare namespace Color { - // contrast - export { contrast }; - // contrastMethods - export { - contrastWCAG21, - contrastAPCA, - contrastMichelson, - contrastWeber, - contrastLstar, - contrastDeltaPhi, - }; - // deltaE - export { - deltaE, - deltaE76, - deltaECMC, - deltaE2000, - deltaEJz, - deltaEITP, - deltaEOK, - }; - // interpolation - export { mix, range, steps }; - // variations - export { lighten, darken }; -} +// Augment existing Color object +declare module "./color" { + export default class Color { + // chromaticity + uv: ToColorPrototype; + xy: ToColorPrototype; + + // contrast + contrast: ToColorPrototype; + static contrast: typeof contrast; -declare class Color extends ColorImport { - // chromaticity - uv: ToColorPrototype; - xy: ToColorPrototype; + // contrastMethods + contrastWCAG21: ToColorPrototype; + contrastAPCA: ToColorPrototype; + contrastMichelson: ToColorPrototype; + contrastWeber: ToColorPrototype; + contrastLstar: ToColorPrototype; + contrastDeltaPhi: ToColorPrototype; - // contrast - contrast: ToColorPrototype; + static contrastWCAG21: typeof contrastWCAG21; + static contrastAPCA: typeof contrastAPCA; + static contrastMichelson: typeof contrastMichelson; + static contrastWeber: typeof contrastWeber; + static contrastLstar: typeof contrastLstar; + static contrastDeltaPhi: typeof contrastDeltaPhi; - // contrastMethods - contrastWCAG21: ToColorPrototype; - contrastAPCA: ToColorPrototype; - contrastMichelson: ToColorPrototype; - contrastWeber: ToColorPrototype; - contrastLstar: ToColorPrototype; - contrastDeltaPhi: ToColorPrototype; + // deltaE + deltaE: ToColorPrototype; + deltaE76: ToColorPrototype; + deltaECMC: ToColorPrototype; + deltaE2000: ToColorPrototype; + deltaEJz: ToColorPrototype; + deltaEITP: ToColorPrototype; + deltaEOK: ToColorPrototype; - // deltaE - deltaE: ToColorPrototype; - deltaE76: ToColorPrototype; - deltaECMC: ToColorPrototype; - deltaE2000: ToColorPrototype; - deltaEJz: ToColorPrototype; - deltaEITP: ToColorPrototype; - deltaEOK: ToColorPrototype; + static deltaE: typeof deltaE; + static deltaE76: typeof deltaE76; + static deltaECMC: typeof deltaECMC; + static deltaE2000: typeof deltaE2000; + static deltaEJz: typeof deltaEJz; + static deltaEITP: typeof deltaEITP; + static deltaEOK: typeof deltaEOK; - // interpolation - mix: ToColorPrototype; - range: ToColorPrototype; - steps: ToColorPrototype; + // interpolation + mix: ToColorPrototype; + range: ToColorPrototype; + steps: ToColorPrototype; + static mix: typeof mix; + static range: typeof range; + static steps: typeof steps; - // luminance - get luminance(): ReturnType; - // the definition for this set in the orignial code like it doesn't actually use the parameter? - set luminance(_: number); + // luminance + get luminance(): ReturnType; + // the definition for this set in the orignial code like it doesn't actually use the parameter? + set luminance(_: number); - // variations - lighten: ToColorPrototype; - darken: ToColorPrototype; + // variations + lighten: ToColorPrototype; + darken: ToColorPrototype; + static lighten: typeof lighten; + static darken: typeof darken; + } } export default Color; diff --git a/types/test/color-index.ts b/types/test/color-index.ts new file mode 100644 index 000000000..d7d651652 --- /dev/null +++ b/types/test/color-index.ts @@ -0,0 +1,10 @@ +import Color from "colorjs.io/src/index"; + +// Make sure that the module augmentation is working +const color1 = new Color("red"); +const color2 = color1.to("srgb"); +const color3: Color = color2; + +color1.contrast; +color2.contrast; +color3.contrast; diff --git a/types/test/color.ts b/types/test/color.ts index 6e29ea03f..b4b093453 100644 --- a/types/test/color.ts +++ b/types/test/color.ts @@ -19,4 +19,4 @@ color.clone(); // $ExpectType Color color.display(); color.display({ space: "srgb" }); -// Most other color methods are those defined in other files, so they aren't tested her +// Most other color methods are those defined in other files, so they aren't tested here