탐색

v2.1.0
폼

서명 패드

손가락, 펜, 마우스로 서명하거나 이름을 대신 입력하는 오목한 영역입니다.

이 페이지의 내용

서명 패드는 손가락, 펜, 마우스로 서명하는 오목한 영역과, 서명 대신 이름을 입력하는 필드로 구성됩니다. 패드는 입력 필드와 같은 오목한 영역으로, 서명할 가는 기준선과 이름이 시작되는 위치의 작은 십자 표시가 있습니다. 각 획은 펜을 누른 세기만큼의 두께를 가진 채운 윤곽선으로 인라인 <svg>에 작성되며, 그림은 SVG 문서로 폼에 담깁니다. 그룹은 네이티브 <fieldset>입니다. legend가 무엇에 서명하는지를 밝히고, <fieldset>에 disabled를 설정하면 패드가 멈추고 안의 모든 요소가 비활성화됩니다.

서명 패드

<fieldset class="signature max-w(440) mx-auto">  <legend class="signature-label">Sign the lease</legend>  <div class="signature-pad">    <svg class="signature-ink" viewBox="0 0 400 160" role="img" aria-label="Your drawn signature"></svg>    <span class="signature-line" aria-hidden="true"></span>    <span class="signature-placeholder" aria-hidden="true">Sign here</span>    <div class="signature-actions">      <button type="button" class="btn btn-sm btn-quiet signature-undo">Undo</button>      <button type="button" class="btn btn-sm btn-quiet signature-clear">Clear</button>    </div>  </div>  <label class="field">    Or type your full name <input class="input signature-name" name="signer" autocomplete="name" placeholder="Ada Lovelace">  </label>  <input type="hidden" class="signature-value" name="signature">  <span class="signature-status" role="status"></span></fieldset><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'export function Example() {  const root = useRef<HTMLFieldSetElement>(null)  useEffect(() => attach(root.current!), [])  return (    <fieldset ref={root} className="signature max-w(440) mx-auto">      <legend className="signature-label">Sign the lease</legend>      <div className="signature-pad">        <svg className="signature-ink" viewBox="0 0 400 160" role="img" aria-label="Your drawn signature"></svg>        <span className="signature-line" aria-hidden="true"></span>        <span className="signature-placeholder" aria-hidden="true">Sign here</span>        <div className="signature-actions">          <button type="button" className="btn btn-sm btn-quiet signature-undo">Undo</button>          <button type="button" className="btn btn-sm btn-quiet signature-clear">Clear</button>        </div>      </div>      <label className="field">        Or type your full name <input className="input signature-name" name="signer" autoComplete="name" placeholder="Ada Lovelace" />      </label>      <input type="hidden" className="signature-value" name="signature" />      <span className="signature-status" role="status"></span>    </fieldset>  )}
<script>  import { attach } from '@master/ui/behaviors'</script><fieldset class="signature max-w(440) mx-auto" {@attach attach}>  <legend class="signature-label">Sign the lease</legend>  <div class="signature-pad">    <svg class="signature-ink" viewBox="0 0 400 160" role="img" aria-label="Your drawn signature"></svg>    <span class="signature-line" aria-hidden="true"></span>    <span class="signature-placeholder" aria-hidden="true">Sign here</span>    <div class="signature-actions">      <button type="button" class="btn btn-sm btn-quiet signature-undo">Undo</button>      <button type="button" class="btn btn-sm btn-quiet signature-clear">Clear</button>    </div>  </div>  <label class="field">    Or type your full name <input class="input signature-name" name="signer" autocomplete="name" placeholder="Ada Lovelace">  </label>  <input type="hidden" class="signature-value" name="signature">  <span class="signature-status" role="status"></span></fieldset>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template>  <fieldset ref="root" class="signature max-w(440) mx-auto">    <legend class="signature-label">Sign the lease</legend>    <div class="signature-pad">      <svg class="signature-ink" viewBox="0 0 400 160" role="img" aria-label="Your drawn signature"></svg>      <span class="signature-line" aria-hidden="true"></span>      <span class="signature-placeholder" aria-hidden="true">Sign here</span>      <div class="signature-actions">        <button type="button" class="btn btn-sm btn-quiet signature-undo">Undo</button>        <button type="button" class="btn btn-sm btn-quiet signature-clear">Clear</button>      </div>    </div>    <label class="field">      Or type your full name <input class="input signature-name" name="signer" autocomplete="name" placeholder="Ada Lovelace">    </label>    <input type="hidden" class="signature-value" name="signature">    <span class="signature-status" role="status"></span>  </fieldset></template>
손가락, 펜, 마우스로 서명해 보세요. Undo는 마지막 획을, Clear는 모든 획을 지웁니다. 이름을 입력하면 필기체로 표시됩니다.

#동작

패드에 그리려면 스크립트가 필요합니다. signature 동작은 signature 클래스가 있는 루트 요소를 받아, 연결한 동작을 해제하는 함수를 반환합니다.

app.js
import { signature } from '@master/ui/behaviors/signature.js'const pad = signature(document.querySelector('.signature'))pad.value // [[[x, y, pressure], …], …], one list of points a strokepad.svg   // '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 160" …>…</svg>', or '' when nothing is drawn
  • 획. 획은 포인터가 지나간 점들로, 그림의 viewBox 단위로 나타내며 각 점에는 0부터 1까지의 압력 값이 있습니다. 펜은 자체 압력 값을 제공하지만 손가락과 마우스는 제공하지 않으므로, 펜이 머무른 곳에 잉크가 고이듯 천천히 움직인 부분이 더 굵게 그려집니다. 각 획은 signature-stroke 경로가 됩니다. 고른 압력에서 --signature-weight 두께를 가진 채운 윤곽선으로, 점들을 지나는 곡선으로 매끄럽게 다듬어지고 끝은 둥급니다. 브라우저가 포인터 이동을 병합하는 경우 병합된 이동도 읽으므로, 손을 빠르게 움직여도 곡선이 유지됩니다.
  • 값. value는 획 목록이며, 이 값을 설정하면 획을 그리고 이벤트는 발생하지 않습니다. svg는 그림을 SVG 문서로 나타낸 것이며, signature-value 필드에도 같은 문서가 담기므로 폼이 이를 제출합니다. 경로는 currentColor를 사용하며, 이미지에서는 검은색이 됩니다.
  • 이벤트. 필드는 획을 그리는 동안 input을, 획이 끝나면 change를 발생시키며, Undo나 Clear로 획을 지울 때는 두 이벤트를 모두 발생시킵니다.
  • Undo와 Clear. Undo는 마지막 획을, Clear는 모든 획을 지웁니다. 첫 획이 생기기 전까지 두 버튼은 화면에 표시되지 않습니다. 지울 것이 없는 동안 스크립트가 버튼에 aria-disabled를 설정하므로, 방금 패드를 비운 버튼은 포커스를 유지하며 그 상태를 알립니다.
  • 상태. signature-status는 첫 획이 끝나면 "Signature drawn", 패드가 비워지면 "Signature cleared", Undo 뒤에는 "Last stroke removed"라고 안내합니다.
