Skip to content

Commit

Permalink
xyz color space (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnuttandrew authored Sep 30, 2024
1 parent 5490dce commit 1b39ceb
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/palette/src/Color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,32 @@ class JZAZBZ extends Color {
}
}

class XYZ extends Color {
static name = "XYZ";
static channelNames = ["x", "y", "z"];
channels = { x: 0, y: 0, z: 0 };
spaceName = "xyz-d65" as const;
// static domains = { x: [0, 9504.7], y: [0, 10000], z: [0, 10888.3] } as Domain;
// static domains = { x: [0, 100], y: [0, 100], z: [0, 100] } as Domain;
static domains = { x: [0, 1.1], y: [1.1, 0], z: [0, 1.1] } as Domain;
static stepSize: Channels = [0.01, 0.01, 0.01];
static dimensionToChannel = { x: "x", y: "z", z: "y" };
static description =
"The fundamental CIE color space, derived from color-matching experiments on human vision. All other color spaces can be converted to XYZ.";

toString(): string {
const [x, y, z] = Object.values(this.channels).map((x) =>
isNaN(x) ? 0 : x
);
return `color(--xyz-d65 ${x} ${y} ${z})`;
}
toPrettyString(): string {
const [x, y, z] = this.prettyChannels();
// return `xyz(${x} ${y} ${z})`;
return `color(--xyz-d65 ${x} ${y} ${z})`;
}
}

class HCT extends Color {
static name = "HCT";
static channelNames = ["h", "c", "t"];
Expand Down Expand Up @@ -561,5 +587,6 @@ export const ColorSpaceDirectory = {
rgb: RGB,
// srgb: RGB,
srgb: SRGB,
"xyz-d65": XYZ,
};
type ColorSpace = keyof typeof ColorSpaceDirectory;

0 comments on commit 1b39ceb

Please sign in to comment.