1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 12:12:48 +01:00
invoiceninja/public/js/jSignature.min.js
2019-01-30 22:25:37 +11:00

3 lines
22 KiB
JavaScript

!function(){function t(t){var n,e,i=t.css("color");t=t[0];for(var s=!1;t&&!e&&!s;){try{n=$(t).css("background-color")}catch(r){n="transparent"}"transparent"!==n&&"rgba(0, 0, 0, 0)"!==n&&(e=n),s=t.body,t=t.parentNode}t=/rgb[a]*\((\d+),\s*(\d+),\s*(\d+)/;var o,s=/#([AaBbCcDdEeFf\d]{2})([AaBbCcDdEeFf\d]{2})([AaBbCcDdEeFf\d]{2})/;n=void 0,(n=i.match(t))?o={r:parseInt(n[1],10),g:parseInt(n[2],10),b:parseInt(n[3],10)}:(n=i.match(s))&&(o={r:parseInt(n[1],16),g:parseInt(n[2],16),b:parseInt(n[3],16)});var a;return e?(n=void 0,(n=e.match(t))?a={r:parseInt(n[1],10),g:parseInt(n[2],10),b:parseInt(n[3],10)}:(n=e.match(s))&&(a={r:parseInt(n[1],16),g:parseInt(n[2],16),b:parseInt(n[3],16)})):a=o&&127<Math.max.apply(null,[o.r,o.g,o.b])?{r:0,g:0,b:0}:{r:255,g:255,b:255},n=function(t){return"rgb("+[t.r,t.g,t.b].join(", ")+")"},o&&a?(t=Math.max.apply(null,[o.r,o.g,o.b]),o=Math.max.apply(null,[a.r,a.g,a.b]),o=Math.round(o+-.75*(o-t)),o={r:o,g:o,b:o}):o?(o=Math.max.apply(null,[o.r,o.g,o.b]),t=1,127<o&&(t=-1),o=Math.round(o+96*t),o={r:o,g:o,b:o}):o={r:191,g:191,b:191},{color:i,"background-color":a?n(a):e,"decor-color":n(o)}}function n(t,n){this.x=t,this.y=n,this.reverse=function(){return new this.constructor(-1*this.x,-1*this.y)},this._length=null,this.getLength=function(){return this._length||(this._length=Math.sqrt(Math.pow(this.x,2)+Math.pow(this.y,2))),this._length};var e=function(t){return Math.round(t/Math.abs(t))};this.resizeTo=function(t){if(0===this.x&&0===this.y)this._length=0;else if(0===this.x)this._length=t,this.y=t*e(this.y);else if(0===this.y)this._length=t,this.x=t*e(this.x);else{var n=Math.abs(this.y/this.x),i=Math.sqrt(Math.pow(t,2)/(1+Math.pow(n,2))),n=n*i;this._length=t,this.x=i*e(this.x),this.y=n*e(this.y)}return this},this.angleTo=function(t){var n=this.getLength()*t.getLength();return 0===n?0:Math.acos(Math.min(Math.max((this.x*t.x+this.y*t.y)/n,-1),1))/Math.PI}}function e(t,e){this.x=t,this.y=e,this.getVectorToCoordinates=function(t,e){return new n(t-this.x,e-this.y)},this.getVectorFromCoordinates=function(t,n){return this.getVectorToCoordinates(t,n).reverse()},this.getVectorToPoint=function(t){return new n(t.x-this.x,t.y-this.y)},this.getVectorFromPoint=function(t){return this.getVectorToPoint(t).reverse()}}function i(t,n,e,i,s){if(this.data=t,this.context=n,t.length)for(var r,o,a=t.length,h=0;h<a;h++){r=t[h],o=r.x.length,e.call(n,r);for(var u=1;u<o;u++)i.call(n,r,u);s.call(n,r)}this.changed=function(){},this.startStrokeFn=e,this.addToStrokeFn=i,this.endStrokeFn=s,this.inStroke=!1,this._stroke=this._lastPoint=null,this.startStroke=function(t){if(t&&"number"==typeof t.x&&"number"==typeof t.y){this._stroke={x:[t.x],y:[t.y]},this.data.push(this._stroke),this._lastPoint=t,this.inStroke=!0;var n=this._stroke,e=this.startStrokeFn,i=this.context;return setTimeout(function(){e.call(i,n)},3),t}return null},this.addToStroke=function(t){if(this.inStroke&&"number"==typeof t.x&&"number"==typeof t.y&&4<Math.abs(t.x-this._lastPoint.x)+Math.abs(t.y-this._lastPoint.y)){var n=this._stroke.x.length;this._stroke.x.push(t.x),this._stroke.y.push(t.y),this._lastPoint=t;var e=this._stroke,i=this.addToStrokeFn,s=this.context;return setTimeout(function(){i.call(s,e,n)},3),t}return null},this.endStroke=function(){var t=this.inStroke;if(this.inStroke=!1,this._lastPoint=null,t){var n=this._stroke,e=this.endStrokeFn,i=this.context,s=this.changed;return setTimeout(function(){e.call(i,n),s.call(i)},3),!0}return null}}function s(t,n,e,i){"ratio"!==n&&"%"!==n.split("")[n.length-1]||(this.eventTokens[e+".parentresized"]=i.subscribe(e+".parentresized",function(n,s,r,o){return function(){var o=s.width();if(o!==r){for(var a in n)n.hasOwnProperty(a)&&(i.unsubscribe(n[a]),delete n[a]);var h=t.settings;t.$parent.children().remove();for(a in t)t.hasOwnProperty(a)&&delete t[a];a=h.data;var u,c,l,d,g,f,o=1*o/r,p=[];for(c=0,l=a.length;c<l;c++){for(f=a[c],u={x:[],y:[]},d=0,g=f.x.length;d<g;d++)u.x.push(f.x[d]*o),u.y.push(f.y[d]*o);p.push(u)}h.data=p,s[e](h)}}}(this.eventTokens,this.$parent,this.$parent.width(),1*this.canvas.width/this.canvas.height)))}function r(n,i,r){var o=this.$parent=$(n);n=this.eventTokens={},this.events=new u(this);var c=$.fn[a]("globalEvents"),l={width:"ratio",height:"ratio",sizeRatio:4,color:"#000","background-color":"#fff","decor-color":"#eee",lineWidth:0,minFatFingerCompensation:-10,showUndoButton:!1,readOnly:!1,data:[]};$.extend(l,t(o)),i&&$.extend(l,i),this.settings=l;for(var d in r)r.hasOwnProperty(d)&&r[d].call(this,d);return this.events.publish(a+".initializing"),this.$controlbarUpper=$('<div style="padding:0 !important; margin:0 !important;width: 100% !important; height: 0 !important; -ms-touch-action: none;margin-top:-1em !important; margin-bottom:1em !important;"></div>').appendTo(o),this.isCanvasEmulator=!1,i=this.canvas=this.initializeCanvas(l),r=$(i),this.$controlbarLower=$('<div style="padding:0 !important; margin:0 !important;width: 100% !important; height: 0 !important; -ms-touch-action: none;margin-top:-1.5em !important; margin-bottom:1.5em !important; position: relative;"></div>').appendTo(o),this.canvasContext=i.getContext("2d"),r.data(a+".this",this),l.lineWidth=function(t,n){return t?t:Math.max(Math.round(n/400),2)}(l.lineWidth,i.width),this.lineCurveThreshold=3*l.lineWidth,l.cssclass&&""!=$.trim(l.cssclass)&&r.addClass(l.cssclass),this.fatFingerCompensation=0,o=function(t){var n,i,s=function(s){return s=s.changedTouches&&0<s.changedTouches.length?s.changedTouches[0]:s,new e(Math.round(s.pageX+n),Math.round(s.pageY+i)+t.fatFingerCompensation)},r=new h(750,function(){t.dataEngine.endStroke()});return this.drawEndHandler=function(n){if(!t.settings.readOnly){try{n.preventDefault()}catch(e){}r.clear(),t.dataEngine.endStroke()}},this.drawStartHandler=function(e){if(!t.settings.readOnly){e.preventDefault();var o=$(t.canvas).offset();n=-1*o.left,i=-1*o.top,t.dataEngine.startStroke(s(e)),r.kick()}},this.drawMoveHandler=function(n){t.settings.readOnly||(n.preventDefault(),t.dataEngine.inStroke&&(t.dataEngine.addToStroke(s(n)),r.kick()))},this}.call({},this),function(t,n,e){var i=this.canvas,s=$(i);this.isCanvasEmulator?(s.bind("mousemove."+a,e),s.bind("mouseup."+a,t),s.bind("mousedown."+a,n)):(i.ontouchstart=function(s){i.onmousedown=i.onmouseup=i.onmousemove=void 0,this.fatFingerCompensation=l.minFatFingerCompensation&&-3*l.lineWidth>l.minFatFingerCompensation?-3*l.lineWidth:l.minFatFingerCompensation,n(s),i.ontouchend=t,i.ontouchstart=n,i.ontouchmove=e},i.onmousedown=function(s){i.ontouchstart=i.ontouchend=i.ontouchmove=void 0,n(s),i.onmousedown=n,i.onmouseup=t,i.onmousemove=e},window.navigator.msPointerEnabled&&(i.onmspointerdown=n,i.onmspointerup=t,i.onmspointermove=e))}.call(this,o.drawEndHandler,o.drawStartHandler,o.drawMoveHandler),n[a+".windowmouseup"]=c.subscribe(a+".windowmouseup",o.drawEndHandler),this.events.publish(a+".attachingEventHandlers"),s.call(this,this,l.width.toString(10),a,c),this.resetCanvas(l.data),this.events.publish(a+".initialized"),this}function o(t){if(t.getContext)return!1;var n=t.ownerDocument.parentWindow,e=n.FlashCanvas?t.ownerDocument.parentWindow.FlashCanvas:"undefined"==typeof FlashCanvas?void 0:FlashCanvas;if(e){if(t=e.initElement(t),e=1,n&&n.screen&&n.screen.deviceXDPI&&n.screen.logicalXDPI&&(e=1*n.screen.deviceXDPI/n.screen.logicalXDPI),1!==e)try{$(t).children("object").get(0).resize(Math.ceil(t.width*e),Math.ceil(t.height*e)),t.getContext("2d").scale(e,e)}catch(i){}return!0}throw Error("Canvas element does not support 2d context. jSignature cannot proceed.")}var a="jSignature",h=function(t,n){var e;return this.kick=function(){clearTimeout(e),e=setTimeout(n,t)},this.clear=function(){clearTimeout(e)},this},u=function(t){this.topics={},this.context=t?t:this,this.publish=function(t,n,e,i){if(this.topics[t]){var s,r,o,a,h=this.topics[t],u=Array.prototype.slice.call(arguments,1),c=[];for(r=0,o=h.length;r<o;r++)a=h[r],s=a[0],a[1]&&(a[0]=function(){},c.push(r)),s.apply(this.context,u);for(r=0,o=c.length;r<o;r++)h.splice(c[r],1)}},this.subscribe=function(t,n,e){return this.topics[t]?this.topics[t].push([n,e]):this.topics[t]=[[n,e]],{topic:t,callback:n}},this.unsubscribe=function(t){if(this.topics[t.topic])for(var n=this.topics[t.topic],e=0,i=n.length;e<i;e++)n[e]&&n[e][0]===t.callback&&n.splice(e,1)}},c=function(t,n,e,i,s){t.beginPath(),t.moveTo(n,e),t.lineTo(i,s),t.closePath(),t.stroke()},l=function(t){var n=this.canvasContext,e=t.x[0];t=t.y[0];var i=this.settings.lineWidth,s=n.fillStyle;n.fillStyle=n.strokeStyle,n.fillRect(e+i/-2,t+i/-2,i,i),n.fillStyle=s},d=function(t,i){var s=new e(t.x[i-1],t.y[i-1]),r=new e(t.x[i],t.y[i]),o=s.getVectorToPoint(r);if(1<i){var a,h=new e(t.x[i-2],t.y[i-2]),u=h.getVectorToPoint(s);if(u.getLength()>this.lineCurveThreshold){a=2<i?new e(t.x[i-3],t.y[i-3]).getVectorToPoint(h):new n(0,0);var l=.35*u.getLength(),d=u.angleTo(a.reverse()),g=o.angleTo(u.reverse());a=new n(a.x+u.x,a.y+u.y).resizeTo(Math.max(.05,d)*l);var f=new n(u.x+o.x,u.y+o.y).reverse().resizeTo(Math.max(.05,g)*l),u=this.canvasContext,l=h.x,g=h.y,d=s.x,p=s.y,v=h.x+a.x,h=h.y+a.y;a=s.x+f.x,f=s.y+f.y,u.beginPath(),u.moveTo(l,g),u.bezierCurveTo(v,h,a,f,d,p),u.closePath(),u.stroke()}}o.getLength()<=this.lineCurveThreshold&&c(this.canvasContext,s.x,s.y,r.x,r.y)},g=function(t){var i=t.x.length-1;if(0<i){var s=new e(t.x[i],t.y[i]),r=new e(t.x[i-1],t.y[i-1]),o=r.getVectorToPoint(s);if(o.getLength()>this.lineCurveThreshold)if(1<i){t=new e(t.x[i-2],t.y[i-2]).getVectorToPoint(r);var a=new n(t.x+o.x,t.y+o.y).resizeTo(o.getLength()/2),o=this.canvasContext;t=r.x;var i=r.y,h=s.x,u=s.y,l=r.x+a.x,r=r.y+a.y,a=s.x,s=s.y;o.beginPath(),o.moveTo(t,i),o.bezierCurveTo(l,r,a,s,h,u),o.closePath(),o.stroke()}else c(this.canvasContext,r.x,r.y,s.x,s.y)}};r.prototype.resetCanvas=function(t,n){var e=this.canvas,s=this.settings,r=this.canvasContext,o=this.isCanvasEmulator,h=e.width,u=e.height;if(n||r.clearRect(0,0,h+30,u+30),r.shadowColor=r.fillStyle=s["background-color"],o&&r.fillRect(0,0,h+30,u+30),r.lineWidth=Math.ceil(parseInt(s.lineWidth,10)),r.lineCap=r.lineJoin="round",null!=s["decor-color"]){r.strokeStyle=s["decor-color"],r.shadowOffsetX=0,r.shadowOffsetY=0;var f=Math.round(u/5);c(r,1.5*f,u-f,h-1.5*f,u-f)}return r.strokeStyle=s.color,o||(r.shadowColor=r.strokeStyle,r.shadowOffsetX=.5*r.lineWidth,r.shadowOffsetY=-.6*r.lineWidth,r.shadowBlur=0),t||(t=[]),r=this.dataEngine=new i(t,this,l,d,g),s.data=t,$(e).data(a+".data",t).data(a+".settings",s),r.changed=function(t,n,e){return function(){n.publish(e+".change"),t.trigger("change")}}(this.$parent,this.events,a),r.changed(),!0},r.prototype.initializeCanvas=function(t){var n=document.createElement("canvas"),e=$(n);return t.width===t.height&&"ratio"===t.height&&(t.width="100%"),e.css("margin",0).css("padding",0).css("border","none").css("height","ratio"!==t.height&&t.height?t.height.toString(10):1).css("width","ratio"!==t.width&&t.width?t.width.toString(10):1).css("-ms-touch-action","none"),e.appendTo(this.$parent),"ratio"===t.height?e.css("height",Math.round(e.width()/t.sizeRatio)):"ratio"===t.width&&e.css("width",Math.round(e.height()*t.sizeRatio)),e.addClass(a),n.width=e.width(),n.height=e.height(),this.isCanvasEmulator=o(n),n.onselectstart=function(t){return t&&t.preventDefault&&t.preventDefault(),t&&t.stopPropagation&&t.stopPropagation(),!1},n},function(t){function n(t,n,e){var i=new Image,s=this;i.onload=function(){s.getContext("2d").drawImage(i,0,0,i.width<s.width?i.width:s.width,i.height<s.height?i.height:s.height)},i.src="data:"+n+","+t}function e(t,n){return this.find("canvas."+a).add(this.filter("canvas."+a)).data(a+".this").resetCanvas(t,n),this}function i(t,n){if(void 0!==n||"string"!=typeof t||"data:"!==t.substr(0,5)||(n=t.slice(5).split(",")[0],t=t.slice(6+n.length),n!==t)){var e=this.find("canvas."+a).add(this.filter("canvas."+a));if(!c.hasOwnProperty(n))throw Error(a+" is unable to find import plugin with for format '"+String(n)+"'");return 0!==e.length&&c[n].call(e[0],t,n,function(t){return function(){return t.resetCanvas.apply(t,arguments)}}(e.data(a+".this"))),this}}var s=new u;!function(t,n,e,i){var s,r=function(){t.publish(n+".parentresized")};e(i).bind("resize."+n,function(){s&&clearTimeout(s),s=setTimeout(r,500)}).bind("mouseup."+n,function(e){t.publish(n+".windowmouseup")})}(s,a,$,t);var o={},h={"default":function(t){return this.toDataURL()},"native":function(t){return t},image:function(t){if(t=this.toDataURL(),"string"==typeof t&&4<t.length&&"data:"===t.slice(0,5)&&-1!==t.indexOf(",")){var n=t.indexOf(",");return[t.slice(5,n),t.substr(n+1)]}return[]}},c={"native":function(t,n,e){e(t)},image:n,"image/png;base64":n,"image/jpeg;base64":n,"image/jpg;base64":n},l={"export":h,"import":c,instance:o},d={init:function(t){return this.each(function(){var n,e=!1;for(n=this.parentNode;n&&!e;)e=n.body,n=n.parentNode;e&&new r(this,t,o)})},getSettings:function(){return this.find("canvas."+a).add(this.filter("canvas."+a)).data(a+".this").settings},isModified:function(){return null!==this.find("canvas."+a).add(this.filter("canvas."+a)).data(a+".this").dataEngine._stroke},updateSetting:function(t,n,e){var i=this.find("canvas."+a).add(this.filter("canvas."+a)).data(a+".this");return i.settings[t]=n,i.resetCanvas(e?null:i.settings.data,!0),i.settings[t]},clear:e,reset:e,addPlugin:function(t,n,e){return l.hasOwnProperty(t)&&(l[t][n]=e),this},listPlugins:function(t){var n=[];if(l.hasOwnProperty(t)){t=l[t];for(var e in t)t.hasOwnProperty(e)&&n.push(e)}return n},getData:function(t){var n=this.find("canvas."+a).add(this.filter("canvas."+a));if(void 0===t&&(t="default"),0!==n.length&&h.hasOwnProperty(t))return h[t].call(n.get(0),n.data(a+".data"),n.data(a+".settings"))},importData:i,setData:i,globalEvents:function(){return s},disable:function(){this.find("input").attr("disabled",1),this.find("canvas."+a).addClass("disabled").data(a+".this").settings.readOnly=!0},enable:function(){this.find("input").removeAttr("disabled"),this.find("canvas."+a).removeClass("disabled").data(a+".this").settings.readOnly=!1},events:function(){return this.find("canvas."+a).add(this.filter("canvas."+a)).data(a+".this").events}};$.fn[a]=function(t){return t&&"object"!=typeof t?"string"==typeof t&&d[t]?d[t].apply(this,Array.prototype.slice.call(arguments,1)):void $.error("Method "+String(t)+" does not exist on jQuery."+a):d.init.apply(this,arguments)}}(window)}(),function(){function t(t,n,e){t=t.call(this),function(t,n,e){t.events.subscribe(e+".change",function(){t.dataEngine.data.length?n.show():n.hide()})}(this,t,n),function(t,n,e){var i=e+".undo";n.bind("click",function(){t.events.publish(i)}),t.events.subscribe(i,function(){var n=t.dataEngine.data;n.length&&(n.pop(),t.resetCanvas(n))})}(this,t,this.events.topics.hasOwnProperty(n+".undo")?e:n)}$.fn.jSignature("addPlugin","instance","UndoButton",function(n){this.events.subscribe("jSignature.attachingEventHandlers",function(){if(this.settings[n]){var e=this.settings[n];"function"!=typeof e&&(e=function(){var t=$('<input type="button" value="Undo last stroke" style="position:absolute;display:none;margin:0 !important;top:auto" />').appendTo(this.$controlbarLower),n=t.width();return t.css("left",Math.round((this.canvas.width-n)/2)),n!==t.width()&&t.width(n),t}),t.call(this,e,"jSignature",n)}})})}(),function(){for(var t={},n={},e="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX".split(""),i=e.length/2,s=i-1;-1<s;s--)t[e[s]]=e[s+i],n[e[s+i]]=e[s];var r=function(n){n=n.split("");for(var e=n.length,i=1;i<e;i++)n[i]=t[n[i]];return n.join("")},o=function(t){for(var n,e,s=[],o=0,a=1,h=t.length,u=0;u<h;u++)n=Math.round(t[u]),e=n-o,o=n,0>e&&0<a?(a=-1,s.push("Z")):0<e&&0>a&&(a=1,s.push("Y")),n=Math.abs(e),n>=i?s.push(r(n.toString(i))):s.push(n.toString(i));return s.join("")},a=function(e){var s=[];e=e.split("");for(var r,o=e.length,a=1,h=[],u=0,c=0;c<o;c++)r=e[c],r in t||"Z"===r||"Y"===r?(0!==h.length&&(h=parseInt(h.join(""),i)*a+u,s.push(h),u=h),"Z"===r?(a=-1,h=[]):"Y"===r?(a=1,h=[]):h=[r]):h.push(n[r]);return s.push(parseInt(h.join(""),i)*a+u),s},h=function(t){for(var n,e=[],i=t.length,s=0;s<i;s++)n=t[s],e.push(o(n.x)),e.push(o(n.y));return e.join("_")},u=function(t){var n=[];t=t.split("_");for(var e=t.length/2,i=0;i<e;i++)n.push({x:a(t[2*i]),y:a(t[2*i+1])});return n},c=function(t){return["image/jsignature;base30",h(t)]},l=function(t,n,e){"string"==typeof t&&("image/jsignature;base30"===t.substring(0,23).toLowerCase()&&(t=t.substring(24)),e(u(t)))};if(null==this.jQuery)throw Error("We need jQuery for some of the functionality. jQuery is not detected. Failing to initialize...");!function(t){t=t.fn.jSignature,t("addPlugin","export","base30",c),t("addPlugin","export","image/jsignature;base30",c),t("addPlugin","import","base30",l),t("addPlugin","import","image/jsignature;base30",l)}(this.jQuery),this.jSignatureDebug&&(this.jSignatureDebug.base30={remapTailChars:r,compressstrokeleg:o,uncompressstrokeleg:a,compressstrokes:h,uncompressstrokes:u,charmap:t})}.call("undefined"!=typeof window?window:this),function(){function t(t,n){this.x=t,this.y=n,this.reverse=function(){return new this.constructor(-1*this.x,-1*this.y)},this._length=null,this.getLength=function(){return this._length||(this._length=Math.sqrt(Math.pow(this.x,2)+Math.pow(this.y,2))),this._length};var e=function(t){return Math.round(t/Math.abs(t))};this.resizeTo=function(t){if(0===this.x&&0===this.y)this._length=0;else if(0===this.x)this._length=t,this.y=t*e(this.y);else if(0===this.y)this._length=t,this.x=t*e(this.x);else{var n=Math.abs(this.y/this.x),i=Math.sqrt(Math.pow(t,2)/(1+Math.pow(n,2))),n=n*i;this._length=t,this.x=i*e(this.x),this.y=n*e(this.y)}return this},this.angleTo=function(t){var n=this.getLength()*t.getLength();return 0===n?0:Math.acos(Math.min(Math.max((this.x*t.x+this.y*t.y)/n,-1),1))/Math.PI}}function n(n,e){this.x=n,this.y=e,this.getVectorToCoordinates=function(n,e){return new t(n-this.x,e-this.y)},this.getVectorFromCoordinates=function(t,n){return this.getVectorToCoordinates(t,n).reverse()},this.getVectorToPoint=function(n){return new t(n.x-this.x,n.y-this.y)},this.getVectorFromPoint=function(t){return this.getVectorToPoint(t).reverse()}}function e(t,n){var e=Math.pow(10,n);return Math.round(t*e)/e}function i(i,s,r){s+=1;var o=new n(i.x[s-1],i.y[s-1]),a=new n(i.x[s],i.y[s]),a=o.getVectorToPoint(a),h=new n(i.x[s-2],i.y[s-2]),o=h.getVectorToPoint(o);return o.getLength()>r?(r=2<s?new n(i.x[s-3],i.y[s-3]).getVectorToPoint(h):new t(0,0),i=.35*o.getLength(),h=o.angleTo(r.reverse()),s=a.angleTo(o.reverse()),r=new t(r.x+o.x,r.y+o.y).resizeTo(Math.max(.05,h)*i),a=new t(o.x+a.x,o.y+a.y).reverse().resizeTo(Math.max(.05,s)*i),a=new t(o.x+a.x,o.y+a.y),["c",e(r.x,2),e(r.y,2),e(a.x,2),e(a.y,2),e(o.x,2),e(o.y,2)]):["l",e(o.x,2),e(o.y,2)]}function s(i,s){var r=i.x.length-1,o=new n(i.x[r],i.y[r]),a=new n(i.x[r-1],i.y[r-1]),o=a.getVectorToPoint(o);if(1<r&&o.getLength()>s){var r=new n(i.x[r-2],i.y[r-2]).getVectorToPoint(a),a=o.angleTo(r.reverse()),h=.35*o.getLength(),r=new t(r.x+o.x,r.y+o.y).resizeTo(Math.max(.05,a)*h);return["c",e(r.x,2),e(r.y,2),e(o.x,2),e(o.y,2),e(o.x,2),e(o.y,2)]}return["l",e(o.x,2),e(o.y,2)]}function r(t,n,r){n=["M",e(t.x[0]-n,2),e(t.y[0]-r,2)],r=1;for(var o=t.x.length-1;r<o;r++)n.push.apply(n,i(t,r,1));return 0<o?n.push.apply(n,s(t,r,1)):0===o&&n.push.apply(n,["l",1,1]),n.join(" ")}function o(t){for(var n=[],e=[["fill",void 0,"none"],["stroke","color","#000000"],["stroke-width","lineWidth",2],["stroke-linecap",void 0,"round"],["stroke-linejoin",void 0,"round"]],i=e.length-1;0<=i;i--){var s=e[i][1],r=e[i][2];n.push(e[i][0]+'="'+(s in t&&t[s]?t[s]:r)+'"')}return n.join(" ")}function a(t,n){var e,i,s=['<?xml version="1.0" encoding="UTF-8" standalone="no"?>','<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'],a=t.length,h=[],u=[],c=i=e=0,l=0,d=[];if(0!==a){for(e=0;e<a;e++){c=t[e],l=[],i={x:[],y:[]};for(var g=void 0,f=void 0,g=0,f=c.x.length;g<f;g++)l.push({x:c.x[g],y:c.y[g]});for(l=simplify(l,.7,!0),g=0,f=l.length;g<f;g++)i.x.push(l[g].x),i.y.push(l[g].y);d.push(i),h=h.concat(i.x),u=u.concat(i.y)}a=Math.min.apply(null,h)-1,e=Math.max.apply(null,h)+1,h=Math.min.apply(null,u)-1,u=Math.max.apply(null,u)+1,c=0>a?0:a,l=0>h?0:h,e-=a,i=u-h}for(s.push('<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="'+e.toString()+'" height="'+i.toString()+'">'),e=0,a=d.length;e<a;e++)i=d[e],s.push("<path "+o(n)+' d="'+r(i,c,l)+'"/>');return s.push("</svg>"),s.join("")}function h(t,n){return[l,a(t,n)]}function u(t,n){return[d,c(a(t,n))]}if(function(t,n){"use strict";(typeof exports!=n+""?exports:t).simplify=function(t,e,i){if(e=e!==n?e*e:1,!i){var s,r=t.length,o=t[0],a=[o];for(i=1;i<r;i++){s=t[i];var h=s.x-o.x,u=s.y-o.y;h*h+u*u>e&&(a.push(s),o=s)}o!==s&&a.push(s),t=a}s=t,i=s.length;var c,l,r=new(typeof Uint8Array!=n+""?Uint8Array:Array)(i),o=0,a=i-1,d=[],g=[],f=[];for(r[o]=r[a]=1;a;){for(u=0,h=o+1;h<a;h++){c=s[h];var p=s[o],v=s[a],y=p.x,x=p.y,p=v.x-y,m=v.y-x,w=void 0;0===p&&0===m||(w=((c.x-y)*p+(c.y-x)*m)/(p*p+m*m),1<w?(y=v.x,x=v.y):0<w&&(y+=p*w,x+=m*w)),p=c.x-y,m=c.y-x,c=p*p+m*m,c>u&&(l=h,u=c)}u>e&&(r[l]=1,d.push(o),g.push(l),d.push(l),g.push(a)),o=d.pop(),a=g.pop()}for(h=0;h<i;h++)r[h]&&f.push(s[h]);return t=f}}(window),"function"!=typeof c)var c=function(t){var n,e,i,s,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".split(""),o=0,a=0,h="",h=[];do n=t.charCodeAt(o++),e=t.charCodeAt(o++),i=t.charCodeAt(o++),s=n<<16|e<<8|i,n=s>>18&63,e=s>>12&63,i=s>>6&63,s&=63,h[a++]=r[n]+r[e]+r[i]+r[s];while(o<t.length);return h=h.join(""),t=t.length%3,(t?h.slice(0,t-3):h)+"===".slice(t||3)};var l="image/svg+xml",d="image/svg+xml;base64";if("undefined"==typeof $)throw Error("We need jQuery for some of the functionality. jQuery is not detected. Failing to initialize...");!function(t){t=t.fn.jSignature,t("addPlugin","export","svg",h),t("addPlugin","export",l,h),t("addPlugin","export","svgbase64",u),t("addPlugin","export",d,u)}($)}();
//# sourceMappingURL=jSignature.min.js.map