옵션설정하는 내용
drawn첫 획이 끝났을 때 상태 영역이 안내하는 문구입니다. 기본값은 "Signature drawn"입니다
cleared패드가 비워졌을 때 안내하는 문구입니다. 기본값은 "Signature cleared"입니다
undoneUndo로 획을 지웠을 때 안내하는 문구입니다. 기본값은 "Last stroke removed"입니다

동작은 signaturePath(stroke, weight)와 signatureSvg(strokes, { viewBox, weight })도 내보냅니다. 이 함수들은 페이지 없이 획을 경로와 문서로 바꾸므로, 서버에서 이 함수로 저장된 서명을 첫 HTML에 그려 넣을 수 있습니다.

#이름 입력

그림에는 키보드 조작이 없습니다. 키보드, 스위치, 스크린 리더로 서명하는 사람이나 손으로 획을 긋기 어려운 사람은 이름을 입력해 서명합니다. 따라서 이름 입력은 부가 기능이 아니라 이 패턴의 일부입니다. 이름 입력은 signature-name 클래스가 있는 네이티브 입력 필드로, --signature-font의 필기체로 표시됩니다. --signature-font는 각 시스템에 기본 탑재된 글꼴(Apple 시스템의 "Snell Roundhand", Windows의 "Segoe Script")을 나열하고 cursive로 끝나는 글꼴 스택입니다. 플레이스홀더는 인터페이스 글꼴을 유지합니다.

스크립트가 없으면 패드에 그릴 수 없으므로 입력한 이름이 서명 전체가 됩니다. 폼은 다른 필드와 마찬가지로 이름 입력을 그 name으로 제출합니다.

#폼에서 사용하기

서명이 필수라면 이름 입력에 required를 설정하세요. 그림도 같은 필수 조건을 충족합니다. 획이 있는 동안 동작은 이름 입력에서 required를 제거하고, 패드가 비워지면 다시 설정합니다. 둘 다 없이 제출하면 이름 입력에 브라우저 자체의 메시지가 표시되며, 한 번 제출을 시도한 뒤에는 :user-invalid가 필드와 패드에 위험 윤곽선을 그리고 필드 안의 field-error가 표시됩니다.

폼에서 사용하기

<form class="grid gap-md max-w(440) mx-auto" id="lease-form">  <fieldset class="signature">    <legend class="signature-label">Sign the lease</legend>    <div class="signature-pad">      <svg class="signature-ink" viewBox="0 0 400 160" role="img" aria-label="Your drawn signature"></svg>      <span class="signature-line" aria-hidden="true"></span>      <span class="signature-placeholder" aria-hidden="true">Sign here</span>      <div class="signature-actions">        <button type="button" class="btn btn-sm btn-quiet signature-undo">Undo</button>        <button type="button" class="btn btn-sm btn-quiet signature-clear">Clear</button>      </div>    </div>    <div class="field">      <label for="lease-signer">Or type your full name</label>      <input class="input signature-name" id="lease-signer" name="signer" autocomplete="name" required aria-describedby="lease-error">      <span class="field-error" id="lease-error">Sign in the box, or type your name.</span>    </div>    <input type="hidden" class="signature-value" name="signature">    <span class="signature-status" role="status"></span>  </fieldset>  <div class="flex items-center gap-sm">    <button class="btn btn-primary">Sign the lease</button>    <output class="text-sm fg-text-muted" id="lease-output"></output>  </div></form><script>document.getElementById('lease-form').addEventListener('submit', function (event) {  event.preventDefault()  var data = new FormData(event.target)  var drawn = data.get('signature')  document.getElementById('lease-output').textContent = drawn ? 'Signed with a drawing of ' + drawn.length + ' characters of SVG' : 'Signed as ' + data.get('signer')})</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
아무것도 그리거나 입력하지 않고 Sign the lease를 눌러 보세요. 브라우저가 서명을 요구하고 패드가 위험 상태로 바뀝니다. 서명을 그리면 필수 조건이 충족됩니다.

애플리케이션이 서명을 거부할 때는 이름 입력에 aria-invalid="true"를 설정하고 그 field-error에 이유를 밝히세요. 두 요소가 하나의 서명이므로 패드에도 함께 위험 윤곽선이 표시됩니다.

#읽기 전용과 비활성화

루트에 signature-readonly를 적용하면 전달받은 서명을 그대로 보여 줍니다. 그 위에는 아무것도 그려지지 않으며 Undo와 Clear는 사라집니다. 이름 입력에도 readonly를 설정하거나 이름 입력을 생략하세요. <fieldset>에 disabled를 설정하면 패드가 멈추고, 잉크와 문구가 비활성 색으로 바뀌며, fieldset이 원래 그러하듯 안의 모든 컨트롤이 비활성화됩니다.

읽기 전용

<fieldset class="signature signature-readonly max-w(440) mx-auto">  <legend class="signature-label">Signed by the tenant on 12 November</legend>  <div class="signature-pad">    <svg class="signature-ink" viewBox="0 0 400 160" role="img" aria-label="The tenant's signature">      <path class="signature-stroke" d="M62.9 73.4Q61.4 76.1 61.4 78.9Q61.3 81.6 62.5 85.7Q63.6 89.7 66.3 94.2Q68.9 98.7 73 102.7Q77.1 106.7 82.4 109.3Q87.7 112 93.6 112.7Q99.6 113.3 105.4 111.8Q111.3 110.3 116.4 107Q121.5 103.6 125.3 99Q129.1 94.5 131.5 89.6Q133.8 84.8 134.7 80.6Q135.7 76.4 135.5 73.6Q135.3 70.9 133.7 70.1Q132.2 69.3 131.5 71.3Q130.8 73.3 131 76.9Q131.2 80.5 132.6 85.4Q134 90.2 136.8 95.4Q139.6 100.5 143.9 105.1Q148.1 109.6 153.4 112.7Q158.7 115.8 164.5 116.9Q170.3 118 176 116.9Q181.8 115.8 186.7 112.9Q191.6 109.9 195.3 105.8Q199 101.7 201.3 97.3Q203.5 92.9 204.3 89.1Q205.2 85.3 204.9 82.8Q204.6 80.3 202.6 80Q200.5 79.6 199.8 81.9Q199.2 84.2 199.5 88Q199.8 91.8 201.5 96.5Q203.1 101.2 206.2 106Q209.4 110.8 213.9 114.6Q218.4 118.5 224 120.7Q229.5 122.9 235.5 122.9Q241.4 122.8 247 120.6Q252.6 118.4 257.3 114.3Q262 110.3 265.4 105.3Q268.8 100.2 270.7 95.1Q272.6 90 273.1 85.7Q273.7 81.4 273.3 78.6Q272.9 75.9 271.5 75.2Q270.1 74.5 269.5 76.4Q269 78.2 269.5 81.6Q269.9 84.9 271.3 89.1L272.6 93.3A1 1 0 0 0 274.6 92.7Q271.8 84.4 271.3 81.3Q270.8 78.2 271 77Q271.3 75.8 271.3 76.1Q271.3 76.5 271.6 78.9Q272 81.3 271.4 85.4Q270.8 89.5 268.9 94.4Q267 99.3 263.8 104.1Q260.5 108.9 256 112.6Q251.5 116.3 246.2 118.3Q240.9 120.3 235.5 120.2Q230.1 120.1 225 118.1Q220 116 215.8 112.4Q211.7 108.7 208.9 104.3Q206 99.8 204.5 95.4Q203.1 91.1 202.8 87.7Q202.5 84.4 202.8 82.9Q203.1 81.5 202.4 81.5Q201.7 81.5 202 83.3Q202.2 85.1 201.5 88.5Q200.8 91.9 198.9 96.1Q196.9 100.2 193.5 104.2Q190.1 108.1 185.5 111Q181 113.8 175.7 114.9Q170.3 116 164.8 115Q159.3 114.1 154.2 111.2Q149.2 108.3 145.1 103.9Q141 99.6 138.3 94.6Q135.5 89.5 134.2 84.9Q132.9 80.2 132.8 76.8Q132.7 73.4 133.1 72.1Q133.6 70.8 133.3 71.1Q133.1 71.4 133.2 73.8Q133.2 76.1 132.3 80Q131.3 83.9 129 88.4Q126.8 92.9 123.1 97.1Q119.5 101.3 114.7 104.4Q110 107.4 104.7 108.7Q99.3 110.1 94 109.4Q88.6 108.8 83.8 106.4Q79 104 75.2 100.3Q71.4 96.6 68.9 92.5Q66.5 88.4 65.3 84.8Q64.2 81.1 64.2 78.8Q64.1 76.5 64.6 75.6L65.1 74.6A1.3 1.3 0 0 0 62.9 73.4Z"></path>      <path class="signature-stroke" d="M96.2 127.6Q127.6 123.9 143.3 122.5Q159 121.1 174.6 120.4Q190.3 119.7 206 120Q221.6 120.2 237.3 121.3Q253 122.5 268.7 124.4Q284.4 126.3 300.1 128.6L315.9 130.9A0.9 0.9 0 0 0 316.1 129.1Q284.7 124.3 269 122.3Q253.2 120.3 237.5 119.1Q221.8 117.8 206 117.5Q190.3 117.2 174.5 117.7Q158.8 118.3 143 119.6Q127.3 121 111.5 122.7L95.8 124.4A1.6 1.6 0 0 0 96.2 127.6Z"></path>    </svg>    <span class="signature-line" aria-hidden="true"></span>  </div></fieldset>
<fieldset className="signature signature-readonly max-w(440) mx-auto">  <legend className="signature-label">Signed by the tenant on 12 November</legend>  <div className="signature-pad">    <svg className="signature-ink" viewBox="0 0 400 160" role="img" aria-label="The tenant's signature">      <path className="signature-stroke" d="M62.9 73.4Q61.4 76.1 61.4 78.9Q61.3 81.6 62.5 85.7Q63.6 89.7 66.3 94.2Q68.9 98.7 73 102.7Q77.1 106.7 82.4 109.3Q87.7 112 93.6 112.7Q99.6 113.3 105.4 111.8Q111.3 110.3 116.4 107Q121.5 103.6 125.3 99Q129.1 94.5 131.5 89.6Q133.8 84.8 134.7 80.6Q135.7 76.4 135.5 73.6Q135.3 70.9 133.7 70.1Q132.2 69.3 131.5 71.3Q130.8 73.3 131 76.9Q131.2 80.5 132.6 85.4Q134 90.2 136.8 95.4Q139.6 100.5 143.9 105.1Q148.1 109.6 153.4 112.7Q158.7 115.8 164.5 116.9Q170.3 118 176 116.9Q181.8 115.8 186.7 112.9Q191.6 109.9 195.3 105.8Q199 101.7 201.3 97.3Q203.5 92.9 204.3 89.1Q205.2 85.3 204.9 82.8Q204.6 80.3 202.6 80Q200.5 79.6 199.8 81.9Q199.2 84.2 199.5 88Q199.8 91.8 201.5 96.5Q203.1 101.2 206.2 106Q209.4 110.8 213.9 114.6Q218.4 118.5 224 120.7Q229.5 122.9 235.5 122.9Q241.4 122.8 247 120.6Q252.6 118.4 257.3 114.3Q262 110.3 265.4 105.3Q268.8 100.2 270.7 95.1Q272.6 90 273.1 85.7Q273.7 81.4 273.3 78.6Q272.9 75.9 271.5 75.2Q270.1 74.5 269.5 76.4Q269 78.2 269.5 81.6Q269.9 84.9 271.3 89.1L272.6 93.3A1 1 0 0 0 274.6 92.7Q271.8 84.4 271.3 81.3Q270.8 78.2 271 77Q271.3 75.8 271.3 76.1Q271.3 76.5 271.6 78.9Q272 81.3 271.4 85.4Q270.8 89.5 268.9 94.4Q267 99.3 263.8 104.1Q260.5 108.9 256 112.6Q251.5 116.3 246.2 118.3Q240.9 120.3 235.5 120.2Q230.1 120.1 225 118.1Q220 116 215.8 112.4Q211.7 108.7 208.9 104.3Q206 99.8 204.5 95.4Q203.1 91.1 202.8 87.7Q202.5 84.4 202.8 82.9Q203.1 81.5 202.4 81.5Q201.7 81.5 202 83.3Q202.2 85.1 201.5 88.5Q200.8 91.9 198.9 96.1Q196.9 100.2 193.5 104.2Q190.1 108.1 185.5 111Q181 113.8 175.7 114.9Q170.3 116 164.8 115Q159.3 114.1 154.2 111.2Q149.2 108.3 145.1 103.9Q141 99.6 138.3 94.6Q135.5 89.5 134.2 84.9Q132.9 80.2 132.8 76.8Q132.7 73.4 133.1 72.1Q133.6 70.8 133.3 71.1Q133.1 71.4 133.2 73.8Q133.2 76.1 132.3 80Q131.3 83.9 129 88.4Q126.8 92.9 123.1 97.1Q119.5 101.3 114.7 104.4Q110 107.4 104.7 108.7Q99.3 110.1 94 109.4Q88.6 108.8 83.8 106.4Q79 104 75.2 100.3Q71.4 96.6 68.9 92.5Q66.5 88.4 65.3 84.8Q64.2 81.1 64.2 78.8Q64.1 76.5 64.6 75.6L65.1 74.6A1.3 1.3 0 0 0 62.9 73.4Z"></path>      <path className="signature-stroke" d="M96.2 127.6Q127.6 123.9 143.3 122.5Q159 121.1 174.6 120.4Q190.3 119.7 206 120Q221.6 120.2 237.3 121.3Q253 122.5 268.7 124.4Q284.4 126.3 300.1 128.6L315.9 130.9A0.9 0.9 0 0 0 316.1 129.1Q284.7 124.3 269 122.3Q253.2 120.3 237.5 119.1Q221.8 117.8 206 117.5Q190.3 117.2 174.5 117.7Q158.8 118.3 143 119.6Q127.3 121 111.5 122.7L95.8 124.4A1.6 1.6 0 0 0 96.2 127.6Z"></path>    </svg>    <span className="signature-line" aria-hidden="true"></span>  </div></fieldset>
<fieldset class="signature signature-readonly max-w(440) mx-auto">  <legend class="signature-label">Signed by the tenant on 12 November</legend>  <div class="signature-pad">    <svg class="signature-ink" viewBox="0 0 400 160" role="img" aria-label="The tenant's signature">      <path class="signature-stroke" d="M62.9 73.4Q61.4 76.1 61.4 78.9Q61.3 81.6 62.5 85.7Q63.6 89.7 66.3 94.2Q68.9 98.7 73 102.7Q77.1 106.7 82.4 109.3Q87.7 112 93.6 112.7Q99.6 113.3 105.4 111.8Q111.3 110.3 116.4 107Q121.5 103.6 125.3 99Q129.1 94.5 131.5 89.6Q133.8 84.8 134.7 80.6Q135.7 76.4 135.5 73.6Q135.3 70.9 133.7 70.1Q132.2 69.3 131.5 71.3Q130.8 73.3 131 76.9Q131.2 80.5 132.6 85.4Q134 90.2 136.8 95.4Q139.6 100.5 143.9 105.1Q148.1 109.6 153.4 112.7Q158.7 115.8 164.5 116.9Q170.3 118 176 116.9Q181.8 115.8 186.7 112.9Q191.6 109.9 195.3 105.8Q199 101.7 201.3 97.3Q203.5 92.9 204.3 89.1Q205.2 85.3 204.9 82.8Q204.6 80.3 202.6 80Q200.5 79.6 199.8 81.9Q199.2 84.2 199.5 88Q199.8 91.8 201.5 96.5Q203.1 101.2 206.2 106Q209.4 110.8 213.9 114.6Q218.4 118.5 224 120.7Q229.5 122.9 235.5 122.9Q241.4 122.8 247 120.6Q252.6 118.4 257.3 114.3Q262 110.3 265.4 105.3Q268.8 100.2 270.7 95.1Q272.6 90 273.1 85.7Q273.7 81.4 273.3 78.6Q272.9 75.9 271.5 75.2Q270.1 74.5 269.5 76.4Q269 78.2 269.5 81.6Q269.9 84.9 271.3 89.1L272.6 93.3A1 1 0 0 0 274.6 92.7Q271.8 84.4 271.3 81.3Q270.8 78.2 271 77Q271.3 75.8 271.3 76.1Q271.3 76.5 271.6 78.9Q272 81.3 271.4 85.4Q270.8 89.5 268.9 94.4Q267 99.3 263.8 104.1Q260.5 108.9 256 112.6Q251.5 116.3 246.2 118.3Q240.9 120.3 235.5 120.2Q230.1 120.1 225 118.1Q220 116 215.8 112.4Q211.7 108.7 208.9 104.3Q206 99.8 204.5 95.4Q203.1 91.1 202.8 87.7Q202.5 84.4 202.8 82.9Q203.1 81.5 202.4 81.5Q201.7 81.5 202 83.3Q202.2 85.1 201.5 88.5Q200.8 91.9 198.9 96.1Q196.9 100.2 193.5 104.2Q190.1 108.1 185.5 111Q181 113.8 175.7 114.9Q170.3 116 164.8 115Q159.3 114.1 154.2 111.2Q149.2 108.3 145.1 103.9Q141 99.6 138.3 94.6Q135.5 89.5 134.2 84.9Q132.9 80.2 132.8 76.8Q132.7 73.4 133.1 72.1Q133.6 70.8 133.3 71.1Q133.1 71.4 133.2 73.8Q133.2 76.1 132.3 80Q131.3 83.9 129 88.4Q126.8 92.9 123.1 97.1Q119.5 101.3 114.7 104.4Q110 107.4 104.7 108.7Q99.3 110.1 94 109.4Q88.6 108.8 83.8 106.4Q79 104 75.2 100.3Q71.4 96.6 68.9 92.5Q66.5 88.4 65.3 84.8Q64.2 81.1 64.2 78.8Q64.1 76.5 64.6 75.6L65.1 74.6A1.3 1.3 0 0 0 62.9 73.4Z"></path>      <path class="signature-stroke" d="M96.2 127.6Q127.6 123.9 143.3 122.5Q159 121.1 174.6 120.4Q190.3 119.7 206 120Q221.6 120.2 237.3 121.3Q253 122.5 268.7 124.4Q284.4 126.3 300.1 128.6L315.9 130.9A0.9 0.9 0 0 0 316.1 129.1Q284.7 124.3 269 122.3Q253.2 120.3 237.5 119.1Q221.8 117.8 206 117.5Q190.3 117.2 174.5 117.7Q158.8 118.3 143 119.6Q127.3 121 111.5 122.7L95.8 124.4A1.6 1.6 0 0 0 96.2 127.6Z"></path>    </svg>    <span class="signature-line" aria-hidden="true"></span>  </div></fieldset>
<template>  <fieldset class="signature signature-readonly max-w(440) mx-auto">    <legend class="signature-label">Signed by the tenant on 12 November</legend>    <div class="signature-pad">      <svg class="signature-ink" viewBox="0 0 400 160" role="img" aria-label="The tenant's signature">        <path class="signature-stroke" d="M62.9 73.4Q61.4 76.1 61.4 78.9Q61.3 81.6 62.5 85.7Q63.6 89.7 66.3 94.2Q68.9 98.7 73 102.7Q77.1 106.7 82.4 109.3Q87.7 112 93.6 112.7Q99.6 113.3 105.4 111.8Q111.3 110.3 116.4 107Q121.5 103.6 125.3 99Q129.1 94.5 131.5 89.6Q133.8 84.8 134.7 80.6Q135.7 76.4 135.5 73.6Q135.3 70.9 133.7 70.1Q132.2 69.3 131.5 71.3Q130.8 73.3 131 76.9Q131.2 80.5 132.6 85.4Q134 90.2 136.8 95.4Q139.6 100.5 143.9 105.1Q148.1 109.6 153.4 112.7Q158.7 115.8 164.5 116.9Q170.3 118 176 116.9Q181.8 115.8 186.7 112.9Q191.6 109.9 195.3 105.8Q199 101.7 201.3 97.3Q203.5 92.9 204.3 89.1Q205.2 85.3 204.9 82.8Q204.6 80.3 202.6 80Q200.5 79.6 199.8 81.9Q199.2 84.2 199.5 88Q199.8 91.8 201.5 96.5Q203.1 101.2 206.2 106Q209.4 110.8 213.9 114.6Q218.4 118.5 224 120.7Q229.5 122.9 235.5 122.9Q241.4 122.8 247 120.6Q252.6 118.4 257.3 114.3Q262 110.3 265.4 105.3Q268.8 100.2 270.7 95.1Q272.6 90 273.1 85.7Q273.7 81.4 273.3 78.6Q272.9 75.9 271.5 75.2Q270.1 74.5 269.5 76.4Q269 78.2 269.5 81.6Q269.9 84.9 271.3 89.1L272.6 93.3A1 1 0 0 0 274.6 92.7Q271.8 84.4 271.3 81.3Q270.8 78.2 271 77Q271.3 75.8 271.3 76.1Q271.3 76.5 271.6 78.9Q272 81.3 271.4 85.4Q270.8 89.5 268.9 94.4Q267 99.3 263.8 104.1Q260.5 108.9 256 112.6Q251.5 116.3 246.2 118.3Q240.9 120.3 235.5 120.2Q230.1 120.1 225 118.1Q220 116 215.8 112.4Q211.7 108.7 208.9 104.3Q206 99.8 204.5 95.4Q203.1 91.1 202.8 87.7Q202.5 84.4 202.8 82.9Q203.1 81.5 202.4 81.5Q201.7 81.5 202 83.3Q202.2 85.1 201.5 88.5Q200.8 91.9 198.9 96.1Q196.9 100.2 193.5 104.2Q190.1 108.1 185.5 111Q181 113.8 175.7 114.9Q170.3 116 164.8 115Q159.3 114.1 154.2 111.2Q149.2 108.3 145.1 103.9Q141 99.6 138.3 94.6Q135.5 89.5 134.2 84.9Q132.9 80.2 132.8 76.8Q132.7 73.4 133.1 72.1Q133.6 70.8 133.3 71.1Q133.1 71.4 133.2 73.8Q133.2 76.1 132.3 80Q131.3 83.9 129 88.4Q126.8 92.9 123.1 97.1Q119.5 101.3 114.7 104.4Q110 107.4 104.7 108.7Q99.3 110.1 94 109.4Q88.6 108.8 83.8 106.4Q79 104 75.2 100.3Q71.4 96.6 68.9 92.5Q66.5 88.4 65.3 84.8Q64.2 81.1 64.2 78.8Q64.1 76.5 64.6 75.6L65.1 74.6A1.3 1.3 0 0 0 62.9 73.4Z"></path>        <path class="signature-stroke" d="M96.2 127.6Q127.6 123.9 143.3 122.5Q159 121.1 174.6 120.4Q190.3 119.7 206 120Q221.6 120.2 237.3 121.3Q253 122.5 268.7 124.4Q284.4 126.3 300.1 128.6L315.9 130.9A0.9 0.9 0 0 0 316.1 129.1Q284.7 124.3 269 122.3Q253.2 120.3 237.5 119.1Q221.8 117.8 206 117.5Q190.3 117.2 174.5 117.7Q158.8 118.3 143 119.6Q127.3 121 111.5 122.7L95.8 124.4A1.6 1.6 0 0 0 96.2 127.6Z"></path>      </svg>      <span class="signature-line" aria-hidden="true"></span>    </div>  </fieldset></template>

