Add a sixth tool with live SVG preview, customizable foreground/background colors, error correction level, margin control, and export as PNG (256–2048px) or SVG. URL params enable shareable state. All processing runs client-side via the qrcode package. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
40 lines
866 B
TypeScript
40 lines
866 B
TypeScript
import QRCode from 'qrcode';
|
|
import type { ErrorCorrectionLevel } from '@/types/qrcode';
|
|
|
|
export async function generateSvg(
|
|
text: string,
|
|
errorCorrection: ErrorCorrectionLevel,
|
|
foregroundColor: string,
|
|
backgroundColor: string,
|
|
margin: number,
|
|
): Promise<string> {
|
|
return QRCode.toString(text, {
|
|
type: 'svg',
|
|
errorCorrectionLevel: errorCorrection,
|
|
color: {
|
|
dark: foregroundColor,
|
|
light: backgroundColor,
|
|
},
|
|
margin,
|
|
});
|
|
}
|
|
|
|
export async function generateDataUrl(
|
|
text: string,
|
|
errorCorrection: ErrorCorrectionLevel,
|
|
foregroundColor: string,
|
|
backgroundColor: string,
|
|
margin: number,
|
|
size: number,
|
|
): Promise<string> {
|
|
return QRCode.toDataURL(text, {
|
|
errorCorrectionLevel: errorCorrection,
|
|
color: {
|
|
dark: foregroundColor,
|
|
light: backgroundColor,
|
|
},
|
|
margin,
|
|
width: size,
|
|
});
|
|
}
|