@atooyu/uxto-ui 1.1.37 → 1.1.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -4999,7 +4999,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
4999
4999
  createElementVNode("view", {
5000
5000
  class: normalizeClass(["u-tabbar__center-btn", {
5001
5001
  "u-tabbar__center-btn--active": __props.modelValue === __props.centerTab.value,
5002
- "u-tabbar__center-btn--left-active": __props.modelValue === __props.leftTab.value
5002
+ "u-tabbar__center-btn--side-active": __props.modelValue === __props.leftTab.value || __props.modelValue === __props.rightTab.value
5003
5003
  }]),
5004
5004
  onClick: _cache[1] || (_cache[1] = ($event) => switchTab(__props.centerTab.value))
5005
5005
  }, [
@@ -5027,7 +5027,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
5027
5027
  };
5028
5028
  }
5029
5029
  });
5030
- const uTabbar = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-10cb84bc"]]);
5030
+ const uTabbar = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-a344a18d"]]);
5031
5031
  const __default__$1 = {
5032
5032
  options: {
5033
5033
  virtualHost: true,
@@ -5098,7 +5098,6 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5098
5098
  [6, 30, 58, 86, 114, 142, 170]
5099
5099
  ];
5100
5100
  const G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;
5101
- const G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0;
5102
5101
  const G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
5103
5102
  const RS_BLOCK_TABLE = [
5104
5103
  [1, 26, 19],
@@ -5180,99 +5179,14 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5180
5179
  [3, 135, 107, 5, 136, 108],
5181
5180
  [3, 67, 41, 13, 68, 42],
5182
5181
  [15, 54, 24, 5, 55, 25],
5183
- [15, 43, 15, 10, 44, 16],
5184
- [4, 144, 116, 4, 145, 117],
5185
- [17, 68, 42],
5186
- [17, 50, 22, 6, 51, 23],
5187
- [19, 46, 16, 6, 47, 17],
5188
- [2, 139, 111, 7, 140, 112],
5189
- [17, 74, 46],
5190
- [7, 54, 24, 16, 55, 25],
5191
- [34, 37, 13],
5192
- [4, 151, 121, 5, 152, 122],
5193
- [4, 75, 47, 14, 76, 48],
5194
- [11, 54, 24, 14, 55, 25],
5195
- [16, 45, 15, 14, 46, 16],
5196
- [6, 147, 117, 4, 148, 118],
5197
- [6, 73, 45, 14, 74, 46],
5198
- [11, 54, 24, 16, 55, 25],
5199
- [30, 46, 16, 2, 47, 17],
5200
- [8, 132, 106, 4, 133, 107],
5201
- [8, 75, 47, 13, 76, 48],
5202
- [7, 54, 24, 22, 55, 25],
5203
- [22, 45, 15, 13, 46, 16],
5204
- [10, 142, 114, 2, 143, 115],
5205
- [19, 74, 46, 4, 75, 47],
5206
- [28, 50, 22, 6, 51, 23],
5207
- [33, 46, 16, 4, 47, 17],
5208
- [8, 152, 122, 4, 153, 123],
5209
- [22, 73, 45, 3, 74, 46],
5210
- [8, 53, 23, 26, 54, 24],
5211
- [12, 45, 15, 28, 46, 16],
5212
- [3, 147, 117, 10, 148, 118],
5213
- [3, 73, 45, 23, 74, 46],
5214
- [4, 54, 24, 31, 55, 25],
5215
- [11, 45, 15, 31, 46, 16],
5216
- [7, 146, 116, 7, 147, 117],
5217
- [21, 73, 45, 7, 74, 46],
5218
- [1, 53, 23, 37, 54, 24],
5219
- [19, 45, 15, 26, 46, 16],
5220
- [5, 145, 115, 10, 146, 116],
5221
- [19, 75, 47, 10, 76, 48],
5222
- [15, 54, 24, 25, 55, 25],
5223
- [23, 45, 15, 25, 46, 16],
5224
- [13, 145, 115, 3, 146, 116],
5225
- [2, 74, 46, 29, 75, 47],
5226
- [42, 54, 24, 1, 55, 25],
5227
- [23, 45, 15, 28, 46, 16],
5228
- [17, 145, 115],
5229
- [10, 74, 46, 23, 75, 47],
5230
- [10, 54, 24, 35, 55, 25],
5231
- [19, 45, 15, 35, 46, 16],
5232
- [17, 145, 115, 1, 146, 116],
5233
- [14, 74, 46, 21, 75, 47],
5234
- [29, 54, 24, 19, 55, 25],
5235
- [11, 45, 15, 46, 46, 16],
5236
- [13, 145, 115, 6, 146, 116],
5237
- [14, 74, 46, 23, 75, 47],
5238
- [44, 54, 24, 7, 55, 25],
5239
- [59, 46, 16, 1, 47, 17],
5240
- [12, 151, 121, 7, 152, 122],
5241
- [12, 75, 47, 26, 76, 48],
5242
- [39, 54, 24, 14, 55, 25],
5243
- [22, 45, 15, 41, 46, 16],
5244
- [6, 151, 121, 14, 152, 122],
5245
- [6, 75, 47, 34, 76, 48],
5246
- [46, 54, 24, 10, 55, 25],
5247
- [2, 45, 15, 64, 46, 16],
5248
- [17, 152, 122, 4, 153, 123],
5249
- [29, 74, 46, 14, 75, 47],
5250
- [49, 54, 24, 10, 55, 25],
5251
- [24, 45, 15, 46, 46, 16],
5252
- [4, 152, 122, 18, 153, 123],
5253
- [13, 74, 46, 32, 75, 47],
5254
- [48, 54, 24, 14, 55, 25],
5255
- [42, 45, 15, 32, 46, 16],
5256
- [20, 147, 117, 4, 148, 118],
5257
- [40, 75, 47, 7, 76, 48],
5258
- [43, 54, 24, 22, 55, 25],
5259
- [10, 45, 15, 67, 46, 16],
5260
- [19, 148, 118, 6, 149, 119],
5261
- [18, 75, 47, 31, 76, 48],
5262
- [34, 54, 24, 34, 55, 25],
5263
- [20, 45, 15, 61, 46, 16]
5182
+ [15, 43, 15, 10, 44, 16]
5264
5183
  ];
5265
- const EXP_TABLE = new Array(256);
5266
- const LOG_TABLE = new Array(256);
5267
- for (let i = 0; i < 8; i++) {
5268
- EXP_TABLE[i] = 1 << i;
5269
- }
5270
- for (let i = 8; i < 256; i++) {
5271
- EXP_TABLE[i] = EXP_TABLE[i - 4] ^ EXP_TABLE[i - 5] ^ EXP_TABLE[i - 6] ^ EXP_TABLE[i - 8];
5272
- }
5273
- for (let i = 0; i < 255; i++) {
5274
- LOG_TABLE[EXP_TABLE[i]] = i;
5275
- }
5184
+ const EXP_TABLE = [];
5185
+ const LOG_TABLE = [];
5186
+ for (let i = 0; i < 8; i++) EXP_TABLE[i] = 1 << i;
5187
+ 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];
5188
+ for (let i = 0; i < 255; i++) LOG_TABLE[EXP_TABLE[i]] = i;
5189
+ for (let i = 255; i < 512; i++) EXP_TABLE[i] = EXP_TABLE[i - 255];
5276
5190
  function glog(n) {
5277
5191
  if (n < 1) throw new Error("glog(" + n + ")");
5278
5192
  return LOG_TABLE[n];
@@ -5282,37 +5196,6 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5282
5196
  while (n >= 256) n -= 255;
5283
5197
  return EXP_TABLE[n];
5284
5198
  }
