Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a support for parsing hsl() and hsla() color formats. #188

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

petrkotek
Copy link

@petrkotek petrkotek commented Jul 6, 2024

Fixes #187.

Note that I verified the functionality by temporarily moving the parseColor function out and running a jest test:

test("rgb()", () => {
  const result = parseColor("rgb(10,20,30)", null);

  expect(result).toEqual([[10, 20, 30], 1]);
});

test("rgba()", () => {
  const result = parseColor("rgba(10,20,30,0.3)", null);

  expect(result).toEqual([[10, 20, 30], 0.3]);
});

test("hsl()", () => {
  const result = parseColor("hsl(122, 57%, 35%)", null);

  expect(result).toEqual([[38, 140, 42], 1]);
});

test("hsla()", () => {
  const result = parseColor("hsla(122, 57%, 35%, 0.4)", null);

  expect(result).toEqual([[38, 140, 42], 0.4]);
});

I would have loved to add tests, but looks like there are none at this stage and the code does't seem to be easily testable without refactoring, so better left for a separate pull request.

Testing SVG -> PDF BEFORE (missing colors for some elements):
image

Testing SVG -> PDF AFTER (colors are correct):
image

@petrkotek petrkotek force-pushed the add-hsl-hsla-support branch 2 times, most recently from c9c1a14 to 2f691ea Compare July 8, 2024 06:13
@petrkotek
Copy link
Author

gentle ping @alafr; would you please consider this contribution? Thanks!

@petrkotek
Copy link
Author

friendly ping @alafr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hsl & hsla color formats not supported
1 participant