Socket
Socket
Sign inDemoInstall

signature_pad

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

signature_pad - npm Package Compare versions

Comparing version 1.6.0-beta.3 to 1.6.0-beta.4

example/css/signature-pad.css

2

dist/signature_pad.js
/*!
* Signature Pad v1.6.0-beta.3
* Signature Pad v1.6.0-beta.4
* https://github.com/szimek/signature_pad

@@ -4,0 +4,0 @@ *

/*!
* Signature Pad v1.6.0-beta.3 | https://github.com/szimek/signature_pad
* Signature Pad v1.6.0-beta.4 | https://github.com/szimek/signature_pad
* (c) 2017 Szymon Nowak | Released under the MIT license
*/
!function(a,b){if("function"==typeof define&&define.amd)define(["exports"],b);else if("undefined"!=typeof exports)b(exports);else{var c={exports:{}};b(c.exports),a.SignaturePad=c.exports}}(this,function(a){"use strict";function b(a,b,c){this.x=a,this.y=b,this.time=c||(new Date).getTime()}function c(a,b,c,d){this.startPoint=a,this.control1=b,this.control2=c,this.endPoint=d}function d(a,b){var c=this,d=b||{};this.velocityFilterWeight=d.velocityFilterWeight||.7,this.minWidth=d.minWidth||.5,this.maxWidth=d.maxWidth||2.5,this.dotSize=d.dotSize||function(){return(this.minWidth+this.maxWidth)/2},this.penColor=d.penColor||"black",this.backgroundColor=d.backgroundColor||"rgba(0,0,0,0)",this.onBegin=d.onBegin,this.onEnd=d.onEnd,this._canvas=a,this._ctx=a.getContext("2d"),this.clear(),this._handleMouseDown=function(a){1===a.which&&(c._mouseButtonDown=!0,c._strokeBegin(a))},this._handleMouseMove=function(a){c._mouseButtonDown&&c._strokeUpdate(a)},this._handleMouseUp=function(a){1===a.which&&c._mouseButtonDown&&(c._mouseButtonDown=!1,c._strokeEnd(a))},this._handleTouchStart=function(a){if(1===a.targetTouches.length){var b=a.changedTouches[0];c._strokeBegin(b)}},this._handleTouchMove=function(a){a.preventDefault();var b=a.targetTouches[0];c._strokeUpdate(b)},this._handleTouchEnd=function(a){var b=a.target===c._canvas;b&&(a.preventDefault(),c._strokeEnd(a))},this.on()}Object.defineProperty(a,"__esModule",{value:!0}),b.prototype.velocityFrom=function(a){return this.time!==a.time?this.distanceTo(a)/(this.time-a.time):1},b.prototype.distanceTo=function(a){return Math.sqrt(Math.pow(this.x-a.x,2)+Math.pow(this.y-a.y,2))},c.prototype.length=function(){for(var a=10,b=0,c=void 0,d=void 0,e=0;e<=a;e+=1){var f=e/a,g=this._point(f,this.startPoint.x,this.control1.x,this.control2.x,this.endPoint.x),h=this._point(f,this.startPoint.y,this.control1.y,this.control2.y,this.endPoint.y);if(e>0){var i=g-c,j=h-d;b+=Math.sqrt(i*i+j*j)}c=g,d=h}return b},c.prototype._point=function(a,b,c,d,e){return b*(1-a)*(1-a)*(1-a)+3*c*(1-a)*(1-a)*a+3*d*(1-a)*a*a+e*a*a*a},d.prototype.clear=function(){var a=this._ctx,b=this._canvas;a.fillStyle=this.backgroundColor,a.clearRect(0,0,b.width,b.height),a.fillRect(0,0,b.width,b.height),this._data=[],this._reset(),this._isEmpty=!0},d.prototype.fromDataURL=function(a){var b=this,c=new Image,d=window.devicePixelRatio||1,e=this._canvas.width/d,f=this._canvas.height/d;this._reset(),c.src=a,c.onload=function(){b._ctx.drawImage(c,0,0,e,f)},this._isEmpty=!1},d.prototype.toDataURL=function(a){var b;switch(a){case"image/svg+xml":return this._toSVG();default:for(var c=arguments.length,d=Array(c>1?c-1:0),e=1;e<c;e++)d[e-1]=arguments[e];return(b=this._canvas).toDataURL.apply(b,[a].concat(d))}},d.prototype.on=function(){this._handleMouseEvents(),this._handleTouchEvents()},d.prototype.off=function(){this._canvas.removeEventListener("mousedown",this._handleMouseDown),this._canvas.removeEventListener("mousemove",this._handleMouseMove),document.removeEventListener("mouseup",this._handleMouseUp),this._canvas.removeEventListener("touchstart",this._handleTouchStart),this._canvas.removeEventListener("touchmove",this._handleTouchMove),this._canvas.removeEventListener("touchend",this._handleTouchEnd)},d.prototype.isEmpty=function(){return this._isEmpty},d.prototype._strokeBegin=function(a){this._data.push([]),this._reset(),this._strokeUpdate(a),"function"==typeof this.onBegin&&this.onBegin(a)},d.prototype._strokeUpdate=function(a){var b=a.clientX,c=a.clientY,d=this._createPoint(b,c),e=this._addPoint(d),f=e.curve,g=e.widths;f&&g&&this._drawCurve(f,g.start,g.end),this._data[this._data.length-1].push({x:d.x,y:d.y,time:d.time})},d.prototype._strokeEnd=function(a){var b=this.points.length>2,c=this.points[0];!b&&c&&this._drawDot(c),"function"==typeof this.onEnd&&this.onEnd(a)},d.prototype._handleMouseEvents=function(){this._mouseButtonDown=!1,this._canvas.addEventListener("mousedown",this._handleMouseDown),this._canvas.addEventListener("mousemove",this._handleMouseMove),document.addEventListener("mouseup",this._handleMouseUp)},d.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)},d.prototype._reset=function(){this.points=[],this._lastVelocity=0,this._lastWidth=(this.minWidth+this.maxWidth)/2,this._ctx.fillStyle=this.penColor},d.prototype._createPoint=function(a,c,d){var e=this._canvas.getBoundingClientRect();return new b(a-e.left,c-e.top,d||(new Date).getTime())},d.prototype._addPoint=function(a){var b=this.points,d=void 0;if(b.push(a),b.length>2){3===b.length&&b.unshift(b[0]),d=this._calculateCurveControlPoints(b[0],b[1],b[2]);var e=d.c2;d=this._calculateCurveControlPoints(b[1],b[2],b[3]);var f=d.c1,g=new c(b[1],e,f,b[2]),h=this._calculateCurveWidths(g);return b.shift(),{curve:g,widths:h}}return{}},d.prototype._calculateCurveControlPoints=function(a,c,d){var e=a.x-c.x,f=a.y-c.y,g=c.x-d.x,h=c.y-d.y,i={x:(a.x+c.x)/2,y:(a.y+c.y)/2},j={x:(c.x+d.x)/2,y:(c.y+d.y)/2},k=Math.sqrt(e*e+f*f),l=Math.sqrt(g*g+h*h),m=i.x-j.x,n=i.y-j.y,o=l/(k+l),p={x:j.x+m*o,y:j.y+n*o},q=c.x-p.x,r=c.y-p.y;return{c1:new b(i.x+q,i.y+r),c2:new b(j.x+q,j.y+r)}},d.prototype._calculateCurveWidths=function(a){var b=a.startPoint,c=a.endPoint,d={start:null,end:null},e=this.velocityFilterWeight*c.velocityFrom(b)+(1-this.velocityFilterWeight)*this._lastVelocity,f=this._strokeWidth(e);return d.start=this._lastWidth,d.end=f,this._lastVelocity=e,this._lastWidth=f,d},d.prototype._strokeWidth=function(a){return Math.max(this.maxWidth/(a+1),this.minWidth)},d.prototype._drawPoint=function(a,b,c){var d=this._ctx;d.moveTo(a,b),d.arc(a,b,c,0,2*Math.PI,!1),this._isEmpty=!1},d.prototype._drawCurve=function(a,b,c){var d=this._ctx,e=c-b,f=Math.floor(a.length());d.beginPath();for(var g=0;g<f;g+=1){var h=g/f,i=h*h,j=i*h,k=1-h,l=k*k,m=l*k,n=m*a.startPoint.x;n+=3*l*h*a.control1.x,n+=3*k*i*a.control2.x,n+=j*a.endPoint.x;var o=m*a.startPoint.y;o+=3*l*h*a.control1.y,o+=3*k*i*a.control2.y,o+=j*a.endPoint.y;var p=b+j*e;this._drawPoint(n,o,p)}d.closePath(),d.fill()},d.prototype._drawDot=function(a){var b=this._ctx,c="function"==typeof this.dotSize?this.dotSize():this.dotSize;b.beginPath(),this._drawPoint(a.x,a.y,c),b.closePath(),b.fill()},d.prototype._fromData=function(a,c,d){for(var e=0;e<a.length;e+=1){var f=a[e];if(f.length>1)for(var g=0;g<f.length;g+=1){var h=f[g],i=new b(h.x,h.y,h.time);if(0===g)this._reset(),this._addPoint(i);else if(g!==f.length-1){var j=this._addPoint(i),k=j.curve,l=j.widths;k&&l&&c(k,l)}}else{this._reset();var m=f[0];d(m)}}},d.prototype._toSVG=function(){var a=this,b=this._data,c=this._canvas,d=0,e=0,f=c.width,g=c.height,h=document.createElementNS("http://www.w3.org/2000/svg","svg");h.setAttributeNS(null,"width",c.width),h.setAttributeNS(null,"height",c.height),this._fromData(b,function(b,c){var d=document.createElementNS("http;//www.w3.org/2000/svg","path");if(!(isNaN(b.control1.x)||isNaN(b.control1.y)||isNaN(b.control2.x)||isNaN(b.control2.y))){var e="M "+b.startPoint.x.toFixed(3)+","+b.startPoint.y.toFixed(3)+" "+("C "+b.control1.x.toFixed(3)+","+b.control1.y.toFixed(3)+" ")+(b.control2.x.toFixed(3)+","+b.control2.y.toFixed(3)+" ")+(b.endPoint.x.toFixed(3)+","+b.endPoint.y.toFixed(3));d.setAttribute("d",e),d.setAttributeNS(null,"stroke-width",(2.25*c.end).toFixed(3)),d.setAttributeNS(null,"stroke",a.penColor),d.setAttributeNS(null,"fill","none"),d.setAttributeNS(null,"stroke-linecap","round"),h.appendChild(d)}},function(b){var c=document.createElementNS("http://www.w3.org/2000/svg","circle"),d="function"==typeof a.dotSize?a.dotSize():a.dotSize;c.setAttributeNS(null,"r",d),c.setAttributeNS(null,"cx",b.x),c.setAttributeNS(null,"cy",b.y),c.setAttributeNS(null,"fill",a.penColor),h.appendChild(c)});var i="data:image/svg+xml;base64,",j='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="'+d+" "+e+" "+f+" "+g+'">',k=h.innerHTML,l="</svg>",m=j+k+l;return i+btoa(m)},d.prototype.fromData=function(a){var b=this;this.clear(),this._fromData(a,function(a,c){return b._drawCurve(a,c.start,c.end)},function(a){return b._drawDot(a)})},d.prototype.toData=function(){return this._data},a.default=d});
{
"name": "signature_pad",
"description": "Library for drawing smooth signatures.",
"version": "1.6.0-beta.3",
"version": "1.6.0-beta.4",
"homepage": "https://github.com/szimek/signature_pad",

@@ -15,4 +15,4 @@ "author": {

"scripts": {
"build": "grunt",
"prepublish": "npm run build && cp dist/signature_pad.js example/js/signature_pad.js"
"build": "grunt && cp dist/signature_pad.js example/js/signature_pad.js",
"prepublish": "npm run build"
},

@@ -24,3 +24,5 @@ "repository": {

"files": [
"dist"
"src",
"dist",
"example"
],

@@ -27,0 +29,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc