n.toFixed(2).replace(/\.00$/, "");
-
export async function renderSVG(qr, params) {
const matrixWidth = qr.version * 4 + 17;
const margin = params["Margin"];
const fg = params["Foreground"];
const bg = params["Background"];
+ const defaultShape = params["Shape"] === "Square-Circle";
const roundness = params["Roundness"];
const file = params["Logo"];
+ const logoRatio = params["Logo size"];
+ const showLogoData = params["Show data behind logo"];
const size = matrixWidth + 2 * margin;
let svg = \`
\`;
return svg;
}
+
+// reduce file bloat from floating point math
+const fmt = (n) => n.toFixed(2).replace(/.00$/, "");
+
+function squircle(x, y, width, handle, cw) {
+ const half = fmt(width / 2);
+
+ if (handle === 0) {
+ return cw ? \`M\${fmt(x + width / 2)},\${fmt(y)}l\${half},\${half}l-\${half},\${half}l-\${half},-\${half}z\` :
+ \`M\${fmt(x + width / 2)},\${fmt(y)}l-\${half},\${half}l\${half},\${half}l\${half},-\${half}z\`
+ }
+
+ const h = fmt(handle);
+ const hInv1 = fmt(half - handle);
+ const hInv2 = fmt(-(half - handle));
+ return cw
+ ? \`M\${fmt(x + width / 2)},\${fmt(y)}c\${h},0 \${half},\${hInv1} \${half},\${half}s\${hInv2},\${half} -\${half},\${half}s-\${half},\${hInv2} -\${half},-\${half}s\${hInv1},-\${half} \${half},-\${half}\`
+ : \`M\${fmt(x + width / 2)},\${fmt(y)}c-\${h},0 -\${half},\${hInv1} -\${half},\${half}s\${hInv1},\${half} \${half},\${half}s\${half},\${hInv2} \${half},-\${half}s\${hInv2},-\${half} -\${half},-\${half}\`;
+}
+
+function roundedRect(x, y, width, radius, cw) {
+ if (radius === 0) {
+ return cw
+ ? \`M\${fmt(x)},\${fmt(y)}h\${width}v\${width}h-\${width}z\`
+ : \`M\${fmt(x)},\${fmt(y)}v\${width}h\${width}v-\${width}z\`;
+ }
+
+ if (radius === width / 2) {
+ const r = fmt(radius);
+ const cwFlag = cw ? "1" : "0";
+ return \`M\${fmt(x + radius)},\${fmt(y)}a\${r},\${r} 0,0,\${cwFlag} 0,\${width}a\${r},\${r} 0,0,\${cwFlag} \${0},-\${width}\`;
+ }
+
+ const r = fmt(radius);
+ const side = fmt(width - 2 * radius);
+ return cw
+ ? \`M\${fmt(x + radius)},\${fmt(y)}h\${side}a\${r},\${r} 0,0,1 \${r},\${r}v\${side}a\${r},\${r} 0,0,1 -\${r},\${r}h-\${side}a\${r},\${r} 0,0,1 -\${r},-\${r}v-\${side}a\${r},\${r} 0,0,1 \${r},-\${r}\`
+ : \`M\${fmt(x + radius)},\${fmt(y)}a\${r},\${r} 0,0,0 -\${r},\${r}v\${side}a\${r},\${r} 0,0,0 \${r},\${r}h\${side}a\${r},\${r} 0,0,0 \${r},-\${r}v-\${side}a\${r},\${r} 0,0,0 -\${r},-\${r}\`;
+}
`