@lottiefiles/relottie-extract-features
v1.9.1
Published
relottie plugin to extract Lottie features
Downloads
98
Maintainers
Readme
relottie-extract-features
A relottie plugin to extract Lottie features from the document and store them in vfile.
FileData
export type UsedCount = number;
export type Used = Map<
AnyTitle,
{
/**
* Total unused count
*/
n: UsedCount;
/**
* Map of parent titles to whether how many nodes is used or not_used in the parent
*/
parents: Map<AnyTitle, { n: UsedCount; y: UsedCount }>;
/**
* Total used count
*/
y: UsedCount;
}
>;
export interface ExtractFeaturesFileData extends Data {
'extract-features': Used;
}
Use
yarn add @lottiefiles/relottie-extract-features
import relottieParse, { type ParseFileData } from '@lottiefiles/relottie-parse';
import relottieStringify, { type StringifyFileData } from '@lottiefiles/relottie-stringify';
import relottieExtractFeatures, { type ExtractFeaturesFileData } from '@lottiefiles/relottie-extract-features';
import { unified } from 'unified';
type FileData = ParseFileData & StringifyFileData & ExtractFeaturesFileData
const lottie = '{ "layers": [ { "nm": "foo", "mn": "bar", "ddd": 0, "ty": 2 } ] }';
const vfile = unified()
.use(relottieParse)
.use(relottieExtractFeatures)
.use(relottieStringify)
.processSync(lottie);
const data = vfile.data as FileData
const output = data['extract-features']
output
:
Map {
"composition" => Object {
"n": 0,
"parents": Map {
"animation" => Object {
"n": 0,
"y": 1,
},
},
"y": 1,
},
"composition-children" => Object {
"n": 0,
"parents": Map {
"composition" => Object {
"n": 0,
"y": 1,
},
},
"y": 1,
},
"layer-image" => Object {
"n": 0,
"parents": Map {
"composition-children" => Object {
"n": 0,
"y": 1,
},
},
"y": 1,
},
"name" => Object {
"n": 0,
"parents": Map {
"layer-image" => Object {
"n": 0,
"y": 1,
},
},
"y": 1,
},
"match-name" => Object {
"n": 0,
"parents": Map {
"layer-image" => Object {
"n": 0,
"y": 1,
},
},
"y": 1,
},
"threedimensional" => Object {
"n": 1,
"parents": Map {
"layer-image" => Object {
"n": 1,
"y": 0,
},
},
"y": 0,
},
"layer-type" => Object {
"n": 0,
"parents": Map {
"layer-image" => Object {
"n": 0,
"y": 1,
},
},
"y": 1,
},
}
Start
pnpm install
pnpm ts-node playground.ts
for testing playground environment (if you are in the root folder you have to enter the package directorycd packages/relottie-extract-features
)- for testing
pnpm test