Skip to content

Commit ab19bd2

Browse files
committed
proper empty gradient
1 parent 2fef98d commit ab19bd2

File tree

3 files changed

+39
-42
lines changed

3 files changed

+39
-42
lines changed

src/jsonUtils/borders.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FileFormat1 as FileFormat } from '@sketch-hq/sketch-file-format-ts';
2-
import { makeColorFromCSS } from './models';
2+
import { makeColorFromCSS, emptyGradient } from './models';
33
import { ViewStyle, LayoutInfo, BorderStyle } from '../types';
44
import same from '../utils/same';
55
import { makeVerticalBorder, makeHorizontalBorder } from './shapeLayers';
@@ -31,14 +31,7 @@ export const createUniformBorder = (
3131
blendMode: FileFormat.BlendMode.Normal,
3232
opacity: 1,
3333
},
34-
gradient: {
35-
_class: 'gradient',
36-
gradientType: FileFormat.GradientType.Linear,
37-
elipseLength: 0,
38-
from: '{0, 0}',
39-
to: '{1, 1}',
40-
stops: [],
41-
},
34+
gradient: emptyGradient,
4235
},
4336
];
4437

src/jsonUtils/models.ts

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,38 @@ export const makeColorFromCSS = (input: Color, alpha: number = 1): FileFormat.Co
8888
};
8989
};
9090

91+
export const emptyGradient: FileFormat.Gradient = {
92+
_class: 'gradient',
93+
elipseLength: 0,
94+
from: '{0.5, 0}',
95+
gradientType: 0,
96+
to: '{0.5, 1}',
97+
stops: [
98+
{
99+
_class: 'gradientStop',
100+
position: 0,
101+
color: {
102+
_class: 'color',
103+
alpha: 1,
104+
blue: 1,
105+
green: 1,
106+
red: 1,
107+
},
108+
},
109+
{
110+
_class: 'gradientStop',
111+
position: 1,
112+
color: {
113+
_class: 'color',
114+
alpha: 1,
115+
blue: 0,
116+
green: 0,
117+
red: 0,
118+
},
119+
},
120+
],
121+
};
122+
91123
// Solid color fill
92124
export const makeColorFill = (cssColor: Color): FileFormat.Fill => ({
93125
_class: 'fill',
@@ -103,14 +135,7 @@ export const makeColorFill = (cssColor: Color): FileFormat.Fill => ({
103135
blendMode: FileFormat.BlendMode.Normal,
104136
opacity: 1,
105137
},
106-
gradient: {
107-
_class: 'gradient',
108-
gradientType: FileFormat.GradientType.Linear,
109-
elipseLength: 0,
110-
from: '{0, 0}',
111-
to: '{1, 1}',
112-
stops: [],
113-
},
138+
gradient: emptyGradient,
114139
});
115140

116141
export const makeImageFill = (
@@ -131,14 +156,7 @@ export const makeImageFill = (
131156
blendMode: FileFormat.BlendMode.Normal,
132157
opacity: 1,
133158
},
134-
gradient: {
135-
_class: 'gradient',
136-
gradientType: FileFormat.GradientType.Linear,
137-
elipseLength: 0,
138-
from: '{0, 0}',
139-
to: '{1, 1}',
140-
stops: [],
141-
},
159+
gradient: emptyGradient,
142160
});
143161

144162
// Used in frames, etc

src/jsonUtils/shapeLayers.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FileFormat1 as FileFormat } from '@sketch-hq/sketch-file-format-ts';
22
import makeResizeConstraint from './resizeConstraint';
3-
import { generateID, makeRect, makeColorFromCSS } from './models';
3+
import { generateID, makeRect, makeColorFromCSS, emptyGradient } from './models';
44
import { makeStyle } from './style';
55
import { Color, ResizeConstraints, ViewStyle } from '../types';
66

@@ -261,14 +261,7 @@ export const makeVerticalBorder = (
261261
blendMode: FileFormat.BlendMode.Normal,
262262
opacity: 1,
263263
},
264-
gradient: {
265-
_class: 'gradient',
266-
gradientType: FileFormat.GradientType.Linear,
267-
elipseLength: 0,
268-
from: '{0, 0}',
269-
to: '{1, 1}',
270-
stops: [],
271-
},
264+
gradient: emptyGradient,
272265
},
273266
];
274267
return content;
@@ -298,14 +291,7 @@ export const makeHorizontalBorder = (
298291
blendMode: FileFormat.BlendMode.Normal,
299292
opacity: 1,
300293
},
301-
gradient: {
302-
_class: 'gradient',
303-
gradientType: FileFormat.GradientType.Linear,
304-
elipseLength: 0,
305-
from: '{0, 0}',
306-
to: '{1, 1}',
307-
stops: [],
308-
},
294+
gradient: emptyGradient,
309295
},
310296
];
311297
return content;

0 commit comments

Comments
 (0)