Author: Robert Ginda rginda@google.com
Port to Node.js: Mike Acton macton@gmail.com
The bulk of this file is color palettes. The rest is a few simple utility functions
npm install dot-colors
And use with var colors = require("dot-colors")
If you have questions, the best place to ask is the chromium-hterm google group
If you want to contribute to the upstream, the best place to ask is the chromium-hterm google group
If you would like to contribute to this port, I have some things in mind:
- Merge in some of the functionality of colors
- Figure out a (good) way to automate the generation of this readme file.
- Make some tests.
- Add examples to this readme in the API section.
- rgbToX11
- x11ToCSS
- hexToRGB
- rgbToHex
- normalizeCSS
- arrayToRGBA
- setAlpha
- mix
- crackRGB
- nameToRGB
- stockColorPalette
colors = require('dot-colors');
x11Value = colors.rgbToX11( rgbValue );
Convert a CSS rgb(ddd,ddd,ddd) color value into an X11 color value. Other CSS color values are ignored to ensure sanitary data handling. Each 'ddd' component is a one byte value specified in decimal.
The X11 color value or null if the value could not be converted.
colors = require('dot-colors');
cssValue = colors.x11ToCSS( x11Value );
Convert an X11 color value into an CSS rgb(...) color value.
The X11 value may be an X11 color name, or an RGB value of the form rgb:hhhh/hhhh/hhhh. If a component value is less than 4 digits it is padded out to 4, then scaled down to fit in a single byte.
The CSS color value or null if the value could not be converted.
colors = require('dot-colors');
rgbValue = colors.hexToRGB( hexValue );
Converts one or more CSS '#RRGGBB' color values into their rgb(...) form.
Arrays are converted in place. If a value cannot be converted, it is replaced with null.
The converted value or values.
colors = require('dot-colors');
hexValue = colors.rgbToHex( rgbValue );
Converts one or more CSS rgb(...) forms into their '#RRGGBB' color values.
If given an rgba(...) form, the alpha field is thrown away.
Arrays are converted in place. If a value cannot be converted, it is replaced with null.
The converted value or values.
colors = require('dot-colors');
normalizedValue = colors.normalizeCSS( cssValue );
Take any valid css color definition and turn it into an rgb or rgba value.
Returns null if the value could not be normalized.
colors = require('dot-colors');
rgbaValue = colors.template( arrayValueValue );
Convert a 3 or 4 element array into an rgba(...) string.
colors = require('dot-colors');
rgbaValue = colors.setAlpha( rgbValue );
Overwrite the alpha channel of an rgb/rgba color.
colors = require('dot-colors');
resultColor = colors.template( base, tint, percent );
Mix a percentage of a tint color into a base color.
colors = require('dot-colors');
rgbaValue = colors.crackRGB( colorValue );
Split an rgb/rgba color into an array of its components.
On success, a 4 element array will be returned. For rgb values, the alpha will be set to 1.
colors = require('dot-colors');
rgbColor = colors.nameToRGB( colorName );
Convert an X11 color name into a CSS rgb(...) value.
Names are stripped of spaces and converted to lowercase. If the name is unknown, null is returned.
This list of color name to RGB mapping is derived from the stock X11 rgb.txt file.
The corresponding CSS rgb(...) value.
colors = require('dot-colors');
palette = colors.stockColorPalette;
The stock color palette. in RGB form.
Array of 256 colors, in this order:
- The "ANSI 16"
- The 6x6 color cubes
- The greyscale ramp