Skip to content

Commit

Permalink
fix: color parse error (#2498)
Browse files Browse the repository at this point in the history
* fix: color parse error

* chore: bump color-string

* chore: add changeset
  • Loading branch information
diegomura authored Jan 16, 2024
1 parent c8fe2c8 commit 6bfe7e8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/fifty-bugs-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@react-pdf/stylesheet': patch
'@react-pdf/render': patch
---

fix: color parse error
2 changes: 1 addition & 1 deletion packages/render/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@react-pdf/textkit": "^4.2.1",
"@react-pdf/types": "^2.3.5",
"abs-svg-path": "^0.1.1",
"color-string": "^1.5.3",
"color-string": "^1.9.1",
"normalize-svg-path": "^1.1.0",
"parse-svg-path": "^0.1.2",
"svg-arc-to-cubic-bezier": "^3.2.0"
Expand Down
5 changes: 5 additions & 0 deletions packages/render/src/utils/parseColor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import colorString from 'color-string';

const black = { value: [0, 0, 0], opacity: 1 };

const parseColor = hex => {
const parsed = colorString.get(hex);

if (!parsed) return black;

const value = colorString.to.hex(parsed.value.slice(0, 3));
const opacity = parsed.value[3];

Expand Down
2 changes: 1 addition & 1 deletion packages/stylesheet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@babel/runtime": "^7.20.13",
"@react-pdf/fns": "2.0.1",
"@react-pdf/types": "^2.3.5",
"color-string": "^1.5.3",
"color-string": "^1.9.1",
"hsl-to-hex": "^1.0.0",
"media-engine": "^1.0.3",
"postcss-value-parser": "^4.1.0"
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3781,10 +3781,10 @@ color-name@^1.0.0, color-name@~1.1.4:
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==

color-string@^1.5.3:
version "1.5.5"
resolved "https://registry.yarnpkg.com/color-string/-/color-string-1.5.5.tgz#65474a8f0e7439625f3d27a6a19d89fc45223014"
integrity sha512-jgIoum0OfQfq9Whcfc2z/VhCNcmQjWbey6qBX0vqt7YICflUmBCh9E9CiQD5GSJ+Uehixm3NUwHVhqUAWRivZg==
color-string@^1.9.1:
version "1.9.1"
resolved "https://registry.yarnpkg.com/color-string/-/color-string-1.9.1.tgz#4467f9146f036f855b764dfb5bf8582bf342c7a4"
integrity sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==
dependencies:
color-name "^1.0.0"
simple-swizzle "^0.2.2"
Expand Down

0 comments on commit 6bfe7e8

Please sign in to comment.