@weapp-vite/qr 1.1.0 → 1.1.2
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/README.md +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.mjs +54 -52
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ process.stdout.write(renderTerminalQrCode(content, { small: true }))
|
|
|
16
16
|
```ts
|
|
17
17
|
import { createQrCodeMatrix } from '@weapp-vite/qr'
|
|
18
18
|
|
|
19
|
-
const matrix = createQrCodeMatrix('https://vite.
|
|
19
|
+
const matrix = createQrCodeMatrix('https://vite.weapp.dev/')
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
### 解码
|
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -702,18 +702,19 @@ var AlignmentPatternFinder = class {
|
|
|
702
702
|
while (j < maxJ && !this.image.data[j + this.image.width * i]) j++;
|
|
703
703
|
let currentState = 0;
|
|
704
704
|
while (j < maxJ) {
|
|
705
|
-
if (this.image.data[j + i * this.image.width])
|
|
706
|
-
|
|
707
|
-
if (
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
705
|
+
if (this.image.data[j + i * this.image.width]) {
|
|
706
|
+
if (currentState === 1) stateCount[currentState]++;
|
|
707
|
+
else if (currentState === 2) {
|
|
708
|
+
if (this.foundPatternCross(stateCount)) {
|
|
709
|
+
const confirmed = this.handlePossibleCenter(stateCount, i, j);
|
|
710
|
+
if (confirmed != null) return confirmed;
|
|
711
|
+
}
|
|
712
|
+
stateCount[0] = stateCount[2];
|
|
713
|
+
stateCount[1] = 1;
|
|
714
|
+
stateCount[2] = 0;
|
|
715
|
+
currentState = 1;
|
|
716
|
+
} else stateCount[++currentState]++;
|
|
717
|
+
} else {
|
|
717
718
|
if (currentState === 1) currentState++;
|
|
718
719
|
stateCount[currentState]++;
|
|
719
720
|
}
|
|
@@ -734,7 +735,6 @@ var AlignmentPatternFinder = class {
|
|
|
734
735
|
* @file 二维码解析内部模块:findpat。
|
|
735
736
|
*/
|
|
736
737
|
const MIN_SKIP = 3;
|
|
737
|
-
const MAX_MODULES = 57;
|
|
738
738
|
const INTEGER_MATH_SHIFT = 8;
|
|
739
739
|
const CENTER_QUORUM = 2;
|
|
740
740
|
function orderBestPatterns(patterns) {
|
|
@@ -1005,10 +1005,12 @@ var FinderPatternFinder = class {
|
|
|
1005
1005
|
let firstConfirmedCenter = null;
|
|
1006
1006
|
for (let i = 0; i < this.possibleCenters.length; i++) {
|
|
1007
1007
|
const center = this.possibleCenters[i];
|
|
1008
|
-
if (center.count >= CENTER_QUORUM)
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1008
|
+
if (center.count >= CENTER_QUORUM) {
|
|
1009
|
+
if (firstConfirmedCenter == null) firstConfirmedCenter = center;
|
|
1010
|
+
else {
|
|
1011
|
+
this.hasSkipped = true;
|
|
1012
|
+
return Math.floor((Math.abs(firstConfirmedCenter.X - center.X) - Math.abs(firstConfirmedCenter.Y - center.Y)) / 2);
|
|
1013
|
+
}
|
|
1012
1014
|
}
|
|
1013
1015
|
}
|
|
1014
1016
|
return 0;
|
|
@@ -1037,7 +1039,7 @@ var FinderPatternFinder = class {
|
|
|
1037
1039
|
this.image = image;
|
|
1038
1040
|
const maxI = image.height;
|
|
1039
1041
|
const maxJ = image.width;
|
|
1040
|
-
let iSkip = Math.floor(3 * maxI /
|
|
1042
|
+
let iSkip = Math.floor(3 * maxI / 228);
|
|
1041
1043
|
if (iSkip < MIN_SKIP || tryHarder) iSkip = MIN_SKIP;
|
|
1042
1044
|
let done = false;
|
|
1043
1045
|
const stateCount = [
|
|
@@ -1057,39 +1059,41 @@ var FinderPatternFinder = class {
|
|
|
1057
1059
|
for (let j = 0; j < maxJ; j++) if (image.data[j + i * image.width]) {
|
|
1058
1060
|
if ((currentState & 1) === 1) currentState++;
|
|
1059
1061
|
stateCount[currentState]++;
|
|
1060
|
-
} else if ((currentState & 1) === 0)
|
|
1061
|
-
if (
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1062
|
+
} else if ((currentState & 1) === 0) {
|
|
1063
|
+
if (currentState === 4) {
|
|
1064
|
+
if (this.foundPatternCross(stateCount)) {
|
|
1065
|
+
if (this.handlePossibleCenter(stateCount, i, j)) {
|
|
1066
|
+
iSkip = 2;
|
|
1067
|
+
if (this.hasSkipped) done = this.haveMultiplyConfirmedCenters();
|
|
1068
|
+
else {
|
|
1069
|
+
const rowSkip = this.findRowSkip();
|
|
1070
|
+
if (rowSkip > stateCount[2]) {
|
|
1071
|
+
i += rowSkip - stateCount[2] - iSkip;
|
|
1072
|
+
j = maxJ - 1;
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
} else {
|
|
1076
|
+
do
|
|
1077
|
+
j++;
|
|
1078
|
+
while (j < maxJ && !image.data[j + i * image.width]);
|
|
1079
|
+
j--;
|
|
1069
1080
|
}
|
|
1081
|
+
currentState = 0;
|
|
1082
|
+
stateCount[0] = 0;
|
|
1083
|
+
stateCount[1] = 0;
|
|
1084
|
+
stateCount[2] = 0;
|
|
1085
|
+
stateCount[3] = 0;
|
|
1086
|
+
stateCount[4] = 0;
|
|
1087
|
+
} else {
|
|
1088
|
+
stateCount[0] = stateCount[2];
|
|
1089
|
+
stateCount[1] = stateCount[3];
|
|
1090
|
+
stateCount[2] = stateCount[4];
|
|
1091
|
+
stateCount[3] = 1;
|
|
1092
|
+
stateCount[4] = 0;
|
|
1093
|
+
currentState = 3;
|
|
1070
1094
|
}
|
|
1071
|
-
} else
|
|
1072
|
-
|
|
1073
|
-
j++;
|
|
1074
|
-
while (j < maxJ && !image.data[j + i * image.width]);
|
|
1075
|
-
j--;
|
|
1076
|
-
}
|
|
1077
|
-
currentState = 0;
|
|
1078
|
-
stateCount[0] = 0;
|
|
1079
|
-
stateCount[1] = 0;
|
|
1080
|
-
stateCount[2] = 0;
|
|
1081
|
-
stateCount[3] = 0;
|
|
1082
|
-
stateCount[4] = 0;
|
|
1083
|
-
} else {
|
|
1084
|
-
stateCount[0] = stateCount[2];
|
|
1085
|
-
stateCount[1] = stateCount[3];
|
|
1086
|
-
stateCount[2] = stateCount[4];
|
|
1087
|
-
stateCount[3] = 1;
|
|
1088
|
-
stateCount[4] = 0;
|
|
1089
|
-
currentState = 3;
|
|
1090
|
-
}
|
|
1091
|
-
else stateCount[++currentState]++;
|
|
1092
|
-
else stateCount[currentState]++;
|
|
1095
|
+
} else stateCount[++currentState]++;
|
|
1096
|
+
} else stateCount[currentState]++;
|
|
1093
1097
|
if (this.foundPatternCross(stateCount)) {
|
|
1094
1098
|
if (this.handlePossibleCenter(stateCount, i, maxJ)) {
|
|
1095
1099
|
iSkip = stateCount[0];
|
|
@@ -2050,9 +2054,7 @@ var QRCodeDataBlockReader = class {
|
|
|
2050
2054
|
case MODE_8BIT_BYTE:
|
|
2051
2055
|
output.push(this.get8bitByteArray(dataLength));
|
|
2052
2056
|
break;
|
|
2053
|
-
case MODE_KANJI:
|
|
2054
|
-
output.push(this.getKanjiString(dataLength));
|
|
2055
|
-
break;
|
|
2057
|
+
case MODE_KANJI: output.push(this.getKanjiString(dataLength));
|
|
2056
2058
|
}
|
|
2057
2059
|
} while (true);
|
|
2058
2060
|
return output;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-vite/qr",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.2",
|
|
5
5
|
"description": "weapp-vite 生态二维码编码、解码与终端渲染工具包",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"node": "^20.19.0 || >=22.12.0"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"sharp": "^0.
|
|
44
|
+
"sharp": "^0.35.4"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"scripts": {
|
|
51
51
|
"dev": "tsdown -w --sourcemap",
|
|
52
52
|
"build": "tsdown",
|
|
53
|
+
"fixtures:generate": "node --import tsx scripts/generate-fixtures.ts",
|
|
53
54
|
"test": "vitest run --config ./vitest.config.ts",
|
|
54
55
|
"test:dev": "vitest --config ./vitest.config.ts",
|
|
55
56
|
"test:types": "tsd",
|