quadqr-js 1.0.2 → 1.2.0

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.
@@ -28,20 +28,30 @@ If no version is supplied, QuadQR automatically chooses the smallest version tha
28
28
  ```js
29
29
  import {
30
30
  encodeText,
31
- renderToCanvas
31
+ renderToCanvas,
32
+ renderToSVG
32
33
  } from "quadqr-js/browser";
33
34
 
34
35
  const code = encodeText("Rendered in the browser");
35
36
 
36
37
  renderToCanvas(code, document.querySelector("#qr"), {
37
- moduleSize: 12,
38
+ imageSize: 720,
38
39
  quietZone: 4,
39
40
  style: "classic"
40
41
  });
42
+
43
+ const svg = renderToSVG(code, {
44
+ imageSize: 720,
45
+ quietZone: 4
46
+ });
41
47
  ```
42
48
 
43
49
  Available presentation styles are `classic`, `depth`, `soft`, and `inset`. Styling does not change the encoded matrix.
44
50
 
51
+ `imageSize` is the exact square output dimension in pixels. If you omit both `imageSize` and `moduleSize`, the renderer defaults to 720 × 720 px. `moduleSize` is still available for low-level pixels-per-module sizing.
52
+
53
+ To add a centered logo, load it as an `Image` and pass it as `logo.source`. Transparent logo pixels remain transparent. Use `clearBackground: true` when you want a padded white area behind the logo. `quietZone` is measured in modules and defaults to `4`.
54
+
45
55
  ## Scan an uploaded image
46
56
 
47
57
  ```js
@@ -125,16 +135,21 @@ const code = await encodeSecureText("Application-managed secret", {
125
135
 
126
136
  The key must be exactly 32 bytes. Never embed the secret key inside the same QuadQR payload.
127
137
 
128
- ## Generate and scan PNG files in Node.js
138
+ ## Generate PNG and SVG files in Node.js
129
139
 
130
140
  ```js
131
141
  import { encodeText } from "quadqr-js";
132
- import { savePNG, scanFile } from "quadqr-js/node";
142
+ import { savePNG, saveSVG, scanFile } from "quadqr-js/node";
133
143
 
134
144
  const code = encodeText("Generated on Node.js");
135
145
 
136
146
  await savePNG(code, "quadqr.png", {
137
- moduleSize: 12,
147
+ imageSize: 720,
148
+ quietZone: 4
149
+ });
150
+
151
+ await saveSVG(code, "quadqr.svg", {
152
+ imageSize: 720,
138
153
  quietZone: 4
139
154
  });
140
155
 
@@ -142,13 +157,13 @@ const result = await scanFile("quadqr.png");
142
157
  console.log(result.text);
143
158
  ```
144
159
 
145
- PNG generation and decoding are built into the Node.js adapter.
160
+ PNG generation/decoding and SVG generation are built into the Node.js adapter.
146
161
 
147
162
  ## Use a script tag
148
163
 
149
164
  ```html
150
165
  <canvas id="qr"></canvas>
151
- <script src="https://cdn.jsdelivr.net/npm/quadqr-js@1.0.1/dist/quadqr.min.js"></script>
166
+ <script src="https://cdn.jsdelivr.net/npm/quadqr-js@1.1.0/dist/quadqr.min.js"></script>
152
167
  <script>
153
168
  const code = QuadQR.encodeText("No build step");
154
169
  QuadQR.renderToCanvas(code, document.querySelector("#qr"));
