qr-decoder-js 1.0.0 → 1.0.2
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 +8 -0
- package/README_ZH.md +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/qr-decoder.js +233 -54
- package/dist/qr-decoder.umd.cjs +2 -2
- package/package.json +16 -7
package/README.md
CHANGED
|
@@ -111,3 +111,11 @@ pnpm build # build the package
|
|
|
111
111
|
## License
|
|
112
112
|
|
|
113
113
|
MIT
|
|
114
|
+
|
|
115
|
+
## Acknowledgements
|
|
116
|
+
|
|
117
|
+
This project uses and is inspired by:
|
|
118
|
+
|
|
119
|
+
- [zxing-wasm](https://github.com/Sec-ant/zxing-wasm) for QR code detection.
|
|
120
|
+
- [Google compact_enc_det](https://github.com/google/compact_enc_det) for character encoding detection.
|
|
121
|
+
- [ced-wasm](https://github.com/neichen/ced-wasm), a WebAssembly port of `compact_enc_det`.
|
package/README_ZH.md
CHANGED
|
@@ -107,3 +107,11 @@ pnpm build # 构建 npm 包
|
|
|
107
107
|
## 许可证
|
|
108
108
|
|
|
109
109
|
MIT
|
|
110
|
+
|
|
111
|
+
## 致谢
|
|
112
|
+
|
|
113
|
+
本项目使用或参考了以下开源项目:
|
|
114
|
+
|
|
115
|
+
- [zxing-wasm](https://github.com/Sec-ant/zxing-wasm):用于二维码识别。
|
|
116
|
+
- [Google compact_enc_det](https://github.com/google/compact_enc_det):用于文本编码检测。
|
|
117
|
+
- [ced-wasm](https://github.com/neichen/ced-wasm):`compact_enc_det` 的 WebAssembly 移植版本。
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface DecodeResult {
|
|
|
6
6
|
encoding?: string;
|
|
7
7
|
/** Raw detection result from ced-wasm (e.g. "GBK"); may be empty. */
|
|
8
8
|
detectedEncoding?: string | null;
|
|
9
|
-
/** Preprocess version that matched: original /
|
|
9
|
+
/** Preprocess version that matched: original / dot-matrix-healed-gray / dot-matrix-binary / red-channel / blue-enhanced / blue / green / gray / inverted / quiet-zone / quiet-zone-red / shear-* (incl. shear-*-red). */
|
|
10
10
|
version?: string;
|
|
11
11
|
error?: string;
|
|
12
12
|
}
|
package/dist/qr-decoder.js
CHANGED
|
@@ -744,26 +744,26 @@ async function b(e = {}) {
|
|
|
744
744
|
throw new M(e).init(t, n), Rn(e), j = e, A++, j;
|
|
745
745
|
}, De = () => A, Oe = (e) => {
|
|
746
746
|
throw j ||= e, j;
|
|
747
|
-
}, ke = () => ie(""),
|
|
747
|
+
}, ke = () => ie(""), P = {}, F = (e) => {
|
|
748
748
|
for (; e.length;) {
|
|
749
749
|
var t = e.pop();
|
|
750
750
|
e.pop()(t);
|
|
751
751
|
}
|
|
752
752
|
};
|
|
753
|
-
function
|
|
753
|
+
function I(e) {
|
|
754
754
|
return this.fromWireType(T[e >> 2]);
|
|
755
755
|
}
|
|
756
|
-
var
|
|
756
|
+
var L = {}, R = {}, Ae = {}, je = class extends Error {
|
|
757
757
|
constructor(e) {
|
|
758
758
|
super(e), this.name = "InternalError";
|
|
759
759
|
}
|
|
760
|
-
},
|
|
761
|
-
throw new
|
|
760
|
+
}, Me = (e) => {
|
|
761
|
+
throw new je(e);
|
|
762
762
|
}, z = (e, t, n) => {
|
|
763
|
-
e.forEach((e) =>
|
|
763
|
+
e.forEach((e) => Ae[e] = t);
|
|
764
764
|
function r(t) {
|
|
765
765
|
var r = n(t);
|
|
766
|
-
r.length !== e.length &&
|
|
766
|
+
r.length !== e.length && Me("Mismatched type converter count");
|
|
767
767
|
for (var i = 0; i < e.length; ++i) U(e[i], r[i]);
|
|
768
768
|
}
|
|
769
769
|
var i = Array(t.length), a = [], o = 0;
|
|
@@ -771,15 +771,15 @@ async function b(e = {}) {
|
|
|
771
771
|
let e = t;
|
|
772
772
|
for (let t = 0; t < e.length; ++t) {
|
|
773
773
|
let n = e[t];
|
|
774
|
-
|
|
775
|
-
i[t] =
|
|
774
|
+
R.hasOwnProperty(n) ? i[t] = R[n] : (a.push(n), L.hasOwnProperty(n) || (L[n] = []), L[n].push(() => {
|
|
775
|
+
i[t] = R[n], ++o, o === a.length && r(i);
|
|
776
776
|
}));
|
|
777
777
|
}
|
|
778
778
|
}
|
|
779
779
|
a.length === 0 && r(i);
|
|
780
780
|
}, Ne = (e) => {
|
|
781
|
-
var t =
|
|
782
|
-
delete
|
|
781
|
+
var t = P[e];
|
|
782
|
+
delete P[e];
|
|
783
783
|
var n = t.rawConstructor, r = t.rawDestructor, i = t.fields, a = i.map((e) => e.getterReturnType).concat(i.map((e) => e.setterArgumentType));
|
|
784
784
|
z([e], a, (e) => {
|
|
785
785
|
var a = {};
|
|
@@ -791,7 +791,7 @@ async function b(e = {}) {
|
|
|
791
791
|
read: (e) => o.fromWireType(s(c, e)),
|
|
792
792
|
write: (e, t) => {
|
|
793
793
|
var n = [];
|
|
794
|
-
u(d, e, l.toWireType(n, t)),
|
|
794
|
+
u(d, e, l.toWireType(n, t)), F(n);
|
|
795
795
|
},
|
|
796
796
|
optional: o.optional
|
|
797
797
|
};
|
|
@@ -810,7 +810,7 @@ async function b(e = {}) {
|
|
|
810
810
|
for (i in a) a[i].write(o, t[i]);
|
|
811
811
|
return e !== null && e.push(r, o), o;
|
|
812
812
|
},
|
|
813
|
-
readValueFromPointer:
|
|
813
|
+
readValueFromPointer: I,
|
|
814
814
|
destructorFunction: r
|
|
815
815
|
}];
|
|
816
816
|
});
|
|
@@ -830,13 +830,13 @@ async function b(e = {}) {
|
|
|
830
830
|
function Fe(e, t) {
|
|
831
831
|
let n = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
832
832
|
var r = t.name;
|
|
833
|
-
if (e || H(`type "${r}" must have a positive integer typeid pointer`),
|
|
833
|
+
if (e || H(`type "${r}" must have a positive integer typeid pointer`), R.hasOwnProperty(e)) {
|
|
834
834
|
if (n.ignoreDuplicateRegistrations) return;
|
|
835
835
|
H(`Cannot register type '${r}' twice`);
|
|
836
836
|
}
|
|
837
|
-
if (
|
|
838
|
-
var i =
|
|
839
|
-
delete
|
|
837
|
+
if (R[e] = t, delete Ae[e], L.hasOwnProperty(e)) {
|
|
838
|
+
var i = L[e];
|
|
839
|
+
delete L[e], i.forEach((e) => e());
|
|
840
840
|
}
|
|
841
841
|
}
|
|
842
842
|
function U(e, t) {
|
|
@@ -986,7 +986,7 @@ async function b(e = {}) {
|
|
|
986
986
|
}, ct = {}, lt = (e, t) => {
|
|
987
987
|
for (t === void 0 && H("ptr should not be undefined"); e.baseClass;) t = e.upcast(t), e = e.baseClass;
|
|
988
988
|
return t;
|
|
989
|
-
}, ut = (e, t) => (t = lt(e, t), ct[t]), dt = (e, t) => ((!t.ptrType || !t.ptr) &&
|
|
989
|
+
}, ut = (e, t) => (t = lt(e, t), ct[t]), dt = (e, t) => ((!t.ptrType || !t.ptr) && Me("makeClassHandle requires ptr and ptrType"), !!t.smartPtrType != !!t.smartPtr && Me("Both smartPtrType and smartPtr must be specified"), t.count = { value: 1 }, W(Object.create(e, { $$: {
|
|
990
990
|
value: t,
|
|
991
991
|
writable: !0
|
|
992
992
|
} })));
|
|
@@ -1032,7 +1032,7 @@ async function b(e = {}) {
|
|
|
1032
1032
|
var t;
|
|
1033
1033
|
(t = this.rawDestructor) == null || t.call(this, e);
|
|
1034
1034
|
},
|
|
1035
|
-
readValueFromPointer:
|
|
1035
|
+
readValueFromPointer: I,
|
|
1036
1036
|
fromWireType: ft
|
|
1037
1037
|
});
|
|
1038
1038
|
};
|
|
@@ -1040,7 +1040,7 @@ async function b(e = {}) {
|
|
|
1040
1040
|
this.name = e, this.registeredClass = t, this.isReference = n, this.isConst = r, this.isSmartPointer = i, this.pointeeType = a, this.sharingPolicy = o, this.rawGetPointee = s, this.rawConstructor = c, this.rawShare = l, this.rawDestructor = u, !i && t.baseClass === void 0 ? r ? (this.toWireType = it, this.destructorFunction = null) : (this.toWireType = ot, this.destructorFunction = null) : this.toWireType = at;
|
|
1041
1041
|
}
|
|
1042
1042
|
var ht = (e, t, n) => {
|
|
1043
|
-
i.hasOwnProperty(e) ||
|
|
1043
|
+
i.hasOwnProperty(e) || Me("Replacing nonexistent public symbol"), i[e].overloadTable !== void 0 && n !== void 0 ? i[e].overloadTable[n] = t : (i[e] = t, i[e].argCount = n);
|
|
1044
1044
|
}, G = {}, gt = (e, t, n) => {
|
|
1045
1045
|
e = e.replace(/p/g, "i");
|
|
1046
1046
|
var r = G[e];
|
|
@@ -1076,9 +1076,9 @@ async function b(e = {}) {
|
|
|
1076
1076
|
}, St = (e, t) => {
|
|
1077
1077
|
var n = [], r = {};
|
|
1078
1078
|
function i(e) {
|
|
1079
|
-
if (!r[e] && !
|
|
1080
|
-
if (
|
|
1081
|
-
|
|
1079
|
+
if (!r[e] && !R[e]) {
|
|
1080
|
+
if (Ae[e]) {
|
|
1081
|
+
Ae[e].forEach(i);
|
|
1082
1082
|
return;
|
|
1083
1083
|
}
|
|
1084
1084
|
n.push(e), r[e] = !0;
|
|
@@ -1140,7 +1140,7 @@ async function b(e = {}) {
|
|
|
1140
1140
|
for (var n = 0; n < u; ++n) d[n] = t[n + 2].toWireType(p, n < 0 || arguments.length <= n ? void 0 : arguments[n]), f.push(d[n]);
|
|
1141
1141
|
var a = r(...f);
|
|
1142
1142
|
function o(n) {
|
|
1143
|
-
if (c)
|
|
1143
|
+
if (c) F(p);
|
|
1144
1144
|
else for (var r = s ? 1 : 2; r < t.length; r++) {
|
|
1145
1145
|
var i = r === 1 ? e : d[r - 2];
|
|
1146
1146
|
t[r].destructorFunction !== null && t[r].destructorFunction(i);
|
|
@@ -1213,7 +1213,7 @@ async function b(e = {}) {
|
|
|
1213
1213
|
return jt(e), t;
|
|
1214
1214
|
},
|
|
1215
1215
|
toWireType: (e, t) => Y.toHandle(t),
|
|
1216
|
-
readValueFromPointer:
|
|
1216
|
+
readValueFromPointer: I,
|
|
1217
1217
|
destructorFunction: null
|
|
1218
1218
|
}, Nt = (e) => U(e, Mt), Pt = (e, t) => {
|
|
1219
1219
|
switch (t) {
|
|
@@ -1391,7 +1391,7 @@ async function b(e = {}) {
|
|
|
1391
1391
|
} else E.set(t, o);
|
|
1392
1392
|
return e !== null && e.push(Q, a), a;
|
|
1393
1393
|
},
|
|
1394
|
-
readValueFromPointer:
|
|
1394
|
+
readValueFromPointer: I,
|
|
1395
1395
|
destructorFunction(e) {
|
|
1396
1396
|
Q(e);
|
|
1397
1397
|
}
|
|
@@ -1443,20 +1443,20 @@ async function b(e = {}) {
|
|
|
1443
1443
|
var o = a(r), s = Mn(4 + o + t);
|
|
1444
1444
|
return T[s >> 2] = o / t, i(r, s + 4, o + t), e !== null && e.push(Q, s), s;
|
|
1445
1445
|
},
|
|
1446
|
-
readValueFromPointer:
|
|
1446
|
+
readValueFromPointer: I,
|
|
1447
1447
|
destructorFunction(e) {
|
|
1448
1448
|
Q(e);
|
|
1449
1449
|
}
|
|
1450
1450
|
});
|
|
1451
1451
|
}, on = (e, t, n, r, i, a) => {
|
|
1452
|
-
|
|
1452
|
+
P[e] = {
|
|
1453
1453
|
name: B(t),
|
|
1454
1454
|
rawConstructor: q(n, r),
|
|
1455
1455
|
rawDestructor: q(i, a),
|
|
1456
1456
|
fields: []
|
|
1457
1457
|
};
|
|
1458
1458
|
}, sn = (e, t, n, r, i, a, o, s, c, l) => {
|
|
1459
|
-
|
|
1459
|
+
P[e].fields.push({
|
|
1460
1460
|
fieldName: B(t),
|
|
1461
1461
|
getterReturnType: n,
|
|
1462
1462
|
getter: q(r, i),
|
|
@@ -1476,7 +1476,7 @@ async function b(e = {}) {
|
|
|
1476
1476
|
var t = ln.length;
|
|
1477
1477
|
return ln.push(e), t;
|
|
1478
1478
|
}, dn = (e, t) => {
|
|
1479
|
-
var n =
|
|
1479
|
+
var n = R[e];
|
|
1480
1480
|
return n === void 0 && H(`${t} has unknown type ${xt(e)}`), n;
|
|
1481
1481
|
}, fn = (e, t) => {
|
|
1482
1482
|
for (var n = Array(e), r = 0; r < e; ++r) n[r] = dn(T[t + r * 4 >> 2], `parameter ${r}`);
|
|
@@ -1511,7 +1511,7 @@ async function b(e = {}) {
|
|
|
1511
1511
|
}, _n = (e) => e ? (e = hn(e), Y.toHandle(globalThis[e])) : Y.toHandle(globalThis), vn = (e) => {
|
|
1512
1512
|
e > 9 && (J[e + 1] += 1);
|
|
1513
1513
|
}, yn = (e, t, n, r, i) => ln[e](t, n, r, i), bn = (e) => {
|
|
1514
|
-
|
|
1514
|
+
F(Y.toValue(e)), jt(e);
|
|
1515
1515
|
}, xn = (e, t, n, r) => {
|
|
1516
1516
|
var i = (/* @__PURE__ */ new Date()).getFullYear(), a = new Date(i, 0, 1), o = new Date(i, 6, 1), s = a.getTimezoneOffset(), c = o.getTimezoneOffset(), l = Math.max(s, c);
|
|
1517
1517
|
T[e >> 2] = l * 60, S[t >> 2] = Number(s != c);
|
|
@@ -2145,9 +2145,125 @@ function D(e) {
|
|
|
2145
2145
|
label: "inverted"
|
|
2146
2146
|
}), a;
|
|
2147
2147
|
}
|
|
2148
|
+
function O(e) {
|
|
2149
|
+
let { data: t, width: n, height: r } = e, i = t.length, a = new ImageData(n, r), o = a.data, s = new ImageData(n, r), c = s.data;
|
|
2150
|
+
for (let e = 0; e < i; e += 4) {
|
|
2151
|
+
let n = t[e], r = t[e + 2], i = t[e + 3];
|
|
2152
|
+
o[e] = n, o[e + 1] = n, o[e + 2] = n, o[e + 3] = i;
|
|
2153
|
+
let a = Math.min(255, Math.max(0, 2 * n - r));
|
|
2154
|
+
c[e] = a, c[e + 1] = a, c[e + 2] = a, c[e + 3] = i;
|
|
2155
|
+
}
|
|
2156
|
+
return [{
|
|
2157
|
+
data: a,
|
|
2158
|
+
label: "red-channel"
|
|
2159
|
+
}, {
|
|
2160
|
+
data: s,
|
|
2161
|
+
label: "blue-enhanced"
|
|
2162
|
+
}];
|
|
2163
|
+
}
|
|
2164
|
+
function k(e, t = [
|
|
2165
|
+
{
|
|
2166
|
+
sx: .35,
|
|
2167
|
+
sy: 0
|
|
2168
|
+
},
|
|
2169
|
+
{
|
|
2170
|
+
sx: -.35,
|
|
2171
|
+
sy: 0
|
|
2172
|
+
},
|
|
2173
|
+
{
|
|
2174
|
+
sx: 0,
|
|
2175
|
+
sy: .35
|
|
2176
|
+
},
|
|
2177
|
+
{
|
|
2178
|
+
sx: 0,
|
|
2179
|
+
sy: -.35
|
|
2180
|
+
},
|
|
2181
|
+
{
|
|
2182
|
+
sx: .25,
|
|
2183
|
+
sy: .25
|
|
2184
|
+
},
|
|
2185
|
+
{
|
|
2186
|
+
sx: -.25,
|
|
2187
|
+
sy: -.25
|
|
2188
|
+
}
|
|
2189
|
+
]) {
|
|
2190
|
+
let { width: n, height: r } = e, i = A(n, r);
|
|
2191
|
+
if (!i) return [];
|
|
2192
|
+
let a = i.getContext("2d");
|
|
2193
|
+
if (!a) return [];
|
|
2194
|
+
a.putImageData(e, 0, 0);
|
|
2195
|
+
let o = Math.round(Math.max(n, r) * .25), s = n + o * 2, c = r + o * 2, l = A(s, c);
|
|
2196
|
+
if (!l) return [];
|
|
2197
|
+
let u = l.getContext("2d", { willReadFrequently: !0 });
|
|
2198
|
+
if (!u) return [];
|
|
2199
|
+
let d = [];
|
|
2200
|
+
for (let { sx: e, sy: a } of t) u.setTransform(1, 0, 0, 1, 0, 0), u.fillStyle = "#FFFFFF", u.fillRect(0, 0, s, c), u.translate(s / 2, c / 2), u.transform(1, a, e, 1, 0, 0), u.drawImage(i, -n / 2, -r / 2), d.push({
|
|
2201
|
+
data: u.getImageData(0, 0, s, c),
|
|
2202
|
+
label: `shear-sx${e}-sy${a}`
|
|
2203
|
+
});
|
|
2204
|
+
return d;
|
|
2205
|
+
}
|
|
2206
|
+
function A(e, t) {
|
|
2207
|
+
if (typeof OffscreenCanvas < "u") return new OffscreenCanvas(e, t);
|
|
2208
|
+
if (typeof document < "u" && typeof document.createElement == "function") {
|
|
2209
|
+
let n = document.createElement("canvas");
|
|
2210
|
+
return n.width = e, n.height = t, n;
|
|
2211
|
+
}
|
|
2212
|
+
return null;
|
|
2213
|
+
}
|
|
2214
|
+
function ye(e, t, n) {
|
|
2215
|
+
let r = t * n, i = new Uint8ClampedArray(r), a = new Uint8ClampedArray(r);
|
|
2216
|
+
for (let r = 1; r < n - 1; r++) {
|
|
2217
|
+
let n = r * t;
|
|
2218
|
+
for (let r = 1; r < t - 1; r++) {
|
|
2219
|
+
let a = 255;
|
|
2220
|
+
for (let i = -1; i <= 1; i++) for (let o = -1; o <= 1; o++) {
|
|
2221
|
+
let s = e[n + i * t + (r + o)];
|
|
2222
|
+
s < a && (a = s);
|
|
2223
|
+
}
|
|
2224
|
+
i[n + r] = a;
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
for (let e = 1; e < n - 1; e++) {
|
|
2228
|
+
let n = e * t;
|
|
2229
|
+
for (let e = 1; e < t - 1; e++) {
|
|
2230
|
+
let r = 0;
|
|
2231
|
+
for (let a = -1; a <= 1; a++) for (let o = -1; o <= 1; o++) {
|
|
2232
|
+
let s = i[n + a * t + (e + o)];
|
|
2233
|
+
s > r && (r = s);
|
|
2234
|
+
}
|
|
2235
|
+
a[n + e] = r;
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
for (let r = 0; r < t; r++) a[r] = e[r], a[(n - 1) * t + r] = e[(n - 1) * t + r];
|
|
2239
|
+
for (let r = 0; r < n; r++) a[r * t] = e[r * t], a[r * t + t - 1] = e[r * t + t - 1];
|
|
2240
|
+
return a;
|
|
2241
|
+
}
|
|
2242
|
+
function j(e, t = 135) {
|
|
2243
|
+
let { data: n, width: r, height: i } = e, a = r * i, o = new Uint8ClampedArray(a);
|
|
2244
|
+
for (let e = 0, t = 0; e < n.length; e += 4, t++) o[t] = n[e];
|
|
2245
|
+
let s = 255, c = 0;
|
|
2246
|
+
for (let e = 0; e < a; e++) o[e] < s && (s = o[e]), o[e] > c && (c = o[e]);
|
|
2247
|
+
let l = Math.max(1, c - s);
|
|
2248
|
+
for (let e = 0; e < a; e++) o[e] = (o[e] - s) / l * 255;
|
|
2249
|
+
let u = ye(o, r, i), d = new Uint8ClampedArray(n.length), f = new Uint8ClampedArray(n.length);
|
|
2250
|
+
for (let e = 0, r = 0; e < n.length; e += 4, r++) {
|
|
2251
|
+
let n = u[r];
|
|
2252
|
+
d[e] = n, d[e + 1] = n, d[e + 2] = n, d[e + 3] = 255;
|
|
2253
|
+
let i = u[r] < t ? 0 : 255;
|
|
2254
|
+
f[e] = i, f[e + 1] = i, f[e + 2] = i, f[e + 3] = 255;
|
|
2255
|
+
}
|
|
2256
|
+
return [{
|
|
2257
|
+
data: new ImageData(d, r, i),
|
|
2258
|
+
label: "dot-matrix-healed-gray"
|
|
2259
|
+
}, {
|
|
2260
|
+
data: new ImageData(f, r, i),
|
|
2261
|
+
label: "dot-matrix-binary"
|
|
2262
|
+
}];
|
|
2263
|
+
}
|
|
2148
2264
|
//#endregion
|
|
2149
2265
|
//#region src/core/encoding.js
|
|
2150
|
-
var
|
|
2266
|
+
var be = {
|
|
2151
2267
|
GB: "gbk",
|
|
2152
2268
|
GBK: "gbk",
|
|
2153
2269
|
GB2312: "gb2312",
|
|
@@ -2188,12 +2304,12 @@ var O = {
|
|
|
2188
2304
|
"ISO-2022-JP": "iso-2022-jp",
|
|
2189
2305
|
"ISO-2022-KR": "iso-2022-kr"
|
|
2190
2306
|
};
|
|
2191
|
-
function
|
|
2307
|
+
function M(e) {
|
|
2192
2308
|
if (!e) return "utf-8";
|
|
2193
2309
|
let t = String(e).trim().toUpperCase();
|
|
2194
|
-
return t = t.replace(/\(.*?\)/g, "").trim(),
|
|
2310
|
+
return t = t.replace(/\(.*?\)/g, "").trim(), be[t] ? be[t] : t.replace(/_/g, "-").toLowerCase();
|
|
2195
2311
|
}
|
|
2196
|
-
var
|
|
2312
|
+
var N = [
|
|
2197
2313
|
"utf-8",
|
|
2198
2314
|
"gbk",
|
|
2199
2315
|
"gb18030",
|
|
@@ -2204,8 +2320,8 @@ var A = [
|
|
|
2204
2320
|
"euc-kr",
|
|
2205
2321
|
"windows-1252"
|
|
2206
2322
|
];
|
|
2207
|
-
function
|
|
2208
|
-
let n = [
|
|
2323
|
+
function xe(e, t) {
|
|
2324
|
+
let n = [M(t), ...N], r = [];
|
|
2209
2325
|
for (let e of n) e && !r.includes(e) && r.push(e);
|
|
2210
2326
|
let i = {
|
|
2211
2327
|
text: "",
|
|
@@ -2213,7 +2329,7 @@ function ye(e, t) {
|
|
|
2213
2329
|
encoding: ""
|
|
2214
2330
|
};
|
|
2215
2331
|
for (let t of r) try {
|
|
2216
|
-
let n = new TextDecoder(t, { fatal: !1 }).decode(e), r =
|
|
2332
|
+
let n = new TextDecoder(t, { fatal: !1 }).decode(e), r = Se(n);
|
|
2217
2333
|
r > i.score && (i = {
|
|
2218
2334
|
text: n,
|
|
2219
2335
|
score: r,
|
|
@@ -2222,7 +2338,7 @@ function ye(e, t) {
|
|
|
2222
2338
|
} catch {}
|
|
2223
2339
|
return i;
|
|
2224
2340
|
}
|
|
2225
|
-
function
|
|
2341
|
+
function Se(e) {
|
|
2226
2342
|
if (!e) return -Infinity;
|
|
2227
2343
|
let t = (e.match(/[\u3400-\u4dbf\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af\uf900-\ufaff]/g) || []).length, n = (e.match(/\uFFFD/g) || []).length, r = 0;
|
|
2228
2344
|
for (let t = 0; t < e.length; t++) {
|
|
@@ -2234,7 +2350,7 @@ function j(e) {
|
|
|
2234
2350
|
}
|
|
2235
2351
|
//#endregion
|
|
2236
2352
|
//#region src/core/decoder.js
|
|
2237
|
-
var
|
|
2353
|
+
var Ce = {
|
|
2238
2354
|
formats: ["QRCode"],
|
|
2239
2355
|
tryRotate: !0,
|
|
2240
2356
|
tryInvert: !0,
|
|
@@ -2243,15 +2359,15 @@ var be = {
|
|
|
2243
2359
|
tryDenoise: !0,
|
|
2244
2360
|
maxNumberOfSymbols: 1
|
|
2245
2361
|
};
|
|
2246
|
-
async function
|
|
2362
|
+
async function we(e, t = {}) {
|
|
2247
2363
|
if (!e || typeof e.width != "number" || typeof e.height != "number" || !e.data) return {
|
|
2248
2364
|
success: !1,
|
|
2249
2365
|
error: "Invalid image data (expected ImageData or {width,height,data})"
|
|
2250
2366
|
};
|
|
2251
2367
|
let n = {
|
|
2252
|
-
...
|
|
2368
|
+
...Ce,
|
|
2253
2369
|
...t
|
|
2254
|
-
}, r =
|
|
2370
|
+
}, r = Te(e), i = null, a = null;
|
|
2255
2371
|
for (let e of r) {
|
|
2256
2372
|
let t;
|
|
2257
2373
|
try {
|
|
@@ -2274,11 +2390,11 @@ async function M(e, t = {}) {
|
|
|
2274
2390
|
};
|
|
2275
2391
|
let o = "utf-8", s = null;
|
|
2276
2392
|
try {
|
|
2277
|
-
s = await ve(i), s && (o =
|
|
2393
|
+
s = await ve(i), s && (o = M(s));
|
|
2278
2394
|
} catch (e) {
|
|
2279
2395
|
console.warn("Encoding detection failed, falling back to utf-8", e);
|
|
2280
2396
|
}
|
|
2281
|
-
let c =
|
|
2397
|
+
let c = xe(i, o);
|
|
2282
2398
|
return c.score < 0 ? {
|
|
2283
2399
|
success: !0,
|
|
2284
2400
|
text: new TextDecoder("utf-8").decode(i),
|
|
@@ -2293,34 +2409,97 @@ async function M(e, t = {}) {
|
|
|
2293
2409
|
version: a
|
|
2294
2410
|
};
|
|
2295
2411
|
}
|
|
2296
|
-
|
|
2297
|
-
|
|
2412
|
+
function* Te(e) {
|
|
2413
|
+
yield {
|
|
2414
|
+
data: e,
|
|
2415
|
+
label: "original"
|
|
2416
|
+
};
|
|
2417
|
+
for (let t of j(e)) yield {
|
|
2418
|
+
data: t.data,
|
|
2419
|
+
label: t.label
|
|
2420
|
+
};
|
|
2421
|
+
for (let t of O(e)) yield {
|
|
2422
|
+
data: t.data,
|
|
2423
|
+
label: t.label
|
|
2424
|
+
};
|
|
2425
|
+
for (let t of D(e)) t.label !== "original" && t.label !== "red" && (yield t);
|
|
2426
|
+
let t = null;
|
|
2427
|
+
try {
|
|
2428
|
+
t = De(e);
|
|
2429
|
+
} catch (e) {
|
|
2430
|
+
console.warn("Quiet-zone padding failed, skipping bordered attempts:", e);
|
|
2431
|
+
}
|
|
2432
|
+
if (t) {
|
|
2433
|
+
yield {
|
|
2434
|
+
data: t,
|
|
2435
|
+
label: "quiet-zone"
|
|
2436
|
+
};
|
|
2437
|
+
let [e] = O(t);
|
|
2438
|
+
yield {
|
|
2439
|
+
data: e.data,
|
|
2440
|
+
label: "quiet-zone-red"
|
|
2441
|
+
};
|
|
2442
|
+
}
|
|
2443
|
+
for (let t of k(e)) {
|
|
2444
|
+
yield {
|
|
2445
|
+
data: t.data,
|
|
2446
|
+
label: t.label
|
|
2447
|
+
};
|
|
2448
|
+
let [e] = O(t.data);
|
|
2449
|
+
yield {
|
|
2450
|
+
data: e.data,
|
|
2451
|
+
label: `${t.label}-red`
|
|
2452
|
+
};
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
function Ee(e, t = 40) {
|
|
2456
|
+
let n = Oe(e.width + t * 2, e.height + t * 2);
|
|
2457
|
+
if (!n) return null;
|
|
2458
|
+
let r = n.getContext("2d");
|
|
2459
|
+
return r ? (r.fillStyle = "#FFFFFF", r.fillRect(0, 0, n.width, n.height), r.drawImage(e, t, t), r.getImageData(0, 0, n.width, n.height)) : null;
|
|
2460
|
+
}
|
|
2461
|
+
function De(e, t) {
|
|
2462
|
+
let { width: n, height: r } = e, i = Oe(n, r);
|
|
2463
|
+
if (!i) return null;
|
|
2464
|
+
let a = i.getContext("2d");
|
|
2465
|
+
return a ? (a.putImageData(e, 0, 0), Ee(i, t || Math.max(32, Math.round(n * .1)))) : null;
|
|
2466
|
+
}
|
|
2467
|
+
function Oe(e, t) {
|
|
2468
|
+
if (typeof OffscreenCanvas < "u") return new OffscreenCanvas(e, t);
|
|
2469
|
+
if (typeof document < "u" && typeof document.createElement == "function") {
|
|
2470
|
+
let n = document.createElement("canvas");
|
|
2471
|
+
return n.width = e, n.height = t, n;
|
|
2472
|
+
}
|
|
2473
|
+
return null;
|
|
2474
|
+
}
|
|
2475
|
+
async function ke(e, t = {}) {
|
|
2476
|
+
return e ? we(await P(e), t) : {
|
|
2298
2477
|
success: !1,
|
|
2299
2478
|
error: "No image provided"
|
|
2300
2479
|
};
|
|
2301
2480
|
}
|
|
2302
|
-
async function
|
|
2481
|
+
async function P(e) {
|
|
2303
2482
|
if (typeof ImageData < "u" && e instanceof ImageData || e && typeof e.width == "number" && typeof e.height == "number" && e.data) return e;
|
|
2304
|
-
if (typeof HTMLImageElement < "u" && e instanceof HTMLImageElement) return
|
|
2483
|
+
if (typeof HTMLImageElement < "u" && e instanceof HTMLImageElement) return F(e);
|
|
2305
2484
|
if (typeof HTMLCanvasElement < "u" && e instanceof HTMLCanvasElement || typeof OffscreenCanvas < "u" && e instanceof OffscreenCanvas) return e.getContext("2d").getImageData(0, 0, e.width, e.height);
|
|
2306
|
-
if (typeof Blob < "u" && e instanceof Blob) return
|
|
2485
|
+
if (typeof Blob < "u" && e instanceof Blob) return I(e);
|
|
2307
2486
|
throw TypeError("Unsupported input type; expected File, Blob, ImageData or HTMLImageElement");
|
|
2308
2487
|
}
|
|
2309
|
-
function
|
|
2488
|
+
function F(e) {
|
|
2310
2489
|
let t = document.createElement("canvas");
|
|
2311
2490
|
t.width = e.naturalWidth || e.width, t.height = e.naturalHeight || e.height;
|
|
2312
2491
|
let n = t.getContext("2d", { willReadFrequently: !0 });
|
|
2313
2492
|
return n.drawImage(e, 0, 0), n.getImageData(0, 0, t.width, t.height);
|
|
2314
2493
|
}
|
|
2315
|
-
function
|
|
2494
|
+
function I(e) {
|
|
2316
2495
|
return new Promise((t, n) => {
|
|
2317
2496
|
let r = URL.createObjectURL(e), i = new Image();
|
|
2318
2497
|
i.onload = () => {
|
|
2319
|
-
URL.revokeObjectURL(r), t(
|
|
2498
|
+
URL.revokeObjectURL(r), t(F(i));
|
|
2320
2499
|
}, i.onerror = () => {
|
|
2321
2500
|
URL.revokeObjectURL(r), n(/* @__PURE__ */ Error("Failed to load the image"));
|
|
2322
2501
|
}, i.src = r;
|
|
2323
2502
|
});
|
|
2324
2503
|
}
|
|
2325
2504
|
//#endregion
|
|
2326
|
-
export {
|
|
2505
|
+
export { ke as decodeQRFile, we as decodeQRImageData };
|