Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update 01_console.js
Browse files Browse the repository at this point in the history
Upstream some changes from nodejs/node#49205

Signed-off-by: Jordan Harband <[email protected]>
ljharb committed Oct 11, 2023
1 parent 27a813d commit 830bed6
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions ext/console/01_console.js
Original file line number Diff line number Diff line change
@@ -2742,34 +2742,34 @@ const HSL_PATTERN = new SafeRegExp(
);

function parseCssColor(colorString) {
if (MapPrototypeHas(colorKeywords, colorString)) {
colorString = MapPrototypeGet(colorKeywords, colorString);
if (colorKeywords.has(colorString)) {
colorString = colorKeywords.get(colorString);
}
// deno-fmt-ignore
const hashMatch = StringPrototypeMatch(colorString, HASH_PATTERN);
if (hashMatch != null) {
return [
Number(`0x${hashMatch[1]}`),
Number(`0x${hashMatch[2]}`),
Number(`0x${hashMatch[3]}`),
NumberParseInt(hashMatch[1], 16),
NumberParseInt(hashMatch[2], 16),
NumberParseInt(hashMatch[3], 16),
];
}
// deno-fmt-ignore
const smallHashMatch = StringPrototypeMatch(colorString, SMALL_HASH_PATTERN);
if (smallHashMatch != null) {
return [
Number(`0x${smallHashMatch[1]}${smallHashMatch[1]}`),
Number(`0x${smallHashMatch[2]}${smallHashMatch[2]}`),
Number(`0x${smallHashMatch[3]}${smallHashMatch[3]}`),
NumberParseInt(`${smallHashMatch[1]}${smallHashMatch[1]}`, 16),
NumberParseInt(`${smallHashMatch[2]}${smallHashMatch[2]}`, 16),
NumberParseInt(`${smallHashMatch[3]}${smallHashMatch[3]}`, 16),
];
}
// deno-fmt-ignore
const rgbMatch = StringPrototypeMatch(colorString, RGB_PATTERN);
if (rgbMatch != null) {
return [
MathRound(MathMax(0, MathMin(255, Number(rgbMatch[1])))),
MathRound(MathMax(0, MathMin(255, Number(rgbMatch[2])))),
MathRound(MathMax(0, MathMin(255, Number(rgbMatch[3])))),
MathRound(MathMax(0, MathMin(255, rgbMatch[1]))),
MathRound(MathMax(0, MathMin(255, rgbMatch[2]))),
MathRound(MathMax(0, MathMin(255, rgbMatch[3]))),
];
}
// deno-fmt-ignore
@@ -2780,8 +2780,8 @@ function parseCssColor(colorString) {
if (h < 0) {
h += 360;
}
const s = MathMax(0, MathMin(100, Number(hslMatch[2]))) / 100;
const l = MathMax(0, MathMin(100, Number(hslMatch[3]))) / 100;
const s = MathMax(0, MathMin(100, hslMatch[2])) / 100;
const l = MathMax(0, MathMin(100, hslMatch[3])) / 100;
const c = (1 - MathAbs(2 * l - 1)) * s;
const x = c * (1 - MathAbs((h / 60) % 2 - 1));
const m = l - c / 2;

0 comments on commit 830bed6

Please sign in to comment.