Skip to content

Commit

Permalink
formatCss(): handle undefined hue for hsl() / hwb() / lch() serializa…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
danburzo committed Aug 5, 2021
1 parent 7f9d27f commit f2795a5
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.
5 changes: 1 addition & 4 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1041,10 +1041,7 @@ Defines a new color space through a _definition_ object. Here's the full definit
h: [0, 360]
},
parsers: [parseHsl],
serialize: c =>
`hsl(${c.h} ${c.s * 100}% ${c.l * 100}%${
c.alpha < 1 ? ` / ${c.alpha}` : ''
})`,
serialize: serializeHsl,
interpolate: {
h: {
use: interpolatorLinear,
Expand Down
2 changes: 1 addition & 1 deletion src/hsl/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const definition = {

parsers: [parseHsl],
serialize: c =>
`hsl(${c.h} ${c.s * 100}% ${c.l * 100}%${
`hsl(${c.h || 0} ${c.s * 100}% ${c.l * 100}%${
c.alpha < 1 ? ` / ${c.alpha}` : ''
})`,

Expand Down
2 changes: 1 addition & 1 deletion src/hwb/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const definition = {

parsers: [parseHwb],
serialize: c =>
`hwb(${c.h} ${c.w * 100}% ${c.b * 100}%${
`hwb(${c.h || 0} ${c.w * 100}% ${c.b * 100}%${
c.alpha < 1 ? ` / ${c.alpha}` : ''
})`,

Expand Down
2 changes: 1 addition & 1 deletion src/lch/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const definition = {

parsers: [parseLch],
serialize: c =>
`lch(${c.l}% ${c.c} ${c.h}${c.alpha < 1 ? ` / ${c.alpha}` : ''})`,
`lch(${c.l}% ${c.c} ${c.h || 0}${c.alpha < 1 ? ` / ${c.alpha}` : ''})`,

interpolate: {
h: { use: interpolatorLinear, fixup: fixupHueShorter },
Expand Down
1 change: 1 addition & 0 deletions test/hsl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,6 @@ tape('formatCss', t => {
t.equal(formatCss('hsl(.5turn 40% 20% / 50%)'), 'hsl(180 40% 20% / 0.5)');
t.equal(formatCss('hsl(.5turn 40% 20%)'), 'hsl(180 40% 20%)');
t.equal(formatCss('hsl(.5turn 40% 20% / 100%)'), 'hsl(180 40% 20%)');
t.equal(formatCss(hsl('#ffffff00')), 'hsl(0 0% 100% / 0)');
t.end();
});
1 change: 1 addition & 0 deletions test/hwb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ tape('formatCss', t => {
t.equal(formatCss('hwb(200 150% 150% / .5)'), 'hwb(200 50% 50% / 0.5)');
t.equal(formatCss('hwb(200 150% 150% / 100%)'), 'hwb(200 50% 50%)');
t.equal(formatCss('hwb(200 150% 150%)'), 'hwb(200 50% 50%)');
t.equal(formatCss(hwb('#ffffff00')), 'hwb(0 100% 0% / 0)');
t.end();
});
1 change: 1 addition & 0 deletions test/lch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ tape('formatCss', t => {
t.equal(formatCss('lch(40 10 30 / 50%)'), 'lch(40% 10 30 / 0.5)');
t.equal(formatCss('lch(40 10 30 / 100%)'), 'lch(40% 10 30)');
t.equal(formatCss('lch(40 10 30)'), 'lch(40% 10 30)');
t.equal(formatCss(lch('#ffffff00')), 'lch(100% 0 0 / 0)');
t.end();
});

0 comments on commit f2795a5

Please sign in to comment.