@progress/kendo-charts 1.19.1 → 1.20.0-dev.202111121622

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 (61) hide show
  1. package/dist/cdn/js/kendo-charts.js +1 -1
  2. package/dist/cdn/main.js +1 -1
  3. package/dist/es/chart/chart.js +15 -6
  4. package/dist/es/chart/constants.js +3 -1
  5. package/dist/es/chart/pan-and-zoom/mousewheel-zoom.js +8 -4
  6. package/dist/es/chart/selection.js +41 -1
  7. package/dist/es/common/mousewheel-delta.js +4 -7
  8. package/dist/es/core/axis.js +47 -0
  9. package/dist/es/core/category-axis.js +62 -20
  10. package/dist/es/core/date-category-axis.js +26 -38
  11. package/dist/es/core/date-value-axis.js +37 -40
  12. package/dist/es/core/logarithmic-axis.js +62 -88
  13. package/dist/es/core/numeric-axis.js +57 -81
  14. package/dist/es/main.js +1 -0
  15. package/dist/es/qrcode/encodings/data-modes/alpha-numeric-data-mode.js +103 -0
  16. package/dist/es/qrcode/encodings/data-modes/byte-data-mode.js +51 -0
  17. package/dist/es/qrcode/encodings/data-modes/data-mode-instances.js +12 -0
  18. package/dist/es/qrcode/encodings/data-modes/numeric-data-mode.js +49 -0
  19. package/dist/es/qrcode/encodings/data-modes/qr-data-mode.js +50 -0
  20. package/dist/es/qrcode/encodings/encoders/iso-encoder.js +29 -0
  21. package/dist/es/qrcode/encodings/encoders/utf8-encoder.js +91 -0
  22. package/dist/es/qrcode/encodings/encoding-result.js +16 -0
  23. package/dist/es/qrcode/encodings/encoding.js +701 -0
  24. package/dist/es/qrcode/encodings/free-cell-visitor.js +57 -0
  25. package/dist/es/qrcode/encodings/version-codewords.js +1289 -0
  26. package/dist/es/qrcode/qrcode.js +403 -0
  27. package/dist/es/qrcode/utils.js +28 -0
  28. package/dist/es/qrcode.js +1 -0
  29. package/dist/es/stock/navigator.js +3 -2
  30. package/dist/es2015/chart/chart.js +15 -6
  31. package/dist/es2015/chart/constants.js +3 -1
  32. package/dist/es2015/chart/pan-and-zoom/mousewheel-zoom.js +6 -4
  33. package/dist/es2015/chart/selection.js +40 -1
  34. package/dist/es2015/common/mousewheel-delta.js +4 -7
  35. package/dist/es2015/core/axis.js +39 -0
  36. package/dist/es2015/core/category-axis.js +56 -18
  37. package/dist/es2015/core/date-category-axis.js +27 -36
  38. package/dist/es2015/core/date-value-axis.js +35 -40
  39. package/dist/es2015/core/logarithmic-axis.js +52 -83
  40. package/dist/es2015/core/numeric-axis.js +47 -78
  41. package/dist/es2015/main.js +1 -0
  42. package/dist/es2015/qrcode/encodings/data-modes/alpha-numeric-data-mode.js +91 -0
  43. package/dist/es2015/qrcode/encodings/data-modes/byte-data-mode.js +41 -0
  44. package/dist/es2015/qrcode/encodings/data-modes/data-mode-instances.js +13 -0
  45. package/dist/es2015/qrcode/encodings/data-modes/numeric-data-mode.js +39 -0
  46. package/dist/es2015/qrcode/encodings/data-modes/qr-data-mode.js +44 -0
  47. package/dist/es2015/qrcode/encodings/encoders/iso-encoder.js +19 -0
  48. package/dist/es2015/qrcode/encodings/encoders/utf8-encoder.js +83 -0
  49. package/dist/es2015/qrcode/encodings/encoding-result.js +10 -0
  50. package/dist/es2015/qrcode/encodings/encoding.js +701 -0
  51. package/dist/es2015/qrcode/encodings/free-cell-visitor.js +49 -0
  52. package/dist/es2015/qrcode/encodings/version-codewords.js +1289 -0
  53. package/dist/es2015/qrcode/qrcode.js +395 -0
  54. package/dist/es2015/qrcode/utils.js +28 -0
  55. package/dist/es2015/qrcode.js +1 -0
  56. package/dist/es2015/stock/navigator.js +3 -2
  57. package/dist/npm/main.d.ts +1 -0
  58. package/dist/npm/main.js +3172 -283
  59. package/dist/npm/qrcode.d.ts +5 -0
  60. package/dist/systemjs/kendo-charts.js +1 -1
  61. package/package.json +1 -1
