Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/captaincodeman/svelte-signature-pad

Capture smoothed signatures as SVG paths in Svelte
https://github.com/captaincodeman/svelte-signature-pad

signature signature-pad

Last synced: about 1 month ago
JSON representation

Capture smoothed signatures as SVG paths in Svelte

Awesome Lists containing this project

README

        

# svelte-signature-pad

Svelte Action to capture smoothed signatures as SVG paths using the excellent [perfect-freehand](https://github.com/steveruizok/perfect-freehand) library.

## Instructions

Install using you package manager of choice:

pnpm i svelte-signature-pad

Import action into page and pass and object with `ondraw` and `oncomplete` method properties.

Each will receive a path which can be rendered as SVG in your component. `ondraw` fires _while the user is drawing_ and would be the current stroke. `oncomplete` fires when they have finished the line (which could transition to a different color).

## Example

```svelte

import { signature } from 'svelte-signature-pad'

let layers: { path: string; width: number; height: number }[] = []

let width: number
let height: number
let preview: string

const ondraw = (path: string) => (preview = path)
const oncomplete = (path: string) => {
preview = ''
layers = [...layers, { width, height, path }]
}

const clear = () => {
layers = []
}



false}
>
{#each layers as layer}



{/each}

{#if preview}



{/if}


Clear

Please sign on the dotted line to indicate that you agree to all the legal terms we all know you didn't read. Thank you!


{#each layers as layer}



{/each}

```