Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

usb-paint

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

usb-paint

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.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
120
increased by62.16%
Maintainers
0
Weekly downloads
 
Created
Source

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

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

ParameterRequiredTypeDefaultDescription
targetNoHTMLElementbody elementTarget container, can be a DOM element or CSS selector
lineOptionsNoLineOptionsType(Details below)Configuration for brush line
showToolsNobooleanfalseShow toolbar or not
toolsConfigNoToolsConfigType(Details below)Toolbar configuration when showTools is true
backgroundNostring-Transparent by default; accepts Hex/RGB/HSL/HSB/color names (e.g., red)

Secondary Parameters

LineOptionsType

ParameterRequiredTypeDefaultDescription
lineWidthNonumber4Brush line width
lineColorNostring#000Brush line color; accepts Hex/RGB/HSL/HSB/color names
lineAlphaNonumber1Brush line opacity
lineSmoothNonumber1Softness of the brush line edges
lineThinNonumber0.6Brush pressure's effect on stroke size
lineStreamNonumber1Degree of stroke simplification
lineStartNonumber0–100Tapering at the start of the line
lineEndNonumber0–100Tapering options at the end of the line

ToolsConfigType

ParameterRequiredTypeDefaultDescription
toolsNostring/ arrayallToolbar tools; accepts any combination of ["eraser", "paint", "trash", "export"]; "[]" hides toolbar, "all" shows all
positionNostring/AxisTypetopToolbar position; accepts "left"/"right"/"top"/"bottom" or AxisType position data (detailed below)
iconsConfigNoobject-Icon configuration for the toolbar
backgroudNoobject-Background configuration for the toolbar

Tertiary Parameters

toolsConfig.position (AxisType)

ParameterRequiredTypeDefaultDescription
xYesnumber-Horizontal coordinate (px)
yYesnumber-Vertical coordinate (px)
directionYesstring-Arrangement direction: row/column

toolsConfig.iconsConfig

ParameterRequiredTypeDefaultDescription
sizeNonumber20Icon size (px)
widthNonumber1.25Icon line width
colorNostring#000Icon line color; accepts Hex/RGB/HSL/HSB/color names
fillNostringnoneIcon fill color; accepts Hex/RGB/HSL/HSB/color names, "none" for no fill by default

toolsConfig.background

ParameterRequiredTypeDefaultDescription
colorNostring#fffBackground color; accepts Hex/RGB/HSL/HSB/color names
borderNostring1px solid rgba(0,0,0,0.1)Border (CSS format)
radiusNonumber10Border radius

Event Triggers

Event NameDescriptionReturn Data
exportToImageExport image database64
eraserToolEraser-
freeDrawToolDrawing-
clearToolClear-

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();

Keywords

FAQs

Package last updated on 07 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc