@atooyu/uxto-ui 1.1.30 → 1.1.32

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/dist/index.mjs CHANGED
@@ -501,7 +501,7 @@ const chat = "data:image/svg+xml,%3csvg%20viewBox='0%200%2024%2024'%20xmlns='htt
501
501
  const clipboard = "data:image/svg+xml,%3csvg%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20fill='currentColor'%20d='M19%203h-4.18C14.4%201.84%2013.3%201%2012%201c-1.3%200-2.4.84-2.82%202H5c-1.1%200-2%20.9-2%202v14c0%201.1.9%202%202%202h14c1.1%200%202-.9%202-2V5c0-1.1-.9-2-2-2zm-7%200c.55%200%201%20.45%201%201s-.45%201-1%201-1-.45-1-1%20.45-1%201-1zm2%2014H7v-2h7v2zm3-4H7v-2h10v2zm0-4H7V7h10v2z'/%3e%3c/svg%3e";
502
502
  const location = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='currentColor'%3e%3cpath%20d='M12%202C8.13%202%205%205.13%205%209c0%205.25%207%2013%207%2013s7-7.75%207-13c0-3.87-3.13-7-7-7zm0%209.5c-1.38%200-2.5-1.12-2.5-2.5s1.12-2.5%202.5-2.5%202.5%201.12%202.5%202.5-1.12%202.5-2.5%202.5z'/%3e%3c/svg%3e";
503
503
  const scan = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='currentColor'%3e%3cpath%20d='M3%2011h8V3H3v8zm2-6h4v4H5V5zm8-2v8h8V3h-8zm6%206h-4V5h4v4zM3%2021h8v-8H3v8zm2-6h4v4H5v-4zm13-2h-2v3h-3v2h3v3h2v-3h3v-2h-3v-3z'/%3e%3c/svg%3e";
504
- const qrcode$1 = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='currentColor'%3e%3cpath%20d='M3%203h6v6H3V3zm2%202v2h2V5H5zm8-2h6v6h-6V3zm2%202v2h2V5h-2zM3%2013h6v6H3v-6zm2%202v2h2v-2H5zm13-2h3v2h-3v-2zm-3%200h2v4h-2v-4zm-2%202h2v2h-2v-2zm2%202h3v2h-3v-2zm3%202h2v2h-2v-2zm-5%200h2v2h-2v-2z'/%3e%3c/svg%3e";
504
+ const qrcode = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='currentColor'%3e%3cpath%20d='M3%203h6v6H3V3zm2%202v2h2V5H5zm8-2h6v6h-6V3zm2%202v2h2V5h-2zM3%2013h6v6H3v-6zm2%202v2h2v-2H5zm13-2h3v2h-3v-2zm-3%200h2v4h-2v-4zm-2%202h2v2h-2v-2zm2%202h3v2h-3v-2zm3%202h2v2h-2v-2zm-5%200h2v2h-2v-2z'/%3e%3c/svg%3e";
505
505
  const moon = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='currentColor'%3e%3cpath%20d='M12%203a9%209%200%20109%209c0-.46-.04-.92-.1-1.36a5.389%205.389%200%2001-4.4%202.26%205.403%205.403%200%2001-3.14-9.8c-.44-.06-.9-.1-1.36-.1z'/%3e%3c/svg%3e";
506
506
  const icons = {
507
507
  // 箭头类
@@ -557,7 +557,7 @@ const icons = {
557
557
  "like": like,
558
558
  "like-o": likeO,
559
559
  "share": share,
560
- "qrcode": qrcode$1,
560
+ "qrcode": qrcode,
561
561
  "moon": moon,
562
562
  // 用户类
563
563
  "user": user,
@@ -5025,1689 +5025,324 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5025
5025
  }
5026
5026
  });
5027
5027
  const uTabbar = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-10cb84bc"]]);
5028
- const qrcode = function(typeNumber, errorCorrectionLevel) {
5029
- const PAD0 = 236;
5030
- const PAD1 = 17;
5031
- let _typeNumber = typeNumber;
5032
- const _errorCorrectionLevel = QRErrorCorrectionLevel[errorCorrectionLevel];
5033
- let _modules = null;
5034
- let _moduleCount = 0;
5035
- let _dataCache = null;
5036
- const _dataList = [];
5037
- const _this = {};
5038
- const makeImpl = function(test, maskPattern) {
5039
- _moduleCount = _typeNumber * 4 + 17;
5040
- _modules = function(moduleCount) {
5041
- const modules = new Array(moduleCount);
5042
- for (let row = 0; row < moduleCount; row += 1) {
5043
- modules[row] = new Array(moduleCount);
5044
- for (let col = 0; col < moduleCount; col += 1) {
5045
- modules[row][col] = null;
5046
- }
5047
- }
5048
- return modules;
5049
- }(_moduleCount);
5050
- setupPositionProbePattern(0, 0);
5051
- setupPositionProbePattern(_moduleCount - 7, 0);
5052
- setupPositionProbePattern(0, _moduleCount - 7);
5053
- setupPositionAdjustPattern();
5054
- setupTimingPattern();
5055
- setupTypeInfo(test, maskPattern);
5056
- if (_typeNumber >= 7) {
5057
- setupTypeNumber(test);
5058
- }
5059
- if (_dataCache == null) {
5060
- _dataCache = createData(_typeNumber, _errorCorrectionLevel, _dataList);
5061
- }
5062
- mapData(_dataCache, maskPattern);
5063
- };
5064
- const setupPositionProbePattern = function(row, col) {
5065
- for (let r = -1; r <= 7; r += 1) {
5066
- if (row + r <= -1 || _moduleCount <= row + r) continue;
5067
- for (let c = -1; c <= 7; c += 1) {
5068
- if (col + c <= -1 || _moduleCount <= col + c) continue;
5069
- if (0 <= r && r <= 6 && (c == 0 || c == 6) || 0 <= c && c <= 6 && (r == 0 || r == 6) || 2 <= r && r <= 4 && 2 <= c && c <= 4) {
5070
- _modules[row + r][col + c] = true;
5071
- } else {
5072
- _modules[row + r][col + c] = false;
5073
- }
5074
- }
5075
- }
5076
- };
5077
- const getBestMaskPattern = function() {
5078
- let minLostPoint = 0;
5079
- let pattern = 0;
5080
- for (let i = 0; i < 8; i += 1) {
5081
- makeImpl(true, i);
5082
- const lostPoint = QRUtil.getLostPoint(_this);
5083
- if (i == 0 || minLostPoint > lostPoint) {
5084
- minLostPoint = lostPoint;
5085
- pattern = i;
5086
- }
5087
- }
5088
- return pattern;
5089
- };
5090
- const setupTimingPattern = function() {
5091
- for (let r = 8; r < _moduleCount - 8; r += 1) {
5092
- if (_modules[r][6] != null) {
5093
- continue;
5094
- }
5095
- _modules[r][6] = r % 2 == 0;
5096
- }
5097
- for (let c = 8; c < _moduleCount - 8; c += 1) {
5098
- if (_modules[6][c] != null) {
5099
- continue;
5100
- }
5101
- _modules[6][c] = c % 2 == 0;
5028
+ const __default__$1 = {
5029
+ options: {
5030
+ virtualHost: true,
5031
+ styleIsolation: "shared"
5032
+ }
5033
+ };
5034
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5035
+ ...__default__$1,
5036
+ __name: "u-qrcode",
5037
+ props: {
5038
+ value: { default: "" },
5039
+ size: { default: 200 },
5040
+ color: { default: "#000000" },
5041
+ bgColor: { default: "#ffffff" },
5042
+ errorCorrectLevel: { default: "M" }
5043
+ },
5044
+ setup(__props) {
5045
+ const props = __props;
5046
+ const modules = ref([]);
5047
+ const cellSize = computed(() => {
5048
+ if (modules.value.length === 0) return 0;
5049
+ return props.size / modules.value.length;
5050
+ });
5051
+ const ECL_MAP = { L: 0, M: 1, Q: 2, H: 3 };
5052
+ const DATA_CAPACITY = [
5053
+ [17, 14, 11, 7],
5054
+ [32, 26, 20, 14],
5055
+ [53, 42, 32, 24],
5056
+ [78, 62, 46, 34],
5057
+ [106, 84, 60, 44],
5058
+ [134, 106, 74, 58],
5059
+ [154, 122, 86, 64],
5060
+ [192, 152, 108, 84],
5061
+ [230, 180, 130, 98],
5062
+ [271, 213, 151, 119],
5063
+ [321, 251, 177, 137],
5064
+ [367, 287, 203, 155],
5065
+ [425, 331, 241, 177],
5066
+ [458, 362, 258, 194],
5067
+ [520, 412, 292, 220],
5068
+ [586, 450, 322, 250],
5069
+ [644, 504, 364, 280],
5070
+ [718, 560, 394, 310],
5071
+ [792, 624, 442, 338],
5072
+ [858, 666, 482, 382],
5073
+ [929, 711, 509, 403],
5074
+ [1003, 779, 565, 439],
5075
+ [1091, 857, 611, 461],
5076
+ [1171, 911, 661, 511],
5077
+ [1273, 997, 715, 535],
5078
+ [1367, 1059, 751, 593],
5079
+ [1465, 1125, 805, 625],
5080
+ [1528, 1190, 868, 658],
5081
+ [1628, 1264, 908, 698],
5082
+ [1732, 1370, 982, 742],
5083
+ [1840, 1452, 1030, 790],
5084
+ [1952, 1538, 1112, 842],
5085
+ [2068, 1628, 1168, 898],
5086
+ [2188, 1722, 1228, 958],
5087
+ [2303, 1809, 1283, 983],
5088
+ [2431, 1911, 1351, 1051],
5089
+ [2563, 1989, 1423, 1093],
5090
+ [2699, 2099, 1499, 1139],
5091
+ [2809, 2213, 1579, 1219],
5092
+ [2953, 2331, 1663, 1273]
5093
+ ];
5094
+ const ECC_CODEWORDS = [
5095
+ [7, 10, 13, 17],
5096
+ [10, 16, 22, 28],
5097
+ [15, 26, 36, 44],
5098
+ [20, 36, 52, 64],
5099
+ [26, 48, 72, 88],
5100
+ [36, 64, 96, 112],
5101
+ [40, 72, 108, 130],
5102
+ [48, 88, 132, 156],
5103
+ [60, 110, 160, 192],
5104
+ [72, 130, 192, 224],
5105
+ [80, 150, 224, 264],
5106
+ [96, 176, 260, 308],
5107
+ [104, 198, 288, 352],
5108
+ [120, 216, 320, 384],
5109
+ [132, 240, 360, 432],
5110
+ [144, 280, 408, 480],
5111
+ [168, 308, 448, 532],
5112
+ [180, 338, 504, 588],
5113
+ [196, 364, 546, 650],
5114
+ [224, 416, 600, 700],
5115
+ [224, 442, 644, 750],
5116
+ [252, 476, 690, 816],
5117
+ [270, 504, 750, 900],
5118
+ [300, 560, 810, 960],
5119
+ [312, 588, 870, 1050],
5120
+ [336, 644, 952, 1110],
5121
+ [360, 700, 1020, 1200],
5122
+ [390, 728, 1050, 1260],
5123
+ [420, 784, 1140, 1350],
5124
+ [450, 812, 1200, 1440],
5125
+ [480, 868, 1290, 1530],
5126
+ [510, 924, 1350, 1620],
5127
+ [540, 980, 1440, 1710],
5128
+ [570, 1036, 1530, 1800],
5129
+ [570, 1064, 1590, 1890],
5130
+ [600, 1120, 1680, 1980],
5131
+ [630, 1204, 1770, 2100],
5132
+ [660, 1260, 1860, 2220],
5133
+ [720, 1316, 1950, 2310],
5134
+ [750, 1372, 2040, 2430]
5135
+ ];
5136
+ const GF_EXP = [];
5137
+ const GF_LOG = [];
5138
+ (function initGF() {
5139
+ let x = 1;
5140
+ for (let i = 0; i < 255; i++) {
5141
+ GF_EXP[i] = x;
5142
+ GF_LOG[x] = i;
5143
+ x = x * 2;
5144
+ if (x >= 256) x ^= 285;
5145
+ }
5146
+ for (let i = 255; i < 512; i++) {
5147
+ GF_EXP[i] = GF_EXP[i - 255];
5148
+ }
5149
+ })();
5150
+ function gfMul(a, b) {
5151
+ if (a === 0 || b === 0) return 0;
5152
+ return GF_EXP[GF_LOG[a] + GF_LOG[b]];
5102
5153
  }
5103
- };
5104
- const setupPositionAdjustPattern = function() {
5105
- const pos = QRUtil.getPatternPosition(_typeNumber);
5106
- for (let i = 0; i < pos.length; i += 1) {
5107
- for (let j = 0; j < pos.length; j += 1) {
5108
- const row = pos[i];
5109
- const col = pos[j];
5110
- if (_modules[row][col] != null) {
5111
- continue;
5154
+ function rsEncode(data, eccCount) {
5155
+ let gen = [1];
5156
+ for (let i = 0; i < eccCount; i++) {
5157
+ const temp = new Array(gen.length + 1).fill(0);
5158
+ for (let j = 0; j < gen.length; j++) {
5159
+ temp[j] ^= gen[j];
5160
+ temp[j + 1] ^= gfMul(gen[j], GF_EXP[i]);
5112
5161
  }
5113
- for (let r = -2; r <= 2; r += 1) {
5114
- for (let c = -2; c <= 2; c += 1) {
5115
- if (r == -2 || r == 2 || c == -2 || c == 2 || r == 0 && c == 0) {
5116
- _modules[row + r][col + c] = true;
5117
- } else {
5118
- _modules[row + r][col + c] = false;
5119
- }
5120
- }
5162
+ gen = temp;
5163
+ }
5164
+ const ecc = new Array(eccCount).fill(0);
5165
+ for (const byte of data) {
5166
+ const factor = byte ^ ecc[0];
5167
+ ecc.shift();
5168
+ ecc.push(0);
5169
+ for (let i = 0; i < eccCount; i++) {
5170
+ ecc[i] ^= gfMul(gen[i], factor);
5121
5171
  }
5122
5172
  }
5173
+ return ecc;
5123
5174
  }
5124
- };
5125
- const setupTypeNumber = function(test) {
5126
- const bits = QRUtil.getBCHTypeNumber(_typeNumber);
5127
- for (let i = 0; i < 18; i += 1) {
5128
- const mod = !test && (bits >> i & 1) == 1;
5129
- _modules[Math.floor(i / 3)][i % 3 + _moduleCount - 8 - 3] = mod;
5130
- }
5131
- for (let i = 0; i < 18; i += 1) {
5132
- const mod = !test && (bits >> i & 1) == 1;
5133
- _modules[i % 3 + _moduleCount - 8 - 3][Math.floor(i / 3)] = mod;
5134
- }
5135
- };
5136
- const setupTypeInfo = function(test, maskPattern) {
5137
- const data = _errorCorrectionLevel << 3 | maskPattern;
5138
- const bits = QRUtil.getBCHTypeInfo(data);
5139
- for (let i = 0; i < 15; i += 1) {
5140
- const mod = !test && (bits >> i & 1) == 1;
5141
- if (i < 6) {
5142
- _modules[i][8] = mod;
5143
- } else if (i < 8) {
5144
- _modules[i + 1][8] = mod;
5145
- } else {
5146
- _modules[_moduleCount - 15 + i][8] = mod;
5147
- }
5148
- }
5149
- for (let i = 0; i < 15; i += 1) {
5150
- const mod = !test && (bits >> i & 1) == 1;
5151
- if (i < 8) {
5152
- _modules[8][_moduleCount - i - 1] = mod;
5153
- } else if (i < 9) {
5154
- _modules[8][15 - i - 1 + 1] = mod;
5155
- } else {
5156
- _modules[8][15 - i - 1] = mod;
5175
+ function getVersion(dataLength, ecl) {
5176
+ const eclIdx = ECL_MAP[ecl] ?? 1;
5177
+ for (let v = 0; v < 40; v++) {
5178
+ if (DATA_CAPACITY[v][eclIdx] >= dataLength) return v + 1;
5157
5179
  }
5180
+ return 40;
5158
5181
  }
5159
- _modules[_moduleCount - 8][8] = !test;
5160
- };
5161
- const mapData = function(data, maskPattern) {
5162
- let inc = -1;
5163
- let row = _moduleCount - 1;
5164
- let bitIndex = 7;
5165
- let byteIndex = 0;
5166
- const maskFunc = QRUtil.getMaskFunction(maskPattern);
5167
- for (let col = _moduleCount - 1; col > 0; col -= 2) {
5168
- if (col == 6) col -= 1;
5169
- while (true) {
5170
- for (let c = 0; c < 2; c += 1) {
5171
- if (_modules[row][col - c] == null) {
5172
- let dark = false;
5173
- if (byteIndex < data.length) {
5174
- dark = (data[byteIndex] >>> bitIndex & 1) == 1;
5175
- }
5176
- const mask = maskFunc(row, col - c);
5177
- if (mask) {
5178
- dark = !dark;
5179
- }
5180
- _modules[row][col - c] = dark;
5181
- bitIndex -= 1;
5182
- if (bitIndex == -1) {
5183
- byteIndex += 1;
5184
- bitIndex = 7;
5182
+ function generateQRCode(data, ecl) {
5183
+ const eclIdx = ECL_MAP[ecl] ?? 1;
5184
+ const version = getVersion(data.length, ecl);
5185
+ const size = version * 4 + 17;
5186
+ const matrix = [];
5187
+ for (let i = 0; i < size; i++) {
5188
+ matrix[i] = new Array(size).fill(-1);
5189
+ }
5190
+ function addFinder(row, col) {
5191
+ for (let r = -1; r <= 7; r++) {
5192
+ for (let c = -1; c <= 7; c++) {
5193
+ const tr = row + r, tc = col + c;
5194
+ if (tr >= 0 && tr < size && tc >= 0 && tc < size) {
5195
+ if (r === -1 || r === 7 || c === -1 || c === 7) {
5196
+ matrix[tr][tc] = 0;
5197
+ } else if (r === 0 || r === 6 || c === 0 || c === 6 || r >= 2 && r <= 4 && c >= 2 && c <= 4) {
5198
+ matrix[tr][tc] = 1;
5199
+ } else {
5200
+ matrix[tr][tc] = 0;
5201
+ }
5185
5202
  }
5186
5203
  }
5187
5204
  }
5188
- row += inc;
5189
- if (row < 0 || _moduleCount <= row) {
5190
- row -= inc;
5191
- inc = -inc;
5192
- break;
5193
- }
5194
- }
5195
- }
5196
- };
5197
- const createBytes = function(buffer, rsBlocks) {
5198
- let offset = 0;
5199
- let maxDcCount = 0;
5200
- let maxEcCount = 0;
5201
- const dcdata = new Array(rsBlocks.length);
5202
- const ecdata = new Array(rsBlocks.length);
5203
- for (let r = 0; r < rsBlocks.length; r += 1) {
5204
- const dcCount = rsBlocks[r].dataCount;
5205
- const ecCount = rsBlocks[r].totalCount - dcCount;
5206
- maxDcCount = Math.max(maxDcCount, dcCount);
5207
- maxEcCount = Math.max(maxEcCount, ecCount);
5208
- dcdata[r] = new Array(dcCount);
5209
- for (let i = 0; i < dcdata[r].length; i += 1) {
5210
- dcdata[r][i] = 255 & buffer.getBuffer()[i + offset];
5211
- }
5212
- offset += dcCount;
5213
- const rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
5214
- const rawPoly = qrPolynomial(dcdata[r], rsPoly.getLength() - 1);
5215
- const modPoly = rawPoly.mod(rsPoly);
5216
- ecdata[r] = new Array(rsPoly.getLength() - 1);
5217
- for (let i = 0; i < ecdata[r].length; i += 1) {
5218
- const modIndex = i + modPoly.getLength() - ecdata[r].length;
5219
- ecdata[r][i] = modIndex >= 0 ? modPoly.getAt(modIndex) : 0;
5220
- }
5221
- }
5222
- let totalCodeCount = 0;
5223
- for (let i = 0; i < rsBlocks.length; i += 1) {
5224
- totalCodeCount += rsBlocks[i].totalCount;
5225
- }
5226
- const data = new Array(totalCodeCount);
5227
- let index = 0;
5228
- for (let i = 0; i < maxDcCount; i += 1) {
5229
- for (let r = 0; r < rsBlocks.length; r += 1) {
5230
- if (i < dcdata[r].length) {
5231
- data[index] = dcdata[r][i];
5232
- index += 1;
5233
- }
5234
5205
  }
5235
- }
5236
- for (let i = 0; i < maxEcCount; i += 1) {
5237
- for (let r = 0; r < rsBlocks.length; r += 1) {
5238
- if (i < ecdata[r].length) {
5239
- data[index] = ecdata[r][i];
5240
- index += 1;
5206
+ addFinder(0, 0);
5207
+ addFinder(size - 7, 0);
5208
+ addFinder(0, size - 7);
5209
+ for (let i = 8; i < size - 8; i++) {
5210
+ matrix[6][i] = i % 2 === 0 ? 1 : 0;
5211
+ matrix[i][6] = i % 2 === 0 ? 1 : 0;
5212
+ }
5213
+ if (version >= 2) {
5214
+ const positions = [6];
5215
+ const step = Math.ceil((size - 13) / (Math.floor(version / 7) + 1));
5216
+ let pos = size - 7;
5217
+ while (pos > 6) {
5218
+ positions.unshift(pos);
5219
+ pos -= step;
5241
5220
  }
5242
- }
5243
- }
5244
- return data;
5245
- };
5246
- const createData = function(typeNumber2, errorCorrectionLevel2, dataList) {
5247
- const rsBlocks = QRRSBlock.getRSBlocks(typeNumber2, errorCorrectionLevel2);
5248
- const buffer = qrBitBuffer();
5249
- for (let i = 0; i < dataList.length; i += 1) {
5250
- const data = dataList[i];
5251
- buffer.put(data.getMode(), 4);
5252
- buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber2));
5253
- data.write(buffer);
5254
- }
5255
- let totalDataCount = 0;
5256
- for (let i = 0; i < rsBlocks.length; i += 1) {
5257
- totalDataCount += rsBlocks[i].dataCount;
5258
- }
5259
- if (buffer.getLengthInBits() > totalDataCount * 8) {
5260
- throw "code length overflow. (" + buffer.getLengthInBits() + ">" + totalDataCount * 8 + ")";
5261
- }
5262
- if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {
5263
- buffer.put(0, 4);
5264
- }
5265
- while (buffer.getLengthInBits() % 8 != 0) {
5266
- buffer.putBit(false);
5267
- }
5268
- while (true) {
5269
- if (buffer.getLengthInBits() >= totalDataCount * 8) {
5270
- break;
5271
- }
5272
- buffer.put(PAD0, 8);
5273
- if (buffer.getLengthInBits() >= totalDataCount * 8) {
5274
- break;
5275
- }
5276
- buffer.put(PAD1, 8);
5277
- }
5278
- return createBytes(buffer, rsBlocks);
5279
- };
5280
- _this.addData = function(data, mode) {
5281
- mode = mode || "Byte";
5282
- let newData = null;
5283
- switch (mode) {
5284
- case "Numeric":
5285
- newData = qrNumber(data);
5286
- break;
5287
- case "Alphanumeric":
5288
- newData = qrAlphaNum(data);
5289
- break;
5290
- case "Byte":
5291
- newData = qr8BitByte(data);
5292
- break;
5293
- case "Kanji":
5294
- newData = qrKanji(data);
5295
- break;
5296
- default:
5297
- throw "mode:" + mode;
5298
- }
5299
- _dataList.push(newData);
5300
- _dataCache = null;
5301
- };
5302
- _this.isDark = function(row, col) {
5303
- if (row < 0 || _moduleCount <= row || col < 0 || _moduleCount <= col) {
5304
- throw row + "," + col;
5305
- }
5306
- return _modules[row][col];
5307
- };
5308
- _this.getModuleCount = function() {
5309
- return _moduleCount;
5310
- };
5311
- _this.make = function() {
5312
- if (_typeNumber < 1) {
5313
- let typeNumber2 = 1;
5314
- for (; typeNumber2 < 40; typeNumber2++) {
5315
- const rsBlocks = QRRSBlock.getRSBlocks(typeNumber2, _errorCorrectionLevel);
5316
- const buffer = qrBitBuffer();
5317
- for (let i = 0; i < _dataList.length; i++) {
5318
- const data = _dataList[i];
5319
- buffer.put(data.getMode(), 4);
5320
- buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber2));
5321
- data.write(buffer);
5322
- }
5323
- let totalDataCount = 0;
5324
- for (let i = 0; i < rsBlocks.length; i++) {
5325
- totalDataCount += rsBlocks[i].dataCount;
5326
- }
5327
- if (buffer.getLengthInBits() <= totalDataCount * 8) {
5328
- break;
5329
- }
5330
- }
5331
- _typeNumber = typeNumber2;
5332
- }
5333
- makeImpl(false, getBestMaskPattern());
5334
- };
5335
- _this.createTableTag = function(cellSize, margin) {
5336
- cellSize = cellSize || 2;
5337
- margin = typeof margin == "undefined" ? cellSize * 4 : margin;
5338
- let qrHtml = "";
5339
- qrHtml += '<table style="';
5340
- qrHtml += " border-width: 0px; border-style: none;";
5341
- qrHtml += " border-collapse: collapse;";
5342
- qrHtml += " padding: 0px; margin: " + margin + "px;";
5343
- qrHtml += '">';
5344
- qrHtml += "<tbody>";
5345
- for (let r = 0; r < _this.getModuleCount(); r += 1) {
5346
- qrHtml += "<tr>";
5347
- for (let c = 0; c < _this.getModuleCount(); c += 1) {
5348
- qrHtml += '<td style="';
5349
- qrHtml += " border-width: 0px; border-style: none;";
5350
- qrHtml += " border-collapse: collapse;";
5351
- qrHtml += " padding: 0px; margin: 0px;";
5352
- qrHtml += " width: " + cellSize + "px;";
5353
- qrHtml += " height: " + cellSize + "px;";
5354
- qrHtml += " background-color: ";
5355
- qrHtml += _this.isDark(r, c) ? "#000000" : "#ffffff";
5356
- qrHtml += ";";
5357
- qrHtml += '"/>';
5358
- }
5359
- qrHtml += "</tr>";
5360
- }
5361
- qrHtml += "</tbody>";
5362
- qrHtml += "</table>";
5363
- return qrHtml;
5364
- };
5365
- _this.createSvgTag = function(cellSize, margin, alt, title) {
5366
- let opts = {};
5367
- if (typeof arguments[0] == "object") {
5368
- opts = arguments[0];
5369
- cellSize = opts.cellSize;
5370
- margin = opts.margin;
5371
- alt = opts.alt;
5372
- title = opts.title;
5373
- }
5374
- cellSize = cellSize || 2;
5375
- margin = typeof margin == "undefined" ? cellSize * 4 : margin;
5376
- alt = typeof alt === "string" ? { text: alt } : alt || {};
5377
- alt.text = alt.text || null;
5378
- alt.id = alt.text ? alt.id || "qrcode-description" : null;
5379
- title = typeof title === "string" ? { text: title } : title || {};
5380
- title.text = title.text || null;
5381
- title.id = title.text ? title.id || "qrcode-title" : null;
5382
- const size = _this.getModuleCount() * cellSize + margin * 2;
5383
- let c, mc, r, mr, qrSvg = "", rect;
5384
- rect = "l" + cellSize + ",0 0," + cellSize + " -" + cellSize + ",0 0,-" + cellSize + "z ";
5385
- qrSvg += '<svg version="1.1" xmlns="http://www.w3.org/2000/svg"';
5386
- qrSvg += !opts.scalable ? ' width="' + size + 'px" height="' + size + 'px"' : "";
5387
- qrSvg += ' viewBox="0 0 ' + size + " " + size + '" ';
5388
- qrSvg += ' preserveAspectRatio="xMinYMin meet"';
5389
- qrSvg += title.text || alt.text ? ' role="img" aria-labelledby="' + escapeXml([title.id, alt.id].join(" ").trim()) + '"' : "";
5390
- qrSvg += ">";
5391
- qrSvg += title.text ? '<title id="' + escapeXml(title.id) + '">' + escapeXml(title.text) + "</title>" : "";
5392
- qrSvg += alt.text ? '<description id="' + escapeXml(alt.id) + '">' + escapeXml(alt.text) + "</description>" : "";
5393
- qrSvg += '<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>';
5394
- qrSvg += '<path d="';
5395
- for (r = 0; r < _this.getModuleCount(); r += 1) {
5396
- mr = r * cellSize + margin;
5397
- for (c = 0; c < _this.getModuleCount(); c += 1) {
5398
- if (_this.isDark(r, c)) {
5399
- mc = c * cellSize + margin;
5400
- qrSvg += "M" + mc + "," + mr + rect;
5401
- }
5402
- }
5403
- }
5404
- qrSvg += '" stroke="transparent" fill="black"/>';
5405
- qrSvg += "</svg>";
5406
- return qrSvg;
5407
- };
5408
- _this.createDataURL = function(cellSize, margin) {
5409
- cellSize = cellSize || 2;
5410
- margin = typeof margin == "undefined" ? cellSize * 4 : margin;
5411
- const size = _this.getModuleCount() * cellSize + margin * 2;
5412
- const min = margin;
5413
- const max = size - margin;
5414
- return createDataURL(size, size, function(x, y) {
5415
- if (min <= x && x < max && min <= y && y < max) {
5416
- const c = Math.floor((x - min) / cellSize);
5417
- const r = Math.floor((y - min) / cellSize);
5418
- return _this.isDark(r, c) ? 0 : 1;
5419
- } else {
5420
- return 1;
5421
- }
5422
- });
5423
- };
5424
- _this.createImgTag = function(cellSize, margin, alt) {
5425
- cellSize = cellSize || 2;
5426
- margin = typeof margin == "undefined" ? cellSize * 4 : margin;
5427
- const size = _this.getModuleCount() * cellSize + margin * 2;
5428
- let img = "";
5429
- img += "<img";
5430
- img += ' src="';
5431
- img += _this.createDataURL(cellSize, margin);
5432
- img += '"';
5433
- img += ' width="';
5434
- img += size;
5435
- img += '"';
5436
- img += ' height="';
5437
- img += size;
5438
- img += '"';
5439
- if (alt) {
5440
- img += ' alt="';
5441
- img += escapeXml(alt);
5442
- img += '"';
5443
- }
5444
- img += "/>";
5445
- return img;
5446
- };
5447
- const escapeXml = function(s) {
5448
- let escaped = "";
5449
- for (let i = 0; i < s.length; i += 1) {
5450
- const c = s.charAt(i);
5451
- switch (c) {
5452
- case "<":
5453
- escaped += "&lt;";
5454
- break;
5455
- case ">":
5456
- escaped += "&gt;";
5457
- break;
5458
- case "&":
5459
- escaped += "&amp;";
5460
- break;
5461
- case '"':
5462
- escaped += "&quot;";
5463
- break;
5464
- default:
5465
- escaped += c;
5466
- break;
5467
- }
5468
- }
5469
- return escaped;
5470
- };
5471
- const _createHalfASCII = function(margin) {
5472
- const cellSize = 1;
5473
- margin = typeof margin == "undefined" ? cellSize * 2 : margin;
5474
- const size = _this.getModuleCount() * cellSize + margin * 2;
5475
- const min = margin;
5476
- const max = size - margin;
5477
- let y, x, r1, r2, p;
5478
- const blocks = {
5479
- "██": "█",
5480
- "█ ": "▀",
5481
- " █": "▄",
5482
- " ": " "
5483
- };
5484
- const blocksLastLineNoMargin = {
5485
- "██": "▀",
5486
- "█ ": "▀",
5487
- " █": " ",
5488
- " ": " "
5489
- };
5490
- let ascii = "";
5491
- for (y = 0; y < size; y += 2) {
5492
- r1 = Math.floor((y - min) / cellSize);
5493
- r2 = Math.floor((y + 1 - min) / cellSize);
5494
- for (x = 0; x < size; x += 1) {
5495
- p = "█";
5496
- if (min <= x && x < max && min <= y && y < max && _this.isDark(r1, Math.floor((x - min) / cellSize))) {
5497
- p = " ";
5498
- }
5499
- if (min <= x && x < max && min <= y + 1 && y + 1 < max && _this.isDark(r2, Math.floor((x - min) / cellSize))) {
5500
- p += " ";
5501
- } else {
5502
- p += "█";
5503
- }
5504
- ascii += margin < 1 && y + 1 >= max ? blocksLastLineNoMargin[p] : blocks[p];
5505
- }
5506
- ascii += "\n";
5507
- }
5508
- if (size % 2 && margin > 0) {
5509
- return ascii.substring(0, ascii.length - size - 1) + Array(size + 1).join("▀");
5510
- }
5511
- return ascii.substring(0, ascii.length - 1);
5512
- };
5513
- _this.createASCII = function(cellSize, margin) {
5514
- cellSize = cellSize || 1;
5515
- if (cellSize < 2) {
5516
- return _createHalfASCII(margin);
5517
- }
5518
- cellSize -= 1;
5519
- margin = typeof margin == "undefined" ? cellSize * 2 : margin;
5520
- const size = _this.getModuleCount() * cellSize + margin * 2;
5521
- const min = margin;
5522
- const max = size - margin;
5523
- let y, x, r, p;
5524
- const white = Array(cellSize + 1).join("██");
5525
- const black = Array(cellSize + 1).join(" ");
5526
- let ascii = "";
5527
- let line = "";
5528
- for (y = 0; y < size; y += 1) {
5529
- r = Math.floor((y - min) / cellSize);
5530
- line = "";
5531
- for (x = 0; x < size; x += 1) {
5532
- p = 1;
5533
- if (min <= x && x < max && min <= y && y < max && _this.isDark(r, Math.floor((x - min) / cellSize))) {
5534
- p = 0;
5535
- }
5536
- line += p ? white : black;
5537
- }
5538
- for (r = 0; r < cellSize; r += 1) {
5539
- ascii += line + "\n";
5540
- }
5541
- }
5542
- return ascii.substring(0, ascii.length - 1);
5543
- };
5544
- _this.renderTo2dContext = function(context, cellSize) {
5545
- cellSize = cellSize || 2;
5546
- const length = _this.getModuleCount();
5547
- for (let row = 0; row < length; row++) {
5548
- for (let col = 0; col < length; col++) {
5549
- context.fillStyle = _this.isDark(row, col) ? "black" : "white";
5550
- context.fillRect(col * cellSize, row * cellSize, cellSize, cellSize);
5551
- }
5552
- }
5553
- };
5554
- return _this;
5555
- };
5556
- qrcode.stringToBytes = function(s) {
5557
- const bytes = [];
5558
- for (let i = 0; i < s.length; i += 1) {
5559
- const c = s.charCodeAt(i);
5560
- bytes.push(c & 255);
5561
- }
5562
- return bytes;
5563
- };
5564
- qrcode.createStringToBytes = function(unicodeData, numChars) {
5565
- const unicodeMap = function() {
5566
- const bin = base64DecodeInputStream(unicodeData);
5567
- const read = function() {
5568
- const b = bin.read();
5569
- if (b == -1) throw "eof";
5570
- return b;
5571
- };
5572
- let count = 0;
5573
- const unicodeMap2 = {};
5574
- while (true) {
5575
- const b0 = bin.read();
5576
- if (b0 == -1) break;
5577
- const b1 = read();
5578
- const b2 = read();
5579
- const b3 = read();
5580
- const k = String.fromCharCode(b0 << 8 | b1);
5581
- const v = b2 << 8 | b3;
5582
- unicodeMap2[k] = v;
5583
- count += 1;
5584
- }
5585
- if (count != numChars) {
5586
- throw count + " != " + numChars;
5587
- }
5588
- return unicodeMap2;
5589
- }();
5590
- const unknownChar = "?".charCodeAt(0);
5591
- return function(s) {
5592
- const bytes = [];
5593
- for (let i = 0; i < s.length; i += 1) {
5594
- const c = s.charCodeAt(i);
5595
- if (c < 128) {
5596
- bytes.push(c);
5597
- } else {
5598
- const b = unicodeMap[s.charAt(i)];
5599
- if (typeof b == "number") {
5600
- if ((b & 255) == b) {
5601
- bytes.push(b);
5602
- } else {
5603
- bytes.push(b >>> 8);
5604
- bytes.push(b & 255);
5605
- }
5606
- } else {
5607
- bytes.push(unknownChar);
5608
- }
5609
- }
5610
- }
5611
- return bytes;
5612
- };
5613
- };
5614
- const QRMode = {
5615
- MODE_NUMBER: 1 << 0,
5616
- MODE_ALPHA_NUM: 1 << 1,
5617
- MODE_8BIT_BYTE: 1 << 2,
5618
- MODE_KANJI: 1 << 3
5619
- };
5620
- const QRErrorCorrectionLevel = {
5621
- L: 1,
5622
- M: 0,
5623
- Q: 3,
5624
- H: 2
5625
- };
5626
- const QRMaskPattern = {
5627
- PATTERN000: 0,
5628
- PATTERN001: 1,
5629
- PATTERN010: 2,
5630
- PATTERN011: 3,
5631
- PATTERN100: 4,
5632
- PATTERN101: 5,
5633
- PATTERN110: 6,
5634
- PATTERN111: 7
5635
- };
5636
- const QRUtil = function() {
5637
- const PATTERN_POSITION_TABLE = [
5638
- [],
5639
- [6, 18],
5640
- [6, 22],
5641
- [6, 26],
5642
- [6, 30],
5643
- [6, 34],
5644
- [6, 22, 38],
5645
- [6, 24, 42],
5646
- [6, 26, 46],
5647
- [6, 28, 50],
5648
- [6, 30, 54],
5649
- [6, 32, 58],
5650
- [6, 34, 62],
5651
- [6, 26, 46, 66],
5652
- [6, 26, 48, 70],
5653
- [6, 26, 50, 74],
5654
- [6, 30, 54, 78],
5655
- [6, 30, 56, 82],
5656
- [6, 30, 58, 86],
5657
- [6, 34, 62, 90],
5658
- [6, 28, 50, 72, 94],
5659
- [6, 26, 50, 74, 98],
5660
- [6, 30, 54, 78, 102],
5661
- [6, 28, 54, 80, 106],
5662
- [6, 32, 58, 84, 110],
5663
- [6, 30, 58, 86, 114],
5664
- [6, 34, 62, 90, 118],
5665
- [6, 26, 50, 74, 98, 122],
5666
- [6, 30, 54, 78, 102, 126],
5667
- [6, 26, 52, 78, 104, 130],
5668
- [6, 30, 56, 82, 108, 134],
5669
- [6, 34, 60, 86, 112, 138],
5670
- [6, 30, 58, 86, 114, 142],
5671
- [6, 34, 62, 90, 118, 146],
5672
- [6, 30, 54, 78, 102, 126, 150],
5673
- [6, 24, 50, 76, 102, 128, 154],
5674
- [6, 28, 54, 80, 106, 132, 158],
5675
- [6, 32, 58, 84, 110, 136, 162],
5676
- [6, 26, 54, 82, 110, 138, 166],
5677
- [6, 30, 58, 86, 114, 142, 170]
5678
- ];
5679
- const G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;
5680
- const G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0;
5681
- const G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
5682
- const _this = {};
5683
- const getBCHDigit = function(data) {
5684
- let digit = 0;
5685
- while (data != 0) {
5686
- digit += 1;
5687
- data >>>= 1;
5688
- }
5689
- return digit;
5690
- };
5691
- _this.getBCHTypeInfo = function(data) {
5692
- let d = data << 10;
5693
- while (getBCHDigit(d) - getBCHDigit(G15) >= 0) {
5694
- d ^= G15 << getBCHDigit(d) - getBCHDigit(G15);
5695
- }
5696
- return (data << 10 | d) ^ G15_MASK;
5697
- };
5698
- _this.getBCHTypeNumber = function(data) {
5699
- let d = data << 12;
5700
- while (getBCHDigit(d) - getBCHDigit(G18) >= 0) {
5701
- d ^= G18 << getBCHDigit(d) - getBCHDigit(G18);
5702
- }
5703
- return data << 12 | d;
5704
- };
5705
- _this.getPatternPosition = function(typeNumber) {
5706
- return PATTERN_POSITION_TABLE[typeNumber - 1];
5707
- };
5708
- _this.getMaskFunction = function(maskPattern) {
5709
- switch (maskPattern) {
5710
- case QRMaskPattern.PATTERN000:
5711
- return function(i, j) {
5712
- return (i + j) % 2 == 0;
5713
- };
5714
- case QRMaskPattern.PATTERN001:
5715
- return function(i, j) {
5716
- return i % 2 == 0;
5717
- };
5718
- case QRMaskPattern.PATTERN010:
5719
- return function(i, j) {
5720
- return j % 3 == 0;
5721
- };
5722
- case QRMaskPattern.PATTERN011:
5723
- return function(i, j) {
5724
- return (i + j) % 3 == 0;
5725
- };
5726
- case QRMaskPattern.PATTERN100:
5727
- return function(i, j) {
5728
- return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0;
5729
- };
5730
- case QRMaskPattern.PATTERN101:
5731
- return function(i, j) {
5732
- return i * j % 2 + i * j % 3 == 0;
5733
- };
5734
- case QRMaskPattern.PATTERN110:
5735
- return function(i, j) {
5736
- return (i * j % 2 + i * j % 3) % 2 == 0;
5737
- };
5738
- case QRMaskPattern.PATTERN111:
5739
- return function(i, j) {
5740
- return (i * j % 3 + (i + j) % 2) % 2 == 0;
5741
- };
5742
- default:
5743
- throw "bad maskPattern:" + maskPattern;
5744
- }
5745
- };
5746
- _this.getErrorCorrectPolynomial = function(errorCorrectLength) {
5747
- let a = qrPolynomial([1], 0);
5748
- for (let i = 0; i < errorCorrectLength; i += 1) {
5749
- a = a.multiply(qrPolynomial([1, QRMath.gexp(i)], 0));
5750
- }
5751
- return a;
5752
- };
5753
- _this.getLengthInBits = function(mode, type) {
5754
- if (1 <= type && type < 10) {
5755
- switch (mode) {
5756
- case QRMode.MODE_NUMBER:
5757
- return 10;
5758
- case QRMode.MODE_ALPHA_NUM:
5759
- return 9;
5760
- case QRMode.MODE_8BIT_BYTE:
5761
- return 8;
5762
- case QRMode.MODE_KANJI:
5763
- return 8;
5764
- default:
5765
- throw "mode:" + mode;
5766
- }
5767
- } else if (type < 27) {
5768
- switch (mode) {
5769
- case QRMode.MODE_NUMBER:
5770
- return 12;
5771
- case QRMode.MODE_ALPHA_NUM:
5772
- return 11;
5773
- case QRMode.MODE_8BIT_BYTE:
5774
- return 16;
5775
- case QRMode.MODE_KANJI:
5776
- return 10;
5777
- default:
5778
- throw "mode:" + mode;
5779
- }
5780
- } else if (type < 41) {
5781
- switch (mode) {
5782
- case QRMode.MODE_NUMBER:
5783
- return 14;
5784
- case QRMode.MODE_ALPHA_NUM:
5785
- return 13;
5786
- case QRMode.MODE_8BIT_BYTE:
5787
- return 16;
5788
- case QRMode.MODE_KANJI:
5789
- return 12;
5790
- default:
5791
- throw "mode:" + mode;
5792
- }
5793
- } else {
5794
- throw "type:" + type;
5795
- }
5796
- };
5797
- _this.getLostPoint = function(qrcode2) {
5798
- const moduleCount = qrcode2.getModuleCount();
5799
- let lostPoint = 0;
5800
- for (let row = 0; row < moduleCount; row += 1) {
5801
- for (let col = 0; col < moduleCount; col += 1) {
5802
- let sameCount = 0;
5803
- const dark = qrcode2.isDark(row, col);
5804
- for (let r = -1; r <= 1; r += 1) {
5805
- if (row + r < 0 || moduleCount <= row + r) {
5806
- continue;
5807
- }
5808
- for (let c = -1; c <= 1; c += 1) {
5809
- if (col + c < 0 || moduleCount <= col + c) {
5810
- continue;
5811
- }
5812
- if (r == 0 && c == 0) {
5813
- continue;
5814
- }
5815
- if (dark == qrcode2.isDark(row + r, col + c)) {
5816
- sameCount += 1;
5221
+ for (const row of positions) {
5222
+ for (const col of positions) {
5223
+ if (matrix[row][col] !== -1) continue;
5224
+ for (let r = -2; r <= 2; r++) {
5225
+ for (let c = -2; c <= 2; c++) {
5226
+ const tr = row + r, tc = col + c;
5227
+ if (tr >= 0 && tr < size && tc >= 0 && tc < size && matrix[tr][tc] === -1) {
5228
+ matrix[tr][tc] = Math.abs(r) === 2 || Math.abs(c) === 2 || r === 0 && c === 0 ? 1 : 0;
5229
+ }
5230
+ }
5817
5231
  }
5818
5232
  }
5819
5233
  }
5820
- if (sameCount > 5) {
5821
- lostPoint += 3 + sameCount - 5;
5822
- }
5823
5234
  }
5824
- }
5825
- for (let row = 0; row < moduleCount - 1; row += 1) {
5826
- for (let col = 0; col < moduleCount - 1; col += 1) {
5827
- let count = 0;
5828
- if (qrcode2.isDark(row, col)) count += 1;
5829
- if (qrcode2.isDark(row + 1, col)) count += 1;
5830
- if (qrcode2.isDark(row, col + 1)) count += 1;
5831
- if (qrcode2.isDark(row + 1, col + 1)) count += 1;
5832
- if (count == 0 || count == 4) {
5833
- lostPoint += 3;
5235
+ matrix[size - 8][8] = 1;
5236
+ for (let i = 0; i < 9; i++) {
5237
+ if (matrix[8][i] === -1) matrix[8][i] = 0;
5238
+ if (matrix[i][8] === -1) matrix[i][8] = 0;
5239
+ }
5240
+ for (let i = 0; i < 8; i++) {
5241
+ if (matrix[8][size - 1 - i] === -1) matrix[8][size - 1 - i] = 0;
5242
+ if (matrix[size - 1 - i][8] === -1) matrix[size - 1 - i][8] = 0;
5243
+ }
5244
+ const eccCount = ECC_CODEWORDS[version - 1][eclIdx];
5245
+ const dataCapacity = DATA_CAPACITY[version - 1][eclIdx];
5246
+ const bits = [];
5247
+ bits.push(0, 1, 0, 0);
5248
+ const cciBits = version <= 9 ? 8 : 16;
5249
+ for (let i = cciBits - 1; i >= 0; i--) {
5250
+ bits.push(data.length >> i & 1);
5251
+ }
5252
+ for (const char of data) {
5253
+ const code2 = char.charCodeAt(0);
5254
+ for (let i = 7; i >= 0; i--) {
5255
+ bits.push(code2 >> i & 1);
5834
5256
  }
5835
5257
  }
5836
- }
5837
- for (let row = 0; row < moduleCount; row += 1) {
5838
- for (let col = 0; col < moduleCount - 6; col += 1) {
5839
- if (qrcode2.isDark(row, col) && !qrcode2.isDark(row, col + 1) && qrcode2.isDark(row, col + 2) && qrcode2.isDark(row, col + 3) && qrcode2.isDark(row, col + 4) && !qrcode2.isDark(row, col + 5) && qrcode2.isDark(row, col + 6)) {
5840
- lostPoint += 40;
5258
+ const termLen = Math.min(4, dataCapacity * 8 - bits.length);
5259
+ for (let i = 0; i < termLen; i++) bits.push(0);
5260
+ while (bits.length % 8 !== 0) bits.push(0);
5261
+ const padBytes = [236, 17];
5262
+ let padIdx = 0;
5263
+ while (bits.length < dataCapacity * 8) {
5264
+ for (let i = 7; i >= 0; i--) {
5265
+ bits.push(padBytes[padIdx] >> i & 1);
5841
5266
  }
5842
- }
5843
- }
5844
- for (let col = 0; col < moduleCount; col += 1) {
5845
- for (let row = 0; row < moduleCount - 6; row += 1) {
5846
- if (qrcode2.isDark(row, col) && !qrcode2.isDark(row + 1, col) && qrcode2.isDark(row + 2, col) && qrcode2.isDark(row + 3, col) && qrcode2.isDark(row + 4, col) && !qrcode2.isDark(row + 5, col) && qrcode2.isDark(row + 6, col)) {
5847
- lostPoint += 40;
5267
+ padIdx = (padIdx + 1) % 2;
5268
+ }
5269
+ const dataBytes = [];
5270
+ for (let i = 0; i < bits.length; i += 8) {
5271
+ let b = 0;
5272
+ for (let j = 0; j < 8; j++) b = b << 1 | (bits[i + j] || 0);
5273
+ dataBytes.push(b);
5274
+ }
5275
+ const eccBytes = rsEncode(dataBytes, eccCount);
5276
+ const codewords = [...dataBytes, ...eccBytes];
5277
+ let bitIdx = 0;
5278
+ let upward = true;
5279
+ for (let col = size - 1; col >= 0; col -= 2) {
5280
+ if (col === 6) col = 5;
5281
+ for (let row = upward ? size - 1 : 0; upward ? row >= 0 : row < size; upward ? row-- : row++) {
5282
+ for (let c = 0; c < 2; c++) {
5283
+ const tc = col - c;
5284
+ if (tc >= 0 && matrix[row][tc] === -1) {
5285
+ let bit = 0;
5286
+ if (bitIdx < codewords.length * 8) {
5287
+ bit = codewords[Math.floor(bitIdx / 8)] >> 7 - bitIdx % 8 & 1;
5288
+ }
5289
+ matrix[row][tc] = bit;
5290
+ bitIdx++;
5291
+ }
5292
+ }
5848
5293
  }
5294
+ upward = !upward;
5849
5295
  }
5850
- }
5851
- let darkCount = 0;
5852
- for (let col = 0; col < moduleCount; col += 1) {
5853
- for (let row = 0; row < moduleCount; row += 1) {
5854
- if (qrcode2.isDark(row, col)) {
5855
- darkCount += 1;
5296
+ for (let row = 0; row < size; row++) {
5297
+ for (let col = 0; col < size; col++) {
5298
+ if (matrix[row][col] >= 0 && (row + col) % 2 === 0) {
5299
+ matrix[row][col] = matrix[row][col] === 1 ? 0 : 1;
5300
+ }
5856
5301
  }
5857
5302
  }
5858
- }
5859
- const ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
5860
- lostPoint += ratio * 10;
5861
- return lostPoint;
5862
- };
5863
- return _this;
5864
- }();
5865
- const QRMath = function() {
5866
- const EXP_TABLE = new Array(256);
5867
- const LOG_TABLE = new Array(256);
5868
- for (let i = 0; i < 8; i += 1) {
5869
- EXP_TABLE[i] = 1 << i;
5870
- }
5871
- for (let i = 8; i < 256; i += 1) {
5872
- EXP_TABLE[i] = EXP_TABLE[i - 4] ^ EXP_TABLE[i - 5] ^ EXP_TABLE[i - 6] ^ EXP_TABLE[i - 8];
5873
- }
5874
- for (let i = 0; i < 255; i += 1) {
5875
- LOG_TABLE[EXP_TABLE[i]] = i;
5876
- }
5877
- const _this = {};
5878
- _this.glog = function(n) {
5879
- if (n < 1) {
5880
- throw "glog(" + n + ")";
5881
- }
5882
- return LOG_TABLE[n];
5883
- };
5884
- _this.gexp = function(n) {
5885
- while (n < 0) {
5886
- n += 255;
5887
- }
5888
- while (n >= 256) {
5889
- n -= 255;
5890
- }
5891
- return EXP_TABLE[n];
5892
- };
5893
- return _this;
5894
- }();
5895
- const qrPolynomial = function(num, shift) {
5896
- if (typeof num.length == "undefined") {
5897
- throw num.length + "/" + shift;
5898
- }
5899
- const _num = function() {
5900
- let offset = 0;
5901
- while (offset < num.length && num[offset] == 0) {
5902
- offset += 1;
5903
- }
5904
- const _num2 = new Array(num.length - offset + shift);
5905
- for (let i = 0; i < num.length - offset; i += 1) {
5906
- _num2[i] = num[i + offset];
5907
- }
5908
- return _num2;
5909
- }();
5910
- const _this = {};
5911
- _this.getAt = function(index) {
5912
- return _num[index];
5913
- };
5914
- _this.getLength = function() {
5915
- return _num.length;
5916
- };
5917
- _this.multiply = function(e) {
5918
- const num2 = new Array(_this.getLength() + e.getLength() - 1);
5919
- for (let i = 0; i < _this.getLength(); i += 1) {
5920
- for (let j = 0; j < e.getLength(); j += 1) {
5921
- num2[i + j] ^= QRMath.gexp(QRMath.glog(_this.getAt(i)) + QRMath.glog(e.getAt(j)));
5922
- }
5923
- }
5924
- return qrPolynomial(num2, 0);
5925
- };
5926
- _this.mod = function(e) {
5927
- if (_this.getLength() - e.getLength() < 0) {
5928
- return _this;
5929
- }
5930
- const ratio = QRMath.glog(_this.getAt(0)) - QRMath.glog(e.getAt(0));
5931
- const num2 = new Array(_this.getLength());
5932
- for (let i = 0; i < _this.getLength(); i += 1) {
5933
- num2[i] = _this.getAt(i);
5934
- }
5935
- for (let i = 0; i < e.getLength(); i += 1) {
5936
- num2[i] ^= QRMath.gexp(QRMath.glog(e.getAt(i)) + ratio);
5937
- }
5938
- return qrPolynomial(num2, 0).mod(e);
5939
- };
5940
- return _this;
5941
- };
5942
- const QRRSBlock = function() {
5943
- const RS_BLOCK_TABLE = [
5944
- // L
5945
- // M
5946
- // Q
5947
- // H
5948
- // 1
5949
- [1, 26, 19],
5950
- [1, 26, 16],
5951
- [1, 26, 13],
5952
- [1, 26, 9],
5953
- // 2
5954
- [1, 44, 34],
5955
- [1, 44, 28],
5956
- [1, 44, 22],
5957
- [1, 44, 16],
5958
- // 3
5959
- [1, 70, 55],
5960
- [1, 70, 44],
5961
- [2, 35, 17],
5962
- [2, 35, 13],
5963
- // 4
5964
- [1, 100, 80],
5965
- [2, 50, 32],
5966
- [2, 50, 24],
5967
- [4, 25, 9],
5968
- // 5
5969
- [1, 134, 108],
5970
- [2, 67, 43],
5971
- [2, 33, 15, 2, 34, 16],
5972
- [2, 33, 11, 2, 34, 12],
5973
- // 6
5974
- [2, 86, 68],
5975
- [4, 43, 27],
5976
- [4, 43, 19],
5977
- [4, 43, 15],
5978
- // 7
5979
- [2, 98, 78],
5980
- [4, 49, 31],
5981
- [2, 32, 14, 4, 33, 15],
5982
- [4, 39, 13, 1, 40, 14],
5983
- // 8
5984
- [2, 121, 97],
5985
- [2, 60, 38, 2, 61, 39],
5986
- [4, 40, 18, 2, 41, 19],
5987
- [4, 40, 14, 2, 41, 15],
5988
- // 9
5989
- [2, 146, 116],
5990
- [3, 58, 36, 2, 59, 37],
5991
- [4, 36, 16, 4, 37, 17],
5992
- [4, 36, 12, 4, 37, 13],
5993
- // 10
5994
- [2, 86, 68, 2, 87, 69],
5995
- [4, 69, 43, 1, 70, 44],
5996
- [6, 43, 19, 2, 44, 20],
5997
- [6, 43, 15, 2, 44, 16],
5998
- // 11
5999
- [4, 101, 81],
6000
- [1, 80, 50, 4, 81, 51],
6001
- [4, 50, 22, 4, 51, 23],
6002
- [3, 36, 12, 8, 37, 13],
6003
- // 12
6004
- [2, 116, 92, 2, 117, 93],
6005
- [6, 58, 36, 2, 59, 37],
6006
- [4, 46, 20, 6, 47, 21],
6007
- [7, 42, 14, 4, 43, 15],
6008
- // 13
6009
- [4, 133, 107],
6010
- [8, 59, 37, 1, 60, 38],
6011
- [8, 44, 20, 4, 45, 21],
6012
- [12, 33, 11, 4, 34, 12],
6013
- // 14
6014
- [3, 145, 115, 1, 146, 116],
6015
- [4, 64, 40, 5, 65, 41],
6016
- [11, 36, 16, 5, 37, 17],
6017
- [11, 36, 12, 5, 37, 13],
6018
- // 15
6019
- [5, 109, 87, 1, 110, 88],
6020
- [5, 65, 41, 5, 66, 42],
6021
- [5, 54, 24, 7, 55, 25],
6022
- [11, 36, 12, 7, 37, 13],
6023
- // 16
6024
- [5, 122, 98, 1, 123, 99],
6025
- [7, 73, 45, 3, 74, 46],
6026
- [15, 43, 19, 2, 44, 20],
6027
- [3, 45, 15, 13, 46, 16],
6028
- // 17
6029
- [1, 135, 107, 5, 136, 108],
6030
- [10, 74, 46, 1, 75, 47],
6031
- [1, 50, 22, 15, 51, 23],
6032
- [2, 42, 14, 17, 43, 15],
6033
- // 18
6034
- [5, 150, 120, 1, 151, 121],
6035
- [9, 69, 43, 4, 70, 44],
6036
- [17, 50, 22, 1, 51, 23],
6037
- [2, 42, 14, 19, 43, 15],
6038
- // 19
6039
- [3, 141, 113, 4, 142, 114],
6040
- [3, 70, 44, 11, 71, 45],
6041
- [17, 47, 21, 4, 48, 22],
6042
- [9, 39, 13, 16, 40, 14],
6043
- // 20
6044
- [3, 135, 107, 5, 136, 108],
6045
- [3, 67, 41, 13, 68, 42],
6046
- [15, 54, 24, 5, 55, 25],
6047
- [15, 43, 15, 10, 44, 16],
6048
- // 21
6049
- [4, 144, 116, 4, 145, 117],
6050
- [17, 68, 42],
6051
- [17, 50, 22, 6, 51, 23],
6052
- [19, 46, 16, 6, 47, 17],
6053
- // 22
6054
- [2, 139, 111, 7, 140, 112],
6055
- [17, 74, 46],
6056
- [7, 54, 24, 16, 55, 25],
6057
- [34, 37, 13],
6058
- // 23
6059
- [4, 151, 121, 5, 152, 122],
6060
- [4, 75, 47, 14, 76, 48],
6061
- [11, 54, 24, 14, 55, 25],
6062
- [16, 45, 15, 14, 46, 16],
6063
- // 24
6064
- [6, 147, 117, 4, 148, 118],
6065
- [6, 73, 45, 14, 74, 46],
6066
- [11, 54, 24, 16, 55, 25],
6067
- [30, 46, 16, 2, 47, 17],
6068
- // 25
6069
- [8, 132, 106, 4, 133, 107],
6070
- [8, 75, 47, 13, 76, 48],
6071
- [7, 54, 24, 22, 55, 25],
6072
- [22, 45, 15, 13, 46, 16],
6073
- // 26
6074
- [10, 142, 114, 2, 143, 115],
6075
- [19, 74, 46, 4, 75, 47],
6076
- [28, 50, 22, 6, 51, 23],
6077
- [33, 46, 16, 4, 47, 17],
6078
- // 27
6079
- [8, 152, 122, 4, 153, 123],
6080
- [22, 73, 45, 3, 74, 46],
6081
- [8, 53, 23, 26, 54, 24],
6082
- [12, 45, 15, 28, 46, 16],
6083
- // 28
6084
- [3, 147, 117, 10, 148, 118],
6085
- [3, 73, 45, 23, 74, 46],
6086
- [4, 54, 24, 31, 55, 25],
6087
- [11, 45, 15, 31, 46, 16],
6088
- // 29
6089
- [7, 146, 116, 7, 147, 117],
6090
- [21, 73, 45, 7, 74, 46],
6091
- [1, 53, 23, 37, 54, 24],
6092
- [19, 45, 15, 26, 46, 16],
6093
- // 30
6094
- [5, 145, 115, 10, 146, 116],
6095
- [19, 75, 47, 10, 76, 48],
6096
- [15, 54, 24, 25, 55, 25],
6097
- [23, 45, 15, 25, 46, 16],
6098
- // 31
6099
- [13, 145, 115, 3, 146, 116],
6100
- [2, 74, 46, 29, 75, 47],
6101
- [42, 54, 24, 1, 55, 25],
6102
- [23, 45, 15, 28, 46, 16],
6103
- // 32
6104
- [17, 145, 115],
6105
- [10, 74, 46, 23, 75, 47],
6106
- [10, 54, 24, 35, 55, 25],
6107
- [19, 45, 15, 35, 46, 16],
6108
- // 33
6109
- [17, 145, 115, 1, 146, 116],
6110
- [14, 74, 46, 21, 75, 47],
6111
- [29, 54, 24, 19, 55, 25],
6112
- [11, 45, 15, 46, 46, 16],
6113
- // 34
6114
- [13, 145, 115, 6, 146, 116],
6115
- [14, 74, 46, 23, 75, 47],
6116
- [44, 54, 24, 7, 55, 25],
6117
- [59, 46, 16, 1, 47, 17],
6118
- // 35
6119
- [12, 151, 121, 7, 152, 122],
6120
- [12, 75, 47, 26, 76, 48],
6121
- [39, 54, 24, 14, 55, 25],
6122
- [22, 45, 15, 41, 46, 16],
6123
- // 36
6124
- [6, 151, 121, 14, 152, 122],
6125
- [6, 75, 47, 34, 76, 48],
6126
- [46, 54, 24, 10, 55, 25],
6127
- [2, 45, 15, 64, 46, 16],
6128
- // 37
6129
- [17, 152, 122, 4, 153, 123],
6130
- [29, 74, 46, 14, 75, 47],
6131
- [49, 54, 24, 10, 55, 25],
6132
- [24, 45, 15, 46, 46, 16],
6133
- // 38
6134
- [4, 152, 122, 18, 153, 123],
6135
- [13, 74, 46, 32, 75, 47],
6136
- [48, 54, 24, 14, 55, 25],
6137
- [42, 45, 15, 32, 46, 16],
6138
- // 39
6139
- [20, 147, 117, 4, 148, 118],
6140
- [40, 75, 47, 7, 76, 48],
6141
- [43, 54, 24, 22, 55, 25],
6142
- [10, 45, 15, 67, 46, 16],
6143
- // 40
6144
- [19, 148, 118, 6, 149, 119],
6145
- [18, 75, 47, 31, 76, 48],
6146
- [34, 54, 24, 34, 55, 25],
6147
- [20, 45, 15, 61, 46, 16]
6148
- ];
6149
- const qrRSBlock = function(totalCount, dataCount) {
6150
- const _this2 = {};
6151
- _this2.totalCount = totalCount;
6152
- _this2.dataCount = dataCount;
6153
- return _this2;
6154
- };
6155
- const _this = {};
6156
- const getRsBlockTable = function(typeNumber, errorCorrectionLevel) {
6157
- switch (errorCorrectionLevel) {
6158
- case QRErrorCorrectionLevel.L:
6159
- return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
6160
- case QRErrorCorrectionLevel.M:
6161
- return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
6162
- case QRErrorCorrectionLevel.Q:
6163
- return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
6164
- case QRErrorCorrectionLevel.H:
6165
- return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
6166
- default:
6167
- return void 0;
6168
- }
6169
- };
6170
- _this.getRSBlocks = function(typeNumber, errorCorrectionLevel) {
6171
- const rsBlock = getRsBlockTable(typeNumber, errorCorrectionLevel);
6172
- if (typeof rsBlock == "undefined") {
6173
- throw "bad rs block @ typeNumber:" + typeNumber + "/errorCorrectionLevel:" + errorCorrectionLevel;
6174
- }
6175
- const length = rsBlock.length / 3;
6176
- const list2 = [];
6177
- for (let i = 0; i < length; i += 1) {
6178
- const count = rsBlock[i * 3 + 0];
6179
- const totalCount = rsBlock[i * 3 + 1];
6180
- const dataCount = rsBlock[i * 3 + 2];
6181
- for (let j = 0; j < count; j += 1) {
6182
- list2.push(qrRSBlock(totalCount, dataCount));
6183
- }
6184
- }
6185
- return list2;
6186
- };
6187
- return _this;
6188
- }();
6189
- const qrBitBuffer = function() {
6190
- const _buffer = [];
6191
- let _length = 0;
6192
- const _this = {};
6193
- _this.getBuffer = function() {
6194
- return _buffer;
6195
- };
6196
- _this.getAt = function(index) {
6197
- const bufIndex = Math.floor(index / 8);
6198
- return (_buffer[bufIndex] >>> 7 - index % 8 & 1) == 1;
6199
- };
6200
- _this.put = function(num, length) {
6201
- for (let i = 0; i < length; i += 1) {
6202
- _this.putBit((num >>> length - i - 1 & 1) == 1);
6203
- }
6204
- };
6205
- _this.getLengthInBits = function() {
6206
- return _length;
6207
- };
6208
- _this.putBit = function(bit) {
6209
- const bufIndex = Math.floor(_length / 8);
6210
- if (_buffer.length <= bufIndex) {
6211
- _buffer.push(0);
6212
- }
6213
- if (bit) {
6214
- _buffer[bufIndex] |= 128 >>> _length % 8;
6215
- }
6216
- _length += 1;
6217
- };
6218
- return _this;
6219
- };
6220
- const qrNumber = function(data) {
6221
- const _mode = QRMode.MODE_NUMBER;
6222
- const _data = data;
6223
- const _this = {};
6224
- _this.getMode = function() {
6225
- return _mode;
6226
- };
6227
- _this.getLength = function(buffer) {
6228
- return _data.length;
6229
- };
6230
- _this.write = function(buffer) {
6231
- const data2 = _data;
6232
- let i = 0;
6233
- while (i + 2 < data2.length) {
6234
- buffer.put(strToNum(data2.substring(i, i + 3)), 10);
6235
- i += 3;
6236
- }
6237
- if (i < data2.length) {
6238
- if (data2.length - i == 1) {
6239
- buffer.put(strToNum(data2.substring(i, i + 1)), 4);
6240
- } else if (data2.length - i == 2) {
6241
- buffer.put(strToNum(data2.substring(i, i + 2)), 7);
6242
- }
6243
- }
6244
- };
6245
- const strToNum = function(s) {
6246
- let num = 0;
6247
- for (let i = 0; i < s.length; i += 1) {
6248
- num = num * 10 + chatToNum(s.charAt(i));
6249
- }
6250
- return num;
6251
- };
6252
- const chatToNum = function(c) {
6253
- if ("0" <= c && c <= "9") {
6254
- return c.charCodeAt(0) - "0".charCodeAt(0);
6255
- }
6256
- throw "illegal char :" + c;
6257
- };
6258
- return _this;
6259
- };
6260
- const qrAlphaNum = function(data) {
6261
- const _mode = QRMode.MODE_ALPHA_NUM;
6262
- const _data = data;
6263
- const _this = {};
6264
- _this.getMode = function() {
6265
- return _mode;
6266
- };
6267
- _this.getLength = function(buffer) {
6268
- return _data.length;
6269
- };
6270
- _this.write = function(buffer) {
6271
- const s = _data;
6272
- let i = 0;
6273
- while (i + 1 < s.length) {
6274
- buffer.put(
6275
- getCode(s.charAt(i)) * 45 + getCode(s.charAt(i + 1)),
6276
- 11
6277
- );
6278
- i += 2;
6279
- }
6280
- if (i < s.length) {
6281
- buffer.put(getCode(s.charAt(i)), 6);
6282
- }
6283
- };
6284
- const getCode = function(c) {
6285
- if ("0" <= c && c <= "9") {
6286
- return c.charCodeAt(0) - "0".charCodeAt(0);
6287
- } else if ("A" <= c && c <= "Z") {
6288
- return c.charCodeAt(0) - "A".charCodeAt(0) + 10;
6289
- } else {
6290
- switch (c) {
6291
- case " ":
6292
- return 36;
6293
- case "$":
6294
- return 37;
6295
- case "%":
6296
- return 38;
6297
- case "*":
6298
- return 39;
6299
- case "+":
6300
- return 40;
6301
- case "-":
6302
- return 41;
6303
- case ".":
6304
- return 42;
6305
- case "/":
6306
- return 43;
6307
- case ":":
6308
- return 44;
6309
- default:
6310
- throw "illegal char :" + c;
6311
- }
6312
- }
6313
- };
6314
- return _this;
6315
- };
6316
- const qr8BitByte = function(data) {
6317
- const _mode = QRMode.MODE_8BIT_BYTE;
6318
- const _bytes = qrcode.stringToBytes(data);
6319
- const _this = {};
6320
- _this.getMode = function() {
6321
- return _mode;
6322
- };
6323
- _this.getLength = function(buffer) {
6324
- return _bytes.length;
6325
- };
6326
- _this.write = function(buffer) {
6327
- for (let i = 0; i < _bytes.length; i += 1) {
6328
- buffer.put(_bytes[i], 8);
6329
- }
6330
- };
6331
- return _this;
6332
- };
6333
- const qrKanji = function(data) {
6334
- const _mode = QRMode.MODE_KANJI;
6335
- const stringToBytes = qrcode.stringToBytes;
6336
- !function(c, code2) {
6337
- const test = stringToBytes(c);
6338
- if (test.length != 2 || (test[0] << 8 | test[1]) != code2) {
6339
- throw "sjis not supported.";
6340
- }
6341
- }("友", 38726);
6342
- const _bytes = stringToBytes(data);
6343
- const _this = {};
6344
- _this.getMode = function() {
6345
- return _mode;
6346
- };
6347
- _this.getLength = function(buffer) {
6348
- return ~~(_bytes.length / 2);
6349
- };
6350
- _this.write = function(buffer) {
6351
- const data2 = _bytes;
6352
- let i = 0;
6353
- while (i + 1 < data2.length) {
6354
- let c = (255 & data2[i]) << 8 | 255 & data2[i + 1];
6355
- if (33088 <= c && c <= 40956) {
6356
- c -= 33088;
6357
- } else if (57408 <= c && c <= 60351) {
6358
- c -= 49472;
6359
- } else {
6360
- throw "illegal char at " + (i + 1) + "/" + c;
6361
- }
6362
- c = (c >>> 8 & 255) * 192 + (c & 255);
6363
- buffer.put(c, 13);
6364
- i += 2;
6365
- }
6366
- if (i < data2.length) {
6367
- throw "illegal char at " + (i + 1);
6368
- }
6369
- };
6370
- return _this;
6371
- };
6372
- const byteArrayOutputStream = function() {
6373
- const _bytes = [];
6374
- const _this = {};
6375
- _this.writeByte = function(b) {
6376
- _bytes.push(b & 255);
6377
- };
6378
- _this.writeShort = function(i) {
6379
- _this.writeByte(i);
6380
- _this.writeByte(i >>> 8);
6381
- };
6382
- _this.writeBytes = function(b, off, len) {
6383
- off = off || 0;
6384
- len = len || b.length;
6385
- for (let i = 0; i < len; i += 1) {
6386
- _this.writeByte(b[i + off]);
6387
- }
6388
- };
6389
- _this.writeString = function(s) {
6390
- for (let i = 0; i < s.length; i += 1) {
6391
- _this.writeByte(s.charCodeAt(i));
6392
- }
6393
- };
6394
- _this.toByteArray = function() {
6395
- return _bytes;
6396
- };
6397
- _this.toString = function() {
6398
- let s = "";
6399
- s += "[";
6400
- for (let i = 0; i < _bytes.length; i += 1) {
6401
- if (i > 0) {
6402
- s += ",";
6403
- }
6404
- s += _bytes[i];
6405
- }
6406
- s += "]";
6407
- return s;
6408
- };
6409
- return _this;
6410
- };
6411
- const base64EncodeOutputStream = function() {
6412
- let _buffer = 0;
6413
- let _buflen = 0;
6414
- let _length = 0;
6415
- let _base64 = "";
6416
- const _this = {};
6417
- const writeEncoded = function(b) {
6418
- _base64 += String.fromCharCode(encode(b & 63));
6419
- };
6420
- const encode = function(n) {
6421
- if (n < 0) {
6422
- throw "n:" + n;
6423
- } else if (n < 26) {
6424
- return 65 + n;
6425
- } else if (n < 52) {
6426
- return 97 + (n - 26);
6427
- } else if (n < 62) {
6428
- return 48 + (n - 52);
6429
- } else if (n == 62) {
6430
- return 43;
6431
- } else if (n == 63) {
6432
- return 47;
6433
- } else {
6434
- throw "n:" + n;
6435
- }
6436
- };
6437
- _this.writeByte = function(n) {
6438
- _buffer = _buffer << 8 | n & 255;
6439
- _buflen += 8;
6440
- _length += 1;
6441
- while (_buflen >= 6) {
6442
- writeEncoded(_buffer >>> _buflen - 6);
6443
- _buflen -= 6;
6444
- }
6445
- };
6446
- _this.flush = function() {
6447
- if (_buflen > 0) {
6448
- writeEncoded(_buffer << 6 - _buflen);
6449
- _buffer = 0;
6450
- _buflen = 0;
6451
- }
6452
- if (_length % 3 != 0) {
6453
- const padlen = 3 - _length % 3;
6454
- for (let i = 0; i < padlen; i += 1) {
6455
- _base64 += "=";
6456
- }
6457
- }
6458
- };
6459
- _this.toString = function() {
6460
- return _base64;
6461
- };
6462
- return _this;
6463
- };
6464
- const base64DecodeInputStream = function(str) {
6465
- const _str = str;
6466
- let _pos = 0;
6467
- let _buffer = 0;
6468
- let _buflen = 0;
6469
- const _this = {};
6470
- _this.read = function() {
6471
- while (_buflen < 8) {
6472
- if (_pos >= _str.length) {
6473
- if (_buflen == 0) {
6474
- return -1;
6475
- }
6476
- throw "unexpected end of file./" + _buflen;
6477
- }
6478
- const c = _str.charAt(_pos);
6479
- _pos += 1;
6480
- if (c == "=") {
6481
- _buflen = 0;
6482
- return -1;
6483
- } else if (c.match(/^\s$/)) {
6484
- continue;
6485
- }
6486
- _buffer = _buffer << 6 | decode(c.charCodeAt(0));
6487
- _buflen += 6;
6488
- }
6489
- const n = _buffer >>> _buflen - 8 & 255;
6490
- _buflen -= 8;
6491
- return n;
6492
- };
6493
- const decode = function(c) {
6494
- if (65 <= c && c <= 90) {
6495
- return c - 65;
6496
- } else if (97 <= c && c <= 122) {
6497
- return c - 97 + 26;
6498
- } else if (48 <= c && c <= 57) {
6499
- return c - 48 + 52;
6500
- } else if (c == 43) {
6501
- return 62;
6502
- } else if (c == 47) {
6503
- return 63;
6504
- } else {
6505
- throw "c:" + c;
6506
- }
6507
- };
6508
- return _this;
6509
- };
6510
- const gifImage = function(width, height) {
6511
- const _width = width;
6512
- const _height = height;
6513
- const _data = new Array(width * height);
6514
- const _this = {};
6515
- _this.setPixel = function(x, y, pixel) {
6516
- _data[y * _width + x] = pixel;
6517
- };
6518
- _this.write = function(out) {
6519
- out.writeString("GIF87a");
6520
- out.writeShort(_width);
6521
- out.writeShort(_height);
6522
- out.writeByte(128);
6523
- out.writeByte(0);
6524
- out.writeByte(0);
6525
- out.writeByte(0);
6526
- out.writeByte(0);
6527
- out.writeByte(0);
6528
- out.writeByte(255);
6529
- out.writeByte(255);
6530
- out.writeByte(255);
6531
- out.writeString(",");
6532
- out.writeShort(0);
6533
- out.writeShort(0);
6534
- out.writeShort(_width);
6535
- out.writeShort(_height);
6536
- out.writeByte(0);
6537
- const lzwMinCodeSize = 2;
6538
- const raster = getLZWRaster(lzwMinCodeSize);
6539
- out.writeByte(lzwMinCodeSize);
6540
- let offset = 0;
6541
- while (raster.length - offset > 255) {
6542
- out.writeByte(255);
6543
- out.writeBytes(raster, offset, 255);
6544
- offset += 255;
6545
- }
6546
- out.writeByte(raster.length - offset);
6547
- out.writeBytes(raster, offset, raster.length - offset);
6548
- out.writeByte(0);
6549
- out.writeString(";");
6550
- };
6551
- const bitOutputStream = function(out) {
6552
- const _out = out;
6553
- let _bitLength = 0;
6554
- let _bitBuffer = 0;
6555
- const _this2 = {};
6556
- _this2.write = function(data, length) {
6557
- if (data >>> length != 0) {
6558
- throw "length over";
6559
- }
6560
- while (_bitLength + length >= 8) {
6561
- _out.writeByte(255 & (data << _bitLength | _bitBuffer));
6562
- length -= 8 - _bitLength;
6563
- data >>>= 8 - _bitLength;
6564
- _bitBuffer = 0;
6565
- _bitLength = 0;
6566
- }
6567
- _bitBuffer = data << _bitLength | _bitBuffer;
6568
- _bitLength = _bitLength + length;
6569
- };
6570
- _this2.flush = function() {
6571
- if (_bitLength > 0) {
6572
- _out.writeByte(_bitBuffer);
6573
- }
6574
- };
6575
- return _this2;
6576
- };
6577
- const getLZWRaster = function(lzwMinCodeSize) {
6578
- const clearCode = 1 << lzwMinCodeSize;
6579
- const endCode = (1 << lzwMinCodeSize) + 1;
6580
- let bitLength = lzwMinCodeSize + 1;
6581
- const table = lzwTable();
6582
- for (let i = 0; i < clearCode; i += 1) {
6583
- table.add(String.fromCharCode(i));
6584
- }
6585
- table.add(String.fromCharCode(clearCode));
6586
- table.add(String.fromCharCode(endCode));
6587
- const byteOut = byteArrayOutputStream();
6588
- const bitOut = bitOutputStream(byteOut);
6589
- bitOut.write(clearCode, bitLength);
6590
- let dataIndex = 0;
6591
- let s = String.fromCharCode(_data[dataIndex]);
6592
- dataIndex += 1;
6593
- while (dataIndex < _data.length) {
6594
- const c = String.fromCharCode(_data[dataIndex]);
6595
- dataIndex += 1;
6596
- if (table.contains(s + c)) {
6597
- s = s + c;
6598
- } else {
6599
- bitOut.write(table.indexOf(s), bitLength);
6600
- if (table.size() < 4095) {
6601
- if (table.size() == 1 << bitLength) {
6602
- bitLength += 1;
6603
- }
6604
- table.add(s + c);
5303
+ const eclBits = { L: 1, M: 0, Q: 3, H: 2 }[ecl] ?? 0;
5304
+ let formatData = eclBits << 3 | 0;
5305
+ let rem = formatData;
5306
+ for (let i = 0; i < 10; i++) {
5307
+ rem = rem << 1 ^ (rem >> 9) * 1335;
5308
+ }
5309
+ const formatBits = (formatData << 10 | rem & 1023) ^ 21522;
5310
+ const fb = [];
5311
+ for (let i = 14; i >= 0; i--) {
5312
+ fb.push(formatBits >> i & 1);
5313
+ }
5314
+ for (let i = 0; i < 6; i++) matrix[8][i] = fb[i];
5315
+ matrix[8][7] = fb[6];
5316
+ matrix[8][8] = fb[7];
5317
+ matrix[7][8] = fb[8];
5318
+ for (let i = 9; i < 15; i++) matrix[14 - i][8] = fb[i];
5319
+ for (let i = 0; i < 8; i++) matrix[8][size - 8 + i] = fb[14 - i];
5320
+ for (let i = 8; i < 15; i++) matrix[size - 15 + i][8] = fb[14 - i];
5321
+ const result = [];
5322
+ for (let row = 0; row < size; row++) {
5323
+ result[row] = [];
5324
+ for (let col = 0; col < size; col++) {
5325
+ result[row][col] = matrix[row][col] === 1;
6605
5326
  }
6606
- s = c;
6607
5327
  }
5328
+ return result;
6608
5329
  }
6609
- bitOut.write(table.indexOf(s), bitLength);
6610
- bitOut.write(endCode, bitLength);
6611
- bitOut.flush();
6612
- return byteOut.toByteArray();
6613
- };
6614
- const lzwTable = function() {
6615
- const _map = {};
6616
- let _size = 0;
6617
- const _this2 = {};
6618
- _this2.add = function(key) {
6619
- if (_this2.contains(key)) {
6620
- throw "dup key:" + key;
6621
- }
6622
- _map[key] = _size;
6623
- _size += 1;
6624
- };
6625
- _this2.size = function() {
6626
- return _size;
6627
- };
6628
- _this2.indexOf = function(key) {
6629
- return _map[key];
6630
- };
6631
- _this2.contains = function(key) {
6632
- return typeof _map[key] != "undefined";
6633
- };
6634
- return _this2;
6635
- };
6636
- return _this;
6637
- };
6638
- const createDataURL = function(width, height, getPixel) {
6639
- const gif = gifImage(width, height);
6640
- for (let y = 0; y < height; y += 1) {
6641
- for (let x = 0; x < width; x += 1) {
6642
- gif.setPixel(x, y, getPixel(x, y));
6643
- }
6644
- }
6645
- const b = byteArrayOutputStream();
6646
- gif.write(b);
6647
- const base64 = base64EncodeOutputStream();
6648
- const bytes = b.toByteArray();
6649
- for (let i = 0; i < bytes.length; i += 1) {
6650
- base64.writeByte(bytes[i]);
6651
- }
6652
- base64.flush();
6653
- return "data:image/gif;base64," + base64;
6654
- };
6655
- qrcode.stringToBytes;
6656
- const __default__$1 = {
6657
- options: {
6658
- virtualHost: true,
6659
- styleIsolation: "shared"
6660
- }
6661
- };
6662
- const _sfc_main$1 = /* @__PURE__ */ defineComponent({
6663
- ...__default__$1,
6664
- __name: "u-qrcode",
6665
- props: {
6666
- value: { default: "" },
6667
- size: { default: 200 },
6668
- color: { default: "#000000" },
6669
- bgColor: { default: "#ffffff" },
6670
- errorCorrectLevel: { default: "M" }
6671
- },
6672
- setup(__props) {
6673
- const props = __props;
6674
- const qrInstance = ref(null);
6675
- const moduleCount = ref(0);
6676
- const cellSize = computed(() => {
6677
- if (moduleCount.value === 0) return 0;
6678
- return props.size / moduleCount.value;
6679
- });
6680
- const isDark = (row, col) => {
6681
- if (!qrInstance.value) return false;
6682
- try {
6683
- return qrInstance.value.isDark(row, col);
6684
- } catch {
6685
- return false;
6686
- }
6687
- };
6688
- const generateQRCode = () => {
5330
+ const generate = () => {
6689
5331
  if (!props.value) {
6690
- qrInstance.value = null;
6691
- moduleCount.value = 0;
5332
+ modules.value = [];
6692
5333
  return;
6693
5334
  }
6694
5335
  try {
6695
- const typeNumber = 0;
6696
- const qr = qrcode(typeNumber, props.errorCorrectLevel);
6697
- qr.addData(props.value);
6698
- qr.make();
6699
- qrInstance.value = qr;
6700
- moduleCount.value = qr.getModuleCount();
5336
+ modules.value = generateQRCode(props.value, props.errorCorrectLevel);
6701
5337
  } catch (e) {
6702
5338
  console.error("QR Code generation failed:", e);
6703
- qrInstance.value = null;
6704
- moduleCount.value = 0;
5339
+ modules.value = [];
6705
5340
  }
6706
5341
  };
6707
- watch(() => props.value, generateQRCode);
6708
- watch(() => props.errorCorrectLevel, generateQRCode);
5342
+ watch(() => props.value, generate);
5343
+ watch(() => props.errorCorrectLevel, generate);
6709
5344
  onMounted(() => {
6710
- generateQRCode();
5345
+ generate();
6711
5346
  });
6712
5347
  return (_ctx, _cache) => {
6713
5348
  return openBlock(), createElementBlock("view", {
@@ -6718,19 +5353,19 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
6718
5353
  class: "u-qrcode__matrix",
6719
5354
  style: normalizeStyle({ backgroundColor: __props.bgColor })
6720
5355
  }, [
6721
- (openBlock(true), createElementBlock(Fragment, null, renderList(moduleCount.value, (row, rowIndex) => {
5356
+ (openBlock(true), createElementBlock(Fragment, null, renderList(modules.value, (row, rowIndex) => {
6722
5357
  return openBlock(), createElementBlock("view", {
6723
5358
  key: rowIndex,
6724
5359
  class: "u-qrcode__row"
6725
5360
  }, [
6726
- (openBlock(true), createElementBlock(Fragment, null, renderList(moduleCount.value, (col, colIndex) => {
5361
+ (openBlock(true), createElementBlock(Fragment, null, renderList(row, (cell, colIndex) => {
6727
5362
  return openBlock(), createElementBlock("view", {
6728
5363
  key: colIndex,
6729
5364
  class: "u-qrcode__cell",
6730
5365
  style: normalizeStyle({
6731
5366
  width: `${cellSize.value}px`,
6732
5367
  height: `${cellSize.value}px`,
6733
- backgroundColor: isDark(rowIndex, colIndex) ? __props.color : __props.bgColor
5368
+ backgroundColor: cell ? __props.color : __props.bgColor
6734
5369
  })
6735
5370
  }, null, 4);
6736
5371
  }), 128))
@@ -6741,7 +5376,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
6741
5376
  };
6742
5377
  }
6743
5378
  });
6744
- const uQrcode = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-d5a07c6c"]]);
5379
+ const uQrcode = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-eebb43a8"]]);
6745
5380
  const _hoisted_1 = { class: "u-barcode" };
6746
5381
  const _hoisted_2 = ["canvas-id"];
6747
5382
  const _hoisted_3 = ["src"];