@ap.cx/hues

中文文档
2.4.0发布于 2020/12/15MITESM + CJS零依赖近 30 天下载 2661

Hues [HYOOZ] is a very simple zero-dependency javascript (tiny) tested color library built for accessibility, RGBa and HSLa manupulation.

原始使用文档
文档目录25 节
  1. How to install
  2. How to use
  3. hues [HYOOZ] definition
  4. Functions
  5. SOON
  6. rgb2hex
  7. rgba2hex
  8. rgb2hsl
  9. rgba2hsla
  10. relativeLuminance
  11. WCAG definition of relative luminance
  12. contrast (A11y Contrast)
  13. aa
  14. aa
  15. str2rgba
  16. hslaVector3
  17. color-string
  18. What is Relative Luminance
  19. What is WCAG
  20. get code
  21. https
  22. SSH
  23. gh (github official cli)
  24. npm publish --access public
  25. License

hues [HYOOZ]

Hues [HYOOZ] is a very simple zero-dependency javascript (tiny) tested color library built for accessibility, RGBa and HSLa manupulation.

Color Hues, Tints, Shades, and Tones, Hues is just another word for colors. 🙃

How to install


npm install --save @ap.cx/hues

or 

yarn add @ap.cx/hues

How to use


import * as hues from "@ap.cx/hues";

or one by one ...


import str2rgba from "@ap.cx/hues";

or


const {
  str2rgba,
  rgba2hsla,
  rgb2hsl,
  hsla2rgba,
  hsl2rgb,
  rgba2hex,
  rgb2hex,
  contrast,
  relativeLuminance,
  aa,
  aaa,
} = require("@ap.cx/hues");

hues [HYOOZ] definition

A color or shade of a color.

Hues is the property of colors that makes them distinct from each other, as determined by the dominant wavelength of light — The hue associated with the shortest wavelengths of the visible spectrum is violet.

  • the sea has a magical turquoise hue today

  • all the hues of the rainbow

This small lib is about RGBa and HSLa colors and Accessibility (AA, AAA).

Functions

SOON

  • is colors blind (soon)
  • closest accessible color (soon)
  • closest colors blind safe color (soon)

rgb2hex


import { rgb2hex } from "@ap.cx/hues";

const result = rgb2hex({
  r: 1.0,
  g: 1.0,
  b: 1.0,
});

console.log(result);

> #ffffff

rgba2hex


import { rgba2hex } from "@ap.cx/hues";

const result = rgba2hex({
  r: 1.0,
  g: 1.0,
  b: 1.0,
  a: 1.0
});

console.log(result);

> #ffffffff

rgb2hsl


import { rgb2hsl } from "@ap.cx/hues";

const result = rgb2hsl({
  r: 1.0,
  g: 1.0,
  b: 1.0,
});

console.log(result);

> {
  h: 0,
  s: 0,
  l: 100,
}

Convert {r, g, b } object to { h, s, l} object.

rgba2hsla


import { rgba2hsla } from "@ap.cx/hues";

const result = rgb2hsl({
  r: 1.0,
  g: 1.0,
  b: 1.0,
  a: 1.0
});

console.log(result);

> {
  h: 0,
  s: 0,
  l: 100,
  a: 1,
}

Convert {r, g, b, a } object to { h, s, l, a } object.

relativeLuminance


import { relativeLuminance } from "@ap.cx/hues";

const result = relativeLuminance({
  r: 1.0,
  g: 1.0,
  b: 1.0,
  a: 1.0
});

console.log(result);

> 1

https://www.topster.net/relative-luminance/

WCAG definition of relative luminance

The relative brightness of any point in a colorspace, normalized to 0 for darkest black and 1 for lightest white.

https://www.w3.org/WAI/GL/wiki/Relative_luminance

contrast (A11y Contrast)

Compare 2 Relative Luminance and calculate the Accessibility ratio.

Text sizeLevel AALevel AAA
small text < 184.5+7+
large text >= 183+4.5+

Minimum required contrast ratio values


