-
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-metadata base with attribute proccess
- Loading branch information
Showing
92 changed files
with
2,855 additions
and
8 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,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,127 @@ | ||
# relottie-metadata | ||
|
||
![npm](https://img.shields.io/npm/v/@lottiefiles/relottie-metadata) | ||
![npm](https://img.shields.io/npm/dt/%40lottiefiles/relottie-metadata) | ||
![npm](https://img.shields.io/npm/l/@lottiefiles/relottie-metadata) | ||
|
||
A [relottie] plugin to extract Lottie metadata from the document and store them in vfile.data. | ||
|
||
## FileData | ||
|
||
```typescript | ||
export interface MetadataFileData extends Data { | ||
metadata: { | ||
/** | ||
* List of colors used in the animation. | ||
*/ | ||
colors: Set<string>(); | ||
/** * | ||
* Size of the Lottie JSON | ||
*/ | ||
fileSize?: FileSizeValue; | ||
/** | ||
* Framerate in frames per second | ||
*/ | ||
framerate: number; | ||
/** | ||
* Total number of frames in the animation. | ||
*/ | ||
frames: number; | ||
/** | ||
* Generator of the animation. | ||
*/ | ||
generator: string; | ||
/** | ||
* Height of the animation. | ||
*/ | ||
height: number; | ||
/** | ||
* Which frame the animation starts at (usually 0) | ||
*/ | ||
inPoint: number; | ||
/** | ||
* Which frame the animation stops/loops at, which makes this the duration in frames when ip is 0 | ||
*/ | ||
outPoint: number; | ||
/** | ||
* Version of the Lottie JSON. | ||
*/ | ||
version: string; | ||
/** | ||
* Width of the animation. | ||
*/ | ||
width: number; | ||
}; | ||
} | ||
``` | ||
|
||
## Use | ||
|
||
```sh | ||
yarn add @lottiefiles/relottie-metadata | ||
``` | ||
|
||
```ts | ||
import relottieParse, { type ParseFileData } from '@lottiefiles/relottie-parse'; | ||
import relottieStringify, { type StringifyFileData } from '@lottiefiles/relottie-stringify'; | ||
import relottieMetadata, { type MetadataFileData } from '@lottiefiles/relottie-metadata'; | ||
import { unified } from 'unified'; | ||
|
||
type FileData = ParseFileData & StringifyFileData & MetadataFileData | ||
|
||
// The Lottie source: __fixtures__/features/auto-orient.json | ||
const lottieJson = '...'; | ||
|
||
const vfile = unified() | ||
.use(relottieParse) | ||
.use(relottieMetadata) | ||
.use(relottieStringify) | ||
.processSync(lottieJson); | ||
|
||
const data = vfile.data as FileData | ||
const output = data['metadata'] | ||
``` | ||
|
||
`output`: | ||
|
||
```snap | ||
{ | ||
"colors": Set { | ||
"#3250b0", | ||
}, | ||
"fileSize": { | ||
"bytes": 2653, | ||
"formated": { | ||
"exponent": 1, | ||
"symbol": "KiB", | ||
"unit": "KiB", | ||
"value": "2.59", | ||
}, | ||
}, | ||
"framerate": 60, | ||
"frames": 180, | ||
"generator": "Glaxnimate 0.4.6-26-g7b05e75c", | ||
"height": 512, | ||
"inPoint": 0, | ||
"outPoint": 180, | ||
"version": "5.5.7", | ||
"width": 512, | ||
} | ||
... | ||
``` | ||
|
||
## 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-metadata`) | ||
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 |
26 changes: 26 additions & 0 deletions
26
packages/relottie-metadata/__tests__/__snapshots__/extra/100-frames.snap
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,26 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`relottie-metadata fixtures extra Test in 100-frames.json should have correct data 1`] = ` | ||
{ | ||
"colors": Set { | ||
"#ffffff", | ||
}, | ||
"fileSize": { | ||
"bytes": 13021, | ||
"formated": { | ||
"exponent": 1, | ||
"symbol": "KiB", | ||
"unit": "KiB", | ||
"value": "12.72", | ||
}, | ||
}, | ||
"framerate": 30, | ||
"frames": 100, | ||
"generator": "@lottiefiles/toolkit-js 0.8.1", | ||
"height": 500, | ||
"inPoint": 0, | ||
"outPoint": 100, | ||
"version": "5.5.5", | ||
"width": 1, | ||
} | ||
`; |
26 changes: 26 additions & 0 deletions
26
packages/relottie-metadata/__tests__/__snapshots__/extra/1000-frames.snap
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,26 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`relottie-metadata fixtures extra Test in 1000-frames.json should have correct data 1`] = ` | ||
{ | ||
"colors": Set { | ||
"#ffffff", | ||
}, | ||
"fileSize": { | ||
"bytes": 124621, | ||
"formated": { | ||
"exponent": 1, | ||
"symbol": "KiB", | ||
"unit": "KiB", | ||
"value": "121.7", | ||
}, | ||
}, | ||
"framerate": 30, | ||
"frames": 1000, | ||
"generator": "@lottiefiles/toolkit-js 0.8.1", | ||
"height": 500, | ||
"inPoint": 0, | ||
"outPoint": 1000, | ||
"version": "", | ||
"width": 1, | ||
} | ||
`; |
26 changes: 26 additions & 0 deletions
26
packages/relottie-metadata/__tests__/__snapshots__/extra/50-frames.snap
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,26 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`relottie-metadata fixtures extra Test in 50-frames.json should have correct data 1`] = ` | ||
{ | ||
"colors": Set { | ||
"#ffffff", | ||
}, | ||
"fileSize": { | ||
"bytes": 7439, | ||
"formated": { | ||
"exponent": 1, | ||
"symbol": "KiB", | ||
"unit": "KiB", | ||
"value": "7.26", | ||
}, | ||
}, | ||
"framerate": 30, | ||
"frames": 50, | ||
"generator": "@lottiefiles/toolkit-js 0.8.1", | ||
"height": 500, | ||
"inPoint": 0, | ||
"outPoint": 50, | ||
"version": "", | ||
"width": 1, | ||
} | ||
`; |
26 changes: 26 additions & 0 deletions
26
packages/relottie-metadata/__tests__/__snapshots__/extra/bicycle.snap
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,26 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`relottie-metadata fixtures extra Test in bicycle.json should have correct data 1`] = ` | ||
{ | ||
"colors": Set { | ||
"#ffffff", | ||
}, | ||
"fileSize": { | ||
"bytes": 145803, | ||
"formated": { | ||
"exponent": 1, | ||
"symbol": "KiB", | ||
"unit": "KiB", | ||
"value": "142.39", | ||
}, | ||
}, | ||
"framerate": 29.9700012207031, | ||
"frames": 150.000006109625, | ||
"generator": "", | ||
"height": 800, | ||
"inPoint": 0, | ||
"outPoint": 150.000006109625, | ||
"version": "5.6.3", | ||
"width": 800, | ||
} | ||
`; |
24 changes: 24 additions & 0 deletions
24
packages/relottie-metadata/__tests__/__snapshots__/extra/delivered.snap
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,24 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`relottie-metadata fixtures extra Test in delivered.json should have correct data 1`] = ` | ||
{ | ||
"colors": Set {}, | ||
"fileSize": { | ||
"bytes": 92103, | ||
"formated": { | ||
"exponent": 1, | ||
"symbol": "KiB", | ||
"unit": "KiB", | ||
"value": "89.94", | ||
}, | ||
}, | ||
"framerate": 30, | ||
"frames": 990, | ||
"generator": "LottieFiles AE 3.0.0", | ||
"height": 1529, | ||
"inPoint": 60, | ||
"outPoint": 1050, | ||
"version": "4.8.0", | ||
"width": 1441, | ||
} | ||
`; |
24 changes: 24 additions & 0 deletions
24
packages/relottie-metadata/__tests__/__snapshots__/extra/ducky.snap
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,24 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`relottie-metadata fixtures extra Test in ducky.json should have correct data 1`] = ` | ||
{ | ||
"colors": Set {}, | ||
"fileSize": { | ||
"bytes": 27948, | ||
"formated": { | ||
"exponent": 1, | ||
"symbol": "KiB", | ||
"unit": "KiB", | ||
"value": "27.29", | ||
}, | ||
}, | ||
"framerate": 60, | ||
"frames": 120, | ||
"generator": "LottieFiles AE ", | ||
"height": 1024, | ||
"inPoint": 0, | ||
"outPoint": 120, | ||
"version": "4.8.0", | ||
"width": 1024, | ||
} | ||
`; |
24 changes: 24 additions & 0 deletions
24
packages/relottie-metadata/__tests__/__snapshots__/extra/extremely-big.snap
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,24 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`relottie-metadata fixtures extra Test in extremely-big.json should have correct data 1`] = ` | ||
{ | ||
"colors": Set {}, | ||
"fileSize": { | ||
"bytes": 1817115, | ||
"formated": { | ||
"exponent": 2, | ||
"symbol": "MiB", | ||
"unit": "MiB", | ||
"value": "1.73", | ||
}, | ||
}, | ||
"framerate": 29.9700012207031, | ||
"frames": 109.0000044396613, | ||
"generator": "", | ||
"height": 5103, | ||
"inPoint": 26.0000010590017, | ||
"outPoint": 135.000005498663, | ||
"version": "5.5.2", | ||
"width": 5103, | ||
} | ||
`; |
24 changes: 24 additions & 0 deletions
24
packages/relottie-metadata/__tests__/__snapshots__/extra/grocery.snap
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,24 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`relottie-metadata fixtures extra Test in grocery.json should have correct data 1`] = ` | ||
{ | ||
"colors": Set {}, | ||
"fileSize": { | ||
"bytes": 157798, | ||
"formated": { | ||
"exponent": 1, | ||
"symbol": "KiB", | ||
"unit": "KiB", | ||
"value": "154.1", | ||
}, | ||
}, | ||
"framerate": 30, | ||
"frames": 1020, | ||
"generator": "LottieFiles AE 3.0.0", | ||
"height": 1528, | ||
"inPoint": 30, | ||
"outPoint": 1050, | ||
"version": "4.8.0", | ||
"width": 1436, | ||
} | ||
`; |
24 changes: 24 additions & 0 deletions
24
packages/relottie-metadata/__tests__/__snapshots__/extra/inlined-assets.snap
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,24 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`relottie-metadata fixtures extra Test in inlined-assets.json should have correct data 1`] = ` | ||
{ | ||
"colors": Set {}, | ||
"fileSize": { | ||
"bytes": 41860, | ||
"formated": { | ||
"exponent": 1, | ||
"symbol": "KiB", | ||
"unit": "KiB", | ||
"value": "40.88", | ||
}, | ||
}, | ||
"framerate": 60, | ||
"frames": 3510, | ||
"generator": "", | ||
"height": 720, | ||
"inPoint": 0, | ||
"outPoint": 3510, | ||
"version": "5.5.1", | ||
"width": 234, | ||
} | ||
`; |
Oops, something went wrong.