@wirunrom/hqr-generate 0.4.2 → 0.5.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/index.d.ts CHANGED
@@ -1,68 +1,66 @@
1
- /* =========================================================
2
- * Types
3
- * ======================================================= */
4
-
5
- export type QrEcc = "L" | "M" | "Q" | "H";
6
-
7
- export interface GenerateOptions {
8
- /**
9
- * Output image size (px)
10
- * @default 320
11
- */
12
- size?: number;
13
-
14
- /**
15
- * Quiet zone / margin (modules)
16
- * @default 4
17
- */
18
- margin?: number;
19
-
20
- /**
21
- * Error correction level
22
- * @default "Q"
23
- */
24
- ecc?: QrEcc;
25
- }
26
-
27
- /* =========================================================
28
- * Generate (Encode)
29
- * ======================================================= */
30
-
31
- /**
32
- * Generate QR code (PNG, fastest & default)
33
- */
34
- export function generate(
35
- text: string,
36
- opts?: GenerateOptions
37
- ): Promise<Uint8Array> | Uint8Array;
38
-
39
- /**
40
- * Generate QR code as PNG
41
- */
42
- export function generate_png(
43
- text: string,
44
- opts?: GenerateOptions
45
- ): Promise<Uint8Array> | Uint8Array;
46
-
47
- /**
48
- * Generate QR code as SVG
49
- */
50
- export function generate_svg(
51
- text: string,
52
- opts?: GenerateOptions
53
- ): Promise<string> | string;
54
-
55
- /* =========================================================
56
- * Decode
57
- * ======================================================= */
58
-
59
- /**
60
- * Decode QR code from image source
61
- *
62
- * Supported inputs:
63
- * - Uint8Array (PNG / JPG / WebP / etc.)
64
- * - ImageData (Browser / Canvas)
65
- */
66
- export function decode(
67
- input: Uint8Array | ImageData
68
- ): Promise<string> | string;
1
+ /* =========================================================
2
+ * Types
3
+ * ======================================================= */
4
+
5
+ export type QrEcc = "L" | "M" | "Q" | "H";
6
+
7
+ export interface GenerateOptions {
8
+ /**
9
+ * Output image size (px)
10
+ * @default 320
11
+ */
12
+ size?: number;
13
+
14
+ /**
15
+ * Quiet zone / margin (modules)
16
+ * @default 4
17
+ */
18
+ margin?: number;
19
+
20
+ /**
21
+ * Error correction level
22
+ * @default "Q"
23
+ */
24
+ ecc?: QrEcc;
25
+ }
26
+
27
+ /* =========================================================
28
+ * Generate (Encode)
29
+ * ======================================================= */
30
+
31
+ /**
32
+ * Generate QR code (PNG, fastest & default)
33
+ */
34
+ export function generate(
35
+ text: string,
36
+ opts?: GenerateOptions,
37
+ ): Promise<Uint8Array> | Uint8Array;
38
+
39
+ /**
40
+ * Generate QR code as PNG
41
+ */
42
+ export function generate_png(
43
+ text: string,
44
+ opts?: GenerateOptions,
45
+ ): Promise<Uint8Array> | Uint8Array;
46
+
47
+ /**
48
+ * Generate QR code as SVG
49
+ */
50
+ export function generate_svg(
51
+ text: string,
52
+ opts?: GenerateOptions,
53
+ ): Promise<string> | string;
54
+
55
+ /* =========================================================
56
+ * Decode
57
+ * ======================================================= */
58
+
59
+ /**
60
+ * Decode QR code from image source
61
+ *
62
+ * Supported inputs:
63
+ * - Uint8Array (PNG / JPG / WebP / etc.)
64
+ * - ImageData (Browser / Canvas)
65
+ */
66
+ export function decode(input: Uint8Array | ImageData): Promise<string> | string;
package/index.node.js CHANGED
@@ -1,33 +1,41 @@
1
- // index.node.js (Node / SSR entry)
2
-
3
- import * as core from "./pkg/nodejs/hqr_generate.js";
4
-
5
- /**
6
- * Default generator (PNG)
7
- */
8
- export function generate(text, opts) {
9
- return core.generate_png(text, opts);
10
- }
11
-
12
- /**
13
- * Generate QR as PNG
14
- */
15
- export function generate_png(text, opts) {
16
- return core.generate_png(text, opts);
17
- }
18
-
19
- /**
20
- * Generate QR as SVG
21
- */
22
- export function generate_svg(text, opts) {
23
- return core.generate_svg(text, opts);
24
- }
25
-
26
- /**
27
- * Decode QR
28
- *
29
- * @param {Uint8Array | ImageData} input
30
- */
31
- export function decode(input) {
32
- return core.decode(input);
33
- }
1
+ // index.node.js (Node / SSR entry)
2
+
3
+ import * as core from "./pkg/nodejs/hqr_generate.js";
4
+
5
+ const ECC_MAP = { L: 0, M: 1, Q: 2, H: 3 };
6
+
7
+ function normalizeOpts(opts) {
8
+ const { size = 320, margin = 4, ecc = "Q" } = opts ?? {};
9
+ const eccCode = ECC_MAP[ecc] ?? 2;
10
+ return [size, margin, eccCode];
11
+ }
12
+
13
+ /**
14
+ * Default generator (PNG)
15
+ */
16
+ export function generate(text, opts) {
17
+ return core.generate_png(text, ...normalizeOpts(opts));
18
+ }
19
+
20
+ /**
21
+ * Generate QR as PNG
22
+ */
23
+ export function generate_png(text, opts) {
24
+ return core.generate_png(text, ...normalizeOpts(opts));
25
+ }
26
+
27
+ /**
28
+ * Generate QR as SVG
29
+ */
30
+ export function generate_svg(text, opts) {
31
+ return core.generate_svg(text, ...normalizeOpts(opts));
32
+ }
33
+
34
+ /**
35
+ * Decode QR
36
+ *
37
+ * @param {Uint8Array | ImageData} input
38
+ */
39
+ export function decode(input) {
40
+ return core.decode(input);
41
+ }
package/index.web.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- // index.web.d.ts
2
- export * from "./index";
1
+ // index.web.d.ts
2
+ export * from "./index";
package/index.web.js CHANGED
@@ -1,52 +1,60 @@
1
- import init, {
2
- generate_png as _generate_png,
3
- generate_svg as _generate_svg,
4
- decode as _decode,
5
- } from "./pkg/web/hqr_generate.js";
6
-
7
- let _initPromise;
8
-
9
- /** @returns {Promise<void>} */
10
- async function ensureInit() {
11
- _initPromise ??= init();
12
- return _initPromise;
13
- }
14
-
15
- /**
16
- * Default QR generator (PNG, fastest)
17
- *
18
- * @param {string} text
19
- * @param {object} [opts]
20
- * @returns {Promise<Uint8Array>}
21
- */
22
- export async function generate(text, opts) {
23
- await ensureInit();
24
- return _generate_png(text, opts);
25
- }
26
-
27
- /**
28
- * Generate QR as PNG
29
- */
30
- export async function generate_png(text, opts) {
31
- await ensureInit();
32
- return _generate_png(text, opts);
33
- }
34
-
35
- /**
36
- * Generate QR as SVG
37
- */
38
- export async function generate_svg(text, opts) {
39
- await ensureInit();
40
- return _generate_svg(text, opts);
41
- }
42
-
43
- /**
44
- * Decode QR from ImageData (Canvas / Browser)
45
- *
46
- * @param {ImageData} image
47
- * @returns {Promise<string>}
48
- */
49
- export async function decode(image) {
50
- await ensureInit();
51
- return _decode(image);
52
- }
1
+ import init, {
2
+ generate_png as _generate_png,
3
+ generate_svg as _generate_svg,
4
+ decode as _decode,
5
+ } from "./pkg/web/hqr_generate.js";
6
+
7
+ let _initPromise;
8
+
9
+ /** @returns {Promise<void>} */
10
+ async function ensureInit() {
11
+ _initPromise ??= init();
12
+ return _initPromise;
13
+ }
14
+
15
+ const ECC_MAP = { L: 0, M: 1, Q: 2, H: 3 };
16
+
17
+ function normalizeOpts(opts) {
18
+ const { size = 320, margin = 4, ecc = "Q" } = opts ?? {};
19
+ const eccCode = ECC_MAP[ecc] ?? 2;
20
+ return [size, margin, eccCode];
21
+ }
22
+
23
+ /**
24
+ * Default QR generator (PNG, fastest)
25
+ *
26
+ * @param {string} text
27
+ * @param {object} [opts]
28
+ * @returns {Promise<Uint8Array>}
29
+ */
30
+ export async function generate(text, opts) {
31
+ await ensureInit();
32
+ return _generate_png(text, ...normalizeOpts(opts));
33
+ }
34
+
35
+ /**
36
+ * Generate QR as PNG
37
+ */
38
+ export async function generate_png(text, opts) {
39
+ await ensureInit();
40
+ return _generate_png(text, ...normalizeOpts(opts));
41
+ }
42
+
43
+ /**
44
+ * Generate QR as SVG
45
+ */
46
+ export async function generate_svg(text, opts) {
47
+ await ensureInit();
48
+ return _generate_svg(text, ...normalizeOpts(opts));
49
+ }
50
+
51
+ /**
52
+ * Decode QR from ImageData (Canvas / Browser)
53
+ *
54
+ * @param {ImageData} image
55
+ * @returns {Promise<string>}
56
+ */
57
+ export async function decode(image) {
58
+ await ensureInit();
59
+ return _decode(image);
60
+ }
package/package.json CHANGED
@@ -1,88 +1,90 @@
1
- {
2
- "name": "@wirunrom/hqr-generate",
3
- "version": "0.4.2",
4
- "description": "High-performance QR code generator and decoder powered by Rust + WASM",
5
- "license": "MIT",
6
- "type": "module",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/wirunrom/hqr-generate.git"
10
- },
11
- "homepage": "https://github.com/wirunrom/hqr-generate#readme",
12
- "files": [
13
- "pkg/**",
14
- "index.node.js",
15
- "index.web.js",
16
- "index.d.ts",
17
- "index.web.d.ts",
18
- "react/**",
19
- "LICENSE",
20
- "README.md"
21
- ],
22
- "types": "./index.d.ts",
23
- "main": "./index.node.js",
24
- "module": "./index.web.js",
25
- "exports": {
26
- ".": {
27
- "types": "./index.d.ts",
28
- "import": "./index.web.js",
29
- "require": "./index.node.js",
30
- "browser": "./index.web.js",
31
- "node": "./index.node.js",
32
- "default": "./index.web.js"
33
- },
34
- "./react": {
35
- "types": "./react/index.d.ts",
36
- "default": "./react/index.js"
37
- },
38
- "./web": {
39
- "types": "./index.d.ts",
40
- "default": "./index.web.js"
41
- }
42
- },
43
- "peerDependencies": {
44
- "react": ">=17"
45
- },
46
- "peerDependenciesMeta": {
47
- "react": {
48
- "optional": true
49
- }
50
- },
51
- "scripts": {
52
- "clean": "rm -rf pkg",
53
- "build:react": "tsc -p tsconfig.react.json",
54
- "build:web": "wasm-pack build --target web --out-dir pkg/web -- --features wasm,decode",
55
- "build:node": "wasm-pack build --target nodejs --out-dir pkg/nodejs -- --features wasm,decode",
56
- "build": "npm run build:web && npm run build:node && npm run build:react",
57
- "prepare": "npm run clean && npm run build && rm -f pkg/**/README.md pkg/**/LICENSE pkg/**/package.json pkg/**/.gitignore",
58
- "release:test": "npm version prerelease --preid=next && npm run publish:test",
59
- "publish:test": "npm publish --tag next --registry=https://registry.npmjs.org --access public",
60
- "publish:npm": "npm publish --registry=https://registry.npmjs.org --access public",
61
- "publish:github": "npm publish --registry=https://npm.pkg.github.com --userconfig .npmrc.github --access public"
62
- },
63
- "keywords": [
64
- "qrcode",
65
- "qr",
66
- "qr-decode",
67
- "rust",
68
- "wasm",
69
- "webassembly",
70
- "react",
71
- "nextjs",
72
- "ssr",
73
- "browser",
74
- "vanilla-js",
75
- "png",
76
- "svg",
77
- "uint8array",
78
- "binary",
79
- "blob",
80
- "performance",
81
- "scan-reliability"
82
- ],
83
- "devDependencies": {
84
- "@types/react": "^19.2.9",
85
- "react": "^19.2.4",
86
- "typescript": "^5.9.3"
87
- }
88
- }
1
+ {
2
+ "name": "@wirunrom/hqr-generate",
3
+ "version": "0.5.0",
4
+ "description": "High-performance QR code generator and decoder powered by Rust + WASM",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/wirunrom/hqr-generate.git"
10
+ },
11
+ "homepage": "https://github.com/wirunrom/hqr-generate#readme",
12
+ "files": [
13
+ "pkg/**",
14
+ "index.node.js",
15
+ "index.web.js",
16
+ "index.d.ts",
17
+ "index.web.d.ts",
18
+ "react/**",
19
+ "LICENSE",
20
+ "README.md"
21
+ ],
22
+ "types": "./index.d.ts",
23
+ "main": "./index.node.js",
24
+ "module": "./index.web.js",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./index.d.ts",
28
+ "import": "./index.web.js",
29
+ "require": "./index.node.js",
30
+ "browser": "./index.web.js",
31
+ "node": "./index.node.js",
32
+ "default": "./index.web.js"
33
+ },
34
+ "./react": {
35
+ "types": "./react/index.d.ts",
36
+ "default": "./react/index.js"
37
+ },
38
+ "./web": {
39
+ "types": "./index.d.ts",
40
+ "default": "./index.web.js"
41
+ }
42
+ },
43
+ "peerDependencies": {
44
+ "react": ">=17"
45
+ },
46
+ "peerDependenciesMeta": {
47
+ "react": {
48
+ "optional": true
49
+ }
50
+ },
51
+ "scripts": {
52
+ "clean": "rm -rf pkg",
53
+ "build:web": "wasm-pack build --target web --out-dir pkg/web -- --features wasm,decode",
54
+ "build:node": "wasm-pack build --target nodejs --out-dir pkg/nodejs -- --features wasm,decode",
55
+ "build:react": "tsc -p tsconfig.react.json",
56
+ "build": "npm run build:web && npm run build:node && npm run build:react",
57
+ "prepack": "npm run clean && npm run build && find pkg \\( -name README.md -o -name LICENSE -o -name package.json -o -name .gitignore \\) -delete",
58
+ "bench": "cargo bench --bench generate",
59
+ "release:test": "npm version prerelease --preid=next && npm run publish:test",
60
+ "publish:test": "npm publish --tag next --registry=https://registry.npmjs.org --access public",
61
+ "publish:npm": "npm publish --registry=https://registry.npmjs.org --access public",
62
+ "publish:github": "npm publish --registry=https://npm.pkg.github.com --userconfig .npmrc.github --access public",
63
+ "postpublish": "git push --follow-tags"
64
+ },
65
+ "keywords": [
66
+ "qrcode",
67
+ "qr",
68
+ "qr-decode",
69
+ "rust",
70
+ "wasm",
71
+ "webassembly",
72
+ "react",
73
+ "nextjs",
74
+ "ssr",
75
+ "browser",
76
+ "vanilla-js",
77
+ "png",
78
+ "svg",
79
+ "uint8array",
80
+ "binary",
81
+ "blob",
82
+ "performance",
83
+ "scan-reliability"
84
+ ],
85
+ "devDependencies": {
86
+ "@types/react": "^19.2.9",
87
+ "react": "^19.2.4",
88
+ "typescript": "^5.9.3"
89
+ }
90
+ }
@@ -88,31 +88,30 @@ function generate_svg(text, size, margin, ecc) {
88
88
  }
