-
Notifications
You must be signed in to change notification settings - Fork 2
/
lottie.ts
877 lines (790 loc) · 15.8 KB
/
lottie.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
export enum BlendMode {
Normal,
Multiply,
Screen,
Overlay,
Darken,
Lighten,
ColorDodge,
ColorBurn,
HardLight,
SoftLight,
Difference,
Exclusion,
Hue,
Saturation,
Color,
Luminosity,
}
export enum MatteMode {
Normal,
Alpha,
InvertedAlpha,
Luma,
InvertedLuma,
}
export enum Layer3DMode {
Off,
On,
}
export enum AutoOrientMode {
Off,
On,
}
export enum EffectValueType {
Number = 0,
Color = 2,
MultiDimensional = 3,
Boolean = 7,
}
export type EffectValue = {
/** Effect value type */
ty: EffectValueType;
/** Effect value index */
ix: number;
/** Name */
nm: string;
/** ??? */
mn: string;
/** Effect value */
v: Value;
};
export enum EffectType {
Transform = 5,
DropShadow = 25,
GaussianBlur = 29,
}
export type Effect = {
/** Effect Index. */
ix: number;
/** After Effect's Name. */
nm: string;
/** Effect type. */
ty: EffectType;
/** Effect parameters. [] */
ef: EffectValue[];
/** ??? */
np: number;
/** Match name (for expressions) */
mn: string;
/** ??? */
en: number;
};
export const enum MaskMode {
No = 'n',
Add = 'a',
Subtract = 's',
Intersect = 'i',
Lighten = 'l',
Darken = 'd',
Difference = 'f',
}
export type Mask = {
/** Inverted Mask flag. */
inv: boolean;
/** Mask name. */
nm?: string;
/** Mask vertices. */
pt: ShapeProperty;
/** Mask opacity. */
o: Value;
/** Mask mode. */
mode: MaskMode;
/** Dilate. */
x: Value;
};
interface LayerBase {
ty: LayerType;
}
export interface VisualLayer extends LayerBase {
/** 3d layer flag */
ddd?: Layer3DMode;
/** Hidden layer */
hd?: boolean;
/** Layer type */
ty: LayerType;
/** After Effects Layer Name */
nm?: string;
/** Layer Parent */
parent?: number;
/** Layer Time Stretching */
sr?: number;
/** Transform properties */
ks: Transform;
/** Auto-Orient along path AE property */
ao?: AutoOrientMode;
/** In Point of layer */
ip: number;
/** Out Point of layer */
op: number;
/** Start Time of layer */
st: number;
/** Blend Mode */
bm?: BlendMode;
/** Matte mode, the layer will inherit the transparency from the layer above */
tt?: MatteMode;
/** Layer index in AE */
ind?: number;
/** Whether the layer has some masks applied */
hasMask?: boolean;
/** List of Masks */
masksProperties?: Mask[];
/** List of Effects */
ef?: Effect[];
/** matte_target */
td?: number;
/**
* Enable motion blur
* (only has effect if Animation.mb is set)
*/
mb?: boolean;
}
export type Layer =
| NullLayer
| ImageLayer
| VideoLayer
| AudioLayer
| TextLayer;
export enum LayerType {
precomp,
solid,
still,
null,
shape,
text,
audio,
pholderVideo,
imageSeq,
video,
pholderStill,
guide,
adjustment,
camera,
light,
}
export type Transform = {
/** Transform Anchor Point. */
a: MultiDimensional;
/** Transform Position. */
p: PositionValue;
/** Transform Scale. */
s: MultiDimensional;
/** Transform Rotation. */
r: Value;
/** Transform Opacity. */
o: Value;
/** Transform Skew. */
sk?: Value;
/** Transform Skew Axis. */
sa?: Value;
};
export type PrecompLayer = Layer & {
/** Reference ID (in assets list) */
refId: string;
};
export type AudioProperties = {
/** Audio levels. [number, number] */
lv: Value;
};
export type ShapeLayer = Layer & {
/** Shape list of items. */
shapes: ShapeElement[];
};
export type SolidColorLayer = Layer & {
ty: LayerType.solid;
/** Color of the layer as a #rrggbb hex. */
sc: string;
/** Height of the layer. */
sh: number;
/** Width of the layer. */
sw: number;
};
export interface LayerWithAssetReference extends LayerBase {
/** id pointing to the source image defined on 'assets' object. */
refId: string;
}
export interface ImageLayer extends VisualLayer, LayerWithAssetReference {
ty: LayerType.still;
}
export interface VideoLayer extends VisualLayer, LayerWithAssetReference {
ty: LayerType.video;
/** ??? Audio Properties? */
ao: number;
/** File format? */
cl: string;
}
// TODO: AudioLayer is not a visual layer
export interface AudioLayer extends VisualLayer, LayerWithAssetReference {
ty: LayerType.audio;
/** Audio Properties. */
au: AudioProperties;
/** File format? */
cl: 'mp3';
}
export interface NullLayer extends VisualLayer, LayerWithAssetReference {
ty: LayerType.null;
}
export type TextAnimatorDataProperty = {
/** Transform Anchor Point. */
a?: MultiDimensional;
/** Transform Position. */
p?: PositionValue;
/** Transform Scale. */
s?: MultiDimensional;
/** Transform Rotation. */
r?: Value;
/** Transform Opacity. */
o?: Value;
/** Transform Skew. */
sk?: Value;
/** Transform Skew Axis. */
sa?: Value;
/** Angle? */
rx?: Value;
/** Angle? */
ry?: Value;
/** Stroke width. */
sw?: Value;
/** Stroke color. */
sc?: MultiDimensional;
/** Fill color. */
fc?: MultiDimensional;
/** fh */
fh?: Value;
/** 0-100? */
fs?: Value;
/** 0-100? */
fb?: Value;
/** Tracking. */
t?: Value;
};
export enum TextJustify {
Left = 0,
Right,
Center,
}
export enum VerticalJustify {
Top = 0,
Center = 1,
Bottom = 2,
}
export type TextBoxSize = [number, number];
export type TextDocument = {
/** Font family. */
f: string;
/** Text color. */
fc: Color4;
/** Font Size. */
s: number;
/** Line height when wrapping. */
lh: number;
/** Size of the box containing the text */
sz?: TextBoxSize;
/** Text. */
t: string;
/** Text alignment. */
j: TextJustify;
/** Character anchor? */
ca: number;
/** Line shift? positive moves text up */
ls: number;
/** Position? */
ps: number[];
/** Tracking */
tr: number;
/** Vertical justification. (Skottie) */
vj?: VerticalJustify;
};
export type TextDataKeyframe = {
/** Start value of keyframe segment. */
s: TextDocument;
/** Start time of keyframe segment. */
t: number;
};
export type TextDocumentData = {
k: TextDataKeyframe[];
};
export type TextMoreOptions = any;
export type MaskedPath = any;
export const enum RangeSelectorDomain {
Characters = 1,
CharactersExcludingSpaces,
Words,
Lines,
}
export const enum RangeSelectorShape {
Square = 1,
RampUp,
RampDown,
Triangle,
Round,
Smooth,
}
export const enum RangeSelectorUnits {
Percentage = 1,
Index,
}
export const enum RangeSelectorMode {
Add = 1,
Subtract,
Intersect,
Min,
Max,
Difference,
}
export type RangeSelector = {
/** number/enum */
t: number;
/** number/enum */
rn: number;
/**
* Domain
*
* 1. Characters
* 2. Characters exluding spaces
* 3. Words
* 4. Lines
*/
b: RangeSelectorDomain;
/**
* Shape
*
* 1. Square
* 2. Ramp up
* 3. Ramp down
* 4. Triangle
* 5. Round
* 6. Smooth
*/
sh: RangeSelectorShape;
/**
* Mode
*
* 1. Add
* 2. Subtract (Unsupported)
* 3. Intersect (Unsupported)
* 4. Min (Unsupported)
* 5. Max (Unsupported)
* 6. Difference (Unsupported)
*/
m?: RangeSelectorMode;
/** Optional square "smoothness" prop. */
sm: Value;
/**
* Units
*
* 1. Percentage
* 2. Index
*/
r: RangeSelectorUnits;
/** Start */
s?: Value;
/** End */
e?: Value;
/** Offset */
o: Value;
/** Amount */
a: Value;
/** Ease high */
xe: Value;
/** Ease low */
ne: Value;
};
export type TextAnimator = {
/** Name */
nm?: string;
/** Range selector */
s?: RangeSelector;
/** Animated properties */
a: TextAnimatorDataProperty;
};
export type TextData = {
a: TextAnimator[];
d: TextDocumentData;
m?: TextMoreOptions;
p?: MaskedPath;
};
export interface TextLayer extends VisualLayer {
ty: LayerType.text;
/** Text Data. */
t: TextData;
}
export type Point = { x: number; y: number };
export type Matrix4 = [
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
];
export type Matrix3 = [
number,
number,
number,
number,
number,
number,
number,
number,
number,
];
export type Node3D = {
transform: Matrix4;
children: Node3D[];
};
export type Context = {
anchor: number[];
position: number[];
rotation: number;
opacity: number;
scale: number[];
points: Array<Point>;
fill: number[];
};
export enum ShapeType {
Group = 'gr',
Rect = 'rc',
Ellipse = 'el',
Fill = 'fl',
TransformShape = 'tr',
Path = 'sh',
}
export type ShapeElement = {
/** Hide element. */
hd: boolean;
/** After Effect's Name. */
nm: string;
/** Shape type. */
ty: ShapeType;
/** Property index. */
cix: number;
/** Blending Mode */
bm: BlendMode;
};
export type GroupShapeElement = ShapeElement & {
/** Number of properties. */
np: number;
/** List of ShapeElement. */
it: Array<ShapeElement>;
};
export type Bezier = {
/** Closed property of shape. */
c?: boolean;
/** Cubic bezier handles for the segments before each vertex. */
i: number[][];
/** Cubic bezier handles for the segments after each vertex. */
o: number[][];
/** Bezier curve vertices. */
v: number[][];
};
export type ShapeProperty = {
/**
* Bezier: Non-animated value.
* ShapePropKeyframe[]: Keyframe list.
*/
k: Bezier | ShapePropKeyframe[];
/** Property index. */
ix?: number;
/** [0-1] Whether it's animated. */
a?: number;
};
export type PathShape = ShapeElement & {
/** Shape's vertices. */
ks: ShapeProperty;
/** index */
ind: number;
};
export type MultiDimensional = {
/**
* number[]: Non-animated value.
* OffsetKeyframe[]: Animated keyframes.
*/
k: number[] | OffsetKeyframe[];
/** Property index. */
ix?: number;
/** [0-1] Whether it's animated. */
a?: number;
/** ??? */
l?: number;
};
export type Value = {
/**
* number | number[]: Non-animated value.
* OffsetKeyframe[]: Animated keyframes.
*/
k: number | number[] | OffsetKeyframe[];
/** Property index. */
ix?: number;
/** [0-1] Whether it's animated. */
a?: number;
/** Split values (???) */
s?: boolean;
};
export type PositionValue = {
/**
* number | number[]: Non-animated value.
* OffsetKeyframe[]: Animated keyframes.
*/
k: number | number[] | OffsetKeyframe[];
/** Property index. */
ix?: number;
/** [0-1] Whether it's animated. */
a?: number;
/** ??? */
l?: number;
};
export type KeyframeBezierHandle = {
/** x position of the handle. */
x: number | number[];
/** y position of the handle. */
y: number | number[];
};
// TODO: Overlap between OffsetKeyframe and ShapePropKeyframe
export type OffsetKeyframe = {
/** Start time of keyframe segment. */
t: number;
/** Bezier curve easing in value. */
i?: KeyframeBezierHandle;
/** Bezier curve easing out value. */
o?: KeyframeBezierHandle;
/** [0-1] Jump to value. */
h?: number;
/** Start value of keyframe segment. */
s: number | number[];
/** End value of keyframe segment. */
e?: number[];
/** In Spatial Tangent. Only for spatial properties. */
ti?: number[];
/** Out Spatial Tangent. Only for spatial properties. */
to?: number[];
};
export type ShapePropKeyframe = {
/** Start time of keyframe segment. */
t: number;
/** Bezier curve easing in value. */
i: KeyframeBezierHandle;
/** Bezier curve easing out value. */
o: KeyframeBezierHandle;
/** [0-1] Jump to the end value. */
h: number;
/** or list of Bezier Start value of keyframe segment. */
s: Bezier;
/** or list of Bezier End value of keyframe segment. */
e: Bezier;
};
export type RectShape = ShapeElement & {
/** After Effect's Direction. */
d: number;
/** Rect's position. */
p: MultiDimensional;
/** Rect's size. */
s: MultiDimensional;
/** Rect's rounded corners. */
r: Value;
};
export type EllipseShape = ShapeElement;
export type TransformShape = ShapeElement & {
/** Anchor point */
a: MultiDimensional;
/** Transform Position. */
p: PositionValue;
/** Transform Scale. */
s: MultiDimensional;
/** Transform Rotation. */
r: Value;
/** Transform Opacity. */
o: Value;
/** Transform Skew. */
sk: Value;
/** Transform Skew Axis. */
sa: Value;
};
export type Color4 = [number, number, number, number];
export type ColorValue = {
/**
* number[]: Non-animated value.
* OffsetKeyframe[]: Animated keyframes.
*/
k: number[] | OffsetKeyframe[];
/** Property index. */
ix: number;
/** [0-1] Whether it's animated. */
a?: number;
};
export enum FillRule {
NonZero = 1,
EvenOdd,
}
export type FillShape = ShapeElement & {
/** Fill Opacity. */
o: Value;
/** Fill Color. */
c: ColorValue;
/** Fill rule. */
r: FillRule;
};
export type Asset = ImageAsset | PrecompAsset | AudioAsset | VideoAsset;
export type MediaAsset = ImageAsset | AudioAsset | VideoAsset;
interface AssetInterface {
/** Id used to reference in a precomp layer */
id: string;
}
export type ImageAsset = AssetInterface & {
/** URL base */
u: string;
/** Path relative to URL base (asset.u) */
p: string;
/** [non standard]: URL */
_p: string;
/** Width */
w: number;
/** Height */
h: number;
};
export type VideoAsset = AssetInterface & {
/** URL base */
u: string;
/** Path relative to URL base (asset.u) */
p: string;
/** [non standard]: URL */
_p: string;
/** Width */
w: number;
/** Height */
h: number;
/** isEmbedded "boolean", [0-1] */
e: number;
};
export type AudioAsset = AssetInterface & {
/** URL base */
u: string;
/** Path relative to URL base (asset.u) */
p: string;
/** [non standard]: URL */
_p: string;
/** isEmbedded "boolean", [0-1] */
e: number;
};
export type PrecompAsset = AssetInterface & {
/** Layers */
layers: Layer[];
};
export enum FontPathOrigin {
CssUrl = 1,
ScriptUrl,
FontUrl,
}
export type Font = {
/** ascent */
ascent: number;
/** font_family */
fFamily: string;
/** name */
fName: string;
/** font_style */
fStyle: string;
/** ??? */
fClass?: string;
/** path */
fPath: string;
/** weight */
fWeight: string;
/** origin */
origin: FontPathOrigin;
};
export type FontList = {
list: Font[];
};
export type CharData = {
shapes: ShapeElement[];
};
export type Chars = {
/** Character Value. */
ch: string;
/** Character Font Family. */
fFamily: string;
/** Character Font Size. */
size: number;
/** Character Font Style. */
style: string;
/** Character Width. */
w: number;
/** Character Data. */
data: CharData;
};
export interface Composition {
/** List of layers. */
layers?: Layer[];
}
export type Animation = {
/** Bodymovin Version. */
v: string;
/** Frames per second. Positive integer. */
fr: number;
/** The time when the composition work area begins, in frames. */
ip: number;
/** The time when the composition work area ends. */
op: number;
/** Composition Width. */
w: number;
/** Composition Height. */
h: number;
/** List of Composition Layers. */
layers?: Layer[];
/** Composition name. */
nm?: string;
/** [0-1] Composition has 3-D layers. */
ddd?: number;
/** source items that can be used in multiple places. */
assets?: Asset[];
/** Available fonts. */
fonts?: FontList;
/** Source chars for text layers. */
chars?: Chars[];
/** Motion blur setting. (Skottie) */
mb?: MotionBlurSettings;
};
/**
* Motion Blur Settings
* Enable motion blur for a layer by setting `layer.mb = true`
*/
export type MotionBlurSettings = {
/**
* Shutter Angle
* AE default: 180
* Skottie default: 0 ([0, 720])
*/
sa?: number;
/**
* Shutter Phase
* AE default: -90
* Skottie default: 0 ([-360, 360])
*/
sp?: number;
/**
* Samples Per Frame
* AE default: 16
* Skottie default: 1 ([1, 64])
*/
spf?: number;
/**
* (not yet supported in any known Lottie player)
* Adaptive Sample Limit
* 2D layer motion automatically uses more samples per frame
* when needed, up to the value specified by Adaptive Sample
* Limit.
* AE default: 128
*/
asl?: number;
};