1 Star 3 Fork 1

簡 Kan / colorsea

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

COLORSEA

详细文档请点这里

minzipped size typescript license last commit build

English | 简体中文

🧐 关于

colorsea.js是一个轻量的使用Typescript编写的颜色工具库

  • 你可以使用此进行颜色空间的转换(RGB, HSL, HSV, HSI, HWB, XYZ, LAB, LCH, xyY)。
  • 像LESS/SASS那样对颜色进行调整,如darken/lighten, saturate/desaturate, spin, fadeIn/fadeOut, mix等方法,单简易上手。
  • 支持CMC(l:c)CIE2000、 CIE1994、 CIE1976等色差查询。
  • 还可以使用X11中国传统色日本传统色等颜色名称来取得颜色。

🏁 快速上手

安装

npm install colorsea 

导入和使用

导入

ES Module

import colorsea from 'colorsea'

CommonJs

const colorsea = require('colorsea')

Browser

<script src="path/to/colorsea.js"></script>

颜色空间转换

// ----- color conversion
colorsea('#ff0000').rgb() // [255, 0, 0]
colorsea('#ff0000', 50).rgba() // [255, 0, 0, 50]
// colorsea() 函数可以创建一个Color实例
const color = colorsea('#405060')
color.rgba() // [255, 0, 0, 50]
color.xyz() // [7.09, 7.67, 12.17]
color.lab() // [33.29, -1.94, -11.36] 
// Convert from other color spaces
colorsea.xyz(7.09, 7.67, 12.17).rgb() // [64, 80, 96]
colorsea.hsl(210, 20, 31.37).rgb() // [64, 80, 96]
// ... Other color spaces are similar

颜色操作

// ---- Color operations
const color = colorsea('#ffffff')
const newColor = color.darken(10) // All operations will return a new Color instance object
newColor.hex() // #e6e6e6
colorsea('#000').lighten(10).hex() // #1a1a1a
colorsea('#ff0000').spin(180).hex() // #00ffff
colorsea.hsl(80, 90, 20).saturate(10).hsl() // [80, 100, 20]
colorsea.hsl(80, 90, 20).desaturate(10).hsl() // [80, 80, 20]
colorsea('#776600').fadeOut(10).rgba() // [119, 102, 0, 90]

const color1 = new Color('#ff0000')
const color2 = new Color('#0000ff')
const color = color1.mix(color2, 20)
color.hex() // #cc0033

色差计算

const color1 = colorsea.lab(80, 30, 120) // 标准色(参考色)
const color2 = colorsea.lab(79, 28, 100) // 样品色

// 使用CMC(1:1)公式
color1.deltaE(color2, 'CMC') // 5.754...
// 参数二默认为'CMC' 故可省略参数二
color1.deltaE(color2)

// CMC(2:1)公式, 只需把权重因子l设为2即可 (c默认为1)
color1.deltaE(color2, 'CMC', { l: 2 }) // 5.719...

// 使用CIE2000公式
color1.deltaE(color2, 'CIE2000') // 3.6815...

// 使用CIE1994公式
color1.deltaE(color2, 'CIE1994') // 3.3725...

// 使用CIE1976公式
color1.deltaE(color2, 'CIE1976') // 20.1246...

使用颜色名称

import colorsea from 'colorsea'
import x11 from 'colorsea/colors/x11'
// 载入X11颜色名
colorsea.useNames(x11)

// 此时你可以直接使用X11颜色名称来创建颜色
colorsea('Aqua') // color: #00ffff
colorsea('Aquamarine') // color: #7fffd4
import chinese from 'colorsea/colors/chinese' //中国传统色
import nippon from 'colorsea/colors/nippon' //日本传统色
// 同时载入两者
colorsea.useNames(chinese).useNames(nippon)

// 使用
colorsea('山梗紫') // color: #61649F
colorsea('水がき') // color: #B9887D

更明细的使用方式请参考文档: https://colorsea.js.org/zh/

参考

MIT License Copyright (c) 2022-present waterbeside Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一个使用Typescript编写的颜色工具库,你可以使用此进行颜色空间的转换,或进行颜色操作 展开 收起
TypeScript 等 2 种语言
MIT
取消

发行版 (1)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
TypeScript
1
https://gitee.com/waterbeside/colorsea.git
git@gitee.com:waterbeside/colorsea.git
waterbeside
colorsea
colorsea
main

搜索帮助

53164aa7 5694891 3bd8fe86 5694891