@eccenca/gui-elements
Version:
GUI elements based on other libraries, usable in React application, written in Typescript.
27 lines • 1.12 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.colorCalculateDistance = void 0;
const color_1 = __importDefault(require("color"));
/**
* Calculates the distance between 2 colors.
* To keep it simple the CIE76 formula is used.
* @see https://en.wikipedia.org/wiki/Color_difference#CIE76
*/
const colorCalculateDistance = ({ color1, color2 }) => {
let colorDistance = null;
try {
const lab1 = (0, color_1.default)(color1).lab();
const lab2 = (0, color_1.default)(color2).lab();
colorDistance = Math.pow((Math.pow((lab1.l() - lab2.l()), 2) + Math.pow((lab1.a() - lab2.a()), 2) + Math.pow((lab1.b() - lab2.b()), 2)), 0.5);
}
catch (error) {
// eslint-disable-next-line no-console
console.warn("Received invalid colors", { color1, color2, error });
}
return colorDistance;
};
exports.colorCalculateDistance = colorCalculateDistance;
//# sourceMappingURL=colorCalculateDistance.js.map