Giter Site home page Giter Site logo

relottie's Introduction

relottie

CI GitHub contributors GitHub

relottie is a tool that transforms Lotties with plugins. These plugins can inspect and change.

Feature highlights

  • ASTs (inspecting and changing content made easy)
  • plugins (plugins you can pick and choose from)

Intro

relottie is a ecosystem of plugins that work with the Lottie file format as structured data, specifically ASTs (abstract syntax trees). ASTs make it easy for programs to deal with Lottie files. We call those programs plugins. Plugins inspect and change trees. You can use the existing plugins or you can make your own.

Contents

What is this?

You can use plugins to change Lottie.

In:

{ "v": "5.5.2" }

Plugin:

import {visit} from 'unist-util-visit'
import type { Plugin, Node } from 'unified'
import type { Root } from '@lottiefiles/last'

const myRelottiePlugin: Plugin<[]> () {
  function transform (tree: Root, _file: VFile): void {
    visit(tree, (node) => {
      if (node.title === 'version') {
        node.title = "6.0.0" 
      }
    })
  }

  return transform
}

Out:

{ "v": "6.0.0" }

You can use relottie for many different things. unified is the core project that transforms content with ASTs. relottie adds support for Lottie to unified. last is the Lottie AST that relottie uses.

This GitHub repository is a monorepo that contains the following packages:

  • last — Type definitions for Lottie Abstract Syntax Tree (last)
  • last-builder — Composable functions to easily build syntax tree (last) structures
  • relottie — a unified processor with support for parsing Lottie input and serializing Lottie as output
  • relottie-parse — plugin to take Lottie as input and turn it into a syntax tree last
  • relottie-stringify — plugin to take a syntax tree (last) and turn it into Lottie as output
  • relottie-cli — Command line interface to inspect and change Lottie files with relottie
  • relottie-extract-features — plugin to extract Lottie features from the document and store them in vfile
  • relottie-metadata — plugin to extract Lottie metadata from the document and store them in vfile.data

When should I use this?

relottie focusses on ASTs and providing an interface for plugins to transform them.

Depending on the input you have and output you want, you can use different parts of relottie. If the input is Lottie JSON file, you can use relottie-parse with unified. If the output is Lottie JSON file, you can use relottie-stringify with unified. If you need to transform LottieJSON to .lottie, you can dotlottie.js

Plugins

relottie plugins deal with Lottie. Some popular examples are:

These plugins are exemplary because what they do and how they do it is quite different, respectively to extend Lottie syntax, inspect trees, change trees, and define other output formats.

You can choose from the plugins that already exist. Here are three good ways to find plugins:

Some plugins are maintained by us here in the @lottiefiles organization while others are maintained by folks elsewhere. Anyone can make relottie plugins, so as always when choosing whether to include dependencies in your project, make sure to carefully assess the quality of relottie plugins too.

Examples

  • be the first one ;)

Syntax

relottie follows last definitions, lottie-types and lottie-docs title names (with a few changes) Some syntax extensions are supported through plugins.

We use momoa JSON parser for our parsing. See its documentation for more information.

Syntax tree

The syntax tree format used in relottie is last. It represents Lottie constructs as JSON objects.

In:

{ "v": "6.0.0" }

Out:

{
  "type": "root",
  "title": "animation",
  "hasExpressions": false,
  "position": {
    "start": {
      "line": 1,
      "column": 1,
      "offset": 0
    },
    "end": {
      "line": 1,
      "column": 17,
      "offset": 16
    }
  },
  "children": [
    {
      "type": "attribute",
      "key": {
        "type": "key",
        "position": {
          "start": {
            "line": 1,
            "column": 3,
            "offset": 2
          },
          "end": {
            "line": 1,
            "column": 6,
            "offset": 5
          }
        },
        "value": "v"
      },
      "title": "version",
      "position": {
        "start": {
          "line": 1,
          "column": 3,
          "offset": 2
        },
        "end": {
          "line": 1,
          "column": 15,
          "offset": 14
        }
      },
      "children": [
        {
          "type": "primitive",
          "value": "6.0.0",
          "position": {
            "start": {
              "line": 1,
              "column": 8,
              "offset": 7
            },
            "end": {
              "line": 1,
              "column": 15,
              "offset": 14
            }
          },
          "valueType": "string"
        }
      ]
    }
  ]
}

