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.
Files changed (212) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +358 -300
  3. package/dist/index.js +27 -7
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +27 -7
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/qr-code-canvas.js +12 -0
  8. package/dist/qr-code-canvas.js.map +1 -0
  9. package/dist/qr-code-canvas.mjs +12 -0
  10. package/dist/qr-code-canvas.mjs.map +1 -0
  11. package/dist/src/api.d.ts.map +1 -1
  12. package/dist/src/art-trace.d.ts +46 -0
  13. package/dist/src/art-trace.d.ts.map +1 -0
  14. package/dist/src/art.d.ts +138 -0
  15. package/dist/src/art.d.ts.map +1 -0
  16. package/dist/src/body-patterns.d.ts +34 -0
  17. package/dist/src/body-patterns.d.ts.map +1 -0
  18. package/dist/src/codegen.d.ts +5 -5
  19. package/dist/src/codegen.d.ts.map +1 -1
  20. package/dist/src/codeword-map.d.ts +40 -0
  21. package/dist/src/codeword-map.d.ts.map +1 -0
  22. package/dist/src/constants.d.ts +4 -7
  23. package/dist/src/constants.d.ts.map +1 -1
  24. package/dist/src/corner-dot.d.ts +3 -1
  25. package/dist/src/corner-dot.d.ts.map +1 -1
  26. package/dist/src/corner-eye.d.ts +5 -2
  27. package/dist/src/corner-eye.d.ts.map +1 -1
  28. package/dist/src/detection.d.ts.map +1 -1
  29. package/dist/src/download.d.ts +50 -6
  30. package/dist/src/download.d.ts.map +1 -1
  31. package/dist/src/eps.d.ts +62 -0
  32. package/dist/src/eps.d.ts.map +1 -0
  33. package/dist/src/frame-icons.d.ts +11 -0
  34. package/dist/src/frame-icons.d.ts.map +1 -0
  35. package/dist/src/frame-import.d.ts +61 -0
  36. package/dist/src/frame-import.d.ts.map +1 -0
  37. package/dist/src/frame-spec.d.ts +24 -0
  38. package/dist/src/frame-spec.d.ts.map +1 -0
  39. package/dist/src/frame-styles.d.ts +50 -0
  40. package/dist/src/frame-styles.d.ts.map +1 -0
  41. package/dist/src/frame.d.ts +126 -0
  42. package/dist/src/frame.d.ts.map +1 -0
  43. package/dist/src/frames/builtin.d.ts +8 -0
  44. package/dist/src/frames/builtin.d.ts.map +1 -0
  45. package/dist/src/frames/official.d.ts +18 -0
  46. package/dist/src/frames/official.d.ts.map +1 -0
  47. package/dist/src/helpers.d.ts +15 -2
  48. package/dist/src/helpers.d.ts.map +1 -1
  49. package/dist/src/index.d.ts +25 -13
  50. package/dist/src/index.d.ts.map +1 -1
  51. package/dist/src/logo-budget.d.ts +54 -0
  52. package/dist/src/logo-budget.d.ts.map +1 -0
  53. package/dist/src/logo-cleanup.d.ts +25 -0
  54. package/dist/src/logo-cleanup.d.ts.map +1 -0
  55. package/dist/src/logo.d.ts +28 -0
  56. package/dist/src/logo.d.ts.map +1 -0
  57. package/dist/src/print.d.ts +73 -0
  58. package/dist/src/print.d.ts.map +1 -0
  59. package/dist/src/qr-code-canvas.d.ts +13 -0
  60. package/dist/src/qr-code-canvas.d.ts.map +1 -0
  61. package/dist/src/qr-code.d.ts +4 -2
  62. package/dist/src/qr-code.d.ts.map +1 -1
  63. package/dist/src/qr-outline.d.ts +41 -0
  64. package/dist/src/qr-outline.d.ts.map +1 -0
  65. package/dist/src/qr-shape.d.ts +72 -0
  66. package/dist/src/qr-shape.d.ts.map +1 -0
  67. package/dist/src/scan-risk.d.ts +40 -0
  68. package/dist/src/scan-risk.d.ts.map +1 -0
  69. package/dist/src/scan-score.d.ts +154 -0
  70. package/dist/src/scan-score.d.ts.map +1 -0
  71. package/dist/src/shapes.d.ts +36 -0
  72. package/dist/src/shapes.d.ts.map +1 -0
  73. package/dist/src/silhouette.d.ts +28 -0
  74. package/dist/src/silhouette.d.ts.map +1 -0
  75. package/dist/src/utils/color.d.ts.map +1 -1
  76. package/dist/src/utils/fmt.d.ts +24 -0
  77. package/dist/src/utils/fmt.d.ts.map +1 -0
  78. package/dist/src/utils/paint.d.ts +80 -0
  79. package/dist/src/utils/paint.d.ts.map +1 -0
  80. package/dist/src/utils/parse-color.d.ts +21 -0
  81. package/dist/src/utils/parse-color.d.ts.map +1 -0
  82. package/dist/src/utils/path-data.d.ts +24 -0
  83. package/dist/src/utils/path-data.d.ts.map +1 -0
  84. package/dist/src/utils/png.d.ts +16 -0
  85. package/dist/src/utils/png.d.ts.map +1 -0
  86. package/dist/src/utils/polygon-clip.d.ts +26 -0
  87. package/dist/src/utils/polygon-clip.d.ts.map +1 -0
  88. package/dist/src/utils/print-shared.d.ts +20 -0
  89. package/dist/src/utils/print-shared.d.ts.map +1 -0
  90. package/dist/src/utils/svg-geometry.d.ts +49 -0
  91. package/dist/src/utils/svg-geometry.d.ts.map +1 -0
  92. package/dist/src/utils/svg-gradient.d.ts +59 -0
  93. package/dist/src/utils/svg-gradient.d.ts.map +1 -0
  94. package/dist/src/utils/svg-painter.d.ts +152 -0
  95. package/dist/src/utils/svg-painter.d.ts.map +1 -0
  96. package/dist/src/utils/webp.d.ts +25 -0
  97. package/dist/src/utils/webp.d.ts.map +1 -0
  98. package/dist/src/utils.d.ts +18 -2
  99. package/dist/src/utils.d.ts.map +1 -1
  100. package/dist/src/webp.d.ts +19 -0
  101. package/dist/src/webp.d.ts.map +1 -0
  102. package/dist/types/art.d.ts +64 -0
  103. package/dist/types/art.d.ts.map +1 -0
  104. package/dist/types/color.d.ts +125 -7
  105. package/dist/types/color.d.ts.map +1 -1
  106. package/dist/types/corner-dot.d.ts +52 -2
  107. package/dist/types/corner-dot.d.ts.map +1 -1
  108. package/dist/types/corner-eye.d.ts +43 -2
  109. package/dist/types/corner-eye.d.ts.map +1 -1
  110. package/dist/types/frame-spec.d.ts +3509 -0
  111. package/dist/types/frame-spec.d.ts.map +1 -0
  112. package/dist/types/frame.d.ts +68 -0
  113. package/dist/types/frame.d.ts.map +1 -0
  114. package/dist/types/image-pattern.d.ts +15 -1
  115. package/dist/types/image-pattern.d.ts.map +1 -1
  116. package/dist/types/index.d.ts +15 -9
  117. package/dist/types/index.d.ts.map +1 -1
  118. package/dist/types/index.js +6 -0
  119. package/dist/types/index.js.map +1 -0
  120. package/dist/types/index.mjs +6 -0
  121. package/dist/types/index.mjs.map +1 -0
  122. package/dist/types/qr.d.ts +1684 -4
  123. package/dist/types/qr.d.ts.map +1 -1
  124. package/dist/types/template.d.ts +2 -2
  125. package/dist/types/template.d.ts.map +1 -1
  126. package/package.json +70 -25
  127. package/src/api.tsx +67 -17
  128. package/src/art-trace.ts +554 -0
  129. package/src/art.tsx +2226 -0
  130. package/src/body-patterns.tsx +389 -0
  131. package/src/codegen.ts +10 -5
  132. package/src/codeword-map.ts +265 -0
  133. package/src/constants.ts +4 -8
  134. package/src/corner-dot.tsx +209 -33
  135. package/src/corner-eye.ts +328 -60
  136. package/src/detection.ts +5 -11
  137. package/src/download.tsx +174 -70
  138. package/src/eps.ts +701 -0
  139. package/src/frame-icons.ts +325 -0
  140. package/src/frame-import.ts +1198 -0
  141. package/src/frame-spec.ts +518 -0
  142. package/src/frame-styles.ts +1095 -0
  143. package/src/frame.tsx +630 -0
  144. package/src/frames/builtin/banner-bottom.json +58 -0
  145. package/src/frames/builtin/circle.json +81 -0
  146. package/src/frames/builtin/rounded-border.json +60 -0
  147. package/src/frames/builtin/ticket.json +51 -0
  148. package/src/frames/builtin.ts +20 -0
  149. package/src/frames/official/attendance.json +110 -0
  150. package/src/frames/official/audio-guide.json +95 -0
  151. package/src/frames/official/book-now.json +103 -0
  152. package/src/frames/official/check-in.json +110 -0
  153. package/src/frames/official/christmas.json +131 -0
  154. package/src/frames/official/donate.json +77 -0
  155. package/src/frames/official/event-ticket.json +77 -0
  156. package/src/frames/official/feedback-bubble.json +73 -0
  157. package/src/frames/official/follow-us.json +83 -0
  158. package/src/frames/official/get-the-app.json +107 -0
  159. package/src/frames/official/halloween.json +80 -0
  160. package/src/frames/official/new-year.json +94 -0
  161. package/src/frames/official/order-at-table.json +86 -0
  162. package/src/frames/official/product-info.json +119 -0
  163. package/src/frames/official/register-product.json +77 -0
  164. package/src/frames/official/review-us.json +127 -0
  165. package/src/frames/official/rsvp-card.json +112 -0
  166. package/src/frames/official/save-contact.json +117 -0
  167. package/src/frames/official/scan-to-pay.json +94 -0
  168. package/src/frames/official/shop-window.json +81 -0
  169. package/src/frames/official/sign-rider.json +81 -0
  170. package/src/frames/official/table-tent.json +75 -0
  171. package/src/frames/official/wifi-card.json +89 -0
  172. package/src/frames/official/winter.json +142 -0
  173. package/src/frames/official.ts +77 -0
  174. package/src/helpers.ts +168 -11
  175. package/src/index.tsx +150 -172
  176. package/src/logo-budget.ts +226 -0
  177. package/src/logo-cleanup.ts +146 -0
  178. package/src/logo.tsx +137 -0
  179. package/src/print.ts +794 -0
  180. package/src/qr-code-canvas.tsx +241 -0
  181. package/src/qr-code.tsx +51 -16
  182. package/src/qr-outline.ts +511 -0
  183. package/src/qr-shape.ts +255 -0
  184. package/src/scan-risk.ts +197 -0
  185. package/src/scan-score.ts +1629 -0
  186. package/src/shapes.ts +169 -0
  187. package/src/silhouette.ts +334 -0
  188. package/src/utils/color.ts +10 -1
  189. package/src/utils/fmt.ts +59 -0
  190. package/src/utils/paint.ts +317 -0
  191. package/src/utils/parse-color.ts +135 -0
  192. package/src/utils/path-data.ts +182 -0
  193. package/src/utils/png.ts +175 -0
  194. package/src/utils/polygon-clip.ts +163 -0
  195. package/src/utils/print-shared.ts +74 -0
  196. package/src/utils/svg-geometry.ts +838 -0
  197. package/src/utils/svg-gradient.ts +407 -0
  198. package/src/utils/svg-painter.ts +946 -0
  199. package/src/utils/webp.ts +556 -0
  200. package/src/utils.tsx +794 -385
  201. package/src/webp.ts +84 -0
  202. package/types/art.ts +74 -0
  203. package/types/color.ts +132 -12
  204. package/types/corner-dot.ts +41 -4
  205. package/types/corner-eye.ts +31 -4
  206. package/types/frame-spec.ts +748 -0
  207. package/types/frame.ts +67 -0
  208. package/types/image-pattern.ts +15 -0
  209. package/types/index.ts +106 -4
  210. package/types/qr.ts +180 -2
  211. package/types/template.ts +2 -2
  212. package/dist/cli.js +0 -4319
package/README.md CHANGED
@@ -1,414 +1,472 @@
1
1
  # qrdx
2
2
 
3
- A powerful, flexible React component library for generating customizable QR codes.
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
- ## Features
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
- - 🎨 **Highly Customizable** — Control colors for QR code, background, eyes, and dots
8
- - 🖼️ **Logo Support** — Embed custom logos or images with automatic excavation
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
- # Using pnpm (recommended in monorepo)
20
- pnpm add qrdx@latest
13
+ npm install qrdx
14
+ # or: pnpm add qrdx / yarn add qrdx
15
+ ```
21
16
 
22
- # Using npm
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
- # Using yarn
26
- yarn add qrdx@latest
19
+ ```bash
20
+ npm install jspdf
27
21
  ```
28
22
 
29
- ## Basic Usage
30
-
31
- ### Simple QR Code
23
+ ## Quick start
32
24
 
33
25
  ```tsx
34
- import { QRCode } from 'qrdx';
35
-
36
- export default function App() {
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
- ### With Custom Colors
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
- ```tsx
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
- ### With Logo
37
+ ### `QRCodeSVG`
38
+
39
+ The core renderer. Every styling option is supported here.
66
40
 
67
41
  ```tsx
68
- import { QRCode } from 'qrdx';
69
-
70
- export default function App() {
71
- return (
72
- <QRCode
73
- url="https://example.com"
74
- hideLogo={false}
75
- logo="https://example.com/logo.png"
76
- size={1024}
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
- ### With Template
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 'qrdx';
86
-
87
- export default function App() {
88
- return (
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
- ### With Custom Dot Patterns
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
- Choose from 7 different dot patterns:
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
- import { QRCode } from 'qrdx';
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
- Available patterns:
117
- - `circle` — Classic circular dots (default)
118
- - `square` — Modern square dots
119
- - `diamond` — Diamond-shaped rotated squares
120
- - `circle-mixed` — Circles with varying sizes
121
- - `pacman` — Pill-shaped rounded rectangles
122
- - `rounded` — Clean squares with smoothly rounded corners
123
- - `clean-square` — Clean rectangles only
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
- ## API Reference
130
+ ## Patterns
126
131
 
127
- ### QRCode Component
132
+ See every option drawn live at [qrdx.dev/docs/styles](https://qrdx.dev/docs/styles).
128
133
 
129
- The main component for rendering QR codes.
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
- #### Props
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
- | Prop | Type | Default | Description |
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
- #### Error Correction Levels
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
- - **L (Low):** ~7% error correction
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
- Higher levels provide better resilience to damage but result in denser QR codes.
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
- ### QRCodeCanvas Component
154
+ ## Colors, gradients and image fills
158
155
 
159
- Direct access to the canvas-based renderer.
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
- import { QRCodeCanvas } from 'qrdx';
163
-
164
- export default function App() {
165
- return (
166
- <QRCodeCanvas
167
- value="https://example.com"
168
- size={512}
169
- bgColor="#ffffff"
170
- fgColor="#000000"
171
- level="Q"
172
- imageSettings={{
173
- src: "https://example.com/logo.png",
174
- height: 128,
175
- width: 128,
176
- excavate: true,
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
- ### Utility Functions
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
- #### getQRAsSVGDataUri
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
- Generate QR code as SVG data URI.
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
- import { getQRAsSVGDataUri } from 'qrdx';
191
-
192
- const dataUri = await getQRAsSVGDataUri({
193
- value: "https://example.com",
194
- size: 512,
195
- fgColor: "#000000",
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
- #### getQRAsCanvas
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
- Generate QR code as canvas or data URL.
202
+ A custom template wraps the QR content (a 300×300 SVG) in your own SVG:
203
203
 
204
204
  ```tsx
205
- import { getQRAsCanvas } from 'qrdx';
206
-
207
- // Get as data URL
208
- const dataUrl = await getQRAsCanvas(
209
- {
210
- value: "https://example.com",
211
- size: 1024,
212
- },
213
- "image/png"
214
- );
215
-
216
- // Get as canvas element
217
- const canvas = await getQRAsCanvas(
218
- {
219
- value: "https://example.com",
220
- size: 1024,
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
- #### getQRData
223
+ ## Frames (call to action)
228
224
 
229
- Helper function to prepare QR code data with sensible defaults.
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
- import { getQRData } from 'qrdx';
233
-
234
- const qrData = getQRData({
235
- url: "https://example.com",
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
- #### getContrastRatio
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
- Calculate WCAG contrast ratio between two colors.
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 { getContrastRatio } from 'qrdx';
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
- const ratio = getContrastRatio("#000000", "#ffffff");
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
- #### getContrastLevel
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
- Get contrast level assessment for QR code scanability.
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
- ```tsx
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
- const level = getContrastLevel(4.5);
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
- ## Templates
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
- The library includes several pre-designed templates:
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
- - `default` — Classic black and white
273
- - `gradient-blue` — Blue gradient style
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
- Templates are automatically applied based on the `templateId` prop.
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
- ## Advanced Usage
295
+ ### Importing an SVG (server)
283
296
 
284
- ### Server-Side Rendering
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
- The QR code generation works in both client and server environments:
299
+ ```ts
300
+ import { importFrameSvg } from "qrdx";
287
301
 
288
- ```tsx
289
- import { getQRAsSVGDataUri } from 'qrdx';
290
-
291
- export default async function ServerComponent() {
292
- const qrDataUri = await getQRAsSVGDataUri({
293
- value: "https://example.com",
294
- size: 512,
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
- ### Downloading QR Codes
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 { getQRAsCanvas } from 'qrdx';
322
+ import { QRCodeSVG, loadQRArtImage } from "qrdx";
305
323
 
306
- async function downloadQR() {
307
- const dataUrl = await getQRAsCanvas(
308
- {
309
- value: "https://example.com",
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
- ### Custom Image Settings
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 { QRCodeCanvas } from 'qrdx';
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
- <QRCodeCanvas
330
- value="https://example.com"
331
- size={1024}
332
- imageSettings={{
333
- src: "https://example.com/logo.png",
334
- height: 256, // Logo height in QR modules
335
- width: 256, // Logo width in QR modules
336
- excavate: true, // Remove QR modules under the logo
337
- x: 384, // Optional: x position
338
- y: 384, // Optional: y position
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
- ## Best Practices
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
- ### Contrast Requirements
388
+ ```ts
389
+ import { downloadPrintEPS, getQRAsEPS, svgToEPS } from "qrdx";
346
390
 
347
- For optimal scanability:
348
- - Maintain a contrast ratio of **at least 3:1** (minimum)
349
- - Aim for **4.5:1 or higher** for best results
350
- - Use the built-in `getContrastRatio` utility to validate
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
- ### Size Recommendations
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
- - **Minimum size:** 128px for basic QR codes
355
- - **Recommended:** 512px for general use
356
- - **High quality:** 1024px or larger for print
357
- - **With logo:** Use larger sizes (1024px+) to maintain scanability
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
- ### Error Correction
403
+ ## Will it scan? (browser)
360
404
 
361
- - Use `Q` level when embedding logos
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
- ### Logo Size
407
+ ```ts
408
+ import { getScanScore, getImageScanScore } from "qrdx";
366
409
 
367
- - Keep logo size between 10-30% of QR code area
368
- - Enable `excavate: true` to maintain scanability
369
- - Test scanning with your target devices
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
- ## TypeScript Support
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
- Full TypeScript support with comprehensive type definitions:
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
- ```tsx
376
- import type { QRProps, QRPropsCanvas, ImageSettings } from 'qrdx';
420
+ ## Scanning (browser)
377
421
 
378
- const imageSettings: ImageSettings = {
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
- const qrProps: QRProps = {
386
- value: "https://example.com",
387
- size: 512,
388
- imageSettings,
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
- ## Browser Support
431
+ `downloadImageWithBoundingBox(img, [topLeft, topRight, bottomLeft, bottomRight], filename)` saves a debug copy of the image with the detected corners outlined.
393
432
 
394
- - Modern browsers with Canvas and SVG support
395
- - Chrome 90+
396
- - Firefox 88+
397
- - Safari 14+
398
- - Edge 90+
433
+ ## Utilities
399
434
 
400
- ## Performance
435
+ ```ts
436
+ import { getContrastLevel, getContrastRatio, getQRData } from "qrdx";
401
437
 
402
- - Optimized Path2D rendering when available
403
- - Efficient module excavation for logo placement
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
- ## License
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
- ISC License - Based on [qrcode.react](https://github.com/zpao/qrcode.react) by Paul O'Shannessy
451
+ ```ts
452
+ import { colorConfigSchema, normalizeColorConfig, type ColorConfig } from "qrdx/types";
410
453
 
411
- ## Credits
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
- - QR code generation algorithm: [qrcode.react](https://github.com/zpao/qrcode.react)
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).