@alfadocs/ui-kit-debug 0.60.0 → 0.62.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.
- package/dist/_chunks/pdf-viewer-chMpwpA4.js +979 -0
- package/dist/_chunks/pdf-viewer-chMpwpA4.js.map +1 -0
- package/dist/_chunks/{sign-document-BmAT0kKD.js → sign-document--nr5cxsB.js} +2 -2
- package/dist/_chunks/{sign-document-BmAT0kKD.js.map → sign-document--nr5cxsB.js.map} +1 -1
- package/dist/_chunks/signature-field-DbhbpLha.js +190 -0
- package/dist/_chunks/signature-field-DbhbpLha.js.map +1 -0
- package/dist/agent-catalog.json +1 -1
- package/dist/components/pdf-viewer/index.js +1 -1
- package/dist/components/pdf-viewer/pdf-viewer.d.ts +7 -0
- package/dist/components/pdf-viewer/pdf-viewer.d.ts.map +1 -1
- package/dist/components/sign-document/index.js +1 -1
- package/dist/components/signature-field/index.js +1 -1
- package/dist/components/signature-field/signature-field.d.ts +8 -0
- package/dist/components/signature-field/signature-field.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/tokens.css +1 -1
- package/package.json +3 -1
- package/dist/_chunks/pdf-viewer-XxWdtKfD.js +0 -965
- package/dist/_chunks/pdf-viewer-XxWdtKfD.js.map +0 -1
- package/dist/_chunks/signature-field-DhscKdgk.js +0 -152
- package/dist/_chunks/signature-field-DhscKdgk.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-viewer-chMpwpA4.js","sources":["../../node_modules/lucide-react/dist/esm/icons/zoom-in.js","../../node_modules/lucide-react/dist/esm/icons/zoom-out.js","../../src/components/pdf-viewer/pdf-viewer.agent.ts","../../src/components/pdf-viewer/pdf-viewer.tsx"],"sourcesContent":["/**\n * @license lucide-react v1.8.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.js';\n\nconst __iconNode = [\n [\"circle\", { cx: \"11\", cy: \"11\", r: \"8\", key: \"4ej97u\" }],\n [\"line\", { x1: \"21\", x2: \"16.65\", y1: \"21\", y2: \"16.65\", key: \"13gj7c\" }],\n [\"line\", { x1: \"11\", x2: \"11\", y1: \"8\", y2: \"14\", key: \"1vmskp\" }],\n [\"line\", { x1: \"8\", x2: \"14\", y1: \"11\", y2: \"11\", key: \"durymu\" }]\n];\nconst ZoomIn = createLucideIcon(\"zoom-in\", __iconNode);\n\nexport { __iconNode, ZoomIn as default };\n//# sourceMappingURL=zoom-in.js.map\n","/**\n * @license lucide-react v1.8.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.js';\n\nconst __iconNode = [\n [\"circle\", { cx: \"11\", cy: \"11\", r: \"8\", key: \"4ej97u\" }],\n [\"line\", { x1: \"21\", x2: \"16.65\", y1: \"21\", y2: \"16.65\", key: \"13gj7c\" }],\n [\"line\", { x1: \"8\", x2: \"14\", y1: \"11\", y2: \"11\", key: \"durymu\" }]\n];\nconst ZoomOut = createLucideIcon(\"zoom-out\", __iconNode);\n\nexport { __iconNode, ZoomOut as default };\n//# sourceMappingURL=zoom-out.js.map\n","import type { AgentAdapter } from '../../agent/types';\nimport type { PDFViewerHandle } from './pdf-viewer';\n\nexport const pdfViewerAgent: AgentAdapter<PDFViewerHandle> = {\n id: 'pdf-viewer',\n capabilities: ['paginate', 'view_change', 'filter'],\n state: {},\n actions: {\n go_to_page: {\n safety: 'read',\n argsType: '{ page: number }',\n description: 'Navigate to a specific 1-indexed page.',\n invoke: (handle, args: { page: number }) => {\n handle.goToPage(args.page);\n },\n },\n set_zoom: {\n safety: 'read',\n argsType: '{ zoom: PDFZoomPreset }',\n description: 'Apply a zoom preset.',\n invoke: (\n handle,\n args: { zoom: Parameters<PDFViewerHandle['setZoom']>[0] },\n ) => {\n handle.setZoom(args.zoom);\n },\n },\n search: {\n safety: 'read',\n argsType: '{ query: string }',\n description:\n 'Search the document for the given query and highlight matches.',\n invoke: (handle, args: { query: string }) => {\n handle.search(args.query);\n },\n },\n print: {\n safety: 'read',\n description: 'Open the browser print dialog for the document.',\n invoke: (handle) => {\n handle.print();\n },\n },\n },\n domHooks: {\n root: { attr: 'data-component', value: 'pdf-viewer' },\n instanceId: {\n attr: 'data-component-id',\n sourceProp: 'id',\n description: 'Sourced from the id prop.',\n },\n },\n};\n","/* ------------------------------------------------------------------ */\n/* PDFViewer — thin React wrapper over Mozilla's pdfjs-dist. */\n/* */\n/* - Worker: loaded once at module scope via Vite's `?url` asset */\n/* import; consumers never configure it (08-third-party §PDF Viewer). */\n/* - Lazy rendering: an IntersectionObserver renders only visible + */\n/* ±1 buffer pages; off-screen pages release GPU memory by setting */\n/* `canvas.width = 0` while the wrapper <article> keeps its reserved */\n/* height so scroll position is stable. */\n/* - Toolbar: WAI-ARIA `role=\"toolbar\"` with roving tabindex (same */\n/* pattern as RichTextEditor — see 05-accessibility.mdx §42). */\n/* - Find bar: Radix Popover; Cmd/Ctrl+F opens; matches decorated in */\n/* the text layer with a `--warning`-tinted background. */\n/* - i18n: every string via `t('pdf.*')`. Icons flipped via `rtl:…`. */\n/* */\n/* TODO: */\n/* - Full PDF.js `printService` integration (A4 / US Letter, 150 DPI,*/\n/* hidden high-DPI canvas). For now `print()` calls `window.print()`*/\n/* which renders the viewer chrome — the `@media print` rule lives */\n/* in a future theme bridge. */\n/* - AnnotationLayer for form fields and links (08-third-party). */\n/* - Accessibility-tag surfacing via `aria-describedby` per the user */\n/* story's screen-reader acceptance row. */\n/* ------------------------------------------------------------------ */\n\nimport {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n type CSSProperties,\n type KeyboardEvent as ReactKeyboardEvent,\n type ReactNode,\n} from 'react';\n// Legacy build, not the default modern one: it bundles the polyfills\n// pdf.js relies on (e.g. Map.prototype.getOrInsertComputed), so PDFs\n// render on older browsers and headless capture engines, not just current Chrome.\nimport * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf.min.mjs';\nimport type {\n PDFDocumentProxy,\n PDFPageProxy,\n} from 'pdfjs-dist/types/src/display/api';\nimport type { PageViewport } from 'pdfjs-dist/types/src/display/display_utils';\nimport { cva } from 'class-variance-authority';\nimport { useTranslation } from 'react-i18next';\nimport * as RadixPopover from '@radix-ui/react-popover';\nimport {\n ChevronLeft,\n ChevronRight,\n ZoomIn,\n ZoomOut,\n Search,\n Printer,\n X,\n} from 'lucide-react';\n\n/* ------------------------------------------------------------------ */\n/* Worker setup — one-shot at module scope */\n/* ------------------------------------------------------------------ */\n\n// Vite resolves `?url` to a static URL string at build time. This keeps\n// PDF.js off the main bundle and lets the consumer not think about it.\nimport pdfjsWorkerUrl from 'pdfjs-dist/legacy/build/pdf.worker.min.mjs?url';\n\nimport { Spinner } from '../spinner';\nimport { Alert } from '../alert';\nimport { useAgentRegistration } from '../../agent/registry';\nimport { pdfViewerAgent } from './pdf-viewer.agent';\n\npdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsWorkerUrl;\n\n/* ------------------------------------------------------------------ */\n/* Public types */\n/* ------------------------------------------------------------------ */\n\nexport type PDFZoomPreset = 'fit-width' | 'fit-page' | 'actual-size' | number;\n\nexport type PDFPageRotation = 0 | 90 | 180 | 270;\n\n/**\n * Arguments passed to `renderPageOverlay` for each rendered page.\n *\n * `pageWidthCss` and `pageHeightCss` are post-zoom, post-rotation CSS\n * pixel dimensions — exactly the rendered box the consumer is\n * positioning content over. They update on resize, zoom, and rotation\n * changes; the render-prop re-runs on every change so positioned\n * children stay in sync with the page geometry without the consumer\n * touching a `ResizeObserver`.\n */\nexport interface PDFPageOverlayArgs {\n /** 1-based page number. */\n pageNumber: number;\n /** CSS-pixel width of the rendered page (post-zoom, post-rotation). */\n pageWidthCss: number;\n /** CSS-pixel height of the rendered page. */\n pageHeightCss: number;\n /**\n * Effective rotation of the rendered viewport in degrees. Reflects\n * `pageRotation` (if set) overriding the page's intrinsic `/Rotate`,\n * otherwise the intrinsic rotation.\n */\n rotation: PDFPageRotation;\n}\n\nexport interface PDFViewerProps {\n /** Opaque instance id — emitted as `data-component-id` for the agent registry. */\n id?: string;\n /** PDF source — URL string, ArrayBuffer, or Uint8Array. */\n src: string | ArrayBuffer | Uint8Array;\n /** Initial page (1-based). Default 1. */\n initialPage?: number;\n /** Initial zoom preset. Default 'fit-width'. */\n initialZoom?: PDFZoomPreset;\n /**\n * Force every page to render at this rotation, overriding the page's\n * intrinsic `/Rotate` metadata. Useful for scanned PDFs that opened\n * sideways, and for the signing-flow consumer that lets users\n * straighten misrotated pages before placing signature fields.\n * `undefined` (default) honours each page's intrinsic rotation.\n */\n pageRotation?: PDFPageRotation;\n /**\n * Render a layer of arbitrary React content positioned over each\n * rendered PDF page — signature fields, redaction boxes, annotation\n * pins, anything that needs to live in PDF coordinate space.\n *\n * The render-prop is invoked **only for pages currently inside the\n * IntersectionObserver buffer** (visible ±1), and the returned tree\n * unmounts when the page leaves the buffer. Consumer-held timers /\n * fetches / subscriptions in overlay children therefore tear down\n * automatically with the page. The overlay container is absolutely\n * positioned, sized to the rendered page, and has\n * `pointer-events: auto` so consumer children can be interactive.\n * Consumers position children themselves (typically\n * `position: absolute; inset-inline-start: %; inset-block-start: %`).\n *\n * The render-prop re-runs on resize, zoom, and rotation changes so\n * positioned children stay aligned without the consumer wiring a\n * `ResizeObserver`. Pages already declare `data-page-number` on the\n * `<article>` ancestor; consumer-rendered children should be\n * keyboard-reachable per the kit's a11y contract.\n *\n * Composition note: PDF.js's `AnnotationLayer` (for native form\n * fields and link annotations) is not yet wired in — see the file\n * header TODO. When it lands, `renderPageOverlay` will compose\n * **above** the AnnotationLayer in z-order, since interactive\n * consumer content should sit on top of intrinsic page widgets.\n */\n renderPageOverlay?: (args: PDFPageOverlayArgs) => ReactNode;\n /** Emits when the currently-most-visible page changes. */\n onPageChange?: (page: number) => void;\n /** Emits once the PDF document has loaded. */\n onLoadComplete?: (info: { numPages: number; title?: string }) => void;\n /** Emits on any load / render error. */\n onError?: (error: Error) => void;\n /** Show the toolbar. Default `true`. */\n toolbar?: boolean;\n /**\n * Toolbar control set. `'full'` (default) is the editor toolbar (page nav,\n * page input, zoom, fit-width, search, print). `'minimal'` is a lean,\n * read-only control set — zoom out / in / preset only — for surfaces like\n * signing where a signer just reads, scrolls, and occasionally zooms.\n */\n toolbarVariant?: 'full' | 'minimal';\n /** Accessible label for the viewer region. */\n ariaLabel?: string;\n /** Extra class names on the wrapper. */\n className?: string;\n}\n\nexport interface PDFViewerHandle {\n goToPage: (page: number) => void;\n setZoom: (zoom: PDFZoomPreset) => void;\n search: (query: string) => void;\n print: () => void;\n}\n\n/* ------------------------------------------------------------------ */\n/* CVA */\n/* ------------------------------------------------------------------ */\n\nconst wrapperVariants = cva(\n [\n 'ds:pdf-viewer-alfadocs ds:flex ds:flex-col',\n // Allow the viewer to shrink below its content's intrinsic width when it\n // sits in a constrained flex/grid context (mobile signing flows): without\n // min-inline-size:0 the page canvas's natural width pins the flex item\n // open, fit-width then measures that inflated width and never scales down.\n 'ds:min-w-0',\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)] ds:[.theme-accessible_&]:border-2',\n 'ds:overflow-hidden',\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 toolbarVariants = cva(\n [\n 'ds:flex ds:flex-wrap ds:items-center ds:gap-[var(--spacing-xs)]',\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-[var(--background)]',\n 'ds:border-b ds:border-[color:var(--border)]',\n ].join(' '),\n);\n\nconst toolbarButtonVariants = cva(\n [\n 'ds:inline-flex 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-sm)] ds:pe-[var(--spacing-sm)]',\n 'ds:rounded-[var(--radius-sm)] ds:bg-transparent ds:text-[var(--foreground)]',\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 pageInputVariants = cva(\n [\n 'ds:[min-block-size:var(--min-target-size)]',\n 'ds:inline-size-[4rem] ds:text-center',\n 'ds:ps-[var(--spacing-xs)] ds:pe-[var(--spacing-xs)]',\n 'ds:rounded-[var(--radius-sm)] ds:border ds:border-[color:var(--border)]',\n 'ds:bg-[var(--background)] ds:text-[var(--foreground)]',\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 zoomSelectVariants = cva(\n [\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)] ds:border ds:border-[color:var(--border)]',\n 'ds:bg-[var(--background)] ds:text-[var(--foreground)]',\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 pagesContainerVariants = cva(\n [\n 'ds:relative ds:flex ds:flex-col ds:items-center',\n 'ds:gap-[var(--spacing-md)]',\n 'ds:p-[var(--spacing-md)]',\n 'ds:bg-[var(--muted)]',\n 'ds:overflow-auto',\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 // NB: `min-block-size-[…]` / `max-block-size-[…]` arbitrary utilities don't\n // generate any CSS in this Tailwind setup (silent no-op) — using them left\n // the container uncapped, so it rendered all pages at full height and never\n // scrolled, which froze the page tracker at 1 and broke SignDocument's\n // read-to-end gate. `min-h`/`max-h` are block-axis height (writing-mode\n // agnostic) and generate correctly.\n 'ds:min-h-[30rem]',\n 'ds:max-h-[80vh]',\n ].join(' '),\n);\n\nconst pageArticleVariants = cva(\n [\n 'ds:relative ds:flex ds:items-center ds:justify-center',\n 'ds:bg-[var(--background)]',\n 'ds:shadow-[var(--shadow-md)]',\n 'ds:rounded-[var(--radius-sm)]',\n ].join(' '),\n);\n\n/* ------------------------------------------------------------------ */\n/* Helpers */\n/* ------------------------------------------------------------------ */\n\nconst ZOOM_PRESETS: ReadonlyArray<PDFZoomPreset> = [\n 'fit-width',\n 'fit-page',\n 'actual-size',\n 0.5,\n 0.75,\n 1,\n 1.25,\n 1.5,\n 2,\n];\n\nfunction isNumberZoom(z: PDFZoomPreset): z is number {\n return typeof z === 'number';\n}\n\nfunction resolveScale(\n zoom: PDFZoomPreset,\n viewport: PageViewport,\n container: HTMLElement | null,\n): number {\n if (isNumberZoom(zoom)) return zoom;\n if (zoom === 'actual-size') return 1;\n if (!container) return 1;\n const style = window.getComputedStyle(container);\n const padX =\n parseFloat(style.paddingInlineStart || '0') +\n parseFloat(style.paddingInlineEnd || '0');\n const padY =\n parseFloat(style.paddingBlockStart || '0') +\n parseFloat(style.paddingBlockEnd || '0');\n const availW = Math.max(container.clientWidth - padX, 1);\n const availH = Math.max(container.clientHeight - padY, 1);\n const baseW = viewport.width;\n const baseH = viewport.height;\n if (zoom === 'fit-width') return availW / baseW;\n // fit-page\n return Math.min(availW / baseW, availH / baseH);\n}\n\ninterface LoadedDocument {\n doc: PDFDocumentProxy;\n numPages: number;\n title?: string;\n}\n\n/* ------------------------------------------------------------------ */\n/* PDFViewer */\n/* ------------------------------------------------------------------ */\n\nexport const PDFViewer = forwardRef<PDFViewerHandle, PDFViewerProps>(\n (\n {\n id,\n src,\n initialPage = 1,\n initialZoom = 'fit-width',\n pageRotation,\n renderPageOverlay,\n onPageChange,\n onLoadComplete,\n onError,\n toolbar = true,\n toolbarVariant = 'full',\n ariaLabel,\n className,\n },\n ref,\n ) => {\n const { t } = useTranslation();\n const rawId = useId();\n const viewerId = useMemo(\n () => `pdf-${rawId.replace(/[^a-zA-Z0-9-_]/g, '')}`,\n [rawId],\n );\n\n /* ---- RTL / reduced motion ------------------------------------ */\n const [isRtl, setIsRtl] = useState(false);\n const [reducedMotion, setReducedMotion] = useState(false);\n useEffect(() => {\n if (typeof document === 'undefined') return undefined;\n setIsRtl(document.documentElement.dir === 'rtl');\n const mql = window.matchMedia('(prefers-reduced-motion: reduce)');\n const sync = (): void => setReducedMotion(mql.matches);\n sync();\n mql.addEventListener('change', sync);\n return () => mql.removeEventListener('change', sync);\n }, []);\n\n /* ---- Document state ------------------------------------------ */\n const [loaded, setLoaded] = useState<LoadedDocument | null>(null);\n const [loadError, setLoadError] = useState<Error | null>(null);\n const [currentPage, setCurrentPage] = useState(initialPage);\n const [zoom, setZoomState] = useState<PDFZoomPreset>(initialZoom);\n const [visibleRange, setVisibleRange] = useState<{\n start: number;\n end: number;\n }>({ start: Math.max(1, initialPage - 1), end: initialPage + 1 });\n const [announcement, setAnnouncement] = useState<string>('');\n const [searchOpen, setSearchOpen] = useState(false);\n const [searchQuery, setSearchQuery] = useState('');\n const [searchMatches, setSearchMatches] = useState<{\n current: number;\n total: number;\n }>({ current: 0, total: 0 });\n\n const onPageChangeRef =\n useRef<PDFViewerProps['onPageChange']>(onPageChange);\n const onLoadCompleteRef =\n useRef<PDFViewerProps['onLoadComplete']>(onLoadComplete);\n const onErrorRef = useRef<PDFViewerProps['onError']>(onError);\n useEffect(() => {\n onPageChangeRef.current = onPageChange;\n onLoadCompleteRef.current = onLoadComplete;\n onErrorRef.current = onError;\n }, [onPageChange, onLoadComplete, onError]);\n\n /* ---- Load the PDF document ----------------------------------- */\n // Ref tracking the currently-loaded document so the cleanup path sees\n // the latest proxy (state closed over in the effect would be stale).\n const loadedRef = useRef<LoadedDocument | null>(null);\n useEffect(() => {\n loadedRef.current = loaded;\n }, [loaded]);\n useEffect(() => {\n let cancelled = false;\n setLoaded(null);\n setLoadError(null);\n\n // `getDocument` accepts a URL string, Uint8Array, or an object with a\n // `data` field. Narrow to what pdfjs expects at runtime. We always pass\n // an options object so that `disableJavaScript` and `isEvalSupported`\n // flow through — patient-uploaded PDFs must not execute embedded JS.\n // See security-hardening.mdx.\n const baseOptions = {\n disableJavaScript: true,\n isEvalSupported: false,\n } as const;\n const task = pdfjsLib.getDocument(\n typeof src === 'string'\n ? { url: src, ...baseOptions }\n : src instanceof Uint8Array\n ? { data: src, ...baseOptions }\n : { data: new Uint8Array(src), ...baseOptions },\n );\n\n task.promise.then(\n async (doc) => {\n if (cancelled) return;\n let title: string | undefined;\n try {\n const meta = await doc.getMetadata();\n const info = meta?.info as { Title?: string } | undefined;\n title = info?.Title;\n } catch {\n title = undefined;\n }\n if (cancelled) {\n // Unmounted while metadata was resolving — destroy the doc we\n // just acquired so the worker channel and font resources are\n // released.\n try {\n await doc.destroy();\n } catch {\n /* ignore */\n }\n return;\n }\n const next: LoadedDocument = { doc, numPages: doc.numPages, title };\n setLoaded(next);\n onLoadCompleteRef.current?.({ numPages: doc.numPages, title });\n },\n (err: unknown) => {\n if (cancelled) return;\n const error = err instanceof Error ? err : new Error(String(err));\n setLoadError(error);\n onErrorRef.current?.(error);\n },\n );\n\n return () => {\n cancelled = true;\n task.destroy();\n // Release the previously-loaded PDFDocumentProxy when src changes\n // or the component unmounts. PDFDocumentProxy holds fonts, embedded\n // resources, and the worker channel — without this call, switching\n // PDFs progressively leaks memory in a long-running SPA.\n const prev = loadedRef.current;\n if (prev) {\n try {\n void prev.doc.destroy();\n } catch {\n /* ignore */\n }\n loadedRef.current = null;\n }\n };\n }, [src]);\n\n /* ---- Current-page announcement ------------------------------- */\n useEffect(() => {\n if (!loaded) return;\n setAnnouncement(\n t('pdf.pageOf', { current: currentPage, total: loaded.numPages }),\n );\n onPageChangeRef.current?.(currentPage);\n }, [currentPage, loaded, t]);\n\n /* ---- Imperative handle --------------------------------------- */\n const pagesContainerRef = useRef<HTMLDivElement>(null);\n const pageArticleRefs = useRef<Array<HTMLElement | null>>([]);\n\n const goToPage = useCallback(\n (page: number) => {\n if (!loaded) return;\n const clamped = Math.max(1, Math.min(page, loaded.numPages));\n setCurrentPage(clamped);\n const article = pageArticleRefs.current[clamped - 1];\n if (article) {\n article.scrollIntoView({\n behavior: reducedMotion ? 'auto' : 'auto',\n block: 'start',\n });\n }\n },\n [loaded, reducedMotion],\n );\n\n const setZoom = useCallback((next: PDFZoomPreset) => {\n setZoomState(next);\n }, []);\n\n const internalPrint = useCallback(() => {\n // TODO: wire PDF.js printService for accurate, chrome-free output.\n if (typeof window !== 'undefined') window.print();\n }, []);\n\n const search = useCallback((query: string) => {\n setSearchQuery(query);\n setSearchOpen(query.length > 0);\n }, []);\n\n const agentHandle = useMemo<PDFViewerHandle>(\n () => ({\n goToPage,\n setZoom,\n search,\n print: internalPrint,\n }),\n [goToPage, setZoom, search, internalPrint],\n );\n useImperativeHandle(ref, () => agentHandle, [agentHandle]);\n useAgentRegistration(pdfViewerAgent, agentHandle, id);\n\n /* ---- Keyboard shortcuts on the viewer ------------------------ */\n const handleViewerKeyDown = useCallback(\n (event: ReactKeyboardEvent<HTMLDivElement>): void => {\n if (!loaded) return;\n const mod = event.metaKey || event.ctrlKey;\n\n if (event.key === 'PageDown') {\n event.preventDefault();\n goToPage(currentPage + 1);\n return;\n }\n if (event.key === 'PageUp') {\n event.preventDefault();\n goToPage(currentPage - 1);\n return;\n }\n if (event.key === 'Home') {\n event.preventDefault();\n goToPage(1);\n return;\n }\n if (event.key === 'End') {\n event.preventDefault();\n goToPage(loaded.numPages);\n return;\n }\n\n if (mod && event.key.toLowerCase() === 'f') {\n event.preventDefault();\n setSearchOpen(true);\n return;\n }\n if (mod && (event.key === '+' || event.key === '=')) {\n event.preventDefault();\n setZoomState((z) => (isNumberZoom(z) ? Math.min(z * 1.25, 4) : 1.25));\n return;\n }\n if (mod && event.key === '-') {\n event.preventDefault();\n setZoomState((z) =>\n isNumberZoom(z) ? Math.max(z / 1.25, 0.25) : 0.75,\n );\n return;\n }\n if (mod && event.key === '0') {\n event.preventDefault();\n setZoomState('fit-width');\n return;\n }\n if (mod && event.key.toLowerCase() === 'p') {\n event.preventDefault();\n internalPrint();\n }\n },\n [currentPage, goToPage, internalPrint, loaded],\n );\n\n /* ---- Intersection observer — visible page tracking ----------- */\n // `currentPage` is referenced only for a fallback inside the observer\n // callback. Including it in the effect deps would destroy and re-create\n // the observer every time the callback updates currentPage — on a\n // 100-page PDF that's O(n) observe() calls on every scroll tick.\n const currentPageRef = useRef<number>(currentPage);\n useEffect(() => {\n currentPageRef.current = currentPage;\n }, [currentPage]);\n useEffect(() => {\n if (!loaded) return undefined;\n const container = pagesContainerRef.current;\n if (!container) return undefined;\n\n const visibility = new Map<number, number>();\n const observer = new IntersectionObserver(\n (entries) => {\n for (const entry of entries) {\n const pageAttr = (entry.target as HTMLElement).dataset.pageNumber;\n if (!pageAttr) continue;\n const n = Number(pageAttr);\n visibility.set(n, entry.intersectionRatio);\n }\n // Compute new \"most visible\" page + visible range\n let best = currentPageRef.current;\n let bestRatio = 0;\n let minVisible = Infinity;\n let maxVisible = -Infinity;\n for (const [page, ratio] of visibility.entries()) {\n if (ratio > bestRatio) {\n best = page;\n bestRatio = ratio;\n }\n if (ratio > 0) {\n minVisible = Math.min(minVisible, page);\n maxVisible = Math.max(maxVisible, page);\n }\n }\n if (bestRatio > 0 && best !== currentPageRef.current) {\n setCurrentPage(best);\n }\n if (minVisible !== Infinity) {\n setVisibleRange({\n start: Math.max(1, minVisible - 1),\n end: Math.min(loaded.numPages, maxVisible + 1),\n });\n }\n },\n { root: container, threshold: [0, 0.25, 0.5, 0.75, 1] },\n );\n\n pageArticleRefs.current.forEach((el) => {\n if (el) observer.observe(el);\n });\n return () => observer.disconnect();\n }, [loaded]);\n\n /* ---- Resize observer — recompute scale on fit presets -------- */\n const [containerSizeTick, setContainerSizeTick] = useState(0);\n useEffect(() => {\n const container = pagesContainerRef.current;\n if (!container || typeof ResizeObserver === 'undefined') return undefined;\n const ro = new ResizeObserver(() => {\n if (zoom === 'fit-width' || zoom === 'fit-page') {\n setContainerSizeTick((v) => v + 1);\n }\n });\n ro.observe(container);\n return () => ro.disconnect();\n }, [zoom]);\n\n /* ---- Toolbar roving tabindex --------------------------------- */\n const toolbarButtonsRef = useRef<Array<HTMLElement | null>>([]);\n const [toolbarFocusIndex, setToolbarFocusIndex] = useState(0);\n const registerToolbarButton = useCallback(\n (index: number) => (el: HTMLElement | null) => {\n toolbarButtonsRef.current[index] = el;\n },\n [],\n );\n const focusToolbarButton = useCallback((index: number) => {\n const btn = toolbarButtonsRef.current[index];\n if (btn) btn.focus();\n }, []);\n // Roving-tabindex span. The minimal toolbar renders only the 3 zoom\n // controls (reindexed 0–2); the full toolbar has 8.\n const toolbarCount = toolbarVariant === 'minimal' ? 2 : 8;\n const handleToolbarKeyDown = useCallback(\n (event: ReactKeyboardEvent<HTMLElement>) => {\n const forward = isRtl ? 'ArrowLeft' : 'ArrowRight';\n const backward = isRtl ? 'ArrowRight' : 'ArrowLeft';\n let next: number | null = null;\n if (event.key === forward)\n next = (toolbarFocusIndex + 1) % toolbarCount;\n else if (event.key === backward)\n next = (toolbarFocusIndex - 1 + toolbarCount) % toolbarCount;\n else if (event.key === 'Home') next = 0;\n else if (event.key === 'End') next = toolbarCount - 1;\n if (next !== null) {\n event.preventDefault();\n setToolbarFocusIndex(next);\n focusToolbarButton(next);\n }\n },\n [focusToolbarButton, isRtl, toolbarFocusIndex],\n );\n\n /* ---- Render ---------------------------------------------------*/\n if (loadError) {\n return (\n <div\n className={[wrapperVariants(), className].filter(Boolean).join(' ')}\n aria-label={ariaLabel ?? t('pdf.error')}\n >\n <div className=\"ds:p-[var(--spacing-lg)]\">\n <Alert variant=\"error\" live=\"polite\">\n <Alert.Description>\n {t('pdf.error')}: {loadError.message}\n </Alert.Description>\n </Alert>\n </div>\n </div>\n );\n }\n\n return (\n // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions -- region-level keyboard shortcuts (search, zoom) intentionally captured at the wrapper for the entire PDF viewer\n <div\n id={viewerId}\n role=\"region\"\n aria-label={ariaLabel ?? t('pdf.toolbarLabel')}\n className={[wrapperVariants(), className].filter(Boolean).join(' ')}\n dir={isRtl ? 'rtl' : undefined}\n onKeyDown={handleViewerKeyDown}\n tabIndex={-1}\n data-component=\"pdf-viewer\"\n data-component-id={id}\n // Exposed for CI assertion (story `WorkerSameOrigin`) — the\n // worker URL must be same-origin so a strict CSP can block\n // cross-origin worker loads. Read by the play function via\n // `getAttribute('data-pdfjs-worker-src')`.\n data-pdfjs-worker-src={pdfjsWorkerUrl}\n >\n {toolbar ? (\n <PDFToolbar\n variant={toolbarVariant}\n currentPage={currentPage}\n numPages={loaded?.numPages ?? 0}\n zoom={zoom}\n onPrev={() => goToPage(currentPage - 1)}\n onNext={() => goToPage(currentPage + 1)}\n onJump={(p) => goToPage(p)}\n onZoomIn={() => {\n setZoomState((z) =>\n isNumberZoom(z) ? Math.min(z * 1.25, 4) : 1.25,\n );\n }}\n onZoomOut={() => {\n setZoomState((z) =>\n isNumberZoom(z) ? Math.max(z / 1.25, 0.25) : 0.75,\n );\n }}\n onZoomPreset={(v) => setZoomState(v)}\n onOpenSearch={() => setSearchOpen(true)}\n onPrint={internalPrint}\n searchOpen={searchOpen}\n onSearchOpenChange={setSearchOpen}\n searchQuery={searchQuery}\n onSearchQueryChange={(v) => {\n setSearchQuery(v);\n }}\n searchMatches={searchMatches}\n register={registerToolbarButton}\n focusIndex={toolbarFocusIndex}\n setFocusIndex={setToolbarFocusIndex}\n onToolbarKeyDown={handleToolbarKeyDown}\n isRtl={isRtl}\n />\n ) : null}\n\n {/* aria-live announcements for page / zoom changes */}\n <div aria-live=\"polite\" aria-atomic=\"true\" className=\"ds:sr-only\">\n {announcement}\n </div>\n\n <div\n ref={pagesContainerRef}\n className={pagesContainerVariants()}\n data-testid=\"pdf-pages-container\"\n // The pages list scrolls (overflow-auto + max-block-size cap), so it\n // must be reachable by keyboard alone — without a tab stop, a\n // keyboard-only user can't scroll a document whose overlays are\n // non-interactive (axe `scrollable-region-focusable`). `tabIndex={0}`\n // makes it focusable; the translated `aria-label` names it without\n // adding a second `role=\"region\"` landmark (which would break the\n // singular region lookups and landmark-uniqueness in consumers).\n // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex -- a scrollable region legitimately needs a keyboard tab stop (axe scrollable-region-focusable); role=\"region\" is deliberately avoided above.\n tabIndex={0}\n aria-label={t('pdf.pagesRegionLabel')}\n >\n {loaded ? (\n Array.from({ length: loaded.numPages }, (_, i) => i + 1).map(\n (pageNumber) => (\n <PDFPage\n key={pageNumber}\n pageNumber={pageNumber}\n totalPages={loaded.numPages}\n doc={loaded.doc}\n zoom={zoom}\n pageRotation={pageRotation}\n renderPageOverlay={renderPageOverlay}\n container={pagesContainerRef.current}\n resizeTick={containerSizeTick}\n shouldRender={\n pageNumber >= visibleRange.start &&\n pageNumber <= visibleRange.end\n }\n registerRef={(el) => {\n pageArticleRefs.current[pageNumber - 1] = el;\n }}\n searchQuery={searchQuery}\n onMatchCount={(count) => {\n // Aggregate simplistically: sum across visible pages.\n setSearchMatches((prev) => {\n if (count === 0 && prev.total === 0) return prev;\n return {\n current: Math.min(prev.current || 1, count || 1),\n total: Math.max(prev.total, count),\n };\n });\n }}\n />\n ),\n )\n ) : (\n <div className=\"ds:inline-flex ds:items-center ds:gap-[var(--spacing-sm)] ds:text-[var(--muted-foreground)] ds:p-[var(--spacing-lg)]\">\n <Spinner size=\"sm\" label={t('pdf.loading')} />\n <span>{t('pdf.loading')}</span>\n </div>\n )}\n </div>\n </div>\n );\n },\n);\n\nPDFViewer.displayName = 'PDFViewer';\n\n/* ------------------------------------------------------------------ */\n/* PDFToolbar */\n/* ------------------------------------------------------------------ */\n\ninterface PDFToolbarProps {\n variant: 'full' | 'minimal';\n currentPage: number;\n numPages: number;\n zoom: PDFZoomPreset;\n onPrev: () => void;\n onNext: () => void;\n onJump: (page: number) => void;\n onZoomIn: () => void;\n onZoomOut: () => void;\n onZoomPreset: (v: PDFZoomPreset) => void;\n onOpenSearch: () => void;\n onPrint: () => void;\n searchOpen: boolean;\n onSearchOpenChange: (v: boolean) => void;\n searchQuery: string;\n onSearchQueryChange: (v: string) => void;\n searchMatches: { current: number; total: number };\n register: (index: number) => (el: HTMLElement | null) => void;\n focusIndex: number;\n setFocusIndex: (n: number) => void;\n onToolbarKeyDown: (event: ReactKeyboardEvent<HTMLElement>) => void;\n isRtl: boolean;\n}\n\nfunction PDFToolbar(props: PDFToolbarProps): ReactNode {\n const { t } = useTranslation();\n const {\n variant,\n currentPage,\n numPages,\n zoom,\n onPrev,\n onNext,\n onJump,\n onZoomIn,\n onZoomOut,\n onZoomPreset,\n onOpenSearch,\n onPrint,\n searchOpen,\n onSearchOpenChange,\n searchQuery,\n onSearchQueryChange,\n searchMatches,\n register,\n focusIndex,\n setFocusIndex,\n onToolbarKeyDown,\n } = props;\n\n // Minimal = zoom-only (read-only signing surface). The zoom cluster\n // reindexes to 0–2 so the roving tabindex stays contiguous.\n const minimal = variant === 'minimal';\n const zoomOutIndex = minimal ? 0 : 3;\n const zoomInIndex = minimal ? 1 : 4;\n // The zoom-preset select (Fit width / Fit page / Actual size / %) is dropped\n // in minimal — a signer just nudges zoom with − / +.\n const zoomSelectIndex = 5;\n\n const [pageInput, setPageInput] = useState(String(currentPage));\n useEffect(() => {\n setPageInput(String(currentPage));\n }, [currentPage]);\n\n const prevDisabled = currentPage <= 1;\n const nextDisabled = currentPage >= numPages;\n\n function commitPageInput(): void {\n const parsed = Number(pageInput);\n if (Number.isFinite(parsed) && parsed >= 1) {\n onJump(Math.min(parsed, numPages));\n } else {\n setPageInput(String(currentPage));\n }\n }\n\n function renderButton(opts: {\n index: number;\n label: string;\n disabled?: boolean;\n onActivate: () => void;\n icon: ReactNode;\n }): ReactNode {\n return (\n <button\n type=\"button\"\n ref={register(opts.index)}\n tabIndex={opts.index === focusIndex ? 0 : -1}\n onFocus={() => setFocusIndex(opts.index)}\n onKeyDown={onToolbarKeyDown}\n aria-label={opts.label}\n aria-disabled={opts.disabled || undefined}\n title={opts.label}\n onClick={(event) => {\n if (opts.disabled) {\n event.preventDefault();\n return;\n }\n opts.onActivate();\n }}\n className={toolbarButtonVariants()}\n >\n {opts.icon}\n </button>\n );\n }\n\n return (\n <div\n role=\"toolbar\"\n aria-label={t('pdf.toolbarLabel')}\n className={toolbarVariants()}\n >\n {!minimal && (\n <>\n {renderButton({\n index: 0,\n label: t('pdf.previousPage'),\n disabled: prevDisabled,\n onActivate: onPrev,\n icon: (\n <ChevronLeft\n aria-hidden=\"true\"\n className=\"ds:block-size-4 ds:inline-size-4 ds:rtl:rotate-180\"\n />\n ),\n })}\n\n {renderButton({\n index: 1,\n label: t('pdf.nextPage'),\n disabled: nextDisabled,\n onActivate: onNext,\n icon: (\n <ChevronRight\n aria-hidden=\"true\"\n className=\"ds:block-size-4 ds:inline-size-4 ds:rtl:rotate-180\"\n />\n ),\n })}\n\n <input\n type=\"number\"\n min={1}\n max={Math.max(numPages, 1)}\n value={pageInput}\n onChange={(e) => setPageInput(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n commitPageInput();\n }\n }}\n onBlur={commitPageInput}\n onFocus={() => setFocusIndex(2)}\n ref={register(2) as (el: HTMLInputElement | null) => void}\n tabIndex={focusIndex === 2 ? 0 : -1}\n aria-label={t('pdf.currentPageInput')}\n className={pageInputVariants()}\n />\n\n <span\n aria-hidden=\"true\"\n className=\"type-body-sm ds:text-[var(--muted-foreground)]\"\n >\n {t('pdf.pageOf', { current: currentPage, total: numPages || 0 })}\n </span>\n\n <span\n aria-hidden=\"true\"\n className=\"ds:inline-block ds:block-size-6 ds:inline-size-px ds:bg-[var(--border)] ds:ms-[var(--spacing-xs)] ds:me-[var(--spacing-xs)]\"\n />\n </>\n )}\n\n {renderButton({\n index: zoomOutIndex,\n label: t('pdf.zoom.out'),\n onActivate: onZoomOut,\n icon: (\n <ZoomOut\n aria-hidden=\"true\"\n className=\"ds:block-size-4 ds:inline-size-4\"\n />\n ),\n })}\n\n {renderButton({\n index: zoomInIndex,\n label: t('pdf.zoom.in'),\n onActivate: onZoomIn,\n icon: (\n <ZoomIn\n aria-hidden=\"true\"\n className=\"ds:block-size-4 ds:inline-size-4\"\n />\n ),\n })}\n\n {!minimal && (\n <select\n aria-label={t('pdf.zoom.preset')}\n value={typeof zoom === 'number' ? String(zoom) : zoom}\n onChange={(e) => {\n const v = e.target.value;\n if (v === 'fit-width' || v === 'fit-page' || v === 'actual-size') {\n onZoomPreset(v);\n } else {\n const parsed = Number(v);\n if (Number.isFinite(parsed)) onZoomPreset(parsed);\n }\n }}\n ref={\n register(zoomSelectIndex) as (el: HTMLSelectElement | null) => void\n }\n tabIndex={focusIndex === zoomSelectIndex ? 0 : -1}\n onFocus={() => setFocusIndex(zoomSelectIndex)}\n onKeyDown={onToolbarKeyDown}\n className={zoomSelectVariants()}\n >\n <option value=\"fit-width\">{t('pdf.zoom.fitWidth')}</option>\n <option value=\"fit-page\">{t('pdf.zoom.fitPage')}</option>\n <option value=\"actual-size\">{t('pdf.zoom.actualSize')}</option>\n {ZOOM_PRESETS.filter(isNumberZoom).map((n) => (\n <option key={n} value={String(n)}>\n {`${Math.round(n * 100)}%`}\n </option>\n ))}\n </select>\n )}\n\n {!minimal && (\n <>\n <RadixPopover.Root\n open={searchOpen}\n onOpenChange={onSearchOpenChange}\n >\n <RadixPopover.Trigger asChild>\n {renderButton({\n index: 6,\n label: t('pdf.search.open'),\n onActivate: onOpenSearch,\n icon: (\n <Search\n aria-hidden=\"true\"\n className=\"ds:block-size-4 ds:inline-size-4\"\n />\n ),\n })}\n </RadixPopover.Trigger>\n <RadixPopover.Portal>\n <RadixPopover.Content\n sideOffset={8}\n className={[\n 'ds:z-[var(--z-popover)]',\n 'ds:bg-[var(--popover)] ds:text-[var(--popover-foreground)]',\n 'ds:rounded-[var(--radius-md)] ds:border ds:border-[color:var(--border)]',\n 'ds:shadow-[var(--shadow-lg)]',\n 'ds:p-[var(--spacing-sm)]',\n 'ds:flex ds:items-center ds:gap-[var(--spacing-xs)]',\n ].join(' ')}\n >\n <input\n type=\"search\"\n // eslint-disable-next-line jsx-a11y/no-autofocus -- focuses the search input when the toolbar opens to capture immediate typing\n autoFocus\n value={searchQuery}\n onChange={(e) => onSearchQueryChange(e.target.value)}\n placeholder={t('pdf.search.placeholder')}\n aria-label={t('pdf.search.placeholder')}\n className={pageInputVariants({\n className: 'ds:inline-size-[16rem] ds:text-start',\n })}\n />\n <span\n aria-live=\"polite\"\n className=\"type-meta ds:text-[var(--muted-foreground)]\"\n >\n {searchMatches.total > 0\n ? t('pdf.search.countOfTotal', {\n current: searchMatches.current,\n total: searchMatches.total,\n })\n : searchQuery\n ? t('pdf.search.noResults')\n : ''}\n </span>\n <RadixPopover.Close asChild>\n <button\n type=\"button\"\n aria-label={t('pdf.search.close')}\n className={toolbarButtonVariants()}\n >\n <X\n aria-hidden=\"true\"\n className=\"ds:block-size-4 ds:inline-size-4\"\n />\n </button>\n </RadixPopover.Close>\n </RadixPopover.Content>\n </RadixPopover.Portal>\n </RadixPopover.Root>\n\n {renderButton({\n index: 7,\n label: t('pdf.print'),\n onActivate: onPrint,\n icon: (\n <Printer\n aria-hidden=\"true\"\n className=\"ds:block-size-4 ds:inline-size-4\"\n />\n ),\n })}\n </>\n )}\n </div>\n );\n}\n\n/* ------------------------------------------------------------------ */\n/* PDFPage — renders one canvas + text layer */\n/* ------------------------------------------------------------------ */\n\ninterface PDFPageProps {\n pageNumber: number;\n totalPages: number;\n doc: PDFDocumentProxy;\n zoom: PDFZoomPreset;\n pageRotation: PDFPageRotation | undefined;\n renderPageOverlay: ((args: PDFPageOverlayArgs) => ReactNode) | undefined;\n container: HTMLElement | null;\n resizeTick: number;\n shouldRender: boolean;\n registerRef: (el: HTMLElement | null) => void;\n searchQuery: string;\n onMatchCount: (count: number) => void;\n}\n\nfunction PDFPage(props: PDFPageProps): ReactNode {\n const {\n pageNumber,\n totalPages,\n doc,\n zoom,\n pageRotation,\n renderPageOverlay,\n container,\n resizeTick,\n shouldRender,\n registerRef,\n searchQuery,\n onMatchCount,\n } = props;\n const { t } = useTranslation();\n\n const canvasRef = useRef<HTMLCanvasElement>(null);\n const textLayerRef = useRef<HTMLDivElement>(null);\n const [dims, setDims] = useState<{ width: number; height: number }>({\n width: 612,\n height: 792,\n });\n const [pageProxy, setPageProxy] = useState<PDFPageProxy | null>(null);\n\n /* Get the page proxy once */\n useEffect(() => {\n let cancelled = false;\n doc.getPage(pageNumber).then((p) => {\n if (!cancelled) setPageProxy(p);\n });\n return () => {\n cancelled = true;\n };\n }, [doc, pageNumber]);\n\n /* Compute dimensions from viewport + zoom (+ optional rotation override) */\n useEffect(() => {\n if (!pageProxy) return;\n // `getViewport` accepts an optional `rotation` that overrides the\n // page's intrinsic `/Rotate`. Pass it through only when the\n // consumer set `pageRotation` explicitly so the default path\n // matches the previous behaviour byte-for-byte.\n const viewportOpts = (scale: number) =>\n pageRotation === undefined\n ? { scale }\n : { scale, rotation: pageRotation };\n const baseViewport = pageProxy.getViewport(viewportOpts(1));\n const scale = resolveScale(zoom, baseViewport, container);\n const scaled = pageProxy.getViewport(viewportOpts(scale));\n setDims({\n width: Math.floor(scaled.width),\n height: Math.floor(scaled.height),\n });\n }, [pageProxy, zoom, container, resizeTick, pageRotation]);\n\n // Derived (not stored) so the overlay receives the correct rotation\n // on the first render that has `pageProxy` — storing it as state\n // would force a second pass through the reconciler before the\n // overlay arg caught up. `pageRotation` (consumer override) wins;\n // otherwise the page's intrinsic `/Rotate` (read from\n // `pageProxy.rotate`). The `as unknown as { rotate?: number }`\n // narrow is needed because `pdfjs-dist`'s public types don't yet\n // expose `.rotate` on `PDFPageProxy` — TODO: remove the cast once\n // upstream types ship it.\n const effectiveRotation: PDFPageRotation =\n pageRotation ??\n (((pageProxy as unknown as { rotate?: number } | null)?.rotate ??\n 0) as PDFPageRotation);\n\n /* Render the canvas + text layer when shouldRender flips on */\n useEffect(() => {\n if (!pageProxy || !shouldRender) {\n // Release GPU memory if we've been culled.\n const canvas = canvasRef.current;\n if (canvas && !shouldRender) {\n canvas.width = 0;\n }\n return undefined;\n }\n\n const canvas = canvasRef.current;\n const textLayerEl = textLayerRef.current;\n if (!canvas) return undefined;\n const ctx = canvas.getContext('2d');\n if (!ctx) return undefined;\n\n const viewportOpts = (scale: number) =>\n pageRotation === undefined\n ? { scale }\n : { scale, rotation: pageRotation };\n const baseViewport = pageProxy.getViewport(viewportOpts(1));\n const scale = resolveScale(zoom, baseViewport, container);\n const viewport = pageProxy.getViewport(viewportOpts(scale));\n const dpr = Math.max(1, window.devicePixelRatio || 1);\n\n canvas.width = Math.floor(viewport.width * dpr);\n canvas.height = Math.floor(viewport.height * dpr);\n ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n\n const renderTask = pageProxy.render({\n canvas,\n canvasContext: ctx,\n viewport,\n });\n\n let cancelled = false;\n let textLayer: pdfjsLib.TextLayer | null = null;\n\n renderTask.promise\n .then(async () => {\n if (cancelled || !textLayerEl) return;\n // Clear prior runs before layering.\n textLayerEl.textContent = '';\n const textContent = await pageProxy.getTextContent();\n if (cancelled) return;\n textLayer = new pdfjsLib.TextLayer({\n textContentSource: textContent,\n container: textLayerEl,\n viewport,\n });\n await textLayer.render();\n // Highlight matches if a search query is active.\n highlightMatches(textLayerEl, searchQuery, onMatchCount);\n })\n .catch(() => {\n // Render cancelled mid-flight — nothing actionable.\n });\n\n return () => {\n cancelled = true;\n try {\n renderTask.cancel();\n } catch {\n /* ignore */\n }\n if (textLayer) {\n try {\n textLayer.cancel();\n } catch {\n /* ignore */\n }\n }\n };\n }, [\n pageProxy,\n shouldRender,\n zoom,\n container,\n resizeTick,\n searchQuery,\n onMatchCount,\n pageRotation,\n ]);\n\n /* Re-run highlight when search query changes without re-rendering */\n useEffect(() => {\n if (!shouldRender) return;\n const textLayerEl = textLayerRef.current;\n if (!textLayerEl) return;\n highlightMatches(textLayerEl, searchQuery, onMatchCount);\n }, [searchQuery, shouldRender, onMatchCount]);\n\n // Inline style — permitted per 23-constraints §Runtime-computed\n // dimensions (PDF.js page viewport × devicePixelRatio). Wrapper height\n // mirrors the canvas so scroll position stays stable even when the\n // page is culled.\n const canvasStyle: CSSProperties = {\n width: dims.width,\n height: dims.height,\n };\n const articleStyle: CSSProperties = {\n width: dims.width,\n height: dims.height,\n };\n\n return (\n <article\n ref={(el) => {\n registerRef(el);\n }}\n data-page-number={pageNumber}\n aria-label={t('pdf.pageOf', { current: pageNumber, total: totalPages })}\n className={pageArticleVariants()}\n // eslint-disable-next-line react/forbid-dom-props -- runtime-computed PDF page dimensions\n style={articleStyle}\n >\n {/* eslint-disable-next-line react/forbid-dom-props -- runtime-computed canvas dimensions */}\n <canvas ref={canvasRef} style={canvasStyle} />\n <div\n ref={textLayerRef}\n aria-hidden=\"false\"\n className={[\n 'ds:absolute ds:inset-0',\n 'ds:overflow-hidden',\n 'ds:select-text',\n 'ds:opacity-100',\n 'ds:[&>span]:absolute ds:[&>span]:whitespace-pre',\n 'ds:[&>span]:text-transparent ds:[&>span]:origin-[0_0]',\n 'ds:[&_[data-match=true]]:bg-[color-mix(in_srgb,var(--warning)_35%,transparent)]',\n 'ds:[&_[data-match=current]]:bg-[color-mix(in_srgb,var(--warning)_60%,transparent)]',\n ].join(' ')}\n />\n {/* Consumer overlay layer — sits above canvas + text layer. Only */}\n {/* mounted while the page is inside the IntersectionObserver */}\n {/* buffer; unmounting tears down consumer-held timers / fetches */}\n {/* the same way the canvas releases GPU memory. Sized via the */}\n {/* article's `width`/`height` style, so it tracks zoom + rotation */}\n {/* without a per-page ResizeObserver. `pointer-events: auto` is */}\n {/* on so consumer children can be interactive while the text */}\n {/* layer underneath remains selectable (transparent text spans). */}\n {shouldRender && renderPageOverlay ? (\n <div\n // `role=\"group\"` + a translated `aria-label` give screen-reader\n // users a stable landmark when interactive overlays exist on a\n // page — without this, consumers' Buttons announce naked, with\n // no cue that they belong to the page above. The label is\n // translation-managed via the existing `pdf.*` namespace.\n role=\"group\"\n aria-label={t('pdf.pageOverlay', { page: pageNumber })}\n className=\"ds:absolute ds:inset-0 ds:pointer-events-auto\"\n data-pdf-page-overlay=\"\"\n data-page-number={pageNumber}\n >\n {renderPageOverlay({\n pageNumber,\n pageWidthCss: dims.width,\n pageHeightCss: dims.height,\n rotation: effectiveRotation,\n })}\n </div>\n ) : null}\n </article>\n );\n}\n\n/* ------------------------------------------------------------------ */\n/* Search-highlight helper */\n/* ------------------------------------------------------------------ */\n\n// Diacritic-insensitive, case-folding normaliser — mirrors the one in\n// command-palette so \"cafe\" matches \"café\" in the text layer.\nfunction normaliseForSearch(value: string): string {\n return value\n .normalize('NFKD')\n .replace(/\\p{Diacritic}/gu, '')\n .toLowerCase();\n}\n\nfunction highlightMatches(\n container: HTMLElement,\n query: string,\n onCount: (count: number) => void,\n): void {\n // Wipe prior highlights.\n const prior = container.querySelectorAll('[data-match]');\n prior.forEach((el) => {\n (el as HTMLElement).removeAttribute('data-match');\n });\n if (!query) {\n onCount(0);\n return;\n }\n const normalisedQuery = normaliseForSearch(query);\n if (!normalisedQuery) {\n onCount(0);\n return;\n }\n // Join span text into one stream so a query spanning wrapped spans still\n // matches, then mark every span overlapping a match range.\n const spans = Array.from(container.querySelectorAll<HTMLSpanElement>('span'));\n const ranges: Array<{ start: number; end: number }> = [];\n const chunks: string[] = [];\n let cursor = 0;\n for (const span of spans) {\n const text = normaliseForSearch(span.textContent ?? '');\n ranges.push({ start: cursor, end: cursor + text.length });\n chunks.push(text);\n cursor += text.length;\n }\n const joined = chunks.join('');\n let matchCount = 0;\n const matched = new Set<number>();\n let from = 0;\n while (from <= joined.length - normalisedQuery.length) {\n const found = joined.indexOf(normalisedQuery, from);\n if (found === -1) break;\n matchCount += 1;\n const matchEnd = found + normalisedQuery.length;\n for (let i = 0; i < ranges.length; i++) {\n const { start, end } = ranges[i];\n if (start < matchEnd && end > found) matched.add(i);\n }\n from = matchEnd;\n }\n matched.forEach((i) => {\n spans[i].setAttribute('data-match', 'true');\n });\n onCount(matchCount);\n}\n\nexport { toolbarButtonVariants, toolbarVariants, wrapperVariants };\n"],"names":["__iconNode","ZoomIn","createLucideIcon","ZoomOut","pdfViewerAgent","handle","args","pdfjsLib","pdfjsWorkerUrl","wrapperVariants","cva","toolbarVariants","toolbarButtonVariants","pageInputVariants","zoomSelectVariants","pagesContainerVariants","pageArticleVariants","ZOOM_PRESETS","isNumberZoom","z","resolveScale","zoom","viewport","container","style","padX","padY","availW","availH","baseW","baseH","PDFViewer","forwardRef","id","src","initialPage","initialZoom","pageRotation","renderPageOverlay","onPageChange","onLoadComplete","onError","toolbar","toolbarVariant","ariaLabel","className","ref","t","useTranslation","rawId","useId","viewerId","useMemo","isRtl","setIsRtl","useState","reducedMotion","setReducedMotion","useEffect","mql","sync","loaded","setLoaded","loadError","setLoadError","currentPage","setCurrentPage","setZoomState","visibleRange","setVisibleRange","announcement","setAnnouncement","searchOpen","setSearchOpen","searchQuery","setSearchQuery","searchMatches","setSearchMatches","onPageChangeRef","useRef","onLoadCompleteRef","onErrorRef","loadedRef","cancelled","baseOptions","task","doc","title","meta","info","next","_a","err","error","prev","pagesContainerRef","pageArticleRefs","goToPage","useCallback","page","clamped","article","setZoom","internalPrint","search","query","agentHandle","useImperativeHandle","useAgentRegistration","handleViewerKeyDown","event","mod","currentPageRef","visibility","observer","entries","entry","pageAttr","n","best","bestRatio","minVisible","maxVisible","ratio","el","containerSizeTick","setContainerSizeTick","ro","v","toolbarButtonsRef","toolbarFocusIndex","setToolbarFocusIndex","registerToolbarButton","index","focusToolbarButton","btn","toolbarCount","handleToolbarKeyDown","forward","backward","jsx","Alert","jsxs","PDFToolbar","p","_","i","pageNumber","PDFPage","count","Spinner","props","variant","numPages","onPrev","onNext","onJump","onZoomIn","onZoomOut","onZoomPreset","onOpenSearch","onPrint","onSearchOpenChange","onSearchQueryChange","register","focusIndex","setFocusIndex","onToolbarKeyDown","minimal","zoomOutIndex","zoomInIndex","zoomSelectIndex","pageInput","setPageInput","prevDisabled","nextDisabled","commitPageInput","parsed","renderButton","opts","Fragment","ChevronLeft","ChevronRight","e","RadixPopover","Search","X","Printer","totalPages","resizeTick","shouldRender","registerRef","onMatchCount","canvasRef","textLayerRef","dims","setDims","pageProxy","setPageProxy","viewportOpts","scale","baseViewport","scaled","effectiveRotation","canvas","textLayerEl","ctx","dpr","renderTask","textLayer","textContent","highlightMatches","canvasStyle","articleStyle","normaliseForSearch","value","onCount","normalisedQuery","spans","ranges","chunks","cursor","span","text","joined","matchCount","matched","from","found","matchEnd","start","end"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,MAAMA,KAAa;AAAA,EACjB,CAAC,UAAU,EAAE,IAAI,MAAM,IAAI,MAAM,GAAG,KAAK,KAAK,UAAU;AAAA,EACxD,CAAC,QAAQ,EAAE,IAAI,MAAM,IAAI,SAAS,IAAI,MAAM,IAAI,SAAS,KAAK,SAAQ,CAAE;AAAA,EACxE,CAAC,QAAQ,EAAE,I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n } from "react/jsx-runtime";
|
|
|
2
2
|
import { forwardRef as ce, useId as le, useMemo as G, useRef as L, useState as x, useEffect as _, useCallback as l, useImperativeHandle as ue } from "react";
|
|
3
3
|
import { c as i } from "./index-D2ZczOXr.js";
|
|
4
4
|
import { useTranslation as me } from "react-i18next";
|
|
5
|
-
import { P as ge } from "./pdf-viewer-
|
|
5
|
+
import { P as ge } from "./pdf-viewer-chMpwpA4.js";
|
|
6
6
|
import { S as pe } from "./signature-capture-COi0Uiqu.js";
|
|
7
7
|
import { u as fe } from "./registry-nPAVE19X.js";
|
|
8
8
|
import { C as J } from "./circle-check-9AeSgJD_.js";
|
|
@@ -341,4 +341,4 @@ export {
|
|
|
341
341
|
je as S,
|
|
342
342
|
ve as s
|
|
343
343
|
};
|
|
344
|
-
//# sourceMappingURL=sign-document
|
|
344
|
+
//# sourceMappingURL=sign-document--nr5cxsB.js.map
|
|
@@ -1 +1 @@
|
|
|
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,OAAO;AAAA,IACL,gBAAgB;AAAA,MACd,MAAM;AAAA,MACN,gBAAgB;AAAA,MAChB,aACE;AAAA,MACF,MAAM,CAACC,MAAWA,EAAO,eAAA;AAAA,IAAe;AAAA,EAC1C;AAAA,EAEF,SAAS;AAAA,IACP,QAAQ;AAAA,MACN,QAAQ;AAAA,MACR,gBAAgB;AAAA,MAChB,aACE;AAAA,MACF,QAAQ,CAACA,MAAWA,EAAO,QAAA;AAAA,IAAQ;AAAA,IAErC,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,gBAAgB;AAAA,MAChB,aAAa;AAAA,MACb,QAAQ,CAACA,MAAW;AAClB,QAAAA,EAAO,MAAA;AAAA,MACT;AAAA,IAAA;AAAA,EACF;AAAA,EAEF,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,OAAO;AAAA,MACP,aAAa;AAAA,IAAA;AAAA,IAEf,YAAY;AAAA,MACV,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,aAAa;AAAA,IAAA;AAAA,EACf;AAEJ,GCyDMC,KAAeC;AAAA,EACnB;AAAA,IACE;AAAA,IACA;A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;AAAA,kBAAA;AAAA,kBAMb,gBAAAY;AAAA,oBAAC;AAAA,oBAAA;AAAA,sBACC,MAAK;AAAA,sBACL,SAAS,MAAM;AACb,wBAAIb,KACCG,EAAA;AAAA,sBACP;AAAA,sBACA,UAAUH;AAAA,sBACV,oBAAkB/B;AAAA,sBAClB,WAAWhC,GAAA;AAAA,sBACX,eAAY;AAAA,sBAEZ,UAAA;AAAA,wBAAA,gBAAA6E,EAACE,GAAA,EAAa,eAAY,QAAO,WAAU,aAAY;AAAA,wBACtDzD,EAAE,sBAAsB;AAAA,sBAAA;AAAA,oBAAA;AAAA,kBAAA;AAAA,gBAC3B;AAAA,cAAA;AAAA,YAAA;AAAA;AAAA,QACF;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEAf,GAAa,cAAc;"}
|
|
1
|
+
{"version":3,"file":"sign-document--nr5cxsB.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,OAAO;AAAA,IACL,gBAAgB;AAAA,MACd,MAAM;AAAA,MACN,gBAAgB;AAAA,MAChB,aACE;AAAA,MACF,MAAM,CAACC,MAAWA,EAAO,eAAA;AAAA,IAAe;AAAA,EAC1C;AAAA,EAEF,SAAS;AAAA,IACP,QAAQ;AAAA,MACN,QAAQ;AAAA,MACR,gBAAgB;AAAA,MAChB,aACE;AAAA,MACF,QAAQ,CAACA,MAAWA,EAAO,QAAA;AAAA,IAAQ;AAAA,IAErC,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,gBAAgB;AAAA,MAChB,aAAa;AAAA,MACb,QAAQ,CAACA,MAAW;AAClB,QAAAA,EAAO,MAAA;AAAA,MACT;AAAA,IAAA;AAAA,EACF;AAAA,EAEF,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,OAAO;AAAA,MACP,aAAa;AAAA,IAAA;AAAA,IAEf,YAAY;AAAA,MACV,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,aAAa;AAAA,IAAA;AAAA,EACf;AAEJ,GCyDMC,KAAeC;AAAA,EACnB;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,EACA,KAAK,GAAG;AAC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,MAAK;AAAA,sBACL,SAAS,MAAM;AACb,wBAAIb,KACCG,EAAA;AAAA,sBACP;AAAA,sBACA,UAAUH;AAAA,sBACV,oBAAkB/B;AAAA,sBAClB,WAAWhC,GAAA;AAAA,sBACX,eAAY;AAAA,sBAEZ,UAAA;AAAA,wBAAA,gBAAA6E,EAACE,GAAA,EAAa,eAAY,QAAO,WAAU,aAAY;AAAA,wBACtDzD,EAAE,sBAAsB;AAAA,sBAAA;AAAA,oBAAA;AAAA,kBAAA;AAAA,gBAC3B;AAAA,cAAA;AAAA,YAAA;AAAA;AAAA,QACF;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEAf,GAAa,cAAc;"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { jsx as s, jsxs as f, Fragment as m } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as k } from "react";
|
|
3
|
+
import { c as y } from "./index-D2ZczOXr.js";
|
|
4
|
+
import { useTranslation as C } from "react-i18next";
|
|
5
|
+
import { S as _ } from "./spinner-OjQNn8oN.js";
|
|
6
|
+
import { C as T } from "./check-DPdL_Sm7.js";
|
|
7
|
+
import { c as w } from "./createLucideIcon-CrFbzy84.js";
|
|
8
|
+
/**
|
|
9
|
+
* @license lucide-react v1.8.0 - ISC
|
|
10
|
+
*
|
|
11
|
+
* This source code is licensed under the ISC license.
|
|
12
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
13
|
+
*/
|
|
14
|
+
const S = [
|
|
15
|
+
["path", { d: "M13 21h8", key: "1jsn5i" }],
|
|
16
|
+
[
|
|
17
|
+
"path",
|
|
18
|
+
{
|
|
19
|
+
d: "M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",
|
|
20
|
+
key: "1a8usu"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
], $ = w("pen-line", S), L = y(
|
|
24
|
+
[
|
|
25
|
+
// Overlay fields are always absolutely positioned within the
|
|
26
|
+
// renderPageOverlay box; the percent geometry rides the inline style.
|
|
27
|
+
"ds:absolute",
|
|
28
|
+
"ds:inline-flex ds:items-center ds:justify-center ds:gap-[var(--spacing-xs)]",
|
|
29
|
+
// The visible box renders at its true percentage geometry. A min-size
|
|
30
|
+
// floor here overstretched short fields past their authored box, so
|
|
31
|
+
// neighbours collided (signed box overlapping the next field). The 44/48px
|
|
32
|
+
// touch target is instead restored via a transparent ::before hit-area
|
|
33
|
+
// expansion — the same pattern Button's `sm` size uses — applied on touch
|
|
34
|
+
// viewports only; on desktop the precise box is the target.
|
|
35
|
+
'ds:before:absolute ds:before:content-[""]',
|
|
36
|
+
"ds:before:inset-x-[calc((var(--min-target-size)-100%)/-2)]",
|
|
37
|
+
"ds:before:inset-y-[calc((var(--min-target-size)-100%)/-2)]",
|
|
38
|
+
"ds:sm:before:hidden",
|
|
39
|
+
// Inline padding lives on the per-state variants below (not the base) so
|
|
40
|
+
// the signed state's tighter padding can't collide with a base ps/pe on
|
|
41
|
+
// the same logical side under Tailwind's JIT ordering.
|
|
42
|
+
"ds:rounded-[var(--radius-sm)]",
|
|
43
|
+
"ds:text-[length:var(--font-size-sm)] ds:font-medium",
|
|
44
|
+
"ds:transition-colors ds:duration-[var(--animation-duration)] ds:motion-reduce:transition-none",
|
|
45
|
+
"ds:focus-visible:outline-[length:var(--focus-ring-width)]",
|
|
46
|
+
"ds:focus-visible:outline-solid",
|
|
47
|
+
"ds:focus-visible:outline-[var(--ring)]",
|
|
48
|
+
"ds:focus-visible:outline-offset-[length:var(--focus-ring-offset)]",
|
|
49
|
+
"ds:forced-colors:focus-visible:outline-[CanvasText]",
|
|
50
|
+
"ds:aria-disabled:cursor-not-allowed"
|
|
51
|
+
].join(" "),
|
|
52
|
+
{
|
|
53
|
+
variants: {
|
|
54
|
+
state: {
|
|
55
|
+
unsigned: [
|
|
56
|
+
"ds:cursor-pointer",
|
|
57
|
+
"ds:ps-[var(--spacing-sm)] ds:pe-[var(--spacing-sm)]",
|
|
58
|
+
"ds:border ds:border-dashed ds:border-[color:var(--ring)]",
|
|
59
|
+
"ds:bg-[color-mix(in_srgb,var(--info)_8%,transparent)]",
|
|
60
|
+
"ds:text-[var(--foreground)]",
|
|
61
|
+
"ds:hover:bg-[color-mix(in_srgb,var(--info)_16%,transparent)]",
|
|
62
|
+
"ds:forced-colors:border-[CanvasText]"
|
|
63
|
+
].join(" "),
|
|
64
|
+
signing: [
|
|
65
|
+
"ds:cursor-progress",
|
|
66
|
+
"ds:ps-[var(--spacing-sm)] ds:pe-[var(--spacing-sm)]",
|
|
67
|
+
"ds:border ds:border-dashed ds:border-[color:var(--border)]",
|
|
68
|
+
"ds:bg-[var(--muted)]",
|
|
69
|
+
"ds:text-[var(--muted-foreground)]",
|
|
70
|
+
"ds:forced-colors:border-[CanvasText]"
|
|
71
|
+
].join(" "),
|
|
72
|
+
signed: [
|
|
73
|
+
// overflow-hidden is NOT on the button root — it would clip the
|
|
74
|
+
// ::before touch-target expansion. It lives on the inner image
|
|
75
|
+
// wrapper instead (see render).
|
|
76
|
+
"ds:cursor-pointer",
|
|
77
|
+
"ds:p-[var(--spacing-xs)]",
|
|
78
|
+
"ds:border ds:border-solid ds:border-[color:var(--success)]",
|
|
79
|
+
"ds:bg-[color-mix(in_srgb,var(--success)_8%,transparent)]",
|
|
80
|
+
"ds:text-[var(--foreground)]",
|
|
81
|
+
"ds:forced-colors:border-[CanvasText]"
|
|
82
|
+
].join(" ")
|
|
83
|
+
},
|
|
84
|
+
// Persistent selection ring for the nav-targeted field. Uses the same
|
|
85
|
+
// tokens as the focus ring but is NOT gated on :focus-visible, so it
|
|
86
|
+
// stays visible as the signer steps between fields. When the field is
|
|
87
|
+
// also focused, the base focus-visible ring composes over it (same
|
|
88
|
+
// outline property, same value) — no visual clash.
|
|
89
|
+
active: {
|
|
90
|
+
true: [
|
|
91
|
+
"ds:outline-solid",
|
|
92
|
+
"ds:outline-[length:var(--focus-ring-width)]",
|
|
93
|
+
"ds:outline-[var(--ring)]",
|
|
94
|
+
"ds:outline-offset-[length:var(--focus-ring-offset)]",
|
|
95
|
+
"ds:forced-colors:outline-[Highlight]"
|
|
96
|
+
].join(" "),
|
|
97
|
+
false: ""
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
defaultVariants: { state: "unsigned", active: !1 }
|
|
101
|
+
}
|
|
102
|
+
), M = k(
|
|
103
|
+
({
|
|
104
|
+
state: e = "unsigned",
|
|
105
|
+
insetInlineStart: o,
|
|
106
|
+
insetBlockStart: a,
|
|
107
|
+
inlineSize: t,
|
|
108
|
+
blockSize: l,
|
|
109
|
+
onActivate: d,
|
|
110
|
+
signedImageSrc: c,
|
|
111
|
+
label: r,
|
|
112
|
+
disabled: v = !1,
|
|
113
|
+
active: u = !1,
|
|
114
|
+
id: p,
|
|
115
|
+
className: b,
|
|
116
|
+
...h
|
|
117
|
+
}, x) => {
|
|
118
|
+
const { t: i } = C(), g = v || e === "signing", n = {};
|
|
119
|
+
o !== void 0 && (n.insetInlineStart = `${o}%`), a !== void 0 && (n.insetBlockStart = `${a}%`), t !== void 0 && (n.inlineSize = `${t}%`), l !== void 0 && (n.blockSize = `${l}%`);
|
|
120
|
+
const z = r ?? i("signatureField.prompt"), F = e === "signing" ? r ? i("signatureField.signingNamed", { label: r }) : i("signatureField.signing") : e === "signed" ? r ? i("signatureField.signedNamed", { label: r }) : i("signatureField.signed") : r ?? i("signatureField.unsigned");
|
|
121
|
+
function j(N) {
|
|
122
|
+
if (g) {
|
|
123
|
+
N.preventDefault();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
d == null || d();
|
|
127
|
+
}
|
|
128
|
+
return /* @__PURE__ */ s(
|
|
129
|
+
"button",
|
|
130
|
+
{
|
|
131
|
+
ref: x,
|
|
132
|
+
type: "button",
|
|
133
|
+
...h,
|
|
134
|
+
"data-component": "signature-field",
|
|
135
|
+
"data-component-id": p,
|
|
136
|
+
"data-state": e,
|
|
137
|
+
"data-active": u || void 0,
|
|
138
|
+
"aria-label": F,
|
|
139
|
+
"aria-disabled": g || void 0,
|
|
140
|
+
"aria-busy": e === "signing" || void 0,
|
|
141
|
+
onClick: j,
|
|
142
|
+
className: [L({ state: e, active: u }), b].filter(Boolean).join(" "),
|
|
143
|
+
style: n,
|
|
144
|
+
children: e === "signing" ? (
|
|
145
|
+
// Decorative: the button's aria-label + aria-busy are the single
|
|
146
|
+
// source of the status announcement, so the Spinner's own
|
|
147
|
+
// role="status" live region is hidden from assistive tech.
|
|
148
|
+
/* @__PURE__ */ s("span", { "aria-hidden": "true", children: /* @__PURE__ */ s(_, { size: "sm", label: i("signatureField.signing") }) })
|
|
149
|
+
) : e === "signed" ? c ? (
|
|
150
|
+
// overflow-hidden + rounding live on this inner wrapper (not the
|
|
151
|
+
// button root) so the signature is clipped to the box WITHOUT
|
|
152
|
+
// clipping the button's ::before touch-target expansion.
|
|
153
|
+
/* @__PURE__ */ s("span", { className: "ds:inline-size-full ds:block-size-full ds:overflow-hidden ds:rounded-[var(--radius-sm)]", children: /* @__PURE__ */ s(
|
|
154
|
+
"img",
|
|
155
|
+
{
|
|
156
|
+
src: c,
|
|
157
|
+
alt: "",
|
|
158
|
+
"aria-hidden": "true",
|
|
159
|
+
className: "ds:block-size-full ds:inline-size-full ds:object-contain"
|
|
160
|
+
}
|
|
161
|
+
) })
|
|
162
|
+
) : /* @__PURE__ */ f(m, { children: [
|
|
163
|
+
/* @__PURE__ */ s(
|
|
164
|
+
T,
|
|
165
|
+
{
|
|
166
|
+
"aria-hidden": "true",
|
|
167
|
+
className: "ds:block-size-4 ds:inline-size-4 ds:text-[var(--success)]"
|
|
168
|
+
}
|
|
169
|
+
),
|
|
170
|
+
/* @__PURE__ */ s("span", { children: i("signatureField.signed") })
|
|
171
|
+
] }) : /* @__PURE__ */ f(m, { children: [
|
|
172
|
+
/* @__PURE__ */ s(
|
|
173
|
+
$,
|
|
174
|
+
{
|
|
175
|
+
"aria-hidden": "true",
|
|
176
|
+
className: "ds:block-size-4 ds:inline-size-4"
|
|
177
|
+
}
|
|
178
|
+
),
|
|
179
|
+
/* @__PURE__ */ s("span", { children: z })
|
|
180
|
+
] })
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
M.displayName = "SignatureField";
|
|
186
|
+
export {
|
|
187
|
+
M as S,
|
|
188
|
+
L as s
|
|
189
|
+
};
|
|
190
|
+
//# sourceMappingURL=signature-field-DbhbpLha.js.map
|