#비율과 잉크

그림의 viewBox가 패드의 비율과 획의 단위를 정합니다. 패드의 너비는 열의 너비와 같고 높이는 viewBox가 정하는 만큼이므로, 휴대폰에서 그린 서명을 데스크톱에서 보여 줘도 모양이 유지됩니다. 0 0 400 160은 폼의 한 줄에 어울리고, 0 0 480 140처럼 더 넓은 상자는 여유 공간이 있는 페이지에 어울립니다. 잉크 색은 --signature-ink로, 기본값은 강한 텍스트 색입니다. --signature-weight는 고른 압력에서의 획 두께를 viewBox 단위로 나타내며, 획을 작성할 때 읽힙니다. 패드의 모서리 반경은 --signature-radius입니다.

#이미지로 내보내기

그림은 확대·축소해도 깨지지 않고 크기도 작은 SVG로 내보내집니다. PDF 라이브러리나 이메일처럼 PNG가 필요한 경우에는 애플리케이션이 SVG를 캔버스에 그립니다.

png.js
async function png(svg, scale = 2) {  const url = URL.createObjectURL(new Blob([svg], { type: 'image/svg+xml' }))  const image = new Image()  image.src = url  await image.decode()  const canvas = document.createElement('canvas')  canvas.width = image.naturalWidth * scale  canvas.height = image.naturalHeight * scale  canvas.getContext('2d').drawImage(image, 0, 0, canvas.width, canvas.height)  URL.revokeObjectURL(url)  return new Promise((resolve) => canvas.toBlob(resolve, 'image/png'))}const blob = await png(pad.svg)

