@particle-academy/react-fancy 5.36.1 → 5.37.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.
- package/CHANGELOG.md +63 -0
- package/dist/{chunk-M5V4NLCQ.cjs → chunk-AE53RKWR.cjs} +2 -2
- package/dist/{chunk-M5V4NLCQ.cjs.map → chunk-AE53RKWR.cjs.map} +1 -1
- package/dist/{chunk-IMYJIPNK.js → chunk-RLE5WYY6.js} +2 -2
- package/dist/{chunk-IMYJIPNK.js.map → chunk-RLE5WYY6.js.map} +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.js +1 -1
- package/dist/qr-code.cjs +4 -4
- package/dist/qr-code.d.cts +38 -16
- package/dist/qr-code.d.ts +38 -16
- package/dist/qr-code.js +1 -1
- package/docs/QrCode.md +68 -29
- package/package.json +1 -1
package/dist/qr-code.js
CHANGED
package/docs/QrCode.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
A QR code rendered as an SVG, with **no dependencies** — the encoder is part of
|
|
4
4
|
the component.
|
|
5
5
|
|
|
6
|
-
ISO/IEC 18004, versions 1–40, error correction L/M/Q/H,
|
|
7
|
-
alphanumeric
|
|
6
|
+
ISO/IEC 18004, versions 1–40, error correction L/M/Q/H, and numeric /
|
|
7
|
+
alphanumeric / byte modes selected automatically.
|
|
8
8
|
|
|
9
9
|
## Import
|
|
10
10
|
|
|
@@ -15,19 +15,46 @@ import { QrCode } from "@particle-academy/react-fancy";
|
|
|
15
15
|
## Basic Usage
|
|
16
16
|
|
|
17
17
|
```tsx
|
|
18
|
-
<QrCode
|
|
19
|
-
value="https://alphar.tail1234.ts.net:7421/pair#482913"
|
|
20
|
-
size={192}
|
|
21
|
-
label="Pair this device"
|
|
22
|
-
/>
|
|
18
|
+
<QrCode value="SN-4829-13" size={192} label="Asset tag for pump 14" />
|
|
23
19
|
```
|
|
24
20
|
|
|
21
|
+
## `value` is any string — this is not a link component
|
|
22
|
+
|
|
23
|
+
A QR code is a byte container. Most of what belongs in one is **not** a web
|
|
24
|
+
address, and those are the cases where the format earns its place, because they
|
|
25
|
+
need no network at all — the scanner reads the value and that *is* the payload.
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
// An identifier, read off a label in a warehouse with no signal.
|
|
29
|
+
<QrCode value="SN-4829-13" label="Asset tag for pump 14" />
|
|
30
|
+
|
|
31
|
+
// Digits only — numeric mode, a third the size of the same value as text.
|
|
32
|
+
<QrCode value="482913" label="Order reference" />
|
|
33
|
+
|
|
34
|
+
// WiFi credentials. Phone cameras offer "Join network" directly.
|
|
35
|
+
// Escape \ ; , : in the SSID and password with a backslash.
|
|
36
|
+
<QrCode value="WIFI:T:WPA;S:Guest;P:hunter2;;" label="Join the guest WiFi" />
|
|
37
|
+
|
|
38
|
+
// A contact, as MeCard — shorter than vCard and widely recognised.
|
|
39
|
+
<QrCode value="MECARD:N:Okafor,Ada;TEL:+15550100;EMAIL:ada@example.com;;" label="Ada Okafor's contact card" />
|
|
40
|
+
|
|
41
|
+
// Other URI schemes are just strings too.
|
|
42
|
+
<QrCode value="tel:+15550100" label="Call the service desk" />
|
|
43
|
+
<QrCode value="geo:51.5033,-0.1196" label="Meet at the south entrance" />
|
|
44
|
+
|
|
45
|
+
// A link is ONE payload among many, not the default.
|
|
46
|
+
<QrCode value="https://example.com/menu" label="Today's menu" />
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Nothing in the component inspects or validates `value`. It encodes the bytes
|
|
50
|
+
you give it, which is why it carries any of the above without a per-format API.
|
|
51
|
+
|
|
25
52
|
## Props
|
|
26
53
|
|
|
27
54
|
| Prop | Type | Default | Description |
|
|
28
55
|
|------|------|---------|-------------|
|
|
29
|
-
| value | `string` | — |
|
|
30
|
-
| label | `string` | — | **Required.** Accessible name. Describe the
|
|
56
|
+
| value | `string` | — | Any string. An empty string renders a valid empty symbol rather than throwing. |
|
|
57
|
+
| label | `string` | — | **Required.** Accessible name. Describe what the code is *for*, not the artefact. |
|
|
31
58
|
| size | `number` | `192` | Rendered width and height in pixels. |
|
|
32
59
|
| errorCorrection | `"L" \| "M" \| "Q" \| "H"` | `"M"` | Damage tolerance. See the note below — higher is not automatically better. |
|
|
33
60
|
| quietZone | `number` | `4` | Modules of clear margin. The standard's minimum is 4. |
|
|
@@ -40,6 +67,23 @@ Every other SVG attribute passes through. `viewBox` and SVG's own `version` are
|
|
|
40
67
|
not accepted — the component owns the first, and the second collides with the QR
|
|
41
68
|
symbol version.
|
|
42
69
|
|
|
70
|
+
## Mode selection is why a short value is a big symbol
|
|
71
|
+
|
|
72
|
+
Automatic, and worth understanding because it decides how scannable the result
|
|
73
|
+
is at a given pixel size:
|
|
74
|
+
|
|
75
|
+
| Value | Mode | Bits per character | Version at `M` |
|
|
76
|
+
|---|---|---|---|
|
|
77
|
+
| `482913` | numeric | 3⅓ | 1 (21 modules) |
|
|
78
|
+
| `SN-4829-13` | alphanumeric | 5½ | 1 (21 modules) |
|
|
79
|
+
| `sn-4829-13` | byte | 8 | 1 (21 modules) |
|
|
80
|
+
| a 47-character URL | byte | 8 | 4 (33 modules) |
|
|
81
|
+
|
|
82
|
+
Uppercase matters: alphanumeric mode covers `0-9 A-Z` and `$%*+-./: ` only, so
|
|
83
|
+
**lower-casing an identifier pushes it into byte mode** and makes the symbol
|
|
84
|
+
bigger for the same information. If you control the format of a code you are
|
|
85
|
+
printing, uppercase it.
|
|
86
|
+
|
|
43
87
|
## Three ways a perfect-looking code fails to scan
|
|
44
88
|
|
|
45
89
|
None of these are visible in a screenshot review, which is why they are here
|
|
@@ -57,40 +101,30 @@ most scanners refuse it. Contrast is what gets scanned, not the dark modules on
|
|
|
57
101
|
their own:
|
|
58
102
|
|
|
59
103
|
```tsx
|
|
60
|
-
<QrCode value={
|
|
104
|
+
<QrCode value={serial} label="Asset tag" foreground="#0b0b0c" background="#ffffff" />
|
|
61
105
|
```
|
|
62
106
|
|
|
63
107
|
**3. Reaching for `"H"` because it sounds safer.** `"H"` survives about 30%
|
|
64
108
|
damage against `"M"`'s 15%, but it holds a third less — so the same value needs
|
|
65
109
|
a larger symbol, and at the same pixel width that means *smaller modules*. On a
|
|
66
110
|
phone screen `"H"` can read worse than `"M"`. Raise it for print, for a label
|
|
67
|
-
that will be scuffed, or when a logo covers part of the symbol.
|
|
111
|
+
that will be scuffed or oiled, or when a logo covers part of the symbol.
|
|
68
112
|
|
|
69
113
|
## It is an image of a value, not the value
|
|
70
114
|
|
|
71
115
|
A QR code is unusable to anyone who cannot point a second device at the screen —
|
|
72
116
|
every screen-reader user, and anyone whose phone is the device displaying it. So
|
|
73
|
-
`label` is required, **and the value should also be
|
|
74
|
-
|
|
75
|
-
|
|
117
|
+
`label` is required, **and the value should also be selectable text** beside it.
|
|
118
|
+
An `aria-label` cannot carry a serial number or a WiFi password someone is
|
|
119
|
+
expected to read off.
|
|
76
120
|
|
|
77
121
|
```tsx
|
|
78
122
|
<div className="flex flex-col items-center gap-3">
|
|
79
|
-
<QrCode value={
|
|
80
|
-
<code className="text-sm">{
|
|
123
|
+
<QrCode value={serial} label="Asset tag for pump 14" background="#ffffff" />
|
|
124
|
+
<code className="select-all text-sm">{serial}</code>
|
|
81
125
|
</div>
|
|
82
126
|
```
|
|
83
127
|
|
|
84
|
-
## A PIN is denser than a URL
|
|
85
|
-
|
|
86
|
-
Mode selection is automatic and it matters. Numeric mode packs three digits into
|
|
87
|
-
ten bits where byte mode spends twenty-four, so a six-digit PIN is a version 1
|
|
88
|
-
symbol — the largest modules and the easiest read:
|
|
89
|
-
|
|
90
|
-
```tsx
|
|
91
|
-
<QrCode value="482913" label="Pairing PIN" /> {/* 21 modules + quiet zone */}
|
|
92
|
-
```
|
|
93
|
-
|
|
94
128
|
## Why SVG, and one path
|
|
95
129
|
|
|
96
130
|
The symbol is one `<path>` of unit squares on a module-unit `viewBox`, not a
|
|
@@ -102,20 +136,22 @@ The module-unit viewBox is what makes `size` free: the symbol is resolution
|
|
|
102
136
|
independent, so it stays crisp at any size and prints at the printer's
|
|
103
137
|
resolution. That is not only cosmetic — a raster code scaled to a non-integer
|
|
104
138
|
multiple of its module size has blurred module edges, and a scanner reading a
|
|
105
|
-
blurred edge guesses.
|
|
139
|
+
blurred edge guesses. For a printed asset label this is the difference between
|
|
140
|
+
a code that reads first time and one a warehouse worker swears at.
|
|
106
141
|
|
|
107
142
|
## The encoder on its own
|
|
108
143
|
|
|
109
144
|
Exported alongside the component, for a consumer that needs modules rather than
|
|
110
|
-
an SVG — a canvas, a PDF, a thermal printer, a terminal:
|
|
145
|
+
an SVG — a canvas, a PDF, a thermal label printer, a terminal:
|
|
111
146
|
|
|
112
147
|
```tsx
|
|
113
148
|
import { encodeQr, selectMode } from "@particle-academy/react-fancy";
|
|
114
149
|
|
|
115
|
-
const symbol = encodeQr("
|
|
150
|
+
const symbol = encodeQr("SN-4829-13", { errorCorrection: "Q" });
|
|
116
151
|
symbol.modules; // boolean[][], true is dark
|
|
117
152
|
symbol.size; // version * 4 + 17
|
|
118
153
|
symbol.version; // 1-40
|
|
154
|
+
symbol.mode; // the mode chosen
|
|
119
155
|
symbol.mask; // the mask chosen by penalty scoring
|
|
120
156
|
selectMode("482913"); // "numeric"
|
|
121
157
|
```
|
|
@@ -125,6 +161,9 @@ fit. That is deliberate: a truncated symbol scans cleanly and yields the wrong
|
|
|
125
161
|
string, which is silent corruption on a surface whose entire job is to carry a
|
|
126
162
|
value accurately.
|
|
127
163
|
|
|
164
|
+
Capacity at the largest symbol (version 40, level `L`): **7,089** digits,
|
|
165
|
+
**4,296** alphanumeric characters, or **2,953** bytes.
|
|
166
|
+
|
|
128
167
|
## Not supported
|
|
129
168
|
|
|
130
169
|
Kanji mode and structured append. Neither has a caller here, and an untested
|