5285
- function createPolynomial(num, shift) {
5286
- let offset = 0;
5287
- while (offset < num.length && num[offset] === 0) offset++;
5288
- const _num = new Array(num.length - offset + shift).fill(0);
5289
- for (let i = 0; i < num.length - offset; i++) {
5290
- _num[i] = num[i + offset];
5291
- }
5292
- return {
5293
- getAt: (index) => _num[index],
5294
- getLength: () => _num.length,
5295
- multiply: (e) => {
5296
- const result = new Array(_num.length + e.getLength() - 1).fill(0);
5297
- for (let i = 0; i < _num.length; i++) {
5298
- for (let j = 0; j < e.getLength(); j++) {
5299
- result[i + j] ^= gexp(glog(_num[i]) + glog(e.getAt(j)));
5300
- }
5301
- }
5302
- return createPolynomial(result, 0);
5303
- },
5304
- mod: (e) => {
5305
- const lenDiff = _num.length - e.getLength();
5306
- if (lenDiff < 0) return createPolynomial(_num, 0);
5307
- const ratio = glog(_num[0]) - glog(e.getAt(0));
5308
- const result = [..._num];
5309
- for (let i = 0; i < e.getLength(); i++) {
5310
- result[i] ^= gexp(glog(e.getAt(i)) + ratio);
5311
- }
5312
- return createPolynomial(result, 0).mod(e);
5313
- }
5314
- };
5315
- }
5316
5199
  function getBCHDigit(data) {
5317
5200
  let digit = 0;
5318
5201
  while (data !== 0) {
@@ -5323,20 +5206,11 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5323
5206
  }
5324
5207
  function getBCHTypeInfo(data) {
5325
5208
  let d = data << 10;
5326
- while (getBCHDigit(d) - getBCHDigit(G15) >= 0) {
5327
- d ^= G15 << getBCHDigit(d) - getBCHDigit(G15);
5328
- }
5209
+ while (getBCHDigit(d) - getBCHDigit(G15) >= 0) d ^= G15 << getBCHDigit(d) - getBCHDigit(G15);
5329
5210
  return (data << 10 | d) ^ G15_MASK;
5330
5211
  }
5331
- function getBCHTypeNumber(data) {
5332
- let d = data << 12;
5333
- while (getBCHDigit(d) - getBCHDigit(G18) >= 0) {
5334
- d ^= G18 << getBCHDigit(d) - getBCHDigit(G18);
5335
- }
5336
- return data << 12 | d;
5337
- }
5338
5212
  function getPatternPosition(typeNumber) {
5339
- return PATTERN_POSITION_TABLE[typeNumber - 1];
5213
+ return PATTERN_POSITION_TABLE[typeNumber - 1] || [];
5340
5214
  }
5341
5215
  function getMaskFunction(maskPattern) {
5342
5216
  switch (maskPattern) {
@@ -5357,72 +5231,20 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5357
5231
  case 7:
5358
5232
  return (i, j) => (i * j % 3 + (i + j) % 2) % 2 === 0;
5359
5233
  default:
5360
- throw new Error("bad maskPattern:" + maskPattern);
5361
- }
5362
- }
5363
- function getErrorCorrectPolynomial(errorCorrectLength) {
5364
- let a = createPolynomial([1], 0);
5365
- for (let i = 0; i < errorCorrectLength; i++) {
5366
- a = a.multiply(createPolynomial([1, gexp(i)], 0));
5367
- }
5368
- return a;
5369
- }
5370
- function getLengthInBits(mode, type) {
5371
- if (1 <= type && type < 10) {
5372
- switch (mode) {
5373
- case 1:
5374
- return 10;
5375
- case 2:
5376
- return 9;
5377
- case 4:
5378
- return 8;
5379
- case 8:
5380
- return 8;
5381
- default:
5382
- throw new Error("mode:" + mode);
5383
- }
5384
- } else if (type < 27) {
5385
- switch (mode) {
5386
- case 1:
5387
- return 12;
5388
- case 2:
5389
- return 11;
5390
- case 4:
5391
- return 16;
5392
- case 8:
5393
- return 10;
5394
- default:
5395
- throw new Error("mode:" + mode);
5396
- }
5397
- } else if (type < 41) {
5398
- switch (mode) {
5399
- case 1:
5400
- return 14;
5401
- case 2:
5402
- return 13;
5403
- case 4:
5404
- return 16;
5405
- case 8:
5406
- return 12;
5407
- default:
5408
- throw new Error("mode:" + mode);
5409
- }
5410
- } else {
5411
- throw new Error("type:" + type);
5234
+ return () => false;
5412
5235
  }
5413
5236
  }
5414
5237
  function getRSBlocks(typeNumber, errorCorrectionLevel) {
5415
- const rsBlock = RS_BLOCK_TABLE[(typeNumber - 1) * 4 + errorCorrectionLevel];
5416
- if (!rsBlock) throw new Error("bad rs block");
5417
- const length = rsBlock.length / 3;
5238
+ const index = (typeNumber - 1) * 4 + errorCorrectionLevel;
5239
+ const block = RS_BLOCK_TABLE[index];
5240
+ if (!block) throw new Error("bad rs block");
5418
5241
  const list2 = [];
5242
+ const length = Math.floor(block.length / 3);
5419
5243
  for (let i = 0; i < length; i++) {
5420
- const count = rsBlock[i * 3 + 0];
5421
- const totalCount = rsBlock[i * 3 + 1];
5422
- const dataCount = rsBlock[i * 3 + 2];
5423
- for (let j = 0; j < count; j++) {
5424
- list2.push({ totalCount, dataCount });
5425
- }
5244
+ const count = block[i * 3];
5245
+ const totalCount = block[i * 3 + 1];
5246
+ const dataCount = block[i * 3 + 2];
5247
+ for (let j = 0; j < count; j++) list2.push({ totalCount, dataCount });
5426
5248
  }
5427
5249
  return list2;
5428
5250
  }
@@ -5438,335 +5260,252 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5438
5260
  return this.length;
5439
5261
  }
