Skip to content

Commit fe90abf

Browse files
Address feedback: Lessen nesting
1 parent cc39297 commit fe90abf

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/common/color-element.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -151,30 +151,30 @@ const Self = class ColorElement extends NudeElement {
151151
try {
152152
return Self.Color.get(value);
153153
}
154-
catch {
155-
// Color.js can't parse the color value; possibly one of the values we can handle gracefully
156-
if (Self.#resolvedColors.has(value)) {
157-
let color = Self.#resolvedColors.get(value);
158-
return Self.Color.get(color);
159-
}
154+
catch {}
160155

161-
if (!globalThis.CSS?.supports("color", value) || !element) {
162-
// Not supported/invalid value, or no element to resolve the color value from
163-
return null;
164-
}
156+
// Color.js can't parse the color value; possibly one of the values we can handle gracefully
157+
if (Self.#resolvedColors.has(value)) {
158+
let color = Self.#resolvedColors.get(value);
159+
return Self.Color.get(color);
160+
}
165161

166-
// One of the supported color values; resolve and cache it
167-
element.style.backgroundColor = value;
168-
let color = getComputedStyle(element).backgroundColor;
169-
element.style.backgroundColor = "";
162+
if (!globalThis.CSS?.supports("color", value) || !element) {
163+
// Not supported/invalid value, or no element to resolve the color value from
164+
return null;
165+
}
170166

171-
let resolvedColor = Self.resolveColor(color);
172-
if (resolvedColor) {
173-
Self.#resolvedColors.set(value, color);
174-
}
167+
// One of the supported color values; resolve and cache it
168+
element.style.backgroundColor = value;
169+
let color = getComputedStyle(element).backgroundColor;
170+
element.style.backgroundColor = "";
175171

176-
return resolvedColor;
172+
let resolvedColor = Self.resolveColor(color);
173+
if (resolvedColor) {
174+
Self.#resolvedColors.set(value, color);
177175
}
176+
177+
return resolvedColor;
178178
}
179179
};
180180

0 commit comments

Comments
 (0)