desaturateBasedOnSpacesWhitepoint = ( color ) => {
const whitePoint = new Color('xyz-d65', color.space.white);
const whitePointChromasticity = {
little_x: whitePoint.x / (whitePoint.x + whitePoint.y + whitePoint.z),
little_y: whitePoint.y / (whitePoint.x + whitePoint.y + whitePoint.z),
little_z: whitePoint.z / (whitePoint.x + whitePoint.y + whitePoint.z)
};
const colorY = color.to('xyz-d65').y;
const grayPointX = (colorY / whitePointChromasticity.little_y) * whitePointChromasticity.little_x;
const grayPointZ = (colorY / whitePointChromasticity.little_y) * whitePointChromasticity.little_z;
const grayPoint = new Color('xyz-d65', [
grayPointX, colorY, grayPointZ
]);
return grayPoint.to(color.space);
}