@@ -172,3 +187,61 @@ npx quadqr-js decode secure.png --password "my-password"
172
187
  ```
173
188
 
174
189
  See [CLI.md](./CLI.md) for the full command reference.
190
+
191
+ ## Compression and signed payloads
192
+
193
+ Compression is available directly on the normal encode APIs. You do not need to select a payload type or use a separate payload mode:
194
+
195
+ ```js
196
+ import { encodeText } from "quadqr-js";
197
+
198
+ const code = encodeText("repeat repeat repeat repeat", {
199
+ compression: "auto",
200
+ ecc: "Q"
201
+ });
202
+ ```
203
+
204
+ `auto` keeps the original payload untouched when compression would not save space.
205
+
206
+ For offline integrity verification:
207
+
208
+ ```js
209
+ import { generateSigningKeyPair, encodeSignedText, decodeMatrix, verifyDecodedSignature } from "quadqr-js";
210
+
211
+ const keys = await generateSigningKeyPair();
212
+ const signed = await encodeSignedText("ticket data", {
213
+ compression: "auto",
214
+ privateKey: keys.privateKey,
215
+ keyId: keys.keyId
216
+ });
217
+
218
+ const result = await verifyDecodedSignature(decodeMatrix(signed.matrix), {
219
+ publicKey: keys.publicKey
220
+ });
221
+ console.log(result.signatureVerified, result.signatureTrusted);
222
+ ```
223
+
224
+ Signing metadata is internal. The private key signs; the trusted public key verifies and remains outside the QuadQR by default. The optional `keyId` lets applications select the correct trusted public key without embedding it in every symbol.
225
+
226
+ ## Print mode
227
+
228
+ ```js
229
+ renderToCanvas(code, canvas, {
230
+ imageSize: 1200,
231
+ mode: "print",
232
+ quietZone: 4
233
+ });
234
+ ```
235
+
236
+ Print mode uses safer defaults but should still be tested with the actual printer, paper, physical size, and target phones.
237
+
238
+ ## Scanability testing
239
+
240
+ ```js
241
+ import { assessScanability } from "quadqr-js";
242
+
243
+ const report = assessScanability(code, { imageSize: 480 });
244
+ console.log(report.score, report.rating);
245
+ ```
246
+
247
+ The browser demo includes an interactive stress lab for testing one distortion at a time or running the full suite.
package/docs/NODE.md CHANGED
@@ -1,123 +1,137 @@
1
- # Node.js
2
-
3
- QuadQR uses the same matrix codec and scanner core in Node.js and the browser. The `quadqr-js/node` entry adds Node-specific PNG, file, and buffer helpers.
4
-
5
- ## Requirements
6
-
7
- Node.js 20.19 or newer.
8
-
9
- ## ESM
10
-
11
- ```js
12
- import { encodeText } from "quadqr-js";
13
- import { savePNG, scanFile } from "quadqr-js/node";
14
- ```
15
-
16
- ## CommonJS
17
-
18
- ```js
19
- const QuadQR = require("quadqr-js");
20
- const QuadQRNode = require("quadqr-js/node");
21
- ```
22
-
23
- ## Generate a PNG
24
-
25
- ```js
26
- const code = QuadQR.encodeText("Server generated");
27
-
28
- await QuadQRNode.savePNG(code, "output.png", {
29
- moduleSize: 12,
30
- quietZone: 4
31
- });
32
- ```
33
-
34
- Use `toPNG()` when you need an in-memory `Buffer`:
35
-
36
- ```js
37
- const png = QuadQRNode.toPNG(code);
38
- ```
39
-
40
- This works well for HTTP responses, object storage, attachments, and other buffer-based workflows.
41
-
42
- ## Scan a PNG file
43
-
44
- ```js
45
- const result = await QuadQRNode.scanFile("output.png");
46
- console.log(result.text);
47
- ```
48
-
49
- Or scan a buffer:
50
-
51
- ```js
52
- const result = await QuadQRNode.scanBuffer(pngBuffer);
53
- ```
54
-
55
- PNG generation and decoding do not require external native dependencies.
56
-
57
- ## Other image formats
58
-
59
- For JPEG, WebP, or AVIF input, the Node adapter can use `sharp` when the consuming application has it installed:
60
-
61
- ```bash
62
- npm install sharp
63
- ```
64
-
65
- If `sharp` is not installed, decode the image to RGBA in your own image pipeline and pass the pixels to `scanImageData()`.
66
-
67
- ## Secure password workflow
68
-
69
- ```js
70
- import {
71
- decryptDecoded,
72
- encodeSecureText
73
- } from "quadqr-js";
74
- import {
75
- savePNG,
76
- scanFile
77
- } from "quadqr-js/node";
78
-
79
- const code = await encodeSecureText("private", {
80
- security: {
81
- mode: "password",
82
- password: process.env.QUADQR_PASSWORD
83
- }
84
- });
85
-
86
- await savePNG(code, "secure.png");
87
-
88
- const locked = await scanFile("secure.png");
89
-
90
- const unlocked = await decryptDecoded(locked, {
91
- password: process.env.QUADQR_PASSWORD
92
- });
93
-
94
- console.log(unlocked.text);
95
- ```
96
-
97
- ## Secure raw-key workflow
98
-
99
- ```js
100
- import {
101
- decryptDecoded,
102
- encodeSecureText,
103
- generateRaw256Key
104
- } from "quadqr-js";
105
- import { toPNG, scanBuffer } from "quadqr-js/node";
106
-
107
- const key = generateRaw256Key();
108
-
109
- const code = await encodeSecureText("machine secret", {
110
- security: {
111
- mode: "raw-key",
112
- key
113
- }
114
- });
115
-
116
- const png = toPNG(code);
117
- const locked = await scanBuffer(png);
118
- const unlocked = await decryptDecoded(locked, { key });
119
-
120
- console.log(unlocked.text);
121
- ```
122
-
123
- Keep long-lived application keys in an appropriate secret-management or platform key-storage system.
1
+ # Node.js
2
+
3
+ QuadQR uses the same matrix codec and scanner core in Node.js and the browser. The `quadqr-js/node` entry adds Node-specific PNG, file, and buffer helpers.
4
+
5
+ ## Requirements
6
+
7
+ Node.js 20.19 or newer.
8
+
9
+ ## ESM
10
+
11
+ ```js
12
+ import { encodeText } from "quadqr-js";
13
+ import { savePNG, saveSVG, scanFile } from "quadqr-js/node";
14
+ ```
15
+
16
+ ## CommonJS
17
+
18
+ ```js
19
+ const QuadQR = require("quadqr-js");
20
+ const QuadQRNode = require("quadqr-js/node");
21
+ ```
22
+
23
+ ## Generate a PNG
24
+
25
+ ```js
26
+ const code = QuadQR.encodeText("Server generated");
27
+
28
+ await QuadQRNode.savePNG(code, "output.png", {
29
+ imageSize: 720,
30
+ quietZone: 4
31
+ });
32
+ ```
33
+
34
+ ## Generate an SVG
35
+
36
+ ```js
37
+ await QuadQRNode.saveSVG(code, "output.svg", {
38
+ imageSize: 720,
39
+ quietZone: 4,
40
+ style: "classic"
41
+ });
42
+ ```
43
+
44
+ `imageSize` is the exact PNG/SVG output dimension in pixels. If you omit both `imageSize` and `moduleSize`, rendering defaults to 720 × 720 px. `moduleSize` remains available for legacy pixels-per-module sizing.
45
+
46
+ Use `toSVG()` when you need the SVG string in memory. SVG logo sources can be URL/data URL strings. For PNG generation with a logo through `renderToImageData()`, pass decoded ImageData-like RGBA pixels as the logo source.
47
+
48
+ Use `toPNG()` when you need an in-memory `Buffer`:
49
+
50
+ ```js
51
+ const png = QuadQRNode.toPNG(code);
52
+ ```
53
+
54
+ This works well for HTTP responses, object storage, attachments, and other buffer-based workflows.
55
+
56
+ ## Scan a PNG file
57
+
58
+ ```js
59
+ const result = await QuadQRNode.scanFile("output.png");
60
+ console.log(result.text);
61
+ ```
62
+
63
+ Or scan a buffer:
64
+
65
+ ```js
66
+ const result = await QuadQRNode.scanBuffer(pngBuffer);
67
+ ```
68
+
69
+ PNG generation and decoding do not require external native dependencies.
70
+
71
+ ## Other image formats
72
+
73
+ For JPEG, WebP, or AVIF input, the Node adapter can use `sharp` when the consuming application has it installed:
74
+
75
+ ```bash
76
+ npm install sharp
77
+ ```
78
+
79
+ If `sharp` is not installed, decode the image to RGBA in your own image pipeline and pass the pixels to `scanImageData()`.
80
+
81
+ ## Secure password workflow
82
+
83
+ ```js
84
+ import {
85
+ decryptDecoded,
86
+ encodeSecureText
87
+ } from "quadqr-js";
88
+ import {
89
+ savePNG,
90
+ scanFile
91
+ } from "quadqr-js/node";
92
+
93
+ const code = await encodeSecureText("private", {
94
+ security: {
95
+ mode: "password",
96
+ password: process.env.QUADQR_PASSWORD
97
+ }
98
+ });
99
+
100
+ await savePNG(code, "secure.png");
101
+
102
+ const locked = await scanFile("secure.png");
103
+
104
+ const unlocked = await decryptDecoded(locked, {
105
+ password: process.env.QUADQR_PASSWORD
106
+ });
107
+
108
+ console.log(unlocked.text);
109
+ ```
110
+
111
+ ## Secure raw-key workflow
112
+
113
+ ```js
114
+ import {
115
+ decryptDecoded,
116
+ encodeSecureText,
117
+ generateRaw256Key
118
+ } from "quadqr-js";
119
+ import { toPNG, scanBuffer } from "quadqr-js/node";
120
+
121
+ const key = generateRaw256Key();
122
+
123
+ const code = await encodeSecureText("machine secret", {
124
+ security: {
125
+ mode: "raw-key",
126
+ key
127
+ }
128
+ });
129
+
130
+ const png = toPNG(code);
131
+ const locked = await scanBuffer(png);
132
+ const unlocked = await decryptDecoded(locked, { key });
133
+
134
+ console.log(unlocked.text);
135
+ ```
136
+
137
+ Keep long-lived application keys in an appropriate secret-management or platform key-storage system.
package/docs/README.md CHANGED
@@ -1,41 +1,59 @@
1
- # QuadQR Documentation
2
-
3
- QuadQR is an experimental four-state RGBW matrix symbology. Each data cell carries exactly two bits using red, green, blue, or white. The JavaScript library supports encoding, rendering, matrix decoding, image and camera scanning, Spectrum ECC, optional authenticated encryption, Node.js PNG workflows, CDN usage, a CLI, TypeScript declarations, and optional prebuilt WebAssembly acceleration.
4
-
5
- ## Live links
6
-
7
- - [Documentation Site](https://akanshsirohi.github.io/QuadQR/docs-site/)
8
- - [Interactive Demo](https://akanshsirohi.github.io/QuadQR/demo/)
9
- - [quadqr-js on npm](https://www.npmjs.com/package/quadqr-js)
10
- - [GitHub Repository](https://github.com/akanshsirohi/QuadQR)
11
-
12
- ## Documentation
13
-
14
- - [Getting Started](./GETTING_STARTED.md)
15
- - [API Reference](./API.md)
16
- - [Browser and CDN](./BROWSER_CDN.md)
17
- - [Node.js](./NODE.md)
18
- - [CLI](./CLI.md)
19
- - [Secure Payloads](./SECURITY.md)
20
- - [WebAssembly](./WASM.md)
21
- - [Wire Format](../FORMAT.md)
22
-
23
- ## Package entry points
24
-
25
- | Entry | Purpose |
26
- | --- | --- |
27
- | `quadqr-js` | Runtime-neutral core API, rendering, scanning, secure payloads, utilities, and optional WASM |
28
- | `quadqr-js/browser` | Browser ESM entry for canvas, files, video, and camera workflows |
29
- | `quadqr-js/node` | Node.js core plus PNG, file, and buffer helpers |
30
- | `quadqr-js/benchmark` | Capacity and codec benchmark helpers |
31
- | `quadqr-js/quadqr.min.js` | Classic browser global bundle for CDN/script-tag usage |
32
-
33
- The matrix codec is shared across runtimes. Browser and Node.js adapters only handle environment-specific input and output.
34
-
35
- ## Compatibility note
36
-
37
- QuadQR is a custom experimental format, not ISO QR Code. Standard QR scanner applications cannot decode QuadQR symbols.
38
-
39
- ## License
40
-
41
- QuadQR is licensed under AGPL-3.0. See [`LICENSE`](../LICENSE).
1
+ # QuadQR Documentation
2
+
3
+ QuadQR is an experimental four-state RGBW matrix symbology. Each data cell carries exactly two bits using red, green, blue, or white. The JavaScript library supports encoding, canvas/RGBA/SVG rendering, adjustable quiet zones, optional centered logos with transparent or cleared backgrounds, matrix decoding, image and camera scanning, Spectrum ECC, optional authenticated encryption, Node.js PNG/SVG workflows, CDN usage, a CLI, TypeScript declarations, and optional prebuilt WebAssembly acceleration.
4
+
5
+ ## Live links
6
+
7
+ - [Documentation Site](https://akanshsirohi.github.io/QuadQR/docs-site/)
8
+ - [Interactive Demo](https://akanshsirohi.github.io/QuadQR/demo/)
9
+ - [quadqr-js on npm](https://www.npmjs.com/package/quadqr-js)
10
+ - [GitHub Repository](https://github.com/akanshsirohi/QuadQR)
11
+
12
+ ## Documentation
13
+
14
+ - [Getting Started](./GETTING_STARTED.md)
15
+ - [API Reference](./API.md)
16
+ - [Browser and CDN](./BROWSER_CDN.md)
17
+ - [Node.js](./NODE.md)
18
+ - [CLI](./CLI.md)
19
+ - [Secure Payloads](./SECURITY.md)
20
+ - [WebAssembly](./WASM.md)
21
+ - [Wire Format](../FORMAT.md)
22
+ - [Technical Specification](../SPECIFICATION.md)
23
+
24
+ ## Package entry points
25
+
26
+ | Entry | Purpose |
27
+ | --- | --- |
28
+ | `quadqr-js` | Runtime-neutral core API, rendering, scanning, secure payloads, utilities, and optional WASM |
29
+ | `quadqr-js/browser` | Browser ESM entry for canvas, files, video, and camera workflows |
30
+ | `quadqr-js/node` | Node.js core plus PNG/SVG, file, and buffer helpers |
31
+ | `quadqr-js/benchmark` | Capacity and codec benchmark helpers |
32
+ | `quadqr-js/quadqr.min.js` | Classic browser global bundle for CDN/script-tag usage |
33
+
34
+ The matrix codec is shared across runtimes. Browser and Node.js adapters only handle environment-specific input and output.
35
+
36
+ ## Compatibility note
37
+
38
+ QuadQR is a custom experimental format, not ISO QR Code. Standard QR scanner applications cannot decode QuadQR symbols.
39
+
40
+ ## License
41
+
42
+ QuadQR is licensed under AGPL-3.0. See [`LICENSE`](../LICENSE).
43
+
44
+ ## Advanced reliability and payload features
45
+
46
+ The current library also includes:
47
+
48
+ - normal text/byte payloads with optional internal LZ compression;
49
+ - portable automatic LZ compression;
50
+ - first-class binary `Uint8Array` APIs;
51
+ - Ed25519 signed QuadQR payloads and trusted-key verification;
52
+ - signed + AES-256-GCM encrypted composition;
53
+ - screen and print rendering modes;
54
+ - ECC-aware automatic logo sizing;
55
+ - normalized scanner confidence and detailed debug mode;
56
+ - deterministic scanability/torture testing;
57
+ - an interactive browser stress-test lab and capacity calculator.
58
+
59
+ See [`../SPECIFICATION.md`](../SPECIFICATION.md) for the layering and interoperability rules and [`API.md`](./API.md) for the public APIs.
package/docs/WASM.md CHANGED
@@ -17,7 +17,7 @@ const state = await initWasm();
17
17
  console.log(state);
18
18
  ```
