All Projects β†’ cdonohue β†’ Polychrome

cdonohue / Polychrome

Licence: mit
🎨 Easy color manipulation in ~2kb (gzipped)

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Polychrome

Colorpicker
jQuery UI widget for color picking (similar to the one in Microsoft Office 2010).
Stars: ✭ 271 (-5.24%)
Mutual labels:  palette, color
Immutable Styles
A library for styling web interfaces with a focus on predictability and robustness. It uses immutability to remove side effects often tied to CSS, allowing UI bugs to be caught ahead of time!
Stars: ✭ 69 (-75.87%)
Mutual labels:  immutable, css-in-js
Chartjs Plugin Colorschemes
Predefined color schemes for Chart.js
Stars: ✭ 189 (-33.92%)
Mutual labels:  palette, color
Calico
cat, but for colors 😼
Stars: ✭ 122 (-57.34%)
Mutual labels:  palette, color
ColorBlender
A .NET library for color matching and palette design.
Stars: ✭ 27 (-90.56%)
Mutual labels:  color, palette
Glidepalette
Android Lollipop Palette is now easy to use with Glide
Stars: ✭ 1,670 (+483.92%)
Mutual labels:  palette, color
Scoped Style
A tiny css in js library πŸš€
Stars: ✭ 129 (-54.9%)
Mutual labels:  tiny, css-in-js
Color.js
Extract colors from an image (0.75 KB) 🎨
Stars: ✭ 42 (-85.31%)
Mutual labels:  palette, color
pantone-colors
Hex values of all 2310 Pantone colors
Stars: ✭ 147 (-48.6%)
Mutual labels:  color, palette
anypalette.js
🎨 Read/write all color palette file formats β€πŸ§‘πŸ’›πŸ’šπŸ’™πŸ’œ
Stars: ✭ 41 (-85.66%)
Mutual labels:  color, palette
Xcodecolorsense
🎈 An Xcode plugin that makes working with color easier
Stars: ✭ 79 (-72.38%)
Mutual labels:  palette, color
material-design-color-palette
🎨Material Design color palette pluin for IntelliJ based IDEs.
Stars: ✭ 19 (-93.36%)
Mutual labels:  color, palette
Color Names
Large list of handpicked color names 🌈
Stars: ✭ 1,198 (+318.88%)
Mutual labels:  palette, color
Styled Theme
Extensible theming system for styled-components πŸ’…
Stars: ✭ 183 (-36.01%)
Mutual labels:  palette, css-in-js
Kirby Color Palette
A color palette to pick colors from in the panel. Kirby 3 only.
Stars: ✭ 47 (-83.57%)
Mutual labels:  palette, color
React Colorful
🎨 A tiny (2,5 KB) color picker component for React and Preact apps
Stars: ✭ 951 (+232.52%)
Mutual labels:  tiny, color
Alembic
βš—οΈ Extract a color palette from Sketch images
Stars: ✭ 565 (+97.55%)
Mutual labels:  palette, color
R Color Palettes
Comprehensive list of color palettes available in r β€οΈπŸ§‘πŸ’›πŸ’šπŸ’™πŸ’œ
Stars: ✭ 708 (+147.55%)
Mutual labels:  palette, color
hcv-color
🌈 Color model HCV/HCG is an alternative to HSV and HSL, derived by Munsell color system, usable for Dark and Light themes... 🌈
Stars: ✭ 44 (-84.62%)
Mutual labels:  color, palette
javascript-color-gradient
Lightweight JavaScript library, used to generate an array of color gradients, between start and finish colors.
Stars: ✭ 54 (-81.12%)
Mutual labels:  color, palette

polychrome

A small ~2kB (gzipped) library for parsing and manipulating colors

logo

Installation

feel free to replace yarn add with npm install

$> yarn add polychrome

Usage

// using ES6 modules
import polychrome from "polychrome";

// using CommonJS modules
const polychrome = require("polychrome");
// Make a polychrome color from hex, rgb(a), and hsl(a) strings
const red = polychrome("#F00");

// Get a string representation of a polychrome color in other formats
red.rgb() // "rgb(255,0,0)"

// Manipulate polychrome colors
const darkerRed = red.darken(20); // (pass in an integer percentage)
darkerRed.hsl() // "hsl(0,100%,40%)"

