@atooyu/uxto-ui 1.1.37 → 1.1.38

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
@@ -5100,7 +5100,6 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
5100
5100
  [6, 30, 58, 86, 114, 142, 170]
5101
5101
  ];
5102
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
5103
  const G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
5105
5104
  const RS_BLOCK_TABLE = [
5106
5105
  [1, 26, 19],
@@ -5182,99 +5181,14 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
5182
5181
  [3, 135, 107, 5, 136, 108],
5183
5182
  [3, 67, 41, 13, 68, 42],
5184
5183
  [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]
5184
+ [15, 43, 15, 10, 44, 16]
5266
5185
  ];
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;
5271
- }
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];
5274
- }
5275
- for (let i = 0; i < 255; i++) {
5276
- LOG_TABLE[EXP_TABLE[i]] = i;
5277
- }
5186
+ const EXP_TABLE = [];
5187
+ const LOG_TABLE = [];
5188
+ for (let i = 0; i < 8; i++) EXP_TABLE[i] = 1 << i;
5189
+ for (let i = 8; i < 256; i++) EXP_TABLE[i] = EXP_TABLE[i - 4] ^ EXP_TABLE[i - 5] ^ EXP_TABLE[i - 6] ^ EXP_TABLE[i - 8];
5190
+ for (let i = 0; i < 255; i++) LOG_TABLE[EXP_TABLE[i]] = i;
5191
+ for (let i = 255; i < 512; i++) EXP_TABLE[i] = EXP_TABLE[i - 255];
5278
5192
  function glog(n) {
5279
5193
  if (n < 1) throw new Error("glog(" + n + ")");
5280
5194
  return LOG_TABLE[n];
@@ -5284,37 +5198,6 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
5284
5198
  while (n >= 256) n -= 255;
5285
5199
  return EXP_TABLE[n];
5286
5200
  }
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];
5293
- }
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)));
5302
- }
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);
5315
- }
5316
- };
5317
- }
5318
5201
  function getBCHDigit(data) {
5319
5202
  let digit = 0;
5320
5203
  while (data !== 0) {
@@ -5325,20 +5208,11 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
5325
5208
  }
5326
5209
  function getBCHTypeInfo(data) {
5327
5210
  let d = data << 10;
5328
- while (getBCHDigit(d) - getBCHDigit(G15) >= 0) {
5329
- d ^= G15 << getBCHDigit(d) - getBCHDigit(G15);
5330
- }
5211
+ while (getBCHDigit(d) - getBCHDigit(G15) >= 0) d ^= G15 << getBCHDigit(d) - getBCHDigit(G15);
5331
5212
  return (data << 10 | d) ^ G15_MASK;
5332
5213
  }
5333
- function getBCHTypeNumber(data) {
5334
- let d = data << 12;
5335
- while (getBCHDigit(d) - getBCHDigit(G18) >= 0) {
5336
- d ^= G18 << getBCHDigit(d) - getBCHDigit(G18);
5337
- }
5338
- return data << 12 | d;
5339
- }
5340
5214
  function getPatternPosition(typeNumber) {
5341
- return PATTERN_POSITION_TABLE[typeNumber - 1];
5215
+ return PATTERN_POSITION_TABLE[typeNumber - 1] || [];
5342
5216
  }
5343
5217
  function getMaskFunction(maskPattern) {
5344
5218
  switch (maskPattern) {
@@ -5359,72 +5233,20 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
5359
5233
  case 7:
5360
5234
  return (i, j) => (i * j % 3 + (i + j) % 2) % 2 === 0;
5361
5235
  default:
5362
- throw new Error("bad maskPattern:" + maskPattern);
5363
- }
5364
- }
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;
5371
- }
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);
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
+ return () => false;
5414
5237
  }
5415
5238
  }
5416
5239
  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;
5240
+ const index = (typeNumber - 1) * 4 + errorCorrectionLevel;
5241
+ const block = RS_BLOCK_TABLE[index];
5242
+ if (!block) throw new Error("bad rs block");
5420
5243
  const list2 = [];
5244
+ const length = Math.floor(block.length / 3);
5421
5245
  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 });
5427
- }
5246
+ const count = block[i * 3];
5247
+ const totalCount = block[i * 3 + 1];
5248
+ const dataCount = block[i * 3 + 2];
5249
+ for (let j = 0; j < count; j++) list2.push({ totalCount, dataCount });
5428
5250
  }
5429
5251
  return list2;
5430
5252
  }
@@ -5440,335 +5262,252 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
5440
5262
  return this.length;
5441
5263
  }
5442
5264
  put(num, len) {
5443
- for (let i = 0; i < len; i++) {
5444
- this.putBit((num >>> len - i - 1 & 1) === 1);
5445
- }
5265
+ for (let i = 0; i < len; i++) this.putBit((num >>> len - i - 1 & 1) === 1);
5446
5266
  }
5447
5267
  putBit(bit) {
5448
5268
  const bufIndex = Math.floor(this.length / 8);
5449
- if (this.buffer.length <= bufIndex) {
5450
- this.buffer.push(0);
5451
- }
5452
- if (bit) {
5453
- this.buffer[bufIndex] |= 128 >>> this.length % 8;
5454
- }
5269
+ if (this.buffer.length <= bufIndex) this.buffer.push(0);
5270
+ if (bit) this.buffer[bufIndex] |= 128 >>> this.length % 8;
5455
5271
  this.length++;
5456
5272
  }
5457
5273
  }
5458
5274
  function stringToBytes(s) {
5459
5275
  const bytes = [];
5460
- for (let i = 0; i < s.length; i++) {
5461
- const c = s.charCodeAt(i);
5462
- bytes.push(c & 255);
5463
- }
5276
+ for (let i = 0; i < s.length; i++) bytes.push(s.charCodeAt(i) & 255);
5464
5277
  return bytes;
5465
5278
  }
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);
5279
+ function getLengthInBits(mode, type) {
5280
+ if (type < 10) return mode === 4 ? 8 : 8;
5281
+ if (type < 27) return mode === 4 ? 16 : 10;
5282
+ return mode === 4 ? 16 : 12;
5283
+ }
5284
+ function multiplyPolynomials(a, b) {
5285
+ const result = new Array(a.length + b.length - 1).fill(0);
5286
+ for (let i = 0; i < a.length; i++) {
5287
+ for (let j = 0; j < b.length; j++) {
5288
+ result[i + j] ^= gexp(glog(a[i]) + glog(b[j]));
5474
5289
  }
5475
5290
  }
5476
- let totalDataCount = 0;
5477
- for (const block of rsBlocks) {
5478
- totalDataCount += block.dataCount;
5479
- }
5480
- if (buffer.getLengthInBits() > totalDataCount * 8) {
5481
- throw new Error("code length overflow");
5482
- }
5483
- if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {
5484
- buffer.put(0, 4);
5485
- }
5486
- while (buffer.getLengthInBits() % 8 !== 0) {
5487
- buffer.putBit(false);
5291
+ return result;
5292
+ }
5293
+ function modPolynomial(a, b) {
5294
+ let result = [...a];
5295
+ while (result.length >= b.length) {
5296
+ const ratio = glog(result[0]) - glog(b[0]);
5297
+ for (let i = 0; i < b.length; i++) {
5298
+ result[i] ^= gexp(glog(b[i]) + ratio);
5299
+ }
5300
+ while (result.length > 0 && result[0] === 0) result.shift();
5488
5301
  }
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);
5302
+ return result;
5303
+ }
5304
+ function getErrorCorrectPolynomial(errorCorrectLength) {
5305
+ let poly = [1];
5306
+ for (let i = 0; i < errorCorrectLength; i++) {
5307
+ poly = multiplyPolynomials(poly, [1, gexp(i)]);
5494
5308
  }
5495
- return createBytes(buffer, rsBlocks);
5309
+ return poly;
5496
5310
  }
