dsh-hello 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -5,7 +5,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function __require() {
8
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
10
+ }) : x)(function(x) {
11
+ if (typeof require !== "undefined") return require.apply(this, arguments);
12
+ throw Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __commonJS = (cb, mod) => function __require2() {
9
15
  try {
10
16
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
17
  } catch (e) {
@@ -983,124 +989,4657 @@ var require_QRCode = __commonJS({
983
989
  ecdata[r][x] = modIndex >= 0 ? modPoly.get(modIndex) : 0;
984
990
  }
985
991
  }
986
- var totalCodeCount = 0;
987
- for (var y = 0; y < rsBlocks.length; y++) {
988
- totalCodeCount += rsBlocks[y].totalCount;
992
+ var totalCodeCount = 0;
993
+ for (var y = 0; y < rsBlocks.length; y++) {
994
+ totalCodeCount += rsBlocks[y].totalCount;
995
+ }
996
+ var data = new Array(totalCodeCount);
997
+ var index = 0;
998
+ for (var z = 0; z < maxDcCount; z++) {
999
+ for (var s = 0; s < rsBlocks.length; s++) {
1000
+ if (z < dcdata[s].length) {
1001
+ data[index++] = dcdata[s][z];
1002
+ }
1003
+ }
1004
+ }
1005
+ for (var xx = 0; xx < maxEcCount; xx++) {
1006
+ for (var t = 0; t < rsBlocks.length; t++) {
1007
+ if (xx < ecdata[t].length) {
1008
+ data[index++] = ecdata[t][xx];
1009
+ }
1010
+ }
1011
+ }
1012
+ return data;
1013
+ };
1014
+ module.exports = QRCode;
1015
+ }
1016
+ });
1017
+
1018
+ // node_modules/.pnpm/qrcode-terminal@0.12.0/node_modules/qrcode-terminal/lib/main.js
1019
+ var require_main = __commonJS({
1020
+ "node_modules/.pnpm/qrcode-terminal@0.12.0/node_modules/qrcode-terminal/lib/main.js"(exports, module) {
1021
+ var QRCode = require_QRCode();
1022
+ var QRErrorCorrectLevel = require_QRErrorCorrectLevel();
1023
+ var black = "\x1B[40m \x1B[0m";
1024
+ var white = "\x1B[47m \x1B[0m";
1025
+ var toCell = function(isBlack) {
1026
+ return isBlack ? black : white;
1027
+ };
1028
+ var repeat = function(color) {
1029
+ return {
1030
+ times: function(count) {
1031
+ return new Array(count).join(color);
1032
+ }
1033
+ };
1034
+ };
1035
+ var fill = function(length, value) {
1036
+ var arr = new Array(length);
1037
+ for (var i = 0; i < length; i++) {
1038
+ arr[i] = value;
1039
+ }
1040
+ return arr;
1041
+ };
1042
+ module.exports = {
1043
+ error: QRErrorCorrectLevel.L,
1044
+ generate: function(input, opts, cb) {
1045
+ if (typeof opts === "function") {
1046
+ cb = opts;
1047
+ opts = {};
1048
+ }
1049
+ var qrcode = new QRCode(-1, this.error);
1050
+ qrcode.addData(input);
1051
+ qrcode.make();
1052
+ var output = "";
1053
+ if (opts && opts.small) {
1054
+ var BLACK = true, WHITE = false;
1055
+ var moduleCount = qrcode.getModuleCount();
1056
+ var moduleData = qrcode.modules.slice();
1057
+ var oddRow = moduleCount % 2 === 1;
1058
+ if (oddRow) {
1059
+ moduleData.push(fill(moduleCount, WHITE));
1060
+ }
1061
+ var platte = {
1062
+ WHITE_ALL: "\u2588",
1063
+ WHITE_BLACK: "\u2580",
1064
+ BLACK_WHITE: "\u2584",
1065
+ BLACK_ALL: " "
1066
+ };
1067
+ var borderTop = repeat(platte.BLACK_WHITE).times(moduleCount + 3);
1068
+ var borderBottom = repeat(platte.WHITE_BLACK).times(moduleCount + 3);
1069
+ output += borderTop + "\n";
1070
+ for (var row = 0; row < moduleCount; row += 2) {
1071
+ output += platte.WHITE_ALL;
1072
+ for (var col = 0; col < moduleCount; col++) {
1073
+ if (moduleData[row][col] === WHITE && moduleData[row + 1][col] === WHITE) {
1074
+ output += platte.WHITE_ALL;
1075
+ } else if (moduleData[row][col] === WHITE && moduleData[row + 1][col] === BLACK) {
1076
+ output += platte.WHITE_BLACK;
1077
+ } else if (moduleData[row][col] === BLACK && moduleData[row + 1][col] === WHITE) {
1078
+ output += platte.BLACK_WHITE;
1079
+ } else {
1080
+ output += platte.BLACK_ALL;
1081
+ }
1082
+ }
1083
+ output += platte.WHITE_ALL + "\n";
1084
+ }
1085
+ if (!oddRow) {
1086
+ output += borderBottom;
1087
+ }
1088
+ } else {
1089
+ var border = repeat(white).times(qrcode.getModuleCount() + 3);
1090
+ output += border + "\n";
1091
+ qrcode.modules.forEach(function(row2) {
1092
+ output += white;
1093
+ output += row2.map(toCell).join("");
1094
+ output += white + "\n";
1095
+ });
1096
+ output += border;
1097
+ }
1098
+ if (cb) cb(output);
1099
+ else console.log(output);
1100
+ },
1101
+ setErrorLevel: function(error) {
1102
+ this.error = QRErrorCorrectLevel[error] || this.error;
1103
+ }
1104
+ };
1105
+ }
1106
+ });
1107
+
1108
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/can-promise.js
1109
+ var require_can_promise = __commonJS({
1110
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/can-promise.js"(exports, module) {
1111
+ module.exports = function() {
1112
+ return typeof Promise === "function" && Promise.prototype && Promise.prototype.then;
1113
+ };
1114
+ }
1115
+ });
1116
+
1117
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js
1118
+ var require_utils = __commonJS({
1119
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js"(exports) {
1120
+ var toSJISFunction;
1121
+ var CODEWORDS_COUNT = [
1122
+ 0,
1123
+ // Not used
1124
+ 26,
1125
+ 44,
1126
+ 70,
1127
+ 100,
1128
+ 134,
1129
+ 172,
1130
+ 196,
1131
+ 242,
1132
+ 292,
1133
+ 346,
1134
+ 404,
1135
+ 466,
1136
+ 532,
1137
+ 581,
1138
+ 655,
1139
+ 733,
1140
+ 815,
1141
+ 901,
1142
+ 991,
1143
+ 1085,
1144
+ 1156,
1145
+ 1258,
1146
+ 1364,
1147
+ 1474,
1148
+ 1588,
1149
+ 1706,
1150
+ 1828,
1151
+ 1921,
1152
+ 2051,
1153
+ 2185,
1154
+ 2323,
1155
+ 2465,
1156
+ 2611,
1157
+ 2761,
1158
+ 2876,
1159
+ 3034,
1160
+ 3196,
1161
+ 3362,
1162
+ 3532,
1163
+ 3706
1164
+ ];
1165
+ exports.getSymbolSize = function getSymbolSize(version) {
1166
+ if (!version) throw new Error('"version" cannot be null or undefined');
1167
+ if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40');
1168
+ return version * 4 + 17;
1169
+ };
1170
+ exports.getSymbolTotalCodewords = function getSymbolTotalCodewords(version) {
1171
+ return CODEWORDS_COUNT[version];
1172
+ };
1173
+ exports.getBCHDigit = function(data) {
1174
+ let digit = 0;
1175
+ while (data !== 0) {
1176
+ digit++;
1177
+ data >>>= 1;
1178
+ }
1179
+ return digit;
1180
+ };
1181
+ exports.setToSJISFunction = function setToSJISFunction(f) {
1182
+ if (typeof f !== "function") {
1183
+ throw new Error('"toSJISFunc" is not a valid function.');
1184
+ }
1185
+ toSJISFunction = f;
1186
+ };
1187
+ exports.isKanjiModeEnabled = function() {
1188
+ return typeof toSJISFunction !== "undefined";
1189
+ };
1190
+ exports.toSJIS = function toSJIS(kanji) {
1191
+ return toSJISFunction(kanji);
1192
+ };
1193
+ }
1194
+ });
1195
+
1196
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-level.js
1197
+ var require_error_correction_level = __commonJS({
1198
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-level.js"(exports) {
1199
+ exports.L = { bit: 1 };
1200
+ exports.M = { bit: 0 };
1201
+ exports.Q = { bit: 3 };
1202
+ exports.H = { bit: 2 };
1203
+ function fromString(string) {
1204
+ if (typeof string !== "string") {
1205
+ throw new Error("Param is not a string");
1206
+ }
1207
+ const lcStr = string.toLowerCase();
1208
+ switch (lcStr) {
1209
+ case "l":
1210
+ case "low":
1211
+ return exports.L;
1212
+ case "m":
1213
+ case "medium":
1214
+ return exports.M;
1215
+ case "q":
1216
+ case "quartile":
1217
+ return exports.Q;
1218
+ case "h":
1219
+ case "high":
1220
+ return exports.H;
1221
+ default:
1222
+ throw new Error("Unknown EC Level: " + string);
1223
+ }
1224
+ }
1225
+ exports.isValid = function isValid(level) {
1226
+ return level && typeof level.bit !== "undefined" && level.bit >= 0 && level.bit < 4;
1227
+ };
1228
+ exports.from = function from2(value, defaultValue) {
1229
+ if (exports.isValid(value)) {
1230
+ return value;
1231
+ }
1232
+ try {
1233
+ return fromString(value);
1234
+ } catch (e) {
1235
+ return defaultValue;
1236
+ }
1237
+ };
1238
+ }
1239
+ });
1240
+
1241
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-buffer.js
1242
+ var require_bit_buffer = __commonJS({
1243
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-buffer.js"(exports, module) {
1244
+ function BitBuffer() {
1245
+ this.buffer = [];
1246
+ this.length = 0;
1247
+ }
1248
+ BitBuffer.prototype = {
1249
+ get: function(index) {
1250
+ const bufIndex = Math.floor(index / 8);
1251
+ return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) === 1;
1252
+ },
1253
+ put: function(num, length) {
1254
+ for (let i = 0; i < length; i++) {
1255
+ this.putBit((num >>> length - i - 1 & 1) === 1);
1256
+ }
1257
+ },
1258
+ getLengthInBits: function() {
1259
+ return this.length;
1260
+ },
1261
+ putBit: function(bit) {
1262
+ const bufIndex = Math.floor(this.length / 8);
1263
+ if (this.buffer.length <= bufIndex) {
1264
+ this.buffer.push(0);
1265
+ }
1266
+ if (bit) {
1267
+ this.buffer[bufIndex] |= 128 >>> this.length % 8;
1268
+ }
1269
+ this.length++;
1270
+ }
1271
+ };
1272
+ module.exports = BitBuffer;
1273
+ }
1274
+ });
1275
+
1276
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-matrix.js
1277
+ var require_bit_matrix = __commonJS({
1278
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-matrix.js"(exports, module) {
1279
+ function BitMatrix(size) {
1280
+ if (!size || size < 1) {
1281
+ throw new Error("BitMatrix size must be defined and greater than 0");
1282
+ }
1283
+ this.size = size;
1284
+ this.data = new Uint8Array(size * size);
1285
+ this.reservedBit = new Uint8Array(size * size);
1286
+ }
1287
+ BitMatrix.prototype.set = function(row, col, value, reserved) {
1288
+ const index = row * this.size + col;
1289
+ this.data[index] = value;
1290
+ if (reserved) this.reservedBit[index] = true;
1291
+ };
1292
+ BitMatrix.prototype.get = function(row, col) {
1293
+ return this.data[row * this.size + col];
1294
+ };
1295
+ BitMatrix.prototype.xor = function(row, col, value) {
1296
+ this.data[row * this.size + col] ^= value;
1297
+ };
1298
+ BitMatrix.prototype.isReserved = function(row, col) {
1299
+ return this.reservedBit[row * this.size + col];
1300
+ };
1301
+ module.exports = BitMatrix;
1302
+ }
1303
+ });
1304
+
1305
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alignment-pattern.js
1306
+ var require_alignment_pattern = __commonJS({
1307
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alignment-pattern.js"(exports) {
1308
+ var getSymbolSize = require_utils().getSymbolSize;
1309
+ exports.getRowColCoords = function getRowColCoords(version) {
1310
+ if (version === 1) return [];
1311
+ const posCount = Math.floor(version / 7) + 2;
1312
+ const size = getSymbolSize(version);
1313
+ const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
1314
+ const positions = [size - 7];
1315
+ for (let i = 1; i < posCount - 1; i++) {
1316
+ positions[i] = positions[i - 1] - intervals;
1317
+ }
1318
+ positions.push(6);
1319
+ return positions.reverse();
1320
+ };
1321
+ exports.getPositions = function getPositions(version) {
1322
+ const coords = [];
1323
+ const pos = exports.getRowColCoords(version);
1324
+ const posLength = pos.length;
1325
+ for (let i = 0; i < posLength; i++) {
1326
+ for (let j = 0; j < posLength; j++) {
1327
+ if (i === 0 && j === 0 || // top-left
1328
+ i === 0 && j === posLength - 1 || // bottom-left
1329
+ i === posLength - 1 && j === 0) {
1330
+ continue;
1331
+ }
1332
+ coords.push([pos[i], pos[j]]);
1333
+ }
1334
+ }
1335
+ return coords;
1336
+ };
1337
+ }
1338
+ });
1339
+
1340
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/finder-pattern.js
1341
+ var require_finder_pattern = __commonJS({
1342
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/finder-pattern.js"(exports) {
1343
+ var getSymbolSize = require_utils().getSymbolSize;
1344
+ var FINDER_PATTERN_SIZE = 7;
1345
+ exports.getPositions = function getPositions(version) {
1346
+ const size = getSymbolSize(version);
1347
+ return [
1348
+ // top-left
1349
+ [0, 0],
1350
+ // top-right
1351
+ [size - FINDER_PATTERN_SIZE, 0],
1352
+ // bottom-left
1353
+ [0, size - FINDER_PATTERN_SIZE]
1354
+ ];
1355
+ };
1356
+ }
1357
+ });
1358
+
1359
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mask-pattern.js
1360
+ var require_mask_pattern = __commonJS({
1361
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mask-pattern.js"(exports) {
1362
+ exports.Patterns = {
1363
+ PATTERN000: 0,
1364
+ PATTERN001: 1,
1365
+ PATTERN010: 2,
1366
+ PATTERN011: 3,
1367
+ PATTERN100: 4,
1368
+ PATTERN101: 5,
1369
+ PATTERN110: 6,
1370
+ PATTERN111: 7
1371
+ };
1372
+ var PenaltyScores = {
1373
+ N1: 3,
1374
+ N2: 3,
1375
+ N3: 40,
1376
+ N4: 10
1377
+ };
1378
+ exports.isValid = function isValid(mask) {
1379
+ return mask != null && mask !== "" && !isNaN(mask) && mask >= 0 && mask <= 7;
1380
+ };
1381
+ exports.from = function from2(value) {
1382
+ return exports.isValid(value) ? parseInt(value, 10) : void 0;
1383
+ };
1384
+ exports.getPenaltyN1 = function getPenaltyN1(data) {
1385
+ const size = data.size;
1386
+ let points = 0;
1387
+ let sameCountCol = 0;
1388
+ let sameCountRow = 0;
1389
+ let lastCol = null;
1390
+ let lastRow = null;
1391
+ for (let row = 0; row < size; row++) {
1392
+ sameCountCol = sameCountRow = 0;
1393
+ lastCol = lastRow = null;
1394
+ for (let col = 0; col < size; col++) {
1395
+ let module2 = data.get(row, col);
1396
+ if (module2 === lastCol) {
1397
+ sameCountCol++;
1398
+ } else {
1399
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
1400
+ lastCol = module2;
1401
+ sameCountCol = 1;
1402
+ }
1403
+ module2 = data.get(col, row);
1404
+ if (module2 === lastRow) {
1405
+ sameCountRow++;
1406
+ } else {
1407
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
1408
+ lastRow = module2;
1409
+ sameCountRow = 1;
1410
+ }
1411
+ }
1412
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
1413
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
1414
+ }
1415
+ return points;
1416
+ };
1417
+ exports.getPenaltyN2 = function getPenaltyN2(data) {
1418
+ const size = data.size;
1419
+ let points = 0;
1420
+ for (let row = 0; row < size - 1; row++) {
1421
+ for (let col = 0; col < size - 1; col++) {
1422
+ const last = data.get(row, col) + data.get(row, col + 1) + data.get(row + 1, col) + data.get(row + 1, col + 1);
1423
+ if (last === 4 || last === 0) points++;
1424
+ }
1425
+ }
1426
+ return points * PenaltyScores.N2;
1427
+ };
1428
+ exports.getPenaltyN3 = function getPenaltyN3(data) {
1429
+ const size = data.size;
1430
+ let points = 0;
1431
+ let bitsCol = 0;
1432
+ let bitsRow = 0;
1433
+ for (let row = 0; row < size; row++) {
1434
+ bitsCol = bitsRow = 0;
1435
+ for (let col = 0; col < size; col++) {
1436
+ bitsCol = bitsCol << 1 & 2047 | data.get(row, col);
1437
+ if (col >= 10 && (bitsCol === 1488 || bitsCol === 93)) points++;
1438
+ bitsRow = bitsRow << 1 & 2047 | data.get(col, row);
1439
+ if (col >= 10 && (bitsRow === 1488 || bitsRow === 93)) points++;
1440
+ }
1441
+ }
1442
+ return points * PenaltyScores.N3;
1443
+ };
1444
+ exports.getPenaltyN4 = function getPenaltyN4(data) {
1445
+ let darkCount = 0;
1446
+ const modulesCount = data.data.length;
1447
+ for (let i = 0; i < modulesCount; i++) darkCount += data.data[i];
1448
+ const k = Math.abs(Math.ceil(darkCount * 100 / modulesCount / 5) - 10);
1449
+ return k * PenaltyScores.N4;
1450
+ };
1451
+ function getMaskAt(maskPattern, i, j) {
1452
+ switch (maskPattern) {
1453
+ case exports.Patterns.PATTERN000:
1454
+ return (i + j) % 2 === 0;
1455
+ case exports.Patterns.PATTERN001:
1456
+ return i % 2 === 0;
1457
+ case exports.Patterns.PATTERN010:
1458
+ return j % 3 === 0;
1459
+ case exports.Patterns.PATTERN011:
1460
+ return (i + j) % 3 === 0;
1461
+ case exports.Patterns.PATTERN100:
1462
+ return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0;
1463
+ case exports.Patterns.PATTERN101:
1464
+ return i * j % 2 + i * j % 3 === 0;
1465
+ case exports.Patterns.PATTERN110:
1466
+ return (i * j % 2 + i * j % 3) % 2 === 0;
1467
+ case exports.Patterns.PATTERN111:
1468
+ return (i * j % 3 + (i + j) % 2) % 2 === 0;
1469
+ default:
1470
+ throw new Error("bad maskPattern:" + maskPattern);
1471
+ }
1472
+ }
1473
+ exports.applyMask = function applyMask(pattern2, data) {
1474
+ const size = data.size;
1475
+ for (let col = 0; col < size; col++) {
1476
+ for (let row = 0; row < size; row++) {
1477
+ if (data.isReserved(row, col)) continue;
1478
+ data.xor(row, col, getMaskAt(pattern2, row, col));
1479
+ }
1480
+ }
1481
+ };
1482
+ exports.getBestMask = function getBestMask(data, setupFormatFunc) {
1483
+ const numPatterns = Object.keys(exports.Patterns).length;
1484
+ let bestPattern = 0;
1485
+ let lowerPenalty = Infinity;
1486
+ for (let p = 0; p < numPatterns; p++) {
1487
+ setupFormatFunc(p);
1488
+ exports.applyMask(p, data);
1489
+ const penalty = exports.getPenaltyN1(data) + exports.getPenaltyN2(data) + exports.getPenaltyN3(data) + exports.getPenaltyN4(data);
1490
+ exports.applyMask(p, data);
1491
+ if (penalty < lowerPenalty) {
1492
+ lowerPenalty = penalty;
1493
+ bestPattern = p;
1494
+ }
1495
+ }
1496
+ return bestPattern;
1497
+ };
1498
+ }
1499
+ });
1500
+
1501
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-code.js
1502
+ var require_error_correction_code = __commonJS({
1503
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-code.js"(exports) {
1504
+ var ECLevel = require_error_correction_level();
1505
+ var EC_BLOCKS_TABLE = [
1506
+ // L M Q H
1507
+ 1,
1508
+ 1,
1509
+ 1,
1510
+ 1,
1511
+ 1,
1512
+ 1,
1513
+ 1,
1514
+ 1,
1515
+ 1,
1516
+ 1,
1517
+ 2,
1518
+ 2,
1519
+ 1,
1520
+ 2,
1521
+ 2,
1522
+ 4,
1523
+ 1,
1524
+ 2,
1525
+ 4,
1526
+ 4,
1527
+ 2,
1528
+ 4,
1529
+ 4,
1530
+ 4,
1531
+ 2,
1532
+ 4,
1533
+ 6,
1534
+ 5,
1535
+ 2,
1536
+ 4,
1537
+ 6,
1538
+ 6,
1539
+ 2,
1540
+ 5,
1541
+ 8,
1542
+ 8,
1543
+ 4,
1544
+ 5,
1545
+ 8,
1546
+ 8,
1547
+ 4,
1548
+ 5,
1549
+ 8,
1550
+ 11,
1551
+ 4,
1552
+ 8,
1553
+ 10,
1554
+ 11,
1555
+ 4,
1556
+ 9,
1557
+ 12,
1558
+ 16,
1559
+ 4,
1560
+ 9,
1561
+ 16,
1562
+ 16,
1563
+ 6,
1564
+ 10,
1565
+ 12,
1566
+ 18,
1567
+ 6,
1568
+ 10,
1569
+ 17,
1570
+ 16,
1571
+ 6,
1572
+ 11,
1573
+ 16,
1574
+ 19,
1575
+ 6,
1576
+ 13,
1577
+ 18,
1578
+ 21,
1579
+ 7,
1580
+ 14,
1581
+ 21,
1582
+ 25,
1583
+ 8,
1584
+ 16,
1585
+ 20,
1586
+ 25,
1587
+ 8,
1588
+ 17,
1589
+ 23,
1590
+ 25,
1591
+ 9,
1592
+ 17,
1593
+ 23,
1594
+ 34,
1595
+ 9,
1596
+ 18,
1597
+ 25,
1598
+ 30,
1599
+ 10,
1600
+ 20,
1601
+ 27,
1602
+ 32,
1603
+ 12,
1604
+ 21,
1605
+ 29,
1606
+ 35,
1607
+ 12,
1608
+ 23,
1609
+ 34,
1610
+ 37,
1611
+ 12,
1612
+ 25,
1613
+ 34,
1614
+ 40,
1615
+ 13,
1616
+ 26,
1617
+ 35,
1618
+ 42,
1619
+ 14,
1620
+ 28,
1621
+ 38,
1622
+ 45,
1623
+ 15,
1624
+ 29,
1625
+ 40,
1626
+ 48,
1627
+ 16,
1628
+ 31,
1629
+ 43,
1630
+ 51,
1631
+ 17,
1632
+ 33,
1633
+ 45,
1634
+ 54,
1635
+ 18,
1636
+ 35,
1637
+ 48,
1638
+ 57,
1639
+ 19,
1640
+ 37,
1641
+ 51,
1642
+ 60,
1643
+ 19,
1644
+ 38,
1645
+ 53,
1646
+ 63,
1647
+ 20,
1648
+ 40,
1649
+ 56,
1650
+ 66,
1651
+ 21,
1652
+ 43,
1653
+ 59,
1654
+ 70,
1655
+ 22,
1656
+ 45,
1657
+ 62,
1658
+ 74,
1659
+ 24,
1660
+ 47,
1661
+ 65,
1662
+ 77,
1663
+ 25,
1664
+ 49,
1665
+ 68,
1666
+ 81
1667
+ ];
1668
+ var EC_CODEWORDS_TABLE = [
1669
+ // L M Q H
1670
+ 7,
1671
+ 10,
1672
+ 13,
1673
+ 17,
1674
+ 10,
1675
+ 16,
1676
+ 22,
1677
+ 28,
1678
+ 15,
1679
+ 26,
1680
+ 36,
1681
+ 44,
1682
+ 20,
1683
+ 36,
1684
+ 52,
1685
+ 64,
1686
+ 26,
1687
+ 48,
1688
+ 72,
1689
+ 88,
1690
+ 36,
1691
+ 64,
1692
+ 96,
1693
+ 112,
1694
+ 40,
1695
+ 72,
1696
+ 108,
1697
+ 130,
1698
+ 48,
1699
+ 88,
1700
+ 132,
1701
+ 156,
1702
+ 60,
1703
+ 110,
1704
+ 160,
1705
+ 192,
1706
+ 72,
1707
+ 130,
1708
+ 192,
1709
+ 224,
1710
+ 80,
1711
+ 150,
1712
+ 224,
1713
+ 264,
1714
+ 96,
1715
+ 176,
1716
+ 260,
1717
+ 308,
1718
+ 104,
1719
+ 198,
1720
+ 288,
1721
+ 352,
1722
+ 120,
1723
+ 216,
1724
+ 320,
1725
+ 384,
1726
+ 132,
1727
+ 240,
1728
+ 360,
1729
+ 432,
1730
+ 144,
1731
+ 280,
1732
+ 408,
1733
+ 480,
1734
+ 168,
1735
+ 308,
1736
+ 448,
1737
+ 532,
1738
+ 180,
1739
+ 338,
1740
+ 504,
1741
+ 588,
1742
+ 196,
1743
+ 364,
1744
+ 546,
1745
+ 650,
1746
+ 224,
1747
+ 416,
1748
+ 600,
1749
+ 700,
1750
+ 224,
1751
+ 442,
1752
+ 644,
1753
+ 750,
1754
+ 252,
1755
+ 476,
1756
+ 690,
1757
+ 816,
1758
+ 270,
1759
+ 504,
1760
+ 750,
1761
+ 900,
1762
+ 300,
1763
+ 560,
1764
+ 810,
1765
+ 960,
1766
+ 312,
1767
+ 588,
1768
+ 870,
1769
+ 1050,
1770
+ 336,
1771
+ 644,
1772
+ 952,
1773
+ 1110,
1774
+ 360,
1775
+ 700,
1776
+ 1020,
1777
+ 1200,
1778
+ 390,
1779
+ 728,
1780
+ 1050,
1781
+ 1260,
1782
+ 420,
1783
+ 784,
1784
+ 1140,
1785
+ 1350,
1786
+ 450,
1787
+ 812,
1788
+ 1200,
1789
+ 1440,
1790
+ 480,
1791
+ 868,
1792
+ 1290,
1793
+ 1530,
1794
+ 510,
1795
+ 924,
1796
+ 1350,
1797
+ 1620,
1798
+ 540,
1799
+ 980,
1800
+ 1440,
1801
+ 1710,
1802
+ 570,
1803
+ 1036,
1804
+ 1530,
1805
+ 1800,
1806
+ 570,
1807
+ 1064,
1808
+ 1590,
1809
+ 1890,
1810
+ 600,
1811
+ 1120,
1812
+ 1680,
1813
+ 1980,
1814
+ 630,
1815
+ 1204,
1816
+ 1770,
1817
+ 2100,
1818
+ 660,
1819
+ 1260,
1820
+ 1860,
1821
+ 2220,
1822
+ 720,
1823
+ 1316,
1824
+ 1950,
1825
+ 2310,
1826
+ 750,
1827
+ 1372,
1828
+ 2040,
1829
+ 2430
1830
+ ];
1831
+ exports.getBlocksCount = function getBlocksCount(version, errorCorrectionLevel) {
1832
+ switch (errorCorrectionLevel) {
1833
+ case ECLevel.L:
1834
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 0];
1835
+ case ECLevel.M:
1836
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 1];
1837
+ case ECLevel.Q:
1838
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 2];
1839
+ case ECLevel.H:
1840
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 3];
1841
+ default:
1842
+ return void 0;
1843
+ }
1844
+ };
1845
+ exports.getTotalCodewordsCount = function getTotalCodewordsCount(version, errorCorrectionLevel) {
1846
+ switch (errorCorrectionLevel) {
1847
+ case ECLevel.L:
1848
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0];
1849
+ case ECLevel.M:
1850
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1];
1851
+ case ECLevel.Q:
1852
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2];
1853
+ case ECLevel.H:
1854
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3];
1855
+ default:
1856
+ return void 0;
1857
+ }
1858
+ };
1859
+ }
1860
+ });
1861
+
1862
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/galois-field.js
1863
+ var require_galois_field = __commonJS({
1864
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/galois-field.js"(exports) {
1865
+ var EXP_TABLE = new Uint8Array(512);
1866
+ var LOG_TABLE = new Uint8Array(256);
1867
+ (function initTables() {
1868
+ let x = 1;
1869
+ for (let i = 0; i < 255; i++) {
1870
+ EXP_TABLE[i] = x;
1871
+ LOG_TABLE[x] = i;
1872
+ x <<= 1;
1873
+ if (x & 256) {
1874
+ x ^= 285;
1875
+ }
1876
+ }
1877
+ for (let i = 255; i < 512; i++) {
1878
+ EXP_TABLE[i] = EXP_TABLE[i - 255];
1879
+ }
1880
+ })();
1881
+ exports.log = function log(n) {
1882
+ if (n < 1) throw new Error("log(" + n + ")");
1883
+ return LOG_TABLE[n];
1884
+ };
1885
+ exports.exp = function exp(n) {
1886
+ return EXP_TABLE[n];
1887
+ };
1888
+ exports.mul = function mul(x, y) {
1889
+ if (x === 0 || y === 0) return 0;
1890
+ return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]];
1891
+ };
1892
+ }
1893
+ });
1894
+
1895
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/polynomial.js
1896
+ var require_polynomial = __commonJS({
1897
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/polynomial.js"(exports) {
1898
+ var GF = require_galois_field();
1899
+ exports.mul = function mul(p1, p2) {
1900
+ const coeff = new Uint8Array(p1.length + p2.length - 1);
1901
+ for (let i = 0; i < p1.length; i++) {
1902
+ for (let j = 0; j < p2.length; j++) {
1903
+ coeff[i + j] ^= GF.mul(p1[i], p2[j]);
1904
+ }
1905
+ }
1906
+ return coeff;
1907
+ };
1908
+ exports.mod = function mod(divident, divisor) {
1909
+ let result = new Uint8Array(divident);
1910
+ while (result.length - divisor.length >= 0) {
1911
+ const coeff = result[0];
1912
+ for (let i = 0; i < divisor.length; i++) {
1913
+ result[i] ^= GF.mul(divisor[i], coeff);
1914
+ }
1915
+ let offset = 0;
1916
+ while (offset < result.length && result[offset] === 0) offset++;
1917
+ result = result.slice(offset);
1918
+ }
1919
+ return result;
1920
+ };
1921
+ exports.generateECPolynomial = function generateECPolynomial(degree) {
1922
+ let poly = new Uint8Array([1]);
1923
+ for (let i = 0; i < degree; i++) {
1924
+ poly = exports.mul(poly, new Uint8Array([1, GF.exp(i)]));
1925
+ }
1926
+ return poly;
1927
+ };
1928
+ }
1929
+ });
1930
+
1931
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/reed-solomon-encoder.js
1932
+ var require_reed_solomon_encoder = __commonJS({
1933
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/reed-solomon-encoder.js"(exports, module) {
1934
+ var Polynomial = require_polynomial();
1935
+ function ReedSolomonEncoder(degree) {
1936
+ this.genPoly = void 0;
1937
+ this.degree = degree;
1938
+ if (this.degree) this.initialize(this.degree);
1939
+ }
1940
+ ReedSolomonEncoder.prototype.initialize = function initialize(degree) {
1941
+ this.degree = degree;
1942
+ this.genPoly = Polynomial.generateECPolynomial(this.degree);
1943
+ };
1944
+ ReedSolomonEncoder.prototype.encode = function encode(data) {
1945
+ if (!this.genPoly) {
1946
+ throw new Error("Encoder not initialized");
1947
+ }
1948
+ const paddedData = new Uint8Array(data.length + this.degree);
1949
+ paddedData.set(data);
1950
+ const remainder = Polynomial.mod(paddedData, this.genPoly);
1951
+ const start = this.degree - remainder.length;
1952
+ if (start > 0) {
1953
+ const buff = new Uint8Array(this.degree);
1954
+ buff.set(remainder, start);
1955
+ return buff;
1956
+ }
1957
+ return remainder;
1958
+ };
1959
+ module.exports = ReedSolomonEncoder;
1960
+ }
1961
+ });
1962
+
1963
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version-check.js
1964
+ var require_version_check = __commonJS({
1965
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version-check.js"(exports) {
1966
+ exports.isValid = function isValid(version) {
1967
+ return !isNaN(version) && version >= 1 && version <= 40;
1968
+ };
1969
+ }
1970
+ });
1971
+
1972
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/regex.js
1973
+ var require_regex = __commonJS({
1974
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/regex.js"(exports) {
1975
+ var numeric = "[0-9]+";
1976
+ var alphanumeric = "[A-Z $%*+\\-./:]+";
1977
+ var kanji = "(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";
1978
+ kanji = kanji.replace(/u/g, "\\u");
1979
+ var byte = "(?:(?![A-Z0-9 $%*+\\-./:]|" + kanji + ")(?:.|[\r\n]))+";
1980
+ exports.KANJI = new RegExp(kanji, "g");
1981
+ exports.BYTE_KANJI = new RegExp("[^A-Z0-9 $%*+\\-./:]+", "g");
1982
+ exports.BYTE = new RegExp(byte, "g");
1983
+ exports.NUMERIC = new RegExp(numeric, "g");
1984
+ exports.ALPHANUMERIC = new RegExp(alphanumeric, "g");
1985
+ var TEST_KANJI = new RegExp("^" + kanji + "$");
1986
+ var TEST_NUMERIC = new RegExp("^" + numeric + "$");
1987
+ var TEST_ALPHANUMERIC = new RegExp("^[A-Z0-9 $%*+\\-./:]+$");
1988
+ exports.testKanji = function testKanji(str) {
1989
+ return TEST_KANJI.test(str);
1990
+ };
1991
+ exports.testNumeric = function testNumeric(str) {
1992
+ return TEST_NUMERIC.test(str);
1993
+ };
1994
+ exports.testAlphanumeric = function testAlphanumeric(str) {
1995
+ return TEST_ALPHANUMERIC.test(str);
1996
+ };
1997
+ }
1998
+ });
1999
+
2000
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js
2001
+ var require_mode = __commonJS({
2002
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js"(exports) {
2003
+ var VersionCheck = require_version_check();
2004
+ var Regex = require_regex();
2005
+ exports.NUMERIC = {
2006
+ id: "Numeric",
2007
+ bit: 1 << 0,
2008
+ ccBits: [10, 12, 14]
2009
+ };
2010
+ exports.ALPHANUMERIC = {
2011
+ id: "Alphanumeric",
2012
+ bit: 1 << 1,
2013
+ ccBits: [9, 11, 13]
2014
+ };
2015
+ exports.BYTE = {
2016
+ id: "Byte",
2017
+ bit: 1 << 2,
2018
+ ccBits: [8, 16, 16]
2019
+ };
2020
+ exports.KANJI = {
2021
+ id: "Kanji",
2022
+ bit: 1 << 3,
2023
+ ccBits: [8, 10, 12]
2024
+ };
2025
+ exports.MIXED = {
2026
+ bit: -1
2027
+ };
2028
+ exports.getCharCountIndicator = function getCharCountIndicator(mode, version) {
2029
+ if (!mode.ccBits) throw new Error("Invalid mode: " + mode);
2030
+ if (!VersionCheck.isValid(version)) {
2031
+ throw new Error("Invalid version: " + version);
2032
+ }
2033
+ if (version >= 1 && version < 10) return mode.ccBits[0];
2034
+ else if (version < 27) return mode.ccBits[1];
2035
+ return mode.ccBits[2];
2036
+ };
2037
+ exports.getBestModeForData = function getBestModeForData(dataStr) {
2038
+ if (Regex.testNumeric(dataStr)) return exports.NUMERIC;
2039
+ else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC;
2040
+ else if (Regex.testKanji(dataStr)) return exports.KANJI;
2041
+ else return exports.BYTE;
2042
+ };
2043
+ exports.toString = function toString2(mode) {
2044
+ if (mode && mode.id) return mode.id;
2045
+ throw new Error("Invalid mode");
2046
+ };
2047
+ exports.isValid = function isValid(mode) {
2048
+ return mode && mode.bit && mode.ccBits;
2049
+ };
2050
+ function fromString(string) {
2051
+ if (typeof string !== "string") {
2052
+ throw new Error("Param is not a string");
2053
+ }
2054
+ const lcStr = string.toLowerCase();
2055
+ switch (lcStr) {
2056
+ case "numeric":
2057
+ return exports.NUMERIC;
2058
+ case "alphanumeric":
2059
+ return exports.ALPHANUMERIC;
2060
+ case "kanji":
2061
+ return exports.KANJI;
2062
+ case "byte":
2063
+ return exports.BYTE;
2064
+ default:
2065
+ throw new Error("Unknown mode: " + string);
2066
+ }
2067
+ }
2068
+ exports.from = function from2(value, defaultValue) {
2069
+ if (exports.isValid(value)) {
2070
+ return value;
2071
+ }
2072
+ try {
2073
+ return fromString(value);
2074
+ } catch (e) {
2075
+ return defaultValue;
2076
+ }
2077
+ };
2078
+ }
2079
+ });
2080
+
2081
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version.js
2082
+ var require_version = __commonJS({
2083
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version.js"(exports) {
2084
+ var Utils = require_utils();
2085
+ var ECCode = require_error_correction_code();
2086
+ var ECLevel = require_error_correction_level();
2087
+ var Mode = require_mode();
2088
+ var VersionCheck = require_version_check();
2089
+ var G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0;
2090
+ var G18_BCH = Utils.getBCHDigit(G18);
2091
+ function getBestVersionForDataLength(mode, length, errorCorrectionLevel) {
2092
+ for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
2093
+ if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
2094
+ return currentVersion;
2095
+ }
2096
+ }
2097
+ return void 0;
2098
+ }
2099
+ function getReservedBitsCount(mode, version) {
2100
+ return Mode.getCharCountIndicator(mode, version) + 4;
2101
+ }
2102
+ function getTotalBitsFromDataArray(segments, version) {
2103
+ let totalBits = 0;
2104
+ segments.forEach(function(data) {
2105
+ const reservedBits = getReservedBitsCount(data.mode, version);
2106
+ totalBits += reservedBits + data.getBitsLength();
2107
+ });
2108
+ return totalBits;
2109
+ }
2110
+ function getBestVersionForMixedData(segments, errorCorrectionLevel) {
2111
+ for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
2112
+ const length = getTotalBitsFromDataArray(segments, currentVersion);
2113
+ if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {
2114
+ return currentVersion;
2115
+ }
2116
+ }
2117
+ return void 0;
2118
+ }
2119
+ exports.from = function from2(value, defaultValue) {
2120
+ if (VersionCheck.isValid(value)) {
2121
+ return parseInt(value, 10);
2122
+ }
2123
+ return defaultValue;
2124
+ };
2125
+ exports.getCapacity = function getCapacity(version, errorCorrectionLevel, mode) {
2126
+ if (!VersionCheck.isValid(version)) {
2127
+ throw new Error("Invalid QR Code version");
2128
+ }
2129
+ if (typeof mode === "undefined") mode = Mode.BYTE;
2130
+ const totalCodewords = Utils.getSymbolTotalCodewords(version);
2131
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
2132
+ const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
2133
+ if (mode === Mode.MIXED) return dataTotalCodewordsBits;
2134
+ const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version);
2135
+ switch (mode) {
2136
+ case Mode.NUMERIC:
2137
+ return Math.floor(usableBits / 10 * 3);
2138
+ case Mode.ALPHANUMERIC:
2139
+ return Math.floor(usableBits / 11 * 2);
2140
+ case Mode.KANJI:
2141
+ return Math.floor(usableBits / 13);
2142
+ case Mode.BYTE:
2143
+ default:
2144
+ return Math.floor(usableBits / 8);
2145
+ }
2146
+ };
2147
+ exports.getBestVersionForData = function getBestVersionForData(data, errorCorrectionLevel) {
2148
+ let seg;
2149
+ const ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M);
2150
+ if (Array.isArray(data)) {
2151
+ if (data.length > 1) {
2152
+ return getBestVersionForMixedData(data, ecl);
2153
+ }
2154
+ if (data.length === 0) {
2155
+ return 1;
2156
+ }
2157
+ seg = data[0];
2158
+ } else {
2159
+ seg = data;
2160
+ }
2161
+ return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl);
2162
+ };
2163
+ exports.getEncodedBits = function getEncodedBits(version) {
2164
+ if (!VersionCheck.isValid(version) || version < 7) {
2165
+ throw new Error("Invalid QR Code version");
2166
+ }
2167
+ let d = version << 12;
2168
+ while (Utils.getBCHDigit(d) - G18_BCH >= 0) {
2169
+ d ^= G18 << Utils.getBCHDigit(d) - G18_BCH;
2170
+ }
2171
+ return version << 12 | d;
2172
+ };
2173
+ }
2174
+ });
2175
+
2176
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/format-info.js
2177
+ var require_format_info = __commonJS({
2178
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/format-info.js"(exports) {
2179
+ var Utils = require_utils();
2180
+ var G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;
2181
+ var G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
2182
+ var G15_BCH = Utils.getBCHDigit(G15);
2183
+ exports.getEncodedBits = function getEncodedBits(errorCorrectionLevel, mask) {
2184
+ const data = errorCorrectionLevel.bit << 3 | mask;
2185
+ let d = data << 10;
2186
+ while (Utils.getBCHDigit(d) - G15_BCH >= 0) {
2187
+ d ^= G15 << Utils.getBCHDigit(d) - G15_BCH;
2188
+ }
2189
+ return (data << 10 | d) ^ G15_MASK;
2190
+ };
2191
+ }
2192
+ });
2193
+
2194
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/numeric-data.js
2195
+ var require_numeric_data = __commonJS({
2196
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/numeric-data.js"(exports, module) {
2197
+ var Mode = require_mode();
2198
+ function NumericData(data) {
2199
+ this.mode = Mode.NUMERIC;
2200
+ this.data = data.toString();
2201
+ }
2202
+ NumericData.getBitsLength = function getBitsLength(length) {
2203
+ return 10 * Math.floor(length / 3) + (length % 3 ? length % 3 * 3 + 1 : 0);
2204
+ };
2205
+ NumericData.prototype.getLength = function getLength() {
2206
+ return this.data.length;
2207
+ };
2208
+ NumericData.prototype.getBitsLength = function getBitsLength() {
2209
+ return NumericData.getBitsLength(this.data.length);
2210
+ };
2211
+ NumericData.prototype.write = function write2(bitBuffer) {
2212
+ let i, group, value;
2213
+ for (i = 0; i + 3 <= this.data.length; i += 3) {
2214
+ group = this.data.substr(i, 3);
2215
+ value = parseInt(group, 10);
2216
+ bitBuffer.put(value, 10);
2217
+ }
2218
+ const remainingNum = this.data.length - i;
2219
+ if (remainingNum > 0) {
2220
+ group = this.data.substr(i);
2221
+ value = parseInt(group, 10);
2222
+ bitBuffer.put(value, remainingNum * 3 + 1);
2223
+ }
2224
+ };
2225
+ module.exports = NumericData;
2226
+ }
2227
+ });
2228
+
2229
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alphanumeric-data.js
2230
+ var require_alphanumeric_data = __commonJS({
2231
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alphanumeric-data.js"(exports, module) {
2232
+ var Mode = require_mode();
2233
+ var ALPHA_NUM_CHARS = [
2234
+ "0",
2235
+ "1",
2236
+ "2",
2237
+ "3",
2238
+ "4",
2239
+ "5",
2240
+ "6",
2241
+ "7",
2242
+ "8",
2243
+ "9",
2244
+ "A",
2245
+ "B",
2246
+ "C",
2247
+ "D",
2248
+ "E",
2249
+ "F",
2250
+ "G",
2251
+ "H",
2252
+ "I",
2253
+ "J",
2254
+ "K",
2255
+ "L",
2256
+ "M",
2257
+ "N",
2258
+ "O",
2259
+ "P",
2260
+ "Q",
2261
+ "R",
2262
+ "S",
2263
+ "T",
2264
+ "U",
2265
+ "V",
2266
+ "W",
2267
+ "X",
2268
+ "Y",
2269
+ "Z",
2270
+ " ",
2271
+ "$",
2272
+ "%",
2273
+ "*",
2274
+ "+",
2275
+ "-",
2276
+ ".",
2277
+ "/",
2278
+ ":"
2279
+ ];
2280
+ function AlphanumericData(data) {
2281
+ this.mode = Mode.ALPHANUMERIC;
2282
+ this.data = data;
2283
+ }
2284
+ AlphanumericData.getBitsLength = function getBitsLength(length) {
2285
+ return 11 * Math.floor(length / 2) + 6 * (length % 2);
2286
+ };
2287
+ AlphanumericData.prototype.getLength = function getLength() {
2288
+ return this.data.length;
2289
+ };
2290
+ AlphanumericData.prototype.getBitsLength = function getBitsLength() {
2291
+ return AlphanumericData.getBitsLength(this.data.length);
2292
+ };
2293
+ AlphanumericData.prototype.write = function write2(bitBuffer) {
2294
+ let i;
2295
+ for (i = 0; i + 2 <= this.data.length; i += 2) {
2296
+ let value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45;
2297
+ value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1]);
2298
+ bitBuffer.put(value, 11);
2299
+ }
2300
+ if (this.data.length % 2) {
2301
+ bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6);
2302
+ }
2303
+ };
2304
+ module.exports = AlphanumericData;
2305
+ }
2306
+ });
2307
+
2308
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/byte-data.js
2309
+ var require_byte_data = __commonJS({
2310
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/byte-data.js"(exports, module) {
2311
+ var Mode = require_mode();
2312
+ function ByteData(data) {
2313
+ this.mode = Mode.BYTE;
2314
+ if (typeof data === "string") {
2315
+ this.data = new TextEncoder().encode(data);
2316
+ } else {
2317
+ this.data = new Uint8Array(data);
2318
+ }
2319
+ }
2320
+ ByteData.getBitsLength = function getBitsLength(length) {
2321
+ return length * 8;
2322
+ };
2323
+ ByteData.prototype.getLength = function getLength() {
2324
+ return this.data.length;
2325
+ };
2326
+ ByteData.prototype.getBitsLength = function getBitsLength() {
2327
+ return ByteData.getBitsLength(this.data.length);
2328
+ };
2329
+ ByteData.prototype.write = function(bitBuffer) {
2330
+ for (let i = 0, l = this.data.length; i < l; i++) {
2331
+ bitBuffer.put(this.data[i], 8);
2332
+ }
2333
+ };
2334
+ module.exports = ByteData;
2335
+ }
2336
+ });
2337
+
2338
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/kanji-data.js
2339
+ var require_kanji_data = __commonJS({
2340
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/kanji-data.js"(exports, module) {
2341
+ var Mode = require_mode();
2342
+ var Utils = require_utils();
2343
+ function KanjiData(data) {
2344
+ this.mode = Mode.KANJI;
2345
+ this.data = data;
2346
+ }
2347
+ KanjiData.getBitsLength = function getBitsLength(length) {
2348
+ return length * 13;
2349
+ };
2350
+ KanjiData.prototype.getLength = function getLength() {
2351
+ return this.data.length;
2352
+ };
2353
+ KanjiData.prototype.getBitsLength = function getBitsLength() {
2354
+ return KanjiData.getBitsLength(this.data.length);
2355
+ };
2356
+ KanjiData.prototype.write = function(bitBuffer) {
2357
+ let i;
2358
+ for (i = 0; i < this.data.length; i++) {
2359
+ let value = Utils.toSJIS(this.data[i]);
2360
+ if (value >= 33088 && value <= 40956) {
2361
+ value -= 33088;
2362
+ } else if (value >= 57408 && value <= 60351) {
2363
+ value -= 49472;
2364
+ } else {
2365
+ throw new Error(
2366
+ "Invalid SJIS character: " + this.data[i] + "\nMake sure your charset is UTF-8"
2367
+ );
2368
+ }
2369
+ value = (value >>> 8 & 255) * 192 + (value & 255);
2370
+ bitBuffer.put(value, 13);
2371
+ }
2372
+ };
2373
+ module.exports = KanjiData;
2374
+ }
2375
+ });
2376
+
2377
+ // node_modules/.pnpm/dijkstrajs@1.0.3/node_modules/dijkstrajs/dijkstra.js
2378
+ var require_dijkstra = __commonJS({
2379
+ "node_modules/.pnpm/dijkstrajs@1.0.3/node_modules/dijkstrajs/dijkstra.js"(exports, module) {
2380
+ "use strict";
2381
+ var dijkstra = {
2382
+ single_source_shortest_paths: function(graph, s, d) {
2383
+ var predecessors = {};
2384
+ var costs = {};
2385
+ costs[s] = 0;
2386
+ var open3 = dijkstra.PriorityQueue.make();
2387
+ open3.push(s, 0);
2388
+ var closest, u, v, cost_of_s_to_u, adjacent_nodes, cost_of_e, cost_of_s_to_u_plus_cost_of_e, cost_of_s_to_v, first_visit;
2389
+ while (!open3.empty()) {
2390
+ closest = open3.pop();
2391
+ u = closest.value;
2392
+ cost_of_s_to_u = closest.cost;
2393
+ adjacent_nodes = graph[u] || {};
2394
+ for (v in adjacent_nodes) {
2395
+ if (adjacent_nodes.hasOwnProperty(v)) {
2396
+ cost_of_e = adjacent_nodes[v];
2397
+ cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
2398
+ cost_of_s_to_v = costs[v];
2399
+ first_visit = typeof costs[v] === "undefined";
2400
+ if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
2401
+ costs[v] = cost_of_s_to_u_plus_cost_of_e;
2402
+ open3.push(v, cost_of_s_to_u_plus_cost_of_e);
2403
+ predecessors[v] = u;
2404
+ }
2405
+ }
2406
+ }
2407
+ }
2408
+ if (typeof d !== "undefined" && typeof costs[d] === "undefined") {
2409
+ var msg = ["Could not find a path from ", s, " to ", d, "."].join("");
2410
+ throw new Error(msg);
2411
+ }
2412
+ return predecessors;
2413
+ },
2414
+ extract_shortest_path_from_predecessor_list: function(predecessors, d) {
2415
+ var nodes = [];
2416
+ var u = d;
2417
+ var predecessor;
2418
+ while (u) {
2419
+ nodes.push(u);
2420
+ predecessor = predecessors[u];
2421
+ u = predecessors[u];
2422
+ }
2423
+ nodes.reverse();
2424
+ return nodes;
2425
+ },
2426
+ find_path: function(graph, s, d) {
2427
+ var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
2428
+ return dijkstra.extract_shortest_path_from_predecessor_list(
2429
+ predecessors,
2430
+ d
2431
+ );
2432
+ },
2433
+ /**
2434
+ * A very naive priority queue implementation.
2435
+ */
2436
+ PriorityQueue: {
2437
+ make: function(opts) {
2438
+ var T = dijkstra.PriorityQueue, t = {}, key;
2439
+ opts = opts || {};
2440
+ for (key in T) {
2441
+ if (T.hasOwnProperty(key)) {
2442
+ t[key] = T[key];
2443
+ }
2444
+ }
2445
+ t.queue = [];
2446
+ t.sorter = opts.sorter || T.default_sorter;
2447
+ return t;
2448
+ },
2449
+ default_sorter: function(a, b) {
2450
+ return a.cost - b.cost;
2451
+ },
2452
+ /**
2453
+ * Add a new item to the queue and ensure the highest priority element
2454
+ * is at the front of the queue.
2455
+ */
2456
+ push: function(value, cost) {
2457
+ var item = { value, cost };
2458
+ this.queue.push(item);
2459
+ this.queue.sort(this.sorter);
2460
+ },
2461
+ /**
2462
+ * Return the highest priority element in the queue.
2463
+ */
2464
+ pop: function() {
2465
+ return this.queue.shift();
2466
+ },
2467
+ empty: function() {
2468
+ return this.queue.length === 0;
2469
+ }
2470
+ }
2471
+ };
2472
+ if (typeof module !== "undefined") {
2473
+ module.exports = dijkstra;
2474
+ }
2475
+ }
2476
+ });
2477
+
2478
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/segments.js
2479
+ var require_segments = __commonJS({
2480
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/segments.js"(exports) {
2481
+ var Mode = require_mode();
2482
+ var NumericData = require_numeric_data();
2483
+ var AlphanumericData = require_alphanumeric_data();
2484
+ var ByteData = require_byte_data();
2485
+ var KanjiData = require_kanji_data();
2486
+ var Regex = require_regex();
2487
+ var Utils = require_utils();
2488
+ var dijkstra = require_dijkstra();
2489
+ function getStringByteLength(str) {
2490
+ return unescape(encodeURIComponent(str)).length;
2491
+ }
2492
+ function getSegments(regex, mode, str) {
2493
+ const segments = [];
2494
+ let result;
2495
+ while ((result = regex.exec(str)) !== null) {
2496
+ segments.push({
2497
+ data: result[0],
2498
+ index: result.index,
2499
+ mode,
2500
+ length: result[0].length
2501
+ });
2502
+ }
2503
+ return segments;
2504
+ }
2505
+ function getSegmentsFromString(dataStr) {
2506
+ const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr);
2507
+ const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr);
2508
+ let byteSegs;
2509
+ let kanjiSegs;
2510
+ if (Utils.isKanjiModeEnabled()) {
2511
+ byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr);
2512
+ kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr);
2513
+ } else {
2514
+ byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr);
2515
+ kanjiSegs = [];
2516
+ }
2517
+ const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs);
2518
+ return segs.sort(function(s1, s2) {
2519
+ return s1.index - s2.index;
2520
+ }).map(function(obj) {
2521
+ return {
2522
+ data: obj.data,
2523
+ mode: obj.mode,
2524
+ length: obj.length
2525
+ };
2526
+ });
2527
+ }
2528
+ function getSegmentBitsLength(length, mode) {
2529
+ switch (mode) {
2530
+ case Mode.NUMERIC:
2531
+ return NumericData.getBitsLength(length);
2532
+ case Mode.ALPHANUMERIC:
2533
+ return AlphanumericData.getBitsLength(length);
2534
+ case Mode.KANJI:
2535
+ return KanjiData.getBitsLength(length);
2536
+ case Mode.BYTE:
2537
+ return ByteData.getBitsLength(length);
2538
+ }
2539
+ }
2540
+ function mergeSegments(segs) {
2541
+ return segs.reduce(function(acc, curr) {
2542
+ const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null;
2543
+ if (prevSeg && prevSeg.mode === curr.mode) {
2544
+ acc[acc.length - 1].data += curr.data;
2545
+ return acc;
2546
+ }
2547
+ acc.push(curr);
2548
+ return acc;
2549
+ }, []);
2550
+ }
2551
+ function buildNodes(segs) {
2552
+ const nodes = [];
2553
+ for (let i = 0; i < segs.length; i++) {
2554
+ const seg = segs[i];
2555
+ switch (seg.mode) {
2556
+ case Mode.NUMERIC:
2557
+ nodes.push([
2558
+ seg,
2559
+ { data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },
2560
+ { data: seg.data, mode: Mode.BYTE, length: seg.length }
2561
+ ]);
2562
+ break;
2563
+ case Mode.ALPHANUMERIC:
2564
+ nodes.push([
2565
+ seg,
2566
+ { data: seg.data, mode: Mode.BYTE, length: seg.length }
2567
+ ]);
2568
+ break;
2569
+ case Mode.KANJI:
2570
+ nodes.push([
2571
+ seg,
2572
+ { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
2573
+ ]);
2574
+ break;
2575
+ case Mode.BYTE:
2576
+ nodes.push([
2577
+ { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
2578
+ ]);
2579
+ }
2580
+ }
2581
+ return nodes;
2582
+ }
2583
+ function buildGraph(nodes, version) {
2584
+ const table = {};
2585
+ const graph = { start: {} };
2586
+ let prevNodeIds = ["start"];
2587
+ for (let i = 0; i < nodes.length; i++) {
2588
+ const nodeGroup = nodes[i];
2589
+ const currentNodeIds = [];
2590
+ for (let j = 0; j < nodeGroup.length; j++) {
2591
+ const node = nodeGroup[j];
2592
+ const key = "" + i + j;
2593
+ currentNodeIds.push(key);
2594
+ table[key] = { node, lastCount: 0 };
2595
+ graph[key] = {};
2596
+ for (let n = 0; n < prevNodeIds.length; n++) {
2597
+ const prevNodeId = prevNodeIds[n];
2598
+ if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
2599
+ graph[prevNodeId][key] = getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) - getSegmentBitsLength(table[prevNodeId].lastCount, node.mode);
2600
+ table[prevNodeId].lastCount += node.length;
2601
+ } else {
2602
+ if (table[prevNodeId]) table[prevNodeId].lastCount = node.length;
2603
+ graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) + 4 + Mode.getCharCountIndicator(node.mode, version);
2604
+ }
2605
+ }
2606
+ }
2607
+ prevNodeIds = currentNodeIds;
2608
+ }
2609
+ for (let n = 0; n < prevNodeIds.length; n++) {
2610
+ graph[prevNodeIds[n]].end = 0;
2611
+ }
2612
+ return { map: graph, table };
2613
+ }
2614
+ function buildSingleSegment(data, modesHint) {
2615
+ let mode;
2616
+ const bestMode = Mode.getBestModeForData(data);
2617
+ mode = Mode.from(modesHint, bestMode);
2618
+ if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {
2619
+ throw new Error('"' + data + '" cannot be encoded with mode ' + Mode.toString(mode) + ".\n Suggested mode is: " + Mode.toString(bestMode));
2620
+ }
2621
+ if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {
2622
+ mode = Mode.BYTE;
2623
+ }
2624
+ switch (mode) {
2625
+ case Mode.NUMERIC:
2626
+ return new NumericData(data);
2627
+ case Mode.ALPHANUMERIC:
2628
+ return new AlphanumericData(data);
2629
+ case Mode.KANJI:
2630
+ return new KanjiData(data);
2631
+ case Mode.BYTE:
2632
+ return new ByteData(data);
2633
+ }
2634
+ }
2635
+ exports.fromArray = function fromArray(array) {
2636
+ return array.reduce(function(acc, seg) {
2637
+ if (typeof seg === "string") {
2638
+ acc.push(buildSingleSegment(seg, null));
2639
+ } else if (seg.data) {
2640
+ acc.push(buildSingleSegment(seg.data, seg.mode));
2641
+ }
2642
+ return acc;
2643
+ }, []);
2644
+ };
2645
+ exports.fromString = function fromString(data, version) {
2646
+ const segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled());
2647
+ const nodes = buildNodes(segs);
2648
+ const graph = buildGraph(nodes, version);
2649
+ const path = dijkstra.find_path(graph.map, "start", "end");
2650
+ const optimizedSegs = [];
2651
+ for (let i = 1; i < path.length - 1; i++) {
2652
+ optimizedSegs.push(graph.table[path[i]].node);
2653
+ }
2654
+ return exports.fromArray(mergeSegments(optimizedSegs));
2655
+ };
2656
+ exports.rawSplit = function rawSplit(data) {
2657
+ return exports.fromArray(
2658
+ getSegmentsFromString(data, Utils.isKanjiModeEnabled())
2659
+ );
2660
+ };
2661
+ }
2662
+ });
2663
+
2664
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/qrcode.js
2665
+ var require_qrcode = __commonJS({
2666
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/qrcode.js"(exports) {
2667
+ var Utils = require_utils();
2668
+ var ECLevel = require_error_correction_level();
2669
+ var BitBuffer = require_bit_buffer();
2670
+ var BitMatrix = require_bit_matrix();
2671
+ var AlignmentPattern = require_alignment_pattern();
2672
+ var FinderPattern = require_finder_pattern();
2673
+ var MaskPattern = require_mask_pattern();
2674
+ var ECCode = require_error_correction_code();
2675
+ var ReedSolomonEncoder = require_reed_solomon_encoder();
2676
+ var Version = require_version();
2677
+ var FormatInfo = require_format_info();
2678
+ var Mode = require_mode();
2679
+ var Segments = require_segments();
2680
+ function setupFinderPattern(matrix, version) {
2681
+ const size = matrix.size;
2682
+ const pos = FinderPattern.getPositions(version);
2683
+ for (let i = 0; i < pos.length; i++) {
2684
+ const row = pos[i][0];
2685
+ const col = pos[i][1];
2686
+ for (let r = -1; r <= 7; r++) {
2687
+ if (row + r <= -1 || size <= row + r) continue;
2688
+ for (let c = -1; c <= 7; c++) {
2689
+ if (col + c <= -1 || size <= col + c) continue;
2690
+ if (r >= 0 && r <= 6 && (c === 0 || c === 6) || c >= 0 && c <= 6 && (r === 0 || r === 6) || r >= 2 && r <= 4 && c >= 2 && c <= 4) {
2691
+ matrix.set(row + r, col + c, true, true);
2692
+ } else {
2693
+ matrix.set(row + r, col + c, false, true);
2694
+ }
2695
+ }
2696
+ }
2697
+ }
2698
+ }
2699
+ function setupTimingPattern(matrix) {
2700
+ const size = matrix.size;
2701
+ for (let r = 8; r < size - 8; r++) {
2702
+ const value = r % 2 === 0;
2703
+ matrix.set(r, 6, value, true);
2704
+ matrix.set(6, r, value, true);
2705
+ }
2706
+ }
2707
+ function setupAlignmentPattern(matrix, version) {
2708
+ const pos = AlignmentPattern.getPositions(version);
2709
+ for (let i = 0; i < pos.length; i++) {
2710
+ const row = pos[i][0];
2711
+ const col = pos[i][1];
2712
+ for (let r = -2; r <= 2; r++) {
2713
+ for (let c = -2; c <= 2; c++) {
2714
+ if (r === -2 || r === 2 || c === -2 || c === 2 || r === 0 && c === 0) {
2715
+ matrix.set(row + r, col + c, true, true);
2716
+ } else {
2717
+ matrix.set(row + r, col + c, false, true);
2718
+ }
2719
+ }
2720
+ }
2721
+ }
2722
+ }
2723
+ function setupVersionInfo(matrix, version) {
2724
+ const size = matrix.size;
2725
+ const bits = Version.getEncodedBits(version);
2726
+ let row, col, mod;
2727
+ for (let i = 0; i < 18; i++) {
2728
+ row = Math.floor(i / 3);
2729
+ col = i % 3 + size - 8 - 3;
2730
+ mod = (bits >> i & 1) === 1;
2731
+ matrix.set(row, col, mod, true);
2732
+ matrix.set(col, row, mod, true);
2733
+ }
2734
+ }
2735
+ function setupFormatInfo(matrix, errorCorrectionLevel, maskPattern) {
2736
+ const size = matrix.size;
2737
+ const bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern);
2738
+ let i, mod;
2739
+ for (i = 0; i < 15; i++) {
2740
+ mod = (bits >> i & 1) === 1;
2741
+ if (i < 6) {
2742
+ matrix.set(i, 8, mod, true);
2743
+ } else if (i < 8) {
2744
+ matrix.set(i + 1, 8, mod, true);
2745
+ } else {
2746
+ matrix.set(size - 15 + i, 8, mod, true);
2747
+ }
2748
+ if (i < 8) {
2749
+ matrix.set(8, size - i - 1, mod, true);
2750
+ } else if (i < 9) {
2751
+ matrix.set(8, 15 - i - 1 + 1, mod, true);
2752
+ } else {
2753
+ matrix.set(8, 15 - i - 1, mod, true);
2754
+ }
2755
+ }
2756
+ matrix.set(size - 8, 8, 1, true);
2757
+ }
2758
+ function setupData(matrix, data) {
2759
+ const size = matrix.size;
2760
+ let inc = -1;
2761
+ let row = size - 1;
2762
+ let bitIndex = 7;
2763
+ let byteIndex = 0;
2764
+ for (let col = size - 1; col > 0; col -= 2) {
2765
+ if (col === 6) col--;
2766
+ while (true) {
2767
+ for (let c = 0; c < 2; c++) {
2768
+ if (!matrix.isReserved(row, col - c)) {
2769
+ let dark = false;
2770
+ if (byteIndex < data.length) {
2771
+ dark = (data[byteIndex] >>> bitIndex & 1) === 1;
2772
+ }
2773
+ matrix.set(row, col - c, dark);
2774
+ bitIndex--;
2775
+ if (bitIndex === -1) {
2776
+ byteIndex++;
2777
+ bitIndex = 7;
2778
+ }
2779
+ }
2780
+ }
2781
+ row += inc;
2782
+ if (row < 0 || size <= row) {
2783
+ row -= inc;
2784
+ inc = -inc;
2785
+ break;
2786
+ }
2787
+ }
2788
+ }
2789
+ }
2790
+ function createData(version, errorCorrectionLevel, segments) {
2791
+ const buffer = new BitBuffer();
2792
+ segments.forEach(function(data) {
2793
+ buffer.put(data.mode.bit, 4);
2794
+ buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version));
2795
+ data.write(buffer);
2796
+ });
2797
+ const totalCodewords = Utils.getSymbolTotalCodewords(version);
2798
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
2799
+ const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
2800
+ if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
2801
+ buffer.put(0, 4);
2802
+ }
2803
+ while (buffer.getLengthInBits() % 8 !== 0) {
2804
+ buffer.putBit(0);
2805
+ }
2806
+ const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8;
2807
+ for (let i = 0; i < remainingByte; i++) {
2808
+ buffer.put(i % 2 ? 17 : 236, 8);
2809
+ }
2810
+ return createCodewords(buffer, version, errorCorrectionLevel);
2811
+ }
2812
+ function createCodewords(bitBuffer, version, errorCorrectionLevel) {
2813
+ const totalCodewords = Utils.getSymbolTotalCodewords(version);
2814
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
2815
+ const dataTotalCodewords = totalCodewords - ecTotalCodewords;
2816
+ const ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel);
2817
+ const blocksInGroup2 = totalCodewords % ecTotalBlocks;
2818
+ const blocksInGroup1 = ecTotalBlocks - blocksInGroup2;
2819
+ const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks);
2820
+ const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks);
2821
+ const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1;
2822
+ const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1;
2823
+ const rs = new ReedSolomonEncoder(ecCount);
2824
+ let offset = 0;
2825
+ const dcData = new Array(ecTotalBlocks);
2826
+ const ecData = new Array(ecTotalBlocks);
2827
+ let maxDataSize = 0;
2828
+ const buffer = new Uint8Array(bitBuffer.buffer);
2829
+ for (let b = 0; b < ecTotalBlocks; b++) {
2830
+ const dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2;
2831
+ dcData[b] = buffer.slice(offset, offset + dataSize);
2832
+ ecData[b] = rs.encode(dcData[b]);
2833
+ offset += dataSize;
2834
+ maxDataSize = Math.max(maxDataSize, dataSize);
2835
+ }
2836
+ const data = new Uint8Array(totalCodewords);
2837
+ let index = 0;
2838
+ let i, r;
2839
+ for (i = 0; i < maxDataSize; i++) {
2840
+ for (r = 0; r < ecTotalBlocks; r++) {
2841
+ if (i < dcData[r].length) {
2842
+ data[index++] = dcData[r][i];
2843
+ }
2844
+ }
2845
+ }
2846
+ for (i = 0; i < ecCount; i++) {
2847
+ for (r = 0; r < ecTotalBlocks; r++) {
2848
+ data[index++] = ecData[r][i];
2849
+ }
2850
+ }
2851
+ return data;
2852
+ }
2853
+ function createSymbol(data, version, errorCorrectionLevel, maskPattern) {
2854
+ let segments;
2855
+ if (Array.isArray(data)) {
2856
+ segments = Segments.fromArray(data);
2857
+ } else if (typeof data === "string") {
2858
+ let estimatedVersion = version;
2859
+ if (!estimatedVersion) {
2860
+ const rawSegments = Segments.rawSplit(data);
2861
+ estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel);
2862
+ }
2863
+ segments = Segments.fromString(data, estimatedVersion || 40);
2864
+ } else {
2865
+ throw new Error("Invalid data");
2866
+ }
2867
+ const bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel);
2868
+ if (!bestVersion) {
2869
+ throw new Error("The amount of data is too big to be stored in a QR Code");
2870
+ }
2871
+ if (!version) {
2872
+ version = bestVersion;
2873
+ } else if (version < bestVersion) {
2874
+ throw new Error(
2875
+ "\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: " + bestVersion + ".\n"
2876
+ );
2877
+ }
2878
+ const dataBits = createData(version, errorCorrectionLevel, segments);
2879
+ const moduleCount = Utils.getSymbolSize(version);
2880
+ const modules = new BitMatrix(moduleCount);
2881
+ setupFinderPattern(modules, version);
2882
+ setupTimingPattern(modules);
2883
+ setupAlignmentPattern(modules, version);
2884
+ setupFormatInfo(modules, errorCorrectionLevel, 0);
2885
+ if (version >= 7) {
2886
+ setupVersionInfo(modules, version);
2887
+ }
2888
+ setupData(modules, dataBits);
2889
+ if (isNaN(maskPattern)) {
2890
+ maskPattern = MaskPattern.getBestMask(
2891
+ modules,
2892
+ setupFormatInfo.bind(null, modules, errorCorrectionLevel)
2893
+ );
2894
+ }
2895
+ MaskPattern.applyMask(maskPattern, modules);
2896
+ setupFormatInfo(modules, errorCorrectionLevel, maskPattern);
2897
+ return {
2898
+ modules,
2899
+ version,
2900
+ errorCorrectionLevel,
2901
+ maskPattern,
2902
+ segments
2903
+ };
2904
+ }
2905
+ exports.create = function create(data, options) {
2906
+ if (typeof data === "undefined" || data === "") {
2907
+ throw new Error("No input text");
2908
+ }
2909
+ let errorCorrectionLevel = ECLevel.M;
2910
+ let version;
2911
+ let mask;
2912
+ if (typeof options !== "undefined") {
2913
+ errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M);
2914
+ version = Version.from(options.version);
2915
+ mask = MaskPattern.from(options.maskPattern);
2916
+ if (options.toSJISFunc) {
2917
+ Utils.setToSJISFunction(options.toSJISFunc);
2918
+ }
2919
+ }
2920
+ return createSymbol(data, version, errorCorrectionLevel, mask);
2921
+ };
2922
+ }
2923
+ });
2924
+
2925
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/chunkstream.js
2926
+ var require_chunkstream = __commonJS({
2927
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/chunkstream.js"(exports, module) {
2928
+ "use strict";
2929
+ var util = __require("util");
2930
+ var Stream = __require("stream");
2931
+ var ChunkStream = module.exports = function() {
2932
+ Stream.call(this);
2933
+ this._buffers = [];
2934
+ this._buffered = 0;
2935
+ this._reads = [];
2936
+ this._paused = false;
2937
+ this._encoding = "utf8";
2938
+ this.writable = true;
2939
+ };
2940
+ util.inherits(ChunkStream, Stream);
2941
+ ChunkStream.prototype.read = function(length, callback) {
2942
+ this._reads.push({
2943
+ length: Math.abs(length),
2944
+ // if length < 0 then at most this length
2945
+ allowLess: length < 0,
2946
+ func: callback
2947
+ });
2948
+ process.nextTick(
2949
+ function() {
2950
+ this._process();
2951
+ if (this._paused && this._reads && this._reads.length > 0) {
2952
+ this._paused = false;
2953
+ this.emit("drain");
2954
+ }
2955
+ }.bind(this)
2956
+ );
2957
+ };
2958
+ ChunkStream.prototype.write = function(data, encoding) {
2959
+ if (!this.writable) {
2960
+ this.emit("error", new Error("Stream not writable"));
2961
+ return false;
2962
+ }
2963
+ let dataBuffer;
2964
+ if (Buffer.isBuffer(data)) {
2965
+ dataBuffer = data;
2966
+ } else {
2967
+ dataBuffer = Buffer.from(data, encoding || this._encoding);
2968
+ }
2969
+ this._buffers.push(dataBuffer);
2970
+ this._buffered += dataBuffer.length;
2971
+ this._process();
2972
+ if (this._reads && this._reads.length === 0) {
2973
+ this._paused = true;
2974
+ }
2975
+ return this.writable && !this._paused;
2976
+ };
2977
+ ChunkStream.prototype.end = function(data, encoding) {
2978
+ if (data) {
2979
+ this.write(data, encoding);
2980
+ }
2981
+ this.writable = false;
2982
+ if (!this._buffers) {
2983
+ return;
2984
+ }
2985
+ if (this._buffers.length === 0) {
2986
+ this._end();
2987
+ } else {
2988
+ this._buffers.push(null);
2989
+ this._process();
2990
+ }
2991
+ };
2992
+ ChunkStream.prototype.destroySoon = ChunkStream.prototype.end;
2993
+ ChunkStream.prototype._end = function() {
2994
+ if (this._reads.length > 0) {
2995
+ this.emit("error", new Error("Unexpected end of input"));
2996
+ }
2997
+ this.destroy();
2998
+ };
2999
+ ChunkStream.prototype.destroy = function() {
3000
+ if (!this._buffers) {
3001
+ return;
3002
+ }
3003
+ this.writable = false;
3004
+ this._reads = null;
3005
+ this._buffers = null;
3006
+ this.emit("close");
3007
+ };
3008
+ ChunkStream.prototype._processReadAllowingLess = function(read) {
3009
+ this._reads.shift();
3010
+ let smallerBuf = this._buffers[0];
3011
+ if (smallerBuf.length > read.length) {
3012
+ this._buffered -= read.length;
3013
+ this._buffers[0] = smallerBuf.slice(read.length);
3014
+ read.func.call(this, smallerBuf.slice(0, read.length));
3015
+ } else {
3016
+ this._buffered -= smallerBuf.length;
3017
+ this._buffers.shift();
3018
+ read.func.call(this, smallerBuf);
3019
+ }
3020
+ };
3021
+ ChunkStream.prototype._processRead = function(read) {
3022
+ this._reads.shift();
3023
+ let pos = 0;
3024
+ let count = 0;
3025
+ let data = Buffer.alloc(read.length);
3026
+ while (pos < read.length) {
3027
+ let buf = this._buffers[count++];
3028
+ let len = Math.min(buf.length, read.length - pos);
3029
+ buf.copy(data, pos, 0, len);
3030
+ pos += len;
3031
+ if (len !== buf.length) {
3032
+ this._buffers[--count] = buf.slice(len);
3033
+ }
3034
+ }
3035
+ if (count > 0) {
3036
+ this._buffers.splice(0, count);
3037
+ }
3038
+ this._buffered -= read.length;
3039
+ read.func.call(this, data);
3040
+ };
3041
+ ChunkStream.prototype._process = function() {
3042
+ try {
3043
+ while (this._buffered > 0 && this._reads && this._reads.length > 0) {
3044
+ let read = this._reads[0];
3045
+ if (read.allowLess) {
3046
+ this._processReadAllowingLess(read);
3047
+ } else if (this._buffered >= read.length) {
3048
+ this._processRead(read);
3049
+ } else {
3050
+ break;
3051
+ }
3052
+ }
3053
+ if (this._buffers && !this.writable) {
3054
+ this._end();
3055
+ }
3056
+ } catch (ex) {
3057
+ this.emit("error", ex);
3058
+ }
3059
+ };
3060
+ }
3061
+ });
3062
+
3063
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/interlace.js
3064
+ var require_interlace = __commonJS({
3065
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/interlace.js"(exports) {
3066
+ "use strict";
3067
+ var imagePasses = [
3068
+ {
3069
+ // pass 1 - 1px
3070
+ x: [0],
3071
+ y: [0]
3072
+ },
3073
+ {
3074
+ // pass 2 - 1px
3075
+ x: [4],
3076
+ y: [0]
3077
+ },
3078
+ {
3079
+ // pass 3 - 2px
3080
+ x: [0, 4],
3081
+ y: [4]
3082
+ },
3083
+ {
3084
+ // pass 4 - 4px
3085
+ x: [2, 6],
3086
+ y: [0, 4]
3087
+ },
3088
+ {
3089
+ // pass 5 - 8px
3090
+ x: [0, 2, 4, 6],
3091
+ y: [2, 6]
3092
+ },
3093
+ {
3094
+ // pass 6 - 16px
3095
+ x: [1, 3, 5, 7],
3096
+ y: [0, 2, 4, 6]
3097
+ },
3098
+ {
3099
+ // pass 7 - 32px
3100
+ x: [0, 1, 2, 3, 4, 5, 6, 7],
3101
+ y: [1, 3, 5, 7]
3102
+ }
3103
+ ];
3104
+ exports.getImagePasses = function(width, height) {
3105
+ let images = [];
3106
+ let xLeftOver = width % 8;
3107
+ let yLeftOver = height % 8;
3108
+ let xRepeats = (width - xLeftOver) / 8;
3109
+ let yRepeats = (height - yLeftOver) / 8;
3110
+ for (let i = 0; i < imagePasses.length; i++) {
3111
+ let pass = imagePasses[i];
3112
+ let passWidth = xRepeats * pass.x.length;
3113
+ let passHeight = yRepeats * pass.y.length;
3114
+ for (let j = 0; j < pass.x.length; j++) {
3115
+ if (pass.x[j] < xLeftOver) {
3116
+ passWidth++;
3117
+ } else {
3118
+ break;
3119
+ }
3120
+ }
3121
+ for (let j = 0; j < pass.y.length; j++) {
3122
+ if (pass.y[j] < yLeftOver) {
3123
+ passHeight++;
3124
+ } else {
3125
+ break;
3126
+ }
3127
+ }
3128
+ if (passWidth > 0 && passHeight > 0) {
3129
+ images.push({ width: passWidth, height: passHeight, index: i });
3130
+ }
3131
+ }
3132
+ return images;
3133
+ };
3134
+ exports.getInterlaceIterator = function(width) {
3135
+ return function(x, y, pass) {
3136
+ let outerXLeftOver = x % imagePasses[pass].x.length;
3137
+ let outerX = (x - outerXLeftOver) / imagePasses[pass].x.length * 8 + imagePasses[pass].x[outerXLeftOver];
3138
+ let outerYLeftOver = y % imagePasses[pass].y.length;
3139
+ let outerY = (y - outerYLeftOver) / imagePasses[pass].y.length * 8 + imagePasses[pass].y[outerYLeftOver];
3140
+ return outerX * 4 + outerY * width * 4;
3141
+ };
3142
+ };
3143
+ }
3144
+ });
3145
+
3146
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/paeth-predictor.js
3147
+ var require_paeth_predictor = __commonJS({
3148
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/paeth-predictor.js"(exports, module) {
3149
+ "use strict";
3150
+ module.exports = function paethPredictor(left, above, upLeft) {
3151
+ let paeth = left + above - upLeft;
3152
+ let pLeft = Math.abs(paeth - left);
3153
+ let pAbove = Math.abs(paeth - above);
3154
+ let pUpLeft = Math.abs(paeth - upLeft);
3155
+ if (pLeft <= pAbove && pLeft <= pUpLeft) {
3156
+ return left;
3157
+ }
3158
+ if (pAbove <= pUpLeft) {
3159
+ return above;
3160
+ }
3161
+ return upLeft;
3162
+ };
3163
+ }
3164
+ });
3165
+
3166
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse.js
3167
+ var require_filter_parse = __commonJS({
3168
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse.js"(exports, module) {
3169
+ "use strict";
3170
+ var interlaceUtils = require_interlace();
3171
+ var paethPredictor = require_paeth_predictor();
3172
+ function getByteWidth(width, bpp, depth) {
3173
+ let byteWidth = width * bpp;
3174
+ if (depth !== 8) {
3175
+ byteWidth = Math.ceil(byteWidth / (8 / depth));
3176
+ }
3177
+ return byteWidth;
3178
+ }
3179
+ var Filter = module.exports = function(bitmapInfo, dependencies) {
3180
+ let width = bitmapInfo.width;
3181
+ let height = bitmapInfo.height;
3182
+ let interlace = bitmapInfo.interlace;
3183
+ let bpp = bitmapInfo.bpp;
3184
+ let depth = bitmapInfo.depth;
3185
+ this.read = dependencies.read;
3186
+ this.write = dependencies.write;
3187
+ this.complete = dependencies.complete;
3188
+ this._imageIndex = 0;
3189
+ this._images = [];
3190
+ if (interlace) {
3191
+ let passes = interlaceUtils.getImagePasses(width, height);
3192
+ for (let i = 0; i < passes.length; i++) {
3193
+ this._images.push({
3194
+ byteWidth: getByteWidth(passes[i].width, bpp, depth),
3195
+ height: passes[i].height,
3196
+ lineIndex: 0
3197
+ });
3198
+ }
3199
+ } else {
3200
+ this._images.push({
3201
+ byteWidth: getByteWidth(width, bpp, depth),
3202
+ height,
3203
+ lineIndex: 0
3204
+ });
3205
+ }
3206
+ if (depth === 8) {
3207
+ this._xComparison = bpp;
3208
+ } else if (depth === 16) {
3209
+ this._xComparison = bpp * 2;
3210
+ } else {
3211
+ this._xComparison = 1;
3212
+ }
3213
+ };
3214
+ Filter.prototype.start = function() {
3215
+ this.read(
3216
+ this._images[this._imageIndex].byteWidth + 1,
3217
+ this._reverseFilterLine.bind(this)
3218
+ );
3219
+ };
3220
+ Filter.prototype._unFilterType1 = function(rawData, unfilteredLine, byteWidth) {
3221
+ let xComparison = this._xComparison;
3222
+ let xBiggerThan = xComparison - 1;
3223
+ for (let x = 0; x < byteWidth; x++) {
3224
+ let rawByte = rawData[1 + x];
3225
+ let f1Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
3226
+ unfilteredLine[x] = rawByte + f1Left;
3227
+ }
3228
+ };
3229
+ Filter.prototype._unFilterType2 = function(rawData, unfilteredLine, byteWidth) {
3230
+ let lastLine = this._lastLine;
3231
+ for (let x = 0; x < byteWidth; x++) {
3232
+ let rawByte = rawData[1 + x];
3233
+ let f2Up = lastLine ? lastLine[x] : 0;
3234
+ unfilteredLine[x] = rawByte + f2Up;
3235
+ }
3236
+ };
3237
+ Filter.prototype._unFilterType3 = function(rawData, unfilteredLine, byteWidth) {
3238
+ let xComparison = this._xComparison;
3239
+ let xBiggerThan = xComparison - 1;
3240
+ let lastLine = this._lastLine;
3241
+ for (let x = 0; x < byteWidth; x++) {
3242
+ let rawByte = rawData[1 + x];
3243
+ let f3Up = lastLine ? lastLine[x] : 0;
3244
+ let f3Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
3245
+ let f3Add = Math.floor((f3Left + f3Up) / 2);
3246
+ unfilteredLine[x] = rawByte + f3Add;
3247
+ }
3248
+ };
3249
+ Filter.prototype._unFilterType4 = function(rawData, unfilteredLine, byteWidth) {
3250
+ let xComparison = this._xComparison;
3251
+ let xBiggerThan = xComparison - 1;
3252
+ let lastLine = this._lastLine;
3253
+ for (let x = 0; x < byteWidth; x++) {
3254
+ let rawByte = rawData[1 + x];
3255
+ let f4Up = lastLine ? lastLine[x] : 0;
3256
+ let f4Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
3257
+ let f4UpLeft = x > xBiggerThan && lastLine ? lastLine[x - xComparison] : 0;
3258
+ let f4Add = paethPredictor(f4Left, f4Up, f4UpLeft);
3259
+ unfilteredLine[x] = rawByte + f4Add;
3260
+ }
3261
+ };
3262
+ Filter.prototype._reverseFilterLine = function(rawData) {
3263
+ let filter = rawData[0];
3264
+ let unfilteredLine;
3265
+ let currentImage = this._images[this._imageIndex];
3266
+ let byteWidth = currentImage.byteWidth;
3267
+ if (filter === 0) {
3268
+ unfilteredLine = rawData.slice(1, byteWidth + 1);
3269
+ } else {
3270
+ unfilteredLine = Buffer.alloc(byteWidth);
3271
+ switch (filter) {
3272
+ case 1:
3273
+ this._unFilterType1(rawData, unfilteredLine, byteWidth);
3274
+ break;
3275
+ case 2:
3276
+ this._unFilterType2(rawData, unfilteredLine, byteWidth);
3277
+ break;
3278
+ case 3:
3279
+ this._unFilterType3(rawData, unfilteredLine, byteWidth);
3280
+ break;
3281
+ case 4:
3282
+ this._unFilterType4(rawData, unfilteredLine, byteWidth);
3283
+ break;
3284
+ default:
3285
+ throw new Error("Unrecognised filter type - " + filter);
3286
+ }
3287
+ }
3288
+ this.write(unfilteredLine);
3289
+ currentImage.lineIndex++;
3290
+ if (currentImage.lineIndex >= currentImage.height) {
3291
+ this._lastLine = null;
3292
+ this._imageIndex++;
3293
+ currentImage = this._images[this._imageIndex];
3294
+ } else {
3295
+ this._lastLine = unfilteredLine;
3296
+ }
3297
+ if (currentImage) {
3298
+ this.read(currentImage.byteWidth + 1, this._reverseFilterLine.bind(this));
3299
+ } else {
3300
+ this._lastLine = null;
3301
+ this.complete();
3302
+ }
3303
+ };
3304
+ }
3305
+ });
3306
+
3307
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-async.js
3308
+ var require_filter_parse_async = __commonJS({
3309
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-async.js"(exports, module) {
3310
+ "use strict";
3311
+ var util = __require("util");
3312
+ var ChunkStream = require_chunkstream();
3313
+ var Filter = require_filter_parse();
3314
+ var FilterAsync = module.exports = function(bitmapInfo) {
3315
+ ChunkStream.call(this);
3316
+ let buffers = [];
3317
+ let that = this;
3318
+ this._filter = new Filter(bitmapInfo, {
3319
+ read: this.read.bind(this),
3320
+ write: function(buffer) {
3321
+ buffers.push(buffer);
3322
+ },
3323
+ complete: function() {
3324
+ that.emit("complete", Buffer.concat(buffers));
3325
+ }
3326
+ });
3327
+ this._filter.start();
3328
+ };
3329
+ util.inherits(FilterAsync, ChunkStream);
3330
+ }
3331
+ });
3332
+
3333
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/constants.js
3334
+ var require_constants = __commonJS({
3335
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/constants.js"(exports, module) {
3336
+ "use strict";
3337
+ module.exports = {
3338
+ PNG_SIGNATURE: [137, 80, 78, 71, 13, 10, 26, 10],
3339
+ TYPE_IHDR: 1229472850,
3340
+ TYPE_IEND: 1229278788,
3341
+ TYPE_IDAT: 1229209940,
3342
+ TYPE_PLTE: 1347179589,
3343
+ TYPE_tRNS: 1951551059,
3344
+ // eslint-disable-line camelcase
3345
+ TYPE_gAMA: 1732332865,
3346
+ // eslint-disable-line camelcase
3347
+ // color-type bits
3348
+ COLORTYPE_GRAYSCALE: 0,
3349
+ COLORTYPE_PALETTE: 1,
3350
+ COLORTYPE_COLOR: 2,
3351
+ COLORTYPE_ALPHA: 4,
3352
+ // e.g. grayscale and alpha
3353
+ // color-type combinations
3354
+ COLORTYPE_PALETTE_COLOR: 3,
3355
+ COLORTYPE_COLOR_ALPHA: 6,
3356
+ COLORTYPE_TO_BPP_MAP: {
3357
+ 0: 1,
3358
+ 2: 3,
3359
+ 3: 1,
3360
+ 4: 2,
3361
+ 6: 4
3362
+ },
3363
+ GAMMA_DIVISION: 1e5
3364
+ };
3365
+ }
3366
+ });
3367
+
3368
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/crc.js
3369
+ var require_crc = __commonJS({
3370
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/crc.js"(exports, module) {
3371
+ "use strict";
3372
+ var crcTable = [];
3373
+ (function() {
3374
+ for (let i = 0; i < 256; i++) {
3375
+ let currentCrc = i;
3376
+ for (let j = 0; j < 8; j++) {
3377
+ if (currentCrc & 1) {
3378
+ currentCrc = 3988292384 ^ currentCrc >>> 1;
3379
+ } else {
3380
+ currentCrc = currentCrc >>> 1;
3381
+ }
3382
+ }
3383
+ crcTable[i] = currentCrc;
3384
+ }
3385
+ })();
3386
+ var CrcCalculator = module.exports = function() {
3387
+ this._crc = -1;
3388
+ };
3389
+ CrcCalculator.prototype.write = function(data) {
3390
+ for (let i = 0; i < data.length; i++) {
3391
+ this._crc = crcTable[(this._crc ^ data[i]) & 255] ^ this._crc >>> 8;
3392
+ }
3393
+ return true;
3394
+ };
3395
+ CrcCalculator.prototype.crc32 = function() {
3396
+ return this._crc ^ -1;
3397
+ };
3398
+ CrcCalculator.crc32 = function(buf) {
3399
+ let crc = -1;
3400
+ for (let i = 0; i < buf.length; i++) {
3401
+ crc = crcTable[(crc ^ buf[i]) & 255] ^ crc >>> 8;
3402
+ }
3403
+ return crc ^ -1;
3404
+ };
3405
+ }
3406
+ });
3407
+
3408
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser.js
3409
+ var require_parser = __commonJS({
3410
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser.js"(exports, module) {
3411
+ "use strict";
3412
+ var constants = require_constants();
3413
+ var CrcCalculator = require_crc();
3414
+ var Parser = module.exports = function(options, dependencies) {
3415
+ this._options = options;
3416
+ options.checkCRC = options.checkCRC !== false;
3417
+ this._hasIHDR = false;
3418
+ this._hasIEND = false;
3419
+ this._emittedHeadersFinished = false;
3420
+ this._palette = [];
3421
+ this._colorType = 0;
3422
+ this._chunks = {};
3423
+ this._chunks[constants.TYPE_IHDR] = this._handleIHDR.bind(this);
3424
+ this._chunks[constants.TYPE_IEND] = this._handleIEND.bind(this);
3425
+ this._chunks[constants.TYPE_IDAT] = this._handleIDAT.bind(this);
3426
+ this._chunks[constants.TYPE_PLTE] = this._handlePLTE.bind(this);
3427
+ this._chunks[constants.TYPE_tRNS] = this._handleTRNS.bind(this);
3428
+ this._chunks[constants.TYPE_gAMA] = this._handleGAMA.bind(this);
3429
+ this.read = dependencies.read;
3430
+ this.error = dependencies.error;
3431
+ this.metadata = dependencies.metadata;
3432
+ this.gamma = dependencies.gamma;
3433
+ this.transColor = dependencies.transColor;
3434
+ this.palette = dependencies.palette;
3435
+ this.parsed = dependencies.parsed;
3436
+ this.inflateData = dependencies.inflateData;
3437
+ this.finished = dependencies.finished;
3438
+ this.simpleTransparency = dependencies.simpleTransparency;
3439
+ this.headersFinished = dependencies.headersFinished || function() {
3440
+ };
3441
+ };
3442
+ Parser.prototype.start = function() {
3443
+ this.read(constants.PNG_SIGNATURE.length, this._parseSignature.bind(this));
3444
+ };
3445
+ Parser.prototype._parseSignature = function(data) {
3446
+ let signature = constants.PNG_SIGNATURE;
3447
+ for (let i = 0; i < signature.length; i++) {
3448
+ if (data[i] !== signature[i]) {
3449
+ this.error(new Error("Invalid file signature"));
3450
+ return;
3451
+ }
3452
+ }
3453
+ this.read(8, this._parseChunkBegin.bind(this));
3454
+ };
3455
+ Parser.prototype._parseChunkBegin = function(data) {
3456
+ let length = data.readUInt32BE(0);
3457
+ let type = data.readUInt32BE(4);
3458
+ let name2 = "";
3459
+ for (let i = 4; i < 8; i++) {
3460
+ name2 += String.fromCharCode(data[i]);
3461
+ }
3462
+ let ancillary = Boolean(data[4] & 32);
3463
+ if (!this._hasIHDR && type !== constants.TYPE_IHDR) {
3464
+ this.error(new Error("Expected IHDR on beggining"));
3465
+ return;
3466
+ }
3467
+ this._crc = new CrcCalculator();
3468
+ this._crc.write(Buffer.from(name2));
3469
+ if (this._chunks[type]) {
3470
+ return this._chunks[type](length);
3471
+ }
3472
+ if (!ancillary) {
3473
+ this.error(new Error("Unsupported critical chunk type " + name2));
3474
+ return;
3475
+ }
3476
+ this.read(length + 4, this._skipChunk.bind(this));
3477
+ };
3478
+ Parser.prototype._skipChunk = function() {
3479
+ this.read(8, this._parseChunkBegin.bind(this));
3480
+ };
3481
+ Parser.prototype._handleChunkEnd = function() {
3482
+ this.read(4, this._parseChunkEnd.bind(this));
3483
+ };
3484
+ Parser.prototype._parseChunkEnd = function(data) {
3485
+ let fileCrc = data.readInt32BE(0);
3486
+ let calcCrc = this._crc.crc32();
3487
+ if (this._options.checkCRC && calcCrc !== fileCrc) {
3488
+ this.error(new Error("Crc error - " + fileCrc + " - " + calcCrc));
3489
+ return;
3490
+ }
3491
+ if (!this._hasIEND) {
3492
+ this.read(8, this._parseChunkBegin.bind(this));
3493
+ }
3494
+ };
3495
+ Parser.prototype._handleIHDR = function(length) {
3496
+ this.read(length, this._parseIHDR.bind(this));
3497
+ };
3498
+ Parser.prototype._parseIHDR = function(data) {
3499
+ this._crc.write(data);
3500
+ let width = data.readUInt32BE(0);
3501
+ let height = data.readUInt32BE(4);
3502
+ let depth = data[8];
3503
+ let colorType = data[9];
3504
+ let compr = data[10];
3505
+ let filter = data[11];
3506
+ let interlace = data[12];
3507
+ if (depth !== 8 && depth !== 4 && depth !== 2 && depth !== 1 && depth !== 16) {
3508
+ this.error(new Error("Unsupported bit depth " + depth));
3509
+ return;
3510
+ }
3511
+ if (!(colorType in constants.COLORTYPE_TO_BPP_MAP)) {
3512
+ this.error(new Error("Unsupported color type"));
3513
+ return;
3514
+ }
3515
+ if (compr !== 0) {
3516
+ this.error(new Error("Unsupported compression method"));
3517
+ return;
3518
+ }
3519
+ if (filter !== 0) {
3520
+ this.error(new Error("Unsupported filter method"));
3521
+ return;
3522
+ }
3523
+ if (interlace !== 0 && interlace !== 1) {
3524
+ this.error(new Error("Unsupported interlace method"));
3525
+ return;
3526
+ }
3527
+ this._colorType = colorType;
3528
+ let bpp = constants.COLORTYPE_TO_BPP_MAP[this._colorType];
3529
+ this._hasIHDR = true;
3530
+ this.metadata({
3531
+ width,
3532
+ height,
3533
+ depth,
3534
+ interlace: Boolean(interlace),
3535
+ palette: Boolean(colorType & constants.COLORTYPE_PALETTE),
3536
+ color: Boolean(colorType & constants.COLORTYPE_COLOR),
3537
+ alpha: Boolean(colorType & constants.COLORTYPE_ALPHA),
3538
+ bpp,
3539
+ colorType
3540
+ });
3541
+ this._handleChunkEnd();
3542
+ };
3543
+ Parser.prototype._handlePLTE = function(length) {
3544
+ this.read(length, this._parsePLTE.bind(this));
3545
+ };
3546
+ Parser.prototype._parsePLTE = function(data) {
3547
+ this._crc.write(data);
3548
+ let entries = Math.floor(data.length / 3);
3549
+ for (let i = 0; i < entries; i++) {
3550
+ this._palette.push([data[i * 3], data[i * 3 + 1], data[i * 3 + 2], 255]);
3551
+ }
3552
+ this.palette(this._palette);
3553
+ this._handleChunkEnd();
3554
+ };
3555
+ Parser.prototype._handleTRNS = function(length) {
3556
+ this.simpleTransparency();
3557
+ this.read(length, this._parseTRNS.bind(this));
3558
+ };
3559
+ Parser.prototype._parseTRNS = function(data) {
3560
+ this._crc.write(data);
3561
+ if (this._colorType === constants.COLORTYPE_PALETTE_COLOR) {
3562
+ if (this._palette.length === 0) {
3563
+ this.error(new Error("Transparency chunk must be after palette"));
3564
+ return;
3565
+ }
3566
+ if (data.length > this._palette.length) {
3567
+ this.error(new Error("More transparent colors than palette size"));
3568
+ return;
3569
+ }
3570
+ for (let i = 0; i < data.length; i++) {
3571
+ this._palette[i][3] = data[i];
3572
+ }
3573
+ this.palette(this._palette);
3574
+ }
3575
+ if (this._colorType === constants.COLORTYPE_GRAYSCALE) {
3576
+ this.transColor([data.readUInt16BE(0)]);
3577
+ }
3578
+ if (this._colorType === constants.COLORTYPE_COLOR) {
3579
+ this.transColor([
3580
+ data.readUInt16BE(0),
3581
+ data.readUInt16BE(2),
3582
+ data.readUInt16BE(4)
3583
+ ]);
3584
+ }
3585
+ this._handleChunkEnd();
3586
+ };
3587
+ Parser.prototype._handleGAMA = function(length) {
3588
+ this.read(length, this._parseGAMA.bind(this));
3589
+ };
3590
+ Parser.prototype._parseGAMA = function(data) {
3591
+ this._crc.write(data);
3592
+ this.gamma(data.readUInt32BE(0) / constants.GAMMA_DIVISION);
3593
+ this._handleChunkEnd();
3594
+ };
3595
+ Parser.prototype._handleIDAT = function(length) {
3596
+ if (!this._emittedHeadersFinished) {
3597
+ this._emittedHeadersFinished = true;
3598
+ this.headersFinished();
3599
+ }
3600
+ this.read(-length, this._parseIDAT.bind(this, length));
3601
+ };
3602
+ Parser.prototype._parseIDAT = function(length, data) {
3603
+ this._crc.write(data);
3604
+ if (this._colorType === constants.COLORTYPE_PALETTE_COLOR && this._palette.length === 0) {
3605
+ throw new Error("Expected palette not found");
3606
+ }
3607
+ this.inflateData(data);
3608
+ let leftOverLength = length - data.length;
3609
+ if (leftOverLength > 0) {
3610
+ this._handleIDAT(leftOverLength);
3611
+ } else {
3612
+ this._handleChunkEnd();
3613
+ }
3614
+ };
3615
+ Parser.prototype._handleIEND = function(length) {
3616
+ this.read(length, this._parseIEND.bind(this));
3617
+ };
3618
+ Parser.prototype._parseIEND = function(data) {
3619
+ this._crc.write(data);
3620
+ this._hasIEND = true;
3621
+ this._handleChunkEnd();
3622
+ if (this.finished) {
3623
+ this.finished();
3624
+ }
3625
+ };
3626
+ }
3627
+ });
3628
+
3629
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitmapper.js
3630
+ var require_bitmapper = __commonJS({
3631
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitmapper.js"(exports) {
3632
+ "use strict";
3633
+ var interlaceUtils = require_interlace();
3634
+ var pixelBppMapper = [
3635
+ // 0 - dummy entry
3636
+ function() {
3637
+ },
3638
+ // 1 - L
3639
+ // 0: 0, 1: 0, 2: 0, 3: 0xff
3640
+ function(pxData, data, pxPos, rawPos) {
3641
+ if (rawPos === data.length) {
3642
+ throw new Error("Ran out of data");
3643
+ }
3644
+ let pixel = data[rawPos];
3645
+ pxData[pxPos] = pixel;
3646
+ pxData[pxPos + 1] = pixel;
3647
+ pxData[pxPos + 2] = pixel;
3648
+ pxData[pxPos + 3] = 255;
3649
+ },
3650
+ // 2 - LA
3651
+ // 0: 0, 1: 0, 2: 0, 3: 1
3652
+ function(pxData, data, pxPos, rawPos) {
3653
+ if (rawPos + 1 >= data.length) {
3654
+ throw new Error("Ran out of data");
3655
+ }
3656
+ let pixel = data[rawPos];
3657
+ pxData[pxPos] = pixel;
3658
+ pxData[pxPos + 1] = pixel;
3659
+ pxData[pxPos + 2] = pixel;
3660
+ pxData[pxPos + 3] = data[rawPos + 1];
3661
+ },
3662
+ // 3 - RGB
3663
+ // 0: 0, 1: 1, 2: 2, 3: 0xff
3664
+ function(pxData, data, pxPos, rawPos) {
3665
+ if (rawPos + 2 >= data.length) {
3666
+ throw new Error("Ran out of data");
3667
+ }
3668
+ pxData[pxPos] = data[rawPos];
3669
+ pxData[pxPos + 1] = data[rawPos + 1];
3670
+ pxData[pxPos + 2] = data[rawPos + 2];
3671
+ pxData[pxPos + 3] = 255;
3672
+ },
3673
+ // 4 - RGBA
3674
+ // 0: 0, 1: 1, 2: 2, 3: 3
3675
+ function(pxData, data, pxPos, rawPos) {
3676
+ if (rawPos + 3 >= data.length) {
3677
+ throw new Error("Ran out of data");
3678
+ }
3679
+ pxData[pxPos] = data[rawPos];
3680
+ pxData[pxPos + 1] = data[rawPos + 1];
3681
+ pxData[pxPos + 2] = data[rawPos + 2];
3682
+ pxData[pxPos + 3] = data[rawPos + 3];
3683
+ }
3684
+ ];
3685
+ var pixelBppCustomMapper = [
3686
+ // 0 - dummy entry
3687
+ function() {
3688
+ },
3689
+ // 1 - L
3690
+ // 0: 0, 1: 0, 2: 0, 3: 0xff
3691
+ function(pxData, pixelData, pxPos, maxBit) {
3692
+ let pixel = pixelData[0];
3693
+ pxData[pxPos] = pixel;
3694
+ pxData[pxPos + 1] = pixel;
3695
+ pxData[pxPos + 2] = pixel;
3696
+ pxData[pxPos + 3] = maxBit;
3697
+ },
3698
+ // 2 - LA
3699
+ // 0: 0, 1: 0, 2: 0, 3: 1
3700
+ function(pxData, pixelData, pxPos) {
3701
+ let pixel = pixelData[0];
3702
+ pxData[pxPos] = pixel;
3703
+ pxData[pxPos + 1] = pixel;
3704
+ pxData[pxPos + 2] = pixel;
3705
+ pxData[pxPos + 3] = pixelData[1];
3706
+ },
3707
+ // 3 - RGB
3708
+ // 0: 0, 1: 1, 2: 2, 3: 0xff
3709
+ function(pxData, pixelData, pxPos, maxBit) {
3710
+ pxData[pxPos] = pixelData[0];
3711
+ pxData[pxPos + 1] = pixelData[1];
3712
+ pxData[pxPos + 2] = pixelData[2];
3713
+ pxData[pxPos + 3] = maxBit;
3714
+ },
3715
+ // 4 - RGBA
3716
+ // 0: 0, 1: 1, 2: 2, 3: 3
3717
+ function(pxData, pixelData, pxPos) {
3718
+ pxData[pxPos] = pixelData[0];
3719
+ pxData[pxPos + 1] = pixelData[1];
3720
+ pxData[pxPos + 2] = pixelData[2];
3721
+ pxData[pxPos + 3] = pixelData[3];
3722
+ }
3723
+ ];
3724
+ function bitRetriever(data, depth) {
3725
+ let leftOver = [];
3726
+ let i = 0;
3727
+ function split() {
3728
+ if (i === data.length) {
3729
+ throw new Error("Ran out of data");
3730
+ }
3731
+ let byte = data[i];
3732
+ i++;
3733
+ let byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
3734
+ switch (depth) {
3735
+ default:
3736
+ throw new Error("unrecognised depth");
3737
+ case 16:
3738
+ byte2 = data[i];
3739
+ i++;
3740
+ leftOver.push((byte << 8) + byte2);
3741
+ break;
3742
+ case 4:
3743
+ byte2 = byte & 15;
3744
+ byte1 = byte >> 4;
3745
+ leftOver.push(byte1, byte2);
3746
+ break;
3747
+ case 2:
3748
+ byte4 = byte & 3;
3749
+ byte3 = byte >> 2 & 3;
3750
+ byte2 = byte >> 4 & 3;
3751
+ byte1 = byte >> 6 & 3;
3752
+ leftOver.push(byte1, byte2, byte3, byte4);
3753
+ break;
3754
+ case 1:
3755
+ byte8 = byte & 1;
3756
+ byte7 = byte >> 1 & 1;
3757
+ byte6 = byte >> 2 & 1;
3758
+ byte5 = byte >> 3 & 1;
3759
+ byte4 = byte >> 4 & 1;
3760
+ byte3 = byte >> 5 & 1;
3761
+ byte2 = byte >> 6 & 1;
3762
+ byte1 = byte >> 7 & 1;
3763
+ leftOver.push(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8);
3764
+ break;
3765
+ }
3766
+ }
3767
+ return {
3768
+ get: function(count) {
3769
+ while (leftOver.length < count) {
3770
+ split();
3771
+ }
3772
+ let returner = leftOver.slice(0, count);
3773
+ leftOver = leftOver.slice(count);
3774
+ return returner;
3775
+ },
3776
+ resetAfterLine: function() {
3777
+ leftOver.length = 0;
3778
+ },
3779
+ end: function() {
3780
+ if (i !== data.length) {
3781
+ throw new Error("extra data found");
3782
+ }
3783
+ }
3784
+ };
3785
+ }
3786
+ function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) {
3787
+ let imageWidth = image.width;
3788
+ let imageHeight = image.height;
3789
+ let imagePass = image.index;
3790
+ for (let y = 0; y < imageHeight; y++) {
3791
+ for (let x = 0; x < imageWidth; x++) {
3792
+ let pxPos = getPxPos(x, y, imagePass);
3793
+ pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
3794
+ rawPos += bpp;
3795
+ }
3796
+ }
3797
+ return rawPos;
3798
+ }
3799
+ function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) {
3800
+ let imageWidth = image.width;
3801
+ let imageHeight = image.height;
3802
+ let imagePass = image.index;
3803
+ for (let y = 0; y < imageHeight; y++) {
3804
+ for (let x = 0; x < imageWidth; x++) {
3805
+ let pixelData = bits.get(bpp);
3806
+ let pxPos = getPxPos(x, y, imagePass);
3807
+ pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
3808
+ }
3809
+ bits.resetAfterLine();
3810
+ }
3811
+ }
3812
+ exports.dataToBitMap = function(data, bitmapInfo) {
3813
+ let width = bitmapInfo.width;
3814
+ let height = bitmapInfo.height;
3815
+ let depth = bitmapInfo.depth;
3816
+ let bpp = bitmapInfo.bpp;
3817
+ let interlace = bitmapInfo.interlace;
3818
+ let bits;
3819
+ if (depth !== 8) {
3820
+ bits = bitRetriever(data, depth);
3821
+ }
3822
+ let pxData;
3823
+ if (depth <= 8) {
3824
+ pxData = Buffer.alloc(width * height * 4);
3825
+ } else {
3826
+ pxData = new Uint16Array(width * height * 4);
3827
+ }
3828
+ let maxBit = Math.pow(2, depth) - 1;
3829
+ let rawPos = 0;
3830
+ let images;
3831
+ let getPxPos;
3832
+ if (interlace) {
3833
+ images = interlaceUtils.getImagePasses(width, height);
3834
+ getPxPos = interlaceUtils.getInterlaceIterator(width, height);
3835
+ } else {
3836
+ let nonInterlacedPxPos = 0;
3837
+ getPxPos = function() {
3838
+ let returner = nonInterlacedPxPos;
3839
+ nonInterlacedPxPos += 4;
3840
+ return returner;
3841
+ };
3842
+ images = [{ width, height }];
3843
+ }
3844
+ for (let imageIndex = 0; imageIndex < images.length; imageIndex++) {
3845
+ if (depth === 8) {
3846
+ rawPos = mapImage8Bit(
3847
+ images[imageIndex],
3848
+ pxData,
3849
+ getPxPos,
3850
+ bpp,
3851
+ data,
3852
+ rawPos
3853
+ );
3854
+ } else {
3855
+ mapImageCustomBit(
3856
+ images[imageIndex],
3857
+ pxData,
3858
+ getPxPos,
3859
+ bpp,
3860
+ bits,
3861
+ maxBit
3862
+ );
3863
+ }
3864
+ }
3865
+ if (depth === 8) {
3866
+ if (rawPos !== data.length) {
3867
+ throw new Error("extra data found");
3868
+ }
3869
+ } else {
3870
+ bits.end();
3871
+ }
3872
+ return pxData;
3873
+ };
3874
+ }
3875
+ });
3876
+
3877
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/format-normaliser.js
3878
+ var require_format_normaliser = __commonJS({
3879
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/format-normaliser.js"(exports, module) {
3880
+ "use strict";
3881
+ function dePalette(indata, outdata, width, height, palette) {
3882
+ let pxPos = 0;
3883
+ for (let y = 0; y < height; y++) {
3884
+ for (let x = 0; x < width; x++) {
3885
+ let color = palette[indata[pxPos]];
3886
+ if (!color) {
3887
+ throw new Error("index " + indata[pxPos] + " not in palette");
3888
+ }
3889
+ for (let i = 0; i < 4; i++) {
3890
+ outdata[pxPos + i] = color[i];
3891
+ }
3892
+ pxPos += 4;
3893
+ }
3894
+ }
3895
+ }
3896
+ function replaceTransparentColor(indata, outdata, width, height, transColor) {
3897
+ let pxPos = 0;
3898
+ for (let y = 0; y < height; y++) {
3899
+ for (let x = 0; x < width; x++) {
3900
+ let makeTrans = false;
3901
+ if (transColor.length === 1) {
3902
+ if (transColor[0] === indata[pxPos]) {
3903
+ makeTrans = true;
3904
+ }
3905
+ } else if (transColor[0] === indata[pxPos] && transColor[1] === indata[pxPos + 1] && transColor[2] === indata[pxPos + 2]) {
3906
+ makeTrans = true;
3907
+ }
3908
+ if (makeTrans) {
3909
+ for (let i = 0; i < 4; i++) {
3910
+ outdata[pxPos + i] = 0;
3911
+ }
3912
+ }
3913
+ pxPos += 4;
3914
+ }
3915
+ }
3916
+ }
3917
+ function scaleDepth(indata, outdata, width, height, depth) {
3918
+ let maxOutSample = 255;
3919
+ let maxInSample = Math.pow(2, depth) - 1;
3920
+ let pxPos = 0;
3921
+ for (let y = 0; y < height; y++) {
3922
+ for (let x = 0; x < width; x++) {
3923
+ for (let i = 0; i < 4; i++) {
3924
+ outdata[pxPos + i] = Math.floor(
3925
+ indata[pxPos + i] * maxOutSample / maxInSample + 0.5
3926
+ );
3927
+ }
3928
+ pxPos += 4;
3929
+ }
3930
+ }
3931
+ }
3932
+ module.exports = function(indata, imageData) {
3933
+ let depth = imageData.depth;
3934
+ let width = imageData.width;
3935
+ let height = imageData.height;
3936
+ let colorType = imageData.colorType;
3937
+ let transColor = imageData.transColor;
3938
+ let palette = imageData.palette;
3939
+ let outdata = indata;
3940
+ if (colorType === 3) {
3941
+ dePalette(indata, outdata, width, height, palette);
3942
+ } else {
3943
+ if (transColor) {
3944
+ replaceTransparentColor(indata, outdata, width, height, transColor);
3945
+ }
3946
+ if (depth !== 8) {
3947
+ if (depth === 16) {
3948
+ outdata = Buffer.alloc(width * height * 4);
3949
+ }
3950
+ scaleDepth(indata, outdata, width, height, depth);
3951
+ }
3952
+ }
3953
+ return outdata;
3954
+ };
3955
+ }
3956
+ });
3957
+
3958
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser-async.js
3959
+ var require_parser_async = __commonJS({
3960
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser-async.js"(exports, module) {
3961
+ "use strict";
3962
+ var util = __require("util");
3963
+ var zlib = __require("zlib");
3964
+ var ChunkStream = require_chunkstream();
3965
+ var FilterAsync = require_filter_parse_async();
3966
+ var Parser = require_parser();
3967
+ var bitmapper = require_bitmapper();
3968
+ var formatNormaliser = require_format_normaliser();
3969
+ var ParserAsync = module.exports = function(options) {
3970
+ ChunkStream.call(this);
3971
+ this._parser = new Parser(options, {
3972
+ read: this.read.bind(this),
3973
+ error: this._handleError.bind(this),
3974
+ metadata: this._handleMetaData.bind(this),
3975
+ gamma: this.emit.bind(this, "gamma"),
3976
+ palette: this._handlePalette.bind(this),
3977
+ transColor: this._handleTransColor.bind(this),
3978
+ finished: this._finished.bind(this),
3979
+ inflateData: this._inflateData.bind(this),
3980
+ simpleTransparency: this._simpleTransparency.bind(this),
3981
+ headersFinished: this._headersFinished.bind(this)
3982
+ });
3983
+ this._options = options;
3984
+ this.writable = true;
3985
+ this._parser.start();
3986
+ };
3987
+ util.inherits(ParserAsync, ChunkStream);
3988
+ ParserAsync.prototype._handleError = function(err) {
3989
+ this.emit("error", err);
3990
+ this.writable = false;
3991
+ this.destroy();
3992
+ if (this._inflate && this._inflate.destroy) {
3993
+ this._inflate.destroy();
3994
+ }
3995
+ if (this._filter) {
3996
+ this._filter.destroy();
3997
+ this._filter.on("error", function() {
3998
+ });
3999
+ }
4000
+ this.errord = true;
4001
+ };
4002
+ ParserAsync.prototype._inflateData = function(data) {
4003
+ if (!this._inflate) {
4004
+ if (this._bitmapInfo.interlace) {
4005
+ this._inflate = zlib.createInflate();
4006
+ this._inflate.on("error", this.emit.bind(this, "error"));
4007
+ this._filter.on("complete", this._complete.bind(this));
4008
+ this._inflate.pipe(this._filter);
4009
+ } else {
4010
+ let rowSize = (this._bitmapInfo.width * this._bitmapInfo.bpp * this._bitmapInfo.depth + 7 >> 3) + 1;
4011
+ let imageSize = rowSize * this._bitmapInfo.height;
4012
+ let chunkSize = Math.max(imageSize, zlib.Z_MIN_CHUNK);
4013
+ this._inflate = zlib.createInflate({ chunkSize });
4014
+ let leftToInflate = imageSize;
4015
+ let emitError = this.emit.bind(this, "error");
4016
+ this._inflate.on("error", function(err) {
4017
+ if (!leftToInflate) {
4018
+ return;
4019
+ }
4020
+ emitError(err);
4021
+ });
4022
+ this._filter.on("complete", this._complete.bind(this));
4023
+ let filterWrite = this._filter.write.bind(this._filter);
4024
+ this._inflate.on("data", function(chunk) {
4025
+ if (!leftToInflate) {
4026
+ return;
4027
+ }
4028
+ if (chunk.length > leftToInflate) {
4029
+ chunk = chunk.slice(0, leftToInflate);
4030
+ }
4031
+ leftToInflate -= chunk.length;
4032
+ filterWrite(chunk);
4033
+ });
4034
+ this._inflate.on("end", this._filter.end.bind(this._filter));
4035
+ }
4036
+ }
4037
+ this._inflate.write(data);
4038
+ };
4039
+ ParserAsync.prototype._handleMetaData = function(metaData) {
4040
+ this._metaData = metaData;
4041
+ this._bitmapInfo = Object.create(metaData);
4042
+ this._filter = new FilterAsync(this._bitmapInfo);
4043
+ };
4044
+ ParserAsync.prototype._handleTransColor = function(transColor) {
4045
+ this._bitmapInfo.transColor = transColor;
4046
+ };
4047
+ ParserAsync.prototype._handlePalette = function(palette) {
4048
+ this._bitmapInfo.palette = palette;
4049
+ };
4050
+ ParserAsync.prototype._simpleTransparency = function() {
4051
+ this._metaData.alpha = true;
4052
+ };
4053
+ ParserAsync.prototype._headersFinished = function() {
4054
+ this.emit("metadata", this._metaData);
4055
+ };
4056
+ ParserAsync.prototype._finished = function() {
4057
+ if (this.errord) {
4058
+ return;
4059
+ }
4060
+ if (!this._inflate) {
4061
+ this.emit("error", "No Inflate block");
4062
+ } else {
4063
+ this._inflate.end();
4064
+ }
4065
+ };
4066
+ ParserAsync.prototype._complete = function(filteredData) {
4067
+ if (this.errord) {
4068
+ return;
4069
+ }
4070
+ let normalisedBitmapData;
4071
+ try {
4072
+ let bitmapData = bitmapper.dataToBitMap(filteredData, this._bitmapInfo);
4073
+ normalisedBitmapData = formatNormaliser(bitmapData, this._bitmapInfo);
4074
+ bitmapData = null;
4075
+ } catch (ex) {
4076
+ this._handleError(ex);
4077
+ return;
4078
+ }
4079
+ this.emit("parsed", normalisedBitmapData);
4080
+ };
4081
+ }
4082
+ });
4083
+
4084
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitpacker.js
4085
+ var require_bitpacker = __commonJS({
4086
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitpacker.js"(exports, module) {
4087
+ "use strict";
4088
+ var constants = require_constants();
4089
+ module.exports = function(dataIn, width, height, options) {
4090
+ let outHasAlpha = [constants.COLORTYPE_COLOR_ALPHA, constants.COLORTYPE_ALPHA].indexOf(
4091
+ options.colorType
4092
+ ) !== -1;
4093
+ if (options.colorType === options.inputColorType) {
4094
+ let bigEndian = (function() {
4095
+ let buffer = new ArrayBuffer(2);
4096
+ new DataView(buffer).setInt16(
4097
+ 0,
4098
+ 256,
4099
+ true
4100
+ /* littleEndian */
4101
+ );
4102
+ return new Int16Array(buffer)[0] !== 256;
4103
+ })();
4104
+ if (options.bitDepth === 8 || options.bitDepth === 16 && bigEndian) {
4105
+ return dataIn;
4106
+ }
4107
+ }
4108
+ let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
4109
+ let maxValue = 255;
4110
+ let inBpp = constants.COLORTYPE_TO_BPP_MAP[options.inputColorType];
4111
+ if (inBpp === 4 && !options.inputHasAlpha) {
4112
+ inBpp = 3;
4113
+ }
4114
+ let outBpp = constants.COLORTYPE_TO_BPP_MAP[options.colorType];
4115
+ if (options.bitDepth === 16) {
4116
+ maxValue = 65535;
4117
+ outBpp *= 2;
4118
+ }
4119
+ let outData = Buffer.alloc(width * height * outBpp);
4120
+ let inIndex = 0;
4121
+ let outIndex = 0;
4122
+ let bgColor = options.bgColor || {};
4123
+ if (bgColor.red === void 0) {
4124
+ bgColor.red = maxValue;
4125
+ }
4126
+ if (bgColor.green === void 0) {
4127
+ bgColor.green = maxValue;
4128
+ }
4129
+ if (bgColor.blue === void 0) {
4130
+ bgColor.blue = maxValue;
4131
+ }
4132
+ function getRGBA() {
4133
+ let red;
4134
+ let green;
4135
+ let blue;
4136
+ let alpha = maxValue;
4137
+ switch (options.inputColorType) {
4138
+ case constants.COLORTYPE_COLOR_ALPHA:
4139
+ alpha = data[inIndex + 3];
4140
+ red = data[inIndex];
4141
+ green = data[inIndex + 1];
4142
+ blue = data[inIndex + 2];
4143
+ break;
4144
+ case constants.COLORTYPE_COLOR:
4145
+ red = data[inIndex];
4146
+ green = data[inIndex + 1];
4147
+ blue = data[inIndex + 2];
4148
+ break;
4149
+ case constants.COLORTYPE_ALPHA:
4150
+ alpha = data[inIndex + 1];
4151
+ red = data[inIndex];
4152
+ green = red;
4153
+ blue = red;
4154
+ break;
4155
+ case constants.COLORTYPE_GRAYSCALE:
4156
+ red = data[inIndex];
4157
+ green = red;
4158
+ blue = red;
4159
+ break;
4160
+ default:
4161
+ throw new Error(
4162
+ "input color type:" + options.inputColorType + " is not supported at present"
4163
+ );
4164
+ }
4165
+ if (options.inputHasAlpha) {
4166
+ if (!outHasAlpha) {
4167
+ alpha /= maxValue;
4168
+ red = Math.min(
4169
+ Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0),
4170
+ maxValue
4171
+ );
4172
+ green = Math.min(
4173
+ Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0),
4174
+ maxValue
4175
+ );
4176
+ blue = Math.min(
4177
+ Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0),
4178
+ maxValue
4179
+ );
4180
+ }
4181
+ }
4182
+ return { red, green, blue, alpha };
4183
+ }
4184
+ for (let y = 0; y < height; y++) {
4185
+ for (let x = 0; x < width; x++) {
4186
+ let rgba = getRGBA(data, inIndex);
4187
+ switch (options.colorType) {
4188
+ case constants.COLORTYPE_COLOR_ALPHA:
4189
+ case constants.COLORTYPE_COLOR:
4190
+ if (options.bitDepth === 8) {
4191
+ outData[outIndex] = rgba.red;
4192
+ outData[outIndex + 1] = rgba.green;
4193
+ outData[outIndex + 2] = rgba.blue;
4194
+ if (outHasAlpha) {
4195
+ outData[outIndex + 3] = rgba.alpha;
4196
+ }
4197
+ } else {
4198
+ outData.writeUInt16BE(rgba.red, outIndex);
4199
+ outData.writeUInt16BE(rgba.green, outIndex + 2);
4200
+ outData.writeUInt16BE(rgba.blue, outIndex + 4);
4201
+ if (outHasAlpha) {
4202
+ outData.writeUInt16BE(rgba.alpha, outIndex + 6);
4203
+ }
4204
+ }
4205
+ break;
4206
+ case constants.COLORTYPE_ALPHA:
4207
+ case constants.COLORTYPE_GRAYSCALE: {
4208
+ let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
4209
+ if (options.bitDepth === 8) {
4210
+ outData[outIndex] = grayscale;
4211
+ if (outHasAlpha) {
4212
+ outData[outIndex + 1] = rgba.alpha;
4213
+ }
4214
+ } else {
4215
+ outData.writeUInt16BE(grayscale, outIndex);
4216
+ if (outHasAlpha) {
4217
+ outData.writeUInt16BE(rgba.alpha, outIndex + 2);
4218
+ }
4219
+ }
4220
+ break;
4221
+ }
4222
+ default:
4223
+ throw new Error("unrecognised color Type " + options.colorType);
4224
+ }
4225
+ inIndex += inBpp;
4226
+ outIndex += outBpp;
4227
+ }
4228
+ }
4229
+ return outData;
4230
+ };
4231
+ }
4232
+ });
4233
+
4234
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-pack.js
4235
+ var require_filter_pack = __commonJS({
4236
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-pack.js"(exports, module) {
4237
+ "use strict";
4238
+ var paethPredictor = require_paeth_predictor();
4239
+ function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
4240
+ for (let x = 0; x < byteWidth; x++) {
4241
+ rawData[rawPos + x] = pxData[pxPos + x];
4242
+ }
4243
+ }
4244
+ function filterSumNone(pxData, pxPos, byteWidth) {
4245
+ let sum = 0;
4246
+ let length = pxPos + byteWidth;
4247
+ for (let i = pxPos; i < length; i++) {
4248
+ sum += Math.abs(pxData[i]);
4249
+ }
4250
+ return sum;
4251
+ }
4252
+ function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
4253
+ for (let x = 0; x < byteWidth; x++) {
4254
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
4255
+ let val = pxData[pxPos + x] - left;
4256
+ rawData[rawPos + x] = val;
4257
+ }
4258
+ }
4259
+ function filterSumSub(pxData, pxPos, byteWidth, bpp) {
4260
+ let sum = 0;
4261
+ for (let x = 0; x < byteWidth; x++) {
4262
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
4263
+ let val = pxData[pxPos + x] - left;
4264
+ sum += Math.abs(val);
4265
+ }
4266
+ return sum;
4267
+ }
4268
+ function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
4269
+ for (let x = 0; x < byteWidth; x++) {
4270
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
4271
+ let val = pxData[pxPos + x] - up;
4272
+ rawData[rawPos + x] = val;
4273
+ }
4274
+ }
4275
+ function filterSumUp(pxData, pxPos, byteWidth) {
4276
+ let sum = 0;
4277
+ let length = pxPos + byteWidth;
4278
+ for (let x = pxPos; x < length; x++) {
4279
+ let up = pxPos > 0 ? pxData[x - byteWidth] : 0;
4280
+ let val = pxData[x] - up;
4281
+ sum += Math.abs(val);
4282
+ }
4283
+ return sum;
4284
+ }
4285
+ function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
4286
+ for (let x = 0; x < byteWidth; x++) {
4287
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
4288
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
4289
+ let val = pxData[pxPos + x] - (left + up >> 1);
4290
+ rawData[rawPos + x] = val;
4291
+ }
4292
+ }
4293
+ function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
4294
+ let sum = 0;
4295
+ for (let x = 0; x < byteWidth; x++) {
4296
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
4297
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
4298
+ let val = pxData[pxPos + x] - (left + up >> 1);
4299
+ sum += Math.abs(val);
4300
+ }
4301
+ return sum;
4302
+ }
4303
+ function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
4304
+ for (let x = 0; x < byteWidth; x++) {
4305
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
4306
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
4307
+ let upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
4308
+ let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
4309
+ rawData[rawPos + x] = val;
4310
+ }
4311
+ }
4312
+ function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
4313
+ let sum = 0;
4314
+ for (let x = 0; x < byteWidth; x++) {
4315
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
4316
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
4317
+ let upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
4318
+ let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
4319
+ sum += Math.abs(val);
4320
+ }
4321
+ return sum;
4322
+ }
4323
+ var filters = {
4324
+ 0: filterNone,
4325
+ 1: filterSub,
4326
+ 2: filterUp,
4327
+ 3: filterAvg,
4328
+ 4: filterPaeth
4329
+ };
4330
+ var filterSums = {
4331
+ 0: filterSumNone,
4332
+ 1: filterSumSub,
4333
+ 2: filterSumUp,
4334
+ 3: filterSumAvg,
4335
+ 4: filterSumPaeth
4336
+ };
4337
+ module.exports = function(pxData, width, height, options, bpp) {
4338
+ let filterTypes;
4339
+ if (!("filterType" in options) || options.filterType === -1) {
4340
+ filterTypes = [0, 1, 2, 3, 4];
4341
+ } else if (typeof options.filterType === "number") {
4342
+ filterTypes = [options.filterType];
4343
+ } else {
4344
+ throw new Error("unrecognised filter types");
4345
+ }
4346
+ if (options.bitDepth === 16) {
4347
+ bpp *= 2;
4348
+ }
4349
+ let byteWidth = width * bpp;
4350
+ let rawPos = 0;
4351
+ let pxPos = 0;
4352
+ let rawData = Buffer.alloc((byteWidth + 1) * height);
4353
+ let sel = filterTypes[0];
4354
+ for (let y = 0; y < height; y++) {
4355
+ if (filterTypes.length > 1) {
4356
+ let min = Infinity;
4357
+ for (let i = 0; i < filterTypes.length; i++) {
4358
+ let sum = filterSums[filterTypes[i]](pxData, pxPos, byteWidth, bpp);
4359
+ if (sum < min) {
4360
+ sel = filterTypes[i];
4361
+ min = sum;
4362
+ }
4363
+ }
4364
+ }
4365
+ rawData[rawPos] = sel;
4366
+ rawPos++;
4367
+ filters[sel](pxData, pxPos, byteWidth, rawData, rawPos, bpp);
4368
+ rawPos += byteWidth;
4369
+ pxPos += byteWidth;
4370
+ }
4371
+ return rawData;
4372
+ };
4373
+ }
4374
+ });
4375
+
4376
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer.js
4377
+ var require_packer = __commonJS({
4378
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer.js"(exports, module) {
4379
+ "use strict";
4380
+ var constants = require_constants();
4381
+ var CrcStream = require_crc();
4382
+ var bitPacker = require_bitpacker();
4383
+ var filter = require_filter_pack();
4384
+ var zlib = __require("zlib");
4385
+ var Packer = module.exports = function(options) {
4386
+ this._options = options;
4387
+ options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
4388
+ options.deflateLevel = options.deflateLevel != null ? options.deflateLevel : 9;
4389
+ options.deflateStrategy = options.deflateStrategy != null ? options.deflateStrategy : 3;
4390
+ options.inputHasAlpha = options.inputHasAlpha != null ? options.inputHasAlpha : true;
4391
+ options.deflateFactory = options.deflateFactory || zlib.createDeflate;
4392
+ options.bitDepth = options.bitDepth || 8;
4393
+ options.colorType = typeof options.colorType === "number" ? options.colorType : constants.COLORTYPE_COLOR_ALPHA;
4394
+ options.inputColorType = typeof options.inputColorType === "number" ? options.inputColorType : constants.COLORTYPE_COLOR_ALPHA;
4395
+ if ([
4396
+ constants.COLORTYPE_GRAYSCALE,
4397
+ constants.COLORTYPE_COLOR,
4398
+ constants.COLORTYPE_COLOR_ALPHA,
4399
+ constants.COLORTYPE_ALPHA
4400
+ ].indexOf(options.colorType) === -1) {
4401
+ throw new Error(
4402
+ "option color type:" + options.colorType + " is not supported at present"
4403
+ );
4404
+ }
4405
+ if ([
4406
+ constants.COLORTYPE_GRAYSCALE,
4407
+ constants.COLORTYPE_COLOR,
4408
+ constants.COLORTYPE_COLOR_ALPHA,
4409
+ constants.COLORTYPE_ALPHA
4410
+ ].indexOf(options.inputColorType) === -1) {
4411
+ throw new Error(
4412
+ "option input color type:" + options.inputColorType + " is not supported at present"
4413
+ );
4414
+ }
4415
+ if (options.bitDepth !== 8 && options.bitDepth !== 16) {
4416
+ throw new Error(
4417
+ "option bit depth:" + options.bitDepth + " is not supported at present"
4418
+ );
4419
+ }
4420
+ };
4421
+ Packer.prototype.getDeflateOptions = function() {
4422
+ return {
4423
+ chunkSize: this._options.deflateChunkSize,
4424
+ level: this._options.deflateLevel,
4425
+ strategy: this._options.deflateStrategy
4426
+ };
4427
+ };
4428
+ Packer.prototype.createDeflate = function() {
4429
+ return this._options.deflateFactory(this.getDeflateOptions());
4430
+ };
4431
+ Packer.prototype.filterData = function(data, width, height) {
4432
+ let packedData = bitPacker(data, width, height, this._options);
4433
+ let bpp = constants.COLORTYPE_TO_BPP_MAP[this._options.colorType];
4434
+ let filteredData = filter(packedData, width, height, this._options, bpp);
4435
+ return filteredData;
4436
+ };
4437
+ Packer.prototype._packChunk = function(type, data) {
4438
+ let len = data ? data.length : 0;
4439
+ let buf = Buffer.alloc(len + 12);
4440
+ buf.writeUInt32BE(len, 0);
4441
+ buf.writeUInt32BE(type, 4);
4442
+ if (data) {
4443
+ data.copy(buf, 8);
4444
+ }
4445
+ buf.writeInt32BE(
4446
+ CrcStream.crc32(buf.slice(4, buf.length - 4)),
4447
+ buf.length - 4
4448
+ );
4449
+ return buf;
4450
+ };
4451
+ Packer.prototype.packGAMA = function(gamma) {
4452
+ let buf = Buffer.alloc(4);
4453
+ buf.writeUInt32BE(Math.floor(gamma * constants.GAMMA_DIVISION), 0);
4454
+ return this._packChunk(constants.TYPE_gAMA, buf);
4455
+ };
4456
+ Packer.prototype.packIHDR = function(width, height) {
4457
+ let buf = Buffer.alloc(13);
4458
+ buf.writeUInt32BE(width, 0);
4459
+ buf.writeUInt32BE(height, 4);
4460
+ buf[8] = this._options.bitDepth;
4461
+ buf[9] = this._options.colorType;
4462
+ buf[10] = 0;
4463
+ buf[11] = 0;
4464
+ buf[12] = 0;
4465
+ return this._packChunk(constants.TYPE_IHDR, buf);
4466
+ };
4467
+ Packer.prototype.packIDAT = function(data) {
4468
+ return this._packChunk(constants.TYPE_IDAT, data);
4469
+ };
4470
+ Packer.prototype.packIEND = function() {
4471
+ return this._packChunk(constants.TYPE_IEND, null);
4472
+ };
4473
+ }
4474
+ });
4475
+
4476
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer-async.js
4477
+ var require_packer_async = __commonJS({
4478
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer-async.js"(exports, module) {
4479
+ "use strict";
4480
+ var util = __require("util");
4481
+ var Stream = __require("stream");
4482
+ var constants = require_constants();
4483
+ var Packer = require_packer();
4484
+ var PackerAsync = module.exports = function(opt) {
4485
+ Stream.call(this);
4486
+ let options = opt || {};
4487
+ this._packer = new Packer(options);
4488
+ this._deflate = this._packer.createDeflate();
4489
+ this.readable = true;
4490
+ };
4491
+ util.inherits(PackerAsync, Stream);
4492
+ PackerAsync.prototype.pack = function(data, width, height, gamma) {
4493
+ this.emit("data", Buffer.from(constants.PNG_SIGNATURE));
4494
+ this.emit("data", this._packer.packIHDR(width, height));
4495
+ if (gamma) {
4496
+ this.emit("data", this._packer.packGAMA(gamma));
4497
+ }
4498
+ let filteredData = this._packer.filterData(data, width, height);
4499
+ this._deflate.on("error", this.emit.bind(this, "error"));
4500
+ this._deflate.on(
4501
+ "data",
4502
+ function(compressedData) {
4503
+ this.emit("data", this._packer.packIDAT(compressedData));
4504
+ }.bind(this)
4505
+ );
4506
+ this._deflate.on(
4507
+ "end",
4508
+ function() {
4509
+ this.emit("data", this._packer.packIEND());
4510
+ this.emit("end");
4511
+ }.bind(this)
4512
+ );
4513
+ this._deflate.end(filteredData);
4514
+ };
4515
+ }
4516
+ });
4517
+
4518
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-inflate.js
4519
+ var require_sync_inflate = __commonJS({
4520
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-inflate.js"(exports, module) {
4521
+ "use strict";
4522
+ var assert = __require("assert").ok;
4523
+ var zlib = __require("zlib");
4524
+ var util = __require("util");
4525
+ var kMaxLength = __require("buffer").kMaxLength;
4526
+ function Inflate(opts) {
4527
+ if (!(this instanceof Inflate)) {
4528
+ return new Inflate(opts);
4529
+ }
4530
+ if (opts && opts.chunkSize < zlib.Z_MIN_CHUNK) {
4531
+ opts.chunkSize = zlib.Z_MIN_CHUNK;
4532
+ }
4533
+ zlib.Inflate.call(this, opts);
4534
+ this._offset = this._offset === void 0 ? this._outOffset : this._offset;
4535
+ this._buffer = this._buffer || this._outBuffer;
4536
+ if (opts && opts.maxLength != null) {
4537
+ this._maxLength = opts.maxLength;
4538
+ }
4539
+ }
4540
+ function createInflate(opts) {
4541
+ return new Inflate(opts);
4542
+ }
4543
+ function _close(engine, callback) {
4544
+ if (callback) {
4545
+ process.nextTick(callback);
4546
+ }
4547
+ if (!engine._handle) {
4548
+ return;
4549
+ }
4550
+ engine._handle.close();
4551
+ engine._handle = null;
4552
+ }
4553
+ Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
4554
+ if (typeof asyncCb === "function") {
4555
+ return zlib.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
4556
+ }
4557
+ let self = this;
4558
+ let availInBefore = chunk && chunk.length;
4559
+ let availOutBefore = this._chunkSize - this._offset;
4560
+ let leftToInflate = this._maxLength;
4561
+ let inOff = 0;
4562
+ let buffers = [];
4563
+ let nread = 0;
4564
+ let error;
4565
+ this.on("error", function(err) {
4566
+ error = err;
4567
+ });
4568
+ function handleChunk(availInAfter, availOutAfter) {
4569
+ if (self._hadError) {
4570
+ return;
4571
+ }
4572
+ let have = availOutBefore - availOutAfter;
4573
+ assert(have >= 0, "have should not go down");
4574
+ if (have > 0) {
4575
+ let out = self._buffer.slice(self._offset, self._offset + have);
4576
+ self._offset += have;
4577
+ if (out.length > leftToInflate) {
4578
+ out = out.slice(0, leftToInflate);
4579
+ }
4580
+ buffers.push(out);
4581
+ nread += out.length;
4582
+ leftToInflate -= out.length;
4583
+ if (leftToInflate === 0) {
4584
+ return false;
4585
+ }
4586
+ }
4587
+ if (availOutAfter === 0 || self._offset >= self._chunkSize) {
4588
+ availOutBefore = self._chunkSize;
4589
+ self._offset = 0;
4590
+ self._buffer = Buffer.allocUnsafe(self._chunkSize);
4591
+ }
4592
+ if (availOutAfter === 0) {
4593
+ inOff += availInBefore - availInAfter;
4594
+ availInBefore = availInAfter;
4595
+ return true;
4596
+ }
4597
+ return false;
4598
+ }
4599
+ assert(this._handle, "zlib binding closed");
4600
+ let res;
4601
+ do {
4602
+ res = this._handle.writeSync(
4603
+ flushFlag,
4604
+ chunk,
4605
+ // in
4606
+ inOff,
4607
+ // in_off
4608
+ availInBefore,
4609
+ // in_len
4610
+ this._buffer,
4611
+ // out
4612
+ this._offset,
4613
+ //out_off
4614
+ availOutBefore
4615
+ );
4616
+ res = res || this._writeState;
4617
+ } while (!this._hadError && handleChunk(res[0], res[1]));
4618
+ if (this._hadError) {
4619
+ throw error;
4620
+ }
4621
+ if (nread >= kMaxLength) {
4622
+ _close(this);
4623
+ throw new RangeError(
4624
+ "Cannot create final Buffer. It would be larger than 0x" + kMaxLength.toString(16) + " bytes"
4625
+ );
4626
+ }
4627
+ let buf = Buffer.concat(buffers, nread);
4628
+ _close(this);
4629
+ return buf;
4630
+ };
4631
+ util.inherits(Inflate, zlib.Inflate);
4632
+ function zlibBufferSync(engine, buffer) {
4633
+ if (typeof buffer === "string") {
4634
+ buffer = Buffer.from(buffer);
4635
+ }
4636
+ if (!(buffer instanceof Buffer)) {
4637
+ throw new TypeError("Not a string or buffer");
4638
+ }
4639
+ let flushFlag = engine._finishFlushFlag;
4640
+ if (flushFlag == null) {
4641
+ flushFlag = zlib.Z_FINISH;
4642
+ }
4643
+ return engine._processChunk(buffer, flushFlag);
4644
+ }
4645
+ function inflateSync(buffer, opts) {
4646
+ return zlibBufferSync(new Inflate(opts), buffer);
4647
+ }
4648
+ module.exports = exports = inflateSync;
4649
+ exports.Inflate = Inflate;
4650
+ exports.createInflate = createInflate;
4651
+ exports.inflateSync = inflateSync;
4652
+ }
4653
+ });
4654
+
4655
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-reader.js
4656
+ var require_sync_reader = __commonJS({
4657
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-reader.js"(exports, module) {
4658
+ "use strict";
4659
+ var SyncReader = module.exports = function(buffer) {
4660
+ this._buffer = buffer;
4661
+ this._reads = [];
4662
+ };
4663
+ SyncReader.prototype.read = function(length, callback) {
4664
+ this._reads.push({
4665
+ length: Math.abs(length),
4666
+ // if length < 0 then at most this length
4667
+ allowLess: length < 0,
4668
+ func: callback
4669
+ });
4670
+ };
4671
+ SyncReader.prototype.process = function() {
4672
+ while (this._reads.length > 0 && this._buffer.length) {
4673
+ let read = this._reads[0];
4674
+ if (this._buffer.length && (this._buffer.length >= read.length || read.allowLess)) {
4675
+ this._reads.shift();
4676
+ let buf = this._buffer;
4677
+ this._buffer = buf.slice(read.length);
4678
+ read.func.call(this, buf.slice(0, read.length));
4679
+ } else {
4680
+ break;
4681
+ }
4682
+ }
4683
+ if (this._reads.length > 0) {
4684
+ return new Error("There are some read requests waitng on finished stream");
4685
+ }
4686
+ if (this._buffer.length > 0) {
4687
+ return new Error("unrecognised content at end of stream");
4688
+ }
4689
+ };
4690
+ }
4691
+ });
4692
+
4693
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-sync.js
4694
+ var require_filter_parse_sync = __commonJS({
4695
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-sync.js"(exports) {
4696
+ "use strict";
4697
+ var SyncReader = require_sync_reader();
4698
+ var Filter = require_filter_parse();
4699
+ exports.process = function(inBuffer, bitmapInfo) {
4700
+ let outBuffers = [];
4701
+ let reader = new SyncReader(inBuffer);
4702
+ let filter = new Filter(bitmapInfo, {
4703
+ read: reader.read.bind(reader),
4704
+ write: function(bufferPart) {
4705
+ outBuffers.push(bufferPart);
4706
+ },
4707
+ complete: function() {
4708
+ }
4709
+ });
4710
+ filter.start();
4711
+ reader.process();
4712
+ return Buffer.concat(outBuffers);
4713
+ };
4714
+ }
4715
+ });
4716
+
4717
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser-sync.js
4718
+ var require_parser_sync = __commonJS({
4719
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser-sync.js"(exports, module) {
4720
+ "use strict";
4721
+ var hasSyncZlib = true;
4722
+ var zlib = __require("zlib");
4723
+ var inflateSync = require_sync_inflate();
4724
+ if (!zlib.deflateSync) {
4725
+ hasSyncZlib = false;
4726
+ }
4727
+ var SyncReader = require_sync_reader();
4728
+ var FilterSync = require_filter_parse_sync();
4729
+ var Parser = require_parser();
4730
+ var bitmapper = require_bitmapper();
4731
+ var formatNormaliser = require_format_normaliser();
4732
+ module.exports = function(buffer, options) {
4733
+ if (!hasSyncZlib) {
4734
+ throw new Error(
4735
+ "To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
4736
+ );
4737
+ }
4738
+ let err;
4739
+ function handleError(_err_) {
4740
+ err = _err_;
4741
+ }
4742
+ let metaData;
4743
+ function handleMetaData(_metaData_) {
4744
+ metaData = _metaData_;
4745
+ }
4746
+ function handleTransColor(transColor) {
4747
+ metaData.transColor = transColor;
4748
+ }
4749
+ function handlePalette(palette) {
4750
+ metaData.palette = palette;
4751
+ }
4752
+ function handleSimpleTransparency() {
4753
+ metaData.alpha = true;
4754
+ }
4755
+ let gamma;
4756
+ function handleGamma(_gamma_) {
4757
+ gamma = _gamma_;
4758
+ }
4759
+ let inflateDataList = [];
4760
+ function handleInflateData(inflatedData2) {
4761
+ inflateDataList.push(inflatedData2);
4762
+ }
4763
+ let reader = new SyncReader(buffer);
4764
+ let parser = new Parser(options, {
4765
+ read: reader.read.bind(reader),
4766
+ error: handleError,
4767
+ metadata: handleMetaData,
4768
+ gamma: handleGamma,
4769
+ palette: handlePalette,
4770
+ transColor: handleTransColor,
4771
+ inflateData: handleInflateData,
4772
+ simpleTransparency: handleSimpleTransparency
4773
+ });
4774
+ parser.start();
4775
+ reader.process();
4776
+ if (err) {
4777
+ throw err;
4778
+ }
4779
+ let inflateData = Buffer.concat(inflateDataList);
4780
+ inflateDataList.length = 0;
4781
+ let inflatedData;
4782
+ if (metaData.interlace) {
4783
+ inflatedData = zlib.inflateSync(inflateData);
4784
+ } else {
4785
+ let rowSize = (metaData.width * metaData.bpp * metaData.depth + 7 >> 3) + 1;
4786
+ let imageSize = rowSize * metaData.height;
4787
+ inflatedData = inflateSync(inflateData, {
4788
+ chunkSize: imageSize,
4789
+ maxLength: imageSize
4790
+ });
4791
+ }
4792
+ inflateData = null;
4793
+ if (!inflatedData || !inflatedData.length) {
4794
+ throw new Error("bad png - invalid inflate data response");
4795
+ }
4796
+ let unfilteredData = FilterSync.process(inflatedData, metaData);
4797
+ inflateData = null;
4798
+ let bitmapData = bitmapper.dataToBitMap(unfilteredData, metaData);
4799
+ unfilteredData = null;
4800
+ let normalisedBitmapData = formatNormaliser(bitmapData, metaData);
4801
+ metaData.data = normalisedBitmapData;
4802
+ metaData.gamma = gamma || 0;
4803
+ return metaData;
4804
+ };
4805
+ }
4806
+ });
4807
+
4808
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer-sync.js
4809
+ var require_packer_sync = __commonJS({
4810
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer-sync.js"(exports, module) {
4811
+ "use strict";
4812
+ var hasSyncZlib = true;
4813
+ var zlib = __require("zlib");
4814
+ if (!zlib.deflateSync) {
4815
+ hasSyncZlib = false;
4816
+ }
4817
+ var constants = require_constants();
4818
+ var Packer = require_packer();
4819
+ module.exports = function(metaData, opt) {
4820
+ if (!hasSyncZlib) {
4821
+ throw new Error(
4822
+ "To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
4823
+ );
4824
+ }
4825
+ let options = opt || {};
4826
+ let packer = new Packer(options);
4827
+ let chunks = [];
4828
+ chunks.push(Buffer.from(constants.PNG_SIGNATURE));
4829
+ chunks.push(packer.packIHDR(metaData.width, metaData.height));
4830
+ if (metaData.gamma) {
4831
+ chunks.push(packer.packGAMA(metaData.gamma));
4832
+ }
4833
+ let filteredData = packer.filterData(
4834
+ metaData.data,
4835
+ metaData.width,
4836
+ metaData.height
4837
+ );
4838
+ let compressedData = zlib.deflateSync(
4839
+ filteredData,
4840
+ packer.getDeflateOptions()
4841
+ );
4842
+ filteredData = null;
4843
+ if (!compressedData || !compressedData.length) {
4844
+ throw new Error("bad png - invalid compressed data response");
4845
+ }
4846
+ chunks.push(packer.packIDAT(compressedData));
4847
+ chunks.push(packer.packIEND());
4848
+ return Buffer.concat(chunks);
4849
+ };
4850
+ }
4851
+ });
4852
+
4853
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/png-sync.js
4854
+ var require_png_sync = __commonJS({
4855
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/png-sync.js"(exports) {
4856
+ "use strict";
4857
+ var parse2 = require_parser_sync();
4858
+ var pack = require_packer_sync();
4859
+ exports.read = function(buffer, options) {
4860
+ return parse2(buffer, options || {});
4861
+ };
4862
+ exports.write = function(png, options) {
4863
+ return pack(png, options);
4864
+ };
4865
+ }
4866
+ });
4867
+
4868
+ // node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/png.js
4869
+ var require_png = __commonJS({
4870
+ "node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/png.js"(exports) {
4871
+ "use strict";
4872
+ var util = __require("util");
4873
+ var Stream = __require("stream");
4874
+ var Parser = require_parser_async();
4875
+ var Packer = require_packer_async();
4876
+ var PNGSync = require_png_sync();
4877
+ var PNG = exports.PNG = function(options) {
4878
+ Stream.call(this);
4879
+ options = options || {};
4880
+ this.width = options.width | 0;
4881
+ this.height = options.height | 0;
4882
+ this.data = this.width > 0 && this.height > 0 ? Buffer.alloc(4 * this.width * this.height) : null;
4883
+ if (options.fill && this.data) {
4884
+ this.data.fill(0);
4885
+ }
4886
+ this.gamma = 0;
4887
+ this.readable = this.writable = true;
4888
+ this._parser = new Parser(options);
4889
+ this._parser.on("error", this.emit.bind(this, "error"));
4890
+ this._parser.on("close", this._handleClose.bind(this));
4891
+ this._parser.on("metadata", this._metadata.bind(this));
4892
+ this._parser.on("gamma", this._gamma.bind(this));
4893
+ this._parser.on(
4894
+ "parsed",
4895
+ function(data) {
4896
+ this.data = data;
4897
+ this.emit("parsed", data);
4898
+ }.bind(this)
4899
+ );
4900
+ this._packer = new Packer(options);
4901
+ this._packer.on("data", this.emit.bind(this, "data"));
4902
+ this._packer.on("end", this.emit.bind(this, "end"));
4903
+ this._parser.on("close", this._handleClose.bind(this));
4904
+ this._packer.on("error", this.emit.bind(this, "error"));
4905
+ };
4906
+ util.inherits(PNG, Stream);
4907
+ PNG.sync = PNGSync;
4908
+ PNG.prototype.pack = function() {
4909
+ if (!this.data || !this.data.length) {
4910
+ this.emit("error", "No data provided");
4911
+ return this;
4912
+ }
4913
+ process.nextTick(
4914
+ function() {
4915
+ this._packer.pack(this.data, this.width, this.height, this.gamma);
4916
+ }.bind(this)
4917
+ );
4918
+ return this;
4919
+ };
4920
+ PNG.prototype.parse = function(data, callback) {
4921
+ if (callback) {
4922
+ let onParsed, onError;
4923
+ onParsed = function(parsedData) {
4924
+ this.removeListener("error", onError);
4925
+ this.data = parsedData;
4926
+ callback(null, this);
4927
+ }.bind(this);
4928
+ onError = function(err) {
4929
+ this.removeListener("parsed", onParsed);
4930
+ callback(err, null);
4931
+ }.bind(this);
4932
+ this.once("parsed", onParsed);
4933
+ this.once("error", onError);
4934
+ }
4935
+ this.end(data);
4936
+ return this;
4937
+ };
4938
+ PNG.prototype.write = function(data) {
4939
+ this._parser.write(data);
4940
+ return true;
4941
+ };
4942
+ PNG.prototype.end = function(data) {
4943
+ this._parser.end(data);
4944
+ };
4945
+ PNG.prototype._metadata = function(metadata) {
4946
+ this.width = metadata.width;
4947
+ this.height = metadata.height;
4948
+ this.emit("metadata", metadata);
4949
+ };
4950
+ PNG.prototype._gamma = function(gamma) {
4951
+ this.gamma = gamma;
4952
+ };
4953
+ PNG.prototype._handleClose = function() {
4954
+ if (!this._parser.writable && !this._packer.readable) {
4955
+ this.emit("close");
989
4956
  }
990
- var data = new Array(totalCodeCount);
991
- var index = 0;
992
- for (var z = 0; z < maxDcCount; z++) {
993
- for (var s = 0; s < rsBlocks.length; s++) {
994
- if (z < dcdata[s].length) {
995
- data[index++] = dcdata[s][z];
4957
+ };
4958
+ PNG.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) {
4959
+ srcX |= 0;
4960
+ srcY |= 0;
4961
+ width |= 0;
4962
+ height |= 0;
4963
+ deltaX |= 0;
4964
+ deltaY |= 0;
4965
+ if (srcX > src.width || srcY > src.height || srcX + width > src.width || srcY + height > src.height) {
4966
+ throw new Error("bitblt reading outside image");
4967
+ }
4968
+ if (deltaX > dst.width || deltaY > dst.height || deltaX + width > dst.width || deltaY + height > dst.height) {
4969
+ throw new Error("bitblt writing outside image");
4970
+ }
4971
+ for (let y = 0; y < height; y++) {
4972
+ src.data.copy(
4973
+ dst.data,
4974
+ (deltaY + y) * dst.width + deltaX << 2,
4975
+ (srcY + y) * src.width + srcX << 2,
4976
+ (srcY + y) * src.width + srcX + width << 2
4977
+ );
4978
+ }
4979
+ };
4980
+ PNG.prototype.bitblt = function(dst, srcX, srcY, width, height, deltaX, deltaY) {
4981
+ PNG.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
4982
+ return this;
4983
+ };
4984
+ PNG.adjustGamma = function(src) {
4985
+ if (src.gamma) {
4986
+ for (let y = 0; y < src.height; y++) {
4987
+ for (let x = 0; x < src.width; x++) {
4988
+ let idx = src.width * y + x << 2;
4989
+ for (let i = 0; i < 3; i++) {
4990
+ let sample = src.data[idx + i] / 255;
4991
+ sample = Math.pow(sample, 1 / 2.2 / src.gamma);
4992
+ src.data[idx + i] = Math.round(sample * 255);
4993
+ }
996
4994
  }
997
4995
  }
4996
+ src.gamma = 0;
998
4997
  }
999
- for (var xx = 0; xx < maxEcCount; xx++) {
1000
- for (var t = 0; t < rsBlocks.length; t++) {
1001
- if (xx < ecdata[t].length) {
1002
- data[index++] = ecdata[t][xx];
4998
+ };
4999
+ PNG.prototype.adjustGamma = function() {
5000
+ PNG.adjustGamma(this);
5001
+ };
5002
+ }
5003
+ });
5004
+
5005
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utils.js
5006
+ var require_utils2 = __commonJS({
5007
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utils.js"(exports) {
5008
+ function hex2rgba(hex) {
5009
+ if (typeof hex === "number") {
5010
+ hex = hex.toString();
5011
+ }
5012
+ if (typeof hex !== "string") {
5013
+ throw new Error("Color should be defined as hex string");
5014
+ }
5015
+ let hexCode = hex.slice().replace("#", "").split("");
5016
+ if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {
5017
+ throw new Error("Invalid hex color: " + hex);
5018
+ }
5019
+ if (hexCode.length === 3 || hexCode.length === 4) {
5020
+ hexCode = Array.prototype.concat.apply([], hexCode.map(function(c) {
5021
+ return [c, c];
5022
+ }));
5023
+ }
5024
+ if (hexCode.length === 6) hexCode.push("F", "F");
5025
+ const hexValue = parseInt(hexCode.join(""), 16);
5026
+ return {
5027
+ r: hexValue >> 24 & 255,
5028
+ g: hexValue >> 16 & 255,
5029
+ b: hexValue >> 8 & 255,
5030
+ a: hexValue & 255,
5031
+ hex: "#" + hexCode.slice(0, 6).join("")
5032
+ };
5033
+ }
5034
+ exports.getOptions = function getOptions(options) {
5035
+ if (!options) options = {};
5036
+ if (!options.color) options.color = {};
5037
+ const margin = typeof options.margin === "undefined" || options.margin === null || options.margin < 0 ? 4 : options.margin;
5038
+ const width = options.width && options.width >= 21 ? options.width : void 0;
5039
+ const scale = options.scale || 4;
5040
+ return {
5041
+ width,
5042
+ scale: width ? 4 : scale,
5043
+ margin,
5044
+ color: {
5045
+ dark: hex2rgba(options.color.dark || "#000000ff"),
5046
+ light: hex2rgba(options.color.light || "#ffffffff")
5047
+ },
5048
+ type: options.type,
5049
+ rendererOpts: options.rendererOpts || {}
5050
+ };
5051
+ };
5052
+ exports.getScale = function getScale(qrSize, opts) {
5053
+ return opts.width && opts.width >= qrSize + opts.margin * 2 ? opts.width / (qrSize + opts.margin * 2) : opts.scale;
5054
+ };
5055
+ exports.getImageWidth = function getImageWidth(qrSize, opts) {
5056
+ const scale = exports.getScale(qrSize, opts);
5057
+ return Math.floor((qrSize + opts.margin * 2) * scale);
5058
+ };
5059
+ exports.qrToImageData = function qrToImageData(imgData, qr, opts) {
5060
+ const size = qr.modules.size;
5061
+ const data = qr.modules.data;
5062
+ const scale = exports.getScale(size, opts);
5063
+ const symbolSize = Math.floor((size + opts.margin * 2) * scale);
5064
+ const scaledMargin = opts.margin * scale;
5065
+ const palette = [opts.color.light, opts.color.dark];
5066
+ for (let i = 0; i < symbolSize; i++) {
5067
+ for (let j = 0; j < symbolSize; j++) {
5068
+ let posDst = (i * symbolSize + j) * 4;
5069
+ let pxColor = opts.color.light;
5070
+ if (i >= scaledMargin && j >= scaledMargin && i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
5071
+ const iSrc = Math.floor((i - scaledMargin) / scale);
5072
+ const jSrc = Math.floor((j - scaledMargin) / scale);
5073
+ pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0];
1003
5074
  }
5075
+ imgData[posDst++] = pxColor.r;
5076
+ imgData[posDst++] = pxColor.g;
5077
+ imgData[posDst++] = pxColor.b;
5078
+ imgData[posDst] = pxColor.a;
1004
5079
  }
1005
5080
  }
1006
- return data;
1007
5081
  };
1008
- module.exports = QRCode;
1009
5082
  }
1010
5083
  });
1011
5084
 
1012
- // node_modules/.pnpm/qrcode-terminal@0.12.0/node_modules/qrcode-terminal/lib/main.js
1013
- var require_main = __commonJS({
1014
- "node_modules/.pnpm/qrcode-terminal@0.12.0/node_modules/qrcode-terminal/lib/main.js"(exports, module) {
1015
- var QRCode = require_QRCode();
1016
- var QRErrorCorrectLevel = require_QRErrorCorrectLevel();
1017
- var black = "\x1B[40m \x1B[0m";
1018
- var white = "\x1B[47m \x1B[0m";
1019
- var toCell = function(isBlack) {
1020
- return isBlack ? black : white;
5085
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/png.js
5086
+ var require_png2 = __commonJS({
5087
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/png.js"(exports) {
5088
+ var fs = __require("fs");
5089
+ var PNG = require_png().PNG;
5090
+ var Utils = require_utils2();
5091
+ exports.render = function render2(qrData, options) {
5092
+ const opts = Utils.getOptions(options);
5093
+ const pngOpts = opts.rendererOpts;
5094
+ const size = Utils.getImageWidth(qrData.modules.size, opts);
5095
+ pngOpts.width = size;
5096
+ pngOpts.height = size;
5097
+ const pngImage = new PNG(pngOpts);
5098
+ Utils.qrToImageData(pngImage.data, qrData, opts);
5099
+ return pngImage;
1021
5100
  };
1022
- var repeat = function(color) {
1023
- return {
1024
- times: function(count) {
1025
- return new Array(count).join(color);
1026
- }
5101
+ exports.renderToDataURL = function renderToDataURL(qrData, options, cb) {
5102
+ if (typeof cb === "undefined") {
5103
+ cb = options;
5104
+ options = void 0;
5105
+ }
5106
+ exports.renderToBuffer(qrData, options, function(err, output) {
5107
+ if (err) cb(err);
5108
+ let url = "data:image/png;base64,";
5109
+ url += output.toString("base64");
5110
+ cb(null, url);
5111
+ });
5112
+ };
5113
+ exports.renderToBuffer = function renderToBuffer(qrData, options, cb) {
5114
+ if (typeof cb === "undefined") {
5115
+ cb = options;
5116
+ options = void 0;
5117
+ }
5118
+ const png = exports.render(qrData, options);
5119
+ const buffer = [];
5120
+ png.on("error", cb);
5121
+ png.on("data", function(data) {
5122
+ buffer.push(data);
5123
+ });
5124
+ png.on("end", function() {
5125
+ cb(null, Buffer.concat(buffer));
5126
+ });
5127
+ png.pack();
5128
+ };
5129
+ exports.renderToFile = function renderToFile(path, qrData, options, cb) {
5130
+ if (typeof cb === "undefined") {
5131
+ cb = options;
5132
+ options = void 0;
5133
+ }
5134
+ let called = false;
5135
+ const done = (...args) => {
5136
+ if (called) return;
5137
+ called = true;
5138
+ cb.apply(null, args);
1027
5139
  };
5140
+ const stream = fs.createWriteStream(path);
5141
+ stream.on("error", done);
5142
+ stream.on("close", done);
5143
+ exports.renderToFileStream(stream, qrData, options);
1028
5144
  };
1029
- var fill = function(length, value) {
1030
- var arr = new Array(length);
1031
- for (var i = 0; i < length; i++) {
1032
- arr[i] = value;
5145
+ exports.renderToFileStream = function renderToFileStream(stream, qrData, options) {
5146
+ const png = exports.render(qrData, options);
5147
+ png.pack().pipe(stream);
5148
+ };
5149
+ }
5150
+ });
5151
+
5152
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utf8.js
5153
+ var require_utf8 = __commonJS({
5154
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utf8.js"(exports) {
5155
+ var Utils = require_utils2();
5156
+ var BLOCK_CHAR = {
5157
+ WW: " ",
5158
+ WB: "\u2584",
5159
+ BB: "\u2588",
5160
+ BW: "\u2580"
5161
+ };
5162
+ var INVERTED_BLOCK_CHAR = {
5163
+ BB: " ",
5164
+ BW: "\u2584",
5165
+ WW: "\u2588",
5166
+ WB: "\u2580"
5167
+ };
5168
+ function getBlockChar(top, bottom, blocks) {
5169
+ if (top && bottom) return blocks.BB;
5170
+ if (top && !bottom) return blocks.BW;
5171
+ if (!top && bottom) return blocks.WB;
5172
+ return blocks.WW;
5173
+ }
5174
+ exports.render = function(qrData, options, cb) {
5175
+ const opts = Utils.getOptions(options);
5176
+ let blocks = BLOCK_CHAR;
5177
+ if (opts.color.dark.hex === "#ffffff" || opts.color.light.hex === "#000000") {
5178
+ blocks = INVERTED_BLOCK_CHAR;
5179
+ }
5180
+ const size = qrData.modules.size;
5181
+ const data = qrData.modules.data;
5182
+ let output = "";
5183
+ let hMargin = Array(size + opts.margin * 2 + 1).join(blocks.WW);
5184
+ hMargin = Array(opts.margin / 2 + 1).join(hMargin + "\n");
5185
+ const vMargin = Array(opts.margin + 1).join(blocks.WW);
5186
+ output += hMargin;
5187
+ for (let i = 0; i < size; i += 2) {
5188
+ output += vMargin;
5189
+ for (let j = 0; j < size; j++) {
5190
+ const topModule = data[i * size + j];
5191
+ const bottomModule = data[(i + 1) * size + j];
5192
+ output += getBlockChar(topModule, bottomModule, blocks);
5193
+ }
5194
+ output += vMargin + "\n";
5195
+ }
5196
+ output += hMargin.slice(0, -1);
5197
+ if (typeof cb === "function") {
5198
+ cb(null, output);
5199
+ }
5200
+ return output;
5201
+ };
5202
+ exports.renderToFile = function renderToFile(path, qrData, options, cb) {
5203
+ if (typeof cb === "undefined") {
5204
+ cb = options;
5205
+ options = void 0;
1033
5206
  }
1034
- return arr;
5207
+ const fs = __require("fs");
5208
+ const utf8 = exports.render(qrData, options);
5209
+ fs.writeFile(path, utf8, cb);
1035
5210
  };
1036
- module.exports = {
1037
- error: QRErrorCorrectLevel.L,
1038
- generate: function(input, opts, cb) {
1039
- if (typeof opts === "function") {
1040
- cb = opts;
1041
- opts = {};
1042
- }
1043
- var qrcode = new QRCode(-1, this.error);
1044
- qrcode.addData(input);
1045
- qrcode.make();
1046
- var output = "";
1047
- if (opts && opts.small) {
1048
- var BLACK = true, WHITE = false;
1049
- var moduleCount = qrcode.getModuleCount();
1050
- var moduleData = qrcode.modules.slice();
1051
- var oddRow = moduleCount % 2 === 1;
1052
- if (oddRow) {
1053
- moduleData.push(fill(moduleCount, WHITE));
5211
+ }
5212
+ });
5213
+
5214
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal.js
5215
+ var require_terminal = __commonJS({
5216
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal.js"(exports) {
5217
+ exports.render = function(qrData, options, cb) {
5218
+ const size = qrData.modules.size;
5219
+ const data = qrData.modules.data;
5220
+ const black = "\x1B[40m \x1B[0m";
5221
+ const white = "\x1B[47m \x1B[0m";
5222
+ let output = "";
5223
+ const hMargin = Array(size + 3).join(white);
5224
+ const vMargin = Array(2).join(white);
5225
+ output += hMargin + "\n";
5226
+ for (let i = 0; i < size; ++i) {
5227
+ output += white;
5228
+ for (let j = 0; j < size; j++) {
5229
+ output += data[i * size + j] ? black : white;
5230
+ }
5231
+ output += vMargin + "\n";
5232
+ }
5233
+ output += hMargin + "\n";
5234
+ if (typeof cb === "function") {
5235
+ cb(null, output);
5236
+ }
5237
+ return output;
5238
+ };
5239
+ }
5240
+ });
5241
+
5242
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal-small.js
5243
+ var require_terminal_small = __commonJS({
5244
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal-small.js"(exports) {
5245
+ var backgroundWhite = "\x1B[47m";
5246
+ var backgroundBlack = "\x1B[40m";
5247
+ var foregroundWhite = "\x1B[37m";
5248
+ var foregroundBlack = "\x1B[30m";
5249
+ var reset = "\x1B[0m";
5250
+ var lineSetupNormal = backgroundWhite + foregroundBlack;
5251
+ var lineSetupInverse = backgroundBlack + foregroundWhite;
5252
+ var createPalette = function(lineSetup, foregroundWhite2, foregroundBlack2) {
5253
+ return {
5254
+ // 1 ... white, 2 ... black, 0 ... transparent (default)
5255
+ "00": reset + " " + lineSetup,
5256
+ "01": reset + foregroundWhite2 + "\u2584" + lineSetup,
5257
+ "02": reset + foregroundBlack2 + "\u2584" + lineSetup,
5258
+ 10: reset + foregroundWhite2 + "\u2580" + lineSetup,
5259
+ 11: " ",
5260
+ 12: "\u2584",
5261
+ 20: reset + foregroundBlack2 + "\u2580" + lineSetup,
5262
+ 21: "\u2580",
5263
+ 22: "\u2588"
5264
+ };
5265
+ };
5266
+ var mkCodePixel = function(modules, size, x, y) {
5267
+ const sizePlus = size + 1;
5268
+ if (x >= sizePlus || y >= sizePlus || y < -1 || x < -1) return "0";
5269
+ if (x >= size || y >= size || y < 0 || x < 0) return "1";
5270
+ const idx = y * size + x;
5271
+ return modules[idx] ? "2" : "1";
5272
+ };
5273
+ var mkCode = function(modules, size, x, y) {
5274
+ return mkCodePixel(modules, size, x, y) + mkCodePixel(modules, size, x, y + 1);
5275
+ };
5276
+ exports.render = function(qrData, options, cb) {
5277
+ const size = qrData.modules.size;
5278
+ const data = qrData.modules.data;
5279
+ const inverse = !!(options && options.inverse);
5280
+ const lineSetup = options && options.inverse ? lineSetupInverse : lineSetupNormal;
5281
+ const white = inverse ? foregroundBlack : foregroundWhite;
5282
+ const black = inverse ? foregroundWhite : foregroundBlack;
5283
+ const palette = createPalette(lineSetup, white, black);
5284
+ const newLine = reset + "\n" + lineSetup;
5285
+ let output = lineSetup;
5286
+ for (let y = -1; y < size + 1; y += 2) {
5287
+ for (let x = -1; x < size; x++) {
5288
+ output += palette[mkCode(data, size, x, y)];
5289
+ }
5290
+ output += palette[mkCode(data, size, size, y)] + newLine;
5291
+ }
5292
+ output += reset;
5293
+ if (typeof cb === "function") {
5294
+ cb(null, output);
5295
+ }
5296
+ return output;
5297
+ };
5298
+ }
5299
+ });
5300
+
5301
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal.js
5302
+ var require_terminal2 = __commonJS({
5303
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal.js"(exports) {
5304
+ var big = require_terminal();
5305
+ var small = require_terminal_small();
5306
+ exports.render = function(qrData, options, cb) {
5307
+ if (options && options.small) {
5308
+ return small.render(qrData, options, cb);
5309
+ }
5310
+ return big.render(qrData, options, cb);
5311
+ };
5312
+ }
5313
+ });
5314
+
5315
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg-tag.js
5316
+ var require_svg_tag = __commonJS({
5317
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg-tag.js"(exports) {
5318
+ var Utils = require_utils2();
5319
+ function getColorAttrib(color, attrib) {
5320
+ const alpha = color.a / 255;
5321
+ const str = attrib + '="' + color.hex + '"';
5322
+ return alpha < 1 ? str + " " + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"' : str;
5323
+ }
5324
+ function svgCmd(cmd, x, y) {
5325
+ let str = cmd + x;
5326
+ if (typeof y !== "undefined") str += " " + y;
5327
+ return str;
5328
+ }
5329
+ function qrToPath(data, size, margin) {
5330
+ let path = "";
5331
+ let moveBy = 0;
5332
+ let newRow = false;
5333
+ let lineLength = 0;
5334
+ for (let i = 0; i < data.length; i++) {
5335
+ const col = Math.floor(i % size);
5336
+ const row = Math.floor(i / size);
5337
+ if (!col && !newRow) newRow = true;
5338
+ if (data[i]) {
5339
+ lineLength++;
5340
+ if (!(i > 0 && col > 0 && data[i - 1])) {
5341
+ path += newRow ? svgCmd("M", col + margin, 0.5 + row + margin) : svgCmd("m", moveBy, 0);
5342
+ moveBy = 0;
5343
+ newRow = false;
1054
5344
  }
1055
- var platte = {
1056
- WHITE_ALL: "\u2588",
1057
- WHITE_BLACK: "\u2580",
1058
- BLACK_WHITE: "\u2584",
1059
- BLACK_ALL: " "
1060
- };
1061
- var borderTop = repeat(platte.BLACK_WHITE).times(moduleCount + 3);
1062
- var borderBottom = repeat(platte.WHITE_BLACK).times(moduleCount + 3);
1063
- output += borderTop + "\n";
1064
- for (var row = 0; row < moduleCount; row += 2) {
1065
- output += platte.WHITE_ALL;
1066
- for (var col = 0; col < moduleCount; col++) {
1067
- if (moduleData[row][col] === WHITE && moduleData[row + 1][col] === WHITE) {
1068
- output += platte.WHITE_ALL;
1069
- } else if (moduleData[row][col] === WHITE && moduleData[row + 1][col] === BLACK) {
1070
- output += platte.WHITE_BLACK;
1071
- } else if (moduleData[row][col] === BLACK && moduleData[row + 1][col] === WHITE) {
1072
- output += platte.BLACK_WHITE;
1073
- } else {
1074
- output += platte.BLACK_ALL;
1075
- }
1076
- }
1077
- output += platte.WHITE_ALL + "\n";
5345
+ if (!(col + 1 < size && data[i + 1])) {
5346
+ path += svgCmd("h", lineLength);
5347
+ lineLength = 0;
1078
5348
  }
1079
- if (!oddRow) {
1080
- output += borderBottom;
5349
+ } else {
5350
+ moveBy++;
5351
+ }
5352
+ }
5353
+ return path;
5354
+ }
5355
+ exports.render = function render2(qrData, options, cb) {
5356
+ const opts = Utils.getOptions(options);
5357
+ const size = qrData.modules.size;
5358
+ const data = qrData.modules.data;
5359
+ const qrcodesize = size + opts.margin * 2;
5360
+ const bg = !opts.color.light.a ? "" : "<path " + getColorAttrib(opts.color.light, "fill") + ' d="M0 0h' + qrcodesize + "v" + qrcodesize + 'H0z"/>';
5361
+ const path = "<path " + getColorAttrib(opts.color.dark, "stroke") + ' d="' + qrToPath(data, size, opts.margin) + '"/>';
5362
+ const viewBox = 'viewBox="0 0 ' + qrcodesize + " " + qrcodesize + '"';
5363
+ const width = !opts.width ? "" : 'width="' + opts.width + '" height="' + opts.width + '" ';
5364
+ const svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path + "</svg>\n";
5365
+ if (typeof cb === "function") {
5366
+ cb(null, svgTag);
5367
+ }
5368
+ return svgTag;
5369
+ };
5370
+ }
5371
+ });
5372
+
5373
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg.js
5374
+ var require_svg = __commonJS({
5375
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg.js"(exports) {
5376
+ var svgTagRenderer = require_svg_tag();
5377
+ exports.render = svgTagRenderer.render;
5378
+ exports.renderToFile = function renderToFile(path, qrData, options, cb) {
5379
+ if (typeof cb === "undefined") {
5380
+ cb = options;
5381
+ options = void 0;
5382
+ }
5383
+ const fs = __require("fs");
5384
+ const svgTag = exports.render(qrData, options);
5385
+ const xmlStr = '<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' + svgTag;
5386
+ fs.writeFile(path, xmlStr, cb);
5387
+ };
5388
+ }
5389
+ });
5390
+
5391
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/canvas.js
5392
+ var require_canvas = __commonJS({
5393
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/canvas.js"(exports) {
5394
+ var Utils = require_utils2();
5395
+ function clearCanvas(ctx, canvas, size) {
5396
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
5397
+ if (!canvas.style) canvas.style = {};
5398
+ canvas.height = size;
5399
+ canvas.width = size;
5400
+ canvas.style.height = size + "px";
5401
+ canvas.style.width = size + "px";
5402
+ }
5403
+ function getCanvasElement() {
5404
+ try {
5405
+ return document.createElement("canvas");
5406
+ } catch (e) {
5407
+ throw new Error("You need to specify a canvas element");
5408
+ }
5409
+ }
5410
+ exports.render = function render2(qrData, canvas, options) {
5411
+ let opts = options;
5412
+ let canvasEl = canvas;
5413
+ if (typeof opts === "undefined" && (!canvas || !canvas.getContext)) {
5414
+ opts = canvas;
5415
+ canvas = void 0;
5416
+ }
5417
+ if (!canvas) {
5418
+ canvasEl = getCanvasElement();
5419
+ }
5420
+ opts = Utils.getOptions(opts);
5421
+ const size = Utils.getImageWidth(qrData.modules.size, opts);
5422
+ const ctx = canvasEl.getContext("2d");
5423
+ const image = ctx.createImageData(size, size);
5424
+ Utils.qrToImageData(image.data, qrData, opts);
5425
+ clearCanvas(ctx, canvasEl, size);
5426
+ ctx.putImageData(image, 0, 0);
5427
+ return canvasEl;
5428
+ };
5429
+ exports.renderToDataURL = function renderToDataURL(qrData, canvas, options) {
5430
+ let opts = options;
5431
+ if (typeof opts === "undefined" && (!canvas || !canvas.getContext)) {
5432
+ opts = canvas;
5433
+ canvas = void 0;
5434
+ }
5435
+ if (!opts) opts = {};
5436
+ const canvasEl = exports.render(qrData, canvas, opts);
5437
+ const type = opts.type || "image/png";
5438
+ const rendererOpts = opts.rendererOpts || {};
5439
+ return canvasEl.toDataURL(type, rendererOpts.quality);
5440
+ };
5441
+ }
5442
+ });
5443
+
5444
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/browser.js
5445
+ var require_browser = __commonJS({
5446
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/browser.js"(exports) {
5447
+ var canPromise = require_can_promise();
5448
+ var QRCode = require_qrcode();
5449
+ var CanvasRenderer = require_canvas();
5450
+ var SvgRenderer = require_svg_tag();
5451
+ function renderCanvas(renderFunc, canvas, text, opts, cb) {
5452
+ const args = [].slice.call(arguments, 1);
5453
+ const argsNum = args.length;
5454
+ const isLastArgCb = typeof args[argsNum - 1] === "function";
5455
+ if (!isLastArgCb && !canPromise()) {
5456
+ throw new Error("Callback required as last argument");
5457
+ }
5458
+ if (isLastArgCb) {
5459
+ if (argsNum < 2) {
5460
+ throw new Error("Too few arguments provided");
5461
+ }
5462
+ if (argsNum === 2) {
5463
+ cb = text;
5464
+ text = canvas;
5465
+ canvas = opts = void 0;
5466
+ } else if (argsNum === 3) {
5467
+ if (canvas.getContext && typeof cb === "undefined") {
5468
+ cb = opts;
5469
+ opts = void 0;
5470
+ } else {
5471
+ cb = opts;
5472
+ opts = text;
5473
+ text = canvas;
5474
+ canvas = void 0;
5475
+ }
5476
+ }
5477
+ } else {
5478
+ if (argsNum < 1) {
5479
+ throw new Error("Too few arguments provided");
5480
+ }
5481
+ if (argsNum === 1) {
5482
+ text = canvas;
5483
+ canvas = opts = void 0;
5484
+ } else if (argsNum === 2 && !canvas.getContext) {
5485
+ opts = text;
5486
+ text = canvas;
5487
+ canvas = void 0;
5488
+ }
5489
+ return new Promise(function(resolve4, reject) {
5490
+ try {
5491
+ const data = QRCode.create(text, opts);
5492
+ resolve4(renderFunc(data, canvas, opts));
5493
+ } catch (e) {
5494
+ reject(e);
1081
5495
  }
5496
+ });
5497
+ }
5498
+ try {
5499
+ const data = QRCode.create(text, opts);
5500
+ cb(null, renderFunc(data, canvas, opts));
5501
+ } catch (e) {
5502
+ cb(e);
5503
+ }
5504
+ }
5505
+ exports.create = QRCode.create;
5506
+ exports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render);
5507
+ exports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL);
5508
+ exports.toString = renderCanvas.bind(null, function(data, _, opts) {
5509
+ return SvgRenderer.render(data, opts);
5510
+ });
5511
+ }
5512
+ });
5513
+
5514
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/server.js
5515
+ var require_server = __commonJS({
5516
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/server.js"(exports) {
5517
+ var canPromise = require_can_promise();
5518
+ var QRCode = require_qrcode();
5519
+ var PngRenderer = require_png2();
5520
+ var Utf8Renderer = require_utf8();
5521
+ var TerminalRenderer = require_terminal2();
5522
+ var SvgRenderer = require_svg();
5523
+ function checkParams(text, opts, cb) {
5524
+ if (typeof text === "undefined") {
5525
+ throw new Error("String required as first argument");
5526
+ }
5527
+ if (typeof cb === "undefined") {
5528
+ cb = opts;
5529
+ opts = {};
5530
+ }
5531
+ if (typeof cb !== "function") {
5532
+ if (!canPromise()) {
5533
+ throw new Error("Callback required as last argument");
1082
5534
  } else {
1083
- var border = repeat(white).times(qrcode.getModuleCount() + 3);
1084
- output += border + "\n";
1085
- qrcode.modules.forEach(function(row2) {
1086
- output += white;
1087
- output += row2.map(toCell).join("");
1088
- output += white + "\n";
1089
- });
1090
- output += border;
5535
+ opts = cb || {};
5536
+ cb = null;
1091
5537
  }
1092
- if (cb) cb(output);
1093
- else console.log(output);
1094
- },
1095
- setErrorLevel: function(error) {
1096
- this.error = QRErrorCorrectLevel[error] || this.error;
1097
5538
  }
5539
+ return {
5540
+ opts,
5541
+ cb
5542
+ };
5543
+ }
5544
+ function getTypeFromFilename(path) {
5545
+ return path.slice((path.lastIndexOf(".") - 1 >>> 0) + 2).toLowerCase();
5546
+ }
5547
+ function getRendererFromType(type) {
5548
+ switch (type) {
5549
+ case "svg":
5550
+ return SvgRenderer;
5551
+ case "txt":
5552
+ case "utf8":
5553
+ return Utf8Renderer;
5554
+ case "png":
5555
+ case "image/png":
5556
+ default:
5557
+ return PngRenderer;
5558
+ }
5559
+ }
5560
+ function getStringRendererFromType(type) {
5561
+ switch (type) {
5562
+ case "svg":
5563
+ return SvgRenderer;
5564
+ case "terminal":
5565
+ return TerminalRenderer;
5566
+ case "utf8":
5567
+ default:
5568
+ return Utf8Renderer;
5569
+ }
5570
+ }
5571
+ function render2(renderFunc, text, params) {
5572
+ if (!params.cb) {
5573
+ return new Promise(function(resolve4, reject) {
5574
+ try {
5575
+ const data = QRCode.create(text, params.opts);
5576
+ return renderFunc(data, params.opts, function(err, data2) {
5577
+ return err ? reject(err) : resolve4(data2);
5578
+ });
5579
+ } catch (e) {
5580
+ reject(e);
5581
+ }
5582
+ });
5583
+ }
5584
+ try {
5585
+ const data = QRCode.create(text, params.opts);
5586
+ return renderFunc(data, params.opts, params.cb);
5587
+ } catch (e) {
5588
+ params.cb(e);
5589
+ }
5590
+ }
5591
+ exports.create = QRCode.create;
5592
+ exports.toCanvas = require_browser().toCanvas;
5593
+ exports.toString = function toString2(text, opts, cb) {
5594
+ const params = checkParams(text, opts, cb);
5595
+ const type = params.opts ? params.opts.type : void 0;
5596
+ const renderer = getStringRendererFromType(type);
5597
+ return render2(renderer.render, text, params);
5598
+ };
5599
+ exports.toDataURL = function toDataURL(text, opts, cb) {
5600
+ const params = checkParams(text, opts, cb);
5601
+ const renderer = getRendererFromType(params.opts.type);
5602
+ return render2(renderer.renderToDataURL, text, params);
5603
+ };
5604
+ exports.toBuffer = function toBuffer(text, opts, cb) {
5605
+ const params = checkParams(text, opts, cb);
5606
+ const renderer = getRendererFromType(params.opts.type);
5607
+ return render2(renderer.renderToBuffer, text, params);
5608
+ };
5609
+ exports.toFile = function toFile(path, text, opts, cb) {
5610
+ if (typeof path !== "string" || !(typeof text === "string" || typeof text === "object")) {
5611
+ throw new Error("Invalid argument");
5612
+ }
5613
+ if (arguments.length < 3 && !canPromise()) {
5614
+ throw new Error("Too few arguments provided");
5615
+ }
5616
+ const params = checkParams(text, opts, cb);
5617
+ const type = params.opts.type || getTypeFromFilename(path);
5618
+ const renderer = getRendererFromType(type);
5619
+ const renderToFile = renderer.renderToFile.bind(null, path);
5620
+ return render2(renderToFile, text, params);
5621
+ };
5622
+ exports.toFileStream = function toFileStream(stream, text, opts) {
5623
+ if (arguments.length < 2) {
5624
+ throw new Error("Too few arguments provided");
5625
+ }
5626
+ const params = checkParams(text, opts, stream.emit.bind(stream, "error"));
5627
+ const renderer = getRendererFromType("png");
5628
+ const renderToFileStream = renderer.renderToFileStream.bind(null, stream);
5629
+ render2(renderToFileStream, text, params);
1098
5630
  };
1099
5631
  }
1100
5632
  });
1101
5633
 
5634
+ // node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/index.js
5635
+ var require_lib = __commonJS({
5636
+ "node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/index.js"(exports, module) {
5637
+ module.exports = require_server();
5638
+ }
5639
+ });
5640
+
1102
5641
  // node_modules/.pnpm/semver@7.8.6/node_modules/semver/internal/constants.js
1103
- var require_constants = __commonJS({
5642
+ var require_constants2 = __commonJS({
1104
5643
  "node_modules/.pnpm/semver@7.8.6/node_modules/semver/internal/constants.js"(exports, module) {
1105
5644
  "use strict";
1106
5645
  var SEMVER_SPEC_VERSION = "2.0.0";
@@ -1177,7 +5716,7 @@ var require_re = __commonJS({
1177
5716
  MAX_SAFE_COMPONENT_LENGTH,
1178
5717
  MAX_SAFE_BUILD_LENGTH,
1179
5718
  MAX_LENGTH
1180
- } = require_constants();
5719
+ } = require_constants2();
1181
5720
  var debug = require_debug();
1182
5721
  exports = module.exports = {};
1183
5722
  var re = exports.re = [];
@@ -1306,7 +5845,7 @@ var require_semver = __commonJS({
1306
5845
  "node_modules/.pnpm/semver@7.8.6/node_modules/semver/classes/semver.js"(exports, module) {
1307
5846
  "use strict";
1308
5847
  var debug = require_debug();
1309
- var { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants();
5848
+ var { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants2();
1310
5849
  var { safeRe: re, t } = require_re();
1311
5850
  var parseOptions = require_parse_options();
1312
5851
  var { compareIdentifiers } = require_identifiers();
@@ -1977,7 +6516,7 @@ var require_truncate = __commonJS({
1977
6516
  "node_modules/.pnpm/semver@7.8.6/node_modules/semver/functions/truncate.js"(exports, module) {
1978
6517
  "use strict";
1979
6518
  var parse2 = require_parse();
1980
- var constants = require_constants();
6519
+ var constants = require_constants2();
1981
6520
  var SemVer = require_semver();
1982
6521
  var truncate3 = (version, truncation, options) => {
1983
6522
  if (!constants.RELEASE_TYPES.includes(truncation)) {
@@ -2059,7 +6598,7 @@ var require_trim_comparator_whitespace = __commonJS({
2059
6598
  MAX_LENGTH,
2060
6599
  MAX_SAFE_BUILD_LENGTH,
2061
6600
  WHITESPACE_CHARACTERS
2062
- } = require_constants();
6601
+ } = require_constants2();
2063
6602
  var whitespace = new Uint8Array(65536);
2064
6603
  for (const char of WHITESPACE_CHARACTERS) {
2065
6604
  whitespace[char.charCodeAt(0)] = 1;
@@ -2401,7 +6940,7 @@ var require_range = __commonJS({
2401
6940
  tildeTrimReplace,
2402
6941
  caretTrimReplace
2403
6942
  } = require_re();
2404
- var { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = require_constants();
6943
+ var { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = require_constants2();
2405
6944
  var BUILDSTRIPRE = new RegExp(src[t.BUILD], "g");
2406
6945
  var isNullSet = (c) => c.value === "<0.0.0-0";
2407
6946
  var isAny = (c) => c.value === "";
@@ -3220,7 +7759,7 @@ var require_semver2 = __commonJS({
3220
7759
  "node_modules/.pnpm/semver@7.8.6/node_modules/semver/index.js"(exports, module) {
3221
7760
  "use strict";
3222
7761
  var internalRe = require_re();
3223
- var constants = require_constants();
7762
+ var constants = require_constants2();
3224
7763
  var SemVer = require_semver();
3225
7764
  var identifiers = require_identifiers();
3226
7765
  var parse2 = require_parse();
@@ -4193,7 +8732,7 @@ var Config = Schema.object({
4193
8732
  pairingMaxAttempts: Schema.number().default(8),
4194
8733
  pairingCode: Schema.string(),
4195
8734
  logPairingCode: Schema.boolean().default(true),
4196
- interactionTarget: Schema.union(["phone-first", "browser-first", "browser-only"]).default("browser-first"),
8735
+ interactionTarget: Schema.union(["phone-first", "browser-first", "browser-only"]).default("browser-only"),
4197
8736
  approvalWaitTimeoutMs: Schema.number().default(2 * 60 * 1e3),
4198
8737
  questionWaitTimeoutMs: Schema.number().default(2 * 60 * 1e3),
4199
8738
  allowSessionWideGrants: Schema.boolean().default(true),
@@ -4234,7 +8773,7 @@ function normalizeConfig(input) {
4234
8773
  pairingCodeLength: raw.pairingCodeLength ?? 4,
4235
8774
  pairingMaxAttempts: raw.pairingMaxAttempts ?? 8,
4236
8775
  logPairingCode: raw.logPairingCode ?? true,
4237
- interactionTarget: raw.interactionTarget ?? "browser-first",
8776
+ interactionTarget: raw.interactionTarget ?? "browser-only",
4238
8777
  approvalWaitTimeoutMs: raw.approvalWaitTimeoutMs ?? 2 * 60 * 1e3,
4239
8778
  questionWaitTimeoutMs: raw.questionWaitTimeoutMs ?? 2 * 60 * 1e3,
4240
8779
  allowSessionWideGrants: raw.allowSessionWideGrants ?? true,
@@ -4830,6 +9369,7 @@ var InteractionBroker = class {
4830
9369
  this.hub = hub;
4831
9370
  this.push = push2;
4832
9371
  this.logger = logger;
9372
+ this.target = config.interactionTarget;
4833
9373
  }
4834
9374
  ctx;
4835
9375
  config;
@@ -4843,12 +9383,19 @@ var InteractionBroker = class {
4843
9383
  foreground = /* @__PURE__ */ new Map();
4844
9384
  /** Hands held interactions back if a foreground app dies without a false ping. */
4845
9385
  presenceSweep = setInterval(() => this.releasePhoneHolds(), 15e3);
9386
+ /** Runtime policy: the config default, replaceable from the admin page. */
9387
+ target;
9388
+ getTarget() {
9389
+ return this.target;
9390
+ }
9391
+ setTarget(target) {
9392
+ if (target === this.target) return;
9393
+ this.target = target;
9394
+ this.logger.info(`[dsh-hello] interaction target is now ${target}`);
9395
+ if (target === "browser-only") this.releasePhoneHolds(true);
9396
+ }
4846
9397
  register() {
4847
9398
  this.presenceSweep.unref?.();
4848
- if (this.config.interactionTarget === "browser-only") {
4849
- this.logger.info("[dsh-hello] interactionTarget browser-only: the app will not answer approvals or questions");
4850
- return;
4851
- }
4852
9399
  const listen = { global: true, prepend: true };
4853
9400
  this.ctx.on("approval/request", async (...args) => {
4854
9401
  const req = args[0];
@@ -5174,7 +9721,7 @@ var InteractionBroker = class {
5174
9721
  */
5175
9722
  shouldHoldForPhone() {
5176
9723
  return shouldHoldInteraction({
5177
- target: this.config.interactionTarget,
9724
+ target: this.target,
5178
9725
  browserLive: this.browserWins(),
5179
9726
  foregroundPhone: this.phoneWins(),
5180
9727
  appConnected: this.appCanAnswer()
@@ -5195,8 +9742,8 @@ var InteractionBroker = class {
5195
9742
  * The app left the foreground (or stopped heartbeating). Any interaction it
5196
9743
  * was holding goes back to dsh so a connected browser can render it now.
5197
9744
  */
5198
- releasePhoneHolds() {
5199
- if (this.hasForegroundPhone()) return;
9745
+ releasePhoneHolds(force = false) {
9746
+ if (!force && this.hasForegroundPhone()) return;
5200
9747
  for (const [id, pending] of [...this.questions]) {
5201
9748
  if (!pending.phoneHold) continue;
5202
9749
  clearTimeout(pending.timer);
@@ -6367,6 +10914,22 @@ function registerRoutes(router, deps) {
6367
10914
  sendJson(rc.res, 200, await adminData(deps, requestBase(rc) ?? requestOrigin(deps, rc) ?? ""));
6368
10915
  }
6369
10916
  });
10917
+ router.add({
10918
+ method: "POST",
10919
+ pattern: "/admin/interaction",
10920
+ auth: "public",
10921
+ handler: async (rc) => {
10922
+ if (!adminAuthorized(deps, rc)) throw new HttpError(401, "admin-unauthorized", "open this page from an authenticated dsh browser");
10923
+ const body = rc.body ?? {};
10924
+ const target = body.target;
10925
+ if (target !== "phone-first" && target !== "browser-first" && target !== "browser-only") {
10926
+ throw new HttpError(400, "bad-target", "target must be phone-first, browser-first, or browser-only");
10927
+ }
10928
+ if (deps.saveInteractionTarget === void 0) throw new HttpError(503, "interaction-unavailable", "this Host cannot change the interaction policy");
10929
+ await deps.saveInteractionTarget(target);
10930
+ sendJson(rc.res, 200, await adminData(deps, requestBase(rc) ?? requestOrigin(deps, rc) ?? ""));
10931
+ }
10932
+ });
6370
10933
  router.add({
6371
10934
  method: "POST",
6372
10935
  pattern: "/admin/lock",
@@ -7380,10 +11943,11 @@ function scheduleCode(result) {
7380
11943
  return typeof code === "string" ? code : void 0;
7381
11944
  }
7382
11945
  function features(deps) {
11946
+ const target = deps.interactionTarget?.() ?? deps.config.interactionTarget;
7383
11947
  return {
7384
- approvals: deps.config.interactionTarget !== "browser-only",
7385
- questions: deps.config.interactionTarget !== "browser-only",
7386
- interactionTarget: deps.config.interactionTarget,
11948
+ approvals: target !== "browser-only",
11949
+ questions: target !== "browser-only",
11950
+ interactionTarget: target,
7387
11951
  presence: true,
7388
11952
  push: deps.push.isConfigured(),
7389
11953
  debugRoutes: deps.config.enableDebugRoutes,
@@ -7463,6 +12027,7 @@ async function adminData(deps, originBase) {
7463
12027
  formatted: view.formatted,
7464
12028
  fixed: view.fixed,
7465
12029
  locked: deps.pairing.isLocked(),
12030
+ interactionTarget: deps.interactionTarget?.() ?? deps.config.interactionTarget,
7466
12031
  expiresAt: view.fixed ? null : view.expiresAt,
7467
12032
  origin,
7468
12033
  basePath: deps.config.basePath,
@@ -7548,7 +12113,7 @@ async function renderQr(text) {
7548
12113
  async function loadQrSvgApi() {
7549
12114
  const isApi = (value) => typeof value === "object" && value !== null && typeof value.toString === "function" && value.toString !== Object.prototype.toString;
7550
12115
  try {
7551
- const mod = await import("qrcode");
12116
+ const mod = await Promise.resolve().then(() => __toESM(require_lib(), 1));
7552
12117
  for (const candidate of [mod.default, mod.default?.default, mod]) {
7553
12118
  if (isApi(candidate)) return candidate;
7554
12119
  }
@@ -8259,6 +12824,23 @@ async function apply(ctx, rawConfig) {
8259
12824
  }
8260
12825
  const interactions = new InteractionBroker(host, config, hub, push2, logger);
8261
12826
  interactions.register();
12827
+ const interactionRecordKey = "dsh-hello/interactions";
12828
+ if (credentials !== void 0) {
12829
+ try {
12830
+ const record = await credentials.readRecord(interactionRecordKey);
12831
+ const target = record?.payload?.target;
12832
+ if (target === "phone-first" || target === "browser-first" || target === "browser-only") {
12833
+ interactions.setTarget(target);
12834
+ }
12835
+ } catch (error) {
12836
+ logger.warn(`[dsh-hello] could not load the interaction target: ${shortError(error)}`);
12837
+ }
12838
+ }
12839
+ const saveInteractionTarget = async (target) => {
12840
+ interactions.setTarget(target);
12841
+ if (credentials === void 0) return;
12842
+ await credentials.modifyRecord(interactionRecordKey, async () => ({ kind: "grant", payload: { target } }));
12843
+ };
8262
12844
  const sessions = createSessionFacade(host);
8263
12845
  const terminals = new TerminalManager(host, logger);
8264
12846
  const connection = readService(ctx, "connection");
@@ -8292,7 +12874,9 @@ async function apply(ctx, rawConfig) {
8292
12874
  logger,
8293
12875
  version,
8294
12876
  pluginVersion: PLUGIN_VERSION,
8295
- webUrl
12877
+ webUrl,
12878
+ saveInteractionTarget,
12879
+ interactionTarget: () => interactions.getTarget()
8296
12880
  });
8297
12881
  ctx.effect(() => {
8298
12882
  const dispose = webServer.register(router.hostRoute());