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

usb-paint

v1.0.2

Published

A universal, simple, and beautiful hand-drawn style painting tool, USB-Paint. It can be introduced and used in any front-end framework or page.

Downloads

191

Readme

English | 简体中文

USB-Paint

A universal (Universal), simple (Simple), and beautiful (Beautiful) Hand-drawn style painting tool component—USB-Paint. You can think of it as a plug-and-play drawing panel tool, like the ubiquitous USB interface, which can be quickly integrated into any frontend project (native HTML, Vue, React, Svelte, Angular).

Features

  • Universal: Supports multiple frontend frameworks, such as native HTML, Vue, React, Svelte, and Angular
  • Simple: Clean page structure with no complex styles or logic
  • Beautiful: Attractive UI design with multi-color/style options and customization support
  • Hand-drawn style
  • Supports various drawing tools, including brush, eraser, clear, and export image functions

Installation & Usage

Method 1: Using npm/yarn (Recommended)

Installation

npm install usb-paint
or
yarn add usb-paint

Usage

Note: When using it within a framework, ensure the DOM is fully loaded before accessing it. For example, in Vue, initialize it in the onMounted or later lifecycle hooks.

import USBPaint from "usb-paint";

new USBPaint({
  target: document.querySelector("#root"),
});

Method 2: Using CDN, directly inserted into HTML

<script src="https://cdn.jsdelivr.net/npm/usb-paint@latest/dist/usbpaint.iife.js" type="text/javascript"></script>
<script>
  let a = new USBPaint({
    target: document.querySelector("#root"),
  });
</script>

Parameter Details

Parameter Example

import USBPaint from "usb-paint";

new USBPaint({
  target: document.querySelector("#root"),
  lineOptions: {
    lineWidth: 8,
    lineColor: "red",
    lineAlpha: 1,
    lineSmooth: 1,
    lineThin: 0.6,
    lineStream: 1,
    lineStart: 0,
    lineEnd: 80,
  },
  showTools: true,
  toolsConfig: {
    tools: "all", // ["eraser", "paint", "trash", "export" ],
    position: {
      x: 400,
      y: 400,
      direction: "column", // column row
    },
    iconsConfig: {
      size: 20,
      width: 0.5,
      color: "red",
      fill: "black",
    },
    backgroud: {
      color: "blue",
      border: "1px solid red",
      radius: 10,
    },
  },
  background: "black",
});

Primary Parameters

| Parameter | Required | Type | Default | Description | | ----------- | -------- | --------------- | --------------- | ----------------------------------------------------------------------- | | target | No | HTMLElement | body element | Target container, can be a DOM element or CSS selector | | lineOptions | No | LineOptionsType | (Details below) | Configuration for brush line | | showTools | No | boolean | false | Show toolbar or not | | toolsConfig | No | ToolsConfigType | (Details below) | Toolbar configuration when showTools is true | | background | No | string | - | Transparent by default; accepts Hex/RGB/HSL/HSB/color names (e.g., red) |

Secondary Parameters

LineOptionsType

| Parameter | Required | Type | Default | Description | | ---------- | -------- | ------ | ------- | ----------------------------------------------------- | | lineWidth | No | number | 4 | Brush line width | | lineColor | No | string | #000 | Brush line color; accepts Hex/RGB/HSL/HSB/color names | | lineAlpha | No | number | 1 | Brush line opacity | | lineSmooth | No | number | 1 | Softness of the brush line edges | | lineThin | No | number | 0.6 | Brush pressure's effect on stroke size | | lineStream | No | number | 1 | Degree of stroke simplification | | lineStart | No | number | 0–100 | Tapering at the start of the line | | lineEnd | No | number | 0–100 | Tapering options at the end of the line |

ToolsConfigType

| Parameter | Required | Type | Default | Description | | ----------- | -------- | --------------- | ------- | --------------------------------------------------------------------------------------------------------------------- | | tools | No | string/ array | all | Toolbar tools; accepts any combination of ["eraser", "paint", "trash", "export"]; "[]" hides toolbar, "all" shows all | | position | No | string/AxisType | top | Toolbar position; accepts "left"/"right"/"top"/"bottom" or AxisType position data (detailed below) | | iconsConfig | No | object | - | Icon configuration for the toolbar | | backgroud | No | object | - | Background configuration for the toolbar |

Tertiary Parameters

toolsConfig.position (AxisType)

| Parameter | Required | Type | Default | Description | | --------- | -------- | ------ | ------- | --------------------------------- | | x | Yes | number | - | Horizontal coordinate (px) | | y | Yes | number | - | Vertical coordinate (px) | | direction | Yes | string | - | Arrangement direction: row/column |

toolsConfig.iconsConfig

| Parameter | Required | Type | Default | Description | | --------- | -------- | ------ | ------- | ----------------------------------------------------------------------------------- | | size | No | number | 20 | Icon size (px) | | width | No | number | 1.25 | Icon line width | | color | No | string | #000 | Icon line color; accepts Hex/RGB/HSL/HSB/color names | | fill | No | string | none | Icon fill color; accepts Hex/RGB/HSL/HSB/color names, "none" for no fill by default |

toolsConfig.background

| Parameter | Required | Type | Default | Description | | --------- | -------- | ------ | ------------------------- | ----------------------------------------------------- | | color | No | string | #fff | Background color; accepts Hex/RGB/HSL/HSB/color names | | border | No | string | 1px solid rgba(0,0,0,0.1) | Border (CSS format) | | radius | No | number | 10 | Border radius |

Event Triggers

| Event Name | Description | Return Data | | ------------- | ----------------- | ----------- | | exportToImage | Export image data | base64 | | eraserTool | Eraser | - | | freeDrawTool | Drawing | - | | clearTool | Clear | - |

Event Trigger Example

import USBPaint from "usb-paint";

const usbPaint = new USBPaint();
// Trigger image export
usbPaint.exportToImage();
// Activate eraser tool
usbPaint.eraserTool();
// Activate drawing tool
usbPaint.freeDrawTool();
// Clear the canvas
usbPaint.clearTool();