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

v-signature

v1.0.9

Published

take on-screen virtual signature

Downloads

226

Readme

v-signature

v-signature is a JavaScript library for capturing and managing digital signatures on an HTML canvas. It provides functionality to draw, clear, save, and configure signature settings.

Installation

You can install v-signature via npm.

npm install v-signature

Importing

For ES Modules

If your project uses ES Modules, you can import v-signature into your JavaScript files.

import vSignature from 'v-signature';
// ...

window.vSignature = vSignature;

For CommonJS

If your project uses CommonJS, you can require v-signature in your JavaScript files.

const vSignature = require('v-signature');
// ...
window.vSignature = vSignature;

Usage

Basic Usage

  1. Create HTML Elements

    Make sure to have an HTML input element for storing the signature data and optionally buttons for clearing and saving.

    <input type="hidden" class="signature">
  2. Initialize signature

    Initialize the vSignature class by specifying the selectors for the input, canvas, clear button, and save button. You can also provide options to configure the appearance and behavior of the signature canvas.

    document.addEventListener('DOMContentLoaded', function() {
        const signature = new vSignature('signature');
    });

Options

You can customize the appearance and behavior of the signature canvas through the options parameter when initializing the vSignature class. This allows you to adjust properties such as width, height, color, line width, background color, border, and border radius.

document.addEventListener('DOMContentLoaded', function() {
    const signature = new vSignature('signature', {
        // ...
        options: {
            width: '100%',
            height: '300px',
            color: '#000000',
            lineWidth: 2,
            backgroundColor: '#f2f2f2',
            border: '1px dashed #b3b3b3',
            borderRadius: '5px',
        }
    });
});

Manually Adding Canvas

If you prefer to manually add a canvas element instead of using the default creation, you can provide a custom selector when initializing the vSignature class to get more customization abilities.

<input type="hidden" class="signature">
<canvas class="signature_pad"></canvas>
document.addEventListener('DOMContentLoaded', function() {
    const signature = new vSignature('signature', {
        canvas: 'signature_pad',
        // ...
        options: {
            // ....
        }
    });
});

Providing Clear and Save Functionality

You can specify buttons for clearing and saving the signature. Ensure that these buttons exist in your HTML and are correctly selected when initializing the vSignature class. You can customize them as you wish.

<input type="hidden" class="signature">
<button class="signature_clear">Clear</button>
<button class="signature_save">Save</button>
document.addEventListener('DOMContentLoaded', function() {
    const signature = new vSignature('signature', {
        // ...
        clear: 'signature_clear',
        save: 'signature_save',
        options: {
            // ....
        }
    });
});

Methods

  • on(event, callback): Register an event listener for the change event, which is triggered when the signature data changes.
signature.on('change', (data) => {
    console.log('Signature changed:', data);
});
  • isEmpty(): Check if the canvas is empty. This method allows you to determine whether any signature has been drawn.
if (signature.isEmpty()) {
    console.log('Canvas is empty');
}

Events

  • change: This event is fired when the signature changes and provides the data URL of the canvas image.

License

MIT License. See the LICENSE file for more details.

Issues

If you find a bug or have a feature request, please open an issue on GitHub.

Acknowledgments

Support

If you like this project, please consider giving it a ⭐. Thanks for your support!