@lglab/react-qr-code
Version:
React library to generate QR codes
1,332 lines • 50.6 kB
JavaScript
import { jsx as C, jsxs as K, Fragment as st } from "react/jsx-runtime";
import { useMemo as v, useCallback as it, useId as at, forwardRef as ct, useRef as lt, useImperativeHandle as ht } from "react";
const ut = /\.?0+$/;
function dt(o) {
return o.toFixed(7).replace(ut, "");
}
const W = (o) => {
const a = o % 360 * (Math.PI / 180), c = Math.max(0, Math.min(100, 50 - 50 * Math.cos(a))), i = Math.max(0, Math.min(100, 50 - 50 * Math.sin(a))), r = Math.max(0, Math.min(100, 50 + 50 * Math.cos(a))), u = Math.max(0, Math.min(100, 50 + 50 * Math.sin(a)));
return {
x1: `${c}%`,
y1: `${i}%`,
x2: `${r}%`,
y2: `${u}%`
};
}, J = (o, a, c, i) => {
const r = c / 2, u = r / 2, l = Math.PI / i;
let p = "";
for (let f = 0; f < 2 * i; f++) {
const e = f * l - Math.PI / 2, n = f % 2 === 0 ? r : u, t = o + n * Math.cos(e), s = a + n * Math.sin(e);
p += `${f === 0 ? "M" : "L"} ${t},${s} `;
}
return p + "Z";
}, tt = (o, a, c, i) => `M ${o} ${a}Q ${o + i} ${a + c / 2}, ${o} ${a + c}Q ${o + c / 2} ${a + c - i}, ${o + c} ${a + c}Q ${o + c - i} ${a + c / 2}, ${o + c} ${a}Q ${o + c / 2} ${a + i}, ${o} ${a}Z`, et = (o, a, c) => {
const i = c / 8;
return `M ${o + c} ${a + i * 3}
V ${a + i}
h -${i}
V ${a}
H ${o + i * 5}
v ${i}
H ${o + i * 3}
V ${a}
H ${o + i}
v ${i}
H ${o}
v ${i * 2}
h ${i}
v ${i * 2}
H ${o}
v ${i * 2}
h ${i}
v ${i}
h ${i * 2}
v -${i}
h ${i * 2}
v ${i}
h ${i * 2}
v -${i}
h ${i}
V ${a + i * 5}
h -${i}
V ${a + i * 3}
h ${i}
Z`;
}, ot = (o, a, c) => {
let i = !1, r = 0;
return [
"M",
1,
0.3262506,
"c",
0,
0.0383376,
-64626e-7,
0.0758377,
-0.0193751,
0.1125001,
"s",
-0.0356247,
0.076875,
-0.0681248,
0.1206252,
"c",
-0.0325,
0.0437499,
-0.0762503,
0.0931247,
-0.1312501,
0.1481249,
"C",
0.7262502,
0.7625008,
0.6566626,
0.8279132,
0.5724999,
0.9037505,
"L",
0.5,
0.9687506,
"L",
0.4275001,
0.9037505,
"C",
0.3433374,
0.8279132,
0.2737499,
0.7625005,
0.21875,
0.7075007,
"C",
0.1637501,
0.6525008,
0.1199999,
0.6031258,
0.0874999,
0.5593758,
"S",
0.0322876,
0.4754133,
0.0193751,
0.4387506,
"S",
0,
0.3645881,
0,
0.3262506,
"c",
0,
-0.0783374,
0.0262499,
-0.1437498,
0.07875,
-0.1962499,
"s",
0.1179124,
-0.07875,
0.1962499,
-0.07875,
"c",
0.0433376,
0,
0.0845875,
91625e-7,
0.12375,
0.0274999,
"S",
0.4716623,
0.1229131,
0.5,
0.1562506,
"c",
0.0283374,
-0.0333375,
0.0620874,
-0.0591625,
0.1012502,
-0.0775,
"c",
0.0391627,
-0.0183375,
0.0804126,
-0.0274999,
0.12375,
-0.0274999,
"c",
0.0783374,
0,
0.1437497,
0.0262499,
0.1962501,
0.07875,
"S",
1,
0.2479131,
1,
0.3262506,
"z"
].map((u) => typeof u == "string" ? (r = 0, i = u.toUpperCase() == u, u) : (r++, u = u * c, i && (u += r % 2 == 1 ? o : a), dt(u))).join(" ");
}, Q = {
"data-testid": "background"
}, $t = ({ background: o, bgGradientId: a, numCells: c }) => {
var r, u;
if (!o)
return null;
if (typeof o == "string")
return /* @__PURE__ */ C("path", { fill: o, d: `M0,0 h${c}v${c}H0z`, ...Q });
const i = W((o == null ? void 0 : o.rotation) || 0);
return /* @__PURE__ */ K(st, { children: [
/* @__PURE__ */ C("defs", { children: o.type === "linear" ? /* @__PURE__ */ C("linearGradient", { id: a, gradientUnits: "userSpaceOnUse", ...i, children: (r = o.stops) == null ? void 0 : r.map((l, p) => /* @__PURE__ */ C("stop", { offset: l.offset, stopColor: l.color }, p)) }) : /* @__PURE__ */ C(
"radialGradient",
{
id: a,
gradientUnits: "userSpaceOnUse",
cx: "50%",
cy: "50%",
r: "50%",
children: (u = o.stops) == null ? void 0 : u.map((l, p) => /* @__PURE__ */ C("stop", { offset: l.offset, stopColor: l.color }, p))
}
) }),
/* @__PURE__ */ C(
"path",
{
fill: `url(#${a})`,
d: `M0,0 h${c}v${c}H0z`,
...Q
}
)
] });
};
/**
* @license QR Code generator library (TypeScript)
* Copyright (c) Project Nayuki.
* SPDX-License-Identifier: MIT
*/
var S;
((o) => {
const l = class l {
/*-- Constructor (low level) and fields --*/
// Creates a new QR Code with the given version number,
// error correction level, data codeword bytes, and mask number.
// This is a low-level API that most users should not use directly.
// A mid-level API is the encodeSegments() function.
constructor(e, n, t, s) {
if (this.version = e, this.errorCorrectionLevel = n, this.modules = [], this.isFunction = [], e < l.MIN_VERSION || e > l.MAX_VERSION)
throw new RangeError("Version value out of range");
if (s < -1 || s > 7)
throw new RangeError("Mask value out of range");
this.size = e * 4 + 17;
let h = [];
for (let d = 0; d < this.size; d++)
h.push(!1);
for (let d = 0; d < this.size; d++)
this.modules.push(h.slice()), this.isFunction.push(h.slice());
this.drawFunctionPatterns();
const $ = this.addEccAndInterleave(t);
if (this.drawCodewords($), s == -1) {
let d = 1e9;
for (let R = 0; R < 8; R++) {
this.applyMask(R), this.drawFormatBits(R);
const E = this.getPenaltyScore();
E < d && (s = R, d = E), this.applyMask(R);
}
}
r(0 <= s && s <= 7), this.mask = s, this.applyMask(s), this.drawFormatBits(s), this.isFunction = [];
}
/*-- Static factory functions (high level) --*/
// Returns a QR Code representing the given Unicode text string at the given error correction level.
// As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer
// Unicode code points (not UTF-16 code units) if the low error correction level is used. The smallest possible
// QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the
// ecl argument if it can be done without increasing the version.
static encodeText(e, n) {
const t = o.QrSegment.makeSegments(e);
return l.encodeSegments(t, n);
}
// Returns a QR Code representing the given binary data at the given error correction level.
// This function always encodes using the binary segment mode, not any text mode. The maximum number of
// bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
// The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
static encodeBinary(e, n) {
const t = o.QrSegment.makeBytes(e);
return l.encodeSegments([t], n);
}
/*-- Static factory functions (mid level) --*/
// Returns a QR Code representing the given segments with the given encoding parameters.
// The smallest possible QR Code version within the given range is automatically
// chosen for the output. Iff boostEcl is true, then the ECC level of the result
// may be higher than the ecl argument if it can be done without increasing the
// version. The mask number is either between 0 to 7 (inclusive) to force that
// mask, or -1 to automatically choose an appropriate mask (which may be slow).
// This function allows the user to create a custom sequence of segments that switches
// between modes (such as alphanumeric and byte) to encode text in less space.
// This is a mid-level API; the high-level API is encodeText() and encodeBinary().
static encodeSegments(e, n, t = 1, s = 40, h = -1, $ = !0) {
if (!(l.MIN_VERSION <= t && t <= s && s <= l.MAX_VERSION) || h < -1 || h > 7)
throw new RangeError("Invalid value");
let d, R;
for (d = t; ; d++) {
const m = l.getNumDataCodewords(d, n) * 8, g = u.getTotalBits(e, d);
if (g <= m) {
R = g;
break;
}
if (d >= s)
throw new RangeError("Data too long");
}
for (const m of [l.Ecc.MEDIUM, l.Ecc.QUARTILE, l.Ecc.HIGH])
$ && R <= l.getNumDataCodewords(d, m) * 8 && (n = m);
let E = [];
for (const m of e) {
c(m.mode.modeBits, 4, E), c(m.numChars, m.mode.numCharCountBits(d), E);
for (const g of m.getData())
E.push(g);
}
r(E.length == R);
const A = l.getNumDataCodewords(d, n) * 8;
r(E.length <= A), c(0, Math.min(4, A - E.length), E), c(0, (8 - E.length % 8) % 8, E), r(E.length % 8 == 0);
for (let m = 236; E.length < A; m ^= 253)
c(m, 8, E);
let M = [];
for (; M.length * 8 < E.length; )
M.push(0);
return E.forEach((m, g) => M[g >>> 3] |= m << 7 - (g & 7)), new l(d, n, M, h);
}
/*-- Accessor methods --*/
// Returns the color of the module (pixel) at the given coordinates, which is false
// for light or true for dark. The top left corner has the coordinates (x=0, y=0).
// If the given coordinates are out of bounds, then false (light) is returned.
getModule(e, n) {
return 0 <= e && e < this.size && 0 <= n && n < this.size && this.modules[n][e];
}
// Modified to expose modules for easy access
getModules() {
return this.modules;
}
/*-- Private helper methods for constructor: Drawing function modules --*/
// Reads this object's version field, and draws and marks all function modules.
drawFunctionPatterns() {
for (let t = 0; t < this.size; t++)
this.setFunctionModule(6, t, t % 2 == 0), this.setFunctionModule(t, 6, t % 2 == 0);
this.drawFinderPattern(3, 3), this.drawFinderPattern(this.size - 4, 3), this.drawFinderPattern(3, this.size - 4);
const e = this.getAlignmentPatternPositions(), n = e.length;
for (let t = 0; t < n; t++)
for (let s = 0; s < n; s++)
t == 0 && s == 0 || t == 0 && s == n - 1 || t == n - 1 && s == 0 || this.drawAlignmentPattern(e[t], e[s]);
this.drawFormatBits(0), this.drawVersion();
}
// Draws two copies of the format bits (with its own error correction code)
// based on the given mask and this object's error correction level field.
drawFormatBits(e) {
const n = this.errorCorrectionLevel.formatBits << 3 | e;
let t = n;
for (let h = 0; h < 10; h++)
t = t << 1 ^ (t >>> 9) * 1335;
const s = (n << 10 | t) ^ 21522;
r(s >>> 15 == 0);
for (let h = 0; h <= 5; h++)
this.setFunctionModule(8, h, i(s, h));
this.setFunctionModule(8, 7, i(s, 6)), this.setFunctionModule(8, 8, i(s, 7)), this.setFunctionModule(7, 8, i(s, 8));
for (let h = 9; h < 15; h++)
this.setFunctionModule(14 - h, 8, i(s, h));
for (let h = 0; h < 8; h++)
this.setFunctionModule(this.size - 1 - h, 8, i(s, h));
for (let h = 8; h < 15; h++)
this.setFunctionModule(8, this.size - 15 + h, i(s, h));
this.setFunctionModule(8, this.size - 8, !0);
}
// Draws two copies of the version bits (with its own error correction code),
// based on this object's version field, iff 7 <= version <= 40.
drawVersion() {
if (this.version < 7)
return;
let e = this.version;
for (let t = 0; t < 12; t++)
e = e << 1 ^ (e >>> 11) * 7973;
const n = this.version << 12 | e;
r(n >>> 18 == 0);
for (let t = 0; t < 18; t++) {
const s = i(n, t), h = this.size - 11 + t % 3, $ = Math.floor(t / 3);
this.setFunctionModule(h, $, s), this.setFunctionModule($, h, s);
}
}
// Draws a 9*9 finder pattern including the border separator,
// with the center module at (x, y). Modules can be out of bounds.
drawFinderPattern(e, n) {
for (let t = -4; t <= 4; t++)
for (let s = -4; s <= 4; s++) {
const h = Math.max(Math.abs(s), Math.abs(t)), $ = e + s, d = n + t;
0 <= $ && $ < this.size && 0 <= d && d < this.size && this.setFunctionModule($, d, h != 2 && h != 4);
}
}
// Draws a 5*5 alignment pattern, with the center module
// at (x, y). All modules must be in bounds.
drawAlignmentPattern(e, n) {
for (let t = -2; t <= 2; t++)
for (let s = -2; s <= 2; s++)
this.setFunctionModule(e + s, n + t, Math.max(Math.abs(s), Math.abs(t)) != 1);
}
// Sets the color of a module and marks it as a function module.
// Only used by the constructor. Coordinates must be in bounds.
setFunctionModule(e, n, t) {
this.modules[n][e] = t, this.isFunction[n][e] = !0;
}
/*-- Private helper methods for constructor: Codewords and masking --*/
// Returns a new byte string representing the given data with the appropriate error correction
// codewords appended to it, based on this object's version and error correction level.
addEccAndInterleave(e) {
const n = this.version, t = this.errorCorrectionLevel;
if (e.length != l.getNumDataCodewords(n, t))
throw new RangeError("Invalid argument");
const s = l.NUM_ERROR_CORRECTION_BLOCKS[t.ordinal][n], h = l.ECC_CODEWORDS_PER_BLOCK[t.ordinal][n], $ = Math.floor(l.getNumRawDataModules(n) / 8), d = s - $ % s, R = Math.floor($ / s);
let E = [];
const A = l.reedSolomonComputeDivisor(h);
for (let m = 0, g = 0; m < s; m++) {
let I = e.slice(g, g + R - h + (m < d ? 0 : 1));
g += I.length;
const w = l.reedSolomonComputeRemainder(I, A);
m < d && I.push(0), E.push(I.concat(w));
}
let M = [];
for (let m = 0; m < E[0].length; m++)
E.forEach((g, I) => {
(m != R - h || I >= d) && M.push(g[m]);
});
return r(M.length == $), M;
}
// Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
// data area of this QR Code. Function modules need to be marked off before this is called.
drawCodewords(e) {
if (e.length != Math.floor(l.getNumRawDataModules(this.version) / 8))
throw new RangeError("Invalid argument");
let n = 0;
for (let t = this.size - 1; t >= 1; t -= 2) {
t == 6 && (t = 5);
for (let s = 0; s < this.size; s++)
for (let h = 0; h < 2; h++) {
const $ = t - h, R = (t + 1 & 2) == 0 ? this.size - 1 - s : s;
!this.isFunction[R][$] && n < e.length * 8 && (this.modules[R][$] = i(e[n >>> 3], 7 - (n & 7)), n++);
}
}
r(n == e.length * 8);
}
// XORs the codeword modules in this QR Code with the given mask pattern.
// The function modules must be marked and the codeword bits must be drawn
// before masking. Due to the arithmetic of XOR, calling applyMask() with
// the same mask value a second time will undo the mask. A final well-formed
// QR Code needs exactly one (not zero, two, etc.) mask applied.
applyMask(e) {
if (e < 0 || e > 7)
throw new RangeError("Mask value out of range");
for (let n = 0; n < this.size; n++)
for (let t = 0; t < this.size; t++) {
let s;
switch (e) {
case 0:
s = (t + n) % 2 == 0;
break;
case 1:
s = n % 2 == 0;
break;
case 2:
s = t % 3 == 0;
break;
case 3:
s = (t + n) % 3 == 0;
break;
case 4:
s = (Math.floor(t / 3) + Math.floor(n / 2)) % 2 == 0;
break;
case 5:
s = t * n % 2 + t * n % 3 == 0;
break;
case 6:
s = (t * n % 2 + t * n % 3) % 2 == 0;
break;
case 7:
s = ((t + n) % 2 + t * n % 3) % 2 == 0;
break;
default:
throw new Error("Unreachable");
}
!this.isFunction[n][t] && s && (this.modules[n][t] = !this.modules[n][t]);
}
}
// Calculates and returns the penalty score based on state of this QR Code's current modules.
// This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
getPenaltyScore() {
let e = 0;
for (let h = 0; h < this.size; h++) {
let $ = !1, d = 0, R = [0, 0, 0, 0, 0, 0, 0];
for (let E = 0; E < this.size; E++)
this.modules[h][E] == $ ? (d++, d == 5 ? e += l.PENALTY_N1 : d > 5 && e++) : (this.finderPenaltyAddHistory(d, R), $ || (e += this.finderPenaltyCountPatterns(R) * l.PENALTY_N3), $ = this.modules[h][E], d = 1);
e += this.finderPenaltyTerminateAndCount($, d, R) * l.PENALTY_N3;
}
for (let h = 0; h < this.size; h++) {
let $ = !1, d = 0, R = [0, 0, 0, 0, 0, 0, 0];
for (let E = 0; E < this.size; E++)
this.modules[E][h] == $ ? (d++, d == 5 ? e += l.PENALTY_N1 : d > 5 && e++) : (this.finderPenaltyAddHistory(d, R), $ || (e += this.finderPenaltyCountPatterns(R) * l.PENALTY_N3), $ = this.modules[E][h], d = 1);
e += this.finderPenaltyTerminateAndCount($, d, R) * l.PENALTY_N3;
}
for (let h = 0; h < this.size - 1; h++)
for (let $ = 0; $ < this.size - 1; $++) {
const d = this.modules[h][$];
d == this.modules[h][$ + 1] && d == this.modules[h + 1][$] && d == this.modules[h + 1][$ + 1] && (e += l.PENALTY_N2);
}
let n = 0;
for (const h of this.modules)
n = h.reduce(($, d) => $ + (d ? 1 : 0), n);
const t = this.size * this.size, s = Math.ceil(Math.abs(n * 20 - t * 10) / t) - 1;
return r(0 <= s && s <= 9), e += s * l.PENALTY_N4, r(0 <= e && e <= 2568888), e;
}
/*-- Private helper functions --*/
// Returns an ascending list of positions of alignment patterns for this version number.
// Each position is in the range [0,177), and are used on both the x and y axes.
// This could be implemented as lookup table of 40 variable-length lists of integers.
getAlignmentPatternPositions() {
if (this.version == 1)
return [];
{
const e = Math.floor(this.version / 7) + 2, n = this.version == 32 ? 26 : Math.ceil((this.version * 4 + 4) / (e * 2 - 2)) * 2;
let t = [6];
for (let s = this.size - 7; t.length < e; s -= n)
t.splice(1, 0, s);
return t;
}
}
// Returns the number of data bits that can be stored in a QR Code of the given version number, after
// all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
// The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
static getNumRawDataModules(e) {
if (e < l.MIN_VERSION || e > l.MAX_VERSION)
throw new RangeError("Version number out of range");
let n = (16 * e + 128) * e + 64;
if (e >= 2) {
const t = Math.floor(e / 7) + 2;
n -= (25 * t - 10) * t - 55, e >= 7 && (n -= 36);
}
return r(208 <= n && n <= 29648), n;
}
// Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
// QR Code of the given version number and error correction level, with remainder bits discarded.
// This stateless pure function could be implemented as a (40*4)-cell lookup table.
static getNumDataCodewords(e, n) {
return Math.floor(l.getNumRawDataModules(e) / 8) - l.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e] * l.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e];
}
// Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be
// implemented as a lookup table over all possible parameter values, instead of as an algorithm.
static reedSolomonComputeDivisor(e) {
if (e < 1 || e > 255)
throw new RangeError("Degree out of range");
let n = [];
for (let s = 0; s < e - 1; s++)
n.push(0);
n.push(1);
let t = 1;
for (let s = 0; s < e; s++) {
for (let h = 0; h < n.length; h++)
n[h] = l.reedSolomonMultiply(n[h], t), h + 1 < n.length && (n[h] ^= n[h + 1]);
t = l.reedSolomonMultiply(t, 2);
}
return n;
}
// Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
static reedSolomonComputeRemainder(e, n) {
let t = n.map((s) => 0);
for (const s of e) {
const h = s ^ t.shift();
t.push(0), n.forEach(($, d) => t[d] ^= l.reedSolomonMultiply($, h));
}
return t;
}
// Returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and result
// are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8.
static reedSolomonMultiply(e, n) {
if (e >>> 8 || n >>> 8)
throw new RangeError("Byte out of range");
let t = 0;
for (let s = 7; s >= 0; s--)
t = t << 1 ^ (t >>> 7) * 285, t ^= (n >>> s & 1) * e;
return r(t >>> 8 == 0), t;
}
// Can only be called immediately after a light run is added, and
// returns either 0, 1, or 2. A helper function for getPenaltyScore().
finderPenaltyCountPatterns(e) {
const n = e[1];
r(n <= this.size * 3);
const t = n > 0 && e[2] == n && e[3] == n * 3 && e[4] == n && e[5] == n;
return (t && e[0] >= n * 4 && e[6] >= n ? 1 : 0) + (t && e[6] >= n * 4 && e[0] >= n ? 1 : 0);
}
// Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
finderPenaltyTerminateAndCount(e, n, t) {
return e && (this.finderPenaltyAddHistory(n, t), n = 0), n += this.size, this.finderPenaltyAddHistory(n, t), this.finderPenaltyCountPatterns(t);
}
// Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
finderPenaltyAddHistory(e, n) {
n[0] == 0 && (e += this.size), n.pop(), n.unshift(e);
}
};
l.MIN_VERSION = 1, l.MAX_VERSION = 40, l.PENALTY_N1 = 3, l.PENALTY_N2 = 3, l.PENALTY_N3 = 40, l.PENALTY_N4 = 10, l.ECC_CODEWORDS_PER_BLOCK = [
// Version: (note that index 0 is for padding, and is set to an illegal value)
//0, 1, 2, 3, 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 Error correction level
[-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],
// Low
[-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],
// Medium
[-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],
// Quartile
[-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]
// High
], l.NUM_ERROR_CORRECTION_BLOCKS = [
// Version: (note that index 0 is for padding, and is set to an illegal value)
//0, 1, 2, 3, 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 Error correction level
[-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],
// Low
[-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],
// Medium
[-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],
// Quartile
[-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]
// High
];
let a = l;
o.QrCode = a;
function c(f, e, n) {
if (e < 0 || e > 31 || f >>> e)
throw new RangeError("Value out of range");
for (let t = e - 1; t >= 0; t--)
n.push(f >>> t & 1);
}
function i(f, e) {
return (f >>> e & 1) != 0;
}
function r(f) {
if (!f)
throw new Error("Assertion error");
}
const p = class p {
/*-- Constructor (low level) and fields --*/
// Creates a new QR Code segment with the given attributes and data.
// The character count (numChars) must agree with the mode and the bit buffer length,
// but the constraint isn't checked. The given bit buffer is cloned and stored.
constructor(e, n, t) {
if (this.mode = e, this.numChars = n, this.bitData = t, n < 0)
throw new RangeError("Invalid argument");
this.bitData = t.slice();
}
/*-- Static factory functions (mid level) --*/
// Returns a segment representing the given binary data encoded in
// byte mode. All input byte arrays are acceptable. Any text string
// can be converted to UTF-8 bytes and encoded as a byte mode segment.
static makeBytes(e) {
let n = [];
for (const t of e)
c(t, 8, n);
return new p(p.Mode.BYTE, e.length, n);
}
// Returns a segment representing the given string of decimal digits encoded in numeric mode.
static makeNumeric(e) {
if (!p.isNumeric(e))
throw new RangeError("String contains non-numeric characters");
let n = [];
for (let t = 0; t < e.length; ) {
const s = Math.min(e.length - t, 3);
c(parseInt(e.substring(t, t + s), 10), s * 3 + 1, n), t += s;
}
return new p(p.Mode.NUMERIC, e.length, n);
}
// Returns a segment representing the given text string encoded in alphanumeric mode.
// The characters allowed are: 0 to 9, A to Z (uppercase only), space,
// dollar, percent, asterisk, plus, hyphen, period, slash, colon.
static makeAlphanumeric(e) {
if (!p.isAlphanumeric(e))
throw new RangeError("String contains unencodable characters in alphanumeric mode");
let n = [], t;
for (t = 0; t + 2 <= e.length; t += 2) {
let s = p.ALPHANUMERIC_CHARSET.indexOf(e.charAt(t)) * 45;
s += p.ALPHANUMERIC_CHARSET.indexOf(e.charAt(t + 1)), c(s, 11, n);
}
return t < e.length && c(p.ALPHANUMERIC_CHARSET.indexOf(e.charAt(t)), 6, n), new p(p.Mode.ALPHANUMERIC, e.length, n);
}
// Returns a new mutable list of zero or more segments to represent the given Unicode text string.
// The result may use various segment modes and switch modes to optimize the length of the bit stream.
static makeSegments(e) {
return e == "" ? [] : p.isNumeric(e) ? [p.makeNumeric(e)] : p.isAlphanumeric(e) ? [p.makeAlphanumeric(e)] : [p.makeBytes(p.toUtf8ByteArray(e))];
}
// Returns a segment representing an Extended Channel Interpretation
// (ECI) designator with the given assignment value.
static makeEci(e) {
let n = [];
if (e < 0)
throw new RangeError("ECI assignment value out of range");
if (e < 128)
c(e, 8, n);
else if (e < 16384)
c(2, 2, n), c(e, 14, n);
else if (e < 1e6)
c(6, 3, n), c(e, 21, n);
else
throw new RangeError("ECI assignment value out of range");
return new p(p.Mode.ECI, 0, n);
}
// Tests whether the given string can be encoded as a segment in numeric mode.
// A string is encodable iff each character is in the range 0 to 9.
static isNumeric(e) {
return p.NUMERIC_REGEX.test(e);
}
// Tests whether the given string can be encoded as a segment in alphanumeric mode.
// A string is encodable iff each character is in the following set: 0 to 9, A to Z
// (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
static isAlphanumeric(e) {
return p.ALPHANUMERIC_REGEX.test(e);
}
/*-- Methods --*/
// Returns a new copy of the data bits of this segment.
getData() {
return this.bitData.slice();
}
// (Package-private) Calculates and returns the number of bits needed to encode the given segments at
// the given version. The result is infinity if a segment has too many characters to fit its length field.
static getTotalBits(e, n) {
let t = 0;
for (const s of e) {
const h = s.mode.numCharCountBits(n);
if (s.numChars >= 1 << h)
return 1 / 0;
t += 4 + h + s.bitData.length;
}
return t;
}
// Returns a new array of bytes representing the given string encoded in UTF-8.
static toUtf8ByteArray(e) {
e = encodeURI(e);
let n = [];
for (let t = 0; t < e.length; t++)
e.charAt(t) != "%" ? n.push(e.charCodeAt(t)) : (n.push(parseInt(e.substring(t + 1, t + 3), 16)), t += 2);
return n;
}
};
p.NUMERIC_REGEX = /^[0-9]*$/, p.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/, p.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
let u = p;
o.QrSegment = u;
})(S || (S = {}));
((o) => {
((a) => {
const i = class i {
// The QR Code can tolerate about 30% erroneous codewords
/*-- Constructor and fields --*/
constructor(u, l) {
this.ordinal = u, this.formatBits = l;
}
};
i.LOW = new i(0, 1), i.MEDIUM = new i(1, 0), i.QUARTILE = new i(2, 3), i.HIGH = new i(3, 2);
let c = i;
a.Ecc = c;
})(o.QrCode || (o.QrCode = {}));
})(S || (S = {}));
((o) => {
((a) => {
const i = class i {
/*-- Constructor and fields --*/
constructor(u, l) {
this.modeBits = u, this.numBitsCharCount = l;
}
/*-- Method --*/
// (Package-private) Returns the bit width of the character count field for a segment in
// this mode in a QR Code at the given version number. The result is in the range [0, 16].
numCharCountBits(u) {
return this.numBitsCharCount[Math.floor((u + 7) / 17)];
}
};
i.NUMERIC = new i(1, [10, 12, 14]), i.ALPHANUMERIC = new i(2, [9, 11, 13]), i.BYTE = new i(4, [8, 16, 16]), i.KANJI = new i(8, [8, 10, 12]), i.ECI = new i(7, [0, 0, 0]);
let c = i;
a.Mode = c;
})(o.QrSegment || (o.QrSegment = {}));
})(S || (S = {}));
const U = S, ft = {
L: U.QrCode.Ecc.LOW,
M: U.QrCode.Ecc.MEDIUM,
Q: U.QrCode.Ecc.QUARTILE,
H: U.QrCode.Ecc.HIGH
}, pt = 128, mt = "M", Et = 1, Mt = 4, nt = 5, H = "#000000", Rt = "square", gt = "square", Nt = "square", It = "react-qr-code", Ct = "react-qr-code-gradient", wt = "react-qr-code-bg-gradient", At = 0.1, N = 7, T = 3, y = [
[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]
], rt = {
"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]
}, k = {
"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
}, q = {
square: 0,
diamond: 0,
circle: 3,
"rounded-sm": 0.5,
rounded: 0.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
}, B = [
[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]
], Pt = (o) => o === "square" || o === "pinched-square" || o === "circle" || o === "star" || o === "heart" || o === "diamond" || o === "hashtag", Ot = (o, a) => o === "square-sm" ? 0.75 : a ? Math.random() * (1 - 0.75) + 0.75 : 1, D = (o, a, c) => {
const i = {
left: o === 0 ? !1 : c[a][o - 1],
right: o === c[a].length - 1 ? !1 : c[a][o + 1],
top: a === 0 ? !1 : c[a - 1][o],
bottom: a === c.length - 1 ? !1 : c[a + 1][o]
};
return {
...i,
count: Object.values(i).filter(Boolean).length
};
}, b = (o, a, c) => `M${o},${a}h${c}v${c}h-${c}Z`, F = (o, a, c) => `M${o},${a + c / 2}a${c / 2},${c / 2} 0 1,0 ${c},0a${c / 2},${c / 2} 0 1,0 -${c},0Z`, Tt = (o, a, c) => `M${o},${a + c / 2}l${c / 2},-${c / 2}l${c / 2},${c / 2}l-${c / 2},${c / 2}Z`, Lt = (o, a) => `M ${o} ${a}
v 1
h 1
v -0.5
a 0.5 0.5, 0, 0, 0, -0.5 -0.5`, Y = (o, a) => `M ${o + 1} ${a}
v 1
h -1
v -0.5
a 0.5 0.5, 0, 0, 1, 0.5 -0.5`, G = (o, a) => `M ${o} ${a}
v 1
h 0.5
a 0.5 0.5, 0, 0, 0, 0.5 -0.5
v -0.5
h -1`, vt = (o, a) => `M ${o + 1} ${a}
v 1
h -0.5
a 0.5 0.5, 0, 0, 1, -0.5 -0.5
v -0.5
h 1`, j = (o, a) => `M ${o} ${a}
v 1
h 0.5
a 0.5 0.5, 0, 0, 0, 0 -1`, V = (o, a) => `M ${o + 1} ${a}
v 1
h -0.5
a 0.5 0.5, 0, 0, 1, 0 -1`, X = (o, a) => `M ${o} ${a + 1}
h 1
v -0.5
a 0.5 0.5, 0, 0, 0, -1 0`, Z = (o, a) => `M ${o} ${a}
h 1
v 0.5
a 0.5 0.5, 0, 0, 1, -1 0`, St = (o, a, c) => `M ${o + 1} ${a}h -${c / 2}a ${c / 2.5} ${c / 2.5}, 0, 0, 0, ${-c / 2.5} ${c / 2.5}v ${c / 2}h ${c / 2}a ${c / 2.5} ${c / 2.5}, 0, 0, 0, ${c / 2.5} ${-c / 2.5}`, Ut = ({
x: o,
y: a,
numCells: c
}) => {
var i, r, u;
return !!((i = B[o]) != null && i[a] || (r = B[o - c + 7]) != null && r[a] || (u = B[o]) != null && u[a - c + 7]);
}, bt = ({
x: o,
y: a,
radius: c
}) => {
const i = T - c, r = c / 2, u = T - r;
return `M ${o} ${a + r}v ${i}a ${r} ${r}, 0, 0, 0, ${r} ${r}h ${u}v ${-u}a ${r} ${r}, 0, 0, 0, ${-r} ${-r}h ${-i}H ${o}z`;
}, Dt = ({
x: o,
y: a,
radius: c
}) => {
const i = T - c, r = c / 2, u = T - r;
return `M ${o} ${a + r}v ${i}a ${r} ${r}, 0, 0, 0, ${r} ${r}h ${u}v ${-u}a ${r} ${r}, 0, 0, 0, ${-r} ${-r}h ${-i}a ${r} ${r}, 0, 0, 0, ${-r} ${r}`;
}, Ft = ({
x: o,
y: a,
numCells: c
}) => {
var i, r, u;
return !!((i = y[o]) != null && i[a] || (r = y[o - c + 7]) != null && r[a] || (u = y[o]) != null && u[a - c + 7]);
}, yt = ({
x: o,
y: a,
radius: c
}) => {
const i = N - c, r = c / 2;
return `M ${o} ${a + r}v ${i}a ${r} ${r}, 0, 0, 0, ${r} ${r}h ${i}a ${r} ${r}, 0, 0, 0, ${r} ${-r}v ${-i}a ${r} ${r}, 0, 0, 0, ${-r} ${-r}h ${-i}a ${r} ${r}, 0, 0, 0, ${-r} ${r}M ${o + r} ${a + 1}h ${i}a ${r - 1} ${r - 1}, 0, 0, 1, ${r - 1} ${r - 1}v ${i}a ${r - 1} ${r - 1}, 0, 0, 1, ${-(r - 1)} ${r - 1}h ${-i}a ${r - 1} ${r - 1}, 0, 0, 1, ${-(r - 1)} ${-(r - 1)}v ${-i}a ${r - 1} ${r - 1}, 0, 0, 1, ${r - 1} ${-(r - 1)}`;
}, Bt = ({
x: o,
y: a,
radius: c
}) => {
const i = N - c, r = c / 2, u = N - r;
return `M ${o} ${a + r}v ${i}a ${r} ${r}, 0, 0, 0, ${r} ${r}h ${u}v ${-u}a ${r} ${r}, 0, 0, 0, ${-r} ${-r}h ${-i}H ${o}zM ${o + r} ${a + 1}h ${i}a ${r - 1} ${r - 1}, 0, 0, 1, ${r - 1} ${r - 1}v ${u - 1}h ${-(u - 1)}a ${r - 1} ${r - 1}, 0, 0, 1, ${-(r - 1)} ${-(r - 1)}v ${-(u - 1)}z`;
}, Ht = ({
x: o,
y: a,
radius: c
}) => {
const i = N - c, r = c / 2, u = N - r;
return `M ${o} ${a + r}v ${i}a ${r} ${r}, 0, 0, 0, ${r} ${r}h ${u}v ${-u}a ${r} ${r}, 0, 0, 0, ${-r} ${-r}h ${-i}a ${r} ${r}, 0, 0, 0, ${-r} ${r}M ${o + r} ${a + 1}h ${i}a ${r - 1} ${r - 1}, 0, 0, 1, ${r - 1} ${r - 1}v ${u - 1}h ${-(u - 1)}a ${r - 1} ${r - 1}, 0, 0, 1, ${-(r - 1)} ${-(r - 1)}v ${-i}a ${r - 1} ${r - 1}, 0, 0, 1, ${r - 1} ${-(r - 1)}`;
}, _t = (o) => ({
color: (o == null ? void 0 : o.color) || H,
style: (o == null ? void 0 : o.style) || Nt,
randomSize: (o == null ? void 0 : o.randomSize) || !1
}), zt = (o) => ({
color: (o == null ? void 0 : o.color) || H,
style: (o == null ? void 0 : o.style) || Rt
}), Qt = (o) => ({
color: (o == null ? void 0 : o.color) || H,
style: (o == null ? void 0 : o.style) || gt
}), kt = ({
modules: o,
margin: a,
settings: c,
gradient: i,
gradientId: r
}) => {
const { color: u, style: l, randomSize: p } = v(
() => _t(c),
[c]
), f = [], e = o.length, n = Pt(l) && p, t = it(
() => Ot(l, n),
[l, n]
);
return o.forEach((s, h) => {
s.forEach(($, d) => {
if (Ft({ x: d, y: h, numCells: e }) || Ut({ x: d, y: h, numCells: e }))
return;
const R = t(), E = 1 * R, A = (1 - 1 * R) / 2, M = d + a + A, m = h + a + A;
if ($) {
if (l === "square" || l === "square-sm")
f.push(b(M, m, E));
else if (l === "pinched-square")
f.push(tt(M, m, E, 0.25));
else if (l === "circle")
f.push(F(M, m, E));
else if (l === "diamond")
f.push(Tt(M, m, E));
else if (l === "star")
f.push(
J(M + E / 2, m + E / 2, E * 1.1, nt)
);
else if (l === "heart")
f.push(ot(M, m, E));
else if (l === "hashtag")
f.push(et(M, m, E));
else if (l === "rounded") {
const { left: g, right: I, top: w, bottom: P, count: O } = D(d, h, o);
O === 0 ? f.push(F(M, m, 1)) : O > 2 || g && I || w && P ? f.push(b(M, m, 1)) : O === 2 ? g && w ? f.push(G(M, m)) : w && I ? f.push(vt(M, m)) : I && P ? f.push(Y(M, m)) : f.push(Lt(M, m)) : w ? f.push(Z(M, m)) : I ? f.push(V(M, m)) : P ? f.push(X(M, m)) : f.push(j(M, m));
} else if (l === "leaf") {
const { left: g, right: I, top: w, bottom: P, count: O } = D(d, h, o);
if (O === 0)
f.push(St(M, m, E));
else if (!g && !w) {
f.push(Y(M, m));
return;
} else !I && !P ? f.push(G(M, m)) : f.push(b(M, m, 1));
} else if (l === "vertical-line") {
const { left: g, right: I, top: w, bottom: P, count: O } = D(d, h, o);
O === 0 || g && !(w || P) || I && !(w || P) ? f.push(F(M, m, 1)) : w && P ? f.push(b(M, m, 1)) : w && !P ? f.push(Z(M, m)) : P && !w && f.push(X(M, m));
} else if (l === "horizontal-line") {
const { left: g, right: I, top: w, bottom: P, count: O } = D(d, h, o);
O === 0 || w && !(g || I) || P && !(g || I) ? f.push(F(M, m, 1)) : g && I ? f.push(b(M, m, 1)) : g && !I ? f.push(j(M, m)) : I && !g && f.push(V(M, m));
}
}
});
}), /* @__PURE__ */ C(
"path",
{
fill: i ? `url(#${r})` : u,
d: f.join(""),
shapeRendering: l === "square" ? "crispEdges" : "geometricPrecision",
"data-testid": "data-modules"
}
);
}, L = {
"data-testid": "finder-patterns-inner"
}, qt = ({
modules: o,
margin: a,
settings: c,
gradient: i,
gradientId: r
}) => {
const { color: u, style: l } = v(
() => Qt(c),
[c]
), p = i ? `url(#${r})` : u, f = v(
() => [
{ x: a + 2, y: a + 2 },
{ x: o.length + a - N + 2, y: a + 2 },
{ x: a + 2, y: o.length + a - N + 2 }
],
[a, o.length]
), e = (n, t) => `finder-patterns-inner-${l}-${n}-${t}`;
if (l === "rounded-sm" || l === "rounded" || l === "rounded-lg" || l === "circle" || l === "square")
return f.map((n) => {
const { x: t, y: s } = n;
return /* @__PURE__ */ C(
"rect",
{
x: t,
y: s,
width: T,
height: T,
fill: p,
rx: q[l],
...L
},
e(t, s)
);
});
if (l === "pinched-square")
return f.map((n) => {
const { x: t, y: s } = n, h = tt(t, s, T, 0.25);
return /* @__PURE__ */ C("path", { fill: p, d: h, ...L }, e(t, s));
});
if (l === "diamond")
return f.map((n) => {
const { x: t, y: s } = n, h = Math.sqrt(1.5), $ = T / h, d = $ - $ / h;
return /* @__PURE__ */ C(
"rect",
{
x: t + d / 2,
y: s + d / 2,
width: $,
height: $,
fill: p,
style: {
transform: "rotate(45deg)",
transformOrigin: "center",
transformBox: "fill-box"
},
...L
},
e(t, s)
);
});
if (l === "inpoint-sm" || l === "inpoint" || l === "inpoint-lg" || l === "outpoint-sm" || l === "outpoint" || l === "outpoint-lg" || l === "leaf-sm" || l === "leaf" || l === "leaf-lg") {
const n = l === "leaf-sm" || l === "leaf" || l === "leaf-lg" ? bt : Dt;
return f.map((t, s) => ({
...t,
rotation: rt[l][s]
})).map(({ x: t, y: s, rotation: h }) => {
const $ = n({
x: t,
y: s,
radius: q[l]
});
return /* @__PURE__ */ C(
"path",
{
fill: p,
d: $,
style: {
transform: `rotate(${h}deg)`,
transformOrigin: "center",
transformBox: "fill-box"
},
...L
},
e(t, s)
);
});
}
if (l === "heart")
return f.map(({ x: n, y: t }) => /* @__PURE__ */ C(
"path",
{
fill: p,
d: ot(n, t, T),
...L
},
e(n, t)
));
if (l === "star")
return f.map(({ x: n, y: t }) => {
const s = n + T / 2, h = t + T / 2, $ = J(s, h, T * 1.2, nt);
return /* @__PURE__ */ C("path", { fill: p, d: $, ...L }, e(n, t));
});
if (l === "hashtag")
return f.map(({ x: n, y: t }) => {
const s = et(n - 0.25, t - 0.25, 3.5);
return /* @__PURE__ */ C("path", { fill: p, d: s, ...L }, e(n, t));
});
}, x = {
"data-testid": "finder-patterns-outer"
}, Yt = ({
modules: o,
margin: a,
settings: c,
gradient: i,
gradientId: r
}) => {
const { style: u, color: l } = v(
() => zt(c),
[c]
), p = i ? `url(#${r})` : l, f = [], e = v(
() => [
{ x: a, y: a },
{ x: o.length + a - N, y: a },
{ x: a, y: o.length + a - N }
],
[a, o.length]
);
if ([
"rounded-sm",
"rounded",
"rounded-lg",
"circle",
"square",
"pinched-square"
].includes(u)) {
for (const n of e) {
const { x: t, y: s } = n;
u === "rounded-sm" || u === "rounded" || u === "rounded-lg" ? f.push(
yt({
x: t,
y: s,
radius: k[u]
})
) : u === "circle" ? f.push(
`M ${t + N / 2} ${s}a ${N / 2} ${N / 2} 0 1 0 0.01 0zzm 0 1a ${N / 2 - 1} ${N / 2 - 1} 0 1 1 -0.01 0Z`
) : u === "pinched-square" ? f.push(
`M ${t} ${s}Q ${t + 0.5} ${s + N / 2}, ${t} ${s + N}Q ${t + N / 2} ${s + N - 0.5}, ${t + N} ${s + N}Q ${t + N - 0.5} ${s + N / 2}, ${t + N} ${s}Q ${t + N / 2} ${s + 0.5}, ${t} ${s}zM ${t + 1} ${s + 1}Q ${t + N / 2} ${s + 1.25}, ${t + N - 1} ${s + 1}Q ${t + N - 1.25} ${s + N / 2}, ${t + N - 1} ${s + N - 1}Q ${t + N / 2} ${s + N - 1.25}, ${t + 1} ${s + N - 1}Q ${t + 1.25} ${s + N / 2}, ${t + 1} ${s + 1}z`
) : f.push(
`M ${t} ${s}v ${N}h ${N}v -7zM ${t + 1} ${s + 1}h ${N - 2}v ${N - 2}h -5z`
);
}
return /* @__PURE__ */ C("path", { fill: p, d: f.join(""), ...x });
}
if (u === "inpoint-sm" || u === "inpoint" || u === "inpoint-lg" || u === "outpoint-sm" || u === "outpoint" || u === "outpoint-lg" || u === "leaf-sm" || u === "leaf" || u === "leaf-lg") {
const n = u === "leaf-sm" || u === "leaf" || u === "leaf-lg" ? Bt : Ht;
return e.map((t, s) => ({
...t,
rotation: rt[u][s]
})).map(({ x: t, y: s, rotation: h }) => {
const $ = n({
x: t,
y: s,
radius: k[u]
});
return /* @__PURE__ */ C(
"path",
{
fill: p,
d: $,
style: {
transform: `rotate(${h}deg)`,
transformOrigin: "center",
transformBox: "fill-box"
},
...x
},
`finder-patterns-outer-${u}-${t}-${s}`
);
});
}
}, Gt = ({ gradient: o, gradientId: a }) => {
var i, r;
if (!o)
return null;
const c = W((o == null ? void 0 : o.rotation) || 0);
return /* @__PURE__ */ C("defs", { children: o.type === "linear" ? /* @__PURE__ */ C("linearGradient", { id: a, gradientUnits: "userSpaceOnUse", ...c, children: (i = o.stops) == null ? void 0 : i.map((u, l) => /* @__PURE__ */ C("stop", { offset: u.offset, stopColor: u.color }, l)) }) : /* @__PURE__ */ C(
"radialGradient",
{
id: a,
gradientUnits: "userSpaceOnUse",
cx: "50%",
cy: "50%",
r: "50%",
children: (r = o.stops) == null ? void 0 : r.map((u, l) => /* @__PURE__ */ C("stop", { offset: u.offset, stopColor: u.color }, l))
}
) });
}, jt = () => {
const o = at();
return {
gradientId: `${Ct}-${o}`,
bgGradientId: `${wt}-${o}`
};
}, Vt = (o, a) => o.slice().map((c, i) => i < a.y || i >= a.y + a.h ? c : c.map((r, u) => u < a.x || u >= a.x + a.w ? r : !1)), Xt = (o, a, c, i) => {
if (i == null)
return null;
const r = o.length + c * 2, u = Math.floor(a * At), l = r / a, p = (i.width || u) * l, f = (i.height || u) * l, e = i.x == null ? o.length / 2 - p / 2 : i.x * l, n = i.y == null ? o.length / 2 - f / 2 : i.y * l, t = i.opacity == null ? 1 : i.opacity;
let s = null;
if (i.excavate) {
const $ = Math.floor(e), d = Math.floor(n), R = Math.ceil(p + e - $), E = Math.ceil(f + n - d);
s = { x: $, y: d, w: R, h: E };
}
const h = i.crossOrigin;
return { x: e, y: n, h: f, w: p, excavation: s, opacity: t, crossOrigin: h };
}, Zt = (o) => o != null ? Math.max(Math.floor(o), 0) : Mt, xt = ({
value: o,
level: a,
minVersion: c,
marginSize: i,
imageSettings: r,
size: u,
boostLevel: l
}) => {
const p = v(() => {
const h = (Array.isArray(o) ? o : [o]).reduce(($, d) => ($.push(...U.QrSegment.makeSegments(d)), $), []);
return U.QrCode.encodeSegments(
h,
ft[a],
c,
void 0,
void 0,
l
);
}, [o, a, c, l]), { cells: f, margin: e, numCells: n, calculatedImageSettings: t } = v(() => {
const s = p.getModules(), h = Zt(i), $ = s.length + h * 2, d = Xt(s, u, h, r);
return {
cells: s,
margin: h,
numCells: $,
calculatedImageSettings: d
};
}, [p, u, r, i]);
return {
qrcode: p,
margin: e,
cells: f,
numCells: n,
calculatedImageSettings: t
};
}, Kt = ({ svgRef: o, fileSize: a, fileName: c }) => {
if (!o.current) return;
const i = o.current.cloneNode(!0);
i.setAttribute("width", a.toString()), i.setAttribute("height", a.toString());
const r = new XMLSerializer(), u = new Blob([r.serializeToString(i)], {
type: "image/svg+xml"
}), l = URL.createObjectURL(u), p = document.createElement("a");
p.href = l, p.download = `${c}.svg`, document.body.appendChild(p), p.click(), document.body.removeChild(p), URL.revokeObjectURL(l);
}, Wt = ({
svgRef: o,
fileSize: a,
fileName: c,
fileFormat: i,
imageSettings: r,
calculatedImageSettings: u,
size: l,
numCells: p,
margin: f
}) => {
if (!o.current) return;
const e = document.createElement("canvas"), n = e.getContext("2d");
if (!n) return;
e.width = a, e.height = a;
const t = new XMLSerializer().serializeToString(o.current), s = new Blob([t], { type: "image/svg+xml;charset=utf-8" }), h = URL.createObjectURL(s), $ = new Image();
$.crossOrigin = "anonymous", $.src = h, $.onload = () => {
if (n.drawImage($, 0, 0, a, a), URL.revokeObjectURL(h), r != null && r.src && u) {
const d = new Image();
d.crossOrigin = "anonymous", d.src = r.src, d.onload = () => {
const R = a / l, E = p / a, A = r.width * R, M = r.x ? (u.x + f) / E : (a - A) / 2, m = r.y ? (u.y + f) / E : (a - A) / 2;
n.drawImage(d, M, m, A, A);
const g = i === "png" ? "image/png" : "image/jpeg", I = document.createElement("a");
I.href = e.toDataURL(g), I.download = `${c}.${i}`, document.body.appendChild(I), I.click(), document.body.removeChild(I);
}, d.onerror = (R) => console.error("Error loading logo:", R);
} else {
const d = i === "png" ? "image/png" : "image/jpeg", R = document.createElement("a");
R.href = e.toDataURL(d), R.download = `${c}.${i}`, document.body.appendChild(R), R.click(), document.body.removeChild(R);
}
}, $.onerror = (d) => console.error("Error loading QR code:", d);
}, Jt = ct((o, a) => {
const {
value: c,
size: i = pt,
level: r = mt,
background: u,
gradient: l,
minVersion: p = Et,
boostLevel: f,
marginSize: e,
finderPatternOuterSettings: n,
finderPatternInnerSettings: t,
dataModulesSettings: s,
imageSettings: h,
svgProps: $
} = o, d = lt(null), { gradientId: R, bgGradientId: E } = jt(), { margin: A, cells: M, numCells: m, calculatedImageSettings: g } = xt({
value: c,
level: r,
minVersion: p,
boostLevel: f,
marginSize: e,
imageSettings: h,
size: i
});
ht(a, () => ({
svg: d.current,
download: ({
name: O = It,
format: _ = "svg",
size: z = 500
}) => {
d.current && (_ === "svg" ? Kt({ svgRef: d, fileSize: z, fileName: O }) : Wt({
svgRef: d,
fileSize: z,
fileName: O,
fileFormat: _,
imageSettings: h,
calculatedImageSettings: g,
size: i,
numCells: m,
margin: A
}));
}
}));
let I = M, w = null;
h != null && g != null && (g.excavation != null && (I = Vt(M, g.excavation)), w = /* @__PURE__ */ C(
"image",
{
href: h.src,
height: g.h,
width: g.w,
x: g.x + A,
y: g.y + A,
preserveAspectRatio: "none",
opacity: g.opacity,
crossOrigin: g.crossOrigin
}
));
const P = {
modules: I,
margin: A,
gradient: l,
gradientId: R
};
return /* @__PURE__ */ K(
"svg",
{
height: i,
width: i,
viewBox: `0 0 ${m} ${m}`,
ref: d,
role: "img",
"