89
89
  }
90
90
  exports.generate_svg = generate_svg;
91
-
92
91
  function __wbg_get_imports() {
93
92
  const import0 = {
94
93
  __proto__: null,
95
- __wbg___wbindgen_debug_string_0bc8482c6e3508ae: function(arg0, arg1) {
94
+ __wbg___wbindgen_debug_string_ab4b34d23d6778bd: function(arg0, arg1) {
96
95
  const ret = debugString(arg1);
97
96
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
98
97
  const len1 = WASM_VECTOR_LEN;
99
98
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
100
99
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
101
100
  },
102
- __wbg___wbindgen_number_get_8ff4255516ccad3e: function(arg0, arg1) {
101
+ __wbg___wbindgen_number_get_c7f42aed0525c451: function(arg0, arg1) {
103
102
  const obj = arg1;
104
103
  const ret = typeof(obj) === 'number' ? obj : undefined;
105
104
  getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
106
105
  getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
107
106
  },
108
- __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
107
+ __wbg___wbindgen_throw_6b64449b9b9ed33c: function(arg0, arg1) {
109
108
  throw new Error(getStringFromWasm0(arg0, arg1));
110
109
  },
111
- __wbg_get_b3ed3ad4be2bc8ac: function() { return handleError(function (arg0, arg1) {
110
+ __wbg_get_6011fa3a58f61074: function() { return handleError(function (arg0, arg1) {
112
111
  const ret = Reflect.get(arg0, arg1);
113
112
  return ret;
114
113
  }, arguments); },
115
- __wbg_instanceof_Uint8Array_9b9075935c74707c: function(arg0) {
114
+ __wbg_instanceof_Uint8Array_152ba1f289edcf3f: function(arg0) {
116
115
  let result;
117
116
  try {
118
117
  result = arg0 instanceof Uint8Array;
@@ -122,19 +121,19 @@ function __wbg_get_imports() {
122
121
  const ret = result;
123
122
  return ret;
124
123
  },
125
- __wbg_length_32ed9a279acd054c: function(arg0) {
124
+ __wbg_length_9f1775224cf1d815: function(arg0) {
126
125
  const ret = arg0.length;
127
126
  return ret;
128
127
  },
129
- __wbg_new_dd2b680c8bf6ae29: function(arg0) {
128
+ __wbg_new_0c7403db6e782f19: function(arg0) {
130
129
  const ret = new Uint8Array(arg0);
131
130
  return ret;
132
131
  },
133
- __wbg_new_from_slice_a3d2629dc1826784: function(arg0, arg1) {
132
+ __wbg_new_from_slice_b5ea43e23f6008c0: function(arg0, arg1) {
134
133
  const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
135
134
  return ret;
136
135
  },
137
- __wbg_prototypesetcall_bdcdcc5842e4d77d: function(arg0, arg1, arg2) {
136
+ __wbg_prototypesetcall_a6b02eb00b0f4ce2: function(arg0, arg1, arg2) {
138
137
  Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
139
138
  },
140
139
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
@@ -335,5 +334,5 @@ let WASM_VECTOR_LEN = 0;
335
334
  const wasmPath = `${__dirname}/hqr_generate_bg.wasm`;
336
335
  const wasmBytes = require('fs').readFileSync(wasmPath);
337
336
  const wasmModule = new WebAssembly.Module(wasmBytes);
338
- const wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
337
+ let wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
339
338
  wasm.__wbindgen_start();
Binary file
@@ -84,31 +84,30 @@ export function generate_svg(text, size, margin, ecc) {
84
84
  wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
85
85
  }
86
86
  }
87
-
88
87
  function __wbg_get_imports() {
89
88
  const import0 = {
90
89
  __proto__: null,
91
- __wbg___wbindgen_debug_string_0bc8482c6e3508ae: function(arg0, arg1) {
90
+ __wbg___wbindgen_debug_string_ab4b34d23d6778bd: function(arg0, arg1) {
92
91
  const ret = debugString(arg1);
93
92
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
94
93
  const len1 = WASM_VECTOR_LEN;
95
94
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
96
95
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
97
96
  },
98
- __wbg___wbindgen_number_get_8ff4255516ccad3e: function(arg0, arg1) {
97
+ __wbg___wbindgen_number_get_c7f42aed0525c451: function(arg0, arg1) {
99
98
  const obj = arg1;
100
99
  const ret = typeof(obj) === 'number' ? obj : undefined;
101
100
  getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
102
101
  getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
103
102
  },
104
- __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
103
+ __wbg___wbindgen_throw_6b64449b9b9ed33c: function(arg0, arg1) {
105
104
  throw new Error(getStringFromWasm0(arg0, arg1));
106
105
  },
107
- __wbg_get_b3ed3ad4be2bc8ac: function() { return handleError(function (arg0, arg1) {
106
+ __wbg_get_6011fa3a58f61074: function() { return handleError(function (arg0, arg1) {
108
107
  const ret = Reflect.get(arg0, arg1);
109
108
  return ret;
110
109
  }, arguments); },
111
- __wbg_instanceof_Uint8Array_9b9075935c74707c: function(arg0) {
110
+ __wbg_instanceof_Uint8Array_152ba1f289edcf3f: function(arg0) {
112
111
  let result;
113
112
  try {
114
113
  result = arg0 instanceof Uint8Array;
@@ -118,19 +117,19 @@ function __wbg_get_imports() {
118
117
  const ret = result;
119
118
  return ret;
120
119
  },
121
- __wbg_length_32ed9a279acd054c: function(arg0) {
120
+ __wbg_length_9f1775224cf1d815: function(arg0) {
122
121
  const ret = arg0.length;
123
122
  return ret;
124
123
  },
125
- __wbg_new_dd2b680c8bf6ae29: function(arg0) {
124
+ __wbg_new_0c7403db6e782f19: function(arg0) {
126
125
  const ret = new Uint8Array(arg0);
127
126
  return ret;
128
127
  },
129
- __wbg_new_from_slice_a3d2629dc1826784: function(arg0, arg1) {
128
+ __wbg_new_from_slice_b5ea43e23f6008c0: function(arg0, arg1) {
130
129
  const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
131
130
  return ret;
132
131
  },
133
- __wbg_prototypesetcall_bdcdcc5842e4d77d: function(arg0, arg1, arg2) {
132
+ __wbg_prototypesetcall_a6b02eb00b0f4ce2: function(arg0, arg1, arg2) {
134
133
  Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
135
134
  },
136
135
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
Binary file