1.0.3 • Published 5 months ago

extract-css-colors v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

npm npm bundle size License

extract-css-colors

This ES module extracts all CSS colors from an element and its children.

Installation

npm i extract-css-colors

Usage

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 PropertySource of Colors
colorText color
backgroundColorBackground color
borderTopColorTop border color
borderRightColorRight border color
borderBottomColorBottom border color
borderLeftColorLeft border color
backgroundImageBackground gradient

License

Released under MIT by @blubitz.

Contributing

If you want to help fix a bug or add new features, 1. Fork this repository 2. Apply changes 4. Submit a pull request

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago