Skip to content

Commit

Permalink
Add a support for parsing hsl() and hsla() color formats.
Browse files Browse the repository at this point in the history
Fixes alafr#187.
  • Loading branch information
petrkotek committed Jul 6, 2024
1 parent b091ebd commit 0a0744a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions source.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,17 @@ var SVGtoPDF = function(doc, svg, x, y, options) {
if (temp[1] < 256 && temp[2] < 256 && temp[3] < 256) {
result = [temp.slice(1, 4), 1];
}
} else if (temp = raw.match(/^hsl\(\s*([0-9]+)\s*,\s*([0-9]+)%\s*,\s*([0-9]+)%\s*\)$/i)) {
temp[1] = parseInt(temp[1]); temp[2] = parseInt(temp[2]); temp[3] = parseInt(temp[3]);
if (temp[1] <= 360 && temp[2] <= 100 && temp[3] <= 100) {
console.log(temp)
result = [hslToRgb(temp[1]/360, temp[2]/100, temp[3]/100), 1];
}
} else if (temp = raw.match(/^hsla\(\s*([0-9]+)\s*,\s*([0-9]+)%\s*,\s*([0-9]+)%\s*,\s*([0-9.]+)\s*\)$/i)) {
temp[1] = parseInt(temp[1]); temp[2] = parseInt(temp[2]); temp[3] = parseInt(temp[3]); temp[4] = parseFloat(temp[4]);
if (temp[1] <= 360 && temp[2] <= 100 && temp[3] <= 100 && temp[4] <= 1) {
result = [hslToRgb(temp[1]/360, temp[2]/100, temp[3]/100), temp[4]];
}
} else if (temp = raw.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i)) {
result = [[parseInt(temp[1], 16), parseInt(temp[2], 16), parseInt(temp[3], 16)], 1];
} else if (temp = raw.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i)) {
Expand Down

0 comments on commit 0a0744a

Please sign in to comment.