5440
5262
  put(num, len) {
5441
- for (let i = 0; i < len; i++) {
5442
- this.putBit((num >>> len - i - 1 & 1) === 1);
5443
- }
5263
+ for (let i = 0; i < len; i++) this.putBit((num >>> len - i - 1 & 1) === 1);
5444
5264
  }
5445
5265
  putBit(bit) {
5446
5266
  const bufIndex = Math.floor(this.length / 8);
5447
- if (this.buffer.length <= bufIndex) {
5448
- this.buffer.push(0);
5449
- }
5450
- if (bit) {
5451
- this.buffer[bufIndex] |= 128 >>> this.length % 8;
5452
- }
5267
+ if (this.buffer.length <= bufIndex) this.buffer.push(0);
5268
+ if (bit) this.buffer[bufIndex] |= 128 >>> this.length % 8;
5453
5269
  this.length++;
5454
5270
  }
5455
5271
  }
5456
5272
  function stringToBytes(s) {
5457
5273
  const bytes = [];
5458
- for (let i = 0; i < s.length; i++) {
5459
- const c = s.charCodeAt(i);
5460
- bytes.push(c & 255);
5461
- }
5274
+ for (let i = 0; i < s.length; i++) bytes.push(s.charCodeAt(i) & 255);
5462
5275
  return bytes;
5463
5276
  }