문서는 viewBox에서 가져온 크기를 width와 height에 담고 있으므로, scale이 해상도를 정합니다. 캔버스에서 아무것도 그려지지 않은 부분은 투명합니다.

#키보드

키동작
Tab키보드로 서명할 수 있는 이름 입력 필드로 이동하며, 그린 내용이 있으면 Undo와 Clear 버튼으로도 이동합니다. 그림에는 키 조작이 없으므로 패드 자체는 포커스를 받지 않습니다.
Enter, Space네이티브 버튼과 같은 방식으로 Undo에서는 마지막 획을, Clear에서는 모든 획을 취소합니다.

#접근성

  • 패드와 이름 입력을 무엇에 서명하는지 밝히는 legend가 있는 <fieldset>으로 묶으세요.
  • 그림에 role="img"로 이미지 역할을 지정하고 aria-label로 이름을 붙인 뒤, 기준선과 플레이스홀더는 aria-hidden="true"로 숨기세요. 그림의 이름이 이미 어디에 서명할지 알려 줍니다.
  • 키로 그릴 수 없으므로 패드는 포커스를 받지 않습니다. 이름 입력에는 서명하는 또 다른 방법임을 알리는 보이는 레이블을 지정하세요.
  • 상태 영역은 보조 기술의 현재 안내를 끊지 않고 상태를 알립니다. 획마다 안내하지 않고, 패드에 서명했거나 패드가 비워졌을 때 안내합니다.
  • 패드 위에서는 손가락이 페이지를 스크롤하지 않고 그림을 그립니다(touch-action: none). 휴대폰 사용자가 패드를 지나 스크롤할 수 있도록 패드의 높이를 서명에 필요한 만큼만 유지하세요.
  • 강제 색상 모드에서는 획을 CanvasText로, 기준선과 십자 표시를 GrayText로 그리며, 패드는 윤곽선을 유지합니다.
  • 동의, 서명자의 신원, 서명 시점의 기록처럼 어떤 표시를 법적으로 서명이 되게 하는 요소는 컴포넌트가 아니라 애플리케이션과 해당 관할 지역의 몫입니다.

#React, Svelte, Vue

signature 컴포넌트는 그룹을 렌더링하고 동작을 연결하며, 획을 받아 외부로 전달합니다. 입력한 이름은 두 번째 값인 typed입니다. 첫 값은 첫 렌더링에 그려지므로, 서버가 보내는 페이지에는 서명이 이미 패드에 그려져 있습니다. npx master-ui add signature 명령을 실행해 프로젝트에 복사하세요. 컴포넌트의 구성과 사용 방법은 React, Svelte, Vue에서 확인할 수 있습니다.

