@weapp-vite/miniprogram-automator 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/dist/index.mjs +2 -4295
  2. package/package.json +5 -4
package/dist/index.mjs CHANGED
@@ -7,8 +7,7 @@ import { EventEmitter } from "node:events";
7
7
  import debug from "debug";
8
8
  import WebSocket from "ws";
9
9
  import fs from "node:fs/promises";
10
- import { Buffer } from "node:buffer";
11
- import sharp from "sharp";
10
+ import { decodeQrCodeFromBase64, renderTerminalQrCode } from "@weapp-vite/qr";
12
11
  //#region src/internal/compat/async.ts
13
12
  /**
14
13
  * @file 异步控制工具。
@@ -568,7 +567,7 @@ async function launchHeadlessAutomator(options) {
568
567
  }
569
568
  //#endregion
570
569
  //#region package.json
571
- var version = "1.0.0";
570
+ var version = "1.0.1";
572
571
  //#endregion
573
572
  //#region src/Native.ts
574
573
  /** Native 的实现。 */
@@ -729,4298 +728,6 @@ var Page = class Page {
729
728
  }
730
729
  };
731
730
  //#endregion
732
- //#region src/internal/qr/vendor/reader/core/result.ts
733
- /** normalizeQrCodeReaderResult 的方法封装。 */
734
- function normalizeQrCodeReaderResult(value) {
735
- if (value && typeof value === "object" && "result" in value && typeof value.result === "string") return value;
736
- throw new TypeError("Invalid QR code reader result");
737
- }
738
- //#endregion
739
- //#region src/internal/qr/vendor/reader/parse/datamask.ts
740
- /**
741
- * @file 二维码解析内部模块:datamask。
742
- */
743
- const DataMask = {};
744
- DataMask.forReference = function(reference) {
745
- if (reference < 0 || reference > 7) throw "System.ArgumentException";
746
- return DataMask.DATA_MASKS[reference];
747
- };
748
- function DataMask000() {
749
- this.unmaskBitMatrix = function(bits, dimension) {
750
- for (let i = 0; i < dimension; i++) for (let j = 0; j < dimension; j++) if (this.isMasked(i, j)) bits.flip(j, i);
751
- };
752
- this.isMasked = function(i, j) {
753
- return (i + j & 1) == 0;
754
- };
755
- }
756
- function DataMask001() {
757
- this.unmaskBitMatrix = function(bits, dimension) {
758
- for (let i = 0; i < dimension; i++) for (let j = 0; j < dimension; j++) if (this.isMasked(i, j)) bits.flip(j, i);
759
- };
760
- this.isMasked = function(i, j) {
761
- return (i & 1) == 0;
762
- };
763
- }
764
- function DataMask010() {
765
- this.unmaskBitMatrix = function(bits, dimension) {
766
- for (let i = 0; i < dimension; i++) for (let j = 0; j < dimension; j++) if (this.isMasked(i, j)) bits.flip(j, i);
767
- };
768
- this.isMasked = function(i, j) {
769
- return j % 3 == 0;
770
- };
771
- }
772
- function DataMask011() {
773
- this.unmaskBitMatrix = function(bits, dimension) {
774
- for (let i = 0; i < dimension; i++) for (let j = 0; j < dimension; j++) if (this.isMasked(i, j)) bits.flip(j, i);
775
- };
776
- this.isMasked = function(i, j) {
777
- return (i + j) % 3 == 0;
778
- };
779
- }
780
- function DataMask100() {
781
- this.unmaskBitMatrix = function(bits, dimension) {
782
- for (let i = 0; i < dimension; i++) for (let j = 0; j < dimension; j++) if (this.isMasked(i, j)) bits.flip(j, i);
783
- };
784
- this.isMasked = function(i, j) {
785
- return (URShift(i, 1) + j / 3 & 1) == 0;
786
- };
787
- }
788
- function DataMask101() {
789
- this.unmaskBitMatrix = function(bits, dimension) {
790
- for (let i = 0; i < dimension; i++) for (let j = 0; j < dimension; j++) if (this.isMasked(i, j)) bits.flip(j, i);
791
- };
792
- this.isMasked = function(i, j) {
793
- const temp = i * j;
794
- return (temp & 1) + temp % 3 == 0;
795
- };
796
- }
797
- function DataMask110() {
798
- this.unmaskBitMatrix = function(bits, dimension) {
799
- for (let i = 0; i < dimension; i++) for (let j = 0; j < dimension; j++) if (this.isMasked(i, j)) bits.flip(j, i);
800
- };
801
- this.isMasked = function(i, j) {
802
- const temp = i * j;
803
- return ((temp & 1) + temp % 3 & 1) == 0;
804
- };
805
- }
806
- function DataMask111() {
807
- this.unmaskBitMatrix = function(bits, dimension) {
808
- for (let i = 0; i < dimension; i++) for (let j = 0; j < dimension; j++) if (this.isMasked(i, j)) bits.flip(j, i);
809
- };
810
- this.isMasked = function(i, j) {
811
- return ((i + j & 1) + i * j % 3 & 1) == 0;
812
- };
813
- }
814
- DataMask.DATA_MASKS = [
815
- new DataMask000(),
816
- new DataMask001(),
817
- new DataMask010(),
818
- new DataMask011(),
819
- new DataMask100(),
820
- new DataMask101(),
821
- new DataMask110(),
822
- new DataMask111()
823
- ];
824
- //#endregion
825
- //#region src/internal/qr/vendor/reader/parse/errorlevel.ts
826
- /**
827
- * @file 二维码解析内部模块:errorlevel。
828
- */
829
- function ErrorCorrectionLevel(ordinal, bits, name) {
830
- this.ordinal_Renamed_Field = ordinal;
831
- this.bits = bits;
832
- this.name = name;
833
- }
834
- ErrorCorrectionLevel.prototype.ordinal = function() {
835
- return this.ordinal_Renamed_Field;
836
- };
837
- ErrorCorrectionLevel.forBits = function(bits) {
838
- if (bits < 0 || bits >= FOR_BITS.length) throw "ArgumentException";
839
- return FOR_BITS[bits];
840
- };
841
- var FOR_BITS = [
842
- new ErrorCorrectionLevel(1, 0, "M"),
843
- new ErrorCorrectionLevel(0, 1, "L"),
844
- new ErrorCorrectionLevel(3, 2, "H"),
845
- new ErrorCorrectionLevel(2, 3, "Q")
846
- ];
847
- //#endregion
848
- //#region src/internal/qr/vendor/reader/parse/formatinf.ts
849
- /**
850
- * @file 二维码解析内部模块:formatinf。
851
- */
852
- const FORMAT_INFO_MASK_QR = 21522;
853
- const FORMAT_INFO_DECODE_LOOKUP = [
854
- [21522, 0],
855
- [20773, 1],
856
- [24188, 2],
857
- [23371, 3],
858
- [17913, 4],
859
- [16590, 5],
860
- [20375, 6],
861
- [19104, 7],
862
- [30660, 8],
863
- [29427, 9],
864
- [32170, 10],
865
- [30877, 11],
866
- [26159, 12],
867
- [25368, 13],
868
- [27713, 14],
869
- [26998, 15],
870
- [5769, 16],
871
- [5054, 17],
872
- [7399, 18],
873
- [6608, 19],
874
- [1890, 20],
875
- [597, 21],
876
- [3340, 22],
877
- [2107, 23],
878
- [13663, 24],
879
- [12392, 25],
880
- [16177, 26],
881
- [14854, 27],
882
- [9396, 28],
883
- [8579, 29],
884
- [11994, 30],
885
- [11245, 31]
886
- ];
887
- const BITS_SET_IN_HALF_BYTE = [
888
- 0,
889
- 1,
890
- 1,
891
- 2,
892
- 1,
893
- 2,
894
- 2,
895
- 3,
896
- 1,
897
- 2,
898
- 2,
899
- 3,
900
- 2,
901
- 3,
902
- 3,
903
- 4
904
- ];
905
- function FormatInformation(formatInfo) {
906
- this.errorCorrectionLevel = ErrorCorrectionLevel.forBits(formatInfo >> 3 & 3);
907
- this.dataMask = formatInfo & 7;
908
- }
909
- FormatInformation.prototype.GetHashCode = function() {
910
- return this.errorCorrectionLevel.ordinal() << 3 | this.dataMask;
911
- };
912
- FormatInformation.prototype.Equals = function(o) {
913
- const other = o;
914
- return this.errorCorrectionLevel == other.errorCorrectionLevel && this.dataMask == other.dataMask;
915
- };
916
- FormatInformation.numBitsDiffering = function(a, b) {
917
- a ^= b;
918
- return BITS_SET_IN_HALF_BYTE[a & 15] + BITS_SET_IN_HALF_BYTE[URShift(a, 4) & 15] + BITS_SET_IN_HALF_BYTE[URShift(a, 8) & 15] + BITS_SET_IN_HALF_BYTE[URShift(a, 12) & 15] + BITS_SET_IN_HALF_BYTE[URShift(a, 16) & 15] + BITS_SET_IN_HALF_BYTE[URShift(a, 20) & 15] + BITS_SET_IN_HALF_BYTE[URShift(a, 24) & 15] + BITS_SET_IN_HALF_BYTE[URShift(a, 28) & 15];
919
- };
920
- FormatInformation.decodeFormatInformation = function(maskedFormatInfo) {
921
- const formatInfo = FormatInformation.doDecodeFormatInformation(maskedFormatInfo);
922
- if (formatInfo != null) return formatInfo;
923
- return FormatInformation.doDecodeFormatInformation(maskedFormatInfo ^ FORMAT_INFO_MASK_QR);
924
- };
925
- FormatInformation.doDecodeFormatInformation = function(maskedFormatInfo) {
926
- let bestDifference = 4294967295;
927
- let bestFormatInfo = 0;
928
- for (let i = 0; i < FORMAT_INFO_DECODE_LOOKUP.length; i++) {
929
- const decodeInfo = FORMAT_INFO_DECODE_LOOKUP[i];
930
- const targetInfo = decodeInfo[0];
931
- if (targetInfo == maskedFormatInfo) return new FormatInformation(decodeInfo[1]);
932
- const bitsDifference = this.numBitsDiffering(maskedFormatInfo, targetInfo);
933
- if (bitsDifference < bestDifference) {
934
- bestFormatInfo = decodeInfo[1];
935
- bestDifference = bitsDifference;
936
- }
937
- }
938
- if (bestDifference <= 3) return new FormatInformation(bestFormatInfo);
939
- return null;
940
- };
941
- //#endregion
942
- //#region src/internal/qr/vendor/reader/parse/bitmat.ts
943
- /**
944
- * @file 二维码解析内部模块:bitmat。
945
- */
946
- function BitMatrix(width, height) {
947
- if (!height) height = width;
948
- if (width < 1 || height < 1) throw "Both dimensions must be greater than 0";
949
- this.width = width;
950
- this.height = height;
951
- let rowSize = width >> 5;
952
- if ((width & 31) != 0) rowSize++;
953
- this.rowSize = rowSize;
954
- this.bits = new Array(rowSize * height);
955
- for (let i = 0; i < this.bits.length; i++) this.bits[i] = 0;
956
- }
957
- Object.defineProperty(BitMatrix.prototype, "Dimension", { get() {
958
- if (this.width != this.height) throw "Can't call getDimension() on a non-square matrix";
959
- return this.width;
960
- } });
961
- BitMatrix.prototype.get_Renamed = function(x, y) {
962
- const offset = y * this.rowSize + (x >> 5);
963
- return (URShift(this.bits[offset], x & 31) & 1) != 0;
964
- };
965
- BitMatrix.prototype.set_Renamed = function(x, y) {
966
- const offset = y * this.rowSize + (x >> 5);
967
- this.bits[offset] |= 1 << (x & 31);
968
- };
969
- BitMatrix.prototype.flip = function(x, y) {
970
- const offset = y * this.rowSize + (x >> 5);
971
- this.bits[offset] ^= 1 << (x & 31);
972
- };
973
- BitMatrix.prototype.clear = function() {
974
- const max = this.bits.length;
975
- for (let i = 0; i < max; i++) this.bits[i] = 0;
976
- };
977
- BitMatrix.prototype.setRegion = function(left, top, width, height) {
978
- if (top < 0 || left < 0) throw "Left and top must be nonnegative";
979
- if (height < 1 || width < 1) throw "Height and width must be at least 1";
980
- const right = left + width;
981
- const bottom = top + height;
982
- if (bottom > this.height || right > this.width) throw "The region must fit inside the matrix";
983
- for (let y = top; y < bottom; y++) {
984
- const offset = y * this.rowSize;
985
- for (let x = left; x < right; x++) this.bits[offset + (x >> 5)] |= 1 << (x & 31);
986
- }
987
- };
988
- //#endregion
989
- //#region src/internal/qr/vendor/reader/parse/version.ts
990
- /**
991
- * @file 二维码解析内部模块:version。
992
- */
993
- function ECB(count, dataCodewords) {
994
- this.count = count;
995
- this.dataCodewords = dataCodewords;
996
- }
997
- function ECBlocks(ecCodewordsPerBlock, ecBlocks1, ecBlocks2) {
998
- this.ecCodewordsPerBlock = ecCodewordsPerBlock;
999
- if (ecBlocks2) this.ecBlocks = [ecBlocks1, ecBlocks2];
1000
- else this.ecBlocks = [ecBlocks1];
1001
- }
1002
- Object.defineProperty(ECBlocks.prototype, "TotalECCodewords", { get() {
1003
- return this.ecCodewordsPerBlock * this.NumBlocks;
1004
- } });
1005
- Object.defineProperty(ECBlocks.prototype, "NumBlocks", { get() {
1006
- let total = 0;
1007
- for (let i = 0; i < this.ecBlocks.length; i++) total += this.ecBlocks[i].length;
1008
- return total;
1009
- } });
1010
- ECBlocks.prototype.getECBlocks = function() {
1011
- return this.ecBlocks;
1012
- };
1013
- function Version(versionNumber, alignmentPatternCenters, ecBlocks1, ecBlocks2, ecBlocks3, ecBlocks4) {
1014
- this.versionNumber = versionNumber;
1015
- this.alignmentPatternCenters = alignmentPatternCenters;
1016
- this.ecBlocks = [
1017
- ecBlocks1,
1018
- ecBlocks2,
1019
- ecBlocks3,
1020
- ecBlocks4
1021
- ];
1022
- let total = 0;
1023
- const ecCodewords = ecBlocks1.ecCodewordsPerBlock;
1024
- const ecbArray = ecBlocks1.getECBlocks();
1025
- for (let i = 0; i < ecbArray.length; i++) {
1026
- const ecBlock = ecbArray[i];
1027
- total += ecBlock.count * (ecBlock.dataCodewords + ecCodewords);
1028
- }
1029
- this.totalCodewords = total;
1030
- }
1031
- Object.defineProperty(Version.prototype, "DimensionForVersion", { get() {
1032
- return 17 + 4 * this.versionNumber;
1033
- } });
1034
- Version.prototype.buildFunctionPattern = function() {
1035
- const dimension = this.DimensionForVersion;
1036
- const bitMatrix = new BitMatrix(dimension);
1037
- bitMatrix.setRegion(0, 0, 9, 9);
1038
- bitMatrix.setRegion(dimension - 8, 0, 8, 9);
1039
- bitMatrix.setRegion(0, dimension - 8, 9, 8);
1040
- const max = this.alignmentPatternCenters.length;
1041
- for (let x = 0; x < max; x++) {
1042
- const i = this.alignmentPatternCenters[x] - 2;
1043
- for (let y = 0; y < max; y++) {
1044
- if (x == 0 && (y == 0 || y == max - 1) || x == max - 1 && y == 0) continue;
1045
- bitMatrix.setRegion(this.alignmentPatternCenters[y] - 2, i, 5, 5);
1046
- }
1047
- }
1048
- bitMatrix.setRegion(6, 9, 1, dimension - 17);
1049
- bitMatrix.setRegion(9, 6, dimension - 17, 1);
1050
- if (this.versionNumber > 6) {
1051
- bitMatrix.setRegion(dimension - 11, 0, 3, 6);
1052
- bitMatrix.setRegion(0, dimension - 11, 6, 3);
1053
- }
1054
- return bitMatrix;
1055
- };
1056
- Version.prototype.getECBlocksForLevel = function(ecLevel) {
1057
- return this.ecBlocks[ecLevel.ordinal()];
1058
- };
1059
- Version.VERSION_DECODE_INFO = [
1060
- 31892,
1061
- 34236,
1062
- 39577,
1063
- 42195,
1064
- 48118,
1065
- 51042,
1066
- 55367,
1067
- 58893,
1068
- 63784,
1069
- 68472,
1070
- 70749,
1071
- 76311,
1072
- 79154,
1073
- 84390,
1074
- 87683,
1075
- 92361,
1076
- 96236,
1077
- 102084,
1078
- 102881,
1079
- 110507,
1080
- 110734,
1081
- 117786,
1082
- 119615,
1083
- 126325,
1084
- 127568,
1085
- 133589,
1086
- 136944,
1087
- 141498,
1088
- 145311,
1089
- 150283,
1090
- 152622,
1091
- 158308,
1092
- 161089,
1093
- 167017
1094
- ];
1095
- Version.VERSIONS = buildVersions();
1096
- Version.getVersionForNumber = function(versionNumber) {
1097
- if (versionNumber < 1 || versionNumber > 40) throw "ArgumentException";
1098
- return Version.VERSIONS[versionNumber - 1];
1099
- };
1100
- Version.getProvisionalVersionForDimension = function(dimension) {
1101
- if (dimension % 4 != 1) throw "Error getProvisionalVersionForDimension";
1102
- try {
1103
- return Version.getVersionForNumber(dimension - 17 >> 2);
1104
- } catch (iae) {
1105
- throw "Error getVersionForNumber";
1106
- }
1107
- };
1108
- Version.decodeVersionInformation = function(versionBits) {
1109
- let bestDifference = 4294967295;
1110
- let bestVersion = 0;
1111
- for (let i = 0; i < Version.VERSION_DECODE_INFO.length; i++) {
1112
- const targetVersion = Version.VERSION_DECODE_INFO[i];
1113
- if (targetVersion == versionBits) return this.getVersionForNumber(i + 7);
1114
- const bitsDifference = FormatInformation.numBitsDiffering(versionBits, targetVersion);
1115
- if (bitsDifference < bestDifference) {
1116
- bestVersion = i + 7;
1117
- bestDifference = bitsDifference;
1118
- }
1119
- }
1120
- if (bestDifference <= 3) return this.getVersionForNumber(bestVersion);
1121
- return null;
1122
- };
1123
- function buildVersions() {
1124
- return [
1125
- new Version(1, [], new ECBlocks(7, new ECB(1, 19)), new ECBlocks(10, new ECB(1, 16)), new ECBlocks(13, new ECB(1, 13)), new ECBlocks(17, new ECB(1, 9))),
1126
- new Version(2, [6, 18], new ECBlocks(10, new ECB(1, 34)), new ECBlocks(16, new ECB(1, 28)), new ECBlocks(22, new ECB(1, 22)), new ECBlocks(28, new ECB(1, 16))),
1127
- new Version(3, [6, 22], new ECBlocks(15, new ECB(1, 55)), new ECBlocks(26, new ECB(1, 44)), new ECBlocks(18, new ECB(2, 17)), new ECBlocks(22, new ECB(2, 13))),
1128
- new Version(4, [6, 26], new ECBlocks(20, new ECB(1, 80)), new ECBlocks(18, new ECB(2, 32)), new ECBlocks(26, new ECB(2, 24)), new ECBlocks(16, new ECB(4, 9))),
1129
- new Version(5, [6, 30], new ECBlocks(26, new ECB(1, 108)), new ECBlocks(24, new ECB(2, 43)), new ECBlocks(18, new ECB(2, 15), new ECB(2, 16)), new ECBlocks(22, new ECB(2, 11), new ECB(2, 12))),
1130
- new Version(6, [6, 34], new ECBlocks(18, new ECB(2, 68)), new ECBlocks(16, new ECB(4, 27)), new ECBlocks(24, new ECB(4, 19)), new ECBlocks(28, new ECB(4, 15))),
1131
- new Version(7, [
1132
- 6,
1133
- 22,
1134
- 38
1135
- ], new ECBlocks(20, new ECB(2, 78)), new ECBlocks(18, new ECB(4, 31)), new ECBlocks(18, new ECB(2, 14), new ECB(4, 15)), new ECBlocks(26, new ECB(4, 13), new ECB(1, 14))),
1136
- new Version(8, [
1137
- 6,
1138
- 24,
1139
- 42
1140
- ], new ECBlocks(24, new ECB(2, 97)), new ECBlocks(22, new ECB(2, 38), new ECB(2, 39)), new ECBlocks(22, new ECB(4, 18), new ECB(2, 19)), new ECBlocks(26, new ECB(4, 14), new ECB(2, 15))),
1141
- new Version(9, [
1142
- 6,
1143
- 26,
1144
- 46
1145
- ], new ECBlocks(30, new ECB(2, 116)), new ECBlocks(22, new ECB(3, 36), new ECB(2, 37)), new ECBlocks(20, new ECB(4, 16), new ECB(4, 17)), new ECBlocks(24, new ECB(4, 12), new ECB(4, 13))),
1146
- new Version(10, [
1147
- 6,
1148
- 28,
1149
- 50
1150
- ], new ECBlocks(18, new ECB(2, 68), new ECB(2, 69)), new ECBlocks(26, new ECB(4, 43), new ECB(1, 44)), new ECBlocks(24, new ECB(6, 19), new ECB(2, 20)), new ECBlocks(28, new ECB(6, 15), new ECB(2, 16))),
1151
- new Version(11, [
1152
- 6,
1153
- 30,
1154
- 54
1155
- ], new ECBlocks(20, new ECB(4, 81)), new ECBlocks(30, new ECB(1, 50), new ECB(4, 51)), new ECBlocks(28, new ECB(4, 22), new ECB(4, 23)), new ECBlocks(24, new ECB(3, 12), new ECB(8, 13))),
1156
- new Version(12, [
1157
- 6,
1158
- 32,
1159
- 58
1160
- ], new ECBlocks(24, new ECB(2, 92), new ECB(2, 93)), new ECBlocks(22, new ECB(6, 36), new ECB(2, 37)), new ECBlocks(26, new ECB(4, 20), new ECB(6, 21)), new ECBlocks(28, new ECB(7, 14), new ECB(4, 15))),
1161
- new Version(13, [
1162
- 6,
1163
- 34,
1164
- 62
1165
- ], new ECBlocks(26, new ECB(4, 107)), new ECBlocks(22, new ECB(8, 37), new ECB(1, 38)), new ECBlocks(24, new ECB(8, 20), new ECB(4, 21)), new ECBlocks(22, new ECB(12, 11), new ECB(4, 12))),
1166
- new Version(14, [
1167
- 6,
1168
- 26,
1169
- 46,
1170
- 66
1171
- ], new ECBlocks(30, new ECB(3, 115), new ECB(1, 116)), new ECBlocks(24, new ECB(4, 40), new ECB(5, 41)), new ECBlocks(20, new ECB(11, 16), new ECB(5, 17)), new ECBlocks(24, new ECB(11, 12), new ECB(5, 13))),
1172
- new Version(15, [
1173
- 6,
1174
- 26,
1175
- 48,
1176
- 70
1177
- ], new ECBlocks(22, new ECB(5, 87), new ECB(1, 88)), new ECBlocks(24, new ECB(5, 41), new ECB(5, 42)), new ECBlocks(30, new ECB(5, 24), new ECB(7, 25)), new ECBlocks(24, new ECB(11, 12), new ECB(7, 13))),
1178
- new Version(16, [
1179
- 6,
1180
- 26,
1181
- 50,
1182
- 74
1183
- ], new ECBlocks(24, new ECB(5, 98), new ECB(1, 99)), new ECBlocks(28, new ECB(7, 45), new ECB(3, 46)), new ECBlocks(24, new ECB(15, 19), new ECB(2, 20)), new ECBlocks(30, new ECB(3, 15), new ECB(13, 16))),
1184
- new Version(17, [
1185
- 6,
1186
- 30,
1187
- 54,
1188
- 78
1189
- ], new ECBlocks(28, new ECB(1, 107), new ECB(5, 108)), new ECBlocks(28, new ECB(10, 46), new ECB(1, 47)), new ECBlocks(28, new ECB(1, 22), new ECB(15, 23)), new ECBlocks(28, new ECB(2, 14), new ECB(17, 15))),
1190
- new Version(18, [
1191
- 6,
1192
- 30,
1193
- 56,
1194
- 82
1195
- ], new ECBlocks(30, new ECB(5, 120), new ECB(1, 121)), new ECBlocks(26, new ECB(9, 43), new ECB(4, 44)), new ECBlocks(28, new ECB(17, 22), new ECB(1, 23)), new ECBlocks(28, new ECB(2, 14), new ECB(19, 15))),
1196
- new Version(19, [
1197
- 6,
1198
- 30,
1199
- 58,
1200
- 86
1201
- ], new ECBlocks(28, new ECB(3, 113), new ECB(4, 114)), new ECBlocks(26, new ECB(3, 44), new ECB(11, 45)), new ECBlocks(26, new ECB(17, 21), new ECB(4, 22)), new ECBlocks(26, new ECB(9, 13), new ECB(16, 14))),
1202
- new Version(20, [
1203
- 6,
1204
- 34,
1205
- 62,
1206
- 90
1207
- ], new ECBlocks(28, new ECB(3, 107), new ECB(5, 108)), new ECBlocks(26, new ECB(3, 41), new ECB(13, 42)), new ECBlocks(30, new ECB(15, 24), new ECB(5, 25)), new ECBlocks(28, new ECB(15, 15), new ECB(10, 16))),
1208
- new Version(21, [
1209
- 6,
1210
- 28,
1211
- 50,
1212
- 72,
1213
- 94
1214
- ], new ECBlocks(28, new ECB(4, 116), new ECB(4, 117)), new ECBlocks(26, new ECB(17, 42)), new ECBlocks(28, new ECB(17, 22), new ECB(6, 23)), new ECBlocks(30, new ECB(19, 16), new ECB(6, 17))),
1215
- new Version(22, [
1216
- 6,
1217
- 26,
1218
- 50,
1219
- 74,
1220
- 98
1221
- ], new ECBlocks(28, new ECB(2, 111), new ECB(7, 112)), new ECBlocks(28, new ECB(17, 46)), new ECBlocks(30, new ECB(7, 24), new ECB(16, 25)), new ECBlocks(24, new ECB(34, 13))),
1222
- new Version(23, [
1223
- 6,
1224
- 30,
1225
- 54,
1226
- 74,
1227
- 102
1228
- ], new ECBlocks(30, new ECB(4, 121), new ECB(5, 122)), new ECBlocks(28, new ECB(4, 47), new ECB(14, 48)), new ECBlocks(30, new ECB(11, 24), new ECB(14, 25)), new ECBlocks(30, new ECB(16, 15), new ECB(14, 16))),
1229
- new Version(24, [
1230
- 6,
1231
- 28,
1232
- 54,
1233
- 80,
1234
- 106
1235
- ], new ECBlocks(30, new ECB(6, 117), new ECB(4, 118)), new ECBlocks(28, new ECB(6, 45), new ECB(14, 46)), new ECBlocks(30, new ECB(11, 24), new ECB(16, 25)), new ECBlocks(30, new ECB(30, 16), new ECB(2, 17))),
1236
- new Version(25, [
1237
- 6,
1238
- 32,
1239
- 58,
1240
- 84,
1241
- 110
1242
- ], new ECBlocks(26, new ECB(8, 106), new ECB(4, 107)), new ECBlocks(28, new ECB(8, 47), new ECB(13, 48)), new ECBlocks(30, new ECB(7, 24), new ECB(22, 25)), new ECBlocks(30, new ECB(22, 15), new ECB(13, 16))),
1243
- new Version(26, [
1244
- 6,
1245
- 30,
1246
- 58,
1247
- 86,
1248
- 114
1249
- ], new ECBlocks(28, new ECB(10, 114), new ECB(2, 115)), new ECBlocks(28, new ECB(19, 46), new ECB(4, 47)), new ECBlocks(28, new ECB(28, 22), new ECB(6, 23)), new ECBlocks(30, new ECB(33, 16), new ECB(4, 17))),
1250
- new Version(27, [
1251
- 6,
1252
- 34,
1253
- 62,
1254
- 90,
1255
- 118
1256
- ], new ECBlocks(30, new ECB(8, 122), new ECB(4, 123)), new ECBlocks(28, new ECB(22, 45), new ECB(3, 46)), new ECBlocks(30, new ECB(8, 23), new ECB(26, 24)), new ECBlocks(30, new ECB(12, 15), new ECB(28, 16))),
1257
- new Version(28, [
1258
- 6,
1259
- 26,
1260
- 50,
1261
- 74,
1262
- 98,
1263
- 122
1264
- ], new ECBlocks(30, new ECB(3, 117), new ECB(10, 118)), new ECBlocks(28, new ECB(3, 45), new ECB(23, 46)), new ECBlocks(30, new ECB(4, 24), new ECB(31, 25)), new ECBlocks(30, new ECB(11, 15), new ECB(31, 16))),
1265
- new Version(29, [
1266
- 6,
1267
- 30,
1268
- 54,
1269
- 78,
1270
- 102,
1271
- 126
1272
- ], new ECBlocks(30, new ECB(7, 116), new ECB(7, 117)), new ECBlocks(28, new ECB(21, 45), new ECB(7, 46)), new ECBlocks(30, new ECB(1, 23), new ECB(37, 24)), new ECBlocks(30, new ECB(19, 15), new ECB(26, 16))),
1273
- new Version(30, [
1274
- 6,
1275
- 26,
1276
- 52,
1277
- 78,
1278
- 104,
1279
- 130
1280
- ], new ECBlocks(30, new ECB(5, 115), new ECB(10, 116)), new ECBlocks(28, new ECB(19, 47), new ECB(10, 48)), new ECBlocks(30, new ECB(15, 24), new ECB(25, 25)), new ECBlocks(30, new ECB(23, 15), new ECB(25, 16))),
1281
- new Version(31, [
1282
- 6,
1283
- 30,
1284
- 56,
1285
- 82,
1286
- 108,
1287
- 134
1288
- ], new ECBlocks(30, new ECB(13, 115), new ECB(3, 116)), new ECBlocks(28, new ECB(2, 46), new ECB(29, 47)), new ECBlocks(30, new ECB(42, 24), new ECB(1, 25)), new ECBlocks(30, new ECB(23, 15), new ECB(28, 16))),
1289
- new Version(32, [
1290
- 6,
1291
- 34,
1292
- 60,
1293
- 86,
1294
- 112,
1295
- 138
1296
- ], new ECBlocks(30, new ECB(17, 115)), new ECBlocks(28, new ECB(10, 46), new ECB(23, 47)), new ECBlocks(30, new ECB(10, 24), new ECB(35, 25)), new ECBlocks(30, new ECB(19, 15), new ECB(35, 16))),
1297
- new Version(33, [
1298
- 6,
1299
- 30,
1300
- 58,
1301
- 86,
1302
- 114,
1303
- 142
1304
- ], new ECBlocks(30, new ECB(17, 115), new ECB(1, 116)), new ECBlocks(28, new ECB(14, 46), new ECB(21, 47)), new ECBlocks(30, new ECB(29, 24), new ECB(19, 25)), new ECBlocks(30, new ECB(11, 15), new ECB(46, 16))),
1305
- new Version(34, [
1306
- 6,
1307
- 34,
1308
- 62,
1309
- 90,
1310
- 118,
1311
- 146
1312
- ], new ECBlocks(30, new ECB(13, 115), new ECB(6, 116)), new ECBlocks(28, new ECB(14, 46), new ECB(23, 47)), new ECBlocks(30, new ECB(44, 24), new ECB(7, 25)), new ECBlocks(30, new ECB(59, 16), new ECB(1, 17))),
1313
- new Version(35, [
1314
- 6,
1315
- 30,
1316
- 54,
1317
- 78,
1318
- 102,
1319
- 126,
1320
- 150
1321
- ], new ECBlocks(30, new ECB(12, 121), new ECB(7, 122)), new ECBlocks(28, new ECB(12, 47), new ECB(26, 48)), new ECBlocks(30, new ECB(39, 24), new ECB(14, 25)), new ECBlocks(30, new ECB(22, 15), new ECB(41, 16))),
1322
- new Version(36, [
1323
- 6,
1324
- 24,
1325
- 50,
1326
- 76,
1327
- 102,
1328
- 128,
1329
- 154
1330
- ], new ECBlocks(30, new ECB(6, 121), new ECB(14, 122)), new ECBlocks(28, new ECB(6, 47), new ECB(34, 48)), new ECBlocks(30, new ECB(46, 24), new ECB(10, 25)), new ECBlocks(30, new ECB(2, 15), new ECB(64, 16))),
1331
- new Version(37, [
1332
- 6,
1333
- 28,
1334
- 54,
1335
- 80,
1336
- 106,
1337
- 132,
1338
- 158
1339
- ], new ECBlocks(30, new ECB(17, 122), new ECB(4, 123)), new ECBlocks(28, new ECB(29, 46), new ECB(14, 47)), new ECBlocks(30, new ECB(49, 24), new ECB(10, 25)), new ECBlocks(30, new ECB(24, 15), new ECB(46, 16))),
1340
- new Version(38, [
1341
- 6,
1342
- 32,
1343
- 58,
1344
- 84,
1345
- 110,
1346
- 136,
1347
- 162
1348
- ], new ECBlocks(30, new ECB(4, 122), new ECB(18, 123)), new ECBlocks(28, new ECB(13, 46), new ECB(32, 47)), new ECBlocks(30, new ECB(48, 24), new ECB(14, 25)), new ECBlocks(30, new ECB(42, 15), new ECB(32, 16))),
1349
- new Version(39, [
1350
- 6,
1351
- 26,
1352
- 54,
1353
- 82,
1354
- 110,
1355
- 138,
1356
- 166
1357
- ], new ECBlocks(30, new ECB(20, 117), new ECB(4, 118)), new ECBlocks(28, new ECB(40, 47), new ECB(7, 48)), new ECBlocks(30, new ECB(43, 24), new ECB(22, 25)), new ECBlocks(30, new ECB(10, 15), new ECB(67, 16))),
1358
- new Version(40, [
1359
- 6,
1360
- 30,
1361
- 58,
1362
- 86,
1363
- 114,
1364
- 142,
1365
- 170
1366
- ], new ECBlocks(30, new ECB(19, 118), new ECB(6, 119)), new ECBlocks(28, new ECB(18, 47), new ECB(31, 48)), new ECBlocks(30, new ECB(34, 24), new ECB(34, 25)), new ECBlocks(30, new ECB(20, 15), new ECB(61, 16)))
1367
- ];
1368
- }
1369
- //#endregion
1370
- //#region src/internal/qr/vendor/reader/parse/bmparser.ts
1371
- /**
1372
- * @file 二维码解析内部模块:bmparser。
1373
- */
1374
- function BitMatrixParser(bitMatrix) {
1375
- const dimension = bitMatrix.Dimension;
1376
- if (dimension < 21 || (dimension & 3) != 1) throw "Error BitMatrixParser";
1377
- this.bitMatrix = bitMatrix;
1378
- this.parsedVersion = null;
1379
- this.parsedFormatInfo = null;
1380
- }
1381
- BitMatrixParser.prototype.copyBit = function(i, j, versionBits) {
1382
- return this.bitMatrix.get_Renamed(i, j) ? versionBits << 1 | 1 : versionBits << 1;
1383
- };
1384
- BitMatrixParser.prototype.readFormatInformation = function() {
1385
- if (this.parsedFormatInfo != null) return this.parsedFormatInfo;
1386
- let formatInfoBits = 0;
1387
- for (var i = 0; i < 6; i++) formatInfoBits = this.copyBit(i, 8, formatInfoBits);
1388
- formatInfoBits = this.copyBit(7, 8, formatInfoBits);
1389
- formatInfoBits = this.copyBit(8, 8, formatInfoBits);
1390
- formatInfoBits = this.copyBit(8, 7, formatInfoBits);
1391
- for (var j = 5; j >= 0; j--) formatInfoBits = this.copyBit(8, j, formatInfoBits);
1392
- this.parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits);
1393
- if (this.parsedFormatInfo != null) return this.parsedFormatInfo;
1394
- const dimension = this.bitMatrix.Dimension;
1395
- formatInfoBits = 0;
1396
- const iMin = dimension - 8;
1397
- for (var i = dimension - 1; i >= iMin; i--) formatInfoBits = this.copyBit(i, 8, formatInfoBits);
1398
- for (var j = dimension - 7; j < dimension; j++) formatInfoBits = this.copyBit(8, j, formatInfoBits);
1399
- this.parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits);
1400
- if (this.parsedFormatInfo != null) return this.parsedFormatInfo;
1401
- throw "Error readFormatInformation";
1402
- };
1403
- BitMatrixParser.prototype.readVersion = function() {
1404
- if (this.parsedVersion != null) return this.parsedVersion;
1405
- const dimension = this.bitMatrix.Dimension;
1406
- const provisionalVersion = dimension - 17 >> 2;
1407
- if (provisionalVersion <= 6) return Version.getVersionForNumber(provisionalVersion);
1408
- let versionBits = 0;
1409
- const ijMin = dimension - 11;
1410
- for (var j = 5; j >= 0; j--) for (var i = dimension - 9; i >= ijMin; i--) versionBits = this.copyBit(i, j, versionBits);
1411
- this.parsedVersion = Version.decodeVersionInformation(versionBits);
1412
- if (this.parsedVersion != null && this.parsedVersion.DimensionForVersion == dimension) return this.parsedVersion;
1413
- versionBits = 0;
1414
- for (var i = 5; i >= 0; i--) for (var j = dimension - 9; j >= ijMin; j--) versionBits = this.copyBit(i, j, versionBits);
1415
- this.parsedVersion = Version.decodeVersionInformation(versionBits);
1416
- if (this.parsedVersion != null && this.parsedVersion.DimensionForVersion == dimension) return this.parsedVersion;
1417
- throw "Error readVersion";
1418
- };
1419
- BitMatrixParser.prototype.readCodewords = function() {
1420
- const formatInfo = this.readFormatInformation();
1421
- const version = this.readVersion();
1422
- const dataMask = DataMask.forReference(formatInfo.dataMask);
1423
- const dimension = this.bitMatrix.Dimension;
1424
- dataMask.unmaskBitMatrix(this.bitMatrix, dimension);
1425
- const functionPattern = version.buildFunctionPattern();
1426
- let readingUp = true;
1427
- const result = new Array(version.totalCodewords);
1428
- let resultOffset = 0;
1429
- let currentByte = 0;
1430
- let bitsRead = 0;
1431
- for (let j = dimension - 1; j > 0; j -= 2) {
1432
- if (j == 6) j--;
1433
- for (let count = 0; count < dimension; count++) {
1434
- const i = readingUp ? dimension - 1 - count : count;
1435
- for (let col = 0; col < 2; col++) if (!functionPattern.get_Renamed(j - col, i)) {
1436
- bitsRead++;
1437
- currentByte <<= 1;
1438
- if (this.bitMatrix.get_Renamed(j - col, i)) currentByte |= 1;
1439
- if (bitsRead == 8) {
1440
- result[resultOffset++] = currentByte;
1441
- bitsRead = 0;
1442
- currentByte = 0;
1443
- }
1444
- }
1445
- }
1446
- readingUp ^= true;
1447
- }
1448
- if (resultOffset != version.totalCodewords) throw "Error readCodewords";
1449
- return result;
1450
- };
1451
- //#endregion
1452
- //#region src/internal/qr/vendor/reader/parse/datablock.ts
1453
- /**
1454
- * @file 二维码解析内部模块:datablock。
1455
- */
1456
- function DataBlock(numDataCodewords, codewords) {
1457
- this.numDataCodewords = numDataCodewords;
1458
- this.codewords = codewords;
1459
- }
1460
- DataBlock.getDataBlocks = function(rawCodewords, version, ecLevel) {
1461
- if (rawCodewords.length != version.totalCodewords) throw "ArgumentException";
1462
- const ecBlocks = version.getECBlocksForLevel(ecLevel);
1463
- let totalBlocks = 0;
1464
- const ecBlockArray = ecBlocks.getECBlocks();
1465
- for (var i = 0; i < ecBlockArray.length; i++) totalBlocks += ecBlockArray[i].count;
1466
- const result = new Array(totalBlocks);
1467
- let numResultBlocks = 0;
1468
- for (var j = 0; j < ecBlockArray.length; j++) {
1469
- const ecBlock = ecBlockArray[j];
1470
- for (var i = 0; i < ecBlock.count; i++) {
1471
- const numDataCodewords = ecBlock.dataCodewords;
1472
- const numBlockCodewords = ecBlocks.ecCodewordsPerBlock + numDataCodewords;
1473
- result[numResultBlocks++] = new DataBlock(numDataCodewords, new Array(numBlockCodewords));
1474
- }
1475
- }
1476
- const shorterBlocksTotalCodewords = result[0].codewords.length;
1477
- let longerBlocksStartAt = result.length - 1;
1478
- while (longerBlocksStartAt >= 0) {
1479
- if (result[longerBlocksStartAt].codewords.length == shorterBlocksTotalCodewords) break;
1480
- longerBlocksStartAt--;
1481
- }
1482
- longerBlocksStartAt++;
1483
- const shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlocks.ecCodewordsPerBlock;
1484
- let rawCodewordsOffset = 0;
1485
- for (var i = 0; i < shorterBlocksNumDataCodewords; i++) for (var j = 0; j < numResultBlocks; j++) result[j].codewords[i] = rawCodewords[rawCodewordsOffset++];
1486
- for (var j = longerBlocksStartAt; j < numResultBlocks; j++) result[j].codewords[shorterBlocksNumDataCodewords] = rawCodewords[rawCodewordsOffset++];
1487
- const max = result[0].codewords.length;
1488
- for (var i = shorterBlocksNumDataCodewords; i < max; i++) for (var j = 0; j < numResultBlocks; j++) {
1489
- const iOffset = j < longerBlocksStartAt ? i : i + 1;
1490
- result[j].codewords[iOffset] = rawCodewords[rawCodewordsOffset++];
1491
- }
1492
- return result;
1493
- };
1494
- //#endregion
1495
- //#region src/internal/qr/vendor/reader/parse/databr.ts
1496
- /**
1497
- * @file 二维码解析内部模块:databr。
1498
- */
1499
- function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode) {
1500
- this.blockPointer = 0;
1501
- this.bitPointer = 7;
1502
- this.dataLength = 0;
1503
- this.blocks = blocks;
1504
- this.numErrorCorrectionCode = numErrorCorrectionCode;
1505
- if (version <= 9) this.dataLengthMode = 0;
1506
- else if (version >= 10 && version <= 26) this.dataLengthMode = 1;
1507
- else if (version >= 27 && version <= 40) this.dataLengthMode = 2;
1508
- }
1509
- QRCodeDataBlockReader.prototype.getNextBits = function(numBits) {
1510
- let bits = 0;
1511
- if (numBits < this.bitPointer + 1) {
1512
- let mask = 0;
1513
- for (var i = 0; i < numBits; i++) mask += 1 << i;
1514
- mask <<= this.bitPointer - numBits + 1;
1515
- bits = (this.blocks[this.blockPointer] & mask) >> this.bitPointer - numBits + 1;
1516
- this.bitPointer -= numBits;
1517
- return bits;
1518
- } else if (numBits < this.bitPointer + 1 + 8) {
1519
- var mask1 = 0;
1520
- for (var i = 0; i < this.bitPointer + 1; i++) mask1 += 1 << i;
1521
- bits = (this.blocks[this.blockPointer] & mask1) << numBits - (this.bitPointer + 1);
1522
- this.blockPointer++;
1523
- bits += this.blocks[this.blockPointer] >> 8 - (numBits - (this.bitPointer + 1));
1524
- this.bitPointer = this.bitPointer - numBits % 8;
1525
- if (this.bitPointer < 0) this.bitPointer = 8 + this.bitPointer;
1526
- return bits;
1527
- } else if (numBits < this.bitPointer + 1 + 16) {
1528
- var mask1 = 0;
1529
- let mask3 = 0;
1530
- for (var i = 0; i < this.bitPointer + 1; i++) mask1 += 1 << i;
1531
- const bitsFirstBlock = (this.blocks[this.blockPointer] & mask1) << numBits - (this.bitPointer + 1);
1532
- this.blockPointer++;
1533
- const bitsSecondBlock = this.blocks[this.blockPointer] << numBits - (this.bitPointer + 1 + 8);
1534
- this.blockPointer++;
1535
- for (var i = 0; i < numBits - (this.bitPointer + 1 + 8); i++) mask3 += 1 << i;
1536
- mask3 <<= 8 - (numBits - (this.bitPointer + 1 + 8));
1537
- const bitsThirdBlock = (this.blocks[this.blockPointer] & mask3) >> 8 - (numBits - (this.bitPointer + 1 + 8));
1538
- bits = bitsFirstBlock + bitsSecondBlock + bitsThirdBlock;
1539
- this.bitPointer = this.bitPointer - (numBits - 8) % 8;
1540
- if (this.bitPointer < 0) this.bitPointer = 8 + this.bitPointer;
1541
- return bits;
1542
- } else return 0;
1543
- };
1544
- QRCodeDataBlockReader.prototype.NextMode = function() {
1545
- if (this.blockPointer > this.blocks.length - this.numErrorCorrectionCode - 2) return 0;
1546
- else return this.getNextBits(4);
1547
- };
1548
- QRCodeDataBlockReader.prototype.getDataLength = function(modeIndicator) {
1549
- let index = 0;
1550
- while (true) {
1551
- if (modeIndicator >> index == 1) break;
1552
- index++;
1553
- }
1554
- return this.getNextBits(qrcode.sizeOfDataLengthInfo[this.dataLengthMode][index]);
1555
- };
1556
- QRCodeDataBlockReader.prototype.getRomanAndFigureString = function(dataLength) {
1557
- let length = dataLength;
1558
- let intData = 0;
1559
- let strData = "";
1560
- const tableRomanAndFigure = [
1561
- "0",
1562
- "1",
1563
- "2",
1564
- "3",
1565
- "4",
1566
- "5",
1567
- "6",
1568
- "7",
1569
- "8",
1570
- "9",
1571
- "A",
1572
- "B",
1573
- "C",
1574
- "D",
1575
- "E",
1576
- "F",
1577
- "G",
1578
- "H",
1579
- "I",
1580
- "J",
1581
- "K",
1582
- "L",
1583
- "M",
1584
- "N",
1585
- "O",
1586
- "P",
1587
- "Q",
1588
- "R",
1589
- "S",
1590
- "T",
1591
- "U",
1592
- "V",
1593
- "W",
1594
- "X",
1595
- "Y",
1596
- "Z",
1597
- " ",
1598
- "$",
1599
- "%",
1600
- "*",
1601
- "+",
1602
- "-",
1603
- ".",
1604
- "/",
1605
- ":"
1606
- ];
1607
- do
1608
- if (length > 1) {
1609
- intData = this.getNextBits(11);
1610
- const firstLetter = Math.floor(intData / 45);
1611
- const secondLetter = intData % 45;
1612
- strData += tableRomanAndFigure[firstLetter];
1613
- strData += tableRomanAndFigure[secondLetter];
1614
- length -= 2;
1615
- } else if (length == 1) {
1616
- intData = this.getNextBits(6);
1617
- strData += tableRomanAndFigure[intData];
1618
- length -= 1;
1619
- }
1620
- while (length > 0);
1621
- return strData;
1622
- };
1623
- QRCodeDataBlockReader.prototype.getFigureString = function(dataLength) {
1624
- let length = dataLength;
1625
- let intData = 0;
1626
- let strData = "";
1627
- do {
1628
- if (length >= 3) {
1629
- intData = this.getNextBits(10);
1630
- if (intData < 100) strData += "0";
1631
- if (intData < 10) strData += "0";
1632
- length -= 3;
1633
- } else if (length == 2) {
1634
- intData = this.getNextBits(7);
1635
- if (intData < 10) strData += "0";
1636
- length -= 2;
1637
- } else if (length == 1) {
1638
- intData = this.getNextBits(4);
1639
- length -= 1;
1640
- }
1641
- strData += intData;
1642
- } while (length > 0);
1643
- return strData;
1644
- };
1645
- QRCodeDataBlockReader.prototype.get8bitByteArray = function(dataLength) {
1646
- let length = dataLength;
1647
- let intData = 0;
1648
- const output = [];
1649
- do {
1650
- intData = this.getNextBits(8);
1651
- output.push(intData);
1652
- length--;
1653
- } while (length > 0);
1654
- return output;
1655
- };
1656
- QRCodeDataBlockReader.prototype.getKanjiString = function(dataLength) {
1657
- let length = dataLength;
1658
- let intData = 0;
1659
- let unicodeString = "";
1660
- do {
1661
- intData = this.getNextBits(13);
1662
- const lowerByte = intData % 192;
1663
- const tempWord = (intData / 192 << 8) + lowerByte;
1664
- let shiftjisWord = 0;
1665
- if (tempWord + 33088 <= 40956) shiftjisWord = tempWord + 33088;
1666
- else shiftjisWord = tempWord + 49472;
1667
- unicodeString += String.fromCharCode(shiftjisWord);
1668
- length--;
1669
- } while (length > 0);
1670
- return unicodeString;
1671
- };
1672
- Object.defineProperty(QRCodeDataBlockReader.prototype, "DataByte", { get() {
1673
- const output = [];
1674
- const MODE_NUMBER = 1;
1675
- const MODE_ROMAN_AND_NUMBER = 2;
1676
- const MODE_8BIT_BYTE = 4;
1677
- const MODE_KANJI = 8;
1678
- do {
1679
- const mode = this.NextMode();
1680
- if (mode == 0) if (output.length > 0) break;
1681
- else throw "Empty data block";
1682
- if (mode != MODE_NUMBER && mode != MODE_ROMAN_AND_NUMBER && mode != MODE_8BIT_BYTE && mode != MODE_KANJI && mode != 7) throw `Invalid mode: ${mode} in (block:${this.blockPointer} bit:${this.bitPointer})`;
1683
- const dataLength = this.getDataLength(mode);
1684
- if (dataLength < 1) throw `Invalid data length: ${dataLength}`;
1685
- switch (mode) {
1686
- case MODE_NUMBER:
1687
- var temp_str = this.getFigureString(dataLength);
1688
- var ta = Array.from({ length: temp_str.length });
1689
- for (var j = 0; j < temp_str.length; j++) ta[j] = temp_str.charCodeAt(j);
1690
- output.push(ta);
1691
- break;
1692
- case MODE_ROMAN_AND_NUMBER:
1693
- var temp_str = this.getRomanAndFigureString(dataLength);
1694
- var ta = Array.from({ length: temp_str.length });
1695
- for (var j = 0; j < temp_str.length; j++) ta[j] = temp_str.charCodeAt(j);
1696
- output.push(ta);
1697
- break;
1698
- case MODE_8BIT_BYTE:
1699
- var temp_sbyteArray3 = this.get8bitByteArray(dataLength);
1700
- output.push(temp_sbyteArray3);
1701
- break;
1702
- case MODE_KANJI:
1703
- var temp_str = this.getKanjiString(dataLength);
1704
- output.push(temp_str);
1705
- break;
1706
- }
1707
- } while (true);
1708
- return output;
1709
- } });
1710
- //#endregion
1711
- //#region src/internal/qr/vendor/reader/error-correction/gf256poly.ts
1712
- /**
1713
- * @file 二维码解析内部模块:gf256poly。
1714
- */
1715
- function GF256Poly(field, coefficients) {
1716
- if (coefficients == null || coefficients.length == 0) throw "System.ArgumentException";
1717
- this.field = field;
1718
- const coefficientsLength = coefficients.length;
1719
- if (coefficientsLength > 1 && coefficients[0] == 0) {
1720
- let firstNonZero = 1;
1721
- while (firstNonZero < coefficientsLength && coefficients[firstNonZero] == 0) firstNonZero++;
1722
- if (firstNonZero == coefficientsLength) this.coefficients = field.Zero.coefficients;
1723
- else {
1724
- this.coefficients = new Array(coefficientsLength - firstNonZero);
1725
- for (let i = 0; i < this.coefficients.length; i++) this.coefficients[i] = 0;
1726
- for (let ci = 0; ci < this.coefficients.length; ci++) this.coefficients[ci] = coefficients[firstNonZero + ci];
1727
- }
1728
- } else this.coefficients = coefficients;
1729
- }
1730
- Object.defineProperty(GF256Poly.prototype, "Zero", { get() {
1731
- return this.coefficients[0] == 0;
1732
- } });
1733
- Object.defineProperty(GF256Poly.prototype, "Degree", { get() {
1734
- return this.coefficients.length - 1;
1735
- } });
1736
- GF256Poly.prototype.getCoefficient = function(degree) {
1737
- return this.coefficients[this.coefficients.length - 1 - degree];
1738
- };
1739
- GF256Poly.prototype.evaluateAt = function(a) {
1740
- if (a == 0) return this.getCoefficient(0);
1741
- const size = this.coefficients.length;
1742
- if (a == 1) {
1743
- let result = 0;
1744
- for (var i = 0; i < size; i++) result = this.field.addOrSubtract(result, this.coefficients[i]);
1745
- return result;
1746
- }
1747
- let result2 = this.coefficients[0];
1748
- for (var i = 1; i < size; i++) result2 = this.field.addOrSubtract(this.field.multiply(a, result2), this.coefficients[i]);
1749
- return result2;
1750
- };
1751
- GF256Poly.prototype.addOrSubtract = function(other) {
1752
- if (this.field != other.field) throw "GF256Polys do not have same GF256 field";
1753
- if (this.Zero) return other;
1754
- if (other.Zero) return this;
1755
- let smallerCoefficients = this.coefficients;
1756
- let largerCoefficients = other.coefficients;
1757
- if (smallerCoefficients.length > largerCoefficients.length) {
1758
- const temp = smallerCoefficients;
1759
- smallerCoefficients = largerCoefficients;
1760
- largerCoefficients = temp;
1761
- }
1762
- const sumDiff = Array.from({ length: largerCoefficients.length });
1763
- const lengthDiff = largerCoefficients.length - smallerCoefficients.length;
1764
- for (let ci = 0; ci < lengthDiff; ci++) sumDiff[ci] = largerCoefficients[ci];
1765
- for (let i = lengthDiff; i < largerCoefficients.length; i++) sumDiff[i] = this.field.addOrSubtract(smallerCoefficients[i - lengthDiff], largerCoefficients[i]);
1766
- return new GF256Poly(this.field, sumDiff);
1767
- };
1768
- GF256Poly.prototype.multiply1 = function(other) {
1769
- if (this.field != other.field) throw "GF256Polys do not have same GF256 field";
1770
- if (this.Zero || other.Zero) return this.field.Zero;
1771
- const aCoefficients = this.coefficients;
1772
- const aLength = aCoefficients.length;
1773
- const bCoefficients = other.coefficients;
1774
- const bLength = bCoefficients.length;
1775
- const product = Array.from({ length: aLength + bLength - 1 });
1776
- for (let i = 0; i < aLength; i++) {
1777
- const aCoeff = aCoefficients[i];
1778
- for (let j = 0; j < bLength; j++) product[i + j] = this.field.addOrSubtract(product[i + j], this.field.multiply(aCoeff, bCoefficients[j]));
1779
- }
1780
- return new GF256Poly(this.field, product);
1781
- };
1782
- GF256Poly.prototype.multiply2 = function(scalar) {
1783
- if (scalar == 0) return this.field.Zero;
1784
- if (scalar == 1) return this;
1785
- const size = this.coefficients.length;
1786
- const product = new Array(size);
1787
- for (let i = 0; i < size; i++) product[i] = this.field.multiply(this.coefficients[i], scalar);
1788
- return new GF256Poly(this.field, product);
1789
- };
1790
- GF256Poly.prototype.multiplyByMonomial = function(degree, coefficient) {
1791
- if (degree < 0) throw "System.ArgumentException";
1792
- if (coefficient == 0) return this.field.Zero;
1793
- const size = this.coefficients.length;
1794
- const product = new Array(size + degree);
1795
- for (var i = 0; i < product.length; i++) product[i] = 0;
1796
- for (var i = 0; i < size; i++) product[i] = this.field.multiply(this.coefficients[i], coefficient);
1797
- return new GF256Poly(this.field, product);
1798
- };
1799
- GF256Poly.prototype.divide = function(other) {
1800
- if (this.field != other.field) throw "GF256Polys do not have same GF256 field";
1801
- if (other.Zero) throw "Divide by 0";
1802
- let quotient = this.field.Zero;
1803
- let remainder = this;
1804
- const denominatorLeadingTerm = other.getCoefficient(other.Degree);
1805
- const inverseDenominatorLeadingTerm = this.field.inverse(denominatorLeadingTerm);
1806
- while (remainder.Degree >= other.Degree && !remainder.Zero) {
1807
- const degreeDifference = remainder.Degree - other.Degree;
1808
- const scale = this.field.multiply(remainder.getCoefficient(remainder.Degree), inverseDenominatorLeadingTerm);
1809
- const term = other.multiplyByMonomial(degreeDifference, scale);
1810
- const iterationQuotient = this.field.buildMonomial(degreeDifference, scale);
1811
- quotient = quotient.addOrSubtract(iterationQuotient);
1812
- remainder = remainder.addOrSubtract(term);
1813
- }
1814
- return [quotient, remainder];
1815
- };
1816
- //#endregion
1817
- //#region src/internal/qr/vendor/reader/error-correction/gf256.ts
1818
- /**
1819
- * @file 二维码解析内部模块:gf256。
1820
- */
1821
- function GF256(primitive) {
1822
- this.expTable = Array.from({ length: 256 });
1823
- this.logTable = Array.from({ length: 256 });
1824
- let x = 1;
1825
- for (var i = 0; i < 256; i++) {
1826
- this.expTable[i] = x;
1827
- x <<= 1;
1828
- if (x >= 256) x ^= primitive;
1829
- }
1830
- for (var i = 0; i < 255; i++) this.logTable[this.expTable[i]] = i;
1831
- const at0 = Array.from({ length: 1 });
1832
- at0[0] = 0;
1833
- this.zero = new GF256Poly(this, new Array(at0));
1834
- const at1 = Array.from({ length: 1 });
1835
- at1[0] = 1;
1836
- this.one = new GF256Poly(this, new Array(at1));
1837
- }
1838
- Object.defineProperty(GF256.prototype, "Zero", { get() {
1839
- return this.zero;
1840
- } });
1841
- Object.defineProperty(GF256.prototype, "One", { get() {
1842
- return this.one;
1843
- } });
1844
- GF256.prototype.buildMonomial = function(degree, coefficient) {
1845
- if (degree < 0) throw "System.ArgumentException";
1846
- if (coefficient == 0) return this.zero;
1847
- const coefficients = new Array(degree + 1);
1848
- for (let i = 0; i < coefficients.length; i++) coefficients[i] = 0;
1849
- coefficients[0] = coefficient;
1850
- return new GF256Poly(this, coefficients);
1851
- };
1852
- GF256.prototype.exp = function(a) {
1853
- return this.expTable[a];
1854
- };
1855
- GF256.prototype.log = function(a) {
1856
- if (a == 0) throw "System.ArgumentException";
1857
- return this.logTable[a];
1858
- };
1859
- GF256.prototype.inverse = function(a) {
1860
- if (a == 0) throw "System.ArithmeticException";
1861
- return this.expTable[255 - this.logTable[a]];
1862
- };
1863
- GF256.prototype.addOrSubtract = function(a, b) {
1864
- return a ^ b;
1865
- };
1866
- GF256.prototype.multiply = function(a, b) {
1867
- if (a == 0 || b == 0) return 0;
1868
- if (a == 1) return b;
1869
- if (b == 1) return a;
1870
- return this.expTable[(this.logTable[a] + this.logTable[b]) % 255];
1871
- };
1872
- GF256.QR_CODE_FIELD = new GF256(285);
1873
- GF256.DATA_MATRIX_FIELD = new GF256(301);
1874
- //#endregion
1875
- //#region src/internal/qr/vendor/reader/error-correction/rsdecoder.ts
1876
- /**
1877
- * @file 二维码解析内部模块:rsdecoder。
1878
- */
1879
- function ReedSolomonDecoder(field) {
1880
- this.field = field;
1881
- }
1882
- ReedSolomonDecoder.prototype.decode = function(received, twoS) {
1883
- const poly = new GF256Poly(this.field, received);
1884
- const syndromeCoefficients = new Array(twoS);
1885
- for (var i = 0; i < syndromeCoefficients.length; i++) syndromeCoefficients[i] = 0;
1886
- const dataMatrix = false;
1887
- let noError = true;
1888
- for (var i = 0; i < twoS; i++) {
1889
- const _eval = poly.evaluateAt(this.field.exp(i));
1890
- syndromeCoefficients[syndromeCoefficients.length - 1 - i] = _eval;
1891
- if (_eval != 0) noError = false;
1892
- }
1893
- if (noError) return;
1894
- const syndrome = new GF256Poly(this.field, syndromeCoefficients);
1895
- const sigmaOmega = this.runEuclideanAlgorithm(this.field.buildMonomial(twoS, 1), syndrome, twoS);
1896
- const sigma = sigmaOmega[0];
1897
- const omega = sigmaOmega[1];
1898
- const errorLocations = this.findErrorLocations(sigma);
1899
- const errorMagnitudes = this.findErrorMagnitudes(omega, errorLocations, dataMatrix);
1900
- for (var i = 0; i < errorLocations.length; i++) {
1901
- const position = received.length - 1 - this.field.log(errorLocations[i]);
1902
- if (position < 0) throw "ReedSolomonException Bad error location";
1903
- received[position] = GF256.prototype.addOrSubtract(received[position], errorMagnitudes[i]);
1904
- }
1905
- };
1906
- ReedSolomonDecoder.prototype.runEuclideanAlgorithm = function(a, b, R) {
1907
- if (a.Degree < b.Degree) {
1908
- const temp = a;
1909
- a = b;
1910
- b = temp;
1911
- }
1912
- let rLast = a;
1913
- let r = b;
1914
- let sLast = this.field.One;
1915
- let s = this.field.Zero;
1916
- let tLast = this.field.Zero;
1917
- let t = this.field.One;
1918
- while (r.Degree >= Math.floor(R / 2)) {
1919
- const rLastLast = rLast;
1920
- const sLastLast = sLast;
1921
- const tLastLast = tLast;
1922
- rLast = r;
1923
- sLast = s;
1924
- tLast = t;
1925
- if (rLast.Zero) throw "r_{i-1} was zero";
1926
- r = rLastLast;
1927
- let q = this.field.Zero;
1928
- const denominatorLeadingTerm = rLast.getCoefficient(rLast.Degree);
1929
- const dltInverse = this.field.inverse(denominatorLeadingTerm);
1930
- while (r.Degree >= rLast.Degree && !r.Zero) {
1931
- const degreeDiff = r.Degree - rLast.Degree;
1932
- const scale = this.field.multiply(r.getCoefficient(r.Degree), dltInverse);
1933
- q = q.addOrSubtract(this.field.buildMonomial(degreeDiff, scale));
1934
- r = r.addOrSubtract(rLast.multiplyByMonomial(degreeDiff, scale));
1935
- }
1936
- s = q.multiply1(sLast).addOrSubtract(sLastLast);
1937
- t = q.multiply1(tLast).addOrSubtract(tLastLast);
1938
- }
1939
- const sigmaTildeAtZero = t.getCoefficient(0);
1940
- if (sigmaTildeAtZero == 0) throw "ReedSolomonException sigmaTilde(0) was zero";
1941
- const inverse = this.field.inverse(sigmaTildeAtZero);
1942
- return [t.multiply2(inverse), r.multiply2(inverse)];
1943
- };
1944
- ReedSolomonDecoder.prototype.findErrorLocations = function(errorLocator) {
1945
- const numErrors = errorLocator.Degree;
1946
- if (numErrors == 1) return new Array(errorLocator.getCoefficient(1));
1947
- const result = new Array(numErrors);
1948
- let e = 0;
1949
- for (let i = 1; i < 256 && e < numErrors; i++) if (errorLocator.evaluateAt(i) == 0) {
1950
- result[e] = this.field.inverse(i);
1951
- e++;
1952
- }
1953
- if (e != numErrors) throw "Error locator degree does not match number of roots";
1954
- return result;
1955
- };
1956
- ReedSolomonDecoder.prototype.findErrorMagnitudes = function(errorEvaluator, errorLocations, dataMatrix) {
1957
- const s = errorLocations.length;
1958
- const result = new Array(s);
1959
- for (let i = 0; i < s; i++) {
1960
- const xiInverse = this.field.inverse(errorLocations[i]);
1961
- let denominator = 1;
1962
- for (let j = 0; j < s; j++) if (i != j) denominator = this.field.multiply(denominator, GF256.prototype.addOrSubtract(1, this.field.multiply(errorLocations[j], xiInverse)));
1963
- result[i] = this.field.multiply(errorEvaluator.evaluateAt(xiInverse), this.field.inverse(denominator));
1964
- if (dataMatrix) result[i] = this.field.multiply(result[i], xiInverse);
1965
- }
1966
- return result;
1967
- };
1968
- //#endregion
1969
- //#region src/internal/qr/vendor/reader/parse/decoder.ts
1970
- /**
1971
- * @file 二维码解析内部模块:decoder。
1972
- */
1973
- const Decoder = {};
1974
- Decoder.rsDecoder = new ReedSolomonDecoder(GF256.QR_CODE_FIELD);
1975
- Decoder.correctErrors = function(codewordBytes, numDataCodewords) {
1976
- const numCodewords = codewordBytes.length;
1977
- const codewordsInts = new Array(numCodewords);
1978
- for (var i = 0; i < numCodewords; i++) codewordsInts[i] = codewordBytes[i] & 255;
1979
- const numECCodewords = codewordBytes.length - numDataCodewords;
1980
- try {
1981
- Decoder.rsDecoder.decode(codewordsInts, numECCodewords);
1982
- } catch (rse) {
1983
- throw rse;
1984
- }
1985
- for (var i = 0; i < numDataCodewords; i++) codewordBytes[i] = codewordsInts[i];
1986
- };
1987
- Decoder.decode = function(bits) {
1988
- const parser = new BitMatrixParser(bits);
1989
- const version = parser.readVersion();
1990
- const ecLevel = parser.readFormatInformation().errorCorrectionLevel;
1991
- const codewords = parser.readCodewords();
1992
- const dataBlocks = DataBlock.getDataBlocks(codewords, version, ecLevel);
1993
- let totalBytes = 0;
1994
- for (var i = 0; i < dataBlocks.length; i++) totalBytes += dataBlocks[i].numDataCodewords;
1995
- const resultBytes = new Array(totalBytes);
1996
- let resultOffset = 0;
1997
- for (let j = 0; j < dataBlocks.length; j++) {
1998
- const dataBlock = dataBlocks[j];
1999
- const codewordBytes = dataBlock.codewords;
2000
- const numDataCodewords = dataBlock.numDataCodewords;
2001
- Decoder.correctErrors(codewordBytes, numDataCodewords);
2002
- for (var i = 0; i < numDataCodewords; i++) resultBytes[resultOffset++] = codewordBytes[i];
2003
- }
2004
- return new QRCodeDataBlockReader(resultBytes, version.versionNumber, ecLevel.bits);
2005
- };
2006
- //#endregion
2007
- //#region src/internal/qr/vendor/reader/detect/alignpat.ts
2008
- /**
2009
- * @file 二维码解析内部模块:alignpat。
2010
- */
2011
- function AlignmentPattern(posX, posY, estimatedModuleSize) {
2012
- this.x = posX;
2013
- this.y = posY;
2014
- this.count = 1;
2015
- this.estimatedModuleSize = estimatedModuleSize;
2016
- }
2017
- Object.defineProperty(AlignmentPattern.prototype, "X", { get() {
2018
- return Math.floor(this.x);
2019
- } });
2020
- Object.defineProperty(AlignmentPattern.prototype, "Y", { get() {
2021
- return Math.floor(this.y);
2022
- } });
2023
- AlignmentPattern.prototype.incrementCount = function() {
2024
- this.count++;
2025
- };
2026
- AlignmentPattern.prototype.aboutEquals = function(moduleSize, i, j) {
2027
- if (Math.abs(i - this.y) <= moduleSize && Math.abs(j - this.x) <= moduleSize) {
2028
- const moduleSizeDiff = Math.abs(moduleSize - this.estimatedModuleSize);
2029
- return moduleSizeDiff <= 1 || moduleSizeDiff / this.estimatedModuleSize <= 1;
2030
- }
2031
- return false;
2032
- };
2033
- function AlignmentPatternFinder(image, startX, startY, width, height, moduleSize, resultPointCallback) {
2034
- this.image = image;
2035
- this.possibleCenters = [];
2036
- this.startX = startX;
2037
- this.startY = startY;
2038
- this.width = width;
2039
- this.height = height;
2040
- this.moduleSize = moduleSize;
2041
- this.crossCheckStateCount = [
2042
- 0,
2043
- 0,
2044
- 0
2045
- ];
2046
- this.resultPointCallback = resultPointCallback;
2047
- }
2048
- AlignmentPatternFinder.prototype.centerFromEnd = function(stateCount, end) {
2049
- return end - stateCount[2] - stateCount[1] / 2;
2050
- };
2051
- AlignmentPatternFinder.prototype.foundPatternCross = function(stateCount) {
2052
- const moduleSize = this.moduleSize;
2053
- const maxVariance = moduleSize / 2;
2054
- for (let i = 0; i < 3; i++) if (Math.abs(moduleSize - stateCount[i]) >= maxVariance) return false;
2055
- return true;
2056
- };
2057
- AlignmentPatternFinder.prototype.crossCheckVertical = function(startI, centerJ, maxCount, originalStateCountTotal) {
2058
- const image = this.image;
2059
- const maxI = image.height;
2060
- const stateCount = this.crossCheckStateCount;
2061
- stateCount[0] = 0;
2062
- stateCount[1] = 0;
2063
- stateCount[2] = 0;
2064
- let i = startI;
2065
- while (i >= 0 && image.data[centerJ + i * image.width] && stateCount[1] <= maxCount) {
2066
- stateCount[1]++;
2067
- i--;
2068
- }
2069
- if (i < 0 || stateCount[1] > maxCount) return NaN;
2070
- while (i >= 0 && !image.data[centerJ + i * image.width] && stateCount[0] <= maxCount) {
2071
- stateCount[0]++;
2072
- i--;
2073
- }
2074
- if (stateCount[0] > maxCount) return NaN;
2075
- i = startI + 1;
2076
- while (i < maxI && image.data[centerJ + i * image.width] && stateCount[1] <= maxCount) {
2077
- stateCount[1]++;
2078
- i++;
2079
- }
2080
- if (i == maxI || stateCount[1] > maxCount) return NaN;
2081
- while (i < maxI && !image.data[centerJ + i * image.width] && stateCount[2] <= maxCount) {
2082
- stateCount[2]++;
2083
- i++;
2084
- }
2085
- if (stateCount[2] > maxCount) return NaN;
2086
- const stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];
2087
- if (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) return NaN;
2088
- return this.foundPatternCross(stateCount) ? this.centerFromEnd(stateCount, i) : NaN;
2089
- };
2090
- AlignmentPatternFinder.prototype.handlePossibleCenter = function(stateCount, i, j) {
2091
- const stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];
2092
- const centerJ = this.centerFromEnd(stateCount, j);
2093
- const centerI = this.crossCheckVertical(i, Math.floor(centerJ), 2 * stateCount[1], stateCountTotal);
2094
- if (!isNaN(centerI)) {
2095
- const estimatedModuleSize = (stateCount[0] + stateCount[1] + stateCount[2]) / 3;
2096
- const max = this.possibleCenters.length;
2097
- for (let index = 0; index < max; index++) if (this.possibleCenters[index].aboutEquals(estimatedModuleSize, centerI, centerJ)) return new AlignmentPattern(centerJ, centerI, estimatedModuleSize);
2098
- const point = new AlignmentPattern(centerJ, centerI, estimatedModuleSize);
2099
- this.possibleCenters.push(point);
2100
- if (this.resultPointCallback != null) this.resultPointCallback.foundPossibleResultPoint(point);
2101
- }
2102
- return null;
2103
- };
2104
- AlignmentPatternFinder.prototype.find = function() {
2105
- const image = this.image;
2106
- const startX = this.startX;
2107
- const height = this.height;
2108
- const maxJ = startX + this.width;
2109
- const middleI = this.startY + (height >> 1);
2110
- const stateCount = [
2111
- 0,
2112
- 0,
2113
- 0
2114
- ];
2115
- for (let iGen = 0; iGen < height; iGen++) {
2116
- const i = middleI + ((iGen & 1) == 0 ? iGen + 1 >> 1 : -(iGen + 1 >> 1));
2117
- stateCount[0] = 0;
2118
- stateCount[1] = 0;
2119
- stateCount[2] = 0;
2120
- let j = startX;
2121
- while (j < maxJ && !image.data[j + image.width * i]) j++;
2122
- let currentState = 0;
2123
- while (j < maxJ) {
2124
- if (image.data[j + i * image.width]) if (currentState == 1) stateCount[currentState]++;
2125
- else if (currentState == 2) {
2126
- if (this.foundPatternCross(stateCount)) {
2127
- var confirmed = this.handlePossibleCenter(stateCount, i, j);
2128
- if (confirmed != null) return confirmed;
2129
- }
2130
- stateCount[0] = stateCount[2];
2131
- stateCount[1] = 1;
2132
- stateCount[2] = 0;
2133
- currentState = 1;
2134
- } else stateCount[++currentState]++;
2135
- else {
2136
- if (currentState == 1) currentState++;
2137
- stateCount[currentState]++;
2138
- }
2139
- j++;
2140
- }
2141
- if (this.foundPatternCross(stateCount)) {
2142
- var confirmed = this.handlePossibleCenter(stateCount, i, maxJ);
2143
- if (confirmed != null) return confirmed;
2144
- }
2145
- }
2146
- if (!(this.possibleCenters.length == 0)) return this.possibleCenters[0];
2147
- throw "Couldn't find enough alignment patterns";
2148
- };
2149
- //#endregion
2150
- //#region src/internal/qr/vendor/reader/detect/findpat.ts
2151
- /**
2152
- * @file 二维码解析内部模块:findpat。
2153
- */
2154
- const MIN_SKIP = 3;
2155
- const MAX_MODULES = 57;
2156
- const INTEGER_MATH_SHIFT = 8;
2157
- const CENTER_QUORUM = 2;
2158
- function orderBestPatterns(patterns) {
2159
- function distance(pattern1, pattern2) {
2160
- const xDiff = pattern1.X - pattern2.X;
2161
- const yDiff = pattern1.Y - pattern2.Y;
2162
- return Math.sqrt(xDiff * xDiff + yDiff * yDiff);
2163
- }
2164
- function crossProductZ(pointA, pointB, pointC) {
2165
- const bX = pointB.x;
2166
- const bY = pointB.y;
2167
- return (pointC.x - bX) * (pointA.y - bY) - (pointC.y - bY) * (pointA.x - bX);
2168
- }
2169
- const zeroOneDistance = distance(patterns[0], patterns[1]);
2170
- const oneTwoDistance = distance(patterns[1], patterns[2]);
2171
- const zeroTwoDistance = distance(patterns[0], patterns[2]);
2172
- let pointA, pointB, pointC;
2173
- if (oneTwoDistance >= zeroOneDistance && oneTwoDistance >= zeroTwoDistance) {
2174
- pointB = patterns[0];
2175
- pointA = patterns[1];
2176
- pointC = patterns[2];
2177
- } else if (zeroTwoDistance >= oneTwoDistance && zeroTwoDistance >= zeroOneDistance) {
2178
- pointB = patterns[1];
2179
- pointA = patterns[0];
2180
- pointC = patterns[2];
2181
- } else {
2182
- pointB = patterns[2];
2183
- pointA = patterns[0];
2184
- pointC = patterns[1];
2185
- }
2186
- if (crossProductZ(pointA, pointB, pointC) < 0) {
2187
- const temp = pointA;
2188
- pointA = pointC;
2189
- pointC = temp;
2190
- }
2191
- patterns[0] = pointA;
2192
- patterns[1] = pointB;
2193
- patterns[2] = pointC;
2194
- }
2195
- function FinderPattern(posX, posY, estimatedModuleSize) {
2196
- this.x = posX;
2197
- this.y = posY;
2198
- this.count = 1;
2199
- this.estimatedModuleSize = estimatedModuleSize;
2200
- }
2201
- Object.defineProperty(FinderPattern.prototype, "X", { get() {
2202
- return this.x;
2203
- } });
2204
- Object.defineProperty(FinderPattern.prototype, "Y", { get() {
2205
- return this.y;
2206
- } });
2207
- FinderPattern.prototype.incrementCount = function() {
2208
- this.count++;
2209
- };
2210
- FinderPattern.prototype.aboutEquals = function(moduleSize, i, j) {
2211
- if (Math.abs(i - this.y) <= moduleSize && Math.abs(j - this.x) <= moduleSize) {
2212
- const moduleSizeDiff = Math.abs(moduleSize - this.estimatedModuleSize);
2213
- return moduleSizeDiff <= 1 || moduleSizeDiff / this.estimatedModuleSize <= 1;
2214
- }
2215
- return false;
2216
- };
2217
- function FinderPatternInfo(patternCenters) {
2218
- this.bottomLeft = patternCenters[0];
2219
- this.topLeft = patternCenters[1];
2220
- this.topRight = patternCenters[2];
2221
- }
2222
- function FinderPatternFinder() {
2223
- this.image = null;
2224
- this.possibleCenters = [];
2225
- this.hasSkipped = false;
2226
- this.crossCheckStateCount = [
2227
- 0,
2228
- 0,
2229
- 0,
2230
- 0,
2231
- 0
2232
- ];
2233
- this.resultPointCallback = null;
2234
- }
2235
- Object.defineProperty(FinderPatternFinder.prototype, "CrossCheckStateCount", { get() {
2236
- this.crossCheckStateCount[0] = 0;
2237
- this.crossCheckStateCount[1] = 0;
2238
- this.crossCheckStateCount[2] = 0;
2239
- this.crossCheckStateCount[3] = 0;
2240
- this.crossCheckStateCount[4] = 0;
2241
- return this.crossCheckStateCount;
2242
- } });
2243
- FinderPatternFinder.prototype.foundPatternCross = function(stateCount) {
2244
- let totalModuleSize = 0;
2245
- for (let i = 0; i < 5; i++) {
2246
- const count = stateCount[i];
2247
- if (count == 0) return false;
2248
- totalModuleSize += count;
2249
- }
2250
- if (totalModuleSize < 7) return false;
2251
- const moduleSize = Math.floor((totalModuleSize << INTEGER_MATH_SHIFT) / 7);
2252
- const maxVariance = Math.floor(moduleSize / 2);
2253
- return Math.abs(moduleSize - (stateCount[0] << INTEGER_MATH_SHIFT)) < maxVariance && Math.abs(moduleSize - (stateCount[1] << INTEGER_MATH_SHIFT)) < maxVariance && Math.abs(3 * moduleSize - (stateCount[2] << INTEGER_MATH_SHIFT)) < 3 * maxVariance && Math.abs(moduleSize - (stateCount[3] << INTEGER_MATH_SHIFT)) < maxVariance && Math.abs(moduleSize - (stateCount[4] << INTEGER_MATH_SHIFT)) < maxVariance;
2254
- };
2255
- FinderPatternFinder.prototype.centerFromEnd = function(stateCount, end) {
2256
- return end - stateCount[4] - stateCount[3] - stateCount[2] / 2;
2257
- };
2258
- FinderPatternFinder.prototype.crossCheckVertical = function(startI, centerJ, maxCount, originalStateCountTotal) {
2259
- const image = this.image;
2260
- const maxI = image.height;
2261
- const stateCount = this.CrossCheckStateCount;
2262
- let i = startI;
2263
- while (i >= 0 && image.data[centerJ + i * image.width]) {
2264
- stateCount[2]++;
2265
- i--;
2266
- }
2267
- if (i < 0) return NaN;
2268
- while (i >= 0 && !image.data[centerJ + i * image.width] && stateCount[1] <= maxCount) {
2269
- stateCount[1]++;
2270
- i--;
2271
- }
2272
- if (i < 0 || stateCount[1] > maxCount) return NaN;
2273
- while (i >= 0 && image.data[centerJ + i * image.width] && stateCount[0] <= maxCount) {
2274
- stateCount[0]++;
2275
- i--;
2276
- }
2277
- if (stateCount[0] > maxCount) return NaN;
2278
- i = startI + 1;
2279
- while (i < maxI && image.data[centerJ + i * image.width]) {
2280
- stateCount[2]++;
2281
- i++;
2282
- }
2283
- if (i == maxI) return NaN;
2284
- while (i < maxI && !image.data[centerJ + i * image.width] && stateCount[3] < maxCount) {
2285
- stateCount[3]++;
2286
- i++;
2287
- }
2288
- if (i == maxI || stateCount[3] >= maxCount) return NaN;
2289
- while (i < maxI && image.data[centerJ + i * image.width] && stateCount[4] < maxCount) {
2290
- stateCount[4]++;
2291
- i++;
2292
- }
2293
- if (stateCount[4] >= maxCount) return NaN;
2294
- const stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];
2295
- if (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) return NaN;
2296
- return this.foundPatternCross(stateCount) ? this.centerFromEnd(stateCount, i) : NaN;
2297
- };
2298
- FinderPatternFinder.prototype.crossCheckHorizontal = function(startJ, centerI, maxCount, originalStateCountTotal) {
2299
- const image = this.image;
2300
- const maxJ = image.width;
2301
- const stateCount = this.CrossCheckStateCount;
2302
- let j = startJ;
2303
- while (j >= 0 && image.data[j + centerI * image.width]) {
2304
- stateCount[2]++;
2305
- j--;
2306
- }
2307
- if (j < 0) return NaN;
2308
- while (j >= 0 && !image.data[j + centerI * image.width] && stateCount[1] <= maxCount) {
2309
- stateCount[1]++;
2310
- j--;
2311
- }
2312
- if (j < 0 || stateCount[1] > maxCount) return NaN;
2313
- while (j >= 0 && image.data[j + centerI * image.width] && stateCount[0] <= maxCount) {
2314
- stateCount[0]++;
2315
- j--;
2316
- }
2317
- if (stateCount[0] > maxCount) return NaN;
2318
- j = startJ + 1;
2319
- while (j < maxJ && image.data[j + centerI * image.width]) {
2320
- stateCount[2]++;
2321
- j++;
2322
- }
2323
- if (j == maxJ) return NaN;
2324
- while (j < maxJ && !image.data[j + centerI * image.width] && stateCount[3] < maxCount) {
2325
- stateCount[3]++;
2326
- j++;
2327
- }
2328
- if (j == maxJ || stateCount[3] >= maxCount) return NaN;
2329
- while (j < maxJ && image.data[j + centerI * image.width] && stateCount[4] < maxCount) {
2330
- stateCount[4]++;
2331
- j++;
2332
- }
2333
- if (stateCount[4] >= maxCount) return NaN;
2334
- const stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];
2335
- if (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= originalStateCountTotal) return NaN;
2336
- return this.foundPatternCross(stateCount) ? this.centerFromEnd(stateCount, j) : NaN;
2337
- };
2338
- FinderPatternFinder.prototype.handlePossibleCenter = function(stateCount, i, j) {
2339
- const stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];
2340
- let centerJ = this.centerFromEnd(stateCount, j);
2341
- const centerI = this.crossCheckVertical(i, Math.floor(centerJ), stateCount[2], stateCountTotal);
2342
- if (!isNaN(centerI)) {
2343
- centerJ = this.crossCheckHorizontal(Math.floor(centerJ), Math.floor(centerI), stateCount[2], stateCountTotal);
2344
- if (!isNaN(centerJ)) {
2345
- const estimatedModuleSize = stateCountTotal / 7;
2346
- let found = false;
2347
- const max = this.possibleCenters.length;
2348
- for (let index = 0; index < max; index++) {
2349
- const center = this.possibleCenters[index];
2350
- if (center.aboutEquals(estimatedModuleSize, centerI, centerJ)) {
2351
- center.incrementCount();
2352
- found = true;
2353
- break;
2354
- }
2355
- }
2356
- if (!found) {
2357
- const point = new FinderPattern(centerJ, centerI, estimatedModuleSize);
2358
- this.possibleCenters.push(point);
2359
- if (this.resultPointCallback != null) this.resultPointCallback.foundPossibleResultPoint(point);
2360
- }
2361
- return true;
2362
- }
2363
- }
2364
- return false;
2365
- };
2366
- FinderPatternFinder.prototype.selectBestPatterns = function() {
2367
- const startSize = this.possibleCenters.length;
2368
- if (startSize < 3) throw `Couldn't find enough finder patterns:${startSize} patterns found`;
2369
- if (startSize > 3) {
2370
- let totalModuleSize = 0;
2371
- let square = 0;
2372
- for (var i = 0; i < startSize; i++) {
2373
- const centerValue = this.possibleCenters[i].estimatedModuleSize;
2374
- totalModuleSize += centerValue;
2375
- square += centerValue * centerValue;
2376
- }
2377
- const average = totalModuleSize / startSize;
2378
- this.possibleCenters.sort((center1, center2) => {
2379
- const dA = Math.abs(center2.estimatedModuleSize - average);
2380
- const dB = Math.abs(center1.estimatedModuleSize - average);
2381
- if (dA < dB) return -1;
2382
- else if (dA == dB) return 0;
2383
- else return 1;
2384
- });
2385
- const stdDev = Math.sqrt(square / startSize - average * average);
2386
- const limit = Math.max(.2 * average, stdDev);
2387
- for (var i = this.possibleCenters - 1; i >= 0; i--) {
2388
- const pattern = this.possibleCenters[i];
2389
- if (Math.abs(pattern.estimatedModuleSize - average) > limit) this.possibleCenters.splice(i, 1);
2390
- }
2391
- }
2392
- if (this.possibleCenters.length > 3) this.possibleCenters.sort((a, b) => {
2393
- if (a.count > b.count) return -1;
2394
- if (a.count < b.count) return 1;
2395
- return 0;
2396
- });
2397
- return [
2398
- this.possibleCenters[0],
2399
- this.possibleCenters[1],
2400
- this.possibleCenters[2]
2401
- ];
2402
- };
2403
- FinderPatternFinder.prototype.findRowSkip = function() {
2404
- const max = this.possibleCenters.length;
2405
- if (max <= 1) return 0;
2406
- let firstConfirmedCenter = null;
2407
- for (let i = 0; i < max; i++) {
2408
- const center = this.possibleCenters[i];
2409
- if (center.count >= CENTER_QUORUM) if (firstConfirmedCenter == null) firstConfirmedCenter = center;
2410
- else {
2411
- this.hasSkipped = true;
2412
- return Math.floor((Math.abs(firstConfirmedCenter.X - center.X) - Math.abs(firstConfirmedCenter.Y - center.Y)) / 2);
2413
- }
2414
- }
2415
- return 0;
2416
- };
2417
- FinderPatternFinder.prototype.haveMultiplyConfirmedCenters = function() {
2418
- let confirmedCount = 0;
2419
- let totalModuleSize = 0;
2420
- const max = this.possibleCenters.length;
2421
- for (var i = 0; i < max; i++) {
2422
- var pattern = this.possibleCenters[i];
2423
- if (pattern.count >= CENTER_QUORUM) {
2424
- confirmedCount++;
2425
- totalModuleSize += pattern.estimatedModuleSize;
2426
- }
2427
- }
2428
- if (confirmedCount < 3) return false;
2429
- const average = totalModuleSize / max;
2430
- let totalDeviation = 0;
2431
- for (var i = 0; i < max; i++) {
2432
- pattern = this.possibleCenters[i];
2433
- totalDeviation += Math.abs(pattern.estimatedModuleSize - average);
2434
- }
2435
- return totalDeviation <= .05 * totalModuleSize;
2436
- };
2437
- FinderPatternFinder.prototype.findFinderPattern = function(image) {
2438
- const tryHarder = false;
2439
- this.image = image;
2440
- const maxI = image.height;
2441
- const maxJ = image.width;
2442
- let iSkip = Math.floor(3 * maxI / (4 * MAX_MODULES));
2443
- if (iSkip < MIN_SKIP || tryHarder) iSkip = MIN_SKIP;
2444
- let done = false;
2445
- const stateCount = Array.from({ length: 5 });
2446
- for (let i = iSkip - 1; i < maxI && !done; i += iSkip) {
2447
- stateCount[0] = 0;
2448
- stateCount[1] = 0;
2449
- stateCount[2] = 0;
2450
- stateCount[3] = 0;
2451
- stateCount[4] = 0;
2452
- let currentState = 0;
2453
- for (let j = 0; j < maxJ; j++) if (image.data[j + i * image.width]) {
2454
- if ((currentState & 1) == 1) currentState++;
2455
- stateCount[currentState]++;
2456
- } else if ((currentState & 1) == 0) if (currentState == 4) if (this.foundPatternCross(stateCount)) {
2457
- var confirmed = this.handlePossibleCenter(stateCount, i, j);
2458
- if (confirmed) {
2459
- iSkip = 2;
2460
- if (this.hasSkipped) done = this.haveMultiplyConfirmedCenters();
2461
- else {
2462
- const rowSkip = this.findRowSkip();
2463
- if (rowSkip > stateCount[2]) {
2464
- i += rowSkip - stateCount[2] - iSkip;
2465
- j = maxJ - 1;
2466
- }
2467
- }
2468
- } else {
2469
- do
2470
- j++;
2471
- while (j < maxJ && !image.data[j + i * image.width]);
2472
- j--;
2473
- }
2474
- currentState = 0;
2475
- stateCount[0] = 0;
2476
- stateCount[1] = 0;
2477
- stateCount[2] = 0;
2478
- stateCount[3] = 0;
2479
- stateCount[4] = 0;
2480
- } else {
2481
- stateCount[0] = stateCount[2];
2482
- stateCount[1] = stateCount[3];
2483
- stateCount[2] = stateCount[4];
2484
- stateCount[3] = 1;
2485
- stateCount[4] = 0;
2486
- currentState = 3;
2487
- }
2488
- else stateCount[++currentState]++;
2489
- else stateCount[currentState]++;
2490
- if (this.foundPatternCross(stateCount)) {
2491
- var confirmed = this.handlePossibleCenter(stateCount, i, maxJ);
2492
- if (confirmed) {
2493
- iSkip = stateCount[0];
2494
- if (this.hasSkipped) done = this.haveMultiplyConfirmedCenters();
2495
- }
2496
- }
2497
- }
2498
- const patternInfo = this.selectBestPatterns();
2499
- orderBestPatterns(patternInfo);
2500
- return new FinderPatternInfo(patternInfo);
2501
- };
2502
- //#endregion
2503
- //#region src/internal/qr/vendor/reader/detect/grid.ts
2504
- /**
2505
- * @file 二维码解析内部模块:grid。
2506
- */
2507
- const GridSampler = {};
2508
- GridSampler.checkAndNudgePoints = function(image, points) {
2509
- const width = image.width;
2510
- const height = image.height;
2511
- let nudged = true;
2512
- for (var offset = 0; offset < points.length && nudged; offset += 2) {
2513
- var x = Math.floor(points[offset]);
2514
- var y = Math.floor(points[offset + 1]);
2515
- if (x < -1 || x > width || y < -1 || y > height) throw "Error.checkAndNudgePoints ";
2516
- nudged = false;
2517
- if (x == -1) {
2518
- points[offset] = 0;
2519
- nudged = true;
2520
- } else if (x == width) {
2521
- points[offset] = width - 1;
2522
- nudged = true;
2523
- }
2524
- if (y == -1) {
2525
- points[offset + 1] = 0;
2526
- nudged = true;
2527
- } else if (y == height) {
2528
- points[offset + 1] = height - 1;
2529
- nudged = true;
2530
- }
2531
- }
2532
- nudged = true;
2533
- for (var offset = points.length - 2; offset >= 0 && nudged; offset -= 2) {
2534
- var x = Math.floor(points[offset]);
2535
- var y = Math.floor(points[offset + 1]);
2536
- if (x < -1 || x > width || y < -1 || y > height) throw "Error.checkAndNudgePoints ";
2537
- nudged = false;
2538
- if (x == -1) {
2539
- points[offset] = 0;
2540
- nudged = true;
2541
- } else if (x == width) {
2542
- points[offset] = width - 1;
2543
- nudged = true;
2544
- }
2545
- if (y == -1) {
2546
- points[offset + 1] = 0;
2547
- nudged = true;
2548
- } else if (y == height) {
2549
- points[offset + 1] = height - 1;
2550
- nudged = true;
2551
- }
2552
- }
2553
- };
2554
- GridSampler.sampleGrid3 = function(image, dimension, transform) {
2555
- const bits = new BitMatrix(dimension);
2556
- const points = Array.from({ length: dimension << 1 });
2557
- for (let y = 0; y < dimension; y++) {
2558
- const max = points.length;
2559
- const iValue = y + .5;
2560
- for (var x = 0; x < max; x += 2) {
2561
- points[x] = (x >> 1) + .5;
2562
- points[x + 1] = iValue;
2563
- }
2564
- transform.transformPoints1(points);
2565
- GridSampler.checkAndNudgePoints(image, points);
2566
- try {
2567
- for (var x = 0; x < max; x += 2) if (image.data[Math.floor(points[x]) + image.width * Math.floor(points[x + 1])]) bits.set_Renamed(x >> 1, y);
2568
- } catch (aioobe) {
2569
- throw "Error.checkAndNudgePoints";
2570
- }
2571
- }
2572
- return bits;
2573
- };
2574
- //#endregion
2575
- //#region src/internal/qr/vendor/reader/detect/detector.ts
2576
- /**
2577
- * @file 二维码解析内部模块:detector。
2578
- */
2579
- function PerspectiveTransform(a11, a21, a31, a12, a22, a32, a13, a23, a33) {
2580
- this.a11 = a11;
2581
- this.a12 = a12;
2582
- this.a13 = a13;
2583
- this.a21 = a21;
2584
- this.a22 = a22;
2585
- this.a23 = a23;
2586
- this.a31 = a31;
2587
- this.a32 = a32;
2588
- this.a33 = a33;
2589
- }
2590
- PerspectiveTransform.prototype.transformPoints1 = function(points) {
2591
- const max = points.length;
2592
- const a11 = this.a11;
2593
- const a12 = this.a12;
2594
- const a13 = this.a13;
2595
- const a21 = this.a21;
2596
- const a22 = this.a22;
2597
- const a23 = this.a23;
2598
- const a31 = this.a31;
2599
- const a32 = this.a32;
2600
- const a33 = this.a33;
2601
- for (let i = 0; i < max; i += 2) {
2602
- const x = points[i];
2603
- const y = points[i + 1];
2604
- const denominator = a13 * x + a23 * y + a33;
2605
- points[i] = (a11 * x + a21 * y + a31) / denominator;
2606
- points[i + 1] = (a12 * x + a22 * y + a32) / denominator;
2607
- }
2608
- };
2609
- PerspectiveTransform.prototype.transformPoints2 = function(xValues, yValues) {
2610
- const n = xValues.length;
2611
- for (let i = 0; i < n; i++) {
2612
- const x = xValues[i];
2613
- const y = yValues[i];
2614
- const denominator = this.a13 * x + this.a23 * y + this.a33;
2615
- xValues[i] = (this.a11 * x + this.a21 * y + this.a31) / denominator;
2616
- yValues[i] = (this.a12 * x + this.a22 * y + this.a32) / denominator;
2617
- }
2618
- };
2619
- PerspectiveTransform.prototype.buildAdjoint = function() {
2620
- return new PerspectiveTransform(this.a22 * this.a33 - this.a23 * this.a32, this.a23 * this.a31 - this.a21 * this.a33, this.a21 * this.a32 - this.a22 * this.a31, this.a13 * this.a32 - this.a12 * this.a33, this.a11 * this.a33 - this.a13 * this.a31, this.a12 * this.a31 - this.a11 * this.a32, this.a12 * this.a23 - this.a13 * this.a22, this.a13 * this.a21 - this.a11 * this.a23, this.a11 * this.a22 - this.a12 * this.a21);
2621
- };
2622
- PerspectiveTransform.prototype.times = function(other) {
2623
- return new PerspectiveTransform(this.a11 * other.a11 + this.a21 * other.a12 + this.a31 * other.a13, this.a11 * other.a21 + this.a21 * other.a22 + this.a31 * other.a23, this.a11 * other.a31 + this.a21 * other.a32 + this.a31 * other.a33, this.a12 * other.a11 + this.a22 * other.a12 + this.a32 * other.a13, this.a12 * other.a21 + this.a22 * other.a22 + this.a32 * other.a23, this.a12 * other.a31 + this.a22 * other.a32 + this.a32 * other.a33, this.a13 * other.a11 + this.a23 * other.a12 + this.a33 * other.a13, this.a13 * other.a21 + this.a23 * other.a22 + this.a33 * other.a23, this.a13 * other.a31 + this.a23 * other.a32 + this.a33 * other.a33);
2624
- };
2625
- PerspectiveTransform.quadrilateralToQuadrilateral = function(x0, y0, x1, y1, x2, y2, x3, y3, x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p) {
2626
- const qToS = this.quadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3);
2627
- return this.squareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p).times(qToS);
2628
- };
2629
- PerspectiveTransform.squareToQuadrilateral = function(x0, y0, x1, y1, x2, y2, x3, y3) {
2630
- const dy2 = y3 - y2;
2631
- const dy3 = y0 - y1 + y2 - y3;
2632
- if (dy2 == 0 && dy3 == 0) return new PerspectiveTransform(x1 - x0, x2 - x1, x0, y1 - y0, y2 - y1, y0, 0, 0, 1);
2633
- else {
2634
- const dx1 = x1 - x2;
2635
- const dx2 = x3 - x2;
2636
- const dx3 = x0 - x1 + x2 - x3;
2637
- const dy1 = y1 - y2;
2638
- const denominator = dx1 * dy2 - dx2 * dy1;
2639
- const a13 = (dx3 * dy2 - dx2 * dy3) / denominator;
2640
- const a23 = (dx1 * dy3 - dx3 * dy1) / denominator;
2641
- return new PerspectiveTransform(x1 - x0 + a13 * x1, x3 - x0 + a23 * x3, x0, y1 - y0 + a13 * y1, y3 - y0 + a23 * y3, y0, a13, a23, 1);
2642
- }
2643
- };
2644
- PerspectiveTransform.quadrilateralToSquare = function(x0, y0, x1, y1, x2, y2, x3, y3) {
2645
- return this.squareToQuadrilateral(x0, y0, x1, y1, x2, y2, x3, y3).buildAdjoint();
2646
- };
2647
- function DetectorResult(bits, points) {
2648
- this.bits = bits;
2649
- this.points = points;
2650
- }
2651
- function Detector(image) {
2652
- this.image = image;
2653
- this.resultPointCallback = null;
2654
- }
2655
- Detector.prototype.sizeOfBlackWhiteBlackRun = function(fromX, fromY, toX, toY) {
2656
- const steep = Math.abs(toY - fromY) > Math.abs(toX - fromX);
2657
- if (steep) {
2658
- let temp = fromX;
2659
- fromX = fromY;
2660
- fromY = temp;
2661
- temp = toX;
2662
- toX = toY;
2663
- toY = temp;
2664
- }
2665
- const dx = Math.abs(toX - fromX);
2666
- const dy = Math.abs(toY - fromY);
2667
- let error = -dx >> 1;
2668
- const ystep = fromY < toY ? 1 : -1;
2669
- const xstep = fromX < toX ? 1 : -1;
2670
- let state = 0;
2671
- for (let x = fromX, y = fromY; x != toX; x += xstep) {
2672
- const realX = steep ? y : x;
2673
- const realY = steep ? x : y;
2674
- if (state == 1) {
2675
- if (this.image.data[realX + realY * this.image.width]) state++;
2676
- } else if (!this.image.data[realX + realY * this.image.width]) state++;
2677
- if (state == 3) {
2678
- const diffX = x - fromX;
2679
- const diffY = y - fromY;
2680
- return Math.sqrt(diffX * diffX + diffY * diffY);
2681
- }
2682
- error += dy;
2683
- if (error > 0) {
2684
- if (y == toY) break;
2685
- y += ystep;
2686
- error -= dx;
2687
- }
2688
- }
2689
- const diffX2 = toX - fromX;
2690
- const diffY2 = toY - fromY;
2691
- return Math.sqrt(diffX2 * diffX2 + diffY2 * diffY2);
2692
- };
2693
- Detector.prototype.sizeOfBlackWhiteBlackRunBothWays = function(fromX, fromY, toX, toY) {
2694
- let result = this.sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY);
2695
- let scale = 1;
2696
- let otherToX = fromX - (toX - fromX);
2697
- if (otherToX < 0) {
2698
- scale = fromX / (fromX - otherToX);
2699
- otherToX = 0;
2700
- } else if (otherToX >= this.image.width) {
2701
- scale = (this.image.width - 1 - fromX) / (otherToX - fromX);
2702
- otherToX = this.image.width - 1;
2703
- }
2704
- let otherToY = Math.floor(fromY - (toY - fromY) * scale);
2705
- scale = 1;
2706
- if (otherToY < 0) {
2707
- scale = fromY / (fromY - otherToY);
2708
- otherToY = 0;
2709
- } else if (otherToY >= this.image.height) {
2710
- scale = (this.image.height - 1 - fromY) / (otherToY - fromY);
2711
- otherToY = this.image.height - 1;
2712
- }
2713
- otherToX = Math.floor(fromX + (otherToX - fromX) * scale);
2714
- result += this.sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY);
2715
- return result - 1;
2716
- };
2717
- Detector.prototype.calculateModuleSizeOneWay = function(pattern, otherPattern) {
2718
- const moduleSizeEst1 = this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(pattern.X), Math.floor(pattern.Y), Math.floor(otherPattern.X), Math.floor(otherPattern.Y));
2719
- const moduleSizeEst2 = this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(otherPattern.X), Math.floor(otherPattern.Y), Math.floor(pattern.X), Math.floor(pattern.Y));
2720
- if (isNaN(moduleSizeEst1)) return moduleSizeEst2 / 7;
2721
- if (isNaN(moduleSizeEst2)) return moduleSizeEst1 / 7;
2722
- return (moduleSizeEst1 + moduleSizeEst2) / 14;
2723
- };
2724
- Detector.prototype.calculateModuleSize = function(topLeft, topRight, bottomLeft) {
2725
- return (this.calculateModuleSizeOneWay(topLeft, topRight) + this.calculateModuleSizeOneWay(topLeft, bottomLeft)) / 2;
2726
- };
2727
- Detector.prototype.distance = function(pattern1, pattern2) {
2728
- const xDiff = pattern1.X - pattern2.X;
2729
- const yDiff = pattern1.Y - pattern2.Y;
2730
- return Math.sqrt(xDiff * xDiff + yDiff * yDiff);
2731
- };
2732
- Detector.prototype.computeDimension = function(topLeft, topRight, bottomLeft, moduleSize) {
2733
- let dimension = (Math.round(this.distance(topLeft, topRight) / moduleSize) + Math.round(this.distance(topLeft, bottomLeft) / moduleSize) >> 1) + 7;
2734
- switch (dimension & 3) {
2735
- case 0:
2736
- dimension++;
2737
- break;
2738
- case 2:
2739
- dimension--;
2740
- break;
2741
- case 3: throw "Error";
2742
- }
2743
- return dimension;
2744
- };
2745
- Detector.prototype.findAlignmentInRegion = function(overallEstModuleSize, estAlignmentX, estAlignmentY, allowanceFactor) {
2746
- const allowance = Math.floor(allowanceFactor * overallEstModuleSize);
2747
- const alignmentAreaLeftX = Math.max(0, estAlignmentX - allowance);
2748
- const alignmentAreaRightX = Math.min(this.image.width - 1, estAlignmentX + allowance);
2749
- if (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3) throw "Error";
2750
- const alignmentAreaTopY = Math.max(0, estAlignmentY - allowance);
2751
- const alignmentAreaBottomY = Math.min(this.image.height - 1, estAlignmentY + allowance);
2752
- return new AlignmentPatternFinder(this.image, alignmentAreaLeftX, alignmentAreaTopY, alignmentAreaRightX - alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize, this.resultPointCallback).find();
2753
- };
2754
- Detector.prototype.createTransform = function(topLeft, topRight, bottomLeft, alignmentPattern, dimension) {
2755
- const dimMinusThree = dimension - 3.5;
2756
- let bottomRightX;
2757
- let bottomRightY;
2758
- let sourceBottomRightX;
2759
- let sourceBottomRightY;
2760
- if (alignmentPattern != null) {
2761
- bottomRightX = alignmentPattern.X;
2762
- bottomRightY = alignmentPattern.Y;
2763
- sourceBottomRightX = sourceBottomRightY = dimMinusThree - 3;
2764
- } else {
2765
- bottomRightX = topRight.X - topLeft.X + bottomLeft.X;
2766
- bottomRightY = topRight.Y - topLeft.Y + bottomLeft.Y;
2767
- sourceBottomRightX = sourceBottomRightY = dimMinusThree;
2768
- }
2769
- return PerspectiveTransform.quadrilateralToQuadrilateral(3.5, 3.5, dimMinusThree, 3.5, sourceBottomRightX, sourceBottomRightY, 3.5, dimMinusThree, topLeft.X, topLeft.Y, topRight.X, topRight.Y, bottomRightX, bottomRightY, bottomLeft.X, bottomLeft.Y);
2770
- };
2771
- Detector.prototype.sampleGrid = function(image, transform, dimension) {
2772
- return GridSampler.sampleGrid3(image, dimension, transform);
2773
- };
2774
- Detector.prototype.processFinderPatternInfo = function(info) {
2775
- const topLeft = info.topLeft;
2776
- const topRight = info.topRight;
2777
- const bottomLeft = info.bottomLeft;
2778
- const moduleSize = this.calculateModuleSize(topLeft, topRight, bottomLeft);
2779
- if (moduleSize < 1) throw "Error";
2780
- const dimension = this.computeDimension(topLeft, topRight, bottomLeft, moduleSize);
2781
- const provisionalVersion = Version.getProvisionalVersionForDimension(dimension);
2782
- const modulesBetweenFPCenters = provisionalVersion.DimensionForVersion - 7;
2783
- let alignmentPattern = null;
2784
- if (provisionalVersion.alignmentPatternCenters.length > 0) {
2785
- const bottomRightX = topRight.X - topLeft.X + bottomLeft.X;
2786
- const bottomRightY = topRight.Y - topLeft.Y + bottomLeft.Y;
2787
- const correctionToTopLeft = 1 - 3 / modulesBetweenFPCenters;
2788
- const estAlignmentX = Math.floor(topLeft.X + correctionToTopLeft * (bottomRightX - topLeft.X));
2789
- const estAlignmentY = Math.floor(topLeft.Y + correctionToTopLeft * (bottomRightY - topLeft.Y));
2790
- for (let i = 4; i <= 16; i <<= 1) {
2791
- alignmentPattern = this.findAlignmentInRegion(moduleSize, estAlignmentX, estAlignmentY, i);
2792
- break;
2793
- }
2794
- }
2795
- const transform = this.createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension);
2796
- const bits = this.sampleGrid(this.image, transform, dimension);
2797
- let points;
2798
- if (alignmentPattern == null) points = [
2799
- bottomLeft,
2800
- topLeft,
2801
- topRight
2802
- ];
2803
- else points = [
2804
- bottomLeft,
2805
- topLeft,
2806
- topRight,
2807
- alignmentPattern
2808
- ];
2809
- return new DetectorResult(bits, points);
2810
- };
2811
- Detector.prototype.detect = function() {
2812
- const info = new FinderPatternFinder().findFinderPattern(this.image);
2813
- return this.processFinderPatternInfo(info);
2814
- };
2815
- //#endregion
2816
- //#region src/internal/qr/vendor/reader/core/qrcode.ts
2817
- /**
2818
- * @file 二维码解析内部模块:qrcode。
2819
- */
2820
- var qrcode = {};
2821
- qrcode.sizeOfDataLengthInfo = [
2822
- [
2823
- 10,
2824
- 9,
2825
- 8,
2826
- 8
2827
- ],
2828
- [
2829
- 12,
2830
- 11,
2831
- 16,
2832
- 10
2833
- ],
2834
- [
2835
- 14,
2836
- 13,
2837
- 16,
2838
- 12
2839
- ]
2840
- ];
2841
- function QrCode() {
2842
- this.imagedata = null;
2843
- this.width = 0;
2844
- this.height = 0;
2845
- this.qrCodeSymbol = null;
2846
- this.debug = false;
2847
- this.callback = null;
2848
- }
2849
- QrCode.prototype.decode = function(src, data) {
2850
- const decode = function() {
2851
- try {
2852
- this.error = void 0;
2853
- this.result = this.process(this.imagedata);
2854
- } catch (e) {
2855
- this.error = e;
2856
- this.result = void 0;
2857
- }
2858
- if (this.callback != null) this.callback(this.error, this.result);
2859
- return this.result;
2860
- }.bind(this);
2861
- if (src != void 0 && src.width != void 0) {
2862
- this.width = src.width;
2863
- this.height = src.height;
2864
- this.imagedata = { data: data || src.data };
2865
- this.imagedata.width = src.width;
2866
- this.imagedata.height = src.height;
2867
- decode();
2868
- } else {
2869
- if (typeof Image === "undefined") throw new TypeError("This source format is not supported in your environment, you need to pass an image buffer with width and height (see https://github.com/edi9999/jsqrcode/blob/master/test/qrcode.js)");
2870
- const image = new Image();
2871
- image.crossOrigin = "Anonymous";
2872
- image.onload = function() {
2873
- const canvas_qr = document.createElement("canvas");
2874
- const context = canvas_qr.getContext("2d");
2875
- const canvas_out = document.getElementById("out-canvas");
2876
- if (canvas_out != null) {
2877
- const outctx = canvas_out.getContext("2d");
2878
- outctx.clearRect(0, 0, 320, 240);
2879
- outctx.drawImage(image, 0, 0, 320, 240);
2880
- }
2881
- canvas_qr.width = image.width;
2882
- canvas_qr.height = image.height;
2883
- context.drawImage(image, 0, 0);
2884
- this.width = image.width;
2885
- this.height = image.height;
2886
- try {
2887
- this.imagedata = context.getImageData(0, 0, image.width, image.height);
2888
- } catch (e) {
2889
- this.result = "Cross domain image reading not supported in your browser! Save it to your computer then drag and drop the file!";
2890
- if (this.callback != null) return this.callback(null, this.result);
2891
- }
2892
- decode();
2893
- }.bind(this);
2894
- image.src = src;
2895
- }
2896
- };
2897
- QrCode.prototype.decode_utf8 = function(s) {
2898
- return decodeURIComponent(escape(s));
2899
- };
2900
- QrCode.prototype.process = function(imageData) {
2901
- const start = Date.now();
2902
- const qRCodeMatrix = new Detector(this.grayScaleToBitmap(this.grayscale(imageData))).detect();
2903
- const data = Decoder.decode(qRCodeMatrix.bits).DataByte;
2904
- let str = "";
2905
- for (let i = 0; i < data.length; i++) for (let j = 0; j < data[i].length; j++) str += String.fromCharCode(data[i][j]);
2906
- const time = Date.now() - start;
2907
- if (this.debug) console.log(`QR Code processing time (ms): ${time}`);
2908
- return {
2909
- result: this.decode_utf8(str),
2910
- points: qRCodeMatrix.points
2911
- };
2912
- };
2913
- QrCode.prototype.getPixel = function(imageData, x, y) {
2914
- if (imageData.width < x) throw "point error";
2915
- if (imageData.height < y) throw "point error";
2916
- const point = x * 4 + y * imageData.width * 4;
2917
- return (imageData.data[point] * 33 + imageData.data[point + 1] * 34 + imageData.data[point + 2] * 33) / 100;
2918
- };
2919
- QrCode.prototype.binarize = function(th) {
2920
- const ret = new Array(this.width * this.height);
2921
- for (let y = 0; y < this.height; y++) for (let x = 0; x < this.width; x++) {
2922
- const gray = this.getPixel(x, y);
2923
- ret[x + y * this.width] = gray <= th;
2924
- }
2925
- return ret;
2926
- };
2927
- QrCode.prototype.getMiddleBrightnessPerArea = function(imageData) {
2928
- const numSqrtArea = 4;
2929
- const areaWidth = Math.floor(imageData.width / numSqrtArea);
2930
- const areaHeight = Math.floor(imageData.height / numSqrtArea);
2931
- const minmax = Array.from({ length: numSqrtArea });
2932
- for (let i = 0; i < numSqrtArea; i++) {
2933
- minmax[i] = Array.from({ length: numSqrtArea });
2934
- for (let i2 = 0; i2 < numSqrtArea; i2++) minmax[i][i2] = [0, 0];
2935
- }
2936
- for (var ay = 0; ay < numSqrtArea; ay++) for (var ax = 0; ax < numSqrtArea; ax++) {
2937
- minmax[ax][ay][0] = 255;
2938
- for (let dy = 0; dy < areaHeight; dy++) for (let dx = 0; dx < areaWidth; dx++) {
2939
- const target = imageData.data[areaWidth * ax + dx + (areaHeight * ay + dy) * imageData.width];
2940
- if (target < minmax[ax][ay][0]) minmax[ax][ay][0] = target;
2941
- if (target > minmax[ax][ay][1]) minmax[ax][ay][1] = target;
2942
- }
2943
- }
2944
- const middle = Array.from({ length: numSqrtArea });
2945
- for (let i3 = 0; i3 < numSqrtArea; i3++) middle[i3] = Array.from({ length: numSqrtArea });
2946
- for (var ay = 0; ay < numSqrtArea; ay++) for (var ax = 0; ax < numSqrtArea; ax++) middle[ax][ay] = Math.floor((minmax[ax][ay][0] + minmax[ax][ay][1]) / 2);
2947
- return middle;
2948
- };
2949
- QrCode.prototype.grayScaleToBitmap = function(grayScaleImageData) {
2950
- const middle = this.getMiddleBrightnessPerArea(grayScaleImageData);
2951
- const sqrtNumArea = middle.length;
2952
- const areaWidth = Math.floor(grayScaleImageData.width / sqrtNumArea);
2953
- const areaHeight = Math.floor(grayScaleImageData.height / sqrtNumArea);
2954
- for (let ay = 0; ay < sqrtNumArea; ay++) for (let ax = 0; ax < sqrtNumArea; ax++) for (let dy = 0; dy < areaHeight; dy++) for (let dx = 0; dx < areaWidth; dx++) grayScaleImageData.data[areaWidth * ax + dx + (areaHeight * ay + dy) * grayScaleImageData.width] = grayScaleImageData.data[areaWidth * ax + dx + (areaHeight * ay + dy) * grayScaleImageData.width] < middle[ax][ay];
2955
- return grayScaleImageData;
2956
- };
2957
- QrCode.prototype.grayscale = function(imageData) {
2958
- const ret = new Array(imageData.width * imageData.height);
2959
- for (let y = 0; y < imageData.height; y++) for (let x = 0; x < imageData.width; x++) {
2960
- const gray = this.getPixel(imageData, x, y);
2961
- ret[x + y * imageData.width] = gray;
2962
- }
2963
- return {
2964
- height: imageData.height,
2965
- width: imageData.width,
2966
- data: ret
2967
- };
2968
- };
2969
- function URShift(number, bits) {
2970
- if (number >= 0) return number >> bits;
2971
- else return (number >> bits) + (2 << ~bits);
2972
- }
2973
- //#endregion
2974
- //#region src/internal/qr/vendor/reader/core/runtime.ts
2975
- /**
2976
- * @file 二维码核心 reader 运行时适配。
2977
- */
2978
- /** createLegacyQrCodeReader 的方法封装。 */
2979
- function createLegacyQrCodeReader() {
2980
- return new QrCode();
2981
- }
2982
- //#endregion
2983
- //#region src/internal/qr/vendor/reader/core/decode.ts
2984
- /** decodeWithLegacyQrCodeCore 的方法封装。 */
2985
- async function decodeWithLegacyQrCodeCore(input) {
2986
- return await new Promise((resolve, reject) => {
2987
- const reader = createLegacyQrCodeReader();
2988
- reader.callback = (error, value) => {
2989
- if (error) {
2990
- reject(error);
2991
- return;
2992
- }
2993
- resolve(normalizeQrCodeReaderResult(value));
2994
- };
2995
- reader.decode(input);
2996
- });
2997
- }
2998
- //#endregion
2999
- //#region src/internal/qr/vendor/reader/decode.ts
3000
- /**
3001
- * @file 二维码 reader vendor 纯函数解码入口。
3002
- */
3003
- /** decodeWithVendorQrReader 的方法封装。 */
3004
- async function decodeWithVendorQrReader(input) {
3005
- return await decodeWithLegacyQrCodeCore(input);
3006
- }
3007
- //#endregion
3008
- //#region src/internal/qr/decode.ts
3009
- /**
3010
- * @file 基于 sharp 的二维码解码封装。
3011
- */
3012
- async function decodeQrCodeBuffer(buffer) {
3013
- const { data, info } = await sharp(buffer).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
3014
- return (await decodeWithVendorQrReader({
3015
- width: info.width,
3016
- height: info.height,
3017
- data
3018
- })).result;
3019
- }
3020
- /** decodeQrCodeFromBase64 的方法封装。 */
3021
- async function decodeQrCodeFromBase64(content) {
3022
- return await decodeQrCodeBuffer(Buffer.from(content, "base64"));
3023
- }
3024
- //#endregion
3025
- //#region src/internal/qr/vendor/terminal/QRCode/QRMode.ts
3026
- /**
3027
- * @file 终端二维码编码内部模块:QRMode。
3028
- */
3029
- const QRMode = {
3030
- MODE_NUMBER: 1,
3031
- MODE_ALPHA_NUM: 2,
3032
- MODE_8BIT_BYTE: 4,
3033
- MODE_KANJI: 8
3034
- };
3035
- //#endregion
3036
- //#region src/internal/qr/vendor/terminal/QRCode/QR8bitByte.ts
3037
- /**
3038
- * @file 终端二维码编码内部模块:QR8bitByte。
3039
- */
3040
- function QR8bitByte(data) {
3041
- this.mode = QRMode.MODE_8BIT_BYTE;
3042
- this.data = data;
3043
- }
3044
- QR8bitByte.prototype = {
3045
- getLength() {
3046
- return this.data.length;
3047
- },
3048
- write(buffer) {
3049
- for (let i = 0; i < this.data.length; i++) buffer.put(this.data.charCodeAt(i), 8);
3050
- }
3051
- };
3052
- //#endregion
3053
- //#region src/internal/qr/vendor/terminal/QRCode/QRBitBuffer.ts
3054
- /**
3055
- * @file 终端二维码编码内部模块:QRBitBuffer。
3056
- */
3057
- function QRBitBuffer() {
3058
- this.buffer = [];
3059
- this.length = 0;
3060
- }
3061
- QRBitBuffer.prototype = {
3062
- get(index) {
3063
- const bufIndex = Math.floor(index / 8);
3064
- return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) == 1;
3065
- },
3066
- put(num, length) {
3067
- for (let i = 0; i < length; i++) this.putBit((num >>> length - i - 1 & 1) == 1);
3068
- },
3069
- getLengthInBits() {
3070
- return this.length;
3071
- },
3072
- putBit(bit) {
3073
- const bufIndex = Math.floor(this.length / 8);
3074
- if (this.buffer.length <= bufIndex) this.buffer.push(0);
3075
- if (bit) this.buffer[bufIndex] |= 128 >>> this.length % 8;
3076
- this.length++;
3077
- }
3078
- };
3079
- //#endregion
3080
- //#region src/internal/qr/vendor/terminal/QRCode/QRMath.ts
3081
- /**
3082
- * @file 终端二维码编码内部模块:QRMath。
3083
- */
3084
- var QRMath = {
3085
- glog(n) {
3086
- if (n < 1) throw new Error(`glog(${n})`);
3087
- return QRMath.LOG_TABLE[n];
3088
- },
3089
- gexp(n) {
3090
- while (n < 0) n += 255;
3091
- while (n >= 256) n -= 255;
3092
- return QRMath.EXP_TABLE[n];
3093
- },
3094
- EXP_TABLE: Array.from({ length: 256 }),
3095
- LOG_TABLE: Array.from({ length: 256 })
3096
- };
3097
- for (var i = 0; i < 8; i++) QRMath.EXP_TABLE[i] = 1 << i;
3098
- for (var i = 8; i < 256; i++) QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4] ^ QRMath.EXP_TABLE[i - 5] ^ QRMath.EXP_TABLE[i - 6] ^ QRMath.EXP_TABLE[i - 8];
3099
- for (var i = 0; i < 255; i++) QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i;
3100
- //#endregion
3101
- //#region src/internal/qr/vendor/terminal/QRCode/QRPolynomial.ts
3102
- /**
3103
- * @file 终端二维码编码内部模块:QRPolynomial。
3104
- */
3105
- function QRPolynomial(num, shift) {
3106
- if (num.length === void 0) throw new Error(`${num.length}/${shift}`);
3107
- let offset = 0;
3108
- while (offset < num.length && num[offset] === 0) offset++;
3109
- this.num = new Array(num.length - offset + shift);
3110
- for (let i = 0; i < num.length - offset; i++) this.num[i] = num[i + offset];
3111
- }
3112
- QRPolynomial.prototype = {
3113
- get(index) {
3114
- return this.num[index];
3115
- },
3116
- getLength() {
3117
- return this.num.length;
3118
- },
3119
- multiply(e) {
3120
- const num = Array.from({ length: this.getLength() + e.getLength() - 1 });
3121
- for (let i = 0; i < this.getLength(); i++) for (let j = 0; j < e.getLength(); j++) num[i + j] ^= QRMath.gexp(QRMath.glog(this.get(i)) + QRMath.glog(e.get(j)));
3122
- return new QRPolynomial(num, 0);
3123
- },
3124
- mod(e) {
3125
- if (this.getLength() - e.getLength() < 0) return this;
3126
- const ratio = QRMath.glog(this.get(0)) - QRMath.glog(e.get(0));
3127
- const num = new Array(this.getLength());
3128
- for (let i = 0; i < this.getLength(); i++) num[i] = this.get(i);
3129
- for (let x = 0; x < e.getLength(); x++) num[x] ^= QRMath.gexp(QRMath.glog(e.get(x)) + ratio);
3130
- return new QRPolynomial(num, 0).mod(e);
3131
- }
3132
- };
3133
- //#endregion
3134
- //#region src/internal/qr/vendor/terminal/QRCode/QRErrorCorrectLevel.ts
3135
- /**
3136
- * @file 终端二维码编码内部模块:QRErrorCorrectLevel。
3137
- */
3138
- const QRErrorCorrectLevel = {
3139
- L: 1,
3140
- M: 0,
3141
- Q: 3,
3142
- H: 2
3143
- };
3144
- //#endregion
3145
- //#region src/internal/qr/vendor/terminal/QRCode/QRRSBlock.ts
3146
- /**
3147
- * @file 终端二维码编码内部模块:QRRSBlock。
3148
- */
3149
- function QRRSBlock(totalCount, dataCount) {
3150
- this.totalCount = totalCount;
3151
- this.dataCount = dataCount;
3152
- }
3153
- QRRSBlock.RS_BLOCK_TABLE = [
3154
- [
3155
- 1,
3156
- 26,
3157
- 19
3158
- ],
3159
- [
3160
- 1,
3161
- 26,
3162
- 16
3163
- ],
3164
- [
3165
- 1,
3166
- 26,
3167
- 13
3168
- ],
3169
- [
3170
- 1,
3171
- 26,
3172
- 9
3173
- ],
3174
- [
3175
- 1,
3176
- 44,
3177
- 34
3178
- ],
3179
- [
3180
- 1,
3181
- 44,
3182
- 28
3183
- ],
3184
- [
3185
- 1,
3186
- 44,
3187
- 22
3188
- ],
3189
- [
3190
- 1,
3191
- 44,
3192
- 16
3193
- ],
3194
- [
3195
- 1,
3196
- 70,
3197
- 55
3198
- ],
3199
- [
3200
- 1,
3201
- 70,
3202
- 44
3203
- ],
3204
- [
3205
- 2,
3206
- 35,
3207
- 17
3208
- ],
3209
- [
3210
- 2,
3211
- 35,
3212
- 13
3213
- ],
3214
- [
3215
- 1,
3216
- 100,
3217
- 80
3218
- ],
3219
- [
3220
- 2,
3221
- 50,
3222
- 32
3223
- ],
3224
- [
3225
- 2,
3226
- 50,
3227
- 24
3228
- ],
3229
- [
3230
- 4,
3231
- 25,
3232
- 9
3233
- ],
3234
- [
3235
- 1,
3236
- 134,
3237
- 108
3238
- ],
3239
- [
3240
- 2,
3241
- 67,
3242
- 43
3243
- ],
3244
- [
3245
- 2,
3246
- 33,
3247
- 15,
3248
- 2,
3249
- 34,
3250
- 16
3251
- ],
3252
- [
3253
- 2,
3254
- 33,
3255
- 11,
3256
- 2,
3257
- 34,
3258
- 12
3259
- ],
3260
- [
3261
- 2,
3262
- 86,
3263
- 68
3264
- ],
3265
- [
3266
- 4,
3267
- 43,
3268
- 27
3269
- ],
3270
- [
3271
- 4,
3272
- 43,
3273
- 19
3274
- ],
3275
- [
3276
- 4,
3277
- 43,
3278
- 15
3279
- ],
3280
- [
3281
- 2,
3282
- 98,
3283
- 78
3284
- ],
3285
- [
3286
- 4,
3287
- 49,
3288
- 31
3289
- ],
3290
- [
3291
- 2,
3292
- 32,
3293
- 14,
3294
- 4,
3295
- 33,
3296
- 15
3297
- ],
3298
- [
3299
- 4,
3300
- 39,
3301
- 13,
3302
- 1,
3303
- 40,
3304
- 14
3305
- ],
3306
- [
3307
- 2,
3308
- 121,
3309
- 97
3310
- ],
3311
- [
3312
- 2,
3313
- 60,
3314
- 38,
3315
- 2,
3316
- 61,
3317
- 39
3318
- ],
3319
- [
3320
- 4,
3321
- 40,
3322
- 18,
3323
- 2,
3324
- 41,
3325
- 19
3326
- ],
3327
- [
3328
- 4,
3329
- 40,
3330
- 14,
3331
- 2,
3332
- 41,
3333
- 15
3334
- ],
3335
- [
3336
- 2,
3337
- 146,
3338
- 116
3339
- ],
3340
- [
3341
- 3,
3342
- 58,
3343
- 36,
3344
- 2,
3345
- 59,
3346
- 37
3347
- ],
3348
- [
3349
- 4,
3350
- 36,
3351
- 16,
3352
- 4,
3353
- 37,
3354
- 17
3355
- ],
3356
- [
3357
- 4,
3358
- 36,
3359
- 12,
3360
- 4,
3361
- 37,
3362
- 13
3363
- ],
3364
- [
3365
- 2,
3366
- 86,
3367
- 68,
3368
- 2,
3369
- 87,
3370
- 69
3371
- ],
3372
- [
3373
- 4,
3374
- 69,
3375
- 43,
3376
- 1,
3377
- 70,
3378
- 44
3379
- ],
3380
- [
3381
- 6,
3382
- 43,
3383
- 19,
3384
- 2,
3385
- 44,
3386
- 20
3387
- ],
3388
- [
3389
- 6,
3390
- 43,
3391
- 15,
3392
- 2,
3393
- 44,
3394
- 16
3395
- ],
3396
- [
3397
- 4,
3398
- 101,
3399
- 81
3400
- ],
3401
- [
3402
- 1,
3403
- 80,
3404
- 50,
3405
- 4,
3406
- 81,
3407
- 51
3408
- ],
3409
- [
3410
- 4,
3411
- 50,
3412
- 22,
3413
- 4,
3414
- 51,
3415
- 23
3416
- ],
3417
- [
3418
- 3,
3419
- 36,
3420
- 12,
3421
- 8,
3422
- 37,
3423
- 13
3424
- ],
3425
- [
3426
- 2,
3427
- 116,
3428
- 92,
3429
- 2,
3430
- 117,
3431
- 93
3432
- ],
3433
- [
3434
- 6,
3435
- 58,
3436
- 36,
3437
- 2,
3438
- 59,
3439
- 37
3440
- ],
3441
- [
3442
- 4,
3443
- 46,
3444
- 20,
3445
- 6,
3446
- 47,
3447
- 21
3448
- ],
3449
- [
3450
- 7,
3451
- 42,
3452
- 14,
3453
- 4,
3454
- 43,
3455
- 15
3456
- ],
3457
- [
3458
- 4,
3459
- 133,
3460
- 107
3461
- ],
3462
- [
3463
- 8,
3464
- 59,
3465
- 37,
3466
- 1,
3467
- 60,
3468
- 38
3469
- ],
3470
- [
3471
- 8,
3472
- 44,
3473
- 20,
3474
- 4,
3475
- 45,
3476
- 21
3477
- ],
3478
- [
3479
- 12,
3480
- 33,
3481
- 11,
3482
- 4,
3483
- 34,
3484
- 12
3485
- ],
3486
- [
3487
- 3,
3488
- 145,
3489
- 115,
3490
- 1,
3491
- 146,
3492
- 116
3493
- ],
3494
- [
3495
- 4,
3496
- 64,
3497
- 40,
3498
- 5,
3499
- 65,
3500
- 41
3501
- ],
3502
- [
3503
- 11,
3504
- 36,
3505
- 16,
3506
- 5,
3507
- 37,
3508
- 17
3509
- ],
3510
- [
3511
- 11,
3512
- 36,
3513
- 12,
3514
- 5,
3515
- 37,
3516
- 13
3517
- ],
3518
- [
3519
- 5,
3520
- 109,
3521
- 87,
3522
- 1,
3523
- 110,
3524
- 88
3525
- ],
3526
- [
3527
- 5,
3528
- 65,
3529
- 41,
3530
- 5,
3531
- 66,
3532
- 42
3533
- ],
3534
- [
3535
- 5,
3536
- 54,
3537
- 24,
3538
- 7,
3539
- 55,
3540
- 25
3541
- ],
3542
- [
3543
- 11,
3544
- 36,
3545
- 12
3546
- ],
3547
- [
3548
- 5,
3549
- 122,
3550
- 98,
3551
- 1,
3552
- 123,
3553
- 99
3554
- ],
3555
- [
3556
- 7,
3557
- 73,
3558
- 45,
3559
- 3,
3560
- 74,
3561
- 46
3562
- ],
3563
- [
3564
- 15,
3565
- 43,
3566
- 19,
3567
- 2,
3568
- 44,
3569
- 20
3570
- ],
3571
- [
3572
- 3,
3573
- 45,
3574
- 15,
3575
- 13,
3576
- 46,
3577
- 16
3578
- ],
3579
- [
3580
- 1,
3581
- 135,
3582
- 107,
3583
- 5,
3584
- 136,
3585
- 108
3586
- ],
3587
- [
3588
- 10,
3589
- 74,
3590
- 46,
3591
- 1,
3592
- 75,
3593
- 47
3594
- ],
3595
- [
3596
- 1,
3597
- 50,
3598
- 22,
3599
- 15,
3600
- 51,
3601
- 23
3602
- ],
3603
- [
3604
- 2,
3605
- 42,
3606
- 14,
3607
- 17,
3608
- 43,
3609
- 15
3610
- ],
3611
- [
3612
- 5,
3613
- 150,
3614
- 120,
3615
- 1,
3616
- 151,
3617
- 121
3618
- ],
3619
- [
3620
- 9,
3621
- 69,
3622
- 43,
3623
- 4,
3624
- 70,
3625
- 44
3626
- ],
3627
- [
3628
- 17,
3629
- 50,
3630
- 22,
3631
- 1,
3632
- 51,
3633
- 23
3634
- ],
3635
- [
3636
- 2,
3637
- 42,
3638
- 14,
3639
- 19,
3640
- 43,
3641
- 15
3642
- ],
3643
- [
3644
- 3,
3645
- 141,
3646
- 113,
3647
- 4,
3648
- 142,
3649
- 114
3650
- ],
3651
- [
3652
- 3,
3653
- 70,
3654
- 44,
3655
- 11,
3656
- 71,
3657
- 45
3658
- ],
3659
- [
3660
- 17,
3661
- 47,
3662
- 21,
3663
- 4,
3664
- 48,
3665
- 22
3666
- ],
3667
- [
3668
- 9,
3669
- 39,
3670
- 13,
3671
- 16,
3672
- 40,
3673
- 14
3674
- ],
3675
- [
3676
- 3,
3677
- 135,
3678
- 107,
3679
- 5,
3680
- 136,
3681
- 108
3682
- ],
3683
- [
3684
- 3,
3685
- 67,
3686
- 41,
3687
- 13,
3688
- 68,
3689
- 42
3690
- ],
3691
- [
3692
- 15,
3693
- 54,
3694
- 24,
3695
- 5,
3696
- 55,
3697
- 25
3698
- ],
3699
- [
3700
- 15,
3701
- 43,
3702
- 15,
3703
- 10,
3704
- 44,
3705
- 16
3706
- ],
3707
- [
3708
- 4,
3709
- 144,
3710
- 116,
3711
- 4,
3712
- 145,
3713
- 117
3714
- ],
3715
- [
3716
- 17,
3717
- 68,
3718
- 42
3719
- ],
3720
- [
3721
- 17,
3722
- 50,
3723
- 22,
3724
- 6,
3725
- 51,
3726
- 23
3727
- ],
3728
- [
3729
- 19,
3730
- 46,
3731
- 16,
3732
- 6,
3733
- 47,
3734
- 17
3735
- ],
3736
- [
3737
- 2,
3738
- 139,
3739
- 111,
3740
- 7,
3741
- 140,
3742
- 112
3743
- ],
3744
- [
3745
- 17,
3746
- 74,
3747
- 46
3748
- ],
3749
- [
3750
- 7,
3751
- 54,
3752
- 24,
3753
- 16,
3754
- 55,
3755
- 25
3756
- ],
3757
- [
3758
- 34,
3759
- 37,
3760
- 13
3761
- ],
3762
- [
3763
- 4,
3764
- 151,
3765
- 121,
3766
- 5,
3767
- 152,
3768
- 122
3769
- ],
3770
- [
3771
- 4,
3772
- 75,
3773
- 47,
3774
- 14,
3775
- 76,
3776
- 48
3777
- ],
3778
- [
3779
- 11,
3780
- 54,
3781
- 24,
3782
- 14,
3783
- 55,
3784
- 25
3785
- ],
3786
- [
3787
- 16,
3788
- 45,
3789
- 15,
3790
- 14,
3791
- 46,
3792
- 16
3793
- ],
3794
- [
3795
- 6,
3796
- 147,
3797
- 117,
3798
- 4,
3799
- 148,
3800
- 118
3801
- ],
3802
- [
3803
- 6,
3804
- 73,
3805
- 45,
3806
- 14,
3807
- 74,
3808
- 46
3809
- ],
3810
- [
3811
- 11,
3812
- 54,
3813
- 24,
3814
- 16,
3815
- 55,
3816
- 25
3817
- ],
3818
- [
3819
- 30,
3820
- 46,
3821
- 16,
3822
- 2,
3823
- 47,
3824
- 17
3825
- ],
3826
- [
3827
- 8,
3828
- 132,
3829
- 106,
3830
- 4,
3831
- 133,
3832
- 107
3833
- ],
3834
- [
3835
- 8,
3836
- 75,
3837
- 47,
3838
- 13,
3839
- 76,
3840
- 48
3841
- ],
3842
- [
3843
- 7,
3844
- 54,
3845
- 24,
3846
- 22,
3847
- 55,
3848
- 25
3849
- ],
3850
- [
3851
- 22,
3852
- 45,
3853
- 15,
3854
- 13,
3855
- 46,
3856
- 16
3857
- ],
3858
- [
3859
- 10,
3860
- 142,
3861
- 114,
3862
- 2,
3863
- 143,
3864
- 115
3865
- ],
3866
- [
3867
- 19,
3868
- 74,
3869
- 46,
3870
- 4,
3871
- 75,
3872
- 47
3873
- ],
3874
- [
3875
- 28,
3876
- 50,
3877
- 22,
3878
- 6,
3879
- 51,
3880
- 23
3881
- ],
3882
- [
3883
- 33,
3884
- 46,
3885
- 16,
3886
- 4,
3887
- 47,
3888
- 17
3889
- ],
3890
- [
3891
- 8,
3892
- 152,
3893
- 122,
3894
- 4,
3895
- 153,
3896
- 123
3897
- ],
3898
- [
3899
- 22,
3900
- 73,
3901
- 45,
3902
- 3,
3903
- 74,
3904
- 46
3905
- ],
3906
- [
3907
- 8,
3908
- 53,
3909
- 23,
3910
- 26,
3911
- 54,
3912
- 24
3913
- ],
3914
- [
3915
- 12,
3916
- 45,
3917
- 15,
3918
- 28,
3919
- 46,
3920
- 16
3921
- ],
3922
- [
3923
- 3,
3924
- 147,
3925
- 117,
3926
- 10,
3927
- 148,
3928
- 118
3929
- ],
3930
- [
3931
- 3,
3932
- 73,
3933
- 45,
3934
- 23,
3935
- 74,
3936
- 46
3937
- ],
3938
- [
3939
- 4,
3940
- 54,
3941
- 24,
3942
- 31,
3943
- 55,
3944
- 25
3945
- ],
3946
- [
3947
- 11,
3948
- 45,
3949
- 15,
3950
- 31,
3951
- 46,
3952
- 16
3953
- ],
3954
- [
3955
- 7,
3956
- 146,
3957
- 116,
3958
- 7,
3959
- 147,
3960
- 117
3961
- ],
3962
- [
3963
- 21,
3964
- 73,
3965
- 45,
3966
- 7,
3967
- 74,
3968
- 46
3969
- ],
3970
- [
3971
- 1,
3972
- 53,
3973
- 23,
3974
- 37,
3975
- 54,
3976
- 24
3977
- ],
3978
- [
3979
- 19,
3980
- 45,
3981
- 15,
3982
- 26,
3983
- 46,
3984
- 16
3985
- ],
3986
- [
3987
- 5,
3988
- 145,
3989
- 115,
3990
- 10,
3991
- 146,
3992
- 116
3993
- ],
3994
- [
3995
- 19,
3996
- 75,
3997
- 47,
3998
- 10,
3999
- 76,
4000
- 48
4001
- ],
4002
- [
4003
- 15,
4004
- 54,
4005
- 24,
4006
- 25,
4007
- 55,
4008
- 25
4009
- ],
4010
- [
4011
- 23,
4012
- 45,
4013
- 15,
4014
- 25,
4015
- 46,
4016
- 16
4017
- ],
4018
- [
4019
- 13,
4020
- 145,
4021
- 115,
4022
- 3,
4023
- 146,
4024
- 116
4025
- ],
4026
- [
4027
- 2,
4028
- 74,
4029
- 46,
4030
- 29,
4031
- 75,
4032
- 47
4033
- ],
4034
- [
4035
- 42,
4036
- 54,
4037
- 24,
4038
- 1,
4039
- 55,
4040
- 25
4041
- ],
4042
- [
4043
- 23,
4044
- 45,
4045
- 15,
4046
- 28,
4047
- 46,
4048
- 16
4049
- ],
4050
- [
4051
- 17,
4052
- 145,
4053
- 115
4054
- ],
4055
- [
4056
- 10,
4057
- 74,
4058
- 46,
4059
- 23,
4060
- 75,
4061
- 47
4062
- ],
4063
- [
4064
- 10,
4065
- 54,
4066
- 24,
4067
- 35,
4068
- 55,
4069
- 25
4070
- ],
4071
- [
4072
- 19,
4073
- 45,
4074
- 15,
4075
- 35,
4076
- 46,
4077
- 16
4078
- ],
4079
- [
4080
- 17,
4081
- 145,
4082
- 115,
4083
- 1,
4084
- 146,
4085
- 116
4086
- ],
4087
- [
4088
- 14,
4089
- 74,
4090
- 46,
4091
- 21,
4092
- 75,
4093
- 47
4094
- ],
4095
- [
4096
- 29,
4097
- 54,
4098
- 24,
4099
- 19,
4100
- 55,
4101
- 25
4102
- ],
4103
- [
4104
- 11,
4105
- 45,
4106
- 15,
4107
- 46,
4108
- 46,
4109
- 16
4110
- ],
4111
- [
4112
- 13,
4113
- 145,
4114
- 115,
4115
- 6,
4116
- 146,
4117
- 116
4118
- ],
4119
- [
4120
- 14,
4121
- 74,
4122
- 46,
4123
- 23,
4124
- 75,
4125
- 47
4126
- ],
4127
- [
4128
- 44,
4129
- 54,
4130
- 24,
4131
- 7,
4132
- 55,
4133
- 25
4134
- ],
4135
- [
4136
- 59,
4137
- 46,
4138
- 16,
4139
- 1,
4140
- 47,
4141
- 17
4142
- ],
4143
- [
4144
- 12,
4145
- 151,
4146
- 121,
4147
- 7,
4148
- 152,
4149
- 122
4150
- ],
4151
- [
4152
- 12,
4153
- 75,
4154
- 47,
4155
- 26,
4156
- 76,
4157
- 48
4158
- ],
4159
- [
4160
- 39,
4161
- 54,
4162
- 24,
4163
- 14,
4164
- 55,
4165
- 25
4166
- ],
4167
- [
4168
- 22,
4169
- 45,
4170
- 15,
4171
- 41,
4172
- 46,
4173
- 16
4174
- ],
4175
- [
4176
- 6,
4177
- 151,
4178
- 121,
4179
- 14,
4180
- 152,
4181
- 122
4182
- ],
4183
- [
4184
- 6,
4185
- 75,
4186
- 47,
4187
- 34,
4188
- 76,
4189
- 48
4190
- ],
4191
- [
4192
- 46,
4193
- 54,
4194
- 24,
4195
- 10,
4196
- 55,
4197
- 25
4198
- ],
4199
- [
4200
- 2,
4201
- 45,
4202
- 15,
4203
- 64,
4204
- 46,
4205
- 16
4206
- ],
4207
- [
4208
- 17,
4209
- 152,
4210
- 122,
4211
- 4,
4212
- 153,
4213
- 123
4214
- ],
4215
- [
4216
- 29,
4217
- 74,
4218
- 46,
4219
- 14,
4220
- 75,
4221
- 47
4222
- ],
4223
- [
4224
- 49,
4225
- 54,
4226
- 24,
4227
- 10,
4228
- 55,
4229
- 25
4230
- ],
4231
- [
4232
- 24,
4233
- 45,
4234
- 15,
4235
- 46,
4236
- 46,
4237
- 16
4238
- ],
4239
- [
4240
- 4,
4241
- 152,
4242
- 122,
4243
- 18,
4244
- 153,
4245
- 123
4246
- ],
4247
- [
4248
- 13,
4249
- 74,
4250
- 46,
4251
- 32,
4252
- 75,
4253
- 47
4254
- ],
4255
- [
4256
- 48,
4257
- 54,
4258
- 24,
4259
- 14,
4260
- 55,
4261
- 25
4262
- ],
4263
- [
4264
- 42,
4265
- 45,
4266
- 15,
4267
- 32,
4268
- 46,
4269
- 16
4270
- ],
4271
- [
4272
- 20,
4273
- 147,
4274
- 117,
4275
- 4,
4276
- 148,
4277
- 118
4278
- ],
4279
- [
4280
- 40,
4281
- 75,
4282
- 47,
4283
- 7,
4284
- 76,
4285
- 48
4286
- ],
4287
- [
4288
- 43,
4289
- 54,
4290
- 24,
4291
- 22,
4292
- 55,
4293
- 25
4294
- ],
4295
- [
4296
- 10,
4297
- 45,
4298
- 15,
4299
- 67,
4300
- 46,
4301
- 16
4302
- ],
4303
- [
4304
- 19,
4305
- 148,
4306
- 118,
4307
- 6,
4308
- 149,
4309
- 119
4310
- ],
4311
- [
4312
- 18,
4313
- 75,
4314
- 47,
4315
- 31,
4316
- 76,
4317
- 48
4318
- ],
4319
- [
4320
- 34,
4321
- 54,
4322
- 24,
4323
- 34,
4324
- 55,
4325
- 25
4326
- ],
4327
- [
4328
- 20,
4329
- 45,
4330
- 15,
4331
- 61,
4332
- 46,
4333
- 16
4334
- ]
4335
- ];
4336
- QRRSBlock.getRSBlocks = function(typeNumber, errorCorrectLevel) {
4337
- const rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel);
4338
- if (rsBlock === void 0) throw new Error(`bad rs block @ typeNumber:${typeNumber}/errorCorrectLevel:${errorCorrectLevel}`);
4339
- const length = rsBlock.length / 3;
4340
- const list = [];
4341
- for (let i = 0; i < length; i++) {
4342
- const count = rsBlock[i * 3 + 0];
4343
- const totalCount = rsBlock[i * 3 + 1];
4344
- const dataCount = rsBlock[i * 3 + 2];
4345
- for (let j = 0; j < count; j++) list.push(new QRRSBlock(totalCount, dataCount));
4346
- }
4347
- return list;
4348
- };
4349
- QRRSBlock.getRsBlockTable = function(typeNumber, errorCorrectLevel) {
4350
- switch (errorCorrectLevel) {
4351
- case QRErrorCorrectLevel.L: return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
4352
- case QRErrorCorrectLevel.M: return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
4353
- case QRErrorCorrectLevel.Q: return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
4354
- case QRErrorCorrectLevel.H: return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
4355
- default: return;
4356
- }
4357
- };
4358
- //#endregion
4359
- //#region src/internal/qr/vendor/terminal/QRCode/QRMaskPattern.ts
4360
- /**
4361
- * @file 终端二维码编码内部模块:QRMaskPattern。
4362
- */
4363
- const QRMaskPattern = {
4364
- PATTERN000: 0,
4365
- PATTERN001: 1,
4366
- PATTERN010: 2,
4367
- PATTERN011: 3,
4368
- PATTERN100: 4,
4369
- PATTERN101: 5,
4370
- PATTERN110: 6,
4371
- PATTERN111: 7
4372
- };
4373
- //#endregion
4374
- //#region src/internal/qr/vendor/terminal/QRCode/QRUtil.ts
4375
- /**
4376
- * @file 终端二维码编码内部模块:QRUtil。
4377
- */
4378
- var QRUtil = {
4379
- PATTERN_POSITION_TABLE: [
4380
- [],
4381
- [6, 18],
4382
- [6, 22],
4383
- [6, 26],
4384
- [6, 30],
4385
- [6, 34],
4386
- [
4387
- 6,
4388
- 22,
4389
- 38
4390
- ],
4391
- [
4392
- 6,
4393
- 24,
4394
- 42
4395
- ],
4396
- [
4397
- 6,
4398
- 26,
4399
- 46
4400
- ],
4401
- [
4402
- 6,
4403
- 28,
4404
- 50
4405
- ],
4406
- [
4407
- 6,
4408
- 30,
4409
- 54
4410
- ],
4411
- [
4412
- 6,
4413
- 32,
4414
- 58
4415
- ],
4416
- [
4417
- 6,
4418
- 34,
4419
- 62
4420
- ],
4421
- [
4422
- 6,
4423
- 26,
4424
- 46,
4425
- 66
4426
- ],
4427
- [
4428
- 6,
4429
- 26,
4430
- 48,
4431
- 70
4432
- ],
4433
- [
4434
- 6,
4435
- 26,
4436
- 50,
4437
- 74
4438
- ],
4439
- [
4440
- 6,
4441
- 30,
4442
- 54,
4443
- 78
4444
- ],
4445
- [
4446
- 6,
4447
- 30,
4448
- 56,
4449
- 82
4450
- ],
4451
- [
4452
- 6,
4453
- 30,
4454
- 58,
4455
- 86
4456
- ],
4457
- [
4458
- 6,
4459
- 34,
4460
- 62,
4461
- 90
4462
- ],
4463
- [
4464
- 6,
4465
- 28,
4466
- 50,
4467
- 72,
4468
- 94
4469
- ],
4470
- [
4471
- 6,
4472
- 26,
4473
- 50,
4474
- 74,
4475
- 98
4476
- ],
4477
- [
4478
- 6,
4479
- 30,
4480
- 54,
4481
- 78,
4482
- 102
4483
- ],
4484
- [
4485
- 6,
4486
- 28,
4487
- 54,
4488
- 80,
4489
- 106
4490
- ],
4491
- [
4492
- 6,
4493
- 32,
4494
- 58,
4495
- 84,
4496
- 110
4497
- ],
4498
- [
4499
- 6,
4500
- 30,
4501
- 58,
4502
- 86,
4503
- 114
4504
- ],
4505
- [
4506
- 6,
4507
- 34,
4508
- 62,
4509
- 90,
4510
- 118
4511
- ],
4512
- [
4513
- 6,
4514
- 26,
4515
- 50,
4516
- 74,
4517
- 98,
4518
- 122
4519
- ],
4520
- [
4521
- 6,
4522
- 30,
4523
- 54,
4524
- 78,
4525
- 102,
4526
- 126
4527
- ],
4528
- [
4529
- 6,
4530
- 26,
4531
- 52,
4532
- 78,
4533
- 104,
4534
- 130
4535
- ],
4536
- [
4537
- 6,
4538
- 30,
4539
- 56,
4540
- 82,
4541
- 108,
4542
- 134
4543
- ],
4544
- [
4545
- 6,
4546
- 34,
4547
- 60,
4548
- 86,
4549
- 112,
4550
- 138
4551
- ],
4552
- [
4553
- 6,
4554
- 30,
4555
- 58,
4556
- 86,
4557
- 114,
4558
- 142
4559
- ],
4560
- [
4561
- 6,
4562
- 34,
4563
- 62,
4564
- 90,
4565
- 118,
4566
- 146
4567
- ],
4568
- [
4569
- 6,
4570
- 30,
4571
- 54,
4572
- 78,
4573
- 102,
4574
- 126,
4575
- 150
4576
- ],
4577
- [
4578
- 6,
4579
- 24,
4580
- 50,
4581
- 76,
4582
- 102,
4583
- 128,
4584
- 154
4585
- ],
4586
- [
4587
- 6,
4588
- 28,
4589
- 54,
4590
- 80,
4591
- 106,
4592
- 132,
4593
- 158
4594
- ],
4595
- [
4596
- 6,
4597
- 32,
4598
- 58,
4599
- 84,
4600
- 110,
4601
- 136,
4602
- 162
4603
- ],
4604
- [
4605
- 6,
4606
- 26,
4607
- 54,
4608
- 82,
4609
- 110,
4610
- 138,
4611
- 166
4612
- ],
4613
- [
4614
- 6,
4615
- 30,
4616
- 58,
4617
- 86,
4618
- 114,
4619
- 142,
4620
- 170
4621
- ]
4622
- ],
4623
- G15: 1335,
4624
- G18: 7973,
4625
- G15_MASK: 21522,
4626
- getBCHTypeInfo(data) {
4627
- let d = data << 10;
4628
- while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) d ^= QRUtil.G15 << QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15);
4629
- return (data << 10 | d) ^ QRUtil.G15_MASK;
4630
- },
4631
- getBCHTypeNumber(data) {
4632
- let d = data << 12;
4633
- while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) d ^= QRUtil.G18 << QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18);
4634
- return data << 12 | d;
4635
- },
4636
- getBCHDigit(data) {
4637
- let digit = 0;
4638
- while (data !== 0) {
4639
- digit++;
4640
- data >>>= 1;
4641
- }
4642
- return digit;
4643
- },
4644
- getPatternPosition(typeNumber) {
4645
- return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1];
4646
- },
4647
- getMask(maskPattern, i, j) {
4648
- switch (maskPattern) {
4649
- case QRMaskPattern.PATTERN000: return (i + j) % 2 === 0;
4650
- case QRMaskPattern.PATTERN001: return i % 2 === 0;
4651
- case QRMaskPattern.PATTERN010: return j % 3 === 0;
4652
- case QRMaskPattern.PATTERN011: return (i + j) % 3 === 0;
4653
- case QRMaskPattern.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0;
4654
- case QRMaskPattern.PATTERN101: return i * j % 2 + i * j % 3 === 0;
4655
- case QRMaskPattern.PATTERN110: return (i * j % 2 + i * j % 3) % 2 === 0;
4656
- case QRMaskPattern.PATTERN111: return (i * j % 3 + (i + j) % 2) % 2 === 0;
4657
- default: throw new Error(`bad maskPattern:${maskPattern}`);
4658
- }
4659
- },
4660
- getErrorCorrectPolynomial(errorCorrectLength) {
4661
- let a = new QRPolynomial([1], 0);
4662
- for (let i = 0; i < errorCorrectLength; i++) a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0));
4663
- return a;
4664
- },
4665
- getLengthInBits(mode, type) {
4666
- if (type >= 1 && type < 10) switch (mode) {
4667
- case QRMode.MODE_NUMBER: return 10;
4668
- case QRMode.MODE_ALPHA_NUM: return 9;
4669
- case QRMode.MODE_8BIT_BYTE: return 8;
4670
- case QRMode.MODE_KANJI: return 8;
4671
- default: throw new Error(`mode:${mode}`);
4672
- }
4673
- else if (type < 27) switch (mode) {
4674
- case QRMode.MODE_NUMBER: return 12;
4675
- case QRMode.MODE_ALPHA_NUM: return 11;
4676
- case QRMode.MODE_8BIT_BYTE: return 16;
4677
- case QRMode.MODE_KANJI: return 10;
4678
- default: throw new Error(`mode:${mode}`);
4679
- }
4680
- else if (type < 41) switch (mode) {
4681
- case QRMode.MODE_NUMBER: return 14;
4682
- case QRMode.MODE_ALPHA_NUM: return 13;
4683
- case QRMode.MODE_8BIT_BYTE: return 16;
4684
- case QRMode.MODE_KANJI: return 12;
4685
- default: throw new Error(`mode:${mode}`);
4686
- }
4687
- else throw new Error(`type:${type}`);
4688
- },
4689
- getLostPoint(qrCode) {
4690
- const moduleCount = qrCode.getModuleCount();
4691
- let lostPoint = 0;
4692
- let row = 0;
4693
- let col = 0;
4694
- for (row = 0; row < moduleCount; row++) for (col = 0; col < moduleCount; col++) {
4695
- let sameCount = 0;
4696
- const dark = qrCode.isDark(row, col);
4697
- for (let r = -1; r <= 1; r++) {
4698
- if (row + r < 0 || moduleCount <= row + r) continue;
4699
- for (let c = -1; c <= 1; c++) {
4700
- if (col + c < 0 || moduleCount <= col + c) continue;
4701
- if (r === 0 && c === 0) continue;
4702
- if (dark === qrCode.isDark(row + r, col + c)) sameCount++;
4703
- }
4704
- }
4705
- if (sameCount > 5) lostPoint += 3 + sameCount - 5;
4706
- }
4707
- for (row = 0; row < moduleCount - 1; row++) for (col = 0; col < moduleCount - 1; col++) {
4708
- let count = 0;
4709
- if (qrCode.isDark(row, col)) count++;
4710
- if (qrCode.isDark(row + 1, col)) count++;
4711
- if (qrCode.isDark(row, col + 1)) count++;
4712
- if (qrCode.isDark(row + 1, col + 1)) count++;
4713
- if (count === 0 || count === 4) lostPoint += 3;
4714
- }
4715
- for (row = 0; row < moduleCount; row++) for (col = 0; col < moduleCount - 6; col++) if (qrCode.isDark(row, col) && !qrCode.isDark(row, col + 1) && qrCode.isDark(row, col + 2) && qrCode.isDark(row, col + 3) && qrCode.isDark(row, col + 4) && !qrCode.isDark(row, col + 5) && qrCode.isDark(row, col + 6)) lostPoint += 40;
4716
- for (col = 0; col < moduleCount; col++) for (row = 0; row < moduleCount - 6; row++) if (qrCode.isDark(row, col) && !qrCode.isDark(row + 1, col) && qrCode.isDark(row + 2, col) && qrCode.isDark(row + 3, col) && qrCode.isDark(row + 4, col) && !qrCode.isDark(row + 5, col) && qrCode.isDark(row + 6, col)) lostPoint += 40;
4717
- let darkCount = 0;
4718
- for (col = 0; col < moduleCount; col++) for (row = 0; row < moduleCount; row++) if (qrCode.isDark(row, col)) darkCount++;
4719
- const ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
4720
- lostPoint += ratio * 10;
4721
- return lostPoint;
4722
- }
4723
- };
4724
- //#endregion
4725
- //#region src/internal/qr/vendor/terminal/QRCode/index.ts
4726
- /**
4727
- * @file 终端二维码编码内部模块:index。
4728
- */
4729
- function QRCode(typeNumber, errorCorrectLevel) {
4730
- this.typeNumber = typeNumber;
4731
- this.errorCorrectLevel = errorCorrectLevel;
4732
- this.modules = null;
4733
- this.moduleCount = 0;
4734
- this.dataCache = null;
4735
- this.dataList = [];
4736
- }
4737
- QRCode.prototype = {
4738
- addData(data) {
4739
- const newData = new QR8bitByte(data);
4740
- this.dataList.push(newData);
4741
- this.dataCache = null;
4742
- },
4743
- isDark(row, col) {
4744
- if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) throw new Error(`${row},${col}`);
4745
- return this.modules[row][col];
4746
- },
4747
- getModuleCount() {
4748
- return this.moduleCount;
4749
- },
4750
- make() {
4751
- if (this.typeNumber < 1) {
4752
- let typeNumber = 1;
4753
- for (typeNumber = 1; typeNumber < 40; typeNumber++) {
4754
- const rsBlocks = QRRSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel);
4755
- const buffer = new QRBitBuffer();
4756
- let totalDataCount = 0;
4757
- for (let i = 0; i < rsBlocks.length; i++) totalDataCount += rsBlocks[i].dataCount;
4758
- for (let x = 0; x < this.dataList.length; x++) {
4759
- const data = this.dataList[x];
4760
- buffer.put(data.mode, 4);
4761
- buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber));
4762
- data.write(buffer);
4763
- }
4764
- if (buffer.getLengthInBits() <= totalDataCount * 8) break;
4765
- }
4766
- this.typeNumber = typeNumber;
4767
- }
4768
- this.makeImpl(false, this.getBestMaskPattern());
4769
- },
4770
- makeImpl(test, maskPattern) {
4771
- this.moduleCount = this.typeNumber * 4 + 17;
4772
- this.modules = new Array(this.moduleCount);
4773
- for (let row = 0; row < this.moduleCount; row++) {
4774
- this.modules[row] = new Array(this.moduleCount);
4775
- for (let col = 0; col < this.moduleCount; col++) this.modules[row][col] = null;
4776
- }
4777
- this.setupPositionProbePattern(0, 0);
4778
- this.setupPositionProbePattern(this.moduleCount - 7, 0);
4779
- this.setupPositionProbePattern(0, this.moduleCount - 7);
4780
- this.setupPositionAdjustPattern();
4781
- this.setupTimingPattern();
4782
- this.setupTypeInfo(test, maskPattern);
4783
- if (this.typeNumber >= 7) this.setupTypeNumber(test);
4784
- if (this.dataCache === null) this.dataCache = QRCode.createData(this.typeNumber, this.errorCorrectLevel, this.dataList);
4785
- this.mapData(this.dataCache, maskPattern);
4786
- },
4787
- setupPositionProbePattern(row, col) {
4788
- for (let r = -1; r <= 7; r++) {
4789
- if (row + r <= -1 || this.moduleCount <= row + r) continue;
4790
- for (let c = -1; c <= 7; c++) {
4791
- if (col + c <= -1 || this.moduleCount <= col + c) continue;
4792
- 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) this.modules[row + r][col + c] = true;
4793
- else this.modules[row + r][col + c] = false;
4794
- }
4795
- }
4796
- },
4797
- getBestMaskPattern() {
4798
- let minLostPoint = 0;
4799
- let pattern = 0;
4800
- for (let i = 0; i < 8; i++) {
4801
- this.makeImpl(true, i);
4802
- const lostPoint = QRUtil.getLostPoint(this);
4803
- if (i === 0 || minLostPoint > lostPoint) {
4804
- minLostPoint = lostPoint;
4805
- pattern = i;
4806
- }
4807
- }
4808
- return pattern;
4809
- },
4810
- createMovieClip(target_mc, instance_name, depth) {
4811
- const qr_mc = target_mc.createEmptyMovieClip(instance_name, depth);
4812
- const cs = 1;
4813
- this.make();
4814
- for (let row = 0; row < this.modules.length; row++) {
4815
- const y = row * cs;
4816
- for (let col = 0; col < this.modules[row].length; col++) {
4817
- const x = col * cs;
4818
- if (this.modules[row][col]) {
4819
- qr_mc.beginFill(0, 100);
4820
- qr_mc.moveTo(x, y);
4821
- qr_mc.lineTo(x + cs, y);
4822
- qr_mc.lineTo(x + cs, y + cs);
4823
- qr_mc.lineTo(x, y + cs);
4824
- qr_mc.endFill();
4825
- }
4826
- }
4827
- }
4828
- return qr_mc;
4829
- },
4830
- setupTimingPattern() {
4831
- for (let r = 8; r < this.moduleCount - 8; r++) {
4832
- if (this.modules[r][6] !== null) continue;
4833
- this.modules[r][6] = r % 2 === 0;
4834
- }
4835
- for (let c = 8; c < this.moduleCount - 8; c++) {
4836
- if (this.modules[6][c] !== null) continue;
4837
- this.modules[6][c] = c % 2 === 0;
4838
- }
4839
- },
4840
- setupPositionAdjustPattern() {
4841
- const pos = QRUtil.getPatternPosition(this.typeNumber);
4842
- for (let i = 0; i < pos.length; i++) for (let j = 0; j < pos.length; j++) {
4843
- const row = pos[i];
4844
- const col = pos[j];
4845
- if (this.modules[row][col] !== null) continue;
4846
- for (let r = -2; r <= 2; r++) for (let c = -2; c <= 2; c++) if (Math.abs(r) === 2 || Math.abs(c) === 2 || r === 0 && c === 0) this.modules[row + r][col + c] = true;
4847
- else this.modules[row + r][col + c] = false;
4848
- }
4849
- },
4850
- setupTypeNumber(test) {
4851
- const bits = QRUtil.getBCHTypeNumber(this.typeNumber);
4852
- let mod;
4853
- for (let i = 0; i < 18; i++) {
4854
- mod = !test && (bits >> i & 1) === 1;
4855
- this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod;
4856
- }
4857
- for (let x = 0; x < 18; x++) {
4858
- mod = !test && (bits >> x & 1) === 1;
4859
- this.modules[x % 3 + this.moduleCount - 8 - 3][Math.floor(x / 3)] = mod;
4860
- }
4861
- },
4862
- setupTypeInfo(test, maskPattern) {
4863
- const data = this.errorCorrectLevel << 3 | maskPattern;
4864
- const bits = QRUtil.getBCHTypeInfo(data);
4865
- let mod;
4866
- for (let v = 0; v < 15; v++) {
4867
- mod = !test && (bits >> v & 1) === 1;
4868
- if (v < 6) this.modules[v][8] = mod;
4869
- else if (v < 8) this.modules[v + 1][8] = mod;
4870
- else this.modules[this.moduleCount - 15 + v][8] = mod;
4871
- }
4872
- for (let h = 0; h < 15; h++) {
4873
- mod = !test && (bits >> h & 1) === 1;
4874
- if (h < 8) this.modules[8][this.moduleCount - h - 1] = mod;
4875
- else if (h < 9) this.modules[8][15 - h - 1 + 1] = mod;
4876
- else this.modules[8][15 - h - 1] = mod;
4877
- }
4878
- this.modules[this.moduleCount - 8][8] = !test;
4879
- },
4880
- mapData(data, maskPattern) {
4881
- let inc = -1;
4882
- let row = this.moduleCount - 1;
4883
- let bitIndex = 7;
4884
- let byteIndex = 0;
4885
- for (let col = this.moduleCount - 1; col > 0; col -= 2) {
4886
- if (col === 6) col--;
4887
- while (true) {
4888
- for (let c = 0; c < 2; c++) if (this.modules[row][col - c] === null) {
4889
- let dark = false;
4890
- if (byteIndex < data.length) dark = (data[byteIndex] >>> bitIndex & 1) === 1;
4891
- if (QRUtil.getMask(maskPattern, row, col - c)) dark = !dark;
4892
- this.modules[row][col - c] = dark;
4893
- bitIndex--;
4894
- if (bitIndex === -1) {
4895
- byteIndex++;
4896
- bitIndex = 7;
4897
- }
4898
- }
4899
- row += inc;
4900
- if (row < 0 || this.moduleCount <= row) {
4901
- row -= inc;
4902
- inc = -inc;
4903
- break;
4904
- }
4905
- }
4906
- }
4907
- }
4908
- };
4909
- QRCode.PAD0 = 236;
4910
- QRCode.PAD1 = 17;
4911
- QRCode.createData = function(typeNumber, errorCorrectLevel, dataList) {
4912
- const rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel);
4913
- const buffer = new QRBitBuffer();
4914
- for (let i = 0; i < dataList.length; i++) {
4915
- const data = dataList[i];
4916
- buffer.put(data.mode, 4);
4917
- buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber));
4918
- data.write(buffer);
4919
- }
4920
- let totalDataCount = 0;
4921
- for (let x = 0; x < rsBlocks.length; x++) totalDataCount += rsBlocks[x].dataCount;
4922
- if (buffer.getLengthInBits() > totalDataCount * 8) throw new Error(`code length overflow. (${buffer.getLengthInBits()}>${totalDataCount * 8})`);
4923
- if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) buffer.put(0, 4);
4924
- while (buffer.getLengthInBits() % 8 !== 0) buffer.putBit(false);
4925
- while (true) {
4926
- if (buffer.getLengthInBits() >= totalDataCount * 8) break;
4927
- buffer.put(QRCode.PAD0, 8);
4928
- if (buffer.getLengthInBits() >= totalDataCount * 8) break;
4929
- buffer.put(QRCode.PAD1, 8);
4930
- }
4931
- return QRCode.createBytes(buffer, rsBlocks);
4932
- };
4933
- QRCode.createBytes = function(buffer, rsBlocks) {
4934
- let offset = 0;
4935
- let maxDcCount = 0;
4936
- let maxEcCount = 0;
4937
- const dcdata = Array.from({ length: rsBlocks.length });
4938
- const ecdata = Array.from({ length: rsBlocks.length });
4939
- for (let r = 0; r < rsBlocks.length; r++) {
4940
- const dcCount = rsBlocks[r].dataCount;
4941
- const ecCount = rsBlocks[r].totalCount - dcCount;
4942
- maxDcCount = Math.max(maxDcCount, dcCount);
4943
- maxEcCount = Math.max(maxEcCount, ecCount);
4944
- dcdata[r] = new Array(dcCount);
4945
- for (let i = 0; i < dcdata[r].length; i++) dcdata[r][i] = 255 & buffer.buffer[i + offset];
4946
- offset += dcCount;
4947
- const rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
4948
- const modPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1).mod(rsPoly);
4949
- ecdata[r] = Array.from({ length: rsPoly.getLength() - 1 });
4950
- for (let x = 0; x < ecdata[r].length; x++) {
4951
- const modIndex = x + modPoly.getLength() - ecdata[r].length;
4952
- ecdata[r][x] = modIndex >= 0 ? modPoly.get(modIndex) : 0;
4953
- }
4954
- }
4955
- let totalCodeCount = 0;
4956
- for (let y = 0; y < rsBlocks.length; y++) totalCodeCount += rsBlocks[y].totalCount;
4957
- const data = new Array(totalCodeCount);
4958
- let index = 0;
4959
- for (let z = 0; z < maxDcCount; z++) for (let s = 0; s < rsBlocks.length; s++) if (z < dcdata[s].length) data[index++] = dcdata[s][z];
4960
- for (let xx = 0; xx < maxEcCount; xx++) for (let t = 0; t < rsBlocks.length; t++) if (xx < ecdata[t].length) data[index++] = ecdata[t][xx];
4961
- return data;
4962
- };
4963
- //#endregion
4964
- //#region src/internal/qr/encode.ts
4965
- const LOW_ERROR_CORRECTION_LEVEL = QRErrorCorrectLevel.L;
4966
- /** createQrCodeMatrix 的方法封装。 */
4967
- function createQrCodeMatrix(input) {
4968
- const qrcode = new QRCode(-1, LOW_ERROR_CORRECTION_LEVEL);
4969
- qrcode.addData(input);
4970
- qrcode.make();
4971
- return qrcode.modules;
4972
- }
4973
- //#endregion
4974
- //#region src/internal/qr/render.ts
4975
- const WHITE_ALL = "█";
4976
- const WHITE_BLACK = "▀";
4977
- const BLACK_WHITE = "▄";
4978
- const BLACK_ALL = " ";
4979
- function fill(length, value) {
4980
- return Array.from({ length }).fill(value);
4981
- }
4982
- function renderCompactQrCode(matrix) {
4983
- const moduleCount = matrix.length;
4984
- const moduleData = [...matrix];
4985
- const oddRow = moduleCount % 2 === 1;
4986
- if (oddRow) moduleData.push(fill(moduleCount, false));
4987
- const borderTop = Array.from({ length: moduleCount + 2 }).fill(BLACK_WHITE).join("");
4988
- const borderBottom = Array.from({ length: moduleCount + 2 }).fill(WHITE_BLACK).join("");
4989
- let output = `${borderTop}\n`;
4990
- for (let row = 0; row < moduleCount; row += 2) {
4991
- output += WHITE_ALL;
4992
- for (let col = 0; col < moduleCount; col += 1) {
4993
- const top = moduleData[row][col];
4994
- const bottom = moduleData[row + 1][col];
4995
- if (!top && !bottom) output += WHITE_ALL;
4996
- else if (!top && bottom) output += WHITE_BLACK;
4997
- else if (top && !bottom) output += BLACK_WHITE;
4998
- else output += BLACK_ALL;
4999
- }
5000
- output += `${WHITE_ALL}\n`;
5001
- }
5002
- if (!oddRow) output += borderBottom;
5003
- return output;
5004
- }
5005
- function renderFullQrCode(matrix) {
5006
- const black = "\x1B[40m \x1B[0m";
5007
- const white = "\x1B[47m \x1B[0m";
5008
- const border = Array.from({ length: matrix.length + 2 }).fill(white).join("");
5009
- let output = `${border}\n`;
5010
- matrix.forEach((row) => {
5011
- output += white;
5012
- output += row.map((cell) => cell ? black : white).join("");
5013
- output += `${white}\n`;
5014
- });
5015
- output += border;
5016
- return output;
5017
- }
5018
- /** renderTerminalQrCode 的方法封装。 */
5019
- function renderTerminalQrCode(input, options = {}) {
5020
- const matrix = createQrCodeMatrix(input);
5021
- return options.small ? renderCompactQrCode(matrix) : renderFullQrCode(matrix);
5022
- }
5023
- //#endregion
5024
731
  //#region src/util.ts
5025
732
  /**
5026
733
  * @file 二维码与插件路径工具。