Skip to content

Commit

Permalink
chore: add playground.js
Browse files Browse the repository at this point in the history
  • Loading branch information
theashraf committed Nov 4, 2024
1 parent 3873f14 commit 9b1d77e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/dotlottie-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"engines": {
"node": ">=18.0.0"
},
"main": "./dist/index.js",
"main": "./dist/index.node.js",
"exports": {
".": {
"node": "./dist/index.node.js",
Expand Down
68 changes: 68 additions & 0 deletions packages/dotlottie-js/playground.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright 2024 Design Barn Inc.
*/

/**
* This is a playground for creating/testing .lottie files.
*/

import fs from 'fs';

import { DotLottie } from './dist/index.node.js';
import BALL_DATA from './src/__tests__/__fixtures__/ball.json' assert { type: 'json' };

async function main() {
const dotLottie = new DotLottie();

dotLottie.addAnimation({
id: 'ball',
data: BALL_DATA,
});

dotLottie.addTheme({
id: 'dark',
data: {
rules: [
{ id: 'ball_color', type: 'Color', value: [0, 1, 0, 1] },
{
id: 'bg_color',
type: 'Color',
keyframes: [
{
frame: 0,
value: [0, 0, 0, 1],
inTangent: { x: 0.6, y: 0.6 },
outTangent: { x: 0.6, y: 0.6 },
},
{ frame: 60, value: [1, 1, 1, 1] },
],
},
],
},
});

dotLottie.addTheme({
id: 'light',
data: {
rules: [
{
id: 'ball_color',
type: 'Color',
keyframes: [
{ frame: 0, value: [0, 0, 0, 1], inTangent: { x: 0.6, y: 0.6 }, outTangent: { x: 0.6, y: 0.6 } },
{ frame: 60, value: [1, 1, 1, 1] },
],
},
{ id: 'bg_color', type: 'Color', value: [0, 0.6, 0.6, 1] },
],
},
});

await dotLottie.build();

const buffer = await dotLottie.toArrayBuffer();

fs.writeFileSync('output.lottie', new Uint8Array(buffer));
}

main();

0 comments on commit 9b1d77e

Please sign in to comment.