@visactor/vrender-components 0.17.5-alpha.0 → 0.17.5
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/scrollbar/scrollbar.js +4 -1
- package/cjs/scrollbar/scrollbar.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 +329 -538
- 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/scrollbar/scrollbar.js +4 -1
- package/es/scrollbar/scrollbar.js.map +1 -1
- package/es/util/label-smartInvert.js +3 -9
- package/es/util/label-smartInvert.js.map +1 -1
- package/package.json +4 -4
|
@@ -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"]}
|
|
@@ -30,7 +30,10 @@ class ScrollBar extends base_1.AbstractComponent {
|
|
|
30
30
|
}, this._onSliderPointerDown = e => {
|
|
31
31
|
e.stopPropagation();
|
|
32
32
|
const {direction: direction} = this.attribute;
|
|
33
|
-
this._prePos = "horizontal" === direction ? e.clientX : e.clientY,
|
|
33
|
+
this._prePos = "horizontal" === direction ? e.clientX : e.clientY, this._dispatchEvent("scrollDown", {
|
|
34
|
+
pos: this._prePos,
|
|
35
|
+
event: e
|
|
36
|
+
}), "browser" === vrender_core_1.vglobal.env ? (vrender_core_1.vglobal.addEventListener("pointermove", this._onSliderPointerMove, {
|
|
34
37
|
capture: !0
|
|
35
38
|
}), vrender_core_1.vglobal.addEventListener("pointerup", this._onSliderPointerUp)) : (this.stage.addEventListener("pointermove", this._onSliderPointerMove, {
|
|
36
39
|
capture: !0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/scrollbar/scrollbar.ts"],"names":[],"mappings":";;;AAKA,yDAAiD;AACjD,6CAAkG;AAClG,uCAAiD;AAIjD,yCAAoD;AAWpD,MAAM,QAAQ,GAAG;IACf,QAAQ,EAAE,iBAAQ;IAClB,QAAQ,EAAE,iBAAQ;CACnB,CAAC;AAEF,IAAA,iCAAsB,GAAE,CAAC;AAEzB,MAAa,SAAU,SAAQ,wBAAgD;IAmC7E,YAAY,UAA+B,EAAE,OAA0B;QACrE,KAAK,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,cAAK,EAAC,EAAE,EAAE,SAAS,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;QAnChG,SAAI,GAAG,WAAW,CAAC;QAuOX,uBAAkB,GAAG,CAAC,CAAwB,EAAE,EAAE;;YAGxD,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GA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AAC,CAAC;IACnB,SAAS,EAAE,UAAU;IACrB,SAAS,EAAE,CAAC;IACZ,QAAQ,EAAE,IAAI;CACf,CAAC","file":"scrollbar.js","sourcesContent":["/**\n * @description 滚动条组件\n */\nimport type { IRectGraphicAttribute, FederatedPointerEvent, IGroup, IRect } from '@visactor/vrender-core';\n// eslint-disable-next-line no-duplicate-imports\nimport { vglobal } from '@visactor/vrender-core';\nimport { merge, normalizePadding, clamp, clampRange, debounce, throttle } from '@visactor/vutils';\nimport { AbstractComponent } from '../core/base';\n\nimport type { ScrollBarAttributes } from './type';\nimport type { ComponentOptions } from '../interface';\nimport { loadScrollbarComponent } from './register';\n\ntype ComponentBounds = {\n x1: number;\n y1: number;\n x2: number;\n y2: number;\n width: number;\n height: number;\n};\n\nconst delayMap = {\n debounce: debounce,\n throttle: throttle\n};\n\nloadScrollbarComponent();\n\nexport class ScrollBar extends AbstractComponent<Required<ScrollBarAttributes>> {\n name = 'scrollbar';\n\n static defaultAttributes = {\n direction: 'horizontal',\n round: true,\n sliderSize: 20,\n sliderStyle: {\n fill: 'rgba(0, 0, 0, .5)'\n },\n railStyle: {\n fill: 'rgba(0, 0, 0, .0)'\n },\n padding: 2,\n scrollRange: [0, 1],\n delayType: 'throttle',\n delayTime: 0,\n realTime: true\n };\n\n private _container!: IGroup;\n // 滚动条滑块\n private _slider!: IRect;\n // 滚动条滑轨\n private _rail!: IRect;\n // 滑块可渲染的区域包围盒\n private _sliderRenderBounds!: ComponentBounds | null;\n // 滑块滑动的范围\n private _sliderLimitRange!: [number, number] | null;\n // 保留滑块上一次的位置\n private _prePos!: number;\n // TODO: 临时方案\n private _viewPosition!: { x: number; y: number };\n private _sliderSize!: number;\n\n constructor(attributes: ScrollBarAttributes, options?: ComponentOptions) {\n super(options?.skipDefault ? attributes : merge({}, ScrollBar.defaultAttributes, attributes));\n }\n\n setScrollRange(range: [number, number], render = true) {\n const {\n direction = 'horizontal',\n limitRange = [0, 1],\n range: preRange,\n realTime = true\n } = this.attribute as ScrollBarAttributes;\n\n const currScrollRange = clampRange(range, limitRange[0], limitRange[1]);\n if (render) {\n // 更新图形\n const sliderPos = this._getSliderPos(currScrollRange);\n if (this._slider) {\n if (direction === 'horizontal') {\n this._slider.setAttribute('x', sliderPos[0], true);\n } else {\n this._slider.setAttribute('y', sliderPos[0], true);\n }\n\n if (!this.stage?.autoRender) {\n this.stage?.renderNextFrame();\n }\n }\n }\n (this.attribute as ScrollBarAttributes).range = currScrollRange;\n // 发射 change 事件\n if (realTime) {\n this._dispatchEvent('scroll', {\n pre: preRange,\n value: currScrollRange\n });\n }\n }\n\n getScrollRange(): [number, number] {\n return (this.attribute as ScrollBarAttributes).range;\n }\n\n // public setLocation(point: PointLocationCfg) {\n // this.translateTo(point.x, point.y);\n // }\n\n // 绑定事件\n protected bindEvents(): void {\n if (this.attribute.disableTriggerEvent) {\n return;\n }\n const { delayType = 'throttle', delayTime = 0 } = this.attribute as ScrollBarAttributes;\n // TODO: wheel 事件支持\n if (this._rail) {\n this._rail.addEventListener(\n 'pointerdown',\n delayMap[delayType](this._onRailPointerDown, delayTime) as EventListener\n );\n }\n if (this._slider) {\n this._slider.addEventListener('pointerdown', this._onSliderPointerDown as EventListener);\n }\n }\n\n protected render() {\n this._reset();\n const {\n direction = 'horizontal',\n width,\n height,\n range,\n limitRange = [0, 1],\n // sliderSize = 20,\n // scrollValue = 0,\n // scrollRange = [0, 1],\n railStyle,\n sliderStyle,\n padding = 2\n } = this.attribute as ScrollBarAttributes;\n\n const group = this.createOrUpdateChild('scrollbar-container', {}, 'group') as IGroup;\n // 绘制轨道\n\n const rail = group.createOrUpdateChild(\n 'scrollbar-rail',\n {\n x: 0,\n y: 0,\n width,\n height,\n ...railStyle\n },\n 'rect'\n ) as IRect;\n this._rail = rail;\n\n // 滑块\n const sliderRenderBounds = this._getSliderRenderBounds();\n const sliderPos = this._getSliderPos(clampRange(range, limitRange[0], limitRange[1]));\n const sliderSize = sliderPos[1] - sliderPos[0];\n this._sliderSize = sliderSize;\n // const sliderRangePos = this._getScrollRange();\n\n let sliderAttribute: IRectGraphicAttribute;\n if (direction === 'horizontal') {\n sliderAttribute = {\n x: sliderPos[0],\n y: sliderRenderBounds.y1,\n width: sliderSize,\n height: sliderRenderBounds.height\n };\n } else {\n sliderAttribute = {\n x: sliderRenderBounds.x1,\n y: sliderPos[0],\n width: sliderRenderBounds.width,\n height: sliderSize\n };\n }\n\n const slider = group.createOrUpdateChild(\n 'slider',\n {\n ...sliderAttribute,\n cornerRadius: this._getDefaultSliderCornerRadius(),\n ...sliderStyle,\n boundsPadding: normalizePadding(padding),\n pickMode: 'imprecise'\n },\n 'rect'\n ) as IRect;\n this._slider = slider;\n this._container = group;\n\n const containerAABBBounds = this._container.AABBBounds;\n this._viewPosition = {\n x: containerAABBBounds.x1,\n y: containerAABBBounds.y1\n };\n }\n\n // 获取滑块渲染的包围盒区域\n private _getSliderRenderBounds() {\n if (this._sliderRenderBounds) {\n return this._sliderRenderBounds;\n }\n const { width, height, padding = 2 } = this.attribute as ScrollBarAttributes;\n const [top, right, bottom, left] = normalizePadding(padding);\n const renderBounds = {\n x1: left,\n y1: top,\n x2: width - right,\n y2: height - bottom,\n width: Math.max(0, width - (left + right)),\n height: Math.max(0, height - (top + bottom))\n };\n this._sliderRenderBounds = renderBounds;\n return renderBounds;\n }\n\n // 获取默认的滑块圆角\n private _getDefaultSliderCornerRadius() {\n const { direction, round } = this.attribute as ScrollBarAttributes;\n\n if (round) {\n const { width, height } = this._getSliderRenderBounds();\n return direction === 'horizontal' ? height : width;\n }\n\n return 0;\n }\n\n // 计算滑块在轨道的位置\n private _getSliderPos(range: [number, number]) {\n const { direction } = this.attribute as ScrollBarAttributes;\n const { width, height, x1, y1 } = this._getSliderRenderBounds();\n\n if (direction === 'horizontal') {\n return [width * range[0] + x1, width * range[1] + x1];\n }\n return [height * range[0] + y1, height * range[1] + y1];\n }\n\n private _getScrollRange() {\n if (this._sliderLimitRange) {\n return this._sliderLimitRange;\n }\n const { limitRange = [0, 1], direction } = this.attribute as ScrollBarAttributes;\n const [min, max] = clampRange(limitRange, 0, 1);\n const { width, height, x1, y1 } = this._getSliderRenderBounds();\n const sliderSize = this._sliderSize;\n\n return direction === 'horizontal'\n ? clampRange([x1 + min * width, x1 + max * width], x1, width - sliderSize)\n : clampRange([y1 + min * height, y1 + max * height], y1, height - sliderSize);\n }\n\n private _onRailPointerDown = (e: FederatedPointerEvent) => {\n // 将事件坐标转换为实际的滑块位置\n // TODO: 这里有问题,应该拿 viewX viewY,同时 graphic 要提供接口获取它的 相对 view 的坐标\n const { viewX, viewY } = e;\n const { direction, width, height, range } = this.attribute as ScrollBarAttributes;\n const sliderSize = this._sliderSize;\n const [min, max] = this._getScrollRange();\n let currentScrollValue;\n if (direction === 'vertical') {\n const relativeY = viewY - this._viewPosition.y;\n const currentYPos = clamp(relativeY - sliderSize / 2, min, max);\n currentScrollValue = relativeY / height;\n this._slider.setAttribute('y', currentYPos, true);\n } else {\n const relativeX = viewX - this._viewPosition.x;\n const currentXPos = clamp(relativeX - sliderSize / 2, min, max);\n currentScrollValue = relativeX / width;\n this._slider.setAttribute('x', currentXPos, true);\n }\n\n this.setScrollRange(\n [currentScrollValue - (range[1] - range[0]) / 2, currentScrollValue + (range[1] - range[0]) / 2],\n false\n );\n\n if (!this.stage?.autoRender) {\n this.stage?.renderNextFrame();\n }\n };\n\n private _onSliderPointerDown = (e: FederatedPointerEvent) => {\n e.stopPropagation();\n const { direction } = this.attribute as ScrollBarAttributes;\n this._prePos = direction === 'horizontal' ? e.clientX : e.clientY;\n if (vglobal.env === 'browser') {\n vglobal.addEventListener('pointermove', this._onSliderPointerMove, { capture: true });\n vglobal.addEventListener('pointerup', this._onSliderPointerUp);\n } else {\n this.stage.addEventListener('pointermove', this._onSliderPointerMove, { capture: true });\n this.stage.addEventListener('pointerup', this._onSliderPointerUp);\n this.stage.addEventListener('pointerupoutside', this._onSliderPointerUp);\n }\n };\n\n private _computeScrollValue = (e: any) => {\n const { direction } = this.attribute as ScrollBarAttributes;\n let currentScrollValue;\n let currentPos;\n let delta = 0;\n\n const { width, height } = this._getSliderRenderBounds();\n if (direction === 'vertical') {\n currentPos = e.clientY;\n delta = currentPos - this._prePos;\n currentScrollValue = delta / height;\n } else {\n currentPos = e.clientX;\n delta = currentPos - this._prePos;\n currentScrollValue = delta / width;\n }\n return [currentPos, currentScrollValue];\n };\n\n private _onSliderPointerMove = delayMap[this.attribute.delayType]((e: any) => {\n e.stopPropagation();\n const preScrollRange = this.getScrollRange();\n const [currentPos, currentScrollValue] = this._computeScrollValue(e);\n this.setScrollRange([preScrollRange[0] + currentScrollValue, preScrollRange[1] + currentScrollValue], true);\n this._prePos = currentPos;\n }, this.attribute.delayTime);\n\n private _onSliderPointerUp = (e: any) => {\n e.preventDefault();\n const { realTime = true, range: preRange, limitRange = [0, 1] } = this.attribute as ScrollBarAttributes;\n // 发射 change 事件\n const preScrollRange = this.getScrollRange();\n const [currentPos, currentScrollValue] = this._computeScrollValue(e);\n const range: [number, number] = [preScrollRange[0] + currentScrollValue, preScrollRange[1] + currentScrollValue];\n if (!realTime) {\n this._dispatchEvent('scroll', {\n pre: preRange,\n value: clampRange(range, limitRange[0], limitRange[1])\n });\n }\n if (vglobal.env === 'browser') {\n vglobal.removeEventListener('pointermove', this._onSliderPointerMove, { capture: true });\n vglobal.removeEventListener('pointerup', this._onSliderPointerUp);\n } else {\n this.stage.removeEventListener('pointermove', this._onSliderPointerMove, { capture: true });\n this.stage.removeEventListener('pointerup', this._onSliderPointerUp);\n this.stage.removeEventListener('pointerupoutside', this._onSliderPointerUp);\n }\n };\n\n private _reset() {\n this._sliderRenderBounds = null;\n this._sliderLimitRange = null;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/scrollbar/scrollbar.ts"],"names":[],"mappings":";;;AAKA,yDAAiD;AACjD,6CAAkG;AAClG,uCAAiD;AAIjD,yCAAoD;AAWpD,MAAM,QAAQ,GAAG;IACf,QAAQ,EAAE,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E,KAAK,GAAG,UAAU,CAAC;YAC1E,CAAC,CAAC,IAAA,mBAAU,EAAC,CAAC,EAAE,GAAG,GAAG,GAAG,MAAM,EAAE,EAAE,GAAG,GAAG,GAAG,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC;IAClF,CAAC;IAoGO,MAAM;QACZ,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;QAChC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAChC,CAAC;;AA7UH,8BA8UC;AA3UQ,2BAAiB,GAAG;IACzB,SAAS,EAAE,YAAY;IACvB,KAAK,EAAE,IAAI;IACX,UAAU,EAAE,EAAE;IACd,WAAW,EAAE;QACX,IAAI,EAAE,mBAAmB;KAC1B;IACD,SAAS,EAAE;QACT,IAAI,EAAE,mBAAmB;KAC1B;IACD,OAAO,EAAE,CAAC;IACV,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IACnB,SAAS,EAAE,UAAU;IACrB,SAAS,EAAE,CAAC;IACZ,QAAQ,EAAE,IAAI;CACf,CAAC","file":"scrollbar.js","sourcesContent":["/**\n * @description 滚动条组件\n */\nimport type { IRectGraphicAttribute, FederatedPointerEvent, IGroup, IRect } from '@visactor/vrender-core';\n// eslint-disable-next-line no-duplicate-imports\nimport { vglobal } from '@visactor/vrender-core';\nimport { merge, normalizePadding, clamp, clampRange, debounce, throttle } from '@visactor/vutils';\nimport { AbstractComponent } from '../core/base';\n\nimport type { ScrollBarAttributes } from './type';\nimport type { ComponentOptions } from '../interface';\nimport { loadScrollbarComponent } from './register';\n\ntype ComponentBounds = {\n x1: number;\n y1: number;\n x2: number;\n y2: number;\n width: number;\n height: number;\n};\n\nconst delayMap = {\n debounce: debounce,\n throttle: throttle\n};\n\nloadScrollbarComponent();\n\nexport class ScrollBar extends AbstractComponent<Required<ScrollBarAttributes>> {\n name = 'scrollbar';\n\n static defaultAttributes = {\n direction: 'horizontal',\n round: true,\n sliderSize: 20,\n sliderStyle: {\n fill: 'rgba(0, 0, 0, .5)'\n },\n railStyle: {\n fill: 'rgba(0, 0, 0, .0)'\n },\n padding: 2,\n scrollRange: [0, 1],\n delayType: 'throttle',\n delayTime: 0,\n realTime: true\n };\n\n private _container!: IGroup;\n // 滚动条滑块\n private _slider!: IRect;\n // 滚动条滑轨\n private _rail!: IRect;\n // 滑块可渲染的区域包围盒\n private _sliderRenderBounds!: ComponentBounds | null;\n // 滑块滑动的范围\n private _sliderLimitRange!: [number, number] | null;\n // 保留滑块上一次的位置\n private _prePos!: number;\n // TODO: 临时方案\n private _viewPosition!: { x: number; y: number };\n private _sliderSize!: number;\n\n constructor(attributes: ScrollBarAttributes, options?: ComponentOptions) {\n super(options?.skipDefault ? attributes : merge({}, ScrollBar.defaultAttributes, attributes));\n }\n\n setScrollRange(range: [number, number], render = true) {\n const {\n direction = 'horizontal',\n limitRange = [0, 1],\n range: preRange,\n realTime = true\n } = this.attribute as ScrollBarAttributes;\n\n const currScrollRange = clampRange(range, limitRange[0], limitRange[1]);\n if (render) {\n // 更新图形\n const sliderPos = this._getSliderPos(currScrollRange);\n if (this._slider) {\n if (direction === 'horizontal') {\n this._slider.setAttribute('x', sliderPos[0], true);\n } else {\n this._slider.setAttribute('y', sliderPos[0], true);\n }\n\n if (!this.stage?.autoRender) {\n this.stage?.renderNextFrame();\n }\n }\n }\n (this.attribute as ScrollBarAttributes).range = currScrollRange;\n // 发射 change 事件\n if (realTime) {\n this._dispatchEvent('scroll', {\n pre: preRange,\n value: currScrollRange\n });\n }\n }\n\n getScrollRange(): [number, number] {\n return (this.attribute as ScrollBarAttributes).range;\n }\n\n // public setLocation(point: PointLocationCfg) {\n // this.translateTo(point.x, point.y);\n // }\n\n // 绑定事件\n protected bindEvents(): void {\n if (this.attribute.disableTriggerEvent) {\n return;\n }\n const { delayType = 'throttle', delayTime = 0 } = this.attribute as ScrollBarAttributes;\n // TODO: wheel 事件支持\n if (this._rail) {\n this._rail.addEventListener(\n 'pointerdown',\n delayMap[delayType](this._onRailPointerDown, delayTime) as EventListener\n );\n }\n if (this._slider) {\n this._slider.addEventListener('pointerdown', this._onSliderPointerDown as EventListener);\n }\n }\n\n protected render() {\n this._reset();\n const {\n direction = 'horizontal',\n width,\n height,\n range,\n limitRange = [0, 1],\n // sliderSize = 20,\n // scrollValue = 0,\n // scrollRange = [0, 1],\n railStyle,\n sliderStyle,\n padding = 2\n } = this.attribute as ScrollBarAttributes;\n\n const group = this.createOrUpdateChild('scrollbar-container', {}, 'group') as IGroup;\n // 绘制轨道\n\n const rail = group.createOrUpdateChild(\n 'scrollbar-rail',\n {\n x: 0,\n y: 0,\n width,\n height,\n ...railStyle\n },\n 'rect'\n ) as IRect;\n this._rail = rail;\n\n // 滑块\n const sliderRenderBounds = this._getSliderRenderBounds();\n const sliderPos = this._getSliderPos(clampRange(range, limitRange[0], limitRange[1]));\n const sliderSize = sliderPos[1] - sliderPos[0];\n this._sliderSize = sliderSize;\n // const sliderRangePos = this._getScrollRange();\n\n let sliderAttribute: IRectGraphicAttribute;\n if (direction === 'horizontal') {\n sliderAttribute = {\n x: sliderPos[0],\n y: sliderRenderBounds.y1,\n width: sliderSize,\n height: sliderRenderBounds.height\n };\n } else {\n sliderAttribute = {\n x: sliderRenderBounds.x1,\n y: sliderPos[0],\n width: sliderRenderBounds.width,\n height: sliderSize\n };\n }\n\n const slider = group.createOrUpdateChild(\n 'slider',\n {\n ...sliderAttribute,\n cornerRadius: this._getDefaultSliderCornerRadius(),\n ...sliderStyle,\n boundsPadding: normalizePadding(padding),\n pickMode: 'imprecise'\n },\n 'rect'\n ) as IRect;\n this._slider = slider;\n this._container = group;\n\n const containerAABBBounds = this._container.AABBBounds;\n this._viewPosition = {\n x: containerAABBBounds.x1,\n y: containerAABBBounds.y1\n };\n }\n\n // 获取滑块渲染的包围盒区域\n private _getSliderRenderBounds() {\n if (this._sliderRenderBounds) {\n return this._sliderRenderBounds;\n }\n const { width, height, padding = 2 } = this.attribute as ScrollBarAttributes;\n const [top, right, bottom, left] = normalizePadding(padding);\n const renderBounds = {\n x1: left,\n y1: top,\n x2: width - right,\n y2: height - bottom,\n width: Math.max(0, width - (left + right)),\n height: Math.max(0, height - (top + bottom))\n };\n this._sliderRenderBounds = renderBounds;\n return renderBounds;\n }\n\n // 获取默认的滑块圆角\n private _getDefaultSliderCornerRadius() {\n const { direction, round } = this.attribute as ScrollBarAttributes;\n\n if (round) {\n const { width, height } = this._getSliderRenderBounds();\n return direction === 'horizontal' ? height : width;\n }\n\n return 0;\n }\n\n // 计算滑块在轨道的位置\n private _getSliderPos(range: [number, number]) {\n const { direction } = this.attribute as ScrollBarAttributes;\n const { width, height, x1, y1 } = this._getSliderRenderBounds();\n\n if (direction === 'horizontal') {\n return [width * range[0] + x1, width * range[1] + x1];\n }\n return [height * range[0] + y1, height * range[1] + y1];\n }\n\n private _getScrollRange() {\n if (this._sliderLimitRange) {\n return this._sliderLimitRange;\n }\n const { limitRange = [0, 1], direction } = this.attribute as ScrollBarAttributes;\n const [min, max] = clampRange(limitRange, 0, 1);\n const { width, height, x1, y1 } = this._getSliderRenderBounds();\n const sliderSize = this._sliderSize;\n\n return direction === 'horizontal'\n ? clampRange([x1 + min * width, x1 + max * width], x1, width - sliderSize)\n : clampRange([y1 + min * height, y1 + max * height], y1, height - sliderSize);\n }\n\n private _onRailPointerDown = (e: FederatedPointerEvent) => {\n // 将事件坐标转换为实际的滑块位置\n // TODO: 这里有问题,应该拿 viewX viewY,同时 graphic 要提供接口获取它的 相对 view 的坐标\n const { viewX, viewY } = e;\n const { direction, width, height, range } = this.attribute as ScrollBarAttributes;\n const sliderSize = this._sliderSize;\n const [min, max] = this._getScrollRange();\n let currentScrollValue;\n if (direction === 'vertical') {\n const relativeY = viewY - this._viewPosition.y;\n const currentYPos = clamp(relativeY - sliderSize / 2, min, max);\n currentScrollValue = relativeY / height;\n this._slider.setAttribute('y', currentYPos, true);\n } else {\n const relativeX = viewX - this._viewPosition.x;\n const currentXPos = clamp(relativeX - sliderSize / 2, min, max);\n currentScrollValue = relativeX / width;\n this._slider.setAttribute('x', currentXPos, true);\n }\n\n this.setScrollRange(\n [currentScrollValue - (range[1] - range[0]) / 2, currentScrollValue + (range[1] - range[0]) / 2],\n false\n );\n\n if (!this.stage?.autoRender) {\n this.stage?.renderNextFrame();\n }\n };\n\n private _onSliderPointerDown = (e: FederatedPointerEvent) => {\n e.stopPropagation();\n const { direction } = this.attribute as ScrollBarAttributes;\n this._prePos = direction === 'horizontal' ? e.clientX : e.clientY;\n this._dispatchEvent('scrollDown', {\n pos: this._prePos,\n event: e\n });\n if (vglobal.env === 'browser') {\n vglobal.addEventListener('pointermove', this._onSliderPointerMove, { capture: true });\n vglobal.addEventListener('pointerup', this._onSliderPointerUp);\n } else {\n this.stage.addEventListener('pointermove', this._onSliderPointerMove, { capture: true });\n this.stage.addEventListener('pointerup', this._onSliderPointerUp);\n this.stage.addEventListener('pointerupoutside', this._onSliderPointerUp);\n }\n };\n\n private _computeScrollValue = (e: any) => {\n const { direction } = this.attribute as ScrollBarAttributes;\n let currentScrollValue;\n let currentPos;\n let delta = 0;\n\n const { width, height } = this._getSliderRenderBounds();\n if (direction === 'vertical') {\n currentPos = e.clientY;\n delta = currentPos - this._prePos;\n currentScrollValue = delta / height;\n } else {\n currentPos = e.clientX;\n delta = currentPos - this._prePos;\n currentScrollValue = delta / width;\n }\n return [currentPos, currentScrollValue];\n };\n\n private _onSliderPointerMove = delayMap[this.attribute.delayType]((e: any) => {\n e.stopPropagation();\n const preScrollRange = this.getScrollRange();\n const [currentPos, currentScrollValue] = this._computeScrollValue(e);\n this.setScrollRange([preScrollRange[0] + currentScrollValue, preScrollRange[1] + currentScrollValue], true);\n this._prePos = currentPos;\n }, this.attribute.delayTime);\n\n private _onSliderPointerUp = (e: any) => {\n e.preventDefault();\n const { realTime = true, range: preRange, limitRange = [0, 1] } = this.attribute as ScrollBarAttributes;\n // 发射 change 事件\n const preScrollRange = this.getScrollRange();\n const [currentPos, currentScrollValue] = this._computeScrollValue(e);\n const range: [number, number] = [preScrollRange[0] + currentScrollValue, preScrollRange[1] + currentScrollValue];\n if (!realTime) {\n this._dispatchEvent('scroll', {\n pre: preRange,\n value: clampRange(range, limitRange[0], limitRange[1])\n });\n }\n if (vglobal.env === 'browser') {\n vglobal.removeEventListener('pointermove', this._onSliderPointerMove, { capture: true });\n vglobal.removeEventListener('pointerup', this._onSliderPointerUp);\n } else {\n this.stage.removeEventListener('pointermove', this._onSliderPointerMove, { capture: true });\n this.stage.removeEventListener('pointerup', this._onSliderPointerUp);\n this.stage.removeEventListener('pointerupoutside', this._onSliderPointerUp);\n }\n };\n\n private _reset() {\n this._sliderRenderBounds = null;\n this._sliderLimitRange = null;\n }\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,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,KAAK,CAAC,qBAA+B,CAAC,CAAC,KAAK,EAAE,CAAC;IAC3E,MAAM,eAAe,GAAG,IAAI,KAAK,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,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oB,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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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"]}
|