1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/public/js/jSignature.min.js
2019-01-30 22:25:07 +11:00

3 lines
23 KiB
JavaScript

!function(){function t(t){var n,e=t.css("color");t=t[0];for(var i=!1;t&&!n&&!i;){try{var r=$(t).css("background-color")}catch(a){r="transparent"}"transparent"!==r&&"rgba(0, 0, 0, 0)"!==r&&(n=r),i=t.body,t=t.parentNode}if(t=/rgb[a]*\((\d+),\s*(\d+),\s*(\d+)/,i=/#([AaBbCcDdEeFf\d]{2})([AaBbCcDdEeFf\d]{2})([AaBbCcDdEeFf\d]{2})/,r=void 0,r=e.match(t))var s={r:parseInt(r[1],10),g:parseInt(r[2],10),b:parseInt(r[3],10)};else(r=e.match(i))&&(s={r:parseInt(r[1],16),g:parseInt(r[2],16),b:parseInt(r[3],16)});if(n)if(r=void 0,r=n.match(t))var o={r:parseInt(r[1],10),g:parseInt(r[2],10),b:parseInt(r[3],10)};else(r=n.match(i))&&(o={r:parseInt(r[1],16),g:parseInt(r[2],16),b:parseInt(r[3],16)});else o=s&&127<Math.max.apply(null,[s.r,s.g,s.b])?{r:0,g:0,b:0}:{r:255,g:255,b:255};return r=function(t){return"rgb("+[t.r,t.g,t.b].join(", ")+")"},s&&o?(t=Math.max.apply(null,[s.r,s.g,s.b]),s=Math.max.apply(null,[o.r,o.g,o.b]),s=Math.round(s+-.75*(s-t)),s={r:s,g:s,b:s}):s?(s=Math.max.apply(null,[s.r,s.g,s.b]),t=1,127<s&&(t=-1),s=Math.round(s+96*t),s={r:s,g:s,b:s}):s={r:191,g:191,b:191},{color:e,"background-color":o?r(o):n,"decor-color":r(s)}}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*=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,r){if(this.data=t,this.context=n,t.length)for(var a,s,o=t.length,h=0;h<o;h++){a=t[h],s=a.x.length,e.call(n,a);for(var u=1;u<s;u++)i.call(n,a,u);r.call(n,a)}this.changed=function(){},this.startStrokeFn=e,this.addToStrokeFn=i,this.endStrokeFn=r,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,r=this.context;return setTimeout(function(){i.call(r,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,r=this.changed;return setTimeout(function(){e.call(i,n),r.call(i)},3),!0}return null}}function r(t,n,e,i){"ratio"!==n&&"%"!==n.split("")[n.length-1]||(this.eventTokens[e+".parentresized"]=i.subscribe(e+".parentresized",function(n,r,a,s){return function(){var s=r.width();if(s!==a){for(var o in n)n.hasOwnProperty(o)&&(i.unsubscribe(n[o]),delete n[o]);var h=t.settings;t.$parent.children().remove();for(o in t)t.hasOwnProperty(o)&&delete t[o];o=h.data,s=1*s/a;var u,c,l=[],d=0;for(u=o.length;d<u;d++){var g=o[d],f={x:[],y:[]},p=0;for(c=g.x.length;p<c;p++)f.x.push(g.x[p]*s),f.y.push(g.y[p]*s);l.push(f)}h.data=l,r[e](h)}}}(this.eventTokens,this.$parent,this.$parent.width(),1*this.canvas.width/this.canvas.height)))}function a(n,i,a){var s=this.$parent=$(n);n=this.eventTokens={},this.events=new h(this);var u=$.fn.jSignature("globalEvents"),c={width:"ratio",height:"ratio",sizeRatio:4,color:"#000","background-color":"#fff","decor-color":"#eee",lineWidth:0,minFatFingerCompensation:-10,showUndoButton:!1,readOnly:!1,data:[],signatureLine:!1};$.extend(c,t(s)),i&&$.extend(c,i),this.settings=c;for(var l in a)a.hasOwnProperty(l)&&a[l].call(this,l);return this.events.publish("jSignature.initializing"),this.$controlbarUpper=$('<div style="padding:0 !important; margin:0 !important;width: 100% !important; height: 0 !important; -ms-touch-action: none; touch-action: none;margin-top:-1em !important; margin-bottom:1em !important;"></div>').appendTo(s),this.isCanvasEmulator=!1,i=this.canvas=this.initializeCanvas(c),a=$(i),this.$controlbarLower=$('<div style="padding:0 !important; margin:0 !important;width: 100% !important; height: 0 !important; -ms-touch-action: none; touch-action: none;margin-top:-1.5em !important; margin-bottom:1.5em !important; position: relative;"></div>').appendTo(s),this.canvasContext=i.getContext("2d"),a.data("jSignature.this",this),c.lineWidth=function(t,n){return t?t:Math.max(Math.round(n/400),2)}(c.lineWidth,i.width),this.lineCurveThreshold=3*c.lineWidth,c.cssclass&&""!=$.trim(c.cssclass)&&a.addClass(c.cssclass),this.fatFingerCompensation=0,s=function(t){var n,i,r=function(r){return r=r.changedTouches&&0<r.changedTouches.length?r.changedTouches[0]:r,new e(Math.round(r.pageX+n),Math.round(r.pageY+i)+t.fatFingerCompensation)},a=new o(750,function(){t.dataEngine.endStroke()});return this.drawEndHandler=function(n){if(!t.settings.readOnly){try{n.preventDefault()}catch(e){}a.clear(),t.dataEngine.endStroke()}},this.drawStartHandler=function(e){if(!t.settings.readOnly){e.preventDefault();var s=$(t.canvas).offset();n=-1*s.left,i=-1*s.top,t.dataEngine.startStroke(r(e)),a.kick()}},this.drawMoveHandler=function(n){t.settings.readOnly||(n.preventDefault(),t.dataEngine.inStroke&&(t.dataEngine.addToStroke(r(n)),a.kick()))},this}.call({},this),function(t,n,e){var i=this.canvas,r=$(i);if(this.isCanvasEmulator)r.bind("mousemove.jSignature",e),r.bind("mouseup.jSignature",t),r.bind("mousedown.jSignature",n);else{var a="function"==typeof i.addEventListener;this.ontouchstart=function(r){i.onmousedown=i.onmouseup=i.onmousemove=void 0,this.fatFingerCompensation=c.minFatFingerCompensation&&-3*c.lineWidth>c.minFatFingerCompensation?-3*c.lineWidth:c.minFatFingerCompensation,n(r),a?(i.addEventListener("touchend",t),i.addEventListener("touchstart",n),i.addEventListener("touchmove",e)):(i.ontouchend=t,i.ontouchstart=n,i.ontouchmove=e)},a?i.addEventListener("touchstart",this.ontouchstart):i.ontouchstart=ontouchstart,i.onmousedown=function(r){a?i.removeEventListener("touchstart",this.ontouchstart):i.ontouchstart=i.ontouchend=i.ontouchmove=void 0,n(r),i.onmousedown=n,i.onmouseup=t,i.onmousemove=e},window.navigator.msPointerEnabled&&(i.onmspointerdown=n,i.onmspointerup=t,i.onmspointermove=e)}}.call(this,s.drawEndHandler,s.drawStartHandler,s.drawMoveHandler),n["jSignature.windowmouseup"]=u.subscribe("jSignature.windowmouseup",s.drawEndHandler),this.events.publish("jSignature.attachingEventHandlers"),r.call(this,this,c.width.toString(10),"jSignature",u),this.resetCanvas(c.data),this.events.publish("jSignature.initialized"),this}function s(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 o=function(t,n){var e;return this.kick=function(){clearTimeout(e),e=setTimeout(n,t)},this.clear=function(){clearTimeout(e)},this},h=function(t){this.topics={},this.context=t?t:this,this.publish=function(t,n,e,i){if(this.topics[t]){var r,a=this.topics[t],s=Array.prototype.slice.call(arguments,1),o=[],h=[],u=0;for(r=a.length;u<r;u++){var c=a[u],l=c[0];c[1]&&(c[0]=function(){},o.push(u)),h.push(l)}for(u=0,r=o.length;u<r;u++)a.splice(o[u],1);for(u=0,r=h.length;u<r;u++)h[u].apply(this.context,s)}},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)}},u=function(t,n,e,i,r){t.beginPath(),t.moveTo(n,e),t.lineTo(i,r),t.closePath(),t.stroke()},c=function(t){var n=this.canvasContext,e=t.x[0];t=t.y[0];var i=this.settings.lineWidth,r=n.fillStyle;n.fillStyle=n.strokeStyle,n.fillRect(e+i/-2,t+i/-2,i,i),n.fillStyle=r},l=function(t,i){var r=new e(t.x[i-1],t.y[i-1]),a=new e(t.x[i],t.y[i]),s=r.getVectorToPoint(a);if(1<i){var o=new e(t.x[i-2],t.y[i-2]),h=o.getVectorToPoint(r);if(h.getLength()>this.lineCurveThreshold){var c=2<i?new e(t.x[i-3],t.y[i-3]).getVectorToPoint(o):new n(0,0),l=.35*h.getLength(),d=h.angleTo(c.reverse()),g=s.angleTo(h.reverse());c=new n(c.x+h.x,c.y+h.y).resizeTo(Math.max(.05,d)*l);var f=new n(h.x+s.x,h.y+s.y).reverse().resizeTo(Math.max(.05,g)*l);h=this.canvasContext,l=o.x,g=o.y,d=r.x;var p=r.y,v=o.x+c.x;o=o.y+c.y,c=r.x+f.x,f=r.y+f.y,h.beginPath(),h.moveTo(l,g),h.bezierCurveTo(v,o,c,f,d,p),h.closePath(),h.stroke()}}s.getLength()<=this.lineCurveThreshold&&u(this.canvasContext,r.x,r.y,a.x,a.y)},d=function(t){var i=t.x.length-1;if(0<i){var r=new e(t.x[i],t.y[i]),a=new e(t.x[i-1],t.y[i-1]),s=a.getVectorToPoint(r);if(s.getLength()>this.lineCurveThreshold)if(1<i){t=new e(t.x[i-2],t.y[i-2]).getVectorToPoint(a);var o=new n(t.x+s.x,t.y+s.y).resizeTo(s.getLength()/2);s=this.canvasContext,t=a.x,i=a.y;var h=r.x,c=r.y,l=a.x+o.x;a=a.y+o.y,o=r.x,r=r.y,s.beginPath(),s.moveTo(t,i),s.bezierCurveTo(l,a,o,r,h,c),s.closePath(),s.stroke()}else u(this.canvasContext,a.x,a.y,r.x,r.y)}};a.prototype.resetCanvas=function(t,n){var e=this.canvas,r=this.settings,a=this.canvasContext,s=this.isCanvasEmulator,o=e.width,h=e.height;if(n||a.clearRect(0,0,o+30,h+30),a.shadowColor=a.fillStyle=r["background-color"],s&&a.fillRect(0,0,o+30,h+30),a.lineWidth=Math.ceil(parseInt(r.lineWidth,10)),a.lineCap=a.lineJoin="round",r.signatureLine){if(null!=r["decor-color"]){a.strokeStyle=r["decor-color"],a.shadowOffsetX=0,a.shadowOffsetY=0;var g=Math.round(h/5);u(a,1.5*g,h-g,o-1.5*g,h-g)}s||(a.shadowColor=a.strokeStyle,a.shadowOffsetX=.5*a.lineWidth,a.shadowOffsetY=-.6*a.lineWidth,a.shadowBlur=0)}return a.strokeStyle=r.color,t||(t=[]),a=this.dataEngine=new i(t,this,c,l,d),r.data=t,$(e).data("jSignature.data",t).data("jSignature.settings",r),a.changed=function(t,n,e){return function(){n.publish(e+".change"),t.trigger("change")}}(this.$parent,this.events,"jSignature"),a.changed(),!0},a.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,padding:0,border:"none",height:"ratio"!==t.height&&t.height?t.height.toString(10):1,width:"ratio"!==t.width&&t.width?t.width.toString(10):1,"-ms-touch-action":"none","touch-action":"none","background-color":t["background-color"]}),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("jSignature"),n.width=e.width(),n.height=e.height(),this.isCanvasEmulator=s(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,r=this;i.onload=function(){var t=r.getContext("2d"),n=t.shadowColor;t.shadowColor="transparent",t.drawImage(i,0,0,i.width<r.width?i.width:r.width,i.height<r.height?i.height:r.height),t.shadowColor=n},i.src="data:"+n+","+t}function e(t,n){return this.find("canvas.jSignature").add(this.filter("canvas.jSignature")).data("jSignature.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.jSignature").add(this.filter("canvas.jSignature"));if(!u.hasOwnProperty(n))throw Error("jSignature is unable to find import plugin with for format '"+String(n)+"'");return 0!==e.length&&u[n].call(e[0],t,n,function(t){return function(){return t.resetCanvas.apply(t,arguments)}}(e.data("jSignature.this"))),this}}var r=new h;!function(t,n,e,i){var r,a=function(){t.publish(n+".parentresized")};e(i).bind("resize."+n,function(){r&&clearTimeout(r),r=setTimeout(a,500)}).bind("mouseup."+n,function(e){t.publish(n+".windowmouseup")})}(r,"jSignature",$,t);var s={},o={"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[]}},u={"native":function(t,n,e){e(t)},image:n,"image/png;base64":n,"image/jpeg;base64":n,"image/jpg;base64":n},c=function(t){var n=!1;for(t=t.parentNode;t&&!n;)n=t.body,t=t.parentNode;return!n},l={"export":o,"import":u,instance:s},d={init:function(t){return this.each(function(){c(this)||new a(this,t,s)})},destroy:function(){return this.each(function(){if(!c(this)){var t=$(this).find("canvas").data("jSignature.this");if(t){t.$controlbarLower.remove(),t.$controlbarUpper.remove(),$(t.canvas).remove();for(var n in t.eventTokens)t.eventTokens.hasOwnProperty(n)&&r.unsubscribe(t.eventTokens[n])}}})},getSettings:function(){return this.find("canvas.jSignature").add(this.filter("canvas.jSignature")).data("jSignature.this").settings},isModified:function(){return null!==this.find("canvas.jSignature").add(this.filter("canvas.jSignature")).data("jSignature.this").dataEngine._stroke},updateSetting:function(t,n,e){var i=this.find("canvas.jSignature").add(this.filter("canvas.jSignature")).data("jSignature.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.jSignature").add(this.filter("canvas.jSignature"));if(void 0===t&&(t="default"),0!==n.length&&o.hasOwnProperty(t))return o[t].call(n.get(0),n.data("jSignature.data"),n.data("jSignature.settings"))},importData:i,setData:i,globalEvents:function(){return r},disable:function(){this.find("input").attr("disabled",1),this.find("canvas.jSignature").addClass("disabled").data("jSignature.this").settings.readOnly=!0},enable:function(){this.find("input").removeAttr("disabled"),this.find("canvas.jSignature").removeClass("disabled").data("jSignature.this").settings.readOnly=!1},events:function(){return this.find("canvas.jSignature").add(this.filter("canvas.jSignature")).data("jSignature.this").events}};$.fn.jSignature=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.jSignature"):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,r=i-1;-1<r;r--)t[e[r]]=e[r+i],n[e[r+i]]=e[r];var a=function(n){n=n.split("");for(var e=n.length,i=1;i<e;i++)n[i]=t[n[i]];return n.join("")},s=function(t){for(var n,e,r=[],s=0,o=1,h=t.length,u=0;u<h;u++)n=Math.round(t[u]),e=n-s,s=n,0>e&&0<o?(o=-1,r.push("Z")):0<e&&0>o&&(o=1,r.push("Y")),n=Math.abs(e),n>=i?r.push(a(n.toString(i))):r.push(n.toString(i));return r.join("")},o=function(e){var r=[];e=e.split("");for(var a,s=e.length,o=1,h=[],u=0,c=0;c<s;c++)a=e[c],a in t||"Z"===a||"Y"===a?(0!==h.length&&(h=parseInt(h.join(""),i)*o+u,r.push(h),u=h),"Z"===a?(o=-1,h=[]):"Y"===a?(o=1,h=[]):h=[a]):h.push(n[a]);return r.push(parseInt(h.join(""),i)*o+u),r},h=function(t){for(var n,e=[],i=t.length,r=0;r<i;r++)n=t[r],e.push(s(n.x)),e.push(s(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:o(t[2*i]),y:o(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:a,compressstrokeleg:s,uncompressstrokeleg:o,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*=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,r,a){r+=1;var s=new n(i.x[r-1],i.y[r-1]),o=new n(i.x[r],i.y[r]);o=s.getVectorToPoint(o);var h=new n(i.x[r-2],i.y[r-2]);return s=h.getVectorToPoint(s),s.getLength()>a?(a=2<r?new n(i.x[r-3],i.y[r-3]).getVectorToPoint(h):new t(0,0),i=.35*s.getLength(),h=s.angleTo(a.reverse()),r=o.angleTo(s.reverse()),a=new t(a.x+s.x,a.y+s.y).resizeTo(Math.max(.05,h)*i),o=new t(s.x+o.x,s.y+o.y).reverse().resizeTo(Math.max(.05,r)*i),o=new t(s.x+o.x,s.y+o.y),["c",e(a.x,2),e(a.y,2),e(o.x,2),e(o.y,2),e(s.x,2),e(s.y,2)]):["l",e(s.x,2),e(s.y,2)]}function r(i,r){var a=i.x.length-1,s=new n(i.x[a],i.y[a]),o=new n(i.x[a-1],i.y[a-1]);if(s=o.getVectorToPoint(s),1<a&&s.getLength()>r){a=new n(i.x[a-2],i.y[a-2]).getVectorToPoint(o),o=s.angleTo(a.reverse());var h=.35*s.getLength();return a=new t(a.x+s.x,a.y+s.y).resizeTo(Math.max(.05,o)*h),["c",e(a.x,2),e(a.y,2),e(s.x,2),e(s.y,2),e(s.x,2),e(s.y,2)]}return["l",e(s.x,2),e(s.y,2)]}function a(t,n,a){n=["M",e(t.x[0]-n,2),e(t.y[0]-a,2)],a=1;for(var s=t.x.length-1;a<s;a++)n.push.apply(n,i(t,a,1));return 0<s?n.push.apply(n,r(t,a,1)):0===s&&n.push.apply(n,["l",1,1]),n.join(" ")}function s(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 r=e[i][1],a=e[i][2];n.push(e[i][0]+'="'+(r in t&&t[r]?t[r]:a)+'"')}return n.join(" ")}function o(t,n){var e,i,r=['<?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">'],o=t.length,h=[],u=[],c=i=e=0,l=0,d=[];if(0!==o){for(e=0;e<o;e++){i=t[e];var g=[],f={x:[],y:[]};for(l=0,c=i.x.length;l<c;l++)g.push({x:i.x[l],y:i.y[l]});for(g=simplify(g,.7,!0),l=0,c=g.length;l<c;l++)f.x.push(g[l].x),f.y.push(g[l].y);i=f,d.push(i),h=h.concat(i.x),u=u.concat(i.y)}o=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>o?0:o,l=0>h?0:h,e-=o,i=u-h}for(r.push('<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="'+e.toString()+'" height="'+i.toString()+'">'),e=0,o=d.length;e<o;e++)i=d[e],r.push("<path "+s(n)+' d="'+a(i,c,l)+'"/>');return r.push("</svg>"),r.join("")}function h(t,n){return["image/svg+xml",o(t,n)]}function u(t,n){return["image/svg+xml;base64",c(o(t,n))]}if(function(t,n){"use strict";t.simplify=function(t,e,i){if(e=e!==n?e*e:1,!i){var r=t.length,a=t[0],s=[a];for(i=1;i<r;i++){var o=t[i],h=o.x-a.x,u=o.y-a.y;h*h+u*u>e&&(s.push(o),a=o)}a!==o&&s.push(o),t=s}o=t,i=o.length,r=new(typeof Uint8Array!=n+""?Uint8Array:Array)(i),a=0,s=i-1;var c,l=[],d=[],g=[];for(r[a]=r[s]=1;s;){for(u=0,h=a+1;h<s;h++){var f=o[h],p=o[a],v=o[s],y=p.x,x=p.y;p=v.x-y;var m=v.y-x;if(0!==p||0!==m){var w=((f.x-y)*p+(f.y-x)*m)/(p*p+m*m);1<w?(y=v.x,x=v.y):0<w&&(y+=p*w,x+=m*w)}p=f.x-y,m=f.y-x,f=p*p+m*m,f>u&&(c=h,u=f)}u>e&&(r[c]=1,l.push(a),d.push(c),l.push(c),d.push(s)),a=l.pop(),s=d.pop()}for(h=0;h<i;h++)r[h]&&g.push(o[h]);return t=g}}(window),"function"!=typeof c)var c=function(t){var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".split(""),e=0,i=0,r=[];do{var a=t.charCodeAt(e++),s=t.charCodeAt(e++),o=t.charCodeAt(e++),h=a<<16|s<<8|o;a=h>>18&63,s=h>>12&63,o=h>>6&63,h&=63,r[i++]=n[a]+n[s]+n[o]+n[h]}while(e<t.length);return n=r.join(""),t=t.length%3,(t?n.slice(0,t-3):n)+"===".slice(t||3)};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","image/svg+xml",h),t("addPlugin","export","svgbase64",u),t("addPlugin","export","image/svg+xml;base64",u)}($)}();
//# sourceMappingURL=jSignature.min.js.map