19
19
 
20
- In QuadQR 0.7.x, the WASM module accelerates CRC-32. Once initialized, normal encode/decode operations automatically use the installed accelerator.
20
+ In QuadQR 1.x, the WASM module accelerates CRC-32. Once initialized, normal encode/decode operations automatically use the installed accelerator.
21
21
 
22
22
  ## Check the current state
23
23
 
@@ -56,7 +56,7 @@ You can also provide WASM bytes directly through the `bytes` option.
56
56
  When the classic `quadqr.min.js` global build is loaded from a CDN, `QuadQR.initWasm()` resolves the bundled sibling WASM asset from the same package/version location.
57
57
 
58
58
  ```html
59
- <script src="https://cdn.jsdelivr.net/npm/quadqr-js@1.0.1/dist/quadqr.min.js"></script>
59
+ <script src="https://cdn.jsdelivr.net/npm/quadqr-js@1.1.0/dist/quadqr.min.js"></script>
60
60
  <script>
61
61
  await QuadQR.initWasm();
62
62
  </script>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "quadqr-js",
3
- "version": "1.0.2",
4
- "description": "QuadQR: experimental four-state RGBW matrix code with Spectrum ECC, browser/Node scanning, CDN builds, and optional AES-256-GCM secure payloads.",
3
+ "version": "1.2.0",
4
+ "description": "QuadQR: experimental four-state RGBW matrix code with Spectrum ECC, compression, Ed25519 signing, browser/Node scanning, diagnostics, stress testing, and optional AES-256-GCM security.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
@@ -44,6 +44,7 @@
44
44
  "bin",
45
45
  "docs",
46
46
  "FORMAT.md",
47
+ "SPECIFICATION.md",
47
48
  "README.md",
48
49
  "LICENSE"
49
50
  ],
@@ -89,7 +90,11 @@
89
90
  "camera-scanner",
90
91
  "encryption",
91
92
  "aes-gcm",
92
- "wasm"
93
+ "wasm",
94
+ "compression",
95
+ "ed25519",
96
+ "scan-diagnostics",
97
+ "print-qr"
93
98
  ],
94
99
  "sideEffects": false
95
100
  }
@@ -1,7 +1,8 @@
1
1
  import type { EccLevel } from "./index.js";
2
2
  export const STANDARD_QR_BYTE_CAPACITY: Readonly<Record<EccLevel, readonly number[]>>;
3
3
  export function getStandardQrByteCapacity(version: number, ecc?: EccLevel): number;
4
- export function compareCapacity(version: number, ecc?: EccLevel): Record<string, number | string>;
5
- export function buildCapacityComparison(options?: { ecc?: EccLevel; versions?: number[] }): Array<Record<string, number | string>>;
4
+ export function compareCapacity(version: number, ecc?: EccLevel): Record<string, number | string | null>;
5
+ export function calculateCapacityPlan(options?: { payload?: string | Uint8Array; payloadBytes?: number; ecc?: EccLevel; compression?: "none" | "auto" | "lz"; signed?: boolean; keyId?: string; embedPublicKey?: boolean }): Record<string, unknown>;
6
+ export function buildCapacityComparison(options?: { ecc?: EccLevel; versions?: number[] }): Array<Record<string, number | string | null>>;
6
7
  export function benchmarkCodec(options?: Record<string, unknown>): Record<string, unknown>;
7
- export function benchmarkReport(options?: Record<string, unknown>): string;
8
+ export function benchmarkReport(options?: Record<string, unknown>): Record<string, unknown>;