Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/css-color-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changes to CSS Color Parser

### Unreleased (patch)

- Fix `rgb()` to clamp out-of-range channels at parse time
- Keep out-of-range channels for relative `rgb()` colors

### 4.2.8

_November 17, 2026_
Expand Down
2 changes: 1 addition & 1 deletion packages/css-color-parser/dist/index.mjs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ColorData } from '../color-data';
import type { CSSToken } from '@csstools/css-tokenizer';

export type normalizeChannelValuesFn = (token: CSSToken, index: number, colorData: ColorData) => CSSToken | false;
export type normalizeChannelValuesFn = (token: CSSToken, index: number, colorData: ColorData, isRelativeColor: boolean) => CSSToken | false;
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function normalize_legacy_sRGB_ChannelValues(token: CSSToken, index: numb
return false;
}

export function normalize_modern_sRGB_ChannelValues(token: CSSToken, index: number, colorData: ColorData): CSSToken | false {
export function normalize_modern_sRGB_ChannelValues(token: CSSToken, index: number, colorData: ColorData, isRelativeColor: boolean): CSSToken | false {
if (isTokenIdent(token) && token[4].value.toLowerCase() === 'none') {
colorData.syntaxFlags.add(SyntaxFlag.HasNoneKeywords);

Expand All @@ -78,8 +78,10 @@ export function normalize_modern_sRGB_ChannelValues(token: CSSToken, index: numb
let value;
if (index === 3) {
value = normalize(token[4].value, 100, 0, 1);
} else {
} else if (isRelativeColor) {
value = normalize(token[4].value, 100, VALUE_FOR_NEGATIVE_INFINITY, VALUE_FOR_POSITIVE_INFINITY);
} else {
value = normalize(token[4].value, 100, 0, 1);
}

return [
Expand All @@ -102,8 +104,10 @@ export function normalize_modern_sRGB_ChannelValues(token: CSSToken, index: numb
let value;
if (index === 3) {
value = normalize(token[4].value, 1, 0, 1);
} else {
} else if (isRelativeColor) {
value = normalize(token[4].value, 255, VALUE_FOR_NEGATIVE_INFINITY, VALUE_FOR_POSITIVE_INFINITY);
} else {
value = normalize(token[4].value, 255, 0, 1);
}

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@ export function threeChannelLegacySyntax(
return false;
}

const channelValue1 = normalizeChannelValues(channel1[0].value, 0, colorData);
const channelValue1 = normalizeChannelValues(channel1[0].value, 0, colorData, false);
if (!channelValue1 || !isTokenNumber(channelValue1)) {
return false;
}

const channelValue2 = normalizeChannelValues(channel2[0].value, 1, colorData);
const channelValue2 = normalizeChannelValues(channel2[0].value, 1, colorData, false);
if (!channelValue2 || !isTokenNumber(channelValue2)) {
return false;
}

const channelValue3 = normalizeChannelValues(channel3[0].value, 2, colorData);
const channelValue3 = normalizeChannelValues(channel3[0].value, 2, colorData, false);
if (!channelValue3 || !isTokenNumber(channelValue3)) {
return false;
}
Expand All @@ -137,7 +137,7 @@ export function threeChannelLegacySyntax(
colorData.syntaxFlags.add(SyntaxFlag.HasAlpha);

if (isTokenNode(channelAlpha[0])) {
const channelValueAlpha = normalizeChannelValues(channelAlpha[0].value, 3, colorData);
const channelValueAlpha = normalizeChannelValues(channelAlpha[0].value, 3, colorData, false);
if (!channelValueAlpha || !isTokenNumber(channelValueAlpha)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,17 @@ export function threeChannelSpaceSeparated(
return false;
}

const channelValue1 = normalizeChannelValues(channel1[0].value, 0, colorData);
const channelValue1 = normalizeChannelValues(channel1[0].value, 0, colorData, !!relativeColorChannels);
if (!channelValue1 || !isTokenNumber(channelValue1)) {
return false;
}

const channelValue2 = normalizeChannelValues(channel2[0].value, 1, colorData);
const channelValue2 = normalizeChannelValues(channel2[0].value, 1, colorData, !!relativeColorChannels);
if (!channelValue2 || !isTokenNumber(channelValue2)) {
return false;
}

const channelValue3 = normalizeChannelValues(channel3[0].value, 2, colorData);
const channelValue3 = normalizeChannelValues(channel3[0].value, 2, colorData, !!relativeColorChannels);
if (!channelValue3 || !isTokenNumber(channelValue3)) {
return false;
}
Expand All @@ -196,7 +196,7 @@ export function threeChannelSpaceSeparated(
colorData.syntaxFlags.add(SyntaxFlag.HasAlpha);

if (isTokenNode(channelAlpha[0])) {
const channelValueAlpha = normalizeChannelValues(channelAlpha[0].value, 3, colorData);
const channelValueAlpha = normalizeChannelValues(channelAlpha[0].value, 3, colorData, !!relativeColorChannels);
if (!channelValueAlpha || !isTokenNumber(channelValueAlpha)) {
return false;
}
Expand All @@ -207,7 +207,7 @@ export function threeChannelSpaceSeparated(
}
} else if (relativeColorChannels && relativeColorChannels.has('alpha')) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const channelValueAlpha = normalizeChannelValues(relativeColorChannels.get('alpha')!, 3, colorData);
const channelValueAlpha = normalizeChannelValues(relativeColorChannels.get('alpha')!, 3, colorData, true);
if (!channelValueAlpha || !isTokenNumber(channelValueAlpha)) {
return false;
}
Expand Down
10 changes: 10 additions & 0 deletions packages/css-color-parser/test/basic/clamping.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ assertChannels('hsl(from red h s calc(l + 100))', [0, 100, 150]);
assertChannels('hsl(0 100% 50% / 200%)', [0, 100, 50], 1);
assertChannels('hsl(0, 100%, 50%, -1)', [0, 100, 50], 0);

// rgb() clamps channels to [0, 1] at parsed-value time.
assertChannels('rgb(300 0 0)', [1, 0, 0]);
assertChannels('rgb(120% 0% 0%)', [1, 0, 0]);
assertChannels('rgb(-10 0 0)', [0, 0, 0]);
assertChannels('rgb(calc(300) 0 0)', [1, 0, 0]);

// Relative rgb() keeps out of range channels.
assertChannels('rgb(from red calc(r * 2) g b)', [2, 0, 0]);
assertChannels('rgb(from red 120% 0% 0%)', [1.2, 0, 0]);

// hwb() does not clamp whiteness or blackness.
assertChannels('hwb(0 -10% 50%)', [0, -10, 50]);
assertChannels('hwb(0 50% -10%)', [0, 50, -10]);
Expand Down
34 changes: 17 additions & 17 deletions packages/css-color-parser/test/fuzzer/001.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ const tests = [
['lab( none 109.238199 exp(calc(41.244745 - -111.633189)) / 0.666667 )', 'lab(none 109.238199 2147483647 / 0.666667)'],
['lab( 0 34.345349 60.351098 / 0.485887 )', 'lab(0 34.345349 60.351098 / 0.485887)'],
['color( srgb hypot(0.309697, calc(infinity)) calc(pi) none )', 'color(srgb 2147483647 3.14159265 none)'],
['rgb( calc(nan) calc(-infinity) hypot(190.367303, 47.619085) )', 'rgb(0, -547608329985, 196)'],
['rgb( calc(nan) calc(-infinity) hypot(190.367303, 47.619085) )', 'rgb(0, 0, 196)'],
['hsl( 324.508768 16.219424 none )', 'hsl(324.508768 16.219424% none)'],
['lab( calc(exp(exp(-35.736885)) * calc(1.5 - 10.5)) hypot(calc(83.33333333333333 + calc(-213.139469 / 0.023263)), -69.308868) -86.897857 )', 'lab(0 9079.09727649 -86.897857)'],
['lch( from color( rec2020 0.079866 0 0.491405 ) h h 307.616522 / 0.704351 )', 'lch(100 301.27559807 307.616522 / 0.704351)'],
Expand All @@ -246,8 +246,8 @@ const tests = [
['lch( 12.349569 0 0 / 8.118691% )', 'lch(12.349569 0 0 / 0.08118691)'],
['oklab( none clamp(0, 0.4, -0.31355) none )', 'oklab(none 0 none)'],
['oklab( 0.749667 -0.108347 -0.030374 )', 'oklab(0.749667 -0.108347 -0.030374)'],
['rgb( calc(hypot(8.651031, 30.158795) * sin(4.699935)) calc(-infinity) 0 )', 'rgb(-31, -547608329985, 0)'],
['rgb( calc(41.934668 * 5.335925) calc(infinity) calc(min(calc(4.376725 * 5.981941), 0) * -0.175296) )', 'rgb(224, 547608329985, 0)'],
['rgb( calc(hypot(8.651031, 30.158795) * sin(4.699935)) calc(-infinity) 0 )', 'rgb(0, 0, 0)'],
['rgb( calc(41.934668 * 5.335925) calc(infinity) calc(min(calc(4.376725 * 5.981941), 0) * -0.175296) )', 'rgb(224, 255, 0)'],
['lab( 91.962401 -57.106492 none )', 'lab(91.962401 -57.106492 none)'],
['color( xyz 0 none 0.606987 )', 'color(xyz-d65 0 none 0.606987)'],
['lab( from color( from color( from color( prophoto-rgb 0.149298 calc(pi) none ) display-p3 none b g ) xyz-d65 0.158083 0.333333 x ) none none a / 0 )', 'lab(none none -65.03068511 / 0)'],
Expand All @@ -265,7 +265,7 @@ const tests = [
['oklab( 0 none none )', 'oklab(0 none none)'],
['color( rec2020 none 0 calc(0.186402 - hypot(1.373011, abs(1.481552))) )', 'color(rec2020 none 0 -1.83353749)'],
['rgb( 7.034704 none 140.564282 / 0 )', 'color(srgb 0.02758707 none 0.55123248 / 0)'],
['rgb( 221.421982 calc(infinity) 85 )', 'rgb(221, 547608329985, 85)'],
['rgb( 221.421982 calc(infinity) 85 )', 'rgb(221, 255, 85)'],
['hwb( from color( from color( xyz-d50 none 0.462028 none ) rec2020 none g none ) calc(209.662737) 33.333333 sin(50) / w )', 'color(srgb 0.33333333 0.67174065 1.00262375 / 0)'],
['rgb( 82.356354 6.836258 127.5 / 0.211586 )', 'rgba(82, 7, 128, 0.211586)'],
['rgb( 85 255 192.299594 )', 'rgb(85, 255, 192)'],
Expand Down Expand Up @@ -334,7 +334,7 @@ const tests = [
['oklch( 0.496417 calc(calc(0.4) / -1) 0 )', 'oklch(0.496417 0 0)'],
['hsl( 34.062099 63.150997 28.156925 )', 'rgb(117, 78, 26)'],
['hsl( from color( a98-rgb 0.136581 none 1 ) 4.593262 s abs(99.525702) )', 'color(srgb 1.00018017 0.99108764 0.99033387)'],
['rgb( calc(hypot(max(182.540061, 127.5), 255)) 104.409564 0 / 0.282385 )', 'rgba(314, 104, 0, 0.282385)'],
['rgb( calc(hypot(max(182.540061, 127.5), 255)) 104.409564 0 / 0.282385 )', 'rgba(255, 104, 0, 0.282385)'],
['lch( from color( prophoto-rgb 0.5 0 0.850156 ) sin(l) none hypot(cos(-75.655843deg), c) )', 'lch(0 none 138.85970627)'],
['lch( 100 53.400093 none )', 'lch(100 53.400093 none)'],
['hwb( 146.869882 75.278764 50 )', 'rgb(153, 153, 153)'],
Expand All @@ -349,7 +349,7 @@ const tests = [
['oklab( from color( srgb cos(calc(-193.880552deg)) 0.17222 0.401876 ) abs(1) exp(19.758458) -0.4 / exp(calc(-131.168232 - 150)) )', 'oklab(1 381056417.6690307 -0.4 / 0)'],
['oklab( 1 0.137281 0.216389 )', 'oklab(1 0.137281 0.216389)'],
['hsl( none 9.127923 82.120252 )', 'hsl(none 9.127923% 82.120252%)'],
['rgb( 8.209657 calc(infinity) 201.497298 )', 'rgb(8, 547608329985, 201)'],
['rgb( 8.209657 calc(infinity) 201.497298 )', 'rgb(8, 255, 201)'],
['lch( none 34.026504 calc(848.410495 / calc(infinity)) / calc(min(7.200019%, 9.113235%) * 3.078458) )', 'lch(none 34.026504 0 / 0.22164956)'],
['hwb( calc(0 - 75.469467) min(65.28164, 68.173873) calc(-infinity) )', 'rgb(4064215367, 744, 5476083555)'],
['color-mix( in lch shorter hue, color( srgb none 0.852753 0.854582 ) 7.084761%, color( srgb-linear 0.770019 0 0.446824 / 1 ) )', 'lch(53.56526189 83.94921589 329.20166048)'],
Expand All @@ -365,7 +365,7 @@ const tests = [
['lch( from color( xyz none 0.203698 calc(e) ) l 132.093395 none )', 'lch(46.35682563 132.093395 none)'],
['hsl( none 0 91.399751 )', 'hsl(none 0% 91.399751%)'],
['oklab( 0.333333 none none / 0.23913 )', 'oklab(0.333333 none none / 0.23913)'],
['rgb( 0 calc(min(154.891594, 168.671204) + calc(0 * calc(0.804693 * -2))) hypot(253.581822, 123.539315) )', 'rgb(0, 155, 282)'],
['rgb( 0 calc(min(154.891594, 168.671204) + calc(0 * calc(0.804693 * -2))) hypot(253.581822, 123.539315) )', 'rgb(0, 155, 255)'],
['color-mix( in lch decreasing hue, color( xyz 0.438429 0.333333 0.182531 ) 65.517522%, color( xyz-d50 0.159926 1 exp(0) ) 70.863026% )', 'lch(83.16861451 141.52675964 285.28381896)'],
['color-mix( in srgb , color( from color( xyz-d65 calc(-infinity) none 0.5 / 1 ) xyz x calc(infinity) x / 0.606142 ) , color( xyz 1 abs(0.208473) exp(99.35778) ) 87.070732% )', 'color(srgb -6834.53891777 3023.61051908 6903.23660205 / 0.94907704)'],
['hsl( 255.931738 100 none / sin(calc(2.849561 / -0.815669)) )', 'hsl(255.931738 100% none / 0.34471346)'],
Expand Down Expand Up @@ -482,8 +482,8 @@ const tests = [
['color( xyz-d65 none clamp(0, 0.834118, 0.666667) none )', 'color(xyz-d65 none 0.666667 none)'],
['rgb( 0 199.591156 0 )', 'rgb(0, 200, 0)'],
['rgb( from color( from color( srgb-linear 0.860652 calc(nan) 0.232488 ) prophoto-rgb calc(g * -1.9755) 0.762289 r ) calc(186.435162 - 0) alpha 0 / g )', 'color(srgb 0.73111828 0.00392157 0)'],
['rgb( 235.609923 47.283663 max(hypot(122.381937, calc(infinity)), 0) )', 'rgb(236, 47, 547608329985)'],
['rgb( none none calc(194.870173 / calc(calc(-0.2 * -1.79064))) )', 'color(srgb none none 2.13386487)'],
['rgb( 235.609923 47.283663 max(hypot(122.381937, calc(infinity)), 0) )', 'rgb(236, 47, 255)'],
['rgb( none none calc(194.870173 / calc(calc(-0.2 * -1.79064))) )', 'color(srgb none none 1)'],
['hwb( none none 0 )', 'hwb(none none 0%)'],
['lch( cos(-249.613732deg) 15.935866 none )', 'lch(0 15.935866 none)'],
['oklch( 0.157551 0.257946 340.696749 )', 'oklch(0.157551 0.257946 340.696749)'],
Expand Down Expand Up @@ -672,7 +672,7 @@ const tests = [
['color-mix( in oklab , color( xyz-d65 0.5 1 0.707001 ) 86.780841%, color( xyz 0.434354 0 0 ) 58.374914% )', 'oklab(0.71537597 0.22173415 0.0347467)'],
['color( xyz-d65 calc(1.5 - 0.382609) none none / calc(0 * 1.420297) )', 'color(xyz-d65 1.117391 none none / 0)'],
['hwb( from color( from color( from color( xyz-d65 0 0.640371 0 ) xyz-d50 none y 0.218355 ) prophoto-rgb calc(0.176119 * 1) b 0.841813 ) alpha calc(150 - 9.60653) none )', 'hwb(1 140.39347% none)'],
['rgb( 34.423485 cos(137.259953deg) 181.943202 / 0 )', 'rgba(34, -1, 182, 0)'],
['rgb( 34.423485 cos(137.259953deg) 181.943202 / 0 )', 'rgba(34, 0, 182, 0)'],
['lch( from color( xyz-d50 0.485835 1 none / abs(calc(pi)) ) 33.333333 150 360 / 0 )', 'lch(33.333333 150 0 / 0)'],
['color( xyz 0 none 0 )', 'color(xyz-d65 0 none 0)'],
['color-mix( in xyz , color( from color( xyz-d50 0 0.646835 none ) xyz-d65 none none none ) 9.390738%, color( display-p3 none 1 calc(clamp(0.762174, 2.761912, sin(2.215377)) / calc(e)) ) 38.277146% )', 'color(xyz-d65 none 0.69731514 0.11853887 / 0.47667884)'],
Expand All @@ -690,7 +690,7 @@ const tests = [
['rgb( 6.137159 46.821834 none )', 'color(srgb 0.02406729 0.18361504 none)'],
['rgb( 100.238788 calc(nan) min(230.399714, 55.948644) / 0.433542 )', 'rgba(100, 0, 56, 0.433542)'],
['hwb( 149.883621 16.652585 none )', 'hwb(149.883621 16.652585% none)'],
['rgb( calc(255) calc(infinity) 218.483173 )', 'rgb(255, 547608329985, 218)'],
['rgb( calc(255) calc(infinity) 218.483173 )', 'rgb(255, 255, 218)'],
['lab( none -121.766665 86.863635 )', 'lab(none -121.766665 86.863635)'],
['oklch( 0.190648 none none / 0.026023 )', 'oklch(0.190648 none none / 0.026023)'],
['oklab( 0.668551 0.042681 -0.173553 )', 'oklab(0.668551 0.042681 -0.173553)'],
Expand Down Expand Up @@ -819,7 +819,7 @@ const tests = [
['color( from color( a98-rgb hypot(0.441295, 0.250898) 0.129619 0.793012 ) a98-rgb alpha r b )', 'color(a98-rgb 1 0.50763282 0.793012)'],
['color( a98-rgb cos(143.643281deg) 0 none )', 'color(a98-rgb -0.80534183 0 none)'],
['hwb( none 1.912003 calc(nan) )', 'hwb(none 1.912003% 0%)'],
['rgb( calc(-infinity) 45.629366 calc(64.785731 + 79.096862) )', 'rgb(-547608329985, 46, 144)'],
['rgb( calc(-infinity) 45.629366 calc(64.785731 + 79.096862) )', 'rgb(0, 46, 144)'],
['rgb( 85 calc(e) none )', 'color(srgb 0.33333333 0.01065993 none)'],
['oklab( from color( xyz-d50 0.896587 none none ) 0 0.238907 b / 0 )', 'oklab(0 0.238907 -0.12316819 / 0)'],
['hwb( 0 85.349249 none )', 'hwb(0 85.349249% none)'],
Expand All @@ -833,7 +833,7 @@ const tests = [
['rgb( 107.504384 44.715789 63.392179 / calc(infinity) )', 'rgb(108, 45, 63)'],
['hwb( cos(calc(-315.484535deg)) 40.545692 88.205864 )', 'rgb(80, 80, 80)'],
['color( from color( display-p3-linear calc(e) exp(-98.38475) 0.191592 ) xyz-d50 none clamp(0.595533, y, x) y / none )', 'color(xyz-d50 none 0.6684061 0.6684061 / none)'],
['rgb( 246.797529 86.72983 cos(-209.768805deg) )', 'rgb(247, 87, -1)'],
['rgb( 246.797529 86.72983 cos(-209.768805deg) )', 'rgb(247, 87, 0)'],
['hwb( calc(infinity) min(69.411012, 8.767027) none )', 'hwb(0 8.767027% none)'],
['lab( 100 7.756526 calc(calc(calc(-2.681244 + 1.267682) + -16.28401) * -1.587916) )', 'lab(100 7.756526 28.10225774)'],
['lab( from color( from color( display-p3 none 0 0.388669 / 69.7914% ) xyz clamp(calc(-infinity), alpha, 0.976685) 0.105852 0.114207 / x ) l abs(-125) b / 1 )', 'lab(41.77753835 125 7.35004285)'],
Expand Down Expand Up @@ -881,7 +881,7 @@ const tests = [
['oklab( from color( xyz-d50 0.807268 0.32067 min(0.40868, 0.810885) ) 0 max(0, hypot(0.4, calc(-0.030582 * b))) -0.027123 )', 'oklab(0 0.40000441 -0.027123)'],
['lch( 38.548982 80.839976 0 )', 'lch(38.548982 80.839976 0)'],
['rgb( from color( display-p3 0.922505 0.5 sin(max(0.541511, 0)) ) 131.390712 0 g / 0.193651 )', 'color(srgb 0.51525769 0 0.4708239 / 0.193651)'],
['rgb( none 76.483413 calc(sin(321.062193) - 182.434759) )', 'color(srgb none 0.29993495 -0.71315268)'],
['rgb( none 76.483413 calc(sin(321.062193) - 182.434759) )', 'color(srgb none 0.29993495 0)'],
['hwb( 0 0 16.023368 )', 'rgb(214, 0, 0)'],
['hwb( from color( srgb none 0.652326 none ) 101.709879 33.333333 0 )', 'color(srgb 0.5365569 1 0.33333333)'],
['rgb( from color( display-p3-linear calc(nan) 0.5 none / calc(0.881721) ) b none 61.381502 )', 'color(srgb none none 0.24071177 / 0.881721)'],
Expand Down Expand Up @@ -921,9 +921,9 @@ const tests = [
['lab( 70.723038 none 1.708723 )', 'lab(70.723038 none 1.708723)'],
['hwb( from color( from color( from color( xyz-d50 0.70824 sin(0.617742) calc(0 / 1.5) ) a98-rgb calc(abs(g) * 5.654729) 1 0.5 ) xyz alpha alpha 0.88516 / 0.333333 ) 180 b calc(w) )', 'color(srgb -0.10750392 0.10008605 0.10008605 / 0.333333)'],
['oklch( from color( xyz 0.731925 0.504303 calc(1) ) 1 none 169.253276 )', 'oklch(1 none 169.253276)'],
['rgb( 42.734825 calc(calc(-infinity)) 26.151235 / 46.921044% )', 'rgba(43, -547608329985, 26, 0.46921044)'],
['rgb( 42.734825 calc(calc(-infinity)) 26.151235 / 46.921044% )', 'rgba(43, 0, 26, 0.46921044)'],
['rgb( none 28.384833 calc(255) )', 'color(srgb none 0.11131307 1)'],
['rgb( calc(315.133726 - 20.130989) 25.682903 min(calc(infinity), calc(infinity)) )', 'rgb(295, 26, 547608329985)'],
['rgb( calc(315.133726 - 20.130989) 25.682903 min(calc(infinity), calc(infinity)) )', 'rgb(255, 26, 255)'],
['lab( from color( display-p3 0.985932 0.689827 calc(infinity) / 1 ) max(0, 0) min(31.125646, sin(alpha)) 125 )', 'lab(0 0.84147098 125)'],
['color( a98-rgb 0.469468 clamp(0.907093, min(0, calc(0.324828)), 0.161473) none )', 'color(a98-rgb 0.469468 0.907093 none)'],
['lch( calc(nan) min(117.058827, 52.211435) max(10.858233, calc(min(5.567971, 24.534393) * 2.5)) )', 'lch(0 52.211435 13.9199275)'],
Expand All @@ -936,7 +936,7 @@ const tests = [
['hwb( 235.503096 15.303526 calc(pi) )', 'rgb(39, 55, 247)'],
['oklch( 0.175124 0.398179 103.679753 )', 'oklch(0.175124 0.398179 103.679753)'],
['oklab( 0.374014 -0.4 calc(infinity) )', 'oklab(0.374014 -0.4 2147483647)'],
['rgb( hypot(255, 255) 255 calc(abs(hypot(138.264497, 382.5)) - 116.192901) / min(47.246912%, 66.903079%) )', 'rgba(361, 255, 291, 0.47246912)'],
['rgb( hypot(255, 255) 255 calc(abs(hypot(138.264497, 382.5)) - 116.192901) / min(47.246912%, 66.903079%) )', 'rgba(255, 255, 255, 0.47246912)'],
['color( xyz 0.279771 0.001492 min(calc(calc(0.095947 + 0.031113) * 0.878689), 0.947537) )', 'color(xyz-d65 0.279771 0.001492 0.11164622)'],
['lab( 64.679206 clamp(18.393616, -31.404007, 105.178129) none )', 'lab(64.679206 18.393616 none)'],
['hwb( none exp(-2.462176) min(calc(abs(13.835308) * calc(infinity)), calc(27.554618 - 96.995669)) )', 'hwb(none 0.08524925% -69.441051%)'],
Expand Down
16 changes: 16 additions & 0 deletions plugins/postcss-color-functional-notation/test/basic.css
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,19 @@ to-clone {

result: var(--a);
}

.out-of-range-modern {
color: rgb(300 0 0);
}

.out-of-range-percentage {
color: rgb(120% 0% 0%);
}

.out-of-range-negative {
color: rgb(-10 0 0);
}

.out-of-range-relative {
color: rgb(from red calc(r * 2) g b);
}
16 changes: 16 additions & 0 deletions plugins/postcss-color-functional-notation/test/basic.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,19 @@ to-clone {

result: var(--a);
}

.out-of-range-modern {
color: rgb(255, 0, 0);
}

.out-of-range-percentage {
color: rgb(255, 0, 0);
}

.out-of-range-negative {
color: rgb(0, 0, 0);
}

.out-of-range-relative {
color: rgb(from red calc(r * 2) g b);
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,22 @@ to-clone {
--a: rgb(255 0 0 / var(--alpha-50));
}
}

.out-of-range-modern {
color: rgb(255, 0, 0);
color: rgb(300 0 0);
}

.out-of-range-percentage {
color: rgb(255, 0, 0);
color: rgb(120% 0% 0%);
}

.out-of-range-negative {
color: rgb(0, 0, 0);
color: rgb(-10 0 0);
}

.out-of-range-relative {
color: rgb(from red calc(r * 2) g b);
}
Loading
Loading