Skip to content

Commit

Permalink
resolve CSS color names when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Nov 16, 2021
1 parent c05ab64 commit 3a0835d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -65,6 +65,7 @@
"colors": "^1.1.2",
"commander": "8.2",
"css": "^3.0.0",
"css-color-names": "^1.0.1",
"deep-freeze-es6": "^1.4.1",
"del": "^6.0.0",
"dependency-resolver": "^2.0.1",
Expand Down
8 changes: 8 additions & 0 deletions tools/checkTheme.js
Expand Up @@ -4,6 +4,7 @@ const fs = require("fs");
const css = require("css");
const wcagContrast = require("wcag-contrast");
const Table = require('cli-table');
const csscolors = require('css-color-names');
// const colors = require('colors/safe.js');


Expand Down Expand Up @@ -199,6 +200,13 @@ class CSSRule {
this.bg = rule.declarations.find(x => x.property =="background")?.value;
this.fg = rule.declarations.find(x => x.property =="color")?.value;

if (this.bg) {
this.bg = csscolors[this.bg] || this.bg;
}
if (this.fg) {
this.fg = csscolors[this.fg] || this.fg;
}

// inherit from body if we're missing fg or bg
if (this.hasColor) {
if (!this.bg) this.bg = body.background;
Expand Down

0 comments on commit 3a0835d

Please sign in to comment.