From c59c1abe6f14c630f539f74971842da1463e6d32 Mon Sep 17 00:00:00 2001 From: karamalie Date: Tue, 28 Sep 2021 15:03:08 +0500 Subject: [PATCH] fix(fix import): fix import for test file --- src/animation/animation.test.ts | 5 +++++ src/animation/animation.ts | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/animation/animation.test.ts b/src/animation/animation.test.ts index 33128e5..856d09f 100644 --- a/src/animation/animation.test.ts +++ b/src/animation/animation.test.ts @@ -48,3 +48,8 @@ test('Get unique colors', async () => { [205, 16, 16, 1], ]); }); + +test('Get text layer', async () => { + const anim = await Animation.fromURL('https://assets10.lottiefiles.com/packages/lf20_8MANkV.json'); + console.log(anim.textLayers); +}); diff --git a/src/animation/animation.ts b/src/animation/animation.ts index 1b9062a..1161fec 100644 --- a/src/animation/animation.ts +++ b/src/animation/animation.ts @@ -143,6 +143,19 @@ export class Animation { return colors; } + /* + * return all the text layers with layer name + */ + + public get textLayers(): Record { + const textLayers: parentLocatorInterface = {}; + const layers = this.getLayersByType(LayerType.TEXT) as TextLayer[]; + layers.forEach((layer, index) => { + textLayers[index + '.' + layer.name] = layer.textData.d.k[0].s.t; + }); + return textLayers; + } + /* * returns the names of all prents given a shape */