npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lottiefiles/lottie-theming

v2.0.1

Published

Lottie theming library

Downloads

10

Readme

Lottie Theming Library

This is a library to extract themable properties and apply different themes to a given Lottie

In Javascript or TypeScript:

  1. Install package using npm or yarn.
npm install --save @lottiefiles/lottie-theming
  1. Import package in your code.
import { LottieTheming } from '@lottiefiles/lottie-theming';

Usage

Given a Lottie this library enables extraction of colors and other properties(WIP) from the Lottie and creates a configuration file with the editable properties. During runtime/implementation on your apps you may apply different themes with your own logic. For example, you could edit this configuration file and add a light theme and a dark theme color palette (see config file structure for reference). In your app you can then use this Library to generate a new Lottie with the given theme applied. You could for example pair this with the Lottie player to play a dark themed Lottie at night and a light themed Lottie during the day. Ofcourse its not only time based, you could write logic to change a Lottie given your own parameters such as location.

Creating theme configuration file and color extraction

  1. Initialise the Library by creating a new instance of LottieTheming.
  2. Then call the init method along with the url of the Lottie.
  3. Call the create config method which will return to you the theme configuration file. This file shows the colors that are themeable and you may add color palettes to this config file.
const theming = new LottieTheming();
await theming.init('https://assets3.lottiefiles.com/packages/lf20_wgh8xmh0.json');
const themeConfig = theming.createConfig();

The example below shows a sample configuration file. Given a Lottie, the library is able to extract out each color and show the user exactly, which frame, shape, and layer the color belongs to. With this information the user is able to add multiple color palettes to a Lottie. Applying the theme happens in runtime which will be explained further in this guide.

     {
       Name: 'testTheme',
       Properties: [
         {
           name: 'Color 0',
           path: 'Frame 0 <- Stroke 1 <- Ellipse 1 <- Shape Layer 4',
           locator: '0'
         },
         {
           name: 'Color 1',
           path: 'Frame 0 <- Fill 1 <- Ellipse 1 <- Shape Layer 4',
           locator: '1'
         },
         {
           name: 'Color 2',
           path: 'Frame 0 <- Stroke 1 <- Ellipse 1 <- Shape Layer 3',
           locator: '2'
         }
       ],
       Themes: [
         {
           defaultTheme: {
             'Color 0': '#13427dff',
             'Color 1': '#13427dff',
             'Color 2': '#5bb3bcff',
           }
         },
         {
           darkTheme: {
             'Color 0': '#ffffffff',
             'Color 1': '#ffffffff',
             'Color 2': '#000000ff',
             'Color 3': '#000000ff',

           }
         }
       ]
     }

Adding themes

To add themes, currently you can directly modify the theme config file and add a named object to the Themes array. The format must be as follows

  {
      defaultTheme: {
        'Color 0': '#13427dff',
        'Color 1': '#13427dff',
        'Color 2': '#5bb3bcff',
      }
  },

The color names must remain as per the name in the Properties array. There is no unique identifier inside of the Lottie format and therefore the ID is set via the Library.

Applying themes

When using this Library to apply themes, assuming your configuration file now has themes other than the default theme added to it, do remember that the instance of the theming library used must be saved to your state and the same instance must be used to apply the Theme. Assuming that you have already called the init method and initialsed the library, you may just call the applyTheme method and pass in the theme configuration file as a JSON object along with the preferred theme to apply. This method will then return back a Lottie that you can load into the player.

// if you have not initialised the library. please do so and call the init method
const theming = new LottieTheming();
theming.init('https://assets3.lottiefiles.com/packages/lf20_wgh8xmh0.json');

// apply theme
const lottie = theming.applyTheme(themeConfig, themeName);

// if time = day
const lottie = theming.applyTheme(themeConfig, 'LightTheme');
// load this returned object to the player

// if time = night
const lottie = theming.applyTheme(themeConfig, 'DarkTheme');
// load this returned object to the player

Testing and development

Testing with jest is set up and you can run yarn test to run the .test file. The source code is located in packages/lib/src/lottie-theming.ts. This library depends on color extraction from the Lottie-JS Library which allows the user to map a Lottie into an object model with named properties. Do have a look at Lottie-JS Library here click here

  1. git clone repo

  2. yarn install

  3. yarn test

License

MIT License © LottieFiles.com