@vvfx/lottie2ir 0.0.1-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +91 -0
- package/dist/assemble-ir-scene.d.ts +12 -0
- package/dist/common/conversion-diagnostic.d.ts +11 -0
- package/dist/common/conversion-types.d.ts +31 -0
- package/dist/common/converter-error.d.ts +17 -0
- package/dist/common/id.d.ts +2 -0
- package/dist/convert-lottie-to-ir.d.ts +10 -0
- package/dist/converter/convert-lottie-image-assets.d.ts +4 -0
- package/dist/converter/convert-lottie-layer.d.ts +28 -0
- package/dist/converter/convert-lottie-mask.d.ts +8 -0
- package/dist/converter/convert-lottie-shapes.d.ts +17 -0
- package/dist/converter/convert-lottie-text.d.ts +20 -0
- package/dist/converter/convert-lottie-transform.d.ts +10 -0
- package/dist/extract-lottie-from-zip.d.ts +11 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +11399 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +11394 -0
- package/dist/index.mjs.map +1 -0
- package/dist/parser/parse-lottie-input.d.ts +9 -0
- package/dist/parser/parse-lottie-layer-stack.d.ts +27 -0
- package/dist/parser/parse-lottie-property.d.ts +17 -0
- package/dist/parser/parse-lottie-text-document.d.ts +3 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT LICENSE
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-present Ant Group Co., Ltd. https://www.antgroup.com/
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# @vvfx/lottie2ir
|
|
2
|
+
|
|
3
|
+
Lottie to Animation IR converter.
|
|
4
|
+
|
|
5
|
+
## Contents
|
|
6
|
+
|
|
7
|
+
- [Install](#install)
|
|
8
|
+
- [Usage](#usage)
|
|
9
|
+
- [API](#api)
|
|
10
|
+
- [Project structure](#project-structure)
|
|
11
|
+
- [Contributing](#contributing)
|
|
12
|
+
- [License](#license)
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
Node.js 22 or later is required.
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pnpm add @vvfx/lottie2ir
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Convert JSON
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { convertLottieToIR } from '@vvfx/lottie2ir';
|
|
28
|
+
|
|
29
|
+
const result = convertLottieToIR(lottieJSON, {
|
|
30
|
+
resourceBaseUrl: 'https://cdn.example.com/animations/data.json',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
console.info(result.scene.format); // animation-ir
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`convertLottieToIR` accepts either a Lottie JSON object or a serialized JSON string. Relative image and font paths are
|
|
37
|
+
resolved against the absolute `resourceBaseUrl`.
|
|
38
|
+
|
|
39
|
+
### Extract ZIP input
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { convertLottieToIR, extractLottieFromZip } from '@vvfx/lottie2ir';
|
|
43
|
+
|
|
44
|
+
const extracted = await extractLottieFromZip(zipArrayBuffer);
|
|
45
|
+
const result = convertLottieToIR(extracted.json, { zipResources: extracted });
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## API
|
|
49
|
+
|
|
50
|
+
### `convertLottieToIR(input, options?)`
|
|
51
|
+
|
|
52
|
+
- `input`: a Lottie JSON object or serialized JSON string.
|
|
53
|
+
- `options.resourceBaseUrl`: absolute base URL for relative image and font paths.
|
|
54
|
+
- `options.zipResources`: ZIP resource directory and Data URL map returned by `extractLottieFromZip`.
|
|
55
|
+
- Returns `{ scene: IRScene; diagnostics: ConversionDiagnostic[] }` after validating the IR scene.
|
|
56
|
+
|
|
57
|
+
### `extractLottieFromZip(zipData)`
|
|
58
|
+
|
|
59
|
+
Accepts a ZIP `ArrayBuffer` and returns the serialized JSON, resource Data URL map, and JSON directory.
|
|
60
|
+
|
|
61
|
+
### Errors
|
|
62
|
+
|
|
63
|
+
`LottieConverterError` and `LOTTIE_CONVERTER_ERROR_CODES` are exported from the package root for JSON, ZIP, conversion
|
|
64
|
+
pipeline, and IR validation failures.
|
|
65
|
+
|
|
66
|
+
## Project structure
|
|
67
|
+
|
|
68
|
+
```text
|
|
69
|
+
src/
|
|
70
|
+
├── convert-lottie-to-ir.ts # Public conversion flow and IR boundary validation
|
|
71
|
+
├── assemble-ir-scene.ts # IRScene and Composition assembly
|
|
72
|
+
├── extract-lottie-from-zip.ts # Lottie JSON and resource extraction from ZIP input
|
|
73
|
+
├── parser/ # Input, layer stack, and property parsing
|
|
74
|
+
├── converter/ # Layer, asset, mask, shape, text, and transform conversion
|
|
75
|
+
├── common/ # Types, error model, and identifier generation
|
|
76
|
+
└── index.ts # Stable public entry
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Contributing
|
|
80
|
+
|
|
81
|
+
Use repository issues for questions and bug reports. Pull requests are welcome. Run the following checks after changing
|
|
82
|
+
conversion behavior:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pnpm --filter @vvfx/lottie2ir test
|
|
86
|
+
pnpm --filter @vvfx/lottie2ir build
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
[MIT](./LICENSE) © 2019-present Ant Group Co., Ltd.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LottieJSON, LottieToIRResult } from './common/conversion-types';
|
|
2
|
+
interface AssembleLottieIRSceneOptions {
|
|
3
|
+
resolveResourceUrl?: (url: string) => string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Assembles a Lottie animation into one root Composition plus one Composition per precomposition asset.
|
|
7
|
+
*
|
|
8
|
+
* Layer references are resolved before conversion, while image and font resources are collected into the shared Scene
|
|
9
|
+
* asset registry. Unsupported or approximated source features are returned as diagnostics.
|
|
10
|
+
*/
|
|
11
|
+
export declare function assembleLottieIRScene(json: LottieJSON, options?: AssembleLottieIRSceneOptions): LottieToIRResult;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ConversionDiagnostic } from '@vvfx/animation-ir/adapter';
|
|
2
|
+
type LottieDiagnosticCode = 'unsupported-layer-type' | 'unsupported-shape-type' | 'unsupported-shape-feature' | 'unsupported-mask' | 'unsupported-track-matte' | 'missing-font' | 'missing-image-asset' | 'missing-text-data' | 'invalid-stretch-ratio' | 'separated-position-fallback' | 'animated-anchor-fallback' | 'animated-gradient-fallback';
|
|
3
|
+
interface CreateLottieDiagnosticOptions {
|
|
4
|
+
code: LottieDiagnosticCode;
|
|
5
|
+
message: string;
|
|
6
|
+
layerInd?: number;
|
|
7
|
+
featureKinds?: string[];
|
|
8
|
+
}
|
|
9
|
+
/** Creates a source-scoped warning for a normalized, approximated, or dropped Lottie feature. */
|
|
10
|
+
export declare function createLottieDiagnostic(options: CreateLottieDiagnosticOptions): ConversionDiagnostic;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { IRScene } from '@vvfx/animation-ir';
|
|
2
|
+
import type { ConversionDiagnostic } from '@vvfx/animation-ir/adapter';
|
|
3
|
+
import type { Animation, Layer, Asset, Text, AnimatedProperty, Shape } from '@lottie-animation-community/lottie-types';
|
|
4
|
+
export type LottieJSON = Animation;
|
|
5
|
+
export type LottieLayer = Layer.Value;
|
|
6
|
+
export type LottieAsset = Asset.Value;
|
|
7
|
+
export type LottieVisualLayer = Layer.Precomposition | Layer.SolidColor | Layer.Image | Layer.Null | Layer.Shape | Layer.Text;
|
|
8
|
+
export type LottiePrecompAsset = Asset.Precomposition & {
|
|
9
|
+
w?: number;
|
|
10
|
+
h?: number;
|
|
11
|
+
};
|
|
12
|
+
export type LottieImageAsset = Asset.Image;
|
|
13
|
+
export type LottieFont = Text.Font;
|
|
14
|
+
export type LottieGradientData = AnimatedProperty.GradientColors;
|
|
15
|
+
export type LottieShapeElement = Shape.Value;
|
|
16
|
+
/** Resources extracted from the directory containing a Lottie JSON file in a ZIP archive. */
|
|
17
|
+
export interface LottieZipResources {
|
|
18
|
+
resources: Record<string, string>;
|
|
19
|
+
dirPath: string;
|
|
20
|
+
}
|
|
21
|
+
export interface LottieToIROptions {
|
|
22
|
+
/** Absolute base URL used to resolve relative image and font paths. */
|
|
23
|
+
resourceBaseUrl?: string;
|
|
24
|
+
/** Resources extracted from the same ZIP archive as the Lottie JSON. */
|
|
25
|
+
zipResources?: LottieZipResources;
|
|
26
|
+
}
|
|
27
|
+
/** Conversion output and non-fatal diagnostics. */
|
|
28
|
+
export interface LottieToIRResult {
|
|
29
|
+
scene: IRScene;
|
|
30
|
+
diagnostics: ConversionDiagnostic[];
|
|
31
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Stable error codes for public control flow. */
|
|
2
|
+
export declare const LOTTIE_CONVERTER_ERROR_CODES: {
|
|
3
|
+
readonly INVALID_LOTTIE_JSON: "INVALID_LOTTIE_JSON";
|
|
4
|
+
readonly ZIP_PARSE_FAILED: "ZIP_PARSE_FAILED";
|
|
5
|
+
readonly ZIP_JSON_NOT_FOUND: "ZIP_JSON_NOT_FOUND";
|
|
6
|
+
readonly IR_VALIDATION_FAILED: "IR_VALIDATION_FAILED";
|
|
7
|
+
readonly CONVERT_PIPELINE_FAILED: "CONVERT_PIPELINE_FAILED";
|
|
8
|
+
};
|
|
9
|
+
export type LottieConverterErrorCode = (typeof LOTTIE_CONVERTER_ERROR_CODES)[keyof typeof LOTTIE_CONVERTER_ERROR_CODES];
|
|
10
|
+
/** Error raised by Lottie parsing, conversion, and ZIP input handling. */
|
|
11
|
+
export declare class LottieConverterError extends Error {
|
|
12
|
+
readonly code: LottieConverterErrorCode;
|
|
13
|
+
readonly details?: Record<string, unknown>;
|
|
14
|
+
constructor(code: LottieConverterErrorCode, message: string, details?: Record<string, unknown>);
|
|
15
|
+
}
|
|
16
|
+
/** Normalizes an unknown failure under the caller-selected public error code. */
|
|
17
|
+
export declare function normalizeToConverterError(error: unknown, fallbackCode: LottieConverterErrorCode, fallbackMessage: string, details?: Record<string, unknown>): LottieConverterError;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LottieJSON, LottieToIROptions, LottieToIRResult } from './common/conversion-types';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a Lottie JSON object or serialized JSON string to Animation IR.
|
|
4
|
+
*
|
|
5
|
+
* ZIP resources take precedence over URLs resolved through `resourceBaseUrl`. The generated Scene is validated before
|
|
6
|
+
* it is returned.
|
|
7
|
+
*
|
|
8
|
+
* @throws `LottieConverterError` when parsing, conversion, or IR validation fails.
|
|
9
|
+
*/
|
|
10
|
+
export declare function convertLottieToIR(input: string | LottieJSON, options?: LottieToIROptions): LottieToIRResult;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type IRImageAsset } from '@vvfx/animation-ir';
|
|
2
|
+
import type { LottieImageAsset } from '../common/conversion-types';
|
|
3
|
+
/** Converts Lottie image assets with resource paths into the shared IR Asset registry. */
|
|
4
|
+
export declare function convertLottieImageAssets(assets: LottieImageAsset[], resolveResourceUrl?: (url: string) => string): IRImageAsset[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type IRLayer, type IRLayerMatte } from '@vvfx/animation-ir';
|
|
2
|
+
import type { ConversionDiagnostic } from '@vvfx/animation-ir/adapter';
|
|
3
|
+
import type { LottieImageAsset, LottiePrecompAsset, LottieVisualLayer } from '../common/conversion-types';
|
|
4
|
+
interface CompositionFrameRange {
|
|
5
|
+
inPoint: number;
|
|
6
|
+
outPoint: number;
|
|
7
|
+
}
|
|
8
|
+
interface ConvertLottieLayerOptions {
|
|
9
|
+
layer: LottieVisualLayer;
|
|
10
|
+
asset?: LottieImageAsset | LottiePrecompAsset;
|
|
11
|
+
id: string;
|
|
12
|
+
parentLayerId?: string;
|
|
13
|
+
matte?: IRLayerMatte;
|
|
14
|
+
compositionRange: CompositionFrameRange;
|
|
15
|
+
precompCompositionId?: string;
|
|
16
|
+
fontAssetIdByName: ReadonlyMap<string, string>;
|
|
17
|
+
}
|
|
18
|
+
interface ConvertLottieLayerResult {
|
|
19
|
+
layer: IRLayer;
|
|
20
|
+
diagnostics: ConversionDiagnostic[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Lowers one supported Lottie Layer after its parent, matte, and precomposition references have been resolved.
|
|
24
|
+
*
|
|
25
|
+
* Fidelity limitations are returned with the converted Layer for Scene-level diagnostic assembly.
|
|
26
|
+
*/
|
|
27
|
+
export declare function convertLottieLayer(options: ConvertLottieLayerOptions): ConvertLottieLayerResult;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type IRMask } from '@vvfx/animation-ir';
|
|
2
|
+
interface LottieMaskConversion {
|
|
3
|
+
mask?: IRMask;
|
|
4
|
+
unsupportedFeatures: string[];
|
|
5
|
+
}
|
|
6
|
+
/** Converts one supported authored Mask and reports features that prevent conversion. */
|
|
7
|
+
export declare function convertLottieMask(maskInfo: unknown): LottieMaskConversion;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { LottieShapeElement } from '../common/conversion-types';
|
|
2
|
+
import type { IRShape } from '@vvfx/animation-ir';
|
|
3
|
+
/** Stable diagnostic labels for unsupported Lottie shape operators. */
|
|
4
|
+
export declare const SHAPE_FEATURE_LABELS: Record<string, string>;
|
|
5
|
+
interface LottieShapeConversion {
|
|
6
|
+
shapes: IRShape[];
|
|
7
|
+
approximatedFeatures: string[];
|
|
8
|
+
hasRenderableGeometry: boolean;
|
|
9
|
+
unsupportedFeatures: string[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Converts supported visible shape geometry into IR painter order.
|
|
13
|
+
*
|
|
14
|
+
* Top-level paints are inherited by groups that do not define their own fills or strokes.
|
|
15
|
+
*/
|
|
16
|
+
export declare function convertLottieShapes(shapes: LottieShapeElement[]): LottieShapeConversion;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type IRFontAsset, type IRLocalBounds, type IRTextContent } from '@vvfx/animation-ir';
|
|
2
|
+
import type { LottieFont, LottieLayer } from '../common/conversion-types';
|
|
3
|
+
interface LottieTextConversion {
|
|
4
|
+
content: IRTextContent;
|
|
5
|
+
localBounds: IRLocalBounds;
|
|
6
|
+
}
|
|
7
|
+
interface LottieFontAssetRegistry {
|
|
8
|
+
assets: IRFontAsset[];
|
|
9
|
+
assetIdByFontName: ReadonlyMap<string, string>;
|
|
10
|
+
}
|
|
11
|
+
/** Builds Font Assets for the Text Layers that participate in conversion. */
|
|
12
|
+
export declare function buildLottieFontAssetRegistry(layers: LottieLayer[], fonts: LottieFont[], resolveResourceUrl?: (url: string) => string): LottieFontAssetRegistry;
|
|
13
|
+
/**
|
|
14
|
+
* Converts the first Lottie Text Document keyframe and returns its IR content and local display bounds.
|
|
15
|
+
*
|
|
16
|
+
* The referenced font is resolved from the Scene-level registry. Non-text Layers and Layers without usable Text
|
|
17
|
+
* Document data return `undefined`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function convertLottieText(layer: LottieLayer, fontAssetIdByName: ReadonlyMap<string, string>): LottieTextConversion | undefined;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IRTransform } from '@vvfx/animation-ir';
|
|
2
|
+
import type { LottieVisualLayer } from '../common/conversion-types';
|
|
3
|
+
export declare function hasAnimatedAnchor(layer: LottieVisualLayer): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Converts Lottie transform properties and keyframes to IR units and tangent ownership.
|
|
6
|
+
*
|
|
7
|
+
* Scale and opacity percentages become normalized factors. Animated anchors use their first keyframe because IR anchors
|
|
8
|
+
* are static.
|
|
9
|
+
*/
|
|
10
|
+
export declare function convertLottieTransform(layer: LottieVisualLayer): IRTransform;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LottieZipResources } from './common/conversion-types';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts Lottie JSON and supported image or font resources from a ZIP archive.
|
|
4
|
+
*
|
|
5
|
+
* Resource Data URLs are keyed by archive path, and `dirPath` identifies the JSON file's parent directory.
|
|
6
|
+
*
|
|
7
|
+
* @throws `LottieConverterError` when the archive is invalid or contains no JSON file.
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractLottieFromZip(zipData: ArrayBuffer): Promise<LottieZipResources & {
|
|
10
|
+
json: string;
|
|
11
|
+
}>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { convertLottieToIR } from './convert-lottie-to-ir';
|
|
2
|
+
export { extractLottieFromZip } from './extract-lottie-from-zip';
|
|
3
|
+
export { LottieConverterError, LOTTIE_CONVERTER_ERROR_CODES } from './common/converter-error';
|
|
4
|
+
export type { LottieConverterErrorCode } from './common/converter-error';
|
|
5
|
+
export type { LottieJSON, LottieToIROptions, LottieToIRResult, LottieZipResources, } from './common/conversion-types';
|