rgb(51, 102, 153)hsl(210, 50%, 40%)所有操作方法原地修改实例并返回 this,支持链式调用。如需保留原色,先 .clone()。
rgb(51, 102, 153)hsl(210, 50%, 40%)rgb(71, 133, 194)hsl(210, 50%, 52%)rgb(92, 133, 173)hsl(210, 33%, 52%)rgb(92, 133, 173)hsl(210, 33%, 52%)import xcolor from '@xpyjs/color'
const original = xcolor('#336699').alpha(1)
original.clone().lighten(20).toRgbString()
original.clone().brighten(20).toRgbString()
original.clone().tint(20).toRgbString()将 HSL 亮度按剩余区间推向白色。amount 为当前亮度到 100% 之间距离的百分比(0–100),默认 10;50 走到剩余距离的一半,100 必定为白色。
xcolor('#ff0000').lighten(20).toHex() // '#ff3333'将 HSL 亮度按当前区间推向黑色。amount 为当前亮度到 0% 之间距离的百分比(0–100),默认 10;50 走到剩余距离的一半,100 必定为黑色。等价于 lighten(-amount)。
xcolor('#ff0000').darken(20).toHex() // '#cc0000'在 RGB 空间将各通道推向 255。默认 10,范围 0–100。
xcolor('#ff0000').brighten(50).toHex() // '#ff8080'增加 HSL 饱和度。默认 10,范围 0–100。
xcolor('#bf4040').saturate(40).toHex() // '#f20d0d'减少 HSL 饱和度。默认 10。
xcolor('#ff0000').desaturate(50).toHex() // '#bf4040'完全去饱和,等价于 desaturate(100)。
别名:greyscale()
xcolor('#ff0000').grayscale().toHex() // '#808080'在 HSL 色轮上旋转色相。支持正负值,自动取模 360°。
别名:rotate()
xcolor('#ff0000').spin(120).toHex() // '#00ff00'
xcolor('#ff0000').spin(-120).toHex() // '#0000ff'RGB 各通道取反(255 - channel),alpha 不变。
别名:invert()
xcolor('#ff0000').negate().toHex() // '#00ffff'降低不透明度。alpha 减少 amount / 100,默认 10。
别名:fadeOut()
xcolor('#ff0000').fade(50).alpha() // 0.5增加不透明度。alpha 增加 amount / 100,默认 10。
别名:fadeIn()
xcolor('rgba(255,0,0,0.5)').opaquer(30).alpha() // 0.8在 RGB 空间与另一个颜色线性混合。amount 为目标颜色的权重(0–100),默认 50。
xcolor('#ff0000').mix('#0000ff', 50).toHex() // '#800080'与白色混合。amount 为白色的权重(0–100),默认 50。
xcolor('#ff0000').tint(50).toHex() // '#ff8080'与黑色混合。amount 为黑色的权重(0–100),默认 50。
xcolor('#ff0000').shade(50).toHex() // '#800000'| 方法 | 参数 | 默认值 | 返回值 | 别名 |
|---|---|---|---|---|
lighten(amount?) | 0–100 | 10 | this | — |
darken(amount?) | 0–100 | 10 | this | — |
brighten(amount?) | 0–100 | 10 | this | — |
saturate(amount?) | 0–100 | 10 | this | — |
desaturate(amount?) | 0–100 | 10 | this | — |
grayscale() | — | — | this | greyscale() |
spin(degrees) | 任意数 | — | this | rotate() |
negate() | — | — | this | invert() |
fade(amount?) | 0–100 | 10 | this | fadeOut() |
opaquer(amount?) | 0–100 | 10 | this | fadeIn() |
mix(color, amount?) | 0–100 | 50 | this | — |
tint(amount?) | 0–100 | 50 | this | — |
shade(amount?) | 0–100 | 50 | this | — |