Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

colorsea

waterbeside7.5kMIT1.2.2TypeScript support: included

A color tool library written in Typescript, you can use it to convert color spaces, and operate on colors like LESS/SASS ( darken/lighten, saturate/desaturate, spin, mix), and color difference query. 颜色工具库,支持颜色空间的转换、各种颜色操作、多种色差查询, 支持中国色、日本色的查询

color, convert, diff, rgb, deltaE, hue, lightness, saturation, hsl, color-diff, color-space, color-names, X11, CIE, CMC, 色差, 中国传统色, nippon colors

readme

COLORSEA

For detailed documents, please click here

minzipped size typescript license last commit build

English | 简体中文

About

colorsea.js is a tiny color tool library written in Typescript.

  • You can use it to convert color spaces (RGB, HSL, HSV, HSI, HWB, XYZ, LAB, LCH, xyY),
  • Adjust the color like LESS/SASS, such as darken/lighten, saturate/desaturate, spin, fadeIn/fadeOut, mix and other methods, easy to use.
  • Support CMC(l:c), CIE2000, CIE1994, CIE1976 color difference queries.
  • Support to use X11, Chinese Traditional Color, Japanese Traditional Color types of color names to get the color

Quick Start

Installation

npm install colorsea 

Import & Use

Import

ES Module

import colorsea from 'colorsea'

CommonJs

const colorsea = require('colorsea')

Browser

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

Color space conversion

// ----- color conversion
colorsea('#ff0000').rgb() // [255, 0, 0]
colorsea('#ff0000', 50).rgba() // [255, 0, 0, 50]
// The colorsea() function can create a Color instance
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

// ---- 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

Color difference calculation

const color1 = colorsea.lab(80, 30, 120) // Standard color (reference color)
const color2 = colorsea.lab(79, 28, 100) // Sample color

// CMC(1:1)
color1.deltaE(color2, 'CMC') // 5.754...

// CMC(2:1) formula, just set the weight factor l to 2 (c defaults to 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...

Use color names

import colorsea from 'colorsea'
import x11 from 'colorsea/colors/x11'
// Load X11 color names
colorsea.useNames(x11)

// At this point you can directly use the X11 color name to create the color instance
colorsea('Aqua') // color: #00ffff
colorsea('Aquamarine') // color: #7fffd4
import chinese from 'colorsea/colors/chinese' // Chinese traditional color
import nippon from 'colorsea/colors/nippon' // Japanese traditional color
// load both
colorsea.useNames(chinese).useNames(nippon)

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

For more detailed usage, please refer to the documentation: https://colorsea.js.org

Reference

changelog

1.2.2 (2024-03-02)

Bug Fixes

  • Fixed typescript declaration file error. #4 (2492124)

1.2.1 (2023-03-10)

Bug Fixes

  • parser: clamp rgb value between 0 and 255 (1684568)

1.2.0 (2023-03-10)

Bug Fixes

  • Fixed calculation of color.mix (51e58f6)
  • The hex2rgb convertor function, if hex does not set alpha, then the returned rgb will not return alpha either (e897d1d)

Features

  • The colorsea function adds a Settings parameter to the instance Settings (8d86102)
  • Allows you to throw error by setting whether an invalid color is entered (4de4447)
  • The colorsea function supports input with a color space string like 'hsl(100, 10%, 50%)' (ab16084)

1.1.0 (2023-02-03)

Features

  • Brightness method and visibility method , Check the visibility of one color over another. (12bca3f)

1.0.1 (2023-02-03)

Features