Signature
A handwritten signature canvas component: a unified canvas 2d form across platforms. Pointer/touch events are normalized to canvas coordinates by toSignaturePoint in @lh-ui/share/core/signature, then incrementally drawn by drawSmoothSegment (quadratic Bézier midpoint interpolation over every three adjacent points), with no polyline artifacts. Undo works on a stack of stroke snapshots (LhSignatureStroke[]); on pop, redrawSnapshot redraws. Supports an eraser, a baseline guide, background color, a disabled state and an empty-state hint.
Basic Usage
<script setup lang="ts">
import { ref } from 'vue'
import { LhSignature } from '@lh-ui/vue3'
const signatureRef = ref<InstanceType<typeof LhSignature>>()
function handleExport() {
const dataUrl = signatureRef.value?.toDataURL('image/png')
console.log(dataUrl)
}
</script>
<template>
<LhSignature ref="signatureRef" @end="handleExport" />
</template>Pen color / line width / background color / guide line
When penColor is not passed, it falls back to the token's dark color (canvas cannot resolve CSS variables, so the --lh-text-primary token fallback #1D2129 is used); once backgroundColor is set, the canvas is filled with that color and the exported bitmap carries the background; guideline draws a baseline dashed line at 2/3 of the canvas height:
<LhSignature pen-color="#D9393B" :line-width="4" />
<LhSignature background-color="#F5F5F5" guideline :height="160" />Eraser and undo
eraser enables the eraser mode: when backgroundColor is not set, it erases through instantly with the destination-out composite mode; when backgroundColor is set, it redraws with the background color covering the strokes (both implementations register in the snapshot, so an undo pops and reverts them synchronously). disabled disables drawing (adds the --disabled modifier; the stylesheet cuts off pointer events):
<LhSignature eraser />Method calls (defineExpose on the ref): toDataURL(type, quality) exports a bitmap, clear() clears the canvas, undo() reverts the last stroke, and isEmpty() checks for emptiness (the snapshot is empty, or all pixels are the background color).
API
Signature Props
| Prop | Description | Type | Default |
|---|---|---|---|
| penColor | Pen color (falls back to the token's dark color when not passed) | string | — |
| lineWidth | Line width in px | number | 3 |
| backgroundColor | Background color (when set, the canvas is filled with that color and the eraser redraws with the background color) | string | — |
| disabled | Disable drawing | boolean | false |
| guideline | Guide line (a baseline dashed line at 2/3 of the canvas height) | boolean | false |
| height | Canvas height in px | number | 200 |
| eraser | Eraser mode (destination-out erasing; when backgroundColor is set, redraws with the background color) | boolean | false |
| sx | sx quick-layout props | LhSxProps | — |
Signature Events
| Event | Description | Callback |
|---|---|---|
| start | A stroke starts (pointerdown) | — |
| signing | Drawing in progress (pointermove), carrying the normalized stroke point | (point: LhSignaturePoint) |
| end | A stroke ends (pointerup / pointercancel) | — |
Signature Methods (defineExpose)
| Method | Description | Parameters |
|---|---|---|
| toDataURL | Export a canvas bitmap (a canvas.toDataURL wrapper) | (type?: string, quality?: number) => string |
| clear | Clear the snapshot and the canvas (redraws the background / guide line together) | — |
| undo | Revert the last stroke (snapshot pop + redraw) | — |
| isEmpty | Whether the canvas is empty (the snapshot is empty or all pixels are the background color) | () => boolean |
Accessibility
The root node is role="img" with the fixed accessible name "Signature canvas"; the empty-state hint (__placeholder) has pointer-events: none and aria-hidden, so it does not interfere with drawing.

