Skip to content

Commit

Permalink
chore: add support for engine ARGB colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Caele committed Dec 16, 2022
1 parent 7697cb0 commit cd82b9f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions apis/theme/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@ export default function theme() {
* theme.validateColor("FOO"); // returns undefined
*/
validateColor(...args) {
/* Added this to support the non-standard ARGB format from engine */
const colorString = args[0];
let matches;
/* eslint-disable no-cond-assign */
if (
typeof colorString === 'string' &&
(matches = /^ARGB\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i.exec(colorString))
) {
// ARGB(255,255,255,255)
const a = parseInt(matches[1], 10) / 255;
const r = parseInt(matches[2], 10);
const g = parseInt(matches[3], 10);
const b = parseFloat(matches[4], 10);
return `rgba(${r},${g},${b},${a})`;
}
/* eslint-enable no-cond-assign */

const c = d3color(...args);
return c ? c.toString() : undefined;
},
Expand Down

0 comments on commit cd82b9f

Please sign in to comment.