Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
react-canvas-draw
Advanced tools
Changelog
[1.2.1] - 2021-11-08
Readme
A simple yet powerful canvas-drawing component for React (Demo)
Install via NPM:
npm install react-canvas-draw --save
or YARN:
yarn add react-canvas-draw
import React from "react";
import ReactDOM from "react-dom";
import CanvasDraw from "react-canvas-draw";
ReactDOM.render(<CanvasDraw />, document.getElementById("root"));
For more examples, like saving and loading a drawing ==> look into the /demo/src
folder.
These are the defaultProps of CanvasDraw. You can pass along any of these props to customize the CanvasDraw component. Examples of how to use the props are also shown in the /demo/src
folder.
static defaultProps = {
onChange: null
loadTimeOffset: 5,
lazyRadius: 30,
brushRadius: 12,
brushColor: "#444",
catenaryColor: "#0a0302",
gridColor: "rgba(150,150,150,0.17)",
hideGrid: false,
canvasWidth: 400,
canvasHeight: 400,
disabled: false,
imgSrc: "",
saveData: null,
immediateLoading: false,
hideInterface: false,
gridSizeX: 25,
gridSizeY: 25,
gridLineWidth: 0.5,
hideGridX: false,
hideGridY: false
enablePanAndZoom: false,
mouseZoomFactor: 0.01,
zoomExtents: { min: 0.33, max: 3 },
};
Useful functions that you can call, e.g. when having a reference to this component:
getSaveData()
returns the drawing's save-data as a stringified objectloadSaveData(saveData: String, immediate: Boolean)
loads a previously saved drawing using the saveData string, as well as an optional boolean flag to load it immediately, instead of live-drawing it.getDataURL(fileType, useBgImage, backgroundColour)
will export the canvas to a data URL, which can subsequently be used to share or manipulate the image file.clear()
clears the canvas completely, including previously erased lines, and resets the view. After a clear, undo()
will have no effect.eraseAll()
clears the drawn lines but retains their data; calling undo()
can restore the erased lines. Note: erased lines are not included in the save data.resetView()
resets the canvas' view to defaults. Has no effect if the enablePanAndZoom
property is false
.undo()
removes the latest change to the drawing. This includes everything drawn since the last MouseDown event.This repo was kickstarted by nwb's awesome react-component starter.
You just need to clone it, yarn it & start it!
If you want to save large strings, like the stringified JSON of a drawing, I recommend you use pieroxy/lz-string for compression. It's LZ compression will bring down your long strings to only ~10% of its original size.
The lazy-brush project as well as its demo app by dulnan have been a heavy influence.
I borrowed a lot of the logic and actually used lazy-brush during the push to v1 of react-canvas-draw. Without it, react-canvas-draw would most likely still be pre v1 and wouldn't feel as good.
Thanks goes to these wonderful people (emoji key):
Martin Beierling-Mutz 💻 📖 💡 🤔 | Jan Hug 🤔 |
---|
This project follows the all-contributors specification. Contributions of any kind welcome!
MIT, see LICENSE for details.
FAQs
A simple yet powerful canvas-drawing component for React.
The npm package react-canvas-draw receives a total of 16,094 weekly downloads. As such, react-canvas-draw popularity was classified as popular.
We found that react-canvas-draw demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.