mirror of https://github.com/luileito/jsketch.git
1 line
1.3 KiB
JavaScript
1 line
1.3 KiB
JavaScript
!function(a){function b(a){function b(b,c,d){var e=c[d],f=c[d+1];if(0===d||e.strokeId!==f.strokeId){if(b.data.firstPointSize){var g=d>0?f:e;b.beginFill(b.data.strokeStyle).fillCircle(g.x,g.y,b.data.firstPointSize).endFill()}d>0&&a.trigger("animationstep"),b.closePath().beginPath()}e.strokeId===f.strokeId&&b.line(e.x,e.y,f.x,f.y).stroke()}function d(a){return a instanceof Array?{x:a[0],y:a[1],time:a[2],strokeId:a[4]}:a}for(var e=dataBind(a.elem)[c],f=e.sketch,g=e.strokes,h=(e.options.events,e.options.graphics),i=[],j=0;j<g.length;j++)for(var k=g[j],l=0;l<k.length;l++){var m=d(k[l]);m.strokeId||(m.strokeId=j),i.push(m)}a.trigger("animationstart");var n,o=0;f.lineStyle(h.strokeStyle,h.lineWidth),function p(){n=requestAnimationFrame(p);try{b(f,i,o,h)}catch(c){console.error(c),cancelAnimationFrame(n)}++o===i.length-1&&(cancelAnimationFrame(n),a.trigger("animationend"))}(),this.cancel=function(){return cancelAnimationFrame(n),this}}var c="sketchable";Sketchable.prototype.plugins.animate=function(a){for(var d={clear:function(a,b){b.animate&&b.animate.cancel()},destroy:function(a,b){b.animate&&b.animate.cancel()}},e="clear destroy".split(" "),f=0;f<e.length;f++){var g=e[f];a.decorate(g,d[g],"animate")}deepExtend(a,{animate:{strokes:function(){var d=dataBind(a.elem)[c];return d.animate=new b(a),a}}})}}(this); |