import { contrast, relativeLuminance } from "@ap.cx/hues";

const relativeLuminance1 = relativeLuminance({
  r: 1.0,
  g: 1.0,
  b: 1.0,
  a: 1.0
});

const relativeLuminance2 = relativeLuminance({
  r: 0.0,
  g: 0.0,
  b: 0.0,
  a: 0.0
});

const ratio = contrast(
  relativeLuminance1,
  relativeLuminance2,
);

console.log(ratio);

> 21

aa


import { aa } from "@ap.cx/hues";

const isAA = aa(ratio); // contrat ratio

console.log(isAA);

> true // or false

aa


import { aa } from "@ap.cx/hues";

const isAAA = aa(ratio); // contrat ratio

console.log(isAAA);

> true // or false

str2rgba


import { str2rgba } from "@ap.cx/hues";

Convert css color string to an rgba object of float.


const result = str2rgba('#ffffffff')

console.log(result);

> {
r: 1.0,
g: 1.0,
b: 1.0,
a: 1.0,
}

hslaVector3


import { hslaVector3 } from "@ap.cx/hues";

change hsl value.


const result = hslaVector3({ h: 0, s: 90, l: 90, a: 1 }, [0,0,1])

console.log(result);

> { h: 0, s: 90, l: 91, a: 1 };


color-string

If you would like to use color string take a look to https://github.com/Qix-/color-string.


What is Relative Luminance

Relative luminance follows the photometric definition of luminance, but with the values normalized to 1 or 100 for a reference white.[1] Like the photometric definition, it is related to the luminous flux density in a particular direction, which is radiant flux density weighted by the luminosity function y(λ) of the CIE Standard Observer. The use of relative values is useful in systems where absolute reproduction is impractical. For example, in prepress for print media, the absolute luminance of light reflecting off the print depends on the illumination and therefore absolute reproduction cannot be assured.


What is WCAG

Web Content Accessibility Guidelines(WCAG) is developed by W3C WAI (The World Wide Web Consortium Web Accessibility Initiative) with a goal of providing a single shared standard for web content accessibility. The WCAG documents explain how to make web content more accessible to people with visual, auditory, physical, speech, cognitive, language, learning, and neurological disabilities.

get code

https


git clone https://github.com/thierryc/hues.git

SSH


git clone [email protected]:thierryc/hues.git

gh (github official cli)


gh repo clone thierryc/hues

npm publish --access public

📦  @ap.cx/[email protected]
=== Tarball Contents ===
9.0kB  dist/hues.cjs.js
8.8kB  dist/hues.esm.js
10.0kB dist/hues.umd.js
695B   package.json
1.9kB  README.md
=== Tarball Details ===
name:          @ap.cx/hues
version:       2.0.1
package size:  5.6 kB
unpacked size: 30.5 kB
shasum:        36d55d09a0030aba49dc0146367e29970d652908
total files:   5  

License

MIT.

版本与发布记录

@ap.cx/hues 共发布 16 个版本,首次发布于 2020/10/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.4.0latest2020/12/155 年前
2.3.02020/12/155 年前
2.2.02020/10/316 年前
2.1.02020/10/136 年前
2.0.62020/10/136 年前
2.0.52020/10/106 年前

关于 @ap.cx/hues 的常见问题

@ap.cx/hues 是什么?

Hues [HYOOZ] is a very simple zero-dependency javascript (tiny) tested color library built for accessibility, RGBa and HSLa manupulation.

如何安装 @ap.cx/hues?

在项目目录运行 npm install @ap.cx/hues,或使用 pnpm add / yarn add / bun add。

@ap.cx/hues 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/ap.cx__hues 是否存在。

@ap.cx/hues 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ap.cx/hues 可以商用吗?

@ap.cx/hues 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ap.cx/hues 的下载量有多少?

根据 npm 官方下载统计,@ap.cx/hues 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,661 次,日均约 89 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ap.cx/hues 还在维护吗?

最新版本 2.4.0 发布于 2020/12/15(5 年前);至今共发布 16 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/10/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。