@@ -0,0 +1,701 @@
1
+ import {
2
+ toBitsString,
3
+ toDecimal
4
+ } from '../utils';
5
+ import { FreeCellVisitor } from './free-cell-visitor';
6
+ import { IsoEncoder } from './encoders/iso-encoder';
7
+ import { Utf8Encoder } from './encoders/utf8-encoder';
8
+ import { VersionsCodewordsInformation } from './version-codewords';
9
+ import { DataModeInstances } from './data-modes/data-mode-instances';
10
+
11
+ let terminator = "0000",
12
+ NUMERIC = "numeric",
13
+ ALPHA_NUMERIC = "alphanumeric",
14
+ BYTE = "byte",
15
+ powersOfTwo = { "1": 0 },
16
+ powersOfTwoResult = { "0": 1 },
17
+ irregularAlignmentPatternsStartDistance = {
18
+ 15: 20, 16: 20, 18: 24, 19: 24, 22: 20,
19
+ 24: 22, 26: 24, 28: 20, 30: 20, 31: 24,
20
+ 32: 28, 33: 24, 36: 18, 37: 22, 39: 20, 40: 24
21
+ },
22
+ finderPattern = [1, 0, 1, 1, 1],
23
+ alignmentPattern = [1, 0, 1],
24
+ errorCorrectionPatterns = { L: "01", M: "00", Q: "11", H: "10" },
25
+ formatMaskPattern = "101010000010010",
26
+ formatGeneratorPolynomial = "10100110111",
27
+ versionGeneratorPolynomial = "1111100100101",
28
+ paddingCodewords = ["11101100", "00010001"],
29
+ finderPatternValue = 93,
30
+ /* eslint-disable arrow-body-style */
31
+ maskPatternConditions = [
32
+ (row, column) => { return (row + column) % 2 === 0; },
33
+ (row) => { return row % 2 === 0; },
34
+ (column) => { return column % 3 === 0; },
35
+ (row, column) => { return (row + column) % 3 === 0; },
36
+ (row, column) => { return (Math.floor(row / 2) + Math.floor(column / 3)) % 2 === 0; },
37
+ (row, column) => { return ((row * column) % 2) + ((row * column) % 3) === 0; },
38
+ (row, column) => { return (((row * column) % 2) + ((row * column) % 3)) % 2 === 0; },
39
+ (row, column) => { return (((row + column) % 2) + ((row * column) % 3)) % 2 === 0; }
40
+ ],
41
+ /* eslint-enable arrow-body-style */
42
+ numberRegex = /^\d+/,
43
+ alphaPattern = "A-Z0-9 $%*+./:-",
44
+ alphaExclusiveSet = "A-Z $%*+./:-",
45
+ alphaRegex = new RegExp("^[" + alphaExclusiveSet + "]+"),
46
+ alphaNumericRegex = new RegExp("^[" + alphaPattern + "]+"),
47
+ byteRegex = new RegExp("^[^" + alphaPattern + "]+"),
48
+ initMinNumericBeforeAlpha = 8,
49
+ initMinNumericBeforeByte = 5,
50
+ initMinAlphaBeforeByte = 8,
51
+ minNumericBeforeAlpha = 17,
52
+ minNumericBeforeByte = 9,
53
+ minAlphaBeforeByte = 16;
54
+
55
+ export const generatorPolynomials = [[1, 0], [1, 25, 0]];
56
+
57
+ export function fillFunctionCell(matrices, bit, x, y) {
58
+ for (let i = 0; i < matrices.length; i++) {
59
+ matrices[i][x][y] = bit;
60
+ }
61
+ }
62
+
63
+ export function fillDataCell(matrices, bit, x, y) {
64
+ for (let i = 0; i < maskPatternConditions.length; i++) {
65
+ matrices[i][x][y] = maskPatternConditions[i](x, y) ? bit ^ 1 : parseInt(bit, 10);
66
+ }
67
+ }
68
+
69
+ export function fillData(matrices, blocks) {
70
+ let cellVisitor = new FreeCellVisitor(matrices[0]),
71
+ block,
72
+ codewordIdx,
73
+ cell;
74
+
75
+ for (let blockIdx = 0; blockIdx < blocks.length; blockIdx++) {
76
+ block = blocks[blockIdx];
77
+ codewordIdx = 0;
78
+
79
+ while (block.length > 0) {
80
+ for (let i = 0; i < block.length; i++) {
81
+ for (let j = 0; j < 8; j++) {
82
+ cell = cellVisitor.getNextCell();
83
+ fillDataCell(matrices, block[i][codewordIdx].charAt(j), cell.row, cell.column);
84
+ }
85
+ }
86
+
87
+ codewordIdx++;
88
+
89
+ while (block[0] && codewordIdx === block[0].length) {
90
+ block.splice(0, 1);
91
+ }
92
+ }
93
+ }
94
+
95
+ while ((cell = cellVisitor.getNextRemainderCell())) {
96
+ fillDataCell(matrices, 0, cell.row, cell.column);
97
+ }
98
+ }
99
+
100
+ export function padDataString(initialDataString, totalDataCodewords) {
101
+ let dataBitsCount = totalDataCodewords * 8,
102
+ terminatorIndex = 0,
103
+ paddingCodewordIndex = 0;
104
+ let dataString = initialDataString;
105
+
106
+ while (dataString.length < dataBitsCount && terminatorIndex < terminator.length) {
107
+ dataString += terminator.charAt(terminatorIndex++);
108
+ }
109
+
110
+ if (dataString.length % 8 !== 0) {
111
+ dataString += new Array(9 - dataString.length % 8).join("0");
112
+ }
113
+
114
+ while (dataString.length < dataBitsCount) {
115
+ dataString += paddingCodewords[paddingCodewordIndex];
116
+ paddingCodewordIndex ^= 1;
117
+ }
118
+
119
+ return dataString;
120
+ }
121
+
122
+ export function generatePowersOfTwo() {
123
+ let result;
124
+ let power;
125
+
126
+ for (power = 1; power < 255; power++) {
127
+ result = powersOfTwoResult[power - 1] * 2;
128
+ if (result > 255) {
129
+ result = result ^ 285;
130
+ }
131
+
132
+ powersOfTwoResult[power] = result;
133
+ powersOfTwo[result] = power;
134
+ }
135
+
136
+ result = (powersOfTwoResult[power - 1] * 2) ^ 285;
137
+ powersOfTwoResult[power] = result;
138
+ powersOfTwoResult[-1] = 0;
139
+ }
140
+
141
+ export function xorPolynomials(x, y) {
142
+ let result = [],
143
+ idx = x.length - 2;
144
+
145
+ for (let i = idx; i >= 0; i--) {
146
+ result[i] = x[i] ^ y[i];
147
+ }
148
+
149
+ return result;
150
+ }
151
+
152
+ export function multiplyPolynomials(x, y) {
153
+ let result = [];
154
+
155
+ for (let i = 0; i < x.length; i++) {
156
+ for (let j = 0; j < y.length; j++) {
157
+ if (result[i + j] === undefined) {
158
+ result[i + j] = (x[i] + (y[j] >= 0 ? y[j] : 0)) % 255;
159
+ } else {
160
+ result[i + j] = powersOfTwo[powersOfTwoResult[result[i + j]] ^ powersOfTwoResult[(x[i] + y[j]) % 255]];
161
+ }
162
+ }
163
+ }
164
+
165
+ return result;
166
+ }
167
+
168
+ export function generateGeneratorPolynomials() {
169
+ let maxErrorCorrectionCodeWordsCount = 68;
170
+
171
+ for (let idx = 2; idx <= maxErrorCorrectionCodeWordsCount; idx++) {
172
+ let firstPolynomial = generatorPolynomials[idx - 1],
173
+ secondPolynomial = [idx, 0];
174
+
175
+ generatorPolynomials[idx] = multiplyPolynomials(firstPolynomial, secondPolynomial);
176
+ }
177
+ }
178
+
179
+ //possibly generate on demand
180
+ generatePowersOfTwo();
181
+ generateGeneratorPolynomials();
182
+
183
+ export function multiplyByConstant(polynomial, power) {
184
+ let result = [],
185
+ idx = polynomial.length - 1;
186
+
187
+ do {
188
+ result[idx] = powersOfTwoResult[(polynomial[idx] + power) % 255];
189
+ idx--;
190
+ }
191
+ while (polynomial[idx] !== undefined);
192
+
193
+ return result;
194
+ }
195
+
196
+ export function generateErrorCodewords(data, errorCodewordsCount) {
197
+ let generator = generatorPolynomials[errorCodewordsCount - 1],
198
+ result = new Array(errorCodewordsCount).concat(data),
199
+ generatorPolynomial = new Array(result.length - generator.length).concat(generator),
200
+ steps = data.length,
201
+ errorCodewords = [],
202
+ divisor,
203
+ idx;
204
+
205
+ for (idx = 0; idx < steps; idx++) {
206
+ divisor = multiplyByConstant(generatorPolynomial, powersOfTwo[result[result.length - 1]]);
207
+ generatorPolynomial.splice(0, 1);
208
+
209
+ result = xorPolynomials(divisor, result);
210
+ }
211
+
212
+ for (idx = result.length - 1; idx >= 0; idx--) {
213
+ errorCodewords[errorCodewordsCount - 1 - idx] = toBitsString(result[idx], 8);
214
+ }
215
+
216
+ return errorCodewords;
217
+ }
218
+
219
+ export function getBlocks(dataStream, versionCodewordsInformation) {
220
+ let codewordStart = 0,
221
+ dataBlocks = [],
222
+ errorBlocks = [],
223
+ dataBlock,
224
+ versionGroups = versionCodewordsInformation.groups,
225
+ blockCodewordsCount,
226
+ groupBlocksCount,
227
+ messagePolynomial,
228
+ codeword;
229
+
230
+ for (let groupIdx = 0; groupIdx < versionGroups.length; groupIdx++) {
231
+ groupBlocksCount = versionGroups[groupIdx][0];
232
+
233
+ for (let blockIdx = 0; blockIdx < groupBlocksCount; blockIdx++) {
234
+ blockCodewordsCount = versionGroups[groupIdx][1];
235
+ dataBlock = [];
236
+ messagePolynomial = [];
237
+
238
+ for (let codewordIdx = 1; codewordIdx <= blockCodewordsCount; codewordIdx++) {
239
+ codeword = dataStream.substring(codewordStart, codewordStart + 8);
240
+ dataBlock.push(codeword);
241
+ messagePolynomial[blockCodewordsCount - codewordIdx] = toDecimal(codeword);
242
+ codewordStart += 8;
243
+ }
244
+
245
+ dataBlocks.push(dataBlock);
246
+ errorBlocks.push(generateErrorCodewords(messagePolynomial,
247
+ versionCodewordsInformation.errorCodewordsPerBlock));
248
+ }
249
+ }
250
+ return [dataBlocks, errorBlocks];
251
+ }
252
+
253
+ export function chooseMode(str, minNumericBeforeAlpha, minNumericBeforeByte, minAlphaBeforeByte, previousMode) {
254
+ let numeric = numberRegex.exec(str),
255
+ numericMatch = numeric ? numeric[0] : "",
256
+ alpha = alphaRegex.exec(str),
257
+ alphaMatch = alpha ? alpha[0] : "",
258
+ alphaNumeric = alphaNumericRegex.exec(str),
259
+ alphaNumericMatch = alphaNumeric ? alphaNumeric[0] : "",
260
+ mode,
261
+ modeString;
262
+
263
+ if (numericMatch &&
264
+ (numericMatch.length >= minNumericBeforeAlpha || str.length === numericMatch.length ||
265
+ (numericMatch.length >= minNumericBeforeByte && !alphaNumericRegex.test(str.charAt(numericMatch.length))))) {
266
+ mode = NUMERIC;
267
+ modeString = numericMatch;
268
+ } else if (alphaNumericMatch && (str.length === alphaNumericMatch.length ||
269
+ alphaNumericMatch.length >= minAlphaBeforeByte || previousMode === ALPHA_NUMERIC)) {
270
+ mode = ALPHA_NUMERIC;
271
+ modeString = numericMatch || alphaMatch;
272
+ } else {
273
+ mode = BYTE;
274
+
275
+ if (alphaNumericMatch) {
276
+ modeString = alphaNumericMatch + byteRegex.exec(str.substring(alphaNumericMatch.length))[0];
277
+ } else {
278
+ modeString = byteRegex.exec(str)[0];
279
+ }
280
+ }
281
+
282
+ return {
283
+ mode: mode,
284
+ modeString: modeString
285
+ };
286
+ }
287
+
288
+ export function getModes(inputString) {
289
+ let modes = [],
290
+ previousMode,
291
+ idx = 0;
292
+ let str = inputString;
293
+
294
+ modes.push(chooseMode(str, initMinNumericBeforeAlpha, initMinNumericBeforeByte, initMinAlphaBeforeByte, previousMode));
295
+ previousMode = modes[0].mode;
296
+ str = str.substr(modes[0].modeString.length);
297
+
298
+ while (str.length > 0) {
299
+ let nextMode = chooseMode(str, minNumericBeforeAlpha, minNumericBeforeByte, minAlphaBeforeByte, previousMode);
300
+
301
+ if (nextMode.mode !== previousMode) {
302
+ previousMode = nextMode.mode;
303
+ modes.push(nextMode);
304
+ idx++;
305
+ } else {
306
+ modes[idx].modeString += nextMode.modeString;
307
+ }
308
+
309
+ str = str.substr(nextMode.modeString.length);
310
+ }
311
+
312
+ return modes;
313
+ }
314
+
315
+ export function getDataCodewordsCount(modes) {
316
+ let length = 0,
317
+ mode;
318
+
319
+ for (let i = 0; i < modes.length; i++) {
320
+ mode = DataModeInstances[modes[i].mode];
321
+ length += mode.getStringBitsLength(modes[i].modeString.length);
322
+ }
323
+
324
+ return Math.ceil(length / 8);
325
+ }
326
+
327
+ export function getVersion(dataCodewordsCount, errorCorrectionLevel) {
328
+ let x = 0,
329
+ y = VersionsCodewordsInformation.length - 1,
330
+ version = Math.floor(VersionsCodewordsInformation.length / 2);
331
+
332
+ do {
333
+ if (dataCodewordsCount < VersionsCodewordsInformation[version][errorCorrectionLevel].totalDataCodewords) {
334
+ y = version;
335
+ } else {
336
+ x = version;
337
+ }
338
+
339
+ version = x + Math.floor((y - x) / 2);
340
+ } while (y - x > 1);
341
+
342
+ if (dataCodewordsCount <= VersionsCodewordsInformation[x][errorCorrectionLevel].totalDataCodewords) {
343
+ return version + 1;
344
+ }
345
+
346
+ return y + 1;
347
+ }
348
+
349
+ export function getDataString(modes, version) {
350
+ let dataString = "",
351
+ mode;
352
+
353
+ for (let i = 0; i < modes.length; i++) {
354
+ mode = DataModeInstances[modes[i].mode];
355
+ dataString += mode.encode(modes[i].modeString, version);
356
+ }
357
+
358
+ return dataString;
359
+ }
360
+
361
+ //fix case all zeros
362
+ export function encodeFormatInformation(format) {
363
+ let formatNumber = toDecimal(format),
364
+ encodedString,
365
+ result = "";
366
+
367
+ if (formatNumber === 0) {
368
+ return "101010000010010";
369
+ }
370
+
371
+ encodedString = encodeBCH(toDecimal(format), formatGeneratorPolynomial, 15);
372
+
373
+ for (let i = 0; i < encodedString.length; i++) {
374
+ result += encodedString.charAt(i) ^ formatMaskPattern.charAt(i);
375
+ }
376
+
377
+ return result;
378
+ }
379
+
380
+ export function encodeBCH(value, generatorPolynomial, codeLength) {
381
+ let generatorNumber = toDecimal(generatorPolynomial),
382
+ polynomialLength = generatorPolynomial.length - 1,
383
+ valueNumber = value << polynomialLength,
384
+ length = codeLength - polynomialLength,
385
+ valueString = toBitsString(value, length),
386
+ result = dividePolynomials(valueNumber, generatorNumber);
387
+
388
+ result = valueString + toBitsString(result, polynomialLength);
389
+
390
+ return result;
391
+ }
392
+
393
+ export function dividePolynomials(numberX, numberY) {
394
+ let yLength = numberY.toString(2).length,
395
+ xLength = numberX.toString(2).length;
396
+ let x = numberX;
397
+
398
+ do {
399
+ x ^= numberY << xLength - yLength;
400
+ xLength = x.toString(2).length;
401
+ }
402
+ while (xLength >= yLength);
403
+
404
+ return x;
405
+ }
406
+
407
+ export function getNumberAt(str, idx) {
408
+ return parseInt(str.charAt(idx), 10);
409
+ }
410
+
411
+ export function initMatrices(version) {
412
+ let matrices = [],
413
+ modules = 17 + 4 * version;
414
+
415
+ for (let i = 0; i < maskPatternConditions.length; i++) {
416
+ matrices[i] = new Array(modules);
417
+
418
+ for (let j = 0; j < modules; j++) {
419
+ matrices[i][j] = new Array(modules);
420
+ }
421
+ }
422
+
423
+ return matrices;
424
+ }
425
+
426
+ export function addFormatInformation(matrices, formatString) {
427
+ let matrix = matrices[0],
428
+ x,
429
+ y,
430
+ idx = 0,
431
+ length = formatString.length;
432
+
433
+ for (x = 0, y = 8; x <= 8; x++) {
434
+ if (x !== 6) {
435
+ fillFunctionCell(matrices, getNumberAt(formatString, length - 1 - idx++), x, y);
436
+ }
437
+ }
438
+
439
+ for (x = 8, y = 7; y >= 0; y--) {
440
+ if (y !== 6) {
441
+ fillFunctionCell(matrices, getNumberAt(formatString, length - 1 - idx++), x, y);
442
+ }
443
+ }
444
+
445
+ idx = 0;
446
+
447
+ for (y = matrix.length - 1, x = 8; y >= matrix.length - 8; y--) {
448
+ fillFunctionCell(matrices, getNumberAt(formatString, length - 1 - idx++), x, y);
449
+ }
450
+
451
+ fillFunctionCell(matrices, 1, matrix.length - 8, 8);
452
+
453
+ for (x = matrix.length - 7, y = 8; x < matrix.length; x++) {
454
+ fillFunctionCell(matrices, getNumberAt(formatString, length - 1 - idx++), x, y);
455
+ }
456
+ }
457
+
458
+ export function encodeVersionInformation(version) {
459
+ return encodeBCH(version, versionGeneratorPolynomial, 18);
460
+ }
461
+
462
+ export function addVersionInformation(matrices, dataString) {
463
+ let matrix = matrices[0],
464
+ modules = matrix.length,
465
+ x1 = 0,
466
+ y1 = modules - 11,
467
+ x2 = modules - 11,
468
+ y2 = 0,
469
+ quotient,
470
+ mod,
471
+ value;
472
+
473
+ for (let idx = 0; idx < dataString.length; idx++) {
474
+ quotient = Math.floor(idx / 3);
475
+ mod = idx % 3;
476
+ value = getNumberAt(dataString, dataString.length - idx - 1);
477
+
478
+ fillFunctionCell(matrices, value, x1 + quotient, y1 + mod);
479
+ fillFunctionCell(matrices, value, x2 + mod, y2 + quotient);
480
+ }
481
+ }
482
+
483
+ export function addCentricPattern(matrices, pattern, x, y) {
484
+ let size = pattern.length + 2,
485
+ length = pattern.length + 1,
486
+ value;
487
+
488
+ for (let i = 0; i < pattern.length; i++) {
489
+ for (let j = i; j < size - i; j++) {
490
+ value = pattern[i];
491
+
492
+ fillFunctionCell(matrices, value, x + j, y + i);
493
+ fillFunctionCell(matrices, value, x + i, y + j);
494
+ fillFunctionCell(matrices, value, x + length - j, y + length - i);
495
+ fillFunctionCell(matrices, value, x + length - i, y + length - j);
496
+ }
497
+ }
498
+ }
499
+
500
+ export function addFinderSeparator(matrices, direction, x, y) {
501
+ let nextX = x,
502
+ nextY = y,
503
+ matrix = matrices[0];
504
+
505
+ do {
506
+ fillFunctionCell(matrices, 0, nextX, y);
507
+ fillFunctionCell(matrices, 0, x, nextY);
508
+ nextX += direction[0];
509
+ nextY += direction[1];
510
+ }
511
+ while (nextX >= 0 && nextX < matrix.length);
512
+ }
513
+
514
+ export function addFinderPatterns(matrices) {
515
+ let modules = matrices[0].length;
516
+
517
+ addCentricPattern(matrices, finderPattern, 0, 0);
518
+ addFinderSeparator(matrices, [-1, -1], 7, 7);
519
+ addCentricPattern(matrices, finderPattern, modules - 7, 0);
520
+ addFinderSeparator(matrices, [1, -1], modules - 8, 7);
521
+ addCentricPattern(matrices, finderPattern, 0, modules - 7);
522
+ addFinderSeparator(matrices, [-1, 1], 7, modules - 8);
523
+ }
524
+
525
+ export function addAlignmentPatterns(matrices, version) {
526
+ if (version < 2) {
527
+ return;
528
+ }
529
+
530
+ let matrix = matrices[0],
531
+ modules = matrix.length,
532
+ pointsCount = Math.floor(version / 7),
533
+ points = [6],
534
+ startDistance,
535
+ distance,
536
+ idx = 0;
537
+
538
+ if ((startDistance = irregularAlignmentPatternsStartDistance[version])) {
539
+ distance = (modules - 13 - startDistance) / pointsCount;
540
+ } else {
541
+ startDistance = distance = (modules - 13) / (pointsCount + 1);
542
+ }
543
+
544
+ points.push(points[idx++] + startDistance);
545
+
546
+ while ((points[idx] + distance) < modules) {
547
+ points.push(points[idx++] + distance);
548
+ }
549
+
550
+ for (let i = 0; i < points.length; i++) {
551
+ for (let j = 0; j < points.length; j++) {
552
+ if (matrix[points[i]][points[j]] === undefined) {
553
+ addCentricPattern(matrices, alignmentPattern, points[i] - 2, points[j] - 2);
554
+ }
555
+ }
556
+ }
557
+ }
558
+
559
+ export function addTimingFunctions(matrices) {
560
+ let row = 6,
561
+ column = 6,
562
+ value = 1,
563
+ modules = matrices[0].length;
564
+
565
+ for (let i = 8; i < modules - 8; i++) {
566
+ fillFunctionCell(matrices, value, row, i);
567
+ fillFunctionCell(matrices, value, i, column);
568
+ value ^= 1;
569
+ }
570
+ }
571
+
572
+ export function scoreMaskMatrixes(matrices) {
573
+ let scores = [],
574
+ previousBits = [],
575
+ darkModules = [],
576
+ patterns = [],
577
+ adjacentSameBits = [],
578
+ matrix,
579
+ i,
580
+ row = 0,
581
+ column = 1,
582
+ modulesLength = matrices[0].length;
583
+
584
+ for (i = 0; i < matrices.length; i++) {
585
+ scores[i] = 0;
586
+ darkModules[i] = 0;
587
+ adjacentSameBits[i] = [0, 0];
588
+ patterns[i] = [0, 0];
589
+ previousBits[i] = [];
590
+ }
591
+
592
+ for (let rowIndex = 0; rowIndex < modulesLength; rowIndex++) {
593
+ for (let columnIndex = 0; columnIndex < modulesLength; columnIndex++) {
594
+ for (let matrixIndex = 0; matrixIndex < matrices.length; matrixIndex++) {
595
+ matrix = matrices[matrixIndex];
596
+ darkModules[matrixIndex] += parseInt(matrix[rowIndex][columnIndex], 10);
597
+
598
+ if (previousBits[matrixIndex][row] === matrix[rowIndex][columnIndex] &&
599
+ rowIndex + 1 < modulesLength &&
600
+ columnIndex - 1 >= 0 &&
601
+ matrix[rowIndex + 1][columnIndex] === previousBits[matrixIndex][row] &&
602
+ matrix[rowIndex + 1][columnIndex - 1] === previousBits[matrixIndex][row]) {
603
+ scores[matrixIndex] += 3;
604
+ }
605
+
606
+ scoreFinderPatternOccurance(matrixIndex, patterns, scores, row, matrix[rowIndex][columnIndex]);
607
+ scoreFinderPatternOccurance(matrixIndex, patterns, scores, column, matrix[columnIndex][rowIndex]);
608
+ scoreAdjacentSameBits(matrixIndex, scores, previousBits, matrix[rowIndex][columnIndex], adjacentSameBits, row);
609
+ scoreAdjacentSameBits(matrixIndex, scores, previousBits, matrix[columnIndex][rowIndex], adjacentSameBits, column);
610
+ }
611
+ }
612
+ }
613
+
614
+ let total = modulesLength * modulesLength,
615
+ minIdx,
616
+ min = Number.MAX_VALUE;
617
+
618
+ for (i = 0; i < scores.length; i++) {
619
+ scores[i] += calculateDarkModulesRatioScore(darkModules[i], total);
620
+
621
+ if (scores[i] < min) {
622
+ min = scores[i];
623
+ minIdx = i;
624
+ }
625
+ }
626
+
627
+ return minIdx;
628
+ }
629
+
630
+ export function scoreFinderPatternOccurance(idx, patterns, scores, rowColumn, bit) {
631
+ patterns[idx][rowColumn] = ((patterns[idx][rowColumn] << 1) ^ bit) % 128;
632
+
633
+ if (patterns[idx][rowColumn] === finderPatternValue) {
634
+ scores[idx] += 40;
635
+ }
636
+ }
637
+
638
+ export function scoreAdjacentSameBits(idx, scores, previousBits, bit, adjacentBits, rowColumn) {
639
+ if (previousBits[idx][rowColumn] === bit) {
640
+ adjacentBits[idx][rowColumn]++;
641
+ } else {
642
+ previousBits[idx][rowColumn] = bit;
643
+
644
+ if (adjacentBits[idx][rowColumn] >= 5) {
645
+ scores[idx] += 3 + adjacentBits[idx][rowColumn] - 5;
646
+ }
647
+
648
+ adjacentBits[idx][rowColumn] = 1;
649
+ }
650
+ }
651
+
652
+ export function calculateDarkModulesRatioScore(darkModules, total) {
653
+ let percent = Math.floor((darkModules / total) * 100),
654
+ mod5 = percent % 5,
655
+ previous = Math.abs(percent - mod5 - 50),
656
+ next = Math.abs(percent + 5 - mod5 - 50),
657
+ score = 10 * Math.min(previous / 5, next / 5);
658
+
659
+ return score;
660
+ }
661
+
662
+ export function createQRCodeDataEncoder(encoding) {
663
+ if (encoding && encoding.toLowerCase().indexOf("utf_8") >= 0) {
664
+ return new Utf8Encoder();
665
+ }
666
+
667
+ return new IsoEncoder();
668
+ }
669
+
670
+ export function encodeData(inputString, errorCorrectionLevel, encoding) {
671
+ let encoder = createQRCodeDataEncoder(encoding),
672
+ encodingResult = encoder.getEncodingResult(inputString, errorCorrectionLevel),
673
+ version = encodingResult.version,
674
+ versionInformation = VersionsCodewordsInformation[version - 1][errorCorrectionLevel],
675
+ dataString = padDataString(encodingResult.dataString, versionInformation.totalDataCodewords),
676
+ blocks = getBlocks(dataString, versionInformation),
677
+ matrices = initMatrices(version);
678
+
679
+ addFinderPatterns(matrices);
680
+ addAlignmentPatterns(matrices, version);
681
+ addTimingFunctions(matrices);
682
+
683
+ if (version >= 7) {
684
+ addVersionInformation(matrices, toBitsString(0, 18));
685
+ }
686
+
687
+ addFormatInformation(matrices, toBitsString(0, 15));
688
+ fillData(matrices, blocks);
689
+
690
+ let minIdx = scoreMaskMatrixes(matrices),
691
+ optimalMatrix = matrices[minIdx];
692
+
693
+ if (version >= 7) {
694
+ addVersionInformation([optimalMatrix], encodeVersionInformation(version));
695
+ }
696
+
697
+ let formatString = errorCorrectionPatterns[errorCorrectionLevel] + toBitsString(minIdx, 3);
698
+ addFormatInformation([optimalMatrix], encodeFormatInformation(formatString));
699
+
700
+ return optimalMatrix;
701
+ }