5497
- function createBytes(buffer, rsBlocks) {
5498
- let offset = 0;
5499
- let maxDcCount = 0;
5500
- let maxEcCount = 0;
5501
- const dcdata = [];
5502
- const ecdata = [];
5311
+ function createData(typeNumber, errorCorrectionLevel, data) {
5312
+ const rsBlocks = getRSBlocks(typeNumber, errorCorrectionLevel);
5313
+ let totalDataCount = 0;
5314
+ for (const block of rsBlocks) totalDataCount += block.dataCount;
5315
+ const buffer = new BitBuffer();
5316
+ buffer.put(4, 4);
5317
+ const bytes = stringToBytes(data);
5318
+ buffer.put(bytes.length, getLengthInBits(4, typeNumber));
5319
+ for (const byte of bytes) buffer.put(byte, 8);
5320
+ if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) buffer.put(0, 4);
5321
+ while (buffer.getLengthInBits() % 8 !== 0) buffer.putBit(false);
5322
+ let padIndex = 0;
5323
+ const padBytes = [PAD0, PAD1];
5324
+ while (buffer.getLengthInBits() < totalDataCount * 8) {
5325
+ buffer.put(padBytes[padIndex], 8);
5326
+ padIndex = (padIndex + 1) % 2;
5327
+ }
5328
+ const dataBuffer = buffer.getBuffer();
5329
+ let dataIndex = 0;
5330
+ const dcData = [];
5331
+ const ecData = [];
5503
5332
  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;
5333
+ const dc = dataBuffer.slice(dataIndex, dataIndex + block.dataCount);
5334
+ dataIndex += block.dataCount;
5335
+ dcData.push(dc);
5336
+ const ecCount = block.totalCount - block.dataCount;
5514
5337
  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);
5338
+ const dataPoly = [...dc, ...new Array(ecCount).fill(0)];
5339
+ const ec = modPolynomial(dataPoly, rsPoly);
5340
+ ecData.push(ec.slice(-ecCount));
5523
5341
  }
5524
5342
  const result = [];
5343
+ let maxDcCount = 0;
5344
+ let maxEcCount = 0;
5345
+ for (const block of rsBlocks) {
5346
+ maxDcCount = Math.max(maxDcCount, block.dataCount);
5347
+ maxEcCount = Math.max(maxEcCount, block.totalCount - block.dataCount);
5348
+ }
5525
5349
  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]);
5350
+ for (const dc of dcData) {
5351
+ if (i < dc.length) result.push(dc[i]);
5528
5352
  }
5529
5353
  }
5530
5354
  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]);
5355
+ for (const ec of ecData) {
5356
+ if (i < ec.length) result.push(ec[i]);
5533
5357
  }
5534
5358
  }
5535
5359
  return result;
