Socket
Socket
Sign inDemoInstall

vue3-lottie

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue3-lottie - npm Package Compare versions

Comparing version 2.2.4 to 2.2.5

3

dist/vue3-lottie.es.js

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

if (lottieAnimation) {
console.log(lottieAnimation);
lottieAnimation.stop();

@@ -341,5 +340,5 @@ }

const plugin = {
version: "2.2.4",
version: "2.2.5",
install
};
export { Vue3Lottie, plugin as default, install };

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

(function(r,i){typeof exports=="object"&&typeof module!="undefined"?i(exports,require("vue"),require("lottie-web")):typeof define=="function"&&define.amd?define(["exports","vue","lottie-web"],i):(r=typeof globalThis!="undefined"?globalThis:r||self,i(r["vue3-lottie"]={},r.Vue,r.Lottie))})(this,function(r,i,h){"use strict";function p(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var g=p(h),F="",S=(t,o)=>{const e=t.__vccOpts||t;for(const[s,d]of o)e[s]=d;return e};const L=i.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}},emits:{onComplete:null,onLoopComplete:null,onEnterFrame:null,onSegmentStart:null,onAnimationLoaded:null},setup(t,{emit:o}){let e=i.ref(null);const s=i.ref("");let d=1;const v=n=>document.querySelector(`[data-id="${n}" ]`)!==null,f=async n=>{let a=t.autoPlay;t.playOnHover&&(a=!1);let l={};if(t.animationData!=={}&&(l=JSON.parse(JSON.stringify(t.animationData))),t.animationLink!="")try{l=await(await fetch(t.animationLink)).json()}catch(c){console.error(c);return}let u=t.loop;typeof u=="number"&&u>0&&(u=u-1),t.delay>0&&(a=!1),e=g.default.loadAnimation({container:n,renderer:"svg",loop:u,autoplay:a,animationData:l}),setTimeout(()=>{a=t.autoPlay,t.playOnHover?e.pause():a?e.play():e.pause(),o("onAnimationLoaded")},t.delay),e.setSpeed(t.speed),t.direction==="reverse"&&e.setDirection(-1),t.direction==="normal"&&e.setDirection(1),(t.pauseAnimation||t.playOnHover)&&e.pause(),e.addEventListener("loopComplete",()=>{t.direction==="alternate"&&(e.stop(),d=d*-1,e.setDirection(d),e.play()),o("onLoopComplete")}),e.addEventListener("complete",()=>{o("onComplete")}),e.addEventListener("enterFrame",()=>{o("onEnterFrame")}),e.addEventListener("segmentStart",()=>{o("onSegmentStart")})},H=i.computed(()=>{let n=t.width,a=t.height;return typeof t.width=="number"&&(n=`${t.width}px`),typeof t.height=="number"&&(a=`${t.height}px`),{"--lottie-animation-container-width":n,"--lottie-animation-container-height":a,"--lottie-animation-container-background-color":t.backgroundColor}}),A=()=>{e&&t.pauseOnHover&&e.pause(),e&&t.playOnHover&&e.play()},D=()=>{e&&t.pauseOnHover&&e.play(),e&&t.playOnHover&&e.pause()};i.watch(()=>t.pauseAnimation,()=>{if((t.pauseOnHover||t.playOnHover)&&t.pauseAnimation){console.error("If you are using pauseAnimation prop for Vue3-Lottie, please remove the props pauseOnHover and playOnHover");return}e&&(t.pauseAnimation?e.pause():e.play())});const E=()=>{e&&e.play()},k=()=>{e&&e.pause()},_=()=>{e&&(console.log(e),e.stop())},C=()=>{e&&e.destroy()},j=(n=1)=>{if(n<=0)throw new Error("Speed must be greater than 0");e&&e.setSpeed(n)},T=n=>{e&&(n==="forward"?e.setDirection(1):n==="reverse"&&e.setDirection(-1))},V=(n,a=!0)=>{e&&e.goToAndStop(n,a)},$=(n,a=!0)=>{e&&e.goToAndPlay(n,a)},B=(n,a=!1)=>{e&&e.playSegments(n,a)},M=(n=!0)=>{e&&e.setSubframe(n)},N=(n=!0)=>{if(e)return e.getDuration(n)},P=n=>{for(var a="",l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",u=l.length,c=0;c<n;c++)a+=l.charAt(Math.floor(Math.random()*u));return a},q=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 a=setInterval(()=>{if(v(n)){clearInterval(a);const l=document.querySelector(`[data-id="${n}" ]`);l&&f(l)}},0)};return i.onMounted(async()=>{s.value=P(20),q(s.value)}),{elementid:s,hoverEnded:D,hoverStarted:A,getCurrentStyle:H,play:E,pause:k,stop:_,destroy:C,setSpeed:j,setDirection:T,goToAndStop:V,goToAndPlay:$,playSegments:B,setSubFrame:M,getDuration:N}}}),O=["data-id"];function b(t,o,e,s,d,v){return i.openBlock(),i.createElementBlock("div",{"data-id":t.elementid,class:"lottie-animation-container",style:i.normalizeStyle(t.getCurrentStyle),onMouseenter:o[0]||(o[0]=(...f)=>t.hoverStarted&&t.hoverStarted(...f)),onMouseleave:o[1]||(o[1]=(...f)=>t.hoverEnded&&t.hoverEnded(...f))},null,44,O)}var m=S(L,[["render",b]]);function y(t,o){const e=Object.assign({},{name:"Vue3Lottie"},o);t.component(`${e.name}`,m)}const w={version:"2.2.4",install:y};r.Vue3Lottie=m,r.default=w,r.install=y,Object.defineProperty(r,"__esModule",{value:!0}),r[Symbol.toStringTag]="Module"});
(function(r,i){typeof exports=="object"&&typeof module!="undefined"?i(exports,require("vue"),require("lottie-web")):typeof define=="function"&&define.amd?define(["exports","vue","lottie-web"],i):(r=typeof globalThis!="undefined"?globalThis:r||self,i(r["vue3-lottie"]={},r.Vue,r.Lottie))})(this,function(r,i,h){"use strict";function p(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var g=p(h),F="",S=(t,o)=>{const e=t.__vccOpts||t;for(const[s,d]of o)e[s]=d;return e};const L=i.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}},emits:{onComplete:null,onLoopComplete:null,onEnterFrame:null,onSegmentStart:null,onAnimationLoaded:null},setup(t,{emit:o}){let e=i.ref(null);const s=i.ref("");let d=1;const v=n=>document.querySelector(`[data-id="${n}" ]`)!==null,f=async n=>{let a=t.autoPlay;t.playOnHover&&(a=!1);let l={};if(t.animationData!=={}&&(l=JSON.parse(JSON.stringify(t.animationData))),t.animationLink!="")try{l=await(await fetch(t.animationLink)).json()}catch(c){console.error(c);return}let u=t.loop;typeof u=="number"&&u>0&&(u=u-1),t.delay>0&&(a=!1),e=g.default.loadAnimation({container:n,renderer:"svg",loop:u,autoplay:a,animationData:l}),setTimeout(()=>{a=t.autoPlay,t.playOnHover?e.pause():a?e.play():e.pause(),o("onAnimationLoaded")},t.delay),e.setSpeed(t.speed),t.direction==="reverse"&&e.setDirection(-1),t.direction==="normal"&&e.setDirection(1),(t.pauseAnimation||t.playOnHover)&&e.pause(),e.addEventListener("loopComplete",()=>{t.direction==="alternate"&&(e.stop(),d=d*-1,e.setDirection(d),e.play()),o("onLoopComplete")}),e.addEventListener("complete",()=>{o("onComplete")}),e.addEventListener("enterFrame",()=>{o("onEnterFrame")}),e.addEventListener("segmentStart",()=>{o("onSegmentStart")})},H=i.computed(()=>{let n=t.width,a=t.height;return typeof t.width=="number"&&(n=`${t.width}px`),typeof t.height=="number"&&(a=`${t.height}px`),{"--lottie-animation-container-width":n,"--lottie-animation-container-height":a,"--lottie-animation-container-background-color":t.backgroundColor}}),A=()=>{e&&t.pauseOnHover&&e.pause(),e&&t.playOnHover&&e.play()},D=()=>{e&&t.pauseOnHover&&e.play(),e&&t.playOnHover&&e.pause()};i.watch(()=>t.pauseAnimation,()=>{if((t.pauseOnHover||t.playOnHover)&&t.pauseAnimation){console.error("If you are using pauseAnimation prop for Vue3-Lottie, please remove the props pauseOnHover and playOnHover");return}e&&(t.pauseAnimation?e.pause():e.play())});const E=()=>{e&&e.play()},k=()=>{e&&e.pause()},_=()=>{e&&e.stop()},C=()=>{e&&e.destroy()},j=(n=1)=>{if(n<=0)throw new Error("Speed must be greater than 0");e&&e.setSpeed(n)},T=n=>{e&&(n==="forward"?e.setDirection(1):n==="reverse"&&e.setDirection(-1))},V=(n,a=!0)=>{e&&e.goToAndStop(n,a)},$=(n,a=!0)=>{e&&e.goToAndPlay(n,a)},B=(n,a=!1)=>{e&&e.playSegments(n,a)},M=(n=!0)=>{e&&e.setSubframe(n)},N=(n=!0)=>{if(e)return e.getDuration(n)},P=n=>{for(var a="",l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",u=l.length,c=0;c<n;c++)a+=l.charAt(Math.floor(Math.random()*u));return a},q=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 a=setInterval(()=>{if(v(n)){clearInterval(a);const l=document.querySelector(`[data-id="${n}" ]`);l&&f(l)}},0)};return i.onMounted(async()=>{s.value=P(20),q(s.value)}),{elementid:s,hoverEnded:D,hoverStarted:A,getCurrentStyle:H,play:E,pause:k,stop:_,destroy:C,setSpeed:j,setDirection:T,goToAndStop:V,goToAndPlay:$,playSegments:B,setSubFrame:M,getDuration:N}}}),O=["data-id"];function b(t,o,e,s,d,v){return i.openBlock(),i.createElementBlock("div",{"data-id":t.elementid,class:"lottie-animation-container",style:i.normalizeStyle(t.getCurrentStyle),onMouseenter:o[0]||(o[0]=(...f)=>t.hoverStarted&&t.hoverStarted(...f)),onMouseleave:o[1]||(o[1]=(...f)=>t.hoverEnded&&t.hoverEnded(...f))},null,44,O)}var m=S(L,[["render",b]]);function y(t,o){const e=Object.assign({},{name:"Vue3Lottie"},o);t.component(`${e.name}`,m)}const w={version:"2.2.5",install:y};r.Vue3Lottie=m,r.default=w,r.install=y,Object.defineProperty(r,"__esModule",{value:!0}),r[Symbol.toStringTag]="Module"});
{
"name": "vue3-lottie",
"version": "2.2.4",
"version": "2.2.5",
"license": "MIT",

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

"@vitejs/plugin-vue": "2.3.3",
"typescript": "4.7.2",
"typescript": "4.7.3",
"vite": "2.9.9",

@@ -62,4 +62,3 @@ "vue": "3.2.36",

"prettier": "npx prettier --write ."
},
"readme": "# Vue 3 Lottie\r\n\r\n[![npm](https://img.shields.io/npm/v/vue3-lottie)](https://www.npmjs.com/package/vue3-lottie) [![Downloads](https://img.shields.io/npm/dt/vue3-lottie)](https://www.npmjs.com/package/vue3-lottie) [![Stars](https://img.shields.io/github/stars/megasanjay/vue3-lottie.svg?style=flat-square)](https://github.com/megasanjay/vue3-lottie/stargazers) [![License](https://img.shields.io/npm/l/vue3-lottie)](https://github.com/megasanjay/vue3-lottie/blob/main/LICENSE) [![GitHub issues](https://img.shields.io/github/issues/megasanjay/vue3-lottie)](https://github.com/megasanjay/vue3-lottie/issues)\r\n\r\n`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.\r\n\r\n# Demos\r\n\r\nView the live demos here: [https://vue3-lottie.vercel.app](https://vue3-lottie.vercel.app)\r\n\r\n# Upgrade to v2.x\r\n\r\nIf you are using version 1.x of `vue3-lottie` you should upgrade to version 2.x. You can do this by running the [Installation and Usage](#installation-and-usage) 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).\r\n\r\n# Installation and Usage\r\n\r\n## Vue 3\r\n\r\n- 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`.\r\n\r\nIf you are using npm:\r\n\r\n```shell\r\nnpm install vue3-lottie@latest --save\r\n```\r\n\r\nIf you are using yarn:\r\n\r\n```shell\r\nyarn add vue3-lottie@latest\r\n```\r\n\r\n- Register the component in your Vue 3 application.\r\n\r\nThe most common use case is to register the component globally.\r\n\r\n```js\r\n// main.js\r\nimport { createApp } from 'vue'\r\nimport Vue3Lottie from 'vue3-lottie'\r\nimport 'vue3-lottie/dist/style.css'\r\n\r\ncreateApp(App).use(Vue3Lottie).mount('#app')\r\n```\r\n\r\nTo define global components for [Volar type-checking](https://github.com/johnsoncodehk/volar/tree/master/extensions/vscode-vue-language-features#usage) you will need to add:\r\n\r\n```ts\r\n// components.d.ts\r\ndeclare module '@vue/runtime-core' {\r\n export interface GlobalComponents {\r\n LottieAnimation: typeof import('vue3-lottie')['Vue3Lottie']\r\n }\r\n}\r\nexport {}\r\n```\r\n\r\nIf needed rename component to use:\r\n\r\n```ts\r\napp.use(Vue3Lottie, { name: 'LottieAnimation' }) // use in template <LottieAnimation />\r\n```\r\n\r\n- `name` string (default: 'Vue3Lottie') - set custom component name\r\n\r\nAlternatively you can also import the component locally.\r\n\r\n```js\r\nimport { Vue3Lottie } from 'vue3-lottie'\r\nimport 'vue3-lottie/dist/style.css'\r\n\r\nexport default {\r\n components: {\r\n Vue3Lottie,\r\n },\r\n}\r\n```\r\n\r\nYou can then use the component in your template\r\n\r\n```vue\r\n<template>\r\n <Vue3Lottie :animationData=\"AstronautJSON\" :height=\"200\" :width=\"200\" />\r\n</template>\r\n\r\n<script>\r\nimport { Vue3Lottie } from 'vue3-lottie'\r\nimport 'vue3-lottie/dist/style.css'\r\n\r\nimport AstronautJSON from './astronaut.json'\r\n\r\nexport default {\r\n components: {\r\n Vue3Lottie,\r\n },\r\n data() {\r\n return {\r\n AstronautJSON,\r\n }\r\n },\r\n}\r\n</script>\r\n```\r\n\r\n## Nuxt 3\r\n\r\nThis is still experimental. Will be updated soon.\r\n\r\n- 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`.\r\n\r\nIf you are using npm:\r\n\r\n```shell\r\nnpm install vue3-lottie@latest --save\r\n```\r\n\r\nIf you are using yarn:\r\n\r\n```shell\r\nyarn add vue3-lottie@latest\r\n```\r\n\r\n- Create a folder called **`plugins`** at the root of your project.\r\n- Create a file named **`vue3-lottie.client.js`** inside the _plugins_ directory.\r\n- Add the following code to the **`vue3-lottie.client.js`** file.\r\n\r\n```js\r\nimport { Vue3Lottie } from 'vue3-lottie'\r\n\r\nexport default defineNuxtPlugin((nuxtApp) => {\r\n nuxtApp.vueApp.use(Vue3Lottie)\r\n})\r\n```\r\n\r\n- Import the css file required by the component into your **`app.vue`** file.\r\n\r\n```js\r\nimport 'vue3-lottie/dist/style.css'\r\n```\r\n\r\n# Props and options\r\n\r\nMore detailed explanations are provided in the [documentation](https://vue3-lottie.vercel.app/guide.html).\r\n\r\n| Prop | Type | Default Value | Description |\r\n| ---------------- | ----------------- | ------------- | ---------------------------------------------------------------------------------------- |\r\n| animationData | Object | {} | The lottie animation data provided as a JSON object |\r\n| animationLink | String | '' | A URL link to the Lottie animation data (eg: `Lottie Animation URL` on lottiefiles.com) |\r\n| width | Number or String | \"100%\" | Width of the lottie animation container (Numbers correspond to pixel values) |\r\n| height | Number or String | \"100%\" | Height of the lottie animation container (Numbers correspond to pixel values) |\r\n| speed | Number | \"1\" | Speed of the lottie animation |\r\n| direction | String | \"forward\" | Animation play direction |\r\n| loop | Number or Boolean | true | The number of instances that the lottie animation should run (true is infinite) |\r\n| autoPlay | Boolean | true | Start animation on component load |\r\n| delay | Number | 0 | Delay the animation play state by some milliseconds |\r\n| pauseAnimation | Boolean | false | Prop to pass reactive variables so that you can control animation pause and play |\r\n| pauseOnHover | Boolean | false | Whether to pause the animation on hover |\r\n| playOnHover | Boolean | false | Whether to play the animation when you hover |\r\n| backgroundColor | String | transparent | Background color of the container |\r\n| rendererSettings | Object | {} | Options for if you want to use an existing canvas to draw (can be ignored on most cases) |\r\n\r\n# Events\r\n\r\nA few events are emitted from the component. Look at the [Demos](#Demos) for examples.\r\n\r\n- onComplete\r\n - If your animation has a finite amount of loops you can use this event to know when the animation has completed.\r\n- onLoopComplete\r\n - If your animation has a finite amount of loops you can use this event to know when the animation has completed a loop.\r\n- onEnterFrame\r\n - This event is fired every frame of the animation. There will be 60 events fired per second if your lottie animation runs at 60fps.\r\n- onSegmentStart\r\n - This event is fired when the animation enters a segment.\r\n- onAnimationLoaded\r\n - This event is fired when the animation has loaded. This should let you know when you can start referencing the methods for the component.\r\n\r\n# Methods\r\n\r\nYou can control the animation with the following methods. These methods can be called by assigning a `ref` value to the `vue3-lottie` component. Look at the [Demos](#Demos) for examples.\r\n\r\n- play\r\n - Plays the animation\r\n- pause\r\n - Pauses the animation\r\n- stop\r\n - Stops the animation. This will also reset the animation to the first frame. Look at the demo for some examples.\r\n- destroy\r\n - You can call this method to destroy the animation. It will remove the animation from the DOM.\r\n- setSpeed(speed)\r\n - You can call this method to change the speed of your animation.\r\n- setDirection(direction)\r\n - You can call this method to change the direction of your animation.\r\n- getDuration(inFrames)\r\n - You can call this method to get the duration of your animation.\r\n- goToAndStop(frameNumber, isFrames)\r\n - 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.\r\n- goToAndPlay(frameNumber, isFrames)\r\n - You can call this method to go to a specific frame of your animation. The animation will be played from this frame.\r\n- playSegments(segments, forceFlag)\r\n - You can call this method to play a specific segment of your animation.\r\n- setSubFrame(subFrame)\r\n - You can call this method to set the subframe value.\r\n\r\n# Credits\r\n\r\nA big thank you goes to [@reslear](https://github.com/reslear) for adding Typescript support to this library. Go check out his profile and give him a follow!\r\n\r\n- [@DamianGlowala](https://github.com/DamianGlowala) - PR [#29](https://github.com/megasanjay/vue3-lottie/pull/29) - Fix `watch` function\r\n\r\n![forthebadge](https://forthebadge.com/images/badges/made-with-vue.svg) ![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)\r\n"
}
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc