@wirunrom/hqr-generate 0.2.23 → 0.3.11
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 +230 -151
- package/index.bundler.js +59 -34
- package/index.d.ts +29 -22
- package/index.web.js +61 -42
- package/package.json +66 -64
- package/pkg/bundler/LICENSE +21 -0
- package/pkg/bundler/README.md +230 -151
- package/pkg/bundler/hqr_generate.d.ts +2 -0
- package/pkg/bundler/hqr_generate.js +1 -1
- package/pkg/bundler/hqr_generate_bg.js +32 -0
- package/pkg/bundler/hqr_generate_bg.wasm +0 -0
- package/pkg/bundler/hqr_generate_bg.wasm.d.ts +3 -2
- package/pkg/bundler/package.json +1 -1
- package/pkg/web/LICENSE +21 -0
- package/pkg/web/README.md +230 -151
- package/pkg/web/hqr_generate.d.ts +5 -2
- package/pkg/web/hqr_generate.js +32 -0
- package/pkg/web/hqr_generate_bg.wasm +0 -0
- package/pkg/web/hqr_generate_bg.wasm.d.ts +3 -2
- package/pkg/web/package.json +1 -1
- package/react/index.d.ts +12 -17
- package/react/index.js +4 -91
- package/react/useQrDecodeFromImageData.d.ts +5 -0
- package/react/useQrDecodeFromImageData.js +47 -0
- package/react/useQrDecodeFromImageSrc.d.ts +6 -0
- package/react/useQrDecodeFromImageSrc.js +59 -0
- package/react/useQrPngBlobUrl.d.ts +6 -0
- package/react/useQrPngBlobUrl.js +52 -0
- package/react/useQrPngDataUrl.d.ts +6 -0
- package/react/useQrPngDataUrl.js +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wirunrom
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,151 +1,230 @@
|
|
|
1
|
-
# @wirunrom/hqr-generate
|
|
2
|
-
|
|
3
|
-
A
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
1
|
+
# @wirunrom/hqr-generate
|
|
2
|
+
|
|
3
|
+
A high-performance **QR Code generator and decoder** with
|
|
4
|
+
**black-and-white only output**, powered by **Rust + WebAssembly (WASM)**.
|
|
5
|
+
|
|
6
|
+
Supports both **QR generation** and **QR decoding (scan)** in modern web applications.
|
|
7
|
+
|
|
8
|
+
This library is designed with a **scan-reliability-first** mindset and a **frontend-first API**, making it easy to use in modern web applications without additional configuration.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- High-contrast **black & white only** output (maximum scan compatibility)
|
|
15
|
+
- Optimized for both **old and new mobile devices**
|
|
16
|
+
- Deterministic and consistent QR output
|
|
17
|
+
- Lightweight and fast (**Rust + WASM**)
|
|
18
|
+
- QR decoding (scan) from browser ImageData
|
|
19
|
+
- Supports:
|
|
20
|
+
- **PNG Data URL** (simple usage)
|
|
21
|
+
- **PNG raw bytes** (best performance, no Base64 overhead)
|
|
22
|
+
- Works out of the box with:
|
|
23
|
+
- Plain HTML / JavaScript
|
|
24
|
+
- React
|
|
25
|
+
- Next.js Client Component (Pages Router & App Router)
|
|
26
|
+
- Modern bundlers (Vite, Webpack, etc.)
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install @wirunrom/hqr-generate
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## API Reference (GenerateQR)
|
|
37
|
+
|
|
38
|
+
Generate a QR code and return a PNG Data URL.
|
|
39
|
+
|
|
40
|
+
Parameters
|
|
41
|
+
|
|
42
|
+
| Name | Type | Default | Description |
|
|
43
|
+
| ------ | -------------------------- | ------- | ---------------------------- |
|
|
44
|
+
| text | `string` | — | Text to encode |
|
|
45
|
+
| size | `number` | `320` | Image size in pixels |
|
|
46
|
+
| margin | `number` | `4` | Quiet zone (recommended ≥ 4) |
|
|
47
|
+
| ecc | `"L" \| "M" \| "Q" \| "H"` | `"Q"` | Error correction level |
|
|
48
|
+
|
|
49
|
+
## Basic Usage [Bundler / React / Next.js (Client)]
|
|
50
|
+
|
|
51
|
+
**Generate PNG Data URL**
|
|
52
|
+
|
|
53
|
+
Simple and widely compatible. Recommended for most use cases.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { qr_png_data_url } from "@wirunrom/hqr-generate";
|
|
57
|
+
|
|
58
|
+
const src = await qr_png_data_url("hello world", 320, 4, "Q");
|
|
59
|
+
|
|
60
|
+
<img src={src} alt="QR Code" />
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**Generate PNG Bytes (Best Performance)**
|
|
64
|
+
|
|
65
|
+
Using raw bytes avoids Base64 overhead and is more memory-efficient.
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { qr_png_bytes } from "@wirunrom/hqr-generate";
|
|
69
|
+
|
|
70
|
+
const bytes = await qr_png_bytes("hello world", 320, 4, "Q");
|
|
71
|
+
|
|
72
|
+
const url = URL.createObjectURL(
|
|
73
|
+
new Blob([bytes], { type: "image/png" })
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
<img src={url} alt="QR Code" />
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Decode QR Code**
|
|
80
|
+
|
|
81
|
+
Decode a QR code from browser ImageData (Canvas / camera / image upload friendly).
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { qr_decode_from_image } from "@wirunrom/hqr-generate";
|
|
85
|
+
|
|
86
|
+
const imageData = ctx.getImageData(0, 0, width, height);
|
|
87
|
+
const text = await qr_decode_from_image(imageData);
|
|
88
|
+
|
|
89
|
+
console.log(text);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Decode runs entirely in WASM and does not require server-side processing.
|
|
93
|
+
|
|
94
|
+
## React Hook Helper (/react)
|
|
95
|
+
|
|
96
|
+
For React or Next.js applications, the library provides idiomatic React hooks that manage async state automatically.
|
|
97
|
+
|
|
98
|
+
**useQrPngDataUrl**
|
|
99
|
+
|
|
100
|
+
Generates a PNG Data URL and updates automatically when inputs change.
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { useQrPngDataUrl } from "@wirunrom/hqr-generate/react";
|
|
104
|
+
|
|
105
|
+
function QR() {
|
|
106
|
+
const src = useQrPngDataUrl("hello world", {
|
|
107
|
+
size: 320,
|
|
108
|
+
margin: 4,
|
|
109
|
+
ecc: "Q",
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (!src) return null;
|
|
113
|
+
return <img src={src} alt="QR Code" />;
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**useQrPngBlobUrl**
|
|
118
|
+
|
|
119
|
+
Generates a Blob URL instead of a Base64 Data URL.
|
|
120
|
+
Recommended for larger QR codes or frequent updates.
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { useQrPngBlobUrl } from "@wirunrom/hqr-generate/react";
|
|
124
|
+
|
|
125
|
+
function QR() {
|
|
126
|
+
const src = useQrPngBlobUrl("hello world", {
|
|
127
|
+
size: 320,
|
|
128
|
+
margin: 4,
|
|
129
|
+
ecc: "Q",
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
if (!src) return null;
|
|
133
|
+
return <img src={src} alt="QR Code" />;
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**useQrDecodeFromImageData**
|
|
138
|
+
|
|
139
|
+
Decode a QR code from browser ImageData.
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import { useQrDecodeFromImageData } from "@wirunrom/hqr-generate/react";
|
|
143
|
+
|
|
144
|
+
function Scanner({ image }: { image: ImageData | null }) {
|
|
145
|
+
const { text, loading, error } = useQrDecodeFromImageData(image);
|
|
146
|
+
|
|
147
|
+
if (loading) return <div>Scanning…</div>;
|
|
148
|
+
if (error) return <div>Error</div>;
|
|
149
|
+
if (!text) return null;
|
|
150
|
+
|
|
151
|
+
return <div>QR: {text}</div>;
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Parameters
|
|
156
|
+
|
|
157
|
+
| Name | Type | Description |
|
|
158
|
+
| ----- | ----------- | ------------------------------------------- |
|
|
159
|
+
| image | `ImageData` | RGBA image data from Canvas or Camera frame |
|
|
160
|
+
|
|
161
|
+
Returns
|
|
162
|
+
|
|
163
|
+
- `Promise<string>`
|
|
164
|
+
- Resolves with decoded QR text
|
|
165
|
+
- Rejects if no QR code is detected or image is invalid
|
|
166
|
+
|
|
167
|
+
Notes
|
|
168
|
+
|
|
169
|
+
- Input must be RGBA ImageData
|
|
170
|
+
- Decode runs entirely in WASM
|
|
171
|
+
- No server or backend required
|
|
172
|
+
- Best results with:
|
|
173
|
+
- High-contrast QR codes
|
|
174
|
+
- Minimal blur
|
|
175
|
+
- Proper quiet zone
|
|
176
|
+
|
|
177
|
+
**useQrDecodeFromImageSrc**
|
|
178
|
+
|
|
179
|
+
Decode a QR code from your image path.
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
import { useQrDecodeFromImageSrc } from "@wirunrom/hqr-generate/react";
|
|
183
|
+
|
|
184
|
+
function DecodeQR({ imagePath }: { imagePath: string | null }) {
|
|
185
|
+
const { text } = useQrDecodeFromImageSrc(imagePath);
|
|
186
|
+
|
|
187
|
+
if (!text) return null;
|
|
188
|
+
|
|
189
|
+
return <div>Decode QR: {text}</div>;
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Parameters
|
|
194
|
+
|
|
195
|
+
| Name | Type | Description |
|
|
196
|
+
| ---- | -------- | --------------- |
|
|
197
|
+
| src | `string` | Your image path |
|
|
198
|
+
|
|
199
|
+
Returns
|
|
200
|
+
|
|
201
|
+
- `Promise<string>`
|
|
202
|
+
- Resolves with decoded QR text
|
|
203
|
+
|
|
204
|
+
## Plain HTML / No Bundler (/web)
|
|
205
|
+
|
|
206
|
+
Use this entry when working with static HTML, CDN, or environments without a bundler.
|
|
207
|
+
|
|
208
|
+
```html
|
|
209
|
+
<script type="module">
|
|
210
|
+
import {
|
|
211
|
+
qr_png_bytes,
|
|
212
|
+
qr_png_data_url,
|
|
213
|
+
qr_decode_from_image_data,
|
|
214
|
+
} from "@wirunrom/hqr-generate/web";
|
|
215
|
+
|
|
216
|
+
const src = await qr_png_data_url("hello world", 320, 4, "Q");
|
|
217
|
+
document.getElementById("qr").src = src;
|
|
218
|
+
|
|
219
|
+
// decode example (canvas)
|
|
220
|
+
const canvas = document.getElementById("c");
|
|
221
|
+
const ctx = canvas.getContext("2d");
|
|
222
|
+
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
223
|
+
|
|
224
|
+
const text = await qr_decode_from_image_data(imageData);
|
|
225
|
+
console.log(text);
|
|
226
|
+
</script>
|
|
227
|
+
|
|
228
|
+
<img id="qr" />
|
|
229
|
+
<canvas id="c" hidden></canvas>
|
|
230
|
+
```
|
package/index.bundler.js
CHANGED
|
@@ -1,34 +1,59 @@
|
|
|
1
|
-
import init, {
|
|
2
|
-
qr_png_data_url as _qr_png_data_url,
|
|
3
|
-
qr_png_bytes as _qr_png_bytes,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
import init, {
|
|
2
|
+
qr_png_data_url as _qr_png_data_url,
|
|
3
|
+
qr_png_bytes as _qr_png_bytes,
|
|
4
|
+
qr_decode_from_rgba as _qr_decode_from_rgba,
|
|
5
|
+
} from "./pkg/bundler/hqr_generate.js";
|
|
6
|
+
|
|
7
|
+
let _initPromise;
|
|
8
|
+
|
|
9
|
+
function eccToU8(ecc) {
|
|
10
|
+
switch (ecc) {
|
|
11
|
+
case "L":
|
|
12
|
+
return 0;
|
|
13
|
+
case "M":
|
|
14
|
+
return 1;
|
|
15
|
+
case "H":
|
|
16
|
+
return 3;
|
|
17
|
+
default:
|
|
18
|
+
return 2;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** @returns {Promise<void>} */
|
|
23
|
+
async function ensureInit() {
|
|
24
|
+
_initPromise ??= init();
|
|
25
|
+
return _initPromise;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} text
|
|
30
|
+
* @param {number} [size=320]
|
|
31
|
+
* @param {number} [margin=4]
|
|
32
|
+
* @param {"L"|"M"|"Q"|"H"} [ecc="Q"]
|
|
33
|
+
* @returns {Promise<string>}
|
|
34
|
+
*/
|
|
35
|
+
export async function qr_png_data_url(text, size = 320, margin = 4, ecc = "Q") {
|
|
36
|
+
await ensureInit();
|
|
37
|
+
return _qr_png_data_url(text, size, margin, eccToU8(ecc));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {string} text
|
|
42
|
+
* @param {number} [size=320]
|
|
43
|
+
* @param {number} [margin=4]
|
|
44
|
+
* @param {"L"|"M"|"Q"|"H"} [ecc="Q"]
|
|
45
|
+
* @returns {Promise<Uint8Array>}
|
|
46
|
+
*/
|
|
47
|
+
export async function qr_png_bytes(text, size = 320, margin = 4, ecc = "Q") {
|
|
48
|
+
await ensureInit();
|
|
49
|
+
return _qr_png_bytes(text, size, margin, eccToU8(ecc));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {ImageData} image
|
|
54
|
+
* @returns {Promise<string>}
|
|
55
|
+
*/
|
|
56
|
+
export async function qr_decode_from_image_data(image) {
|
|
57
|
+
await ensureInit();
|
|
58
|
+
return _qr_decode_from_rgba(image.width, image.height, image.data);
|
|
59
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
export type QrEcc = "L" | "M" | "Q" | "H";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Generate QR code PNG as Data URL (base64).
|
|
5
|
-
*/
|
|
6
|
-
export declare function qr_png_data_url(
|
|
7
|
-
text: string,
|
|
8
|
-
size?: number,
|
|
9
|
-
margin?: number,
|
|
10
|
-
ecc?: QrEcc
|
|
11
|
-
): Promise<string>;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Generate QR code PNG as raw bytes (Uint8Array).
|
|
15
|
-
* Recommended for best performance (Blob URL, upload, caching).
|
|
16
|
-
*/
|
|
17
|
-
export declare function qr_png_bytes(
|
|
18
|
-
text: string,
|
|
19
|
-
size?: number,
|
|
20
|
-
margin?: number,
|
|
21
|
-
ecc?: QrEcc
|
|
22
|
-
): Promise<Uint8Array>;
|
|
1
|
+
export type QrEcc = "L" | "M" | "Q" | "H";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generate QR code PNG as Data URL (base64).
|
|
5
|
+
*/
|
|
6
|
+
export declare function qr_png_data_url(
|
|
7
|
+
text: string,
|
|
8
|
+
size?: number,
|
|
9
|
+
margin?: number,
|
|
10
|
+
ecc?: QrEcc
|
|
11
|
+
): Promise<string>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Generate QR code PNG as raw bytes (Uint8Array).
|
|
15
|
+
* Recommended for best performance (Blob URL, upload, caching).
|
|
16
|
+
*/
|
|
17
|
+
export declare function qr_png_bytes(
|
|
18
|
+
text: string,
|
|
19
|
+
size?: number,
|
|
20
|
+
margin?: number,
|
|
21
|
+
ecc?: QrEcc
|
|
22
|
+
): Promise<Uint8Array>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Decode QR from browser ImageData
|
|
26
|
+
*/
|
|
27
|
+
export function qr_decode_from_image_data(
|
|
28
|
+
image: ImageData
|
|
29
|
+
): Promise<string>;
|
package/index.web.js
CHANGED
|
@@ -1,42 +1,61 @@
|
|
|
1
|
-
import init, {
|
|
2
|
-
qr_png_data_url as _qr_png_data_url,
|
|
3
|
-
qr_png_bytes as _qr_png_bytes,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
* @param {
|
|
30
|
-
* @param {number} [
|
|
31
|
-
* @param {
|
|
32
|
-
* @
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
1
|
+
import init, {
|
|
2
|
+
qr_png_data_url as _qr_png_data_url,
|
|
3
|
+
qr_png_bytes as _qr_png_bytes,
|
|
4
|
+
qr_decode_from_rgba as _qr_decode_from_rgba,
|
|
5
|
+
} from "./pkg/web/hqr_generate.js";
|
|
6
|
+
|
|
7
|
+
let _initPromise;
|
|
8
|
+
|
|
9
|
+
function eccToU8(ecc) {
|
|
10
|
+
switch (ecc) {
|
|
11
|
+
case "L":
|
|
12
|
+
return 0;
|
|
13
|
+
case "M":
|
|
14
|
+
return 1;
|
|
15
|
+
case "H":
|
|
16
|
+
return 3;
|
|
17
|
+
default:
|
|
18
|
+
return 2;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** @returns {Promise<void>} */
|
|
23
|
+
async function ensureInit() {
|
|
24
|
+
_initPromise ??= init();
|
|
25
|
+
return _initPromise;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} text
|
|
30
|
+
* @param {number} [size=320]
|
|
31
|
+
* @param {number} [margin=4]
|
|
32
|
+
* @param {"L"|"M"|"Q"|"H"} [ecc="Q"]
|
|
33
|
+
* @returns {Promise<string>}
|
|
34
|
+
*/
|
|
35
|
+
export async function qr_png_data_url(text, size = 320, margin = 4, ecc = "Q") {
|
|
36
|
+
await ensureInit();
|
|
37
|
+
return _qr_png_data_url(text, size, margin, eccToU8(ecc));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {string} text
|
|
42
|
+
* @param {number} [size=320]
|
|
43
|
+
* @param {number} [margin=4]
|
|
44
|
+
* @param {"L"|"M"|"Q"|"H"} [ecc="Q"]
|
|
45
|
+
* @returns {Promise<Uint8Array>}
|
|
46
|
+
*/
|
|
47
|
+
export async function qr_png_bytes(text, size = 320, margin = 4, ecc = "Q") {
|
|
48
|
+
await ensureInit();
|
|
49
|
+
return _qr_png_bytes(text, size, margin, eccToU8(ecc));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Decode QR from Image (browser/canvas friendly)
|
|
54
|
+
*
|
|
55
|
+
* @param {ImageData} image
|
|
56
|
+
* @returns {Promise<string>}
|
|
57
|
+
*/
|
|
58
|
+
export async function qr_decode_from_image_data(image) {
|
|
59
|
+
await ensureInit();
|
|
60
|
+
return _qr_decode_from_rgba(image.width, image.height, image.data);
|
|
61
|
+
}
|