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 2.0.0 to 2.1.0-beta.1

src/throttle.js

3

CHANGELOG.md
## Changelog
### 2.1.0-beta.1
* Added throttling. (@kunukn in #237)
### 2.0.0

@@ -3,0 +6,0 @@ Unfortunately, some breaking changes were introduced in 1.6.0, so to follow the semantic versioning, it's re-released as 2.0.0.

/*!
* Signature Pad v2.0.0
* Signature Pad v2.1.0-beta.1
* https://github.com/szimek/signature_pad

@@ -74,2 +74,37 @@ *

/* eslint-disable */
// http://stackoverflow.com/a/27078401/815507
function throttle(func, wait, options) {
var context, args, result;
var timeout = null;
var previous = 0;
if (!options) options = {};
var later = function later() {
previous = options.leading === false ? 0 : Date.now();
timeout = null;
result = func.apply(context, args);
if (!timeout) context = args = null;
};
return function () {
var now = Date.now();
if (!previous && options.leading === false) previous = now;
var remaining = wait - (now - previous);
context = this;
args = arguments;
if (remaining <= 0 || remaining > wait) {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
previous = now;
result = func.apply(context, args);
if (!timeout) context = args = null;
} else if (!timeout && options.trailing !== false) {
timeout = setTimeout(later, remaining);
}
return result;
};
}
function SignaturePad(canvas, options) {

@@ -82,2 +117,10 @@ var self = this;

this.maxWidth = opts.maxWidth || 2.5;
this.throttle = opts.throttle || 16; // in miliseconds
if (this.throttle) {
this._strokeMoveUpdate = throttle(SignaturePad.prototype._strokeUpdate, this.throttle);
} else {
this._strokeMoveUpdate = SignaturePad.prototype._strokeUpdate;
}
this.dotSize = opts.dotSize || function () {

@@ -106,3 +149,3 @@ return (this.minWidth + this.maxWidth) / 2;

if (self._mouseButtonDown) {
self._strokeUpdate(event);
self._strokeMoveUpdate(event);
}

@@ -130,3 +173,3 @@ };

var touch = event.targetTouches[0];
self._strokeUpdate(touch);
self._strokeMoveUpdate(touch);
};

@@ -133,0 +176,0 @@

2

dist/signature_pad.min.js

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.SignaturePad=e()}(this,function(){"use strict";function t(t,e,i){this.x=t,this.y=e,this.time=i||(new Date).getTime()}function e(t,e,i,o){this.startPoint=t,this.control1=e,this.control2=i,this.endPoint=o}function i(t,e){var i=this,o=e||{};this.velocityFilterWeight=o.velocityFilterWeight||.7,this.minWidth=o.minWidth||.5,this.maxWidth=o.maxWidth||2.5,this.dotSize=o.dotSize||function(){return(this.minWidth+this.maxWidth)/2},this.penColor=o.penColor||"black",this.backgroundColor=o.backgroundColor||"rgba(0,0,0,0)",this.onBegin=o.onBegin,this.onEnd=o.onEnd,this._canvas=t,this._ctx=t.getContext("2d"),this.clear(),this._handleMouseDown=function(t){1===t.which&&(i._mouseButtonDown=!0,i._strokeBegin(t))},this._handleMouseMove=function(t){i._mouseButtonDown&&i._strokeUpdate(t)},this._handleMouseUp=function(t){1===t.which&&i._mouseButtonDown&&(i._mouseButtonDown=!1,i._strokeEnd(t))},this._handleTouchStart=function(t){if(1===t.targetTouches.length){var e=t.changedTouches[0];i._strokeBegin(e)}},this._handleTouchMove=function(t){t.preventDefault();var e=t.targetTouches[0];i._strokeUpdate(e)},this._handleTouchEnd=function(t){var e=t.target===i._canvas;e&&(t.preventDefault(),i._strokeEnd(t))},this.on()}return t.prototype.velocityFrom=function(t){return this.time!==t.time?this.distanceTo(t)/(this.time-t.time):1},t.prototype.distanceTo=function(t){return Math.sqrt(Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2))},e.prototype.length=function(){for(var t=10,e=0,i=void 0,o=void 0,n=0;n<=t;n+=1){var s=n/t,r=this._point(s,this.startPoint.x,this.control1.x,this.control2.x,this.endPoint.x),h=this._point(s,this.startPoint.y,this.control1.y,this.control2.y,this.endPoint.y);if(n>0){var a=r-i,c=h-o;e+=Math.sqrt(a*a+c*c)}i=r,o=h}return e},e.prototype._point=function(t,e,i,o,n){return e*(1-t)*(1-t)*(1-t)+3*i*(1-t)*(1-t)*t+3*o*(1-t)*t*t+n*t*t*t},i.prototype.clear=function(){var t=this._ctx,e=this._canvas;t.fillStyle=this.backgroundColor,t.clearRect(0,0,e.width,e.height),t.fillRect(0,0,e.width,e.height),this._data=[],this._reset(),this._isEmpty=!0},i.prototype.fromDataURL=function(t){var e=this,i=new Image,o=window.devicePixelRatio||1,n=this._canvas.width/o,s=this._canvas.height/o;this._reset(),i.src=t,i.onload=function(){e._ctx.drawImage(i,0,0,n,s)},this._isEmpty=!1},i.prototype.toDataURL=function(t){var e;switch(t){case"image/svg+xml":return this._toSVG();default:for(var i=arguments.length,o=Array(i>1?i-1:0),n=1;n<i;n++)o[n-1]=arguments[n];return(e=this._canvas).toDataURL.apply(e,[t].concat(o))}},i.prototype.on=function(){this._handleMouseEvents(),this._handleTouchEvents()},i.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)},i.prototype.isEmpty=function(){return this._isEmpty},i.prototype._strokeBegin=function(t){this._data.push([]),this._reset(),this._strokeUpdate(t),"function"==typeof this.onBegin&&this.onBegin(t)},i.prototype._strokeUpdate=function(t){var e=t.clientX,i=t.clientY,o=this._createPoint(e,i),n=this._addPoint(o),s=n.curve,r=n.widths;s&&r&&this._drawCurve(s,r.start,r.end),this._data[this._data.length-1].push({x:o.x,y:o.y,time:o.time})},i.prototype._strokeEnd=function(t){var e=this.points.length>2,i=this.points[0];!e&&i&&this._drawDot(i),"function"==typeof this.onEnd&&this.onEnd(t)},i.prototype._handleMouseEvents=function(){this._mouseButtonDown=!1,this._canvas.addEventListener("mousedown",this._handleMouseDown),this._canvas.addEventListener("mousemove",this._handleMouseMove),document.addEventListener("mouseup",this._handleMouseUp)},i.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)},i.prototype._reset=function(){this.points=[],this._lastVelocity=0,this._lastWidth=(this.minWidth+this.maxWidth)/2,this._ctx.fillStyle=this.penColor},i.prototype._createPoint=function(e,i,o){var n=this._canvas.getBoundingClientRect();return new t(e-n.left,i-n.top,o||(new Date).getTime())},i.prototype._addPoint=function(t){var i=this.points,o=void 0;if(i.push(t),i.length>2){3===i.length&&i.unshift(i[0]),o=this._calculateCurveControlPoints(i[0],i[1],i[2]);var n=o.c2;o=this._calculateCurveControlPoints(i[1],i[2],i[3]);var s=o.c1,r=new e(i[1],n,s,i[2]),h=this._calculateCurveWidths(r);return i.shift(),{curve:r,widths:h}}return{}},i.prototype._calculateCurveControlPoints=function(e,i,o){var n=e.x-i.x,s=e.y-i.y,r=i.x-o.x,h=i.y-o.y,a={x:(e.x+i.x)/2,y:(e.y+i.y)/2},c={x:(i.x+o.x)/2,y:(i.y+o.y)/2},d=Math.sqrt(n*n+s*s),u=Math.sqrt(r*r+h*h),l=a.x-c.x,v=a.y-c.y,_=u/(d+u),p={x:c.x+l*_,y:c.y+v*_},y=i.x-p.x,f=i.y-p.y;return{c1:new t(a.x+y,a.y+f),c2:new t(c.x+y,c.y+f)}},i.prototype._calculateCurveWidths=function(t){var e=t.startPoint,i=t.endPoint,o={start:null,end:null},n=this.velocityFilterWeight*i.velocityFrom(e)+(1-this.velocityFilterWeight)*this._lastVelocity,s=this._strokeWidth(n);return o.start=this._lastWidth,o.end=s,this._lastVelocity=n,this._lastWidth=s,o},i.prototype._strokeWidth=function(t){return Math.max(this.maxWidth/(t+1),this.minWidth)},i.prototype._drawPoint=function(t,e,i){var o=this._ctx;o.moveTo(t,e),o.arc(t,e,i,0,2*Math.PI,!1),this._isEmpty=!1},i.prototype._drawCurve=function(t,e,i){var o=this._ctx,n=i-e,s=Math.floor(t.length());o.beginPath();for(var r=0;r<s;r+=1){var h=r/s,a=h*h,c=a*h,d=1-h,u=d*d,l=u*d,v=l*t.startPoint.x;v+=3*u*h*t.control1.x,v+=3*d*a*t.control2.x,v+=c*t.endPoint.x;var _=l*t.startPoint.y;_+=3*u*h*t.control1.y,_+=3*d*a*t.control2.y,_+=c*t.endPoint.y;var p=e+c*n;this._drawPoint(v,_,p)}o.closePath(),o.fill()},i.prototype._drawDot=function(t){var e=this._ctx,i="function"==typeof this.dotSize?this.dotSize():this.dotSize;e.beginPath(),this._drawPoint(t.x,t.y,i),e.closePath(),e.fill()},i.prototype._fromData=function(e,i,o){for(var n=0;n<e.length;n+=1){var s=e[n];if(s.length>1)for(var r=0;r<s.length;r+=1){var h=s[r],a=new t(h.x,h.y,h.time);if(0===r)this._reset(),this._addPoint(a);else if(r!==s.length-1){var c=this._addPoint(a),d=c.curve,u=c.widths;d&&u&&i(d,u)}}else{this._reset();var l=s[0];o(l)}}},i.prototype._toSVG=function(){var t=this,e=this._data,i=this._canvas,o=Math.max(window.devicePixelRatio||1,1),n=0,s=0,r=i.width/o,h=i.height/o,a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttributeNS(null,"width",i.width),a.setAttributeNS(null,"height",i.height),this._fromData(e,function(e,i){var o=document.createElement("path");if(!(isNaN(e.control1.x)||isNaN(e.control1.y)||isNaN(e.control2.x)||isNaN(e.control2.y))){var n="M "+e.startPoint.x.toFixed(3)+","+e.startPoint.y.toFixed(3)+" "+("C "+e.control1.x.toFixed(3)+","+e.control1.y.toFixed(3)+" ")+(e.control2.x.toFixed(3)+","+e.control2.y.toFixed(3)+" ")+(e.endPoint.x.toFixed(3)+","+e.endPoint.y.toFixed(3));o.setAttribute("d",n),o.setAttribute("stroke-width",(2.25*i.end).toFixed(3)),o.setAttribute("stroke",t.penColor),o.setAttribute("fill","none"),o.setAttribute("stroke-linecap","round"),a.appendChild(o)}},function(e){var i=document.createElement("circle"),o="function"==typeof t.dotSize?t.dotSize():t.dotSize;i.setAttribute("r",o),i.setAttribute("cx",e.x),i.setAttribute("cy",e.y),i.setAttribute("fill",t.penColor),a.appendChild(i)});var c="data:image/svg+xml;base64,",d='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"'+(' viewBox="'+n+" "+s+" "+r+" "+h+'"')+(' width="'+r+'"')+(' height="'+h+'"')+">",u=a.innerHTML;if(void 0===u){var l=document.createElement("dummy"),v=a.childNodes;l.innerHTML="";for(var _=0;_<v.length;_+=1)l.appendChild(v[_].cloneNode(!0));u=l.innerHTML}var p="</svg>",y=d+u+p;return c+btoa(y)},i.prototype.fromData=function(t){var e=this;this.clear(),this._fromData(t,function(t,i){return e._drawCurve(t,i.start,i.end)},function(t){return e._drawDot(t)})},i.prototype.toData=function(){return this._data},i});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.SignaturePad=e()}(this,function(){"use strict";function t(t,e,o){this.x=t,this.y=e,this.time=o||(new Date).getTime()}function e(t,e,o,i){this.startPoint=t,this.control1=e,this.control2=o,this.endPoint=i}function o(t,e,o){var i,n,s,r=null,h=0;o||(o={});var a=function(){h=o.leading===!1?0:Date.now(),r=null,s=t.apply(i,n),r||(i=n=null)};return function(){var c=Date.now();h||o.leading!==!1||(h=c);var u=e-(c-h);return i=this,n=arguments,u<=0||u>e?(r&&(clearTimeout(r),r=null),h=c,s=t.apply(i,n),r||(i=n=null)):r||o.trailing===!1||(r=setTimeout(a,u)),s}}function i(t,e){var n=this,s=e||{};this.velocityFilterWeight=s.velocityFilterWeight||.7,this.minWidth=s.minWidth||.5,this.maxWidth=s.maxWidth||2.5,this.throttle=s.throttle||16,this.throttle?this._strokeMoveUpdate=o(i.prototype._strokeUpdate,this.throttle):this._strokeMoveUpdate=i.prototype._strokeUpdate,this.dotSize=s.dotSize||function(){return(this.minWidth+this.maxWidth)/2},this.penColor=s.penColor||"black",this.backgroundColor=s.backgroundColor||"rgba(0,0,0,0)",this.onBegin=s.onBegin,this.onEnd=s.onEnd,this._canvas=t,this._ctx=t.getContext("2d"),this.clear(),this._handleMouseDown=function(t){1===t.which&&(n._mouseButtonDown=!0,n._strokeBegin(t))},this._handleMouseMove=function(t){n._mouseButtonDown&&n._strokeMoveUpdate(t)},this._handleMouseUp=function(t){1===t.which&&n._mouseButtonDown&&(n._mouseButtonDown=!1,n._strokeEnd(t))},this._handleTouchStart=function(t){if(1===t.targetTouches.length){var e=t.changedTouches[0];n._strokeBegin(e)}},this._handleTouchMove=function(t){t.preventDefault();var e=t.targetTouches[0];n._strokeMoveUpdate(e)},this._handleTouchEnd=function(t){var e=t.target===n._canvas;e&&(t.preventDefault(),n._strokeEnd(t))},this.on()}return t.prototype.velocityFrom=function(t){return this.time!==t.time?this.distanceTo(t)/(this.time-t.time):1},t.prototype.distanceTo=function(t){return Math.sqrt(Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2))},e.prototype.length=function(){for(var t=10,e=0,o=void 0,i=void 0,n=0;n<=t;n+=1){var s=n/t,r=this._point(s,this.startPoint.x,this.control1.x,this.control2.x,this.endPoint.x),h=this._point(s,this.startPoint.y,this.control1.y,this.control2.y,this.endPoint.y);if(n>0){var a=r-o,c=h-i;e+=Math.sqrt(a*a+c*c)}o=r,i=h}return e},e.prototype._point=function(t,e,o,i,n){return e*(1-t)*(1-t)*(1-t)+3*o*(1-t)*(1-t)*t+3*i*(1-t)*t*t+n*t*t*t},i.prototype.clear=function(){var t=this._ctx,e=this._canvas;t.fillStyle=this.backgroundColor,t.clearRect(0,0,e.width,e.height),t.fillRect(0,0,e.width,e.height),this._data=[],this._reset(),this._isEmpty=!0},i.prototype.fromDataURL=function(t){var e=this,o=new Image,i=window.devicePixelRatio||1,n=this._canvas.width/i,s=this._canvas.height/i;this._reset(),o.src=t,o.onload=function(){e._ctx.drawImage(o,0,0,n,s)},this._isEmpty=!1},i.prototype.toDataURL=function(t){var e;switch(t){case"image/svg+xml":return this._toSVG();default:for(var o=arguments.length,i=Array(o>1?o-1:0),n=1;n<o;n++)i[n-1]=arguments[n];return(e=this._canvas).toDataURL.apply(e,[t].concat(i))}},i.prototype.on=function(){this._handleMouseEvents(),this._handleTouchEvents()},i.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)},i.prototype.isEmpty=function(){return this._isEmpty},i.prototype._strokeBegin=function(t){this._data.push([]),this._reset(),this._strokeUpdate(t),"function"==typeof this.onBegin&&this.onBegin(t)},i.prototype._strokeUpdate=function(t){var e=t.clientX,o=t.clientY,i=this._createPoint(e,o),n=this._addPoint(i),s=n.curve,r=n.widths;s&&r&&this._drawCurve(s,r.start,r.end),this._data[this._data.length-1].push({x:i.x,y:i.y,time:i.time})},i.prototype._strokeEnd=function(t){var e=this.points.length>2,o=this.points[0];!e&&o&&this._drawDot(o),"function"==typeof this.onEnd&&this.onEnd(t)},i.prototype._handleMouseEvents=function(){this._mouseButtonDown=!1,this._canvas.addEventListener("mousedown",this._handleMouseDown),this._canvas.addEventListener("mousemove",this._handleMouseMove),document.addEventListener("mouseup",this._handleMouseUp)},i.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)},i.prototype._reset=function(){this.points=[],this._lastVelocity=0,this._lastWidth=(this.minWidth+this.maxWidth)/2,this._ctx.fillStyle=this.penColor},i.prototype._createPoint=function(e,o,i){var n=this._canvas.getBoundingClientRect();return new t(e-n.left,o-n.top,i||(new Date).getTime())},i.prototype._addPoint=function(t){var o=this.points,i=void 0;if(o.push(t),o.length>2){3===o.length&&o.unshift(o[0]),i=this._calculateCurveControlPoints(o[0],o[1],o[2]);var n=i.c2;i=this._calculateCurveControlPoints(o[1],o[2],o[3]);var s=i.c1,r=new e(o[1],n,s,o[2]),h=this._calculateCurveWidths(r);return o.shift(),{curve:r,widths:h}}return{}},i.prototype._calculateCurveControlPoints=function(e,o,i){var n=e.x-o.x,s=e.y-o.y,r=o.x-i.x,h=o.y-i.y,a={x:(e.x+o.x)/2,y:(e.y+o.y)/2},c={x:(o.x+i.x)/2,y:(o.y+i.y)/2},u=Math.sqrt(n*n+s*s),d=Math.sqrt(r*r+h*h),l=a.x-c.x,v=a.y-c.y,p=d/(u+d),_={x:c.x+l*p,y:c.y+v*p},y=o.x-_.x,f=o.y-_.y;return{c1:new t(a.x+y,a.y+f),c2:new t(c.x+y,c.y+f)}},i.prototype._calculateCurveWidths=function(t){var e=t.startPoint,o=t.endPoint,i={start:null,end:null},n=this.velocityFilterWeight*o.velocityFrom(e)+(1-this.velocityFilterWeight)*this._lastVelocity,s=this._strokeWidth(n);return i.start=this._lastWidth,i.end=s,this._lastVelocity=n,this._lastWidth=s,i},i.prototype._strokeWidth=function(t){return Math.max(this.maxWidth/(t+1),this.minWidth)},i.prototype._drawPoint=function(t,e,o){var i=this._ctx;i.moveTo(t,e),i.arc(t,e,o,0,2*Math.PI,!1),this._isEmpty=!1},i.prototype._drawCurve=function(t,e,o){var i=this._ctx,n=o-e,s=Math.floor(t.length());i.beginPath();for(var r=0;r<s;r+=1){var h=r/s,a=h*h,c=a*h,u=1-h,d=u*u,l=d*u,v=l*t.startPoint.x;v+=3*d*h*t.control1.x,v+=3*u*a*t.control2.x,v+=c*t.endPoint.x;var p=l*t.startPoint.y;p+=3*d*h*t.control1.y,p+=3*u*a*t.control2.y,p+=c*t.endPoint.y;var _=e+c*n;this._drawPoint(v,p,_)}i.closePath(),i.fill()},i.prototype._drawDot=function(t){var e=this._ctx,o="function"==typeof this.dotSize?this.dotSize():this.dotSize;e.beginPath(),this._drawPoint(t.x,t.y,o),e.closePath(),e.fill()},i.prototype._fromData=function(e,o,i){for(var n=0;n<e.length;n+=1){var s=e[n];if(s.length>1)for(var r=0;r<s.length;r+=1){var h=s[r],a=new t(h.x,h.y,h.time);if(0===r)this._reset(),this._addPoint(a);else if(r!==s.length-1){var c=this._addPoint(a),u=c.curve,d=c.widths;u&&d&&o(u,d)}}else{this._reset();var l=s[0];i(l)}}},i.prototype._toSVG=function(){var t=this,e=this._data,o=this._canvas,i=Math.max(window.devicePixelRatio||1,1),n=0,s=0,r=o.width/i,h=o.height/i,a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttributeNS(null,"width",o.width),a.setAttributeNS(null,"height",o.height),this._fromData(e,function(e,o){var i=document.createElement("path");if(!(isNaN(e.control1.x)||isNaN(e.control1.y)||isNaN(e.control2.x)||isNaN(e.control2.y))){var n="M "+e.startPoint.x.toFixed(3)+","+e.startPoint.y.toFixed(3)+" "+("C "+e.control1.x.toFixed(3)+","+e.control1.y.toFixed(3)+" ")+(e.control2.x.toFixed(3)+","+e.control2.y.toFixed(3)+" ")+(e.endPoint.x.toFixed(3)+","+e.endPoint.y.toFixed(3));i.setAttribute("d",n),i.setAttribute("stroke-width",(2.25*o.end).toFixed(3)),i.setAttribute("stroke",t.penColor),i.setAttribute("fill","none"),i.setAttribute("stroke-linecap","round"),a.appendChild(i)}},function(e){var o=document.createElement("circle"),i="function"==typeof t.dotSize?t.dotSize():t.dotSize;o.setAttribute("r",i),o.setAttribute("cx",e.x),o.setAttribute("cy",e.y),o.setAttribute("fill",t.penColor),a.appendChild(o)});var c="data:image/svg+xml;base64,",u='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"'+(' viewBox="'+n+" "+s+" "+r+" "+h+'"')+(' width="'+r+'"')+(' height="'+h+'"')+">",d=a.innerHTML;if(void 0===d){var l=document.createElement("dummy"),v=a.childNodes;l.innerHTML="";for(var p=0;p<v.length;p+=1)l.appendChild(v[p].cloneNode(!0));d=l.innerHTML}var _="</svg>",y=u+d+_;return c+btoa(y)},i.prototype.fromData=function(t){var e=this;this.clear(),this._fromData(t,function(t,o){return e._drawCurve(t,o.start,o.end)},function(t){return e._drawDot(t)})},i.prototype.toData=function(){return this._data},i});
/*!
* Signature Pad v2.0.0
* Signature Pad v2.1.0-beta.1
* https://github.com/szimek/signature_pad

@@ -74,2 +74,37 @@ *

/* eslint-disable */
// http://stackoverflow.com/a/27078401/815507
function throttle(func, wait, options) {
var context, args, result;
var timeout = null;
var previous = 0;
if (!options) options = {};
var later = function later() {
previous = options.leading === false ? 0 : Date.now();
timeout = null;
result = func.apply(context, args);
if (!timeout) context = args = null;
};
return function () {
var now = Date.now();
if (!previous && options.leading === false) previous = now;
var remaining = wait - (now - previous);
context = this;
args = arguments;
if (remaining <= 0 || remaining > wait) {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
previous = now;
result = func.apply(context, args);
if (!timeout) context = args = null;
} else if (!timeout && options.trailing !== false) {
timeout = setTimeout(later, remaining);
}
return result;
};
}
function SignaturePad(canvas, options) {

@@ -82,2 +117,10 @@ var self = this;

this.maxWidth = opts.maxWidth || 2.5;
this.throttle = opts.throttle || 16; // in miliseconds
if (this.throttle) {
this._strokeMoveUpdate = throttle(SignaturePad.prototype._strokeUpdate, this.throttle);
} else {
this._strokeMoveUpdate = SignaturePad.prototype._strokeUpdate;
}
this.dotSize = opts.dotSize || function () {

@@ -106,3 +149,3 @@ return (this.minWidth + this.maxWidth) / 2;

if (self._mouseButtonDown) {
self._strokeUpdate(event);
self._strokeMoveUpdate(event);
}

@@ -130,3 +173,3 @@ };

var touch = event.targetTouches[0];
self._strokeUpdate(touch);
self._strokeMoveUpdate(touch);
};

