Skip to content

Commit 01f2b59

Browse files
committed
Color improvements and add OKLab
1 parent 0d8ae25 commit 01f2b59

40 files changed

Lines changed: 5401 additions & 3149 deletions

bench/baselines/node24-linux-x64-intel-core-i9-9820x-3-30ghz.json

Lines changed: 3394 additions & 2764 deletions
Large diffs are not rendered by default.

bench/suites/color.bench.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@ export default defineSuite("color", (b, { Pts, fx }) => {
8686
sink(acc);
8787
},
8888
});
89+
90+
// The normalized flags take a different path (denormalize on the way
91+
// in, map through Color.ranges on the way out), so measure it too.
92+
b.case(`Color.${name} (normalized)`, {
93+
batch: N,
94+
setupOnce: () =>
95+
fx
96+
.colors(`color:${name}:normalized`, N, sourceMode)
97+
.map((c) => c.$normalize()),
98+
run: (source) => {
99+
let acc = 0;
100+
for (let i = 0; i < N; i++)
101+
acc += Color[name](source[i], true, true)[0];
102+
sink(acc);
103+
},
104+
});
89105
}
90106

91107
b.case("Color.toMode (no conversion)", {

dist/index.d.mts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ type CanvasSpaceOptions = {
139139
offscreen?: boolean;
140140
pixelDensity?: number;
141141
};
142-
type ColorType = "rgb" | "hsl" | "hsb" | "lab" | "lch" | "luv" | "xyz";
142+
type ColorType = "rgb" | "hsl" | "hsb" | "lab" | "lch" | "luv" | "xyz" | "oklab" | "oklch";
143143
type DelaunayShape = {
144144
i: number;
145145
j: number;
@@ -969,11 +969,15 @@ declare class Color extends Pt {
969969
static lch(...args: any[]): Color;
970970
static luv(...args: any[]): Color;
971971
static xyz(...args: any[]): Color;
972+
static oklab(...args: any[]): Color;
973+
static oklch(...args: any[]): Color;
972974
static maxValues(mode: string): Pt;
973975
get hex(): string;
974976
get rgb(): string;
975977
get rgba(): string;
976978
clone(): Color;
979+
private static _denorm;
980+
private static _normOut;
977981
toMode(mode: ColorType, convert?: boolean): this;
978982
get mode(): ColorType;
979983
get r(): number;
@@ -1021,6 +1025,12 @@ declare class Color extends Pt {
10211025
static LUVtoXYZ(luv: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
10221026
static LABtoLCH(lab: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
10231027
static LCHtoLAB(lch: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
1028+
static RGBtoOKLAB(rgb: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
1029+
static OKLABtoRGB(oklab: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
1030+
static RGBtoOKLCH(rgb: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
1031+
static OKLCHtoRGB(oklch: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
1032+
static OKLABtoOKLCH(oklab: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
1033+
static OKLCHtoOKLAB(oklch: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
10241034
}
10251035
//#endregion
10261036
//#region src/Util.d.ts

dist/index.d.mts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ type CanvasSpaceOptions = {
139139
offscreen?: boolean;
140140
pixelDensity?: number;
141141
};
142-
type ColorType = "rgb" | "hsl" | "hsb" | "lab" | "lch" | "luv" | "xyz";
142+
type ColorType = "rgb" | "hsl" | "hsb" | "lab" | "lch" | "luv" | "xyz" | "oklab" | "oklch";
143143
type DelaunayShape = {
144144
i: number;
145145
j: number;
@@ -969,11 +969,15 @@ declare class Color extends Pt {
969969
static lch(...args: any[]): Color;
970970
static luv(...args: any[]): Color;
971971
static xyz(...args: any[]): Color;
972+
static oklab(...args: any[]): Color;
973+
static oklch(...args: any[]): Color;
972974
static maxValues(mode: string): Pt;
973975
get hex(): string;
974976
get rgb(): string;
975977
get rgba(): string;
976978
clone(): Color;
979+
private static _denorm;
980+
private static _normOut;
977981
toMode(mode: ColorType, convert?: boolean): this;
978982
get mode(): ColorType;
979983
get r(): number;
@@ -1021,6 +1025,12 @@ declare class Color extends Pt {
10211025
static LUVtoXYZ(luv: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
10221026
static LABtoLCH(lab: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
10231027
static LCHtoLAB(lch: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
1028+
static RGBtoOKLAB(rgb: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
1029+
static OKLABtoRGB(oklab: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
1030+
static RGBtoOKLCH(rgb: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
1031+
static OKLCHtoRGB(oklch: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
1032+
static OKLABtoOKLCH(oklab: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
1033+
static OKLCHtoOKLAB(oklch: Color, normalizedInput?: boolean, normalizedOutput?: boolean): Color;
10241034
}
10251035
//#endregion
10261036
//#region src/Util.d.ts

dist/index.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)