{"version":3,"file":"QRCode.cjs","names":[],"sources":["../../../src/components/QRCode/QRCode.tsx"],"sourcesContent":["import { useMemo } from \"react\";\nimport type { HTMLAttributes } from \"react\";\n\nimport { cn } from \"@/utils/cn\";\n\nimport { encodeQR, matrixToPath } from \"./qr-encode\";\nimport type { QRErrorCorrection } from \"./qr-encode\";\nimport styles from \"./QRCode.module.css\";\n\nexport interface QRCodeProps extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n    /** The payload. Encoded as UTF-8 when it is not plain digits or upper-case text. */\n    value: string;\n    /** Rendered side in px, quiet zone included. Default `160`. */\n    size?: number;\n    /** Error correction level. Default `\"M\"`. */\n    level?: QRErrorCorrection;\n    /** Quiet zone in modules. The standard asks for 4; below that, scanners start to miss. */\n    margin?: number;\n    /** Module colour. Defaults to black — see the note on dark mode below. */\n    color?: string;\n    /** Background colour. Defaults to white. */\n    background?: string;\n    /**\n     * Accessible name. Defaults to naming the payload, because a screen reader\n     * user cannot scan the symbol: the content has to reach them as text.\n     */\n    label?: string;\n}\n\n/**\n * A QR symbol, encoded in the browser and drawn as SVG.\n *\n * No dependency and no network round trip: an image service would leak the\n * payload — a payment link, a session token, an invite — to a third party, and\n * the encoder is a few kilobytes.\n *\n * SVG rather than canvas so the symbol stays sharp at any size and prints at\n * the printer's resolution instead of the screen's. Everything is one path\n * (horizontal runs merged), because a version-10 symbol is 3 481 modules and\n * that many elements costs real paint time.\n *\n * The colours are **black on white in both themes, on purpose** — they are the\n * one part of the SDK that ignores the theme tokens. Scanners expect\n * dark-on-light, and the ones that cope with an inverted symbol do it slowly and\n * unreliably; a QR that looks integrated with a dark page and scans on the third\n * try is worse than one that looks pasted on. Wiring the modules to\n * `--tempest-text` would flip them light in dark mode and leave a light symbol\n * on the white background, which scans as nothing at all. Override\n * `color`/`background` only with a scanner in hand.\n *\n * @throws {QRCapacityError} When the payload is too long for a version-40\n * symbol at the chosen level. That is a programming error rather than a state\n * to render, so it surfaces instead of silently drawing nothing — wrap it in\n * `ErrorBoundary` if the payload comes from user input.\n *\n * @example\n * <QRCode value=\"https://tempest.dev\" />\n * <QRCode value={pixPayload} level=\"H\" size={220} label=\"QR do Pix\" />\n */\nexport function QRCode({\n    value,\n    size = 160,\n    level = \"M\",\n    margin = 4,\n    color = \"#000000\",\n    background = \"#ffffff\",\n    label,\n    className,\n    style,\n    ...rest\n}: QRCodeProps) {\n    const { path, side } = useMemo(() => {\n        const matrix = encodeQR(value, { level });\n        return {\n            path: matrixToPath(matrix, margin),\n            side: matrix.size + margin * 2,\n        };\n    }, [value, level, margin]);\n\n    return (\n        <div\n            className={cn(styles.wrapper, className)}\n            style={{ width: size, height: size, ...style }}\n            {...rest}\n        >\n            <svg\n                className={styles.svg}\n                viewBox={`0 0 ${side} ${side}`}\n                width={size}\n                height={size}\n                role=\"img\"\n                aria-label={label ?? `QR code: ${value}`}\n                shapeRendering=\"crispEdges\"\n            >\n                <rect width={side} height={side} fill={background} />\n                <path d={path} fill={color} />\n            </svg>\n        </div>\n    );\n}\n"],"mappings":"0JA2DA,SAAgB,EAAO,CACnB,QACA,OAAO,IACP,QAAQ,IACR,SAAS,EACT,QAAQ,UACR,aAAa,UACb,QACA,YACA,QACA,GAAG,GACS,CACZ,GAAM,CAAE,OAAM,SAAA,EAAS,EAAA,QAAA,KAAc,CACjC,IAAM,EAAS,EAAA,SAAS,EAAO,CAAE,OAAM,CAAC,EACxC,MAAO,CACH,KAAM,EAAA,aAAa,EAAQ,CAAM,EACjC,KAAM,EAAO,KAAO,EAAS,CACjC,CACJ,EAAG,CAAC,EAAO,EAAO,CAAM,CAAC,EAEzB,OACI,EAAA,EAAA,IAAA,CAAC,MAAD,CACI,UAAW,EAAA,GAAG,EAAA,QAAO,QAAS,CAAS,EACvC,MAAO,CAAE,MAAO,EAAM,OAAQ,EAAM,GAAG,CAAM,EAC7C,GAAI,EAEJ,UAAA,EAAA,EAAA,KAAA,CAAC,MAAD,CACI,UAAW,EAAA,QAAO,IAClB,QAAS,OAAO,EAAK,GAAG,IACxB,MAAO,EACP,OAAQ,EACR,KAAK,MACL,aAAY,GAAS,YAAY,IACjC,eAAe,aAPnB,SAAA,EASI,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,MAAO,EAAM,OAAQ,EAAM,KAAM,CAAa,CAAA,GACpD,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,EAAG,EAAM,KAAM,CAAQ,CAAA,CAC5B,GACJ,CAAA,CAEb"}