ui/signature.tsx
'use client'import { useState, type ChangeEvent, type ComponentProps } from 'react'import { signature, signaturePath } from '@master/ui/behaviors/signature.js'import { useBehavior } from './use-behavior'/** One stroke: the points it passed through, in the units of the viewBox, each with the pressure there. */export type SignatureStroke = [x: number, y: number, pressure: number][]export interface SignatureProps extends Omit<ComponentProps<'fieldset'>, 'defaultValue' | 'onChange' | 'name' | 'ref'> {  /** What is being signed: the legend of the group. */  label: string  /** The strokes drawn. */  value?: SignatureStroke[]  defaultValue?: SignatureStroke[]  /** Called as a stroke is drawn, and when Undo or Clear takes strokes back. */  onValueChange?: (value: SignatureStroke[]) => void  /** The name a form submits the drawing under, as an SVG document. */  name?: string  /** The drawing's viewBox: the pad's proportions and the units of a stroke. */  viewBox?: string  /** The drawing's name, as an image. */  padLabel?: string  /** Where to sign, until the first stroke. */  placeholder?: string  undoLabel?: string  clearLabel?: string  /** The label of the typed name, the keyboard's way to sign. */  typedLabel?: string  /** The typed name. */  typed?: string  defaultTyped?: string  onTypedChange?: (typed: string) => void  /** The name a form submits the typed name under. */  typedName?: string  /** A signature is required: the typed name is, until something is drawn. */  required?: boolean  readOnly?: boolean  invalid?: boolean  /** What the status says when the pad is signed, when it is emptied and when Undo takes a stroke back. */  messages?: { drawn?: string, cleared?: string, undone?: string }}/** A pad to sign in and a name to type instead. `disabled` disables the whole group. */export function Signature({ label, value, defaultValue, onValueChange, name, viewBox = '0 0 400 160', padLabel = 'Your drawn signature', placeholder = 'Sign here', undoLabel = 'Undo', clearLabel = 'Clear', typedLabel = 'Or type your full name', typed, defaultTyped, onTypedChange, typedName, required, readOnly, invalid, messages, className, ...root }: SignatureProps) {  const ref = useBehavior(signature, { drawn: messages?.drawn, cleared: messages?.cleared, undone: messages?.undone }, { value, defaultValue, onValueChange })  const [first] = useState(() => value ?? defaultValue ?? [])  const empty = first.length === 0  const field = typed === undefined    ? { defaultValue: defaultTyped }    : { value: typed }  return (    <fieldset className={['signature', readOnly && 'signature-readonly', className].filter(Boolean).join(' ')} ref={ref} {...root}>      <legend className="signature-label">{label}</legend>      <div className="signature-pad">        <svg className="signature-ink" viewBox={viewBox} role="img" aria-label={padLabel}>          {first.map((stroke, index) => <path className="signature-stroke" d={signaturePath(stroke)} key={index} />)}        </svg>        <span className="signature-line" aria-hidden="true" />        <span className="signature-placeholder" aria-hidden="true">{placeholder}</span>        <div className="signature-actions">          <button type="button" className="btn btn-sm btn-quiet signature-undo" aria-disabled={empty || undefined}>{undoLabel}</button>          <button type="button" className="btn btn-sm btn-quiet signature-clear" aria-disabled={empty || undefined}>{clearLabel}</button>        </div>      </div>      <label className="field">        {typedLabel}        <input className="input signature-name" name={typedName} autoComplete="name" required={required} readOnly={readOnly} aria-invalid={invalid || undefined} {...field} onChange={(event: ChangeEvent<HTMLInputElement>) => onTypedChange?.(event.target.value)} />      </label>      {/*        A hidden field's value is its attribute, which React writes back on every render, a default as well as a        value: the behavior fills it. So the first render carries no drawing here, where Svelte's and Vue's do,        and a form sent before the page has hydrated sends none.      */}      <input type="hidden" className="signature-value" name={name} />      <span className="signature-status" role="status" />    </fieldset>  )}
ui/Signature.svelte
<script lang="ts" module>  import type { HTMLFieldsetAttributes } from 'svelte/elements'  /** One stroke: the points it passed through, in the units of the viewBox, each with the pressure there. */  export type SignatureStroke = [x: number, y: number, pressure: number][]  export interface SignatureProps extends Omit<HTMLFieldsetAttributes, 'children' | 'name'> {    /** What is being signed: the legend of the group. */    label: string    /** The strokes drawn. Bind it, or leave it out. */    value?: SignatureStroke[]    /** Called as a stroke is drawn, and when Undo or Clear takes strokes back. */    onValueChange?: (value: SignatureStroke[]) => void    /** The name a form submits the drawing under, as an SVG document. */    name?: string    /** The drawing's viewBox: the pad's proportions and the units of a stroke. */    viewBox?: string    /** The drawing's name, as an image. */    padLabel?: string    /** Where to sign, until the first stroke. */    placeholder?: string    undoLabel?: string    clearLabel?: string    /** The label of the typed name, the keyboard's way to sign. */    typedLabel?: string    /** The typed name. Bind it, or leave it out. */    typed?: string    onTypedChange?: (typed: string) => void    /** The name a form submits the typed name under. */    typedName?: string    /** A signature is required: the typed name is, until something is drawn. */    required?: boolean    readonly?: boolean    invalid?: boolean    /** What the status says when the pad is signed, when it is emptied and when Undo takes a stroke back. */    messages?: { drawn?: string, cleared?: string, undone?: string }  }</script><script lang="ts">  import { untrack } from 'svelte'  import { signature, signaturePath, signatureSvg } from '@master/ui/behaviors/signature.js'  import { behavior } from './behavior.svelte.js'  let { label, value = $bindable(), onValueChange, name, viewBox = '0 0 400 160', padLabel = 'Your drawn signature', placeholder = 'Sign here', undoLabel = 'Undo', clearLabel = 'Clear', typedLabel = 'Or type your full name', typed = $bindable(), onTypedChange, typedName, required, readonly, invalid, messages, class: className, ...root }: SignatureProps = $props()  const first = untrack(() => value) ?? []  const empty = first.length === 0  const svg = signatureSvg(first, { viewBox: untrack(() => viewBox) })  // The behavior lifts required from the typed name while there is a drawing. Svelte writes a boolean property  // again each time the element's other attributes change; through a spread it compares and leaves it.  const needed = { required: untrack(() => required) }  const attach = behavior(signature, () => ({ drawn: messages?.drawn, cleared: messages?.cleared, undone: messages?.undone }), {    value: () => value,    change: (next) => { value = next; onValueChange?.(next) },  })</script><!--  @component  A pad to sign in and a name to type instead. `disabled` disables the whole group.--><fieldset class={['signature', readonly && 'signature-readonly', className]} {@attach attach} {...root}>  <legend class="signature-label">{label}</legend>  <div class="signature-pad">    <svg class="signature-ink" {viewBox} role="img" aria-label={padLabel}>      {#each first as stroke, index (index)}        <path class="signature-stroke" d={signaturePath(stroke)} />      {/each}    </svg>    <span class="signature-line" aria-hidden="true"></span>    <span class="signature-placeholder" aria-hidden="true">{placeholder}</span>    <div class="signature-actions">      <button type="button" class="btn btn-sm btn-quiet signature-undo" aria-disabled={empty || undefined}>{undoLabel}</button>      <button type="button" class="btn btn-sm btn-quiet signature-clear" aria-disabled={empty || undefined}>{clearLabel}</button>    </div>  </div>  <label class="field">    {typedLabel}    <input class="input signature-name" name={typedName} autocomplete="name" {...needed} {readonly} aria-invalid={invalid || undefined} bind:value={typed} oninput={() => onTypedChange?.(typed ?? '')} />  </label>  <input type="hidden" class="signature-value" {name} value={svg} />  <span class="signature-status" role="status"></span></fieldset>
ui/Signature.vue
<script lang="ts">/** One stroke: the points it passed through, in the units of the viewBox, each with the pressure there. */export type SignatureStroke = [x: number, y: number, pressure: number][]</script><script setup lang="ts">import { useTemplateRef } from 'vue'import { signature, signaturePath, signatureSvg } from '@master/ui/behaviors/signature.js'import { useBehavior } from './use-behavior'defineOptions({ inheritAttrs: false })const { viewBox = '0 0 400 160', padLabel = 'Your drawn signature', placeholder = 'Sign here', undoLabel = 'Undo', clearLabel = 'Clear', typedLabel = 'Or type your full name', messages } = defineProps<{  /** What is being signed: the legend of the group. */  label: string  /** The name a form submits the drawing under, as an SVG document. */  name?: string  /** The drawing's viewBox: the pad's proportions and the units of a stroke. */  viewBox?: string  /** The drawing's name, as an image. */  padLabel?: string  /** Where to sign, until the first stroke. */  placeholder?: string  undoLabel?: string  clearLabel?: string  /** The label of the typed name, the keyboard's way to sign. */  typedLabel?: string  /** The name a form submits the typed name under. */  typedName?: string  /** A signature is required: the typed name is, until something is drawn. */  required?: boolean  readonly?: boolean  invalid?: boolean  /** What the status says when the pad is signed, when it is emptied and when Undo takes a stroke back. */  messages?: { drawn?: string, cleared?: string, undone?: string }}>()/** The strokes drawn: `v-model`. It changes as a stroke is drawn, and when Undo or Clear takes strokes back. */const model = defineModel<SignatureStroke[]>()/** The typed name: `v-model:typed`. */const typed = defineModel<string>('typed')/* A pad to sign in and a name to type instead. `disabled` disables the whole group. */const first = model.value ?? []const empty = first.length === 0const svg = signatureSvg(first, { viewBox })const root = useTemplateRef<HTMLFieldSetElement>('root')useBehavior(root, signature, () => ({ drawn: messages?.drawn, cleared: messages?.cleared, undone: messages?.undone }), model)</script><template>  <fieldset class="signature" :class="{ 'signature-readonly': readonly }" ref="root" v-bind="$attrs">    <legend class="signature-label">{{ label }}</legend>    <div class="signature-pad">      <svg class="signature-ink" :viewBox="viewBox" role="img" :aria-label="padLabel">        <path v-for="(stroke, index) in first" :key="index" class="signature-stroke" :d="signaturePath(stroke)" />      </svg>      <span class="signature-line" aria-hidden="true" />      <span class="signature-placeholder" aria-hidden="true">{{ placeholder }}</span>      <div class="signature-actions">        <button type="button" class="btn btn-sm btn-quiet signature-undo" :aria-disabled="empty || undefined">{{ undoLabel }}</button>        <button type="button" class="btn btn-sm btn-quiet signature-clear" :aria-disabled="empty || undefined">{{ clearLabel }}</button>      </div>    </div>    <label class="field">      {{ typedLabel }}      <input v-model="typed" class="input signature-name" :name="typedName" autocomplete="name" :required="required" :readonly="readonly" :aria-invalid="invalid || undefined">    </label>    <input type="hidden" class="signature-value" :name="name" :value.attr="svg">    <span class="signature-status" role="status" />  </fieldset></template>

