This document defines the Diamond visual style for @goker/qr-code.
Non-negotiable rule: the QR matrix stays identical (same data, ECC, mask, version, and quiet zone). Only the SVG rendering changes. The quiet zone MUST remain intact.
You get the Diamond look in exactly two simple ways:
-
Diagonal grouping (
grouping: "45"orgrouping: "-45")- produces diagonal segments that naturally form a diamond silhouette.
-
Rotate the whole QR (
rotateDeg: 45)- rotates the rendered output as a single SVG group.
There is no extra encoding logic, no alternate QR structure, and no special “diamond algorithm”. It is purely a rendering technique.
Only two shapes are supported:
moduleShape: "square"moduleShape: "circle"
Anything else is unnecessary because corner rounding and grouping already cover the design space.
cornerRadius is not optional. It MUST work for every output type.
This means:
- If modules are rendered as
rect, use rounded rect. - If modules / segments are rendered as
polygon, the renderer MUST convert them into a rounded path (fillet each corner) and output a path. - If output is already a
path(e.g., blob mode), corner rounding MUST be applied consistently where corners/joins exist.
Implementation requirement: corner rounding must be implemented as a geometry post-process that can round corners for polygon/path geometries, not just for rects.
Grouping controls how the matrix is turned into geometry:
grouping: "row"grouping: "col"grouping: "dot"grouping: "blob"grouping: "45"grouping: "-45"
Important: grouping MUST be independent from any "renderer" label or preset.
If you keep a renderer: "classic" | "diamond" option, then diamond MUST be only a preset.
Diamond preset mapping:
rotateDeg = 45grouping = "-45"
That’s it. No additional behaviors.
If you remove renderer entirely, users can achieve the same result by explicitly setting
rotateDeg and grouping.
Square modules MUST support rotation:
moduleRotationDeg: number(e.g.,0,45,90)
This enables “kilim / woven pattern” aesthetics when combined with row/col/dot grouping.
Rules:
- Applies only when
moduleShape: "square". - Does not change the QR matrix; only rotates the rendered geometry for each module/segment.
For grouping: "45" and grouping: "-45":
- Output segments correspond to 4-corner trapezoid/parallelogram shapes in diagonal space.
- These MUST be drawn as polygons, not rects.
- Then cornerRadius rounding converts polygons to rounded paths.
This is mandatory for correctness and visual consistency.
Using polygons as a primary geometry primitive makes it easier to:
- apply cornerRadius consistently,
- build stylized diagonal segments,
- keep the style stable across resolutions and export contexts.
Do NOT use:
strokestroke-linecapstroke-linejoin
Stroke-based styling can shift edges, blur module boundaries, and break the visual structure. All thickness and rounding MUST come from geometry.
Quiet zone MUST remain visually empty after:
- grouping,
- rounding,
- module rotation,
- global rotation.
A stable render pipeline:
- Build geometry in matrix space (+ quiet zone padding).
- Apply grouping to produce segments.
- Apply
moduleRotationDeg(square-only), where applicable. - Apply cornerRadius rounding as a geometry post-process.
- Apply global rotation (
rotateDeg, e.g., 45°) to the final SVG group.
Diamond is not a separate QR type. It is simply diagonal grouping (±45°) and/or a global 45° rotation, while preserving the original QR matrix and quiet zone.