-
Notifications
You must be signed in to change notification settings - Fork 19
/
repeater-shape.ts
110 lines (87 loc) · 2.68 KB
/
repeater-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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { PropertyType, ShapeType, RepeaterComposite } from '../constants';
import { Property } from '../properties';
import { Shape } from './shape';
/**
* Repeater shape type.
*/
export class RepeaterShape extends Shape {
/**
* Repeater shape type: rp
*/
public readonly type = ShapeType.REPEATER;
public anchor: Property = new Property(this, PropertyType.ANCHOR);
public startOpacity: Property = new Property(this, PropertyType.OPACITY);
public endOpacity: Property = new Property(this, PropertyType.OPACITY);
public position: Property = new Property(this, PropertyType.POSITION);
public rotation: Property = new Property(this, PropertyType.ROTATION);
public scale: Property = new Property(this, PropertyType.SCALE);
public shapes: Shape[] = [];
public skew: Property = new Property(this, PropertyType.SKEW);
public skewAxis: Property = new Property(this, PropertyType.SKEW_AXIS);
public copies: Property = new Property(this, PropertyType.NUMBER);
public offset: Property = new Property(this, PropertyType.NUMBER);
public composition: RepeaterComposite = RepeaterComposite.ABOVE;
/**
* Convert the Lottie JSON object to class instance.
*
* @param json JSON object
* @returns GroupShape instance
*/
public fromJSON(json: Record<string, any>): RepeaterShape {
// 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.copies.fromJSON(json.c);
this.composition = json.m;
this.offset.fromJSON(json.o);
this.anchor.fromJSON(json.tr.a);
this.startOpacity.fromJSON(json.tr.so);
this.endOpacity.fromJSON(json.tr.eo);
this.position.fromJSON(json.tr.p);
this.rotation.fromJSON(json.tr.r);
this.scale.fromJSON(json.tr.s);
if (json.tr.sk) {
this.skew.fromJSON(json.tr.sk);
}
if (json.tr.sa) {
this.skewAxis.fromJSON(json.tr.sa);
}
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
m: this.composition,
c: this.copies,
o: this.offset,
tr: {
a: this.anchor,
so: this.startOpacity,
eo: this.endOpacity,
p: this.position,
r: this.rotation,
s: this.scale,
sk: this.skew,
sa: this.skewAxis,
}
};
}
}