jsketch/dist/sketchable.animate.min.js

1 line
1.5 KiB
JavaScript

!function(a){function b(a){function b(a,b,c,d){var e=b[c-1],f=b[c];if(a.data.firstPointSize&&(1===c||f.strokeId!==e.strokeId)){var g=c>1?f:e;a.beginFill(a.data.strokeStyle).fillCircle(g.x,g.y,a.data.firstPointSize)}a.lineStyle(d.strokeStyle,d.lineWidth).beginPath(),f.strokeId===e.strokeId&&a.line(e.x,e.y,f.x,f.y).stroke(),a.closePath()}function d(a){return a instanceof Array?{x:a[0],y:a[1],t:a[2]}:a}for(var e=dataBind(a.elem)[c],f=e.sketch,g=e.strokes,h=e.options.events,i=e.options.graphics,j=[],k=0;k<g.length;k++)for(var l=g[k],m=0;m<l.length;m++){var n=d(l[m]);n.strokeId=k,j.push(n)}var o,p=1,q=j.length-1;"function"==typeof h.animationstart&&h.animationstart(a.elem,e),function r(){o=requestAnimationFrame(r);try{b(f,j,p,i),p++}catch(c){console.error(c),cancelAnimationFrame(o)}p==q&&(cancelAnimationFrame(o),"function"==typeof h.animationend&&h.animationend(a.elem,e))}(),this.cancel=function(){return cancelAnimationFrame(o),this}}var c="sketchable";Sketchable.prototype.plugins.animate=function(a){function d(b){if(!e.options["_bound.animate$"+b])if(e.options["_bound.animate$"+b]=!0,e.options.events&&"function"==typeof e.options.events[b]){var c=e.options.events[b];e.options.events[b]=function(){c.apply(a,arguments),f[b].apply(a,arguments)}}else e.options.events[b]=f[b]}for(var e=a.config(),f={clear:function(a,b){b.animate&&b.animate.cancel()},destroy:function(a,b){b.animate&&b.animate.cancel()}},g="clear destroy".split(" "),h=0;h<g.length;h++)d(g[h]);deepExtend(a,{animate:{strokes:function(){var d=dataBind(a.elem)[c];return d.animate=new b(a),a}}})}}(this);