5464
- function createData(typeNumber, errorCorrectionLevel, dataList) {
5465
- const rsBlocks = getRSBlocks(typeNumber, errorCorrectionLevel);
5466
- const buffer = new BitBuffer();
5467
- for (const data of dataList) {
5468
- buffer.put(data.mode, 4);
5469
- buffer.put(stringToBytes(data.data).length, getLengthInBits(data.mode, typeNumber));
5470
- for (const byte of stringToBytes(data.data)) {
5471
- buffer.put(byte, 8);
5277
+ function getLengthInBits(mode, type) {
5278
+ if (type < 10) return mode === 4 ? 8 : 8;
5279
+ if (type < 27) return mode === 4 ? 16 : 10;
5280
+ return mode === 4 ? 16 : 12;
5281
+ }
5282
+ function multiplyPolynomials(a, b) {
5283
+ const result = new Array(a.length + b.length - 1).fill(0);
5284
+ for (let i = 0; i < a.length; i++) {
5285
+ for (let j = 0; j < b.length; j++) {
5286
+ result[i + j] ^= gexp(glog(a[i]) + glog(b[j]));
5472
5287
  }
5473
5288
  }
5474
- let totalDataCount = 0;
5475
- for (const block of rsBlocks) {
5476
- totalDataCount += block.dataCount;
5477
- }
5478
- if (buffer.getLengthInBits() > totalDataCount * 8) {
5479
- throw new Error("code length overflow");
5480
- }
5481
- if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {
5482
- buffer.put(0, 4);
5483
- }
5484
- while (buffer.getLengthInBits() % 8 !== 0) {
5485
- buffer.putBit(false);
5289
+ return result;
5290
+ }
5291
+ function modPolynomial(a, b) {
5292
+ let result = [...a];
5293
+ while (result.length >= b.length) {
5294
+ const ratio = glog(result[0]) - glog(b[0]);
5295
+ for (let i = 0; i < b.length; i++) {
5296
+ result[i] ^= gexp(glog(b[i]) + ratio);
5297
+ }
5298
+ while (result.length > 0 && result[0] === 0) result.shift();
5486
5299
  }
5487
- while (true) {
5488
- if (buffer.getLengthInBits() >= totalDataCount * 8) break;
5489
- buffer.put(PAD0, 8);
5490
- if (buffer.getLengthInBits() >= totalDataCount * 8) break;
5491
- buffer.put(PAD1, 8);
5300
+ return result;
5301
+ }
5302
+ function getErrorCorrectPolynomial(errorCorrectLength) {
5303
+ let poly = [1];
5304
+ for (let i = 0; i < errorCorrectLength; i++) {
5305
+ poly = multiplyPolynomials(poly, [1, gexp(i)]);
5492
5306
  }
5493
- return createBytes(buffer, rsBlocks);
5307
+ return poly;
5494
5308
  }
5495
- function createBytes(buffer, rsBlocks) {
5496
- let offset = 0;
5497
- let maxDcCount = 0;
5498
- let maxEcCount = 0;
5499
- const dcdata = [];
5500
- const ecdata = [];
5309
+ function createData(typeNumber, errorCorrectionLevel, data) {
5310
+ const rsBlocks = getRSBlocks(typeNumber, errorCorrectionLevel);
5311
+ let totalDataCount = 0;
5312
+ for (const block of rsBlocks) totalDataCount += block.dataCount;
5313
+ const buffer = new BitBuffer();
5314
+ buffer.put(4, 4);
5315
+ const bytes = stringToBytes(data);
5316
+ buffer.put(bytes.length, getLengthInBits(4, typeNumber));
5317
+ for (const byte of bytes) buffer.put(byte, 8);
5318
+ if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) buffer.put(0, 4);
5319
+ while (buffer.getLengthInBits() % 8 !== 0) buffer.putBit(false);
5320
+ let padIndex = 0;
5321
+ const padBytes = [PAD0, PAD1];
5322
+ while (buffer.getLengthInBits() < totalDataCount * 8) {
5323
+ buffer.put(padBytes[padIndex], 8);
5324
+ padIndex = (padIndex + 1) % 2;
5325
+ }
5326
+ const dataBuffer = buffer.getBuffer();
5327
+ let dataIndex = 0;
5328
+ const dcData = [];
5329
+ const ecData = [];
5501
5330
  for (const block of rsBlocks) {
5502
- const dcCount = block.dataCount;
5503
- const ecCount = block.totalCount - dcCount;
5504
- maxDcCount = Math.max(maxDcCount, dcCount);
5505
- maxEcCount = Math.max(maxEcCount, ecCount);
5506
- const dc = [];
5507
- for (let i = 0; i < dcCount; i++) {
5508
- dc.push(255 & buffer.getBuffer()[i + offset]);
5509
- }
5510
- dcdata.push(dc);
5511
- offset += dcCount;
5331
+ const dc = dataBuffer.slice(dataIndex, dataIndex + block.dataCount);
5332
+ dataIndex += block.dataCount;
5333
+ dcData.push(dc);
5334
+ const ecCount = block.totalCount - block.dataCount;
5512
5335
  const rsPoly = getErrorCorrectPolynomial(ecCount);
5513
- const rawPoly = createPolynomial(dc, rsPoly.getLength() - 1);
5514
- const modPoly = rawPoly.mod(rsPoly);
5515
- const ec = new Array(rsPoly.getLength() - 1).fill(0);
5516
- for (let i = 0; i < ec.length; i++) {
5517
- const modIndex = i + modPoly.getLength() - ec.length;
5518
- ec[i] = modIndex >= 0 ? modPoly.getAt(modIndex) : 0;
5519
- }
5520
- ecdata.push(ec);
5336
+ const dataPoly = [...dc, ...new Array(ecCount).fill(0)];
5337
+ const ec = modPolynomial(dataPoly, rsPoly);
5338
+ ecData.push(ec.slice(-ecCount));
5521
5339
  }
5522
5340
  const result = [];
5341
+ let maxDcCount = 0;
5342
+ let maxEcCount = 0;
5343
+ for (const block of rsBlocks) {
5344
+ maxDcCount = Math.max(maxDcCount, block.dataCount);
5345
+ maxEcCount = Math.max(maxEcCount, block.totalCount - block.dataCount);
5346
+ }
5523
5347
  for (let i = 0; i < maxDcCount; i++) {
5524
- for (let j = 0; j < dcdata.length; j++) {
5525
- if (i < dcdata[j].length) result.push(dcdata[j][i]);
5348
+ for (const dc of dcData) {
5349
+ if (i < dc.length) result.push(dc[i]);
5526
5350
  }
5527
5351
  }
5528
5352
  for (let i = 0; i < maxEcCount; i++) {
5529
- for (let j = 0; j < ecdata.length; j++) {
5530
- if (i < ecdata[j].length) result.push(ecdata[j][i]);
5353
+ for (const ec of ecData) {
5354
+ if (i < ec.length) result.push(ec[i]);
5531
5355
  }
5532
5356
  }
5533
5357
  return result;
5534
5358
  }
5535
- class QRCode {
5536
- constructor(typeNumber, errorCorrectionLevel) {
5537
- __publicField(this, "typeNumber");
5538
- __publicField(this, "errorCorrectionLevel");
5539
- __publicField(this, "modules", []);
5540
- __publicField(this, "moduleCount", 0);
5541
- __publicField(this, "dataCache", null);
5542
- this.typeNumber = typeNumber;
5543
- this.errorCorrectionLevel = QRErrorCorrectionLevel[errorCorrectionLevel];
5544
- }
5545
- addData(data) {
5546
- const dataList = [{ mode: 4, data }];
5547
- this.dataCache = createData(this.typeNumber, this.errorCorrectionLevel, dataList);
5548
- }
5549
- make() {
5550
- if (this.typeNumber < 1) {
5551
- let typeNumber = 1;
5552
- for (; typeNumber < 40; typeNumber++) {
5553
- try {
5554
- const testData = createData(typeNumber, this.errorCorrectionLevel, [{ mode: 4, data: "test" }]);
5555
- this.dataCache = createData(typeNumber, this.errorCorrectionLevel, [{ mode: 4, data: "" }]);
5556
- break;
5557
- } catch {
5558
- continue;
5559
- }
5560
- }
5561
- this.typeNumber = typeNumber;
5562
- }
5563
- this.makeImpl(false, this.getBestMaskPattern());
5564
- }
5565
- getBestMaskPattern() {
5566
- let minLostPoint = 0;
5567
- let pattern = 0;
5568
- for (let i = 0; i < 8; i++) {
5569
- this.makeImpl(true, i);
5570
- const lostPoint = this.getLostPoint();
5571
- if (i === 0 || minLostPoint > lostPoint) {
5572
- minLostPoint = lostPoint;
5573
- pattern = i;
5574
- }
5575
- }
5576
- return pattern;
5577
- }
5578
- makeImpl(test, maskPattern) {
5579
- this.moduleCount = this.typeNumber * 4 + 17;
5580
- this.modules = [];
5581
- for (let row = 0; row < this.moduleCount; row++) {
5582
- this.modules[row] = new Array(this.moduleCount).fill(null);
5583
- }
5584
- this.setupPositionProbePattern(0, 0);
5585
- this.setupPositionProbePattern(this.moduleCount - 7, 0);
5586
- this.setupPositionProbePattern(0, this.moduleCount - 7);
5587
- this.setupPositionAdjustPattern();
5588
- this.setupTimingPattern();
5589
- this.setupTypeInfo(test, maskPattern);
5590
- if (this.typeNumber >= 7) {
5591
- this.setupTypeNumber(test);
5592
- }
5593
- if (this.dataCache === null) {
5594
- throw new Error("dataCache is null");
5595
- }
5596
- this.mapData(this.dataCache, maskPattern);
5597
- }
5598
- setupPositionProbePattern(row, col) {
5359
+ function generateQRCode(text, errorLevel) {
5360
+ const ecl = QRErrorCorrectionLevel[errorLevel] ?? 0;
5361
+ let typeNumber = 1;
5362
+ for (; typeNumber <= 40; typeNumber++) {
5363
+ const rsBlocks = getRSBlocks(typeNumber, ecl);
5364
+ let totalDataCount = 0;
5365
+ for (const block of rsBlocks) totalDataCount += block.dataCount;
5366
+ const lengthBits = typeNumber < 10 ? 8 : 16;
5367
+ const totalBits = 4 + lengthBits + stringToBytes(text).length * 8;
5368
+ if (totalBits <= totalDataCount * 8) break;
5369
+ }
5370
+ const size = typeNumber * 4 + 17;
5371
+ const data = createData(typeNumber, ecl, text);
5372
+ const mod = [];
5373
+ for (let i = 0; i < size; i++) mod[i] = new Array(size).fill(null);
5374
+ const setupFinderPattern = (row, col) => {
5599
5375
  for (let r = -1; r <= 7; r++) {
5600
- if (row + r <= -1 || this.moduleCount <= row + r) continue;
5601
5376
  for (let c = -1; c <= 7; c++) {
5602
- if (col + c <= -1 || this.moduleCount <= col + c) continue;
5603
- 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) {
5604
- this.modules[row + r][col + c] = true;
5377
+ const nr = row + r, nc = col + c;
5378
+ if (nr < 0 || nr >= size || nc < 0 || nc >= size) continue;
5379
+ 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) {
5380
+ mod[nr][nc] = true;
5605
5381
  } else {
5606
- this.modules[row + r][col + c] = false;
5382
+ mod[nr][nc] = false;
5607
5383
  }
5608
5384
  }
5609
5385
  }
5610
- }
5611
- setupTimingPattern() {
5612
- for (let r = 8; r < this.moduleCount - 8; r++) {
5613
- if (this.modules[r][6] !== null) continue;
5614
- this.modules[r][6] = r % 2 === 0;
5615
- }
5616
- for (let c = 8; c < this.moduleCount - 8; c++) {
5617
- if (this.modules[6][c] !== null) continue;
5618
- this.modules[6][c] = c % 2 === 0;
5619
- }
5620
- }
5621
- setupPositionAdjustPattern() {
5622
- const pos = getPatternPosition(this.typeNumber);
5623
- for (let i = 0; i < pos.length; i++) {
5624
- for (let j = 0; j < pos.length; j++) {
5625
- const row = pos[i];
5626
- const col = pos[j];
5627
- if (this.modules[row][col] !== null) continue;
5628
- for (let r = -2; r <= 2; r++) {
5629
- for (let c = -2; c <= 2; c++) {
5630
- if (r === -2 || r === 2 || c === -2 || c === 2 || r === 0 && c === 0) {
5631
- this.modules[row + r][col + c] = true;
5632
- } else {
5633
- this.modules[row + r][col + c] = false;
5634
- }
5635
- }
5386
+ };
5387
+ setupFinderPattern(0, 0);
5388
+ setupFinderPattern(size - 7, 0);
5389
+ setupFinderPattern(0, size - 7);
5390
+ for (let i = 8; i < size - 8; i++) {
5391
+ if (mod[i][6] === null) mod[i][6] = i % 2 === 0;
5392
+ if (mod[6][i] === null) mod[6][i] = i % 2 === 0;
5393
+ }
5394
+ const alignPos = getPatternPosition(typeNumber);
5395
+ for (const row of alignPos) {
5396
+ for (const col of alignPos) {
5397
+ if (mod[row][col] !== null) continue;
5398
+ for (let r = -2; r <= 2; r++) {
5399
+ for (let c = -2; c <= 2; c++) {
5400
+ mod[row + r][col + c] = r === -2 || r === 2 || c === -2 || c === 2 || r === 0 && c === 0;
5636
5401
  }
5637
5402
  }
5638
5403
  }
5639
5404
  }
5640
- setupTypeNumber(test) {
5641
- const bits = getBCHTypeNumber(this.typeNumber);
5642
- for (let i = 0; i < 18; i++) {
5643
- const mod = !test && (bits >> i & 1) === 1;
5644
- this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod;
5645
- }
5646
- for (let i = 0; i < 18; i++) {
5647
- const mod = !test && (bits >> i & 1) === 1;
5648
- this.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)] = mod;
5649
- }
5650
- }
5651
- setupTypeInfo(test, maskPattern) {
5652
- const data = this.errorCorrectionLevel << 3 | maskPattern;
5653
- const bits = getBCHTypeInfo(data);
5654
- for (let i = 0; i < 15; i++) {
5655
- const mod = !test && (bits >> i & 1) === 1;
5656
- if (i < 6) {
5657
- this.modules[i][8] = mod;
5658
- } else if (i < 8) {
5659
- this.modules[i + 1][8] = mod;
5660
- } else {
5661
- this.modules[this.moduleCount - 15 + i][8] = mod;
5405
+ for (let i = 0; i < 9; i++) {
5406
+ if (mod[8][i] === null) mod[8][i] = false;
5407
+ if (mod[i][8] === null) mod[i][8] = false;
5408
+ }
5409
+ for (let i = 0; i < 8; i++) {
5410
+ if (mod[8][size - 1 - i] === null) mod[8][size - 1 - i] = false;
5411
+ if (mod[size - 1 - i][8] === null) mod[size - 1 - i][8] = false;
5412
+ }
5413
+ mod[size - 8][8] = true;
5414
+ if (typeNumber >= 7) {
5415
+ const bits = typeNumber;
5416
+ for (let i = 0; i < 6; i++) {
5417
+ for (let j = 0; j < 3; j++) {
5418
+ mod[i][size - 11 + j] = (bits >> i * 3 + j & 1) === 1;
5419
+ mod[size - 11 + j][i] = (bits >> i * 3 + j & 1) === 1;
5662
5420
  }
5663
5421
  }
5664
- for (let i = 0; i < 15; i++) {
5665
- const mod = !test && (bits >> i & 1) === 1;
5666
- if (i < 8) {
5667
- this.modules[8][this.moduleCount - i - 1] = mod;
5668
- } else if (i < 9) {
5669
- this.modules[8][15 - i - 1 + 1] = mod;
5670
- } else {
5671
- this.modules[8][15 - i - 1] = mod;
5672
- }
5422
+ }
5423
+ let bestMask = 0;
5424
+ let bestPenalty = Infinity;
5425
+ for (let mask = 0; mask < 8; mask++) {
5426
+ const testMod = mod.map((row) => [...row]);
5427
+ mapData(testMod, size, data, mask);
5428
+ const penalty = calculatePenalty(testMod, size);
5429
+ if (penalty < bestPenalty) {
5430
+ bestPenalty = penalty;
5431
+ bestMask = mask;
5673
5432
  }
5674
- this.modules[this.moduleCount - 8][8] = !test;
5675
- }
5676
- mapData(data, maskPattern) {
5677
- let inc = -1;
5678
- let row = this.moduleCount - 1;
5679
- let bitIndex = 7;
5680
- let byteIndex = 0;
5681
- const maskFunc = getMaskFunction(maskPattern);
5682
- for (let col = this.moduleCount - 1; col > 0; col -= 2) {
5683
- if (col === 6) col -= 1;
5684
- while (true) {
5685
- for (let c = 0; c < 2; c++) {
5686
- if (this.modules[row][col - c] === null) {
5687
- let dark = false;
5688
- if (byteIndex < data.length) {
5689
- dark = (data[byteIndex] >>> bitIndex & 1) === 1;
5690
- }
5691
- const mask = maskFunc(row, col - c);
5692
- if (mask) dark = !dark;
5693
- this.modules[row][col - c] = dark;
5694
- bitIndex--;
5695
- if (bitIndex === -1) {
5696
- byteIndex++;
5697
- bitIndex = 7;
5698
- }
5699
- }
5700
- }
5701
- row += inc;
5702
- if (row < 0 || this.moduleCount <= row) {
5703
- row -= inc;
5704
- inc = -inc;
5705
- break;
5706
- }
5707
- }
5433
+ }
5434
+ mapData(mod, size, data, bestMask);
5435
+ const formatData = ecl << 3 | bestMask;
5436
+ const formatBits = getBCHTypeInfo(formatData);
5437
+ for (let i = 0; i < 6; i++) mod[8][i] = (formatBits >> i & 1) === 1;
5438
+ mod[8][7] = (formatBits >> 6 & 1) === 1;
5439
+ mod[8][8] = (formatBits >> 7 & 1) === 1;
5440
+ mod[7][8] = (formatBits >> 8 & 1) === 1;
5441
+ for (let i = 9; i < 15; i++) mod[14 - i][8] = (formatBits >> i & 1) === 1;
5442
+ for (let i = 0; i < 8; i++) mod[8][size - 1 - i] = (formatBits >> i & 1) === 1;
5443
+ for (let i = 8; i < 15; i++) mod[size - 15 + i][8] = (formatBits >> i & 1) === 1;
5444
+ const result = [];
5445
+ for (let r = 0; r < size; r++) {
5446
+ result[r] = [];
5447
+ for (let c = 0; c < size; c++) {
5448
+ result[r][c] = mod[r][c] === true;
5708
5449
  }
5709
5450
  }
5710
- getLostPoint() {
5711
- let lostPoint = 0;
5712
- for (let row = 0; row < this.moduleCount; row++) {
5713
- for (let col = 0; col < this.moduleCount; col++) {
5714
- let sameCount = 0;
5715
- const dark = this.modules[row][col];
5716
- for (let r = -1; r <= 1; r++) {
5717
- if (row + r < 0 || this.moduleCount <= row + r) continue;
5718
- for (let c = -1; c <= 1; c++) {
5719
- if (col + c < 0 || this.moduleCount <= col + c) continue;
5720
- if (r === 0 && c === 0) continue;
5721
- if (dark === this.modules[row + r][col + c]) sameCount++;
5451
+ return { modules: result, moduleCount: size };
5452
+ }
5453
+ function mapData(mod, size, data, maskPattern) {
5454
+ const maskFunc = getMaskFunction(maskPattern);
5455
+ let bitIndex = 0;
5456
+ let inc = -1;
5457
+ let row = size - 1;
5458
+ for (let col = size - 1; col > 0; col -= 2) {
5459
+ if (col === 6) col = 5;
5460
+ while (true) {
5461
+ for (let c = 0; c < 2; c++) {
5462
+ const tc = col - c;
5463
+ if (mod[row][tc] === null) {
5464
+ let dark = false;
5465
+ if (bitIndex < data.length * 8) {
5466
+ dark = (data[Math.floor(bitIndex / 8)] >>> 7 - bitIndex % 8 & 1) === 1;
5722
5467
  }
5468
+ if (maskFunc(row, tc)) dark = !dark;
5469
+ mod[row][tc] = dark;
5470
+ bitIndex++;
5723
5471
  }
5724
- if (sameCount > 5) lostPoint += 3 + sameCount - 5;
5725
5472
  }
5726
- }
5727
- for (let row = 0; row < this.moduleCount - 1; row++) {
5728
- for (let col = 0; col < this.moduleCount - 1; col++) {
5729
- let count = 0;
5730
- if (this.modules[row][col]) count++;
5731
- if (this.modules[row + 1][col]) count++;
5732
- if (this.modules[row][col + 1]) count++;
5733
- if (this.modules[row + 1][col + 1]) count++;
5734
- if (count === 0 || count === 4) lostPoint += 3;
5473
+ row += inc;
5474
+ if (row < 0 || row >= size) {
5475
+ row -= inc;
5476
+ inc = -inc;
5477
+ break;
5735
5478
  }
5736
5479
  }
5737
- for (let row = 0; row < this.moduleCount; row++) {
5738
- for (let col = 0; col < this.moduleCount - 6; col++) {
5739
- 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]) {
5740
- lostPoint += 40;
5741
- }
5742
- }
5743
- }
5744
- for (let col = 0; col < this.moduleCount; col++) {
5745
- for (let row = 0; row < this.moduleCount - 6; row++) {
5746
- 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]) {
5747
- lostPoint += 40;
5748
- }
5749
- }
5750
- }
5751
- let darkCount = 0;
5752
- for (let col = 0; col < this.moduleCount; col++) {
5753
- for (let row = 0; row < this.moduleCount; row++) {
5754
- if (this.modules[row][col]) darkCount++;
5480
+ }
5481
+ }
5482
+ function calculatePenalty(mod, size) {
5483
+ let penalty = 0;
5484
+ for (let row = 0; row < size; row++) {
5485
+ let count = 1;
5486
+ for (let col = 1; col < size; col++) {
5487
+ if (mod[row][col] === mod[row][col - 1]) {
5488
+ count++;
5489
+ } else {
5490
+ if (count >= 5) penalty += 3 + (count - 5);
5491
+ count = 1;
5755
5492
  }
5756
5493
  }
5757
- const ratio = Math.abs(100 * darkCount / this.moduleCount / this.moduleCount - 50) / 5;
5758
- lostPoint += ratio * 10;
5759
- return lostPoint;
5760
- }
5761
- getModuleCount() {
5762
- return this.moduleCount;
5494
+ if (count >= 5) penalty += 3 + (count - 5);
5763
5495
  }
5764
- isDark(row, col) {
5765
- if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) {
5766
- throw new Error(row + "," + col);
5496
+ for (let col = 0; col < size; col++) {
5497
+ let count = 1;
5498
+ for (let row = 1; row < size; row++) {
5499
+ if (mod[row][col] === mod[row - 1][col]) {
5500
+ count++;
5501
+ } else {
5502
+ if (count >= 5) penalty += 3 + (count - 5);
5503
+ count = 1;
5504
+ }
5767
5505
  }
5768
- return this.modules[row][col] === true;
5506
+ if (count >= 5) penalty += 3 + (count - 5);
5769
5507
  }
5508
+ return penalty;
5770
5509
  }
5771
5510
  const generate = () => {
5772
5511
  if (!props.value) {
@@ -5775,19 +5514,9 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5775
5514
  return;
5776
5515
  }
5777
5516
  try {
5778
- const qr = new QRCode(0, props.errorCorrectLevel);
5779
- qr.addData(props.value);
5780
- qr.make();
5781
- const count = qr.getModuleCount();
5782
- moduleCount.value = count;
5783
- const result = [];
5784
- for (let row = 0; row < count; row++) {
5785
- result[row] = [];
5786
- for (let col = 0; col < count; col++) {
5787
- result[row][col] = qr.isDark(row, col);
5788
- }
5789
- }
5790
- modules.value = result;
5517
+ const qr = generateQRCode(props.value, props.errorCorrectLevel);
5518
+ modules.value = qr.modules;
5519
+ moduleCount.value = qr.moduleCount;
5791
5520
  } catch (e) {
5792
5521
  console.error("QR Code generation failed:", e);
5793
5522
  modules.value = [];
@@ -5829,7 +5558,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5829
5558
  };
5830
5559
  }
5831
5560
  });
5832
- const uQrcode = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-e3d52c6f"]]);
5561
+ const uQrcode = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-a6ae1830"]]);
5833
5562
  const _hoisted_1 = { class: "u-barcode" };
5834
5563
  const _hoisted_2 = ["canvas-id"];
5835
5564
  const _hoisted_3 = ["src"];