@visactor/vrender-components 0.17.5-alpha.1 → 0.17.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/label/base.js +1 -1
- package/cjs/label/base.js.map +1 -1
- package/cjs/poptip/index.d.ts +2 -1
- package/cjs/poptip/index.js +9 -5
- package/cjs/poptip/index.js.map +1 -1
- package/cjs/poptip/module.d.ts +3 -0
- package/cjs/poptip/module.js +21 -0
- package/cjs/poptip/module.js.map +1 -0
- package/cjs/poptip/poptip-plugin.js +1 -1
- package/cjs/poptip/poptip-plugin.js.map +1 -1
- package/cjs/poptip/poptip.js.map +1 -1
- package/cjs/poptip/register.d.ts +0 -3
- package/cjs/poptip/register.js +3 -15
- package/cjs/poptip/register.js.map +1 -1
- package/cjs/scrollbar/module.d.ts +3 -0
- package/cjs/scrollbar/module.js +17 -0
- package/cjs/scrollbar/module.js.map +1 -0
- package/cjs/scrollbar/register.d.ts +0 -3
- package/cjs/scrollbar/register.js +3 -10
- package/cjs/scrollbar/register.js.map +1 -1
- package/cjs/util/label-smartInvert.js +5 -11
- package/cjs/util/label-smartInvert.js.map +1 -1
- package/dist/index.js +345 -551
- package/dist/index.min.js +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/label/base.js +1 -1
- package/es/label/base.js.map +1 -1
- package/es/poptip/index.d.ts +2 -1
- package/es/poptip/index.js +3 -1
- package/es/poptip/index.js.map +1 -1
- package/es/poptip/module.d.ts +3 -0
- package/es/poptip/module.js +17 -0
- package/es/poptip/module.js.map +1 -0
- package/es/poptip/poptip-plugin.js +1 -1
- package/es/poptip/poptip-plugin.js.map +1 -1
- package/es/poptip/poptip.js.map +1 -1
- package/es/poptip/register.d.ts +0 -3
- package/es/poptip/register.js +0 -17
- package/es/poptip/register.js.map +1 -1
- package/es/scrollbar/module.d.ts +3 -0
- package/es/scrollbar/module.js +12 -0
- package/es/scrollbar/module.js.map +1 -0
- package/es/scrollbar/register.d.ts +0 -3
- package/es/scrollbar/register.js +0 -12
- package/es/scrollbar/register.js.map +1 -1
- package/es/util/label-smartInvert.js +3 -9
- package/es/util/label-smartInvert.js.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/poptip/register.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"sources":["../src/poptip/register.ts"],"names":[],"mappings":";;;AACA,6CAAyC;AAEzC,mCAA+C;AAC/C,yDAAuG;AAEvG,SAAgB,mBAAmB;IACjC,IAAA,4BAAa,GAAE,CAAC;IAChB,IAAA,+BAAgB,GAAE,CAAC;IACnB,IAAA,6BAAc,GAAE,CAAC;IACjB,IAAA,2BAAY,GAAE,CAAC;AACjB,CAAC;AALD,kDAKC;AAED,SAAgB,cAAc,CAAC,kBAAoC;IACjE,IAAA,cAAK,EAAC,aAAK,CAAC,MAAM,EAAE,qBAAa,EAAE,kBAAkB,CAAC,CAAC;AACzD,CAAC;AAFD,wCAEC","file":"register.js","sourcesContent":["import { container } from '@visactor/vrender-core';\nimport { merge } from '@visactor/vutils';\nimport type { PopTipAttributes } from './type';\nimport { DEFAULT_THEME, theme } from './theme';\nimport { registerGroup, registerRect, registerSymbol, registerWrapText } from '@visactor/vrender-kits';\n\nexport function loadPoptipComponent() {\n registerGroup();\n registerWrapText();\n registerSymbol();\n registerRect();\n}\n\nexport function setPoptipTheme(defaultPoptipTheme: PopTipAttributes) {\n merge(theme.poptip, DEFAULT_THEME, defaultPoptipTheme);\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.loadScrollbar = exports.scrollbarModule = void 0;
|
|
6
|
+
|
|
7
|
+
const vrender_core_1 = require("@visactor/vrender-core"), scrollbar_plugin_1 = require("./scrollbar-plugin");
|
|
8
|
+
|
|
9
|
+
function loadScrollbar() {
|
|
10
|
+
vrender_core_1.container.load(exports.scrollbarModule);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.scrollbarModule = new vrender_core_1.ContainerModule(((bind, unbind, isBound, rebind) => {
|
|
14
|
+
isBound(scrollbar_plugin_1.ScrollBarPlugin) || (bind(scrollbar_plugin_1.ScrollBarPlugin).toSelf(),
|
|
15
|
+
bind(vrender_core_1.AutoEnablePlugins).toService(scrollbar_plugin_1.ScrollBarPlugin));
|
|
16
|
+
})), exports.loadScrollbar = loadScrollbar;
|
|
17
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/scrollbar/module.ts"],"names":[],"mappings":";;;AAAA,yDAAuF;AACvF,yDAAqD;AAExC,QAAA,eAAe,GAAG,IAAI,8BAAe,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;IACnF,IAAI,CAAC,OAAO,CAAC,kCAAe,CAAC,EAAE;QAC7B,IAAI,CAAC,kCAAe,CAAC,CAAC,MAAM,EAAE,CAAC;QAC/B,IAAI,CAAC,gCAAiB,CAAC,CAAC,SAAS,CAAC,kCAAe,CAAC,CAAC;KACpD;AACH,CAAC,CAAC,CAAC;AAEH,SAAgB,aAAa;IAC3B,wBAAS,CAAC,IAAI,CAAC,uBAAe,CAAC,CAAC;AAClC,CAAC;AAFD,sCAEC","file":"module.js","sourcesContent":["import { AutoEnablePlugins, ContainerModule, container } from '@visactor/vrender-core';\nimport { ScrollBarPlugin } from './scrollbar-plugin';\n\nexport const scrollbarModule = new ContainerModule((bind, unbind, isBound, rebind) => {\n if (!isBound(ScrollBarPlugin)) {\n bind(ScrollBarPlugin).toSelf();\n bind(AutoEnablePlugins).toService(ScrollBarPlugin);\n }\n});\n\nexport function loadScrollbar() {\n container.load(scrollbarModule);\n}\n"]}
|
|
@@ -2,20 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: !0
|
|
5
|
-
}), exports.loadScrollbarComponent =
|
|
5
|
+
}), exports.loadScrollbarComponent = void 0;
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
function loadScrollbar() {
|
|
10
|
-
vrender_core_1.container.load(exports.scrollbarModule);
|
|
11
|
-
}
|
|
7
|
+
const vrender_kits_1 = require("@visactor/vrender-kits");
|
|
12
8
|
|
|
13
9
|
function loadScrollbarComponent() {
|
|
14
10
|
(0, vrender_kits_1.registerGroup)(), (0, vrender_kits_1.registerRect)();
|
|
15
11
|
}
|
|
16
12
|
|
|
17
|
-
exports.
|
|
18
|
-
isBound(scrollbar_plugin_1.ScrollBarPlugin) || (bind(scrollbar_plugin_1.ScrollBarPlugin).toSelf(),
|
|
19
|
-
bind(vrender_core_1.AutoEnablePlugins).toService(scrollbar_plugin_1.ScrollBarPlugin));
|
|
20
|
-
})), exports.loadScrollbar = loadScrollbar, exports.loadScrollbarComponent = loadScrollbarComponent;
|
|
13
|
+
exports.loadScrollbarComponent = loadScrollbarComponent;
|
|
21
14
|
//# sourceMappingURL=register.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/scrollbar/register.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"sources":["../src/scrollbar/register.ts"],"names":[],"mappings":";;;AAAA,yDAAqE;AAErE,SAAgB,sBAAsB;IACpC,IAAA,4BAAa,GAAE,CAAC;IAChB,IAAA,2BAAY,GAAE,CAAC;AACjB,CAAC;AAHD,wDAGC","file":"register.js","sourcesContent":["import { registerGroup, registerRect } from '@visactor/vrender-kits';\n\nexport function loadScrollbarComponent() {\n registerGroup();\n registerRect();\n}\n"]}
|
|
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
}), exports.smartInvertStrategy = exports.contrastAccessibilityChecker = exports.labelSmartInvert = void 0;
|
|
6
6
|
|
|
7
|
-
const vutils_1 = require("@visactor/vutils"), defaultAlternativeColors = [ "#ffffff", "#000000" ]
|
|
7
|
+
const vutils_1 = require("@visactor/vutils"), defaultAlternativeColors = [ "#ffffff", "#000000" ];
|
|
8
8
|
|
|
9
9
|
function labelSmartInvert(foregroundColorOrigin, backgroundColorOrogin, textType, contrastRatiosThreshold, alternativeColors, mode) {
|
|
10
10
|
if ("string" != typeof foregroundColorOrigin || "string" != typeof backgroundColorOrogin) return foregroundColorOrigin;
|
|
11
|
-
const foregroundColor = new Color(foregroundColorOrigin).toHex(), backgroundColor = new Color(backgroundColorOrogin).toHex();
|
|
11
|
+
const foregroundColor = new vutils_1.Color(foregroundColorOrigin).toHex(), backgroundColor = new vutils_1.Color(backgroundColorOrogin).toHex();
|
|
12
12
|
return contrastAccessibilityChecker(foregroundColor, backgroundColor, textType, contrastRatiosThreshold, mode) ? foregroundColor : improveContrastReverse(foregroundColor, backgroundColor, textType, contrastRatiosThreshold, alternativeColors, mode);
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -21,8 +21,8 @@ function improveContrastReverse(foregroundColor, backgroundColor, textType, cont
|
|
|
21
21
|
|
|
22
22
|
function contrastAccessibilityChecker(foregroundColor, backgroundColor, textType, contrastRatiosThreshold, mode) {
|
|
23
23
|
if ("lightness" === mode) {
|
|
24
|
-
const backgroundColorLightness = Color.getColorBrightness(new Color(backgroundColor));
|
|
25
|
-
return Color.getColorBrightness(new Color(foregroundColor)) < .5 ? backgroundColorLightness >= .5 : backgroundColorLightness < .5;
|
|
24
|
+
const backgroundColorLightness = vutils_1.Color.getColorBrightness(new vutils_1.Color(backgroundColor));
|
|
25
|
+
return vutils_1.Color.getColorBrightness(new vutils_1.Color(foregroundColor)) < .5 ? backgroundColorLightness >= .5 : backgroundColorLightness < .5;
|
|
26
26
|
}
|
|
27
27
|
return contrastRatiosThreshold ? contrastRatios(foregroundColor, backgroundColor) > contrastRatiosThreshold : "largeText" === textType ? contrastRatios(foregroundColor, backgroundColor) > 3 : contrastRatios(foregroundColor, backgroundColor) > 4.5;
|
|
28
28
|
}
|
|
@@ -33,19 +33,13 @@ function contrastRatios(foregroundColor, backgroundColor) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
function getColorLuminance(color) {
|
|
36
|
-
const rgb8bit = vutils_1.
|
|
36
|
+
const rgb8bit = (0, vutils_1.hexToRgb)(color), RsRGB = rgb8bit[0] / 255, GsRGB = rgb8bit[1] / 255, BsRGB = rgb8bit[2] / 255;
|
|
37
37
|
let R, G, B;
|
|
38
38
|
R = RsRGB <= .03928 ? RsRGB / 12.92 : Math.pow((RsRGB + .055) / 1.055, 2.4), G = GsRGB <= .03928 ? GsRGB / 12.92 : Math.pow((GsRGB + .055) / 1.055, 2.4),
|
|
39
39
|
B = BsRGB <= .03928 ? BsRGB / 12.92 : Math.pow((BsRGB + .055) / 1.055, 2.4);
|
|
40
40
|
return .2126 * R + .7152 * G + .0722 * B;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
function formatColorToHex(originColor) {
|
|
44
|
-
if (null == originColor ? void 0 : originColor.includes("#")) return originColor;
|
|
45
|
-
const c = new vutils_1.ColorUtil.Color(originColor), {r: r, g: g, b: b} = c.color;
|
|
46
|
-
return "#" + vutils_1.ColorUtil.rgbToHex(r, g, b);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
43
|
function smartInvertStrategy(fillStrategy, baseColor, invertColor, similarColor) {
|
|
50
44
|
let result;
|
|
51
45
|
switch (fillStrategy) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/util/label-smartInvert.ts"],"names":[],"mappings":";;;AACA,6CAA6C;AAE7C,MAAM,wBAAwB,GAAa,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AAClE,MAAM,EAAE,KAAK,EAAE,GAAG,kBAAS,CAAC;AAQ5B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nB;SAAM;QACL,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,CAAC;KAC5C;IACD,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;IAC/C,OAAO,CAAC,CAAC;AACX,CAAC;AAQD,SAAS,gBAAgB,CAAC,WAA+B;IACvD,IAAK,WAAsB,aAAtB,WAAW,uBAAX,WAAW,CAAa,QAAQ,CAAC,GAAG,CAAC,EAAE;QAC1C,OAAO,WAAW,CAAC;KACpB;IACD,MAAM,CAAC,GAAG,IAAI,kBAAS,CAAC,KAAK,CAAC,WAAqB,CAAC,CAAC;IACrD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC;IAC5B,OAAO,GAAG,GAAG,kBAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3C,CAAC;AAED,SAAgB,mBAAmB,CACjC,YAAoB,EACpB,SAAiB,EACjB,WAAmB,EACnB,YAAoB;IAEpB,IAAI,MAAM,CAAC;IACX,QAAQ,YAAY,EAAE;QACpB,KAAK,MAAM;YACT,MAAM,GAAG,SAAS,CAAC;YACnB,MAAM;QACR,KAAK,YAAY;YACf,MAAM,GAAG,WAAW,CAAC;YACrB,MAAM;QACR,KAAK,aAAa;YAChB,MAAM,GAAG,YAAY,CAAC;QACxB;YACE,MAAM;KACT;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AApBD,kDAoBC","file":"label-smartInvert.js","sourcesContent":["import type { IColor } from '@visactor/vrender-core';\nimport { ColorUtil } from '@visactor/vutils';\n\nconst defaultAlternativeColors: string[] = ['#ffffff', '#000000'];\nconst { Color } = ColorUtil;\n\n/**\n * 标签智能反色\n * @param foregroundColorOrigin\n * @param backgroundColorOrogin\n * @returns\n */\nexport function labelSmartInvert(\n foregroundColorOrigin: IColor | undefined,\n backgroundColorOrogin: IColor | undefined,\n textType?: string | undefined,\n contrastRatiosThreshold?: number,\n alternativeColors?: string | string[],\n mode?: string\n): IColor | undefined {\n if (typeof foregroundColorOrigin !== 'string' || typeof backgroundColorOrogin !== 'string') {\n return foregroundColorOrigin;\n }\n const foregroundColor = new Color(foregroundColorOrigin as string).toHex();\n const backgroundColor = new Color(backgroundColorOrogin as string).toHex();\n if (!contrastAccessibilityChecker(foregroundColor, backgroundColor, textType, contrastRatiosThreshold, mode)) {\n return improveContrastReverse(\n foregroundColor,\n backgroundColor,\n textType,\n contrastRatiosThreshold,\n alternativeColors,\n mode\n );\n }\n return foregroundColor;\n}\n\n/**\n * 提升对比度\n * 对于对比度不足阈值的情况,推荐备选颜色色板中的颜色提升对比\n * @param foregroundColor\n * @param backgroundColor\n * @returns\n */\nfunction improveContrastReverse(\n foregroundColor: IColor | undefined,\n backgroundColor: IColor | undefined,\n textType?: IColor | undefined,\n contrastRatiosThreshold?: number,\n alternativeColors?: string | string[],\n mode?: string\n) {\n const alternativeColorPalletes: string[] = [];\n if (alternativeColors) {\n if (alternativeColors instanceof Array) {\n alternativeColorPalletes.push(...alternativeColors);\n } else {\n alternativeColorPalletes.push(alternativeColors);\n }\n }\n alternativeColorPalletes.push(...defaultAlternativeColors);\n for (const alternativeColor of alternativeColorPalletes) {\n if (foregroundColor === alternativeColor) {\n continue;\n }\n if (contrastAccessibilityChecker(alternativeColor, backgroundColor, textType, contrastRatiosThreshold, mode)) {\n return alternativeColor;\n }\n }\n return undefined;\n}\n\n/**\n * 颜色对比度可行性检查 https://webaim.org/articles/contrast/\n * - WCAG 2.0 AA 级要求普通文本的对比度至少为 4.5:1,大文本的对比度至少为 3:1。(目前按照此标准)\n * - WCAG 2.1 要求图形和用户界面组件(例如表单输入边框)的对比度至少为 3:1。\n * - WCAG AAA 级要求普通文本的对比度至少为 7:1,大文本的对比度至少为 4.5:1。\n * @param foregroundColor\n * @param backgroundColor\n * @returns\n */\nexport function contrastAccessibilityChecker(\n foregroundColor: IColor | undefined,\n backgroundColor: IColor | undefined,\n textType?: IColor | undefined,\n contrastRatiosThreshold?: number,\n mode?: string\n): boolean {\n if (mode === 'lightness') {\n const backgroundColorLightness = Color.getColorBrightness(new Color(backgroundColor as string));\n const foregroundColorLightness = Color.getColorBrightness(new Color(foregroundColor as string));\n if (foregroundColorLightness < 0.5) {\n // 文字颜色为'#ffffff'\n if (backgroundColorLightness >= 0.5) {\n return true;\n }\n return false;\n }\n // 文字颜色为‘#000000'\n if (backgroundColorLightness < 0.5) {\n return true;\n }\n return false;\n }\n //Contrast ratios can range from 1 to 21\n if (contrastRatiosThreshold) {\n if (contrastRatios(foregroundColor, backgroundColor) > contrastRatiosThreshold) {\n return true;\n }\n return false;\n } else if (textType === 'largeText') {\n if (contrastRatios(foregroundColor, backgroundColor) > 3) {\n return true;\n }\n return false;\n }\n if (contrastRatios(foregroundColor, backgroundColor) > 4.5) {\n return true;\n }\n return false;\n}\n\n/**\n * 计算颜色对比度 https://webaim.org/articles/contrast/\n * Contrast ratios can range from 1 to 21 (commonly written 1:1 to 21:1).\n * (L1 + 0.05) / (L2 + 0.05), whereby:\n * L1 is the relative luminance of the lighter of the colors, and\n * L2 is the relative luminance of the darker of the colors.\n * @param foregroundColor\n * @param backgroundColor\n * @returns\n */\nfunction contrastRatios(foregroundColor: IColor | undefined, backgroundColor: IColor | undefined): number {\n const foregroundColorLuminance = getColorLuminance(foregroundColor as string);\n const backgroundColorLuminance = getColorLuminance(backgroundColor as string);\n const L1 = foregroundColorLuminance > backgroundColorLuminance ? foregroundColorLuminance : backgroundColorLuminance;\n const L2 = foregroundColorLuminance > backgroundColorLuminance ? backgroundColorLuminance : foregroundColorLuminance;\n const contrastRatios = (L1 + 0.05) / (L2 + 0.05);\n return contrastRatios;\n}\n\n/**\n * 计算相对亮度 https://webaim.org/articles/contrast/\n * the relative brightness of any point in a colorspace, normalized to 0 for darkest black and 1 for lightest white\n * Note 1: For the sRGB colorspace, the relative luminance of a color is defined as\n * L = 0.2126 * R + 0.7152 * G + 0.0722 * B where R, G and B are defined as:\n * if RsRGB <= 0.03928 then R = RsRGB/12.92 else R = ((RsRGB+0.055)/1.055) ^ 2.4\n * if GsRGB <= 0.03928 then G = GsRGB/12.92 else G = ((GsRGB+0.055)/1.055) ^ 2.4\n * if BsRGB <= 0.03928 then B = BsRGB/12.92 else B = ((BsRGB+0.055)/1.055) ^ 2.4\n * and RsRGB, GsRGB, and BsRGB are defined as:\n * RsRGB = R8bit/255\n * GsRGB = G8bit/255\n * BsRGB = B8bit/255\n * @param color\n * @returns\n */\nfunction getColorLuminance(color: string): number {\n const rgb8bit = ColorUtil.hexToRgb(color);\n const RsRGB = rgb8bit[0] / 255;\n const GsRGB = rgb8bit[1] / 255;\n const BsRGB = rgb8bit[2] / 255;\n let R;\n let G;\n let B;\n if (RsRGB <= 0.03928) {\n R = RsRGB / 12.92;\n } else {\n R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);\n }\n if (GsRGB <= 0.03928) {\n G = GsRGB / 12.92;\n } else {\n G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);\n }\n if (BsRGB <= 0.03928) {\n B = BsRGB / 12.92;\n } else {\n B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);\n }\n const L = 0.2126 * R + 0.7152 * G + 0.0722 * B;\n return L;\n}\n\n/**\n * 规范化color格式为hex\n * 当color为颜色名称或rgb时,对其进行规范化处理\n * @param originColor\n * @returns\n */\nfunction formatColorToHex(originColor: IColor | undefined) {\n if ((originColor as string)?.includes('#')) {\n return originColor;\n }\n const c = new ColorUtil.Color(originColor as string);\n const { r, g, b } = c.color;\n return '#' + ColorUtil.rgbToHex(r, g, b);\n}\n\nexport function smartInvertStrategy(\n fillStrategy: string,\n baseColor: IColor,\n invertColor: IColor,\n similarColor: IColor\n) {\n let result;\n switch (fillStrategy) {\n case 'base':\n result = baseColor;\n break;\n case 'invertBase':\n result = invertColor;\n break;\n case 'similarBase':\n result = similarColor;\n default:\n break;\n }\n return result;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/util/label-smartInvert.ts"],"names":[],"mappings":";;;AACA,6CAAmD;AAEnD,MAAM,wBAAwB,GAAa,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AAQlE,SAAgB,gBAAgB,CAC9B,qBAAyC,EACzC,qBAAyC,EACzC,QAA6B,EAC7B,uBAAgC,EAChC,iBAAqC,EACrC,IAAa;IAEb,IAAI,OAAO,qBAAqB,KAAK,QAAQ,IAAI,OAAO,qBAAqB,KAAK,QAAQ,EAAE;QAC1F,OAAO,qBAAqB,CAAC;KAC9B;IACD,MAAM,eAAe,GAAG,IAAI,cAAK,CAAC,qBAA+B,CAAC,CAAC,KAAK,EAAE,CAAC;IAC3E,MAAM,eAAe,GAAG,IAAI,cAAK,CAAC,qBAA+B,CAAC,CAAC,KAAK,EAAE,CAAC;IAC3E,IAAI,CAAC,4BAA4B,CAAC,eAAe,EAAE,eAAe,EAAE,QAAQ,EAAE,uBAAuB,EAAE,IAAI,CAAC,EAAE;QAC5G,OAAO,sBAAsB,CAC3B,eAAe,EACf,eAAe,EACf,QAAQ,EACR,uBAAuB,EACvB,iBAAiB,EACjB,IAAI,CACL,CAAC;KACH;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAxBD,4CAwBC;AASD,SAAS,sBAAsB,CAC7B,eAAmC,EACnC,eAAmC,EACnC,QAA6B,EAC7B,uBAAgC,EAChC,iBAAqC,EACrC,IAAa;IAEb,MAAM,wBAAwB,GAAa,EAAE,CAAC;IAC9C,IAAI,iBAAiB,EAAE;QACrB,IAAI,iBAAiB,YAAY,KAAK,EAAE;YACtC,wBAAwB,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,CAAC;SACrD;aAAM;YACL,wBAAwB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;SAClD;KACF;IACD,wBAAwB,CAAC,IAAI,CAAC,GAAG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nB;SAAM;QACL,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,CAAC;KAC5C;IACD,IAAI,KAAK,IAAI,OAAO,EAAE;QACpB,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC;KACnB;SAAM;QACL,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,CAAC;KAC5C;IACD,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;IAC/C,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAgB,mBAAmB,CACjC,YAAoB,EACpB,SAAiB,EACjB,WAAmB,EACnB,YAAoB;IAEpB,IAAI,MAAM,CAAC;IACX,QAAQ,YAAY,EAAE;QACpB,KAAK,MAAM;YACT,MAAM,GAAG,SAAS,CAAC;YACnB,MAAM;QACR,KAAK,YAAY;YACf,MAAM,GAAG,WAAW,CAAC;YACrB,MAAM;QACR,KAAK,aAAa;YAChB,MAAM,GAAG,YAAY,CAAC;QACxB;YACE,MAAM;KACT;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AApBD,kDAoBC","file":"label-smartInvert.js","sourcesContent":["import type { IColor } from '@visactor/vrender-core';\nimport { Color, hexToRgb } from '@visactor/vutils';\n\nconst defaultAlternativeColors: string[] = ['#ffffff', '#000000'];\n\n/**\n * 标签智能反色\n * @param foregroundColorOrigin\n * @param backgroundColorOrogin\n * @returns\n */\nexport function labelSmartInvert(\n foregroundColorOrigin: IColor | undefined,\n backgroundColorOrogin: IColor | undefined,\n textType?: string | undefined,\n contrastRatiosThreshold?: number,\n alternativeColors?: string | string[],\n mode?: string\n): IColor | undefined {\n if (typeof foregroundColorOrigin !== 'string' || typeof backgroundColorOrogin !== 'string') {\n return foregroundColorOrigin;\n }\n const foregroundColor = new Color(foregroundColorOrigin as string).toHex();\n const backgroundColor = new Color(backgroundColorOrogin as string).toHex();\n if (!contrastAccessibilityChecker(foregroundColor, backgroundColor, textType, contrastRatiosThreshold, mode)) {\n return improveContrastReverse(\n foregroundColor,\n backgroundColor,\n textType,\n contrastRatiosThreshold,\n alternativeColors,\n mode\n );\n }\n return foregroundColor;\n}\n\n/**\n * 提升对比度\n * 对于对比度不足阈值的情况,推荐备选颜色色板中的颜色提升对比\n * @param foregroundColor\n * @param backgroundColor\n * @returns\n */\nfunction improveContrastReverse(\n foregroundColor: IColor | undefined,\n backgroundColor: IColor | undefined,\n textType?: IColor | undefined,\n contrastRatiosThreshold?: number,\n alternativeColors?: string | string[],\n mode?: string\n) {\n const alternativeColorPalletes: string[] = [];\n if (alternativeColors) {\n if (alternativeColors instanceof Array) {\n alternativeColorPalletes.push(...alternativeColors);\n } else {\n alternativeColorPalletes.push(alternativeColors);\n }\n }\n alternativeColorPalletes.push(...defaultAlternativeColors);\n for (const alternativeColor of alternativeColorPalletes) {\n if (foregroundColor === alternativeColor) {\n continue;\n }\n if (contrastAccessibilityChecker(alternativeColor, backgroundColor, textType, contrastRatiosThreshold, mode)) {\n return alternativeColor;\n }\n }\n return undefined;\n}\n\n/**\n * 颜色对比度可行性检查 https://webaim.org/articles/contrast/\n * - WCAG 2.0 AA 级要求普通文本的对比度至少为 4.5:1,大文本的对比度至少为 3:1。(目前按照此标准)\n * - WCAG 2.1 要求图形和用户界面组件(例如表单输入边框)的对比度至少为 3:1。\n * - WCAG AAA 级要求普通文本的对比度至少为 7:1,大文本的对比度至少为 4.5:1。\n * @param foregroundColor\n * @param backgroundColor\n * @returns\n */\nexport function contrastAccessibilityChecker(\n foregroundColor: IColor | undefined,\n backgroundColor: IColor | undefined,\n textType?: IColor | undefined,\n contrastRatiosThreshold?: number,\n mode?: string\n): boolean {\n if (mode === 'lightness') {\n const backgroundColorLightness = Color.getColorBrightness(new Color(backgroundColor as string));\n const foregroundColorLightness = Color.getColorBrightness(new Color(foregroundColor as string));\n if (foregroundColorLightness < 0.5) {\n // 文字颜色为'#ffffff'\n if (backgroundColorLightness >= 0.5) {\n return true;\n }\n return false;\n }\n // 文字颜色为‘#000000'\n if (backgroundColorLightness < 0.5) {\n return true;\n }\n return false;\n }\n //Contrast ratios can range from 1 to 21\n if (contrastRatiosThreshold) {\n if (contrastRatios(foregroundColor, backgroundColor) > contrastRatiosThreshold) {\n return true;\n }\n return false;\n } else if (textType === 'largeText') {\n if (contrastRatios(foregroundColor, backgroundColor) > 3) {\n return true;\n }\n return false;\n }\n if (contrastRatios(foregroundColor, backgroundColor) > 4.5) {\n return true;\n }\n return false;\n}\n\n/**\n * 计算颜色对比度 https://webaim.org/articles/contrast/\n * Contrast ratios can range from 1 to 21 (commonly written 1:1 to 21:1).\n * (L1 + 0.05) / (L2 + 0.05), whereby:\n * L1 is the relative luminance of the lighter of the colors, and\n * L2 is the relative luminance of the darker of the colors.\n * @param foregroundColor\n * @param backgroundColor\n * @returns\n */\nfunction contrastRatios(foregroundColor: IColor | undefined, backgroundColor: IColor | undefined): number {\n const foregroundColorLuminance = getColorLuminance(foregroundColor as string);\n const backgroundColorLuminance = getColorLuminance(backgroundColor as string);\n const L1 = foregroundColorLuminance > backgroundColorLuminance ? foregroundColorLuminance : backgroundColorLuminance;\n const L2 = foregroundColorLuminance > backgroundColorLuminance ? backgroundColorLuminance : foregroundColorLuminance;\n const contrastRatios = (L1 + 0.05) / (L2 + 0.05);\n return contrastRatios;\n}\n\n/**\n * 计算相对亮度 https://webaim.org/articles/contrast/\n * the relative brightness of any point in a colorspace, normalized to 0 for darkest black and 1 for lightest white\n * Note 1: For the sRGB colorspace, the relative luminance of a color is defined as\n * L = 0.2126 * R + 0.7152 * G + 0.0722 * B where R, G and B are defined as:\n * if RsRGB <= 0.03928 then R = RsRGB/12.92 else R = ((RsRGB+0.055)/1.055) ^ 2.4\n * if GsRGB <= 0.03928 then G = GsRGB/12.92 else G = ((GsRGB+0.055)/1.055) ^ 2.4\n * if BsRGB <= 0.03928 then B = BsRGB/12.92 else B = ((BsRGB+0.055)/1.055) ^ 2.4\n * and RsRGB, GsRGB, and BsRGB are defined as:\n * RsRGB = R8bit/255\n * GsRGB = G8bit/255\n * BsRGB = B8bit/255\n * @param color\n * @returns\n */\nfunction getColorLuminance(color: string): number {\n const rgb8bit = hexToRgb(color);\n const RsRGB = rgb8bit[0] / 255;\n const GsRGB = rgb8bit[1] / 255;\n const BsRGB = rgb8bit[2] / 255;\n let R;\n let G;\n let B;\n if (RsRGB <= 0.03928) {\n R = RsRGB / 12.92;\n } else {\n R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);\n }\n if (GsRGB <= 0.03928) {\n G = GsRGB / 12.92;\n } else {\n G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);\n }\n if (BsRGB <= 0.03928) {\n B = BsRGB / 12.92;\n } else {\n B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);\n }\n const L = 0.2126 * R + 0.7152 * G + 0.0722 * B;\n return L;\n}\n\nexport function smartInvertStrategy(\n fillStrategy: string,\n baseColor: IColor,\n invertColor: IColor,\n similarColor: IColor\n) {\n let result;\n switch (fillStrategy) {\n case 'base':\n result = baseColor;\n break;\n case 'invertBase':\n result = invertColor;\n break;\n case 'similarBase':\n result = similarColor;\n default:\n break;\n }\n return result;\n}\n"]}
|