@alfadocs/ui-kit-debug 0.55.0 → 0.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"sign-document-BzHTjMVC.js","sources":["../../src/components/sign-document/sign-document.agent.ts","../../src/components/sign-document/sign-document.tsx"],"sourcesContent":["/* -------------------------------------------------------------------- */\n/* Agent adapter — SignDocument. */\n/* */\n/* State exposes only structural lifecycle info — never the signature */\n/* bytes (the signed consent is sensitive; persistence is the consumer's */\n/* concern). The single write action confirms the captured signature. */\n/* */\n/* See `src/docs/26-agent-readiness.mdx` for the contract. */\n/* -------------------------------------------------------------------- */\n\nimport type { AgentAdapter } from '../../agent/types';\nimport type { SignDocumentHandle } from './sign-document';\n\nexport const signDocumentAgent: AgentAdapter<SignDocumentHandle> = {\n id: 'sign-document',\n capabilities: ['submit'],\n state: {\n isReadComplete: {\n type: 'boolean',\n descriptionKey: 'signDocument.agent.state.isReadComplete',\n description:\n 'True when the reader has reached the last page (or read-gating is off).',\n read: (handle) => handle.isReadComplete(),\n },\n },\n actions: {\n submit: {\n safety: 'write',\n descriptionKey: 'signDocument.agent.actions.confirm',\n description:\n 'Confirm the current signature, emitting it via onSign. No-op if unsigned.',\n invoke: (handle) => handle.confirm(),\n },\n reset: {\n safety: 'destructive',\n descriptionKey: 'signDocument.agent.actions.reset',\n description: 'Clear the captured signature and return to unsigned.',\n invoke: (handle) => {\n handle.reset();\n },\n },\n },\n domHooks: {\n root: {\n attr: 'data-component',\n value: 'sign-document',\n description: 'Marks the SignDocument wrapper.',\n },\n instanceId: {\n attr: 'data-component-id',\n sourceProp: 'id',\n description: 'Sourced from the id prop.',\n },\n },\n};\n","/* ------------------------------------------------------------------ */\n/* SignDocument — review a PDF document, then sign it. */\n/* */\n/* Fills the kit gap where consumers hand-composed PDFViewer + */\n/* SignatureCapture for consents (e.g. sign.alfadocs.com, HTP-4889). */\n/* This component owns the composition and the read-gate so the consent */\n/* flow is a single primitive: */\n/* */\n/* - PDFViewer (the document) renders above; the signing surface */\n/* renders below. */\n/* - When `requireReadToEnd` (default), the SignatureCapture pad and */\n/* the \"Confirm & sign\" button are gated until the reader reaches the */\n/* LAST page. We track this via PDFViewer's onLoadComplete (numPages) */\n/* + onPageChange (currentPage === numPages). NOTE: last-page-reached */\n/* is an APPROXIMATE read signal — a fit-page zoom can show the last */\n/* page without scrolling. That is acceptable for this gate; a */\n/* legal-grade \"read every page\" guarantee is the consumer's call. */\n/* - When `signedAt` is set the component renders an already-signed */\n/* read-only state (no pad) so re-sign-on-change consumers can show */\n/* signed status. */\n/* - Security: no fetch / XHR / storage / globals here. SignatureCapture */\n/* owns the export payload (PNG/SVG + sha256); the consumer owns */\n/* persistence via onSign. */\n/* - i18n: every authored string via `t('signDocument.*')` (bare keys */\n/* under the `ui` namespace). PDFViewer's `pdf.*` and */\n/* SignatureCapture's `signature.*` strings already exist. */\n/* ------------------------------------------------------------------ */\n\nimport {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { cva } from 'class-variance-authority';\nimport { useTranslation } from 'react-i18next';\nimport { CheckCircle2 } from 'lucide-react';\nimport { PDFViewer } from '../pdf-viewer';\nimport {\n SignatureCapture,\n type SignatureCaptureHandle,\n type SignatureConfirmPayload,\n} from '../signature-capture';\nimport { useAgentRegistration } from '../../agent';\nimport { signDocumentAgent } from './sign-document.agent';\n\n/* ------------------------------------------------------------------ */\n/* Public types */\n/* ------------------------------------------------------------------ */\n\nexport interface SignDocumentProps {\n /** Opaque instance id — emitted as `data-component-id` for the agent registry. */\n id?: string;\n /** Document PDF — URL string, ArrayBuffer, or Uint8Array. Passed to PDFViewer. */\n src: string | ArrayBuffer | Uint8Array;\n /** Accessible name for the document region (also used as a heading). */\n documentTitle?: string;\n /**\n * Gate the signature + Confirm until the reader reaches the last page.\n * Default `true`. Last-page-reached is an approximate read signal (a\n * fit-page zoom can show the last page without scrolling) — adequate for\n * this gate; legal-grade read tracking is the consumer's concern.\n */\n requireReadToEnd?: boolean;\n /** Fired when the user captures a signature AND confirms. */\n onSign?: (payload: SignatureConfirmPayload) => void;\n /** Forwarded from PDFViewer on any load / render error. */\n onError?: (error: Error) => void;\n /**\n * When set, render the already-signed read-only state: shows \"Signed\" +\n * the signed date and hides the pad. Use for re-sign-on-change consumers\n * that surface signed status. `null` / `undefined` → unsigned.\n */\n signedAt?: string | null;\n /**\n * Optional on-behalf attribution. When both `signer` and `subject` are\n * given, a \"Signed by {signer} on behalf of {subject}\" note renders both\n * near the signature pad (so the signer sees who they're signing for) AND\n * inside the already-signed read-only banner. Omit (the default) and\n * nothing extra renders — the existing subject-agnostic API is unchanged.\n * Provide both to opt in; a lone `signer` or `subject` renders nothing.\n */\n signedByNote?: { signer: string; subject: string };\n /** Disable all controls (document still readable). */\n disabled?: boolean;\n /** Render read-only: the document is shown but the pad is suppressed. */\n readOnly?: boolean;\n /** Accessible label for the component's group region. */\n ariaLabel?: string;\n /** Extra class names merged onto the outermost wrapper. */\n className?: string;\n}\n\n/** Curated imperative handle for agent / external automation. */\nexport interface SignDocumentHandle {\n /** Clear the captured signature, returning to the unsigned state. */\n reset: () => void;\n /** Confirm the current signature; resolves the payload, or null if unsigned. */\n confirm: () => Promise<SignatureConfirmPayload | null>;\n /** True when the reader has reached the last page (or the gate is off). */\n isReadComplete: () => boolean;\n}\n\n/* ------------------------------------------------------------------ */\n/* CVA */\n/* ------------------------------------------------------------------ */\n\nconst rootVariants = cva(\n [\n 'ds:flex ds:flex-col ds:gap-[var(--spacing-md)]',\n 'ds:rounded-[var(--radius-md)] ds:border ds:border-[color:var(--card-border)]',\n 'ds:shadow-[var(--shadow-card)] ds:[.theme-accessible_&]:border-2',\n 'ds:bg-[var(--background)] ds:text-[var(--foreground)]',\n 'ds:p-[var(--spacing-md)]',\n 'ds:aria-disabled:opacity-[var(--opacity-50)] ds:aria-disabled:cursor-not-allowed',\n ].join(' '),\n);\n\nconst headingVariants = cva(\n ['type-heading-sm ds:text-[var(--foreground)]'].join(' '),\n);\n\nconst signSectionVariants = cva(\n ['ds:flex ds:flex-col ds:gap-[var(--spacing-sm)]'].join(' '),\n);\n\nconst sectionLabelVariants = cva(\n ['type-body-sm ds:font-medium ds:text-[var(--foreground)]'].join(' '),\n);\n\nconst progressVariants = cva(\n [\n 'ds:inline-flex ds:items-center ds:gap-[var(--spacing-xs)]',\n 'type-body-sm ds:text-[var(--muted-foreground)]',\n ].join(' '),\n);\n\n// The \"scroll to the end to sign\" hint uses --info as a low-emphasis\n// informational tint — tokenised, logical-property insets, no accent over\n// arbitrary content.\nconst hintVariants = cva(\n [\n 'ds:flex ds:items-center ds:gap-[var(--spacing-xs)]',\n 'type-body-sm',\n 'ds:rounded-[var(--radius-sm)]',\n 'ds:ps-[var(--spacing-sm)] ds:pe-[var(--spacing-sm)]',\n 'ds:pt-[var(--spacing-xs)] ds:pb-[var(--spacing-xs)]',\n 'ds:bg-[color-mix(in_srgb,var(--info)_10%,transparent)]',\n 'ds:text-[var(--foreground)]',\n 'ds:border ds:border-[color:color-mix(in_srgb,var(--info)_40%,transparent)]',\n ].join(' '),\n);\n\nconst confirmButtonVariants = cva(\n [\n 'ds:inline-flex ds:inline-size-full ds:items-center ds:justify-center',\n 'ds:[min-block-size:var(--min-target-size)]',\n 'ds:[min-inline-size:var(--min-target-size)]',\n 'ds:gap-[var(--spacing-xs)]',\n 'ds:ps-[var(--spacing-md)] ds:pe-[var(--spacing-md)]',\n 'ds:pt-[var(--spacing-md)] ds:pb-[var(--spacing-md)]',\n 'ds:rounded-[var(--radius-sm)]',\n 'ds:bg-[var(--primary)] ds:text-[var(--primary-foreground)]',\n 'ds:text-[length:var(--font-size-base)] ds:font-medium',\n 'ds:transition-colors ds:duration-[var(--animation-duration)] ds:motion-reduce:transition-none',\n 'ds:hover:bg-[var(--primary-hover)]',\n 'ds:focus-visible:outline-[length:var(--focus-ring-width)]',\n 'ds:focus-visible:outline-solid',\n 'ds:focus-visible:outline-[var(--ring)]',\n 'ds:focus-visible:outline-offset-[length:var(--focus-ring-offset)]',\n 'ds:forced-colors:focus-visible:outline-[CanvasText]',\n 'ds:disabled:opacity-[var(--opacity-50)] ds:disabled:cursor-not-allowed',\n 'ds:disabled:hover:bg-[var(--primary)]',\n ].join(' '),\n);\n\n// The signed banner uses the semantic --success alias for the confirmed\n// state — never the raw ramp step (constraint §11).\nconst signedBannerVariants = cva(\n [\n 'ds:flex ds:items-center ds:gap-[var(--spacing-sm)]',\n 'ds:rounded-[var(--radius-sm)]',\n 'ds:ps-[var(--spacing-md)] ds:pe-[var(--spacing-md)]',\n 'ds:pt-[var(--spacing-sm)] ds:pb-[var(--spacing-sm)]',\n 'ds:bg-[color-mix(in_srgb,var(--success)_12%,transparent)]',\n 'ds:text-[var(--foreground)]',\n 'ds:border ds:border-[color:color-mix(in_srgb,var(--success)_45%,transparent)]',\n ].join(' '),\n);\n\n// The on-behalf attribution note. Low-emphasis muted text — it qualifies the\n// signature, it isn't an action. `placement` swaps the inset/spacing so the\n// same string reads correctly above the pad (a hint) and inside the signed\n// banner (a continuation of the signed copy).\nconst attributionVariants = cva(['type-body-sm'].join(' '), {\n variants: {\n placement: {\n pad: 'ds:text-[var(--muted-foreground)]',\n banner: 'ds:block ds:text-[var(--foreground)]',\n },\n },\n defaultVariants: { placement: 'pad' },\n});\n\n/* ------------------------------------------------------------------ */\n/* Helpers */\n/* ------------------------------------------------------------------ */\n\n/**\n * Format an ISO timestamp using the active i18n locale. Falls back to the\n * raw string if it can't be parsed so a malformed `signedAt` never throws.\n */\nfunction formatSignedAt(iso: string, locale: string): string {\n const date = new Date(iso);\n if (Number.isNaN(date.getTime())) return iso;\n try {\n return new Intl.DateTimeFormat(locale, {\n dateStyle: 'long',\n timeStyle: 'short',\n }).format(date);\n } catch {\n return date.toISOString();\n }\n}\n\n/* ------------------------------------------------------------------ */\n/* SignDocument */\n/* ------------------------------------------------------------------ */\n\nexport const SignDocument = forwardRef<SignDocumentHandle, SignDocumentProps>(\n (\n {\n id,\n src,\n documentTitle,\n requireReadToEnd = true,\n onSign,\n onError,\n signedAt = null,\n signedByNote,\n disabled = false,\n readOnly = false,\n ariaLabel,\n className,\n },\n ref,\n ) => {\n const { t, i18n } = useTranslation();\n const rawId = useId();\n const idSafe = useMemo(\n () => `sign-doc-${rawId.replace(/[^a-zA-Z0-9-_]/g, '')}`,\n [rawId],\n );\n const docHeadingId = `${idSafe}-doc-heading`;\n const signLabelId = `${idSafe}-sign-label`;\n const liveRegionId = `${idSafe}-live`;\n // Stable, static describedby target for the sign section + Confirm —\n // kept separate from the polite live region so describedby points at\n // unchanging text, not the transition announcer (which only carries\n // gate-met / signed announcements).\n const gateHintId = `${idSafe}-gate-hint`;\n\n const signatureRef = useRef<SignatureCaptureHandle>(null);\n\n const [numPages, setNumPages] = useState(0);\n const [currentPage, setCurrentPage] = useState(1);\n // True once the reader has reached the last page at least once. Sticky:\n // scrolling back up does not re-lock the signature.\n const [reachedEnd, setReachedEnd] = useState(false);\n // Mirrors the pad's ink state so the Confirm button re-renders when a\n // signature lands. SignatureCapture's isEmpty() is a sync ref read (no\n // re-render) and its onStart only fires on a DRAWN stroke — not on the\n // typed fallback. We poll the handle so both paths gate Confirm\n // identically; onStart/onClear below are immediate-feedback hints.\n const [hasSignature, setHasSignature] = useState(false);\n\n const isSigned = signedAt != null;\n const inert = disabled || readOnly || isSigned;\n\n // Latest callbacks via refs so the async confirm path never closes over\n // a stale prop.\n const onSignRef = useRef(onSign);\n const onErrorRef = useRef(onError);\n useEffect(() => {\n onSignRef.current = onSign;\n onErrorRef.current = onError;\n }, [onSign, onError]);\n\n /* ---- Per-document reset -------------------------------------- */\n // When the consumer swaps `src` to a NEW document, the previous \"read\n // complete\" state must NOT carry over — otherwise the new document\n // could be signed without being read. Reset the per-document state;\n // PDFViewer's onLoadComplete re-sets reachedEnd for single-page docs.\n useEffect(() => {\n setReachedEnd(false);\n setNumPages(0);\n setCurrentPage(1);\n setHasSignature(false);\n }, [src]);\n\n /* ---- Read-gate tracking -------------------------------------- */\n const handleLoadComplete = useCallback(\n (info: { numPages: number; title?: string }) => {\n setNumPages(info.numPages);\n // A single-page document is \"read to the end\" the moment it loads.\n if (info.numPages <= 1) setReachedEnd(true);\n },\n [],\n );\n\n const handlePageChange = useCallback((page: number) => {\n setCurrentPage(page);\n setNumPages((total) => {\n if (total > 0 && page >= total) setReachedEnd(true);\n return total;\n });\n }, []);\n\n const handleError = useCallback((error: Error) => {\n onErrorRef.current?.(error);\n }, []);\n\n /* ---- Signature-presence polling ------------------------------ */\n // Poll the pad's isEmpty() while the signing surface is live so the\n // Confirm button reflects both drawn AND typed signatures. Cheap\n // (a single boolean ref read on an interval); torn down when signed,\n // read-only, or unmounted.\n const signLive = !isSigned && !readOnly;\n useEffect(() => {\n if (!signLive) return undefined;\n const tick = (): void => {\n const pad = signatureRef.current;\n if (!pad) return;\n setHasSignature(!pad.isEmpty());\n };\n tick();\n const interval = window.setInterval(tick, 200);\n return () => window.clearInterval(interval);\n }, [signLive]);\n\n // The gate is satisfied when reading isn't required, or the reader has\n // reached the last page at least once.\n const readComplete = !requireReadToEnd || reachedEnd;\n const canSign = !inert && readComplete;\n const confirmDisabled = !canSign || !hasSignature;\n\n /* ---- Confirm path -------------------------------------------- */\n // `onSign` fires from SignatureCapture's `onConfirm` (wired below) — the\n // single source of truth, so it fires once whether the user clicks the\n // pad's own Confirm or this component's \"Confirm & sign\". This handle\n // just proxies the pad's confirm() and returns its payload.\n const handleSigned = useCallback((payload: SignatureConfirmPayload) => {\n onSignRef.current?.(payload);\n }, []);\n\n const confirm =\n useCallback(async (): Promise<SignatureConfirmPayload | null> => {\n const pad = signatureRef.current;\n if (!pad) return null;\n return pad.confirm();\n }, []);\n\n const reset = useCallback(() => {\n signatureRef.current?.clear();\n setHasSignature(false);\n }, []);\n\n /* ---- Imperative handle + agent registration ------------------ */\n const agentHandle = useMemo<SignDocumentHandle>(\n () => ({\n reset,\n confirm,\n isReadComplete: () => readComplete,\n }),\n [reset, confirm, readComplete],\n );\n useImperativeHandle(ref, () => agentHandle, [agentHandle]);\n useAgentRegistration(signDocumentAgent, agentHandle, id);\n\n /* ---- Derived strings ----------------------------------------- */\n const regionLabel =\n ariaLabel ??\n (documentTitle\n ? t('signDocument.regionLabelNamed', { title: documentTitle })\n : t('signDocument.regionLabel'));\n const documentRegionLabel =\n documentTitle ?? t('signDocument.documentLabel');\n\n // Live region — ONLY transition announcements (gate met / signed).\n const liveText = isSigned\n ? t('signDocument.signedOn', {\n date: formatSignedAt(signedAt as string, i18n.language),\n })\n : readComplete\n ? t('signDocument.readyToSign')\n : '';\n\n // Static describedby target — always names WHY Confirm is unavailable\n // (or stays empty when it's actionable). Stable text, never live.\n const gateHintText = !readComplete\n ? t('signDocument.scrollToEnd')\n : !hasSignature\n ? t('signDocument.signToEnable')\n : '';\n\n // On-behalf attribution — only when BOTH signer and subject are present\n // (a lone half is meaningless). Rendered above the pad and in the signed\n // banner. Optional: undefined → no attribution, API unchanged.\n const attributionText =\n signedByNote?.signer && signedByNote?.subject\n ? t('signDocument.signedByOnBehalf', {\n signer: signedByNote.signer,\n subject: signedByNote.subject,\n })\n : null;\n\n return (\n <div\n role=\"group\"\n // Prefer labelling by the visible heading so the visible + accessible\n // names match; fall back to aria-label only when there's no heading.\n aria-labelledby={!ariaLabel && documentTitle ? docHeadingId : undefined}\n aria-label={ariaLabel || !documentTitle ? regionLabel : undefined}\n aria-disabled={disabled || undefined}\n className={[rootVariants(), className].filter(Boolean).join(' ')}\n data-component=\"sign-document\"\n data-component-id={id}\n data-signed={isSigned || undefined}\n >\n {/* Polite live region — ONLY transition announcements (gate met /\n signed). Static describedby text lives in the gate-hint span. */}\n <span\n role=\"status\"\n aria-live=\"polite\"\n aria-atomic=\"true\"\n className=\"ds:sr-only\"\n data-testid=\"sign-document-live\"\n id={liveRegionId}\n >\n {liveText}\n </span>\n\n {/* Static, non-live describedby target for the sign group + Confirm:\n names why Confirm is unavailable (or empty when actionable). */}\n <span className=\"ds:sr-only\" id={gateHintId}>\n {gateHintText}\n </span>\n\n {documentTitle ? (\n <h2 id={docHeadingId} className={headingVariants()}>\n {documentTitle}\n </h2>\n ) : null}\n\n {/* The document. PDFViewer owns its own toolbar, a11y, and zoom. */}\n <PDFViewer\n src={src}\n ariaLabel={documentRegionLabel}\n onLoadComplete={handleLoadComplete}\n onPageChange={handlePageChange}\n onError={handleError}\n />\n\n {isSigned ? (\n /* ---- Already-signed, read-only ---- */\n <div\n className={signedBannerVariants()}\n data-testid=\"sign-document-signed\"\n >\n <CheckCircle2\n aria-hidden=\"true\"\n className=\"ds:size-5 ds:text-[var(--success)] ds:shrink-0\"\n />\n <span className=\"type-body-sm\">\n <strong className=\"ds:font-semibold\">\n {t('signDocument.signed')}\n </strong>\n {' — '}\n {t('signDocument.signedOn', {\n date: formatSignedAt(signedAt as string, i18n.language),\n })}\n {attributionText ? (\n <span\n className={attributionVariants({ placement: 'banner' })}\n data-testid=\"sign-document-attribution\"\n >\n {attributionText}\n </span>\n ) : null}\n </span>\n </div>\n ) : readOnly ? null : (\n /* ---- Sign surface ---- */\n <div\n className={signSectionVariants()}\n role=\"group\"\n aria-labelledby={signLabelId}\n aria-describedby={gateHintId}\n >\n <div className=\"ds:flex ds:flex-wrap ds:items-center ds:justify-between ds:gap-[var(--spacing-sm)]\">\n <span id={signLabelId} className={sectionLabelVariants()}>\n {t('signDocument.signatureSection')}\n </span>\n {numPages > 0 ? (\n <span\n className={progressVariants()}\n data-testid=\"sign-document-progress\"\n >\n {t('signDocument.pageProgress', {\n current: currentPage,\n total: numPages,\n })}\n </span>\n ) : null}\n </div>\n\n {attributionText ? (\n <p\n className={attributionVariants({ placement: 'pad' })}\n data-testid=\"sign-document-attribution\"\n >\n {attributionText}\n </p>\n ) : null}\n\n {requireReadToEnd && !readComplete ? (\n <p className={hintVariants()} data-testid=\"sign-document-hint\">\n {t('signDocument.scrollToEnd')}\n </p>\n ) : null}\n\n {/* The pad is always mounted so a keyboard user can prepare a\n typed signature; the Confirm button is the gate. When the\n read-gate is unmet the pad is disabled so it can't accept\n ink prematurely. */}\n <SignatureCapture\n ref={signatureRef}\n ariaLabel={t('signDocument.signatureSection')}\n disabled={disabled || !readComplete}\n onStart={() => setHasSignature(true)}\n onClear={() => setHasSignature(false)}\n onConfirm={handleSigned}\n />\n\n {/* Native `disabled` (not aria-disabled) so a gated Confirm\n leaves the tab order entirely — mirrors how Button gates a\n primary action. describedby names WHY it's unavailable. */}\n <button\n type=\"button\"\n onClick={() => {\n if (confirmDisabled) return;\n void confirm();\n }}\n disabled={confirmDisabled}\n aria-describedby={gateHintId}\n className={confirmButtonVariants()}\n data-testid=\"sign-document-confirm\"\n >\n <CheckCircle2 aria-hidden=\"true\" className=\"ds:size-4\" />\n {t('signDocument.confirm')}\n </button>\n </div>\n )}\n </div>\n );\n },\n);\n\nSignDocument.displayName = 'SignDocument';\n\nexport { rootVariants as signDocumentRootVariants };\n"],"names":["signDocumentAgent","handle","rootVariants","cva","headingVariants","signSectionVariants","sectionLabelVariants","progressVariants","hintVariants","confirmButtonVariants","signedBannerVariants","attributionVariants","formatSignedAt","iso","locale","date","SignDocument","forwardRef","id","src","documentTitle","requireReadToEnd","onSign","onError","signedAt","signedByNote","disabled","readOnly","ariaLabel","className","ref","t","i18n","useTranslation","rawId","useId","idSafe","useMemo","docHeadingId","signLabelId","liveRegionId","gateHintId","signatureRef","useRef","numPages","setNumPages","useState","currentPage","setCurrentPage","reachedEnd","setReachedEnd","hasSignature","setHasSignature","isSigned","inert","onSignRef","onErrorRef","useEffect","handleLoadComplete","useCallback","info","handlePageChange","page","total","handleError","error","_a","signLive","tick","pad","interval","readComplete","confirmDisabled","handleSigned","payload","confirm","reset","agentHandle","useImperativeHandle","useAgentRegistration","regionLabel","documentRegionLabel","liveText","gateHintText","attributionText","jsxs","jsx","PDFViewer","CheckCircle2","SignatureCapture"],"mappings":";;;;;;;;AAaO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;AAAA,IAAA;AAAA,EAIR;AACF;AAEAf,GAAa,cAAc;"}
1
+ {"version":3,"file":"sign-document-BmAT0kKD.js","sources":["../../src/components/sign-document/sign-document.agent.ts","../../src/components/sign-document/sign-document.tsx"],"sourcesContent":["/* -------------------------------------------------------------------- */\n/* Agent adapter — SignDocument. */\n/* */\n/* State exposes only structural lifecycle info — never the signature */\n/* bytes (the signed consent is sensitive; persistence is the consumer's */\n/* concern). The single write action confirms the captured signature. */\n/* */\n/* See `src/docs/26-agent-readiness.mdx` for the contract. */\n/* -------------------------------------------------------------------- */\n\nimport type { AgentAdapter } from '../../agent/types';\nimport type { SignDocumentHandle } from './sign-document';\n\nexport const signDocumentAgent: AgentAdapter<SignDocumentHandle> = {\n id: 'sign-document',\n capabilities: ['submit'],\n state: {\n isReadComplete: {\n type: 'boolean',\n descriptionKey: 'signDocument.agent.state.isReadComplete',\n description:\n 'True when the reader has reached the last page (or read-gating is off).',\n read: (handle) => handle.isReadComplete(),\n },\n },\n actions: {\n submit: {\n safety: 'write',\n descriptionKey: 'signDocument.agent.actions.confirm',\n description:\n 'Confirm the current signature, emitting it via onSign. No-op if unsigned.',\n invoke: (handle) => handle.confirm(),\n },\n reset: {\n safety: 'destructive',\n descriptionKey: 'signDocument.agent.actions.reset',\n description: 'Clear the captured signature and return to unsigned.',\n invoke: (handle) => {\n handle.reset();\n },\n },\n },\n domHooks: {\n root: {\n attr: 'data-component',\n value: 'sign-document',\n description: 'Marks the SignDocument wrapper.',\n },\n instanceId: {\n attr: 'data-component-id',\n sourceProp: 'id',\n description: 'Sourced from the id prop.',\n },\n },\n};\n","/* ------------------------------------------------------------------ */\n/* SignDocument — review a PDF document, then sign it. */\n/* */\n/* Fills the kit gap where consumers hand-composed PDFViewer + */\n/* SignatureCapture for consents (e.g. sign.alfadocs.com, HTP-4889). */\n/* This component owns the composition and the read-gate so the consent */\n/* flow is a single primitive: */\n/* */\n/* - PDFViewer (the document) renders above; the signing surface */\n/* renders below. */\n/* - When `requireReadToEnd` (default), the SignatureCapture pad and */\n/* the \"Confirm & sign\" button are gated until the reader reaches the */\n/* LAST page. We track this via PDFViewer's onLoadComplete (numPages) */\n/* + onPageChange (currentPage === numPages). NOTE: last-page-reached */\n/* is an APPROXIMATE read signal — a fit-page zoom can show the last */\n/* page without scrolling. That is acceptable for this gate; a */\n/* legal-grade \"read every page\" guarantee is the consumer's call. */\n/* - When `signedAt` is set the component renders an already-signed */\n/* read-only state (no pad) so re-sign-on-change consumers can show */\n/* signed status. */\n/* - Security: no fetch / XHR / storage / globals here. SignatureCapture */\n/* owns the export payload (PNG/SVG + sha256); the consumer owns */\n/* persistence via onSign. */\n/* - i18n: every authored string via `t('signDocument.*')` (bare keys */\n/* under the `ui` namespace). PDFViewer's `pdf.*` and */\n/* SignatureCapture's `signature.*` strings already exist. */\n/* ------------------------------------------------------------------ */\n\nimport {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { cva } from 'class-variance-authority';\nimport { useTranslation } from 'react-i18next';\nimport { CheckCircle2 } from 'lucide-react';\nimport { PDFViewer } from '../pdf-viewer';\nimport {\n SignatureCapture,\n type SignatureCaptureHandle,\n type SignatureConfirmPayload,\n} from '../signature-capture';\nimport { useAgentRegistration } from '../../agent';\nimport { signDocumentAgent } from './sign-document.agent';\n\n/* ------------------------------------------------------------------ */\n/* Public types */\n/* ------------------------------------------------------------------ */\n\nexport interface SignDocumentProps {\n /** Opaque instance id — emitted as `data-component-id` for the agent registry. */\n id?: string;\n /** Document PDF — URL string, ArrayBuffer, or Uint8Array. Passed to PDFViewer. */\n src: string | ArrayBuffer | Uint8Array;\n /** Accessible name for the document region (also used as a heading). */\n documentTitle?: string;\n /**\n * Gate the signature + Confirm until the reader reaches the last page.\n * Default `true`. Last-page-reached is an approximate read signal (a\n * fit-page zoom can show the last page without scrolling) — adequate for\n * this gate; legal-grade read tracking is the consumer's concern.\n */\n requireReadToEnd?: boolean;\n /** Fired when the user captures a signature AND confirms. */\n onSign?: (payload: SignatureConfirmPayload) => void;\n /** Forwarded from PDFViewer on any load / render error. */\n onError?: (error: Error) => void;\n /**\n * When set, render the already-signed read-only state: shows \"Signed\" +\n * the signed date and hides the pad. Use for re-sign-on-change consumers\n * that surface signed status. `null` / `undefined` → unsigned.\n */\n signedAt?: string | null;\n /**\n * Optional on-behalf attribution. When both `signer` and `subject` are\n * given, a \"Signed by {signer} on behalf of {subject}\" note renders both\n * near the signature pad (so the signer sees who they're signing for) AND\n * inside the already-signed read-only banner. Omit (the default) and\n * nothing extra renders — the existing subject-agnostic API is unchanged.\n * Provide both to opt in; a lone `signer` or `subject` renders nothing.\n */\n signedByNote?: { signer: string; subject: string };\n /** Disable all controls (document still readable). */\n disabled?: boolean;\n /** Render read-only: the document is shown but the pad is suppressed. */\n readOnly?: boolean;\n /** Accessible label for the component's group region. */\n ariaLabel?: string;\n /** Extra class names merged onto the outermost wrapper. */\n className?: string;\n}\n\n/** Curated imperative handle for agent / external automation. */\nexport interface SignDocumentHandle {\n /** Clear the captured signature, returning to the unsigned state. */\n reset: () => void;\n /** Confirm the current signature; resolves the payload, or null if unsigned. */\n confirm: () => Promise<SignatureConfirmPayload | null>;\n /** True when the reader has reached the last page (or the gate is off). */\n isReadComplete: () => boolean;\n}\n\n/* ------------------------------------------------------------------ */\n/* CVA */\n/* ------------------------------------------------------------------ */\n\nconst rootVariants = cva(\n [\n 'ds:flex ds:flex-col ds:gap-[var(--spacing-md)]',\n 'ds:rounded-[var(--radius-md)] ds:border ds:border-[color:var(--card-border)]',\n 'ds:shadow-[var(--shadow-card)] ds:[.theme-accessible_&]:border-2',\n 'ds:bg-[var(--background)] ds:text-[var(--foreground)]',\n 'ds:p-[var(--spacing-md)]',\n 'ds:aria-disabled:opacity-[var(--opacity-50)] ds:aria-disabled:cursor-not-allowed',\n ].join(' '),\n);\n\nconst headingVariants = cva(\n ['type-heading-sm ds:text-[var(--foreground)]'].join(' '),\n);\n\nconst signSectionVariants = cva(\n ['ds:flex ds:flex-col ds:gap-[var(--spacing-sm)]'].join(' '),\n);\n\nconst sectionLabelVariants = cva(\n ['type-body-sm ds:font-medium ds:text-[var(--foreground)]'].join(' '),\n);\n\nconst progressVariants = cva(\n [\n 'ds:inline-flex ds:items-center ds:gap-[var(--spacing-xs)]',\n 'type-body-sm ds:text-[var(--muted-foreground)]',\n ].join(' '),\n);\n\n// The \"scroll to the end to sign\" hint uses --info as a low-emphasis\n// informational tint — tokenised, logical-property insets, no accent over\n// arbitrary content.\nconst hintVariants = cva(\n [\n 'ds:flex ds:items-center ds:gap-[var(--spacing-xs)]',\n 'type-body-sm',\n 'ds:rounded-[var(--radius-sm)]',\n 'ds:ps-[var(--spacing-sm)] ds:pe-[var(--spacing-sm)]',\n 'ds:pt-[var(--spacing-xs)] ds:pb-[var(--spacing-xs)]',\n 'ds:bg-[color-mix(in_srgb,var(--info)_10%,transparent)]',\n 'ds:text-[var(--foreground)]',\n 'ds:border ds:border-[color:color-mix(in_srgb,var(--info)_40%,transparent)]',\n ].join(' '),\n);\n\nconst confirmButtonVariants = cva(\n [\n 'ds:inline-flex ds:inline-size-full ds:items-center ds:justify-center',\n 'ds:[min-block-size:var(--min-target-size)]',\n 'ds:[min-inline-size:var(--min-target-size)]',\n 'ds:gap-[var(--spacing-xs)]',\n 'ds:ps-[var(--spacing-md)] ds:pe-[var(--spacing-md)]',\n 'ds:pt-[var(--spacing-md)] ds:pb-[var(--spacing-md)]',\n 'ds:rounded-[var(--radius-sm)]',\n 'ds:bg-[var(--primary)] ds:text-[var(--primary-foreground)]',\n 'ds:text-[length:var(--font-size-base)] ds:font-medium',\n 'ds:transition-colors ds:duration-[var(--animation-duration)] ds:motion-reduce:transition-none',\n 'ds:hover:bg-[var(--primary-hover)]',\n 'ds:focus-visible:outline-[length:var(--focus-ring-width)]',\n 'ds:focus-visible:outline-solid',\n 'ds:focus-visible:outline-[var(--ring)]',\n 'ds:focus-visible:outline-offset-[length:var(--focus-ring-offset)]',\n 'ds:forced-colors:focus-visible:outline-[CanvasText]',\n 'ds:disabled:opacity-[var(--opacity-50)] ds:disabled:cursor-not-allowed',\n 'ds:disabled:hover:bg-[var(--primary)]',\n ].join(' '),\n);\n\n// The signed banner uses the semantic --success alias for the confirmed\n// state — never the raw ramp step (constraint §11).\nconst signedBannerVariants = cva(\n [\n 'ds:flex ds:items-center ds:gap-[var(--spacing-sm)]',\n 'ds:rounded-[var(--radius-sm)]',\n 'ds:ps-[var(--spacing-md)] ds:pe-[var(--spacing-md)]',\n 'ds:pt-[var(--spacing-sm)] ds:pb-[var(--spacing-sm)]',\n 'ds:bg-[color-mix(in_srgb,var(--success)_12%,transparent)]',\n 'ds:text-[var(--foreground)]',\n 'ds:border ds:border-[color:color-mix(in_srgb,var(--success)_45%,transparent)]',\n ].join(' '),\n);\n\n// The on-behalf attribution note. Low-emphasis muted text — it qualifies the\n// signature, it isn't an action. `placement` swaps the inset/spacing so the\n// same string reads correctly above the pad (a hint) and inside the signed\n// banner (a continuation of the signed copy).\nconst attributionVariants = cva(['type-body-sm'].join(' '), {\n variants: {\n placement: {\n pad: 'ds:text-[var(--muted-foreground)]',\n banner: 'ds:block ds:text-[var(--foreground)]',\n },\n },\n defaultVariants: { placement: 'pad' },\n});\n\n/* ------------------------------------------------------------------ */\n/* Helpers */\n/* ------------------------------------------------------------------ */\n\n/**\n * Format an ISO timestamp using the active i18n locale. Falls back to the\n * raw string if it can't be parsed so a malformed `signedAt` never throws.\n */\nfunction formatSignedAt(iso: string, locale: string): string {\n const date = new Date(iso);\n if (Number.isNaN(date.getTime())) return iso;\n try {\n return new Intl.DateTimeFormat(locale, {\n dateStyle: 'long',\n timeStyle: 'short',\n }).format(date);\n } catch {\n return date.toISOString();\n }\n}\n\n/* ------------------------------------------------------------------ */\n/* SignDocument */\n/* ------------------------------------------------------------------ */\n\nexport const SignDocument = forwardRef<SignDocumentHandle, SignDocumentProps>(\n (\n {\n id,\n src,\n documentTitle,\n requireReadToEnd = true,\n onSign,\n onError,\n signedAt = null,\n signedByNote,\n disabled = false,\n readOnly = false,\n ariaLabel,\n className,\n },\n ref,\n ) => {\n const { t, i18n } = useTranslation();\n const rawId = useId();\n const idSafe = useMemo(\n () => `sign-doc-${rawId.replace(/[^a-zA-Z0-9-_]/g, '')}`,\n [rawId],\n );\n const docHeadingId = `${idSafe}-doc-heading`;\n const signLabelId = `${idSafe}-sign-label`;\n const liveRegionId = `${idSafe}-live`;\n // Stable, static describedby target for the sign section + Confirm —\n // kept separate from the polite live region so describedby points at\n // unchanging text, not the transition announcer (which only carries\n // gate-met / signed announcements).\n const gateHintId = `${idSafe}-gate-hint`;\n\n const signatureRef = useRef<SignatureCaptureHandle>(null);\n\n const [numPages, setNumPages] = useState(0);\n const [currentPage, setCurrentPage] = useState(1);\n // True once the reader has reached the last page at least once. Sticky:\n // scrolling back up does not re-lock the signature.\n const [reachedEnd, setReachedEnd] = useState(false);\n // Mirrors the pad's ink state so the Confirm button re-renders when a\n // signature lands. SignatureCapture's isEmpty() is a sync ref read (no\n // re-render) and its onStart only fires on a DRAWN stroke — not on the\n // typed fallback. We poll the handle so both paths gate Confirm\n // identically; onStart/onClear below are immediate-feedback hints.\n const [hasSignature, setHasSignature] = useState(false);\n\n const isSigned = signedAt != null;\n const inert = disabled || readOnly || isSigned;\n\n // Latest callbacks via refs so the async confirm path never closes over\n // a stale prop.\n const onSignRef = useRef(onSign);\n const onErrorRef = useRef(onError);\n useEffect(() => {\n onSignRef.current = onSign;\n onErrorRef.current = onError;\n }, [onSign, onError]);\n\n /* ---- Per-document reset -------------------------------------- */\n // When the consumer swaps `src` to a NEW document, the previous \"read\n // complete\" state must NOT carry over — otherwise the new document\n // could be signed without being read. Reset the per-document state;\n // PDFViewer's onLoadComplete re-sets reachedEnd for single-page docs.\n useEffect(() => {\n setReachedEnd(false);\n setNumPages(0);\n setCurrentPage(1);\n setHasSignature(false);\n }, [src]);\n\n /* ---- Read-gate tracking -------------------------------------- */\n const handleLoadComplete = useCallback(\n (info: { numPages: number; title?: string }) => {\n setNumPages(info.numPages);\n // A single-page document is \"read to the end\" the moment it loads.\n if (info.numPages <= 1) setReachedEnd(true);\n },\n [],\n );\n\n const handlePageChange = useCallback((page: number) => {\n setCurrentPage(page);\n setNumPages((total) => {\n if (total > 0 && page >= total) setReachedEnd(true);\n return total;\n });\n }, []);\n\n const handleError = useCallback((error: Error) => {\n onErrorRef.current?.(error);\n }, []);\n\n /* ---- Signature-presence polling ------------------------------ */\n // Poll the pad's isEmpty() while the signing surface is live so the\n // Confirm button reflects both drawn AND typed signatures. Cheap\n // (a single boolean ref read on an interval); torn down when signed,\n // read-only, or unmounted.\n const signLive = !isSigned && !readOnly;\n useEffect(() => {\n if (!signLive) return undefined;\n const tick = (): void => {\n const pad = signatureRef.current;\n if (!pad) return;\n setHasSignature(!pad.isEmpty());\n };\n tick();\n const interval = window.setInterval(tick, 200);\n return () => window.clearInterval(interval);\n }, [signLive]);\n\n // The gate is satisfied when reading isn't required, or the reader has\n // reached the last page at least once.\n const readComplete = !requireReadToEnd || reachedEnd;\n const canSign = !inert && readComplete;\n const confirmDisabled = !canSign || !hasSignature;\n\n /* ---- Confirm path -------------------------------------------- */\n // `onSign` fires from SignatureCapture's `onConfirm` (wired below) — the\n // single source of truth, so it fires once whether the user clicks the\n // pad's own Confirm or this component's \"Confirm & sign\". This handle\n // just proxies the pad's confirm() and returns its payload.\n const handleSigned = useCallback((payload: SignatureConfirmPayload) => {\n onSignRef.current?.(payload);\n }, []);\n\n const confirm =\n useCallback(async (): Promise<SignatureConfirmPayload | null> => {\n const pad = signatureRef.current;\n if (!pad) return null;\n return pad.confirm();\n }, []);\n\n const reset = useCallback(() => {\n signatureRef.current?.clear();\n setHasSignature(false);\n }, []);\n\n /* ---- Imperative handle + agent registration ------------------ */\n const agentHandle = useMemo<SignDocumentHandle>(\n () => ({\n reset,\n confirm,\n isReadComplete: () => readComplete,\n }),\n [reset, confirm, readComplete],\n );\n useImperativeHandle(ref, () => agentHandle, [agentHandle]);\n useAgentRegistration(signDocumentAgent, agentHandle, id);\n\n /* ---- Derived strings ----------------------------------------- */\n const regionLabel =\n ariaLabel ??\n (documentTitle\n ? t('signDocument.regionLabelNamed', { title: documentTitle })\n : t('signDocument.regionLabel'));\n const documentRegionLabel =\n documentTitle ?? t('signDocument.documentLabel');\n\n // Live region — ONLY transition announcements (gate met / signed).\n const liveText = isSigned\n ? t('signDocument.signedOn', {\n date: formatSignedAt(signedAt as string, i18n.language),\n })\n : readComplete\n ? t('signDocument.readyToSign')\n : '';\n\n // Static describedby target — always names WHY Confirm is unavailable\n // (or stays empty when it's actionable). Stable text, never live.\n const gateHintText = !readComplete\n ? t('signDocument.scrollToEnd')\n : !hasSignature\n ? t('signDocument.signToEnable')\n : '';\n\n // On-behalf attribution — only when BOTH signer and subject are present\n // (a lone half is meaningless). Rendered above the pad and in the signed\n // banner. Optional: undefined → no attribution, API unchanged.\n const attributionText =\n signedByNote?.signer && signedByNote?.subject\n ? t('signDocument.signedByOnBehalf', {\n signer: signedByNote.signer,\n subject: signedByNote.subject,\n })\n : null;\n\n return (\n <div\n role=\"group\"\n // Prefer labelling by the visible heading so the visible + accessible\n // names match; fall back to aria-label only when there's no heading.\n aria-labelledby={!ariaLabel && documentTitle ? docHeadingId : undefined}\n aria-label={ariaLabel || !documentTitle ? regionLabel : undefined}\n aria-disabled={disabled || undefined}\n className={[rootVariants(), className].filter(Boolean).join(' ')}\n data-component=\"sign-document\"\n data-component-id={id}\n data-signed={isSigned || undefined}\n >\n {/* Polite live region — ONLY transition announcements (gate met /\n signed). Static describedby text lives in the gate-hint span. */}\n <span\n role=\"status\"\n aria-live=\"polite\"\n aria-atomic=\"true\"\n className=\"ds:sr-only\"\n data-testid=\"sign-document-live\"\n id={liveRegionId}\n >\n {liveText}\n </span>\n\n {/* Static, non-live describedby target for the sign group + Confirm:\n names why Confirm is unavailable (or empty when actionable). */}\n <span className=\"ds:sr-only\" id={gateHintId}>\n {gateHintText}\n </span>\n\n {documentTitle ? (\n <h2 id={docHeadingId} className={headingVariants()}>\n {documentTitle}\n </h2>\n ) : null}\n\n {/* The document. PDFViewer owns its own toolbar, a11y, and zoom. */}\n <PDFViewer\n src={src}\n ariaLabel={documentRegionLabel}\n onLoadComplete={handleLoadComplete}\n onPageChange={handlePageChange}\n onError={handleError}\n />\n\n {isSigned ? (\n /* ---- Already-signed, read-only ---- */\n <div\n className={signedBannerVariants()}\n data-testid=\"sign-document-signed\"\n >\n <CheckCircle2\n aria-hidden=\"true\"\n className=\"ds:size-5 ds:text-[var(--success)] ds:shrink-0\"\n />\n <span className=\"type-body-sm\">\n <strong className=\"ds:font-semibold\">\n {t('signDocument.signed')}\n </strong>\n {' — '}\n {t('signDocument.signedOn', {\n date: formatSignedAt(signedAt as string, i18n.language),\n })}\n {attributionText ? (\n <span\n className={attributionVariants({ placement: 'banner' })}\n data-testid=\"sign-document-attribution\"\n >\n {attributionText}\n </span>\n ) : null}\n </span>\n </div>\n ) : readOnly ? null : (\n /* ---- Sign surface ---- */\n <div\n className={signSectionVariants()}\n role=\"group\"\n aria-labelledby={signLabelId}\n aria-describedby={gateHintId}\n >\n <div className=\"ds:flex ds:flex-wrap ds:items-center ds:justify-between ds:gap-[var(--spacing-sm)]\">\n <span id={signLabelId} className={sectionLabelVariants()}>\n {t('signDocument.signatureSection')}\n </span>\n {numPages > 0 ? (\n <span\n className={progressVariants()}\n data-testid=\"sign-document-progress\"\n >\n {t('signDocument.pageProgress', {\n current: currentPage,\n total: numPages,\n })}\n </span>\n ) : null}\n </div>\n\n {attributionText ? (\n <p\n className={attributionVariants({ placement: 'pad' })}\n data-testid=\"sign-document-attribution\"\n >\n {attributionText}\n </p>\n ) : null}\n\n {requireReadToEnd && !readComplete ? (\n <p className={hintVariants()} data-testid=\"sign-document-hint\">\n {t('signDocument.scrollToEnd')}\n </p>\n ) : null}\n\n {/* The pad is always mounted so a keyboard user can prepare a\n typed signature; the Confirm button is the gate. When the\n read-gate is unmet the pad is disabled so it can't accept\n ink prematurely. */}\n <SignatureCapture\n ref={signatureRef}\n ariaLabel={t('signDocument.signatureSection')}\n disabled={disabled || !readComplete}\n onStart={() => setHasSignature(true)}\n onClear={() => setHasSignature(false)}\n onConfirm={handleSigned}\n />\n\n {/* Native `disabled` (not aria-disabled) so a gated Confirm\n leaves the tab order entirely — mirrors how Button gates a\n primary action. describedby names WHY it's unavailable. */}\n <button\n type=\"button\"\n onClick={() => {\n if (confirmDisabled) return;\n void confirm();\n }}\n disabled={confirmDisabled}\n aria-describedby={gateHintId}\n className={confirmButtonVariants()}\n data-testid=\"sign-document-confirm\"\n >\n <CheckCircle2 aria-hidden=\"true\" className=\"ds:size-4\" />\n {t('signDocument.confirm')}\n </button>\n </div>\n )}\n </div>\n );\n },\n);\n\nSignDocument.displayName = 'SignDocument';\n\nexport { rootVariants as signDocumentRootVariants };\n"],"names":["signDocumentAgent","handle","rootVariants","cva","headingVariants","signSectionVariants","sectionLabelVariants","progressVariants","hintVariants","confirmButtonVariants","signedBannerVariants","attributionVariants","formatSignedAt","iso","locale","date","SignDocument","forwardRef","id","src","documentTitle","requireReadToEnd","onSign","onError","signedAt","signedByNote","disabled","readOnly","ariaLabel","className","ref","t","i18n","useTranslation","rawId","useId","idSafe","useMemo","docHeadingId","signLabelId","liveRegionId","gateHintId","signatureRef","useRef","numPages","setNumPages","useState","currentPage","setCurrentPage","reachedEnd","setReachedEnd","hasSignature","setHasSignature","isSigned","inert","onSignRef","onErrorRef","useEffect","handleLoadComplete","useCallback","info","handlePageChange","page","total","handleError","error","_a","signLive","tick","pad","interval","readComplete","confirmDisabled","handleSigned","payload","confirm","reset","agentHandle","useImperativeHandle","useAgentRegistration","regionLabel","documentRegionLabel","liveText","gateHintText","attributionText","jsxs","jsx","PDFViewer","CheckCircle2","SignatureCapture"],"mappings":";;;;;;;;AAaO,MAAMA,KAAsD;AAAA,EACjE,IAAI;AAAA,EACJ,cAAc,CAAC,QAAQ;AAAA,EACvB,OA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
57
  ), Ee = R(
58
58
  [
59
59
  "ds:relative ds:block",
60
- "ds:inline-size-[var(--signature-width)]",
61
- "ds:block-size-[var(--signature-height)]",
60
+ // Mobile-first: fill the available width but never exceed the configured
61
+ // pad width. Arbitrary-property form because `inline-size-[]` /
62
+ // `block-size-[…]` named utilities emit no CSS here (see canvasVariants).
63
+ "ds:[inline-size:100%]",
64
+ "ds:[max-inline-size:var(--signature-width)]",
65
+ "ds:[block-size:var(--signature-height)]",
62
66
  "ds:rounded-[var(--radius-sm)]",
63
67
  "ds:border ds:border-[color:var(--border)]",
64
68
  "ds:bg-[var(--background)]",
@@ -72,8 +76,16 @@ const je = {
72
76
  ), $e = R(
73
77
  [
74
78
  "ds:block",
75
- "ds:inline-size-full",
76
- "ds:block-size-full",
79
+ // Arbitrary-property form, NOT `inline-size-full` / `block-size-full`:
80
+ // the `inline-size-*` / `block-size-*` named utilities generate no CSS in
81
+ // this Tailwind setup, so on a block <div> they silently fall back to auto
82
+ // (harmless) but on a replaced <canvas> the element then sizes to its
83
+ // backing-store `width`/`height` attribute — which scaleCanvas drives up to
84
+ // MAX_CANVAS_PX (4096) in a feedback loop, overflowing the pad on mobile.
85
+ // The `[property:value]` escape hatch always emits, pinning the canvas to
86
+ // the frame so the loop can't run away.
87
+ "ds:[inline-size:100%]",
88
+ "ds:[block-size:100%]",
77
89
  "ds:touch-none",
78
90
  "ds:select-none"
79
91
  ].join(" ")
@@ -141,8 +153,11 @@ const je = {
141
153
  ), Ie = R(
142
154
  [
143
155
  "ds:flex ds:items-center ds:justify-center",
144
- "ds:inline-size-[var(--signature-width)]",
145
- "ds:block-size-[var(--signature-height)]",
156
+ // Match the pad frame: responsive width capped at the configured size.
157
+ // Arbitrary-property form (the named `*-size-[…]` utilities are no-ops here).
158
+ "ds:[inline-size:100%]",
159
+ "ds:[max-inline-size:var(--signature-width)]",
160
+ "ds:[block-size:var(--signature-height)]",
146
161
  "ds:rounded-[var(--radius-sm)]",
147
162
  "ds:border ds:border-[color:var(--card-border)]",
148
163
  "ds:[.theme-accessible_&]:border-2",
@@ -501,4 +516,4 @@ export {
501
516
  We as S,
502
517
  je as s
503
518
  };
504
- //# sourceMappingURL=signature-capture-CHbrKoA_.js.map
519
+ //# sourceMappingURL=signature-capture-COi0Uiqu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature-capture-COi0Uiqu.js","sources":["../../src/components/signature-capture/signature-capture.agent.ts","../../src/components/signature-capture/signature-capture.tsx"],"sourcesContent":["import type { AgentAdapter } from '../../agent/types';\nimport type { SignatureCaptureHandle } from './signature-capture';\n\nexport const signatureCaptureAgent: AgentAdapter<SignatureCaptureHandle> = {\n id: 'signature-capture',\n capabilities: ['edit_inline', 'submit'],\n state: {\n isEmpty: {\n type: 'boolean',\n description: 'True when no signature has been drawn or typed.',\n read: (handle) => handle.isEmpty(),\n },\n },\n actions: {\n clear: {\n safety: 'destructive',\n description: 'Erase the current signature. Loses unsaved input.',\n invoke: (handle) => {\n handle.clear();\n },\n },\n undo: {\n safety: 'write',\n description: 'Undo the last stroke.',\n invoke: (handle) => {\n handle.undo();\n },\n },\n confirm: {\n safety: 'write',\n description: 'Commit the signature and return its serialised payload.',\n invoke: (handle) => handle.confirm(),\n },\n },\n domHooks: {\n root: { attr: 'data-component', value: 'signature-capture' },\n instanceId: {\n attr: 'data-component-id',\n sourceProp: 'id',\n description: 'Sourced from the id prop.',\n },\n },\n};\n","/* ------------------------------------------------------------------ */\n/* SignatureCapture — thin React wrapper over signature_pad. */\n/* */\n/* - Library: `signature_pad` (08-third-party §Signature Pad). We */\n/* instantiate one pad per mounted canvas and expose imperative */\n/* clear / undo / isEmpty / confirm verbs to the consumer. */\n/* - Colors: `penColor` / `backgroundColor` default to */\n/* `--foreground` / `--background` via `getComputedStyle()`. Theme */\n/* switches are observed via a MutationObserver on `<html class>` */\n/* so the ink recolours when the theme flips. */\n/* - DPR scaling: canvas attribute `width/height = cssSize * DPR`; the */\n/* 2D context is scaled by the same factor. A `ResizeObserver` */\n/* replays strokes via `fromData()` on re-scale so nothing is lost. */\n/* - Typed fallback: keyboard-only path renders a text input styled in */\n/* italic `var(--font-sans)` (per 23-constraints §10 — serif is */\n/* marketing only). On confirm we render the string to an offscreen */\n/* canvas for the PNG/SVG export. */\n/* - Confirm payload: `{ png, svg, widthMm, heightMm, capturedAt, */\n/* sha256, strokes? }`. `sha256` is the SubtleCrypto digest of the */\n/* PNG bytes — tamper-evident for audit trails. */\n/* - Security: no `fetch` / `XMLHttpRequest` / `localStorage` / */\n/* `sessionStorage` in this file — the consumer owns persistence. */\n/* */\n/* TODO: */\n/* - 3× DPI re-render for print: currently `toDataURL('image/png')` */\n/* exports the live canvas (already at DPR). A proper 300-DPI */\n/* pipeline would create an offscreen canvas at `cssSize × 3` and */\n/* replay strokes via `fromData()` — deferred pending the print */\n/* bridge landing. */\n/* - Typed-fallback canvas font can't read CSS variables directly */\n/* (Canvas2D resolves fonts at paint time and won't expand */\n/* `var(--font-size-2xl)`); we use a fixed `32px italic` + the */\n/* user's font stack, which is visually close but not */\n/* theme-reactive. Will migrate once the typography tokens expose */\n/* a resolved `font` shorthand. */\n/* ------------------------------------------------------------------ */\n\nimport {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n type CSSProperties,\n} from 'react';\nimport SignaturePad from 'signature_pad';\nimport type { PointGroup } from 'signature_pad';\nimport { cva } from 'class-variance-authority';\nimport { useTranslation } from 'react-i18next';\nimport { useAgentRegistration } from '../../agent/registry';\nimport { signatureCaptureAgent } from './signature-capture.agent';\n\n/* ------------------------------------------------------------------ */\n/* Public types */\n/* ------------------------------------------------------------------ */\n\nexport interface SignatureConfirmPayload {\n /** Data URL of the captured signature rendered as PNG. */\n png: string;\n /** SVG string trimmed to the stroke bounding box. */\n svg: string;\n /** Physical width in millimetres, derived from CSS px. */\n widthMm: number;\n /** Physical height in millimetres, derived from CSS px. */\n heightMm: number;\n /** ISO-8601 UTC timestamp for when `confirm()` resolved. */\n capturedAt: string;\n /** Hex-encoded SHA-256 digest of the PNG bytes. */\n sha256: string;\n /** Raw stroke data from `signature_pad.toData()` — optional for replays. */\n strokes?: PointGroup[];\n}\n\nexport interface SignatureCaptureProps {\n /** Opaque instance id — emitted as `data-component-id` for the agent registry. */\n id?: string;\n /** Called with the export payload when the user confirms the signature. */\n onConfirm?: (payload: SignatureConfirmPayload) => void;\n /** Called after the pad is cleared (explicit user action). */\n onClear?: () => void;\n /** Called when the user starts drawing a new stroke. */\n onStart?: () => void;\n /** CSS width of the pad. Default 400. */\n width?: number | string;\n /** CSS height of the pad. Default 200. */\n height?: number | string;\n /** Pen colour override — defaults to `var(--foreground)`. */\n penColor?: string;\n /** Background override — defaults to `var(--background)`. */\n backgroundColor?: string;\n /** Show the typed-name fallback toggle. Default `true`. */\n allowTypedFallback?: boolean;\n /**\n * When set, on confirm() the captured PNG data URL is written into a hidden\n * `<input name={name}>` so consumers can POST the signature declaratively.\n * The PNG data URL satisfies the server's `data:image/png` prefix check.\n * Default off.\n */\n name?: string;\n /** Disable the entire component. */\n disabled?: boolean;\n /** Accessible label for the pad region. */\n ariaLabel?: string;\n /** Extra class names on the wrapper. */\n className?: string;\n}\n\nexport interface SignatureCaptureHandle {\n clear: () => void;\n undo: () => void;\n isEmpty: () => boolean;\n confirm: () => Promise<SignatureConfirmPayload | null>;\n}\n\n/* ------------------------------------------------------------------ */\n/* CVA */\n/* ------------------------------------------------------------------ */\n\nconst wrapperVariants = cva(\n [\n 'ds:signature-capture-alfadocs ds:flex ds:flex-col',\n 'ds:gap-[var(--spacing-sm)]',\n 'ds:bg-[var(--background)] ds:text-[var(--foreground)]',\n 'ds:rounded-[var(--radius-md)] ds:border ds:border-[color:var(--card-border)]',\n 'ds:shadow-[var(--shadow-card)]',\n 'ds:[.theme-accessible_&]:border-2',\n 'ds:p-[var(--spacing-sm)]',\n 'ds:aria-disabled:opacity-[var(--opacity-50)] ds:aria-disabled:cursor-not-allowed',\n ].join(' '),\n);\n\nconst padFrameVariants = cva(\n [\n 'ds:relative ds:block',\n // Mobile-first: fill the available width but never exceed the configured\n // pad width. Arbitrary-property form because `inline-size-[…]` /\n // `block-size-[…]` named utilities emit no CSS here (see canvasVariants).\n 'ds:[inline-size:100%]',\n 'ds:[max-inline-size:var(--signature-width)]',\n 'ds:[block-size:var(--signature-height)]',\n 'ds:rounded-[var(--radius-sm)]',\n 'ds:border ds:border-[color:var(--border)]',\n 'ds:bg-[var(--background)]',\n 'ds:overflow-hidden',\n 'ds:touch-none',\n 'ds:focus-visible:outline-[length:var(--focus-ring-width)]',\n 'ds:focus-visible:outline-solid',\n 'ds:focus-visible:outline-[var(--ring)]',\n 'ds:forced-colors:focus-visible:outline-[CanvasText]',\n ].join(' '),\n);\n\nconst canvasVariants = cva(\n [\n 'ds:block',\n // Arbitrary-property form, NOT `inline-size-full` / `block-size-full`:\n // the `inline-size-*` / `block-size-*` named utilities generate no CSS in\n // this Tailwind setup, so on a block <div> they silently fall back to auto\n // (harmless) but on a replaced <canvas> the element then sizes to its\n // backing-store `width`/`height` attribute — which scaleCanvas drives up to\n // MAX_CANVAS_PX (4096) in a feedback loop, overflowing the pad on mobile.\n // The `[property:value]` escape hatch always emits, pinning the canvas to\n // the frame so the loop can't run away.\n 'ds:[inline-size:100%]',\n 'ds:[block-size:100%]',\n 'ds:touch-none',\n 'ds:select-none',\n ].join(' '),\n);\n\nconst toolbarVariants = cva(\n ['ds:flex ds:items-stretch ds:flex-wrap ds:gap-[var(--spacing-sm)]'].join(\n ' ',\n ),\n);\n\n// Toolbar actions are sized for thumbs: they grow to fill the pad width\n// (`flex-1`), sit above the 44/48px floor, and use base-size text so they read\n// clearly on a phone.\nconst actionButtonVariants = cva(\n [\n 'ds:inline-flex ds:flex-1 ds:items-center ds:justify-center',\n 'ds:[min-block-size:var(--min-target-size)]',\n 'ds:[min-inline-size:var(--min-target-size)]',\n 'ds:gap-[var(--spacing-xs)]',\n 'ds:ps-[var(--spacing-md)] ds:pe-[var(--spacing-md)]',\n 'ds:pt-[var(--spacing-md)] ds:pb-[var(--spacing-md)]',\n 'ds:rounded-[var(--radius-sm)]',\n 'ds:border ds:border-[color:var(--border)]',\n 'ds:bg-transparent ds:text-[var(--foreground)]',\n 'ds:text-[length:var(--font-size-base)] ds:font-medium',\n 'ds:transition-colors ds:duration-[var(--animation-duration)] ds:motion-reduce:transition-none',\n 'ds:hover:bg-[var(--muted)]',\n 'ds:focus-visible:outline-[length:var(--focus-ring-width)]',\n 'ds:focus-visible:outline-solid',\n 'ds:focus-visible:outline-[var(--ring)]',\n 'ds:focus-visible:outline-offset-[length:var(--focus-ring-offset)]',\n 'ds:forced-colors:focus-visible:outline-[CanvasText]',\n 'ds:aria-disabled:opacity-[var(--opacity-50)] ds:aria-disabled:cursor-not-allowed',\n ].join(' '),\n);\n\nconst confirmButtonVariants = cva(\n [\n 'ds:inline-flex ds:flex-1 ds:items-center ds:justify-center',\n 'ds:[min-block-size:var(--min-target-size)]',\n 'ds:[min-inline-size:var(--min-target-size)]',\n 'ds:ps-[var(--spacing-md)] ds:pe-[var(--spacing-md)]',\n 'ds:pt-[var(--spacing-md)] ds:pb-[var(--spacing-md)]',\n 'ds:rounded-[var(--radius-sm)]',\n 'ds:bg-[var(--primary)] ds:text-[var(--primary-foreground)]',\n 'ds:text-[length:var(--font-size-base)] ds:font-medium',\n 'ds:transition-colors ds:duration-[var(--animation-duration)] ds:motion-reduce:transition-none',\n 'ds:hover:bg-[var(--primary-hover)]',\n 'ds:focus-visible:outline-[length:var(--focus-ring-width)]',\n 'ds:focus-visible:outline-solid',\n 'ds:focus-visible:outline-[var(--ring)]',\n 'ds:focus-visible:outline-offset-[length:var(--focus-ring-offset)]',\n 'ds:forced-colors:focus-visible:outline-[CanvasText]',\n 'ds:aria-disabled:opacity-[var(--opacity-50)] ds:aria-disabled:cursor-not-allowed',\n ].join(' '),\n);\n\nconst typedInputVariants = cva(\n [\n 'ds:block ds:inline-size-full',\n 'ds:[min-block-size:var(--min-target-size)]',\n 'ds:ps-[var(--spacing-sm)] ds:pe-[var(--spacing-sm)]',\n 'ds:rounded-[var(--radius-sm)]',\n 'ds:border ds:border-[color:var(--border)]',\n 'ds:bg-[var(--background)] ds:text-[var(--foreground)]',\n 'ds:font-[family-name:var(--font-sans)]',\n 'ds:italic',\n 'ds:tracking-[0.1em]',\n 'ds:text-[length:var(--font-size-lg)]',\n 'ds:focus-visible:outline-[length:var(--focus-ring-width)]',\n 'ds:focus-visible:outline-solid',\n 'ds:focus-visible:outline-[var(--ring)]',\n 'ds:forced-colors:focus-visible:outline-[CanvasText]',\n ].join(' '),\n);\n\nconst typedPreviewVariants = cva(\n [\n 'ds:flex ds:items-center ds:justify-center',\n // Match the pad frame: responsive width capped at the configured size.\n // Arbitrary-property form (the named `*-size-[…]` utilities are no-ops here).\n 'ds:[inline-size:100%]',\n 'ds:[max-inline-size:var(--signature-width)]',\n 'ds:[block-size:var(--signature-height)]',\n 'ds:rounded-[var(--radius-sm)]',\n 'ds:border ds:border-[color:var(--card-border)]',\n 'ds:[.theme-accessible_&]:border-2',\n 'ds:bg-[var(--background)] ds:text-[var(--foreground)]',\n 'ds:font-[family-name:var(--font-sans)]',\n 'ds:italic',\n 'ds:tracking-[0.1em]',\n 'ds:text-[length:var(--font-size-2xl)]',\n 'ds:p-[var(--spacing-md)]',\n ].join(' '),\n);\n\n/* ------------------------------------------------------------------ */\n/* Helpers */\n/* ------------------------------------------------------------------ */\n\ntype SignatureState = 'empty' | 'drawing' | 'captured' | 'cleared';\n\n/**\n * Resolve a CSS custom property against `document.documentElement`. We\n * can't pass `var(--foreground)` to signature_pad directly — the lib\n * stamps the string straight into `ctx.strokeStyle`, which only accepts\n * concrete colour values. Looking the variable up at runtime keeps the\n * component in tokens-only compliance.\n */\nfunction resolveCssVar(name: string): string {\n if (typeof document === 'undefined') return '';\n const value = getComputedStyle(document.documentElement)\n .getPropertyValue(name)\n .trim();\n return value;\n}\n\nfunction toCssSize(v: number | string | undefined, fallback: string): string {\n if (typeof v === 'number') return `${v}px`;\n if (typeof v === 'string' && v.length > 0) return v;\n return fallback;\n}\n\n/**\n * Parse a pixel value, returning `null` for non-pixel strings (e.g.\n * \"100%\", \"50vw\") so the caller can fall back to the measured rect.\n * parseFloat(\"100%\") would silently return 100 — a 100mm-wide export\n * masquerading as 26mm. Allow only digits, dot, minus, whitespace, \"px\".\n */\nfunction parsePxValue(v: string): number | null {\n if (typeof v === 'string' && /[^0-9.\\s\\-px]/i.test(v)) return null;\n const n = parseFloat(v);\n if (!Number.isFinite(n)) return null;\n return n;\n}\n\n/** Hex-encode a Uint8Array. */\nfunction toHex(bytes: Uint8Array): string {\n let out = '';\n for (let i = 0; i < bytes.length; i += 1) {\n const b = bytes[i];\n out += b.toString(16).padStart(2, '0');\n }\n return out;\n}\n\n/** Decode a base64 string into bytes without `atob` polyfills. */\nfunction base64ToBytes(b64: string): Uint8Array {\n if (typeof atob === 'function') {\n const bin = atob(b64);\n const bytes = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i += 1) bytes[i] = bin.charCodeAt(i);\n return bytes;\n }\n // Fallback — node-style Buffer, gated behind a runtime check.\n const g = globalThis as {\n Buffer?: { from: (s: string, enc: string) => Uint8Array };\n };\n if (g.Buffer) return g.Buffer.from(b64, 'base64');\n return new Uint8Array();\n}\n\nasync function sha256Hex(bytes: Uint8Array): Promise<string> {\n const g = globalThis as { crypto?: Crypto };\n if (g.crypto?.subtle) {\n // Copy the bytes into a fresh ArrayBuffer so the slice is always an\n // ArrayBuffer (never a SharedArrayBuffer) — SubtleCrypto's BufferSource\n // narrowing doesn't accept the latter.\n const copy = new Uint8Array(bytes.byteLength);\n copy.set(bytes);\n const digest = await g.crypto.subtle.digest('SHA-256', copy.buffer);\n return toHex(new Uint8Array(digest));\n }\n // No subtle crypto — return empty so callers can still use the rest\n // of the payload. Test env is expected to stub crypto.subtle.\n return '';\n}\n\n/**\n * Render the typed fallback string onto an offscreen canvas and return\n * it. Used by the confirm path when the user has typed their name\n * instead of drawing. Size is fixed at `32px italic` because Canvas2D\n * resolves fonts eagerly and can't expand `var(--font-size-*)`.\n */\nfunction renderTypedSignatureToCanvas(\n text: string,\n cssWidth: number,\n cssHeight: number,\n penColor: string,\n backgroundColor: string,\n): HTMLCanvasElement {\n const dpr = Math.max(\n 1,\n typeof window !== 'undefined' ? window.devicePixelRatio : 1,\n );\n const canvas = document.createElement('canvas');\n canvas.width = Math.floor(cssWidth * dpr);\n canvas.height = Math.floor(cssHeight * dpr);\n const ctx = canvas.getContext('2d');\n if (!ctx) return canvas;\n ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n // Fill background with the token-resolved colour.\n ctx.fillStyle = backgroundColor || 'transparent';\n ctx.fillRect(0, 0, cssWidth, cssHeight);\n // Draw the typed signature centred.\n ctx.fillStyle = penColor || 'currentColor';\n ctx.font = '32px italic sans-serif';\n ctx.textAlign = 'center';\n ctx.textBaseline = 'middle';\n ctx.fillText(text, cssWidth / 2, cssHeight / 2, cssWidth - 16);\n return canvas;\n}\n\n/* ------------------------------------------------------------------ */\n/* SignatureCapture */\n/* ------------------------------------------------------------------ */\n\nexport const SignatureCapture = forwardRef<\n SignatureCaptureHandle,\n SignatureCaptureProps\n>(\n (\n {\n id,\n onConfirm,\n onClear,\n onStart,\n width = 400,\n height = 200,\n penColor,\n backgroundColor,\n allowTypedFallback = true,\n name,\n disabled = false,\n ariaLabel,\n className,\n },\n ref,\n ) => {\n const { t } = useTranslation();\n const rawId = useId();\n const idSafe = useMemo(\n () => `sig-${rawId.replace(/[^a-zA-Z0-9-_]/g, '')}`,\n [rawId],\n );\n const liveRegionId = `${idSafe}-live`;\n\n const wrapperRef = useRef<HTMLDivElement>(null);\n const padFrameRef = useRef<HTMLDivElement>(null);\n const canvasRef = useRef<HTMLCanvasElement>(null);\n const typedPreviewRef = useRef<HTMLDivElement>(null);\n const signaturePadRef = useRef<SignaturePad | null>(null);\n\n const [mode, setMode] = useState<'draw' | 'typed'>('draw');\n const [typedValue, setTypedValue] = useState('');\n // Mirrors the last confirmed PNG data URL into a hidden form field when\n // `name` is set, so consumers can POST the signature declaratively.\n const [boundValue, setBoundValue] = useState('');\n // Tracks whether the pad has any ink — gates the Confirm button.\n // signature_pad's isEmpty() is a sync ref read and won't trigger\n // re-renders; this state mirrors it so React sees the change.\n const [padHasInk, setPadHasInk] = useState(false);\n // Retained state — consumers may subscribe to the pad's lifecycle via\n // `onConfirm`/`onClear`/`onStart`; we still track the machine internally\n // so the live region + confirm button stay coherent.\n const signatureStateRef = useRef<SignatureState>('empty');\n const [announcement, setAnnouncement] = useState<string>('');\n const [resolvedPen, setResolvedPen] = useState<string>('');\n const [resolvedBg, setResolvedBg] = useState<string>('');\n\n // Stable callback refs so we can wire signature_pad once without\n // re-instantiating on every render.\n const onStartRef = useRef<SignatureCaptureProps['onStart']>(onStart);\n const onClearRef = useRef<SignatureCaptureProps['onClear']>(onClear);\n const onConfirmRef = useRef<SignatureCaptureProps['onConfirm']>(onConfirm);\n useEffect(() => {\n onStartRef.current = onStart;\n onClearRef.current = onClear;\n onConfirmRef.current = onConfirm;\n }, [onStart, onClear, onConfirm]);\n\n /* ---- Announce helper ---------------------------------------- */\n const announce = useCallback(\n (next: SignatureState) => {\n signatureStateRef.current = next;\n setAnnouncement(t(`signature.state.${next}`));\n },\n [t],\n );\n\n /* ---- Resolve tokens ----------------------------------------- */\n useEffect(() => {\n if (typeof document === 'undefined') return undefined;\n function resolveAll(): void {\n const pen = penColor ?? resolveCssVar('--foreground');\n const bg = backgroundColor ?? resolveCssVar('--background');\n // Fall back to `currentColor` / `transparent` — keyword literals\n // are token-neutral and honour the surrounding theme even when\n // the CSS variable is briefly unavailable (SSR, initial paint).\n setResolvedPen(pen || 'currentColor');\n setResolvedBg(bg || 'transparent');\n }\n resolveAll();\n // Watch for theme-class changes on <html>.\n const mo = new MutationObserver(() => {\n resolveAll();\n });\n mo.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['class'],\n });\n return () => mo.disconnect();\n }, [penColor, backgroundColor]);\n\n /* ---- Apply colour changes to an existing pad ---------------- */\n useEffect(() => {\n const pad = signaturePadRef.current;\n if (!pad) return;\n if (resolvedPen) pad.penColor = resolvedPen;\n if (resolvedBg) pad.backgroundColor = resolvedBg;\n }, [resolvedPen, resolvedBg]);\n\n /* ---- Instantiate signature_pad ------------------------------ */\n useEffect(() => {\n if (mode !== 'draw') return undefined;\n const canvas = canvasRef.current;\n if (!canvas) return undefined;\n\n const pad = new SignaturePad(canvas, {\n penColor: resolvedPen || 'currentColor',\n backgroundColor: resolvedBg || 'transparent',\n minWidth: 0.5,\n maxWidth: 2.5,\n velocityFilterWeight: 0.7,\n });\n signaturePadRef.current = pad;\n\n const handleBegin = (): void => {\n setPadHasInk(true);\n announce('drawing');\n onStartRef.current?.();\n };\n const handleEnd = (): void => {\n // Keep state as 'drawing' — transition to 'captured' on confirm.\n };\n pad.addEventListener('beginStroke', handleBegin);\n pad.addEventListener('endStroke', handleEnd);\n\n // Initial DPR scale + announcement.\n scaleCanvas(canvas);\n announce('empty');\n\n return () => {\n pad.removeEventListener('beginStroke', handleBegin);\n pad.removeEventListener('endStroke', handleEnd);\n // Clear strokes from memory; 08-third-party §Signature Pad.\n pad.clear();\n pad.off();\n signaturePadRef.current = null;\n };\n // We intentionally re-create the pad only when switching between\n // typed and draw modes. Color updates flow through the effect above.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [mode]);\n\n /* ---- Disabled state ----------------------------------------- */\n useEffect(() => {\n const pad = signaturePadRef.current;\n if (!pad) return;\n if (disabled) pad.off();\n else pad.on();\n }, [disabled, mode]);\n\n /* ---- DPR + ResizeObserver ----------------------------------- */\n // Hard-cap backing-store dimensions to bound memory. 4096 px × 4096 px at\n // 4 bytes per pixel is ~67 MB — generous for any realistic signature, but\n // well under the multi-GB allocation a careless or malicious prop could\n // request on a high-DPR display. See security-hardening.mdx.\n const MAX_CANVAS_PX = 4096;\n const scaleCanvas = useCallback(\n (canvas: HTMLCanvasElement) => {\n const rect = canvas.getBoundingClientRect();\n const dpr = Math.max(\n 1,\n typeof window !== 'undefined' ? window.devicePixelRatio : 1,\n );\n const rawWidth = Math.max(1, Math.floor(rect.width * dpr));\n const rawHeight = Math.max(1, Math.floor(rect.height * dpr));\n const targetWidth = Math.min(rawWidth, MAX_CANVAS_PX);\n const targetHeight = Math.min(rawHeight, MAX_CANVAS_PX);\n if (\n import.meta.env.DEV &&\n (rawWidth !== targetWidth || rawHeight !== targetHeight)\n ) {\n // Silent in production; a consumer shipping 10k × 10k probably wants\n // the nudge.\n console.warn(\n `[SignatureCapture] clamped canvas backing store from ${rawWidth}x${rawHeight} to ${targetWidth}x${targetHeight} (cap = ${MAX_CANVAS_PX}px).`,\n );\n }\n if (canvas.width === targetWidth && canvas.height === targetHeight)\n return;\n\n const pad = signaturePadRef.current;\n const prior = pad ? pad.toData() : null;\n canvas.width = targetWidth;\n canvas.height = targetHeight;\n const ctx = canvas.getContext('2d');\n if (ctx) ctx.scale(dpr, dpr);\n if (pad) {\n if (resolvedBg) pad.backgroundColor = resolvedBg;\n if (resolvedPen) pad.penColor = resolvedPen;\n pad.clear();\n if (prior && prior.length > 0) {\n pad.fromData(prior);\n }\n }\n },\n [resolvedBg, resolvedPen],\n );\n\n useEffect(() => {\n const canvas = canvasRef.current;\n if (!canvas) return undefined;\n if (typeof ResizeObserver === 'undefined') {\n scaleCanvas(canvas);\n return undefined;\n }\n const ro = new ResizeObserver(() => {\n scaleCanvas(canvas);\n });\n ro.observe(canvas);\n return () => ro.disconnect();\n }, [scaleCanvas]);\n\n /* ---- Imperative handle -------------------------------------- */\n const clear = useCallback(() => {\n const pad = signaturePadRef.current;\n if (pad) pad.clear();\n setTypedValue('');\n setBoundValue('');\n setPadHasInk(false);\n announce('cleared');\n onClearRef.current?.();\n }, [announce]);\n\n const undo = useCallback(() => {\n const pad = signaturePadRef.current;\n if (!pad) return;\n const data = pad.toData();\n if (!data || data.length === 0) return;\n data.pop();\n pad.fromData(data);\n if (data.length === 0) {\n setPadHasInk(false);\n announce('empty');\n }\n }, [announce]);\n\n const isEmpty = useCallback((): boolean => {\n if (mode === 'typed') return typedValue.trim().length === 0;\n const pad = signaturePadRef.current;\n return pad ? pad.isEmpty() : true;\n }, [mode, typedValue]);\n\n const confirm =\n useCallback(async (): Promise<SignatureConfirmPayload | null> => {\n // parsePxValue returns null for \"100%\" / \"50vw\" etc. — fall back\n // to the live rendered rect so widthMm reflects reality, not a\n // mis-parsed parseFloat(\"100%\") = 100.\n const widthParsed = parsePxValue(\n typeof width === 'number' ? `${width}` : String(width),\n );\n const heightParsed = parsePxValue(\n typeof height === 'number' ? `${height}` : String(height),\n );\n const measureEl =\n mode === 'draw'\n ? (canvasRef.current ?? padFrameRef.current ?? wrapperRef.current)\n : (typedPreviewRef.current ?? wrapperRef.current);\n const measuredRect = measureEl?.getBoundingClientRect();\n const cssWidth =\n widthParsed ?? (measuredRect ? measuredRect.width : 400);\n const cssHeight =\n heightParsed ?? (measuredRect ? measuredRect.height : 200);\n\n let pngDataUrl = '';\n let svgString = '';\n let strokes: PointGroup[] | undefined;\n\n if (mode === 'draw') {\n const pad = signaturePadRef.current;\n if (!pad || pad.isEmpty()) return null;\n pngDataUrl = pad.toDataURL('image/png');\n svgString = pad.toSVG();\n strokes = pad.toData();\n } else {\n const value = typedValue.trim();\n if (value.length === 0) return null;\n const offscreen = renderTypedSignatureToCanvas(\n value,\n cssWidth,\n cssHeight,\n resolvedPen || 'currentColor',\n resolvedBg || 'transparent',\n );\n pngDataUrl = offscreen.toDataURL('image/png');\n // Inline SVG — we can't call toSVG() because signature_pad isn't\n // driving the canvas. Build a minimal SVG with the rendered text.\n const safeText = value\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&#39;');\n svgString =\n `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 ${cssWidth} ${cssHeight}\" width=\"${cssWidth}\" height=\"${cssHeight}\">` +\n `<text x=\"50%\" y=\"50%\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"sans-serif\" font-style=\"italic\" font-size=\"32\" fill=\"${resolvedPen || 'currentColor'}\" letter-spacing=\"3\">${safeText}</text>` +\n `</svg>`;\n }\n\n // 96 CSS px = 25.4 mm (per W3C CSS absolute length definition).\n const widthMm = (cssWidth * 25.4) / 96;\n const heightMm = (cssHeight * 25.4) / 96;\n const capturedAt = new Date().toISOString();\n\n // Compute SHA-256 of the PNG bytes.\n let sha256 = '';\n if (pngDataUrl) {\n const commaIx = pngDataUrl.indexOf(',');\n const b64 = commaIx >= 0 ? pngDataUrl.slice(commaIx + 1) : '';\n const bytes = base64ToBytes(b64);\n sha256 = await sha256Hex(bytes);\n }\n\n const payload: SignatureConfirmPayload = {\n png: pngDataUrl,\n svg: svgString,\n widthMm,\n heightMm,\n capturedAt,\n sha256,\n strokes,\n };\n\n announce('captured');\n if (name) setBoundValue(payload.png);\n onConfirmRef.current?.(payload);\n return payload;\n }, [\n mode,\n typedValue,\n width,\n height,\n resolvedPen,\n resolvedBg,\n announce,\n name,\n ]);\n\n const agentHandle = useMemo<SignatureCaptureHandle>(\n () => ({\n clear,\n undo,\n isEmpty,\n confirm,\n }),\n [clear, undo, isEmpty, confirm],\n );\n useImperativeHandle(ref, () => agentHandle, [agentHandle]);\n useAgentRegistration(signatureCaptureAgent, agentHandle, id);\n\n /* ---- Derived UI state --------------------------------------- */\n // Gate Confirm on React state, not the signature_pad ref — its\n // isEmpty() doesn't trigger re-renders, leaving the button stale.\n const hasContent =\n mode === 'typed' ? typedValue.trim().length > 0 : padHasInk;\n const confirmDisabled = disabled || !hasContent;\n // Inline style — permitted per 23-constraints §Runtime-computed\n // dimensions (CSS custom property setter for dynamic width/height\n // from consumer props; the width rule lives in Tailwind arbitrary\n // values that read --signature-width / --signature-height).\n const sizeStyle: CSSProperties = {\n ['--signature-width' as unknown as keyof CSSProperties]: toCssSize(\n width,\n 'var(--signature-default-width)',\n ),\n ['--signature-height' as unknown as keyof CSSProperties]: toCssSize(\n height,\n 'var(--signature-default-height)',\n ),\n } as CSSProperties;\n\n /* ---- Render -------------------------------------------------- */\n return (\n <div\n ref={wrapperRef}\n role=\"group\"\n aria-label={ariaLabel ?? t('signature.padLabel')}\n aria-disabled={disabled || undefined}\n className={[wrapperVariants(), className].filter(Boolean).join(' ')}\n // eslint-disable-next-line react/forbid-dom-props -- runtime-computed pad dimensions\n style={sizeStyle}\n data-component=\"signature-capture\"\n data-component-id={id}\n >\n {name ? (\n <input type=\"hidden\" name={name} value={boundValue} readOnly />\n ) : null}\n {mode === 'draw' ? (\n <div ref={padFrameRef} className={padFrameVariants()}>\n <canvas\n ref={canvasRef}\n role=\"img\"\n aria-label={t('signature.padLabel')}\n className={canvasVariants()}\n data-testid=\"signature-canvas\"\n />\n </div>\n ) : (\n <label className=\"ds:flex ds:flex-col ds:gap-[var(--spacing-xs)]\">\n <span className=\"type-body-sm ds:text-[var(--muted-foreground)]\">\n {t('signature.typedFallback.label')}\n </span>\n <input\n type=\"text\"\n value={typedValue}\n onChange={(e) => {\n setTypedValue(e.target.value);\n if (e.target.value.length > 0) announce('drawing');\n else announce('empty');\n }}\n placeholder={t('signature.typedFallback.placeholder')}\n aria-label={t('signature.typedFallback.label')}\n disabled={disabled}\n className={typedInputVariants()}\n data-testid=\"signature-typed-input\"\n />\n {typedValue ? (\n <div\n ref={typedPreviewRef}\n className={typedPreviewVariants()}\n aria-hidden=\"true\"\n >\n {typedValue}\n </div>\n ) : null}\n </label>\n )}\n\n {/* Live region — state transitions (empty, drawing, captured, cleared) */}\n <div\n id={liveRegionId}\n aria-live=\"polite\"\n aria-atomic=\"true\"\n className=\"ds:sr-only\"\n data-testid=\"signature-live\"\n >\n {announcement}\n </div>\n\n <div\n className={toolbarVariants()}\n role=\"group\"\n aria-label={t('signature.padLabel')}\n >\n <button\n type=\"button\"\n onClick={() => {\n if (disabled) return;\n clear();\n }}\n aria-disabled={disabled || undefined}\n className={actionButtonVariants()}\n >\n {t('signature.clear')}\n </button>\n {allowTypedFallback ? (\n <button\n type=\"button\"\n onClick={() => {\n if (disabled) return;\n setTypedValue('');\n setMode((m) => (m === 'draw' ? 'typed' : 'draw'));\n announce('cleared');\n }}\n aria-disabled={disabled || undefined}\n className={actionButtonVariants()}\n aria-pressed={mode === 'typed'}\n >\n {mode === 'draw'\n ? t('signature.typedFallback.toggle')\n : t('signature.typedFallback.toggleDraw')}\n </button>\n ) : null}\n <button\n type=\"button\"\n onClick={() => {\n if (confirmDisabled) return;\n void confirm();\n }}\n aria-disabled={confirmDisabled || undefined}\n aria-describedby={liveRegionId}\n className={confirmButtonVariants()}\n data-testid=\"signature-confirm\"\n >\n {t('signature.confirm')}\n </button>\n </div>\n </div>\n );\n },\n);\n\nSignatureCapture.displayName = 'SignatureCapture';\n\nexport {\n wrapperVariants as signatureWrapperVariants,\n actionButtonVariants as signatureActionButtonVariants,\n confirmButtonVariants as signatureConfirmButtonVariants,\n};\n"],"names":["signatureCaptureAgent","handle","wrapperVariants","cva","padFrameVariants","canvasVariants","toolbarVariants","actionButtonVariants","confirmButtonVariants","typedInputVariants","typedPreviewVariants","resolveCssVar","name","toCssSize","v","fallback","parsePxValue","toHex","bytes","out","i","b","base64ToBytes","b64","bin","g","sha256Hex","_a","copy","digest","renderTypedSignatureToCanvas","text","cssWidth","cssHeight","penColor","backgroundColor","dpr","canvas","ctx","SignatureCapture","forwardRef","id","onConfirm","onClear","onStart","width","height","allowTypedFallback","disabled","ariaLabel","className","ref","t","useTranslation","rawId","useId","liveRegionId","useMemo","wrapperRef","useRef","padFrameRef","canvasRef","typedPreviewRef","signaturePadRef","mode","setMode","useState","typedValue","setTypedValue","boundValue","setBoundValue","padHasInk","setPadHasInk","signatureStateRef","announcement","setAnnouncement","resolvedPen","setResolvedPen","resolvedBg","setResolvedBg","onStartRef","onClearRef","onConfirmRef","useEffect","announce","useCallback","next","resolveAll","pen","bg","mo","pad","SignaturePad","handleBegin","handleEnd","scaleCanvas","MAX_CANVAS_PX","rect","rawWidth","rawHeight","targetWidth","targetHeight","prior","ro","clear","undo","data","isEmpty","confirm","widthParsed","heightParsed","measureEl","measuredRect","pngDataUrl","svgString","strokes","value","safeText","widthMm","heightMm","capturedAt","sha256","commaIx","payload","agentHandle","useImperativeHandle","useAgentRegistration","hasContent","confirmDisabled","sizeStyle","jsxs","jsx","m"],"mappings":";;;;;;AAGO,MAAMA,KAA8D;AAAA,EACzE,IAAI;AAAA,EACJ,cAAc,CAAC,eAAe,QAAQ;AAAA,EACtC,OAAO;AAAA,IACL,SAAS;AAAA,MACP,MAAM;AAAA,MACN,aAAa;AAAA,MACb,MAAM,CAACC,MAAWA,EAAO,QAAA;AAAA,IAAQ;AAAA,EACnC;AAAA,EAEF,SAAS;AAAA,IACP,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,QAAQ,CAACA,MAAW;AAClB,QAAAA,EAAO,MAAA;AAAA,MACT;AAAA,IAAA;AAAA,IAEF,MAAM;AAAA,MACJ,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,QAAQ,CAACA,MAAW;AAClB,QAAAA,EAAO,KAAA;AAAA,MACT;AAAA,IAAA;AAAA,IAEF,SAAS;AAAA,MACP,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,QAAQ,CAACA,MAAWA,EAAO,QAAA;AAAA,IAAQ;AAAA,EACrC;AAAA,EAEF,UAAU;AAAA,IACR,MAAM,EAAE,MAAM,kBAAkB,OAAO,oBAAA;AAAA,IACvC,YAAY;AAAA,MACV,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,aAAa;AAAA,IAAA;AAAA,EACf;AAEJ,GC+EMC,KAAkBC;AAAA,EACtB;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,EACA,KAAK,GAAG;AACZ,GAEMC,KAA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AAAA,UAGH,gBAAAwD;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,WAAW5H,GAAA;AAAA,cACX,MAAK;AAAA,cACL,cAAY8C,EAAE,oBAAoB;AAAA,cAElC,UAAA;AAAA,gBAAA,gBAAA+E;AAAA,kBAAC;AAAA,kBAAA;AAAA,oBACC,MAAK;AAAA,oBACL,SAAS,MAAM;AACb,sBAAInF,KACJwD,EAAA;AAAA,oBACF;AAAA,oBACA,iBAAexD,KAAY;AAAA,oBAC3B,WAAWzC,GAAA;AAAA,oBAEV,YAAE,iBAAiB;AAAA,kBAAA;AAAA,gBAAA;AAAA,gBAErBwC,KACC,gBAAAoF;AAAA,kBAAC;AAAA,kBAAA;AAAA,oBACC,MAAK;AAAA,oBACL,SAAS,MAAM;AACb,sBAAInF,MACJoB,EAAc,EAAE,GAChBH,GAAQ,CAACmE,MAAOA,MAAM,SAAS,UAAU,MAAO,GAChDhD,EAAS,SAAS;AAAA,oBACpB;AAAA,oBACA,iBAAepC,KAAY;AAAA,oBAC3B,WAAWzC,GAAA;AAAA,oBACX,gBAAcyD,MAAS;AAAA,oBAEtB,UACGZ,QADM,SACJ,mCACA,oCADgC;AAAA,kBACI;AAAA,gBAAA,IAE1C;AAAA,gBACJ,gBAAA+E;AAAA,kBAAC;AAAA,kBAAA;AAAA,oBACC,MAAK;AAAA,oBACL,SAAS,MAAM;AACb,sBAAIH,MACCpB,EAAA;AAAA,oBACP;AAAA,oBACA,iBAAeoB,MAAmB;AAAA,oBAClC,oBAAkBxE;AAAA,oBAClB,WAAWhD,GAAA;AAAA,oBACX,eAAY;AAAA,oBAEX,YAAE,mBAAmB;AAAA,kBAAA;AAAA,gBAAA;AAAA,cACxB;AAAA,YAAA;AAAA,UAAA;AAAA,QACF;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAEA+B,GAAiB,cAAc;"}
@@ -0,0 +1,147 @@
1
+ import { useRef as E, useEffect as B, useState as h, useMemo as I, useCallback as g } from "react";
2
+ function R(o) {
3
+ return o != null && o.current ? o.current : typeof document > "u" ? null : document;
4
+ }
5
+ function T(o, s) {
6
+ const r = typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(o) : (
7
+ // SSR / jsdom fallback — drop every character that's
8
+ // significant in a CSS attribute selector. Conservative but
9
+ // robust enough for the test environment.
10
+ o.replace(/["'\\[\]]/g, "")
11
+ ), c = `[data-error-anchor="${r}"], [name="${r}"], [name$="[${r}]"]`, l = Array.from(s.querySelectorAll(c));
12
+ return l.length === 0 ? null : l.find((f) => f.offsetParent !== null) ?? l[0];
13
+ }
14
+ function q(o, s, r = {}) {
15
+ const {
16
+ scope: c,
17
+ scrollOptions: l = { behavior: "smooth", block: "center" },
18
+ focus: p = !0,
19
+ skipInitialMount: f = !0
20
+ } = r, t = E(!1), a = E(null), i = s.find((m) => !!o[m]) ?? null;
21
+ B(() => {
22
+ if (f && !t.current) {
23
+ t.current = !0, a.current = i;
24
+ return;
25
+ }
26
+ if (!i) {
27
+ a.current = null;
28
+ return;
29
+ }
30
+ if (i === a.current || typeof window > "u") return;
31
+ const m = window.requestAnimationFrame(() => {
32
+ const F = R(c);
33
+ if (!F) return;
34
+ const S = T(i, F);
35
+ S && (S.scrollIntoView(l), p && S.focus({ preventScroll: !0 }), a.current = i);
36
+ });
37
+ return () => window.cancelAnimationFrame(m);
38
+ }, [i]);
39
+ }
40
+ function k(o, s = !1) {
41
+ const r = {};
42
+ for (const c of o)
43
+ r[c.id] = { signed: s ? !1 : !!c.signed };
44
+ return r;
45
+ }
46
+ function M(o) {
47
+ const [s, r] = h(
48
+ () => k(o)
49
+ ), [c, l] = h(null), [p, f] = h(
50
+ () => {
51
+ var n;
52
+ return ((n = o[0]) == null ? void 0 : n.id) ?? null;
53
+ }
54
+ ), t = I(
55
+ () => o.map((n) => {
56
+ const e = s[n.id];
57
+ return {
58
+ ...n,
59
+ signed: e ? e.signed : !!n.signed,
60
+ payload: e == null ? void 0 : e.payload
61
+ };
62
+ }),
63
+ [o, s]
64
+ ), a = I(
65
+ () => t.reduce((n, e) => e.signed ? n + 1 : n, 0),
66
+ [t]
67
+ ), i = t.length, m = i > 0 && a === i, F = g((n) => {
68
+ l(n);
69
+ }, []), S = g(() => {
70
+ l(null);
71
+ }, []), v = g((n, e) => {
72
+ r((u) => ({ ...u, [n]: { signed: !0, payload: e } })), l((u) => u === n ? null : u);
73
+ }, []), w = g(
74
+ (n) => {
75
+ var e;
76
+ return !!((e = s[n]) != null && e.signed);
77
+ },
78
+ [s]
79
+ ), y = g(() => {
80
+ var n;
81
+ r(k(o, !0)), l(null), f(((n = o[0]) == null ? void 0 : n.id) ?? null);
82
+ }, [o]), C = g(() => {
83
+ f((n) => {
84
+ const e = t.length;
85
+ if (e === 0) return null;
86
+ const u = n ? t.findIndex((d) => d.id === n) : -1;
87
+ return t[(u + 1 + e) % e].id;
88
+ });
89
+ }, [t]), x = g(() => {
90
+ f((n) => {
91
+ const e = t.length;
92
+ if (e === 0) return null;
93
+ const u = n ? t.findIndex((d) => d.id === n) : 0;
94
+ return t[(u - 1 + e) % e].id;
95
+ });
96
+ }, [t]), b = g(() => {
97
+ f((n) => {
98
+ const e = t.length;
99
+ if (e === 0) return n;
100
+ const u = n ? t.findIndex((d) => d.id === n) : -1;
101
+ for (let d = 1; d <= e; d += 1) {
102
+ const A = t[(u + d) % e];
103
+ if (!A.signed) return A.id;
104
+ }
105
+ return n;
106
+ });
107
+ }, [t]);
108
+ return I(
109
+ () => ({
110
+ fields: t,
111
+ signedCount: a,
112
+ total: i,
113
+ isComplete: m,
114
+ activeFieldId: c,
115
+ openField: F,
116
+ closeField: S,
117
+ markSigned: v,
118
+ isFieldSigned: w,
119
+ reset: y,
120
+ cursorFieldId: p,
121
+ goToNextField: C,
122
+ goToPreviousField: x,
123
+ goToNextUnsigned: b
124
+ }),
125
+ [
126
+ t,
127
+ a,
128
+ i,
129
+ m,
130
+ c,
131
+ F,
132
+ S,
133
+ v,
134
+ w,
135
+ y,
136
+ p,
137
+ C,
138
+ x,
139
+ b
140
+ ]
141
+ );
142
+ }
143
+ export {
144
+ M as a,
145
+ q as u
146
+ };
147
+ //# sourceMappingURL=use-signing-session-CyOZWinp.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-signing-session-C5evzYmo.js","sources":["../../src/hooks/use-scroll-to-first-error.ts","../../src/hooks/use-signing-session.ts"],"sourcesContent":["import { useEffect, useRef, type RefObject } from 'react';\n\n/* -------------------------------------------------------------------- */\n/* Types */\n/* -------------------------------------------------------------------- */\n\nexport interface UseScrollToFirstErrorOptions {\n /**\n * Limits the DOM query to this element. Useful when the page renders\n * more than one form, or when an unrelated component happens to share\n * a field name. Defaults to `document`.\n */\n scope?: RefObject<HTMLElement | null>;\n /**\n * Forwarded to `scrollIntoView`. Defaults to\n * `{ behavior: 'smooth', block: 'center' }`. Pass\n * `{ behavior: 'auto' }` (or omit `behavior`) on consumers that\n * respect `prefers-reduced-motion` upstream — the kit doesn't shadow\n * the user's motion preference inside the hook, since some consumers\n * deliberately keep a near-instant snap for power-user form flows.\n */\n scrollOptions?: ScrollIntoViewOptions;\n /**\n * Move keyboard focus to the errored field after scrolling. Default\n * `true`. The focus call uses `preventScroll: true` so the smooth\n * scroll the hook just did isn't replaced by a snap.\n *\n * Setting this `false` defeats the keyboard-user side of WCAG 3.3.1\n * — the viewport will scroll but the active element stays on the\n * submit button, forcing a Shift+Tab back into the form. Only flip\n * this off when an upstream concern (e.g. a custom error summary\n * panel that owns its own focus) is taking responsibility.\n */\n focus?: boolean;\n /**\n * On the very first render, do nothing even if `errors` already has\n * entries. Default `true`. Without this the hook would yank the\n * viewport whenever a form is hydrated with server-rendered errors\n * from a no-JS fallback path — bad UX, since the user landed on the\n * page and hasn't asked for any movement yet. Set `false` only when\n * the consumer explicitly wants the initial-mount scroll (rare).\n */\n skipInitialMount?: boolean;\n}\n\n/* -------------------------------------------------------------------- */\n/* Helpers */\n/* -------------------------------------------------------------------- */\n\nfunction getScopeRoot(\n scope: RefObject<HTMLElement | null> | undefined,\n): ParentNode | null {\n if (scope?.current) return scope.current;\n if (typeof document === 'undefined') return null;\n return document;\n}\n\n/**\n * Resolve the DOM element to scroll/focus for a given errored field\n * name. The match order is:\n *\n * 1. `[data-error-anchor=\"<name>\"]` — the consumer's explicit hook,\n * used for Radix-based fields (Checkbox / Select / Switch) where\n * the named `<input>` is hidden behind a visible `<button>`.\n * Consumers set this on the trigger.\n * 2. `[name=\"<name>\"]` — the literal field name.\n * 3. `[name$=\"[<name>]\"]` — Symfony form-prefixed names like\n * `privacy_generator[fiscal_code]`. Suffix match keeps the hook\n * consumer-agnostic; no need to thread the form prefix through.\n *\n * Returns the first visible element among the matches. \"Visible\" here\n * means `offsetParent !== null` — that's the cheap heuristic Radix's\n * hidden inputs (display:none-equivalent positioning) fail and the\n * visible triggers pass. Falls back to the first match if every match\n * is hidden, so a field can still be scrolled into view even when the\n * trigger uses a non-standard layout.\n */\nfunction findErrorElement(name: string, root: ParentNode): HTMLElement | null {\n // `CSS.escape` is load-bearing here, not cosmetic. The Symfony\n // suffix-match arm embeds `name` inside `[name$=\"[${safe}]\"]`, so a\n // field name containing `]` would otherwise close the attribute\n // selector early and turn the rest of the string into stray\n // selector tokens. We don't expect adversarial input in practice\n // (server-controlled field names), but a server returning a `]`\n // in a 422 payload shouldn't be able to break the query.\n const safe =\n typeof CSS !== 'undefined' && typeof CSS.escape === 'function'\n ? CSS.escape(name)\n : // SSR / jsdom fallback — drop every character that's\n // significant in a CSS attribute selector. Conservative but\n // robust enough for the test environment.\n name.replace(/[\"'\\\\[\\]]/g, '');\n const selector =\n `[data-error-anchor=\"${safe}\"], ` +\n `[name=\"${safe}\"], ` +\n `[name$=\"[${safe}]\"]`;\n\n const matches = Array.from(root.querySelectorAll<HTMLElement>(selector));\n if (matches.length === 0) return null;\n\n const visible = matches.find((el) => el.offsetParent !== null);\n return visible ?? matches[0];\n}\n\n/* -------------------------------------------------------------------- */\n/* Hook */\n/* -------------------------------------------------------------------- */\n\n/**\n * Scrolls the first errored field into view and (by default) focuses\n * it, after `errors` changes. Backs the standard AlfaDocs rebrand\n * validation-error UX: after a 422 with `{ errors: { field: message } }`\n * is rendered inline, the user shouldn't be left staring at red labels\n * they can't see. Implements WCAG 3.3.1 / 3.3.3.\n *\n * The hook is stateless and never mutates the DOM beyond the\n * `scrollIntoView` + `focus` calls.\n *\n * @example\n * const fieldOrder = ['firstName', 'email', 'fiscalCode'] as const;\n * const [errors, setErrors] = useState<Record<string, string>>({});\n * useScrollToFirstError(errors, fieldOrder);\n *\n * @example Radix-based field\n * <Checkbox data-error-anchor=\"consent\" name=\"consent\" />\n * // hook scrolls to the visible <button>, not Radix's hidden input.\n *\n * @example Scoped to one form\n * const formRef = useRef<HTMLFormElement>(null);\n * useScrollToFirstError(errors, fieldOrder, { scope: formRef });\n */\nexport function useScrollToFirstError(\n errors: Readonly<Record<string, string | undefined>>,\n fieldOrder: ReadonlyArray<string>,\n options: UseScrollToFirstErrorOptions = {},\n): void {\n const {\n scope,\n scrollOptions = { behavior: 'smooth', block: 'center' },\n focus = true,\n skipInitialMount = true,\n } = options;\n\n // Single ref guards the initial-mount skip across StrictMode's\n // mount/unmount/remount cycle — flipped inside the effect body, not\n // in cleanup, so the second run sees `true` and stays gated.\n const ranOnceRef = useRef(false);\n\n // Track the previous \"first errored field name\" so a re-render that\n // leaves the same field errored doesn't re-scroll. We intentionally\n // depend on the resolved name (not the whole errors object) — that\n // way callers can mutate `errors` shape freely as long as the head\n // of the validation list is stable, which is the typical pattern\n // after a server returns the same 422 twice in a row.\n const lastScrolledFieldRef = useRef<string | null>(null);\n\n // Resolve the first errored field by visual order. A field is\n // \"errored\" iff its key has a truthy string value — the kit's form\n // contract is `Record<string, string | undefined>` where `undefined`\n // / missing keys mean \"no error\".\n const firstErroredField =\n fieldOrder.find((name) => Boolean(errors[name])) ?? null;\n\n useEffect(() => {\n if (skipInitialMount && !ranOnceRef.current) {\n ranOnceRef.current = true;\n // Record what we skipped so the next render doesn't try to\n // scroll to a field that was already errored at mount.\n lastScrolledFieldRef.current = firstErroredField;\n return;\n }\n\n if (!firstErroredField) {\n lastScrolledFieldRef.current = null;\n return;\n }\n\n if (firstErroredField === lastScrolledFieldRef.current) return;\n\n if (typeof window === 'undefined') return;\n\n // rAF defers the scroll until after the browser has laid out the\n // freshly-rendered error labels. Calling scrollIntoView synchronously\n // inside useEffect would fire before the new DOM is painted on\n // some browsers, leaving the viewport pointing at the old layout.\n const handle = window.requestAnimationFrame(() => {\n const root = getScopeRoot(scope);\n if (!root) return;\n const el = findErrorElement(firstErroredField, root);\n if (!el) return;\n\n el.scrollIntoView(scrollOptions);\n if (focus) {\n // preventScroll: true so the browser doesn't override the\n // smooth scroll above with a snap to put the element at the\n // top of the viewport.\n el.focus({ preventScroll: true });\n }\n lastScrolledFieldRef.current = firstErroredField;\n });\n\n return () => window.cancelAnimationFrame(handle);\n // `scrollOptions` / `focus` / `scope` / `skipInitialMount` are\n // option bag values — re-running on their identity change would\n // be surprising. The hook re-fires only when the field at the\n // head of the errored list changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [firstErroredField]);\n}\n","import { useCallback, useMemo, useState } from 'react';\n\n/* ------------------------------------------------------------------ */\n/* useSigningSession */\n/* */\n/* Orchestration state for a multi-field signing flow: N signature */\n/* fields across M pages (and optionally multiple PDFs per envelope), */\n/* a live \"X of Y signed\" counter, and a completion gate. Pure state — */\n/* no I/O, no globals, no persistence. The consumer owns the documents, */\n/* the capture UI, and where signatures are sent. */\n/* */\n/* Generic over the field shape (so geometry / page / docIndex / label */\n/* ride along untouched and `fields` can map straight onto SignatureField)*/\n/* and over the captured payload type (typically SignatureConfirmPayload).*/\n/* */\n/* The SET of field ids and their initial `signed` flags are captured at */\n/* first render — an envelope's fields are fixed for the session. Field */\n/* geometry/label changes still flow through `fields` on every render. */\n/* ------------------------------------------------------------------ */\n\n/** Minimum shape a signing field must satisfy. */\nexport interface SigningFieldBase {\n /** Stable, unique id for the field within the session. */\n id: string;\n /** Initial signed state (default `false`). */\n signed?: boolean;\n}\n\ninterface SignedEntry<TPayload> {\n signed: boolean;\n payload?: TPayload;\n}\n\n/** A consumer field enriched with the session's live signed state + payload. */\nexport type SigningField<TField extends SigningFieldBase, TPayload> = TField & {\n signed: boolean;\n payload?: TPayload;\n};\n\nexport interface UseSigningSessionReturn<\n TField extends SigningFieldBase,\n TPayload,\n> {\n /** The input fields, each enriched with live `signed` + `payload`. */\n fields: SigningField<TField, TPayload>[];\n /** How many fields are currently signed. */\n signedCount: number;\n /** Total number of fields. */\n total: number;\n /** True when every field is signed (and there is at least one). */\n isComplete: boolean;\n /** The field whose capture UI is currently open, or `null`. */\n activeFieldId: string | null;\n /** Open a field's capture UI (sets `activeFieldId`). */\n openField: (id: string) => void;\n /** Close any open capture UI (clears `activeFieldId`). */\n closeField: () => void;\n /** Flip a field to signed, storing its payload, and close it if active. */\n markSigned: (id: string, payload?: TPayload) => void;\n /** Read a single field's signed state. */\n isFieldSigned: (id: string) => boolean;\n /** Clear all signatures and close any open field. */\n reset: () => void;\n}\n\nfunction seedSigned<TField extends SigningFieldBase, TPayload>(\n fields: TField[],\n forceUnsigned = false,\n): Record<string, SignedEntry<TPayload>> {\n const map: Record<string, SignedEntry<TPayload>> = {};\n for (const field of fields) {\n map[field.id] = { signed: forceUnsigned ? false : Boolean(field.signed) };\n }\n return map;\n}\n\nexport function useSigningSession<\n TField extends SigningFieldBase,\n TPayload = unknown,\n>(fields: TField[]): UseSigningSessionReturn<TField, TPayload> {\n const [signed, setSigned] = useState<Record<string, SignedEntry<TPayload>>>(\n () => seedSigned<TField, TPayload>(fields),\n );\n const [activeFieldId, setActiveFieldId] = useState<string | null>(null);\n\n const enriched = useMemo<SigningField<TField, TPayload>[]>(\n () =>\n fields.map((field) => {\n const entry = signed[field.id];\n return {\n ...field,\n signed: entry ? entry.signed : Boolean(field.signed),\n payload: entry?.payload,\n };\n }),\n [fields, signed],\n );\n\n const signedCount = useMemo(\n () =>\n enriched.reduce((count, field) => (field.signed ? count + 1 : count), 0),\n [enriched],\n );\n const total = enriched.length;\n const isComplete = total > 0 && signedCount === total;\n\n const openField = useCallback((id: string) => {\n setActiveFieldId(id);\n }, []);\n\n const closeField = useCallback(() => {\n setActiveFieldId(null);\n }, []);\n\n const markSigned = useCallback((id: string, payload?: TPayload) => {\n setSigned((prev) => ({ ...prev, [id]: { signed: true, payload } }));\n setActiveFieldId((current) => (current === id ? null : current));\n }, []);\n\n const isFieldSigned = useCallback(\n (id: string) => Boolean(signed[id]?.signed),\n [signed],\n );\n\n const reset = useCallback(() => {\n setSigned(seedSigned<TField, TPayload>(fields, true));\n setActiveFieldId(null);\n }, [fields]);\n\n return useMemo(\n () => ({\n fields: enriched,\n signedCount,\n total,\n isComplete,\n activeFieldId,\n openField,\n closeField,\n markSigned,\n isFieldSigned,\n reset,\n }),\n [\n enriched,\n signedCount,\n total,\n isComplete,\n activeFieldId,\n openField,\n closeField,\n markSigned,\n isFieldSigned,\n reset,\n ],\n );\n}\n"],"names":["getScopeRoot","scope","findErrorElement","name","root","safe","selector","matches","el","useScrollToFirstError","errors","fieldOrder","options","scrollOptions","focus","skipInitialMount","ranOnceRef","useRef","lastScrolledFieldRef","firstErroredField","useEffect","handle","seedSigned","fields","forceUnsigned","map","field","useSigningSession","signed","setSigned","useState","activeFieldId","setActiveFieldId","enriched","useMemo","entry","signedCount","count","total","isComplete","openField","useCallback","id","closeField","markSigned","payload","prev","current","isFieldSigned","_a","reset"],"mappings":";AAiDA,SAASA,EACPC,GACmB;AACnB,SAAIA,KAAA,QAAAA,EAAO,UAAgBA,EAAM,UAC7B,OAAO,WAAa,MAAoB,OACrC;AACT;AAsBA,SAASC,EAAiBC,GAAcC,GAAsC;AAQ5E,QAAMC,IACJ,OAAO,MAAQ,OAAe,OAAO,IAAI,UAAW,aAChD,IAAI,OAAOF,CAAI;AAAA;AAAA;AAAA;AAAA,IAIfA,EAAK,QAAQ,cAAc,EAAE;AAAA,KAC7BG,IACJ,uBA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AQO,IAAArB,EAAOc,CAAE,MAAT,QAAAO,EAAY;AAAA;AAAA,IACpC,CAACrB,CAAM;AAAA,EAAA,GAGHsB,IAAQT,EAAY,MAAM;AAC9B,IAAAZ,EAAUP,EAA6BC,GAAQ,EAAI,CAAC,GACpDS,EAAiB,IAAI;AAAA,EACvB,GAAG,CAACT,CAAM,CAAC;AAEX,SAAOW;AAAA,IACL,OAAO;AAAA,MACL,QAAQD;AAAA,MACR,aAAAG;AAAA,MACA,OAAAE;AAAA,MACA,YAAAC;AAAA,MACA,eAAAR;AAAA,MACA,WAAAS;AAAA,MACA,YAAAG;AAAA,MACA,YAAAC;AAAA,MACA,eAAAI;AAAA,MACA,OAAAE;AAAA,IAAA;AAAA,IAEF;AAAA,MACEjB;AAAA,MACAG;AAAA,MACAE;AAAA,MACAC;AAAA,MACAR;AAAA,MACAS;AAAA,MACAG;AAAA,MACAC;AAAA,MACAI;AAAA,MACAE;AAAA,IAAA;AAAA,EACF;AAEJ;"}
1
+ {"version":3,"file":"use-signing-session-CyOZWinp.js","sources":["../../src/hooks/use-scroll-to-first-error.ts","../../src/hooks/use-signing-session.ts"],"sourcesContent":["import { useEffect, useRef, type RefObject } from 'react';\n\n/* -------------------------------------------------------------------- */\n/* Types */\n/* -------------------------------------------------------------------- */\n\nexport interface UseScrollToFirstErrorOptions {\n /**\n * Limits the DOM query to this element. Useful when the page renders\n * more than one form, or when an unrelated component happens to share\n * a field name. Defaults to `document`.\n */\n scope?: RefObject<HTMLElement | null>;\n /**\n * Forwarded to `scrollIntoView`. Defaults to\n * `{ behavior: 'smooth', block: 'center' }`. Pass\n * `{ behavior: 'auto' }` (or omit `behavior`) on consumers that\n * respect `prefers-reduced-motion` upstream — the kit doesn't shadow\n * the user's motion preference inside the hook, since some consumers\n * deliberately keep a near-instant snap for power-user form flows.\n */\n scrollOptions?: ScrollIntoViewOptions;\n /**\n * Move keyboard focus to the errored field after scrolling. Default\n * `true`. The focus call uses `preventScroll: true` so the smooth\n * scroll the hook just did isn't replaced by a snap.\n *\n * Setting this `false` defeats the keyboard-user side of WCAG 3.3.1\n * — the viewport will scroll but the active element stays on the\n * submit button, forcing a Shift+Tab back into the form. Only flip\n * this off when an upstream concern (e.g. a custom error summary\n * panel that owns its own focus) is taking responsibility.\n */\n focus?: boolean;\n /**\n * On the very first render, do nothing even if `errors` already has\n * entries. Default `true`. Without this the hook would yank the\n * viewport whenever a form is hydrated with server-rendered errors\n * from a no-JS fallback path — bad UX, since the user landed on the\n * page and hasn't asked for any movement yet. Set `false` only when\n * the consumer explicitly wants the initial-mount scroll (rare).\n */\n skipInitialMount?: boolean;\n}\n\n/* -------------------------------------------------------------------- */\n/* Helpers */\n/* -------------------------------------------------------------------- */\n\nfunction getScopeRoot(\n scope: RefObject<HTMLElement | null> | undefined,\n): ParentNode | null {\n if (scope?.current) return scope.current;\n if (typeof document === 'undefined') return null;\n return document;\n}\n\n/**\n * Resolve the DOM element to scroll/focus for a given errored field\n * name. The match order is:\n *\n * 1. `[data-error-anchor=\"<name>\"]` — the consumer's explicit hook,\n * used for Radix-based fields (Checkbox / Select / Switch) where\n * the named `<input>` is hidden behind a visible `<button>`.\n * Consumers set this on the trigger.\n * 2. `[name=\"<name>\"]` — the literal field name.\n * 3. `[name$=\"[<name>]\"]` — Symfony form-prefixed names like\n * `privacy_generator[fiscal_code]`. Suffix match keeps the hook\n * consumer-agnostic; no need to thread the form prefix through.\n *\n * Returns the first visible element among the matches. \"Visible\" here\n * means `offsetParent !== null` — that's the cheap heuristic Radix's\n * hidden inputs (display:none-equivalent positioning) fail and the\n * visible triggers pass. Falls back to the first match if every match\n * is hidden, so a field can still be scrolled into view even when the\n * trigger uses a non-standard layout.\n */\nfunction findErrorElement(name: string, root: ParentNode): HTMLElement | null {\n // `CSS.escape` is load-bearing here, not cosmetic. The Symfony\n // suffix-match arm embeds `name` inside `[name$=\"[${safe}]\"]`, so a\n // field name containing `]` would otherwise close the attribute\n // selector early and turn the rest of the string into stray\n // selector tokens. We don't expect adversarial input in practice\n // (server-controlled field names), but a server returning a `]`\n // in a 422 payload shouldn't be able to break the query.\n const safe =\n typeof CSS !== 'undefined' && typeof CSS.escape === 'function'\n ? CSS.escape(name)\n : // SSR / jsdom fallback — drop every character that's\n // significant in a CSS attribute selector. Conservative but\n // robust enough for the test environment.\n name.replace(/[\"'\\\\[\\]]/g, '');\n const selector =\n `[data-error-anchor=\"${safe}\"], ` +\n `[name=\"${safe}\"], ` +\n `[name$=\"[${safe}]\"]`;\n\n const matches = Array.from(root.querySelectorAll<HTMLElement>(selector));\n if (matches.length === 0) return null;\n\n const visible = matches.find((el) => el.offsetParent !== null);\n return visible ?? matches[0];\n}\n\n/* -------------------------------------------------------------------- */\n/* Hook */\n/* -------------------------------------------------------------------- */\n\n/**\n * Scrolls the first errored field into view and (by default) focuses\n * it, after `errors` changes. Backs the standard AlfaDocs rebrand\n * validation-error UX: after a 422 with `{ errors: { field: message } }`\n * is rendered inline, the user shouldn't be left staring at red labels\n * they can't see. Implements WCAG 3.3.1 / 3.3.3.\n *\n * The hook is stateless and never mutates the DOM beyond the\n * `scrollIntoView` + `focus` calls.\n *\n * @example\n * const fieldOrder = ['firstName', 'email', 'fiscalCode'] as const;\n * const [errors, setErrors] = useState<Record<string, string>>({});\n * useScrollToFirstError(errors, fieldOrder);\n *\n * @example Radix-based field\n * <Checkbox data-error-anchor=\"consent\" name=\"consent\" />\n * // hook scrolls to the visible <button>, not Radix's hidden input.\n *\n * @example Scoped to one form\n * const formRef = useRef<HTMLFormElement>(null);\n * useScrollToFirstError(errors, fieldOrder, { scope: formRef });\n */\nexport function useScrollToFirstError(\n errors: Readonly<Record<string, string | undefined>>,\n fieldOrder: ReadonlyArray<string>,\n options: UseScrollToFirstErrorOptions = {},\n): void {\n const {\n scope,\n scrollOptions = { behavior: 'smooth', block: 'center' },\n focus = true,\n skipInitialMount = true,\n } = options;\n\n // Single ref guards the initial-mount skip across StrictMode's\n // mount/unmount/remount cycle — flipped inside the effect body, not\n // in cleanup, so the second run sees `true` and stays gated.\n const ranOnceRef = useRef(false);\n\n // Track the previous \"first errored field name\" so a re-render that\n // leaves the same field errored doesn't re-scroll. We intentionally\n // depend on the resolved name (not the whole errors object) — that\n // way callers can mutate `errors` shape freely as long as the head\n // of the validation list is stable, which is the typical pattern\n // after a server returns the same 422 twice in a row.\n const lastScrolledFieldRef = useRef<string | null>(null);\n\n // Resolve the first errored field by visual order. A field is\n // \"errored\" iff its key has a truthy string value — the kit's form\n // contract is `Record<string, string | undefined>` where `undefined`\n // / missing keys mean \"no error\".\n const firstErroredField =\n fieldOrder.find((name) => Boolean(errors[name])) ?? null;\n\n useEffect(() => {\n if (skipInitialMount && !ranOnceRef.current) {\n ranOnceRef.current = true;\n // Record what we skipped so the next render doesn't try to\n // scroll to a field that was already errored at mount.\n lastScrolledFieldRef.current = firstErroredField;\n return;\n }\n\n if (!firstErroredField) {\n lastScrolledFieldRef.current = null;\n return;\n }\n\n if (firstErroredField === lastScrolledFieldRef.current) return;\n\n if (typeof window === 'undefined') return;\n\n // rAF defers the scroll until after the browser has laid out the\n // freshly-rendered error labels. Calling scrollIntoView synchronously\n // inside useEffect would fire before the new DOM is painted on\n // some browsers, leaving the viewport pointing at the old layout.\n const handle = window.requestAnimationFrame(() => {\n const root = getScopeRoot(scope);\n if (!root) return;\n const el = findErrorElement(firstErroredField, root);\n if (!el) return;\n\n el.scrollIntoView(scrollOptions);\n if (focus) {\n // preventScroll: true so the browser doesn't override the\n // smooth scroll above with a snap to put the element at the\n // top of the viewport.\n el.focus({ preventScroll: true });\n }\n lastScrolledFieldRef.current = firstErroredField;\n });\n\n return () => window.cancelAnimationFrame(handle);\n // `scrollOptions` / `focus` / `scope` / `skipInitialMount` are\n // option bag values — re-running on their identity change would\n // be surprising. The hook re-fires only when the field at the\n // head of the errored list changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [firstErroredField]);\n}\n","import { useCallback, useMemo, useState } from 'react';\n\n/* ------------------------------------------------------------------ */\n/* useSigningSession */\n/* */\n/* Orchestration state for a multi-field signing flow: N signature */\n/* fields across M pages (and optionally multiple PDFs per envelope), */\n/* a live \"X of Y signed\" counter, and a completion gate. Pure state — */\n/* no I/O, no globals, no persistence. The consumer owns the documents, */\n/* the capture UI, and where signatures are sent. */\n/* */\n/* Generic over the field shape (so geometry / page / docIndex / label */\n/* ride along untouched and `fields` can map straight onto SignatureField)*/\n/* and over the captured payload type (typically SignatureConfirmPayload).*/\n/* */\n/* The SET of field ids and their initial `signed` flags are captured at */\n/* first render — an envelope's fields are fixed for the session. Field */\n/* geometry/label changes still flow through `fields` on every render. */\n/* ------------------------------------------------------------------ */\n\n/** Minimum shape a signing field must satisfy. */\nexport interface SigningFieldBase {\n /** Stable, unique id for the field within the session. */\n id: string;\n /** Initial signed state (default `false`). */\n signed?: boolean;\n}\n\ninterface SignedEntry<TPayload> {\n signed: boolean;\n payload?: TPayload;\n}\n\n/** A consumer field enriched with the session's live signed state + payload. */\nexport type SigningField<TField extends SigningFieldBase, TPayload> = TField & {\n signed: boolean;\n payload?: TPayload;\n};\n\nexport interface UseSigningSessionReturn<\n TField extends SigningFieldBase,\n TPayload,\n> {\n /** The input fields, each enriched with live `signed` + `payload`. */\n fields: SigningField<TField, TPayload>[];\n /** How many fields are currently signed. */\n signedCount: number;\n /** Total number of fields. */\n total: number;\n /** True when every field is signed (and there is at least one). */\n isComplete: boolean;\n /** The field whose capture UI is currently open, or `null`. */\n activeFieldId: string | null;\n /** Open a field's capture UI (sets `activeFieldId`). */\n openField: (id: string) => void;\n /** Close any open capture UI (clears `activeFieldId`). */\n closeField: () => void;\n /** Flip a field to signed, storing its payload, and close it if active. */\n markSigned: (id: string, payload?: TPayload) => void;\n /** Read a single field's signed state. */\n isFieldSigned: (id: string) => boolean;\n /** Clear all signatures and close any open field. */\n reset: () => void;\n /** The field currently targeted by next/previous navigation, or `null`. */\n cursorFieldId: string | null;\n /** Move the navigation cursor to the next field (input order, cycling). */\n goToNextField: () => void;\n /** Move the navigation cursor to the previous field (cycling). */\n goToPreviousField: () => void;\n /** Move the cursor to the next still-unsigned field (cycling); no-op if all signed. */\n goToNextUnsigned: () => void;\n}\n\nfunction seedSigned<TField extends SigningFieldBase, TPayload>(\n fields: TField[],\n forceUnsigned = false,\n): Record<string, SignedEntry<TPayload>> {\n const map: Record<string, SignedEntry<TPayload>> = {};\n for (const field of fields) {\n map[field.id] = { signed: forceUnsigned ? false : Boolean(field.signed) };\n }\n return map;\n}\n\nexport function useSigningSession<\n TField extends SigningFieldBase,\n TPayload = unknown,\n>(fields: TField[]): UseSigningSessionReturn<TField, TPayload> {\n const [signed, setSigned] = useState<Record<string, SignedEntry<TPayload>>>(\n () => seedSigned<TField, TPayload>(fields),\n );\n const [activeFieldId, setActiveFieldId] = useState<string | null>(null);\n const [cursorFieldId, setCursorFieldId] = useState<string | null>(\n () => fields[0]?.id ?? null,\n );\n\n const enriched = useMemo<SigningField<TField, TPayload>[]>(\n () =>\n fields.map((field) => {\n const entry = signed[field.id];\n return {\n ...field,\n signed: entry ? entry.signed : Boolean(field.signed),\n payload: entry?.payload,\n };\n }),\n [fields, signed],\n );\n\n const signedCount = useMemo(\n () =>\n enriched.reduce((count, field) => (field.signed ? count + 1 : count), 0),\n [enriched],\n );\n const total = enriched.length;\n const isComplete = total > 0 && signedCount === total;\n\n const openField = useCallback((id: string) => {\n setActiveFieldId(id);\n }, []);\n\n const closeField = useCallback(() => {\n setActiveFieldId(null);\n }, []);\n\n const markSigned = useCallback((id: string, payload?: TPayload) => {\n setSigned((prev) => ({ ...prev, [id]: { signed: true, payload } }));\n setActiveFieldId((current) => (current === id ? null : current));\n }, []);\n\n const isFieldSigned = useCallback(\n (id: string) => Boolean(signed[id]?.signed),\n [signed],\n );\n\n const reset = useCallback(() => {\n setSigned(seedSigned<TField, TPayload>(fields, true));\n setActiveFieldId(null);\n setCursorFieldId(fields[0]?.id ?? null);\n }, [fields]);\n\n const goToNextField = useCallback(() => {\n setCursorFieldId((cur) => {\n const len = enriched.length;\n if (len === 0) return null;\n const i = cur ? enriched.findIndex((f) => f.id === cur) : -1;\n return enriched[(i + 1 + len) % len].id;\n });\n }, [enriched]);\n\n const goToPreviousField = useCallback(() => {\n setCursorFieldId((cur) => {\n const len = enriched.length;\n if (len === 0) return null;\n const i = cur ? enriched.findIndex((f) => f.id === cur) : 0;\n return enriched[(i - 1 + len) % len].id;\n });\n }, [enriched]);\n\n const goToNextUnsigned = useCallback(() => {\n setCursorFieldId((cur) => {\n const len = enriched.length;\n if (len === 0) return cur;\n const start = cur ? enriched.findIndex((f) => f.id === cur) : -1;\n for (let step = 1; step <= len; step += 1) {\n const field = enriched[(start + step) % len];\n if (!field.signed) return field.id;\n }\n return cur;\n });\n }, [enriched]);\n\n return useMemo(\n () => ({\n fields: enriched,\n signedCount,\n total,\n isComplete,\n activeFieldId,\n openField,\n closeField,\n markSigned,\n isFieldSigned,\n reset,\n cursorFieldId,\n goToNextField,\n goToPreviousField,\n goToNextUnsigned,\n }),\n [\n enriched,\n signedCount,\n total,\n isComplete,\n activeFieldId,\n openField,\n closeField,\n markSigned,\n isFieldSigned,\n reset,\n cursorFieldId,\n goToNextField,\n goToPreviousField,\n goToNextUnsigned,\n ],\n );\n}\n"],"names":["getScopeRoot","scope","findErrorElement","name","root","safe","selector","matches","el","useScrollToFirstError","errors","fieldOrder","options","scrollOptions","focus","skipInitialMount","ranOnceRef","useRef","lastScrolledFieldRef","firstErroredField","useEffect","handle","seedSigned","fields","forceUnsigned","map","field","useSigningSession","signed","setSigned","useState","activeFieldId","setActiveFieldId","cursorFieldId","setCursorFieldId","_a","enriched","useMemo","entry","signedCount","count","total","isComplete","openField","useCallback","id","closeField","markSigned","payload","prev","current","isFieldSigned","reset","goToNextField","cur","len","i","f","goToPreviousField","goToNextUnsigned","start","step"],"mappings":";AAiDA,SAASA,EACPC,GACmB;AACnB,SAAIA,KAAA,QAAAA,EAAO,UAAgBA,EAAM,UAC7B,OAAO,WAAa,MAAoB,OACrC;AAC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