Skip to content

Commit

Permalink
Add new optional module for parsing named colors
Browse files Browse the repository at this point in the history
  • Loading branch information
LeaVerou committed Dec 10, 2020
1 parent 2e0d6f0 commit 4576b96
Show file tree
Hide file tree
Showing 3 changed files with 779 additions and 1 deletion.
6 changes: 6 additions & 0 deletions get/modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@
"name": "Chromatic adaptation",
"id": "CATs",
"description": "Color.js core only supports chromatic adaptation between D50 and D65 using the linear Bradford method. This module supports chromatic adaptation between arbitrary illuminants (with 9 presets) using Bradford, Van Kries, CAT02, or CAT16."
},
{
"name": "Color keywords",
"id": "keywords",
"path": ".",
"description": "To parse [CSS named colors](https://www.w3.org/TR/css-color-4/#named-colors) in Node, and to improve performance when parsing named colors in the client-side."
}
]
}
4 changes: 3 additions & 1 deletion src/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,9 @@ export default class Color {

if (!/^color|^rgb/.test(name) && hasDOM && document.head) {
// Use browser to parse when a DOM is available
// we only use this for color names right now, but also for future-proofing
// we mainly use this for color names right now if keywords.js is not included
// and for future-proofing

let previousColor = document.head.style.color;
document.head.style.color = "";
document.head.style.color = str;
Expand Down
Loading

0 comments on commit 4576b96

Please sign in to comment.