Skip to content

Commit

Permalink
feat: relottie-extract-features package (#81)
Browse files Browse the repository at this point in the history
* feat: relottie-extract-features package

* chore(extract-features): add missing to-vfile deps

* docs: add relottie-extract-features into mono readme

* chore(size-limit): add extract-features
  • Loading branch information
Aidosmf committed Dec 1, 2023
1 parent e225c1e commit 88e286c
Show file tree
Hide file tree
Showing 72 changed files with 46,127 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-gifts-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lottiefiles/relottie-extract-features': major
---

feat: initial major release that helps to extract Lottie features from the document
3 changes: 3 additions & 0 deletions .size-limit.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ module.exports = [
{
path: 'packages/relottie-stringify/dist/index.js',
},
{
path: 'packages/relottie-extract-features/dist/index.js',
},
];
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ This GitHub repository is a monorepo that contains the following packages:
— plugin to take a syntax tree (last) and turn it into Lottie as output
* [`relottie-cli`][relottie-cli]
— Command line interface to inspect and change Lottie files with relottie
* [`relottie-extract-features`][relottie-extract-features]
— plugin to extract Lottie features from the document and store them in vfile

## When should I use this?

Expand Down Expand Up @@ -350,6 +352,8 @@ The initial release of this project was authored by

[relottie-cli]: https://github.com/LottieFiles/relottie/tree/main/packages/relottie-cli

[relottie-extract-features]: https://github.com/LottieFiles/relottie/tree/main/packages/relottie-extract-features

[lottie-types]: https://www.npmjs.com/package/@lottiefiles/lottie-types

[dotlottie.js]: https://github.com/dotlottie/dotlottie-js/
Expand Down
16 changes: 16 additions & 0 deletions packages/relottie-extract-features/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
MIT License

Copyright (c) 2023 LottieFiles.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
156 changes: 156 additions & 0 deletions packages/relottie-extract-features/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# relottie-extract-features

A [relottie] plugin to extract Lottie features from the document and store them in vfile.

## FileData

The `used` data includes counts

```typescript
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

```sh
yarn add @lottiefiles/relottie-extract-features
```

```ts
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`:

```snap
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

1. `pnpm install`
2. `pnpm ts-node playground.ts` for testing playground environment (if you are in the root folder you have to enter the package directory `cd packages/relottie-extract-features`)
3. for testing `pnpm test`

## Legal

[MIT](LICENSE) © [LottieFiles](https://www.lottiefiles.com)

<!-- Definitions -->

[relottie]: https://github.com/LottieFiles/relottie

[unified]: https://github.com/unifiedjs/unified
Loading

0 comments on commit 88e286c

Please sign in to comment.