可读颜色
该项目提供了一种功能,用以确定一种颜色----根据 已建立算法 - 在特定背景上应易于读取.
示例使用大小写: 您要在未知的图形用户界面元素上显示文本 背景颜色 f.ex. 如果用户可以选择颜色或者颜色是 从其他数值中生成.
该项目披露了四种算法/方法:
- W3C( 如果没有指定方法默认): 见 http://www.w3.org/TR/AERT#color-contrast (中文(简体) )
- WCAG:见 https://www.w3.org/WAI/WCAG22/Techniques/general/G18.html (中文(简体) )
- 光度:前景和背景的光度差10%
- 轻度接触:见 https://colorusage.arc.nasa.gov/luminance-cont.php (中文(简体) )
见演示 https://codepen.io/米歇尔-阿尔伯特/pen/eYxrXeG
库会将背景颜色的"光"转换为可读 找到值。 如果找不到,它就会停在"全黑"或 "全白"("全白"). 后一种“ 断接” 可能导致仍然无法读取的颜色 根据所选方法,在边缘情况下.
注:迄今为止,通过《公约》,取得了最佳成果 W3C 财务报告和审定财务报表 WCAG
方法。 。 。 其余的仍然在场,以进行反向兼容和
参考文献.
示例
import { getReadableColor } from "@exhuma/readable-color";
// Get a readable color with the default method.
const readableColor = getReadableColor("#123456");
// example using another method.
const anotherColor = getReadableColor("#123456", "WCAG");
const theElement = document.getElementById("my-element");
theElement.style.color = readableColor;
发展
要安装依赖性 :
npm install
为建设:
npm run build
运行 dev 服务器 :
npm run dev
然后访问:http://localhost:5173/src/index.html