5536
5360
  }
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 {
5560
- continue;
5561
- }
5562
- }
5563
- this.typeNumber = typeNumber;
5564
- }
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
- }
5577
- }
5578
- return pattern;
5579
- }
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);
5585
- }
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);
5594
- }
5595
- if (this.dataCache === null) {
5596
- throw new Error("dataCache is null");
5597
- }
5598
- this.mapData(this.dataCache, maskPattern);
5599
- }
5600
- setupPositionProbePattern(row, col) {
5361
+ function generateQRCode(text, errorLevel) {
5362
+ const ecl = QRErrorCorrectionLevel[errorLevel] ?? 0;
5363
+ let typeNumber = 1;
5364
+ for (; typeNumber <= 40; typeNumber++) {
5365
+ const rsBlocks = getRSBlocks(typeNumber, ecl);
5366
+ let totalDataCount = 0;
5367
+ for (const block of rsBlocks) totalDataCount += block.dataCount;
5368
+ const lengthBits = typeNumber < 10 ? 8 : 16;
5369
+ const totalBits = 4 + lengthBits + stringToBytes(text).length * 8;
5370
+ if (totalBits <= totalDataCount * 8) break;
5371
+ }
5372
+ const size = typeNumber * 4 + 17;
5373
+ const data = createData(typeNumber, ecl, text);
5374
+ const mod = [];
5375
+ for (let i = 0; i < size; i++) mod[i] = new Array(size).fill(null);
5376
+ const setupFinderPattern = (row, col) => {
5601
5377
  for (let r = -1; r <= 7; r++) {
5602
- if (row + r <= -1 || this.moduleCount <= row + r) continue;
5603
5378
  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;
5379
+ const nr = row + r, nc = col + c;
5380
+ if (nr < 0 || nr >= size || nc < 0 || nc >= size) continue;
5381
+ if (r >= 0 && r <= 6 && (c === 0 || c === 6) || c >= 0 && c <= 6 && (r === 0 || r === 6) || r >= 2 && r <= 4 && c >= 2 && c <= 4) {
5382
+ mod[nr][nc] = true;
5607
5383
  } else {
5608
- this.modules[row + r][col + c] = false;
5384
+ mod[nr][nc] = false;
5609
5385
  }
5610
5386
  }
5611
5387
  }
5612
- }
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
- }
5622
- }
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
- }
5388
+ };
5389
+ setupFinderPattern(0, 0);
5390
+ setupFinderPattern(size - 7, 0);
5391
+ setupFinderPattern(0, size - 7);
5392
+ for (let i = 8; i < size - 8; i++) {
5393
+ if (mod[i][6] === null) mod[i][6] = i % 2 === 0;
5394
+ if (mod[6][i] === null) mod[6][i] = i % 2 === 0;
5395
+ }
5396
+ const alignPos = getPatternPosition(typeNumber);
5397
+ for (const row of alignPos) {
5398
+ for (const col of alignPos) {
5399
+ if (mod[row][col] !== null) continue;
5400
+ for (let r = -2; r <= 2; r++) {
5401
+ for (let c = -2; c <= 2; c++) {
5402
+ mod[row + r][col + c] = r === -2 || r === 2 || c === -2 || c === 2 || r === 0 && c === 0;
5638
5403
  }
5639
5404
  }
5640
5405
  }
5641
5406
  }
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
- }
5652
- }
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;
5407
+ for (let i = 0; i < 9; i++) {
5408
+ if (mod[8][i] === null) mod[8][i] = false;
5409
+ if (mod[i][8] === null) mod[i][8] = false;
5410
+ }
5411
+ for (let i = 0; i < 8; i++) {
5412
+ if (mod[8][size - 1 - i] === null) mod[8][size - 1 - i] = false;
5413
+ if (mod[size - 1 - i][8] === null) mod[size - 1 - i][8] = false;
5414
+ }
5415
+ mod[size - 8][8] = true;
5416
+ if (typeNumber >= 7) {
5417
+ const bits = typeNumber;
5418
+ for (let i = 0; i < 6; i++) {
5419
+ for (let j = 0; j < 3; j++) {
5420
+ mod[i][size - 11 + j] = (bits >> i * 3 + j & 1) === 1;
5421
+ mod[size - 11 + j][i] = (bits >> i * 3 + j & 1) === 1;
5664
5422
  }
5665
5423
  }
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
- }
5424
+ }
5425
+ let bestMask = 0;
5426
+ let bestPenalty = Infinity;
5427
+ for (let mask = 0; mask < 8; mask++) {
5428
+ const testMod = mod.map((row) => [...row]);
5429
+ mapData(testMod, size, data, mask);
5430
+ const penalty = calculatePenalty(testMod, size);
5431
+ if (penalty < bestPenalty) {
5432
+ bestPenalty = penalty;
5433
+ bestMask = mask;
5675
5434
  }
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
- }
5435
+ }
5436
+ mapData(mod, size, data, bestMask);
5437
+ const formatData = ecl << 3 | bestMask;
5438
+ const formatBits = getBCHTypeInfo(formatData);
5439
+ for (let i = 0; i < 6; i++) mod[8][i] = (formatBits >> i & 1) === 1;
5440
+ mod[8][7] = (formatBits >> 6 & 1) === 1;
5441
+ mod[8][8] = (formatBits >> 7 & 1) === 1;
5442
+ mod[7][8] = (formatBits >> 8 & 1) === 1;
5443
+ for (let i = 9; i < 15; i++) mod[14 - i][8] = (formatBits >> i & 1) === 1;
5444
+ for (let i = 0; i < 8; i++) mod[8][size - 1 - i] = (formatBits >> i & 1) === 1;
5445
+ for (let i = 8; i < 15; i++) mod[size - 15 + i][8] = (formatBits >> i & 1) === 1;
5446
+ const result = [];
5447
+ for (let r = 0; r < size; r++) {
5448
+ result[r] = [];
5449
+ for (let c = 0; c < size; c++) {
5450
+ result[r][c] = mod[r][c] === true;
5710
5451
  }
5711
5452
  }
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++;
5453
+ return { modules: result, moduleCount: size };
5454
+ }
5455
+ function mapData(mod, size, data, maskPattern) {
5456
+ const maskFunc = getMaskFunction(maskPattern);
5457
+ let bitIndex = 0;
5458
+ let inc = -1;
5459
+ let row = size - 1;
5460
+ for (let col = size - 1; col > 0; col -= 2) {
5461
+ if (col === 6) col = 5;
5462
+ while (true) {
5463
+ for (let c = 0; c < 2; c++) {
5464
+ const tc = col - c;
5465
+ if (mod[row][tc] === null) {
5466
+ let dark = false;
5467
+ if (bitIndex < data.length * 8) {
5468
+ dark = (data[Math.floor(bitIndex / 8)] >>> 7 - bitIndex % 8 & 1) === 1;
5724
5469
  }
5470
+ if (maskFunc(row, tc)) dark = !dark;
5471
+ mod[row][tc] = dark;
5472
+ bitIndex++;
5725
5473
  }
5726
- if (sameCount > 5) lostPoint += 3 + sameCount - 5;
5727
5474
  }
5728
- }
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;
5475
+ row += inc;
5476
+ if (row < 0 || row >= size) {
5477
+ row -= inc;
5478
+ inc = -inc;
5479
+ break;
5737
5480
  }
5738
5481
  }
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++;
5482
+ }
5483
+ }
5484
+ function calculatePenalty(mod, size) {
5485
+ let penalty = 0;
5486
+ for (let row = 0; row < size; row++) {
5487
+ let count = 1;
5488
+ for (let col = 1; col < size; col++) {
5489
+ if (mod[row][col] === mod[row][col - 1]) {
5490
+ count++;
5491
+ } else {
5492
+ if (count >= 5) penalty += 3 + (count - 5);
5493
+ count = 1;
5757
5494
  }
5758
5495
  }
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;
5496
+ if (count >= 5) penalty += 3 + (count - 5);
5765
5497
  }
5766
- isDark(row, col) {
5767
- if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) {
5768
- throw new Error(row + "," + col);
5498
+ for (let col = 0; col < size; col++) {
5499
+ let count = 1;
5500
+ for (let row = 1; row < size; row++) {
5501
+ if (mod[row][col] === mod[row - 1][col]) {
5502
+ count++;
5503
+ } else {
5504
+ if (count >= 5) penalty += 3 + (count - 5);
5505
+ count = 1;
5506
+ }
5769
5507
  }
5770
- return this.modules[row][col] === true;
5508
+ if (count >= 5) penalty += 3 + (count - 5);
5771
5509
  }
5510
+ return penalty;
5772
5511
  }
5773
5512
  const generate = () => {
5774
5513
  if (!props.value) {
@@ -5777,19 +5516,9 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
5777
5516
  return;
5778
5517
  }
5779
5518
  try {
5780
- const qr = new QRCode(0, props.errorCorrectLevel);
5781
- qr.addData(props.value);
5782
- qr.make();
5783
- const count = qr.getModuleCount();
5784
- moduleCount.value = count;
5785
- const result = [];
5786
- for (let row = 0; row < count; row++) {
5787
- result[row] = [];
5788
- for (let col = 0; col < count; col++) {
5789
- result[row][col] = qr.isDark(row, col);
5790
- }
5791
- }
5792
- modules.value = result;
5519
+ const qr = generateQRCode(props.value, props.errorCorrectLevel);
5520
+ modules.value = qr.modules;
5521
+ moduleCount.value = qr.moduleCount;
5793
5522
  } catch (e) {
5794
5523
  console.error("QR Code generation failed:", e);
5795
5524
  modules.value = [];
@@ -5831,7 +5560,7 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
5831
5560
  };
5832
5561
  }
5833
5562
  });
5834
- const uQrcode = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-e3d52c6f"]]);
5563
+ const uQrcode = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-a6ae1830"]]);
5835
5564
  const _hoisted_1 = { class: "u-barcode" };
5836
5565
  const _hoisted_2 = ["canvas-id"];
5837
5566
  const _hoisted_3 = ["src"];