react-id-card-generator 1.0.0 → 1.0.2

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.
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var _commonjsHelpers = require('../../../_virtual/_commonjsHelpers.js');
4
- var qrious = require('../../../_virtual/qrious.js');
3
+ var qrious$1 = require('../../../_virtual/qrious2.js');
5
4
 
6
5
  /*
7
6
  * QRious v4.0.2
@@ -21,2354 +20,2359 @@ var qrious = require('../../../_virtual/qrious.js');
21
20
  * You should have received a copy of the GNU General Public License
22
21
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
22
  */
24
-
25
- (function (module, exports$1) {
26
- (function (global, factory) {
27
- module.exports = factory() ;
28
- }(_commonjsHelpers.commonjsGlobal, (function () {
29
- /*
30
- * Copyright (C) 2017 Alasdair Mercer, !ninja
31
- *
32
- * Permission is hereby granted, free of charge, to any person obtaining a copy
33
- * of this software and associated documentation files (the "Software"), to deal
34
- * in the Software without restriction, including without limitation the rights
35
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
36
- * copies of the Software, and to permit persons to whom the Software is
37
- * furnished to do so, subject to the following conditions:
38
- *
39
- * The above copyright notice and this permission notice shall be included in all
40
- * copies or substantial portions of the Software.
41
- *
42
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
45
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
46
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
47
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
48
- * SOFTWARE.
49
- */
50
-
51
- /**
52
- * A bare-bones constructor for surrogate prototype swapping.
53
- *
54
- * @private
55
- * @constructor
56
- */
57
- var Constructor = /* istanbul ignore next */ function() {};
58
- /**
59
- * A reference to <code>Object.prototype.hasOwnProperty</code>.
60
- *
61
- * @private
62
- * @type {Function}
63
- */
64
- var hasOwnProperty = Object.prototype.hasOwnProperty;
65
- /**
66
- * A reference to <code>Array.prototype.slice</code>.
67
- *
68
- * @private
69
- * @type {Function}
70
- */
71
- var slice = Array.prototype.slice;
72
-
73
- /**
74
- * Creates an object which inherits the given <code>prototype</code>.
75
- *
76
- * Optionally, the created object can be extended further with the specified <code>properties</code>.
77
- *
78
- * @param {Object} prototype - the prototype to be inherited by the created object
79
- * @param {Object} [properties] - the optional properties to be extended by the created object
80
- * @return {Object} The newly created object.
81
- * @private
82
- */
83
- function createObject(prototype, properties) {
84
- var result;
85
- /* istanbul ignore next */
86
- if (typeof Object.create === 'function') {
87
- result = Object.create(prototype);
88
- } else {
89
- Constructor.prototype = prototype;
90
- result = new Constructor();
91
- Constructor.prototype = null;
92
- }
93
-
94
- if (properties) {
95
- extendObject(true, result, properties);
96
- }
97
-
98
- return result;
99
- }
100
-
101
- /**
102
- * Extends the constructor to which this method is associated with the <code>prototype</code> and/or
103
- * <code>statics</code> provided.
104
- *
105
- * If <code>name</code> is provided, it will be used as the class name and can be accessed via a special
106
- * <code>class_</code> property on the child constructor, otherwise the class name of the super constructor will be used
107
- * instead. The class name may also be used string representation for instances of the child constructor (via
108
- * <code>toString</code>), but this is not applicable to the <i>lite</i> version of Nevis.
109
- *
110
- * If <code>constructor</code> is provided, it will be used as the constructor for the child, otherwise a simple
111
- * constructor which only calls the super constructor will be used instead.
112
- *
113
- * The super constructor can be accessed via a special <code>super_</code> property on the child constructor.
114
- *
115
- * @param {string} [name=this.class_] - the class name to be used for the child constructor
116
- * @param {Function} [constructor] - the constructor for the child
117
- * @param {Object} [prototype] - the prototype properties to be defined for the child
118
- * @param {Object} [statics] - the static properties to be defined for the child
119
- * @return {Function} The child <code>constructor</code> provided or the one created if none was given.
120
- * @public
121
- */
122
- function extend(name, constructor, prototype, statics) {
123
- var superConstructor = this;
124
-
125
- if (typeof name !== 'string') {
126
- statics = prototype;
127
- prototype = constructor;
128
- constructor = name;
129
- name = null;
130
- }
131
-
132
- if (typeof constructor !== 'function') {
133
- statics = prototype;
134
- prototype = constructor;
135
- constructor = function() {
136
- return superConstructor.apply(this, arguments);
137
- };
138
- }
139
-
140
- extendObject(false, constructor, superConstructor, statics);
141
-
142
- constructor.prototype = createObject(superConstructor.prototype, prototype);
143
- constructor.prototype.constructor = constructor;
144
-
145
- constructor.class_ = name || superConstructor.class_;
146
- constructor.super_ = superConstructor;
147
-
148
- return constructor;
149
- }
150
-
151
- /**
152
- * Extends the specified <code>target</code> object with the properties in each of the <code>sources</code> provided.
153
- *
154
- * if any source is <code>null</code> it will be ignored.
155
- *
156
- * @param {boolean} own - <code>true</code> to only copy <b>own</b> properties from <code>sources</code> onto
157
- * <code>target</code>; otherwise <code>false</code>
158
- * @param {Object} target - the target object which should be extended
159
- * @param {...Object} [sources] - the source objects whose properties are to be copied onto <code>target</code>
160
- * @return {void}
161
- * @private
162
- */
163
- function extendObject(own, target, sources) {
164
- sources = slice.call(arguments, 2);
165
-
166
- var property;
167
- var source;
168
-
169
- for (var i = 0, length = sources.length; i < length; i++) {
170
- source = sources[i];
171
-
172
- for (property in source) {
173
- if (!own || hasOwnProperty.call(source, property)) {
174
- target[property] = source[property];
175
- }
176
- }
177
- }
178
- }
179
-
180
- var extend_1 = extend;
181
-
182
- /**
183
- * The base class from which all others should extend.
184
- *
185
- * @public
186
- * @constructor
187
- */
188
- function Nevis() {}
189
- Nevis.class_ = 'Nevis';
190
- Nevis.super_ = Object;
191
-
192
- /**
193
- * Extends the constructor to which this method is associated with the <code>prototype</code> and/or
194
- * <code>statics</code> provided.
195
- *
196
- * If <code>name</code> is provided, it will be used as the class name and can be accessed via a special
197
- * <code>class_</code> property on the child constructor, otherwise the class name of the super constructor will be used
198
- * instead. The class name may also be used string representation for instances of the child constructor (via
199
- * <code>toString</code>), but this is not applicable to the <i>lite</i> version of Nevis.
200
- *
201
- * If <code>constructor</code> is provided, it will be used as the constructor for the child, otherwise a simple
202
- * constructor which only calls the super constructor will be used instead.
203
- *
204
- * The super constructor can be accessed via a special <code>super_</code> property on the child constructor.
205
- *
206
- * @param {string} [name=this.class_] - the class name to be used for the child constructor
207
- * @param {Function} [constructor] - the constructor for the child
208
- * @param {Object} [prototype] - the prototype properties to be defined for the child
209
- * @param {Object} [statics] - the static properties to be defined for the child
210
- * @return {Function} The child <code>constructor</code> provided or the one created if none was given.
211
- * @public
212
- * @static
213
- * @memberof Nevis
214
- */
215
- Nevis.extend = extend_1;
216
-
217
- var nevis = Nevis;
218
-
219
- var lite = nevis;
220
-
221
- /**
222
- * Responsible for rendering a QR code {@link Frame} on a specific type of element.
223
- *
224
- * A renderer may be dependant on the rendering of another element, so the ordering of their execution is important.
225
- *
226
- * The rendering of a element can be deferred by disabling the renderer initially, however, any attempt get the element
227
- * from the renderer will result in it being immediately enabled and the element being rendered.
228
- *
229
- * @param {QRious} qrious - the {@link QRious} instance to be used
230
- * @param {*} element - the element onto which the QR code is to be rendered
231
- * @param {boolean} [enabled] - <code>true</code> this {@link Renderer} is enabled; otherwise <code>false</code>.
232
- * @public
233
- * @class
234
- * @extends Nevis
235
- */
236
- var Renderer = lite.extend(function(qrious, element, enabled) {
237
- /**
238
- * The {@link QRious} instance.
239
- *
240
- * @protected
241
- * @type {QRious}
242
- * @memberof Renderer#
243
- */
244
- this.qrious = qrious;
245
-
246
- /**
247
- * The element onto which this {@link Renderer} is rendering the QR code.
248
- *
249
- * @protected
250
- * @type {*}
251
- * @memberof Renderer#
252
- */
253
- this.element = element;
254
- this.element.qrious = qrious;
255
-
256
- /**
257
- * Whether this {@link Renderer} is enabled.
258
- *
259
- * @protected
260
- * @type {boolean}
261
- * @memberof Renderer#
262
- */
263
- this.enabled = Boolean(enabled);
264
- }, {
265
-
266
- /**
267
- * Draws the specified QR code <code>frame</code> on the underlying element.
268
- *
269
- * Implementations of {@link Renderer} <b>must</b> override this method with their own specific logic.
270
- *
271
- * @param {Frame} frame - the {@link Frame} to be drawn
272
- * @return {void}
273
- * @protected
274
- * @abstract
275
- * @memberof Renderer#
276
- */
277
- draw: function(frame) {},
278
-
279
- /**
280
- * Returns the element onto which this {@link Renderer} is rendering the QR code.
281
- *
282
- * If this method is called while this {@link Renderer} is disabled, it will be immediately enabled and rendered
283
- * before the element is returned.
284
- *
285
- * @return {*} The element.
286
- * @public
287
- * @memberof Renderer#
288
- */
289
- getElement: function() {
290
- if (!this.enabled) {
291
- this.enabled = true;
292
- this.render();
293
- }
294
-
295
- return this.element;
296
- },
297
-
298
- /**
299
- * Calculates the size (in pixel units) to represent an individual module within the QR code based on the
300
- * <code>frame</code> provided.
301
- *
302
- * Any configured padding will be excluded from the returned size.
303
- *
304
- * The returned value will be at least one, even in cases where the size of the QR code does not fit its contents.
305
- * This is done so that the inevitable clipping is handled more gracefully since this way at least something is
306
- * displayed instead of just a blank space filled by the background color.
307
- *
308
- * @param {Frame} frame - the {@link Frame} from which the module size is to be derived
309
- * @return {number} The pixel size for each module in the QR code which will be no less than one.
310
- * @protected
311
- * @memberof Renderer#
312
- */
313
- getModuleSize: function(frame) {
314
- var qrious = this.qrious;
315
- var padding = qrious.padding || 0;
316
- var pixels = Math.floor((qrious.size - (padding * 2)) / frame.width);
317
-
318
- return Math.max(1, pixels);
319
- },
320
-
321
- /**
322
- * Calculates the offset/padding (in pixel units) to be inserted before the QR code based on the <code>frame</code>
323
- * provided.
324
- *
325
- * The returned value will be zero if there is no available offset or if the size of the QR code does not fit its
326
- * contents. It will never be a negative value. This is done so that the inevitable clipping appears more naturally
327
- * and it is not clipped from all directions.
328
- *
329
- * @param {Frame} frame - the {@link Frame} from which the offset is to be derived
330
- * @return {number} The pixel offset for the QR code which will be no less than zero.
331
- * @protected
332
- * @memberof Renderer#
333
- */
334
- getOffset: function(frame) {
335
- var qrious = this.qrious;
336
- var padding = qrious.padding;
337
-
338
- if (padding != null) {
339
- return padding;
340
- }
341
-
342
- var moduleSize = this.getModuleSize(frame);
343
- var offset = Math.floor((qrious.size - (moduleSize * frame.width)) / 2);
344
-
345
- return Math.max(0, offset);
346
- },
347
-
348
- /**
349
- * Renders a QR code on the underlying element based on the <code>frame</code> provided.
350
- *
351
- * @param {Frame} frame - the {@link Frame} to be rendered
352
- * @return {void}
353
- * @public
354
- * @memberof Renderer#
355
- */
356
- render: function(frame) {
357
- if (this.enabled) {
358
- this.resize();
359
- this.reset();
360
- this.draw(frame);
361
- }
362
- },
363
-
364
- /**
365
- * Resets the underlying element, effectively clearing any previously rendered QR code.
366
- *
367
- * Implementations of {@link Renderer} <b>must</b> override this method with their own specific logic.
368
- *
369
- * @return {void}
370
- * @protected
371
- * @abstract
372
- * @memberof Renderer#
373
- */
374
- reset: function() {},
375
-
376
- /**
377
- * Ensures that the size of the underlying element matches that defined on the associated {@link QRious} instance.
378
- *
379
- * Implementations of {@link Renderer} <b>must</b> override this method with their own specific logic.
380
- *
381
- * @return {void}
382
- * @protected
383
- * @abstract
384
- * @memberof Renderer#
385
- */
386
- resize: function() {}
387
-
388
- });
389
-
390
- var Renderer_1 = Renderer;
391
-
392
- /**
393
- * An implementation of {@link Renderer} for working with <code>canvas</code> elements.
394
- *
395
- * @public
396
- * @class
397
- * @extends Renderer
398
- */
399
- var CanvasRenderer = Renderer_1.extend({
400
-
401
- /**
402
- * @override
403
- */
404
- draw: function(frame) {
405
- var i, j;
406
- var qrious = this.qrious;
407
- var moduleSize = this.getModuleSize(frame);
408
- var offset = this.getOffset(frame);
409
- var context = this.element.getContext('2d');
410
-
411
- context.fillStyle = qrious.foreground;
412
- context.globalAlpha = qrious.foregroundAlpha;
413
-
414
- for (i = 0; i < frame.width; i++) {
415
- for (j = 0; j < frame.width; j++) {
416
- if (frame.buffer[(j * frame.width) + i]) {
417
- context.fillRect((moduleSize * i) + offset, (moduleSize * j) + offset, moduleSize, moduleSize);
418
- }
419
- }
420
- }
421
- },
422
-
423
- /**
424
- * @override
425
- */
426
- reset: function() {
427
- var qrious = this.qrious;
428
- var context = this.element.getContext('2d');
429
- var size = qrious.size;
430
-
431
- context.lineWidth = 1;
432
- context.clearRect(0, 0, size, size);
433
- context.fillStyle = qrious.background;
434
- context.globalAlpha = qrious.backgroundAlpha;
435
- context.fillRect(0, 0, size, size);
436
- },
437
-
438
- /**
439
- * @override
440
- */
441
- resize: function() {
442
- var element = this.element;
443
-
444
- element.width = element.height = this.qrious.size;
445
- }
446
-
447
- });
448
-
449
- var CanvasRenderer_1 = CanvasRenderer;
450
-
451
- /* eslint no-multi-spaces: "off" */
452
-
453
-
454
-
455
- /**
456
- * Contains alignment pattern information.
457
- *
458
- * @public
459
- * @class
460
- * @extends Nevis
461
- */
462
- var Alignment = lite.extend(null, {
463
-
464
- /**
465
- * The alignment pattern block.
466
- *
467
- * @public
468
- * @static
469
- * @type {number[]}
470
- * @memberof Alignment
471
- */
472
- BLOCK: [
473
- 0, 11, 15, 19, 23, 27, 31,
474
- 16, 18, 20, 22, 24, 26, 28, 20, 22, 24, 24, 26, 28, 28, 22, 24, 24,
475
- 26, 26, 28, 28, 24, 24, 26, 26, 26, 28, 28, 24, 26, 26, 26, 28, 28
476
- ]
477
-
478
- });
479
-
480
- var Alignment_1 = Alignment;
481
-
482
- /* eslint no-multi-spaces: "off" */
483
-
484
-
485
-
486
- /**
487
- * Contains error correction information.
488
- *
489
- * @public
490
- * @class
491
- * @extends Nevis
492
- */
493
- var ErrorCorrection = lite.extend(null, {
494
-
495
- /**
496
- * The error correction blocks.
497
- *
498
- * There are four elements per version. The first two indicate the number of blocks, then the data width, and finally
499
- * the ECC width.
500
- *
501
- * @public
502
- * @static
503
- * @type {number[]}
504
- * @memberof ErrorCorrection
505
- */
506
- BLOCKS: [
507
- 1, 0, 19, 7, 1, 0, 16, 10, 1, 0, 13, 13, 1, 0, 9, 17,
508
- 1, 0, 34, 10, 1, 0, 28, 16, 1, 0, 22, 22, 1, 0, 16, 28,
509
- 1, 0, 55, 15, 1, 0, 44, 26, 2, 0, 17, 18, 2, 0, 13, 22,
510
- 1, 0, 80, 20, 2, 0, 32, 18, 2, 0, 24, 26, 4, 0, 9, 16,
511
- 1, 0, 108, 26, 2, 0, 43, 24, 2, 2, 15, 18, 2, 2, 11, 22,
512
- 2, 0, 68, 18, 4, 0, 27, 16, 4, 0, 19, 24, 4, 0, 15, 28,
513
- 2, 0, 78, 20, 4, 0, 31, 18, 2, 4, 14, 18, 4, 1, 13, 26,
514
- 2, 0, 97, 24, 2, 2, 38, 22, 4, 2, 18, 22, 4, 2, 14, 26,
515
- 2, 0, 116, 30, 3, 2, 36, 22, 4, 4, 16, 20, 4, 4, 12, 24,
516
- 2, 2, 68, 18, 4, 1, 43, 26, 6, 2, 19, 24, 6, 2, 15, 28,
517
- 4, 0, 81, 20, 1, 4, 50, 30, 4, 4, 22, 28, 3, 8, 12, 24,
518
- 2, 2, 92, 24, 6, 2, 36, 22, 4, 6, 20, 26, 7, 4, 14, 28,
519
- 4, 0, 107, 26, 8, 1, 37, 22, 8, 4, 20, 24, 12, 4, 11, 22,
520
- 3, 1, 115, 30, 4, 5, 40, 24, 11, 5, 16, 20, 11, 5, 12, 24,
521
- 5, 1, 87, 22, 5, 5, 41, 24, 5, 7, 24, 30, 11, 7, 12, 24,
522
- 5, 1, 98, 24, 7, 3, 45, 28, 15, 2, 19, 24, 3, 13, 15, 30,
523
- 1, 5, 107, 28, 10, 1, 46, 28, 1, 15, 22, 28, 2, 17, 14, 28,
524
- 5, 1, 120, 30, 9, 4, 43, 26, 17, 1, 22, 28, 2, 19, 14, 28,
525
- 3, 4, 113, 28, 3, 11, 44, 26, 17, 4, 21, 26, 9, 16, 13, 26,
526
- 3, 5, 107, 28, 3, 13, 41, 26, 15, 5, 24, 30, 15, 10, 15, 28,
527
- 4, 4, 116, 28, 17, 0, 42, 26, 17, 6, 22, 28, 19, 6, 16, 30,
528
- 2, 7, 111, 28, 17, 0, 46, 28, 7, 16, 24, 30, 34, 0, 13, 24,
529
- 4, 5, 121, 30, 4, 14, 47, 28, 11, 14, 24, 30, 16, 14, 15, 30,
530
- 6, 4, 117, 30, 6, 14, 45, 28, 11, 16, 24, 30, 30, 2, 16, 30,
531
- 8, 4, 106, 26, 8, 13, 47, 28, 7, 22, 24, 30, 22, 13, 15, 30,
532
- 10, 2, 114, 28, 19, 4, 46, 28, 28, 6, 22, 28, 33, 4, 16, 30,
533
- 8, 4, 122, 30, 22, 3, 45, 28, 8, 26, 23, 30, 12, 28, 15, 30,
534
- 3, 10, 117, 30, 3, 23, 45, 28, 4, 31, 24, 30, 11, 31, 15, 30,
535
- 7, 7, 116, 30, 21, 7, 45, 28, 1, 37, 23, 30, 19, 26, 15, 30,
536
- 5, 10, 115, 30, 19, 10, 47, 28, 15, 25, 24, 30, 23, 25, 15, 30,
537
- 13, 3, 115, 30, 2, 29, 46, 28, 42, 1, 24, 30, 23, 28, 15, 30,
538
- 17, 0, 115, 30, 10, 23, 46, 28, 10, 35, 24, 30, 19, 35, 15, 30,
539
- 17, 1, 115, 30, 14, 21, 46, 28, 29, 19, 24, 30, 11, 46, 15, 30,
540
- 13, 6, 115, 30, 14, 23, 46, 28, 44, 7, 24, 30, 59, 1, 16, 30,
541
- 12, 7, 121, 30, 12, 26, 47, 28, 39, 14, 24, 30, 22, 41, 15, 30,
542
- 6, 14, 121, 30, 6, 34, 47, 28, 46, 10, 24, 30, 2, 64, 15, 30,
543
- 17, 4, 122, 30, 29, 14, 46, 28, 49, 10, 24, 30, 24, 46, 15, 30,
544
- 4, 18, 122, 30, 13, 32, 46, 28, 48, 14, 24, 30, 42, 32, 15, 30,
545
- 20, 4, 117, 30, 40, 7, 47, 28, 43, 22, 24, 30, 10, 67, 15, 30,
546
- 19, 6, 118, 30, 18, 31, 47, 28, 34, 34, 24, 30, 20, 61, 15, 30
547
- ],
548
-
549
- /**
550
- * The final format bits with mask (level << 3 | mask).
551
- *
552
- * @public
553
- * @static
554
- * @type {number[]}
555
- * @memberof ErrorCorrection
556
- */
557
- FINAL_FORMAT: [
558
- // L
559
- 0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976,
560
- // M
561
- 0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0,
562
- // Q
563
- 0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed,
564
- // H
565
- 0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b
566
- ],
567
-
568
- /**
569
- * A map of human-readable ECC levels.
570
- *
571
- * @public
572
- * @static
573
- * @type {Object.<string, number>}
574
- * @memberof ErrorCorrection
575
- */
576
- LEVELS: {
577
- L: 1,
578
- M: 2,
579
- Q: 3,
580
- H: 4
581
- }
582
-
583
- });
584
-
585
- var ErrorCorrection_1 = ErrorCorrection;
586
-
587
- /**
588
- * Contains Galois field information.
589
- *
590
- * @public
591
- * @class
592
- * @extends Nevis
593
- */
594
- var Galois = lite.extend(null, {
595
-
596
- /**
597
- * The Galois field exponent table.
598
- *
599
- * @public
600
- * @static
601
- * @type {number[]}
602
- * @memberof Galois
603
- */
604
- EXPONENT: [
605
- 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1d, 0x3a, 0x74, 0xe8, 0xcd, 0x87, 0x13, 0x26,
606
- 0x4c, 0x98, 0x2d, 0x5a, 0xb4, 0x75, 0xea, 0xc9, 0x8f, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0,
607
- 0x9d, 0x27, 0x4e, 0x9c, 0x25, 0x4a, 0x94, 0x35, 0x6a, 0xd4, 0xb5, 0x77, 0xee, 0xc1, 0x9f, 0x23,
608
- 0x46, 0x8c, 0x05, 0x0a, 0x14, 0x28, 0x50, 0xa0, 0x5d, 0xba, 0x69, 0xd2, 0xb9, 0x6f, 0xde, 0xa1,
609
- 0x5f, 0xbe, 0x61, 0xc2, 0x99, 0x2f, 0x5e, 0xbc, 0x65, 0xca, 0x89, 0x0f, 0x1e, 0x3c, 0x78, 0xf0,
610
- 0xfd, 0xe7, 0xd3, 0xbb, 0x6b, 0xd6, 0xb1, 0x7f, 0xfe, 0xe1, 0xdf, 0xa3, 0x5b, 0xb6, 0x71, 0xe2,
611
- 0xd9, 0xaf, 0x43, 0x86, 0x11, 0x22, 0x44, 0x88, 0x0d, 0x1a, 0x34, 0x68, 0xd0, 0xbd, 0x67, 0xce,
612
- 0x81, 0x1f, 0x3e, 0x7c, 0xf8, 0xed, 0xc7, 0x93, 0x3b, 0x76, 0xec, 0xc5, 0x97, 0x33, 0x66, 0xcc,
613
- 0x85, 0x17, 0x2e, 0x5c, 0xb8, 0x6d, 0xda, 0xa9, 0x4f, 0x9e, 0x21, 0x42, 0x84, 0x15, 0x2a, 0x54,
614
- 0xa8, 0x4d, 0x9a, 0x29, 0x52, 0xa4, 0x55, 0xaa, 0x49, 0x92, 0x39, 0x72, 0xe4, 0xd5, 0xb7, 0x73,
615
- 0xe6, 0xd1, 0xbf, 0x63, 0xc6, 0x91, 0x3f, 0x7e, 0xfc, 0xe5, 0xd7, 0xb3, 0x7b, 0xf6, 0xf1, 0xff,
616
- 0xe3, 0xdb, 0xab, 0x4b, 0x96, 0x31, 0x62, 0xc4, 0x95, 0x37, 0x6e, 0xdc, 0xa5, 0x57, 0xae, 0x41,
617
- 0x82, 0x19, 0x32, 0x64, 0xc8, 0x8d, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0, 0xdd, 0xa7, 0x53, 0xa6,
618
- 0x51, 0xa2, 0x59, 0xb2, 0x79, 0xf2, 0xf9, 0xef, 0xc3, 0x9b, 0x2b, 0x56, 0xac, 0x45, 0x8a, 0x09,
619
- 0x12, 0x24, 0x48, 0x90, 0x3d, 0x7a, 0xf4, 0xf5, 0xf7, 0xf3, 0xfb, 0xeb, 0xcb, 0x8b, 0x0b, 0x16,
620
- 0x2c, 0x58, 0xb0, 0x7d, 0xfa, 0xe9, 0xcf, 0x83, 0x1b, 0x36, 0x6c, 0xd8, 0xad, 0x47, 0x8e, 0x00
621
- ],
622
-
623
- /**
624
- * The Galois field log table.
625
- *
626
- * @public
627
- * @static
628
- * @type {number[]}
629
- * @memberof Galois
630
- */
631
- LOG: [
632
- 0xff, 0x00, 0x01, 0x19, 0x02, 0x32, 0x1a, 0xc6, 0x03, 0xdf, 0x33, 0xee, 0x1b, 0x68, 0xc7, 0x4b,
633
- 0x04, 0x64, 0xe0, 0x0e, 0x34, 0x8d, 0xef, 0x81, 0x1c, 0xc1, 0x69, 0xf8, 0xc8, 0x08, 0x4c, 0x71,
634
- 0x05, 0x8a, 0x65, 0x2f, 0xe1, 0x24, 0x0f, 0x21, 0x35, 0x93, 0x8e, 0xda, 0xf0, 0x12, 0x82, 0x45,
635
- 0x1d, 0xb5, 0xc2, 0x7d, 0x6a, 0x27, 0xf9, 0xb9, 0xc9, 0x9a, 0x09, 0x78, 0x4d, 0xe4, 0x72, 0xa6,
636
- 0x06, 0xbf, 0x8b, 0x62, 0x66, 0xdd, 0x30, 0xfd, 0xe2, 0x98, 0x25, 0xb3, 0x10, 0x91, 0x22, 0x88,
637
- 0x36, 0xd0, 0x94, 0xce, 0x8f, 0x96, 0xdb, 0xbd, 0xf1, 0xd2, 0x13, 0x5c, 0x83, 0x38, 0x46, 0x40,
638
- 0x1e, 0x42, 0xb6, 0xa3, 0xc3, 0x48, 0x7e, 0x6e, 0x6b, 0x3a, 0x28, 0x54, 0xfa, 0x85, 0xba, 0x3d,
639
- 0xca, 0x5e, 0x9b, 0x9f, 0x0a, 0x15, 0x79, 0x2b, 0x4e, 0xd4, 0xe5, 0xac, 0x73, 0xf3, 0xa7, 0x57,
640
- 0x07, 0x70, 0xc0, 0xf7, 0x8c, 0x80, 0x63, 0x0d, 0x67, 0x4a, 0xde, 0xed, 0x31, 0xc5, 0xfe, 0x18,
641
- 0xe3, 0xa5, 0x99, 0x77, 0x26, 0xb8, 0xb4, 0x7c, 0x11, 0x44, 0x92, 0xd9, 0x23, 0x20, 0x89, 0x2e,
642
- 0x37, 0x3f, 0xd1, 0x5b, 0x95, 0xbc, 0xcf, 0xcd, 0x90, 0x87, 0x97, 0xb2, 0xdc, 0xfc, 0xbe, 0x61,
643
- 0xf2, 0x56, 0xd3, 0xab, 0x14, 0x2a, 0x5d, 0x9e, 0x84, 0x3c, 0x39, 0x53, 0x47, 0x6d, 0x41, 0xa2,
644
- 0x1f, 0x2d, 0x43, 0xd8, 0xb7, 0x7b, 0xa4, 0x76, 0xc4, 0x17, 0x49, 0xec, 0x7f, 0x0c, 0x6f, 0xf6,
645
- 0x6c, 0xa1, 0x3b, 0x52, 0x29, 0x9d, 0x55, 0xaa, 0xfb, 0x60, 0x86, 0xb1, 0xbb, 0xcc, 0x3e, 0x5a,
646
- 0xcb, 0x59, 0x5f, 0xb0, 0x9c, 0xa9, 0xa0, 0x51, 0x0b, 0xf5, 0x16, 0xeb, 0x7a, 0x75, 0x2c, 0xd7,
647
- 0x4f, 0xae, 0xd5, 0xe9, 0xe6, 0xe7, 0xad, 0xe8, 0x74, 0xd6, 0xf4, 0xea, 0xa8, 0x50, 0x58, 0xaf
648
- ]
649
-
650
- });
651
-
652
- var Galois_1 = Galois;
653
-
654
- /**
655
- * Contains version pattern information.
656
- *
657
- * @public
658
- * @class
659
- * @extends Nevis
660
- */
661
- var Version = lite.extend(null, {
662
-
663
- /**
664
- * The version pattern block.
665
- *
666
- * @public
667
- * @static
668
- * @type {number[]}
669
- * @memberof Version
670
- */
671
- BLOCK: [
672
- 0xc94, 0x5bc, 0xa99, 0x4d3, 0xbf6, 0x762, 0x847, 0x60d, 0x928, 0xb78, 0x45d, 0xa17, 0x532,
673
- 0x9a6, 0x683, 0x8c9, 0x7ec, 0xec4, 0x1e1, 0xfab, 0x08e, 0xc1a, 0x33f, 0xd75, 0x250, 0x9d5,
674
- 0x6f0, 0x8ba, 0x79f, 0xb0b, 0x42e, 0xa64, 0x541, 0xc69
675
- ]
676
-
677
- });
678
-
679
- var Version_1 = Version;
680
-
681
- /**
682
- * Generates information for a QR code frame based on a specific value to be encoded.
683
- *
684
- * @param {Frame~Options} options - the options to be used
685
- * @public
686
- * @class
687
- * @extends Nevis
688
- */
689
- var Frame = lite.extend(function(options) {
690
- var dataBlock, eccBlock, index, neccBlock1, neccBlock2;
691
- var valueLength = options.value.length;
692
-
693
- this._badness = [];
694
- this._level = ErrorCorrection_1.LEVELS[options.level];
695
- this._polynomial = [];
696
- this._value = options.value;
697
- this._version = 0;
698
- this._stringBuffer = [];
699
-
700
- while (this._version < 40) {
701
- this._version++;
702
-
703
- index = ((this._level - 1) * 4) + ((this._version - 1) * 16);
704
-
705
- neccBlock1 = ErrorCorrection_1.BLOCKS[index++];
706
- neccBlock2 = ErrorCorrection_1.BLOCKS[index++];
707
- dataBlock = ErrorCorrection_1.BLOCKS[index++];
708
- eccBlock = ErrorCorrection_1.BLOCKS[index];
709
-
710
- index = (dataBlock * (neccBlock1 + neccBlock2)) + neccBlock2 - 3 + (this._version <= 9);
711
-
712
- if (valueLength <= index) {
713
- break;
714
- }
715
- }
716
-
717
- this._dataBlock = dataBlock;
718
- this._eccBlock = eccBlock;
719
- this._neccBlock1 = neccBlock1;
720
- this._neccBlock2 = neccBlock2;
721
-
722
- /**
723
- * The data width is based on version.
724
- *
725
- * @public
726
- * @type {number}
727
- * @memberof Frame#
728
- */
729
- // FIXME: Ensure that it fits instead of being truncated.
730
- var width = this.width = 17 + (4 * this._version);
731
-
732
- /**
733
- * The image buffer.
734
- *
735
- * @public
736
- * @type {number[]}
737
- * @memberof Frame#
738
- */
739
- this.buffer = Frame._createArray(width * width);
740
-
741
- this._ecc = Frame._createArray(dataBlock + ((dataBlock + eccBlock) * (neccBlock1 + neccBlock2)) + neccBlock2);
742
- this._mask = Frame._createArray(((width * (width + 1)) + 1) / 2);
743
-
744
- this._insertFinders();
745
- this._insertAlignments();
746
-
747
- // Insert single foreground cell.
748
- this.buffer[8 + (width * (width - 8))] = 1;
749
-
750
- this._insertTimingGap();
751
- this._reverseMask();
752
- this._insertTimingRowAndColumn();
753
- this._insertVersion();
754
- this._syncMask();
755
- this._convertBitStream(valueLength);
756
- this._calculatePolynomial();
757
- this._appendEccToData();
758
- this._interleaveBlocks();
759
- this._pack();
760
- this._finish();
761
- }, {
762
-
763
- _addAlignment: function(x, y) {
764
- var i;
765
- var buffer = this.buffer;
766
- var width = this.width;
767
-
768
- buffer[x + (width * y)] = 1;
769
-
770
- for (i = -2; i < 2; i++) {
771
- buffer[x + i + (width * (y - 2))] = 1;
772
- buffer[x - 2 + (width * (y + i + 1))] = 1;
773
- buffer[x + 2 + (width * (y + i))] = 1;
774
- buffer[x + i + 1 + (width * (y + 2))] = 1;
775
- }
776
-
777
- for (i = 0; i < 2; i++) {
778
- this._setMask(x - 1, y + i);
779
- this._setMask(x + 1, y - i);
780
- this._setMask(x - i, y - 1);
781
- this._setMask(x + i, y + 1);
782
- }
783
- },
784
-
785
- _appendData: function(data, dataLength, ecc, eccLength) {
786
- var bit, i, j;
787
- var polynomial = this._polynomial;
788
- var stringBuffer = this._stringBuffer;
789
-
790
- for (i = 0; i < eccLength; i++) {
791
- stringBuffer[ecc + i] = 0;
792
- }
793
-
794
- for (i = 0; i < dataLength; i++) {
795
- bit = Galois_1.LOG[stringBuffer[data + i] ^ stringBuffer[ecc]];
796
-
797
- if (bit !== 255) {
798
- for (j = 1; j < eccLength; j++) {
799
- stringBuffer[ecc + j - 1] = stringBuffer[ecc + j] ^
800
- Galois_1.EXPONENT[Frame._modN(bit + polynomial[eccLength - j])];
801
- }
802
- } else {
803
- for (j = ecc; j < ecc + eccLength; j++) {
804
- stringBuffer[j] = stringBuffer[j + 1];
805
- }
806
- }
807
-
808
- stringBuffer[ecc + eccLength - 1] = bit === 255 ? 0 : Galois_1.EXPONENT[Frame._modN(bit + polynomial[0])];
809
- }
810
- },
811
-
812
- _appendEccToData: function() {
813
- var i;
814
- var data = 0;
815
- var dataBlock = this._dataBlock;
816
- var ecc = this._calculateMaxLength();
817
- var eccBlock = this._eccBlock;
818
-
819
- for (i = 0; i < this._neccBlock1; i++) {
820
- this._appendData(data, dataBlock, ecc, eccBlock);
821
-
822
- data += dataBlock;
823
- ecc += eccBlock;
824
- }
825
-
826
- for (i = 0; i < this._neccBlock2; i++) {
827
- this._appendData(data, dataBlock + 1, ecc, eccBlock);
828
-
829
- data += dataBlock + 1;
830
- ecc += eccBlock;
831
- }
832
- },
833
-
834
- _applyMask: function(mask) {
835
- var r3x, r3y, x, y;
836
- var buffer = this.buffer;
837
- var width = this.width;
838
-
839
- switch (mask) {
840
- case 0:
841
- for (y = 0; y < width; y++) {
842
- for (x = 0; x < width; x++) {
843
- if (!((x + y) & 1) && !this._isMasked(x, y)) {
844
- buffer[x + (y * width)] ^= 1;
845
- }
846
- }
847
- }
848
-
849
- break;
850
- case 1:
851
- for (y = 0; y < width; y++) {
852
- for (x = 0; x < width; x++) {
853
- if (!(y & 1) && !this._isMasked(x, y)) {
854
- buffer[x + (y * width)] ^= 1;
855
- }
856
- }
857
- }
858
-
859
- break;
860
- case 2:
861
- for (y = 0; y < width; y++) {
862
- for (r3x = 0, x = 0; x < width; x++, r3x++) {
863
- if (r3x === 3) {
864
- r3x = 0;
865
- }
866
-
867
- if (!r3x && !this._isMasked(x, y)) {
868
- buffer[x + (y * width)] ^= 1;
869
- }
870
- }
871
- }
872
-
873
- break;
874
- case 3:
875
- for (r3y = 0, y = 0; y < width; y++, r3y++) {
876
- if (r3y === 3) {
877
- r3y = 0;
878
- }
879
-
880
- for (r3x = r3y, x = 0; x < width; x++, r3x++) {
881
- if (r3x === 3) {
882
- r3x = 0;
883
- }
884
-
885
- if (!r3x && !this._isMasked(x, y)) {
886
- buffer[x + (y * width)] ^= 1;
887
- }
888
- }
889
- }
890
-
891
- break;
892
- case 4:
893
- for (y = 0; y < width; y++) {
894
- for (r3x = 0, r3y = (y >> 1) & 1, x = 0; x < width; x++, r3x++) {
895
- if (r3x === 3) {
896
- r3x = 0;
897
- r3y = !r3y;
898
- }
899
-
900
- if (!r3y && !this._isMasked(x, y)) {
901
- buffer[x + (y * width)] ^= 1;
902
- }
903
- }
904
- }
905
-
906
- break;
907
- case 5:
908
- for (r3y = 0, y = 0; y < width; y++, r3y++) {
909
- if (r3y === 3) {
910
- r3y = 0;
911
- }
912
-
913
- for (r3x = 0, x = 0; x < width; x++, r3x++) {
914
- if (r3x === 3) {
915
- r3x = 0;
916
- }
917
-
918
- if (!((x & y & 1) + !(!r3x | !r3y)) && !this._isMasked(x, y)) {
919
- buffer[x + (y * width)] ^= 1;
920
- }
921
- }
922
- }
923
-
924
- break;
925
- case 6:
926
- for (r3y = 0, y = 0; y < width; y++, r3y++) {
927
- if (r3y === 3) {
928
- r3y = 0;
929
- }
930
-
931
- for (r3x = 0, x = 0; x < width; x++, r3x++) {
932
- if (r3x === 3) {
933
- r3x = 0;
934
- }
935
-
936
- if (!((x & y & 1) + (r3x && r3x === r3y) & 1) && !this._isMasked(x, y)) {
937
- buffer[x + (y * width)] ^= 1;
938
- }
939
- }
940
- }
941
-
942
- break;
943
- case 7:
944
- for (r3y = 0, y = 0; y < width; y++, r3y++) {
945
- if (r3y === 3) {
946
- r3y = 0;
947
- }
948
-
949
- for (r3x = 0, x = 0; x < width; x++, r3x++) {
950
- if (r3x === 3) {
951
- r3x = 0;
952
- }
953
-
954
- if (!((r3x && r3x === r3y) + (x + y & 1) & 1) && !this._isMasked(x, y)) {
955
- buffer[x + (y * width)] ^= 1;
956
- }
957
- }
958
- }
959
-
960
- break;
961
- }
962
- },
963
-
964
- _calculateMaxLength: function() {
965
- return (this._dataBlock * (this._neccBlock1 + this._neccBlock2)) + this._neccBlock2;
966
- },
967
-
968
- _calculatePolynomial: function() {
969
- var i, j;
970
- var eccBlock = this._eccBlock;
971
- var polynomial = this._polynomial;
972
-
973
- polynomial[0] = 1;
974
-
975
- for (i = 0; i < eccBlock; i++) {
976
- polynomial[i + 1] = 1;
977
-
978
- for (j = i; j > 0; j--) {
979
- polynomial[j] = polynomial[j] ? polynomial[j - 1] ^
980
- Galois_1.EXPONENT[Frame._modN(Galois_1.LOG[polynomial[j]] + i)] : polynomial[j - 1];
981
- }
982
-
983
- polynomial[0] = Galois_1.EXPONENT[Frame._modN(Galois_1.LOG[polynomial[0]] + i)];
984
- }
985
-
986
- // Use logs for generator polynomial to save calculation step.
987
- for (i = 0; i <= eccBlock; i++) {
988
- polynomial[i] = Galois_1.LOG[polynomial[i]];
989
- }
990
- },
991
-
992
- _checkBadness: function() {
993
- var b, b1, h, x, y;
994
- var bad = 0;
995
- var badness = this._badness;
996
- var buffer = this.buffer;
997
- var width = this.width;
998
-
999
- // Blocks of same colour.
1000
- for (y = 0; y < width - 1; y++) {
1001
- for (x = 0; x < width - 1; x++) {
1002
- // All foreground colour.
1003
- if ((buffer[x + (width * y)] &&
1004
- buffer[x + 1 + (width * y)] &&
1005
- buffer[x + (width * (y + 1))] &&
1006
- buffer[x + 1 + (width * (y + 1))]) ||
1007
- // All background colour.
1008
- !(buffer[x + (width * y)] ||
1009
- buffer[x + 1 + (width * y)] ||
1010
- buffer[x + (width * (y + 1))] ||
1011
- buffer[x + 1 + (width * (y + 1))])) {
1012
- bad += Frame.N2;
1013
- }
1014
- }
1015
- }
1016
-
1017
- var bw = 0;
1018
-
1019
- // X runs.
1020
- for (y = 0; y < width; y++) {
1021
- h = 0;
1022
-
1023
- badness[0] = 0;
1024
-
1025
- for (b = 0, x = 0; x < width; x++) {
1026
- b1 = buffer[x + (width * y)];
1027
-
1028
- if (b === b1) {
1029
- badness[h]++;
1030
- } else {
1031
- badness[++h] = 1;
1032
- }
1033
-
1034
- b = b1;
1035
- bw += b ? 1 : -1;
1036
- }
1037
-
1038
- bad += this._getBadness(h);
1039
- }
1040
-
1041
- if (bw < 0) {
1042
- bw = -bw;
1043
- }
1044
-
1045
- var count = 0;
1046
- var big = bw;
1047
- big += big << 2;
1048
- big <<= 1;
1049
-
1050
- while (big > width * width) {
1051
- big -= width * width;
1052
- count++;
1053
- }
1054
-
1055
- bad += count * Frame.N4;
1056
-
1057
- // Y runs.
1058
- for (x = 0; x < width; x++) {
1059
- h = 0;
1060
-
1061
- badness[0] = 0;
1062
-
1063
- for (b = 0, y = 0; y < width; y++) {
1064
- b1 = buffer[x + (width * y)];
1065
-
1066
- if (b === b1) {
1067
- badness[h]++;
1068
- } else {
1069
- badness[++h] = 1;
1070
- }
1071
-
1072
- b = b1;
1073
- }
1074
-
1075
- bad += this._getBadness(h);
1076
- }
1077
-
1078
- return bad;
1079
- },
1080
-
1081
- _convertBitStream: function(length) {
1082
- var bit, i;
1083
- var ecc = this._ecc;
1084
- var version = this._version;
1085
-
1086
- // Convert string to bit stream. 8-bit data to QR-coded 8-bit data (numeric, alphanumeric, or kanji not supported).
1087
- for (i = 0; i < length; i++) {
1088
- ecc[i] = this._value.charCodeAt(i);
1089
- }
1090
-
1091
- var stringBuffer = this._stringBuffer = ecc.slice();
1092
- var maxLength = this._calculateMaxLength();
1093
-
1094
- if (length >= maxLength - 2) {
1095
- length = maxLength - 2;
1096
-
1097
- if (version > 9) {
1098
- length--;
1099
- }
1100
- }
1101
-
1102
- // Shift and re-pack to insert length prefix.
1103
- var index = length;
1104
-
1105
- if (version > 9) {
1106
- stringBuffer[index + 2] = 0;
1107
- stringBuffer[index + 3] = 0;
1108
-
1109
- while (index--) {
1110
- bit = stringBuffer[index];
1111
-
1112
- stringBuffer[index + 3] |= 255 & (bit << 4);
1113
- stringBuffer[index + 2] = bit >> 4;
1114
- }
1115
-
1116
- stringBuffer[2] |= 255 & (length << 4);
1117
- stringBuffer[1] = length >> 4;
1118
- stringBuffer[0] = 0x40 | (length >> 12);
1119
- } else {
1120
- stringBuffer[index + 1] = 0;
1121
- stringBuffer[index + 2] = 0;
1122
-
1123
- while (index--) {
1124
- bit = stringBuffer[index];
1125
-
1126
- stringBuffer[index + 2] |= 255 & (bit << 4);
1127
- stringBuffer[index + 1] = bit >> 4;
1128
- }
1129
-
1130
- stringBuffer[1] |= 255 & (length << 4);
1131
- stringBuffer[0] = 0x40 | (length >> 4);
1132
- }
1133
-
1134
- // Fill to end with pad pattern.
1135
- index = length + 3 - (version < 10);
1136
-
1137
- while (index < maxLength) {
1138
- stringBuffer[index++] = 0xec;
1139
- stringBuffer[index++] = 0x11;
1140
- }
1141
- },
1142
-
1143
- _getBadness: function(length) {
1144
- var i;
1145
- var badRuns = 0;
1146
- var badness = this._badness;
1147
-
1148
- for (i = 0; i <= length; i++) {
1149
- if (badness[i] >= 5) {
1150
- badRuns += Frame.N1 + badness[i] - 5;
1151
- }
1152
- }
1153
-
1154
- // FBFFFBF as in finder.
1155
- for (i = 3; i < length - 1; i += 2) {
1156
- if (badness[i - 2] === badness[i + 2] &&
1157
- badness[i + 2] === badness[i - 1] &&
1158
- badness[i - 1] === badness[i + 1] &&
1159
- badness[i - 1] * 3 === badness[i] &&
1160
- // Background around the foreground pattern? Not part of the specs.
1161
- (badness[i - 3] === 0 || i + 3 > length ||
1162
- badness[i - 3] * 3 >= badness[i] * 4 ||
1163
- badness[i + 3] * 3 >= badness[i] * 4)) {
1164
- badRuns += Frame.N3;
1165
- }
1166
- }
1167
-
1168
- return badRuns;
1169
- },
1170
-
1171
- _finish: function() {
1172
- // Save pre-mask copy of frame.
1173
- this._stringBuffer = this.buffer.slice();
1174
-
1175
- var currentMask, i;
1176
- var bit = 0;
1177
- var mask = 30000;
1178
-
1179
- /*
1180
- * Using for instead of while since in original Arduino code if an early mask was "good enough" it wouldn't try for
1181
- * a better one since they get more complex and take longer.
1182
- */
1183
- for (i = 0; i < 8; i++) {
1184
- // Returns foreground-background imbalance.
1185
- this._applyMask(i);
1186
-
1187
- currentMask = this._checkBadness();
1188
-
1189
- // Is current mask better than previous best?
1190
- if (currentMask < mask) {
1191
- mask = currentMask;
1192
- bit = i;
1193
- }
1194
-
1195
- // Don't increment "i" to a void redoing mask.
1196
- if (bit === 7) {
1197
- break;
1198
- }
1199
-
1200
- // Reset for next pass.
1201
- this.buffer = this._stringBuffer.slice();
1202
- }
1203
-
1204
- // Redo best mask as none were "good enough" (i.e. last wasn't bit).
1205
- if (bit !== i) {
1206
- this._applyMask(bit);
1207
- }
1208
-
1209
- // Add in final mask/ECC level bytes.
1210
- mask = ErrorCorrection_1.FINAL_FORMAT[bit + (this._level - 1 << 3)];
1211
-
1212
- var buffer = this.buffer;
1213
- var width = this.width;
1214
-
1215
- // Low byte.
1216
- for (i = 0; i < 8; i++, mask >>= 1) {
1217
- if (mask & 1) {
1218
- buffer[width - 1 - i + (width * 8)] = 1;
1219
-
1220
- if (i < 6) {
1221
- buffer[8 + (width * i)] = 1;
1222
- } else {
1223
- buffer[8 + (width * (i + 1))] = 1;
1224
- }
1225
- }
1226
- }
1227
-
1228
- // High byte.
1229
- for (i = 0; i < 7; i++, mask >>= 1) {
1230
- if (mask & 1) {
1231
- buffer[8 + (width * (width - 7 + i))] = 1;
1232
-
1233
- if (i) {
1234
- buffer[6 - i + (width * 8)] = 1;
1235
- } else {
1236
- buffer[7 + (width * 8)] = 1;
1237
- }
1238
- }
1239
- }
1240
- },
1241
-
1242
- _interleaveBlocks: function() {
1243
- var i, j;
1244
- var dataBlock = this._dataBlock;
1245
- var ecc = this._ecc;
1246
- var eccBlock = this._eccBlock;
1247
- var k = 0;
1248
- var maxLength = this._calculateMaxLength();
1249
- var neccBlock1 = this._neccBlock1;
1250
- var neccBlock2 = this._neccBlock2;
1251
- var stringBuffer = this._stringBuffer;
1252
-
1253
- for (i = 0; i < dataBlock; i++) {
1254
- for (j = 0; j < neccBlock1; j++) {
1255
- ecc[k++] = stringBuffer[i + (j * dataBlock)];
1256
- }
1257
-
1258
- for (j = 0; j < neccBlock2; j++) {
1259
- ecc[k++] = stringBuffer[(neccBlock1 * dataBlock) + i + (j * (dataBlock + 1))];
1260
- }
1261
- }
1262
-
1263
- for (j = 0; j < neccBlock2; j++) {
1264
- ecc[k++] = stringBuffer[(neccBlock1 * dataBlock) + i + (j * (dataBlock + 1))];
1265
- }
1266
-
1267
- for (i = 0; i < eccBlock; i++) {
1268
- for (j = 0; j < neccBlock1 + neccBlock2; j++) {
1269
- ecc[k++] = stringBuffer[maxLength + i + (j * eccBlock)];
1270
- }
1271
- }
1272
-
1273
- this._stringBuffer = ecc;
1274
- },
1275
-
1276
- _insertAlignments: function() {
1277
- var i, x, y;
1278
- var version = this._version;
1279
- var width = this.width;
1280
-
1281
- if (version > 1) {
1282
- i = Alignment_1.BLOCK[version];
1283
- y = width - 7;
1284
-
1285
- for (;;) {
1286
- x = width - 7;
1287
-
1288
- while (x > i - 3) {
1289
- this._addAlignment(x, y);
1290
-
1291
- if (x < i) {
1292
- break;
1293
- }
1294
-
1295
- x -= i;
1296
- }
1297
-
1298
- if (y <= i + 9) {
1299
- break;
1300
- }
1301
-
1302
- y -= i;
1303
-
1304
- this._addAlignment(6, y);
1305
- this._addAlignment(y, 6);
1306
- }
1307
- }
1308
- },
1309
-
1310
- _insertFinders: function() {
1311
- var i, j, x, y;
1312
- var buffer = this.buffer;
1313
- var width = this.width;
1314
-
1315
- for (i = 0; i < 3; i++) {
1316
- j = 0;
1317
- y = 0;
1318
-
1319
- if (i === 1) {
1320
- j = width - 7;
1321
- }
1322
- if (i === 2) {
1323
- y = width - 7;
1324
- }
1325
-
1326
- buffer[y + 3 + (width * (j + 3))] = 1;
1327
-
1328
- for (x = 0; x < 6; x++) {
1329
- buffer[y + x + (width * j)] = 1;
1330
- buffer[y + (width * (j + x + 1))] = 1;
1331
- buffer[y + 6 + (width * (j + x))] = 1;
1332
- buffer[y + x + 1 + (width * (j + 6))] = 1;
1333
- }
1334
-
1335
- for (x = 1; x < 5; x++) {
1336
- this._setMask(y + x, j + 1);
1337
- this._setMask(y + 1, j + x + 1);
1338
- this._setMask(y + 5, j + x);
1339
- this._setMask(y + x + 1, j + 5);
1340
- }
1341
-
1342
- for (x = 2; x < 4; x++) {
1343
- buffer[y + x + (width * (j + 2))] = 1;
1344
- buffer[y + 2 + (width * (j + x + 1))] = 1;
1345
- buffer[y + 4 + (width * (j + x))] = 1;
1346
- buffer[y + x + 1 + (width * (j + 4))] = 1;
1347
- }
1348
- }
1349
- },
1350
-
1351
- _insertTimingGap: function() {
1352
- var x, y;
1353
- var width = this.width;
1354
-
1355
- for (y = 0; y < 7; y++) {
1356
- this._setMask(7, y);
1357
- this._setMask(width - 8, y);
1358
- this._setMask(7, y + width - 7);
1359
- }
1360
-
1361
- for (x = 0; x < 8; x++) {
1362
- this._setMask(x, 7);
1363
- this._setMask(x + width - 8, 7);
1364
- this._setMask(x, width - 8);
1365
- }
1366
- },
1367
-
1368
- _insertTimingRowAndColumn: function() {
1369
- var x;
1370
- var buffer = this.buffer;
1371
- var width = this.width;
1372
-
1373
- for (x = 0; x < width - 14; x++) {
1374
- if (x & 1) {
1375
- this._setMask(8 + x, 6);
1376
- this._setMask(6, 8 + x);
1377
- } else {
1378
- buffer[8 + x + (width * 6)] = 1;
1379
- buffer[6 + (width * (8 + x))] = 1;
1380
- }
1381
- }
1382
- },
1383
-
1384
- _insertVersion: function() {
1385
- var i, j, x, y;
1386
- var buffer = this.buffer;
1387
- var version = this._version;
1388
- var width = this.width;
1389
-
1390
- if (version > 6) {
1391
- i = Version_1.BLOCK[version - 7];
1392
- j = 17;
1393
-
1394
- for (x = 0; x < 6; x++) {
1395
- for (y = 0; y < 3; y++, j--) {
1396
- if (1 & (j > 11 ? version >> j - 12 : i >> j)) {
1397
- buffer[5 - x + (width * (2 - y + width - 11))] = 1;
1398
- buffer[2 - y + width - 11 + (width * (5 - x))] = 1;
1399
- } else {
1400
- this._setMask(5 - x, 2 - y + width - 11);
1401
- this._setMask(2 - y + width - 11, 5 - x);
1402
- }
1403
- }
1404
- }
1405
- }
1406
- },
1407
-
1408
- _isMasked: function(x, y) {
1409
- var bit = Frame._getMaskBit(x, y);
1410
-
1411
- return this._mask[bit] === 1;
1412
- },
1413
-
1414
- _pack: function() {
1415
- var bit, i, j;
1416
- var k = 1;
1417
- var v = 1;
1418
- var width = this.width;
1419
- var x = width - 1;
1420
- var y = width - 1;
1421
-
1422
- // Interleaved data and ECC codes.
1423
- var length = ((this._dataBlock + this._eccBlock) * (this._neccBlock1 + this._neccBlock2)) + this._neccBlock2;
1424
-
1425
- for (i = 0; i < length; i++) {
1426
- bit = this._stringBuffer[i];
1427
-
1428
- for (j = 0; j < 8; j++, bit <<= 1) {
1429
- if (0x80 & bit) {
1430
- this.buffer[x + (width * y)] = 1;
1431
- }
1432
-
1433
- // Find next fill position.
1434
- do {
1435
- if (v) {
1436
- x--;
1437
- } else {
1438
- x++;
1439
-
1440
- if (k) {
1441
- if (y !== 0) {
1442
- y--;
1443
- } else {
1444
- x -= 2;
1445
- k = !k;
1446
-
1447
- if (x === 6) {
1448
- x--;
1449
- y = 9;
1450
- }
1451
- }
1452
- } else if (y !== width - 1) {
1453
- y++;
1454
- } else {
1455
- x -= 2;
1456
- k = !k;
1457
-
1458
- if (x === 6) {
1459
- x--;
1460
- y -= 8;
1461
- }
1462
- }
1463
- }
1464
-
1465
- v = !v;
1466
- } while (this._isMasked(x, y));
1467
- }
1468
- }
1469
- },
1470
-
1471
- _reverseMask: function() {
1472
- var x, y;
1473
- var width = this.width;
1474
-
1475
- for (x = 0; x < 9; x++) {
1476
- this._setMask(x, 8);
1477
- }
1478
-
1479
- for (x = 0; x < 8; x++) {
1480
- this._setMask(x + width - 8, 8);
1481
- this._setMask(8, x);
1482
- }
1483
-
1484
- for (y = 0; y < 7; y++) {
1485
- this._setMask(8, y + width - 7);
1486
- }
1487
- },
1488
-
1489
- _setMask: function(x, y) {
1490
- var bit = Frame._getMaskBit(x, y);
1491
-
1492
- this._mask[bit] = 1;
1493
- },
1494
-
1495
- _syncMask: function() {
1496
- var x, y;
1497
- var width = this.width;
1498
-
1499
- for (y = 0; y < width; y++) {
1500
- for (x = 0; x <= y; x++) {
1501
- if (this.buffer[x + (width * y)]) {
1502
- this._setMask(x, y);
1503
- }
1504
- }
1505
- }
1506
- }
1507
-
1508
- }, {
1509
-
1510
- _createArray: function(length) {
1511
- var i;
1512
- var array = [];
1513
-
1514
- for (i = 0; i < length; i++) {
1515
- array[i] = 0;
1516
- }
1517
-
1518
- return array;
1519
- },
1520
-
1521
- _getMaskBit: function(x, y) {
1522
- var bit;
1523
-
1524
- if (x > y) {
1525
- bit = x;
1526
- x = y;
1527
- y = bit;
1528
- }
1529
-
1530
- bit = y;
1531
- bit += y * y;
1532
- bit >>= 1;
1533
- bit += x;
1534
-
1535
- return bit;
1536
- },
1537
-
1538
- _modN: function(x) {
1539
- while (x >= 255) {
1540
- x -= 255;
1541
- x = (x >> 8) + (x & 255);
1542
- }
1543
-
1544
- return x;
1545
- },
1546
-
1547
- // *Badness* coefficients.
1548
- N1: 3,
1549
- N2: 3,
1550
- N3: 40,
1551
- N4: 10
1552
-
1553
- });
1554
-
1555
- var Frame_1 = Frame;
1556
-
1557
- /**
1558
- * The options used by {@link Frame}.
1559
- *
1560
- * @typedef {Object} Frame~Options
1561
- * @property {string} level - The ECC level to be used.
1562
- * @property {string} value - The value to be encoded.
1563
- */
1564
-
1565
- /**
1566
- * An implementation of {@link Renderer} for working with <code>img</code> elements.
1567
- *
1568
- * This depends on {@link CanvasRenderer} being executed first as this implementation simply applies the data URL from
1569
- * the rendered <code>canvas</code> element as the <code>src</code> for the <code>img</code> element being rendered.
1570
- *
1571
- * @public
1572
- * @class
1573
- * @extends Renderer
1574
- */
1575
- var ImageRenderer = Renderer_1.extend({
1576
-
1577
- /**
1578
- * @override
1579
- */
1580
- draw: function() {
1581
- this.element.src = this.qrious.toDataURL();
1582
- },
1583
-
1584
- /**
1585
- * @override
1586
- */
1587
- reset: function() {
1588
- this.element.src = '';
1589
- },
1590
-
1591
- /**
1592
- * @override
1593
- */
1594
- resize: function() {
1595
- var element = this.element;
1596
-
1597
- element.width = element.height = this.qrious.size;
1598
- }
1599
-
1600
- });
1601
-
1602
- var ImageRenderer_1 = ImageRenderer;
1603
-
1604
- /**
1605
- * Defines an available option while also configuring how values are applied to the target object.
1606
- *
1607
- * Optionally, a default value can be specified as well a value transformer for greater control over how the option
1608
- * value is applied.
1609
- *
1610
- * If no value transformer is specified, then any specified option will be applied directly. All values are maintained
1611
- * on the target object itself as a field using the option name prefixed with a single underscore.
1612
- *
1613
- * When an option is specified as modifiable, the {@link OptionManager} will be required to include a setter for the
1614
- * property that is defined on the target object that uses the option name.
1615
- *
1616
- * @param {string} name - the name to be used
1617
- * @param {boolean} [modifiable] - <code>true</code> if the property defined on target objects should include a setter;
1618
- * otherwise <code>false</code>
1619
- * @param {*} [defaultValue] - the default value to be used
1620
- * @param {Option~ValueTransformer} [valueTransformer] - the value transformer to be used
1621
- * @public
1622
- * @class
1623
- * @extends Nevis
1624
- */
1625
- var Option = lite.extend(function(name, modifiable, defaultValue, valueTransformer) {
1626
- /**
1627
- * The name for this {@link Option}.
1628
- *
1629
- * @public
1630
- * @type {string}
1631
- * @memberof Option#
1632
- */
1633
- this.name = name;
1634
-
1635
- /**
1636
- * Whether a setter should be included on the property defined on target objects for this {@link Option}.
1637
- *
1638
- * @public
1639
- * @type {boolean}
1640
- * @memberof Option#
1641
- */
1642
- this.modifiable = Boolean(modifiable);
1643
-
1644
- /**
1645
- * The default value for this {@link Option}.
1646
- *
1647
- * @public
1648
- * @type {*}
1649
- * @memberof Option#
1650
- */
1651
- this.defaultValue = defaultValue;
1652
-
1653
- this._valueTransformer = valueTransformer;
1654
- }, {
1655
-
1656
- /**
1657
- * Transforms the specified <code>value</code> so that it can be applied for this {@link Option}.
1658
- *
1659
- * If a value transformer has been specified for this {@link Option}, it will be called upon to transform
1660
- * <code>value</code>. Otherwise, <code>value</code> will be returned directly.
1661
- *
1662
- * @param {*} value - the value to be transformed
1663
- * @return {*} The transformed value or <code>value</code> if no value transformer is specified.
1664
- * @public
1665
- * @memberof Option#
1666
- */
1667
- transform: function(value) {
1668
- var transformer = this._valueTransformer;
1669
- if (typeof transformer === 'function') {
1670
- return transformer(value, this);
1671
- }
1672
-
1673
- return value;
1674
- }
1675
-
1676
- });
1677
-
1678
- var Option_1 = Option;
1679
-
1680
- /**
1681
- * Returns a transformed value for the specified <code>value</code> to be applied for the <code>option</code> provided.
1682
- *
1683
- * @callback Option~ValueTransformer
1684
- * @param {*} value - the value to be transformed
1685
- * @param {Option} option - the {@link Option} for which <code>value</code> is being transformed
1686
- * @return {*} The transform value.
1687
- */
1688
-
1689
- /**
1690
- * Contains utility methods that are useful throughout the library.
1691
- *
1692
- * @public
1693
- * @class
1694
- * @extends Nevis
1695
- */
1696
- var Utilities = lite.extend(null, {
1697
-
1698
- /**
1699
- * Returns the absolute value of a given number.
1700
- *
1701
- * This method is simply a convenient shorthand for <code>Math.abs</code> while ensuring that nulls are returned as
1702
- * <code>null</code> instead of zero.
1703
- *
1704
- * @param {number} value - the number whose absolute value is to be returned
1705
- * @return {number} The absolute value of <code>value</code> or <code>null</code> if <code>value</code> is
1706
- * <code>null</code>.
1707
- * @public
1708
- * @static
1709
- * @memberof Utilities
1710
- */
1711
- abs: function(value) {
1712
- return value != null ? Math.abs(value) : null;
1713
- },
1714
-
1715
- /**
1716
- * Returns whether the specified <code>object</code> has a property with the specified <code>name</code> as an own
1717
- * (not inherited) property.
1718
- *
1719
- * @param {Object} object - the object on which the property is to be checked
1720
- * @param {string} name - the name of the property to be checked
1721
- * @return {boolean} <code>true</code> if <code>object</code> has an own property with <code>name</code>.
1722
- * @public
1723
- * @static
1724
- * @memberof Utilities
1725
- */
1726
- hasOwn: function(object, name) {
1727
- return Object.prototype.hasOwnProperty.call(object, name);
1728
- },
1729
-
1730
- /**
1731
- * A non-operation method that does absolutely nothing.
1732
- *
1733
- * @return {void}
1734
- * @public
1735
- * @static
1736
- * @memberof Utilities
1737
- */
1738
- noop: function() {},
1739
-
1740
- /**
1741
- * Transforms the specified <code>string</code> to upper case while remaining null-safe.
1742
- *
1743
- * @param {string} string - the string to be transformed to upper case
1744
- * @return {string} <code>string</code> transformed to upper case if <code>string</code> is not <code>null</code>.
1745
- * @public
1746
- * @static
1747
- * @memberof Utilities
1748
- */
1749
- toUpperCase: function(string) {
1750
- return string != null ? string.toUpperCase() : null;
1751
- }
1752
-
1753
- });
1754
-
1755
- var Utilities_1 = Utilities;
1756
-
1757
- /**
1758
- * Manages multiple {@link Option} instances that are intended to be used by multiple implementations.
1759
- *
1760
- * Although the option definitions are shared between targets, the values are maintained on the targets themselves.
1761
- *
1762
- * @param {Option[]} options - the options to be used
1763
- * @public
1764
- * @class
1765
- * @extends Nevis
1766
- */
1767
- var OptionManager = lite.extend(function(options) {
1768
- /**
1769
- * The available options for this {@link OptionManager}.
1770
- *
1771
- * @public
1772
- * @type {Object.<string, Option>}
1773
- * @memberof OptionManager#
1774
- */
1775
- this.options = {};
1776
-
1777
- options.forEach(function(option) {
1778
- this.options[option.name] = option;
1779
- }, this);
1780
- }, {
1781
-
1782
- /**
1783
- * Returns whether an option with the specified <code>name</code> is available.
1784
- *
1785
- * @param {string} name - the name of the {@link Option} whose existence is to be checked
1786
- * @return {boolean} <code>true</code> if an {@link Option} exists with <code>name</code>; otherwise
1787
- * <code>false</code>.
1788
- * @public
1789
- * @memberof OptionManager#
1790
- */
1791
- exists: function(name) {
1792
- return this.options[name] != null;
1793
- },
1794
-
1795
- /**
1796
- * Returns the value of the option with the specified <code>name</code> on the <code>target</code> object provided.
1797
- *
1798
- * @param {string} name - the name of the {@link Option} whose value on <code>target</code> is to be returned
1799
- * @param {Object} target - the object from which the value of the named {@link Option} is to be returned
1800
- * @return {*} The value of the {@link Option} with <code>name</code> on <code>target</code>.
1801
- * @public
1802
- * @memberof OptionManager#
1803
- */
1804
- get: function(name, target) {
1805
- return OptionManager._get(this.options[name], target);
1806
- },
1807
-
1808
- /**
1809
- * Returns a copy of all of the available options on the <code>target</code> object provided.
1810
- *
1811
- * @param {Object} target - the object from which the option name/value pairs are to be returned
1812
- * @return {Object.<string, *>} A hash containing the name/value pairs of all options on <code>target</code>.
1813
- * @public
1814
- * @memberof OptionManager#
1815
- */
1816
- getAll: function(target) {
1817
- var name;
1818
- var options = this.options;
1819
- var result = {};
1820
-
1821
- for (name in options) {
1822
- if (Utilities_1.hasOwn(options, name)) {
1823
- result[name] = OptionManager._get(options[name], target);
1824
- }
1825
- }
1826
-
1827
- return result;
1828
- },
1829
-
1830
- /**
1831
- * Initializes the available options for the <code>target</code> object provided and then applies the initial values
1832
- * within the speciifed <code>options</code>.
1833
- *
1834
- * This method will throw an error if any of the names within <code>options</code> does not match an available option.
1835
- *
1836
- * This involves setting the default values and defining properties for all of the available options on
1837
- * <code>target</code> before finally calling {@link OptionMananger#setAll} with <code>options</code> and
1838
- * <code>target</code>. Any options that are configured to be modifiable will have a setter included in their defined
1839
- * property that will allow its corresponding value to be modified.
1840
- *
1841
- * If a change handler is specified, it will be called whenever the value changes on <code>target</code> for a
1842
- * modifiable option, but only when done so via the defined property's setter.
1843
- *
1844
- * @param {Object.<string, *>} options - the name/value pairs of the initial options to be set
1845
- * @param {Object} target - the object on which the options are to be initialized
1846
- * @param {Function} [changeHandler] - the function to be called whenever the value of an modifiable option changes on
1847
- * <code>target</code>
1848
- * @return {void}
1849
- * @throws {Error} If <code>options</code> contains an invalid option name.
1850
- * @public
1851
- * @memberof OptionManager#
1852
- */
1853
- init: function(options, target, changeHandler) {
1854
- if (typeof changeHandler !== 'function') {
1855
- changeHandler = Utilities_1.noop;
1856
- }
1857
-
1858
- var name, option;
1859
-
1860
- for (name in this.options) {
1861
- if (Utilities_1.hasOwn(this.options, name)) {
1862
- option = this.options[name];
1863
-
1864
- OptionManager._set(option, option.defaultValue, target);
1865
- OptionManager._createAccessor(option, target, changeHandler);
1866
- }
1867
- }
1868
-
1869
- this._setAll(options, target, true);
1870
- },
1871
-
1872
- /**
1873
- * Sets the value of the option with the specified <code>name</code> on the <code>target</code> object provided to
1874
- * <code>value</code>.
1875
- *
1876
- * This method will throw an error if <code>name</code> does not match an available option or matches an option that
1877
- * cannot be modified.
1878
- *
1879
- * If <code>value</code> is <code>null</code> and the {@link Option} has a default value configured, then that default
1880
- * value will be used instead. If the {@link Option} also has a value transformer configured, it will be used to
1881
- * transform whichever value was determined to be used.
1882
- *
1883
- * This method returns whether the value of the underlying field on <code>target</code> was changed as a result.
1884
- *
1885
- * @param {string} name - the name of the {@link Option} whose value is to be set
1886
- * @param {*} value - the value to be set for the named {@link Option} on <code>target</code>
1887
- * @param {Object} target - the object on which <code>value</code> is to be set for the named {@link Option}
1888
- * @return {boolean} <code>true</code> if the underlying field on <code>target</code> was changed; otherwise
1889
- * <code>false</code>.
1890
- * @throws {Error} If <code>name</code> is invalid or is for an option that cannot be modified.
1891
- * @public
1892
- * @memberof OptionManager#
1893
- */
1894
- set: function(name, value, target) {
1895
- return this._set(name, value, target);
1896
- },
1897
-
1898
- /**
1899
- * Sets all of the specified <code>options</code> on the <code>target</code> object provided to their corresponding
1900
- * values.
1901
- *
1902
- * This method will throw an error if any of the names within <code>options</code> does not match an available option
1903
- * or matches an option that cannot be modified.
1904
- *
1905
- * If any value within <code>options</code> is <code>null</code> and the corresponding {@link Option} has a default
1906
- * value configured, then that default value will be used instead. If an {@link Option} also has a value transformer
1907
- * configured, it will be used to transform whichever value was determined to be used.
1908
- *
1909
- * This method returns whether the value for any of the underlying fields on <code>target</code> were changed as a
1910
- * result.
1911
- *
1912
- * @param {Object.<string, *>} options - the name/value pairs of options to be set
1913
- * @param {Object} target - the object on which the options are to be set
1914
- * @return {boolean} <code>true</code> if any of the underlying fields on <code>target</code> were changed; otherwise
1915
- * <code>false</code>.
1916
- * @throws {Error} If <code>options</code> contains an invalid option name or an option that cannot be modiifed.
1917
- * @public
1918
- * @memberof OptionManager#
1919
- */
1920
- setAll: function(options, target) {
1921
- return this._setAll(options, target);
1922
- },
1923
-
1924
- _set: function(name, value, target, allowUnmodifiable) {
1925
- var option = this.options[name];
1926
- if (!option) {
1927
- throw new Error('Invalid option: ' + name);
1928
- }
1929
- if (!option.modifiable && !allowUnmodifiable) {
1930
- throw new Error('Option cannot be modified: ' + name);
1931
- }
1932
-
1933
- return OptionManager._set(option, value, target);
1934
- },
1935
-
1936
- _setAll: function(options, target, allowUnmodifiable) {
1937
- if (!options) {
1938
- return false;
1939
- }
1940
-
1941
- var name;
1942
- var changed = false;
1943
-
1944
- for (name in options) {
1945
- if (Utilities_1.hasOwn(options, name) && this._set(name, options[name], target, allowUnmodifiable)) {
1946
- changed = true;
1947
- }
1948
- }
1949
-
1950
- return changed;
1951
- }
1952
-
1953
- }, {
1954
-
1955
- _createAccessor: function(option, target, changeHandler) {
1956
- var descriptor = {
1957
- get: function() {
1958
- return OptionManager._get(option, target);
1959
- }
1960
- };
1961
-
1962
- if (option.modifiable) {
1963
- descriptor.set = function(value) {
1964
- if (OptionManager._set(option, value, target)) {
1965
- changeHandler(value, option);
1966
- }
1967
- };
1968
- }
1969
-
1970
- Object.defineProperty(target, option.name, descriptor);
1971
- },
1972
-
1973
- _get: function(option, target) {
1974
- return target['_' + option.name];
1975
- },
1976
-
1977
- _set: function(option, value, target) {
1978
- var fieldName = '_' + option.name;
1979
- var oldValue = target[fieldName];
1980
- var newValue = option.transform(value != null ? value : option.defaultValue);
1981
-
1982
- target[fieldName] = newValue;
1983
-
1984
- return newValue !== oldValue;
1985
- }
1986
-
1987
- });
1988
-
1989
- var OptionManager_1 = OptionManager;
1990
-
1991
- /**
1992
- * Called whenever the value of a modifiable {@link Option} is changed on a target object via the defined property's
1993
- * setter.
1994
- *
1995
- * @callback OptionManager~ChangeHandler
1996
- * @param {*} value - the new value for <code>option</code> on the target object
1997
- * @param {Option} option - the modifable {@link Option} whose value has changed on the target object.
1998
- * @return {void}
1999
- */
2000
-
2001
- /**
2002
- * A basic manager for {@link Service} implementations that are mapped to simple names.
2003
- *
2004
- * @public
2005
- * @class
2006
- * @extends Nevis
2007
- */
2008
- var ServiceManager = lite.extend(function() {
2009
- this._services = {};
2010
- }, {
2011
-
2012
- /**
2013
- * Returns the {@link Service} being managed with the specified <code>name</code>.
2014
- *
2015
- * @param {string} name - the name of the {@link Service} to be returned
2016
- * @return {Service} The {@link Service} is being managed with <code>name</code>.
2017
- * @throws {Error} If no {@link Service} is being managed with <code>name</code>.
2018
- * @public
2019
- * @memberof ServiceManager#
2020
- */
2021
- getService: function(name) {
2022
- var service = this._services[name];
2023
- if (!service) {
2024
- throw new Error('Service is not being managed with name: ' + name);
2025
- }
2026
-
2027
- return service;
2028
- },
2029
-
2030
- /**
2031
- * Sets the {@link Service} implementation to be managed for the specified <code>name</code> to the
2032
- * <code>service</code> provided.
2033
- *
2034
- * @param {string} name - the name of the {@link Service} to be managed with <code>name</code>
2035
- * @param {Service} service - the {@link Service} implementation to be managed
2036
- * @return {void}
2037
- * @throws {Error} If a {@link Service} is already being managed with the same <code>name</code>.
2038
- * @public
2039
- * @memberof ServiceManager#
2040
- */
2041
- setService: function(name, service) {
2042
- if (this._services[name]) {
2043
- throw new Error('Service is already managed with name: ' + name);
2044
- }
2045
-
2046
- if (service) {
2047
- this._services[name] = service;
2048
- }
2049
- }
2050
-
2051
- });
2052
-
2053
- var ServiceManager_1 = ServiceManager;
2054
-
2055
- var optionManager = new OptionManager_1([
2056
- new Option_1('background', true, 'white'),
2057
- new Option_1('backgroundAlpha', true, 1, Utilities_1.abs),
2058
- new Option_1('element'),
2059
- new Option_1('foreground', true, 'black'),
2060
- new Option_1('foregroundAlpha', true, 1, Utilities_1.abs),
2061
- new Option_1('level', true, 'L', Utilities_1.toUpperCase),
2062
- new Option_1('mime', true, 'image/png'),
2063
- new Option_1('padding', true, null, Utilities_1.abs),
2064
- new Option_1('size', true, 100, Utilities_1.abs),
2065
- new Option_1('value', true, '')
2066
- ]);
2067
- var serviceManager = new ServiceManager_1();
2068
-
2069
- /**
2070
- * Enables configuration of a QR code generator which uses HTML5 <code>canvas</code> for rendering.
2071
- *
2072
- * @param {QRious~Options} [options] - the options to be used
2073
- * @throws {Error} If any <code>options</code> are invalid.
2074
- * @public
2075
- * @class
2076
- * @extends Nevis
2077
- */
2078
- var QRious = lite.extend(function(options) {
2079
- optionManager.init(options, this, this.update.bind(this));
2080
-
2081
- var element = optionManager.get('element', this);
2082
- var elementService = serviceManager.getService('element');
2083
- var canvas = element && elementService.isCanvas(element) ? element : elementService.createCanvas();
2084
- var image = element && elementService.isImage(element) ? element : elementService.createImage();
2085
-
2086
- this._canvasRenderer = new CanvasRenderer_1(this, canvas, true);
2087
- this._imageRenderer = new ImageRenderer_1(this, image, image === element);
2088
-
2089
- this.update();
2090
- }, {
2091
-
2092
- /**
2093
- * Returns all of the options configured for this {@link QRious}.
2094
- *
2095
- * Any changes made to the returned object will not be reflected in the options themselves or their corresponding
2096
- * underlying fields.
2097
- *
2098
- * @return {Object.<string, *>} A copy of the applied options.
2099
- * @public
2100
- * @memberof QRious#
2101
- */
2102
- get: function() {
2103
- return optionManager.getAll(this);
2104
- },
2105
-
2106
- /**
2107
- * Sets all of the specified <code>options</code> and automatically updates this {@link QRious} if any of the
2108
- * underlying fields are changed as a result.
2109
- *
2110
- * This is the preferred method for updating multiple options at one time to avoid unnecessary updates between
2111
- * changes.
2112
- *
2113
- * @param {QRious~Options} options - the options to be set
2114
- * @return {void}
2115
- * @throws {Error} If any <code>options</code> are invalid or cannot be modified.
2116
- * @public
2117
- * @memberof QRious#
2118
- */
2119
- set: function(options) {
2120
- if (optionManager.setAll(options, this)) {
2121
- this.update();
2122
- }
2123
- },
2124
-
2125
- /**
2126
- * Returns the image data URI for the generated QR code using the <code>mime</code> provided.
2127
- *
2128
- * @param {string} [mime] - the MIME type for the image
2129
- * @return {string} The image data URI for the QR code.
2130
- * @public
2131
- * @memberof QRious#
2132
- */
2133
- toDataURL: function(mime) {
2134
- return this.canvas.toDataURL(mime || this.mime);
2135
- },
2136
-
2137
- /**
2138
- * Updates this {@link QRious} by generating a new {@link Frame} and re-rendering the QR code.
2139
- *
2140
- * @return {void}
2141
- * @protected
2142
- * @memberof QRious#
2143
- */
2144
- update: function() {
2145
- var frame = new Frame_1({
2146
- level: this.level,
2147
- value: this.value
2148
- });
2149
-
2150
- this._canvasRenderer.render(frame);
2151
- this._imageRenderer.render(frame);
2152
- }
2153
-
2154
- }, {
2155
-
2156
- /**
2157
- * Configures the <code>service</code> provided to be used by all {@link QRious} instances.
2158
- *
2159
- * @param {Service} service - the {@link Service} to be configured
2160
- * @return {void}
2161
- * @throws {Error} If a {@link Service} has already been configured with the same name.
2162
- * @public
2163
- * @static
2164
- * @memberof QRious
2165
- */
2166
- use: function(service) {
2167
- serviceManager.setService(service.getName(), service);
2168
- }
2169
-
2170
- });
2171
-
2172
- Object.defineProperties(QRious.prototype, {
2173
-
2174
- canvas: {
2175
- /**
2176
- * Returns the <code>canvas</code> element being used to render the QR code for this {@link QRious}.
2177
- *
2178
- * @return {*} The <code>canvas</code> element.
2179
- * @public
2180
- * @memberof QRious#
2181
- * @alias canvas
2182
- */
2183
- get: function() {
2184
- return this._canvasRenderer.getElement();
2185
- }
2186
- },
2187
-
2188
- image: {
2189
- /**
2190
- * Returns the <code>img</code> element being used to render the QR code for this {@link QRious}.
2191
- *
2192
- * @return {*} The <code>img</code> element.
2193
- * @public
2194
- * @memberof QRious#
2195
- * @alias image
2196
- */
2197
- get: function() {
2198
- return this._imageRenderer.getElement();
2199
- }
2200
- }
2201
-
2202
- });
2203
-
2204
- var QRious_1$2 = QRious;
2205
-
2206
- /**
2207
- * The options used by {@link QRious}.
2208
- *
2209
- * @typedef {Object} QRious~Options
2210
- * @property {string} [background="white"] - The background color to be applied to the QR code.
2211
- * @property {number} [backgroundAlpha=1] - The background alpha to be applied to the QR code.
2212
- * @property {*} [element] - The element to be used to render the QR code which may either be an <code>canvas</code> or
2213
- * <code>img</code>. The element(s) will be created if needed.
2214
- * @property {string} [foreground="black"] - The foreground color to be applied to the QR code.
2215
- * @property {number} [foregroundAlpha=1] - The foreground alpha to be applied to the QR code.
2216
- * @property {string} [level="L"] - The error correction level to be applied to the QR code.
2217
- * @property {string} [mime="image/png"] - The MIME type to be used to render the image for the QR code.
2218
- * @property {number} [padding] - The padding for the QR code in pixels.
2219
- * @property {number} [size=100] - The size of the QR code in pixels.
2220
- * @property {string} [value=""] - The value to be encoded within the QR code.
2221
- */
2222
-
2223
- var index = QRious_1$2;
2224
-
2225
- /**
2226
- * Defines a service contract that must be met by all implementations.
2227
- *
2228
- * @public
2229
- * @class
2230
- * @extends Nevis
2231
- */
2232
- var Service = lite.extend({
2233
-
2234
- /**
2235
- * Returns the name of this {@link Service}.
2236
- *
2237
- * @return {string} The service name.
2238
- * @public
2239
- * @abstract
2240
- * @memberof Service#
2241
- */
2242
- getName: function() {}
2243
-
2244
- });
2245
-
2246
- var Service_1 = Service;
2247
-
2248
- /**
2249
- * A service for working with elements.
2250
- *
2251
- * @public
2252
- * @class
2253
- * @extends Service
2254
- */
2255
- var ElementService = Service_1.extend({
2256
-
2257
- /**
2258
- * Creates an instance of a canvas element.
2259
- *
2260
- * Implementations of {@link ElementService} <b>must</b> override this method with their own specific logic.
2261
- *
2262
- * @return {*} The newly created canvas element.
2263
- * @public
2264
- * @abstract
2265
- * @memberof ElementService#
2266
- */
2267
- createCanvas: function() {},
2268
-
2269
- /**
2270
- * Creates an instance of a image element.
2271
- *
2272
- * Implementations of {@link ElementService} <b>must</b> override this method with their own specific logic.
2273
- *
2274
- * @return {*} The newly created image element.
2275
- * @public
2276
- * @abstract
2277
- * @memberof ElementService#
2278
- */
2279
- createImage: function() {},
2280
-
2281
- /**
2282
- * @override
2283
- */
2284
- getName: function() {
2285
- return 'element';
2286
- },
2287
-
2288
- /**
2289
- * Returns whether the specified <code>element</code> is a canvas.
2290
- *
2291
- * Implementations of {@link ElementService} <b>must</b> override this method with their own specific logic.
2292
- *
2293
- * @param {*} element - the element to be checked
2294
- * @return {boolean} <code>true</code> if <code>element</code> is a canvas; otherwise <code>false</code>.
2295
- * @public
2296
- * @abstract
2297
- * @memberof ElementService#
2298
- */
2299
- isCanvas: function(element) {},
2300
-
2301
- /**
2302
- * Returns whether the specified <code>element</code> is an image.
2303
- *
2304
- * Implementations of {@link ElementService} <b>must</b> override this method with their own specific logic.
2305
- *
2306
- * @param {*} element - the element to be checked
2307
- * @return {boolean} <code>true</code> if <code>element</code> is an image; otherwise <code>false</code>.
2308
- * @public
2309
- * @abstract
2310
- * @memberof ElementService#
2311
- */
2312
- isImage: function(element) {}
2313
-
2314
- });
2315
-
2316
- var ElementService_1 = ElementService;
2317
-
2318
- /**
2319
- * An implementation of {@link ElementService} intended for use within a browser environment.
2320
- *
2321
- * @public
2322
- * @class
2323
- * @extends ElementService
2324
- */
2325
- var BrowserElementService = ElementService_1.extend({
2326
-
2327
- /**
2328
- * @override
2329
- */
2330
- createCanvas: function() {
2331
- return document.createElement('canvas');
2332
- },
2333
-
2334
- /**
2335
- * @override
2336
- */
2337
- createImage: function() {
2338
- return document.createElement('img');
2339
- },
2340
-
2341
- /**
2342
- * @override
2343
- */
2344
- isCanvas: function(element) {
2345
- return element instanceof HTMLCanvasElement;
2346
- },
2347
-
2348
- /**
2349
- * @override
2350
- */
2351
- isImage: function(element) {
2352
- return element instanceof HTMLImageElement;
2353
- }
2354
-
2355
- });
2356
-
2357
- var BrowserElementService_1 = BrowserElementService;
2358
-
2359
- index.use(new BrowserElementService_1());
2360
-
2361
- var QRious_1 = index;
2362
-
2363
- return QRious_1;
2364
-
2365
- })));
2366
-
2367
-
2368
- } (qrious.__module));
2369
-
2370
- var qriousExports = qrious.__module.exports;
2371
- var QRious = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(qriousExports);
2372
-
2373
- module.exports = QRious;
23
+ var qrious = qrious$1.__module.exports;
24
+
25
+ var hasRequiredQrious;
26
+
27
+ function requireQrious () {
28
+ if (hasRequiredQrious) return qrious$1.__module.exports;
29
+ hasRequiredQrious = 1;
30
+ (function (module, exports$1) {
31
+ (function (global, factory) {
32
+ module.exports = factory() ;
33
+ }(qrious, (function () {
34
+ /*
35
+ * Copyright (C) 2017 Alasdair Mercer, !ninja
36
+ *
37
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
38
+ * of this software and associated documentation files (the "Software"), to deal
39
+ * in the Software without restriction, including without limitation the rights
40
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
41
+ * copies of the Software, and to permit persons to whom the Software is
42
+ * furnished to do so, subject to the following conditions:
43
+ *
44
+ * The above copyright notice and this permission notice shall be included in all
45
+ * copies or substantial portions of the Software.
46
+ *
47
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
48
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
49
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
50
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
51
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
52
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
53
+ * SOFTWARE.
54
+ */
55
+
56
+ /**
57
+ * A bare-bones constructor for surrogate prototype swapping.
58
+ *
59
+ * @private
60
+ * @constructor
61
+ */
62
+ var Constructor = /* istanbul ignore next */ function() {};
63
+ /**
64
+ * A reference to <code>Object.prototype.hasOwnProperty</code>.
65
+ *
66
+ * @private
67
+ * @type {Function}
68
+ */
69
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
70
+ /**
71
+ * A reference to <code>Array.prototype.slice</code>.
72
+ *
73
+ * @private
74
+ * @type {Function}
75
+ */
76
+ var slice = Array.prototype.slice;
77
+
78
+ /**
79
+ * Creates an object which inherits the given <code>prototype</code>.
80
+ *
81
+ * Optionally, the created object can be extended further with the specified <code>properties</code>.
82
+ *
83
+ * @param {Object} prototype - the prototype to be inherited by the created object
84
+ * @param {Object} [properties] - the optional properties to be extended by the created object
85
+ * @return {Object} The newly created object.
86
+ * @private
87
+ */
88
+ function createObject(prototype, properties) {
89
+ var result;
90
+ /* istanbul ignore next */
91
+ if (typeof Object.create === 'function') {
92
+ result = Object.create(prototype);
93
+ } else {
94
+ Constructor.prototype = prototype;
95
+ result = new Constructor();
96
+ Constructor.prototype = null;
97
+ }
98
+
99
+ if (properties) {
100
+ extendObject(true, result, properties);
101
+ }
102
+
103
+ return result;
104
+ }
105
+
106
+ /**
107
+ * Extends the constructor to which this method is associated with the <code>prototype</code> and/or
108
+ * <code>statics</code> provided.
109
+ *
110
+ * If <code>name</code> is provided, it will be used as the class name and can be accessed via a special
111
+ * <code>class_</code> property on the child constructor, otherwise the class name of the super constructor will be used
112
+ * instead. The class name may also be used string representation for instances of the child constructor (via
113
+ * <code>toString</code>), but this is not applicable to the <i>lite</i> version of Nevis.
114
+ *
115
+ * If <code>constructor</code> is provided, it will be used as the constructor for the child, otherwise a simple
116
+ * constructor which only calls the super constructor will be used instead.
117
+ *
118
+ * The super constructor can be accessed via a special <code>super_</code> property on the child constructor.
119
+ *
120
+ * @param {string} [name=this.class_] - the class name to be used for the child constructor
121
+ * @param {Function} [constructor] - the constructor for the child
122
+ * @param {Object} [prototype] - the prototype properties to be defined for the child
123
+ * @param {Object} [statics] - the static properties to be defined for the child
124
+ * @return {Function} The child <code>constructor</code> provided or the one created if none was given.
125
+ * @public
126
+ */
127
+ function extend(name, constructor, prototype, statics) {
128
+ var superConstructor = this;
129
+
130
+ if (typeof name !== 'string') {
131
+ statics = prototype;
132
+ prototype = constructor;
133
+ constructor = name;
134
+ name = null;
135
+ }
136
+
137
+ if (typeof constructor !== 'function') {
138
+ statics = prototype;
139
+ prototype = constructor;
140
+ constructor = function() {
141
+ return superConstructor.apply(this, arguments);
142
+ };
143
+ }
144
+
145
+ extendObject(false, constructor, superConstructor, statics);
146
+
147
+ constructor.prototype = createObject(superConstructor.prototype, prototype);
148
+ constructor.prototype.constructor = constructor;
149
+
150
+ constructor.class_ = name || superConstructor.class_;
151
+ constructor.super_ = superConstructor;
152
+
153
+ return constructor;
154
+ }
155
+
156
+ /**
157
+ * Extends the specified <code>target</code> object with the properties in each of the <code>sources</code> provided.
158
+ *
159
+ * if any source is <code>null</code> it will be ignored.
160
+ *
161
+ * @param {boolean} own - <code>true</code> to only copy <b>own</b> properties from <code>sources</code> onto
162
+ * <code>target</code>; otherwise <code>false</code>
163
+ * @param {Object} target - the target object which should be extended
164
+ * @param {...Object} [sources] - the source objects whose properties are to be copied onto <code>target</code>
165
+ * @return {void}
166
+ * @private
167
+ */
168
+ function extendObject(own, target, sources) {
169
+ sources = slice.call(arguments, 2);
170
+
171
+ var property;
172
+ var source;
173
+
174
+ for (var i = 0, length = sources.length; i < length; i++) {
175
+ source = sources[i];
176
+
177
+ for (property in source) {
178
+ if (!own || hasOwnProperty.call(source, property)) {
179
+ target[property] = source[property];
180
+ }
181
+ }
182
+ }
183
+ }
184
+
185
+ var extend_1 = extend;
186
+
187
+ /**
188
+ * The base class from which all others should extend.
189
+ *
190
+ * @public
191
+ * @constructor
192
+ */
193
+ function Nevis() {}
194
+ Nevis.class_ = 'Nevis';
195
+ Nevis.super_ = Object;
196
+
197
+ /**
198
+ * Extends the constructor to which this method is associated with the <code>prototype</code> and/or
199
+ * <code>statics</code> provided.
200
+ *
201
+ * If <code>name</code> is provided, it will be used as the class name and can be accessed via a special
202
+ * <code>class_</code> property on the child constructor, otherwise the class name of the super constructor will be used
203
+ * instead. The class name may also be used string representation for instances of the child constructor (via
204
+ * <code>toString</code>), but this is not applicable to the <i>lite</i> version of Nevis.
205
+ *
206
+ * If <code>constructor</code> is provided, it will be used as the constructor for the child, otherwise a simple
207
+ * constructor which only calls the super constructor will be used instead.
208
+ *
209
+ * The super constructor can be accessed via a special <code>super_</code> property on the child constructor.
210
+ *
211
+ * @param {string} [name=this.class_] - the class name to be used for the child constructor
212
+ * @param {Function} [constructor] - the constructor for the child
213
+ * @param {Object} [prototype] - the prototype properties to be defined for the child
214
+ * @param {Object} [statics] - the static properties to be defined for the child
215
+ * @return {Function} The child <code>constructor</code> provided or the one created if none was given.
216
+ * @public
217
+ * @static
218
+ * @memberof Nevis
219
+ */
220
+ Nevis.extend = extend_1;
221
+
222
+ var nevis = Nevis;
223
+
224
+ var lite = nevis;
225
+
226
+ /**
227
+ * Responsible for rendering a QR code {@link Frame} on a specific type of element.
228
+ *
229
+ * A renderer may be dependant on the rendering of another element, so the ordering of their execution is important.
230
+ *
231
+ * The rendering of a element can be deferred by disabling the renderer initially, however, any attempt get the element
232
+ * from the renderer will result in it being immediately enabled and the element being rendered.
233
+ *
234
+ * @param {QRious} qrious - the {@link QRious} instance to be used
235
+ * @param {*} element - the element onto which the QR code is to be rendered
236
+ * @param {boolean} [enabled] - <code>true</code> this {@link Renderer} is enabled; otherwise <code>false</code>.
237
+ * @public
238
+ * @class
239
+ * @extends Nevis
240
+ */
241
+ var Renderer = lite.extend(function(qrious, element, enabled) {
242
+ /**
243
+ * The {@link QRious} instance.
244
+ *
245
+ * @protected
246
+ * @type {QRious}
247
+ * @memberof Renderer#
248
+ */
249
+ this.qrious = qrious;
250
+
251
+ /**
252
+ * The element onto which this {@link Renderer} is rendering the QR code.
253
+ *
254
+ * @protected
255
+ * @type {*}
256
+ * @memberof Renderer#
257
+ */
258
+ this.element = element;
259
+ this.element.qrious = qrious;
260
+
261
+ /**
262
+ * Whether this {@link Renderer} is enabled.
263
+ *
264
+ * @protected
265
+ * @type {boolean}
266
+ * @memberof Renderer#
267
+ */
268
+ this.enabled = Boolean(enabled);
269
+ }, {
270
+
271
+ /**
272
+ * Draws the specified QR code <code>frame</code> on the underlying element.
273
+ *
274
+ * Implementations of {@link Renderer} <b>must</b> override this method with their own specific logic.
275
+ *
276
+ * @param {Frame} frame - the {@link Frame} to be drawn
277
+ * @return {void}
278
+ * @protected
279
+ * @abstract
280
+ * @memberof Renderer#
281
+ */
282
+ draw: function(frame) {},
283
+
284
+ /**
285
+ * Returns the element onto which this {@link Renderer} is rendering the QR code.
286
+ *
287
+ * If this method is called while this {@link Renderer} is disabled, it will be immediately enabled and rendered
288
+ * before the element is returned.
289
+ *
290
+ * @return {*} The element.
291
+ * @public
292
+ * @memberof Renderer#
293
+ */
294
+ getElement: function() {
295
+ if (!this.enabled) {
296
+ this.enabled = true;
297
+ this.render();
298
+ }
299
+
300
+ return this.element;
301
+ },
302
+
303
+ /**
304
+ * Calculates the size (in pixel units) to represent an individual module within the QR code based on the
305
+ * <code>frame</code> provided.
306
+ *
307
+ * Any configured padding will be excluded from the returned size.
308
+ *
309
+ * The returned value will be at least one, even in cases where the size of the QR code does not fit its contents.
310
+ * This is done so that the inevitable clipping is handled more gracefully since this way at least something is
311
+ * displayed instead of just a blank space filled by the background color.
312
+ *
313
+ * @param {Frame} frame - the {@link Frame} from which the module size is to be derived
314
+ * @return {number} The pixel size for each module in the QR code which will be no less than one.
315
+ * @protected
316
+ * @memberof Renderer#
317
+ */
318
+ getModuleSize: function(frame) {
319
+ var qrious = this.qrious;
320
+ var padding = qrious.padding || 0;
321
+ var pixels = Math.floor((qrious.size - (padding * 2)) / frame.width);
322
+
323
+ return Math.max(1, pixels);
324
+ },
325
+
326
+ /**
327
+ * Calculates the offset/padding (in pixel units) to be inserted before the QR code based on the <code>frame</code>
328
+ * provided.
329
+ *
330
+ * The returned value will be zero if there is no available offset or if the size of the QR code does not fit its
331
+ * contents. It will never be a negative value. This is done so that the inevitable clipping appears more naturally
332
+ * and it is not clipped from all directions.
333
+ *
334
+ * @param {Frame} frame - the {@link Frame} from which the offset is to be derived
335
+ * @return {number} The pixel offset for the QR code which will be no less than zero.
336
+ * @protected
337
+ * @memberof Renderer#
338
+ */
339
+ getOffset: function(frame) {
340
+ var qrious = this.qrious;
341
+ var padding = qrious.padding;
342
+
343
+ if (padding != null) {
344
+ return padding;
345
+ }
346
+
347
+ var moduleSize = this.getModuleSize(frame);
348
+ var offset = Math.floor((qrious.size - (moduleSize * frame.width)) / 2);
349
+
350
+ return Math.max(0, offset);
351
+ },
352
+
353
+ /**
354
+ * Renders a QR code on the underlying element based on the <code>frame</code> provided.
355
+ *
356
+ * @param {Frame} frame - the {@link Frame} to be rendered
357
+ * @return {void}
358
+ * @public
359
+ * @memberof Renderer#
360
+ */
361
+ render: function(frame) {
362
+ if (this.enabled) {
363
+ this.resize();
364
+ this.reset();
365
+ this.draw(frame);
366
+ }
367
+ },
368
+
369
+ /**
370
+ * Resets the underlying element, effectively clearing any previously rendered QR code.
371
+ *
372
+ * Implementations of {@link Renderer} <b>must</b> override this method with their own specific logic.
373
+ *
374
+ * @return {void}
375
+ * @protected
376
+ * @abstract
377
+ * @memberof Renderer#
378
+ */
379
+ reset: function() {},
380
+
381
+ /**
382
+ * Ensures that the size of the underlying element matches that defined on the associated {@link QRious} instance.
383
+ *
384
+ * Implementations of {@link Renderer} <b>must</b> override this method with their own specific logic.
385
+ *
386
+ * @return {void}
387
+ * @protected
388
+ * @abstract
389
+ * @memberof Renderer#
390
+ */
391
+ resize: function() {}
392
+
393
+ });
394
+
395
+ var Renderer_1 = Renderer;
396
+
397
+ /**
398
+ * An implementation of {@link Renderer} for working with <code>canvas</code> elements.
399
+ *
400
+ * @public
401
+ * @class
402
+ * @extends Renderer
403
+ */
404
+ var CanvasRenderer = Renderer_1.extend({
405
+
406
+ /**
407
+ * @override
408
+ */
409
+ draw: function(frame) {
410
+ var i, j;
411
+ var qrious = this.qrious;
412
+ var moduleSize = this.getModuleSize(frame);
413
+ var offset = this.getOffset(frame);
414
+ var context = this.element.getContext('2d');
415
+
416
+ context.fillStyle = qrious.foreground;
417
+ context.globalAlpha = qrious.foregroundAlpha;
418
+
419
+ for (i = 0; i < frame.width; i++) {
420
+ for (j = 0; j < frame.width; j++) {
421
+ if (frame.buffer[(j * frame.width) + i]) {
422
+ context.fillRect((moduleSize * i) + offset, (moduleSize * j) + offset, moduleSize, moduleSize);
423
+ }
424
+ }
425
+ }
426
+ },
427
+
428
+ /**
429
+ * @override
430
+ */
431
+ reset: function() {
432
+ var qrious = this.qrious;
433
+ var context = this.element.getContext('2d');
434
+ var size = qrious.size;
435
+
436
+ context.lineWidth = 1;
437
+ context.clearRect(0, 0, size, size);
438
+ context.fillStyle = qrious.background;
439
+ context.globalAlpha = qrious.backgroundAlpha;
440
+ context.fillRect(0, 0, size, size);
441
+ },
442
+
443
+ /**
444
+ * @override
445
+ */
446
+ resize: function() {
447
+ var element = this.element;
448
+
449
+ element.width = element.height = this.qrious.size;
450
+ }
451
+
452
+ });
453
+
454
+ var CanvasRenderer_1 = CanvasRenderer;
455
+
456
+ /* eslint no-multi-spaces: "off" */
457
+
458
+
459
+
460
+ /**
461
+ * Contains alignment pattern information.
462
+ *
463
+ * @public
464
+ * @class
465
+ * @extends Nevis
466
+ */
467
+ var Alignment = lite.extend(null, {
468
+
469
+ /**
470
+ * The alignment pattern block.
471
+ *
472
+ * @public
473
+ * @static
474
+ * @type {number[]}
475
+ * @memberof Alignment
476
+ */
477
+ BLOCK: [
478
+ 0, 11, 15, 19, 23, 27, 31,
479
+ 16, 18, 20, 22, 24, 26, 28, 20, 22, 24, 24, 26, 28, 28, 22, 24, 24,
480
+ 26, 26, 28, 28, 24, 24, 26, 26, 26, 28, 28, 24, 26, 26, 26, 28, 28
481
+ ]
482
+
483
+ });
484
+
485
+ var Alignment_1 = Alignment;
486
+
487
+ /* eslint no-multi-spaces: "off" */
488
+
489
+
490
+
491
+ /**
492
+ * Contains error correction information.
493
+ *
494
+ * @public
495
+ * @class
496
+ * @extends Nevis
497
+ */
498
+ var ErrorCorrection = lite.extend(null, {
499
+
500
+ /**
501
+ * The error correction blocks.
502
+ *
503
+ * There are four elements per version. The first two indicate the number of blocks, then the data width, and finally
504
+ * the ECC width.
505
+ *
506
+ * @public
507
+ * @static
508
+ * @type {number[]}
509
+ * @memberof ErrorCorrection
510
+ */
511
+ BLOCKS: [
512
+ 1, 0, 19, 7, 1, 0, 16, 10, 1, 0, 13, 13, 1, 0, 9, 17,
513
+ 1, 0, 34, 10, 1, 0, 28, 16, 1, 0, 22, 22, 1, 0, 16, 28,
514
+ 1, 0, 55, 15, 1, 0, 44, 26, 2, 0, 17, 18, 2, 0, 13, 22,
515
+ 1, 0, 80, 20, 2, 0, 32, 18, 2, 0, 24, 26, 4, 0, 9, 16,
516
+ 1, 0, 108, 26, 2, 0, 43, 24, 2, 2, 15, 18, 2, 2, 11, 22,
517
+ 2, 0, 68, 18, 4, 0, 27, 16, 4, 0, 19, 24, 4, 0, 15, 28,
518
+ 2, 0, 78, 20, 4, 0, 31, 18, 2, 4, 14, 18, 4, 1, 13, 26,
519
+ 2, 0, 97, 24, 2, 2, 38, 22, 4, 2, 18, 22, 4, 2, 14, 26,
520
+ 2, 0, 116, 30, 3, 2, 36, 22, 4, 4, 16, 20, 4, 4, 12, 24,
521
+ 2, 2, 68, 18, 4, 1, 43, 26, 6, 2, 19, 24, 6, 2, 15, 28,
522
+ 4, 0, 81, 20, 1, 4, 50, 30, 4, 4, 22, 28, 3, 8, 12, 24,
523
+ 2, 2, 92, 24, 6, 2, 36, 22, 4, 6, 20, 26, 7, 4, 14, 28,
524
+ 4, 0, 107, 26, 8, 1, 37, 22, 8, 4, 20, 24, 12, 4, 11, 22,
525
+ 3, 1, 115, 30, 4, 5, 40, 24, 11, 5, 16, 20, 11, 5, 12, 24,
526
+ 5, 1, 87, 22, 5, 5, 41, 24, 5, 7, 24, 30, 11, 7, 12, 24,
527
+ 5, 1, 98, 24, 7, 3, 45, 28, 15, 2, 19, 24, 3, 13, 15, 30,
528
+ 1, 5, 107, 28, 10, 1, 46, 28, 1, 15, 22, 28, 2, 17, 14, 28,
529
+ 5, 1, 120, 30, 9, 4, 43, 26, 17, 1, 22, 28, 2, 19, 14, 28,
530
+ 3, 4, 113, 28, 3, 11, 44, 26, 17, 4, 21, 26, 9, 16, 13, 26,
531
+ 3, 5, 107, 28, 3, 13, 41, 26, 15, 5, 24, 30, 15, 10, 15, 28,
532
+ 4, 4, 116, 28, 17, 0, 42, 26, 17, 6, 22, 28, 19, 6, 16, 30,
533
+ 2, 7, 111, 28, 17, 0, 46, 28, 7, 16, 24, 30, 34, 0, 13, 24,
534
+ 4, 5, 121, 30, 4, 14, 47, 28, 11, 14, 24, 30, 16, 14, 15, 30,
535
+ 6, 4, 117, 30, 6, 14, 45, 28, 11, 16, 24, 30, 30, 2, 16, 30,
536
+ 8, 4, 106, 26, 8, 13, 47, 28, 7, 22, 24, 30, 22, 13, 15, 30,
537
+ 10, 2, 114, 28, 19, 4, 46, 28, 28, 6, 22, 28, 33, 4, 16, 30,
538
+ 8, 4, 122, 30, 22, 3, 45, 28, 8, 26, 23, 30, 12, 28, 15, 30,
539
+ 3, 10, 117, 30, 3, 23, 45, 28, 4, 31, 24, 30, 11, 31, 15, 30,
540
+ 7, 7, 116, 30, 21, 7, 45, 28, 1, 37, 23, 30, 19, 26, 15, 30,
541
+ 5, 10, 115, 30, 19, 10, 47, 28, 15, 25, 24, 30, 23, 25, 15, 30,
542
+ 13, 3, 115, 30, 2, 29, 46, 28, 42, 1, 24, 30, 23, 28, 15, 30,
543
+ 17, 0, 115, 30, 10, 23, 46, 28, 10, 35, 24, 30, 19, 35, 15, 30,
544
+ 17, 1, 115, 30, 14, 21, 46, 28, 29, 19, 24, 30, 11, 46, 15, 30,
545
+ 13, 6, 115, 30, 14, 23, 46, 28, 44, 7, 24, 30, 59, 1, 16, 30,
546
+ 12, 7, 121, 30, 12, 26, 47, 28, 39, 14, 24, 30, 22, 41, 15, 30,
547
+ 6, 14, 121, 30, 6, 34, 47, 28, 46, 10, 24, 30, 2, 64, 15, 30,
548
+ 17, 4, 122, 30, 29, 14, 46, 28, 49, 10, 24, 30, 24, 46, 15, 30,
549
+ 4, 18, 122, 30, 13, 32, 46, 28, 48, 14, 24, 30, 42, 32, 15, 30,
550
+ 20, 4, 117, 30, 40, 7, 47, 28, 43, 22, 24, 30, 10, 67, 15, 30,
551
+ 19, 6, 118, 30, 18, 31, 47, 28, 34, 34, 24, 30, 20, 61, 15, 30
552
+ ],
553
+
554
+ /**
555
+ * The final format bits with mask (level << 3 | mask).
556
+ *
557
+ * @public
558
+ * @static
559
+ * @type {number[]}
560
+ * @memberof ErrorCorrection
561
+ */
562
+ FINAL_FORMAT: [
563
+ // L
564
+ 0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976,
565
+ // M
566
+ 0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0,
567
+ // Q
568
+ 0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed,
569
+ // H
570
+ 0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b
571
+ ],
572
+
573
+ /**
574
+ * A map of human-readable ECC levels.
575
+ *
576
+ * @public
577
+ * @static
578
+ * @type {Object.<string, number>}
579
+ * @memberof ErrorCorrection
580
+ */
581
+ LEVELS: {
582
+ L: 1,
583
+ M: 2,
584
+ Q: 3,
585
+ H: 4
586
+ }
587
+
588
+ });
589
+
590
+ var ErrorCorrection_1 = ErrorCorrection;
591
+
592
+ /**
593
+ * Contains Galois field information.
594
+ *
595
+ * @public
596
+ * @class
597
+ * @extends Nevis
598
+ */
599
+ var Galois = lite.extend(null, {
600
+
601
+ /**
602
+ * The Galois field exponent table.
603
+ *
604
+ * @public
605
+ * @static
606
+ * @type {number[]}
607
+ * @memberof Galois
608
+ */
609
+ EXPONENT: [
610
+ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1d, 0x3a, 0x74, 0xe8, 0xcd, 0x87, 0x13, 0x26,
611
+ 0x4c, 0x98, 0x2d, 0x5a, 0xb4, 0x75, 0xea, 0xc9, 0x8f, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0,
612
+ 0x9d, 0x27, 0x4e, 0x9c, 0x25, 0x4a, 0x94, 0x35, 0x6a, 0xd4, 0xb5, 0x77, 0xee, 0xc1, 0x9f, 0x23,
613
+ 0x46, 0x8c, 0x05, 0x0a, 0x14, 0x28, 0x50, 0xa0, 0x5d, 0xba, 0x69, 0xd2, 0xb9, 0x6f, 0xde, 0xa1,
614
+ 0x5f, 0xbe, 0x61, 0xc2, 0x99, 0x2f, 0x5e, 0xbc, 0x65, 0xca, 0x89, 0x0f, 0x1e, 0x3c, 0x78, 0xf0,
615
+ 0xfd, 0xe7, 0xd3, 0xbb, 0x6b, 0xd6, 0xb1, 0x7f, 0xfe, 0xe1, 0xdf, 0xa3, 0x5b, 0xb6, 0x71, 0xe2,
616
+ 0xd9, 0xaf, 0x43, 0x86, 0x11, 0x22, 0x44, 0x88, 0x0d, 0x1a, 0x34, 0x68, 0xd0, 0xbd, 0x67, 0xce,
617
+ 0x81, 0x1f, 0x3e, 0x7c, 0xf8, 0xed, 0xc7, 0x93, 0x3b, 0x76, 0xec, 0xc5, 0x97, 0x33, 0x66, 0xcc,
618
+ 0x85, 0x17, 0x2e, 0x5c, 0xb8, 0x6d, 0xda, 0xa9, 0x4f, 0x9e, 0x21, 0x42, 0x84, 0x15, 0x2a, 0x54,
619
+ 0xa8, 0x4d, 0x9a, 0x29, 0x52, 0xa4, 0x55, 0xaa, 0x49, 0x92, 0x39, 0x72, 0xe4, 0xd5, 0xb7, 0x73,
620
+ 0xe6, 0xd1, 0xbf, 0x63, 0xc6, 0x91, 0x3f, 0x7e, 0xfc, 0xe5, 0xd7, 0xb3, 0x7b, 0xf6, 0xf1, 0xff,
621
+ 0xe3, 0xdb, 0xab, 0x4b, 0x96, 0x31, 0x62, 0xc4, 0x95, 0x37, 0x6e, 0xdc, 0xa5, 0x57, 0xae, 0x41,
622
+ 0x82, 0x19, 0x32, 0x64, 0xc8, 0x8d, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0, 0xdd, 0xa7, 0x53, 0xa6,
623
+ 0x51, 0xa2, 0x59, 0xb2, 0x79, 0xf2, 0xf9, 0xef, 0xc3, 0x9b, 0x2b, 0x56, 0xac, 0x45, 0x8a, 0x09,
624
+ 0x12, 0x24, 0x48, 0x90, 0x3d, 0x7a, 0xf4, 0xf5, 0xf7, 0xf3, 0xfb, 0xeb, 0xcb, 0x8b, 0x0b, 0x16,
625
+ 0x2c, 0x58, 0xb0, 0x7d, 0xfa, 0xe9, 0xcf, 0x83, 0x1b, 0x36, 0x6c, 0xd8, 0xad, 0x47, 0x8e, 0x00
626
+ ],
627
+
628
+ /**
629
+ * The Galois field log table.
630
+ *
631
+ * @public
632
+ * @static
633
+ * @type {number[]}
634
+ * @memberof Galois
635
+ */
636
+ LOG: [
637
+ 0xff, 0x00, 0x01, 0x19, 0x02, 0x32, 0x1a, 0xc6, 0x03, 0xdf, 0x33, 0xee, 0x1b, 0x68, 0xc7, 0x4b,
638
+ 0x04, 0x64, 0xe0, 0x0e, 0x34, 0x8d, 0xef, 0x81, 0x1c, 0xc1, 0x69, 0xf8, 0xc8, 0x08, 0x4c, 0x71,
639
+ 0x05, 0x8a, 0x65, 0x2f, 0xe1, 0x24, 0x0f, 0x21, 0x35, 0x93, 0x8e, 0xda, 0xf0, 0x12, 0x82, 0x45,
640
+ 0x1d, 0xb5, 0xc2, 0x7d, 0x6a, 0x27, 0xf9, 0xb9, 0xc9, 0x9a, 0x09, 0x78, 0x4d, 0xe4, 0x72, 0xa6,
641
+ 0x06, 0xbf, 0x8b, 0x62, 0x66, 0xdd, 0x30, 0xfd, 0xe2, 0x98, 0x25, 0xb3, 0x10, 0x91, 0x22, 0x88,
642
+ 0x36, 0xd0, 0x94, 0xce, 0x8f, 0x96, 0xdb, 0xbd, 0xf1, 0xd2, 0x13, 0x5c, 0x83, 0x38, 0x46, 0x40,
643
+ 0x1e, 0x42, 0xb6, 0xa3, 0xc3, 0x48, 0x7e, 0x6e, 0x6b, 0x3a, 0x28, 0x54, 0xfa, 0x85, 0xba, 0x3d,
644
+ 0xca, 0x5e, 0x9b, 0x9f, 0x0a, 0x15, 0x79, 0x2b, 0x4e, 0xd4, 0xe5, 0xac, 0x73, 0xf3, 0xa7, 0x57,
645
+ 0x07, 0x70, 0xc0, 0xf7, 0x8c, 0x80, 0x63, 0x0d, 0x67, 0x4a, 0xde, 0xed, 0x31, 0xc5, 0xfe, 0x18,
646
+ 0xe3, 0xa5, 0x99, 0x77, 0x26, 0xb8, 0xb4, 0x7c, 0x11, 0x44, 0x92, 0xd9, 0x23, 0x20, 0x89, 0x2e,
647
+ 0x37, 0x3f, 0xd1, 0x5b, 0x95, 0xbc, 0xcf, 0xcd, 0x90, 0x87, 0x97, 0xb2, 0xdc, 0xfc, 0xbe, 0x61,
648
+ 0xf2, 0x56, 0xd3, 0xab, 0x14, 0x2a, 0x5d, 0x9e, 0x84, 0x3c, 0x39, 0x53, 0x47, 0x6d, 0x41, 0xa2,
649
+ 0x1f, 0x2d, 0x43, 0xd8, 0xb7, 0x7b, 0xa4, 0x76, 0xc4, 0x17, 0x49, 0xec, 0x7f, 0x0c, 0x6f, 0xf6,
650
+ 0x6c, 0xa1, 0x3b, 0x52, 0x29, 0x9d, 0x55, 0xaa, 0xfb, 0x60, 0x86, 0xb1, 0xbb, 0xcc, 0x3e, 0x5a,
651
+ 0xcb, 0x59, 0x5f, 0xb0, 0x9c, 0xa9, 0xa0, 0x51, 0x0b, 0xf5, 0x16, 0xeb, 0x7a, 0x75, 0x2c, 0xd7,
652
+ 0x4f, 0xae, 0xd5, 0xe9, 0xe6, 0xe7, 0xad, 0xe8, 0x74, 0xd6, 0xf4, 0xea, 0xa8, 0x50, 0x58, 0xaf
653
+ ]
654
+
655
+ });
656
+
657
+ var Galois_1 = Galois;
658
+
659
+ /**
660
+ * Contains version pattern information.
661
+ *
662
+ * @public
663
+ * @class
664
+ * @extends Nevis
665
+ */
666
+ var Version = lite.extend(null, {
667
+
668
+ /**
669
+ * The version pattern block.
670
+ *
671
+ * @public
672
+ * @static
673
+ * @type {number[]}
674
+ * @memberof Version
675
+ */
676
+ BLOCK: [
677
+ 0xc94, 0x5bc, 0xa99, 0x4d3, 0xbf6, 0x762, 0x847, 0x60d, 0x928, 0xb78, 0x45d, 0xa17, 0x532,
678
+ 0x9a6, 0x683, 0x8c9, 0x7ec, 0xec4, 0x1e1, 0xfab, 0x08e, 0xc1a, 0x33f, 0xd75, 0x250, 0x9d5,
679
+ 0x6f0, 0x8ba, 0x79f, 0xb0b, 0x42e, 0xa64, 0x541, 0xc69
680
+ ]
681
+
682
+ });
683
+
684
+ var Version_1 = Version;
685
+
686
+ /**
687
+ * Generates information for a QR code frame based on a specific value to be encoded.
688
+ *
689
+ * @param {Frame~Options} options - the options to be used
690
+ * @public
691
+ * @class
692
+ * @extends Nevis
693
+ */
694
+ var Frame = lite.extend(function(options) {
695
+ var dataBlock, eccBlock, index, neccBlock1, neccBlock2;
696
+ var valueLength = options.value.length;
697
+
698
+ this._badness = [];
699
+ this._level = ErrorCorrection_1.LEVELS[options.level];
700
+ this._polynomial = [];
701
+ this._value = options.value;
702
+ this._version = 0;
703
+ this._stringBuffer = [];
704
+
705
+ while (this._version < 40) {
706
+ this._version++;
707
+
708
+ index = ((this._level - 1) * 4) + ((this._version - 1) * 16);
709
+
710
+ neccBlock1 = ErrorCorrection_1.BLOCKS[index++];
711
+ neccBlock2 = ErrorCorrection_1.BLOCKS[index++];
712
+ dataBlock = ErrorCorrection_1.BLOCKS[index++];
713
+ eccBlock = ErrorCorrection_1.BLOCKS[index];
714
+
715
+ index = (dataBlock * (neccBlock1 + neccBlock2)) + neccBlock2 - 3 + (this._version <= 9);
716
+
717
+ if (valueLength <= index) {
718
+ break;
719
+ }
720
+ }
721
+
722
+ this._dataBlock = dataBlock;
723
+ this._eccBlock = eccBlock;
724
+ this._neccBlock1 = neccBlock1;
725
+ this._neccBlock2 = neccBlock2;
726
+
727
+ /**
728
+ * The data width is based on version.
729
+ *
730
+ * @public
731
+ * @type {number}
732
+ * @memberof Frame#
733
+ */
734
+ // FIXME: Ensure that it fits instead of being truncated.
735
+ var width = this.width = 17 + (4 * this._version);
736
+
737
+ /**
738
+ * The image buffer.
739
+ *
740
+ * @public
741
+ * @type {number[]}
742
+ * @memberof Frame#
743
+ */
744
+ this.buffer = Frame._createArray(width * width);
745
+
746
+ this._ecc = Frame._createArray(dataBlock + ((dataBlock + eccBlock) * (neccBlock1 + neccBlock2)) + neccBlock2);
747
+ this._mask = Frame._createArray(((width * (width + 1)) + 1) / 2);
748
+
749
+ this._insertFinders();
750
+ this._insertAlignments();
751
+
752
+ // Insert single foreground cell.
753
+ this.buffer[8 + (width * (width - 8))] = 1;
754
+
755
+ this._insertTimingGap();
756
+ this._reverseMask();
757
+ this._insertTimingRowAndColumn();
758
+ this._insertVersion();
759
+ this._syncMask();
760
+ this._convertBitStream(valueLength);
761
+ this._calculatePolynomial();
762
+ this._appendEccToData();
763
+ this._interleaveBlocks();
764
+ this._pack();
765
+ this._finish();
766
+ }, {
767
+
768
+ _addAlignment: function(x, y) {
769
+ var i;
770
+ var buffer = this.buffer;
771
+ var width = this.width;
772
+
773
+ buffer[x + (width * y)] = 1;
774
+
775
+ for (i = -2; i < 2; i++) {
776
+ buffer[x + i + (width * (y - 2))] = 1;
777
+ buffer[x - 2 + (width * (y + i + 1))] = 1;
778
+ buffer[x + 2 + (width * (y + i))] = 1;
779
+ buffer[x + i + 1 + (width * (y + 2))] = 1;
780
+ }
781
+
782
+ for (i = 0; i < 2; i++) {
783
+ this._setMask(x - 1, y + i);
784
+ this._setMask(x + 1, y - i);
785
+ this._setMask(x - i, y - 1);
786
+ this._setMask(x + i, y + 1);
787
+ }
788
+ },
789
+
790
+ _appendData: function(data, dataLength, ecc, eccLength) {
791
+ var bit, i, j;
792
+ var polynomial = this._polynomial;
793
+ var stringBuffer = this._stringBuffer;
794
+
795
+ for (i = 0; i < eccLength; i++) {
796
+ stringBuffer[ecc + i] = 0;
797
+ }
798
+
799
+ for (i = 0; i < dataLength; i++) {
800
+ bit = Galois_1.LOG[stringBuffer[data + i] ^ stringBuffer[ecc]];
801
+
802
+ if (bit !== 255) {
803
+ for (j = 1; j < eccLength; j++) {
804
+ stringBuffer[ecc + j - 1] = stringBuffer[ecc + j] ^
805
+ Galois_1.EXPONENT[Frame._modN(bit + polynomial[eccLength - j])];
806
+ }
807
+ } else {
808
+ for (j = ecc; j < ecc + eccLength; j++) {
809
+ stringBuffer[j] = stringBuffer[j + 1];
810
+ }
811
+ }
812
+
813
+ stringBuffer[ecc + eccLength - 1] = bit === 255 ? 0 : Galois_1.EXPONENT[Frame._modN(bit + polynomial[0])];
814
+ }
815
+ },
816
+
817
+ _appendEccToData: function() {
818
+ var i;
819
+ var data = 0;
820
+ var dataBlock = this._dataBlock;
821
+ var ecc = this._calculateMaxLength();
822
+ var eccBlock = this._eccBlock;
823
+
824
+ for (i = 0; i < this._neccBlock1; i++) {
825
+ this._appendData(data, dataBlock, ecc, eccBlock);
826
+
827
+ data += dataBlock;
828
+ ecc += eccBlock;
829
+ }
830
+
831
+ for (i = 0; i < this._neccBlock2; i++) {
832
+ this._appendData(data, dataBlock + 1, ecc, eccBlock);
833
+
834
+ data += dataBlock + 1;
835
+ ecc += eccBlock;
836
+ }
837
+ },
838
+
839
+ _applyMask: function(mask) {
840
+ var r3x, r3y, x, y;
841
+ var buffer = this.buffer;
842
+ var width = this.width;
843
+
844
+ switch (mask) {
845
+ case 0:
846
+ for (y = 0; y < width; y++) {
847
+ for (x = 0; x < width; x++) {
848
+ if (!((x + y) & 1) && !this._isMasked(x, y)) {
849
+ buffer[x + (y * width)] ^= 1;
850
+ }
851
+ }
852
+ }
853
+
854
+ break;
855
+ case 1:
856
+ for (y = 0; y < width; y++) {
857
+ for (x = 0; x < width; x++) {
858
+ if (!(y & 1) && !this._isMasked(x, y)) {
859
+ buffer[x + (y * width)] ^= 1;
860
+ }
861
+ }
862
+ }
863
+
864
+ break;
865
+ case 2:
866
+ for (y = 0; y < width; y++) {
867
+ for (r3x = 0, x = 0; x < width; x++, r3x++) {
868
+ if (r3x === 3) {
869
+ r3x = 0;
870
+ }
871
+
872
+ if (!r3x && !this._isMasked(x, y)) {
873
+ buffer[x + (y * width)] ^= 1;
874
+ }
875
+ }
876
+ }
877
+
878
+ break;
879
+ case 3:
880
+ for (r3y = 0, y = 0; y < width; y++, r3y++) {
881
+ if (r3y === 3) {
882
+ r3y = 0;
883
+ }
884
+
885
+ for (r3x = r3y, x = 0; x < width; x++, r3x++) {
886
+ if (r3x === 3) {
887
+ r3x = 0;
888
+ }
889
+
890
+ if (!r3x && !this._isMasked(x, y)) {
891
+ buffer[x + (y * width)] ^= 1;
892
+ }
893
+ }
894
+ }
895
+
896
+ break;
897
+ case 4:
898
+ for (y = 0; y < width; y++) {
899
+ for (r3x = 0, r3y = (y >> 1) & 1, x = 0; x < width; x++, r3x++) {
900
+ if (r3x === 3) {
901
+ r3x = 0;
902
+ r3y = !r3y;
903
+ }
904
+
905
+ if (!r3y && !this._isMasked(x, y)) {
906
+ buffer[x + (y * width)] ^= 1;
907
+ }
908
+ }
909
+ }
910
+
911
+ break;
912
+ case 5:
913
+ for (r3y = 0, y = 0; y < width; y++, r3y++) {
914
+ if (r3y === 3) {
915
+ r3y = 0;
916
+ }
917
+
918
+ for (r3x = 0, x = 0; x < width; x++, r3x++) {
919
+ if (r3x === 3) {
920
+ r3x = 0;
921
+ }
922
+
923
+ if (!((x & y & 1) + !(!r3x | !r3y)) && !this._isMasked(x, y)) {
924
+ buffer[x + (y * width)] ^= 1;
925
+ }
926
+ }
927
+ }
928
+
929
+ break;
930
+ case 6:
931
+ for (r3y = 0, y = 0; y < width; y++, r3y++) {
932
+ if (r3y === 3) {
933
+ r3y = 0;
934
+ }
935
+
936
+ for (r3x = 0, x = 0; x < width; x++, r3x++) {
937
+ if (r3x === 3) {
938
+ r3x = 0;
939
+ }
940
+
941
+ if (!((x & y & 1) + (r3x && r3x === r3y) & 1) && !this._isMasked(x, y)) {
942
+ buffer[x + (y * width)] ^= 1;
943
+ }
944
+ }
945
+ }
946
+
947
+ break;
948
+ case 7:
949
+ for (r3y = 0, y = 0; y < width; y++, r3y++) {
950
+ if (r3y === 3) {
951
+ r3y = 0;
952
+ }
953
+
954
+ for (r3x = 0, x = 0; x < width; x++, r3x++) {
955
+ if (r3x === 3) {
956
+ r3x = 0;
957
+ }
958
+
959
+ if (!((r3x && r3x === r3y) + (x + y & 1) & 1) && !this._isMasked(x, y)) {
960
+ buffer[x + (y * width)] ^= 1;
961
+ }
962
+ }
963
+ }
964
+
965
+ break;
966
+ }
967
+ },
968
+
969
+ _calculateMaxLength: function() {
970
+ return (this._dataBlock * (this._neccBlock1 + this._neccBlock2)) + this._neccBlock2;
971
+ },
972
+
973
+ _calculatePolynomial: function() {
974
+ var i, j;
975
+ var eccBlock = this._eccBlock;
976
+ var polynomial = this._polynomial;
977
+
978
+ polynomial[0] = 1;
979
+
980
+ for (i = 0; i < eccBlock; i++) {
981
+ polynomial[i + 1] = 1;
982
+
983
+ for (j = i; j > 0; j--) {
984
+ polynomial[j] = polynomial[j] ? polynomial[j - 1] ^
985
+ Galois_1.EXPONENT[Frame._modN(Galois_1.LOG[polynomial[j]] + i)] : polynomial[j - 1];
986
+ }
987
+
988
+ polynomial[0] = Galois_1.EXPONENT[Frame._modN(Galois_1.LOG[polynomial[0]] + i)];
989
+ }
990
+
991
+ // Use logs for generator polynomial to save calculation step.
992
+ for (i = 0; i <= eccBlock; i++) {
993
+ polynomial[i] = Galois_1.LOG[polynomial[i]];
994
+ }
995
+ },
996
+
997
+ _checkBadness: function() {
998
+ var b, b1, h, x, y;
999
+ var bad = 0;
1000
+ var badness = this._badness;
1001
+ var buffer = this.buffer;
1002
+ var width = this.width;
1003
+
1004
+ // Blocks of same colour.
1005
+ for (y = 0; y < width - 1; y++) {
1006
+ for (x = 0; x < width - 1; x++) {
1007
+ // All foreground colour.
1008
+ if ((buffer[x + (width * y)] &&
1009
+ buffer[x + 1 + (width * y)] &&
1010
+ buffer[x + (width * (y + 1))] &&
1011
+ buffer[x + 1 + (width * (y + 1))]) ||
1012
+ // All background colour.
1013
+ !(buffer[x + (width * y)] ||
1014
+ buffer[x + 1 + (width * y)] ||
1015
+ buffer[x + (width * (y + 1))] ||
1016
+ buffer[x + 1 + (width * (y + 1))])) {
1017
+ bad += Frame.N2;
1018
+ }
1019
+ }
1020
+ }
1021
+
1022
+ var bw = 0;
1023
+
1024
+ // X runs.
1025
+ for (y = 0; y < width; y++) {
1026
+ h = 0;
1027
+
1028
+ badness[0] = 0;
1029
+
1030
+ for (b = 0, x = 0; x < width; x++) {
1031
+ b1 = buffer[x + (width * y)];
1032
+
1033
+ if (b === b1) {
1034
+ badness[h]++;
1035
+ } else {
1036
+ badness[++h] = 1;
1037
+ }
1038
+
1039
+ b = b1;
1040
+ bw += b ? 1 : -1;
1041
+ }
1042
+
1043
+ bad += this._getBadness(h);
1044
+ }
1045
+
1046
+ if (bw < 0) {
1047
+ bw = -bw;
1048
+ }
1049
+
1050
+ var count = 0;
1051
+ var big = bw;
1052
+ big += big << 2;
1053
+ big <<= 1;
1054
+
1055
+ while (big > width * width) {
1056
+ big -= width * width;
1057
+ count++;
1058
+ }
1059
+
1060
+ bad += count * Frame.N4;
1061
+
1062
+ // Y runs.
1063
+ for (x = 0; x < width; x++) {
1064
+ h = 0;
1065
+
1066
+ badness[0] = 0;
1067
+
1068
+ for (b = 0, y = 0; y < width; y++) {
1069
+ b1 = buffer[x + (width * y)];
1070
+
1071
+ if (b === b1) {
1072
+ badness[h]++;
1073
+ } else {
1074
+ badness[++h] = 1;
1075
+ }
1076
+
1077
+ b = b1;
1078
+ }
1079
+
1080
+ bad += this._getBadness(h);
1081
+ }
1082
+
1083
+ return bad;
1084
+ },
1085
+
1086
+ _convertBitStream: function(length) {
1087
+ var bit, i;
1088
+ var ecc = this._ecc;
1089
+ var version = this._version;
1090
+
1091
+ // Convert string to bit stream. 8-bit data to QR-coded 8-bit data (numeric, alphanumeric, or kanji not supported).
1092
+ for (i = 0; i < length; i++) {
1093
+ ecc[i] = this._value.charCodeAt(i);
1094
+ }
1095
+
1096
+ var stringBuffer = this._stringBuffer = ecc.slice();
1097
+ var maxLength = this._calculateMaxLength();
1098
+
1099
+ if (length >= maxLength - 2) {
1100
+ length = maxLength - 2;
1101
+
1102
+ if (version > 9) {
1103
+ length--;
1104
+ }
1105
+ }
1106
+
1107
+ // Shift and re-pack to insert length prefix.
1108
+ var index = length;
1109
+
1110
+ if (version > 9) {
1111
+ stringBuffer[index + 2] = 0;
1112
+ stringBuffer[index + 3] = 0;
1113
+
1114
+ while (index--) {
1115
+ bit = stringBuffer[index];
1116
+
1117
+ stringBuffer[index + 3] |= 255 & (bit << 4);
1118
+ stringBuffer[index + 2] = bit >> 4;
1119
+ }
1120
+
1121
+ stringBuffer[2] |= 255 & (length << 4);
1122
+ stringBuffer[1] = length >> 4;
1123
+ stringBuffer[0] = 0x40 | (length >> 12);
1124
+ } else {
1125
+ stringBuffer[index + 1] = 0;
1126
+ stringBuffer[index + 2] = 0;
1127
+
1128
+ while (index--) {
1129
+ bit = stringBuffer[index];
1130
+
1131
+ stringBuffer[index + 2] |= 255 & (bit << 4);
1132
+ stringBuffer[index + 1] = bit >> 4;
1133
+ }
1134
+
1135
+ stringBuffer[1] |= 255 & (length << 4);
1136
+ stringBuffer[0] = 0x40 | (length >> 4);
1137
+ }
1138
+
1139
+ // Fill to end with pad pattern.
1140
+ index = length + 3 - (version < 10);
1141
+
1142
+ while (index < maxLength) {
1143
+ stringBuffer[index++] = 0xec;
1144
+ stringBuffer[index++] = 0x11;
1145
+ }
1146
+ },
1147
+
1148
+ _getBadness: function(length) {
1149
+ var i;
1150
+ var badRuns = 0;
1151
+ var badness = this._badness;
1152
+
1153
+ for (i = 0; i <= length; i++) {
1154
+ if (badness[i] >= 5) {
1155
+ badRuns += Frame.N1 + badness[i] - 5;
1156
+ }
1157
+ }
1158
+
1159
+ // FBFFFBF as in finder.
1160
+ for (i = 3; i < length - 1; i += 2) {
1161
+ if (badness[i - 2] === badness[i + 2] &&
1162
+ badness[i + 2] === badness[i - 1] &&
1163
+ badness[i - 1] === badness[i + 1] &&
1164
+ badness[i - 1] * 3 === badness[i] &&
1165
+ // Background around the foreground pattern? Not part of the specs.
1166
+ (badness[i - 3] === 0 || i + 3 > length ||
1167
+ badness[i - 3] * 3 >= badness[i] * 4 ||
1168
+ badness[i + 3] * 3 >= badness[i] * 4)) {
1169
+ badRuns += Frame.N3;
1170
+ }
1171
+ }
1172
+
1173
+ return badRuns;
1174
+ },
1175
+
1176
+ _finish: function() {
1177
+ // Save pre-mask copy of frame.
1178
+ this._stringBuffer = this.buffer.slice();
1179
+
1180
+ var currentMask, i;
1181
+ var bit = 0;
1182
+ var mask = 30000;
1183
+
1184
+ /*
1185
+ * Using for instead of while since in original Arduino code if an early mask was "good enough" it wouldn't try for
1186
+ * a better one since they get more complex and take longer.
1187
+ */
1188
+ for (i = 0; i < 8; i++) {
1189
+ // Returns foreground-background imbalance.
1190
+ this._applyMask(i);
1191
+
1192
+ currentMask = this._checkBadness();
1193
+
1194
+ // Is current mask better than previous best?
1195
+ if (currentMask < mask) {
1196
+ mask = currentMask;
1197
+ bit = i;
1198
+ }
1199
+
1200
+ // Don't increment "i" to a void redoing mask.
1201
+ if (bit === 7) {
1202
+ break;
1203
+ }
1204
+
1205
+ // Reset for next pass.
1206
+ this.buffer = this._stringBuffer.slice();
1207
+ }
1208
+
1209
+ // Redo best mask as none were "good enough" (i.e. last wasn't bit).
1210
+ if (bit !== i) {
1211
+ this._applyMask(bit);
1212
+ }
1213
+
1214
+ // Add in final mask/ECC level bytes.
1215
+ mask = ErrorCorrection_1.FINAL_FORMAT[bit + (this._level - 1 << 3)];
1216
+
1217
+ var buffer = this.buffer;
1218
+ var width = this.width;
1219
+
1220
+ // Low byte.
1221
+ for (i = 0; i < 8; i++, mask >>= 1) {
1222
+ if (mask & 1) {
1223
+ buffer[width - 1 - i + (width * 8)] = 1;
1224
+
1225
+ if (i < 6) {
1226
+ buffer[8 + (width * i)] = 1;
1227
+ } else {
1228
+ buffer[8 + (width * (i + 1))] = 1;
1229
+ }
1230
+ }
1231
+ }
1232
+
1233
+ // High byte.
1234
+ for (i = 0; i < 7; i++, mask >>= 1) {
1235
+ if (mask & 1) {
1236
+ buffer[8 + (width * (width - 7 + i))] = 1;
1237
+
1238
+ if (i) {
1239
+ buffer[6 - i + (width * 8)] = 1;
1240
+ } else {
1241
+ buffer[7 + (width * 8)] = 1;
1242
+ }
1243
+ }
1244
+ }
1245
+ },
1246
+
1247
+ _interleaveBlocks: function() {
1248
+ var i, j;
1249
+ var dataBlock = this._dataBlock;
1250
+ var ecc = this._ecc;
1251
+ var eccBlock = this._eccBlock;
1252
+ var k = 0;
1253
+ var maxLength = this._calculateMaxLength();
1254
+ var neccBlock1 = this._neccBlock1;
1255
+ var neccBlock2 = this._neccBlock2;
1256
+ var stringBuffer = this._stringBuffer;
1257
+
1258
+ for (i = 0; i < dataBlock; i++) {
1259
+ for (j = 0; j < neccBlock1; j++) {
1260
+ ecc[k++] = stringBuffer[i + (j * dataBlock)];
1261
+ }
1262
+
1263
+ for (j = 0; j < neccBlock2; j++) {
1264
+ ecc[k++] = stringBuffer[(neccBlock1 * dataBlock) + i + (j * (dataBlock + 1))];
1265
+ }
1266
+ }
1267
+
1268
+ for (j = 0; j < neccBlock2; j++) {
1269
+ ecc[k++] = stringBuffer[(neccBlock1 * dataBlock) + i + (j * (dataBlock + 1))];
1270
+ }
1271
+
1272
+ for (i = 0; i < eccBlock; i++) {
1273
+ for (j = 0; j < neccBlock1 + neccBlock2; j++) {
1274
+ ecc[k++] = stringBuffer[maxLength + i + (j * eccBlock)];
1275
+ }
1276
+ }
1277
+
1278
+ this._stringBuffer = ecc;
1279
+ },
1280
+
1281
+ _insertAlignments: function() {
1282
+ var i, x, y;
1283
+ var version = this._version;
1284
+ var width = this.width;
1285
+
1286
+ if (version > 1) {
1287
+ i = Alignment_1.BLOCK[version];
1288
+ y = width - 7;
1289
+
1290
+ for (;;) {
1291
+ x = width - 7;
1292
+
1293
+ while (x > i - 3) {
1294
+ this._addAlignment(x, y);
1295
+
1296
+ if (x < i) {
1297
+ break;
1298
+ }
1299
+
1300
+ x -= i;
1301
+ }
1302
+
1303
+ if (y <= i + 9) {
1304
+ break;
1305
+ }
1306
+
1307
+ y -= i;
1308
+
1309
+ this._addAlignment(6, y);
1310
+ this._addAlignment(y, 6);
1311
+ }
1312
+ }
1313
+ },
1314
+
1315
+ _insertFinders: function() {
1316
+ var i, j, x, y;
1317
+ var buffer = this.buffer;
1318
+ var width = this.width;
1319
+
1320
+ for (i = 0; i < 3; i++) {
1321
+ j = 0;
1322
+ y = 0;
1323
+
1324
+ if (i === 1) {
1325
+ j = width - 7;
1326
+ }
1327
+ if (i === 2) {
1328
+ y = width - 7;
1329
+ }
1330
+
1331
+ buffer[y + 3 + (width * (j + 3))] = 1;
1332
+
1333
+ for (x = 0; x < 6; x++) {
1334
+ buffer[y + x + (width * j)] = 1;
1335
+ buffer[y + (width * (j + x + 1))] = 1;
1336
+ buffer[y + 6 + (width * (j + x))] = 1;
1337
+ buffer[y + x + 1 + (width * (j + 6))] = 1;
1338
+ }
1339
+
1340
+ for (x = 1; x < 5; x++) {
1341
+ this._setMask(y + x, j + 1);
1342
+ this._setMask(y + 1, j + x + 1);
1343
+ this._setMask(y + 5, j + x);
1344
+ this._setMask(y + x + 1, j + 5);
1345
+ }
1346
+
1347
+ for (x = 2; x < 4; x++) {
1348
+ buffer[y + x + (width * (j + 2))] = 1;
1349
+ buffer[y + 2 + (width * (j + x + 1))] = 1;
1350
+ buffer[y + 4 + (width * (j + x))] = 1;
1351
+ buffer[y + x + 1 + (width * (j + 4))] = 1;
1352
+ }
1353
+ }
1354
+ },
1355
+
1356
+ _insertTimingGap: function() {
1357
+ var x, y;
1358
+ var width = this.width;
1359
+
1360
+ for (y = 0; y < 7; y++) {
1361
+ this._setMask(7, y);
1362
+ this._setMask(width - 8, y);
1363
+ this._setMask(7, y + width - 7);
1364
+ }
1365
+
1366
+ for (x = 0; x < 8; x++) {
1367
+ this._setMask(x, 7);
1368
+ this._setMask(x + width - 8, 7);
1369
+ this._setMask(x, width - 8);
1370
+ }
1371
+ },
1372
+
1373
+ _insertTimingRowAndColumn: function() {
1374
+ var x;
1375
+ var buffer = this.buffer;
1376
+ var width = this.width;
1377
+
1378
+ for (x = 0; x < width - 14; x++) {
1379
+ if (x & 1) {
1380
+ this._setMask(8 + x, 6);
1381
+ this._setMask(6, 8 + x);
1382
+ } else {
1383
+ buffer[8 + x + (width * 6)] = 1;
1384
+ buffer[6 + (width * (8 + x))] = 1;
1385
+ }
1386
+ }
1387
+ },
1388
+
1389
+ _insertVersion: function() {
1390
+ var i, j, x, y;
1391
+ var buffer = this.buffer;
1392
+ var version = this._version;
1393
+ var width = this.width;
1394
+
1395
+ if (version > 6) {
1396
+ i = Version_1.BLOCK[version - 7];
1397
+ j = 17;
1398
+
1399
+ for (x = 0; x < 6; x++) {
1400
+ for (y = 0; y < 3; y++, j--) {
1401
+ if (1 & (j > 11 ? version >> j - 12 : i >> j)) {
1402
+ buffer[5 - x + (width * (2 - y + width - 11))] = 1;
1403
+ buffer[2 - y + width - 11 + (width * (5 - x))] = 1;
1404
+ } else {
1405
+ this._setMask(5 - x, 2 - y + width - 11);
1406
+ this._setMask(2 - y + width - 11, 5 - x);
1407
+ }
1408
+ }
1409
+ }
1410
+ }
1411
+ },
1412
+
1413
+ _isMasked: function(x, y) {
1414
+ var bit = Frame._getMaskBit(x, y);
1415
+
1416
+ return this._mask[bit] === 1;
1417
+ },
1418
+
1419
+ _pack: function() {
1420
+ var bit, i, j;
1421
+ var k = 1;
1422
+ var v = 1;
1423
+ var width = this.width;
1424
+ var x = width - 1;
1425
+ var y = width - 1;
1426
+
1427
+ // Interleaved data and ECC codes.
1428
+ var length = ((this._dataBlock + this._eccBlock) * (this._neccBlock1 + this._neccBlock2)) + this._neccBlock2;
1429
+
1430
+ for (i = 0; i < length; i++) {
1431
+ bit = this._stringBuffer[i];
1432
+
1433
+ for (j = 0; j < 8; j++, bit <<= 1) {
1434
+ if (0x80 & bit) {
1435
+ this.buffer[x + (width * y)] = 1;
1436
+ }
1437
+
1438
+ // Find next fill position.
1439
+ do {
1440
+ if (v) {
1441
+ x--;
1442
+ } else {
1443
+ x++;
1444
+
1445
+ if (k) {
1446
+ if (y !== 0) {
1447
+ y--;
1448
+ } else {
1449
+ x -= 2;
1450
+ k = !k;
1451
+
1452
+ if (x === 6) {
1453
+ x--;
1454
+ y = 9;
1455
+ }
1456
+ }
1457
+ } else if (y !== width - 1) {
1458
+ y++;
1459
+ } else {
1460
+ x -= 2;
1461
+ k = !k;
1462
+
1463
+ if (x === 6) {
1464
+ x--;
1465
+ y -= 8;
1466
+ }
1467
+ }
1468
+ }
1469
+
1470
+ v = !v;
1471
+ } while (this._isMasked(x, y));
1472
+ }
1473
+ }
1474
+ },
1475
+
1476
+ _reverseMask: function() {
1477
+ var x, y;
1478
+ var width = this.width;
1479
+
1480
+ for (x = 0; x < 9; x++) {
1481
+ this._setMask(x, 8);
1482
+ }
1483
+
1484
+ for (x = 0; x < 8; x++) {
1485
+ this._setMask(x + width - 8, 8);
1486
+ this._setMask(8, x);
1487
+ }
1488
+
1489
+ for (y = 0; y < 7; y++) {
1490
+ this._setMask(8, y + width - 7);
1491
+ }
1492
+ },
1493
+
1494
+ _setMask: function(x, y) {
1495
+ var bit = Frame._getMaskBit(x, y);
1496
+
1497
+ this._mask[bit] = 1;
1498
+ },
1499
+
1500
+ _syncMask: function() {
1501
+ var x, y;
1502
+ var width = this.width;
1503
+
1504
+ for (y = 0; y < width; y++) {
1505
+ for (x = 0; x <= y; x++) {
1506
+ if (this.buffer[x + (width * y)]) {
1507
+ this._setMask(x, y);
1508
+ }
1509
+ }
1510
+ }
1511
+ }
1512
+
1513
+ }, {
1514
+
1515
+ _createArray: function(length) {
1516
+ var i;
1517
+ var array = [];
1518
+
1519
+ for (i = 0; i < length; i++) {
1520
+ array[i] = 0;
1521
+ }
1522
+
1523
+ return array;
1524
+ },
1525
+
1526
+ _getMaskBit: function(x, y) {
1527
+ var bit;
1528
+
1529
+ if (x > y) {
1530
+ bit = x;
1531
+ x = y;
1532
+ y = bit;
1533
+ }
1534
+
1535
+ bit = y;
1536
+ bit += y * y;
1537
+ bit >>= 1;
1538
+ bit += x;
1539
+
1540
+ return bit;
1541
+ },
1542
+
1543
+ _modN: function(x) {
1544
+ while (x >= 255) {
1545
+ x -= 255;
1546
+ x = (x >> 8) + (x & 255);
1547
+ }
1548
+
1549
+ return x;
1550
+ },
1551
+
1552
+ // *Badness* coefficients.
1553
+ N1: 3,
1554
+ N2: 3,
1555
+ N3: 40,
1556
+ N4: 10
1557
+
1558
+ });
1559
+
1560
+ var Frame_1 = Frame;
1561
+
1562
+ /**
1563
+ * The options used by {@link Frame}.
1564
+ *
1565
+ * @typedef {Object} Frame~Options
1566
+ * @property {string} level - The ECC level to be used.
1567
+ * @property {string} value - The value to be encoded.
1568
+ */
1569
+
1570
+ /**
1571
+ * An implementation of {@link Renderer} for working with <code>img</code> elements.
1572
+ *
1573
+ * This depends on {@link CanvasRenderer} being executed first as this implementation simply applies the data URL from
1574
+ * the rendered <code>canvas</code> element as the <code>src</code> for the <code>img</code> element being rendered.
1575
+ *
1576
+ * @public
1577
+ * @class
1578
+ * @extends Renderer
1579
+ */
1580
+ var ImageRenderer = Renderer_1.extend({
1581
+
1582
+ /**
1583
+ * @override
1584
+ */
1585
+ draw: function() {
1586
+ this.element.src = this.qrious.toDataURL();
1587
+ },
1588
+
1589
+ /**
1590
+ * @override
1591
+ */
1592
+ reset: function() {
1593
+ this.element.src = '';
1594
+ },
1595
+
1596
+ /**
1597
+ * @override
1598
+ */
1599
+ resize: function() {
1600
+ var element = this.element;
1601
+
1602
+ element.width = element.height = this.qrious.size;
1603
+ }
1604
+
1605
+ });
1606
+
1607
+ var ImageRenderer_1 = ImageRenderer;
1608
+
1609
+ /**
1610
+ * Defines an available option while also configuring how values are applied to the target object.
1611
+ *
1612
+ * Optionally, a default value can be specified as well a value transformer for greater control over how the option
1613
+ * value is applied.
1614
+ *
1615
+ * If no value transformer is specified, then any specified option will be applied directly. All values are maintained
1616
+ * on the target object itself as a field using the option name prefixed with a single underscore.
1617
+ *
1618
+ * When an option is specified as modifiable, the {@link OptionManager} will be required to include a setter for the
1619
+ * property that is defined on the target object that uses the option name.
1620
+ *
1621
+ * @param {string} name - the name to be used
1622
+ * @param {boolean} [modifiable] - <code>true</code> if the property defined on target objects should include a setter;
1623
+ * otherwise <code>false</code>
1624
+ * @param {*} [defaultValue] - the default value to be used
1625
+ * @param {Option~ValueTransformer} [valueTransformer] - the value transformer to be used
1626
+ * @public
1627
+ * @class
1628
+ * @extends Nevis
1629
+ */
1630
+ var Option = lite.extend(function(name, modifiable, defaultValue, valueTransformer) {
1631
+ /**
1632
+ * The name for this {@link Option}.
1633
+ *
1634
+ * @public
1635
+ * @type {string}
1636
+ * @memberof Option#
1637
+ */
1638
+ this.name = name;
1639
+
1640
+ /**
1641
+ * Whether a setter should be included on the property defined on target objects for this {@link Option}.
1642
+ *
1643
+ * @public
1644
+ * @type {boolean}
1645
+ * @memberof Option#
1646
+ */
1647
+ this.modifiable = Boolean(modifiable);
1648
+
1649
+ /**
1650
+ * The default value for this {@link Option}.
1651
+ *
1652
+ * @public
1653
+ * @type {*}
1654
+ * @memberof Option#
1655
+ */
1656
+ this.defaultValue = defaultValue;
1657
+
1658
+ this._valueTransformer = valueTransformer;
1659
+ }, {
1660
+
1661
+ /**
1662
+ * Transforms the specified <code>value</code> so that it can be applied for this {@link Option}.
1663
+ *
1664
+ * If a value transformer has been specified for this {@link Option}, it will be called upon to transform
1665
+ * <code>value</code>. Otherwise, <code>value</code> will be returned directly.
1666
+ *
1667
+ * @param {*} value - the value to be transformed
1668
+ * @return {*} The transformed value or <code>value</code> if no value transformer is specified.
1669
+ * @public
1670
+ * @memberof Option#
1671
+ */
1672
+ transform: function(value) {
1673
+ var transformer = this._valueTransformer;
1674
+ if (typeof transformer === 'function') {
1675
+ return transformer(value, this);
1676
+ }
1677
+
1678
+ return value;
1679
+ }
1680
+
1681
+ });
1682
+
1683
+ var Option_1 = Option;
1684
+
1685
+ /**
1686
+ * Returns a transformed value for the specified <code>value</code> to be applied for the <code>option</code> provided.
1687
+ *
1688
+ * @callback Option~ValueTransformer
1689
+ * @param {*} value - the value to be transformed
1690
+ * @param {Option} option - the {@link Option} for which <code>value</code> is being transformed
1691
+ * @return {*} The transform value.
1692
+ */
1693
+
1694
+ /**
1695
+ * Contains utility methods that are useful throughout the library.
1696
+ *
1697
+ * @public
1698
+ * @class
1699
+ * @extends Nevis
1700
+ */
1701
+ var Utilities = lite.extend(null, {
1702
+
1703
+ /**
1704
+ * Returns the absolute value of a given number.
1705
+ *
1706
+ * This method is simply a convenient shorthand for <code>Math.abs</code> while ensuring that nulls are returned as
1707
+ * <code>null</code> instead of zero.
1708
+ *
1709
+ * @param {number} value - the number whose absolute value is to be returned
1710
+ * @return {number} The absolute value of <code>value</code> or <code>null</code> if <code>value</code> is
1711
+ * <code>null</code>.
1712
+ * @public
1713
+ * @static
1714
+ * @memberof Utilities
1715
+ */
1716
+ abs: function(value) {
1717
+ return value != null ? Math.abs(value) : null;
1718
+ },
1719
+
1720
+ /**
1721
+ * Returns whether the specified <code>object</code> has a property with the specified <code>name</code> as an own
1722
+ * (not inherited) property.
1723
+ *
1724
+ * @param {Object} object - the object on which the property is to be checked
1725
+ * @param {string} name - the name of the property to be checked
1726
+ * @return {boolean} <code>true</code> if <code>object</code> has an own property with <code>name</code>.
1727
+ * @public
1728
+ * @static
1729
+ * @memberof Utilities
1730
+ */
1731
+ hasOwn: function(object, name) {
1732
+ return Object.prototype.hasOwnProperty.call(object, name);
1733
+ },
1734
+
1735
+ /**
1736
+ * A non-operation method that does absolutely nothing.
1737
+ *
1738
+ * @return {void}
1739
+ * @public
1740
+ * @static
1741
+ * @memberof Utilities
1742
+ */
1743
+ noop: function() {},
1744
+
1745
+ /**
1746
+ * Transforms the specified <code>string</code> to upper case while remaining null-safe.
1747
+ *
1748
+ * @param {string} string - the string to be transformed to upper case
1749
+ * @return {string} <code>string</code> transformed to upper case if <code>string</code> is not <code>null</code>.
1750
+ * @public
1751
+ * @static
1752
+ * @memberof Utilities
1753
+ */
1754
+ toUpperCase: function(string) {
1755
+ return string != null ? string.toUpperCase() : null;
1756
+ }
1757
+
1758
+ });
1759
+
1760
+ var Utilities_1 = Utilities;
1761
+
1762
+ /**
1763
+ * Manages multiple {@link Option} instances that are intended to be used by multiple implementations.
1764
+ *
1765
+ * Although the option definitions are shared between targets, the values are maintained on the targets themselves.
1766
+ *
1767
+ * @param {Option[]} options - the options to be used
1768
+ * @public
1769
+ * @class
1770
+ * @extends Nevis
1771
+ */
1772
+ var OptionManager = lite.extend(function(options) {
1773
+ /**
1774
+ * The available options for this {@link OptionManager}.
1775
+ *
1776
+ * @public
1777
+ * @type {Object.<string, Option>}
1778
+ * @memberof OptionManager#
1779
+ */
1780
+ this.options = {};
1781
+
1782
+ options.forEach(function(option) {
1783
+ this.options[option.name] = option;
1784
+ }, this);
1785
+ }, {
1786
+
1787
+ /**
1788
+ * Returns whether an option with the specified <code>name</code> is available.
1789
+ *
1790
+ * @param {string} name - the name of the {@link Option} whose existence is to be checked
1791
+ * @return {boolean} <code>true</code> if an {@link Option} exists with <code>name</code>; otherwise
1792
+ * <code>false</code>.
1793
+ * @public
1794
+ * @memberof OptionManager#
1795
+ */
1796
+ exists: function(name) {
1797
+ return this.options[name] != null;
1798
+ },
1799
+
1800
+ /**
1801
+ * Returns the value of the option with the specified <code>name</code> on the <code>target</code> object provided.
1802
+ *
1803
+ * @param {string} name - the name of the {@link Option} whose value on <code>target</code> is to be returned
1804
+ * @param {Object} target - the object from which the value of the named {@link Option} is to be returned
1805
+ * @return {*} The value of the {@link Option} with <code>name</code> on <code>target</code>.
1806
+ * @public
1807
+ * @memberof OptionManager#
1808
+ */
1809
+ get: function(name, target) {
1810
+ return OptionManager._get(this.options[name], target);
1811
+ },
1812
+
1813
+ /**
1814
+ * Returns a copy of all of the available options on the <code>target</code> object provided.
1815
+ *
1816
+ * @param {Object} target - the object from which the option name/value pairs are to be returned
1817
+ * @return {Object.<string, *>} A hash containing the name/value pairs of all options on <code>target</code>.
1818
+ * @public
1819
+ * @memberof OptionManager#
1820
+ */
1821
+ getAll: function(target) {
1822
+ var name;
1823
+ var options = this.options;
1824
+ var result = {};
1825
+
1826
+ for (name in options) {
1827
+ if (Utilities_1.hasOwn(options, name)) {
1828
+ result[name] = OptionManager._get(options[name], target);
1829
+ }
1830
+ }
1831
+
1832
+ return result;
1833
+ },
1834
+
1835
+ /**
1836
+ * Initializes the available options for the <code>target</code> object provided and then applies the initial values
1837
+ * within the speciifed <code>options</code>.
1838
+ *
1839
+ * This method will throw an error if any of the names within <code>options</code> does not match an available option.
1840
+ *
1841
+ * This involves setting the default values and defining properties for all of the available options on
1842
+ * <code>target</code> before finally calling {@link OptionMananger#setAll} with <code>options</code> and
1843
+ * <code>target</code>. Any options that are configured to be modifiable will have a setter included in their defined
1844
+ * property that will allow its corresponding value to be modified.
1845
+ *
1846
+ * If a change handler is specified, it will be called whenever the value changes on <code>target</code> for a
1847
+ * modifiable option, but only when done so via the defined property's setter.
1848
+ *
1849
+ * @param {Object.<string, *>} options - the name/value pairs of the initial options to be set
1850
+ * @param {Object} target - the object on which the options are to be initialized
1851
+ * @param {Function} [changeHandler] - the function to be called whenever the value of an modifiable option changes on
1852
+ * <code>target</code>
1853
+ * @return {void}
1854
+ * @throws {Error} If <code>options</code> contains an invalid option name.
1855
+ * @public
1856
+ * @memberof OptionManager#
1857
+ */
1858
+ init: function(options, target, changeHandler) {
1859
+ if (typeof changeHandler !== 'function') {
1860
+ changeHandler = Utilities_1.noop;
1861
+ }
1862
+
1863
+ var name, option;
1864
+
1865
+ for (name in this.options) {
1866
+ if (Utilities_1.hasOwn(this.options, name)) {
1867
+ option = this.options[name];
1868
+
1869
+ OptionManager._set(option, option.defaultValue, target);
1870
+ OptionManager._createAccessor(option, target, changeHandler);
1871
+ }
1872
+ }
1873
+
1874
+ this._setAll(options, target, true);
1875
+ },
1876
+
1877
+ /**
1878
+ * Sets the value of the option with the specified <code>name</code> on the <code>target</code> object provided to
1879
+ * <code>value</code>.
1880
+ *
1881
+ * This method will throw an error if <code>name</code> does not match an available option or matches an option that
1882
+ * cannot be modified.
1883
+ *
1884
+ * If <code>value</code> is <code>null</code> and the {@link Option} has a default value configured, then that default
1885
+ * value will be used instead. If the {@link Option} also has a value transformer configured, it will be used to
1886
+ * transform whichever value was determined to be used.
1887
+ *
1888
+ * This method returns whether the value of the underlying field on <code>target</code> was changed as a result.
1889
+ *
1890
+ * @param {string} name - the name of the {@link Option} whose value is to be set
1891
+ * @param {*} value - the value to be set for the named {@link Option} on <code>target</code>
1892
+ * @param {Object} target - the object on which <code>value</code> is to be set for the named {@link Option}
1893
+ * @return {boolean} <code>true</code> if the underlying field on <code>target</code> was changed; otherwise
1894
+ * <code>false</code>.
1895
+ * @throws {Error} If <code>name</code> is invalid or is for an option that cannot be modified.
1896
+ * @public
1897
+ * @memberof OptionManager#
1898
+ */
1899
+ set: function(name, value, target) {
1900
+ return this._set(name, value, target);
1901
+ },
1902
+
1903
+ /**
1904
+ * Sets all of the specified <code>options</code> on the <code>target</code> object provided to their corresponding
1905
+ * values.
1906
+ *
1907
+ * This method will throw an error if any of the names within <code>options</code> does not match an available option
1908
+ * or matches an option that cannot be modified.
1909
+ *
1910
+ * If any value within <code>options</code> is <code>null</code> and the corresponding {@link Option} has a default
1911
+ * value configured, then that default value will be used instead. If an {@link Option} also has a value transformer
1912
+ * configured, it will be used to transform whichever value was determined to be used.
1913
+ *
1914
+ * This method returns whether the value for any of the underlying fields on <code>target</code> were changed as a
1915
+ * result.
1916
+ *
1917
+ * @param {Object.<string, *>} options - the name/value pairs of options to be set
1918
+ * @param {Object} target - the object on which the options are to be set
1919
+ * @return {boolean} <code>true</code> if any of the underlying fields on <code>target</code> were changed; otherwise
1920
+ * <code>false</code>.
1921
+ * @throws {Error} If <code>options</code> contains an invalid option name or an option that cannot be modiifed.
1922
+ * @public
1923
+ * @memberof OptionManager#
1924
+ */
1925
+ setAll: function(options, target) {
1926
+ return this._setAll(options, target);
1927
+ },
1928
+
1929
+ _set: function(name, value, target, allowUnmodifiable) {
1930
+ var option = this.options[name];
1931
+ if (!option) {
1932
+ throw new Error('Invalid option: ' + name);
1933
+ }
1934
+ if (!option.modifiable && !allowUnmodifiable) {
1935
+ throw new Error('Option cannot be modified: ' + name);
1936
+ }
1937
+
1938
+ return OptionManager._set(option, value, target);
1939
+ },
1940
+
1941
+ _setAll: function(options, target, allowUnmodifiable) {
1942
+ if (!options) {
1943
+ return false;
1944
+ }
1945
+
1946
+ var name;
1947
+ var changed = false;
1948
+
1949
+ for (name in options) {
1950
+ if (Utilities_1.hasOwn(options, name) && this._set(name, options[name], target, allowUnmodifiable)) {
1951
+ changed = true;
1952
+ }
1953
+ }
1954
+
1955
+ return changed;
1956
+ }
1957
+
1958
+ }, {
1959
+
1960
+ _createAccessor: function(option, target, changeHandler) {
1961
+ var descriptor = {
1962
+ get: function() {
1963
+ return OptionManager._get(option, target);
1964
+ }
1965
+ };
1966
+
1967
+ if (option.modifiable) {
1968
+ descriptor.set = function(value) {
1969
+ if (OptionManager._set(option, value, target)) {
1970
+ changeHandler(value, option);
1971
+ }
1972
+ };
1973
+ }
1974
+
1975
+ Object.defineProperty(target, option.name, descriptor);
1976
+ },
1977
+
1978
+ _get: function(option, target) {
1979
+ return target['_' + option.name];
1980
+ },
1981
+
1982
+ _set: function(option, value, target) {
1983
+ var fieldName = '_' + option.name;
1984
+ var oldValue = target[fieldName];
1985
+ var newValue = option.transform(value != null ? value : option.defaultValue);
1986
+
1987
+ target[fieldName] = newValue;
1988
+
1989
+ return newValue !== oldValue;
1990
+ }
1991
+
1992
+ });
1993
+
1994
+ var OptionManager_1 = OptionManager;
1995
+
1996
+ /**
1997
+ * Called whenever the value of a modifiable {@link Option} is changed on a target object via the defined property's
1998
+ * setter.
1999
+ *
2000
+ * @callback OptionManager~ChangeHandler
2001
+ * @param {*} value - the new value for <code>option</code> on the target object
2002
+ * @param {Option} option - the modifable {@link Option} whose value has changed on the target object.
2003
+ * @return {void}
2004
+ */
2005
+
2006
+ /**
2007
+ * A basic manager for {@link Service} implementations that are mapped to simple names.
2008
+ *
2009
+ * @public
2010
+ * @class
2011
+ * @extends Nevis
2012
+ */
2013
+ var ServiceManager = lite.extend(function() {
2014
+ this._services = {};
2015
+ }, {
2016
+
2017
+ /**
2018
+ * Returns the {@link Service} being managed with the specified <code>name</code>.
2019
+ *
2020
+ * @param {string} name - the name of the {@link Service} to be returned
2021
+ * @return {Service} The {@link Service} is being managed with <code>name</code>.
2022
+ * @throws {Error} If no {@link Service} is being managed with <code>name</code>.
2023
+ * @public
2024
+ * @memberof ServiceManager#
2025
+ */
2026
+ getService: function(name) {
2027
+ var service = this._services[name];
2028
+ if (!service) {
2029
+ throw new Error('Service is not being managed with name: ' + name);
2030
+ }
2031
+
2032
+ return service;
2033
+ },
2034
+
2035
+ /**
2036
+ * Sets the {@link Service} implementation to be managed for the specified <code>name</code> to the
2037
+ * <code>service</code> provided.
2038
+ *
2039
+ * @param {string} name - the name of the {@link Service} to be managed with <code>name</code>
2040
+ * @param {Service} service - the {@link Service} implementation to be managed
2041
+ * @return {void}
2042
+ * @throws {Error} If a {@link Service} is already being managed with the same <code>name</code>.
2043
+ * @public
2044
+ * @memberof ServiceManager#
2045
+ */
2046
+ setService: function(name, service) {
2047
+ if (this._services[name]) {
2048
+ throw new Error('Service is already managed with name: ' + name);
2049
+ }
2050
+
2051
+ if (service) {
2052
+ this._services[name] = service;
2053
+ }
2054
+ }
2055
+
2056
+ });
2057
+
2058
+ var ServiceManager_1 = ServiceManager;
2059
+
2060
+ var optionManager = new OptionManager_1([
2061
+ new Option_1('background', true, 'white'),
2062
+ new Option_1('backgroundAlpha', true, 1, Utilities_1.abs),
2063
+ new Option_1('element'),
2064
+ new Option_1('foreground', true, 'black'),
2065
+ new Option_1('foregroundAlpha', true, 1, Utilities_1.abs),
2066
+ new Option_1('level', true, 'L', Utilities_1.toUpperCase),
2067
+ new Option_1('mime', true, 'image/png'),
2068
+ new Option_1('padding', true, null, Utilities_1.abs),
2069
+ new Option_1('size', true, 100, Utilities_1.abs),
2070
+ new Option_1('value', true, '')
2071
+ ]);
2072
+ var serviceManager = new ServiceManager_1();
2073
+
2074
+ /**
2075
+ * Enables configuration of a QR code generator which uses HTML5 <code>canvas</code> for rendering.
2076
+ *
2077
+ * @param {QRious~Options} [options] - the options to be used
2078
+ * @throws {Error} If any <code>options</code> are invalid.
2079
+ * @public
2080
+ * @class
2081
+ * @extends Nevis
2082
+ */
2083
+ var QRious = lite.extend(function(options) {
2084
+ optionManager.init(options, this, this.update.bind(this));
2085
+
2086
+ var element = optionManager.get('element', this);
2087
+ var elementService = serviceManager.getService('element');
2088
+ var canvas = element && elementService.isCanvas(element) ? element : elementService.createCanvas();
2089
+ var image = element && elementService.isImage(element) ? element : elementService.createImage();
2090
+
2091
+ this._canvasRenderer = new CanvasRenderer_1(this, canvas, true);
2092
+ this._imageRenderer = new ImageRenderer_1(this, image, image === element);
2093
+
2094
+ this.update();
2095
+ }, {
2096
+
2097
+ /**
2098
+ * Returns all of the options configured for this {@link QRious}.
2099
+ *
2100
+ * Any changes made to the returned object will not be reflected in the options themselves or their corresponding
2101
+ * underlying fields.
2102
+ *
2103
+ * @return {Object.<string, *>} A copy of the applied options.
2104
+ * @public
2105
+ * @memberof QRious#
2106
+ */
2107
+ get: function() {
2108
+ return optionManager.getAll(this);
2109
+ },
2110
+
2111
+ /**
2112
+ * Sets all of the specified <code>options</code> and automatically updates this {@link QRious} if any of the
2113
+ * underlying fields are changed as a result.
2114
+ *
2115
+ * This is the preferred method for updating multiple options at one time to avoid unnecessary updates between
2116
+ * changes.
2117
+ *
2118
+ * @param {QRious~Options} options - the options to be set
2119
+ * @return {void}
2120
+ * @throws {Error} If any <code>options</code> are invalid or cannot be modified.
2121
+ * @public
2122
+ * @memberof QRious#
2123
+ */
2124
+ set: function(options) {
2125
+ if (optionManager.setAll(options, this)) {
2126
+ this.update();
2127
+ }
2128
+ },
2129
+
2130
+ /**
2131
+ * Returns the image data URI for the generated QR code using the <code>mime</code> provided.
2132
+ *
2133
+ * @param {string} [mime] - the MIME type for the image
2134
+ * @return {string} The image data URI for the QR code.
2135
+ * @public
2136
+ * @memberof QRious#
2137
+ */
2138
+ toDataURL: function(mime) {
2139
+ return this.canvas.toDataURL(mime || this.mime);
2140
+ },
2141
+
2142
+ /**
2143
+ * Updates this {@link QRious} by generating a new {@link Frame} and re-rendering the QR code.
2144
+ *
2145
+ * @return {void}
2146
+ * @protected
2147
+ * @memberof QRious#
2148
+ */
2149
+ update: function() {
2150
+ var frame = new Frame_1({
2151
+ level: this.level,
2152
+ value: this.value
2153
+ });
2154
+
2155
+ this._canvasRenderer.render(frame);
2156
+ this._imageRenderer.render(frame);
2157
+ }
2158
+
2159
+ }, {
2160
+
2161
+ /**
2162
+ * Configures the <code>service</code> provided to be used by all {@link QRious} instances.
2163
+ *
2164
+ * @param {Service} service - the {@link Service} to be configured
2165
+ * @return {void}
2166
+ * @throws {Error} If a {@link Service} has already been configured with the same name.
2167
+ * @public
2168
+ * @static
2169
+ * @memberof QRious
2170
+ */
2171
+ use: function(service) {
2172
+ serviceManager.setService(service.getName(), service);
2173
+ }
2174
+
2175
+ });
2176
+
2177
+ Object.defineProperties(QRious.prototype, {
2178
+
2179
+ canvas: {
2180
+ /**
2181
+ * Returns the <code>canvas</code> element being used to render the QR code for this {@link QRious}.
2182
+ *
2183
+ * @return {*} The <code>canvas</code> element.
2184
+ * @public
2185
+ * @memberof QRious#
2186
+ * @alias canvas
2187
+ */
2188
+ get: function() {
2189
+ return this._canvasRenderer.getElement();
2190
+ }
2191
+ },
2192
+
2193
+ image: {
2194
+ /**
2195
+ * Returns the <code>img</code> element being used to render the QR code for this {@link QRious}.
2196
+ *
2197
+ * @return {*} The <code>img</code> element.
2198
+ * @public
2199
+ * @memberof QRious#
2200
+ * @alias image
2201
+ */
2202
+ get: function() {
2203
+ return this._imageRenderer.getElement();
2204
+ }
2205
+ }
2206
+
2207
+ });
2208
+
2209
+ var QRious_1$2 = QRious;
2210
+
2211
+ /**
2212
+ * The options used by {@link QRious}.
2213
+ *
2214
+ * @typedef {Object} QRious~Options
2215
+ * @property {string} [background="white"] - The background color to be applied to the QR code.
2216
+ * @property {number} [backgroundAlpha=1] - The background alpha to be applied to the QR code.
2217
+ * @property {*} [element] - The element to be used to render the QR code which may either be an <code>canvas</code> or
2218
+ * <code>img</code>. The element(s) will be created if needed.
2219
+ * @property {string} [foreground="black"] - The foreground color to be applied to the QR code.
2220
+ * @property {number} [foregroundAlpha=1] - The foreground alpha to be applied to the QR code.
2221
+ * @property {string} [level="L"] - The error correction level to be applied to the QR code.
2222
+ * @property {string} [mime="image/png"] - The MIME type to be used to render the image for the QR code.
2223
+ * @property {number} [padding] - The padding for the QR code in pixels.
2224
+ * @property {number} [size=100] - The size of the QR code in pixels.
2225
+ * @property {string} [value=""] - The value to be encoded within the QR code.
2226
+ */
2227
+
2228
+ var index = QRious_1$2;
2229
+
2230
+ /**
2231
+ * Defines a service contract that must be met by all implementations.
2232
+ *
2233
+ * @public
2234
+ * @class
2235
+ * @extends Nevis
2236
+ */
2237
+ var Service = lite.extend({
2238
+
2239
+ /**
2240
+ * Returns the name of this {@link Service}.
2241
+ *
2242
+ * @return {string} The service name.
2243
+ * @public
2244
+ * @abstract
2245
+ * @memberof Service#
2246
+ */
2247
+ getName: function() {}
2248
+
2249
+ });
2250
+
2251
+ var Service_1 = Service;
2252
+
2253
+ /**
2254
+ * A service for working with elements.
2255
+ *
2256
+ * @public
2257
+ * @class
2258
+ * @extends Service
2259
+ */
2260
+ var ElementService = Service_1.extend({
2261
+
2262
+ /**
2263
+ * Creates an instance of a canvas element.
2264
+ *
2265
+ * Implementations of {@link ElementService} <b>must</b> override this method with their own specific logic.
2266
+ *
2267
+ * @return {*} The newly created canvas element.
2268
+ * @public
2269
+ * @abstract
2270
+ * @memberof ElementService#
2271
+ */
2272
+ createCanvas: function() {},
2273
+
2274
+ /**
2275
+ * Creates an instance of a image element.
2276
+ *
2277
+ * Implementations of {@link ElementService} <b>must</b> override this method with their own specific logic.
2278
+ *
2279
+ * @return {*} The newly created image element.
2280
+ * @public
2281
+ * @abstract
2282
+ * @memberof ElementService#
2283
+ */
2284
+ createImage: function() {},
2285
+
2286
+ /**
2287
+ * @override
2288
+ */
2289
+ getName: function() {
2290
+ return 'element';
2291
+ },
2292
+
2293
+ /**
2294
+ * Returns whether the specified <code>element</code> is a canvas.
2295
+ *
2296
+ * Implementations of {@link ElementService} <b>must</b> override this method with their own specific logic.
2297
+ *
2298
+ * @param {*} element - the element to be checked
2299
+ * @return {boolean} <code>true</code> if <code>element</code> is a canvas; otherwise <code>false</code>.
2300
+ * @public
2301
+ * @abstract
2302
+ * @memberof ElementService#
2303
+ */
2304
+ isCanvas: function(element) {},
2305
+
2306
+ /**
2307
+ * Returns whether the specified <code>element</code> is an image.
2308
+ *
2309
+ * Implementations of {@link ElementService} <b>must</b> override this method with their own specific logic.
2310
+ *
2311
+ * @param {*} element - the element to be checked
2312
+ * @return {boolean} <code>true</code> if <code>element</code> is an image; otherwise <code>false</code>.
2313
+ * @public
2314
+ * @abstract
2315
+ * @memberof ElementService#
2316
+ */
2317
+ isImage: function(element) {}
2318
+
2319
+ });
2320
+
2321
+ var ElementService_1 = ElementService;
2322
+
2323
+ /**
2324
+ * An implementation of {@link ElementService} intended for use within a browser environment.
2325
+ *
2326
+ * @public
2327
+ * @class
2328
+ * @extends ElementService
2329
+ */
2330
+ var BrowserElementService = ElementService_1.extend({
2331
+
2332
+ /**
2333
+ * @override
2334
+ */
2335
+ createCanvas: function() {
2336
+ return document.createElement('canvas');
2337
+ },
2338
+
2339
+ /**
2340
+ * @override
2341
+ */
2342
+ createImage: function() {
2343
+ return document.createElement('img');
2344
+ },
2345
+
2346
+ /**
2347
+ * @override
2348
+ */
2349
+ isCanvas: function(element) {
2350
+ return element instanceof HTMLCanvasElement;
2351
+ },
2352
+
2353
+ /**
2354
+ * @override
2355
+ */
2356
+ isImage: function(element) {
2357
+ return element instanceof HTMLImageElement;
2358
+ }
2359
+
2360
+ });
2361
+
2362
+ var BrowserElementService_1 = BrowserElementService;
2363
+
2364
+ index.use(new BrowserElementService_1());
2365
+
2366
+ var QRious_1 = index;
2367
+
2368
+ return QRious_1;
2369
+
2370
+ })));
2371
+
2372
+
2373
+ } (qrious$1.__module));
2374
+ return qrious$1.__module.exports;
2375
+ }
2376
+
2377
+ exports.__require = requireQrious;
2374
2378
  //# sourceMappingURL=qrious.js.map