@researai/deepscientist 1.5.8 → 1.5.11

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 (148) hide show
  1. package/LICENSE +186 -21
  2. package/README.md +108 -95
  3. package/assets/branding/connector-qq.png +0 -0
  4. package/assets/branding/connector-rokid.png +0 -0
  5. package/assets/branding/connector-weixin.png +0 -0
  6. package/assets/branding/projects.png +0 -0
  7. package/bin/ds.js +172 -13
  8. package/docs/assets/branding/projects.png +0 -0
  9. package/docs/en/00_QUICK_START.md +308 -70
  10. package/docs/en/01_SETTINGS_REFERENCE.md +3 -0
  11. package/docs/en/02_START_RESEARCH_GUIDE.md +112 -0
  12. package/docs/en/04_LINGZHU_CONNECTOR_GUIDE.md +62 -179
  13. package/docs/en/09_DOCTOR.md +41 -5
  14. package/docs/en/10_WEIXIN_CONNECTOR_GUIDE.md +137 -0
  15. package/docs/en/11_LICENSE_AND_RISK.md +256 -0
  16. package/docs/en/12_GUIDED_WORKFLOW_TOUR.md +427 -0
  17. package/docs/en/13_CORE_ARCHITECTURE_GUIDE.md +297 -0
  18. package/docs/en/14_PROMPT_SKILLS_AND_MCP_GUIDE.md +506 -0
  19. package/docs/en/99_ACKNOWLEDGEMENTS.md +4 -1
  20. package/docs/en/README.md +79 -0
  21. package/docs/images/lingzhu/rokid-agent-platform-create.png +0 -0
  22. package/docs/images/weixin/weixin-plugin-entry.png +0 -0
  23. package/docs/images/weixin/weixin-plugin-entry.svg +33 -0
  24. package/docs/images/weixin/weixin-qr-confirm.svg +30 -0
  25. package/docs/images/weixin/weixin-quest-media-flow.svg +44 -0
  26. package/docs/images/weixin/weixin-settings-bind.svg +57 -0
  27. package/docs/zh/00_QUICK_START.md +315 -74
  28. package/docs/zh/01_SETTINGS_REFERENCE.md +3 -0
  29. package/docs/zh/02_START_RESEARCH_GUIDE.md +112 -0
  30. package/docs/zh/04_LINGZHU_CONNECTOR_GUIDE.md +62 -193
  31. package/docs/zh/09_DOCTOR.md +41 -5
  32. package/docs/zh/10_WEIXIN_CONNECTOR_GUIDE.md +144 -0
  33. package/docs/zh/11_LICENSE_AND_RISK.md +256 -0
  34. package/docs/zh/12_GUIDED_WORKFLOW_TOUR.md +423 -0
  35. package/docs/zh/13_CORE_ARCHITECTURE_GUIDE.md +296 -0
  36. package/docs/zh/14_PROMPT_SKILLS_AND_MCP_GUIDE.md +506 -0
  37. package/docs/zh/99_ACKNOWLEDGEMENTS.md +4 -1
  38. package/docs/zh/README.md +126 -0
  39. package/install.sh +0 -34
  40. package/package.json +3 -3
  41. package/pyproject.toml +2 -2
  42. package/src/deepscientist/__init__.py +1 -1
  43. package/src/deepscientist/annotations.py +343 -0
  44. package/src/deepscientist/artifact/arxiv.py +484 -37
  45. package/src/deepscientist/artifact/metrics.py +1 -3
  46. package/src/deepscientist/artifact/service.py +1347 -111
  47. package/src/deepscientist/arxiv_library.py +275 -0
  48. package/src/deepscientist/bash_exec/service.py +9 -0
  49. package/src/deepscientist/bridges/builtins.py +2 -0
  50. package/src/deepscientist/bridges/connectors.py +447 -0
  51. package/src/deepscientist/channels/__init__.py +2 -0
  52. package/src/deepscientist/channels/builtins.py +3 -1
  53. package/src/deepscientist/channels/qq.py +1 -1
  54. package/src/deepscientist/channels/qq_gateway.py +1 -1
  55. package/src/deepscientist/channels/relay.py +7 -1
  56. package/src/deepscientist/channels/weixin.py +59 -0
  57. package/src/deepscientist/channels/weixin_ilink.py +317 -0
  58. package/src/deepscientist/config/models.py +22 -2
  59. package/src/deepscientist/config/service.py +431 -60
  60. package/src/deepscientist/connector/__init__.py +4 -0
  61. package/src/deepscientist/connector/connector_profiles.py +481 -0
  62. package/src/deepscientist/connector/lingzhu_support.py +668 -0
  63. package/src/deepscientist/connector/qq_profiles.py +206 -0
  64. package/src/deepscientist/connector/weixin_support.py +663 -0
  65. package/src/deepscientist/connector_profiles.py +1 -374
  66. package/src/deepscientist/connector_runtime.py +2 -0
  67. package/src/deepscientist/daemon/api/handlers.py +295 -5
  68. package/src/deepscientist/daemon/api/router.py +16 -1
  69. package/src/deepscientist/daemon/app.py +1130 -61
  70. package/src/deepscientist/doctor.py +5 -2
  71. package/src/deepscientist/gitops/diff.py +120 -29
  72. package/src/deepscientist/lingzhu_support.py +1 -182
  73. package/src/deepscientist/mcp/server.py +14 -5
  74. package/src/deepscientist/prompts/builder.py +29 -1
  75. package/src/deepscientist/qq_profiles.py +1 -196
  76. package/src/deepscientist/quest/node_traces.py +152 -2
  77. package/src/deepscientist/quest/service.py +169 -43
  78. package/src/deepscientist/quest/stage_views.py +172 -9
  79. package/src/deepscientist/registries/baseline.py +56 -4
  80. package/src/deepscientist/runners/codex.py +55 -3
  81. package/src/deepscientist/weixin_support.py +1 -0
  82. package/src/prompts/connectors/lingzhu.md +3 -1
  83. package/src/prompts/connectors/weixin.md +230 -0
  84. package/src/prompts/system.md +9 -0
  85. package/src/skills/idea/SKILL.md +16 -0
  86. package/src/skills/idea/references/literature-survey-template.md +24 -0
  87. package/src/skills/idea/references/related-work-playbook.md +4 -0
  88. package/src/skills/idea/references/selection-gate.md +9 -0
  89. package/src/skills/write/SKILL.md +1 -1
  90. package/src/tui/package.json +1 -1
  91. package/src/ui/dist/assets/{AiManusChatView-m2FNtwbn.js → AiManusChatView-D0mTXG4-.js} +156 -48
  92. package/src/ui/dist/assets/{AnalysisPlugin-BMTF8EGL.js → AnalysisPlugin-Db0cTXxm.js} +1 -1
  93. package/src/ui/dist/assets/{CliPlugin-BEOWgxCI.js → CliPlugin-DrV8je02.js} +164 -9
  94. package/src/ui/dist/assets/{CodeEditorPlugin-BCXvjqmb.js → CodeEditorPlugin-QXMSCH71.js} +8 -8
  95. package/src/ui/dist/assets/{CodeViewerPlugin-DaJcy3nD.js → CodeViewerPlugin-7hhtWj_E.js} +5 -5
  96. package/src/ui/dist/assets/{DocViewerPlugin-ByfeIq4K.js → DocViewerPlugin-BWMSnRJe.js} +3 -3
  97. package/src/ui/dist/assets/{GitDiffViewerPlugin-Cksf3VZ-.js → GitDiffViewerPlugin-7J9h9Vy_.js} +20 -21
  98. package/src/ui/dist/assets/{ImageViewerPlugin-CFz-OsTS.js → ImageViewerPlugin-CHJl_0lr.js} +5 -5
  99. package/src/ui/dist/assets/{LabCopilotPanel-CJ1cJzoX.js → LabCopilotPanel-1qSow1es.js} +11 -11
  100. package/src/ui/dist/assets/{LabPlugin-BF3dVJwa.js → LabPlugin-eQpPPCEp.js} +2 -1
  101. package/src/ui/dist/assets/{LatexPlugin-DDkwZ6Sj.js → LatexPlugin-BwRfi89Z.js} +7 -7
  102. package/src/ui/dist/assets/{MarkdownViewerPlugin-HAuvurcT.js → MarkdownViewerPlugin-836PVQWV.js} +4 -4
  103. package/src/ui/dist/assets/{MarketplacePlugin-BtoTYy2C.js → MarketplacePlugin-C2y_556i.js} +3 -3
  104. package/src/ui/dist/assets/{NotebookEditor-CSJYx7b-.js → NotebookEditor-BRzJbGsn.js} +12 -12
  105. package/src/ui/dist/assets/{NotebookEditor-DQgRezm_.js → NotebookEditor-DIX7Mlzu.js} +1 -1
  106. package/src/ui/dist/assets/{PdfLoader-DPa_-fv6.js → PdfLoader-DzRaTAlq.js} +14 -7
  107. package/src/ui/dist/assets/{PdfMarkdownPlugin-BZpXOEjm.js → PdfMarkdownPlugin-DZUfIUnp.js} +73 -6
  108. package/src/ui/dist/assets/{PdfViewerPlugin-BT8a6wGR.js → PdfViewerPlugin-BwtICzue.js} +103 -34
  109. package/src/ui/dist/assets/PdfViewerPlugin-DQ11QcSf.css +3627 -0
  110. package/src/ui/dist/assets/{SearchPlugin-D_blveZi.js → SearchPlugin-DHeIAMsx.js} +1 -1
  111. package/src/ui/dist/assets/{TextViewerPlugin-Btx0M3hX.js → TextViewerPlugin-C3tCmFox.js} +5 -4
  112. package/src/ui/dist/assets/{VNCViewer-DImJO4rO.js → VNCViewer-CQsKVm3t.js} +10 -10
  113. package/src/ui/dist/assets/bot-BEA2vWuK.js +21 -0
  114. package/src/ui/dist/assets/branding/logo-rokid.png +0 -0
  115. package/src/ui/dist/assets/browser-BAcuE0Xj.js +2895 -0
  116. package/src/ui/dist/assets/{code-BUfXGJSl.js → code-XfbSR8K2.js} +1 -1
  117. package/src/ui/dist/assets/{file-content-VqamwI3X.js → file-content-BjxNaIfy.js} +1 -1
  118. package/src/ui/dist/assets/{file-diff-panel-C_wOoS7a.js → file-diff-panel-D_lLVQk0.js} +1 -1
  119. package/src/ui/dist/assets/{file-socket-D2bTuMVP.js → file-socket-D9x_5vlY.js} +1 -1
  120. package/src/ui/dist/assets/{image-BZkGJ4mM.js → image-BhWT33W1.js} +1 -1
  121. package/src/ui/dist/assets/{index-DdRW6RMJ.js → index--c4iXtuy.js} +12 -12
  122. package/src/ui/dist/assets/{index-CxkvSeKw.js → index-BDxipwrC.js} +2 -2
  123. package/src/ui/dist/assets/{index-DjggJovS.js → index-DZTZ8mWP.js} +14934 -9613
  124. package/src/ui/dist/assets/{index-DXZ1daiJ.css → index-Dqj-Mjb4.css} +2 -13
  125. package/src/ui/dist/assets/index-PJbSbPTy.js +25 -0
  126. package/src/ui/dist/assets/{monaco-DHMc7kKM.js → monaco-K8izTGgo.js} +1 -1
  127. package/src/ui/dist/assets/{pdf-effect-queue-DSw_D3RV.js → pdf-effect-queue-DfBors6y.js} +16 -1
  128. package/src/ui/dist/assets/pdf.worker.min-yatZIOMy.mjs +21 -0
  129. package/src/ui/dist/assets/{popover-B85oCgCS.js → popover-yFK1J4fL.js} +1 -1
  130. package/src/ui/dist/assets/{project-sync-DOMCcPac.js → project-sync-PENr2zcz.js} +1 -74
  131. package/src/ui/dist/assets/select-CAbJDfYv.js +1690 -0
  132. package/src/ui/dist/assets/{sigma-BO2rQrl3.js → sigma-DEuYJqTl.js} +1 -1
  133. package/src/ui/dist/assets/{index-D9QIGcmc.js → square-check-big-omoSUmcd.js} +2 -13
  134. package/src/ui/dist/assets/{trash-BsVEH_dV.js → trash--F119N47.js} +1 -1
  135. package/src/ui/dist/assets/{useCliAccess-b8L6JuZm.js → useCliAccess-D31UR23I.js} +1 -1
  136. package/src/ui/dist/assets/{useFileDiffOverlay-BY7uA9hV.js → useFileDiffOverlay-BH6KcMzq.js} +1 -1
  137. package/src/ui/dist/assets/{wrap-text-BwyVuUIK.js → wrap-text-CZ613PM5.js} +1 -1
  138. package/src/ui/dist/assets/{zoom-out-RDpLugQP.js → zoom-out-BgDLAv3z.js} +1 -1
  139. package/src/ui/dist/index.html +2 -2
  140. package/src/ui/dist/assets/AutoFigurePlugin-BGxN8Umr.css +0 -3056
  141. package/src/ui/dist/assets/AutoFigurePlugin-DxPdMUNb.js +0 -8149
  142. package/src/ui/dist/assets/PdfViewerPlugin-BJXtIwj_.css +0 -260
  143. package/src/ui/dist/assets/Stepper-DH2k75Vo.js +0 -158
  144. package/src/ui/dist/assets/bibtex-B-Hqu0Sg.js +0 -189
  145. package/src/ui/dist/assets/file-utils--zJCPN1i.js +0 -109
  146. package/src/ui/dist/assets/message-square-FUIPIhU2.js +0 -16
  147. package/src/ui/dist/assets/pdfjs-DU1YE8WO.js +0 -3
  148. package/src/ui/dist/assets/tooltip-B1OspAkx.js +0 -108
