class ColorSurface {
#fnMaxChroma100;
constructor(fnSurface, space) {
this.fnSurface = fnSurface;
this.space = space;
this.#fnMaxChroma100 = _.memoize(
function (luminance) {
const hue = this.fnSurface(luminance);
return [0.4, 0.2, 0.6];
}
);
}
get raster() {
const fnSurface = this.fnSurface;
const toSrgb = _.flow([
colorUtils.fromPolar,
this.space.from100,
this.space.toSRgb
]);
return function (chroma, luminance) {
try {
const hue = fnSurface(luminance);
const sRgb = toSrgb([luminance, chroma, hue]);
const hex = colorUtils.inRgbGamut(sRgb)
? colorUtils.hexFromSRgb(sRgb)
: undefined;
return hex;
} catch (error) {
throw `${error} for {luminance: ${luminance}, chroma: ${chroma}}`;
}
};
}
sRgbMaxChroma100(luminance) {
return this.#fnMaxChroma100(luminance);
}
static fromHue = function (
hue,
{ lum = 50, dHue = 0, space = colorSpaces.munsell } = {}
) {
const fnSurface = function (luminance) {
return hue + dHue * (luminance - lum);
};
return new ColorSurface(fnSurface, space);
};
static fromHex = function (
hex,
{ dHue = 0, space = colorSpaces.munsell } = {}
) {
const [lum, _, hue] = _.flow(
colorUtils.hexToSRgb,
space.fromSRgb,
space.to100,
colorUtils.toPolar
)(hex);
return this.fromHue(hue, { lum: lum, dHue: 0, space: space });
};
static fromHexHex = function (
hex1,
hex2,
{ short = true, space = colorSpaces.munsell } = {}
) {
const toPolar = _.flow(
colorUtils.hexToSRgb,
space.fromSRgb,
space.to100,
colorUtils.toPolar
);
const [lum1, _1, hue1] = toPolar(hex1);
const [lum2, _2, hue2] = toPolar(hex2);
const dHue = path(hue1, hue2, { short: short });
return this.fromHue(hue1, { lum: lum1, dHue: dHue, space: space });
};
static fromHexArray(arrHex, { space = colorSpaces.munsell }) {
throw "not implemented";
}
}