Skip to content

Commit cbb8c23

Browse files
committed
Make non-absolute colors invalid in @font-palette-values/override-colors
1 parent 5a7aad3 commit cbb8c23

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

__tests__/stylesheet.js

+5
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,11 @@ describe('CSS grammar - semantic', () => {
14681468
14691469
style {}
14701470
color: red;
1471+
override-colors: 0 currentcolor;
1472+
override-colors: 0 AccentColor;
1473+
override-colors: 0 light-dark(red, red);
1474+
override-colors: 0 contrast-color(red);
1475+
override-colors: 0 device-cmyk(0 0 0 0);
14711476
14721477
base-palette: initial;
14731478
base-palette: inherit(--custom);

lib/parse/postprocess.js

+19
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,25 @@ function postParseCalcValue(value) {
250250
return value.types[0] === '<simple-block>' ? value.value : value
251251
}
252252

253+
/**
254+
* @param {object} color
255+
* @param {object} node
256+
* @returns {SyntaxError|object}
257+
* @see {@link https://drafts.csswg.org/css-fonts-4/#descdef-font-palette-values-override-colors}
258+
*
259+
* It aborts parsing when the color is not an absolute color for override-colors
260+
* in @font-palette-values.
261+
*/
262+
function postParseColor(color, node) {
263+
if (
264+
node.context.declaration?.definition.name === 'override-colors'
265+
&& !color.types.includes('<color-base>')
266+
) {
267+
return error(node)
268+
}
269+
return color
270+
}
271+
253272
/**
254273
* @param {object|object[]} schemes
255274
* @param {object} node

0 commit comments

Comments
 (0)