Files
AtreidesAssetsFree/client/ui/qr.js
T

24 lines
1.1 KiB
JavaScript
Raw Normal View History

2026-10-29 11:57:29 +01:00
// Generated, do not edit. sha256:0357e7318367558ea1c4f3c06bae817f3ef795f556618cac3bc184f31a478f4c
import qrcode from '../vendor/qrcode/qrcode.mjs';
import { esc } from './escape.js';
const ALPHANUMERIC = /^[0-9A-Z $%*+\-./:]*$/;
export const invoiceQrText = (paymentRequest) => `LIGHTNING:${String(paymentRequest).toUpperCase()}`;
export function qrMatrix(text) {
const qr = qrcode(0, 'M');
qr.addData(text, ALPHANUMERIC.test(text) ? 'Alphanumeric' : 'Byte');
qr.make();
const n = qr.getModuleCount();
return Array.from({ length: n }, (_, r) => Array.from({ length: n }, (_, c) => qr.isDark(r, c)));
}
export function qrSvg(text, { quiet = 4, label = '', px = 240 } = {}) {
const m = qrMatrix(text);
const size = m.length + quiet * 2;
let d = '';
m.forEach((row, r) => row.forEach((dark, c) => { if (dark) d += `M${c + quiet} ${r + quiet}h1v1h-1z`; }));
return `<svg class="qr" width="${px}" height="${px}" viewBox="0 0 ${size} ${size}" role="img"${label ? ` aria-label="${esc(label)}"` : ''} shape-rendering="crispEdges">`
+ `<rect width="${size}" height="${size}" fill="#fff"/><path d="${d}" fill="#000"/></svg>`;
}