extract-css-colors
v1.0.3
Published
Extract color palettes from web elements
Readme
extract-css-colors
This ES module extracts all CSS colors from an element and its children.
Installation
npm i extract-css-colorsUsage
Syntax
cssColors(element)Return value
["rgb(0, 0, 0)", "rgba(0, 0, 0, 0)", ...]An array of strings. Each string being either a rgb() value or rgba() value. Color values include all colors found in the element and its children.
Example
import cssColors from './node_modules/extract-css-colors/index.js'
const el = document.getElementById('yourElement')
console.log( cssColors(el) )
/*
Array(12) [ "rgb(0, 0, 0)", "rgba(0, 0, 0, 0)", "rgb(255, 0, 0)", "rgb(0, 0, 255)", "rgb(0, 128, 0)", "rgb(255, 153, 0)", "rgb(128, 0, 128)", "rgb(255, 192, 203)", "rgb(100, 200, 100)", "rgb(165, 42, 42)", … ]
*/Notes
Only the following CSS properties are used by the module to generate the color palette.
| CSS Property | Source of Colors | |-------------------|--------------------| | color | Text color | | backgroundColor | Background color | | borderTopColor | Top border color | | borderRightColor | Right border color | | borderBottomColor | Bottom border color| | borderLeftColor | Left border color | | backgroundImage | Background gradient|
License
Released under MIT by @blubitz.
Contributing
If you want to help fix a bug or add new features,
- Fork this repository
- Apply changes
- Submit a pull request
