-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: relottie-extract-features package (#81)
* 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
Showing
72 changed files
with
46,127 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.