signature_pad.min.js 9.4 KB

123456789101112131415161718192021
  1. var $jscomp={scope:{}};$jscomp.defineProperty="function"==typeof Object.defineProperties?Object.defineProperty:function(d,g,b){if(b.get||b.set)throw new TypeError("ES3 does not support getters and setters.");d!=Array.prototype&&d!=Object.prototype&&(d[g]=b.value)};$jscomp.getGlobal=function(d){return"undefined"!=typeof window&&window===d?d:"undefined"!=typeof global?global:d};$jscomp.global=$jscomp.getGlobal(this);
  2. $jscomp.polyfill=function(d,g,b,f){if(g){b=$jscomp.global;d=d.split(".");for(f=0;f<d.length-1;f++){var n=d[f];n in b||(b[n]={});b=b[n]}d=d[d.length-1];f=b[d];g=g(f);g!=f&&null!=g&&$jscomp.defineProperty(b,d,{configurable:!0,writable:!0,value:g})}};$jscomp.polyfill("Array.prototype.fill",function(d){return d?d:function(d,b,f){var g=this.length||0;0>b&&(b=Math.max(0,g+b));if(null==f||f>g)f=g;f=Number(f);0>f&&(f=Math.max(0,g+f));for(b=Number(b||0);b<f;b++)this[b]=d;return this}},"es6-impl","es3");
  3. (function(d,g){"function"===typeof define&&define.amd?define([],function(){return d.SignaturePad=g()}):"object"===typeof exports?module.exports=g():d.SignaturePad=g()})(this,function(){function d(d){var b=[];this.push=function(f){if(null==f)return!1;null==d||isNaN(d)||b.length==d&&this.pop();b.unshift(f);return!0};this.pop=function(){return b.pop()};this.size=function(){return b.length};this.quere=function(){return b}}return function(g){var b=function(a,c){var e=this,b=c||{};this.velocityFilterWeight=
  4. b.velocityFilterWeight||.7;this.minWidth=b.minWidth||.5;this.maxWidth=b.maxWidth||2.5;this.dotSize=b.dotSize||function(){return(this.minWidth+this.maxWidth)/2};this.penColor=b.penColor||"black";this.backgroundColor=b.backgroundColor||"rgba(0,0,0,0)";this.onEnd=b.onEnd;this.onBegin=b.onBegin;this._canvas=a;this._ctx=a.getContext("2d");this._ctx.lineJoin="round";this._ctx.lineCap="round";this.count=0;this.clear();this.ptQueue=new d(6);this.testTimer=function(){};this.funcCompleteListener=function(){for(var a=
  5. e.maxWidth;0<e.ptQueue.size();){console.log(a+"----"+e.ptQueue.size());var c=e.ptQueue.pop();this.curPos=c;e._drawLine(a);this.oldPos=c;a-=a/10}};this._handleMouseDown=function(a){1===a.which&&(e._mouseButtonDown=!0,e._strokeBegin(a))};this._handleMouseMove=function(a){e._mouseButtonDown&&e._strokeUpdate(a)};this._handleMouseUp=function(a){1===a.which&&e._mouseButtonDown&&(e._mouseButtonDown=!1,e._strokeEnd(a))};this._handleTouchStart=function(a){1==a.targetTouches.length&&e._strokeBegin(a.changedTouches[0])};
  6. this._handleTouchMove=function(a){a.preventDefault();e._strokeUpdate(a.targetTouches[0])};this._handleTouchEnd=function(a){a.target===e._canvas&&(a.preventDefault(),e._strokeEnd(a))};this._handleTouchCancel=function(a){a.target===e._canvas&&(a.preventDefault(),e._strokeEnd(a))};this._handleMouseEvents();this._handleTouchEvents()};b.prototype.simulate_mouseevent=function(a,c){if(void 0!==a&&null!==a)if(g.all)a.fireEvent("on"+c);else{var e=g.createEvent("MouseEvents");e.initEvent(c,!0,!0);a.dispatchEvent(e)}};
  7. b.prototype.clear=function(){var a=this._ctx,c=this._canvas;a.fillStyle=this.backgroundColor;a.clearRect(0,0,c.width,c.height);a.fillRect(0,0,c.width,c.height);this._reset()};b.prototype.toDataURL=function(a,c){var e=this._canvas;return e.toDataURL.apply(e,arguments)};b.prototype.fromDataURL=function(a){var c=this,e=new Image,b=window.devicePixelRatio||1,d=this._canvas.width/b,l=this._canvas.height/b;this._reset();e.src=a;e.onload=function(){c._ctx.drawImage(e,0,0,d,l)};this._isEmpty=!1};b.prototype._strokeUpdate=
  8. function(a){a=this._createPoint(a);this._ctx.fillStyle=this.penColor;this._ctx.strokeStyle=this.penColor;this.curPos=a;this._drawLine();this.oldPos=this.curPos};b.prototype._strokeBegin=function(a){for(this._reset();0<this.ptQueue.size();)this.ptQueue.pop();this.oldPos=this._createPoint(a);self.oldPos=self.curPos;this.penPress=0;this.LstTrans=.1;this.LstSize=0;this._ctx.fillStyle=this.penColor;this._ctx.strokeStyle=this.penColor;this.count=0;if("function"===typeof this.onBegin)this.onBegin(a)};b.prototype._strokeDraw=
  9. function(a){var c=this._ctx,e="function"===typeof this.dotSize?this.dotSize():this.dotSize;c.beginPath();this._drawPoint(a.x,a.y,e);c.closePath();c.fill()};b.prototype._strokeEnd=function(a){this.penPress=0;this.oldPos=this.curPos;if("function"===typeof this.onEnd)this.onEnd(a)};b.prototype._handleMouseEvents=function(){this._mouseButtonDown=!1;this._canvas.addEventListener("mousedown",this._handleMouseDown);this._canvas.addEventListener("mousemove",this._handleMouseMove);g.addEventListener("mouseup",
  10. this._handleMouseUp)};b.prototype._handleTouchEvents=function(){this._canvas.style.msTouchAction="none";this._canvas.style.touchAction="none";this._canvas.addEventListener("touchstart",this._handleTouchStart);this._canvas.addEventListener("touchmove",this._handleTouchMove);this._canvas.addEventListener("touchend",this._handleTouchEnd);this._canvas.addEventListener("touchcancel",this._handleTouchCancel)};b.prototype.on=function(){this._handleMouseEvents();this._handleTouchEvents()};b.prototype.off=
  11. function(){this._canvas.removeEventListener("mousedown",this._handleMouseDown);this._canvas.removeEventListener("mousemove",this._handleMouseMove);g.removeEventListener("mouseup",this._handleMouseUp);this._canvas.removeEventListener("touchstart",this._handleTouchStart);this._canvas.removeEventListener("touchmove",this._handleTouchMove);this._canvas.removeEventListener("touchend",this._handleTouchEnd);this._canvas.removeEventListener("touchcancel",this._handleTouchCancel)};b.prototype.isEmpty=function(){return this._isEmpty};
  12. b.prototype._reset=function(){this.points=[];this._lastVelocity=0;this._lastWidth=(this.minWidth+this.maxWidth)/2;this._isEmpty=!0;this._ctx.fillStyle=this.penColor};b.prototype._createPoint=function(a){var c=this._canvas.getBoundingClientRect();return new f(a.clientX-c.left,a.clientY-c.top)};b.prototype._addPoint=function(a){var c=this.points,e;c.push(a);2<c.length&&(3===c.length&&c.unshift(c[0]),e=this._calculateCurveControlPoints(c[0],c[1],c[2]),a=e.c2,e=this._calculateCurveControlPoints(c[1],
  13. c[2],c[3]),e=e.c1,a=new n(c[1],a,e,c[2]),this._addCurve(a),c.shift())};b.prototype._calculateCurveControlPoints=function(a,c,e){var b=a.x-c.x,d=a.y-c.y,l=c.x-e.x,g=c.y-e.y,t=(a.x+c.x)/2;a=(a.y+c.y)/2;var m=(c.x+e.x)/2;e=(c.y+e.y)/2;l=Math.sqrt(l*l+g*g);d=l/(Math.sqrt(b*b+d*d)+l);b=c.x-(m+(t-m)*d);c=c.y-(e+(a-e)*d);return{c1:new f(t+b,a+c),c2:new f(m+b,e+c)}};b.prototype._addCurve=function(a){var c,e;c=a.endPoint.velocityFrom(a.startPoint);c=this.velocityFilterWeight*c+(1-this.velocityFilterWeight)*
  14. this._lastVelocity;e=this._strokeWidth(c);this._drawCurve(a,this._lastWidth,e);this._lastVelocity=c;this._lastWidth=e};b.prototype._drawPoint=function(a,c,e){var b=this._ctx;b.moveTo(a,c);b.arc(a,c,e,0,2*Math.PI,!1);this._isEmpty=!1};b.prototype._drawCurve=function(a,c,e){var b=this._ctx;e-=c;var d,l,f,g,m,q,r,k,h;d=Math.floor(a.length());b.beginPath();for(f=0;f<d;f++)l=f/d,g=l*l,m=g*l,q=1-l,r=q*q,k=r*q,h=k*a.startPoint.x,h+=3*r*l*a.control1.x,h+=3*q*g*a.control2.x,h+=m*a.endPoint.x,k*=a.startPoint.y,
  15. k+=3*r*l*a.control1.y,k+=3*q*g*a.control2.y,k+=m*a.endPoint.y,l=c+m*e,this._drawPoint(h,k,l);b.closePath();b.fill()};b.prototype._drawLine=function(a){var c,b,d,f,g,n,t,m,q,r,k,h,p,u,v,w,x;b=a||this.maxWidth;0==this.curPos.x-this.oldPos.x&&(this.curPos.x+=.1);0==this.curPos.y-this.oldPos.y&&(this.curPos.y+=.1);a=this.curPos.x-this.oldPos.x;c=this.curPos.y-this.oldPos.y;this.penPress=Math.round(this.penPress+(Math.max((1024-5*Math.pow(a*a+c*c,.5))/10,5)-this.penPress)/3);c=this.penPress/100;a=1*c;
  16. b=c*b*2;1<a?a=1:.2>a&&(a=.2);c=this.curPos.x-this.oldPos.x;d=this.curPos.y-this.oldPos.y;f=b-this.LstSize;g=a-this.LstTrans;if(Math.abs(c)>=Math.abs(d)&&0<Math.abs(c))for(k=Math.abs(c),p=0<c?1:-1,n=d/k,t=f/k,m=g/k,w=this.oldPos.x,x=this.oldPos.y,h=0;h<=k;h++)u=this.oldPos.x+p*h,v=this.oldPos.y+n*h,q=this.LstSize+t*h,r=this.LstTrans+m*h,this._ctx.globalAlpha=Math.max(r,.85),this._ctx.lineWidth=Math.max(q,1),this._ctx.beginPath(),this._ctx.moveTo(Math.round(w-.1*p),Math.round(x-.1*p)),this._ctx.lineTo(Math.round(u+
  17. .1*p),Math.round(v+.1*p)),this._ctx.stroke(),this._ctx.closePath(),w=u,x=v;if(Math.abs(d)>=Math.abs(c)&&0<Math.abs(d))for(k=Math.abs(d),p=0<d?1:-1,n=c/k,t=f/k,m=g/k,w=this.oldPos.x,x=this.oldPos.y,h=0;h<=k;h++)u=this.oldPos.x+n*h,v=this.oldPos.y+p*h,q=this.LstSize+t*h,r=this.LstTrans+m*h,this._ctx.globalAlpha=Math.max(r,.85),this._ctx.lineWidth=Math.max(q,1),this._ctx.beginPath(),this._ctx.moveTo(Math.round(w-.1*p),Math.round(x-.1*p)),this._ctx.lineTo(Math.round(u+.1*p),Math.round(v+.1*p)),this._ctx.stroke(),
  18. this._ctx.closePath(),w=u,x=v;this.LstTrans=a;this.LstSize=b};b.prototype._strokeWidth=function(a){return Math.max(this.maxWidth/(a+1),this.minWidth)};var f=function(a,c,b){this.x=a;this.y=c;this.time=b||(new Date).getTime()};f.prototype.velocityFrom=function(a){return this.time!==a.time?this.distanceTo(a)/(this.time-a.time):1};f.prototype.distanceTo=function(a){return Math.sqrt(Math.pow(this.x-a.x,2)+Math.pow(this.y-a.y,2))};var n=function(a,c,b,d){this.startPoint=a;this.control1=c;this.control2=
  19. b;this.endPoint=d};n.prototype.length=function(){var a=0,c,b,d,f,g;for(c=0;10>=c;c++)b=c/10,d=this._point(b,this.startPoint.x,this.control1.x,this.control2.x,this.endPoint.x),b=this._point(b,this.startPoint.y,this.control1.y,this.control2.y,this.endPoint.y),0<c&&(f=d-f,g=b-g,a+=Math.sqrt(f*f+g*g)),f=d,g=b;return a};n.prototype._point=function(a,b,d,f,g){return b*(1-a)*(1-a)*(1-a)+3*d*(1-a)*(1-a)*a+3*f*(1-a)*a*a+g*a*a*a};return b}(document)});
  20. // V1.0.0.310
  21. //# sourceMappingURL=c:/signature_pad.min.map