UNPKG

vue-svga

Version:
2 lines (1 loc) 4.13 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@babel/runtime/regenerator"),require("svga.lite")):"function"==typeof define&&define.amd?define(["exports","@babel/runtime/regenerator","svga.lite"],t):t((e=e||self).svga={},e._regeneratorRuntime,e.svga_lite)}(this,(function(e,t,n){"use strict";function r(e,t,n,r,a,o,s){try{var i=e[o](s),u=i.value}catch(e){return void n(e)}i.done?t(u):Promise.resolve(u).then(r,a)}function a(e){return function(){var t=this,n=arguments;return new Promise((function(a,o){var s=e.apply(t,n);function i(e){r(s,a,o,i,u,"next",e)}function u(e){r(s,a,o,i,u,"throw",e)}i(void 0)}))}}t=t&&t.hasOwnProperty("default")?t.default:t;var o=new n.Downloader;var s=function(e,t,n,r,a,o,s,i,u,c){"boolean"!=typeof s&&(u=i,i=s,s=!1);var d="function"==typeof n?n.options:n;let l;if(e&&e.render&&(d.render=e.render,d.staticRenderFns=e.staticRenderFns,d._compiled=!0,a&&(d.functional=!0)),r&&(d._scopeId=r),o?(l=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),t&&t.call(this,u(e)),e&&e._registeredComponents&&e._registeredComponents.add(o)},d._ssrRegister=l):t&&(l=s?function(e){t.call(this,c(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,i(e))}),l)if(d.functional){var e=d.render;d.render=function(t,n){return l.call(n),e(t,n)}}else{var e=d.beforeCreate;d.beforeCreate=e?[].concat(e,l):[l]}return n}({render:function(){var e=this.$createElement;return(this._self._c||e)("canvas")},staticRenderFns:[]},void 0,{name:"svga",props:{src:{type:String,required:!0},options:{type:Object,default:function(){return{}}}},data:function(){return{parser:null,player:null,svgaData:null,isMount:!1,canPlay:!1,needPlay:!1,parseEnd:!1,canMount:!1}},mounted:function(){var e=this;return a(t.mark((function r(){var a,o,s,i,u,c,d,l,p,f,v,h,y,m,_,g;return t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=e.player=new n.Player(e.$el),o=e.options,s=o.loop,i=void 0===s?0:s,u=o.fillMode,c=void 0===u?"forwards":u,d=o.playMode,l=void 0===d?"forwards":d,p=o.startFrame,f=void 0===p?0:p,v=o.endFrame,h=void 0===v?0:v,y=o.autoPlay,m=void 0===y||y,_=o.autoMount,g=void 0===_||_,a.set({loop:i,fillMode:c,playMode:l,startFrame:f,endFrame:h}),t.next=5,e.parseSvgaData(e.src);case 5:if(e.svgaData=t.sent,e.$emit("parsed"),e.parseEnd=!0,e.needMount&&e.mount(),a.$on("start",(function(){return e.$emit("start")})).$on("pause",(function(){return e.$emit("pause")})).$on("stop",(function(){return e.$emit("stop")})).$on("end",(function(){return e.$emit("end")})).$on("clear",(function(){return e.$emit("clear")})).$on("process",(function(){return e.$emit("process",a.progress)})),!g){t.next=17;break}return t.next=13,e.mount(m);case 13:e.canPlay=!0,e.needPlay&&e.start(),t.next=18;break;case 17:m&&e.start();case 18:case"end":return t.stop()}}),r)})))()},methods:{start:function(){this.player&&(this.canPlay?this.player.start():this.needPlay=!0)},pause:function(){this.player&&this.player.pause()},stop:function(){this.player&&this.player.stop()},clear:function(){this.player&&(this.player.clear(),this.player=this.svgaData=null)},mount:function(e){var n=this;return a(t.mark((function r(){var a;return t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!n.parseEnd){t.next=8;break}return t.next=3,n.player.mount(n.svgaData);case 3:a=t.sent,n.canPlay=n.isMount=!0,(n.needPlay||e)&&n.player.start(),t.next=9;break;case 8:n.needMount=!0;case 9:return t.abrupt("return",a);case 10:case"end":return t.stop()}}),r)})))()},parseSvgaData:function(e){var r=this;return a(t.mark((function a(){var s,i;return t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return s=r.parser=new n.Parser,t.next=3,o.get(e);case 3:return i=t.sent,t.next=6,s.do(i);case 6:return t.abrupt("return",t.sent);case 7:case"end":return t.stop()}}),a)})))()}},beforeDestroy:function(){this.clear()}},void 0,!1,void 0,!1,void 0,void 0,void 0);var i={install:function(e){e.component(s.name,s)}};e.default=i,e.svga=s,Object.defineProperty(e,"__esModule",{value:!0})}));