Types

The relottie organization and the unified as a whole is fully typed with TypeScript. Types for last are available in last. Also have a look at lottie-types.

For TypeScript to work, it is particularly important to type your plugins correctly. We strongly recommend using the Plugin type from unified with its generics and to use the node types for the syntax trees provided by last.

import type { Root } from '@lottiefiles/last';
import type { Plugin } from 'unified';

export function myRelottiePluginAcceptingOptions(options): Plugin<[Options?], Root> {
  // `options` is `Options?`.
  return function (tree, file) {
    // `tree` is `Root`.
  }
}

Compatibility

As of now, that is Node.js 16.0+, and 18.0+ (other versions have not been tested yet) Our projects sometimes work with older versions, but this is not guaranteed.

Security

As last properties can have expressions, and improper use of last can open you up to cross-site scripting cross-site scripting (XSS). Carefully assess each plugin and the risks involved in using them.

Setting up Monorepo

git clone https://github.com/LottieFiles/relottie.git

cd relottie

pnpm install

Running in dev mode

pnpm dev

Running test suite

pnpm test

Add a changelog message

We use changeset

pnpm changelog

Building

pnpm build

Linting

pnpm lint

Contribute

Any contributions are welcome.

Community & Support

  • Github issues. For bugs and errors you encounter using this player.
  • Discord. For hanging out with the community and sharing your awesome Lottie animations!

Acknowledgments

The initial release of this project was authored by @aidosmf

License

MIT © LottieFiles

relottie's People

Contributors

aidosmf avatar github-actions[bot] avatar jawish avatar lottiefiles-bot avatar renovate[bot] avatar theashraf avatar xbbshampoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

relottie's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency @lottiefiles/lottie-types to v1.4.1
  • chore(deps): update dependency @types/jest-specific-snapshot to v0.5.9
  • chore(deps): update dependency @types/unist to v2.0.10
  • chore(deps): update dependency prettier to v2.8.8
  • chore(deps): update dependency syncpack to v8.5.14
  • chore(deps): update dependency tape to v5.7.2
  • chore(deps): update dependency tsup to v6.7.0
  • chore(deps): update dependency turbo to v1.10.16
  • chore(deps): update dependency typescript to v4.9.5
  • chore(deps): update dependency zx to v7.2.3
  • fix(deps): update dependency unist-util-is to v5.2.1
  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-node action to v4
  • chore(deps): update dependency @commitlint/cli to v18
  • chore(deps): update dependency @size-limit/preset-big-lib to v11
  • chore(deps): update dependency @types/node to v20
  • chore(deps): update dependency @types/unist to v3
  • chore(deps): update dependency clinic to v13
  • chore(deps): update dependency eslint to v8
  • chore(deps): update dependency execa to v8
  • chore(deps): update dependency jest-specific-snapshot to v8
  • chore(deps): update dependency lint-staged to v15
  • chore(deps): update dependency npm-check-updates to v16
  • chore(deps): update dependency prettier to v3
  • chore(deps): update dependency remark-cli to v12
  • chore(deps): update dependency size-limit to v11
  • chore(deps): update dependency syncpack to v11
  • chore(deps): update dependency tsup to v7
  • chore(deps): update dependency typescript to v5
  • chore(deps): update dependency unist-util-visit to v5
  • chore(deps): update dependency vfile to v6
  • chore(deps): update dependency vfile-reporter to v8
  • fix(deps): update dependency @humanwhocodes/momoa to v3
  • fix(deps): update dependency unified to v11
  • fix(deps): update dependency unified-args to v11
  • fix(deps): update dependency unist-builder to v4
  • fix(deps): update dependency unist-util-is to v6
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/release.yml
  • actions/checkout v2
  • pnpm/action-setup v2
  • actions/setup-node v3
  • andresz1/size-limit-action v1
  • actions/checkout v2
  • pnpm/action-setup v2
  • actions/setup-node v3
  • changesets/action v1
  • actions/setup-node v3
  • changesets/action v1
npm
package.json
  • @changesets/cli 2.23.2
  • @commitlint/cli 17.0.3
  • @lottiefiles/commitlint-config 2.0.0
  • @lottiefiles/eslint-plugin 3.0.0
  • @lottiefiles/jest-config 1.0.0
  • @lottiefiles/prettier-config 3.0.0
  • @lottiefiles/tsconfig 2.0.0
  • @size-limit/preset-big-lib 8.2.6
  • clinic 11.1.2
  • cross-env 7.0.3
  • esbuild 0.14.49
  • eslint 7.32.0
  • husky 8.0.3
  • jest 28.1.3
  • jest-specific-snapshot 5.0.0
  • lint-staged 13.0.3
  • npm-check-updates 15.3.4
  • prettier 2.7.1
  • remark-cli 11.0.0
  • size-limit 8.2.6
  • syncpack 8.2.4
  • turbo 1.3.4
  • typescript 4.7.4
  • pnpm 8.6.9
packages/last-builder/package.json
  • unist-builder 3.0.0
  • @jest/globals 28.1.3
  • @lottiefiles/jest-config 1.0.0
  • @lottiefiles/lottie-types 1.4.0
  • @types/jest 28.1.8
  • @types/unist 2.0.7
  • esbuild 0.14.49
  • tsup 6.1.3
  • typescript 4.7.4
  • node >=18
packages/last/package.json
  • @jest/globals 28.1.3
  • @lottiefiles/jest-config 1.0.0
  • @lottiefiles/lottie-types 1.4.0
  • @types/jest 28.1.8
  • @types/unist 2.0.7
  • esbuild 0.14.49
  • tsup 6.1.3
  • typescript 4.7.4
  • node >=18
packages/relottie-cli/package.json
  • unified-args 10.0.0
  • execa 6.0.0
  • tape 5.0.0
  • tsup 6.1.3
  • node >=18
packages/relottie-parse/package.json
  • @humanwhocodes/momoa 2.0.3
  • unist-util-is 5.1.1
  • @jest/globals 28.1.3
  • @lottiefiles/jest-config 1.0.0
  • @lottiefiles/lottie-types 1.4.0
  • @types/jest 28.1.8
  • @types/jest-specific-snapshot 0.5.6
  • @types/node 18.0.4
  • @types/unist 2.0.7
  • esbuild 0.14.49
  • jest 28.1.3
  • jest-specific-snapshot 5.0.0
  • ts-jest 28.0.8
  • ts-node 10.9.1
  • tsup 6.1.3
  • typescript 4.7.4
  • unified 10.1.2
  • vfile 5.3.7
  • vfile-reporter 7.0.5
  • node >=18
packages/relottie-stringify/package.json
  • @jest/globals 28.1.3
  • @lottiefiles/jest-config 1.0.0
  • @lottiefiles/lottie-types 1.4.0
  • @types/jest 28.1.8
  • @types/node 18.0.4
  • @types/unist 2.0.7
  • esbuild 0.14.49
  • ts-node 10.9.1
  • tsup 6.1.3
  • typescript 4.7.4
  • unified 10.1.2
  • unist-util-visit 4.1.2
  • vfile 5.3.7
  • node >=18
packages/relottie/package.json
  • unified 10.1.2
  • @jest/globals 28.1.3
  • @lottiefiles/jest-config 1.0.0
  • @types/jest 28.1.8
  • @types/jest-specific-snapshot 0.5.6
  • @types/node 18.0.4
  • @types/unist 2.0.7
  • esbuild 0.14.49
  • jest-specific-snapshot 5.0.0
  • ts-node 10.9.1
  • tsup 6.1.3
  • typescript 4.7.4
  • vfile-reporter 7.0.5
  • node >=18
scripts/package.json
  • zx 7.0.7

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.