/*! jSketch drawing lib (all in one) | v2.0.1 | 2019-09-03 */ !function(a){function b(a,b){if(!a)throw new Error("Sketchable requires a DOM element or selector.");return"string"==typeof a&&(a=document.querySelector(a)),this.setContext(a),this.stageWidth=a.offsetWidth,this.stageHeight=a.offsetHeight,this.data=b,this.callStack=[],this.setDefaults()}b.prototype={setContext:function(a){if(!a)throw new Error("No canvas element specified.");return this.canvas=a,this.context=a.getContext("2d"),this},setDefaults:function(){var a={fillStyle:this.data.fillStyle||"#F00",strokeStyle:this.data.strokeStyle||"#F0F",lineWidth:this.data.lineWidth||2,lineCap:this.data.lineCap||"round",lineJoin:this.data.lineJoin||"round",miterLimit:this.data.miterLimit||10};for(var b in a){var c=a[b];this.callStack.push({property:b,value:c})}return this.saveGraphics(a).restoreGraphics()},size:function(a,b){var c=parseFloat(a),d=parseFloat(b);return this.stageWidth=c,this.stageHeight=d,this.canvas.width=c,this.canvas.height=d,this.restoreGraphics(),this},background:function(a){var b=[0,0,this.stageWidth,this.stageHeight];return this.beginFill(a),this.context.fillRect.apply(this.context,b),this.endFill(),this.callStack.push({property:"fillStyle",value:a}),this.callStack.push({method:"fillRect",args:b}),this},stage:function(a,b,c){return this.size(a,b).background(c),this},beginFill:function(a){return this.saveGraphics({fillStyle:a}),this.context.fillStyle=a,this.callStack.push({property:"fillStyle",value:a}),this},endFill:function(){return this.restoreGraphics(),this},lineStyle:function(a,b,c,d,e){var f={strokeStyle:a,lineWidth:b,lineCap:c,lineJoin:d,miterLimit:e};return this.saveGraphics(f).restoreGraphics()},moveTo:function(a,b){var c=[].slice.call(arguments);return this.context.moveTo.apply(this.context,c),this.callStack.push({method:"moveTo",args:c}),this},lineTo:function(a,b){var c=[].slice.call(arguments);return this.context.lineTo.apply(this.context,c),this.callStack.push({method:"lineTo",args:c}),this},line:function(a,b,c,d){return this.moveTo(a,b),this.lineTo(c,d),this},curveTo:function(a,b,c,d){var e=[c,d,a,b];return this.context.quadraticCurveTo.apply(this.context,e),this.callStack.push({method:"quadraticCurveTo",args:e}),this},curve:function(a,b,c,d,e,f){return this.moveTo(a,b),this.curveTo(c,d,e,f),this},stroke:function(){return this.context.stroke(),this.callStack.push({method:"stroke"}),this},strokeRect:function(a,b,c,d){var e=[].slice.call(arguments);return this.context.beginPath(),this.context.strokeRect.apply(this.context,e),this.context.closePath(),this.callStack.push({method:"strokeRect",args:e}),this},fillRect:function(a,b,c,d){var e=[].slice.call(arguments);return this.context.beginPath(),this.context.fillRect.apply(this.context,e),this.context.closePath(),this.callStack.push({method:"fillRect",args:e}),this},rect:function(a,b,c,d){var e=[].slice.call(arguments);return this.fillRect.apply(this,e),this.strokeRect.apply(this,e),this},strokeCircle:function(a,b,c){var d=[a,b,c,0,2*Math.PI,!1];return this.context.beginPath(),this.context.arc.apply(this.context,d),this.context.stroke(),this.context.closePath(),this.callStack.push({method:"strokeCircle",args:d}),this},fillCircle:function(a,b,c){var d=[a,b,c,0,2*Math.PI,!1];return this.context.beginPath(),this.context.arc.apply(this.context,d),this.context.fill(),this.context.closePath(),this.callStack.push({method:"fillCircle",args:d}),this},circle:function(a,b,c){var d=[].slice.call(arguments);return this.fillCircle.apply(this,d),this.strokeCircle.apply(this,d),this},radialCircle:function(a,b,c,d,e){("undefined"==typeof d||0>d)&&(d=1);var f=this.context.createRadialGradient(a,b,c,a,b,d);e&&"array"===e.constructor.name.toLowerCase()||(e=[this.context.fillStyle,"white"]);for(var g=0;g',a+="Generated with jSketch: https://luis.leiva.name/jsketch/",a+="",a+="",a+=c(),a+="",a+="",a.replace(/\s+/g," ")}function c(){for(var a="",b=0;b=g){clearInterval(j);var c=b();a(c)}else console.info("Waiting for %s async operations to be finished ...",g)}if("function"!=typeof a)throw new Error("You must supply a callback in toSVG() method.");var e=this,f=[],g=0,h={},i={addAsync:function(){return g++,""},removeAsync:function(){return g--,""},drawImage:function(a,b,c){return''},fillRect:function(a,b,c,d){return''},strokeRect:function(a,b,c,d){return''},strokeCircle:function(a,b,c){return''},fillCircle:function(a,b,c){return''},beginPath:function(){return f=[],""},closePath:function(){var a="";return f.length>0&&(a='',f=[]),a},moveTo:function(a,b){return f.push("M "+a+" "+b),""},lineTo:function(a,b){return f.push("L "+a+" "+b),""},quadraticCurveTo:function(a,b,c,d){return f.push("Q "+a+" "+b+" "+c+" "+d),""}},j=setInterval(d,150);return this}}(this),function(){function a(a){var d=a[c],e=b.length;return d||(d=a[c]=e,b[d]={}),b[d]}var b=[0],c="data"+Date.now();window.dataBind=a}(),window.Event={add:function(a,b,c){return a?("string"==typeof a&&(a=document.querySelector(a)),void(a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent?a.attachEvent("on"+b,c):a[b+c]=function(){c(window.event)})):!1},remove:function(a,b,c){return a?("string"==typeof a&&(a=document.querySelector(a)),void(a.removeEventListener?a.removeEventListener(b,c,!1):a.detachEvent?a.detachEvent("on"+b,c):a[b+c]=null)):!1},isRightClick:function(a){return a||(a=window.event),a.which?3===a.which:a.button?2===e.button:!1}},window.deepExtend=function(a){a=a||{};for(var b=1;b1){var e=d.length-1,f=d[e],g=d[e-1];f[0]==g[0]&&f[1]==g[1]&&d.splice(e,1)}}function g(a){return a.touches?!1:void m(a)}function h(a){return a.touches?!1:void n(a)}function i(a){return a.touches?!1:void o(a)}function j(a){p(a,m),a.preventDefault()}function k(a){p(a,n),a.preventDefault()}function l(a){p(a,o),a.preventDefault()}function m(a){if(Event.isRightClick(a))return!1;var b=Math.abs(a.identifier||0),c=a.target,d=dataBind(c)[r],g=d.options;if(g.interactive){var h=e(a);"function"==typeof g.events.mousedownBefore&&g.events.mousedownBefore(c,d,a),g.graphics.firstPointSize>0&&d.sketch.beginFill(g.graphics.fillStyle).fillCircle(h.x,h.y,g.graphics.firstPointSize).endFill(),d.sketch.isDrawing=!0,d.sketch.beginPath();var i=d.coords[b];i||(i=[]),i.length>0&&d.strokes.push(i),d.coords[b]=[],f(b,d,h),"function"==typeof g.events.mousedown&&g.events.mousedown(c,d,a)}}function n(a){var b=Math.abs(a.identifier||0),c=a.target,d=dataBind(c)[r],g=d.options;if(g.interactive&&(g.mouseupMovements&&0!==d.strokes.length||d.sketch.isDrawing)){var h=e(a);"function"==typeof g.events.mousemoveBefore&&g.events.mousemoveBefore(c,d,a);var i=d.coords[b],j=i[i.length-1];if(j){var k=d.sketch;d.sketch.isDrawing?k.lineStyle(g.graphics.strokeStyle,g.graphics.lineWidth):g.mouseupMovements&&k.lineStyle(g.mouseupMovements.strokeStyle||"#DDD",g.mouseupMovements.lineWidth||1),k.line(j[0],j[1],h.x,h.y).stroke()}f(b,d,h),"function"==typeof g.events.mousemove&&g.events.mousemove(c,d,a)}}function o(a){var b=Math.abs(a.identifier||0),c=a.target,d=dataBind(c)[r],e=d.options;e.interactive&&("function"==typeof e.events.mouseupBefore&&e.events.mouseupBefore(c,d,a),d.sketch.isDrawing=!1,d.sketch.closePath(),d.strokes.push(d.coords[b]),d.coords[b]=[],"function"==typeof e.events.mouseup&&e.events.mouseup(c,d,a))}function p(a,b){var c=a.target,d=dataBind(c)[r],e=d.options;if(e.multitouch)for(var f=a.changedTouches,g=0;g3&&(j=1===h[3]),!j&&!c.mouseupMovements)break;if(0===g){c.graphics.firstPointSize>0&&d.beginFill(c.graphics.fillStyle).fillCircle(h[0],h[1],c.graphics.firstPointSize).endFill();var k,l;j?(k=c.strokeStyle,l=c.lineWidth):c.mouseupMovements&&(k=c.mouseupMovements.strokeStyle||"#DDD",l=c.mouseupMovements.lineWidth||1),d.lineStyle(k,l)}else i&&d.beginPath().line(h[0],h[1],i[0],i[1]).stroke().closePath()}}var r="sketchable",s=a.document;b.prototype={init:function(a){var c=deepExtend({},b.prototype.defaults,a||{}),e=this.elem,f=dataBind(e)[r];f||(Event.add(e,"mousedown",g),Event.add(e,"mousemove",h),Event.add(e,"mouseup",i),Event.add(e,"touchstart",j),Event.add(e,"touchmove",k),Event.add(e,"touchend",l),d(e,c));var m=new jSketch(e,c.graphics);dataBind(e)[r]=f={strokes:[],coords:{},timestamp:0,sketch:m,instance:this,options:c},"function"==typeof c.events.init&&c.events.init(e,f);for(var n in this.plugins)this.plugins[n](this);return this},config:function(a){var c=this.elem,e=dataBind(c)[r];return a?(e.options=deepExtend({},b.prototype.defaults,e.options,a),d(c),this):e.options},data:function(a){var b=this.elem,c=dataBind(b)[r];return a?c[a]:c},strokes:function(a){var b=this.elem,c=dataBind(b)[r];return a?(c.strokes=a,q(b),this):c.strokes},handler:function(a){var b=this.elem,c=dataBind(b)[r];return a(b,c),this},trigger:function(a){var b=this.elem,c=dataBind(b)[r],d=c.options.events;return d&&"function"==typeof d[a]&&d[a](b,c),this},clear:function(a){var b=this.elem,c=dataBind(b)[r],d=c.options;return c.sketch.clear(),a||(c.strokes=[],c.coords={}),"function"==typeof d.events.clear&&d.events.clear(b,c),this},reset:function(a){var b=this.elem,c=dataBind(b)[r],d=c.options;return this.destroy().init(a),"function"==typeof d.events.reset&&d.events.reset(b,c),this},destroy:function(){var a=this.elem,b=dataBind(a)[r],c=b.options;return Event.remove(a,"mouseup",i),Event.remove(a,"mousemove",h),Event.remove(a,"mousedown",g),Event.remove(a,"touchstart",j),Event.remove(a,"touchmove",k),Event.remove(a,"touchend",l),dataBind(a)[r]=null,"function"==typeof c.events.destroy&&c.events.destroy(a,b),this},decorate:function(a,b,c){var d=this.elem,e=dataBind(d)[r],f=e.options,g="_bound$"+a+"."+c;if(!e[g]){if(e[g]=!0,f.events&&"function"==typeof f.events[a]){var h=f.events[a];f.events[a]=function(){h.apply(this,arguments),b.apply(this,arguments)}}else f.events[a]=b;return this}}},b.prototype.plugins={},b.prototype.defaults={interactive:!0,mouseupMovements:!1,relTimestamps:!1,multitouch:!0,cssCursors:!0,filterCoords:!1,events:{},graphics:{firstPointSize:3,lineWidth:3,strokeStyle:"#F0F",fillStyle:"#F0F",lineCap:"round",lineJoin:"round",miterLimit:10}},a.Sketchable=b}(this),function(a){function b(a){function b(b,c){a.handler(function(a,d){d.sketch.clear(),d.sketch.context.drawImage(b,0,0),d.strokes=c.strokes.slice(),d.sketch.callStack=c.callStack.slice()})}function c(b){a.handler(function(a,c){b&&b.identifier>0?e[f].strokes=c.strokes.slice():(e.push({image:a.toDataURL(),strokes:c.strokes.slice(),callStack:c.sketch.callStack.slice()}),f++)})}function d(a){if(a.ctrlKey)switch(a.which){case 26:a.shiftKey?g.redo():g.undo();break;case 25:g.redo()}}var e=[],f=-1,g=this;this.undo=function(){return f>0&&(f--,this.restore(),a.trigger("mementoundo")),this},this.redo=function(){return f0?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