0.4.5 • Published 3 years ago

@paintable/core v0.4.5

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

@paintable/core

This is the core module. And you can use it inside your webpage, if you want

Demo: https://paintable-core.vercel.app (npm run vercel-build)

npm install @paintable/core

How to use

Import library:

import { Paintable } from '@paintable/core';

or load from a CDN

<script src="https://cdn.jsdelivr.net/npm/@paintable/core"></script>

and create an instance with

const paintable = new Paintable(/*
  OPTIONS { scope: 'the-name' }
*/);

First of all, you need to know all about the properties and methods of the paintable instance.

Instance properities

These are the properties of the paintable. You can pass them initially as an object to the constructor or/and set them with an appropriate method. For example if you want to set the canvas asynchronously.

Value/KeyMethodTypeDescriptionDefaultRequired
scopesetScope()stringA unqiue "scope" name for your paintingpaintable-
colorsetColor()stringDrawing color#000000-
accuracysetAccuracy()numberLine accuracy. higher = better curves4-
lineWidthsetLineWidth()numberSize of line5-
thresholdsetThreshold()numberDistance after line starts0-
factorsetFactor()numberSacling factor1-
isErasersetEraser()booleanIndicator if eraser is activefalse-
isActivesetActive()booleanIndicator if paint is activatedfalse-
canvassetCanvas()HTMLCanvasElementThe canvas elementnullx

Instance methods to handle the canvas

MethodDescriptionOnlyOnly if isActive is true
undo()Undo stepx
redo()Redo stepx
cancel()Cancel drawx
save()Save the current imagex
clear(keepHistory = false, force = false)You can set a keepHistory to true if you want to keep everything previously painted in history. Set force to true, to clear everything no matter if it is active or not/

Example

This is the smallest example. It uses a CDN to load the library.

<!DOCTYPE html>
<html lang="en">
  <body>
    <canvas id="canvas" height="500" width="500"></canvas><br />

    <script src="https://cdn.jsdelivr.net/npm/@paintable/core"></script>
    <script>
      // create instance
      const paintable = new Paintable();

      // set the canvas element
      paintable.setCanvas(document.querySelector('#canvas'));

      // activate paintable
      paintable.setActive(true);

      // OR with initial values --------------

      // create instance
      const paintable = new Paintable({
        // used to identify the paintable
        scope: 'a-unique-identifier',
        // set the canvas element
        canvas: document.querySelector('#canvas'),
        color: '#000000',
        active: true
        accuracy: 6
      });
    </script>
  </body>
</html>

Overwrite methods

You can simply overwrite methods of the paintable, if you want. Some methods you may want to override: moveEvent, startEvent and stopEvent

const paintable = new Paintable();

// the old event
const moveEvent = paintable.moveEvent;

// overwrite it
paintable.moveEvent = function () {
  // call old event to ensure functionality
  moveEvent.apply(this, arguments);

  // your code
};

Development

npm run install
npm run serve
0.4.5

3 years ago

0.4.4

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago