- {/* Live PNG from the QR endpoint */}
- {/* eslint-disable-next-line @next/next/no-img-element */}
-
+ {/* Live preview */}
+
+
+
+ {t('errorLevel')}: {ecc}
+
-
+ {/* Scannability warning */}
+ {lowContrast && (
+
+ ⚠️ {t('lowContrast')}
+
+ )}
+
+ ⚠️ {t('verifyScan')}
+
+
+ {/* Templates */}
+
+ {t('templates')}
+
+ {templates.map((tpl) => (
+
+ ))}
+
+
+
+ {/* Customization */}
+
+ {t('customize')}
+
+ patch({ dotsColor: v })} />
+ patch({ cornersColor: v })} />
+
+ {/* Background incl. transparent */}
+
+
{t('background')}
+
+
+ patch({ background: e.target.value })}
+ className="h-9 w-14 rounded-lg border-0 bg-transparent"
+ />
+
+
+
+ {/* Dot shape */}
+
+
{t('dotShape')}
+
+ {DOT_SHAPES.map((s) => (
+
+ ))}
+
+
+
+ {/* Corner shape */}
+
+
{t('cornerShape')}
+
+ {CORNER_SHAPES.map((s) => (
+
+ ))}
+
+
+
+ {/* Gradient */}
+
+
{t('gradient')}
+
+
+ {config.gradient?.enabled && (
+
+ patch({ gradient: { ...config.gradient!, color2: e.target.value } })
+ }
+ className="h-9 w-14 rounded-lg border-0 bg-transparent"
+ />
+ )}
+
+
+
+ {/* Logo */}
+
+
{t('logo')}
+
+ {config.logo && (
+
+ )}
+
+
+
+ {config.logo && {t('logoHint')}
}
+
+
+ {/* Save */}
+
+
+ {/* Link + export */}
+
{link}
);
}
+
+function ColorRow({
+ label,
+ value,
+ onChange,
+}: {
+ label: string;
+ value: string;
+ onChange: (v: string) => void;
+}) {
+ return (
+
+ );
+}
diff --git a/src/components/editor/types.ts b/src/components/editor/types.ts
index 9c0d712..a5a7386 100644
--- a/src/components/editor/types.ts
+++ b/src/components/editor/types.ts
@@ -24,12 +24,25 @@ export type EditorSection = {
products: EditorProduct[];
};
+export type QrConfig = {
+ template?: string;
+ dotsColor?: string;
+ dotsType?: 'square' | 'dots' | 'rounded' | 'classy' | 'classy-rounded' | 'extra-rounded';
+ cornersColor?: string;
+ cornersType?: 'square' | 'dot' | 'extra-rounded';
+ background?: string; // hex or 'transparent'
+ gradient?: { enabled: boolean; color2: string; type: 'linear' | 'radial' };
+ logo?: string | null;
+ errorCorrectionLevel?: 'L' | 'M' | 'Q' | 'H';
+};
+
export type EditorData = {
slug: string;
name: string;
ordersEnabled: boolean;
defaultLocale: Locale;
palette: Palette;
+ qrConfig: QrConfig;
publishedVersionName: string | null;
sections: EditorSection[];
};
diff --git a/src/lib/contrast.ts b/src/lib/contrast.ts
new file mode 100644
index 0000000..47e7eec
--- /dev/null
+++ b/src/lib/contrast.ts
@@ -0,0 +1,40 @@
+// WCAG relative-luminance contrast ratio, used to warn when a QR's dots vs
+// background won't scan reliably. QR scanners need strong contrast; we treat
+// anything below ~3:1 as risky and recommend much higher for print.
+function hexToRgb(hex: string): [number, number, number] | null {
+ const m = hex.replace('#', '');
+ if (m.length === 3) {
+ const r = parseInt(m[0] + m[0], 16);
+ const g = parseInt(m[1] + m[1], 16);
+ const b = parseInt(m[2] + m[2], 16);
+ return [r, g, b];
+ }
+ if (m.length === 6) {
+ return [parseInt(m.slice(0, 2), 16), parseInt(m.slice(2, 4), 16), parseInt(m.slice(4, 6), 16)];
+ }
+ return null;
+}
+
+function luminance([r, g, b]: [number, number, number]): number {
+ const a = [r, g, b].map((v) => {
+ const s = v / 255;
+ return s <= 0.03928 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);
+ });
+ return 0.2126 * a[0] + 0.7152 * a[1] + 0.7252 * a[2];
+}
+
+// Returns contrast ratio (1..21). `background='transparent'` is measured against
+// white, since that's the most common print surface.
+export function contrastRatio(dots: string, background: string): number {
+ const fg = hexToRgb(dots);
+ const bg = hexToRgb(background === 'transparent' ? '#ffffff' : background);
+ if (!fg || !bg) return 21;
+ const l1 = luminance(fg);
+ const l2 = luminance(bg);
+ const lighter = Math.max(l1, l2);
+ const darker = Math.min(l1, l2);
+ return (lighter + 0.05) / (darker + 0.05);
+}
+
+// Below this, scanning becomes unreliable — surface the warning.
+export const QR_MIN_CONTRAST = 4;