Skip to content
Open
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
2 changes: 1 addition & 1 deletion packages/css-color-parser/dist/index.mjs

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions packages/css-color-parser/src/color-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ export function colorDataTo(colorData: ColorData, toNotation: ColorNotation): Co
};

// Change any powerless components in src to missing components
colorData.channels = convertPowerlessComponentsToMissingComponents(colorData.channels, colorData.colorNotation);
Comment thread
romainmenke marked this conversation as resolved.
if (colorData.colorNotation !== toNotation) {
colorData.channels = convertPowerlessComponentsToMissingComponents(colorData.channels, colorData.colorNotation);
}

const outputColorData: ColorData = {
...colorData,
Expand Down Expand Up @@ -582,7 +584,9 @@ export function colorDataTo(colorData: ColorData, toNotation: ColorNotation): Co
}
}

outputColorData.channels = convertPowerlessComponentsToMissingComponents(outputColorData.channels, toNotation);
if (colorData.colorNotation !== toNotation) {
outputColorData.channels = convertPowerlessComponentsToMissingComponents(outputColorData.channels, toNotation);
}

return outputColorData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { parse } from '../util/parse.mjs';
import { serialize_OKLCH_data } from '../util/serialize.mjs';

const tests = [
['color-mix(in oklch, oklch(100% 0% 60deg), oklch(50% 50% 0deg))', 'oklch(0.75 0.1 0)'],
['color-mix(in oklch, oklch(100% 0% 60deg), oklch(50% 50% 0deg))', 'oklch(0.75 0.1 30)'],
['color-mix(in oklch, rgb(255, 255, 255), rgb(180, 6, 95))', 'oklch(0.75031 0.10016 359.858)'],
['color-mix(in lch, oklch(75% 0% 60deg), oklch(75% 50% 0deg))', 'oklch(0.74979 0.09824 0.10588)'],
['color-mix(in oklch, oklch(100% 0% none), oklch(50% 50% 0deg))', 'oklch(0.75 0.1 0)'],
['color-mix(in oklch, oklch(100% none 60deg), oklch(50% 50% 0deg))', 'oklch(0.75 0.2 0)'],
['color-mix(in oklch, oklch(100% none 60deg), oklch(50% 50% 0deg))', 'oklch(0.75 0.2 30)'],

// Analogous sets
['color-mix(in oklch, rgb(none none none), oklch(0.5 0.2 50))', 'oklch(0.5 0.2 50)'],
Expand Down
9 changes: 5 additions & 4 deletions packages/css-color-parser/test/basic/color-mix-function.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ const tests = [
['color-mix(in hsl increasing hue, hsl(180deg 50% 50%), hsl(180deg 50% 50%))', canonicalize('hsl(180deg 50% 50%)')],
['color-mix(in hsl decreasing hue, hsl(180deg 50% 50%), hsl(180deg 50% 50%))', canonicalize('hsl(180deg 50% 50%)')],

['color-mix(in hsl, color-mix(in hsl longer hue, hsl(50deg 0% 50%), hsl(50deg 0% 50%)), hsl(180deg 100% 50%))', canonicalize('hsl(180deg 50% 50%)')],
['color-mix(in hsl longer hue, hsl(50deg 0% 50%), hsl(50deg 0% 50%))', canonicalize('hsl(230deg 0% 50%)')],
['color-mix(in hsl, color-mix(in hsl longer hue, hsl(50deg 0% 50%), hsl(50deg 0% 50%)), hsl(180deg 100% 50%))', canonicalize('hsl(205deg 50% 50%)')],

['color-mix(in hsl, hsl(30deg 40% 80% / 25%) 0%, hsl(90deg none none / none))', canonicalize('hsl(30deg 40% 80% / 25%)')],
['color-mix(in hsl, hsl(30deg 40% 80% / 25%) 0%, hsl(90deg none none / none))', canonicalize('hsl(90deg 40% 80% / 25%)')],
['color-mix(in hwb, hwb(30deg 30% 40% / 25%) 0%, hwb(90deg none none / 0.5))', canonicalize('hwb(90deg 30% 40% / 0.5)')],
['color-mix(in hsl, hsl(from hsl(none 50% 50%) h s l), hsl(from hsl(120deg 50% 50%) h s l))', canonicalize('hsl(120deg 50% 50%)')],
['color-mix(in hsl, hsl(from hsl(0deg 50% 50%) none s l), hsl(from hsl(120deg 50% 50%) h s l))', canonicalize('hsl(120deg 50% 50%)')],
Expand Down Expand Up @@ -223,7 +224,7 @@ assert.deepStrictEqual(
color(parse('color-mix(in lch, lch(100 0 40deg), lch(100 0 60deg))')),
{
colorNotation: 'lch',
channels: [100, 0, Number.NaN],
channels: [100, 0, 50],
alpha: 1,
syntaxFlags: new Set(['color-mix']),
},
Expand Down Expand Up @@ -283,7 +284,7 @@ assert.deepStrictEqual(
color(parse('color-mix(in hsl, lch(none 0 30), hsl(50 0 none))')),
{
colorNotation: 'hsl',
channels: [Number.NaN, 0, Number.NaN],
channels: [50, 0, Number.NaN],
alpha: 1,
syntaxFlags: new Set(['color-mix']),
},
Expand Down
20 changes: 10 additions & 10 deletions packages/css-color-parser/test/basic/none-exhaustive.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
{
const tests = [
// https://github.com/w3c/csswg-drafts/issues/14095
['hsl(from hsl(180 none 50%) h s l)', 'hsl(none none 50%)'],
['hsl(from hsl(180 0 50%) h s l)', 'hsl(none 0% 50%)'],
['hsl(from hsl(180 none 50%) h s l)', 'hsl(180 none 50%)'],
['hsl(from hsl(180 0 50%) h s l)', 'color(srgb 0.5 0.5 0.5)'],
['hsl(from lch(20 none 180) h s l)', 'hsl(none none 18.93757452%)'],
['hsl(from lch(20 0 180) h s l)', 'hsl(none 0% 18.93757452%)'],

// https://github.com/w3c/csswg-drafts/issues/14100
['lch(from orchid l 0 h)', 'lch(62.75256542 0 326.96909222)'],
['lch(from lch(from orchid l 0 h) l c h)', 'lch(62.75256542 0 none)'],
['color-mix(in lch, lch(from orchid l 0 h))', 'lch(62.75256542 0 none)'],
['lch(from lch(from orchid l 0 h) l c h)', 'lch(62.75256542 0 326.96909222)'],
['color-mix(in lch, lch(from orchid l 0 h))', 'lch(62.75256542 0 326.96909222)'],

// exhaustive tests
// HSL
['hsl(from hsl(none 50% 50%) h s l)', 'hsl(none 50% 50%)'],
['hsl(from hsl(180 none 50%) h s l)', 'hsl(none none 50%)'],
['hsl(from hsl(180 none 50%) h s l)', 'hsl(180 none 50%)'],
['hsl(from hsl(180 50% none) h s l)', 'hsl(180 50% none)'],
['hsl(from hsl(none none 50%) h s l)', 'hsl(none none 50%)'],
['hsl(from hsl(180 none none) h s l)', 'hsl(none none none)'],
['hsl(from hsl(180 none none) h s l)', 'hsl(180 none none)'],
['hsl(from hsl(none 50% none) h s l)', 'hsl(none 50% none)'],
['hsl(from hsl(none none none) h s l)', 'hsl(none none none)'],

Expand Down Expand Up @@ -137,9 +137,9 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
['lch(from hwb(none none none) l c h)', 'lch(none none none)'],

['lch(from lch(none 20 180) l c h)', 'lch(none 20 180)'],
['lch(from lch(20 none 180) l c h)', 'lch(20 none none)'],
['lch(from lch(20 none 180) l c h)', 'lch(20 none 180)'],
['lch(from lch(20 20 none) l c h)', 'lch(20 20 none)'],
['lch(from lch(none none 180) l c h)', 'lch(none none none)'],
['lch(from lch(none none 180) l c h)', 'lch(none none 180)'],
['lch(from lch(20 none none) l c h)', 'lch(20 none none)'],
['lch(from lch(none 20 none) l c h)', 'lch(none 20 none)'],
['lch(from lch(none none none) l c h)', 'lch(none none none)'],
Expand Down Expand Up @@ -197,9 +197,9 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
['oklch(from lch(none none none) l c h)', 'oklch(none none none)'],

['oklch(from oklch(none 0.2 180) l c h)', 'oklch(none 0.2 180)'],
['oklch(from oklch(0.2 none 180) l c h)', 'oklch(0.2 none none)'],
['oklch(from oklch(0.2 none 180) l c h)', 'oklch(0.2 none 180)'],
['oklch(from oklch(0.2 0.2 none) l c h)', 'oklch(0.2 0.2 none)'],
['oklch(from oklch(none none 180) l c h)', 'oklch(none none none)'],
['oklch(from oklch(none none 180) l c h)', 'oklch(none none 180)'],
['oklch(from oklch(0.2 none none) l c h)', 'oklch(0.2 none none)'],
['oklch(from oklch(none 0.2 none) l c h)', 'oklch(none 0.2 none)'],
['oklch(from oklch(none none none) l c h)', 'oklch(none none none)'],
Expand Down
36 changes: 18 additions & 18 deletions packages/css-color-parser/test/basic/powerless-exhaustive.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
// exhaustive tests
// HSL
['hsl(from hsl(0 50% 50%) h s l)', 'color(srgb 0.75 0.25 0.25)'],
['hsl(from hsl(180 0 50%) h s l)', 'hsl(none 0% 50%)'],
['hsl(from hsl(180 0 50%) h s l)', 'color(srgb 0.5 0.5 0.5)'],
['hsl(from hsl(180 50% 0) h s l)', 'color(srgb 0 0 0)'],
['hsl(from hsl(0 0 50%) h s l)', 'hsl(none 0% 50%)'],
['hsl(from hsl(180 0 0) h s l)', 'hsl(none 0% 0%)'],
['hsl(from hsl(0 0 50%) h s l)', 'color(srgb 0.5 0.5 0.5)'],
['hsl(from hsl(180 0 0) h s l)', 'color(srgb 0 0 0)'],
['hsl(from hsl(0 50% 0) h s l)', 'color(srgb 0 0 0)'],
['hsl(from hsl(0 0 0) h s l)', 'hsl(none 0% 0%)'],
['hsl(from hsl(0 0 0) h s l)', 'color(srgb 0 0 0)'],

['hsl(from hwb(0 25% 25%) h s l)', 'color(srgb 0.75 0.25 0.25)'],
['hsl(from hwb(180 100% 25%) h s l)', 'hsl(none 0% 80%)'],
Expand Down Expand Up @@ -53,12 +53,12 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
['hwb(from hsl(0 0 0) h w b)', 'hwb(none 0% 100%)'],

['hwb(from hwb(0 25% 25%) h w b)', 'color(srgb 0.75 0.25 0.25)'],
['hwb(from hwb(180 100% 25%) h w b)', 'hwb(none 100% 25%)'],
['hwb(from hwb(180 25% 100%) h w b)', 'hwb(none 25% 100%)'],
['hwb(from hwb(0 100% 25%) h w b)', 'hwb(none 100% 25%)'],
['hwb(from hwb(180 100% 100%) h w b)', 'hwb(none 100% 100%)'],
['hwb(from hwb(0 25% 100%) h w b)', 'hwb(none 25% 100%)'],
['hwb(from hwb(0 100% 100%) h w b)', 'hwb(none 100% 100%)'],
['hwb(from hwb(180 100% 25%) h w b)', 'color(srgb 0.8 0.8 0.8)'],
['hwb(from hwb(180 25% 100%) h w b)', 'color(srgb 0.2 0.2 0.2)'],
['hwb(from hwb(0 100% 25%) h w b)', 'color(srgb 0.8 0.8 0.8)'],
['hwb(from hwb(180 100% 100%) h w b)', 'color(srgb 0.5 0.5 0.5)'],
['hwb(from hwb(0 25% 100%) h w b)', 'color(srgb 0.2 0.2 0.2)'],
['hwb(from hwb(0 100% 100%) h w b)', 'color(srgb 0.5 0.5 0.5)'],

['hwb(from lch(0 20 180) h w b)', 'color(srgb -0.13099833 0.05952886 -0.00460494)'],
['hwb(from lch(20 0 180) h w b)', 'hwb(none 18.93757452% 81.06242548%)'],
Expand Down Expand Up @@ -99,12 +99,12 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
['lch(from hwb(0 100% 100%) l c h)', 'lch(53.38896474 0 none)'],

['lch(from lch(0 20 180) l c h)', 'lch(0 20 180)'],
['lch(from lch(20 0 180) l c h)', 'lch(20 0 none)'],
['lch(from lch(20 0 180) l c h)', 'lch(20 0 180)'],
['lch(from lch(20 20 0) l c h)', 'lch(20 20 0)'],
['lch(from lch(0 0 180) l c h)', 'lch(0 0 none)'],
['lch(from lch(20 0 0) l c h)', 'lch(20 0 none)'],
['lch(from lch(0 0 180) l c h)', 'lch(0 0 180)'],
['lch(from lch(20 0 0) l c h)', 'lch(20 0 0)'],
['lch(from lch(0 20 0) l c h)', 'lch(0 20 0)'],
['lch(from lch(0 0 0) l c h)', 'lch(0 0 none)'],
['lch(from lch(0 0 0) l c h)', 'lch(0 0 0)'],

['lch(from oklch(0 0.2 180) l c h)', 'lch(0.00996014 2.6503948 181.20369565)'],
['lch(from oklch(0.2 0 180) l c h)', 'lch(7.22637037 0 none)'],
Expand Down Expand Up @@ -145,12 +145,12 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
['oklch(from lch(0 0 0) l c h)', 'oklch(0 0 none)'],

['oklch(from oklch(0 0.2 180) l c h)', 'oklch(0 0.2 180)'],
['oklch(from oklch(0.2 0 180) l c h)', 'oklch(0.2 0 none)'],
['oklch(from oklch(0.2 0 180) l c h)', 'oklch(0.2 0 180)'],
['oklch(from oklch(0.2 0.2 0) l c h)', 'oklch(0.2 0.2 0)'],
['oklch(from oklch(0 0 180) l c h)', 'oklch(0 0 none)'],
['oklch(from oklch(0.2 0 0) l c h)', 'oklch(0.2 0 none)'],
['oklch(from oklch(0 0 180) l c h)', 'oklch(0 0 180)'],
['oklch(from oklch(0.2 0 0) l c h)', 'oklch(0.2 0 0)'],
['oklch(from oklch(0 0.2 0) l c h)', 'oklch(0 0.2 0)'],
['oklch(from oklch(0 0 0) l c h)', 'oklch(0 0 none)'],
['oklch(from oklch(0 0 0) l c h)', 'oklch(0 0 0)'],

['oklch(from rgb(0 0 0) l c h)', 'oklch(0 0 none)'],
['oklch(from color(display-p3 0 0 0) l c h)', 'oklch(0 0 none)'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import { serialize_sRGB_data } from '../util/serialize.mjs';
['color-mix(in hsl, hsl(120deg 20% 40%), hsl(none none none))', canonicalize('hsl(120deg 20% 40%)')],
['color-mix(in hsl, hsl(120deg 20% none), hsl(30deg 40% 60%))', canonicalize('hsl(75deg 30% 60%)')],
['color-mix(in hsl, hsl(120deg 20% 40%), hsl(30deg 20% none))', canonicalize('hsl(75deg 20% 40%)')],
['color-mix(in hsl, hsl(none 20% 40%), hsl(30deg none 80%))', canonicalize('hsl(none 20% 60%)')],
['color-mix(in hsl, hsl(none 20% 40%), hsl(30deg none 80%))', canonicalize('hsl(30deg 20% 60%)')],

['color-mix(in hsl, hsl(120deg 40% 40% / none), hsl(0deg 40% 40%))', canonicalize('hsl(60deg 40% 40%)')],
['color-mix(in hsl, hsl(120deg 40% 40% / none), hsl(0deg 40% 40% / 0.5))', canonicalize('hsl(60deg 40% 40% / 0.5)')],
Expand Down Expand Up @@ -213,7 +213,7 @@ import { serialize_sRGB_data } from '../util/serialize.mjs';
['color-mix(in lch, lch(10 20 30deg), lch(none none none))', canonicalize('lch(10 20 30)')],
['color-mix(in lch, lch(10 20 none), lch(50 60 70deg))', canonicalize('lch(30 40 70)')],
['color-mix(in lch, lch(10 20 30deg), lch(50 60 none))', canonicalize('lch(30 40 30)')],
['color-mix(in lch, lch(none 20 30deg), lch(50 none 70deg))', canonicalize('lch(50 20 30)')],
['color-mix(in lch, lch(none 20 30deg), lch(50 none 70deg))', canonicalize('lch(50 20 50)')],
['color-mix(in lch, lch(10 20 30deg / none), lch(50 60 70deg))', canonicalize('lch(30 40 50)')],
['color-mix(in lch, lch(10 20 30deg / none), lch(50 60 70deg / 0.5))', canonicalize('lch(30 40 50 / 0.5)')],
['color-mix(in lch, lch(10 20 30deg / none), lch(50 60 70deg / none))', canonicalize('lch(30 40 50 / none)')],
Expand Down Expand Up @@ -293,14 +293,14 @@ import { serialize_sRGB_data } from '../util/serialize.mjs';
['color-mix(in oklch, oklch(0.1 0.2 30deg), oklch(none none none))', canonicalize('oklch(0.1 0.2 30)')],
['color-mix(in oklch, oklch(0.1 0.2 none), oklch(0.5 0.6 70deg))', canonicalize('oklch(0.3 0.4 70)')],
['color-mix(in oklch, oklch(0.1 0.2 30deg), oklch(0.5 0.6 none))', canonicalize('oklch(0.3 0.4 30)')],
['color-mix(in oklch, oklch(none 0.2 30deg), oklch(0.5 none 70deg))', canonicalize('oklch(0.5 0.2 30)')],
['color-mix(in oklch, oklch(none 0.2 30deg), oklch(0.5 none 70deg))', canonicalize('oklch(0.5 0.2 50)')],
['color-mix(in oklch, oklch(0.1 0.2 30deg / none), oklch(0.5 0.6 70deg))', canonicalize('oklch(0.3 0.4 50)')],
['color-mix(in oklch, oklch(0.1 0.2 30deg / none), oklch(0.5 0.6 70deg / 0.5))', canonicalize('oklch(0.3 0.4 50 / 0.5)')],
['color-mix(in oklch, oklch(0.1 0.2 30deg / none), oklch(0.5 0.6 70deg / none))', canonicalize('oklch(0.3 0.4 50 / none)')],

['color-mix(in oklch, oklch(0.1 0.2 30deg / 25%) 0%, oklch(0.5 none none / none))', canonicalize('oklch(0.5 0.2 30 / 0.25)')],
['color-mix(in oklch, oklch(0.1 0.2 30deg / 25%) 0%, oklch(none 0.5 none / none))', canonicalize('oklch(0.1 0.5 30 / 0.25)')],
['color-mix(in oklch, oklch(0.1 0.2 30deg / 25%) 0%, oklch(none none 90deg / none))', canonicalize('oklch(0.1 0.2 30 / 0.25)')],
['color-mix(in oklch, oklch(0.1 0.2 30deg / 25%) 0%, oklch(none none 90deg / none))', canonicalize('oklch(0.1 0.2 90 / 0.25)')],
['color-mix(in oklch, oklch(0.1 0.2 30deg / 25%) 0%, oklch(0.5 0.5 none / none))', canonicalize('oklch(0.5 0.5 30 / 0.25)')],
['color-mix(in oklch, oklch(0.1 0.2 30deg / 25%) 0%, oklch(none none none / 0.5))', canonicalize('oklch(0.1 0.2 30 / 0.5)')],
['color-mix(in oklch, oklch(0.1 0.2 30deg / 25%) 0%, oklch(0.5 none none / 0.5))', canonicalize('oklch(0.5 0.2 30 / 0.5)')],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@

.spec-example-25 {
--mygray: rgb(152, 152, 152);
--mymuted: rgb(201, 131, 153);
--mymuted: rgb(185, 136, 182);
}

.spec-example-26 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@

.spec-example-25 {
--mygray: rgb(152, 152, 152);
--mymuted: rgb(201, 131, 153);
--mymuted: rgb(185, 136, 182);
}

@supports (color: lab(from red l 1 1% / calc(alpha + 0.1))) {
Expand Down
Loading