UNPKG

870 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.isContrastColorWhite = void 0;
4var tslib_1 = require("tslib");
5var color_util_1 = (0, tslib_1.__importDefault)(require("@antv/color-util"));
6// 内置的一些特殊设置
7var preset = {
8 '#5B8FF9': true,
9};
10// 根据YIQ亮度判断指定颜色取反色是不是白色
11// http://24ways.org/2010/calculating-color-contrast
12// http://www.w3.org/TR/AERT#color-contrast
13var isContrastColorWhite = function (color) {
14 var rgb = color_util_1.default.toRGB(color).toUpperCase();
15 if (preset[rgb]) {
16 return preset[rgb];
17 }
18 var _a = color_util_1.default.rgb2arr(rgb), r = _a[0], g = _a[1], b = _a[2];
19 var isDark = (r * 299 + g * 587 + b * 114) / 1000 < 128;
20 return isDark;
21};
22exports.isContrastColorWhite = isContrastColorWhite;
23//# sourceMappingURL=color.js.map
\No newline at end of file