@weapp-vite/qr 1.1.1 → 1.1.3

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 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.icebreaker.top/')
19
+ const matrix = createQrCodeMatrix('https://vite.weapp.dev/')
20
20
  ```
21
21
 
22
22
  ### 解码
package/dist/index.d.mts CHANGED
@@ -1,22 +1,21 @@
1
1
  import { Buffer } from "node:buffer";
2
-
3
2
  //#region src/codeType.d.ts
4
3
  /** QRCodeType 的类型定义。 */
5
4
  type QRCodeType = 'qr' | 'mini-program-code' | 'unknown';
6
5
  /** detectCodeTypeFromBuffer 的方法封装。 */
7
- declare function detectCodeTypeFromBuffer(buffer: Buffer): Promise<"qr" | "mini-program-code" | "unknown">;
6
+ export declare function detectCodeTypeFromBuffer(buffer: Buffer): Promise<"qr" | "mini-program-code" | "unknown">;
8
7
  /** detectCodeTypeFromBase64 的方法封装。 */
9
- declare function detectCodeTypeFromBase64(content: string): Promise<"qr" | "mini-program-code" | "unknown">;
8
+ export declare function detectCodeTypeFromBase64(content: string): Promise<"qr" | "mini-program-code" | "unknown">;
10
9
  /** detectCodeTypeFromFile 的方法封装。 */
11
- declare function detectCodeTypeFromFile(filePath: string): Promise<"qr" | "mini-program-code" | "unknown">;
10
+ export declare function detectCodeTypeFromFile(filePath: string): Promise<"qr" | "mini-program-code" | "unknown">;
12
11
  //#endregion
13
12
  //#region src/decode.d.ts
14
13
  /** decodeQrCodeFromBuffer 的方法封装。 */
15
- declare function decodeQrCodeFromBuffer(buffer: Buffer): Promise<string>;
14
+ export declare function decodeQrCodeFromBuffer(buffer: Buffer): Promise<string>;
16
15
  /** decodeQrCodeFromBase64 的方法封装。 */
17
- declare function decodeQrCodeFromBase64(content: string): Promise<string>;
16
+ export declare function decodeQrCodeFromBase64(content: string): Promise<string>;
18
17
  /** decodeQrCodeFromFile 的方法封装。 */
19
- declare function decodeQrCodeFromFile(filePath: string): Promise<string>;
18
+ export declare function decodeQrCodeFromFile(filePath: string): Promise<string>;
20
19
  //#endregion
21
20
  //#region src/types.d.ts
22
21
  /**
@@ -31,7 +30,7 @@ type QRCodeMatrix = boolean[][];
31
30
  //#endregion
32
31
  //#region src/encode.d.ts
33
32
  /** createQrCodeMatrix 的方法封装。 */
34
- declare function createQrCodeMatrix(input: string): QRCodeMatrix;
33
+ export declare function createQrCodeMatrix(input: string): QRCodeMatrix;
35
34
  //#endregion
36
35
  //#region src/miniProgramCode.d.ts
37
36
  interface MiniProgramCodePoint {
@@ -55,7 +54,7 @@ interface MiniProgramCodeDetectionResult {
55
54
  logoBounds?: MiniProgramCodeBounds;
56
55
  }
57
56
  /** detectMiniProgramCodeFromBuffer 的方法封装。 */
58
- declare function detectMiniProgramCodeFromBuffer(buffer: Buffer): Promise<{
57
+ export declare function detectMiniProgramCodeFromBuffer(buffer: Buffer): Promise<{
59
58
  kind: "wechat-mini-program-code";
60
59
  width: number;
61
60
  height: number;
@@ -75,7 +74,7 @@ declare function detectMiniProgramCodeFromBuffer(buffer: Buffer): Promise<{
75
74
  } | undefined;
76
75
  } | null>;
77
76
  /** detectMiniProgramCodeFromBase64 的方法封装。 */
78
- declare function detectMiniProgramCodeFromBase64(content: string): Promise<{
77
+ export declare function detectMiniProgramCodeFromBase64(content: string): Promise<{
79
78
  kind: "wechat-mini-program-code";
80
79
  width: number;
81
80
  height: number;
@@ -95,7 +94,7 @@ declare function detectMiniProgramCodeFromBase64(content: string): Promise<{
95
94
  } | undefined;
96
95
  } | null>;
97
96
  /** detectMiniProgramCodeFromFile 的方法封装。 */
98
- declare function detectMiniProgramCodeFromFile(filePath: string): Promise<{
97
+ export declare function detectMiniProgramCodeFromFile(filePath: string): Promise<{
99
98
  kind: "wechat-mini-program-code";
100
99
  width: number;
101
100
  height: number;
@@ -135,12 +134,12 @@ type QRCodeReaderConstructor = new () => QRCodeReaderInstance;
135
134
  //#endregion
136
135
  //#region src/reader/decode.d.ts
137
136
  /** decodeWithQrReader 的方法封装。 */
138
- declare function decodeWithQrReader(input: QRCodeReaderInput): Promise<QRCodeReaderResult>;
137
+ export declare function decodeWithQrReader(input: QRCodeReaderInput): Promise<QRCodeReaderResult>;
139
138
  //#endregion
140
139
  //#region src/render.d.ts
141
140
  /** renderTerminalQrCodeFromMatrix 的方法封装。 */
142
- declare function renderTerminalQrCodeFromMatrix(matrix: QRCodeMatrix, options?: QRCodeRenderOptions): string;
141
+ export declare function renderTerminalQrCodeFromMatrix(matrix: QRCodeMatrix, options?: QRCodeRenderOptions): string;
143
142
  /** renderTerminalQrCode 的方法封装。 */
144
- declare function renderTerminalQrCode(input: string, options?: QRCodeRenderOptions): string;
143
+ export declare function renderTerminalQrCode(input: string, options?: QRCodeRenderOptions): string;
145
144
  //#endregion
146
- export { type MiniProgramCodeDetectionResult, type QRCodeMatrix, type QRCodeReaderConstructor, type QRCodeReaderInput, type QRCodeReaderInstance, type QRCodeReaderResult, type QRCodeRenderOptions, type QRCodeType, createQrCodeMatrix, decodeQrCodeFromBase64, decodeQrCodeFromBuffer, decodeQrCodeFromFile, decodeWithQrReader, detectCodeTypeFromBase64, detectCodeTypeFromBuffer, detectCodeTypeFromFile, detectMiniProgramCodeFromBase64, detectMiniProgramCodeFromBuffer, detectMiniProgramCodeFromFile, renderTerminalQrCode, renderTerminalQrCodeFromMatrix };
145
+ export type { MiniProgramCodeDetectionResult, QRCodeMatrix, QRCodeReaderConstructor, QRCodeReaderInput, QRCodeReaderInstance, QRCodeReaderResult, QRCodeRenderOptions, QRCodeType };
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]) if (currentState === 1) stateCount[currentState]++;
706
- else if (currentState === 2) {
707
- if (this.foundPatternCross(stateCount)) {
708
- const confirmed = this.handlePossibleCenter(stateCount, i, j);
709
- if (confirmed != null) return confirmed;
710
- }
711
- stateCount[0] = stateCount[2];
712
- stateCount[1] = 1;
713
- stateCount[2] = 0;
714
- currentState = 1;
715
- } else stateCount[++currentState]++;
716
- else {
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) if (firstConfirmedCenter == null) firstConfirmedCenter = center;
1009
- else {
1010
- this.hasSkipped = true;
1011
- return Math.floor((Math.abs(firstConfirmedCenter.X - center.X) - Math.abs(firstConfirmedCenter.Y - center.Y)) / 2);
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 / (4 * MAX_MODULES));
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) if (currentState === 4) if (this.foundPatternCross(stateCount)) {
1061
- if (this.handlePossibleCenter(stateCount, i, j)) {
1062
- iSkip = 2;
1063
- if (this.hasSkipped) done = this.haveMultiplyConfirmedCenters();
1064
- else {
1065
- const rowSkip = this.findRowSkip();
1066
- if (rowSkip > stateCount[2]) {
1067
- i += rowSkip - stateCount[2] - iSkip;
1068
- j = maxJ - 1;
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
- do
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,11 +1,11 @@
1
1
  {
2
2
  "name": "@weapp-vite/qr",
3
3
  "type": "module",
4
- "version": "1.1.1",
4
+ "version": "1.1.3",
5
5
  "description": "weapp-vite 生态二维码编码、解码与终端渲染工具包",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
8
- "homepage": "https://github.com/weapp-vite/weapp-vite",
8
+ "homepage": "https://github.com/weapp-vite/weapp-vite#readme",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "git+https://github.com/weapp-vite/weapp-vite.git",
@@ -16,11 +16,16 @@
16
16
  },
17
17
  "keywords": [
18
18
  "weapp-vite",
19
+ "weapp",
20
+ "wechat",
21
+ "mini-program",
22
+ "miniprogram",
19
23
  "qr",
20
24
  "qrcode",
21
25
  "terminal",
22
26
  "decode",
23
- "encode"
27
+ "encode",
28
+ "vite"
24
29
  ],
25
30
  "sideEffects": false,
26
31
  "exports": {
@@ -41,7 +46,7 @@
41
46
  "node": "^20.19.0 || >=22.12.0"
42
47
  },
43
48
  "dependencies": {
44
- "sharp": "^0.35.1"
49
+ "sharp": "^0.35.4"
45
50
  },
46
51
  "publishConfig": {
47
52
  "access": "public",
@@ -50,6 +55,7 @@
50
55
  "scripts": {
51
56
  "dev": "tsdown -w --sourcemap",
52
57
  "build": "tsdown",
58
+ "fixtures:generate": "node --import tsx scripts/generate-fixtures.ts",
53
59
  "test": "vitest run --config ./vitest.config.ts",
54
60
  "test:dev": "vitest --config ./vitest.config.ts",
55
61
  "test:types": "tsd",