/* ═══════════════════════════════════════════════════════════════ QR CODE A QR code as an , sized by its container. `center` puts something on a badge over the middle: the NGU dove, or an image (an SVG from src/assets/qr, passed as a data: URL). With anything there, the code switches to high error correction so the modules under the badge are recovered when it's scanned (see lib/qr.ts). The badge covers under 6% of the code, well inside what 'H' repairs, and never reaches the three corner finder patterns. `ink` is the modules and the badge's outline, `paper` the background and the badge. A code should stay dark on light with strong contrast to scan reliably; QrCodeMaker warns when it doesn't, this just draws what it's given. Everything is drawn in the SVG itself (no CSS, and an image is embedded rather than linked), so the element serializes to a file that looks the same outside the page. `ref` reaches the for exactly that. ═══════════════════════════════════════════════════════════════ */ import { useMemo, type Ref } from 'react' import DoveMark from './DoveMark.tsx' import { qrMatrix, qrPath } from '../lib/qr.ts' /* The spec's minimum quiet zone, in modules. Less and some scanners can't find the edge of the code. */ const MARGIN = 4 /* Dark enough to scan as black; the site's deep teal. */ export const QR_INK = '#001011' export const QR_PAPER = '#ffffff' export const QR_DOVE = '#00748a' /* Badge side as a share of the code's width. */ const BADGE = 0.24 /* DoveMark's own viewBox is 72.87 × 48.57. */ const DOVE_ASPECT = 72.867699 / 48.568241 export type QrCenter = { kind: 'dove'; color?: string } | { kind: 'image'; src: string } | null export default function QrCode({ value, center = null, ink = QR_INK, paper = QR_PAPER, label, ref, className, }: { value: string center?: QrCenter ink?: string paper?: string /** Accessible name for the image, e.g. "QR code for /retreats". */ label: string ref?: Ref className?: string }) { const level = center ? 'H' : 'M' const matrix = useMemo(() => qrMatrix(value, level), [value, level]) const path = useMemo(() => qrPath(matrix, MARGIN), [matrix]) const total = matrix.size + MARGIN * 2 const badge = matrix.size * BADGE const badgeAt = (total - badge) / 2 const doveWidth = badge * 0.78 const doveHeight = doveWidth / DOVE_ASPECT const imageSize = badge * 0.8 return ( {center && ( {center.kind === 'dove' ? ( ) : ( )} )} ) }