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

@paintable/core

v0.4.5

Published

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

Downloads

27

Readme

@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/Key | Method | Type | Description | Default | Required | | --------- | -------------- | ----------------- | --------------------------------------- | --------- | -------- | | scope | setScope() | string | A unqiue "scope" name for your painting | paintable | - | | color | setColor() | string | Drawing color | #000000 | - | | accuracy | setAccuracy() | number | Line accuracy. higher = better curves | 4 | - | | lineWidth | setLineWidth() | number | Size of line | 5 | - | | threshold | setThreshold() | number | Distance after line starts | 0 | - | | factor | setFactor() | number | Sacling factor | 1 | - | | isEraser | setEraser() | boolean | Indicator if eraser is active | false | - | | isActive | setActive() | boolean | Indicator if paint is activated | false | - | | canvas | setCanvas() | HTMLCanvasElement | The canvas element | null | x |

Instance methods to handle the canvas

| Method | Description | Only | Only if isActive is true | | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---- | ---------------------------- | | undo() | Undo step | | x | | redo() | Redo step | | x | | cancel() | Cancel draw | | x | | save() | Save the current image | | x | | 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