Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[types] Merge Color types #259

Merged
merged 3 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 64 additions & 68 deletions types/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,93 +1,89 @@
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,
contrastMichelson,
contrastWeber,
contrastLstar,
contrastDeltaPhi,
} from "../src/contrast/index";
import deltaE from "../src/deltaE";
} from "./contrast/index";
import deltaE from "./deltaE";
import {
deltaE76,
deltaECMC,
deltaE2000,
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<typeof uv>;
xy: ToColorPrototype<typeof xy>;

// contrast
contrast: ToColorPrototype<typeof contrast>;
static contrast: typeof contrast;

declare class Color extends ColorImport {
// chromaticity
uv: ToColorPrototype<typeof uv>;
xy: ToColorPrototype<typeof xy>;
// contrastMethods
contrastWCAG21: ToColorPrototype<typeof contrastWCAG21>;
contrastAPCA: ToColorPrototype<typeof contrastAPCA>;
contrastMichelson: ToColorPrototype<typeof contrastMichelson>;
contrastWeber: ToColorPrototype<typeof contrastWeber>;
contrastLstar: ToColorPrototype<typeof contrastLstar>;
contrastDeltaPhi: ToColorPrototype<typeof contrastDeltaPhi>;

// contrast
contrast: ToColorPrototype<typeof contrast>;
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<typeof contrastWCAG21>;
contrastAPCA: ToColorPrototype<typeof contrastAPCA>;
contrastMichelson: ToColorPrototype<typeof contrastMichelson>;
contrastWeber: ToColorPrototype<typeof contrastWeber>;
contrastLstar: ToColorPrototype<typeof contrastLstar>;
contrastDeltaPhi: ToColorPrototype<typeof contrastDeltaPhi>;
// deltaE
deltaE: ToColorPrototype<typeof deltaE>;
deltaE76: ToColorPrototype<typeof deltaE76>;
deltaECMC: ToColorPrototype<typeof deltaECMC>;
deltaE2000: ToColorPrototype<typeof deltaE2000>;
deltaEJz: ToColorPrototype<typeof deltaEJz>;
deltaEITP: ToColorPrototype<typeof deltaEITP>;
deltaEOK: ToColorPrototype<typeof deltaEOK>;

// deltaE
deltaE: ToColorPrototype<typeof deltaE>;
deltaE76: ToColorPrototype<typeof deltaE76>;
deltaECMC: ToColorPrototype<typeof deltaECMC>;
deltaE2000: ToColorPrototype<typeof deltaE2000>;
deltaEJz: ToColorPrototype<typeof deltaEJz>;
deltaEITP: ToColorPrototype<typeof deltaEITP>;
deltaEOK: ToColorPrototype<typeof deltaEOK>;
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<typeof mix>;
range: ToColorPrototype<typeof range>;
steps: ToColorPrototype<typeof steps>;
// interpolation
mix: ToColorPrototype<typeof mix>;
range: ToColorPrototype<typeof range>;
steps: ToColorPrototype<typeof steps>;
static mix: typeof mix;
static range: typeof range;
static steps: typeof steps;

// luminance
get luminance(): ReturnType<typeof getLuminance>;
// the definition for this set in the orignial code like it doesn't actually use the parameter?
set luminance(_: number);
// luminance
get luminance(): ReturnType<typeof getLuminance>;
// the definition for this set in the orignial code like it doesn't actually use the parameter?
set luminance(_: number);

// variations
lighten: ToColorPrototype<typeof lighten>;
darken: ToColorPrototype<typeof darken>;
// variations
lighten: ToColorPrototype<typeof lighten>;
darken: ToColorPrototype<typeof darken>;
static lighten: typeof lighten;
static darken: typeof darken;
}
}

export default Color;
10 changes: 10 additions & 0 deletions types/test/color-index.ts
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion types/test/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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