mirror of https://github.com/luileito/jsketch.git
1 line
1.6 KiB
JavaScript
1 line
1.6 KiB
JavaScript
!function(a){function b(a){function b(a,b,c,d){var e=b[c],f=b[c+1];if(a.data.firstPointSize&&(1===c||e.strokeId!==f.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(),e.strokeId===f.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,l=0;l<g.length;l++){for(var m=[],n=g[l],o=0;o<n.length;o++){var p=d(n[o]);p.strokeId=l,m.push(p),k++}j.push(m)}"function"==typeof h.animationstart&&h.animationstart(a,e);for(var q={},r=1,l=0;l<j.length;l++)!function(c){var d=j[c],g=0;!function l(){q[c]=requestAnimationFrame(l);try{b(f,d,g,i)}catch(j){console.error(j),cancelAnimationFrame(q[c])}++g===d.length-1&&cancelAnimationFrame(q[c]),++r===k-1&&"function"==typeof h.animationend&&h.animationend(a,e)}()}(l);this.cancel=function(){for(var a in q)cancelAnimationFrame(q[a]);return 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); |