From 9b1d77e50fc92f56927b2c02b1d8decfe93013e0 Mon Sep 17 00:00:00 2001 From: Abdelrahman Ashraf Date: Mon, 4 Nov 2024 23:33:19 +0700 Subject: [PATCH] chore: add playground.js --- packages/dotlottie-js/package.json | 2 +- packages/dotlottie-js/playground.js | 68 +++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 packages/dotlottie-js/playground.js diff --git a/packages/dotlottie-js/package.json b/packages/dotlottie-js/package.json index 36039d4..c192c11 100644 --- a/packages/dotlottie-js/package.json +++ b/packages/dotlottie-js/package.json @@ -21,7 +21,7 @@ "engines": { "node": ">=18.0.0" }, - "main": "./dist/index.js", + "main": "./dist/index.node.js", "exports": { ".": { "node": "./dist/index.node.js", diff --git a/packages/dotlottie-js/playground.js b/packages/dotlottie-js/playground.js new file mode 100644 index 0000000..0804a04 --- /dev/null +++ b/packages/dotlottie-js/playground.js @@ -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();