From a30941888f492dfa2272cd6ff892da6d3212c3e5 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 17 Apr 2025 00:21:14 +0200 Subject: [PATCH] REFA: extended usage of _hex variable --- src/color.js | 7 +++++-- src/modifier.js | 14 +++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/color.js b/src/color.js index 1464d88..380be0b 100644 --- a/src/color.js +++ b/src/color.js @@ -12,7 +12,7 @@ class Color { #red; #green; #blue; - #hex; + _hex; /** * @@ -40,7 +40,10 @@ class Color { * @returns */ hex(hexcode) { - this.#hex = hexcode; + if (!hexcode.startsWith('#')) { + hexcode = '#' + hexcode; + } + this._hex = hexcode; return this; } } diff --git a/src/modifier.js b/src/modifier.js index 691a032..b48934b 100644 --- a/src/modifier.js +++ b/src/modifier.js @@ -174,11 +174,15 @@ class Modifier { * @returns {Modifier} this modifier object */ background(color) { - this._modifications["background-color"] = ( - color - ? color.cssRGBString() - : "inherit" - ); + if (color) { + if (color._hex) { + this._modifications["background-color"] = color._hex; + } else { + this._modifications["background-color"] = color.cssRGBString(); + } + } else { + this._modifications["background-color"] = "inherit"; + } return this; }