{"version":3,"file":"QRCode.mjs","names":["qrCodeMessages"],"sources":["../../../src/base-ui/QRCode/QRCode.tsx"],"sourcesContent":["'use client';\n\nimport { cx } from 'antd-style';\nimport { RotateCw } from 'lucide-react';\nimport { memo, useMemo } from 'react';\nimport { encode } from 'uqr';\n\nimport { panelStyles } from '@/base-ui/panelStyles';\nimport Spin from '@/base-ui/Spin';\nimport qrCodeMessages from '@/i18n/resources/en/qrCode';\nimport { useTranslation } from '@/i18n/useTranslation';\nimport Icon from '@/Icon';\n\nimport { buildQrPath } from './qrPath';\nimport { styles } from './style';\nimport type { QRCodeProps } from './type';\n\nconst ICON_RATIO = 0.22;\n\nconst QRCode = memo<QRCodeProps>(\n  ({\n    bgColor = '#fff',\n    bordered = true,\n    className,\n    color = '#000',\n    errorLevel = 'M',\n    icon,\n    onRefresh,\n    ref,\n    size = 160,\n    status = 'active',\n    style,\n    value,\n    ...rest\n  }) => {\n    const { t } = useTranslation(qrCodeMessages);\n    const { count, path } = useMemo(() => {\n      try {\n        const { data } = encode(value, { border: 0, ecc: icon ? 'H' : errorLevel });\n        const hole = icon ? Math.ceil(data.length * ICON_RATIO) | 1 : 0;\n        return { count: data.length, path: buildQrPath(data, hole) };\n      } catch {\n        return { count: 0, path: '' };\n      }\n    }, [value, icon, errorLevel]);\n\n    return (\n      <div\n        className={cx(styles.root, bordered && styles.bordered, className)}\n        ref={ref}\n        style={{ background: bgColor, ...style }}\n        {...rest}\n      >\n        <svg\n          aria-label={value}\n          height={size}\n          role=\"img\"\n          shapeRendering=\"crispEdges\"\n          viewBox={`0 0 ${count} ${count}`}\n          width={size}\n        >\n          <rect fill={bgColor} height={count} width={count} />\n          <path d={path} fill={color} />\n        </svg>\n        {icon && (\n          <span\n            className={styles.icon}\n            style={{ height: size * ICON_RATIO, width: size * ICON_RATIO }}\n          >\n            {icon}\n          </span>\n        )}\n        {status === 'loading' && (\n          <span aria-label={t('qrCode.loading')} className={styles.overlay} role=\"status\">\n            <Spin style={{ color: '#666' }} />\n          </span>\n        )}\n        {status === 'expired' && (\n          <span className={styles.overlay}>\n            <span className={styles.overlayTitle}>{t('qrCode.expired')}</span>\n            {onRefresh && (\n              <button\n                className={panelStyles.pill}\n                style={{ background: '#080808', color: '#fff' }}\n                type=\"button\"\n                onClick={onRefresh}\n              >\n                <Icon icon={RotateCw} size={14} />\n                {t('qrCode.refresh')}\n              </button>\n            )}\n          </span>\n        )}\n      </div>\n    );\n  },\n);\n\nQRCode.displayName = 'QRCode';\n\nexport default QRCode;\n"],"mappings":";;;;;;;;;;;;;;AAiBA,MAAM,aAAa;AAEnB,MAAM,SAAS,MACZ,EACC,UAAU,QACV,WAAW,MACX,WACA,QAAQ,QACR,aAAa,KACb,MACA,WACA,KACA,OAAO,KACP,SAAS,UACT,OACA,OACA,GAAG,WACC;CACJ,MAAM,EAAE,MAAM,eAAeA,cAAc;CAC3C,MAAM,EAAE,OAAO,SAAS,cAAc;EACpC,IAAI;GACF,MAAM,EAAE,SAAS,OAAO,OAAO;IAAE,QAAQ;IAAG,KAAK,OAAO,MAAM;GAAW,CAAC;GAC1E,MAAM,OAAO,OAAO,KAAK,KAAK,KAAK,SAAS,UAAU,IAAI,IAAI;GAC9D,OAAO;IAAE,OAAO,KAAK;IAAQ,MAAM,YAAY,MAAM,IAAI;GAAE;EAC7D,QAAQ;GACN,OAAO;IAAE,OAAO;IAAG,MAAM;GAAG;EAC9B;CACF,GAAG;EAAC;EAAO;EAAM;CAAU,CAAC;CAE5B,OACE,qBAAC,OAAD;EACE,WAAW,GAAG,OAAO,MAAM,YAAY,OAAO,UAAU,SAAS;EAC5D;EACL,OAAO;GAAE,YAAY;GAAS,GAAG;EAAM;EACvC,GAAI;EAJN,UAAA;GAME,qBAAC,OAAD;IACE,cAAY;IACZ,QAAQ;IACR,MAAK;IACL,gBAAe;IACf,SAAS,OAAO,MAAM,GAAG;IACzB,OAAO;IANT,UAAA,CAQE,oBAAC,QAAD;KAAM,MAAM;KAAS,QAAQ;KAAO,OAAO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