qrdx 0.0.46 → 0.0.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +358 -300
- package/dist/index.js +27 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -7
- package/dist/index.mjs.map +1 -1
- package/dist/qr-code-canvas.js +12 -0
- package/dist/qr-code-canvas.js.map +1 -0
- package/dist/qr-code-canvas.mjs +12 -0
- package/dist/qr-code-canvas.mjs.map +1 -0
- package/dist/src/api.d.ts.map +1 -1
- package/dist/src/art-trace.d.ts +46 -0
- package/dist/src/art-trace.d.ts.map +1 -0
- package/dist/src/art.d.ts +138 -0
- package/dist/src/art.d.ts.map +1 -0
- package/dist/src/body-patterns.d.ts +34 -0
- package/dist/src/body-patterns.d.ts.map +1 -0
- package/dist/src/codegen.d.ts +5 -5
- package/dist/src/codegen.d.ts.map +1 -1
- package/dist/src/codeword-map.d.ts +40 -0
- package/dist/src/codeword-map.d.ts.map +1 -0
- package/dist/src/constants.d.ts +4 -7
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/corner-dot.d.ts +3 -1
- package/dist/src/corner-dot.d.ts.map +1 -1
- package/dist/src/corner-eye.d.ts +5 -2
- package/dist/src/corner-eye.d.ts.map +1 -1
- package/dist/src/detection.d.ts.map +1 -1
- package/dist/src/download.d.ts +50 -6
- package/dist/src/download.d.ts.map +1 -1
- package/dist/src/eps.d.ts +62 -0
- package/dist/src/eps.d.ts.map +1 -0
- package/dist/src/frame-icons.d.ts +11 -0
- package/dist/src/frame-icons.d.ts.map +1 -0
- package/dist/src/frame-import.d.ts +61 -0
- package/dist/src/frame-import.d.ts.map +1 -0
- package/dist/src/frame-spec.d.ts +24 -0
- package/dist/src/frame-spec.d.ts.map +1 -0
- package/dist/src/frame-styles.d.ts +50 -0
- package/dist/src/frame-styles.d.ts.map +1 -0
- package/dist/src/frame.d.ts +126 -0
- package/dist/src/frame.d.ts.map +1 -0
- package/dist/src/frames/builtin.d.ts +8 -0
- package/dist/src/frames/builtin.d.ts.map +1 -0
- package/dist/src/frames/official.d.ts +18 -0
- package/dist/src/frames/official.d.ts.map +1 -0
- package/dist/src/helpers.d.ts +15 -2
- package/dist/src/helpers.d.ts.map +1 -1
- package/dist/src/index.d.ts +25 -13
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/logo-budget.d.ts +54 -0
- package/dist/src/logo-budget.d.ts.map +1 -0
- package/dist/src/logo-cleanup.d.ts +25 -0
- package/dist/src/logo-cleanup.d.ts.map +1 -0
- package/dist/src/logo.d.ts +28 -0
- package/dist/src/logo.d.ts.map +1 -0
- package/dist/src/print.d.ts +73 -0
- package/dist/src/print.d.ts.map +1 -0
- package/dist/src/qr-code-canvas.d.ts +13 -0
- package/dist/src/qr-code-canvas.d.ts.map +1 -0
- package/dist/src/qr-code.d.ts +4 -2
- package/dist/src/qr-code.d.ts.map +1 -1
- package/dist/src/qr-outline.d.ts +41 -0
- package/dist/src/qr-outline.d.ts.map +1 -0
- package/dist/src/qr-shape.d.ts +72 -0
- package/dist/src/qr-shape.d.ts.map +1 -0
- package/dist/src/scan-risk.d.ts +40 -0
- package/dist/src/scan-risk.d.ts.map +1 -0
- package/dist/src/scan-score.d.ts +154 -0
- package/dist/src/scan-score.d.ts.map +1 -0
- package/dist/src/shapes.d.ts +36 -0
- package/dist/src/shapes.d.ts.map +1 -0
- package/dist/src/silhouette.d.ts +28 -0
- package/dist/src/silhouette.d.ts.map +1 -0
- package/dist/src/utils/color.d.ts.map +1 -1
- package/dist/src/utils/fmt.d.ts +24 -0
- package/dist/src/utils/fmt.d.ts.map +1 -0
- package/dist/src/utils/paint.d.ts +80 -0
- package/dist/src/utils/paint.d.ts.map +1 -0
- package/dist/src/utils/parse-color.d.ts +21 -0
- package/dist/src/utils/parse-color.d.ts.map +1 -0
- package/dist/src/utils/path-data.d.ts +24 -0
- package/dist/src/utils/path-data.d.ts.map +1 -0
- package/dist/src/utils/png.d.ts +16 -0
- package/dist/src/utils/png.d.ts.map +1 -0
- package/dist/src/utils/polygon-clip.d.ts +26 -0
- package/dist/src/utils/polygon-clip.d.ts.map +1 -0
- package/dist/src/utils/print-shared.d.ts +20 -0
- package/dist/src/utils/print-shared.d.ts.map +1 -0
- package/dist/src/utils/svg-geometry.d.ts +49 -0
- package/dist/src/utils/svg-geometry.d.ts.map +1 -0
- package/dist/src/utils/svg-gradient.d.ts +59 -0
- package/dist/src/utils/svg-gradient.d.ts.map +1 -0
- package/dist/src/utils/svg-painter.d.ts +152 -0
- package/dist/src/utils/svg-painter.d.ts.map +1 -0
- package/dist/src/utils/webp.d.ts +25 -0
- package/dist/src/utils/webp.d.ts.map +1 -0
- package/dist/src/utils.d.ts +18 -2
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/webp.d.ts +19 -0
- package/dist/src/webp.d.ts.map +1 -0
- package/dist/types/art.d.ts +64 -0
- package/dist/types/art.d.ts.map +1 -0
- package/dist/types/color.d.ts +125 -7
- package/dist/types/color.d.ts.map +1 -1
- package/dist/types/corner-dot.d.ts +52 -2
- package/dist/types/corner-dot.d.ts.map +1 -1
- package/dist/types/corner-eye.d.ts +43 -2
- package/dist/types/corner-eye.d.ts.map +1 -1
- package/dist/types/frame-spec.d.ts +3509 -0
- package/dist/types/frame-spec.d.ts.map +1 -0
- package/dist/types/frame.d.ts +68 -0
- package/dist/types/frame.d.ts.map +1 -0
- package/dist/types/image-pattern.d.ts +15 -1
- package/dist/types/image-pattern.d.ts.map +1 -1
- package/dist/types/index.d.ts +15 -9
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +6 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/qr.d.ts +1684 -4
- package/dist/types/qr.d.ts.map +1 -1
- package/dist/types/template.d.ts +2 -2
- package/dist/types/template.d.ts.map +1 -1
- package/package.json +70 -25
- package/src/api.tsx +67 -17
- package/src/art-trace.ts +554 -0
- package/src/art.tsx +2226 -0
- package/src/body-patterns.tsx +389 -0
- package/src/codegen.ts +10 -5
- package/src/codeword-map.ts +265 -0
- package/src/constants.ts +4 -8
- package/src/corner-dot.tsx +209 -33
- package/src/corner-eye.ts +328 -60
- package/src/detection.ts +5 -11
- package/src/download.tsx +174 -70
- package/src/eps.ts +701 -0
- package/src/frame-icons.ts +325 -0
- package/src/frame-import.ts +1198 -0
- package/src/frame-spec.ts +518 -0
- package/src/frame-styles.ts +1095 -0
- package/src/frame.tsx +630 -0
- package/src/frames/builtin/banner-bottom.json +58 -0
- package/src/frames/builtin/circle.json +81 -0
- package/src/frames/builtin/rounded-border.json +60 -0
- package/src/frames/builtin/ticket.json +51 -0
- package/src/frames/builtin.ts +20 -0
- package/src/frames/official/attendance.json +110 -0
- package/src/frames/official/audio-guide.json +95 -0
- package/src/frames/official/book-now.json +103 -0
- package/src/frames/official/check-in.json +110 -0
- package/src/frames/official/christmas.json +131 -0
- package/src/frames/official/donate.json +77 -0
- package/src/frames/official/event-ticket.json +77 -0
- package/src/frames/official/feedback-bubble.json +73 -0
- package/src/frames/official/follow-us.json +83 -0
- package/src/frames/official/get-the-app.json +107 -0
- package/src/frames/official/halloween.json +80 -0
- package/src/frames/official/new-year.json +94 -0
- package/src/frames/official/order-at-table.json +86 -0
- package/src/frames/official/product-info.json +119 -0
- package/src/frames/official/register-product.json +77 -0
- package/src/frames/official/review-us.json +127 -0
- package/src/frames/official/rsvp-card.json +112 -0
- package/src/frames/official/save-contact.json +117 -0
- package/src/frames/official/scan-to-pay.json +94 -0
- package/src/frames/official/shop-window.json +81 -0
- package/src/frames/official/sign-rider.json +81 -0
- package/src/frames/official/table-tent.json +75 -0
- package/src/frames/official/wifi-card.json +89 -0
- package/src/frames/official/winter.json +142 -0
- package/src/frames/official.ts +77 -0
- package/src/helpers.ts +168 -11
- package/src/index.tsx +150 -172
- package/src/logo-budget.ts +226 -0
- package/src/logo-cleanup.ts +146 -0
- package/src/logo.tsx +137 -0
- package/src/print.ts +794 -0
- package/src/qr-code-canvas.tsx +241 -0
- package/src/qr-code.tsx +51 -16
- package/src/qr-outline.ts +511 -0
- package/src/qr-shape.ts +255 -0
- package/src/scan-risk.ts +197 -0
- package/src/scan-score.ts +1629 -0
- package/src/shapes.ts +169 -0
- package/src/silhouette.ts +334 -0
- package/src/utils/color.ts +10 -1
- package/src/utils/fmt.ts +59 -0
- package/src/utils/paint.ts +317 -0
- package/src/utils/parse-color.ts +135 -0
- package/src/utils/path-data.ts +182 -0
- package/src/utils/png.ts +175 -0
- package/src/utils/polygon-clip.ts +163 -0
- package/src/utils/print-shared.ts +74 -0
- package/src/utils/svg-geometry.ts +838 -0
- package/src/utils/svg-gradient.ts +407 -0
- package/src/utils/svg-painter.ts +946 -0
- package/src/utils/webp.ts +556 -0
- package/src/utils.tsx +794 -385
- package/src/webp.ts +84 -0
- package/types/art.ts +74 -0
- package/types/color.ts +132 -12
- package/types/corner-dot.ts +41 -4
- package/types/corner-eye.ts +31 -4
- package/types/frame-spec.ts +748 -0
- package/types/frame.ts +67 -0
- package/types/image-pattern.ts +15 -0
- package/types/index.ts +106 -4
- package/types/qr.ts +180 -2
- package/types/template.ts +2 -2
- package/dist/cli.js +0 -4319
package/README.md
CHANGED
|
@@ -1,414 +1,472 @@
|
|
|
1
1
|
# qrdx
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Customizable QR codes for React: SVG and canvas rendering, dot and eye patterns, gradients, logos, call-to-action frames, Logo QR and Image QR art, PNG/JPG/WebP/SVG/PDF/EPS export, print-ready files, a scan score and QR scanning.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
It powers the [QRdx](https://qrdx.dev) QR code generator. Docs: [qrdx.dev/docs](https://qrdx.dev/docs) · CLI: [`@qrdx/cli`](https://www.npmjs.com/package/@qrdx/cli) · No-code: [image API](https://qrdx.dev/docs/developers/image-api) and [MCP server](https://qrdx.dev/docs/developers/mcp)
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- 🎭 **Templates** — Pre-designed templates for various visual styles
|
|
10
|
-
- 📱 **Multiple Formats** — Canvas and SVG rendering with export options
|
|
11
|
-
- ♿ **Accessibility** — Built-in contrast checking utilities
|
|
12
|
-
- ⚡ **Performance** — Optimized rendering with Path2D support
|
|
13
|
-
- 🎯 **TypeScript** — Full type safety and IntelliSense support
|
|
14
|
-
- 🔒 **Error Correction** — Configurable error correction levels (L, M, Q, H)
|
|
7
|
+
> [!NOTE]
|
|
8
|
+
> This README documents qrdx 0.0.47, the version in this repository. npm still has 0.0.46, so `npm install qrdx` installs 0.0.46 until 0.0.47 is published. In 0.0.46 the basic code works, but most patterns, frames, Art QR, EPS export and the scan score came later, and it lists React 19, sharp and jspdf as its own dependencies. Until the release is out, use every option in the [playground](https://qrdx.dev/playground), or render images from a URL with the [image API](https://qrdx.dev/docs/developers/image-api). Run `npm view qrdx version` to see what npm installs, and see [CHANGELOG.md](./CHANGELOG.md) for what 0.0.47 adds.
|
|
15
9
|
|
|
16
10
|
## Installation
|
|
17
11
|
|
|
18
12
|
```bash
|
|
19
|
-
|
|
20
|
-
pnpm add qrdx
|
|
13
|
+
npm install qrdx
|
|
14
|
+
# or: pnpm add qrdx / yarn add qrdx
|
|
15
|
+
```
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
npm install qrdx@latest
|
|
17
|
+
`react` and `react-dom` (18 or newer) are peer dependencies. PDF export also needs the optional `jspdf` peer:
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
```bash
|
|
20
|
+
npm install jspdf
|
|
27
21
|
```
|
|
28
22
|
|
|
29
|
-
##
|
|
30
|
-
|
|
31
|
-
### Simple QR Code
|
|
23
|
+
## Quick start
|
|
32
24
|
|
|
33
25
|
```tsx
|
|
34
|
-
import {
|
|
35
|
-
|
|
36
|
-
export
|
|
37
|
-
return
|
|
38
|
-
<QRCode
|
|
39
|
-
url="https://example.com"
|
|
40
|
-
size={512}
|
|
41
|
-
/>
|
|
42
|
-
);
|
|
26
|
+
import { QRCodeSVG } from "qrdx";
|
|
27
|
+
|
|
28
|
+
export function Example() {
|
|
29
|
+
return <QRCodeSVG value="https://example.com" size={256} />;
|
|
43
30
|
}
|
|
44
31
|
```
|
|
45
32
|
|
|
46
|
-
|
|
33
|
+
`QRCodeSVG` and `QRCode` use no client-only hooks, so they render in React Server Components as well as on the client. `QRCodeCanvas` is a client component (it ships with `"use client"`). The download, clipboard and scanning helpers need a browser DOM.
|
|
47
34
|
|
|
48
|
-
|
|
49
|
-
import { QRCode } from 'qrdx';
|
|
50
|
-
|
|
51
|
-
export default function App() {
|
|
52
|
-
return (
|
|
53
|
-
<QRCode
|
|
54
|
-
url="https://example.com"
|
|
55
|
-
fgColor="#1a56db"
|
|
56
|
-
bgColor="#f9fafb"
|
|
57
|
-
eyeColor="#0d47a1"
|
|
58
|
-
dotColor="#1976d2"
|
|
59
|
-
size={512}
|
|
60
|
-
/>
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
```
|
|
35
|
+
## Components
|
|
64
36
|
|
|
65
|
-
###
|
|
37
|
+
### `QRCodeSVG`
|
|
38
|
+
|
|
39
|
+
The core renderer. Every styling option is supported here.
|
|
66
40
|
|
|
67
41
|
```tsx
|
|
68
|
-
import {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
42
|
+
import { QRCodeSVG } from "qrdx";
|
|
43
|
+
|
|
44
|
+
<QRCodeSVG
|
|
45
|
+
value="https://example.com"
|
|
46
|
+
size={512}
|
|
47
|
+
level="H"
|
|
48
|
+
fgColor="#1a56db"
|
|
49
|
+
bgColor="#f9fafb"
|
|
50
|
+
eyeColor="#0d47a1"
|
|
51
|
+
dotColor="#1976d2"
|
|
52
|
+
bodyPattern="rounded"
|
|
53
|
+
cornerEyePattern="rounded"
|
|
54
|
+
cornerEyeDotPattern="circle"
|
|
55
|
+
margin={2}
|
|
56
|
+
imageSettings={{
|
|
57
|
+
src: "https://example.com/logo.png",
|
|
58
|
+
width: 128,
|
|
59
|
+
height: 128,
|
|
60
|
+
excavate: true,
|
|
61
|
+
}}
|
|
62
|
+
/>;
|
|
80
63
|
```
|
|
81
64
|
|
|
82
|
-
|
|
65
|
+
| Prop | Type | Default | Description |
|
|
66
|
+
|------|------|---------|-------------|
|
|
67
|
+
| `value` | `string` | **required** | Text or URL to encode |
|
|
68
|
+
| `size` | `number` | `128` | Width and height in pixels |
|
|
69
|
+
| `level` | `"L" \| "M" \| "Q" \| "H"` | `"Q"` | Error correction level |
|
|
70
|
+
| `fgColor` | `ColorConfig` | `"#000000"` | Data module color (solid or gradient) |
|
|
71
|
+
| `bgColor` | `ColorConfig` | `"#FFFFFF"` | Background color (solid or gradient) |
|
|
72
|
+
| `eyeColor` | `ColorConfig` | `fgColor` | Color of the three corner eyes (outer squares) |
|
|
73
|
+
| `dotColor` | `ColorConfig` | `fgColor` | Color of the dots inside the corner eyes |
|
|
74
|
+
| `bodyPattern` | `BodyPattern` | `"circle"` | Shape of the data modules |
|
|
75
|
+
| `cornerEyePattern` | `CornerEyePattern` | `"gear"` | Shape of the corner eyes |
|
|
76
|
+
| `cornerEyeDotPattern` | `CornerEyeDotPattern` | `"circle"` | Shape of the corner eye dots |
|
|
77
|
+
| `margin` | `number` | `0` | Quiet zone in modules. The QR spec recommends 4 when the code sits on a busy or dark background |
|
|
78
|
+
| `imageSettings` | `ImageSettings` | — | Center image; see below |
|
|
79
|
+
| `templateId` | `string` | — | Built-in decorative template; see [Templates](#templates) |
|
|
80
|
+
| `customTemplate` | `TemplateDefinition` | — | Your own template (takes precedence over `templateId`) |
|
|
81
|
+
| `customProps` | `Record<string, any>` | — | Extra props passed to the template wrapper |
|
|
82
|
+
| `isOGContext` | `boolean` | `false` | Render the logo as an absolutely positioned `<img>` for OG image renderers |
|
|
83
|
+
| `frame` | `QRFrame` | — | "Scan me" style frame; see [Frames](#frames-call-to-action) |
|
|
84
|
+
| `art` | `QRArt` | — | Blend a logo or photo into the modules; see [Art QR](#art-qr-logo-qr-and-image-qr) |
|
|
85
|
+
|
|
86
|
+
Any other SVG attribute (`className`, `style`, `aria-label`, …) is forwarded to the root `<svg>`.
|
|
87
|
+
|
|
88
|
+
`imageSettings`: `src` (image URL or data URL), `width` and `height` (pixels, relative to `size`), `excavate` (clear the modules behind the image), optional `x` / `y`, `shape` (`"square"`, `"rounded"` or `"circle"` crop) and `plate` (a solid color behind the logo, in its shape; the logo is inset on it). The crop is a clip path that the PDF and EPS exporters apply too. `removeLogoBackground(src)` (browser) and `removeLogoBackdrop(pixels)` clear a logo's solid background from the edges inward. Use level `H` (or at least `Q`) with a logo and keep it under roughly 25% of the code's width.
|
|
89
|
+
|
|
90
|
+
### `QRCode`
|
|
91
|
+
|
|
92
|
+
A convenience wrapper around `QRCodeSVG` with a simpler logo API (`logo` / `hideLogo`).
|
|
83
93
|
|
|
84
94
|
```tsx
|
|
85
|
-
import { QRCode } from
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
<QRCode
|
|
90
|
-
url="https://example.com"
|
|
91
|
-
templateId="gradient-blue"
|
|
92
|
-
size={512}
|
|
93
|
-
/>
|
|
94
|
-
);
|
|
95
|
-
}
|
|
95
|
+
import { QRCode } from "qrdx";
|
|
96
|
+
|
|
97
|
+
<QRCode value="https://example.com" size={256} />; // no logo
|
|
98
|
+
<QRCode value="https://example.com" size={256} logo="https://example.com/logo.png" level="H" />;
|
|
96
99
|
```
|
|
97
100
|
|
|
98
|
-
|
|
101
|
+
It accepts the `QRCodeSVG` styling props above (`value`, `size`, `level`, colors, patterns, `margin`, `templateId`, `customTemplate`, `customProps`, `style`) plus:
|
|
102
|
+
|
|
103
|
+
| Prop | Type | Default | Description |
|
|
104
|
+
|------|------|---------|-------------|
|
|
105
|
+
| `logo` | `string` | — | Center logo URL or data URL. No logo is drawn unless you pass one |
|
|
106
|
+
| `hideLogo` | `boolean` | `false` | Hide the logo even when `logo` is set (handy for toggles) |
|
|
107
|
+
| `logoOptions` | `LogoOptions` | — | Logo `size` (share of the code's width, 0.1–0.3, default 0.25), `padding` (clear space, 0–2 modules), `x` / `y` (center across the code, 0–1, default 0.5), `shape` and `plate` |
|
|
108
|
+
| `scale` | `number` | `1` | Multiplier applied to `size` |
|
|
109
|
+
|
|
110
|
+
The logo is drawn at 25% of the code's width with the modules behind it excavated, so pair it with level `H` (or at least the default `Q`). `getQRData` takes the same `logoOptions` and turns them into `imageSettings`; with `autoLevel` it lays the logo out at the level the code is drawn at. Both cap the logo (size plus clear space) so its worst Reed–Solomon block loses at most 60% of what it can repair (`getLogoSizeLimit`, `getLogoBlockDamage`, on `getCodewordMap`); small codes hold smaller logos. Raw `imageSettings` passed to `QRCodeSVG`, `QRCodeCanvas` or `getQRAsSVG` get the same cap: a logo that fits is drawn as given, a bigger one is shrunk around its own center, keeping its aspect ratio and clear space. `getScanScore` checks the logo as passed, before the cap, with the same per-block count.
|
|
99
111
|
|
|
100
|
-
|
|
112
|
+
### `QRCodeCanvas`
|
|
113
|
+
|
|
114
|
+
Renders to a `<canvas>` (device-pixel-ratio aware). It draws plain square modules with solid colors only — gradients fall back to their first stop, and the pattern, eye/dot color, `eyeColors`, `moduleScale` and template props are ignored. Use `QRCodeSVG` for styled codes.
|
|
101
115
|
|
|
102
116
|
```tsx
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
export default function App() {
|
|
106
|
-
return (
|
|
107
|
-
<QRCode
|
|
108
|
-
url="https://example.com"
|
|
109
|
-
bodyPattern="rounded"
|
|
110
|
-
size={512}
|
|
111
|
-
/>
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
```
|
|
117
|
+
"use client";
|
|
118
|
+
import { QRCodeCanvas } from "qrdx";
|
|
115
119
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
120
|
+
<QRCodeCanvas
|
|
121
|
+
value="https://example.com"
|
|
122
|
+
size={256}
|
|
123
|
+
level="Q"
|
|
124
|
+
fgColor="#000000"
|
|
125
|
+
bgColor="#ffffff"
|
|
126
|
+
imageSettings={{ src: "/logo.png", width: 64, height: 64, excavate: true }}
|
|
127
|
+
/>;
|
|
128
|
+
```
|
|
124
129
|
|
|
125
|
-
##
|
|
130
|
+
## Patterns
|
|
126
131
|
|
|
127
|
-
|
|
132
|
+
See every option drawn live at [qrdx.dev/docs/styles](https://qrdx.dev/docs/styles).
|
|
128
133
|
|
|
129
|
-
|
|
134
|
+
**Body** (`bodyPattern`, default `circle`): <!-- catalogue:BODY_PATTERN -->`circle`, `circle-large`, `square`, `diamond`, `circle-mixed`, `pacman`, `rounded`, `small-square`, `vertical-line`, `horizontal-line`, `liquid`, `liquid-horizontal`, `liquid-vertical`, `classy`, `classy-rounded`, `leaf`, `plus`, `hexagon`, `star`, `heart`, `random-dots`, `mosaic`, `octagon`<!-- /catalogue -->
|
|
130
135
|
|
|
131
|
-
|
|
136
|
+
**Corner eye** (`cornerEyePattern`, default `gear`): <!-- catalogue:CORNER_EYE_PATTERNS -->`square`, `rounded`, `gear`, `circle`, `diya`, `extra-rounded`, `message`, `pointy`, `leaf`, `drop`, `octagon`, `bevel`, `squircle`, `cushion`, `shield`, `petal`, `leaf-reverse`<!-- /catalogue -->
|
|
132
137
|
|
|
133
|
-
|
|
134
|
-
|------|------|---------|-------------|
|
|
135
|
-
| `url` | `string` | **required** | The URL or text to encode |
|
|
136
|
-
| `size` | `number` | `128` | Size of the QR code in pixels |
|
|
137
|
-
| `scale` | `number` | `1` | Scale multiplier for the QR code |
|
|
138
|
-
| `fgColor` | `string` | `#000000` | Foreground/QR code color |
|
|
139
|
-
| `bgColor` | `string` | `#ffffff` | Background color |
|
|
140
|
-
| `eyeColor` | `string` | `fgColor` | Color for the position markers (eyes) |
|
|
141
|
-
| `dotColor` | `string` | `fgColor` | Color for the data dots |
|
|
142
|
-
| `hideLogo` | `boolean` | `true` | Whether to hide the logo |
|
|
143
|
-
| `logo` | `string` | Default Flam logo | URL to custom logo image |
|
|
144
|
-
| `templateId` | `string` | `'default'` | ID of the template to use |
|
|
145
|
-
| `level` | `'L' \| 'M' \| 'Q' \| 'H'` | `'Q'` | Error correction level |
|
|
146
|
-
| `margin` | `number` | `0` | Margin around the QR code (in modules) |
|
|
138
|
+
**Corner eye dot** (`cornerEyeDotPattern`, default `circle`): <!-- catalogue:CORNER_EYE_DOT_PATTERNS -->`square`, `rounded`, `circle`, `message`, `message-reverse`, `diya`, `diya-reverse`, `rounded-triangle`, `leaf`, `drop`, `plus`, `cross-rounded`, `hexagon`, `octagon`, `flower`, `heart`, `squircle`, `dots`, `extra-rounded`, `leaf-reverse`, `drop-reverse`<!-- /catalogue -->
|
|
147
139
|
|
|
148
|
-
|
|
140
|
+
The same lists are exported as `BODY_PATTERN`, `CORNER_EYE_PATTERNS` and `CORNER_EYE_DOT_PATTERNS`. `liquid` and `classy` join neighbouring modules into one outline; `leaf`, `drop` and `petal` eyes turn to face their corner of the code. Alignment patterns are always drawn as solid squares. Every value is tested to decode with jsQR through a phone-camera model next to every other value (and was checked with ZXing and in sharp renders); `square` and `rounded` eyes scan most reliably and `circle` eyes may be missed by some apps. A few body × eye pairs are weak together (`WEAK_BODY_EYES`), and `getStylePairRisk(props)` returns the warning `getScanScore` shows.
|
|
149
141
|
|
|
150
|
-
|
|
151
|
-
- **M (Medium):** ~15% error correction
|
|
152
|
-
- **Q (Quartile):** ~25% error correction
|
|
153
|
-
- **H (High):** ~30% error correction
|
|
142
|
+
**Retired:** `curly` eyes and `diamond`, `star` and `banner` eye dots don't scan reliably, so they are no longer in these lists. They are deprecated, not removed: the types and zod schemas still accept them and the renderer still draws them, so saved designs keep working (`RETIRED_CORNER_EYE_PATTERNS`, `RETIRED_CORNER_EYE_DOT_PATTERNS`; `pickableCornerEyePatternSchema` and `pickableCornerEyeDotPatternSchema` accept only offered values).
|
|
154
143
|
|
|
155
|
-
|
|
144
|
+
| Option | Notes |
|
|
145
|
+
| --- | --- |
|
|
146
|
+
| `eyeColors` | Per-eye `{ outer, inner }` colors (or gradients) for `topLeft`, `topRight`, `bottomLeft`; each overrides `eyeColor` / `dotColor` |
|
|
147
|
+
| `moduleScale` | 0.5–1 (default 1): smaller modules for a spaced look; each pattern stops at the smallest size that still scans (`MODULE_SCALE_FLOOR`) |
|
|
148
|
+
| `autoLevel` | Raise `level` to H when a logo covers more than 7% of the code (off by default) |
|
|
149
|
+
| `shape` | `"square"` (default), `"circle"` or `"heart"`: the symbol sits in a disc or a heart filled with decorative modules, behind a light ring of `margin` modules (at least `QR_CIRCLE_QUIET_MIN`, 3). It also takes a `QRSilhouette` traced from a picture (`loadQRSilhouette` in the browser, `createQRSilhouette` from pixels); `getQRSilhouetteFit` refuses one too thin to hold the code, which then draws square. `getLayoutMargin` gives the margin it is drawn with; print sizes and logos follow it. `getQRAsSVG` draws it square |
|
|
150
|
+
| `frameLabelMarkers` | For editors: marks each frame label `<text>` with `data-qrdx-frame-label` (`"text"`, `"secondaryText"` or a spec label's id), so a preview can edit labels in place. Off by default; exports never include it |
|
|
151
|
+
| `imageSettings.padding` | Extra clear space around an excavated logo, in pixels |
|
|
152
|
+
| `bgColor="transparent"` | No background paint (transparent PNG/SVG, no fill in PDF/EPS) |
|
|
156
153
|
|
|
157
|
-
|
|
154
|
+
## Colors, gradients and image fills
|
|
158
155
|
|
|
159
|
-
|
|
156
|
+
Every color prop takes a `ColorConfig`: a CSS color string, `{ type: "solid", color }`, a linear, radial or angular gradient, or an image fill.
|
|
160
157
|
|
|
161
158
|
```tsx
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
159
|
+
<QRCodeSVG
|
|
160
|
+
value="https://example.com"
|
|
161
|
+
fgColor={{
|
|
162
|
+
type: "linear",
|
|
163
|
+
angle: 135, // 0 = left→right, 90 = top→bottom
|
|
164
|
+
stops: [
|
|
165
|
+
{ color: "#6366f1", offset: 0 },
|
|
166
|
+
{ color: "#ec4899", offset: 100 },
|
|
167
|
+
],
|
|
168
|
+
}}
|
|
169
|
+
bgColor={{
|
|
170
|
+
type: "radial",
|
|
171
|
+
stops: [
|
|
172
|
+
{ color: "#ffffff", offset: 0 },
|
|
173
|
+
{ color: "#f1f5f9", offset: 100 },
|
|
174
|
+
],
|
|
175
|
+
}}
|
|
176
|
+
/>
|
|
181
177
|
```
|
|
182
178
|
|
|
183
|
-
|
|
179
|
+
Gradients need at least 2 stops; `offset` is a percentage (0–100).
|
|
180
|
+
|
|
181
|
+
**Angular gradients.** `{ type: "angular", stops, angle }` sweeps the colors clockwise around the centre of what it fills (the code, or each eye), like CSS `conic-gradient(from <angle>deg, …)`. `angle` is where the sweep starts, in degrees clockwise from the top. SVG has no conic gradient, so it is drawn as a fan of thin wedges in a `<pattern>`; PDF and EPS paint the same wedges inside each shape.
|
|
184
182
|
|
|
185
|
-
|
|
183
|
+
**Alpha.** Colors and gradient stops keep alpha (`#1d4ed8cc`, `rgba(…)`). SVG writes it as `fill-opacity` and `stop-opacity`. PDF keeps it as a fill opacity, except that a gradient whose stops differ in alpha, or a see-through angular gradient, is mixed with the background. EPS has no transparency, so see-through colors are mixed with the background there. `getScanContrast(props)` judges see-through colors as they look.
|
|
186
184
|
|
|
187
|
-
|
|
185
|
+
**Image fills.** `{ type: "image", src, fit, scale, position, opacity, underlay }` paints a picture through the background, the dots or the eyes. It is laid over the whole code, so dots and eyes that share a picture show one picture. `fit` is `cover` (default), `contain` or `tile`; `scale` is 0.1–4; `position` is `center` or an edge or corner (`top-left`, `top`, …); `underlay` is a solid color under the picture that its `opacity` lets through. `src` is held like a logo: a PNG or JPEG data URL embeds everywhere, and servers never fetch a remote address.
|
|
188
186
|
|
|
189
187
|
```tsx
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
bgColor: "#ffffff",
|
|
197
|
-
});
|
|
188
|
+
<QRCodeSVG
|
|
189
|
+
value="https://example.com"
|
|
190
|
+
level="H"
|
|
191
|
+
fgColor={{ type: "image", src: photoDataUrl, opacity: 0.85, underlay: "#1f2937" }}
|
|
192
|
+
bgColor="#ffffff"
|
|
193
|
+
/>
|
|
198
194
|
```
|
|
199
195
|
|
|
200
|
-
|
|
196
|
+
SVG draws an image fill as a `<pattern>`, and PDF embeds the picture once. EPS refuses image fills: `getQRAsEPS` throws `EPS_IMAGE_FILL_REASON`, and `hasImageFill(props)` tells you beforehand. The contrast check judges a picture by its lightest and darkest tones and asks more of it (`SCAN_IMAGE_CONTRAST_MIN`), since its detail reads as noise.
|
|
197
|
+
|
|
198
|
+
## Templates
|
|
199
|
+
|
|
200
|
+
Built-in `templateId` values: `default`, `Arrow`, `StandardBox`, `SquareBorder`, `StrikedBox`, `Halloween` (case-sensitive). `getTemplateIds()`, `getAllTemplates()` and `getTemplate(id)` list them at runtime.
|
|
201
201
|
|
|
202
|
-
|
|
202
|
+
A custom template wraps the QR content (a 300×300 SVG) in your own SVG:
|
|
203
203
|
|
|
204
204
|
```tsx
|
|
205
|
-
import {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
},
|
|
222
|
-
"image/png",
|
|
223
|
-
true
|
|
224
|
-
);
|
|
205
|
+
import { QRCodeSVG, type TemplateDefinition } from "qrdx";
|
|
206
|
+
|
|
207
|
+
const Framed: TemplateDefinition<{ label?: string }> = {
|
|
208
|
+
id: "Framed",
|
|
209
|
+
name: "Framed",
|
|
210
|
+
wrapper: (children, props) => (
|
|
211
|
+
<svg viewBox="0 0 300 340" xmlns="http://www.w3.org/2000/svg">
|
|
212
|
+
<g transform="translate(20, 20) scale(0.87)">{children}</g>
|
|
213
|
+
<text x="150" y="325" textAnchor="middle" fill={props?.fgColor}>
|
|
214
|
+
{props?.label}
|
|
215
|
+
</text>
|
|
216
|
+
</svg>
|
|
217
|
+
),
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
<QRCodeSVG value="https://example.com" customTemplate={Framed} customProps={{ label: "Scan me" }} />;
|
|
225
221
|
```
|
|
226
222
|
|
|
227
|
-
|
|
223
|
+
## Frames (call to action)
|
|
228
224
|
|
|
229
|
-
|
|
225
|
+
`frame` draws a "Scan me" style frame around any code (`QRCode`, `QRCodeSVG`, `QRCodeCanvas`, `getQRAsSVG`, `getQRData` and the download helpers). The frame is added around the code, so the output grows; the modules and quiet zone are not touched.
|
|
230
226
|
|
|
231
227
|
```tsx
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
fgColor: "#000000",
|
|
237
|
-
bgColor: "#ffffff",
|
|
238
|
-
eyeColor: "#1a56db",
|
|
239
|
-
dotColor: "#3b82f6",
|
|
240
|
-
hideLogo: false,
|
|
241
|
-
logo: "https://example.com/logo.png",
|
|
242
|
-
margin: 4,
|
|
243
|
-
});
|
|
228
|
+
<QRCode
|
|
229
|
+
value="https://example.com/menu"
|
|
230
|
+
frame={{ style: "banner-bottom", text: "Scan for the menu", color: "#1e3a8a" }}
|
|
231
|
+
/>
|
|
244
232
|
```
|
|
245
233
|
|
|
246
|
-
|
|
234
|
+
| Option | Default | Notes |
|
|
235
|
+
| --- | --- | --- |
|
|
236
|
+
| `style` | — | One of `FRAME_STYLES`: <!-- catalogue:FRAME_STYLES -->`none`, `banner-bottom`, `banner-top`, `border`, `rounded-border`, `speech-bubble`, `banner-top-bottom`, `speech-bubble-top`, `chat-bubble`, `circle`, `polaroid`, `phone`, `ticket`, `badge`, `envelope`, `tag`, `menu-card`, `sticker`, `gradient-border`, `focus`<!-- /catalogue --> |
|
|
237
|
+
| `text` | `"Scan me"` | Up to 24 characters; `""` hides the label |
|
|
238
|
+
| `color` | `#000000` | Frame color (`gradient-border`: start color) |
|
|
239
|
+
| `textColor` | white on the frame, `color` on light areas | Label color |
|
|
240
|
+
| `secondaryText` | — | Second label (`banner-top-bottom`, `circle`, `menu-card`), up to 24 characters |
|
|
241
|
+
| `secondaryColor` | `#db2777` | End color of `gradient-border` |
|
|
242
|
+
| `fontScale` | `1` | Label size, 0.5–1.5 (labels still shrink to fit) |
|
|
243
|
+
|
|
244
|
+
Frames are plain shapes and text with opaque colors, so SVG, PNG, PDF and EPS match: the gradient border is drawn as fine solid color steps, and `circle` sets its letters as rotated text in every format.
|
|
245
|
+
|
|
246
|
+
The label uses a system font stack (nothing is fetched). `getFrameDimensions(size, frame)` returns the output size for a `size`-pixel code, and `frameSchema` (zod) validates frame options. To draw a frame of your own, see [Custom frames](#custom-frames).
|
|
247
247
|
|
|
248
|
-
|
|
248
|
+
## Custom frames
|
|
249
|
+
|
|
250
|
+
A custom frame is data: a JSON **frame spec** with shapes, labels, theme colors and the place the code goes. Pass it as `frame: { style: "custom", spec }`. The engine turns it into the same plain shapes the built-in frames use, so SVG, canvas (PNG/JPG), PDF and EPS draw the same artwork. A spec holds no markup, URLs, scripts or images, so specs from other people are safe to store and render.
|
|
249
251
|
|
|
250
252
|
```tsx
|
|
251
|
-
import {
|
|
253
|
+
import { QRCodeSVG, type FrameSpec } from "qrdx";
|
|
254
|
+
|
|
255
|
+
const spec: FrameSpec = {
|
|
256
|
+
kind: "qrdx.frame",
|
|
257
|
+
version: 1,
|
|
258
|
+
artboard: { width: 1240, height: 1460 },
|
|
259
|
+
qr: { x: 120, y: 120, size: 1000, padding: 80, radius: 24 }, // the code, its margin included
|
|
260
|
+
colors: { frame: "#111111", text: "#ffffff" }, // defaults the theme can override
|
|
261
|
+
shapes: [
|
|
262
|
+
{ type: "rect", x: 0, y: 0, width: 1240, height: 1460, radius: 64, fill: "frame" },
|
|
263
|
+
{ type: "icon", icon: "wifi", x: 80, y: 1260, size: 120, fill: "text" },
|
|
264
|
+
],
|
|
265
|
+
labels: [
|
|
266
|
+
{
|
|
267
|
+
type: "text", id: "cta", slot: "primary", text: "Scan to join Wi-Fi",
|
|
268
|
+
box: { x: 240, y: 1240, width: 920, height: 160 }, align: "start", color: "text",
|
|
269
|
+
},
|
|
270
|
+
],
|
|
271
|
+
};
|
|
252
272
|
|
|
253
|
-
|
|
254
|
-
// Returns: 21 (maximum contrast)
|
|
273
|
+
<QRCodeSVG value="WIFI:T:WPA;S:Guest;P:secret;;" frame={{ style: "custom", spec, color: "#1e3a8a" }} />;
|
|
255
274
|
```
|
|
256
275
|
|
|
257
|
-
|
|
276
|
+
**Units and layout.** Coordinates are in artboard units; the spec is scaled so `qr.size` becomes the code's size. The engine always paints an opaque plate of the code's background (white when the background is transparent) under the code and `qr.padding` around it, so nothing in the spec can show in the quiet zone. Labels may not overlap the code or its padding.
|
|
258
277
|
|
|
259
|
-
|
|
278
|
+
**Shapes** are painted behind the code, in order: `rect` (with `radius` and an optional `hole`), `circle` (with an optional `hole` radius, for rings), `ellipse`, `polygon`, `path` (SVG path data: `M L H V C S Q T A Z` and plain numbers only), `line` (a filled bar with `width`, `cap: "butt" | "round"` and an optional `dash: [dash, gap]`) and `icon` (a built-in glyph by id: <!-- catalogue:FRAME_ICONS -->`wifi`, `star`, `heart`, `phone`, `headphones`, `calendar`, `user`, `chat`, `bag`, `bell`, `cup`, `card`, `check`, `info`, `home`, `pin`, `share`, `download`, `clock`, `snowflake`, `pumpkin`, `tree`, `sparkle`, `gift`<!-- /catalogue -->).
|
|
260
279
|
|
|
261
|
-
|
|
262
|
-
import { getContrastLevel } from 'qrdx';
|
|
280
|
+
**Colors.** A fill is a theme token or a fixed `#rgb`/`#rrggbb` color. `frame` is the frame's `color` (else `colors.frame`), `text` is `textColor` (else `colors.text`, else the frame color), `accent` is `secondaryColor` (else `colors.accent`, else the frame color) and `background` is the code's background. `{ mix: [a, b], amount }` is an opaque tint, and `{ gradient: { from, to, direction, steps } }` draws a gradient as solid color steps, which EPS can print too. `bleed` names the color print bleed continues with when the artwork fills its edges.
|
|
263
281
|
|
|
264
|
-
|
|
265
|
-
// Returns: { level: 'medium', warning: false, message: '...' }
|
|
266
|
-
```
|
|
282
|
+
**Labels.** A `text` label is fitted in its `box` (`align` start, middle or end; `weight` bold or regular; `fontSize` defaults to 52% of the box height and never exceeds 95% of it). A `curved` label sets its letters along a circle (`curve: { cx, cy, radius, side: "top" | "bottom", spread }`). `slot: "primary"` shows the frame's `text`, `"secondary"` its `secondaryText` (each falls back to the label's own `text`, and `""` hides it), and `"fixed"` always shows `text`. `fontScale` scales every label. Text is cleaned with `sanitizeFrameText` (no control, invisible or direction-override characters, at most 24 characters). PDF and EPS print labels in Helvetica, so use Latin-1 text there (`isLatin1Text`).
|
|
267
283
|
|
|
268
|
-
|
|
284
|
+
**Validation.** `frameSpecSchema` (zod) checks every field and the hard limits in `FRAME_SPEC_LIMITS`: artboard sides of 50 to 2000 units, at most 3 decimals per number, 64 shapes, 8 labels, 256 points per polygon, 16,000 characters per path, 2,000 segments in all, 32 KB of JSON, a code at least half the artboard's shorter side and padding of at least 4% of the code. `getFrameSpecIssues(spec)` lists problems as text. Drawing an invalid spec throws a `FrameSpecError` instead of leaving the frame out.
|
|
269
285
|
|
|
270
|
-
|
|
286
|
+
**Official frames.** `OFFICIAL_FRAMES` holds 24 ready-made specs (20 use cases such as a Wi-Fi card, a table tent, a review card and an event ticket, and 4 seasonal ones), each with an `id`, `name`, `description`, suggested `contentTypes` and `tags`, released under CC0 1.0. `getOfficialFrame(id)` returns one. `BUILT_IN_FRAME_SPECS` has `banner-bottom`, `rounded-border`, `circle` and `ticket` written as specs, as starting points.
|
|
271
287
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
- `gradient-purple` — Purple gradient style
|
|
275
|
-
- `gradient-green` — Green gradient style
|
|
276
|
-
- `dots` — Rounded dot style
|
|
277
|
-
- `rounded` — Rounded corners style
|
|
278
|
-
- And many more...
|
|
288
|
+
```ts
|
|
289
|
+
import { getOfficialFrame } from "qrdx";
|
|
279
290
|
|
|
280
|
-
|
|
291
|
+
const wifi = getOfficialFrame("wifi-card"); // undefined for an unknown id
|
|
292
|
+
const frame = wifi && ({ style: "custom", spec: wifi.spec, secondaryText: "Harbour Guest" } as const);
|
|
293
|
+
```
|
|
281
294
|
|
|
282
|
-
|
|
295
|
+
### Importing an SVG (server)
|
|
283
296
|
|
|
284
|
-
|
|
297
|
+
`importFrameSvg(svg, options?)` converts SVG artwork into a spec, for a server to run on uploads. It never stores or returns the SVG: only filled shapes survive, rewritten as path data from the numbers it parsed, with colors as hex.
|
|
285
298
|
|
|
286
|
-
|
|
299
|
+
```ts
|
|
300
|
+
import { importFrameSvg } from "qrdx";
|
|
287
301
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
return <img src={qrDataUri} alt="QR Code" />;
|
|
302
|
+
const result = importFrameSvg(uploadedSvg);
|
|
303
|
+
if (result.ok) {
|
|
304
|
+
save(result.spec); // validated with frameSpecSchema
|
|
305
|
+
show(result.warnings); // what was dropped or changed, e.g. "Removed 2 images"
|
|
306
|
+
show(result.palette); // colors found, and which became the frame and accent tokens
|
|
307
|
+
} else {
|
|
308
|
+
reject(result.error);
|
|
298
309
|
}
|
|
299
310
|
```
|
|
300
311
|
|
|
301
|
-
|
|
312
|
+
- **Kept:** `svg`, `g`, `path`, `rect`, `circle`, `ellipse`, `polygon` and `polyline` fills (transforms applied), and strokes on `rect`, `circle`, `ellipse` and `line`, turned into filled outlines. Internal gradients become their first color. The two most used colors become the `frame` and `accent` tokens, so the frame follows the theme.
|
|
313
|
+
- **Removed, with a warning:** `script`, `style`, `foreignObject`, `image`, `use`, text, filters, masks, clip paths, patterns, animation and unknown elements; every attribute other than geometry and paint, so `on*` handlers and `href`/`xlink:href` go too; `url(...)` paints that point outside the file; strokes on paths and polylines (outline them first).
|
|
314
|
+
- **Refused:** files over 200 KB, any DOCTYPE or entity declaration, processing instructions other than the XML declaration, malformed markup (it is scanned in linear time before parsing), more than 500 elements, nesting deeper than 16 and more than 4,000 path segments (`FRAME_IMPORT_LIMITS`).
|
|
315
|
+
- **The code's place:** a `rect` with the id `qr` (or `qr-code`, `qrdx-qr`) marks it and isn't drawn; or pass `options.qr` in the SVG's units. Without either, the code is centered at 60% of the shorter side and a warning says so. Shapes are clipped to the artboard (the viewBox, scaled so its longer side is 1000 units).
|
|
316
|
+
|
|
317
|
+
## Art QR (Logo QR and Image QR)
|
|
318
|
+
|
|
319
|
+
`art` blends a logo or photo into the modules while keeping a real, scannable code: finder, timing and alignment patterns are always drawn solid. It is vector output with no AI, so it renders on the server and exports to SVG, PDF and EPS.
|
|
302
320
|
|
|
303
321
|
```tsx
|
|
304
|
-
import {
|
|
322
|
+
import { QRCodeSVG, loadQRArtImage } from "qrdx";
|
|
305
323
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
size: 2048,
|
|
311
|
-
fgColor: "#000000",
|
|
312
|
-
bgColor: "#ffffff",
|
|
313
|
-
},
|
|
314
|
-
"image/png"
|
|
315
|
-
);
|
|
316
|
-
|
|
317
|
-
const link = document.createElement('a');
|
|
318
|
-
link.download = 'qrcode.png';
|
|
319
|
-
link.href = dataUrl;
|
|
320
|
-
link.click();
|
|
321
|
-
}
|
|
324
|
+
// Browser: sample an uploaded file, a data URL or an <img>
|
|
325
|
+
const image = await loadQRArtImage(file, { mode: "logo" });
|
|
326
|
+
|
|
327
|
+
<QRCodeSVG value="https://example.com" size={512} level="H" art={{ mode: "logo", image, intensity: 0.7 }} />;
|
|
322
328
|
```
|
|
323
329
|
|
|
324
|
-
|
|
330
|
+
`mode` is `logo` (modules inside the logo take its colors) or `halftone` (every module shows the photo around a center that keeps the true value). `intensity` goes from `0` (plain) to `1` (default `0.6`).
|
|
331
|
+
|
|
332
|
+
`variant` picks a look within the mode (`QR_ART_VARIANTS`; the first is the default):
|
|
333
|
+
|
|
334
|
+
- `logo`: `blend` traces the logo into crisp vector shapes that fill the code under a fine dot screen; `badge` puts it on a rounded plate in the middle of a code tinted with its colors. Every module under the plate can spoil a codeword, so `intensity` grows the plate only as far as each error correction block can repair with room to spare. Small codes get a smaller logo, and the smallest (version 1, version 2 at L or M, version 3 at L) draw no plate and keep only the logo's colors.
|
|
335
|
+
- `halftone`: `color` shows the photo in full color; `mono` is an error-diffused black-and-white halftone.
|
|
336
|
+
|
|
337
|
+
In logo mode the finder eyes take the logo's colors unless you pass `matchEyes: false`; per-eye `eyeColors` still win. In Node, pass decoded RGBA pixels to `createQRArtImage` instead of `loadQRArtImage`: `decodePNGPixels(bytes)` reads an 8-bit PNG into them without a canvas or sharp. `art.image` is plain JSON, so you can store it with a design. Use level `H` and check the result with `getScanScore`, or, for rendered pixels in Node, with `scanQRPixels(pixels, value)`, which decodes them as they are and through the phone-camera model. See the [Art QR docs](https://qrdx.dev/docs/features/art-qr).
|
|
338
|
+
|
|
339
|
+
Art only renders dark dots on a light background: the background must be at least `QR_ART_MIN_LUMA_GAP` (0.35) lighter in luma than `fgColor` (gradients by their first stop). Otherwise the plain code is drawn so nothing gets worse. `getQRArtColorIssue(fgColor, bgColor)` returns `"inverted"`, `"low-contrast"` or `null`, so an editor can say why art isn't showing.
|
|
340
|
+
|
|
341
|
+
## Export and download (browser)
|
|
325
342
|
|
|
326
343
|
```tsx
|
|
327
|
-
import {
|
|
344
|
+
import {
|
|
345
|
+
copyQRCodeToClipboard,
|
|
346
|
+
downloadQRCode,
|
|
347
|
+
getQRAsWebP,
|
|
348
|
+
getQRCodeDataUrl,
|
|
349
|
+
getSVGString,
|
|
350
|
+
PRESET_SIZES,
|
|
351
|
+
} from "qrdx";
|
|
352
|
+
|
|
353
|
+
const props = { value: "https://example.com", bodyPattern: "rounded" as const };
|
|
354
|
+
|
|
355
|
+
await downloadQRCode(props, { format: "png", size: PRESET_SIZES.large }); // png | jpg | webp | svg | pdf | eps
|
|
356
|
+
await downloadQRCode(props, { format: "webp", size: PRESET_SIZES.large }); // lossless WebP
|
|
357
|
+
const webp = await getQRAsWebP({ ...props, size: 1024 }); // a Blob; { quality: 0.9 } makes it lossy
|
|
358
|
+
await downloadQRCode(props, { format: "pdf", size: { width: 1200, height: 1200 }, filename: "qr.pdf" });
|
|
359
|
+
const dataUrl = await getQRCodeDataUrl(props, "svg", { width: 512, height: 512 });
|
|
360
|
+
await copyQRCodeToClipboard(props, { width: 512, height: 512 }); // PNG to the clipboard
|
|
361
|
+
const svgMarkup = await getSVGString(props);
|
|
362
|
+
```
|
|
328
363
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
364
|
+
Sizes must be square and between 50 and 5000 pixels (`validateSize`); with a frame the file is larger by the frame. For `eps`, `size.width` is in PostScript points (72 per inch). When `props.size` is set, a logo laid out for that size is scaled with the export (`withQRSize`). PDF export loads `jspdf` on demand and throws a clear error if it is not installed; EPS needs no extra package.
|
|
365
|
+
|
|
366
|
+
WebP is lossless by default, so module edges stay exact, and a transparent background stays transparent. `quality` (0 to 1, in `downloadQRCode` options or `getQRAsWebP`) asks for a smaller lossy file instead. The browser's canvas encodes it where it can; where it can't (Safari hands back a PNG for `image/webp`), QRdx encodes the pixels itself with a small built-in lossless encoder, so a `.webp` file is always WebP. `canvasToWebP(canvas)` does the same for any canvas, and `encodeWebPLossless(rgba, width, height)` encodes raw RGBA pixels without a DOM. Lower-level helpers: `getQRAsSVGDataUri(props)` and `getQRAsCanvas(props, mimeType, returnCanvas?)`.
|
|
367
|
+
|
|
368
|
+
Vector output writes coordinates with at most 3 decimals (0.001 px in SVG, 0.001 pt in PDF and EPS; scale factors keep 6), so edges move by at most 0.0005 px and SVG markup is roughly 30% smaller than with full-precision numbers.
|
|
369
|
+
|
|
370
|
+
### Print-ready files
|
|
371
|
+
|
|
372
|
+
`downloadPrintPDF` writes a vector PDF at an exact physical size: modules, eyes and frames are vector paths (a logo stays a raster image), with optional bleed and crop marks. `getQRAsPrintPDF` / `getQRAsPrintPDFBuffer` return the PDF instead of downloading it (they also run in Node).
|
|
373
|
+
|
|
374
|
+
```ts
|
|
375
|
+
import { downloadPrintPDF, downloadPrintSVG, getPrintLayout } from "qrdx";
|
|
376
|
+
|
|
377
|
+
const props = { value: "https://example.com", frame: { style: "banner-bottom" } } as const;
|
|
378
|
+
|
|
379
|
+
// 40 mm wide code, 3 mm bleed, crop marks, CMYK colors
|
|
380
|
+
await downloadPrintPDF(props, { size: 40, unit: "mm", bleed: 3, cropMarks: true, colorMode: "cmyk" });
|
|
381
|
+
await downloadPrintSVG(props, { size: 1.5, unit: "in" }); // SVG with width="…in"
|
|
382
|
+
|
|
383
|
+
getPrintLayout(props, { size: 40 }).maxScanDistance; // 400 (mm): a code scans from ~10× its width
|
|
341
384
|
```
|
|
342
385
|
|
|
343
|
-
|
|
386
|
+
Vector EPS for print shops and design tools (Illustrator, InDesign, CorelDRAW) works the same way, in the browser or in Node:
|
|
344
387
|
|
|
345
|
-
|
|
388
|
+
```ts
|
|
389
|
+
import { downloadPrintEPS, getQRAsEPS, svgToEPS } from "qrdx";
|
|
346
390
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
391
|
+
const eps = await getQRAsEPS(props, { sizeMm: 40, bleedMm: 3, colorMode: "cmyk" }); // EPSF-3.0 string
|
|
392
|
+
await downloadPrintEPS(props, { sizeMm: 40, filename: "qr.eps" });
|
|
393
|
+
const fromSvg = await svgToEPS(svgMarkup, { width: 144 }); // any SVG this library renders, 144 pt wide
|
|
394
|
+
```
|
|
351
395
|
|
|
352
|
-
|
|
396
|
+
EPS has no transparency or crop marks, and PNG and JPEG logos are embedded as images. Linear and radial gradients stay smooth: the PDF paints them as native shadings and the EPS with `shfill` (the file then declares PostScript LanguageLevel 3), clipped to each module, eye and eye centre, in the same color mode as the solid colors.
|
|
353
397
|
|
|
354
|
-
-
|
|
355
|
-
-
|
|
356
|
-
-
|
|
357
|
-
-
|
|
398
|
+
- `size` is the width of the code itself; a frame adds to the page.
|
|
399
|
+
- `colorMode: "cmyk"` uses a naive conversion (`rgbToCmyk`: K = 1 − max(R, G, B), no ICC profile). Ask your printer for a color-managed conversion when exact brand colors matter.
|
|
400
|
+
- Gradients stay gradients in the PDF (native shadings). In CMYK mode the blend runs between the converted stop colors. Frame text uses Helvetica Bold, so characters outside Latin-1 may not render in the PDF.
|
|
401
|
+
- Rule of thumb for size: width ≈ scan distance ÷ 10 (2 cm wide at 20 cm).
|
|
358
402
|
|
|
359
|
-
|
|
403
|
+
## Will it scan? (browser)
|
|
360
404
|
|
|
361
|
-
-
|
|
362
|
-
- Use `H` level for QR codes that might get damaged
|
|
363
|
-
- Use `L` level for simple, clean environments
|
|
405
|
+
`getScanScore(props)` estimates how reliably a design scans. It renders the code at 96, 160 and 320 px, simulates camera blur and contrast loss, decodes each with jsQR, and combines that with contrast (per-eye colors included), polarity, logo coverage vs. error correction, a logo moved over a corner eye or the bottom-right alignment pattern, quiet zone and eye-shape risk (`circle` eyes only read in lenient decoders; retired `curly` eyes in saved designs fail strict ones). Known-weak style pairs come from `getStylePairRisk`; a `circle` centre inside square-cornered eyes is flagged as `sharp-dot-eye` (missed by jsQR in sharp renders) without lowering the score.
|
|
364
406
|
|
|
365
|
-
|
|
407
|
+
```ts
|
|
408
|
+
import { getScanScore, getImageScanScore } from "qrdx";
|
|
366
409
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
410
|
+
const { score, grade, checks } = await getScanScore({ value: "https://example.com", bodyPattern: "circle" });
|
|
411
|
+
// score 0–100, grade "great" | "ok" | "risky" | "fails",
|
|
412
|
+
// checks [{ id, passed, message, fix? }]
|
|
370
413
|
|
|
371
|
-
|
|
414
|
+
// Score an existing image (File/Blob or <img>): decoded content plus what can be measured from pixels
|
|
415
|
+
const report = await getImageScanScore(file); // { data, version, score, grade, checks }
|
|
416
|
+
```
|
|
372
417
|
|
|
373
|
-
|
|
418
|
+
It is a heuristic built on one open-source decoder: phone camera apps vary, so treat it as a guide and test-scan important prints.
|
|
374
419
|
|
|
375
|
-
|
|
376
|
-
import type { QRProps, QRPropsCanvas, ImageSettings } from 'qrdx';
|
|
420
|
+
## Scanning (browser)
|
|
377
421
|
|
|
378
|
-
|
|
379
|
-
src: "https://example.com/logo.png",
|
|
380
|
-
height: 256,
|
|
381
|
-
width: 256,
|
|
382
|
-
excavate: true,
|
|
383
|
-
};
|
|
422
|
+
`handleImageLoad` decodes a QR code from an `<img>` using [jsQR](https://github.com/cozmo/jsQR), trying several crops and scales. jsQR is loaded on first use.
|
|
384
423
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
424
|
+
```ts
|
|
425
|
+
import { handleImageLoad } from "qrdx";
|
|
426
|
+
|
|
427
|
+
const text = await handleImageLoad(imgElement, 400); // decoded string, or "NO_QR"
|
|
428
|
+
const full = await handleImageLoad(imgElement, 400, true); // full jsQR result (data, location, …)
|
|
390
429
|
```
|
|
391
430
|
|
|
392
|
-
|
|
431
|
+
`downloadImageWithBoundingBox(img, [topLeft, topRight, bottomLeft, bottomRight], filename)` saves a debug copy of the image with the detected corners outlined.
|
|
393
432
|
|
|
394
|
-
|
|
395
|
-
- Chrome 90+
|
|
396
|
-
- Firefox 88+
|
|
397
|
-
- Safari 14+
|
|
398
|
-
- Edge 90+
|
|
433
|
+
## Utilities
|
|
399
434
|
|
|
400
|
-
|
|
435
|
+
```ts
|
|
436
|
+
import { getContrastLevel, getContrastRatio, getQRData } from "qrdx";
|
|
401
437
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
- Minimal re-renders with React hooks
|
|
405
|
-
- Supports high-DPI displays automatically
|
|
438
|
+
getContrastRatio("#000000", "#ffffff"); // 21 (accepts #rgb, #rrggbb, #rrggbbaa)
|
|
439
|
+
getContrastLevel(4.5); // { level: "AA", warning: false, message: "Good contrast" }
|
|
406
440
|
|
|
407
|
-
|
|
441
|
+
// Normalised props, including the logo imageSettings used by <QRCode>
|
|
442
|
+
const data = getQRData({ value: "https://example.com", logo: "https://example.com/logo.png" });
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
`getContrastLevel` returns `AAA` (≥ 7), `AA` (≥ 4.5), `AA Large` (≥ 3, with a warning) or `Fail`.
|
|
446
|
+
|
|
447
|
+
### Server-safe types and schemas
|
|
448
|
+
|
|
449
|
+
`qrdx/types` exports the TypeScript types, the [zod](https://zod.dev) schemas (`qrPropsSchema`, `colorConfigSchema`, …), the pattern lists and the color helpers without any React code:
|
|
408
450
|
|
|
409
|
-
|
|
451
|
+
```ts
|
|
452
|
+
import { colorConfigSchema, normalizeColorConfig, type ColorConfig } from "qrdx/types";
|
|
410
453
|
|
|
411
|
-
|
|
454
|
+
const parsed = colorConfigSchema.parse(JSON.parse(userInput));
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
## Error correction
|
|
458
|
+
|
|
459
|
+
| Level | Recovers |
|
|
460
|
+
|-------|----------|
|
|
461
|
+
| `L` | ~7% |
|
|
462
|
+
| `M` | ~15% |
|
|
463
|
+
| `Q` | ~25% (default) |
|
|
464
|
+
| `H` | ~30% |
|
|
465
|
+
|
|
466
|
+
Higher levels survive more damage (and larger logos) but produce denser codes.
|
|
467
|
+
|
|
468
|
+
## License
|
|
412
469
|
|
|
413
|
-
|
|
470
|
+
[MIT](./LICENSE) © Ritesh Bucha and QRdx contributors. Versions before 0.0.47 were published under AGPL-3.0-or-later.
|
|
414
471
|
|
|
472
|
+
Includes code from [qrcode.react](https://github.com/zpao/qrcode.react) (ISC, © Paul O'Shannessy) and the [QR Code generator library](https://www.nayuki.io/page/qr-code-generator-library) (MIT, © Project Nayuki).
|