npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

canvas-drawing

v1.0.6

Published

a easy to use canvas-drawing lib 🎨

Downloads

19

Readme

canvas-drawing

a easy to use drawing board lib 🎨

  • 0 dependencies
  • Modern browser compatibility

Installing

Using npm:

npm install canvas-drawing

Using yarn:

yarn add canvas-drawing

Using script tag

<script src="your_path/dist/canvas-drawing.min.js"></script>

Play

live example

or

git clone this repository then open example/index.html in your browser

example1

example1

Usage

Initialize

<script type="text/javascript" src="//{you path to the dist file}/dist/canvas-drawing.min.js"></script>
<style>.container { width: 500px; height: 500px; }</style>
<div class="container"></div>
// More options are available in the following documents
const options = {
  container: document.getElementsByClassName('container')[0]
}
/*
  A canvas has 2 sizes, the dimension of the pixels in the canvas and the display size. 
  canvas's dimension of the pixels is (devicePixelRatio * canvas's display size) by default.
  canvas's display size equals container's size (width/height)
*/  
const draw = new canvasDrawing(options); 

Options

| Options | Type | Default value | Description | | :------------------ | :----------------: | :---------------------: | :-------------------------------------------- | | container | HtmlDom (required) | / | Container for canvas | | bgImg | String | Empty string | Canvas background Image's url, if you needed. | | canvasBgColor | String | #fff | Canvas background Color | | lineColor | String | #f00 | Color of brush | | lineWidth | String / Number | 1 | Width of brush | | arrowSize | String / Number | 15 | Size of arrows | | eraserSize | String / Number | 10 | Size of eraser | | textFontSize | String / Number | 16 | Font size of the textArea | | textLineHeight | String / Number | 20 | Font lineheight of the textArea | | textColor | String | #f00 | Font color of the textArea | | textareaPlaceholder | String | Type here... | Textarea's placeholder | | ratio | Nubmer | window.devicePixelRatio | Affects the quality of the picture |

APIs

| Method | Arguments | Description | | :--------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------- | | config( type,val ) | tpye's enum(lineColor, lineWidth, arrowSize, eraserSize, canvasBgColor, textFontSize, textLineHeight, textColor, bgImg, textareaPlaceholder, ratio) | Modifying the default configuration | | setMode( mode ) | mode's enum(pencil, straightLine, rect, circle, arrow, text, eraser) | Set current mode | | saveImg( [options] ) | default value { tpye: 'png', fileName: 'canvas_imgae' } | Save the canvas as an image, and download. | | generateBase64([type]) | default value "png" | Generate Base64 data | | undo() | / | Undo operation | | redo() | / | Redo operation | | clear() | / | Clear canvas |

Listeners

coords it will return canvas's coords (x, y) and Mouse's coords (clientX, clientY)

drawBegin
  import CanvasDrawing from 'canvas-drawing'
  const draw = new CanvasDrawing({container: Dom})
  draw.evt.on('drawBegin', function(coords) {
    console.log('begin', coords);  
  })
drawing
  draw.evt.on('drawing', function(coords) {
    console.log('drawing', coords);  
  })
drawEnd
  draw.evt.on('drawEnd', function(coords) {
    console.log('end', coords);
  })

removeListeners

  draw.evt.off('drawBegin');
  draw.evt.off('drawing');
  draw.evt.off('drawEnd');
  // or
  draw.evt.removeAllListeners();

Example

  // init
  import CanvasDrawing from 'canvas-drawing'
  const container = document.getElementsByClassName('container')[0]
  const draw = new CanvasDrawing({container: container})

  // methods
  draw.conifg('lineColor', '#FF1493')                         // Change the color of the brush.
  draw.setMode('rect')                                        // Now you can draw the rectangle.

  draw.generateBase64().then(data => console.log(data))       // generateBase64 method default is to export the PNG base64 data.                  
  draw.generateBase64('jpeg').then(data => console.log(data)) // get smaller data.              

  draw.saveImg()                                              // Save the canvas as an PNG images, and the file name is canvas_imgae.png.
  draw.saveImg({fileName: '233.png'})                         // Just Change of file name.
  draw.saveImg({tpye: 'jpeg', fileName: 'small.jpeg'})        // Sometimes we just need smaller pictures.

License

MIT