@agicash/qr-scanner 0.1.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/LICENSE +21 -0
- package/README.md +136 -0
- package/dist/index.cjs +1065 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +106 -0
- package/dist/index.d.ts +106 -0
- package/dist/index.js +1036 -0
- package/dist/index.js.map +1 -0
- package/dist/worker.js +1785 -0
- package/dist/worker.js.map +1 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MakePrisms
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# @agicash/qr-scanner
|
|
2
|
+
|
|
3
|
+
High-performance QR code scanner for the web, powered by ZXing-C++ WebAssembly. Drop-in replacement for [nimiq/qr-scanner](https://github.com/nimiq/qr-scanner) with significantly better decoding of dense QR codes.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **No forced downscale** - feeds high-resolution frames to the decoder (720-1080px+)
|
|
8
|
+
- **WASM decoder** - ZXing-C++ compiled to WebAssembly, ~2x faster than pure-JS decoders
|
|
9
|
+
- **Web Worker** - decoding runs off the main thread, keeping UI at 60fps
|
|
10
|
+
- **`tryHarder` mode** - additional processing passes for hard-to-read codes
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
bun add @agicash/qr-scanner
|
|
16
|
+
# or
|
|
17
|
+
npm install @agicash/qr-scanner
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
### Live Camera Scanner
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import QrScanner from '@agicash/qr-scanner';
|
|
26
|
+
|
|
27
|
+
const scanner = new QrScanner(videoElement, (result) => {
|
|
28
|
+
console.log(result.data); // decoded string
|
|
29
|
+
console.log(result.cornerPoints); // QR code corner positions
|
|
30
|
+
}, {
|
|
31
|
+
highlightScanRegion: true,
|
|
32
|
+
highlightCodeOutline: true,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
await scanner.start();
|
|
36
|
+
|
|
37
|
+
// Later...
|
|
38
|
+
scanner.destroy();
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Scan a Single Image
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import QrScanner from '@agicash/qr-scanner';
|
|
45
|
+
|
|
46
|
+
const result = await QrScanner.scanImage(fileOrBlobOrUrl);
|
|
47
|
+
console.log(result.data);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## API
|
|
51
|
+
|
|
52
|
+
### Constructor
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
new QrScanner(videoElement, onDecode, options?)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Options
|
|
59
|
+
|
|
60
|
+
| Option | Type | Default | Description |
|
|
61
|
+
|--------|------|---------|-------------|
|
|
62
|
+
| `onDecodeError` | `(error) => void` | no-op | Called when no QR code found |
|
|
63
|
+
| `calculateScanRegion` | `(video) => ScanRegion` | centered 2/3 square | Define the scan crop area |
|
|
64
|
+
| `preferredCamera` | `'environment' \| 'user' \| string` | `'environment'` | Camera to use |
|
|
65
|
+
| `maxScansPerSecond` | `number` | `15` | Max decode attempts per second |
|
|
66
|
+
| `highlightScanRegion` | `boolean` | `false` | Show scan region overlay |
|
|
67
|
+
| `highlightCodeOutline` | `boolean` | `false` | Highlight detected QR code |
|
|
68
|
+
| `overlay` | `HTMLDivElement` | - | Custom overlay element |
|
|
69
|
+
| `cameraResolution` | `object` | `{ width: { ideal: 1920 }, height: { ideal: 1080 } }` | Camera resolution |
|
|
70
|
+
| `decoderOptions` | `Partial<ReaderOptions>` | - | zxing-wasm reader options |
|
|
71
|
+
|
|
72
|
+
### Instance Methods
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
scanner.start(): Promise<void>
|
|
76
|
+
scanner.stop(): void
|
|
77
|
+
scanner.destroy(): void
|
|
78
|
+
scanner.pause(stopStreamImmediately?): Promise<boolean>
|
|
79
|
+
scanner.setCamera(facingModeOrDeviceId): Promise<void>
|
|
80
|
+
scanner.hasFlash(): Promise<boolean>
|
|
81
|
+
scanner.isFlashOn(): boolean
|
|
82
|
+
scanner.toggleFlash(): Promise<void>
|
|
83
|
+
scanner.turnFlashOn(): Promise<void>
|
|
84
|
+
scanner.turnFlashOff(): Promise<void>
|
|
85
|
+
scanner.setInversionMode(mode): void
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Static Methods
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
QrScanner.hasCamera(): Promise<boolean>
|
|
92
|
+
QrScanner.listCameras(requestLabels?): Promise<Camera[]>
|
|
93
|
+
QrScanner.scanImage(source, options?): Promise<ScanResult>
|
|
94
|
+
QrScanner.preload(): Promise<void>
|
|
95
|
+
QrScanner.configureWasm(overrides): void
|
|
96
|
+
QrScanner.setWorkerUrl(url): void
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Worker Loading
|
|
100
|
+
|
|
101
|
+
The library uses a Web Worker for off-thread QR decoding. The worker script (`dist/worker.js`) is resolved automatically by modern bundlers (Vite, webpack 5, Parcel) via `new URL('./worker.js', import.meta.url)`.
|
|
102
|
+
|
|
103
|
+
For CJS consumers or non-standard setups, set the worker URL manually:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
QrScanner.setWorkerUrl('/assets/@agicash/qr-scanner/dist/worker.js');
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## WASM Loading
|
|
110
|
+
|
|
111
|
+
By default, the WASM binary (~919 KB) loads from jsDelivr CDN. To self-host:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
QrScanner.configureWasm({
|
|
115
|
+
locateFile: (filename) => `/wasm/${filename}`,
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Migration from qr-scanner
|
|
120
|
+
|
|
121
|
+
| qr-scanner | @agicash/qr-scanner |
|
|
122
|
+
|------------|-----------------|
|
|
123
|
+
| `returnDetailedScanResult: true` | Always returns `ScanResult` |
|
|
124
|
+
| `ScanRegion.downScaledWidth/Height` | Removed - no downscaling |
|
|
125
|
+
| `createQrEngine()` | Removed - engine is internal |
|
|
126
|
+
| `setGrayscaleWeights()` | Removed - handled by WASM |
|
|
127
|
+
| `DEFAULT_CANVAS_SIZE` | Removed - no canvas downscale |
|
|
128
|
+
| Multiple constructor overloads | Single constructor |
|
|
129
|
+
|
|
130
|
+
## Browser Support
|
|
131
|
+
|
|
132
|
+
Chrome 80+, Safari 16+, Firefox 80+, Edge 80+
|
|
133
|
+
|
|
134
|
+
## License
|
|
135
|
+
|
|
136
|
+
MIT
|