@atooyu/uxto-ui 1.1.36 → 1.1.37

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