A reusable digital signature pad component for Vue.js and vanilla JavaScript
npm install @visionary-studio/numeric-signaturebash
npm install @visionary-studio/numeric-signature
`
$3
`vue
:width="600"
:height="300"
@end="handleSignature"
/>
`
$3
`vue
:width="800"
:height="400"
color="#0066cc"
background-color="#f8f9fa"
:line-width="3"
:show-controls="true"
:show-color-picker="true"
:show-line-width="true"
:show-export="true"
:colors="['#000000', '#0066cc', '#ff0000', '#008000']"
:line-widths="[1, 2, 3, 4, 5]"
@start="onStart"
@draw="onDraw"
@end="onEnd"
@change="onChange"
/>
`
๐ API Reference
$3
| Prop | Type | Default | Description |
|------|------|---------|-------------|
| width | number | 400 | Canvas width in pixels |
| height | number | 200 | Canvas height in pixels |
| color | string | '#000000' | Stroke color |
| backgroundColor | string | '#ffffff' | Canvas background |
| lineWidth | number | 2 | Stroke thickness |
| smoothing | number | 0.5 | Stroke smoothing (0-1) |
| pressure | boolean | false | Enable pressure sensitivity |
| showControls | boolean | true | Show control buttons |
| showGrid | boolean | false | Show background grid |
| showColorPicker | boolean | true | Show color selection |
| showLineWidth | boolean | true | Show line width options |
| showExport | boolean | true | Show export buttons |
| colors | string[] | ['#000000', '#0000ff', '#ff0000', '#008000'] | Available colors |
| lineWidths | number[] | [1, 2, 3, 4] | Available line widths |
| texts | object | See below | Custom button labels |
$3
`typescript
interface TextLabels {
clear?: string; // Default: 'Clear'
undo?: string; // Default: 'Undo'
color?: string; // Default: 'Color'
lineWidth?: string; // Default: 'Line Width'
export?: string; // Default: 'Export'
}
`
$3
| Event | Payload | Description |
|-------|---------|-------------|
| start | SignaturePoint | Drawing started |
| draw | SignaturePoint | Drawing in progress |
| end | SignatureData | Drawing completed |
| change | SignatureData \| null | Signature data changed |
| clear | - | Canvas cleared |
$3
`vue
`
| Method | Return | Description |
|--------|--------|-------------|
| clear() | void | Clear the canvas |
| undo() | void | Remove last stroke |
| getData() | SignatureData \| null | Get signature data |
| setData(data) | void | Set signature data |
| toDataURL(format?, quality?) | string | Export as data URL |
| toBlob(format?, quality?) | Promise | Export as blob |
$3
| Property | Type | Description |
|----------|------|-------------|
| isEmpty | boolean | Canvas is empty |
| isDrawing | boolean | Currently drawing |
| signatureData | SignatureData \| null | Current signature data |
๐ Data Types
$3
`typescript
interface SignatureData {
strokes: SignatureStroke[]
width: number
height: number
backgroundColor: string
timestamp: number
}
`
$3
`typescript
interface SignatureStroke {
points: SignaturePoint[]
color: string
width: number
timestamp: number
}
`
$3
`typescript
interface SignaturePoint {
x: number
y: number
pressure?: number
timestamp?: number
}
`
๐ฏ Use Cases
$3
`vue
Contract Agreement
Please sign below to confirm:
:width="600"
:height="200"
@end="saveContractSignature"
/>
`
$3
`vue
:width="350"
:height="150"
:show-controls="false"
:show-export="false"
@end="captureMobileSignature"
/>
`
$3
`vue
Verify Your Identity
Draw your signature to continue:
:width="400"
:height="200"
color="#0066cc"
@end="verifySignature"
/>
`
๐ ๏ธ Integration Examples
$3
`typescript
// stores/signature.js
import { defineStore } from 'pinia'
export const useSignatureStore = defineStore('signature', {
state: () => ({
signatures: []
}),
actions: {
addSignature(data) {
this.signatures.push({
id: Date.now(),
data,
timestamp: new Date().toISOString()
})
}
}
})
`
$3
`vue
`
$3
`vue
`
๐จ Customization
$3
`css
.signature-canvas {
--signature-border-color: #e5e7eb;
--signature-focus-color: #3b82f6;
--signature-background: #ffffff;
}
`
$3
`vue
`
๐งช Testing
The library includes comprehensive tests:
`bash
Run all tests
npm test
Run tests with UI
npm run test:ui
Run tests with coverage
npm run test:coverage
`
$3
- โ
Canvas drawing functionality
- โ
Touch and mouse events
- โ
Export/import operations
- โ
Data validation
- โ
Vue component integration
- โ
Composable behavior
๐ฆ Build & Distribution
`bash
Build for development
npm run dev
Build library for distribution
npm run build-lib
Build demo application
npm run build
Type checking
npm run type-check
`
๐ง Development
$3
`
src/
โโโ components/
โ โโโ SignaturePad.vue # Main Vue component
โโโ composables/
โ โโโ useSignature.ts # Vue composable
โโโ utils/
โ โโโ signature-canvas.ts # Canvas logic
โ โโโ signature-utils.ts # Utility functions
โโโ types/
โ โโโ signature.ts # TypeScript types
โโโ App.vue # Demo application
โโโ main.ts # Entry point
โโโ index.ts # Library exports
``