1.0.2 • Published 3 years ago

vue-drawable-kanvas v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

vue-drawable-canvas

VueJS Component - drawable 'object-based' canvas

Vue3.

Install

yarn add vue-drawable-canvas

Usage

To test - clone repo and run:

yarn serve

To use (See the playground folder for a working demo):

<!-- MyComponent.vue -->

<template>
  <VueDrawableCanvas
    ref="canvas"
  />
</template>

<script>
import VueDrawingCanvas from 'vue-drawing-canvas';

export default {
  name: 'MyComponent',
  components: {
    VueDrawingCanvas,
  },
};
</script>

The component have these modes of usage:

String
draw
erase
move

The component can draw these shapes:

String
pencil
circle
rectangle
triangle
text
background

The given mode and shape are set by props.

Canvas shapes are erased or moved by selecting the appropriate mode then clicking and/or dragging the shape.

Props

NameTypeDefault valueDescription
widthNumber800The canvas width
heightNumber600The canvas height
fontString3rem ArialThe font size and type
lineWidthNumber5The width of the stroke
strokeStyleString#000000The color of the stroke
fillStyleStringtransparentThe color of the fill. Note: also sets the text color
backgroundColorStringtransparentThe background color
backgroundImageString''The background image
stretchBackgroundImageBooleanfalseStretces the background image to fit the canvas
shapestringstringThe shape to be drawn
modestringstringThe canvas mode
devicePixelRatioBooleantrueAdjust the canavs resolution based on the devicePixelRatio

Emits

EventDataDescription
mousedownMouseEvent, CoordinateEmits the mouse event and the coordinate relative to the canvas where the mouse was clicked
targetCoordinateIf mouse click or drag is above an object on the canvas the coordinates realtive to the canvas is emitted

Methods

Method nameParametersReturn valueDescription
clear-voidClear the canvas and the undo/redo history
undo-void-
redo-void-
savescaleNumberreturns blob
drawText(coordinate, text)voidAdds text to the canvas. The coordinate is the top left coordinate where the text will be placed. (Text is rendered with textBaseline 'top')

License

MIT