Skip to content

Commit 4472cc7

Browse files
committed
Revert "revert"
This reverts commit aed29a6.
1 parent aed29a6 commit 4472cc7

3 files changed

Lines changed: 52 additions & 30 deletions

File tree

packages/css-color-parser/dist/index.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/css-color-parser/src/color-data.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,24 +598,46 @@ function convertPowerlessComponentsToMissingComponents(a: Color, colorNotation:
598598
case ColorNotation.HSL:
599599
if ((Number.isNaN(out[1]) ? 0 : out[1]) <= 0.001) {
600600
out[0] = Number.NaN;
601+
602+
if ((Number.isNaN(out[1]) ? 0 : out[1]) > 0 && !Number.isNaN(out[1])) {
603+
out[1] = 0;
604+
}
601605
}
602606

603607
break;
604608
case ColorNotation.HWB:
605609
if ((Math.max(0, (Number.isNaN(out[1]) ? 0 : out[1])) + Math.max(0, (Number.isNaN(out[2]) ? 0 : out[2]))) >= 99.999) {
606610
out[0] = Number.NaN;
611+
612+
if ((Math.max(0, (Number.isNaN(out[1]) ? 0 : out[1])) + Math.max(0, (Number.isNaN(out[2]) ? 0 : out[2]))) < 100) {
613+
if (!Number.isNaN(out[1]) && !Number.isNaN(out[2])) {
614+
out[2] = 100 - out[1];
615+
} else if (!Number.isNaN(out[1])) {
616+
out[1] = 100;
617+
} else if (!Number.isNaN(out[2])) {
618+
out[2] = 100;
619+
}
620+
}
607621
}
608622

609623
break;
610624
case ColorNotation.LCH:
611625
if ((Number.isNaN(out[1]) ? 0 : out[1]) <= 0.0015) {
612626
out[2] = Number.NaN;
627+
628+
if ((Number.isNaN(out[1]) ? 0 : out[1]) > 0 && !Number.isNaN(out[1])) {
629+
out[1] = 0;
630+
}
613631
}
614632

615633
break;
616634
case ColorNotation.OKLCH:
617635
if ((Number.isNaN(out[1]) ? 0 : out[1]) <= 0.000004) {
618636
out[2] = Number.NaN;
637+
638+
if ((Number.isNaN(out[1]) ? 0 : out[1]) > 0 && !Number.isNaN(out[1])) {
639+
out[1] = 0;
640+
}
619641
}
620642

621643
break;

packages/css-color-parser/test/basic/powerless-exhaustive.mjs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
1313
['hsl(from hsl(0 50% 0) h s l)', 'color(srgb 0 0 0)'],
1414
['hsl(from hsl(0 0 0) h s l)', 'color(srgb 0 0 0)'],
1515

16-
['hsl(from hsl(180 0.001% 50%) h s l)', 'color(srgb 0.500005 0.499995 0.499995)'],
16+
['hsl(from hsl(180 0.001% 50%) h s l)', 'color(srgb 0.5 0.5 0.5)'],
1717
['hsl(from hsl(180 0.0011% 50%) h s l)', 'color(srgb 0.4999945 0.5000055 0.5000055)'],
1818

1919
['hsl(from hwb(0 25% 25%) h s l)', 'color(srgb 0.75 0.25 0.25)'],
@@ -24,7 +24,7 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
2424
['hsl(from hwb(0 25% 100%) h s l)', 'hsl(none 0% 20%)'],
2525
['hsl(from hwb(0 100% 100%) h s l)', 'hsl(none 0% 50%)'],
2626

27-
['hsl(from hwb(180 49.999% 50%) h s l)', 'hsl(none 0.00100001% 49.9995%)'],
27+
['hsl(from hwb(180 49.999% 50%) h s l)', 'hsl(none 0% 49.999%)'],
2828
['hsl(from hwb(180 49.998% 50%) h s l)', 'color(srgb 0.49998 0.5 0.5)'],
2929

3030
['hsl(from lch(0 20 180) h s l)', 'color(srgb -0.13099833 0.05952886 -0.00460494)'],
@@ -35,7 +35,7 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
3535
['hsl(from lch(0 20 0) h s l)', 'color(srgb 0.13099833 -0.05952886 0.00460494)'],
3636
['hsl(from lch(0 0 0) h s l)', 'hsl(none 0% 0%)'],
3737

38-
['hsl(from lch(20 0.0015 180) h s l)', 'hsl(none 0.00309202% 18.93788137%)'],
38+
['hsl(from lch(20 0.0015 180) h s l)', 'hsl(none 0% 18.93757452%)'],
3939
['hsl(from lch(20 0.00151 180) h s l)', 'color(srgb 0.18936676 0.18937855 0.18937554)'],
4040

4141
['hsl(from oklch(0 0.2 180) h s l)', 'color(srgb -0.0266189 0.00845442 0.00006795)'],
@@ -46,19 +46,19 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
4646
['hsl(from oklch(0 0.2 0) h s l)', 'color(srgb 0.0266189 -0.00845442 -0.00006795)'],
4747
['hsl(from oklch(0 0 0) h s l)', 'hsl(none 0% 0%)'],
4848

49-
['hsl(from oklch(0.2 0.000004 180) h s l)', 'hsl(none 0.00551409% 8.61063148%)'],
49+
['hsl(from oklch(0.2 0.000004 180) h s l)', 'hsl(none 0% 8.61042044%)'],
5050
['hsl(from oklch(0.2 0.0000041 180) h s l)', 'color(srgb 0.08609717 0.08610691 0.08610449)'],
5151

5252
['hsl(from rgb(0 0 0) h s l)', 'hsl(none 0% 0%)'],
5353
['hsl(from color(display-p3 0 0 0) h s l)', 'hsl(none 0% 0%)'],
5454
['hsl(from lab(0 0 0) h s l)', 'hsl(none 0% 0%)'],
5555
['hsl(from oklab(0 0 0) h s l)', 'hsl(none 0% 0%)'],
5656

57-
['hsl(from color(display-p3 0.50000322 0.49999533 0.49999517) h s l)', 'hsl(none 0.00099966% 49.99999965%)'],
57+
['hsl(from color(display-p3 0.50000322 0.49999533 0.49999517) h s l)', 'hsl(none 0% 49.99999965%)'],
5858
['hsl(from color(display-p3 0.49999645 0.50000513 0.50000531) h s l)', 'color(srgb 0.4999945 0.5000055 0.5000055)'],
5959

6060
['color(from hsl(180 0% 50%) display-p3 r g b)', 'color(display-p3 0.5 0.5 0.5)'],
61-
['color(from hsl(180 0.001% 50%) display-p3 r g b)', 'color(display-p3 0.50000322 0.49999533 0.49999517)'],
61+
['color(from hsl(180 0.001% 50%) display-p3 r g b)', 'color(display-p3 0.5 0.5 0.5)'],
6262
['color(from hsl(180 0.0011% 50%) display-p3 r g b)', 'color(display-p3 0.49999645 0.50000513 0.50000531)'],
6363

6464
// HWB
@@ -70,7 +70,7 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
7070
['hwb(from hsl(0 50% 0) h w b)', 'hwb(none 0% 100%)'],
7171
['hwb(from hsl(0 0 0) h w b)', 'hwb(none 0% 100%)'],
7272

73-
['hwb(from hsl(180 0.001% 50%) h w b)', 'hwb(none 49.9995% 49.9995%)'],
73+
['hwb(from hsl(180 0.001% 50%) h w b)', 'hwb(none 50% 50%)'],
7474
['hwb(from hsl(180 0.0011% 50%) h w b)', 'color(srgb 0.4999945 0.5000055 0.5000055)'],
7575

7676
['hwb(from hwb(0 25% 25%) h w b)', 'color(srgb 0.75 0.25 0.25)'],
@@ -81,15 +81,15 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
8181
['hwb(from hwb(0 25% 100%) h w b)', 'color(srgb 0.2 0.2 0.2)'],
8282
['hwb(from hwb(0 100% 100%) h w b)', 'color(srgb 0.5 0.5 0.5)'],
8383

84-
['hwb(from hwb(180 99.999% 0%) h w b)', 'color(srgb 1 0.99999 0.99999)'],
84+
['hwb(from hwb(180 99.999% 0%) h w b)', 'color(srgb 0.99999 0.99999 0.99999)'],
8585
['hwb(from hwb(180 99.999% none) h w b)', 'hwb(180 99.999% none)'],
86-
['hwb(from hsl(from hwb(180 99.999% none) h s l) h w b)', 'hwb(none 99.999% 0%)'],
86+
['hwb(from hsl(from hwb(180 99.999% none) h s l) h w b)', 'hwb(none 100% 0%)'],
8787
['hwb(from hwb(180 99.998% 0%) h w b)', 'color(srgb 0.99998 1 1)'],
88-
['hwb(from hwb(180 0% 99.999%) h w b)', 'color(srgb 0.00001 0 0)'],
88+
['hwb(from hwb(180 0% 99.999%) h w b)', 'color(srgb 0 0 0)'],
8989
['hwb(from hwb(180 none 99.999%) h w b)', 'hwb(180 none 99.999%)'],
90-
['hwb(from hsl(from hwb(180 none 99.999%) h s l) h w b)', 'hwb(none 0% 99.999%)'],
90+
['hwb(from hsl(from hwb(180 none 99.999%) h s l) h w b)', 'hwb(none 0% 100%)'],
9191
['hwb(from hwb(180 0% 99.998%) h w b)', 'color(srgb 0 0.00002 0.00002)'],
92-
['hwb(from hwb(180 49.999% 50%) h w b)', 'color(srgb 0.5 0.49999 0.49999)'],
92+
['hwb(from hwb(180 49.999% 50%) h w b)', 'color(srgb 0.49999 0.49999 0.49999)'],
9393
['hwb(from hwb(180 49.998% 50%) h w b)', 'color(srgb 0.49998 0.5 0.5)'],
9494

9595
['hwb(from lch(0 20 180) h w b)', 'color(srgb -0.13099833 0.05952886 -0.00460494)'],
@@ -100,7 +100,7 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
100100
['hwb(from lch(0 20 0) h w b)', 'color(srgb 0.13099833 -0.05952886 0.00460494)'],
101101
['hwb(from lch(0 0 0) h w b)', 'hwb(none 0% 100%)'],
102102

103-
['hwb(from lch(20 0.0015 180) h w b)', 'hwb(none 18.93729581% 81.06153307%)'],
103+
['hwb(from lch(20 0.0015 180) h w b)', 'hwb(none 18.93757452% 81.06242548%)'],
104104
['hwb(from lch(20 0.00151 180) h w b)', 'color(srgb 0.18936676 0.18937855 0.18937554)'],
105105

106106
['hwb(from oklch(0 0.2 180) h w b)', 'color(srgb -0.0266189 0.00845442 0.00006795)'],
@@ -111,19 +111,19 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
111111
['hwb(from oklch(0 0.2 0) h w b)', 'color(srgb 0.0266189 -0.00845442 -0.00006795)'],
112112
['hwb(from oklch(0 0 0) h w b)', 'hwb(none 0% 100%)'],
113113

114-
['hwb(from oklch(0.8 0.000004 180) h w b)', 'hwb(none 74.3202188% 25.67843825%)'],
114+
['hwb(from oklch(0.8 0.000004 180) h w b)', 'hwb(none 74.3205918% 25.6794082%)'],
115115
['hwb(from oklch(0.8 0.0000041 180) h w b)', 'color(srgb 0.74319598 0.74320974 0.74320633)'],
116116

117117
['hwb(from rgb(0 0 0) h w b)', 'hwb(none 0% 100%)'],
118118
['hwb(from color(display-p3 0 0 0) h w b)', 'hwb(none 0% 100%)'],
119119
['hwb(from lab(0 0 0) h w b)', 'hwb(none 0% 100%)'],
120120
['hwb(from oklab(0 0 0) h w b)', 'hwb(none 0% 100%)'],
121121

122-
['hwb(from color(display-p3 0.50000322 0.49999533 0.49999517) h w b)', 'hwb(none 49.99949982% 49.99950052%)'],
122+
['hwb(from color(display-p3 0.50000322 0.49999533 0.49999517) h w b)', 'hwb(none 49.99949982% 50.00050018%)'],
123123
['hwb(from color(display-p3 0.49999645 0.50000513 0.50000531) h w b)', 'color(srgb 0.4999945 0.5000055 0.5000055)'],
124124

125125
['color(from hwb(180 50% 50%) display-p3 r g b)', 'color(display-p3 0.5 0.5 0.5)'],
126-
['color(from hwb(180 49.999% 50%) display-p3 r g b)', 'color(display-p3 0.49999822 0.49999033 0.49999017)'],
126+
['color(from hwb(180 49.999% 50%) display-p3 r g b)', 'color(display-p3 0.49999 0.49999 0.49999)'],
127127
['color(from hwb(180 49.998% 50%) display-p3 r g b)', 'color(display-p3 0.49998355 0.49999934 0.49999966)'],
128128

129129
// LCH
@@ -135,8 +135,8 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
135135
['lch(from hsl(0 50% 0) l c h)', 'lch(0 0 none)'],
136136
['lch(from hsl(0 0 0) l c h)', 'lch(0 0 none)'],
137137

138-
['lch(from hsl(180 0.001% 50%) l c h)', 'lch(53.38868718 0.00105193 none)'],
139-
['lch(from hsl(180 0.0011% 50%) l c h)', 'lch(53.38927006 0.00115711 none)'],
138+
['lch(from hsl(180 0.001% 50%) l c h)', 'lch(53.38896474 0 none)'],
139+
['lch(from hsl(180 0.0011% 50%) l c h)', 'lch(53.38927006 0 none)'],
140140

141141
['lch(from hwb(0 25% 25%) l c h)', 'lch(46.42043661 59.74639249 29.95665674)'],
142142
['lch(from hwb(180 100% 25%) l c h)', 'lch(82.04578167 0 none)'],
@@ -146,7 +146,7 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
146146
['lch(from hwb(0 25% 100%) l c h)', 'lch(21.24673129 0 none)'],
147147
['lch(from hwb(0 100% 100%) l c h)', 'lch(53.38896474 0 none)'],
148148

149-
['lch(from hwb(180 99.999% 0%) l c h)', 'lch(99.99931609 0.00092512 none)'],
149+
['lch(from hwb(180 99.999% 0%) l c h)', 'lch(99.99912038 0 none)'],
150150
['lch(from hwb(180 99.998% 0%) l c h)', 'lch(99.99960858 0.00185022 199.69899791)'],
151151

152152
['lch(from lch(0 20 180) l c h)', 'lch(0 20 180)'],
@@ -168,19 +168,19 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
168168
['lch(from oklch(0 0.2 0) l c h)', 'lch(0 2.6503948 1.20369565)'],
169169
['lch(from oklch(0 0 0) l c h)', 'lch(0 0 none)'],
170170

171-
['lch(from oklch(0.2 0.000004 180) l c h)', 'lch(7.22632342 0.00126523 none)'],
172-
['lch(from oklch(0.2 0.0000041 180) l c h)', 'lch(7.22641849 0.00129685 none)'],
171+
['lch(from oklch(0.2 0.000004 180) l c h)', 'lch(7.22637037 0 none)'],
172+
['lch(from oklch(0.2 0.0000041 180) l c h)', 'lch(7.22641849 0 none)'],
173173

174174
['lch(from rgb(0 0 0) l c h)', 'lch(0 0 none)'],
175175
['lch(from color(display-p3 0 0 0) l c h)', 'lch(0 0 none)'],
176176
['lch(from lab(0 0 0) l c h)', 'lch(0 0 none)'],
177177
['lch(from oklab(0 0 0) l c h)', 'lch(0 0 none)'],
178178

179-
['lch(from color(display-p3 0.1893689 0.18937814 0.18937561) l c h)', 'lch(19.99999973 0.00149922 none)'],
179+
['lch(from color(display-p3 0.1893689 0.18937814 0.18937561) l c h)', 'lch(19.99999973 0 none)'],
180180
['lch(from color(display-p3 0.18936885 0.18937816 0.18937561) l c h)', 'lch(19.99999994 0.00151062 180.02568063)'],
181181

182182
['color(from lch(20 0 180) display-p3 r g b)', 'color(display-p3 0.18937575 0.18937575 0.18937575)'],
183-
['color(from lch(20 0.0015 180) display-p3 r g b)', 'color(display-p3 0.18938259 0.18937335 0.18937588)'],
183+
['color(from lch(20 0.0015 180) display-p3 r g b)', 'color(display-p3 0.18937575 0.18937575 0.18937575)'],
184184
['color(from lch(20 0.00151 180) display-p3 r g b)', 'color(display-p3 0.18936885 0.18937816 0.18937561)'],
185185

186186
// oklch
@@ -192,8 +192,8 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
192192
['oklch(from hsl(0 50% 0) l c h)', 'oklch(0 0 none)'],
193193
['oklch(from hsl(0 0 0) l c h)', 'oklch(0 0 none)'],
194194

195-
['oklch(from hsl(180 0.001% 50%) l c h)', 'oklch(0.59817861 0.00000307 none)'],
196-
['oklch(from hsl(180 0.0011% 50%) l c h)', 'oklch(0.59818306 0.00000338 none)'],
195+
['oklch(from hsl(180 0.001% 50%) l c h)', 'oklch(0.59818073 0 none)'],
196+
['oklch(from hsl(180 0.0011% 50%) l c h)', 'oklch(0.59818306 0 none)'],
197197

198198
['oklch(from hwb(0 25% 25%) l c h)', 'oklch(0.55233858 0.16366995 24.21253898)'],
199199
['oklch(from hwb(180 100% 25%) l c h)', 'oklch(0.84522226 0 none)'],
@@ -203,7 +203,7 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
203203
['oklch(from hwb(0 25% 100%) l c h)', 'oklch(0.32109251 0 none)'],
204204
['oklch(from hwb(0 100% 100%) l c h)', 'oklch(0.59818073 0 none)'],
205205

206-
['oklch(from hwb(180 99.999% 0%) l c h)', 'oklch(0.99999435 0.0000027 none)'],
206+
['oklch(from hwb(180 99.999% 0%) l c h)', 'oklch(0.99999242 0 none)'],
207207
['oklch(from hwb(180 99.998% 0%) l c h)', 'oklch(0.99999614 0.00000541 197.15830446)'],
208208

209209
['oklch(from lch(0 20 180) l c h)', 'oklch(0 0.26412556 175.27132911)'],
@@ -214,7 +214,7 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
214214
['oklch(from lch(0 20 0) l c h)', 'oklch(0.05666101 0.26412556 355.27132911)'],
215215
['oklch(from lch(0 0 0) l c h)', 'oklch(0 0 none)'],
216216

217-
['oklch(from lch(20 0.0015 180) l c h)', 'oklch(0.31034531 0.00000443 none)'],
217+
['oklch(from lch(20 0.0015 180) l c h)', 'oklch(0.31034483 0 none)'],
218218
['oklch(from lch(20 0.00151 180) l c h)', 'oklch(0.31034434 0.00000446 179.50900432)'],
219219

220220
['oklch(from oklch(0 0.2 180) l c h)', 'oklch(0 0.2 180)'],
@@ -233,11 +233,11 @@ import { computedValue, reducePrecisionWholeValue } from '../util/serialize.mjs'
233233
['oklch(from lab(0 0 0) l c h)', 'oklch(0 0 none)'],
234234
['oklch(from oklab(0 0 0) l c h)', 'oklch(0 0 none)'],
235235

236-
['oklch(from color(display-p3 0.08610937692934956 0.08610188202042188 0.08610387292082256) l c h)', 'oklch(0.2 0.000004 none)'],
236+
['oklch(from color(display-p3 0.08610937692934956 0.08610188202042188 0.08610387292082256) l c h)', 'oklch(0.2 0 none)'],
237237
['oklch(from color(display-p3 0.0860989 0.08610658 0.08610454) l c h)', 'oklch(0.2 0.0000041 179.99967542)'],
238238

239239
['color(from oklch(0.5 0 180) display-p3 r g b)', 'color(display-p3 0.38857286 0.38857286 0.38857286)'],
240-
['color(from oklch(0.5 0.000004 180) display-p3 r g b)', 'color(display-p3 0.38857936 0.38856994 0.38857244)'],
240+
['color(from oklch(0.5 0.000004 180) display-p3 r g b)', 'color(display-p3 0.38857286 0.38857286 0.38857286)'],
241241
['color(from oklch(0.5 0.0000041 180) display-p3 r g b)', 'color(display-p3 0.38856619 0.38857585 0.38857329)'],
242242
];
243243

0 commit comments

Comments
 (0)