Signature 서명
손글씨 서명 캔버스 컴포넌트: canvas 2d로 모든 플랫폼에서 동일한 형태를 제공합니다. pointer/touch 이벤트는 @lh-ui/share/core/signature의 toSignaturePoint로 캔버스 좌표로 정규화된 뒤, drawSmoothSegment (인접한 세 점의 이차 베지어 중점 보간)가 증분 그리기를 수행해 시각적으로 꺾인 선이 없습니다. undo는 필적 스냅샷(LhSignatureStroke[])을 스택으로 사용하고, 꺼낸 뒤 redrawSnapshot으로 다시 그립니다. 지우개, 기준 보조선, 배경색, 비활성화 상태와 빈 상태 알림을 지원합니다.
기본 사용법
<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>펜 색상 / 선 너비 / 배경색 / 보조선
penColor는 미전달 시 토큰 대체 어두운 색을 사용합니다(canvas는 CSS 변수를 해석할 수 없어 --lh-text-primary 토큰의 대비 색 #1D2129를 사용). backgroundColor를 설정하면 캔버스를 해당 색으로 채우고 내보내는 비트맵에 배경이 포함됩니다. guideline은 캔버스 2/3 지점에 기준 점선을 그립니다:
<LhSignature pen-color="#D9393B" :line-width="4" />
<LhSignature background-color="#F5F5F5" guideline :height="160" />지우개와 실행 취소
eraser로 지우개 모드를 켭니다: backgroundColor를 설정하지 않았을 때는 destination-out 합성으로 즉시 지워지고, backgroundColor를 설정했을 때는 배경색으로 덮어서 다시 그립니다(두 구현 모두 스냅샷에 등록되어, undo 꺼내기가 동일하게 취소합니다). disabled로 그리기를 비활성화합니다 (--disabled 수식어를 추가하고 스타일시트가 포인터 이벤트를 차단):
<LhSignature eraser />메서드 호출(ref의 defineExpose): toDataURL(type, quality)로 비트맵 내보내기, clear()로 모두 지우기, undo()로 마지막 획 취소, isEmpty()로 빈 상태 판정(스냅샷이 비어 있거나 픽셀이 모두 배경색).
API
Signature Props
| 속성 | 설명 | 타입 | 기본값 |
|---|---|---|---|
| penColor | 펜 색상(미전달 시 토큰 대체 어두운 색) | string | — |
| lineWidth | 선 너비 px | number | 3 |
| backgroundColor | 배경색(설정하면 캔버스를 해당 색으로 채우고, 지우개는 배경색으로 덮어서 다시 그림) | string | — |
| disabled | 그리기 비활성화 | boolean | false |
| guideline | 보조선(기준 점선, 캔버스 2/3 지점) | boolean | false |
| height | 캔버스 높이 px | number | 200 |
| eraser | 지우개 모드(destination-out으로 지우기, backgroundColor를 설정했을 때는 배경색으로 덮어서 다시 그림) | boolean | false |
| sx | sx 빠른 레이아웃 속성 | LhSxProps | — |
Signature Events
| 이벤트 | 설명 | 콜백 매개변수 |
|---|---|---|
| start | 한 획 시작(pointerdown) | — |
| signing | 그리는 중(pointermove), 정규화된 필적 점을 전달 | (point: LhSignaturePoint) |
| end | 한 획 종료(pointerup / pointercancel) | — |
Signature 메서드(defineExpose)
| 메서드 | 설명 | 매개변수 |
|---|---|---|
| toDataURL | 캔버스 비트맵 내보내기(canvas.toDataURL 래퍼) | (type?: string, quality?: number) => string |
| clear | 스냅샷과 캔버스 비우기(배경 / 보조선도 함께 다시 그림) | — |
| undo | 마지막 획 취소(스냅샷 꺼내기 + 다시 그리기) | — |
| isEmpty | 캔버스가 비어 있는지 여부(스냅샷이 비어 있거나 픽셀이 모두 배경색) | () => boolean |
접근성
루트 노드는 role="img"이며 접근성 이름은 '서명 캔버스'로 고정됩니다. 빈 상태 알림(__placeholder)은 pointer-events: none이고 aria-hidden이며 그리기를 방해하지 않습니다.

