Skip to content

Commit 6d0ea0b

Browse files
committed
v0.1.1 - drop copyCanvas dependency
- copyCanvas depended on createCanvas, which uses node-gyp and other dependencies to create, which is wildly unnecessary for this - added 4 lines of code to do this instead - also have example's css make the trimmed image have a white background color so it's more noticeable (and resembles the drawing canvas) - didn't know you could use both a background-image and a background-color on the same element o.o
1 parent ef0483e commit 6d0ea0b

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

example/styles.cssm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ body {
3333
background-size: 200px 50px;
3434
width: 200px;
3535
height: 50px;
36+
background-color: white;
3637
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-signature-canvas",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "A signature pad implementation in React",
55
"main": "build/index.js",
66
"scripts": {
@@ -45,7 +45,6 @@
4545
"react-dom": "^0.14.0 || ^15.0.0"
4646
},
4747
"dependencies": {
48-
"copy-canvas": "^1.0.0",
4948
"trim-canvas": "^0.1.0"
5049
}
5150
}

src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { Component, PropTypes } from 'react'
2-
import copyCanvas from 'copy-canvas'
32
import trimCanvas from 'trim-canvas'
43

54
import Bezier from './bezier.js'
@@ -73,7 +72,13 @@ export default class SignatureCanvas extends Component {
7372

7473
// return a trimmed copy of the canvas
7574
getTrimmedCanvas = () => {
76-
return trimCanvas(copyCanvas(this._canvas))
75+
// copy the canvas
76+
let copy = document.createElement('canvas')
77+
copy.width = this._canvas.width
78+
copy.height = this._canvas.height
79+
copy.getContext('2d').drawImage(this._canvas, 0, 0)
80+
// then trim it
81+
return trimCanvas(copy)
7782
}
7883

7984
isEmpty = () => this._isEmpty

0 commit comments

Comments
 (0)