-
Notifications
You must be signed in to change notification settings - Fork 19
/
gradient-fill-shape.ts
93 lines (76 loc) · 2.39 KB
/
gradient-fill-shape.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { BlendMode, FillRuleType, GradientFillType, PropertyType, ShapeType } from '../constants';
import { Gradient, Property } from '../properties';
import { Shape } from './shape';
/**
* Gradient fill shape type.
*/
export class GradientFillShape extends Shape {
/**
* Gradient shape type: gf
*/
public readonly type = ShapeType.GRADIENT_FILL;
public blendMode: BlendMode = BlendMode.NORMAL;
public endPoint: Property = new Property(this, PropertyType.POSITION);
public gradientColors: Gradient = new Gradient();
public gradientType: GradientFillType = GradientFillType.LINEAR;
public highlightAngle: Property = new Property(this, PropertyType.NUMBER);
public highlightLength: Property = new Property(this, PropertyType.NUMBER);
public opacity: Property = new Property(this, PropertyType.OPACITY);
public startPoint: Property = new Property(this, PropertyType.POSITION);
public fillRule: FillRuleType = FillRuleType.EVEN_ODD;
/**
* Convert the Lottie JSON object to class instance.
*
* @param json JSON object
* @returns GradientFillShape instance
*/
public fromJSON(json: Record<string, any>): GradientFillShape {
// Base shape
this.classNames = json.cl;
this.id = json.ln;
this.isHidden = json.hd;
this.matchName = json.mn;
this.name = json.nm;
// This shape
this.blendMode = json.bm;
this.endPoint.fromJSON(json.e);
this.gradientColors.fromJSON(json.g);
this.gradientType = json.t;
this.opacity.fromJSON(json.o);
this.startPoint.fromJSON(json.s);
this.fillRule = json.r;
if (this.gradientType === GradientFillType.LINEAR) {
this.highlightAngle.fromJSON(json.a);
this.highlightLength.fromJSON(json.h);
}
return this;
}
/**
* Convert the class instance to Lottie JSON object.
*
* Called by Javascript when serializing object with JSON.stringify()
*
* @returns JSON object
*/
public toJSON(): Record<string, any> {
return {
ty: this.type,
// Base shape
cl: this.classNames,
hd: this.isHidden,
ln: this.id,
mn: this.matchName,
nm: this.name,
// This shape
bm: this.blendMode,
e: this.endPoint,
g: this.gradientColors,
t: this.gradientType,
a: this.highlightAngle,
h: this.highlightLength,
o: this.opacity,
r: this.fillRule,
s: this.startPoint,
};
}
}