#클래스

클래스설명
signature<legend>가 있는 <fieldset>에 적용하는 그룹입니다. 패드, 버튼, 이름 입력, 폼이 제출하는 필드, 상태 영역을 담습니다.
signature-readonly그린 서명을 그대로 보여 줍니다. 더 그릴 수 없으며 Undo와 Clear 버튼은 사라집니다. 이름 입력 필드에도 readonly를 지정하세요.적용할 클래스는 signature입니다
signature-label<legend>로, 무엇에 서명하는지 나타냅니다.
signature-pad포인터로 그리는 오목한 영역입니다. 브라우저의 터치 제스처를 받지 않으므로 손가락으로 스크롤하는 대신 그릴 수 있습니다.
signature-ink패드 안의 인라인 <svg>로 그린 서명입니다. viewBox가 패드의 비율과 획의 단위를 정합니다. 이미지로서 이름을 지정하세요.
signature-stroke획 하나로, 스크립트가 그림에 기록하는 채워진 윤곽선입니다.
signature-line서명할 기준선으로, 이름이 시작하는 곳에 가는 X 표시가 있습니다. aria-hidden="true"로 숨기세요.
signature-placeholder서명할 위치를 알려 주는 문구로, 첫 획을 그을 때까지 표시합니다. 그림의 이름이 같은 내용을 전달하므로 aria-hidden="true"로 숨기세요.
signature-actions패드 위쪽 모서리에 놓이는 Undo와 Clear 버튼 행
signature-undo마지막 획을 취소하는 버튼입니다. 획이 생기기 전까지는 보이지 않으며, 획이 없는 동안 스크립트가 aria-disabled를 지정합니다.
signature-clear모든 획을 지우는 버튼입니다. 획이 생기기 전까지는 보이지 않으며, 획이 없는 동안 스크립트가 aria-disabled를 지정합니다.
signature-name이름 입력으로, input 클래스를 적용한 입력 필드에 필기체 글꼴로 표시합니다. 보이는 레이블을 지정하세요.
signature-value폼이 제출하는 필드입니다. 스크립트가 그린 서명을 SVG 문서로 기록합니다. name을 지정하세요.
signature-status화면에서 잘라 내 보이지 않게 한 영역입니다. 서명하거나 지웠을 때 스크립트가 보조 기술을 위해 알리는 내용을 담습니다.

#사용자 지정 속성

속성기본값설명
--signature-inkvar(--color-text-strong)획의 색상
--signature-weight2.5균일한 압력에서 획의 두께로, 그림의 viewBox 단위입니다. 스크립트가 획을 기록할 때 이 값을 읽습니다.
--signature-radiusvar(--radius-control-lg)패드의 모서리 반경
--signature-font"Snell Roundhand", "Segoe Script", "Bradley Hand", "Apple Chancery", cursive이름 입력에 쓰는 필기체 글꼴

#소스

