Signature
Signature component: canvas 2d handwriting capture (identical on web and mini-programs). Stroke smoothing (quadratic Bezier interpolation), undo snapshots, eraser mode and dataURL export all reuse the pure functions from @lh-ui/share/core/signature; the port only fetches the canvas context and normalizes touch input. Serves form signatures, handwritten confirmations and sketch annotations.
Platform differences (registered): this port uses the canvas 2d form — touch events are unified as touch (touchstart / touchmove / touchend on both H5 and mini-programs, coordinates taken from
touches[0]), normalized withtoSignaturePointagainst the canvas position and fed into share core'sdrawSmoothSegmentfor incremental smooth drawing; undo goes throughpushStroke/undoStrokesnapshots plus a fullredrawSnapshotrepaint. The canvas context is fetched via@/adapter/canvas(the same pattern as lh-qrcode / lh-chart), with dpr scaling handled by the adapter layer.
Basic usage
<template>
<lh-signature :height="200" />
</template>Pen color and line width
penColor sets the pen color and lineWidth the line width (3 by default). When penColor is omitted, the literal token fallback color is used (canvas cannot consume var(--lh-*) strings):
<lh-signature pen-color="#B87800" :line-width="5" />Background color and guideline
backgroundColor sets the canvas background (transparent when omitted); guideline enables the dashed baseline (at roughly two-thirds down the canvas, hinting the baseline area):
<lh-signature background-color="#F5F3EE" guideline />Eraser
eraser enables the eraser mode: strokes erase existing paths with the destination-out composite operation, and erase flags are recorded per stroke in the undo stack so repaints apply a second erase pass:
<lh-signature eraser />Imperative methods (via ref)
<template>
<lh-signature ref="sigRef" />
<button @click="sigRef?.clear()">Clear</button>
<button @click="sigRef?.undo()">Undo</button>
<button @click="onExport">Export</button>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import type { LhSignatureExposed } from '@lh-ui/uniapp'
const sigRef = ref<LhSignatureExposed | null>(null)
function onExport() {
const dataUrl = sigRef.value?.toDataURL('image/png') ?? ''
// upload / preview dataUrl
}
</script>Events
| Event | Description | Callback args |
|---|---|---|
| start | Pen down | (point: LhSignaturePoint) |
| signing | Pen moving (each touch point) | (point: LhSignaturePoint) |
| end | Pen up (stroke finished) | — |
LhSignaturePoint is { x: number, y: number, t?: number }; coordinates are relative to the canvas top-left corner (CSS logical pixels).
Props
| Prop | Description | Type | Default |
|---|---|---|---|
| penColor | Pen color | string | body color fallback |
| lineWidth | Line width | number | 3 |
| backgroundColor | Canvas background color | string | — (transparent) |
| disabled | Disable drawing | boolean | false |
| guideline | Guideline (dashed baseline) | boolean | false |
| height | Canvas height in px | number | 200 |
| eraser | Eraser mode | boolean | false |
| customClass | Custom class (forwarded to the root node) | string | — |
| sx | sx quick layout props | LhSxProps | — |
Methods (defineExpose)
| Method | Description | Args |
|---|---|---|
| toDataURL | Export the canvas as a dataURL | (type?: string, quality?: number) |
| clear | Clear the canvas | — |
| undo | Undo the last stroke | — |
| isEmpty | Whether the canvas is blank | — → boolean |
Accessibility
The root node carries the role="region" semantics and an aria-label ("Signature canvas" by default, "Signature canvas (disabled)" when disabled), plus aria-disabled.

