Skip to content

Commit

Permalink
fix: fix gradients with rgba values returning rgba(0, 0, 0, 0) (#1429)
Browse files Browse the repository at this point in the history
Co-authored-by: teunverhaert <[email protected]>
  • Loading branch information
teunverhaert and teunverhaert authored Jan 20, 2025
1 parent 4b5f1e9 commit 803d1f8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-insects-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'style-dictionary': patch
---

Fix gradients with rgba values returning rgba(0, 0, 0, 0)
13 changes: 13 additions & 0 deletions __tests__/common/transforms.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,19 @@ describe('common', () => {
it('should ignore gradients', () => {
expect(isColor({ type: 'color', value: 'linear-gradient(#e66465, #9198e5)' }, {})).to.be
.false;
expect(isColor({ type: 'color', value: 'linear-gradient(red, yellow)' }, {})).to.be.false;
expect(
isColor(
{ type: 'color', value: 'linear-gradient(rgba(0, 0, 0, 0.00), rgba(0, 0, 0, 0.60))' },
{},
),
).to.be.false;
expect(isColor({ type: 'color', value: 'repeating-linear-gradient(#e66465, #9198e5)' }, {}))
.to.be.false;
expect(isColor({ type: 'color', value: 'radial-gradient(#e66465, #9198e5)' }, {})).to.be
.false;
expect(isColor({ type: 'color', value: 'repeating-radial-gradient(#e66465, #9198e5)' }, {}))
.to.be.false;
});

it('should ignore values that cannot convert to a color', () => {
Expand Down
42 changes: 42 additions & 0 deletions patches/tinycolor2+1.6.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
diff --git a/node_modules/tinycolor2/cjs/tinycolor.js b/node_modules/tinycolor2/cjs/tinycolor.js
index 4f584ca..af03edf 100644
--- a/node_modules/tinycolor2/cjs/tinycolor.js
+++ b/node_modules/tinycolor2/cjs/tinycolor.js
@@ -1061,6 +1061,9 @@
// based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
function stringInputToObject(color) {
color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
+ if (color.startsWith("linear-gradient") || color.startsWith("radial-gradient") || color.startsWith("repeating-linear-gradient") || color.startsWith("repeating-radial-gradient")) {
+ return false;
+ }
var named = false;
if (names[color]) {
color = names[color];
diff --git a/node_modules/tinycolor2/esm/tinycolor.js b/node_modules/tinycolor2/esm/tinycolor.js
index 374f5ea..8405a82 100644
--- a/node_modules/tinycolor2/esm/tinycolor.js
+++ b/node_modules/tinycolor2/esm/tinycolor.js
@@ -1055,6 +1055,9 @@ function isValidCSSUnit(color) {
// based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
function stringInputToObject(color) {
color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
+ if (color.startsWith("linear-gradient") || color.startsWith("radial-gradient") || color.startsWith("repeating-linear-gradient") || color.startsWith("repeating-radial-gradient")) {
+ return false;
+ }
var named = false;
if (names[color]) {
color = names[color];
diff --git a/node_modules/tinycolor2/tinycolor.js b/node_modules/tinycolor2/tinycolor.js
index 52601df..f2ef959 100644
--- a/node_modules/tinycolor2/tinycolor.js
+++ b/node_modules/tinycolor2/tinycolor.js
@@ -1064,6 +1064,9 @@
// based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
function stringInputToObject(color) {
color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
+ if (color.startsWith("linear-gradient") || color.startsWith("radial-gradient") || color.startsWith("repeating-linear-gradient") || color.startsWith("repeating-radial-gradient")) {
+ return false;
+ }
var named = false;
if (names[color]) {
color = names[color];

0 comments on commit 803d1f8

Please sign in to comment.