@lglab/react-qr-code
Version:
React library to generate QR codes
1,763 lines (1,762 loc) • 43.1 kB
JavaScript
import { forwardRef as e, useCallback as t, useId as n, useImperativeHandle as r, useMemo as i, useRef as a } from "react";
import { Fragment as o, jsx as s, jsxs as c } from "react/jsx-runtime";
//#region src/utils/svg.ts
var l = /\.?0+$/;
function u(e) {
return e.toFixed(7).replace(l, "");
}
var d = (e) => {
let t = e % 360 * (Math.PI / 180), n = Math.max(0, Math.min(100, 50 - 50 * Math.cos(t))), r = Math.max(0, Math.min(100, 50 - 50 * Math.sin(t))), i = Math.max(0, Math.min(100, 50 + 50 * Math.cos(t))), a = Math.max(0, Math.min(100, 50 + 50 * Math.sin(t)));
return {
x1: `${n}%`,
y1: `${r}%`,
x2: `${i}%`,
y2: `${a}%`
};
}, f = (e, t, n, r) => {
let i = n / 2, a = i / 2, o = Math.PI / r, s = "";
for (let n = 0; n < 2 * r; n++) {
let r = n * o - Math.PI / 2, c = n % 2 == 0 ? i : a, l = e + c * Math.cos(r), u = t + c * Math.sin(r);
s += `${n === 0 ? "M" : "L"} ${l},${u} `;
}
return s + "Z";
}, p = (e, t, n, r) => `M ${e} ${t}Q ${e + r} ${t + n / 2}, ${e} ${t + n}Q ${e + n / 2} ${t + n - r}, ${e + n} ${t + n}Q ${e + n - r} ${t + n / 2}, ${e + n} ${t}Q ${e + n / 2} ${t + r}, ${e} ${t}Z`, m = .15, h = .1, g = .7, _ = 4, v = (e, t, n) => {
let r = n * m, i = n * h, a = n - r * 2, o = `M${e},${t + r}h${n}v${a}h${-n}Z`, s = n * g, c = e + (n - s) / 2, l = (s - i) / 3;
return o + Array.from({ length: _ }, (e, a) => {
let o = c + l * a;
return `M${o},${t}h${i}v${r}h${-i}ZM${o},${t + n - r}h${i}v${r}h${-i}Z`;
}).join("");
}, y = (e, t, n) => {
let r = n / 8;
return `M ${e + n} ${t + r * 3}
V ${t + r}
h -${r}
V ${t}
H ${e + r * 5}
v ${r}
H ${e + r * 3}
V ${t}
H ${e + r}
v ${r}
H ${e}
v ${r * 2}
h ${r}
v ${r * 2}
H ${e}
v ${r * 2}
h ${r}
v ${r}
h ${r * 2}
v -${r}
h ${r * 2}
v ${r}
h ${r * 2}
v -${r}
h ${r}
V ${t + r * 5}
h -${r}
V ${t + r * 3}
h ${r}
Z`;
}, b = (e, t, n) => {
let r = !1, i = 0;
return [
"M",
1,
.3262506,
"c",
0,
.0383376,
-.0064626,
.0758377,
-.0193751,
.1125001,
"s",
-.0356247,
.076875,
-.0681248,
.1206252,
"c",
-.0325,
.0437499,
-.0762503,
.0931247,
-.1312501,
.1481249,
"C",
.7262502,
.7625008,
.6566626,
.8279132,
.5724999,
.9037505,
"L",
.5,
.9687506,
"L",
.4275001,
.9037505,
"C",
.3433374,
.8279132,
.2737499,
.7625005,
.21875,
.7075007,
"C",
.1637501,
.6525008,
.1199999,
.6031258,
.0874999,
.5593758,
"S",
.0322876,
.4754133,
.0193751,
.4387506,
"S",
0,
.3645881,
0,
.3262506,
"c",
0,
-.0783374,
.0262499,
-.1437498,
.07875,
-.1962499,
"s",
.1179124,
-.07875,
.1962499,
-.07875,
"c",
.0433376,
0,
.0845875,
.0091625,
.12375,
.0274999,
"S",
.4716623,
.1229131,
.5,
.1562506,
"c",
.0283374,
-.0333375,
.0620874,
-.0591625,
.1012502,
-.0775,
"c",
.0391627,
-.0183375,
.0804126,
-.0274999,
.12375,
-.0274999,
"c",
.0783374,
0,
.1437497,
.0262499,
.1962501,
.07875,
"S",
1,
.2479131,
1,
.3262506,
"z"
].map((a) => typeof a == "string" ? (i = 0, r = a.toUpperCase() == a, a) : (i++, a *= n, r && (a += i % 2 == 1 ? e : t), u(a))).join(" ");
}, x = { "data-testid": "background" }, S = ({ background: e, bgGradientId: t, numCells: n }) => {
if (!e) return null;
if (typeof e == "string") return /* @__PURE__ */ s("path", {
fill: e,
d: `M0,0 h${n}v${n}H0z`,
...x
});
let r = d(e?.rotation || 0);
return /* @__PURE__ */ c(o, { children: [/* @__PURE__ */ s("defs", { children: e.type === "linear" ? /* @__PURE__ */ s("linearGradient", {
id: t,
gradientUnits: "userSpaceOnUse",
...r,
children: e.stops?.map((e, t) => /* @__PURE__ */ s("stop", {
offset: e.offset,
stopColor: e.color
}, t))
}) : /* @__PURE__ */ s("radialGradient", {
id: t,
gradientUnits: "userSpaceOnUse",
cx: "50%",
cy: "50%",
r: "50%",
children: e.stops?.map((e, t) => /* @__PURE__ */ s("stop", {
offset: e.offset,
stopColor: e.color
}, t))
}) }), /* @__PURE__ */ s("path", {
fill: `url(#${t})`,
d: `M0,0 h${n}v${n}H0z`,
...x
})] });
}, C;
(function(e) {
class t {
static encodeText(e, n) {
let r = C.QrSegment.makeSegments(e);
return t.encodeSegments(r, n);
}
static encodeBinary(e, n) {
let r = C.QrSegment.makeBytes(e);
return t.encodeSegments([r], n);
}
static encodeSegments(e, r, o = 1, s = 40, c = -1, l = !0) {
if (!(t.MIN_VERSION <= o && o <= s && s <= t.MAX_VERSION) || c < -1 || c > 7) throw RangeError("Invalid value");
let u, d;
for (u = o;; u++) {
let n = t.getNumDataCodewords(u, r) * 8, i = a.getTotalBits(e, u);
if (i <= n) {
d = i;
break;
}
if (u >= s) throw RangeError("Data too long");
}
for (let e of [
t.Ecc.MEDIUM,
t.Ecc.QUARTILE,
t.Ecc.HIGH
]) l && d <= t.getNumDataCodewords(u, e) * 8 && (r = e);
let f = [];
for (let t of e) {
n(t.mode.modeBits, 4, f), n(t.numChars, t.mode.numCharCountBits(u), f);
for (let e of t.getData()) f.push(e);
}
i(f.length == d);
let p = t.getNumDataCodewords(u, r) * 8;
i(f.length <= p), n(0, Math.min(4, p - f.length), f), n(0, (8 - f.length % 8) % 8, f), i(f.length % 8 == 0);
for (let e = 236; f.length < p; e ^= 253) n(e, 8, f);
let m = [];
for (; m.length * 8 < f.length;) m.push(0);
return f.forEach((e, t) => m[t >>> 3] |= e << 7 - (t & 7)), new t(u, r, m, c);
}
constructor(e, n, r, a) {
if (this.version = e, this.errorCorrectionLevel = n, this.modules = [], this.isFunction = [], e < t.MIN_VERSION || e > t.MAX_VERSION) throw RangeError("Version value out of range");
if (a < -1 || a > 7) throw RangeError("Mask value out of range");
this.size = e * 4 + 17;
let o = [];
for (let e = 0; e < this.size; e++) o.push(!1);
for (let e = 0; e < this.size; e++) this.modules.push(o.slice()), this.isFunction.push(o.slice());
this.drawFunctionPatterns();
let s = this.addEccAndInterleave(r);
if (this.drawCodewords(s), a == -1) {
let e = 1e9;
for (let t = 0; t < 8; t++) {
this.applyMask(t), this.drawFormatBits(t);
let n = this.getPenaltyScore();
n < e && (a = t, e = n), this.applyMask(t);
}
}
i(0 <= a && a <= 7), this.mask = a, this.applyMask(a), this.drawFormatBits(a), this.isFunction = [];
}
getModule(e, t) {
return 0 <= e && e < this.size && 0 <= t && t < this.size && this.modules[t][e];
}
getModules() {
return this.modules;
}
drawFunctionPatterns() {
for (let e = 0; e < this.size; e++) this.setFunctionModule(6, e, e % 2 == 0), this.setFunctionModule(e, 6, e % 2 == 0);
this.drawFinderPattern(3, 3), this.drawFinderPattern(this.size - 4, 3), this.drawFinderPattern(3, this.size - 4);
let e = this.getAlignmentPatternPositions(), t = e.length;
for (let n = 0; n < t; n++) for (let r = 0; r < t; r++) n == 0 && r == 0 || n == 0 && r == t - 1 || n == t - 1 && r == 0 || this.drawAlignmentPattern(e[n], e[r]);
this.drawFormatBits(0), this.drawVersion();
}
drawFormatBits(e) {
let t = this.errorCorrectionLevel.formatBits << 3 | e, n = t;
for (let e = 0; e < 10; e++) n = n << 1 ^ (n >>> 9) * 1335;
let a = (t << 10 | n) ^ 21522;
i(!(a >>> 15));
for (let e = 0; e <= 5; e++) this.setFunctionModule(8, e, r(a, e));
this.setFunctionModule(8, 7, r(a, 6)), this.setFunctionModule(8, 8, r(a, 7)), this.setFunctionModule(7, 8, r(a, 8));
for (let e = 9; e < 15; e++) this.setFunctionModule(14 - e, 8, r(a, e));
for (let e = 0; e < 8; e++) this.setFunctionModule(this.size - 1 - e, 8, r(a, e));
for (let e = 8; e < 15; e++) this.setFunctionModule(8, this.size - 15 + e, r(a, e));
this.setFunctionModule(8, this.size - 8, !0);
}
drawVersion() {
if (this.version < 7) return;
let e = this.version;
for (let t = 0; t < 12; t++) e = e << 1 ^ (e >>> 11) * 7973;
let t = this.version << 12 | e;
i(!(t >>> 18));
for (let e = 0; e < 18; e++) {
let n = r(t, e), i = this.size - 11 + e % 3, a = Math.floor(e / 3);
this.setFunctionModule(i, a, n), this.setFunctionModule(a, i, n);
}
}
drawFinderPattern(e, t) {
for (let n = -4; n <= 4; n++) for (let r = -4; r <= 4; r++) {
let i = Math.max(Math.abs(r), Math.abs(n)), a = e + r, o = t + n;
0 <= a && a < this.size && 0 <= o && o < this.size && this.setFunctionModule(a, o, i != 2 && i != 4);
}
}
drawAlignmentPattern(e, t) {
for (let n = -2; n <= 2; n++) for (let r = -2; r <= 2; r++) this.setFunctionModule(e + r, t + n, Math.max(Math.abs(r), Math.abs(n)) != 1);
}
setFunctionModule(e, t, n) {
this.modules[t][e] = n, this.isFunction[t][e] = !0;
}
addEccAndInterleave(e) {
let n = this.version, r = this.errorCorrectionLevel;
if (e.length != t.getNumDataCodewords(n, r)) throw RangeError("Invalid argument");
let a = t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][n], o = t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][n], s = Math.floor(t.getNumRawDataModules(n) / 8), c = a - s % a, l = Math.floor(s / a), u = [], d = t.reedSolomonComputeDivisor(o);
for (let n = 0, r = 0; n < a; n++) {
let i = e.slice(r, r + l - o + (n < c ? 0 : 1));
r += i.length;
let a = t.reedSolomonComputeRemainder(i, d);
n < c && i.push(0), u.push(i.concat(a));
}
let f = [];
for (let e = 0; e < u[0].length; e++) u.forEach((t, n) => {
(e != l - o || n >= c) && f.push(t[e]);
});
return i(f.length == s), f;
}
drawCodewords(e) {
if (e.length != Math.floor(t.getNumRawDataModules(this.version) / 8)) throw RangeError("Invalid argument");
let n = 0;
for (let t = this.size - 1; t >= 1; t -= 2) {
t == 6 && (t = 5);
for (let i = 0; i < this.size; i++) for (let a = 0; a < 2; a++) {
let o = t - a, s = t + 1 & 2 ? i : this.size - 1 - i;
!this.isFunction[s][o] && n < e.length * 8 && (this.modules[s][o] = r(e[n >>> 3], 7 - (n & 7)), n++);
}
}
i(n == e.length * 8);
}
applyMask(e) {
if (e < 0 || e > 7) throw RangeError("Mask value out of range");
for (let t = 0; t < this.size; t++) for (let n = 0; n < this.size; n++) {
let r;
switch (e) {
case 0:
r = (n + t) % 2 == 0;
break;
case 1:
r = t % 2 == 0;
break;
case 2:
r = n % 3 == 0;
break;
case 3:
r = (n + t) % 3 == 0;
break;
case 4:
r = (Math.floor(n / 3) + Math.floor(t / 2)) % 2 == 0;
break;
case 5:
r = n * t % 2 + n * t % 3 == 0;
break;
case 6:
r = (n * t % 2 + n * t % 3) % 2 == 0;
break;
case 7:
r = ((n + t) % 2 + n * t % 3) % 2 == 0;
break;
default: throw Error("Unreachable");
}
!this.isFunction[t][n] && r && (this.modules[t][n] = !this.modules[t][n]);
}
}
getPenaltyScore() {
let e = 0;
for (let n = 0; n < this.size; n++) {
let r = !1, i = 0, a = [
0,
0,
0,
0,
0,
0,
0
];
for (let o = 0; o < this.size; o++) this.modules[n][o] == r ? (i++, i == 5 ? e += t.PENALTY_N1 : i > 5 && e++) : (this.finderPenaltyAddHistory(i, a), r || (e += this.finderPenaltyCountPatterns(a) * t.PENALTY_N3), r = this.modules[n][o], i = 1);
e += this.finderPenaltyTerminateAndCount(r, i, a) * t.PENALTY_N3;
}
for (let n = 0; n < this.size; n++) {
let r = !1, i = 0, a = [
0,
0,
0,
0,
0,
0,
0
];
for (let o = 0; o < this.size; o++) this.modules[o][n] == r ? (i++, i == 5 ? e += t.PENALTY_N1 : i > 5 && e++) : (this.finderPenaltyAddHistory(i, a), r || (e += this.finderPenaltyCountPatterns(a) * t.PENALTY_N3), r = this.modules[o][n], i = 1);
e += this.finderPenaltyTerminateAndCount(r, i, a) * t.PENALTY_N3;
}
for (let n = 0; n < this.size - 1; n++) for (let r = 0; r < this.size - 1; r++) {
let i = this.modules[n][r];
i == this.modules[n][r + 1] && i == this.modules[n + 1][r] && i == this.modules[n + 1][r + 1] && (e += t.PENALTY_N2);
}
let n = 0;
for (let e of this.modules) n = e.reduce((e, t) => e + +!!t, n);
let r = this.size * this.size, a = Math.ceil(Math.abs(n * 20 - r * 10) / r) - 1;
return i(0 <= a && a <= 9), e += a * t.PENALTY_N4, i(0 <= e && e <= 2568888), e;
}
getAlignmentPatternPositions() {
if (this.version == 1) return [];
{
let e = Math.floor(this.version / 7) + 2, t = this.version == 32 ? 26 : Math.ceil((this.version * 4 + 4) / (e * 2 - 2)) * 2, n = [6];
for (let r = this.size - 7; n.length < e; r -= t) n.splice(1, 0, r);
return n;
}
}
static getNumRawDataModules(e) {
if (e < t.MIN_VERSION || e > t.MAX_VERSION) throw RangeError("Version number out of range");
let n = (16 * e + 128) * e + 64;
if (e >= 2) {
let t = Math.floor(e / 7) + 2;
n -= (25 * t - 10) * t - 55, e >= 7 && (n -= 36);
}
return i(208 <= n && n <= 29648), n;
}
static getNumDataCodewords(e, n) {
return Math.floor(t.getNumRawDataModules(e) / 8) - t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e] * t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e];
}
static reedSolomonComputeDivisor(e) {
if (e < 1 || e > 255) throw RangeError("Degree out of range");
let n = [];
for (let t = 0; t < e - 1; t++) n.push(0);
n.push(1);
let r = 1;
for (let i = 0; i < e; i++) {
for (let e = 0; e < n.length; e++) n[e] = t.reedSolomonMultiply(n[e], r), e + 1 < n.length && (n[e] ^= n[e + 1]);
r = t.reedSolomonMultiply(r, 2);
}
return n;
}
static reedSolomonComputeRemainder(e, n) {
let r = n.map((e) => 0);
for (let i of e) {
let e = i ^ r.shift();
r.push(0), n.forEach((n, i) => r[i] ^= t.reedSolomonMultiply(n, e));
}
return r;
}
static reedSolomonMultiply(e, t) {
if (e >>> 8 || t >>> 8) throw RangeError("Byte out of range");
let n = 0;
for (let r = 7; r >= 0; r--) n = n << 1 ^ (n >>> 7) * 285, n ^= (t >>> r & 1) * e;
return i(!(n >>> 8)), n;
}
finderPenaltyCountPatterns(e) {
let t = e[1];
i(t <= this.size * 3);
let n = t > 0 && e[2] == t && e[3] == t * 3 && e[4] == t && e[5] == t;
return (n && e[0] >= t * 4 && e[6] >= t ? 1 : 0) + (n && e[6] >= t * 4 && e[0] >= t ? 1 : 0);
}
finderPenaltyTerminateAndCount(e, t, n) {
return e && (this.finderPenaltyAddHistory(t, n), t = 0), t += this.size, this.finderPenaltyAddHistory(t, n), this.finderPenaltyCountPatterns(n);
}
finderPenaltyAddHistory(e, t) {
t[0] == 0 && (e += this.size), t.pop(), t.unshift(e);
}
static {
this.MIN_VERSION = 1;
}
static {
this.MAX_VERSION = 40;
}
static {
this.PENALTY_N1 = 3;
}
static {
this.PENALTY_N2 = 3;
}
static {
this.PENALTY_N3 = 40;
}
static {
this.PENALTY_N4 = 10;
}
static {
this.ECC_CODEWORDS_PER_BLOCK = [
[
-1,
7,
10,
15,
20,
26,
18,
20,
24,
30,
18,
20,
24,
26,
30,
22,
24,
28,
30,
28,
28,
28,
28,
30,
30,
26,
28,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30
],
[
-1,
10,
16,
26,
18,
24,
16,
18,
22,
22,
26,
30,
22,
22,
24,
24,
28,
28,
26,
26,
26,
26,
28,
28,
28,
28,
28,
28,
28,
28,
28,
28,
28,
28,
28,
28,
28,
28,
28,
28,
28
],
[
-1,
13,
22,
18,
26,
18,
24,
18,
22,
20,
24,
28,
26,
24,
20,
30,
24,
28,
28,
26,
30,
28,
30,
30,
30,
30,
28,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30
],
[
-1,
17,
28,
22,
16,
22,
28,
26,
26,
24,
28,
24,
28,
22,
24,
24,
30,
28,
28,
26,
28,
30,
24,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30,
30
]
];
}
static {
this.NUM_ERROR_CORRECTION_BLOCKS = [
[
-1,
1,
1,
1,
1,
1,
2,
2,
2,
2,
4,
4,
4,
4,
4,
6,
6,
6,
6,
7,
8,
8,
9,
9,
10,
12,
12,
12,
13,
14,
15,
16,
17,
18,
19,
19,
20,
21,
22,
24,
25
],
[
-1,
1,
1,
1,
2,
2,
4,
4,
4,
5,
5,
5,
8,
9,
9,
10,
10,
11,
13,
14,
16,
17,
17,
18,
20,
21,
23,
25,
26,
28,
29,
31,
33,
35,
37,
38,
40,
43,
45,
47,
49
],
[
-1,
1,
1,
2,
2,
4,
4,
6,
6,
8,
8,
8,
10,
12,
16,
12,
17,
16,
18,
21,
20,
23,
23,
25,
27,
29,
34,
34,
35,
38,
40,
43,
45,
48,
51,
53,
56,
59,
62,
65,
68
],
[
-1,
1,
1,
2,
4,
4,
4,
5,
6,
8,
8,
11,
11,
16,
16,
18,
16,
19,
21,
25,
25,
25,
34,
30,
32,
35,
37,
40,
42,
45,
48,
51,
54,
57,
60,
63,
66,
70,
74,
77,
81
]
];
}
}
e.QrCode = t;
function n(e, t, n) {
if (t < 0 || t > 31 || e >>> t) throw RangeError("Value out of range");
for (let r = t - 1; r >= 0; r--) n.push(e >>> r & 1);
}
function r(e, t) {
return !!(e >>> t & 1);
}
function i(e) {
if (!e) throw Error("Assertion error");
}
class a {
static makeBytes(e) {
let t = [];
for (let r of e) n(r, 8, t);
return new a(a.Mode.BYTE, e.length, t);
}
static makeNumeric(e) {
if (!a.isNumeric(e)) throw RangeError("String contains non-numeric characters");
let t = [];
for (let r = 0; r < e.length;) {
let i = Math.min(e.length - r, 3);
n(parseInt(e.substring(r, r + i), 10), i * 3 + 1, t), r += i;
}
return new a(a.Mode.NUMERIC, e.length, t);
}
static makeAlphanumeric(e) {
if (!a.isAlphanumeric(e)) throw RangeError("String contains unencodable characters in alphanumeric mode");
let t = [], r;
for (r = 0; r + 2 <= e.length; r += 2) {
let i = a.ALPHANUMERIC_CHARSET.indexOf(e.charAt(r)) * 45;
i += a.ALPHANUMERIC_CHARSET.indexOf(e.charAt(r + 1)), n(i, 11, t);
}
return r < e.length && n(a.ALPHANUMERIC_CHARSET.indexOf(e.charAt(r)), 6, t), new a(a.Mode.ALPHANUMERIC, e.length, t);
}
static makeSegments(e) {
return e == "" ? [] : a.isNumeric(e) ? [a.makeNumeric(e)] : a.isAlphanumeric(e) ? [a.makeAlphanumeric(e)] : [a.makeBytes(a.toUtf8ByteArray(e))];
}
static makeEci(e) {
let t = [];
if (e < 0) throw RangeError("ECI assignment value out of range");
if (e < 128) n(e, 8, t);
else if (e < 16384) n(2, 2, t), n(e, 14, t);
else if (e < 1e6) n(6, 3, t), n(e, 21, t);
else throw RangeError("ECI assignment value out of range");
return new a(a.Mode.ECI, 0, t);
}
static isNumeric(e) {
return a.NUMERIC_REGEX.test(e);
}
static isAlphanumeric(e) {
return a.ALPHANUMERIC_REGEX.test(e);
}
constructor(e, t, n) {
if (this.mode = e, this.numChars = t, this.bitData = n, t < 0) throw RangeError("Invalid argument");
this.bitData = n.slice();
}
getData() {
return this.bitData.slice();
}
static getTotalBits(e, t) {
let n = 0;
for (let r of e) {
let e = r.mode.numCharCountBits(t);
if (r.numChars >= 1 << e) return Infinity;
n += 4 + e + r.bitData.length;
}
return n;
}
static toUtf8ByteArray(e) {
e = encodeURI(e);
let t = [];
for (let n = 0; n < e.length; n++) e.charAt(n) == "%" ? (t.push(parseInt(e.substring(n + 1, n + 3), 16)), n += 2) : t.push(e.charCodeAt(n));
return t;
}
static {
this.NUMERIC_REGEX = /^[0-9]*$/;
}
static {
this.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
}
static {
this.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
}
}
e.QrSegment = a;
})(C ||= {}), (function(e) {
let t;
(function(e) {
class t {
static {
this.LOW = new t(0, 1);
}
static {
this.MEDIUM = new t(1, 0);
}
static {
this.QUARTILE = new t(2, 3);
}
static {
this.HIGH = new t(3, 2);
}
constructor(e, t) {
this.ordinal = e, this.formatBits = t;
}
}
e.Ecc = t;
})(t ||= e.QrCode ||= {});
})(C ||= {}), (function(e) {
let t;
(function(e) {
class t {
static {
this.NUMERIC = new t(1, [
10,
12,
14
]);
}
static {
this.ALPHANUMERIC = new t(2, [
9,
11,
13
]);
}
static {
this.BYTE = new t(4, [
8,
16,
16
]);
}
static {
this.KANJI = new t(8, [
8,
10,
12
]);
}
static {
this.ECI = new t(7, [
0,
0,
0
]);
}
constructor(e, t) {
this.modeBits = e, this.numBitsCharCount = t;
}
numCharCountBits(e) {
return this.numBitsCharCount[Math.floor((e + 7) / 17)];
}
}
e.Mode = t;
})(t ||= e.QrSegment ||= {});
})(C ||= {});
var w = C, T = {
L: w.QrCode.Ecc.LOW,
M: w.QrCode.Ecc.MEDIUM,
Q: w.QrCode.Ecc.QUARTILE,
H: w.QrCode.Ecc.HIGH
}, E = .5, D = .5, O = "react-qr-code", k = "react-qr-code-gradient", A = "react-qr-code-bg-gradient", ee = .1, j = [
[
1,
1,
1,
1,
1,
1,
1
],
[
1,
0,
0,
0,
0,
0,
1
],
[
1,
0,
0,
0,
0,
0,
1
],
[
1,
0,
0,
0,
0,
0,
1
],
[
1,
0,
0,
0,
0,
0,
1
],
[
1,
0,
0,
0,
0,
0,
1
],
[
1,
1,
1,
1,
1,
1,
1
]
], M = {
"inpoint-sm": [
0,
90,
-90
],
inpoint: [
0,
90,
-90
],
"inpoint-lg": [
0,
90,
-90
],
"outpoint-sm": [
180,
-90,
90
],
outpoint: [
180,
-90,
90
],
"outpoint-lg": [
180,
-90,
90
],
"leaf-sm": [
0,
90,
-90
],
leaf: [
0,
90,
-90
],
"leaf-lg": [
0,
90,
-90
]
}, N = {
"rounded-sm": 3,
rounded: 4,
"rounded-lg": 5,
"leaf-sm": 3,
leaf: 4,
"leaf-lg": 5,
"inpoint-sm": 3,
inpoint: 4,
"inpoint-lg": 5,
"outpoint-sm": 3,
outpoint: 4,
"outpoint-lg": 5
}, P = {
square: 0,
diamond: 0,
circle: 3,
"rounded-sm": .5,
rounded: .9,
"rounded-lg": 1.1,
"leaf-sm": 1.5,
leaf: 2,
"leaf-lg": 2.3,
"inpoint-sm": 1.5,
inpoint: 2,
"inpoint-lg": 2.3,
"outpoint-sm": 1.5,
outpoint: 2,
"outpoint-lg": 2.3
}, F = [
[
0,
0,
0,
0,
0,
0,
0
],
[
0,
0,
0,
0,
0,
0,
0
],
[
0,
0,
1,
1,
1,
0,
0
],
[
0,
0,
1,
1,
1,
0,
0
],
[
0,
0,
1,
1,
1,
0,
0
],
[
0,
0,
0,
0,
0,
0,
0
],
[
0,
0,
0,
0,
0,
0,
0
]
], I = ({ x: e, y: t, numCells: n }) => !!(F[e]?.[t] || F[e - n + 7]?.[t] || F[e]?.[t - n + 7]), te = ({ x: e, y: t, radius: n }) => {
let r = 3 - n, i = n / 2, a = 3 - i;
return `M ${e} ${t + i}v ${r}a ${i} ${i}, 0, 0, 0, ${i} ${i}h ${a}v ${-a}a ${i} ${i}, 0, 0, 0, ${-i} ${-i}h ${-r}H ${e}z`;
}, L = ({ x: e, y: t, radius: n }) => {
let r = 3 - n, i = n / 2, a = 3 - i;
return `M ${e} ${t + i}v ${r}a ${i} ${i}, 0, 0, 0, ${i} ${i}h ${a}v ${-a}a ${i} ${i}, 0, 0, 0, ${-i} ${-i}h ${-r}a ${i} ${i}, 0, 0, 0, ${-i} ${i}`;
}, R = ({ x: e, y: t, numCells: n }) => !!(j[e]?.[t] || j[e - n + 7]?.[t] || j[e]?.[t - n + 7]), ne = ({ x: e, y: t, radius: n }) => {
let r = 7 - n, i = n / 2;
return `M ${e} ${t + i}v ${r}a ${i} ${i}, 0, 0, 0, ${i} ${i}h ${r}a ${i} ${i}, 0, 0, 0, ${i} ${-i}v ${-r}a ${i} ${i}, 0, 0, 0, ${-i} ${-i}h ${-r}a ${i} ${i}, 0, 0, 0, ${-i} ${i}M ${e + i} ${t + 1}h ${r}a ${i - 1} ${i - 1}, 0, 0, 1, ${i - 1} ${i - 1}v ${r}a ${i - 1} ${i - 1}, 0, 0, 1, ${-(i - 1)} ${i - 1}h ${-r}a ${i - 1} ${i - 1}, 0, 0, 1, ${-(i - 1)} ${-(i - 1)}v ${-r}a ${i - 1} ${i - 1}, 0, 0, 1, ${i - 1} ${-(i - 1)}`;
}, re = ({ x: e, y: t, radius: n }) => {
let r = 7 - n, i = n / 2, a = 7 - i;
return `M ${e} ${t + i}v ${r}a ${i} ${i}, 0, 0, 0, ${i} ${i}h ${a}v ${-a}a ${i} ${i}, 0, 0, 0, ${-i} ${-i}h ${-r}H ${e}zM ${e + i} ${t + 1}h ${r}a ${i - 1} ${i - 1}, 0, 0, 1, ${i - 1} ${i - 1}v ${a - 1}h ${-(a - 1)}a ${i - 1} ${i - 1}, 0, 0, 1, ${-(i - 1)} ${-(i - 1)}v ${-(a - 1)}z`;
}, ie = ({ x: e, y: t, radius: n }) => {
let r = 7 - n, i = n / 2, a = 7 - i;
return `M ${e} ${t + i}v ${r}a ${i} ${i}, 0, 0, 0, ${i} ${i}h ${a}v ${-a}a ${i} ${i}, 0, 0, 0, ${-i} ${-i}h ${-r}a ${i} ${i}, 0, 0, 0, ${-i} ${i}M ${e + i} ${t + 1}h ${r}a ${i - 1} ${i - 1}, 0, 0, 1, ${i - 1} ${i - 1}v ${a - 1}h ${-(a - 1)}a ${i - 1} ${i - 1}, 0, 0, 1, ${-(i - 1)} ${-(i - 1)}v ${-r}a ${i - 1} ${i - 1}, 0, 0, 1, ${i - 1} ${-(i - 1)}`;
}, z = (e) => e === "square" || e === "pinched-square" || e === "circle" || e === "star" || e === "heart" || e === "diamond" || e === "hashtag", ae = (e) => {
let t = 2166136261;
return e.forEach((e) => {
e.forEach((e) => {
t = Math.imul(t ^ +!!e, 16777619);
});
}), t >>> 0;
}, oe = (e, t, n) => {
let r = (n ^ Math.imul(e, 668265261) ^ Math.imul(t, 374761393)) >>> 0;
return r = Math.imul(r ^ r >>> 15, 739982445) >>> 0, r = Math.imul(r ^ r >>> 13, 695872825) >>> 0, ((r ^ r >>> 16) >>> 0) / 4294967296;
}, se = (e, t, n = 1, r = 0, i = 0, a = 0) => e === "square-sm" ? .75 : t ? oe(r, i, a) * .25 + .75 : z(e) ? n : 1, B = (e, t, n) => {
let r = {
left: e !== 0 && n[t][e - 1],
right: e !== n[t].length - 1 && n[t][e + 1],
top: t !== 0 && n[t - 1][e],
bottom: t !== n.length - 1 && n[t + 1][e]
};
return {
...r,
count: Object.values(r).filter(Boolean).length
};
}, V = ({ x: e, y: t, modules: n, numCells: r }) => t >= 0 && t < n.length && e >= 0 && e < n[t].length && n[t][e] && !R({
x: e,
y: t,
numCells: r
}) && !I({
x: e,
y: t,
numCells: r
}), ce = (e, t, n, r) => {
let i = {
left: V({
x: e - 1,
y: t,
modules: n,
numCells: r
}),
right: V({
x: e + 1,
y: t,
modules: n,
numCells: r
}),
top: V({
x: e,
y: t - 1,
modules: n,
numCells: r
}),
bottom: V({
x: e,
y: t + 1,
modules: n,
numCells: r
})
};
return {
...i,
count: Object.values(i).filter(Boolean).length
};
}, H = (e, t, n, r) => `M${e},${t}h${n}v${r}h${-n}Z`, U = (e, t, n) => H(e, t, n, n), W = (e, t, n) => `M${e},${t + n / 2}a${n / 2},${n / 2} 0 1,0 ${n},0a${n / 2},${n / 2} 0 1,0 -${n},0Z`, le = (e, t, n) => `M${e},${t + n / 2}l${n / 2},-${n / 2}l${n / 2},${n / 2}l-${n / 2},${n / 2}Z`, ue = (e, t, n) => `M${e - n},${t}a${n},${n} 0 1,1 ${n * 2},0a${n},${n} 0 1,1 ${-n * 2},0Z`, de = ({ count: e }) => e === 1, fe = (e, t) => `M ${e} ${t}
v 1
h 1
v -0.5
a 0.5 0.5, 0, 0, 0, -0.5 -0.5`, G = (e, t) => `M ${e + 1} ${t}
v 1
h -1
v -0.5
a 0.5 0.5, 0, 0, 1, 0.5 -0.5`, K = (e, t) => `M ${e} ${t}
v 1
h 0.5
a 0.5 0.5, 0, 0, 0, 0.5 -0.5
v -0.5
h -1`, pe = (e, t) => `M ${e + 1} ${t}
v 1
h -0.5
a 0.5 0.5, 0, 0, 1, -0.5 -0.5
v -0.5
h 1`, q = (e, t, n = 1) => {
let r = t + .5, i = n / 2, a = 1 - i;
return `M ${e} ${r - i}
v ${n}
h ${a}
a ${i} ${i}, 0, 0, 0, 0 -${n}`;
}, J = (e, t, n = 1) => {
let r = t + .5, i = n / 2, a = 1 - i;
return `M ${e + 1} ${r - i}
v ${n}
h -${a}
a ${i} ${i}, 0, 0, 1, 0 -${n}`;
}, Y = (e, t, n = 1) => {
let r = e + .5, i = n / 2, a = 1 - i;
return `M ${r - i} ${t + 1}
h ${n}
v -${a}
a ${i} ${i}, 0, 0, 0, -${n} 0`;
}, X = (e, t, n = 1) => {
let r = e + .5, i = n / 2, a = 1 - i;
return `M ${r - i} ${t}
h ${n}
v ${a}
a ${i} ${i}, 0, 0, 1, -${n} 0`;
}, me = (e, t, n, r) => {
let { left: i, right: a, top: o, bottom: s } = r, c = e + .5, l = t + .5, u = n / 2, d = !o && !i, f = !o && !a, p = !s && !a, m = !s && !i, h = o ? t : l - u, g = a ? e + 1 : c + u, _ = s ? t + 1 : l + u, v = i ? e : c - u, y = [`M ${d ? c : c - u} ${h}`];
return y.push(`L ${f ? c : c + u} ${h}`), f ? y.push(`A ${u} ${u} 0 0 1 ${c + u} ${l}`) : o && a ? y.push(`L ${c + u} ${l - u} L ${e + 1} ${l - u}`) : o ? y.push(`L ${c + u} ${l - u}`) : a && y.push(`L ${e + 1} ${l - u}`), y.push(`L ${g} ${p ? l : l + u}`), p ? y.push(`A ${u} ${u} 0 0 1 ${c} ${l + u}`) : a && s ? y.push(`L ${c + u} ${l + u} L ${c + u} ${t + 1}`) : a ? y.push(`L ${c + u} ${l + u}`) : s && y.push(`L ${c + u} ${t + 1}`), y.push(`L ${m ? c : c - u} ${_}`), m ? y.push(`A ${u} ${u} 0 0 1 ${c - u} ${l}`) : s && i ? y.push(`L ${c - u} ${l + u} L ${e} ${l + u}`) : s ? y.push(`L ${c - u} ${l + u}`) : i && y.push(`L ${e} ${l + u}`), y.push(`L ${v} ${d ? l : l - u}`), d ? y.push(`A ${u} ${u} 0 0 1 ${c} ${l - u}`) : i && o ? y.push(`L ${c - u} ${l - u} L ${c - u} ${t}`) : i ? y.push(`L ${c - u} ${l - u}`) : o && y.push(`L ${c - u} ${t}`), y.push("Z"), y.join(" ");
}, he = (e, t, n) => `M ${e + 1} ${t}h -${n / 2}a ${n / 2.5} ${n / 2.5}, 0, 0, 0, ${-n / 2.5} ${n / 2.5}v ${n / 2}h ${n / 2}a ${n / 2.5} ${n / 2.5}, 0, 0, 0, ${n / 2.5} ${-n / 2.5}`, ge = (e) => {
let t = e?.style || "square", n = t === "circuit-board" ? E : 1;
return {
color: e?.color || "#000000",
style: t,
randomSize: e?.randomSize || !1,
size: e?.size ?? 1,
lineWidth: e?.lineWidth ?? n
};
}, _e = (e) => ({
color: e?.color || "#000000",
style: e?.style || "square"
}), ve = (e) => ({
color: e?.color || "#000000",
style: e?.style || "square"
}), ye = ({ modules: e, cells: n, margin: r, settings: a, gradient: o, gradientId: c }) => {
let { color: l, style: u, randomSize: d, size: m, lineWidth: h } = i(() => ge(a), [a]), g = [], _ = e.length, v = z(u) && d, x = i(() => v ? ae(n) : 0, [v, n]), S = t((e, t) => se(u, v, m, e, t, x), [
u,
v,
m,
x
]);
e.forEach((t, n) => {
t.forEach((t, i) => {
if (R({
x: i,
y: n,
numCells: _
}) || I({
x: i,
y: n,
numCells: _
})) return;
let a = S(i, n), o = 1 * a, s = (1 - 1 * a) / 2, c = i + r, l = n + r, d = c + s, m = l + s, v = (1 - h) / 2;
if (t) {
if (u === "circuit-board") {
let t = c + .5, r = l + .5, a = h / 2, o = 1 + h, s = ce(i, n, e, _), { right: u, bottom: d, count: f } = s;
if (u && g.push(H(t - a, r - a, o, h)), d && g.push(H(t - a, r - a, h, o)), f === 0) {
let e = .25 / 2;
g.push(U(c + e, l + e, .75));
} else de({
...s,
count: f
}) && g.push(ue(t, r, D));
} else if (u === "square" || u === "square-sm") g.push(U(d, m, o));
else if (u === "pinched-square") g.push(p(d, m, o, .25));
else if (u === "circle") g.push(W(d, m, o));
else if (u === "diamond") g.push(le(d, m, o));
else if (u === "star") g.push(f(d + o / 2, m + o / 2, o * 1.1, 5));
else if (u === "heart") g.push(b(d, m, o));
else if (u === "hashtag") g.push(y(d, m, o));
else if (u === "rounded") {
let t = B(i, n, e), { left: r, right: a, top: o, bottom: s, count: u } = t;
h === 1 ? u === 0 ? g.push(W(d, m, 1)) : u > 2 || r && a || o && s ? g.push(U(d, m, 1)) : u === 2 ? r && o ? g.push(K(d, m)) : o && a ? g.push(pe(d, m)) : a && s ? g.push(G(d, m)) : g.push(fe(d, m)) : o ? g.push(X(d, m)) : a ? g.push(J(d, m)) : s ? g.push(Y(d, m)) : g.push(q(d, m)) : g.push(me(c, l, h, t));
} else if (u === "leaf") {
let { left: t, right: r, top: a, bottom: s, count: c } = B(i, n, e);
if (c === 0) g.push(he(d, m, o));
else if (!t && !a) {
g.push(G(d, m));
return;
} else !r && !s ? g.push(K(d, m)) : g.push(U(d, m, 1));
} else if (u === "vertical-line") {
let { left: t, right: r, top: a, bottom: o, count: s } = B(i, n, e);
s === 0 || t && !(a || o) || r && !(a || o) ? g.push(W(c + v, l + v, h)) : a && o ? g.push(H(c + v, l, h, 1)) : a && !o ? g.push(X(c, l, h)) : o && !a && g.push(Y(c, l, h));
} else if (u === "horizontal-line") {
let { left: t, right: r, top: a, bottom: o, count: s } = B(i, n, e);
s === 0 || a && !(t || r) || o && !(t || r) ? g.push(W(c + v, l + v, h)) : t && r ? g.push(H(c, l + v, 1, h)) : t && !r ? g.push(q(c, l, h)) : r && !t && g.push(J(c, l, h));
}
}
});
});
let C = o ? `url(#${c})` : l;
return /* @__PURE__ */ s("path", {
fill: C,
d: g.join(""),
shapeRendering: u === "square" ? "crispEdges" : "geometricPrecision",
"data-testid": "data-modules"
});
}, Z = { "data-testid": "finder-patterns-inner" }, be = ({ modules: e, margin: t, settings: n, gradient: r, gradientId: a }) => {
let { color: o, style: c } = i(() => ve(n), [n]), l = r ? `url(#${a})` : o, u = i(() => [
{
x: t + 2,
y: t + 2
},
{
x: e.length + t - 7 + 2,
y: t + 2
},
{
x: t + 2,
y: e.length + t - 7 + 2
}
], [t, e.length]), d = (e, t) => `finder-patterns-inner-${c}-${e}-${t}`;
if (c === "rounded-sm" || c === "rounded" || c === "rounded-lg" || c === "circle" || c === "square") return u.map((e) => {
let { x: t, y: n } = e;
return /* @__PURE__ */ s("rect", {
x: t,
y: n,
width: 3,
height: 3,
fill: l,
rx: P[c],
...Z
}, d(t, n));
});
if (c === "pinched-square") return u.map((e) => {
let { x: t, y: n } = e, r = p(t, n, 3, .25);
return /* @__PURE__ */ s("path", {
fill: l,
d: r,
...Z
}, d(t, n));
});
if (c === "diamond") return u.map((e) => {
let { x: t, y: n } = e, r = Math.sqrt(1.5), i = 3 / r, a = i - i / r;
return /* @__PURE__ */ s("rect", {
x: t + a / 2,
y: n + a / 2,
width: i,
height: i,
fill: l,
style: {
transform: "rotate(45deg)",
transformOrigin: "center",
transformBox: "fill-box"
},
...Z
}, d(t, n));
});
if (c === "inpoint-sm" || c === "inpoint" || c === "inpoint-lg" || c === "outpoint-sm" || c === "outpoint" || c === "outpoint-lg" || c === "leaf-sm" || c === "leaf" || c === "leaf-lg") {
let e = c === "leaf-sm" || c === "leaf" || c === "leaf-lg" ? te : L;
return u.map((e, t) => ({
...e,
rotation: M[c][t]
})).map(({ x: t, y: n, rotation: r }) => {
let i = e({
x: t,
y: n,
radius: P[c]
});
return /* @__PURE__ */ s("path", {
fill: l,
d: i,
style: {
transform: `rotate(${r}deg)`,
transformOrigin: "center",
transformBox: "fill-box"
},
...Z
}, d(t, n));
});
}
if (c === "heart") return u.map(({ x: e, y: t }) => /* @__PURE__ */ s("path", {
fill: l,
d: b(e, t, 3),
...Z
}, d(e, t)));
if (c === "star") return u.map(({ x: e, y: t }) => {
let n = f(e + 3 / 2, t + 3 / 2, 3 * 1.2, 5);
return /* @__PURE__ */ s("path", {
fill: l,
d: n,
...Z
}, d(e, t));
});
if (c === "microchip") return u.map(({ x: e, y: t }) => {
let n = v(e, t, 3);
return /* @__PURE__ */ s("path", {
fill: l,
d: n,
...Z
}, d(e, t));
});
if (c === "hashtag") return u.map(({ x: e, y: t }) => {
let n = y(e - .25, t - .25, 3.5);
return /* @__PURE__ */ s("path", {
fill: l,
d: n,
...Z
}, d(e, t));
});
}, Q = { "data-testid": "finder-patterns-outer" }, xe = ({ modules: e, margin: t, settings: n, gradient: r, gradientId: a }) => {
let { style: o, color: c } = i(() => _e(n), [n]), l = r ? `url(#${a})` : c, u = [], d = i(() => [
{
x: t,
y: t
},
{
x: e.length + t - 7,
y: t
},
{
x: t,
y: e.length + t - 7
}
], [t, e.length]);
if ([
"rounded-sm",
"rounded",
"rounded-lg",
"circle",
"square",
"pinched-square"
].includes(o)) {
for (let e of d) {
let { x: t, y: n } = e;
if (o === "rounded-sm" || o === "rounded" || o === "rounded-lg") u.push(ne({
x: t,
y: n,
radius: N[o]
}));
else if (o === "circle") u.push(`M ${t + 7 / 2} ${n}a ${7 / 2} ${7 / 2} 0 1 0 0.01 0zzm 0 1a ${7 / 2 - 1} ${7 / 2 - 1} 0 1 1 -0.01 0Z`);
else if (o === "pinched-square") {
let e = .5, r = 1.25;
u.push(`M ${t} ${n}Q ${t + e} ${n + 7 / 2}, ${t} ${n + 7}Q ${t + 7 / 2} ${n + 7 - e}, ${t + 7} ${n + 7}Q ${t + 7 - e} ${n + 7 / 2}, ${t + 7} ${n}Q ${t + 7 / 2} ${n + e}, ${t} ${n}zM ${t + 1} ${n + 1}Q ${t + 7 / 2} ${n + r}, ${t + 7 - 1} ${n + 1}Q ${t + 7 - r} ${n + 7 / 2}, ${t + 7 - 1} ${n + 7 - 1}Q ${t + 7 / 2} ${n + 7 - r}, ${t + 1} ${n + 7 - 1}Q ${t + r} ${n + 7 / 2}, ${t + 1} ${n + 1}z`);
} else u.push(`M ${t} ${n}v 7h 7v -7zM ${t + 1} ${n + 1}h 5v 5h -5z`);
}
return /* @__PURE__ */ s("path", {
fill: l,
d: u.join(""),
...Q
});
}
if (o === "inpoint-sm" || o === "inpoint" || o === "inpoint-lg" || o === "outpoint-sm" || o === "outpoint" || o === "outpoint-lg" || o === "leaf-sm" || o === "leaf" || o === "leaf-lg") {
let e = o === "leaf-sm" || o === "leaf" || o === "leaf-lg" ? re : ie;
return d.map((e, t) => ({
...e,
rotation: M[o][t]
})).map(({ x: t, y: n, rotation: r }) => {
let i = e({
x: t,
y: n,
radius: N[o]
});
return /* @__PURE__ */ s("path", {
fill: l,
d: i,
style: {
transform: `rotate(${r}deg)`,
transformOrigin: "center",
transformBox: "fill-box"
},
...Q
}, `finder-patterns-outer-${o}-${t}-${n}`);
});
}
}, Se = ({ gradient: e, gradientId: t }) => {
if (!e) return null;
let n = d(e?.rotation || 0);
return /* @__PURE__ */ s("defs", { children: e.type === "linear" ? /* @__PURE__ */ s("linearGradient", {
id: t,
gradientUnits: "userSpaceOnUse",
...n,
children: e.stops?.map((e, t) => /* @__PURE__ */ s("stop", {
offset: e.offset,
stopColor: e.color
}, t))
}) : /* @__PURE__ */ s("radialGradient", {
id: t,
gradientUnits: "userSpaceOnUse",
cx: "50%",
cy: "50%",
r: "50%",
children: e.stops?.map((e, t) => /* @__PURE__ */ s("stop", {
offset: e.offset,
stopColor: e.color
}, t))
}) });
}, Ce = () => {
let e = n();
return {
gradientId: `${k}-${e}`,
bgGradientId: `${A}-${e}`
};
}, we = (e, t) => e.slice().map((e, n) => n < t.y || n >= t.y + t.h ? e : e.map((e, n) => n < t.x || n >= t.x + t.w ? e : !1)), Te = (e, t, n, r) => {
if (r == null) return null;
let i = e.length + n * 2, a = Math.floor(t * ee), o = i / t, s = (r.width || a) * o, c = (r.height || a) * o, l = r.x == null ? e.length / 2 - s / 2 : r.x * o, u = r.y == null ? e.length / 2 - c / 2 : r.y * o, d = r.opacity == null ? 1 : r.opacity, f = null;
if (r.excavate) {
let e = Math.floor(l), t = Math.floor(u);
f = {
x: e,
y: t,
w: Math.ceil(s + l - e),
h: Math.ceil(c + u - t)
};
}
let p = r.crossOrigin;
return {
x: l,
y: u,
h: c,
w: s,
excavation: f,
opacity: d,
crossOrigin: p
};
}, Ee = (e) => e == null ? 4 : Math.max(Math.floor(e), 0), De = ({ value: e, level: t, minVersion: n, marginSize: r, imageSettings: a, size: o, boostLevel: s }) => {
let c = i(() => {
let r = (Array.isArray(e) ? e : [e]).reduce((e, t) => (e.push(...w.QrSegment.makeSegments(t)), e), []);
return w.QrCode.encodeSegments(r, T[t], n, void 0, void 0, s);
}, [
e,
t,
n,
s
]), { cells: l, margin: u, numCells: d, calculatedImageSettings: f } = i(() => {
let e = c.getModules(), t = Ee(r);
return {
cells: e,
margin: t,
numCells: e.length + t * 2,
calculatedImageSettings: Te(e, o, t, a)
};
}, [
c,
o,
a,
r
]);
return {
qrcode: c,
margin: u,
cells: l,
numCells: d,
calculatedImageSettings: f
};
}, Oe = ({ svgRef: e, fileSize: t, fileName: n }) => {
if (!e.current) return;
let r = e.current.cloneNode(!0);
r.setAttribute("width", t.toString()), r.setAttribute("height", t.toString());
let i = new XMLSerializer(), a = new Blob([i.serializeToString(r)], { type: "image/svg+xml" }), o = URL.createObjectURL(a), s = document.createElement("a");
s.href = o, s.download = `${n}.svg`, document.body.appendChild(s), s.click(), document.body.removeChild(s), URL.revokeObjectURL(o);
}, ke = ({ svgRef: e, fileSize: t, fileName: n, fileFormat: r, imageSettings: i, calculatedImageSettings: a, size: o, numCells: s, margin: c }) => {
if (!e.current) return;
let l = document.createElement("canvas"), u = l.getContext("2d");
if (!u) return;
l.width = t, l.height = t;
let d = new XMLSerializer().serializeToString(e.current), f = new Blob([d], { type: "image/svg+xml;charset=utf-8" }), p = URL.createObjectURL(f), m = new Image();
m.crossOrigin = "anonymous", m.src = p, m.onload = () => {
if (u.drawImage(m, 0, 0, t, t), URL.revokeObjectURL(p), i?.src && a) {
let e = new Image();
e.crossOrigin = "anonymous", e.src = i.src, e.onload = () => {
let d = t / o, f = s / t, p = i.width * d, m = i.x ? (a.x + c) / f : (t - p) / 2, h = i.y ? (a.y + c) / f : (t - p) / 2;
u.drawImage(e, m, h, p, p);
let g = r === "png" ? "image/png" : "image/jpeg", _ = document.createElement("a");
_.href = l.toDataURL(g), _.download = `${n}.${r}`, document.body.appendChild(_), _.click(), document.body.removeChild(_);
}, e.onerror = (e) => console.error("Error loading logo:", e);
} else {
let e = r === "png" ? "image/png" : "image/jpeg", t = document.createElement("a");
t.href = l.toDataURL(e), t.download = `${n}.${r}`, document.body.appendChild(t), t.click(), document.body.removeChild(t);
}
}, m.onerror = (e) => console.error("Error loading QR code:", e);
}, $ = e((e, t) => {
let { value: n, size: i = 128, level: o = "M", background: l, gradient: u, minVersion: d = 1, boostLevel: f, marginSize: p, finderPatternOuterSettings: m, finderPatternInnerSettings: h, dataModulesSettings: g, imageSettings: _, svgProps: v } = e, y = a(null), { gradientId: b, bgGradientId: x } = Ce(), { margin: C, cells: w, numCells: T, calculatedImageSettings: E } = De({
value: n,
level: o,
minVersion: d,
boostLevel: f,
marginSize: p,
imageSettings: _,
size: i
});
r(t, () => ({
svg: y.current,
download: ({ name: e = O, format: t = "svg", size: n = 500 }) => {
y.current && (t === "svg" ? Oe({
svgRef: y,
fileSize: n,
fileName: e
}) : ke({
svgRef: y,
fileSize: n,
fileName: e,
fileFormat: t,
imageSettings: _,
calculatedImageSettings: E,
size: i,
numCells: T,
margin: C
}));
}
}));
let D = w, k = null;
_ != null && E != null && (E.excavation != null && (D = we(w, E.excavation)), k = /* @__PURE__ */ s("image", {
href: _.src,
height: E.h,
width: E.w,
x: E.x + C,
y: E.y + C,
preserveAspectRatio: "none",
opacity: E.opacity,
crossOrigin: E.crossOrigin
}));
let A = {
modules: D,
margin: C,
gradient: u,
gradientId: b
};
return /* @__PURE__ */ c("svg", {
height: i,
width: i,
viewBox: `0 0 ${T} ${T}`,
ref: y,
role: "img",
"aria-label": v?.["aria-label"] || "QR Code",
...v,
children: [
/* @__PURE__ */ s(Se, {
gradient: u,
gradientId: b
}),
/* @__PURE__ */ s(S, {
background: l,
bgGradientId: x,
numCells: T
}),
/* @__PURE__ */ s(xe, {
settings: m,
...A
}),
/* @__PURE__ */ s(be, {
settings: h,
...A
}),
/* @__PURE__ */ s(ye, {
settings: g,
cells: w,
...A
}),
k
]
});
});
$.displayName = "ReactQRCode";
//#endregion
export { $ as ReactQRCode };