#[cfg_attr(not(target_arch = "wasm32"), allow(dead_code))]
pub(crate) fn qr_svg(data: &str) -> Option<String> {
use qrcode::render::svg;
use qrcode::QrCode;
let code = QrCode::new(data.as_bytes()).ok()?;
Some(
code.render::<svg::Color>()
.min_dimensions(200, 200)
.dark_color(svg::Color("#000000"))
.light_color(svg::Color("#ffffff"))
.quiet_zone(true)
.build(),
)
}
#[cfg(test)]
mod tests {
use super::qr_svg;
#[test]
fn invite_link_renders_svg_qr() {
let link = "https://localharness.xyz/?invite=inv-1-abcdefghij";
let svg = qr_svg(link).expect("QR encode must succeed for a share link");
assert!(!svg.is_empty());
assert!(svg.contains("<svg"), "must be inline SVG: {svg}");
assert!(
svg.contains(r#"viewBox="0 0 205 205""#),
"expected the version-4 41-module ×5 viewBox: {svg}"
);
assert!(
svg.contains(r#"shape-rendering="crispEdges""#),
"modules must not anti-alias: {svg}"
);
assert!(svg.contains("#ffffff"), "white module background: {svg}");
}
}