Skip to content

Commit 92f46d0

Browse files
Address feedback: Improve API + add some docs
1 parent f6f88bc commit 92f46d0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/common/color-element.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ const Self = class ColorElement extends NudeElement {
3131
static Color;
3232
static all = {};
3333
static dependencies = new Set();
34-
static resolvedColors = new Map();
34+
35+
/** @type {Map<string, Color>} */
36+
static #resolvedColors = new Map();
3537

3638
static globalStyles = [{ css: baseGlobalStyles }];
3739

@@ -143,15 +145,16 @@ const Self = class ColorElement extends NudeElement {
143145
* Resolve a color value and cache it.
144146
* @param {string} value Color value to resolve.
145147
* @param {Element} element Element to get computed style from to resolve the color value.
148+
* @returns {Color | null} Resolved color value or null if the value cannot be resolved.
146149
*/
147150
static resolveColor (value, element) {
148151
try {
149152
return Self.Color.get(value);
150153
}
151154
catch {
152155
// Color.js can't parse the color value; possibly one of the values we can handle gracefully
153-
if (Self.resolvedColors.has(value)) {
154-
return Self.resolvedColors.get(value);
156+
if (Self.#resolvedColors.has(value)) {
157+
return Self.#resolvedColors.get(value);
155158
}
156159

157160
if (!CSS.supports("color", value)) {
@@ -162,7 +165,8 @@ const Self = class ColorElement extends NudeElement {
162165
// One of the supported color values; resolve and cache it
163166
element.style.backgroundColor = value;
164167
let color = getComputedStyle(element).backgroundColor;
165-
Self.resolvedColors.set(value, color);
168+
color = Self.Color.get(color);
169+
Self.#resolvedColors.set(value, color);
166170
element.style.backgroundColor = "";
167171

168172
return color;

0 commit comments

Comments
 (0)