qr 0.5.3 → 0.5.5
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/README.md +28 -27
- package/decode.d.ts +16 -2
- package/decode.d.ts.map +1 -1
- package/decode.js +462 -70
- package/decode.js.map +1 -1
- package/dom.d.ts +1 -0
- package/dom.d.ts.map +1 -1
- package/dom.js +15 -0
- package/dom.js.map +1 -1
- package/index.d.ts +28 -5
- package/index.d.ts.map +1 -1
- package/index.js +445 -228
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/src/decode.ts +427 -72
- package/src/dom.ts +14 -0
- package/src/index.ts +431 -256
package/README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# paulmillr-qr
|
|
2
2
|
|
|
3
|
-
Minimal 0-
|
|
3
|
+
Minimal 0-dependency QR code generator & reader.
|
|
4
4
|
|
|
5
5
|
- 🔒 Auditable, 0-dependency
|
|
6
|
-
-
|
|
6
|
+
- 🏎 Fast: [faster](#speed) than all JS implementations
|
|
7
|
+
- 🔍 Reliable: 100MB+ of extensive test vectors ensure correctness
|
|
8
|
+
- 🏞️ Encoding (generating) supports ASCII, term, gif, svg and png codes
|
|
7
9
|
- 📷 Decoding (reading) supports camera feed input, files and non-browser environments
|
|
8
|
-
-
|
|
9
|
-
- 🪶 14KB (gzipped) for encoding + decoding, 7KB for encoding
|
|
10
|
+
- 🪶 18KB (gzipped) for encoding + decoding, 9KB for encoding
|
|
10
11
|
|
|
11
12
|
Check out:
|
|
12
13
|
|
|
@@ -52,6 +53,8 @@ const terminalFriendly = encodeQR(txt, 'term'); // 2x larger, all fonts are OK
|
|
|
52
53
|
const gifBytes = encodeQR(txt, 'gif'); // Uncompressed GIF
|
|
53
54
|
const svgElement = encodeQR(txt, 'svg'); // SVG vector image element
|
|
54
55
|
const array = encodeQR(txt, 'raw'); // 2d array for canvas or other libs
|
|
56
|
+
// import { svgToPng } from 'qr/dom.js';
|
|
57
|
+
// const png = svgToPng(svgElement, 512, 512); // .png, using DOM
|
|
55
58
|
|
|
56
59
|
// Options
|
|
57
60
|
// Custom error correction level
|
|
@@ -135,10 +138,6 @@ function decodeWithExternal() {
|
|
|
135
138
|
const decoded = decodeQR(parseGIF(gifBytes));
|
|
136
139
|
console.log('decoded(gif)', decoded);
|
|
137
140
|
}
|
|
138
|
-
|
|
139
|
-
// c) draw gif/svg to browser DOM canvas
|
|
140
|
-
import { svgToPng } from 'qr/dom.js';
|
|
141
|
-
const png = svgToPng(encodeQR('Hello world', 'svg'), 512, 512);
|
|
142
141
|
```
|
|
143
142
|
|
|
144
143
|
### Decoding options
|
|
@@ -235,27 +234,29 @@ Future plans:
|
|
|
235
234
|
|
|
236
235
|
## Speed
|
|
237
236
|
|
|
238
|
-
Benchmarks measured with Apple
|
|
237
|
+
Benchmarks measured with Apple M4 with node.js 25.
|
|
239
238
|
|
|
240
239
|
```
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
encode
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
encode
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
decode
|
|
257
|
-
|
|
258
|
-
|
|
240
|
+
# encode format=ascii
|
|
241
|
+
@paulmillr/qr x 9,050 ops/sec @ 110μs/op
|
|
242
|
+
qrcode-generator x 4,543 ops/sec @ 220μs/op
|
|
243
|
+
nuintun x 3,413 ops/sec @ 292μs/op
|
|
244
|
+
|
|
245
|
+
# encode format=gif
|
|
246
|
+
@paulmillr/qr x 8,439 ops/sec @ 118μs/op
|
|
247
|
+
qrcode-generator x 2,909 ops/sec @ 343μs/op
|
|
248
|
+
nuintun x 3,470 ops/sec @ 288μs/op
|
|
249
|
+
|
|
250
|
+
# encode of large qr
|
|
251
|
+
@paulmillr/qr x 334 ops/sec @ 2ms/op
|
|
252
|
+
qrcode-generator x 174 ops/sec @ 5ms/op
|
|
253
|
+
nuintun x 221 ops/sec @ 4ms/op
|
|
254
|
+
|
|
255
|
+
# decode
|
|
256
|
+
@paulmillr/qr x 662 ops/sec @ 1ms/op
|
|
257
|
+
jsqr x 50 ops/sec @ 19ms/op
|
|
258
|
+
nuintun x 49 ops/sec @ 20ms/op
|
|
259
|
+
instascan x 128 ops/sec @ 7ms/op ± 31.44% (4ms..166ms)
|
|
259
260
|
```
|
|
260
261
|
|
|
261
262
|
## License
|
package/decode.d.ts
CHANGED
|
@@ -27,7 +27,21 @@ import { Bitmap } from './index.ts';
|
|
|
27
27
|
export type FinderPoints = [Pattern, Pattern, Point, Pattern];
|
|
28
28
|
/**
|
|
29
29
|
* Convert to grayscale. The function is the most expensive part of decoding:
|
|
30
|
-
* it takes up to 90% of time.
|
|
30
|
+
* it takes up to 90% of time.
|
|
31
|
+
*
|
|
32
|
+
* Binarization pipeline:
|
|
33
|
+
* 1. Convert RGB/RGBA image to one luma byte per pixel.
|
|
34
|
+
* 2. Split the image into 8x8 blocks and collect per-block mean/min/max.
|
|
35
|
+
* 3. Build a 5x5 neighborhood mean over those block means.
|
|
36
|
+
* 4. Turn each 8x8 block into bitmap bits using a local cut derived from:
|
|
37
|
+
* - the neighborhood mean,
|
|
38
|
+
* - the current block statistics,
|
|
39
|
+
* - a cheap whole-image color-spread estimate,
|
|
40
|
+
* - and, on risky scenes, a local variance field over block means.
|
|
41
|
+
*
|
|
42
|
+
* Instead of producing "best looking" thresholding: we produce a
|
|
43
|
+
* bitmap where finder patterns survive perspective / blur / highlights while
|
|
44
|
+
* keeping false dark regions low enough for downstream finder selection.
|
|
31
45
|
*/
|
|
32
46
|
declare function toBitmap(img: Image): Bitmap;
|
|
33
47
|
type Pattern = Point & {
|
|
@@ -43,7 +57,7 @@ declare function detect(b: Bitmap): {
|
|
|
43
57
|
bits: Bitmap;
|
|
44
58
|
points: FinderPoints;
|
|
45
59
|
};
|
|
46
|
-
declare function decodeBitmap(b: Bitmap, decoder?: (bytes: Uint8Array) => string): string;
|
|
60
|
+
declare function decodeBitmap(b: Bitmap, decoder?: (bytes: Uint8Array, eci: number) => string): string;
|
|
47
61
|
export type DecodeOpts = {
|
|
48
62
|
cropToSquare?: boolean;
|
|
49
63
|
textDecoder?: (bytes: Uint8Array) => string;
|
package/decode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["src/decode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE;AACF;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAiC,KAAK,EAAQ,KAAK,EAAE,MAAM,YAAY,CAAC;AACpF,OAAO,EAAE,MAAM,EAAS,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["src/decode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE;AACF;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAiC,KAAK,EAAQ,KAAK,EAAE,MAAM,YAAY,CAAC;AACpF,OAAO,EAAE,MAAM,EAAS,MAAM,YAAY,CAAC;AA6B3C,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AAoC9D;;;;;;;;;;;;;;;;;GAiBG;AACH,iBAAS,QAAQ,CAAC,GAAG,EAAE,KAAK,GAAG,MAAM,CA2TpC;AAGD,KAAK,OAAO,GAAG,KAAK,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AA8K7D,iBAAS,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG;IAC9B,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;CACb,CA8HA;AAoHD,iBAAS,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;I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