@@ -133,0 +176,0 @@

{
"name": "signature_pad",
"description": "Library for drawing smooth signatures.",
"version": "2.0.0",
"version": "2.1.0-beta.1",
"homepage": "https://github.com/szimek/signature_pad",

@@ -6,0 +6,0 @@ "author": {

@@ -78,2 +78,4 @@ # Signature Pad [![npm](https://d25lcipzij17d.cloudfront.net/badge.svg?id=js&type=6&v=2.0.0&x2=0)](https://www.npmjs.com/package/signature_pad) [![Code Climate](https://codeclimate.com/github/szimek/signature_pad.png)](https://codeclimate.com/github/szimek/signature_pad)

<dd>(float) Maximum width of a line. Defaults to <code>2.5</code>.</dd>
<dt>throttle</dt>
<dd>(integer) Draw the next point at most once per every <code>x</code> milliseconds. Set it to <code>0</code> to turn off throttling. Defaults to <code>16</code>.</dd>
<dt>backgroundColor</dt>

@@ -80,0 +82,0 @@ <dd>(string) Color used to clear the background. Can be any color format accepted by <code>context.fillStyle</code>. Defaults to <code>"rgba(0,0,0,0)"</code> (transparent black). Use a non-transparent color e.g. <code>"rgb(255,255,255)"</code> (opaque white) if you'd like to save signatures as JPEG images.</dd>

import Point from './point';
import Bezier from './bezier';
import throttle from './throttle';

@@ -11,2 +12,10 @@ function SignaturePad(canvas, options) {

this.maxWidth = opts.maxWidth || 2.5;
this.throttle = opts.throttle || 16; // in miliseconds
if (this.throttle) {
this._strokeMoveUpdate = throttle(SignaturePad.prototype._strokeUpdate, this.throttle);
} else {
this._strokeMoveUpdate = SignaturePad.prototype._strokeUpdate;
}
this.dotSize = opts.dotSize || function () {

@@ -35,3 +44,3 @@ return (this.minWidth + this.maxWidth) / 2;

if (self._mouseButtonDown) {
self._strokeUpdate(event);
self._strokeMoveUpdate(event);
}

@@ -59,3 +68,3 @@ };

const touch = event.targetTouches[0];
self._strokeUpdate(touch);
self._strokeMoveUpdate(touch);
};

@@ -62,0 +71,0 @@

Sorry, the diff of this file is not supported yet

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