From 6bfe7e8a30d96c04a1552800159992705f3605b1 Mon Sep 17 00:00:00 2001 From: Diego Muracciole Date: Tue, 16 Jan 2024 02:23:47 +0100 Subject: [PATCH] fix: color parse error (#2498) * fix: color parse error * chore: bump color-string * chore: add changeset --- .changeset/fifty-bugs-change.md | 6 ++++++ packages/render/package.json | 2 +- packages/render/src/utils/parseColor.js | 5 +++++ packages/stylesheet/package.json | 2 +- yarn.lock | 8 ++++---- 5 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 .changeset/fifty-bugs-change.md diff --git a/.changeset/fifty-bugs-change.md b/.changeset/fifty-bugs-change.md new file mode 100644 index 000000000..1bd650114 --- /dev/null +++ b/.changeset/fifty-bugs-change.md @@ -0,0 +1,6 @@ +--- +'@react-pdf/stylesheet': patch +'@react-pdf/render': patch +--- + +fix: color parse error diff --git a/packages/render/package.json b/packages/render/package.json index 682b004d1..0035e029c 100644 --- a/packages/render/package.json +++ b/packages/render/package.json @@ -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" diff --git a/packages/render/src/utils/parseColor.js b/packages/render/src/utils/parseColor.js index 581e95d10..1198344e6 100644 --- a/packages/render/src/utils/parseColor.js +++ b/packages/render/src/utils/parseColor.js @@ -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]; diff --git a/packages/stylesheet/package.json b/packages/stylesheet/package.json index 876910908..7988433df 100644 --- a/packages/stylesheet/package.json +++ b/packages/stylesheet/package.json @@ -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" diff --git a/yarn.lock b/yarn.lock index 1c2e29a35..3b4a5feee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"