coinley-checkout 0.1.7 → 0.1.8

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.
@@ -1,4 +1,4 @@
1
- import require$$0, { createContext, useContext, useState, useEffect, forwardRef, useImperativeHandle } from "react";
1
+ import React, { createContext, useContext, useState, useEffect, forwardRef, useImperativeHandle } from "react";
2
2
  const styles = "";
3
3
  let apiConfig = {
4
4
  apiKey: null,
@@ -128,7 +128,7 @@ function requireReactJsxRuntime_production_min() {
128
128
  if (hasRequiredReactJsxRuntime_production_min)
129
129
  return reactJsxRuntime_production_min;
130
130
  hasRequiredReactJsxRuntime_production_min = 1;
131
- var f = require$$0, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: true, ref: true, __self: true, __source: true };
131
+ var f = React, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: true, ref: true, __self: true, __source: true };
132
132
  function q(c, a, g) {
133
133
  var b, d = {}, e = null, h = null;
134
134
  void 0 !== g && (e = "" + g);
@@ -163,7 +163,7 @@ function requireReactJsxRuntime_development() {
163
163
  hasRequiredReactJsxRuntime_development = 1;
164
164
  if (process.env.NODE_ENV !== "production") {
165
165
  (function() {
166
- var React = require$$0;
166
+ var React$1 = React;
167
167
  var REACT_ELEMENT_TYPE = Symbol.for("react.element");
168
168
  var REACT_PORTAL_TYPE = Symbol.for("react.portal");
169
169
  var REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
@@ -189,7 +189,7 @@ function requireReactJsxRuntime_development() {
189
189
  }
190
190
  return null;
191
191
  }
192
- var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
192
+ var ReactSharedInternals = React$1.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
193
193
  function error(format) {
194
194
  {
195
195
  {
@@ -1106,48 +1106,1168 @@ const CoinleyProvider = ({
1106
1106
  };
1107
1107
  return /* @__PURE__ */ jsxRuntimeExports.jsx(CoinleyContext.Provider, { value, children });
1108
1108
  };
1109
- const QRCode = ({ walletAddress, amount, currency, theme = "light" }) => {
1110
- const qrDisplay = /* @__PURE__ */ jsxRuntimeExports.jsxs(
1111
- "div",
1112
- {
1113
- style: {
1114
- width: "200px",
1115
- height: "200px",
1116
- backgroundColor: theme === "dark" ? "#374151" : "#f3f4f6",
1117
- display: "flex",
1118
- alignItems: "center",
1119
- justifyContent: "center",
1120
- color: theme === "dark" ? "white" : "black",
1121
- fontWeight: "bold",
1122
- border: `1px solid ${theme === "dark" ? "#4b5563" : "#e5e7eb"}`,
1123
- margin: "0 auto"
1109
+ var __defProp = Object.defineProperty;
1110
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1111
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
1112
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
1113
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1114
+ var __spreadValues = (a, b) => {
1115
+ for (var prop in b || (b = {}))
1116
+ if (__hasOwnProp.call(b, prop))
1117
+ __defNormalProp(a, prop, b[prop]);
1118
+ if (__getOwnPropSymbols)
1119
+ for (var prop of __getOwnPropSymbols(b)) {
1120
+ if (__propIsEnum.call(b, prop))
1121
+ __defNormalProp(a, prop, b[prop]);
1122
+ }
1123
+ return a;
1124
+ };
1125
+ var __objRest = (source, exclude) => {
1126
+ var target = {};
1127
+ for (var prop in source)
1128
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
1129
+ target[prop] = source[prop];
1130
+ if (source != null && __getOwnPropSymbols)
1131
+ for (var prop of __getOwnPropSymbols(source)) {
1132
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
1133
+ target[prop] = source[prop];
1134
+ }
1135
+ return target;
1136
+ };
1137
+ /**
1138
+ * @license QR Code generator library (TypeScript)
1139
+ * Copyright (c) Project Nayuki.
1140
+ * SPDX-License-Identifier: MIT
1141
+ */
1142
+ var qrcodegen;
1143
+ ((qrcodegen2) => {
1144
+ const _QrCode = class _QrCode2 {
1145
+ /*-- Constructor (low level) and fields --*/
1146
+ // Creates a new QR Code with the given version number,
1147
+ // error correction level, data codeword bytes, and mask number.
1148
+ // This is a low-level API that most users should not use directly.
1149
+ // A mid-level API is the encodeSegments() function.
1150
+ constructor(version, errorCorrectionLevel, dataCodewords, msk) {
1151
+ this.version = version;
1152
+ this.errorCorrectionLevel = errorCorrectionLevel;
1153
+ this.modules = [];
1154
+ this.isFunction = [];
1155
+ if (version < _QrCode2.MIN_VERSION || version > _QrCode2.MAX_VERSION)
1156
+ throw new RangeError("Version value out of range");
1157
+ if (msk < -1 || msk > 7)
1158
+ throw new RangeError("Mask value out of range");
1159
+ this.size = version * 4 + 17;
1160
+ let row = [];
1161
+ for (let i = 0; i < this.size; i++)
1162
+ row.push(false);
1163
+ for (let i = 0; i < this.size; i++) {
1164
+ this.modules.push(row.slice());
1165
+ this.isFunction.push(row.slice());
1166
+ }
1167
+ this.drawFunctionPatterns();
1168
+ const allCodewords = this.addEccAndInterleave(dataCodewords);
1169
+ this.drawCodewords(allCodewords);
1170
+ if (msk == -1) {
1171
+ let minPenalty = 1e9;
1172
+ for (let i = 0; i < 8; i++) {
1173
+ this.applyMask(i);
1174
+ this.drawFormatBits(i);
1175
+ const penalty = this.getPenaltyScore();
1176
+ if (penalty < minPenalty) {
1177
+ msk = i;
1178
+ minPenalty = penalty;
1179
+ }
1180
+ this.applyMask(i);
1181
+ }
1182
+ }
1183
+ assert(0 <= msk && msk <= 7);
1184
+ this.mask = msk;
1185
+ this.applyMask(msk);
1186
+ this.drawFormatBits(msk);
1187
+ this.isFunction = [];
1188
+ }
1189
+ /*-- Static factory functions (high level) --*/
1190
+ // Returns a QR Code representing the given Unicode text string at the given error correction level.
1191
+ // As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer
1192
+ // Unicode code points (not UTF-16 code units) if the low error correction level is used. The smallest possible
1193
+ // QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the
1194
+ // ecl argument if it can be done without increasing the version.
1195
+ static encodeText(text, ecl) {
1196
+ const segs = qrcodegen2.QrSegment.makeSegments(text);
1197
+ return _QrCode2.encodeSegments(segs, ecl);
1198
+ }
1199
+ // Returns a QR Code representing the given binary data at the given error correction level.
1200
+ // This function always encodes using the binary segment mode, not any text mode. The maximum number of
1201
+ // bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
1202
+ // The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
1203
+ static encodeBinary(data, ecl) {
1204
+ const seg = qrcodegen2.QrSegment.makeBytes(data);
1205
+ return _QrCode2.encodeSegments([seg], ecl);
1206
+ }
1207
+ /*-- Static factory functions (mid level) --*/
1208
+ // Returns a QR Code representing the given segments with the given encoding parameters.
1209
+ // The smallest possible QR Code version within the given range is automatically
1210
+ // chosen for the output. Iff boostEcl is true, then the ECC level of the result
1211
+ // may be higher than the ecl argument if it can be done without increasing the
1212
+ // version. The mask number is either between 0 to 7 (inclusive) to force that
1213
+ // mask, or -1 to automatically choose an appropriate mask (which may be slow).
1214
+ // This function allows the user to create a custom sequence of segments that switches
1215
+ // between modes (such as alphanumeric and byte) to encode text in less space.
1216
+ // This is a mid-level API; the high-level API is encodeText() and encodeBinary().
1217
+ static encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
1218
+ if (!(_QrCode2.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= _QrCode2.MAX_VERSION) || mask < -1 || mask > 7)
1219
+ throw new RangeError("Invalid value");
1220
+ let version;
1221
+ let dataUsedBits;
1222
+ for (version = minVersion; ; version++) {
1223
+ const dataCapacityBits2 = _QrCode2.getNumDataCodewords(version, ecl) * 8;
1224
+ const usedBits = QrSegment.getTotalBits(segs, version);
1225
+ if (usedBits <= dataCapacityBits2) {
1226
+ dataUsedBits = usedBits;
1227
+ break;
1228
+ }
1229
+ if (version >= maxVersion)
1230
+ throw new RangeError("Data too long");
1231
+ }
1232
+ for (const newEcl of [_QrCode2.Ecc.MEDIUM, _QrCode2.Ecc.QUARTILE, _QrCode2.Ecc.HIGH]) {
1233
+ if (boostEcl && dataUsedBits <= _QrCode2.getNumDataCodewords(version, newEcl) * 8)
1234
+ ecl = newEcl;
1235
+ }
1236
+ let bb = [];
1237
+ for (const seg of segs) {
1238
+ appendBits(seg.mode.modeBits, 4, bb);
1239
+ appendBits(seg.numChars, seg.mode.numCharCountBits(version), bb);
1240
+ for (const b of seg.getData())
1241
+ bb.push(b);
1242
+ }
1243
+ assert(bb.length == dataUsedBits);
1244
+ const dataCapacityBits = _QrCode2.getNumDataCodewords(version, ecl) * 8;
1245
+ assert(bb.length <= dataCapacityBits);
1246
+ appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
1247
+ appendBits(0, (8 - bb.length % 8) % 8, bb);
1248
+ assert(bb.length % 8 == 0);
1249
+ for (let padByte = 236; bb.length < dataCapacityBits; padByte ^= 236 ^ 17)
1250
+ appendBits(padByte, 8, bb);
1251
+ let dataCodewords = [];
1252
+ while (dataCodewords.length * 8 < bb.length)
1253
+ dataCodewords.push(0);
1254
+ bb.forEach((b, i) => dataCodewords[i >>> 3] |= b << 7 - (i & 7));
1255
+ return new _QrCode2(version, ecl, dataCodewords, mask);
1256
+ }
1257
+ /*-- Accessor methods --*/
1258
+ // Returns the color of the module (pixel) at the given coordinates, which is false
1259
+ // for light or true for dark. The top left corner has the coordinates (x=0, y=0).
1260
+ // If the given coordinates are out of bounds, then false (light) is returned.
1261
+ getModule(x, y) {
1262
+ return 0 <= x && x < this.size && 0 <= y && y < this.size && this.modules[y][x];
1263
+ }
1264
+ // Modified to expose modules for easy access
1265
+ getModules() {
1266
+ return this.modules;
1267
+ }
1268
+ /*-- Private helper methods for constructor: Drawing function modules --*/
1269
+ // Reads this object's version field, and draws and marks all function modules.
1270
+ drawFunctionPatterns() {
1271
+ for (let i = 0; i < this.size; i++) {
1272
+ this.setFunctionModule(6, i, i % 2 == 0);
1273
+ this.setFunctionModule(i, 6, i % 2 == 0);
1274
+ }
1275
+ this.drawFinderPattern(3, 3);
1276
+ this.drawFinderPattern(this.size - 4, 3);
1277
+ this.drawFinderPattern(3, this.size - 4);
1278
+ const alignPatPos = this.getAlignmentPatternPositions();
1279
+ const numAlign = alignPatPos.length;
1280
+ for (let i = 0; i < numAlign; i++) {
1281
+ for (let j = 0; j < numAlign; j++) {
1282
+ if (!(i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0))
1283
+ this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
1284
+ }
1285
+ }
1286
+ this.drawFormatBits(0);
1287
+ this.drawVersion();
1288
+ }
1289
+ // Draws two copies of the format bits (with its own error correction code)
1290
+ // based on the given mask and this object's error correction level field.
1291
+ drawFormatBits(mask) {
1292
+ const data = this.errorCorrectionLevel.formatBits << 3 | mask;
1293
+ let rem = data;
1294
+ for (let i = 0; i < 10; i++)
1295
+ rem = rem << 1 ^ (rem >>> 9) * 1335;
1296
+ const bits = (data << 10 | rem) ^ 21522;
1297
+ assert(bits >>> 15 == 0);
1298
+ for (let i = 0; i <= 5; i++)
1299
+ this.setFunctionModule(8, i, getBit(bits, i));
1300
+ this.setFunctionModule(8, 7, getBit(bits, 6));
1301
+ this.setFunctionModule(8, 8, getBit(bits, 7));
1302
+ this.setFunctionModule(7, 8, getBit(bits, 8));
1303
+ for (let i = 9; i < 15; i++)
1304
+ this.setFunctionModule(14 - i, 8, getBit(bits, i));
1305
+ for (let i = 0; i < 8; i++)
1306
+ this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
1307
+ for (let i = 8; i < 15; i++)
1308
+ this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
1309
+ this.setFunctionModule(8, this.size - 8, true);
1310
+ }
1311
+ // Draws two copies of the version bits (with its own error correction code),
1312
+ // based on this object's version field, iff 7 <= version <= 40.
1313
+ drawVersion() {
1314
+ if (this.version < 7)
1315
+ return;
1316
+ let rem = this.version;
1317
+ for (let i = 0; i < 12; i++)
1318
+ rem = rem << 1 ^ (rem >>> 11) * 7973;
1319
+ const bits = this.version << 12 | rem;
1320
+ assert(bits >>> 18 == 0);
1321
+ for (let i = 0; i < 18; i++) {
1322
+ const color = getBit(bits, i);
1323
+ const a = this.size - 11 + i % 3;
1324
+ const b = Math.floor(i / 3);
1325
+ this.setFunctionModule(a, b, color);
1326
+ this.setFunctionModule(b, a, color);
1327
+ }
1328
+ }
1329
+ // Draws a 9*9 finder pattern including the border separator,
1330
+ // with the center module at (x, y). Modules can be out of bounds.
1331
+ drawFinderPattern(x, y) {
1332
+ for (let dy = -4; dy <= 4; dy++) {
1333
+ for (let dx = -4; dx <= 4; dx++) {
1334
+ const dist = Math.max(Math.abs(dx), Math.abs(dy));
1335
+ const xx = x + dx;
1336
+ const yy = y + dy;
1337
+ if (0 <= xx && xx < this.size && 0 <= yy && yy < this.size)
1338
+ this.setFunctionModule(xx, yy, dist != 2 && dist != 4);
1339
+ }
1340
+ }
1341
+ }
1342
+ // Draws a 5*5 alignment pattern, with the center module
1343
+ // at (x, y). All modules must be in bounds.
1344
+ drawAlignmentPattern(x, y) {
1345
+ for (let dy = -2; dy <= 2; dy++) {
1346
+ for (let dx = -2; dx <= 2; dx++)
1347
+ this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1);
1348
+ }
1349
+ }
1350
+ // Sets the color of a module and marks it as a function module.
1351
+ // Only used by the constructor. Coordinates must be in bounds.
1352
+ setFunctionModule(x, y, isDark) {
1353
+ this.modules[y][x] = isDark;
1354
+ this.isFunction[y][x] = true;
1355
+ }
1356
+ /*-- Private helper methods for constructor: Codewords and masking --*/
1357
+ // Returns a new byte string representing the given data with the appropriate error correction
1358
+ // codewords appended to it, based on this object's version and error correction level.
1359
+ addEccAndInterleave(data) {
1360
+ const ver = this.version;
1361
+ const ecl = this.errorCorrectionLevel;
1362
+ if (data.length != _QrCode2.getNumDataCodewords(ver, ecl))
1363
+ throw new RangeError("Invalid argument");
1364
+ const numBlocks = _QrCode2.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
1365
+ const blockEccLen = _QrCode2.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver];
1366
+ const rawCodewords = Math.floor(_QrCode2.getNumRawDataModules(ver) / 8);
1367
+ const numShortBlocks = numBlocks - rawCodewords % numBlocks;
1368
+ const shortBlockLen = Math.floor(rawCodewords / numBlocks);
1369
+ let blocks = [];
1370
+ const rsDiv = _QrCode2.reedSolomonComputeDivisor(blockEccLen);
1371
+ for (let i = 0, k = 0; i < numBlocks; i++) {
1372
+ let dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
1373
+ k += dat.length;
1374
+ const ecc = _QrCode2.reedSolomonComputeRemainder(dat, rsDiv);
1375
+ if (i < numShortBlocks)
1376
+ dat.push(0);
1377
+ blocks.push(dat.concat(ecc));
1378
+ }
1379
+ let result = [];
1380
+ for (let i = 0; i < blocks[0].length; i++) {
1381
+ blocks.forEach((block, j) => {
1382
+ if (i != shortBlockLen - blockEccLen || j >= numShortBlocks)
1383
+ result.push(block[i]);
1384
+ });
1385
+ }
1386
+ assert(result.length == rawCodewords);
1387
+ return result;
1388
+ }
1389
+ // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
1390
+ // data area of this QR Code. Function modules need to be marked off before this is called.
1391
+ drawCodewords(data) {
1392
+ if (data.length != Math.floor(_QrCode2.getNumRawDataModules(this.version) / 8))
1393
+ throw new RangeError("Invalid argument");
1394
+ let i = 0;
1395
+ for (let right = this.size - 1; right >= 1; right -= 2) {
1396
+ if (right == 6)
1397
+ right = 5;
1398
+ for (let vert = 0; vert < this.size; vert++) {
1399
+ for (let j = 0; j < 2; j++) {
1400
+ const x = right - j;
1401
+ const upward = (right + 1 & 2) == 0;
1402
+ const y = upward ? this.size - 1 - vert : vert;
1403
+ if (!this.isFunction[y][x] && i < data.length * 8) {
1404
+ this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
1405
+ i++;
1406
+ }
1407
+ }
1408
+ }
1409
+ }
1410
+ assert(i == data.length * 8);
1411
+ }
1412
+ // XORs the codeword modules in this QR Code with the given mask pattern.
1413
+ // The function modules must be marked and the codeword bits must be drawn
1414
+ // before masking. Due to the arithmetic of XOR, calling applyMask() with
1415
+ // the same mask value a second time will undo the mask. A final well-formed
1416
+ // QR Code needs exactly one (not zero, two, etc.) mask applied.
1417
+ applyMask(mask) {
1418
+ if (mask < 0 || mask > 7)
1419
+ throw new RangeError("Mask value out of range");
1420
+ for (let y = 0; y < this.size; y++) {
1421
+ for (let x = 0; x < this.size; x++) {
1422
+ let invert;
1423
+ switch (mask) {
1424
+ case 0:
1425
+ invert = (x + y) % 2 == 0;
1426
+ break;
1427
+ case 1:
1428
+ invert = y % 2 == 0;
1429
+ break;
1430
+ case 2:
1431
+ invert = x % 3 == 0;
1432
+ break;
1433
+ case 3:
1434
+ invert = (x + y) % 3 == 0;
1435
+ break;
1436
+ case 4:
1437
+ invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 == 0;
1438
+ break;
1439
+ case 5:
1440
+ invert = x * y % 2 + x * y % 3 == 0;
1441
+ break;
1442
+ case 6:
1443
+ invert = (x * y % 2 + x * y % 3) % 2 == 0;
1444
+ break;
1445
+ case 7:
1446
+ invert = ((x + y) % 2 + x * y % 3) % 2 == 0;
1447
+ break;
1448
+ default:
1449
+ throw new Error("Unreachable");
1450
+ }
1451
+ if (!this.isFunction[y][x] && invert)
1452
+ this.modules[y][x] = !this.modules[y][x];
1453
+ }
1454
+ }
1455
+ }
1456
+ // Calculates and returns the penalty score based on state of this QR Code's current modules.
1457
+ // This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
1458
+ getPenaltyScore() {
1459
+ let result = 0;
1460
+ for (let y = 0; y < this.size; y++) {
1461
+ let runColor = false;
1462
+ let runX = 0;
1463
+ let runHistory = [0, 0, 0, 0, 0, 0, 0];
1464
+ for (let x = 0; x < this.size; x++) {
1465
+ if (this.modules[y][x] == runColor) {
1466
+ runX++;
1467
+ if (runX == 5)
1468
+ result += _QrCode2.PENALTY_N1;
1469
+ else if (runX > 5)
1470
+ result++;
1471
+ } else {
1472
+ this.finderPenaltyAddHistory(runX, runHistory);
1473
+ if (!runColor)
1474
+ result += this.finderPenaltyCountPatterns(runHistory) * _QrCode2.PENALTY_N3;
1475
+ runColor = this.modules[y][x];
1476
+ runX = 1;
1477
+ }
1478
+ }
1479
+ result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * _QrCode2.PENALTY_N3;
1480
+ }
1481
+ for (let x = 0; x < this.size; x++) {
1482
+ let runColor = false;
1483
+ let runY = 0;
1484
+ let runHistory = [0, 0, 0, 0, 0, 0, 0];
1485
+ for (let y = 0; y < this.size; y++) {
1486
+ if (this.modules[y][x] == runColor) {
1487
+ runY++;
1488
+ if (runY == 5)
1489
+ result += _QrCode2.PENALTY_N1;
1490
+ else if (runY > 5)
1491
+ result++;
1492
+ } else {
1493
+ this.finderPenaltyAddHistory(runY, runHistory);
1494
+ if (!runColor)
1495
+ result += this.finderPenaltyCountPatterns(runHistory) * _QrCode2.PENALTY_N3;
1496
+ runColor = this.modules[y][x];
1497
+ runY = 1;
1498
+ }
1499
+ }
1500
+ result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * _QrCode2.PENALTY_N3;
1501
+ }
1502
+ for (let y = 0; y < this.size - 1; y++) {
1503
+ for (let x = 0; x < this.size - 1; x++) {
1504
+ const color = this.modules[y][x];
1505
+ if (color == this.modules[y][x + 1] && color == this.modules[y + 1][x] && color == this.modules[y + 1][x + 1])
1506
+ result += _QrCode2.PENALTY_N2;
1507
+ }
1508
+ }
1509
+ let dark = 0;
1510
+ for (const row of this.modules)
1511
+ dark = row.reduce((sum, color) => sum + (color ? 1 : 0), dark);
1512
+ const total = this.size * this.size;
1513
+ const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
1514
+ assert(0 <= k && k <= 9);
1515
+ result += k * _QrCode2.PENALTY_N4;
1516
+ assert(0 <= result && result <= 2568888);
1517
+ return result;
1518
+ }
1519
+ /*-- Private helper functions --*/
1520
+ // Returns an ascending list of positions of alignment patterns for this version number.
1521
+ // Each position is in the range [0,177), and are used on both the x and y axes.
1522
+ // This could be implemented as lookup table of 40 variable-length lists of integers.
1523
+ getAlignmentPatternPositions() {
1524
+ if (this.version == 1)
1525
+ return [];
1526
+ else {
1527
+ const numAlign = Math.floor(this.version / 7) + 2;
1528
+ const step = this.version == 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
1529
+ let result = [6];
1530
+ for (let pos = this.size - 7; result.length < numAlign; pos -= step)
1531
+ result.splice(1, 0, pos);
1532
+ return result;
1533
+ }
1534
+ }
1535
+ // Returns the number of data bits that can be stored in a QR Code of the given version number, after
1536
+ // all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
1537
+ // The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
1538
+ static getNumRawDataModules(ver) {
1539
+ if (ver < _QrCode2.MIN_VERSION || ver > _QrCode2.MAX_VERSION)
1540
+ throw new RangeError("Version number out of range");
1541
+ let result = (16 * ver + 128) * ver + 64;
1542
+ if (ver >= 2) {
1543
+ const numAlign = Math.floor(ver / 7) + 2;
1544
+ result -= (25 * numAlign - 10) * numAlign - 55;
1545
+ if (ver >= 7)
1546
+ result -= 36;
1547
+ }
1548
+ assert(208 <= result && result <= 29648);
1549
+ return result;
1550
+ }
1551
+ // Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
1552
+ // QR Code of the given version number and error correction level, with remainder bits discarded.
1553
+ // This stateless pure function could be implemented as a (40*4)-cell lookup table.
1554
+ static getNumDataCodewords(ver, ecl) {
1555
+ return Math.floor(_QrCode2.getNumRawDataModules(ver) / 8) - _QrCode2.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] * _QrCode2.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
1556
+ }
1557
+ // Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be
1558
+ // implemented as a lookup table over all possible parameter values, instead of as an algorithm.
1559
+ static reedSolomonComputeDivisor(degree) {
1560
+ if (degree < 1 || degree > 255)
1561
+ throw new RangeError("Degree out of range");
1562
+ let result = [];
1563
+ for (let i = 0; i < degree - 1; i++)
1564
+ result.push(0);
1565
+ result.push(1);
1566
+ let root = 1;
1567
+ for (let i = 0; i < degree; i++) {
1568
+ for (let j = 0; j < result.length; j++) {
1569
+ result[j] = _QrCode2.reedSolomonMultiply(result[j], root);
1570
+ if (j + 1 < result.length)
1571
+ result[j] ^= result[j + 1];
1572
+ }
1573
+ root = _QrCode2.reedSolomonMultiply(root, 2);
1574
+ }
1575
+ return result;
1576
+ }
1577
+ // Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
1578
+ static reedSolomonComputeRemainder(data, divisor) {
1579
+ let result = divisor.map((_) => 0);
1580
+ for (const b of data) {
1581
+ const factor = b ^ result.shift();
1582
+ result.push(0);
1583
+ divisor.forEach((coef, i) => result[i] ^= _QrCode2.reedSolomonMultiply(coef, factor));
1584
+ }
1585
+ return result;
1586
+ }
1587
+ // Returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and result
1588
+ // are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8.
1589
+ static reedSolomonMultiply(x, y) {
1590
+ if (x >>> 8 != 0 || y >>> 8 != 0)
1591
+ throw new RangeError("Byte out of range");
1592
+ let z = 0;
1593
+ for (let i = 7; i >= 0; i--) {
1594
+ z = z << 1 ^ (z >>> 7) * 285;
1595
+ z ^= (y >>> i & 1) * x;
1596
+ }
1597
+ assert(z >>> 8 == 0);
1598
+ return z;
1599
+ }
1600
+ // Can only be called immediately after a light run is added, and
1601
+ // returns either 0, 1, or 2. A helper function for getPenaltyScore().
1602
+ finderPenaltyCountPatterns(runHistory) {
1603
+ const n = runHistory[1];
1604
+ assert(n <= this.size * 3);
1605
+ const core = n > 0 && runHistory[2] == n && runHistory[3] == n * 3 && runHistory[4] == n && runHistory[5] == n;
1606
+ return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0) + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0);
1607
+ }
1608
+ // Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
1609
+ finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
1610
+ if (currentRunColor) {
1611
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
1612
+ currentRunLength = 0;
1613
+ }
1614
+ currentRunLength += this.size;
1615
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
1616
+ return this.finderPenaltyCountPatterns(runHistory);
1617
+ }
1618
+ // Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
1619
+ finderPenaltyAddHistory(currentRunLength, runHistory) {
1620
+ if (runHistory[0] == 0)
1621
+ currentRunLength += this.size;
1622
+ runHistory.pop();
1623
+ runHistory.unshift(currentRunLength);
1624
+ }
1625
+ };
1626
+ _QrCode.MIN_VERSION = 1;
1627
+ _QrCode.MAX_VERSION = 40;
1628
+ _QrCode.PENALTY_N1 = 3;
1629
+ _QrCode.PENALTY_N2 = 3;
1630
+ _QrCode.PENALTY_N3 = 40;
1631
+ _QrCode.PENALTY_N4 = 10;
1632
+ _QrCode.ECC_CODEWORDS_PER_BLOCK = [
1633
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
1634
+ //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
1635
+ [-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],
1636
+ // Low
1637
+ [-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],
1638
+ // Medium
1639
+ [-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],
1640
+ // Quartile
1641
+ [-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]
1642
+ // High
1643
+ ];
1644
+ _QrCode.NUM_ERROR_CORRECTION_BLOCKS = [
1645
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
1646
+ //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
1647
+ [-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],
1648
+ // Low
1649
+ [-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],
1650
+ // Medium
1651
+ [-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],
1652
+ // Quartile
1653
+ [-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]
1654
+ // High
1655
+ ];
1656
+ qrcodegen2.QrCode = _QrCode;
1657
+ function appendBits(val, len, bb) {
1658
+ if (len < 0 || len > 31 || val >>> len != 0)
1659
+ throw new RangeError("Value out of range");
1660
+ for (let i = len - 1; i >= 0; i--)
1661
+ bb.push(val >>> i & 1);
1662
+ }
1663
+ function getBit(x, i) {
1664
+ return (x >>> i & 1) != 0;
1665
+ }
1666
+ function assert(cond) {
1667
+ if (!cond)
1668
+ throw new Error("Assertion error");
1669
+ }
1670
+ const _QrSegment = class _QrSegment2 {
1671
+ /*-- Constructor (low level) and fields --*/
1672
+ // Creates a new QR Code segment with the given attributes and data.
1673
+ // The character count (numChars) must agree with the mode and the bit buffer length,
1674
+ // but the constraint isn't checked. The given bit buffer is cloned and stored.
1675
+ constructor(mode, numChars, bitData) {
1676
+ this.mode = mode;
1677
+ this.numChars = numChars;
1678
+ this.bitData = bitData;
1679
+ if (numChars < 0)
1680
+ throw new RangeError("Invalid argument");
1681
+ this.bitData = bitData.slice();
1682
+ }
1683
+ /*-- Static factory functions (mid level) --*/
1684
+ // Returns a segment representing the given binary data encoded in
1685
+ // byte mode. All input byte arrays are acceptable. Any text string
1686
+ // can be converted to UTF-8 bytes and encoded as a byte mode segment.
1687
+ static makeBytes(data) {
1688
+ let bb = [];
1689
+ for (const b of data)
1690
+ appendBits(b, 8, bb);
1691
+ return new _QrSegment2(_QrSegment2.Mode.BYTE, data.length, bb);
1692
+ }
1693
+ // Returns a segment representing the given string of decimal digits encoded in numeric mode.
1694
+ static makeNumeric(digits) {
1695
+ if (!_QrSegment2.isNumeric(digits))
1696
+ throw new RangeError("String contains non-numeric characters");
1697
+ let bb = [];
1698
+ for (let i = 0; i < digits.length; ) {
1699
+ const n = Math.min(digits.length - i, 3);
1700
+ appendBits(parseInt(digits.substring(i, i + n), 10), n * 3 + 1, bb);
1701
+ i += n;
1702
+ }
1703
+ return new _QrSegment2(_QrSegment2.Mode.NUMERIC, digits.length, bb);
1704
+ }
1705
+ // Returns a segment representing the given text string encoded in alphanumeric mode.
1706
+ // The characters allowed are: 0 to 9, A to Z (uppercase only), space,
1707
+ // dollar, percent, asterisk, plus, hyphen, period, slash, colon.
1708
+ static makeAlphanumeric(text) {
1709
+ if (!_QrSegment2.isAlphanumeric(text))
1710
+ throw new RangeError("String contains unencodable characters in alphanumeric mode");
1711
+ let bb = [];
1712
+ let i;
1713
+ for (i = 0; i + 2 <= text.length; i += 2) {
1714
+ let temp = _QrSegment2.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
1715
+ temp += _QrSegment2.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
1716
+ appendBits(temp, 11, bb);
1717
+ }
1718
+ if (i < text.length)
1719
+ appendBits(_QrSegment2.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
1720
+ return new _QrSegment2(_QrSegment2.Mode.ALPHANUMERIC, text.length, bb);
1721
+ }
1722
+ // Returns a new mutable list of zero or more segments to represent the given Unicode text string.
1723
+ // The result may use various segment modes and switch modes to optimize the length of the bit stream.
1724
+ static makeSegments(text) {
1725
+ if (text == "")
1726
+ return [];
1727
+ else if (_QrSegment2.isNumeric(text))
1728
+ return [_QrSegment2.makeNumeric(text)];
1729
+ else if (_QrSegment2.isAlphanumeric(text))
1730
+ return [_QrSegment2.makeAlphanumeric(text)];
1731
+ else
1732
+ return [_QrSegment2.makeBytes(_QrSegment2.toUtf8ByteArray(text))];
1733
+ }
1734
+ // Returns a segment representing an Extended Channel Interpretation
1735
+ // (ECI) designator with the given assignment value.
1736
+ static makeEci(assignVal) {
1737
+ let bb = [];
1738
+ if (assignVal < 0)
1739
+ throw new RangeError("ECI assignment value out of range");
1740
+ else if (assignVal < 1 << 7)
1741
+ appendBits(assignVal, 8, bb);
1742
+ else if (assignVal < 1 << 14) {
1743
+ appendBits(2, 2, bb);
1744
+ appendBits(assignVal, 14, bb);
1745
+ } else if (assignVal < 1e6) {
1746
+ appendBits(6, 3, bb);
1747
+ appendBits(assignVal, 21, bb);
1748
+ } else
1749
+ throw new RangeError("ECI assignment value out of range");
1750
+ return new _QrSegment2(_QrSegment2.Mode.ECI, 0, bb);
1751
+ }
1752
+ // Tests whether the given string can be encoded as a segment in numeric mode.
1753
+ // A string is encodable iff each character is in the range 0 to 9.
1754
+ static isNumeric(text) {
1755
+ return _QrSegment2.NUMERIC_REGEX.test(text);
1756
+ }
1757
+ // Tests whether the given string can be encoded as a segment in alphanumeric mode.
1758
+ // A string is encodable iff each character is in the following set: 0 to 9, A to Z
1759
+ // (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
1760
+ static isAlphanumeric(text) {
1761
+ return _QrSegment2.ALPHANUMERIC_REGEX.test(text);
1762
+ }
1763
+ /*-- Methods --*/
1764
+ // Returns a new copy of the data bits of this segment.
1765
+ getData() {
1766
+ return this.bitData.slice();
1767
+ }
1768
+ // (Package-private) Calculates and returns the number of bits needed to encode the given segments at
1769
+ // the given version. The result is infinity if a segment has too many characters to fit its length field.
1770
+ static getTotalBits(segs, version) {
1771
+ let result = 0;
1772
+ for (const seg of segs) {
1773
+ const ccbits = seg.mode.numCharCountBits(version);
1774
+ if (seg.numChars >= 1 << ccbits)
1775
+ return Infinity;
1776
+ result += 4 + ccbits + seg.bitData.length;
1777
+ }
1778
+ return result;
1779
+ }
1780
+ // Returns a new array of bytes representing the given string encoded in UTF-8.
1781
+ static toUtf8ByteArray(str) {
1782
+ str = encodeURI(str);
1783
+ let result = [];
1784
+ for (let i = 0; i < str.length; i++) {
1785
+ if (str.charAt(i) != "%")
1786
+ result.push(str.charCodeAt(i));
1787
+ else {
1788
+ result.push(parseInt(str.substring(i + 1, i + 3), 16));
1789
+ i += 2;
1790
+ }
1791
+ }
1792
+ return result;
1793
+ }
1794
+ };
1795
+ _QrSegment.NUMERIC_REGEX = /^[0-9]*$/;
1796
+ _QrSegment.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
1797
+ _QrSegment.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
1798
+ let QrSegment = _QrSegment;
1799
+ qrcodegen2.QrSegment = _QrSegment;
1800
+ })(qrcodegen || (qrcodegen = {}));
1801
+ ((qrcodegen2) => {
1802
+ ((QrCode2) => {
1803
+ const _Ecc = class _Ecc {
1804
+ // The QR Code can tolerate about 30% erroneous codewords
1805
+ /*-- Constructor and fields --*/
1806
+ constructor(ordinal, formatBits) {
1807
+ this.ordinal = ordinal;
1808
+ this.formatBits = formatBits;
1809
+ }
1810
+ };
1811
+ _Ecc.LOW = new _Ecc(0, 1);
1812
+ _Ecc.MEDIUM = new _Ecc(1, 0);
1813
+ _Ecc.QUARTILE = new _Ecc(2, 3);
1814
+ _Ecc.HIGH = new _Ecc(3, 2);
1815
+ QrCode2.Ecc = _Ecc;
1816
+ })(qrcodegen2.QrCode || (qrcodegen2.QrCode = {}));
1817
+ })(qrcodegen || (qrcodegen = {}));
1818
+ ((qrcodegen2) => {
1819
+ ((QrSegment2) => {
1820
+ const _Mode = class _Mode {
1821
+ /*-- Constructor and fields --*/
1822
+ constructor(modeBits, numBitsCharCount) {
1823
+ this.modeBits = modeBits;
1824
+ this.numBitsCharCount = numBitsCharCount;
1825
+ }
1826
+ /*-- Method --*/
1827
+ // (Package-private) Returns the bit width of the character count field for a segment in
1828
+ // this mode in a QR Code at the given version number. The result is in the range [0, 16].
1829
+ numCharCountBits(ver) {
1830
+ return this.numBitsCharCount[Math.floor((ver + 7) / 17)];
1831
+ }
1832
+ };
1833
+ _Mode.NUMERIC = new _Mode(1, [10, 12, 14]);
1834
+ _Mode.ALPHANUMERIC = new _Mode(2, [9, 11, 13]);
1835
+ _Mode.BYTE = new _Mode(4, [8, 16, 16]);
1836
+ _Mode.KANJI = new _Mode(8, [8, 10, 12]);
1837
+ _Mode.ECI = new _Mode(7, [0, 0, 0]);
1838
+ QrSegment2.Mode = _Mode;
1839
+ })(qrcodegen2.QrSegment || (qrcodegen2.QrSegment = {}));
1840
+ })(qrcodegen || (qrcodegen = {}));
1841
+ var qrcodegen_default = qrcodegen;
1842
+ /**
1843
+ * @license qrcode.react
1844
+ * Copyright (c) Paul O'Shannessy
1845
+ * SPDX-License-Identifier: ISC
1846
+ */
1847
+ var ERROR_LEVEL_MAP = {
1848
+ L: qrcodegen_default.QrCode.Ecc.LOW,
1849
+ M: qrcodegen_default.QrCode.Ecc.MEDIUM,
1850
+ Q: qrcodegen_default.QrCode.Ecc.QUARTILE,
1851
+ H: qrcodegen_default.QrCode.Ecc.HIGH
1852
+ };
1853
+ var DEFAULT_SIZE = 128;
1854
+ var DEFAULT_LEVEL = "L";
1855
+ var DEFAULT_BGCOLOR = "#FFFFFF";
1856
+ var DEFAULT_FGCOLOR = "#000000";
1857
+ var DEFAULT_INCLUDEMARGIN = false;
1858
+ var DEFAULT_MINVERSION = 1;
1859
+ var SPEC_MARGIN_SIZE = 4;
1860
+ var DEFAULT_MARGIN_SIZE = 0;
1861
+ var DEFAULT_IMG_SCALE = 0.1;
1862
+ function generatePath(modules, margin = 0) {
1863
+ const ops = [];
1864
+ modules.forEach(function(row, y) {
1865
+ let start = null;
1866
+ row.forEach(function(cell, x) {
1867
+ if (!cell && start !== null) {
1868
+ ops.push(
1869
+ `M${start + margin} ${y + margin}h${x - start}v1H${start + margin}z`
1870
+ );
1871
+ start = null;
1872
+ return;
1873
+ }
1874
+ if (x === row.length - 1) {
1875
+ if (!cell) {
1876
+ return;
1877
+ }
1878
+ if (start === null) {
1879
+ ops.push(`M${x + margin},${y + margin} h1v1H${x + margin}z`);
1880
+ } else {
1881
+ ops.push(
1882
+ `M${start + margin},${y + margin} h${x + 1 - start}v1H${start + margin}z`
1883
+ );
1884
+ }
1885
+ return;
1886
+ }
1887
+ if (cell && start === null) {
1888
+ start = x;
1889
+ }
1890
+ });
1891
+ });
1892
+ return ops.join("");
1893
+ }
1894
+ function excavateModules(modules, excavation) {
1895
+ return modules.slice().map((row, y) => {
1896
+ if (y < excavation.y || y >= excavation.y + excavation.h) {
1897
+ return row;
1898
+ }
1899
+ return row.map((cell, x) => {
1900
+ if (x < excavation.x || x >= excavation.x + excavation.w) {
1901
+ return cell;
1902
+ }
1903
+ return false;
1904
+ });
1905
+ });
1906
+ }
1907
+ function getImageSettings(cells, size, margin, imageSettings) {
1908
+ if (imageSettings == null) {
1909
+ return null;
1910
+ }
1911
+ const numCells = cells.length + margin * 2;
1912
+ const defaultSize = Math.floor(size * DEFAULT_IMG_SCALE);
1913
+ const scale = numCells / size;
1914
+ const w = (imageSettings.width || defaultSize) * scale;
1915
+ const h = (imageSettings.height || defaultSize) * scale;
1916
+ const x = imageSettings.x == null ? cells.length / 2 - w / 2 : imageSettings.x * scale;
1917
+ const y = imageSettings.y == null ? cells.length / 2 - h / 2 : imageSettings.y * scale;
1918
+ const opacity = imageSettings.opacity == null ? 1 : imageSettings.opacity;
1919
+ let excavation = null;
1920
+ if (imageSettings.excavate) {
1921
+ let floorX = Math.floor(x);
1922
+ let floorY = Math.floor(y);
1923
+ let ceilW = Math.ceil(w + x - floorX);
1924
+ let ceilH = Math.ceil(h + y - floorY);
1925
+ excavation = { x: floorX, y: floorY, w: ceilW, h: ceilH };
1926
+ }
1927
+ const crossOrigin = imageSettings.crossOrigin;
1928
+ return { x, y, h, w, excavation, opacity, crossOrigin };
1929
+ }
1930
+ function getMarginSize(includeMargin, marginSize) {
1931
+ if (marginSize != null) {
1932
+ return Math.max(Math.floor(marginSize), 0);
1933
+ }
1934
+ return includeMargin ? SPEC_MARGIN_SIZE : DEFAULT_MARGIN_SIZE;
1935
+ }
1936
+ function useQRCode({
1937
+ value,
1938
+ level,
1939
+ minVersion,
1940
+ includeMargin,
1941
+ marginSize,
1942
+ imageSettings,
1943
+ size,
1944
+ boostLevel
1945
+ }) {
1946
+ let qrcode = React.useMemo(() => {
1947
+ const values = Array.isArray(value) ? value : [value];
1948
+ const segments = values.reduce((accum, v) => {
1949
+ accum.push(...qrcodegen_default.QrSegment.makeSegments(v));
1950
+ return accum;
1951
+ }, []);
1952
+ return qrcodegen_default.QrCode.encodeSegments(
1953
+ segments,
1954
+ ERROR_LEVEL_MAP[level],
1955
+ minVersion,
1956
+ void 0,
1957
+ void 0,
1958
+ boostLevel
1959
+ );
1960
+ }, [value, level, minVersion, boostLevel]);
1961
+ const { cells, margin, numCells, calculatedImageSettings } = React.useMemo(() => {
1962
+ let cells2 = qrcode.getModules();
1963
+ const margin2 = getMarginSize(includeMargin, marginSize);
1964
+ const numCells2 = cells2.length + margin2 * 2;
1965
+ const calculatedImageSettings2 = getImageSettings(
1966
+ cells2,
1967
+ size,
1968
+ margin2,
1969
+ imageSettings
1970
+ );
1971
+ return {
1972
+ cells: cells2,
1973
+ margin: margin2,
1974
+ numCells: numCells2,
1975
+ calculatedImageSettings: calculatedImageSettings2
1976
+ };
1977
+ }, [qrcode, size, imageSettings, includeMargin, marginSize]);
1978
+ return {
1979
+ qrcode,
1980
+ margin,
1981
+ cells,
1982
+ numCells,
1983
+ calculatedImageSettings
1984
+ };
1985
+ }
1986
+ var SUPPORTS_PATH2D = function() {
1987
+ try {
1988
+ new Path2D().addPath(new Path2D());
1989
+ } catch (e) {
1990
+ return false;
1991
+ }
1992
+ return true;
1993
+ }();
1994
+ var QRCodeCanvas = React.forwardRef(
1995
+ function QRCodeCanvas2(props, forwardedRef) {
1996
+ const _a = props, {
1997
+ value,
1998
+ size = DEFAULT_SIZE,
1999
+ level = DEFAULT_LEVEL,
2000
+ bgColor = DEFAULT_BGCOLOR,
2001
+ fgColor = DEFAULT_FGCOLOR,
2002
+ includeMargin = DEFAULT_INCLUDEMARGIN,
2003
+ minVersion = DEFAULT_MINVERSION,
2004
+ boostLevel,
2005
+ marginSize,
2006
+ imageSettings
2007
+ } = _a, extraProps = __objRest(_a, [
2008
+ "value",
2009
+ "size",
2010
+ "level",
2011
+ "bgColor",
2012
+ "fgColor",
2013
+ "includeMargin",
2014
+ "minVersion",
2015
+ "boostLevel",
2016
+ "marginSize",
2017
+ "imageSettings"
2018
+ ]);
2019
+ const _b = extraProps, { style } = _b, otherProps = __objRest(_b, ["style"]);
2020
+ const imgSrc = imageSettings == null ? void 0 : imageSettings.src;
2021
+ const _canvas = React.useRef(null);
2022
+ const _image = React.useRef(null);
2023
+ const setCanvasRef = React.useCallback(
2024
+ (node) => {
2025
+ _canvas.current = node;
2026
+ if (typeof forwardedRef === "function") {
2027
+ forwardedRef(node);
2028
+ } else if (forwardedRef) {
2029
+ forwardedRef.current = node;
2030
+ }
1124
2031
  },
1125
- children: [
1126
- currency,
1127
- " Payment QR"
1128
- ]
2032
+ [forwardedRef]
2033
+ );
2034
+ const [isImgLoaded, setIsImageLoaded] = React.useState(false);
2035
+ const { margin, cells, numCells, calculatedImageSettings } = useQRCode({
2036
+ value,
2037
+ level,
2038
+ minVersion,
2039
+ boostLevel,
2040
+ includeMargin,
2041
+ marginSize,
2042
+ imageSettings,
2043
+ size
2044
+ });
2045
+ React.useEffect(() => {
2046
+ if (_canvas.current != null) {
2047
+ const canvas = _canvas.current;
2048
+ const ctx = canvas.getContext("2d");
2049
+ if (!ctx) {
2050
+ return;
2051
+ }
2052
+ let cellsToDraw = cells;
2053
+ const image = _image.current;
2054
+ const haveImageToRender = calculatedImageSettings != null && image !== null && image.complete && image.naturalHeight !== 0 && image.naturalWidth !== 0;
2055
+ if (haveImageToRender) {
2056
+ if (calculatedImageSettings.excavation != null) {
2057
+ cellsToDraw = excavateModules(
2058
+ cells,
2059
+ calculatedImageSettings.excavation
2060
+ );
2061
+ }
2062
+ }
2063
+ const pixelRatio = window.devicePixelRatio || 1;
2064
+ canvas.height = canvas.width = size * pixelRatio;
2065
+ const scale = size / numCells * pixelRatio;
2066
+ ctx.scale(scale, scale);
2067
+ ctx.fillStyle = bgColor;
2068
+ ctx.fillRect(0, 0, numCells, numCells);
2069
+ ctx.fillStyle = fgColor;
2070
+ if (SUPPORTS_PATH2D) {
2071
+ ctx.fill(new Path2D(generatePath(cellsToDraw, margin)));
2072
+ } else {
2073
+ cells.forEach(function(row, rdx) {
2074
+ row.forEach(function(cell, cdx) {
2075
+ if (cell) {
2076
+ ctx.fillRect(cdx + margin, rdx + margin, 1, 1);
2077
+ }
2078
+ });
2079
+ });
2080
+ }
2081
+ if (calculatedImageSettings) {
2082
+ ctx.globalAlpha = calculatedImageSettings.opacity;
2083
+ }
2084
+ if (haveImageToRender) {
2085
+ ctx.drawImage(
2086
+ image,
2087
+ calculatedImageSettings.x + margin,
2088
+ calculatedImageSettings.y + margin,
2089
+ calculatedImageSettings.w,
2090
+ calculatedImageSettings.h
2091
+ );
2092
+ }
2093
+ }
2094
+ });
2095
+ React.useEffect(() => {
2096
+ setIsImageLoaded(false);
2097
+ }, [imgSrc]);
2098
+ const canvasStyle = __spreadValues({ height: size, width: size }, style);
2099
+ let img = null;
2100
+ if (imgSrc != null) {
2101
+ img = /* @__PURE__ */ React.createElement(
2102
+ "img",
2103
+ {
2104
+ src: imgSrc,
2105
+ key: imgSrc,
2106
+ style: { display: "none" },
2107
+ onLoad: () => {
2108
+ setIsImageLoaded(true);
2109
+ },
2110
+ ref: _image,
2111
+ crossOrigin: calculatedImageSettings == null ? void 0 : calculatedImageSettings.crossOrigin
2112
+ }
2113
+ );
1129
2114
  }
1130
- );
1131
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1132
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: theme === "dark" ? "bg-gray-700" : "bg-white", children: qrDisplay }),
1133
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { textAlign: "center", marginTop: "12px", fontSize: "14px" }, children: "Scan with your wallet app to pay" }),
1134
- walletAddress && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: { marginTop: "12px" }, children: [
1135
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: { fontSize: "12px", marginBottom: "4px" }, children: [
2115
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
2116
+ "canvas",
2117
+ __spreadValues({
2118
+ style: canvasStyle,
2119
+ height: size,
2120
+ width: size,
2121
+ ref: setCanvasRef,
2122
+ role: "img"
2123
+ }, otherProps)
2124
+ ), img);
2125
+ }
2126
+ );
2127
+ QRCodeCanvas.displayName = "QRCodeCanvas";
2128
+ var QRCodeSVG = React.forwardRef(
2129
+ function QRCodeSVG2(props, forwardedRef) {
2130
+ const _a = props, {
2131
+ value,
2132
+ size = DEFAULT_SIZE,
2133
+ level = DEFAULT_LEVEL,
2134
+ bgColor = DEFAULT_BGCOLOR,
2135
+ fgColor = DEFAULT_FGCOLOR,
2136
+ includeMargin = DEFAULT_INCLUDEMARGIN,
2137
+ minVersion = DEFAULT_MINVERSION,
2138
+ boostLevel,
2139
+ title,
2140
+ marginSize,
2141
+ imageSettings
2142
+ } = _a, otherProps = __objRest(_a, [
2143
+ "value",
2144
+ "size",
2145
+ "level",
2146
+ "bgColor",
2147
+ "fgColor",
2148
+ "includeMargin",
2149
+ "minVersion",
2150
+ "boostLevel",
2151
+ "title",
2152
+ "marginSize",
2153
+ "imageSettings"
2154
+ ]);
2155
+ const { margin, cells, numCells, calculatedImageSettings } = useQRCode({
2156
+ value,
2157
+ level,
2158
+ minVersion,
2159
+ boostLevel,
2160
+ includeMargin,
2161
+ marginSize,
2162
+ imageSettings,
2163
+ size
2164
+ });
2165
+ let cellsToDraw = cells;
2166
+ let image = null;
2167
+ if (imageSettings != null && calculatedImageSettings != null) {
2168
+ if (calculatedImageSettings.excavation != null) {
2169
+ cellsToDraw = excavateModules(
2170
+ cells,
2171
+ calculatedImageSettings.excavation
2172
+ );
2173
+ }
2174
+ image = /* @__PURE__ */ React.createElement(
2175
+ "image",
2176
+ {
2177
+ href: imageSettings.src,
2178
+ height: calculatedImageSettings.h,
2179
+ width: calculatedImageSettings.w,
2180
+ x: calculatedImageSettings.x + margin,
2181
+ y: calculatedImageSettings.y + margin,
2182
+ preserveAspectRatio: "none",
2183
+ opacity: calculatedImageSettings.opacity,
2184
+ crossOrigin: calculatedImageSettings.crossOrigin
2185
+ }
2186
+ );
2187
+ }
2188
+ const fgPath = generatePath(cellsToDraw, margin);
2189
+ return /* @__PURE__ */ React.createElement(
2190
+ "svg",
2191
+ __spreadValues({
2192
+ height: size,
2193
+ width: size,
2194
+ viewBox: `0 0 ${numCells} ${numCells}`,
2195
+ ref: forwardedRef,
2196
+ role: "img"
2197
+ }, otherProps),
2198
+ !!title && /* @__PURE__ */ React.createElement("title", null, title),
2199
+ /* @__PURE__ */ React.createElement(
2200
+ "path",
2201
+ {
2202
+ fill: bgColor,
2203
+ d: `M0,0 h${numCells}v${numCells}H0z`,
2204
+ shapeRendering: "crispEdges"
2205
+ }
2206
+ ),
2207
+ /* @__PURE__ */ React.createElement("path", { fill: fgColor, d: fgPath, shapeRendering: "crispEdges" }),
2208
+ image
2209
+ );
2210
+ }
2211
+ );
2212
+ QRCodeSVG.displayName = "QRCodeSVG";
2213
+ const QRCode = ({
2214
+ walletAddress,
2215
+ amount,
2216
+ currency,
2217
+ theme = "light",
2218
+ size = 200
2219
+ }) => {
2220
+ const getQRCodeData = () => {
2221
+ if (!walletAddress)
2222
+ return "";
2223
+ const schemes = {
2224
+ "USDT": "ethereum",
2225
+ "USDC": "ethereum",
2226
+ "BNB": "binance",
2227
+ "SOL": "solana",
2228
+ "USDC_SOL": "solana"
2229
+ };
2230
+ const scheme = schemes[currency] || "ethereum";
2231
+ return `${scheme}:${walletAddress}?amount=${amount}&currency=${currency}`;
2232
+ };
2233
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center", children: [
2234
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `p-4 rounded-lg ${theme === "dark" ? "bg-gray-700" : "bg-white"} mb-3`, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
2235
+ QRCodeSVG,
2236
+ {
2237
+ value: getQRCodeData(),
2238
+ size,
2239
+ bgColor: theme === "dark" ? "#374151" : "#ffffff",
2240
+ fgColor: theme === "dark" ? "#ffffff" : "#000000",
2241
+ level: "M",
2242
+ includeMargin: true
2243
+ }
2244
+ ) }),
2245
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `text-center text-sm ${theme === "dark" ? "text-gray-300" : "text-gray-700"}`, children: "Scan with your wallet app to pay" }),
2246
+ walletAddress && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-3 w-full", children: [
2247
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: `text-xs ${theme === "dark" ? "text-gray-400" : "text-gray-500"} mb-1`, children: [
1136
2248
  "Send ",
1137
2249
  amount,
1138
2250
  " ",
1139
2251
  currency,
1140
2252
  " to:"
1141
2253
  ] }),
1142
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: {
1143
- fontSize: "12px",
1144
- fontFamily: "monospace",
1145
- padding: "8px",
1146
- backgroundColor: theme === "dark" ? "#1f2937" : "#f3f4f6",
1147
- borderRadius: "4px",
1148
- overflowWrap: "break-word"
1149
- }, children: walletAddress })
1150
- ] })
2254
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `text-xs font-mono p-2 rounded overflow-auto break-all ${theme === "dark" ? "bg-gray-800 text-gray-300" : "bg-gray-100 text-gray-700"}`, children: walletAddress })
2255
+ ] }),
2256
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-4 w-full", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `p-3 rounded ${theme === "dark" ? "bg-gray-700" : "bg-gray-100"}`, children: [
2257
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { className: `text-sm font-medium mb-2 ${theme === "dark" ? "text-white" : "text-gray-800"}`, children: "Payment Instructions" }),
2258
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("ol", { className: `text-xs space-y-2 ${theme === "dark" ? "text-gray-300" : "text-gray-600"}`, children: [
2259
+ /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: "1. Open your crypto wallet app" }),
2260
+ /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: "2. Scan the QR code above" }),
2261
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { children: [
2262
+ "3. Confirm the payment amount (",
2263
+ amount,
2264
+ " ",
2265
+ currency,
2266
+ ")"
2267
+ ] }),
2268
+ /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: '4. Click "Pay Now" button below after sending the payment' })
2269
+ ] })
2270
+ ] }) })
1151
2271
  ] });
1152
2272
  };
1153
2273
  const PaymentStatus = ({ status, message, theme = "light" }) => {
@@ -1553,7 +2673,7 @@ const DEFAULT_CONFIG = {
1553
2673
  testMode: false,
1554
2674
  theme: "light"
1555
2675
  };
1556
- const VERSION = "1.0.7";
2676
+ const VERSION = "1.0.8";
1557
2677
  export {
1558
2678
  CoinleyCheckout,
1559
2679
  CoinleyModal,