Socket
Socket
Sign inDemoInstall

vue3-lottie

Package Overview
Dependencies
32
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0-beta to 3.0.1-beta

6

dist/vue3-lottie.es.js

@@ -93,3 +93,3 @@ import { defineComponent, ref, computed, watch, onMounted, openBlock, createElementBlock, createElementVNode, normalizeStyle } from "vue";

};
const loadLottie = async (element) => {
const loadLottie = async () => {
let animationData = props.animationData;

@@ -357,5 +357,5 @@ if (props.animationLink != "") {

lottie_player,
getDuration,
direction,
loopCounter,
getDuration,
setDirection,

@@ -391,5 +391,5 @@ setSpeed,

const plugin = {
version: "3.0.0-beta",
version: "3.0.1-beta",
install
};
export { Vue3Lottie, plugin as default, install };

@@ -1,1 +0,1 @@

(function(u,n){typeof exports=="object"&&typeof module!="undefined"?n(exports,require("vue"),require("@lottiefiles/lottie-player")):typeof define=="function"&&define.amd?define(["exports","vue","@lottiefiles/lottie-player"],n):(u=typeof globalThis!="undefined"?globalThis:u||self,n(u["vue3-lottie"]={},u.Vue,u.LottiePlayer))})(this,function(u,n,h){"use strict";function L(t){if(t&&t.__esModule)return t;var a={__proto__:null,[Symbol.toStringTag]:"Module"};return t&&Object.keys(t).forEach(function(e){if(e!=="default"){var r=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(a,e,r.get?r:{enumerable:!0,get:function(){return t[e]}})}}),a.default=t,Object.freeze(a)}var g=L(h),A="",O=(t,a)=>{const e=t.__vccOpts||t;for(const[r,o]of a)e[r]=o;return e};const b=n.defineComponent({props:{animationData:{type:Object,default:()=>({})},animationLink:{type:String,default:""},loop:{type:[Boolean,Number],default:!0},autoPlay:{type:Boolean,default:!0},width:{type:[Number,String],default:"100%"},height:{type:[Number,String],default:"100%"},speed:{type:Number,default:1},delay:{type:Number,default:0},direction:{type:String,default:"forward"},pauseOnHover:{type:Boolean,default:!1},playOnHover:{type:Boolean,default:!1},backgroundColor:{type:String,default:"transparent"},pauseAnimation:{type:Boolean,default:!1},showControls:{type:Boolean,default:!1}},emits:{onLoad:null,onReady:null,onError:null,onPlay:null,onPause:null,onStop:null,onLoopComplete:null,onComplete:null,onEnterFrame:null},setup(t,{emit:a}){let e=n.ref(null);const r=n.ref("");let o=n.ref(1),v=n.ref(0);const s=l=>document.querySelector(`[data-id="${l}" ]`)!==null,w=async l=>{let i=t.animationData;if(t.animationLink!="")try{i=await(await fetch(t.animationLink)).json()}catch(f){console.error(f);return}e.value.load(i),t.autoPlay||(e.value.seek(0),e.value.pause()),t.playOnHover&&(e.value.seek(0),e.value.pause()),t.delay>0&&(e.value.seek(0),e.value.pause()),setTimeout(()=>{t.direction==="reverse"&&(e.value.seek(d()-1),e.value.setDirection(-1),o.value=-1),t.direction==="normal"&&(e.value.setDirection(1),o.value=1),t.autoPlay&&(t.playOnHover?(e.value.seek(0),e.value.pause()):e.value.play())},t.delay),e.value.setSpeed(t.speed),(t.pauseAnimation||t.playOnHover)&&e.value.pause(),e.value.addEventListener("load",()=>{a("onLoad")}),e.value.addEventListener("error",()=>{a("onError")}),e.value.addEventListener("ready",()=>{a("onReady")}),e.value.addEventListener("play",()=>{t.loop===!0||typeof t.loop=="number"||a("onPlay")}),e.value.addEventListener("pause",()=>{t.loop===!0||typeof t.loop=="number"||a("onPause")}),e.value.addEventListener("stop",()=>{typeof t.loop=="number"||a("onStop")}),e.value.addEventListener("complete",()=>{t.direction==="alternate"?(e.value.pause(),o.value=o.value*-1,e.value.setDirection(o.value),e.value.play(),typeof t.loop=="number"&&(v.value++,v.value<t.loop?a("onLoopComplete"):(v.value=0,e.value.pause(),a("onLoopComplete"),a("onComplete")))):t.loop===!0?(o.value==-1?e.value.seek(d()-1):e.value.stop(),a("onLoopComplete"),t.autoPlay?e.value.play():(e.value.seek(0),e.value.pause())):typeof t.loop=="number"?(v.value++,v.value<t.loop?(e.value.stop(),a("onLoopComplete"),e.value.play()):(v.value=0,e.value.pause(),a("onComplete"))):(e.value.pause(),a("onComplete"))}),e.value.addEventListener("frame",()=>{a("onEnterFrame")})},H=n.computed(()=>{let l=t.width,i=t.height;return typeof t.width=="number"&&(l=`${t.width}px`),typeof t.height=="number"&&(i=`${t.height}px`),{"--lottie-animation-container-width":l,"--lottie-animation-container-height":i,"--lottie-animation-container-background-color":t.backgroundColor}}),_=()=>{e.value&&t.pauseOnHover&&(e.value.pause(),a("onPause")),e.value&&t.playOnHover&&(e.value.play(),a("onPlay"))},k=()=>{e.value&&t.pauseOnHover&&(e.value.play(),a("onPlay")),e.value&&t.playOnHover&&(e.value.pause(),a("onPause"))};n.watch(t,()=>{(t.pauseOnHover||t.playOnHover)&&t.pauseAnimation&&console.error("If you are using pauseAnimation prop for Vue3-Lottie, please remove the props pauseOnHover or playOnHover"),!t.pauseOnHover&&!t.playOnHover&&(e.value&&t.pauseAnimation?(e.value.pause(),a("onPause")):e.value&&!t.pauseAnimation&&(e.value.play(),a("onPlay")))});const C=()=>{e.value&&(e.value.play(),a("onPlay"))},D=()=>{e.value&&(e.value.pause(),a("onPause"))},j=()=>{e.value&&(e.value.stop(),a("onStop"))},M=(l=1)=>{if(l<=0)throw new Error("Speed must be greater than 0");e.value&&e.value.setSpeed(l)},V=l=>{e.value&&(l==="forward"?(e.value.setDirection(1),o.value=1):l==="reverse"&&(e.value.setDirection(-1),o.value=-1))},d=()=>{if(e.value)return e.value.getLottie().totalFrames},$=l=>{for(var i="",f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",p=f.length,m=0;m<l;m++)i+=f.charAt(Math.floor(Math.random()*p));return i},B=l=>{if(t.pauseOnHover&&t.playOnHover)throw new Error("You cannot set pauseOnHover and playOnHover for Vue3-Lottie at the same time.");if(t.animationLink===""&&t.animationData==={})throw new Error("You must provide either animationLink or animationData");const i=setInterval(()=>{s(l)&&(clearInterval(i),document.querySelector(`[data-id="${l}" ]`)&&w())},0)};return n.onMounted(async()=>{r.value=$(20),B(r.value)}),{elementid:r,hoverEnded:k,hoverStarted:_,getCurrentStyle:H,LottiePlayer:g,lottie_player:e,getDuration:d,direction:o,loopCounter:v,setDirection:V,setSpeed:M,stop:j,pause:D,play:C}}}),S=["data-id","controls"];function E(t,a,e,r,o,v){return n.openBlock(),n.createElementBlock("div",null,[n.createElementVNode("lottie-player",{"data-id":t.elementid,ref:"lottie_player",controls:t.$props.showControls,style:n.normalizeStyle(t.getCurrentStyle),class:"lottie-animation-container",onMouseenter:a[0]||(a[0]=(...s)=>t.hoverStarted&&t.hoverStarted(...s)),onMouseleave:a[1]||(a[1]=(...s)=>t.hoverEnded&&t.hoverEnded(...s))},null,44,S)])}var y=O(b,[["render",E]]);function c(t,a){const e=Object.assign({},{name:"Vue3Lottie"},a);t.component(`${e.name}`,y)}const P={version:"3.0.0-beta",install:c};u.Vue3Lottie=y,u.default=P,u.install=c,Object.defineProperty(u,"__esModule",{value:!0}),u[Symbol.toStringTag]="Module"});
(function(u,o){typeof exports=="object"&&typeof module!="undefined"?o(exports,require("vue"),require("@lottiefiles/lottie-player")):typeof define=="function"&&define.amd?define(["exports","vue","@lottiefiles/lottie-player"],o):(u=typeof globalThis!="undefined"?globalThis:u||self,o(u["vue3-lottie"]={},u.Vue,u.LottiePlayer))})(this,function(u,o,m){"use strict";function h(t){if(t&&t.__esModule)return t;var a={__proto__:null,[Symbol.toStringTag]:"Module"};return t&&Object.keys(t).forEach(function(e){if(e!=="default"){var r=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(a,e,r.get?r:{enumerable:!0,get:function(){return t[e]}})}}),a.default=t,Object.freeze(a)}var L=h(m),A="",g=(t,a)=>{const e=t.__vccOpts||t;for(const[r,l]of a)e[r]=l;return e};const O=o.defineComponent({props:{animationData:{type:Object,default:()=>({})},animationLink:{type:String,default:""},loop:{type:[Boolean,Number],default:!0},autoPlay:{type:Boolean,default:!0},width:{type:[Number,String],default:"100%"},height:{type:[Number,String],default:"100%"},speed:{type:Number,default:1},delay:{type:Number,default:0},direction:{type:String,default:"forward"},pauseOnHover:{type:Boolean,default:!1},playOnHover:{type:Boolean,default:!1},backgroundColor:{type:String,default:"transparent"},pauseAnimation:{type:Boolean,default:!1},showControls:{type:Boolean,default:!1}},emits:{onLoad:null,onReady:null,onError:null,onPlay:null,onPause:null,onStop:null,onLoopComplete:null,onComplete:null,onEnterFrame:null},setup(t,{emit:a}){let e=o.ref(null);const r=o.ref("");let l=o.ref(1),v=o.ref(0);const f=n=>document.querySelector(`[data-id="${n}" ]`)!==null,P=async()=>{let n=t.animationData;if(t.animationLink!="")try{n=await(await fetch(t.animationLink)).json()}catch(i){console.error(i);return}e.value.load(n),t.autoPlay||(e.value.seek(0),e.value.pause()),t.playOnHover&&(e.value.seek(0),e.value.pause()),t.delay>0&&(e.value.seek(0),e.value.pause()),setTimeout(()=>{t.direction==="reverse"&&(e.value.seek(d()-1),e.value.setDirection(-1),l.value=-1),t.direction==="normal"&&(e.value.setDirection(1),l.value=1),t.autoPlay&&(t.playOnHover?(e.value.seek(0),e.value.pause()):e.value.play())},t.delay),e.value.setSpeed(t.speed),(t.pauseAnimation||t.playOnHover)&&e.value.pause(),e.value.addEventListener("load",()=>{a("onLoad")}),e.value.addEventListener("error",()=>{a("onError")}),e.value.addEventListener("ready",()=>{a("onReady")}),e.value.addEventListener("play",()=>{t.loop===!0||typeof t.loop=="number"||a("onPlay")}),e.value.addEventListener("pause",()=>{t.loop===!0||typeof t.loop=="number"||a("onPause")}),e.value.addEventListener("stop",()=>{typeof t.loop=="number"||a("onStop")}),e.value.addEventListener("complete",()=>{t.direction==="alternate"?(e.value.pause(),l.value=l.value*-1,e.value.setDirection(l.value),e.value.play(),typeof t.loop=="number"&&(v.value++,v.value<t.loop?a("onLoopComplete"):(v.value=0,e.value.pause(),a("onLoopComplete"),a("onComplete")))):t.loop===!0?(l.value==-1?e.value.seek(d()-1):e.value.stop(),a("onLoopComplete"),t.autoPlay?e.value.play():(e.value.seek(0),e.value.pause())):typeof t.loop=="number"?(v.value++,v.value<t.loop?(e.value.stop(),a("onLoopComplete"),e.value.play()):(v.value=0,e.value.pause(),a("onComplete"))):(e.value.pause(),a("onComplete"))}),e.value.addEventListener("frame",()=>{a("onEnterFrame")})},w=o.computed(()=>{let n=t.width,i=t.height;return typeof t.width=="number"&&(n=`${t.width}px`),typeof t.height=="number"&&(i=`${t.height}px`),{"--lottie-animation-container-width":n,"--lottie-animation-container-height":i,"--lottie-animation-container-background-color":t.backgroundColor}}),H=()=>{e.value&&t.pauseOnHover&&(e.value.pause(),a("onPause")),e.value&&t.playOnHover&&(e.value.play(),a("onPlay"))},_=()=>{e.value&&t.pauseOnHover&&(e.value.play(),a("onPlay")),e.value&&t.playOnHover&&(e.value.pause(),a("onPause"))};o.watch(t,()=>{(t.pauseOnHover||t.playOnHover)&&t.pauseAnimation&&console.error("If you are using pauseAnimation prop for Vue3-Lottie, please remove the props pauseOnHover or playOnHover"),!t.pauseOnHover&&!t.playOnHover&&(e.value&&t.pauseAnimation?(e.value.pause(),a("onPause")):e.value&&!t.pauseAnimation&&(e.value.play(),a("onPlay")))});const k=()=>{e.value&&(e.value.play(),a("onPlay"))},C=()=>{e.value&&(e.value.pause(),a("onPause"))},D=()=>{e.value&&(e.value.stop(),a("onStop"))},j=(n=1)=>{if(n<=0)throw new Error("Speed must be greater than 0");e.value&&e.value.setSpeed(n)},M=n=>{e.value&&(n==="forward"?(e.value.setDirection(1),l.value=1):n==="reverse"&&(e.value.setDirection(-1),l.value=-1))},d=()=>{if(e.value)return e.value.getLottie().totalFrames},V=n=>{for(var i="",s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",B=s.length,p=0;p<n;p++)i+=s.charAt(Math.floor(Math.random()*B));return i},$=n=>{if(t.pauseOnHover&&t.playOnHover)throw new Error("You cannot set pauseOnHover and playOnHover for Vue3-Lottie at the same time.");if(t.animationLink===""&&t.animationData==={})throw new Error("You must provide either animationLink or animationData");const i=setInterval(()=>{f(n)&&(clearInterval(i),document.querySelector(`[data-id="${n}" ]`)&&P())},0)};return o.onMounted(async()=>{r.value=V(20),$(r.value)}),{elementid:r,hoverEnded:_,hoverStarted:H,getCurrentStyle:w,LottiePlayer:L,lottie_player:e,direction:l,loopCounter:v,getDuration:d,setDirection:M,setSpeed:j,stop:D,pause:C,play:k}}}),b=["data-id","controls"];function S(t,a,e,r,l,v){return o.openBlock(),o.createElementBlock("div",null,[o.createElementVNode("lottie-player",{"data-id":t.elementid,ref:"lottie_player",controls:t.$props.showControls,style:o.normalizeStyle(t.getCurrentStyle),class:"lottie-animation-container",onMouseenter:a[0]||(a[0]=(...f)=>t.hoverStarted&&t.hoverStarted(...f)),onMouseleave:a[1]||(a[1]=(...f)=>t.hoverEnded&&t.hoverEnded(...f))},null,44,b)])}var y=g(O,[["render",S]]);function c(t,a){const e=Object.assign({},{name:"Vue3Lottie"},a);t.component(`${e.name}`,y)}const E={version:"3.0.1-beta",install:c};u.Vue3Lottie=y,u.default=E,u.install=c,Object.defineProperty(u,"__esModule",{value:!0}),u[Symbol.toStringTag]="Module"});

@@ -84,5 +84,5 @@ import { PropType } from 'vue';

lottie_player: any;
getDuration: () => any;
direction: import("vue").Ref<number>;
loopCounter: import("vue").Ref<number>;
getDuration: () => any;
setDirection: (direction_: 'forward' | 'reverse') => void;

@@ -89,0 +89,0 @@ setSpeed: (speed?: number) => void;

{
"name": "vue3-lottie",
"version": "3.0.0-beta",
"version": "3.0.1-beta",
"license": "MIT",

@@ -5,0 +5,0 @@ "author": "Sanjay Soundarajan <info@sanjaysoundarajan.dev> (https://sanjaysoundarajan.dev)",

@@ -5,3 +5,3 @@ # Vue 3 Lottie

`vue3-lottie` was created to help developers add Lottie animations to their Vue 3 applications. In my search for a simple way to add Lottie animations to my Vue application I found a suprising lack of maintained solutions. `vue3-lottie` is a vue wrapper around the `lottie-web` library with a few additional features.
`vue3-lottie` was created to help developers add Lottie animations to their Vue 3 applications. In my search for a simple way to add Lottie animations to my Vue application I found a suprising lack of maintained solutions. `vue3-lottie` is a vue wrapper around the `lottie-player` library with a few additional features.

@@ -14,3 +14,3 @@ # Demos

If you are using version 1.x of `vue3-lottie` you should upgrade to version 2.x. You can do this by running the [Installation](#installation) command below. This adds TS support for the component. There are some new imports so take a look at the [new documentation](https://vue3-lottie.vercel.app/guide.html#usage).
If you are using version 1.x or v2.x of `vue3-lottie` you should upgrade to version 3.x. You can do this by running the [Installation](#installation) command below. There are some new imports so take a look at the [new documentation](https://vue3-lottie.vercel.app/guide.html#usage).

@@ -31,4 +31,18 @@ # Installation

# Usage
# Installation and Usage
## Vue 3
- You can install `vue3-lottie` over `yarn` or `npm`. `lottie-web` is a dependency of `vue3-lottie` and should be automatically installed when you install `vue3-lottie`.
```bash
yarn add vue3-lottie@latest
```
```bash
npm install vue3-lottie@latest --save
```
- Register the component in your Vue 3 application.
The most common use case is to register the component globally.

@@ -40,2 +54,3 @@

import Vue3Lottie from 'vue3-lottie'
import 'vue3-lottie/dist/style.css'

@@ -46,20 +61,7 @@

Alternatively you can also import the component locally.
Alternatively you can import the component locally.
```js
import { Vue3Lottie } from 'vue3-lottie'
import 'vue3-lottie/dist/style.css'
export default {
components: {
Vue3Lottie,
},
}
```
You can then use the component in your template
```vue
<template>
<Vue3Lottie :animationData="DogJSON" :height="200" :width="200" />
<Vue3Lottie :animationData="AstronautJSON" :height="200" :width="200" />
</template>

@@ -71,3 +73,3 @@

import DogJSON from './lotties/dog.json'
const AstronautJSON = require('./astronaut.json')

@@ -80,3 +82,3 @@ export default {

return {
DogJSON,
AstronautJSON,
}

@@ -88,2 +90,32 @@ },

## Nuxt 3
- You can install `vue3-lottie` over `yarn` or `npm`. `lottie-web` is a dependency of `vue3-lottie` and should be automatically installed when you install `vue3-lottie`.
```bash
yarn add vue3-lottie@latest
```
```bash
npm install vue3-lottie@latest --save
```
- Create a folder called **`plugins`** at the root of your project.
- Create a file named **`vue3-lottie.client.js`** inside the _plugins_ directory.
- Add the following code to the **`vue3-lottie.client.js`** file.
```js
import { Vue3Lottie } from 'vue3-lottie'
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(Vue3Lottie)
})
```
- Import the css file required by the component into your **`app.vue`** file.
```js
import 'vue3-lottie/dist/style.css'
```
# Props and options

@@ -93,18 +125,18 @@

| Prop | Type | Default Value | Description |
| ---------------- | ----------------- | ------------- | ---------------------------------------------------------------------------------------- |
| animationData | Object | {} | The lottie animation data provided as a JSON object |
| animationLink | String | '' | A URL link to the Lottie animation data (eg: `Lottie Animation URL` on lottiefiles.com) |
| width | Number or String | "100%" | Width of the lottie animation container (Numbers correspond to pixel values) |
| height | Number or String | "100%" | Height of the lottie animation container (Numbers correspond to pixel values) |
| speed | Number | "1" | Speed of the lottie animation |
| direction | String | "forward" | Animation play direction |
| loop | Number or Boolean | true | The number of instances that the lottie animation should run (true is infinite) |
| autoPlay | Boolean | true | Start animation on component load |
| delay | Number | 0 | Delay the animation play state by some milliseconds |
| pauseAnimation | Boolean | false | Prop to pass reactive variables so that you can control animation pause and play |
| pauseOnHover | Boolean | false | Whether to pause the animation on hover |
| playOnHover | Boolean | false | Whether to play the animation when you hover |
| backgroundColor | String | transparent | Background color of the container |
| rendererSettings | Object | {} | Options for if you want to use an existing canvas to draw (can be ignored on most cases) |
| Prop | Type | Default Value | Description |
| --------------- | ----------------- | ------------- | --------------------------------------------------------------------------------------- |
| animationData | Object | {} | The lottie animation data provided as a JSON object |
| animationLink | String | '' | A URL link to the Lottie animation data (eg: `Lottie Animation URL` on lottiefiles.com) |
| width | Number or String | "100%" | Width of the lottie animation container (Numbers correspond to pixel values) |
| height | Number or String | "100%" | Height of the lottie animation container (Numbers correspond to pixel values) |
| speed | Number | "1" | Speed of the lottie animation |
| direction | String | "forward" | Animation play direction |
| loop | Number or Boolean | true | The number of instances that the lottie animation should run (true is infinite) |
| autoPlay | Boolean | true | Start animation on component load |
| delay | Number | 0 | Delay the animation play state by some milliseconds |
| pauseAnimation | Boolean | false | Prop to pass reactive variables so that you can control animation pause and play |
| pauseOnHover | Boolean | false | Whether to pause the animation on hover |
| playOnHover | Boolean | false | Whether to play the animation when you hover |
| backgroundColor | String | transparent | Background color of the container |
| showControls | Boolean | false | Show the lottie-player controls |

@@ -115,2 +147,14 @@ # Events

- onLoad
- This event is fired when your animation data is loaded.
- onReady
- This event is fired when your animation data is loaded and player is ready.
- onError
- This event is fired when an animation source cannot be parsed, fails to load or has format errors.
- onPlay
- This event is fired when the animation starts playing.
- onPause
- This event is fired when the animation is paused.
- onStop
- This event is fired when the animation is stopped.
- onComplete

@@ -122,4 +166,2 @@ - If your animation has a finite amount of loops you can use this event to know when the animation has completed.

- This event is fired every frame of the animation. There will be 60 events fired per second if your lottie animation runs at 60fps.
- onSegmentStart
- This event is fired when the animation enters a segment.

@@ -142,12 +184,4 @@ # Methods

- You can call this method to change the direction of your animation.
- getDuration(inFrames)
- You can call this method to get the duration of your animation.
- goToAndStop(frameNumber, isFrames)
- You can call this method to go to a specific frame of your animation. The animation will be stopped at the end of this call.
- goToAndPlay(frameNumber, isFrames)
- You can call this method to go to a specific frame of your animation. The animation will be played from this frame.
- playSegments(segments, forceFlag)
- You can call this method to play a specific segment of your animation.
- setSubFrame(subFrame)
- You can call this method to set the subframe value.
- getDuration()
- You can call this method to get the total number of frames of your animation.

@@ -154,0 +188,0 @@ # Credits

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc