Socket
Socket
Sign inDemoInstall

react-canvas-draw

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-canvas-draw - npm Package Compare versions

Comparing version 0.1.6 to 0.1.7

2

es/index.js

@@ -118,2 +118,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

_this.linesArray = [];
_this.startDrawIdx = [];
};

@@ -145,3 +146,2 @@

_this.startDrawIdx.push(_this.linesArray.length);
console.log(_this.startDrawIdx);

@@ -148,0 +148,0 @@ var _this$getMousePos = _this.getMousePos(e),

@@ -127,2 +127,3 @@ "use strict";

_this.linesArray = [];
_this.startDrawIdx = [];
};

@@ -154,3 +155,2 @@

_this.startDrawIdx.push(_this.linesArray.length);
console.log(_this.startDrawIdx);

@@ -157,0 +157,0 @@ var _this$getMousePos = _this.getMousePos(e),

{
"name": "react-canvas-draw",
"version": "0.1.6",
"version": "0.1.7",
"description": "A simple yet powerful canvas-drawing component for React.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

/*!
* react-canvas-draw v0.1.5 - https://mbeierl.github.io/react-canvas-draw/
* react-canvas-draw v0.1.6 - https://mbeierl.github.io/react-canvas-draw/
* MIT Licensed

@@ -213,2 +213,3 @@ */

_this.linesArray = [];
_this.startDrawIdx = [];
};

@@ -240,3 +241,2 @@

_this.startDrawIdx.push(_this.linesArray.length);
console.log(_this.startDrawIdx);

@@ -243,0 +243,0 @@ var _this$getMousePos = _this.getMousePos(e),

/*!
* react-canvas-draw v0.1.5 - https://mbeierl.github.io/react-canvas-draw/
* react-canvas-draw v0.1.6 - https://mbeierl.github.io/react-canvas-draw/
* MIT Licensed
*/
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports.ReactCanvasDraw=e(require("react")):t.ReactCanvasDraw=e(t.React)}("undefined"!=typeof self?self:this,function(t){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){t.exports=r(1)},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),r.d(e,"default",function(){return c});var n,o,a=r(2),s=r.n(a),i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t};var c=(o=n=function(t){function e(r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var n=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.call(this,r));return n.getSaveData=function(){var t={linesArray:n.linesArray,width:n.props.canvasWidth,height:n.props.canvasHeight};return JSON.stringify(t)},n.loadSaveData=function(t,e){try{if("string"!=typeof t)throw new Error("saveData needs to be a stringified array!");var r=JSON.parse(t),o=r.linesArray,a=r.width,s=r.height;if(!o||"function"!=typeof o.push)throw new Error("linesArray needs to be an array!");if(n.clear(),a===n.props.canvasWidth&&s===n.props.canvasHeight)n.linesArray=o;else{var c=n.props.canvasWidth/a,u=n.props.canvasHeight/s,p=(c+u)/2;n.linesArray=o.map(function(t){return i({},t,{endX:t.endX*c,endY:t.endY*u,startX:t.startX*c,startY:t.startY*u,size:t.size*p})})}n.redraw(e)}catch(t){throw t}},n.redraw=function(t){n.ctx&&n.ctx.clearRect(0,0,n.props.canvasWidth,n.props.canvasHeight),n.linesArray.forEach(function(e,r){t?n.drawLine(e):window.setTimeout(function(){return n.drawLine(e)},r*n.props.loadTimeOffset)})},n.getMousePos=function(t){var e=n.canvas.getBoundingClientRect(),r=t.clientX,o=t.clientY;return t.touches&&t.touches.length>0&&(r=t.touches[0].clientX,o=t.touches[0].clientY),{x:r-e.left,y:o-e.top}},n.clear=function(){n.ctx&&n.ctx.clearRect(0,0,n.props.canvasWidth,n.props.canvasHeight),n.linesArray=[]},n.undo=function(){return n.startDrawIdx.length>0&&(n.linesArray.splice(n.startDrawIdx.pop()),n.redraw(!0),!0)},n.drawLine=function(t){n.ctx&&(n.ctx.strokeStyle=t.color,n.ctx.lineWidth=t.size,n.ctx.lineCap="round",n.ctx.beginPath(),n.ctx.moveTo(t.startX,t.startY),n.ctx.lineTo(t.endX,t.endY),n.ctx.stroke())},n.drawStart=function(t){n.isMouseDown=!0,n.startDrawIdx.push(n.linesArray.length),console.log(n.startDrawIdx);var e=n.getMousePos(t),r=e.x,o=e.y;n.x=r,n.y=o,n.draw(t)},n.drawEnd=function(){n.isMouseDown=!1},n.draw=function(t){if(n.isMouseDown){var e=n.getMousePos(t),r=e.x+1,o=e.y+1,a={color:n.props.brushColor,size:n.props.brushSize,startX:n.x,startY:n.y,endX:r,endY:o};n.drawLine(a),n.linesArray.push(a),"function"==typeof n.props.onChange&&n.props.onChange(n.linesArray),n.x=r,n.y=o}},n.isMouseDown=!1,n.linesArray=[],n.startDrawIdx=[],n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.render=function(){var t=this;return s.a.createElement("canvas",{width:this.props.canvasWidth,height:this.props.canvasHeight,style:i({display:"block",background:"#fff",touchAction:"none"},this.props.style),ref:function(e){e&&(t.canvas=e,t.ctx=e.getContext("2d"))},onMouseDown:this.drawStart,onClick:function(){return!1},onMouseUp:this.drawEnd,onMouseOut:this.drawEnd,onMouseMove:this.draw,onTouchStart:this.drawStart,onTouchMove:this.draw,onTouchEnd:this.drawEnd,onTouchCancel:this.drawEnd})},e}(a.Component),n.defaultProps={loadTimeOffset:5,brushSize:6,brushColor:"#444",canvasWidth:400,canvasHeight:400},o)},function(e,r){e.exports=t}]).default});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports.ReactCanvasDraw=e(require("react")):t.ReactCanvasDraw=e(t.React)}("undefined"!=typeof self?self:this,function(t){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){t.exports=r(1)},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),r.d(e,"default",function(){return c});var n,o,a=r(2),s=r.n(a),i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t};var c=(o=n=function(t){function e(r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var n=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.call(this,r));return n.getSaveData=function(){var t={linesArray:n.linesArray,width:n.props.canvasWidth,height:n.props.canvasHeight};return JSON.stringify(t)},n.loadSaveData=function(t,e){try{if("string"!=typeof t)throw new Error("saveData needs to be a stringified array!");var r=JSON.parse(t),o=r.linesArray,a=r.width,s=r.height;if(!o||"function"!=typeof o.push)throw new Error("linesArray needs to be an array!");if(n.clear(),a===n.props.canvasWidth&&s===n.props.canvasHeight)n.linesArray=o;else{var c=n.props.canvasWidth/a,u=n.props.canvasHeight/s,p=(c+u)/2;n.linesArray=o.map(function(t){return i({},t,{endX:t.endX*c,endY:t.endY*u,startX:t.startX*c,startY:t.startY*u,size:t.size*p})})}n.redraw(e)}catch(t){throw t}},n.redraw=function(t){n.ctx&&n.ctx.clearRect(0,0,n.props.canvasWidth,n.props.canvasHeight),n.linesArray.forEach(function(e,r){t?n.drawLine(e):window.setTimeout(function(){return n.drawLine(e)},r*n.props.loadTimeOffset)})},n.getMousePos=function(t){var e=n.canvas.getBoundingClientRect(),r=t.clientX,o=t.clientY;return t.touches&&t.touches.length>0&&(r=t.touches[0].clientX,o=t.touches[0].clientY),{x:r-e.left,y:o-e.top}},n.clear=function(){n.ctx&&n.ctx.clearRect(0,0,n.props.canvasWidth,n.props.canvasHeight),n.linesArray=[],n.startDrawIdx=[]},n.undo=function(){return n.startDrawIdx.length>0&&(n.linesArray.splice(n.startDrawIdx.pop()),n.redraw(!0),!0)},n.drawLine=function(t){n.ctx&&(n.ctx.strokeStyle=t.color,n.ctx.lineWidth=t.size,n.ctx.lineCap="round",n.ctx.beginPath(),n.ctx.moveTo(t.startX,t.startY),n.ctx.lineTo(t.endX,t.endY),n.ctx.stroke())},n.drawStart=function(t){n.isMouseDown=!0,n.startDrawIdx.push(n.linesArray.length);var e=n.getMousePos(t),r=e.x,o=e.y;n.x=r,n.y=o,n.draw(t)},n.drawEnd=function(){n.isMouseDown=!1},n.draw=function(t){if(n.isMouseDown){var e=n.getMousePos(t),r=e.x+1,o=e.y+1,a={color:n.props.brushColor,size:n.props.brushSize,startX:n.x,startY:n.y,endX:r,endY:o};n.drawLine(a),n.linesArray.push(a),"function"==typeof n.props.onChange&&n.props.onChange(n.linesArray),n.x=r,n.y=o}},n.isMouseDown=!1,n.linesArray=[],n.startDrawIdx=[],n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.render=function(){var t=this;return s.a.createElement("canvas",{width:this.props.canvasWidth,height:this.props.canvasHeight,style:i({display:"block",background:"#fff",touchAction:"none"},this.props.style),ref:function(e){e&&(t.canvas=e,t.ctx=e.getContext("2d"))},onMouseDown:this.drawStart,onClick:function(){return!1},onMouseUp:this.drawEnd,onMouseOut:this.drawEnd,onMouseMove:this.draw,onTouchStart:this.drawStart,onTouchMove:this.draw,onTouchEnd:this.drawEnd,onTouchCancel:this.drawEnd})},e}(a.Component),n.defaultProps={loadTimeOffset:5,brushSize:6,brushColor:"#444",canvasWidth:400,canvasHeight:400},o)},function(e,r){e.exports=t}]).default});
//# sourceMappingURL=react-canvas-draw.min.js.map

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