uqrcode.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440
  1. // uqrcode.js
  2. //---------------------------------------------------------------------
  3. // github https://github.com/Sansnn/uQRCode
  4. //---------------------------------------------------------------------
  5. let uQRCode = {};
  6. (function() {
  7. //---------------------------------------------------------------------
  8. // QRCode for JavaScript
  9. //
  10. // Copyright (c) 2009 Kazuhiko Arase
  11. //
  12. // URL: http://www.d-project.com/
  13. //
  14. // Licensed under the MIT license:
  15. // http://www.opensource.org/licenses/mit-license.php
  16. //
  17. // The word "QR Code" is registered trademark of
  18. // DENSO WAVE INCORPORATED
  19. // http://www.denso-wave.com/qrcode/faqpatent-e.html
  20. //
  21. //---------------------------------------------------------------------
  22. //---------------------------------------------------------------------
  23. // QR8bitByte
  24. //---------------------------------------------------------------------
  25. function QR8bitByte(data) {
  26. this.mode = QRMode.MODE_8BIT_BYTE;
  27. this.data = data;
  28. }
  29. QR8bitByte.prototype = {
  30. getLength: function(buffer) {
  31. return this.data.length;
  32. },
  33. write: function(buffer) {
  34. for (var i = 0; i < this.data.length; i++) {
  35. // not JIS ...
  36. buffer.put(this.data.charCodeAt(i), 8);
  37. }
  38. }
  39. };
  40. //---------------------------------------------------------------------
  41. // QRCode
  42. //---------------------------------------------------------------------
  43. function QRCode(typeNumber, errorCorrectLevel) {
  44. this.typeNumber = typeNumber;
  45. this.errorCorrectLevel = errorCorrectLevel;
  46. this.modules = null;
  47. this.moduleCount = 0;
  48. this.dataCache = null;
  49. this.dataList = new Array();
  50. }
  51. QRCode.prototype = {
  52. addData: function(data) {
  53. var newData = new QR8bitByte(data);
  54. this.dataList.push(newData);
  55. this.dataCache = null;
  56. },
  57. isDark: function(row, col) {
  58. if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) {
  59. throw new Error(row + "," + col);
  60. }
  61. return this.modules[row][col];
  62. },
  63. getModuleCount: function() {
  64. return this.moduleCount;
  65. },
  66. make: function() {
  67. // Calculate automatically typeNumber if provided is < 1
  68. if (this.typeNumber < 1) {
  69. var typeNumber = 1;
  70. for (typeNumber = 1; typeNumber < 40; typeNumber++) {
  71. var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel);
  72. var buffer = new QRBitBuffer();
  73. var totalDataCount = 0;
  74. for (var i = 0; i < rsBlocks.length; i++) {
  75. totalDataCount += rsBlocks[i].dataCount;
  76. }
  77. for (var i = 0; i < this.dataList.length; i++) {
  78. var data = this.dataList[i];
  79. buffer.put(data.mode, 4);
  80. buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber));
  81. data.write(buffer);
  82. }
  83. if (buffer.getLengthInBits() <= totalDataCount * 8)
  84. break;
  85. }
  86. this.typeNumber = typeNumber;
  87. }
  88. this.makeImpl(false, this.getBestMaskPattern());
  89. },
  90. makeImpl: function(test, maskPattern) {
  91. this.moduleCount = this.typeNumber * 4 + 17;
  92. this.modules = new Array(this.moduleCount);
  93. for (var row = 0; row < this.moduleCount; row++) {
  94. this.modules[row] = new Array(this.moduleCount);
  95. for (var col = 0; col < this.moduleCount; col++) {
  96. this.modules[row][col] = null; //(col + row) % 3;
  97. }
  98. }
  99. this.setupPositionProbePattern(0, 0);
  100. this.setupPositionProbePattern(this.moduleCount - 7, 0);
  101. this.setupPositionProbePattern(0, this.moduleCount - 7);
  102. this.setupPositionAdjustPattern();
  103. this.setupTimingPattern();
  104. this.setupTypeInfo(test, maskPattern);
  105. if (this.typeNumber >= 7) {
  106. this.setupTypeNumber(test);
  107. }
  108. if (this.dataCache == null) {
  109. this.dataCache = QRCode.createData(this.typeNumber, this.errorCorrectLevel, this.dataList);
  110. }
  111. this.mapData(this.dataCache, maskPattern);
  112. },
  113. setupPositionProbePattern: function(row, col) {
  114. for (var r = -1; r <= 7; r++) {
  115. if (row + r <= -1 || this.moduleCount <= row + r) continue;
  116. for (var c = -1; c <= 7; c++) {
  117. if (col + c <= -1 || this.moduleCount <= col + c) continue;
  118. if ((0 <= r && r <= 6 && (c == 0 || c == 6)) ||
  119. (0 <= c && c <= 6 && (r == 0 || r == 6)) ||
  120. (2 <= r && r <= 4 && 2 <= c && c <= 4)) {
  121. this.modules[row + r][col + c] = true;
  122. } else {
  123. this.modules[row + r][col + c] = false;
  124. }
  125. }
  126. }
  127. },
  128. getBestMaskPattern: function() {
  129. var minLostPoint = 0;
  130. var pattern = 0;
  131. for (var i = 0; i < 8; i++) {
  132. this.makeImpl(true, i);
  133. var lostPoint = QRUtil.getLostPoint(this);
  134. if (i == 0 || minLostPoint > lostPoint) {
  135. minLostPoint = lostPoint;
  136. pattern = i;
  137. }
  138. }
  139. return pattern;
  140. },
  141. createMovieClip: function(target_mc, instance_name, depth) {
  142. var qr_mc = target_mc.createEmptyMovieClip(instance_name, depth);
  143. var cs = 1;
  144. this.make();
  145. for (var row = 0; row < this.modules.length; row++) {
  146. var y = row * cs;
  147. for (var col = 0; col < this.modules[row].length; col++) {
  148. var x = col * cs;
  149. var dark = this.modules[row][col];
  150. if (dark) {
  151. qr_mc.beginFill(0, 100);
  152. qr_mc.moveTo(x, y);
  153. qr_mc.lineTo(x + cs, y);
  154. qr_mc.lineTo(x + cs, y + cs);
  155. qr_mc.lineTo(x, y + cs);
  156. qr_mc.endFill();
  157. }
  158. }
  159. }
  160. return qr_mc;
  161. },
  162. setupTimingPattern: function() {
  163. for (var r = 8; r < this.moduleCount - 8; r++) {
  164. if (this.modules[r][6] != null) {
  165. continue;
  166. }
  167. this.modules[r][6] = (r % 2 == 0);
  168. }
  169. for (var c = 8; c < this.moduleCount - 8; c++) {
  170. if (this.modules[6][c] != null) {
  171. continue;
  172. }
  173. this.modules[6][c] = (c % 2 == 0);
  174. }
  175. },
  176. setupPositionAdjustPattern: function() {
  177. var pos = QRUtil.getPatternPosition(this.typeNumber);
  178. for (var i = 0; i < pos.length; i++) {
  179. for (var j = 0; j < pos.length; j++) {
  180. var row = pos[i];
  181. var col = pos[j];
  182. if (this.modules[row][col] != null) {
  183. continue;
  184. }
  185. for (var r = -2; r <= 2; r++) {
  186. for (var c = -2; c <= 2; c++) {
  187. if (r == -2 || r == 2 || c == -2 || c == 2 ||
  188. (r == 0 && c == 0)) {
  189. this.modules[row + r][col + c] = true;
  190. } else {
  191. this.modules[row + r][col + c] = false;
  192. }
  193. }
  194. }
  195. }
  196. }
  197. },
  198. setupTypeNumber: function(test) {
  199. var bits = QRUtil.getBCHTypeNumber(this.typeNumber);
  200. for (var i = 0; i < 18; i++) {
  201. var mod = (!test && ((bits >> i) & 1) == 1);
  202. this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod;
  203. }
  204. for (var i = 0; i < 18; i++) {
  205. var mod = (!test && ((bits >> i) & 1) == 1);
  206. this.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)] = mod;
  207. }
  208. },
  209. setupTypeInfo: function(test, maskPattern) {
  210. var data = (this.errorCorrectLevel << 3) | maskPattern;
  211. var bits = QRUtil.getBCHTypeInfo(data);
  212. // vertical
  213. for (var i = 0; i < 15; i++) {
  214. var mod = (!test && ((bits >> i) & 1) == 1);
  215. if (i < 6) {
  216. this.modules[i][8] = mod;
  217. } else if (i < 8) {
  218. this.modules[i + 1][8] = mod;
  219. } else {
  220. this.modules[this.moduleCount - 15 + i][8] = mod;
  221. }
  222. }
  223. // horizontal
  224. for (var i = 0; i < 15; i++) {
  225. var mod = (!test && ((bits >> i) & 1) == 1);
  226. if (i < 8) {
  227. this.modules[8][this.moduleCount - i - 1] = mod;
  228. } else if (i < 9) {
  229. this.modules[8][15 - i - 1 + 1] = mod;
  230. } else {
  231. this.modules[8][15 - i - 1] = mod;
  232. }
  233. }
  234. // fixed module
  235. this.modules[this.moduleCount - 8][8] = (!test);
  236. },
  237. mapData: function(data, maskPattern) {
  238. var inc = -1;
  239. var row = this.moduleCount - 1;
  240. var bitIndex = 7;
  241. var byteIndex = 0;
  242. for (var col = this.moduleCount - 1; col > 0; col -= 2) {
  243. if (col == 6) col--;
  244. while (true) {
  245. for (var c = 0; c < 2; c++) {
  246. if (this.modules[row][col - c] == null) {
  247. var dark = false;
  248. if (byteIndex < data.length) {
  249. dark = (((data[byteIndex] >>> bitIndex) & 1) == 1);
  250. }
  251. var mask = QRUtil.getMask(maskPattern, row, col - c);
  252. if (mask) {
  253. dark = !dark;
  254. }
  255. this.modules[row][col - c] = dark;
  256. bitIndex--;
  257. if (bitIndex == -1) {
  258. byteIndex++;
  259. bitIndex = 7;
  260. }
  261. }
  262. }
  263. row += inc;
  264. if (row < 0 || this.moduleCount <= row) {
  265. row -= inc;
  266. inc = -inc;
  267. break;
  268. }
  269. }
  270. }
  271. }
  272. };
  273. QRCode.PAD0 = 0xEC;
  274. QRCode.PAD1 = 0x11;
  275. QRCode.createData = function(typeNumber, errorCorrectLevel, dataList) {
  276. var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel);
  277. var buffer = new QRBitBuffer();
  278. for (var i = 0; i < dataList.length; i++) {
  279. var data = dataList[i];
  280. buffer.put(data.mode, 4);
  281. buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber));
  282. data.write(buffer);
  283. }
  284. // calc num max data.
  285. var totalDataCount = 0;
  286. for (var i = 0; i < rsBlocks.length; i++) {
  287. totalDataCount += rsBlocks[i].dataCount;
  288. }
  289. if (buffer.getLengthInBits() > totalDataCount * 8) {
  290. throw new Error("code length overflow. (" +
  291. buffer.getLengthInBits() +
  292. ">" +
  293. totalDataCount * 8 +
  294. ")");
  295. }
  296. // end code
  297. if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {
  298. buffer.put(0, 4);
  299. }
  300. // padding
  301. while (buffer.getLengthInBits() % 8 != 0) {
  302. buffer.putBit(false);
  303. }
  304. // padding
  305. while (true) {
  306. if (buffer.getLengthInBits() >= totalDataCount * 8) {
  307. break;
  308. }
  309. buffer.put(QRCode.PAD0, 8);
  310. if (buffer.getLengthInBits() >= totalDataCount * 8) {
  311. break;
  312. }
  313. buffer.put(QRCode.PAD1, 8);
  314. }
  315. return QRCode.createBytes(buffer, rsBlocks);
  316. }
  317. QRCode.createBytes = function(buffer, rsBlocks) {
  318. var offset = 0;
  319. var maxDcCount = 0;
  320. var maxEcCount = 0;
  321. var dcdata = new Array(rsBlocks.length);
  322. var ecdata = new Array(rsBlocks.length);
  323. for (var r = 0; r < rsBlocks.length; r++) {
  324. var dcCount = rsBlocks[r].dataCount;
  325. var ecCount = rsBlocks[r].totalCount - dcCount;
  326. maxDcCount = Math.max(maxDcCount, dcCount);
  327. maxEcCount = Math.max(maxEcCount, ecCount);
  328. dcdata[r] = new Array(dcCount);
  329. for (var i = 0; i < dcdata[r].length; i++) {
  330. dcdata[r][i] = 0xff & buffer.buffer[i + offset];
  331. }
  332. offset += dcCount;
  333. var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
  334. var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1);
  335. var modPoly = rawPoly.mod(rsPoly);
  336. ecdata[r] = new Array(rsPoly.getLength() - 1);
  337. for (var i = 0; i < ecdata[r].length; i++) {
  338. var modIndex = i + modPoly.getLength() - ecdata[r].length;
  339. ecdata[r][i] = (modIndex >= 0) ? modPoly.get(modIndex) : 0;
  340. }
  341. }
  342. var totalCodeCount = 0;
  343. for (var i = 0; i < rsBlocks.length; i++) {
  344. totalCodeCount += rsBlocks[i].totalCount;
  345. }
  346. var data = new Array(totalCodeCount);
  347. var index = 0;
  348. for (var i = 0; i < maxDcCount; i++) {
  349. for (var r = 0; r < rsBlocks.length; r++) {
  350. if (i < dcdata[r].length) {
  351. data[index++] = dcdata[r][i];
  352. }
  353. }
  354. }
  355. for (var i = 0; i < maxEcCount; i++) {
  356. for (var r = 0; r < rsBlocks.length; r++) {
  357. if (i < ecdata[r].length) {
  358. data[index++] = ecdata[r][i];
  359. }
  360. }
  361. }
  362. return data;
  363. }
  364. //---------------------------------------------------------------------
  365. // QRMode
  366. //---------------------------------------------------------------------
  367. var QRMode = {
  368. MODE_NUMBER: 1 << 0,
  369. MODE_ALPHA_NUM: 1 << 1,
  370. MODE_8BIT_BYTE: 1 << 2,
  371. MODE_KANJI: 1 << 3
  372. };
  373. //---------------------------------------------------------------------
  374. // QRErrorCorrectLevel
  375. //---------------------------------------------------------------------
  376. var QRErrorCorrectLevel = {
  377. L: 1,
  378. M: 0,
  379. Q: 3,
  380. H: 2
  381. };
  382. //---------------------------------------------------------------------
  383. // QRMaskPattern
  384. //---------------------------------------------------------------------
  385. var QRMaskPattern = {
  386. PATTERN000: 0,
  387. PATTERN001: 1,
  388. PATTERN010: 2,
  389. PATTERN011: 3,
  390. PATTERN100: 4,
  391. PATTERN101: 5,
  392. PATTERN110: 6,
  393. PATTERN111: 7
  394. };
  395. //---------------------------------------------------------------------
  396. // QRUtil
  397. //---------------------------------------------------------------------
  398. var QRUtil = {
  399. PATTERN_POSITION_TABLE: [
  400. [],
  401. [6, 18],
  402. [6, 22],
  403. [6, 26],
  404. [6, 30],
  405. [6, 34],
  406. [6, 22, 38],
  407. [6, 24, 42],
  408. [6, 26, 46],
  409. [6, 28, 50],
  410. [6, 30, 54],
  411. [6, 32, 58],
  412. [6, 34, 62],
  413. [6, 26, 46, 66],
  414. [6, 26, 48, 70],
  415. [6, 26, 50, 74],
  416. [6, 30, 54, 78],
  417. [6, 30, 56, 82],
  418. [6, 30, 58, 86],
  419. [6, 34, 62, 90],
  420. [6, 28, 50, 72, 94],
  421. [6, 26, 50, 74, 98],
  422. [6, 30, 54, 78, 102],
  423. [6, 28, 54, 80, 106],
  424. [6, 32, 58, 84, 110],
  425. [6, 30, 58, 86, 114],
  426. [6, 34, 62, 90, 118],
  427. [6, 26, 50, 74, 98, 122],
  428. [6, 30, 54, 78, 102, 126],
  429. [6, 26, 52, 78, 104, 130],
  430. [6, 30, 56, 82, 108, 134],
  431. [6, 34, 60, 86, 112, 138],
  432. [6, 30, 58, 86, 114, 142],
  433. [6, 34, 62, 90, 118, 146],
  434. [6, 30, 54, 78, 102, 126, 150],
  435. [6, 24, 50, 76, 102, 128, 154],
  436. [6, 28, 54, 80, 106, 132, 158],
  437. [6, 32, 58, 84, 110, 136, 162],
  438. [6, 26, 54, 82, 110, 138, 166],
  439. [6, 30, 58, 86, 114, 142, 170]
  440. ],
  441. G15: (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0),
  442. G18: (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0),
  443. G15_MASK: (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1),
  444. getBCHTypeInfo: function(data) {
  445. var d = data << 10;
  446. while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) {
  447. d ^= (QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15)));
  448. }
  449. return ((data << 10) | d) ^ QRUtil.G15_MASK;
  450. },
  451. getBCHTypeNumber: function(data) {
  452. var d = data << 12;
  453. while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) {
  454. d ^= (QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18)));
  455. }
  456. return (data << 12) | d;
  457. },
  458. getBCHDigit: function(data) {
  459. var digit = 0;
  460. while (data != 0) {
  461. digit++;
  462. data >>>= 1;
  463. }
  464. return digit;
  465. },
  466. getPatternPosition: function(typeNumber) {
  467. return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1];
  468. },
  469. getMask: function(maskPattern, i, j) {
  470. switch (maskPattern) {
  471. case QRMaskPattern.PATTERN000:
  472. return (i + j) % 2 == 0;
  473. case QRMaskPattern.PATTERN001:
  474. return i % 2 == 0;
  475. case QRMaskPattern.PATTERN010:
  476. return j % 3 == 0;
  477. case QRMaskPattern.PATTERN011:
  478. return (i + j) % 3 == 0;
  479. case QRMaskPattern.PATTERN100:
  480. return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0;
  481. case QRMaskPattern.PATTERN101:
  482. return (i * j) % 2 + (i * j) % 3 == 0;
  483. case QRMaskPattern.PATTERN110:
  484. return ((i * j) % 2 + (i * j) % 3) % 2 == 0;
  485. case QRMaskPattern.PATTERN111:
  486. return ((i * j) % 3 + (i + j) % 2) % 2 == 0;
  487. default:
  488. throw new Error("bad maskPattern:" + maskPattern);
  489. }
  490. },
  491. getErrorCorrectPolynomial: function(errorCorrectLength) {
  492. var a = new QRPolynomial([1], 0);
  493. for (var i = 0; i < errorCorrectLength; i++) {
  494. a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0));
  495. }
  496. return a;
  497. },
  498. getLengthInBits: function(mode, type) {
  499. if (1 <= type && type < 10) {
  500. // 1 - 9
  501. switch (mode) {
  502. case QRMode.MODE_NUMBER:
  503. return 10;
  504. case QRMode.MODE_ALPHA_NUM:
  505. return 9;
  506. case QRMode.MODE_8BIT_BYTE:
  507. return 8;
  508. case QRMode.MODE_KANJI:
  509. return 8;
  510. default:
  511. throw new Error("mode:" + mode);
  512. }
  513. } else if (type < 27) {
  514. // 10 - 26
  515. switch (mode) {
  516. case QRMode.MODE_NUMBER:
  517. return 12;
  518. case QRMode.MODE_ALPHA_NUM:
  519. return 11;
  520. case QRMode.MODE_8BIT_BYTE:
  521. return 16;
  522. case QRMode.MODE_KANJI:
  523. return 10;
  524. default:
  525. throw new Error("mode:" + mode);
  526. }
  527. } else if (type < 41) {
  528. // 27 - 40
  529. switch (mode) {
  530. case QRMode.MODE_NUMBER:
  531. return 14;
  532. case QRMode.MODE_ALPHA_NUM:
  533. return 13;
  534. case QRMode.MODE_8BIT_BYTE:
  535. return 16;
  536. case QRMode.MODE_KANJI:
  537. return 12;
  538. default:
  539. throw new Error("mode:" + mode);
  540. }
  541. } else {
  542. throw new Error("type:" + type);
  543. }
  544. },
  545. getLostPoint: function(qrCode) {
  546. var moduleCount = qrCode.getModuleCount();
  547. var lostPoint = 0;
  548. // LEVEL1
  549. for (var row = 0; row < moduleCount; row++) {
  550. for (var col = 0; col < moduleCount; col++) {
  551. var sameCount = 0;
  552. var dark = qrCode.isDark(row, col);
  553. for (var r = -1; r <= 1; r++) {
  554. if (row + r < 0 || moduleCount <= row + r) {
  555. continue;
  556. }
  557. for (var c = -1; c <= 1; c++) {
  558. if (col + c < 0 || moduleCount <= col + c) {
  559. continue;
  560. }
  561. if (r == 0 && c == 0) {
  562. continue;
  563. }
  564. if (dark == qrCode.isDark(row + r, col + c)) {
  565. sameCount++;
  566. }
  567. }
  568. }
  569. if (sameCount > 5) {
  570. lostPoint += (3 + sameCount - 5);
  571. }
  572. }
  573. }
  574. // LEVEL2
  575. for (var row = 0; row < moduleCount - 1; row++) {
  576. for (var col = 0; col < moduleCount - 1; col++) {
  577. var count = 0;
  578. if (qrCode.isDark(row, col)) count++;
  579. if (qrCode.isDark(row + 1, col)) count++;
  580. if (qrCode.isDark(row, col + 1)) count++;
  581. if (qrCode.isDark(row + 1, col + 1)) count++;
  582. if (count == 0 || count == 4) {
  583. lostPoint += 3;
  584. }
  585. }
  586. }
  587. // LEVEL3
  588. for (var row = 0; row < moduleCount; row++) {
  589. for (var col = 0; col < moduleCount - 6; col++) {
  590. if (qrCode.isDark(row, col) &&
  591. !qrCode.isDark(row, col + 1) &&
  592. qrCode.isDark(row, col + 2) &&
  593. qrCode.isDark(row, col + 3) &&
  594. qrCode.isDark(row, col + 4) &&
  595. !qrCode.isDark(row, col + 5) &&
  596. qrCode.isDark(row, col + 6)) {
  597. lostPoint += 40;
  598. }
  599. }
  600. }
  601. for (var col = 0; col < moduleCount; col++) {
  602. for (var row = 0; row < moduleCount - 6; row++) {
  603. if (qrCode.isDark(row, col) &&
  604. !qrCode.isDark(row + 1, col) &&
  605. qrCode.isDark(row + 2, col) &&
  606. qrCode.isDark(row + 3, col) &&
  607. qrCode.isDark(row + 4, col) &&
  608. !qrCode.isDark(row + 5, col) &&
  609. qrCode.isDark(row + 6, col)) {
  610. lostPoint += 40;
  611. }
  612. }
  613. }
  614. // LEVEL4
  615. var darkCount = 0;
  616. for (var col = 0; col < moduleCount; col++) {
  617. for (var row = 0; row < moduleCount; row++) {
  618. if (qrCode.isDark(row, col)) {
  619. darkCount++;
  620. }
  621. }
  622. }
  623. var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
  624. lostPoint += ratio * 10;
  625. return lostPoint;
  626. }
  627. };
  628. //---------------------------------------------------------------------
  629. // QRMath
  630. //---------------------------------------------------------------------
  631. var QRMath = {
  632. glog: function(n) {
  633. if (n < 1) {
  634. throw new Error("glog(" + n + ")");
  635. }
  636. return QRMath.LOG_TABLE[n];
  637. },
  638. gexp: function(n) {
  639. while (n < 0) {
  640. n += 255;
  641. }
  642. while (n >= 256) {
  643. n -= 255;
  644. }
  645. return QRMath.EXP_TABLE[n];
  646. },
  647. EXP_TABLE: new Array(256),
  648. LOG_TABLE: new Array(256)
  649. };
  650. for (var i = 0; i < 8; i++) {
  651. QRMath.EXP_TABLE[i] = 1 << i;
  652. }
  653. for (var i = 8; i < 256; i++) {
  654. QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4] ^
  655. QRMath.EXP_TABLE[i - 5] ^
  656. QRMath.EXP_TABLE[i - 6] ^
  657. QRMath.EXP_TABLE[i - 8];
  658. }
  659. for (var i = 0; i < 255; i++) {
  660. QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i;
  661. }
  662. //---------------------------------------------------------------------
  663. // QRPolynomial
  664. //---------------------------------------------------------------------
  665. function QRPolynomial(num, shift) {
  666. if (num.length == undefined) {
  667. throw new Error(num.length + "/" + shift);
  668. }
  669. var offset = 0;
  670. while (offset < num.length && num[offset] == 0) {
  671. offset++;
  672. }
  673. this.num = new Array(num.length - offset + shift);
  674. for (var i = 0; i < num.length - offset; i++) {
  675. this.num[i] = num[i + offset];
  676. }
  677. }
  678. QRPolynomial.prototype = {
  679. get: function(index) {
  680. return this.num[index];
  681. },
  682. getLength: function() {
  683. return this.num.length;
  684. },
  685. multiply: function(e) {
  686. var num = new Array(this.getLength() + e.getLength() - 1);
  687. for (var i = 0; i < this.getLength(); i++) {
  688. for (var j = 0; j < e.getLength(); j++) {
  689. num[i + j] ^= QRMath.gexp(QRMath.glog(this.get(i)) + QRMath.glog(e.get(j)));
  690. }
  691. }
  692. return new QRPolynomial(num, 0);
  693. },
  694. mod: function(e) {
  695. if (this.getLength() - e.getLength() < 0) {
  696. return this;
  697. }
  698. var ratio = QRMath.glog(this.get(0)) - QRMath.glog(e.get(0));
  699. var num = new Array(this.getLength());
  700. for (var i = 0; i < this.getLength(); i++) {
  701. num[i] = this.get(i);
  702. }
  703. for (var i = 0; i < e.getLength(); i++) {
  704. num[i] ^= QRMath.gexp(QRMath.glog(e.get(i)) + ratio);
  705. }
  706. // recursive call
  707. return new QRPolynomial(num, 0).mod(e);
  708. }
  709. };
  710. //---------------------------------------------------------------------
  711. // QRRSBlock
  712. //---------------------------------------------------------------------
  713. function QRRSBlock(totalCount, dataCount) {
  714. this.totalCount = totalCount;
  715. this.dataCount = dataCount;
  716. }
  717. QRRSBlock.RS_BLOCK_TABLE = [
  718. // L
  719. // M
  720. // Q
  721. // H
  722. // 1
  723. [1, 26, 19],
  724. [1, 26, 16],
  725. [1, 26, 13],
  726. [1, 26, 9],
  727. // 2
  728. [1, 44, 34],
  729. [1, 44, 28],
  730. [1, 44, 22],
  731. [1, 44, 16],
  732. // 3
  733. [1, 70, 55],
  734. [1, 70, 44],
  735. [2, 35, 17],
  736. [2, 35, 13],
  737. // 4
  738. [1, 100, 80],
  739. [2, 50, 32],
  740. [2, 50, 24],
  741. [4, 25, 9],
  742. // 5
  743. [1, 134, 108],
  744. [2, 67, 43],
  745. [2, 33, 15, 2, 34, 16],
  746. [2, 33, 11, 2, 34, 12],
  747. // 6
  748. [2, 86, 68],
  749. [4, 43, 27],
  750. [4, 43, 19],
  751. [4, 43, 15],
  752. // 7
  753. [2, 98, 78],
  754. [4, 49, 31],
  755. [2, 32, 14, 4, 33, 15],
  756. [4, 39, 13, 1, 40, 14],
  757. // 8
  758. [2, 121, 97],
  759. [2, 60, 38, 2, 61, 39],
  760. [4, 40, 18, 2, 41, 19],
  761. [4, 40, 14, 2, 41, 15],
  762. // 9
  763. [2, 146, 116],
  764. [3, 58, 36, 2, 59, 37],
  765. [4, 36, 16, 4, 37, 17],
  766. [4, 36, 12, 4, 37, 13],
  767. // 10
  768. [2, 86, 68, 2, 87, 69],
  769. [4, 69, 43, 1, 70, 44],
  770. [6, 43, 19, 2, 44, 20],
  771. [6, 43, 15, 2, 44, 16],
  772. // 11
  773. [4, 101, 81],
  774. [1, 80, 50, 4, 81, 51],
  775. [4, 50, 22, 4, 51, 23],
  776. [3, 36, 12, 8, 37, 13],
  777. // 12
  778. [2, 116, 92, 2, 117, 93],
  779. [6, 58, 36, 2, 59, 37],
  780. [4, 46, 20, 6, 47, 21],
  781. [7, 42, 14, 4, 43, 15],
  782. // 13
  783. [4, 133, 107],
  784. [8, 59, 37, 1, 60, 38],
  785. [8, 44, 20, 4, 45, 21],
  786. [12, 33, 11, 4, 34, 12],
  787. // 14
  788. [3, 145, 115, 1, 146, 116],
  789. [4, 64, 40, 5, 65, 41],
  790. [11, 36, 16, 5, 37, 17],
  791. [11, 36, 12, 5, 37, 13],
  792. // 15
  793. [5, 109, 87, 1, 110, 88],
  794. [5, 65, 41, 5, 66, 42],
  795. [5, 54, 24, 7, 55, 25],
  796. [11, 36, 12],
  797. // 16
  798. [5, 122, 98, 1, 123, 99],
  799. [7, 73, 45, 3, 74, 46],
  800. [15, 43, 19, 2, 44, 20],
  801. [3, 45, 15, 13, 46, 16],
  802. // 17
  803. [1, 135, 107, 5, 136, 108],
  804. [10, 74, 46, 1, 75, 47],
  805. [1, 50, 22, 15, 51, 23],
  806. [2, 42, 14, 17, 43, 15],
  807. // 18
  808. [5, 150, 120, 1, 151, 121],
  809. [9, 69, 43, 4, 70, 44],
  810. [17, 50, 22, 1, 51, 23],
  811. [2, 42, 14, 19, 43, 15],
  812. // 19
  813. [3, 141, 113, 4, 142, 114],
  814. [3, 70, 44, 11, 71, 45],
  815. [17, 47, 21, 4, 48, 22],
  816. [9, 39, 13, 16, 40, 14],
  817. // 20
  818. [3, 135, 107, 5, 136, 108],
  819. [3, 67, 41, 13, 68, 42],
  820. [15, 54, 24, 5, 55, 25],
  821. [15, 43, 15, 10, 44, 16],
  822. // 21
  823. [4, 144, 116, 4, 145, 117],
  824. [17, 68, 42],
  825. [17, 50, 22, 6, 51, 23],
  826. [19, 46, 16, 6, 47, 17],
  827. // 22
  828. [2, 139, 111, 7, 140, 112],
  829. [17, 74, 46],
  830. [7, 54, 24, 16, 55, 25],
  831. [34, 37, 13],
  832. // 23
  833. [4, 151, 121, 5, 152, 122],
  834. [4, 75, 47, 14, 76, 48],
  835. [11, 54, 24, 14, 55, 25],
  836. [16, 45, 15, 14, 46, 16],
  837. // 24
  838. [6, 147, 117, 4, 148, 118],
  839. [6, 73, 45, 14, 74, 46],
  840. [11, 54, 24, 16, 55, 25],
  841. [30, 46, 16, 2, 47, 17],
  842. // 25
  843. [8, 132, 106, 4, 133, 107],
  844. [8, 75, 47, 13, 76, 48],
  845. [7, 54, 24, 22, 55, 25],
  846. [22, 45, 15, 13, 46, 16],
  847. // 26
  848. [10, 142, 114, 2, 143, 115],
  849. [19, 74, 46, 4, 75, 47],
  850. [28, 50, 22, 6, 51, 23],
  851. [33, 46, 16, 4, 47, 17],
  852. // 27
  853. [8, 152, 122, 4, 153, 123],
  854. [22, 73, 45, 3, 74, 46],
  855. [8, 53, 23, 26, 54, 24],
  856. [12, 45, 15, 28, 46, 16],
  857. // 28
  858. [3, 147, 117, 10, 148, 118],
  859. [3, 73, 45, 23, 74, 46],
  860. [4, 54, 24, 31, 55, 25],
  861. [11, 45, 15, 31, 46, 16],
  862. // 29
  863. [7, 146, 116, 7, 147, 117],
  864. [21, 73, 45, 7, 74, 46],
  865. [1, 53, 23, 37, 54, 24],
  866. [19, 45, 15, 26, 46, 16],
  867. // 30
  868. [5, 145, 115, 10, 146, 116],
  869. [19, 75, 47, 10, 76, 48],
  870. [15, 54, 24, 25, 55, 25],
  871. [23, 45, 15, 25, 46, 16],
  872. // 31
  873. [13, 145, 115, 3, 146, 116],
  874. [2, 74, 46, 29, 75, 47],
  875. [42, 54, 24, 1, 55, 25],
  876. [23, 45, 15, 28, 46, 16],
  877. // 32
  878. [17, 145, 115],
  879. [10, 74, 46, 23, 75, 47],
  880. [10, 54, 24, 35, 55, 25],
  881. [19, 45, 15, 35, 46, 16],
  882. // 33
  883. [17, 145, 115, 1, 146, 116],
  884. [14, 74, 46, 21, 75, 47],
  885. [29, 54, 24, 19, 55, 25],
  886. [11, 45, 15, 46, 46, 16],
  887. // 34
  888. [13, 145, 115, 6, 146, 116],
  889. [14, 74, 46, 23, 75, 47],
  890. [44, 54, 24, 7, 55, 25],
  891. [59, 46, 16, 1, 47, 17],
  892. // 35
  893. [12, 151, 121, 7, 152, 122],
  894. [12, 75, 47, 26, 76, 48],
  895. [39, 54, 24, 14, 55, 25],
  896. [22, 45, 15, 41, 46, 16],
  897. // 36
  898. [6, 151, 121, 14, 152, 122],
  899. [6, 75, 47, 34, 76, 48],
  900. [46, 54, 24, 10, 55, 25],
  901. [2, 45, 15, 64, 46, 16],
  902. // 37
  903. [17, 152, 122, 4, 153, 123],
  904. [29, 74, 46, 14, 75, 47],
  905. [49, 54, 24, 10, 55, 25],
  906. [24, 45, 15, 46, 46, 16],
  907. // 38
  908. [4, 152, 122, 18, 153, 123],
  909. [13, 74, 46, 32, 75, 47],
  910. [48, 54, 24, 14, 55, 25],
  911. [42, 45, 15, 32, 46, 16],
  912. // 39
  913. [20, 147, 117, 4, 148, 118],
  914. [40, 75, 47, 7, 76, 48],
  915. [43, 54, 24, 22, 55, 25],
  916. [10, 45, 15, 67, 46, 16],
  917. // 40
  918. [19, 148, 118, 6, 149, 119],
  919. [18, 75, 47, 31, 76, 48],
  920. [34, 54, 24, 34, 55, 25],
  921. [20, 45, 15, 61, 46, 16]
  922. ];
  923. QRRSBlock.getRSBlocks = function(typeNumber, errorCorrectLevel) {
  924. var rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel);
  925. if (rsBlock == undefined) {
  926. throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel);
  927. }
  928. var length = rsBlock.length / 3;
  929. var list = new Array();
  930. for (var i = 0; i < length; i++) {
  931. var count = rsBlock[i * 3 + 0];
  932. var totalCount = rsBlock[i * 3 + 1];
  933. var dataCount = rsBlock[i * 3 + 2];
  934. for (var j = 0; j < count; j++) {
  935. list.push(new QRRSBlock(totalCount, dataCount));
  936. }
  937. }
  938. return list;
  939. }
  940. QRRSBlock.getRsBlockTable = function(typeNumber, errorCorrectLevel) {
  941. switch (errorCorrectLevel) {
  942. case QRErrorCorrectLevel.L:
  943. return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
  944. case QRErrorCorrectLevel.M:
  945. return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
  946. case QRErrorCorrectLevel.Q:
  947. return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
  948. case QRErrorCorrectLevel.H:
  949. return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
  950. default:
  951. return undefined;
  952. }
  953. }
  954. //---------------------------------------------------------------------
  955. // QRBitBuffer
  956. //---------------------------------------------------------------------
  957. function QRBitBuffer() {
  958. this.buffer = new Array();
  959. this.length = 0;
  960. }
  961. QRBitBuffer.prototype = {
  962. get: function(index) {
  963. var bufIndex = Math.floor(index / 8);
  964. return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) == 1;
  965. },
  966. put: function(num, length) {
  967. for (var i = 0; i < length; i++) {
  968. this.putBit(((num >>> (length - i - 1)) & 1) == 1);
  969. }
  970. },
  971. getLengthInBits: function() {
  972. return this.length;
  973. },
  974. putBit: function(bit) {
  975. var bufIndex = Math.floor(this.length / 8);
  976. if (this.buffer.length <= bufIndex) {
  977. this.buffer.push(0);
  978. }
  979. if (bit) {
  980. this.buffer[bufIndex] |= (0x80 >>> (this.length % 8));
  981. }
  982. this.length++;
  983. }
  984. };
  985. //---------------------------------------------------------------------
  986. // Support Chinese
  987. //---------------------------------------------------------------------
  988. function utf16To8(text) {
  989. var result = '';
  990. var c;
  991. for (var i = 0; i < text.length; i++) {
  992. c = text.charCodeAt(i);
  993. if (c >= 0x0001 && c <= 0x007F) {
  994. result += text.charAt(i);
  995. } else if (c > 0x07FF) {
  996. result += String.fromCharCode(0xE0 | c >> 12 & 0x0F);
  997. result += String.fromCharCode(0x80 | c >> 6 & 0x3F);
  998. result += String.fromCharCode(0x80 | c >> 0 & 0x3F);
  999. } else {
  1000. result += String.fromCharCode(0xC0 | c >> 6 & 0x1F);
  1001. result += String.fromCharCode(0x80 | c >> 0 & 0x3F);
  1002. }
  1003. }
  1004. return result;
  1005. }
  1006. uQRCode = {
  1007. errorCorrectLevel: QRErrorCorrectLevel,
  1008. defaults: {
  1009. size: 354,
  1010. margin: 0,
  1011. backgroundColor: '#ffffff',
  1012. foregroundColor: '#000000',
  1013. fileType: 'png', // 'jpg', 'png'
  1014. errorCorrectLevel: QRErrorCorrectLevel.H,
  1015. typeNumber: -1
  1016. },
  1017. make: function(options) {
  1018. return new Promise((reslove, reject) => {
  1019. var defaultOptions = {
  1020. canvasId: options.canvasId,
  1021. componentInstance: options.componentInstance,
  1022. text: options.text,
  1023. size: this.defaults.size,
  1024. margin: this.defaults.margin,
  1025. backgroundColor: this.defaults.backgroundColor,
  1026. foregroundColor: this.defaults.foregroundColor,
  1027. fileType: this.defaults.fileType,
  1028. errorCorrectLevel: this.defaults.errorCorrectLevel,
  1029. typeNumber: this.defaults.typeNumber
  1030. };
  1031. if (options) {
  1032. for (var i in options) {
  1033. defaultOptions[i] = options[i];
  1034. }
  1035. }
  1036. options = defaultOptions;
  1037. if (!options.canvasId) {
  1038. console.error('uQRCode: Please set canvasId!');
  1039. return;
  1040. }
  1041. function createCanvas() {
  1042. var qrcode = new QRCode(options.typeNumber, options.errorCorrectLevel);
  1043. qrcode.addData(utf16To8(options.text));
  1044. qrcode.make();
  1045. var ctx = uni.createCanvasContext(options.canvasId, options.componentInstance);
  1046. ctx.setFillStyle(options.backgroundColor);
  1047. ctx.fillRect(0, 0, options.size, options.size);
  1048. var tileW = (options.size - options.margin * 2) / qrcode.getModuleCount();
  1049. var tileH = tileW;
  1050. for (var row = 0; row < qrcode.getModuleCount(); row++) {
  1051. for (var col = 0; col < qrcode.getModuleCount(); col++) {
  1052. var style = qrcode.isDark(row, col) ? options.foregroundColor : options.backgroundColor;
  1053. ctx.setFillStyle(style);
  1054. var x = Math.round(col * tileW) + options.margin;
  1055. var y = Math.round(row * tileH) + options.margin;
  1056. var w = Math.ceil((col + 1) * tileW) - Math.floor(col * tileW);
  1057. var h = Math.ceil((row + 1) * tileW) - Math.floor(row * tileW);
  1058. ctx.fillRect(x, y, w, h);
  1059. }
  1060. }
  1061. setTimeout(function() {
  1062. ctx.draw(false, (function() {
  1063. setTimeout(function() {
  1064. uni.canvasToTempFilePath({
  1065. canvasId: options.canvasId,
  1066. fileType: options.fileType,
  1067. width: options.size,
  1068. height: options.size,
  1069. destWidth: options.size,
  1070. destHeight: options.size,
  1071. success: function(res) {
  1072. let resData; // 将统一为base64格式
  1073. let tempFilePath = res.tempFilePath; // H5为base64,其他为相对路径
  1074. // #ifdef H5
  1075. resData = tempFilePath;
  1076. options.success && options.success(resData);
  1077. reslove(resData);
  1078. // #endif
  1079. // #ifdef APP-PLUS
  1080. const path = plus.io.convertLocalFileSystemURL(tempFilePath) // 绝对路径
  1081. let fileReader = new plus.io.FileReader();
  1082. fileReader.readAsDataURL(path);
  1083. fileReader.onloadend = res => {
  1084. resData = res.target.result;
  1085. options.success && options.success(resData);
  1086. reslove(resData);
  1087. };
  1088. // #endif
  1089. // #ifdef MP-WEIXIN || MP-QQ || MP-TOUTIAO
  1090. uni.getFileSystemManager().readFile({
  1091. filePath: tempFilePath,
  1092. encoding: 'base64',
  1093. success: res => {
  1094. resData = 'data:image/png;base64,' + res.data;
  1095. options.success && options.success(resData);
  1096. reslove(resData);
  1097. }
  1098. })
  1099. // #endif
  1100. // #ifndef H5 || APP-PLUS || MP-WEIXIN || MP-QQ || MP-TOUTIAO
  1101. if (plus) {
  1102. const path = plus.io.convertLocalFileSystemURL(tempFilePath) // 绝对路径
  1103. let fileReader = new plus.io.FileReader();
  1104. fileReader.readAsDataURL(path);
  1105. fileReader.onloadend = res => {
  1106. resData = res.target.result;
  1107. options.success && options.success(resData);
  1108. reslove(resData);
  1109. };
  1110. } else {
  1111. uni.request({
  1112. url: tempFilePath,
  1113. method: 'GET',
  1114. responseType: 'arraybuffer',
  1115. success: res => {
  1116. resData = `data:image/png;base64,${uni.arrayBufferToBase64(res.data)}`; // 把arraybuffer转成base64
  1117. options.success && options.success(resData);
  1118. reslove(resData);
  1119. }
  1120. })
  1121. }
  1122. // #endif
  1123. },
  1124. fail: function(error) {
  1125. options.fail && options.fail(error);
  1126. reject(error);
  1127. },
  1128. complete: function(res) {
  1129. options.complete && options.complete(res);
  1130. }
  1131. }, options.componentInstance);
  1132. }, options.text.length + 100);
  1133. })());
  1134. }, 150);
  1135. }
  1136. createCanvas();
  1137. });
  1138. }
  1139. }
  1140. })()
  1141. export default uQRCode