nano-scan 0.0.1
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 +157 -0
- package/dist/esm/index.js +1939 -0
- package/dist/index.d.ts +39 -0
- package/dist/umd/index.js +1947 -0
- package/dist/utils.d.ts +35 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 PED
|
|
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,157 @@
|
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<img src="./docs/logo.svg" alt="Nano Scan logo" height="64" valign="middle">
|
|
3
|
+
<div>Nano Scan</div>
|
|
4
|
+
</h1>
|
|
5
|
+
|
|
6
|
+
**NanoScan** is a lightweight, high-performance web barcode and QR code scanner powered by
|
|
7
|
+
[`zxing-wasm`](https://github.com/Sec-ant/zxing-wasm). Designed for maximum compatibility and flexibility, it supports
|
|
8
|
+
all barcode types recognized by zxing-wasm and includes enhanced support for small or distant codes via canvas-based
|
|
9
|
+
zooming.
|
|
10
|
+
|
|
11
|
+
<div align="center">
|
|
12
|
+
<h3>
|
|
13
|
+
<a href="https://pedx.github.io/nano-scan/" target="_blank" rel="noopener noreferrer">
|
|
14
|
+
👉 Try the live demo
|
|
15
|
+
</a>
|
|
16
|
+
</h3>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<p align="center">
|
|
20
|
+
<img src="./docs/qrcode.svg" alt="Nano Scan QR Code Test" width="1086px" align="middle">
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
## ✨ Features
|
|
24
|
+
|
|
25
|
+
- 🔍 **Supports All ZXing Formats** Full access to `zxing-wasm`'s decoding capabilities, including QR codes, EAN, Code
|
|
26
|
+
128, and more.
|
|
27
|
+
|
|
28
|
+
- 🎥 **Camera Zoom Fallback** Automatically falls back to canvas-based digital zoom when native camera zoom APIs are not
|
|
29
|
+
available — ideal for scanning small codes (~1cm).
|
|
30
|
+
|
|
31
|
+
- ⚡️ **Tiny & Easy to Integrate** Minimal footprint and a clean API make NanoScan easy to drop into any web project.
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install nano-scan
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Basic Usage
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import NanoScan from 'nano-scan';
|
|
43
|
+
|
|
44
|
+
const nanoScan = new NanoScan({
|
|
45
|
+
container: document.getElementById('camera-container'),
|
|
46
|
+
resolution: {
|
|
47
|
+
width: 1080,
|
|
48
|
+
height: 1080,
|
|
49
|
+
},
|
|
50
|
+
fps: 30,
|
|
51
|
+
zoom: 2,
|
|
52
|
+
onScan: (result) => {
|
|
53
|
+
console.log(result);
|
|
54
|
+
},
|
|
55
|
+
onError: (error) => {
|
|
56
|
+
console.error(error);
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Start scanning
|
|
61
|
+
nanoScan.startScan();
|
|
62
|
+
|
|
63
|
+
// Stop scanning
|
|
64
|
+
nanoScan.stopScan();
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Class: NanoScan
|
|
68
|
+
|
|
69
|
+
Main class providing barcode/QR code scanning functionality.
|
|
70
|
+
|
|
71
|
+
### Constructor
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
constructor(options: INanoScanOptions)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### Parameters
|
|
78
|
+
|
|
79
|
+
`options` - Configuration object of type `INanoScanOptions`
|
|
80
|
+
|
|
81
|
+
### Configuration Options (INanoScanOptions)
|
|
82
|
+
|
|
83
|
+
| Parameter | Type | Default | Description |
|
|
84
|
+
| -------------- | ----------------------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------ |
|
|
85
|
+
| `container` | `HTMLElement \| null` | `null` | **Required**. HTML container element for displaying camera preview |
|
|
86
|
+
| `resolution` | `{ width: number, height: number }` | `{ width: 1080, height: 1080 }` | Camera resolution |
|
|
87
|
+
| `zxingOptions` | `ReaderOptions` | `{ tryHarder: true, formats: ['QRCode'], maxNumberOfSymbols: 1 }` | zxing-wasm reader options |
|
|
88
|
+
| `zxingWASMUrl` | `string` | `undefined` | Custom zxing-wasm WebAssembly file URL |
|
|
89
|
+
| `marker` | `boolean` | `true` | Whether to display scan result marker |
|
|
90
|
+
| `frame` | `boolean` | `true` | Whether to display scan frame |
|
|
91
|
+
| `fps` | `number` | `30` | Scanning frame rate |
|
|
92
|
+
| `zoom` | `number` | `1` | Initial zoom level |
|
|
93
|
+
| `trick` | `boolean` | `true` | Whether to use rotation trick for optimized scanning (helps with angled codes) |
|
|
94
|
+
| `onScan` | `(result: string) => void` | `noop` | Callback function when a result is scanned |
|
|
95
|
+
| `onError` | `(error: Error) => void` | `noop` | Callback function when an error occurs |
|
|
96
|
+
|
|
97
|
+
### Methods
|
|
98
|
+
|
|
99
|
+
#### startScan()
|
|
100
|
+
|
|
101
|
+
Starts the scanning process.
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
async startScan(): Promise<void>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Initializes the camera, sets up canvases, and begins the scanning loop.
|
|
108
|
+
|
|
109
|
+
#### stopScan()
|
|
110
|
+
|
|
111
|
+
Stops the scanning process.
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
stopScan(): void
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Stops the camera and scanning loop.
|
|
118
|
+
|
|
119
|
+
#### zoomIn(step?)
|
|
120
|
+
|
|
121
|
+
Zooms in the camera view.
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
zoomIn(step: number = 0.1): void
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
| Parameter | Type | Default | Description |
|
|
128
|
+
| --------- | -------- | ------- | -------------------- |
|
|
129
|
+
| `step` | `number` | `0.1` | Amount to zoom in by |
|
|
130
|
+
|
|
131
|
+
#### zoomOut(step?)
|
|
132
|
+
|
|
133
|
+
Zooms out the camera view.
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
zoomOut(step: number = 0.1): void
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
| Parameter | Type | Default | Description |
|
|
140
|
+
| --------- | -------- | ------- | --------------------- |
|
|
141
|
+
| `step` | `number` | `0.1` | Amount to zoom out by |
|
|
142
|
+
|
|
143
|
+
#### zoomTo(zoom)
|
|
144
|
+
|
|
145
|
+
Zooms the camera view to a specific level.
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
zoomTo(zoom: number): void
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
| Parameter | Type | Description |
|
|
152
|
+
| --------- | -------- | ----------------- |
|
|
153
|
+
| `zoom` | `number` | Zoom level to set |
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
[MIT](LICENSE)
|