Skip to content

Commit 803d1f8

Browse files
teunverhaertteunverhaert
and
teunverhaert
authored
fix: fix gradients with rgba values returning rgba(0, 0, 0, 0) (#1429)
Co-authored-by: teunverhaert <[email protected]>
1 parent 4b5f1e9 commit 803d1f8

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

.changeset/quiet-insects-march.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'style-dictionary': patch
3+
---
4+
5+
Fix gradients with rgba values returning rgba(0, 0, 0, 0)

__tests__/common/transforms.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,19 @@ describe('common', () => {
14681468
it('should ignore gradients', () => {
14691469
expect(isColor({ type: 'color', value: 'linear-gradient(#e66465, #9198e5)' }, {})).to.be
14701470
.false;
1471+
expect(isColor({ type: 'color', value: 'linear-gradient(red, yellow)' }, {})).to.be.false;
1472+
expect(
1473+
isColor(
1474+
{ type: 'color', value: 'linear-gradient(rgba(0, 0, 0, 0.00), rgba(0, 0, 0, 0.60))' },
1475+
{},
1476+
),
1477+
).to.be.false;
1478+
expect(isColor({ type: 'color', value: 'repeating-linear-gradient(#e66465, #9198e5)' }, {}))
1479+
.to.be.false;
1480+
expect(isColor({ type: 'color', value: 'radial-gradient(#e66465, #9198e5)' }, {})).to.be
1481+
.false;
1482+
expect(isColor({ type: 'color', value: 'repeating-radial-gradient(#e66465, #9198e5)' }, {}))
1483+
.to.be.false;
14711484
});
14721485

14731486
it('should ignore values that cannot convert to a color', () => {

patches/tinycolor2+1.6.0.patch

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
diff --git a/node_modules/tinycolor2/cjs/tinycolor.js b/node_modules/tinycolor2/cjs/tinycolor.js
2+
index 4f584ca..af03edf 100644
3+
--- a/node_modules/tinycolor2/cjs/tinycolor.js
4+
+++ b/node_modules/tinycolor2/cjs/tinycolor.js
5+
@@ -1061,6 +1061,9 @@
6+
// based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
7+
function stringInputToObject(color) {
8+
color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
9+
+ if (color.startsWith("linear-gradient") || color.startsWith("radial-gradient") || color.startsWith("repeating-linear-gradient") || color.startsWith("repeating-radial-gradient")) {
10+
+ return false;
11+
+ }
12+
var named = false;
13+
if (names[color]) {
14+
color = names[color];
15+
diff --git a/node_modules/tinycolor2/esm/tinycolor.js b/node_modules/tinycolor2/esm/tinycolor.js
16+
index 374f5ea..8405a82 100644
17+
--- a/node_modules/tinycolor2/esm/tinycolor.js
18+
+++ b/node_modules/tinycolor2/esm/tinycolor.js
19+
@@ -1055,6 +1055,9 @@ function isValidCSSUnit(color) {
20+
// based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
21+
function stringInputToObject(color) {
22+
color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
23+
+ if (color.startsWith("linear-gradient") || color.startsWith("radial-gradient") || color.startsWith("repeating-linear-gradient") || color.startsWith("repeating-radial-gradient")) {
24+
+ return false;
25+
+ }
26+
var named = false;
27+
if (names[color]) {
28+
color = names[color];
29+
diff --git a/node_modules/tinycolor2/tinycolor.js b/node_modules/tinycolor2/tinycolor.js
30+
index 52601df..f2ef959 100644
31+
--- a/node_modules/tinycolor2/tinycolor.js
32+
+++ b/node_modules/tinycolor2/tinycolor.js
33+
@@ -1064,6 +1064,9 @@
34+
// based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
35+
function stringInputToObject(color) {
36+
color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
37+
+ if (color.startsWith("linear-gradient") || color.startsWith("radial-gradient") || color.startsWith("repeating-linear-gradient") || color.startsWith("repeating-radial-gradient")) {
38+
+ return false;
39+
+ }
40+
var named = false;
41+
if (names[color]) {
42+
color = names[color];

0 commit comments

Comments
 (0)