// Chain polychrome methods together before outputting
polychrome("#F00").darken(20).fadeOut(60).rgb() // "rgba(204,0,0,0.4)"

API Reference

Polychrome Object

polychrome(colorString)

colorString can be a hex (3 or 6 digit), rgb(a), or hsl(a) string. Returns a polychrome object.

A polychrome object consists of the following properties:

  • rHex - 2 character hex string representation of the red color channel
  • gHex - 2 character hex string representation of the green color channel
  • bHex - 2 character hex string representation of the blue color channel
  • r - value of the red color channel [0 - 255]
  • g - value of the green color channel [0 - 255]
  • b - value of the blue color channel [0 - 255]
  • h - hue of the color [0 - 360]
  • s - saturation of the color [0 - 100]
  • l - lightness of the color [0 - 100]
  • luma - luma value of the color [0 - 255]

In addition to the above properties, the following methods are available to a polychrome for outputting CSS color strings:

  • .hex() - returns a 6-digit hexadecimal CSS compatible color string

    polychrome("rgb(0, 0, 0)").hex() // "#000000"
    
  • .rgb() - returns an rgb(a) CSS compatible color string

    // rgba will be used if an alpha value exists
    polychrome("#000").rgb()           // "rgb(0,0,0)"
    polychrome("#000").fadeOut(60).rgb() // "rgba(0,0,0,.4)"
    
  • .hsl() - returns an hsl(a) CSS compatible color string

    // hsla will be used if an alpha value exists
    polychrome("#000").hsl()           // "hsl(0,0%,0%)"
    polychrome("#000").fadeOut(60).hsl() // "hsla(0,0%,0%,.4)"
    

Alpha

  • .setAlpha(value)

    Returns a polychrome with an alpha value absolutely set to value. No change occurs if value is omitted.

  • .fadeIn(percentage)

    Returns a polychrome faded in by percentage. Default 50 if no percentage is passed in.

  • .fadeOut(percentage)

    Returns a polychrome faded out by percentage. Default 50 if no percentage is passed in.

Contrast

  • .contrast(dark, light)

    Checks luma value of polychrome and returns dark or light polychrome depending on the contrast level. If a contrast ratio of at least 4.5:1 is not met, the dark/light colors will be darkened / lightened until a valid ratio is met.

    polychrome("#000").contrast().rgb() // "rgb(255,255,255)"
    
    polychrome("#DDD").contrast("#333", "#EEE").hex() // "#333333"
    

    dark and light can be a String or polychrome. They default to black (#000) and white (#FFF) if params are not passed in.

Hue

  • .setHue(value)

    Returns a polychrome with a hue value absolutely set to value. No change occurs if value is omitted.

  • .spin(degrees)

    Returns a polychrome with a hue value rotated degrees. Can be a positive or negative degree value. When bounds of [0 - 360] are reached, hue will continue in a circular fashion until it has been spun the full amount.

  • .complimentary()

    Returns a polychrome with a hue value rotated 180 degrees. Shorthand for .spin(180).

Lightness

  • .setLightness(value)

    Returns a polychrome with a lightness value absolutely set to value. No change occurs if value is omitted.

  • .lighten(percentage)

    Returns a polychrome lightened by percentage. Default 10 if no percentage is passed in.

  • .darken(percentage)

    Returns a polychrome darkened by percentage. Default 10 if no percentage is passed in.

Mix

  • .mix(otherColor)

    Returns a polychrome mixed with otherColor. otherColor can be another polychrome or a color string that will be parsed.

  • .tint()

    Returns a polychrome mixed with white (#FFFFFF). Shorthand for .mix("#FFFFFF").

  • .shade()

    Returns a polychrome mixed with black (#000000). Shorthand for .mix("#000000").

Saturation

  • .setSaturation(value)

    Returns a polychrome with a saturation value absolutely set to value. No change occurs if value is omitted.

  • .saturate(percentage)

    Returns a polychrome saturated by percentage. Default 10 if no percentage is passed in.

  • .desaturate(percentage)

    Returns a polychrome desaturated by percentage. Default 10 if no percentage is passed in.

  • .grayscale()

    Returns a polychrome with saturation set to 0. Shorthand for .setSaturation(0).


License

MIT License 2017 Β© Chad Donohue

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].