relottie-extract-features
A relottie plugin to extract Lottie features from the document and store them in vfile.
FileData
The used data includes counts
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: Used;  };}Use
yarn add @lottiefiles/relottie-extract-featuresimport 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 FileDataconst output = data['extract-features']output:
Object {  "used": 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.tsfor testing playground environment (if you are in the root folder you have to enter the package directory- cd packages/relottie-extract-features)
- for testing pnpm test