@@ -0,0 +1,2895 @@
1
+ function _mergeNamespaces(n, m) {
2
+ for (var i = 0; i < m.length; i++) {
3
+ const e = m[i];
4
+ if (typeof e !== 'string' && !Array.isArray(e)) { for (const k in e) {
5
+ if (k !== 'default' && !(k in n)) {
6
+ const d = Object.getOwnPropertyDescriptor(e, k);
7
+ if (d) {
8
+ Object.defineProperty(n, k, d.get ? d : {
9
+ enumerable: true,
10
+ get: () => e[k]
11
+ });
12
+ }
13
+ }
14
+ } }
15
+ }
16
+ return Object.freeze(Object.defineProperty(n, Symbol.toStringTag, { value: 'Module' }));
17
+ }
18
+
19
+ var browser$1 = {};
20
+
21
+ // can-promise has a crash in some versions of react native that dont have
22
+ // standard global objects
23
+ // https://github.com/soldair/node-qrcode/issues/157
24
+
25
+ var canPromise$1 = function () {
26
+ return typeof Promise === 'function' && Promise.prototype && Promise.prototype.then
27
+ };
28
+
29
+ var qrcode = {};
30
+
31
+ var utils$1 = {};
32
+
33
+ let toSJISFunction;
34
+ const CODEWORDS_COUNT = [
35
+ 0, // Not used
36
+ 26, 44, 70, 100, 134, 172, 196, 242, 292, 346,
37
+ 404, 466, 532, 581, 655, 733, 815, 901, 991, 1085,
38
+ 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185,
39
+ 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706
40
+ ];
41
+
42
+ /**
43
+ * Returns the QR Code size for the specified version
44
+ *
45
+ * @param {Number} version QR Code version
46
+ * @return {Number} size of QR code
47
+ */
48
+ utils$1.getSymbolSize = function getSymbolSize (version) {
49
+ if (!version) throw new Error('"version" cannot be null or undefined')
50
+ if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40')
51
+ return version * 4 + 17
52
+ };
53
+
54
+ /**
55
+ * Returns the total number of codewords used to store data and EC information.
56
+ *
57
+ * @param {Number} version QR Code version
58
+ * @return {Number} Data length in bits
59
+ */
60
+ utils$1.getSymbolTotalCodewords = function getSymbolTotalCodewords (version) {
61
+ return CODEWORDS_COUNT[version]
62
+ };
63
+
64
+ /**
65
+ * Encode data with Bose-Chaudhuri-Hocquenghem
66
+ *
67
+ * @param {Number} data Value to encode
68
+ * @return {Number} Encoded value
69
+ */
70
+ utils$1.getBCHDigit = function (data) {
71
+ let digit = 0;
72
+
73
+ while (data !== 0) {
74
+ digit++;
75
+ data >>>= 1;
76
+ }
77
+
78
+ return digit
79
+ };
80
+
81
+ utils$1.setToSJISFunction = function setToSJISFunction (f) {
82
+ if (typeof f !== 'function') {
83
+ throw new Error('"toSJISFunc" is not a valid function.')
84
+ }
85
+
86
+ toSJISFunction = f;
87
+ };
88
+
89
+ utils$1.isKanjiModeEnabled = function () {
90
+ return typeof toSJISFunction !== 'undefined'
91
+ };
92
+
93
+ utils$1.toSJIS = function toSJIS (kanji) {
94
+ return toSJISFunction(kanji)
95
+ };
96
+
97
+ var errorCorrectionLevel = {};
98
+
99
+ (function (exports$1) {
100
+ exports$1.L = { bit: 1 };
101
+ exports$1.M = { bit: 0 };
102
+ exports$1.Q = { bit: 3 };
103
+ exports$1.H = { bit: 2 };
104
+
105
+ function fromString (string) {
106
+ if (typeof string !== 'string') {
107
+ throw new Error('Param is not a string')
108
+ }
109
+
110
+ const lcStr = string.toLowerCase();
111
+
112
+ switch (lcStr) {
113
+ case 'l':
114
+ case 'low':
115
+ return exports$1.L
116
+
117
+ case 'm':
118
+ case 'medium':
119
+ return exports$1.M
120
+
121
+ case 'q':
122
+ case 'quartile':
123
+ return exports$1.Q
124
+
125
+ case 'h':
126
+ case 'high':
127
+ return exports$1.H
128
+
129
+ default:
130
+ throw new Error('Unknown EC Level: ' + string)
131
+ }
132
+ }
133
+
134
+ exports$1.isValid = function isValid (level) {
135
+ return level && typeof level.bit !== 'undefined' &&
136
+ level.bit >= 0 && level.bit < 4
137
+ };
138
+
139
+ exports$1.from = function from (value, defaultValue) {
140
+ if (exports$1.isValid(value)) {
141
+ return value
142
+ }
143
+
144
+ try {
145
+ return fromString(value)
146
+ } catch (e) {
147
+ return defaultValue
148
+ }
149
+ };
150
+ } (errorCorrectionLevel));
151
+
152
+ function BitBuffer$1 () {
153
+ this.buffer = [];
154
+ this.length = 0;
155
+ }
156
+
157
+ BitBuffer$1.prototype = {
158
+
159
+ get: function (index) {
160
+ const bufIndex = Math.floor(index / 8);
161
+ return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) === 1
162
+ },
163
+
164
+ put: function (num, length) {
165
+ for (let i = 0; i < length; i++) {
166
+ this.putBit(((num >>> (length - i - 1)) & 1) === 1);
167
+ }
168
+ },
169
+
170
+ getLengthInBits: function () {
171
+ return this.length
172
+ },
173
+
174
+ putBit: function (bit) {
175
+ const bufIndex = Math.floor(this.length / 8);
176
+ if (this.buffer.length <= bufIndex) {
177
+ this.buffer.push(0);
178
+ }
179
+
180
+ if (bit) {
181
+ this.buffer[bufIndex] |= (0x80 >>> (this.length % 8));
182
+ }
183
+
184
+ this.length++;
185
+ }
186
+ };
187
+
188
+ var bitBuffer = BitBuffer$1;
189
+
190
+ /**
191
+ * Helper class to handle QR Code symbol modules
192
+ *
193
+ * @param {Number} size Symbol size
194
+ */
195
+
196
+ function BitMatrix$1 (size) {
197
+ if (!size || size < 1) {
198
+ throw new Error('BitMatrix size must be defined and greater than 0')
199
+ }
200
+
201
+ this.size = size;
202
+ this.data = new Uint8Array(size * size);
203
+ this.reservedBit = new Uint8Array(size * size);
204
+ }
205
+
206
+ /**
207
+ * Set bit value at specified location
208
+ * If reserved flag is set, this bit will be ignored during masking process
209
+ *
210
+ * @param {Number} row
211
+ * @param {Number} col
212
+ * @param {Boolean} value
213
+ * @param {Boolean} reserved
214
+ */
215
+ BitMatrix$1.prototype.set = function (row, col, value, reserved) {
216
+ const index = row * this.size + col;
217
+ this.data[index] = value;
218
+ if (reserved) this.reservedBit[index] = true;
219
+ };
220
+
221
+ /**
222
+ * Returns bit value at specified location
223
+ *
224
+ * @param {Number} row
225
+ * @param {Number} col
226
+ * @return {Boolean}
227
+ */
228
+ BitMatrix$1.prototype.get = function (row, col) {
229
+ return this.data[row * this.size + col]
230
+ };
231
+
232
+ /**
233
+ * Applies xor operator at specified location
234
+ * (used during masking process)
235
+ *
236
+ * @param {Number} row
237
+ * @param {Number} col
238
+ * @param {Boolean} value
239
+ */
240
+ BitMatrix$1.prototype.xor = function (row, col, value) {
241
+ this.data[row * this.size + col] ^= value;
242
+ };
243
+
244
+ /**
245
+ * Check if bit at specified location is reserved
246
+ *
247
+ * @param {Number} row
248
+ * @param {Number} col
249
+ * @return {Boolean}
250
+ */
251
+ BitMatrix$1.prototype.isReserved = function (row, col) {
252
+ return this.reservedBit[row * this.size + col]
253
+ };
254
+
255
+ var bitMatrix = BitMatrix$1;
256
+
257
+ var alignmentPattern = {};
258
+
259
+ /**
260
+ * Alignment pattern are fixed reference pattern in defined positions
261
+ * in a matrix symbology, which enables the decode software to re-synchronise
262
+ * the coordinate mapping of the image modules in the event of moderate amounts
263
+ * of distortion of the image.
264
+ *
265
+ * Alignment patterns are present only in QR Code symbols of version 2 or larger
266
+ * and their number depends on the symbol version.
267
+ */
268
+
269
+ (function (exports$1) {
270
+ const getSymbolSize = utils$1.getSymbolSize;
271
+
272
+ /**
273
+ * Calculate the row/column coordinates of the center module of each alignment pattern
274
+ * for the specified QR Code version.
275
+ *
276
+ * The alignment patterns are positioned symmetrically on either side of the diagonal
277
+ * running from the top left corner of the symbol to the bottom right corner.
278
+ *
279
+ * Since positions are simmetrical only half of the coordinates are returned.
280
+ * Each item of the array will represent in turn the x and y coordinate.
281
+ * @see {@link getPositions}
282
+ *
283
+ * @param {Number} version QR Code version
284
+ * @return {Array} Array of coordinate
285
+ */
286
+ exports$1.getRowColCoords = function getRowColCoords (version) {
287
+ if (version === 1) return []
288
+
289
+ const posCount = Math.floor(version / 7) + 2;
290
+ const size = getSymbolSize(version);
291
+ const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
292
+ const positions = [size - 7]; // Last coord is always (size - 7)
293
+
294
+ for (let i = 1; i < posCount - 1; i++) {
295
+ positions[i] = positions[i - 1] - intervals;
296
+ }
297
+
298
+ positions.push(6); // First coord is always 6
299
+
300
+ return positions.reverse()
301
+ };
302
+
303
+ /**
304
+ * Returns an array containing the positions of each alignment pattern.
305
+ * Each array's element represent the center point of the pattern as (x, y) coordinates
306
+ *
307
+ * Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}
308
+ * and filtering out the items that overlaps with finder pattern
309
+ *
310
+ * @example
311
+ * For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.
312
+ * The alignment patterns, therefore, are to be centered on (row, column)
313
+ * positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).
314
+ * Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns
315
+ * and are not therefore used for alignment patterns.
316
+ *
317
+ * let pos = getPositions(7)
318
+ * // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]
319
+ *
320
+ * @param {Number} version QR Code version
321
+ * @return {Array} Array of coordinates
322
+ */
323
+ exports$1.getPositions = function getPositions (version) {
324
+ const coords = [];
325
+ const pos = exports$1.getRowColCoords(version);
326
+ const posLength = pos.length;
327
+
328
+ for (let i = 0; i < posLength; i++) {
329
+ for (let j = 0; j < posLength; j++) {
330
+ // Skip if position is occupied by finder patterns
331
+ if ((i === 0 && j === 0) || // top-left
332
+ (i === 0 && j === posLength - 1) || // bottom-left
333
+ (i === posLength - 1 && j === 0)) { // top-right
334
+ continue
335
+ }
336
+
337
+ coords.push([pos[i], pos[j]]);
338
+ }
339
+ }
340
+
341
+ return coords
342
+ };
343
+ } (alignmentPattern));
344
+
345
+ var finderPattern = {};
346
+
347
+ const getSymbolSize = utils$1.getSymbolSize;
348
+ const FINDER_PATTERN_SIZE = 7;
349
+
350
+ /**
351
+ * Returns an array containing the positions of each finder pattern.
352
+ * Each array's element represent the top-left point of the pattern as (x, y) coordinates
353
+ *
354
+ * @param {Number} version QR Code version
355
+ * @return {Array} Array of coordinates
356
+ */
357
+ finderPattern.getPositions = function getPositions (version) {
358
+ const size = getSymbolSize(version);
359
+
360
+ return [
361
+ // top-left
362
+ [0, 0],
363
+ // top-right
364
+ [size - FINDER_PATTERN_SIZE, 0],
365
+ // bottom-left
366
+ [0, size - FINDER_PATTERN_SIZE]
367
+ ]
368
+ };
369
+
370
+ var maskPattern = {};
371
+
372
+ /**
373
+ * Data mask pattern reference
374
+ * @type {Object}
375
+ */
376
+
377
+ (function (exports$1) {
378
+ exports$1.Patterns = {
379
+ PATTERN000: 0,
380
+ PATTERN001: 1,
381
+ PATTERN010: 2,
382
+ PATTERN011: 3,
383
+ PATTERN100: 4,
384
+ PATTERN101: 5,
385
+ PATTERN110: 6,
386
+ PATTERN111: 7
387
+ };
388
+
389
+ /**
390
+ * Weighted penalty scores for the undesirable features
391
+ * @type {Object}
392
+ */
393
+ const PenaltyScores = {
394
+ N1: 3,
395
+ N2: 3,
396
+ N3: 40,
397
+ N4: 10
398
+ };
399
+
400
+ /**
401
+ * Check if mask pattern value is valid
402
+ *
403
+ * @param {Number} mask Mask pattern
404
+ * @return {Boolean} true if valid, false otherwise
405
+ */
406
+ exports$1.isValid = function isValid (mask) {
407
+ return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7
408
+ };
409
+
410
+ /**
411
+ * Returns mask pattern from a value.
412
+ * If value is not valid, returns undefined
413
+ *
414
+ * @param {Number|String} value Mask pattern value
415
+ * @return {Number} Valid mask pattern or undefined
416
+ */
417
+ exports$1.from = function from (value) {
418
+ return exports$1.isValid(value) ? parseInt(value, 10) : undefined
419
+ };
420
+
421
+ /**
422
+ * Find adjacent modules in row/column with the same color
423
+ * and assign a penalty value.
424
+ *
425
+ * Points: N1 + i
426
+ * i is the amount by which the number of adjacent modules of the same color exceeds 5
427
+ */
428
+ exports$1.getPenaltyN1 = function getPenaltyN1 (data) {
429
+ const size = data.size;
430
+ let points = 0;
431
+ let sameCountCol = 0;
432
+ let sameCountRow = 0;
433
+ let lastCol = null;
434
+ let lastRow = null;
435
+
436
+ for (let row = 0; row < size; row++) {
437
+ sameCountCol = sameCountRow = 0;
438
+ lastCol = lastRow = null;
439
+
440
+ for (let col = 0; col < size; col++) {
441
+ let module = data.get(row, col);
442
+ if (module === lastCol) {
443
+ sameCountCol++;
444
+ } else {
445
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
446
+ lastCol = module;
447
+ sameCountCol = 1;
448
+ }
449
+
450
+ module = data.get(col, row);
451
+ if (module === lastRow) {
452
+ sameCountRow++;
453
+ } else {
454
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
455
+ lastRow = module;
456
+ sameCountRow = 1;
457
+ }
458
+ }
459
+
460
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
461
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
462
+ }
463
+
464
+ return points
465
+ };
466
+
467
+ /**
468
+ * Find 2x2 blocks with the same color and assign a penalty value
469
+ *
470
+ * Points: N2 * (m - 1) * (n - 1)
471
+ */
472
+ exports$1.getPenaltyN2 = function getPenaltyN2 (data) {
473
+ const size = data.size;
474
+ let points = 0;
475
+
476
+ for (let row = 0; row < size - 1; row++) {
477
+ for (let col = 0; col < size - 1; col++) {
478
+ const last = data.get(row, col) +
479
+ data.get(row, col + 1) +
480
+ data.get(row + 1, col) +
481
+ data.get(row + 1, col + 1);
482
+
483
+ if (last === 4 || last === 0) points++;
484
+ }
485
+ }
486
+
487
+ return points * PenaltyScores.N2
488
+ };
489
+
490
+ /**
491
+ * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,
492
+ * preceded or followed by light area 4 modules wide
493
+ *
494
+ * Points: N3 * number of pattern found
495
+ */
496
+ exports$1.getPenaltyN3 = function getPenaltyN3 (data) {
497
+ const size = data.size;
498
+ let points = 0;
499
+ let bitsCol = 0;
500
+ let bitsRow = 0;
501
+
502
+ for (let row = 0; row < size; row++) {
503
+ bitsCol = bitsRow = 0;
504
+ for (let col = 0; col < size; col++) {
505
+ bitsCol = ((bitsCol << 1) & 0x7FF) | data.get(row, col);
506
+ if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++;
507
+
508
+ bitsRow = ((bitsRow << 1) & 0x7FF) | data.get(col, row);
509
+ if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++;
510
+ }
511
+ }
512
+
513
+ return points * PenaltyScores.N3
514
+ };
515
+
516
+ /**
517
+ * Calculate proportion of dark modules in entire symbol
518
+ *
519
+ * Points: N4 * k
520
+ *
521
+ * k is the rating of the deviation of the proportion of dark modules
522
+ * in the symbol from 50% in steps of 5%
523
+ */
524
+ exports$1.getPenaltyN4 = function getPenaltyN4 (data) {
525
+ let darkCount = 0;
526
+ const modulesCount = data.data.length;
527
+
528
+ for (let i = 0; i < modulesCount; i++) darkCount += data.data[i];
529
+
530
+ const k = Math.abs(Math.ceil((darkCount * 100 / modulesCount) / 5) - 10);
531
+
532
+ return k * PenaltyScores.N4
533
+ };
534
+
535
+ /**
536
+ * Return mask value at given position
537
+ *
538
+ * @param {Number} maskPattern Pattern reference value
539
+ * @param {Number} i Row
540
+ * @param {Number} j Column
541
+ * @return {Boolean} Mask value
542
+ */
543
+ function getMaskAt (maskPattern, i, j) {
544
+ switch (maskPattern) {
545
+ case exports$1.Patterns.PATTERN000: return (i + j) % 2 === 0
546
+ case exports$1.Patterns.PATTERN001: return i % 2 === 0
547
+ case exports$1.Patterns.PATTERN010: return j % 3 === 0
548
+ case exports$1.Patterns.PATTERN011: return (i + j) % 3 === 0
549
+ case exports$1.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0
550
+ case exports$1.Patterns.PATTERN101: return (i * j) % 2 + (i * j) % 3 === 0
551
+ case exports$1.Patterns.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 === 0
552
+ case exports$1.Patterns.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 === 0
553
+
554
+ default: throw new Error('bad maskPattern:' + maskPattern)
555
+ }
556
+ }
557
+
558
+ /**
559
+ * Apply a mask pattern to a BitMatrix
560
+ *
561
+ * @param {Number} pattern Pattern reference number
562
+ * @param {BitMatrix} data BitMatrix data
563
+ */
564
+ exports$1.applyMask = function applyMask (pattern, data) {
565
+ const size = data.size;
566
+
567
+ for (let col = 0; col < size; col++) {
568
+ for (let row = 0; row < size; row++) {
569
+ if (data.isReserved(row, col)) continue
570
+ data.xor(row, col, getMaskAt(pattern, row, col));
571
+ }
572
+ }
573
+ };
574
+
575
+ /**
576
+ * Returns the best mask pattern for data
577
+ *
578
+ * @param {BitMatrix} data
579
+ * @return {Number} Mask pattern reference number
580
+ */
581
+ exports$1.getBestMask = function getBestMask (data, setupFormatFunc) {
582
+ const numPatterns = Object.keys(exports$1.Patterns).length;
583
+ let bestPattern = 0;
584
+ let lowerPenalty = Infinity;
585
+
586
+ for (let p = 0; p < numPatterns; p++) {
587
+ setupFormatFunc(p);
588
+ exports$1.applyMask(p, data);
589
+
590
+ // Calculate penalty
591
+ const penalty =
592
+ exports$1.getPenaltyN1(data) +
593
+ exports$1.getPenaltyN2(data) +
594
+ exports$1.getPenaltyN3(data) +
595
+ exports$1.getPenaltyN4(data);
596
+
597
+ // Undo previously applied mask
598
+ exports$1.applyMask(p, data);
599
+
600
+ if (penalty < lowerPenalty) {
601
+ lowerPenalty = penalty;
602
+ bestPattern = p;
603
+ }
604
+ }
605
+
606
+ return bestPattern
607
+ };
608
+ } (maskPattern));
609
+
610
+ var errorCorrectionCode = {};
611
+
612
+ const ECLevel$1 = errorCorrectionLevel;
613
+
614
+ const EC_BLOCKS_TABLE = [
615
+ // L M Q H
616
+ 1, 1, 1, 1,
617
+ 1, 1, 1, 1,
618
+ 1, 1, 2, 2,
619
+ 1, 2, 2, 4,
620
+ 1, 2, 4, 4,
621
+ 2, 4, 4, 4,
622
+ 2, 4, 6, 5,
623
+ 2, 4, 6, 6,
624
+ 2, 5, 8, 8,
625
+ 4, 5, 8, 8,
626
+ 4, 5, 8, 11,
627
+ 4, 8, 10, 11,
628
+ 4, 9, 12, 16,
629
+ 4, 9, 16, 16,
630
+ 6, 10, 12, 18,
631
+ 6, 10, 17, 16,
632
+ 6, 11, 16, 19,
633
+ 6, 13, 18, 21,
634
+ 7, 14, 21, 25,
635
+ 8, 16, 20, 25,
636
+ 8, 17, 23, 25,
637
+ 9, 17, 23, 34,
638
+ 9, 18, 25, 30,
639
+ 10, 20, 27, 32,
640
+ 12, 21, 29, 35,
641
+ 12, 23, 34, 37,
642
+ 12, 25, 34, 40,
643
+ 13, 26, 35, 42,
644
+ 14, 28, 38, 45,
645
+ 15, 29, 40, 48,
646
+ 16, 31, 43, 51,
647
+ 17, 33, 45, 54,
648
+ 18, 35, 48, 57,
649
+ 19, 37, 51, 60,
650
+ 19, 38, 53, 63,
651
+ 20, 40, 56, 66,
652
+ 21, 43, 59, 70,
653
+ 22, 45, 62, 74,
654
+ 24, 47, 65, 77,
655
+ 25, 49, 68, 81
656
+ ];
657
+
658
+ const EC_CODEWORDS_TABLE = [
659
+ // L M Q H
660
+ 7, 10, 13, 17,
661
+ 10, 16, 22, 28,
662
+ 15, 26, 36, 44,
663
+ 20, 36, 52, 64,
664
+ 26, 48, 72, 88,
665
+ 36, 64, 96, 112,
666
+ 40, 72, 108, 130,
667
+ 48, 88, 132, 156,
668
+ 60, 110, 160, 192,
669
+ 72, 130, 192, 224,
670
+ 80, 150, 224, 264,
671
+ 96, 176, 260, 308,
672
+ 104, 198, 288, 352,
673
+ 120, 216, 320, 384,
674
+ 132, 240, 360, 432,
675
+ 144, 280, 408, 480,
676
+ 168, 308, 448, 532,
677
+ 180, 338, 504, 588,
678
+ 196, 364, 546, 650,
679
+ 224, 416, 600, 700,
680
+ 224, 442, 644, 750,
681
+ 252, 476, 690, 816,
682
+ 270, 504, 750, 900,
683
+ 300, 560, 810, 960,
684
+ 312, 588, 870, 1050,
685
+ 336, 644, 952, 1110,
686
+ 360, 700, 1020, 1200,
687
+ 390, 728, 1050, 1260,
688
+ 420, 784, 1140, 1350,
689
+ 450, 812, 1200, 1440,
690
+ 480, 868, 1290, 1530,
691
+ 510, 924, 1350, 1620,
692
+ 540, 980, 1440, 1710,
693
+ 570, 1036, 1530, 1800,
694
+ 570, 1064, 1590, 1890,
695
+ 600, 1120, 1680, 1980,
696
+ 630, 1204, 1770, 2100,
697
+ 660, 1260, 1860, 2220,
698
+ 720, 1316, 1950, 2310,
699
+ 750, 1372, 2040, 2430
700
+ ];
701
+
702
+ /**
703
+ * Returns the number of error correction block that the QR Code should contain
704
+ * for the specified version and error correction level.
705
+ *
706
+ * @param {Number} version QR Code version
707
+ * @param {Number} errorCorrectionLevel Error correction level
708
+ * @return {Number} Number of error correction blocks
709
+ */
710
+ errorCorrectionCode.getBlocksCount = function getBlocksCount (version, errorCorrectionLevel) {
711
+ switch (errorCorrectionLevel) {
712
+ case ECLevel$1.L:
713
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 0]
714
+ case ECLevel$1.M:
715
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 1]
716
+ case ECLevel$1.Q:
717
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 2]
718
+ case ECLevel$1.H:
719
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 3]
720
+ default:
721
+ return undefined
722
+ }
723
+ };
724
+
725
+ /**
726
+ * Returns the number of error correction codewords to use for the specified
727
+ * version and error correction level.
728
+ *
729
+ * @param {Number} version QR Code version
730
+ * @param {Number} errorCorrectionLevel Error correction level
731
+ * @return {Number} Number of error correction codewords
732
+ */
733
+ errorCorrectionCode.getTotalCodewordsCount = function getTotalCodewordsCount (version, errorCorrectionLevel) {
734
+ switch (errorCorrectionLevel) {
735
+ case ECLevel$1.L:
736
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0]
737
+ case ECLevel$1.M:
738
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1]
739
+ case ECLevel$1.Q:
740
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2]
741
+ case ECLevel$1.H:
742
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3]
743
+ default:
744
+ return undefined
745
+ }
746
+ };
747
+
748
+ var polynomial = {};
749
+
750
+ var galoisField = {};
751
+
752
+ const EXP_TABLE = new Uint8Array(512);
753
+ const LOG_TABLE = new Uint8Array(256)
754
+ /**
755
+ * Precompute the log and anti-log tables for faster computation later
756
+ *
757
+ * For each possible value in the galois field 2^8, we will pre-compute
758
+ * the logarithm and anti-logarithm (exponential) of this value
759
+ *
760
+ * ref {@link https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Introduction_to_mathematical_fields}
761
+ */
762
+ ;(function initTables () {
763
+ let x = 1;
764
+ for (let i = 0; i < 255; i++) {
765
+ EXP_TABLE[i] = x;
766
+ LOG_TABLE[x] = i;
767
+
768
+ x <<= 1; // multiply by 2
769
+
770
+ // The QR code specification says to use byte-wise modulo 100011101 arithmetic.
771
+ // This means that when a number is 256 or larger, it should be XORed with 0x11D.
772
+ if (x & 0x100) { // similar to x >= 256, but a lot faster (because 0x100 == 256)
773
+ x ^= 0x11D;
774
+ }
775
+ }
776
+
777
+ // Optimization: double the size of the anti-log table so that we don't need to mod 255 to
778
+ // stay inside the bounds (because we will mainly use this table for the multiplication of
779
+ // two GF numbers, no more).
780
+ // @see {@link mul}
781
+ for (let i = 255; i < 512; i++) {
782
+ EXP_TABLE[i] = EXP_TABLE[i - 255];
783
+ }
784
+ }());
785
+
786
+ /**
787
+ * Returns log value of n inside Galois Field
788
+ *
789
+ * @param {Number} n
790
+ * @return {Number}
791
+ */
792
+ galoisField.log = function log (n) {
793
+ if (n < 1) throw new Error('log(' + n + ')')
794
+ return LOG_TABLE[n]
795
+ };
796
+
797
+ /**
798
+ * Returns anti-log value of n inside Galois Field
799
+ *
800
+ * @param {Number} n
801
+ * @return {Number}
802
+ */
803
+ galoisField.exp = function exp (n) {
804
+ return EXP_TABLE[n]
805
+ };
806
+
807
+ /**
808
+ * Multiplies two number inside Galois Field
809
+ *
810
+ * @param {Number} x
811
+ * @param {Number} y
812
+ * @return {Number}
813
+ */
814
+ galoisField.mul = function mul (x, y) {
815
+ if (x === 0 || y === 0) return 0
816
+
817
+ // should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized
818
+ // @see {@link initTables}
819
+ return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]]
820
+ };
821
+
822
+ (function (exports$1) {
823
+ const GF = galoisField;
824
+
825
+ /**
826
+ * Multiplies two polynomials inside Galois Field
827
+ *
828
+ * @param {Uint8Array} p1 Polynomial
829
+ * @param {Uint8Array} p2 Polynomial
830
+ * @return {Uint8Array} Product of p1 and p2
831
+ */
832
+ exports$1.mul = function mul (p1, p2) {
833
+ const coeff = new Uint8Array(p1.length + p2.length - 1);
834
+
835
+ for (let i = 0; i < p1.length; i++) {
836
+ for (let j = 0; j < p2.length; j++) {
837
+ coeff[i + j] ^= GF.mul(p1[i], p2[j]);
838
+ }
839
+ }
840
+
841
+ return coeff
842
+ };
843
+
844
+ /**
845
+ * Calculate the remainder of polynomials division
846
+ *
847
+ * @param {Uint8Array} divident Polynomial
848
+ * @param {Uint8Array} divisor Polynomial
849
+ * @return {Uint8Array} Remainder
850
+ */
851
+ exports$1.mod = function mod (divident, divisor) {
852
+ let result = new Uint8Array(divident);
853
+
854
+ while ((result.length - divisor.length) >= 0) {
855
+ const coeff = result[0];
856
+
857
+ for (let i = 0; i < divisor.length; i++) {
858
+ result[i] ^= GF.mul(divisor[i], coeff);
859
+ }
860
+
861
+ // remove all zeros from buffer head
862
+ let offset = 0;
863
+ while (offset < result.length && result[offset] === 0) offset++;
864
+ result = result.slice(offset);
865
+ }
866
+
867
+ return result
868
+ };
869
+
870
+ /**
871
+ * Generate an irreducible generator polynomial of specified degree
872
+ * (used by Reed-Solomon encoder)
873
+ *
874
+ * @param {Number} degree Degree of the generator polynomial
875
+ * @return {Uint8Array} Buffer containing polynomial coefficients
876
+ */
877
+ exports$1.generateECPolynomial = function generateECPolynomial (degree) {
878
+ let poly = new Uint8Array([1]);
879
+ for (let i = 0; i < degree; i++) {
880
+ poly = exports$1.mul(poly, new Uint8Array([1, GF.exp(i)]));
881
+ }
882
+
883
+ return poly
884
+ };
885
+ } (polynomial));
886
+
887
+ const Polynomial = polynomial;
888
+
889
+ function ReedSolomonEncoder$1 (degree) {
890
+ this.genPoly = undefined;
891
+ this.degree = degree;
892
+
893
+ if (this.degree) this.initialize(this.degree);
894
+ }
895
+
896
+ /**
897
+ * Initialize the encoder.
898
+ * The input param should correspond to the number of error correction codewords.
899
+ *
900
+ * @param {Number} degree
901
+ */
902
+ ReedSolomonEncoder$1.prototype.initialize = function initialize (degree) {
903
+ // create an irreducible generator polynomial
904
+ this.degree = degree;
905
+ this.genPoly = Polynomial.generateECPolynomial(this.degree);
906
+ };
907
+
908
+ /**
909
+ * Encodes a chunk of data
910
+ *
911
+ * @param {Uint8Array} data Buffer containing input data
912
+ * @return {Uint8Array} Buffer containing encoded data
913
+ */
914
+ ReedSolomonEncoder$1.prototype.encode = function encode (data) {
915
+ if (!this.genPoly) {
916
+ throw new Error('Encoder not initialized')
917
+ }
918
+
919
+ // Calculate EC for this data block
920
+ // extends data size to data+genPoly size
921
+ const paddedData = new Uint8Array(data.length + this.degree);
922
+ paddedData.set(data);
923
+
924
+ // The error correction codewords are the remainder after dividing the data codewords
925
+ // by a generator polynomial
926
+ const remainder = Polynomial.mod(paddedData, this.genPoly);
927
+
928
+ // return EC data blocks (last n byte, where n is the degree of genPoly)
929
+ // If coefficients number in remainder are less than genPoly degree,
930
+ // pad with 0s to the left to reach the needed number of coefficients
931
+ const start = this.degree - remainder.length;
932
+ if (start > 0) {
933
+ const buff = new Uint8Array(this.degree);
934
+ buff.set(remainder, start);
935
+
936
+ return buff
937
+ }
938
+
939
+ return remainder
940
+ };
941
+
942
+ var reedSolomonEncoder = ReedSolomonEncoder$1;
943
+
944
+ var version = {};
945
+
946
+ var mode = {};
947
+
948
+ var versionCheck = {};
949
+
950
+ /**
951
+ * Check if QR Code version is valid
952
+ *
953
+ * @param {Number} version QR Code version
954
+ * @return {Boolean} true if valid version, false otherwise
955
+ */
956
+
957
+ versionCheck.isValid = function isValid (version) {
958
+ return !isNaN(version) && version >= 1 && version <= 40
959
+ };
960
+
961
+ var regex = {};
962
+
963
+ const numeric = '[0-9]+';
964
+ const alphanumeric = '[A-Z $%*+\\-./:]+';
965
+ let kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' +
966
+ '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' +
967
+ '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' +
968
+ '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+';
969
+ kanji = kanji.replace(/u/g, '\\u');
970
+
971
+ const byte = '(?:(?![A-Z0-9 $%*+\\-./:]|' + kanji + ')(?:.|[\r\n]))+';
972
+
973
+ regex.KANJI = new RegExp(kanji, 'g');
974
+ regex.BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\-./:]+', 'g');
975
+ regex.BYTE = new RegExp(byte, 'g');
976
+ regex.NUMERIC = new RegExp(numeric, 'g');
977
+ regex.ALPHANUMERIC = new RegExp(alphanumeric, 'g');
978
+
979
+ const TEST_KANJI = new RegExp('^' + kanji + '$');
980
+ const TEST_NUMERIC = new RegExp('^' + numeric + '$');
981
+ const TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\-./:]+$');
982
+
983
+ regex.testKanji = function testKanji (str) {
984
+ return TEST_KANJI.test(str)
985
+ };
986
+
987
+ regex.testNumeric = function testNumeric (str) {
988
+ return TEST_NUMERIC.test(str)
989
+ };
990
+
991
+ regex.testAlphanumeric = function testAlphanumeric (str) {
992
+ return TEST_ALPHANUMERIC.test(str)
993
+ };
994
+
995
+ (function (exports$1) {
996
+ const VersionCheck = versionCheck;
997
+ const Regex = regex;
998
+
999
+ /**
1000
+ * Numeric mode encodes data from the decimal digit set (0 - 9)
1001
+ * (byte values 30HEX to 39HEX).
1002
+ * Normally, 3 data characters are represented by 10 bits.
1003
+ *
1004
+ * @type {Object}
1005
+ */
1006
+ exports$1.NUMERIC = {
1007
+ id: 'Numeric',
1008
+ bit: 1 << 0,
1009
+ ccBits: [10, 12, 14]
1010
+ };
1011
+
1012
+ /**
1013
+ * Alphanumeric mode encodes data from a set of 45 characters,
1014
+ * i.e. 10 numeric digits (0 - 9),
1015
+ * 26 alphabetic characters (A - Z),
1016
+ * and 9 symbols (SP, $, %, *, +, -, ., /, :).
1017
+ * Normally, two input characters are represented by 11 bits.
1018
+ *
1019
+ * @type {Object}
1020
+ */
1021
+ exports$1.ALPHANUMERIC = {
1022
+ id: 'Alphanumeric',
1023
+ bit: 1 << 1,
1024
+ ccBits: [9, 11, 13]
1025
+ };
1026
+
1027
+ /**
1028
+ * In byte mode, data is encoded at 8 bits per character.
1029
+ *
1030
+ * @type {Object}
1031
+ */
1032
+ exports$1.BYTE = {
1033
+ id: 'Byte',
1034
+ bit: 1 << 2,
1035
+ ccBits: [8, 16, 16]
1036
+ };
1037
+
1038
+ /**
1039
+ * The Kanji mode efficiently encodes Kanji characters in accordance with
1040
+ * the Shift JIS system based on JIS X 0208.
1041
+ * The Shift JIS values are shifted from the JIS X 0208 values.
1042
+ * JIS X 0208 gives details of the shift coded representation.
1043
+ * Each two-byte character value is compacted to a 13-bit binary codeword.
1044
+ *
1045
+ * @type {Object}
1046
+ */
1047
+ exports$1.KANJI = {
1048
+ id: 'Kanji',
1049
+ bit: 1 << 3,
1050
+ ccBits: [8, 10, 12]
1051
+ };
1052
+
1053
+ /**
1054
+ * Mixed mode will contain a sequences of data in a combination of any of
1055
+ * the modes described above
1056
+ *
1057
+ * @type {Object}
1058
+ */
1059
+ exports$1.MIXED = {
1060
+ bit: -1
1061
+ };
1062
+
1063
+ /**
1064
+ * Returns the number of bits needed to store the data length
1065
+ * according to QR Code specifications.
1066
+ *
1067
+ * @param {Mode} mode Data mode
1068
+ * @param {Number} version QR Code version
1069
+ * @return {Number} Number of bits
1070
+ */
1071
+ exports$1.getCharCountIndicator = function getCharCountIndicator (mode, version) {
1072
+ if (!mode.ccBits) throw new Error('Invalid mode: ' + mode)
1073
+
1074
+ if (!VersionCheck.isValid(version)) {
1075
+ throw new Error('Invalid version: ' + version)
1076
+ }
1077
+
1078
+ if (version >= 1 && version < 10) return mode.ccBits[0]
1079
+ else if (version < 27) return mode.ccBits[1]
1080
+ return mode.ccBits[2]
1081
+ };
1082
+
1083
+ /**
1084
+ * Returns the most efficient mode to store the specified data
1085
+ *
1086
+ * @param {String} dataStr Input data string
1087
+ * @return {Mode} Best mode
1088
+ */
1089
+ exports$1.getBestModeForData = function getBestModeForData (dataStr) {
1090
+ if (Regex.testNumeric(dataStr)) return exports$1.NUMERIC
1091
+ else if (Regex.testAlphanumeric(dataStr)) return exports$1.ALPHANUMERIC
1092
+ else if (Regex.testKanji(dataStr)) return exports$1.KANJI
1093
+ else return exports$1.BYTE
1094
+ };
1095
+
1096
+ /**
1097
+ * Return mode name as string
1098
+ *
1099
+ * @param {Mode} mode Mode object
1100
+ * @returns {String} Mode name
1101
+ */
1102
+ exports$1.toString = function toString (mode) {
1103
+ if (mode && mode.id) return mode.id
1104
+ throw new Error('Invalid mode')
1105
+ };
1106
+
1107
+ /**
1108
+ * Check if input param is a valid mode object
1109
+ *
1110
+ * @param {Mode} mode Mode object
1111
+ * @returns {Boolean} True if valid mode, false otherwise
1112
+ */
1113
+ exports$1.isValid = function isValid (mode) {
1114
+ return mode && mode.bit && mode.ccBits
1115
+ };
1116
+
1117
+ /**
1118
+ * Get mode object from its name
1119
+ *
1120
+ * @param {String} string Mode name
1121
+ * @returns {Mode} Mode object
1122
+ */
1123
+ function fromString (string) {
1124
+ if (typeof string !== 'string') {
1125
+ throw new Error('Param is not a string')
1126
+ }
1127
+
1128
+ const lcStr = string.toLowerCase();
1129
+
1130
+ switch (lcStr) {
1131
+ case 'numeric':
1132
+ return exports$1.NUMERIC
1133
+ case 'alphanumeric':
1134
+ return exports$1.ALPHANUMERIC
1135
+ case 'kanji':
1136
+ return exports$1.KANJI
1137
+ case 'byte':
1138
+ return exports$1.BYTE
1139
+ default:
1140
+ throw new Error('Unknown mode: ' + string)
1141
+ }
1142
+ }
1143
+
1144
+ /**
1145
+ * Returns mode from a value.
1146
+ * If value is not a valid mode, returns defaultValue
1147
+ *
1148
+ * @param {Mode|String} value Encoding mode
1149
+ * @param {Mode} defaultValue Fallback value
1150
+ * @return {Mode} Encoding mode
1151
+ */
1152
+ exports$1.from = function from (value, defaultValue) {
1153
+ if (exports$1.isValid(value)) {
1154
+ return value
1155
+ }
1156
+
1157
+ try {
1158
+ return fromString(value)
1159
+ } catch (e) {
1160
+ return defaultValue
1161
+ }
1162
+ };
1163
+ } (mode));
1164
+
1165
+ (function (exports$1) {
1166
+ const Utils = utils$1;
1167
+ const ECCode = errorCorrectionCode;
1168
+ const ECLevel = errorCorrectionLevel;
1169
+ const Mode = mode;
1170
+ const VersionCheck = versionCheck;
1171
+
1172
+ // Generator polynomial used to encode version information
1173
+ const G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0);
1174
+ const G18_BCH = Utils.getBCHDigit(G18);
1175
+
1176
+ function getBestVersionForDataLength (mode, length, errorCorrectionLevel) {
1177
+ for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
1178
+ if (length <= exports$1.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
1179
+ return currentVersion
1180
+ }
1181
+ }
1182
+
1183
+ return undefined
1184
+ }
1185
+
1186
+ function getReservedBitsCount (mode, version) {
1187
+ // Character count indicator + mode indicator bits
1188
+ return Mode.getCharCountIndicator(mode, version) + 4
1189
+ }
1190
+
1191
+ function getTotalBitsFromDataArray (segments, version) {
1192
+ let totalBits = 0;
1193
+
1194
+ segments.forEach(function (data) {
1195
+ const reservedBits = getReservedBitsCount(data.mode, version);
1196
+ totalBits += reservedBits + data.getBitsLength();
1197
+ });
1198
+
1199
+ return totalBits
1200
+ }
1201
+
1202
+ function getBestVersionForMixedData (segments, errorCorrectionLevel) {
1203
+ for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
1204
+ const length = getTotalBitsFromDataArray(segments, currentVersion);
1205
+ if (length <= exports$1.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {
1206
+ return currentVersion
1207
+ }
1208
+ }
1209
+
1210
+ return undefined
1211
+ }
1212
+
1213
+ /**
1214
+ * Returns version number from a value.
1215
+ * If value is not a valid version, returns defaultValue
1216
+ *
1217
+ * @param {Number|String} value QR Code version
1218
+ * @param {Number} defaultValue Fallback value
1219
+ * @return {Number} QR Code version number
1220
+ */
1221
+ exports$1.from = function from (value, defaultValue) {
1222
+ if (VersionCheck.isValid(value)) {
1223
+ return parseInt(value, 10)
1224
+ }
1225
+
1226
+ return defaultValue
1227
+ };
1228
+
1229
+ /**
1230
+ * Returns how much data can be stored with the specified QR code version
1231
+ * and error correction level
1232
+ *
1233
+ * @param {Number} version QR Code version (1-40)
1234
+ * @param {Number} errorCorrectionLevel Error correction level
1235
+ * @param {Mode} mode Data mode
1236
+ * @return {Number} Quantity of storable data
1237
+ */
1238
+ exports$1.getCapacity = function getCapacity (version, errorCorrectionLevel, mode) {
1239
+ if (!VersionCheck.isValid(version)) {
1240
+ throw new Error('Invalid QR Code version')
1241
+ }
1242
+
1243
+ // Use Byte mode as default
1244
+ if (typeof mode === 'undefined') mode = Mode.BYTE;
1245
+
1246
+ // Total codewords for this QR code version (Data + Error correction)
1247
+ const totalCodewords = Utils.getSymbolTotalCodewords(version);
1248
+
1249
+ // Total number of error correction codewords
1250
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
1251
+
1252
+ // Total number of data codewords
1253
+ const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
1254
+
1255
+ if (mode === Mode.MIXED) return dataTotalCodewordsBits
1256
+
1257
+ const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version);
1258
+
1259
+ // Return max number of storable codewords
1260
+ switch (mode) {
1261
+ case Mode.NUMERIC:
1262
+ return Math.floor((usableBits / 10) * 3)
1263
+
1264
+ case Mode.ALPHANUMERIC:
1265
+ return Math.floor((usableBits / 11) * 2)
1266
+
1267
+ case Mode.KANJI:
1268
+ return Math.floor(usableBits / 13)
1269
+
1270
+ case Mode.BYTE:
1271
+ default:
1272
+ return Math.floor(usableBits / 8)
1273
+ }
1274
+ };
1275
+
1276
+ /**
1277
+ * Returns the minimum version needed to contain the amount of data
1278
+ *
1279
+ * @param {Segment} data Segment of data
1280
+ * @param {Number} [errorCorrectionLevel=H] Error correction level
1281
+ * @param {Mode} mode Data mode
1282
+ * @return {Number} QR Code version
1283
+ */
1284
+ exports$1.getBestVersionForData = function getBestVersionForData (data, errorCorrectionLevel) {
1285
+ let seg;
1286
+
1287
+ const ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M);
1288
+
1289
+ if (Array.isArray(data)) {
1290
+ if (data.length > 1) {
1291
+ return getBestVersionForMixedData(data, ecl)
1292
+ }
1293
+
1294
+ if (data.length === 0) {
1295
+ return 1
1296
+ }
1297
+
1298
+ seg = data[0];
1299
+ } else {
1300
+ seg = data;
1301
+ }
1302
+
1303
+ return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl)
1304
+ };
1305
+
1306
+ /**
1307
+ * Returns version information with relative error correction bits
1308
+ *
1309
+ * The version information is included in QR Code symbols of version 7 or larger.
1310
+ * It consists of an 18-bit sequence containing 6 data bits,
1311
+ * with 12 error correction bits calculated using the (18, 6) Golay code.
1312
+ *
1313
+ * @param {Number} version QR Code version
1314
+ * @return {Number} Encoded version info bits
1315
+ */
1316
+ exports$1.getEncodedBits = function getEncodedBits (version) {
1317
+ if (!VersionCheck.isValid(version) || version < 7) {
1318
+ throw new Error('Invalid QR Code version')
1319
+ }
1320
+
1321
+ let d = version << 12;
1322
+
1323
+ while (Utils.getBCHDigit(d) - G18_BCH >= 0) {
1324
+ d ^= (G18 << (Utils.getBCHDigit(d) - G18_BCH));
1325
+ }
1326
+
1327
+ return (version << 12) | d
1328
+ };
1329
+ } (version));
1330
+
1331
+ var formatInfo = {};
1332
+
1333
+ const Utils$3 = utils$1;
1334
+
1335
+ const G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0);
1336
+ const G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1);
1337
+ const G15_BCH = Utils$3.getBCHDigit(G15);
1338
+
1339
+ /**
1340
+ * Returns format information with relative error correction bits
1341
+ *
1342
+ * The format information is a 15-bit sequence containing 5 data bits,
1343
+ * with 10 error correction bits calculated using the (15, 5) BCH code.
1344
+ *
1345
+ * @param {Number} errorCorrectionLevel Error correction level
1346
+ * @param {Number} mask Mask pattern
1347
+ * @return {Number} Encoded format information bits
1348
+ */
1349
+ formatInfo.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) {
1350
+ const data = ((errorCorrectionLevel.bit << 3) | mask);
1351
+ let d = data << 10;
1352
+
1353
+ while (Utils$3.getBCHDigit(d) - G15_BCH >= 0) {
1354
+ d ^= (G15 << (Utils$3.getBCHDigit(d) - G15_BCH));
1355
+ }
1356
+
1357
+ // xor final data with mask pattern in order to ensure that
1358
+ // no combination of Error Correction Level and data mask pattern
1359
+ // will result in an all-zero data string
1360
+ return ((data << 10) | d) ^ G15_MASK
1361
+ };
1362
+
1363
+ var segments = {};
1364
+
1365
+ const Mode$4 = mode;
1366
+
1367
+ function NumericData (data) {
1368
+ this.mode = Mode$4.NUMERIC;
1369
+ this.data = data.toString();
1370
+ }
1371
+
1372
+ NumericData.getBitsLength = function getBitsLength (length) {
1373
+ return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0)
1374
+ };
1375
+
1376
+ NumericData.prototype.getLength = function getLength () {
1377
+ return this.data.length
1378
+ };
1379
+
1380
+ NumericData.prototype.getBitsLength = function getBitsLength () {
1381
+ return NumericData.getBitsLength(this.data.length)
1382
+ };
1383
+
1384
+ NumericData.prototype.write = function write (bitBuffer) {
1385
+ let i, group, value;
1386
+
1387
+ // The input data string is divided into groups of three digits,
1388
+ // and each group is converted to its 10-bit binary equivalent.
1389
+ for (i = 0; i + 3 <= this.data.length; i += 3) {
1390
+ group = this.data.substr(i, 3);
1391
+ value = parseInt(group, 10);
1392
+
1393
+ bitBuffer.put(value, 10);
1394
+ }
1395
+
1396
+ // If the number of input digits is not an exact multiple of three,
1397
+ // the final one or two digits are converted to 4 or 7 bits respectively.
1398
+ const remainingNum = this.data.length - i;
1399
+ if (remainingNum > 0) {
1400
+ group = this.data.substr(i);
1401
+ value = parseInt(group, 10);
1402
+
1403
+ bitBuffer.put(value, remainingNum * 3 + 1);
1404
+ }
1405
+ };
1406
+
1407
+ var numericData = NumericData;
1408
+
1409
+ const Mode$3 = mode;
1410
+
1411
+ /**
1412
+ * Array of characters available in alphanumeric mode
1413
+ *
1414
+ * As per QR Code specification, to each character
1415
+ * is assigned a value from 0 to 44 which in this case coincides
1416
+ * with the array index
1417
+ *
1418
+ * @type {Array}
1419
+ */
1420
+ const ALPHA_NUM_CHARS = [
1421
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
1422
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
1423
+ 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
1424
+ ' ', '$', '%', '*', '+', '-', '.', '/', ':'
1425
+ ];
1426
+
1427
+ function AlphanumericData (data) {
1428
+ this.mode = Mode$3.ALPHANUMERIC;
1429
+ this.data = data;
1430
+ }
1431
+
1432
+ AlphanumericData.getBitsLength = function getBitsLength (length) {
1433
+ return 11 * Math.floor(length / 2) + 6 * (length % 2)
1434
+ };
1435
+
1436
+ AlphanumericData.prototype.getLength = function getLength () {
1437
+ return this.data.length
1438
+ };
1439
+
1440
+ AlphanumericData.prototype.getBitsLength = function getBitsLength () {
1441
+ return AlphanumericData.getBitsLength(this.data.length)
1442
+ };
1443
+
1444
+ AlphanumericData.prototype.write = function write (bitBuffer) {
1445
+ let i;
1446
+
1447
+ // Input data characters are divided into groups of two characters
1448
+ // and encoded as 11-bit binary codes.
1449
+ for (i = 0; i + 2 <= this.data.length; i += 2) {
1450
+ // The character value of the first character is multiplied by 45
1451
+ let value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45;
1452
+
1453
+ // The character value of the second digit is added to the product
1454
+ value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1]);
1455
+
1456
+ // The sum is then stored as 11-bit binary number
1457
+ bitBuffer.put(value, 11);
1458
+ }
1459
+
1460
+ // If the number of input data characters is not a multiple of two,
1461
+ // the character value of the final character is encoded as a 6-bit binary number.
1462
+ if (this.data.length % 2) {
1463
+ bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6);
1464
+ }
1465
+ };
1466
+
1467
+ var alphanumericData = AlphanumericData;
1468
+
1469
+ const Mode$2 = mode;
1470
+
1471
+ function ByteData (data) {
1472
+ this.mode = Mode$2.BYTE;
1473
+ if (typeof (data) === 'string') {
1474
+ this.data = new TextEncoder().encode(data);
1475
+ } else {
1476
+ this.data = new Uint8Array(data);
1477
+ }
1478
+ }
1479
+
1480
+ ByteData.getBitsLength = function getBitsLength (length) {
1481
+ return length * 8
1482
+ };
1483
+
1484
+ ByteData.prototype.getLength = function getLength () {
1485
+ return this.data.length
1486
+ };
1487
+
1488
+ ByteData.prototype.getBitsLength = function getBitsLength () {
1489
+ return ByteData.getBitsLength(this.data.length)
1490
+ };
1491
+
1492
+ ByteData.prototype.write = function (bitBuffer) {
1493
+ for (let i = 0, l = this.data.length; i < l; i++) {
1494
+ bitBuffer.put(this.data[i], 8);
1495
+ }
1496
+ };
1497
+
1498
+ var byteData = ByteData;
1499
+
1500
+ const Mode$1 = mode;
1501
+ const Utils$2 = utils$1;
1502
+
1503
+ function KanjiData (data) {
1504
+ this.mode = Mode$1.KANJI;
1505
+ this.data = data;
1506
+ }
1507
+
1508
+ KanjiData.getBitsLength = function getBitsLength (length) {
1509
+ return length * 13
1510
+ };
1511
+
1512
+ KanjiData.prototype.getLength = function getLength () {
1513
+ return this.data.length
1514
+ };
1515
+
1516
+ KanjiData.prototype.getBitsLength = function getBitsLength () {
1517
+ return KanjiData.getBitsLength(this.data.length)
1518
+ };
1519
+
1520
+ KanjiData.prototype.write = function (bitBuffer) {
1521
+ let i;
1522
+
1523
+ // In the Shift JIS system, Kanji characters are represented by a two byte combination.
1524
+ // These byte values are shifted from the JIS X 0208 values.
1525
+ // JIS X 0208 gives details of the shift coded representation.
1526
+ for (i = 0; i < this.data.length; i++) {
1527
+ let value = Utils$2.toSJIS(this.data[i]);
1528
+
1529
+ // For characters with Shift JIS values from 0x8140 to 0x9FFC:
1530
+ if (value >= 0x8140 && value <= 0x9FFC) {
1531
+ // Subtract 0x8140 from Shift JIS value
1532
+ value -= 0x8140;
1533
+
1534
+ // For characters with Shift JIS values from 0xE040 to 0xEBBF
1535
+ } else if (value >= 0xE040 && value <= 0xEBBF) {
1536
+ // Subtract 0xC140 from Shift JIS value
1537
+ value -= 0xC140;
1538
+ } else {
1539
+ throw new Error(
1540
+ 'Invalid SJIS character: ' + this.data[i] + '\n' +
1541
+ 'Make sure your charset is UTF-8')
1542
+ }
1543
+
1544
+ // Multiply most significant byte of result by 0xC0
1545
+ // and add least significant byte to product
1546
+ value = (((value >>> 8) & 0xff) * 0xC0) + (value & 0xff);
1547
+
1548
+ // Convert result to a 13-bit binary string
1549
+ bitBuffer.put(value, 13);
1550
+ }
1551
+ };
1552
+
1553
+ var kanjiData = KanjiData;
1554
+
1555
+ var dijkstra = {exports: {}};
1556
+
1557
+ (function (module) {
1558
+
1559
+ /******************************************************************************
1560
+ * Created 2008-08-19.
1561
+ *
1562
+ * Dijkstra path-finding functions. Adapted from the Dijkstar Python project.
1563
+ *
1564
+ * Copyright (C) 2008
1565
+ * Wyatt Baldwin <self@wyattbaldwin.com>
1566
+ * All rights reserved
1567
+ *
1568
+ * Licensed under the MIT license.
1569
+ *
1570
+ * http://www.opensource.org/licenses/mit-license.php
1571
+ *
1572
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1573
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1574
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1575
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1576
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1577
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1578
+ * THE SOFTWARE.
1579
+ *****************************************************************************/
1580
+ var dijkstra = {
1581
+ single_source_shortest_paths: function(graph, s, d) {
1582
+ // Predecessor map for each node that has been encountered.
1583
+ // node ID => predecessor node ID
1584
+ var predecessors = {};
1585
+
1586
+ // Costs of shortest paths from s to all nodes encountered.
1587
+ // node ID => cost
1588
+ var costs = {};
1589
+ costs[s] = 0;
1590
+
1591
+ // Costs of shortest paths from s to all nodes encountered; differs from
1592
+ // `costs` in that it provides easy access to the node that currently has
1593
+ // the known shortest path from s.
1594
+ // XXX: Do we actually need both `costs` and `open`?
1595
+ var open = dijkstra.PriorityQueue.make();
1596
+ open.push(s, 0);
1597
+
1598
+ var closest,
1599
+ u, v,
1600
+ cost_of_s_to_u,
1601
+ adjacent_nodes,
1602
+ cost_of_e,
1603
+ cost_of_s_to_u_plus_cost_of_e,
1604
+ cost_of_s_to_v,
1605
+ first_visit;
1606
+ while (!open.empty()) {
1607
+ // In the nodes remaining in graph that have a known cost from s,
1608
+ // find the node, u, that currently has the shortest path from s.
1609
+ closest = open.pop();
1610
+ u = closest.value;
1611
+ cost_of_s_to_u = closest.cost;
1612
+
1613
+ // Get nodes adjacent to u...
1614
+ adjacent_nodes = graph[u] || {};
1615
+
1616
+ // ...and explore the edges that connect u to those nodes, updating
1617
+ // the cost of the shortest paths to any or all of those nodes as
1618
+ // necessary. v is the node across the current edge from u.
1619
+ for (v in adjacent_nodes) {
1620
+ if (adjacent_nodes.hasOwnProperty(v)) {
1621
+ // Get the cost of the edge running from u to v.
1622
+ cost_of_e = adjacent_nodes[v];
1623
+
1624
+ // Cost of s to u plus the cost of u to v across e--this is *a*
1625
+ // cost from s to v that may or may not be less than the current
1626
+ // known cost to v.
1627
+ cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
1628
+
1629
+ // If we haven't visited v yet OR if the current known cost from s to
1630
+ // v is greater than the new cost we just found (cost of s to u plus
1631
+ // cost of u to v across e), update v's cost in the cost list and
1632
+ // update v's predecessor in the predecessor list (it's now u).
1633
+ cost_of_s_to_v = costs[v];
1634
+ first_visit = (typeof costs[v] === 'undefined');
1635
+ if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
1636
+ costs[v] = cost_of_s_to_u_plus_cost_of_e;
1637
+ open.push(v, cost_of_s_to_u_plus_cost_of_e);
1638
+ predecessors[v] = u;
1639
+ }
1640
+ }
1641
+ }
1642
+ }
1643
+
1644
+ if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') {
1645
+ var msg = ['Could not find a path from ', s, ' to ', d, '.'].join('');
1646
+ throw new Error(msg);
1647
+ }
1648
+
1649
+ return predecessors;
1650
+ },
1651
+
1652
+ extract_shortest_path_from_predecessor_list: function(predecessors, d) {
1653
+ var nodes = [];
1654
+ var u = d;
1655
+ while (u) {
1656
+ nodes.push(u);
1657
+ predecessors[u];
1658
+ u = predecessors[u];
1659
+ }
1660
+ nodes.reverse();
1661
+ return nodes;
1662
+ },
1663
+
1664
+ find_path: function(graph, s, d) {
1665
+ var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
1666
+ return dijkstra.extract_shortest_path_from_predecessor_list(
1667
+ predecessors, d);
1668
+ },
1669
+
1670
+ /**
1671
+ * A very naive priority queue implementation.
1672
+ */
1673
+ PriorityQueue: {
1674
+ make: function (opts) {
1675
+ var T = dijkstra.PriorityQueue,
1676
+ t = {},
1677
+ key;
1678
+ opts = opts || {};
1679
+ for (key in T) {
1680
+ if (T.hasOwnProperty(key)) {
1681
+ t[key] = T[key];
1682
+ }
1683
+ }
1684
+ t.queue = [];
1685
+ t.sorter = opts.sorter || T.default_sorter;
1686
+ return t;
1687
+ },
1688
+
1689
+ default_sorter: function (a, b) {
1690
+ return a.cost - b.cost;
1691
+ },
1692
+
1693
+ /**
1694
+ * Add a new item to the queue and ensure the highest priority element
1695
+ * is at the front of the queue.
1696
+ */
1697
+ push: function (value, cost) {
1698
+ var item = {value: value, cost: cost};
1699
+ this.queue.push(item);
1700
+ this.queue.sort(this.sorter);
1701
+ },
1702
+
1703
+ /**
1704
+ * Return the highest priority element in the queue.
1705
+ */
1706
+ pop: function () {
1707
+ return this.queue.shift();
1708
+ },
1709
+
1710
+ empty: function () {
1711
+ return this.queue.length === 0;
1712
+ }
1713
+ }
1714
+ };
1715
+
1716
+
1717
+ // node.js module exports
1718
+ {
1719
+ module.exports = dijkstra;
1720
+ }
1721
+ } (dijkstra));
1722
+
1723
+ var dijkstraExports = dijkstra.exports;
1724
+
1725
+ (function (exports$1) {
1726
+ const Mode = mode;
1727
+ const NumericData = numericData;
1728
+ const AlphanumericData = alphanumericData;
1729
+ const ByteData = byteData;
1730
+ const KanjiData = kanjiData;
1731
+ const Regex = regex;
1732
+ const Utils = utils$1;
1733
+ const dijkstra = dijkstraExports;
1734
+
1735
+ /**
1736
+ * Returns UTF8 byte length
1737
+ *
1738
+ * @param {String} str Input string
1739
+ * @return {Number} Number of byte
1740
+ */
1741
+ function getStringByteLength (str) {
1742
+ return unescape(encodeURIComponent(str)).length
1743
+ }
1744
+
1745
+ /**
1746
+ * Get a list of segments of the specified mode
1747
+ * from a string
1748
+ *
1749
+ * @param {Mode} mode Segment mode
1750
+ * @param {String} str String to process
1751
+ * @return {Array} Array of object with segments data
1752
+ */
1753
+ function getSegments (regex, mode, str) {
1754
+ const segments = [];
1755
+ let result;
1756
+
1757
+ while ((result = regex.exec(str)) !== null) {
1758
+ segments.push({
1759
+ data: result[0],
1760
+ index: result.index,
1761
+ mode: mode,
1762
+ length: result[0].length
1763
+ });
1764
+ }
1765
+
1766
+ return segments
1767
+ }
1768
+
1769
+ /**
1770
+ * Extracts a series of segments with the appropriate
1771
+ * modes from a string
1772
+ *
1773
+ * @param {String} dataStr Input string
1774
+ * @return {Array} Array of object with segments data
1775
+ */
1776
+ function getSegmentsFromString (dataStr) {
1777
+ const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr);
1778
+ const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr);
1779
+ let byteSegs;
1780
+ let kanjiSegs;
1781
+
1782
+ if (Utils.isKanjiModeEnabled()) {
1783
+ byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr);
1784
+ kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr);
1785
+ } else {
1786
+ byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr);
1787
+ kanjiSegs = [];
1788
+ }
1789
+
1790
+ const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs);
1791
+
1792
+ return segs
1793
+ .sort(function (s1, s2) {
1794
+ return s1.index - s2.index
1795
+ })
1796
+ .map(function (obj) {
1797
+ return {
1798
+ data: obj.data,
1799
+ mode: obj.mode,
1800
+ length: obj.length
1801
+ }
1802
+ })
1803
+ }
1804
+
1805
+ /**
1806
+ * Returns how many bits are needed to encode a string of
1807
+ * specified length with the specified mode
1808
+ *
1809
+ * @param {Number} length String length
1810
+ * @param {Mode} mode Segment mode
1811
+ * @return {Number} Bit length
1812
+ */
1813
+ function getSegmentBitsLength (length, mode) {
1814
+ switch (mode) {
1815
+ case Mode.NUMERIC:
1816
+ return NumericData.getBitsLength(length)
1817
+ case Mode.ALPHANUMERIC:
1818
+ return AlphanumericData.getBitsLength(length)
1819
+ case Mode.KANJI:
1820
+ return KanjiData.getBitsLength(length)
1821
+ case Mode.BYTE:
1822
+ return ByteData.getBitsLength(length)
1823
+ }
1824
+ }
1825
+
1826
+ /**
1827
+ * Merges adjacent segments which have the same mode
1828
+ *
1829
+ * @param {Array} segs Array of object with segments data
1830
+ * @return {Array} Array of object with segments data
1831
+ */
1832
+ function mergeSegments (segs) {
1833
+ return segs.reduce(function (acc, curr) {
1834
+ const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null;
1835
+ if (prevSeg && prevSeg.mode === curr.mode) {
1836
+ acc[acc.length - 1].data += curr.data;
1837
+ return acc
1838
+ }
1839
+
1840
+ acc.push(curr);
1841
+ return acc
1842
+ }, [])
1843
+ }
1844
+
1845
+ /**
1846
+ * Generates a list of all possible nodes combination which
1847
+ * will be used to build a segments graph.
1848
+ *
1849
+ * Nodes are divided by groups. Each group will contain a list of all the modes
1850
+ * in which is possible to encode the given text.
1851
+ *
1852
+ * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte.
1853
+ * The group for '12345' will contain then 3 objects, one for each
1854
+ * possible encoding mode.
1855
+ *
1856
+ * Each node represents a possible segment.
1857
+ *
1858
+ * @param {Array} segs Array of object with segments data
1859
+ * @return {Array} Array of object with segments data
1860
+ */
1861
+ function buildNodes (segs) {
1862
+ const nodes = [];
1863
+ for (let i = 0; i < segs.length; i++) {
1864
+ const seg = segs[i];
1865
+
1866
+ switch (seg.mode) {
1867
+ case Mode.NUMERIC:
1868
+ nodes.push([seg,
1869
+ { data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },
1870
+ { data: seg.data, mode: Mode.BYTE, length: seg.length }
1871
+ ]);
1872
+ break
1873
+ case Mode.ALPHANUMERIC:
1874
+ nodes.push([seg,
1875
+ { data: seg.data, mode: Mode.BYTE, length: seg.length }
1876
+ ]);
1877
+ break
1878
+ case Mode.KANJI:
1879
+ nodes.push([seg,
1880
+ { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
1881
+ ]);
1882
+ break
1883
+ case Mode.BYTE:
1884
+ nodes.push([
1885
+ { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
1886
+ ]);
1887
+ }
1888
+ }
1889
+
1890
+ return nodes
1891
+ }
1892
+
1893
+ /**
1894
+ * Builds a graph from a list of nodes.
1895
+ * All segments in each node group will be connected with all the segments of
1896
+ * the next group and so on.
1897
+ *
1898
+ * At each connection will be assigned a weight depending on the
1899
+ * segment's byte length.
1900
+ *
1901
+ * @param {Array} nodes Array of object with segments data
1902
+ * @param {Number} version QR Code version
1903
+ * @return {Object} Graph of all possible segments
1904
+ */
1905
+ function buildGraph (nodes, version) {
1906
+ const table = {};
1907
+ const graph = { start: {} };
1908
+ let prevNodeIds = ['start'];
1909
+
1910
+ for (let i = 0; i < nodes.length; i++) {
1911
+ const nodeGroup = nodes[i];
1912
+ const currentNodeIds = [];
1913
+
1914
+ for (let j = 0; j < nodeGroup.length; j++) {
1915
+ const node = nodeGroup[j];
1916
+ const key = '' + i + j;
1917
+
1918
+ currentNodeIds.push(key);
1919
+ table[key] = { node: node, lastCount: 0 };
1920
+ graph[key] = {};
1921
+
1922
+ for (let n = 0; n < prevNodeIds.length; n++) {
1923
+ const prevNodeId = prevNodeIds[n];
1924
+
1925
+ if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
1926
+ graph[prevNodeId][key] =
1927
+ getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) -
1928
+ getSegmentBitsLength(table[prevNodeId].lastCount, node.mode);
1929
+
1930
+ table[prevNodeId].lastCount += node.length;
1931
+ } else {
1932
+ if (table[prevNodeId]) table[prevNodeId].lastCount = node.length;
1933
+
1934
+ graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) +
1935
+ 4 + Mode.getCharCountIndicator(node.mode, version); // switch cost
1936
+ }
1937
+ }
1938
+ }
1939
+
1940
+ prevNodeIds = currentNodeIds;
1941
+ }
1942
+
1943
+ for (let n = 0; n < prevNodeIds.length; n++) {
1944
+ graph[prevNodeIds[n]].end = 0;
1945
+ }
1946
+
1947
+ return { map: graph, table: table }
1948
+ }
1949
+
1950
+ /**
1951
+ * Builds a segment from a specified data and mode.
1952
+ * If a mode is not specified, the more suitable will be used.
1953
+ *
1954
+ * @param {String} data Input data
1955
+ * @param {Mode | String} modesHint Data mode
1956
+ * @return {Segment} Segment
1957
+ */
1958
+ function buildSingleSegment (data, modesHint) {
1959
+ let mode;
1960
+ const bestMode = Mode.getBestModeForData(data);
1961
+
1962
+ mode = Mode.from(modesHint, bestMode);
1963
+
1964
+ // Make sure data can be encoded
1965
+ if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {
1966
+ throw new Error('"' + data + '"' +
1967
+ ' cannot be encoded with mode ' + Mode.toString(mode) +
1968
+ '.\n Suggested mode is: ' + Mode.toString(bestMode))
1969
+ }
1970
+
1971
+ // Use Mode.BYTE if Kanji support is disabled
1972
+ if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {
1973
+ mode = Mode.BYTE;
1974
+ }
1975
+
1976
+ switch (mode) {
1977
+ case Mode.NUMERIC:
1978
+ return new NumericData(data)
1979
+
1980
+ case Mode.ALPHANUMERIC:
1981
+ return new AlphanumericData(data)
1982
+
1983
+ case Mode.KANJI:
1984
+ return new KanjiData(data)
1985
+
1986
+ case Mode.BYTE:
1987
+ return new ByteData(data)
1988
+ }
1989
+ }
1990
+
1991
+ /**
1992
+ * Builds a list of segments from an array.
1993
+ * Array can contain Strings or Objects with segment's info.
1994
+ *
1995
+ * For each item which is a string, will be generated a segment with the given
1996
+ * string and the more appropriate encoding mode.
1997
+ *
1998
+ * For each item which is an object, will be generated a segment with the given
1999
+ * data and mode.
2000
+ * Objects must contain at least the property "data".
2001
+ * If property "mode" is not present, the more suitable mode will be used.
2002
+ *
2003
+ * @param {Array} array Array of objects with segments data
2004
+ * @return {Array} Array of Segments
2005
+ */
2006
+ exports$1.fromArray = function fromArray (array) {
2007
+ return array.reduce(function (acc, seg) {
2008
+ if (typeof seg === 'string') {
2009
+ acc.push(buildSingleSegment(seg, null));
2010
+ } else if (seg.data) {
2011
+ acc.push(buildSingleSegment(seg.data, seg.mode));
2012
+ }
2013
+
2014
+ return acc
2015
+ }, [])
2016
+ };
2017
+
2018
+ /**
2019
+ * Builds an optimized sequence of segments from a string,
2020
+ * which will produce the shortest possible bitstream.
2021
+ *
2022
+ * @param {String} data Input string
2023
+ * @param {Number} version QR Code version
2024
+ * @return {Array} Array of segments
2025
+ */
2026
+ exports$1.fromString = function fromString (data, version) {
2027
+ const segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled());
2028
+
2029
+ const nodes = buildNodes(segs);
2030
+ const graph = buildGraph(nodes, version);
2031
+ const path = dijkstra.find_path(graph.map, 'start', 'end');
2032
+
2033
+ const optimizedSegs = [];
2034
+ for (let i = 1; i < path.length - 1; i++) {
2035
+ optimizedSegs.push(graph.table[path[i]].node);
2036
+ }
2037
+
2038
+ return exports$1.fromArray(mergeSegments(optimizedSegs))
2039
+ };
2040
+
2041
+ /**
2042
+ * Splits a string in various segments with the modes which
2043
+ * best represent their content.
2044
+ * The produced segments are far from being optimized.
2045
+ * The output of this function is only used to estimate a QR Code version
2046
+ * which may contain the data.
2047
+ *
2048
+ * @param {string} data Input string
2049
+ * @return {Array} Array of segments
2050
+ */
2051
+ exports$1.rawSplit = function rawSplit (data) {
2052
+ return exports$1.fromArray(
2053
+ getSegmentsFromString(data, Utils.isKanjiModeEnabled())
2054
+ )
2055
+ };
2056
+ } (segments));
2057
+
2058
+ const Utils$1 = utils$1;
2059
+ const ECLevel = errorCorrectionLevel;
2060
+ const BitBuffer = bitBuffer;
2061
+ const BitMatrix = bitMatrix;
2062
+ const AlignmentPattern = alignmentPattern;
2063
+ const FinderPattern = finderPattern;
2064
+ const MaskPattern = maskPattern;
2065
+ const ECCode = errorCorrectionCode;
2066
+ const ReedSolomonEncoder = reedSolomonEncoder;
2067
+ const Version = version;
2068
+ const FormatInfo = formatInfo;
2069
+ const Mode = mode;
2070
+ const Segments = segments;
2071
+
2072
+ /**
2073
+ * QRCode for JavaScript
2074
+ *
2075
+ * modified by Ryan Day for nodejs support
2076
+ * Copyright (c) 2011 Ryan Day
2077
+ *
2078
+ * Licensed under the MIT license:
2079
+ * http://www.opensource.org/licenses/mit-license.php
2080
+ *
2081
+ //---------------------------------------------------------------------
2082
+ // QRCode for JavaScript
2083
+ //
2084
+ // Copyright (c) 2009 Kazuhiko Arase
2085
+ //
2086
+ // URL: http://www.d-project.com/
2087
+ //
2088
+ // Licensed under the MIT license:
2089
+ // http://www.opensource.org/licenses/mit-license.php
2090
+ //
2091
+ // The word "QR Code" is registered trademark of
2092
+ // DENSO WAVE INCORPORATED
2093
+ // http://www.denso-wave.com/qrcode/faqpatent-e.html
2094
+ //
2095
+ //---------------------------------------------------------------------
2096
+ */
2097
+
2098
+ /**
2099
+ * Add finder patterns bits to matrix
2100
+ *
2101
+ * @param {BitMatrix} matrix Modules matrix
2102
+ * @param {Number} version QR Code version
2103
+ */
2104
+ function setupFinderPattern (matrix, version) {
2105
+ const size = matrix.size;
2106
+ const pos = FinderPattern.getPositions(version);
2107
+
2108
+ for (let i = 0; i < pos.length; i++) {
2109
+ const row = pos[i][0];
2110
+ const col = pos[i][1];
2111
+
2112
+ for (let r = -1; r <= 7; r++) {
2113
+ if (row + r <= -1 || size <= row + r) continue
2114
+
2115
+ for (let c = -1; c <= 7; c++) {
2116
+ if (col + c <= -1 || size <= col + c) continue
2117
+
2118
+ if ((r >= 0 && r <= 6 && (c === 0 || c === 6)) ||
2119
+ (c >= 0 && c <= 6 && (r === 0 || r === 6)) ||
2120
+ (r >= 2 && r <= 4 && c >= 2 && c <= 4)) {
2121
+ matrix.set(row + r, col + c, true, true);
2122
+ } else {
2123
+ matrix.set(row + r, col + c, false, true);
2124
+ }
2125
+ }
2126
+ }
2127
+ }
2128
+ }
2129
+
2130
+ /**
2131
+ * Add timing pattern bits to matrix
2132
+ *
2133
+ * Note: this function must be called before {@link setupAlignmentPattern}
2134
+ *
2135
+ * @param {BitMatrix} matrix Modules matrix
2136
+ */
2137
+ function setupTimingPattern (matrix) {
2138
+ const size = matrix.size;
2139
+
2140
+ for (let r = 8; r < size - 8; r++) {
2141
+ const value = r % 2 === 0;
2142
+ matrix.set(r, 6, value, true);
2143
+ matrix.set(6, r, value, true);
2144
+ }
2145
+ }
2146
+
2147
+ /**
2148
+ * Add alignment patterns bits to matrix
2149
+ *
2150
+ * Note: this function must be called after {@link setupTimingPattern}
2151
+ *
2152
+ * @param {BitMatrix} matrix Modules matrix
2153
+ * @param {Number} version QR Code version
2154
+ */
2155
+ function setupAlignmentPattern (matrix, version) {
2156
+ const pos = AlignmentPattern.getPositions(version);
2157
+
2158
+ for (let i = 0; i < pos.length; i++) {
2159
+ const row = pos[i][0];
2160
+ const col = pos[i][1];
2161
+
2162
+ for (let r = -2; r <= 2; r++) {
2163
+ for (let c = -2; c <= 2; c++) {
2164
+ if (r === -2 || r === 2 || c === -2 || c === 2 ||
2165
+ (r === 0 && c === 0)) {
2166
+ matrix.set(row + r, col + c, true, true);
2167
+ } else {
2168
+ matrix.set(row + r, col + c, false, true);
2169
+ }
2170
+ }
2171
+ }
2172
+ }
2173
+ }
2174
+
2175
+ /**
2176
+ * Add version info bits to matrix
2177
+ *
2178
+ * @param {BitMatrix} matrix Modules matrix
2179
+ * @param {Number} version QR Code version
2180
+ */
2181
+ function setupVersionInfo (matrix, version) {
2182
+ const size = matrix.size;
2183
+ const bits = Version.getEncodedBits(version);
2184
+ let row, col, mod;
2185
+
2186
+ for (let i = 0; i < 18; i++) {
2187
+ row = Math.floor(i / 3);
2188
+ col = i % 3 + size - 8 - 3;
2189
+ mod = ((bits >> i) & 1) === 1;
2190
+
2191
+ matrix.set(row, col, mod, true);
2192
+ matrix.set(col, row, mod, true);
2193
+ }
2194
+ }
2195
+
2196
+ /**
2197
+ * Add format info bits to matrix
2198
+ *
2199
+ * @param {BitMatrix} matrix Modules matrix
2200
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2201
+ * @param {Number} maskPattern Mask pattern reference value
2202
+ */
2203
+ function setupFormatInfo (matrix, errorCorrectionLevel, maskPattern) {
2204
+ const size = matrix.size;
2205
+ const bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern);
2206
+ let i, mod;
2207
+
2208
+ for (i = 0; i < 15; i++) {
2209
+ mod = ((bits >> i) & 1) === 1;
2210
+
2211
+ // vertical
2212
+ if (i < 6) {
2213
+ matrix.set(i, 8, mod, true);
2214
+ } else if (i < 8) {
2215
+ matrix.set(i + 1, 8, mod, true);
2216
+ } else {
2217
+ matrix.set(size - 15 + i, 8, mod, true);
2218
+ }
2219
+
2220
+ // horizontal
2221
+ if (i < 8) {
2222
+ matrix.set(8, size - i - 1, mod, true);
2223
+ } else if (i < 9) {
2224
+ matrix.set(8, 15 - i - 1 + 1, mod, true);
2225
+ } else {
2226
+ matrix.set(8, 15 - i - 1, mod, true);
2227
+ }
2228
+ }
2229
+
2230
+ // fixed module
2231
+ matrix.set(size - 8, 8, 1, true);
2232
+ }
2233
+
2234
+ /**
2235
+ * Add encoded data bits to matrix
2236
+ *
2237
+ * @param {BitMatrix} matrix Modules matrix
2238
+ * @param {Uint8Array} data Data codewords
2239
+ */
2240
+ function setupData (matrix, data) {
2241
+ const size = matrix.size;
2242
+ let inc = -1;
2243
+ let row = size - 1;
2244
+ let bitIndex = 7;
2245
+ let byteIndex = 0;
2246
+
2247
+ for (let col = size - 1; col > 0; col -= 2) {
2248
+ if (col === 6) col--;
2249
+
2250
+ while (true) {
2251
+ for (let c = 0; c < 2; c++) {
2252
+ if (!matrix.isReserved(row, col - c)) {
2253
+ let dark = false;
2254
+
2255
+ if (byteIndex < data.length) {
2256
+ dark = (((data[byteIndex] >>> bitIndex) & 1) === 1);
2257
+ }
2258
+
2259
+ matrix.set(row, col - c, dark);
2260
+ bitIndex--;
2261
+
2262
+ if (bitIndex === -1) {
2263
+ byteIndex++;
2264
+ bitIndex = 7;
2265
+ }
2266
+ }
2267
+ }
2268
+
2269
+ row += inc;
2270
+
2271
+ if (row < 0 || size <= row) {
2272
+ row -= inc;
2273
+ inc = -inc;
2274
+ break
2275
+ }
2276
+ }
2277
+ }
2278
+ }
2279
+
2280
+ /**
2281
+ * Create encoded codewords from data input
2282
+ *
2283
+ * @param {Number} version QR Code version
2284
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2285
+ * @param {ByteData} data Data input
2286
+ * @return {Uint8Array} Buffer containing encoded codewords
2287
+ */
2288
+ function createData (version, errorCorrectionLevel, segments) {
2289
+ // Prepare data buffer
2290
+ const buffer = new BitBuffer();
2291
+
2292
+ segments.forEach(function (data) {
2293
+ // prefix data with mode indicator (4 bits)
2294
+ buffer.put(data.mode.bit, 4);
2295
+
2296
+ // Prefix data with character count indicator.
2297
+ // The character count indicator is a string of bits that represents the
2298
+ // number of characters that are being encoded.
2299
+ // The character count indicator must be placed after the mode indicator
2300
+ // and must be a certain number of bits long, depending on the QR version
2301
+ // and data mode
2302
+ // @see {@link Mode.getCharCountIndicator}.
2303
+ buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version));
2304
+
2305
+ // add binary data sequence to buffer
2306
+ data.write(buffer);
2307
+ });
2308
+
2309
+ // Calculate required number of bits
2310
+ const totalCodewords = Utils$1.getSymbolTotalCodewords(version);
2311
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
2312
+ const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
2313
+
2314
+ // Add a terminator.
2315
+ // If the bit string is shorter than the total number of required bits,
2316
+ // a terminator of up to four 0s must be added to the right side of the string.
2317
+ // If the bit string is more than four bits shorter than the required number of bits,
2318
+ // add four 0s to the end.
2319
+ if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
2320
+ buffer.put(0, 4);
2321
+ }
2322
+
2323
+ // If the bit string is fewer than four bits shorter, add only the number of 0s that
2324
+ // are needed to reach the required number of bits.
2325
+
2326
+ // After adding the terminator, if the number of bits in the string is not a multiple of 8,
2327
+ // pad the string on the right with 0s to make the string's length a multiple of 8.
2328
+ while (buffer.getLengthInBits() % 8 !== 0) {
2329
+ buffer.putBit(0);
2330
+ }
2331
+
2332
+ // Add pad bytes if the string is still shorter than the total number of required bits.
2333
+ // Extend the buffer to fill the data capacity of the symbol corresponding to
2334
+ // the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC)
2335
+ // and 00010001 (0x11) alternately.
2336
+ const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8;
2337
+ for (let i = 0; i < remainingByte; i++) {
2338
+ buffer.put(i % 2 ? 0x11 : 0xEC, 8);
2339
+ }
2340
+
2341
+ return createCodewords(buffer, version, errorCorrectionLevel)
2342
+ }
2343
+
2344
+ /**
2345
+ * Encode input data with Reed-Solomon and return codewords with
2346
+ * relative error correction bits
2347
+ *
2348
+ * @param {BitBuffer} bitBuffer Data to encode
2349
+ * @param {Number} version QR Code version
2350
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2351
+ * @return {Uint8Array} Buffer containing encoded codewords
2352
+ */
2353
+ function createCodewords (bitBuffer, version, errorCorrectionLevel) {
2354
+ // Total codewords for this QR code version (Data + Error correction)
2355
+ const totalCodewords = Utils$1.getSymbolTotalCodewords(version);
2356
+
2357
+ // Total number of error correction codewords
2358
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
2359
+
2360
+ // Total number of data codewords
2361
+ const dataTotalCodewords = totalCodewords - ecTotalCodewords;
2362
+
2363
+ // Total number of blocks
2364
+ const ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel);
2365
+
2366
+ // Calculate how many blocks each group should contain
2367
+ const blocksInGroup2 = totalCodewords % ecTotalBlocks;
2368
+ const blocksInGroup1 = ecTotalBlocks - blocksInGroup2;
2369
+
2370
+ const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks);
2371
+
2372
+ const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks);
2373
+ const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1;
2374
+
2375
+ // Number of EC codewords is the same for both groups
2376
+ const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1;
2377
+
2378
+ // Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount
2379
+ const rs = new ReedSolomonEncoder(ecCount);
2380
+
2381
+ let offset = 0;
2382
+ const dcData = new Array(ecTotalBlocks);
2383
+ const ecData = new Array(ecTotalBlocks);
2384
+ let maxDataSize = 0;
2385
+ const buffer = new Uint8Array(bitBuffer.buffer);
2386
+
2387
+ // Divide the buffer into the required number of blocks
2388
+ for (let b = 0; b < ecTotalBlocks; b++) {
2389
+ const dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2;
2390
+
2391
+ // extract a block of data from buffer
2392
+ dcData[b] = buffer.slice(offset, offset + dataSize);
2393
+
2394
+ // Calculate EC codewords for this data block
2395
+ ecData[b] = rs.encode(dcData[b]);
2396
+
2397
+ offset += dataSize;
2398
+ maxDataSize = Math.max(maxDataSize, dataSize);
2399
+ }
2400
+
2401
+ // Create final data
2402
+ // Interleave the data and error correction codewords from each block
2403
+ const data = new Uint8Array(totalCodewords);
2404
+ let index = 0;
2405
+ let i, r;
2406
+
2407
+ // Add data codewords
2408
+ for (i = 0; i < maxDataSize; i++) {
2409
+ for (r = 0; r < ecTotalBlocks; r++) {
2410
+ if (i < dcData[r].length) {
2411
+ data[index++] = dcData[r][i];
2412
+ }
2413
+ }
2414
+ }
2415
+
2416
+ // Apped EC codewords
2417
+ for (i = 0; i < ecCount; i++) {
2418
+ for (r = 0; r < ecTotalBlocks; r++) {
2419
+ data[index++] = ecData[r][i];
2420
+ }
2421
+ }
2422
+
2423
+ return data
2424
+ }
2425
+
2426
+ /**
2427
+ * Build QR Code symbol
2428
+ *
2429
+ * @param {String} data Input string
2430
+ * @param {Number} version QR Code version
2431
+ * @param {ErrorCorretionLevel} errorCorrectionLevel Error level
2432
+ * @param {MaskPattern} maskPattern Mask pattern
2433
+ * @return {Object} Object containing symbol data
2434
+ */
2435
+ function createSymbol (data, version, errorCorrectionLevel, maskPattern) {
2436
+ let segments;
2437
+
2438
+ if (Array.isArray(data)) {
2439
+ segments = Segments.fromArray(data);
2440
+ } else if (typeof data === 'string') {
2441
+ let estimatedVersion = version;
2442
+
2443
+ if (!estimatedVersion) {
2444
+ const rawSegments = Segments.rawSplit(data);
2445
+
2446
+ // Estimate best version that can contain raw splitted segments
2447
+ estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel);
2448
+ }
2449
+
2450
+ // Build optimized segments
2451
+ // If estimated version is undefined, try with the highest version
2452
+ segments = Segments.fromString(data, estimatedVersion || 40);
2453
+ } else {
2454
+ throw new Error('Invalid data')
2455
+ }
2456
+
2457
+ // Get the min version that can contain data
2458
+ const bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel);
2459
+
2460
+ // If no version is found, data cannot be stored
2461
+ if (!bestVersion) {
2462
+ throw new Error('The amount of data is too big to be stored in a QR Code')
2463
+ }
2464
+
2465
+ // If not specified, use min version as default
2466
+ if (!version) {
2467
+ version = bestVersion;
2468
+
2469
+ // Check if the specified version can contain the data
2470
+ } else if (version < bestVersion) {
2471
+ throw new Error('\n' +
2472
+ 'The chosen QR Code version cannot contain this amount of data.\n' +
2473
+ 'Minimum version required to store current data is: ' + bestVersion + '.\n'
2474
+ )
2475
+ }
2476
+
2477
+ const dataBits = createData(version, errorCorrectionLevel, segments);
2478
+
2479
+ // Allocate matrix buffer
2480
+ const moduleCount = Utils$1.getSymbolSize(version);
2481
+ const modules = new BitMatrix(moduleCount);
2482
+
2483
+ // Add function modules
2484
+ setupFinderPattern(modules, version);
2485
+ setupTimingPattern(modules);
2486
+ setupAlignmentPattern(modules, version);
2487
+
2488
+ // Add temporary dummy bits for format info just to set them as reserved.
2489
+ // This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask}
2490
+ // since the masking operation must be performed only on the encoding region.
2491
+ // These blocks will be replaced with correct values later in code.
2492
+ setupFormatInfo(modules, errorCorrectionLevel, 0);
2493
+
2494
+ if (version >= 7) {
2495
+ setupVersionInfo(modules, version);
2496
+ }
2497
+
2498
+ // Add data codewords
2499
+ setupData(modules, dataBits);
2500
+
2501
+ if (isNaN(maskPattern)) {
2502
+ // Find best mask pattern
2503
+ maskPattern = MaskPattern.getBestMask(modules,
2504
+ setupFormatInfo.bind(null, modules, errorCorrectionLevel));
2505
+ }
2506
+
2507
+ // Apply mask pattern
2508
+ MaskPattern.applyMask(maskPattern, modules);
2509
+
2510
+ // Replace format info bits with correct values
2511
+ setupFormatInfo(modules, errorCorrectionLevel, maskPattern);
2512
+
2513
+ return {
2514
+ modules: modules,
2515
+ version: version,
2516
+ errorCorrectionLevel: errorCorrectionLevel,
2517
+ maskPattern: maskPattern,
2518
+ segments: segments
2519
+ }
2520
+ }
2521
+
2522
+ /**
2523
+ * QR Code
2524
+ *
2525
+ * @param {String | Array} data Input data
2526
+ * @param {Object} options Optional configurations
2527
+ * @param {Number} options.version QR Code version
2528
+ * @param {String} options.errorCorrectionLevel Error correction level
2529
+ * @param {Function} options.toSJISFunc Helper func to convert utf8 to sjis
2530
+ */
2531
+ qrcode.create = function create (data, options) {
2532
+ if (typeof data === 'undefined' || data === '') {
2533
+ throw new Error('No input text')
2534
+ }
2535
+
2536
+ let errorCorrectionLevel = ECLevel.M;
2537
+ let version;
2538
+ let mask;
2539
+
2540
+ if (typeof options !== 'undefined') {
2541
+ // Use higher error correction level as default
2542
+ errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M);
2543
+ version = Version.from(options.version);
2544
+ mask = MaskPattern.from(options.maskPattern);
2545
+
2546
+ if (options.toSJISFunc) {
2547
+ Utils$1.setToSJISFunction(options.toSJISFunc);
2548
+ }
2549
+ }
2550
+
2551
+ return createSymbol(data, version, errorCorrectionLevel, mask)
2552
+ };
2553
+
2554
+ var canvas = {};
2555
+
2556
+ var utils = {};
2557
+
2558
+ (function (exports$1) {
2559
+ function hex2rgba (hex) {
2560
+ if (typeof hex === 'number') {
2561
+ hex = hex.toString();
2562
+ }
2563
+
2564
+ if (typeof hex !== 'string') {
2565
+ throw new Error('Color should be defined as hex string')
2566
+ }
2567
+
2568
+ let hexCode = hex.slice().replace('#', '').split('');
2569
+ if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {
2570
+ throw new Error('Invalid hex color: ' + hex)
2571
+ }
2572
+
2573
+ // Convert from short to long form (fff -> ffffff)
2574
+ if (hexCode.length === 3 || hexCode.length === 4) {
2575
+ hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) {
2576
+ return [c, c]
2577
+ }));
2578
+ }
2579
+
2580
+ // Add default alpha value
2581
+ if (hexCode.length === 6) hexCode.push('F', 'F');
2582
+
2583
+ const hexValue = parseInt(hexCode.join(''), 16);
2584
+
2585
+ return {
2586
+ r: (hexValue >> 24) & 255,
2587
+ g: (hexValue >> 16) & 255,
2588
+ b: (hexValue >> 8) & 255,
2589
+ a: hexValue & 255,
2590
+ hex: '#' + hexCode.slice(0, 6).join('')
2591
+ }
2592
+ }
2593
+
2594
+ exports$1.getOptions = function getOptions (options) {
2595
+ if (!options) options = {};
2596
+ if (!options.color) options.color = {};
2597
+
2598
+ const margin = typeof options.margin === 'undefined' ||
2599
+ options.margin === null ||
2600
+ options.margin < 0
2601
+ ? 4
2602
+ : options.margin;
2603
+
2604
+ const width = options.width && options.width >= 21 ? options.width : undefined;
2605
+ const scale = options.scale || 4;
2606
+
2607
+ return {
2608
+ width: width,
2609
+ scale: width ? 4 : scale,
2610
+ margin: margin,
2611
+ color: {
2612
+ dark: hex2rgba(options.color.dark || '#000000ff'),
2613
+ light: hex2rgba(options.color.light || '#ffffffff')
2614
+ },
2615
+ type: options.type,
2616
+ rendererOpts: options.rendererOpts || {}
2617
+ }
2618
+ };
2619
+
2620
+ exports$1.getScale = function getScale (qrSize, opts) {
2621
+ return opts.width && opts.width >= qrSize + opts.margin * 2
2622
+ ? opts.width / (qrSize + opts.margin * 2)
2623
+ : opts.scale
2624
+ };
2625
+
2626
+ exports$1.getImageWidth = function getImageWidth (qrSize, opts) {
2627
+ const scale = exports$1.getScale(qrSize, opts);
2628
+ return Math.floor((qrSize + opts.margin * 2) * scale)
2629
+ };
2630
+
2631
+ exports$1.qrToImageData = function qrToImageData (imgData, qr, opts) {
2632
+ const size = qr.modules.size;
2633
+ const data = qr.modules.data;
2634
+ const scale = exports$1.getScale(size, opts);
2635
+ const symbolSize = Math.floor((size + opts.margin * 2) * scale);
2636
+ const scaledMargin = opts.margin * scale;
2637
+ const palette = [opts.color.light, opts.color.dark];
2638
+
2639
+ for (let i = 0; i < symbolSize; i++) {
2640
+ for (let j = 0; j < symbolSize; j++) {
2641
+ let posDst = (i * symbolSize + j) * 4;
2642
+ let pxColor = opts.color.light;
2643
+
2644
+ if (i >= scaledMargin && j >= scaledMargin &&
2645
+ i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
2646
+ const iSrc = Math.floor((i - scaledMargin) / scale);
2647
+ const jSrc = Math.floor((j - scaledMargin) / scale);
2648
+ pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0];
2649
+ }
2650
+
2651
+ imgData[posDst++] = pxColor.r;
2652
+ imgData[posDst++] = pxColor.g;
2653
+ imgData[posDst++] = pxColor.b;
2654
+ imgData[posDst] = pxColor.a;
2655
+ }
2656
+ }
2657
+ };
2658
+ } (utils));
2659
+
2660
+ (function (exports$1) {
2661
+ const Utils = utils;
2662
+
2663
+ function clearCanvas (ctx, canvas, size) {
2664
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
2665
+
2666
+ if (!canvas.style) canvas.style = {};
2667
+ canvas.height = size;
2668
+ canvas.width = size;
2669
+ canvas.style.height = size + 'px';
2670
+ canvas.style.width = size + 'px';
2671
+ }
2672
+
2673
+ function getCanvasElement () {
2674
+ try {
2675
+ return document.createElement('canvas')
2676
+ } catch (e) {
2677
+ throw new Error('You need to specify a canvas element')
2678
+ }
2679
+ }
2680
+
2681
+ exports$1.render = function render (qrData, canvas, options) {
2682
+ let opts = options;
2683
+ let canvasEl = canvas;
2684
+
2685
+ if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
2686
+ opts = canvas;
2687
+ canvas = undefined;
2688
+ }
2689
+
2690
+ if (!canvas) {
2691
+ canvasEl = getCanvasElement();
2692
+ }
2693
+
2694
+ opts = Utils.getOptions(opts);
2695
+ const size = Utils.getImageWidth(qrData.modules.size, opts);
2696
+
2697
+ const ctx = canvasEl.getContext('2d');
2698
+ const image = ctx.createImageData(size, size);
2699
+ Utils.qrToImageData(image.data, qrData, opts);
2700
+
2701
+ clearCanvas(ctx, canvasEl, size);
2702
+ ctx.putImageData(image, 0, 0);
2703
+
2704
+ return canvasEl
2705
+ };
2706
+
2707
+ exports$1.renderToDataURL = function renderToDataURL (qrData, canvas, options) {
2708
+ let opts = options;
2709
+
2710
+ if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
2711
+ opts = canvas;
2712
+ canvas = undefined;
2713
+ }
2714
+
2715
+ if (!opts) opts = {};
2716
+
2717
+ const canvasEl = exports$1.render(qrData, canvas, opts);
2718
+
2719
+ const type = opts.type || 'image/png';
2720
+ const rendererOpts = opts.rendererOpts || {};
2721
+
2722
+ return canvasEl.toDataURL(type, rendererOpts.quality)
2723
+ };
2724
+ } (canvas));
2725
+
2726
+ var svgTag = {};
2727
+
2728
+ const Utils = utils;
2729
+
2730
+ function getColorAttrib (color, attrib) {
2731
+ const alpha = color.a / 255;
2732
+ const str = attrib + '="' + color.hex + '"';
2733
+
2734
+ return alpha < 1
2735
+ ? str + ' ' + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"'
2736
+ : str
2737
+ }
2738
+
2739
+ function svgCmd (cmd, x, y) {
2740
+ let str = cmd + x;
2741
+ if (typeof y !== 'undefined') str += ' ' + y;
2742
+
2743
+ return str
2744
+ }
2745
+
2746
+ function qrToPath (data, size, margin) {
2747
+ let path = '';
2748
+ let moveBy = 0;
2749
+ let newRow = false;
2750
+ let lineLength = 0;
2751
+
2752
+ for (let i = 0; i < data.length; i++) {
2753
+ const col = Math.floor(i % size);
2754
+ const row = Math.floor(i / size);
2755
+
2756
+ if (!col && !newRow) newRow = true;
2757
+
2758
+ if (data[i]) {
2759
+ lineLength++;
2760
+
2761
+ if (!(i > 0 && col > 0 && data[i - 1])) {
2762
+ path += newRow
2763
+ ? svgCmd('M', col + margin, 0.5 + row + margin)
2764
+ : svgCmd('m', moveBy, 0);
2765
+
2766
+ moveBy = 0;
2767
+ newRow = false;
2768
+ }
2769
+
2770
+ if (!(col + 1 < size && data[i + 1])) {
2771
+ path += svgCmd('h', lineLength);
2772
+ lineLength = 0;
2773
+ }
2774
+ } else {
2775
+ moveBy++;
2776
+ }
2777
+ }
2778
+
2779
+ return path
2780
+ }
2781
+
2782
+ svgTag.render = function render (qrData, options, cb) {
2783
+ const opts = Utils.getOptions(options);
2784
+ const size = qrData.modules.size;
2785
+ const data = qrData.modules.data;
2786
+ const qrcodesize = size + opts.margin * 2;
2787
+
2788
+ const bg = !opts.color.light.a
2789
+ ? ''
2790
+ : '<path ' + getColorAttrib(opts.color.light, 'fill') +
2791
+ ' d="M0 0h' + qrcodesize + 'v' + qrcodesize + 'H0z"/>';
2792
+
2793
+ const path =
2794
+ '<path ' + getColorAttrib(opts.color.dark, 'stroke') +
2795
+ ' d="' + qrToPath(data, size, opts.margin) + '"/>';
2796
+
2797
+ const viewBox = 'viewBox="' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '"';
2798
+
2799
+ const width = !opts.width ? '' : 'width="' + opts.width + '" height="' + opts.width + '" ';
2800
+
2801
+ const svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path + '</svg>\n';
2802
+
2803
+ if (typeof cb === 'function') {
2804
+ cb(null, svgTag);
2805
+ }
2806
+
2807
+ return svgTag
2808
+ };
2809
+
2810
+ const canPromise = canPromise$1;
2811
+
2812
+ const QRCode = qrcode;
2813
+ const CanvasRenderer = canvas;
2814
+ const SvgRenderer = svgTag;
2815
+
2816
+ function renderCanvas (renderFunc, canvas, text, opts, cb) {
2817
+ const args = [].slice.call(arguments, 1);
2818
+ const argsNum = args.length;
2819
+ const isLastArgCb = typeof args[argsNum - 1] === 'function';
2820
+
2821
+ if (!isLastArgCb && !canPromise()) {
2822
+ throw new Error('Callback required as last argument')
2823
+ }
2824
+
2825
+ if (isLastArgCb) {
2826
+ if (argsNum < 2) {
2827
+ throw new Error('Too few arguments provided')
2828
+ }
2829
+
2830
+ if (argsNum === 2) {
2831
+ cb = text;
2832
+ text = canvas;
2833
+ canvas = opts = undefined;
2834
+ } else if (argsNum === 3) {
2835
+ if (canvas.getContext && typeof cb === 'undefined') {
2836
+ cb = opts;
2837
+ opts = undefined;
2838
+ } else {
2839
+ cb = opts;
2840
+ opts = text;
2841
+ text = canvas;
2842
+ canvas = undefined;
2843
+ }
2844
+ }
2845
+ } else {
2846
+ if (argsNum < 1) {
2847
+ throw new Error('Too few arguments provided')
2848
+ }
2849
+
2850
+ if (argsNum === 1) {
2851
+ text = canvas;
2852
+ canvas = opts = undefined;
2853
+ } else if (argsNum === 2 && !canvas.getContext) {
2854
+ opts = text;
2855
+ text = canvas;
2856
+ canvas = undefined;
2857
+ }
2858
+
2859
+ return new Promise(function (resolve, reject) {
2860
+ try {
2861
+ const data = QRCode.create(text, opts);
2862
+ resolve(renderFunc(data, canvas, opts));
2863
+ } catch (e) {
2864
+ reject(e);
2865
+ }
2866
+ })
2867
+ }
2868
+
2869
+ try {
2870
+ const data = QRCode.create(text, opts);
2871
+ cb(null, renderFunc(data, canvas, opts));
2872
+ } catch (e) {
2873
+ cb(e);
2874
+ }
2875
+ }
2876
+
2877
+ var create = browser$1.create = QRCode.create;
2878
+ var toCanvas = browser$1.toCanvas = renderCanvas.bind(null, CanvasRenderer.render);
2879
+ var toDataURL = browser$1.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL);
2880
+
2881
+ // only svg for now.
2882
+ var toString = browser$1.toString = renderCanvas.bind(null, function (data, _, opts) {
2883
+ return SvgRenderer.render(data, opts)
2884
+ });
2885
+
2886
+ const browser = /*#__PURE__*/_mergeNamespaces({
2887
+ __proto__: null,
2888
+ create,
2889
+ default: browser$1,
2890
+ toCanvas,
2891
+ toDataURL,
2892
+ toString
2893
+ }, [browser$1]);
2894
+
2895
+ export { browser as b };