@master/ui/components/signature.css
/* * Signature: a well to sign in with a finger, a pen or a mouse, and a field to type the name instead. * The pad is the same well as a text field, cut into its surface, with a hairline to sign on and a fine cross * where the name begins. The drawing is an inline <svg> whose viewBox sets the pad's proportions; a script * writes each stroke into it as a filled path, an outline as wide as the pen pressed or, for a finger and a * mouse, as slowly as it moved, so the ink and its weight come from this stylesheet and the line from the hand. * Until there is a stroke the pad shows its placeholder, and Undo and Clear stay out of sight. * * A drawing has no keyboard, so the typed name is part of the pattern: a native field whose words are set in * a script face. It is the whole signature without a script, and the keyboard's way to sign with one. In * forced colors the strokes are drawn in CanvasText and the line and the cross in GrayText. */@layer components.ui {  .signature {    --signature-ink: var(--color-text-strong);    --signature-weight: 2.5;    --signature-radius: var(--radius-control-lg);    --signature-font: "Snell Roundhand", "Segoe Script", "Bradley Hand", "Apple Chancery", cursive;    display: grid;    gap: .75rem;    min-width: 0;    margin: 0;    padding: 0;    border: 0;  }  /* The <legend>: what is being signed, in the voice of a field's label. */  .signature-label {    margin-bottom: .5rem;    padding: 0;    color: var(--color-text-strong);    font-size: .875rem;    font-weight: var(--font-weight-control);    line-height: 1.4;  }  /*   * The pad: a well the pointer draws in. It takes no gesture of the browser's, so a finger draws instead of   * scrolling the page, and no selection, so a quick stroke does not select the placeholder.   */  .signature-pad {    position: relative;    min-width: 0;    border-radius: calc(var(--signature-radius) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: var(--color-surface-inset);    box-shadow: var(--shadow-pressed);    cursor: crosshair;    touch-action: none;    user-select: none;    -webkit-user-select: none;    -webkit-tap-highlight-color: transparent;    transition-property: box-shadow, background-color;    transition-duration: var(--duration-quick);    transition-timing-function: var(--easing-glide);    @media (hover: hover) {      &:hover {        background: var(--color-surface-inset-hover);      }    }    @media (forced-colors: active) {      outline: 1px solid FieldText;      outline-offset: -1px;    }  }  /* The drawing: as wide as the pad and as tall as its viewBox makes it, clipped to the pad's corner. */  .signature-ink {    display: block;    width: 100%;    height: auto;    border-radius: inherit;    corner-shape: inherit;    overflow: hidden;  }  /* One stroke, written by the script: a filled outline, so its width can follow the pressure along it. */  .signature-stroke {    fill: var(--signature-ink);    stroke: none;    @media (forced-colors: active) {      fill: CanvasText;      forced-color-adjust: none;    }  }  /* The line to sign on, a quarter of the way up, with a fine cross where the name begins. */  .signature-line {    position: absolute;    inset-inline: 1.5rem;    bottom: 26%;    height: 1px;    background: var(--color-line-strong);    pointer-events: none;    &::before {      content: '';      position: absolute;      inset-inline-start: 0;      bottom: .4375rem;      width: .625rem;      height: .625rem;      background: var(--color-text-muted);      mask:        linear-gradient(45deg, transparent calc(50% - .75px), currentColor 0 calc(50% + .75px), transparent 0),        linear-gradient(-45deg, transparent calc(50% - .75px), currentColor 0 calc(50% + .75px), transparent 0);    }    @media (forced-colors: active) {      background: GrayText;      forced-color-adjust: none;      &::before {        background: GrayText;      }    }  }  /* Says where to sign, above the line, until the first stroke. */  .signature-placeholder {    position: absolute;    inset-inline: 1.5rem;    bottom: calc(26% + 1.25rem);    margin: 0;    color: var(--color-text-muted);    font-size: .8125rem;    line-height: 1.5;    text-align: center;    text-wrap: balance;    pointer-events: none;  }  /*   * Undo and Clear, in the pad's top corner: the drawing rarely reaches it. They stand 4px in, and their corner   * is the pad's less that inset (8px from its 12px), so the two curves stay concentric.   */  .signature-actions {    position: absolute;    inset-block-start: 4px;    inset-inline-end: 4px;    display: flex;    gap: .25rem;    cursor: default;    /* The button multiplies its radius by the corner scale itself, so the inset is divided by it here. */    .btn {      --btn-radius: calc(var(--signature-radius) - 4px / var(--corner-scale));    }  }  /*   * Undo and Clear have nothing to do until there is a stroke, so they wait out of sight. The one that just   * emptied the pad keeps its focus, and stays until focus moves on, marked aria-disabled by the script.   */  .signature-undo, .signature-clear {    transition-property: opacity, visibility;    transition-duration: var(--duration-quick);    transition-timing-function: var(--easing-glide);  }  .signature:not(:has(.signature-stroke)) :is(.signature-undo, .signature-clear):not(:focus) {    opacity: 0;    visibility: hidden;  }  .signature-pad:has(.signature-stroke) .signature-placeholder {    visibility: hidden;  }  /* The typed name, set in a script face at the size of a large field; the placeholder stays in the face of the interface. */  .signature-name {    /* A large field's height, padding and corner, the corner the pad above it has too. */    --input-height: 2.75rem;    --input-padding-x: .875rem;    --input-radius: var(--radius-control-lg);    padding-block: .5rem;    font-family: var(--signature-font);    font-size: 1.5rem;    line-height: 1.75rem;    &::placeholder {      font-family: var(--font-family-sans);      font-size: .875rem;    }  }  /* The field a form submits: the drawing as SVG, written by the script. It never takes room. */  .signature-value {    display: none;  }  /* What the script says when the drawing changes, for assistive technology; clipped out of sight. */  .signature-status {    position: absolute;    width: 1px;    height: 1px;    margin: -1px;    padding: 0;    overflow: hidden;    clip-path: inset(50%);    white-space: nowrap;  }  /*   * Invalid: the typed name is marked, or it is required and empty once the reader has tried. The name and the   * drawing are one signature, so the pad takes the danger contour the field does; say why under the field.   */  .signature:has(.signature-name:is([aria-invalid="true"], :user-invalid)) .signature-pad {    box-shadow: var(--shadow-pressed), inset 0 0 0 .5px var(--color-danger), 0 0 0 .5px color-mix(in oklab, var(--color-danger) 45%, transparent);    /* Forced colors drop the danger shadow: the pad's outline says it instead, as the field's does. */    @media (forced-colors: active) {      outline-color: Mark;    }  }  /*   * Read-only: the drawing is shown as it is; nothing draws on it and nothing clears it. With nothing to draw,   * the pad gives the browser its gestures back, so a finger on it scrolls the page.   */  .signature.signature-readonly {    .signature-pad {      cursor: default;      touch-action: auto;      @media (hover: hover) {        &:hover {          background: var(--color-surface-inset);        }      }    }    :is(.signature-undo, .signature-clear) {      display: none;    }  }  /* Disabled, on the <fieldset>: the well keeps its place, the ink and the words turn to disabled ink. */  .signature:disabled {    --signature-ink: var(--color-text-disabled);    .signature-label, .signature-placeholder {      color: var(--color-text-disabled);    }    .signature-line::before {      background: var(--color-text-disabled);    }    .signature-pad {      cursor: not-allowed;      touch-action: auto;      @media (hover: hover) {        &:hover {          background: var(--color-surface-inset);        }      }    }    :is(.signature-undo, .signature-clear) {      display: none;    }    /* The line and the strokes opt out of forced colors, so disabled ink is given the system's own here, and the pad's edge as well. */    @media (forced-colors: active) {      .signature-label, .signature-placeholder {        color: GrayText;      }      .signature-pad {        outline-color: GrayText;      }      .signature-line::before {        background: GrayText;      }      .signature-stroke {        fill: GrayText;      }    }  }}